Skip to content

Commit a3dc949

Browse files
tianqingwxiangzh1
authored andcommitted
[X86] Add TSXLDTRK instructions.
Summary: For more details about these instructions, please refer to the latest ISE document: https://software.intel.com/en-us/download/intel-architecture-instruction-set-extensions-programming-reference Reviewers: craig.topper, RKSimon, LuoYuanke Reviewed By: craig.topper Subscribers: mgorny, hiraditya, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D77205
1 parent 2bcf579 commit a3dc949

File tree

24 files changed

+208
-0
lines changed

24 files changed

+208
-0
lines changed

clang/docs/ClangCommandLineReference.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3175,6 +3175,8 @@ X86
31753175

31763176
.. option:: -mtbm, -mno-tbm
31773177

3178+
.. option:: -mtsxldtrk, -mno-tsxldtrk
3179+
31783180
.. option:: -mvaes, -mno-vaes
31793181

31803182
.. option:: -mvpclmulqdq, -mno-vpclmulqdq

clang/include/clang/Basic/BuiltinsX86.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,6 +1903,10 @@ TARGET_BUILTIN(__builtin_ia32_enqcmds, "Ucv*vC*", "n", "enqcmd")
19031903
// SERIALIZE
19041904
TARGET_BUILTIN(__builtin_ia32_serialize, "v", "n", "serialize")
19051905

