Author: Mikołaj Piróg Date: 2026-07-07T15:03:15+02:00 New Revision: 91578461e8a112941afeed18679efb168b81f796
URL: https://github.com/llvm/llvm-project/commit/91578461e8a112941afeed18679efb168b81f796 DIFF: https://github.com/llvm/llvm-project/commit/91578461e8a112941afeed18679efb168b81f796.diff LOG: [X86] Sync compiler-rt cpu subtypes and vendors with libgcc and refactor internal cpu type tables in LLVM (#171172) This is a continuation of previous PR: https://github.com/llvm/llvm-project/pull/168750 compiler-rt was synced with libgcc on ProcessorVendor and ProcessorSubtype fields and so was llvm. Cpu type, subtype and vendor entries in X86TargetParser.def were refactored to use ABI_VALUE. LLVM doesn't set the ABI_VALUE for its enums -- clang now takes care of that by reading the ABI_VALUE. I've removed and added some comments to better explain what is going on. While at it, I've added tests to check that right values are passed for vendor, subtypes, types and features (the last ones weren't added in feature sync PR: https://github.com/llvm/llvm-project/pull/168750) Parts of the PR (test) have been realized using Claude Code Added: clang/test/CodeGen/builtin-cpu-is-cputype.c clang/test/CodeGen/builtin-cpu-is-subtype.c clang/test/CodeGen/builtin-cpu-is-vendor.c clang/test/CodeGen/builtin-cpu-supports-all.c Modified: clang/lib/Basic/Targets/X86.cpp clang/lib/CodeGen/TargetBuiltins/X86.cpp compiler-rt/lib/builtins/cpu_model/x86.c llvm/include/llvm/TargetParser/X86TargetParser.def llvm/include/llvm/TargetParser/X86TargetParser.h llvm/lib/TargetParser/X86TargetParser.cpp Removed: clang/test/CodeGen/builtin-cpu-is.c ################################################################################ diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp index d995ccabbcdc0..34daa703e32d8 100644 --- a/clang/lib/Basic/Targets/X86.cpp +++ b/clang/lib/Basic/Targets/X86.cpp @@ -1385,11 +1385,9 @@ void X86TargetInfo::getCPUSpecificCPUDispatchFeatures( // rather than the full range of cpus. bool X86TargetInfo::validateCpuIs(StringRef FeatureStr) const { return llvm::StringSwitch<bool>(FeatureStr) -#define X86_VENDOR(ENUM, STRING) .Case(STRING, true) -#define X86_CPU_TYPE_ALIAS(ENUM, ALIAS) .Case(ALIAS, true) -#define X86_CPU_TYPE(ENUM, STR) .Case(STR, true) -#define X86_CPU_SUBTYPE_ALIAS(ENUM, ALIAS) .Case(ALIAS, true) -#define X86_CPU_SUBTYPE(ENUM, STR) .Case(STR, true) +#define X86_VENDOR(ENUM, STRING, ABI_VALUE) .Case(STRING, true) +#define X86_CPU_TYPE(ENUM, STR, ABI_VALUE) .Case(STR, true) +#define X86_CPU_SUBTYPE(ENUM, STR, ABI_VALUE) .Case(STR, true) #include "llvm/TargetParser/X86TargetParser.def" .Default(false); } diff --git a/clang/lib/CodeGen/TargetBuiltins/X86.cpp b/clang/lib/CodeGen/TargetBuiltins/X86.cpp index 50125a71fcd5f..0e675421d4278 100644 --- a/clang/lib/CodeGen/TargetBuiltins/X86.cpp +++ b/clang/lib/CodeGen/TargetBuiltins/X86.cpp @@ -682,18 +682,11 @@ Value *CodeGenFunction::EmitX86CpuIs(StringRef CPUStr) { cast<llvm::GlobalValue>(CpuModel)->setDSOLocal(true); // Calculate the index needed to access the correct field based on the - // range. Also adjust the expected value. + // range. ABI_VALUE matches with compiler-rt/libgcc values. auto [Index, Value] = StringSwitch<std::pair<unsigned, unsigned>>(CPUStr) -#define X86_VENDOR(ENUM, STRING) \ - .Case(STRING, {0u, static_cast<unsigned>(llvm::X86::ENUM)}) -#define X86_CPU_TYPE_ALIAS(ENUM, ALIAS) \ - .Case(ALIAS, {1u, static_cast<unsigned>(llvm::X86::ENUM)}) -#define X86_CPU_TYPE(ENUM, STR) \ - .Case(STR, {1u, static_cast<unsigned>(llvm::X86::ENUM)}) -#define X86_CPU_SUBTYPE_ALIAS(ENUM, ALIAS) \ - .Case(ALIAS, {2u, static_cast<unsigned>(llvm::X86::ENUM)}) -#define X86_CPU_SUBTYPE(ENUM, STR) \ - .Case(STR, {2u, static_cast<unsigned>(llvm::X86::ENUM)}) +#define X86_VENDOR(ENUM, STRING, ABI_VALUE) .Case(STRING, {0u, ABI_VALUE}) +#define X86_CPU_TYPE(ENUM, STR, ABI_VALUE) .Case(STR, {1u, ABI_VALUE}) +#define X86_CPU_SUBTYPE(ENUM, STR, ABI_VALUE) .Case(STR, {2u, ABI_VALUE}) #include "llvm/TargetParser/X86TargetParser.def" .Default({0, 0}); assert(Value != 0 && "Invalid CPUStr passed to CpuIs"); diff --git a/clang/test/CodeGen/builtin-cpu-is-cputype.c b/clang/test/CodeGen/builtin-cpu-is-cputype.c new file mode 100644 index 0000000000000..55fe308787d0f --- /dev/null +++ b/clang/test/CodeGen/builtin-cpu-is-cputype.c @@ -0,0 +1,145 @@ +// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm < %s | FileCheck %s + +// Test that __builtin_cpu_is emits the correct ABI value for every CPU type, +// in llvm/include/llvm/TargetParser/X86TargetParser.def. +extern void a(const char *); + +// CHECK: @__cpu_model = external dso_local global { i32, i32, i32, [1 x i32] } + +#define TEST_CPU_IS(NAME, STR) \ + void test_##NAME(void) { \ + if (__builtin_cpu_is(STR)) \ + a(STR); \ + } + +// CHECK-LABEL: define{{.*}} void @test_bonnell( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 4) +// CHECK: = icmp eq i32 [[LOAD]], 1 +TEST_CPU_IS(bonnell, "bonnell") + +// CHECK-LABEL: define{{.*}} void @test_core2( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 4) +// CHECK: = icmp eq i32 [[LOAD]], 2 +TEST_CPU_IS(core2, "core2") + +// CHECK-LABEL: define{{.*}} void @test_corei7( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 4) +// CHECK: = icmp eq i32 [[LOAD]], 3 +TEST_CPU_IS(corei7, "corei7") + +// CHECK-LABEL: define{{.*}} void @test_amdfam10h( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 4) +// CHECK: = icmp eq i32 [[LOAD]], 4 +TEST_CPU_IS(amdfam10h, "amdfam10h") + +// CHECK-LABEL: define{{.*}} void @test_amdfam15h( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 4) +// CHECK: = icmp eq i32 [[LOAD]], 5 +TEST_CPU_IS(amdfam15h, "amdfam15h") + +// CHECK-LABEL: define{{.*}} void @test_silvermont( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 4) +// CHECK: = icmp eq i32 [[LOAD]], 6 +TEST_CPU_IS(silvermont, "silvermont") + +// CHECK-LABEL: define{{.*}} void @test_knl( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 4) +// CHECK: = icmp eq i32 [[LOAD]], 7 +TEST_CPU_IS(knl, "knl") + +// CHECK-LABEL: define{{.*}} void @test_btver1( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 4) +// CHECK: = icmp eq i32 [[LOAD]], 8 +TEST_CPU_IS(btver1, "btver1") + +// CHECK-LABEL: define{{.*}} void @test_btver2( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 4) +// CHECK: = icmp eq i32 [[LOAD]], 9 +TEST_CPU_IS(btver2, "btver2") + +// CHECK-LABEL: define{{.*}} void @test_amdfam17h( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 4) +// CHECK: = icmp eq i32 [[LOAD]], 10 +TEST_CPU_IS(amdfam17h, "amdfam17h") + +// CHECK-LABEL: define{{.*}} void @test_knm( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 4) +// CHECK: = icmp eq i32 [[LOAD]], 11 +TEST_CPU_IS(knm, "knm") + +// CHECK-LABEL: define{{.*}} void @test_goldmont( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 4) +// CHECK: = icmp eq i32 [[LOAD]], 12 +TEST_CPU_IS(goldmont, "goldmont") + +// CHECK-LABEL: define{{.*}} void @test_goldmont_plus( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 4) +// CHECK: = icmp eq i32 [[LOAD]], 13 +TEST_CPU_IS(goldmont_plus, "goldmont-plus") + +// CHECK-LABEL: define{{.*}} void @test_tremont( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 4) +// CHECK: = icmp eq i32 [[LOAD]], 14 +TEST_CPU_IS(tremont, "tremont") + +// CHECK-LABEL: define{{.*}} void @test_amdfam19h( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 4) +// CHECK: = icmp eq i32 [[LOAD]], 15 +TEST_CPU_IS(amdfam19h, "amdfam19h") + +// CHECK-LABEL: define{{.*}} void @test_zhaoxin_fam7h( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 4) +// CHECK: = icmp eq i32 [[LOAD]], 16 +TEST_CPU_IS(zhaoxin_fam7h, "zhaoxin_fam7h") + +// CHECK-LABEL: define{{.*}} void @test_sierraforest( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 4) +// CHECK: = icmp eq i32 [[LOAD]], 17 +TEST_CPU_IS(sierraforest, "sierraforest") + +// CHECK-LABEL: define{{.*}} void @test_grandridge( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 4) +// CHECK: = icmp eq i32 [[LOAD]], 18 +TEST_CPU_IS(grandridge, "grandridge") + +// CHECK-LABEL: define{{.*}} void @test_clearwaterforest( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 4) +// CHECK: = icmp eq i32 [[LOAD]], 19 +TEST_CPU_IS(clearwaterforest, "clearwaterforest") + +// CHECK-LABEL: define{{.*}} void @test_amdfam1ah( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 4) +// CHECK: = icmp eq i32 [[LOAD]], 20 +TEST_CPU_IS(amdfam1ah, "amdfam1ah") + +// CHECK-LABEL: define{{.*}} void @test_hygonfam18h( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 4) +// CHECK: = icmp eq i32 [[LOAD]], 21 +TEST_CPU_IS(hygonfam18h, "hygonfam18h") + +// Aliases + +// CHECK-LABEL: define{{.*}} void @test_atom( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 4) +// CHECK: = icmp eq i32 [[LOAD]], 1 +TEST_CPU_IS(atom, "atom") + +// CHECK-LABEL: define{{.*}} void @test_amdfam10( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 4) +// CHECK: = icmp eq i32 [[LOAD]], 4 +TEST_CPU_IS(amdfam10, "amdfam10") + +// CHECK-LABEL: define{{.*}} void @test_amdfam15( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 4) +// CHECK: = icmp eq i32 [[LOAD]], 5 +TEST_CPU_IS(amdfam15, "amdfam15") + +// CHECK-LABEL: define{{.*}} void @test_slm( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 4) +// CHECK: = icmp eq i32 [[LOAD]], 6 +TEST_CPU_IS(slm, "slm") + +// CHECK-LABEL: define{{.*}} void @test_amdfam1a( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 4) +// CHECK: = icmp eq i32 [[LOAD]], 20 +TEST_CPU_IS(amdfam1a, "amdfam1a") diff --git a/clang/test/CodeGen/builtin-cpu-is-subtype.c b/clang/test/CodeGen/builtin-cpu-is-subtype.c new file mode 100644 index 0000000000000..8dbe58e852bc2 --- /dev/null +++ b/clang/test/CodeGen/builtin-cpu-is-subtype.c @@ -0,0 +1,255 @@ +// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm < %s | FileCheck %s + +// Test that __builtin_cpu_is emits the correct ABI value for every CPU +// subtype, llvm/include/llvm/TargetParser/X86TargetParser.def. +extern void a(const char *); + +// CHECK: @__cpu_model = external dso_local global { i32, i32, i32, [1 x i32] } + +#define TEST_CPU_IS(NAME, STR) \ + void test_##NAME(void) { \ + if (__builtin_cpu_is(STR)) \ + a(STR); \ + } + +// CHECK-LABEL: define{{.*}} void @test_nehalem( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 1 +TEST_CPU_IS(nehalem, "nehalem") + +// CHECK-LABEL: define{{.*}} void @test_westmere( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 2 +TEST_CPU_IS(westmere, "westmere") + +// CHECK-LABEL: define{{.*}} void @test_sandybridge( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 3 +TEST_CPU_IS(sandybridge, "sandybridge") + +// CHECK-LABEL: define{{.*}} void @test_barcelona( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 4 +TEST_CPU_IS(barcelona, "barcelona") + +// CHECK-LABEL: define{{.*}} void @test_shanghai( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 5 +TEST_CPU_IS(shanghai, "shanghai") + +// CHECK-LABEL: define{{.*}} void @test_istanbul( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 6 +TEST_CPU_IS(istanbul, "istanbul") + +// CHECK-LABEL: define{{.*}} void @test_bdver1( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 7 +TEST_CPU_IS(bdver1, "bdver1") + +// CHECK-LABEL: define{{.*}} void @test_bdver2( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 8 +TEST_CPU_IS(bdver2, "bdver2") + +// CHECK-LABEL: define{{.*}} void @test_bdver3( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 9 +TEST_CPU_IS(bdver3, "bdver3") + +// CHECK-LABEL: define{{.*}} void @test_bdver4( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 10 +TEST_CPU_IS(bdver4, "bdver4") + +// CHECK-LABEL: define{{.*}} void @test_znver1( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 11 +TEST_CPU_IS(znver1, "znver1") + +// CHECK-LABEL: define{{.*}} void @test_ivybridge( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 12 +TEST_CPU_IS(ivybridge, "ivybridge") + +// CHECK-LABEL: define{{.*}} void @test_haswell( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 13 +TEST_CPU_IS(haswell, "haswell") + +// CHECK-LABEL: define{{.*}} void @test_broadwell( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 14 +TEST_CPU_IS(broadwell, "broadwell") + +// CHECK-LABEL: define{{.*}} void @test_skylake( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 15 +TEST_CPU_IS(skylake, "skylake") + +// CHECK-LABEL: define{{.*}} void @test_skylake_avx512( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 16 +TEST_CPU_IS(skylake_avx512, "skylake-avx512") + +// CHECK-LABEL: define{{.*}} void @test_cannonlake( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 17 +TEST_CPU_IS(cannonlake, "cannonlake") + +// CHECK-LABEL: define{{.*}} void @test_icelake_client( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 18 +TEST_CPU_IS(icelake_client, "icelake-client") + +// CHECK-LABEL: define{{.*}} void @test_icelake_server( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 19 +TEST_CPU_IS(icelake_server, "icelake-server") + +// CHECK-LABEL: define{{.*}} void @test_znver2( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 20 +TEST_CPU_IS(znver2, "znver2") + +// CHECK-LABEL: define{{.*}} void @test_cascadelake( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 21 +TEST_CPU_IS(cascadelake, "cascadelake") + +// CHECK-LABEL: define{{.*}} void @test_tigerlake( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 22 +TEST_CPU_IS(tigerlake, "tigerlake") + +// CHECK-LABEL: define{{.*}} void @test_cooperlake( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 23 +TEST_CPU_IS(cooperlake, "cooperlake") + +// CHECK-LABEL: define{{.*}} void @test_sapphirerapids( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 24 +TEST_CPU_IS(sapphirerapids, "sapphirerapids") + +// CHECK-LABEL: define{{.*}} void @test_alderlake( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 25 +TEST_CPU_IS(alderlake, "alderlake") + +// CHECK-LABEL: define{{.*}} void @test_znver3( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 26 +TEST_CPU_IS(znver3, "znver3") + +// CHECK-LABEL: define{{.*}} void @test_rocketlake( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 27 +TEST_CPU_IS(rocketlake, "rocketlake") + +// CHECK-LABEL: define{{.*}} void @test_zhaoxin_fam7h_lujiazui( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 28 +TEST_CPU_IS(zhaoxin_fam7h_lujiazui, "zhaoxin_fam7h_lujiazui") + +// CHECK-LABEL: define{{.*}} void @test_znver4( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 29 +TEST_CPU_IS(znver4, "znver4") + +// CHECK-LABEL: define{{.*}} void @test_graniterapids( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 30 +TEST_CPU_IS(graniterapids, "graniterapids") + +// CHECK-LABEL: define{{.*}} void @test_graniterapids_d( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 31 +TEST_CPU_IS(graniterapids_d, "graniterapids-d") + +// CHECK-LABEL: define{{.*}} void @test_arrowlake( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 32 +TEST_CPU_IS(arrowlake, "arrowlake") + +// CHECK-LABEL: define{{.*}} void @test_arrowlake_s( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 33 +TEST_CPU_IS(arrowlake_s, "arrowlake-s") + +// CHECK-LABEL: define{{.*}} void @test_pantherlake( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 34 +TEST_CPU_IS(pantherlake, "pantherlake") + +// CHECK-LABEL: define{{.*}} void @test_znver5( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 36 +TEST_CPU_IS(znver5, "znver5") + +// CHECK-LABEL: define{{.*}} void @test_diamondrapids( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 38 +TEST_CPU_IS(diamondrapids, "diamondrapids") + +// CHECK-LABEL: define{{.*}} void @test_novalake( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 39 +TEST_CPU_IS(novalake, "novalake") + +// CHECK-LABEL: define{{.*}} void @test_znver6( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 40 +TEST_CPU_IS(znver6, "znver6") + +// CHECK-LABEL: define{{.*}} void @test_c86_4g_m4( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 41 +TEST_CPU_IS(c86_4g_m4, "c86-4g-m4") + +// CHECK-LABEL: define{{.*}} void @test_c86_4g_m6( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 42 +TEST_CPU_IS(c86_4g_m6, "c86-4g-m6") + +// CHECK-LABEL: define{{.*}} void @test_c86_4g_m7( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 43 +TEST_CPU_IS(c86_4g_m7, "c86-4g-m7") + +// CHECK-LABEL: define{{.*}} void @test_c86_4g_m8( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 44 +TEST_CPU_IS(c86_4g_m8, "c86-4g-m8") + +// Aliases + +// CHECK-LABEL: define{{.*}} void @test_emeraldrapids( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 24 +TEST_CPU_IS(emeraldrapids, "emeraldrapids") + +// CHECK-LABEL: define{{.*}} void @test_raptorlake( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 25 +TEST_CPU_IS(raptorlake, "raptorlake") + +// CHECK-LABEL: define{{.*}} void @test_meteorlake( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 25 +TEST_CPU_IS(meteorlake, "meteorlake") + +// CHECK-LABEL: define{{.*}} void @test_gracemont( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 25 +TEST_CPU_IS(gracemont, "gracemont") + +// CHECK-LABEL: define{{.*}} void @test_lunarlake( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 33 +TEST_CPU_IS(lunarlake, "lunarlake") + +// CHECK-LABEL: define{{.*}} void @test_wildcatlake( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) +// CHECK: = icmp eq i32 [[LOAD]], 34 +TEST_CPU_IS(wildcatlake, "wildcatlake") diff --git a/clang/test/CodeGen/builtin-cpu-is-vendor.c b/clang/test/CodeGen/builtin-cpu-is-vendor.c new file mode 100644 index 0000000000000..1532a566028e2 --- /dev/null +++ b/clang/test/CodeGen/builtin-cpu-is-vendor.c @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm < %s | FileCheck %s + +// Test that __builtin_cpu_is emits the correct ABI value and field offset for +// every vendor (field offset 0) in llvm/include/llvm/TargetParser/ +// X86TargetParser.def. +extern void a(const char *); + +// CHECK: @__cpu_model = external dso_local global { i32, i32, i32, [1 x i32] } + +#define TEST_CPU_IS(NAME, STR) \ + void test_##NAME(void) { \ + if (__builtin_cpu_is(STR)) \ + a(STR); \ + } + +// CHECK-LABEL: define{{.*}} void @test_intel( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr @__cpu_model +// CHECK: = icmp eq i32 [[LOAD]], 1 +TEST_CPU_IS(intel, "intel") + +// CHECK-LABEL: define{{.*}} void @test_amd( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr @__cpu_model +// CHECK: = icmp eq i32 [[LOAD]], 2 +TEST_CPU_IS(amd, "amd") + +// CHECK-LABEL: define{{.*}} void @test_other( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr @__cpu_model +// CHECK: = icmp eq i32 [[LOAD]], 5 +TEST_CPU_IS(other, "other") diff --git a/clang/test/CodeGen/builtin-cpu-is.c b/clang/test/CodeGen/builtin-cpu-is.c deleted file mode 100644 index a1d32e2b4bac2..0000000000000 --- a/clang/test/CodeGen/builtin-cpu-is.c +++ /dev/null @@ -1,55 +0,0 @@ -// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm < %s| FileCheck %s - -// Test that we have the structure definition, the gep offsets, the name of the -// global, the bit grab, and the icmp correct. -extern void a(const char *); - -// CHECK: @__cpu_model = external dso_local global { i32, i32, i32, [1 x i32] } - -void intel(void) { - if (__builtin_cpu_is("intel")) - a("intel"); - - // CHECK: [[LOAD:%[^ ]+]] = load i32, ptr @__cpu_model - // CHECK: = icmp eq i32 [[LOAD]], 1 -} - -void amd(void) { - if (__builtin_cpu_is("amd")) - a("amd"); - - // CHECK: [[LOAD:%[^ ]+]] = load i32, ptr @__cpu_model - // CHECK: = icmp eq i32 [[LOAD]], 2 -} - -void atom(void) { - if (__builtin_cpu_is("atom")) - a("atom"); - - // CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 4) - // CHECK: = icmp eq i32 [[LOAD]], 1 -} - -void amdfam10h(void) { - if (__builtin_cpu_is("amdfam10h")) - a("amdfam10h"); - - // CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 4) - // CHECK: = icmp eq i32 [[LOAD]], 4 -} - -void barcelona(void) { - if (__builtin_cpu_is("barcelona")) - a("barcelona"); - - // CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) - // CHECK: = icmp eq i32 [[LOAD]], 4 -} - -void nehalem(void) { - if (__builtin_cpu_is("nehalem")) - a("nehalem"); - - // CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 8) - // CHECK: = icmp eq i32 [[LOAD]], 1 -} diff --git a/clang/test/CodeGen/builtin-cpu-supports-all.c b/clang/test/CodeGen/builtin-cpu-supports-all.c new file mode 100644 index 0000000000000..c1274ccda827e --- /dev/null +++ b/clang/test/CodeGen/builtin-cpu-supports-all.c @@ -0,0 +1,538 @@ +// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm < %s | FileCheck %s + +// Test that __builtin_cpu_supports emits the correct field and bit for every +// feature listed in llvm/include/llvm/TargetParser/X86TargetParser.def. +extern void a(const char *); + +// CHECK: @__cpu_model = external dso_local global { i32, i32, i32, [1 x i32] } + +#define TEST_CPU_SUPPORTS(NAME, STR) \ + void test_##NAME(void) { \ + if (__builtin_cpu_supports(STR)) \ + a(STR); \ + } + +// CHECK-LABEL: define{{.*}} void @test_cmov( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 12) +// CHECK: = and i32 [[LOAD]], 1 +TEST_CPU_SUPPORTS(cmov, "cmov") + +// CHECK-LABEL: define{{.*}} void @test_mmx( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 12) +// CHECK: = and i32 [[LOAD]], 2 +TEST_CPU_SUPPORTS(mmx, "mmx") + +// CHECK-LABEL: define{{.*}} void @test_popcnt( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 12) +// CHECK: = and i32 [[LOAD]], 4 +TEST_CPU_SUPPORTS(popcnt, "popcnt") + +// CHECK-LABEL: define{{.*}} void @test_sse( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 12) +// CHECK: = and i32 [[LOAD]], 8 +TEST_CPU_SUPPORTS(sse, "sse") + +// CHECK-LABEL: define{{.*}} void @test_sse2( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 12) +// CHECK: = and i32 [[LOAD]], 16 +TEST_CPU_SUPPORTS(sse2, "sse2") + +// CHECK-LABEL: define{{.*}} void @test_sse3( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 12) +// CHECK: = and i32 [[LOAD]], 32 +TEST_CPU_SUPPORTS(sse3, "sse3") + +// CHECK-LABEL: define{{.*}} void @test_ssse3( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 12) +// CHECK: = and i32 [[LOAD]], 64 +TEST_CPU_SUPPORTS(ssse3, "ssse3") + +// CHECK-LABEL: define{{.*}} void @test_sse4_1( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 12) +// CHECK: = and i32 [[LOAD]], 128 +TEST_CPU_SUPPORTS(sse4_1, "sse4.1") + +// CHECK-LABEL: define{{.*}} void @test_sse4_2( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 12) +// CHECK: = and i32 [[LOAD]], 256 +TEST_CPU_SUPPORTS(sse4_2, "sse4.2") + +// CHECK-LABEL: define{{.*}} void @test_avx( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 12) +// CHECK: = and i32 [[LOAD]], 512 +TEST_CPU_SUPPORTS(avx, "avx") + +// CHECK-LABEL: define{{.*}} void @test_avx2( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 12) +// CHECK: = and i32 [[LOAD]], 1024 +TEST_CPU_SUPPORTS(avx2, "avx2") + +// CHECK-LABEL: define{{.*}} void @test_sse4a( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 12) +// CHECK: = and i32 [[LOAD]], 2048 +TEST_CPU_SUPPORTS(sse4a, "sse4a") + +// CHECK-LABEL: define{{.*}} void @test_fma4( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 12) +// CHECK: = and i32 [[LOAD]], 4096 +TEST_CPU_SUPPORTS(fma4, "fma4") + +// CHECK-LABEL: define{{.*}} void @test_xop( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 12) +// CHECK: = and i32 [[LOAD]], 8192 +TEST_CPU_SUPPORTS(xop, "xop") + +// CHECK-LABEL: define{{.*}} void @test_fma( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 12) +// CHECK: = and i32 [[LOAD]], 16384 +TEST_CPU_SUPPORTS(fma, "fma") + +// CHECK-LABEL: define{{.*}} void @test_avx512f( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 12) +// CHECK: = and i32 [[LOAD]], 32768 +TEST_CPU_SUPPORTS(avx512f, "avx512f") + +// CHECK-LABEL: define{{.*}} void @test_bmi( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 12) +// CHECK: = and i32 [[LOAD]], 65536 +TEST_CPU_SUPPORTS(bmi, "bmi") + +// CHECK-LABEL: define{{.*}} void @test_bmi2( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 12) +// CHECK: = and i32 [[LOAD]], 131072 +TEST_CPU_SUPPORTS(bmi2, "bmi2") + +// CHECK-LABEL: define{{.*}} void @test_aes( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 12) +// CHECK: = and i32 [[LOAD]], 262144 +TEST_CPU_SUPPORTS(aes, "aes") + +// CHECK-LABEL: define{{.*}} void @test_pclmul( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 12) +// CHECK: = and i32 [[LOAD]], 524288 +TEST_CPU_SUPPORTS(pclmul, "pclmul") + +// CHECK-LABEL: define{{.*}} void @test_avx512vl( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 12) +// CHECK: = and i32 [[LOAD]], 1048576 +TEST_CPU_SUPPORTS(avx512vl, "avx512vl") + +// CHECK-LABEL: define{{.*}} void @test_avx512bw( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 12) +// CHECK: = and i32 [[LOAD]], 2097152 +TEST_CPU_SUPPORTS(avx512bw, "avx512bw") + +// CHECK-LABEL: define{{.*}} void @test_avx512dq( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 12) +// CHECK: = and i32 [[LOAD]], 4194304 +TEST_CPU_SUPPORTS(avx512dq, "avx512dq") + +// CHECK-LABEL: define{{.*}} void @test_avx512cd( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 12) +// CHECK: = and i32 [[LOAD]], 8388608 +TEST_CPU_SUPPORTS(avx512cd, "avx512cd") + +// CHECK-LABEL: define{{.*}} void @test_avx512vbmi( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 12) +// CHECK: = and i32 [[LOAD]], 67108864 +TEST_CPU_SUPPORTS(avx512vbmi, "avx512vbmi") + +// CHECK-LABEL: define{{.*}} void @test_avx512ifma( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 12) +// CHECK: = and i32 [[LOAD]], 134217728 +TEST_CPU_SUPPORTS(avx512ifma, "avx512ifma") + +// CHECK-LABEL: define{{.*}} void @test_avx512vpopcntdq( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 12) +// CHECK: = and i32 [[LOAD]], 1073741824 +TEST_CPU_SUPPORTS(avx512vpopcntdq, "avx512vpopcntdq") + +// CHECK-LABEL: define{{.*}} void @test_avx512vbmi2( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_model, i64 12) +// CHECK: = and i32 [[LOAD]], -2147483648 +TEST_CPU_SUPPORTS(avx512vbmi2, "avx512vbmi2") + +// CHECK-LABEL: define{{.*}} void @test_gfni( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr @__cpu_features2 +// CHECK: = and i32 [[LOAD]], 1 +TEST_CPU_SUPPORTS(gfni, "gfni") + +// CHECK-LABEL: define{{.*}} void @test_vpclmulqdq( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr @__cpu_features2 +// CHECK: = and i32 [[LOAD]], 2 +TEST_CPU_SUPPORTS(vpclmulqdq, "vpclmulqdq") + +// CHECK-LABEL: define{{.*}} void @test_avx512vnni( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr @__cpu_features2 +// CHECK: = and i32 [[LOAD]], 4 +TEST_CPU_SUPPORTS(avx512vnni, "avx512vnni") + +// CHECK-LABEL: define{{.*}} void @test_avx512bitalg( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr @__cpu_features2 +// CHECK: = and i32 [[LOAD]], 8 +TEST_CPU_SUPPORTS(avx512bitalg, "avx512bitalg") + +// CHECK-LABEL: define{{.*}} void @test_avx512bf16( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr @__cpu_features2 +// CHECK: = and i32 [[LOAD]], 16 +TEST_CPU_SUPPORTS(avx512bf16, "avx512bf16") + +// CHECK-LABEL: define{{.*}} void @test_avx512vp2intersect( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr @__cpu_features2 +// CHECK: = and i32 [[LOAD]], 32 +TEST_CPU_SUPPORTS(avx512vp2intersect, "avx512vp2intersect") + +// CHECK-LABEL: define{{.*}} void @test_adx( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr @__cpu_features2 +// CHECK: = and i32 [[LOAD]], 256 +TEST_CPU_SUPPORTS(adx, "adx") + +// CHECK-LABEL: define{{.*}} void @test_cldemote( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr @__cpu_features2 +// CHECK: = and i32 [[LOAD]], 1024 +TEST_CPU_SUPPORTS(cldemote, "cldemote") + +// CHECK-LABEL: define{{.*}} void @test_clflushopt( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr @__cpu_features2 +// CHECK: = and i32 [[LOAD]], 2048 +TEST_CPU_SUPPORTS(clflushopt, "clflushopt") + +// CHECK-LABEL: define{{.*}} void @test_clwb( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr @__cpu_features2 +// CHECK: = and i32 [[LOAD]], 4096 +TEST_CPU_SUPPORTS(clwb, "clwb") + +// CHECK-LABEL: define{{.*}} void @test_clzero( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr @__cpu_features2 +// CHECK: = and i32 [[LOAD]], 8192 +TEST_CPU_SUPPORTS(clzero, "clzero") + +// CHECK-LABEL: define{{.*}} void @test_cx16( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr @__cpu_features2 +// CHECK: = and i32 [[LOAD]], 16384 +TEST_CPU_SUPPORTS(cx16, "cx16") + +// CHECK-LABEL: define{{.*}} void @test_enqcmd( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr @__cpu_features2 +// CHECK: = and i32 [[LOAD]], 65536 +TEST_CPU_SUPPORTS(enqcmd, "enqcmd") + +// CHECK-LABEL: define{{.*}} void @test_f16c( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr @__cpu_features2 +// CHECK: = and i32 [[LOAD]], 131072 +TEST_CPU_SUPPORTS(f16c, "f16c") + +// CHECK-LABEL: define{{.*}} void @test_fsgsbase( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr @__cpu_features2 +// CHECK: = and i32 [[LOAD]], 262144 +TEST_CPU_SUPPORTS(fsgsbase, "fsgsbase") + +// CHECK-LABEL: define{{.*}} void @test_sahf( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr @__cpu_features2 +// CHECK: = and i32 [[LOAD]], 4194304 +TEST_CPU_SUPPORTS(sahf, "sahf") + +// CHECK-LABEL: define{{.*}} void @test_64bit( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr @__cpu_features2 +// CHECK: = and i32 [[LOAD]], 8388608 +TEST_CPU_SUPPORTS(64bit, "64bit") + +// CHECK-LABEL: define{{.*}} void @test_lwp( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr @__cpu_features2 +// CHECK: = and i32 [[LOAD]], 16777216 +TEST_CPU_SUPPORTS(lwp, "lwp") + +// CHECK-LABEL: define{{.*}} void @test_lzcnt( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr @__cpu_features2 +// CHECK: = and i32 [[LOAD]], 33554432 +TEST_CPU_SUPPORTS(lzcnt, "lzcnt") + +// CHECK-LABEL: define{{.*}} void @test_movbe( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr @__cpu_features2 +// CHECK: = and i32 [[LOAD]], 67108864 +TEST_CPU_SUPPORTS(movbe, "movbe") + +// CHECK-LABEL: define{{.*}} void @test_movdir64b( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr @__cpu_features2 +// CHECK: = and i32 [[LOAD]], 134217728 +TEST_CPU_SUPPORTS(movdir64b, "movdir64b") + +// CHECK-LABEL: define{{.*}} void @test_movdiri( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr @__cpu_features2 +// CHECK: = and i32 [[LOAD]], 268435456 +TEST_CPU_SUPPORTS(movdiri, "movdiri") + +// CHECK-LABEL: define{{.*}} void @test_mwaitx( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr @__cpu_features2 +// CHECK: = and i32 [[LOAD]], 536870912 +TEST_CPU_SUPPORTS(mwaitx, "mwaitx") + +// CHECK-LABEL: define{{.*}} void @test_pconfig( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr @__cpu_features2 +// CHECK: = and i32 [[LOAD]], -2147483648 +TEST_CPU_SUPPORTS(pconfig, "pconfig") + +// CHECK-LABEL: define{{.*}} void @test_pku( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 4) +// CHECK: = and i32 [[LOAD]], 1 +TEST_CPU_SUPPORTS(pku, "pku") + +// CHECK-LABEL: define{{.*}} void @test_prfchw( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 4) +// CHECK: = and i32 [[LOAD]], 4 +TEST_CPU_SUPPORTS(prfchw, "prfchw") + +// CHECK-LABEL: define{{.*}} void @test_ptwrite( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 4) +// CHECK: = and i32 [[LOAD]], 8 +TEST_CPU_SUPPORTS(ptwrite, "ptwrite") + +// CHECK-LABEL: define{{.*}} void @test_rdpid( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 4) +// CHECK: = and i32 [[LOAD]], 16 +TEST_CPU_SUPPORTS(rdpid, "rdpid") + +// CHECK-LABEL: define{{.*}} void @test_rdrnd( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 4) +// CHECK: = and i32 [[LOAD]], 32 +TEST_CPU_SUPPORTS(rdrnd, "rdrnd") + +// CHECK-LABEL: define{{.*}} void @test_rdseed( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 4) +// CHECK: = and i32 [[LOAD]], 64 +TEST_CPU_SUPPORTS(rdseed, "rdseed") + +// CHECK-LABEL: define{{.*}} void @test_rtm( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 4) +// CHECK: = and i32 [[LOAD]], 128 +TEST_CPU_SUPPORTS(rtm, "rtm") + +// CHECK-LABEL: define{{.*}} void @test_serialize( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 4) +// CHECK: = and i32 [[LOAD]], 256 +TEST_CPU_SUPPORTS(serialize, "serialize") + +// CHECK-LABEL: define{{.*}} void @test_sgx( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 4) +// CHECK: = and i32 [[LOAD]], 512 +TEST_CPU_SUPPORTS(sgx, "sgx") + +// CHECK-LABEL: define{{.*}} void @test_sha( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 4) +// CHECK: = and i32 [[LOAD]], 1024 +TEST_CPU_SUPPORTS(sha, "sha") + +// CHECK-LABEL: define{{.*}} void @test_shstk( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 4) +// CHECK: = and i32 [[LOAD]], 2048 +TEST_CPU_SUPPORTS(shstk, "shstk") + +// CHECK-LABEL: define{{.*}} void @test_tbm( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 4) +// CHECK: = and i32 [[LOAD]], 4096 +TEST_CPU_SUPPORTS(tbm, "tbm") + +// CHECK-LABEL: define{{.*}} void @test_tsxldtrk( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 4) +// CHECK: = and i32 [[LOAD]], 8192 +TEST_CPU_SUPPORTS(tsxldtrk, "tsxldtrk") + +// CHECK-LABEL: define{{.*}} void @test_vaes( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 4) +// CHECK: = and i32 [[LOAD]], 16384 +TEST_CPU_SUPPORTS(vaes, "vaes") + +// CHECK-LABEL: define{{.*}} void @test_waitpkg( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 4) +// CHECK: = and i32 [[LOAD]], 32768 +TEST_CPU_SUPPORTS(waitpkg, "waitpkg") + +// CHECK-LABEL: define{{.*}} void @test_wbnoinvd( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 4) +// CHECK: = and i32 [[LOAD]], 65536 +TEST_CPU_SUPPORTS(wbnoinvd, "wbnoinvd") + +// CHECK-LABEL: define{{.*}} void @test_xsave( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 4) +// CHECK: = and i32 [[LOAD]], 131072 +TEST_CPU_SUPPORTS(xsave, "xsave") + +// CHECK-LABEL: define{{.*}} void @test_xsavec( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 4) +// CHECK: = and i32 [[LOAD]], 262144 +TEST_CPU_SUPPORTS(xsavec, "xsavec") + +// CHECK-LABEL: define{{.*}} void @test_xsaveopt( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 4) +// CHECK: = and i32 [[LOAD]], 524288 +TEST_CPU_SUPPORTS(xsaveopt, "xsaveopt") + +// CHECK-LABEL: define{{.*}} void @test_xsaves( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 4) +// CHECK: = and i32 [[LOAD]], 1048576 +TEST_CPU_SUPPORTS(xsaves, "xsaves") + +// CHECK-LABEL: define{{.*}} void @test_amx_tile( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 4) +// CHECK: = and i32 [[LOAD]], 2097152 +TEST_CPU_SUPPORTS(amx_tile, "amx-tile") + +// CHECK-LABEL: define{{.*}} void @test_amx_int8( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 4) +// CHECK: = and i32 [[LOAD]], 4194304 +TEST_CPU_SUPPORTS(amx_int8, "amx-int8") + +// CHECK-LABEL: define{{.*}} void @test_amx_bf16( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 4) +// CHECK: = and i32 [[LOAD]], 8388608 +TEST_CPU_SUPPORTS(amx_bf16, "amx-bf16") + +// CHECK-LABEL: define{{.*}} void @test_uintr( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 4) +// CHECK: = and i32 [[LOAD]], 16777216 +TEST_CPU_SUPPORTS(uintr, "uintr") + +// CHECK-LABEL: define{{.*}} void @test_hreset( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 4) +// CHECK: = and i32 [[LOAD]], 33554432 +TEST_CPU_SUPPORTS(hreset, "hreset") + +// CHECK-LABEL: define{{.*}} void @test_kl( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 4) +// CHECK: = and i32 [[LOAD]], 67108864 +TEST_CPU_SUPPORTS(kl, "kl") + +// CHECK-LABEL: define{{.*}} void @test_widekl( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 4) +// CHECK: = and i32 [[LOAD]], 268435456 +TEST_CPU_SUPPORTS(widekl, "widekl") + +// CHECK-LABEL: define{{.*}} void @test_avxvnni( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 4) +// CHECK: = and i32 [[LOAD]], 536870912 +TEST_CPU_SUPPORTS(avxvnni, "avxvnni") + +// CHECK-LABEL: define{{.*}} void @test_avx512fp16( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 4) +// CHECK: = and i32 [[LOAD]], 1073741824 +TEST_CPU_SUPPORTS(avx512fp16, "avx512fp16") + +// CHECK-LABEL: define{{.*}} void @test_x86_64( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 4) +// CHECK: = and i32 [[LOAD]], -2147483648 +TEST_CPU_SUPPORTS(x86_64, "x86-64") + +// CHECK-LABEL: define{{.*}} void @test_x86_64_v2( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 8) +// CHECK: = and i32 [[LOAD]], 1 +TEST_CPU_SUPPORTS(x86_64_v2, "x86-64-v2") + +// CHECK-LABEL: define{{.*}} void @test_x86_64_v3( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 8) +// CHECK: = and i32 [[LOAD]], 2 +TEST_CPU_SUPPORTS(x86_64_v3, "x86-64-v3") + +// CHECK-LABEL: define{{.*}} void @test_x86_64_v4( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 8) +// CHECK: = and i32 [[LOAD]], 4 +TEST_CPU_SUPPORTS(x86_64_v4, "x86-64-v4") + +// CHECK-LABEL: define{{.*}} void @test_avxifma( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 8) +// CHECK: = and i32 [[LOAD]], 8 +TEST_CPU_SUPPORTS(avxifma, "avxifma") + +// CHECK-LABEL: define{{.*}} void @test_avxvnniint8( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 8) +// CHECK: = and i32 [[LOAD]], 16 +TEST_CPU_SUPPORTS(avxvnniint8, "avxvnniint8") + +// CHECK-LABEL: define{{.*}} void @test_avxneconvert( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 8) +// CHECK: = and i32 [[LOAD]], 32 +TEST_CPU_SUPPORTS(avxneconvert, "avxneconvert") + +// CHECK-LABEL: define{{.*}} void @test_cmpccxadd( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 8) +// CHECK: = and i32 [[LOAD]], 64 +TEST_CPU_SUPPORTS(cmpccxadd, "cmpccxadd") + +// CHECK-LABEL: define{{.*}} void @test_amx_fp16( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 8) +// CHECK: = and i32 [[LOAD]], 128 +TEST_CPU_SUPPORTS(amx_fp16, "amx-fp16") + +// CHECK-LABEL: define{{.*}} void @test_prefetchi( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 8) +// CHECK: = and i32 [[LOAD]], 256 +TEST_CPU_SUPPORTS(prefetchi, "prefetchi") + +// CHECK-LABEL: define{{.*}} void @test_raoint( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 8) +// CHECK: = and i32 [[LOAD]], 512 +TEST_CPU_SUPPORTS(raoint, "raoint") + +// CHECK-LABEL: define{{.*}} void @test_amx_complex( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 8) +// CHECK: = and i32 [[LOAD]], 1024 +TEST_CPU_SUPPORTS(amx_complex, "amx-complex") + +// CHECK-LABEL: define{{.*}} void @test_avxvnniint16( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 8) +// CHECK: = and i32 [[LOAD]], 2048 +TEST_CPU_SUPPORTS(avxvnniint16, "avxvnniint16") + +// CHECK-LABEL: define{{.*}} void @test_sm3( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 8) +// CHECK: = and i32 [[LOAD]], 4096 +TEST_CPU_SUPPORTS(sm3, "sm3") + +// CHECK-LABEL: define{{.*}} void @test_sha512( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 8) +// CHECK: = and i32 [[LOAD]], 8192 +TEST_CPU_SUPPORTS(sha512, "sha512") + +// CHECK-LABEL: define{{.*}} void @test_sm4( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 8) +// CHECK: = and i32 [[LOAD]], 16384 +TEST_CPU_SUPPORTS(sm4, "sm4") + +// CHECK-LABEL: define{{.*}} void @test_apxf( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 8) +// CHECK: = and i32 [[LOAD]], 32768 +TEST_CPU_SUPPORTS(apxf, "apxf") + +// CHECK-LABEL: define{{.*}} void @test_usermsr( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 8) +// CHECK: = and i32 [[LOAD]], 65536 +TEST_CPU_SUPPORTS(usermsr, "usermsr") + +// CHECK-LABEL: define{{.*}} void @test_avx10_1( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 8) +// CHECK: = and i32 [[LOAD]], 262144 +TEST_CPU_SUPPORTS(avx10_1, "avx10.1") + +// CHECK-LABEL: define{{.*}} void @test_avx10_2( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 8) +// CHECK: = and i32 [[LOAD]], 1048576 +TEST_CPU_SUPPORTS(avx10_2, "avx10.2") + +// CHECK-LABEL: define{{.*}} void @test_amx_avx512( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 8) +// CHECK: = and i32 [[LOAD]], 2097152 +TEST_CPU_SUPPORTS(amx_avx512, "amx-avx512") + +// CHECK-LABEL: define{{.*}} void @test_amx_fp8( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 8) +// CHECK: = and i32 [[LOAD]], 16777216 +TEST_CPU_SUPPORTS(amx_fp8, "amx-fp8") + +// CHECK-LABEL: define{{.*}} void @test_movrs( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 8) +// CHECK: = and i32 [[LOAD]], 33554432 +TEST_CPU_SUPPORTS(movrs, "movrs") + +// CHECK-LABEL: define{{.*}} void @test_amx_movrs( +// CHECK: [[LOAD:%[^ ]+]] = load i32, ptr getelementptr inbounds nuw (i8, ptr @__cpu_features2, i64 8) +// CHECK: = and i32 [[LOAD]], 67108864 +TEST_CPU_SUPPORTS(amx_movrs, "amx-movrs") diff --git a/compiler-rt/lib/builtins/cpu_model/x86.c b/compiler-rt/lib/builtins/cpu_model/x86.c index 8320cc9f0d074..ae1abf70396da 100644 --- a/compiler-rt/lib/builtins/cpu_model/x86.c +++ b/compiler-rt/lib/builtins/cpu_model/x86.c @@ -42,7 +42,8 @@ enum VendorSignatures { enum ProcessorVendors { VENDOR_INTEL = 1, VENDOR_AMD, - VENDOR_HYGON, + // VENDOR_ZHAOXIN + VENDOR_HYGON = 4, VENDOR_OTHER, VENDOR_MAX }; @@ -107,10 +108,12 @@ enum ProcessorSubtypes { INTEL_COREI7_ARROWLAKE, INTEL_COREI7_ARROWLAKE_S, INTEL_COREI7_PANTHERLAKE, - AMDFAM1AH_ZNVER5, - AMDFAM1AH_ZNVER6, - INTEL_COREI7_DIAMONDRAPIDS, + // ZHAOXIN_FAM7H_YONGFENG + AMDFAM1AH_ZNVER5 = 36, + // ZHAOXIN_FAM7H_SHIJIDADAO + INTEL_COREI7_DIAMONDRAPIDS = 38, INTEL_COREI7_NOVALAKE, + AMDFAM1AH_ZNVER6, HYGONFAM18H_C86_4G_M4, HYGONFAM18H_C86_4G_M6, HYGONFAM18H_C86_4G_M7, diff --git a/llvm/include/llvm/TargetParser/X86TargetParser.def b/llvm/include/llvm/TargetParser/X86TargetParser.def index 355eb940d5cf3..0185bfa76db66 100644 --- a/llvm/include/llvm/TargetParser/X86TargetParser.def +++ b/llvm/include/llvm/TargetParser/X86TargetParser.def @@ -12,127 +12,118 @@ // NOTE: NO INCLUDE GUARD DESIRED! +// ABI_VALUE is used throughout the file by compiler frontend to match values +// in compiler-rt/libgcc. + #ifndef X86_VENDOR -#define X86_VENDOR(ENUM, STR) +#define X86_VENDOR(ENUM, STR, ABI_VALUE) #endif -X86_VENDOR(VENDOR_INTEL, "intel") -X86_VENDOR(VENDOR_AMD, "amd") +X86_VENDOR(VENDOR_INTEL, "intel", 1) +X86_VENDOR(VENDOR_AMD, "amd", 2) +X86_VENDOR(VENDOR_OTHER, "other", 5) #undef X86_VENDOR -// This macro is used for cpu types present in compiler-rt/libgcc. #ifndef X86_CPU_TYPE -#define X86_CPU_TYPE(ENUM, STR) -#endif - -#ifndef X86_CPU_TYPE_ALIAS -#define X86_CPU_TYPE_ALIAS(ENUM, STR) +#define X86_CPU_TYPE(ENUM, STR, ABI_VALUE) #endif // This list must match what is implemented in libgcc and compilert-rt. Clang // uses this to know how to implement __builtin_cpu_is. -X86_CPU_TYPE(INTEL_BONNELL, "bonnell") -X86_CPU_TYPE(INTEL_CORE2, "core2") -X86_CPU_TYPE(INTEL_COREI7, "corei7") -X86_CPU_TYPE(AMDFAM10H, "amdfam10h") -X86_CPU_TYPE(AMDFAM15H, "amdfam15h") -X86_CPU_TYPE(INTEL_SILVERMONT, "silvermont") -X86_CPU_TYPE(INTEL_KNL, "knl") -X86_CPU_TYPE(AMD_BTVER1, "btver1") -X86_CPU_TYPE(AMD_BTVER2, "btver2") -X86_CPU_TYPE(AMDFAM17H, "amdfam17h") -X86_CPU_TYPE(INTEL_KNM, "knm") -X86_CPU_TYPE(INTEL_GOLDMONT, "goldmont") -X86_CPU_TYPE(INTEL_GOLDMONT_PLUS, "goldmont-plus") -X86_CPU_TYPE(INTEL_TREMONT, "tremont") -X86_CPU_TYPE(AMDFAM19H, "amdfam19h") -X86_CPU_TYPE(ZHAOXIN_FAM7H, "zhaoxin_fam7h") -X86_CPU_TYPE(INTEL_SIERRAFOREST, "sierraforest") -X86_CPU_TYPE(INTEL_GRANDRIDGE, "grandridge") -X86_CPU_TYPE(INTEL_CLEARWATERFOREST, "clearwaterforest") -X86_CPU_TYPE(AMDFAM1AH, "amdfam1ah") -X86_CPU_TYPE(HYGONFAM18H, "hygonfam18h") +X86_CPU_TYPE(INTEL_BONNELL, "bonnell", 1) +X86_CPU_TYPE(INTEL_CORE2, "core2", 2) +X86_CPU_TYPE(INTEL_COREI7, "corei7", 3) +X86_CPU_TYPE(AMDFAM10H, "amdfam10h", 4) +X86_CPU_TYPE(AMDFAM15H, "amdfam15h", 5) +X86_CPU_TYPE(INTEL_SILVERMONT, "silvermont", 6) +X86_CPU_TYPE(INTEL_KNL, "knl", 7) +X86_CPU_TYPE(AMD_BTVER1, "btver1", 8) +X86_CPU_TYPE(AMD_BTVER2, "btver2", 9) +X86_CPU_TYPE(AMDFAM17H, "amdfam17h", 10) +X86_CPU_TYPE(INTEL_KNM, "knm", 11) +X86_CPU_TYPE(INTEL_GOLDMONT, "goldmont", 12) +X86_CPU_TYPE(INTEL_GOLDMONT_PLUS, "goldmont-plus", 13) +X86_CPU_TYPE(INTEL_TREMONT, "tremont", 14) +X86_CPU_TYPE(AMDFAM19H, "amdfam19h", 15) +X86_CPU_TYPE(ZHAOXIN_FAM7H, "zhaoxin_fam7h", 16) +X86_CPU_TYPE(INTEL_SIERRAFOREST, "sierraforest", 17) +X86_CPU_TYPE(INTEL_GRANDRIDGE, "grandridge", 18) +X86_CPU_TYPE(INTEL_CLEARWATERFOREST, "clearwaterforest", 19) +X86_CPU_TYPE(AMDFAM1AH, "amdfam1ah", 20) +X86_CPU_TYPE(HYGONFAM18H, "hygonfam18h", 21) -// Alternate names supported by __builtin_cpu_is and target multiversioning. -X86_CPU_TYPE_ALIAS(INTEL_BONNELL, "atom") -X86_CPU_TYPE_ALIAS(AMDFAM10H, "amdfam10") -X86_CPU_TYPE_ALIAS(AMDFAM15H, "amdfam15") -X86_CPU_TYPE_ALIAS(AMDFAM1AH, "amdfam1a") -X86_CPU_TYPE_ALIAS(INTEL_SILVERMONT, "slm") +// Aliases -- a diff erent name for the same cpu, represented as having the same +// ABI_VALUE. +X86_CPU_TYPE(ATOM, "atom", 1) +X86_CPU_TYPE(AMDFAM10, "amdfam10", 4) +X86_CPU_TYPE(AMDFAM15, "amdfam15", 5) +X86_CPU_TYPE(SLM, "slm", 6) +X86_CPU_TYPE(AMDFAM1A, "amdfam1a", 20) -#undef X86_CPU_TYPE_ALIAS #undef X86_CPU_TYPE // This macro is used for cpu subtypes present in compiler-rt/libgcc. #ifndef X86_CPU_SUBTYPE -#define X86_CPU_SUBTYPE(ENUM, STR) -#endif - -#ifndef X86_CPU_SUBTYPE_ALIAS -#define X86_CPU_SUBTYPE_ALIAS(ENUM, STR) +#define X86_CPU_SUBTYPE(ENUM, STR, ABI_VALUE) #endif // This list must match what is implemented in libgcc and compilert-rt. Clang // uses this to know how to implement __builtin_cpu_is. -X86_CPU_SUBTYPE(INTEL_COREI7_NEHALEM, "nehalem") -X86_CPU_SUBTYPE(INTEL_COREI7_WESTMERE, "westmere") -X86_CPU_SUBTYPE(INTEL_COREI7_SANDYBRIDGE, "sandybridge") -X86_CPU_SUBTYPE(AMDFAM10H_BARCELONA, "barcelona") -X86_CPU_SUBTYPE(AMDFAM10H_SHANGHAI, "shanghai") -X86_CPU_SUBTYPE(AMDFAM10H_ISTANBUL, "istanbul") -X86_CPU_SUBTYPE(AMDFAM15H_BDVER1, "bdver1") -X86_CPU_SUBTYPE(AMDFAM15H_BDVER2, "bdver2") -X86_CPU_SUBTYPE(AMDFAM15H_BDVER3, "bdver3") -X86_CPU_SUBTYPE(AMDFAM15H_BDVER4, "bdver4") -X86_CPU_SUBTYPE(AMDFAM17H_ZNVER1, "znver1") -X86_CPU_SUBTYPE(INTEL_COREI7_IVYBRIDGE, "ivybridge") -X86_CPU_SUBTYPE(INTEL_COREI7_HASWELL, "haswell") -X86_CPU_SUBTYPE(INTEL_COREI7_BROADWELL, "broadwell") -X86_CPU_SUBTYPE(INTEL_COREI7_SKYLAKE, "skylake") -X86_CPU_SUBTYPE(INTEL_COREI7_SKYLAKE_AVX512, "skylake-avx512") -X86_CPU_SUBTYPE(INTEL_COREI7_CANNONLAKE, "cannonlake") -X86_CPU_SUBTYPE(INTEL_COREI7_ICELAKE_CLIENT, "icelake-client") -X86_CPU_SUBTYPE(INTEL_COREI7_ICELAKE_SERVER, "icelake-server") -X86_CPU_SUBTYPE(AMDFAM17H_ZNVER2, "znver2") -X86_CPU_SUBTYPE(INTEL_COREI7_CASCADELAKE, "cascadelake") -X86_CPU_SUBTYPE(INTEL_COREI7_TIGERLAKE, "tigerlake") -X86_CPU_SUBTYPE(INTEL_COREI7_COOPERLAKE, "cooperlake") -X86_CPU_SUBTYPE(INTEL_COREI7_SAPPHIRERAPIDS, "sapphirerapids") -X86_CPU_SUBTYPE(INTEL_COREI7_ALDERLAKE, "alderlake") -X86_CPU_SUBTYPE(AMDFAM19H_ZNVER3, "znver3") -X86_CPU_SUBTYPE(INTEL_COREI7_ROCKETLAKE, "rocketlake") -X86_CPU_SUBTYPE(ZHAOXIN_FAM7H_LUJIAZUI, "zhaoxin_fam7h_lujiazui") -X86_CPU_SUBTYPE(AMDFAM19H_ZNVER4, "znver4") -X86_CPU_SUBTYPE(INTEL_COREI7_GRANITERAPIDS, "graniterapids") -X86_CPU_SUBTYPE(INTEL_COREI7_GRANITERAPIDS_D,"graniterapids-d") -X86_CPU_SUBTYPE(INTEL_COREI7_ARROWLAKE, "arrowlake") -X86_CPU_SUBTYPE(INTEL_COREI7_ARROWLAKE_S, "arrowlake-s") -X86_CPU_SUBTYPE(INTEL_COREI7_PANTHERLAKE, "pantherlake") -X86_CPU_SUBTYPE(AMDFAM1AH_ZNVER5, "znver5") -X86_CPU_SUBTYPE(AMDFAM1AH_ZNVER6, "znver6") -X86_CPU_SUBTYPE(INTEL_COREI7_DIAMONDRAPIDS, "diamondrapids") -X86_CPU_SUBTYPE(INTEL_COREI7_NOVALAKE, "novalake") -X86_CPU_SUBTYPE(HYGONFAM18H_C86_4G_M4, "c86-4g-m4") -X86_CPU_SUBTYPE(HYGONFAM18H_C86_4G_M6, "c86-4g-m6") -X86_CPU_SUBTYPE(HYGONFAM18H_C86_4G_M7, "c86-4g-m7") -X86_CPU_SUBTYPE(HYGONFAM18H_C86_4G_M8, "c86-4g-m8") +X86_CPU_SUBTYPE(INTEL_COREI7_NEHALEM, "nehalem", 1) +X86_CPU_SUBTYPE(INTEL_COREI7_WESTMERE, "westmere", 2) +X86_CPU_SUBTYPE(INTEL_COREI7_SANDYBRIDGE, "sandybridge", 3) +X86_CPU_SUBTYPE(AMDFAM10H_BARCELONA, "barcelona", 4) +X86_CPU_SUBTYPE(AMDFAM10H_SHANGHAI, "shanghai", 5) +X86_CPU_SUBTYPE(AMDFAM10H_ISTANBUL, "istanbul", 6) +X86_CPU_SUBTYPE(AMDFAM15H_BDVER1, "bdver1", 7) +X86_CPU_SUBTYPE(AMDFAM15H_BDVER2, "bdver2", 8) +X86_CPU_SUBTYPE(AMDFAM15H_BDVER3, "bdver3", 9) +X86_CPU_SUBTYPE(AMDFAM15H_BDVER4, "bdver4", 10) +X86_CPU_SUBTYPE(AMDFAM17H_ZNVER1, "znver1", 11) +X86_CPU_SUBTYPE(INTEL_COREI7_IVYBRIDGE, "ivybridge", 12) +X86_CPU_SUBTYPE(INTEL_COREI7_HASWELL, "haswell", 13) +X86_CPU_SUBTYPE(INTEL_COREI7_BROADWELL, "broadwell", 14) +X86_CPU_SUBTYPE(INTEL_COREI7_SKYLAKE, "skylake", 15) +X86_CPU_SUBTYPE(INTEL_COREI7_SKYLAKE_AVX512, "skylake-avx512", 16) +X86_CPU_SUBTYPE(INTEL_COREI7_CANNONLAKE, "cannonlake", 17) +X86_CPU_SUBTYPE(INTEL_COREI7_ICELAKE_CLIENT, "icelake-client", 18) +X86_CPU_SUBTYPE(INTEL_COREI7_ICELAKE_SERVER, "icelake-server", 19) +X86_CPU_SUBTYPE(AMDFAM17H_ZNVER2, "znver2", 20) +X86_CPU_SUBTYPE(INTEL_COREI7_CASCADELAKE, "cascadelake", 21) +X86_CPU_SUBTYPE(INTEL_COREI7_TIGERLAKE, "tigerlake", 22) +X86_CPU_SUBTYPE(INTEL_COREI7_COOPERLAKE, "cooperlake", 23) +X86_CPU_SUBTYPE(INTEL_COREI7_SAPPHIRERAPIDS, "sapphirerapids", 24) +X86_CPU_SUBTYPE(INTEL_COREI7_ALDERLAKE, "alderlake", 25) +X86_CPU_SUBTYPE(AMDFAM19H_ZNVER3, "znver3", 26) +X86_CPU_SUBTYPE(INTEL_COREI7_ROCKETLAKE, "rocketlake", 27) +X86_CPU_SUBTYPE(ZHAOXIN_FAM7H_LUJIAZUI, "zhaoxin_fam7h_lujiazui", 28) +X86_CPU_SUBTYPE(AMDFAM19H_ZNVER4, "znver4", 29) +X86_CPU_SUBTYPE(INTEL_COREI7_GRANITERAPIDS, "graniterapids", 30) +X86_CPU_SUBTYPE(INTEL_COREI7_GRANITERAPIDS_D,"graniterapids-d", 31) +X86_CPU_SUBTYPE(INTEL_COREI7_ARROWLAKE, "arrowlake", 32) +X86_CPU_SUBTYPE(INTEL_COREI7_ARROWLAKE_S, "arrowlake-s", 33) +X86_CPU_SUBTYPE(INTEL_COREI7_PANTHERLAKE, "pantherlake", 34) +X86_CPU_SUBTYPE(AMDFAM1AH_ZNVER5, "znver5", 36) +X86_CPU_SUBTYPE(INTEL_COREI7_DIAMONDRAPIDS, "diamondrapids", 38) +X86_CPU_SUBTYPE(INTEL_COREI7_NOVALAKE, "novalake", 39) +X86_CPU_SUBTYPE(AMDFAM1AH_ZNVER6, "znver6", 40) +X86_CPU_SUBTYPE(HYGONFAM18H_C86_4G_M4, "c86-4g-m4", 41) +X86_CPU_SUBTYPE(HYGONFAM18H_C86_4G_M6, "c86-4g-m6", 42) +X86_CPU_SUBTYPE(HYGONFAM18H_C86_4G_M7, "c86-4g-m7", 43) +X86_CPU_SUBTYPE(HYGONFAM18H_C86_4G_M8, "c86-4g-m8", 44) -// Alternate names supported by __builtin_cpu_is and target multiversioning. -X86_CPU_SUBTYPE_ALIAS(INTEL_COREI7_ALDERLAKE, "raptorlake") -X86_CPU_SUBTYPE_ALIAS(INTEL_COREI7_ALDERLAKE, "meteorlake") -X86_CPU_SUBTYPE_ALIAS(INTEL_COREI7_SAPPHIRERAPIDS, "emeraldrapids") -X86_CPU_SUBTYPE_ALIAS(INTEL_COREI7_ARROWLAKE_S,"lunarlake") -X86_CPU_SUBTYPE_ALIAS(INTEL_COREI7_ALDERLAKE, "gracemont") -X86_CPU_SUBTYPE_ALIAS(INTEL_COREI7_PANTHERLAKE, "wildcatlake") +// Aliases +X86_CPU_SUBTYPE(INTEL_COREI7_EMERALRAPIDS, "emeraldrapids", 24) +X86_CPU_SUBTYPE(INTEL_COREI7_RAPTORLAKE, "raptorlake", 25) +X86_CPU_SUBTYPE(INTEL_COREI7_METEORLAKE, "meteorlake", 25) +X86_CPU_SUBTYPE(INTEL_COREI7_GRACEMONT, "gracemont", 25) +X86_CPU_SUBTYPE(INTEL_COREI7_LUNARLAKE, "lunarlake", 33) +X86_CPU_SUBTYPE(INTEL_COREI7_WILDCATLAKE, "wildcatlake", 34) -#undef X86_CPU_SUBTYPE_ALIAS #undef X86_CPU_SUBTYPE // X86_FEATURE_COMPAT is used for cpu types present in compiler-rt/libgcc (i.e. // types we can multiversion on). The third parameter PRIORITY is required // by the attribute 'target' checking. - -// Order of bits has to match what's implemented in compiler-rt/libgcc. That's what the -// ABI_VALUE is for - CodeGenFunction::GetX86CpuSupportsMask uses it. #ifndef X86_FEATURE_COMPAT #define X86_FEATURE_COMPAT(ENUM, STR, PRIORITY, ABI_VALUE) X86_FEATURE(ENUM, STR) #endif @@ -282,7 +273,7 @@ X86_FEATURE (RETPOLINE_INDIRECT_CALLS, "retpoline-indirect-calls") X86_FEATURE (LVI_CFI, "lvi-cfi") X86_FEATURE (LVI_LOAD_HARDENING, "lvi-load-hardening") -// Max number of priorities. Priorities form a consecutive range +// Max number of priorities. Priorities form a consecutive range. #define MAX_PRIORITY 35 #undef X86_FEATURE_COMPAT diff --git a/llvm/include/llvm/TargetParser/X86TargetParser.h b/llvm/include/llvm/TargetParser/X86TargetParser.h index 351af41079d3e..4552287507fd3 100644 --- a/llvm/include/llvm/TargetParser/X86TargetParser.h +++ b/llvm/include/llvm/TargetParser/X86TargetParser.h @@ -24,38 +24,24 @@ class StringRef; namespace X86 { -// This should be kept in sync with libcc/compiler-rt as its included by clang -// as a proxy for what's in libgcc/compiler-rt. enum ProcessorVendors : unsigned { - VENDOR_DUMMY, -#define X86_VENDOR(ENUM, STRING) \ - ENUM, +#define X86_VENDOR(ENUM, STRING, ABI_VALUE) ENUM, #include "llvm/TargetParser/X86TargetParser.def" - VENDOR_OTHER + CPU_VENDOR_MAX }; -// This should be kept in sync with libcc/compiler-rt as its included by clang -// as a proxy for what's in libgcc/compiler-rt. enum ProcessorTypes : unsigned { - CPU_TYPE_DUMMY, -#define X86_CPU_TYPE(ENUM, STRING) \ - ENUM, +#define X86_CPU_TYPE(ENUM, STRING, ABI_VALUE) ENUM, #include "llvm/TargetParser/X86TargetParser.def" CPU_TYPE_MAX }; -// This should be kept in sync with libcc/compiler-rt as its included by clang -// as a proxy for what's in libgcc/compiler-rt. enum ProcessorSubtypes : unsigned { - CPU_SUBTYPE_DUMMY, -#define X86_CPU_SUBTYPE(ENUM, STRING) \ - ENUM, +#define X86_CPU_SUBTYPE(ENUM, STRING, ABI_VALUE) ENUM, #include "llvm/TargetParser/X86TargetParser.def" CPU_SUBTYPE_MAX }; -// This should be kept in sync with libcc/compiler-rt as it should be used -// by clang as a proxy for what's in libgcc/compiler-rt. enum ProcessorFeatures { #define X86_FEATURE(ENUM, STRING) FEATURE_##ENUM, #include "llvm/TargetParser/X86TargetParser.def" diff --git a/llvm/lib/TargetParser/X86TargetParser.cpp b/llvm/lib/TargetParser/X86TargetParser.cpp index 16a40f4473b43..ad1c0011bc2b5 100644 --- a/llvm/lib/TargetParser/X86TargetParser.cpp +++ b/llvm/lib/TargetParser/X86TargetParser.cpp @@ -793,6 +793,7 @@ llvm::X86::getCpuSupportsMask(ArrayRef<StringRef> FeatureStrs) { // Processor features and mapping to processor feature value. std::array<uint32_t, 4> FeatureMask{}; for (StringRef FeatureStr : FeatureStrs) { + // ABI_VALUE is used to match values in compiler-rt/libgcc unsigned Feature = StringSwitch<unsigned>(FeatureStr) #define X86_FEATURE_COMPAT(ENUM, STR, PRIORITY, ABI_VALUE) .Case(STR, ABI_VALUE) #define X86_MICROARCH_LEVEL(ENUM, STR, PRIORITY, ABI_VALUE) \ _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
