// If there is no non-pseudo in the current block, loop back around and try
// the previous block (if there is one).
while ((FMBB = getBBFallenThrough(FMBB, TII))) {
- for (MachineInstr &I : make_range(FMBB->rbegin(), FMBB->rend()))
+ for (MachineInstr &I : llvm::reverse(*FMBB))
if (!I.isPseudo())
return &I;
}
}
return true;
}
- for (auto RPII = RegPairs.rbegin(), RPIE = RegPairs.rend(); RPII != RPIE;
- ++RPII) {
- RegPairInfo RPI = *RPII;
+ for (const RegPairInfo &RPI : llvm::reverse(RegPairs)) {
unsigned Reg1 = RPI.Reg1;
unsigned Reg2 = RPI.Reg2;
unsigned StrOpc;
}
} else {
RegionMRT *Region = Tree->getRegionMRT();
- SetVector<MRT *> *Children = Region->getChildren();
- for (auto CI = Children->rbegin(), CE = Children->rend(); CI != CE; ++CI) {
- if (containsNewBackedge(*CI, MBBs))
+ for (MRT *C : llvm::reverse(*Region->getChildren()))
+ if (containsNewBackedge(C, MBBs))
return true;
- }
}
return false;
}
bool CopyPropagation::processBlock(MachineBasicBlock &B, const RegisterSet&) {
std::vector<MachineInstr*> Instrs;
- for (auto I = B.rbegin(), E = B.rend(); I != E; ++I)
- Instrs.push_back(&*I);
+ for (MachineInstr &MI : llvm::reverse(B))
+ Instrs.push_back(&MI);
bool Changed = false;
for (auto I : Instrs) {
return true;
return false;
};
- for (auto I = B.rbegin(), E = B.rend(); I != E; ++I) {
- if (I->isDebugInstr())
+ for (MachineInstr &I : llvm::reverse(B)) {
+ if (I.isDebugInstr())
continue;
// This isn't 100% accurate, but it's safe.
// It won't detect (as a kill) a case like this
// r0 = add r0, 1 <-- r0 should be "killed"
// ... = r0
- for (MachineOperand &Op : I->operands()) {
+ for (MachineOperand &Op : I.operands()) {
if (!Op.isReg() || !Op.isUse())
continue;
assert(Op.getSubReg() == 0 && "Should have physical registers only");
bool Live = IsLive(Op.getReg());
Op.setIsKill(!Live);
}
- LPR.stepBackward(*I);
+ LPR.stepBackward(I);
}
return Changed;
continue;
if (PB == BB)
continue;
- for (auto I = PB->instr_rbegin(), E = PB->instr_rend(); I != E; ++I) {
- unsigned Opc = I->getOpcode();
+ for (MachineInstr &I : llvm::reverse(PB->instrs())) {
+ unsigned Opc = I.getOpcode();
if (Opc == LOOPi || Opc == LOOPr)
- return &*I;
+ return &I;
// We've reached a different loop, which means the loop01 has been
// removed.
- if (Opc == EndLoopOp && I->getOperand(0).getMBB() != TargetBB)
+ if (Opc == EndLoopOp && I.getOperand(0).getMBB() != TargetBB)
return nullptr;
}
// Check the predecessors for the LOOP instruction.
SmallVectorImpl<MachineInstr *> &PHIs,
Register Dst) {
DenseMap<MachineInstr *, MachineInstr *> ChangedPHIMap;
- for (auto It = PHIs.rbegin(), End = PHIs.rend(); It != End; ++It) {
- MachineInstr *PHI = *It;
+ for (MachineInstr *PHI : llvm::reverse(PHIs)) {
SmallVector<std::pair<MachineOperand, MachineOperand>, 4> PHIOps;
// We check if the current PHI node can be changed by looking at its
// operands. If all the operands are either copies from primed
LiveRegs.addLiveOuts(MBB);
// Iterate backwards through the block looking for instructions to change.
- for (auto MBBI = MBB.rbegin(), MBBE = MBB.rend(); MBBI != MBBE; ++MBBI) {
- MachineInstr &MI = *MBBI;
+ for (MachineInstr &MI : llvm::reverse(MBB)) {
switch (MI.getOpcode()) {
case SystemZ::IILF:
Changed |= shortenIIF(MI, SystemZ::LLILL, SystemZ::LLILH);
SmallVector<EndMarkerInfo, 8> Stack;
SmallVector<const MachineBasicBlock *, 8> EHPadStack;
for (auto &MBB : reverse(MF)) {
- for (auto I = MBB.rbegin(), E = MBB.rend(); I != E; ++I) {
- MachineInstr &MI = *I;
+ for (MachineInstr &MI : llvm::reverse(MBB)) {
switch (MI.getOpcode()) {
case WebAssembly::BLOCK:
case WebAssembly::TRY:
PB != PE; ++PB) {
MachineBasicBlock *PMBB = *PB;
int PredCount = 0;
- for (MachineBasicBlock::reverse_iterator PBInst = PMBB->rbegin(),
- PME = PMBB->rend();
- PBInst != PME; ++PBInst) {
- if (PBInst->isMetaInstruction())
+ for (MachineInstr &PBInst : llvm::reverse(*PMBB)) {
+ if (PBInst.isMetaInstruction())
continue;
PredCount++;
if (PredCount >= LimitLeft)
break;
- if (PBInst->getDesc().isCall())
+ if (PBInst.getDesc().isCall())
break;
- PotentialBlockers.push_back(&*PBInst);
+ PotentialBlockers.push_back(&PBInst);
}
}
}
LPR.addLiveOuts(MBB);
- for (MachineBasicBlock::reverse_iterator I = MBB.rbegin(), E = MBB.rend();
- I != E; ++I) {
- if (I->isDebugInstr())
+ for (MachineInstr &MI : llvm::reverse(MBB)) {
+ if (MI.isDebugInstr())
continue;
std::bitset<8> Defs;
SmallVector<MachineOperand *, 2> Uses;
- MachineInstr &MI = *I;
- for (auto &MO : I->operands()) {
+ for (auto &MO : MI.operands()) {
if (!MO.isReg())
continue;
MachineInstr *ConditionDef = nullptr;
bool SingleUseCondition = true;
- for (auto I = std::next(MBB.rbegin()), E = MBB.rend(); I != E; ++I) {
- if (I->modifiesRegister(X86::EFLAGS, TRI)) {
- ConditionDef = &*I;
+ for (MachineInstr &MI : llvm::drop_begin(llvm::reverse(MBB))) {
+ if (MI.modifiesRegister(X86::EFLAGS, TRI)) {
+ ConditionDef = &MI;
break;
}
- if (I->readsRegister(X86::EFLAGS, TRI))
+ if (MI.readsRegister(X86::EFLAGS, TRI))
SingleUseCondition = false;
}