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