Index: docs/ClangCommandLineReference.rst =================================================================== --- docs/ClangCommandLineReference.rst +++ docs/ClangCommandLineReference.rst @@ -2484,6 +2484,8 @@ .. option:: -mvpclmulqdq, -mno-vpclmulqdq +.. option:: -mwbnoinvd, -mno-wbnoinvd + .. option:: -mx87, -m80387, -mno-x87 .. option:: -mxop, -mno-xop Index: include/clang/Basic/BuiltinsX86.def =================================================================== --- include/clang/Basic/BuiltinsX86.def +++ include/clang/Basic/BuiltinsX86.def @@ -679,6 +679,9 @@ //CLWB TARGET_BUILTIN(__builtin_ia32_clwb, "vvC*", "", "clwb") +//WBNOINVD +TARGET_BUILTIN(__builtin_ia32_wbnoinvd, "v", "", "wbnoinvd") + // ADX TARGET_BUILTIN(__builtin_ia32_addcarryx_u32, "UcUcUiUiUi*", "", "adx") TARGET_BUILTIN(__builtin_ia32_addcarry_u32, "UcUcUiUiUi*", "", "") Index: include/clang/Driver/Options.td =================================================================== --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -2593,6 +2593,8 @@ def mno_clflushopt : Flag<["-"], "mno-clflushopt">, Group; def mclwb : Flag<["-"], "mclwb">, Group; def mno_clwb : Flag<["-"], "mno-clwb">, Group; +def mwbnoinvd : Flag<["-"], "mwbnoinvd">, Group; +def mno_wbnoinvd : Flag<["-"], "mno-wbnoinvd">, Group; def mclzero : Flag<["-"], "mclzero">, Group; def mno_clzero : Flag<["-"], "mno-clzero">, Group; def mcx16 : Flag<["-"], "mcx16">, Group; Index: lib/Basic/Targets/X86.h =================================================================== --- lib/Basic/Targets/X86.h +++ lib/Basic/Targets/X86.h @@ -100,6 +100,7 @@ bool HasRetpoline = false; bool HasRetpolineExternalThunk = false; bool HasLAHFSAHF = false; + bool HasWBNOINVD = false; protected: /// \brief Enumeration of all of the X86 CPUs supported by Clang. Index: lib/Basic/Targets/X86.cpp =================================================================== --- lib/Basic/Targets/X86.cpp +++ lib/Basic/Targets/X86.cpp @@ -154,6 +154,8 @@ break; case CK_IcelakeServer: + setFeatureEnabledImpl(Features, "wbnoinvd", true); + LLVM_FALLTHROUGH; case CK_IcelakeClient: setFeatureEnabledImpl(Features, "vaes", true); setFeatureEnabledImpl(Features, "gfni", true); @@ -792,6 +794,8 @@ HasCLFLUSHOPT = true; } else if (Feature == "+clwb") { HasCLWB = true; + } else if (Feature == "+wbnoinvd") { + HasWBNOINVD = true; } else if (Feature == "+prefetchwt1") { HasPREFETCHWT1 = true; } else if (Feature == "+clzero") { @@ -1134,6 +1138,8 @@ Builder.defineMacro("__CLFLUSHOPT__"); if (HasCLWB) Builder.defineMacro("__CLWB__"); + if (HasWBNOINVD) + Builder.defineMacro("__WBNOINVD__"); if (HasMPX) Builder.defineMacro("__MPX__"); if (HasSHSTK) @@ -1297,6 +1303,7 @@ .Case("tbm", true) .Case("vaes", true) .Case("vpclmulqdq", true) + .Case("wbnoinvd", true) .Case("x87", true) .Case("xop", true) .Case("xsave", true) @@ -1371,6 +1378,7 @@ .Case("tbm", HasTBM) .Case("vaes", HasVAES) .Case("vpclmulqdq", HasVPCLMULQDQ) + .Case("wbnoinvd", HasWBNOINVD) .Case("x86", true) .Case("x86_32", getTriple().getArch() == llvm::Triple::x86) .Case("x86_64", getTriple().getArch() == llvm::Triple::x86_64) Index: lib/Headers/CMakeLists.txt =================================================================== --- lib/Headers/CMakeLists.txt +++ lib/Headers/CMakeLists.txt @@ -95,6 +95,7 @@ varargs.h vecintrin.h vpclmulqdqintrin.h + wbnoinvdintrin.h wmmintrin.h __wmmintrin_aes.h __wmmintrin_pclmul.h Index: lib/Headers/cpuid.h =================================================================== --- lib/Headers/cpuid.h +++ lib/Headers/cpuid.h @@ -215,8 +215,9 @@ #define bit_3DNOWP 0x40000000 #define bit_3DNOW 0x80000000 -/* Features in %ebx for leaf 0x80000001 */ +/* Features in %ebx for leaf 0x80000008 */ #define bit_CLZERO 0x00000001 +#define bit_WBNOINVD 0x00000200 #if __i386__ Index: lib/Headers/wbnoinvdintrin.h =================================================================== --- /dev/null +++ lib/Headers/wbnoinvdintrin.h @@ -0,0 +1,38 @@ +/*===-------------- wbnoinvdintrin.h - wbnoinvd intrinsic-------------------=== + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + *===-----------------------------------------------------------------------=== + */ + +#ifndef __X86INTRIN_H +#error "Never use directly; include instead." +#endif + +#ifndef __WBNOINVDINTRIN_H +#define __WBNOINVDINTRIN_H + +static __inline__ void + __attribute__((__always_inline__, __nodebug__, __target__("wbnoinvd"))) +_wbnoinvd (void) +{ + __builtin_ia32_wbnoinvd (); +} + +#endif /* __WBNOINVDINTRIN_H */ Index: lib/Headers/x86intrin.h =================================================================== --- lib/Headers/x86intrin.h +++ lib/Headers/x86intrin.h @@ -88,4 +88,8 @@ #include #endif +#if !defined(_MSC_VER) || __has_feature(modules) || defined(__WBNOINVD__) +#include +#endif + #endif /* __X86INTRIN_H */ Index: test/CodeGen/builtin-wbnoinvd.c =================================================================== --- /dev/null +++ test/CodeGen/builtin-wbnoinvd.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 %s -ffreestanding -triple=x86_64-unknown-unknown -target-feature +wbnoinvd -emit-llvm -o - -Wall -Werror | FileCheck %s + +#include + +void test_wbnoinvd(void) { + //CHECK-LABEL: @test_wbnoinvd + //CHECK: call void @llvm.x86.wbnoinvd() + _wbnoinvd(); +} Index: test/CodeGen/builtins-x86.c =================================================================== --- test/CodeGen/builtins-x86.c +++ test/CodeGen/builtins-x86.c @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -DUSE_64 -triple x86_64-unknown-unknown -target-feature +fxsr -target-feature +avx -target-feature +xsaveopt -target-feature +xsaves -target-feature +xsavec -target-feature +mwaitx -target-feature +clzero -target-feature +ibt -target-feature +shstk -emit-llvm -o %t %s -// RUN: %clang_cc1 -DUSE_ALL -triple x86_64-unknown-unknown -target-feature +fxsr -target-feature +avx -target-feature +xsaveopt -target-feature +xsaves -target-feature +xsavec -target-feature +mwaitx -target-feature +ibt -target-feature +shstk -target-feature +clzero -fsyntax-only -o %t %s +// RUN: %clang_cc1 -DUSE_64 -triple x86_64-unknown-unknown -target-feature +fxsr -target-feature +avx -target-feature +xsaveopt -target-feature +xsaves -target-feature +xsavec -target-feature +mwaitx -target-feature +clzero -target-feature +ibt -target-feature +shstk -target-feature +wbnoinvd -emit-llvm -o %t %s +// RUN: %clang_cc1 -DUSE_ALL -triple x86_64-unknown-unknown -target-feature +fxsr -target-feature +avx -target-feature +xsaveopt -target-feature +xsaves -target-feature +xsavec -target-feature +mwaitx -target-feature +ibt -target-feature +shstk -target-feature +clzero -target-feature +wbnoinvd -fsyntax-only -o %t %s #ifdef USE_ALL #define USE_3DNOW @@ -305,6 +305,7 @@ tmp_i = __rdtsc(); tmp_i = __builtin_ia32_rdtscp(&tmp_Ui); tmp_LLi = __builtin_ia32_rdpmc(tmp_i); + __builtin_ia32_wbnoinvd(); #ifdef USE_64 tmp_LLi = __builtin_ia32_cvtss2si64(tmp_V4f); tmp_LLi = __builtin_ia32_cvttss2si64(tmp_V4f); Index: test/Driver/x86-target-features.c =================================================================== --- test/Driver/x86-target-features.c +++ test/Driver/x86-target-features.c @@ -60,6 +60,11 @@ // CLWB: "-target-feature" "+clwb" // NO-CLWB: "-target-feature" "-clwb" +// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mwbnoinvd %s -### -o %t.o 2>&1 | FileCheck -check-prefix=WBNOINVD %s +// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mno-wbnoinvd %s -### -o %t.o 2>&1 | FileCheck -check-prefix=NO-WBNOINVD %s +// WBNOINVD: "-target-feature" "+wbnoinvd" +// NO-WBNOINVD: "-target-feature" "-wbnoinvd" + // RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mmovbe %s -### -o %t.o 2>&1 | FileCheck -check-prefix=MOVBE %s // RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mno-movbe %s -### -o %t.o 2>&1 | FileCheck -check-prefix=NO-MOVBE %s // MOVBE: "-target-feature" "+movbe" Index: test/Preprocessor/predefined-arch-macros.c =================================================================== --- test/Preprocessor/predefined-arch-macros.c +++ test/Preprocessor/predefined-arch-macros.c @@ -1100,6 +1100,7 @@ // CHECK_ICL_M32: #define __SSSE3__ 1 // CHECK_ICL_M32: #define __VAES__ 1 // CHECK_ICL_M32: #define __VPCLMULQDQ__ 1 +// CHECK_ICL_M32-NOT: #define __WBNOINVD__ 1 // CHECK_ICL_M32: #define __XSAVEC__ 1 // CHECK_ICL_M32: #define __XSAVEOPT__ 1 // CHECK_ICL_M32: #define __XSAVES__ 1 @@ -1156,6 +1157,7 @@ // CHECK_ICL_M64: #define __SSSE3__ 1 // CHECK_ICL_M64: #define __VAES__ 1 // CHECK_ICL_M64: #define __VPCLMULQDQ__ 1 +// CHECK_ICL_M64-NOT: #define __WBNOINVD__ 1 // CHECK_ICL_M64: #define __XSAVEC__ 1 // CHECK_ICL_M64: #define __XSAVEOPT__ 1 // CHECK_ICL_M64: #define __XSAVES__ 1 @@ -1213,6 +1215,7 @@ // CHECK_ICX_M32: #define __SSSE3__ 1 // CHECK_ICX_M32: #define __VAES__ 1 // CHECK_ICX_M32: #define __VPCLMULQDQ__ 1 +// CHECK_ICX_M32: #define __WBNOINVD__ 1 // CHECK_ICX_M32: #define __XSAVEC__ 1 // CHECK_ICX_M32: #define __XSAVEOPT__ 1 // CHECK_ICX_M32: #define __XSAVES__ 1 @@ -1269,6 +1272,7 @@ // CHECK_ICX_M64: #define __SSSE3__ 1 // CHECK_ICX_M64: #define __VAES__ 1 // CHECK_ICX_M64: #define __VPCLMULQDQ__ 1 +// CHECK_ICX_M64: #define __WBNOINVD__ 1 // CHECK_ICX_M64: #define __XSAVEC__ 1 // CHECK_ICX_M64: #define __XSAVEOPT__ 1 // CHECK_ICX_M64: #define __XSAVES__ 1