This is an archive of the discontinued LLVM Phabricator instance.

[Clang][AArch64] Support AArch64 target(..) attribute formats.
ClosedPublic

Authored by dmgreen on Sep 14 2022, 3:57 AM.

Details

Summary

This adds support under AArch64 for the target("..") attributes. The current parsing is very X86-shaped, this patch attempts to bring it line with the GCC implementation from https://gcc.gnu.org/onlinedocs/gcc/AArch64-Function-Attributes.html#AArch64-Function-Attributes.

The supported formats are:

  • "arch=<arch>" strings, that specify the architecture features for a function as per the -march=arch+feature option.
  • "cpu=<cpu>" strings, that specify the target-cpu and any implied atributes as per the -mcpu=cpu+feature option.
  • "tune=<cpu>" strings, that specify the tune-cpu cpu for a function as per -mtune.
  • "+<feature>", "+no<feature>" enables/disables the specific feature, for compatibility with GCC target attributes.
  • "<feature>", "no-<feature>" enabled/disables the specific feature, for backward compatibility with previous releases.

To do this, the parsing of target attributes has been moved into TargetInfo to give the target the opportunity to override the existing parsing. The only non-aarch64 change should be a minor alteration to the error message, specifying using "CPU" to describe the cpu, not "architecture", and the DuplicateArch/Tune from ParsedTargetAttr have been combined into a single option.

Diff Detail

Event Timeline

dmgreen created this revision.Sep 14 2022, 3:57 AM
dmgreen requested review of this revision.Sep 14 2022, 3:57 AM
danielkiss accepted this revision.Sep 26 2022, 1:30 PM

Maybe a test case where all option present could be useful. like __attribute__((target("arch=armv8.1-a,tune=cortex-a710,branch-protection=standard")))
To reach better gcc compatibility a new feature names to be harmonised/alternative to be added but this is a separate issue.

LGTM

This revision is now accepted and ready to land.Sep 26 2022, 1:30 PM
Matt added a subscriber: Matt.Sep 27 2022, 11:37 AM

Thanks for the review. I've had to rejig the tests a little to not be dependant on having a feature map in setFeatureEnabled. And for the dependant arch features we add now. The sve features we should be able to adjust back in the future. And I've added the other tests, thanks for the suggestion.

This revision was landed with ongoing or failed builds.Oct 1 2022, 7:41 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptOct 1 2022, 7:41 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript