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 gprc:$out), (ins), "#TCHECK_RET", []>;
24 def TBEGIN_RET : PPCCustomInserterPseudo<(outs gprc:$out), (ins u1imm:$R), "#TBEGIN_RET", []>;
28 let Predicates = [HasHTM] in {
31 def TBEGIN : XForm_htm0 <31, 654,
32 (outs), (ins u1imm:$R), "tbegin. $R", IIC_SprMTSPR, []>;
34 def TEND : XForm_htm1 <31, 686,
35 (outs), (ins u1imm:$A), "tend. $A", IIC_SprMTSPR, []>;
37 def TABORT : XForm_base_r3xo <31, 910,
38 (outs), (ins gprc:$A), "tabort. $A", IIC_SprMTSPR,
44 def TABORTWC : XForm_base_r3xo <31, 782,
45 (outs), (ins u5imm:$RTS, gprc:$A, gprc:$B),
46 "tabortwc. $RTS, $A, $B", IIC_SprMTSPR, []>,
49 def TABORTWCI : XForm_base_r3xo <31, 846,
50 (outs), (ins u5imm:$RTS, gprc:$A, u5imm:$B),
51 "tabortwci. $RTS, $A, $B", IIC_SprMTSPR, []>,
54 def TABORTDC : XForm_base_r3xo <31, 814,
55 (outs), (ins u5imm:$RTS, gprc:$A, gprc:$B),
56 "tabortdc. $RTS, $A, $B", IIC_SprMTSPR, []>,
59 def TABORTDCI : XForm_base_r3xo <31, 878,
60 (outs), (ins u5imm:$RTS, gprc:$A, u5imm:$B),
61 "tabortdci. $RTS, $A, $B", IIC_SprMTSPR, []>,
64 def TSR : XForm_htm2 <31, 750,
65 (outs), (ins u1imm:$L), "tsr. $L", IIC_SprMTSPR, []>,
68 def TRECLAIM : XForm_base_r3xo <31, 942,
69 (outs), (ins gprc:$A), "treclaim. $A",
76 def TRECHKPT : XForm_base_r3xo <31, 1006,
77 (outs), (ins), "trechkpt.", IIC_SprMTSPR, []>,
86 def TCHECK : XForm_htm3 <31, 718,
87 (outs crrc:$BF), (ins), "tcheck $BF", IIC_SprMTSPR, []>;
90 // All HTM instructions, with the exception of tcheck, set CR0 with the
91 // value of the MSR Transaction State (TS) bits that exist before the
92 // instruction is executed. For tbegin., the EQ bit in CR0 can be used
93 // to determine whether the transaction was successfully started (0) or
94 // failed (1). We use an XORI pattern to 'flip' the bit to match the
95 // tbegin builtin API which defines a return value of 1 as success.
97 def : Pat<(int_ppc_tbegin i32:$R),
98 (XORI (TBEGIN_RET(HTM_get_imm imm:$R)), 1)>;
100 def : Pat<(int_ppc_tend i32:$R),
101 (TEND (HTM_get_imm imm:$R))>;
103 def : Pat<(int_ppc_tabort i32:$R),
106 def : Pat<(int_ppc_tabortwc i32:$TO, i32:$RA, i32:$RB),
107 (TABORTWC (HTM_get_imm imm:$TO), $RA, $RB)>;
109 def : Pat<(int_ppc_tabortwci i32:$TO, i32:$RA, i32:$SI),
110 (TABORTWCI (HTM_get_imm imm:$TO), $RA, (HTM_get_imm imm:$SI))>;
112 def : Pat<(int_ppc_tabortdc i32:$TO, i32:$RA, i32:$RB),
113 (TABORTDC (HTM_get_imm imm:$TO), $RA, $RB)>;
115 def : Pat<(int_ppc_tabortdci i32:$TO, i32:$RA, i32:$SI),
116 (TABORTDCI (HTM_get_imm imm:$TO), $RA, (HTM_get_imm imm:$SI))>;
118 def : Pat<(int_ppc_tcheck),
121 def : Pat<(int_ppc_treclaim i32:$RA),
124 def : Pat<(int_ppc_trechkpt),
127 def : Pat<(int_ppc_tsr i32:$L),
128 (TSR (HTM_get_imm imm:$L))>;
130 def : Pat<(int_ppc_get_texasr),
133 def : Pat<(int_ppc_get_texasru),
136 def : Pat<(int_ppc_get_tfhar),
139 def : Pat<(int_ppc_get_tfiar),
143 def : Pat<(int_ppc_set_texasr i64:$V),
146 def : Pat<(int_ppc_set_texasru i64:$V),
149 def : Pat<(int_ppc_set_tfhar i64:$V),
152 def : Pat<(int_ppc_set_tfiar i64:$V),
156 // Extended mnemonics
157 def : Pat<(int_ppc_tendall),
160 def : Pat<(int_ppc_tresume),
163 def : Pat<(int_ppc_tsuspend),
166 def : Pat<(i64 (int_ppc_ttest)),
167 (RLDICL (i64 (COPY (TABORTWCI 0, (LI 0), 0))), 36, 28)>;