From 7f00806a6a8833d70aaa8ec43159e5668d98ac66 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Mon, 15 Nov 2021 21:28:46 -0800 Subject: [PATCH] [llvm] Use make_early_inc_range (NFC) --- llvm/lib/CodeGen/ExpandPostRAPseudos.cpp | 7 +------ llvm/lib/CodeGen/MachineStripDebug.cpp | 21 +++++++++------------ llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp | 7 +++---- llvm/lib/CodeGen/TailDuplicator.cpp | 11 ++++------- llvm/lib/Target/NVPTX/NVPTXLowerAlloca.cpp | 5 +---- llvm/lib/Target/SystemZ/SystemZElimCompare.cpp | 7 +++---- 6 files changed, 21 insertions(+), 37 deletions(-) diff --git a/llvm/lib/CodeGen/ExpandPostRAPseudos.cpp b/llvm/lib/CodeGen/ExpandPostRAPseudos.cpp index d909d6a..7300ea6 100644 --- a/llvm/lib/CodeGen/ExpandPostRAPseudos.cpp +++ b/llvm/lib/CodeGen/ExpandPostRAPseudos.cpp @@ -189,12 +189,7 @@ bool ExpandPostRA::runOnMachineFunction(MachineFunction &MF) { bool MadeChange = false; for (MachineBasicBlock &MBB : MF) { - for (MachineBasicBlock::iterator mi = MBB.begin(), me = MBB.end(); - mi != me;) { - MachineInstr &MI = *mi; - // Advance iterator here because MI may be erased. - ++mi; - + for (MachineInstr &MI : llvm::make_early_inc_range(MBB)) { // Only expand pseudos. if (!MI.isPseudo()) continue; diff --git a/llvm/lib/CodeGen/MachineStripDebug.cpp b/llvm/lib/CodeGen/MachineStripDebug.cpp index a1cb12f..86cf499 100644 --- a/llvm/lib/CodeGen/MachineStripDebug.cpp +++ b/llvm/lib/CodeGen/MachineStripDebug.cpp @@ -50,29 +50,26 @@ struct StripDebugMachineModule : public ModulePass { continue; MachineFunction &MF = *MaybeMF; for (MachineBasicBlock &MBB : MF) { - for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end(); - I != E;) { - if (I->isDebugInstr()) { + for (MachineInstr &MI : llvm::make_early_inc_range(MBB)) { + if (MI.isDebugInstr()) { // FIXME: We should remove all of them. However, AArch64 emits an // invalid `DBG_VALUE $lr` with only one operand instead of // the usual three and has a test that depends on it's // preservation. Preserve it for now. - if (I->getNumOperands() > 1) { - LLVM_DEBUG(dbgs() << "Removing debug instruction " << *I); - I = MBB.erase(I); + if (MI.getNumOperands() > 1) { + LLVM_DEBUG(dbgs() << "Removing debug instruction " << MI); + MBB.erase(&MI); Changed |= true; continue; } } - if (I->getDebugLoc()) { - LLVM_DEBUG(dbgs() << "Removing location " << *I); - I->setDebugLoc(DebugLoc()); + if (MI.getDebugLoc()) { + LLVM_DEBUG(dbgs() << "Removing location " << MI); + MI.setDebugLoc(DebugLoc()); Changed |= true; - ++I; continue; } - LLVM_DEBUG(dbgs() << "Keeping " << *I); - ++I; + LLVM_DEBUG(dbgs() << "Keeping " << MI); } } } diff --git a/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp b/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp index d9c7267..e3eb3f8 100644 --- a/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp +++ b/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp @@ -90,8 +90,8 @@ static bool lowerObjCCall(Function &F, const char *NewFn, CallInst::TailCallKind OverridingTCK = getOverridingTailCallKind(F); - for (auto I = F.use_begin(), E = F.use_end(); I != E;) { - auto *CB = cast(I->getUser()); + for (Use &U : llvm::make_early_inc_range(F.uses())) { + auto *CB = cast(U.getUser()); if (CB->getCalledFunction() != &F) { objcarc::ARCInstKind Kind = objcarc::getAttachedARCFunctionKind(CB); @@ -100,13 +100,12 @@ static bool lowerObjCCall(Function &F, const char *NewFn, Kind == objcarc::ARCInstKind::ClaimRV) && "use expected to be the argument of operand bundle " "\"clang.arc.attachedcall\""); - I++->set(FCache.getCallee()); + U.set(FCache.getCallee()); continue; } auto *CI = cast(CB); assert(CI->getCalledFunction() && "Cannot lower an indirect call!"); - ++I; IRBuilder<> Builder(CI->getParent(), CI->getIterator()); SmallVector Args(CI->args()); diff --git a/llvm/lib/CodeGen/TailDuplicator.cpp b/llvm/lib/CodeGen/TailDuplicator.cpp index 806cb17..943bd18 100644 --- a/llvm/lib/CodeGen/TailDuplicator.cpp +++ b/llvm/lib/CodeGen/TailDuplicator.cpp @@ -901,18 +901,15 @@ bool TailDuplicator::tailDuplicate(bool IsSimple, MachineBasicBlock *TailBB, // Clone the contents of TailBB into PredBB. DenseMap LocalVRMap; SmallVector, 4> CopyInfos; - for (MachineBasicBlock::iterator I = TailBB->begin(), E = TailBB->end(); - I != E; /* empty */) { - MachineInstr *MI = &*I; - ++I; - if (MI->isPHI()) { + for (MachineInstr &MI : llvm::make_early_inc_range(*TailBB)) { + if (MI.isPHI()) { // Replace the uses of the def of the PHI with the register coming // from PredBB. - processPHI(MI, TailBB, PredBB, LocalVRMap, CopyInfos, UsedByPhi, true); + processPHI(&MI, TailBB, PredBB, LocalVRMap, CopyInfos, UsedByPhi, true); } else { // Replace def of virtual registers with new registers, and update // uses with PHI source register or the new registers. - duplicateInstruction(MI, TailBB, PredBB, LocalVRMap, UsedByPhi); + duplicateInstruction(&MI, TailBB, PredBB, LocalVRMap, UsedByPhi); } } appendCopies(PredBB, CopyInfos, Copies); diff --git a/llvm/lib/Target/NVPTX/NVPTXLowerAlloca.cpp b/llvm/lib/Target/NVPTX/NVPTXLowerAlloca.cpp index 1bd0255..3692384 100644 --- a/llvm/lib/Target/NVPTX/NVPTXLowerAlloca.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXLowerAlloca.cpp @@ -78,15 +78,12 @@ bool NVPTXLowerAlloca::runOnFunction(Function &F) { new AddrSpaceCastInst(NewASCToLocal, GenericAddrTy, ""); NewASCToLocal->insertAfter(allocaInst); NewASCToGeneric->insertAfter(NewASCToLocal); - for (Value::use_iterator UI = allocaInst->use_begin(), - UE = allocaInst->use_end(); - UI != UE;) { + for (Use &AllocaUse : llvm::make_early_inc_range(allocaInst->uses())) { // Check Load, Store, GEP, and BitCast Uses on alloca and make them // use the converted generic address, in order to expose non-generic // addrspacecast to NVPTXInferAddressSpaces. For other types // of instructions this is unnecessary and may introduce redundant // address cast. - const auto &AllocaUse = *UI++; auto LI = dyn_cast(AllocaUse.getUser()); if (LI && LI->getPointerOperand() == allocaInst && !LI->isVolatile()) { diff --git a/llvm/lib/Target/SystemZ/SystemZElimCompare.cpp b/llvm/lib/Target/SystemZ/SystemZElimCompare.cpp index 19b703b..ac94570 100644 --- a/llvm/lib/Target/SystemZ/SystemZElimCompare.cpp +++ b/llvm/lib/Target/SystemZ/SystemZElimCompare.cpp @@ -571,10 +571,9 @@ bool SystemZElimCompare::optimizeCompareZero( // Also do a forward search to handle cases where an instruction after the // compare can be converted, like // LTEBRCompare %f0s, %f0s; %f2s = LER %f0s => LTEBRCompare %f2s, %f0s - for (MachineBasicBlock::iterator MBBI = - std::next(MachineBasicBlock::iterator(&Compare)), MBBE = MBB.end(); - MBBI != MBBE;) { - MachineInstr &MI = *MBBI++; + auto MIRange = llvm::make_range( + std::next(MachineBasicBlock::iterator(&Compare)), MBB.end()); + for (MachineInstr &MI : llvm::make_early_inc_range(MIRange)) { if (preservesValueOf(MI, SrcReg)) { // Try to eliminate Compare by reusing a CC result from MI. if (convertToLoadAndTest(MI, Compare, CCUsers)) { -- 2.7.4