Skip to content

Commit

Permalink
verify-uselistorder: Call verifyModule() and improve output
Browse files Browse the repository at this point in the history
Call `verifyModule()` after parsing and after every transformation.
Also convert some `DEBUG(dbgs())` to `errs()` to increase visibility
into what's going on.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215951 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
dexonsmith committed Aug 18, 2014
1 parent f359f7e commit 36c1508
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 31 deletions.
4 changes: 2 additions & 2 deletions test/Bitcode/use-list-order.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -129,7 +129,7 @@ loop1:

loop2:
%var = phi i32 [ %var, %loop1 ], [ %var, %loop2 ]
br label %loop1
br label %loop2
}

; Check that block addresses work.
Expand Down
62 changes: 33 additions & 29 deletions tools/verify-uselistorder/verify-uselistorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -327,47 +328,45 @@ static bool matches(const ValueMapping &LM, const ValueMapping &RM) {
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,
Expand Down Expand Up @@ -486,18 +485,21 @@ static void changeUseLists(Module &M, Changer changeValueUseList) {
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); });
DEBUG(dbgs() << "\n");
}

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");
Expand Down Expand Up @@ -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;
}

Expand All @@ -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);
Expand Down

0 comments on commit 36c1508

Please sign in to comment.