Mercurial > projects > ldc
diff gen/optimizer.cpp @ 1285:91d9386d4a5a
Implement another D-specific pass: -dgc2stack
This one promotes GC allocations to stack memory when it can determine it's safe
to do so.
Not all GC calls are recognized yet (in fact only one *is* recognized for now).
Needs metadata, so disabled for LLVM versions that don't support it.
author | Frits van Bommel <fvbommel wxs.nl> |
---|---|
date | Sat, 02 May 2009 11:58:50 +0200 |
parents | 29d3861aa2da |
children | 6c8af78364f5 |
line wrap: on
line diff
--- a/gen/optimizer.cpp Sat May 02 11:58:50 2009 +0200 +++ b/gen/optimizer.cpp Sat May 02 11:58:50 2009 +0200 @@ -45,6 +45,11 @@ cl::desc("Disable simplification of runtime calls in -O<N>"), cl::ZeroOrMore); +static cl::opt<bool> +disableGCToStack("disable-gc2stack", + cl::desc("Disable promotion of GC allocations to stack memory in -O<N>"), + cl::ZeroOrMore); + static cl::opt<opts::BoolOrDefaultAdapter, false, opts::FlagParser> enableInlining("inlining", cl::desc("(*) Enable function inlining in -O<N>"), @@ -93,6 +98,8 @@ pm.add(createInstructionCombiningPass()); pm.add(createCFGSimplificationPass()); pm.add(createPruneEHPass()); + if (!disableLangSpecificPasses && !disableGCToStack) + pm.add(createGarbageCollect2Stack()); } // -inline @@ -101,8 +108,10 @@ if (optimizeLevel >= 2) { // Run some optimizations to clean up after inlining. + pm.add(createScalarReplAggregatesPass()); pm.add(createInstructionCombiningPass()); - pm.add(createScalarReplAggregatesPass()); + if (!disableLangSpecificPasses && !disableGCToStack) + pm.add(createGarbageCollect2Stack()); // Inline again, to catch things like foreach delegates // passed to inlined opApply's where the function wasn't @@ -110,14 +119,23 @@ pm.add(createFunctionInliningPass()); // Run clean-up again. + pm.add(createScalarReplAggregatesPass()); pm.add(createInstructionCombiningPass()); - pm.add(createScalarReplAggregatesPass()); + if (!disableLangSpecificPasses && !disableGCToStack) + pm.add(createGarbageCollect2Stack()); } } - if (optimizeLevel >= 2 && !disableLangSpecificPasses - && !disableSimplifyRuntimeCalls) { - pm.add(createSimplifyDRuntimeCalls()); + if (optimizeLevel >= 2 && !disableLangSpecificPasses) { + if (!disableSimplifyRuntimeCalls) + pm.add(createSimplifyDRuntimeCalls()); + + if (!disableGCToStack) { + // Run some clean-up after the last GC to stack promotion pass. + pm.add(createScalarReplAggregatesPass()); + pm.add(createInstructionCombiningPass()); + pm.add(createCFGSimplificationPass()); + } } // -O3