1
Fork 0

Test enabling MIR inliner

This commit is contained in:
Wesley Wiser 2021-09-30 22:03:49 -04:00 committed by Camille GILLOT
parent b33c6e1bd8
commit d1d9092e3c
2 changed files with 24 additions and 11 deletions

View file

@ -9,6 +9,7 @@ use rustc_middle::mir::visit::*;
use rustc_middle::mir::*; use rustc_middle::mir::*;
use rustc_middle::ty::subst::Subst; use rustc_middle::ty::subst::Subst;
use rustc_middle::ty::{self, ConstKind, Instance, InstanceDef, ParamEnv, Ty, TyCtxt}; use rustc_middle::ty::{self, ConstKind, Instance, InstanceDef, ParamEnv, Ty, TyCtxt};
use rustc_session::config::OptLevel;
use rustc_span::{hygiene::ExpnKind, ExpnData, LocalExpnId, Span}; use rustc_span::{hygiene::ExpnKind, ExpnData, LocalExpnId, Span};
use rustc_target::spec::abi::Abi; use rustc_target::spec::abi::Abi;
@ -43,7 +44,15 @@ impl<'tcx> MirPass<'tcx> for Inline {
return enabled; return enabled;
} }
sess.opts.mir_opt_level() >= 3 match sess.mir_opt_level() {
0 | 1 => false,
2 => {
(sess.opts.optimize == OptLevel::Default
|| sess.opts.optimize == OptLevel::Aggressive)
&& sess.opts.incremental == None
}
_ => true,
}
} }
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
@ -321,8 +330,14 @@ impl<'tcx> Inliner<'tcx> {
callsite: &CallSite<'tcx>, callsite: &CallSite<'tcx>,
callee_attrs: &CodegenFnAttrs, callee_attrs: &CodegenFnAttrs,
) -> Result<(), &'static str> { ) -> Result<(), &'static str> {
if let InlineAttr::Never = callee_attrs.inline { match callee_attrs.inline {
return Err("never inline hint"); InlineAttr::Never => return Err("never inline hint"),
InlineAttr::Always => {}
_ => {
if self.tcx.sess.mir_opt_level() <= 2 {
return Err("at mir-opt-level=2, only #[inline(always)] is inlined");
}
}
} }
// Only inline local functions if they would be eligible for cross-crate // Only inline local functions if they would be eligible for cross-crate
@ -505,8 +520,7 @@ impl<'tcx> Inliner<'tcx> {
if let InlineAttr::Always = callee_attrs.inline { if let InlineAttr::Always = callee_attrs.inline {
debug!("INLINING {:?} because inline(always) [cost={}]", callsite, cost); debug!("INLINING {:?} because inline(always) [cost={}]", callsite, cost);
Ok(()) Ok(())
} else { } else if cost <= threshold {
if cost <= threshold {
debug!("INLINING {:?} [cost={} <= threshold={}]", callsite, cost, threshold); debug!("INLINING {:?} [cost={} <= threshold={}]", callsite, cost, threshold);
Ok(()) Ok(())
} else { } else {
@ -514,7 +528,6 @@ impl<'tcx> Inliner<'tcx> {
Err("cost above threshold") Err("cost above threshold")
} }
} }
}
fn inline_call( fn inline_call(
&self, &self,

View file

@ -1,5 +1,5 @@
// build-fail // build-fail
// compile-flags:-Zpolymorphize=on // compile-flags:-Zpolymorphize=on -Zinline-mir=off
#![feature(generic_const_exprs, generators, generator_trait, rustc_attrs)] #![feature(generic_const_exprs, generators, generator_trait, rustc_attrs)]
//~^ WARN the feature `generic_const_exprs` is incomplete //~^ WARN the feature `generic_const_exprs` is incomplete