Skip to content

Commit

Permalink
[FMV][AArch64] Changes in fmv-features metadata.
Browse files Browse the repository at this point in the history
* We want the default version to have this attribute too otherwise
  it becomes indistinguishable from non-versioned functions.

* We don't need the '+' unlike target-features which can negate.
  This will allow using the parsing API of target_version/clones
  for the metadata too.
  • Loading branch information
labrinea committed Jan 8, 2025
1 parent 5083980 commit a93614e
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 134 deletions.
16 changes: 12 additions & 4 deletions clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2748,17 +2748,25 @@ 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()) {
}
if (IsDefault) {
Attrs.addAttribute("fmv-features");
AddedAttr = true;
} else if (!Feats.empty()) {
llvm::sort(Feats);
std::string FMVFeatures;
for (StringRef F : Feats)
FMVFeatures.append(",+" + F.str());
FMVFeatures.append("," + F.str());
Attrs.addAttribute("fmv-features", FMVFeatures.substr(1));
AddedAttr = true;
}
Expand Down
96 changes: 49 additions & 47 deletions clang/test/CodeGen/AArch64/fmv-features.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,56 +145,58 @@ __attribute__((target_version("aes+bf16+bti+crc"))) 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 #[[multiple_features]] = {{.*}} "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

0 comments on commit a93614e

Please sign in to comment.