1906+
// TSXLDTRK
1907+
TARGET_BUILTIN(__builtin_ia32_xsusldtrk, "v", "n", "tsxldtrk")
1908+
TARGET_BUILTIN(__builtin_ia32_xresldtrk, "v", "n", "tsxldtrk")
1909+
19061910
// MSVC
19071911
TARGET_HEADER_BUILTIN(_BitScanForward, "UcUNi*UNi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
19081912
TARGET_HEADER_BUILTIN(_BitScanReverse, "UcUNi*UNi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3230,6 +3230,8 @@ def msha : Flag<["-"], "msha">, Group<m_x86_Features_Group>;
32303230
def mno_sha : Flag<["-"], "mno-sha">, Group<m_x86_Features_Group>;
32313231
def mtbm : Flag<["-"], "mtbm">, Group<m_x86_Features_Group>;
32323232
def mno_tbm : Flag<["-"], "mno-tbm">, Group<m_x86_Features_Group>;
3233+
def mtsxldtrk : Flag<["-"], "mtsxldtrk">, Group<m_x86_Features_Group>;
3234+
def mno_tsxldtrk : Flag<["-"], "mno-tsxldtrk">, Group<m_x86_Features_Group>;
32333235
def mvaes : Flag<["-"], "mvaes">, Group<m_x86_Features_Group>;
32343236
def mno_vaes : Flag<["-"], "mno-vaes">, Group<m_x86_Features_Group>;
32353237
def mvpclmulqdq : Flag<["-"], "mvpclmulqdq">, Group<m_x86_Features_Group>;

clang/lib/Basic/Targets/X86.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,8 @@ bool X86TargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
859859
HasENQCMD = true;
860860
} else if (Feature == "+serialize") {
861861
HasSERIALIZE = true;
862+
} else if (Feature == "+tsxldtrk") {
863+
HasTSXLDTRK = true;
862864
}
863865

864866
X86SSEEnum Level = llvm::StringSwitch<X86SSEEnum>(Feature)
@@ -1251,6 +1253,8 @@ void X86TargetInfo::getTargetDefines(const LangOptions &Opts,
12511253
Builder.defineMacro("__ENQCMD__");
12521254
if (HasSERIALIZE)
12531255
Builder.defineMacro("__SERIALIZE__");
1256+
if (HasTSXLDTRK)
1257+
Builder.defineMacro("__TSXLDTRK__");
12541258

12551259
// Each case falls through to the previous one here.
12561260
switch (SSELevel) {
@@ -1407,6 +1411,7 @@ bool X86TargetInfo::isValidFeatureName(StringRef Name) const {
14071411
.Case("sse4.2", true)
14081412
.Case("sse4a", true)
14091413
.Case("tbm", true)
1414+
.Case("tsxldtrk", true)
14101415
.Case("vaes", true)
14111416
.Case("vpclmulqdq", true)
14121417
.Case("wbnoinvd", true)
@@ -1491,6 +1496,7 @@ bool X86TargetInfo::hasFeature(StringRef Feature) const {
14911496
.Case("sse4.2", SSELevel >= SSE42)
14921497
.Case("sse4a", XOPLevel >= SSE4A)
14931498
.Case("tbm", HasTBM)
1499+
.Case("tsxldtrk", HasTSXLDTRK)
14941500
.Case("vaes", HasVAES)
14951501
.Case("vpclmulqdq", HasVPCLMULQDQ)
14961502
.Case("wbnoinvd", HasWBNOINVD)

clang/lib/Basic/Targets/X86.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ class LLVM_LIBRARY_VISIBILITY X86TargetInfo : public TargetInfo {
125125
bool HasINVPCID = false;
126126
bool HasENQCMD = false;
127127
bool HasSERIALIZE = false;
128+
bool HasTSXLDTRK = false;
128129

129130
protected:
130131
/// Enumeration of all of the X86 CPUs supported by Clang.

clang/lib/Headers/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ set(files
104104
tbmintrin.h
105105
tgmath.h
106106
tmmintrin.h
107+
tsxldtrkintrin.h
107108
unwind.h
108109
vadefs.h
109110
vaesintrin.h

clang/lib/Headers/cpuid.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@
183183
#define bit_AVX5124VNNIW 0x00000004
184184
#define bit_AVX5124FMAPS 0x00000008
185185
#define bit_SERIALIZE 0x00004000
186+
#define bit_TSXLDTRK 0x00010000
186187
#define bit_PCONFIG 0x00040000
187188
#define bit_IBT 0x00100000
188189

clang/lib/Headers/immintrin.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,10 @@ _storebe_i64(void * __P, long long __D) {
438438
#include <serializeintrin.h>
439439
#endif
440440

441+
#if !defined(_MSC_VER) || __has_feature(modules) || defined(__TSXLDTRK__)
442+
#include <tsxldtrkintrin.h>
443+
#endif
444+
441445
#if defined(_MSC_VER) && __has_extension(gnu_asm)
442446
/* Define the default attributes for these intrinsics */
443447
#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__))

clang/lib/Headers/tsxldtrkintrin.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*===------------- tsxldtrkintrin.h - tsxldtrk intrinsics ------------------===
2+
*
3+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
* See https://llvm.org/LICENSE.txt for license information.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*
7+
*===-----------------------------------------------------------------------===
8+
*/
9+
10+
#ifndef __IMMINTRIN_H
11+
#error "Never use <tsxldtrkintrin.h> directly; include <immintrin.h> instead."
12+
#endif
13+
14+
#ifndef __TSXLDTRKINTRIN_H
15+
#define __TSXLDTRKINTRIN_H
16+
17+
/* Define the default attributes for the functions in this file */
18+
#define _DEFAULT_FN_ATTRS \
19+
__attribute__((__always_inline__, __nodebug__, __target__("tsxldtrk")))
20+
21+
/// Marks the start of an TSX (RTM) suspend load address tracking region. If
22+
/// this intrinsic is used inside a transactional region, subsequent loads
23+
/// are not added to the read set of the transaction. If it's used inside a
24+
/// suspend load address tracking region it will cause transaction abort.
25+
/// If it's used outside of a transactional region it behaves like a NOP.
26+
///
27+
/// \headerfile <x86intrin.h>
28+
///
29+
/// This intrinsic corresponds to the \c XSUSLDTRK instruction.
30+
///
31+
static __inline__ void _DEFAULT_FN_ATTRS
32+
_xsusldtrk (void)
33+
{
34+
__builtin_ia32_xsusldtrk();
35+
}
36+
37+
/// Marks the end of an TSX (RTM) suspend load address tracking region. If this
38+
/// intrinsic is used inside a suspend load address tracking region it will
39+
/// end the suspend region and all following load addresses will be added to
40+
/// the transaction read set. If it's used inside an active transaction but
41+
/// not in a suspend region it will cause transaction abort. If it's used
42+
/// outside of a transactional region it behaves like a NOP.
43+
///
44+
/// \headerfile <x86intrin.h>
45+
///
46+
/// This intrinsic corresponds to the \c XRESLDTRK instruction.
47+
///
48+
static __inline__ void _DEFAULT_FN_ATTRS
49+
_xresldtrk (void)
50+
{
51+
__builtin_ia32_xresldtrk();
52+
}
53+
54+
#undef _DEFAULT_FN_ATTRS
55+
56+
#endif /* __TSXLDTRKINTRIN_H */
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 %s -ffreestanding -triple i386-unknown-unknown -target-feature +tsxldtrk -emit-llvm -o - | FileCheck %s
2+
// RUN: %clang_cc1 %s -ffreestanding -triple x86_64-unknown-unknown -target-feature +tsxldtrk -emit-llvm -o - | FileCheck %s
3+
4+
#include <immintrin.h>
5+
6+
void test_xsusldtrk() {
7+
// CHECK-LABEL: test_xsusldtrk
8+
// CHECK: call void @llvm.x86.xsusldtrk()
9+
_xsusldtrk();
10+
}
11+
12+
void test_xresldtrk() {
13+
// CHECK-LABEL: test_xresldtrk
14+
// CHECK: call void @llvm.x86.xresldtrk()
15+
_xresldtrk();
16+
}

0 commit comments

Comments
 (0)