Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 1 | // WebAssemblyInstrAtomics.td-WebAssembly Atomic codegen support-*- tablegen -*- |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
JF Bastien | 5ca0bac | 2015-07-10 18:23:10 +0000 | [diff] [blame] | 9 | /// |
| 10 | /// \file |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 11 | /// WebAssembly Atomic operand code-gen constructs. |
JF Bastien | 5ca0bac | 2015-07-10 18:23:10 +0000 | [diff] [blame] | 12 | /// |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 15 | //===----------------------------------------------------------------------===// |
| 16 | // Atomic loads |
| 17 | //===----------------------------------------------------------------------===// |
| 18 | |
Derek Schuff | 18ba192 | 2017-08-30 18:07:45 +0000 | [diff] [blame] | 19 | let Defs = [ARGUMENTS] in { |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame] | 20 | defm ATOMIC_LOAD_I32 : WebAssemblyLoad<I32, "i32.atomic.load", 0xfe10>; |
| 21 | defm ATOMIC_LOAD_I64 : WebAssemblyLoad<I64, "i64.atomic.load", 0xfe11>; |
Derek Schuff | 18ba192 | 2017-08-30 18:07:45 +0000 | [diff] [blame] | 22 | } // Defs = [ARGUMENTS] |
| 23 | |
| 24 | // Select loads with no constant offset. |
| 25 | let Predicates = [HasAtomics] in { |
Derek Schuff | 885dc59 | 2017-10-05 21:18:42 +0000 | [diff] [blame] | 26 | def : LoadPatNoOffset<i32, atomic_load_32, ATOMIC_LOAD_I32>; |
| 27 | def : LoadPatNoOffset<i64, atomic_load_64, ATOMIC_LOAD_I64>; |
Derek Schuff | 0f3bc0f | 2017-08-31 21:51:48 +0000 | [diff] [blame] | 28 | |
Derek Schuff | 885dc59 | 2017-10-05 21:18:42 +0000 | [diff] [blame] | 29 | // Select loads with a constant offset. |
| 30 | |
| 31 | // Pattern with address + immediate offset |
| 32 | def : LoadPatImmOff<i32, atomic_load_32, regPlusImm, ATOMIC_LOAD_I32>; |
| 33 | def : LoadPatImmOff<i64, atomic_load_64, regPlusImm, ATOMIC_LOAD_I64>; |
| 34 | def : LoadPatImmOff<i32, atomic_load_32, or_is_add, ATOMIC_LOAD_I32>; |
| 35 | def : LoadPatImmOff<i64, atomic_load_64, or_is_add, ATOMIC_LOAD_I64>; |
| 36 | |
| 37 | def : LoadPatGlobalAddr<i32, atomic_load_32, ATOMIC_LOAD_I32>; |
| 38 | def : LoadPatGlobalAddr<i64, atomic_load_64, ATOMIC_LOAD_I64>; |
| 39 | |
| 40 | def : LoadPatExternalSym<i32, atomic_load_32, ATOMIC_LOAD_I32>; |
| 41 | def : LoadPatExternalSym<i64, atomic_load_64, ATOMIC_LOAD_I64>; |
| 42 | |
Derek Schuff | 885dc59 | 2017-10-05 21:18:42 +0000 | [diff] [blame] | 43 | // Select loads with just a constant offset. |
| 44 | def : LoadPatOffsetOnly<i32, atomic_load_32, ATOMIC_LOAD_I32>; |
| 45 | def : LoadPatOffsetOnly<i64, atomic_load_64, ATOMIC_LOAD_I64>; |
| 46 | |
| 47 | def : LoadPatGlobalAddrOffOnly<i32, atomic_load_32, ATOMIC_LOAD_I32>; |
| 48 | def : LoadPatGlobalAddrOffOnly<i64, atomic_load_64, ATOMIC_LOAD_I64>; |
| 49 | |
| 50 | def : LoadPatExternSymOffOnly<i32, atomic_load_32, ATOMIC_LOAD_I32>; |
| 51 | def : LoadPatExternSymOffOnly<i64, atomic_load_64, ATOMIC_LOAD_I64>; |
| 52 | |
| 53 | } // Predicates = [HasAtomics] |
| 54 | |
| 55 | // Extending loads. Note that there are only zero-extending atomic loads, no |
| 56 | // sign-extending loads. |
| 57 | let Defs = [ARGUMENTS] in { |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame] | 58 | defm ATOMIC_LOAD8_U_I32 : WebAssemblyLoad<I32, "i32.atomic.load8_u", 0xfe12>; |
| 59 | defm ATOMIC_LOAD16_U_I32 : WebAssemblyLoad<I32, "i32.atomic.load16_u", 0xfe13>; |
| 60 | defm ATOMIC_LOAD8_U_I64 : WebAssemblyLoad<I64, "i64.atomic.load8_u", 0xfe14>; |
| 61 | defm ATOMIC_LOAD16_U_I64 : WebAssemblyLoad<I64, "i64.atomic.load16_u", 0xfe15>; |
| 62 | defm ATOMIC_LOAD32_U_I64 : WebAssemblyLoad<I64, "i64.atomic.load32_u", 0xfe16>; |
Derek Schuff | 885dc59 | 2017-10-05 21:18:42 +0000 | [diff] [blame] | 63 | } // Defs = [ARGUMENTS] |
| 64 | |
Heejin Ahn | d31bc98 | 2018-07-09 20:18:21 +0000 | [diff] [blame^] | 65 | // Fragments for extending loads. These are different from regular loads because |
Derek Schuff | 885dc59 | 2017-10-05 21:18:42 +0000 | [diff] [blame] | 66 | // the SDNodes are derived from AtomicSDNode rather than LoadSDNode and |
| 67 | // therefore don't have the extension type field. So instead of matching that, |
| 68 | // we match the patterns that the type legalizer expands them to. |
| 69 | |
| 70 | // We directly match zext patterns and select the zext atomic loads. |
| 71 | // i32 (zext (i8 (atomic_load_8))) gets legalized to |
| 72 | // i32 (and (i32 (atomic_load_8)), 255) |
| 73 | // These can be selected to a single zero-extending atomic load instruction. |
Heejin Ahn | d31bc98 | 2018-07-09 20:18:21 +0000 | [diff] [blame^] | 74 | def zext_aload_8_32 : |
| 75 | PatFrag<(ops node:$addr), (and (i32 (atomic_load_8 node:$addr)), 255)>; |
| 76 | def zext_aload_16_32 : |
| 77 | PatFrag<(ops node:$addr), (and (i32 (atomic_load_16 node:$addr)), 65535)>; |
Derek Schuff | 885dc59 | 2017-10-05 21:18:42 +0000 | [diff] [blame] | 78 | // Unlike regular loads, extension to i64 is handled differently than i32. |
| 79 | // i64 (zext (i8 (atomic_load_8))) gets legalized to |
| 80 | // i64 (and (i64 (anyext (i32 (atomic_load_8)))), 255) |
| 81 | def zext_aload_8_64 : |
| 82 | PatFrag<(ops node:$addr), |
| 83 | (and (i64 (anyext (i32 (atomic_load_8 node:$addr)))), 255)>; |
| 84 | def zext_aload_16_64 : |
| 85 | PatFrag<(ops node:$addr), |
| 86 | (and (i64 (anyext (i32 (atomic_load_16 node:$addr)))), 65535)>; |
| 87 | def zext_aload_32_64 : |
| 88 | PatFrag<(ops node:$addr), |
| 89 | (zext (i32 (atomic_load node:$addr)))>; |
| 90 | |
| 91 | // We don't have single sext atomic load instructions. So for sext loads, we |
| 92 | // match bare subword loads (for 32-bit results) and anyext loads (for 64-bit |
| 93 | // results) and select a zext load; the next instruction will be sext_inreg |
| 94 | // which is selected by itself. |
Heejin Ahn | d31bc98 | 2018-07-09 20:18:21 +0000 | [diff] [blame^] | 95 | def sext_aload_8_64 : |
Derek Schuff | 885dc59 | 2017-10-05 21:18:42 +0000 | [diff] [blame] | 96 | PatFrag<(ops node:$addr), (anyext (i32 (atomic_load_8 node:$addr)))>; |
Heejin Ahn | d31bc98 | 2018-07-09 20:18:21 +0000 | [diff] [blame^] | 97 | def sext_aload_16_64 : |
Derek Schuff | 885dc59 | 2017-10-05 21:18:42 +0000 | [diff] [blame] | 98 | PatFrag<(ops node:$addr), (anyext (i32 (atomic_load_16 node:$addr)))>; |
| 99 | |
| 100 | let Predicates = [HasAtomics] in { |
| 101 | // Select zero-extending loads with no constant offset. |
Heejin Ahn | d31bc98 | 2018-07-09 20:18:21 +0000 | [diff] [blame^] | 102 | def : LoadPatNoOffset<i32, zext_aload_8_32, ATOMIC_LOAD8_U_I32>; |
| 103 | def : LoadPatNoOffset<i32, zext_aload_16_32, ATOMIC_LOAD16_U_I32>; |
Derek Schuff | 885dc59 | 2017-10-05 21:18:42 +0000 | [diff] [blame] | 104 | def : LoadPatNoOffset<i64, zext_aload_8_64, ATOMIC_LOAD8_U_I64>; |
| 105 | def : LoadPatNoOffset<i64, zext_aload_16_64, ATOMIC_LOAD16_U_I64>; |
| 106 | def : LoadPatNoOffset<i64, zext_aload_32_64, ATOMIC_LOAD32_U_I64>; |
| 107 | |
| 108 | // Select sign-extending loads with no constant offset |
| 109 | def : LoadPatNoOffset<i32, atomic_load_8, ATOMIC_LOAD8_U_I32>; |
| 110 | def : LoadPatNoOffset<i32, atomic_load_16, ATOMIC_LOAD16_U_I32>; |
Heejin Ahn | d31bc98 | 2018-07-09 20:18:21 +0000 | [diff] [blame^] | 111 | def : LoadPatNoOffset<i64, sext_aload_8_64, ATOMIC_LOAD8_U_I64>; |
| 112 | def : LoadPatNoOffset<i64, sext_aload_16_64, ATOMIC_LOAD16_U_I64>; |
| 113 | // 32->64 sext load gets selected as i32.atomic.load, i64.extend_s/i32 |
Derek Schuff | 885dc59 | 2017-10-05 21:18:42 +0000 | [diff] [blame] | 114 | |
| 115 | // Zero-extending loads with constant offset |
Heejin Ahn | d31bc98 | 2018-07-09 20:18:21 +0000 | [diff] [blame^] | 116 | def : LoadPatImmOff<i32, zext_aload_8_32, regPlusImm, ATOMIC_LOAD8_U_I32>; |
| 117 | def : LoadPatImmOff<i32, zext_aload_16_32, regPlusImm, ATOMIC_LOAD16_U_I32>; |
| 118 | def : LoadPatImmOff<i32, zext_aload_8_32, or_is_add, ATOMIC_LOAD8_U_I32>; |
| 119 | def : LoadPatImmOff<i32, zext_aload_16_32, or_is_add, ATOMIC_LOAD16_U_I32>; |
Derek Schuff | 885dc59 | 2017-10-05 21:18:42 +0000 | [diff] [blame] | 120 | def : LoadPatImmOff<i64, zext_aload_8_64, regPlusImm, ATOMIC_LOAD8_U_I64>; |
| 121 | def : LoadPatImmOff<i64, zext_aload_16_64, regPlusImm, ATOMIC_LOAD16_U_I64>; |
| 122 | def : LoadPatImmOff<i64, zext_aload_32_64, regPlusImm, ATOMIC_LOAD32_U_I64>; |
| 123 | def : LoadPatImmOff<i64, zext_aload_8_64, or_is_add, ATOMIC_LOAD8_U_I64>; |
| 124 | def : LoadPatImmOff<i64, zext_aload_16_64, or_is_add, ATOMIC_LOAD16_U_I64>; |
| 125 | def : LoadPatImmOff<i64, zext_aload_32_64, or_is_add, ATOMIC_LOAD32_U_I64>; |
| 126 | |
| 127 | // Sign-extending loads with constant offset |
| 128 | def : LoadPatImmOff<i32, atomic_load_8, regPlusImm, ATOMIC_LOAD8_U_I32>; |
| 129 | def : LoadPatImmOff<i32, atomic_load_16, regPlusImm, ATOMIC_LOAD16_U_I32>; |
| 130 | def : LoadPatImmOff<i32, atomic_load_8, or_is_add, ATOMIC_LOAD8_U_I32>; |
| 131 | def : LoadPatImmOff<i32, atomic_load_16, or_is_add, ATOMIC_LOAD16_U_I32>; |
Heejin Ahn | d31bc98 | 2018-07-09 20:18:21 +0000 | [diff] [blame^] | 132 | def : LoadPatImmOff<i64, sext_aload_8_64, regPlusImm, ATOMIC_LOAD8_U_I64>; |
| 133 | def : LoadPatImmOff<i64, sext_aload_16_64, regPlusImm, ATOMIC_LOAD16_U_I64>; |
| 134 | def : LoadPatImmOff<i64, sext_aload_8_64, or_is_add, ATOMIC_LOAD8_U_I64>; |
| 135 | def : LoadPatImmOff<i64, sext_aload_16_64, or_is_add, ATOMIC_LOAD16_U_I64>; |
Derek Schuff | 885dc59 | 2017-10-05 21:18:42 +0000 | [diff] [blame] | 136 | // No 32->64 patterns, just use i32.atomic.load and i64.extend_s/i64 |
| 137 | |
Heejin Ahn | d31bc98 | 2018-07-09 20:18:21 +0000 | [diff] [blame^] | 138 | def : LoadPatGlobalAddr<i32, zext_aload_8_32, ATOMIC_LOAD8_U_I32>; |
| 139 | def : LoadPatGlobalAddr<i32, zext_aload_16_32, ATOMIC_LOAD16_U_I32>; |
Derek Schuff | 885dc59 | 2017-10-05 21:18:42 +0000 | [diff] [blame] | 140 | def : LoadPatGlobalAddr<i64, zext_aload_8_64, ATOMIC_LOAD8_U_I64>; |
| 141 | def : LoadPatGlobalAddr<i64, zext_aload_16_64, ATOMIC_LOAD16_U_I64>; |
| 142 | def : LoadPatGlobalAddr<i64, zext_aload_32_64, ATOMIC_LOAD32_U_I64>; |
| 143 | def : LoadPatGlobalAddr<i32, atomic_load_8, ATOMIC_LOAD8_U_I32>; |
| 144 | def : LoadPatGlobalAddr<i32, atomic_load_16, ATOMIC_LOAD16_U_I32>; |
Heejin Ahn | d31bc98 | 2018-07-09 20:18:21 +0000 | [diff] [blame^] | 145 | def : LoadPatGlobalAddr<i64, sext_aload_8_64, ATOMIC_LOAD8_U_I64>; |
| 146 | def : LoadPatGlobalAddr<i64, sext_aload_16_64, ATOMIC_LOAD16_U_I64>; |
Derek Schuff | 885dc59 | 2017-10-05 21:18:42 +0000 | [diff] [blame] | 147 | |
Heejin Ahn | d31bc98 | 2018-07-09 20:18:21 +0000 | [diff] [blame^] | 148 | def : LoadPatExternalSym<i32, zext_aload_8_32, ATOMIC_LOAD8_U_I32>; |
| 149 | def : LoadPatExternalSym<i32, zext_aload_16_32, ATOMIC_LOAD16_U_I32>; |
Derek Schuff | 885dc59 | 2017-10-05 21:18:42 +0000 | [diff] [blame] | 150 | def : LoadPatExternalSym<i64, zext_aload_8_64, ATOMIC_LOAD8_U_I64>; |
| 151 | def : LoadPatExternalSym<i64, zext_aload_16_64, ATOMIC_LOAD16_U_I64>; |
| 152 | def : LoadPatExternalSym<i64, zext_aload_32_64, ATOMIC_LOAD32_U_I64>; |
| 153 | def : LoadPatExternalSym<i32, atomic_load_8, ATOMIC_LOAD8_U_I32>; |
| 154 | def : LoadPatExternalSym<i32, atomic_load_16, ATOMIC_LOAD16_U_I32>; |
Heejin Ahn | d31bc98 | 2018-07-09 20:18:21 +0000 | [diff] [blame^] | 155 | def : LoadPatExternalSym<i64, sext_aload_8_64, ATOMIC_LOAD8_U_I64>; |
| 156 | def : LoadPatExternalSym<i64, sext_aload_16_64, ATOMIC_LOAD16_U_I64>; |
Derek Schuff | 885dc59 | 2017-10-05 21:18:42 +0000 | [diff] [blame] | 157 | |
| 158 | // Extending loads with just a constant offset |
Heejin Ahn | d31bc98 | 2018-07-09 20:18:21 +0000 | [diff] [blame^] | 159 | def : LoadPatOffsetOnly<i32, zext_aload_8_32, ATOMIC_LOAD8_U_I32>; |
| 160 | def : LoadPatOffsetOnly<i32, zext_aload_16_32, ATOMIC_LOAD16_U_I32>; |
Derek Schuff | 885dc59 | 2017-10-05 21:18:42 +0000 | [diff] [blame] | 161 | def : LoadPatOffsetOnly<i64, zext_aload_8_64, ATOMIC_LOAD8_U_I64>; |
| 162 | def : LoadPatOffsetOnly<i64, zext_aload_16_64, ATOMIC_LOAD16_U_I64>; |
| 163 | def : LoadPatOffsetOnly<i64, zext_aload_32_64, ATOMIC_LOAD32_U_I64>; |
| 164 | def : LoadPatOffsetOnly<i32, atomic_load_8, ATOMIC_LOAD8_U_I32>; |
| 165 | def : LoadPatOffsetOnly<i32, atomic_load_16, ATOMIC_LOAD16_U_I32>; |
Heejin Ahn | d31bc98 | 2018-07-09 20:18:21 +0000 | [diff] [blame^] | 166 | def : LoadPatOffsetOnly<i64, sext_aload_8_64, ATOMIC_LOAD8_U_I64>; |
| 167 | def : LoadPatOffsetOnly<i64, sext_aload_16_64, ATOMIC_LOAD16_U_I64>; |
Derek Schuff | 885dc59 | 2017-10-05 21:18:42 +0000 | [diff] [blame] | 168 | |
Heejin Ahn | d31bc98 | 2018-07-09 20:18:21 +0000 | [diff] [blame^] | 169 | def : LoadPatGlobalAddrOffOnly<i32, zext_aload_8_32, ATOMIC_LOAD8_U_I32>; |
| 170 | def : LoadPatGlobalAddrOffOnly<i32, zext_aload_16_32, ATOMIC_LOAD16_U_I32>; |
Derek Schuff | 885dc59 | 2017-10-05 21:18:42 +0000 | [diff] [blame] | 171 | def : LoadPatGlobalAddrOffOnly<i64, zext_aload_8_64, ATOMIC_LOAD8_U_I64>; |
| 172 | def : LoadPatGlobalAddrOffOnly<i64, zext_aload_16_64, ATOMIC_LOAD16_U_I64>; |
| 173 | def : LoadPatGlobalAddrOffOnly<i64, zext_aload_32_64, ATOMIC_LOAD32_U_I64>; |
| 174 | def : LoadPatGlobalAddrOffOnly<i32, atomic_load_8, ATOMIC_LOAD8_U_I32>; |
| 175 | def : LoadPatGlobalAddrOffOnly<i32, atomic_load_16, ATOMIC_LOAD16_U_I32>; |
Heejin Ahn | d31bc98 | 2018-07-09 20:18:21 +0000 | [diff] [blame^] | 176 | def : LoadPatGlobalAddrOffOnly<i64, sext_aload_8_64, ATOMIC_LOAD8_U_I64>; |
| 177 | def : LoadPatGlobalAddrOffOnly<i64, sext_aload_16_64, ATOMIC_LOAD16_U_I64>; |
Derek Schuff | 885dc59 | 2017-10-05 21:18:42 +0000 | [diff] [blame] | 178 | |
Heejin Ahn | d31bc98 | 2018-07-09 20:18:21 +0000 | [diff] [blame^] | 179 | def : LoadPatExternSymOffOnly<i32, zext_aload_8_32, ATOMIC_LOAD8_U_I32>; |
| 180 | def : LoadPatExternSymOffOnly<i32, zext_aload_16_32, ATOMIC_LOAD16_U_I32>; |
Derek Schuff | 885dc59 | 2017-10-05 21:18:42 +0000 | [diff] [blame] | 181 | def : LoadPatExternSymOffOnly<i64, zext_aload_8_64, ATOMIC_LOAD8_U_I64>; |
| 182 | def : LoadPatExternSymOffOnly<i64, zext_aload_16_64, ATOMIC_LOAD16_U_I64>; |
| 183 | def : LoadPatExternSymOffOnly<i64, zext_aload_32_64, ATOMIC_LOAD32_U_I64>; |
| 184 | def : LoadPatExternSymOffOnly<i32, atomic_load_8, ATOMIC_LOAD8_U_I32>; |
| 185 | def : LoadPatExternSymOffOnly<i32, atomic_load_16, ATOMIC_LOAD16_U_I32>; |
Heejin Ahn | d31bc98 | 2018-07-09 20:18:21 +0000 | [diff] [blame^] | 186 | def : LoadPatExternSymOffOnly<i64, sext_aload_8_64, ATOMIC_LOAD8_U_I64>; |
| 187 | def : LoadPatExternSymOffOnly<i64, sext_aload_16_64, ATOMIC_LOAD16_U_I64>; |
Derek Schuff | 885dc59 | 2017-10-05 21:18:42 +0000 | [diff] [blame] | 188 | |
| 189 | } // Predicates = [HasAtomics] |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 190 | |
| 191 | //===----------------------------------------------------------------------===// |
| 192 | // Atomic stores |
| 193 | //===----------------------------------------------------------------------===// |
| 194 | |
Heejin Ahn | 402b490 | 2018-07-02 21:22:59 +0000 | [diff] [blame] | 195 | let Defs = [ARGUMENTS] in { |
| 196 | defm ATOMIC_STORE_I32 : WebAssemblyStore<I32, "i32.atomic.store", 0xfe17>; |
| 197 | defm ATOMIC_STORE_I64 : WebAssemblyStore<I64, "i64.atomic.store", 0xfe18>; |
| 198 | } // Defs = [ARGUMENTS] |
| 199 | |
| 200 | // We need an 'atomic' version of store patterns because store and atomic_store |
| 201 | // nodes have different operand orders: |
| 202 | // store: (store $val, $ptr) |
| 203 | // atomic_store: (store $ptr, $val) |
| 204 | |
| 205 | let Predicates = [HasAtomics] in { |
| 206 | |
| 207 | // Select stores with no constant offset. |
Heejin Ahn | d31bc98 | 2018-07-09 20:18:21 +0000 | [diff] [blame^] | 208 | class AStorePatNoOffset<ValueType ty, PatFrag kind, NI inst> : |
| 209 | Pat<(kind I32:$addr, ty:$val), (inst 0, 0, I32:$addr, ty:$val)>; |
Heejin Ahn | 402b490 | 2018-07-02 21:22:59 +0000 | [diff] [blame] | 210 | def : AStorePatNoOffset<i32, atomic_store_32, ATOMIC_STORE_I32>; |
| 211 | def : AStorePatNoOffset<i64, atomic_store_64, ATOMIC_STORE_I64>; |
| 212 | |
| 213 | // Select stores with a constant offset. |
| 214 | |
| 215 | // Pattern with address + immediate offset |
Heejin Ahn | d31bc98 | 2018-07-09 20:18:21 +0000 | [diff] [blame^] | 216 | class AStorePatImmOff<ValueType ty, PatFrag kind, PatFrag operand, NI inst> : |
| 217 | Pat<(kind (operand I32:$addr, imm:$off), ty:$val), |
| 218 | (inst 0, imm:$off, I32:$addr, ty:$val)>; |
Heejin Ahn | 402b490 | 2018-07-02 21:22:59 +0000 | [diff] [blame] | 219 | def : AStorePatImmOff<i32, atomic_store_32, regPlusImm, ATOMIC_STORE_I32>; |
| 220 | def : AStorePatImmOff<i64, atomic_store_64, regPlusImm, ATOMIC_STORE_I64>; |
| 221 | def : AStorePatImmOff<i32, atomic_store_32, or_is_add, ATOMIC_STORE_I32>; |
| 222 | def : AStorePatImmOff<i64, atomic_store_64, or_is_add, ATOMIC_STORE_I64>; |
| 223 | |
Heejin Ahn | d31bc98 | 2018-07-09 20:18:21 +0000 | [diff] [blame^] | 224 | class AStorePatGlobalAddr<ValueType ty, PatFrag kind, NI inst> : |
| 225 | Pat<(kind (regPlusGA I32:$addr, (WebAssemblywrapper tglobaladdr:$off)), |
| 226 | ty:$val), |
Heejin Ahn | 402b490 | 2018-07-02 21:22:59 +0000 | [diff] [blame] | 227 | (inst 0, tglobaladdr:$off, I32:$addr, ty:$val)>; |
| 228 | def : AStorePatGlobalAddr<i32, atomic_store_32, ATOMIC_STORE_I32>; |
| 229 | def : AStorePatGlobalAddr<i64, atomic_store_64, ATOMIC_STORE_I64>; |
| 230 | |
Heejin Ahn | d31bc98 | 2018-07-09 20:18:21 +0000 | [diff] [blame^] | 231 | class AStorePatExternalSym<ValueType ty, PatFrag kind, NI inst> : |
| 232 | Pat<(kind (add I32:$addr, (WebAssemblywrapper texternalsym:$off)), ty:$val), |
Heejin Ahn | 402b490 | 2018-07-02 21:22:59 +0000 | [diff] [blame] | 233 | (inst 0, texternalsym:$off, I32:$addr, ty:$val)>; |
| 234 | def : AStorePatExternalSym<i32, atomic_store_32, ATOMIC_STORE_I32>; |
| 235 | def : AStorePatExternalSym<i64, atomic_store_64, ATOMIC_STORE_I64>; |
| 236 | |
| 237 | // Select stores with just a constant offset. |
Heejin Ahn | d31bc98 | 2018-07-09 20:18:21 +0000 | [diff] [blame^] | 238 | class AStorePatOffsetOnly<ValueType ty, PatFrag kind, NI inst> : |
| 239 | Pat<(kind imm:$off, ty:$val), (inst 0, imm:$off, (CONST_I32 0), ty:$val)>; |
Heejin Ahn | 402b490 | 2018-07-02 21:22:59 +0000 | [diff] [blame] | 240 | def : AStorePatOffsetOnly<i32, atomic_store_32, ATOMIC_STORE_I32>; |
| 241 | def : AStorePatOffsetOnly<i64, atomic_store_64, ATOMIC_STORE_I64>; |
| 242 | |
Heejin Ahn | d31bc98 | 2018-07-09 20:18:21 +0000 | [diff] [blame^] | 243 | class AStorePatGlobalAddrOffOnly<ValueType ty, PatFrag kind, NI inst> : |
| 244 | Pat<(kind (WebAssemblywrapper tglobaladdr:$off), ty:$val), |
Heejin Ahn | 402b490 | 2018-07-02 21:22:59 +0000 | [diff] [blame] | 245 | (inst 0, tglobaladdr:$off, (CONST_I32 0), ty:$val)>; |
| 246 | def : AStorePatGlobalAddrOffOnly<i32, atomic_store_32, ATOMIC_STORE_I32>; |
| 247 | def : AStorePatGlobalAddrOffOnly<i64, atomic_store_64, ATOMIC_STORE_I64>; |
| 248 | |
Heejin Ahn | d31bc98 | 2018-07-09 20:18:21 +0000 | [diff] [blame^] | 249 | class AStorePatExternSymOffOnly<ValueType ty, PatFrag kind, NI inst> : |
| 250 | Pat<(kind (WebAssemblywrapper texternalsym:$off), ty:$val), |
Heejin Ahn | 402b490 | 2018-07-02 21:22:59 +0000 | [diff] [blame] | 251 | (inst 0, texternalsym:$off, (CONST_I32 0), ty:$val)>; |
| 252 | def : AStorePatExternSymOffOnly<i32, atomic_store_32, ATOMIC_STORE_I32>; |
| 253 | def : AStorePatExternSymOffOnly<i64, atomic_store_64, ATOMIC_STORE_I64>; |
| 254 | |
| 255 | } // Predicates = [HasAtomics] |
| 256 | |
| 257 | // Truncating stores. |
| 258 | let Defs = [ARGUMENTS] in { |
| 259 | defm ATOMIC_STORE8_I32 : WebAssemblyStore<I32, "i32.atomic.store8", 0xfe19>; |
| 260 | defm ATOMIC_STORE16_I32 : WebAssemblyStore<I32, "i32.atomic.store16", 0xfe1a>; |
| 261 | defm ATOMIC_STORE8_I64 : WebAssemblyStore<I64, "i64.atomic.store8", 0xfe1b>; |
| 262 | defm ATOMIC_STORE16_I64 : WebAssemblyStore<I64, "i64.atomic.store16", 0xfe1c>; |
| 263 | defm ATOMIC_STORE32_I64 : WebAssemblyStore<I64, "i64.atomic.store32", 0xfe1d>; |
| 264 | } // Defs = [ARGUMENTS] |
| 265 | |
| 266 | // Fragments for truncating stores. |
| 267 | |
| 268 | // We don't have single truncating atomic store instructions. For 32-bit |
| 269 | // instructions, we just need to match bare atomic stores. On the other hand, |
| 270 | // truncating stores from i64 values are once truncated to i32 first. |
Heejin Ahn | d31bc98 | 2018-07-09 20:18:21 +0000 | [diff] [blame^] | 271 | class trunc_astore_64<PatFrag kind> : |
Heejin Ahn | 402b490 | 2018-07-02 21:22:59 +0000 | [diff] [blame] | 272 | PatFrag<(ops node:$addr, node:$val), |
Heejin Ahn | d31bc98 | 2018-07-09 20:18:21 +0000 | [diff] [blame^] | 273 | (kind node:$addr, (i32 (trunc (i64 node:$val))))>; |
Heejin Ahn | 402b490 | 2018-07-02 21:22:59 +0000 | [diff] [blame] | 274 | def trunc_astore_8_64 : trunc_astore_64<atomic_store_8>; |
| 275 | def trunc_astore_16_64 : trunc_astore_64<atomic_store_16>; |
| 276 | def trunc_astore_32_64 : trunc_astore_64<atomic_store_32>; |
| 277 | |
| 278 | let Predicates = [HasAtomics] in { |
| 279 | |
| 280 | // Truncating stores with no constant offset |
| 281 | def : AStorePatNoOffset<i32, atomic_store_8, ATOMIC_STORE8_I32>; |
| 282 | def : AStorePatNoOffset<i32, atomic_store_16, ATOMIC_STORE16_I32>; |
| 283 | def : AStorePatNoOffset<i64, trunc_astore_8_64, ATOMIC_STORE8_I64>; |
| 284 | def : AStorePatNoOffset<i64, trunc_astore_16_64, ATOMIC_STORE16_I64>; |
| 285 | def : AStorePatNoOffset<i64, trunc_astore_32_64, ATOMIC_STORE32_I64>; |
| 286 | |
| 287 | // Truncating stores with a constant offset |
| 288 | def : AStorePatImmOff<i32, atomic_store_8, regPlusImm, ATOMIC_STORE8_I32>; |
| 289 | def : AStorePatImmOff<i32, atomic_store_16, regPlusImm, ATOMIC_STORE16_I32>; |
| 290 | def : AStorePatImmOff<i64, trunc_astore_8_64, regPlusImm, ATOMIC_STORE8_I64>; |
| 291 | def : AStorePatImmOff<i64, trunc_astore_16_64, regPlusImm, ATOMIC_STORE16_I64>; |
| 292 | def : AStorePatImmOff<i64, trunc_astore_32_64, regPlusImm, ATOMIC_STORE32_I64>; |
| 293 | def : AStorePatImmOff<i32, atomic_store_8, or_is_add, ATOMIC_STORE8_I32>; |
| 294 | def : AStorePatImmOff<i32, atomic_store_16, or_is_add, ATOMIC_STORE16_I32>; |
| 295 | def : AStorePatImmOff<i64, trunc_astore_8_64, or_is_add, ATOMIC_STORE8_I64>; |
| 296 | def : AStorePatImmOff<i64, trunc_astore_16_64, or_is_add, ATOMIC_STORE16_I64>; |
| 297 | def : AStorePatImmOff<i64, trunc_astore_32_64, or_is_add, ATOMIC_STORE32_I64>; |
| 298 | |
| 299 | def : AStorePatGlobalAddr<i32, atomic_store_8, ATOMIC_STORE8_I32>; |
| 300 | def : AStorePatGlobalAddr<i32, atomic_store_16, ATOMIC_STORE16_I32>; |
| 301 | def : AStorePatGlobalAddr<i64, trunc_astore_8_64, ATOMIC_STORE8_I64>; |
| 302 | def : AStorePatGlobalAddr<i64, trunc_astore_16_64, ATOMIC_STORE16_I64>; |
| 303 | def : AStorePatGlobalAddr<i64, trunc_astore_32_64, ATOMIC_STORE32_I64>; |
| 304 | |
| 305 | def : AStorePatExternalSym<i32, atomic_store_8, ATOMIC_STORE8_I32>; |
| 306 | def : AStorePatExternalSym<i32, atomic_store_16, ATOMIC_STORE16_I32>; |
| 307 | def : AStorePatExternalSym<i64, trunc_astore_8_64, ATOMIC_STORE8_I64>; |
| 308 | def : AStorePatExternalSym<i64, trunc_astore_16_64, ATOMIC_STORE16_I64>; |
| 309 | def : AStorePatExternalSym<i64, trunc_astore_32_64, ATOMIC_STORE32_I64>; |
| 310 | |
| 311 | // Truncating stores with just a constant offset |
| 312 | def : AStorePatOffsetOnly<i32, atomic_store_8, ATOMIC_STORE8_I32>; |
| 313 | def : AStorePatOffsetOnly<i32, atomic_store_16, ATOMIC_STORE16_I32>; |
| 314 | def : AStorePatOffsetOnly<i64, trunc_astore_8_64, ATOMIC_STORE8_I64>; |
| 315 | def : AStorePatOffsetOnly<i64, trunc_astore_16_64, ATOMIC_STORE16_I64>; |
| 316 | def : AStorePatOffsetOnly<i64, trunc_astore_32_64, ATOMIC_STORE32_I64>; |
| 317 | |
| 318 | def : AStorePatGlobalAddrOffOnly<i32, atomic_store_8, ATOMIC_STORE8_I32>; |
| 319 | def : AStorePatGlobalAddrOffOnly<i32, atomic_store_16, ATOMIC_STORE16_I32>; |
| 320 | def : AStorePatGlobalAddrOffOnly<i64, trunc_astore_8_64, ATOMIC_STORE8_I64>; |
| 321 | def : AStorePatGlobalAddrOffOnly<i64, trunc_astore_16_64, ATOMIC_STORE16_I64>; |
| 322 | def : AStorePatGlobalAddrOffOnly<i64, trunc_astore_32_64, ATOMIC_STORE32_I64>; |
| 323 | |
| 324 | def : AStorePatExternSymOffOnly<i32, atomic_store_8, ATOMIC_STORE8_I32>; |
| 325 | def : AStorePatExternSymOffOnly<i32, atomic_store_16, ATOMIC_STORE16_I32>; |
| 326 | def : AStorePatExternSymOffOnly<i64, trunc_astore_8_64, ATOMIC_STORE8_I64>; |
| 327 | def : AStorePatExternSymOffOnly<i64, trunc_astore_16_64, ATOMIC_STORE16_I64>; |
| 328 | def : AStorePatExternSymOffOnly<i64, trunc_astore_32_64, ATOMIC_STORE32_I64>; |
| 329 | |
| 330 | } // Predicates = [HasAtomics] |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 331 | |
| 332 | //===----------------------------------------------------------------------===// |
| 333 | // Low-level exclusive operations |
| 334 | //===----------------------------------------------------------------------===// |
| 335 | |
| 336 | // TODO: add exclusive operations here... |
| 337 | |
| 338 | // Load-exclusives. |
| 339 | |
| 340 | // Store-exclusives. |
| 341 | |
| 342 | // Store-release-exclusives. |
| 343 | |
| 344 | // And clear exclusive. |
Derek Schuff | 18ba192 | 2017-08-30 18:07:45 +0000 | [diff] [blame] | 345 | |