From: Pawel Bylica Date: Wed, 24 Jun 2015 11:49:44 +0000 (+0000) Subject: [llvm-stress] Simple refactoring and better style. NFC. X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=611e493ece3f55fbc9ed4eda5826b4a35ecc614a [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 --- diff --git a/tools/llvm-stress/llvm-stress.cpp b/tools/llvm-stress/llvm-stress.cpp index f5e718ba65b..727d03f9d6e 100644 --- a/tools/llvm-stress/llvm-stress.cpp +++ b/tools/llvm-stress/llvm-stress.cpp @@ -96,24 +96,21 @@ private: /// Generate an empty function with a default argument list. Function *GenEmptyFunction(Module *M) { - // Type Definitions - std::vector ArgsTy; // Define a few arguments LLVMContext &Context = M->getContext(); - ArgsTy.push_back(PointerType::get(IntegerType::getInt8Ty(Context), 0)); - ArgsTy.push_back(PointerType::get(IntegerType::getInt32Ty(Context), 0)); - ArgsTy.push_back(PointerType::get(IntegerType::getInt64Ty(Context), 0)); - ArgsTy.push_back(IntegerType::getInt32Ty(Context)); - ArgsTy.push_back(IntegerType::getInt64Ty(Context)); - ArgsTy.push_back(IntegerType::getInt8Ty(Context)); - - FunctionType *FuncTy = FunctionType::get(Type::getVoidTy(Context), ArgsTy, 0); + Type* ArgsTy[] = { + Type::getInt8PtrTy(Context), + Type::getInt32PtrTy(Context), + Type::getInt64PtrTy(Context), + Type::getInt32Ty(Context), + Type::getInt64Ty(Context), + Type::getInt8Ty(Context) + }; + + auto *FuncTy = FunctionType::get(Type::getVoidTy(Context), ArgsTy, false); // Pick a unique name to describe the input parameters - std::stringstream ss; - ss<<"autogen_SD"<setCallingConv(CallingConv::C); return Func; } @@ -620,59 +617,45 @@ static void FillFunction(Function *F, Random &R) { Modifier::PieceTable PT; // Consider arguments as legal values. - for (Function::arg_iterator it = F->arg_begin(), e = F->arg_end(); - it != e; ++it) - PT.push_back(it); + for (auto &arg : F->args()) + PT.push_back(&arg); // List of modifiers which add new random instructions. - std::vector Modifiers; - std::unique_ptr LM(new LoadModifier(BB, &PT, &R)); - std::unique_ptr SM(new StoreModifier(BB, &PT, &R)); - std::unique_ptr EE(new ExtractElementModifier(BB, &PT, &R)); - std::unique_ptr SHM(new ShuffModifier(BB, &PT, &R)); - std::unique_ptr IE(new InsertElementModifier(BB, &PT, &R)); - std::unique_ptr BM(new BinModifier(BB, &PT, &R)); - std::unique_ptr CM(new CastModifier(BB, &PT, &R)); - std::unique_ptr SLM(new SelectModifier(BB, &PT, &R)); - std::unique_ptr PM(new CmpModifier(BB, &PT, &R)); - Modifiers.push_back(LM.get()); - Modifiers.push_back(SM.get()); - Modifiers.push_back(EE.get()); - Modifiers.push_back(SHM.get()); - Modifiers.push_back(IE.get()); - Modifiers.push_back(BM.get()); - Modifiers.push_back(CM.get()); - Modifiers.push_back(SLM.get()); - Modifiers.push_back(PM.get()); + std::vector> Modifiers; + Modifiers.emplace_back(new LoadModifier(BB, &PT, &R)); + Modifiers.emplace_back(new StoreModifier(BB, &PT, &R)); + auto SM = Modifiers.back().get(); + Modifiers.emplace_back(new ExtractElementModifier(BB, &PT, &R)); + Modifiers.emplace_back(new ShuffModifier(BB, &PT, &R)); + Modifiers.emplace_back(new InsertElementModifier(BB, &PT, &R)); + Modifiers.emplace_back(new BinModifier(BB, &PT, &R)); + Modifiers.emplace_back(new CastModifier(BB, &PT, &R)); + Modifiers.emplace_back(new SelectModifier(BB, &PT, &R)); + Modifiers.emplace_back(new CmpModifier(BB, &PT, &R)); // Generate the random instructions - AllocaModifier AM(BB, &PT, &R); AM.ActN(5); // Throw in a few allocas - ConstModifier COM(BB, &PT, &R); COM.ActN(40); // Throw in a few constants + AllocaModifier{BB, &PT, &R}.ActN(5); // Throw in a few allocas + ConstModifier{BB, &PT, &R}.ActN(40); // Throw in a few constants - for (unsigned i=0; i< SizeCL / Modifiers.size(); ++i) - for (std::vector::iterator it = Modifiers.begin(), - e = Modifiers.end(); it != e; ++it) { - (*it)->Act(); - } + for (unsigned i = 0; i < SizeCL / Modifiers.size(); ++i) + for (auto &Mod : Modifiers) + Mod->Act(); SM->ActN(5); // Throw in a few stores. } static void IntroduceControlFlow(Function *F, Random &R) { std::vector BoolInst; - for (BasicBlock::iterator it = F->begin()->begin(), - e = F->begin()->end(); it != e; ++it) { - if (it->getType() == IntegerType::getInt1Ty(F->getContext())) - BoolInst.push_back(it); + for (auto &Instr : F->front()) { + if (Instr.getType() == IntegerType::getInt1Ty(F->getContext())) + BoolInst.push_back(&Instr); } std::random_shuffle(BoolInst.begin(), BoolInst.end(), R); - for (std::vector::iterator it = BoolInst.begin(), - e = BoolInst.end(); it != e; ++it) { - Instruction *Instr = *it; + for (auto *Instr : BoolInst) { BasicBlock *Curr = Instr->getParent(); - BasicBlock::iterator Loc= Instr; + BasicBlock::iterator Loc = Instr; BasicBlock *Next = Curr->splitBasicBlock(Loc, "CF"); Instr->moveBefore(Curr->getTerminator()); if (Curr != &F->getEntryBlock()) { @@ -688,7 +671,7 @@ int main(int argc, char **argv) { cl::ParseCommandLineOptions(argc, argv, "llvm codegen stress-tester\n"); llvm_shutdown_obj Y; - std::unique_ptr M(new Module("/tmp/autogen.bc", getGlobalContext())); + auto M = make_unique("/tmp/autogen.bc", getGlobalContext()); Function *F = GenEmptyFunction(M.get()); // Pick an initial seed value