1 //===-- PPCInstrHTM.td - The PowerPC Hardware Transactional Memory -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file describes the Hardware Transactional Memory extension to the
10 // PowerPC instruction set.
12 //===----------------------------------------------------------------------===//
16 def HasHTM : Predicate<"PPCSubTarget->hasHTM()">;
18 def HTM_get_imm : SDNodeXForm<imm, [{
19 return getI32Imm (N->getZExtValue(), SDLoc(N));
22 let hasSideEffects = 1 in {
23 def TCHECK_RET : PPCCustomInserterPseudo<(outs crrc:$out), (ins), "#TCHECK_RET", []>;
27 let Predicates = [HasHTM] in {
29 def TBEGIN : XForm_htm0 <31, 654,
30 (outs crrc0:$ret), (ins u1imm:$R), "tbegin. $R", IIC_SprMTSPR, []>;
32 def TEND : XForm_htm1 <31, 686,
33 (outs crrc0:$ret), (ins u1imm:$A), "tend. $A", IIC_SprMTSPR, []>;
35 def TABORT : XForm_base_r3xo <31, 910,
36 (outs crrc0:$ret), (ins gprc:$A), "tabort. $A", IIC_SprMTSPR,
42 def TABORTWC : XForm_base_r3xo <31, 782,
43 (outs crrc0:$ret), (ins u5imm:$RTS, gprc:$A, gprc:$B),
44 "tabortwc. $RTS, $A, $B", IIC_SprMTSPR, []>,
47 def TABORTWCI : XForm_base_r3xo <31, 846,
48 (outs crrc0:$ret), (ins u5imm:$RTS, gprc:$A, u5imm:$B),
49 "tabortwci. $RTS, $A, $B", IIC_SprMTSPR, []>,
52 def TABORTDC : XForm_base_r3xo <31, 814,
53 (outs crrc0:$ret), (ins u5imm:$RTS, gprc:$A, gprc:$B),
54 "tabortdc. $RTS, $A, $B", IIC_SprMTSPR, []>,
57 def TABORTDCI : XForm_base_r3xo <31, 878,
58 (outs crrc0:$ret), (ins u5imm:$RTS, gprc:$A, u5imm:$B),
59 "tabortdci. $RTS, $A, $B", IIC_SprMTSPR, []>,
62 def TSR : XForm_htm2 <31, 750,
63 (outs crrc0:$ret), (ins u1imm:$L), "tsr. $L", IIC_SprMTSPR, []>,
66 def TCHECK : XForm_htm3 <31, 718,
67 (outs), (ins crrc:$BF), "tcheck $BF", IIC_SprMTSPR, []>;
70 def TRECLAIM : XForm_base_r3xo <31, 942,
71 (outs crrc:$ret), (ins gprc:$A), "treclaim. $A",
78 def TRECHKPT : XForm_base_r3xo <31, 1006,
79 (outs crrc:$ret), (ins), "trechkpt.", IIC_SprMTSPR, []>,
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.
95 def : Pat<(int_ppc_tbegin i32:$R),
98 TBEGIN (HTM_get_imm imm:$R)), sub_eq),
101 def : Pat<(int_ppc_tend i32:$R),
102 (TEND (HTM_get_imm imm:$R))>;
105 def : Pat<(int_ppc_tabort i32:$R),
108 def : Pat<(int_ppc_tabortwc i32:$TO, i32:$RA, i32:$RB),
109 (TABORTWC (HTM_get_imm imm:$TO), $RA, $RB)>;
111 def : Pat<(int_ppc_tabortwci i32:$TO, i32:$RA, i32:$SI),
112 (TABORTWCI (HTM_get_imm imm:$TO), $RA, (HTM_get_imm imm:$SI))>;
114 def : Pat<(int_ppc_tabortdc i32:$TO, i32:$RA, i32:$RB),
115 (TABORTDC (HTM_get_imm imm:$TO), $RA, $RB)>;
117 def : Pat<(int_ppc_tabortdci i32:$TO, i32:$RA, i32:$SI),
118 (TABORTDCI (HTM_get_imm imm:$TO), $RA, (HTM_get_imm imm:$SI))>;
120 def : Pat<(int_ppc_tcheck),
123 def : Pat<(int_ppc_treclaim i32:$RA),
126 def : Pat<(int_ppc_trechkpt),
129 def : Pat<(int_ppc_tsr i32:$L),
130 (TSR (HTM_get_imm imm:$L))>;
132 def : Pat<(int_ppc_get_texasr),
135 def : Pat<(int_ppc_get_texasru),
138 def : Pat<(int_ppc_get_tfhar),
141 def : Pat<(int_ppc_get_tfiar),
145 def : Pat<(int_ppc_set_texasr i64:$V),
148 def : Pat<(int_ppc_set_texasru i64:$V),
151 def : Pat<(int_ppc_set_tfhar i64:$V),
154 def : Pat<(int_ppc_set_tfiar i64:$V),
158 // Extended mnemonics
159 def : Pat<(int_ppc_tendall),
162 def : Pat<(int_ppc_tresume),
165 def : Pat<(int_ppc_tsuspend),
168 def : Pat<(i64 (int_ppc_ttest)),
169 (RLDICL (i64 (COPY (TABORTWCI 0, ZERO, 0))), 36, 28)>;