summaryrefslogtreecommitdiff
path: root/tools/llvm-stress
diff options
context:
space:
mode:
authorNadav Rotem <nadav.rotem@intel.com>2012-06-21 08:58:15 +0000
committerNadav Rotem <nadav.rotem@intel.com>2012-06-21 08:58:15 +0000
commit7060221ae256ded2b7bbfec60a2c9bdc71426ff2 (patch)
treecd931c3655f62ee8855269e6d239979de9e3ca71 /tools/llvm-stress
parent09d3233c9ebf74a007faaae7f47f68d7285f7ac4 (diff)
llvm-stress: Stabalize (by using an ordered container) and add randomness to the order in which loops are generated.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158908 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-stress')
-rw-r--r--tools/llvm-stress/llvm-stress.cpp29
1 files changed, 20 insertions, 9 deletions
diff --git a/tools/llvm-stress/llvm-stress.cpp b/tools/llvm-stress/llvm-stress.cpp
index fb05a589e8b..31252dd7f77 100644
--- a/tools/llvm-stress/llvm-stress.cpp
+++ b/tools/llvm-stress/llvm-stress.cpp
@@ -82,6 +82,12 @@ public:
uint64_t Val = Rand32();
return Val | (uint64_t(Rand32()) << 32);
}
+
+ /// Rand operator for STL algorithms.
+ ptrdiff_t operator()(ptrdiff_t y) {
+ return Rand64() % y;
+ }
+
private:
unsigned Seed;
};
@@ -599,15 +605,13 @@ struct CmpModifier: public Modifier {
}
};
-void FillFunction(Function *F) {
+void FillFunction(Function *F, Random &R) {
// Create a legal entry block.
BasicBlock *BB = BasicBlock::Create(F->getContext(), "BB", F);
ReturnInst::Create(F->getContext(), BB);
// Create the value table.
Modifier::PieceTable PT;
- // Pick an initial seed value
- Random R(SeedCL);
// Consider arguments as legal values.
for (Function::arg_iterator it = F->arg_begin(), e = F->arg_end();
@@ -648,15 +652,17 @@ void FillFunction(Function *F) {
SM->ActN(5); // Throw in a few stores.
}
-void IntroduceControlFlow(Function *F) {
- std::set<Instruction*> BoolInst;
+void IntroduceControlFlow(Function *F, Random &R) {
+ std::vector<Instruction*> BoolInst;
for (BasicBlock::iterator it = F->begin()->begin(),
e = F->begin()->end(); it != e; ++it) {
if (it->getType() == IntegerType::getInt1Ty(F->getContext()))
- BoolInst.insert(it);
+ BoolInst.push_back(it);
}
- for (std::set<Instruction*>::iterator it = BoolInst.begin(),
+ std::random_shuffle(BoolInst.begin(), BoolInst.end(), R);
+
+ for (std::vector<Instruction*>::iterator it = BoolInst.begin(),
e = BoolInst.end(); it != e; ++it) {
Instruction *Instr = *it;
BasicBlock *Curr = Instr->getParent();
@@ -678,8 +684,13 @@ int main(int argc, char **argv) {
std::auto_ptr<Module> M(new Module("/tmp/autogen.bc", getGlobalContext()));
Function *F = GenEmptyFunction(M.get());
- FillFunction(F);
- IntroduceControlFlow(F);
+
+ // Pick an initial seed value
+ Random R(SeedCL);
+ // Generate lots of random instructions inside a single basic block.
+ FillFunction(F, R);
+ // Break the basic block into many loops.
+ IntroduceControlFlow(F, R);
// Figure out what stream we are supposed to write to...
OwningPtr<tool_output_file> Out;