diff gen/optimizer.cpp @ 1482:d9c5f5a43403

Run `semantic3` on imported modules, and emit new symbols with `available_externally` linkage. This allows the inliner to inline functions from other modules while telling the code generator to ignore those functions (treat them as declarations) Still generates a few extra `TypeInfo`s and strings... Disabled when generating debug info because I don't really understand it, and it doesn't like this.
author Frits van Bommel <fvbommel wxs.nl>
date Sun, 07 Jun 2009 16:00:13 +0200
parents e0f03e11cdf8
children defafbabbe32
line wrap: on
line diff
--- a/gen/optimizer.cpp	Sun Jun 07 15:07:29 2009 +0200
+++ b/gen/optimizer.cpp	Sun Jun 07 16:00:13 2009 +0200
@@ -12,6 +12,7 @@
 #include "llvm/Support/PassNameParser.h"
 
 #include "root.h"       // error()
+#include <cstring>      // strcmp();
 
 using namespace llvm;
 
@@ -78,6 +79,19 @@
         || (enableInlining == cl::BOU_UNSET && optimizeLevel >= 3);
 }
 
+// Determine whether the inliner will be run.
+bool willInline() {
+    if (doInline())
+        return true;
+    // It may also have been specified explicitly on the command line as an explicit pass
+    typedef cl::list<const PassInfo*, bool, PassNameParser> PL;
+    for (PL::iterator I = passList.begin(), E = passList.end(); I != E; ++I) {
+        if (!std::strcmp((*I)->getPassArgument(), "inline"))
+            return true;
+    }
+    return false;
+}
+
 // Some extra accessors for the linker: (llvm-ld version only, currently unused?)
 int optLevel() {
     return optimizeLevel;
@@ -108,7 +122,6 @@
         else
             addPass(pm, createScalarReplAggregatesPass());
         addPass(pm, createGlobalOptimizerPass());
-        addPass(pm, createGlobalDCEPass());
     }
 
     // -O2
@@ -208,6 +221,10 @@
         addPass(pm, createConstantMergePass());
     }
 
+    if (optimizeLevel >= 1) {
+        addPass(pm, createGlobalDCEPass());
+    }
+
     // level -O4 and -O5 are linktime optimizations
 }