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 MipsWrapperPIC : SDNode<"MipsISD::WrapperPIC", 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()">;
136 //===----------------------------------------------------------------------===//
137 // Mips Operand, Complex Patterns and Transformations Definitions.
138 //===----------------------------------------------------------------------===//
140 // Instruction operand types
141 def jmptarget : Operand<OtherVT> {
142 let EncoderMethod = "getJumpTargetOpValue";
144 def brtarget : Operand<OtherVT> {
145 let EncoderMethod = "getBranchTargetOpValue";
146 let OperandType = "OPERAND_PCREL";
148 def calltarget : Operand<iPTR> {
149 let EncoderMethod = "getJumpTargetOpValue";
151 def calltarget64: Operand<i64>;
152 def simm16 : Operand<i32>;
153 def simm16_64 : Operand<i64>;
154 def shamt : Operand<i32>;
157 def uimm16 : Operand<i32> {
158 let PrintMethod = "printUnsignedImm";
162 def mem : Operand<i32> {
163 let PrintMethod = "printMemOperand";
164 let MIOperandInfo = (ops CPURegs, simm16);
165 let EncoderMethod = "getMemEncoding";
168 def mem64 : Operand<i64> {
169 let PrintMethod = "printMemOperand";
170 let MIOperandInfo = (ops CPU64Regs, simm16_64);
173 def mem_ea : Operand<i32> {
174 let PrintMethod = "printMemOperandEA";
175 let MIOperandInfo = (ops CPURegs, simm16);
176 let EncoderMethod = "getMemEncoding";
179 def mem_ea_64 : Operand<i64> {
180 let PrintMethod = "printMemOperandEA";
181 let MIOperandInfo = (ops CPU64Regs, simm16_64);
182 let EncoderMethod = "getMemEncoding";
185 // size operand of ext instruction
186 def size_ext : Operand<i32> {
187 let EncoderMethod = "getSizeExtEncoding";
190 // size operand of ins instruction
191 def size_ins : Operand<i32> {
192 let EncoderMethod = "getSizeInsEncoding";
195 // Transformation Function - get the lower 16 bits.
196 def LO16 : SDNodeXForm<imm, [{
197 return getImm(N, N->getZExtValue() & 0xFFFF);
200 // Transformation Function - get the higher 16 bits.
201 def HI16 : SDNodeXForm<imm, [{
202 return getImm(N, (N->getZExtValue() >> 16) & 0xFFFF);
205 // Node immediate fits as 16-bit sign extended on target immediate.
207 def immSExt16 : PatLeaf<(imm), [{ return isInt<16>(N->getSExtValue()); }]>;
209 // Node immediate fits as 16-bit zero extended on target immediate.
210 // The LO16 param means that only the lower 16 bits of the node
211 // immediate are caught.
213 def immZExt16 : PatLeaf<(imm), [{
214 if (N->getValueType(0) == MVT::i32)
215 return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
217 return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
220 // shamt field must fit in 5 bits.
221 def immZExt5 : ImmLeaf<i32, [{return Imm == (Imm & 0x1f);}]>;
223 // Mips Address Mode! SDNode frameindex could possibily be a match
224 // since load and store instructions from stack used it.
225 def addr : ComplexPattern<iPTR, 2, "SelectAddr", [frameindex], []>;
227 //===----------------------------------------------------------------------===//
228 // Pattern fragment for load/store
229 //===----------------------------------------------------------------------===//
230 class UnalignedLoad<PatFrag Node> : PatFrag<(ops node:$ptr), (Node node:$ptr), [{
231 LoadSDNode *LD = cast<LoadSDNode>(N);
232 return LD->getMemoryVT().getSizeInBits()/8 > LD->getAlignment();
235 class AlignedLoad<PatFrag Node> : PatFrag<(ops node:$ptr), (Node node:$ptr), [{
236 LoadSDNode *LD = cast<LoadSDNode>(N);
237 return LD->getMemoryVT().getSizeInBits()/8 <= LD->getAlignment();
240 class UnalignedStore<PatFrag Node> : PatFrag<(ops node:$val, node:$ptr),
241 (Node node:$val, node:$ptr), [{
242 StoreSDNode *SD = cast<StoreSDNode>(N);
243 return SD->getMemoryVT().getSizeInBits()/8 > SD->getAlignment();
246 class AlignedStore<PatFrag Node> : PatFrag<(ops node:$val, node:$ptr),
247 (Node node:$val, node:$ptr), [{
248 StoreSDNode *SD = cast<StoreSDNode>(N);
249 return SD->getMemoryVT().getSizeInBits()/8 <= SD->getAlignment();
252 // Load/Store PatFrags.
253 def sextloadi16_a : AlignedLoad<sextloadi16>;
254 def zextloadi16_a : AlignedLoad<zextloadi16>;
255 def extloadi16_a : AlignedLoad<extloadi16>;
256 def load_a : AlignedLoad<load>;
257 def sextloadi32_a : AlignedLoad<sextloadi32>;
258 def zextloadi32_a : AlignedLoad<zextloadi32>;
259 def extloadi32_a : AlignedLoad<extloadi32>;
260 def truncstorei16_a : AlignedStore<truncstorei16>;
261 def store_a : AlignedStore<store>;
262 def truncstorei32_a : AlignedStore<truncstorei32>;
263 def sextloadi16_u : UnalignedLoad<sextloadi16>;
264 def zextloadi16_u : UnalignedLoad<zextloadi16>;
265 def extloadi16_u : UnalignedLoad<extloadi16>;
266 def load_u : UnalignedLoad<load>;
267 def sextloadi32_u : UnalignedLoad<sextloadi32>;
268 def zextloadi32_u : UnalignedLoad<zextloadi32>;
269 def extloadi32_u : UnalignedLoad<extloadi32>;
270 def truncstorei16_u : UnalignedStore<truncstorei16>;
271 def store_u : UnalignedStore<store>;
272 def truncstorei32_u : UnalignedStore<truncstorei32>;
274 //===----------------------------------------------------------------------===//
275 // Instructions specific format
276 //===----------------------------------------------------------------------===//
278 // Arithmetic and logical instructions with 3 register operands.
279 class ArithLogicR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
280 InstrItinClass itin, RegisterClass RC, bit isComm = 0>:
281 FR<op, func, (outs RC:$rd), (ins RC:$rs, RC:$rt),
282 !strconcat(instr_asm, "\t$rd, $rs, $rt"),
283 [(set RC:$rd, (OpNode RC:$rs, RC:$rt))], itin> {
285 let isCommutable = isComm;
288 class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm,
289 InstrItinClass itin, RegisterClass RC, bit isComm = 0>:
290 FR<op, func, (outs RC:$rd), (ins RC:$rs, RC:$rt),
291 !strconcat(instr_asm, "\t$rd, $rs, $rt"), [], itin> {
293 let isCommutable = isComm;
296 // Arithmetic and logical instructions with 2 register operands.
297 class ArithLogicI<bits<6> op, string instr_asm, SDNode OpNode,
298 Operand Od, PatLeaf imm_type, RegisterClass RC> :
299 FI<op, (outs RC:$rt), (ins RC:$rs, Od:$imm16),
300 !strconcat(instr_asm, "\t$rt, $rs, $imm16"),
301 [(set RC:$rt, (OpNode RC:$rs, imm_type:$imm16))], IIAlu>;
303 class ArithOverflowI<bits<6> op, string instr_asm, SDNode OpNode,
304 Operand Od, PatLeaf imm_type, RegisterClass RC> :
305 FI<op, (outs RC:$rt), (ins RC:$rs, Od:$imm16),
306 !strconcat(instr_asm, "\t$rt, $rs, $imm16"), [], IIAlu>;
308 // Arithmetic Multiply ADD/SUB
309 let rd = 0, shamt = 0, Defs = [HI, LO], Uses = [HI, LO] in
310 class MArithR<bits<6> func, string instr_asm, SDNode op, bit isComm = 0> :
311 FR<0x1c, func, (outs), (ins CPURegs:$rs, CPURegs:$rt),
312 !strconcat(instr_asm, "\t$rs, $rt"),
313 [(op CPURegs:$rs, CPURegs:$rt, LO, HI)], IIImul> {
316 let isCommutable = isComm;
320 class LogicNOR<bits<6> op, bits<6> func, string instr_asm, RegisterClass RC>:
321 FR<op, func, (outs RC:$rd), (ins RC:$rs, RC:$rt),
322 !strconcat(instr_asm, "\t$rd, $rs, $rt"),
323 [(set RC:$rd, (not (or RC:$rs, RC:$rt)))], IIAlu> {
325 let isCommutable = 1;
329 class shift_rotate_imm<bits<6> func, bits<5> isRotate, string instr_asm,
330 SDNode OpNode, PatFrag PF, Operand ImmOpnd,
332 FR<0x00, func, (outs RC:$rd), (ins RC:$rt, ImmOpnd:$shamt),
333 !strconcat(instr_asm, "\t$rd, $rt, $shamt"),
334 [(set RC:$rd, (OpNode RC:$rt, PF:$shamt))], IIAlu> {
338 // 32-bit shift instructions.
339 class shift_rotate_imm32<bits<6> func, bits<5> isRotate, string instr_asm,
341 shift_rotate_imm<func, isRotate, instr_asm, OpNode, immZExt5, shamt, CPURegs>;
343 class shift_rotate_reg<bits<6> func, bits<5> isRotate, string instr_asm,
344 SDNode OpNode, RegisterClass RC>:
345 FR<0x00, func, (outs RC:$rd), (ins CPURegs:$rs, RC:$rt),
346 !strconcat(instr_asm, "\t$rd, $rt, $rs"),
347 [(set RC:$rd, (OpNode RC:$rt, CPURegs:$rs))], IIAlu> {
348 let shamt = isRotate;
351 // Load Upper Imediate
352 class LoadUpper<bits<6> op, string instr_asm, RegisterClass RC, Operand Imm>:
353 FI<op, (outs RC:$rt), (ins Imm:$imm16),
354 !strconcat(instr_asm, "\t$rt, $imm16"), [], IIAlu> {
358 class FMem<bits<6> op, dag outs, dag ins, string asmstr, list<dag> pattern,
359 InstrItinClass itin>: FFI<op, outs, ins, asmstr, pattern> {
361 let Inst{25-21} = addr{20-16};
362 let Inst{15-0} = addr{15-0};
366 let canFoldAsLoad = 1 in
367 class LoadM<bits<6> op, string instr_asm, PatFrag OpNode, RegisterClass RC,
368 Operand MemOpnd, bit Pseudo>:
369 FMem<op, (outs RC:$rt), (ins MemOpnd:$addr),
370 !strconcat(instr_asm, "\t$rt, $addr"),
371 [(set RC:$rt, (OpNode addr:$addr))], IILoad> {
372 let isPseudo = Pseudo;
375 class StoreM<bits<6> op, string instr_asm, PatFrag OpNode, RegisterClass RC,
376 Operand MemOpnd, bit Pseudo>:
377 FMem<op, (outs), (ins RC:$rt, MemOpnd:$addr),
378 !strconcat(instr_asm, "\t$rt, $addr"),
379 [(OpNode RC:$rt, addr:$addr)], IIStore> {
380 let isPseudo = Pseudo;
383 // Unaligned Memory Load/Store
384 let canFoldAsLoad = 1 in
385 class LoadUnAlign<bits<6> op, RegisterClass RC, Operand MemOpnd>:
386 FMem<op, (outs RC:$rt), (ins MemOpnd:$addr), "", [], IILoad> {}
388 class StoreUnAlign<bits<6> op, RegisterClass RC, Operand MemOpnd>:
389 FMem<op, (outs), (ins RC:$rt, MemOpnd:$addr), "", [], IIStore> {}
392 multiclass LoadM32<bits<6> op, string instr_asm, PatFrag OpNode,
394 def #NAME# : LoadM<op, instr_asm, OpNode, CPURegs, mem, Pseudo>,
396 def _P8 : LoadM<op, instr_asm, OpNode, CPURegs, mem64, Pseudo>,
401 multiclass LoadM64<bits<6> op, string instr_asm, PatFrag OpNode,
403 def #NAME# : LoadM<op, instr_asm, OpNode, CPU64Regs, mem, Pseudo>,
405 def _P8 : LoadM<op, instr_asm, OpNode, CPU64Regs, mem64, Pseudo>,
410 multiclass LoadUnAlign32<bits<6> op> {
411 def #NAME# : LoadUnAlign<op, CPURegs, mem>,
413 def _P8 : LoadUnAlign<op, CPURegs, mem64>,
417 multiclass StoreM32<bits<6> op, string instr_asm, PatFrag OpNode,
419 def #NAME# : StoreM<op, instr_asm, OpNode, CPURegs, mem, Pseudo>,
421 def _P8 : StoreM<op, instr_asm, OpNode, CPURegs, mem64, Pseudo>,
426 multiclass StoreM64<bits<6> op, string instr_asm, PatFrag OpNode,
428 def #NAME# : StoreM<op, instr_asm, OpNode, CPU64Regs, mem, Pseudo>,
430 def _P8 : StoreM<op, instr_asm, OpNode, CPU64Regs, mem64, Pseudo>,
435 multiclass StoreUnAlign32<bits<6> op> {
436 def #NAME# : StoreUnAlign<op, CPURegs, mem>,
438 def _P8 : StoreUnAlign<op, CPURegs, mem64>,
442 // Conditional Branch
443 class CBranch<bits<6> op, string instr_asm, PatFrag cond_op, RegisterClass RC>:
444 BranchBase<op, (outs), (ins RC:$rs, RC:$rt, brtarget:$imm16),
445 !strconcat(instr_asm, "\t$rs, $rt, $imm16"),
446 [(brcond (i32 (cond_op RC:$rs, RC:$rt)), bb:$imm16)], IIBranch> {
448 let isTerminator = 1;
449 let hasDelaySlot = 1;
452 class CBranchZero<bits<6> op, bits<5> _rt, string instr_asm, PatFrag cond_op,
454 BranchBase<op, (outs), (ins RC:$rs, brtarget:$imm16),
455 !strconcat(instr_asm, "\t$rs, $imm16"),
456 [(brcond (i32 (cond_op RC:$rs, 0)), bb:$imm16)], IIBranch> {
459 let isTerminator = 1;
460 let hasDelaySlot = 1;
464 class SetCC_R<bits<6> op, bits<6> func, string instr_asm, PatFrag cond_op,
466 FR<op, func, (outs CPURegs:$rd), (ins RC:$rs, RC:$rt),
467 !strconcat(instr_asm, "\t$rd, $rs, $rt"),
468 [(set CPURegs:$rd, (cond_op RC:$rs, RC:$rt))],
473 class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op, Operand Od,
474 PatLeaf imm_type, RegisterClass RC>:
475 FI<op, (outs CPURegs:$rt), (ins RC:$rs, Od:$imm16),
476 !strconcat(instr_asm, "\t$rt, $rs, $imm16"),
477 [(set CPURegs:$rt, (cond_op RC:$rs, imm_type:$imm16))],
480 // Unconditional branch
481 class UncondBranch<bits<6> op, string instr_asm>:
482 BranchBase<op, (outs), (ins brtarget:$imm16),
483 !strconcat(instr_asm, "\t$imm16"), [(br bb:$imm16)], IIBranch> {
487 let isTerminator = 1;
489 let hasDelaySlot = 1;
492 let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1,
493 isIndirectBranch = 1 in
494 class JumpFR<bits<6> op, bits<6> func, string instr_asm, RegisterClass RC>:
495 FR<op, func, (outs), (ins RC:$rs),
496 !strconcat(instr_asm, "\t$rs"), [(brind RC:$rs)], IIBranch> {
502 // Jump and Link (Call)
503 let isCall=1, hasDelaySlot=1,
504 // All calls clobber the non-callee saved registers...
505 Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9,
506 K0, K1, D0, D1, D2, D3, D4, D5, D6, D7, D8, D9], Uses = [GP] in {
507 class JumpLink<bits<6> op, string instr_asm>:
508 FJ<op, (outs), (ins calltarget:$target, variable_ops),
509 !strconcat(instr_asm, "\t$target"), [(MipsJmpLink imm:$target)],
512 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
513 FR<op, func, (outs), (ins CPURegs:$rs, variable_ops),
514 !strconcat(instr_asm, "\t$rs"), [(MipsJmpLink CPURegs:$rs)], IIBranch> {
520 class BranchLink<string instr_asm>:
521 FI<0x1, (outs), (ins CPURegs:$rs, brtarget:$imm16, variable_ops),
522 !strconcat(instr_asm, "\t$rs, $imm16"), [], IIBranch>;
526 class Mult<bits<6> func, string instr_asm, InstrItinClass itin,
527 RegisterClass RC, list<Register> DefRegs>:
528 FR<0x00, func, (outs), (ins RC:$rs, RC:$rt),
529 !strconcat(instr_asm, "\t$rs, $rt"), [], itin> {
532 let isCommutable = 1;
536 class Mult32<bits<6> func, string instr_asm, InstrItinClass itin>:
537 Mult<func, instr_asm, itin, CPURegs, [HI, LO]>;
539 class Div<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin,
540 RegisterClass RC, list<Register> DefRegs>:
541 FR<0x00, func, (outs), (ins RC:$rs, RC:$rt),
542 !strconcat(instr_asm, "\t$$zero, $rs, $rt"),
543 [(op RC:$rs, RC:$rt)], itin> {
549 class Div32<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin>:
550 Div<op, func, instr_asm, itin, CPURegs, [HI, LO]>;
553 class MoveFromLOHI<bits<6> func, string instr_asm, RegisterClass RC,
554 list<Register> UseRegs>:
555 FR<0x00, func, (outs RC:$rd), (ins),
556 !strconcat(instr_asm, "\t$rd"), [], IIHiLo> {
563 class MoveToLOHI<bits<6> func, string instr_asm, RegisterClass RC,
564 list<Register> DefRegs>:
565 FR<0x00, func, (outs), (ins RC:$rs),
566 !strconcat(instr_asm, "\t$rs"), [], IIHiLo> {
573 class EffectiveAddress<string instr_asm, RegisterClass RC, Operand Mem> :
574 FMem<0x09, (outs RC:$rt), (ins Mem:$addr),
575 instr_asm, [(set RC:$rt, addr:$addr)], IIAlu>;
577 // Count Leading Ones/Zeros in Word
578 class CountLeading0<bits<6> func, string instr_asm, RegisterClass RC>:
579 FR<0x1c, func, (outs RC:$rd), (ins RC:$rs),
580 !strconcat(instr_asm, "\t$rd, $rs"),
581 [(set RC:$rd, (ctlz RC:$rs))], IIAlu>,
582 Requires<[HasBitCount]> {
587 class CountLeading1<bits<6> func, string instr_asm, RegisterClass RC>:
588 FR<0x1c, func, (outs RC:$rd), (ins RC:$rs),
589 !strconcat(instr_asm, "\t$rd, $rs"),
590 [(set RC:$rd, (ctlz (not RC:$rs)))], IIAlu>,
591 Requires<[HasBitCount]> {
596 // Sign Extend in Register.
597 class SignExtInReg<bits<5> sa, string instr_asm, ValueType vt>:
598 FR<0x1f, 0x20, (outs CPURegs:$rd), (ins CPURegs:$rt),
599 !strconcat(instr_asm, "\t$rd, $rt"),
600 [(set CPURegs:$rd, (sext_inreg CPURegs:$rt, vt))], NoItinerary> {
603 let Predicates = [HasSEInReg];
607 class ByteSwap<bits<6> func, bits<5> sa, string instr_asm>:
608 FR<0x1f, func, (outs CPURegs:$rd), (ins CPURegs:$rt),
609 !strconcat(instr_asm, "\t$rd, $rt"),
610 [(set CPURegs:$rd, (bswap CPURegs:$rt))], NoItinerary> {
613 let Predicates = [HasSwap];
617 class ReadHardware: FR<0x1f, 0x3b, (outs CPURegs:$rt), (ins HWRegs:$rd),
618 "rdhwr\t$rt, $rd", [], IIAlu> {
624 class ExtBase<bits<6> _funct, string instr_asm, RegisterClass RC>:
625 FR<0x1f, _funct, (outs RC:$rt), (ins RC:$rs, uimm16:$pos, size_ext:$sz),
626 !strconcat(instr_asm, " $rt, $rs, $pos, $sz"),
627 [(set RC:$rt, (MipsExt RC:$rs, imm:$pos, imm:$sz))], NoItinerary> {
632 let Predicates = [HasMips32r2];
635 class InsBase<bits<6> _funct, string instr_asm, RegisterClass RC>:
636 FR<0x1f, _funct, (outs RC:$rt),
637 (ins RC:$rs, uimm16:$pos, size_ins:$sz, RC:$src),
638 !strconcat(instr_asm, " $rt, $rs, $pos, $sz"),
639 [(set RC:$rt, (MipsIns RC:$rs, imm:$pos, imm:$sz, RC:$src))],
645 let Predicates = [HasMips32r2];
646 let Constraints = "$src = $rt";
649 // Atomic instructions with 2 source operands (ATOMIC_SWAP & ATOMIC_LOAD_*).
650 class Atomic2Ops<PatFrag Op, string Opstr, RegisterClass DRC,
652 MipsPseudo<(outs DRC:$dst), (ins PRC:$ptr, DRC:$incr),
653 !strconcat("atomic_", Opstr, "\t$dst, $ptr, $incr"),
654 [(set DRC:$dst, (Op PRC:$ptr, DRC:$incr))]>;
656 multiclass Atomic2Ops32<PatFrag Op, string Opstr> {
657 def #NAME# : Atomic2Ops<Op, Opstr, CPURegs, CPURegs>, Requires<[NotN64]>;
658 def _P8 : Atomic2Ops<Op, Opstr, CPURegs, CPU64Regs>, Requires<[IsN64]>;
661 // Atomic Compare & Swap.
662 class AtomicCmpSwap<PatFrag Op, string Width, RegisterClass DRC,
664 MipsPseudo<(outs DRC:$dst), (ins PRC:$ptr, DRC:$cmp, DRC:$swap),
665 !strconcat("atomic_cmp_swap_", Width, "\t$dst, $ptr, $cmp, $swap"),
666 [(set DRC:$dst, (Op PRC:$ptr, DRC:$cmp, DRC:$swap))]>;
668 multiclass AtomicCmpSwap32<PatFrag Op, string Width> {
669 def #NAME# : AtomicCmpSwap<Op, Width, CPURegs, CPURegs>, Requires<[NotN64]>;
670 def _P8 : AtomicCmpSwap<Op, Width, CPURegs, CPU64Regs>, Requires<[IsN64]>;
673 class LLBase<bits<6> Opc, string opstring, RegisterClass RC, Operand Mem> :
674 FMem<Opc, (outs RC:$rt), (ins Mem:$addr),
675 !strconcat(opstring, "\t$rt, $addr"), [], IILoad> {
679 class SCBase<bits<6> Opc, string opstring, RegisterClass RC, Operand Mem> :
680 FMem<Opc, (outs RC:$dst), (ins RC:$rt, Mem:$addr),
681 !strconcat(opstring, "\t$rt, $addr"), [], IIStore> {
683 let Constraints = "$rt = $dst";
686 //===----------------------------------------------------------------------===//
687 // Pseudo instructions
688 //===----------------------------------------------------------------------===//
690 // As stack alignment is always done with addiu, we need a 16-bit immediate
691 let Defs = [SP], Uses = [SP] in {
692 def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
693 "!ADJCALLSTACKDOWN $amt",
694 [(callseq_start timm:$amt)]>;
695 def ADJCALLSTACKUP : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
696 "!ADJCALLSTACKUP $amt1",
697 [(callseq_end timm:$amt1, timm:$amt2)]>;
700 // Some assembly macros need to avoid pseudoinstructions and assembler
701 // automatic reodering, we should reorder ourselves.
702 def MACRO : MipsPseudo<(outs), (ins), ".set\tmacro", []>;
703 def REORDER : MipsPseudo<(outs), (ins), ".set\treorder", []>;
704 def NOMACRO : MipsPseudo<(outs), (ins), ".set\tnomacro", []>;
705 def NOREORDER : MipsPseudo<(outs), (ins), ".set\tnoreorder", []>;
707 // These macros are inserted to prevent GAS from complaining
708 // when using the AT register.
709 def NOAT : MipsPseudo<(outs), (ins), ".set\tnoat", []>;
710 def ATMACRO : MipsPseudo<(outs), (ins), ".set\tat", []>;
712 // When handling PIC code the assembler needs .cpload and .cprestore
713 // directives. If the real instructions corresponding these directives
714 // are used, we have the same behavior, but get also a bunch of warnings
715 // from the assembler.
716 def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$picreg), ".cpload\t$picreg", []>;
717 def CPRESTORE : MipsPseudo<(outs), (ins i32imm:$loc), ".cprestore\t$loc", []>;
719 let usesCustomInserter = 1 in {
720 defm ATOMIC_LOAD_ADD_I8 : Atomic2Ops32<atomic_load_add_8, "load_add_8">;
721 defm ATOMIC_LOAD_ADD_I16 : Atomic2Ops32<atomic_load_add_16, "load_add_16">;
722 defm ATOMIC_LOAD_ADD_I32 : Atomic2Ops32<atomic_load_add_32, "load_add_32">;
723 defm ATOMIC_LOAD_SUB_I8 : Atomic2Ops32<atomic_load_sub_8, "load_sub_8">;
724 defm ATOMIC_LOAD_SUB_I16 : Atomic2Ops32<atomic_load_sub_16, "load_sub_16">;
725 defm ATOMIC_LOAD_SUB_I32 : Atomic2Ops32<atomic_load_sub_32, "load_sub_32">;
726 defm ATOMIC_LOAD_AND_I8 : Atomic2Ops32<atomic_load_and_8, "load_and_8">;
727 defm ATOMIC_LOAD_AND_I16 : Atomic2Ops32<atomic_load_and_16, "load_and_16">;
728 defm ATOMIC_LOAD_AND_I32 : Atomic2Ops32<atomic_load_and_32, "load_and_32">;
729 defm ATOMIC_LOAD_OR_I8 : Atomic2Ops32<atomic_load_or_8, "load_or_8">;
730 defm ATOMIC_LOAD_OR_I16 : Atomic2Ops32<atomic_load_or_16, "load_or_16">;
731 defm ATOMIC_LOAD_OR_I32 : Atomic2Ops32<atomic_load_or_32, "load_or_32">;
732 defm ATOMIC_LOAD_XOR_I8 : Atomic2Ops32<atomic_load_xor_8, "load_xor_8">;
733 defm ATOMIC_LOAD_XOR_I16 : Atomic2Ops32<atomic_load_xor_16, "load_xor_16">;
734 defm ATOMIC_LOAD_XOR_I32 : Atomic2Ops32<atomic_load_xor_32, "load_xor_32">;
735 defm ATOMIC_LOAD_NAND_I8 : Atomic2Ops32<atomic_load_nand_8, "load_nand_8">;
736 defm ATOMIC_LOAD_NAND_I16 : Atomic2Ops32<atomic_load_nand_16, "load_nand_16">;
737 defm ATOMIC_LOAD_NAND_I32 : Atomic2Ops32<atomic_load_nand_32, "load_nand_32">;
739 defm ATOMIC_SWAP_I8 : Atomic2Ops32<atomic_swap_8, "swap_8">;
740 defm ATOMIC_SWAP_I16 : Atomic2Ops32<atomic_swap_16, "swap_16">;
741 defm ATOMIC_SWAP_I32 : Atomic2Ops32<atomic_swap_32, "swap_32">;
743 defm ATOMIC_CMP_SWAP_I8 : AtomicCmpSwap32<atomic_cmp_swap_8, "8">;
744 defm ATOMIC_CMP_SWAP_I16 : AtomicCmpSwap32<atomic_cmp_swap_16, "16">;
745 defm ATOMIC_CMP_SWAP_I32 : AtomicCmpSwap32<atomic_cmp_swap_32, "32">;
748 //===----------------------------------------------------------------------===//
749 // Instruction definition
750 //===----------------------------------------------------------------------===//
752 //===----------------------------------------------------------------------===//
753 // MipsI Instructions
754 //===----------------------------------------------------------------------===//
756 /// Arithmetic Instructions (ALU Immediate)
757 def ADDiu : ArithLogicI<0x09, "addiu", add, simm16, immSExt16, CPURegs>;
758 def ADDi : ArithOverflowI<0x08, "addi", add, simm16, immSExt16, CPURegs>;
759 def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16, CPURegs>;
760 def SLTiu : SetCC_I<0x0b, "sltiu", setult, simm16, immSExt16, CPURegs>;
761 def ANDi : ArithLogicI<0x0c, "andi", and, uimm16, immZExt16, CPURegs>;
762 def ORi : ArithLogicI<0x0d, "ori", or, uimm16, immZExt16, CPURegs>;
763 def XORi : ArithLogicI<0x0e, "xori", xor, uimm16, immZExt16, CPURegs>;
764 def LUi : LoadUpper<0x0f, "lui", CPURegs, uimm16>;
766 /// Arithmetic Instructions (3-Operand, R-Type)
767 def ADDu : ArithLogicR<0x00, 0x21, "addu", add, IIAlu, CPURegs, 1>;
768 def SUBu : ArithLogicR<0x00, 0x23, "subu", sub, IIAlu, CPURegs>;
769 def ADD : ArithOverflowR<0x00, 0x20, "add", IIAlu, CPURegs, 1>;
770 def SUB : ArithOverflowR<0x00, 0x22, "sub", IIAlu, CPURegs>;
771 def SLT : SetCC_R<0x00, 0x2a, "slt", setlt, CPURegs>;
772 def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult, CPURegs>;
773 def AND : ArithLogicR<0x00, 0x24, "and", and, IIAlu, CPURegs, 1>;
774 def OR : ArithLogicR<0x00, 0x25, "or", or, IIAlu, CPURegs, 1>;
775 def XOR : ArithLogicR<0x00, 0x26, "xor", xor, IIAlu, CPURegs, 1>;
776 def NOR : LogicNOR<0x00, 0x27, "nor", CPURegs>;
778 /// Shift Instructions
779 def SLL : shift_rotate_imm32<0x00, 0x00, "sll", shl>;
780 def SRL : shift_rotate_imm32<0x02, 0x00, "srl", srl>;
781 def SRA : shift_rotate_imm32<0x03, 0x00, "sra", sra>;
782 def SLLV : shift_rotate_reg<0x04, 0x00, "sllv", shl, CPURegs>;
783 def SRLV : shift_rotate_reg<0x06, 0x00, "srlv", srl, CPURegs>;
784 def SRAV : shift_rotate_reg<0x07, 0x00, "srav", sra, CPURegs>;
786 // Rotate Instructions
787 let Predicates = [HasMips32r2] in {
788 def ROTR : shift_rotate_imm32<0x02, 0x01, "rotr", rotr>;
789 def ROTRV : shift_rotate_reg<0x06, 0x01, "rotrv", rotr, CPURegs>;
792 /// Load and Store Instructions
794 defm LB : LoadM32<0x20, "lb", sextloadi8>;
795 defm LBu : LoadM32<0x24, "lbu", zextloadi8>;
796 defm LH : LoadM32<0x21, "lh", sextloadi16_a>;
797 defm LHu : LoadM32<0x25, "lhu", zextloadi16_a>;
798 defm LW : LoadM32<0x23, "lw", load_a>;
799 defm SB : StoreM32<0x28, "sb", truncstorei8>;
800 defm SH : StoreM32<0x29, "sh", truncstorei16_a>;
801 defm SW : StoreM32<0x2b, "sw", store_a>;
804 defm ULH : LoadM32<0x21, "ulh", sextloadi16_u, 1>;
805 defm ULHu : LoadM32<0x25, "ulhu", zextloadi16_u, 1>;
806 defm ULW : LoadM32<0x23, "ulw", load_u, 1>;
807 defm USH : StoreM32<0x29, "ush", truncstorei16_u, 1>;
808 defm USW : StoreM32<0x2b, "usw", store_u, 1>;
810 /// Primitives for unaligned
811 defm LWL : LoadUnAlign32<0x22>;
812 defm LWR : LoadUnAlign32<0x26>;
813 defm SWL : StoreUnAlign32<0x2A>;
814 defm SWR : StoreUnAlign32<0x2E>;
816 let hasSideEffects = 1 in
817 def SYNC : MipsInst<(outs), (ins i32imm:$stype), "sync $stype",
818 [(MipsSync imm:$stype)], NoItinerary, FrmOther>
823 let Inst{10-6} = stype;
827 /// Load-linked, Store-conditional
828 def LL : LLBase<0x30, "ll", CPURegs, mem>, Requires<[NotN64]>;
829 def LL_P8 : LLBase<0x30, "ll", CPURegs, mem64>, Requires<[IsN64]>;
830 def SC : SCBase<0x38, "sc", CPURegs, mem>, Requires<[NotN64]>;
831 def SC_P8 : SCBase<0x38, "sc", CPURegs, mem64>, Requires<[IsN64]>;
833 /// Jump and Branch Instructions
834 def JR : JumpFR<0x00, 0x08, "jr", CPURegs>;
835 def JAL : JumpLink<0x03, "jal">;
836 def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
837 def B : UncondBranch<0x04, "b">;
838 def BEQ : CBranch<0x04, "beq", seteq, CPURegs>;
839 def BNE : CBranch<0x05, "bne", setne, CPURegs>;
840 def BGEZ : CBranchZero<0x01, 1, "bgez", setge, CPURegs>;
841 def BGTZ : CBranchZero<0x07, 0, "bgtz", setgt, CPURegs>;
842 def BLEZ : CBranchZero<0x06, 0, "blez", setle, CPURegs>;
843 def BLTZ : CBranchZero<0x01, 0, "bltz", setlt, CPURegs>;
846 def BGEZAL : BranchLink<"bgezal">;
848 def BLTZAL : BranchLink<"bltzal">;
850 let isReturn=1, isTerminator=1, hasDelaySlot=1,
851 isBarrier=1, hasCtrlDep=1, rd=0, rt=0, shamt=0 in
852 def RET : FR <0x00, 0x08, (outs), (ins CPURegs:$target),
853 "jr\t$target", [(MipsRet CPURegs:$target)], IIBranch>;
855 /// Multiply and Divide Instructions.
856 def MULT : Mult32<0x18, "mult", IIImul>;
857 def MULTu : Mult32<0x19, "multu", IIImul>;
858 def SDIV : Div32<MipsDivRem, 0x1a, "div", IIIdiv>;
859 def UDIV : Div32<MipsDivRemU, 0x1b, "divu", IIIdiv>;
861 def MTHI : MoveToLOHI<0x11, "mthi", CPURegs, [HI]>;
862 def MTLO : MoveToLOHI<0x13, "mtlo", CPURegs, [LO]>;
863 def MFHI : MoveFromLOHI<0x10, "mfhi", CPURegs, [HI]>;
864 def MFLO : MoveFromLOHI<0x12, "mflo", CPURegs, [LO]>;
866 /// Sign Ext In Register Instructions.
867 def SEB : SignExtInReg<0x10, "seb", i8>;
868 def SEH : SignExtInReg<0x18, "seh", i16>;
871 def CLZ : CountLeading0<0x20, "clz", CPURegs>;
872 def CLO : CountLeading1<0x21, "clo", CPURegs>;
875 def WSBW : ByteSwap<0x20, 0x2, "wsbw">;
879 def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
881 // FrameIndexes are legalized when they are operands from load/store
882 // instructions. The same not happens for stack address copies, so an
883 // add op with mem ComplexPattern is used and the stack address copy
884 // can be matched. It's similar to Sparc LEA_ADDRi
885 def LEA_ADDiu : EffectiveAddress<"addiu\t$rt, $addr", CPURegs, mem_ea>;
887 // DynAlloc node points to dynamically allocated stack space.
888 // $sp is added to the list of implicitly used registers to prevent dead code
889 // elimination from removing instructions that modify $sp.
891 def DynAlloc : EffectiveAddress<"addiu\t$rt, $addr", CPURegs, mem_ea>;
894 def MADD : MArithR<0, "madd", MipsMAdd, 1>;
895 def MADDU : MArithR<1, "maddu", MipsMAddu, 1>;
896 def MSUB : MArithR<4, "msub", MipsMSub>;
897 def MSUBU : MArithR<5, "msubu", MipsMSubu>;
899 // MUL is a assembly macro in the current used ISAs. In recent ISA's
900 // it is a real instruction.
901 def MUL : ArithLogicR<0x1c, 0x02, "mul", mul, IIImul, CPURegs, 1>,
902 Requires<[HasMips32]>;
904 def RDHWR : ReadHardware;
906 def EXT : ExtBase<0, "ext", CPURegs>;
907 def INS : InsBase<4, "ins", CPURegs>;
909 //===----------------------------------------------------------------------===//
910 // Arbitrary patterns that map to one or more instructions
911 //===----------------------------------------------------------------------===//
914 def : Pat<(i32 immSExt16:$in),
915 (ADDiu ZERO, imm:$in)>;
916 def : Pat<(i32 immZExt16:$in),
917 (ORi ZERO, imm:$in)>;
919 // Arbitrary immediates
920 def : Pat<(i32 imm:$imm),
921 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
924 def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
925 (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
926 def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
927 (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
928 def : Pat<(addc CPURegs:$src, immSExt16:$imm),
929 (ADDiu CPURegs:$src, imm:$imm)>;
932 def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
933 (JAL tglobaladdr:$dst)>;
934 def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
935 (JAL texternalsym:$dst)>;
936 //def : Pat<(MipsJmpLink CPURegs:$dst),
937 // (JALR CPURegs:$dst)>;
940 def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
941 def : Pat<(MipsHi tblockaddress:$in), (LUi tblockaddress:$in)>;
942 def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
943 def : Pat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
945 def : Pat<(MipsLo tglobaladdr:$in), (ADDiu ZERO, tglobaladdr:$in)>;
946 def : Pat<(MipsLo tblockaddress:$in), (ADDiu ZERO, tblockaddress:$in)>;
947 def : Pat<(MipsLo tjumptable:$in), (ADDiu ZERO, tjumptable:$in)>;
948 def : Pat<(MipsLo tconstpool:$in), (ADDiu ZERO, tconstpool:$in)>;
950 def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
951 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
952 def : Pat<(add CPURegs:$hi, (MipsLo tblockaddress:$lo)),
953 (ADDiu CPURegs:$hi, tblockaddress:$lo)>;
954 def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
955 (ADDiu CPURegs:$hi, tjumptable:$lo)>;
956 def : Pat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)),
957 (ADDiu CPURegs:$hi, tconstpool:$lo)>;
960 def : Pat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)),
961 (ADDiu CPURegs:$gp, tglobaladdr:$in)>;
962 def : Pat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)),
963 (ADDiu CPURegs:$gp, tconstpool:$in)>;
966 def : Pat<(add CPURegs:$gp, (MipsTlsGd tglobaltlsaddr:$in)),
967 (ADDiu CPURegs:$gp, tglobaltlsaddr:$in)>;
970 def : Pat<(MipsTprelHi tglobaltlsaddr:$in), (LUi tglobaltlsaddr:$in)>;
971 def : Pat<(MipsTprelLo tglobaltlsaddr:$in), (ADDiu ZERO, tglobaltlsaddr:$in)>;
972 def : Pat<(add CPURegs:$hi, (MipsTprelLo tglobaltlsaddr:$lo)),
973 (ADDiu CPURegs:$hi, tglobaltlsaddr:$lo)>;
976 class WrapperPICPat<SDNode node, Instruction ADDiuOp, Register GPReg>:
977 Pat<(MipsWrapperPIC node:$in),
978 (ADDiuOp GPReg, node:$in)>;
980 def : WrapperPICPat<tglobaladdr, ADDiu, GP>;
981 def : WrapperPICPat<tconstpool, ADDiu, GP>;
982 def : WrapperPICPat<texternalsym, ADDiu, GP>;
983 def : WrapperPICPat<tblockaddress, ADDiu, GP>;
984 def : WrapperPICPat<tjumptable, ADDiu, GP>;
986 // Mips does not have "not", so we expand our way
987 def : Pat<(not CPURegs:$in),
988 (NOR CPURegs:$in, ZERO)>;
990 // extended load and stores
991 def : Pat<(extloadi1 addr:$src), (LBu addr:$src)>;
992 def : Pat<(extloadi8 addr:$src), (LBu addr:$src)>;
993 def : Pat<(extloadi16_a addr:$src), (LHu addr:$src)>;
994 def : Pat<(extloadi16_u addr:$src), (ULHu addr:$src)>;
997 def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
1000 multiclass BrcondPats<RegisterClass RC, Instruction BEQOp, Instruction BNEOp,
1001 Instruction SLTOp, Instruction SLTuOp, Instruction SLTiOp,
1002 Instruction SLTiuOp, Register ZEROReg> {
1003 def : Pat<(brcond (i32 (setne RC:$lhs, 0)), bb:$dst),
1004 (BNEOp RC:$lhs, ZEROReg, bb:$dst)>;
1005 def : Pat<(brcond (i32 (seteq RC:$lhs, 0)), bb:$dst),
1006 (BEQOp RC:$lhs, ZEROReg, bb:$dst)>;
1008 def : Pat<(brcond (i32 (setge RC:$lhs, RC:$rhs)), bb:$dst),
1009 (BEQ (SLTOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>;
1010 def : Pat<(brcond (i32 (setuge RC:$lhs, RC:$rhs)), bb:$dst),
1011 (BEQ (SLTuOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>;
1012 def : Pat<(brcond (i32 (setge RC:$lhs, immSExt16:$rhs)), bb:$dst),
1013 (BEQ (SLTiOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
1014 def : Pat<(brcond (i32 (setuge RC:$lhs, immSExt16:$rhs)), bb:$dst),
1015 (BEQ (SLTiuOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
1017 def : Pat<(brcond (i32 (setle RC:$lhs, RC:$rhs)), bb:$dst),
1018 (BEQ (SLTOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>;
1019 def : Pat<(brcond (i32 (setule RC:$lhs, RC:$rhs)), bb:$dst),
1020 (BEQ (SLTuOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>;
1022 def : Pat<(brcond RC:$cond, bb:$dst),
1023 (BNEOp RC:$cond, ZEROReg, bb:$dst)>;
1026 defm : BrcondPats<CPURegs, BEQ, BNE, SLT, SLTu, SLTi, SLTiu, ZERO>;
1029 multiclass SeteqPats<RegisterClass RC, Instruction SLTiuOp, Instruction XOROp,
1030 Instruction SLTuOp, Register ZEROReg> {
1031 def : Pat<(seteq RC:$lhs, RC:$rhs),
1032 (SLTiuOp (XOROp RC:$lhs, RC:$rhs), 1)>;
1033 def : Pat<(setne RC:$lhs, RC:$rhs),
1034 (SLTuOp ZEROReg, (XOROp RC:$lhs, RC:$rhs))>;
1037 multiclass SetlePats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
1038 def : Pat<(setle RC:$lhs, RC:$rhs),
1039 (XORi (SLTOp RC:$rhs, RC:$lhs), 1)>;
1040 def : Pat<(setule RC:$lhs, RC:$rhs),
1041 (XORi (SLTuOp RC:$rhs, RC:$lhs), 1)>;
1044 multiclass SetgtPats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
1045 def : Pat<(setgt RC:$lhs, RC:$rhs),
1046 (SLTOp RC:$rhs, RC:$lhs)>;
1047 def : Pat<(setugt RC:$lhs, RC:$rhs),
1048 (SLTuOp RC:$rhs, RC:$lhs)>;
1051 multiclass SetgePats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
1052 def : Pat<(setge RC:$lhs, RC:$rhs),
1053 (XORi (SLTOp RC:$lhs, RC:$rhs), 1)>;
1054 def : Pat<(setuge RC:$lhs, RC:$rhs),
1055 (XORi (SLTuOp RC:$lhs, RC:$rhs), 1)>;
1058 multiclass SetgeImmPats<RegisterClass RC, Instruction SLTiOp,
1059 Instruction SLTiuOp> {
1060 def : Pat<(setge RC:$lhs, immSExt16:$rhs),
1061 (XORi (SLTiOp RC:$lhs, immSExt16:$rhs), 1)>;
1062 def : Pat<(setuge RC:$lhs, immSExt16:$rhs),
1063 (XORi (SLTiuOp RC:$lhs, immSExt16:$rhs), 1)>;
1066 defm : SeteqPats<CPURegs, SLTiu, XOR, SLTu, ZERO>;
1067 defm : SetlePats<CPURegs, SLT, SLTu>;
1068 defm : SetgtPats<CPURegs, SLT, SLTu>;
1069 defm : SetgePats<CPURegs, SLT, SLTu>;
1070 defm : SetgeImmPats<CPURegs, SLTi, SLTiu>;
1072 // select MipsDynAlloc
1073 def : Pat<(MipsDynAlloc addr:$f), (DynAlloc addr:$f)>;
1075 //===----------------------------------------------------------------------===//
1076 // Floating Point Support
1077 //===----------------------------------------------------------------------===//
1079 include "MipsInstrFPU.td"
1080 include "Mips64InstrInfo.td"
1081 include "MipsCondMov.td"