Skip to content

Commit fd56aa3

Browse files
- Removed calls to needsUnwindTableEntry() so that VG is always
spilled if there are streaming mode changes in the function. - Added requiresVGSpill() to AArch64MachineFunctionInfo which returns true if the function has streaming mode changes and hasSVE is true. With this change, we will no longer spill VG at the beginning of functions if the target does not also have SVE. - Removed SpilledStreamingVG flag from spillCalleeSavedRegisters. - Rebased to include recent changes to the changeStreamingMode interface.
1 parent dab8ab8 commit fd56aa3

8 files changed

+385
-272
lines changed

llvm/lib/Target/AArch64/AArch64ExpandPseudoInsts.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1559,7 +1559,7 @@ bool AArch64ExpandPseudo::expandMI(MachineBasicBlock &MBB,
15591559
const AArch64FunctionInfo *AFI = MF.getInfo<AArch64FunctionInfo>();
15601560

15611561
if ((!FuncAttrs.hasStreamingBody() && FuncAttrs.hasStreamingInterface()) ||
1562-
!AFI->hasStreamingModeChanges())
1562+
!AFI->requiresVGSpill(MF))
15631563
return false;
15641564

15651565
int64_t StreamingVGIdx = AFI->getStreamingVGIdx();

llvm/lib/Target/AArch64/AArch64FrameLowering.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ bool AArch64FrameLowering::homogeneousPrologEpilog(
321321
return false;
322322

323323
auto *AFI = MF.getInfo<AArch64FunctionInfo>();
324-
if (AFI->hasSwiftAsyncContext() || AFI->hasStreamingModeChanges())
324+
if (AFI->hasSwiftAsyncContext() || AFI->requiresVGSpill(MF))
325325
return false;
326326

327327
// If there are an odd number of GPRs before LR and FP in the CSRs list,
@@ -567,7 +567,7 @@ void AArch64FrameLowering::emitCalleeSavedGPRLocations(
567567
continue;
568568

569569
assert(!Info.isSpilledToReg() && "Spilling to registers not implemented");
570-
unsigned DwarfReg = TRI.getDwarfRegNum(Info.getReg(), true);
570+
int64_t DwarfReg = TRI.getDwarfRegNum(Info.getReg(), true);
571571
int64_t Offset = MFI.getObjectOffset(FrameIdx) - getOffsetOfLocalArea();
572572

573573
// Locally streaming functions save two values for VG, but we should only
@@ -1361,8 +1361,9 @@ static MachineBasicBlock::iterator convertCalleeSaveRestoreToSPPrePostIncDec(
13611361
// vector length. Move past these instructions if necessary.
13621362
unsigned Opc = MBBI->getOpcode();
13631363
if (Opc == AArch64::CNTD_XPiI || Opc == AArch64::RDSVLI_XI) {
1364-
AArch64FunctionInfo AFI = *MBB.getParent()->getInfo<AArch64FunctionInfo>();
1365-
assert(AFI.hasStreamingModeChanges() &&
1364+
MachineFunction &MF = *MBB.getParent();
1365+
AArch64FunctionInfo *AFI = MF.getInfo<AArch64FunctionInfo>();
1366+
assert(AFI->requiresVGSpill(MF) &&
13661367
"Unexpected callee-save save/restore opcode!");
13671368
++MBBI;
13681369
if (MBBI->getOpcode() == AArch64::UBFMXri)
@@ -1862,10 +1863,11 @@ void AArch64FrameLowering::emitPrologue(MachineFunction &MF,
18621863
!IsSVECalleeSave(MBBI)) {
18631864
unsigned Opc = MBBI->getOpcode();
18641865
// Move past instructions generated to calculate VG
1865-
if (Opc == AArch64::CNTD_XPiI || Opc == AArch64::RDSVLI_XI ||
1866-
Opc == AArch64::UBFMXri) {
1867-
assert(AFI->hasStreamingModeChanges() && "Unexpected opcode!");
1866+
if (Opc == AArch64::CNTD_XPiI || Opc == AArch64::RDSVLI_XI) {
1867+
assert(AFI->requiresVGSpill(MF) && "Unexpected opcode!");
18681868
++MBBI;
1869+
if (MBBI->getOpcode() == AArch64::UBFMXri)
1870+
++MBBI;
18691871
}
18701872
if (CombineSPBump)
18711873
fixupCalleeSaveRestoreStackOffset(*MBBI, AFI->getLocalStackSize(),
@@ -3017,11 +3019,10 @@ bool AArch64FrameLowering::spillCalleeSavedRegisters(
30173019
ArrayRef<CalleeSavedInfo> CSI, const TargetRegisterInfo *TRI) const {
30183020
MachineFunction &MF = *MBB.getParent();
30193021
const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo();
3022+
AArch64FunctionInfo *AFI = MF.getInfo<AArch64FunctionInfo>();
30203023
bool NeedsWinCFI = needsWinCFI(MF);
30213024
DebugLoc DL;
30223025
SmallVector<RegPairInfo, 8> RegPairs;
3023-
bool SpilledStreamingVG = false;
3024-
MachineFrameInfo &MFI = MF.getFrameInfo();
30253026

30263027
computeCalleeSaveRegisterPairs(MF, CSI, TRI, RegPairs, hasFP(MF));
30273028

@@ -3099,7 +3100,7 @@ bool AArch64FrameLowering::spillCalleeSavedRegisters(
30993100
SMEAttrs Attrs(MF.getFunction());
31003101

31013102
if (Attrs.hasStreamingBody() && !Attrs.hasStreamingInterface() &&
3102-
!SpilledStreamingVG) {
3103+
AFI->getStreamingVGIdx() == std::numeric_limits<int>::max()) {
31033104
// For locally-streaming functions, we need to store both the streaming
31043105
// & non-streaming VG. Spill the streaming value first.
31053106
BuildMI(MBB, MI, DL, TII.get(AArch64::RDSVLI_XI), Reg1)
@@ -3111,9 +3112,7 @@ bool AArch64FrameLowering::spillCalleeSavedRegisters(
31113112
.addImm(63)
31123113
.setMIFlag(MachineInstr::FrameSetup);
31133114

3114-
AArch64FunctionInfo *AFI = MF.getInfo<AArch64FunctionInfo>();
31153115
AFI->setStreamingVGIdx(RPI.FrameIdx);
3116-
SpilledStreamingVG = true;
31173116
} else {
31183117
BuildMI(MBB, MI, DL, TII.get(AArch64::CNTD_XPiI), Reg1)
31193118
.addImm(31)
@@ -3394,7 +3393,7 @@ void AArch64FrameLowering::determineCalleeSaves(MachineFunction &MF,
33943393
// non-streaming VG value.
33953394
const Function &F = MF.getFunction();
33963395
SMEAttrs Attrs(F);
3397-
if (AFI->hasStreamingModeChanges() && F.needsUnwindTableEntry()) {
3396+
if (AFI->requiresVGSpill(MF)) {
33983397
if (Attrs.hasStreamingBody() && !Attrs.hasStreamingInterface())
33993398
CSStackSize += 16;
34003399
else
@@ -3538,8 +3537,7 @@ bool AArch64FrameLowering::assignCalleeSavedSpillSlots(
35383537
}
35393538

35403539
// Insert VG into the list of CSRs, immediately before LR if saved.
3541-
const Function &F = MF.getFunction();
3542-
if (AFI->hasStreamingModeChanges() && F.needsUnwindTableEntry()) {
3540+
if (AFI->requiresVGSpill(MF)) {
35433541
std::vector<CalleeSavedInfo> VGSaves;
35443542
SMEAttrs Attrs(MF.getFunction());
35453543

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8336,7 +8336,7 @@ AArch64TargetLowering::LowerCall(CallLoweringInfo &CLI,
83368336
Chain = NewChain.getValue(0);
83378337
InGlue = NewChain.getValue(1);
83388338

8339-
if (IsLocallyStreaming && MF.getFunction().needsUnwindTableEntry()) {
8339+
if (IsLocallyStreaming && Subtarget->hasSVE()) {
83408340
NewChain = DAG.getNode(
83418341
AArch64ISD::VG_UNWIND, DL, DAG.getVTList(MVT::Other, MVT::Glue),
83428342
{Chain, DAG.getTargetConstant(/*Save*/ 1, DL, MVT::i64), InGlue});
@@ -8498,7 +8498,7 @@ AArch64TargetLowering::LowerCall(CallLoweringInfo &CLI,
84988498
DAG, DL, !CalleeAttrs.hasStreamingInterface(), Result, InGlue,
84998499
getSMCondition(CallerAttrs, CalleeAttrs), PStateSM);
85008500

8501-
if (IsLocallyStreaming && MF.getFunction().needsUnwindTableEntry())
8501+
if (IsLocallyStreaming && Subtarget->hasSVE())
85028502
Result = DAG.getNode(
85038503
AArch64ISD::VG_UNWIND, DL, MVT::Other,
85048504
{Result, DAG.getTargetConstant(/*Restore*/ 0, DL, MVT::i64)});

llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef LLVM_LIB_TARGET_AARCH64_AARCH64MACHINEFUNCTIONINFO_H
1414
#define LLVM_LIB_TARGET_AARCH64_AARCH64MACHINEFUNCTIONINFO_H
1515

16+
#include "AArch64Subtarget.h"
1617
#include "llvm/ADT/ArrayRef.h"
1718
#include "llvm/ADT/SmallPtrSet.h"
1819
#include "llvm/ADT/SmallVector.h"
@@ -488,6 +489,11 @@ class AArch64FunctionInfo final : public MachineFunctionInfo {
488489
HasStreamingModeChanges = HasChanges;
489490
}
490491

492+
bool requiresVGSpill(const MachineFunction &MF) const {
493+
const AArch64Subtarget &STI = MF.getSubtarget<AArch64Subtarget>();
494+
return STI.hasSVE() && HasStreamingModeChanges;
495+
}
496+
491497
bool hasStackProbing() const { return StackProbeSize != 0; }
492498

493499
int64_t getStackProbeSize() const { return StackProbeSize; }

llvm/test/CodeGen/AArch64/sme-call-streaming-compatible-to-normal-fn-wihout-sme-attr.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
2-
; RUN: llc -mattr=+sve < %s | FileCheck %s
2+
; RUN: llc < %s | FileCheck %s
33

44
; Verify that the following code can be compiled without +sme, because if the
55
; call is not entered in streaming-SVE mode at runtime, the codepath leading

0 commit comments

Comments
 (0)