From be50f5ab9d0b7303c8962cfeeafdc0531bb5f741 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Tue, 10 Nov 2009 17:50:53 +0000 Subject: [PATCH] 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 --- clang/include/clang/Frontend/CompileOptions.h | 9 ++++++-- clang/lib/Frontend/Backend.cpp | 23 ++++++++++++------- clang/tools/clang-cc/clang-cc.cpp | 22 +++++------------- 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/clang/include/clang/Frontend/CompileOptions.h b/clang/include/clang/Frontend/CompileOptions.h index ad53a8d592ba..2e8cfddf180e 100644 --- a/clang/include/clang/Frontend/CompileOptions.h +++ b/clang/include/clang/Frontend/CompileOptions.h @@ -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; } }; diff --git a/clang/lib/Frontend/Backend.cpp b/clang/lib/Frontend/Backend.cpp index 13aecf171718..af6dbafd1d36 100644 --- a/clang/lib/Frontend/Backend.cpp +++ b/clang/lib/Frontend/Backend.cpp @@ -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, diff --git a/clang/tools/clang-cc/clang-cc.cpp b/clang/tools/clang-cc/clang-cc.cpp index bd18165467ee..d177bab185ac 100644 --- a/clang/tools/clang-cc/clang-cc.cpp +++ b/clang/tools/clang-cc/clang-cc.cpp @@ -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;