@@ -1464,59 +1464,27 @@ void PEI::replaceFrameIndicesBackward(MachineBasicBlock *BB,
1464
1464
RS->enterBasicBlockEnd (*BB);
1465
1465
1466
1466
for (MachineInstr &MI : make_early_inc_range (reverse (*BB))) {
1467
+ // Step backwards to get the liveness state at (immedately after) MI.
1468
+ RS->backward (MI);
1467
1469
1468
- // Register scavenger backward step
1469
- MachineBasicBlock::iterator Step (MI);
1470
1470
for (unsigned i = 0 ; i != MI.getNumOperands (); ++i) {
1471
1471
if (!MI.getOperand (i).isFI ())
1472
1472
continue ;
1473
1473
1474
1474
if (replaceFrameIndexDebugInstr (MF, MI, i, SPAdj))
1475
1475
continue ;
1476
1476
1477
- // If this instruction has a FrameIndex operand, we need to
1478
- // use that target machine register info object to eliminate
1479
- // it.
1480
-
1481
- // TRI.eliminateFrameIndex may lower the frame index to a sequence of
1482
- // instructions. It also can remove/change instructions passed by the
1483
- // iterator and invalidate the iterator. We have to take care of this. For
1484
- // that we support two iterators: *Step* - points to the position up to
1485
- // which the scavenger should scan by the next iteration to have liveness
1486
- // information up to date. *Curr* - keeps track of the correct RS->MBBI -
1487
- // the scan start point. It points to the currently processed instruction
1488
- // right before the frame lowering.
1477
+ // Eliminate this FrameIndex operand.
1489
1478
//
1490
- // ITERATORS WORK AS FOLLOWS:
1491
- // *Step* is shifted one step back right before the frame lowering and
1492
- // one step forward right after it. No matter how many instructions were
1493
- // inserted, *Step* will be right after the position which is going to be
1494
- // processed in the next iteration, thus, in the correct position for the
1495
- // scavenger to go up to.
1496
- // *Curr* is shifted one step forward right before calling
1497
- // TRI.eliminateFrameIndex and one step backward after. Thus, we make sure
1498
- // it points right to the position that is the correct starting point for
1499
- // the scavenger to scan.
1500
- MachineBasicBlock::iterator Curr = ++RS->getCurrentPosition ();
1501
-
1502
- // Shift back
1503
- --Step;
1504
-
1479
+ // Save and restore the scavenger's position around the call to
1480
+ // eliminateFrameIndex in case it erases MI and invalidates the iterator.
1481
+ MachineBasicBlock::iterator Save = std::next (RS->getCurrentPosition ());
1505
1482
bool Removed = TRI.eliminateFrameIndex (MI, SPAdj, i, RS);
1506
- // Restore to unify logic with a shift back that happens in the end of
1507
- // the outer loop.
1508
- ++Step;
1509
- RS->skipTo (--Curr);
1483
+ RS->skipTo (std::prev (Save));
1484
+
1510
1485
if (Removed)
1511
1486
break ;
1512
1487
}
1513
-
1514
- // Shift it to make RS collect reg info up to the current instruction.
1515
- if (Step != BB->begin ())
1516
- Step--;
1517
-
1518
- // Update register states.
1519
- RS->backward (Step);
1520
1488
}
1521
1489
}
1522
1490
0 commit comments