fix infinite recursion if a global's initializer references the global
[oota-llvm.git] / tools / lto2 / LTOCodeGenerator.cpp
index db27145bbf9e3b0549e06579e0fbc16cf97dc381..13ba0db0f6da2a0f2f6417a522efb3d69abc97dd 100644 (file)
@@ -340,6 +340,11 @@ bool LTOCodeGenerator::generateAssemblyCode(std::ostream& out, std::string& errM
     // Add an appropriate TargetData instance for this module...
     passes.add(new TargetData(*_target->getTargetData()));
     
+    // Propagate constants at call sites into the functions they call.  This
+    // opens opportunities for globalopt (and inlining) by substituting function
+    // pointers passed as arguments to direct uses of functions.  
+    passes.add(createIPSCCPPass());
+
     // Now that we internalized some globals, see if we can hack on them!
     passes.add(createGlobalOptimizerPass());
 
@@ -352,12 +357,15 @@ bool LTOCodeGenerator::generateAssemblyCode(std::ostream& out, std::string& errM
     // supporting.
     passes.add(createStripSymbolsPass());
     
-    // Propagate constants at call sites into the functions they call.
-    passes.add(createIPConstantPropagationPass());
-
     // Remove unused arguments from functions...
     passes.add(createDeadArgEliminationPass());
 
+    // Reduce the code after globalopt and ipsccp.  Both can open up significant
+    // simplification opportunities, and both can propagate functions through
+    // function pointers.  When this happens, we often have to resolve varargs
+    // calls, etc, so let instcombine do this.
+    passes.add(createInstructionCombiningPass());
+
     passes.add(createFunctionInliningPass()); // Inline small functions
 
     passes.add(createPruneEHPass());            // Remove dead EH info
@@ -378,6 +386,7 @@ bool LTOCodeGenerator::generateAssemblyCode(std::ostream& out, std::string& errM
 
     passes.add(createLICMPass());               // Hoist loop invariants
     passes.add(createGVNPass());               // Remove common subexprs
+    passes.add(createMemCpyOptPass());  // Remove dead memcpy's
     passes.add(createDeadStoreEliminationPass()); // Nuke dead stores
 
     // Cleanup and simplify the code after the scalar optimizations.