Skip to content

[FMV][AArch64] Changes in fmv-features metadata. #122192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
#include "llvm/TargetParser/X86TargetParser.h"
#include "llvm/Transforms/Utils/BuildLibCalls.h"
#include <optional>
#include <set>

using namespace clang;
using namespace CodeGen;
Expand Down Expand Up @@ -2748,17 +2749,26 @@ bool CodeGenModule::GetCPUAndFeaturesAttributes(GlobalDecl GD,
Attrs.addAttribute("target-features", llvm::join(Features, ","));
AddedAttr = true;
}
// Add metadata for AArch64 Function Multi Versioning.
if (getTarget().getTriple().isAArch64()) {
llvm::SmallVector<StringRef, 8> Feats;
if (TV)
bool IsDefault = false;
if (TV) {
IsDefault = TV->isDefaultVersion();
TV->getFeatures(Feats);
else if (TC)
} else if (TC) {
IsDefault = TC->isDefaultVersion(GD.getMultiVersionIndex());
TC->getFeatures(Feats, GD.getMultiVersionIndex());
if (!Feats.empty()) {
llvm::sort(Feats);
}
if (IsDefault) {
Attrs.addAttribute("fmv-features");
AddedAttr = true;
} else if (!Feats.empty()) {
// Sort features and remove duplicates.
std::set<StringRef> OrderedFeats(Feats.begin(), Feats.end());
std::string FMVFeatures;
for (StringRef F : Feats)
FMVFeatures.append(",+" + F.str());
for (StringRef F : OrderedFeats)
FMVFeatures.append("," + F.str());
Attrs.addAttribute("fmv-features", FMVFeatures.substr(1));
AddedAttr = true;
}
Expand Down Expand Up @@ -2800,6 +2810,7 @@ void CodeGenModule::setNonAliasAttributes(GlobalDecl GD,
llvm::AttributeMask RemoveAttrs;
RemoveAttrs.addAttribute("target-cpu");
RemoveAttrs.addAttribute("target-features");
RemoveAttrs.addAttribute("fmv-features");
RemoveAttrs.addAttribute("tune-cpu");
F->removeFnAttrs(RemoveAttrs);
F->addFnAttrs(Attrs);
Expand Down
100 changes: 51 additions & 49 deletions clang/test/CodeGen/AArch64/fmv-features.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,62 +139,64 @@ __attribute__((target_version("sve2-sm4"))) int fmv(void) { return 0; }
// CHECK: define dso_local i32 @fmv._Mwfxt() #[[wfxt:[0-9]+]] {
__attribute__((target_version("wfxt"))) int fmv(void) { return 0; }

// CHECK: define dso_local i32 @fmv._MaesMbf16MbtiMcrc() #[[multiple_features:[0-9]+]] {
__attribute__((target_version("aes+bf16+bti+crc"))) int fmv(void) { return 0; }
// CHECK: define dso_local i32 @fmv._MaesMbf16MbtiMcrc() #[[unordered_features_with_duplicates:[0-9]+]] {
__attribute__((target_version("crc+bti+bti+bti+aes+aes+bf16"))) int fmv(void) { return 0; }

// CHECK-NOT: define dso_local i32 @fmv._M{{.*}}
__attribute__((target_version("non_existent_extension"))) int fmv(void);

// CHECK: define dso_local i32 @fmv.default() #[[default:[0-9]+]] {
__attribute__((target_version("default"))) int fmv(void);

int caller() {
return fmv();
}

// CHECK: attributes #[[aes]] = { {{.*}} "fmv-features"="+aes"
// CHECK: attributes #[[bf16]] = { {{.*}} "fmv-features"="+bf16"
// CHECK: attributes #[[bti]] = { {{.*}} "fmv-features"="+bti"
// CHECK: attributes #[[crc]] = { {{.*}} "fmv-features"="+crc"
// CHECK: attributes #[[dit]] = { {{.*}} "fmv-features"="+dit"
// CHECK: attributes #[[dotprod]] = { {{.*}} "fmv-features"="+dotprod"
// CHECK: attributes #[[dpb]] = { {{.*}} "fmv-features"="+dpb"
// CHECK: attributes #[[dpb2]] = { {{.*}} "fmv-features"="+dpb2"
// CHECK: attributes #[[f32mm]] = { {{.*}} "fmv-features"="+f32mm"
// CHECK: attributes #[[f64mm]] = { {{.*}} "fmv-features"="+f64mm"
// CHECK: attributes #[[fcma]] = { {{.*}} "fmv-features"="+fcma"
// CHECK: attributes #[[flagm]] = { {{.*}} "fmv-features"="+flagm"
// CHECK: attributes #[[flagm2]] = { {{.*}} "fmv-features"="+flagm2"
// CHECK: attributes #[[fp]] = { {{.*}} "fmv-features"="+fp"
// CHECK: attributes #[[fp16]] = { {{.*}} "fmv-features"="+fp16"
// CHECK: attributes #[[fp16fml]] = { {{.*}} "fmv-features"="+fp16fml"
// CHECK: attributes #[[frintts]] = { {{.*}} "fmv-features"="+frintts"
// CHECK: attributes #[[i8mm]] = { {{.*}} "fmv-features"="+i8mm"
// CHECK: attributes #[[jscvt]] = { {{.*}} "fmv-features"="+jscvt"
// CHECK: attributes #[[ls64]] = { {{.*}} "fmv-features"="+ls64"
// CHECK: attributes #[[lse]] = { {{.*}} "fmv-features"="+lse"
// CHECK: attributes #[[memtag]] = { {{.*}} "fmv-features"="+memtag"
// CHECK: attributes #[[mops]] = { {{.*}} "fmv-features"="+mops"
// CHECK: attributes #[[predres]] = { {{.*}} "fmv-features"="+predres"
// CHECK: attributes #[[rcpc]] = { {{.*}} "fmv-features"="+rcpc"
// CHECK: attributes #[[rcpc2]] = { {{.*}} "fmv-features"="+rcpc2"
// CHECK: attributes #[[rcpc3]] = { {{.*}} "fmv-features"="+rcpc3"
// CHECK: attributes #[[rdm]] = { {{.*}} "fmv-features"="+rdm"
// CHECK: attributes #[[rng]] = { {{.*}} "fmv-features"="+rng"
// CHECK: attributes #[[sb]] = { {{.*}} "fmv-features"="+sb"
// CHECK: attributes #[[sha2]] = { {{.*}} "fmv-features"="+sha2"
// CHECK: attributes #[[sha3]] = { {{.*}} "fmv-features"="+sha3"
// CHECK: attributes #[[simd]] = { {{.*}} "fmv-features"="+simd"
// CHECK: attributes #[[sm4]] = { {{.*}} "fmv-features"="+sm4"
// CHECK: attributes #[[sme]] = { {{.*}} "fmv-features"="+sme"
// CHECK: attributes #[[sme_f64f64]] = { {{.*}} "fmv-features"="+sme-f64f64"
// CHECK: attributes #[[sme_i16i64]] = { {{.*}} "fmv-features"="+sme-i16i64"
// CHECK: attributes #[[sme2]] = { {{.*}} "fmv-features"="+sme2"
// CHECK: attributes #[[ssbs]] = { {{.*}} "fmv-features"="+ssbs"
// CHECK: attributes #[[sve]] = { {{.*}} "fmv-features"="+sve"
// CHECK: attributes #[[sve2]] = { {{.*}} "fmv-features"="+sve2"
// CHECK: attributes #[[sve2_aes]] = { {{.*}} "fmv-features"="+sve2-aes"
// CHECK: attributes #[[sve2_bitperm]] = { {{.*}} "fmv-features"="+sve2-bitperm"
// CHECK: attributes #[[sve2_sha3]] = { {{.*}} "fmv-features"="+sve2-sha3"
// CHECK: attributes #[[sve2_sm4]] = { {{.*}} "fmv-features"="+sve2-sm4"
// CHECK: attributes #[[wfxt]] = { {{.*}} "fmv-features"="+wfxt"
// CHECK: attributes #[[multiple_features]] = { {{.*}} "fmv-features"="+aes,+bf16,+bti,+crc"
// CHECK: attributes #[[aes]] = {{.*}} "fmv-features"="aes"
// CHECK: attributes #[[bf16]] = {{.*}} "fmv-features"="bf16"
// CHECK: attributes #[[bti]] = {{.*}} "fmv-features"="bti"
// CHECK: attributes #[[crc]] = {{.*}} "fmv-features"="crc"
// CHECK: attributes #[[dit]] = {{.*}} "fmv-features"="dit"
// CHECK: attributes #[[dotprod]] = {{.*}} "fmv-features"="dotprod"
// CHECK: attributes #[[dpb]] = {{.*}} "fmv-features"="dpb"
// CHECK: attributes #[[dpb2]] = {{.*}} "fmv-features"="dpb2"
// CHECK: attributes #[[f32mm]] = {{.*}} "fmv-features"="f32mm"
// CHECK: attributes #[[f64mm]] = {{.*}} "fmv-features"="f64mm"
// CHECK: attributes #[[fcma]] = {{.*}} "fmv-features"="fcma"
// CHECK: attributes #[[flagm]] = {{.*}} "fmv-features"="flagm"
// CHECK: attributes #[[flagm2]] = {{.*}} "fmv-features"="flagm2"
// CHECK: attributes #[[fp]] = {{.*}} "fmv-features"="fp"
// CHECK: attributes #[[fp16]] = {{.*}} "fmv-features"="fp16"
// CHECK: attributes #[[fp16fml]] = {{.*}} "fmv-features"="fp16fml"
// CHECK: attributes #[[frintts]] = {{.*}} "fmv-features"="frintts"
// CHECK: attributes #[[i8mm]] = {{.*}} "fmv-features"="i8mm"
// CHECK: attributes #[[jscvt]] = {{.*}} "fmv-features"="jscvt"
// CHECK: attributes #[[ls64]] = {{.*}} "fmv-features"="ls64"
// CHECK: attributes #[[lse]] = {{.*}} "fmv-features"="lse"
// CHECK: attributes #[[memtag]] = {{.*}} "fmv-features"="memtag"
// CHECK: attributes #[[mops]] = {{.*}} "fmv-features"="mops"
// CHECK: attributes #[[predres]] = {{.*}} "fmv-features"="predres"
// CHECK: attributes #[[rcpc]] = {{.*}} "fmv-features"="rcpc"
// CHECK: attributes #[[rcpc2]] = {{.*}} "fmv-features"="rcpc2"
// CHECK: attributes #[[rcpc3]] = {{.*}} "fmv-features"="rcpc3"
// CHECK: attributes #[[rdm]] = {{.*}} "fmv-features"="rdm"
// CHECK: attributes #[[rng]] = {{.*}} "fmv-features"="rng"
// CHECK: attributes #[[sb]] = {{.*}} "fmv-features"="sb"
// CHECK: attributes #[[sha2]] = {{.*}} "fmv-features"="sha2"
// CHECK: attributes #[[sha3]] = {{.*}} "fmv-features"="sha3"
// CHECK: attributes #[[simd]] = {{.*}} "fmv-features"="simd"
// CHECK: attributes #[[sm4]] = {{.*}} "fmv-features"="sm4"
// CHECK: attributes #[[sme]] = {{.*}} "fmv-features"="sme"
// CHECK: attributes #[[sme_f64f64]] = {{.*}} "fmv-features"="sme-f64f64"
// CHECK: attributes #[[sme_i16i64]] = {{.*}} "fmv-features"="sme-i16i64"
// CHECK: attributes #[[sme2]] = {{.*}} "fmv-features"="sme2"
// CHECK: attributes #[[ssbs]] = {{.*}} "fmv-features"="ssbs"
// CHECK: attributes #[[sve]] = {{.*}} "fmv-features"="sve"
// CHECK: attributes #[[sve2]] = {{.*}} "fmv-features"="sve2"
// CHECK: attributes #[[sve2_aes]] = {{.*}} "fmv-features"="sve2-aes"
// CHECK: attributes #[[sve2_bitperm]] = {{.*}} "fmv-features"="sve2-bitperm"
// CHECK: attributes #[[sve2_sha3]] = {{.*}} "fmv-features"="sve2-sha3"
// CHECK: attributes #[[sve2_sm4]] = {{.*}} "fmv-features"="sve2-sm4"
// CHECK: attributes #[[wfxt]] = {{.*}} "fmv-features"="wfxt"
// CHECK: attributes #[[unordered_features_with_duplicates]] = {{.*}} "fmv-features"="aes,bf16,bti,crc"
// CHECK: attributes #[[default]] = {{.*}} "fmv-features"
2 changes: 1 addition & 1 deletion clang/test/CodeGen/AArch64/fmv-priority.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ int call() { return fn(); }
//
//
// CHECK-LABEL: define dso_local i32 @call(
// CHECK-SAME: ) #[[ATTR0]] {
// CHECK-SAME: ) #[[ATTR1:[0-9]+]] {
// CHECK-NEXT: [[ENTRY:.*:]]
// CHECK-NEXT: [[CALL:%.*]] = call i32 @fn()
// CHECK-NEXT: ret i32 [[CALL]]
Expand Down
25 changes: 14 additions & 11 deletions clang/test/CodeGen/AArch64/fmv-streaming.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ __attribute__((target_version("default"))) void sc_callee(void) __arm_streaming_


// CHECK-LABEL: define {{[^@]+}}@n_caller
// CHECK-SAME: () #[[default]] {
// CHECK-SAME: () #[[caller:[0-9]+]] {
// CHECK: call void @n_callee()
// CHECK: call void @s_callee() #[[streaming:[0-9]+]]
// CHECK: call void @sc_callee() #[[streaming_compatible:[0-9]+]]
// CHECK: call void @s_callee() #[[callsite_streaming:[0-9]+]]
// CHECK: call void @sc_callee() #[[callsite_streaming_compatible:[0-9]+]]
//
void n_caller(void) {
n_callee();
Expand All @@ -66,10 +66,10 @@ void n_caller(void) {


// CHECK-LABEL: define {{[^@]+}}@s_caller
// CHECK-SAME: () #[[default_streaming]] {
// CHECK-SAME: () #[[caller_streaming:[0-9]+]] {
// CHECK: call void @n_callee()
// CHECK: call void @s_callee() #[[streaming]]
// CHECK: call void @sc_callee() #[[streaming_compatible]]
// CHECK: call void @s_callee() #[[callsite_streaming]]
// CHECK: call void @sc_callee() #[[callsite_streaming_compatible]]
//
void s_caller(void) __arm_streaming {
n_callee();
Expand All @@ -79,10 +79,10 @@ void s_caller(void) __arm_streaming {


// CHECK-LABEL: define {{[^@]+}}@sc_caller
// CHECK-SAME: () #[[default_streaming_compatible]] {
// CHECK-SAME: () #[[caller_streaming_compatible:[0-9]+]] {
// CHECK: call void @n_callee()
// CHECK: call void @s_callee() #[[streaming]]
// CHECK: call void @sc_callee() #[[streaming_compatible]]
// CHECK: call void @s_callee() #[[callsite_streaming]]
// CHECK: call void @sc_callee() #[[callsite_streaming_compatible]]
//
void sc_caller(void) __arm_streaming_compatible {
n_callee();
Expand All @@ -103,5 +103,8 @@ void sc_caller(void) __arm_streaming_compatible {
// CHECK: attributes #[[simd_streaming_compatible]] = {{.*}} "aarch64_pstate_sm_compatible"
// CHECK: attributes #[[locally_streaming_sme2_streaming_compatible]] = {{.*}} "aarch64_pstate_sm_body" "aarch64_pstate_sm_compatible"
// CHECK: attributes #[[default_streaming_compatible]] = {{.*}} "aarch64_pstate_sm_compatible"
// CHECK: attributes #[[streaming]] = {{.*}} "aarch64_pstate_sm_enabled"
// CHECK: attributes #[[streaming_compatible]] = {{.*}} "aarch64_pstate_sm_compatible"
// CHECK: attributes #[[caller]] = {{.*}}
// CHECK: attributes #[[caller_streaming]] = {{.*}} "aarch64_pstate_sm_enabled"
// CHECK: attributes #[[caller_streaming_compatible]] = {{.*}} "aarch64_pstate_sm_compatible"
// CHECK: attributes #[[callsite_streaming]] = {{.*}} "aarch64_pstate_sm_enabled"
// CHECK: attributes #[[callsite_streaming_compatible]] = {{.*}} "aarch64_pstate_sm_compatible"
Loading
Loading