Skip to content

Commit 6e9cd8e

Browse files
- Replace pseudos with cfi instructions in processFunctionBeforeFrameIndicesReplaced
and removed handling from AArch64ExpandPseudoInsts. - Removed diagnostics from Clang for unwinding without +sve. - Removed hasSVE() check when emitting pseudos around calls in AArch64ISelLowering. - Emit a call to __arm_get_current_vg from spillCalleeSavedRegisters if HasSVE is false & preserve X0 around the call if live. - Updated LLVM tests with streaming-mode changes to also pass +sve.
1 parent 325b6b4 commit 6e9cd8e

21 files changed

+566
-462
lines changed

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1412,7 +1412,7 @@ def MultiGPU: DiagGroup<"multi-gpu">;
14121412
// libc and the CRT to be skipped.
14131413
def AVRRtlibLinkingQuirks : DiagGroup<"avr-rtlib-linking-quirks">;
14141414

1415-
// A warning group related to AArch64 SME function attributes.
1415+
// A warning group related to AArch64 SME function attribues.
14161416
def AArch64SMEAttributes : DiagGroup<"aarch64-sme-attributes">;
14171417

14181418
// A warning group for things that will change semantics in the future.

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3776,12 +3776,6 @@ def err_conflicting_attributes_arm_state : Error<
37763776
"conflicting attributes for state '%0'">;
37773777
def err_sme_streaming_cannot_be_multiversioned : Error<
37783778
"streaming function cannot be multi-versioned">;
3779-
def err_sme_streaming_mode_change_no_sve : Error<
3780-
"function requires a streaming-mode change, unwinding is not possible without 'sve'. "
3781-
"Consider marking this function as 'noexcept' or '__attribute__((nothrow))'">;
3782-
def err_sme_locally_streaming_no_sve : Error<
3783-
"unwinding is not possible for locally-streaming functions without 'sve'. "
3784-
"Consider marking this function as 'noexcept' or '__attribute__((nothrow))'">;
37853779
def err_unknown_arm_state : Error<
37863780
"unknown state '%0'">;
37873781
def err_missing_arm_state : Error<

