From 5ea141e9198aa9c5b4149df3f9e64bca40fb2438 Mon Sep 17 00:00:00 2001 From: Frits van Bommel Date: Thu, 16 Apr 2009 11:58:43 +0200 Subject: [PATCH] Tweak some optimizations. Delegates passed to inlined functions now also stand a chance of being inlined. This should make opApply as efficient as a regular loop, as long as both opApply and the foreachbody are eligible for inlining; which is to say most non-virtual opApply invocations will likely get fully inlined now. (Note: above requires -O2 -enable-inlining or -O3) --- gen/optimizer.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/gen/optimizer.cpp b/gen/optimizer.cpp index 37545775..cbe5270d 100644 --- a/gen/optimizer.cpp +++ b/gen/optimizer.cpp @@ -65,7 +65,10 @@ static void addPassesForOptLevel(PassManager& pm) { pm.add(createGlobalDCEPass()); pm.add(createRaiseAllocationsPass()); pm.add(createCFGSimplificationPass()); - pm.add(createPromoteMemoryToRegisterPass()); + if (optimizeLevel == 1) + pm.add(createPromoteMemoryToRegisterPass()); + else + pm.add(createScalarReplAggregatesPass()); pm.add(createGlobalOptimizerPass()); pm.add(createGlobalDCEPass()); } @@ -83,6 +86,21 @@ static void addPassesForOptLevel(PassManager& pm) { // -inline if (doInline()) { pm.add(createFunctionInliningPass()); + + if (optimizeLevel >= 2) { + // Run some optimizations to clean up after inlining. + pm.add(createInstructionCombiningPass()); + pm.add(createScalarReplAggregatesPass()); + + // Inline again, to catch things like foreach delegates + // passed inlined opApply's where the function wasn't + // known during the first inliner pass. + pm.add(createFunctionInliningPass()); + + // Run clean-up again. + pm.add(createInstructionCombiningPass()); + pm.add(createScalarReplAggregatesPass()); + } } // -O3