Initialize.
[oota-llvm.git] / lib / Transforms / IPO / InlineSimple.cpp
index eea28a745c57902a637e9fe7b92c20312da8222f..fe0ea5a4e89e8cee4d49fac90f6547d09e433135 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
 #include "llvm/Transforms/IPO.h"
 #include "llvm/Transforms/IPO/InlinerPass.h"
 #include "llvm/Transforms/Utils/InlineCost.h"
-#include <set>
+#include "llvm/ADT/SmallPtrSet.h"
 
 using namespace llvm;
 
 namespace {
 
   class VISIBILITY_HIDDEN SimpleInliner : public Inliner {
-    std::set<const Function*> NeverInline; // Functions that are never inlined
+    // Functions that are never inlined
+    SmallPtrSet<const Function*, 16> NeverInline; 
     InlineCostAnalyzer CA;
   public:
     SimpleInliner() : Inliner(&ID) {}
+    SimpleInliner(int Threshold) : Inliner(&ID, Threshold) {}
     static char ID; // Pass identification, replacement for typeid
     int getInlineCost(CallSite CS) {
       return CA.getInlineCost(CS, NeverInline);
@@ -46,6 +48,10 @@ namespace {
 
 Pass *llvm::createFunctionInliningPass() { return new SimpleInliner(); }
 
+Pass *llvm::createFunctionInliningPass(int Threshold) { 
+  return new SimpleInliner(Threshold);
+}
+
 // doInitialization - Initializes the vector of functions that have been
 // annotated with the noinline attribute.
 bool SimpleInliner::doInitialization(CallGraph &CG) {
@@ -58,6 +64,10 @@ bool SimpleInliner::doInitialization(CallGraph &CG) {
   if (GV == 0)
     return false;
 
+  // Don't crash on invalid code
+  if (!GV->hasInitializer())
+    return false;
+  
   const ConstantArray *InitList = dyn_cast<ConstantArray>(GV->getInitializer());
   
   if (InitList == 0)