changeset 1171:461a85f0db31

Change meaning of optimization levels: -O0 now means 'no optimization' like with other compilers.
author Frits van Bommel <fvbommel wxs.nl>
date Sun, 29 Mar 2009 15:51:14 +0200
parents e40c65bd8c5d
children b3887714b735
files gen/linker.cpp gen/optimizer.cpp
diffstat 2 files changed, 9 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/gen/linker.cpp	Sun Mar 29 15:46:55 2009 +0200
+++ b/gen/linker.cpp	Sun Mar 29 15:51:14 2009 +0200
@@ -121,9 +121,9 @@
         {
         case 0:
             args.push_back("-disable-opt");
-            args.push_back("-globaldce");
             break;
         case 1:
+            args.push_back("-globaldce");
             args.push_back("-disable-opt");
             args.push_back("-globaldce");
             args.push_back("-mem2reg");
--- a/gen/optimizer.cpp	Sun Mar 29 15:46:55 2009 +0200
+++ b/gen/optimizer.cpp	Sun Mar 29 15:51:14 2009 +0200
@@ -24,14 +24,14 @@
     cl::ZeroOrMore,
     cl::values(
         clEnumValN(2, "O",  "Equivalent to -O2"),
-        clEnumValN(0, "O0", "Trivial optimizations only"),
+        clEnumValN(0, "O0", "No optimizations (default)"),
         clEnumValN(1, "O1", "Simple optimizations"),
         clEnumValN(2, "O2", "Good optimizations"),
         clEnumValN(3, "O3", "Aggressive optimizations"),
         clEnumValN(4, "O4", "Link-time optimization"), //  not implemented?
         clEnumValN(5, "O5", "Link-time optimization"), //  not implemented?
         clEnumValEnd),
-    cl::init(-1));
+    cl::init(0));
 
 static cl::opt<bool> enableInlining("enable-inlining",
     cl::desc("Enable function inlining (in -O<N>, if given)"),
@@ -48,22 +48,17 @@
 }
 
 bool optimize() {
-    return (optimizeLevel != -1) || enableInlining || passList.empty();
+    return optimizeLevel || enableInlining || passList.empty();
 }
 
 // this function inserts some or all of the std-compile-opts passes depending on the
 // optimization level given.
 static void addPassesForOptLevel(PassManager& pm) {
-    // -O0
-    if (optimizeLevel >= 0)
+    // -O1
+    if (optimizeLevel >= 1)
     {
         //pm.add(createStripDeadPrototypesPass());
         pm.add(createGlobalDCEPass());
-    }
-
-    // -O1
-    if (optimizeLevel >= 1)
-    {
         pm.add(createRaiseAllocationsPass());
         pm.add(createCFGSimplificationPass());
         pm.add(createPromoteMemoryToRegisterPass());
@@ -129,15 +124,15 @@
 // Returns true if any optimization passes were invoked.
 bool ldc_optimize_module(llvm::Module* m)
 {
-    if (!enableInlining && optimizeLevel == -1 && passList.empty())
+    if (!enableInlining && optimizeLevel == 0 && passList.empty())
         return false;
 
     PassManager pm;
     pm.add(new TargetData(m));
 
-    bool optimize = (optimizeLevel != -1) || enableInlining;
+    bool optimize = optimizeLevel != 0 || enableInlining;
 
-    unsigned optPos = optimizeLevel != -1
+    unsigned optPos = optimizeLevel != 0
                     ? optimizeLevel.getPosition()
                     : enableInlining.getPosition();