Skip to content

Commit f2b1b7f

Browse files
committed
Supports option 2 of ARM-software/acle#403
depends on option 1 #146092
1 parent c5e6d92 commit f2b1b7f

File tree

5 files changed

+41
-14
lines changed

5 files changed

+41
-14
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4911,7 +4911,8 @@ class Sema final : public SemaBase {
49114911
bool checkTargetAttr(SourceLocation LiteralLoc, StringRef Str);
49124912

49134913
/// Check Target Version attrs
4914-
bool checkTargetVersionAttr(SourceLocation Loc, Decl *D, StringRef Str);
4914+
bool checkTargetVersionAttr(SourceLocation Loc, Decl *D, StringRef Str,
4915+
SmallString<64> &);
49154916
bool checkTargetClonesAttrString(
49164917
SourceLocation LiteralLoc, StringRef Str, const StringLiteral *Literal,
49174918
Decl *D, bool &HasDefault, bool &HasCommas, bool &HasNotDefault,

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3279,7 +3279,7 @@ bool Sema::checkTargetAttr(SourceLocation LiteralLoc, StringRef AttrStr) {
32793279
}
32803280

32813281
bool Sema::checkTargetVersionAttr(SourceLocation LiteralLoc, Decl *D,
3282-
StringRef AttrStr) {
3282+
StringRef AttrStr, SmallString<64> &NewStr) {
32833283
enum FirstParam { Unsupported };
32843284
enum SecondParam { None };
32853285
enum ThirdParam { Target, TargetClones, TargetVersion };
@@ -3330,11 +3330,19 @@ bool Sema::checkTargetVersionAttr(SourceLocation LiteralLoc, Decl *D,
33303330
return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
33313331
<< Unsupported << None << AttrStr << TargetVersion;
33323332

3333+
NewStr = AttrStr;
33333334
return false;
33343335
}
3335-
AttrStr.split(Features, "+");
3336+
3337+
auto [LHS, RHS] = AttrStr.split(';');
3338+
LHS.split(Features, '+');
3339+
if (!RHS.empty())
3340+
RHS.split(Features, '+');
33363341
for (auto &CurFeature : Features) {
33373342
CurFeature = CurFeature.trim();
3343+
if (!NewStr.empty())
3344+
NewStr.append("+");
3345+
NewStr.append(CurFeature);
33383346
if (CurFeature == "default")
33393347
continue;
33403348
if (!Context.getTargetInfo().validateCpuSupports(CurFeature))
@@ -3346,12 +3354,13 @@ bool Sema::checkTargetVersionAttr(SourceLocation LiteralLoc, Decl *D,
33463354

33473355
static void handleTargetVersionAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
33483356
StringRef Str;
3357+
SmallString<64> NewStr;
33493358
SourceLocation LiteralLoc;
33503359
if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, &LiteralLoc) ||
3351-
S.checkTargetVersionAttr(LiteralLoc, D, Str))
3360+
S.checkTargetVersionAttr(LiteralLoc, D, Str, NewStr))
33523361
return;
33533362
TargetVersionAttr *NewAttr =
3354-
::new (S.Context) TargetVersionAttr(S.Context, AL, Str);
3363+
::new (S.Context) TargetVersionAttr(S.Context, AL, NewStr);
33553364
D->addAttr(NewAttr);
33563365
}
33573366

@@ -3404,6 +3413,19 @@ bool Sema::checkTargetClonesAttrString(
34043413
else
34053414
StringsBuffer.push_back(Cur);
34063415
} else {
3416+
auto [LHS, RHS] = Cur.split(';');
3417+
StringRef Priority;
3418+
if (LHS.starts_with("priority")) {
3419+
Priority = LHS;
3420+
Cur = !RHS.empty() ? RHS : LHS;
3421+
} else if (RHS.starts_with("priority")) {
3422+
Priority = RHS;
3423+
Cur = LHS;
3424+
}
3425+
if (!Priority.empty() && !TInfo.validateCpuSupports(Priority))
3426+
Diag(CurLoc, diag::warn_unsupported_target_attribute)
3427+
<< Unsupported << None << Priority << TargetClones;
3428+
34073429
std::pair<StringRef, StringRef> CurParts = {{}, Cur};
34083430
llvm::SmallVector<StringRef, 8> CurFeatures;
34093431
while (!CurParts.second.empty()) {
@@ -3426,6 +3448,10 @@ bool Sema::checkTargetClonesAttrString(
34263448
Res.append("+");
34273449
Res.append(CurFeat);
34283450
}
3451+
if (!Res.empty() && !Priority.empty()) {
3452+
Res.append("+");
3453+
Res.append(Priority);
3454+
}
34293455
if (llvm::is_contained(StringsBuffer, Res) || DefaultIsDupe)
34303456
Diag(CurLoc, diag::warn_target_clone_duplicate_options);
34313457
else if (!HasCodeGenImpact)

clang/test/AST/attr-target-version.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
int __attribute__((target_version("sve2-bitperm + sha2"))) foov(void) { return 1; }
44
int __attribute__((target_clones(" lse + fp + sha3 ", "default"))) fooc(void) { return 2; }
55
// CHECK: TargetVersionAttr
6-
// CHECK: sve2-bitperm + sha2
6+
// CHECK: sve2-bitperm+sha2
77
// CHECK: TargetClonesAttr
88
// CHECK: fp+lse+sha3 default

clang/test/CodeGen/AArch64/fmv-duplicate-mangled-name.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ __attribute__((target_clones("aes", "lse", "default"))) int explicit_default_bad
2828
__attribute__((target_version("aes"))) int explicit_version_priority(void) { return 0; }
2929
// expected-error@+2 {{definition with same mangled name 'explicit_version_priority._Maes' as another definition}}
3030
// expected-note@-2 {{previous definition is here}}
31-
__attribute__((target_version("priority1+aes"))) int explicit_version_priority(void) { return 1; }
31+
__attribute__((target_version("priority1;aes"))) int explicit_version_priority(void) { return 1; }
3232

3333
#elif defined(CHECK_EXPLICIT_CLONES_PRIORITY)
3434

35-
__attribute__((target_version("aes+priority2"))) int explicit_clones_priority(void) { return 0; }
35+
__attribute__((target_version("aes;priority2"))) int explicit_clones_priority(void) { return 0; }
3636
// expected-error@+2 {{definition with same mangled name 'explicit_clones_priority._Maes' as another definition}}
3737
// expected-note@-2 {{previous definition is here}}
38-
__attribute__((target_clones("priority1+aes", "lse"))) int explicit_clones_priority(void) { return 1; }
38+
__attribute__((target_clones("priority1;aes", "lse"))) int explicit_clones_priority(void) { return 1; }
3939

4040
#endif

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --check-attributes --check-globals --include-generated-funcs
22
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -O3 -fno-inline -emit-llvm -o - %s | FileCheck %s
33

4-
__attribute__((target_version("priority1+lse"))) int foo(void) { return 1; }
5-
__attribute__((target_version("priority2+sve2"))) int foo(void) { return 2; }
6-
__attribute__((target_version("priority3+sve"))) int foo(void) { return 3; }
4+
__attribute__((target_version("priority1;lse"))) int foo(void) { return 1; }
5+
__attribute__((target_version("priority2;sve2"))) int foo(void) { return 2; }
6+
__attribute__((target_version("priority3;sve"))) int foo(void) { return 3; }
77
__attribute__((target_version( "default"))) int foo(void) { return 0; }
88

9-
__attribute__((target_clones("priority1+lse+sve2", "priority2+lse", "priority3+sve", "default")))
9+
__attribute__((target_clones("priority1;lse+sve2", "priority2;lse", "priority3;sve", "default")))
1010
int fmv_caller(void) { return foo(); }
1111

1212

1313
__attribute__((target_version("aes"))) int bar(void) { return 1; }
14-
__attribute__((target_version("priority1+sm4"))) int bar(void) { return 2; }
14+
__attribute__((target_version("priority1;sm4"))) int bar(void) { return 2; }
1515
__attribute__((target_version("default"))) int bar(void) { return 0; }
1616

1717
__attribute__((target("aes"))) int regular_caller_aes() { return bar(); }

0 commit comments

Comments
 (0)