@@ -44,7 +44,7 @@ pub(crate) fn codegen_fn<'tcx>(
4444 let symbol_name = tcx. symbol_name ( instance) . name . to_string ( ) ;
4545 let _timer = tcx. prof . generic_activity_with_arg ( "codegen fn" , & * symbol_name) ;
4646
47- let mir = tcx . instance_mir ( instance. def ) ;
47+ let mir = rustc_mir_transform :: build_codegen_mir ( tcx , instance) ;
4848 let _mir_guard = crate :: PrintOnPanic ( || {
4949 let mut buf = Vec :: new ( ) ;
5050 with_no_trimmed_paths ! ( {
@@ -282,10 +282,8 @@ fn verify_func(tcx: TyCtxt<'_>, writer: &crate::pretty_clif::CommentWriter, func
282282}
283283
284284fn codegen_fn_body ( fx : & mut FunctionCx < ' _ , ' _ , ' _ > , start_block : Block ) {
285- let arg_uninhabited = fx
286- . mir
287- . args_iter ( )
288- . any ( |arg| fx. layout_of ( fx. monomorphize ( fx. mir . local_decls [ arg] . ty ) ) . is_uninhabited ( ) ) ;
285+ let arg_uninhabited =
286+ fx. mir . args_iter ( ) . any ( |arg| fx. layout_of ( fx. mir . local_decls [ arg] . ty ) . is_uninhabited ( ) ) ;
289287 if arg_uninhabited {
290288 fx. bcx . append_block_params_for_function_params ( fx. block_map [ START_BLOCK ] ) ;
291289 fx. bcx . switch_to_block ( fx. block_map [ START_BLOCK ] ) ;
@@ -297,19 +295,10 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
297295 . generic_activity ( "codegen prelude" )
298296 . run ( || crate :: abi:: codegen_fn_prelude ( fx, start_block) ) ;
299297
300- let reachable_blocks = traversal:: mono_reachable_as_bitset ( fx. mir , fx. tcx , fx. instance ) ;
301-
302298 for ( bb, bb_data) in fx. mir . basic_blocks . iter_enumerated ( ) {
303299 let block = fx. get_block ( bb) ;
304300 fx. bcx . switch_to_block ( block) ;
305301
306- if !reachable_blocks. contains ( bb) {
307- // We want to skip this block, because it's not reachable. But we still create
308- // the block so terminators in other blocks can reference it.
309- fx. bcx . ins ( ) . trap ( TrapCode :: user ( 1 /* unreachable */ ) . unwrap ( ) ) ;
310- continue ;
311- }
312-
313302 if bb_data. is_cleanup {
314303 if cfg ! ( not( feature = "unwinding" ) ) {
315304 continue ;
@@ -698,8 +687,8 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt:
698687 ref operand,
699688 to_ty,
700689 ) => {
701- let from_ty = fx . monomorphize ( operand. ty ( & fx. mir . local_decls , fx. tcx ) ) ;
702- let to_layout = fx. layout_of ( fx . monomorphize ( to_ty) ) ;
690+ let from_ty = operand. ty ( & fx. mir . local_decls , fx. tcx ) ;
691+ let to_layout = fx. layout_of ( to_ty) ;
703692 match * from_ty. kind ( ) {
704693 ty:: FnDef ( def_id, args) => {
705694 let func_ref = fx. get_function_ref (
@@ -722,7 +711,7 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt:
722711 ref operand,
723712 to_ty,
724713 ) => {
725- let to_layout = fx. layout_of ( fx . monomorphize ( to_ty) ) ;
714+ let to_layout = fx. layout_of ( to_ty) ;
726715 let operand = codegen_operand ( fx, operand) ;
727716 lval. write_cvalue ( fx, operand. cast_pointer_to ( to_layout) ) ;
728717 }
@@ -752,7 +741,6 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt:
752741 ) => {
753742 let operand = codegen_operand ( fx, operand) ;
754743 let from_ty = operand. layout ( ) . ty ;
755- let to_ty = fx. monomorphize ( to_ty) ;
756744
757745 fn is_wide_ptr < ' tcx > ( fx : & FunctionCx < ' _ , ' _ , ' tcx > , ty : Ty < ' tcx > ) -> bool {
758746 ty. builtin_deref ( true ) . is_some_and ( |pointee_ty| {
@@ -824,8 +812,7 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt:
824812 }
825813 Rvalue :: Repeat ( ref operand, times) => {
826814 let operand = codegen_operand ( fx, operand) ;
827- let times = fx
828- . monomorphize ( times)
815+ let times = times
829816 . try_to_target_usize ( fx. tcx )
830817 . expect ( "expected monomorphic const in codegen" ) ;
831818 if operand. layout ( ) . size . bytes ( ) == 0 {
@@ -862,7 +849,7 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt:
862849 if matches ! ( * * kind, AggregateKind :: RawPtr ( ..) ) =>
863850 {
864851 let ty = to_place_and_rval. 1 . ty ( & fx. mir . local_decls , fx. tcx ) ;
865- let layout = fx. layout_of ( fx . monomorphize ( ty ) ) ;
852+ let layout = fx. layout_of ( ty ) ;
866853 let [ data, meta] = & * operands. raw else {
867854 bug ! ( "RawPtr fields: {operands:?}" ) ;
868855 } ;
@@ -957,8 +944,7 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt:
957944fn codegen_array_len < ' tcx > ( fx : & mut FunctionCx < ' _ , ' _ , ' tcx > , place : CPlace < ' tcx > ) -> Value {
958945 match * place. layout ( ) . ty . kind ( ) {
959946 ty:: Array ( _elem_ty, len) => {
960- let len = fx
961- . monomorphize ( len)
947+ let len = len
962948 . try_to_target_usize ( fx. tcx )
963949 . expect ( "expected monomorphic const in codegen" ) as i64 ;
964950 fx. bcx . ins ( ) . iconst ( fx. pointer_type , len)
@@ -981,7 +967,7 @@ pub(crate) fn codegen_place<'tcx>(
981967 }
982968 PlaceElem :: OpaqueCast ( ty) => bug ! ( "encountered OpaqueCast({ty}) in codegen" ) ,
983969 PlaceElem :: UnwrapUnsafeBinder ( ty) => {
984- cplace = cplace. place_transmute_type ( fx, fx . monomorphize ( ty ) ) ;
970+ cplace = cplace. place_transmute_type ( fx, ty ) ;
985971 }
986972 PlaceElem :: Field ( field, _ty) => {
987973 cplace = cplace. place_field ( fx, field) ;
0 commit comments