Skip to content

Commit b93ffa8

Browse files
authored
[FMV][AArch64] Changes in fmv-features metadata. (#122192)
* 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.
1 parent 6f53886 commit b93ffa8

File tree

6 files changed

+154
-138
lines changed

6 files changed

+154
-138
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
#include "llvm/TargetParser/X86TargetParser.h"
7474
#include "llvm/Transforms/Utils/BuildLibCalls.h"
7575
#include <optional>
76+
#include <set>
7677

7778
using namespace clang;
7879
using namespace CodeGen;
@@ -2748,17 +2749,26 @@ bool CodeGenModule::GetCPUAndFeaturesAttributes(GlobalDecl GD,
27482749
Attrs.addAttribute("target-features", llvm::join(Features, ","));
27492750
AddedAttr = true;
27502751
}
2752+
// Add metadata for AArch64 Function Multi Versioning.
27512753
if (getTarget().getTriple().isAArch64()) {
27522754
llvm::SmallVector<StringRef, 8> Feats;
2753-
if (TV)
2755+
bool IsDefault = false;
2756+
if (TV) {
2757+
IsDefault = TV->isDefaultVersion();
27542758
TV->getFeatures(Feats);
2755-
else if (TC)
2759+
} else if (TC) {
2760+
IsDefault = TC->isDefaultVersion(GD.getMultiVersionIndex());
27562761
TC->getFeatures(Feats, GD.getMultiVersionIndex());
2757-
if (!Feats.empty()) {
2758-
llvm::sort(Feats);
2762+
}
2763+
if (IsDefault) {
2764+
Attrs.addAttribute("fmv-features");
2765+
AddedAttr = true;
2766+
} else if (!Feats.empty()) {
2767+
// Sort features and remove duplicates.
2768+
std::set<StringRef> OrderedFeats(Feats.begin(), Feats.end());
27592769
std::string FMVFeatures;
2760-
for (StringRef F : Feats)
2761-
FMVFeatures.append(",+" + F.str());
2770+
for (StringRef F : OrderedFeats)
2771+
FMVFeatures.append("," + F.str());
27622772
Attrs.addAttribute("fmv-features", FMVFeatures.substr(1));
27632773
AddedAttr = true;
27642774
}
@@ -2800,6 +2810,7 @@ void CodeGenModule::setNonAliasAttributes(GlobalDecl GD,
28002810
llvm::AttributeMask RemoveAttrs;
28012811
RemoveAttrs.addAttribute("target-cpu");
28022812
RemoveAttrs.addAttribute("target-features");
2813+
RemoveAttrs.addAttribute("fmv-features");
28032814
RemoveAttrs.addAttribute("tune-cpu");
28042815
F->removeFnAttrs(RemoveAttrs);
28052816
F->addFnAttrs(Attrs);

clang/test/CodeGen/AArch64/fmv-features.c

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -139,62 +139,64 @@ __attribute__((target_version("sve2-sm4"))) int fmv(void) { return 0; }
139139
// CHECK: define dso_local i32 @fmv._Mwfxt() #[[wfxt:[0-9]+]] {
140140
__attribute__((target_version("wfxt"))) int fmv(void) { return 0; }
141141

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

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

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

150151
int caller() {
151152
return fmv();
152153
}
153154

154-
// CHECK: attributes #[[aes]] = { {{.*}} "fmv-features"="+aes"
155-
// CHECK: attributes #[[bf16]] = { {{.*}} "fmv-features"="+bf16"
156-
// CHECK: attributes #[[bti]] = { {{.*}} "fmv-features"="+bti"
157-
// CHECK: attributes #[[crc]] = { {{.*}} "fmv-features"="+crc"
158-
// CHECK: attributes #[[dit]] = { {{.*}} "fmv-features"="+dit"
159-
// CHECK: attributes #[[dotprod]] = { {{.*}} "fmv-features"="+dotprod"
160-
// CHECK: attributes #[[dpb]] = { {{.*}} "fmv-features"="+dpb"
161-
// CHECK: attributes #[[dpb2]] = { {{.*}} "fmv-features"="+dpb2"
162-
// CHECK: attributes #[[f32mm]] = { {{.*}} "fmv-features"="+f32mm"
163-
// CHECK: attributes #[[f64mm]] = { {{.*}} "fmv-features"="+f64mm"
164-
// CHECK: attributes #[[fcma]] = { {{.*}} "fmv-features"="+fcma"
165-
// CHECK: attributes #[[flagm]] = { {{.*}} "fmv-features"="+flagm"
166-
// CHECK: attributes #[[flagm2]] = { {{.*}} "fmv-features"="+flagm2"
167-
// CHECK: attributes #[[fp]] = { {{.*}} "fmv-features"="+fp"
168-
// CHECK: attributes #[[fp16]] = { {{.*}} "fmv-features"="+fp16"
169-
// CHECK: attributes #[[fp16fml]] = { {{.*}} "fmv-features"="+fp16fml"
170-
// CHECK: attributes #[[frintts]] = { {{.*}} "fmv-features"="+frintts"
171-
// CHECK: attributes #[[i8mm]] = { {{.*}} "fmv-features"="+i8mm"
172-
// CHECK: attributes #[[jscvt]] = { {{.*}} "fmv-features"="+jscvt"
173-
// CHECK: attributes #[[ls64]] = { {{.*}} "fmv-features"="+ls64"
174-
// CHECK: attributes #[[lse]] = { {{.*}} "fmv-features"="+lse"
175-
// CHECK: attributes #[[memtag]] = { {{.*}} "fmv-features"="+memtag"
176-
// CHECK: attributes #[[mops]] = { {{.*}} "fmv-features"="+mops"
177-
// CHECK: attributes #[[predres]] = { {{.*}} "fmv-features"="+predres"
178-
// CHECK: attributes #[[rcpc]] = { {{.*}} "fmv-features"="+rcpc"
179-
// CHECK: attributes #[[rcpc2]] = { {{.*}} "fmv-features"="+rcpc2"
180-
// CHECK: attributes #[[rcpc3]] = { {{.*}} "fmv-features"="+rcpc3"
181-
// CHECK: attributes #[[rdm]] = { {{.*}} "fmv-features"="+rdm"
182-
// CHECK: attributes #[[rng]] = { {{.*}} "fmv-features"="+rng"
183-
// CHECK: attributes #[[sb]] = { {{.*}} "fmv-features"="+sb"
184-
// CHECK: attributes #[[sha2]] = { {{.*}} "fmv-features"="+sha2"
185-
// CHECK: attributes #[[sha3]] = { {{.*}} "fmv-features"="+sha3"
186-
// CHECK: attributes #[[simd]] = { {{.*}} "fmv-features"="+simd"
187-
// CHECK: attributes #[[sm4]] = { {{.*}} "fmv-features"="+sm4"
188-
// CHECK: attributes #[[sme]] = { {{.*}} "fmv-features"="+sme"
189-
// CHECK: attributes #[[sme_f64f64]] = { {{.*}} "fmv-features"="+sme-f64f64"
190-
// CHECK: attributes #[[sme_i16i64]] = { {{.*}} "fmv-features"="+sme-i16i64"
191-
// CHECK: attributes #[[sme2]] = { {{.*}} "fmv-features"="+sme2"
192-
// CHECK: attributes #[[ssbs]] = { {{.*}} "fmv-features"="+ssbs"
193-
// CHECK: attributes #[[sve]] = { {{.*}} "fmv-features"="+sve"
194-
// CHECK: attributes #[[sve2]] = { {{.*}} "fmv-features"="+sve2"
195-
// CHECK: attributes #[[sve2_aes]] = { {{.*}} "fmv-features"="+sve2-aes"
196-
// CHECK: attributes #[[sve2_bitperm]] = { {{.*}} "fmv-features"="+sve2-bitperm"
197-
// CHECK: attributes #[[sve2_sha3]] = { {{.*}} "fmv-features"="+sve2-sha3"
198-
// CHECK: attributes #[[sve2_sm4]] = { {{.*}} "fmv-features"="+sve2-sm4"
199-
// CHECK: attributes #[[wfxt]] = { {{.*}} "fmv-features"="+wfxt"
200-
// CHECK: attributes #[[multiple_features]] = { {{.*}} "fmv-features"="+aes,+bf16,+bti,+crc"
155+
// CHECK: attributes #[[aes]] = {{.*}} "fmv-features"="aes"
156+
// CHECK: attributes #[[bf16]] = {{.*}} "fmv-features"="bf16"
157+
// CHECK: attributes #[[bti]] = {{.*}} "fmv-features"="bti"
158+
// CHECK: attributes #[[crc]] = {{.*}} "fmv-features"="crc"
159+
// CHECK: attributes #[[dit]] = {{.*}} "fmv-features"="dit"
160+
// CHECK: attributes #[[dotprod]] = {{.*}} "fmv-features"="dotprod"
161+
// CHECK: attributes #[[dpb]] = {{.*}} "fmv-features"="dpb"
162+
// CHECK: attributes #[[dpb2]] = {{.*}} "fmv-features"="dpb2"
163+
// CHECK: attributes #[[f32mm]] = {{.*}} "fmv-features"="f32mm"
164+
// CHECK: attributes #[[f64mm]] = {{.*}} "fmv-features"="f64mm"
165+
// CHECK: attributes #[[fcma]] = {{.*}} "fmv-features"="fcma"
166+
// CHECK: attributes #[[flagm]] = {{.*}} "fmv-features"="flagm"
167+
// CHECK: attributes #[[flagm2]] = {{.*}} "fmv-features"="flagm2"
168+
// CHECK: attributes #[[fp]] = {{.*}} "fmv-features"="fp"
169+
// CHECK: attributes #[[fp16]] = {{.*}} "fmv-features"="fp16"
170+
// CHECK: attributes #[[fp16fml]] = {{.*}} "fmv-features"="fp16fml"
171+
// CHECK: attributes #[[frintts]] = {{.*}} "fmv-features"="frintts"
172+
// CHECK: attributes #[[i8mm]] = {{.*}} "fmv-features"="i8mm"
173+
// CHECK: attributes #[[jscvt]] = {{.*}} "fmv-features"="jscvt"
174+
// CHECK: attributes #[[ls64]] = {{.*}} "fmv-features"="ls64"
175+
// CHECK: attributes #[[lse]] = {{.*}} "fmv-features"="lse"
176+
// CHECK: attributes #[[memtag]] = {{.*}} "fmv-features"="memtag"
177+
// CHECK: attributes #[[mops]] = {{.*}} "fmv-features"="mops"
178+
// CHECK: attributes #[[predres]] = {{.*}} "fmv-features"="predres"
179+
// CHECK: attributes #[[rcpc]] = {{.*}} "fmv-features"="rcpc"
180+
// CHECK: attributes #[[rcpc2]] = {{.*}} "fmv-features"="rcpc2"
181+
// CHECK: attributes #[[rcpc3]] = {{.*}} "fmv-features"="rcpc3"
182+
// CHECK: attributes #[[rdm]] = {{.*}} "fmv-features"="rdm"
183+
// CHECK: attributes #[[rng]] = {{.*}} "fmv-features"="rng"
184+
// CHECK: attributes #[[sb]] = {{.*}} "fmv-features"="sb"
185+
// CHECK: attributes #[[sha2]] = {{.*}} "fmv-features"="sha2"
186+
// CHECK: attributes #[[sha3]] = {{.*}} "fmv-features"="sha3"
187+
// CHECK: attributes #[[simd]] = {{.*}} "fmv-features"="simd"
188+
// CHECK: attributes #[[sm4]] = {{.*}} "fmv-features"="sm4"
189+
// CHECK: attributes #[[sme]] = {{.*}} "fmv-features"="sme"
190+
// CHECK: attributes #[[sme_f64f64]] = {{.*}} "fmv-features"="sme-f64f64"
191+
// CHECK: attributes #[[sme_i16i64]] = {{.*}} "fmv-features"="sme-i16i64"
192+
// CHECK: attributes #[[sme2]] = {{.*}} "fmv-features"="sme2"
193+
// CHECK: attributes #[[ssbs]] = {{.*}} "fmv-features"="ssbs"
194+
// CHECK: attributes #[[sve]] = {{.*}} "fmv-features"="sve"
195+
// CHECK: attributes #[[sve2]] = {{.*}} "fmv-features"="sve2"
196+
// CHECK: attributes #[[sve2_aes]] = {{.*}} "fmv-features"="sve2-aes"
197+
// CHECK: attributes #[[sve2_bitperm]] = {{.*}} "fmv-features"="sve2-bitperm"
198+
// CHECK: attributes #[[sve2_sha3]] = {{.*}} "fmv-features"="sve2-sha3"
199+
// CHECK: attributes #[[sve2_sm4]] = {{.*}} "fmv-features"="sve2-sm4"
200+
// CHECK: attributes #[[wfxt]] = {{.*}} "fmv-features"="wfxt"
201+
// CHECK: attributes #[[unordered_features_with_duplicates]] = {{.*}} "fmv-features"="aes,bf16,bti,crc"
202+
// CHECK: attributes #[[default]] = {{.*}} "fmv-features"

clang/test/CodeGen/AArch64/fmv-priority.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ int call() { return fn(); }
2626
//
2727
//
2828
// CHECK-LABEL: define dso_local i32 @call(
29-
// CHECK-SAME: ) #[[ATTR0]] {
29+
// CHECK-SAME: ) #[[ATTR1:[0-9]+]] {
3030
// CHECK-NEXT: [[ENTRY:.*:]]
3131
// CHECK-NEXT: [[CALL:%.*]] = call i32 @fn()
3232
// CHECK-NEXT: ret i32 [[CALL]]

clang/test/CodeGen/AArch64/fmv-streaming.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ __attribute__((target_version("default"))) void sc_callee(void) __arm_streaming_
5353

5454

5555
// CHECK-LABEL: define {{[^@]+}}@n_caller
56-
// CHECK-SAME: () #[[default]] {
56+
// CHECK-SAME: () #[[caller:[0-9]+]] {
5757
// CHECK: call void @n_callee()
58-
// CHECK: call void @s_callee() #[[streaming:[0-9]+]]
59-
// CHECK: call void @sc_callee() #[[streaming_compatible:[0-9]+]]
58+
// CHECK: call void @s_callee() #[[callsite_streaming:[0-9]+]]
59+
// CHECK: call void @sc_callee() #[[callsite_streaming_compatible:[0-9]+]]
6060
//
6161
void n_caller(void) {
6262
n_callee();
@@ -66,10 +66,10 @@ void n_caller(void) {
6666

6767

6868
// CHECK-LABEL: define {{[^@]+}}@s_caller
69-
// CHECK-SAME: () #[[default_streaming]] {
69+
// CHECK-SAME: () #[[caller_streaming:[0-9]+]] {
7070
// CHECK: call void @n_callee()
71-
// CHECK: call void @s_callee() #[[streaming]]
72-
// CHECK: call void @sc_callee() #[[streaming_compatible]]
71+
// CHECK: call void @s_callee() #[[callsite_streaming]]
72+
// CHECK: call void @sc_callee() #[[callsite_streaming_compatible]]
7373
//
7474
void s_caller(void) __arm_streaming {
7575
n_callee();
@@ -79,10 +79,10 @@ void s_caller(void) __arm_streaming {
7979

8080

8181
// CHECK-LABEL: define {{[^@]+}}@sc_caller
82-
// CHECK-SAME: () #[[default_streaming_compatible]] {
82+
// CHECK-SAME: () #[[caller_streaming_compatible:[0-9]+]] {
8383
// CHECK: call void @n_callee()
84-
// CHECK: call void @s_callee() #[[streaming]]
85-
// CHECK: call void @sc_callee() #[[streaming_compatible]]
84+
// CHECK: call void @s_callee() #[[callsite_streaming]]
85+
// CHECK: call void @sc_callee() #[[callsite_streaming_compatible]]
8686
//
8787
void sc_caller(void) __arm_streaming_compatible {
8888
n_callee();
@@ -103,5 +103,8 @@ void sc_caller(void) __arm_streaming_compatible {
103103
// CHECK: attributes #[[simd_streaming_compatible]] = {{.*}} "aarch64_pstate_sm_compatible"
104104
// CHECK: attributes #[[locally_streaming_sme2_streaming_compatible]] = {{.*}} "aarch64_pstate_sm_body" "aarch64_pstate_sm_compatible"
105105
// CHECK: attributes #[[default_streaming_compatible]] = {{.*}} "aarch64_pstate_sm_compatible"
106-
// CHECK: attributes #[[streaming]] = {{.*}} "aarch64_pstate_sm_enabled"
107-
// CHECK: attributes #[[streaming_compatible]] = {{.*}} "aarch64_pstate_sm_compatible"
106+
// CHECK: attributes #[[caller]] = {{.*}}
107+
// CHECK: attributes #[[caller_streaming]] = {{.*}} "aarch64_pstate_sm_enabled"
108+
// CHECK: attributes #[[caller_streaming_compatible]] = {{.*}} "aarch64_pstate_sm_compatible"
109+
// CHECK: attributes #[[callsite_streaming]] = {{.*}} "aarch64_pstate_sm_enabled"
110+
// CHECK: attributes #[[callsite_streaming_compatible]] = {{.*}} "aarch64_pstate_sm_compatible"

0 commit comments

Comments
 (0)