@@ -9,6 +9,7 @@ use rustc_middle::mir::visit::*;
9
9
use rustc_middle:: mir:: * ;
10
10
use rustc_middle:: ty:: subst:: Subst ;
11
11
use rustc_middle:: ty:: { self , ConstKind , Instance , InstanceDef , ParamEnv , Ty , TyCtxt } ;
12
+ use rustc_session:: config:: OptLevel ;
12
13
use rustc_span:: { hygiene:: ExpnKind , ExpnData , LocalExpnId , Span } ;
13
14
use rustc_target:: spec:: abi:: Abi ;
14
15
@@ -43,7 +44,15 @@ impl<'tcx> MirPass<'tcx> for Inline {
43
44
return enabled;
44
45
}
45
46
46
- sess. opts . mir_opt_level ( ) >= 3
47
+ match sess. mir_opt_level ( ) {
48
+ 0 | 1 => false ,
49
+ 2 => {
50
+ ( sess. opts . optimize == OptLevel :: Default
51
+ || sess. opts . optimize == OptLevel :: Aggressive )
52
+ && sess. opts . incremental == None
53
+ }
54
+ _ => true ,
55
+ }
47
56
}
48
57
49
58
fn run_pass ( & self , tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
@@ -321,8 +330,14 @@ impl<'tcx> Inliner<'tcx> {
321
330
callsite : & CallSite < ' tcx > ,
322
331
callee_attrs : & CodegenFnAttrs ,
323
332
) -> Result < ( ) , & ' static str > {
324
- if let InlineAttr :: Never = callee_attrs. inline {
325
- return Err ( "never inline hint" ) ;
333
+ match callee_attrs. inline {
334
+ InlineAttr :: Never => return Err ( "never inline hint" ) ,
335
+ InlineAttr :: Always => { }
336
+ _ => {
337
+ if self . tcx . sess . mir_opt_level ( ) <= 2 {
338
+ return Err ( "at mir-opt-level=2, only #[inline(always)] is inlined" ) ;
339
+ }
340
+ }
326
341
}
327
342
328
343
// Only inline local functions if they would be eligible for cross-crate
@@ -505,14 +520,12 @@ impl<'tcx> Inliner<'tcx> {
505
520
if let InlineAttr :: Always = callee_attrs. inline {
506
521
debug ! ( "INLINING {:?} because inline(always) [cost={}]" , callsite, cost) ;
507
522
Ok ( ( ) )
523
+ } else if cost <= threshold {
524
+ debug ! ( "INLINING {:?} [cost={} <= threshold={}]" , callsite, cost, threshold) ;
525
+ Ok ( ( ) )
508
526
} else {
509
- if cost <= threshold {
510
- debug ! ( "INLINING {:?} [cost={} <= threshold={}]" , callsite, cost, threshold) ;
511
- Ok ( ( ) )
512
- } else {
513
- debug ! ( "NOT inlining {:?} [cost={} > threshold={}]" , callsite, cost, threshold) ;
514
- Err ( "cost above threshold" )
515
- }
527
+ debug ! ( "NOT inlining {:?} [cost={} > threshold={}]" , callsite, cost, threshold) ;
528
+ Err ( "cost above threshold" )
516
529
}
517
530
}
518
531
0 commit comments