llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Qiu Chaofan (ecnelises) <details> <summary>Changes</summary> Currently targets except AArch64 cannot recognize function attribute specifying target CPU. Make it equivalent to `arch` directive. --- Full diff: https://github.com/llvm/llvm-project/pull/68678.diff 2 Files Affected: - (modified) clang/lib/Basic/TargetInfo.cpp (+4-3) - (modified) clang/test/Sema/attr-target.c (+4) ``````````diff diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp index 6cd5d618a4acaa5..474f4173eb5257d 100644 --- a/clang/lib/Basic/TargetInfo.cpp +++ b/clang/lib/Basic/TargetInfo.cpp @@ -560,11 +560,12 @@ ParsedTargetAttr TargetInfo::parseTargetAttr(StringRef Features) const { } // While we're here iterating check for a different target cpu. - if (Feature.startswith("arch=")) { + if (Feature.startswith("arch=") || Feature.startswith("cpu=")) { + auto [Key, CPU] = Feature.split("="); if (!Ret.CPU.empty()) - Ret.Duplicate = "arch="; + Ret.Duplicate = StringRef(Key.data(), Key.size() + 1); else - Ret.CPU = Feature.split("=").second.trim(); + Ret.CPU = CPU.trim(); } else if (Feature.startswith("tune=")) { if (!Ret.Tune.empty()) Ret.Duplicate = "tune="; diff --git a/clang/test/Sema/attr-target.c b/clang/test/Sema/attr-target.c index 3416a3d0a6ba134..631e40b947ed69b 100644 --- a/clang/test/Sema/attr-target.c +++ b/clang/test/Sema/attr-target.c @@ -17,10 +17,14 @@ int __attribute__((target("avx,sse4.2,arch=hiss"))) meow(void) { return 4; } int __attribute__((target("woof"))) bark(void) { return 4; } // no warning, same as saying 'nothing'. int __attribute__((target("arch="))) turtle(void) { return 4; } +// no warning, same as saying 'nothing'. +int __attribute__((target("cpu="))) equus(void) { return 4; } //expected-warning@+1 {{unknown CPU 'hiss' in the 'target' attribute string; 'target' attribute ignored}} int __attribute__((target("arch=hiss,arch=woof"))) pine_tree(void) { return 4; } //expected-warning@+1 {{duplicate 'arch=' in the 'target' attribute string; 'target' attribute ignored}} int __attribute__((target("arch=ivybridge,arch=haswell"))) oak_tree(void) { return 4; } +//expected-warning@+1 {{duplicate 'cpu=' in the 'target' attribute string; 'target' attribute ignored}} +int __attribute__((target("arch=ivybridge,cpu=haswell"))) cypress_tree(void) { return 4; } //expected-warning@+1 {{unsupported 'branch-protection' in the 'target' attribute string; 'target' attribute ignored}} int __attribute__((target("branch-protection=none"))) birch_tree(void) { return 5; } //expected-warning@+1 {{unknown tune CPU 'hiss' in the 'target' attribute string; 'target' attribute ignored}} `````````` </details> https://github.com/llvm/llvm-project/pull/68678 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits