1 //===- MipsInstrInfo.td - Target Description for Mips Target -*- 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 contains the Mips implementation of the TargetInstrInfo class. 11 // 12 //===----------------------------------------------------------------------===// 13 14 15 //===----------------------------------------------------------------------===// 16 // Mips profiles and nodes 17 //===----------------------------------------------------------------------===// 18 19 def SDT_MipsJmpLink : SDTypeProfile<0, 1, [SDTCisVT<0, iPTR>]>; 20 def SDT_MipsCMov : SDTypeProfile<1, 4, [SDTCisSameAs<0, 1>, 21 SDTCisSameAs<1, 2>, 22 SDTCisSameAs<3, 4>, 23 SDTCisInt<4>]>; 24 def SDT_MipsCallSeqStart : SDCallSeqStart<[SDTCisVT<0, i32>]>; 25 def SDT_MipsCallSeqEnd : SDCallSeqEnd<[SDTCisVT<0, i32>, SDTCisVT<1, i32>]>; 26 def SDT_ExtractLOHI : SDTypeProfile<1, 2, [SDTCisInt<0>, SDTCisVT<1, untyped>, 27 SDTCisVT<2, i32>]>; 28 def SDT_InsertLOHI : SDTypeProfile<1, 2, [SDTCisVT<0, untyped>, 29 SDTCisVT<1, i32>, 30 SDTCisSameAs<1, 2>]>; 31 def SDT_MipsMultDiv : SDTypeProfile<1, 2, [SDTCisVT<0, untyped>, SDTCisInt<1>, 32 SDTCisSameAs<1, 2>]>; 33 def SDT_MipsMAddMSub : SDTypeProfile<1, 3, 34 [SDTCisVT<0, untyped>, SDTCisSameAs<0, 3>, 35 SDTCisVT<1, i32>, SDTCisSameAs<1, 2>]>; 36 def SDT_MipsDivRem16 : SDTypeProfile<0, 2, [SDTCisInt<0>, SDTCisSameAs<0, 1>]>; 37 38 def SDT_MipsThreadPointer : SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>; 39 40 def SDT_Sync : SDTypeProfile<0, 1, [SDTCisVT<0, i32>]>; 41 42 def SDT_Ext : SDTypeProfile<1, 3, [SDTCisInt<0>, SDTCisSameAs<0, 1>, 43 SDTCisVT<2, i32>, SDTCisSameAs<2, 3>]>; 44 def SDT_Ins : SDTypeProfile<1, 4, [SDTCisInt<0>, SDTCisSameAs<0, 1>, 45 SDTCisVT<2, i32>, SDTCisSameAs<2, 3>, 46 SDTCisSameAs<0, 4>]>; 47 48 def SDTMipsLoadLR : SDTypeProfile<1, 2, 49 [SDTCisInt<0>, SDTCisPtrTy<1>, 50 SDTCisSameAs<0, 2>]>; 51 52 // Call 53 def MipsJmpLink : SDNode<"MipsISD::JmpLink",SDT_MipsJmpLink, 54 [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue, 55 SDNPVariadic]>; 56 57 // Tail call 58 def MipsTailCall : SDNode<"MipsISD::TailCall", SDT_MipsJmpLink, 59 [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>; 60 61 // Hi and Lo nodes are used to handle global addresses. Used on 62 // MipsISelLowering to lower stuff like GlobalAddress, ExternalSymbol 63 // static model. (nothing to do with Mips Registers Hi and Lo) 64 def MipsHi : SDNode<"MipsISD::Hi", SDTIntUnaryOp>; 65 def MipsLo : SDNode<"MipsISD::Lo", SDTIntUnaryOp>; 66 def MipsGPRel : SDNode<"MipsISD::GPRel", SDTIntUnaryOp>; 67 68 // TlsGd node is used to handle General Dynamic TLS 69 def MipsTlsGd : SDNode<"MipsISD::TlsGd", SDTIntUnaryOp>; 70 71 // TprelHi and TprelLo nodes are used to handle Local Exec TLS 72 def MipsTprelHi : SDNode<"MipsISD::TprelHi", SDTIntUnaryOp>; 73 def MipsTprelLo : SDNode<"MipsISD::TprelLo", SDTIntUnaryOp>; 74 75 // Thread pointer 76 def MipsThreadPointer: SDNode<"MipsISD::ThreadPointer", SDT_MipsThreadPointer>; 77 78 // Return 79 def MipsRet : SDNode<"MipsISD::Ret", SDTNone, 80 [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>; 81 82 // These are target-independent nodes, but have target-specific formats. 83 def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_MipsCallSeqStart, 84 [SDNPHasChain, SDNPSideEffect, SDNPOutGlue]>; 85 def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_MipsCallSeqEnd, 86 [SDNPHasChain, SDNPSideEffect, 87 SDNPOptInGlue, SDNPOutGlue]>; 88 89 // Node used to extract integer from LO/HI register. 90 def ExtractLOHI : SDNode<"MipsISD::ExtractLOHI", SDT_ExtractLOHI>; 91 92 // Node used to insert 32-bit integers to LOHI register pair. 93 def InsertLOHI : SDNode<"MipsISD::InsertLOHI", SDT_InsertLOHI>; 94 95 // Mult nodes. 96 def MipsMult : SDNode<"MipsISD::Mult", SDT_MipsMultDiv>; 97 def MipsMultu : SDNode<"MipsISD::Multu", SDT_MipsMultDiv>; 98 99 // MAdd*/MSub* nodes 100 def MipsMAdd : SDNode<"MipsISD::MAdd", SDT_MipsMAddMSub>; 101 def MipsMAddu : SDNode<"MipsISD::MAddu", SDT_MipsMAddMSub>; 102 def MipsMSub : SDNode<"MipsISD::MSub", SDT_MipsMAddMSub>; 103 def MipsMSubu : SDNode<"MipsISD::MSubu", SDT_MipsMAddMSub>; 104 105 // DivRem(u) nodes 106 def MipsDivRem : SDNode<"MipsISD::DivRem", SDT_MipsMultDiv>; 107 def MipsDivRemU : SDNode<"MipsISD::DivRemU", SDT_MipsMultDiv>; 108 def MipsDivRem16 : SDNode<"MipsISD::DivRem16", SDT_MipsDivRem16, 109 [SDNPOutGlue]>; 110 def MipsDivRemU16 : SDNode<"MipsISD::DivRemU16", SDT_MipsDivRem16, 111 [SDNPOutGlue]>; 112 113 // Target constant nodes that are not part of any isel patterns and remain 114 // unchanged can cause instructions with illegal operands to be emitted. 115 // Wrapper node patterns give the instruction selector a chance to replace 116 // target constant nodes that would otherwise remain unchanged with ADDiu 117 // nodes. Without these wrapper node patterns, the following conditional move 118 // instrucion is emitted when function cmov2 in test/CodeGen/Mips/cmov.ll is 119 // compiled: 120 // movn %got(d)($gp), %got(c)($gp), $4 121 // This instruction is illegal since movn can take only register operands. 122 123 def MipsWrapper : SDNode<"MipsISD::Wrapper", SDTIntBinOp>; 124 125 def MipsSync : SDNode<"MipsISD::Sync", SDT_Sync, [SDNPHasChain,SDNPSideEffect]>; 126 127 def MipsExt : SDNode<"MipsISD::Ext", SDT_Ext>; 128 def MipsIns : SDNode<"MipsISD::Ins", SDT_Ins>; 129 130 def MipsLWL : SDNode<"MipsISD::LWL", SDTMipsLoadLR, 131 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>; 132 def MipsLWR : SDNode<"MipsISD::LWR", SDTMipsLoadLR, 133 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>; 134 def MipsSWL : SDNode<"MipsISD::SWL", SDTStore, 135 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>; 136 def MipsSWR : SDNode<"MipsISD::SWR", SDTStore, 137 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>; 138 def MipsLDL : SDNode<"MipsISD::LDL", SDTMipsLoadLR, 139 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>; 140 def MipsLDR : SDNode<"MipsISD::LDR", SDTMipsLoadLR, 141 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>; 142 def MipsSDL : SDNode<"MipsISD::SDL", SDTStore, 143 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>; 144 def MipsSDR : SDNode<"MipsISD::SDR", SDTStore, 145 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>; 146 147 //===----------------------------------------------------------------------===// 148 // Mips Instruction Predicate Definitions. 149 //===----------------------------------------------------------------------===// 150 def HasSEInReg : Predicate<"Subtarget.hasSEInReg()">, 151 AssemblerPredicate<"FeatureSEInReg">; 152 def HasBitCount : Predicate<"Subtarget.hasBitCount()">, 153 AssemblerPredicate<"FeatureBitCount">; 154 def HasSwap : Predicate<"Subtarget.hasSwap()">, 155 AssemblerPredicate<"FeatureSwap">; 156 def HasCondMov : Predicate<"Subtarget.hasCondMov()">, 157 AssemblerPredicate<"FeatureCondMov">; 158 def HasFPIdx : Predicate<"Subtarget.hasFPIdx()">, 159 AssemblerPredicate<"FeatureFPIdx">; 160 def HasMips32 : Predicate<"Subtarget.hasMips32()">, 161 AssemblerPredicate<"FeatureMips32">; 162 def HasMips32r2 : Predicate<"Subtarget.hasMips32r2()">, 163 AssemblerPredicate<"FeatureMips32r2">; 164 def HasMips64 : Predicate<"Subtarget.hasMips64()">, 165 AssemblerPredicate<"FeatureMips64">; 166 def NotMips64 : Predicate<"!Subtarget.hasMips64()">, 167 AssemblerPredicate<"!FeatureMips64">; 168 def HasMips64r2 : Predicate<"Subtarget.hasMips64r2()">, 169 AssemblerPredicate<"FeatureMips64r2">; 170 def IsN64 : Predicate<"Subtarget.isABI_N64()">, 171 AssemblerPredicate<"FeatureN64">; 172 def NotN64 : Predicate<"!Subtarget.isABI_N64()">, 173 AssemblerPredicate<"!FeatureN64">; 174 def InMips16Mode : Predicate<"Subtarget.inMips16Mode()">, 175 AssemblerPredicate<"FeatureMips16">; 176 def RelocStatic : Predicate<"TM.getRelocationModel() == Reloc::Static">, 177 AssemblerPredicate<"FeatureMips32">; 178 def RelocPIC : Predicate<"TM.getRelocationModel() == Reloc::PIC_">, 179 AssemblerPredicate<"FeatureMips32">; 180 def NoNaNsFPMath : Predicate<"TM.Options.NoNaNsFPMath">, 181 AssemblerPredicate<"FeatureMips32">; 182 def HasStdEnc : Predicate<"Subtarget.hasStandardEncoding()">, 183 AssemblerPredicate<"!FeatureMips16">; 184 def NotDSP : Predicate<"!Subtarget.hasDSP()">; 185 186 class MipsPat<dag pattern, dag result> : Pat<pattern, result> { 187 let Predicates = [HasStdEnc]; 188 } 189 190 class IsCommutable { 191 bit isCommutable = 1; 192 } 193 194 class IsBranch { 195 bit isBranch = 1; 196 } 197 198 class IsReturn { 199 bit isReturn = 1; 200 } 201 202 class IsCall { 203 bit isCall = 1; 204 } 205 206 class IsTailCall { 207 bit isCall = 1; 208 bit isTerminator = 1; 209 bit isReturn = 1; 210 bit isBarrier = 1; 211 bit hasExtraSrcRegAllocReq = 1; 212 bit isCodeGenOnly = 1; 213 } 214 215 class IsAsCheapAsAMove { 216 bit isAsCheapAsAMove = 1; 217 } 218 219 class NeverHasSideEffects { 220 bit neverHasSideEffects = 1; 221 } 222 223 //===----------------------------------------------------------------------===// 224 // Instruction format superclass 225 //===----------------------------------------------------------------------===// 226 227 include "MipsInstrFormats.td" 228 229 //===----------------------------------------------------------------------===// 230 // Mips Operand, Complex Patterns and Transformations Definitions. 231 //===----------------------------------------------------------------------===// 232 233 // Instruction operand types 234 def jmptarget : Operand<OtherVT> { 235 let EncoderMethod = "getJumpTargetOpValue"; 236 } 237 def brtarget : Operand<OtherVT> { 238 let EncoderMethod = "getBranchTargetOpValue"; 239 let OperandType = "OPERAND_PCREL"; 240 let DecoderMethod = "DecodeBranchTarget"; 241 } 242 def calltarget : Operand<iPTR> { 243 let EncoderMethod = "getJumpTargetOpValue"; 244 } 245 def calltarget64: Operand<i64>; 246 def simm16 : Operand<i32> { 247 let DecoderMethod= "DecodeSimm16"; 248 } 249 250 def simm20 : Operand<i32> { 251 } 252 253 def uimm20 : Operand<i32> { 254 } 255 256 def uimm10 : Operand<i32> { 257 } 258 259 def simm16_64 : Operand<i64>; 260 def shamt : Operand<i32>; 261 262 // Unsigned Operand 263 def uimm16 : Operand<i32> { 264 let PrintMethod = "printUnsignedImm"; 265 } 266 267 def MipsMemAsmOperand : AsmOperandClass { 268 let Name = "Mem"; 269 let ParserMethod = "parseMemOperand"; 270 } 271 272 // Address operand 273 def mem : Operand<i32> { 274 let PrintMethod = "printMemOperand"; 275 let MIOperandInfo = (ops GPR32, simm16); 276 let EncoderMethod = "getMemEncoding"; 277 let ParserMatchClass = MipsMemAsmOperand; 278 let OperandType = "OPERAND_MEMORY"; 279 } 280 281 def mem64 : Operand<i64> { 282 let PrintMethod = "printMemOperand"; 283 let MIOperandInfo = (ops GPR64, simm16_64); 284 let EncoderMethod = "getMemEncoding"; 285 let ParserMatchClass = MipsMemAsmOperand; 286 let OperandType = "OPERAND_MEMORY"; 287 } 288 289 def mem_ea : Operand<i32> { 290 let PrintMethod = "printMemOperandEA"; 291 let MIOperandInfo = (ops GPR32, simm16); 292 let EncoderMethod = "getMemEncoding"; 293 let OperandType = "OPERAND_MEMORY"; 294 } 295 296 def mem_ea_64 : Operand<i64> { 297 let PrintMethod = "printMemOperandEA"; 298 let MIOperandInfo = (ops GPR64, simm16_64); 299 let EncoderMethod = "getMemEncoding"; 300 let OperandType = "OPERAND_MEMORY"; 301 } 302 303 // size operand of ext instruction 304 def size_ext : Operand<i32> { 305 let EncoderMethod = "getSizeExtEncoding"; 306 let DecoderMethod = "DecodeExtSize"; 307 } 308 309 // size operand of ins instruction 310 def size_ins : Operand<i32> { 311 let EncoderMethod = "getSizeInsEncoding"; 312 let DecoderMethod = "DecodeInsSize"; 313 } 314 315 // Transformation Function - get the lower 16 bits. 316 def LO16 : SDNodeXForm<imm, [{ 317 return getImm(N, N->getZExtValue() & 0xFFFF); 318 }]>; 319 320 // Transformation Function - get the higher 16 bits. 321 def HI16 : SDNodeXForm<imm, [{ 322 return getImm(N, (N->getZExtValue() >> 16) & 0xFFFF); 323 }]>; 324 325 // Plus 1. 326 def Plus1 : SDNodeXForm<imm, [{ return getImm(N, N->getSExtValue() + 1); }]>; 327 328 // Node immediate fits as 16-bit sign extended on target immediate. 329 // e.g. addi, andi 330 def immSExt8 : PatLeaf<(imm), [{ return isInt<8>(N->getSExtValue()); }]>; 331 332 // Node immediate fits as 16-bit sign extended on target immediate. 333 // e.g. addi, andi 334 def immSExt16 : PatLeaf<(imm), [{ return isInt<16>(N->getSExtValue()); }]>; 335 336 // Node immediate fits as 15-bit sign extended on target immediate. 337 // e.g. addi, andi 338 def immSExt15 : PatLeaf<(imm), [{ return isInt<15>(N->getSExtValue()); }]>; 339 340 // Node immediate fits as 16-bit zero extended on target immediate. 341 // The LO16 param means that only the lower 16 bits of the node 342 // immediate are caught. 343 // e.g. addiu, sltiu 344 def immZExt16 : PatLeaf<(imm), [{ 345 if (N->getValueType(0) == MVT::i32) 346 return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue(); 347 else 348 return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue(); 349 }], LO16>; 350 351 // Immediate can be loaded with LUi (32-bit int with lower 16-bit cleared). 352 def immLow16Zero : PatLeaf<(imm), [{ 353 int64_t Val = N->getSExtValue(); 354 return isInt<32>(Val) && !(Val & 0xffff); 355 }]>; 356 357 // shamt field must fit in 5 bits. 358 def immZExt5 : ImmLeaf<i32, [{return Imm == (Imm & 0x1f);}]>; 359 360 // True if (N + 1) fits in 16-bit field. 361 def immSExt16Plus1 : PatLeaf<(imm), [{ 362 return isInt<17>(N->getSExtValue()) && isInt<16>(N->getSExtValue() + 1); 363 }]>; 364 365 // Mips Address Mode! SDNode frameindex could possibily be a match 366 // since load and store instructions from stack used it. 367 def addr : 368 ComplexPattern<iPTR, 2, "selectIntAddr", [frameindex]>; 369 370 def addrRegImm : 371 ComplexPattern<iPTR, 2, "selectAddrRegImm", [frameindex]>; 372 373 def addrDefault : 374 ComplexPattern<iPTR, 2, "selectAddrDefault", [frameindex]>; 375 376 //===----------------------------------------------------------------------===// 377 // Instructions specific format 378 //===----------------------------------------------------------------------===// 379 380 // Arithmetic and logical instructions with 3 register operands. 381 class ArithLogicR<string opstr, RegisterOperand RO, bit isComm = 0, 382 InstrItinClass Itin = NoItinerary, 383 SDPatternOperator OpNode = null_frag>: 384 InstSE<(outs RO:$rd), (ins RO:$rs, RO:$rt), 385 !strconcat(opstr, "\t$rd, $rs, $rt"), 386 [(set RO:$rd, (OpNode RO:$rs, RO:$rt))], Itin, FrmR, opstr> { 387 let isCommutable = isComm; 388 let isReMaterializable = 1; 389 } 390 391 // Arithmetic and logical instructions with 2 register operands. 392 class ArithLogicI<string opstr, Operand Od, RegisterOperand RO, 393 InstrItinClass Itin = NoItinerary, 394 SDPatternOperator imm_type = null_frag, 395 SDPatternOperator OpNode = null_frag> : 396 InstSE<(outs RO:$rt), (ins RO:$rs, Od:$imm16), 397 !strconcat(opstr, "\t$rt, $rs, $imm16"), 398 [(set RO:$rt, (OpNode RO:$rs, imm_type:$imm16))], 399 Itin, FrmI, opstr> { 400 let isReMaterializable = 1; 401 let TwoOperandAliasConstraint = "$rs = $rt"; 402 } 403 404 // Arithmetic Multiply ADD/SUB 405 class MArithR<string opstr, bit isComm = 0> : 406 InstSE<(outs), (ins GPR32Opnd:$rs, GPR32Opnd:$rt), 407 !strconcat(opstr, "\t$rs, $rt"), [], IIImult, FrmR> { 408 let Defs = [HI, LO]; 409 let Uses = [HI, LO]; 410 let isCommutable = isComm; 411 } 412 413 // Logical 414 class LogicNOR<string opstr, RegisterOperand RO>: 415 InstSE<(outs RO:$rd), (ins RO:$rs, RO:$rt), 416 !strconcat(opstr, "\t$rd, $rs, $rt"), 417 [(set RO:$rd, (not (or RO:$rs, RO:$rt)))], IIArith, FrmR, opstr> { 418 let isCommutable = 1; 419 } 420 421 // Shifts 422 class shift_rotate_imm<string opstr, Operand ImmOpnd, 423 RegisterOperand RO, SDPatternOperator OpNode = null_frag, 424 SDPatternOperator PF = null_frag> : 425 InstSE<(outs RO:$rd), (ins RO:$rt, ImmOpnd:$shamt), 426 !strconcat(opstr, "\t$rd, $rt, $shamt"), 427 [(set RO:$rd, (OpNode RO:$rt, PF:$shamt))], IIArith, FrmR, opstr>; 428 429 class shift_rotate_reg<string opstr, RegisterOperand RO, 430 SDPatternOperator OpNode = null_frag>: 431 InstSE<(outs RO:$rd), (ins RO:$rt, GPR32Opnd:$rs), 432 !strconcat(opstr, "\t$rd, $rt, $rs"), 433 [(set RO:$rd, (OpNode RO:$rt, GPR32Opnd:$rs))], IIArith, FrmR, opstr>; 434 435 // Load Upper Imediate 436 class LoadUpper<string opstr, RegisterOperand RO, Operand Imm>: 437 InstSE<(outs RO:$rt), (ins Imm:$imm16), !strconcat(opstr, "\t$rt, $imm16"), 438 [], IIArith, FrmI>, IsAsCheapAsAMove { 439 let neverHasSideEffects = 1; 440 let isReMaterializable = 1; 441 } 442 443 class FMem<bits<6> op, dag outs, dag ins, string asmstr, list<dag> pattern, 444 InstrItinClass itin>: FFI<op, outs, ins, asmstr, pattern> { 445 bits<21> addr; 446 let Inst{25-21} = addr{20-16}; 447 let Inst{15-0} = addr{15-0}; 448 let DecoderMethod = "DecodeMem"; 449 } 450 451 // Memory Load/Store 452 class Load<string opstr, SDPatternOperator OpNode, DAGOperand RO, 453 InstrItinClass Itin, Operand MemOpnd, ComplexPattern Addr, 454 string ofsuffix> : 455 InstSE<(outs RO:$rt), (ins MemOpnd:$addr), !strconcat(opstr, "\t$rt, $addr"), 456 [(set RO:$rt, (OpNode Addr:$addr))], NoItinerary, FrmI, 457 !strconcat(opstr, ofsuffix)> { 458 let DecoderMethod = "DecodeMem"; 459 let canFoldAsLoad = 1; 460 let mayLoad = 1; 461 } 462 463 class Store<string opstr, SDPatternOperator OpNode, DAGOperand RO, 464 InstrItinClass Itin, Operand MemOpnd, ComplexPattern Addr, 465 string ofsuffix> : 466 InstSE<(outs), (ins RO:$rt, MemOpnd:$addr), !strconcat(opstr, "\t$rt, $addr"), 467 [(OpNode RO:$rt, Addr:$addr)], NoItinerary, FrmI, 468 !strconcat(opstr, ofsuffix)> { 469 let DecoderMethod = "DecodeMem"; 470 let mayStore = 1; 471 } 472 473 multiclass LoadM<string opstr, DAGOperand RO, 474 SDPatternOperator OpNode = null_frag, 475 InstrItinClass Itin = NoItinerary, 476 ComplexPattern Addr = addr> { 477 def NAME : Load<opstr, OpNode, RO, Itin, mem, Addr, "">, 478 Requires<[NotN64, HasStdEnc]>; 479 def _P8 : Load<opstr, OpNode, RO, Itin, mem64, Addr, "_p8">, 480 Requires<[IsN64, HasStdEnc]> { 481 let DecoderNamespace = "Mips64"; 482 let isCodeGenOnly = 1; 483 } 484 } 485 486 multiclass StoreM<string opstr, DAGOperand RO, 487 SDPatternOperator OpNode = null_frag, 488 InstrItinClass Itin = NoItinerary, 489 ComplexPattern Addr = addr> { 490 def NAME : Store<opstr, OpNode, RO, Itin, mem, Addr, "">, 491 Requires<[NotN64, HasStdEnc]>; 492 def _P8 : Store<opstr, OpNode, RO, Itin, mem64, Addr, "_p8">, 493 Requires<[IsN64, HasStdEnc]> { 494 let DecoderNamespace = "Mips64"; 495 let isCodeGenOnly = 1; 496 } 497 } 498 499 // Load/Store Left/Right 500 let canFoldAsLoad = 1 in 501 class LoadLeftRight<string opstr, SDNode OpNode, RegisterOperand RO, 502 Operand MemOpnd> : 503 InstSE<(outs RO:$rt), (ins MemOpnd:$addr, RO:$src), 504 !strconcat(opstr, "\t$rt, $addr"), 505 [(set RO:$rt, (OpNode addr:$addr, RO:$src))], NoItinerary, FrmI> { 506 let DecoderMethod = "DecodeMem"; 507 string Constraints = "$src = $rt"; 508 } 509 510 class StoreLeftRight<string opstr, SDNode OpNode, RegisterOperand RO, 511 Operand MemOpnd>: 512 InstSE<(outs), (ins RO:$rt, MemOpnd:$addr), !strconcat(opstr, "\t$rt, $addr"), 513 [(OpNode RO:$rt, addr:$addr)], NoItinerary, FrmI> { 514 let DecoderMethod = "DecodeMem"; 515 } 516 517 multiclass LoadLeftRightM<string opstr, SDNode OpNode, RegisterOperand RO> { 518 def NAME : LoadLeftRight<opstr, OpNode, RO, mem>, 519 Requires<[NotN64, HasStdEnc]>; 520 def _P8 : LoadLeftRight<opstr, OpNode, RO, mem64>, 521 Requires<[IsN64, HasStdEnc]> { 522 let DecoderNamespace = "Mips64"; 523 let isCodeGenOnly = 1; 524 } 525 } 526 527 multiclass StoreLeftRightM<string opstr, SDNode OpNode, RegisterOperand RO> { 528 def NAME : StoreLeftRight<opstr, OpNode, RO, mem>, 529 Requires<[NotN64, HasStdEnc]>; 530 def _P8 : StoreLeftRight<opstr, OpNode, RO, mem64>, 531 Requires<[IsN64, HasStdEnc]> { 532 let DecoderNamespace = "Mips64"; 533 let isCodeGenOnly = 1; 534 } 535 } 536 537 // Conditional Branch 538 class CBranch<string opstr, PatFrag cond_op, RegisterOperand RO> : 539 InstSE<(outs), (ins RO:$rs, RO:$rt, brtarget:$offset), 540 !strconcat(opstr, "\t$rs, $rt, $offset"), 541 [(brcond (i32 (cond_op RO:$rs, RO:$rt)), bb:$offset)], IIBranch, 542 FrmI> { 543 let isBranch = 1; 544 let isTerminator = 1; 545 let hasDelaySlot = 1; 546 let Defs = [AT]; 547 } 548 549 class CBranchZero<string opstr, PatFrag cond_op, RegisterOperand RO> : 550 InstSE<(outs), (ins RO:$rs, brtarget:$offset), 551 !strconcat(opstr, "\t$rs, $offset"), 552 [(brcond (i32 (cond_op RO:$rs, 0)), bb:$offset)], IIBranch, FrmI> { 553 let isBranch = 1; 554 let isTerminator = 1; 555 let hasDelaySlot = 1; 556 let Defs = [AT]; 557 } 558 559 // SetCC 560 class SetCC_R<string opstr, PatFrag cond_op, RegisterOperand RO> : 561 InstSE<(outs GPR32Opnd:$rd), (ins RO:$rs, RO:$rt), 562 !strconcat(opstr, "\t$rd, $rs, $rt"), 563 [(set GPR32Opnd:$rd, (cond_op RO:$rs, RO:$rt))], 564 IIslt, FrmR, opstr>; 565 566 class SetCC_I<string opstr, PatFrag cond_op, Operand Od, PatLeaf imm_type, 567 RegisterOperand RO>: 568 InstSE<(outs GPR32Opnd:$rt), (ins RO:$rs, Od:$imm16), 569 !strconcat(opstr, "\t$rt, $rs, $imm16"), 570 [(set GPR32Opnd:$rt, (cond_op RO:$rs, imm_type:$imm16))], 571 IIslt, FrmI, opstr>; 572 573 // Jump 574 class JumpFJ<DAGOperand opnd, string opstr, SDPatternOperator operator, 575 SDPatternOperator targetoperator> : 576 InstSE<(outs), (ins opnd:$target), !strconcat(opstr, "\t$target"), 577 [(operator targetoperator:$target)], IIBranch, FrmJ> { 578 let isTerminator=1; 579 let isBarrier=1; 580 let hasDelaySlot = 1; 581 let DecoderMethod = "DecodeJumpTarget"; 582 let Defs = [AT]; 583 } 584 585 // Unconditional branch 586 class UncondBranch<string opstr> : 587 InstSE<(outs), (ins brtarget:$offset), !strconcat(opstr, "\t$offset"), 588 [(br bb:$offset)], IIBranch, FrmI> { 589 let isBranch = 1; 590 let isTerminator = 1; 591 let isBarrier = 1; 592 let hasDelaySlot = 1; 593 let Predicates = [RelocPIC, HasStdEnc]; 594 let Defs = [AT]; 595 } 596 597 // Base class for indirect branch and return instruction classes. 598 let isTerminator=1, isBarrier=1, hasDelaySlot = 1 in 599 class JumpFR<RegisterOperand RO, SDPatternOperator operator = null_frag>: 600 InstSE<(outs), (ins RO:$rs), "jr\t$rs", [(operator RO:$rs)], IIBranch, FrmR>; 601 602 // Indirect branch 603 class IndirectBranch<RegisterOperand RO>: JumpFR<RO, brind> { 604 let isBranch = 1; 605 let isIndirectBranch = 1; 606 } 607 608 // Return instruction 609 class RetBase<RegisterOperand RO>: JumpFR<RO> { 610 let isReturn = 1; 611 let isCodeGenOnly = 1; 612 let hasCtrlDep = 1; 613 let hasExtraSrcRegAllocReq = 1; 614 } 615 616 // Jump and Link (Call) 617 let isCall=1, hasDelaySlot=1, Defs = [RA] in { 618 class JumpLink<string opstr> : 619 InstSE<(outs), (ins calltarget:$target), !strconcat(opstr, "\t$target"), 620 [(MipsJmpLink imm:$target)], IIBranch, FrmJ> { 621 let DecoderMethod = "DecodeJumpTarget"; 622 } 623 624 class JumpLinkRegPseudo<RegisterOperand RO, Instruction JALRInst, 625 Register RetReg, RegisterOperand ResRO = RO>: 626 PseudoSE<(outs), (ins RO:$rs), [(MipsJmpLink RO:$rs)], IIBranch>, 627 PseudoInstExpansion<(JALRInst RetReg, ResRO:$rs)>; 628 629 class JumpLinkReg<string opstr, RegisterOperand RO>: 630 InstSE<(outs RO:$rd), (ins RO:$rs), !strconcat(opstr, "\t$rd, $rs"), 631 [], IIBranch, FrmR>; 632 633 class BGEZAL_FT<string opstr, RegisterOperand RO> : 634 InstSE<(outs), (ins RO:$rs, brtarget:$offset), 635 !strconcat(opstr, "\t$rs, $offset"), [], IIBranch, FrmI>; 636 637 } 638 639 class BAL_BR_Pseudo<Instruction RealInst> : 640 PseudoSE<(outs), (ins brtarget:$offset), [], IIBranch>, 641 PseudoInstExpansion<(RealInst ZERO, brtarget:$offset)> { 642 let isBranch = 1; 643 let isTerminator = 1; 644 let isBarrier = 1; 645 let hasDelaySlot = 1; 646 let Defs = [RA]; 647 } 648 649 // Syscall 650 class SYS_FT<string opstr> : 651 InstSE<(outs), (ins uimm20:$code_), 652 !strconcat(opstr, "\t$code_"), [], NoItinerary, FrmI>; 653 // Break 654 class BRK_FT<string opstr> : 655 InstSE<(outs), (ins uimm10:$code_1, uimm10:$code_2), 656 !strconcat(opstr, "\t$code_1, $code_2"), [], NoItinerary, FrmOther>; 657 658 // (D)Eret 659 class ER_FT<string opstr> : 660 InstSE<(outs), (ins), 661 opstr, [], NoItinerary, FrmOther>; 662 663 // Sync 664 let hasSideEffects = 1 in 665 class SYNC_FT : 666 InstSE<(outs), (ins i32imm:$stype), "sync $stype", [(MipsSync imm:$stype)], 667 NoItinerary, FrmOther>; 668 669 let hasSideEffects = 1 in 670 class TEQ_FT<string opstr, RegisterOperand RO> : 671 InstSE<(outs), (ins RO:$rs, RO:$rt, uimm16:$code_), 672 !strconcat(opstr, "\t$rs, $rt, $code_"), [], NoItinerary, FrmI>; 673 674 // Mul, Div 675 class Mult<string opstr, InstrItinClass itin, RegisterOperand RO, 676 list<Register> DefRegs> : 677 InstSE<(outs), (ins RO:$rs, RO:$rt), !strconcat(opstr, "\t$rs, $rt"), [], 678 itin, FrmR, opstr> { 679 let isCommutable = 1; 680 let Defs = DefRegs; 681 let neverHasSideEffects = 1; 682 } 683 684 // Pseudo multiply/divide instruction with explicit accumulator register 685 // operands. 686 class MultDivPseudo<Instruction RealInst, RegisterClass R0, RegisterOperand R1, 687 SDPatternOperator OpNode, InstrItinClass Itin, 688 bit IsComm = 1, bit HasSideEffects = 0, 689 bit UsesCustomInserter = 0> : 690 PseudoSE<(outs R0:$ac), (ins R1:$rs, R1:$rt), 691 [(set R0:$ac, (OpNode R1:$rs, R1:$rt))], Itin>, 692 PseudoInstExpansion<(RealInst R1:$rs, R1:$rt)> { 693 let isCommutable = IsComm; 694 let hasSideEffects = HasSideEffects; 695 let usesCustomInserter = UsesCustomInserter; 696 } 697 698 // Pseudo multiply add/sub instruction with explicit accumulator register 699 // operands. 700 class MAddSubPseudo<Instruction RealInst, SDPatternOperator OpNode> 701 : PseudoSE<(outs ACRegs:$ac), 702 (ins GPR32Opnd:$rs, GPR32Opnd:$rt, ACRegs:$acin), 703 [(set ACRegs:$ac, 704 (OpNode GPR32Opnd:$rs, GPR32Opnd:$rt, ACRegs:$acin))], 705 IIImult>, 706 PseudoInstExpansion<(RealInst GPR32Opnd:$rs, GPR32Opnd:$rt)> { 707 string Constraints = "$acin = $ac"; 708 } 709 710 class Div<string opstr, InstrItinClass itin, RegisterOperand RO, 711 list<Register> DefRegs> : 712 InstSE<(outs), (ins RO:$rs, RO:$rt), !strconcat(opstr, "\t$$zero, $rs, $rt"), 713 [], itin, FrmR> { 714 let Defs = DefRegs; 715 } 716 717 // Move from Hi/Lo 718 class MoveFromLOHI<string opstr, RegisterOperand RO, list<Register> UseRegs>: 719 InstSE<(outs RO:$rd), (ins), !strconcat(opstr, "\t$rd"), [], IIHiLo, FrmR> { 720 let Uses = UseRegs; 721 let neverHasSideEffects = 1; 722 } 723 724 class MoveToLOHI<string opstr, RegisterOperand RO, list<Register> DefRegs>: 725 InstSE<(outs), (ins RO:$rs), !strconcat(opstr, "\t$rs"), [], IIHiLo, FrmR> { 726 let Defs = DefRegs; 727 let neverHasSideEffects = 1; 728 } 729 730 class EffectiveAddress<string opstr, RegisterOperand RO, Operand Mem> : 731 InstSE<(outs RO:$rt), (ins Mem:$addr), !strconcat(opstr, "\t$rt, $addr"), 732 [(set RO:$rt, addr:$addr)], NoItinerary, FrmI> { 733 let isCodeGenOnly = 1; 734 let DecoderMethod = "DecodeMem"; 735 } 736 737 // Count Leading Ones/Zeros in Word 738 class CountLeading0<string opstr, RegisterOperand RO>: 739 InstSE<(outs RO:$rd), (ins RO:$rs), !strconcat(opstr, "\t$rd, $rs"), 740 [(set RO:$rd, (ctlz RO:$rs))], IIArith, FrmR>, 741 Requires<[HasBitCount, HasStdEnc]>; 742 743 class CountLeading1<string opstr, RegisterOperand RO>: 744 InstSE<(outs RO:$rd), (ins RO:$rs), !strconcat(opstr, "\t$rd, $rs"), 745 [(set RO:$rd, (ctlz (not RO:$rs)))], IIArith, FrmR>, 746 Requires<[HasBitCount, HasStdEnc]>; 747 748 749 // Sign Extend in Register. 750 class SignExtInReg<string opstr, ValueType vt, RegisterOperand RO> : 751 InstSE<(outs RO:$rd), (ins RO:$rt), !strconcat(opstr, "\t$rd, $rt"), 752 [(set RO:$rd, (sext_inreg RO:$rt, vt))], IIseb, FrmR> { 753 let Predicates = [HasSEInReg, HasStdEnc]; 754 } 755 756 // Subword Swap 757 class SubwordSwap<string opstr, RegisterOperand RO>: 758 InstSE<(outs RO:$rd), (ins RO:$rt), !strconcat(opstr, "\t$rd, $rt"), [], 759 NoItinerary, FrmR> { 760 let Predicates = [HasSwap, HasStdEnc]; 761 let neverHasSideEffects = 1; 762 } 763 764 // Read Hardware 765 class ReadHardware<RegisterOperand CPURegOperand, RegisterOperand RO> : 766 InstSE<(outs CPURegOperand:$rt), (ins RO:$rd), "rdhwr\t$rt, $rd", [], 767 IIArith, FrmR>; 768 769 // Ext and Ins 770 class ExtBase<string opstr, RegisterOperand RO>: 771 InstSE<(outs RO:$rt), (ins RO:$rs, uimm16:$pos, size_ext:$size), 772 !strconcat(opstr, " $rt, $rs, $pos, $size"), 773 [(set RO:$rt, (MipsExt RO:$rs, imm:$pos, imm:$size))], NoItinerary, 774 FrmR> { 775 let Predicates = [HasMips32r2, HasStdEnc]; 776 } 777 778 class InsBase<string opstr, RegisterOperand RO>: 779 InstSE<(outs RO:$rt), (ins RO:$rs, uimm16:$pos, size_ins:$size, RO:$src), 780 !strconcat(opstr, " $rt, $rs, $pos, $size"), 781 [(set RO:$rt, (MipsIns RO:$rs, imm:$pos, imm:$size, RO:$src))], 782 NoItinerary, FrmR> { 783 let Predicates = [HasMips32r2, HasStdEnc]; 784 let Constraints = "$src = $rt"; 785 } 786 787 // Atomic instructions with 2 source operands (ATOMIC_SWAP & ATOMIC_LOAD_*). 788 class Atomic2Ops<PatFrag Op, RegisterClass DRC, RegisterClass PRC> : 789 PseudoSE<(outs DRC:$dst), (ins PRC:$ptr, DRC:$incr), 790 [(set DRC:$dst, (Op PRC:$ptr, DRC:$incr))]>; 791 792 multiclass Atomic2Ops32<PatFrag Op> { 793 def NAME : Atomic2Ops<Op, GPR32, GPR32>, Requires<[NotN64, HasStdEnc]>; 794 def _P8 : Atomic2Ops<Op, GPR32, GPR64>, Requires<[IsN64, HasStdEnc]>; 795 } 796 797 // Atomic Compare & Swap. 798 class AtomicCmpSwap<PatFrag Op, RegisterClass DRC, RegisterClass PRC> : 799 PseudoSE<(outs DRC:$dst), (ins PRC:$ptr, DRC:$cmp, DRC:$swap), 800 [(set DRC:$dst, (Op PRC:$ptr, DRC:$cmp, DRC:$swap))]>; 801 802 multiclass AtomicCmpSwap32<PatFrag Op> { 803 def NAME : AtomicCmpSwap<Op, GPR32, GPR32>, 804 Requires<[NotN64, HasStdEnc]>; 805 def _P8 : AtomicCmpSwap<Op, GPR32, GPR64>, 806 Requires<[IsN64, HasStdEnc]>; 807 } 808 809 class LLBase<string opstr, RegisterOperand RO, Operand Mem> : 810 InstSE<(outs RO:$rt), (ins Mem:$addr), !strconcat(opstr, "\t$rt, $addr"), 811 [], NoItinerary, FrmI> { 812 let DecoderMethod = "DecodeMem"; 813 let mayLoad = 1; 814 } 815 816 class SCBase<string opstr, RegisterOperand RO, Operand Mem> : 817 InstSE<(outs RO:$dst), (ins RO:$rt, Mem:$addr), 818 !strconcat(opstr, "\t$rt, $addr"), [], NoItinerary, FrmI> { 819 let DecoderMethod = "DecodeMem"; 820 let mayStore = 1; 821 let Constraints = "$rt = $dst"; 822 } 823 824 class MFC3OP<dag outs, dag ins, string asmstr> : 825 InstSE<outs, ins, asmstr, [], NoItinerary, FrmFR>; 826 827 let isBarrier = 1, isTerminator = 1, isCodeGenOnly = 1 in 828 def TRAP : InstSE<(outs), (ins), "break", [(trap)], NoItinerary, FrmOther> { 829 let Inst = 0x0000000d; 830 } 831 832 //===----------------------------------------------------------------------===// 833 // Pseudo instructions 834 //===----------------------------------------------------------------------===// 835 836 // Return RA. 837 let isReturn=1, isTerminator=1, hasDelaySlot=1, isBarrier=1, hasCtrlDep=1 in 838 def RetRA : PseudoSE<(outs), (ins), [(MipsRet)]>; 839 840 let Defs = [SP], Uses = [SP], hasSideEffects = 1 in { 841 def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins i32imm:$amt), 842 [(callseq_start timm:$amt)]>; 843 def ADJCALLSTACKUP : MipsPseudo<(outs), (ins i32imm:$amt1, i32imm:$amt2), 844 [(callseq_end timm:$amt1, timm:$amt2)]>; 845 } 846 847 let usesCustomInserter = 1 in { 848 defm ATOMIC_LOAD_ADD_I8 : Atomic2Ops32<atomic_load_add_8>; 849 defm ATOMIC_LOAD_ADD_I16 : Atomic2Ops32<atomic_load_add_16>; 850 defm ATOMIC_LOAD_ADD_I32 : Atomic2Ops32<atomic_load_add_32>; 851 defm ATOMIC_LOAD_SUB_I8 : Atomic2Ops32<atomic_load_sub_8>; 852 defm ATOMIC_LOAD_SUB_I16 : Atomic2Ops32<atomic_load_sub_16>; 853 defm ATOMIC_LOAD_SUB_I32 : Atomic2Ops32<atomic_load_sub_32>; 854 defm ATOMIC_LOAD_AND_I8 : Atomic2Ops32<atomic_load_and_8>; 855 defm ATOMIC_LOAD_AND_I16 : Atomic2Ops32<atomic_load_and_16>; 856 defm ATOMIC_LOAD_AND_I32 : Atomic2Ops32<atomic_load_and_32>; 857 defm ATOMIC_LOAD_OR_I8 : Atomic2Ops32<atomic_load_or_8>; 858 defm ATOMIC_LOAD_OR_I16 : Atomic2Ops32<atomic_load_or_16>; 859 defm ATOMIC_LOAD_OR_I32 : Atomic2Ops32<atomic_load_or_32>; 860 defm ATOMIC_LOAD_XOR_I8 : Atomic2Ops32<atomic_load_xor_8>; 861 defm ATOMIC_LOAD_XOR_I16 : Atomic2Ops32<atomic_load_xor_16>; 862 defm ATOMIC_LOAD_XOR_I32 : Atomic2Ops32<atomic_load_xor_32>; 863 defm ATOMIC_LOAD_NAND_I8 : Atomic2Ops32<atomic_load_nand_8>; 864 defm ATOMIC_LOAD_NAND_I16 : Atomic2Ops32<atomic_load_nand_16>; 865 defm ATOMIC_LOAD_NAND_I32 : Atomic2Ops32<atomic_load_nand_32>; 866 867 defm ATOMIC_SWAP_I8 : Atomic2Ops32<atomic_swap_8>; 868 defm ATOMIC_SWAP_I16 : Atomic2Ops32<atomic_swap_16>; 869 defm ATOMIC_SWAP_I32 : Atomic2Ops32<atomic_swap_32>; 870 871 defm ATOMIC_CMP_SWAP_I8 : AtomicCmpSwap32<atomic_cmp_swap_8>; 872 defm ATOMIC_CMP_SWAP_I16 : AtomicCmpSwap32<atomic_cmp_swap_16>; 873 defm ATOMIC_CMP_SWAP_I32 : AtomicCmpSwap32<atomic_cmp_swap_32>; 874 } 875 876 /// Pseudo instructions for loading and storing accumulator registers. 877 let isPseudo = 1, isCodeGenOnly = 1 in { 878 defm LOAD_AC64 : LoadM<"", ACRegs>; 879 defm STORE_AC64 : StoreM<"", ACRegs>; 880 } 881 882 //===----------------------------------------------------------------------===// 883 // Instruction definition 884 //===----------------------------------------------------------------------===// 885 //===----------------------------------------------------------------------===// 886 // MipsI Instructions 887 //===----------------------------------------------------------------------===// 888 889 /// Arithmetic Instructions (ALU Immediate) 890 def ADDiu : MMRel, ArithLogicI<"addiu", simm16, GPR32Opnd, IIArith, immSExt16, 891 add>, 892 ADDI_FM<0x9>, IsAsCheapAsAMove; 893 def ADDi : MMRel, ArithLogicI<"addi", simm16, GPR32Opnd>, ADDI_FM<0x8>; 894 def SLTi : MMRel, SetCC_I<"slti", setlt, simm16, immSExt16, GPR32Opnd>, 895 SLTI_FM<0xa>; 896 def SLTiu : MMRel, SetCC_I<"sltiu", setult, simm16, immSExt16, GPR32Opnd>, 897 SLTI_FM<0xb>; 898 def ANDi : MMRel, ArithLogicI<"andi", uimm16, GPR32Opnd, IILogic, immZExt16, 899 and>, 900 ADDI_FM<0xc>; 901 def ORi : MMRel, ArithLogicI<"ori", uimm16, GPR32Opnd, IILogic, immZExt16, 902 or>, 903 ADDI_FM<0xd>; 904 def XORi : MMRel, ArithLogicI<"xori", uimm16, GPR32Opnd, IILogic, immZExt16, 905 xor>, 906 ADDI_FM<0xe>; 907 def LUi : MMRel, LoadUpper<"lui", GPR32Opnd, uimm16>, LUI_FM; 908 909 /// Arithmetic Instructions (3-Operand, R-Type) 910 def ADDu : MMRel, ArithLogicR<"addu", GPR32Opnd, 1, IIArith, add>, 911 ADD_FM<0, 0x21>; 912 def SUBu : MMRel, ArithLogicR<"subu", GPR32Opnd, 0, IIArith, sub>, 913 ADD_FM<0, 0x23>; 914 def MUL : MMRel, ArithLogicR<"mul", GPR32Opnd, 1, IIImul, mul>, 915 ADD_FM<0x1c, 2>; 916 def ADD : MMRel, ArithLogicR<"add", GPR32Opnd>, ADD_FM<0, 0x20>; 917 def SUB : MMRel, ArithLogicR<"sub", GPR32Opnd>, ADD_FM<0, 0x22>; 918 def SLT : MMRel, SetCC_R<"slt", setlt, GPR32Opnd>, ADD_FM<0, 0x2a>; 919 def SLTu : MMRel, SetCC_R<"sltu", setult, GPR32Opnd>, ADD_FM<0, 0x2b>; 920 def AND : MMRel, ArithLogicR<"and", GPR32Opnd, 1, IILogic, and>, 921 ADD_FM<0, 0x24>; 922 def OR : MMRel, ArithLogicR<"or", GPR32Opnd, 1, IILogic, or>, 923 ADD_FM<0, 0x25>; 924 def XOR : MMRel, ArithLogicR<"xor", GPR32Opnd, 1, IILogic, xor>, 925 ADD_FM<0, 0x26>; 926 def NOR : MMRel, LogicNOR<"nor", GPR32Opnd>, ADD_FM<0, 0x27>; 927 928 /// Shift Instructions 929 def SLL : MMRel, shift_rotate_imm<"sll", shamt, GPR32Opnd, shl, immZExt5>, 930 SRA_FM<0, 0>; 931 def SRL : MMRel, shift_rotate_imm<"srl", shamt, GPR32Opnd, srl, immZExt5>, 932 SRA_FM<2, 0>; 933 def SRA : MMRel, shift_rotate_imm<"sra", shamt, GPR32Opnd, sra, immZExt5>, 934 SRA_FM<3, 0>; 935 def SLLV : MMRel, shift_rotate_reg<"sllv", GPR32Opnd, shl>, SRLV_FM<4, 0>; 936 def SRLV : MMRel, shift_rotate_reg<"srlv", GPR32Opnd, srl>, SRLV_FM<6, 0>; 937 def SRAV : MMRel, shift_rotate_reg<"srav", GPR32Opnd, sra>, SRLV_FM<7, 0>; 938 939 // Rotate Instructions 940 let Predicates = [HasMips32r2, HasStdEnc] in { 941 def ROTR : MMRel, shift_rotate_imm<"rotr", shamt, GPR32Opnd, rotr, 942 immZExt5>, 943 SRA_FM<2, 1>; 944 def ROTRV : MMRel, shift_rotate_reg<"rotrv", GPR32Opnd, rotr>, 945 SRLV_FM<6, 1>; 946 } 947 948 /// Load and Store Instructions 949 /// aligned 950 defm LB : LoadM<"lb", GPR32Opnd, sextloadi8, IILoad>, MMRel, LW_FM<0x20>; 951 defm LBu : LoadM<"lbu", GPR32Opnd, zextloadi8, IILoad, addrDefault>, MMRel, 952 LW_FM<0x24>; 953 defm LH : LoadM<"lh", GPR32Opnd, sextloadi16, IILoad, addrDefault>, MMRel, 954 LW_FM<0x21>; 955 defm LHu : LoadM<"lhu", GPR32Opnd, zextloadi16, IILoad>, MMRel, LW_FM<0x25>; 956 defm LW : LoadM<"lw", GPR32Opnd, load, IILoad, addrDefault>, MMRel, LW_FM<0x23>; 957 defm SB : StoreM<"sb", GPR32Opnd, truncstorei8, IIStore>, MMRel, LW_FM<0x28>; 958 defm SH : StoreM<"sh", GPR32Opnd, truncstorei16, IIStore>, MMRel, LW_FM<0x29>; 959 defm SW : StoreM<"sw", GPR32Opnd, store, IIStore>, MMRel, LW_FM<0x2b>; 960 961 /// load/store left/right 962 defm LWL : LoadLeftRightM<"lwl", MipsLWL, GPR32Opnd>, LW_FM<0x22>; 963 defm LWR : LoadLeftRightM<"lwr", MipsLWR, GPR32Opnd>, LW_FM<0x26>; 964 defm SWL : StoreLeftRightM<"swl", MipsSWL, GPR32Opnd>, LW_FM<0x2a>; 965 defm SWR : StoreLeftRightM<"swr", MipsSWR, GPR32Opnd>, LW_FM<0x2e>; 966 967 def SYNC : SYNC_FT, SYNC_FM; 968 def TEQ : TEQ_FT<"teq", GPR32Opnd>, TEQ_FM<0x34>; 969 970 def BREAK : BRK_FT<"break">, BRK_FM<0xd>; 971 def SYSCALL : SYS_FT<"syscall">, SYS_FM<0xc>; 972 973 def ERET : ER_FT<"eret">, ER_FM<0x18>; 974 def DERET : ER_FT<"deret">, ER_FM<0x1f>; 975 976 /// Load-linked, Store-conditional 977 let Predicates = [NotN64, HasStdEnc] in { 978 def LL : LLBase<"ll", GPR32Opnd, mem>, LW_FM<0x30>; 979 def SC : SCBase<"sc", GPR32Opnd, mem>, LW_FM<0x38>; 980 } 981 982 let Predicates = [IsN64, HasStdEnc], DecoderNamespace = "Mips64" in { 983 def LL_P8 : LLBase<"ll", GPR32Opnd, mem64>, LW_FM<0x30>; 984 def SC_P8 : SCBase<"sc", GPR32Opnd, mem64>, LW_FM<0x38>; 985 } 986 987 /// Jump and Branch Instructions 988 def J : JumpFJ<jmptarget, "j", br, bb>, FJ<2>, 989 Requires<[RelocStatic, HasStdEnc]>, IsBranch; 990 def JR : IndirectBranch<GPR32Opnd>, MTLO_FM<8>; 991 def B : UncondBranch<"b">, B_FM; 992 def BEQ : CBranch<"beq", seteq, GPR32Opnd>, BEQ_FM<4>; 993 def BNE : CBranch<"bne", setne, GPR32Opnd>, BEQ_FM<5>; 994 def BGEZ : CBranchZero<"bgez", setge, GPR32Opnd>, BGEZ_FM<1, 1>; 995 def BGTZ : CBranchZero<"bgtz", setgt, GPR32Opnd>, BGEZ_FM<7, 0>; 996 def BLEZ : CBranchZero<"blez", setle, GPR32Opnd>, BGEZ_FM<6, 0>; 997 def BLTZ : CBranchZero<"bltz", setlt, GPR32Opnd>, BGEZ_FM<1, 0>; 998 999 def JAL : JumpLink<"jal">, FJ<3>; 1000 def JALR : JumpLinkReg<"jalr", GPR32Opnd>, JALR_FM; 1001 def JALRPseudo : JumpLinkRegPseudo<GPR32Opnd, JALR, RA>; 1002 def BGEZAL : BGEZAL_FT<"bgezal", GPR32Opnd>, BGEZAL_FM<0x11>; 1003 def BLTZAL : BGEZAL_FT<"bltzal", GPR32Opnd>, BGEZAL_FM<0x10>; 1004 def BAL_BR : BAL_BR_Pseudo<BGEZAL>; 1005 def TAILCALL : JumpFJ<calltarget, "j", MipsTailCall, imm>, FJ<2>, IsTailCall; 1006 def TAILCALL_R : JumpFR<GPR32Opnd, MipsTailCall>, MTLO_FM<8>, IsTailCall; 1007 1008 def RET : RetBase<GPR32Opnd>, MTLO_FM<8>; 1009 1010 // Exception handling related node and instructions. 1011 // The conversion sequence is: 1012 // ISD::EH_RETURN -> MipsISD::EH_RETURN -> 1013 // MIPSeh_return -> (stack change + indirect branch) 1014 // 1015 // MIPSeh_return takes the place of regular return instruction 1016 // but takes two arguments (V1, V0) which are used for storing 1017 // the offset and return address respectively. 1018 def SDT_MipsEHRET : SDTypeProfile<0, 2, [SDTCisInt<0>, SDTCisPtrTy<1>]>; 1019 1020 def MIPSehret : SDNode<"MipsISD::EH_RETURN", SDT_MipsEHRET, 1021 [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>; 1022 1023 let Uses = [V0, V1], isTerminator = 1, isReturn = 1, isBarrier = 1 in { 1024 def MIPSeh_return32 : MipsPseudo<(outs), (ins GPR32:$spoff, GPR32:$dst), 1025 [(MIPSehret GPR32:$spoff, GPR32:$dst)]>; 1026 def MIPSeh_return64 : MipsPseudo<(outs), (ins GPR64:$spoff, 1027 GPR64:$dst), 1028 [(MIPSehret GPR64:$spoff, GPR64:$dst)]>; 1029 } 1030 1031 /// Multiply and Divide Instructions. 1032 def MULT : MMRel, Mult<"mult", IIImult, GPR32Opnd, [HI, LO]>, 1033 MULT_FM<0, 0x18>; 1034 def MULTu : MMRel, Mult<"multu", IIImult, GPR32Opnd, [HI, LO]>, 1035 MULT_FM<0, 0x19>; 1036 def PseudoMULT : MultDivPseudo<MULT, ACRegs, GPR32Opnd, MipsMult, IIImult>; 1037 def PseudoMULTu : MultDivPseudo<MULTu, ACRegs, GPR32Opnd, MipsMultu, IIImult>; 1038 def SDIV : Div<"div", IIIdiv, GPR32Opnd, [HI, LO]>, MULT_FM<0, 0x1a>; 1039 def UDIV : Div<"divu", IIIdiv, GPR32Opnd, [HI, LO]>, MULT_FM<0, 0x1b>; 1040 def PseudoSDIV : MultDivPseudo<SDIV, ACRegs, GPR32Opnd, MipsDivRem, IIIdiv, 1041 0, 1, 1>; 1042 def PseudoUDIV : MultDivPseudo<UDIV, ACRegs, GPR32Opnd, MipsDivRemU, IIIdiv, 1043 0, 1, 1>; 1044 1045 def MTHI : MoveToLOHI<"mthi", GPR32Opnd, [HI]>, MTLO_FM<0x11>; 1046 def MTLO : MoveToLOHI<"mtlo", GPR32Opnd, [LO]>, MTLO_FM<0x13>; 1047 def MFHI : MoveFromLOHI<"mfhi", GPR32Opnd, [HI]>, MFLO_FM<0x10>; 1048 def MFLO : MoveFromLOHI<"mflo", GPR32Opnd, [LO]>, MFLO_FM<0x12>; 1049 1050 /// Sign Ext In Register Instructions. 1051 def SEB : SignExtInReg<"seb", i8, GPR32Opnd>, SEB_FM<0x10, 0x20>; 1052 def SEH : SignExtInReg<"seh", i16, GPR32Opnd>, SEB_FM<0x18, 0x20>; 1053 1054 /// Count Leading 1055 def CLZ : CountLeading0<"clz", GPR32Opnd>, CLO_FM<0x20>; 1056 def CLO : CountLeading1<"clo", GPR32Opnd>, CLO_FM<0x21>; 1057 1058 /// Word Swap Bytes Within Halfwords 1059 def WSBH : SubwordSwap<"wsbh", GPR32Opnd>, SEB_FM<2, 0x20>; 1060 1061 /// No operation. 1062 def NOP : PseudoSE<(outs), (ins), []>, PseudoInstExpansion<(SLL ZERO, ZERO, 0)>; 1063 1064 // FrameIndexes are legalized when they are operands from load/store 1065 // instructions. The same not happens for stack address copies, so an 1066 // add op with mem ComplexPattern is used and the stack address copy 1067 // can be matched. It's similar to Sparc LEA_ADDRi 1068 def LEA_ADDiu : EffectiveAddress<"addiu", GPR32Opnd, mem_ea>, LW_FM<9>; 1069 1070 // MADD*/MSUB* 1071 def MADD : MArithR<"madd", 1>, MULT_FM<0x1c, 0>; 1072 def MADDU : MArithR<"maddu", 1>, MULT_FM<0x1c, 1>; 1073 def MSUB : MArithR<"msub">, MULT_FM<0x1c, 4>; 1074 def MSUBU : MArithR<"msubu">, MULT_FM<0x1c, 5>; 1075 def PseudoMADD : MAddSubPseudo<MADD, MipsMAdd>; 1076 def PseudoMADDU : MAddSubPseudo<MADDU, MipsMAddu>; 1077 def PseudoMSUB : MAddSubPseudo<MSUB, MipsMSub>; 1078 def PseudoMSUBU : MAddSubPseudo<MSUBU, MipsMSubu>; 1079 1080 def RDHWR : ReadHardware<GPR32Opnd, HWRegsOpnd>, RDHWR_FM; 1081 1082 def EXT : ExtBase<"ext", GPR32Opnd>, EXT_FM<0>; 1083 def INS : InsBase<"ins", GPR32Opnd>, EXT_FM<4>; 1084 1085 /// Move Control Registers From/To CPU Registers 1086 def MFC0_3OP : MFC3OP<(outs GPR32Opnd:$rt), 1087 (ins GPR32Opnd:$rd, uimm16:$sel), 1088 "mfc0\t$rt, $rd, $sel">, MFC3OP_FM<0x10, 0>; 1089 1090 def MTC0_3OP : MFC3OP<(outs GPR32Opnd:$rd, uimm16:$sel), 1091 (ins GPR32Opnd:$rt), 1092 "mtc0\t$rt, $rd, $sel">, MFC3OP_FM<0x10, 4>; 1093 1094 def MFC2_3OP : MFC3OP<(outs GPR32Opnd:$rt), 1095 (ins GPR32Opnd:$rd, uimm16:$sel), 1096 "mfc2\t$rt, $rd, $sel">, MFC3OP_FM<0x12, 0>; 1097 1098 def MTC2_3OP : MFC3OP<(outs GPR32Opnd:$rd, uimm16:$sel), 1099 (ins GPR32Opnd:$rt), 1100 "mtc2\t$rt, $rd, $sel">, MFC3OP_FM<0x12, 4>; 1101 1102 //===----------------------------------------------------------------------===// 1103 // Instruction aliases 1104 //===----------------------------------------------------------------------===// 1105 def : InstAlias<"move $dst, $src", 1106 (ADDu GPR32Opnd:$dst, GPR32Opnd:$src,ZERO), 1>, 1107 Requires<[NotMips64]>; 1108 def : InstAlias<"bal $offset", (BGEZAL ZERO, brtarget:$offset), 0>; 1109 def : InstAlias<"addu $rs, $rt, $imm", 1110 (ADDiu GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm), 0>; 1111 def : InstAlias<"add $rs, $rt, $imm", 1112 (ADDi GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm), 0>; 1113 def : InstAlias<"and $rs, $rt, $imm", 1114 (ANDi GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm), 0>; 1115 def : InstAlias<"j $rs", (JR GPR32Opnd:$rs), 0>; 1116 def : InstAlias<"jalr $rs", (JALR RA, GPR32Opnd:$rs), 0>; 1117 def : InstAlias<"jal $rs", (JALR RA, GPR32Opnd:$rs), 0>; 1118 def : InstAlias<"jal $rd,$rs", (JALR GPR32Opnd:$rd, GPR32Opnd:$rs), 0>; 1119 def : InstAlias<"not $rt, $rs", 1120 (NOR GPR32Opnd:$rt, GPR32Opnd:$rs, ZERO), 0>; 1121 def : InstAlias<"neg $rt, $rs", 1122 (SUB GPR32Opnd:$rt, ZERO, GPR32Opnd:$rs), 1>; 1123 def : InstAlias<"negu $rt, $rs", 1124 (SUBu GPR32Opnd:$rt, ZERO, GPR32Opnd:$rs), 1>; 1125 def : InstAlias<"slt $rs, $rt, $imm", 1126 (SLTi GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm), 0>; 1127 def : InstAlias<"xor $rs, $rt, $imm", 1128 (XORi GPR32Opnd:$rs, GPR32Opnd:$rt, uimm16:$imm), 0>; 1129 def : InstAlias<"or $rs, $rt, $imm", 1130 (ORi GPR32Opnd:$rs, GPR32Opnd:$rt, uimm16:$imm), 0>; 1131 def : InstAlias<"nop", (SLL ZERO, ZERO, 0), 1>; 1132 def : InstAlias<"mfc0 $rt, $rd", 1133 (MFC0_3OP GPR32Opnd:$rt, GPR32Opnd:$rd, 0), 0>; 1134 def : InstAlias<"mtc0 $rt, $rd", 1135 (MTC0_3OP GPR32Opnd:$rd, 0, GPR32Opnd:$rt), 0>; 1136 def : InstAlias<"mfc2 $rt, $rd", 1137 (MFC2_3OP GPR32Opnd:$rt, GPR32Opnd:$rd, 0), 0>; 1138 def : InstAlias<"mtc2 $rt, $rd", 1139 (MTC2_3OP GPR32Opnd:$rd, 0, GPR32Opnd:$rt), 0>; 1140 def : InstAlias<"bnez $rs,$offset", 1141 (BNE GPR32Opnd:$rs, ZERO, brtarget:$offset), 0>; 1142 def : InstAlias<"beqz $rs,$offset", 1143 (BEQ GPR32Opnd:$rs, ZERO, brtarget:$offset), 0>; 1144 def : InstAlias<"syscall", (SYSCALL 0), 1>; 1145 1146 def : InstAlias<"break $imm", (BREAK uimm10:$imm, 0), 1>; 1147 def : InstAlias<"break", (BREAK 0, 0), 1>; 1148 //===----------------------------------------------------------------------===// 1149 // Assembler Pseudo Instructions 1150 //===----------------------------------------------------------------------===// 1151 1152 class LoadImm32< string instr_asm, Operand Od, RegisterOperand RO> : 1153 MipsAsmPseudoInst<(outs RO:$rt), (ins Od:$imm32), 1154 !strconcat(instr_asm, "\t$rt, $imm32")> ; 1155 def LoadImm32Reg : LoadImm32<"li", shamt,GPR32Opnd>; 1156 1157 class LoadAddress<string instr_asm, Operand MemOpnd, RegisterOperand RO> : 1158 MipsAsmPseudoInst<(outs RO:$rt), (ins MemOpnd:$addr), 1159 !strconcat(instr_asm, "\t$rt, $addr")> ; 1160 def LoadAddr32Reg : LoadAddress<"la", mem, GPR32Opnd>; 1161 1162 class LoadAddressImm<string instr_asm, Operand Od, RegisterOperand RO> : 1163 MipsAsmPseudoInst<(outs RO:$rt), (ins Od:$imm32), 1164 !strconcat(instr_asm, "\t$rt, $imm32")> ; 1165 def LoadAddr32Imm : LoadAddressImm<"la", shamt,GPR32Opnd>; 1166 1167 1168 1169 //===----------------------------------------------------------------------===// 1170 // Arbitrary patterns that map to one or more instructions 1171 //===----------------------------------------------------------------------===// 1172 1173 // Load/store pattern templates. 1174 class LoadRegImmPat<Instruction LoadInst, ValueType ValTy, PatFrag Node> : 1175 MipsPat<(ValTy (Node addrRegImm:$a)), (LoadInst addrRegImm:$a)>; 1176 1177 class StoreRegImmPat<Instruction StoreInst, ValueType ValTy> : 1178 MipsPat<(store ValTy:$v, addrRegImm:$a), (StoreInst ValTy:$v, addrRegImm:$a)>; 1179 1180 // Small immediates 1181 def : MipsPat<(i32 immSExt16:$in), 1182 (ADDiu ZERO, imm:$in)>; 1183 def : MipsPat<(i32 immZExt16:$in), 1184 (ORi ZERO, imm:$in)>; 1185 def : MipsPat<(i32 immLow16Zero:$in), 1186 (LUi (HI16 imm:$in))>; 1187 1188 // Arbitrary immediates 1189 def : MipsPat<(i32 imm:$imm), 1190 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>; 1191 1192 // Carry MipsPatterns 1193 def : MipsPat<(subc GPR32:$lhs, GPR32:$rhs), 1194 (SUBu GPR32:$lhs, GPR32:$rhs)>; 1195 let Predicates = [HasStdEnc, NotDSP] in { 1196 def : MipsPat<(addc GPR32:$lhs, GPR32:$rhs), 1197 (ADDu GPR32:$lhs, GPR32:$rhs)>; 1198 def : MipsPat<(addc GPR32:$src, immSExt16:$imm), 1199 (ADDiu GPR32:$src, imm:$imm)>; 1200 } 1201 1202 // Call 1203 def : MipsPat<(MipsJmpLink (i32 tglobaladdr:$dst)), 1204 (JAL tglobaladdr:$dst)>; 1205 def : MipsPat<(MipsJmpLink (i32 texternalsym:$dst)), 1206 (JAL texternalsym:$dst)>; 1207 //def : MipsPat<(MipsJmpLink GPR32:$dst), 1208 // (JALR GPR32:$dst)>; 1209 1210 // Tail call 1211 def : MipsPat<(MipsTailCall (iPTR tglobaladdr:$dst)), 1212 (TAILCALL tglobaladdr:$dst)>; 1213 def : MipsPat<(MipsTailCall (iPTR texternalsym:$dst)), 1214 (TAILCALL texternalsym:$dst)>; 1215 // hi/lo relocs 1216 def : MipsPat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>; 1217 def : MipsPat<(MipsHi tblockaddress:$in), (LUi tblockaddress:$in)>; 1218 def : MipsPat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>; 1219 def : MipsPat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>; 1220 def : MipsPat<(MipsHi tglobaltlsaddr:$in), (LUi tglobaltlsaddr:$in)>; 1221 def : MipsPat<(MipsHi texternalsym:$in), (LUi texternalsym:$in)>; 1222 1223 def : MipsPat<(MipsLo tglobaladdr:$in), (ADDiu ZERO, tglobaladdr:$in)>; 1224 def : MipsPat<(MipsLo tblockaddress:$in), (ADDiu ZERO, tblockaddress:$in)>; 1225 def : MipsPat<(MipsLo tjumptable:$in), (ADDiu ZERO, tjumptable:$in)>; 1226 def : MipsPat<(MipsLo tconstpool:$in), (ADDiu ZERO, tconstpool:$in)>; 1227 def : MipsPat<(MipsLo tglobaltlsaddr:$in), (ADDiu ZERO, tglobaltlsaddr:$in)>; 1228 def : MipsPat<(MipsLo texternalsym:$in), (ADDiu ZERO, texternalsym:$in)>; 1229 1230 def : MipsPat<(add GPR32:$hi, (MipsLo tglobaladdr:$lo)), 1231 (ADDiu GPR32:$hi, tglobaladdr:$lo)>; 1232 def : MipsPat<(add GPR32:$hi, (MipsLo tblockaddress:$lo)), 1233 (ADDiu GPR32:$hi, tblockaddress:$lo)>; 1234 def : MipsPat<(add GPR32:$hi, (MipsLo tjumptable:$lo)), 1235 (ADDiu GPR32:$hi, tjumptable:$lo)>; 1236 def : MipsPat<(add GPR32:$hi, (MipsLo tconstpool:$lo)), 1237 (ADDiu GPR32:$hi, tconstpool:$lo)>; 1238 def : MipsPat<(add GPR32:$hi, (MipsLo tglobaltlsaddr:$lo)), 1239 (ADDiu GPR32:$hi, tglobaltlsaddr:$lo)>; 1240 1241 // gp_rel relocs 1242 def : MipsPat<(add GPR32:$gp, (MipsGPRel tglobaladdr:$in)), 1243 (ADDiu GPR32:$gp, tglobaladdr:$in)>; 1244 def : MipsPat<(add GPR32:$gp, (MipsGPRel tconstpool:$in)), 1245 (ADDiu GPR32:$gp, tconstpool:$in)>; 1246 1247 // wrapper_pic 1248 class WrapperPat<SDNode node, Instruction ADDiuOp, RegisterClass RC>: 1249 MipsPat<(MipsWrapper RC:$gp, node:$in), 1250 (ADDiuOp RC:$gp, node:$in)>; 1251 1252 def : WrapperPat<tglobaladdr, ADDiu, GPR32>; 1253 def : WrapperPat<tconstpool, ADDiu, GPR32>; 1254 def : WrapperPat<texternalsym, ADDiu, GPR32>; 1255 def : WrapperPat<tblockaddress, ADDiu, GPR32>; 1256 def : WrapperPat<tjumptable, ADDiu, GPR32>; 1257 def : WrapperPat<tglobaltlsaddr, ADDiu, GPR32>; 1258 1259 // Mips does not have "not", so we expand our way 1260 def : MipsPat<(not GPR32:$in), 1261 (NOR GPR32Opnd:$in, ZERO)>; 1262 1263 // extended loads 1264 let Predicates = [NotN64, HasStdEnc] in { 1265 def : MipsPat<(i32 (extloadi1 addr:$src)), (LBu addr:$src)>; 1266 def : MipsPat<(i32 (extloadi8 addr:$src)), (LBu addr:$src)>; 1267 def : MipsPat<(i32 (extloadi16 addr:$src)), (LHu addr:$src)>; 1268 } 1269 let Predicates = [IsN64, HasStdEnc] in { 1270 def : MipsPat<(i32 (extloadi1 addr:$src)), (LBu_P8 addr:$src)>; 1271 def : MipsPat<(i32 (extloadi8 addr:$src)), (LBu_P8 addr:$src)>; 1272 def : MipsPat<(i32 (extloadi16 addr:$src)), (LHu_P8 addr:$src)>; 1273 } 1274 1275 // peepholes 1276 let Predicates = [NotN64, HasStdEnc] in { 1277 def : MipsPat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>; 1278 } 1279 let Predicates = [IsN64, HasStdEnc] in { 1280 def : MipsPat<(store (i32 0), addr:$dst), (SW_P8 ZERO, addr:$dst)>; 1281 } 1282 1283 // brcond patterns 1284 multiclass BrcondPats<RegisterClass RC, Instruction BEQOp, Instruction BNEOp, 1285 Instruction SLTOp, Instruction SLTuOp, Instruction SLTiOp, 1286 Instruction SLTiuOp, Register ZEROReg> { 1287 def : MipsPat<(brcond (i32 (setne RC:$lhs, 0)), bb:$dst), 1288 (BNEOp RC:$lhs, ZEROReg, bb:$dst)>; 1289 def : MipsPat<(brcond (i32 (seteq RC:$lhs, 0)), bb:$dst), 1290 (BEQOp RC:$lhs, ZEROReg, bb:$dst)>; 1291 1292 def : MipsPat<(brcond (i32 (setge RC:$lhs, RC:$rhs)), bb:$dst), 1293 (BEQ (SLTOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>; 1294 def : MipsPat<(brcond (i32 (setuge RC:$lhs, RC:$rhs)), bb:$dst), 1295 (BEQ (SLTuOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>; 1296 def : MipsPat<(brcond (i32 (setge RC:$lhs, immSExt16:$rhs)), bb:$dst), 1297 (BEQ (SLTiOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>; 1298 def : MipsPat<(brcond (i32 (setuge RC:$lhs, immSExt16:$rhs)), bb:$dst), 1299 (BEQ (SLTiuOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>; 1300 def : MipsPat<(brcond (i32 (setgt RC:$lhs, immSExt16Plus1:$rhs)), bb:$dst), 1301 (BEQ (SLTiOp RC:$lhs, (Plus1 imm:$rhs)), ZERO, bb:$dst)>; 1302 def : MipsPat<(brcond (i32 (setugt RC:$lhs, immSExt16Plus1:$rhs)), bb:$dst), 1303 (BEQ (SLTiuOp RC:$lhs, (Plus1 imm:$rhs)), ZERO, bb:$dst)>; 1304 1305 def : MipsPat<(brcond (i32 (setle RC:$lhs, RC:$rhs)), bb:$dst), 1306 (BEQ (SLTOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>; 1307 def : MipsPat<(brcond (i32 (setule RC:$lhs, RC:$rhs)), bb:$dst), 1308 (BEQ (SLTuOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>; 1309 1310 def : MipsPat<(brcond RC:$cond, bb:$dst), 1311 (BNEOp RC:$cond, ZEROReg, bb:$dst)>; 1312 } 1313 1314 defm : BrcondPats<GPR32, BEQ, BNE, SLT, SLTu, SLTi, SLTiu, ZERO>; 1315 1316 def : MipsPat<(brcond (i32 (setlt i32:$lhs, 1)), bb:$dst), 1317 (BLEZ i32:$lhs, bb:$dst)>; 1318 def : MipsPat<(brcond (i32 (setgt i32:$lhs, -1)), bb:$dst), 1319 (BGEZ i32:$lhs, bb:$dst)>; 1320 1321 // setcc patterns 1322 multiclass SeteqPats<RegisterClass RC, Instruction SLTiuOp, Instruction XOROp, 1323 Instruction SLTuOp, Register ZEROReg> { 1324 def : MipsPat<(seteq RC:$lhs, 0), 1325 (SLTiuOp RC:$lhs, 1)>; 1326 def : MipsPat<(setne RC:$lhs, 0), 1327 (SLTuOp ZEROReg, RC:$lhs)>; 1328 def : MipsPat<(seteq RC:$lhs, RC:$rhs), 1329 (SLTiuOp (XOROp RC:$lhs, RC:$rhs), 1)>; 1330 def : MipsPat<(setne RC:$lhs, RC:$rhs), 1331 (SLTuOp ZEROReg, (XOROp RC:$lhs, RC:$rhs))>; 1332 } 1333 1334 multiclass SetlePats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> { 1335 def : MipsPat<(setle RC:$lhs, RC:$rhs), 1336 (XORi (SLTOp RC:$rhs, RC:$lhs), 1)>; 1337 def : MipsPat<(setule RC:$lhs, RC:$rhs), 1338 (XORi (SLTuOp RC:$rhs, RC:$lhs), 1)>; 1339 } 1340 1341 multiclass SetgtPats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> { 1342 def : MipsPat<(setgt RC:$lhs, RC:$rhs), 1343 (SLTOp RC:$rhs, RC:$lhs)>; 1344 def : MipsPat<(setugt RC:$lhs, RC:$rhs), 1345 (SLTuOp RC:$rhs, RC:$lhs)>; 1346 } 1347 1348 multiclass SetgePats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> { 1349 def : MipsPat<(setge RC:$lhs, RC:$rhs), 1350 (XORi (SLTOp RC:$lhs, RC:$rhs), 1)>; 1351 def : MipsPat<(setuge RC:$lhs, RC:$rhs), 1352 (XORi (SLTuOp RC:$lhs, RC:$rhs), 1)>; 1353 } 1354 1355 multiclass SetgeImmPats<RegisterClass RC, Instruction SLTiOp, 1356 Instruction SLTiuOp> { 1357 def : MipsPat<(setge RC:$lhs, immSExt16:$rhs), 1358 (XORi (SLTiOp RC:$lhs, immSExt16:$rhs), 1)>; 1359 def : MipsPat<(setuge RC:$lhs, immSExt16:$rhs), 1360 (XORi (SLTiuOp RC:$lhs, immSExt16:$rhs), 1)>; 1361 } 1362 1363 defm : SeteqPats<GPR32, SLTiu, XOR, SLTu, ZERO>; 1364 defm : SetlePats<GPR32, SLT, SLTu>; 1365 defm : SetgtPats<GPR32, SLT, SLTu>; 1366 defm : SetgePats<GPR32, SLT, SLTu>; 1367 defm : SetgeImmPats<GPR32, SLTi, SLTiu>; 1368 1369 // bswap pattern 1370 def : MipsPat<(bswap GPR32:$rt), (ROTR (WSBH GPR32:$rt), 16)>; 1371 1372 // mflo/hi patterns. 1373 def : MipsPat<(i32 (ExtractLOHI ACRegs:$ac, imm:$lohi_idx)), 1374 (EXTRACT_SUBREG ACRegs:$ac, imm:$lohi_idx)>; 1375 1376 // Load halfword/word patterns. 1377 let AddedComplexity = 40 in { 1378 let Predicates = [NotN64, HasStdEnc] in { 1379 def : LoadRegImmPat<LBu, i32, zextloadi8>; 1380 def : LoadRegImmPat<LH, i32, sextloadi16>; 1381 def : LoadRegImmPat<LW, i32, load>; 1382 } 1383 let Predicates = [IsN64, HasStdEnc] in { 1384 def : LoadRegImmPat<LBu_P8, i32, zextloadi8>; 1385 def : LoadRegImmPat<LH_P8, i32, sextloadi16>; 1386 def : LoadRegImmPat<LW_P8, i32, load>; 1387 } 1388 } 1389 1390 //===----------------------------------------------------------------------===// 1391 // Floating Point Support 1392 //===----------------------------------------------------------------------===// 1393 1394 include "MipsInstrFPU.td" 1395 include "Mips64InstrInfo.td" 1396 include "MipsCondMov.td" 1397 1398 // 1399 // Mips16 1400 1401 include "Mips16InstrFormats.td" 1402 include "Mips16InstrInfo.td" 1403 1404 // DSP 1405 include "MipsDSPInstrFormats.td" 1406 include "MipsDSPInstrInfo.td" 1407 1408 // Micromips 1409 include "MicroMipsInstrFormats.td" 1410 include "MicroMipsInstrInfo.td" 1411