From: Gabor Buella Date: Wed, 11 Apr 2018 20:09:09 +0000 (+0000) Subject: [x86] wbnoinvd intrinsic X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=633f56e9211661ed022b16a2743521d6a081c8c1;p=clang [x86] wbnoinvd intrinsic The WBNOINVD instruction writes back all modified cache lines in the processor’s internal cache to main memory but does not invalidate (flush) the internal caches. Reviewers: craig.topper, zvi, ashlykov Reviewed By: craig.topper Differential Revision: https://reviews.llvm.org/D43817 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@329848 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/docs/ClangCommandLineReference.rst b/docs/ClangCommandLineReference.rst index 67eb56a4ce..6b86dd6ea9 100644 --- a/docs/ClangCommandLineReference.rst +++ b/docs/ClangCommandLineReference.rst @@ -2484,6 +2484,8 @@ X86 .. option:: -mvpclmulqdq, -mno-vpclmulqdq +.. option:: -mwbnoinvd, -mno-wbnoinvd + .. option:: -mx87, -m80387, -mno-x87 .. option:: -mxop, -mno-xop diff --git a/include/clang/Basic/BuiltinsX86.def b/include/clang/Basic/BuiltinsX86.def index 6d06d5c2d0..6fa7e68be7 100644 --- a/include/clang/Basic/BuiltinsX86.def +++ b/include/clang/Basic/BuiltinsX86.def @@ -679,6 +679,9 @@ TARGET_BUILTIN(__builtin_ia32_clflushopt, "vvC*", "", "clflushopt") //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*", "", "") diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index ab9335a45f..2bc5ee29d8 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -2598,6 +2598,8 @@ def mclflushopt : Flag<["-"], "mclflushopt">, Group; 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; diff --git a/lib/Basic/Targets/X86.cpp b/lib/Basic/Targets/X86.cpp index 34c406f3b0..387d1f88b5 100644 --- a/lib/Basic/Targets/X86.cpp +++ b/lib/Basic/Targets/X86.cpp @@ -154,6 +154,8 @@ bool X86TargetInfo::initFeatureMap( 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 @@ bool X86TargetInfo::handleTargetFeatures(std::vector &Features, 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 @@ void X86TargetInfo::getTargetDefines(const LangOptions &Opts, Builder.defineMacro("__CLFLUSHOPT__"); if (HasCLWB) Builder.defineMacro("__CLWB__"); + if (HasWBNOINVD) + Builder.defineMacro("__WBNOINVD__"); if (HasMPX) Builder.defineMacro("__MPX__"); if (HasSHSTK) @@ -1297,6 +1303,7 @@ bool X86TargetInfo::isValidFeatureName(StringRef Name) const { .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 @@ bool X86TargetInfo::hasFeature(StringRef Feature) const { .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) diff --git a/lib/Basic/Targets/X86.h b/lib/Basic/Targets/X86.h index 91db1dfdf3..381a75757e 100644 --- a/lib/Basic/Targets/X86.h +++ b/lib/Basic/Targets/X86.h @@ -100,6 +100,7 @@ class LLVM_LIBRARY_VISIBILITY X86TargetInfo : public TargetInfo { bool HasRetpoline = false; bool HasRetpolineExternalThunk = false; bool HasLAHFSAHF = false; + bool HasWBNOINVD = false; protected: /// \brief Enumeration of all of the X86 CPUs supported by Clang. diff --git a/lib/Headers/CMakeLists.txt b/lib/Headers/CMakeLists.txt index a6ea5b600f..98c004f4ea 100644 --- a/lib/Headers/CMakeLists.txt +++ b/lib/Headers/CMakeLists.txt @@ -95,6 +95,7 @@ set(files varargs.h vecintrin.h vpclmulqdqintrin.h + wbnoinvdintrin.h wmmintrin.h __wmmintrin_aes.h __wmmintrin_pclmul.h diff --git a/lib/Headers/cpuid.h b/lib/Headers/cpuid.h index a41c3113bb..832cfb2a50 100644 --- a/lib/Headers/cpuid.h +++ b/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__ diff --git a/lib/Headers/wbnoinvdintrin.h b/lib/Headers/wbnoinvdintrin.h new file mode 100644 index 0000000000..0852dc1729 --- /dev/null +++ b/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 */ diff --git a/lib/Headers/x86intrin.h b/lib/Headers/x86intrin.h index 31ee7b82dd..53151f7d3b 100644 --- a/lib/Headers/x86intrin.h +++ b/lib/Headers/x86intrin.h @@ -88,4 +88,8 @@ #include #endif +#if !defined(_MSC_VER) || __has_feature(modules) || defined(__WBNOINVD__) +#include +#endif + #endif /* __X86INTRIN_H */ diff --git a/test/CodeGen/builtin-wbnoinvd.c b/test/CodeGen/builtin-wbnoinvd.c new file mode 100644 index 0000000000..008a759883 --- /dev/null +++ b/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(); +} diff --git a/test/CodeGen/builtins-x86.c b/test/CodeGen/builtins-x86.c index fc3cc448cf..1f6ded20da 100644 --- a/test/CodeGen/builtins-x86.c +++ b/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 @@ void f0() { 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); diff --git a/test/Driver/x86-target-features.c b/test/Driver/x86-target-features.c index 530ba04e19..ccc2a6225c 100644 --- a/test/Driver/x86-target-features.c +++ b/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" diff --git a/test/Preprocessor/predefined-arch-macros.c b/test/Preprocessor/predefined-arch-macros.c index fe664ce3f6..9b6123172b 100644 --- a/test/Preprocessor/predefined-arch-macros.c +++ b/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