mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-01-11 18:33:14 +01:00
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)
This commit is contained in:
@@ -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 @@ static cl::opt<char> optimizeLevel(
|
||||
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 @@ static void addPassesForOptLevel(PassManager& pm) {
|
||||
}
|
||||
}
|
||||
|
||||
if (optimizeLevel >= 2 && !disableLangSpecificPasses
|
||||
&& !disableSimplifyRuntimeCalls) {
|
||||
pm.add(createSimplifyDRuntimeCalls());
|
||||
}
|
||||
|
||||
// -O3
|
||||
if (optimizeLevel >= 3)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user