[cfe-commits] r86691 - in /cfe/trunk: include/clang/Frontend/CompileOptions.h lib/Frontend/Backend.cpp tools/clang-cc/clang-cc.cpp

Daniel Dunbar daniel at zuster.org
Tue Nov 10 09:50:53 PST 2009


Author: ddunbar
Date: Tue Nov 10 11:50:53 2009
New Revision: 86691

URL: http://llvm.org/viewvc/llvm-project?rev=86691&view=rev
Log:
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.

Modified:
    cfe/trunk/include/clang/Frontend/CompileOptions.h
    cfe/trunk/lib/Frontend/Backend.cpp
    cfe/trunk/tools/clang-cc/clang-cc.cpp

Modified: cfe/trunk/include/clang/Frontend/CompileOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CompileOptions.h?rev=86691&r1=86690&r2=86691&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/CompileOptions.h (original)
+++ cfe/trunk/include/clang/Frontend/CompileOptions.h Tue Nov 10 11:50:53 2009
@@ -43,8 +43,12 @@
   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 @@
     DisableRedZone = 0;
     NoImplicitFloat = 0;
     MergeAllConstants = 1;
+    DisableLLVMOpts = 0;
   }
 };
 

Modified: cfe/trunk/lib/Frontend/Backend.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/Backend.cpp?rev=86691&r1=86690&r2=86691&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/Backend.cpp (original)
+++ cfe/trunk/lib/Frontend/Backend.cpp Tue Nov 10 11:50:53 2009
@@ -266,22 +266,30 @@
 }
 
 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 @@
 
   // 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,

Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=86691&r1=86690&r2=86691&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Tue Nov 10 11:50:53 2009
@@ -1304,24 +1304,14 @@
   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;





More information about the cfe-commits mailing list