Enable inlining by default for -O3+.

This commit is contained in:
Frits van Bommel 2009-03-29 19:38:59 +02:00
parent aa508e792a
commit 424bb88da0
2 changed files with 32 additions and 11 deletions

View file

@ -62,7 +62,23 @@ namespace opts {
push_back(str.c_str()); push_back(str.c_str());
} }
}; };
/// Helper class to allow use of a parser<bool> with BoolOrDefault
class BoolOrDefaultAdapter {
cl::boolOrDefault value;
public:
operator cl::boolOrDefault() {
return value;
}
void operator=(cl::boolOrDefault val) {
value = val;
}
void operator=(bool val) {
*this = (val ? cl::BOU_TRUE : cl::BOU_FALSE);
}
};
} }
#endif #endif

View file

@ -1,4 +1,5 @@
#include "gen/optimizer.h" #include "gen/optimizer.h"
#include "gen/cl_helpers.h"
#include "llvm/PassManager.h" #include "llvm/PassManager.h"
#include "llvm/LinkAllPasses.h" #include "llvm/LinkAllPasses.h"
@ -32,22 +33,26 @@ static cl::opt<char> optimizeLevel(
clEnumValEnd), clEnumValEnd),
cl::init(0)); cl::init(0));
static cl::opt<bool> enableInlining("enable-inlining", static cl::opt<opts::BoolOrDefaultAdapter, false, opts::FlagParser>
cl::desc("Enable function inlining (in -O<N>, if given)"), enableInlining("inlining",
cl::ZeroOrMore, cl::desc("(*) Enable function inlining (in -O<N>, if given)"),
cl::init(false)); cl::ZeroOrMore);
// Some accessors for the linker: (llvm-ld version only, currently unused?) // Determine whether or not to run the inliner as part of the default list of
// optimization passes.
// If not explicitly specified, treat as false for -O0-2, and true for -O3.
bool doInline() { bool doInline() {
return enableInlining; return enableInlining == cl::BOU_TRUE
|| (enableInlining == cl::BOU_UNSET && optimizeLevel >= 3);
} }
// Some extra accessors for the linker: (llvm-ld version only, currently unused?)
int optLevel() { int optLevel() {
return optimizeLevel; return optimizeLevel;
} }
bool optimize() { bool optimize() {
return optimizeLevel || enableInlining || passList.empty(); return optimizeLevel || doInline() || passList.empty();
} }
// this function inserts some or all of the std-compile-opts passes depending on the // this function inserts some or all of the std-compile-opts passes depending on the
@ -76,7 +81,7 @@ static void addPassesForOptLevel(PassManager& pm) {
} }
// -inline // -inline
if (enableInlining) { if (doInline()) {
pm.add(createFunctionInliningPass()); pm.add(createFunctionInliningPass());
} }
@ -123,13 +128,13 @@ static void addPassesForOptLevel(PassManager& pm) {
// Returns true if any optimization passes were invoked. // Returns true if any optimization passes were invoked.
bool ldc_optimize_module(llvm::Module* m) bool ldc_optimize_module(llvm::Module* m)
{ {
if (!enableInlining && optimizeLevel == 0 && passList.empty()) if (!doInline() && optimizeLevel == 0 && passList.empty())
return false; return false;
PassManager pm; PassManager pm;
pm.add(new TargetData(m)); pm.add(new TargetData(m));
bool optimize = optimizeLevel != 0 || enableInlining; bool optimize = optimizeLevel != 0 || doInline();
unsigned optPos = optimizeLevel != 0 unsigned optPos = optimizeLevel != 0
? optimizeLevel.getPosition() ? optimizeLevel.getPosition()