[llvm] r269003 - llc: Rework -run-pass option

Matthias Braun via llvm-commits llvm-commits at lists.llvm.org
Mon May 9 18:32:45 PDT 2016


Author: matze
Date: Mon May  9 20:32:44 2016
New Revision: 269003

URL: http://llvm.org/viewvc/llvm-project?rev=269003&view=rev
Log:
llc: Rework -run-pass option

We now construct a custom pass pipeline instead of injecting
start-before/stop-after into the default pipeline construction. This
allows to specify any pass known to the pass registry. Previously
specifying indirectly added analysis passes or passes not added to the
pipeline add all would not be added and we would silently do nothing.

This also restricts the -run-pass option to cases with .mir input.

Removed:
    llvm/trunk/test/CodeGen/Generic/run-pass.ll
Modified:
    llvm/trunk/include/llvm/CodeGen/Passes.h
    llvm/trunk/tools/llc/llc.cpp

Modified: llvm/trunk/include/llvm/CodeGen/Passes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/Passes.h?rev=269003&r1=269002&r2=269003&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/Passes.h (original)
+++ llvm/trunk/include/llvm/CodeGen/Passes.h Mon May  9 20:32:44 2016
@@ -254,6 +254,18 @@ public:
     return nullptr;
   }
 
+  /// printAndVerify - Add a pass to dump then verify the machine function, if
+  /// those steps are enabled.
+  ///
+  void printAndVerify(const std::string &Banner);
+
+  /// Add a pass to print the machine function if printing is enabled.
+  void addPrintPass(const std::string &Banner);
+
+  /// Add a pass to perform basic verification of the machine function if
+  /// verification is enabled.
+  void addVerifyPass(const std::string &Banner);
+
 protected:
   // Helper to verify the analysis is really immutable.
   void setOpt(bool &Opt, bool Val);
@@ -360,18 +372,6 @@ protected:
   /// addMachinePasses helper to create the target-selected or overriden
   /// regalloc pass.
   FunctionPass *createRegAllocPass(bool Optimized);
-
-  /// printAndVerify - Add a pass to dump then verify the machine function, if
-  /// those steps are enabled.
-  ///
-  void printAndVerify(const std::string &Banner);
-
-  /// Add a pass to print the machine function if printing is enabled.
-  void addPrintPass(const std::string &Banner);
-
-  /// Add a pass to perform basic verification of the machine function if
-  /// verification is enabled.
-  void addVerifyPass(const std::string &Banner);
 };
 } // namespace llvm
 

Removed: llvm/trunk/test/CodeGen/Generic/run-pass.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Generic/run-pass.ll?rev=269002&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/Generic/run-pass.ll (original)
+++ llvm/trunk/test/CodeGen/Generic/run-pass.ll (removed)
@@ -1,7 +0,0 @@
-; RUN: llc < %s -debug-pass=Structure -run-pass=gc-lowering -o /dev/null 2>&1 | FileCheck %s
-
-; CHECK: -gc-lowering
-; CHECK: FunctionPass Manager
-; CHECK-NEXT: Lower Garbage Collection Instructions
-; CHECK-NEXT: Machine Function Analysis
-; CHECK-NEXT: MIR Printing Pass

Modified: llvm/trunk/tools/llc/llc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llc/llc.cpp?rev=269003&r1=269002&r2=269003&view=diff
==============================================================================
--- llvm/trunk/tools/llc/llc.cpp (original)
+++ llvm/trunk/tools/llc/llc.cpp Mon May  9 20:32:44 2016
@@ -21,6 +21,7 @@
 #include "llvm/CodeGen/LinkAllAsmWriterComponents.h"
 #include "llvm/CodeGen/LinkAllCodegenComponents.h"
 #include "llvm/CodeGen/MIRParser/MIRParser.h"
+#include "llvm/CodeGen/MachineFunctionPass.h"
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/IRPrintingPasses.h"
 #include "llvm/IR/LLVMContext.h"
@@ -361,12 +362,37 @@ static int compileModule(char **argv, LL
                              "redundant when run-pass is specified.\n";
         return 1;
       }
+      if (!MIR) {
+        errs() << argv[0] << ": run-pass needs a .mir input.\n";
+        return 1;
+      }
       const PassInfo *PI = PR->getPassInfo(RunPass);
       if (!PI) {
         errs() << argv[0] << ": run-pass pass is not registered.\n";
         return 1;
       }
-      StopAfterID = StartBeforeID = PI->getTypeInfo();
+      LLVMTargetMachine &LLVMTM = static_cast<LLVMTargetMachine&>(*Target);
+      TargetPassConfig *TPC = LLVMTM.createPassConfig(PM);
+      PM.add(TPC);
+      LLVMTM.addMachineModuleInfo(PM);
+      LLVMTM.addMachineFunctionAnalysis(PM, MIR.get());
+
+      Pass *P;
+      if (PI->getTargetMachineCtor())
+        P = PI->getTargetMachineCtor()(Target.get());
+      else if (PI->getNormalCtor())
+        P = PI->getNormalCtor()();
+      else {
+        errs() << argv[0] << ": cannot create pass: "
+               << PI->getPassName() << "\n";
+        return 1;
+      }
+      std::string Banner
+        = std::string("After ") + std::string(P->getPassName());
+      PM.add(P);
+      TPC->printAndVerify(Banner);
+
+      PM.add(createPrintMIRPass(errs()));
     } else {
       if (!StartAfter.empty()) {
         const PassInfo *PI = PR->getPassInfo(StartAfter);
@@ -384,14 +410,15 @@ static int compileModule(char **argv, LL
         }
         StopAfterID = PI->getTypeInfo();
       }
-    }
 
-    // Ask the target to add backend passes as necessary.
-    if (Target->addPassesToEmitFile(PM, *OS, FileType, NoVerify, StartBeforeID,
-                                    StartAfterID, StopAfterID, MIR.get())) {
-      errs() << argv[0] << ": target does not support generation of this"
-             << " file type!\n";
-      return 1;
+      // Ask the target to add backend passes as necessary.
+      if (Target->addPassesToEmitFile(PM, *OS, FileType, NoVerify,
+                                      StartBeforeID, StartAfterID, StopAfterID,
+                                      MIR.get())) {
+        errs() << argv[0] << ": target does not support generation of this"
+               << " file type!\n";
+        return 1;
+      }
     }
 
     // Before executing passes, print the final values of the LLVM options.




More information about the llvm-commits mailing list