1 //===-- llvm-stress.cpp - Generate random LL files to stress-test LLVM ----===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This program is a utility that generates random .ll files to stress-test
11 // different components in LLVM.
13 //===----------------------------------------------------------------------===//
15 #include "llvm/Analysis/CallGraphSCCPass.h"
16 #include "llvm/IR/Constants.h"
17 #include "llvm/IR/IRPrintingPasses.h"
18 #include "llvm/IR/Instruction.h"
19 #include "llvm/IR/LLVMContext.h"
20 #include "llvm/IR/LegacyPassNameParser.h"
21 #include "llvm/IR/Module.h"
22 #include "llvm/IR/Verifier.h"
23 #include "llvm/PassManager.h"
24 #include "llvm/Support/Debug.h"
25 #include "llvm/Support/ManagedStatic.h"
26 #include "llvm/Support/PluginLoader.h"
27 #include "llvm/Support/PrettyStackTrace.h"
28 #include "llvm/Support/ToolOutputFile.h"
35 static cl::opt<unsigned> SeedCL("seed",
36 cl::desc("Seed used for randomness"), cl::init(0));
37 static cl::opt<unsigned> SizeCL("size",
38 cl::desc("The estimated size of the generated function (# of instrs)"),
40 static cl::opt<std::string>
41 OutputFilename("o", cl::desc("Override output filename"),
42 cl::value_desc("filename"));
44 static cl::opt<bool> GenHalfFloat("generate-half-float",
45 cl::desc("Generate half-length floating-point values"), cl::init(false));
46 static cl::opt<bool> GenX86FP80("generate-x86-fp80",
47 cl::desc("Generate 80-bit X86 floating-point values"), cl::init(false));
48 static cl::opt<bool> GenFP128("generate-fp128",
49 cl::desc("Generate 128-bit floating-point values"), cl::init(false));
50 static cl::opt<bool> GenPPCFP128("generate-ppc-fp128",
51 cl::desc("Generate 128-bit PPC floating-point values"), cl::init(false));
52 static cl::opt<bool> GenX86MMX("generate-x86-mmx",
53 cl::desc("Generate X86 MMX floating-point values"), cl::init(false));
56 /// A utility class to provide a pseudo-random number generator which is
57 /// the same across all platforms. This is somewhat close to the libc
58 /// implementation. Note: This is not a cryptographically secure pseudorandom
63 Random(unsigned _seed):Seed(_seed) {}
65 /// Return a random integer, up to a
66 /// maximum of 2**19 - 1.
68 uint32_t Val = Seed + 0x000b07a1;
69 Seed = (Val * 0x3c7c0ac1);
70 // Only lowest 19 bits are random-ish.
71 return Seed & 0x7ffff;
74 /// Return a random 32 bit integer.
76 uint32_t Val = Rand();
78 return Val | (Rand() << 16);
81 /// Return a random 64 bit integer.
83 uint64_t Val = Rand32();
84 return Val | (uint64_t(Rand32()) << 32);
87 /// Rand operator for STL algorithms.
88 ptrdiff_t operator()(ptrdiff_t y) {
96 /// Generate an empty function with a default argument list.
97 Function *GenEmptyFunction(Module *M) {
99 std::vector<Type*> ArgsTy;
100 // Define a few arguments
101 LLVMContext &Context = M->getContext();
102 ArgsTy.push_back(PointerType::get(IntegerType::getInt8Ty(Context), 0));
103 ArgsTy.push_back(PointerType::get(IntegerType::getInt32Ty(Context), 0));
104 ArgsTy.push_back(PointerType::get(IntegerType::getInt64Ty(Context), 0));
105 ArgsTy.push_back(IntegerType::getInt32Ty(Context));
106 ArgsTy.push_back(IntegerType::getInt64Ty(Context));
107 ArgsTy.push_back(IntegerType::getInt8Ty(Context));
109 FunctionType *FuncTy = FunctionType::get(Type::getVoidTy(Context), ArgsTy, 0);
110 // Pick a unique name to describe the input parameters
111 std::stringstream ss;
112 ss<<"autogen_SD"<<SeedCL;
113 Function *Func = Function::Create(FuncTy, GlobalValue::ExternalLinkage,
116 Func->setCallingConv(CallingConv::C);
120 /// A base class, implementing utilities needed for
121 /// modifying and adding new random instructions.
123 /// Used to store the randomly generated values.
124 typedef std::vector<Value*> PieceTable;
128 Modifier(BasicBlock *Block, PieceTable *PT, Random *R):
129 BB(Block),PT(PT),Ran(R),Context(BB->getContext()) {}
131 /// virtual D'tor to silence warnings.
132 virtual ~Modifier() {}
134 /// Add a new instruction.
135 virtual void Act() = 0;
136 /// Add N new instructions,
137 virtual void ActN(unsigned n) {
138 for (unsigned i=0; i<n; ++i)
143 /// Return a random value from the list of known values.
144 Value *getRandomVal() {
146 return PT->at(Ran->Rand() % PT->size());
149 Constant *getRandomConstant(Type *Tp) {
150 if (Tp->isIntegerTy()) {
152 return ConstantInt::getAllOnesValue(Tp);
153 return ConstantInt::getNullValue(Tp);
154 } else if (Tp->isFloatingPointTy()) {
156 return ConstantFP::getAllOnesValue(Tp);
157 return ConstantFP::getNullValue(Tp);
159 return UndefValue::get(Tp);
162 /// Return a random value with a known type.
163 Value *getRandomValue(Type *Tp) {
164 unsigned index = Ran->Rand();
165 for (unsigned i=0; i<PT->size(); ++i) {
166 Value *V = PT->at((index + i) % PT->size());
167 if (V->getType() == Tp)
171 // If the requested type was not found, generate a constant value.
172 if (Tp->isIntegerTy()) {
174 return ConstantInt::getAllOnesValue(Tp);
175 return ConstantInt::getNullValue(Tp);
176 } else if (Tp->isFloatingPointTy()) {
178 return ConstantFP::getAllOnesValue(Tp);
179 return ConstantFP::getNullValue(Tp);
180 } else if (Tp->isVectorTy()) {
181 VectorType *VTp = cast<VectorType>(Tp);
183 std::vector<Constant*> TempValues;
184 TempValues.reserve(VTp->getNumElements());
185 for (unsigned i = 0; i < VTp->getNumElements(); ++i)
186 TempValues.push_back(getRandomConstant(VTp->getScalarType()));
188 ArrayRef<Constant*> VectorValue(TempValues);
189 return ConstantVector::get(VectorValue);
192 return UndefValue::get(Tp);
195 /// Return a random value of any pointer type.
196 Value *getRandomPointerValue() {
197 unsigned index = Ran->Rand();
198 for (unsigned i=0; i<PT->size(); ++i) {
199 Value *V = PT->at((index + i) % PT->size());
200 if (V->getType()->isPointerTy())
203 return UndefValue::get(pickPointerType());
206 /// Return a random value of any vector type.
207 Value *getRandomVectorValue() {
208 unsigned index = Ran->Rand();
209 for (unsigned i=0; i<PT->size(); ++i) {
210 Value *V = PT->at((index + i) % PT->size());
211 if (V->getType()->isVectorTy())
214 return UndefValue::get(pickVectorType());
217 /// Pick a random type.
219 return (Ran->Rand() & 1 ? pickVectorType() : pickScalarType());
222 /// Pick a random pointer type.
223 Type *pickPointerType() {
224 Type *Ty = pickType();
225 return PointerType::get(Ty, 0);
228 /// Pick a random vector type.
229 Type *pickVectorType(unsigned len = (unsigned)-1) {
230 // Pick a random vector width in the range 2**0 to 2**4.
231 // by adding two randoms we are generating a normal-like distribution
233 unsigned width = 1<<((Ran->Rand() % 3) + (Ran->Rand() % 3));
236 // Vectors of x86mmx are illegal; keep trying till we get something else.
238 Ty = pickScalarType();
239 } while (Ty->isX86_MMXTy());
241 if (len != (unsigned)-1)
243 return VectorType::get(Ty, width);
246 /// Pick a random scalar type.
247 Type *pickScalarType() {
250 switch (Ran->Rand() % 30) {
251 case 0: t = Type::getInt1Ty(Context); break;
252 case 1: t = Type::getInt8Ty(Context); break;
253 case 2: t = Type::getInt16Ty(Context); break;
255 case 5: t = Type::getFloatTy(Context); break;
257 case 8: t = Type::getDoubleTy(Context); break;
259 case 11: t = Type::getInt32Ty(Context); break;
261 case 14: t = Type::getInt64Ty(Context); break;
263 case 17: if (GenHalfFloat) t = Type::getHalfTy(Context); break;
265 case 20: if (GenX86FP80) t = Type::getX86_FP80Ty(Context); break;
267 case 23: if (GenFP128) t = Type::getFP128Ty(Context); break;
269 case 26: if (GenPPCFP128) t = Type::getPPC_FP128Ty(Context); break;
271 case 29: if (GenX86MMX) t = Type::getX86_MMXTy(Context); break;
272 default: llvm_unreachable("Invalid scalar value");
279 /// Basic block to populate
283 /// Random number generator
286 LLVMContext &Context;
289 struct LoadModifier: public Modifier {
290 LoadModifier(BasicBlock *BB, PieceTable *PT, Random *R):Modifier(BB, PT, R) {}
291 void Act() override {
292 // Try to use predefined pointers. If non-exist, use undef pointer value;
293 Value *Ptr = getRandomPointerValue();
294 Value *V = new LoadInst(Ptr, "L", BB->getTerminator());
299 struct StoreModifier: public Modifier {
300 StoreModifier(BasicBlock *BB, PieceTable *PT, Random *R):Modifier(BB, PT, R) {}
301 void Act() override {
302 // Try to use predefined pointers. If non-exist, use undef pointer value;
303 Value *Ptr = getRandomPointerValue();
304 Type *Tp = Ptr->getType();
305 Value *Val = getRandomValue(Tp->getContainedType(0));
306 Type *ValTy = Val->getType();
308 // Do not store vectors of i1s because they are unsupported
310 if (ValTy->isVectorTy() && ValTy->getScalarSizeInBits() == 1)
313 new StoreInst(Val, Ptr, BB->getTerminator());
317 struct BinModifier: public Modifier {
318 BinModifier(BasicBlock *BB, PieceTable *PT, Random *R):Modifier(BB, PT, R) {}
320 void Act() override {
321 Value *Val0 = getRandomVal();
322 Value *Val1 = getRandomValue(Val0->getType());
324 // Don't handle pointer types.
325 if (Val0->getType()->isPointerTy() ||
326 Val1->getType()->isPointerTy())
329 // Don't handle i1 types.
330 if (Val0->getType()->getScalarSizeInBits() == 1)
334 bool isFloat = Val0->getType()->getScalarType()->isFloatingPointTy();
335 Instruction* Term = BB->getTerminator();
336 unsigned R = Ran->Rand() % (isFloat ? 7 : 13);
337 Instruction::BinaryOps Op;
340 default: llvm_unreachable("Invalid BinOp");
341 case 0:{Op = (isFloat?Instruction::FAdd : Instruction::Add); break; }
342 case 1:{Op = (isFloat?Instruction::FSub : Instruction::Sub); break; }
343 case 2:{Op = (isFloat?Instruction::FMul : Instruction::Mul); break; }
344 case 3:{Op = (isFloat?Instruction::FDiv : Instruction::SDiv); break; }
345 case 4:{Op = (isFloat?Instruction::FDiv : Instruction::UDiv); break; }
346 case 5:{Op = (isFloat?Instruction::FRem : Instruction::SRem); break; }
347 case 6:{Op = (isFloat?Instruction::FRem : Instruction::URem); break; }
348 case 7: {Op = Instruction::Shl; break; }
349 case 8: {Op = Instruction::LShr; break; }
350 case 9: {Op = Instruction::AShr; break; }
351 case 10:{Op = Instruction::And; break; }
352 case 11:{Op = Instruction::Or; break; }
353 case 12:{Op = Instruction::Xor; break; }
356 PT->push_back(BinaryOperator::Create(Op, Val0, Val1, "B", Term));
360 /// Generate constant values.
361 struct ConstModifier: public Modifier {
362 ConstModifier(BasicBlock *BB, PieceTable *PT, Random *R):Modifier(BB, PT, R) {}
363 void Act() override {
364 Type *Ty = pickType();
366 if (Ty->isVectorTy()) {
367 switch (Ran->Rand() % 2) {
368 case 0: if (Ty->getScalarType()->isIntegerTy())
369 return PT->push_back(ConstantVector::getAllOnesValue(Ty));
370 case 1: if (Ty->getScalarType()->isIntegerTy())
371 return PT->push_back(ConstantVector::getNullValue(Ty));
375 if (Ty->isFloatingPointTy()) {
376 // Generate 128 random bits, the size of the (currently)
377 // largest floating-point types.
378 uint64_t RandomBits[2];
379 for (unsigned i = 0; i < 2; ++i)
380 RandomBits[i] = Ran->Rand64();
382 APInt RandomInt(Ty->getPrimitiveSizeInBits(), makeArrayRef(RandomBits));
383 APFloat RandomFloat(Ty->getFltSemantics(), RandomInt);
386 return PT->push_back(ConstantFP::getNullValue(Ty));
387 return PT->push_back(ConstantFP::get(Ty->getContext(), RandomFloat));
390 if (Ty->isIntegerTy()) {
391 switch (Ran->Rand() % 7) {
392 case 0: if (Ty->isIntegerTy())
393 return PT->push_back(ConstantInt::get(Ty,
394 APInt::getAllOnesValue(Ty->getPrimitiveSizeInBits())));
395 case 1: if (Ty->isIntegerTy())
396 return PT->push_back(ConstantInt::get(Ty,
397 APInt::getNullValue(Ty->getPrimitiveSizeInBits())));
398 case 2: case 3: case 4: case 5:
399 case 6: if (Ty->isIntegerTy())
400 PT->push_back(ConstantInt::get(Ty, Ran->Rand()));
407 struct AllocaModifier: public Modifier {
408 AllocaModifier(BasicBlock *BB, PieceTable *PT, Random *R):Modifier(BB, PT, R){}
410 void Act() override {
411 Type *Tp = pickType();
412 PT->push_back(new AllocaInst(Tp, "A", BB->getFirstNonPHI()));
416 struct ExtractElementModifier: public Modifier {
417 ExtractElementModifier(BasicBlock *BB, PieceTable *PT, Random *R):
418 Modifier(BB, PT, R) {}
420 void Act() override {
421 Value *Val0 = getRandomVectorValue();
422 Value *V = ExtractElementInst::Create(Val0,
423 ConstantInt::get(Type::getInt32Ty(BB->getContext()),
424 Ran->Rand() % cast<VectorType>(Val0->getType())->getNumElements()),
425 "E", BB->getTerminator());
426 return PT->push_back(V);
430 struct ShuffModifier: public Modifier {
431 ShuffModifier(BasicBlock *BB, PieceTable *PT, Random *R):Modifier(BB, PT, R) {}
432 void Act() override {
434 Value *Val0 = getRandomVectorValue();
435 Value *Val1 = getRandomValue(Val0->getType());
437 unsigned Width = cast<VectorType>(Val0->getType())->getNumElements();
438 std::vector<Constant*> Idxs;
440 Type *I32 = Type::getInt32Ty(BB->getContext());
441 for (unsigned i=0; i<Width; ++i) {
442 Constant *CI = ConstantInt::get(I32, Ran->Rand() % (Width*2));
443 // Pick some undef values.
444 if (!(Ran->Rand() % 5))
445 CI = UndefValue::get(I32);
449 Constant *Mask = ConstantVector::get(Idxs);
451 Value *V = new ShuffleVectorInst(Val0, Val1, Mask, "Shuff",
452 BB->getTerminator());
457 struct InsertElementModifier: public Modifier {
458 InsertElementModifier(BasicBlock *BB, PieceTable *PT, Random *R):
459 Modifier(BB, PT, R) {}
461 void Act() override {
462 Value *Val0 = getRandomVectorValue();
463 Value *Val1 = getRandomValue(Val0->getType()->getScalarType());
465 Value *V = InsertElementInst::Create(Val0, Val1,
466 ConstantInt::get(Type::getInt32Ty(BB->getContext()),
467 Ran->Rand() % cast<VectorType>(Val0->getType())->getNumElements()),
468 "I", BB->getTerminator());
469 return PT->push_back(V);
474 struct CastModifier: public Modifier {
475 CastModifier(BasicBlock *BB, PieceTable *PT, Random *R):Modifier(BB, PT, R) {}
476 void Act() override {
478 Value *V = getRandomVal();
479 Type *VTy = V->getType();
480 Type *DestTy = pickScalarType();
482 // Handle vector casts vectors.
483 if (VTy->isVectorTy()) {
484 VectorType *VecTy = cast<VectorType>(VTy);
485 DestTy = pickVectorType(VecTy->getNumElements());
489 if (VTy == DestTy) return;
492 if (VTy->isPointerTy()) {
493 if (!DestTy->isPointerTy())
494 DestTy = PointerType::get(DestTy, 0);
495 return PT->push_back(
496 new BitCastInst(V, DestTy, "PC", BB->getTerminator()));
499 unsigned VSize = VTy->getScalarType()->getPrimitiveSizeInBits();
500 unsigned DestSize = DestTy->getScalarType()->getPrimitiveSizeInBits();
502 // Generate lots of bitcasts.
503 if ((Ran->Rand() & 1) && VSize == DestSize) {
504 return PT->push_back(
505 new BitCastInst(V, DestTy, "BC", BB->getTerminator()));
508 // Both types are integers:
509 if (VTy->getScalarType()->isIntegerTy() &&
510 DestTy->getScalarType()->isIntegerTy()) {
511 if (VSize > DestSize) {
512 return PT->push_back(
513 new TruncInst(V, DestTy, "Tr", BB->getTerminator()));
515 assert(VSize < DestSize && "Different int types with the same size?");
517 return PT->push_back(
518 new ZExtInst(V, DestTy, "ZE", BB->getTerminator()));
519 return PT->push_back(new SExtInst(V, DestTy, "Se", BB->getTerminator()));
524 if (VTy->getScalarType()->isFloatingPointTy() &&
525 DestTy->getScalarType()->isIntegerTy()) {
527 return PT->push_back(
528 new FPToSIInst(V, DestTy, "FC", BB->getTerminator()));
529 return PT->push_back(new FPToUIInst(V, DestTy, "FC", BB->getTerminator()));
533 if (VTy->getScalarType()->isIntegerTy() &&
534 DestTy->getScalarType()->isFloatingPointTy()) {
536 return PT->push_back(
537 new SIToFPInst(V, DestTy, "FC", BB->getTerminator()));
538 return PT->push_back(new UIToFPInst(V, DestTy, "FC", BB->getTerminator()));
543 if (VTy->getScalarType()->isFloatingPointTy() &&
544 DestTy->getScalarType()->isFloatingPointTy()) {
545 if (VSize > DestSize) {
546 return PT->push_back(
547 new FPTruncInst(V, DestTy, "Tr", BB->getTerminator()));
548 } else if (VSize < DestSize) {
549 return PT->push_back(
550 new FPExtInst(V, DestTy, "ZE", BB->getTerminator()));
552 // If VSize == DestSize, then the two types must be fp128 and ppc_fp128,
553 // for which there is no defined conversion. So do nothing.
559 struct SelectModifier: public Modifier {
560 SelectModifier(BasicBlock *BB, PieceTable *PT, Random *R):
561 Modifier(BB, PT, R) {}
563 void Act() override {
564 // Try a bunch of different select configuration until a valid one is found.
565 Value *Val0 = getRandomVal();
566 Value *Val1 = getRandomValue(Val0->getType());
568 Type *CondTy = Type::getInt1Ty(Context);
570 // If the value type is a vector, and we allow vector select, then in 50%
571 // of the cases generate a vector select.
572 if (Val0->getType()->isVectorTy() && (Ran->Rand() % 1)) {
573 unsigned NumElem = cast<VectorType>(Val0->getType())->getNumElements();
574 CondTy = VectorType::get(CondTy, NumElem);
577 Value *Cond = getRandomValue(CondTy);
578 Value *V = SelectInst::Create(Cond, Val0, Val1, "Sl", BB->getTerminator());
579 return PT->push_back(V);
584 struct CmpModifier: public Modifier {
585 CmpModifier(BasicBlock *BB, PieceTable *PT, Random *R):Modifier(BB, PT, R) {}
586 void Act() override {
588 Value *Val0 = getRandomVal();
589 Value *Val1 = getRandomValue(Val0->getType());
591 if (Val0->getType()->isPointerTy()) return;
592 bool fp = Val0->getType()->getScalarType()->isFloatingPointTy();
597 (CmpInst::LAST_FCMP_PREDICATE - CmpInst::FIRST_FCMP_PREDICATE) +
598 CmpInst::FIRST_FCMP_PREDICATE;
601 (CmpInst::LAST_ICMP_PREDICATE - CmpInst::FIRST_ICMP_PREDICATE) +
602 CmpInst::FIRST_ICMP_PREDICATE;
605 Value *V = CmpInst::Create(fp ? Instruction::FCmp : Instruction::ICmp,
606 op, Val0, Val1, "Cmp", BB->getTerminator());
607 return PT->push_back(V);
611 } // end anonymous namespace
613 static void FillFunction(Function *F, Random &R) {
614 // Create a legal entry block.
615 BasicBlock *BB = BasicBlock::Create(F->getContext(), "BB", F);
616 ReturnInst::Create(F->getContext(), BB);
618 // Create the value table.
619 Modifier::PieceTable PT;
621 // Consider arguments as legal values.
622 for (Function::arg_iterator it = F->arg_begin(), e = F->arg_end();
626 // List of modifiers which add new random instructions.
627 std::vector<Modifier*> Modifiers;
628 std::unique_ptr<Modifier> LM(new LoadModifier(BB, &PT, &R));
629 std::unique_ptr<Modifier> SM(new StoreModifier(BB, &PT, &R));
630 std::unique_ptr<Modifier> EE(new ExtractElementModifier(BB, &PT, &R));
631 std::unique_ptr<Modifier> SHM(new ShuffModifier(BB, &PT, &R));
632 std::unique_ptr<Modifier> IE(new InsertElementModifier(BB, &PT, &R));
633 std::unique_ptr<Modifier> BM(new BinModifier(BB, &PT, &R));
634 std::unique_ptr<Modifier> CM(new CastModifier(BB, &PT, &R));
635 std::unique_ptr<Modifier> SLM(new SelectModifier(BB, &PT, &R));
636 std::unique_ptr<Modifier> PM(new CmpModifier(BB, &PT, &R));
637 Modifiers.push_back(LM.get());
638 Modifiers.push_back(SM.get());
639 Modifiers.push_back(EE.get());
640 Modifiers.push_back(SHM.get());
641 Modifiers.push_back(IE.get());
642 Modifiers.push_back(BM.get());
643 Modifiers.push_back(CM.get());
644 Modifiers.push_back(SLM.get());
645 Modifiers.push_back(PM.get());
647 // Generate the random instructions
648 AllocaModifier AM(BB, &PT, &R); AM.ActN(5); // Throw in a few allocas
649 ConstModifier COM(BB, &PT, &R); COM.ActN(40); // Throw in a few constants
651 for (unsigned i=0; i< SizeCL / Modifiers.size(); ++i)
652 for (std::vector<Modifier*>::iterator it = Modifiers.begin(),
653 e = Modifiers.end(); it != e; ++it) {
657 SM->ActN(5); // Throw in a few stores.
660 static void IntroduceControlFlow(Function *F, Random &R) {
661 std::vector<Instruction*> BoolInst;
662 for (BasicBlock::iterator it = F->begin()->begin(),
663 e = F->begin()->end(); it != e; ++it) {
664 if (it->getType() == IntegerType::getInt1Ty(F->getContext()))
665 BoolInst.push_back(it);
668 std::random_shuffle(BoolInst.begin(), BoolInst.end(), R);
670 for (std::vector<Instruction*>::iterator it = BoolInst.begin(),
671 e = BoolInst.end(); it != e; ++it) {
672 Instruction *Instr = *it;
673 BasicBlock *Curr = Instr->getParent();
674 BasicBlock::iterator Loc= Instr;
675 BasicBlock *Next = Curr->splitBasicBlock(Loc, "CF");
676 Instr->moveBefore(Curr->getTerminator());
677 if (Curr != &F->getEntryBlock()) {
678 BranchInst::Create(Curr, Next, Instr, Curr->getTerminator());
679 Curr->getTerminator()->eraseFromParent();
684 int main(int argc, char **argv) {
685 // Init LLVM, call llvm_shutdown() on exit, parse args, etc.
686 llvm::PrettyStackTraceProgram X(argc, argv);
687 cl::ParseCommandLineOptions(argc, argv, "llvm codegen stress-tester\n");
690 std::unique_ptr<Module> M(new Module("/tmp/autogen.bc", getGlobalContext()));
691 Function *F = GenEmptyFunction(M.get());
693 // Pick an initial seed value
695 // Generate lots of random instructions inside a single basic block.
697 // Break the basic block into many loops.
698 IntroduceControlFlow(F, R);
700 // Figure out what stream we are supposed to write to...
701 std::unique_ptr<tool_output_file> Out;
702 // Default to standard output.
703 if (OutputFilename.empty())
704 OutputFilename = "-";
706 std::string ErrorInfo;
707 Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo,
709 if (!ErrorInfo.empty()) {
710 errs() << ErrorInfo << '\n';
715 Passes.add(createVerifierPass());
716 Passes.add(createPrintModulePass(Out->os()));
717 Passes.run(*M.get());