[llvm-commits] [dragonegg] r131864 - /dragonegg/trunk/src/Backend.cpp

Duncan Sands baldrick at free.fr
Sun May 22 12:32:30 PDT 2011


Author: baldrick
Date: Sun May 22 14:32:30 2011
New Revision: 131864

URL: http://llvm.org/viewvc/llvm-project?rev=131864&view=rev
Log:
Clean up pass management a little (there's much more that could be done here).
In particular, use the standard set of per-function passes rather than a home
grown set.  The other main change is that if there are no passes to be run
then they are just run (presumably at little cost).  Previously the code tried
to detect this case and avoid running anything at all.  (To be honest, "no
passes to be run" typically means: only the TargetData pass).

Modified:
    dragonegg/trunk/src/Backend.cpp

Modified: dragonegg/trunk/src/Backend.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Backend.cpp?rev=131864&r1=131863&r2=131864&view=diff
==============================================================================
--- dragonegg/trunk/src/Backend.cpp (original)
+++ dragonegg/trunk/src/Backend.cpp Sun May 22 14:32:30 2011
@@ -95,6 +95,7 @@
 // Global state for the LLVM backend.
 Module *TheModule = 0;
 DebugInfo *TheDebugInfo = 0;
+PassManagerBuilder PassBuilder;
 TargetMachine *TheTarget = 0;
 TargetFolder *TheFolder = 0;
 TypeConverter *TheTypeConverter = 0;
@@ -401,10 +402,6 @@
   // purposes, and shouldn't really be for general use.
   std::vector<std::string> ArgStrings;
 
-  unsigned threshold = GuessAtInliningThreshold();
-  std::string Arg("--inline-threshold="+utostr(threshold));
-  ArgStrings.push_back(Arg);
-
 //TODO  if (flag_limited_precision > 0) {
 //TODO    std::string Arg("--limit-float-precision="+utostr(flag_limited_precision));
 //TODO    ArgStrings.push_back(Arg);
@@ -587,6 +584,18 @@
   // Perform language specific configuration.
   InstallLanguageSettings();
 
+  // Configure the pass builder.
+  PassBuilder.OptLevel = IROptLevel();
+  PassBuilder.SizeLevel = optimize_size;
+  PassBuilder.DisableSimplifyLibCalls = flag_no_simplify_libcalls;
+  PassBuilder.DisableUnrollLoops = !flag_unroll_loops;
+  PassBuilder.DisableUnitAtATime = !flag_unit_at_a_time;
+
+  PassBuilder.LibraryInfo =
+    new TargetLibraryInfo((Triple)TheModule->getTargetTriple());
+  if (flag_no_simplify_libcalls)
+    PassBuilder.LibraryInfo->disableAllFunctions();
+
   Initialized = true;
 }
 
@@ -696,33 +705,14 @@
 
   // Create and set up the per-function pass manager.
   // FIXME: Move the code generator to be function-at-a-time.
-  PerFunctionPasses =
-    new FunctionPassManager(TheModule);
-  PerFunctionPasses->add(new TargetData(*TheTarget->getTargetData()));
+  PerFunctionPasses = new FunctionPassManager(TheModule);
+  PerFunctionPasses->add(new TargetData(TheModule));
 
-  // In -O0 if checking is disabled, we don't even have per-function passes.
-  bool HasPerFunctionPasses = false;
 #ifdef ENABLE_CHECKING
   PerFunctionPasses->add(createVerifierPass());
-  HasPerFunctionPasses = true;
 #endif
 
-  if (IROptLevel() > 0) {
-    HasPerFunctionPasses = true;
-
-    TargetLibraryInfo *TLI =
-      new TargetLibraryInfo(Triple(TheModule->getTargetTriple()));
-    if (flag_no_simplify_libcalls)
-      TLI->disableAllFunctions();
-    PerFunctionPasses->add(TLI);
-
-    PerFunctionPasses->add(createCFGSimplificationPass());
-    if (IROptLevel() == 1)
-      PerFunctionPasses->add(createPromoteMemoryToRegisterPass());
-    else
-      PerFunctionPasses->add(createScalarReplAggregatesPass());
-    PerFunctionPasses->add(createInstructionCombiningPass());
-  }
+  PassBuilder.populateFunctionPassManager(*PerFunctionPasses);
 
   // If there are no module-level passes that have to be run, we codegen as
   // each function is parsed.
@@ -732,7 +722,6 @@
   // this for fast -O0 compiles!
   if (!EmitIR && 0) {
     FunctionPassManager *PM = PerFunctionPasses;
-    HasPerFunctionPasses = true;
 
     // Request that addPassesToEmitFile run the Verifier after running
     // passes which modify the IR.
@@ -751,34 +740,21 @@
       DieAbjectly("Error interfacing to target machine!");
   }
 
-  if (HasPerFunctionPasses) {
-    PerFunctionPasses->doInitialization();
-  } else {
-    delete PerFunctionPasses;
-    PerFunctionPasses = 0;
-  }
+  PerFunctionPasses->doInitialization();
 }
 
 static void createPerModuleOptimizationPasses() {
   if (PerModulePasses)
-    // llvm_pch_write_init has already created the per module passes.
     return;
 
-  // FIXME: AT -O0/O1, we should stream out functions at a time.
   PerModulePasses = new PassManager();
-  PerModulePasses->add(new TargetData(*TheTarget->getTargetData()));
-  bool HasPerModulePasses = false;
-
-  TargetLibraryInfo *TLI =
-    new TargetLibraryInfo(Triple(TheModule->getTargetTriple()));
-  if (flag_no_simplify_libcalls)
-    TLI->disableAllFunctions();
-  PerModulePasses->add(TLI);
+  PerModulePasses->add(new TargetData(TheModule));
 
   bool NeedAlwaysInliner = false;
   llvm::Pass *InliningPass = 0;
   if (flag_inline_small_functions && !flag_no_inline) {
-    InliningPass = createFunctionInliningPass();    // Inline small functions
+    // Inline small functions.
+    InliningPass = createFunctionInliningPass(GuessAtInliningThreshold());
   } else {
     // If full inliner is not run, check if always-inline is needed to handle
     // functions that are  marked as always_inline.
@@ -794,29 +770,19 @@
       InliningPass = createAlwaysInlinerPass();  // Inline always_inline funcs
   }
 
-  HasPerModulePasses = true;
-  
-  PassManagerBuilder Builder;
-  Builder.OptLevel = IROptLevel();
-  Builder.SizeLevel = optimize_size;
-  Builder.Inliner = InliningPass;
-  Builder.DisableSimplifyLibCalls = flag_no_simplify_libcalls;
-  Builder.DisableUnrollLoops = !flag_unroll_loops;
-  Builder.DisableUnitAtATime = !flag_unit_at_a_time;
-  Builder.populateModulePassManager(*PerModulePasses);
+  PassBuilder.Inliner = InliningPass;
+  PassBuilder.populateModulePassManager(*PerModulePasses);
 
   if (EmitIR && 0) {
     // Emit an LLVM .bc file to the output.  This is used when passed
     // -emit-llvm -c to the GCC driver.
     InitializeOutputStreams(true);
     PerModulePasses->add(createBitcodeWriterPass(*OutStream));
-    HasPerModulePasses = true;
   } else if (EmitIR) {
     // Emit an LLVM .ll file to the output.  This is used when passed
     // -emit-llvm -S to the GCC driver.
     InitializeOutputStreams(false);
     PerModulePasses->add(createPrintModulePass(OutStream));
-    HasPerModulePasses = true;
   } else {
     // If there are passes we have to run on the entire module, we do codegen
     // as a separate "pass" after that happens.
@@ -846,11 +812,6 @@
         DieAbjectly("Error interfacing to target machine!");
     }
   }
-
-  if (!HasPerModulePasses) {
-    delete PerModulePasses;
-    PerModulePasses = 0;
-  }
 }
 
 //TODO/// llvm_asm_file_start - Start the .s file.





More information about the llvm-commits mailing list