diff --git a/lib/Transforms/IPO/Inliner.cpp b/lib/Transforms/IPO/Inliner.cpp index 6c7a1914a95..8ad72ab9a17 100644 --- a/lib/Transforms/IPO/Inliner.cpp +++ b/lib/Transforms/IPO/Inliner.cpp @@ -64,10 +64,13 @@ bool Inliner::runOnSCC(const std::vector &SCC) { if (isa(I) || isa(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) : diff --git a/lib/Transforms/IPO/Inliner.h b/lib/Transforms/IPO/Inliner.h index 2f770bfd55d..1f3d0d2dc22 100644 --- a/lib/Transforms/IPO/Inliner.h +++ b/lib/Transforms/IPO/Inliner.h @@ -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 IsRecursiveFunction; + bool performInlining(CallSite CS, std::set &SCC); };