Skip to content

Commit

Permalink
[Hexagon] Use make_early_inc_range (NFC)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazutakahirata committed Nov 4, 2021
1 parent 3255578 commit 2887117
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 41 deletions.
6 changes: 2 additions & 4 deletions llvm/lib/Target/Hexagon/HexagonConstPropagation.cpp
Expand Up @@ -3132,11 +3132,9 @@ void HexagonConstEvaluator::replaceAllRegUsesWith(Register FromReg,
Register ToReg) {
assert(FromReg.isVirtual());
assert(ToReg.isVirtual());
for (auto I = MRI->use_begin(FromReg), E = MRI->use_end(); I != E;) {
MachineOperand &O = *I;
++I;
for (MachineOperand &O :
llvm::make_early_inc_range(MRI->use_operands(FromReg)))
O.setReg(ToReg);
}
}

bool HexagonConstEvaluator::rewriteHexBranch(MachineInstr &BrI,
Expand Down
14 changes: 6 additions & 8 deletions llvm/lib/Target/Hexagon/HexagonExpandCondsets.cpp
Expand Up @@ -1070,20 +1070,18 @@ bool HexagonExpandCondsets::predicate(MachineInstr &TfrI, bool Cond,
bool HexagonExpandCondsets::predicateInBlock(MachineBasicBlock &B,
std::set<Register> &UpdRegs) {
bool Changed = false;
MachineBasicBlock::iterator I, E, NextI;
for (I = B.begin(), E = B.end(); I != E; I = NextI) {
NextI = std::next(I);
unsigned Opc = I->getOpcode();
for (MachineInstr &MI : llvm::make_early_inc_range(B)) {
unsigned Opc = MI.getOpcode();
if (Opc == Hexagon::A2_tfrt || Opc == Hexagon::A2_tfrf) {
bool Done = predicate(*I, (Opc == Hexagon::A2_tfrt), UpdRegs);
bool Done = predicate(MI, (Opc == Hexagon::A2_tfrt), UpdRegs);
if (!Done) {
// If we didn't predicate I, we may need to remove it in case it is
// an "identity" copy, e.g. %1 = A2_tfrt %2, %1.
if (RegisterRef(I->getOperand(0)) == RegisterRef(I->getOperand(2))) {
for (auto &Op : I->operands())
if (RegisterRef(MI.getOperand(0)) == RegisterRef(MI.getOperand(2))) {
for (auto &Op : MI.operands())
if (Op.isReg())
UpdRegs.insert(Op.getReg());
removeInstr(*I);
removeInstr(MI);
}
}
Changed |= Done;
Expand Down
13 changes: 5 additions & 8 deletions llvm/lib/Target/Hexagon/HexagonGenMux.cpp
Expand Up @@ -232,22 +232,19 @@ bool HexagonGenMux::genMuxInBlock(MachineBasicBlock &B) {
CondsetMap CM;
MuxInfoList ML;

MachineBasicBlock::iterator NextI, End = B.end();
for (MachineBasicBlock::iterator I = B.begin(); I != End; I = NextI) {
MachineInstr *MI = &*I;
NextI = std::next(I);
unsigned Opc = MI->getOpcode();
for (MachineInstr &MI : llvm::make_early_inc_range(B)) {
unsigned Opc = MI.getOpcode();
if (!isCondTransfer(Opc))
continue;
Register DR = MI->getOperand(0).getReg();
Register DR = MI.getOperand(0).getReg();
if (isRegPair(DR))
continue;
MachineOperand &PredOp = MI->getOperand(1);
MachineOperand &PredOp = MI.getOperand(1);
if (PredOp.isUndef())
continue;

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

Expand Down
14 changes: 7 additions & 7 deletions llvm/lib/Target/Hexagon/HexagonHardwareLoops.cpp
Expand Up @@ -1094,15 +1094,15 @@ void HexagonHardwareLoops::removeIfDead(MachineInstr *MI) {
if (!MO.isReg() || !MO.isDef())
continue;
Register Reg = MO.getReg();
MachineRegisterInfo::use_iterator nextI;
for (MachineRegisterInfo::use_iterator I = MRI->use_begin(Reg),
E = MRI->use_end(); I != E; I = nextI) {
nextI = std::next(I); // I is invalidated by the setReg
MachineInstr *UseMI = I->getParent();
// We use make_early_inc_range here because setReg below invalidates the
// iterator.
for (MachineOperand &MO :
llvm::make_early_inc_range(MRI->use_operands(Reg))) {
MachineInstr *UseMI = MO.getParent();
if (UseMI == MI)
continue;
if (I->isDebug())
I->setReg(0U);
if (MO.isDebug())
MO.setReg(0U);
}
}

Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/Hexagon/HexagonISelDAGToDAG.cpp
Expand Up @@ -2247,8 +2247,8 @@ SDValue HexagonDAGToDAGISel::balanceSubTree(SDNode *N, bool TopLevel) {
}

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

Expand Down
6 changes: 2 additions & 4 deletions llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp
Expand Up @@ -1490,10 +1490,8 @@ void PolynomialMultiplyRecognize::cleanupLoopBody(BasicBlock *LoopB) {
if (Value *SV = SimplifyInstruction(&I, {DL, &TLI, &DT}))
I.replaceAllUsesWith(SV);

for (auto I = LoopB->begin(), N = I; I != LoopB->end(); I = N) {
N = std::next(I);
RecursivelyDeleteTriviallyDeadInstructions(&*I, &TLI);
}
for (Instruction &I : llvm::make_early_inc_range(*LoopB))
RecursivelyDeleteTriviallyDeadInstructions(&I, &TLI);
}

unsigned PolynomialMultiplyRecognize::getInverseMxN(unsigned QP) {
Expand Down
4 changes: 1 addition & 3 deletions llvm/lib/Target/Hexagon/HexagonSplitConst32AndConst64.cpp
Expand Up @@ -70,9 +70,7 @@ bool HexagonSplitConst32AndConst64::runOnMachineFunction(MachineFunction &Fn) {

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

if (Opc == Hexagon::CONST32) {
Expand Down
7 changes: 2 additions & 5 deletions llvm/lib/Target/Hexagon/HexagonVLIWPacketizer.cpp
Expand Up @@ -1160,12 +1160,9 @@ bool HexagonPacketizerList::cannotCoexist(const MachineInstr &MI,
void HexagonPacketizerList::unpacketizeSoloInstrs(MachineFunction &MF) {
for (auto &B : MF) {
MachineBasicBlock::iterator BundleIt;
MachineBasicBlock::instr_iterator NextI;
for (auto I = B.instr_begin(), E = B.instr_end(); I != E; I = NextI) {
NextI = std::next(I);
MachineInstr &MI = *I;
for (MachineInstr &MI : llvm::make_early_inc_range(B.instrs())) {
if (MI.isBundle())
BundleIt = I;
BundleIt = MI.getIterator();
if (!MI.isInsideBundle())
continue;

Expand Down

0 comments on commit 2887117

Please sign in to comment.