From: Duncan P. N. Exon Smith Date: Tue, 20 Oct 2015 19:36:39 +0000 (+0000) Subject: bugpoint: Remove implicit ilist iterator conversions, NFC X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=1e221d5c2cb38938fe0c7ffedfb078af33d036cb;p=oota-llvm.git bugpoint: Remove implicit ilist iterator conversions, NFC This is the last of the implicit ilist iterator conversions in LLVM. Still up for debate whether we let these bitrot back: http://lists.llvm.org/pipermail/llvm-dev/2015-October/091617.html git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250852 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/tools/bugpoint/CrashDebugger.cpp b/tools/bugpoint/CrashDebugger.cpp index 6564ccea483..7d2b531fa32 100644 --- a/tools/bugpoint/CrashDebugger.cpp +++ b/tools/bugpoint/CrashDebugger.cpp @@ -155,11 +155,10 @@ ReduceCrashingGlobalVariables::TestGlobalVariables( // Loop over and delete any global variables which we aren't supposed to be // playing with... - for (Module::global_iterator I = M->global_begin(), E = M->global_end(); - I != E; ++I) - if (I->hasInitializer() && !GVSet.count(I)) { - I->setInitializer(nullptr); - I->setLinkage(GlobalValue::ExternalLinkage); + for (GlobalVariable &I : M->globals()) + if (I.hasInitializer() && !GVSet.count(&I)) { + I.setInitializer(nullptr); + I.setLinkage(GlobalValue::ExternalLinkage); } // Try running the hacked up program... @@ -253,9 +252,9 @@ bool ReduceCrashingFunctions::TestFuncs(std::vector &Funcs) { if (!ReplaceFuncsWithNull) { // Loop over and delete any functions which we aren't supposed to be playing // with... - for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) - if (!I->isDeclaration() && !Functions.count(I)) - DeleteFunctionBody(I); + for (Function &I : *M) + if (!I.isDeclaration() && !Functions.count(&I)) + DeleteFunctionBody(&I); } else { std::vector ToRemove; // First, remove aliases to functions we're about to purge. @@ -280,12 +279,12 @@ bool ReduceCrashingFunctions::TestFuncs(std::vector &Funcs) { ToRemove.push_back(&Alias); } - for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) { - if (!I->isDeclaration() && !Functions.count(I)) { - PointerType *Ty = cast(I->getType()); + for (Function &I : *M) { + if (!I.isDeclaration() && !Functions.count(&I)) { + PointerType *Ty = cast(I.getType()); Constant *Replacement = ConstantPointerNull::get(Ty); - I->replaceAllUsesWith(Replacement); - ToRemove.push_back(I); + I.replaceAllUsesWith(Replacement); + ToRemove.push_back(&I); } } @@ -361,11 +360,12 @@ bool ReduceCrashingBlocks::TestBlocks(std::vector &BBs) { // Loop over and delete any hack up any blocks that are not listed... for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) for (Function::iterator BB = I->begin(), E = I->end(); BB != E; ++BB) - if (!Blocks.count(BB) && BB->getTerminator()->getNumSuccessors()) { + if (!Blocks.count(&*BB) && BB->getTerminator()->getNumSuccessors()) { // Loop over all of the successors of this block, deleting any PHI nodes // that might include it. - for (succ_iterator SI = succ_begin(BB), E = succ_end(BB); SI != E; ++SI) - (*SI)->removePredecessor(BB); + for (succ_iterator SI = succ_begin(&*BB), E = succ_end(&*BB); SI != E; + ++SI) + (*SI)->removePredecessor(&*BB); TerminatorInst *BBTerm = BB->getTerminator(); @@ -374,7 +374,7 @@ bool ReduceCrashingBlocks::TestBlocks(std::vector &BBs) { // Replace the old terminator instruction. BB->getInstList().pop_back(); - new UnreachableInst(BB->getContext(), BB); + new UnreachableInst(BB->getContext(), &*BB); } // The CFG Simplifier pass may delete one of the basic blocks we are @@ -468,7 +468,7 @@ bool ReduceCrashingInstructions::TestInsts(std::vector for (Module::iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI) for (Function::iterator FI = MI->begin(), FE = MI->end(); FI != FE; ++FI) for (BasicBlock::iterator I = FI->begin(), E = FI->end(); I != E;) { - Instruction *Inst = I++; + Instruction *Inst = &*I++; if (!Instructions.count(Inst) && !isa(Inst) && !Inst->isEHPad()) { if (!Inst->getType()->isVoidTy()) @@ -538,7 +538,7 @@ static bool DebugACrash(BugDriver &BD, for (Module::global_iterator I = BD.getProgram()->global_begin(), E = BD.getProgram()->global_end(); I != E; ++I) if (I->hasInitializer()) - GVs.push_back(I); + GVs.push_back(&*I); if (GVs.size() > 1 && !BugpointIsInterrupted) { outs() << "\n*** Attempting to reduce the number of global " @@ -558,10 +558,9 @@ static bool DebugACrash(BugDriver &BD, // Now try to reduce the number of functions in the module to something small. std::vector Functions; - for (Module::iterator I = BD.getProgram()->begin(), - E = BD.getProgram()->end(); I != E; ++I) - if (!I->isDeclaration()) - Functions.push_back(I); + for (Function &F : *BD.getProgram()) + if (!F.isDeclaration()) + Functions.push_back(&F); if (Functions.size() > 1 && !BugpointIsInterrupted) { outs() << "\n*** Attempting to reduce the number of functions " @@ -581,10 +580,9 @@ static bool DebugACrash(BugDriver &BD, // if (!DisableSimplifyCFG && !BugpointIsInterrupted) { std::vector Blocks; - for (Module::const_iterator I = BD.getProgram()->begin(), - E = BD.getProgram()->end(); I != E; ++I) - for (Function::const_iterator FI = I->begin(), E = I->end(); FI !=E; ++FI) - Blocks.push_back(FI); + for (Function &F : *BD.getProgram()) + for (BasicBlock &BB : F) + Blocks.push_back(&BB); unsigned OldSize = Blocks.size(); ReduceCrashingBlocks(BD, TestFn).reduceList(Blocks, Error); if (Blocks.size() < OldSize) @@ -595,14 +593,11 @@ static bool DebugACrash(BugDriver &BD, // cases with large basic blocks where the problem is at one end. if (!BugpointIsInterrupted) { std::vector Insts; - for (Module::const_iterator MI = BD.getProgram()->begin(), - ME = BD.getProgram()->end(); MI != ME; ++MI) - for (Function::const_iterator FI = MI->begin(), FE = MI->end(); FI != FE; - ++FI) - for (BasicBlock::const_iterator I = FI->begin(), E = FI->end(); - I != E; ++I) - if (!isa(I)) - Insts.push_back(I); + for (const Function &F : *BD.getProgram()) + for (const BasicBlock &BB : F) + for (const Instruction &I : BB) + if (!isa(&I)) + Insts.push_back(&I); ReduceCrashingInstructions(BD, TestFn).reduceList(Insts, Error); } @@ -647,7 +642,7 @@ static bool DebugACrash(BugDriver &BD, outs() << "Checking instruction: " << *I; std::unique_ptr M = - BD.deleteInstructionFromProgram(I, Simplification); + BD.deleteInstructionFromProgram(&*I, Simplification); // Find out if the pass still crashes on this pass... if (TestFn(BD, M.get())) { diff --git a/tools/bugpoint/ExtractFunction.cpp b/tools/bugpoint/ExtractFunction.cpp index 238cbbc70a0..21d3d984599 100644 --- a/tools/bugpoint/ExtractFunction.cpp +++ b/tools/bugpoint/ExtractFunction.cpp @@ -100,7 +100,7 @@ BugDriver::deleteInstructionFromProgram(const Instruction *I, BasicBlock::iterator RI = RBI->begin(); // Get iterator to corresponding inst std::advance(RI, std::distance(PBB->begin(), BasicBlock::const_iterator(I))); - Instruction *TheInst = RI; // Got the corresponding instruction! + Instruction *TheInst = &*RI; // Got the corresponding instruction! // If this instruction produces a value, replace any users with null values if (!TheInst->getType()->isVoidTy()) @@ -306,16 +306,14 @@ llvm::SplitFunctionsOutOfModule(Module *M, // Remove the Safe functions from the Test module - for (Module::iterator I = New->begin(), E = New->end(); I != E; ++I) - if (!TestFunctions.count(I)) - DeleteFunctionBody(I); - + for (Function &I : *New) + if (!TestFunctions.count(&I)) + DeleteFunctionBody(&I); // Try to split the global initializers evenly - for (Module::global_iterator I = M->global_begin(), E = M->global_end(); - I != E; ++I) { - GlobalVariable *GV = cast(NewVMap[I]); - if (Function *TestFn = globalInitUsesExternalBA(I)) { + for (GlobalVariable &I : M->globals()) { + GlobalVariable *GV = cast(NewVMap[&I]); + if (Function *TestFn = globalInitUsesExternalBA(&I)) { if (Function *SafeFn = globalInitUsesExternalBA(GV)) { errs() << "*** Error: when reducing functions, encountered " "the global '"; @@ -325,7 +323,7 @@ llvm::SplitFunctionsOutOfModule(Module *M, << "' and from test function '" << TestFn->getName() << "'.\n"; exit(1); } - I->setInitializer(nullptr); // Delete the initializer to make it external + I.setInitializer(nullptr); // Delete the initializer to make it external } else { // If we keep it in the safe module, then delete it in the test module GV->setInitializer(nullptr); diff --git a/tools/bugpoint/Miscompilation.cpp b/tools/bugpoint/Miscompilation.cpp index 2be9bba07d9..0ca47e77041 100644 --- a/tools/bugpoint/Miscompilation.cpp +++ b/tools/bugpoint/Miscompilation.cpp @@ -545,9 +545,8 @@ static bool ExtractBlocks(BugDriver &BD, std::vector Blocks; for (unsigned i = 0, e = MiscompiledFunctions.size(); i != e; ++i) - for (Function::iterator I = MiscompiledFunctions[i]->begin(), - E = MiscompiledFunctions[i]->end(); I != E; ++I) - Blocks.push_back(I); + for (BasicBlock &BB : *MiscompiledFunctions[i]) + Blocks.push_back(&BB); // Use the list reducer to identify blocks that can be extracted without // obscuring the bug. The Blocks list will end up containing blocks that must @@ -628,9 +627,9 @@ DebugAMiscompilation(BugDriver &BD, // the program. std::vector MiscompiledFunctions; Module *Prog = BD.getProgram(); - for (Module::iterator I = Prog->begin(), E = Prog->end(); I != E; ++I) - if (!I->isDeclaration()) - MiscompiledFunctions.push_back(I); + for (Function &F : *Prog) + if (!F.isDeclaration()) + MiscompiledFunctions.push_back(&F); // Do the reduction... if (!BugpointIsInterrupted) @@ -802,7 +801,7 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test, I = newMain->arg_begin(), E = newMain->arg_end(), OI = oldMain->arg_begin(); I != E; ++I, ++OI) { I->setName(OI->getName()); // Copy argument names from oldMain - args.push_back(I); + args.push_back(&*I); } // Call the old main function and return its result @@ -905,9 +904,8 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test, // Save the argument list. std::vector Args; - for (Function::arg_iterator i = FuncWrapper->arg_begin(), - e = FuncWrapper->arg_end(); i != e; ++i) - Args.push_back(i); + for (Argument &A : FuncWrapper->args()) + Args.push_back(&A); // Pass on the arguments to the real function, return its result if (F->getReturnType()->isVoidTy()) {