Skip to content

Commit 2887117

Browse files
[Hexagon] Use make_early_inc_range (NFC)
1 parent 3255578 commit 2887117

8 files changed

+27
-41
lines changed

llvm/lib/Target/Hexagon/HexagonConstPropagation.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3132,11 +3132,9 @@ void HexagonConstEvaluator::replaceAllRegUsesWith(Register FromReg,
31323132
Register ToReg) {
31333133
assert(FromReg.isVirtual());
31343134
assert(ToReg.isVirtual());
3135-
for (auto I = MRI->use_begin(FromReg), E = MRI->use_end(); I != E;) {
3136-
MachineOperand &O = *I;
3137-
++I;
3135+
for (MachineOperand &O :
3136+
llvm::make_early_inc_range(MRI->use_operands(FromReg)))
31383137
O.setReg(ToReg);
3139-
}
31403138
}
31413139

31423140
bool HexagonConstEvaluator::rewriteHexBranch(MachineInstr &BrI,

llvm/lib/Target/Hexagon/HexagonExpandCondsets.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,20 +1070,18 @@ bool HexagonExpandCondsets::predicate(MachineInstr &TfrI, bool Cond,
10701070
bool HexagonExpandCondsets::predicateInBlock(MachineBasicBlock &B,
10711071
std::set<Register> &UpdRegs) {
10721072
bool Changed = false;
1073-
MachineBasicBlock::iterator I, E, NextI;
1074-
for (I = B.begin(), E = B.end(); I != E; I = NextI) {
1075-
NextI = std::next(I);
1076-
unsigned Opc = I->getOpcode();
1073+
for (MachineInstr &MI : llvm::make_early_inc_range(B)) {
1074+
unsigned Opc = MI.getOpcode();
10771075
if (Opc == Hexagon::A2_tfrt || Opc == Hexagon::A2_tfrf) {
1078-
bool Done = predicate(*I, (Opc == Hexagon::A2_tfrt), UpdRegs);
1076+
bool Done = predicate(MI, (Opc == Hexagon::A2_tfrt), UpdRegs);
10791077
if (!Done) {
10801078
// If we didn't predicate I, we may need to remove it in case it is
10811079
// an "identity" copy, e.g. %1 = A2_tfrt %2, %1.
1082-
if (RegisterRef(I->getOperand(0)) == RegisterRef(I->getOperand(2))) {
1083-
for (auto &Op : I->operands())
1080+
if (RegisterRef(MI.getOperand(0)) == RegisterRef(MI.getOperand(2))) {
1081+
for (auto &Op : MI.operands())
10841082
if (Op.isReg())
10851083
UpdRegs.insert(Op.getReg());
1086-
removeInstr(*I);
1084+
removeInstr(MI);
10871085
}
10881086
}
10891087
Changed |= Done;

llvm/lib/Target/Hexagon/HexagonGenMux.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -232,22 +232,19 @@ bool HexagonGenMux::genMuxInBlock(MachineBasicBlock &B) {
232232
CondsetMap CM;
233233
MuxInfoList ML;
234234

235-
MachineBasicBlock::iterator NextI, End = B.end();
236-
for (MachineBasicBlock::iterator I = B.begin(); I != End; I = NextI) {
237-
MachineInstr *MI = &*I;
238-
NextI = std::next(I);
239-
unsigned Opc = MI->getOpcode();
235+
for (MachineInstr &MI : llvm::make_early_inc_range(B)) {
236+
unsigned Opc = MI.getOpcode();
240237
if (!isCondTransfer(Opc))
241238
continue;
242-
Register DR = MI->getOperand(0).getReg();
239+
Register DR = MI.getOperand(0).getReg();
243240
if (isRegPair(DR))
244241
continue;
245-
MachineOperand &PredOp = MI->getOperand(1);
242+
MachineOperand &PredOp = MI.getOperand(1);
246243
if (PredOp.isUndef())
247244
continue;
248245

249246
Register PR = PredOp.getReg();
250-
unsigned Idx = I2X.lookup(MI);
247+
unsigned Idx = I2X.lookup(&MI);
251248
CondsetMap::iterator F = CM.find(DR);
252249
bool IfTrue = HII->isPredicatedTrue(Opc);
253250

llvm/lib/Target/Hexagon/HexagonHardwareLoops.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,15 +1094,15 @@ void HexagonHardwareLoops::removeIfDead(MachineInstr *MI) {
10941094
if (!MO.isReg() || !MO.isDef())
10951095
continue;
10961096
Register Reg = MO.getReg();
1097-
MachineRegisterInfo::use_iterator nextI;
1098-
for (MachineRegisterInfo::use_iterator I = MRI->use_begin(Reg),
1099-
E = MRI->use_end(); I != E; I = nextI) {
1100-
nextI = std::next(I); // I is invalidated by the setReg
1101-
MachineInstr *UseMI = I->getParent();
1097+
// We use make_early_inc_range here because setReg below invalidates the
1098+
// iterator.
1099+
for (MachineOperand &MO :
1100+
llvm::make_early_inc_range(MRI->use_operands(Reg))) {
1101+
MachineInstr *UseMI = MO.getParent();
11021102
if (UseMI == MI)
11031103
continue;
1104-
if (I->isDebug())
1105-
I->setReg(0U);
1104+
if (MO.isDebug())
1105+
MO.setReg(0U);
11061106
}
11071107
}
11081108

llvm/lib/Target/Hexagon/HexagonISelDAGToDAG.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2247,8 +2247,8 @@ SDValue HexagonDAGToDAGISel::balanceSubTree(SDNode *N, bool TopLevel) {
22472247
}
22482248

22492249
void HexagonDAGToDAGISel::rebalanceAddressTrees() {
2250-
for (auto I = CurDAG->allnodes_begin(), E = CurDAG->allnodes_end(); I != E;) {
2251-
SDNode *N = &*I++;
2250+
for (SDNode &Node : llvm::make_early_inc_range(CurDAG->allnodes())) {
2251+
SDNode *N = &Node;
22522252
if (N->getOpcode() != ISD::LOAD && N->getOpcode() != ISD::STORE)
22532253
continue;
22542254

llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,10 +1490,8 @@ void PolynomialMultiplyRecognize::cleanupLoopBody(BasicBlock *LoopB) {
14901490
if (Value *SV = SimplifyInstruction(&I, {DL, &TLI, &DT}))
14911491
I.replaceAllUsesWith(SV);
14921492

1493-
for (auto I = LoopB->begin(), N = I; I != LoopB->end(); I = N) {
1494-
N = std::next(I);
1495-
RecursivelyDeleteTriviallyDeadInstructions(&*I, &TLI);
1496-
}
1493+
for (Instruction &I : llvm::make_early_inc_range(*LoopB))
1494+
RecursivelyDeleteTriviallyDeadInstructions(&I, &TLI);
14971495
}
14981496

14991497
unsigned PolynomialMultiplyRecognize::getInverseMxN(unsigned QP) {

llvm/lib/Target/Hexagon/HexagonSplitConst32AndConst64.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ bool HexagonSplitConst32AndConst64::runOnMachineFunction(MachineFunction &Fn) {
7070

7171
// Loop over all of the basic blocks
7272
for (MachineBasicBlock &B : Fn) {
73-
for (auto I = B.begin(), E = B.end(); I != E; ) {
74-
MachineInstr &MI = *I;
75-
++I;
73+
for (MachineInstr &MI : llvm::make_early_inc_range(B)) {
7674
unsigned Opc = MI.getOpcode();
7775

7876
if (Opc == Hexagon::CONST32) {

llvm/lib/Target/Hexagon/HexagonVLIWPacketizer.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,12 +1160,9 @@ bool HexagonPacketizerList::cannotCoexist(const MachineInstr &MI,
11601160
void HexagonPacketizerList::unpacketizeSoloInstrs(MachineFunction &MF) {
11611161
for (auto &B : MF) {
11621162
MachineBasicBlock::iterator BundleIt;
1163-
MachineBasicBlock::instr_iterator NextI;
1164-
for (auto I = B.instr_begin(), E = B.instr_end(); I != E; I = NextI) {
1165-
NextI = std::next(I);
1166-
MachineInstr &MI = *I;
1163+
for (MachineInstr &MI : llvm::make_early_inc_range(B.instrs())) {
11671164
if (MI.isBundle())
1168-
BundleIt = I;
1165+
BundleIt = MI.getIterator();
11691166
if (!MI.isInsideBundle())
11701167
continue;
11711168

0 commit comments

Comments
 (0)