mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-06 19:06:02 +03:00
Change meaning of optimization levels: -O0 now means 'no optimization' like with
other compilers.
This commit is contained in:
parent
e129494812
commit
257d305032
2 changed files with 9 additions and 14 deletions
|
@ -121,9 +121,9 @@ int linkExecutable(const char* argv0)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
args.push_back("-disable-opt");
|
args.push_back("-disable-opt");
|
||||||
args.push_back("-globaldce");
|
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
|
args.push_back("-globaldce");
|
||||||
args.push_back("-disable-opt");
|
args.push_back("-disable-opt");
|
||||||
args.push_back("-globaldce");
|
args.push_back("-globaldce");
|
||||||
args.push_back("-mem2reg");
|
args.push_back("-mem2reg");
|
||||||
|
|
|
@ -24,14 +24,14 @@ static cl::opt<char> optimizeLevel(
|
||||||
cl::ZeroOrMore,
|
cl::ZeroOrMore,
|
||||||
cl::values(
|
cl::values(
|
||||||
clEnumValN(2, "O", "Equivalent to -O2"),
|
clEnumValN(2, "O", "Equivalent to -O2"),
|
||||||
clEnumValN(0, "O0", "Trivial optimizations only"),
|
clEnumValN(0, "O0", "No optimizations (default)"),
|
||||||
clEnumValN(1, "O1", "Simple optimizations"),
|
clEnumValN(1, "O1", "Simple optimizations"),
|
||||||
clEnumValN(2, "O2", "Good optimizations"),
|
clEnumValN(2, "O2", "Good optimizations"),
|
||||||
clEnumValN(3, "O3", "Aggressive optimizations"),
|
clEnumValN(3, "O3", "Aggressive optimizations"),
|
||||||
clEnumValN(4, "O4", "Link-time optimization"), // not implemented?
|
clEnumValN(4, "O4", "Link-time optimization"), // not implemented?
|
||||||
clEnumValN(5, "O5", "Link-time optimization"), // not implemented?
|
clEnumValN(5, "O5", "Link-time optimization"), // not implemented?
|
||||||
clEnumValEnd),
|
clEnumValEnd),
|
||||||
cl::init(-1));
|
cl::init(0));
|
||||||
|
|
||||||
static cl::opt<bool> enableInlining("enable-inlining",
|
static cl::opt<bool> enableInlining("enable-inlining",
|
||||||
cl::desc("Enable function inlining (in -O<N>, if given)"),
|
cl::desc("Enable function inlining (in -O<N>, if given)"),
|
||||||
|
@ -48,22 +48,17 @@ int optLevel() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool optimize() {
|
bool optimize() {
|
||||||
return (optimizeLevel != -1) || enableInlining || passList.empty();
|
return optimizeLevel || enableInlining || 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
|
||||||
// optimization level given.
|
// optimization level given.
|
||||||
static void addPassesForOptLevel(PassManager& pm) {
|
static void addPassesForOptLevel(PassManager& pm) {
|
||||||
// -O0
|
|
||||||
if (optimizeLevel >= 0)
|
|
||||||
{
|
|
||||||
//pm.add(createStripDeadPrototypesPass());
|
|
||||||
pm.add(createGlobalDCEPass());
|
|
||||||
}
|
|
||||||
|
|
||||||
// -O1
|
// -O1
|
||||||
if (optimizeLevel >= 1)
|
if (optimizeLevel >= 1)
|
||||||
{
|
{
|
||||||
|
//pm.add(createStripDeadPrototypesPass());
|
||||||
|
pm.add(createGlobalDCEPass());
|
||||||
pm.add(createRaiseAllocationsPass());
|
pm.add(createRaiseAllocationsPass());
|
||||||
pm.add(createCFGSimplificationPass());
|
pm.add(createCFGSimplificationPass());
|
||||||
pm.add(createPromoteMemoryToRegisterPass());
|
pm.add(createPromoteMemoryToRegisterPass());
|
||||||
|
@ -129,15 +124,15 @@ 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 == -1 && passList.empty())
|
if (!enableInlining && 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 != -1) || enableInlining;
|
bool optimize = optimizeLevel != 0 || enableInlining;
|
||||||
|
|
||||||
unsigned optPos = optimizeLevel != -1
|
unsigned optPos = optimizeLevel != 0
|
||||||
? optimizeLevel.getPosition()
|
? optimizeLevel.getPosition()
|
||||||
: enableInlining.getPosition();
|
: enableInlining.getPosition();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue