1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 03:02:36 +01:00

verify-uselistorder: Reverse use-lists at every verification

Updated `verify-uselistorder` to more than double the number of use-list
orders it checks.

  - Every time it verifies an order, it then reverses the order and
    verifies again.

  - It now verifies the initial order, before running any shuffles.

Changed the default to `-num-shuffles=1`, since this is already four
checks, and after r214584 shuffling is guaranteed to make a new order.

This is part of PR5680.

llvm-svn: 214596
This commit is contained in:
Duncan P. N. Exon Smith 2014-08-01 23:49:41 +00:00
parent acd5f9dd8a
commit 0fe753a70b

View File

@ -64,7 +64,7 @@ static cl::opt<bool> SaveTemps("save-temps", cl::desc("Save temp files"),
static cl::opt<unsigned> static cl::opt<unsigned>
NumShuffles("num-shuffles", NumShuffles("num-shuffles",
cl::desc("Number of times to shuffle and verify use-lists"), cl::desc("Number of times to shuffle and verify use-lists"),
cl::init(5)); cl::init(1));
namespace { namespace {
@ -413,43 +413,70 @@ static void shuffleValueUseLists(Value *V, std::minstd_rand0 &Gen,
}); });
} }
/// Shuffle all use-lists in a module. static void reverseValueUseLists(Value *V, DenseSet<Value *> &Seen) {
static void shuffleUseLists(Module &M, unsigned SeedOffset) { if (!Seen.insert(V).second)
DEBUG(dbgs() << "*** shuffle-use-lists ***\n"); return;
std::minstd_rand0 Gen(std::minstd_rand0::default_seed + SeedOffset);
DenseSet<Value *> Seen;
// Shuffle the use-list of each value that would be serialized to an IR file if (auto *C = dyn_cast<Constant>(V))
// (bitcode or assembly). if (!isa<GlobalValue>(C))
auto shuffle = [&](Value *V) { shuffleValueUseLists(V, Gen, Seen); }; for (Value *Op : C->operands())
reverseValueUseLists(Op, Seen);
if (V->use_empty() || std::next(V->use_begin()) == V->use_end())
// Nothing to shuffle for 0 or 1 users.
return;
DEBUG({
dbgs() << "V = ";
V->dump();
for (const Use &U : V->uses()) {
dbgs() << " - order: op = " << U.getOperandNo() << ", U = ";
U.getUser()->dump();
}
dbgs() << " => reverse\n";
});
V->reverseUseList();
DEBUG({
for (const Use &U : V->uses()) {
dbgs() << " - order: op = " << U.getOperandNo() << ", U = ";
U.getUser()->dump();
}
});
}
template <class Changer>
static void changeUseLists(Module &M, Changer changeValueUseList) {
// Visit every value that would be serialized to an IR file.
//
// Globals. // Globals.
for (GlobalVariable &G : M.globals()) for (GlobalVariable &G : M.globals())
shuffle(&G); changeValueUseList(&G);
for (GlobalAlias &A : M.aliases()) for (GlobalAlias &A : M.aliases())
shuffle(&A); changeValueUseList(&A);
for (Function &F : M) for (Function &F : M)
shuffle(&F); changeValueUseList(&F);
// Constants used by globals. // Constants used by globals.
for (GlobalVariable &G : M.globals()) for (GlobalVariable &G : M.globals())
if (G.hasInitializer()) if (G.hasInitializer())
shuffle(G.getInitializer()); changeValueUseList(G.getInitializer());
for (GlobalAlias &A : M.aliases()) for (GlobalAlias &A : M.aliases())
shuffle(A.getAliasee()); changeValueUseList(A.getAliasee());
for (Function &F : M) for (Function &F : M)
if (F.hasPrefixData()) if (F.hasPrefixData())
shuffle(F.getPrefixData()); changeValueUseList(F.getPrefixData());
// Function bodies. // Function bodies.
for (Function &F : M) { for (Function &F : M) {
for (Argument &A : F.args()) for (Argument &A : F.args())
shuffle(&A); changeValueUseList(&A);
for (BasicBlock &BB : F) for (BasicBlock &BB : F)
shuffle(&BB); changeValueUseList(&BB);
for (BasicBlock &BB : F) for (BasicBlock &BB : F)
for (Instruction &I : BB) for (Instruction &I : BB)
shuffle(&I); changeValueUseList(&I);
// Constants used by instructions. // Constants used by instructions.
for (BasicBlock &BB : F) for (BasicBlock &BB : F)
@ -457,9 +484,22 @@ static void shuffleUseLists(Module &M, unsigned SeedOffset) {
for (Value *Op : I.operands()) for (Value *Op : I.operands())
if ((isa<Constant>(Op) && !isa<GlobalValue>(*Op)) || if ((isa<Constant>(Op) && !isa<GlobalValue>(*Op)) ||
isa<InlineAsm>(Op)) isa<InlineAsm>(Op))
shuffle(Op); changeValueUseList(Op);
} }
}
static void shuffleUseLists(Module &M, unsigned SeedOffset) {
DEBUG(dbgs() << "*** 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");
DenseSet<Value *> Seen;
changeUseLists(M, [&](Value *V) { reverseValueUseLists(V, Seen); });
DEBUG(dbgs() << "\n"); DEBUG(dbgs() << "\n");
} }
@ -495,12 +535,20 @@ int main(int argc, char **argv) {
return 0; return 0;
} }
// Verify the use lists now and after reversing them.
verifyUseListOrder(*M);
reverseUseLists(*M);
verifyUseListOrder(*M);
for (unsigned I = 0, E = NumShuffles; I != E; ++I) { for (unsigned I = 0, E = NumShuffles; I != E; ++I) {
DEBUG(dbgs() << "*** iteration: " << I << " ***\n"); DEBUG(dbgs() << "*** iteration: " << I << " ***\n");
// Shuffle with a different seed each time so that use-lists that aren't // Shuffle with a different (deterministic) seed each time.
// modified the first time are likely to be modified the next time.
shuffleUseLists(*M, I); shuffleUseLists(*M, I);
// Verify again before and after reversing.
verifyUseListOrder(*M);
reverseUseLists(*M);
verifyUseListOrder(*M); verifyUseListOrder(*M);
} }