This is an archive of the discontinued LLVM Phabricator instance.

[Clang][AArch64] Diagnostics for SME attributes when target doesn't have 'sme'
ClosedPublic

Authored by sdesmalen on Aug 7 2023, 3:31 AM.

Details

Summary

This patch adds error diagnostics to Clang when code uses the AArch64 SME
attributes without specifying 'sme' as available target attribute.

  • Function definitions marked as 'arm_streaming', 'arm_locally_streaming', 'arm_shared_za' or 'arm_new_za' will by definition use or require SME instructions.
  • Calls from non-streaming functions to streaming-functions require the compiler to enable/disable streaming-SVE mode around the call-site.

In some cases we can accept the SME attributes without having 'sme' enabled:

  • Function declaration can have the SME attributes.
  • Definitions can be __arm_streaming_compatible since the generated code should execute on processing elements without SME.

Diff Detail

Event Timeline

sdesmalen created this revision.Aug 7 2023, 3:31 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 7 2023, 3:31 AM
sdesmalen requested review of this revision.Aug 7 2023, 3:31 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptAug 7 2023, 3:31 AM

The intent looks good to me, but I'm not in a position to approve. Very pedantic, sorry, but on the description, I think:

Calls from non-streaming functions to streaming-functions require the compiler to enable/disable streaming-SVE mode around the call-site.

would be more accurate as:

Calls from non-streaming mode to streaming functions…

since it applies to calls from streaming-compatible functions too. (Which is what the patch implements.)

clang/include/clang/Basic/DiagnosticSemaKinds.td
3629

Seems like we can easily split this into two and distinguish the cases, since the code that gives the error can always tell which case applies. I think not having SME for streaming mode is logically more fundamental than not having SME for ZA.

I think sme should be SME (if it's referring to the ISA feature) or should be quoted (if it's referring to the feature syntax).

clang/lib/Sema/SemaChecking.cpp
6631

I don't know the code well enough to know whether this is the right place to check this. if it is, though, I suppose the comment needs to be updated too.

I agree the intention looks right from a spec POV.

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

Looks like this was intended to be __arm_streaming_compatible.

llvm/lib/Target/AArch64/AArch64SMEInstrInfo.td
158

I don't think even SVE is required. A function like:

void foo() __arm_streaming_compatible {
   printf ("Hello, world!\n");
}

should be OK for base Armv8-A.

sdesmalen updated this revision to Diff 547782.Aug 7 2023, 7:34 AM
sdesmalen marked 4 inline comments as done.
  • Renamed sme to 'sme' to make it clear that it relates to the target feature
  • Split function executed in streaming-SVE mode or using ZA state, requires sme into:
    • function executed in streaming-SVE mode requires 'sme'
    • function using ZA state requires 'sme'
  • Removed requirement for SVE being enabled for streaming-compatible functions
  • Updated comment of Sema::checkCall

LGTM in terms of intent.

clang/lib/Sema/SemaDecl.cpp
12092

Suggest making this an else if. We only need to give one error for a call to a streaming shared-ZA function, since the underlying error is the same.

aaron.ballman added inline comments.Aug 7 2023, 10:32 AM
clang/test/Sema/aarch64-sme-func-attrs-without-target-feature.cpp
21

Is this a requirement of the specification? I guess I was surprised we're going to these lengths rather than diagnosing the attribute in SemaDeclAttr.cpp when sme is not enabled.

rsandifo-arm added inline comments.Aug 7 2023, 10:56 AM
clang/test/Sema/aarch64-sme-func-attrs-without-target-feature.cpp
21

Yeah. The problem is that it's possible (and reasonable!) to enable SME for only part of a translation unit. E.g. an ifunc might have SME and non-SME implementations, with those implementations being in the same translation unit. Things like the target and target_version attributes exist to allow this.

A function that's compiled with SME enabled might want to call streaming functions. There therefore needs to be a way of declaring streaming functions without assuming that the whole TU is SME.

Clang bits generally LGTM aside from a minor request; I'll leave the final sign-off to an LLVM person so those changes can also be reviewed.

clang/lib/Sema/SemaDecl.cpp
12092

Agreed; I think we need only one diagnostic in that case.

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

Ah, thank you for the explanation, then this extra effort makes a lot more sense.

sdesmalen updated this revision to Diff 547933.Aug 7 2023, 1:41 PM
sdesmalen marked 2 inline comments as done.

Removed double error message for missing 'sme' for both ZA and Streaming

Thanks for the review of the Clang side @aaron.ballman and @rsandifo-arm.

@paulwalker-arm would you be happy to have a look at the LLVM side of this patch?

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

Thanks, I missed that!

Matt added a subscriber: Matt.Aug 7 2023, 3:44 PM
sdesmalen updated this revision to Diff 548130.Aug 8 2023, 2:44 AM
  • (Clang) Added test-cases for indirect calls.
  • (LLVM) Moved the pseudo definition out of the 'let Predicates = [HasSME] {}' block as well.
paulwalker-arm added inline comments.Aug 8 2023, 4:46 AM
clang/lib/Sema/SemaChecking.cpp
6722

contains("sme") seems more appropriate here?

clang/lib/Sema/SemaDecl.cpp
12088

As above.

12092

Can this be just else given by this point I believe you know UsesZA has to be true.

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

Does the test require SVE to be enabled?

4

diagnostics

14–18

Is it worth including tests where "sme2" is used? or are we already comfortable feature inheritance is well tested?

llvm/lib/Target/AArch64/AArch64SMEInstrInfo.td
144–164

Doesn't this class belong in SMEInstrFormats.td, then you'll not need to override Predicates?

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

Verify the...

sdesmalen updated this revision to Diff 548168.Aug 8 2023, 5:33 AM
sdesmalen marked 10 inline comments as done.

Address further review comments.

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

I'm not sure how well this is tested, but I guess there's no harm in adding an extra test for it.

llvm/lib/Target/AArch64/AArch64SMEInstrInfo.td
144–164

Good point, I've moved the class over and the InstAliases as well (which I guess also shouldn't depend on SME being available)

paulwalker-arm accepted this revision.Aug 8 2023, 6:06 AM
This revision is now accepted and ready to land.Aug 8 2023, 6:06 AM
sdesmalen updated this revision to Diff 548526.Aug 9 2023, 2:22 AM

Updated LLVM MC tests which were failing because smstart/smstop are no longer predicated by 'sme'.
Sorry, I only just noticed that I hadn't run all the tests yet.

@paulwalker-arm could you give this another look?

paulwalker-arm accepted this revision.Aug 9 2023, 2:36 AM
This revision was landed with ongoing or failed builds.Aug 9 2023, 5:31 AM
This revision was automatically updated to reflect the committed changes.