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:
Daniel Dunbar 2009-11-10 17:50:53 +00:00
parent ede182ef05
commit be50f5ab9d
3 changed files with 28 additions and 26 deletions

View File

@ -43,8 +43,12 @@ public:
unsigned NoCommon : 1; /// Set when -fno-common or C++ is enabled.
unsigned DisableRedZone : 1; /// Set when -mno-red-zone 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.
InliningMethod Inlining;
@ -69,6 +73,7 @@ public:
DisableRedZone = 0;
NoImplicitFloat = 0;
MergeAllConstants = 1;
DisableLLVMOpts = 0;
}
};

View File

@ -266,22 +266,30 @@ bool BackendConsumer::AddEmitPasses(std::string &Error) {
}
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.
if (CompileOpts.VerifyModule)
getPerFunctionPasses()->add(createVerifierPass());
// Assume that standard function passes aren't run for -O0.
if (CompileOpts.OptimizationLevel > 0)
llvm::createStandardFunctionPasses(getPerFunctionPasses(),
CompileOpts.OptimizationLevel);
if (OptLevel > 0)
llvm::createStandardFunctionPasses(getPerFunctionPasses(), OptLevel);
llvm::Pass *InliningPass = 0;
switch (CompileOpts.Inlining) {
switch (Inlining) {
case CompileOptions::NoInlining: break;
case CompileOptions::NormalInlining: {
// Inline small functions
unsigned Threshold = (CompileOpts.OptimizeSize ||
CompileOpts.OptimizationLevel < 3) ? 50 : 200;
unsigned Threshold = (CompileOpts.OptimizeSize || OptLevel < 3) ? 50 : 200;
InliningPass = createFunctionInliningPass(Threshold);
break;
}
@ -292,8 +300,7 @@ void BackendConsumer::CreatePasses() {
// For now we always create per module passes.
PassManager *PM = getPerModulePasses();
llvm::createStandardModulePasses(PM, CompileOpts.OptimizationLevel,
CompileOpts.OptimizeSize,
llvm::createStandardModulePasses(PM, OptLevel, CompileOpts.OptimizeSize,
CompileOpts.UnitAtATime,
CompileOpts.UnrollLoops,
CompileOpts.SimplifyLibCalls,

View File

@ -1304,24 +1304,14 @@ static void InitializeCompileOptions(CompileOptions &Opts,
using namespace codegenoptions;
Opts.OptimizeSize = OptSize;
Opts.DebugInfo = GenerateDebugInfo;
Opts.DisableLLVMOpts = DisableLLVMOptimizations;
if (DisableLLVMOptimizations) {
Opts.OptimizationLevel = 0;
Opts.Inlining = CompileOptions::NoInlining;
} else {
if (OptSize) {
// -Os implies -O2
Opts.OptimizationLevel = 2;
} else {
Opts.OptimizationLevel = OptLevel;
}
// -Os implies -O2
Opts.OptimizationLevel = OptSize ? 2 : OptLevel;
// We must always run at least the always inlining pass.
if (Opts.OptimizationLevel > 1)
Opts.Inlining = CompileOptions::NormalInlining;
else
Opts.Inlining = CompileOptions::OnlyAlwaysInlining;
}
// We must always run at least the always inlining pass.
Opts.Inlining = (Opts.OptimizationLevel > 1) ? CompileOptions::NormalInlining
: CompileOptions::OnlyAlwaysInlining;
Opts.UnrollLoops = (Opts.OptimizationLevel > 1 && !OptSize);
Opts.SimplifyLibCalls = !LangOpts.NoBuiltin;