@@ -388,6 +388,7 @@ fn mir_built(tcx: TyCtxt<'_>, def: LocalDefId) -> &Steal<Body<'_>> {
388
388
& Lint ( sanity_check:: SanityCheck ) ,
389
389
] ,
390
390
None ,
391
+ pm:: Optimizations :: Enable ,
391
392
) ;
392
393
tcx. alloc_steal_mir ( body)
393
394
}
@@ -440,6 +441,7 @@ fn mir_promoted(
440
441
& mut body,
441
442
& [ & promote_pass, & simplify:: SimplifyCfg :: PromoteConsts , & coverage:: InstrumentCoverage ] ,
442
443
Some ( MirPhase :: Analysis ( AnalysisPhase :: Initial ) ) ,
444
+ pm:: Optimizations :: Enable ,
443
445
) ;
444
446
445
447
lint_tail_expr_drop_order:: run_lint ( tcx, def, & body) ;
@@ -473,7 +475,7 @@ fn inner_mir_for_ctfe(tcx: TyCtxt<'_>, def: LocalDefId) -> Body<'_> {
473
475
} ;
474
476
475
477
let mut body = remap_mir_for_const_eval_select ( tcx, body, hir:: Constness :: Const ) ;
476
- pm:: run_passes ( tcx, & mut body, & [ & ctfe_limit:: CtfeLimit ] , None ) ;
478
+ pm:: run_passes ( tcx, & mut body, & [ & ctfe_limit:: CtfeLimit ] , None , pm :: Optimizations :: Enable ) ;
477
479
478
480
body
479
481
}
@@ -493,7 +495,7 @@ fn mir_drops_elaborated_and_const_checked(tcx: TyCtxt<'_>, def: LocalDefId) -> &
493
495
let is_fn_like = tcx. def_kind ( def) . is_fn_like ( ) ;
494
496
if is_fn_like {
495
497
// Do not compute the mir call graph without said call graph actually being used.
496
- if pm:: should_run_pass ( tcx, & inline:: Inline )
498
+ if pm:: should_run_pass ( tcx, & inline:: Inline , pm :: Optimizations :: Enable )
497
499
|| inline:: ForceInline :: should_run_pass_for_callee ( tcx, def. to_def_id ( ) )
498
500
{
499
501
tcx. ensure_with_value ( ) . mir_inliner_callees ( ty:: InstanceKind :: Item ( def. to_def_id ( ) ) ) ;
@@ -533,6 +535,7 @@ pub fn run_analysis_to_runtime_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'
533
535
& Lint ( post_drop_elaboration:: CheckLiveDrops ) ,
534
536
] ,
535
537
None ,
538
+ pm:: Optimizations :: Enable ,
536
539
) ;
537
540
}
538
541
@@ -557,7 +560,13 @@ fn run_analysis_cleanup_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
557
560
& deref_separator:: Derefer ,
558
561
] ;
559
562
560
- pm:: run_passes ( tcx, body, passes, Some ( MirPhase :: Analysis ( AnalysisPhase :: PostCleanup ) ) ) ;
563
+ pm:: run_passes (
564
+ tcx,
565
+ body,
566
+ passes,
567
+ Some ( MirPhase :: Analysis ( AnalysisPhase :: PostCleanup ) ) ,
568
+ pm:: Optimizations :: Enable ,
569
+ ) ;
561
570
}
562
571
563
572
/// Returns the sequence of passes that lowers analysis to runtime MIR.
@@ -597,7 +606,13 @@ fn run_runtime_cleanup_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
597
606
& simplify:: SimplifyCfg :: PreOptimizations ,
598
607
] ;
599
608
600
- pm:: run_passes ( tcx, body, passes, Some ( MirPhase :: Runtime ( RuntimePhase :: PostCleanup ) ) ) ;
609
+ pm:: run_passes (
610
+ tcx,
611
+ body,
612
+ passes,
613
+ Some ( MirPhase :: Runtime ( RuntimePhase :: PostCleanup ) ) ,
614
+ pm:: Optimizations :: Enable ,
615
+ ) ;
601
616
602
617
// Clear this by anticipation. Optimizations and runtime MIR have no reason to look
603
618
// into this information, which is meant for borrowck diagnostics.
@@ -611,6 +626,15 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
611
626
WithMinOptLevel ( 1 , x)
612
627
}
613
628
629
+ let def_id = body. source . def_id ( ) ;
630
+ let optimizations = if tcx. def_kind ( def_id) . has_codegen_attrs ( )
631
+ && tcx. codegen_fn_attrs ( def_id) . optimize . do_not_optimize ( )
632
+ {
633
+ pm:: Optimizations :: Disable
634
+ } else {
635
+ pm:: Optimizations :: Enable
636
+ } ;
637
+
614
638
// The main optimizations that we do on MIR.
615
639
pm:: run_passes (
616
640
tcx,
@@ -683,6 +707,7 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
683
707
& dump_mir:: Marker ( "PreCodegen" ) ,
684
708
] ,
685
709
Some ( MirPhase :: Runtime ( RuntimePhase :: Optimized ) ) ,
710
+ optimizations,
686
711
) ;
687
712
}
688
713
0 commit comments