Skip to content

Commit ddba54e

Browse files
committed
Avoid TLI.getSupportedLibcallImpl
Rewrite to check a (much smaller) list of libcalls
1 parent 97b3cf5 commit ddba54e

File tree

3 files changed

+51
-44
lines changed

3 files changed

+51
-44
lines changed

llvm/lib/Target/AArch64/AArch64FrameLowering.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,27 +1475,25 @@ static bool requiresSaveVG(const MachineFunction &MF) {
14751475
return true;
14761476
}
14771477

1478-
bool isVGInstruction(MachineBasicBlock::iterator MBBI) {
1478+
static bool matchLibcall(const TargetLowering &TLI, const MachineOperand &MO,
1479+
RTLIB::Libcall LC) {
1480+
return MO.isSymbol() && TLI.getLibcallName(LC) == MO.getSymbolName();
1481+
}
1482+
1483+
bool isVGInstruction(MachineBasicBlock::iterator MBBI,
1484+
const TargetLowering &TLI) {
14791485
unsigned Opc = MBBI->getOpcode();
14801486
if (Opc == AArch64::CNTD_XPiI || Opc == AArch64::RDSVLI_XI ||
14811487
Opc == AArch64::UBFMXri)
14821488
return true;
14831489

1484-
if (requiresGetVGCall(*MBBI->getMF())) {
1485-
if (Opc == AArch64::ORRXrr)
1486-
return true;
1490+
if (!requiresGetVGCall(*MBBI->getMF()))
1491+
return false;
14871492

1488-
if (Opc == AArch64::BL) {
1489-
auto Op1 = MBBI->getOperand(0);
1490-
auto &TLI =
1491-
*MBBI->getMF()->getSubtarget<AArch64Subtarget>().getTargetLowering();
1492-
char const *GetCurrentVG =
1493-
TLI.getLibcallName(RTLIB::SMEABI_GET_CURRENT_VG);
1494-
return Op1.isSymbol() && StringRef(Op1.getSymbolName()) == GetCurrentVG;
1495-
}
1496-
}
1493+
if (Opc == AArch64::BL)
1494+
return matchLibcall(TLI, MBBI->getOperand(0), RTLIB::SMEABI_GET_CURRENT_VG);
14971495

1498-
return false;
1496+
return Opc == AArch64::ORRXrr;
14991497
}
15001498

15011499
// Convert callee-save register save/restore instruction to do stack pointer
@@ -1514,9 +1512,11 @@ static MachineBasicBlock::iterator convertCalleeSaveRestoreToSPPrePostIncDec(
15141512
// functions, we need to do this for both the streaming and non-streaming
15151513
// vector length. Move past these instructions if necessary.
15161514
MachineFunction &MF = *MBB.getParent();
1517-
if (requiresSaveVG(MF))
1518-
while (isVGInstruction(MBBI))
1515+
if (requiresSaveVG(MF)) {
1516+
auto &TLI = *MF.getSubtarget().getTargetLowering();
1517+
while (isVGInstruction(MBBI, TLI))
15191518
++MBBI;
1519+
}
15201520

15211521
switch (MBBI->getOpcode()) {
15221522
default:
@@ -2100,11 +2100,12 @@ void AArch64FrameLowering::emitPrologue(MachineFunction &MF,
21002100
// Move past the saves of the callee-saved registers, fixing up the offsets
21012101
// and pre-inc if we decided to combine the callee-save and local stack
21022102
// pointer bump above.
2103+
auto &TLI = *MF.getSubtarget().getTargetLowering();
21032104
while (MBBI != End && MBBI->getFlag(MachineInstr::FrameSetup) &&
21042105
!IsSVECalleeSave(MBBI)) {
21052106
if (CombineSPBump &&
21062107
// Only fix-up frame-setup load/store instructions.
2107-
(!requiresSaveVG(MF) || !isVGInstruction(MBBI)))
2108+
(!requiresSaveVG(MF) || !isVGInstruction(MBBI, TLI)))
21082109
fixupCalleeSaveRestoreStackOffset(*MBBI, AFI->getLocalStackSize(),
21092110
NeedsWinCFI, &HasWinCFI);
21102111
++MBBI;

llvm/lib/Target/AArch64/Utils/AArch64SMEAttributes.cpp

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -81,34 +81,40 @@ SMEAttrs::SMEAttrs(const AttributeList &Attrs) {
8181

8282
void SMEAttrs::addKnownFunctionAttrs(StringRef FuncName,
8383
const TargetLowering &TLI) {
84-
RTLIB::LibcallImpl Impl = TLI.getSupportedLibcallImpl(FuncName);
85-
if (Impl == RTLIB::Unsupported)
86-
return;
87-
RTLIB::Libcall LC = RTLIB::RuntimeLibcallsInfo::getLibcallFromImpl(Impl);
84+
struct SMERoutineAttr {
85+
RTLIB::Libcall LC{RTLIB::UNKNOWN_LIBCALL};
86+
unsigned Attrs{SMEAttrs::Normal};
87+
};
88+
89+
static constexpr unsigned SMCompatiableABIRoutine =
90+
SMEAttrs::SM_Compatible | SMEAttrs::SME_ABI_Routine;
91+
static constexpr unsigned SMCompatiableABIRoutineInZA =
92+
SMCompatiableABIRoutine | encodeZAState(StateValue::In);
93+
94+
// Table of SME routine -> Known attributes.
95+
static constexpr SMERoutineAttr SMERoutineAttrs[]{
96+
{RTLIB::SMEABI_SME_STATE, SMCompatiableABIRoutine},
97+
{RTLIB::SMEABI_TPIDR2_SAVE, SMCompatiableABIRoutine},
98+
{RTLIB::SMEABI_GET_CURRENT_VG, SMCompatiableABIRoutine},
99+
{RTLIB::SMEABI_SME_STATE_SIZE, SMCompatiableABIRoutine},
100+
{RTLIB::SMEABI_SME_SAVE, SMCompatiableABIRoutine},
101+
{RTLIB::SMEABI_SME_RESTORE, SMCompatiableABIRoutine},
102+
{RTLIB::SMEABI_ZA_DISABLE, SMCompatiableABIRoutineInZA},
103+
{RTLIB::SMEABI_TPIDR2_RESTORE, SMCompatiableABIRoutineInZA},
104+
{RTLIB::SC_MEMCPY, SMEAttrs::SM_Compatible},
105+
{RTLIB::SC_MEMMOVE, SMEAttrs::SM_Compatible},
106+
{RTLIB::SC_MEMSET, SMEAttrs::SM_Compatible},
107+
{RTLIB::SC_MEMCHR, SMEAttrs::SM_Compatible},
108+
};
109+
88110
unsigned KnownAttrs = SMEAttrs::Normal;
89-
switch (LC) {
90-
case RTLIB::SMEABI_SME_STATE:
91-
case RTLIB::SMEABI_TPIDR2_SAVE:
92-
case RTLIB::SMEABI_GET_CURRENT_VG:
93-
case RTLIB::SMEABI_SME_STATE_SIZE:
94-
case RTLIB::SMEABI_SME_SAVE:
95-
case RTLIB::SMEABI_SME_RESTORE:
96-
KnownAttrs |= SMEAttrs::SM_Compatible | SMEAttrs::SME_ABI_Routine;
97-
break;
98-
case RTLIB::SMEABI_ZA_DISABLE:
99-
case RTLIB::SMEABI_TPIDR2_RESTORE:
100-
KnownAttrs |= SMEAttrs::SM_Compatible | encodeZAState(StateValue::In) |
101-
SMEAttrs::SME_ABI_Routine;
102-
break;
103-
case RTLIB::SC_MEMCPY:
104-
case RTLIB::SC_MEMMOVE:
105-
case RTLIB::SC_MEMSET:
106-
case RTLIB::SC_MEMCHR:
107-
KnownAttrs |= SMEAttrs::SM_Compatible;
108-
break;
109-
default:
110-
break;
111+
for (auto [LC, Attrs] : SMERoutineAttrs) {
112+
if (TLI.getLibcallName(LC) == FuncName) {
113+
KnownAttrs = Attrs;
114+
break;
115+
}
111116
}
117+
112118
set(KnownAttrs);
113119
}
114120

llvm/lib/Target/AArch64/Utils/AArch64SMEAttributes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class SMEAttrs {
8484
static StateValue decodeZAState(unsigned Bitmask) {
8585
return static_cast<StateValue>((Bitmask & ZA_Mask) >> ZA_Shift);
8686
}
87-
static unsigned encodeZAState(StateValue S) {
87+
static constexpr unsigned encodeZAState(StateValue S) {
8888
return static_cast<unsigned>(S) << ZA_Shift;
8989
}
9090

0 commit comments

Comments
 (0)