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