forked from OSchip/llvm-project
Localize -disable-llvm-optzns handling to BackendConsumer::CreatePasses.
- This is conceptually better since the only thing we want this option to do is preserve the internal module as constructed by IRgen, before running any passes. - This also fixes bugs in -disable-llvm-optzns handling with regards to debug info. llvm-svn: 86691
This commit is contained in:
parent
ede182ef05
commit
be50f5ab9d
|
@ -43,8 +43,12 @@ public:
|
||||||
unsigned NoCommon : 1; /// Set when -fno-common or C++ is enabled.
|
unsigned NoCommon : 1; /// Set when -fno-common or C++ is enabled.
|
||||||
unsigned DisableRedZone : 1; /// Set when -mno-red-zone is enabled.
|
unsigned DisableRedZone : 1; /// Set when -mno-red-zone is enabled.
|
||||||
unsigned NoImplicitFloat : 1; /// Set when -mno-implicit-float is enabled.
|
unsigned NoImplicitFloat : 1; /// Set when -mno-implicit-float is enabled.
|
||||||
unsigned MergeAllConstants : 1; // Merge identical constants.
|
unsigned MergeAllConstants : 1; /// Merge identical constants.
|
||||||
|
unsigned DisableLLVMOpts : 1; /// Don't run any optimizations, for use in
|
||||||
|
/// getting .bc files that correspond to the
|
||||||
|
/// internal state before optimizations are
|
||||||
|
/// done.
|
||||||
|
|
||||||
/// Inlining - The kind of inlining to perform.
|
/// Inlining - The kind of inlining to perform.
|
||||||
InliningMethod Inlining;
|
InliningMethod Inlining;
|
||||||
|
|
||||||
|
@ -69,6 +73,7 @@ public:
|
||||||
DisableRedZone = 0;
|
DisableRedZone = 0;
|
||||||
NoImplicitFloat = 0;
|
NoImplicitFloat = 0;
|
||||||
MergeAllConstants = 1;
|
MergeAllConstants = 1;
|
||||||
|
DisableLLVMOpts = 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -266,22 +266,30 @@ bool BackendConsumer::AddEmitPasses(std::string &Error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void BackendConsumer::CreatePasses() {
|
void BackendConsumer::CreatePasses() {
|
||||||
|
unsigned OptLevel = CompileOpts.OptimizationLevel;
|
||||||
|
CompileOptions::InliningMethod Inlining = CompileOpts.Inlining;
|
||||||
|
|
||||||
|
// Handle disabling of LLVM optimization, where we want to preserve the
|
||||||
|
// internal module before any optimization.
|
||||||
|
if (CompileOpts.DisableLLVMOpts) {
|
||||||
|
OptLevel = 0;
|
||||||
|
Inlining = CompileOpts.NoInlining;
|
||||||
|
}
|
||||||
|
|
||||||
// In -O0 if checking is disabled, we don't even have per-function passes.
|
// In -O0 if checking is disabled, we don't even have per-function passes.
|
||||||
if (CompileOpts.VerifyModule)
|
if (CompileOpts.VerifyModule)
|
||||||
getPerFunctionPasses()->add(createVerifierPass());
|
getPerFunctionPasses()->add(createVerifierPass());
|
||||||
|
|
||||||
// Assume that standard function passes aren't run for -O0.
|
// Assume that standard function passes aren't run for -O0.
|
||||||
if (CompileOpts.OptimizationLevel > 0)
|
if (OptLevel > 0)
|
||||||
llvm::createStandardFunctionPasses(getPerFunctionPasses(),
|
llvm::createStandardFunctionPasses(getPerFunctionPasses(), OptLevel);
|
||||||
CompileOpts.OptimizationLevel);
|
|
||||||
|
|
||||||
llvm::Pass *InliningPass = 0;
|
llvm::Pass *InliningPass = 0;
|
||||||
switch (CompileOpts.Inlining) {
|
switch (Inlining) {
|
||||||
case CompileOptions::NoInlining: break;
|
case CompileOptions::NoInlining: break;
|
||||||
case CompileOptions::NormalInlining: {
|
case CompileOptions::NormalInlining: {
|
||||||
// Inline small functions
|
// Inline small functions
|
||||||
unsigned Threshold = (CompileOpts.OptimizeSize ||
|
unsigned Threshold = (CompileOpts.OptimizeSize || OptLevel < 3) ? 50 : 200;
|
||||||
CompileOpts.OptimizationLevel < 3) ? 50 : 200;
|
|
||||||
InliningPass = createFunctionInliningPass(Threshold);
|
InliningPass = createFunctionInliningPass(Threshold);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -292,8 +300,7 @@ void BackendConsumer::CreatePasses() {
|
||||||
|
|
||||||
// For now we always create per module passes.
|
// For now we always create per module passes.
|
||||||
PassManager *PM = getPerModulePasses();
|
PassManager *PM = getPerModulePasses();
|
||||||
llvm::createStandardModulePasses(PM, CompileOpts.OptimizationLevel,
|
llvm::createStandardModulePasses(PM, OptLevel, CompileOpts.OptimizeSize,
|
||||||
CompileOpts.OptimizeSize,
|
|
||||||
CompileOpts.UnitAtATime,
|
CompileOpts.UnitAtATime,
|
||||||
CompileOpts.UnrollLoops,
|
CompileOpts.UnrollLoops,
|
||||||
CompileOpts.SimplifyLibCalls,
|
CompileOpts.SimplifyLibCalls,
|
||||||
|
|
|
@ -1304,24 +1304,14 @@ static void InitializeCompileOptions(CompileOptions &Opts,
|
||||||
using namespace codegenoptions;
|
using namespace codegenoptions;
|
||||||
Opts.OptimizeSize = OptSize;
|
Opts.OptimizeSize = OptSize;
|
||||||
Opts.DebugInfo = GenerateDebugInfo;
|
Opts.DebugInfo = GenerateDebugInfo;
|
||||||
|
Opts.DisableLLVMOpts = DisableLLVMOptimizations;
|
||||||
|
|
||||||
if (DisableLLVMOptimizations) {
|
// -Os implies -O2
|
||||||
Opts.OptimizationLevel = 0;
|
Opts.OptimizationLevel = OptSize ? 2 : OptLevel;
|
||||||
Opts.Inlining = CompileOptions::NoInlining;
|
|
||||||
} else {
|
|
||||||
if (OptSize) {
|
|
||||||
// -Os implies -O2
|
|
||||||
Opts.OptimizationLevel = 2;
|
|
||||||
} else {
|
|
||||||
Opts.OptimizationLevel = OptLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We must always run at least the always inlining pass.
|
// We must always run at least the always inlining pass.
|
||||||
if (Opts.OptimizationLevel > 1)
|
Opts.Inlining = (Opts.OptimizationLevel > 1) ? CompileOptions::NormalInlining
|
||||||
Opts.Inlining = CompileOptions::NormalInlining;
|
: CompileOptions::OnlyAlwaysInlining;
|
||||||
else
|
|
||||||
Opts.Inlining = CompileOptions::OnlyAlwaysInlining;
|
|
||||||
}
|
|
||||||
|
|
||||||
Opts.UnrollLoops = (Opts.OptimizationLevel > 1 && !OptSize);
|
Opts.UnrollLoops = (Opts.OptimizationLevel > 1 && !OptSize);
|
||||||
Opts.SimplifyLibCalls = !LangOpts.NoBuiltin;
|
Opts.SimplifyLibCalls = !LangOpts.NoBuiltin;
|
||||||
|
|
Loading…
Reference in New Issue