From 46868c07bb2312c271310942f2a37591570125da Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 14 Jul 2008 17:32:59 +0000 Subject: [PATCH] Reapply r53540, now with the matching header! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53557 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Transforms/Utils/InlineCost.h | 7 ++++++- lib/Transforms/Utils/InlineCost.cpp | 24 +++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/include/llvm/Transforms/Utils/InlineCost.h b/include/llvm/Transforms/Utils/InlineCost.h index 24d3fc7523d..9e044d83f9e 100644 --- a/include/llvm/Transforms/Utils/InlineCost.h +++ b/include/llvm/Transforms/Utils/InlineCost.h @@ -38,6 +38,10 @@ namespace llvm { // FunctionInfo - For each function, calculate the size of it in blocks and // instructions. struct FunctionInfo { + /// NeverInline - True if this callee should never be inlined into a + /// caller. + bool NeverInline; + /// NumInsts, NumBlocks - Keep track of how large each function is, which /// is used to estimate the code size cost of inlining it. unsigned NumInsts, NumBlocks; @@ -53,7 +57,8 @@ namespace llvm { /// entry here. std::vector ArgumentWeights; - FunctionInfo() : NumInsts(0), NumBlocks(0), NumVectorInsts(0) {} + FunctionInfo() : NeverInline(false), NumInsts(0), NumBlocks(0), + NumVectorInsts(0) {} /// analyzeFunction - Fill in the current structure with information /// gleaned from the specified function. diff --git a/lib/Transforms/Utils/InlineCost.cpp b/lib/Transforms/Utils/InlineCost.cpp index c17705bf850..10cb77bbcba 100644 --- a/lib/Transforms/Utils/InlineCost.cpp +++ b/lib/Transforms/Utils/InlineCost.cpp @@ -100,9 +100,27 @@ void InlineCostAnalyzer::FunctionInfo::analyzeFunction(Function *F) { for (Function::const_iterator BB = F->begin(), E = F->end(); BB != E; ++BB) { for (BasicBlock::const_iterator II = BB->begin(), E = BB->end(); II != E; ++II) { - if (isa(II)) continue; // Debug intrinsics don't count. if (isa(II)) continue; // PHI nodes don't count. + // Special handling for calls. + if (isa(II) || isa(II)) { + if (isa(II)) + continue; // Debug intrinsics don't count as size. + + CallSite CS = CallSite::get(const_cast(&*II)); + + // If this function contains a call to setjmp or _setjmp, never inline + // it. This is a hack because we depend on the user marking their local + // variables as volatile if they are live across a setjmp call, and they + // probably won't do this in callers. + if (Function *F = CS.getCalledFunction()) + if (F->isDeclaration() && + (F->isName("setjmp") || F->isName("_setjmp"))) { + NeverInline = true; + return; + } + } + if (isa(II) || isa(II->getType())) ++NumVectorInsts; @@ -194,6 +212,10 @@ int InlineCostAnalyzer::getInlineCost(CallSite CS, // If we haven't calculated this information yet, do so now. if (CalleeFI.NumBlocks == 0) CalleeFI.analyzeFunction(Callee); + + // If we should never inline this, return a huge cost. + if (CalleeFI.NeverInline) + return 2000000000; // Add to the inline quality for properties that make the call valuable to // inline. This includes factors that indicate that the result of inlining