Skip to content

Commit 6f0d4e2

Browse files
committed
[AArch64][NFC] Switch to LiveRegUnits
1 parent cfadf3f commit 6f0d4e2

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

llvm/lib/Target/AArch64/AArch64FrameLowering.cpp

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@
197197
#include "llvm/ADT/SmallVector.h"
198198
#include "llvm/ADT/Statistic.h"
199199
#include "llvm/CodeGen/LivePhysRegs.h"
200+
#include "llvm/CodeGen/LiveRegUnits.h"
200201
#include "llvm/CodeGen/MachineBasicBlock.h"
201202
#include "llvm/CodeGen/MachineFrameInfo.h"
202203
#include "llvm/CodeGen/MachineFunction.h"
@@ -988,7 +989,7 @@ void AArch64FrameLowering::emitZeroCallUsedRegs(BitVector RegsToZero,
988989
}
989990
}
990991

991-
static void getLiveRegsForEntryMBB(LivePhysRegs &LiveRegs,
992+
static void getLiveRegsForEntryMBB(LiveRegUnits &LiveRegs,
992993
const MachineBasicBlock &MBB) {
993994
const MachineFunction *MF = MBB.getParent();
994995
LiveRegs.addLiveIns(MBB);
@@ -1011,23 +1012,20 @@ static void getLiveRegsForEntryMBB(LivePhysRegs &LiveRegs,
10111012
// doesn't seem worth the benefit.
10121013
static Register findScratchNonCalleeSaveRegister(MachineBasicBlock *MBB) {
10131014
MachineFunction *MF = MBB->getParent();
1014-
1015-
// If MBB is an entry block, use X9 as the scratch register
1016-
if (&MF->front() == MBB)
1017-
return AArch64::X9;
1018-
10191015
const AArch64Subtarget &Subtarget = MF->getSubtarget<AArch64Subtarget>();
10201016
const AArch64RegisterInfo &TRI = *Subtarget.getRegisterInfo();
1021-
LivePhysRegs LiveRegs(TRI);
1017+
LiveRegUnits LiveRegs(TRI);
10221018
getLiveRegsForEntryMBB(LiveRegs, *MBB);
10231019

10241020
// Prefer X9 since it was historically used for the prologue scratch reg.
1025-
const MachineRegisterInfo &MRI = MF->getRegInfo();
1026-
if (LiveRegs.available(MRI, AArch64::X9))
1021+
if (LiveRegs.available(AArch64::X9))
10271022
return AArch64::X9;
10281023

1029-
for (unsigned Reg : AArch64::GPR64RegClass) {
1030-
if (LiveRegs.available(MRI, Reg))
1024+
BitVector Allocatable =
1025+
TRI.getAllocatableSet(*MF, TRI.getRegClass(AArch64::GPR64RegClassID));
1026+
1027+
for (unsigned Reg : Allocatable.set_bits()) {
1028+
if (LiveRegs.available(Reg))
10311029
return Reg;
10321030
}
10331031
return AArch64::NoRegister;
@@ -1043,14 +1041,11 @@ bool AArch64FrameLowering::canUseAsPrologue(
10431041
const AArch64FunctionInfo *AFI = MF->getInfo<AArch64FunctionInfo>();
10441042

10451043
if (AFI->hasSwiftAsyncContext()) {
1046-
const AArch64RegisterInfo &TRI = *Subtarget.getRegisterInfo();
1047-
const MachineRegisterInfo &MRI = MF->getRegInfo();
1048-
LivePhysRegs LiveRegs(TRI);
1044+
LiveRegUnits LiveRegs(*RegInfo);
10491045
getLiveRegsForEntryMBB(LiveRegs, MBB);
10501046
// The StoreSwiftAsyncContext clobbers X16 and X17. Make sure they are
10511047
// available.
1052-
if (!LiveRegs.available(MRI, AArch64::X16) ||
1053-
!LiveRegs.available(MRI, AArch64::X17))
1048+
if (!LiveRegs.available(AArch64::X16) || !LiveRegs.available(AArch64::X17))
10541049
return false;
10551050
}
10561051

@@ -1603,7 +1598,7 @@ static void emitDefineCFAWithFP(MachineFunction &MF, MachineBasicBlock &MBB,
16031598
/// Collect live registers from the end of \p MI's parent up to (including) \p
16041599
/// MI in \p LiveRegs.
16051600
static void getLivePhysRegsUpTo(MachineInstr &MI, const TargetRegisterInfo &TRI,
1606-
LivePhysRegs &LiveRegs) {
1601+
LiveRegUnits &LiveRegs) {
16071602

16081603
MachineBasicBlock &MBB = *MI.getParent();
16091604
LiveRegs.addLiveOuts(MBB);
@@ -1641,7 +1636,7 @@ void AArch64FrameLowering::emitPrologue(MachineFunction &MF,
16411636
NonFrameStart->getFlag(MachineInstr::FrameSetup))
16421637
++NonFrameStart;
16431638

1644-
LivePhysRegs LiveRegs(*TRI);
1639+
LiveRegUnits LiveRegs(*TRI);
16451640
if (NonFrameStart != MBB.end()) {
16461641
getLivePhysRegsUpTo(*NonFrameStart, *TRI, LiveRegs);
16471642
// Ignore registers used for stack management for now.
@@ -1659,7 +1654,7 @@ void AArch64FrameLowering::emitPrologue(MachineFunction &MF,
16591654
make_range(MBB.instr_begin(), NonFrameStart->getIterator())) {
16601655
for (auto &Op : MI.operands())
16611656
if (Op.isReg() && Op.isDef())
1662-
assert(!LiveRegs.contains(Op.getReg()) &&
1657+
assert(LiveRegs.available(Op.getReg()) &&
16631658
"live register clobbered by inserted prologue instructions");
16641659
}
16651660
});
@@ -4014,7 +4009,7 @@ MachineBasicBlock::iterator tryMergeAdjacentSTG(MachineBasicBlock::iterator II,
40144009
// FIXME : This approach of bailing out from merge is conservative in
40154010
// some ways like even if stg loops are not present after merge the
40164011
// insert list, this liveness check is done (which is not needed).
4017-
LivePhysRegs LiveRegs(*(MBB->getParent()->getSubtarget().getRegisterInfo()));
4012+
LiveRegUnits LiveRegs(*(MBB->getParent()->getSubtarget().getRegisterInfo()));
40184013
LiveRegs.addLiveOuts(*MBB);
40194014
for (auto I = MBB->rbegin();; ++I) {
40204015
MachineInstr &MI = *I;
@@ -4023,7 +4018,7 @@ MachineBasicBlock::iterator tryMergeAdjacentSTG(MachineBasicBlock::iterator II,
40234018
LiveRegs.stepBackward(*I);
40244019
}
40254020
InsertI++;
4026-
if (LiveRegs.contains(AArch64::NZCV))
4021+
if (!LiveRegs.available(AArch64::NZCV))
40274022
return InsertI;
40284023

40294024
llvm::stable_sort(Instrs,

0 commit comments

Comments
 (0)