aboutsummaryrefslogtreecommitdiffstats
path: root/tools/llvm-stress/llvm-stress.cpp
diff options
context:
space:
mode:
authorShih-wei Liao <sliao@google.com>2012-08-03 00:11:18 -0700
committerShih-wei Liao <sliao@google.com>2012-08-03 00:11:18 -0700
commit7744acd1ab73b3eec6f1449f47083abe3fb1b527 (patch)
tree17ef28b6d1034fdea7f42a19bebe7ad834901d62 /tools/llvm-stress/llvm-stress.cpp
parent4a05ed708aed4c7a099d924ed3feb604d3e44074 (diff)
parenta94d6e87c4c49f2e81b01d66d8bfb591277f8f96 (diff)
downloadexternal_llvm-7744acd1ab73b3eec6f1449f47083abe3fb1b527.zip
external_llvm-7744acd1ab73b3eec6f1449f47083abe3fb1b527.tar.gz
external_llvm-7744acd1ab73b3eec6f1449f47083abe3fb1b527.tar.bz2
Merge with LLVM upstream r160668 (Jul 24th 2012)
Conflicts: include/llvm/Support/ELF.h lib/CodeGen/AsmPrinter/AsmPrinter.cpp lib/Support/Memory.cpp lib/Transforms/Instrumentation/AddressSanitizer.cpp Change-Id: Iddd658cf2eadc7165b2805b446d31af2c5c9917f
Diffstat (limited to 'tools/llvm-stress/llvm-stress.cpp')
-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 fb05a58..31252dd 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;