fix PR5009 by making CGSCCPM realize that a call was devirtualized
[oota-llvm.git] / lib / Analysis / InlineCost.cpp
index 50400d3085d91514099b239b4f8257ff8022d86c..b478b503ba99dde8b7d8288254417fa53e9e83d7 100644 (file)
@@ -159,10 +159,18 @@ void CodeMetrics::analyzeBasicBlock(const BasicBlock *BB) {
       // 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 (Function *F = CS.getCalledFunction()) {
         if (F->isDeclaration() && 
             (F->getName() == "setjmp" || F->getName() == "_setjmp"))
           NeverInline = true;
+       
+        // If this call is to function itself, then the function is recursive.
+        // Inlining it into other functions is a bad idea, because this is
+        // basically just a form of loop peeling, and our metrics aren't useful
+        // for that case.
+        if (F == BB->getParent())
+          NeverInline = true;
+      }
 
       if (!isa<IntrinsicInst>(II) && !callIsSmall(CS.getCalledFunction())) {
         // Each argument to a call takes on average one instruction to set up.
@@ -263,13 +271,6 @@ InlineCost InlineCostAnalyzer::getInlineCost(CallSite CS,
       CS.isNoInline())
     return llvm::InlineCost::getNever();
 
-  // Don't inline directly recursive calls, for now. Inlining a directly
-  // recursive call is effectively unrolling a loop, so it calls for different
-  // heuristics, which aren't implemented yet. Until then, err on the
-  // conservative side.
-  if (Callee == Caller)
-    return llvm::InlineCost::getNever();
-
   // InlineCost - This value measures how good of an inline candidate this call
   // site is to inline.  A lower inline cost make is more likely for the call to
   // be inlined.  This value may go negative.