Index: cfe/trunk/include/clang/Basic/BuiltinsX86.def =================================================================== --- cfe/trunk/include/clang/Basic/BuiltinsX86.def +++ cfe/trunk/include/clang/Basic/BuiltinsX86.def @@ -894,6 +894,9 @@ BUILTIN(__builtin_ia32_rdtsc, "ULLi", "") BUILTIN(__rdtsc, "ULLi", "") BUILTIN(__builtin_ia32_rdtscp, "ULLiUi*", "") + +TARGET_BUILTIN(__builtin_ia32_rdpid, "Ui", "", "rdpid") + // PKU TARGET_BUILTIN(__builtin_ia32_rdpkru, "Ui", "", "pku") TARGET_BUILTIN(__builtin_ia32_wrpkru, "vUi", "", "pku") Index: cfe/trunk/include/clang/Driver/Options.td =================================================================== --- cfe/trunk/include/clang/Driver/Options.td +++ cfe/trunk/include/clang/Driver/Options.td @@ -2562,6 +2562,8 @@ def mno_prefetchwt1 : Flag<["-"], "mno-prefetchwt1">, Group; def mprfchw : Flag<["-"], "mprfchw">, Group; def mno_prfchw : Flag<["-"], "mno-prfchw">, Group; +def mrdpid : Flag<["-"], "mrdpid">, Group; +def mno_rdpid : Flag<["-"], "mno-rdpid">, Group; def mrdrnd : Flag<["-"], "mrdrnd">, Group; def mno_rdrnd : Flag<["-"], "mno-rdrnd">, Group; def mrtm : Flag<["-"], "mrtm">, Group; Index: cfe/trunk/lib/Basic/Targets/X86.h =================================================================== --- cfe/trunk/lib/Basic/Targets/X86.h +++ cfe/trunk/lib/Basic/Targets/X86.h @@ -96,6 +96,7 @@ bool HasCLWB = false; bool HasMOVBE = false; bool HasPREFETCHWT1 = false; + bool HasRDPID = false; /// \brief Enumeration of all of the X86 CPUs supported by Clang. /// Index: cfe/trunk/lib/Basic/Targets/X86.cpp =================================================================== --- cfe/trunk/lib/Basic/Targets/X86.cpp +++ cfe/trunk/lib/Basic/Targets/X86.cpp @@ -160,6 +160,7 @@ setFeatureEnabledImpl(Features, "avx512vnni", true); setFeatureEnabledImpl(Features, "avx512vbmi2", true); setFeatureEnabledImpl(Features, "avx512vpopcntdq", true); + setFeatureEnabledImpl(Features, "rdpid", true); LLVM_FALLTHROUGH; case CK_Cannonlake: setFeatureEnabledImpl(Features, "avx512ifma", true); @@ -784,6 +785,8 @@ HasPREFETCHWT1 = true; } else if (Feature == "+clzero") { HasCLZERO = true; + } else if (Feature == "+rdpid") { + HasRDPID = true; } X86SSEEnum Level = llvm::StringSwitch(Feature) @@ -1123,6 +1126,8 @@ Builder.defineMacro("__PREFETCHWT1__"); if (HasCLZERO) Builder.defineMacro("__CLZERO__"); + if (HasRDPID) + Builder.defineMacro("__RDPID__"); // Each case falls through to the previous one here. switch (SSELevel) { @@ -1253,6 +1258,7 @@ .Case("popcnt", true) .Case("prefetchwt1", true) .Case("prfchw", true) + .Case("rdpid", true) .Case("rdrnd", true) .Case("rdseed", true) .Case("rtm", true) @@ -1324,6 +1330,7 @@ .Case("popcnt", HasPOPCNT) .Case("prefetchwt1", HasPREFETCHWT1) .Case("prfchw", HasPRFCHW) + .Case("rdpid", HasRDPID) .Case("rdrnd", HasRDRND) .Case("rdseed", HasRDSEED) .Case("rtm", HasRTM) Index: cfe/trunk/lib/Headers/immintrin.h =================================================================== --- cfe/trunk/lib/Headers/immintrin.h +++ cfe/trunk/lib/Headers/immintrin.h @@ -247,6 +247,18 @@ #include #endif +#if !defined(_MSC_VER) || __has_feature(modules) || defined(__RDPID__) +/// \brief Returns the value of the IA32_TSC_AUX MSR (0xc0000103). +/// +/// \headerfile +/// +/// This intrinsic corresponds to the RDPID instruction. +static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__, __target__("rdpid"))) +_rdpid_u32(void) { + return __builtin_ia32_rdpid(); +} +#endif // __RDPID__ + #if !defined(_MSC_VER) || __has_feature(modules) || defined(__RDRND__) static __inline__ int __attribute__((__always_inline__, __nodebug__, __target__("rdrnd"))) _rdrand16_step(unsigned short *__p) Index: cfe/trunk/test/CodeGen/rdpid-builtins.c =================================================================== --- cfe/trunk/test/CodeGen/rdpid-builtins.c +++ cfe/trunk/test/CodeGen/rdpid-builtins.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -ffreestanding -triple x86_64-unknown-unknown -target-feature +rdpid -emit-llvm -o - %s | FileCheck %s + + +#include + +unsigned int test_rdpid_u32(void) { +// CHECK-LABEL: @test_rdpid_u32 +// CHECK: call i32 @llvm.x86.rdpid + return _rdpid_u32(); +} Index: cfe/trunk/test/Driver/x86-target-features.c =================================================================== --- cfe/trunk/test/Driver/x86-target-features.c +++ cfe/trunk/test/Driver/x86-target-features.c @@ -125,3 +125,7 @@ // VBMI2: "-target-feature" "+avx512vbmi2" // NO-VBMI2: "-target-feature" "-avx512vbmi2" +// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mrdpid %s -### -o %t.o 2>&1 | FileCheck -check-prefix=RDPID %s +// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mno-rdpid %s -### -o %t.o 2>&1 | FileCheck -check-prefix=NO-RDPID %s +// RDPID: "-target-feature" "+rdpid" +// NO-RDPID: "-target-feature" "-rdpid" Index: cfe/trunk/test/Preprocessor/predefined-arch-macros.c =================================================================== --- cfe/trunk/test/Preprocessor/predefined-arch-macros.c +++ cfe/trunk/test/Preprocessor/predefined-arch-macros.c @@ -1086,6 +1086,7 @@ // CHECK_ICL_M32: #define __PKU__ 1 // CHECK_ICL_M32: #define __POPCNT__ 1 // CHECK_ICL_M32: #define __PRFCHW__ 1 +// CHECK_ICL_M32: #define __RDPID__ 1 // CHECK_ICL_M32: #define __RDRND__ 1 // CHECK_ICL_M32: #define __RDSEED__ 1 // CHECK_ICL_M32: #define __RTM__ 1 @@ -1141,6 +1142,7 @@ // CHECK_ICL_M64: #define __PKU__ 1 // CHECK_ICL_M64: #define __POPCNT__ 1 // CHECK_ICL_M64: #define __PRFCHW__ 1 +// CHECK_ICL_M64: #define __RDPID__ 1 // CHECK_ICL_M64: #define __RDRND__ 1 // CHECK_ICL_M64: #define __RDSEED__ 1 // CHECK_ICL_M64: #define __RTM__ 1 Index: cfe/trunk/test/Preprocessor/x86_target_features.c =================================================================== --- cfe/trunk/test/Preprocessor/x86_target_features.c +++ cfe/trunk/test/Preprocessor/x86_target_features.c @@ -436,3 +436,6 @@ // VPCLMULQDQNOPCLMUL-NOT: #define __PCLMUL__ 1 // VPCLMULQDQNOPCLMUL-NOT: #define __VPCLMULQDQ__ 1 +// RUN: %clang -target i386-unknown-unknown -march=atom -mrdpid -x c -E -dM -o - %s | FileCheck -match-full-lines --check-prefix=RDPID %s + +// RDPID: #define __RDPID__ 1