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 HasMips2 : Predicate<"Subtarget.hasMips2()">,
150 AssemblerPredicate<"FeatureMips2">;
151 def HasMips3_32 : Predicate<"Subtarget.hasMips3_32()">,
152 AssemblerPredicate<"FeatureMips3_32">;
153 def HasMips3 : Predicate<"Subtarget.hasMips3()">,
154 AssemblerPredicate<"FeatureMips3">;
155 def HasMips4_32 : Predicate<"Subtarget.hasMips4_32()">,
156 AssemblerPredicate<"FeatureMips4_32">;
157 def HasMips4_32r2 : Predicate<"Subtarget.hasMips4_32r2()">,
158 AssemblerPredicate<"FeatureMips4_32r2">;
159 def HasMips5_32r2 : Predicate<"Subtarget.hasMips5_32r2()">,
160 AssemblerPredicate<"FeatureMips5_32r2">;
161 def HasMips32 : Predicate<"Subtarget.hasMips32()">,
162 AssemblerPredicate<"FeatureMips32">;
163 def HasMips32r2 : Predicate<"Subtarget.hasMips32r2()">,
164 AssemblerPredicate<"FeatureMips32r2">;
165 def HasMips32r6 : Predicate<"Subtarget.hasMips32r6()">,
166 AssemblerPredicate<"FeatureMips32r6">;
167 def IsGP64bit : Predicate<"Subtarget.isGP64bit()">,
168 AssemblerPredicate<"FeatureGP64Bit">;
169 def IsGP32bit : Predicate<"!Subtarget.isGP64bit()">,
170 AssemblerPredicate<"!FeatureGP64Bit">;
171 def HasMips64 : Predicate<"Subtarget.hasMips64()">,
172 AssemblerPredicate<"FeatureMips64">;
173 def IsGP32 : Predicate<"!Subtarget.isGP64()">,
174 AssemblerPredicate<"!FeatureGP64Bit">;
175 def IsGP64 : Predicate<"Subtarget.isGP64()">,
176 AssemblerPredicate<"FeatureGP64Bit">;
177 def HasMips64r2 : Predicate<"Subtarget.hasMips64r2()">,
178 AssemblerPredicate<"FeatureMips64r2">;
179 def HasMips64r6 : Predicate<"Subtarget.hasMips64r6()">,
180 AssemblerPredicate<"FeatureMips64r6">;
181 def IsN64 : Predicate<"Subtarget.isABI_N64()">,
182 AssemblerPredicate<"FeatureN64">;
183 def InMips16Mode : Predicate<"Subtarget.inMips16Mode()">,
184 AssemblerPredicate<"FeatureMips16">;
185 def HasCnMips : Predicate<"Subtarget.hasCnMips()">,
186 AssemblerPredicate<"FeatureCnMips">;
187 def RelocStatic : Predicate<"TM.getRelocationModel() == Reloc::Static">,
188 AssemblerPredicate<"FeatureMips32">;
189 def RelocPIC : Predicate<"TM.getRelocationModel() == Reloc::PIC_">,
190 AssemblerPredicate<"FeatureMips32">;
191 def NoNaNsFPMath : Predicate<"TM.Options.NoNaNsFPMath">;
192 def HasStdEnc : Predicate<"Subtarget.hasStandardEncoding()">,
193 AssemblerPredicate<"!FeatureMips16">;
194 def NotDSP : Predicate<"!Subtarget.hasDSP()">;
195 def InMicroMips : Predicate<"Subtarget.inMicroMipsMode()">,
196 AssemblerPredicate<"FeatureMicroMips">;
197 def NotInMicroMips : Predicate<"!Subtarget.inMicroMipsMode()">,
198 AssemblerPredicate<"!FeatureMicroMips">;
199 def IsLE : Predicate<"Subtarget.isLittle()">;
200 def IsBE : Predicate<"!Subtarget.isLittle()">;
201 def IsNotNaCl : Predicate<"!Subtarget.isTargetNaCl()">;
203 //===----------------------------------------------------------------------===//
204 // Mips GPR size adjectives.
205 // They are mutually exclusive.
206 //===----------------------------------------------------------------------===//
208 class GPR_64 { list<Predicate> GPRPredicates = [IsGP64bit]; }
210 //===----------------------------------------------------------------------===//
211 // Mips ISA/ASE membership and instruction group membership adjectives.
212 // They are mutually exclusive.
213 //===----------------------------------------------------------------------===//
215 class ISA_MIPS2 { list<Predicate> InsnPredicates = [HasMips2]; }
216 class ISA_MIPS3 { list<Predicate> InsnPredicates = [HasMips3]; }
217 class ISA_MIPS32 { list<Predicate> InsnPredicates = [HasMips32]; }
218 class ISA_MIPS32R2 { list<Predicate> InsnPredicates = [HasMips32r2]; }
219 class ISA_MIPS64 { list<Predicate> InsnPredicates = [HasMips64]; }
220 class ISA_MIPS64R2 { list<Predicate> InsnPredicates = [HasMips64r2]; }
221 class ISA_MIPS32R6 { list<Predicate> InsnPredicates = [HasMips32r6]; }
222 class ISA_MIPS64R6 { list<Predicate> InsnPredicates = [HasMips64r6]; }
224 // The portions of MIPS-III that were also added to MIPS32
225 class INSN_MIPS3_32 { list<Predicate> InsnPredicates = [HasMips3_32]; }
227 // The portions of MIPS-IV that were also added to MIPS32
228 class INSN_MIPS4_32 { list<Predicate> InsnPredicates = [HasMips4_32]; }
230 // The portions of MIPS-IV that were also added to MIPS32R2
231 class INSN_MIPS4_32R2 { list<Predicate> InsnPredicates = [HasMips4_32r2]; }
233 // The portions of MIPS-V that were also added to MIPS32R2
234 class INSN_MIPS5_32R2 { list<Predicate> InsnPredicates = [HasMips5_32r2]; }
236 //===----------------------------------------------------------------------===//
238 class MipsPat<dag pattern, dag result> : Pat<pattern, result>, PredicateControl {
239 let EncodingPredicates = [HasStdEnc];
242 class MipsInstAlias<string Asm, dag Result, bit Emit = 0b1> :
243 InstAlias<Asm, Result, Emit>, PredicateControl;
246 bit isCommutable = 1;
263 bit isTerminator = 1;
266 bit hasExtraSrcRegAllocReq = 1;
267 bit isCodeGenOnly = 1;
270 class IsAsCheapAsAMove {
271 bit isAsCheapAsAMove = 1;
274 class NeverHasSideEffects {
275 bit neverHasSideEffects = 1;
278 //===----------------------------------------------------------------------===//
279 // Instruction format superclass
280 //===----------------------------------------------------------------------===//
282 include "MipsInstrFormats.td"
284 //===----------------------------------------------------------------------===//
285 // Mips Operand, Complex Patterns and Transformations Definitions.
286 //===----------------------------------------------------------------------===//
288 def MipsJumpTargetAsmOperand : AsmOperandClass {
289 let Name = "JumpTarget";
290 let ParserMethod = "ParseJumpTarget";
291 let PredicateMethod = "isImm";
292 let RenderMethod = "addImmOperands";
295 // Instruction operand types
296 def jmptarget : Operand<OtherVT> {
297 let EncoderMethod = "getJumpTargetOpValue";
298 let ParserMatchClass = MipsJumpTargetAsmOperand;
300 def brtarget : Operand<OtherVT> {
301 let EncoderMethod = "getBranchTargetOpValue";
302 let OperandType = "OPERAND_PCREL";
303 let DecoderMethod = "DecodeBranchTarget";
304 let ParserMatchClass = MipsJumpTargetAsmOperand;
306 def calltarget : Operand<iPTR> {
307 let EncoderMethod = "getJumpTargetOpValue";
308 let ParserMatchClass = MipsJumpTargetAsmOperand;
311 def simm10 : Operand<i32>;
313 def simm16 : Operand<i32> {
314 let DecoderMethod= "DecodeSimm16";
317 def simm20 : Operand<i32> {
320 def uimm20 : Operand<i32> {
323 def uimm10 : Operand<i32> {
326 def simm16_64 : Operand<i64> {
327 let DecoderMethod = "DecodeSimm16";
331 def uimmz : Operand<i32> {
332 let PrintMethod = "printUnsignedImm";
336 def uimm5 : Operand<i32> {
337 let PrintMethod = "printUnsignedImm";
340 def uimm6 : Operand<i32> {
341 let PrintMethod = "printUnsignedImm";
344 def uimm16 : Operand<i32> {
345 let PrintMethod = "printUnsignedImm";
348 def pcrel16 : Operand<i32> {
351 def MipsMemAsmOperand : AsmOperandClass {
353 let ParserMethod = "parseMemOperand";
356 def MipsInvertedImmoperand : AsmOperandClass {
358 let RenderMethod = "addImmOperands";
359 let ParserMethod = "parseInvNum";
362 def InvertedImOperand : Operand<i32> {
363 let ParserMatchClass = MipsInvertedImmoperand;
366 def InvertedImOperand64 : Operand<i64> {
367 let ParserMatchClass = MipsInvertedImmoperand;
370 class mem_generic : Operand<iPTR> {
371 let PrintMethod = "printMemOperand";
372 let MIOperandInfo = (ops ptr_rc, simm16);
373 let EncoderMethod = "getMemEncoding";
374 let ParserMatchClass = MipsMemAsmOperand;
375 let OperandType = "OPERAND_MEMORY";
379 def mem : mem_generic;
381 // MSA specific address operand
382 def mem_msa : mem_generic {
383 let MIOperandInfo = (ops ptr_rc, simm10);
384 let EncoderMethod = "getMSAMemEncoding";
387 def mem_ea : Operand<iPTR> {
388 let PrintMethod = "printMemOperandEA";
389 let MIOperandInfo = (ops ptr_rc, simm16);
390 let EncoderMethod = "getMemEncoding";
391 let OperandType = "OPERAND_MEMORY";
394 def PtrRC : Operand<iPTR> {
395 let MIOperandInfo = (ops ptr_rc);
396 let DecoderMethod = "DecodePtrRegisterClass";
397 let ParserMatchClass = GPR32AsmOperand;
400 // size operand of ext instruction
401 def size_ext : Operand<i32> {
402 let EncoderMethod = "getSizeExtEncoding";
403 let DecoderMethod = "DecodeExtSize";
406 // size operand of ins instruction
407 def size_ins : Operand<i32> {
408 let EncoderMethod = "getSizeInsEncoding";
409 let DecoderMethod = "DecodeInsSize";
412 // Transformation Function - get the lower 16 bits.
413 def LO16 : SDNodeXForm<imm, [{
414 return getImm(N, N->getZExtValue() & 0xFFFF);
417 // Transformation Function - get the higher 16 bits.
418 def HI16 : SDNodeXForm<imm, [{
419 return getImm(N, (N->getZExtValue() >> 16) & 0xFFFF);
423 def Plus1 : SDNodeXForm<imm, [{ return getImm(N, N->getSExtValue() + 1); }]>;
425 // Node immediate is zero (e.g. insve.d)
426 def immz : PatLeaf<(imm), [{ return N->getSExtValue() == 0; }]>;
428 // Node immediate fits as 16-bit sign extended on target immediate.
430 def immSExt8 : PatLeaf<(imm), [{ return isInt<8>(N->getSExtValue()); }]>;
432 // Node immediate fits as 16-bit sign extended on target immediate.
434 def immSExt16 : PatLeaf<(imm), [{ return isInt<16>(N->getSExtValue()); }]>;
436 // Node immediate fits as 15-bit sign extended on target immediate.
438 def immSExt15 : PatLeaf<(imm), [{ return isInt<15>(N->getSExtValue()); }]>;
440 // Node immediate fits as 16-bit zero extended on target immediate.
441 // The LO16 param means that only the lower 16 bits of the node
442 // immediate are caught.
444 def immZExt16 : PatLeaf<(imm), [{
445 if (N->getValueType(0) == MVT::i32)
446 return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
448 return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
451 // Immediate can be loaded with LUi (32-bit int with lower 16-bit cleared).
452 def immLow16Zero : PatLeaf<(imm), [{
453 int64_t Val = N->getSExtValue();
454 return isInt<32>(Val) && !(Val & 0xffff);
457 // shamt field must fit in 5 bits.
458 def immZExt5 : ImmLeaf<i32, [{return Imm == (Imm & 0x1f);}]>;
460 // True if (N + 1) fits in 16-bit field.
461 def immSExt16Plus1 : PatLeaf<(imm), [{
462 return isInt<17>(N->getSExtValue()) && isInt<16>(N->getSExtValue() + 1);
465 // Mips Address Mode! SDNode frameindex could possibily be a match
466 // since load and store instructions from stack used it.
468 ComplexPattern<iPTR, 2, "selectIntAddr", [frameindex]>;
471 ComplexPattern<iPTR, 2, "selectAddrRegImm", [frameindex]>;
474 ComplexPattern<iPTR, 2, "selectAddrRegReg", [frameindex]>;
477 ComplexPattern<iPTR, 2, "selectAddrDefault", [frameindex]>;
479 def addrimm10 : ComplexPattern<iPTR, 2, "selectIntAddrMSA", [frameindex]>;
481 //===----------------------------------------------------------------------===//
482 // Instructions specific format
483 //===----------------------------------------------------------------------===//
485 // Arithmetic and logical instructions with 3 register operands.
486 class ArithLogicR<string opstr, RegisterOperand RO, bit isComm = 0,
487 InstrItinClass Itin = NoItinerary,
488 SDPatternOperator OpNode = null_frag>:
489 InstSE<(outs RO:$rd), (ins RO:$rs, RO:$rt),
490 !strconcat(opstr, "\t$rd, $rs, $rt"),
491 [(set RO:$rd, (OpNode RO:$rs, RO:$rt))], Itin, FrmR, opstr> {
492 let isCommutable = isComm;
493 let isReMaterializable = 1;
494 let TwoOperandAliasConstraint = "$rd = $rs";
497 // Arithmetic and logical instructions with 2 register operands.
498 class ArithLogicI<string opstr, Operand Od, RegisterOperand RO,
499 InstrItinClass Itin = NoItinerary,
500 SDPatternOperator imm_type = null_frag,
501 SDPatternOperator OpNode = null_frag> :
502 InstSE<(outs RO:$rt), (ins RO:$rs, Od:$imm16),
503 !strconcat(opstr, "\t$rt, $rs, $imm16"),
504 [(set RO:$rt, (OpNode RO:$rs, imm_type:$imm16))],
506 let isReMaterializable = 1;
507 let TwoOperandAliasConstraint = "$rs = $rt";
510 // Arithmetic Multiply ADD/SUB
511 class MArithR<string opstr, InstrItinClass itin, bit isComm = 0> :
512 InstSE<(outs), (ins GPR32Opnd:$rs, GPR32Opnd:$rt),
513 !strconcat(opstr, "\t$rs, $rt"), [], itin, FrmR, opstr> {
514 let Defs = [HI0, LO0];
515 let Uses = [HI0, LO0];
516 let isCommutable = isComm;
520 class LogicNOR<string opstr, RegisterOperand RO>:
521 InstSE<(outs RO:$rd), (ins RO:$rs, RO:$rt),
522 !strconcat(opstr, "\t$rd, $rs, $rt"),
523 [(set RO:$rd, (not (or RO:$rs, RO:$rt)))], II_NOR, FrmR, opstr> {
524 let isCommutable = 1;
528 class shift_rotate_imm<string opstr, Operand ImmOpnd,
529 RegisterOperand RO, InstrItinClass itin,
530 SDPatternOperator OpNode = null_frag,
531 SDPatternOperator PF = null_frag> :
532 InstSE<(outs RO:$rd), (ins RO:$rt, ImmOpnd:$shamt),
533 !strconcat(opstr, "\t$rd, $rt, $shamt"),
534 [(set RO:$rd, (OpNode RO:$rt, PF:$shamt))], itin, FrmR, opstr> {
535 let TwoOperandAliasConstraint = "$rt = $rd";
538 class shift_rotate_reg<string opstr, RegisterOperand RO, InstrItinClass itin,
539 SDPatternOperator OpNode = null_frag>:
540 InstSE<(outs RO:$rd), (ins RO:$rt, GPR32Opnd:$rs),
541 !strconcat(opstr, "\t$rd, $rt, $rs"),
542 [(set RO:$rd, (OpNode RO:$rt, GPR32Opnd:$rs))], itin, FrmR,
545 // Load Upper Imediate
546 class LoadUpper<string opstr, RegisterOperand RO, Operand Imm>:
547 InstSE<(outs RO:$rt), (ins Imm:$imm16), !strconcat(opstr, "\t$rt, $imm16"),
548 [], II_LUI, FrmI, opstr>, IsAsCheapAsAMove {
549 let neverHasSideEffects = 1;
550 let isReMaterializable = 1;
554 class Load<string opstr, DAGOperand RO, SDPatternOperator OpNode = null_frag,
555 InstrItinClass Itin = NoItinerary, ComplexPattern Addr = addr> :
556 InstSE<(outs RO:$rt), (ins mem:$addr), !strconcat(opstr, "\t$rt, $addr"),
557 [(set RO:$rt, (OpNode Addr:$addr))], Itin, FrmI, opstr> {
558 let DecoderMethod = "DecodeMem";
559 let canFoldAsLoad = 1;
563 class Store<string opstr, DAGOperand RO, SDPatternOperator OpNode = null_frag,
564 InstrItinClass Itin = NoItinerary, ComplexPattern Addr = addr> :
565 InstSE<(outs), (ins RO:$rt, mem:$addr), !strconcat(opstr, "\t$rt, $addr"),
566 [(OpNode RO:$rt, Addr:$addr)], Itin, FrmI, opstr> {
567 let DecoderMethod = "DecodeMem";
571 // Load/Store Left/Right
572 let canFoldAsLoad = 1 in
573 class LoadLeftRight<string opstr, SDNode OpNode, RegisterOperand RO,
574 InstrItinClass Itin> :
575 InstSE<(outs RO:$rt), (ins mem:$addr, RO:$src),
576 !strconcat(opstr, "\t$rt, $addr"),
577 [(set RO:$rt, (OpNode addr:$addr, RO:$src))], Itin, FrmI> {
578 let DecoderMethod = "DecodeMem";
579 string Constraints = "$src = $rt";
582 class StoreLeftRight<string opstr, SDNode OpNode, RegisterOperand RO,
583 InstrItinClass Itin> :
584 InstSE<(outs), (ins RO:$rt, mem:$addr), !strconcat(opstr, "\t$rt, $addr"),
585 [(OpNode RO:$rt, addr:$addr)], Itin, FrmI> {
586 let DecoderMethod = "DecodeMem";
589 // Conditional Branch
590 class CBranch<string opstr, DAGOperand opnd, PatFrag cond_op,
591 RegisterOperand RO> :
592 InstSE<(outs), (ins RO:$rs, RO:$rt, opnd:$offset),
593 !strconcat(opstr, "\t$rs, $rt, $offset"),
594 [(brcond (i32 (cond_op RO:$rs, RO:$rt)), bb:$offset)], IIBranch,
597 let isTerminator = 1;
598 let hasDelaySlot = 1;
602 class CBranchZero<string opstr, DAGOperand opnd, PatFrag cond_op,
603 RegisterOperand RO> :
604 InstSE<(outs), (ins RO:$rs, opnd:$offset),
605 !strconcat(opstr, "\t$rs, $offset"),
606 [(brcond (i32 (cond_op RO:$rs, 0)), bb:$offset)], IIBranch,
609 let isTerminator = 1;
610 let hasDelaySlot = 1;
615 class SetCC_R<string opstr, PatFrag cond_op, RegisterOperand RO> :
616 InstSE<(outs GPR32Opnd:$rd), (ins RO:$rs, RO:$rt),
617 !strconcat(opstr, "\t$rd, $rs, $rt"),
618 [(set GPR32Opnd:$rd, (cond_op RO:$rs, RO:$rt))],
619 II_SLT_SLTU, FrmR, opstr>;
621 class SetCC_I<string opstr, PatFrag cond_op, Operand Od, PatLeaf imm_type,
623 InstSE<(outs GPR32Opnd:$rt), (ins RO:$rs, Od:$imm16),
624 !strconcat(opstr, "\t$rt, $rs, $imm16"),
625 [(set GPR32Opnd:$rt, (cond_op RO:$rs, imm_type:$imm16))],
626 II_SLTI_SLTIU, FrmI, opstr>;
629 class JumpFJ<DAGOperand opnd, string opstr, SDPatternOperator operator,
630 SDPatternOperator targetoperator, string bopstr> :
631 InstSE<(outs), (ins opnd:$target), !strconcat(opstr, "\t$target"),
632 [(operator targetoperator:$target)], IIBranch, FrmJ, bopstr> {
635 let hasDelaySlot = 1;
636 let DecoderMethod = "DecodeJumpTarget";
640 // Unconditional branch
641 class UncondBranch<Instruction BEQInst> :
642 PseudoSE<(outs), (ins brtarget:$offset), [(br bb:$offset)], IIBranch>,
643 PseudoInstExpansion<(BEQInst ZERO, ZERO, brtarget:$offset)> {
645 let isTerminator = 1;
647 let hasDelaySlot = 1;
648 let AdditionalPredicates = [RelocPIC];
652 // Base class for indirect branch and return instruction classes.
653 let isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
654 class JumpFR<string opstr, RegisterOperand RO,
655 SDPatternOperator operator = null_frag>:
656 InstSE<(outs), (ins RO:$rs), "jr\t$rs", [(operator RO:$rs)], IIBranch,
660 class IndirectBranch<string opstr, RegisterOperand RO> :
661 JumpFR<opstr, RO, brind> {
663 let isIndirectBranch = 1;
666 // Return instruction
667 class RetBase<string opstr, RegisterOperand RO>: JumpFR<opstr, RO> {
669 let isCodeGenOnly = 1;
671 let hasExtraSrcRegAllocReq = 1;
674 // Jump and Link (Call)
675 let isCall=1, hasDelaySlot=1, Defs = [RA] in {
676 class JumpLink<string opstr, DAGOperand opnd> :
677 InstSE<(outs), (ins opnd:$target), !strconcat(opstr, "\t$target"),
678 [(MipsJmpLink imm:$target)], IIBranch, FrmJ, opstr> {
679 let DecoderMethod = "DecodeJumpTarget";
682 class JumpLinkRegPseudo<RegisterOperand RO, Instruction JALRInst,
683 Register RetReg, RegisterOperand ResRO = RO>:
684 PseudoSE<(outs), (ins RO:$rs), [(MipsJmpLink RO:$rs)], IIBranch>,
685 PseudoInstExpansion<(JALRInst RetReg, ResRO:$rs)>;
687 class JumpLinkReg<string opstr, RegisterOperand RO>:
688 InstSE<(outs RO:$rd), (ins RO:$rs), !strconcat(opstr, "\t$rd, $rs"),
691 class BGEZAL_FT<string opstr, DAGOperand opnd, RegisterOperand RO> :
692 InstSE<(outs), (ins RO:$rs, opnd:$offset),
693 !strconcat(opstr, "\t$rs, $offset"), [], IIBranch, FrmI, opstr>;
697 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1, hasDelaySlot = 1,
698 hasExtraSrcRegAllocReq = 1, Defs = [AT] in {
699 class TailCall<Instruction JumpInst> :
700 PseudoSE<(outs), (ins calltarget:$target), [], IIBranch>,
701 PseudoInstExpansion<(JumpInst jmptarget:$target)>;
703 class TailCallReg<RegisterOperand RO, Instruction JRInst,
704 RegisterOperand ResRO = RO> :
705 PseudoSE<(outs), (ins RO:$rs), [(MipsTailCall RO:$rs)], IIBranch>,
706 PseudoInstExpansion<(JRInst ResRO:$rs)>;
709 class BAL_BR_Pseudo<Instruction RealInst> :
710 PseudoSE<(outs), (ins brtarget:$offset), [], IIBranch>,
711 PseudoInstExpansion<(RealInst ZERO, brtarget:$offset)> {
713 let isTerminator = 1;
715 let hasDelaySlot = 1;
720 class SYS_FT<string opstr> :
721 InstSE<(outs), (ins uimm20:$code_),
722 !strconcat(opstr, "\t$code_"), [], NoItinerary, FrmI, opstr>;
724 class BRK_FT<string opstr> :
725 InstSE<(outs), (ins uimm10:$code_1, uimm10:$code_2),
726 !strconcat(opstr, "\t$code_1, $code_2"), [], NoItinerary,
730 class ER_FT<string opstr> :
731 InstSE<(outs), (ins),
732 opstr, [], NoItinerary, FrmOther, opstr>;
735 class DEI_FT<string opstr, RegisterOperand RO> :
736 InstSE<(outs RO:$rt), (ins),
737 !strconcat(opstr, "\t$rt"), [], NoItinerary, FrmOther, opstr>;
740 class WAIT_FT<string opstr> :
741 InstSE<(outs), (ins), opstr, [], NoItinerary, FrmOther, opstr>;
744 let hasSideEffects = 1 in
745 class SYNC_FT<string opstr> :
746 InstSE<(outs), (ins i32imm:$stype), "sync $stype", [(MipsSync imm:$stype)],
747 NoItinerary, FrmOther, opstr>;
749 let hasSideEffects = 1 in
750 class TEQ_FT<string opstr, RegisterOperand RO> :
751 InstSE<(outs), (ins RO:$rs, RO:$rt, uimm16:$code_),
752 !strconcat(opstr, "\t$rs, $rt, $code_"), [], NoItinerary,
755 class TEQI_FT<string opstr, RegisterOperand RO> :
756 InstSE<(outs), (ins RO:$rs, uimm16:$imm16),
757 !strconcat(opstr, "\t$rs, $imm16"), [], NoItinerary, FrmOther, opstr>;
759 class Mult<string opstr, InstrItinClass itin, RegisterOperand RO,
760 list<Register> DefRegs> :
761 InstSE<(outs), (ins RO:$rs, RO:$rt), !strconcat(opstr, "\t$rs, $rt"), [],
763 let isCommutable = 1;
765 let neverHasSideEffects = 1;
768 // Pseudo multiply/divide instruction with explicit accumulator register
770 class MultDivPseudo<Instruction RealInst, RegisterClass R0, RegisterOperand R1,
771 SDPatternOperator OpNode, InstrItinClass Itin,
772 bit IsComm = 1, bit HasSideEffects = 0,
773 bit UsesCustomInserter = 0> :
774 PseudoSE<(outs R0:$ac), (ins R1:$rs, R1:$rt),
775 [(set R0:$ac, (OpNode R1:$rs, R1:$rt))], Itin>,
776 PseudoInstExpansion<(RealInst R1:$rs, R1:$rt)> {
777 let isCommutable = IsComm;
778 let hasSideEffects = HasSideEffects;
779 let usesCustomInserter = UsesCustomInserter;
782 // Pseudo multiply add/sub instruction with explicit accumulator register
784 class MAddSubPseudo<Instruction RealInst, SDPatternOperator OpNode,
786 : PseudoSE<(outs ACC64:$ac),
787 (ins GPR32Opnd:$rs, GPR32Opnd:$rt, ACC64:$acin),
789 (OpNode GPR32Opnd:$rs, GPR32Opnd:$rt, ACC64:$acin))],
791 PseudoInstExpansion<(RealInst GPR32Opnd:$rs, GPR32Opnd:$rt)> {
792 string Constraints = "$acin = $ac";
795 class Div<string opstr, InstrItinClass itin, RegisterOperand RO,
796 list<Register> DefRegs> :
797 InstSE<(outs), (ins RO:$rs, RO:$rt), !strconcat(opstr, "\t$$zero, $rs, $rt"),
798 [], itin, FrmR, opstr> {
803 class PseudoMFLOHI<RegisterClass DstRC, RegisterClass SrcRC, SDNode OpNode>
804 : PseudoSE<(outs DstRC:$rd), (ins SrcRC:$hilo),
805 [(set DstRC:$rd, (OpNode SrcRC:$hilo))], II_MFHI_MFLO>;
807 class MoveFromLOHI<string opstr, RegisterOperand RO, Register UseReg>:
808 InstSE<(outs RO:$rd), (ins), !strconcat(opstr, "\t$rd"), [], II_MFHI_MFLO,
811 let neverHasSideEffects = 1;
814 class PseudoMTLOHI<RegisterClass DstRC, RegisterClass SrcRC>
815 : PseudoSE<(outs DstRC:$lohi), (ins SrcRC:$lo, SrcRC:$hi),
816 [(set DstRC:$lohi, (MipsMTLOHI SrcRC:$lo, SrcRC:$hi))],
819 class MoveToLOHI<string opstr, RegisterOperand RO, list<Register> DefRegs>:
820 InstSE<(outs), (ins RO:$rs), !strconcat(opstr, "\t$rs"), [], II_MTHI_MTLO,
823 let neverHasSideEffects = 1;
826 class EffectiveAddress<string opstr, RegisterOperand RO> :
827 InstSE<(outs RO:$rt), (ins mem_ea:$addr), !strconcat(opstr, "\t$rt, $addr"),
828 [(set RO:$rt, addr:$addr)], NoItinerary, FrmI,
829 !strconcat(opstr, "_lea")> {
830 let isCodeGenOnly = 1;
831 let DecoderMethod = "DecodeMem";
834 // Count Leading Ones/Zeros in Word
835 class CountLeading0<string opstr, RegisterOperand RO>:
836 InstSE<(outs RO:$rd), (ins RO:$rs), !strconcat(opstr, "\t$rd, $rs"),
837 [(set RO:$rd, (ctlz RO:$rs))], II_CLZ, FrmR, opstr>;
839 class CountLeading1<string opstr, RegisterOperand RO>:
840 InstSE<(outs RO:$rd), (ins RO:$rs), !strconcat(opstr, "\t$rd, $rs"),
841 [(set RO:$rd, (ctlz (not RO:$rs)))], II_CLO, FrmR, opstr>;
843 // Sign Extend in Register.
844 class SignExtInReg<string opstr, ValueType vt, RegisterOperand RO,
845 InstrItinClass itin> :
846 InstSE<(outs RO:$rd), (ins RO:$rt), !strconcat(opstr, "\t$rd, $rt"),
847 [(set RO:$rd, (sext_inreg RO:$rt, vt))], itin, FrmR, opstr>;
850 class SubwordSwap<string opstr, RegisterOperand RO>:
851 InstSE<(outs RO:$rd), (ins RO:$rt), !strconcat(opstr, "\t$rd, $rt"), [],
852 NoItinerary, FrmR, opstr> {
853 let neverHasSideEffects = 1;
857 class ReadHardware<RegisterOperand CPURegOperand, RegisterOperand RO> :
858 InstSE<(outs CPURegOperand:$rt), (ins RO:$rd), "rdhwr\t$rt, $rd", [],
862 class ExtBase<string opstr, RegisterOperand RO, Operand PosOpnd,
863 SDPatternOperator Op = null_frag>:
864 InstSE<(outs RO:$rt), (ins RO:$rs, PosOpnd:$pos, size_ext:$size),
865 !strconcat(opstr, " $rt, $rs, $pos, $size"),
866 [(set RO:$rt, (Op RO:$rs, imm:$pos, imm:$size))], NoItinerary,
867 FrmR, opstr>, ISA_MIPS32R2;
869 class InsBase<string opstr, RegisterOperand RO, Operand PosOpnd,
870 SDPatternOperator Op = null_frag>:
871 InstSE<(outs RO:$rt), (ins RO:$rs, PosOpnd:$pos, size_ins:$size, RO:$src),
872 !strconcat(opstr, " $rt, $rs, $pos, $size"),
873 [(set RO:$rt, (Op RO:$rs, imm:$pos, imm:$size, RO:$src))],
874 NoItinerary, FrmR, opstr>, ISA_MIPS32R2 {
875 let Constraints = "$src = $rt";
878 // Atomic instructions with 2 source operands (ATOMIC_SWAP & ATOMIC_LOAD_*).
879 class Atomic2Ops<PatFrag Op, RegisterClass DRC> :
880 PseudoSE<(outs DRC:$dst), (ins PtrRC:$ptr, DRC:$incr),
881 [(set DRC:$dst, (Op iPTR:$ptr, DRC:$incr))]>;
883 // Atomic Compare & Swap.
884 class AtomicCmpSwap<PatFrag Op, RegisterClass DRC> :
885 PseudoSE<(outs DRC:$dst), (ins PtrRC:$ptr, DRC:$cmp, DRC:$swap),
886 [(set DRC:$dst, (Op iPTR:$ptr, DRC:$cmp, DRC:$swap))]>;
888 class LLBase<string opstr, RegisterOperand RO> :
889 InstSE<(outs RO:$rt), (ins mem:$addr), !strconcat(opstr, "\t$rt, $addr"),
890 [], NoItinerary, FrmI> {
891 let DecoderMethod = "DecodeMem";
895 class SCBase<string opstr, RegisterOperand RO> :
896 InstSE<(outs RO:$dst), (ins RO:$rt, mem:$addr),
897 !strconcat(opstr, "\t$rt, $addr"), [], NoItinerary, FrmI> {
898 let DecoderMethod = "DecodeMem";
900 let Constraints = "$rt = $dst";
903 class MFC3OP<string asmstr, RegisterOperand RO> :
904 InstSE<(outs RO:$rt, RO:$rd, uimm16:$sel), (ins),
905 !strconcat(asmstr, "\t$rt, $rd, $sel"), [], NoItinerary, FrmFR>;
907 class TrapBase<Instruction RealInst>
908 : PseudoSE<(outs), (ins), [(trap)], NoItinerary>,
909 PseudoInstExpansion<(RealInst 0, 0)> {
911 let isTerminator = 1;
912 let isCodeGenOnly = 1;
915 //===----------------------------------------------------------------------===//
916 // Pseudo instructions
917 //===----------------------------------------------------------------------===//
920 let isReturn=1, isTerminator=1, hasDelaySlot=1, isBarrier=1, hasCtrlDep=1 in
921 def RetRA : PseudoSE<(outs), (ins), [(MipsRet)]>;
923 let Defs = [SP], Uses = [SP], hasSideEffects = 1 in {
924 def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins i32imm:$amt),
925 [(callseq_start timm:$amt)]>;
926 def ADJCALLSTACKUP : MipsPseudo<(outs), (ins i32imm:$amt1, i32imm:$amt2),
927 [(callseq_end timm:$amt1, timm:$amt2)]>;
930 let usesCustomInserter = 1 in {
931 def ATOMIC_LOAD_ADD_I8 : Atomic2Ops<atomic_load_add_8, GPR32>;
932 def ATOMIC_LOAD_ADD_I16 : Atomic2Ops<atomic_load_add_16, GPR32>;
933 def ATOMIC_LOAD_ADD_I32 : Atomic2Ops<atomic_load_add_32, GPR32>;
934 def ATOMIC_LOAD_SUB_I8 : Atomic2Ops<atomic_load_sub_8, GPR32>;
935 def ATOMIC_LOAD_SUB_I16 : Atomic2Ops<atomic_load_sub_16, GPR32>;
936 def ATOMIC_LOAD_SUB_I32 : Atomic2Ops<atomic_load_sub_32, GPR32>;
937 def ATOMIC_LOAD_AND_I8 : Atomic2Ops<atomic_load_and_8, GPR32>;
938 def ATOMIC_LOAD_AND_I16 : Atomic2Ops<atomic_load_and_16, GPR32>;
939 def ATOMIC_LOAD_AND_I32 : Atomic2Ops<atomic_load_and_32, GPR32>;
940 def ATOMIC_LOAD_OR_I8 : Atomic2Ops<atomic_load_or_8, GPR32>;
941 def ATOMIC_LOAD_OR_I16 : Atomic2Ops<atomic_load_or_16, GPR32>;
942 def ATOMIC_LOAD_OR_I32 : Atomic2Ops<atomic_load_or_32, GPR32>;
943 def ATOMIC_LOAD_XOR_I8 : Atomic2Ops<atomic_load_xor_8, GPR32>;
944 def ATOMIC_LOAD_XOR_I16 : Atomic2Ops<atomic_load_xor_16, GPR32>;
945 def ATOMIC_LOAD_XOR_I32 : Atomic2Ops<atomic_load_xor_32, GPR32>;
946 def ATOMIC_LOAD_NAND_I8 : Atomic2Ops<atomic_load_nand_8, GPR32>;
947 def ATOMIC_LOAD_NAND_I16 : Atomic2Ops<atomic_load_nand_16, GPR32>;
948 def ATOMIC_LOAD_NAND_I32 : Atomic2Ops<atomic_load_nand_32, GPR32>;
950 def ATOMIC_SWAP_I8 : Atomic2Ops<atomic_swap_8, GPR32>;
951 def ATOMIC_SWAP_I16 : Atomic2Ops<atomic_swap_16, GPR32>;
952 def ATOMIC_SWAP_I32 : Atomic2Ops<atomic_swap_32, GPR32>;
954 def ATOMIC_CMP_SWAP_I8 : AtomicCmpSwap<atomic_cmp_swap_8, GPR32>;
955 def ATOMIC_CMP_SWAP_I16 : AtomicCmpSwap<atomic_cmp_swap_16, GPR32>;
956 def ATOMIC_CMP_SWAP_I32 : AtomicCmpSwap<atomic_cmp_swap_32, GPR32>;
959 /// Pseudo instructions for loading and storing accumulator registers.
960 let isPseudo = 1, isCodeGenOnly = 1 in {
961 def LOAD_ACC64 : Load<"", ACC64>;
962 def STORE_ACC64 : Store<"", ACC64>;
965 // We need these two pseudo instructions to avoid offset calculation for long
966 // branches. See the comment in file MipsLongBranch.cpp for detailed
969 // Expands to: lui $dst, %hi($tgt - $baltgt)
970 def LONG_BRANCH_LUi : PseudoSE<(outs GPR32Opnd:$dst),
971 (ins brtarget:$tgt, brtarget:$baltgt), []>;
973 // Expands to: addiu $dst, $src, %lo($tgt - $baltgt)
974 def LONG_BRANCH_ADDiu : PseudoSE<(outs GPR32Opnd:$dst),
975 (ins GPR32Opnd:$src, brtarget:$tgt, brtarget:$baltgt), []>;
977 //===----------------------------------------------------------------------===//
978 // Instruction definition
979 //===----------------------------------------------------------------------===//
980 //===----------------------------------------------------------------------===//
981 // MipsI Instructions
982 //===----------------------------------------------------------------------===//
984 /// Arithmetic Instructions (ALU Immediate)
985 def ADDiu : MMRel, ArithLogicI<"addiu", simm16, GPR32Opnd, II_ADDIU, immSExt16,
987 ADDI_FM<0x9>, IsAsCheapAsAMove;
988 def ADDi : MMRel, ArithLogicI<"addi", simm16, GPR32Opnd>, ADDI_FM<0x8>;
989 def SLTi : MMRel, SetCC_I<"slti", setlt, simm16, immSExt16, GPR32Opnd>,
991 def SLTiu : MMRel, SetCC_I<"sltiu", setult, simm16, immSExt16, GPR32Opnd>,
993 def ANDi : MMRel, ArithLogicI<"andi", uimm16, GPR32Opnd, II_ANDI, immZExt16,
996 def ORi : MMRel, ArithLogicI<"ori", uimm16, GPR32Opnd, II_ORI, immZExt16,
999 def XORi : MMRel, ArithLogicI<"xori", uimm16, GPR32Opnd, II_XORI, immZExt16,
1002 def LUi : MMRel, LoadUpper<"lui", GPR32Opnd, uimm16>, LUI_FM;
1004 /// Arithmetic Instructions (3-Operand, R-Type)
1005 def ADDu : MMRel, ArithLogicR<"addu", GPR32Opnd, 1, II_ADDU, add>,
1007 def SUBu : MMRel, ArithLogicR<"subu", GPR32Opnd, 0, II_SUBU, sub>,
1009 let Defs = [HI0, LO0] in
1010 def MUL : MMRel, ArithLogicR<"mul", GPR32Opnd, 1, II_MUL, mul>,
1011 ADD_FM<0x1c, 2>, ISA_MIPS32;
1012 def ADD : MMRel, ArithLogicR<"add", GPR32Opnd>, ADD_FM<0, 0x20>;
1013 def SUB : MMRel, ArithLogicR<"sub", GPR32Opnd>, ADD_FM<0, 0x22>;
1014 def SLT : MMRel, SetCC_R<"slt", setlt, GPR32Opnd>, ADD_FM<0, 0x2a>;
1015 def SLTu : MMRel, SetCC_R<"sltu", setult, GPR32Opnd>, ADD_FM<0, 0x2b>;
1016 def AND : MMRel, ArithLogicR<"and", GPR32Opnd, 1, II_AND, and>,
1018 def OR : MMRel, ArithLogicR<"or", GPR32Opnd, 1, II_OR, or>,
1020 def XOR : MMRel, ArithLogicR<"xor", GPR32Opnd, 1, II_XOR, xor>,
1022 def NOR : MMRel, LogicNOR<"nor", GPR32Opnd>, ADD_FM<0, 0x27>;
1024 /// Shift Instructions
1025 def SLL : MMRel, shift_rotate_imm<"sll", uimm5, GPR32Opnd, II_SLL, shl,
1026 immZExt5>, SRA_FM<0, 0>;
1027 def SRL : MMRel, shift_rotate_imm<"srl", uimm5, GPR32Opnd, II_SRL, srl,
1028 immZExt5>, SRA_FM<2, 0>;
1029 def SRA : MMRel, shift_rotate_imm<"sra", uimm5, GPR32Opnd, II_SRA, sra,
1030 immZExt5>, SRA_FM<3, 0>;
1031 def SLLV : MMRel, shift_rotate_reg<"sllv", GPR32Opnd, II_SLLV, shl>,
1033 def SRLV : MMRel, shift_rotate_reg<"srlv", GPR32Opnd, II_SRLV, srl>,
1035 def SRAV : MMRel, shift_rotate_reg<"srav", GPR32Opnd, II_SRAV, sra>,
1038 // Rotate Instructions
1039 def ROTR : MMRel, shift_rotate_imm<"rotr", uimm5, GPR32Opnd, II_ROTR, rotr,
1041 SRA_FM<2, 1>, ISA_MIPS32R2;
1042 def ROTRV : MMRel, shift_rotate_reg<"rotrv", GPR32Opnd, II_ROTRV, rotr>,
1043 SRLV_FM<6, 1>, ISA_MIPS32R2;
1045 /// Load and Store Instructions
1047 def LB : Load<"lb", GPR32Opnd, sextloadi8, II_LB>, MMRel, LW_FM<0x20>;
1048 def LBu : Load<"lbu", GPR32Opnd, zextloadi8, II_LBU, addrDefault>, MMRel,
1050 def LH : Load<"lh", GPR32Opnd, sextloadi16, II_LH, addrDefault>, MMRel,
1052 def LHu : Load<"lhu", GPR32Opnd, zextloadi16, II_LHU>, MMRel, LW_FM<0x25>;
1053 def LW : Load<"lw", GPR32Opnd, load, II_LW, addrDefault>, MMRel,
1055 def SB : Store<"sb", GPR32Opnd, truncstorei8, II_SB>, MMRel, LW_FM<0x28>;
1056 def SH : Store<"sh", GPR32Opnd, truncstorei16, II_SH>, MMRel, LW_FM<0x29>;
1057 def SW : Store<"sw", GPR32Opnd, store, II_SW>, MMRel, LW_FM<0x2b>;
1059 /// load/store left/right
1060 let EncodingPredicates = []<Predicate>, // FIXME: Lack of HasStdEnc is probably a bug
1061 AdditionalPredicates = [NotInMicroMips] in {
1062 def LWL : LoadLeftRight<"lwl", MipsLWL, GPR32Opnd, II_LWL>, LW_FM<0x22>;
1063 def LWR : LoadLeftRight<"lwr", MipsLWR, GPR32Opnd, II_LWR>, LW_FM<0x26>;
1064 def SWL : StoreLeftRight<"swl", MipsSWL, GPR32Opnd, II_SWL>, LW_FM<0x2a>;
1065 def SWR : StoreLeftRight<"swr", MipsSWR, GPR32Opnd, II_SWR>, LW_FM<0x2e>;
1068 def SYNC : MMRel, SYNC_FT<"sync">, SYNC_FM;
1069 def TEQ : MMRel, TEQ_FT<"teq", GPR32Opnd>, TEQ_FM<0x34>;
1070 def TGE : MMRel, TEQ_FT<"tge", GPR32Opnd>, TEQ_FM<0x30>;
1071 def TGEU : MMRel, TEQ_FT<"tgeu", GPR32Opnd>, TEQ_FM<0x31>;
1072 def TLT : MMRel, TEQ_FT<"tlt", GPR32Opnd>, TEQ_FM<0x32>;
1073 def TLTU : MMRel, TEQ_FT<"tltu", GPR32Opnd>, TEQ_FM<0x33>;
1074 def TNE : MMRel, TEQ_FT<"tne", GPR32Opnd>, TEQ_FM<0x36>;
1076 def TEQI : MMRel, TEQI_FT<"teqi", GPR32Opnd>, TEQI_FM<0xc>, ISA_MIPS2;
1077 def TGEI : MMRel, TEQI_FT<"tgei", GPR32Opnd>, TEQI_FM<0x8>, ISA_MIPS2;
1078 def TGEIU : MMRel, TEQI_FT<"tgeiu", GPR32Opnd>, TEQI_FM<0x9>, ISA_MIPS2;
1079 def TLTI : MMRel, TEQI_FT<"tlti", GPR32Opnd>, TEQI_FM<0xa>, ISA_MIPS2;
1080 def TTLTIU : MMRel, TEQI_FT<"tltiu", GPR32Opnd>, TEQI_FM<0xb>, ISA_MIPS2;
1081 def TNEI : MMRel, TEQI_FT<"tnei", GPR32Opnd>, TEQI_FM<0xe>, ISA_MIPS2;
1083 def BREAK : MMRel, BRK_FT<"break">, BRK_FM<0xd>;
1084 def SYSCALL : MMRel, SYS_FT<"syscall">, SYS_FM<0xc>;
1085 def TRAP : TrapBase<BREAK>;
1087 def ERET : MMRel, ER_FT<"eret">, ER_FM<0x18>, INSN_MIPS3_32;
1088 def DERET : MMRel, ER_FT<"deret">, ER_FM<0x1f>, ISA_MIPS32;
1090 def EI : MMRel, DEI_FT<"ei", GPR32Opnd>, EI_FM<1>;
1091 def DI : MMRel, DEI_FT<"di", GPR32Opnd>, EI_FM<0>;
1093 let EncodingPredicates = []<Predicate>, // FIXME: Lack of HasStdEnc is probably a bug
1094 AdditionalPredicates = [NotInMicroMips] in {
1095 def WAIT : WAIT_FT<"wait">, WAIT_FM;
1097 /// Load-linked, Store-conditional
1098 def LL : LLBase<"ll", GPR32Opnd>, LW_FM<0x30>, ISA_MIPS2;
1099 def SC : SCBase<"sc", GPR32Opnd>, LW_FM<0x38>, ISA_MIPS2;
1102 /// Jump and Branch Instructions
1103 def J : MMRel, JumpFJ<jmptarget, "j", br, bb, "j">, FJ<2>,
1104 AdditionalRequires<[RelocStatic]>, IsBranch;
1105 def JR : MMRel, IndirectBranch<"jr", GPR32Opnd>, MTLO_FM<8>;
1106 def BEQ : MMRel, CBranch<"beq", brtarget, seteq, GPR32Opnd>, BEQ_FM<4>;
1107 def BNE : MMRel, CBranch<"bne", brtarget, setne, GPR32Opnd>, BEQ_FM<5>;
1108 def BGEZ : MMRel, CBranchZero<"bgez", brtarget, setge, GPR32Opnd>,
1110 def BGTZ : MMRel, CBranchZero<"bgtz", brtarget, setgt, GPR32Opnd>,
1112 def BLEZ : MMRel, CBranchZero<"blez", brtarget, setle, GPR32Opnd>,
1114 def BLTZ : MMRel, CBranchZero<"bltz", brtarget, setlt, GPR32Opnd>,
1116 def B : UncondBranch<BEQ>;
1118 def JAL : MMRel, JumpLink<"jal", calltarget>, FJ<3>;
1119 let AdditionalPredicates = [NotInMicroMips] in {
1120 def JALR : JumpLinkReg<"jalr", GPR32Opnd>, JALR_FM;
1121 def JALRPseudo : JumpLinkRegPseudo<GPR32Opnd, JALR, RA>;
1123 def JALX : JumpLink<"jalx", calltarget>, FJ<0x1D>;
1124 def BGEZAL : MMRel, BGEZAL_FT<"bgezal", brtarget, GPR32Opnd>, BGEZAL_FM<0x11>;
1125 def BLTZAL : MMRel, BGEZAL_FT<"bltzal", brtarget, GPR32Opnd>, BGEZAL_FM<0x10>;
1126 def BAL_BR : BAL_BR_Pseudo<BGEZAL>;
1127 def TAILCALL : TailCall<J>;
1128 def TAILCALL_R : TailCallReg<GPR32Opnd, JR>;
1130 def RET : MMRel, RetBase<"ret", GPR32Opnd>, MTLO_FM<8>;
1132 // Exception handling related node and instructions.
1133 // The conversion sequence is:
1134 // ISD::EH_RETURN -> MipsISD::EH_RETURN ->
1135 // MIPSeh_return -> (stack change + indirect branch)
1137 // MIPSeh_return takes the place of regular return instruction
1138 // but takes two arguments (V1, V0) which are used for storing
1139 // the offset and return address respectively.
1140 def SDT_MipsEHRET : SDTypeProfile<0, 2, [SDTCisInt<0>, SDTCisPtrTy<1>]>;
1142 def MIPSehret : SDNode<"MipsISD::EH_RETURN", SDT_MipsEHRET,
1143 [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
1145 let Uses = [V0, V1], isTerminator = 1, isReturn = 1, isBarrier = 1 in {
1146 def MIPSeh_return32 : MipsPseudo<(outs), (ins GPR32:$spoff, GPR32:$dst),
1147 [(MIPSehret GPR32:$spoff, GPR32:$dst)]>;
1148 def MIPSeh_return64 : MipsPseudo<(outs), (ins GPR64:$spoff,
1150 [(MIPSehret GPR64:$spoff, GPR64:$dst)]>;
1153 /// Multiply and Divide Instructions.
1154 def MULT : MMRel, Mult<"mult", II_MULT, GPR32Opnd, [HI0, LO0]>,
1156 def MULTu : MMRel, Mult<"multu", II_MULTU, GPR32Opnd, [HI0, LO0]>,
1158 def SDIV : MMRel, Div<"div", II_DIV, GPR32Opnd, [HI0, LO0]>,
1160 def UDIV : MMRel, Div<"divu", II_DIVU, GPR32Opnd, [HI0, LO0]>,
1163 def MTHI : MMRel, MoveToLOHI<"mthi", GPR32Opnd, [HI0]>, MTLO_FM<0x11>;
1164 def MTLO : MMRel, MoveToLOHI<"mtlo", GPR32Opnd, [LO0]>, MTLO_FM<0x13>;
1165 let EncodingPredicates = []<Predicate>, // FIXME: Lack of HasStdEnc is probably a bug
1166 AdditionalPredicates = [NotInMicroMips] in {
1167 def MFHI : MMRel, MoveFromLOHI<"mfhi", GPR32Opnd, AC0>, MFLO_FM<0x10>;
1168 def MFLO : MMRel, MoveFromLOHI<"mflo", GPR32Opnd, AC0>, MFLO_FM<0x12>;
1171 /// Sign Ext In Register Instructions.
1172 def SEB : MMRel, SignExtInReg<"seb", i8, GPR32Opnd, II_SEB>,
1173 SEB_FM<0x10, 0x20>, ISA_MIPS32R2;
1174 def SEH : MMRel, SignExtInReg<"seh", i16, GPR32Opnd, II_SEH>,
1175 SEB_FM<0x18, 0x20>, ISA_MIPS32R2;
1178 def CLZ : MMRel, CountLeading0<"clz", GPR32Opnd>, CLO_FM<0x20>, ISA_MIPS32;
1179 def CLO : MMRel, CountLeading1<"clo", GPR32Opnd>, CLO_FM<0x21>, ISA_MIPS32;
1181 /// Word Swap Bytes Within Halfwords
1182 def WSBH : MMRel, SubwordSwap<"wsbh", GPR32Opnd>, SEB_FM<2, 0x20>, ISA_MIPS32R2;
1185 def NOP : PseudoSE<(outs), (ins), []>, PseudoInstExpansion<(SLL ZERO, ZERO, 0)>;
1187 // FrameIndexes are legalized when they are operands from load/store
1188 // instructions. The same not happens for stack address copies, so an
1189 // add op with mem ComplexPattern is used and the stack address copy
1190 // can be matched. It's similar to Sparc LEA_ADDRi
1191 def LEA_ADDiu : MMRel, EffectiveAddress<"addiu", GPR32Opnd>, LW_FM<9>;
1194 def MADD : MMRel, MArithR<"madd", II_MADD, 1>, MULT_FM<0x1c, 0>, ISA_MIPS32;
1195 def MADDU : MMRel, MArithR<"maddu", II_MADDU, 1>, MULT_FM<0x1c, 1>, ISA_MIPS32;
1196 def MSUB : MMRel, MArithR<"msub", II_MSUB>, MULT_FM<0x1c, 4>, ISA_MIPS32;
1197 def MSUBU : MMRel, MArithR<"msubu", II_MSUBU>, MULT_FM<0x1c, 5>, ISA_MIPS32;
1199 let AdditionalPredicates = [NotDSP] in {
1200 def PseudoMULT : MultDivPseudo<MULT, ACC64, GPR32Opnd, MipsMult, II_MULT>;
1201 def PseudoMULTu : MultDivPseudo<MULTu, ACC64, GPR32Opnd, MipsMultu, II_MULTU>;
1202 def PseudoMFHI : PseudoMFLOHI<GPR32, ACC64, MipsMFHI>;
1203 def PseudoMFLO : PseudoMFLOHI<GPR32, ACC64, MipsMFLO>;
1204 def PseudoMTLOHI : PseudoMTLOHI<ACC64, GPR32>;
1205 def PseudoMADD : MAddSubPseudo<MADD, MipsMAdd, II_MADD>;
1206 def PseudoMADDU : MAddSubPseudo<MADDU, MipsMAddu, II_MADDU>;
1207 def PseudoMSUB : MAddSubPseudo<MSUB, MipsMSub, II_MSUB>;
1208 def PseudoMSUBU : MAddSubPseudo<MSUBU, MipsMSubu, II_MSUBU>;
1211 def PseudoSDIV : MultDivPseudo<SDIV, ACC64, GPR32Opnd, MipsDivRem, II_DIV,
1213 def PseudoUDIV : MultDivPseudo<UDIV, ACC64, GPR32Opnd, MipsDivRemU, II_DIVU,
1216 def RDHWR : ReadHardware<GPR32Opnd, HWRegsOpnd>, RDHWR_FM;
1218 def EXT : MMRel, ExtBase<"ext", GPR32Opnd, uimm5, MipsExt>, EXT_FM<0>;
1219 def INS : MMRel, InsBase<"ins", GPR32Opnd, uimm5, MipsIns>, EXT_FM<4>;
1221 /// Move Control Registers From/To CPU Registers
1222 def MFC0 : MFC3OP<"mfc0", GPR32Opnd>, MFC3OP_FM<0x10, 0>, ISA_MIPS32;
1223 def MTC0 : MFC3OP<"mtc0", GPR32Opnd>, MFC3OP_FM<0x10, 4>, ISA_MIPS32;
1224 def MFC2 : MFC3OP<"mfc2", GPR32Opnd>, MFC3OP_FM<0x12, 0>;
1225 def MTC2 : MFC3OP<"mtc2", GPR32Opnd>, MFC3OP_FM<0x12, 4>;
1227 class Barrier<string asmstr> : InstSE<(outs), (ins), asmstr, [], NoItinerary,
1229 def SSNOP : Barrier<"ssnop">, BARRIER_FM<1>;
1230 def EHB : Barrier<"ehb">, BARRIER_FM<3>;
1231 def PAUSE : Barrier<"pause">, BARRIER_FM<5>, ISA_MIPS32R2;
1233 class TLB<string asmstr> : InstSE<(outs), (ins), asmstr, [], NoItinerary,
1235 def TLBP : TLB<"tlbp">, COP0_TLB_FM<0x08>;
1236 def TLBR : TLB<"tlbr">, COP0_TLB_FM<0x01>;
1237 def TLBWI : TLB<"tlbwi">, COP0_TLB_FM<0x02>;
1238 def TLBWR : TLB<"tlbwr">, COP0_TLB_FM<0x06>;
1240 //===----------------------------------------------------------------------===//
1241 // Instruction aliases
1242 //===----------------------------------------------------------------------===//
1243 def : MipsInstAlias<"move $dst, $src",
1244 (ADDu GPR32Opnd:$dst, GPR32Opnd:$src,ZERO), 1>,
1245 Requires<[IsGP32, NotInMicroMips]>;
1246 def : MipsInstAlias<"bal $offset", (BGEZAL ZERO, brtarget:$offset), 0>;
1247 def : MipsInstAlias<"addu $rs, $rt, $imm",
1248 (ADDiu GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm), 0>;
1249 def : MipsInstAlias<"add $rs, $rt, $imm",
1250 (ADDi GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm), 0>;
1251 def : MipsInstAlias<"and $rs, $rt, $imm",
1252 (ANDi GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm), 0>;
1253 def : MipsInstAlias<"j $rs", (JR GPR32Opnd:$rs), 0>;
1254 let Predicates = [NotInMicroMips] in {
1255 def : MipsInstAlias<"jalr $rs", (JALR RA, GPR32Opnd:$rs), 0>;
1257 def : MipsInstAlias<"jal $rs", (JALR RA, GPR32Opnd:$rs), 0>;
1258 def : MipsInstAlias<"jal $rd,$rs", (JALR GPR32Opnd:$rd, GPR32Opnd:$rs), 0>;
1259 def : MipsInstAlias<"not $rt, $rs",
1260 (NOR GPR32Opnd:$rt, GPR32Opnd:$rs, ZERO), 0>;
1261 def : MipsInstAlias<"neg $rt, $rs",
1262 (SUB GPR32Opnd:$rt, ZERO, GPR32Opnd:$rs), 1>;
1263 def : MipsInstAlias<"negu $rt",
1264 (SUBu GPR32Opnd:$rt, ZERO, GPR32Opnd:$rt), 0>;
1265 def : MipsInstAlias<"negu $rt, $rs",
1266 (SUBu GPR32Opnd:$rt, ZERO, GPR32Opnd:$rs), 1>;
1267 def : MipsInstAlias<"slt $rs, $rt, $imm",
1268 (SLTi GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm), 0>;
1269 def : MipsInstAlias<"sltu $rt, $rs, $imm",
1270 (SLTiu GPR32Opnd:$rt, GPR32Opnd:$rs, simm16:$imm), 0>;
1271 def : MipsInstAlias<"xor $rs, $rt, $imm",
1272 (XORi GPR32Opnd:$rs, GPR32Opnd:$rt, uimm16:$imm), 0>;
1273 def : MipsInstAlias<"or $rs, $rt, $imm",
1274 (ORi GPR32Opnd:$rs, GPR32Opnd:$rt, uimm16:$imm), 0>;
1275 def : MipsInstAlias<"nop", (SLL ZERO, ZERO, 0), 1>;
1276 def : MipsInstAlias<"mfc0 $rt, $rd", (MFC0 GPR32Opnd:$rt, GPR32Opnd:$rd, 0), 0>;
1277 def : MipsInstAlias<"mtc0 $rt, $rd", (MTC0 GPR32Opnd:$rt, GPR32Opnd:$rd, 0), 0>;
1278 def : MipsInstAlias<"mfc2 $rt, $rd", (MFC2 GPR32Opnd:$rt, GPR32Opnd:$rd, 0), 0>;
1279 def : MipsInstAlias<"mtc2 $rt, $rd", (MTC2 GPR32Opnd:$rt, GPR32Opnd:$rd, 0), 0>;
1280 def : MipsInstAlias<"b $offset", (BEQ ZERO, ZERO, brtarget:$offset), 0>;
1281 def : MipsInstAlias<"bnez $rs,$offset",
1282 (BNE GPR32Opnd:$rs, ZERO, brtarget:$offset), 0>;
1283 def : MipsInstAlias<"beqz $rs,$offset",
1284 (BEQ GPR32Opnd:$rs, ZERO, brtarget:$offset), 0>;
1285 def : MipsInstAlias<"syscall", (SYSCALL 0), 1>;
1287 def : MipsInstAlias<"break $imm", (BREAK uimm10:$imm, 0), 1>;
1288 def : MipsInstAlias<"break", (BREAK 0, 0), 1>;
1289 def : MipsInstAlias<"ei", (EI ZERO), 1>;
1290 def : MipsInstAlias<"di", (DI ZERO), 1>;
1292 def : MipsInstAlias<"teq $rs, $rt", (TEQ GPR32Opnd:$rs, GPR32Opnd:$rt, 0), 1>;
1293 def : MipsInstAlias<"tge $rs, $rt", (TGE GPR32Opnd:$rs, GPR32Opnd:$rt, 0), 1>;
1294 def : MipsInstAlias<"tgeu $rs, $rt", (TGEU GPR32Opnd:$rs, GPR32Opnd:$rt, 0),
1296 def : MipsInstAlias<"tlt $rs, $rt", (TLT GPR32Opnd:$rs, GPR32Opnd:$rt, 0), 1>;
1297 def : MipsInstAlias<"tltu $rs, $rt", (TLTU GPR32Opnd:$rs, GPR32Opnd:$rt, 0),
1299 def : MipsInstAlias<"tne $rs, $rt", (TNE GPR32Opnd:$rs, GPR32Opnd:$rt, 0), 1>;
1300 def : MipsInstAlias<"sll $rd, $rt, $rs",
1301 (SLLV GPR32Opnd:$rd, GPR32Opnd:$rt, GPR32Opnd:$rs), 0>;
1302 def : MipsInstAlias<"sub, $rd, $rs, $imm",
1303 (ADDi GPR32Opnd:$rd, GPR32Opnd:$rs,
1304 InvertedImOperand:$imm)>;
1305 def : MipsInstAlias<"sub $rs, $imm",
1306 (ADDi GPR32Opnd:$rs, GPR32Opnd:$rs, InvertedImOperand:$imm),
1308 def : MipsInstAlias<"subu, $rd, $rs, $imm",
1309 (ADDiu GPR32Opnd:$rd, GPR32Opnd:$rs,
1310 InvertedImOperand:$imm)>;
1311 def : MipsInstAlias<"subu $rs, $imm", (ADDiu GPR32Opnd:$rs, GPR32Opnd:$rs,
1312 InvertedImOperand:$imm), 0>;
1313 def : MipsInstAlias<"sra $rd, $rt, $rs",
1314 (SRAV GPR32Opnd:$rd, GPR32Opnd:$rt, GPR32Opnd:$rs), 0>;
1315 def : MipsInstAlias<"srl $rd, $rt, $rs",
1316 (SRLV GPR32Opnd:$rd, GPR32Opnd:$rt, GPR32Opnd:$rs), 0>;
1317 //===----------------------------------------------------------------------===//
1318 // Assembler Pseudo Instructions
1319 //===----------------------------------------------------------------------===//
1321 class LoadImm32< string instr_asm, Operand Od, RegisterOperand RO> :
1322 MipsAsmPseudoInst<(outs RO:$rt), (ins Od:$imm32),
1323 !strconcat(instr_asm, "\t$rt, $imm32")> ;
1324 def LoadImm32Reg : LoadImm32<"li", uimm5, GPR32Opnd>;
1326 class LoadAddress<string instr_asm, Operand MemOpnd, RegisterOperand RO> :
1327 MipsAsmPseudoInst<(outs RO:$rt), (ins MemOpnd:$addr),
1328 !strconcat(instr_asm, "\t$rt, $addr")> ;
1329 def LoadAddr32Reg : LoadAddress<"la", mem, GPR32Opnd>;
1331 class LoadAddressImm<string instr_asm, Operand Od, RegisterOperand RO> :
1332 MipsAsmPseudoInst<(outs RO:$rt), (ins Od:$imm32),
1333 !strconcat(instr_asm, "\t$rt, $imm32")> ;
1334 def LoadAddr32Imm : LoadAddressImm<"la", uimm5, GPR32Opnd>;
1336 //===----------------------------------------------------------------------===//
1337 // Arbitrary patterns that map to one or more instructions
1338 //===----------------------------------------------------------------------===//
1340 // Load/store pattern templates.
1341 class LoadRegImmPat<Instruction LoadInst, ValueType ValTy, PatFrag Node> :
1342 MipsPat<(ValTy (Node addrRegImm:$a)), (LoadInst addrRegImm:$a)>;
1344 class StoreRegImmPat<Instruction StoreInst, ValueType ValTy> :
1345 MipsPat<(store ValTy:$v, addrRegImm:$a), (StoreInst ValTy:$v, addrRegImm:$a)>;
1348 def : MipsPat<(i32 immSExt16:$in),
1349 (ADDiu ZERO, imm:$in)>;
1350 def : MipsPat<(i32 immZExt16:$in),
1351 (ORi ZERO, imm:$in)>;
1352 def : MipsPat<(i32 immLow16Zero:$in),
1353 (LUi (HI16 imm:$in))>;
1355 // Arbitrary immediates
1356 def : MipsPat<(i32 imm:$imm),
1357 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
1359 // Carry MipsPatterns
1360 def : MipsPat<(subc GPR32:$lhs, GPR32:$rhs),
1361 (SUBu GPR32:$lhs, GPR32:$rhs)>;
1362 let AdditionalPredicates = [NotDSP] in {
1363 def : MipsPat<(addc GPR32:$lhs, GPR32:$rhs),
1364 (ADDu GPR32:$lhs, GPR32:$rhs)>;
1365 def : MipsPat<(addc GPR32:$src, immSExt16:$imm),
1366 (ADDiu GPR32:$src, imm:$imm)>;
1370 def : MipsPat<(MipsJmpLink (i32 tglobaladdr:$dst)),
1371 (JAL tglobaladdr:$dst)>;
1372 def : MipsPat<(MipsJmpLink (i32 texternalsym:$dst)),
1373 (JAL texternalsym:$dst)>;
1374 //def : MipsPat<(MipsJmpLink GPR32:$dst),
1375 // (JALR GPR32:$dst)>;
1378 def : MipsPat<(MipsTailCall (iPTR tglobaladdr:$dst)),
1379 (TAILCALL tglobaladdr:$dst)>;
1380 def : MipsPat<(MipsTailCall (iPTR texternalsym:$dst)),
1381 (TAILCALL texternalsym:$dst)>;
1383 def : MipsPat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
1384 def : MipsPat<(MipsHi tblockaddress:$in), (LUi tblockaddress:$in)>;
1385 def : MipsPat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
1386 def : MipsPat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
1387 def : MipsPat<(MipsHi tglobaltlsaddr:$in), (LUi tglobaltlsaddr:$in)>;
1388 def : MipsPat<(MipsHi texternalsym:$in), (LUi texternalsym:$in)>;
1390 def : MipsPat<(MipsLo tglobaladdr:$in), (ADDiu ZERO, tglobaladdr:$in)>;
1391 def : MipsPat<(MipsLo tblockaddress:$in), (ADDiu ZERO, tblockaddress:$in)>;
1392 def : MipsPat<(MipsLo tjumptable:$in), (ADDiu ZERO, tjumptable:$in)>;
1393 def : MipsPat<(MipsLo tconstpool:$in), (ADDiu ZERO, tconstpool:$in)>;
1394 def : MipsPat<(MipsLo tglobaltlsaddr:$in), (ADDiu ZERO, tglobaltlsaddr:$in)>;
1395 def : MipsPat<(MipsLo texternalsym:$in), (ADDiu ZERO, texternalsym:$in)>;
1397 def : MipsPat<(add GPR32:$hi, (MipsLo tglobaladdr:$lo)),
1398 (ADDiu GPR32:$hi, tglobaladdr:$lo)>;
1399 def : MipsPat<(add GPR32:$hi, (MipsLo tblockaddress:$lo)),
1400 (ADDiu GPR32:$hi, tblockaddress:$lo)>;
1401 def : MipsPat<(add GPR32:$hi, (MipsLo tjumptable:$lo)),
1402 (ADDiu GPR32:$hi, tjumptable:$lo)>;
1403 def : MipsPat<(add GPR32:$hi, (MipsLo tconstpool:$lo)),
1404 (ADDiu GPR32:$hi, tconstpool:$lo)>;
1405 def : MipsPat<(add GPR32:$hi, (MipsLo tglobaltlsaddr:$lo)),
1406 (ADDiu GPR32:$hi, tglobaltlsaddr:$lo)>;
1409 def : MipsPat<(add GPR32:$gp, (MipsGPRel tglobaladdr:$in)),
1410 (ADDiu GPR32:$gp, tglobaladdr:$in)>;
1411 def : MipsPat<(add GPR32:$gp, (MipsGPRel tconstpool:$in)),
1412 (ADDiu GPR32:$gp, tconstpool:$in)>;
1415 class WrapperPat<SDNode node, Instruction ADDiuOp, RegisterClass RC>:
1416 MipsPat<(MipsWrapper RC:$gp, node:$in),
1417 (ADDiuOp RC:$gp, node:$in)>;
1419 def : WrapperPat<tglobaladdr, ADDiu, GPR32>;
1420 def : WrapperPat<tconstpool, ADDiu, GPR32>;
1421 def : WrapperPat<texternalsym, ADDiu, GPR32>;
1422 def : WrapperPat<tblockaddress, ADDiu, GPR32>;
1423 def : WrapperPat<tjumptable, ADDiu, GPR32>;
1424 def : WrapperPat<tglobaltlsaddr, ADDiu, GPR32>;
1426 // Mips does not have "not", so we expand our way
1427 def : MipsPat<(not GPR32:$in),
1428 (NOR GPR32Opnd:$in, ZERO)>;
1431 def : MipsPat<(i32 (extloadi1 addr:$src)), (LBu addr:$src)>;
1432 def : MipsPat<(i32 (extloadi8 addr:$src)), (LBu addr:$src)>;
1433 def : MipsPat<(i32 (extloadi16 addr:$src)), (LHu addr:$src)>;
1436 def : MipsPat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
1439 multiclass BrcondPats<RegisterClass RC, Instruction BEQOp, Instruction BNEOp,
1440 Instruction SLTOp, Instruction SLTuOp, Instruction SLTiOp,
1441 Instruction SLTiuOp, Register ZEROReg> {
1442 def : MipsPat<(brcond (i32 (setne RC:$lhs, 0)), bb:$dst),
1443 (BNEOp RC:$lhs, ZEROReg, bb:$dst)>;
1444 def : MipsPat<(brcond (i32 (seteq RC:$lhs, 0)), bb:$dst),
1445 (BEQOp RC:$lhs, ZEROReg, bb:$dst)>;
1447 def : MipsPat<(brcond (i32 (setge RC:$lhs, RC:$rhs)), bb:$dst),
1448 (BEQ (SLTOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>;
1449 def : MipsPat<(brcond (i32 (setuge RC:$lhs, RC:$rhs)), bb:$dst),
1450 (BEQ (SLTuOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>;
1451 def : MipsPat<(brcond (i32 (setge RC:$lhs, immSExt16:$rhs)), bb:$dst),
1452 (BEQ (SLTiOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
1453 def : MipsPat<(brcond (i32 (setuge RC:$lhs, immSExt16:$rhs)), bb:$dst),
1454 (BEQ (SLTiuOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
1455 def : MipsPat<(brcond (i32 (setgt RC:$lhs, immSExt16Plus1:$rhs)), bb:$dst),
1456 (BEQ (SLTiOp RC:$lhs, (Plus1 imm:$rhs)), ZERO, bb:$dst)>;
1457 def : MipsPat<(brcond (i32 (setugt RC:$lhs, immSExt16Plus1:$rhs)), bb:$dst),
1458 (BEQ (SLTiuOp RC:$lhs, (Plus1 imm:$rhs)), ZERO, bb:$dst)>;
1460 def : MipsPat<(brcond (i32 (setle RC:$lhs, RC:$rhs)), bb:$dst),
1461 (BEQ (SLTOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>;
1462 def : MipsPat<(brcond (i32 (setule RC:$lhs, RC:$rhs)), bb:$dst),
1463 (BEQ (SLTuOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>;
1465 def : MipsPat<(brcond RC:$cond, bb:$dst),
1466 (BNEOp RC:$cond, ZEROReg, bb:$dst)>;
1469 defm : BrcondPats<GPR32, BEQ, BNE, SLT, SLTu, SLTi, SLTiu, ZERO>;
1471 def : MipsPat<(brcond (i32 (setlt i32:$lhs, 1)), bb:$dst),
1472 (BLEZ i32:$lhs, bb:$dst)>;
1473 def : MipsPat<(brcond (i32 (setgt i32:$lhs, -1)), bb:$dst),
1474 (BGEZ i32:$lhs, bb:$dst)>;
1477 multiclass SeteqPats<RegisterClass RC, Instruction SLTiuOp, Instruction XOROp,
1478 Instruction SLTuOp, Register ZEROReg> {
1479 def : MipsPat<(seteq RC:$lhs, 0),
1480 (SLTiuOp RC:$lhs, 1)>;
1481 def : MipsPat<(setne RC:$lhs, 0),
1482 (SLTuOp ZEROReg, RC:$lhs)>;
1483 def : MipsPat<(seteq RC:$lhs, RC:$rhs),
1484 (SLTiuOp (XOROp RC:$lhs, RC:$rhs), 1)>;
1485 def : MipsPat<(setne RC:$lhs, RC:$rhs),
1486 (SLTuOp ZEROReg, (XOROp RC:$lhs, RC:$rhs))>;
1489 multiclass SetlePats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
1490 def : MipsPat<(setle RC:$lhs, RC:$rhs),
1491 (XORi (SLTOp RC:$rhs, RC:$lhs), 1)>;
1492 def : MipsPat<(setule RC:$lhs, RC:$rhs),
1493 (XORi (SLTuOp RC:$rhs, RC:$lhs), 1)>;
1496 multiclass SetgtPats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
1497 def : MipsPat<(setgt RC:$lhs, RC:$rhs),
1498 (SLTOp RC:$rhs, RC:$lhs)>;
1499 def : MipsPat<(setugt RC:$lhs, RC:$rhs),
1500 (SLTuOp RC:$rhs, RC:$lhs)>;
1503 multiclass SetgePats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
1504 def : MipsPat<(setge RC:$lhs, RC:$rhs),
1505 (XORi (SLTOp RC:$lhs, RC:$rhs), 1)>;
1506 def : MipsPat<(setuge RC:$lhs, RC:$rhs),
1507 (XORi (SLTuOp RC:$lhs, RC:$rhs), 1)>;
1510 multiclass SetgeImmPats<RegisterClass RC, Instruction SLTiOp,
1511 Instruction SLTiuOp> {
1512 def : MipsPat<(setge RC:$lhs, immSExt16:$rhs),
1513 (XORi (SLTiOp RC:$lhs, immSExt16:$rhs), 1)>;
1514 def : MipsPat<(setuge RC:$lhs, immSExt16:$rhs),
1515 (XORi (SLTiuOp RC:$lhs, immSExt16:$rhs), 1)>;
1518 defm : SeteqPats<GPR32, SLTiu, XOR, SLTu, ZERO>;
1519 defm : SetlePats<GPR32, SLT, SLTu>;
1520 defm : SetgtPats<GPR32, SLT, SLTu>;
1521 defm : SetgePats<GPR32, SLT, SLTu>;
1522 defm : SetgeImmPats<GPR32, SLTi, SLTiu>;
1525 def : MipsPat<(bswap GPR32:$rt), (ROTR (WSBH GPR32:$rt), 16)>;
1527 // Load halfword/word patterns.
1528 let AddedComplexity = 40 in {
1529 def : LoadRegImmPat<LBu, i32, zextloadi8>;
1530 def : LoadRegImmPat<LH, i32, sextloadi16>;
1531 def : LoadRegImmPat<LW, i32, load>;
1534 //===----------------------------------------------------------------------===//
1535 // Floating Point Support
1536 //===----------------------------------------------------------------------===//
1538 include "MipsInstrFPU.td"
1539 include "Mips64InstrInfo.td"
1540 include "MipsCondMov.td"
1542 include "Mips32r6InstrInfo.td"
1543 include "Mips64r6InstrInfo.td"
1548 include "Mips16InstrFormats.td"
1549 include "Mips16InstrInfo.td"
1552 include "MipsDSPInstrFormats.td"
1553 include "MipsDSPInstrInfo.td"
1556 include "MipsMSAInstrFormats.td"
1557 include "MipsMSAInstrInfo.td"
1560 include "MicroMipsInstrFormats.td"
1561 include "MicroMipsInstrInfo.td"
1562 include "MicroMipsInstrFPU.td"