Permit inlining functions that contain dynamic allocations now that
authorChris Lattner <sabre@nondot.org>
Fri, 13 Jan 2006 19:35:43 +0000 (19:35 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 13 Jan 2006 19:35:43 +0000 (19:35 +0000)
InlineFunction handles this case safely.  This implements
Transforms/Inline/dynamic_alloca_test.ll.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25288 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/IPO/InlineSimple.cpp

index 0d579bc1ff334c2acdd7def03541a77deb191efd..4a41bb6af5dc1dff866ddab99845cf81b479f35e 100644 (file)
@@ -33,16 +33,6 @@ namespace {
   // FunctionInfo - For each function, calculate the size of it in blocks and
   // instructions.
   struct FunctionInfo {
-    // HasAllocas - Keep track of whether or not a function contains an alloca
-    // instruction that is not in the entry block of the function.  Inlining
-    // this call could cause us to blow out the stack, because the stack memory
-    // would never be released.
-    //
-    // FIXME: LLVM needs a way of dealloca'ing memory, which would make this
-    // irrelevant!
-    //
-    bool HasAllocas;
-
     // 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 +43,7 @@ namespace {
     // entry here.
     std::vector<ArgInfo> ArgumentWeights;
 
-    FunctionInfo() : HasAllocas(false), NumInsts(0), NumBlocks(0) {}
+    FunctionInfo() : NumInsts(0), NumBlocks(0) {}
 
     /// analyzeFunction - Fill in the current structure with information gleaned
     /// from the specified function.
@@ -148,17 +138,9 @@ void FunctionInfo::analyzeFunction(Function *F) {
   // each instruction counts as 10.
   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)) ++NumInsts;
-
-      // If there is an alloca in the body of the function, we cannot currently
-      // inline the function without the risk of exploding the stack.
-      if (isa<AllocaInst>(II) && BB != F->begin()) {
-        HasAllocas = true;
-        this->NumBlocks = this->NumInsts = 1;
-        return;
-      }
-    }
+         II != E; ++II)
+      if (!isa<DbgInfoIntrinsic>(II)) 
+        ++NumInsts;
 
     ++NumBlocks;
   }
@@ -218,11 +200,6 @@ int SimpleInliner::getInlineCost(CallSite CS) {
   if (CalleeFI.NumBlocks == 0)
     CalleeFI.analyzeFunction(Callee);
 
-  // Don't inline calls to functions with allocas that are not in the entry
-  // block of the function.
-  if (CalleeFI.HasAllocas)
-    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
   // the function will be optimizable.  Currently this just looks at arguments