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;
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);
}
}
}
CallInst::TailCallKind OverridingTCK = getOverridingTailCallKind(F);
- for (auto I = F.use_begin(), E = F.use_end(); I != E;) {
- auto *CB = cast<CallBase>(I->getUser());
+ for (Use &U : llvm::make_early_inc_range(F.uses())) {
+ auto *CB = cast<CallBase>(U.getUser());
if (CB->getCalledFunction() != &F) {
objcarc::ARCInstKind Kind = objcarc::getAttachedARCFunctionKind(CB);
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<CallInst>(CB);
assert(CI->getCalledFunction() && "Cannot lower an indirect call!");
- ++I;
IRBuilder<> Builder(CI->getParent(), CI->getIterator());
SmallVector<Value *, 8> Args(CI->args());
// Clone the contents of TailBB into PredBB.
DenseMap<Register, RegSubRegPair> LocalVRMap;
SmallVector<std::pair<Register, RegSubRegPair>, 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);
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<LoadInst>(AllocaUse.getUser());
if (LI && LI->getPointerOperand() == allocaInst &&
!LI->isVolatile()) {
// 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)) {