llvm.org GIT mirror llvm / 611e493
[llvm-stress] Simple refactoring and better style. NFC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240534 91177308-0d34-0410-b5e6-96231b3b80d8 Pawel Bylica 4 years ago
1 changed file(s) with 37 addition(s) and 54 deletion(s). Raw diff Collapse all Expand all
9595
9696 /// Generate an empty function with a default argument list.
9797 Function *GenEmptyFunction(Module *M) {
98 // Type Definitions
99 std::vector ArgsTy;
10098 // Define a few arguments
10199 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));
108
109 FunctionType *FuncTy = FunctionType::get(Type::getVoidTy(Context), ArgsTy, 0);
100 Type* ArgsTy[] = {
101 Type::getInt8PtrTy(Context),
102 Type::getInt32PtrTy(Context),
103 Type::getInt64PtrTy(Context),
104 Type::getInt32Ty(Context),
105 Type::getInt64Ty(Context),
106 Type::getInt8Ty(Context)
107 };
108
109 auto *FuncTy = FunctionType::get(Type::getVoidTy(Context), ArgsTy, false);
110110 // Pick a unique name to describe the input parameters
111 std::stringstream ss;
112 ss<<"autogen_SD"<
113 Function *Func = Function::Create(FuncTy, GlobalValue::ExternalLinkage,
114 ss.str(), M);
115
111 Twine Name = "autogen_SD" + Twine{SeedCL};
112 auto *Func = Function::Create(FuncTy, GlobalValue::ExternalLinkage, Name, M);
116113 Func->setCallingConv(CallingConv::C);
117114 return Func;
118115 }
619616 Modifier::PieceTable PT;
620617
621618 // Consider arguments as legal values.
622 for (Function::arg_iterator it = F->arg_begin(), e = F->arg_end();
623 it != e; ++it)
624 PT.push_back(it);
619 for (auto &arg : F->args())
620 PT.push_back(&arg);
625621
626622 // List of modifiers which add new random instructions.
627 std::vector Modifiers;
628 std::unique_ptr LM(new LoadModifier(BB, &PT, &R));
629 std::unique_ptr SM(new StoreModifier(BB, &PT, &R));
630 std::unique_ptr EE(new ExtractElementModifier(BB, &PT, &R));
631 std::unique_ptr SHM(new ShuffModifier(BB, &PT, &R));
632 std::unique_ptr IE(new InsertElementModifier(BB, &PT, &R));
633 std::unique_ptr BM(new BinModifier(BB, &PT, &R));
634 std::unique_ptr CM(new CastModifier(BB, &PT, &R));
635 std::unique_ptr SLM(new SelectModifier(BB, &PT, &R));
636 std::unique_ptr 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());
623 std::vector> Modifiers;
624 Modifiers.emplace_back(new LoadModifier(BB, &PT, &R));
625 Modifiers.emplace_back(new StoreModifier(BB, &PT, &R));
626 auto SM = Modifiers.back().get();
627 Modifiers.emplace_back(new ExtractElementModifier(BB, &PT, &R));
628 Modifiers.emplace_back(new ShuffModifier(BB, &PT, &R));
629 Modifiers.emplace_back(new InsertElementModifier(BB, &PT, &R));
630 Modifiers.emplace_back(new BinModifier(BB, &PT, &R));
631 Modifiers.emplace_back(new CastModifier(BB, &PT, &R));
632 Modifiers.emplace_back(new SelectModifier(BB, &PT, &R));
633 Modifiers.emplace_back(new CmpModifier(BB, &PT, &R));
646634
647635 // 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
650
651 for (unsigned i=0; i< SizeCL / Modifiers.size(); ++i)
652 for (std::vector::iterator it = Modifiers.begin(),
653 e = Modifiers.end(); it != e; ++it) {
654 (*it)->Act();
655 }
636 AllocaModifier{BB, &PT, &R}.ActN(5); // Throw in a few allocas
637 ConstModifier{BB, &PT, &R}.ActN(40); // Throw in a few constants
638
639 for (unsigned i = 0; i < SizeCL / Modifiers.size(); ++i)
640 for (auto &Mod : Modifiers)
641 Mod->Act();
656642
657643 SM->ActN(5); // Throw in a few stores.
658644 }
659645
660646 static void IntroduceControlFlow(Function *F, Random &R) {
661647 std::vector 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);
648 for (auto &Instr : F->front()) {
649 if (Instr.getType() == IntegerType::getInt1Ty(F->getContext()))
650 BoolInst.push_back(&Instr);
666651 }
667652
668653 std::random_shuffle(BoolInst.begin(), BoolInst.end(), R);
669654
670 for (std::vector::iterator it = BoolInst.begin(),
671 e = BoolInst.end(); it != e; ++it) {
672 Instruction *Instr = *it;
655 for (auto *Instr : BoolInst) {
673656 BasicBlock *Curr = Instr->getParent();
674 BasicBlock::iterator Loc= Instr;
657 BasicBlock::iterator Loc = Instr;
675658 BasicBlock *Next = Curr->splitBasicBlock(Loc, "CF");
676659 Instr->moveBefore(Curr->getTerminator());
677660 if (Curr != &F->getEntryBlock()) {
687670 cl::ParseCommandLineOptions(argc, argv, "llvm codegen stress-tester\n");
688671 llvm_shutdown_obj Y;
689672
690 std::unique_ptr M(new Module("/tmp/autogen.bc", getGlobalContext()));
673 auto M = make_unique("/tmp/autogen.bc", getGlobalContext());
691674 Function *F = GenEmptyFunction(M.get());
692675
693676 // Pick an initial seed value