X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=tools%2Fverify-uselistorder%2Fverify-uselistorder.cpp;h=0bb9b0dce02ad9f0e8719b9f369cb2fe2f502c95;hb=36c150801a3afb763c7d3d7b0c0e8cc046b14aaf;hp=885326cffd276121e087f8a720108bb7765dce68;hpb=f359f7ef8c8cccea0c830308289fe7fe2c148bdc;p=oota-llvm.git diff --git a/tools/verify-uselistorder/verify-uselistorder.cpp b/tools/verify-uselistorder/verify-uselistorder.cpp index 885326cffd2..0bb9b0dce02 100644 --- a/tools/verify-uselistorder/verify-uselistorder.cpp +++ b/tools/verify-uselistorder/verify-uselistorder.cpp @@ -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 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 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 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(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 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 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);