Mercurial > hg > Members > tobaru > cbc > CbC_llvm
comparison lib/Transforms/IPO/Inliner.cpp @ 80:67baa08a3894
update to LLVM 3.6
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 25 Sep 2014 16:56:18 +0900 |
parents | 54457678186b |
children | 60c9769439b8 |
comparison
equal
deleted
inserted
replaced
76:9e74acfe8c42 | 80:67baa08a3894 |
---|---|
11 // missing any calls and updating the call graph. The decisions of which calls | 11 // missing any calls and updating the call graph. The decisions of which calls |
12 // are profitable to inline are implemented elsewhere. | 12 // are profitable to inline are implemented elsewhere. |
13 // | 13 // |
14 //===----------------------------------------------------------------------===// | 14 //===----------------------------------------------------------------------===// |
15 | 15 |
16 #define DEBUG_TYPE "inline" | |
17 #include "llvm/Transforms/IPO/InlinerPass.h" | 16 #include "llvm/Transforms/IPO/InlinerPass.h" |
18 #include "llvm/ADT/SmallPtrSet.h" | 17 #include "llvm/ADT/SmallPtrSet.h" |
19 #include "llvm/ADT/Statistic.h" | 18 #include "llvm/ADT/Statistic.h" |
19 #include "llvm/Analysis/AliasAnalysis.h" | |
20 #include "llvm/Analysis/AssumptionTracker.h" | |
20 #include "llvm/Analysis/CallGraph.h" | 21 #include "llvm/Analysis/CallGraph.h" |
21 #include "llvm/Analysis/InlineCost.h" | 22 #include "llvm/Analysis/InlineCost.h" |
23 #include "llvm/IR/CallSite.h" | |
22 #include "llvm/IR/DataLayout.h" | 24 #include "llvm/IR/DataLayout.h" |
25 #include "llvm/IR/DiagnosticInfo.h" | |
23 #include "llvm/IR/Instructions.h" | 26 #include "llvm/IR/Instructions.h" |
24 #include "llvm/IR/IntrinsicInst.h" | 27 #include "llvm/IR/IntrinsicInst.h" |
25 #include "llvm/IR/Module.h" | 28 #include "llvm/IR/Module.h" |
26 #include "llvm/Support/CallSite.h" | |
27 #include "llvm/Support/CommandLine.h" | 29 #include "llvm/Support/CommandLine.h" |
28 #include "llvm/Support/Debug.h" | 30 #include "llvm/Support/Debug.h" |
29 #include "llvm/Support/raw_ostream.h" | 31 #include "llvm/Support/raw_ostream.h" |
30 #include "llvm/Target/TargetLibraryInfo.h" | 32 #include "llvm/Target/TargetLibraryInfo.h" |
31 #include "llvm/Transforms/Utils/Cloning.h" | 33 #include "llvm/Transforms/Utils/Cloning.h" |
32 #include "llvm/Transforms/Utils/Local.h" | 34 #include "llvm/Transforms/Utils/Local.h" |
33 using namespace llvm; | 35 using namespace llvm; |
34 | 36 |
37 #define DEBUG_TYPE "inline" | |
38 | |
35 STATISTIC(NumInlined, "Number of functions inlined"); | 39 STATISTIC(NumInlined, "Number of functions inlined"); |
36 STATISTIC(NumCallsDeleted, "Number of call sites deleted, not inlined"); | 40 STATISTIC(NumCallsDeleted, "Number of call sites deleted, not inlined"); |
37 STATISTIC(NumDeleted, "Number of functions deleted because all callers found"); | 41 STATISTIC(NumDeleted, "Number of functions deleted because all callers found"); |
38 STATISTIC(NumMergedAllocas, "Number of allocas merged together"); | 42 STATISTIC(NumMergedAllocas, "Number of allocas merged together"); |
39 | 43 |
48 | 52 |
49 static cl::opt<int> | 53 static cl::opt<int> |
50 HintThreshold("inlinehint-threshold", cl::Hidden, cl::init(325), | 54 HintThreshold("inlinehint-threshold", cl::Hidden, cl::init(325), |
51 cl::desc("Threshold for inlining functions with inline hint")); | 55 cl::desc("Threshold for inlining functions with inline hint")); |
52 | 56 |
57 // We instroduce this threshold to help performance of instrumentation based | |
58 // PGO before we actually hook up inliner with analysis passes such as BPI and | |
59 // BFI. | |
60 static cl::opt<int> | |
61 ColdThreshold("inlinecold-threshold", cl::Hidden, cl::init(225), | |
62 cl::desc("Threshold for inlining functions with cold attribute")); | |
63 | |
53 // Threshold to use when optsize is specified (and there is no -inline-limit). | 64 // Threshold to use when optsize is specified (and there is no -inline-limit). |
54 const int OptSizeThreshold = 75; | 65 const int OptSizeThreshold = 75; |
55 | 66 |
56 Inliner::Inliner(char &ID) | 67 Inliner::Inliner(char &ID) |
57 : CallGraphSCCPass(ID), InlineThreshold(InlineLimit), InsertLifetime(true) {} | 68 : CallGraphSCCPass(ID), InlineThreshold(InlineLimit), InsertLifetime(true) {} |
63 | 74 |
64 /// getAnalysisUsage - For this class, we declare that we require and preserve | 75 /// getAnalysisUsage - For this class, we declare that we require and preserve |
65 /// the call graph. If the derived class implements this method, it should | 76 /// the call graph. If the derived class implements this method, it should |
66 /// always explicitly call the implementation here. | 77 /// always explicitly call the implementation here. |
67 void Inliner::getAnalysisUsage(AnalysisUsage &AU) const { | 78 void Inliner::getAnalysisUsage(AnalysisUsage &AU) const { |
79 AU.addRequired<AliasAnalysis>(); | |
80 AU.addRequired<AssumptionTracker>(); | |
68 CallGraphSCCPass::getAnalysisUsage(AU); | 81 CallGraphSCCPass::getAnalysisUsage(AU); |
69 } | 82 } |
70 | 83 |
71 | 84 |
72 typedef DenseMap<ArrayType*, std::vector<AllocaInst*> > | 85 typedef DenseMap<ArrayType*, std::vector<AllocaInst*> > |
115 /// inline this call site we attempt to reuse already available allocas or add | 128 /// inline this call site we attempt to reuse already available allocas or add |
116 /// any new allocas to the set if not possible. | 129 /// any new allocas to the set if not possible. |
117 static bool InlineCallIfPossible(CallSite CS, InlineFunctionInfo &IFI, | 130 static bool InlineCallIfPossible(CallSite CS, InlineFunctionInfo &IFI, |
118 InlinedArrayAllocasTy &InlinedArrayAllocas, | 131 InlinedArrayAllocasTy &InlinedArrayAllocas, |
119 int InlineHistory, bool InsertLifetime, | 132 int InlineHistory, bool InsertLifetime, |
120 const DataLayout *TD) { | 133 const DataLayout *DL) { |
121 Function *Callee = CS.getCalledFunction(); | 134 Function *Callee = CS.getCalledFunction(); |
122 Function *Caller = CS.getCaller(); | 135 Function *Caller = CS.getCaller(); |
123 | 136 |
124 // Try to inline the function. Get the list of static allocas that were | 137 // Try to inline the function. Get the list of static allocas that were |
125 // inlined. | 138 // inlined. |
174 | 187 |
175 // Don't bother trying to merge array allocations (they will usually be | 188 // Don't bother trying to merge array allocations (they will usually be |
176 // canonicalized to be an allocation *of* an array), or allocations whose | 189 // canonicalized to be an allocation *of* an array), or allocations whose |
177 // type is not itself an array (because we're afraid of pessimizing SRoA). | 190 // type is not itself an array (because we're afraid of pessimizing SRoA). |
178 ArrayType *ATy = dyn_cast<ArrayType>(AI->getAllocatedType()); | 191 ArrayType *ATy = dyn_cast<ArrayType>(AI->getAllocatedType()); |
179 if (ATy == 0 || AI->isArrayAllocation()) | 192 if (!ATy || AI->isArrayAllocation()) |
180 continue; | 193 continue; |
181 | 194 |
182 // Get the list of all available allocas for this array type. | 195 // Get the list of all available allocas for this array type. |
183 std::vector<AllocaInst*> &AllocasForType = InlinedArrayAllocas[ATy]; | 196 std::vector<AllocaInst*> &AllocasForType = InlinedArrayAllocas[ATy]; |
184 | 197 |
194 unsigned Align1 = AI->getAlignment(), | 207 unsigned Align1 = AI->getAlignment(), |
195 Align2 = AvailableAlloca->getAlignment(); | 208 Align2 = AvailableAlloca->getAlignment(); |
196 // If we don't have data layout information, and only one alloca is using | 209 // If we don't have data layout information, and only one alloca is using |
197 // the target default, then we can't safely merge them because we can't | 210 // the target default, then we can't safely merge them because we can't |
198 // pick the greater alignment. | 211 // pick the greater alignment. |
199 if (!TD && (!Align1 || !Align2) && Align1 != Align2) | 212 if (!DL && (!Align1 || !Align2) && Align1 != Align2) |
200 continue; | 213 continue; |
201 | 214 |
202 // The available alloca has to be in the right function, not in some other | 215 // The available alloca has to be in the right function, not in some other |
203 // function in this SCC. | 216 // function in this SCC. |
204 if (AvailableAlloca->getParent() != AI->getParent()) | 217 if (AvailableAlloca->getParent() != AI->getParent()) |
216 | 229 |
217 AI->replaceAllUsesWith(AvailableAlloca); | 230 AI->replaceAllUsesWith(AvailableAlloca); |
218 | 231 |
219 if (Align1 != Align2) { | 232 if (Align1 != Align2) { |
220 if (!Align1 || !Align2) { | 233 if (!Align1 || !Align2) { |
221 assert(TD && "DataLayout required to compare default alignments"); | 234 assert(DL && "DataLayout required to compare default alignments"); |
222 unsigned TypeAlign = TD->getABITypeAlignment(AI->getAllocatedType()); | 235 unsigned TypeAlign = DL->getABITypeAlignment(AI->getAllocatedType()); |
223 | 236 |
224 Align1 = Align1 ? Align1 : TypeAlign; | 237 Align1 = Align1 ? Align1 : TypeAlign; |
225 Align2 = Align2 ? Align2 : TypeAlign; | 238 Align2 = Align2 ? Align2 : TypeAlign; |
226 } | 239 } |
227 | 240 |
230 } | 243 } |
231 | 244 |
232 AI->eraseFromParent(); | 245 AI->eraseFromParent(); |
233 MergedAwayAlloca = true; | 246 MergedAwayAlloca = true; |
234 ++NumMergedAllocas; | 247 ++NumMergedAllocas; |
235 IFI.StaticAllocas[AllocaNo] = 0; | 248 IFI.StaticAllocas[AllocaNo] = nullptr; |
236 break; | 249 break; |
237 } | 250 } |
238 | 251 |
239 // If we already nuked the alloca, we're done with it. | 252 // If we already nuked the alloca, we're done with it. |
240 if (MergedAwayAlloca) | 253 if (MergedAwayAlloca) |
275 if (InlineHint && HintThreshold > thres | 288 if (InlineHint && HintThreshold > thres |
276 && !Caller->getAttributes().hasAttribute(AttributeSet::FunctionIndex, | 289 && !Caller->getAttributes().hasAttribute(AttributeSet::FunctionIndex, |
277 Attribute::MinSize)) | 290 Attribute::MinSize)) |
278 thres = HintThreshold; | 291 thres = HintThreshold; |
279 | 292 |
293 // Listen to the cold attribute when it would decrease the threshold. | |
294 bool ColdCallee = Callee && !Callee->isDeclaration() && | |
295 Callee->getAttributes().hasAttribute(AttributeSet::FunctionIndex, | |
296 Attribute::Cold); | |
297 // Command line argument for InlineLimit will override the default | |
298 // ColdThreshold. If we have -inline-threshold but no -inlinecold-threshold, | |
299 // do not use the default cold threshold even if it is smaller. | |
300 if ((InlineLimit.getNumOccurrences() == 0 || | |
301 ColdThreshold.getNumOccurrences() > 0) && ColdCallee && | |
302 ColdThreshold < thres) | |
303 thres = ColdThreshold; | |
304 | |
280 return thres; | 305 return thres; |
306 } | |
307 | |
308 static void emitAnalysis(CallSite CS, const Twine &Msg) { | |
309 Function *Caller = CS.getCaller(); | |
310 LLVMContext &Ctx = Caller->getContext(); | |
311 DebugLoc DLoc = CS.getInstruction()->getDebugLoc(); | |
312 emitOptimizationRemarkAnalysis(Ctx, DEBUG_TYPE, *Caller, DLoc, Msg); | |
281 } | 313 } |
282 | 314 |
283 /// shouldInline - Return true if the inliner should attempt to inline | 315 /// shouldInline - Return true if the inliner should attempt to inline |
284 /// at the given CallSite. | 316 /// at the given CallSite. |
285 bool Inliner::shouldInline(CallSite CS) { | 317 bool Inliner::shouldInline(CallSite CS) { |
286 InlineCost IC = getInlineCost(CS); | 318 InlineCost IC = getInlineCost(CS); |
287 | 319 |
288 if (IC.isAlways()) { | 320 if (IC.isAlways()) { |
289 DEBUG(dbgs() << " Inlining: cost=always" | 321 DEBUG(dbgs() << " Inlining: cost=always" |
290 << ", Call: " << *CS.getInstruction() << "\n"); | 322 << ", Call: " << *CS.getInstruction() << "\n"); |
323 emitAnalysis(CS, Twine(CS.getCalledFunction()->getName()) + | |
324 " should always be inlined (cost=always)"); | |
291 return true; | 325 return true; |
292 } | 326 } |
293 | 327 |
294 if (IC.isNever()) { | 328 if (IC.isNever()) { |
295 DEBUG(dbgs() << " NOT Inlining: cost=never" | 329 DEBUG(dbgs() << " NOT Inlining: cost=never" |
296 << ", Call: " << *CS.getInstruction() << "\n"); | 330 << ", Call: " << *CS.getInstruction() << "\n"); |
331 emitAnalysis(CS, Twine(CS.getCalledFunction()->getName() + | |
332 " should never be inlined (cost=never)")); | |
297 return false; | 333 return false; |
298 } | 334 } |
299 | 335 |
300 Function *Caller = CS.getCaller(); | 336 Function *Caller = CS.getCaller(); |
301 if (!IC) { | 337 if (!IC) { |
302 DEBUG(dbgs() << " NOT Inlining: cost=" << IC.getCost() | 338 DEBUG(dbgs() << " NOT Inlining: cost=" << IC.getCost() |
303 << ", thres=" << (IC.getCostDelta() + IC.getCost()) | 339 << ", thres=" << (IC.getCostDelta() + IC.getCost()) |
304 << ", Call: " << *CS.getInstruction() << "\n"); | 340 << ", Call: " << *CS.getInstruction() << "\n"); |
341 emitAnalysis(CS, Twine(CS.getCalledFunction()->getName() + | |
342 " too costly to inline (cost=") + | |
343 Twine(IC.getCost()) + ", threshold=" + | |
344 Twine(IC.getCostDelta() + IC.getCost()) + ")"); | |
305 return false; | 345 return false; |
306 } | 346 } |
307 | 347 |
308 // Try to detect the case where the current inlining candidate caller (call | 348 // Try to detect the case where the current inlining candidate caller (call |
309 // it B) is a static or linkonce-ODR function and is an inlining candidate | 349 // it B) is a static or linkonce-ODR function and is an inlining candidate |
319 // and templates in C++. | 359 // and templates in C++. |
320 // | 360 // |
321 // FIXME: All of this logic should be sunk into getInlineCost. It relies on | 361 // FIXME: All of this logic should be sunk into getInlineCost. It relies on |
322 // the internal implementation of the inline cost metrics rather than | 362 // the internal implementation of the inline cost metrics rather than |
323 // treating them as truly abstract units etc. | 363 // treating them as truly abstract units etc. |
324 if (Caller->hasLocalLinkage() || | 364 if (Caller->hasLocalLinkage() || Caller->hasLinkOnceODRLinkage()) { |
325 Caller->getLinkage() == GlobalValue::LinkOnceODRLinkage) { | |
326 int TotalSecondaryCost = 0; | 365 int TotalSecondaryCost = 0; |
327 // The candidate cost to be imposed upon the current function. | 366 // The candidate cost to be imposed upon the current function. |
328 int CandidateCost = IC.getCost() - (InlineConstants::CallPenalty + 1); | 367 int CandidateCost = IC.getCost() - (InlineConstants::CallPenalty + 1); |
329 // This bool tracks what happens if we do NOT inline C into B. | 368 // This bool tracks what happens if we do NOT inline C into B. |
330 bool callerWillBeRemoved = Caller->hasLocalLinkage(); | 369 bool callerWillBeRemoved = Caller->hasLocalLinkage(); |
331 // This bool tracks what happens if we DO inline C into B. | 370 // This bool tracks what happens if we DO inline C into B. |
332 bool inliningPreventsSomeOuterInline = false; | 371 bool inliningPreventsSomeOuterInline = false; |
333 for (Value::use_iterator I = Caller->use_begin(), E =Caller->use_end(); | 372 for (User *U : Caller->users()) { |
334 I != E; ++I) { | 373 CallSite CS2(U); |
335 CallSite CS2(*I); | |
336 | 374 |
337 // If this isn't a call to Caller (it could be some other sort | 375 // If this isn't a call to Caller (it could be some other sort |
338 // of reference) skip it. Such references will prevent the caller | 376 // of reference) skip it. Such references will prevent the caller |
339 // from being removed. | 377 // from being removed. |
340 if (!CS2 || CS2.getCalledFunction() != Caller) { | 378 if (!CS2 || CS2.getCalledFunction() != Caller) { |
361 } | 399 } |
362 // If all outer calls to Caller would get inlined, the cost for the last | 400 // If all outer calls to Caller would get inlined, the cost for the last |
363 // one is set very low by getInlineCost, in anticipation that Caller will | 401 // one is set very low by getInlineCost, in anticipation that Caller will |
364 // be removed entirely. We did not account for this above unless there | 402 // be removed entirely. We did not account for this above unless there |
365 // is only one caller of Caller. | 403 // is only one caller of Caller. |
366 if (callerWillBeRemoved && Caller->use_begin() != Caller->use_end()) | 404 if (callerWillBeRemoved && !Caller->use_empty()) |
367 TotalSecondaryCost += InlineConstants::LastCallToStaticBonus; | 405 TotalSecondaryCost += InlineConstants::LastCallToStaticBonus; |
368 | 406 |
369 if (inliningPreventsSomeOuterInline && TotalSecondaryCost < IC.getCost()) { | 407 if (inliningPreventsSomeOuterInline && TotalSecondaryCost < IC.getCost()) { |
370 DEBUG(dbgs() << " NOT Inlining: " << *CS.getInstruction() << | 408 DEBUG(dbgs() << " NOT Inlining: " << *CS.getInstruction() << |
371 " Cost = " << IC.getCost() << | 409 " Cost = " << IC.getCost() << |
372 ", outer Cost = " << TotalSecondaryCost << '\n'); | 410 ", outer Cost = " << TotalSecondaryCost << '\n'); |
411 emitAnalysis( | |
412 CS, Twine("Not inlining. Cost of inlining " + | |
413 CS.getCalledFunction()->getName() + | |
414 " increases the cost of inlining " + | |
415 CS.getCaller()->getName() + " in other contexts")); | |
373 return false; | 416 return false; |
374 } | 417 } |
375 } | 418 } |
376 | 419 |
377 DEBUG(dbgs() << " Inlining: cost=" << IC.getCost() | 420 DEBUG(dbgs() << " Inlining: cost=" << IC.getCost() |
378 << ", thres=" << (IC.getCostDelta() + IC.getCost()) | 421 << ", thres=" << (IC.getCostDelta() + IC.getCost()) |
379 << ", Call: " << *CS.getInstruction() << '\n'); | 422 << ", Call: " << *CS.getInstruction() << '\n'); |
423 emitAnalysis( | |
424 CS, CS.getCalledFunction()->getName() + Twine(" can be inlined into ") + | |
425 CS.getCaller()->getName() + " with cost=" + Twine(IC.getCost()) + | |
426 " (threshold=" + Twine(IC.getCostDelta() + IC.getCost()) + ")"); | |
380 return true; | 427 return true; |
381 } | 428 } |
382 | 429 |
383 /// InlineHistoryIncludes - Return true if the specified inline history ID | 430 /// InlineHistoryIncludes - Return true if the specified inline history ID |
384 /// indicates an inline history that includes the specified function. | 431 /// indicates an inline history that includes the specified function. |
394 return false; | 441 return false; |
395 } | 442 } |
396 | 443 |
397 bool Inliner::runOnSCC(CallGraphSCC &SCC) { | 444 bool Inliner::runOnSCC(CallGraphSCC &SCC) { |
398 CallGraph &CG = getAnalysis<CallGraphWrapperPass>().getCallGraph(); | 445 CallGraph &CG = getAnalysis<CallGraphWrapperPass>().getCallGraph(); |
399 const DataLayout *TD = getAnalysisIfAvailable<DataLayout>(); | 446 AssumptionTracker *AT = &getAnalysis<AssumptionTracker>(); |
447 DataLayoutPass *DLP = getAnalysisIfAvailable<DataLayoutPass>(); | |
448 const DataLayout *DL = DLP ? &DLP->getDataLayout() : nullptr; | |
400 const TargetLibraryInfo *TLI = getAnalysisIfAvailable<TargetLibraryInfo>(); | 449 const TargetLibraryInfo *TLI = getAnalysisIfAvailable<TargetLibraryInfo>(); |
450 AliasAnalysis *AA = &getAnalysis<AliasAnalysis>(); | |
401 | 451 |
402 SmallPtrSet<Function*, 8> SCCFunctions; | 452 SmallPtrSet<Function*, 8> SCCFunctions; |
403 DEBUG(dbgs() << "Inliner visiting SCC:"); | 453 DEBUG(dbgs() << "Inliner visiting SCC:"); |
404 for (CallGraphSCC::iterator I = SCC.begin(), E = SCC.end(); I != E; ++I) { | 454 for (CallGraphSCC::iterator I = SCC.begin(), E = SCC.end(); I != E; ++I) { |
405 Function *F = (*I)->getFunction(); | 455 Function *F = (*I)->getFunction(); |
454 if (SCCFunctions.count(F)) | 504 if (SCCFunctions.count(F)) |
455 std::swap(CallSites[i--], CallSites[--FirstCallInSCC]); | 505 std::swap(CallSites[i--], CallSites[--FirstCallInSCC]); |
456 | 506 |
457 | 507 |
458 InlinedArrayAllocasTy InlinedArrayAllocas; | 508 InlinedArrayAllocasTy InlinedArrayAllocas; |
459 InlineFunctionInfo InlineInfo(&CG, TD); | 509 InlineFunctionInfo InlineInfo(&CG, DL, AA, AT); |
460 | 510 |
461 // Now that we have all of the call sites, loop over them and inline them if | 511 // Now that we have all of the call sites, loop over them and inline them if |
462 // it looks profitable to do so. | 512 // it looks profitable to do so. |
463 bool Changed = false; | 513 bool Changed = false; |
464 bool LocalChange; | 514 bool LocalChange; |
483 CG[Caller]->removeCallEdgeFor(CS); | 533 CG[Caller]->removeCallEdgeFor(CS); |
484 CS.getInstruction()->eraseFromParent(); | 534 CS.getInstruction()->eraseFromParent(); |
485 ++NumCallsDeleted; | 535 ++NumCallsDeleted; |
486 } else { | 536 } else { |
487 // We can only inline direct calls to non-declarations. | 537 // We can only inline direct calls to non-declarations. |
488 if (Callee == 0 || Callee->isDeclaration()) continue; | 538 if (!Callee || Callee->isDeclaration()) continue; |
489 | 539 |
490 // If this call site was obtained by inlining another function, verify | 540 // If this call site was obtained by inlining another function, verify |
491 // that the include path for the function did not include the callee | 541 // that the include path for the function did not include the callee |
492 // itself. If so, we'd be recursively inlining the same function, | 542 // itself. If so, we'd be recursively inlining the same function, |
493 // which would provide the same callsites, which would cause us to | 543 // which would provide the same callsites, which would cause us to |
495 int InlineHistoryID = CallSites[CSi].second; | 545 int InlineHistoryID = CallSites[CSi].second; |
496 if (InlineHistoryID != -1 && | 546 if (InlineHistoryID != -1 && |
497 InlineHistoryIncludes(Callee, InlineHistoryID, InlineHistory)) | 547 InlineHistoryIncludes(Callee, InlineHistoryID, InlineHistory)) |
498 continue; | 548 continue; |
499 | 549 |
500 | 550 LLVMContext &CallerCtx = Caller->getContext(); |
551 | |
552 // Get DebugLoc to report. CS will be invalid after Inliner. | |
553 DebugLoc DLoc = CS.getInstruction()->getDebugLoc(); | |
554 | |
501 // If the policy determines that we should inline this function, | 555 // If the policy determines that we should inline this function, |
502 // try to do so. | 556 // try to do so. |
503 if (!shouldInline(CS)) | 557 if (!shouldInline(CS)) { |
558 emitOptimizationRemarkMissed(CallerCtx, DEBUG_TYPE, *Caller, DLoc, | |
559 Twine(Callee->getName() + | |
560 " will not be inlined into " + | |
561 Caller->getName())); | |
504 continue; | 562 continue; |
563 } | |
505 | 564 |
506 // Attempt to inline the function. | 565 // Attempt to inline the function. |
507 if (!InlineCallIfPossible(CS, InlineInfo, InlinedArrayAllocas, | 566 if (!InlineCallIfPossible(CS, InlineInfo, InlinedArrayAllocas, |
508 InlineHistoryID, InsertLifetime, TD)) | 567 InlineHistoryID, InsertLifetime, DL)) { |
568 emitOptimizationRemarkMissed(CallerCtx, DEBUG_TYPE, *Caller, DLoc, | |
569 Twine(Callee->getName() + | |
570 " will not be inlined into " + | |
571 Caller->getName())); | |
509 continue; | 572 continue; |
573 } | |
510 ++NumInlined; | 574 ++NumInlined; |
511 | 575 |
576 // Report the inline decision. | |
577 emitOptimizationRemark( | |
578 CallerCtx, DEBUG_TYPE, *Caller, DLoc, | |
579 Twine(Callee->getName() + " inlined into " + Caller->getName())); | |
580 | |
512 // If inlining this function gave us any new call sites, throw them | 581 // If inlining this function gave us any new call sites, throw them |
513 // onto our worklist to process. They are useful inline candidates. | 582 // onto our worklist to process. They are useful inline candidates. |
514 if (!InlineInfo.InlinedCalls.empty()) { | 583 if (!InlineInfo.InlinedCalls.empty()) { |
515 // Create a new inline history entry for this, so that we remember | 584 // Create a new inline history entry for this, so that we remember |
516 // that these new callsites came about due to inlining Callee. | 585 // that these new callsites came about due to inlining Callee. |