[PATCH] D14965: [llc/opt] Add an option to run all passes twice

Keno Fischer via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 24 13:27:41 PST 2015


loladiro created this revision.
loladiro added subscribers: llvm-commits, kcc.
loladiro set the repository for this revision to rL LLVM.

Lately, I have submitted a number of patches to fix bugs that only occurred when using the same pass manager to compile multiple modules (generally these bugs are failure to reset some persistent state). Unfortunately I don't think there is currently a way to test that from the command line. This adds a very simple flag to both llc and opt, under which the tools will simply re-run their respective pass pipelines using the same pass manager on the same module. I believe that should be sufficient to be able to test for that kind of bug, but any other ideas would be appreciated as well.

Repository:
  rL LLVM

http://reviews.llvm.org/D14965

Files:
  tools/llc/llc.cpp
  tools/opt/opt.cpp

Index: tools/opt/opt.cpp
===================================================================
--- tools/opt/opt.cpp
+++ tools/opt/opt.cpp
@@ -190,6 +190,11 @@
     cl::desc("Preserve use-list order when writing LLVM assembly."),
     cl::init(false), cl::Hidden);
 
+static cl::opt<bool>
+    RunTwice("run-twice",
+             cl::desc("Run all passes twice, re-using the same pass manager."),
+             cl::init(false), cl::Hidden);
+
 static inline void addPass(legacy::PassManagerBase &PM, Pass *P) {
   // Add the pass to the pass manager...
   PM.add(P);
@@ -598,6 +603,11 @@
   // Now that we have all of the passes ready, run them.
   Passes.run(*M);
 
+  // If requested, run all passes again with the same pass manager to catch
+  // bugs caused by persistent state in the passes
+  if (RunTwice)
+    Passes.run(*M);
+
   // Declare success.
   if (!NoOutput || PrintBreakpoints)
     Out->keep();
Index: tools/llc/llc.cpp
===================================================================
--- tools/llc/llc.cpp
+++ tools/llc/llc.cpp
@@ -96,6 +96,11 @@
                                 cl::desc("Add comments to directives."),
                                 cl::init(true));
 
+static cl::opt<bool> CompileTwice(
+    "compile-twice", cl::Hidden,
+    cl::desc("Run everything twice, re-using the same pass manager."),
+    cl::init(false));
+
 static int compileModule(char **, LLVMContext &);
 
 static std::unique_ptr<tool_output_file>
@@ -379,6 +384,11 @@
     cl::PrintOptionValues();
 
     PM.run(*M);
+
+    // If requested, run the pass manager over the same module again,
+    // to catch any bugs due to persistent state in the passes
+    if (CompileTwice)
+      PM.run(*M);
   }
 
   // Declare success.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14965.41078.patch
Type: text/x-patch
Size: 1736 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151124/c0cbccd0/attachment.bin>


More information about the llvm-commits mailing list