summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-07-14 00:46:56 +0000
committerChris Lattner <sabre@nondot.org>2008-07-14 00:46:56 +0000
commitac77bfdbd4d83edbc17c9fd362b5d692cbbeff40 (patch)
tree0e02698aea676d215294d39ea77881992112dbc2 /lib
parent4238453135ed5808b4515f516ed7ccd1fe8a5750 (diff)
downloadllvm-ac77bfdbd4d83edbc17c9fd362b5d692cbbeff40.tar.gz
llvm-ac77bfdbd4d83edbc17c9fd362b5d692cbbeff40.tar.bz2
llvm-ac77bfdbd4d83edbc17c9fd362b5d692cbbeff40.tar.xz
If a function calls setjmp, never inline it into other functions. This is
a hack around the fact that we don't represent the CFG correctly for sj/lj. It fixes PR2486. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53540 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Transforms/Utils/InlineCost.cpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/lib/Transforms/Utils/InlineCost.cpp b/lib/Transforms/Utils/InlineCost.cpp
index c17705bf85..10cb77bbcb 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<DbgInfoIntrinsic>(II)) continue; // Debug intrinsics don't count.
if (isa<PHINode>(II)) continue; // PHI nodes don't count.
+ // Special handling for calls.
+ if (isa<CallInst>(II) || isa<InvokeInst>(II)) {
+ if (isa<DbgInfoIntrinsic>(II))
+ continue; // Debug intrinsics don't count as size.
+
+ CallSite CS = CallSite::get(const_cast<Instruction*>(&*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<ExtractElementInst>(II) || isa<VectorType>(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