Skip to content
Snippets Groups Projects
Commit 0fb74081 authored by Nadav Rotem's avatar Nadav Rotem
Browse files

llvm-stress: Stabalize (by using an ordered container) and add randomness to...

llvm-stress: Stabalize (by using an ordered container) and add randomness to the order in which loops are generated.

llvm-svn: 158908
parent c4dabab9
No related branches found
No related tags found
No related merge requests found
...@@ -82,6 +82,12 @@ public: ...@@ -82,6 +82,12 @@ public:
uint64_t Val = Rand32(); uint64_t Val = Rand32();
return Val | (uint64_t(Rand32()) << 32); return Val | (uint64_t(Rand32()) << 32);
} }
/// Rand operator for STL algorithms.
ptrdiff_t operator()(ptrdiff_t y) {
return Rand64() % y;
}
private: private:
unsigned Seed; unsigned Seed;
}; };
...@@ -599,15 +605,13 @@ struct CmpModifier: public Modifier { ...@@ -599,15 +605,13 @@ struct CmpModifier: public Modifier {
} }
}; };
void FillFunction(Function *F) { void FillFunction(Function *F, Random &R) {
// Create a legal entry block. // Create a legal entry block.
BasicBlock *BB = BasicBlock::Create(F->getContext(), "BB", F); BasicBlock *BB = BasicBlock::Create(F->getContext(), "BB", F);
ReturnInst::Create(F->getContext(), BB); ReturnInst::Create(F->getContext(), BB);
// Create the value table. // Create the value table.
Modifier::PieceTable PT; Modifier::PieceTable PT;
// Pick an initial seed value
Random R(SeedCL);
// Consider arguments as legal values. // Consider arguments as legal values.
for (Function::arg_iterator it = F->arg_begin(), e = F->arg_end(); for (Function::arg_iterator it = F->arg_begin(), e = F->arg_end();
...@@ -648,15 +652,17 @@ void FillFunction(Function *F) { ...@@ -648,15 +652,17 @@ void FillFunction(Function *F) {
SM->ActN(5); // Throw in a few stores. SM->ActN(5); // Throw in a few stores.
} }
void IntroduceControlFlow(Function *F) { void IntroduceControlFlow(Function *F, Random &R) {
std::set<Instruction*> BoolInst; std::vector<Instruction*> BoolInst;
for (BasicBlock::iterator it = F->begin()->begin(), for (BasicBlock::iterator it = F->begin()->begin(),
e = F->begin()->end(); it != e; ++it) { e = F->begin()->end(); it != e; ++it) {
if (it->getType() == IntegerType::getInt1Ty(F->getContext())) 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) { e = BoolInst.end(); it != e; ++it) {
Instruction *Instr = *it; Instruction *Instr = *it;
BasicBlock *Curr = Instr->getParent(); BasicBlock *Curr = Instr->getParent();
...@@ -678,8 +684,13 @@ int main(int argc, char **argv) { ...@@ -678,8 +684,13 @@ int main(int argc, char **argv) {
std::auto_ptr<Module> M(new Module("/tmp/autogen.bc", getGlobalContext())); std::auto_ptr<Module> M(new Module("/tmp/autogen.bc", getGlobalContext()));
Function *F = GenEmptyFunction(M.get()); 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... // Figure out what stream we are supposed to write to...
OwningPtr<tool_output_file> Out; OwningPtr<tool_output_file> Out;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment