llvm.org GIT mirror llvm / 05d883a
Revert r268107 -- debug build failure git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@268116 91177308-0d34-0410-b5e6-96231b3b80d8 Xinliang David Li 3 years ago
2 changed file(s) with 71 addition(s) and 83 deletion(s). Raw diff Collapse all Expand all
6868 /// shouldInline - Return true if the inliner should attempt to
6969 /// inline at the given CallSite.
7070 bool shouldInline(CallSite CS);
71 /// Return true if inlining of CS can block the caller from being
72 /// inlined which is proved to be more beneficial. \p IC is the
73 /// estimated inline cost associated with callsite \p CS.
74 bool shouldBeDeferred(Function *Caller, CallSite CS, InlineCost IC);
7571
7672 protected:
7773 AssumptionCacheTracker *ACT;
226226 emitOptimizationRemarkAnalysis(Ctx, DEBUG_TYPE, *Caller, DLoc, Msg);
227227 }
228228
229 bool Inliner::shouldBeDeferred(Function *Caller, CallSite CS, InlineCost IC) {
230
231 // For now we only handle local or inline functions.
232 if (!Caller->hasLocalLinkage() && !Caller->hasLinkOnceODRLinkage())
233 return false;
234 // Try to detect the case where the current inlining candidate caller (call
235 // it B) is a static or linkonce-ODR function and is an inlining candidate
236 // elsewhere, and the current candidate callee (call it C) is large enough
237 // that inlining it into B would make B too big to inline later. In these
238 // circumstances it may be best not to inline C into B, but to inline B into
239 // its callers.
240 //
241 // This only applies to static and linkonce-ODR functions because those are
242 // expected to be available for inlining in the translation units where they
243 // are used. Thus we will always have the opportunity to make local inlining
244 // decisions. Importantly the linkonce-ODR linkage covers inline functions
245 // and templates in C++.
246 //
247 // FIXME: All of this logic should be sunk into getInlineCost. It relies on
248 // the internal implementation of the inline cost metrics rather than
249 // treating them as truly abstract units etc.
250 int TotalSecondaryCost = 0;
251 // The candidate cost to be imposed upon the current function.
252 int CandidateCost = IC.getCost() - (InlineConstants::CallPenalty + 1);
253 // This bool tracks what happens if we do NOT inline C into B.
254 bool callerWillBeRemoved = Caller->hasLocalLinkage();
255 // This bool tracks what happens if we DO inline C into B.
256 bool inliningPreventsSomeOuterInline = false;
257 for (User *U : Caller->users()) {
258 CallSite CS2(U);
259
260 // If this isn't a call to Caller (it could be some other sort
261 // of reference) skip it. Such references will prevent the caller
262 // from being removed.
263 if (!CS2 || CS2.getCalledFunction() != Caller) {
264 callerWillBeRemoved = false;
265 continue;
266 }
267
268 InlineCost IC2 = getInlineCost(CS2);
269 ++NumCallerCallersAnalyzed;
270 if (!IC2) {
271 callerWillBeRemoved = false;
272 continue;
273 }
274 if (IC2.isAlways())
275 continue;
276
277 // See if inlining or original callsite would erase the cost delta of
278 // this callsite. We subtract off the penalty for the call instruction,
279 // which we would be deleting.
280 if (IC2.getCostDelta() <= CandidateCost) {
281 inliningPreventsSomeOuterInline = true;
282 TotalSecondaryCost += IC2.getCost();
283 }
284 }
285 // If all outer calls to Caller would get inlined, the cost for the last
286 // one is set very low by getInlineCost, in anticipation that Caller will
287 // be removed entirely. We did not account for this above unless there
288 // is only one caller of Caller.
289 if (callerWillBeRemoved && !Caller->use_empty())
290 TotalSecondaryCost += InlineConstants::LastCallToStaticBonus;
291
292 if (inliningPreventsSomeOuterInline && TotalSecondaryCost < IC.getCost())
293 return true;
294
295 return false;
296 }
297
298229 /// Return true if the inliner should attempt to inline at the given CallSite.
299230 bool Inliner::shouldInline(CallSite CS) {
300231 InlineCost IC = getInlineCost(CS);
326257 Twine(IC.getCostDelta() + IC.getCost()) + ")");
327258 return false;
328259 }
329
330 if (shouldBeDeferred(Caller, CS, IC)) {
331 DEBUG(dbgs() << " NOT Inlining: " << *CS.getInstruction()
332 << " Cost = " << IC.getCost()
333 << ", outer Cost = " << TotalSecondaryCost << '\n');
334 emitAnalysis(CS, Twine("Not inlining. Cost of inlining " +
335 CS.getCalledFunction()->getName() +
336 " increases the cost of inlining " +
337 CS.getCaller()->getName() + " in other contexts"));
338 return false;
260
261 // Try to detect the case where the current inlining candidate caller (call
262 // it B) is a static or linkonce-ODR function and is an inlining candidate
263 // elsewhere, and the current candidate callee (call it C) is large enough
264 // that inlining it into B would make B too big to inline later. In these
265 // circumstances it may be best not to inline C into B, but to inline B into
266 // its callers.
267 //
268 // This only applies to static and linkonce-ODR functions because those are
269 // expected to be available for inlining in the translation units where they
270 // are used. Thus we will always have the opportunity to make local inlining
271 // decisions. Importantly the linkonce-ODR linkage covers inline functions
272 // and templates in C++.
273 //
274 // FIXME: All of this logic should be sunk into getInlineCost. It relies on
275 // the internal implementation of the inline cost metrics rather than
276 // treating them as truly abstract units etc.
277 if (Caller->hasLocalLinkage() || Caller->hasLinkOnceODRLinkage()) {
278 int TotalSecondaryCost = 0;
279 // The candidate cost to be imposed upon the current function.
280 int CandidateCost = IC.getCost() - (InlineConstants::CallPenalty + 1);
281 // This bool tracks what happens if we do NOT inline C into B.
282 bool callerWillBeRemoved = Caller->hasLocalLinkage();
283 // This bool tracks what happens if we DO inline C into B.
284 bool inliningPreventsSomeOuterInline = false;
285 for (User *U : Caller->users()) {
286 CallSite CS2(U);
287
288 // If this isn't a call to Caller (it could be some other sort
289 // of reference) skip it. Such references will prevent the caller
290 // from being removed.
291 if (!CS2 || CS2.getCalledFunction() != Caller) {
292 callerWillBeRemoved = false;
293 continue;
294 }
295
296 InlineCost IC2 = getInlineCost(CS2);
297 ++NumCallerCallersAnalyzed;
298 if (!IC2) {
299 callerWillBeRemoved = false;
300 continue;
301 }
302 if (IC2.isAlways())
303 continue;
304
305 // See if inlining or original callsite would erase the cost delta of
306 // this callsite. We subtract off the penalty for the call instruction,
307 // which we would be deleting.
308 if (IC2.getCostDelta() <= CandidateCost) {
309 inliningPreventsSomeOuterInline = true;
310 TotalSecondaryCost += IC2.getCost();
311 }
312 }
313 // If all outer calls to Caller would get inlined, the cost for the last
314 // one is set very low by getInlineCost, in anticipation that Caller will
315 // be removed entirely. We did not account for this above unless there
316 // is only one caller of Caller.
317 if (callerWillBeRemoved && !Caller->use_empty())
318 TotalSecondaryCost += InlineConstants::LastCallToStaticBonus;
319
320 if (inliningPreventsSomeOuterInline && TotalSecondaryCost < IC.getCost()) {
321 DEBUG(dbgs() << " NOT Inlining: " << *CS.getInstruction() <<
322 " Cost = " << IC.getCost() <<
323 ", outer Cost = " << TotalSecondaryCost << '\n');
324 emitAnalysis(
325 CS, Twine("Not inlining. Cost of inlining " +
326 CS.getCalledFunction()->getName() +
327 " increases the cost of inlining " +
328 CS.getCaller()->getName() + " in other contexts"));
329 return false;
330 }
339331 }
340332
341333 DEBUG(dbgs() << " Inlining: cost=" << IC.getCost()