[PATCH] D21005: Add a -verify-after-all option

Sanjoy Das via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 5 14:54:26 PDT 2016

sanjoy created this revision.
sanjoy added reviewers: davide, bogner, mehdi_amini, chandlerc.
sanjoy added a subscriber: llvm-commits.
sanjoy added a dependency: D21004: [LegacyPM] Namespace some classes; NFC.
Herald added subscribers: mcrosier, mehdi_amini.

When investigating PR27997 I notied that there is no easy way in opt or
clang to verify the IR after each transform pass.  There is a
`-verify-each` option in opt, but

 - When running `opt -O3` it appends the verifier pass after the whole
  -O3 pipeline, not after each individual transform pass
 - It is in `opt` so isn't accessible from clang via `-mllvm`

With `-verify-after-all`, triaging bugs like PR27997 should become
easier, since we'd be able to run something like `clang -O3 -mllvm
-verify-after-all -mllvm -print-after-all` to quickly discover which
pass broke SSA, if any.

Depends on D21004



Index: lib/IR/LegacyPassManager.cpp
--- lib/IR/LegacyPassManager.cpp
+++ lib/IR/LegacyPassManager.cpp
@@ -18,6 +18,7 @@
 #include "llvm/IR/LegacyPassManagers.h"
 #include "llvm/IR/LegacyPassNameParser.h"
 #include "llvm/IR/Module.h"
+#include "llvm/IR/Verifier.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -84,6 +85,12 @@
               llvm::cl::desc("Print IR after each pass"),
+static cl::opt<bool> VerifyAfterAll(
+    "verify-after-all",
+    llvm::cl::desc(
+        "Verify the IR after each pass (and crash if the IR does not verify)"),
+    cl::init(false));
 static cl::list<std::string>
     PrintFuncsList("filter-print-funcs", cl::value_desc("function names"),
                    cl::desc("Only print IR for functions whose name "
@@ -696,6 +703,11 @@
       dbgs(), std::string("*** IR Dump After ") + P->getPassName() + " ***");
     PP->assignPassManager(activeStack, getTopLevelPassManagerType());
+  if (PI && !PI->isAnalysis() && VerifyAfterAll) {
+    createVerifierPass()->assignPassManager(activeStack,
+                                            getTopLevelPassManagerType());
+  }
 /// Find the pass that implements Analysis AID. Search immutable

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21005.59676.patch
Type: text/x-patch
Size: 1365 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160605/92fee4b2/attachment.bin>

More information about the llvm-commits mailing list