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 //===----------------------------------------------------------------------===//
14 //===----------------------------------------------------------------------===//
15 // Instruction format superclass
16 //===----------------------------------------------------------------------===//
18 include "MipsInstrFormats.td"
20 //===----------------------------------------------------------------------===//
21 // Mips profiles and nodes
22 //===----------------------------------------------------------------------===//
24 def SDT_MipsRet : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
25 def SDT_MipsJmpLink : SDTypeProfile<0, 1, [SDTCisVT<0, iPTR>]>;
26 def SDT_MipsCMov : SDTypeProfile<1, 4, [SDTCisSameAs<0, 1>,
30 def SDT_MipsCallSeqStart : SDCallSeqStart<[SDTCisVT<0, i32>]>;
31 def SDT_MipsCallSeqEnd : SDCallSeqEnd<[SDTCisVT<0, i32>, SDTCisVT<1, i32>]>;
32 def SDT_MipsMAddMSub : SDTypeProfile<0, 4,
33 [SDTCisVT<0, i32>, SDTCisSameAs<0, 1>,
36 def SDT_MipsDivRem : SDTypeProfile<0, 2,
40 def SDT_MipsThreadPointer : SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>;
42 def SDT_MipsDynAlloc : SDTypeProfile<1, 1, [SDTCisVT<0, iPTR>,
44 def SDT_Sync : SDTypeProfile<0, 1, [SDTCisVT<0, i32>]>;
46 def SDT_Ext : SDTypeProfile<1, 3, [SDTCisInt<0>, SDTCisSameAs<0, 1>,
47 SDTCisVT<2, i32>, SDTCisSameAs<2, 3>]>;
48 def SDT_Ins : SDTypeProfile<1, 4, [SDTCisInt<0>, SDTCisSameAs<0, 1>,
49 SDTCisVT<2, i32>, SDTCisSameAs<2, 3>,
53 def MipsJmpLink : SDNode<"MipsISD::JmpLink",SDT_MipsJmpLink,
54 [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue,
57 // Hi and Lo nodes are used to handle global addresses. Used on
58 // MipsISelLowering to lower stuff like GlobalAddress, ExternalSymbol
59 // static model. (nothing to do with Mips Registers Hi and Lo)
60 def MipsHi : SDNode<"MipsISD::Hi", SDTIntUnaryOp>;
61 def MipsLo : SDNode<"MipsISD::Lo", SDTIntUnaryOp>;
62 def MipsGPRel : SDNode<"MipsISD::GPRel", SDTIntUnaryOp>;
64 // TlsGd node is used to handle General Dynamic TLS
65 def MipsTlsGd : SDNode<"MipsISD::TlsGd", SDTIntUnaryOp>;
67 // TprelHi and TprelLo nodes are used to handle Local Exec TLS
68 def MipsTprelHi : SDNode<"MipsISD::TprelHi", SDTIntUnaryOp>;
69 def MipsTprelLo : SDNode<"MipsISD::TprelLo", SDTIntUnaryOp>;
72 def MipsThreadPointer: SDNode<"MipsISD::ThreadPointer", SDT_MipsThreadPointer>;
75 def MipsRet : SDNode<"MipsISD::Ret", SDT_MipsRet, [SDNPHasChain,
78 // These are target-independent nodes, but have target-specific formats.
79 def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_MipsCallSeqStart,
80 [SDNPHasChain, SDNPOutGlue]>;
81 def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_MipsCallSeqEnd,
82 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
85 def MipsMAdd : SDNode<"MipsISD::MAdd", SDT_MipsMAddMSub,
86 [SDNPOptInGlue, SDNPOutGlue]>;
87 def MipsMAddu : SDNode<"MipsISD::MAddu", SDT_MipsMAddMSub,
88 [SDNPOptInGlue, SDNPOutGlue]>;
89 def MipsMSub : SDNode<"MipsISD::MSub", SDT_MipsMAddMSub,
90 [SDNPOptInGlue, SDNPOutGlue]>;
91 def MipsMSubu : SDNode<"MipsISD::MSubu", SDT_MipsMAddMSub,
92 [SDNPOptInGlue, SDNPOutGlue]>;
95 def MipsDivRem : SDNode<"MipsISD::DivRem", SDT_MipsDivRem,
97 def MipsDivRemU : SDNode<"MipsISD::DivRemU", SDT_MipsDivRem,
100 // Target constant nodes that are not part of any isel patterns and remain
101 // unchanged can cause instructions with illegal operands to be emitted.
102 // Wrapper node patterns give the instruction selector a chance to replace
103 // target constant nodes that would otherwise remain unchanged with ADDiu
104 // nodes. Without these wrapper node patterns, the following conditional move
105 // instrucion is emitted when function cmov2 in test/CodeGen/Mips/cmov.ll is
107 // movn %got(d)($gp), %got(c)($gp), $4
108 // This instruction is illegal since movn can take only register operands.
110 def MipsWrapper : SDNode<"MipsISD::Wrapper", SDTIntUnaryOp>;
112 // Pointer to dynamically allocated stack area.
113 def MipsDynAlloc : SDNode<"MipsISD::DynAlloc", SDT_MipsDynAlloc,
114 [SDNPHasChain, SDNPInGlue]>;
116 def MipsSync : SDNode<"MipsISD::Sync", SDT_Sync, [SDNPHasChain]>;
118 def MipsExt : SDNode<"MipsISD::Ext", SDT_Ext>;
119 def MipsIns : SDNode<"MipsISD::Ins", SDT_Ins>;
121 //===----------------------------------------------------------------------===//
122 // Mips Instruction Predicate Definitions.
123 //===----------------------------------------------------------------------===//
124 def HasSEInReg : Predicate<"Subtarget.hasSEInReg()">;
125 def HasBitCount : Predicate<"Subtarget.hasBitCount()">;
126 def HasSwap : Predicate<"Subtarget.hasSwap()">;
127 def HasCondMov : Predicate<"Subtarget.hasCondMov()">;
128 def HasMips32 : Predicate<"Subtarget.hasMips32()">;
129 def HasMips32r2 : Predicate<"Subtarget.hasMips32r2()">;
130 def HasMips64 : Predicate<"Subtarget.hasMips64()">;
131 def NotMips64 : Predicate<"!Subtarget.hasMips64()">;
132 def HasMips64r2 : Predicate<"Subtarget.hasMips64r2()">;
133 def IsN64 : Predicate<"Subtarget.isABI_N64()">;
134 def NotN64 : Predicate<"!Subtarget.isABI_N64()">;
135 def RelocStatic : Predicate<"TM.getRelocationModel() == Reloc::Static">;
136 def RelocPIC : Predicate<"TM.getRelocationModel() == Reloc::PIC_">;
138 //===----------------------------------------------------------------------===//
139 // Mips Operand, Complex Patterns and Transformations Definitions.
140 //===----------------------------------------------------------------------===//
142 // Instruction operand types
143 def jmptarget : Operand<OtherVT> {
144 let EncoderMethod = "getJumpTargetOpValue";
146 def brtarget : Operand<OtherVT> {
147 let EncoderMethod = "getBranchTargetOpValue";
148 let OperandType = "OPERAND_PCREL";
150 def calltarget : Operand<iPTR> {
151 let EncoderMethod = "getJumpTargetOpValue";
153 def calltarget64: Operand<i64>;
154 def simm16 : Operand<i32>;
155 def simm16_64 : Operand<i64>;
156 def shamt : Operand<i32>;
159 def uimm16 : Operand<i32> {
160 let PrintMethod = "printUnsignedImm";
164 def mem : Operand<i32> {
165 let PrintMethod = "printMemOperand";
166 let MIOperandInfo = (ops CPURegs, simm16);
167 let EncoderMethod = "getMemEncoding";
170 def mem64 : Operand<i64> {
171 let PrintMethod = "printMemOperand";
172 let MIOperandInfo = (ops CPU64Regs, simm16_64);
175 def mem_ea : Operand<i32> {
176 let PrintMethod = "printMemOperandEA";
177 let MIOperandInfo = (ops CPURegs, simm16);
178 let EncoderMethod = "getMemEncoding";
181 def mem_ea_64 : Operand<i64> {
182 let PrintMethod = "printMemOperandEA";
183 let MIOperandInfo = (ops CPU64Regs, simm16_64);
184 let EncoderMethod = "getMemEncoding";
187 // size operand of ext instruction
188 def size_ext : Operand<i32> {
189 let EncoderMethod = "getSizeExtEncoding";
192 // size operand of ins instruction
193 def size_ins : Operand<i32> {
194 let EncoderMethod = "getSizeInsEncoding";
197 // Transformation Function - get the lower 16 bits.
198 def LO16 : SDNodeXForm<imm, [{
199 return getImm(N, N->getZExtValue() & 0xFFFF);
202 // Transformation Function - get the higher 16 bits.
203 def HI16 : SDNodeXForm<imm, [{
204 return getImm(N, (N->getZExtValue() >> 16) & 0xFFFF);
207 // Node immediate fits as 16-bit sign extended on target immediate.
209 def immSExt16 : PatLeaf<(imm), [{ return isInt<16>(N->getSExtValue()); }]>;
211 // Node immediate fits as 16-bit zero extended on target immediate.
212 // The LO16 param means that only the lower 16 bits of the node
213 // immediate are caught.
215 def immZExt16 : PatLeaf<(imm), [{
216 if (N->getValueType(0) == MVT::i32)
217 return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
219 return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
222 // shamt field must fit in 5 bits.
223 def immZExt5 : ImmLeaf<i32, [{return Imm == (Imm & 0x1f);}]>;
225 // Mips Address Mode! SDNode frameindex could possibily be a match
226 // since load and store instructions from stack used it.
227 def addr : ComplexPattern<iPTR, 2, "SelectAddr", [frameindex], []>;
229 //===----------------------------------------------------------------------===//
230 // Pattern fragment for load/store
231 //===----------------------------------------------------------------------===//
232 class UnalignedLoad<PatFrag Node> : PatFrag<(ops node:$ptr), (Node node:$ptr), [{
233 LoadSDNode *LD = cast<LoadSDNode>(N);
234 return LD->getMemoryVT().getSizeInBits()/8 > LD->getAlignment();
237 class AlignedLoad<PatFrag Node> : PatFrag<(ops node:$ptr), (Node node:$ptr), [{
238 LoadSDNode *LD = cast<LoadSDNode>(N);
239 return LD->getMemoryVT().getSizeInBits()/8 <= LD->getAlignment();
242 class UnalignedStore<PatFrag Node> : PatFrag<(ops node:$val, node:$ptr),
243 (Node node:$val, node:$ptr), [{
244 StoreSDNode *SD = cast<StoreSDNode>(N);
245 return SD->getMemoryVT().getSizeInBits()/8 > SD->getAlignment();
248 class AlignedStore<PatFrag Node> : PatFrag<(ops node:$val, node:$ptr),
249 (Node node:$val, node:$ptr), [{
250 StoreSDNode *SD = cast<StoreSDNode>(N);
251 return SD->getMemoryVT().getSizeInBits()/8 <= SD->getAlignment();
254 // Load/Store PatFrags.
255 def sextloadi16_a : AlignedLoad<sextloadi16>;
256 def zextloadi16_a : AlignedLoad<zextloadi16>;
257 def extloadi16_a : AlignedLoad<extloadi16>;
258 def load_a : AlignedLoad<load>;
259 def sextloadi32_a : AlignedLoad<sextloadi32>;
260 def zextloadi32_a : AlignedLoad<zextloadi32>;
261 def extloadi32_a : AlignedLoad<extloadi32>;
262 def truncstorei16_a : AlignedStore<truncstorei16>;
263 def store_a : AlignedStore<store>;
264 def truncstorei32_a : AlignedStore<truncstorei32>;
265 def sextloadi16_u : UnalignedLoad<sextloadi16>;
266 def zextloadi16_u : UnalignedLoad<zextloadi16>;
267 def extloadi16_u : UnalignedLoad<extloadi16>;
268 def load_u : UnalignedLoad<load>;
269 def sextloadi32_u : UnalignedLoad<sextloadi32>;
270 def zextloadi32_u : UnalignedLoad<zextloadi32>;
271 def extloadi32_u : UnalignedLoad<extloadi32>;
272 def truncstorei16_u : UnalignedStore<truncstorei16>;
273 def store_u : UnalignedStore<store>;
274 def truncstorei32_u : UnalignedStore<truncstorei32>;
276 //===----------------------------------------------------------------------===//
277 // Instructions specific format
278 //===----------------------------------------------------------------------===//
280 // Arithmetic and logical instructions with 3 register operands.
281 class ArithLogicR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
282 InstrItinClass itin, RegisterClass RC, bit isComm = 0>:
283 FR<op, func, (outs RC:$rd), (ins RC:$rs, RC:$rt),
284 !strconcat(instr_asm, "\t$rd, $rs, $rt"),
285 [(set RC:$rd, (OpNode RC:$rs, RC:$rt))], itin> {
287 let isCommutable = isComm;
290 class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm,
291 InstrItinClass itin, RegisterClass RC, bit isComm = 0>:
292 FR<op, func, (outs RC:$rd), (ins RC:$rs, RC:$rt),
293 !strconcat(instr_asm, "\t$rd, $rs, $rt"), [], itin> {
295 let isCommutable = isComm;
298 // Arithmetic and logical instructions with 2 register operands.
299 class ArithLogicI<bits<6> op, string instr_asm, SDNode OpNode,
300 Operand Od, PatLeaf imm_type, RegisterClass RC> :
301 FI<op, (outs RC:$rt), (ins RC:$rs, Od:$imm16),
302 !strconcat(instr_asm, "\t$rt, $rs, $imm16"),
303 [(set RC:$rt, (OpNode RC:$rs, imm_type:$imm16))], IIAlu>;
305 class ArithOverflowI<bits<6> op, string instr_asm, SDNode OpNode,
306 Operand Od, PatLeaf imm_type, RegisterClass RC> :
307 FI<op, (outs RC:$rt), (ins RC:$rs, Od:$imm16),
308 !strconcat(instr_asm, "\t$rt, $rs, $imm16"), [], IIAlu>;
310 // Arithmetic Multiply ADD/SUB
311 let rd = 0, shamt = 0, Defs = [HI, LO], Uses = [HI, LO] in
312 class MArithR<bits<6> func, string instr_asm, SDNode op, bit isComm = 0> :
313 FR<0x1c, func, (outs), (ins CPURegs:$rs, CPURegs:$rt),
314 !strconcat(instr_asm, "\t$rs, $rt"),
315 [(op CPURegs:$rs, CPURegs:$rt, LO, HI)], IIImul> {
318 let isCommutable = isComm;
322 class LogicNOR<bits<6> op, bits<6> func, string instr_asm, RegisterClass RC>:
323 FR<op, func, (outs RC:$rd), (ins RC:$rs, RC:$rt),
324 !strconcat(instr_asm, "\t$rd, $rs, $rt"),
325 [(set RC:$rd, (not (or RC:$rs, RC:$rt)))], IIAlu> {
327 let isCommutable = 1;
331 class shift_rotate_imm<bits<6> func, bits<5> isRotate, string instr_asm,
332 SDNode OpNode, PatFrag PF, Operand ImmOpnd,
334 FR<0x00, func, (outs RC:$rd), (ins RC:$rt, ImmOpnd:$shamt),
335 !strconcat(instr_asm, "\t$rd, $rt, $shamt"),
336 [(set RC:$rd, (OpNode RC:$rt, PF:$shamt))], IIAlu> {
340 // 32-bit shift instructions.
341 class shift_rotate_imm32<bits<6> func, bits<5> isRotate, string instr_asm,
343 shift_rotate_imm<func, isRotate, instr_asm, OpNode, immZExt5, shamt, CPURegs>;
345 class shift_rotate_reg<bits<6> func, bits<5> isRotate, string instr_asm,
346 SDNode OpNode, RegisterClass RC>:
347 FR<0x00, func, (outs RC:$rd), (ins CPURegs:$rs, RC:$rt),
348 !strconcat(instr_asm, "\t$rd, $rt, $rs"),
349 [(set RC:$rd, (OpNode RC:$rt, CPURegs:$rs))], IIAlu> {
350 let shamt = isRotate;
353 // Load Upper Imediate
354 class LoadUpper<bits<6> op, string instr_asm, RegisterClass RC, Operand Imm>:
355 FI<op, (outs RC:$rt), (ins Imm:$imm16),
356 !strconcat(instr_asm, "\t$rt, $imm16"), [], IIAlu> {
360 class FMem<bits<6> op, dag outs, dag ins, string asmstr, list<dag> pattern,
361 InstrItinClass itin>: FFI<op, outs, ins, asmstr, pattern> {
363 let Inst{25-21} = addr{20-16};
364 let Inst{15-0} = addr{15-0};
368 let canFoldAsLoad = 1 in
369 class LoadM<bits<6> op, string instr_asm, PatFrag OpNode, RegisterClass RC,
370 Operand MemOpnd, bit Pseudo>:
371 FMem<op, (outs RC:$rt), (ins MemOpnd:$addr),
372 !strconcat(instr_asm, "\t$rt, $addr"),
373 [(set RC:$rt, (OpNode addr:$addr))], IILoad> {
374 let isPseudo = Pseudo;
377 class StoreM<bits<6> op, string instr_asm, PatFrag OpNode, RegisterClass RC,
378 Operand MemOpnd, bit Pseudo>:
379 FMem<op, (outs), (ins RC:$rt, MemOpnd:$addr),
380 !strconcat(instr_asm, "\t$rt, $addr"),
381 [(OpNode RC:$rt, addr:$addr)], IIStore> {
382 let isPseudo = Pseudo;
385 // Unaligned Memory Load/Store
386 let canFoldAsLoad = 1 in
387 class LoadUnAlign<bits<6> op, RegisterClass RC, Operand MemOpnd>:
388 FMem<op, (outs RC:$rt), (ins MemOpnd:$addr), "", [], IILoad> {}
390 class StoreUnAlign<bits<6> op, RegisterClass RC, Operand MemOpnd>:
391 FMem<op, (outs), (ins RC:$rt, MemOpnd:$addr), "", [], IIStore> {}
394 multiclass LoadM32<bits<6> op, string instr_asm, PatFrag OpNode,
396 def #NAME# : LoadM<op, instr_asm, OpNode, CPURegs, mem, Pseudo>,
398 def _P8 : LoadM<op, instr_asm, OpNode, CPURegs, mem64, Pseudo>,
403 multiclass LoadM64<bits<6> op, string instr_asm, PatFrag OpNode,
405 def #NAME# : LoadM<op, instr_asm, OpNode, CPU64Regs, mem, Pseudo>,
407 def _P8 : LoadM<op, instr_asm, OpNode, CPU64Regs, mem64, Pseudo>,
412 multiclass LoadUnAlign32<bits<6> op> {
413 def #NAME# : LoadUnAlign<op, CPURegs, mem>,
415 def _P8 : LoadUnAlign<op, CPURegs, mem64>,
419 multiclass StoreM32<bits<6> op, string instr_asm, PatFrag OpNode,
421 def #NAME# : StoreM<op, instr_asm, OpNode, CPURegs, mem, Pseudo>,
423 def _P8 : StoreM<op, instr_asm, OpNode, CPURegs, mem64, Pseudo>,
428 multiclass StoreM64<bits<6> op, string instr_asm, PatFrag OpNode,
430 def #NAME# : StoreM<op, instr_asm, OpNode, CPU64Regs, mem, Pseudo>,
432 def _P8 : StoreM<op, instr_asm, OpNode, CPU64Regs, mem64, Pseudo>,
437 multiclass StoreUnAlign32<bits<6> op> {
438 def #NAME# : StoreUnAlign<op, CPURegs, mem>,
440 def _P8 : StoreUnAlign<op, CPURegs, mem64>,
444 // Conditional Branch
445 class CBranch<bits<6> op, string instr_asm, PatFrag cond_op, RegisterClass RC>:
446 BranchBase<op, (outs), (ins RC:$rs, RC:$rt, brtarget:$imm16),
447 !strconcat(instr_asm, "\t$rs, $rt, $imm16"),
448 [(brcond (i32 (cond_op RC:$rs, RC:$rt)), bb:$imm16)], IIBranch> {
450 let isTerminator = 1;
451 let hasDelaySlot = 1;
454 class CBranchZero<bits<6> op, bits<5> _rt, string instr_asm, PatFrag cond_op,
456 BranchBase<op, (outs), (ins RC:$rs, brtarget:$imm16),
457 !strconcat(instr_asm, "\t$rs, $imm16"),
458 [(brcond (i32 (cond_op RC:$rs, 0)), bb:$imm16)], IIBranch> {
461 let isTerminator = 1;
462 let hasDelaySlot = 1;
466 class SetCC_R<bits<6> op, bits<6> func, string instr_asm, PatFrag cond_op,
468 FR<op, func, (outs CPURegs:$rd), (ins RC:$rs, RC:$rt),
469 !strconcat(instr_asm, "\t$rd, $rs, $rt"),
470 [(set CPURegs:$rd, (cond_op RC:$rs, RC:$rt))],
475 class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op, Operand Od,
476 PatLeaf imm_type, RegisterClass RC>:
477 FI<op, (outs CPURegs:$rt), (ins RC:$rs, Od:$imm16),
478 !strconcat(instr_asm, "\t$rt, $rs, $imm16"),
479 [(set CPURegs:$rt, (cond_op RC:$rs, imm_type:$imm16))],
483 class JumpFJ<bits<6> op, string instr_asm>:
484 FJ<op, (outs), (ins jmptarget:$target),
485 !strconcat(instr_asm, "\t$target"), [(br bb:$target)], IIBranch> {
489 let hasDelaySlot = 1;
490 let Predicates = [RelocStatic];
493 // Unconditional branch
494 class UncondBranch<bits<6> op, string instr_asm>:
495 BranchBase<op, (outs), (ins brtarget:$imm16),
496 !strconcat(instr_asm, "\t$imm16"), [(br bb:$imm16)], IIBranch> {
500 let isTerminator = 1;
502 let hasDelaySlot = 1;
503 let Predicates = [RelocPIC];
506 let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1,
507 isIndirectBranch = 1 in
508 class JumpFR<bits<6> op, bits<6> func, string instr_asm, RegisterClass RC>:
509 FR<op, func, (outs), (ins RC:$rs),
510 !strconcat(instr_asm, "\t$rs"), [(brind RC:$rs)], IIBranch> {
516 // Jump and Link (Call)
517 let isCall=1, hasDelaySlot=1,
518 // All calls clobber the non-callee saved registers...
519 Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9,
520 K0, K1, D0, D1, D2, D3, D4, D5, D6, D7, D8, D9], Uses = [GP] in {
521 class JumpLink<bits<6> op, string instr_asm>:
522 FJ<op, (outs), (ins calltarget:$target, variable_ops),
523 !strconcat(instr_asm, "\t$target"), [(MipsJmpLink imm:$target)],
526 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
527 FR<op, func, (outs), (ins CPURegs:$rs, variable_ops),
528 !strconcat(instr_asm, "\t$rs"), [(MipsJmpLink CPURegs:$rs)], IIBranch> {
534 class BranchLink<string instr_asm>:
535 FI<0x1, (outs), (ins CPURegs:$rs, brtarget:$imm16, variable_ops),
536 !strconcat(instr_asm, "\t$rs, $imm16"), [], IIBranch>;
540 class Mult<bits<6> func, string instr_asm, InstrItinClass itin,
541 RegisterClass RC, list<Register> DefRegs>:
542 FR<0x00, func, (outs), (ins RC:$rs, RC:$rt),
543 !strconcat(instr_asm, "\t$rs, $rt"), [], itin> {
546 let isCommutable = 1;
550 class Mult32<bits<6> func, string instr_asm, InstrItinClass itin>:
551 Mult<func, instr_asm, itin, CPURegs, [HI, LO]>;
553 class Div<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin,
554 RegisterClass RC, list<Register> DefRegs>:
555 FR<0x00, func, (outs), (ins RC:$rs, RC:$rt),
556 !strconcat(instr_asm, "\t$$zero, $rs, $rt"),
557 [(op RC:$rs, RC:$rt)], itin> {
563 class Div32<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin>:
564 Div<op, func, instr_asm, itin, CPURegs, [HI, LO]>;
567 class MoveFromLOHI<bits<6> func, string instr_asm, RegisterClass RC,
568 list<Register> UseRegs>:
569 FR<0x00, func, (outs RC:$rd), (ins),
570 !strconcat(instr_asm, "\t$rd"), [], IIHiLo> {
577 class MoveToLOHI<bits<6> func, string instr_asm, RegisterClass RC,
578 list<Register> DefRegs>:
579 FR<0x00, func, (outs), (ins RC:$rs),
580 !strconcat(instr_asm, "\t$rs"), [], IIHiLo> {
587 class EffectiveAddress<string instr_asm, RegisterClass RC, Operand Mem> :
588 FMem<0x09, (outs RC:$rt), (ins Mem:$addr),
589 instr_asm, [(set RC:$rt, addr:$addr)], IIAlu>;
591 // Count Leading Ones/Zeros in Word
592 class CountLeading0<bits<6> func, string instr_asm, RegisterClass RC>:
593 FR<0x1c, func, (outs RC:$rd), (ins RC:$rs),
594 !strconcat(instr_asm, "\t$rd, $rs"),
595 [(set RC:$rd, (ctlz RC:$rs))], IIAlu>,
596 Requires<[HasBitCount]> {
601 class CountLeading1<bits<6> func, string instr_asm, RegisterClass RC>:
602 FR<0x1c, func, (outs RC:$rd), (ins RC:$rs),
603 !strconcat(instr_asm, "\t$rd, $rs"),
604 [(set RC:$rd, (ctlz (not RC:$rs)))], IIAlu>,
605 Requires<[HasBitCount]> {
610 // Sign Extend in Register.
611 class SignExtInReg<bits<5> sa, string instr_asm, ValueType vt>:
612 FR<0x1f, 0x20, (outs CPURegs:$rd), (ins CPURegs:$rt),
613 !strconcat(instr_asm, "\t$rd, $rt"),
614 [(set CPURegs:$rd, (sext_inreg CPURegs:$rt, vt))], NoItinerary> {
617 let Predicates = [HasSEInReg];
621 class ByteSwap<bits<6> func, bits<5> sa, string instr_asm>:
622 FR<0x1f, func, (outs CPURegs:$rd), (ins CPURegs:$rt),
623 !strconcat(instr_asm, "\t$rd, $rt"),
624 [(set CPURegs:$rd, (bswap CPURegs:$rt))], NoItinerary> {
627 let Predicates = [HasSwap];
631 class ReadHardware<RegisterClass CPURegClass, RegisterClass HWRegClass>
632 : FR<0x1f, 0x3b, (outs CPURegClass:$rt), (ins HWRegClass:$rd),
633 "rdhwr\t$rt, $rd", [], IIAlu> {
639 class ExtBase<bits<6> _funct, string instr_asm, RegisterClass RC>:
640 FR<0x1f, _funct, (outs RC:$rt), (ins RC:$rs, uimm16:$pos, size_ext:$sz),
641 !strconcat(instr_asm, " $rt, $rs, $pos, $sz"),
642 [(set RC:$rt, (MipsExt RC:$rs, imm:$pos, imm:$sz))], NoItinerary> {
647 let Predicates = [HasMips32r2];
650 class InsBase<bits<6> _funct, string instr_asm, RegisterClass RC>:
651 FR<0x1f, _funct, (outs RC:$rt),
652 (ins RC:$rs, uimm16:$pos, size_ins:$sz, RC:$src),
653 !strconcat(instr_asm, " $rt, $rs, $pos, $sz"),
654 [(set RC:$rt, (MipsIns RC:$rs, imm:$pos, imm:$sz, RC:$src))],
660 let Predicates = [HasMips32r2];
661 let Constraints = "$src = $rt";
664 // Atomic instructions with 2 source operands (ATOMIC_SWAP & ATOMIC_LOAD_*).
665 class Atomic2Ops<PatFrag Op, string Opstr, RegisterClass DRC,
667 MipsPseudo<(outs DRC:$dst), (ins PRC:$ptr, DRC:$incr),
668 !strconcat("atomic_", Opstr, "\t$dst, $ptr, $incr"),
669 [(set DRC:$dst, (Op PRC:$ptr, DRC:$incr))]>;
671 multiclass Atomic2Ops32<PatFrag Op, string Opstr> {
672 def #NAME# : Atomic2Ops<Op, Opstr, CPURegs, CPURegs>, Requires<[NotN64]>;
673 def _P8 : Atomic2Ops<Op, Opstr, CPURegs, CPU64Regs>, Requires<[IsN64]>;
676 // Atomic Compare & Swap.
677 class AtomicCmpSwap<PatFrag Op, string Width, RegisterClass DRC,
679 MipsPseudo<(outs DRC:$dst), (ins PRC:$ptr, DRC:$cmp, DRC:$swap),
680 !strconcat("atomic_cmp_swap_", Width, "\t$dst, $ptr, $cmp, $swap"),
681 [(set DRC:$dst, (Op PRC:$ptr, DRC:$cmp, DRC:$swap))]>;
683 multiclass AtomicCmpSwap32<PatFrag Op, string Width> {
684 def #NAME# : AtomicCmpSwap<Op, Width, CPURegs, CPURegs>, Requires<[NotN64]>;
685 def _P8 : AtomicCmpSwap<Op, Width, CPURegs, CPU64Regs>, Requires<[IsN64]>;
688 class LLBase<bits<6> Opc, string opstring, RegisterClass RC, Operand Mem> :
689 FMem<Opc, (outs RC:$rt), (ins Mem:$addr),
690 !strconcat(opstring, "\t$rt, $addr"), [], IILoad> {
694 class SCBase<bits<6> Opc, string opstring, RegisterClass RC, Operand Mem> :
695 FMem<Opc, (outs RC:$dst), (ins RC:$rt, Mem:$addr),
696 !strconcat(opstring, "\t$rt, $addr"), [], IIStore> {
698 let Constraints = "$rt = $dst";
701 //===----------------------------------------------------------------------===//
702 // Pseudo instructions
703 //===----------------------------------------------------------------------===//
705 // As stack alignment is always done with addiu, we need a 16-bit immediate
706 let Defs = [SP], Uses = [SP] in {
707 def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
708 "!ADJCALLSTACKDOWN $amt",
709 [(callseq_start timm:$amt)]>;
710 def ADJCALLSTACKUP : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
711 "!ADJCALLSTACKUP $amt1",
712 [(callseq_end timm:$amt1, timm:$amt2)]>;
715 // Some assembly macros need to avoid pseudoinstructions and assembler
716 // automatic reodering, we should reorder ourselves.
717 def MACRO : MipsPseudo<(outs), (ins), ".set\tmacro", []>;
718 def REORDER : MipsPseudo<(outs), (ins), ".set\treorder", []>;
719 def NOMACRO : MipsPseudo<(outs), (ins), ".set\tnomacro", []>;
720 def NOREORDER : MipsPseudo<(outs), (ins), ".set\tnoreorder", []>;
722 // These macros are inserted to prevent GAS from complaining
723 // when using the AT register.
724 def NOAT : MipsPseudo<(outs), (ins), ".set\tnoat", []>;
725 def ATMACRO : MipsPseudo<(outs), (ins), ".set\tat", []>;
727 // When handling PIC code the assembler needs .cpload and .cprestore
728 // directives. If the real instructions corresponding these directives
729 // are used, we have the same behavior, but get also a bunch of warnings
730 // from the assembler.
731 def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$picreg), ".cpload\t$picreg", []>;
732 def CPRESTORE : MipsPseudo<(outs), (ins i32imm:$loc), ".cprestore\t$loc", []>;
734 let usesCustomInserter = 1 in {
735 defm ATOMIC_LOAD_ADD_I8 : Atomic2Ops32<atomic_load_add_8, "load_add_8">;
736 defm ATOMIC_LOAD_ADD_I16 : Atomic2Ops32<atomic_load_add_16, "load_add_16">;
737 defm ATOMIC_LOAD_ADD_I32 : Atomic2Ops32<atomic_load_add_32, "load_add_32">;
738 defm ATOMIC_LOAD_SUB_I8 : Atomic2Ops32<atomic_load_sub_8, "load_sub_8">;
739 defm ATOMIC_LOAD_SUB_I16 : Atomic2Ops32<atomic_load_sub_16, "load_sub_16">;
740 defm ATOMIC_LOAD_SUB_I32 : Atomic2Ops32<atomic_load_sub_32, "load_sub_32">;
741 defm ATOMIC_LOAD_AND_I8 : Atomic2Ops32<atomic_load_and_8, "load_and_8">;
742 defm ATOMIC_LOAD_AND_I16 : Atomic2Ops32<atomic_load_and_16, "load_and_16">;
743 defm ATOMIC_LOAD_AND_I32 : Atomic2Ops32<atomic_load_and_32, "load_and_32">;
744 defm ATOMIC_LOAD_OR_I8 : Atomic2Ops32<atomic_load_or_8, "load_or_8">;
745 defm ATOMIC_LOAD_OR_I16 : Atomic2Ops32<atomic_load_or_16, "load_or_16">;
746 defm ATOMIC_LOAD_OR_I32 : Atomic2Ops32<atomic_load_or_32, "load_or_32">;
747 defm ATOMIC_LOAD_XOR_I8 : Atomic2Ops32<atomic_load_xor_8, "load_xor_8">;
748 defm ATOMIC_LOAD_XOR_I16 : Atomic2Ops32<atomic_load_xor_16, "load_xor_16">;
749 defm ATOMIC_LOAD_XOR_I32 : Atomic2Ops32<atomic_load_xor_32, "load_xor_32">;
750 defm ATOMIC_LOAD_NAND_I8 : Atomic2Ops32<atomic_load_nand_8, "load_nand_8">;
751 defm ATOMIC_LOAD_NAND_I16 : Atomic2Ops32<atomic_load_nand_16, "load_nand_16">;
752 defm ATOMIC_LOAD_NAND_I32 : Atomic2Ops32<atomic_load_nand_32, "load_nand_32">;
754 defm ATOMIC_SWAP_I8 : Atomic2Ops32<atomic_swap_8, "swap_8">;
755 defm ATOMIC_SWAP_I16 : Atomic2Ops32<atomic_swap_16, "swap_16">;
756 defm ATOMIC_SWAP_I32 : Atomic2Ops32<atomic_swap_32, "swap_32">;
758 defm ATOMIC_CMP_SWAP_I8 : AtomicCmpSwap32<atomic_cmp_swap_8, "8">;
759 defm ATOMIC_CMP_SWAP_I16 : AtomicCmpSwap32<atomic_cmp_swap_16, "16">;
760 defm ATOMIC_CMP_SWAP_I32 : AtomicCmpSwap32<atomic_cmp_swap_32, "32">;
763 //===----------------------------------------------------------------------===//
764 // Instruction definition
765 //===----------------------------------------------------------------------===//
767 //===----------------------------------------------------------------------===//
768 // MipsI Instructions
769 //===----------------------------------------------------------------------===//
771 /// Arithmetic Instructions (ALU Immediate)
772 def ADDiu : ArithLogicI<0x09, "addiu", add, simm16, immSExt16, CPURegs>;
773 def ADDi : ArithOverflowI<0x08, "addi", add, simm16, immSExt16, CPURegs>;
774 def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16, CPURegs>;
775 def SLTiu : SetCC_I<0x0b, "sltiu", setult, simm16, immSExt16, CPURegs>;
776 def ANDi : ArithLogicI<0x0c, "andi", and, uimm16, immZExt16, CPURegs>;
777 def ORi : ArithLogicI<0x0d, "ori", or, uimm16, immZExt16, CPURegs>;
778 def XORi : ArithLogicI<0x0e, "xori", xor, uimm16, immZExt16, CPURegs>;
779 def LUi : LoadUpper<0x0f, "lui", CPURegs, uimm16>;
781 /// Arithmetic Instructions (3-Operand, R-Type)
782 def ADDu : ArithLogicR<0x00, 0x21, "addu", add, IIAlu, CPURegs, 1>;
783 def SUBu : ArithLogicR<0x00, 0x23, "subu", sub, IIAlu, CPURegs>;
784 def ADD : ArithOverflowR<0x00, 0x20, "add", IIAlu, CPURegs, 1>;
785 def SUB : ArithOverflowR<0x00, 0x22, "sub", IIAlu, CPURegs>;
786 def SLT : SetCC_R<0x00, 0x2a, "slt", setlt, CPURegs>;
787 def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult, CPURegs>;
788 def AND : ArithLogicR<0x00, 0x24, "and", and, IIAlu, CPURegs, 1>;
789 def OR : ArithLogicR<0x00, 0x25, "or", or, IIAlu, CPURegs, 1>;
790 def XOR : ArithLogicR<0x00, 0x26, "xor", xor, IIAlu, CPURegs, 1>;
791 def NOR : LogicNOR<0x00, 0x27, "nor", CPURegs>;
793 /// Shift Instructions
794 def SLL : shift_rotate_imm32<0x00, 0x00, "sll", shl>;
795 def SRL : shift_rotate_imm32<0x02, 0x00, "srl", srl>;
796 def SRA : shift_rotate_imm32<0x03, 0x00, "sra", sra>;
797 def SLLV : shift_rotate_reg<0x04, 0x00, "sllv", shl, CPURegs>;
798 def SRLV : shift_rotate_reg<0x06, 0x00, "srlv", srl, CPURegs>;
799 def SRAV : shift_rotate_reg<0x07, 0x00, "srav", sra, CPURegs>;
801 // Rotate Instructions
802 let Predicates = [HasMips32r2] in {
803 def ROTR : shift_rotate_imm32<0x02, 0x01, "rotr", rotr>;
804 def ROTRV : shift_rotate_reg<0x06, 0x01, "rotrv", rotr, CPURegs>;
807 /// Load and Store Instructions
809 defm LB : LoadM32<0x20, "lb", sextloadi8>;
810 defm LBu : LoadM32<0x24, "lbu", zextloadi8>;
811 defm LH : LoadM32<0x21, "lh", sextloadi16_a>;
812 defm LHu : LoadM32<0x25, "lhu", zextloadi16_a>;
813 defm LW : LoadM32<0x23, "lw", load_a>;
814 defm SB : StoreM32<0x28, "sb", truncstorei8>;
815 defm SH : StoreM32<0x29, "sh", truncstorei16_a>;
816 defm SW : StoreM32<0x2b, "sw", store_a>;
819 defm ULH : LoadM32<0x21, "ulh", sextloadi16_u, 1>;
820 defm ULHu : LoadM32<0x25, "ulhu", zextloadi16_u, 1>;
821 defm ULW : LoadM32<0x23, "ulw", load_u, 1>;
822 defm USH : StoreM32<0x29, "ush", truncstorei16_u, 1>;
823 defm USW : StoreM32<0x2b, "usw", store_u, 1>;
825 /// Primitives for unaligned
826 defm LWL : LoadUnAlign32<0x22>;
827 defm LWR : LoadUnAlign32<0x26>;
828 defm SWL : StoreUnAlign32<0x2A>;
829 defm SWR : StoreUnAlign32<0x2E>;
831 let hasSideEffects = 1 in
832 def SYNC : MipsInst<(outs), (ins i32imm:$stype), "sync $stype",
833 [(MipsSync imm:$stype)], NoItinerary, FrmOther>
838 let Inst{10-6} = stype;
842 /// Load-linked, Store-conditional
843 def LL : LLBase<0x30, "ll", CPURegs, mem>, Requires<[NotN64]>;
844 def LL_P8 : LLBase<0x30, "ll", CPURegs, mem64>, Requires<[IsN64]>;
845 def SC : SCBase<0x38, "sc", CPURegs, mem>, Requires<[NotN64]>;
846 def SC_P8 : SCBase<0x38, "sc", CPURegs, mem64>, Requires<[IsN64]>;
848 /// Jump and Branch Instructions
849 def J : JumpFJ<0x02, "j">;
850 def JR : JumpFR<0x00, 0x08, "jr", CPURegs>;
851 def JAL : JumpLink<0x03, "jal">;
852 def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
853 def B : UncondBranch<0x04, "b">;
854 def BEQ : CBranch<0x04, "beq", seteq, CPURegs>;
855 def BNE : CBranch<0x05, "bne", setne, CPURegs>;
856 def BGEZ : CBranchZero<0x01, 1, "bgez", setge, CPURegs>;
857 def BGTZ : CBranchZero<0x07, 0, "bgtz", setgt, CPURegs>;
858 def BLEZ : CBranchZero<0x06, 0, "blez", setle, CPURegs>;
859 def BLTZ : CBranchZero<0x01, 0, "bltz", setlt, CPURegs>;
862 def BGEZAL : BranchLink<"bgezal">;
864 def BLTZAL : BranchLink<"bltzal">;
866 let isReturn=1, isTerminator=1, hasDelaySlot=1,
867 isBarrier=1, hasCtrlDep=1, rd=0, rt=0, shamt=0 in
868 def RET : FR <0x00, 0x08, (outs), (ins CPURegs:$target),
869 "jr\t$target", [(MipsRet CPURegs:$target)], IIBranch>;
871 /// Multiply and Divide Instructions.
872 def MULT : Mult32<0x18, "mult", IIImul>;
873 def MULTu : Mult32<0x19, "multu", IIImul>;
874 def SDIV : Div32<MipsDivRem, 0x1a, "div", IIIdiv>;
875 def UDIV : Div32<MipsDivRemU, 0x1b, "divu", IIIdiv>;
877 def MTHI : MoveToLOHI<0x11, "mthi", CPURegs, [HI]>;
878 def MTLO : MoveToLOHI<0x13, "mtlo", CPURegs, [LO]>;
879 def MFHI : MoveFromLOHI<0x10, "mfhi", CPURegs, [HI]>;
880 def MFLO : MoveFromLOHI<0x12, "mflo", CPURegs, [LO]>;
882 /// Sign Ext In Register Instructions.
883 def SEB : SignExtInReg<0x10, "seb", i8>;
884 def SEH : SignExtInReg<0x18, "seh", i16>;
887 def CLZ : CountLeading0<0x20, "clz", CPURegs>;
888 def CLO : CountLeading1<0x21, "clo", CPURegs>;
891 def WSBW : ByteSwap<0x20, 0x2, "wsbw">;
895 def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
897 // FrameIndexes are legalized when they are operands from load/store
898 // instructions. The same not happens for stack address copies, so an
899 // add op with mem ComplexPattern is used and the stack address copy
900 // can be matched. It's similar to Sparc LEA_ADDRi
901 def LEA_ADDiu : EffectiveAddress<"addiu\t$rt, $addr", CPURegs, mem_ea>;
903 // DynAlloc node points to dynamically allocated stack space.
904 // $sp is added to the list of implicitly used registers to prevent dead code
905 // elimination from removing instructions that modify $sp.
907 def DynAlloc : EffectiveAddress<"addiu\t$rt, $addr", CPURegs, mem_ea>;
910 def MADD : MArithR<0, "madd", MipsMAdd, 1>;
911 def MADDU : MArithR<1, "maddu", MipsMAddu, 1>;
912 def MSUB : MArithR<4, "msub", MipsMSub>;
913 def MSUBU : MArithR<5, "msubu", MipsMSubu>;
915 // MUL is a assembly macro in the current used ISAs. In recent ISA's
916 // it is a real instruction.
917 def MUL : ArithLogicR<0x1c, 0x02, "mul", mul, IIImul, CPURegs, 1>,
918 Requires<[HasMips32]>;
920 def RDHWR : ReadHardware<CPURegs, HWRegs>;
922 def EXT : ExtBase<0, "ext", CPURegs>;
923 def INS : InsBase<4, "ins", CPURegs>;
925 //===----------------------------------------------------------------------===//
926 // Arbitrary patterns that map to one or more instructions
927 //===----------------------------------------------------------------------===//
930 def : Pat<(i32 immSExt16:$in),
931 (ADDiu ZERO, imm:$in)>;
932 def : Pat<(i32 immZExt16:$in),
933 (ORi ZERO, imm:$in)>;
935 // Arbitrary immediates
936 def : Pat<(i32 imm:$imm),
937 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
940 def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
941 (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
942 def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
943 (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
944 def : Pat<(addc CPURegs:$src, immSExt16:$imm),
945 (ADDiu CPURegs:$src, imm:$imm)>;
948 def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
949 (JAL tglobaladdr:$dst)>;
950 def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
951 (JAL texternalsym:$dst)>;
952 //def : Pat<(MipsJmpLink CPURegs:$dst),
953 // (JALR CPURegs:$dst)>;
956 def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
957 def : Pat<(MipsHi tblockaddress:$in), (LUi tblockaddress:$in)>;
958 def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
959 def : Pat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
960 def : Pat<(MipsHi tglobaltlsaddr:$in), (LUi tglobaltlsaddr:$in)>;
962 def : Pat<(MipsLo tglobaladdr:$in), (ADDiu ZERO, tglobaladdr:$in)>;
963 def : Pat<(MipsLo tblockaddress:$in), (ADDiu ZERO, tblockaddress:$in)>;
964 def : Pat<(MipsLo tjumptable:$in), (ADDiu ZERO, tjumptable:$in)>;
965 def : Pat<(MipsLo tconstpool:$in), (ADDiu ZERO, tconstpool:$in)>;
966 def : Pat<(MipsLo tglobaltlsaddr:$in), (ADDiu ZERO, tglobaltlsaddr:$in)>;
968 def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
969 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
970 def : Pat<(add CPURegs:$hi, (MipsLo tblockaddress:$lo)),
971 (ADDiu CPURegs:$hi, tblockaddress:$lo)>;
972 def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
973 (ADDiu CPURegs:$hi, tjumptable:$lo)>;
974 def : Pat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)),
975 (ADDiu CPURegs:$hi, tconstpool:$lo)>;
976 def : Pat<(add CPURegs:$hi, (MipsLo tglobaltlsaddr:$lo)),
977 (ADDiu CPURegs:$hi, tglobaltlsaddr:$lo)>;
980 def : Pat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)),
981 (ADDiu CPURegs:$gp, tglobaladdr:$in)>;
982 def : Pat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)),
983 (ADDiu CPURegs:$gp, tconstpool:$in)>;
986 class WrapperPat<SDNode node, Instruction ADDiuOp, Register GPReg>:
987 Pat<(MipsWrapper node:$in),
988 (ADDiuOp GPReg, node:$in)>;
990 def : WrapperPat<tglobaladdr, ADDiu, GP>;
991 def : WrapperPat<tconstpool, ADDiu, GP>;
992 def : WrapperPat<texternalsym, ADDiu, GP>;
993 def : WrapperPat<tblockaddress, ADDiu, GP>;
994 def : WrapperPat<tjumptable, ADDiu, GP>;
995 def : WrapperPat<tglobaltlsaddr, ADDiu, GP>;
997 // Mips does not have "not", so we expand our way
998 def : Pat<(not CPURegs:$in),
999 (NOR CPURegs:$in, ZERO)>;
1001 // extended load and stores
1002 def : Pat<(extloadi1 addr:$src), (LBu addr:$src)>;
1003 def : Pat<(extloadi8 addr:$src), (LBu addr:$src)>;
1004 def : Pat<(extloadi16_a addr:$src), (LHu addr:$src)>;
1005 def : Pat<(extloadi16_u addr:$src), (ULHu addr:$src)>;
1008 def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
1011 multiclass BrcondPats<RegisterClass RC, Instruction BEQOp, Instruction BNEOp,
1012 Instruction SLTOp, Instruction SLTuOp, Instruction SLTiOp,
1013 Instruction SLTiuOp, Register ZEROReg> {
1014 def : Pat<(brcond (i32 (setne RC:$lhs, 0)), bb:$dst),
1015 (BNEOp RC:$lhs, ZEROReg, bb:$dst)>;
1016 def : Pat<(brcond (i32 (seteq RC:$lhs, 0)), bb:$dst),
1017 (BEQOp RC:$lhs, ZEROReg, bb:$dst)>;
1019 def : Pat<(brcond (i32 (setge RC:$lhs, RC:$rhs)), bb:$dst),
1020 (BEQ (SLTOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>;
1021 def : Pat<(brcond (i32 (setuge RC:$lhs, RC:$rhs)), bb:$dst),
1022 (BEQ (SLTuOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>;
1023 def : Pat<(brcond (i32 (setge RC:$lhs, immSExt16:$rhs)), bb:$dst),
1024 (BEQ (SLTiOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
1025 def : Pat<(brcond (i32 (setuge RC:$lhs, immSExt16:$rhs)), bb:$dst),
1026 (BEQ (SLTiuOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
1028 def : Pat<(brcond (i32 (setle RC:$lhs, RC:$rhs)), bb:$dst),
1029 (BEQ (SLTOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>;
1030 def : Pat<(brcond (i32 (setule RC:$lhs, RC:$rhs)), bb:$dst),
1031 (BEQ (SLTuOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>;
1033 def : Pat<(brcond RC:$cond, bb:$dst),
1034 (BNEOp RC:$cond, ZEROReg, bb:$dst)>;
1037 defm : BrcondPats<CPURegs, BEQ, BNE, SLT, SLTu, SLTi, SLTiu, ZERO>;
1040 multiclass SeteqPats<RegisterClass RC, Instruction SLTiuOp, Instruction XOROp,
1041 Instruction SLTuOp, Register ZEROReg> {
1042 def : Pat<(seteq RC:$lhs, RC:$rhs),
1043 (SLTiuOp (XOROp RC:$lhs, RC:$rhs), 1)>;
1044 def : Pat<(setne RC:$lhs, RC:$rhs),
1045 (SLTuOp ZEROReg, (XOROp RC:$lhs, RC:$rhs))>;
1048 multiclass SetlePats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
1049 def : Pat<(setle RC:$lhs, RC:$rhs),
1050 (XORi (SLTOp RC:$rhs, RC:$lhs), 1)>;
1051 def : Pat<(setule RC:$lhs, RC:$rhs),
1052 (XORi (SLTuOp RC:$rhs, RC:$lhs), 1)>;
1055 multiclass SetgtPats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
1056 def : Pat<(setgt RC:$lhs, RC:$rhs),
1057 (SLTOp RC:$rhs, RC:$lhs)>;
1058 def : Pat<(setugt RC:$lhs, RC:$rhs),
1059 (SLTuOp RC:$rhs, RC:$lhs)>;
1062 multiclass SetgePats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
1063 def : Pat<(setge RC:$lhs, RC:$rhs),
1064 (XORi (SLTOp RC:$lhs, RC:$rhs), 1)>;
1065 def : Pat<(setuge RC:$lhs, RC:$rhs),
1066 (XORi (SLTuOp RC:$lhs, RC:$rhs), 1)>;
1069 multiclass SetgeImmPats<RegisterClass RC, Instruction SLTiOp,
1070 Instruction SLTiuOp> {
1071 def : Pat<(setge RC:$lhs, immSExt16:$rhs),
1072 (XORi (SLTiOp RC:$lhs, immSExt16:$rhs), 1)>;
1073 def : Pat<(setuge RC:$lhs, immSExt16:$rhs),
1074 (XORi (SLTiuOp RC:$lhs, immSExt16:$rhs), 1)>;
1077 defm : SeteqPats<CPURegs, SLTiu, XOR, SLTu, ZERO>;
1078 defm : SetlePats<CPURegs, SLT, SLTu>;
1079 defm : SetgtPats<CPURegs, SLT, SLTu>;
1080 defm : SetgePats<CPURegs, SLT, SLTu>;
1081 defm : SetgeImmPats<CPURegs, SLTi, SLTiu>;
1083 // select MipsDynAlloc
1084 def : Pat<(MipsDynAlloc addr:$f), (DynAlloc addr:$f)>;
1086 //===----------------------------------------------------------------------===//
1087 // Floating Point Support
1088 //===----------------------------------------------------------------------===//
1090 include "MipsInstrFPU.td"
1091 include "Mips64InstrInfo.td"
1092 include "MipsCondMov.td"