// Copy any terminator instructions to the new kernel, and update
// names as needed.
- for (MachineBasicBlock::iterator I = BB->getFirstTerminator(),
- E = BB->instr_end();
- I != E; ++I) {
- MachineInstr *NewMI = MF.CloneMachineInstr(&*I);
+ for (MachineInstr &MI : BB->terminators()) {
+ MachineInstr *NewMI = MF.CloneMachineInstr(&MI);
updateInstruction(NewMI, false, MaxStageCount, 0, VRMap);
KernelBB->push_back(NewMI);
- InstrMap[NewMI] = &*I;
+ InstrMap[NewMI] = &MI;
}
NewKernel = KernelBB;
bool Changed = false;
for (MachineBasicBlock &MBB : MF) {
bool LocalChange = false;
- for (MachineBasicBlock::iterator I = MBB.getFirstTerminator(),
- E = MBB.end();
- I != E; ++I) {
- MachineInstr &MI = *I;
+ for (MachineInstr &MI : MBB.terminators()) {
switch (MI.getOpcode()) {
default:
break;
unsigned SIInstrInfo::removeBranch(MachineBasicBlock &MBB,
int *BytesRemoved) const {
- MachineBasicBlock::iterator I = MBB.getFirstTerminator();
-
unsigned Count = 0;
unsigned RemovedSize = 0;
- while (I != MBB.end()) {
- MachineBasicBlock::iterator Next = std::next(I);
+ for (MachineInstr &MI : llvm::make_early_inc_range(MBB.terminators())) {
// Skip over artificial terminators when removing instructions.
- if (I->isBranch() || I->isReturn()) {
- RemovedSize += getInstSizeInBytes(*I);
- I->eraseFromParent();
+ if (MI.isBranch() || MI.isReturn()) {
+ RemovedSize += getInstSizeInBytes(MI);
+ MI.eraseFromParent();
++Count;
}
- I = Next;
}
if (BytesRemoved)
/// Returns true if MBB contains an instruction that returns.
static bool hasReturn(const MachineBasicBlock &MBB) {
- for (auto I = MBB.getFirstTerminator(), E = MBB.end(); I != E; ++I)
- if (I->isReturn())
+ for (const MachineInstr &MI : MBB.terminators())
+ if (MI.isReturn())
return true;
return false;
}
// Emit incoming terminator(s). Be optimistic and assume that branch
// prediction will generally do "the right thing".
- for (MachineBasicBlock::iterator I = SinglePredMBB->getFirstTerminator();
- I != SinglePredMBB->end(); I++) {
- LLVM_DEBUG(dbgs() << "** Emitting incoming branch: "; I->dump(););
- bool TakenBranch = (I->isBranch() &&
- (TII->getBranchInfo(*I).isIndirect() ||
- TII->getBranchInfo(*I).getMBBTarget() == MBB));
- HazardRec->emitInstruction(&*I, TakenBranch);
+ for (MachineInstr &MI : SinglePredMBB->terminators()) {
+ LLVM_DEBUG(dbgs() << "** Emitting incoming branch: "; MI.dump(););
+ bool TakenBranch = (MI.isBranch() &&
+ (TII->getBranchInfo(MI).isIndirect() ||
+ TII->getBranchInfo(MI).getMBBTarget() == MBB));
+ HazardRec->emitInstruction(&MI, TakenBranch);
if (TakenBranch)
break;
}