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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215951 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith 2014-08-18 23:44:14 +00:00
parent f359f7ef8c
commit 36c150801a
2 changed files with 35 additions and 31 deletions

View File

@ -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.

View File

@ -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 &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,
@ -486,10 +485,13 @@ 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); });
@ -497,7 +499,7 @@ static void shuffleUseLists(Module &M, unsigned SeedOffset) {
}
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);