Skip to content

Commit 5d3b95e

Browse files
arsenmdvbuka
authored andcommitted
AArch64: Use RuntimeLibcallsInfo in SMEAttributes (NFC) (llvm#164968)
Eventually this should be program state, and not part of TargetLowering so avoid direct references to the libcall functions in it. The usage of RuntimeLibcallsInfo here is not good though, particularly the use through TargetTransformInfo. It would be better if the IR attributes were directly encoded in the libcall definition (or at least made consistent elsewhere). The parsing of the attributes should not also be responsible for doing the libcall recognition, which is the only part pulling in the dependency.
1 parent b6e337d commit 5d3b95e

File tree

5 files changed

+30
-21
lines changed

5 files changed

+30
-21
lines changed

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3576,6 +3576,10 @@ class LLVM_ABI TargetLoweringBase {
35763576
return nullptr;
35773577
}
35783578

3579+
const RTLIB::RuntimeLibcallsInfo &getRuntimeLibcallsInfo() const {
3580+
return Libcalls;
3581+
}
3582+
35793583
void setLibcallImpl(RTLIB::Libcall Call, RTLIB::LibcallImpl Impl) {
35803584
Libcalls.setLibcallImpl(Call, Impl);
35813585
}

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9002,12 +9002,12 @@ static void analyzeCallOperands(const AArch64TargetLowering &TLI,
90029002
}
90039003

90049004
static SMECallAttrs
9005-
getSMECallAttrs(const Function &Caller, const AArch64TargetLowering &TLI,
9005+
getSMECallAttrs(const Function &Caller, const RTLIB::RuntimeLibcallsInfo &RTLCI,
90069006
const TargetLowering::CallLoweringInfo &CLI) {
90079007
if (CLI.CB)
9008-
return SMECallAttrs(*CLI.CB, &TLI);
9008+
return SMECallAttrs(*CLI.CB, &RTLCI);
90099009
if (auto *ES = dyn_cast<ExternalSymbolSDNode>(CLI.Callee))
9010-
return SMECallAttrs(SMEAttrs(Caller), SMEAttrs(ES->getSymbol(), TLI));
9010+
return SMECallAttrs(SMEAttrs(Caller), SMEAttrs(ES->getSymbol(), RTLCI));
90119011
return SMECallAttrs(SMEAttrs(Caller), SMEAttrs(SMEAttrs::Normal));
90129012
}
90139013

@@ -9029,7 +9029,8 @@ bool AArch64TargetLowering::isEligibleForTailCallOptimization(
90299029

90309030
// SME Streaming functions are not eligible for TCO as they may require
90319031
// the streaming mode or ZA to be restored after returning from the call.
9032-
SMECallAttrs CallAttrs = getSMECallAttrs(CallerF, *this, CLI);
9032+
SMECallAttrs CallAttrs =
9033+
getSMECallAttrs(CallerF, getRuntimeLibcallsInfo(), CLI);
90339034
if (CallAttrs.requiresSMChange() || CallAttrs.requiresLazySave() ||
90349035
CallAttrs.requiresPreservingAllZAState() ||
90359036
CallAttrs.caller().hasStreamingBody())
@@ -9454,7 +9455,8 @@ AArch64TargetLowering::LowerCall(CallLoweringInfo &CLI,
94549455
}
94559456

94569457
// Determine whether we need any streaming mode changes.
9457-
SMECallAttrs CallAttrs = getSMECallAttrs(MF.getFunction(), *this, CLI);
9458+
SMECallAttrs CallAttrs =
9459+
getSMECallAttrs(MF.getFunction(), getRuntimeLibcallsInfo(), CLI);
94589460

94599461
std::optional<unsigned> ZAMarkerNode;
94609462
bool UseNewSMEABILowering = getTM().useNewSMEABILowering();
@@ -29818,7 +29820,7 @@ bool AArch64TargetLowering::fallBackToDAGISel(const Instruction &Inst) const {
2981829820

2981929821
// Checks to allow the use of SME instructions
2982029822
if (auto *Base = dyn_cast<CallBase>(&Inst)) {
29821-
auto CallAttrs = SMECallAttrs(*Base, this);
29823+
auto CallAttrs = SMECallAttrs(*Base, &getRuntimeLibcallsInfo());
2982229824
if (CallAttrs.requiresSMChange() || CallAttrs.requiresLazySave() ||
2982329825
CallAttrs.requiresPreservingZT0() ||
2982429826
CallAttrs.requiresPreservingAllZAState())

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ static cl::opt<bool> EnableScalableAutovecInStreamingMode(
224224
static bool isSMEABIRoutineCall(const CallInst &CI,
225225
const AArch64TargetLowering &TLI) {
226226
const auto *F = CI.getCalledFunction();
227-
return F && SMEAttrs(F->getName(), TLI).isSMEABIRoutine();
227+
return F &&
228+
SMEAttrs(F->getName(), TLI.getRuntimeLibcallsInfo()).isSMEABIRoutine();
228229
}
229230

230231
/// Returns true if the function has explicit operations that can only be
@@ -355,7 +356,7 @@ AArch64TTIImpl::getInlineCallPenalty(const Function *F, const CallBase &Call,
355356
// change only once and avoid inlining of G into F.
356357

357358
SMEAttrs FAttrs(*F);
358-
SMECallAttrs CallAttrs(Call, getTLI());
359+
SMECallAttrs CallAttrs(Call, &getTLI()->getRuntimeLibcallsInfo());
359360

360361
if (SMECallAttrs(FAttrs, CallAttrs.callee()).requiresSMChange()) {
361362
if (F == Call.getCaller()) // (1)

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ SMEAttrs::SMEAttrs(const AttributeList &Attrs) {
7575
}
7676

7777
void SMEAttrs::addKnownFunctionAttrs(StringRef FuncName,
78-
const AArch64TargetLowering &TLI) {
79-
RTLIB::LibcallImpl Impl = TLI.getSupportedLibcallImpl(FuncName);
78+
const RTLIB::RuntimeLibcallsInfo &RTLCI) {
79+
RTLIB::LibcallImpl Impl = RTLCI.getSupportedLibcallImpl(FuncName);
8080
if (Impl == RTLIB::Unsupported)
8181
return;
8282
unsigned KnownAttrs = SMEAttrs::Normal;
@@ -124,11 +124,12 @@ bool SMECallAttrs::requiresSMChange() const {
124124
return true;
125125
}
126126

127-
SMECallAttrs::SMECallAttrs(const CallBase &CB, const AArch64TargetLowering *TLI)
127+
SMECallAttrs::SMECallAttrs(const CallBase &CB,
128+
const RTLIB::RuntimeLibcallsInfo *RTLCI)
128129
: CallerFn(*CB.getFunction()), CalledFn(SMEAttrs::Normal),
129130
Callsite(CB.getAttributes()), IsIndirect(CB.isIndirectCall()) {
130131
if (auto *CalledFunction = CB.getCalledFunction())
131-
CalledFn = SMEAttrs(*CalledFunction, TLI);
132+
CalledFn = SMEAttrs(*CalledFunction, RTLCI);
132133

133134
// An `invoke` of an agnostic ZA function may not return normally (it may
134135
// resume in an exception block). In this case, it acts like a private ZA

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
#include "llvm/IR/Function.h"
1313

1414
namespace llvm {
15-
16-
class AArch64TargetLowering;
15+
namespace RTLIB {
16+
struct RuntimeLibcallsInfo;
17+
}
1718

1819
class Function;
1920
class CallBase;
@@ -52,14 +53,14 @@ class SMEAttrs {
5253

5354
SMEAttrs() = default;
5455
SMEAttrs(unsigned Mask) { set(Mask); }
55-
SMEAttrs(const Function &F, const AArch64TargetLowering *TLI = nullptr)
56+
SMEAttrs(const Function &F, const RTLIB::RuntimeLibcallsInfo *RTLCI = nullptr)
5657
: SMEAttrs(F.getAttributes()) {
57-
if (TLI)
58-
addKnownFunctionAttrs(F.getName(), *TLI);
58+
if (RTLCI)
59+
addKnownFunctionAttrs(F.getName(), *RTLCI);
5960
}
6061
SMEAttrs(const AttributeList &L);
61-
SMEAttrs(StringRef FuncName, const AArch64TargetLowering &TLI) {
62-
addKnownFunctionAttrs(FuncName, TLI);
62+
SMEAttrs(StringRef FuncName, const RTLIB::RuntimeLibcallsInfo &RTLCI) {
63+
addKnownFunctionAttrs(FuncName, RTLCI);
6364
};
6465

6566
void set(unsigned M, bool Enable = true) {
@@ -157,7 +158,7 @@ class SMEAttrs {
157158

158159
private:
159160
void addKnownFunctionAttrs(StringRef FuncName,
160-
const AArch64TargetLowering &TLI);
161+
const RTLIB::RuntimeLibcallsInfo &RTLCI);
161162
void validate() const;
162163
};
163164

@@ -175,7 +176,7 @@ class SMECallAttrs {
175176
SMEAttrs Callsite = SMEAttrs::Normal)
176177
: CallerFn(Caller), CalledFn(Callee), Callsite(Callsite) {}
177178

178-
SMECallAttrs(const CallBase &CB, const AArch64TargetLowering *TLI);
179+
SMECallAttrs(const CallBase &CB, const RTLIB::RuntimeLibcallsInfo *RTLCI);
179180

180181
SMEAttrs &caller() { return CallerFn; }
181182
SMEAttrs &callee() { return IsIndirect ? Callsite : CalledFn; }

0 commit comments

Comments
 (0)