clang/lib/Sema/SemaChecking.cpp

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3901,11 +3901,8 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto,
39013901
// If the callee has an AArch64 SME attribute to indicate that it is an
39023902
// __arm_streaming function, then the caller requires SME to be available.
39033903
FunctionProtoType::ExtProtoInfo ExtInfo = Proto->getExtProtoInfo();
3904-
auto *CallerFD = dyn_cast<FunctionDecl>(CurContext);
3905-
bool IsCalleeStreaming =
3906-
ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask;
3907-
if (IsCalleeStreaming) {
3908-
if (CallerFD) {
3904+
if (ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask) {
3905+
if (auto *CallerFD = dyn_cast<FunctionDecl>(CurContext)) {
39093906
llvm::StringMap<bool> CallerFeatureMap;
39103907
Context.getFunctionFeatureMap(CallerFeatureMap, CallerFD);
39113908
if (!CallerFeatureMap.contains("sme"))
@@ -3915,32 +3912,18 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto,
39153912
}
39163913
}
39173914

3918-
if (CallerFD && (!FD || !FD->getBuiltinID())) {
3915+
// If the call requires a streaming-mode change and has scalable vector
3916+
// arguments or return values, then warn the user that the streaming and
3917+
// non-streaming vector lengths may be different.
3918+
const auto *CallerFD = dyn_cast<FunctionDecl>(CurContext);
3919+
if (CallerFD && (!FD || !FD->getBuiltinID()) &&
3920+
(IsScalableArg || IsScalableRet)) {
3921+
bool IsCalleeStreaming =
3922+
ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateSMEnabledMask;
39193923
bool IsCalleeStreamingCompatible =
39203924
ExtInfo.AArch64SMEAttributes &
39213925
FunctionType::SME_PStateSMCompatibleMask;
39223926
SemaARM::ArmStreamingType CallerFnType = getArmStreamingFnType(CallerFD);
3923-
bool NoThrow =
3924-
!getLangOpts().Exceptions ||
3925-
(Proto && !isUnresolvedExceptionSpec(Proto->getExceptionSpecType()) &&
3926-
Proto->isNothrow()) ||
3927-
(FD && FD->hasAttr<NoThrowAttr>());
3928-
3929-
// SME functions may require SVE to be available for unwinding, as the
3930-
// value of VG needs to be preserved across streaming-mode changes.
3931-
if (!NoThrow && !Context.getTargetInfo().hasFeature("sve")) {
3932-
if (CallerFD->hasAttr<ArmLocallyStreamingAttr>())
3933-
Diag(Loc, diag::err_sme_locally_streaming_no_sve);
3934-
3935-
if ((CallerFnType == SemaARM::ArmStreaming ||
3936-
CallerFnType == SemaARM::ArmStreamingCompatible) &&
3937-
(!IsCalleeStreaming && !IsCalleeStreamingCompatible))
3938-
Diag(Loc, diag::err_sme_streaming_mode_change_no_sve);
3939-
}
3940-
3941-
// If the call requires a streaming-mode change and has scalable vector
3942-
// arguments or return values, then warn the user that the streaming and
3943-
// non-streaming vector lengths may be different.
39443927
if (!IsCalleeStreamingCompatible &&
39453928
(CallerFnType == SemaARM::ArmStreamingCompatible ||
39463929
((CallerFnType == SemaARM::ArmStreaming) ^ IsCalleeStreaming))) {

clang/test/CodeGen/aarch64-sme-inline-streaming-attrs.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -S -o /dev/null -target-feature +sve -target-feature +sme -verify -DTEST_NONE %s
2-
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -S -o /dev/null -target-feature +sve -target-feature +sme -verify -DTEST_COMPATIBLE %s
3-
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -S -o /dev/null -target-feature +sve -target-feature +sme -verify -DTEST_STREAMING %s
4-
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -S -o /dev/null -target-feature +sve -target-feature +sme -verify -DTEST_LOCALLY %s
1+
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -S -o /dev/null -target-feature +sme -verify -DTEST_NONE %s
2+
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -S -o /dev/null -target-feature +sme -verify -DTEST_COMPATIBLE %s
3+
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -S -o /dev/null -target-feature +sme -verify -DTEST_STREAMING %s
4+
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -S -o /dev/null -target-feature +sme -verify -DTEST_LOCALLY %s
55

66
#define __ai __attribute__((always_inline))
77
__ai void inlined_fn(void) {}

clang/test/CodeGen/aarch64-sme-intrinsics/aarch64-sme-attrs.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme \
2-
// RUN: -target-feature +sve -disable-O0-optnone -Werror -emit-llvm -o - %s \
2+
// RUN: -disable-O0-optnone -Werror -emit-llvm -o - %s \
33
// RUN: | opt -S -passes=mem2reg \
44
// RUN: | opt -S -passes=inline \
55
// RUN: | FileCheck %s
@@ -278,18 +278,18 @@ int test_variadic_template() __arm_inout("za") {
278278
preserves_za_decl);
279279
}
280280

281-
// CHECK: attributes #[[SM_ENABLED]] = { mustprogress noinline nounwind vscale_range(1,16) "aarch64_pstate_sm_enabled" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+fp-armv8,+fullfp16,+neon,+sme,+sve" }
282-
// CHECK: attributes #[[NORMAL_DECL]] = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+fp-armv8,+fullfp16,+neon,+sme,+sve" }
283-
// CHECK: attributes #[[SM_ENABLED_DECL]] = { "aarch64_pstate_sm_enabled" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+fp-armv8,+fullfp16,+neon,+sme,+sve" }
284-
// CHECK: attributes #[[SM_COMPATIBLE]] = { mustprogress noinline nounwind vscale_range(1,16) "aarch64_pstate_sm_compatible" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+fp-armv8,+fullfp16,+neon,+sme,+sve" }
285-
// CHECK: attributes #[[SM_COMPATIBLE_DECL]] = { "aarch64_pstate_sm_compatible" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+fp-armv8,+fullfp16,+neon,+sme,+sve" }
286-
// CHECK: attributes #[[SM_BODY]] = { mustprogress noinline nounwind vscale_range(1,16) "aarch64_pstate_sm_body" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+fp-armv8,+fullfp16,+neon,+sme,+sve" }
287-
// CHECK: attributes #[[ZA_SHARED]] = { mustprogress noinline nounwind vscale_range(1,16) "aarch64_inout_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+fp-armv8,+fullfp16,+neon,+sme,+sve" }
288-
// CHECK: attributes #[[ZA_SHARED_DECL]] = { "aarch64_inout_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+fp-armv8,+fullfp16,+neon,+sme,+sve" }
289-
// CHECK: attributes #[[ZA_PRESERVED]] = { mustprogress noinline nounwind vscale_range(1,16) "aarch64_preserves_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+fp-armv8,+fullfp16,+neon,+sme,+sve" }
290-
// CHECK: attributes #[[ZA_PRESERVED_DECL]] = { "aarch64_preserves_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+fp-armv8,+fullfp16,+neon,+sme,+sve" }
291-
// CHECK: attributes #[[ZA_NEW]] = { mustprogress noinline nounwind vscale_range(1,16) "aarch64_new_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+fp-armv8,+fullfp16,+neon,+sme,+sve" }
292-
// CHECK: attributes #[[NORMAL_DEF]] = { mustprogress noinline nounwind vscale_range(1,16) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+fp-armv8,+fullfp16,+neon,+sme,+sve" }
281+
// CHECK: attributes #[[SM_ENABLED]] = { mustprogress noinline nounwind "aarch64_pstate_sm_enabled" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" }
282+
// CHECK: attributes #[[NORMAL_DECL]] = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" }
283+
// CHECK: attributes #[[SM_ENABLED_DECL]] = { "aarch64_pstate_sm_enabled" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" }
284+
// CHECK: attributes #[[SM_COMPATIBLE]] = { mustprogress noinline nounwind "aarch64_pstate_sm_compatible" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" }
285+
// CHECK: attributes #[[SM_COMPATIBLE_DECL]] = { "aarch64_pstate_sm_compatible" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" }
286+
// CHECK: attributes #[[SM_BODY]] = { mustprogress noinline nounwind "aarch64_pstate_sm_body" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" }
287+
// CHECK: attributes #[[ZA_SHARED]] = { mustprogress noinline nounwind "aarch64_inout_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" }
288+
// CHECK: attributes #[[ZA_SHARED_DECL]] = { "aarch64_inout_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" }
289+
// CHECK: attributes #[[ZA_PRESERVED]] = { mustprogress noinline nounwind "aarch64_preserves_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" }
290+
// CHECK: attributes #[[ZA_PRESERVED_DECL]] = { "aarch64_preserves_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" }
291+
// CHECK: attributes #[[ZA_NEW]] = { mustprogress noinline nounwind "aarch64_new_za" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" }
292+
// CHECK: attributes #[[NORMAL_DEF]] = { mustprogress noinline nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+bf16,+sme" }
293293
// CHECK: attributes #[[SM_ENABLED_CALL]] = { "aarch64_pstate_sm_enabled" }
294294
// CHECK: attributes #[[SM_COMPATIBLE_CALL]] = { "aarch64_pstate_sm_compatible" }
295295
// CHECK: attributes #[[SM_BODY_CALL]] = { "aarch64_pstate_sm_body" }

clang/test/Sema/aarch64-sme-func-attrs-without-target-feature.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void non_streaming_def(void (*streaming_fn_ptr)(void) __arm_streaming,
3838
void streaming_compatible_def2(void (*streaming_fn_ptr)(void) __arm_streaming,
3939
void (*streaming_compatible_fn_ptr)(void) __arm_streaming_compatible)
4040
__arm_streaming_compatible {
41-
non_streaming_decl();
41+
non_streaming_decl(); // OK
4242
streaming_compatible_decl(); // OK
4343
streaming_compatible_fn_ptr(); // OK
4444
streaming_decl(); // expected-error {{call to a streaming function requires 'sme'}}

clang/test/Sema/aarch64-streaming-mode-changes-no-sve.cpp

Lines changed: 0 additions & 89 deletions
This file was deleted.

llvm/lib/Target/AArch64/AArch64ExpandPseudoInsts.cpp

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,57 +1599,6 @@ bool AArch64ExpandPseudo::expandMI(MachineBasicBlock &MBB,
15991599
case AArch64::COALESCER_BARRIER_FPR128:
16001600
MI.eraseFromParent();
16011601
return true;
1602-
case AArch64::VGSavePseudo:
1603-
case AArch64::VGRestorePseudo: {
1604-
MachineFunction &MF = *MBB.getParent();
1605-
SMEAttrs FuncAttrs(MF.getFunction());
1606-
bool LocallyStreaming =
1607-
FuncAttrs.hasStreamingBody() && !FuncAttrs.hasStreamingInterface();
1608-
const AArch64FunctionInfo *AFI = MF.getInfo<AArch64FunctionInfo>();
1609-
1610-
if (!AFI->requiresVGSpill(MF))
1611-
return false;
1612-
1613-
int64_t VGFrameIdx =
1614-
LocallyStreaming ? AFI->getStreamingVGIdx() : AFI->getVGIdx();
1615-
assert(VGFrameIdx != std::numeric_limits<int>::max() &&
1616-
"Expected FrameIdx for VG");
1617-
1618-
const TargetSubtargetInfo &STI = MF.getSubtarget();
1619-
const TargetInstrInfo &TII = *STI.getInstrInfo();
1620-
const TargetRegisterInfo &TRI = *STI.getRegisterInfo();
1621-
1622-
if (Opcode == AArch64::VGSavePseudo) {
1623-
// This pseudo has been inserted after a streaming-mode change
1624-
// to save the streaming value of VG before a call.
1625-
// Calculate and emit the CFI offset using VGFrameIdx.
1626-
MachineFrameInfo &MFI = MF.getFrameInfo();
1627-
const AArch64FrameLowering *TFI =
1628-
MF.getSubtarget<AArch64Subtarget>().getFrameLowering();
1629-
1630-
int64_t Offset =
1631-
MFI.getObjectOffset(VGFrameIdx) - TFI->getOffsetOfLocalArea();
1632-
unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::createOffset(
1633-
nullptr, TRI.getDwarfRegNum(AArch64::VG, true), Offset));
1634-
BuildMI(MBB, MBBI, MBBI->getDebugLoc(),
1635-
TII.get(TargetOpcode::CFI_INSTRUCTION))
1636-
.addCFIIndex(CFIIndex)
1637-
.setMIFlags(MachineInstr::FrameSetup);
1638-
} else {
1639-
// This is a restore of VG after returning from the call. Emit the
1640-
// .cfi_restore instruction, which sets the rule for VG to the same
1641-
// as it was on entry to the function.
1642-
++MBBI;
1643-
DebugLoc DL = MI.getDebugLoc();
1644-
unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::createRestore(
1645-
nullptr, TRI.getDwarfRegNum(AArch64::VG, true)));
1646-
BuildMI(MBB, MBBI, DL, TII.get(TargetOpcode::CFI_INSTRUCTION))
1647-
.addCFIIndex(CFIIndex);
1648-
}
1649-
1650-
MI.eraseFromParent();
1651-
return true;
1652-
}
16531602
case AArch64::LD1B_2Z_IMM_PSEUDO:
16541603
return expandMultiVecPseudo(
16551604
MBB, MBBI, AArch64::ZPR2RegClass, AArch64::ZPR2StridedRegClass,

0 commit comments

Comments
 (0)