Skip to content

Commit f097377

Browse files
committed
[AArch64] Prepare for split ZPR and PPR area allocation (NFCI)
This patch attempts to refactor AArch64FrameLowering to allow the size of the ZPR and PPR areas to be calculated separately. This will be used by a subsequent patch to support allocating ZPRs and PPRs to separate areas. This patch should be an NFC and is split out to make later functional changes easier to spot.
1 parent 11b0cf8 commit f097377

8 files changed

+288
-173
lines changed

llvm/lib/Target/AArch64/AArch64FrameLowering.cpp

Lines changed: 126 additions & 94 deletions
Large diffs are not rendered by default.

llvm/lib/Target/AArch64/AArch64FrameLowering.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ class AArch64FunctionInfo;
2424
class AArch64PrologueEmitter;
2525
class AArch64EpilogueEmitter;
2626

27+
struct SVEStackSizes {
28+
uint64_t ZPRStackSize{0};
29+
uint64_t PPRStackSize{0};
30+
};
31+
2732
class AArch64FrameLowering : public TargetFrameLowering {
2833
public:
2934
explicit AArch64FrameLowering()
@@ -147,7 +152,16 @@ class AArch64FrameLowering : public TargetFrameLowering {
147152

148153
bool requiresSaveVG(const MachineFunction &MF) const;
149154

150-
StackOffset getSVEStackSize(const MachineFunction &MF) const;
155+
/// Returns the size of the entire ZPR stackframe (calleesaves + spills).
156+
StackOffset getZPRStackSize(const MachineFunction &MF) const;
157+
158+
/// Returns the size of the entire PPR stackframe (calleesaves + spills).
159+
StackOffset getPPRStackSize(const MachineFunction &MF) const;
160+
161+
/// Returns the size of the entire SVE stackframe (PPRs + ZPRs).
162+
StackOffset getSVEStackSize(const MachineFunction &MF) const {
163+
return getZPRStackSize(MF) + getPPRStackSize(MF);
164+
}
151165

152166
friend class AArch64PrologueEpilogueCommon;
153167
friend class AArch64PrologueEmitter;
@@ -167,10 +181,6 @@ class AArch64FrameLowering : public TargetFrameLowering {
167181
/// Returns true if CSRs should be paired.
168182
bool producePairRegisters(MachineFunction &MF) const;
169183

170-
int64_t estimateSVEStackObjectOffsets(MachineFrameInfo &MF) const;
171-
int64_t assignSVEStackObjectOffsets(MachineFrameInfo &MF,
172-
int &MinCSFrameIndex,
173-
int &MaxCSFrameIndex) const;
174184
/// Make a determination whether a Hazard slot is used and create it if
175185
/// needed.
176186
void determineStackHazardSlot(MachineFunction &MF,

llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,21 @@
2323

2424
using namespace llvm;
2525

26+
static std::optional<uint64_t>
27+
getSVEStackSize(const AArch64FunctionInfo &MFI,
28+
uint64_t (AArch64FunctionInfo::*GetStackSize)() const) {
29+
if (!MFI.hasCalculatedStackSizeSVE())
30+
return std::nullopt;
31+
return (MFI.*GetStackSize)();
32+
}
33+
2634
yaml::AArch64FunctionInfo::AArch64FunctionInfo(
2735
const llvm::AArch64FunctionInfo &MFI)
2836
: HasRedZone(MFI.hasRedZone()),
29-
StackSizeSVE(MFI.hasCalculatedStackSizeSVE()
30-
? std::optional<uint64_t>(MFI.getStackSizeSVE())
31-
: std::nullopt),
37+
StackSizeZPR(
38+
getSVEStackSize(MFI, &llvm::AArch64FunctionInfo::getStackSizeZPR)),
39+
StackSizePPR(
40+
getSVEStackSize(MFI, &llvm::AArch64FunctionInfo::getStackSizePPR)),
3241
HasStackFrame(MFI.hasStackFrame()
3342
? std::optional<bool>(MFI.hasStackFrame())
3443
: std::nullopt) {}
@@ -41,8 +50,9 @@ void AArch64FunctionInfo::initializeBaseYamlFields(
4150
const yaml::AArch64FunctionInfo &YamlMFI) {
4251
if (YamlMFI.HasRedZone)
4352
HasRedZone = YamlMFI.HasRedZone;
44-
if (YamlMFI.StackSizeSVE)
45-
setStackSizeSVE(*YamlMFI.StackSizeSVE);
53+
if (YamlMFI.StackSizeZPR || YamlMFI.StackSizePPR)
54+
setStackSizeSVE(YamlMFI.StackSizeZPR.value_or(0),
55+
YamlMFI.StackSizePPR.value_or(0));
4656
if (YamlMFI.HasStackFrame)
4757
setHasStackFrame(*YamlMFI.HasStackFrame);
4858
}

llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.h

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,10 @@ class AArch64FunctionInfo final : public MachineFunctionInfo {
7474
/// Amount of stack frame size, not including callee-saved registers.
7575
uint64_t LocalStackSize = 0;
7676

77-
/// The start and end frame indices for the SVE callee saves.
78-
int MinSVECSFrameIndex = 0;
79-
int MaxSVECSFrameIndex = 0;
80-
8177
/// Amount of stack frame size used for saving callee-saved registers.
8278
unsigned CalleeSavedStackSize = 0;
83-
unsigned SVECalleeSavedStackSize = 0;
79+
unsigned ZPRCalleeSavedStackSize = 0;
80+
unsigned PPRCalleeSavedStackSize = 0;
8481
bool HasCalleeSavedStackSize = false;
8582
bool HasSVECalleeSavedStackSize = false;
8683

@@ -137,9 +134,10 @@ class AArch64FunctionInfo final : public MachineFunctionInfo {
137134
/// SVE stack size (for predicates and data vectors) are maintained here
138135
/// rather than in FrameInfo, as the placement and Stack IDs are target
139136
/// specific.
140-
uint64_t StackSizeSVE = 0;
137+
uint64_t StackSizeZPR = 0;
138+
uint64_t StackSizePPR = 0;
141139

142-
/// HasCalculatedStackSizeSVE indicates whether StackSizeSVE is valid.
140+
/// HasCalculatedStackSizeSVE indicates whether StackSizeZPR/PPR is valid.
143141
bool HasCalculatedStackSizeSVE = false;
144142

145143
/// Has a value when it is known whether or not the function uses a
@@ -312,16 +310,25 @@ class AArch64FunctionInfo final : public MachineFunctionInfo {
312310
TailCallReservedStack = bytes;
313311
}
314312

315-
bool hasCalculatedStackSizeSVE() const { return HasCalculatedStackSizeSVE; }
316-
317-
void setStackSizeSVE(uint64_t S) {
313+
void setStackSizeSVE(uint64_t ZPR, uint64_t PPR) {
314+
StackSizeZPR = ZPR;
315+
StackSizePPR = PPR;
318316
HasCalculatedStackSizeSVE = true;
319-
StackSizeSVE = S;
320317
}
321318

322-
uint64_t getStackSizeSVE() const {
319+
uint64_t getStackSizeZPR() const {
323320
assert(hasCalculatedStackSizeSVE());
324-
return StackSizeSVE;
321+
return StackSizeZPR;
322+
}
323+
uint64_t getStackSizePPR() const {
324+
assert(hasCalculatedStackSizeSVE());
325+
return StackSizePPR;
326+
}
327+
328+
bool hasCalculatedStackSizeSVE() const { return HasCalculatedStackSizeSVE; }
329+
330+
bool hasSVEStackSize() const {
331+
return getStackSizeZPR() > 0 || getStackSizePPR() > 0;
325332
}
326333

327334
bool hasStackFrame() const { return HasStackFrame; }
@@ -414,23 +421,25 @@ class AArch64FunctionInfo final : public MachineFunctionInfo {
414421
}
415422

416423
// Saves the CalleeSavedStackSize for SVE vectors in 'scalable bytes'
417-
void setSVECalleeSavedStackSize(unsigned Size) {
418-
SVECalleeSavedStackSize = Size;
424+
void setSVECalleeSavedStackSize(unsigned ZPR, unsigned PPR) {
425+
ZPRCalleeSavedStackSize = ZPR;
426+
PPRCalleeSavedStackSize = PPR;
419427
HasSVECalleeSavedStackSize = true;
420428
}
421-
unsigned getSVECalleeSavedStackSize() const {
429+
unsigned getZPRCalleeSavedStackSize() const {
422430
assert(HasSVECalleeSavedStackSize &&
423-
"SVECalleeSavedStackSize has not been calculated");
424-
return SVECalleeSavedStackSize;
431+
"ZPRCalleeSavedStackSize has not been calculated");
432+
return ZPRCalleeSavedStackSize;
425433
}
426-
427-
void setMinMaxSVECSFrameIndex(int Min, int Max) {
428-
MinSVECSFrameIndex = Min;
429-
MaxSVECSFrameIndex = Max;
434+
unsigned getPPRCalleeSavedStackSize() const {
435+
assert(HasSVECalleeSavedStackSize &&
436+
"PPRCalleeSavedStackSize has not been calculated");
437+
return PPRCalleeSavedStackSize;
430438
}
431439

432-
int getMinSVECSFrameIndex() const { return MinSVECSFrameIndex; }
433-
int getMaxSVECSFrameIndex() const { return MaxSVECSFrameIndex; }
440+
unsigned getSVECalleeSavedStackSize() const {
441+
return getZPRCalleeSavedStackSize() + getPPRCalleeSavedStackSize();
442+
}
434443

435444
void incNumLocalDynamicTLSAccesses() { ++NumLocalDynamicTLSAccesses; }
436445
unsigned getNumLocalDynamicTLSAccesses() const {
@@ -611,7 +620,8 @@ class AArch64FunctionInfo final : public MachineFunctionInfo {
611620
namespace yaml {
612621
struct AArch64FunctionInfo final : public yaml::MachineFunctionInfo {
613622
std::optional<bool> HasRedZone;
614-
std::optional<uint64_t> StackSizeSVE;
623+
std::optional<uint64_t> StackSizeZPR;
624+
std::optional<uint64_t> StackSizePPR;
615625
std::optional<bool> HasStackFrame;
616626

617627
AArch64FunctionInfo() = default;
@@ -624,7 +634,8 @@ struct AArch64FunctionInfo final : public yaml::MachineFunctionInfo {
624634
template <> struct MappingTraits<AArch64FunctionInfo> {
625635
static void mapping(IO &YamlIO, AArch64FunctionInfo &MFI) {
626636
YamlIO.mapOptional("hasRedZone", MFI.HasRedZone);
627-
YamlIO.mapOptional("stackSizeSVE", MFI.StackSizeSVE);
637+
YamlIO.mapOptional("stackSizeZPR", MFI.StackSizeZPR);
638+
YamlIO.mapOptional("stackSizePPR", MFI.StackSizePPR);
628639
YamlIO.mapOptional("hasStackFrame", MFI.HasStackFrame);
629640
}
630641
};

0 commit comments

Comments
 (0)