@@ -37,7 +37,7 @@ const UNKNOWN_SIZE_COST: usize = 10;
3737
3838pub struct Inline ;
3939
40- #[ derive( Copy , Clone ) ]
40+ #[ derive( Copy , Clone , Debug ) ]
4141struct CallSite < ' tcx > {
4242 callee : DefId ,
4343 substs : & ' tcx Substs < ' tcx > ,
@@ -113,7 +113,9 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
113113 loop {
114114 local_change = false ;
115115 while let Some ( callsite) = callsites. pop_front ( ) {
116+ debug ! ( "checking whether to inline callsite {:?}" , callsite) ;
116117 if !self . tcx . is_mir_available ( callsite. callee ) {
118+ debug ! ( "checking whether to inline callsite {:?} - MIR unavailable" , callsite) ;
117119 continue ;
118120 }
119121
@@ -133,10 +135,12 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
133135 } ;
134136
135137 let start = caller_mir. basic_blocks ( ) . len ( ) ;
136-
138+ debug ! ( "attempting to inline callsite {:?} - mir={:?}" , callsite , callee_mir ) ;
137139 if !self . inline_call ( callsite, caller_mir, callee_mir) {
140+ debug ! ( "attempting to inline callsite {:?} - failure" , callsite) ;
138141 continue ;
139142 }
143+ debug ! ( "attempting to inline callsite {:?} - success" , callsite) ;
140144
141145 // Add callsites from inlined function
142146 for ( bb, bb_data) in caller_mir. basic_blocks ( ) . iter_enumerated ( ) . skip ( start) {
@@ -180,16 +184,19 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
180184 callee_mir : & Mir < ' tcx > )
181185 -> bool
182186 {
187+ debug ! ( "should_inline({:?})" , callsite) ;
183188 let tcx = self . tcx ;
184189
185190 // Don't inline closures that have captures
186191 // FIXME: Handle closures better
187192 if callee_mir. upvar_decls . len ( ) > 0 {
193+ debug ! ( " upvar decls present - not inlining" ) ;
188194 return false ;
189195 }
190196
191197 // Cannot inline generators which haven't been transformed yet
192198 if callee_mir. yield_ty . is_some ( ) {
199+ debug ! ( " yield ty present - not inlining" ) ;
193200 return false ;
194201 }
195202
@@ -201,7 +208,10 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
201208 // there are cases that prevent inlining that we
202209 // need to check for first.
203210 attr:: InlineAttr :: Always => true ,
204- attr:: InlineAttr :: Never => return false ,
211+ attr:: InlineAttr :: Never => {
212+ debug ! ( "#[inline(never)] present - not inlining" ) ;
213+ return false
214+ }
205215 attr:: InlineAttr :: Hint => true ,
206216 attr:: InlineAttr :: None => false ,
207217 } ;
@@ -211,6 +221,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
211221 // reference unexported symbols
212222 if callsite. callee . is_local ( ) {
213223 if callsite. substs . types ( ) . count ( ) == 0 && !hinted {
224+ debug ! ( " callee is an exported function - not inlining" ) ;
214225 return false ;
215226 }
216227 }
@@ -232,6 +243,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
232243 if callee_mir. basic_blocks ( ) . len ( ) <= 3 {
233244 threshold += threshold / 4 ;
234245 }
246+ debug ! ( " final inline threshold = {}" , threshold) ;
235247
236248 // FIXME: Give a bonus to functions with only a single caller
237249
@@ -327,12 +339,17 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
327339 }
328340 }
329341
330- debug ! ( "Inline cost for {:?} is {}" , callsite. callee, cost) ;
331-
332342 if let attr:: InlineAttr :: Always = hint {
343+ debug ! ( "INLINING {:?} because inline(always) [cost={}]" , callsite, cost) ;
333344 true
334345 } else {
335- cost <= threshold
346+ if cost <= threshold {
347+ debug ! ( "INLINING {:?} [cost={} <= threshold={}]" , callsite, cost, threshold) ;
348+ true
349+ } else {
350+ debug ! ( "NOT inlining {:?} [cost={} > threshold={}]" , callsite, cost, threshold) ;
351+ false
352+ }
336353 }
337354 }
338355
0 commit comments