summaryrefslogtreecommitdiff
path: root/lib/Transforms/Utils/InlineFunction.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-01-13 19:34:14 +0000
committerChris Lattner <sabre@nondot.org>2006-01-13 19:34:14 +0000
commitbf229f488a7541abd979cc3fbe9c3ce1c100e5c0 (patch)
tree4a62a4a4419311a730b6b40243efc06065dad404 /lib/Transforms/Utils/InlineFunction.cpp
parent1fdf4a859f03ce5aa4ce9acba29ce321c847388e (diff)
downloadllvm-bf229f488a7541abd979cc3fbe9c3ce1c100e5c0.tar.gz
llvm-bf229f488a7541abd979cc3fbe9c3ce1c100e5c0.tar.bz2
llvm-bf229f488a7541abd979cc3fbe9c3ce1c100e5c0.tar.xz
If inlining a call to a function that contains dynamic allocas, wrap the
resultant code with llvm.stacksave/llvm.stackrestore intrinsics. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25286 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils/InlineFunction.cpp')
-rw-r--r--lib/Transforms/Utils/InlineFunction.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/Transforms/Utils/InlineFunction.cpp b/lib/Transforms/Utils/InlineFunction.cpp
index 1b08694ac3..0c2be0f7f6 100644
--- a/lib/Transforms/Utils/InlineFunction.cpp
+++ b/lib/Transforms/Utils/InlineFunction.cpp
@@ -215,6 +215,36 @@ bool llvm::InlineFunction(CallSite CS) {
}
}
+ // If the inlined code contained dynamic alloca instructions, wrap the inlined
+ // code with llvm.stacksave/llvm.stackrestore intrinsics.
+ if (InlinedFunctionInfo.ContainsDynamicAllocas) {
+ Module *M = Caller->getParent();
+ const Type *SBytePtr = PointerType::get(Type::SByteTy);
+ // Get the two intrinsics we care about.
+ Function *StackSave, *StackRestore;
+ StackSave = M->getOrInsertFunction("llvm.stacksave", SBytePtr, NULL);
+ StackRestore = M->getOrInsertFunction("llvm.stackrestore", Type::VoidTy,
+ SBytePtr, NULL);
+
+ // Insert the llvm.stacksave.
+ Value *SavedPtr = new CallInst(StackSave, "savedstack",
+ FirstNewBlock->begin());
+
+ // Insert a call to llvm.stackrestore before any return instructions in the
+ // inlined function.
+ for (unsigned i = 0, e = Returns.size(); i != e; ++i)
+ new CallInst(StackRestore, SavedPtr, "", Returns[i]);
+
+ // If we are inlining an invoke instruction, insert restores before each
+ // unwind. These unwinds will be rewritten into branches later.
+ if (InlinedFunctionInfo.ContainsUnwinds && isa<InvokeInst>(TheCall)) {
+ for (Function::iterator BB = FirstNewBlock, E = Caller->end();
+ BB != E; ++BB)
+ if (UnwindInst *UI = dyn_cast<UnwindInst>(BB->getTerminator()))
+ new CallInst(StackRestore, SavedPtr, "", UI);
+ }
+ }
+
// If we are inlining tail call instruction through a call site that isn't
// marked 'tail', we must remove the tail marker for any calls in the inlined
// code.