Add missing newlines at EOF (for clang++).
[oota-llvm.git] / lib / Transforms / Utils / BasicInliner.cpp
index 5c2c6989b71611d5dfe267ca68d52fa4d0a3562b..b5ffe0606504ae41275fd1d09af4ae1089aad340 100644 (file)
@@ -13,7 +13,6 @@
 //===----------------------------------------------------------------------===//
 
 #define DEBUG_TYPE "basicinliner"
-
 #include "llvm/Module.h"
 #include "llvm/Function.h"
 #include "llvm/Transforms/Utils/BasicInliner.h"
 #include "llvm/Support/CallSite.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include <vector>
 
 using namespace llvm;
 
 static cl::opt<unsigned>     
-BasicInlineThreshold("inline-threshold", cl::Hidden, cl::init(200),
-                     cl::desc("Control the amount of basic inlining to perform (default = 200)"));
+BasicInlineThreshold("basic-inline-threshold", cl::Hidden, cl::init(200),
+   cl::desc("Control the amount of basic inlining to perform (default = 200)"));
 
 namespace llvm {
 
   /// BasicInlinerImpl - BasicInliner implemantation class. This hides
   /// container info, used by basic inliner, from public interface.
-  struct VISIBILITY_HIDDEN BasicInlinerImpl {
+  struct BasicInlinerImpl {
     
     BasicInlinerImpl(const BasicInlinerImpl&); // DO NOT IMPLEMENT
     void operator=(const BasicInlinerImpl&); // DO NO IMPLEMENT
@@ -89,37 +89,50 @@ void BasicInlinerImpl::inlineFunctions() {
       }
   }
   
-  DOUT << ": " << CallSites.size() << " call sites.\n";
+  DEBUG(errs() << ": " << CallSites.size() << " call sites.\n");
   
   // Inline call sites.
   bool Changed = false;
   do {
     Changed = false;
-    for (unsigned index = 0; index != CallSites.size() && !CallSites.empty(); ++index) {
+    for (unsigned index = 0; index != CallSites.size() && !CallSites.empty(); 
+         ++index) {
       CallSite CS = CallSites[index];
       if (Function *Callee = CS.getCalledFunction()) {
         
-        // Eliminate calls taht are never inlinable.
+        // Eliminate calls that are never inlinable.
         if (Callee->isDeclaration() ||
             CS.getInstruction()->getParent()->getParent() == Callee) {
           CallSites.erase(CallSites.begin() + index);
-              --index;
-              continue;
+          --index;
+          continue;
         }
-        int InlineCost = CA.getInlineCost(CS, NeverInline);
-        if (InlineCost >= (int) BasicInlineThreshold) {
-              DOUT << "  NOT Inlining: cost = " << InlineCost
-                   << ", call: " <<  *CS.getInstruction();
-              continue;
+        InlineCost IC = CA.getInlineCost(CS, NeverInline);
+        if (IC.isAlways()) {        
+          DEBUG(errs() << "  Inlining: cost=always"
+                       <<", call: " << *CS.getInstruction());
+        } else if (IC.isNever()) {
+          DEBUG(errs() << "  NOT Inlining: cost=never"
+                       <<", call: " << *CS.getInstruction());
+          continue;
+        } else {
+          int Cost = IC.getValue();
+          
+          if (Cost >= (int) BasicInlineThreshold) {
+            DEBUG(errs() << "  NOT Inlining: cost = " << Cost
+                         << ", call: " <<  *CS.getInstruction());
+            continue;
+          } else {
+            DEBUG(errs() << "  Inlining: cost = " << Cost
+                         << ", call: " <<  *CS.getInstruction());
+          }
         }
         
-        DOUT << "  Inlining: cost=" << InlineCost
-             <<", call: " << *CS.getInstruction();
-        
         // Inline
         if (InlineFunction(CS, NULL, TD)) {
-          if (Callee->use_empty() && Callee->hasInternalLinkage())
-                DeadFunctions.insert(Callee);
+          if (Callee->use_empty() && (Callee->hasLocalLinkage() ||
+                                      Callee->hasAvailableExternallyLinkage()))
+            DeadFunctions.insert(Callee);
           Changed = true;
           CallSites.erase(CallSites.begin() + index);
           --index;