1 include "AArch64InstrFormats.td"
3 //===----------------------------------------------------------------------===//
4 // Target-specific ISD nodes and profiles
5 //===----------------------------------------------------------------------===//
7 def SDT_A64ret : SDTypeProfile<0, 0, []>;
8 def A64ret : SDNode<"AArch64ISD::Ret", SDT_A64ret, [SDNPHasChain,
12 // (ins NZCV, Condition, Dest)
13 def SDT_A64br_cc : SDTypeProfile<0, 3, [SDTCisVT<0, i32>]>;
14 def A64br_cc : SDNode<"AArch64ISD::BR_CC", SDT_A64br_cc, [SDNPHasChain]>;
16 // (outs Result), (ins NZCV, IfTrue, IfFalse, Condition)
17 def SDT_A64select_cc : SDTypeProfile<1, 4, [SDTCisVT<1, i32>,
20 def A64select_cc : SDNode<"AArch64ISD::SELECT_CC", SDT_A64select_cc>;
22 // (outs NZCV), (ins LHS, RHS, Condition)
23 def SDT_A64setcc : SDTypeProfile<1, 3, [SDTCisVT<0, i32>,
25 def A64setcc : SDNode<"AArch64ISD::SETCC", SDT_A64setcc>;
28 // (outs GPR64), (ins)
29 def A64threadpointer : SDNode<"AArch64ISD::THREAD_POINTER", SDTPtrLeaf>;
31 // A64 compares don't care about the cond really (they set all flags) so a
32 // simple binary operator is useful.
33 def A64cmp : PatFrag<(ops node:$lhs, node:$rhs),
34 (A64setcc node:$lhs, node:$rhs, cond)>;
37 // When matching a notional (CMP op1, (sub 0, op2)), we'd like to use a CMN
38 // instruction on the grounds that "op1 - (-op2) == op1 + op2". However, the C
39 // and V flags can be set differently by this operation. It comes down to
40 // whether "SInt(~op2)+1 == SInt(~op2+1)" (and the same for UInt). If they are
41 // then everything is fine. If not then the optimization is wrong. Thus general
42 // comparisons are only valid if op2 != 0.
44 // So, finally, the only LLVM-native comparisons that don't mention C and V are
45 // SETEQ and SETNE. They're the only ones we can safely use CMN for in the
46 // absence of information about op2.
47 def equality_cond : PatLeaf<(cond), [{
48 return N->get() == ISD::SETEQ || N->get() == ISD::SETNE;
51 def A64cmn : PatFrag<(ops node:$lhs, node:$rhs),
52 (A64setcc node:$lhs, (sub 0, node:$rhs), equality_cond)>;
54 // There are two layers of indirection here, driven by the following
56 // + TableGen does not know CodeModel or Reloc so that decision should be
57 // made for a variable/address at ISelLowering.
58 // + The output of ISelLowering should be selectable (hence the Wrapper,
59 // rather than a bare target opcode)
60 def SDTAArch64Wrapper : SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>,
65 def A64WrapperSmall : SDNode<"AArch64ISD::WrapperSmall", SDTAArch64Wrapper>;
68 def SDTAArch64GOTLoad : SDTypeProfile<1, 1, [SDTCisPtrTy<0>, SDTCisPtrTy<1>]>;
69 def A64GOTLoad : SDNode<"AArch64ISD::GOTLoad", SDTAArch64GOTLoad,
73 // (A64BFI LHS, RHS, LSB, Width)
74 def SDTA64BFI : SDTypeProfile<1, 4, [SDTCisSameAs<0, 1>,
79 def A64Bfi : SDNode<"AArch64ISD::BFI", SDTA64BFI>;
81 // (A64EXTR HiReg, LoReg, LSB)
82 def SDTA64EXTR : SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>,
84 def A64Extr : SDNode<"AArch64ISD::EXTR", SDTA64EXTR>;
86 // (A64[SU]BFX Field, ImmR, ImmS).
88 // Note that ImmR and ImmS are already encoded for the actual instructions. The
89 // more natural LSB and Width mix together to form ImmR and ImmS, something
90 // which TableGen can't handle.
91 def SDTA64BFX : SDTypeProfile<1, 3, [SDTCisVT<2, i64>, SDTCisVT<3, i64>]>;
92 def A64Sbfx : SDNode<"AArch64ISD::SBFX", SDTA64BFX>;
94 def A64Ubfx : SDNode<"AArch64ISD::UBFX", SDTA64BFX>;
96 //===----------------------------------------------------------------------===//
97 // Call sequence pseudo-instructions
98 //===----------------------------------------------------------------------===//
101 def SDT_AArch64Call : SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>;
102 def AArch64Call : SDNode<"AArch64ISD::Call", SDT_AArch64Call,
103 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue, SDNPVariadic]>;
105 def AArch64tcret : SDNode<"AArch64ISD::TC_RETURN", SDT_AArch64Call,
106 [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
108 // The TLSDESCCALL node is a variant call which goes to an indirectly calculated
109 // destination but needs a relocation against a fixed symbol. As such it has two
110 // certain operands: the callee and the relocated variable.
112 // The TLS ABI only allows it to be selected to a BLR instructin (with
113 // appropriate relocation).
114 def SDTTLSDescCall : SDTypeProfile<0, -2, [SDTCisPtrTy<0>, SDTCisPtrTy<1>]>;
116 def A64tlsdesc_blr : SDNode<"AArch64ISD::TLSDESCCALL", SDTTLSDescCall,
117 [SDNPInGlue, SDNPOutGlue, SDNPHasChain,
121 def SDT_AArch64CallSeqStart : SDCallSeqStart<[ SDTCisPtrTy<0> ]>;
122 def AArch64callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_AArch64CallSeqStart,
123 [SDNPHasChain, SDNPOutGlue]>;
125 def SDT_AArch64CallSeqEnd : SDCallSeqEnd<[ SDTCisPtrTy<0>, SDTCisPtrTy<1> ]>;
126 def AArch64callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_AArch64CallSeqEnd,
127 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
131 // These pseudo-instructions have special semantics by virtue of being passed to
132 // the InstrInfo constructor. CALLSEQ_START/CALLSEQ_END are produced by
133 // LowerCall to (in our case) tell the back-end about stack adjustments for
134 // arguments passed on the stack. Here we select those markers to
135 // pseudo-instructions which explicitly set the stack, and finally in the
136 // RegisterInfo we convert them to a true stack adjustment.
137 let Defs = [XSP], Uses = [XSP] in {
138 def ADJCALLSTACKDOWN : PseudoInst<(outs), (ins i64imm:$amt),
139 [(AArch64callseq_start timm:$amt)]>;
141 def ADJCALLSTACKUP : PseudoInst<(outs), (ins i64imm:$amt1, i64imm:$amt2),
142 [(AArch64callseq_end timm:$amt1, timm:$amt2)]>;
145 //===----------------------------------------------------------------------===//
146 // Atomic operation pseudo-instructions
147 //===----------------------------------------------------------------------===//
149 let usesCustomInserter = 1, Defs = [NZCV] in {
150 multiclass AtomicSizes<string opname> {
151 def _I8 : PseudoInst<(outs GPR32:$dst), (ins GPR64:$ptr, GPR32:$incr),
152 [(set GPR32:$dst, (!cast<SDNode>(opname # "_8") GPR64:$ptr, GPR32:$incr))]>;
153 def _I16 : PseudoInst<(outs GPR32:$dst), (ins GPR64:$ptr, GPR32:$incr),
154 [(set GPR32:$dst, (!cast<SDNode>(opname # "_16") GPR64:$ptr, GPR32:$incr))]>;
155 def _I32 : PseudoInst<(outs GPR32:$dst), (ins GPR64:$ptr, GPR32:$incr),
156 [(set GPR32:$dst, (!cast<SDNode>(opname # "_32") GPR64:$ptr, GPR32:$incr))]>;
157 def _I64 : PseudoInst<(outs GPR64:$dst), (ins GPR64:$ptr, GPR64:$incr),
158 [(set GPR64:$dst, (!cast<SDNode>(opname # "_64") GPR64:$ptr, GPR64:$incr))]>;
162 defm ATOMIC_LOAD_ADD : AtomicSizes<"atomic_load_add">;
163 defm ATOMIC_LOAD_SUB : AtomicSizes<"atomic_load_sub">;
164 defm ATOMIC_LOAD_AND : AtomicSizes<"atomic_load_and">;
165 defm ATOMIC_LOAD_OR : AtomicSizes<"atomic_load_or">;
166 defm ATOMIC_LOAD_XOR : AtomicSizes<"atomic_load_xor">;
167 defm ATOMIC_LOAD_NAND : AtomicSizes<"atomic_load_nand">;
168 defm ATOMIC_LOAD_MIN : AtomicSizes<"atomic_load_min">;
169 defm ATOMIC_LOAD_MAX : AtomicSizes<"atomic_load_max">;
170 defm ATOMIC_LOAD_UMIN : AtomicSizes<"atomic_load_umin">;
171 defm ATOMIC_LOAD_UMAX : AtomicSizes<"atomic_load_umax">;
172 defm ATOMIC_SWAP : AtomicSizes<"atomic_swap">;
174 let usesCustomInserter = 1, Defs = [NZCV] in {
175 def ATOMIC_CMP_SWAP_I8
176 : PseudoInst<(outs GPR32:$dst), (ins GPR64:$ptr, GPR32:$old, GPR32:$new),
178 (atomic_cmp_swap_8 GPR64:$ptr, GPR32:$old, GPR32:$new))]>;
179 def ATOMIC_CMP_SWAP_I16
180 : PseudoInst<(outs GPR32:$dst), (ins GPR64:$ptr, GPR32:$old, GPR32:$new),
182 (atomic_cmp_swap_16 GPR64:$ptr, GPR32:$old, GPR32:$new))]>;
183 def ATOMIC_CMP_SWAP_I32
184 : PseudoInst<(outs GPR32:$dst), (ins GPR64:$ptr, GPR32:$old, GPR32:$new),
186 (atomic_cmp_swap_32 GPR64:$ptr, GPR32:$old, GPR32:$new))]>;
187 def ATOMIC_CMP_SWAP_I64
188 : PseudoInst<(outs GPR64:$dst), (ins GPR64:$ptr, GPR64:$old, GPR64:$new),
190 (atomic_cmp_swap_64 GPR64:$ptr, GPR64:$old, GPR64:$new))]>;
193 //===----------------------------------------------------------------------===//
194 // Add-subtract (extended register) instructions
195 //===----------------------------------------------------------------------===//
196 // Contains: ADD, ADDS, SUB, SUBS + aliases CMN, CMP
198 // The RHS of these operations is conceptually a sign/zero-extended
199 // register, optionally shifted left by 1-4. The extension can be a
200 // NOP (e.g. "sxtx" sign-extending a 64-bit register to 64-bits) but
201 // must be specified with one exception:
203 // If one of the registers is sp/wsp then LSL is an alias for UXTW in
204 // 32-bit instructions and UXTX in 64-bit versions, the shift amount
205 // is not optional in that case (but can explicitly be 0), and the
206 // entire suffix can be skipped (e.g. "add sp, x3, x2").
208 multiclass extend_operands<string PREFIX, string Diag> {
209 def _asmoperand : AsmOperandClass {
211 let RenderMethod = "addRegExtendOperands";
212 let PredicateMethod = "isRegExtend<A64SE::" # PREFIX # ">";
213 let DiagnosticType = "AddSubRegExtend" # Diag;
216 def _operand : Operand<i64>,
217 ImmLeaf<i64, [{ return Imm >= 0 && Imm <= 4; }]> {
218 let PrintMethod = "printRegExtendOperand<A64SE::" # PREFIX # ">";
219 let DecoderMethod = "DecodeRegExtendOperand";
220 let ParserMatchClass = !cast<AsmOperandClass>(PREFIX # "_asmoperand");
224 defm UXTB : extend_operands<"UXTB", "Small">;
225 defm UXTH : extend_operands<"UXTH", "Small">;
226 defm UXTW : extend_operands<"UXTW", "Small">;
227 defm UXTX : extend_operands<"UXTX", "Large">;
228 defm SXTB : extend_operands<"SXTB", "Small">;
229 defm SXTH : extend_operands<"SXTH", "Small">;
230 defm SXTW : extend_operands<"SXTW", "Small">;
231 defm SXTX : extend_operands<"SXTX", "Large">;
233 def LSL_extasmoperand : AsmOperandClass {
234 let Name = "RegExtendLSL";
235 let RenderMethod = "addRegExtendOperands";
236 let DiagnosticType = "AddSubRegExtendLarge";
239 def LSL_extoperand : Operand<i64> {
240 let ParserMatchClass = LSL_extasmoperand;
244 // The patterns for various sign-extensions are a little ugly and
245 // non-uniform because everything has already been promoted to the
246 // legal i64 and i32 types. We'll wrap the various variants up in a
247 // class for use later.
249 dag uxtb; dag uxth; dag uxtw; dag uxtx;
250 dag sxtb; dag sxth; dag sxtw; dag sxtx;
253 def extends_to_i64 : extend_types {
254 let uxtb = (and (anyext GPR32:$Rm), 255);
255 let uxth = (and (anyext GPR32:$Rm), 65535);
256 let uxtw = (zext GPR32:$Rm);
257 let uxtx = (i64 GPR64:$Rm);
259 let sxtb = (sext_inreg (anyext GPR32:$Rm), i8);
260 let sxth = (sext_inreg (anyext GPR32:$Rm), i16);
261 let sxtw = (sext GPR32:$Rm);
262 let sxtx = (i64 GPR64:$Rm);
266 def extends_to_i32 : extend_types {
267 let uxtb = (and GPR32:$Rm, 255);
268 let uxth = (and GPR32:$Rm, 65535);
269 let uxtw = (i32 GPR32:$Rm);
270 let uxtx = (i32 GPR32:$Rm);
272 let sxtb = (sext_inreg GPR32:$Rm, i8);
273 let sxth = (sext_inreg GPR32:$Rm, i16);
274 let sxtw = (i32 GPR32:$Rm);
275 let sxtx = (i32 GPR32:$Rm);
278 // Now, six of the extensions supported are easy and uniform: if the source size
279 // is 32-bits or less, then Rm is always a 32-bit register. We'll instantiate
280 // those instructions in one block.
282 // The uxtx/sxtx could potentially be merged in, but three facts dissuaded me:
283 // + It would break the naming scheme: either ADDxx_uxtx or ADDww_uxtx would
285 // + Patterns are very different as well.
286 // + Passing different registers would be ugly (more fields in extend_types
287 // would probably be the best option).
288 multiclass addsub_exts<bit sf, bit op, bit S, string asmop,
289 SDPatternOperator opfrag,
290 dag outs, extend_types exts, RegisterClass GPRsp> {
291 def w_uxtb : A64I_addsubext<sf, op, S, 0b00, 0b000,
293 (ins GPRsp:$Rn, GPR32:$Rm, UXTB_operand:$Imm3),
294 !strconcat(asmop, "$Rn, $Rm, $Imm3"),
295 [(opfrag GPRsp:$Rn, (shl exts.uxtb, UXTB_operand:$Imm3))],
297 def w_uxth : A64I_addsubext<sf, op, S, 0b00, 0b001,
299 (ins GPRsp:$Rn, GPR32:$Rm, UXTH_operand:$Imm3),
300 !strconcat(asmop, "$Rn, $Rm, $Imm3"),
301 [(opfrag GPRsp:$Rn, (shl exts.uxth, UXTH_operand:$Imm3))],
303 def w_uxtw : A64I_addsubext<sf, op, S, 0b00, 0b010,
305 (ins GPRsp:$Rn, GPR32:$Rm, UXTW_operand:$Imm3),
306 !strconcat(asmop, "$Rn, $Rm, $Imm3"),
307 [(opfrag GPRsp:$Rn, (shl exts.uxtw, UXTW_operand:$Imm3))],
310 def w_sxtb : A64I_addsubext<sf, op, S, 0b00, 0b100,
312 (ins GPRsp:$Rn, GPR32:$Rm, SXTB_operand:$Imm3),
313 !strconcat(asmop, "$Rn, $Rm, $Imm3"),
314 [(opfrag GPRsp:$Rn, (shl exts.sxtb, SXTB_operand:$Imm3))],
316 def w_sxth : A64I_addsubext<sf, op, S, 0b00, 0b101,
318 (ins GPRsp:$Rn, GPR32:$Rm, SXTH_operand:$Imm3),
319 !strconcat(asmop, "$Rn, $Rm, $Imm3"),
320 [(opfrag GPRsp:$Rn, (shl exts.sxth, SXTH_operand:$Imm3))],
322 def w_sxtw : A64I_addsubext<sf, op, S, 0b00, 0b110,
324 (ins GPRsp:$Rn, GPR32:$Rm, SXTW_operand:$Imm3),
325 !strconcat(asmop, "$Rn, $Rm, $Imm3"),
326 [(opfrag GPRsp:$Rn, (shl exts.sxtw, SXTW_operand:$Imm3))],
330 // These two could be merge in with the above, but their patterns aren't really
331 // necessary and the naming-scheme would necessarily break:
332 multiclass addsub_xxtx<bit op, bit S, string asmop, SDPatternOperator opfrag,
334 def x_uxtx : A64I_addsubext<0b1, op, S, 0b00, 0b011,
336 (ins GPR64xsp:$Rn, GPR64:$Rm, UXTX_operand:$Imm3),
337 !strconcat(asmop, "$Rn, $Rm, $Imm3"),
338 [(opfrag GPR64xsp:$Rn, (shl GPR64:$Rm, UXTX_operand:$Imm3))],
341 def x_sxtx : A64I_addsubext<0b1, op, S, 0b00, 0b111,
343 (ins GPR64xsp:$Rn, GPR64:$Rm, SXTX_operand:$Imm3),
344 !strconcat(asmop, "$Rn, $Rm, $Imm3"),
345 [/* No Pattern: same as uxtx */],
349 multiclass addsub_wxtx<bit op, bit S, string asmop, dag outs> {
350 def w_uxtx : A64I_addsubext<0b0, op, S, 0b00, 0b011,
352 (ins GPR32wsp:$Rn, GPR32:$Rm, UXTX_operand:$Imm3),
353 !strconcat(asmop, "$Rn, $Rm, $Imm3"),
354 [/* No pattern: probably same as uxtw */],
357 def w_sxtx : A64I_addsubext<0b0, op, S, 0b00, 0b111,
359 (ins GPR32wsp:$Rn, GPR32:$Rm, SXTX_operand:$Imm3),
360 !strconcat(asmop, "$Rn, $Rm, $Imm3"),
361 [/* No Pattern: probably same as uxtw */],
365 class SetRD<RegisterClass RC, SDPatternOperator op>
366 : PatFrag<(ops node:$lhs, node:$rhs), (set RC:$Rd, (op node:$lhs, node:$rhs))>;
367 class SetNZCV<SDPatternOperator op>
368 : PatFrag<(ops node:$lhs, node:$rhs), (set NZCV, (op node:$lhs, node:$rhs))>;
370 defm ADDxx :addsub_exts<0b1, 0b0, 0b0, "add\t$Rd, ", SetRD<GPR64xsp, add>,
371 (outs GPR64xsp:$Rd), extends_to_i64, GPR64xsp>,
372 addsub_xxtx< 0b0, 0b0, "add\t$Rd, ", SetRD<GPR64xsp, add>,
373 (outs GPR64xsp:$Rd)>;
374 defm ADDww :addsub_exts<0b0, 0b0, 0b0, "add\t$Rd, ", SetRD<GPR32wsp, add>,
375 (outs GPR32wsp:$Rd), extends_to_i32, GPR32wsp>,
376 addsub_wxtx< 0b0, 0b0, "add\t$Rd, ",
377 (outs GPR32wsp:$Rd)>;
378 defm SUBxx :addsub_exts<0b1, 0b1, 0b0, "sub\t$Rd, ", SetRD<GPR64xsp, sub>,
379 (outs GPR64xsp:$Rd), extends_to_i64, GPR64xsp>,
380 addsub_xxtx< 0b1, 0b0, "sub\t$Rd, ", SetRD<GPR64xsp, sub>,
381 (outs GPR64xsp:$Rd)>;
382 defm SUBww :addsub_exts<0b0, 0b1, 0b0, "sub\t$Rd, ", SetRD<GPR32wsp, sub>,
383 (outs GPR32wsp:$Rd), extends_to_i32, GPR32wsp>,
384 addsub_wxtx< 0b1, 0b0, "sub\t$Rd, ",
385 (outs GPR32wsp:$Rd)>;
387 let Defs = [NZCV] in {
388 defm ADDSxx :addsub_exts<0b1, 0b0, 0b1, "adds\t$Rd, ", SetRD<GPR64, addc>,
389 (outs GPR64:$Rd), extends_to_i64, GPR64xsp>,
390 addsub_xxtx< 0b0, 0b1, "adds\t$Rd, ", SetRD<GPR64, addc>,
392 defm ADDSww :addsub_exts<0b0, 0b0, 0b1, "adds\t$Rd, ", SetRD<GPR32, addc>,
393 (outs GPR32:$Rd), extends_to_i32, GPR32wsp>,
394 addsub_wxtx< 0b0, 0b1, "adds\t$Rd, ",
396 defm SUBSxx :addsub_exts<0b1, 0b1, 0b1, "subs\t$Rd, ", SetRD<GPR64, subc>,
397 (outs GPR64:$Rd), extends_to_i64, GPR64xsp>,
398 addsub_xxtx< 0b1, 0b1, "subs\t$Rd, ", SetRD<GPR64, subc>,
400 defm SUBSww :addsub_exts<0b0, 0b1, 0b1, "subs\t$Rd, ", SetRD<GPR32, subc>,
401 (outs GPR32:$Rd), extends_to_i32, GPR32wsp>,
402 addsub_wxtx< 0b1, 0b1, "subs\t$Rd, ",
406 let Rd = 0b11111, isCompare = 1 in {
407 defm CMNx : addsub_exts<0b1, 0b0, 0b1, "cmn\t", SetNZCV<A64cmn>,
408 (outs), extends_to_i64, GPR64xsp>,
409 addsub_xxtx< 0b0, 0b1, "cmn\t", SetNZCV<A64cmn>, (outs)>;
410 defm CMNw : addsub_exts<0b0, 0b0, 0b1, "cmn\t", SetNZCV<A64cmn>,
411 (outs), extends_to_i32, GPR32wsp>,
412 addsub_wxtx< 0b0, 0b1, "cmn\t", (outs)>;
413 defm CMPx : addsub_exts<0b1, 0b1, 0b1, "cmp\t", SetNZCV<A64cmp>,
414 (outs), extends_to_i64, GPR64xsp>,
415 addsub_xxtx< 0b1, 0b1, "cmp\t", SetNZCV<A64cmp>, (outs)>;
416 defm CMPw : addsub_exts<0b0, 0b1, 0b1, "cmp\t", SetNZCV<A64cmp>,
417 (outs), extends_to_i32, GPR32wsp>,
418 addsub_wxtx< 0b1, 0b1, "cmp\t", (outs)>;
422 // Now patterns for the operation without a shift being needed. No patterns are
423 // created for uxtx/sxtx since they're non-uniform and it's expected that
424 // add/sub (shifted register) will handle those cases anyway.
425 multiclass addsubext_noshift_patterns<string prefix, SDPatternOperator nodeop,
426 RegisterClass GPRsp, extend_types exts> {
427 def : Pat<(nodeop GPRsp:$Rn, exts.uxtb),
428 (!cast<Instruction>(prefix # "w_uxtb") GPRsp:$Rn, GPR32:$Rm, 0)>;
429 def : Pat<(nodeop GPRsp:$Rn, exts.uxth),
430 (!cast<Instruction>(prefix # "w_uxth") GPRsp:$Rn, GPR32:$Rm, 0)>;
431 def : Pat<(nodeop GPRsp:$Rn, exts.uxtw),
432 (!cast<Instruction>(prefix # "w_uxtw") GPRsp:$Rn, GPR32:$Rm, 0)>;
434 def : Pat<(nodeop GPRsp:$Rn, exts.sxtb),
435 (!cast<Instruction>(prefix # "w_sxtb") GPRsp:$Rn, GPR32:$Rm, 0)>;
436 def : Pat<(nodeop GPRsp:$Rn, exts.sxth),
437 (!cast<Instruction>(prefix # "w_sxth") GPRsp:$Rn, GPR32:$Rm, 0)>;
438 def : Pat<(nodeop GPRsp:$Rn, exts.sxtw),
439 (!cast<Instruction>(prefix # "w_sxtw") GPRsp:$Rn, GPR32:$Rm, 0)>;
442 defm : addsubext_noshift_patterns<"ADDxx", add, GPR64xsp, extends_to_i64>;
443 defm : addsubext_noshift_patterns<"ADDww", add, GPR32wsp, extends_to_i32>;
444 defm : addsubext_noshift_patterns<"SUBxx", sub, GPR64xsp, extends_to_i64>;
445 defm : addsubext_noshift_patterns<"SUBww", sub, GPR32wsp, extends_to_i32>;
447 defm : addsubext_noshift_patterns<"CMNx", A64cmn, GPR64xsp, extends_to_i64>;
448 defm : addsubext_noshift_patterns<"CMNw", A64cmn, GPR32wsp, extends_to_i32>;
449 defm : addsubext_noshift_patterns<"CMPx", A64cmp, GPR64xsp, extends_to_i64>;
450 defm : addsubext_noshift_patterns<"CMPw", A64cmp, GPR32wsp, extends_to_i32>;
452 // An extend of "lsl #imm" is valid if and only if one of Rn and Rd is
453 // sp/wsp. It is synonymous with uxtx/uxtw depending on the size of the
454 // operation. Also permitted in this case is complete omission of the argument,
455 // which implies "lsl #0".
456 multiclass lsl_aliases<string asmop, Instruction inst, RegisterClass GPR_Rd,
457 RegisterClass GPR_Rn, RegisterClass GPR_Rm> {
458 def : InstAlias<!strconcat(asmop, " $Rd, $Rn, $Rm"),
459 (inst GPR_Rd:$Rd, GPR_Rn:$Rn, GPR_Rm:$Rm, 0)>;
461 def : InstAlias<!strconcat(asmop, " $Rd, $Rn, $Rm, $LSL"),
462 (inst GPR_Rd:$Rd, GPR_Rn:$Rn, GPR_Rm:$Rm, LSL_extoperand:$LSL)>;
466 defm : lsl_aliases<"add", ADDxxx_uxtx, Rxsp, GPR64xsp, GPR64>;
467 defm : lsl_aliases<"add", ADDxxx_uxtx, GPR64xsp, Rxsp, GPR64>;
468 defm : lsl_aliases<"add", ADDwww_uxtw, Rwsp, GPR32wsp, GPR32>;
469 defm : lsl_aliases<"add", ADDwww_uxtw, GPR32wsp, Rwsp, GPR32>;
470 defm : lsl_aliases<"sub", SUBxxx_uxtx, Rxsp, GPR64xsp, GPR64>;
471 defm : lsl_aliases<"sub", SUBxxx_uxtx, GPR64xsp, Rxsp, GPR64>;
472 defm : lsl_aliases<"sub", SUBwww_uxtw, Rwsp, GPR32wsp, GPR32>;
473 defm : lsl_aliases<"sub", SUBwww_uxtw, GPR32wsp, Rwsp, GPR32>;
475 // Rd cannot be sp for flag-setting variants so only half of the aliases are
477 defm : lsl_aliases<"adds", ADDSxxx_uxtx, GPR64, Rxsp, GPR64>;
478 defm : lsl_aliases<"adds", ADDSwww_uxtw, GPR32, Rwsp, GPR32>;
479 defm : lsl_aliases<"subs", SUBSxxx_uxtx, GPR64, Rxsp, GPR64>;
480 defm : lsl_aliases<"subs", SUBSwww_uxtw, GPR32, Rwsp, GPR32>;
482 // CMP unfortunately has to be different because the instruction doesn't have a
484 multiclass cmp_lsl_aliases<string asmop, Instruction inst,
485 RegisterClass GPR_Rn, RegisterClass GPR_Rm> {
486 def : InstAlias<!strconcat(asmop, " $Rn, $Rm"),
487 (inst GPR_Rn:$Rn, GPR_Rm:$Rm, 0)>;
489 def : InstAlias<!strconcat(asmop, " $Rn, $Rm, $LSL"),
490 (inst GPR_Rn:$Rn, GPR_Rm:$Rm, LSL_extoperand:$LSL)>;
493 defm : cmp_lsl_aliases<"cmp", CMPxx_uxtx, Rxsp, GPR64>;
494 defm : cmp_lsl_aliases<"cmp", CMPww_uxtw, Rwsp, GPR32>;
495 defm : cmp_lsl_aliases<"cmn", CMNxx_uxtx, Rxsp, GPR64>;
496 defm : cmp_lsl_aliases<"cmn", CMNww_uxtw, Rwsp, GPR32>;
498 //===----------------------------------------------------------------------===//
499 // Add-subtract (immediate) instructions
500 //===----------------------------------------------------------------------===//
501 // Contains: ADD, ADDS, SUB, SUBS + aliases CMN, CMP, MOV
503 // These instructions accept a 12-bit unsigned immediate, optionally shifted
504 // left by 12 bits. Official assembly format specifies a 12 bit immediate with
505 // one of "", "LSL #0", "LSL #12" supplementary operands.
507 // There are surprisingly few ways to make this work with TableGen, so this
508 // implementation has separate instructions for the "LSL #0" and "LSL #12"
511 // If the MCInst retained a single combined immediate (which could be 0x123000,
512 // for example) then both components (imm & shift) would have to be delegated to
513 // a single assembly operand. This would entail a separate operand parser
514 // (because the LSL would have to live in the same AArch64Operand as the
515 // immediate to be accessible); assembly parsing is rather complex and
516 // error-prone C++ code.
518 // By splitting the immediate, we can delegate handling this optional operand to
519 // an InstAlias. Supporting functions to generate the correct MCInst are still
520 // required, but these are essentially trivial and parsing can remain generic.
522 // Rejected plans with rationale:
523 // ------------------------------
525 // In an ideal world you'de have two first class immediate operands (in
526 // InOperandList, specifying imm12 and shift). Unfortunately this is not
527 // selectable by any means I could discover.
529 // An Instruction with two MCOperands hidden behind a single entry in
530 // InOperandList (expanded by ComplexPatterns and MIOperandInfo) was functional,
531 // but required more C++ code to handle encoding/decoding. Parsing (the intended
532 // main beneficiary) ended up equally complex because of the optional nature of
535 // Attempting to circumvent the need for a custom OperandParser above by giving
536 // InstAliases without the "lsl #0" failed. add/sub could be accommodated but
537 // the cmp/cmn aliases didn't use the MIOperandInfo to determine how operands
538 // should be parsed: there was no way to accommodate an "lsl #12".
540 let ParserMethod = "ParseImmWithLSLOperand",
541 RenderMethod = "addImmWithLSLOperands" in {
542 // Derived PredicateMethod fields are different for each
543 def addsubimm_lsl0_asmoperand : AsmOperandClass {
544 let Name = "AddSubImmLSL0";
545 // If an error is reported against this operand, instruction could also be a
547 let DiagnosticType = "AddSubSecondSource";
550 def addsubimm_lsl12_asmoperand : AsmOperandClass {
551 let Name = "AddSubImmLSL12";
552 let DiagnosticType = "AddSubSecondSource";
556 def shr_12_XFORM : SDNodeXForm<imm, [{
557 return CurDAG->getTargetConstant(N->getSExtValue() >> 12, MVT::i32);
560 def shr_12_neg_XFORM : SDNodeXForm<imm, [{
561 return CurDAG->getTargetConstant((-N->getSExtValue()) >> 12, MVT::i32);
564 def neg_XFORM : SDNodeXForm<imm, [{
565 return CurDAG->getTargetConstant(-N->getSExtValue(), MVT::i32);
569 multiclass addsub_imm_operands<ValueType ty> {
570 let PrintMethod = "printAddSubImmLSL0Operand",
571 EncoderMethod = "getAddSubImmOpValue",
572 ParserMatchClass = addsubimm_lsl0_asmoperand in {
573 def _posimm_lsl0 : Operand<ty>,
574 ImmLeaf<ty, [{ return Imm >= 0 && (Imm & ~0xfff) == 0; }]>;
575 def _negimm_lsl0 : Operand<ty>,
576 ImmLeaf<ty, [{ return Imm < 0 && (-Imm & ~0xfff) == 0; }],
580 let PrintMethod = "printAddSubImmLSL12Operand",
581 EncoderMethod = "getAddSubImmOpValue",
582 ParserMatchClass = addsubimm_lsl12_asmoperand in {
583 def _posimm_lsl12 : Operand<ty>,
584 ImmLeaf<ty, [{ return Imm >= 0 && (Imm & ~0xfff000) == 0; }],
587 def _negimm_lsl12 : Operand<ty>,
588 ImmLeaf<ty, [{ return Imm < 0 && (-Imm & ~0xfff000) == 0; }],
593 // The add operands don't need any transformation
594 defm addsubimm_operand_i32 : addsub_imm_operands<i32>;
595 defm addsubimm_operand_i64 : addsub_imm_operands<i64>;
597 multiclass addsubimm_varieties<string prefix, bit sf, bit op, bits<2> shift,
598 string asmop, string cmpasmop,
599 Operand imm_operand, Operand cmp_imm_operand,
600 RegisterClass GPR, RegisterClass GPRsp,
602 // All registers for non-S variants allow SP
603 def _s : A64I_addsubimm<sf, op, 0b0, shift,
605 (ins GPRsp:$Rn, imm_operand:$Imm12),
606 !strconcat(asmop, "\t$Rd, $Rn, $Imm12"),
608 (add GPRsp:$Rn, imm_operand:$Imm12))],
612 // S variants can read SP but would write to ZR
613 def _S : A64I_addsubimm<sf, op, 0b1, shift,
615 (ins GPRsp:$Rn, imm_operand:$Imm12),
616 !strconcat(asmop, "s\t$Rd, $Rn, $Imm12"),
617 [(set GPR:$Rd, (addc GPRsp:$Rn, imm_operand:$Imm12))],
622 // Note that the pattern here for ADDS is subtle. Canonically CMP
623 // a, b becomes SUBS a, b. If b < 0 then this is equivalent to
624 // ADDS a, (-b). This is not true in general.
625 def _cmp : A64I_addsubimm<sf, op, 0b1, shift,
626 (outs), (ins GPRsp:$Rn, imm_operand:$Imm12),
627 !strconcat(cmpasmop, " $Rn, $Imm12"),
629 (A64cmp GPRsp:$Rn, cmp_imm_operand:$Imm12))],
638 multiclass addsubimm_shifts<string prefix, bit sf, bit op,
639 string asmop, string cmpasmop, string operand, string cmpoperand,
640 RegisterClass GPR, RegisterClass GPRsp, AArch64Reg ZR> {
641 defm _lsl0 : addsubimm_varieties<prefix # "_lsl0", sf, op, 0b00,
643 !cast<Operand>(operand # "_lsl0"),
644 !cast<Operand>(cmpoperand # "_lsl0"),
647 defm _lsl12 : addsubimm_varieties<prefix # "_lsl12", sf, op, 0b01,
649 !cast<Operand>(operand # "_lsl12"),
650 !cast<Operand>(cmpoperand # "_lsl12"),
654 defm ADDwwi : addsubimm_shifts<"ADDwi", 0b0, 0b0, "add", "cmn",
655 "addsubimm_operand_i32_posimm",
656 "addsubimm_operand_i32_negimm",
657 GPR32, GPR32wsp, WZR>;
658 defm ADDxxi : addsubimm_shifts<"ADDxi", 0b1, 0b0, "add", "cmn",
659 "addsubimm_operand_i64_posimm",
660 "addsubimm_operand_i64_negimm",
661 GPR64, GPR64xsp, XZR>;
662 defm SUBwwi : addsubimm_shifts<"SUBwi", 0b0, 0b1, "sub", "cmp",
663 "addsubimm_operand_i32_negimm",
664 "addsubimm_operand_i32_posimm",
665 GPR32, GPR32wsp, WZR>;
666 defm SUBxxi : addsubimm_shifts<"SUBxi", 0b1, 0b1, "sub", "cmp",
667 "addsubimm_operand_i64_negimm",
668 "addsubimm_operand_i64_posimm",
669 GPR64, GPR64xsp, XZR>;
671 multiclass MOVsp<RegisterClass GPRsp, RegisterClass SP, Instruction addop> {
672 def _fromsp : InstAlias<"mov $Rd, $Rn",
673 (addop GPRsp:$Rd, SP:$Rn, 0),
676 def _tosp : InstAlias<"mov $Rd, $Rn",
677 (addop SP:$Rd, GPRsp:$Rn, 0),
681 // Recall Rxsp is a RegisterClass containing *just* xsp.
682 defm MOVxx : MOVsp<GPR64xsp, Rxsp, ADDxxi_lsl0_s>;
683 defm MOVww : MOVsp<GPR32wsp, Rwsp, ADDwwi_lsl0_s>;
685 //===----------------------------------------------------------------------===//
686 // Add-subtract (shifted register) instructions
687 //===----------------------------------------------------------------------===//
688 // Contains: ADD, ADDS, SUB, SUBS + aliases CMN, CMP, NEG, NEGS
690 //===-------------------------------
691 // 1. The "shifed register" operands. Shared with logical insts.
692 //===-------------------------------
694 multiclass shift_operands<string prefix, string form> {
695 def _asmoperand_i32 : AsmOperandClass {
696 let Name = "Shift" # form # "i32";
697 let RenderMethod = "addShiftOperands";
698 let PredicateMethod = "isShift<A64SE::" # form # ", false>";
699 let DiagnosticType = "AddSubRegShift32";
702 // Note that the operand type is intentionally i64 because the DAGCombiner
703 // puts these into a canonical form.
704 def _i32 : Operand<i64>, ImmLeaf<i64, [{ return Imm >= 0 && Imm <= 31; }]> {
706 = !cast<AsmOperandClass>(prefix # "_asmoperand_i32");
707 let PrintMethod = "printShiftOperand<A64SE::" # form # ">";
708 let DecoderMethod = "Decode32BitShiftOperand";
711 def _asmoperand_i64 : AsmOperandClass {
712 let Name = "Shift" # form # "i64";
713 let RenderMethod = "addShiftOperands";
714 let PredicateMethod = "isShift<A64SE::" # form # ", true>";
715 let DiagnosticType = "AddSubRegShift64";
718 def _i64 : Operand<i64>, ImmLeaf<i64, [{ return Imm >= 0 && Imm <= 63; }]> {
720 = !cast<AsmOperandClass>(prefix # "_asmoperand_i64");
721 let PrintMethod = "printShiftOperand<A64SE::" # form # ">";
725 defm lsl_operand : shift_operands<"lsl_operand", "LSL">;
726 defm lsr_operand : shift_operands<"lsr_operand", "LSR">;
727 defm asr_operand : shift_operands<"asr_operand", "ASR">;
729 // Not used for add/sub, but defined here for completeness. The "logical
730 // (shifted register)" instructions *do* have an ROR variant.
731 defm ror_operand : shift_operands<"ror_operand", "ROR">;
733 //===-------------------------------
734 // 2. The basic 3.5-operand ADD/SUB/ADDS/SUBS instructions.
735 //===-------------------------------
737 // N.b. the commutable parameter is just !N. It will be first against the wall
738 // when the revolution comes.
739 multiclass addsub_shifts<string prefix, bit sf, bit op, bit s, bit commutable,
740 string asmop, SDPatternOperator opfrag, string sty,
741 RegisterClass GPR, list<Register> defs> {
742 let isCommutable = commutable, Defs = defs in {
743 def _lsl : A64I_addsubshift<sf, op, s, 0b00,
745 (ins GPR:$Rn, GPR:$Rm,
746 !cast<Operand>("lsl_operand_" # sty):$Imm6),
747 !strconcat(asmop, "\t$Rd, $Rn, $Rm, $Imm6"),
748 [(set GPR:$Rd, (opfrag GPR:$Rn, (shl GPR:$Rm,
749 !cast<Operand>("lsl_operand_" # sty):$Imm6))
753 def _lsr : A64I_addsubshift<sf, op, s, 0b01,
755 (ins GPR:$Rn, GPR:$Rm,
756 !cast<Operand>("lsr_operand_" # sty):$Imm6),
757 !strconcat(asmop, "\t$Rd, $Rn, $Rm, $Imm6"),
758 [(set GPR:$Rd, (opfrag GPR:$Rn, (srl GPR:$Rm,
759 !cast<Operand>("lsr_operand_" # sty):$Imm6))
763 def _asr : A64I_addsubshift<sf, op, s, 0b10,
765 (ins GPR:$Rn, GPR:$Rm,
766 !cast<Operand>("asr_operand_" # sty):$Imm6),
767 !strconcat(asmop, "\t$Rd, $Rn, $Rm, $Imm6"),
768 [(set GPR:$Rd, (opfrag GPR:$Rn, (sra GPR:$Rm,
769 !cast<Operand>("asr_operand_" # sty):$Imm6))
775 : InstAlias<!strconcat(asmop, " $Rd, $Rn, $Rm"),
776 (!cast<Instruction>(prefix # "_lsl") GPR:$Rd, GPR:$Rn,
779 def : Pat<(opfrag GPR:$Rn, GPR:$Rm),
780 (!cast<Instruction>(prefix # "_lsl") GPR:$Rn, GPR:$Rm, 0)>;
783 multiclass addsub_sizes<string prefix, bit op, bit s, bit commutable,
784 string asmop, SDPatternOperator opfrag,
785 list<Register> defs> {
786 defm xxx : addsub_shifts<prefix # "xxx", 0b1, op, s,
787 commutable, asmop, opfrag, "i64", GPR64, defs>;
788 defm www : addsub_shifts<prefix # "www", 0b0, op, s,
789 commutable, asmop, opfrag, "i32", GPR32, defs>;
793 defm ADD : addsub_sizes<"ADD", 0b0, 0b0, 0b1, "add", add, []>;
794 defm SUB : addsub_sizes<"SUB", 0b1, 0b0, 0b0, "sub", sub, []>;
796 defm ADDS : addsub_sizes<"ADDS", 0b0, 0b1, 0b1, "adds", addc, [NZCV]>;
797 defm SUBS : addsub_sizes<"SUBS", 0b1, 0b1, 0b0, "subs", subc, [NZCV]>;
799 //===-------------------------------
800 // 1. The NEG/NEGS aliases
801 //===-------------------------------
803 multiclass neg_alias<Instruction INST, RegisterClass GPR,
804 Register ZR, Operand shift_operand, SDNode shiftop> {
805 def : InstAlias<"neg $Rd, $Rm, $Imm6",
806 (INST GPR:$Rd, ZR, GPR:$Rm, shift_operand:$Imm6)>;
808 def : Pat<(sub 0, (shiftop GPR:$Rm, shift_operand:$Imm6)),
809 (INST ZR, GPR:$Rm, shift_operand:$Imm6)>;
812 defm : neg_alias<SUBwww_lsl, GPR32, WZR, lsl_operand_i32, shl>;
813 defm : neg_alias<SUBwww_lsr, GPR32, WZR, lsr_operand_i32, srl>;
814 defm : neg_alias<SUBwww_asr, GPR32, WZR, asr_operand_i32, sra>;
815 def : InstAlias<"neg $Rd, $Rm", (SUBwww_lsl GPR32:$Rd, WZR, GPR32:$Rm, 0)>;
816 def : Pat<(sub 0, GPR32:$Rm), (SUBwww_lsl WZR, GPR32:$Rm, 0)>;
818 defm : neg_alias<SUBxxx_lsl, GPR64, XZR, lsl_operand_i64, shl>;
819 defm : neg_alias<SUBxxx_lsr, GPR64, XZR, lsr_operand_i64, srl>;
820 defm : neg_alias<SUBxxx_asr, GPR64, XZR, asr_operand_i64, sra>;
821 def : InstAlias<"neg $Rd, $Rm", (SUBxxx_lsl GPR64:$Rd, XZR, GPR64:$Rm, 0)>;
822 def : Pat<(sub 0, GPR64:$Rm), (SUBxxx_lsl XZR, GPR64:$Rm, 0)>;
824 // NEGS doesn't get any patterns yet: defining multiple outputs means C++ has to
826 class negs_alias<Instruction INST, RegisterClass GPR,
827 Register ZR, Operand shift_operand, SDNode shiftop>
828 : InstAlias<"negs $Rd, $Rm, $Imm6",
829 (INST GPR:$Rd, ZR, GPR:$Rm, shift_operand:$Imm6)>;
831 def : negs_alias<SUBSwww_lsl, GPR32, WZR, lsl_operand_i32, shl>;
832 def : negs_alias<SUBSwww_lsr, GPR32, WZR, lsr_operand_i32, srl>;
833 def : negs_alias<SUBSwww_asr, GPR32, WZR, asr_operand_i32, sra>;
834 def : InstAlias<"negs $Rd, $Rm", (SUBSwww_lsl GPR32:$Rd, WZR, GPR32:$Rm, 0)>;
836 def : negs_alias<SUBSxxx_lsl, GPR64, XZR, lsl_operand_i64, shl>;
837 def : negs_alias<SUBSxxx_lsr, GPR64, XZR, lsr_operand_i64, srl>;
838 def : negs_alias<SUBSxxx_asr, GPR64, XZR, asr_operand_i64, sra>;
839 def : InstAlias<"negs $Rd, $Rm", (SUBSxxx_lsl GPR64:$Rd, XZR, GPR64:$Rm, 0)>;
841 //===-------------------------------
842 // 1. The CMP/CMN aliases
843 //===-------------------------------
845 multiclass cmp_shifts<string prefix, bit sf, bit op, bit commutable,
846 string asmop, SDPatternOperator opfrag, string sty,
848 let isCommutable = commutable, Rd = 0b11111, Defs = [NZCV] in {
849 def _lsl : A64I_addsubshift<sf, op, 0b1, 0b00,
851 (ins GPR:$Rn, GPR:$Rm,
852 !cast<Operand>("lsl_operand_" # sty):$Imm6),
853 !strconcat(asmop, "\t$Rn, $Rm, $Imm6"),
854 [(set NZCV, (opfrag GPR:$Rn, (shl GPR:$Rm,
855 !cast<Operand>("lsl_operand_" # sty):$Imm6))
859 def _lsr : A64I_addsubshift<sf, op, 0b1, 0b01,
861 (ins GPR:$Rn, GPR:$Rm,
862 !cast<Operand>("lsr_operand_" # sty):$Imm6),
863 !strconcat(asmop, "\t$Rn, $Rm, $Imm6"),
864 [(set NZCV, (opfrag GPR:$Rn, (srl GPR:$Rm,
865 !cast<Operand>("lsr_operand_" # sty):$Imm6))
869 def _asr : A64I_addsubshift<sf, op, 0b1, 0b10,
871 (ins GPR:$Rn, GPR:$Rm,
872 !cast<Operand>("asr_operand_" # sty):$Imm6),
873 !strconcat(asmop, "\t$Rn, $Rm, $Imm6"),
874 [(set NZCV, (opfrag GPR:$Rn, (sra GPR:$Rm,
875 !cast<Operand>("asr_operand_" # sty):$Imm6))
881 : InstAlias<!strconcat(asmop, " $Rn, $Rm"),
882 (!cast<Instruction>(prefix # "_lsl") GPR:$Rn, GPR:$Rm, 0)>;
884 def : Pat<(opfrag GPR:$Rn, GPR:$Rm),
885 (!cast<Instruction>(prefix # "_lsl") GPR:$Rn, GPR:$Rm, 0)>;
888 defm CMPww : cmp_shifts<"CMPww", 0b0, 0b1, 0b0, "cmp", A64cmp, "i32", GPR32>;
889 defm CMPxx : cmp_shifts<"CMPxx", 0b1, 0b1, 0b0, "cmp", A64cmp, "i64", GPR64>;
891 defm CMNww : cmp_shifts<"CMNww", 0b0, 0b0, 0b1, "cmn", A64cmn, "i32", GPR32>;
892 defm CMNxx : cmp_shifts<"CMNxx", 0b1, 0b0, 0b1, "cmn", A64cmn, "i64", GPR64>;
894 //===----------------------------------------------------------------------===//
895 // Add-subtract (with carry) instructions
896 //===----------------------------------------------------------------------===//
897 // Contains: ADC, ADCS, SBC, SBCS + aliases NGC, NGCS
899 multiclass A64I_addsubcarrySizes<bit op, bit s, string asmop> {
900 let Uses = [NZCV] in {
901 def www : A64I_addsubcarry<0b0, op, s, 0b000000,
902 (outs GPR32:$Rd), (ins GPR32:$Rn, GPR32:$Rm),
903 !strconcat(asmop, "\t$Rd, $Rn, $Rm"),
906 def xxx : A64I_addsubcarry<0b1, op, s, 0b000000,
907 (outs GPR64:$Rd), (ins GPR64:$Rn, GPR64:$Rm),
908 !strconcat(asmop, "\t$Rd, $Rn, $Rm"),
913 let isCommutable = 1 in {
914 defm ADC : A64I_addsubcarrySizes<0b0, 0b0, "adc">;
917 defm SBC : A64I_addsubcarrySizes<0b1, 0b0, "sbc">;
919 let Defs = [NZCV] in {
920 let isCommutable = 1 in {
921 defm ADCS : A64I_addsubcarrySizes<0b0, 0b1, "adcs">;
924 defm SBCS : A64I_addsubcarrySizes<0b1, 0b1, "sbcs">;
927 def : InstAlias<"ngc $Rd, $Rm", (SBCwww GPR32:$Rd, WZR, GPR32:$Rm)>;
928 def : InstAlias<"ngc $Rd, $Rm", (SBCxxx GPR64:$Rd, XZR, GPR64:$Rm)>;
929 def : InstAlias<"ngcs $Rd, $Rm", (SBCSwww GPR32:$Rd, WZR, GPR32:$Rm)>;
930 def : InstAlias<"ngcs $Rd, $Rm", (SBCSxxx GPR64:$Rd, XZR, GPR64:$Rm)>;
932 // Note that adde and sube can form a chain longer than two (e.g. for 256-bit
933 // addition). So the flag-setting instructions are appropriate.
934 def : Pat<(adde GPR32:$Rn, GPR32:$Rm), (ADCSwww GPR32:$Rn, GPR32:$Rm)>;
935 def : Pat<(adde GPR64:$Rn, GPR64:$Rm), (ADCSxxx GPR64:$Rn, GPR64:$Rm)>;
936 def : Pat<(sube GPR32:$Rn, GPR32:$Rm), (SBCSwww GPR32:$Rn, GPR32:$Rm)>;
937 def : Pat<(sube GPR64:$Rn, GPR64:$Rm), (SBCSxxx GPR64:$Rn, GPR64:$Rm)>;
939 //===----------------------------------------------------------------------===//
941 //===----------------------------------------------------------------------===//
942 // Contains: SBFM, BFM, UBFM, [SU]XT[BHW], ASR, LSR, LSL, SBFI[ZX], BFI, BFXIL,
945 // Because of the rather complicated nearly-overlapping aliases, the decoding of
946 // this range of instructions is handled manually. The architectural
947 // instructions are BFM, SBFM and UBFM but a disassembler should never produce
950 // In the end, the best option was to use BFM instructions for decoding under
951 // almost all circumstances, but to create aliasing *Instructions* for each of
952 // the canonical forms and specify a completely custom decoder which would
953 // substitute the correct MCInst as needed.
955 // This also simplifies instruction selection, parsing etc because the MCInsts
956 // have a shape that's closer to their use in code.
958 //===-------------------------------
959 // 1. The architectural BFM instructions
960 //===-------------------------------
962 def uimm5_asmoperand : AsmOperandClass {
964 let PredicateMethod = "isUImm<5>";
965 let RenderMethod = "addImmOperands";
966 let DiagnosticType = "UImm5";
969 def uimm6_asmoperand : AsmOperandClass {
971 let PredicateMethod = "isUImm<6>";
972 let RenderMethod = "addImmOperands";
973 let DiagnosticType = "UImm6";
976 def bitfield32_imm : Operand<i64>,
977 ImmLeaf<i64, [{ return Imm >= 0 && Imm < 32; }]> {
978 let ParserMatchClass = uimm5_asmoperand;
980 let DecoderMethod = "DecodeBitfield32ImmOperand";
984 def bitfield64_imm : Operand<i64>,
985 ImmLeaf<i64, [{ return Imm >= 0 && Imm < 64; }]> {
986 let ParserMatchClass = uimm6_asmoperand;
988 // Default decoder works in 64-bit case: the 6-bit field can take any value.
991 multiclass A64I_bitfieldSizes<bits<2> opc, string asmop> {
992 def wwii : A64I_bitfield<0b0, opc, 0b0, (outs GPR32:$Rd),
993 (ins GPR32:$Rn, bitfield32_imm:$ImmR, bitfield32_imm:$ImmS),
994 !strconcat(asmop, "\t$Rd, $Rn, $ImmR, $ImmS"),
996 let DecoderMethod = "DecodeBitfieldInstruction";
999 def xxii : A64I_bitfield<0b1, opc, 0b1, (outs GPR64:$Rd),
1000 (ins GPR64:$Rn, bitfield64_imm:$ImmR, bitfield64_imm:$ImmS),
1001 !strconcat(asmop, "\t$Rd, $Rn, $ImmR, $ImmS"),
1003 let DecoderMethod = "DecodeBitfieldInstruction";
1007 defm SBFM : A64I_bitfieldSizes<0b00, "sbfm">;
1008 defm UBFM : A64I_bitfieldSizes<0b10, "ubfm">;
1010 // BFM instructions modify the destination register rather than defining it
1013 A64I_bitfield<0b0, 0b01, 0b0, (outs GPR32:$Rd),
1014 (ins GPR32:$src, GPR32:$Rn, bitfield32_imm:$ImmR, bitfield32_imm:$ImmS),
1015 "bfm\t$Rd, $Rn, $ImmR, $ImmS", [], NoItinerary> {
1016 let DecoderMethod = "DecodeBitfieldInstruction";
1017 let Constraints = "$src = $Rd";
1021 A64I_bitfield<0b1, 0b01, 0b1, (outs GPR64:$Rd),
1022 (ins GPR64:$src, GPR64:$Rn, bitfield64_imm:$ImmR, bitfield64_imm:$ImmS),
1023 "bfm\t$Rd, $Rn, $ImmR, $ImmS", [], NoItinerary> {
1024 let DecoderMethod = "DecodeBitfieldInstruction";
1025 let Constraints = "$src = $Rd";
1029 //===-------------------------------
1030 // 2. Extend aliases to 64-bit dest
1031 //===-------------------------------
1033 // Unfortunately the extensions that end up as 64-bits cannot be handled by an
1034 // instruction alias: their syntax is (for example) "SXTB x0, w0", which needs
1035 // to be mapped to "SBFM x0, x0, #0, 7" (changing the class of Rn). InstAlias is
1036 // not capable of such a map as far as I'm aware
1038 // Note that these instructions are strictly more specific than the
1039 // BFM ones (in ImmR) so they can handle their own decoding.
1040 class A64I_bf_ext<bit sf, bits<2> opc, RegisterClass GPRDest, string asmop,
1041 bits<6> imms, dag pattern>
1042 : A64I_bitfield<sf, opc, sf,
1043 (outs GPRDest:$Rd), (ins GPR32:$Rn),
1044 !strconcat(asmop, "\t$Rd, $Rn"),
1045 [(set GPRDest:$Rd, pattern)], NoItinerary> {
1046 let ImmR = 0b000000;
1050 // Signed extensions
1051 def SXTBxw : A64I_bf_ext<0b1, 0b00, GPR64, "sxtb", 7,
1052 (sext_inreg (anyext GPR32:$Rn), i8)>;
1053 def SXTBww : A64I_bf_ext<0b0, 0b00, GPR32, "sxtb", 7,
1054 (sext_inreg GPR32:$Rn, i8)>;
1055 def SXTHxw : A64I_bf_ext<0b1, 0b00, GPR64, "sxth", 15,
1056 (sext_inreg (anyext GPR32:$Rn), i16)>;
1057 def SXTHww : A64I_bf_ext<0b0, 0b00, GPR32, "sxth", 15,
1058 (sext_inreg GPR32:$Rn, i16)>;
1059 def SXTWxw : A64I_bf_ext<0b1, 0b00, GPR64, "sxtw", 31, (sext GPR32:$Rn)>;
1061 // Unsigned extensions
1062 def UXTBww : A64I_bf_ext<0b0, 0b10, GPR32, "uxtb", 7,
1063 (and GPR32:$Rn, 255)>;
1064 def UXTHww : A64I_bf_ext<0b0, 0b10, GPR32, "uxth", 15,
1065 (and GPR32:$Rn, 65535)>;
1067 // The 64-bit unsigned variants are not strictly architectural but recommended
1069 let isAsmParserOnly = 1 in {
1070 def UXTBxw : A64I_bf_ext<0b0, 0b10, GPR64, "uxtb", 7,
1071 (and (anyext GPR32:$Rn), 255)>;
1072 def UXTHxw : A64I_bf_ext<0b0, 0b10, GPR64, "uxth", 15,
1073 (and (anyext GPR32:$Rn), 65535)>;
1076 // Extra patterns for when the source register is actually 64-bits
1077 // too. There's no architectural difference here, it's just LLVM
1078 // shinanigans. There's no need for equivalent zero-extension patterns
1079 // because they'll already be caught by logical (immediate) matching.
1080 def : Pat<(sext_inreg GPR64:$Rn, i8),
1081 (SXTBxw (EXTRACT_SUBREG GPR64:$Rn, sub_32))>;
1082 def : Pat<(sext_inreg GPR64:$Rn, i16),
1083 (SXTHxw (EXTRACT_SUBREG GPR64:$Rn, sub_32))>;
1084 def : Pat<(sext_inreg GPR64:$Rn, i32),
1085 (SXTWxw (EXTRACT_SUBREG GPR64:$Rn, sub_32))>;
1088 //===-------------------------------
1089 // 3. Aliases for ASR and LSR (the simple shifts)
1090 //===-------------------------------
1092 // These also handle their own decoding because ImmS being set makes
1093 // them take precedence over BFM.
1094 multiclass A64I_shift<bits<2> opc, string asmop, SDNode opnode> {
1095 def wwi : A64I_bitfield<0b0, opc, 0b0,
1096 (outs GPR32:$Rd), (ins GPR32:$Rn, bitfield32_imm:$ImmR),
1097 !strconcat(asmop, "\t$Rd, $Rn, $ImmR"),
1098 [(set GPR32:$Rd, (opnode GPR32:$Rn, bitfield32_imm:$ImmR))],
1103 def xxi : A64I_bitfield<0b1, opc, 0b1,
1104 (outs GPR64:$Rd), (ins GPR64:$Rn, bitfield64_imm:$ImmR),
1105 !strconcat(asmop, "\t$Rd, $Rn, $ImmR"),
1106 [(set GPR64:$Rd, (opnode GPR64:$Rn, bitfield64_imm:$ImmR))],
1113 defm ASR : A64I_shift<0b00, "asr", sra>;
1114 defm LSR : A64I_shift<0b10, "lsr", srl>;
1116 //===-------------------------------
1117 // 4. Aliases for LSL
1118 //===-------------------------------
1120 // Unfortunately LSL and subsequent aliases are much more complicated. We need
1121 // to be able to say certain output instruction fields depend in a complex
1122 // manner on combinations of input assembly fields).
1124 // MIOperandInfo *might* have been able to do it, but at the cost of
1125 // significantly more C++ code.
1127 // N.b. contrary to usual practice these operands store the shift rather than
1128 // the machine bits in an MCInst. The complexity overhead of consistency
1129 // outweighed the benefits in this case (custom asmparser, printer and selection
1130 // vs custom encoder).
1131 def bitfield32_lsl_imm : Operand<i64>,
1132 ImmLeaf<i64, [{ return Imm >= 0 && Imm <= 31; }]> {
1133 let ParserMatchClass = uimm5_asmoperand;
1134 let EncoderMethod = "getBitfield32LSLOpValue";
1137 def bitfield64_lsl_imm : Operand<i64>,
1138 ImmLeaf<i64, [{ return Imm >= 0 && Imm <= 63; }]> {
1139 let ParserMatchClass = uimm6_asmoperand;
1140 let EncoderMethod = "getBitfield64LSLOpValue";
1143 class A64I_bitfield_lsl<bit sf, RegisterClass GPR, Operand operand>
1144 : A64I_bitfield<sf, 0b10, sf, (outs GPR:$Rd), (ins GPR:$Rn, operand:$FullImm),
1145 "lsl\t$Rd, $Rn, $FullImm",
1146 [(set GPR:$Rd, (shl GPR:$Rn, operand:$FullImm))],
1149 let ImmR = FullImm{5-0};
1150 let ImmS = FullImm{11-6};
1152 // No disassembler allowed because it would overlap with BFM which does the
1154 let isAsmParserOnly = 1;
1157 def LSLwwi : A64I_bitfield_lsl<0b0, GPR32, bitfield32_lsl_imm>;
1158 def LSLxxi : A64I_bitfield_lsl<0b1, GPR64, bitfield64_lsl_imm>;
1160 //===-------------------------------
1161 // 5. Aliases for bitfield extract instructions
1162 //===-------------------------------
1164 def bfx32_width_asmoperand : AsmOperandClass {
1165 let Name = "BFX32Width";
1166 let PredicateMethod = "isBitfieldWidth<32>";
1167 let RenderMethod = "addBFXWidthOperands";
1168 let DiagnosticType = "Width32";
1171 def bfx32_width : Operand<i64>, ImmLeaf<i64, [{ return true; }]> {
1172 let PrintMethod = "printBFXWidthOperand";
1173 let ParserMatchClass = bfx32_width_asmoperand;
1176 def bfx64_width_asmoperand : AsmOperandClass {
1177 let Name = "BFX64Width";
1178 let PredicateMethod = "isBitfieldWidth<64>";
1179 let RenderMethod = "addBFXWidthOperands";
1180 let DiagnosticType = "Width64";
1183 def bfx64_width : Operand<i64> {
1184 let PrintMethod = "printBFXWidthOperand";
1185 let ParserMatchClass = bfx64_width_asmoperand;
1189 multiclass A64I_bitfield_extract<bits<2> opc, string asmop, SDNode op> {
1190 def wwii : A64I_bitfield<0b0, opc, 0b0, (outs GPR32:$Rd),
1191 (ins GPR32:$Rn, bitfield32_imm:$ImmR, bfx32_width:$ImmS),
1192 !strconcat(asmop, "\t$Rd, $Rn, $ImmR, $ImmS"),
1193 [(set GPR32:$Rd, (op GPR32:$Rn, imm:$ImmR, imm:$ImmS))],
1195 // As above, no disassembler allowed.
1196 let isAsmParserOnly = 1;
1199 def xxii : A64I_bitfield<0b1, opc, 0b1, (outs GPR64:$Rd),
1200 (ins GPR64:$Rn, bitfield64_imm:$ImmR, bfx64_width:$ImmS),
1201 !strconcat(asmop, "\t$Rd, $Rn, $ImmR, $ImmS"),
1202 [(set GPR64:$Rd, (op GPR64:$Rn, imm:$ImmR, imm:$ImmS))],
1204 // As above, no disassembler allowed.
1205 let isAsmParserOnly = 1;
1209 defm SBFX : A64I_bitfield_extract<0b00, "sbfx", A64Sbfx>;
1210 defm UBFX : A64I_bitfield_extract<0b10, "ubfx", A64Ubfx>;
1212 // Again, variants based on BFM modify Rd so need it as an input too.
1213 def BFXILwwii : A64I_bitfield<0b0, 0b01, 0b0, (outs GPR32:$Rd),
1214 (ins GPR32:$src, GPR32:$Rn, bitfield32_imm:$ImmR, bfx32_width:$ImmS),
1215 "bfxil\t$Rd, $Rn, $ImmR, $ImmS", [], NoItinerary> {
1216 // As above, no disassembler allowed.
1217 let isAsmParserOnly = 1;
1218 let Constraints = "$src = $Rd";
1221 def BFXILxxii : A64I_bitfield<0b1, 0b01, 0b1, (outs GPR64:$Rd),
1222 (ins GPR64:$src, GPR64:$Rn, bitfield64_imm:$ImmR, bfx64_width:$ImmS),
1223 "bfxil\t$Rd, $Rn, $ImmR, $ImmS", [], NoItinerary> {
1224 // As above, no disassembler allowed.
1225 let isAsmParserOnly = 1;
1226 let Constraints = "$src = $Rd";
1229 // SBFX instructions can do a 1-instruction sign-extension of boolean values.
1230 def : Pat<(sext_inreg GPR64:$Rn, i1), (SBFXxxii GPR64:$Rn, 0, 0)>;
1231 def : Pat<(sext_inreg GPR32:$Rn, i1), (SBFXwwii GPR32:$Rn, 0, 0)>;
1232 def : Pat<(i64 (sext_inreg (anyext GPR32:$Rn), i1)),
1233 (SBFXxxii (SUBREG_TO_REG (i64 0), GPR32:$Rn, sub_32), 0, 0)>;
1235 // UBFX makes sense as an implementation of a 64-bit zero-extension too. Could
1236 // use either 64-bit or 32-bit variant, but 32-bit might be more efficient.
1237 def : Pat<(zext GPR32:$Rn), (SUBREG_TO_REG (i64 0), (UBFXwwii GPR32:$Rn, 0, 31),
1240 //===-------------------------------
1241 // 6. Aliases for bitfield insert instructions
1242 //===-------------------------------
1244 def bfi32_lsb_asmoperand : AsmOperandClass {
1245 let Name = "BFI32LSB";
1246 let PredicateMethod = "isUImm<5>";
1247 let RenderMethod = "addBFILSBOperands<32>";
1248 let DiagnosticType = "UImm5";
1251 def bfi32_lsb : Operand<i64>,
1252 ImmLeaf<i64, [{ return Imm >= 0 && Imm <= 31; }]> {
1253 let PrintMethod = "printBFILSBOperand<32>";
1254 let ParserMatchClass = bfi32_lsb_asmoperand;
1257 def bfi64_lsb_asmoperand : AsmOperandClass {
1258 let Name = "BFI64LSB";
1259 let PredicateMethod = "isUImm<6>";
1260 let RenderMethod = "addBFILSBOperands<64>";
1261 let DiagnosticType = "UImm6";
1264 def bfi64_lsb : Operand<i64>,
1265 ImmLeaf<i64, [{ return Imm >= 0 && Imm <= 63; }]> {
1266 let PrintMethod = "printBFILSBOperand<64>";
1267 let ParserMatchClass = bfi64_lsb_asmoperand;
1270 // Width verification is performed during conversion so width operand can be
1271 // shared between 32/64-bit cases. Still needed for the print method though
1272 // because ImmR encodes "width - 1".
1273 def bfi32_width_asmoperand : AsmOperandClass {
1274 let Name = "BFI32Width";
1275 let PredicateMethod = "isBitfieldWidth<32>";
1276 let RenderMethod = "addBFIWidthOperands";
1277 let DiagnosticType = "Width32";
1280 def bfi32_width : Operand<i64>,
1281 ImmLeaf<i64, [{ return Imm >= 1 && Imm <= 32; }]> {
1282 let PrintMethod = "printBFIWidthOperand";
1283 let ParserMatchClass = bfi32_width_asmoperand;
1286 def bfi64_width_asmoperand : AsmOperandClass {
1287 let Name = "BFI64Width";
1288 let PredicateMethod = "isBitfieldWidth<64>";
1289 let RenderMethod = "addBFIWidthOperands";
1290 let DiagnosticType = "Width64";
1293 def bfi64_width : Operand<i64>,
1294 ImmLeaf<i64, [{ return Imm >= 1 && Imm <= 64; }]> {
1295 let PrintMethod = "printBFIWidthOperand";
1296 let ParserMatchClass = bfi64_width_asmoperand;
1299 multiclass A64I_bitfield_insert<bits<2> opc, string asmop> {
1300 def wwii : A64I_bitfield<0b0, opc, 0b0, (outs GPR32:$Rd),
1301 (ins GPR32:$Rn, bfi32_lsb:$ImmR, bfi32_width:$ImmS),
1302 !strconcat(asmop, "\t$Rd, $Rn, $ImmR, $ImmS"),
1304 // As above, no disassembler allowed.
1305 let isAsmParserOnly = 1;
1308 def xxii : A64I_bitfield<0b1, opc, 0b1, (outs GPR64:$Rd),
1309 (ins GPR64:$Rn, bfi64_lsb:$ImmR, bfi64_width:$ImmS),
1310 !strconcat(asmop, "\t$Rd, $Rn, $ImmR, $ImmS"),
1312 // As above, no disassembler allowed.
1313 let isAsmParserOnly = 1;
1317 defm SBFIZ : A64I_bitfield_insert<0b00, "sbfiz">;
1318 defm UBFIZ : A64I_bitfield_insert<0b10, "ubfiz">;
1321 def BFIwwii : A64I_bitfield<0b0, 0b01, 0b0, (outs GPR32:$Rd),
1322 (ins GPR32:$src, GPR32:$Rn, bfi32_lsb:$ImmR, bfi32_width:$ImmS),
1323 "bfi\t$Rd, $Rn, $ImmR, $ImmS", [], NoItinerary> {
1324 // As above, no disassembler allowed.
1325 let isAsmParserOnly = 1;
1326 let Constraints = "$src = $Rd";
1329 def BFIxxii : A64I_bitfield<0b1, 0b01, 0b1, (outs GPR64:$Rd),
1330 (ins GPR64:$src, GPR64:$Rn, bfi64_lsb:$ImmR, bfi64_width:$ImmS),
1331 "bfi\t$Rd, $Rn, $ImmR, $ImmS", [], NoItinerary> {
1332 // As above, no disassembler allowed.
1333 let isAsmParserOnly = 1;
1334 let Constraints = "$src = $Rd";
1337 //===----------------------------------------------------------------------===//
1338 // Compare and branch (immediate)
1339 //===----------------------------------------------------------------------===//
1340 // Contains: CBZ, CBNZ
1342 class label_asmoperand<int width, int scale> : AsmOperandClass {
1343 let Name = "Label" # width # "_" # scale;
1344 let PredicateMethod = "isLabel<" # width # "," # scale # ">";
1345 let RenderMethod = "addLabelOperands<" # width # ", " # scale # ">";
1346 let DiagnosticType = "Label";
1349 def label_wid19_scal4_asmoperand : label_asmoperand<19, 4>;
1351 // All conditional immediate branches are the same really: 19 signed bits scaled
1352 // by the instruction-size (4).
1353 def bcc_target : Operand<OtherVT> {
1354 // This label is a 19-bit offset from PC, scaled by the instruction-width: 4.
1355 let ParserMatchClass = label_wid19_scal4_asmoperand;
1356 let PrintMethod = "printLabelOperand<19, 4>";
1357 let EncoderMethod = "getLabelOpValue<AArch64::fixup_a64_condbr>";
1358 let OperandType = "OPERAND_PCREL";
1361 multiclass cmpbr_sizes<bit op, string asmop, ImmLeaf SETOP> {
1362 let isBranch = 1, isTerminator = 1 in {
1363 def x : A64I_cmpbr<0b1, op,
1365 (ins GPR64:$Rt, bcc_target:$Label),
1366 !strconcat(asmop,"\t$Rt, $Label"),
1367 [(A64br_cc (A64cmp GPR64:$Rt, 0), SETOP, bb:$Label)],
1370 def w : A64I_cmpbr<0b0, op,
1372 (ins GPR32:$Rt, bcc_target:$Label),
1373 !strconcat(asmop,"\t$Rt, $Label"),
1374 [(A64br_cc (A64cmp GPR32:$Rt, 0), SETOP, bb:$Label)],
1379 defm CBZ : cmpbr_sizes<0b0, "cbz", ImmLeaf<i32, [{
1380 return Imm == A64CC::EQ;
1382 defm CBNZ : cmpbr_sizes<0b1, "cbnz", ImmLeaf<i32, [{
1383 return Imm == A64CC::NE;
1386 //===----------------------------------------------------------------------===//
1387 // Conditional branch (immediate) instructions
1388 //===----------------------------------------------------------------------===//
1391 def cond_code_asmoperand : AsmOperandClass {
1392 let Name = "CondCode";
1393 let DiagnosticType = "CondCode";
1396 def cond_code : Operand<i32>, ImmLeaf<i32, [{
1397 return Imm >= 0 && Imm <= 15;
1399 let PrintMethod = "printCondCodeOperand";
1400 let ParserMatchClass = cond_code_asmoperand;
1403 def Bcc : A64I_condbr<0b0, 0b0, (outs),
1404 (ins cond_code:$Cond, bcc_target:$Label),
1405 "b.$Cond $Label", [(A64br_cc NZCV, (i32 imm:$Cond), bb:$Label)],
1409 let isTerminator = 1;
1412 //===----------------------------------------------------------------------===//
1413 // Conditional compare (immediate) instructions
1414 //===----------------------------------------------------------------------===//
1415 // Contains: CCMN, CCMP
1417 def uimm4_asmoperand : AsmOperandClass {
1419 let PredicateMethod = "isUImm<4>";
1420 let RenderMethod = "addImmOperands";
1421 let DiagnosticType = "UImm4";
1424 def uimm4 : Operand<i32> {
1425 let ParserMatchClass = uimm4_asmoperand;
1428 def uimm5 : Operand<i32> {
1429 let ParserMatchClass = uimm5_asmoperand;
1432 // The only difference between this operand and the one for instructions like
1433 // B.cc is that it's parsed manually. The other get parsed implicitly as part of
1434 // the mnemonic handling.
1435 def cond_code_op_asmoperand : AsmOperandClass {
1436 let Name = "CondCodeOp";
1437 let RenderMethod = "addCondCodeOperands";
1438 let PredicateMethod = "isCondCode";
1439 let ParserMethod = "ParseCondCodeOperand";
1440 let DiagnosticType = "CondCode";
1443 def cond_code_op : Operand<i32> {
1444 let PrintMethod = "printCondCodeOperand";
1445 let ParserMatchClass = cond_code_op_asmoperand;
1448 class A64I_condcmpimmImpl<bit sf, bit op, RegisterClass GPR, string asmop>
1449 : A64I_condcmpimm<sf, op, 0b0, 0b0, 0b1, (outs),
1450 (ins GPR:$Rn, uimm5:$UImm5, uimm4:$NZCVImm, cond_code_op:$Cond),
1451 !strconcat(asmop, "\t$Rn, $UImm5, $NZCVImm, $Cond"),
1456 def CCMNwi : A64I_condcmpimmImpl<0b0, 0b0, GPR32, "ccmn">;
1457 def CCMNxi : A64I_condcmpimmImpl<0b1, 0b0, GPR64, "ccmn">;
1458 def CCMPwi : A64I_condcmpimmImpl<0b0, 0b1, GPR32, "ccmp">;
1459 def CCMPxi : A64I_condcmpimmImpl<0b1, 0b1, GPR64, "ccmp">;
1461 //===----------------------------------------------------------------------===//
1462 // Conditional compare (register) instructions
1463 //===----------------------------------------------------------------------===//
1464 // Contains: CCMN, CCMP
1466 class A64I_condcmpregImpl<bit sf, bit op, RegisterClass GPR, string asmop>
1467 : A64I_condcmpreg<sf, op, 0b0, 0b0, 0b1,
1469 (ins GPR:$Rn, GPR:$Rm, uimm4:$NZCVImm, cond_code_op:$Cond),
1470 !strconcat(asmop, "\t$Rn, $Rm, $NZCVImm, $Cond"),
1475 def CCMNww : A64I_condcmpregImpl<0b0, 0b0, GPR32, "ccmn">;
1476 def CCMNxx : A64I_condcmpregImpl<0b1, 0b0, GPR64, "ccmn">;
1477 def CCMPww : A64I_condcmpregImpl<0b0, 0b1, GPR32, "ccmp">;
1478 def CCMPxx : A64I_condcmpregImpl<0b1, 0b1, GPR64, "ccmp">;
1480 //===----------------------------------------------------------------------===//
1481 // Conditional select instructions
1482 //===----------------------------------------------------------------------===//
1483 // Contains: CSEL, CSINC, CSINV, CSNEG + aliases CSET, CSETM, CINC, CINV, CNEG
1485 // Condition code which is encoded as the inversion (semantically rather than
1486 // bitwise) in the instruction.
1487 def inv_cond_code_op_asmoperand : AsmOperandClass {
1488 let Name = "InvCondCodeOp";
1489 let RenderMethod = "addInvCondCodeOperands";
1490 let PredicateMethod = "isCondCode";
1491 let ParserMethod = "ParseCondCodeOperand";
1492 let DiagnosticType = "CondCode";
1495 def inv_cond_code_op : Operand<i32> {
1496 let ParserMatchClass = inv_cond_code_op_asmoperand;
1499 // Having a separate operand for the selectable use-case is debatable, but gives
1500 // consistency with cond_code.
1501 def inv_cond_XFORM : SDNodeXForm<imm, [{
1502 A64CC::CondCodes CC = static_cast<A64CC::CondCodes>(N->getZExtValue());
1503 return CurDAG->getTargetConstant(A64InvertCondCode(CC), MVT::i32);
1507 : ImmLeaf<i32, [{ return Imm >= 0 && Imm <= 15; }], inv_cond_XFORM>;
1510 multiclass A64I_condselSizes<bit op, bits<2> op2, string asmop,
1511 SDPatternOperator select> {
1512 let Uses = [NZCV] in {
1513 def wwwc : A64I_condsel<0b0, op, 0b0, op2,
1515 (ins GPR32:$Rn, GPR32:$Rm, cond_code_op:$Cond),
1516 !strconcat(asmop, "\t$Rd, $Rn, $Rm, $Cond"),
1517 [(set GPR32:$Rd, (select GPR32:$Rn, GPR32:$Rm))],
1521 def xxxc : A64I_condsel<0b1, op, 0b0, op2,
1523 (ins GPR64:$Rn, GPR64:$Rm, cond_code_op:$Cond),
1524 !strconcat(asmop, "\t$Rd, $Rn, $Rm, $Cond"),
1525 [(set GPR64:$Rd, (select GPR64:$Rn, GPR64:$Rm))],
1531 : PatFrag<(ops node:$lhs, node:$rhs),
1532 (A64select_cc NZCV, node:$lhs, node:$rhs, (i32 imm:$Cond))>;
1534 class complex_select<SDPatternOperator opnode>
1535 : PatFrag<(ops node:$lhs, node:$rhs),
1536 (A64select_cc NZCV, node:$lhs, (opnode node:$rhs), (i32 imm:$Cond))>;
1539 defm CSEL : A64I_condselSizes<0b0, 0b00, "csel", simple_select>;
1540 defm CSINC : A64I_condselSizes<0b0, 0b01, "csinc",
1541 complex_select<PatFrag<(ops node:$val),
1542 (add node:$val, 1)>>>;
1543 defm CSINV : A64I_condselSizes<0b1, 0b00, "csinv", complex_select<not>>;
1544 defm CSNEG : A64I_condselSizes<0b1, 0b01, "csneg", complex_select<ineg>>;
1546 // Now the instruction aliases, which fit nicely into LLVM's model:
1548 def : InstAlias<"cset $Rd, $Cond",
1549 (CSINCwwwc GPR32:$Rd, WZR, WZR, inv_cond_code_op:$Cond)>;
1550 def : InstAlias<"cset $Rd, $Cond",
1551 (CSINCxxxc GPR64:$Rd, XZR, XZR, inv_cond_code_op:$Cond)>;
1552 def : InstAlias<"csetm $Rd, $Cond",
1553 (CSINVwwwc GPR32:$Rd, WZR, WZR, inv_cond_code_op:$Cond)>;
1554 def : InstAlias<"csetm $Rd, $Cond",
1555 (CSINVxxxc GPR64:$Rd, XZR, XZR, inv_cond_code_op:$Cond)>;
1556 def : InstAlias<"cinc $Rd, $Rn, $Cond",
1557 (CSINCwwwc GPR32:$Rd, GPR32:$Rn, GPR32:$Rn, inv_cond_code_op:$Cond)>;
1558 def : InstAlias<"cinc $Rd, $Rn, $Cond",
1559 (CSINCxxxc GPR64:$Rd, GPR64:$Rn, GPR64:$Rn, inv_cond_code_op:$Cond)>;
1560 def : InstAlias<"cinv $Rd, $Rn, $Cond",
1561 (CSINVwwwc GPR32:$Rd, GPR32:$Rn, GPR32:$Rn, inv_cond_code_op:$Cond)>;
1562 def : InstAlias<"cinv $Rd, $Rn, $Cond",
1563 (CSINVxxxc GPR64:$Rd, GPR64:$Rn, GPR64:$Rn, inv_cond_code_op:$Cond)>;
1564 def : InstAlias<"cneg $Rd, $Rn, $Cond",
1565 (CSNEGwwwc GPR32:$Rd, GPR32:$Rn, GPR32:$Rn, inv_cond_code_op:$Cond)>;
1566 def : InstAlias<"cneg $Rd, $Rn, $Cond",
1567 (CSNEGxxxc GPR64:$Rd, GPR64:$Rn, GPR64:$Rn, inv_cond_code_op:$Cond)>;
1569 // Finally some helper patterns.
1571 // For CSET (a.k.a. zero-extension of icmp)
1572 def : Pat<(A64select_cc NZCV, 0, 1, cond_code:$Cond),
1573 (CSINCwwwc WZR, WZR, cond_code:$Cond)>;
1574 def : Pat<(A64select_cc NZCV, 1, 0, inv_cond_code:$Cond),
1575 (CSINCwwwc WZR, WZR, inv_cond_code:$Cond)>;
1577 def : Pat<(A64select_cc NZCV, 0, 1, cond_code:$Cond),
1578 (CSINCxxxc XZR, XZR, cond_code:$Cond)>;
1579 def : Pat<(A64select_cc NZCV, 1, 0, inv_cond_code:$Cond),
1580 (CSINCxxxc XZR, XZR, inv_cond_code:$Cond)>;
1582 // For CSETM (a.k.a. sign-extension of icmp)
1583 def : Pat<(A64select_cc NZCV, 0, -1, cond_code:$Cond),
1584 (CSINVwwwc WZR, WZR, cond_code:$Cond)>;
1585 def : Pat<(A64select_cc NZCV, -1, 0, inv_cond_code:$Cond),
1586 (CSINVwwwc WZR, WZR, inv_cond_code:$Cond)>;
1588 def : Pat<(A64select_cc NZCV, 0, -1, cond_code:$Cond),
1589 (CSINVxxxc XZR, XZR, cond_code:$Cond)>;
1590 def : Pat<(A64select_cc NZCV, -1, 0, inv_cond_code:$Cond),
1591 (CSINVxxxc XZR, XZR, inv_cond_code:$Cond)>;
1593 // CINC, CINV and CNEG get dealt with automatically, which leaves the issue of
1594 // commutativity. The instructions are to complex for isCommutable to be used,
1595 // so we have to create the patterns manually:
1597 // No commutable pattern for CSEL since the commuted version is isomorphic.
1600 def :Pat<(A64select_cc NZCV, (add GPR32:$Rm, 1), GPR32:$Rn,
1601 inv_cond_code:$Cond),
1602 (CSINCwwwc GPR32:$Rn, GPR32:$Rm, inv_cond_code:$Cond)>;
1603 def :Pat<(A64select_cc NZCV, (add GPR64:$Rm, 1), GPR64:$Rn,
1604 inv_cond_code:$Cond),
1605 (CSINCxxxc GPR64:$Rn, GPR64:$Rm, inv_cond_code:$Cond)>;
1608 def :Pat<(A64select_cc NZCV, (not GPR32:$Rm), GPR32:$Rn, inv_cond_code:$Cond),
1609 (CSINVwwwc GPR32:$Rn, GPR32:$Rm, inv_cond_code:$Cond)>;
1610 def :Pat<(A64select_cc NZCV, (not GPR64:$Rm), GPR64:$Rn, inv_cond_code:$Cond),
1611 (CSINVxxxc GPR64:$Rn, GPR64:$Rm, inv_cond_code:$Cond)>;
1614 def :Pat<(A64select_cc NZCV, (ineg GPR32:$Rm), GPR32:$Rn, inv_cond_code:$Cond),
1615 (CSNEGwwwc GPR32:$Rn, GPR32:$Rm, inv_cond_code:$Cond)>;
1616 def :Pat<(A64select_cc NZCV, (ineg GPR64:$Rm), GPR64:$Rn, inv_cond_code:$Cond),
1617 (CSNEGxxxc GPR64:$Rn, GPR64:$Rm, inv_cond_code:$Cond)>;
1619 //===----------------------------------------------------------------------===//
1620 // Data Processing (1 source) instructions
1621 //===----------------------------------------------------------------------===//
1622 // Contains: RBIT, REV16, REV, REV32, CLZ, CLS.
1624 // We define an unary operator which always fails. We will use this to
1625 // define unary operators that cannot be matched.
1627 class A64I_dp_1src_impl<bit sf, bits<6> opcode, string asmop,
1628 list<dag> patterns, RegisterClass GPRrc,
1629 InstrItinClass itin>:
1634 !strconcat(asmop, "\t$Rd, $Rn"),
1640 multiclass A64I_dp_1src <bits<6> opcode, string asmop> {
1641 let neverHasSideEffects = 1 in {
1642 def ww : A64I_dp_1src_impl<0b0, opcode, asmop, [], GPR32, NoItinerary>;
1643 def xx : A64I_dp_1src_impl<0b1, opcode, asmop, [], GPR64, NoItinerary>;
1647 defm RBIT : A64I_dp_1src<0b000000, "rbit">;
1648 defm CLS : A64I_dp_1src<0b000101, "cls">;
1649 defm CLZ : A64I_dp_1src<0b000100, "clz">;
1651 def : Pat<(ctlz GPR32:$Rn), (CLZww GPR32:$Rn)>;
1652 def : Pat<(ctlz GPR64:$Rn), (CLZxx GPR64:$Rn)>;
1653 def : Pat<(ctlz_zero_undef GPR32:$Rn), (CLZww GPR32:$Rn)>;
1654 def : Pat<(ctlz_zero_undef GPR64:$Rn), (CLZxx GPR64:$Rn)>;
1656 def : Pat<(cttz GPR32:$Rn), (CLZww (RBITww GPR32:$Rn))>;
1657 def : Pat<(cttz GPR64:$Rn), (CLZxx (RBITxx GPR64:$Rn))>;
1658 def : Pat<(cttz_zero_undef GPR32:$Rn), (CLZww (RBITww GPR32:$Rn))>;
1659 def : Pat<(cttz_zero_undef GPR64:$Rn), (CLZxx (RBITxx GPR64:$Rn))>;
1662 def REVww : A64I_dp_1src_impl<0b0, 0b000010, "rev",
1663 [(set GPR32:$Rd, (bswap GPR32:$Rn))],
1664 GPR32, NoItinerary>;
1665 def REVxx : A64I_dp_1src_impl<0b1, 0b000011, "rev",
1666 [(set GPR64:$Rd, (bswap GPR64:$Rn))],
1667 GPR64, NoItinerary>;
1668 def REV32xx : A64I_dp_1src_impl<0b1, 0b000010, "rev32",
1669 [(set GPR64:$Rd, (bswap (rotr GPR64:$Rn, (i64 32))))],
1670 GPR64, NoItinerary>;
1671 def REV16ww : A64I_dp_1src_impl<0b0, 0b000001, "rev16",
1672 [(set GPR32:$Rd, (bswap (rotr GPR32:$Rn, (i64 16))))],
1675 def REV16xx : A64I_dp_1src_impl<0b1, 0b000001, "rev16", [], GPR64, NoItinerary>;
1677 //===----------------------------------------------------------------------===//
1678 // Data Processing (2 sources) instructions
1679 //===----------------------------------------------------------------------===//
1680 // Contains: CRC32C?[BHWX], UDIV, SDIV, LSLV, LSRV, ASRV, RORV + aliases LSL,
1684 class dp_2src_impl<bit sf, bits<6> opcode, string asmop, list<dag> patterns,
1685 RegisterClass GPRsp,
1686 InstrItinClass itin>:
1690 !strconcat(asmop, "\t$Rd, $Rn, $Rm"),
1692 (ins GPRsp:$Rn, GPRsp:$Rm),
1696 multiclass dp_2src_crc<bit c, string asmop> {
1697 def B_www : dp_2src_impl<0b0, {0, 1, 0, c, 0, 0},
1698 !strconcat(asmop, "b"), [], GPR32, NoItinerary>;
1699 def H_www : dp_2src_impl<0b0, {0, 1, 0, c, 0, 1},
1700 !strconcat(asmop, "h"), [], GPR32, NoItinerary>;
1701 def W_www : dp_2src_impl<0b0, {0, 1, 0, c, 1, 0},
1702 !strconcat(asmop, "w"), [], GPR32, NoItinerary>;
1703 def X_wwx : A64I_dp_2src<0b1, {0, 1, 0, c, 1, 1}, 0b0,
1704 !strconcat(asmop, "x\t$Rd, $Rn, $Rm"),
1705 (outs GPR32:$Rd), (ins GPR32:$Rn, GPR64:$Rm), [],
1709 multiclass dp_2src_zext <bits<6> opcode, string asmop, SDPatternOperator op> {
1710 def www : dp_2src_impl<0b0,
1714 (op GPR32:$Rn, (i64 (zext GPR32:$Rm))))],
1717 def xxx : dp_2src_impl<0b1,
1720 [(set GPR64:$Rd, (op GPR64:$Rn, GPR64:$Rm))],
1726 multiclass dp_2src <bits<6> opcode, string asmop, SDPatternOperator op> {
1727 def www : dp_2src_impl<0b0,
1730 [(set GPR32:$Rd, (op GPR32:$Rn, GPR32:$Rm))],
1733 def xxx : dp_2src_impl<0b1,
1736 [(set GPR64:$Rd, (op GPR64:$Rn, GPR64:$Rm))],
1741 // Here we define the data processing 2 source instructions.
1742 defm CRC32 : dp_2src_crc<0b0, "crc32">;
1743 defm CRC32C : dp_2src_crc<0b1, "crc32c">;
1745 defm UDIV : dp_2src<0b000010, "udiv", udiv>;
1746 defm SDIV : dp_2src<0b000011, "sdiv", sdiv>;
1748 defm LSLV : dp_2src_zext<0b001000, "lsl", shl>;
1749 defm LSRV : dp_2src_zext<0b001001, "lsr", srl>;
1750 defm ASRV : dp_2src_zext<0b001010, "asr", sra>;
1751 defm RORV : dp_2src_zext<0b001011, "ror", rotr>;
1753 // Extra patterns for an incoming 64-bit value for a 32-bit
1754 // operation. Since the LLVM operations are undefined (as in C) if the
1755 // RHS is out of range, it's perfectly permissible to discard the high
1756 // bits of the GPR64.
1757 def : Pat<(shl GPR32:$Rn, GPR64:$Rm),
1758 (LSLVwww GPR32:$Rn, (EXTRACT_SUBREG GPR64:$Rm, sub_32))>;
1759 def : Pat<(srl GPR32:$Rn, GPR64:$Rm),
1760 (LSRVwww GPR32:$Rn, (EXTRACT_SUBREG GPR64:$Rm, sub_32))>;
1761 def : Pat<(sra GPR32:$Rn, GPR64:$Rm),
1762 (ASRVwww GPR32:$Rn, (EXTRACT_SUBREG GPR64:$Rm, sub_32))>;
1763 def : Pat<(rotr GPR32:$Rn, GPR64:$Rm),
1764 (RORVwww GPR32:$Rn, (EXTRACT_SUBREG GPR64:$Rm, sub_32))>;
1766 // Here we define the aliases for the data processing 2 source instructions.
1767 def LSL_mnemonic : MnemonicAlias<"lslv", "lsl">;
1768 def LSR_mnemonic : MnemonicAlias<"lsrv", "lsr">;
1769 def ASR_menmonic : MnemonicAlias<"asrv", "asr">;
1770 def ROR_menmonic : MnemonicAlias<"rorv", "ror">;
1772 //===----------------------------------------------------------------------===//
1773 // Data Processing (3 sources) instructions
1774 //===----------------------------------------------------------------------===//
1775 // Contains: MADD, MSUB, SMADDL, SMSUBL, SMULH, UMADDL, UMSUBL, UMULH
1776 // + aliases MUL, MNEG, SMULL, SMNEGL, UMULL, UMNEGL
1778 class A64I_dp3_4operand<bit sf, bits<6> opcode, RegisterClass AccReg,
1779 RegisterClass SrcReg, string asmop, dag pattern>
1780 : A64I_dp3<sf, opcode,
1781 (outs AccReg:$Rd), (ins SrcReg:$Rn, SrcReg:$Rm, AccReg:$Ra),
1782 !strconcat(asmop, "\t$Rd, $Rn, $Rm, $Ra"),
1783 [(set AccReg:$Rd, pattern)], NoItinerary> {
1784 RegisterClass AccGPR = AccReg;
1785 RegisterClass SrcGPR = SrcReg;
1788 def MADDwwww : A64I_dp3_4operand<0b0, 0b000000, GPR32, GPR32, "madd",
1789 (add GPR32:$Ra, (mul GPR32:$Rn, GPR32:$Rm))>;
1790 def MADDxxxx : A64I_dp3_4operand<0b1, 0b000000, GPR64, GPR64, "madd",
1791 (add GPR64:$Ra, (mul GPR64:$Rn, GPR64:$Rm))>;
1793 def MSUBwwww : A64I_dp3_4operand<0b0, 0b000001, GPR32, GPR32, "msub",
1794 (sub GPR32:$Ra, (mul GPR32:$Rn, GPR32:$Rm))>;
1795 def MSUBxxxx : A64I_dp3_4operand<0b1, 0b000001, GPR64, GPR64, "msub",
1796 (sub GPR64:$Ra, (mul GPR64:$Rn, GPR64:$Rm))>;
1798 def SMADDLxwwx : A64I_dp3_4operand<0b1, 0b000010, GPR64, GPR32, "smaddl",
1799 (add GPR64:$Ra, (mul (i64 (sext GPR32:$Rn)), (sext GPR32:$Rm)))>;
1800 def SMSUBLxwwx : A64I_dp3_4operand<0b1, 0b000011, GPR64, GPR32, "smsubl",
1801 (sub GPR64:$Ra, (mul (i64 (sext GPR32:$Rn)), (sext GPR32:$Rm)))>;
1803 def UMADDLxwwx : A64I_dp3_4operand<0b1, 0b001010, GPR64, GPR32, "umaddl",
1804 (add GPR64:$Ra, (mul (i64 (zext GPR32:$Rn)), (zext GPR32:$Rm)))>;
1805 def UMSUBLxwwx : A64I_dp3_4operand<0b1, 0b001011, GPR64, GPR32, "umsubl",
1806 (sub GPR64:$Ra, (mul (i64 (zext GPR32:$Rn)), (zext GPR32:$Rm)))>;
1808 let isCommutable = 1, PostEncoderMethod = "fixMulHigh" in {
1809 def UMULHxxx : A64I_dp3<0b1, 0b001100, (outs GPR64:$Rd),
1810 (ins GPR64:$Rn, GPR64:$Rm),
1811 "umulh\t$Rd, $Rn, $Rm",
1812 [(set GPR64:$Rd, (mulhu GPR64:$Rn, GPR64:$Rm))],
1815 def SMULHxxx : A64I_dp3<0b1, 0b000100, (outs GPR64:$Rd),
1816 (ins GPR64:$Rn, GPR64:$Rm),
1817 "smulh\t$Rd, $Rn, $Rm",
1818 [(set GPR64:$Rd, (mulhs GPR64:$Rn, GPR64:$Rm))],
1822 multiclass A64I_dp3_3operand<string asmop, A64I_dp3_4operand INST,
1823 Register ZR, dag pattern> {
1824 def : InstAlias<asmop # " $Rd, $Rn, $Rm",
1825 (INST INST.AccGPR:$Rd, INST.SrcGPR:$Rn, INST.SrcGPR:$Rm, ZR)>;
1827 def : Pat<pattern, (INST INST.SrcGPR:$Rn, INST.SrcGPR:$Rm, ZR)>;
1830 defm : A64I_dp3_3operand<"mul", MADDwwww, WZR, (mul GPR32:$Rn, GPR32:$Rm)>;
1831 defm : A64I_dp3_3operand<"mul", MADDxxxx, XZR, (mul GPR64:$Rn, GPR64:$Rm)>;
1833 defm : A64I_dp3_3operand<"mneg", MSUBwwww, WZR,
1834 (sub 0, (mul GPR32:$Rn, GPR32:$Rm))>;
1835 defm : A64I_dp3_3operand<"mneg", MSUBxxxx, XZR,
1836 (sub 0, (mul GPR64:$Rn, GPR64:$Rm))>;
1838 defm : A64I_dp3_3operand<"smull", SMADDLxwwx, XZR,
1839 (mul (i64 (sext GPR32:$Rn)), (sext GPR32:$Rm))>;
1840 defm : A64I_dp3_3operand<"smnegl", SMSUBLxwwx, XZR,
1841 (sub 0, (mul (i64 (sext GPR32:$Rn)), (sext GPR32:$Rm)))>;
1843 defm : A64I_dp3_3operand<"umull", UMADDLxwwx, XZR,
1844 (mul (i64 (zext GPR32:$Rn)), (zext GPR32:$Rm))>;
1845 defm : A64I_dp3_3operand<"umnegl", UMSUBLxwwx, XZR,
1846 (sub 0, (mul (i64 (zext GPR32:$Rn)), (zext GPR32:$Rm)))>;
1849 //===----------------------------------------------------------------------===//
1850 // Exception generation
1851 //===----------------------------------------------------------------------===//
1852 // Contains: SVC, HVC, SMC, BRK, HLT, DCPS1, DCPS2, DCPS3
1854 def uimm16_asmoperand : AsmOperandClass {
1855 let Name = "UImm16";
1856 let PredicateMethod = "isUImm<16>";
1857 let RenderMethod = "addImmOperands";
1858 let DiagnosticType = "UImm16";
1861 def uimm16 : Operand<i32> {
1862 let ParserMatchClass = uimm16_asmoperand;
1865 class A64I_exceptImpl<bits<3> opc, bits<2> ll, string asmop>
1866 : A64I_exception<opc, 0b000, ll, (outs), (ins uimm16:$UImm16),
1867 !strconcat(asmop, "\t$UImm16"), [], NoItinerary> {
1869 let isTerminator = 1;
1872 def SVCi : A64I_exceptImpl<0b000, 0b01, "svc">;
1873 def HVCi : A64I_exceptImpl<0b000, 0b10, "hvc">;
1874 def SMCi : A64I_exceptImpl<0b000, 0b11, "smc">;
1875 def BRKi : A64I_exceptImpl<0b001, 0b00, "brk">;
1876 def HLTi : A64I_exceptImpl<0b010, 0b00, "hlt">;
1878 def DCPS1i : A64I_exceptImpl<0b101, 0b01, "dcps1">;
1879 def DCPS2i : A64I_exceptImpl<0b101, 0b10, "dcps2">;
1880 def DCPS3i : A64I_exceptImpl<0b101, 0b11, "dcps3">;
1882 // The immediate is optional for the DCPS instructions, defaulting to 0.
1883 def : InstAlias<"dcps1", (DCPS1i 0)>;
1884 def : InstAlias<"dcps2", (DCPS2i 0)>;
1885 def : InstAlias<"dcps3", (DCPS3i 0)>;
1887 //===----------------------------------------------------------------------===//
1888 // Extract (immediate)
1889 //===----------------------------------------------------------------------===//
1890 // Contains: EXTR + alias ROR
1892 def EXTRwwwi : A64I_extract<0b0, 0b000, 0b0,
1894 (ins GPR32:$Rn, GPR32:$Rm, bitfield32_imm:$LSB),
1895 "extr\t$Rd, $Rn, $Rm, $LSB",
1897 (A64Extr GPR32:$Rn, GPR32:$Rm, imm:$LSB))],
1899 def EXTRxxxi : A64I_extract<0b1, 0b000, 0b1,
1901 (ins GPR64:$Rn, GPR64:$Rm, bitfield64_imm:$LSB),
1902 "extr\t$Rd, $Rn, $Rm, $LSB",
1904 (A64Extr GPR64:$Rn, GPR64:$Rm, imm:$LSB))],
1907 def : InstAlias<"ror $Rd, $Rs, $LSB",
1908 (EXTRwwwi GPR32:$Rd, GPR32:$Rs, GPR32:$Rs, bitfield32_imm:$LSB)>;
1909 def : InstAlias<"ror $Rd, $Rs, $LSB",
1910 (EXTRxxxi GPR64:$Rd, GPR64:$Rs, GPR64:$Rs, bitfield64_imm:$LSB)>;
1912 def : Pat<(rotr GPR32:$Rn, bitfield32_imm:$LSB),
1913 (EXTRwwwi GPR32:$Rn, GPR32:$Rn, bitfield32_imm:$LSB)>;
1914 def : Pat<(rotr GPR64:$Rn, bitfield64_imm:$LSB),
1915 (EXTRxxxi GPR64:$Rn, GPR64:$Rn, bitfield64_imm:$LSB)>;
1917 //===----------------------------------------------------------------------===//
1918 // Floating-point compare instructions
1919 //===----------------------------------------------------------------------===//
1920 // Contains: FCMP, FCMPE
1922 def fpzero_asmoperand : AsmOperandClass {
1923 let Name = "FPZero";
1924 let ParserMethod = "ParseFPImmOperand";
1925 let DiagnosticType = "FPZero";
1928 def fpz32 : Operand<f32>,
1929 ComplexPattern<f32, 1, "SelectFPZeroOperand", [fpimm]> {
1930 let ParserMatchClass = fpzero_asmoperand;
1931 let PrintMethod = "printFPZeroOperand";
1934 def fpz64 : Operand<f64>,
1935 ComplexPattern<f64, 1, "SelectFPZeroOperand", [fpimm]> {
1936 let ParserMatchClass = fpzero_asmoperand;
1937 let PrintMethod = "printFPZeroOperand";
1940 multiclass A64I_fpcmpSignal<bits<2> type, bit imm, dag ins, string asmop2,
1942 def _quiet : A64I_fpcmp<0b0, 0b0, type, 0b00, {0b0, imm, 0b0, 0b0, 0b0},
1943 (outs), ins, !strconcat("fcmp\t$Rn, ", asmop2),
1944 [pattern], NoItinerary> {
1948 def _sig : A64I_fpcmp<0b0, 0b0, type, 0b00, {0b1, imm, 0b0, 0b0, 0b0},
1949 (outs), ins, !strconcat("fcmpe\t$Rn, ", asmop2),
1955 defm FCMPss : A64I_fpcmpSignal<0b00, 0b0, (ins FPR32:$Rn, FPR32:$Rm), "$Rm",
1956 (set NZCV, (A64cmp (f32 FPR32:$Rn), FPR32:$Rm))>;
1957 defm FCMPdd : A64I_fpcmpSignal<0b01, 0b0, (ins FPR64:$Rn, FPR64:$Rm), "$Rm",
1958 (set NZCV, (A64cmp (f64 FPR64:$Rn), FPR64:$Rm))>;
1960 // What would be Rm should be written as 0, but anything is valid for
1961 // disassembly so we can't set the bits
1962 let PostEncoderMethod = "fixFCMPImm" in {
1963 defm FCMPsi : A64I_fpcmpSignal<0b00, 0b1, (ins FPR32:$Rn, fpz32:$Imm), "$Imm",
1964 (set NZCV, (A64cmp (f32 FPR32:$Rn), fpz32:$Imm))>;
1966 defm FCMPdi : A64I_fpcmpSignal<0b01, 0b1, (ins FPR64:$Rn, fpz64:$Imm), "$Imm",
1967 (set NZCV, (A64cmp (f64 FPR64:$Rn), fpz64:$Imm))>;
1971 //===----------------------------------------------------------------------===//
1972 // Floating-point conditional compare instructions
1973 //===----------------------------------------------------------------------===//
1974 // Contains: FCCMP, FCCMPE
1976 class A64I_fpccmpImpl<bits<2> type, bit op, RegisterClass FPR, string asmop>
1977 : A64I_fpccmp<0b0, 0b0, type, op,
1979 (ins FPR:$Rn, FPR:$Rm, uimm4:$NZCVImm, cond_code_op:$Cond),
1980 !strconcat(asmop, "\t$Rn, $Rm, $NZCVImm, $Cond"),
1985 def FCCMPss : A64I_fpccmpImpl<0b00, 0b0, FPR32, "fccmp">;
1986 def FCCMPEss : A64I_fpccmpImpl<0b00, 0b1, FPR32, "fccmpe">;
1987 def FCCMPdd : A64I_fpccmpImpl<0b01, 0b0, FPR64, "fccmp">;
1988 def FCCMPEdd : A64I_fpccmpImpl<0b01, 0b1, FPR64, "fccmpe">;
1990 //===----------------------------------------------------------------------===//
1991 // Floating-point conditional select instructions
1992 //===----------------------------------------------------------------------===//
1995 let Uses = [NZCV] in {
1996 def FCSELsssc : A64I_fpcondsel<0b0, 0b0, 0b00, (outs FPR32:$Rd),
1997 (ins FPR32:$Rn, FPR32:$Rm, cond_code_op:$Cond),
1998 "fcsel\t$Rd, $Rn, $Rm, $Cond",
2000 (simple_select (f32 FPR32:$Rn),
2005 def FCSELdddc : A64I_fpcondsel<0b0, 0b0, 0b01, (outs FPR64:$Rd),
2006 (ins FPR64:$Rn, FPR64:$Rm, cond_code_op:$Cond),
2007 "fcsel\t$Rd, $Rn, $Rm, $Cond",
2009 (simple_select (f64 FPR64:$Rn),
2014 //===----------------------------------------------------------------------===//
2015 // Floating-point data-processing (1 source)
2016 //===----------------------------------------------------------------------===//
2017 // Contains: FMOV, FABS, FNEG, FSQRT, FCVT, FRINT[NPMZAXI].
2019 def FPNoUnop : PatFrag<(ops node:$val), (fneg node:$val),
2020 [{ (void)N; return false; }]>;
2022 // First we do the fairly trivial bunch with uniform "OP s, s" and "OP d, d"
2023 // syntax. Default to no pattern because most are odd enough not to have one.
2024 multiclass A64I_fpdp1sizes<bits<6> opcode, string asmstr,
2025 SDPatternOperator opnode = FPNoUnop> {
2026 def ss : A64I_fpdp1<0b0, 0b0, 0b00, opcode, (outs FPR32:$Rd), (ins FPR32:$Rn),
2027 !strconcat(asmstr, "\t$Rd, $Rn"),
2028 [(set (f32 FPR32:$Rd), (opnode FPR32:$Rn))],
2031 def dd : A64I_fpdp1<0b0, 0b0, 0b01, opcode, (outs FPR64:$Rd), (ins FPR64:$Rn),
2032 !strconcat(asmstr, "\t$Rd, $Rn"),
2033 [(set (f64 FPR64:$Rd), (opnode FPR64:$Rn))],
2037 defm FMOV : A64I_fpdp1sizes<0b000000, "fmov">;
2038 defm FABS : A64I_fpdp1sizes<0b000001, "fabs", fabs>;
2039 defm FNEG : A64I_fpdp1sizes<0b000010, "fneg", fneg>;
2040 defm FSQRT : A64I_fpdp1sizes<0b000011, "fsqrt", fsqrt>;
2042 defm FRINTN : A64I_fpdp1sizes<0b001000, "frintn">;
2043 defm FRINTP : A64I_fpdp1sizes<0b001001, "frintp", fceil>;
2044 defm FRINTM : A64I_fpdp1sizes<0b001010, "frintm", ffloor>;
2045 defm FRINTZ : A64I_fpdp1sizes<0b001011, "frintz", ftrunc>;
2046 defm FRINTA : A64I_fpdp1sizes<0b001100, "frinta">;
2047 defm FRINTX : A64I_fpdp1sizes<0b001110, "frintx", frint>;
2048 defm FRINTI : A64I_fpdp1sizes<0b001111, "frinti", fnearbyint>;
2050 // The FCVT instrucitons have different source and destination register-types,
2051 // but the fields are uniform everywhere a D-register (say) crops up. Package
2052 // this information in a Record.
2053 class FCVTRegType<RegisterClass rc, bits<2> fld, ValueType vt> {
2054 RegisterClass Class = rc;
2060 def FCVT16 : FCVTRegType<FPR16, 0b11, f16>;
2061 def FCVT32 : FCVTRegType<FPR32, 0b00, f32>;
2062 def FCVT64 : FCVTRegType<FPR64, 0b01, f64>;
2064 class A64I_fpdp1_fcvt<FCVTRegType DestReg, FCVTRegType SrcReg, SDNode opnode>
2065 : A64I_fpdp1<0b0, 0b0, {SrcReg.t1, SrcReg.t0},
2066 {0,0,0,1, DestReg.t1, DestReg.t0},
2067 (outs DestReg.Class:$Rd), (ins SrcReg.Class:$Rn),
2069 [(set (DestReg.VT DestReg.Class:$Rd),
2070 (opnode (SrcReg.VT SrcReg.Class:$Rn)))], NoItinerary>;
2072 def FCVTds : A64I_fpdp1_fcvt<FCVT64, FCVT32, fextend>;
2073 def FCVThs : A64I_fpdp1_fcvt<FCVT16, FCVT32, fround>;
2074 def FCVTsd : A64I_fpdp1_fcvt<FCVT32, FCVT64, fround>;
2075 def FCVThd : A64I_fpdp1_fcvt<FCVT16, FCVT64, fround>;
2076 def FCVTsh : A64I_fpdp1_fcvt<FCVT32, FCVT16, fextend>;
2077 def FCVTdh : A64I_fpdp1_fcvt<FCVT64, FCVT16, fextend>;
2080 //===----------------------------------------------------------------------===//
2081 // Floating-point data-processing (2 sources) instructions
2082 //===----------------------------------------------------------------------===//
2083 // Contains: FMUL, FDIV, FADD, FSUB, FMAX, FMIN, FMAXNM, FMINNM, FNMUL
2085 def FPNoBinop : PatFrag<(ops node:$lhs, node:$rhs), (fadd node:$lhs, node:$rhs),
2086 [{ (void)N; return false; }]>;
2088 multiclass A64I_fpdp2sizes<bits<4> opcode, string asmstr,
2089 SDPatternOperator opnode> {
2090 def sss : A64I_fpdp2<0b0, 0b0, 0b00, opcode,
2092 (ins FPR32:$Rn, FPR32:$Rm),
2093 !strconcat(asmstr, "\t$Rd, $Rn, $Rm"),
2094 [(set (f32 FPR32:$Rd), (opnode FPR32:$Rn, FPR32:$Rm))],
2097 def ddd : A64I_fpdp2<0b0, 0b0, 0b01, opcode,
2099 (ins FPR64:$Rn, FPR64:$Rm),
2100 !strconcat(asmstr, "\t$Rd, $Rn, $Rm"),
2101 [(set (f64 FPR64:$Rd), (opnode FPR64:$Rn, FPR64:$Rm))],
2105 let isCommutable = 1 in {
2106 defm FMUL : A64I_fpdp2sizes<0b0000, "fmul", fmul>;
2107 defm FADD : A64I_fpdp2sizes<0b0010, "fadd", fadd>;
2109 // No patterns for these.
2110 defm FMAX : A64I_fpdp2sizes<0b0100, "fmax", FPNoBinop>;
2111 defm FMIN : A64I_fpdp2sizes<0b0101, "fmin", FPNoBinop>;
2112 defm FMAXNM : A64I_fpdp2sizes<0b0110, "fmaxnm", FPNoBinop>;
2113 defm FMINNM : A64I_fpdp2sizes<0b0111, "fminnm", FPNoBinop>;
2115 defm FNMUL : A64I_fpdp2sizes<0b1000, "fnmul",
2116 PatFrag<(ops node:$lhs, node:$rhs),
2117 (fneg (fmul node:$lhs, node:$rhs))> >;
2120 defm FDIV : A64I_fpdp2sizes<0b0001, "fdiv", fdiv>;
2121 defm FSUB : A64I_fpdp2sizes<0b0011, "fsub", fsub>;
2123 //===----------------------------------------------------------------------===//
2124 // Floating-point data-processing (3 sources) instructions
2125 //===----------------------------------------------------------------------===//
2126 // Contains: FMADD, FMSUB, FNMADD, FNMSUB
2128 def fmsub : PatFrag<(ops node:$Rn, node:$Rm, node:$Ra),
2129 (fma (fneg node:$Rn), node:$Rm, node:$Ra)>;
2130 def fnmadd : PatFrag<(ops node:$Rn, node:$Rm, node:$Ra),
2131 (fma node:$Rn, node:$Rm, (fneg node:$Ra))>;
2132 def fnmsub : PatFrag<(ops node:$Rn, node:$Rm, node:$Ra),
2133 (fma (fneg node:$Rn), node:$Rm, (fneg node:$Ra))>;
2135 class A64I_fpdp3Impl<string asmop, RegisterClass FPR, ValueType VT,
2136 bits<2> type, bit o1, bit o0, SDPatternOperator fmakind>
2137 : A64I_fpdp3<0b0, 0b0, type, o1, o0, (outs FPR:$Rd),
2138 (ins FPR:$Rn, FPR:$Rm, FPR:$Ra),
2139 !strconcat(asmop,"\t$Rd, $Rn, $Rm, $Ra"),
2140 [(set FPR:$Rd, (fmakind (VT FPR:$Rn), FPR:$Rm, FPR:$Ra))],
2143 def FMADDssss : A64I_fpdp3Impl<"fmadd", FPR32, f32, 0b00, 0b0, 0b0, fma>;
2144 def FMSUBssss : A64I_fpdp3Impl<"fmsub", FPR32, f32, 0b00, 0b0, 0b1, fmsub>;
2145 def FNMADDssss : A64I_fpdp3Impl<"fnmadd", FPR32, f32, 0b00, 0b1, 0b0, fnmadd>;
2146 def FNMSUBssss : A64I_fpdp3Impl<"fnmsub", FPR32, f32, 0b00, 0b1, 0b1, fnmsub>;
2148 def FMADDdddd : A64I_fpdp3Impl<"fmadd", FPR64, f64, 0b01, 0b0, 0b0, fma>;
2149 def FMSUBdddd : A64I_fpdp3Impl<"fmsub", FPR64, f64, 0b01, 0b0, 0b1, fmsub>;
2150 def FNMADDdddd : A64I_fpdp3Impl<"fnmadd", FPR64, f64, 0b01, 0b1, 0b0, fnmadd>;
2151 def FNMSUBdddd : A64I_fpdp3Impl<"fnmsub", FPR64, f64, 0b01, 0b1, 0b1, fnmsub>;
2153 //===----------------------------------------------------------------------===//
2154 // Floating-point <-> fixed-point conversion instructions
2155 //===----------------------------------------------------------------------===//
2156 // Contains: FCVTZS, FCVTZU, SCVTF, UCVTF
2158 // #1-#32 allowed, encoded as "64 - <specified imm>
2159 def fixedpos_asmoperand_i32 : AsmOperandClass {
2160 let Name = "CVTFixedPos32";
2161 let RenderMethod = "addCVTFixedPosOperands";
2162 let PredicateMethod = "isCVTFixedPos<32>";
2163 let DiagnosticType = "CVTFixedPos32";
2166 // Also encoded as "64 - <specified imm>" but #1-#64 allowed.
2167 def fixedpos_asmoperand_i64 : AsmOperandClass {
2168 let Name = "CVTFixedPos64";
2169 let RenderMethod = "addCVTFixedPosOperands";
2170 let PredicateMethod = "isCVTFixedPos<64>";
2171 let DiagnosticType = "CVTFixedPos64";
2174 // We need the cartesian product of f32/f64 i32/i64 operands for
2176 // + Selection needs to use operands of correct floating type
2177 // + Assembly parsing and decoding depend on integer width
2178 class cvtfix_i32_op<ValueType FloatVT>
2180 ComplexPattern<FloatVT, 1, "SelectCVTFixedPosOperand<32>", [fpimm]> {
2181 let ParserMatchClass = fixedpos_asmoperand_i32;
2182 let DecoderMethod = "DecodeCVT32FixedPosOperand";
2183 let PrintMethod = "printCVTFixedPosOperand";
2186 class cvtfix_i64_op<ValueType FloatVT>
2188 ComplexPattern<FloatVT, 1, "SelectCVTFixedPosOperand<64>", [fpimm]> {
2189 let ParserMatchClass = fixedpos_asmoperand_i64;
2190 let PrintMethod = "printCVTFixedPosOperand";
2193 // Because of the proliferation of weird operands, it's not really
2194 // worth going for a multiclass here. Oh well.
2196 class A64I_fptofix<bit sf, bits<2> type, bits<3> opcode,
2197 RegisterClass GPR, RegisterClass FPR, Operand scale_op,
2198 string asmop, SDNode cvtop>
2199 : A64I_fpfixed<sf, 0b0, type, 0b11, opcode,
2200 (outs GPR:$Rd), (ins FPR:$Rn, scale_op:$Scale),
2201 !strconcat(asmop, "\t$Rd, $Rn, $Scale"),
2202 [(set GPR:$Rd, (cvtop (fmul FPR:$Rn, scale_op:$Scale)))],
2205 def FCVTZSwsi : A64I_fptofix<0b0, 0b00, 0b000, GPR32, FPR32,
2206 cvtfix_i32_op<f32>, "fcvtzs", fp_to_sint>;
2207 def FCVTZSxsi : A64I_fptofix<0b1, 0b00, 0b000, GPR64, FPR32,
2208 cvtfix_i64_op<f32>, "fcvtzs", fp_to_sint>;
2209 def FCVTZUwsi : A64I_fptofix<0b0, 0b00, 0b001, GPR32, FPR32,
2210 cvtfix_i32_op<f32>, "fcvtzu", fp_to_uint>;
2211 def FCVTZUxsi : A64I_fptofix<0b1, 0b00, 0b001, GPR64, FPR32,
2212 cvtfix_i64_op<f32>, "fcvtzu", fp_to_uint>;
2214 def FCVTZSwdi : A64I_fptofix<0b0, 0b01, 0b000, GPR32, FPR64,
2215 cvtfix_i32_op<f64>, "fcvtzs", fp_to_sint>;
2216 def FCVTZSxdi : A64I_fptofix<0b1, 0b01, 0b000, GPR64, FPR64,
2217 cvtfix_i64_op<f64>, "fcvtzs", fp_to_sint>;
2218 def FCVTZUwdi : A64I_fptofix<0b0, 0b01, 0b001, GPR32, FPR64,
2219 cvtfix_i32_op<f64>, "fcvtzu", fp_to_uint>;
2220 def FCVTZUxdi : A64I_fptofix<0b1, 0b01, 0b001, GPR64, FPR64,
2221 cvtfix_i64_op<f64>, "fcvtzu", fp_to_uint>;
2224 class A64I_fixtofp<bit sf, bits<2> type, bits<3> opcode,
2225 RegisterClass FPR, RegisterClass GPR, Operand scale_op,
2226 string asmop, SDNode cvtop>
2227 : A64I_fpfixed<sf, 0b0, type, 0b00, opcode,
2228 (outs FPR:$Rd), (ins GPR:$Rn, scale_op:$Scale),
2229 !strconcat(asmop, "\t$Rd, $Rn, $Scale"),
2230 [(set FPR:$Rd, (fdiv (cvtop GPR:$Rn), scale_op:$Scale))],
2233 def SCVTFswi : A64I_fixtofp<0b0, 0b00, 0b010, FPR32, GPR32,
2234 cvtfix_i32_op<f32>, "scvtf", sint_to_fp>;
2235 def SCVTFsxi : A64I_fixtofp<0b1, 0b00, 0b010, FPR32, GPR64,
2236 cvtfix_i64_op<f32>, "scvtf", sint_to_fp>;
2237 def UCVTFswi : A64I_fixtofp<0b0, 0b00, 0b011, FPR32, GPR32,
2238 cvtfix_i32_op<f32>, "ucvtf", uint_to_fp>;
2239 def UCVTFsxi : A64I_fixtofp<0b1, 0b00, 0b011, FPR32, GPR64,
2240 cvtfix_i64_op<f32>, "ucvtf", uint_to_fp>;
2241 def SCVTFdwi : A64I_fixtofp<0b0, 0b01, 0b010, FPR64, GPR32,
2242 cvtfix_i32_op<f64>, "scvtf", sint_to_fp>;
2243 def SCVTFdxi : A64I_fixtofp<0b1, 0b01, 0b010, FPR64, GPR64,
2244 cvtfix_i64_op<f64>, "scvtf", sint_to_fp>;
2245 def UCVTFdwi : A64I_fixtofp<0b0, 0b01, 0b011, FPR64, GPR32,
2246 cvtfix_i32_op<f64>, "ucvtf", uint_to_fp>;
2247 def UCVTFdxi : A64I_fixtofp<0b1, 0b01, 0b011, FPR64, GPR64,
2248 cvtfix_i64_op<f64>, "ucvtf", uint_to_fp>;
2250 //===----------------------------------------------------------------------===//
2251 // Floating-point <-> integer conversion instructions
2252 //===----------------------------------------------------------------------===//
2253 // Contains: FCVTZS, FCVTZU, SCVTF, UCVTF
2255 class A64I_fpintI<bit sf, bits<2> type, bits<2> rmode, bits<3> opcode,
2256 RegisterClass DestPR, RegisterClass SrcPR, string asmop>
2257 : A64I_fpint<sf, 0b0, type, rmode, opcode, (outs DestPR:$Rd), (ins SrcPR:$Rn),
2258 !strconcat(asmop, "\t$Rd, $Rn"), [], NoItinerary>;
2260 multiclass A64I_fptointRM<bits<2> rmode, bit o2, string asmop> {
2261 def Sws : A64I_fpintI<0b0, 0b00, rmode, {o2, 0, 0},
2262 GPR32, FPR32, asmop # "s">;
2263 def Sxs : A64I_fpintI<0b1, 0b00, rmode, {o2, 0, 0},
2264 GPR64, FPR32, asmop # "s">;
2265 def Uws : A64I_fpintI<0b0, 0b00, rmode, {o2, 0, 1},
2266 GPR32, FPR32, asmop # "u">;
2267 def Uxs : A64I_fpintI<0b1, 0b00, rmode, {o2, 0, 1},
2268 GPR64, FPR32, asmop # "u">;
2270 def Swd : A64I_fpintI<0b0, 0b01, rmode, {o2, 0, 0},
2271 GPR32, FPR64, asmop # "s">;
2272 def Sxd : A64I_fpintI<0b1, 0b01, rmode, {o2, 0, 0},
2273 GPR64, FPR64, asmop # "s">;
2274 def Uwd : A64I_fpintI<0b0, 0b01, rmode, {o2, 0, 1},
2275 GPR32, FPR64, asmop # "u">;
2276 def Uxd : A64I_fpintI<0b1, 0b01, rmode, {o2, 0, 1},
2277 GPR64, FPR64, asmop # "u">;
2280 defm FCVTN : A64I_fptointRM<0b00, 0b0, "fcvtn">;
2281 defm FCVTP : A64I_fptointRM<0b01, 0b0, "fcvtp">;
2282 defm FCVTM : A64I_fptointRM<0b10, 0b0, "fcvtm">;
2283 defm FCVTZ : A64I_fptointRM<0b11, 0b0, "fcvtz">;
2284 defm FCVTA : A64I_fptointRM<0b00, 0b1, "fcvta">;
2286 def : Pat<(i32 (fp_to_sint FPR32:$Rn)), (FCVTZSws FPR32:$Rn)>;
2287 def : Pat<(i64 (fp_to_sint FPR32:$Rn)), (FCVTZSxs FPR32:$Rn)>;
2288 def : Pat<(i32 (fp_to_uint FPR32:$Rn)), (FCVTZUws FPR32:$Rn)>;
2289 def : Pat<(i64 (fp_to_uint FPR32:$Rn)), (FCVTZUxs FPR32:$Rn)>;
2290 def : Pat<(i32 (fp_to_sint (f64 FPR64:$Rn))), (FCVTZSwd FPR64:$Rn)>;
2291 def : Pat<(i64 (fp_to_sint (f64 FPR64:$Rn))), (FCVTZSxd FPR64:$Rn)>;
2292 def : Pat<(i32 (fp_to_uint (f64 FPR64:$Rn))), (FCVTZUwd FPR64:$Rn)>;
2293 def : Pat<(i64 (fp_to_uint (f64 FPR64:$Rn))), (FCVTZUxd FPR64:$Rn)>;
2295 multiclass A64I_inttofp<bit o0, string asmop> {
2296 def CVTFsw : A64I_fpintI<0b0, 0b00, 0b00, {0, 1, o0}, FPR32, GPR32, asmop>;
2297 def CVTFsx : A64I_fpintI<0b1, 0b00, 0b00, {0, 1, o0}, FPR32, GPR64, asmop>;
2298 def CVTFdw : A64I_fpintI<0b0, 0b01, 0b00, {0, 1, o0}, FPR64, GPR32, asmop>;
2299 def CVTFdx : A64I_fpintI<0b1, 0b01, 0b00, {0, 1, o0}, FPR64, GPR64, asmop>;
2302 defm S : A64I_inttofp<0b0, "scvtf">;
2303 defm U : A64I_inttofp<0b1, "ucvtf">;
2305 def : Pat<(f32 (sint_to_fp GPR32:$Rn)), (SCVTFsw GPR32:$Rn)>;
2306 def : Pat<(f32 (sint_to_fp GPR64:$Rn)), (SCVTFsx GPR64:$Rn)>;
2307 def : Pat<(f64 (sint_to_fp GPR32:$Rn)), (SCVTFdw GPR32:$Rn)>;
2308 def : Pat<(f64 (sint_to_fp GPR64:$Rn)), (SCVTFdx GPR64:$Rn)>;
2309 def : Pat<(f32 (uint_to_fp GPR32:$Rn)), (UCVTFsw GPR32:$Rn)>;
2310 def : Pat<(f32 (uint_to_fp GPR64:$Rn)), (UCVTFsx GPR64:$Rn)>;
2311 def : Pat<(f64 (uint_to_fp GPR32:$Rn)), (UCVTFdw GPR32:$Rn)>;
2312 def : Pat<(f64 (uint_to_fp GPR64:$Rn)), (UCVTFdx GPR64:$Rn)>;
2314 def FMOVws : A64I_fpintI<0b0, 0b00, 0b00, 0b110, GPR32, FPR32, "fmov">;
2315 def FMOVsw : A64I_fpintI<0b0, 0b00, 0b00, 0b111, FPR32, GPR32, "fmov">;
2316 def FMOVxd : A64I_fpintI<0b1, 0b01, 0b00, 0b110, GPR64, FPR64, "fmov">;
2317 def FMOVdx : A64I_fpintI<0b1, 0b01, 0b00, 0b111, FPR64, GPR64, "fmov">;
2319 def : Pat<(i32 (bitconvert (f32 FPR32:$Rn))), (FMOVws FPR32:$Rn)>;
2320 def : Pat<(f32 (bitconvert (i32 GPR32:$Rn))), (FMOVsw GPR32:$Rn)>;
2321 def : Pat<(i64 (bitconvert (f64 FPR64:$Rn))), (FMOVxd FPR64:$Rn)>;
2322 def : Pat<(f64 (bitconvert (i64 GPR64:$Rn))), (FMOVdx GPR64:$Rn)>;
2324 def lane1_asmoperand : AsmOperandClass {
2326 let RenderMethod = "addImmOperands";
2327 let DiagnosticType = "Lane1";
2330 def lane1 : Operand<i32> {
2331 let ParserMatchClass = lane1_asmoperand;
2332 let PrintMethod = "printBareImmOperand";
2335 let DecoderMethod = "DecodeFMOVLaneInstruction" in {
2336 def FMOVxv : A64I_fpint<0b1, 0b0, 0b10, 0b01, 0b110,
2337 (outs GPR64:$Rd), (ins VPR128:$Rn, lane1:$Lane),
2338 "fmov\t$Rd, $Rn.d[$Lane]", [], NoItinerary>;
2340 def FMOVvx : A64I_fpint<0b1, 0b0, 0b10, 0b01, 0b111,
2341 (outs VPR128:$Rd), (ins GPR64:$Rn, lane1:$Lane),
2342 "fmov\t$Rd.d[$Lane], $Rn", [], NoItinerary>;
2345 def : InstAlias<"fmov $Rd, $Rn.2d[$Lane]",
2346 (FMOVxv GPR64:$Rd, VPR128:$Rn, lane1:$Lane), 0b0>;
2348 def : InstAlias<"fmov $Rd.2d[$Lane], $Rn",
2349 (FMOVvx VPR128:$Rd, GPR64:$Rn, lane1:$Lane), 0b0>;
2351 //===----------------------------------------------------------------------===//
2352 // Floating-point immediate instructions
2353 //===----------------------------------------------------------------------===//
2356 def fpimm_asmoperand : AsmOperandClass {
2357 let Name = "FMOVImm";
2358 let ParserMethod = "ParseFPImmOperand";
2359 let DiagnosticType = "FPImm";
2362 // The MCOperand for these instructions are the encoded 8-bit values.
2363 def SDXF_fpimm : SDNodeXForm<fpimm, [{
2365 A64Imms::isFPImm(N->getValueAPF(), Imm8);
2366 return CurDAG->getTargetConstant(Imm8, MVT::i32);
2369 class fmov_operand<ValueType FT>
2371 PatLeaf<(FT fpimm), [{ return A64Imms::isFPImm(N->getValueAPF()); }],
2373 let PrintMethod = "printFPImmOperand";
2374 let ParserMatchClass = fpimm_asmoperand;
2377 def fmov32_operand : fmov_operand<f32>;
2378 def fmov64_operand : fmov_operand<f64>;
2380 class A64I_fpimm_impl<bits<2> type, RegisterClass Reg, ValueType VT,
2381 Operand fmov_operand>
2382 : A64I_fpimm<0b0, 0b0, type, 0b00000,
2384 (ins fmov_operand:$Imm8),
2386 [(set (VT Reg:$Rd), fmov_operand:$Imm8)],
2389 def FMOVsi : A64I_fpimm_impl<0b00, FPR32, f32, fmov32_operand>;
2390 def FMOVdi : A64I_fpimm_impl<0b01, FPR64, f64, fmov64_operand>;
2392 //===----------------------------------------------------------------------===//
2393 // Load-register (literal) instructions
2394 //===----------------------------------------------------------------------===//
2395 // Contains: LDR, LDRSW, PRFM
2397 def ldrlit_label_asmoperand : AsmOperandClass {
2398 let Name = "LoadLitLabel";
2399 let RenderMethod = "addLabelOperands<19, 4>";
2400 let DiagnosticType = "Label";
2403 def ldrlit_label : Operand<i64> {
2404 let EncoderMethod = "getLoadLitLabelOpValue";
2406 // This label is a 19-bit offset from PC, scaled by the instruction-width: 4.
2407 let PrintMethod = "printLabelOperand<19, 4>";
2408 let ParserMatchClass = ldrlit_label_asmoperand;
2409 let OperandType = "OPERAND_PCREL";
2412 // Various instructions take an immediate value (which can always be used),
2413 // where some numbers have a symbolic name to make things easier. These operands
2414 // and the associated functions abstract away the differences.
2415 multiclass namedimm<string prefix, string mapper> {
2416 def _asmoperand : AsmOperandClass {
2417 let Name = "NamedImm" # prefix;
2418 let PredicateMethod = "isUImm";
2419 let RenderMethod = "addImmOperands";
2420 let ParserMethod = "ParseNamedImmOperand<" # mapper # ">";
2421 let DiagnosticType = "NamedImm_" # prefix;
2424 def _op : Operand<i32> {
2425 let ParserMatchClass = !cast<AsmOperandClass>(prefix # "_asmoperand");
2426 let PrintMethod = "printNamedImmOperand<" # mapper # ">";
2427 let DecoderMethod = "DecodeNamedImmOperand<" # mapper # ">";
2431 defm prefetch : namedimm<"prefetch", "A64PRFM::PRFMMapper">;
2433 class A64I_LDRlitSimple<bits<2> opc, bit v, RegisterClass OutReg,
2434 list<dag> patterns = []>
2435 : A64I_LDRlit<opc, v, (outs OutReg:$Rt), (ins ldrlit_label:$Imm19),
2436 "ldr\t$Rt, $Imm19", patterns, NoItinerary>;
2438 let mayLoad = 1 in {
2439 def LDRw_lit : A64I_LDRlitSimple<0b00, 0b0, GPR32,
2440 [(set (i32 GPR32:$Rt), (load constpool:$Imm19))]>;
2441 def LDRx_lit : A64I_LDRlitSimple<0b01, 0b0, GPR64,
2442 [(set (i64 GPR64:$Rt), (load constpool:$Imm19))]>;
2445 def LDRs_lit : A64I_LDRlitSimple<0b00, 0b1, FPR32,
2446 [(set (f32 FPR32:$Rt), (load constpool:$Imm19))]>;
2447 def LDRd_lit : A64I_LDRlitSimple<0b01, 0b1, FPR64,
2448 [(set (f64 FPR64:$Rt), (load constpool:$Imm19))]>;
2450 let mayLoad = 1 in {
2451 def LDRq_lit : A64I_LDRlitSimple<0b10, 0b1, FPR128>;
2454 def LDRSWx_lit : A64I_LDRlit<0b10, 0b0,
2456 (ins ldrlit_label:$Imm19),
2457 "ldrsw\t$Rt, $Imm19",
2460 def PRFM_lit : A64I_LDRlit<0b11, 0b0,
2461 (outs), (ins prefetch_op:$Rt, ldrlit_label:$Imm19),
2462 "prfm\t$Rt, $Imm19",
2466 //===----------------------------------------------------------------------===//
2467 // Load-store exclusive instructions
2468 //===----------------------------------------------------------------------===//
2469 // Contains: STXRB, STXRH, STXR, LDXRB, LDXRH, LDXR. STXP, LDXP, STLXRB,
2470 // STLXRH, STLXR, LDAXRB, LDAXRH, LDAXR, STLXP, LDAXP, STLRB,
2471 // STLRH, STLR, LDARB, LDARH, LDAR
2473 // Since these instructions have the undefined register bits set to 1 in
2474 // their canonical form, we need a post encoder method to set those bits
2475 // to 1 when encoding these instructions. We do this using the
2476 // fixLoadStoreExclusive function. This function has template parameters:
2478 // fixLoadStoreExclusive<int hasRs, int hasRt2>
2480 // hasRs indicates that the instruction uses the Rs field, so we won't set
2481 // it to 1 (and the same for Rt2). We don't need template parameters for
2482 // the other register fiels since Rt and Rn are always used.
2484 // This operand parses a GPR64xsp register, followed by an optional immediate
2486 def GPR64xsp0_asmoperand : AsmOperandClass {
2487 let Name = "GPR64xsp0";
2488 let PredicateMethod = "isWrappedReg";
2489 let RenderMethod = "addRegOperands";
2490 let ParserMethod = "ParseLSXAddressOperand";
2491 // Diagnostics are provided by ParserMethod
2494 def GPR64xsp0 : RegisterOperand<GPR64xsp> {
2495 let ParserMatchClass = GPR64xsp0_asmoperand;
2498 //===----------------------------------
2499 // Store-exclusive (releasing & normal)
2500 //===----------------------------------
2502 class A64I_SRexs_impl<bits<2> size, bits<3> opcode, string asm, dag outs,
2503 dag ins, list<dag> pat,
2504 InstrItinClass itin> :
2505 A64I_LDSTex_stn <size,
2506 opcode{2}, 0, opcode{1}, opcode{0},
2508 !strconcat(asm, "\t$Rs, $Rt, [$Rn]"),
2511 let PostEncoderMethod = "fixLoadStoreExclusive<1,0>";
2514 multiclass A64I_SRex<string asmstr, bits<3> opcode, string prefix> {
2515 def _byte: A64I_SRexs_impl<0b00, opcode, !strconcat(asmstr, "b"),
2516 (outs GPR32:$Rs), (ins GPR32:$Rt, GPR64xsp0:$Rn),
2519 def _hword: A64I_SRexs_impl<0b01, opcode, !strconcat(asmstr, "h"),
2520 (outs GPR32:$Rs), (ins GPR32:$Rt, GPR64xsp0:$Rn),
2523 def _word: A64I_SRexs_impl<0b10, opcode, asmstr,
2524 (outs GPR32:$Rs), (ins GPR32:$Rt, GPR64xsp0:$Rn),
2527 def _dword: A64I_SRexs_impl<0b11, opcode, asmstr,
2528 (outs GPR32:$Rs), (ins GPR64:$Rt, GPR64xsp0:$Rn),
2532 defm STXR : A64I_SRex<"stxr", 0b000, "STXR">;
2533 defm STLXR : A64I_SRex<"stlxr", 0b001, "STLXR">;
2535 //===----------------------------------
2537 //===----------------------------------
2539 class A64I_LRexs_impl<bits<2> size, bits<3> opcode, string asm, dag outs,
2540 dag ins, list<dag> pat,
2541 InstrItinClass itin> :
2542 A64I_LDSTex_tn <size,
2543 opcode{2}, 1, opcode{1}, opcode{0},
2545 !strconcat(asm, "\t$Rt, [$Rn]"),
2548 let PostEncoderMethod = "fixLoadStoreExclusive<0,0>";
2551 multiclass A64I_LRex<string asmstr, bits<3> opcode> {
2552 def _byte: A64I_LRexs_impl<0b00, opcode, !strconcat(asmstr, "b"),
2553 (outs GPR32:$Rt), (ins GPR64xsp0:$Rn),
2556 def _hword: A64I_LRexs_impl<0b01, opcode, !strconcat(asmstr, "h"),
2557 (outs GPR32:$Rt), (ins GPR64xsp0:$Rn),
2560 def _word: A64I_LRexs_impl<0b10, opcode, asmstr,
2561 (outs GPR32:$Rt), (ins GPR64xsp0:$Rn),
2564 def _dword: A64I_LRexs_impl<0b11, opcode, asmstr,
2565 (outs GPR64:$Rt), (ins GPR64xsp0:$Rn),
2569 defm LDXR : A64I_LRex<"ldxr", 0b000>;
2570 defm LDAXR : A64I_LRex<"ldaxr", 0b001>;
2571 defm LDAR : A64I_LRex<"ldar", 0b101>;
2573 class acquiring_load<PatFrag base>
2574 : PatFrag<(ops node:$ptr), (base node:$ptr), [{
2575 return cast<AtomicSDNode>(N)->getOrdering() == Acquire;
2578 def atomic_load_acquire_8 : acquiring_load<atomic_load_8>;
2579 def atomic_load_acquire_16 : acquiring_load<atomic_load_16>;
2580 def atomic_load_acquire_32 : acquiring_load<atomic_load_32>;
2581 def atomic_load_acquire_64 : acquiring_load<atomic_load_64>;
2583 def : Pat<(atomic_load_acquire_8 GPR64xsp:$Rn), (LDAR_byte GPR64xsp0:$Rn)>;
2584 def : Pat<(atomic_load_acquire_16 GPR64xsp:$Rn), (LDAR_hword GPR64xsp0:$Rn)>;
2585 def : Pat<(atomic_load_acquire_32 GPR64xsp:$Rn), (LDAR_word GPR64xsp0:$Rn)>;
2586 def : Pat<(atomic_load_acquire_64 GPR64xsp:$Rn), (LDAR_dword GPR64xsp0:$Rn)>;
2588 //===----------------------------------
2589 // Store-release (no exclusivity)
2590 //===----------------------------------
2592 class A64I_SLexs_impl<bits<2> size, bits<3> opcode, string asm, dag outs,
2593 dag ins, list<dag> pat,
2594 InstrItinClass itin> :
2595 A64I_LDSTex_tn <size,
2596 opcode{2}, 0, opcode{1}, opcode{0},
2598 !strconcat(asm, "\t$Rt, [$Rn]"),
2601 let PostEncoderMethod = "fixLoadStoreExclusive<0,0>";
2604 class releasing_store<PatFrag base>
2605 : PatFrag<(ops node:$ptr, node:$val), (base node:$ptr, node:$val), [{
2606 return cast<AtomicSDNode>(N)->getOrdering() == Release;
2609 def atomic_store_release_8 : releasing_store<atomic_store_8>;
2610 def atomic_store_release_16 : releasing_store<atomic_store_16>;
2611 def atomic_store_release_32 : releasing_store<atomic_store_32>;
2612 def atomic_store_release_64 : releasing_store<atomic_store_64>;
2614 multiclass A64I_SLex<string asmstr, bits<3> opcode, string prefix> {
2615 def _byte: A64I_SLexs_impl<0b00, opcode, !strconcat(asmstr, "b"),
2616 (outs), (ins GPR32:$Rt, GPR64xsp0:$Rn),
2617 [(atomic_store_release_8 GPR64xsp0:$Rn, GPR32:$Rt)],
2620 def _hword: A64I_SLexs_impl<0b01, opcode, !strconcat(asmstr, "h"),
2621 (outs), (ins GPR32:$Rt, GPR64xsp0:$Rn),
2622 [(atomic_store_release_16 GPR64xsp0:$Rn, GPR32:$Rt)],
2625 def _word: A64I_SLexs_impl<0b10, opcode, asmstr,
2626 (outs), (ins GPR32:$Rt, GPR64xsp0:$Rn),
2627 [(atomic_store_release_32 GPR64xsp0:$Rn, GPR32:$Rt)],
2630 def _dword: A64I_SLexs_impl<0b11, opcode, asmstr,
2631 (outs), (ins GPR64:$Rt, GPR64xsp0:$Rn),
2632 [(atomic_store_release_64 GPR64xsp0:$Rn, GPR64:$Rt)],
2636 defm STLR : A64I_SLex<"stlr", 0b101, "STLR">;
2638 //===----------------------------------
2639 // Store-exclusive pair (releasing & normal)
2640 //===----------------------------------
2642 class A64I_SPexs_impl<bits<2> size, bits<3> opcode, string asm, dag outs,
2643 dag ins, list<dag> pat,
2644 InstrItinClass itin> :
2645 A64I_LDSTex_stt2n <size,
2646 opcode{2}, 0, opcode{1}, opcode{0},
2648 !strconcat(asm, "\t$Rs, $Rt, $Rt2, [$Rn]"),
2654 multiclass A64I_SPex<string asmstr, bits<3> opcode> {
2655 def _word: A64I_SPexs_impl<0b10, opcode, asmstr, (outs),
2656 (ins GPR32:$Rs, GPR32:$Rt, GPR32:$Rt2,
2660 def _dword: A64I_SPexs_impl<0b11, opcode, asmstr, (outs),
2661 (ins GPR32:$Rs, GPR64:$Rt, GPR64:$Rt2,
2666 defm STXP : A64I_SPex<"stxp", 0b010>;
2667 defm STLXP : A64I_SPex<"stlxp", 0b011>;
2669 //===----------------------------------
2670 // Load-exclusive pair (acquiring & normal)
2671 //===----------------------------------
2673 class A64I_LPexs_impl<bits<2> size, bits<3> opcode, string asm, dag outs,
2674 dag ins, list<dag> pat,
2675 InstrItinClass itin> :
2676 A64I_LDSTex_tt2n <size,
2677 opcode{2}, 1, opcode{1}, opcode{0},
2679 !strconcat(asm, "\t$Rt, $Rt2, [$Rn]"),
2682 let DecoderMethod = "DecodeLoadPairExclusiveInstruction";
2683 let PostEncoderMethod = "fixLoadStoreExclusive<0,1>";
2686 multiclass A64I_LPex<string asmstr, bits<3> opcode> {
2687 def _word: A64I_LPexs_impl<0b10, opcode, asmstr,
2688 (outs GPR32:$Rt, GPR32:$Rt2),
2689 (ins GPR64xsp0:$Rn),
2692 def _dword: A64I_LPexs_impl<0b11, opcode, asmstr,
2693 (outs GPR64:$Rt, GPR64:$Rt2),
2694 (ins GPR64xsp0:$Rn),
2698 defm LDXP : A64I_LPex<"ldxp", 0b010>;
2699 defm LDAXP : A64I_LPex<"ldaxp", 0b011>;
2701 //===----------------------------------------------------------------------===//
2702 // Load-store register (unscaled immediate) instructions
2703 //===----------------------------------------------------------------------===//
2704 // Contains: LDURB, LDURH, LDRUSB, LDRUSH, LDRUSW, STUR, STURB, STURH and PRFUM
2708 //===----------------------------------------------------------------------===//
2709 // Load-store register (register offset) instructions
2710 //===----------------------------------------------------------------------===//
2711 // Contains: LDRB, LDRH, LDRSB, LDRSH, LDRSW, STR, STRB, STRH and PRFM
2715 //===----------------------------------------------------------------------===//
2716 // Load-store register (unsigned immediate) instructions
2717 //===----------------------------------------------------------------------===//
2718 // Contains: LDRB, LDRH, LDRSB, LDRSH, LDRSW, STR, STRB, STRH and PRFM
2722 //===----------------------------------------------------------------------===//
2723 // Load-store register (immediate post-indexed) instructions
2724 //===----------------------------------------------------------------------===//
2725 // Contains: STRB, STRH, STR, LDRB, LDRH, LDR, LDRSB, LDRSH, LDRSW
2729 //===----------------------------------------------------------------------===//
2730 // Load-store register (immediate pre-indexed) instructions
2731 //===----------------------------------------------------------------------===//
2732 // Contains: STRB, STRH, STR, LDRB, LDRH, LDR, LDRSB, LDRSH, LDRSW
2734 // Note that patterns are much later on in a completely separate section (they
2735 // need ADRPxi to be defined).
2737 //===-------------------------------
2738 // 1. Various operands needed
2739 //===-------------------------------
2741 //===-------------------------------
2742 // 1.1 Unsigned 12-bit immediate operands
2743 //===-------------------------------
2744 // The addressing mode for these instructions consists of an unsigned 12-bit
2745 // immediate which is scaled by the size of the memory access.
2747 // We represent this in the MC layer by two operands:
2748 // 1. A base register.
2749 // 2. A 12-bit immediate: not multiplied by access size, so "LDR x0,[x0,#8]"
2750 // would have '1' in this field.
2751 // This means that separate functions are needed for converting representations
2752 // which *are* aware of the intended access size.
2754 // Anything that creates an MCInst (Decoding, selection and AsmParsing) has to
2755 // know the access size via some means. An isolated operand does not have this
2756 // information unless told from here, which means we need separate tablegen
2757 // Operands for each access size. This multiclass takes care of instantiating
2758 // the correct template functions in the rest of the backend.
2760 //===-------------------------------
2761 // 1.1 Unsigned 12-bit immediate operands
2762 //===-------------------------------
2764 multiclass offsets_uimm12<int MemSize, string prefix> {
2765 def uimm12_asmoperand : AsmOperandClass {
2766 let Name = "OffsetUImm12_" # MemSize;
2767 let PredicateMethod = "isOffsetUImm12<" # MemSize # ">";
2768 let RenderMethod = "addOffsetUImm12Operands<" # MemSize # ">";
2769 let DiagnosticType = "LoadStoreUImm12_" # MemSize;
2772 // Pattern is really no more than an ImmLeaf, but predicated on MemSize which
2773 // complicates things beyond TableGen's ken.
2774 def uimm12 : Operand<i64>,
2775 ComplexPattern<i64, 1, "SelectOffsetUImm12<" # MemSize # ">"> {
2776 let ParserMatchClass
2777 = !cast<AsmOperandClass>(prefix # uimm12_asmoperand);
2779 let PrintMethod = "printOffsetUImm12Operand<" # MemSize # ">";
2780 let EncoderMethod = "getOffsetUImm12OpValue<" # MemSize # ">";
2784 defm byte_ : offsets_uimm12<1, "byte_">;
2785 defm hword_ : offsets_uimm12<2, "hword_">;
2786 defm word_ : offsets_uimm12<4, "word_">;
2787 defm dword_ : offsets_uimm12<8, "dword_">;
2788 defm qword_ : offsets_uimm12<16, "qword_">;
2790 //===-------------------------------
2791 // 1.1 Signed 9-bit immediate operands
2792 //===-------------------------------
2794 // The MCInst is expected to store the bit-wise encoding of the value,
2795 // which amounts to lopping off the extended sign bits.
2796 def SDXF_simm9 : SDNodeXForm<imm, [{
2797 return CurDAG->getTargetConstant(N->getZExtValue() & 0x1ff, MVT::i32);
2800 def simm9_asmoperand : AsmOperandClass {
2802 let PredicateMethod = "isSImm<9>";
2803 let RenderMethod = "addSImmOperands<9>";
2804 let DiagnosticType = "LoadStoreSImm9";
2807 def simm9 : Operand<i64>,
2808 ImmLeaf<i64, [{ return Imm >= -0x100 && Imm <= 0xff; }],
2810 let PrintMethod = "printOffsetSImm9Operand";
2811 let ParserMatchClass = simm9_asmoperand;
2815 //===-------------------------------
2816 // 1.3 Register offset extensions
2817 //===-------------------------------
2819 // The assembly-syntax for these addressing-modes is:
2820 // [<Xn|SP>, <R><m> {, <extend> {<amount>}}]
2822 // The essential semantics are:
2823 // + <amount> is a shift: #<log(transfer size)> or #0
2824 // + <R> can be W or X.
2825 // + If <R> is W, <extend> can be UXTW or SXTW
2826 // + If <R> is X, <extend> can be LSL or SXTX
2828 // The trickiest of those constraints is that Rm can be either GPR32 or GPR64,
2829 // which will need separate instructions for LLVM type-consistency. We'll also
2830 // need separate operands, of course.
2831 multiclass regexts<int MemSize, int RmSize, RegisterClass GPR,
2832 string Rm, string prefix> {
2833 def regext_asmoperand : AsmOperandClass {
2834 let Name = "AddrRegExtend_" # MemSize # "_" # Rm;
2835 let PredicateMethod = "isAddrRegExtend<" # MemSize # "," # RmSize # ">";
2836 let RenderMethod = "addAddrRegExtendOperands<" # MemSize # ">";
2837 let DiagnosticType = "LoadStoreExtend" # RmSize # "_" # MemSize;
2840 def regext : Operand<i64> {
2842 = "printAddrRegExtendOperand<" # MemSize # ", " # RmSize # ">";
2844 let DecoderMethod = "DecodeAddrRegExtendOperand";
2845 let ParserMatchClass
2846 = !cast<AsmOperandClass>(prefix # regext_asmoperand);
2850 multiclass regexts_wx<int MemSize, string prefix> {
2851 // Rm is an X-register if LSL or SXTX are specified as the shift.
2852 defm Xm_ : regexts<MemSize, 64, GPR64, "Xm", prefix # "Xm_">;
2854 // Rm is a W-register if UXTW or SXTW are specified as the shift.
2855 defm Wm_ : regexts<MemSize, 32, GPR32, "Wm", prefix # "Wm_">;
2858 defm byte_ : regexts_wx<1, "byte_">;
2859 defm hword_ : regexts_wx<2, "hword_">;
2860 defm word_ : regexts_wx<4, "word_">;
2861 defm dword_ : regexts_wx<8, "dword_">;
2862 defm qword_ : regexts_wx<16, "qword_">;
2865 //===------------------------------
2866 // 2. The instructions themselves.
2867 //===------------------------------
2869 // We have the following instructions to implement:
2870 // | | B | H | W | X |
2871 // |-----------------+-------+-------+-------+--------|
2872 // | unsigned str | STRB | STRH | STR | STR |
2873 // | unsigned ldr | LDRB | LDRH | LDR | LDR |
2874 // | signed ldr to W | LDRSB | LDRSH | - | - |
2875 // | signed ldr to X | LDRSB | LDRSH | LDRSW | (PRFM) |
2877 // This will instantiate the LDR/STR instructions you'd expect to use for an
2878 // unsigned datatype (first two rows above) or floating-point register, which is
2879 // reasonably uniform across all access sizes.
2882 //===------------------------------
2883 // 2.1 Regular instructions
2884 //===------------------------------
2886 // This class covers the basic unsigned or irrelevantly-signed loads and stores,
2887 // to general-purpose and floating-point registers.
2889 class AddrParams<string prefix> {
2890 Operand uimm12 = !cast<Operand>(prefix # "_uimm12");
2892 Operand regextWm = !cast<Operand>(prefix # "_Wm_regext");
2893 Operand regextXm = !cast<Operand>(prefix # "_Xm_regext");
2896 def byte_addrparams : AddrParams<"byte">;
2897 def hword_addrparams : AddrParams<"hword">;
2898 def word_addrparams : AddrParams<"word">;
2899 def dword_addrparams : AddrParams<"dword">;
2900 def qword_addrparams : AddrParams<"qword">;
2902 multiclass A64I_LDRSTR_unsigned<string prefix, bits<2> size, bit v,
2903 bit high_opc, string asmsuffix,
2904 RegisterClass GPR, AddrParams params> {
2905 // Unsigned immediate
2906 def _STR : A64I_LSunsigimm<size, v, {high_opc, 0b0},
2907 (outs), (ins GPR:$Rt, GPR64xsp:$Rn, params.uimm12:$UImm12),
2908 "str" # asmsuffix # "\t$Rt, [$Rn, $UImm12]",
2912 def : InstAlias<"str" # asmsuffix # " $Rt, [$Rn]",
2913 (!cast<Instruction>(prefix # "_STR") GPR:$Rt, GPR64xsp:$Rn, 0)>;
2915 def _LDR : A64I_LSunsigimm<size, v, {high_opc, 0b1},
2916 (outs GPR:$Rt), (ins GPR64xsp:$Rn, params.uimm12:$UImm12),
2917 "ldr" # asmsuffix # "\t$Rt, [$Rn, $UImm12]",
2921 def : InstAlias<"ldr" # asmsuffix # " $Rt, [$Rn]",
2922 (!cast<Instruction>(prefix # "_LDR") GPR:$Rt, GPR64xsp:$Rn, 0)>;
2924 // Register offset (four of these: load/store and Wm/Xm).
2925 let mayLoad = 1 in {
2926 def _Wm_RegOffset_LDR : A64I_LSregoff<size, v, {high_opc, 0b1}, 0b0,
2928 (ins GPR64xsp:$Rn, GPR32:$Rm, params.regextWm:$Ext),
2929 "ldr" # asmsuffix # "\t$Rt, [$Rn, $Rm, $Ext]",
2932 def _Xm_RegOffset_LDR : A64I_LSregoff<size, v, {high_opc, 0b1}, 0b1,
2934 (ins GPR64xsp:$Rn, GPR64:$Rm, params.regextXm:$Ext),
2935 "ldr" # asmsuffix # "\t$Rt, [$Rn, $Rm, $Ext]",
2938 def : InstAlias<"ldr" # asmsuffix # " $Rt, [$Rn, $Rm]",
2939 (!cast<Instruction>(prefix # "_Xm_RegOffset_LDR") GPR:$Rt, GPR64xsp:$Rn,
2942 let mayStore = 1 in {
2943 def _Wm_RegOffset_STR : A64I_LSregoff<size, v, {high_opc, 0b0}, 0b0,
2944 (outs), (ins GPR:$Rt, GPR64xsp:$Rn, GPR32:$Rm,
2945 params.regextWm:$Ext),
2946 "str" # asmsuffix # "\t$Rt, [$Rn, $Rm, $Ext]",
2949 def _Xm_RegOffset_STR : A64I_LSregoff<size, v, {high_opc, 0b0}, 0b1,
2950 (outs), (ins GPR:$Rt, GPR64xsp:$Rn, GPR64:$Rm,
2951 params.regextXm:$Ext),
2952 "str" # asmsuffix # "\t$Rt, [$Rn, $Rm, $Ext]",
2955 def : InstAlias<"str" # asmsuffix # " $Rt, [$Rn, $Rm]",
2956 (!cast<Instruction>(prefix # "_Xm_RegOffset_STR") GPR:$Rt, GPR64xsp:$Rn,
2959 // Unaligned immediate
2960 def _STUR : A64I_LSunalimm<size, v, {high_opc, 0b0},
2961 (outs), (ins GPR:$Rt, GPR64xsp:$Rn, simm9:$SImm9),
2962 "stur" # asmsuffix # "\t$Rt, [$Rn, $SImm9]",
2966 def : InstAlias<"stur" # asmsuffix # " $Rt, [$Rn]",
2967 (!cast<Instruction>(prefix # "_STUR") GPR:$Rt, GPR64xsp:$Rn, 0)>;
2969 def _LDUR : A64I_LSunalimm<size, v, {high_opc, 0b1},
2970 (outs GPR:$Rt), (ins GPR64xsp:$Rn, simm9:$SImm9),
2971 "ldur" # asmsuffix # "\t$Rt, [$Rn, $SImm9]",
2975 def : InstAlias<"ldur" # asmsuffix # " $Rt, [$Rn]",
2976 (!cast<Instruction>(prefix # "_LDUR") GPR:$Rt, GPR64xsp:$Rn, 0)>;
2979 def _PostInd_STR : A64I_LSpostind<size, v, {high_opc, 0b0},
2980 (outs GPR64xsp:$Rn_wb),
2981 (ins GPR:$Rt, GPR64xsp:$Rn, simm9:$SImm9),
2982 "str" # asmsuffix # "\t$Rt, [$Rn], $SImm9",
2984 let Constraints = "$Rn = $Rn_wb";
2987 // Decoder only needed for unpredictability checking (FIXME).
2988 let DecoderMethod = "DecodeSingleIndexedInstruction";
2991 def _PostInd_LDR : A64I_LSpostind<size, v, {high_opc, 0b1},
2992 (outs GPR:$Rt, GPR64xsp:$Rn_wb),
2993 (ins GPR64xsp:$Rn, simm9:$SImm9),
2994 "ldr" # asmsuffix # "\t$Rt, [$Rn], $SImm9",
2997 let Constraints = "$Rn = $Rn_wb";
2998 let DecoderMethod = "DecodeSingleIndexedInstruction";
3002 def _PreInd_STR : A64I_LSpreind<size, v, {high_opc, 0b0},
3003 (outs GPR64xsp:$Rn_wb),
3004 (ins GPR:$Rt, GPR64xsp:$Rn, simm9:$SImm9),
3005 "str" # asmsuffix # "\t$Rt, [$Rn, $SImm9]!",
3007 let Constraints = "$Rn = $Rn_wb";
3010 // Decoder only needed for unpredictability checking (FIXME).
3011 let DecoderMethod = "DecodeSingleIndexedInstruction";
3014 def _PreInd_LDR : A64I_LSpreind<size, v, {high_opc, 0b1},
3015 (outs GPR:$Rt, GPR64xsp:$Rn_wb),
3016 (ins GPR64xsp:$Rn, simm9:$SImm9),
3017 "ldr" # asmsuffix # "\t$Rt, [$Rn, $SImm9]!",
3020 let Constraints = "$Rn = $Rn_wb";
3021 let DecoderMethod = "DecodeSingleIndexedInstruction";
3026 // STRB/LDRB: First define the instructions
3028 : A64I_LDRSTR_unsigned<"LS8", 0b00, 0b0, 0b0, "b", GPR32, byte_addrparams>;
3032 : A64I_LDRSTR_unsigned<"LS16", 0b01, 0b0, 0b0, "h", GPR32, hword_addrparams>;
3035 // STR/LDR to/from a W register
3037 : A64I_LDRSTR_unsigned<"LS32", 0b10, 0b0, 0b0, "", GPR32, word_addrparams>;
3039 // STR/LDR to/from an X register
3041 : A64I_LDRSTR_unsigned<"LS64", 0b11, 0b0, 0b0, "", GPR64, dword_addrparams>;
3043 // STR/LDR to/from a B register
3045 : A64I_LDRSTR_unsigned<"LSFP8", 0b00, 0b1, 0b0, "", FPR8, byte_addrparams>;
3047 // STR/LDR to/from an H register
3049 : A64I_LDRSTR_unsigned<"LSFP16", 0b01, 0b1, 0b0, "", FPR16, hword_addrparams>;
3051 // STR/LDR to/from an S register
3053 : A64I_LDRSTR_unsigned<"LSFP32", 0b10, 0b1, 0b0, "", FPR32, word_addrparams>;
3054 // STR/LDR to/from a D register
3056 : A64I_LDRSTR_unsigned<"LSFP64", 0b11, 0b1, 0b0, "", FPR64, dword_addrparams>;
3057 // STR/LDR to/from a Q register
3059 : A64I_LDRSTR_unsigned<"LSFP128", 0b00, 0b1, 0b1, "", FPR128,
3062 //===------------------------------
3064 //===------------------------------
3066 // Byte and half-word signed loads can both go into either an X or a W register,
3067 // so it's worth factoring out. Signed word loads don't fit because there is no
3069 multiclass A64I_LDR_signed<bits<2> size, string asmopcode, AddrParams params,
3072 def w : A64I_LSunsigimm<size, 0b0, 0b11,
3074 (ins GPR64xsp:$Rn, params.uimm12:$UImm12),
3075 "ldrs" # asmopcode # "\t$Rt, [$Rn, $UImm12]",
3079 def : InstAlias<"ldrs" # asmopcode # " $Rt, [$Rn]",
3080 (!cast<Instruction>(prefix # w) GPR32:$Rt, GPR64xsp:$Rn, 0)>;
3082 def x : A64I_LSunsigimm<size, 0b0, 0b10,
3084 (ins GPR64xsp:$Rn, params.uimm12:$UImm12),
3085 "ldrs" # asmopcode # "\t$Rt, [$Rn, $UImm12]",
3089 def : InstAlias<"ldrs" # asmopcode # " $Rt, [$Rn]",
3090 (!cast<Instruction>(prefix # x) GPR64:$Rt, GPR64xsp:$Rn, 0)>;
3093 let mayLoad = 1 in {
3094 def w_Wm_RegOffset : A64I_LSregoff<size, 0b0, 0b11, 0b0,
3096 (ins GPR64xsp:$Rn, GPR32:$Rm, params.regextWm:$Ext),
3097 "ldrs" # asmopcode # "\t$Rt, [$Rn, $Rm, $Ext]",
3100 def w_Xm_RegOffset : A64I_LSregoff<size, 0b0, 0b11, 0b1,
3102 (ins GPR64xsp:$Rn, GPR64:$Rm, params.regextXm:$Ext),
3103 "ldrs" # asmopcode # "\t$Rt, [$Rn, $Rm, $Ext]",
3106 def x_Wm_RegOffset : A64I_LSregoff<size, 0b0, 0b10, 0b0,
3108 (ins GPR64xsp:$Rn, GPR32:$Rm, params.regextWm:$Ext),
3109 "ldrs" # asmopcode # "\t$Rt, [$Rn, $Rm, $Ext]",
3112 def x_Xm_RegOffset : A64I_LSregoff<size, 0b0, 0b10, 0b1,
3114 (ins GPR64xsp:$Rn, GPR64:$Rm, params.regextXm:$Ext),
3115 "ldrs" # asmopcode # "\t$Rt, [$Rn, $Rm, $Ext]",
3118 def : InstAlias<"ldrs" # asmopcode # " $Rt, [$Rn, $Rm]",
3119 (!cast<Instruction>(prefix # "w_Xm_RegOffset") GPR32:$Rt, GPR64xsp:$Rn,
3122 def : InstAlias<"ldrs" # asmopcode # " $Rt, [$Rn, $Rm]",
3123 (!cast<Instruction>(prefix # "x_Xm_RegOffset") GPR64:$Rt, GPR64xsp:$Rn,
3127 let mayLoad = 1 in {
3129 def w_U : A64I_LSunalimm<size, 0b0, 0b11,
3131 (ins GPR64xsp:$Rn, simm9:$SImm9),
3132 "ldurs" # asmopcode # "\t$Rt, [$Rn, $SImm9]",
3135 def x_U : A64I_LSunalimm<size, 0b0, 0b10,
3137 (ins GPR64xsp:$Rn, simm9:$SImm9),
3138 "ldurs" # asmopcode # "\t$Rt, [$Rn, $SImm9]",
3143 def w_PostInd : A64I_LSpostind<size, 0b0, 0b11,
3144 (outs GPR32:$Rt, GPR64xsp:$Rn_wb),
3145 (ins GPR64xsp:$Rn, simm9:$SImm9),
3146 "ldrs" # asmopcode # "\t$Rt, [$Rn], $SImm9",
3148 let Constraints = "$Rn = $Rn_wb";
3149 let DecoderMethod = "DecodeSingleIndexedInstruction";
3152 def x_PostInd : A64I_LSpostind<size, 0b0, 0b10,
3153 (outs GPR64:$Rt, GPR64xsp:$Rn_wb),
3154 (ins GPR64xsp:$Rn, simm9:$SImm9),
3155 "ldrs" # asmopcode # "\t$Rt, [$Rn], $SImm9",
3157 let Constraints = "$Rn = $Rn_wb";
3158 let DecoderMethod = "DecodeSingleIndexedInstruction";
3162 def w_PreInd : A64I_LSpreind<size, 0b0, 0b11,
3163 (outs GPR32:$Rt, GPR64xsp:$Rn_wb),
3164 (ins GPR64xsp:$Rn, simm9:$SImm9),
3165 "ldrs" # asmopcode # "\t$Rt, [$Rn, $SImm9]!",
3167 let Constraints = "$Rn = $Rn_wb";
3168 let DecoderMethod = "DecodeSingleIndexedInstruction";
3171 def x_PreInd : A64I_LSpreind<size, 0b0, 0b10,
3172 (outs GPR64:$Rt, GPR64xsp:$Rn_wb),
3173 (ins GPR64xsp:$Rn, simm9:$SImm9),
3174 "ldrs" # asmopcode # "\t$Rt, [$Rn, $SImm9]!",
3176 let Constraints = "$Rn = $Rn_wb";
3177 let DecoderMethod = "DecodeSingleIndexedInstruction";
3179 } // let mayLoad = 1
3183 defm LDRSB : A64I_LDR_signed<0b00, "b", byte_addrparams, "LDRSB">;
3185 defm LDRSH : A64I_LDR_signed<0b01, "h", hword_addrparams, "LDRSH">;
3187 // LDRSW: load a 32-bit register, sign-extending to 64-bits.
3189 : A64I_LSunsigimm<0b10, 0b0, 0b10,
3191 (ins GPR64xsp:$Rn, word_uimm12:$UImm12),
3192 "ldrsw\t$Rt, [$Rn, $UImm12]",
3196 def : InstAlias<"ldrsw $Rt, [$Rn]", (LDRSWx GPR64:$Rt, GPR64xsp:$Rn, 0)>;
3198 let mayLoad = 1 in {
3199 def LDRSWx_Wm_RegOffset : A64I_LSregoff<0b10, 0b0, 0b10, 0b0,
3201 (ins GPR64xsp:$Rn, GPR32:$Rm, word_Wm_regext:$Ext),
3202 "ldrsw\t$Rt, [$Rn, $Rm, $Ext]",
3205 def LDRSWx_Xm_RegOffset : A64I_LSregoff<0b10, 0b0, 0b10, 0b1,
3207 (ins GPR64xsp:$Rn, GPR64:$Rm, word_Xm_regext:$Ext),
3208 "ldrsw\t$Rt, [$Rn, $Rm, $Ext]",
3211 def : InstAlias<"ldrsw $Rt, [$Rn, $Rm]",
3212 (LDRSWx_Xm_RegOffset GPR64:$Rt, GPR64xsp:$Rn, GPR64:$Rm, 2)>;
3216 : A64I_LSunalimm<0b10, 0b0, 0b10,
3218 (ins GPR64xsp:$Rn, simm9:$SImm9),
3219 "ldursw\t$Rt, [$Rn, $SImm9]",
3223 def : InstAlias<"ldursw $Rt, [$Rn]", (LDURSWx GPR64:$Rt, GPR64xsp:$Rn, 0)>;
3226 : A64I_LSpostind<0b10, 0b0, 0b10,
3227 (outs GPR64:$Rt, GPR64xsp:$Rn_wb),
3228 (ins GPR64xsp:$Rn, simm9:$SImm9),
3229 "ldrsw\t$Rt, [$Rn], $SImm9",
3232 let Constraints = "$Rn = $Rn_wb";
3233 let DecoderMethod = "DecodeSingleIndexedInstruction";
3236 def LDRSWx_PreInd : A64I_LSpreind<0b10, 0b0, 0b10,
3237 (outs GPR64:$Rt, GPR64xsp:$Rn_wb),
3238 (ins GPR64xsp:$Rn, simm9:$SImm9),
3239 "ldrsw\t$Rt, [$Rn, $SImm9]!",
3242 let Constraints = "$Rn = $Rn_wb";
3243 let DecoderMethod = "DecodeSingleIndexedInstruction";
3246 //===------------------------------
3247 // 2.4 Prefetch operations
3248 //===------------------------------
3250 def PRFM : A64I_LSunsigimm<0b11, 0b0, 0b10, (outs),
3251 (ins prefetch_op:$Rt, GPR64xsp:$Rn, dword_uimm12:$UImm12),
3252 "prfm\t$Rt, [$Rn, $UImm12]",
3256 def : InstAlias<"prfm $Rt, [$Rn]",
3257 (PRFM prefetch_op:$Rt, GPR64xsp:$Rn, 0)>;
3259 let mayLoad = 1 in {
3260 def PRFM_Wm_RegOffset : A64I_LSregoff<0b11, 0b0, 0b10, 0b0, (outs),
3261 (ins prefetch_op:$Rt, GPR64xsp:$Rn,
3262 GPR32:$Rm, dword_Wm_regext:$Ext),
3263 "prfm\t$Rt, [$Rn, $Rm, $Ext]",
3265 def PRFM_Xm_RegOffset : A64I_LSregoff<0b11, 0b0, 0b10, 0b1, (outs),
3266 (ins prefetch_op:$Rt, GPR64xsp:$Rn,
3267 GPR64:$Rm, dword_Xm_regext:$Ext),
3268 "prfm\t$Rt, [$Rn, $Rm, $Ext]",
3272 def : InstAlias<"prfm $Rt, [$Rn, $Rm]",
3273 (PRFM_Xm_RegOffset prefetch_op:$Rt, GPR64xsp:$Rn,
3277 def PRFUM : A64I_LSunalimm<0b11, 0b0, 0b10, (outs),
3278 (ins prefetch_op:$Rt, GPR64xsp:$Rn, simm9:$SImm9),
3279 "prfum\t$Rt, [$Rn, $SImm9]",
3283 def : InstAlias<"prfum $Rt, [$Rn]",
3284 (PRFUM prefetch_op:$Rt, GPR64xsp:$Rn, 0)>;
3286 //===----------------------------------------------------------------------===//
3287 // Load-store register (unprivileged) instructions
3288 //===----------------------------------------------------------------------===//
3289 // Contains: LDTRB, LDTRH, LDTRSB, LDTRSH, LDTRSW, STTR, STTRB and STTRH
3291 // These instructions very much mirror the "unscaled immediate" loads, but since
3292 // there are no floating-point variants we need to split them out into their own
3293 // section to avoid instantiation of "ldtr d0, [sp]" etc.
3295 multiclass A64I_LDTRSTTR<bits<2> size, string asmsuffix, RegisterClass GPR,
3297 def _UnPriv_STR : A64I_LSunpriv<size, 0b0, 0b00,
3298 (outs), (ins GPR:$Rt, GPR64xsp:$Rn, simm9:$SImm9),
3299 "sttr" # asmsuffix # "\t$Rt, [$Rn, $SImm9]",
3304 def : InstAlias<"sttr" # asmsuffix # " $Rt, [$Rn]",
3305 (!cast<Instruction>(prefix # "_UnPriv_STR") GPR:$Rt, GPR64xsp:$Rn, 0)>;
3307 def _UnPriv_LDR : A64I_LSunpriv<size, 0b0, 0b01,
3308 (outs GPR:$Rt), (ins GPR64xsp:$Rn, simm9:$SImm9),
3309 "ldtr" # asmsuffix # "\t$Rt, [$Rn, $SImm9]",
3314 def : InstAlias<"ldtr" # asmsuffix # " $Rt, [$Rn]",
3315 (!cast<Instruction>(prefix # "_UnPriv_LDR") GPR:$Rt, GPR64xsp:$Rn, 0)>;
3319 // STTRB/LDTRB: First define the instructions
3320 defm LS8 : A64I_LDTRSTTR<0b00, "b", GPR32, "LS8">;
3323 defm LS16 : A64I_LDTRSTTR<0b01, "h", GPR32, "LS16">;
3325 // STTR/LDTR to/from a W register
3326 defm LS32 : A64I_LDTRSTTR<0b10, "", GPR32, "LS32">;
3328 // STTR/LDTR to/from an X register
3329 defm LS64 : A64I_LDTRSTTR<0b11, "", GPR64, "LS64">;
3331 // Now a class for the signed instructions that can go to either 32 or 64
3333 multiclass A64I_LDTR_signed<bits<2> size, string asmopcode, string prefix> {
3334 let mayLoad = 1 in {
3335 def w : A64I_LSunpriv<size, 0b0, 0b11,
3337 (ins GPR64xsp:$Rn, simm9:$SImm9),
3338 "ldtrs" # asmopcode # "\t$Rt, [$Rn, $SImm9]",
3341 def x : A64I_LSunpriv<size, 0b0, 0b10,
3343 (ins GPR64xsp:$Rn, simm9:$SImm9),
3344 "ldtrs" # asmopcode # "\t$Rt, [$Rn, $SImm9]",
3348 def : InstAlias<"ldtrs" # asmopcode # " $Rt, [$Rn]",
3349 (!cast<Instruction>(prefix # "w") GPR32:$Rt, GPR64xsp:$Rn, 0)>;
3351 def : InstAlias<"ldtrs" # asmopcode # " $Rt, [$Rn]",
3352 (!cast<Instruction>(prefix # "x") GPR64:$Rt, GPR64xsp:$Rn, 0)>;
3357 defm LDTRSB : A64I_LDTR_signed<0b00, "b", "LDTRSB">;
3359 defm LDTRSH : A64I_LDTR_signed<0b01, "h", "LDTRSH">;
3361 // And finally LDTRSW which only goes to 64 bits.
3362 def LDTRSWx : A64I_LSunpriv<0b10, 0b0, 0b10,
3364 (ins GPR64xsp:$Rn, simm9:$SImm9),
3365 "ldtrsw\t$Rt, [$Rn, $SImm9]",
3369 def : InstAlias<"ldtrsw $Rt, [$Rn]", (LDTRSWx GPR64:$Rt, GPR64xsp:$Rn, 0)>;
3371 //===----------------------------------------------------------------------===//
3372 // Load-store register pair (offset) instructions
3373 //===----------------------------------------------------------------------===//
3377 //===----------------------------------------------------------------------===//
3378 // Load-store register pair (post-indexed) instructions
3379 //===----------------------------------------------------------------------===//
3380 // Contains: STP, LDP, LDPSW
3384 //===----------------------------------------------------------------------===//
3385 // Load-store register pair (pre-indexed) instructions
3386 //===----------------------------------------------------------------------===//
3387 // Contains: STP, LDP, LDPSW
3391 //===----------------------------------------------------------------------===//
3392 // Load-store non-temporal register pair (offset) instructions
3393 //===----------------------------------------------------------------------===//
3394 // Contains: STNP, LDNP
3397 // Anything that creates an MCInst (Decoding, selection and AsmParsing) has to
3398 // know the access size via some means. An isolated operand does not have this
3399 // information unless told from here, which means we need separate tablegen
3400 // Operands for each access size. This multiclass takes care of instantiating
3401 // the correct template functions in the rest of the backend.
3403 multiclass offsets_simm7<string MemSize, string prefix> {
3404 // The bare signed 7-bit immediate is used in post-indexed instructions, but
3405 // because of the scaling performed a generic "simm7" operand isn't
3406 // appropriate here either.
3407 def simm7_asmoperand : AsmOperandClass {
3408 let Name = "SImm7_Scaled" # MemSize;
3409 let PredicateMethod = "isSImm7Scaled<" # MemSize # ">";
3410 let RenderMethod = "addSImm7ScaledOperands<" # MemSize # ">";
3411 let DiagnosticType = "LoadStoreSImm7_" # MemSize;
3414 def simm7 : Operand<i64> {
3415 let PrintMethod = "printSImm7ScaledOperand<" # MemSize # ">";
3416 let ParserMatchClass = !cast<AsmOperandClass>(prefix # "simm7_asmoperand");
3420 defm word_ : offsets_simm7<"4", "word_">;
3421 defm dword_ : offsets_simm7<"8", "dword_">;
3422 defm qword_ : offsets_simm7<"16", "qword_">;
3424 multiclass A64I_LSPsimple<bits<2> opc, bit v, RegisterClass SomeReg,
3425 Operand simm7, string prefix> {
3426 def _STR : A64I_LSPoffset<opc, v, 0b0, (outs),
3427 (ins SomeReg:$Rt, SomeReg:$Rt2, GPR64xsp:$Rn, simm7:$SImm7),
3428 "stp\t$Rt, $Rt2, [$Rn, $SImm7]", [], NoItinerary> {
3430 let DecoderMethod = "DecodeLDSTPairInstruction";
3432 def : InstAlias<"stp $Rt, $Rt2, [$Rn]",
3433 (!cast<Instruction>(prefix # "_STR") SomeReg:$Rt,
3434 SomeReg:$Rt2, GPR64xsp:$Rn, 0)>;
3436 def _LDR : A64I_LSPoffset<opc, v, 0b1,
3437 (outs SomeReg:$Rt, SomeReg:$Rt2),
3438 (ins GPR64xsp:$Rn, simm7:$SImm7),
3439 "ldp\t$Rt, $Rt2, [$Rn, $SImm7]", [], NoItinerary> {
3441 let DecoderMethod = "DecodeLDSTPairInstruction";
3443 def : InstAlias<"ldp $Rt, $Rt2, [$Rn]",
3444 (!cast<Instruction>(prefix # "_LDR") SomeReg:$Rt,
3445 SomeReg:$Rt2, GPR64xsp:$Rn, 0)>;
3447 def _PostInd_STR : A64I_LSPpostind<opc, v, 0b0,
3448 (outs GPR64xsp:$Rn_wb),
3449 (ins SomeReg:$Rt, SomeReg:$Rt2,
3452 "stp\t$Rt, $Rt2, [$Rn], $SImm7",
3455 let Constraints = "$Rn = $Rn_wb";
3457 // Decoder only needed for unpredictability checking (FIXME).
3458 let DecoderMethod = "DecodeLDSTPairInstruction";
3461 def _PostInd_LDR : A64I_LSPpostind<opc, v, 0b1,
3462 (outs SomeReg:$Rt, SomeReg:$Rt2, GPR64xsp:$Rn_wb),
3463 (ins GPR64xsp:$Rn, simm7:$SImm7),
3464 "ldp\t$Rt, $Rt2, [$Rn], $SImm7",
3467 let Constraints = "$Rn = $Rn_wb";
3468 let DecoderMethod = "DecodeLDSTPairInstruction";
3471 def _PreInd_STR : A64I_LSPpreind<opc, v, 0b0, (outs GPR64xsp:$Rn_wb),
3472 (ins SomeReg:$Rt, SomeReg:$Rt2, GPR64xsp:$Rn, simm7:$SImm7),
3473 "stp\t$Rt, $Rt2, [$Rn, $SImm7]!",
3476 let Constraints = "$Rn = $Rn_wb";
3477 let DecoderMethod = "DecodeLDSTPairInstruction";
3480 def _PreInd_LDR : A64I_LSPpreind<opc, v, 0b1,
3481 (outs SomeReg:$Rt, SomeReg:$Rt2, GPR64xsp:$Rn_wb),
3482 (ins GPR64xsp:$Rn, simm7:$SImm7),
3483 "ldp\t$Rt, $Rt2, [$Rn, $SImm7]!",
3486 let Constraints = "$Rn = $Rn_wb";
3487 let DecoderMethod = "DecodeLDSTPairInstruction";
3490 def _NonTemp_STR : A64I_LSPnontemp<opc, v, 0b0, (outs),
3491 (ins SomeReg:$Rt, SomeReg:$Rt2, GPR64xsp:$Rn, simm7:$SImm7),
3492 "stnp\t$Rt, $Rt2, [$Rn, $SImm7]", [], NoItinerary> {
3494 let DecoderMethod = "DecodeLDSTPairInstruction";
3496 def : InstAlias<"stnp $Rt, $Rt2, [$Rn]",
3497 (!cast<Instruction>(prefix # "_NonTemp_STR") SomeReg:$Rt,
3498 SomeReg:$Rt2, GPR64xsp:$Rn, 0)>;
3500 def _NonTemp_LDR : A64I_LSPnontemp<opc, v, 0b1,
3501 (outs SomeReg:$Rt, SomeReg:$Rt2),
3502 (ins GPR64xsp:$Rn, simm7:$SImm7),
3503 "ldnp\t$Rt, $Rt2, [$Rn, $SImm7]", [], NoItinerary> {
3505 let DecoderMethod = "DecodeLDSTPairInstruction";
3507 def : InstAlias<"ldnp $Rt, $Rt2, [$Rn]",
3508 (!cast<Instruction>(prefix # "_NonTemp_LDR") SomeReg:$Rt,
3509 SomeReg:$Rt2, GPR64xsp:$Rn, 0)>;
3514 defm LSPair32 : A64I_LSPsimple<0b00, 0b0, GPR32, word_simm7, "LSPair32">;
3515 defm LSPair64 : A64I_LSPsimple<0b10, 0b0, GPR64, dword_simm7, "LSPair64">;
3516 defm LSFPPair32 : A64I_LSPsimple<0b00, 0b1, FPR32, word_simm7, "LSFPPair32">;
3517 defm LSFPPair64 : A64I_LSPsimple<0b01, 0b1, FPR64, dword_simm7, "LSFPPair64">;
3518 defm LSFPPair128 : A64I_LSPsimple<0b10, 0b1, FPR128, qword_simm7,
3522 def LDPSWx : A64I_LSPoffset<0b01, 0b0, 0b1,
3523 (outs GPR64:$Rt, GPR64:$Rt2),
3524 (ins GPR64xsp:$Rn, word_simm7:$SImm7),
3525 "ldpsw\t$Rt, $Rt2, [$Rn, $SImm7]", [], NoItinerary> {
3527 let DecoderMethod = "DecodeLDSTPairInstruction";
3529 def : InstAlias<"ldpsw $Rt, $Rt2, [$Rn]",
3530 (LDPSWx GPR64:$Rt, GPR64:$Rt2, GPR64xsp:$Rn, 0)>;
3532 def LDPSWx_PostInd : A64I_LSPpostind<0b01, 0b0, 0b1,
3533 (outs GPR64:$Rt, GPR64:$Rt2, GPR64:$Rn_wb),
3534 (ins GPR64xsp:$Rn, word_simm7:$SImm7),
3535 "ldpsw\t$Rt, $Rt2, [$Rn], $SImm7",
3538 let Constraints = "$Rn = $Rn_wb";
3539 let DecoderMethod = "DecodeLDSTPairInstruction";
3542 def LDPSWx_PreInd : A64I_LSPpreind<0b01, 0b0, 0b1,
3543 (outs GPR64:$Rt, GPR64:$Rt2, GPR64:$Rn_wb),
3544 (ins GPR64xsp:$Rn, word_simm7:$SImm7),
3545 "ldpsw\t$Rt, $Rt2, [$Rn, $SImm7]!",
3548 let Constraints = "$Rn = $Rn_wb";
3549 let DecoderMethod = "DecodeLDSTPairInstruction";
3552 //===----------------------------------------------------------------------===//
3553 // Logical (immediate) instructions
3554 //===----------------------------------------------------------------------===//
3555 // Contains: AND, ORR, EOR, ANDS, + aliases TST, MOV
3557 multiclass logical_imm_operands<string prefix, string note,
3558 int size, ValueType VT> {
3559 def _asmoperand : AsmOperandClass {
3560 let Name = "LogicalImm" # note # size;
3561 let PredicateMethod = "isLogicalImm" # note # "<" # size # ">";
3562 let RenderMethod = "addLogicalImmOperands<" # size # ">";
3563 let DiagnosticType = "LogicalSecondSource";
3567 : Operand<VT>, ComplexPattern<VT, 1, "SelectLogicalImm", [imm]> {
3568 let ParserMatchClass = !cast<AsmOperandClass>(prefix # "_asmoperand");
3569 let PrintMethod = "printLogicalImmOperand<" # size # ">";
3570 let DecoderMethod = "DecodeLogicalImmOperand<" # size # ">";
3574 defm logical_imm32 : logical_imm_operands<"logical_imm32", "", 32, i32>;
3575 defm logical_imm64 : logical_imm_operands<"logical_imm64", "", 64, i64>;
3577 // The mov versions only differ in assembly parsing, where they
3578 // exclude values representable with either MOVZ or MOVN.
3579 defm logical_imm32_mov
3580 : logical_imm_operands<"logical_imm32_mov", "MOV", 32, i32>;
3581 defm logical_imm64_mov
3582 : logical_imm_operands<"logical_imm64_mov", "MOV", 64, i64>;
3585 multiclass A64I_logimmSizes<bits<2> opc, string asmop, SDNode opnode> {
3586 def wwi : A64I_logicalimm<0b0, opc, (outs GPR32wsp:$Rd),
3587 (ins GPR32:$Rn, logical_imm32_operand:$Imm),
3588 !strconcat(asmop, "\t$Rd, $Rn, $Imm"),
3590 (opnode GPR32:$Rn, logical_imm32_operand:$Imm))],
3593 def xxi : A64I_logicalimm<0b1, opc, (outs GPR64xsp:$Rd),
3594 (ins GPR64:$Rn, logical_imm64_operand:$Imm),
3595 !strconcat(asmop, "\t$Rd, $Rn, $Imm"),
3597 (opnode GPR64:$Rn, logical_imm64_operand:$Imm))],
3601 defm AND : A64I_logimmSizes<0b00, "and", and>;
3602 defm ORR : A64I_logimmSizes<0b01, "orr", or>;
3603 defm EOR : A64I_logimmSizes<0b10, "eor", xor>;
3605 let Defs = [NZCV] in {
3606 def ANDSwwi : A64I_logicalimm<0b0, 0b11, (outs GPR32:$Rd),
3607 (ins GPR32:$Rn, logical_imm32_operand:$Imm),
3608 "ands\t$Rd, $Rn, $Imm",
3611 def ANDSxxi : A64I_logicalimm<0b1, 0b11, (outs GPR64:$Rd),
3612 (ins GPR64:$Rn, logical_imm64_operand:$Imm),
3613 "ands\t$Rd, $Rn, $Imm",
3618 def : InstAlias<"tst $Rn, $Imm",
3619 (ANDSwwi WZR, GPR32:$Rn, logical_imm32_operand:$Imm)>;
3620 def : InstAlias<"tst $Rn, $Imm",
3621 (ANDSxxi XZR, GPR64:$Rn, logical_imm64_operand:$Imm)>;
3622 def : InstAlias<"mov $Rd, $Imm",
3623 (ORRwwi GPR32wsp:$Rd, WZR, logical_imm32_mov_operand:$Imm)>;
3624 def : InstAlias<"mov $Rd, $Imm",
3625 (ORRxxi GPR64xsp:$Rd, XZR, logical_imm64_mov_operand:$Imm)>;
3627 //===----------------------------------------------------------------------===//
3628 // Logical (shifted register) instructions
3629 //===----------------------------------------------------------------------===//
3630 // Contains: AND, BIC, ORR, ORN, EOR, EON, ANDS, BICS + aliases TST, MVN, MOV
3632 // Operand for optimizing (icmp (and LHS, RHS), 0, SomeCode). In theory "ANDS"
3633 // behaves differently for unsigned comparisons, so we defensively only allow
3634 // signed or n/a as the operand. In practice "unsigned greater than 0" is "not
3635 // equal to 0" and LLVM gives us this.
3636 def signed_cond : PatLeaf<(cond), [{
3637 return !isUnsignedIntSetCC(N->get());
3641 // These instructions share their "shift" operands with add/sub (shifted
3642 // register instructions). They are defined there.
3644 // N.b. the commutable parameter is just !N. It will be first against the wall
3645 // when the revolution comes.
3646 multiclass logical_shifts<string prefix, bit sf, bits<2> opc,
3647 bit N, bit commutable,
3648 string asmop, SDPatternOperator opfrag, string sty,
3649 RegisterClass GPR, list<Register> defs> {
3650 let isCommutable = commutable, Defs = defs in {
3651 def _lsl : A64I_logicalshift<sf, opc, 0b00, N,
3653 (ins GPR:$Rn, GPR:$Rm,
3654 !cast<Operand>("lsl_operand_" # sty):$Imm6),
3655 !strconcat(asmop, "\t$Rd, $Rn, $Rm, $Imm6"),
3656 [(set GPR:$Rd, (opfrag GPR:$Rn, (shl GPR:$Rm,
3657 !cast<Operand>("lsl_operand_" # sty):$Imm6))
3661 def _lsr : A64I_logicalshift<sf, opc, 0b01, N,
3663 (ins GPR:$Rn, GPR:$Rm,
3664 !cast<Operand>("lsr_operand_" # sty):$Imm6),
3665 !strconcat(asmop, "\t$Rd, $Rn, $Rm, $Imm6"),
3666 [(set GPR:$Rd, (opfrag GPR:$Rn, (srl GPR:$Rm,
3667 !cast<Operand>("lsr_operand_" # sty):$Imm6))
3671 def _asr : A64I_logicalshift<sf, opc, 0b10, N,
3673 (ins GPR:$Rn, GPR:$Rm,
3674 !cast<Operand>("asr_operand_" # sty):$Imm6),
3675 !strconcat(asmop, "\t$Rd, $Rn, $Rm, $Imm6"),
3676 [(set GPR:$Rd, (opfrag GPR:$Rn, (sra GPR:$Rm,
3677 !cast<Operand>("asr_operand_" # sty):$Imm6))
3681 def _ror : A64I_logicalshift<sf, opc, 0b11, N,
3683 (ins GPR:$Rn, GPR:$Rm,
3684 !cast<Operand>("ror_operand_" # sty):$Imm6),
3685 !strconcat(asmop, "\t$Rd, $Rn, $Rm, $Imm6"),
3686 [(set GPR:$Rd, (opfrag GPR:$Rn, (rotr GPR:$Rm,
3687 !cast<Operand>("ror_operand_" # sty):$Imm6))
3693 : InstAlias<!strconcat(asmop, " $Rd, $Rn, $Rm"),
3694 (!cast<Instruction>(prefix # "_lsl") GPR:$Rd, GPR:$Rn,
3697 def : Pat<(opfrag GPR:$Rn, GPR:$Rm),
3698 (!cast<Instruction>(prefix # "_lsl") GPR:$Rn, GPR:$Rm, 0)>;
3701 multiclass logical_sizes<string prefix, bits<2> opc, bit N, bit commutable,
3702 string asmop, SDPatternOperator opfrag,
3703 list<Register> defs> {
3704 defm xxx : logical_shifts<prefix # "xxx", 0b1, opc, N,
3705 commutable, asmop, opfrag, "i64", GPR64, defs>;
3706 defm www : logical_shifts<prefix # "www", 0b0, opc, N,
3707 commutable, asmop, opfrag, "i32", GPR32, defs>;
3711 defm AND : logical_sizes<"AND", 0b00, 0b0, 0b1, "and", and, []>;
3712 defm ORR : logical_sizes<"ORR", 0b01, 0b0, 0b1, "orr", or, []>;
3713 defm EOR : logical_sizes<"EOR", 0b10, 0b0, 0b1, "eor", xor, []>;
3714 defm ANDS : logical_sizes<"ANDS", 0b11, 0b0, 0b1, "ands",
3715 PatFrag<(ops node:$lhs, node:$rhs), (and node:$lhs, node:$rhs),
3716 [{ (void)N; return false; }]>,
3719 defm BIC : logical_sizes<"BIC", 0b00, 0b1, 0b0, "bic",
3720 PatFrag<(ops node:$lhs, node:$rhs),
3721 (and node:$lhs, (not node:$rhs))>, []>;
3722 defm ORN : logical_sizes<"ORN", 0b01, 0b1, 0b0, "orn",
3723 PatFrag<(ops node:$lhs, node:$rhs),
3724 (or node:$lhs, (not node:$rhs))>, []>;
3725 defm EON : logical_sizes<"EON", 0b10, 0b1, 0b0, "eon",
3726 PatFrag<(ops node:$lhs, node:$rhs),
3727 (xor node:$lhs, (not node:$rhs))>, []>;
3728 defm BICS : logical_sizes<"BICS", 0b11, 0b1, 0b0, "bics",
3729 PatFrag<(ops node:$lhs, node:$rhs),
3730 (and node:$lhs, (not node:$rhs)),
3731 [{ (void)N; return false; }]>,
3734 multiclass tst_shifts<string prefix, bit sf, string sty, RegisterClass GPR> {
3735 let isCommutable = 1, Rd = 0b11111, Defs = [NZCV] in {
3736 def _lsl : A64I_logicalshift<sf, 0b11, 0b00, 0b0,
3738 (ins GPR:$Rn, GPR:$Rm,
3739 !cast<Operand>("lsl_operand_" # sty):$Imm6),
3740 "tst\t$Rn, $Rm, $Imm6",
3741 [(set NZCV, (A64setcc (and GPR:$Rn, (shl GPR:$Rm,
3742 !cast<Operand>("lsl_operand_" # sty):$Imm6)),
3747 def _lsr : A64I_logicalshift<sf, 0b11, 0b01, 0b0,
3749 (ins GPR:$Rn, GPR:$Rm,
3750 !cast<Operand>("lsr_operand_" # sty):$Imm6),
3751 "tst\t$Rn, $Rm, $Imm6",
3752 [(set NZCV, (A64setcc (and GPR:$Rn, (srl GPR:$Rm,
3753 !cast<Operand>("lsr_operand_" # sty):$Imm6)),
3757 def _asr : A64I_logicalshift<sf, 0b11, 0b10, 0b0,
3759 (ins GPR:$Rn, GPR:$Rm,
3760 !cast<Operand>("asr_operand_" # sty):$Imm6),
3761 "tst\t$Rn, $Rm, $Imm6",
3762 [(set NZCV, (A64setcc (and GPR:$Rn, (sra GPR:$Rm,
3763 !cast<Operand>("asr_operand_" # sty):$Imm6)),
3767 def _ror : A64I_logicalshift<sf, 0b11, 0b11, 0b0,
3769 (ins GPR:$Rn, GPR:$Rm,
3770 !cast<Operand>("ror_operand_" # sty):$Imm6),
3771 "tst\t$Rn, $Rm, $Imm6",
3772 [(set NZCV, (A64setcc (and GPR:$Rn, (rotr GPR:$Rm,
3773 !cast<Operand>("ror_operand_" # sty):$Imm6)),
3778 def _noshift : InstAlias<"tst $Rn, $Rm",
3779 (!cast<Instruction>(prefix # "_lsl") GPR:$Rn, GPR:$Rm, 0)>;
3781 def : Pat<(A64setcc (and GPR:$Rn, GPR:$Rm), 0, signed_cond),
3782 (!cast<Instruction>(prefix # "_lsl") GPR:$Rn, GPR:$Rm, 0)>;
3785 defm TSTxx : tst_shifts<"TSTxx", 0b1, "i64", GPR64>;
3786 defm TSTww : tst_shifts<"TSTww", 0b0, "i32", GPR32>;
3789 multiclass mvn_shifts<string prefix, bit sf, string sty, RegisterClass GPR> {
3790 let isCommutable = 0, Rn = 0b11111 in {
3791 def _lsl : A64I_logicalshift<sf, 0b01, 0b00, 0b1,
3794 !cast<Operand>("lsl_operand_" # sty):$Imm6),
3795 "mvn\t$Rd, $Rm, $Imm6",
3796 [(set GPR:$Rd, (not (shl GPR:$Rm,
3797 !cast<Operand>("lsl_operand_" # sty):$Imm6)))],
3801 def _lsr : A64I_logicalshift<sf, 0b01, 0b01, 0b1,
3804 !cast<Operand>("lsr_operand_" # sty):$Imm6),
3805 "mvn\t$Rd, $Rm, $Imm6",
3806 [(set GPR:$Rd, (not (srl GPR:$Rm,
3807 !cast<Operand>("lsr_operand_" # sty):$Imm6)))],
3810 def _asr : A64I_logicalshift<sf, 0b01, 0b10, 0b1,
3813 !cast<Operand>("asr_operand_" # sty):$Imm6),
3814 "mvn\t$Rd, $Rm, $Imm6",
3815 [(set GPR:$Rd, (not (sra GPR:$Rm,
3816 !cast<Operand>("asr_operand_" # sty):$Imm6)))],
3819 def _ror : A64I_logicalshift<sf, 0b01, 0b11, 0b1,
3822 !cast<Operand>("ror_operand_" # sty):$Imm6),
3823 "mvn\t$Rd, $Rm, $Imm6",
3824 [(set GPR:$Rd, (not (rotr GPR:$Rm,
3825 !cast<Operand>("lsl_operand_" # sty):$Imm6)))],
3829 def _noshift : InstAlias<"mvn $Rn, $Rm",
3830 (!cast<Instruction>(prefix # "_lsl") GPR:$Rn, GPR:$Rm, 0)>;
3832 def : Pat<(not GPR:$Rm),
3833 (!cast<Instruction>(prefix # "_lsl") GPR:$Rm, 0)>;
3836 defm MVNxx : mvn_shifts<"MVNxx", 0b1, "i64", GPR64>;
3837 defm MVNww : mvn_shifts<"MVNww", 0b0, "i32", GPR32>;
3839 def MOVxx :InstAlias<"mov $Rd, $Rm", (ORRxxx_lsl GPR64:$Rd, XZR, GPR64:$Rm, 0)>;
3840 def MOVww :InstAlias<"mov $Rd, $Rm", (ORRwww_lsl GPR32:$Rd, WZR, GPR32:$Rm, 0)>;
3842 //===----------------------------------------------------------------------===//
3843 // Move wide (immediate) instructions
3844 //===----------------------------------------------------------------------===//
3845 // Contains: MOVN, MOVZ, MOVK + MOV aliases
3847 // A wide variety of different relocations are needed for variants of these
3848 // instructions, so it turns out that we need a different operand for all of
3850 multiclass movw_operands<string prefix, string instname, int width> {
3851 def _imm_asmoperand : AsmOperandClass {
3852 let Name = instname # width # "Shifted" # shift;
3853 let PredicateMethod = "is" # instname # width # "Imm";
3854 let RenderMethod = "addMoveWideImmOperands";
3855 let ParserMethod = "ParseImmWithLSLOperand";
3856 let DiagnosticType = "MOVWUImm16";
3859 def _imm : Operand<i32> {
3860 let ParserMatchClass = !cast<AsmOperandClass>(prefix # "_imm_asmoperand");
3861 let PrintMethod = "printMoveWideImmOperand";
3862 let EncoderMethod = "getMoveWideImmOpValue";
3863 let DecoderMethod = "DecodeMoveWideImmOperand<" # width # ">";
3865 let MIOperandInfo = (ops uimm16:$UImm16, imm:$Shift);
3869 defm movn32 : movw_operands<"movn32", "MOVN", 32>;
3870 defm movn64 : movw_operands<"movn64", "MOVN", 64>;
3871 defm movz32 : movw_operands<"movz32", "MOVZ", 32>;
3872 defm movz64 : movw_operands<"movz64", "MOVZ", 64>;
3873 defm movk32 : movw_operands<"movk32", "MOVK", 32>;
3874 defm movk64 : movw_operands<"movk64", "MOVK", 64>;
3876 multiclass A64I_movwSizes<bits<2> opc, string asmop, dag ins32bit,
3879 def wii : A64I_movw<0b0, opc, (outs GPR32:$Rd), ins32bit,
3880 !strconcat(asmop, "\t$Rd, $FullImm"),
3883 let UImm16 = FullImm{15-0};
3884 let Shift = FullImm{17-16};
3887 def xii : A64I_movw<0b1, opc, (outs GPR64:$Rd), ins64bit,
3888 !strconcat(asmop, "\t$Rd, $FullImm"),
3891 let UImm16 = FullImm{15-0};
3892 let Shift = FullImm{17-16};
3896 let isMoveImm = 1, isReMaterializable = 1,
3897 isAsCheapAsAMove = 1, neverHasSideEffects = 1 in {
3898 defm MOVN : A64I_movwSizes<0b00, "movn",
3899 (ins movn32_imm:$FullImm),
3900 (ins movn64_imm:$FullImm)>;
3902 // Some relocations are able to convert between a MOVZ and a MOVN. If these
3903 // are applied the instruction must be emitted with the corresponding bits as
3904 // 0, which means a MOVZ needs to override that bit from the default.
3905 let PostEncoderMethod = "fixMOVZ" in
3906 defm MOVZ : A64I_movwSizes<0b10, "movz",
3907 (ins movz32_imm:$FullImm),
3908 (ins movz64_imm:$FullImm)>;
3911 let Constraints = "$src = $Rd" in
3912 defm MOVK : A64I_movwSizes<0b11, "movk",
3913 (ins GPR32:$src, movk32_imm:$FullImm),
3914 (ins GPR64:$src, movk64_imm:$FullImm)>;
3917 // And now the "MOV" aliases. These also need their own operands because what
3918 // they accept is completely different to what the base instructions accept.
3919 multiclass movalias_operand<string prefix, string basename,
3920 string immpredicate, int width> {
3921 def _asmoperand : AsmOperandClass {
3922 let Name = basename # width # "MovAlias";
3924 = "isMoveWideMovAlias<" # width # ", A64Imms::" # immpredicate # ">";
3926 = "addMoveWideMovAliasOperands<" # width # ", "
3927 # "A64Imms::" # immpredicate # ">";
3930 def _movimm : Operand<i32> {
3931 let ParserMatchClass = !cast<AsmOperandClass>(prefix # "_asmoperand");
3933 let MIOperandInfo = (ops uimm16:$UImm16, imm:$Shift);
3937 defm movz32 : movalias_operand<"movz32", "MOVZ", "isMOVZImm", 32>;
3938 defm movz64 : movalias_operand<"movz64", "MOVZ", "isMOVZImm", 64>;
3939 defm movn32 : movalias_operand<"movn32", "MOVN", "isOnlyMOVNImm", 32>;
3940 defm movn64 : movalias_operand<"movn64", "MOVN", "isOnlyMOVNImm", 64>;
3942 // FIXME: these are officially canonical aliases, but TableGen is too limited to
3943 // print them at the moment. I believe in this case an "AliasPredicate" method
3944 // will need to be implemented. to allow it, as well as the more generally
3945 // useful handling of non-register, non-constant operands.
3946 class movalias<Instruction INST, RegisterClass GPR, Operand operand>
3947 : InstAlias<"mov $Rd, $FullImm", (INST GPR:$Rd, operand:$FullImm)>;
3949 def : movalias<MOVZwii, GPR32, movz32_movimm>;
3950 def : movalias<MOVZxii, GPR64, movz64_movimm>;
3951 def : movalias<MOVNwii, GPR32, movn32_movimm>;
3952 def : movalias<MOVNxii, GPR64, movn64_movimm>;
3954 //===----------------------------------------------------------------------===//
3955 // PC-relative addressing instructions
3956 //===----------------------------------------------------------------------===//
3957 // Contains: ADR, ADRP
3959 def adr_label : Operand<i64> {
3960 let EncoderMethod = "getLabelOpValue<AArch64::fixup_a64_adr_prel>";
3962 // This label is a 21-bit offset from PC, unscaled
3963 let PrintMethod = "printLabelOperand<21, 1>";
3964 let ParserMatchClass = label_asmoperand<21, 1>;
3965 let OperandType = "OPERAND_PCREL";
3968 def adrp_label_asmoperand : AsmOperandClass {
3969 let Name = "AdrpLabel";
3970 let RenderMethod = "addLabelOperands<21, 4096>";
3971 let DiagnosticType = "Label";
3974 def adrp_label : Operand<i64> {
3975 let EncoderMethod = "getAdrpLabelOpValue";
3977 // This label is a 21-bit offset from PC, scaled by the page-size: 4096.
3978 let PrintMethod = "printLabelOperand<21, 4096>";
3979 let ParserMatchClass = adrp_label_asmoperand;
3980 let OperandType = "OPERAND_PCREL";
3983 let neverHasSideEffects = 1 in {
3984 def ADRxi : A64I_PCADR<0b0, (outs GPR64:$Rd), (ins adr_label:$Label),
3985 "adr\t$Rd, $Label", [], NoItinerary>;
3987 def ADRPxi : A64I_PCADR<0b1, (outs GPR64:$Rd), (ins adrp_label:$Label),
3988 "adrp\t$Rd, $Label", [], NoItinerary>;
3991 //===----------------------------------------------------------------------===//
3992 // System instructions
3993 //===----------------------------------------------------------------------===//
3994 // Contains: HINT, CLREX, DSB, DMB, ISB, MSR, SYS, SYSL, MRS
3995 // + aliases IC, DC, AT, TLBI, NOP, YIELD, WFE, WFI, SEV, SEVL
3997 // Op1 and Op2 fields are sometimes simple 3-bit unsigned immediate values.
3998 def uimm3_asmoperand : AsmOperandClass {
4000 let PredicateMethod = "isUImm<3>";
4001 let RenderMethod = "addImmOperands";
4002 let DiagnosticType = "UImm3";
4005 def uimm3 : Operand<i32> {
4006 let ParserMatchClass = uimm3_asmoperand;
4009 // The HINT alias can accept a simple unsigned 7-bit immediate.
4010 def uimm7_asmoperand : AsmOperandClass {
4012 let PredicateMethod = "isUImm<7>";
4013 let RenderMethod = "addImmOperands";
4014 let DiagnosticType = "UImm7";
4017 def uimm7 : Operand<i32> {
4018 let ParserMatchClass = uimm7_asmoperand;
4021 // Multiclass namedimm is defined with the prefetch operands. Most of these fit
4022 // into the NamedImmMapper scheme well: they either accept a named operand or
4023 // any immediate under a particular value (which may be 0, implying no immediate
4025 defm dbarrier : namedimm<"dbarrier", "A64DB::DBarrierMapper">;
4026 defm isb : namedimm<"isb", "A64ISB::ISBMapper">;
4027 defm ic : namedimm<"ic", "A64IC::ICMapper">;
4028 defm dc : namedimm<"dc", "A64DC::DCMapper">;
4029 defm at : namedimm<"at", "A64AT::ATMapper">;
4030 defm tlbi : namedimm<"tlbi", "A64TLBI::TLBIMapper">;
4032 // However, MRS and MSR are more complicated for a few reasons:
4033 // * There are ~1000 generic names S3_<op1>_<CRn>_<CRm>_<Op2> which have an
4034 // implementation-defined effect
4035 // * Most registers are shared, but some are read-only or write-only.
4036 // * There is a variant of MSR which accepts the same register name (SPSel),
4037 // but which would have a different encoding.
4039 // In principle these could be resolved in with more complicated subclasses of
4040 // NamedImmMapper, however that imposes an overhead on other "named
4041 // immediates". Both in concrete terms with virtual tables and in unnecessary
4044 // The solution adopted here is to take the MRS/MSR Mappers out of the usual
4045 // hierarchy (they're not derived from NamedImmMapper) and to add logic for
4046 // their special situation.
4047 def mrs_asmoperand : AsmOperandClass {
4049 let ParserMethod = "ParseSysRegOperand";
4050 let DiagnosticType = "MRS";
4053 def mrs_op : Operand<i32> {
4054 let ParserMatchClass = mrs_asmoperand;
4055 let PrintMethod = "printMRSOperand";
4056 let DecoderMethod = "DecodeMRSOperand";
4059 def msr_asmoperand : AsmOperandClass {
4060 let Name = "MSRWithReg";
4062 // Note that SPSel is valid for both this and the pstate operands, but with
4063 // different immediate encodings. This is why these operands provide a string
4064 // AArch64Operand rather than an immediate. The overlap is small enough that
4065 // it could be resolved with hackery now, but who can say in future?
4066 let ParserMethod = "ParseSysRegOperand";
4067 let DiagnosticType = "MSR";
4070 def msr_op : Operand<i32> {
4071 let ParserMatchClass = msr_asmoperand;
4072 let PrintMethod = "printMSROperand";
4073 let DecoderMethod = "DecodeMSROperand";
4076 def pstate_asmoperand : AsmOperandClass {
4077 let Name = "MSRPState";
4078 // See comment above about parser.
4079 let ParserMethod = "ParseSysRegOperand";
4080 let DiagnosticType = "MSR";
4083 def pstate_op : Operand<i32> {
4084 let ParserMatchClass = pstate_asmoperand;
4085 let PrintMethod = "printNamedImmOperand<A64PState::PStateMapper>";
4086 let DecoderMethod = "DecodeNamedImmOperand<A64PState::PStateMapper>";
4089 // When <CRn> is specified, an assembler should accept something like "C4", not
4090 // the usual "#4" immediate.
4091 def CRx_asmoperand : AsmOperandClass {
4093 let PredicateMethod = "isUImm<4>";
4094 let RenderMethod = "addImmOperands";
4095 let ParserMethod = "ParseCRxOperand";
4096 // Diagnostics are handled in all cases by ParseCRxOperand.
4099 def CRx : Operand<i32> {
4100 let ParserMatchClass = CRx_asmoperand;
4101 let PrintMethod = "printCRxOperand";
4105 // Finally, we can start defining the instructions.
4107 // HINT is straightforward, with a few aliases.
4108 def HINTi : A64I_system<0b0, (outs), (ins uimm7:$UImm7), "hint\t$UImm7",
4111 let CRm = UImm7{6-3};
4112 let Op2 = UImm7{2-0};
4120 def : InstAlias<"nop", (HINTi 0)>;
4121 def : InstAlias<"yield", (HINTi 1)>;
4122 def : InstAlias<"wfe", (HINTi 2)>;
4123 def : InstAlias<"wfi", (HINTi 3)>;
4124 def : InstAlias<"sev", (HINTi 4)>;
4125 def : InstAlias<"sevl", (HINTi 5)>;
4127 // Quite a few instructions then follow a similar pattern of fixing common
4128 // fields in the bitpattern, we'll define a helper-class for them.
4129 class simple_sys<bits<2> op0, bits<3> op1, bits<4> crn, bits<3> op2,
4130 Operand operand, string asmop>
4131 : A64I_system<0b0, (outs), (ins operand:$CRm), !strconcat(asmop, "\t$CRm"),
4141 def CLREXi : simple_sys<0b00, 0b011, 0b0011, 0b010, uimm4, "clrex">;
4142 def DSBi : simple_sys<0b00, 0b011, 0b0011, 0b100, dbarrier_op, "dsb">;
4143 def DMBi : simple_sys<0b00, 0b011, 0b0011, 0b101, dbarrier_op, "dmb">;
4144 def ISBi : simple_sys<0b00, 0b011, 0b0011, 0b110, isb_op, "isb">;
4146 def : InstAlias<"clrex", (CLREXi 0b1111)>;
4147 def : InstAlias<"isb", (ISBi 0b1111)>;
4149 // (DMBi 0xb) is a "DMB ISH" instruciton, appropriate for Linux SMP
4150 // configurations at least.
4151 def : Pat<(atomic_fence imm, imm), (DMBi 0xb)>;
4153 // Any SYS bitpattern can be represented with a complex and opaque "SYS"
4155 def SYSiccix : A64I_system<0b0, (outs),
4156 (ins uimm3:$Op1, CRx:$CRn, CRx:$CRm,
4157 uimm3:$Op2, GPR64:$Rt),
4158 "sys\t$Op1, $CRn, $CRm, $Op2, $Rt",
4163 // You can skip the Xt argument whether it makes sense or not for the generic
4165 def : InstAlias<"sys $Op1, $CRn, $CRm, $Op2",
4166 (SYSiccix uimm3:$Op1, CRx:$CRn, CRx:$CRm, uimm3:$Op2, XZR)>;
4169 // But many have aliases, which obviously don't fit into
4170 class SYSalias<dag ins, string asmstring>
4171 : A64I_system<0b0, (outs), ins, asmstring, [], NoItinerary> {
4172 let isAsmParserOnly = 1;
4176 let Op1 = SysOp{13-11};
4177 let CRn = SysOp{10-7};
4178 let CRm = SysOp{6-3};
4179 let Op2 = SysOp{2-0};
4182 def ICix : SYSalias<(ins ic_op:$SysOp, GPR64:$Rt), "ic\t$SysOp, $Rt">;
4184 def ICi : SYSalias<(ins ic_op:$SysOp), "ic\t$SysOp"> {
4188 def DCix : SYSalias<(ins dc_op:$SysOp, GPR64:$Rt), "dc\t$SysOp, $Rt">;
4189 def ATix : SYSalias<(ins at_op:$SysOp, GPR64:$Rt), "at\t$SysOp, $Rt">;
4191 def TLBIix : SYSalias<(ins tlbi_op:$SysOp, GPR64:$Rt), "tlbi\t$SysOp, $Rt">;
4193 def TLBIi : SYSalias<(ins tlbi_op:$SysOp), "tlbi\t$SysOp"> {
4198 def SYSLxicci : A64I_system<0b1, (outs GPR64:$Rt),
4199 (ins uimm3:$Op1, CRx:$CRn, CRx:$CRm, uimm3:$Op2),
4200 "sysl\t$Rt, $Op1, $CRn, $CRm, $Op2",
4205 // The instructions themselves are rather simple for MSR and MRS.
4206 def MSRix : A64I_system<0b0, (outs), (ins msr_op:$SysReg, GPR64:$Rt),
4207 "msr\t$SysReg, $Rt", [], NoItinerary> {
4209 let Op0 = SysReg{15-14};
4210 let Op1 = SysReg{13-11};
4211 let CRn = SysReg{10-7};
4212 let CRm = SysReg{6-3};
4213 let Op2 = SysReg{2-0};
4216 def MRSxi : A64I_system<0b1, (outs GPR64:$Rt), (ins mrs_op:$SysReg),
4217 "mrs\t$Rt, $SysReg", [], NoItinerary> {
4219 let Op0 = SysReg{15-14};
4220 let Op1 = SysReg{13-11};
4221 let CRn = SysReg{10-7};
4222 let CRm = SysReg{6-3};
4223 let Op2 = SysReg{2-0};
4226 def MSRii : A64I_system<0b0, (outs), (ins pstate_op:$PState, uimm4:$CRm),
4227 "msr\t$PState, $CRm", [], NoItinerary> {
4231 let Op1 = PState{5-3};
4233 let Op2 = PState{2-0};
4237 //===----------------------------------------------------------------------===//
4238 // Test & branch (immediate) instructions
4239 //===----------------------------------------------------------------------===//
4240 // Contains: TBZ, TBNZ
4242 // The bit to test is a simple unsigned 6-bit immediate in the X-register
4244 def uimm6 : Operand<i64> {
4245 let ParserMatchClass = uimm6_asmoperand;
4248 def label_wid14_scal4_asmoperand : label_asmoperand<14, 4>;
4250 def tbimm_target : Operand<OtherVT> {
4251 let EncoderMethod = "getLabelOpValue<AArch64::fixup_a64_tstbr>";
4253 // This label is a 14-bit offset from PC, scaled by the instruction-width: 4.
4254 let PrintMethod = "printLabelOperand<14, 4>";
4255 let ParserMatchClass = label_wid14_scal4_asmoperand;
4257 let OperandType = "OPERAND_PCREL";
4260 def A64eq : ImmLeaf<i32, [{ return Imm == A64CC::EQ; }]>;
4261 def A64ne : ImmLeaf<i32, [{ return Imm == A64CC::NE; }]>;
4263 // These instructions correspond to patterns involving "and" with a power of
4264 // two, which we need to be able to select.
4265 def tstb64_pat : ComplexPattern<i64, 1, "SelectTSTBOperand<64>">;
4266 def tstb32_pat : ComplexPattern<i32, 1, "SelectTSTBOperand<32>">;
4268 let isBranch = 1, isTerminator = 1 in {
4269 def TBZxii : A64I_TBimm<0b0, (outs),
4270 (ins GPR64:$Rt, uimm6:$Imm, tbimm_target:$Label),
4271 "tbz\t$Rt, $Imm, $Label",
4272 [(A64br_cc (A64cmp (and GPR64:$Rt, tstb64_pat:$Imm), 0),
4276 def TBNZxii : A64I_TBimm<0b1, (outs),
4277 (ins GPR64:$Rt, uimm6:$Imm, tbimm_target:$Label),
4278 "tbnz\t$Rt, $Imm, $Label",
4279 [(A64br_cc (A64cmp (and GPR64:$Rt, tstb64_pat:$Imm), 0),
4284 // Note, these instructions overlap with the above 64-bit patterns. This is
4285 // intentional, "tbz x3, #1, somewhere" and "tbz w3, #1, somewhere" would both
4286 // do the same thing and are both permitted assembly. They also both have
4287 // sensible DAG patterns.
4288 def TBZwii : A64I_TBimm<0b0, (outs),
4289 (ins GPR32:$Rt, uimm5:$Imm, tbimm_target:$Label),
4290 "tbz\t$Rt, $Imm, $Label",
4291 [(A64br_cc (A64cmp (and GPR32:$Rt, tstb32_pat:$Imm), 0),
4297 def TBNZwii : A64I_TBimm<0b1, (outs),
4298 (ins GPR32:$Rt, uimm5:$Imm, tbimm_target:$Label),
4299 "tbnz\t$Rt, $Imm, $Label",
4300 [(A64br_cc (A64cmp (and GPR32:$Rt, tstb32_pat:$Imm), 0),
4307 //===----------------------------------------------------------------------===//
4308 // Unconditional branch (immediate) instructions
4309 //===----------------------------------------------------------------------===//
4312 def label_wid26_scal4_asmoperand : label_asmoperand<26, 4>;
4314 def bimm_target : Operand<OtherVT> {
4315 let EncoderMethod = "getLabelOpValue<AArch64::fixup_a64_uncondbr>";
4317 // This label is a 26-bit offset from PC, scaled by the instruction-width: 4.
4318 let PrintMethod = "printLabelOperand<26, 4>";
4319 let ParserMatchClass = label_wid26_scal4_asmoperand;
4321 let OperandType = "OPERAND_PCREL";
4324 def blimm_target : Operand<i64> {
4325 let EncoderMethod = "getLabelOpValue<AArch64::fixup_a64_call>";
4327 // This label is a 26-bit offset from PC, scaled by the instruction-width: 4.
4328 let PrintMethod = "printLabelOperand<26, 4>";
4329 let ParserMatchClass = label_wid26_scal4_asmoperand;
4331 let OperandType = "OPERAND_PCREL";
4334 class A64I_BimmImpl<bit op, string asmop, list<dag> patterns, Operand lbl_type>
4335 : A64I_Bimm<op, (outs), (ins lbl_type:$Label),
4336 !strconcat(asmop, "\t$Label"), patterns,
4339 let isBranch = 1 in {
4340 def Bimm : A64I_BimmImpl<0b0, "b", [(br bb:$Label)], bimm_target> {
4341 let isTerminator = 1;
4345 def BLimm : A64I_BimmImpl<0b1, "bl",
4346 [(AArch64Call tglobaladdr:$Label)], blimm_target> {
4352 def : Pat<(AArch64Call texternalsym:$Label), (BLimm texternalsym:$Label)>;
4354 //===----------------------------------------------------------------------===//
4355 // Unconditional branch (register) instructions
4356 //===----------------------------------------------------------------------===//
4357 // Contains: BR, BLR, RET, ERET, DRP.
4359 // Most of the notional opcode fields in the A64I_Breg format are fixed in A64
4361 class A64I_BregImpl<bits<4> opc,
4362 dag outs, dag ins, string asmstr, list<dag> patterns,
4363 InstrItinClass itin = NoItinerary>
4364 : A64I_Breg<opc, 0b11111, 0b000000, 0b00000,
4365 outs, ins, asmstr, patterns, itin> {
4367 let isIndirectBranch = 1;
4370 // Note that these are not marked isCall or isReturn because as far as LLVM is
4371 // concerned they're not. "ret" is just another jump unless it has been selected
4372 // by LLVM as the function's return.
4374 let isBranch = 1 in {
4375 def BRx : A64I_BregImpl<0b0000,(outs), (ins GPR64:$Rn),
4376 "br\t$Rn", [(brind GPR64:$Rn)]> {
4378 let isTerminator = 1;
4381 def BLRx : A64I_BregImpl<0b0001, (outs), (ins GPR64:$Rn),
4382 "blr\t$Rn", [(AArch64Call GPR64:$Rn)]> {
4388 def RETx : A64I_BregImpl<0b0010, (outs), (ins GPR64:$Rn),
4391 let isTerminator = 1;
4395 // Create a separate pseudo-instruction for codegen to use so that we don't
4396 // flag x30 as used in every function. It'll be restored before the RET by the
4397 // epilogue if it's legitimately used.
4398 def RET : A64PseudoExpand<(outs), (ins), [(A64ret)], (RETx (ops X30))> {
4399 let isTerminator = 1;
4404 def ERET : A64I_BregImpl<0b0100, (outs), (ins), "eret", []> {
4407 let isTerminator = 1;
4411 def DRPS : A64I_BregImpl<0b0101, (outs), (ins), "drps", []> {
4417 def RETAlias : InstAlias<"ret", (RETx X30)>;
4420 //===----------------------------------------------------------------------===//
4421 // Address generation patterns
4422 //===----------------------------------------------------------------------===//
4424 // Primary method of address generation for the small/absolute memory model is
4425 // an ADRP/ADR pair:
4426 // ADRP x0, some_variable
4427 // ADD x0, x0, #:lo12:some_variable
4429 // The load/store elision of the ADD is accomplished when selecting
4430 // addressing-modes. This just mops up the cases where that doesn't work and we
4431 // really need an address in some register.
4433 // This wrapper applies a LO12 modifier to the address. Otherwise we could just
4434 // use the same address.
4436 class ADRP_ADD<SDNode Wrapper, SDNode addrop>
4437 : Pat<(Wrapper addrop:$Hi, addrop:$Lo12, (i32 imm)),
4438 (ADDxxi_lsl0_s (ADRPxi addrop:$Hi), addrop:$Lo12)>;
4440 def : ADRP_ADD<A64WrapperSmall, tblockaddress>;
4441 def : ADRP_ADD<A64WrapperSmall, texternalsym>;
4442 def : ADRP_ADD<A64WrapperSmall, tglobaladdr>;
4443 def : ADRP_ADD<A64WrapperSmall, tglobaltlsaddr>;
4444 def : ADRP_ADD<A64WrapperSmall, tjumptable>;
4446 //===----------------------------------------------------------------------===//
4447 // GOT access patterns
4448 //===----------------------------------------------------------------------===//
4452 class GOTLoadSmall<SDNode addrfrag>
4453 : Pat<(A64GOTLoad (A64WrapperSmall addrfrag:$Hi, addrfrag:$Lo12, 8)),
4454 (LS64_LDR (ADRPxi addrfrag:$Hi), addrfrag:$Lo12)>;
4456 def : GOTLoadSmall<texternalsym>;
4457 def : GOTLoadSmall<tglobaladdr>;
4458 def : GOTLoadSmall<tglobaltlsaddr>;
4460 //===----------------------------------------------------------------------===//
4461 // Tail call handling
4462 //===----------------------------------------------------------------------===//
4464 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1, Uses = [XSP] in {
4466 : PseudoInst<(outs), (ins i64imm:$dst, i32imm:$FPDiff),
4467 [(AArch64tcret tglobaladdr:$dst, (i32 timm:$FPDiff))]>;
4470 : PseudoInst<(outs), (ins tcGPR64:$dst, i32imm:$FPDiff),
4471 [(AArch64tcret tcGPR64:$dst, (i32 timm:$FPDiff))]>;
4474 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1,
4476 def TAIL_Bimm : A64PseudoExpand<(outs), (ins bimm_target:$Label), [],
4477 (Bimm bimm_target:$Label)>;
4479 def TAIL_BRx : A64PseudoExpand<(outs), (ins tcGPR64:$Rd), [],
4484 def : Pat<(AArch64tcret texternalsym:$dst, (i32 timm:$FPDiff)),
4485 (TC_RETURNdi texternalsym:$dst, imm:$FPDiff)>;
4487 //===----------------------------------------------------------------------===//
4488 // Thread local storage
4489 //===----------------------------------------------------------------------===//
4491 // This is a pseudo-instruction representing the ".tlsdesccall" directive in
4492 // assembly. Its effect is to insert an R_AARCH64_TLSDESC_CALL relocation at the
4493 // current location. It should always be immediately followed by a BLR
4494 // instruction, and is intended solely for relaxation by the linker.
4496 def : Pat<(A64threadpointer), (MRSxi 0xde82)>;
4498 def TLSDESCCALL : PseudoInst<(outs), (ins i64imm:$Lbl), []> {
4499 let hasSideEffects = 1;
4502 def TLSDESC_BLRx : PseudoInst<(outs), (ins GPR64:$Rn, i64imm:$Var),
4503 [(A64tlsdesc_blr GPR64:$Rn, tglobaltlsaddr:$Var)]> {
4508 def : Pat<(A64tlsdesc_blr GPR64:$Rn, texternalsym:$Var),
4509 (TLSDESC_BLRx GPR64:$Rn, texternalsym:$Var)>;
4511 //===----------------------------------------------------------------------===//
4512 // Bitfield patterns
4513 //===----------------------------------------------------------------------===//
4515 def bfi32_lsb_to_immr : SDNodeXForm<imm, [{
4516 return CurDAG->getTargetConstant((32 - N->getZExtValue()) % 32, MVT::i64);
4519 def bfi64_lsb_to_immr : SDNodeXForm<imm, [{
4520 return CurDAG->getTargetConstant((64 - N->getZExtValue()) % 64, MVT::i64);
4523 def bfi_width_to_imms : SDNodeXForm<imm, [{
4524 return CurDAG->getTargetConstant(N->getZExtValue() - 1, MVT::i64);
4528 // The simpler patterns deal with cases where no AND mask is actually needed
4529 // (either all bits are used or the low 32 bits are used).
4530 let AddedComplexity = 10 in {
4532 def : Pat<(A64Bfi GPR64:$src, GPR64:$Rn, imm:$ImmR, imm:$ImmS),
4533 (BFIxxii GPR64:$src, GPR64:$Rn,
4534 (bfi64_lsb_to_immr (i64 imm:$ImmR)),
4535 (bfi_width_to_imms (i64 imm:$ImmS)))>;
4537 def : Pat<(A64Bfi GPR32:$src, GPR32:$Rn, imm:$ImmR, imm:$ImmS),
4538 (BFIwwii GPR32:$src, GPR32:$Rn,
4539 (bfi32_lsb_to_immr (i64 imm:$ImmR)),
4540 (bfi_width_to_imms (i64 imm:$ImmS)))>;
4543 def : Pat<(and (A64Bfi GPR64:$src, GPR64:$Rn, imm:$ImmR, imm:$ImmS),
4545 (SUBREG_TO_REG (i64 0),
4546 (BFIwwii (EXTRACT_SUBREG GPR64:$src, sub_32),
4547 (EXTRACT_SUBREG GPR64:$Rn, sub_32),
4548 (bfi32_lsb_to_immr (i64 imm:$ImmR)),
4549 (bfi_width_to_imms (i64 imm:$ImmS))),
4554 //===----------------------------------------------------------------------===//
4555 // Constant island entries
4556 //===----------------------------------------------------------------------===//
4558 // The constant island pass needs to create "instructions" in the middle of the
4559 // instruction stream to reresent its constants.
4561 def cpinst_operand : Operand<i32>;
4563 def CONSTPOOL_ENTRY : PseudoInst<(outs), (ins cpinst_operand:$instid,
4564 cpinst_operand:$cpidx,
4565 i32imm:$size), []> {
4566 let neverHasSideEffects = 1;
4567 let isNotDuplicable = 1;
4570 //===----------------------------------------------------------------------===//
4571 // Miscellaneous patterns
4572 //===----------------------------------------------------------------------===//
4574 // Truncation from 64 to 32-bits just involves renaming your register.
4575 def : Pat<(i32 (trunc (i64 GPR64:$val))), (EXTRACT_SUBREG GPR64:$val, sub_32)>;
4577 // Similarly, extension where we don't care about the high bits is
4579 def : Pat<(i64 (anyext (i32 GPR32:$val))),
4580 (INSERT_SUBREG (IMPLICIT_DEF), GPR32:$val, sub_32)>;
4582 // SELECT instructions providing f128 types need to be handled by a
4583 // pseudo-instruction since the eventual code will need to introduce basic
4584 // blocks and control flow.
4585 def F128CSEL : PseudoInst<(outs FPR128:$Rd),
4586 (ins FPR128:$Rn, FPR128:$Rm, cond_code_op:$Cond),
4587 [(set FPR128:$Rd, (simple_select (f128 FPR128:$Rn),
4590 let usesCustomInserter = 1;
4593 //===----------------------------------------------------------------------===//
4594 // Load/store patterns
4595 //===----------------------------------------------------------------------===//
4597 // There are lots of patterns here, because we need to allow at least three
4598 // parameters to vary independently.
4599 // 1. Instruction: "ldrb w9, [sp]", "ldrh w9, [sp]", ...
4600 // 2. LLVM source: zextloadi8, anyextloadi8, ...
4601 // 3. Address-generation: A64Wrapper, (add BASE, OFFSET), ...
4603 // The biggest problem turns out to be the address-generation variable. At the
4604 // point of instantiation we need to produce two DAGs, one for the pattern and
4605 // one for the instruction. Doing this at the lowest level of classes doesn't
4608 // Consider the simple uimm12 addressing mode, and the desire to match both (add
4609 // GPR64xsp:$Rn, uimm12:$Offset) and GPR64xsp:$Rn, particularly on the
4610 // instruction side. We'd need to insert either "GPR64xsp" and "uimm12" or
4611 // "GPR64xsp" and "0" into an unknown dag. !subst is not capable of this
4612 // operation, and PatFrags are for selection not output.
4614 // As a result, the address-generation patterns are the final
4615 // instantiations. However, we do still need to vary the operand for the address
4616 // further down (At the point we're deciding A64WrapperSmall, we don't know
4617 // the memory width of the operation).
4619 //===------------------------------
4620 // 1. Basic infrastructural defs
4621 //===------------------------------
4623 // First, some simple classes for !foreach and !subst to use:
4634 // You can't use !subst on an actual immediate, but you *can* use it on an
4635 // operand record that happens to match a single immediate. So we do.
4636 def imm_eq0 : ImmLeaf<i64, [{ return Imm == 0; }]>;
4637 def imm_eq1 : ImmLeaf<i64, [{ return Imm == 1; }]>;
4638 def imm_eq2 : ImmLeaf<i64, [{ return Imm == 2; }]>;
4639 def imm_eq3 : ImmLeaf<i64, [{ return Imm == 3; }]>;
4640 def imm_eq4 : ImmLeaf<i64, [{ return Imm == 4; }]>;
4642 // If the low bits of a pointer are known to be 0 then an "or" is just as good
4643 // as addition for computing an offset. This fragment forwards that check for
4645 def add_like_or : PatFrag<(ops node:$lhs, node:$rhs), (or node:$lhs, node:$rhs),
4647 return CurDAG->isBaseWithConstantOffset(SDValue(N, 0));
4650 // Load/store (unsigned immediate) operations with relocations against global
4651 // symbols (for lo12) are only valid if those symbols have correct alignment
4652 // (since the immediate offset is divided by the access scale, it can't have a
4655 // The guaranteed alignment is provided as part of the WrapperSmall
4656 // operation, and checked against one of these.
4657 def any_align : ImmLeaf<i32, [{ (void)Imm; return true; }]>;
4658 def min_align2 : ImmLeaf<i32, [{ return Imm >= 2; }]>;
4659 def min_align4 : ImmLeaf<i32, [{ return Imm >= 4; }]>;
4660 def min_align8 : ImmLeaf<i32, [{ return Imm >= 8; }]>;
4661 def min_align16 : ImmLeaf<i32, [{ return Imm >= 16; }]>;
4663 // "Normal" load/store instructions can be used on atomic operations, provided
4664 // the ordering parameter is at most "monotonic". Anything above that needs
4665 // special handling with acquire/release instructions.
4666 class simple_load<PatFrag base>
4667 : PatFrag<(ops node:$ptr), (base node:$ptr), [{
4668 return cast<AtomicSDNode>(N)->getOrdering() <= Monotonic;
4671 def atomic_load_simple_i8 : simple_load<atomic_load_8>;
4672 def atomic_load_simple_i16 : simple_load<atomic_load_16>;
4673 def atomic_load_simple_i32 : simple_load<atomic_load_32>;
4674 def atomic_load_simple_i64 : simple_load<atomic_load_64>;
4676 class simple_store<PatFrag base>
4677 : PatFrag<(ops node:$ptr, node:$val), (base node:$ptr, node:$val), [{
4678 return cast<AtomicSDNode>(N)->getOrdering() <= Monotonic;
4681 def atomic_store_simple_i8 : simple_store<atomic_store_8>;
4682 def atomic_store_simple_i16 : simple_store<atomic_store_16>;
4683 def atomic_store_simple_i32 : simple_store<atomic_store_32>;
4684 def atomic_store_simple_i64 : simple_store<atomic_store_64>;
4686 //===------------------------------
4687 // 2. UImm12 and SImm9
4688 //===------------------------------
4690 // These instructions have two operands providing the address so they can be
4691 // treated similarly for most purposes.
4693 //===------------------------------
4694 // 2.1 Base patterns covering extend/truncate semantics
4695 //===------------------------------
4697 // Atomic patterns can be shared between integer operations of all sizes, a
4698 // quick multiclass here allows reuse.
4699 multiclass ls_atomic_pats<Instruction LOAD, Instruction STORE, dag Base,
4700 dag Offset, dag address, RegisterClass TPR,
4702 def : Pat<(!cast<PatFrag>("atomic_load_simple_" # sty) address),
4703 (LOAD Base, Offset)>;
4705 def : Pat<(!cast<PatFrag>("atomic_store_simple_" # sty) address, TPR:$Rt),
4706 (STORE TPR:$Rt, Base, Offset)>;
4709 // Instructions accessing a memory chunk smaller than a register (or, in a
4710 // pinch, the same size) have a characteristic set of patterns they want to
4711 // match: extending loads and truncating stores. This class deals with the
4712 // sign-neutral version of those patterns.
4714 // It will be instantiated across multiple addressing-modes.
4715 multiclass ls_small_pats<Instruction LOAD, Instruction STORE,
4716 dag Base, dag Offset,
4717 dag address, ValueType sty>
4718 : ls_atomic_pats<LOAD, STORE, Base, Offset, address, GPR32, sty> {
4719 def : Pat<(!cast<SDNode>(zextload # sty) address), (LOAD Base, Offset)>;
4721 def : Pat<(!cast<SDNode>(extload # sty) address), (LOAD Base, Offset)>;
4723 // For zero-extension to 64-bits we have to tell LLVM that the whole 64-bit
4724 // register was actually set.
4725 def : Pat<(i64 (!cast<SDNode>(zextload # sty) address)),
4726 (SUBREG_TO_REG (i64 0), (LOAD Base, Offset), sub_32)>;
4728 def : Pat<(i64 (!cast<SDNode>(extload # sty) address)),
4729 (SUBREG_TO_REG (i64 0), (LOAD Base, Offset), sub_32)>;
4731 def : Pat<(!cast<SDNode>(truncstore # sty) GPR32:$Rt, address),
4732 (STORE GPR32:$Rt, Base, Offset)>;
4734 // For truncating store from 64-bits, we have to manually tell LLVM to
4735 // ignore the high bits of the x register.
4736 def : Pat<(!cast<SDNode>(truncstore # sty) GPR64:$Rt, address),
4737 (STORE (EXTRACT_SUBREG GPR64:$Rt, sub_32), Base, Offset)>;
4740 // Next come patterns for sign-extending loads.
4741 multiclass load_signed_pats<string T, string U, dag Base, dag Offset,
4742 dag address, ValueType sty> {
4743 def : Pat<(i32 (!cast<SDNode>("sextload" # sty) address)),
4744 (!cast<Instruction>("LDRS" # T # "w" # U) Base, Offset)>;
4746 def : Pat<(i64 (!cast<SDNode>("sextload" # sty) address)),
4747 (!cast<Instruction>("LDRS" # T # "x" # U) Base, Offset)>;
4751 // and finally "natural-width" loads and stores come next.
4752 multiclass ls_neutral_pats<Instruction LOAD, Instruction STORE, dag Base,
4753 dag Offset, dag address, RegisterClass TPR,
4755 def : Pat<(sty (load address)), (LOAD Base, Offset)>;
4756 def : Pat<(store (sty TPR:$Rt), address), (STORE TPR:$Rt, Base, Offset)>;
4759 // Integer operations also get atomic instructions to select for.
4760 multiclass ls_int_neutral_pats<Instruction LOAD, Instruction STORE, dag Base,
4761 dag Offset, dag address, RegisterClass TPR,
4763 : ls_neutral_pats<LOAD, STORE, Base, Offset, address, TPR, sty>,
4764 ls_atomic_pats<LOAD, STORE, Base, Offset, address, TPR, sty>;
4766 //===------------------------------
4767 // 2.2. Addressing-mode instantiations
4768 //===------------------------------
4770 multiclass uimm12_pats<dag address, dag Base, dag Offset> {
4771 defm : ls_small_pats<LS8_LDR, LS8_STR, Base,
4772 !foreach(decls.pattern, Offset,
4773 !subst(OFFSET, byte_uimm12, decls.pattern)),
4774 !foreach(decls.pattern, address,
4775 !subst(OFFSET, byte_uimm12,
4776 !subst(ALIGN, any_align, decls.pattern))),
4778 defm : ls_small_pats<LS16_LDR, LS16_STR, Base,
4779 !foreach(decls.pattern, Offset,
4780 !subst(OFFSET, hword_uimm12, decls.pattern)),
4781 !foreach(decls.pattern, address,
4782 !subst(OFFSET, hword_uimm12,
4783 !subst(ALIGN, min_align2, decls.pattern))),
4785 defm : ls_small_pats<LS32_LDR, LS32_STR, Base,
4786 !foreach(decls.pattern, Offset,
4787 !subst(OFFSET, word_uimm12, decls.pattern)),
4788 !foreach(decls.pattern, address,
4789 !subst(OFFSET, word_uimm12,
4790 !subst(ALIGN, min_align4, decls.pattern))),
4793 defm : ls_int_neutral_pats<LS32_LDR, LS32_STR, Base,
4794 !foreach(decls.pattern, Offset,
4795 !subst(OFFSET, word_uimm12, decls.pattern)),
4796 !foreach(decls.pattern, address,
4797 !subst(OFFSET, word_uimm12,
4798 !subst(ALIGN, min_align4, decls.pattern))),
4801 defm : ls_int_neutral_pats<LS64_LDR, LS64_STR, Base,
4802 !foreach(decls.pattern, Offset,
4803 !subst(OFFSET, dword_uimm12, decls.pattern)),
4804 !foreach(decls.pattern, address,
4805 !subst(OFFSET, dword_uimm12,
4806 !subst(ALIGN, min_align8, decls.pattern))),
4809 defm : ls_neutral_pats<LSFP16_LDR, LSFP16_STR, Base,
4810 !foreach(decls.pattern, Offset,
4811 !subst(OFFSET, hword_uimm12, decls.pattern)),
4812 !foreach(decls.pattern, address,
4813 !subst(OFFSET, hword_uimm12,
4814 !subst(ALIGN, min_align2, decls.pattern))),
4817 defm : ls_neutral_pats<LSFP32_LDR, LSFP32_STR, Base,
4818 !foreach(decls.pattern, Offset,
4819 !subst(OFFSET, word_uimm12, decls.pattern)),
4820 !foreach(decls.pattern, address,
4821 !subst(OFFSET, word_uimm12,
4822 !subst(ALIGN, min_align4, decls.pattern))),
4825 defm : ls_neutral_pats<LSFP64_LDR, LSFP64_STR, Base,
4826 !foreach(decls.pattern, Offset,
4827 !subst(OFFSET, dword_uimm12, decls.pattern)),
4828 !foreach(decls.pattern, address,
4829 !subst(OFFSET, dword_uimm12,
4830 !subst(ALIGN, min_align8, decls.pattern))),
4833 defm : ls_neutral_pats<LSFP128_LDR, LSFP128_STR, Base,
4834 !foreach(decls.pattern, Offset,
4835 !subst(OFFSET, qword_uimm12, decls.pattern)),
4836 !foreach(decls.pattern, address,
4837 !subst(OFFSET, qword_uimm12,
4838 !subst(ALIGN, min_align16, decls.pattern))),
4841 defm : load_signed_pats<"B", "", Base,
4842 !foreach(decls.pattern, Offset,
4843 !subst(OFFSET, byte_uimm12, decls.pattern)),
4844 !foreach(decls.pattern, address,
4845 !subst(OFFSET, byte_uimm12,
4846 !subst(ALIGN, any_align, decls.pattern))),
4849 defm : load_signed_pats<"H", "", Base,
4850 !foreach(decls.pattern, Offset,
4851 !subst(OFFSET, hword_uimm12, decls.pattern)),
4852 !foreach(decls.pattern, address,
4853 !subst(OFFSET, hword_uimm12,
4854 !subst(ALIGN, min_align2, decls.pattern))),
4857 def : Pat<(sextloadi32 !foreach(decls.pattern, address,
4858 !subst(OFFSET, word_uimm12,
4859 !subst(ALIGN, min_align4, decls.pattern)))),
4860 (LDRSWx Base, !foreach(decls.pattern, Offset,
4861 !subst(OFFSET, word_uimm12, decls.pattern)))>;
4864 // Straightforward patterns of last resort: a pointer with or without an
4865 // appropriate offset.
4866 defm : uimm12_pats<(i64 GPR64xsp:$Rn), (i64 GPR64xsp:$Rn), (i64 0)>;
4867 defm : uimm12_pats<(add GPR64xsp:$Rn, OFFSET:$UImm12),
4868 (i64 GPR64xsp:$Rn), (i64 OFFSET:$UImm12)>;
4870 // The offset could be hidden behind an "or", of course:
4871 defm : uimm12_pats<(add_like_or GPR64xsp:$Rn, OFFSET:$UImm12),
4872 (i64 GPR64xsp:$Rn), (i64 OFFSET:$UImm12)>;
4874 // Global addresses under the small-absolute model should use these
4875 // instructions. There are ELF relocations specifically for it.
4876 defm : uimm12_pats<(A64WrapperSmall tglobaladdr:$Hi, tglobaladdr:$Lo12, ALIGN),
4877 (ADRPxi tglobaladdr:$Hi), (i64 tglobaladdr:$Lo12)>;
4879 defm : uimm12_pats<(A64WrapperSmall tglobaltlsaddr:$Hi, tglobaltlsaddr:$Lo12,
4881 (ADRPxi tglobaltlsaddr:$Hi), (i64 tglobaltlsaddr:$Lo12)>;
4883 // External symbols that make it this far should also get standard relocations.
4884 defm : uimm12_pats<(A64WrapperSmall texternalsym:$Hi, texternalsym:$Lo12,
4886 (ADRPxi texternalsym:$Hi), (i64 texternalsym:$Lo12)>;
4889 // We also want to use uimm12 instructions for local variables at the moment.
4890 def tframeindex_XFORM : SDNodeXForm<frameindex, [{
4891 int FI = cast<FrameIndexSDNode>(N)->getIndex();
4892 return CurDAG->getTargetFrameIndex(FI, MVT::i64);
4895 defm : uimm12_pats<(i64 frameindex:$Rn),
4896 (tframeindex_XFORM tframeindex:$Rn), (i64 0)>;
4898 // These can be much simpler than uimm12 because we don't to change the operand
4899 // type (e.g. LDURB and LDURH take the same operands).
4900 multiclass simm9_pats<dag address, dag Base, dag Offset> {
4901 defm : ls_small_pats<LS8_LDUR, LS8_STUR, Base, Offset, address, i8>;
4902 defm : ls_small_pats<LS16_LDUR, LS16_STUR, Base, Offset, address, i16>;
4904 defm : ls_int_neutral_pats<LS32_LDUR, LS32_STUR, Base, Offset, address,
4906 defm : ls_int_neutral_pats<LS64_LDUR, LS64_STUR, Base, Offset, address,
4909 defm : ls_neutral_pats<LSFP16_LDUR, LSFP16_STUR, Base, Offset, address,
4911 defm : ls_neutral_pats<LSFP32_LDUR, LSFP32_STUR, Base, Offset, address,
4913 defm : ls_neutral_pats<LSFP64_LDUR, LSFP64_STUR, Base, Offset, address,
4915 defm : ls_neutral_pats<LSFP128_LDUR, LSFP128_STUR, Base, Offset, address,
4918 def : Pat<(i64 (zextloadi32 address)),
4919 (SUBREG_TO_REG (i64 0), (LS32_LDUR Base, Offset), sub_32)>;
4921 def : Pat<(truncstorei32 GPR64:$Rt, address),
4922 (LS32_STUR (EXTRACT_SUBREG GPR64:$Rt, sub_32), Base, Offset)>;
4924 defm : load_signed_pats<"B", "_U", Base, Offset, address, i8>;
4925 defm : load_signed_pats<"H", "_U", Base, Offset, address, i16>;
4926 def : Pat<(sextloadi32 address), (LDURSWx Base, Offset)>;
4929 defm : simm9_pats<(add GPR64xsp:$Rn, simm9:$SImm9),
4930 (i64 GPR64xsp:$Rn), (SDXF_simm9 simm9:$SImm9)>;
4932 defm : simm9_pats<(add_like_or GPR64xsp:$Rn, simm9:$SImm9),
4933 (i64 GPR64xsp:$Rn), (SDXF_simm9 simm9:$SImm9)>;
4936 //===------------------------------
4937 // 3. Register offset patterns
4938 //===------------------------------
4940 // Atomic patterns can be shared between integer operations of all sizes, a
4941 // quick multiclass here allows reuse.
4942 multiclass ro_atomic_pats<Instruction LOAD, Instruction STORE, dag Base,
4943 dag Offset, dag Extend, dag address,
4944 RegisterClass TPR, ValueType sty> {
4945 def : Pat<(!cast<PatFrag>("atomic_load_simple_" # sty) address),
4946 (LOAD Base, Offset, Extend)>;
4948 def : Pat<(!cast<PatFrag>("atomic_store_simple_" # sty) address, TPR:$Rt),
4949 (STORE TPR:$Rt, Base, Offset, Extend)>;
4952 // The register offset instructions take three operands giving the instruction,
4953 // and have an annoying split between instructions where Rm is 32-bit and
4954 // 64-bit. So we need a special hierarchy to describe them. Other than that the
4955 // same operations should be supported as for simm9 and uimm12 addressing.
4957 multiclass ro_small_pats<Instruction LOAD, Instruction STORE,
4958 dag Base, dag Offset, dag Extend,
4959 dag address, ValueType sty>
4960 : ro_atomic_pats<LOAD, STORE, Base, Offset, Extend, address, GPR32, sty> {
4961 def : Pat<(!cast<SDNode>(zextload # sty) address),
4962 (LOAD Base, Offset, Extend)>;
4964 def : Pat<(!cast<SDNode>(extload # sty) address),
4965 (LOAD Base, Offset, Extend)>;
4967 // For zero-extension to 64-bits we have to tell LLVM that the whole 64-bit
4968 // register was actually set.
4969 def : Pat<(i64 (!cast<SDNode>(zextload # sty) address)),
4970 (SUBREG_TO_REG (i64 0), (LOAD Base, Offset, Extend), sub_32)>;
4972 def : Pat<(i64 (!cast<SDNode>(extload # sty) address)),
4973 (SUBREG_TO_REG (i64 0), (LOAD Base, Offset, Extend), sub_32)>;
4975 def : Pat<(!cast<SDNode>(truncstore # sty) GPR32:$Rt, address),
4976 (STORE GPR32:$Rt, Base, Offset, Extend)>;
4978 // For truncating store from 64-bits, we have to manually tell LLVM to
4979 // ignore the high bits of the x register.
4980 def : Pat<(!cast<SDNode>(truncstore # sty) GPR64:$Rt, address),
4981 (STORE (EXTRACT_SUBREG GPR64:$Rt, sub_32), Base, Offset, Extend)>;
4985 // Next come patterns for sign-extending loads.
4986 multiclass ro_signed_pats<string T, string Rm, dag Base, dag Offset, dag Extend,
4987 dag address, ValueType sty> {
4988 def : Pat<(i32 (!cast<SDNode>("sextload" # sty) address)),
4989 (!cast<Instruction>("LDRS" # T # "w_" # Rm # "_RegOffset")
4990 Base, Offset, Extend)>;
4992 def : Pat<(i64 (!cast<SDNode>("sextload" # sty) address)),
4993 (!cast<Instruction>("LDRS" # T # "x_" # Rm # "_RegOffset")
4994 Base, Offset, Extend)>;
4997 // and finally "natural-width" loads and stores come next.
4998 multiclass ro_neutral_pats<Instruction LOAD, Instruction STORE,
4999 dag Base, dag Offset, dag Extend, dag address,
5000 RegisterClass TPR, ValueType sty> {
5001 def : Pat<(sty (load address)), (LOAD Base, Offset, Extend)>;
5002 def : Pat<(store (sty TPR:$Rt), address),
5003 (STORE TPR:$Rt, Base, Offset, Extend)>;
5006 multiclass ro_int_neutral_pats<Instruction LOAD, Instruction STORE,
5007 dag Base, dag Offset, dag Extend, dag address,
5008 RegisterClass TPR, ValueType sty>
5009 : ro_neutral_pats<LOAD, STORE, Base, Offset, Extend, address, TPR, sty>,
5010 ro_atomic_pats<LOAD, STORE, Base, Offset, Extend, address, TPR, sty>;
5012 multiclass regoff_pats<string Rm, dag address, dag Base, dag Offset,
5014 defm : ro_small_pats<!cast<Instruction>("LS8_" # Rm # "_RegOffset_LDR"),
5015 !cast<Instruction>("LS8_" # Rm # "_RegOffset_STR"),
5016 Base, Offset, Extend,
5017 !foreach(decls.pattern, address,
5018 !subst(SHIFT, imm_eq0, decls.pattern)),
5020 defm : ro_small_pats<!cast<Instruction>("LS16_" # Rm # "_RegOffset_LDR"),
5021 !cast<Instruction>("LS16_" # Rm # "_RegOffset_STR"),
5022 Base, Offset, Extend,
5023 !foreach(decls.pattern, address,
5024 !subst(SHIFT, imm_eq1, decls.pattern)),
5026 defm : ro_small_pats<!cast<Instruction>("LS32_" # Rm # "_RegOffset_LDR"),
5027 !cast<Instruction>("LS32_" # Rm # "_RegOffset_STR"),
5028 Base, Offset, Extend,
5029 !foreach(decls.pattern, address,
5030 !subst(SHIFT, imm_eq2, decls.pattern)),
5033 defm : ro_int_neutral_pats<
5034 !cast<Instruction>("LS32_" # Rm # "_RegOffset_LDR"),
5035 !cast<Instruction>("LS32_" # Rm # "_RegOffset_STR"),
5036 Base, Offset, Extend,
5037 !foreach(decls.pattern, address,
5038 !subst(SHIFT, imm_eq2, decls.pattern)),
5041 defm : ro_int_neutral_pats<
5042 !cast<Instruction>("LS64_" # Rm # "_RegOffset_LDR"),
5043 !cast<Instruction>("LS64_" # Rm # "_RegOffset_STR"),
5044 Base, Offset, Extend,
5045 !foreach(decls.pattern, address,
5046 !subst(SHIFT, imm_eq3, decls.pattern)),
5049 defm : ro_neutral_pats<!cast<Instruction>("LSFP16_" # Rm # "_RegOffset_LDR"),
5050 !cast<Instruction>("LSFP16_" # Rm # "_RegOffset_STR"),
5051 Base, Offset, Extend,
5052 !foreach(decls.pattern, address,
5053 !subst(SHIFT, imm_eq1, decls.pattern)),
5056 defm : ro_neutral_pats<!cast<Instruction>("LSFP32_" # Rm # "_RegOffset_LDR"),
5057 !cast<Instruction>("LSFP32_" # Rm # "_RegOffset_STR"),
5058 Base, Offset, Extend,
5059 !foreach(decls.pattern, address,
5060 !subst(SHIFT, imm_eq2, decls.pattern)),
5063 defm : ro_neutral_pats<!cast<Instruction>("LSFP64_" # Rm # "_RegOffset_LDR"),
5064 !cast<Instruction>("LSFP64_" # Rm # "_RegOffset_STR"),
5065 Base, Offset, Extend,
5066 !foreach(decls.pattern, address,
5067 !subst(SHIFT, imm_eq3, decls.pattern)),
5070 defm : ro_neutral_pats<!cast<Instruction>("LSFP128_" # Rm # "_RegOffset_LDR"),
5071 !cast<Instruction>("LSFP128_" # Rm # "_RegOffset_STR"),
5072 Base, Offset, Extend,
5073 !foreach(decls.pattern, address,
5074 !subst(SHIFT, imm_eq4, decls.pattern)),
5077 defm : ro_signed_pats<"B", Rm, Base, Offset, Extend,
5078 !foreach(decls.pattern, address,
5079 !subst(SHIFT, imm_eq0, decls.pattern)),
5082 defm : ro_signed_pats<"H", Rm, Base, Offset, Extend,
5083 !foreach(decls.pattern, address,
5084 !subst(SHIFT, imm_eq1, decls.pattern)),
5087 def : Pat<(sextloadi32 !foreach(decls.pattern, address,
5088 !subst(SHIFT, imm_eq2, decls.pattern))),
5089 (!cast<Instruction>("LDRSWx_" # Rm # "_RegOffset")
5090 Base, Offset, Extend)>;
5094 // Finally we're in a position to tell LLVM exactly what addresses are reachable
5095 // using register-offset instructions. Essentially a base plus a possibly
5096 // extended, possibly shifted (by access size) offset.
5098 defm : regoff_pats<"Wm", (add GPR64xsp:$Rn, (sext GPR32:$Rm)),
5099 (i64 GPR64xsp:$Rn), (i32 GPR32:$Rm), (i64 6)>;
5101 defm : regoff_pats<"Wm", (add GPR64xsp:$Rn, (shl (sext GPR32:$Rm), SHIFT)),
5102 (i64 GPR64xsp:$Rn), (i32 GPR32:$Rm), (i64 7)>;
5104 defm : regoff_pats<"Wm", (add GPR64xsp:$Rn, (zext GPR32:$Rm)),
5105 (i64 GPR64xsp:$Rn), (i32 GPR32:$Rm), (i64 2)>;
5107 defm : regoff_pats<"Wm", (add GPR64xsp:$Rn, (shl (zext GPR32:$Rm), SHIFT)),
5108 (i64 GPR64xsp:$Rn), (i32 GPR32:$Rm), (i64 3)>;
5110 defm : regoff_pats<"Xm", (add GPR64xsp:$Rn, GPR64:$Rm),
5111 (i64 GPR64xsp:$Rn), (i64 GPR64:$Rm), (i64 2)>;
5113 defm : regoff_pats<"Xm", (add GPR64xsp:$Rn, (shl GPR64:$Rm, SHIFT)),
5114 (i64 GPR64xsp:$Rn), (i64 GPR64:$Rm), (i64 3)>;