blob: 7a07b4259150b1e464e6cafe97883889f12d72ac [file] [log] [blame]
Kit Barton535e69d2015-03-25 19:36:23 +00001//===-- PPCInstrHTM.td - The PowerPC Hardware Transactional Memory -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Kit Barton535e69d2015-03-25 19:36:23 +00006//
7//===----------------------------------------------------------------------===//
8//
9// This file describes the Hardware Transactional Memory extension to the
10// PowerPC instruction set.
11//
12//===----------------------------------------------------------------------===//
13
14
15
16def HasHTM : Predicate<"PPCSubTarget->hasHTM()">;
17
18def HTM_get_imm : SDNodeXForm<imm, [{
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +000019 return getI32Imm (N->getZExtValue(), SDLoc(N));
Kit Barton535e69d2015-03-25 19:36:23 +000020}]>;
21
Jinsong Jic7b43b92018-12-13 15:12:57 +000022let hasSideEffects = 1 in {
23def TCHECK_RET : PPCCustomInserterPseudo<(outs crrc:$out), (ins), "#TCHECK_RET", []>;
Kit Barton535e69d2015-03-25 19:36:23 +000024}
25
26
27let Predicates = [HasHTM] in {
28
29def TBEGIN : XForm_htm0 <31, 654,
30 (outs crrc0:$ret), (ins u1imm:$R), "tbegin. $R", IIC_SprMTSPR, []>;
31
32def TEND : XForm_htm1 <31, 686,
33 (outs crrc0:$ret), (ins u1imm:$A), "tend. $A", IIC_SprMTSPR, []>;
34
35def TABORT : XForm_base_r3xo <31, 910,
36 (outs crrc0:$ret), (ins gprc:$A), "tabort. $A", IIC_SprMTSPR,
37 []>, isDOT {
38 let RST = 0;
39 let B = 0;
40}
41
42def TABORTWC : XForm_base_r3xo <31, 782,
43 (outs crrc0:$ret), (ins u5imm:$RTS, gprc:$A, gprc:$B),
44 "tabortwc. $RTS, $A, $B", IIC_SprMTSPR, []>,
45 isDOT;
46
47def TABORTWCI : XForm_base_r3xo <31, 846,
48 (outs crrc0:$ret), (ins u5imm:$RTS, gprc:$A, u5imm:$B),
49 "tabortwci. $RTS, $A, $B", IIC_SprMTSPR, []>,
50 isDOT;
51
52def TABORTDC : XForm_base_r3xo <31, 814,
53 (outs crrc0:$ret), (ins u5imm:$RTS, gprc:$A, gprc:$B),
54 "tabortdc. $RTS, $A, $B", IIC_SprMTSPR, []>,
55 isDOT;
56
57def TABORTDCI : XForm_base_r3xo <31, 878,
58 (outs crrc0:$ret), (ins u5imm:$RTS, gprc:$A, u5imm:$B),
59 "tabortdci. $RTS, $A, $B", IIC_SprMTSPR, []>,
60 isDOT;
61
62def TSR : XForm_htm2 <31, 750,
63 (outs crrc0:$ret), (ins u1imm:$L), "tsr. $L", IIC_SprMTSPR, []>,
64 isDOT;
65
66def TCHECK : XForm_htm3 <31, 718,
67 (outs), (ins crrc:$BF), "tcheck $BF", IIC_SprMTSPR, []>;
68
69
70def TRECLAIM : XForm_base_r3xo <31, 942,
71 (outs crrc:$ret), (ins gprc:$A), "treclaim. $A",
72 IIC_SprMTSPR, []>,
73 isDOT {
74 let RST = 0;
75 let B = 0;
76}
77
78def TRECHKPT : XForm_base_r3xo <31, 1006,
79 (outs crrc:$ret), (ins), "trechkpt.", IIC_SprMTSPR, []>,
80 isDOT {
81 let RST = 0;
82 let A = 0;
83 let B = 0;
84}
85
86// Builtins
87
88// All HTM instructions, with the exception of tcheck, set CR0 with the
89// value of the MSR Transaction State (TS) bits that exist before the
90// instruction is executed. For tbegin., the EQ bit in CR0 can be used
91// to determine whether the transaction was successfully started (0) or
92// failed (1). We use an XORI pattern to 'flip' the bit to match the
93// tbegin builtin API which defines a return value of 1 as success.
94
95def : Pat<(int_ppc_tbegin i32:$R),
96 (XORI
97 (EXTRACT_SUBREG (
98 TBEGIN (HTM_get_imm imm:$R)), sub_eq),
99 1)>;
100
101def : Pat<(int_ppc_tend i32:$R),
102 (TEND (HTM_get_imm imm:$R))>;
103
104
105def : Pat<(int_ppc_tabort i32:$R),
106 (TABORT $R)>;
107
108def : Pat<(int_ppc_tabortwc i32:$TO, i32:$RA, i32:$RB),
109 (TABORTWC (HTM_get_imm imm:$TO), $RA, $RB)>;
110
111def : Pat<(int_ppc_tabortwci i32:$TO, i32:$RA, i32:$SI),
112 (TABORTWCI (HTM_get_imm imm:$TO), $RA, (HTM_get_imm imm:$SI))>;
113
114def : Pat<(int_ppc_tabortdc i32:$TO, i32:$RA, i32:$RB),
115 (TABORTDC (HTM_get_imm imm:$TO), $RA, $RB)>;
116
117def : Pat<(int_ppc_tabortdci i32:$TO, i32:$RA, i32:$SI),
118 (TABORTDCI (HTM_get_imm imm:$TO), $RA, (HTM_get_imm imm:$SI))>;
119
120def : Pat<(int_ppc_tcheck),
121 (TCHECK_RET)>;
122
123def : Pat<(int_ppc_treclaim i32:$RA),
124 (TRECLAIM $RA)>;
125
126def : Pat<(int_ppc_trechkpt),
127 (TRECHKPT)>;
128
129def : Pat<(int_ppc_tsr i32:$L),
130 (TSR (HTM_get_imm imm:$L))>;
131
132def : Pat<(int_ppc_get_texasr),
133 (MFSPR8 130)>;
134
135def : Pat<(int_ppc_get_texasru),
136 (MFSPR8 131)>;
137
138def : Pat<(int_ppc_get_tfhar),
139 (MFSPR8 128)>;
140
141def : Pat<(int_ppc_get_tfiar),
142 (MFSPR8 129)>;
143
144
145def : Pat<(int_ppc_set_texasr i64:$V),
146 (MTSPR8 130, $V)>;
147
148def : Pat<(int_ppc_set_texasru i64:$V),
149 (MTSPR8 131, $V)>;
150
151def : Pat<(int_ppc_set_tfhar i64:$V),
152 (MTSPR8 128, $V)>;
153
154def : Pat<(int_ppc_set_tfiar i64:$V),
155 (MTSPR8 129, $V)>;
156
157
158// Extended mnemonics
159def : Pat<(int_ppc_tendall),
160 (TEND 1)>;
161
162def : Pat<(int_ppc_tresume),
163 (TSR 1)>;
164
165def : Pat<(int_ppc_tsuspend),
166 (TSR 0)>;
167
168def : Pat<(i64 (int_ppc_ttest)),
169 (RLDICL (i64 (COPY (TABORTWCI 0, ZERO, 0))), 36, 28)>;
170
171} // [HasHTM]