1 //===- Mips64InstrInfo.td - Mips64 Instruction Information -*- tablegen -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file describes Mips64 instructions.
12 //===----------------------------------------------------------------------===//
14 //===----------------------------------------------------------------------===//
15 // Mips Operand, Complex Patterns and Transformations Definitions.
16 //===----------------------------------------------------------------------===//
18 // Instruction operand types
19 def shamt_64 : Operand<i64>;
22 def uimm16_64 : Operand<i64> {
23 let PrintMethod = "printUnsignedImm";
26 // Transformation Function - get Imm - 32.
27 def Subtract32 : SDNodeXForm<imm, [{
28 return getImm(N, (unsigned)N->getZExtValue() - 32);
31 // shamt must fit in 6 bits.
32 def immZExt6 : ImmLeaf<i32, [{return Imm == (Imm & 0x3f);}]>;
34 //===----------------------------------------------------------------------===//
35 // Instructions specific format
36 //===----------------------------------------------------------------------===//
37 let usesCustomInserter = 1 in {
38 def ATOMIC_LOAD_ADD_I64 : Atomic2Ops<atomic_load_add_64, GPR64>;
39 def ATOMIC_LOAD_SUB_I64 : Atomic2Ops<atomic_load_sub_64, GPR64>;
40 def ATOMIC_LOAD_AND_I64 : Atomic2Ops<atomic_load_and_64, GPR64>;
41 def ATOMIC_LOAD_OR_I64 : Atomic2Ops<atomic_load_or_64, GPR64>;
42 def ATOMIC_LOAD_XOR_I64 : Atomic2Ops<atomic_load_xor_64, GPR64>;
43 def ATOMIC_LOAD_NAND_I64 : Atomic2Ops<atomic_load_nand_64, GPR64>;
44 def ATOMIC_SWAP_I64 : Atomic2Ops<atomic_swap_64, GPR64>;
45 def ATOMIC_CMP_SWAP_I64 : AtomicCmpSwap<atomic_cmp_swap_64, GPR64>;
48 /// Pseudo instructions for loading and storing accumulator registers.
49 let isPseudo = 1, isCodeGenOnly = 1 in {
50 def LOAD_ACC128 : Load<"", ACC128>;
51 def STORE_ACC128 : Store<"", ACC128>;
54 //===----------------------------------------------------------------------===//
55 // Instruction definition
56 //===----------------------------------------------------------------------===//
57 let DecoderNamespace = "Mips64" in {
58 /// Arithmetic Instructions (ALU Immediate)
59 def DADDi : ArithLogicI<"daddi", simm16_64, GPR64Opnd>, ADDI_FM<0x18>;
60 def DADDiu : ArithLogicI<"daddiu", simm16_64, GPR64Opnd, IIArith,
62 ADDI_FM<0x19>, IsAsCheapAsAMove;
64 let isCodeGenOnly = 1 in {
65 def SLTi64 : SetCC_I<"slti", setlt, simm16_64, immSExt16, GPR64Opnd>,
67 def SLTiu64 : SetCC_I<"sltiu", setult, simm16_64, immSExt16, GPR64Opnd>,
69 def ANDi64 : ArithLogicI<"andi", uimm16_64, GPR64Opnd, IILogic, immZExt16,
72 def ORi64 : ArithLogicI<"ori", uimm16_64, GPR64Opnd, IILogic, immZExt16,
75 def XORi64 : ArithLogicI<"xori", uimm16_64, GPR64Opnd, IILogic, immZExt16,
78 def LUi64 : LoadUpper<"lui", GPR64Opnd, uimm16_64>, LUI_FM;
81 /// Arithmetic Instructions (3-Operand, R-Type)
82 def DADD : ArithLogicR<"dadd", GPR64Opnd>, ADD_FM<0, 0x2c>;
83 def DADDu : ArithLogicR<"daddu", GPR64Opnd, 1, IIArith, add>,
85 def DSUBu : ArithLogicR<"dsubu", GPR64Opnd, 0, IIArith, sub>,
88 let isCodeGenOnly = 1 in {
89 def SLT64 : SetCC_R<"slt", setlt, GPR64Opnd>, ADD_FM<0, 0x2a>;
90 def SLTu64 : SetCC_R<"sltu", setult, GPR64Opnd>, ADD_FM<0, 0x2b>;
91 def AND64 : ArithLogicR<"and", GPR64Opnd, 1, IIArith, and>, ADD_FM<0, 0x24>;
92 def OR64 : ArithLogicR<"or", GPR64Opnd, 1, IIArith, or>, ADD_FM<0, 0x25>;
93 def XOR64 : ArithLogicR<"xor", GPR64Opnd, 1, IIArith, xor>, ADD_FM<0, 0x26>;
94 def NOR64 : LogicNOR<"nor", GPR64Opnd>, ADD_FM<0, 0x27>;
97 /// Shift Instructions
98 def DSLL : shift_rotate_imm<"dsll", shamt, GPR64Opnd, shl, immZExt6>,
100 def DSRL : shift_rotate_imm<"dsrl", shamt, GPR64Opnd, srl, immZExt6>,
102 def DSRA : shift_rotate_imm<"dsra", shamt, GPR64Opnd, sra, immZExt6>,
104 def DSLLV : shift_rotate_reg<"dsllv", GPR64Opnd, shl>, SRLV_FM<0x14, 0>;
105 def DSRLV : shift_rotate_reg<"dsrlv", GPR64Opnd, srl>, SRLV_FM<0x16, 0>;
106 def DSRAV : shift_rotate_reg<"dsrav", GPR64Opnd, sra>, SRLV_FM<0x17, 0>;
107 def DSLL32 : shift_rotate_imm<"dsll32", shamt, GPR64Opnd>, SRA_FM<0x3c, 0>;
108 def DSRL32 : shift_rotate_imm<"dsrl32", shamt, GPR64Opnd>, SRA_FM<0x3e, 0>;
109 def DSRA32 : shift_rotate_imm<"dsra32", shamt, GPR64Opnd>, SRA_FM<0x3f, 0>;
111 // Rotate Instructions
112 let Predicates = [HasMips64r2, HasStdEnc] in {
113 def DROTR : shift_rotate_imm<"drotr", shamt, GPR64Opnd, rotr, immZExt6>,
115 def DROTRV : shift_rotate_reg<"drotrv", GPR64Opnd, rotr>,
119 /// Load and Store Instructions
121 let isCodeGenOnly = 1 in {
122 def LB64 : Load<"lb", GPR64Opnd, sextloadi8, IILoad>, LW_FM<0x20>;
123 def LBu64 : Load<"lbu", GPR64Opnd, zextloadi8, IILoad>, LW_FM<0x24>;
124 def LH64 : Load<"lh", GPR64Opnd, sextloadi16, IILoad>, LW_FM<0x21>;
125 def LHu64 : Load<"lhu", GPR64Opnd, zextloadi16, IILoad>, LW_FM<0x25>;
126 def LW64 : Load<"lw", GPR64Opnd, sextloadi32, IILoad>, LW_FM<0x23>;
127 def SB64 : Store<"sb", GPR64Opnd, truncstorei8, IIStore>, LW_FM<0x28>;
128 def SH64 : Store<"sh", GPR64Opnd, truncstorei16, IIStore>, LW_FM<0x29>;
129 def SW64 : Store<"sw", GPR64Opnd, truncstorei32, IIStore>, LW_FM<0x2b>;
132 def LWu : Load<"lwu", GPR64Opnd, zextloadi32, IILoad>, LW_FM<0x27>;
133 def LD : Load<"ld", GPR64Opnd, load, IILoad>, LW_FM<0x37>;
134 def SD : Store<"sd", GPR64Opnd, store, IIStore>, LW_FM<0x3f>;
136 /// load/store left/right
137 let isCodeGenOnly = 1 in {
138 def LWL64 : LoadLeftRight<"lwl", MipsLWL, GPR64Opnd>, LW_FM<0x22>;
139 def LWR64 : LoadLeftRight<"lwr", MipsLWR, GPR64Opnd>, LW_FM<0x26>;
140 def SWL64 : StoreLeftRight<"swl", MipsSWL, GPR64Opnd>, LW_FM<0x2a>;
141 def SWR64 : StoreLeftRight<"swr", MipsSWR, GPR64Opnd>, LW_FM<0x2e>;
144 def LDL : LoadLeftRight<"ldl", MipsLDL, GPR64Opnd>, LW_FM<0x1a>;
145 def LDR : LoadLeftRight<"ldr", MipsLDR, GPR64Opnd>, LW_FM<0x1b>;
146 def SDL : StoreLeftRight<"sdl", MipsSDL, GPR64Opnd>, LW_FM<0x2c>;
147 def SDR : StoreLeftRight<"sdr", MipsSDR, GPR64Opnd>, LW_FM<0x2d>;
149 /// Load-linked, Store-conditional
150 def LLD : LLBase<"lld", GPR64Opnd>, LW_FM<0x34>;
151 def SCD : SCBase<"scd", GPR64Opnd>, LW_FM<0x3c>;
153 /// Jump and Branch Instructions
154 let isCodeGenOnly = 1 in {
155 def JR64 : IndirectBranch<GPR64Opnd>, MTLO_FM<8>;
156 def BEQ64 : CBranch<"beq", seteq, GPR64Opnd>, BEQ_FM<4>;
157 def BNE64 : CBranch<"bne", setne, GPR64Opnd>, BEQ_FM<5>;
158 def BGEZ64 : CBranchZero<"bgez", setge, GPR64Opnd>, BGEZ_FM<1, 1>;
159 def BGTZ64 : CBranchZero<"bgtz", setgt, GPR64Opnd>, BGEZ_FM<7, 0>;
160 def BLEZ64 : CBranchZero<"blez", setle, GPR64Opnd>, BGEZ_FM<6, 0>;
161 def BLTZ64 : CBranchZero<"bltz", setlt, GPR64Opnd>, BGEZ_FM<1, 0>;
162 def JALR64 : JumpLinkReg<"jalr", GPR64Opnd>, JALR_FM;
163 def JALR64Pseudo : JumpLinkRegPseudo<GPR64Opnd, JALR, RA, GPR32Opnd>;
164 def TAILCALL64_R : JumpFR<GPR64Opnd, MipsTailCall>, MTLO_FM<8>, IsTailCall;
167 /// Multiply and Divide Instructions.
168 def DMULT : Mult<"dmult", IIImult, GPR64Opnd, [HI0_64, LO0_64]>,
170 def DMULTu : Mult<"dmultu", IIImult, GPR64Opnd, [HI0_64, LO0_64]>,
172 def PseudoDMULT : MultDivPseudo<DMULT, ACC128, GPR64Opnd, MipsMult,
174 def PseudoDMULTu : MultDivPseudo<DMULTu, ACC128, GPR64Opnd, MipsMultu,
176 def DSDIV : Div<"ddiv", IIIdiv, GPR64Opnd, [HI0_64, LO0_64]>, MULT_FM<0, 0x1e>;
177 def DUDIV : Div<"ddivu", IIIdiv, GPR64Opnd, [HI0_64, LO0_64]>, MULT_FM<0, 0x1f>;
178 def PseudoDSDIV : MultDivPseudo<DSDIV, ACC128, GPR64Opnd, MipsDivRem,
180 def PseudoDUDIV : MultDivPseudo<DUDIV, ACC128, GPR64Opnd, MipsDivRemU,
183 let isCodeGenOnly = 1 in {
184 def MTHI64 : MoveToLOHI<"mthi", GPR64Opnd, [HI0_64]>, MTLO_FM<0x11>;
185 def MTLO64 : MoveToLOHI<"mtlo", GPR64Opnd, [LO0_64]>, MTLO_FM<0x13>;
186 def MFHI64 : MoveFromLOHI<"mfhi", GPR64Opnd, [HI0_64]>, MFLO_FM<0x10>;
187 def MFLO64 : MoveFromLOHI<"mflo", GPR64Opnd, [LO0_64]>, MFLO_FM<0x12>;
189 /// Sign Ext In Register Instructions.
190 def SEB64 : SignExtInReg<"seb", i8, GPR64Opnd>, SEB_FM<0x10, 0x20>;
191 def SEH64 : SignExtInReg<"seh", i16, GPR64Opnd>, SEB_FM<0x18, 0x20>;
195 def DCLZ : CountLeading0<"dclz", GPR64Opnd>, CLO_FM<0x24>;
196 def DCLO : CountLeading1<"dclo", GPR64Opnd>, CLO_FM<0x25>;
198 /// Double Word Swap Bytes/HalfWords
199 def DSBH : SubwordSwap<"dsbh", GPR64Opnd>, SEB_FM<2, 0x24>;
200 def DSHD : SubwordSwap<"dshd", GPR64Opnd>, SEB_FM<5, 0x24>;
202 def LEA_ADDiu64 : EffectiveAddress<"daddiu", GPR64Opnd>, LW_FM<0x19>;
204 let isCodeGenOnly = 1 in
205 def RDHWR64 : ReadHardware<GPR64Opnd, HWRegsOpnd>, RDHWR_FM;
207 def DEXT : ExtBase<"dext", GPR64Opnd>, EXT_FM<3>;
208 let Pattern = []<dag> in {
209 def DEXTU : ExtBase<"dextu", GPR64Opnd>, EXT_FM<2>;
210 def DEXTM : ExtBase<"dextm", GPR64Opnd>, EXT_FM<1>;
212 def DINS : InsBase<"dins", GPR64Opnd>, EXT_FM<7>;
213 let Pattern = []<dag> in {
214 def DINSU : InsBase<"dinsu", GPR64Opnd>, EXT_FM<6>;
215 def DINSM : InsBase<"dinsm", GPR64Opnd>, EXT_FM<5>;
218 let isCodeGenOnly = 1, rs = 0, shamt = 0 in {
219 def DSLL64_32 : FR<0x00, 0x3c, (outs GPR64:$rd), (ins GPR32:$rt),
220 "dsll\t$rd, $rt, 32", [], IIArith>;
221 def SLL64_32 : FR<0x0, 0x00, (outs GPR64:$rd), (ins GPR32:$rt),
222 "sll\t$rd, $rt, 0", [], IIArith>;
223 def SLL64_64 : FR<0x0, 0x00, (outs GPR64:$rd), (ins GPR64:$rt),
224 "sll\t$rd, $rt, 0", [], IIArith>;
227 //===----------------------------------------------------------------------===//
228 // Arbitrary patterns that map to one or more instructions
229 //===----------------------------------------------------------------------===//
232 let Predicates = [HasStdEnc] in {
233 def : MipsPat<(i64 (extloadi1 addr:$src)), (LB64 addr:$src)>;
234 def : MipsPat<(i64 (extloadi8 addr:$src)), (LB64 addr:$src)>;
235 def : MipsPat<(i64 (extloadi16 addr:$src)), (LH64 addr:$src)>;
236 def : MipsPat<(i64 (extloadi32 addr:$src)), (LW64 addr:$src)>;
240 def : MipsPat<(MipsHi tglobaladdr:$in), (LUi64 tglobaladdr:$in)>;
241 def : MipsPat<(MipsHi tblockaddress:$in), (LUi64 tblockaddress:$in)>;
242 def : MipsPat<(MipsHi tjumptable:$in), (LUi64 tjumptable:$in)>;
243 def : MipsPat<(MipsHi tconstpool:$in), (LUi64 tconstpool:$in)>;
244 def : MipsPat<(MipsHi tglobaltlsaddr:$in), (LUi64 tglobaltlsaddr:$in)>;
245 def : MipsPat<(MipsHi texternalsym:$in), (LUi64 texternalsym:$in)>;
247 def : MipsPat<(MipsLo tglobaladdr:$in), (DADDiu ZERO_64, tglobaladdr:$in)>;
248 def : MipsPat<(MipsLo tblockaddress:$in), (DADDiu ZERO_64, tblockaddress:$in)>;
249 def : MipsPat<(MipsLo tjumptable:$in), (DADDiu ZERO_64, tjumptable:$in)>;
250 def : MipsPat<(MipsLo tconstpool:$in), (DADDiu ZERO_64, tconstpool:$in)>;
251 def : MipsPat<(MipsLo tglobaltlsaddr:$in),
252 (DADDiu ZERO_64, tglobaltlsaddr:$in)>;
253 def : MipsPat<(MipsLo texternalsym:$in), (DADDiu ZERO_64, texternalsym:$in)>;
255 def : MipsPat<(add GPR64:$hi, (MipsLo tglobaladdr:$lo)),
256 (DADDiu GPR64:$hi, tglobaladdr:$lo)>;
257 def : MipsPat<(add GPR64:$hi, (MipsLo tblockaddress:$lo)),
258 (DADDiu GPR64:$hi, tblockaddress:$lo)>;
259 def : MipsPat<(add GPR64:$hi, (MipsLo tjumptable:$lo)),
260 (DADDiu GPR64:$hi, tjumptable:$lo)>;
261 def : MipsPat<(add GPR64:$hi, (MipsLo tconstpool:$lo)),
262 (DADDiu GPR64:$hi, tconstpool:$lo)>;
263 def : MipsPat<(add GPR64:$hi, (MipsLo tglobaltlsaddr:$lo)),
264 (DADDiu GPR64:$hi, tglobaltlsaddr:$lo)>;
266 def : WrapperPat<tglobaladdr, DADDiu, GPR64>;
267 def : WrapperPat<tconstpool, DADDiu, GPR64>;
268 def : WrapperPat<texternalsym, DADDiu, GPR64>;
269 def : WrapperPat<tblockaddress, DADDiu, GPR64>;
270 def : WrapperPat<tjumptable, DADDiu, GPR64>;
271 def : WrapperPat<tglobaltlsaddr, DADDiu, GPR64>;
273 defm : BrcondPats<GPR64, BEQ64, BNE64, SLT64, SLTu64, SLTi64, SLTiu64,
276 def : MipsPat<(brcond (i32 (setlt i64:$lhs, 1)), bb:$dst),
277 (BLEZ64 i64:$lhs, bb:$dst)>;
278 def : MipsPat<(brcond (i32 (setgt i64:$lhs, -1)), bb:$dst),
279 (BGEZ64 i64:$lhs, bb:$dst)>;
282 defm : SeteqPats<GPR64, SLTiu64, XOR64, SLTu64, ZERO_64>;
283 defm : SetlePats<GPR64, SLT64, SLTu64>;
284 defm : SetgtPats<GPR64, SLT64, SLTu64>;
285 defm : SetgePats<GPR64, SLT64, SLTu64>;
286 defm : SetgeImmPats<GPR64, SLTi64, SLTiu64>;
289 def : MipsPat<(i32 (trunc GPR64:$src)),
290 (SLL (EXTRACT_SUBREG GPR64:$src, sub_32), 0)>,
291 Requires<[IsN64, HasStdEnc]>;
293 // 32-to-64-bit extension
294 def : MipsPat<(i64 (anyext GPR32:$src)), (SLL64_32 GPR32:$src)>;
295 def : MipsPat<(i64 (zext GPR32:$src)), (DSRL (DSLL64_32 GPR32:$src), 32)>;
296 def : MipsPat<(i64 (sext GPR32:$src)), (SLL64_32 GPR32:$src)>;
298 // Sign extend in register
299 def : MipsPat<(i64 (sext_inreg GPR64:$src, i32)),
300 (SLL64_64 GPR64:$src)>;
303 def : MipsPat<(bswap GPR64:$rt), (DSHD (DSBH GPR64:$rt))>;
306 def : MipsPat<(i64 (ExtractLOHI ACC128:$ac, imm:$lohi_idx)),
307 (EXTRACT_SUBREG ACC128:$ac, imm:$lohi_idx)>;
309 //===----------------------------------------------------------------------===//
310 // Instruction aliases
311 //===----------------------------------------------------------------------===//
312 def : InstAlias<"move $dst, $src",
313 (DADDu GPR64Opnd:$dst, GPR64Opnd:$src, ZERO_64), 1>,
314 Requires<[HasMips64]>;
315 def : InstAlias<"daddu $rs, $rt, $imm",
316 (DADDiu GPR64Opnd:$rs, GPR64Opnd:$rt, simm16_64:$imm),
318 def : InstAlias<"dadd $rs, $rt, $imm",
319 (DADDi GPR64Opnd:$rs, GPR64Opnd:$rt, simm16_64:$imm),
322 /// Move between CPU and coprocessor registers
323 let DecoderNamespace = "Mips64" in {
324 def DMFC0_3OP64 : MFC3OP<(outs GPR64Opnd:$rt),
325 (ins GPR64Opnd:$rd, uimm16:$sel),
326 "dmfc0\t$rt, $rd, $sel">, MFC3OP_FM<0x10, 1>;
327 def DMTC0_3OP64 : MFC3OP<(outs GPR64Opnd:$rd, uimm16:$sel),
329 "dmtc0\t$rt, $rd, $sel">, MFC3OP_FM<0x10, 5>;
330 def DMFC2_3OP64 : MFC3OP<(outs GPR64Opnd:$rt),
331 (ins GPR64Opnd:$rd, uimm16:$sel),
332 "dmfc2\t$rt, $rd, $sel">, MFC3OP_FM<0x12, 1>;
333 def DMTC2_3OP64 : MFC3OP<(outs GPR64Opnd:$rd, uimm16:$sel),
335 "dmtc2\t$rt, $rd, $sel">, MFC3OP_FM<0x12, 5>;
338 // Two operand (implicit 0 selector) versions:
339 def : InstAlias<"dmfc0 $rt, $rd",
340 (DMFC0_3OP64 GPR64Opnd:$rt, GPR64Opnd:$rd, 0), 0>;
341 def : InstAlias<"dmtc0 $rt, $rd",
342 (DMTC0_3OP64 GPR64Opnd:$rd, 0, GPR64Opnd:$rt), 0>;
343 def : InstAlias<"dmfc2 $rt, $rd",
344 (DMFC2_3OP64 GPR64Opnd:$rt, GPR64Opnd:$rd, 0), 0>;
345 def : InstAlias<"dmtc2 $rt, $rd",
346 (DMTC2_3OP64 GPR64Opnd:$rd, 0, GPR64Opnd:$rt), 0>;