@@ -37,7 +37,7 @@ const UNKNOWN_SIZE_COST: usize = 10;
37
37
38
38
pub struct Inline ;
39
39
40
- #[ derive( Copy , Clone ) ]
40
+ #[ derive( Copy , Clone , Debug ) ]
41
41
struct CallSite < ' tcx > {
42
42
callee : DefId ,
43
43
substs : & ' tcx Substs < ' tcx > ,
@@ -113,7 +113,9 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
113
113
loop {
114
114
local_change = false ;
115
115
while let Some ( callsite) = callsites. pop_front ( ) {
116
+ debug ! ( "checking whether to inline callsite {:?}" , callsite) ;
116
117
if !self . tcx . is_mir_available ( callsite. callee ) {
118
+ debug ! ( "checking whether to inline callsite {:?} - MIR unavailable" , callsite) ;
117
119
continue ;
118
120
}
119
121
@@ -133,10 +135,12 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
133
135
} ;
134
136
135
137
let start = caller_mir. basic_blocks ( ) . len ( ) ;
136
-
138
+ debug ! ( "attempting to inline callsite {:?} - mir={:?}" , callsite , callee_mir ) ;
137
139
if !self . inline_call ( callsite, caller_mir, callee_mir) {
140
+ debug ! ( "attempting to inline callsite {:?} - failure" , callsite) ;
138
141
continue ;
139
142
}
143
+ debug ! ( "attempting to inline callsite {:?} - success" , callsite) ;
140
144
141
145
// Add callsites from inlined function
142
146
for ( bb, bb_data) in caller_mir. basic_blocks ( ) . iter_enumerated ( ) . skip ( start) {
@@ -180,16 +184,19 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
180
184
callee_mir : & Mir < ' tcx > )
181
185
-> bool
182
186
{
187
+ debug ! ( "should_inline({:?})" , callsite) ;
183
188
let tcx = self . tcx ;
184
189
185
190
// Don't inline closures that have captures
186
191
// FIXME: Handle closures better
187
192
if callee_mir. upvar_decls . len ( ) > 0 {
193
+ debug ! ( " upvar decls present - not inlining" ) ;
188
194
return false ;
189
195
}
190
196
191
197
// Cannot inline generators which haven't been transformed yet
192
198
if callee_mir. yield_ty . is_some ( ) {
199
+ debug ! ( " yield ty present - not inlining" ) ;
193
200
return false ;
194
201
}
195
202
@@ -201,7 +208,10 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
201
208
// there are cases that prevent inlining that we
202
209
// need to check for first.
203
210
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
+ }
205
215
attr:: InlineAttr :: Hint => true ,
206
216
attr:: InlineAttr :: None => false ,
207
217
} ;
@@ -211,6 +221,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
211
221
// reference unexported symbols
212
222
if callsite. callee . is_local ( ) {
213
223
if callsite. substs . types ( ) . count ( ) == 0 && !hinted {
224
+ debug ! ( " callee is an exported function - not inlining" ) ;
214
225
return false ;
215
226
}
216
227
}
@@ -232,6 +243,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
232
243
if callee_mir. basic_blocks ( ) . len ( ) <= 3 {
233
244
threshold += threshold / 4 ;
234
245
}
246
+ debug ! ( " final inline threshold = {}" , threshold) ;
235
247
236
248
// FIXME: Give a bonus to functions with only a single caller
237
249
@@ -327,12 +339,17 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
327
339
}
328
340
}
329
341
330
- debug ! ( "Inline cost for {:?} is {}" , callsite. callee, cost) ;
331
-
332
342
if let attr:: InlineAttr :: Always = hint {
343
+ debug ! ( "INLINING {:?} because inline(always) [cost={}]" , callsite, cost) ;
333
344
true
334
345
} 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
+ }
336
353
}
337
354
}
338
355
0 commit comments