[llvm] r215951 - verify-uselistorder: Call verifyModule() and improve output

Duncan P. N. Exon Smith dexonsmith at apple.com
Mon Aug 18 16:44:15 PDT 2014


Author: dexonsmith
Date: Mon Aug 18 18:44:14 2014
New Revision: 215951

URL: http://llvm.org/viewvc/llvm-project?rev=215951&view=rev
Log:
verify-uselistorder: Call verifyModule() and improve output

Call `verifyModule()` after parsing and after every transformation.
Also convert some `DEBUG(dbgs())` to `errs()` to increase visibility
into what's going on.

Modified:
    llvm/trunk/test/Bitcode/use-list-order.ll
    llvm/trunk/tools/verify-uselistorder/verify-uselistorder.cpp

Modified: llvm/trunk/test/Bitcode/use-list-order.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/use-list-order.ll?rev=215951&r1=215950&r2=215951&view=diff
==============================================================================
--- llvm/trunk/test/Bitcode/use-list-order.ll (original)
+++ llvm/trunk/test/Bitcode/use-list-order.ll Mon Aug 18 18:44:14 2014
@@ -120,7 +120,7 @@ entry:
 }
 
 ; Check for when an instruction is its own user.
-define void @selfUser() {
+define void @selfUser(i1 %a) {
 entry:
   ret void
 
@@ -129,7 +129,7 @@ loop1:
 
 loop2:
   %var = phi i32 [ %var, %loop1 ], [ %var, %loop2 ]
-  br label %loop1
+  br label %loop2
 }
 
 ; Check that block addresses work.

Modified: llvm/trunk/tools/verify-uselistorder/verify-uselistorder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/verify-uselistorder/verify-uselistorder.cpp?rev=215951&r1=215950&r2=215951&view=diff
==============================================================================
--- llvm/trunk/tools/verify-uselistorder/verify-uselistorder.cpp (original)
+++ llvm/trunk/tools/verify-uselistorder/verify-uselistorder.cpp Mon Aug 18 18:44:14 2014
@@ -34,6 +34,7 @@
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/UseListOrder.h"
+#include "llvm/IR/Verifier.h"
 #include "llvm/IRReader/IRReader.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
@@ -327,47 +328,45 @@ static bool matches(const ValueMapping &
   return true;
 }
 
-static bool verifyBitcodeUseListOrder(const Module &M) {
-  DEBUG(dbgs() << "*** verify-use-list-order: bitcode ***\n");
+static void verifyAfterRoundTrip(const Module &M,
+                                 std::unique_ptr<Module> OtherM) {
+  if (!OtherM)
+    report_fatal_error("parsing failed");
+  if (verifyModule(*OtherM, &errs()))
+    report_fatal_error("verification failed");
+  if (!matches(ValueMapping(M), ValueMapping(*OtherM)))
+    report_fatal_error("use-list order changed");
+}
+static void verifyBitcodeUseListOrder(const Module &M) {
+  errs() << "*** verify-use-list-order: bitcode ***\n";
   TempFile F;
   if (F.init("bc"))
-    return false;
+    report_fatal_error("failed to initialize bitcode file");
 
   if (F.writeBitcode(M))
-    return false;
+    report_fatal_error("failed to write bitcode");
 
   LLVMContext Context;
-  std::unique_ptr<Module> OtherM = F.readBitcode(Context);
-  if (!OtherM)
-    return false;
-
-  return matches(ValueMapping(M), ValueMapping(*OtherM));
+  verifyAfterRoundTrip(M, F.readBitcode(Context));
 }
 
-static bool verifyAssemblyUseListOrder(const Module &M) {
-  DEBUG(dbgs() << "*** verify-use-list-order: assembly ***\n");
+static void verifyAssemblyUseListOrder(const Module &M) {
+  errs() << "*** verify-use-list-order: assembly ***\n";
   TempFile F;
   if (F.init("ll"))
-    return false;
+    report_fatal_error("failed to initialize assembly file");
 
   if (F.writeAssembly(M))
-    return false;
+    report_fatal_error("failed to write assembly");
 
   LLVMContext Context;
-  std::unique_ptr<Module> OtherM = F.readAssembly(Context);
-  if (!OtherM)
-    return false;
-
-  return matches(ValueMapping(M), ValueMapping(*OtherM));
+  verifyAfterRoundTrip(M, F.readAssembly(Context));
 }
 
 static void verifyUseListOrder(const Module &M) {
-  if (!verifyBitcodeUseListOrder(M))
-    report_fatal_error("bitcode use-list order changed");
-
+  verifyBitcodeUseListOrder(M);
   if (shouldPreserveAssemblyUseListOrder())
-    if (!verifyAssemblyUseListOrder(M))
-      report_fatal_error("assembly use-list order changed");
+    verifyAssemblyUseListOrder(M);
 }
 
 static void shuffleValueUseLists(Value *V, std::minstd_rand0 &Gen,
@@ -486,10 +485,13 @@ static void changeUseLists(Module &M, Ch
               isa<InlineAsm>(Op))
             changeValueUseList(Op);
   }
+
+  if (verifyModule(M, &errs()))
+    report_fatal_error("verification failed");
 }
 
 static void shuffleUseLists(Module &M, unsigned SeedOffset) {
-  DEBUG(dbgs() << "*** shuffle-use-lists ***\n");
+  errs() << "*** shuffle-use-lists ***\n";
   std::minstd_rand0 Gen(std::minstd_rand0::default_seed + SeedOffset);
   DenseSet<Value *> Seen;
   changeUseLists(M, [&](Value *V) { shuffleValueUseLists(V, Gen, Seen); });
@@ -497,7 +499,7 @@ static void shuffleUseLists(Module &M, u
 }
 
 static void reverseUseLists(Module &M) {
-  DEBUG(dbgs() << "*** reverse-use-lists ***\n");
+  errs() << "*** reverse-use-lists ***\n";
   DenseSet<Value *> Seen;
   changeUseLists(M, [&](Value *V) { reverseValueUseLists(V, Seen); });
   DEBUG(dbgs() << "\n");
@@ -526,12 +528,14 @@ int main(int argc, char **argv) {
     Err.print(argv[0], errs());
     return 1;
   }
+  if (verifyModule(*M, &errs()))
+    report_fatal_error("verification failed");
 
-  DEBUG(dbgs() << "*** verify-use-list-order ***\n");
+  errs() << "*** verify-use-list-order ***\n";
   if (!shouldPreserveBitcodeUseListOrder()) {
     // Can't verify if order isn't preserved.
-    DEBUG(dbgs() << "warning: cannot verify bitcode; "
-                    "try -preserve-bc-use-list-order\n");
+    errs() << "warning: cannot verify bitcode; "
+              "try -preserve-bc-use-list-order\n";
     return 0;
   }
 
@@ -541,7 +545,7 @@ int main(int argc, char **argv) {
   verifyUseListOrder(*M);
 
   for (unsigned I = 0, E = NumShuffles; I != E; ++I) {
-    DEBUG(dbgs() << "*** iteration: " << I << " ***\n");
+    errs() << "*** shuffle iteration: " << I + 1 << " of " << E << " ***\n";
 
     // Shuffle with a different (deterministic) seed each time.
     shuffleUseLists(*M, I);





More information about the llvm-commits mailing list