1 //===- MipsInstrInfo.td - Target Description for Mips Target -*- tablegen -*-=//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the Mips implementation of the TargetInstrInfo class.
12 //===----------------------------------------------------------------------===//
15 //===----------------------------------------------------------------------===//
16 // Mips profiles and nodes
17 //===----------------------------------------------------------------------===//
19 def SDT_MipsJmpLink : SDTypeProfile<0, 1, [SDTCisVT<0, iPTR>]>;
20 def SDT_MipsCMov : SDTypeProfile<1, 4, [SDTCisSameAs<0, 1>,
24 def SDT_MipsCallSeqStart : SDCallSeqStart<[SDTCisVT<0, i32>]>;
25 def SDT_MipsCallSeqEnd : SDCallSeqEnd<[SDTCisVT<0, i32>, SDTCisVT<1, i32>]>;
26 def SDT_MFLOHI : SDTypeProfile<1, 1, [SDTCisInt<0>, SDTCisVT<1, untyped>]>;
27 def SDT_MTLOHI : SDTypeProfile<1, 2, [SDTCisVT<0, untyped>,
28 SDTCisInt<1>, SDTCisSameAs<1, 2>]>;
29 def SDT_MipsMultDiv : SDTypeProfile<1, 2, [SDTCisVT<0, untyped>, SDTCisInt<1>,
31 def SDT_MipsMAddMSub : SDTypeProfile<1, 3,
32 [SDTCisVT<0, untyped>, SDTCisSameAs<0, 3>,
33 SDTCisVT<1, i32>, SDTCisSameAs<1, 2>]>;
34 def SDT_MipsDivRem16 : SDTypeProfile<0, 2, [SDTCisInt<0>, SDTCisSameAs<0, 1>]>;
36 def SDT_MipsThreadPointer : SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>;
38 def SDT_Sync : SDTypeProfile<0, 1, [SDTCisVT<0, i32>]>;
40 def SDT_Ext : SDTypeProfile<1, 3, [SDTCisInt<0>, SDTCisSameAs<0, 1>,
41 SDTCisVT<2, i32>, SDTCisSameAs<2, 3>]>;
42 def SDT_Ins : SDTypeProfile<1, 4, [SDTCisInt<0>, SDTCisSameAs<0, 1>,
43 SDTCisVT<2, i32>, SDTCisSameAs<2, 3>,
46 def SDTMipsLoadLR : SDTypeProfile<1, 2,
47 [SDTCisInt<0>, SDTCisPtrTy<1>,
51 def MipsJmpLink : SDNode<"MipsISD::JmpLink",SDT_MipsJmpLink,
52 [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue,
56 def MipsTailCall : SDNode<"MipsISD::TailCall", SDT_MipsJmpLink,
57 [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
59 // Hi and Lo nodes are used to handle global addresses. Used on
60 // MipsISelLowering to lower stuff like GlobalAddress, ExternalSymbol
61 // static model. (nothing to do with Mips Registers Hi and Lo)
62 def MipsHi : SDNode<"MipsISD::Hi", SDTIntUnaryOp>;
63 def MipsLo : SDNode<"MipsISD::Lo", SDTIntUnaryOp>;
64 def MipsGPRel : SDNode<"MipsISD::GPRel", SDTIntUnaryOp>;
66 // TlsGd node is used to handle General Dynamic TLS
67 def MipsTlsGd : SDNode<"MipsISD::TlsGd", SDTIntUnaryOp>;
69 // TprelHi and TprelLo nodes are used to handle Local Exec TLS
70 def MipsTprelHi : SDNode<"MipsISD::TprelHi", SDTIntUnaryOp>;
71 def MipsTprelLo : SDNode<"MipsISD::TprelLo", SDTIntUnaryOp>;
74 def MipsThreadPointer: SDNode<"MipsISD::ThreadPointer", SDT_MipsThreadPointer>;
77 def MipsRet : SDNode<"MipsISD::Ret", SDTNone,
78 [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
80 // These are target-independent nodes, but have target-specific formats.
81 def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_MipsCallSeqStart,
82 [SDNPHasChain, SDNPSideEffect, SDNPOutGlue]>;
83 def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_MipsCallSeqEnd,
84 [SDNPHasChain, SDNPSideEffect,
85 SDNPOptInGlue, SDNPOutGlue]>;
87 // Nodes used to extract LO/HI registers.
88 def MipsMFHI : SDNode<"MipsISD::MFHI", SDT_MFLOHI>;
89 def MipsMFLO : SDNode<"MipsISD::MFLO", SDT_MFLOHI>;
91 // Node used to insert 32-bit integers to LOHI register pair.
92 def MipsMTLOHI : SDNode<"MipsISD::MTLOHI", SDT_MTLOHI>;
95 def MipsMult : SDNode<"MipsISD::Mult", SDT_MipsMultDiv>;
96 def MipsMultu : SDNode<"MipsISD::Multu", SDT_MipsMultDiv>;
99 def MipsMAdd : SDNode<"MipsISD::MAdd", SDT_MipsMAddMSub>;
100 def MipsMAddu : SDNode<"MipsISD::MAddu", SDT_MipsMAddMSub>;
101 def MipsMSub : SDNode<"MipsISD::MSub", SDT_MipsMAddMSub>;
102 def MipsMSubu : SDNode<"MipsISD::MSubu", SDT_MipsMAddMSub>;
105 def MipsDivRem : SDNode<"MipsISD::DivRem", SDT_MipsMultDiv>;
106 def MipsDivRemU : SDNode<"MipsISD::DivRemU", SDT_MipsMultDiv>;
107 def MipsDivRem16 : SDNode<"MipsISD::DivRem16", SDT_MipsDivRem16,
109 def MipsDivRemU16 : SDNode<"MipsISD::DivRemU16", SDT_MipsDivRem16,
112 // Target constant nodes that are not part of any isel patterns and remain
113 // unchanged can cause instructions with illegal operands to be emitted.
114 // Wrapper node patterns give the instruction selector a chance to replace
115 // target constant nodes that would otherwise remain unchanged with ADDiu
116 // nodes. Without these wrapper node patterns, the following conditional move
117 // instruction is emitted when function cmov2 in test/CodeGen/Mips/cmov.ll is
119 // movn %got(d)($gp), %got(c)($gp), $4
120 // This instruction is illegal since movn can take only register operands.
122 def MipsWrapper : SDNode<"MipsISD::Wrapper", SDTIntBinOp>;
124 def MipsSync : SDNode<"MipsISD::Sync", SDT_Sync, [SDNPHasChain,SDNPSideEffect]>;
126 def MipsExt : SDNode<"MipsISD::Ext", SDT_Ext>;
127 def MipsIns : SDNode<"MipsISD::Ins", SDT_Ins>;
129 def MipsLWL : SDNode<"MipsISD::LWL", SDTMipsLoadLR,
130 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
131 def MipsLWR : SDNode<"MipsISD::LWR", SDTMipsLoadLR,
132 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
133 def MipsSWL : SDNode<"MipsISD::SWL", SDTStore,
134 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
135 def MipsSWR : SDNode<"MipsISD::SWR", SDTStore,
136 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
137 def MipsLDL : SDNode<"MipsISD::LDL", SDTMipsLoadLR,
138 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
139 def MipsLDR : SDNode<"MipsISD::LDR", SDTMipsLoadLR,
140 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
141 def MipsSDL : SDNode<"MipsISD::SDL", SDTStore,
142 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
143 def MipsSDR : SDNode<"MipsISD::SDR", SDTStore,
144 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
146 //===----------------------------------------------------------------------===//
147 // Mips Instruction Predicate Definitions.
148 //===----------------------------------------------------------------------===//
149 def HasSEInReg : Predicate<"Subtarget.hasSEInReg()">,
150 AssemblerPredicate<"FeatureSEInReg">;
151 def HasBitCount : Predicate<"Subtarget.hasBitCount()">,
152 AssemblerPredicate<"FeatureBitCount">;
153 def HasSwap : Predicate<"Subtarget.hasSwap()">,
154 AssemblerPredicate<"FeatureSwap">;
155 def HasCondMov : Predicate<"Subtarget.hasCondMov()">,
156 AssemblerPredicate<"FeatureCondMov">;
157 def HasFPIdx : Predicate<"Subtarget.hasFPIdx()">,
158 AssemblerPredicate<"FeatureFPIdx">;
159 def HasMips32 : Predicate<"Subtarget.hasMips32()">,
160 AssemblerPredicate<"FeatureMips32">;
161 def HasMips32r2 : Predicate<"Subtarget.hasMips32r2()">,
162 AssemblerPredicate<"FeatureMips32r2">;
163 def HasMips64 : Predicate<"Subtarget.hasMips64()">,
164 AssemblerPredicate<"FeatureMips64">;
165 def IsGP32 : Predicate<"!Subtarget.isGP64()">,
166 AssemblerPredicate<"!FeatureGP64Bit">;
167 def IsGP64 : Predicate<"Subtarget.isGP64()">,
168 AssemblerPredicate<"FeatureGP64Bit">;
169 def HasMips64r2 : Predicate<"Subtarget.hasMips64r2()">,
170 AssemblerPredicate<"FeatureMips64r2">;
171 def IsN64 : Predicate<"Subtarget.isABI_N64()">,
172 AssemblerPredicate<"FeatureN64">;
173 def InMips16Mode : Predicate<"Subtarget.inMips16Mode()">,
174 AssemblerPredicate<"FeatureMips16">;
175 def HasCnMips : Predicate<"Subtarget.hasCnMips()">,
176 AssemblerPredicate<"FeatureCnMips">;
177 def RelocStatic : Predicate<"TM.getRelocationModel() == Reloc::Static">,
178 AssemblerPredicate<"FeatureMips32">;
179 def RelocPIC : Predicate<"TM.getRelocationModel() == Reloc::PIC_">,
180 AssemblerPredicate<"FeatureMips32">;
181 def NoNaNsFPMath : Predicate<"TM.Options.NoNaNsFPMath">;
182 def HasStdEnc : Predicate<"Subtarget.hasStandardEncoding()">,
183 AssemblerPredicate<"!FeatureMips16">;
184 def NotDSP : Predicate<"!Subtarget.hasDSP()">;
185 def InMicroMips : Predicate<"Subtarget.inMicroMipsMode()">,
186 AssemblerPredicate<"FeatureMicroMips">;
187 def NotInMicroMips : Predicate<"!Subtarget.inMicroMipsMode()">,
188 AssemblerPredicate<"!FeatureMicroMips">;
189 def IsLE : Predicate<"Subtarget.isLittle()">;
190 def IsBE : Predicate<"!Subtarget.isLittle()">;
191 def IsNotNaCl : Predicate<"!Subtarget.isTargetNaCl()">;
193 class MipsPat<dag pattern, dag result> : Pat<pattern, result> {
194 let Predicates = [HasStdEnc];
198 bit isCommutable = 1;
215 bit isTerminator = 1;
218 bit hasExtraSrcRegAllocReq = 1;
219 bit isCodeGenOnly = 1;
222 class IsAsCheapAsAMove {
223 bit isAsCheapAsAMove = 1;
226 class NeverHasSideEffects {
227 bit neverHasSideEffects = 1;
230 //===----------------------------------------------------------------------===//
231 // Instruction format superclass
232 //===----------------------------------------------------------------------===//
234 include "MipsInstrFormats.td"
236 //===----------------------------------------------------------------------===//
237 // Mips Operand, Complex Patterns and Transformations Definitions.
238 //===----------------------------------------------------------------------===//
240 def MipsJumpTargetAsmOperand : AsmOperandClass {
241 let Name = "JumpTarget";
242 let ParserMethod = "ParseJumpTarget";
243 let PredicateMethod = "isImm";
244 let RenderMethod = "addImmOperands";
247 // Instruction operand types
248 def jmptarget : Operand<OtherVT> {
249 let EncoderMethod = "getJumpTargetOpValue";
250 let ParserMatchClass = MipsJumpTargetAsmOperand;
252 def brtarget : Operand<OtherVT> {
253 let EncoderMethod = "getBranchTargetOpValue";
254 let OperandType = "OPERAND_PCREL";
255 let DecoderMethod = "DecodeBranchTarget";
256 let ParserMatchClass = MipsJumpTargetAsmOperand;
258 def calltarget : Operand<iPTR> {
259 let EncoderMethod = "getJumpTargetOpValue";
260 let ParserMatchClass = MipsJumpTargetAsmOperand;
263 def simm10 : Operand<i32>;
265 def simm16 : Operand<i32> {
266 let DecoderMethod= "DecodeSimm16";
269 def simm20 : Operand<i32> {
272 def uimm20 : Operand<i32> {
275 def uimm10 : Operand<i32> {
278 def simm16_64 : Operand<i64> {
279 let DecoderMethod = "DecodeSimm16";
283 def uimmz : Operand<i32> {
284 let PrintMethod = "printUnsignedImm";
288 def uimm5 : Operand<i32> {
289 let PrintMethod = "printUnsignedImm";
292 def uimm6 : Operand<i32> {
293 let PrintMethod = "printUnsignedImm";
296 def uimm16 : Operand<i32> {
297 let PrintMethod = "printUnsignedImm";
300 def pcrel16 : Operand<i32> {
303 def MipsMemAsmOperand : AsmOperandClass {
305 let ParserMethod = "parseMemOperand";
308 def MipsInvertedImmoperand : AsmOperandClass {
310 let RenderMethod = "addImmOperands";
311 let ParserMethod = "parseInvNum";
314 def InvertedImOperand : Operand<i32> {
315 let ParserMatchClass = MipsInvertedImmoperand;
318 class mem_generic : Operand<iPTR> {
319 let PrintMethod = "printMemOperand";
320 let MIOperandInfo = (ops ptr_rc, simm16);
321 let EncoderMethod = "getMemEncoding";
322 let ParserMatchClass = MipsMemAsmOperand;
323 let OperandType = "OPERAND_MEMORY";
327 def mem : mem_generic;
329 // MSA specific address operand
330 def mem_msa : mem_generic {
331 let MIOperandInfo = (ops ptr_rc, simm10);
332 let EncoderMethod = "getMSAMemEncoding";
335 def mem_ea : Operand<iPTR> {
336 let PrintMethod = "printMemOperandEA";
337 let MIOperandInfo = (ops ptr_rc, simm16);
338 let EncoderMethod = "getMemEncoding";
339 let OperandType = "OPERAND_MEMORY";
342 def PtrRC : Operand<iPTR> {
343 let MIOperandInfo = (ops ptr_rc);
344 let DecoderMethod = "DecodePtrRegisterClass";
345 let ParserMatchClass = GPR32AsmOperand;
348 // size operand of ext instruction
349 def size_ext : Operand<i32> {
350 let EncoderMethod = "getSizeExtEncoding";
351 let DecoderMethod = "DecodeExtSize";
354 // size operand of ins instruction
355 def size_ins : Operand<i32> {
356 let EncoderMethod = "getSizeInsEncoding";
357 let DecoderMethod = "DecodeInsSize";
360 // Transformation Function - get the lower 16 bits.
361 def LO16 : SDNodeXForm<imm, [{
362 return getImm(N, N->getZExtValue() & 0xFFFF);
365 // Transformation Function - get the higher 16 bits.
366 def HI16 : SDNodeXForm<imm, [{
367 return getImm(N, (N->getZExtValue() >> 16) & 0xFFFF);
371 def Plus1 : SDNodeXForm<imm, [{ return getImm(N, N->getSExtValue() + 1); }]>;
373 // Node immediate is zero (e.g. insve.d)
374 def immz : PatLeaf<(imm), [{ return N->getSExtValue() == 0; }]>;
376 // Node immediate fits as 16-bit sign extended on target immediate.
378 def immSExt8 : PatLeaf<(imm), [{ return isInt<8>(N->getSExtValue()); }]>;
380 // Node immediate fits as 16-bit sign extended on target immediate.
382 def immSExt16 : PatLeaf<(imm), [{ return isInt<16>(N->getSExtValue()); }]>;
384 // Node immediate fits as 15-bit sign extended on target immediate.
386 def immSExt15 : PatLeaf<(imm), [{ return isInt<15>(N->getSExtValue()); }]>;
388 // Node immediate fits as 16-bit zero extended on target immediate.
389 // The LO16 param means that only the lower 16 bits of the node
390 // immediate are caught.
392 def immZExt16 : PatLeaf<(imm), [{
393 if (N->getValueType(0) == MVT::i32)
394 return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
396 return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
399 // Immediate can be loaded with LUi (32-bit int with lower 16-bit cleared).
400 def immLow16Zero : PatLeaf<(imm), [{
401 int64_t Val = N->getSExtValue();
402 return isInt<32>(Val) && !(Val & 0xffff);
405 // shamt field must fit in 5 bits.
406 def immZExt5 : ImmLeaf<i32, [{return Imm == (Imm & 0x1f);}]>;
408 // True if (N + 1) fits in 16-bit field.
409 def immSExt16Plus1 : PatLeaf<(imm), [{
410 return isInt<17>(N->getSExtValue()) && isInt<16>(N->getSExtValue() + 1);
413 // Mips Address Mode! SDNode frameindex could possibily be a match
414 // since load and store instructions from stack used it.
416 ComplexPattern<iPTR, 2, "selectIntAddr", [frameindex]>;
419 ComplexPattern<iPTR, 2, "selectAddrRegImm", [frameindex]>;
422 ComplexPattern<iPTR, 2, "selectAddrRegReg", [frameindex]>;
425 ComplexPattern<iPTR, 2, "selectAddrDefault", [frameindex]>;
427 def addrimm10 : ComplexPattern<iPTR, 2, "selectIntAddrMSA", [frameindex]>;
429 //===----------------------------------------------------------------------===//
430 // Instructions specific format
431 //===----------------------------------------------------------------------===//
433 // Arithmetic and logical instructions with 3 register operands.
434 class ArithLogicR<string opstr, RegisterOperand RO, bit isComm = 0,
435 InstrItinClass Itin = NoItinerary,
436 SDPatternOperator OpNode = null_frag>:
437 InstSE<(outs RO:$rd), (ins RO:$rs, RO:$rt),
438 !strconcat(opstr, "\t$rd, $rs, $rt"),
439 [(set RO:$rd, (OpNode RO:$rs, RO:$rt))], Itin, FrmR, opstr> {
440 let isCommutable = isComm;
441 let isReMaterializable = 1;
442 let TwoOperandAliasConstraint = "$rd = $rs";
445 // Arithmetic and logical instructions with 2 register operands.
446 class ArithLogicI<string opstr, Operand Od, RegisterOperand RO,
447 InstrItinClass Itin = NoItinerary,
448 SDPatternOperator imm_type = null_frag,
449 SDPatternOperator OpNode = null_frag> :
450 InstSE<(outs RO:$rt), (ins RO:$rs, Od:$imm16),
451 !strconcat(opstr, "\t$rt, $rs, $imm16"),
452 [(set RO:$rt, (OpNode RO:$rs, imm_type:$imm16))],
454 let isReMaterializable = 1;
455 let TwoOperandAliasConstraint = "$rs = $rt";
458 // Arithmetic Multiply ADD/SUB
459 class MArithR<string opstr, InstrItinClass itin, bit isComm = 0> :
460 InstSE<(outs), (ins GPR32Opnd:$rs, GPR32Opnd:$rt),
461 !strconcat(opstr, "\t$rs, $rt"), [], itin, FrmR, opstr> {
462 let Defs = [HI0, LO0];
463 let Uses = [HI0, LO0];
464 let isCommutable = isComm;
468 class LogicNOR<string opstr, RegisterOperand RO>:
469 InstSE<(outs RO:$rd), (ins RO:$rs, RO:$rt),
470 !strconcat(opstr, "\t$rd, $rs, $rt"),
471 [(set RO:$rd, (not (or RO:$rs, RO:$rt)))], II_NOR, FrmR, opstr> {
472 let isCommutable = 1;
476 class shift_rotate_imm<string opstr, Operand ImmOpnd,
477 RegisterOperand RO, InstrItinClass itin,
478 SDPatternOperator OpNode = null_frag,
479 SDPatternOperator PF = null_frag> :
480 InstSE<(outs RO:$rd), (ins RO:$rt, ImmOpnd:$shamt),
481 !strconcat(opstr, "\t$rd, $rt, $shamt"),
482 [(set RO:$rd, (OpNode RO:$rt, PF:$shamt))], itin, FrmR, opstr>;
484 class shift_rotate_reg<string opstr, RegisterOperand RO, InstrItinClass itin,
485 SDPatternOperator OpNode = null_frag>:
486 InstSE<(outs RO:$rd), (ins RO:$rt, GPR32Opnd:$rs),
487 !strconcat(opstr, "\t$rd, $rt, $rs"),
488 [(set RO:$rd, (OpNode RO:$rt, GPR32Opnd:$rs))], itin, FrmR,
491 // Load Upper Imediate
492 class LoadUpper<string opstr, RegisterOperand RO, Operand Imm>:
493 InstSE<(outs RO:$rt), (ins Imm:$imm16), !strconcat(opstr, "\t$rt, $imm16"),
494 [], II_LUI, FrmI, opstr>, IsAsCheapAsAMove {
495 let neverHasSideEffects = 1;
496 let isReMaterializable = 1;
500 class Load<string opstr, DAGOperand RO, SDPatternOperator OpNode = null_frag,
501 InstrItinClass Itin = NoItinerary, ComplexPattern Addr = addr> :
502 InstSE<(outs RO:$rt), (ins mem:$addr), !strconcat(opstr, "\t$rt, $addr"),
503 [(set RO:$rt, (OpNode Addr:$addr))], Itin, FrmI, opstr> {
504 let DecoderMethod = "DecodeMem";
505 let canFoldAsLoad = 1;
509 class Store<string opstr, DAGOperand RO, SDPatternOperator OpNode = null_frag,
510 InstrItinClass Itin = NoItinerary, ComplexPattern Addr = addr> :
511 InstSE<(outs), (ins RO:$rt, mem:$addr), !strconcat(opstr, "\t$rt, $addr"),
512 [(OpNode RO:$rt, Addr:$addr)], Itin, FrmI, opstr> {
513 let DecoderMethod = "DecodeMem";
517 // Load/Store Left/Right
518 let canFoldAsLoad = 1 in
519 class LoadLeftRight<string opstr, SDNode OpNode, RegisterOperand RO,
520 InstrItinClass Itin> :
521 InstSE<(outs RO:$rt), (ins mem:$addr, RO:$src),
522 !strconcat(opstr, "\t$rt, $addr"),
523 [(set RO:$rt, (OpNode addr:$addr, RO:$src))], Itin, FrmI> {
524 let DecoderMethod = "DecodeMem";
525 string Constraints = "$src = $rt";
528 class StoreLeftRight<string opstr, SDNode OpNode, RegisterOperand RO,
529 InstrItinClass Itin> :
530 InstSE<(outs), (ins RO:$rt, mem:$addr), !strconcat(opstr, "\t$rt, $addr"),
531 [(OpNode RO:$rt, addr:$addr)], Itin, FrmI> {
532 let DecoderMethod = "DecodeMem";
535 // Conditional Branch
536 class CBranch<string opstr, DAGOperand opnd, PatFrag cond_op,
537 RegisterOperand RO> :
538 InstSE<(outs), (ins RO:$rs, RO:$rt, opnd:$offset),
539 !strconcat(opstr, "\t$rs, $rt, $offset"),
540 [(brcond (i32 (cond_op RO:$rs, RO:$rt)), bb:$offset)], IIBranch,
543 let isTerminator = 1;
544 let hasDelaySlot = 1;
548 class CBranchZero<string opstr, DAGOperand opnd, PatFrag cond_op,
549 RegisterOperand RO> :
550 InstSE<(outs), (ins RO:$rs, opnd:$offset),
551 !strconcat(opstr, "\t$rs, $offset"),
552 [(brcond (i32 (cond_op RO:$rs, 0)), bb:$offset)], IIBranch,
555 let isTerminator = 1;
556 let hasDelaySlot = 1;
561 class SetCC_R<string opstr, PatFrag cond_op, RegisterOperand RO> :
562 InstSE<(outs GPR32Opnd:$rd), (ins RO:$rs, RO:$rt),
563 !strconcat(opstr, "\t$rd, $rs, $rt"),
564 [(set GPR32Opnd:$rd, (cond_op RO:$rs, RO:$rt))],
565 II_SLT_SLTU, FrmR, opstr>;
567 class SetCC_I<string opstr, PatFrag cond_op, Operand Od, PatLeaf imm_type,
569 InstSE<(outs GPR32Opnd:$rt), (ins RO:$rs, Od:$imm16),
570 !strconcat(opstr, "\t$rt, $rs, $imm16"),
571 [(set GPR32Opnd:$rt, (cond_op RO:$rs, imm_type:$imm16))],
572 II_SLTI_SLTIU, FrmI, opstr>;
575 class JumpFJ<DAGOperand opnd, string opstr, SDPatternOperator operator,
576 SDPatternOperator targetoperator, string bopstr> :
577 InstSE<(outs), (ins opnd:$target), !strconcat(opstr, "\t$target"),
578 [(operator targetoperator:$target)], IIBranch, FrmJ, bopstr> {
581 let hasDelaySlot = 1;
582 let DecoderMethod = "DecodeJumpTarget";
586 // Unconditional branch
587 class UncondBranch<Instruction BEQInst> :
588 PseudoSE<(outs), (ins brtarget:$offset), [(br bb:$offset)], IIBranch>,
589 PseudoInstExpansion<(BEQInst ZERO, ZERO, brtarget:$offset)> {
591 let isTerminator = 1;
593 let hasDelaySlot = 1;
594 let Predicates = [RelocPIC, HasStdEnc];
598 // Base class for indirect branch and return instruction classes.
599 let isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
600 class JumpFR<string opstr, RegisterOperand RO,
601 SDPatternOperator operator = null_frag>:
602 InstSE<(outs), (ins RO:$rs), "jr\t$rs", [(operator RO:$rs)], IIBranch,
606 class IndirectBranch<string opstr, RegisterOperand RO> :
607 JumpFR<opstr, RO, brind> {
609 let isIndirectBranch = 1;
612 // Return instruction
613 class RetBase<string opstr, RegisterOperand RO>: JumpFR<opstr, RO> {
615 let isCodeGenOnly = 1;
617 let hasExtraSrcRegAllocReq = 1;
620 // Jump and Link (Call)
621 let isCall=1, hasDelaySlot=1, Defs = [RA] in {
622 class JumpLink<string opstr, DAGOperand opnd> :
623 InstSE<(outs), (ins opnd:$target), !strconcat(opstr, "\t$target"),
624 [(MipsJmpLink imm:$target)], IIBranch, FrmJ, opstr> {
625 let DecoderMethod = "DecodeJumpTarget";
628 class JumpLinkRegPseudo<RegisterOperand RO, Instruction JALRInst,
629 Register RetReg, RegisterOperand ResRO = RO>:
630 PseudoSE<(outs), (ins RO:$rs), [(MipsJmpLink RO:$rs)], IIBranch>,
631 PseudoInstExpansion<(JALRInst RetReg, ResRO:$rs)>;
633 class JumpLinkReg<string opstr, RegisterOperand RO>:
634 InstSE<(outs RO:$rd), (ins RO:$rs), !strconcat(opstr, "\t$rd, $rs"),
637 class BGEZAL_FT<string opstr, DAGOperand opnd, RegisterOperand RO> :
638 InstSE<(outs), (ins RO:$rs, opnd:$offset),
639 !strconcat(opstr, "\t$rs, $offset"), [], IIBranch, FrmI, opstr>;
643 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1, hasDelaySlot = 1,
644 hasExtraSrcRegAllocReq = 1, Defs = [AT] in {
645 class TailCall<Instruction JumpInst> :
646 PseudoSE<(outs), (ins calltarget:$target), [], IIBranch>,
647 PseudoInstExpansion<(JumpInst jmptarget:$target)>;
649 class TailCallReg<RegisterOperand RO, Instruction JRInst,
650 RegisterOperand ResRO = RO> :
651 PseudoSE<(outs), (ins RO:$rs), [(MipsTailCall RO:$rs)], IIBranch>,
652 PseudoInstExpansion<(JRInst ResRO:$rs)>;
655 class BAL_BR_Pseudo<Instruction RealInst> :
656 PseudoSE<(outs), (ins brtarget:$offset), [], IIBranch>,
657 PseudoInstExpansion<(RealInst ZERO, brtarget:$offset)> {
659 let isTerminator = 1;
661 let hasDelaySlot = 1;
666 class SYS_FT<string opstr> :
667 InstSE<(outs), (ins uimm20:$code_),
668 !strconcat(opstr, "\t$code_"), [], NoItinerary, FrmI, opstr>;
670 class BRK_FT<string opstr> :
671 InstSE<(outs), (ins uimm10:$code_1, uimm10:$code_2),
672 !strconcat(opstr, "\t$code_1, $code_2"), [], NoItinerary,
676 class ER_FT<string opstr> :
677 InstSE<(outs), (ins),
678 opstr, [], NoItinerary, FrmOther, opstr>;
681 class DEI_FT<string opstr, RegisterOperand RO> :
682 InstSE<(outs RO:$rt), (ins),
683 !strconcat(opstr, "\t$rt"), [], NoItinerary, FrmOther, opstr>;
686 class WAIT_FT<string opstr> :
687 InstSE<(outs), (ins), opstr, [], NoItinerary, FrmOther, opstr>;
690 let hasSideEffects = 1 in
691 class SYNC_FT<string opstr> :
692 InstSE<(outs), (ins i32imm:$stype), "sync $stype", [(MipsSync imm:$stype)],
693 NoItinerary, FrmOther, opstr>;
695 let hasSideEffects = 1 in
696 class TEQ_FT<string opstr, RegisterOperand RO> :
697 InstSE<(outs), (ins RO:$rs, RO:$rt, uimm16:$code_),
698 !strconcat(opstr, "\t$rs, $rt, $code_"), [], NoItinerary,
701 class TEQI_FT<string opstr, RegisterOperand RO> :
702 InstSE<(outs), (ins RO:$rs, uimm16:$imm16),
703 !strconcat(opstr, "\t$rs, $imm16"), [], NoItinerary, FrmOther, opstr>;
705 class Mult<string opstr, InstrItinClass itin, RegisterOperand RO,
706 list<Register> DefRegs> :
707 InstSE<(outs), (ins RO:$rs, RO:$rt), !strconcat(opstr, "\t$rs, $rt"), [],
709 let isCommutable = 1;
711 let neverHasSideEffects = 1;
714 // Pseudo multiply/divide instruction with explicit accumulator register
716 class MultDivPseudo<Instruction RealInst, RegisterClass R0, RegisterOperand R1,
717 SDPatternOperator OpNode, InstrItinClass Itin,
718 bit IsComm = 1, bit HasSideEffects = 0,
719 bit UsesCustomInserter = 0> :
720 PseudoSE<(outs R0:$ac), (ins R1:$rs, R1:$rt),
721 [(set R0:$ac, (OpNode R1:$rs, R1:$rt))], Itin>,
722 PseudoInstExpansion<(RealInst R1:$rs, R1:$rt)> {
723 let isCommutable = IsComm;
724 let hasSideEffects = HasSideEffects;
725 let usesCustomInserter = UsesCustomInserter;
728 // Pseudo multiply add/sub instruction with explicit accumulator register
730 class MAddSubPseudo<Instruction RealInst, SDPatternOperator OpNode,
732 : PseudoSE<(outs ACC64:$ac),
733 (ins GPR32Opnd:$rs, GPR32Opnd:$rt, ACC64:$acin),
735 (OpNode GPR32Opnd:$rs, GPR32Opnd:$rt, ACC64:$acin))],
737 PseudoInstExpansion<(RealInst GPR32Opnd:$rs, GPR32Opnd:$rt)> {
738 string Constraints = "$acin = $ac";
741 class Div<string opstr, InstrItinClass itin, RegisterOperand RO,
742 list<Register> DefRegs> :
743 InstSE<(outs), (ins RO:$rs, RO:$rt), !strconcat(opstr, "\t$$zero, $rs, $rt"),
744 [], itin, FrmR, opstr> {
749 class PseudoMFLOHI<RegisterClass DstRC, RegisterClass SrcRC, SDNode OpNode>
750 : PseudoSE<(outs DstRC:$rd), (ins SrcRC:$hilo),
751 [(set DstRC:$rd, (OpNode SrcRC:$hilo))], II_MFHI_MFLO>;
753 class MoveFromLOHI<string opstr, RegisterOperand RO, Register UseReg>:
754 InstSE<(outs RO:$rd), (ins), !strconcat(opstr, "\t$rd"), [], II_MFHI_MFLO,
757 let neverHasSideEffects = 1;
760 class PseudoMTLOHI<RegisterClass DstRC, RegisterClass SrcRC>
761 : PseudoSE<(outs DstRC:$lohi), (ins SrcRC:$lo, SrcRC:$hi),
762 [(set DstRC:$lohi, (MipsMTLOHI SrcRC:$lo, SrcRC:$hi))],
765 class MoveToLOHI<string opstr, RegisterOperand RO, list<Register> DefRegs>:
766 InstSE<(outs), (ins RO:$rs), !strconcat(opstr, "\t$rs"), [], II_MTHI_MTLO,
769 let neverHasSideEffects = 1;
772 class EffectiveAddress<string opstr, RegisterOperand RO> :
773 InstSE<(outs RO:$rt), (ins mem_ea:$addr), !strconcat(opstr, "\t$rt, $addr"),
774 [(set RO:$rt, addr:$addr)], NoItinerary, FrmI,
775 !strconcat(opstr, "_lea")> {
776 let isCodeGenOnly = 1;
777 let DecoderMethod = "DecodeMem";
780 // Count Leading Ones/Zeros in Word
781 class CountLeading0<string opstr, RegisterOperand RO>:
782 InstSE<(outs RO:$rd), (ins RO:$rs), !strconcat(opstr, "\t$rd, $rs"),
783 [(set RO:$rd, (ctlz RO:$rs))], II_CLZ, FrmR, opstr>,
784 Requires<[HasBitCount, HasStdEnc]>;
786 class CountLeading1<string opstr, RegisterOperand RO>:
787 InstSE<(outs RO:$rd), (ins RO:$rs), !strconcat(opstr, "\t$rd, $rs"),
788 [(set RO:$rd, (ctlz (not RO:$rs)))], II_CLO, FrmR, opstr>,
789 Requires<[HasBitCount, HasStdEnc]>;
791 // Sign Extend in Register.
792 class SignExtInReg<string opstr, ValueType vt, RegisterOperand RO,
793 InstrItinClass itin> :
794 InstSE<(outs RO:$rd), (ins RO:$rt), !strconcat(opstr, "\t$rd, $rt"),
795 [(set RO:$rd, (sext_inreg RO:$rt, vt))], itin, FrmR, opstr> {
796 let Predicates = [HasSEInReg, HasStdEnc];
800 class SubwordSwap<string opstr, RegisterOperand RO>:
801 InstSE<(outs RO:$rd), (ins RO:$rt), !strconcat(opstr, "\t$rd, $rt"), [],
802 NoItinerary, FrmR, opstr> {
803 let Predicates = [HasSwap, HasStdEnc];
804 let neverHasSideEffects = 1;
808 class ReadHardware<RegisterOperand CPURegOperand, RegisterOperand RO> :
809 InstSE<(outs CPURegOperand:$rt), (ins RO:$rd), "rdhwr\t$rt, $rd", [],
813 class ExtBase<string opstr, RegisterOperand RO, Operand PosOpnd,
814 SDPatternOperator Op = null_frag>:
815 InstSE<(outs RO:$rt), (ins RO:$rs, PosOpnd:$pos, size_ext:$size),
816 !strconcat(opstr, " $rt, $rs, $pos, $size"),
817 [(set RO:$rt, (Op RO:$rs, imm:$pos, imm:$size))], NoItinerary,
819 let Predicates = [HasMips32r2, HasStdEnc];
822 class InsBase<string opstr, RegisterOperand RO, Operand PosOpnd,
823 SDPatternOperator Op = null_frag>:
824 InstSE<(outs RO:$rt), (ins RO:$rs, PosOpnd:$pos, size_ins:$size, RO:$src),
825 !strconcat(opstr, " $rt, $rs, $pos, $size"),
826 [(set RO:$rt, (Op RO:$rs, imm:$pos, imm:$size, RO:$src))],
827 NoItinerary, FrmR, opstr> {
828 let Predicates = [HasMips32r2, HasStdEnc];
829 let Constraints = "$src = $rt";
832 // Atomic instructions with 2 source operands (ATOMIC_SWAP & ATOMIC_LOAD_*).
833 class Atomic2Ops<PatFrag Op, RegisterClass DRC> :
834 PseudoSE<(outs DRC:$dst), (ins PtrRC:$ptr, DRC:$incr),
835 [(set DRC:$dst, (Op iPTR:$ptr, DRC:$incr))]>;
837 // Atomic Compare & Swap.
838 class AtomicCmpSwap<PatFrag Op, RegisterClass DRC> :
839 PseudoSE<(outs DRC:$dst), (ins PtrRC:$ptr, DRC:$cmp, DRC:$swap),
840 [(set DRC:$dst, (Op iPTR:$ptr, DRC:$cmp, DRC:$swap))]>;
842 class LLBase<string opstr, RegisterOperand RO> :
843 InstSE<(outs RO:$rt), (ins mem:$addr), !strconcat(opstr, "\t$rt, $addr"),
844 [], NoItinerary, FrmI> {
845 let DecoderMethod = "DecodeMem";
849 class SCBase<string opstr, RegisterOperand RO> :
850 InstSE<(outs RO:$dst), (ins RO:$rt, mem:$addr),
851 !strconcat(opstr, "\t$rt, $addr"), [], NoItinerary, FrmI> {
852 let DecoderMethod = "DecodeMem";
854 let Constraints = "$rt = $dst";
857 class MFC3OP<string asmstr, RegisterOperand RO> :
858 InstSE<(outs RO:$rt, RO:$rd, uimm16:$sel), (ins),
859 !strconcat(asmstr, "\t$rt, $rd, $sel"), [], NoItinerary, FrmFR>;
861 class TrapBase<Instruction RealInst>
862 : PseudoSE<(outs), (ins), [(trap)], NoItinerary>,
863 PseudoInstExpansion<(RealInst 0, 0)> {
865 let isTerminator = 1;
866 let isCodeGenOnly = 1;
869 //===----------------------------------------------------------------------===//
870 // Pseudo instructions
871 //===----------------------------------------------------------------------===//
874 let isReturn=1, isTerminator=1, hasDelaySlot=1, isBarrier=1, hasCtrlDep=1 in
875 def RetRA : PseudoSE<(outs), (ins), [(MipsRet)]>;
877 let Defs = [SP], Uses = [SP], hasSideEffects = 1 in {
878 def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins i32imm:$amt),
879 [(callseq_start timm:$amt)]>;
880 def ADJCALLSTACKUP : MipsPseudo<(outs), (ins i32imm:$amt1, i32imm:$amt2),
881 [(callseq_end timm:$amt1, timm:$amt2)]>;
884 let usesCustomInserter = 1 in {
885 def ATOMIC_LOAD_ADD_I8 : Atomic2Ops<atomic_load_add_8, GPR32>;
886 def ATOMIC_LOAD_ADD_I16 : Atomic2Ops<atomic_load_add_16, GPR32>;
887 def ATOMIC_LOAD_ADD_I32 : Atomic2Ops<atomic_load_add_32, GPR32>;
888 def ATOMIC_LOAD_SUB_I8 : Atomic2Ops<atomic_load_sub_8, GPR32>;
889 def ATOMIC_LOAD_SUB_I16 : Atomic2Ops<atomic_load_sub_16, GPR32>;
890 def ATOMIC_LOAD_SUB_I32 : Atomic2Ops<atomic_load_sub_32, GPR32>;
891 def ATOMIC_LOAD_AND_I8 : Atomic2Ops<atomic_load_and_8, GPR32>;
892 def ATOMIC_LOAD_AND_I16 : Atomic2Ops<atomic_load_and_16, GPR32>;
893 def ATOMIC_LOAD_AND_I32 : Atomic2Ops<atomic_load_and_32, GPR32>;
894 def ATOMIC_LOAD_OR_I8 : Atomic2Ops<atomic_load_or_8, GPR32>;
895 def ATOMIC_LOAD_OR_I16 : Atomic2Ops<atomic_load_or_16, GPR32>;
896 def ATOMIC_LOAD_OR_I32 : Atomic2Ops<atomic_load_or_32, GPR32>;
897 def ATOMIC_LOAD_XOR_I8 : Atomic2Ops<atomic_load_xor_8, GPR32>;
898 def ATOMIC_LOAD_XOR_I16 : Atomic2Ops<atomic_load_xor_16, GPR32>;
899 def ATOMIC_LOAD_XOR_I32 : Atomic2Ops<atomic_load_xor_32, GPR32>;
900 def ATOMIC_LOAD_NAND_I8 : Atomic2Ops<atomic_load_nand_8, GPR32>;
901 def ATOMIC_LOAD_NAND_I16 : Atomic2Ops<atomic_load_nand_16, GPR32>;
902 def ATOMIC_LOAD_NAND_I32 : Atomic2Ops<atomic_load_nand_32, GPR32>;
904 def ATOMIC_SWAP_I8 : Atomic2Ops<atomic_swap_8, GPR32>;
905 def ATOMIC_SWAP_I16 : Atomic2Ops<atomic_swap_16, GPR32>;
906 def ATOMIC_SWAP_I32 : Atomic2Ops<atomic_swap_32, GPR32>;
908 def ATOMIC_CMP_SWAP_I8 : AtomicCmpSwap<atomic_cmp_swap_8, GPR32>;
909 def ATOMIC_CMP_SWAP_I16 : AtomicCmpSwap<atomic_cmp_swap_16, GPR32>;
910 def ATOMIC_CMP_SWAP_I32 : AtomicCmpSwap<atomic_cmp_swap_32, GPR32>;
913 /// Pseudo instructions for loading and storing accumulator registers.
914 let isPseudo = 1, isCodeGenOnly = 1 in {
915 def LOAD_ACC64 : Load<"", ACC64>;
916 def STORE_ACC64 : Store<"", ACC64>;
919 //===----------------------------------------------------------------------===//
920 // Instruction definition
921 //===----------------------------------------------------------------------===//
922 //===----------------------------------------------------------------------===//
923 // MipsI Instructions
924 //===----------------------------------------------------------------------===//
926 /// Arithmetic Instructions (ALU Immediate)
927 def ADDiu : MMRel, ArithLogicI<"addiu", simm16, GPR32Opnd, II_ADDIU, immSExt16,
929 ADDI_FM<0x9>, IsAsCheapAsAMove;
930 def ADDi : MMRel, ArithLogicI<"addi", simm16, GPR32Opnd>, ADDI_FM<0x8>;
931 def SLTi : MMRel, SetCC_I<"slti", setlt, simm16, immSExt16, GPR32Opnd>,
933 def SLTiu : MMRel, SetCC_I<"sltiu", setult, simm16, immSExt16, GPR32Opnd>,
935 def ANDi : MMRel, ArithLogicI<"andi", uimm16, GPR32Opnd, II_ANDI, immZExt16,
938 def ORi : MMRel, ArithLogicI<"ori", uimm16, GPR32Opnd, II_ORI, immZExt16,
941 def XORi : MMRel, ArithLogicI<"xori", uimm16, GPR32Opnd, II_XORI, immZExt16,
944 def LUi : MMRel, LoadUpper<"lui", GPR32Opnd, uimm16>, LUI_FM;
946 /// Arithmetic Instructions (3-Operand, R-Type)
947 def ADDu : MMRel, ArithLogicR<"addu", GPR32Opnd, 1, II_ADDU, add>,
949 def SUBu : MMRel, ArithLogicR<"subu", GPR32Opnd, 0, II_SUBU, sub>,
951 let Defs = [HI0, LO0] in
952 def MUL : MMRel, ArithLogicR<"mul", GPR32Opnd, 1, II_MUL, mul>,
954 def ADD : MMRel, ArithLogicR<"add", GPR32Opnd>, ADD_FM<0, 0x20>;
955 def SUB : MMRel, ArithLogicR<"sub", GPR32Opnd>, ADD_FM<0, 0x22>;
956 def SLT : MMRel, SetCC_R<"slt", setlt, GPR32Opnd>, ADD_FM<0, 0x2a>;
957 def SLTu : MMRel, SetCC_R<"sltu", setult, GPR32Opnd>, ADD_FM<0, 0x2b>;
958 def AND : MMRel, ArithLogicR<"and", GPR32Opnd, 1, II_AND, and>,
960 def OR : MMRel, ArithLogicR<"or", GPR32Opnd, 1, II_OR, or>,
962 def XOR : MMRel, ArithLogicR<"xor", GPR32Opnd, 1, II_XOR, xor>,
964 def NOR : MMRel, LogicNOR<"nor", GPR32Opnd>, ADD_FM<0, 0x27>;
966 /// Shift Instructions
967 def SLL : MMRel, shift_rotate_imm<"sll", uimm5, GPR32Opnd, II_SLL, shl,
968 immZExt5>, SRA_FM<0, 0>;
969 def SRL : MMRel, shift_rotate_imm<"srl", uimm5, GPR32Opnd, II_SRL, srl,
970 immZExt5>, SRA_FM<2, 0>;
971 def SRA : MMRel, shift_rotate_imm<"sra", uimm5, GPR32Opnd, II_SRA, sra,
972 immZExt5>, SRA_FM<3, 0>;
973 def SLLV : MMRel, shift_rotate_reg<"sllv", GPR32Opnd, II_SLLV, shl>,
975 def SRLV : MMRel, shift_rotate_reg<"srlv", GPR32Opnd, II_SRLV, srl>,
977 def SRAV : MMRel, shift_rotate_reg<"srav", GPR32Opnd, II_SRAV, sra>,
980 // Rotate Instructions
981 let Predicates = [HasMips32r2, HasStdEnc] in {
982 def ROTR : MMRel, shift_rotate_imm<"rotr", uimm5, GPR32Opnd, II_ROTR, rotr,
983 immZExt5>, SRA_FM<2, 1>;
984 def ROTRV : MMRel, shift_rotate_reg<"rotrv", GPR32Opnd, II_ROTRV, rotr>,
988 /// Load and Store Instructions
990 def LB : Load<"lb", GPR32Opnd, sextloadi8, II_LB>, MMRel, LW_FM<0x20>;
991 def LBu : Load<"lbu", GPR32Opnd, zextloadi8, II_LBU, addrDefault>, MMRel,
993 def LH : Load<"lh", GPR32Opnd, sextloadi16, II_LH, addrDefault>, MMRel,
995 def LHu : Load<"lhu", GPR32Opnd, zextloadi16, II_LHU>, MMRel, LW_FM<0x25>;
996 def LW : Load<"lw", GPR32Opnd, load, II_LW, addrDefault>, MMRel,
998 def SB : Store<"sb", GPR32Opnd, truncstorei8, II_SB>, MMRel, LW_FM<0x28>;
999 def SH : Store<"sh", GPR32Opnd, truncstorei16, II_SH>, MMRel, LW_FM<0x29>;
1000 def SW : Store<"sw", GPR32Opnd, store, II_SW>, MMRel, LW_FM<0x2b>;
1002 /// load/store left/right
1003 let Predicates = [NotInMicroMips] in {
1004 def LWL : LoadLeftRight<"lwl", MipsLWL, GPR32Opnd, II_LWL>, LW_FM<0x22>;
1005 def LWR : LoadLeftRight<"lwr", MipsLWR, GPR32Opnd, II_LWR>, LW_FM<0x26>;
1006 def SWL : StoreLeftRight<"swl", MipsSWL, GPR32Opnd, II_SWL>, LW_FM<0x2a>;
1007 def SWR : StoreLeftRight<"swr", MipsSWR, GPR32Opnd, II_SWR>, LW_FM<0x2e>;
1010 def SYNC : MMRel, SYNC_FT<"sync">, SYNC_FM;
1011 def TEQ : MMRel, TEQ_FT<"teq", GPR32Opnd>, TEQ_FM<0x34>;
1012 def TGE : MMRel, TEQ_FT<"tge", GPR32Opnd>, TEQ_FM<0x30>;
1013 def TGEU : MMRel, TEQ_FT<"tgeu", GPR32Opnd>, TEQ_FM<0x31>;
1014 def TLT : MMRel, TEQ_FT<"tlt", GPR32Opnd>, TEQ_FM<0x32>;
1015 def TLTU : MMRel, TEQ_FT<"tltu", GPR32Opnd>, TEQ_FM<0x33>;
1016 def TNE : MMRel, TEQ_FT<"tne", GPR32Opnd>, TEQ_FM<0x36>;
1018 def TEQI : MMRel, TEQI_FT<"teqi", GPR32Opnd>, TEQI_FM<0xc>;
1019 def TGEI : MMRel, TEQI_FT<"tgei", GPR32Opnd>, TEQI_FM<0x8>;
1020 def TGEIU : MMRel, TEQI_FT<"tgeiu", GPR32Opnd>, TEQI_FM<0x9>;
1021 def TLTI : MMRel, TEQI_FT<"tlti", GPR32Opnd>, TEQI_FM<0xa>;
1022 def TTLTIU : MMRel, TEQI_FT<"tltiu", GPR32Opnd>, TEQI_FM<0xb>;
1023 def TNEI : MMRel, TEQI_FT<"tnei", GPR32Opnd>, TEQI_FM<0xe>;
1025 def BREAK : MMRel, BRK_FT<"break">, BRK_FM<0xd>;
1026 def SYSCALL : MMRel, SYS_FT<"syscall">, SYS_FM<0xc>;
1027 def TRAP : TrapBase<BREAK>;
1029 def ERET : MMRel, ER_FT<"eret">, ER_FM<0x18>;
1030 def DERET : MMRel, ER_FT<"deret">, ER_FM<0x1f>;
1032 def EI : MMRel, DEI_FT<"ei", GPR32Opnd>, EI_FM<1>;
1033 def DI : MMRel, DEI_FT<"di", GPR32Opnd>, EI_FM<0>;
1035 let Predicates = [NotInMicroMips] in {
1036 def WAIT : WAIT_FT<"wait">, WAIT_FM;
1038 /// Load-linked, Store-conditional
1039 def LL : LLBase<"ll", GPR32Opnd>, LW_FM<0x30>;
1040 def SC : SCBase<"sc", GPR32Opnd>, LW_FM<0x38>;
1043 /// Jump and Branch Instructions
1044 def J : MMRel, JumpFJ<jmptarget, "j", br, bb, "j">, FJ<2>,
1045 Requires<[RelocStatic, HasStdEnc]>, IsBranch;
1046 def JR : MMRel, IndirectBranch<"jr", GPR32Opnd>, MTLO_FM<8>;
1047 def BEQ : MMRel, CBranch<"beq", brtarget, seteq, GPR32Opnd>, BEQ_FM<4>;
1048 def BNE : MMRel, CBranch<"bne", brtarget, setne, GPR32Opnd>, BEQ_FM<5>;
1049 def BGEZ : MMRel, CBranchZero<"bgez", brtarget, setge, GPR32Opnd>,
1051 def BGTZ : MMRel, CBranchZero<"bgtz", brtarget, setgt, GPR32Opnd>,
1053 def BLEZ : MMRel, CBranchZero<"blez", brtarget, setle, GPR32Opnd>,
1055 def BLTZ : MMRel, CBranchZero<"bltz", brtarget, setlt, GPR32Opnd>,
1057 def B : UncondBranch<BEQ>;
1059 def JAL : MMRel, JumpLink<"jal", calltarget>, FJ<3>;
1060 let Predicates = [NotInMicroMips, HasStdEnc] in {
1061 def JALR : JumpLinkReg<"jalr", GPR32Opnd>, JALR_FM;
1062 def JALRPseudo : JumpLinkRegPseudo<GPR32Opnd, JALR, RA>;
1064 def JALX : JumpLink<"jalx", calltarget>, FJ<0x1D>;
1065 def BGEZAL : MMRel, BGEZAL_FT<"bgezal", brtarget, GPR32Opnd>, BGEZAL_FM<0x11>;
1066 def BLTZAL : MMRel, BGEZAL_FT<"bltzal", brtarget, GPR32Opnd>, BGEZAL_FM<0x10>;
1067 def BAL_BR : BAL_BR_Pseudo<BGEZAL>;
1068 def TAILCALL : TailCall<J>;
1069 def TAILCALL_R : TailCallReg<GPR32Opnd, JR>;
1071 def RET : MMRel, RetBase<"ret", GPR32Opnd>, MTLO_FM<8>;
1073 // Exception handling related node and instructions.
1074 // The conversion sequence is:
1075 // ISD::EH_RETURN -> MipsISD::EH_RETURN ->
1076 // MIPSeh_return -> (stack change + indirect branch)
1078 // MIPSeh_return takes the place of regular return instruction
1079 // but takes two arguments (V1, V0) which are used for storing
1080 // the offset and return address respectively.
1081 def SDT_MipsEHRET : SDTypeProfile<0, 2, [SDTCisInt<0>, SDTCisPtrTy<1>]>;
1083 def MIPSehret : SDNode<"MipsISD::EH_RETURN", SDT_MipsEHRET,
1084 [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
1086 let Uses = [V0, V1], isTerminator = 1, isReturn = 1, isBarrier = 1 in {
1087 def MIPSeh_return32 : MipsPseudo<(outs), (ins GPR32:$spoff, GPR32:$dst),
1088 [(MIPSehret GPR32:$spoff, GPR32:$dst)]>;
1089 def MIPSeh_return64 : MipsPseudo<(outs), (ins GPR64:$spoff,
1091 [(MIPSehret GPR64:$spoff, GPR64:$dst)]>;
1094 /// Multiply and Divide Instructions.
1095 def MULT : MMRel, Mult<"mult", II_MULT, GPR32Opnd, [HI0, LO0]>,
1097 def MULTu : MMRel, Mult<"multu", II_MULTU, GPR32Opnd, [HI0, LO0]>,
1099 def SDIV : MMRel, Div<"div", II_DIV, GPR32Opnd, [HI0, LO0]>,
1101 def UDIV : MMRel, Div<"divu", II_DIVU, GPR32Opnd, [HI0, LO0]>,
1104 def MTHI : MMRel, MoveToLOHI<"mthi", GPR32Opnd, [HI0]>, MTLO_FM<0x11>;
1105 def MTLO : MMRel, MoveToLOHI<"mtlo", GPR32Opnd, [LO0]>, MTLO_FM<0x13>;
1106 let Predicates = [NotInMicroMips] in {
1107 def MFHI : MMRel, MoveFromLOHI<"mfhi", GPR32Opnd, AC0>, MFLO_FM<0x10>;
1108 def MFLO : MMRel, MoveFromLOHI<"mflo", GPR32Opnd, AC0>, MFLO_FM<0x12>;
1111 /// Sign Ext In Register Instructions.
1112 def SEB : MMRel, SignExtInReg<"seb", i8, GPR32Opnd, II_SEB>, SEB_FM<0x10, 0x20>;
1113 def SEH : MMRel, SignExtInReg<"seh", i16, GPR32Opnd, II_SEH>, SEB_FM<0x18, 0x20>;
1116 def CLZ : MMRel, CountLeading0<"clz", GPR32Opnd>, CLO_FM<0x20>;
1117 def CLO : MMRel, CountLeading1<"clo", GPR32Opnd>, CLO_FM<0x21>;
1119 /// Word Swap Bytes Within Halfwords
1120 def WSBH : MMRel, SubwordSwap<"wsbh", GPR32Opnd>, SEB_FM<2, 0x20>;
1123 def NOP : PseudoSE<(outs), (ins), []>, PseudoInstExpansion<(SLL ZERO, ZERO, 0)>;
1125 // FrameIndexes are legalized when they are operands from load/store
1126 // instructions. The same not happens for stack address copies, so an
1127 // add op with mem ComplexPattern is used and the stack address copy
1128 // can be matched. It's similar to Sparc LEA_ADDRi
1129 def LEA_ADDiu : MMRel, EffectiveAddress<"addiu", GPR32Opnd>, LW_FM<9>;
1132 def MADD : MMRel, MArithR<"madd", II_MADD, 1>, MULT_FM<0x1c, 0>;
1133 def MADDU : MMRel, MArithR<"maddu", II_MADDU, 1>, MULT_FM<0x1c, 1>;
1134 def MSUB : MMRel, MArithR<"msub", II_MSUB>, MULT_FM<0x1c, 4>;
1135 def MSUBU : MMRel, MArithR<"msubu", II_MSUBU>, MULT_FM<0x1c, 5>;
1137 let Predicates = [HasStdEnc, NotDSP] in {
1138 def PseudoMULT : MultDivPseudo<MULT, ACC64, GPR32Opnd, MipsMult, II_MULT>;
1139 def PseudoMULTu : MultDivPseudo<MULTu, ACC64, GPR32Opnd, MipsMultu, II_MULTU>;
1140 def PseudoMFHI : PseudoMFLOHI<GPR32, ACC64, MipsMFHI>;
1141 def PseudoMFLO : PseudoMFLOHI<GPR32, ACC64, MipsMFLO>;
1142 def PseudoMTLOHI : PseudoMTLOHI<ACC64, GPR32>;
1143 def PseudoMADD : MAddSubPseudo<MADD, MipsMAdd, II_MADD>;
1144 def PseudoMADDU : MAddSubPseudo<MADDU, MipsMAddu, II_MADDU>;
1145 def PseudoMSUB : MAddSubPseudo<MSUB, MipsMSub, II_MSUB>;
1146 def PseudoMSUBU : MAddSubPseudo<MSUBU, MipsMSubu, II_MSUBU>;
1149 def PseudoSDIV : MultDivPseudo<SDIV, ACC64, GPR32Opnd, MipsDivRem, II_DIV,
1151 def PseudoUDIV : MultDivPseudo<UDIV, ACC64, GPR32Opnd, MipsDivRemU, II_DIVU,
1154 def RDHWR : ReadHardware<GPR32Opnd, HWRegsOpnd>, RDHWR_FM;
1156 def EXT : MMRel, ExtBase<"ext", GPR32Opnd, uimm5, MipsExt>, EXT_FM<0>;
1157 def INS : MMRel, InsBase<"ins", GPR32Opnd, uimm5, MipsIns>, EXT_FM<4>;
1159 /// Move Control Registers From/To CPU Registers
1160 def MFC0 : MFC3OP<"mfc0", GPR32Opnd>, MFC3OP_FM<0x10, 0>;
1161 def MTC0 : MFC3OP<"mtc0", GPR32Opnd>, MFC3OP_FM<0x10, 4>;
1162 def MFC2 : MFC3OP<"mfc2", GPR32Opnd>, MFC3OP_FM<0x12, 0>;
1163 def MTC2 : MFC3OP<"mtc2", GPR32Opnd>, MFC3OP_FM<0x12, 4>;
1165 class Barrier<string asmstr> : InstSE<(outs), (ins), asmstr, [], NoItinerary,
1167 def SSNOP : Barrier<"ssnop">, BARRIER_FM<1>;
1168 def EHB : Barrier<"ehb">, BARRIER_FM<3>;
1169 def PAUSE : Barrier<"pause">, BARRIER_FM<5>, Requires<[HasMips32r2]>;
1171 //===----------------------------------------------------------------------===//
1172 // Instruction aliases
1173 //===----------------------------------------------------------------------===//
1174 def : InstAlias<"move $dst, $src",
1175 (ADDu GPR32Opnd:$dst, GPR32Opnd:$src,ZERO), 1>,
1176 Requires<[IsGP32, NotInMicroMips]>;
1177 def : InstAlias<"bal $offset", (BGEZAL ZERO, brtarget:$offset), 0>;
1178 def : InstAlias<"addu $rs, $rt, $imm",
1179 (ADDiu GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm), 0>;
1180 def : InstAlias<"add $rs, $rt, $imm",
1181 (ADDi GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm), 0>;
1182 def : InstAlias<"and $rs, $rt, $imm",
1183 (ANDi GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm), 0>;
1184 def : InstAlias<"j $rs", (JR GPR32Opnd:$rs), 0>;
1185 let Predicates = [NotInMicroMips] in {
1186 def : InstAlias<"jalr $rs", (JALR RA, GPR32Opnd:$rs), 0>;
1188 def : InstAlias<"jal $rs", (JALR RA, GPR32Opnd:$rs), 0>;
1189 def : InstAlias<"jal $rd,$rs", (JALR GPR32Opnd:$rd, GPR32Opnd:$rs), 0>;
1190 def : InstAlias<"not $rt, $rs",
1191 (NOR GPR32Opnd:$rt, GPR32Opnd:$rs, ZERO), 0>;
1192 def : InstAlias<"neg $rt, $rs",
1193 (SUB GPR32Opnd:$rt, ZERO, GPR32Opnd:$rs), 1>;
1194 def : InstAlias<"negu $rt, $rs",
1195 (SUBu GPR32Opnd:$rt, ZERO, GPR32Opnd:$rs), 1>;
1196 def : InstAlias<"slt $rs, $rt, $imm",
1197 (SLTi GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm), 0>;
1198 def : InstAlias<"xor $rs, $rt, $imm",
1199 (XORi GPR32Opnd:$rs, GPR32Opnd:$rt, uimm16:$imm), 0>;
1200 def : InstAlias<"or $rs, $rt, $imm",
1201 (ORi GPR32Opnd:$rs, GPR32Opnd:$rt, uimm16:$imm), 0>;
1202 def : InstAlias<"nop", (SLL ZERO, ZERO, 0), 1>;
1203 def : InstAlias<"mfc0 $rt, $rd", (MFC0 GPR32Opnd:$rt, GPR32Opnd:$rd, 0), 0>;
1204 def : InstAlias<"mtc0 $rt, $rd", (MTC0 GPR32Opnd:$rt, GPR32Opnd:$rd, 0), 0>;
1205 def : InstAlias<"mfc2 $rt, $rd", (MFC2 GPR32Opnd:$rt, GPR32Opnd:$rd, 0), 0>;
1206 def : InstAlias<"mtc2 $rt, $rd", (MTC2 GPR32Opnd:$rt, GPR32Opnd:$rd, 0), 0>;
1207 def : InstAlias<"b $offset", (BEQ ZERO, ZERO, brtarget:$offset), 0>;
1208 def : InstAlias<"bnez $rs,$offset",
1209 (BNE GPR32Opnd:$rs, ZERO, brtarget:$offset), 0>;
1210 def : InstAlias<"beqz $rs,$offset",
1211 (BEQ GPR32Opnd:$rs, ZERO, brtarget:$offset), 0>;
1212 def : InstAlias<"syscall", (SYSCALL 0), 1>;
1214 def : InstAlias<"break $imm", (BREAK uimm10:$imm, 0), 1>;
1215 def : InstAlias<"break", (BREAK 0, 0), 1>;
1216 def : InstAlias<"ei", (EI ZERO), 1>;
1217 def : InstAlias<"di", (DI ZERO), 1>;
1219 def : InstAlias<"teq $rs, $rt", (TEQ GPR32Opnd:$rs, GPR32Opnd:$rt, 0), 1>;
1220 def : InstAlias<"tge $rs, $rt", (TGE GPR32Opnd:$rs, GPR32Opnd:$rt, 0), 1>;
1221 def : InstAlias<"tgeu $rs, $rt", (TGEU GPR32Opnd:$rs, GPR32Opnd:$rt, 0), 1>;
1222 def : InstAlias<"tlt $rs, $rt", (TLT GPR32Opnd:$rs, GPR32Opnd:$rt, 0), 1>;
1223 def : InstAlias<"tltu $rs, $rt", (TLTU GPR32Opnd:$rs, GPR32Opnd:$rt, 0), 1>;
1224 def : InstAlias<"tne $rs, $rt", (TNE GPR32Opnd:$rs, GPR32Opnd:$rt, 0), 1>;
1225 def : InstAlias<"sub, $rd, $rs, $imm",
1226 (ADDi GPR32Opnd:$rd, GPR32Opnd:$rs, InvertedImOperand:$imm)>;
1227 def : InstAlias<"subu, $rd, $rs, $imm",
1228 (ADDiu GPR32Opnd:$rd, GPR32Opnd:$rs, InvertedImOperand:$imm)>;
1230 //===----------------------------------------------------------------------===//
1231 // Assembler Pseudo Instructions
1232 //===----------------------------------------------------------------------===//
1234 class LoadImm32< string instr_asm, Operand Od, RegisterOperand RO> :
1235 MipsAsmPseudoInst<(outs RO:$rt), (ins Od:$imm32),
1236 !strconcat(instr_asm, "\t$rt, $imm32")> ;
1237 def LoadImm32Reg : LoadImm32<"li", uimm5, GPR32Opnd>;
1239 class LoadAddress<string instr_asm, Operand MemOpnd, RegisterOperand RO> :
1240 MipsAsmPseudoInst<(outs RO:$rt), (ins MemOpnd:$addr),
1241 !strconcat(instr_asm, "\t$rt, $addr")> ;
1242 def LoadAddr32Reg : LoadAddress<"la", mem, GPR32Opnd>;
1244 class LoadAddressImm<string instr_asm, Operand Od, RegisterOperand RO> :
1245 MipsAsmPseudoInst<(outs RO:$rt), (ins Od:$imm32),
1246 !strconcat(instr_asm, "\t$rt, $imm32")> ;
1247 def LoadAddr32Imm : LoadAddressImm<"la", uimm5, GPR32Opnd>;
1249 //===----------------------------------------------------------------------===//
1250 // Arbitrary patterns that map to one or more instructions
1251 //===----------------------------------------------------------------------===//
1253 // Load/store pattern templates.
1254 class LoadRegImmPat<Instruction LoadInst, ValueType ValTy, PatFrag Node> :
1255 MipsPat<(ValTy (Node addrRegImm:$a)), (LoadInst addrRegImm:$a)>;
1257 class StoreRegImmPat<Instruction StoreInst, ValueType ValTy> :
1258 MipsPat<(store ValTy:$v, addrRegImm:$a), (StoreInst ValTy:$v, addrRegImm:$a)>;
1261 def : MipsPat<(i32 immSExt16:$in),
1262 (ADDiu ZERO, imm:$in)>;
1263 def : MipsPat<(i32 immZExt16:$in),
1264 (ORi ZERO, imm:$in)>;
1265 def : MipsPat<(i32 immLow16Zero:$in),
1266 (LUi (HI16 imm:$in))>;
1268 // Arbitrary immediates
1269 def : MipsPat<(i32 imm:$imm),
1270 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
1272 // Carry MipsPatterns
1273 def : MipsPat<(subc GPR32:$lhs, GPR32:$rhs),
1274 (SUBu GPR32:$lhs, GPR32:$rhs)>;
1275 let Predicates = [HasStdEnc, NotDSP] in {
1276 def : MipsPat<(addc GPR32:$lhs, GPR32:$rhs),
1277 (ADDu GPR32:$lhs, GPR32:$rhs)>;
1278 def : MipsPat<(addc GPR32:$src, immSExt16:$imm),
1279 (ADDiu GPR32:$src, imm:$imm)>;
1283 def : MipsPat<(MipsJmpLink (i32 tglobaladdr:$dst)),
1284 (JAL tglobaladdr:$dst)>;
1285 def : MipsPat<(MipsJmpLink (i32 texternalsym:$dst)),
1286 (JAL texternalsym:$dst)>;
1287 //def : MipsPat<(MipsJmpLink GPR32:$dst),
1288 // (JALR GPR32:$dst)>;
1291 def : MipsPat<(MipsTailCall (iPTR tglobaladdr:$dst)),
1292 (TAILCALL tglobaladdr:$dst)>;
1293 def : MipsPat<(MipsTailCall (iPTR texternalsym:$dst)),
1294 (TAILCALL texternalsym:$dst)>;
1296 def : MipsPat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
1297 def : MipsPat<(MipsHi tblockaddress:$in), (LUi tblockaddress:$in)>;
1298 def : MipsPat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
1299 def : MipsPat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
1300 def : MipsPat<(MipsHi tglobaltlsaddr:$in), (LUi tglobaltlsaddr:$in)>;
1301 def : MipsPat<(MipsHi texternalsym:$in), (LUi texternalsym:$in)>;
1303 def : MipsPat<(MipsLo tglobaladdr:$in), (ADDiu ZERO, tglobaladdr:$in)>;
1304 def : MipsPat<(MipsLo tblockaddress:$in), (ADDiu ZERO, tblockaddress:$in)>;
1305 def : MipsPat<(MipsLo tjumptable:$in), (ADDiu ZERO, tjumptable:$in)>;
1306 def : MipsPat<(MipsLo tconstpool:$in), (ADDiu ZERO, tconstpool:$in)>;
1307 def : MipsPat<(MipsLo tglobaltlsaddr:$in), (ADDiu ZERO, tglobaltlsaddr:$in)>;
1308 def : MipsPat<(MipsLo texternalsym:$in), (ADDiu ZERO, texternalsym:$in)>;
1310 def : MipsPat<(add GPR32:$hi, (MipsLo tglobaladdr:$lo)),
1311 (ADDiu GPR32:$hi, tglobaladdr:$lo)>;
1312 def : MipsPat<(add GPR32:$hi, (MipsLo tblockaddress:$lo)),
1313 (ADDiu GPR32:$hi, tblockaddress:$lo)>;
1314 def : MipsPat<(add GPR32:$hi, (MipsLo tjumptable:$lo)),
1315 (ADDiu GPR32:$hi, tjumptable:$lo)>;
1316 def : MipsPat<(add GPR32:$hi, (MipsLo tconstpool:$lo)),
1317 (ADDiu GPR32:$hi, tconstpool:$lo)>;
1318 def : MipsPat<(add GPR32:$hi, (MipsLo tglobaltlsaddr:$lo)),
1319 (ADDiu GPR32:$hi, tglobaltlsaddr:$lo)>;
1322 def : MipsPat<(add GPR32:$gp, (MipsGPRel tglobaladdr:$in)),
1323 (ADDiu GPR32:$gp, tglobaladdr:$in)>;
1324 def : MipsPat<(add GPR32:$gp, (MipsGPRel tconstpool:$in)),
1325 (ADDiu GPR32:$gp, tconstpool:$in)>;
1328 class WrapperPat<SDNode node, Instruction ADDiuOp, RegisterClass RC>:
1329 MipsPat<(MipsWrapper RC:$gp, node:$in),
1330 (ADDiuOp RC:$gp, node:$in)>;
1332 def : WrapperPat<tglobaladdr, ADDiu, GPR32>;
1333 def : WrapperPat<tconstpool, ADDiu, GPR32>;
1334 def : WrapperPat<texternalsym, ADDiu, GPR32>;
1335 def : WrapperPat<tblockaddress, ADDiu, GPR32>;
1336 def : WrapperPat<tjumptable, ADDiu, GPR32>;
1337 def : WrapperPat<tglobaltlsaddr, ADDiu, GPR32>;
1339 // Mips does not have "not", so we expand our way
1340 def : MipsPat<(not GPR32:$in),
1341 (NOR GPR32Opnd:$in, ZERO)>;
1344 let Predicates = [HasStdEnc] in {
1345 def : MipsPat<(i32 (extloadi1 addr:$src)), (LBu addr:$src)>;
1346 def : MipsPat<(i32 (extloadi8 addr:$src)), (LBu addr:$src)>;
1347 def : MipsPat<(i32 (extloadi16 addr:$src)), (LHu addr:$src)>;
1351 let Predicates = [HasStdEnc] in
1352 def : MipsPat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
1355 multiclass BrcondPats<RegisterClass RC, Instruction BEQOp, Instruction BNEOp,
1356 Instruction SLTOp, Instruction SLTuOp, Instruction SLTiOp,
1357 Instruction SLTiuOp, Register ZEROReg> {
1358 def : MipsPat<(brcond (i32 (setne RC:$lhs, 0)), bb:$dst),
1359 (BNEOp RC:$lhs, ZEROReg, bb:$dst)>;
1360 def : MipsPat<(brcond (i32 (seteq RC:$lhs, 0)), bb:$dst),
1361 (BEQOp RC:$lhs, ZEROReg, bb:$dst)>;
1363 def : MipsPat<(brcond (i32 (setge RC:$lhs, RC:$rhs)), bb:$dst),
1364 (BEQ (SLTOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>;
1365 def : MipsPat<(brcond (i32 (setuge RC:$lhs, RC:$rhs)), bb:$dst),
1366 (BEQ (SLTuOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>;
1367 def : MipsPat<(brcond (i32 (setge RC:$lhs, immSExt16:$rhs)), bb:$dst),
1368 (BEQ (SLTiOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
1369 def : MipsPat<(brcond (i32 (setuge RC:$lhs, immSExt16:$rhs)), bb:$dst),
1370 (BEQ (SLTiuOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
1371 def : MipsPat<(brcond (i32 (setgt RC:$lhs, immSExt16Plus1:$rhs)), bb:$dst),
1372 (BEQ (SLTiOp RC:$lhs, (Plus1 imm:$rhs)), ZERO, bb:$dst)>;
1373 def : MipsPat<(brcond (i32 (setugt RC:$lhs, immSExt16Plus1:$rhs)), bb:$dst),
1374 (BEQ (SLTiuOp RC:$lhs, (Plus1 imm:$rhs)), ZERO, bb:$dst)>;
1376 def : MipsPat<(brcond (i32 (setle RC:$lhs, RC:$rhs)), bb:$dst),
1377 (BEQ (SLTOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>;
1378 def : MipsPat<(brcond (i32 (setule RC:$lhs, RC:$rhs)), bb:$dst),
1379 (BEQ (SLTuOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>;
1381 def : MipsPat<(brcond RC:$cond, bb:$dst),
1382 (BNEOp RC:$cond, ZEROReg, bb:$dst)>;
1385 defm : BrcondPats<GPR32, BEQ, BNE, SLT, SLTu, SLTi, SLTiu, ZERO>;
1387 def : MipsPat<(brcond (i32 (setlt i32:$lhs, 1)), bb:$dst),
1388 (BLEZ i32:$lhs, bb:$dst)>;
1389 def : MipsPat<(brcond (i32 (setgt i32:$lhs, -1)), bb:$dst),
1390 (BGEZ i32:$lhs, bb:$dst)>;
1393 multiclass SeteqPats<RegisterClass RC, Instruction SLTiuOp, Instruction XOROp,
1394 Instruction SLTuOp, Register ZEROReg> {
1395 def : MipsPat<(seteq RC:$lhs, 0),
1396 (SLTiuOp RC:$lhs, 1)>;
1397 def : MipsPat<(setne RC:$lhs, 0),
1398 (SLTuOp ZEROReg, RC:$lhs)>;
1399 def : MipsPat<(seteq RC:$lhs, RC:$rhs),
1400 (SLTiuOp (XOROp RC:$lhs, RC:$rhs), 1)>;
1401 def : MipsPat<(setne RC:$lhs, RC:$rhs),
1402 (SLTuOp ZEROReg, (XOROp RC:$lhs, RC:$rhs))>;
1405 multiclass SetlePats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
1406 def : MipsPat<(setle RC:$lhs, RC:$rhs),
1407 (XORi (SLTOp RC:$rhs, RC:$lhs), 1)>;
1408 def : MipsPat<(setule RC:$lhs, RC:$rhs),
1409 (XORi (SLTuOp RC:$rhs, RC:$lhs), 1)>;
1412 multiclass SetgtPats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
1413 def : MipsPat<(setgt RC:$lhs, RC:$rhs),
1414 (SLTOp RC:$rhs, RC:$lhs)>;
1415 def : MipsPat<(setugt RC:$lhs, RC:$rhs),
1416 (SLTuOp RC:$rhs, RC:$lhs)>;
1419 multiclass SetgePats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
1420 def : MipsPat<(setge RC:$lhs, RC:$rhs),
1421 (XORi (SLTOp RC:$lhs, RC:$rhs), 1)>;
1422 def : MipsPat<(setuge RC:$lhs, RC:$rhs),
1423 (XORi (SLTuOp RC:$lhs, RC:$rhs), 1)>;
1426 multiclass SetgeImmPats<RegisterClass RC, Instruction SLTiOp,
1427 Instruction SLTiuOp> {
1428 def : MipsPat<(setge RC:$lhs, immSExt16:$rhs),
1429 (XORi (SLTiOp RC:$lhs, immSExt16:$rhs), 1)>;
1430 def : MipsPat<(setuge RC:$lhs, immSExt16:$rhs),
1431 (XORi (SLTiuOp RC:$lhs, immSExt16:$rhs), 1)>;
1434 defm : SeteqPats<GPR32, SLTiu, XOR, SLTu, ZERO>;
1435 defm : SetlePats<GPR32, SLT, SLTu>;
1436 defm : SetgtPats<GPR32, SLT, SLTu>;
1437 defm : SetgePats<GPR32, SLT, SLTu>;
1438 defm : SetgeImmPats<GPR32, SLTi, SLTiu>;
1441 def : MipsPat<(bswap GPR32:$rt), (ROTR (WSBH GPR32:$rt), 16)>;
1443 // Load halfword/word patterns.
1444 let AddedComplexity = 40 in {
1445 let Predicates = [HasStdEnc] in {
1446 def : LoadRegImmPat<LBu, i32, zextloadi8>;
1447 def : LoadRegImmPat<LH, i32, sextloadi16>;
1448 def : LoadRegImmPat<LW, i32, load>;
1452 //===----------------------------------------------------------------------===//
1453 // Floating Point Support
1454 //===----------------------------------------------------------------------===//
1456 include "MipsInstrFPU.td"
1457 include "Mips64InstrInfo.td"
1458 include "MipsCondMov.td"
1463 include "Mips16InstrFormats.td"
1464 include "Mips16InstrInfo.td"
1467 include "MipsDSPInstrFormats.td"
1468 include "MipsDSPInstrInfo.td"
1471 include "MipsMSAInstrFormats.td"
1472 include "MipsMSAInstrInfo.td"
1475 include "MicroMipsInstrFormats.td"
1476 include "MicroMipsInstrInfo.td"
1477 include "MicroMipsInstrFPU.td"