Skip to content

Commit

Permalink
[AArch64] Avoid RegScavenger::forward in AArch64SpeculationHardening
Browse files Browse the repository at this point in the history
RegScavenger::backward is preferred because it does not rely on accurate
kill flags.

Differential Revision: https://reviews.llvm.org/D150560
  • Loading branch information
jayfoad committed May 23, 2023
1 parent 47d30de commit 910af0e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions llvm/lib/Target/AArch64/AArch64SpeculationHardening.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,18 +286,20 @@ bool AArch64SpeculationHardening::instrumentControlFlow(
bool TmpRegisterNotAvailableEverywhere = false;

RegScavenger RS;
RS.enterBasicBlock(MBB);
RS.enterBasicBlockEnd(MBB);

for (MachineBasicBlock::iterator I = MBB.begin(); I != MBB.end(); I++) {
MachineInstr &MI = *I;
for (MachineBasicBlock::iterator I = MBB.end(); I != MBB.begin(); ) {
MachineInstr &MI = *--I;
if (!MI.isReturn() && !MI.isCall())
continue;

// The RegScavenger represents registers available *after* the MI
// instruction pointed to by RS.getCurrentPosition().
// We need to have a register that is available *before* the MI is executed.
if (I != MBB.begin())
RS.forward(std::prev(I));
if (I == MBB.begin())
RS.enterBasicBlock(MBB);
else
RS.backward(std::prev(I));
// FIXME: The below just finds *a* unused register. Maybe code could be
// optimized more if this looks for the register that isn't used for the
// longest time around this place, to enable more scheduling freedom. Not
Expand Down

0 comments on commit 910af0e

Please sign in to comment.