GBuella created this revision. GBuella added reviewers: craig.topper, zvi, ashlykov. Herald added subscribers: cfe-commits, mgorny.
Also, a new intrinsic for the wbinvd instruction. Repository: rC Clang https://reviews.llvm.org/D43817 Files: docs/ClangCommandLineReference.rst include/clang/Basic/BuiltinsX86.def include/clang/Driver/Options.td lib/Basic/Targets/X86.cpp lib/Basic/Targets/X86.h lib/Headers/CMakeLists.txt lib/Headers/cpuid.h lib/Headers/ia32intrin.h lib/Headers/wbnoinvdintrin.h lib/Headers/x86intrin.h test/CodeGen/builtin-wbnoinvd.c test/CodeGen/builtins-x86.c test/Driver/x86-target-features.c
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/CodeGen/builtins-x86.c =================================================================== --- test/CodeGen/builtins-x86.c +++ test/CodeGen/builtins-x86.c @@ -305,6 +305,7 @@ tmp_i = __rdtsc(); tmp_i = __builtin_ia32_rdtscp(&tmp_Ui); tmp_LLi = __builtin_ia32_rdpmc(tmp_i); + __builtin_ia32_wbinvd(); #ifdef USE_64 tmp_LLi = __builtin_ia32_cvtss2si64(tmp_V4f); tmp_LLi = __builtin_ia32_cvttss2si64(tmp_V4f); 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-apple-darwin -target-feature +wbnoinvd -emit-llvm -o - -Wall -Werror | FileCheck %s + +#include <x86intrin.h> + +void test_wbnoinvd(void) { + //CHECK-LABEL: @test_wbnoinvd + //CHECK: @llvm.x86.wbnoinvd + _wbnoinvd(); +} Index: lib/Headers/x86intrin.h =================================================================== --- lib/Headers/x86intrin.h +++ lib/Headers/x86intrin.h @@ -94,4 +94,9 @@ #include <clzerointrin.h> #endif +#if !defined(_MSC_VER) || __has_feature(modules) || defined(__WBNOINVD__) +#include <wbnoinvdintrin.h> +#endif + + #endif /* __X86INTRIN_H */ Index: lib/Headers/wbnoinvdintrin.h =================================================================== --- /dev/null +++ lib/Headers/wbnoinvdintrin.h @@ -0,0 +1,33 @@ +/*===---- 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 <wbnoinvdintrin.h> directly; include <x86intrin.h> instead." +#endif + +#ifndef __WBNOINVDINTRIN_H +#define __WBNOINVDINTRIN_H + +#define _wbnoinvd __builtin_ia32_wbnoinvd + +#endif /* __WBNOINVDINTRIN_H */ Index: lib/Headers/ia32intrin.h =================================================================== --- lib/Headers/ia32intrin.h +++ lib/Headers/ia32intrin.h @@ -76,4 +76,6 @@ #define _rdpmc(A) __rdpmc(A) +#define _wbinvd() __builtin_ia32_wbinvd() + #endif /* __IA32INTRIN_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/CMakeLists.txt =================================================================== --- lib/Headers/CMakeLists.txt +++ lib/Headers/CMakeLists.txt @@ -57,6 +57,7 @@ smmintrin.h tmmintrin.h vadefs.h + wbnoinvdintrin.h wmmintrin.h __wmmintrin_aes.h __wmmintrin_pclmul.h Index: lib/Basic/Targets/X86.h =================================================================== --- lib/Basic/Targets/X86.h +++ lib/Basic/Targets/X86.h @@ -90,6 +90,7 @@ bool HasCLWB = false; bool HasMOVBE = false; bool HasPREFETCHWT1 = false; + bool HasWBNOINVD = false; /// \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 @@ -133,6 +133,7 @@ case CK_Icelake: // TODO: Add icelake features here. + setFeatureEnabledImpl(Features, "wbnoinvd", true); LLVM_FALLTHROUGH; case CK_Cannonlake: setFeatureEnabledImpl(Features, "avx512ifma", true); @@ -716,6 +717,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") { @@ -1036,6 +1039,8 @@ Builder.defineMacro("__CLFLUSHOPT__"); if (HasCLWB) Builder.defineMacro("__CLWB__"); + if (HasWBNOINVD) + Builder.defineMacro("__WBNOINVD__"); if (HasMPX) Builder.defineMacro("__MPX__"); if (HasSHSTK) @@ -1185,6 +1190,7 @@ .Case("sse4.2", true) .Case("sse4a", true) .Case("tbm", true) + .Case("wbnoinvd", true) .Case("x87", true) .Case("xop", true) .Case("xsave", true) @@ -1249,6 +1255,7 @@ .Case("sse4.2", SSELevel >= SSE42) .Case("sse4a", XOPLevel >= SSE4A) .Case("tbm", HasTBM) + .Case("wbnoinvd", HasWBNOINVD) .Case("x86", true) .Case("x86_32", getTriple().getArch() == llvm::Triple::x86) .Case("x86_64", getTriple().getArch() == llvm::Triple::x86_64) Index: include/clang/Driver/Options.td =================================================================== --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -2537,6 +2537,8 @@ def mno_clflushopt : Flag<["-"], "mno-clflushopt">, Group<m_x86_Features_Group>; def mclwb : Flag<["-"], "mclwb">, Group<m_x86_Features_Group>; def mno_clwb : Flag<["-"], "mno-clwb">, Group<m_x86_Features_Group>; +def mwbnoinvd : Flag<["-"], "mwbnoinvd">, Group<m_x86_Features_Group>; +def mno_wbnoinvd : Flag<["-"], "mno-wbnoinvd">, Group<m_x86_Features_Group>; def mclzero : Flag<["-"], "mclzero">, Group<m_x86_Features_Group>; def mno_clzero : Flag<["-"], "mno-clzero">, Group<m_x86_Features_Group>; def mcx16 : Flag<["-"], "mcx16">, Group<m_x86_Features_Group>; Index: include/clang/Basic/BuiltinsX86.def =================================================================== --- include/clang/Basic/BuiltinsX86.def +++ include/clang/Basic/BuiltinsX86.def @@ -654,6 +654,10 @@ //CLWB TARGET_BUILTIN(__builtin_ia32_clwb, "vvC*", "", "clwb") +//WBNOINVD + wbinvd instruction +TARGET_BUILTIN(__builtin_ia32_wbinvd, "v", "", "") +TARGET_BUILTIN(__builtin_ia32_wbnoinvd, "v", "", "wbnoinvd") + // ADX TARGET_BUILTIN(__builtin_ia32_addcarryx_u32, "UcUcUiUiUi*", "", "adx") TARGET_BUILTIN(__builtin_ia32_addcarry_u32, "UcUcUiUiUi*", "", "") Index: docs/ClangCommandLineReference.rst =================================================================== --- docs/ClangCommandLineReference.rst +++ docs/ClangCommandLineReference.rst @@ -2356,6 +2356,8 @@ .. option:: -mclwb, -mno-clwb +.. option:: -mwbnoinvd, -mno-wbnoinvd + .. option:: -mclzero, -mno-clzero .. option:: -mcx16, -mno-cx16
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits