Do NOT inline self recursive calls into other functions. This is causing the
authorChris Lattner <sabre@nondot.org>
Sun, 9 Nov 2003 05:05:36 +0000 (05:05 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 9 Nov 2003 05:05:36 +0000 (05:05 +0000)
pool allocator no end of trouble, and doesn't make a lot of sense anyway.  This
does not solve the problem with mutually recursive functions, but they are much less common.

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

lib/Transforms/IPO/Inliner.cpp
lib/Transforms/IPO/Inliner.h

index 6c7a1914a958fc08a5c1fc7dca9a97b8b010fc57..8ad72ab9a1702e71c5537588968c883ca48cec9e 100644 (file)
@@ -64,10 +64,13 @@ bool Inliner::runOnSCC(const std::vector<CallGraphNode*> &SCC) {
         if (isa<CallInst>(I) || isa<InvokeInst>(I)) {
           CallSite CS = CallSite::get(I);
           if (Function *Callee = CS.getCalledFunction())
-            if (!Callee->isExternal()) {
+            if (!Callee->isExternal() && !IsRecursiveFunction.count(Callee)) {
               // Determine whether this is a function IN the SCC...
               bool inSCC = SCCFunctions.count(Callee);
 
+              // Keep track of whether this is a directly recursive function.
+              if (Callee == F) IsRecursiveFunction.insert(F);
+
               // If the policy determines that we should inline this function,
               // try to do so...
               int InlineCost = inSCC ? getRecursiveInlineCost(CS) :
index 2f770bfd55d6ffb82246c87c88bf1f533874b2e8..1f3d0d2dc22d24b9be7fcf49e24b669fcaa92ad1 100644 (file)
@@ -51,7 +51,13 @@ struct Inliner : public CallGraphSCCPass {
   virtual int getRecursiveInlineCost(CallSite CS);
 
 private:
+  // InlineThreshold - Cache the value here for easy access.
   unsigned InlineThreshold;
+
+  // IsRecursiveFunction - This contains all functions which are directly
+  // recursive, which we do NOT want to inline into other functions.
+  std::set<Function*> IsRecursiveFunction;
+
   bool performInlining(CallSite CS, std::set<Function*> &SCC);
 };