diff gen/optimizer.cpp @ 1275:bedf0bfb8fdb

Implement first D-specific optimization pass: -simplify-drtcalls. It uses the machinery of the standard -simplify-libcalls pass, but optimizes calls to the D runtime instead of calls to C libraries. At the moment, these optimizations are implemented by this pass: - Avoid the runtime call for `arr.length = newlen` if it can determine that the new length isn't longer than the old one. - Ditto for `cast(T[]) arr` if it will clearly always succeed. (e.g. if the length of the original array is zero, or if the old element size is a multiple of the new element size)
author Frits van Bommel <fvbommel wxs.nl>
date Tue, 28 Apr 2009 21:58:06 +0200
parents 4ae3b3ceea11
children 29d3861aa2da
line wrap: on
line diff
--- a/gen/optimizer.cpp	Mon Apr 27 22:34:36 2009 +0200
+++ b/gen/optimizer.cpp	Tue Apr 28 21:58:06 2009 +0200
@@ -1,6 +1,8 @@
 #include "gen/optimizer.h"
 #include "gen/cl_helpers.h"
 
+#include "gen/passes/Passes.h"
+
 #include "llvm/PassManager.h"
 #include "llvm/LinkAllPasses.h"
 #include "llvm/Analysis/LoopPass.h"
@@ -33,9 +35,19 @@
         clEnumValEnd),
     cl::init(0));
 
+static cl::opt<bool>
+disableLangSpecificPasses("disable-d-passes",
+    cl::desc("Disable D-specific passes in -O<N>"),
+    cl::ZeroOrMore);
+
+static cl::opt<bool>
+disableSimplifyRuntimeCalls("disable-simplify-drtcalls",
+    cl::desc("Disable simplification of runtime calls in -O<N>"),
+    cl::ZeroOrMore);
+
 static cl::opt<opts::BoolOrDefaultAdapter, false, opts::FlagParser>
 enableInlining("inlining",
-    cl::desc("(*) Enable function inlining (in -O<N>, if given)"),
+    cl::desc("(*) Enable function inlining in -O<N>"),
     cl::ZeroOrMore);
 
 // Determine whether or not to run the inliner as part of the default list of
@@ -103,6 +115,11 @@
         }
     }
 
+    if (optimizeLevel >= 2 && !disableLangSpecificPasses
+            && !disableSimplifyRuntimeCalls) {
+        pm.add(createSimplifyDRuntimeCalls());
+    }
+
     // -O3
     if (optimizeLevel >= 3)
     {