Kit Barton | 535e69d | 2015-03-25 19:36:23 +0000 | [diff] [blame] | 1 | //===-- PPCInstrHTM.td - The PowerPC Hardware Transactional Memory -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Kit Barton | 535e69d | 2015-03-25 19:36:23 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file describes the Hardware Transactional Memory extension to the |
| 10 | // PowerPC instruction set. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | |
| 15 | |
| 16 | def HasHTM : Predicate<"PPCSubTarget->hasHTM()">; |
| 17 | |
| 18 | def HTM_get_imm : SDNodeXForm<imm, [{ |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 19 | return getI32Imm (N->getZExtValue(), SDLoc(N)); |
Kit Barton | 535e69d | 2015-03-25 19:36:23 +0000 | [diff] [blame] | 20 | }]>; |
| 21 | |
Jinsong Ji | c7b43b9 | 2018-12-13 15:12:57 +0000 | [diff] [blame] | 22 | let hasSideEffects = 1 in { |
| 23 | def TCHECK_RET : PPCCustomInserterPseudo<(outs crrc:$out), (ins), "#TCHECK_RET", []>; |
Kit Barton | 535e69d | 2015-03-25 19:36:23 +0000 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | |
| 27 | let Predicates = [HasHTM] in { |
| 28 | |
| 29 | def TBEGIN : XForm_htm0 <31, 654, |
| 30 | (outs crrc0:$ret), (ins u1imm:$R), "tbegin. $R", IIC_SprMTSPR, []>; |
| 31 | |
| 32 | def TEND : XForm_htm1 <31, 686, |
| 33 | (outs crrc0:$ret), (ins u1imm:$A), "tend. $A", IIC_SprMTSPR, []>; |
| 34 | |
| 35 | def 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 | |
| 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, []>, |
| 45 | isDOT; |
| 46 | |
| 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, []>, |
| 50 | isDOT; |
| 51 | |
| 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, []>, |
| 55 | isDOT; |
| 56 | |
| 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, []>, |
| 60 | isDOT; |
| 61 | |
| 62 | def TSR : XForm_htm2 <31, 750, |
| 63 | (outs crrc0:$ret), (ins u1imm:$L), "tsr. $L", IIC_SprMTSPR, []>, |
| 64 | isDOT; |
| 65 | |
| 66 | def TCHECK : XForm_htm3 <31, 718, |
| 67 | (outs), (ins crrc:$BF), "tcheck $BF", IIC_SprMTSPR, []>; |
| 68 | |
| 69 | |
| 70 | def 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 | |
| 78 | def 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 | |
| 95 | def : Pat<(int_ppc_tbegin i32:$R), |
| 96 | (XORI |
| 97 | (EXTRACT_SUBREG ( |
| 98 | TBEGIN (HTM_get_imm imm:$R)), sub_eq), |
| 99 | 1)>; |
| 100 | |
| 101 | def : Pat<(int_ppc_tend i32:$R), |
| 102 | (TEND (HTM_get_imm imm:$R))>; |
| 103 | |
| 104 | |
| 105 | def : Pat<(int_ppc_tabort i32:$R), |
| 106 | (TABORT $R)>; |
| 107 | |
| 108 | def : Pat<(int_ppc_tabortwc i32:$TO, i32:$RA, i32:$RB), |
| 109 | (TABORTWC (HTM_get_imm imm:$TO), $RA, $RB)>; |
| 110 | |
| 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))>; |
| 113 | |
| 114 | def : Pat<(int_ppc_tabortdc i32:$TO, i32:$RA, i32:$RB), |
| 115 | (TABORTDC (HTM_get_imm imm:$TO), $RA, $RB)>; |
| 116 | |
| 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))>; |
| 119 | |
| 120 | def : Pat<(int_ppc_tcheck), |
| 121 | (TCHECK_RET)>; |
| 122 | |
| 123 | def : Pat<(int_ppc_treclaim i32:$RA), |
| 124 | (TRECLAIM $RA)>; |
| 125 | |
| 126 | def : Pat<(int_ppc_trechkpt), |
| 127 | (TRECHKPT)>; |
| 128 | |
| 129 | def : Pat<(int_ppc_tsr i32:$L), |
| 130 | (TSR (HTM_get_imm imm:$L))>; |
| 131 | |
| 132 | def : Pat<(int_ppc_get_texasr), |
| 133 | (MFSPR8 130)>; |
| 134 | |
| 135 | def : Pat<(int_ppc_get_texasru), |
| 136 | (MFSPR8 131)>; |
| 137 | |
| 138 | def : Pat<(int_ppc_get_tfhar), |
| 139 | (MFSPR8 128)>; |
| 140 | |
| 141 | def : Pat<(int_ppc_get_tfiar), |
| 142 | (MFSPR8 129)>; |
| 143 | |
| 144 | |
| 145 | def : Pat<(int_ppc_set_texasr i64:$V), |
| 146 | (MTSPR8 130, $V)>; |
| 147 | |
| 148 | def : Pat<(int_ppc_set_texasru i64:$V), |
| 149 | (MTSPR8 131, $V)>; |
| 150 | |
| 151 | def : Pat<(int_ppc_set_tfhar i64:$V), |
| 152 | (MTSPR8 128, $V)>; |
| 153 | |
| 154 | def : Pat<(int_ppc_set_tfiar i64:$V), |
| 155 | (MTSPR8 129, $V)>; |
| 156 | |
| 157 | |
| 158 | // Extended mnemonics |
| 159 | def : Pat<(int_ppc_tendall), |
| 160 | (TEND 1)>; |
| 161 | |
| 162 | def : Pat<(int_ppc_tresume), |
| 163 | (TSR 1)>; |
| 164 | |
| 165 | def : Pat<(int_ppc_tsuspend), |
| 166 | (TSR 0)>; |
| 167 | |
| 168 | def : Pat<(i64 (int_ppc_ttest)), |
| 169 | (RLDICL (i64 (COPY (TABORTWCI 0, ZERO, 0))), 36, 28)>; |
| 170 | |
| 171 | } // [HasHTM] |