Skip to content

Commit 12600c8

Browse files
committed
[Clang][AArch64] Emit 'unimplemented' diagnostic for SME.
When a function F has ZA and ZT0 state, calls another function G that only shares ZT0 state with its caller, F will have to save ZA before the call to G, and restore it afterwards (rather than setting up a lazy-sve). This is not yet implemented in LLVM and does not result in a compile-time error either. So instead of silently generating incorrect code, it's better to emit an error saying this is not yet implemented.
1 parent 6759819 commit 12600c8

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3711,6 +3711,12 @@ def err_sme_za_call_no_za_state : Error<
37113711
"call to a shared ZA function requires the caller to have ZA state">;
37123712
def err_sme_zt0_call_no_zt0_state : Error<
37133713
"call to a shared ZT0 function requires the caller to have ZT0 state">;
3714+
def err_sme_unimplemented_za_save_restore : Error<
3715+
"call to a function that shares state other than 'za' from a "
3716+
"function that has live 'za' state requires a spill/fill of ZA, which is not yet "
3717+
"implemented">;
3718+
def note_sme_use_preserves_za : Note<
3719+
"add '__arm_preserves(\"za\")' to the callee if it preserves ZA">;
37143720
def err_sme_definition_using_sm_in_non_sme_target : Error<
37153721
"function executed in streaming-SVE mode requires 'sme'">;
37163722
def err_sme_definition_using_za_in_non_sme_target : Error<

clang/lib/Sema/SemaChecking.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7544,6 +7544,13 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto,
75447544

75457545
if (CalleeArmZT0State != FunctionType::ARM_None && !CallerHasZT0State)
75467546
Diag(Loc, diag::err_sme_zt0_call_no_zt0_state);
7547+
7548+
if (CallerHasZAState &&
7549+
CalleeArmZAState == FunctionType::ARM_None &&
7550+
CalleeArmZT0State != FunctionType::ARM_None) {
7551+
Diag(Loc, diag::err_sme_unimplemented_za_save_restore);
7552+
Diag(Loc, diag::note_sme_use_preserves_za);
7553+
}
75477554
}
75487555
}
75497556

clang/test/Sema/aarch64-sme-func-attrs.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -fsyntax-only -verify %s
2-
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -fsyntax-only -verify=expected-cpp -x c++ %s
1+
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -fsyntax-only -verify %s
2+
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -fsyntax-only -verify=expected-cpp -x c++ %s
33

44
// Valid attributes
55

@@ -445,3 +445,12 @@ void conflicting_state_attrs_preserves_out_zt0(void) __arm_preserves("zt0") __ar
445445
// expected-cpp-error@+2 {{conflicting attributes for state 'zt0'}}
446446
// expected-error@+1 {{conflicting attributes for state 'zt0'}}
447447
void conflicting_state_attrs_preserves_inout_zt0(void) __arm_preserves("zt0") __arm_inout("zt0");
448+
449+
// Test that we get a diagnostic for unimplemented case.
450+
void unimplemented_spill_fill_za(void (*share_zt0_only)(void) __arm_inout("zt0")) __arm_inout("za", "zt0") {
451+
// expected-cpp-error@+4 {{call to a function that shares state other than 'za' from a function that has live 'za' state requires a spill/fill of ZA, which is not yet implemented}}
452+
// expected-cpp-note@+3 {{add '__arm_preserves("za")' to the callee if it preserves ZA}}
453+
// expected-error@+2 {{call to a function that shares state other than 'za' from a function that has live 'za' state requires a spill/fill of ZA, which is not yet implemented}}
454+
// expected-note@+1 {{add '__arm_preserves("za")' to the callee if it preserves ZA}}
455+
share_zt0_only();
456+
}

0 commit comments

Comments
 (0)