aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenFunction.cpp
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2023-08-25 20:56:25 -0700
committerFangrui Song <i@maskray.me>2023-08-25 20:56:25 -0700
commit27da15381cbe2ac6fd1319f6409dbbab9a857b7b (patch)
tree7ddb526b8d321736684bffb84c0fcd53efa3e371 /clang/lib/CodeGen/CodeGenFunction.cpp
parent9de3b35ac9159d5bae6e6796cb91e4f877a07189 (diff)
downloadllvm-27da15381cbe2ac6fd1319f6409dbbab9a857b7b.zip
llvm-27da15381cbe2ac6fd1319f6409dbbab9a857b7b.tar.gz
llvm-27da15381cbe2ac6fd1319f6409dbbab9a857b7b.tar.bz2
[X86] __builtin_cpu_supports: support x86-64{,-v2,-v3,-v4}
GCC 12 (https://gcc.gnu.org/PR101696) allows __builtin_cpu_supports("x86-64") (and -v2 -v3 -v4). This patch ports the feature. * Add `FEATURE_X86_64_{BASELINE,V2,V3,V4}` to enum ProcessorFeatures, but keep CPU_FEATURE_MAX unchanged to make FeatureInfos/FeatureInfos_WithPLUS happy. * Change validateCpuSupports to allow `x86-64{,-v2,-v3,-v4}` * Change getCpuSupportsMask to return `std::array<uint32_t, 4>` where `x86-64{,-v2,-v3,-v4}` set bits `FEATURE_X86_64_{BASELINE,V2,V3,V4}`. * `target("x86-64")` and `cpu_dispatch(x86_64)` are invalid. Tested by commit 9de3b35ac9159d5bae6e6796cb91e4f877a07189 Close https://github.com/llvm/llvm-project/issues/59961 Reviewed By: pengfei Differential Revision: https://reviews.llvm.org/D158811
Diffstat (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenFunction.cpp22
1 files changed, 5 insertions, 17 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp
index 7b456ed..bf83171 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -2683,24 +2683,12 @@ llvm::Value *CodeGenFunction::FormX86ResolverCondition(
if (!RO.Conditions.Architecture.empty()) {
StringRef Arch = RO.Conditions.Architecture;
- std::array<uint32_t, 4> Mask{};
- // If arch= specifies an x86-64 micro-architecture level, test a special
- // feature named FEATURE_X86_64_*, otherwise we use __builtin_cpu_is.
- if (Arch.consume_front("x86-64")) {
- if (Arch.empty()) // FEATURE_X86_64_BASELINE 95=2*32+31
- Mask[2] = 1u << 31;
- else if (Arch == "-v2") // FEATURE_X86_64_V2 96==3*32+0
- Mask[3] = 1u << 0;
- else if (Arch == "-v3") // FEATURE_X86_64_V3 97==3*32+1
- Mask[3] = 1u << 1;
- else if (Arch == "-v4") // FEATURE_X86_64_V3 98==3*32+2
- Mask[3] = 1u << 2;
- else
- llvm_unreachable("invalid x86-64 micro-architecture level");
- Condition = EmitX86CpuSupports(Mask);
- } else {
+ // If arch= specifies an x86-64 micro-architecture level, test the feature
+ // with __builtin_cpu_supports, otherwise use __builtin_cpu_is.
+ if (Arch.starts_with("x86-64"))
+ Condition = EmitX86CpuSupports({Arch});
+ else
Condition = EmitX86CpuIs(Arch);
- }
}
if (!RO.Conditions.Features.empty()) {