Skip to content

Commit

Permalink
Rollup merge of rust-lang#45895 - arielb1:inline-debug, r=eddyb
Browse files Browse the repository at this point in the history
add a bunch of debug logging to MIR inlining

r? @eddyb

@bors rollup
  • Loading branch information
kennytm authored Nov 10, 2017
2 parents 253d18e + 48655ea commit 9c76885
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/librustc_mir/transform/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const UNKNOWN_SIZE_COST: usize = 10;

pub struct Inline;

#[derive(Copy, Clone)]
#[derive(Copy, Clone, Debug)]
struct CallSite<'tcx> {
callee: DefId,
substs: &'tcx Substs<'tcx>,
Expand Down Expand Up @@ -113,7 +113,9 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
loop {
local_change = false;
while let Some(callsite) = callsites.pop_front() {
debug!("checking whether to inline callsite {:?}", callsite);
if !self.tcx.is_mir_available(callsite.callee) {
debug!("checking whether to inline callsite {:?} - MIR unavailable", callsite);
continue;
}

Expand All @@ -133,10 +135,12 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
};

let start = caller_mir.basic_blocks().len();

debug!("attempting to inline callsite {:?} - mir={:?}", callsite, callee_mir);
if !self.inline_call(callsite, caller_mir, callee_mir) {
debug!("attempting to inline callsite {:?} - failure", callsite);
continue;
}
debug!("attempting to inline callsite {:?} - success", callsite);

// Add callsites from inlined function
for (bb, bb_data) in caller_mir.basic_blocks().iter_enumerated().skip(start) {
Expand Down Expand Up @@ -180,16 +184,19 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
callee_mir: &Mir<'tcx>)
-> bool
{
debug!("should_inline({:?})", callsite);
let tcx = self.tcx;

// Don't inline closures that have captures
// FIXME: Handle closures better
if callee_mir.upvar_decls.len() > 0 {
debug!(" upvar decls present - not inlining");
return false;
}

// Cannot inline generators which haven't been transformed yet
if callee_mir.yield_ty.is_some() {
debug!(" yield ty present - not inlining");
return false;
}

Expand All @@ -201,7 +208,10 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
// there are cases that prevent inlining that we
// need to check for first.
attr::InlineAttr::Always => true,
attr::InlineAttr::Never => return false,
attr::InlineAttr::Never => {
debug!("#[inline(never)] present - not inlining");
return false
}
attr::InlineAttr::Hint => true,
attr::InlineAttr::None => false,
};
Expand All @@ -211,6 +221,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
// reference unexported symbols
if callsite.callee.is_local() {
if callsite.substs.types().count() == 0 && !hinted {
debug!(" callee is an exported function - not inlining");
return false;
}
}
Expand All @@ -232,6 +243,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
if callee_mir.basic_blocks().len() <= 3 {
threshold += threshold / 4;
}
debug!(" final inline threshold = {}", threshold);

// FIXME: Give a bonus to functions with only a single caller

Expand Down Expand Up @@ -327,12 +339,17 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
}
}

debug!("Inline cost for {:?} is {}", callsite.callee, cost);

if let attr::InlineAttr::Always = hint {
debug!("INLINING {:?} because inline(always) [cost={}]", callsite, cost);
true
} else {
cost <= threshold
if cost <= threshold {
debug!("INLINING {:?} [cost={} <= threshold={}]", callsite, cost, threshold);
true
} else {
debug!("NOT inlining {:?} [cost={} > threshold={}]", callsite, cost, threshold);
false
}
}
}

Expand Down

0 comments on commit 9c76885

Please sign in to comment.