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,
41 def MipsJmpLink : SDNode<"MipsISD::JmpLink",SDT_MipsJmpLink,
42 [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue,
45 // Hi and Lo nodes are used to handle global addresses. Used on
46 // MipsISelLowering to lower stuff like GlobalAddress, ExternalSymbol
47 // static model. (nothing to do with Mips Registers Hi and Lo)
48 def MipsHi : SDNode<"MipsISD::Hi", SDTIntUnaryOp>;
49 def MipsLo : SDNode<"MipsISD::Lo", SDTIntUnaryOp>;
50 def MipsGPRel : SDNode<"MipsISD::GPRel", SDTIntUnaryOp>;
53 def MipsRet : SDNode<"MipsISD::Ret", SDT_MipsRet, [SDNPHasChain,
56 // These are target-independent nodes, but have target-specific formats.
57 def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_MipsCallSeqStart,
58 [SDNPHasChain, SDNPOutGlue]>;
59 def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_MipsCallSeqEnd,
60 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
63 def MipsMAdd : SDNode<"MipsISD::MAdd", SDT_MipsMAddMSub,
64 [SDNPOptInGlue, SDNPOutGlue]>;
65 def MipsMAddu : SDNode<"MipsISD::MAddu", SDT_MipsMAddMSub,
66 [SDNPOptInGlue, SDNPOutGlue]>;
67 def MipsMSub : SDNode<"MipsISD::MSub", SDT_MipsMAddMSub,
68 [SDNPOptInGlue, SDNPOutGlue]>;
69 def MipsMSubu : SDNode<"MipsISD::MSubu", SDT_MipsMAddMSub,
70 [SDNPOptInGlue, SDNPOutGlue]>;
73 def MipsDivRem : SDNode<"MipsISD::DivRem", SDT_MipsDivRem,
75 def MipsDivRemU : SDNode<"MipsISD::DivRemU", SDT_MipsDivRem,
78 //===----------------------------------------------------------------------===//
79 // Mips Instruction Predicate Definitions.
80 //===----------------------------------------------------------------------===//
81 def HasSEInReg : Predicate<"Subtarget.hasSEInReg()">;
82 def HasBitCount : Predicate<"Subtarget.hasBitCount()">;
83 def HasSwap : Predicate<"Subtarget.hasSwap()">;
84 def HasCondMov : Predicate<"Subtarget.hasCondMov()">;
85 def IsMips32 : Predicate<"Subtarget.isMips32()">;
86 def IsMips32r2 : Predicate<"Subtarget.isMips32r2()">;
88 //===----------------------------------------------------------------------===//
89 // Mips Operand, Complex Patterns and Transformations Definitions.
90 //===----------------------------------------------------------------------===//
92 // Instruction operand types
93 def brtarget : Operand<OtherVT>;
94 def calltarget : Operand<i32>;
95 def simm16 : Operand<i32>;
96 def shamt : Operand<i32>;
99 def uimm16 : Operand<i32> {
100 let PrintMethod = "printUnsignedImm";
104 def mem : Operand<i32> {
105 let PrintMethod = "printMemOperand";
106 let MIOperandInfo = (ops simm16, CPURegs);
109 // Transformation Function - get the lower 16 bits.
110 def LO16 : SDNodeXForm<imm, [{
111 return getI32Imm((unsigned)N->getZExtValue() & 0xFFFF);
114 // Transformation Function - get the higher 16 bits.
115 def HI16 : SDNodeXForm<imm, [{
116 return getI32Imm((unsigned)N->getZExtValue() >> 16);
119 // Node immediate fits as 16-bit sign extended on target immediate.
121 def immSExt16 : PatLeaf<(imm), [{ return isInt<16>(N->getSExtValue()); }]>;
123 // Node immediate fits as 16-bit zero extended on target immediate.
124 // The LO16 param means that only the lower 16 bits of the node
125 // immediate are caught.
127 def immZExt16 : PatLeaf<(imm), [{
128 if (N->getValueType(0) == MVT::i32)
129 return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
131 return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
134 // shamt field must fit in 5 bits.
135 def immZExt5 : PatLeaf<(imm), [{
136 return N->getZExtValue() == ((N->getZExtValue()) & 0x1f) ;
139 // Mips Address Mode! SDNode frameindex could possibily be a match
140 // since load and store instructions from stack used it.
141 def addr : ComplexPattern<iPTR, 2, "SelectAddr", [frameindex], []>;
143 //===----------------------------------------------------------------------===//
144 // Instructions specific format
145 //===----------------------------------------------------------------------===//
147 // Arithmetic 3 register operands
148 class ArithR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
149 InstrItinClass itin, bit isComm = 0>:
150 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
151 !strconcat(instr_asm, "\t$dst, $b, $c"),
152 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], itin> {
153 let isCommutable = isComm;
156 class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm,
158 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
159 !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu> {
160 let isCommutable = isComm;
163 // Arithmetic 2 register operands
164 class ArithI<bits<6> op, string instr_asm, SDNode OpNode,
165 Operand Od, PatLeaf imm_type> :
166 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
167 !strconcat(instr_asm, "\t$dst, $b, $c"),
168 [(set CPURegs:$dst, (OpNode CPURegs:$b, imm_type:$c))], IIAlu>;
170 class ArithOverflowI<bits<6> op, string instr_asm, SDNode OpNode,
171 Operand Od, PatLeaf imm_type> :
172 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
173 !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu>;
175 // Arithmetic Multiply ADD/SUB
176 let rd = 0, shamt = 0, Defs = [HI, LO], Uses = [HI, LO] in
177 class MArithR<bits<6> func, string instr_asm, SDNode op, bit isComm = 0> :
178 FR<0x1c, func, (outs), (ins CPURegs:$rs, CPURegs:$rt),
179 !strconcat(instr_asm, "\t$rs, $rt"),
180 [(op CPURegs:$rs, CPURegs:$rt, LO, HI)], IIImul> {
181 let isCommutable = isComm;
185 let isCommutable = 1 in
186 class LogicR<bits<6> func, string instr_asm, SDNode OpNode>:
187 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
188 !strconcat(instr_asm, "\t$dst, $b, $c"),
189 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
191 class LogicI<bits<6> op, string instr_asm, SDNode OpNode>:
192 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, uimm16:$c),
193 !strconcat(instr_asm, "\t$dst, $b, $c"),
194 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt16:$c))], IIAlu>;
196 let isCommutable = 1 in
197 class LogicNOR<bits<6> op, bits<6> func, string instr_asm>:
198 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
199 !strconcat(instr_asm, "\t$dst, $b, $c"),
200 [(set CPURegs:$dst, (not (or CPURegs:$b, CPURegs:$c)))], IIAlu>;
203 class LogicR_shift_rotate_imm<bits<6> func, bits<5> _rs, string instr_asm,
205 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, shamt:$c),
206 !strconcat(instr_asm, "\t$dst, $b, $c"),
207 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt5:$c))], IIAlu> {
211 class LogicR_shift_rotate_reg<bits<6> func, bits<5> _shamt, string instr_asm,
213 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$c, CPURegs:$b),
214 !strconcat(instr_asm, "\t$dst, $b, $c"),
215 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu> {
219 // Load Upper Imediate
220 class LoadUpper<bits<6> op, string instr_asm>:
224 !strconcat(instr_asm, "\t$dst, $imm"),
228 let canFoldAsLoad = 1, hasDelaySlot = 1 in
229 class LoadM<bits<6> op, string instr_asm, PatFrag OpNode>:
230 FI<op, (outs CPURegs:$dst), (ins mem:$addr),
231 !strconcat(instr_asm, "\t$dst, $addr"),
232 [(set CPURegs:$dst, (OpNode addr:$addr))], IILoad>;
234 class StoreM<bits<6> op, string instr_asm, PatFrag OpNode>:
235 FI<op, (outs), (ins CPURegs:$dst, mem:$addr),
236 !strconcat(instr_asm, "\t$dst, $addr"),
237 [(OpNode CPURegs:$dst, addr:$addr)], IIStore>;
239 // Conditional Branch
240 let isBranch = 1, isTerminator=1, hasDelaySlot = 1 in {
241 class CBranch<bits<6> op, string instr_asm, PatFrag cond_op>:
242 FI<op, (outs), (ins CPURegs:$a, CPURegs:$b, brtarget:$offset),
243 !strconcat(instr_asm, "\t$a, $b, $offset"),
244 [(brcond (cond_op CPURegs:$a, CPURegs:$b), bb:$offset)],
247 class CBranchZero<bits<6> op, string instr_asm, PatFrag cond_op>:
248 FI<op, (outs), (ins CPURegs:$src, brtarget:$offset),
249 !strconcat(instr_asm, "\t$src, $offset"),
250 [(brcond (cond_op CPURegs:$src, 0), bb:$offset)],
255 class SetCC_R<bits<6> op, bits<6> func, string instr_asm,
257 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
258 !strconcat(instr_asm, "\t$dst, $b, $c"),
259 [(set CPURegs:$dst, (cond_op CPURegs:$b, CPURegs:$c))],
262 class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op,
263 Operand Od, PatLeaf imm_type>:
264 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
265 !strconcat(instr_asm, "\t$dst, $b, $c"),
266 [(set CPURegs:$dst, (cond_op CPURegs:$b, imm_type:$c))],
269 // Unconditional branch
270 let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
271 class JumpFJ<bits<6> op, string instr_asm>:
272 FJ<op, (outs), (ins brtarget:$target),
273 !strconcat(instr_asm, "\t$target"), [(br bb:$target)], IIBranch>;
275 let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in
276 class JumpFR<bits<6> op, bits<6> func, string instr_asm>:
277 FR<op, func, (outs), (ins CPURegs:$target),
278 !strconcat(instr_asm, "\t$target"), [(brind CPURegs:$target)], IIBranch>;
280 // Jump and Link (Call)
281 let isCall=1, hasDelaySlot=1,
282 // All calls clobber the non-callee saved registers...
283 Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9,
284 K0, K1, D0, D1, D2, D3, D4, D5, D6, D7, D8, D9], Uses = [GP] in {
285 class JumpLink<bits<6> op, string instr_asm>:
286 FJ<op, (outs), (ins calltarget:$target, variable_ops),
287 !strconcat(instr_asm, "\t$target"), [(MipsJmpLink imm:$target)],
291 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
292 FR<op, func, (outs), (ins CPURegs:$rs, variable_ops),
293 !strconcat(instr_asm, "\t$rs"), [(MipsJmpLink CPURegs:$rs)], IIBranch>;
295 class BranchLink<string instr_asm>:
296 FI<0x1, (outs), (ins CPURegs:$rs, brtarget:$target, variable_ops),
297 !strconcat(instr_asm, "\t$rs, $target"), [], IIBranch>;
301 let Defs = [HI, LO] in {
302 let isCommutable = 1 in
303 class Mul<bits<6> func, string instr_asm, InstrItinClass itin>:
304 FR<0x00, func, (outs), (ins CPURegs:$a, CPURegs:$b),
305 !strconcat(instr_asm, "\t$a, $b"), [], itin>;
307 class Div<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin>:
308 FR<0x00, func, (outs), (ins CPURegs:$a, CPURegs:$b),
309 !strconcat(instr_asm, "\t$$zero, $a, $b"),
310 [(op CPURegs:$a, CPURegs:$b)], itin>;
314 class MoveFromLOHI<bits<6> func, string instr_asm>:
315 FR<0x00, func, (outs CPURegs:$dst), (ins),
316 !strconcat(instr_asm, "\t$dst"), [], IIHiLo>;
318 class MoveToLOHI<bits<6> func, string instr_asm>:
319 FR<0x00, func, (outs), (ins CPURegs:$src),
320 !strconcat(instr_asm, "\t$src"), [], IIHiLo>;
322 class EffectiveAddress<string instr_asm> :
323 FI<0x09, (outs CPURegs:$dst), (ins mem:$addr),
324 instr_asm, [(set CPURegs:$dst, addr:$addr)], IIAlu>;
326 // Count Leading Ones/Zeros in Word
327 class CountLeading<bits<6> func, string instr_asm, list<dag> pattern>:
328 FR<0x1c, func, (outs CPURegs:$dst), (ins CPURegs:$src),
329 !strconcat(instr_asm, "\t$dst, $src"), pattern, IIAlu>,
330 Requires<[HasBitCount]> {
335 // Sign Extend in Register.
336 class SignExtInReg<bits<6> func, string instr_asm, ValueType vt>:
337 FR<0x3f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
338 !strconcat(instr_asm, "\t$dst, $src"),
339 [(set CPURegs:$dst, (sext_inreg CPURegs:$src, vt))], NoItinerary>;
342 class ByteSwap<bits<6> func, string instr_asm>:
343 FR<0x1f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
344 !strconcat(instr_asm, "\t$dst, $src"),
345 [(set CPURegs:$dst, (bswap CPURegs:$src))], NoItinerary>;
348 class CondMov<bits<6> func, string instr_asm, PatLeaf MovCode>:
349 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$F, CPURegs:$T,
350 CPURegs:$cond), !strconcat(instr_asm, "\t$dst, $T, $cond"),
353 //===----------------------------------------------------------------------===//
354 // Pseudo instructions
355 //===----------------------------------------------------------------------===//
357 // As stack alignment is always done with addiu, we need a 16-bit immediate
358 let Defs = [SP], Uses = [SP] in {
359 def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
360 "!ADJCALLSTACKDOWN $amt",
361 [(callseq_start timm:$amt)]>;
362 def ADJCALLSTACKUP : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
363 "!ADJCALLSTACKUP $amt1",
364 [(callseq_end timm:$amt1, timm:$amt2)]>;
367 // Some assembly macros need to avoid pseudoinstructions and assembler
368 // automatic reodering, we should reorder ourselves.
369 def MACRO : MipsPseudo<(outs), (ins), ".set\tmacro", []>;
370 def REORDER : MipsPseudo<(outs), (ins), ".set\treorder", []>;
371 def NOMACRO : MipsPseudo<(outs), (ins), ".set\tnomacro", []>;
372 def NOREORDER : MipsPseudo<(outs), (ins), ".set\tnoreorder", []>;
374 // These macros are inserted to prevent GAS from complaining
375 // when using the AT register.
376 def NOAT : MipsPseudo<(outs), (ins), ".set\tnoat", []>;
377 def ATMACRO : MipsPseudo<(outs), (ins), ".set\tat", []>;
379 // When handling PIC code the assembler needs .cpload and .cprestore
380 // directives. If the real instructions corresponding these directives
381 // are used, we have the same behavior, but get also a bunch of warnings
382 // from the assembler.
383 def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$picreg), ".cpload\t$picreg", []>;
384 def CPRESTORE : MipsPseudo<(outs), (ins i32imm:$loc), ".cprestore\t$loc\n", []>;
386 //===----------------------------------------------------------------------===//
387 // Instruction definition
388 //===----------------------------------------------------------------------===//
390 //===----------------------------------------------------------------------===//
391 // MipsI Instructions
392 //===----------------------------------------------------------------------===//
394 /// Arithmetic Instructions (ALU Immediate)
395 def ADDiu : ArithI<0x09, "addiu", add, simm16, immSExt16>;
396 def ADDi : ArithOverflowI<0x08, "addi", add, simm16, immSExt16>;
397 def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16>;
398 def SLTiu : SetCC_I<0x0b, "sltiu", setult, simm16, immSExt16>;
399 def ANDi : LogicI<0x0c, "andi", and>;
400 def ORi : LogicI<0x0d, "ori", or>;
401 def XORi : LogicI<0x0e, "xori", xor>;
402 def LUi : LoadUpper<0x0f, "lui">;
404 /// Arithmetic Instructions (3-Operand, R-Type)
405 def ADDu : ArithR<0x00, 0x21, "addu", add, IIAlu, 1>;
406 def SUBu : ArithR<0x00, 0x23, "subu", sub, IIAlu>;
407 def ADD : ArithOverflowR<0x00, 0x20, "add", 1>;
408 def SUB : ArithOverflowR<0x00, 0x22, "sub">;
409 def SLT : SetCC_R<0x00, 0x2a, "slt", setlt>;
410 def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult>;
411 def AND : LogicR<0x24, "and", and>;
412 def OR : LogicR<0x25, "or", or>;
413 def XOR : LogicR<0x26, "xor", xor>;
414 def NOR : LogicNOR<0x00, 0x27, "nor">;
416 /// Shift Instructions
417 def SLL : LogicR_shift_rotate_imm<0x00, 0x00, "sll", shl>;
418 def SRL : LogicR_shift_rotate_imm<0x02, 0x00, "srl", srl>;
419 def SRA : LogicR_shift_rotate_imm<0x03, 0x00, "sra", sra>;
420 def SLLV : LogicR_shift_rotate_reg<0x04, 0x00, "sllv", shl>;
421 def SRLV : LogicR_shift_rotate_reg<0x06, 0x00, "srlv", srl>;
422 def SRAV : LogicR_shift_rotate_reg<0x07, 0x00, "srav", sra>;
424 // Rotate Instructions
425 let Predicates = [IsMips32r2] in {
426 def ROTR : LogicR_shift_rotate_imm<0x02, 0x01, "rotr", rotr>;
427 def ROTRV : LogicR_shift_rotate_reg<0x06, 0x01, "rotrv", rotr>;
430 /// Load and Store Instructions
431 def LB : LoadM<0x20, "lb", sextloadi8>;
432 def LBu : LoadM<0x24, "lbu", zextloadi8>;
433 def LH : LoadM<0x21, "lh", sextloadi16>;
434 def LHu : LoadM<0x25, "lhu", zextloadi16>;
435 def LW : LoadM<0x23, "lw", load>;
436 def SB : StoreM<0x28, "sb", truncstorei8>;
437 def SH : StoreM<0x29, "sh", truncstorei16>;
438 def SW : StoreM<0x2b, "sw", store>;
440 /// Jump and Branch Instructions
441 def J : JumpFJ<0x02, "j">;
442 def JR : JumpFR<0x00, 0x08, "jr">;
443 def JAL : JumpLink<0x03, "jal">;
444 def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
445 def BEQ : CBranch<0x04, "beq", seteq>;
446 def BNE : CBranch<0x05, "bne", setne>;
449 def BGEZ : CBranchZero<0x01, "bgez", setge>;
452 def BGTZ : CBranchZero<0x07, "bgtz", setgt>;
453 def BLEZ : CBranchZero<0x07, "blez", setle>;
454 def BLTZ : CBranchZero<0x01, "bltz", setlt>;
457 def BGEZAL : BranchLink<"bgezal">;
458 def BLTZAL : BranchLink<"bltzal">;
460 let isReturn=1, isTerminator=1, hasDelaySlot=1,
461 isBarrier=1, hasCtrlDep=1, rs=0, rt=0, shamt=0 in
462 def RET : FR <0x00, 0x02, (outs), (ins CPURegs:$target),
463 "jr\t$target", [(MipsRet CPURegs:$target)], IIBranch>;
465 /// Multiply and Divide Instructions.
466 def MULT : Mul<0x18, "mult", IIImul>;
467 def MULTu : Mul<0x19, "multu", IIImul>;
468 def SDIV : Div<MipsDivRem, 0x1a, "div", IIIdiv>;
469 def UDIV : Div<MipsDivRemU, 0x1b, "divu", IIIdiv>;
472 def MTHI : MoveToLOHI<0x11, "mthi">;
474 def MTLO : MoveToLOHI<0x13, "mtlo">;
477 def MFHI : MoveFromLOHI<0x10, "mfhi">;
479 def MFLO : MoveFromLOHI<0x12, "mflo">;
481 /// Sign Ext In Register Instructions.
482 let Predicates = [HasSEInReg] in {
483 let shamt = 0x10, rs = 0 in
484 def SEB : SignExtInReg<0x21, "seb", i8>;
486 let shamt = 0x18, rs = 0 in
487 def SEH : SignExtInReg<0x20, "seh", i16>;
491 def CLZ : CountLeading<0b100000, "clz",
492 [(set CPURegs:$dst, (ctlz CPURegs:$src))]>;
493 def CLO : CountLeading<0b100001, "clo",
494 [(set CPURegs:$dst, (ctlz (not CPURegs:$src)))]>;
497 let Predicates = [HasSwap] in {
498 let shamt = 0x3, rs = 0 in
499 def WSBW : ByteSwap<0x20, "wsbw">;
503 def MIPS_CMOV_ZERO : PatLeaf<(i32 0)>;
504 def MIPS_CMOV_NZERO : PatLeaf<(i32 1)>;
506 // Conditional moves:
507 // These instructions are expanded in
508 // MipsISelLowering::EmitInstrWithCustomInserter if target does not have
509 // conditional move instructions.
510 // flag:int, data:int
511 let usesCustomInserter = 1, shamt = 0, Constraints = "$F = $dst" in
512 class CondMovIntInt<bits<6> funct, string instr_asm> :
513 FR<0, funct, (outs CPURegs:$dst),
514 (ins CPURegs:$T, CPURegs:$cond, CPURegs:$F),
515 !strconcat(instr_asm, "\t$dst, $T, $cond"), [], NoItinerary>;
517 def MOVZ_I : CondMovIntInt<0x0a, "movz">;
518 def MOVN_I : CondMovIntInt<0x0b, "movn">;
522 def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
524 // FrameIndexes are legalized when they are operands from load/store
525 // instructions. The same not happens for stack address copies, so an
526 // add op with mem ComplexPattern is used and the stack address copy
527 // can be matched. It's similar to Sparc LEA_ADDRi
528 def LEA_ADDiu : EffectiveAddress<"addiu\t$dst, ${addr:stackloc}">;
531 def MADD : MArithR<0, "madd", MipsMAdd, 1>;
532 def MADDU : MArithR<1, "maddu", MipsMAddu, 1>;
533 def MSUB : MArithR<4, "msub", MipsMSub>;
534 def MSUBU : MArithR<5, "msubu", MipsMSubu>;
536 // MUL is a assembly macro in the current used ISAs. In recent ISA's
537 // it is a real instruction.
538 def MUL : ArithR<0x1c, 0x02, "mul", mul, IIImul, 1>, Requires<[IsMips32]>;
540 //===----------------------------------------------------------------------===//
541 // Arbitrary patterns that map to one or more instructions
542 //===----------------------------------------------------------------------===//
545 def : Pat<(i32 immSExt16:$in),
546 (ADDiu ZERO, imm:$in)>;
547 def : Pat<(i32 immZExt16:$in),
548 (ORi ZERO, imm:$in)>;
550 // Arbitrary immediates
551 def : Pat<(i32 imm:$imm),
552 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
555 def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
556 (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
557 def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
558 (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
559 def : Pat<(addc CPURegs:$src, immSExt16:$imm),
560 (ADDiu CPURegs:$src, imm:$imm)>;
563 def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
564 (JAL tglobaladdr:$dst)>;
565 def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
566 (JAL texternalsym:$dst)>;
567 //def : Pat<(MipsJmpLink CPURegs:$dst),
568 // (JALR CPURegs:$dst)>;
571 def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
572 def : Pat<(MipsHi tblockaddress:$in), (LUi tblockaddress:$in)>;
573 def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
574 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
575 def : Pat<(add CPURegs:$hi, (MipsLo tblockaddress:$lo)),
576 (ADDiu CPURegs:$hi, tblockaddress:$lo)>;
578 def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
579 def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
580 (ADDiu CPURegs:$hi, tjumptable:$lo)>;
582 def : Pat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
583 def : Pat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)),
584 (ADDiu CPURegs:$hi, tconstpool:$lo)>;
587 def : Pat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)),
588 (ADDiu CPURegs:$gp, tglobaladdr:$in)>;
589 def : Pat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)),
590 (ADDiu CPURegs:$gp, tconstpool:$in)>;
592 // Mips does not have "not", so we expand our way
593 def : Pat<(not CPURegs:$in),
594 (NOR CPURegs:$in, ZERO)>;
596 // extended load and stores
597 def : Pat<(extloadi1 addr:$src), (LBu addr:$src)>;
598 def : Pat<(extloadi8 addr:$src), (LBu addr:$src)>;
599 def : Pat<(extloadi16 addr:$src), (LHu addr:$src)>;
602 def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
605 def : Pat<(brcond (setne CPURegs:$lhs, 0), bb:$dst),
606 (BNE CPURegs:$lhs, ZERO, bb:$dst)>;
607 def : Pat<(brcond (seteq CPURegs:$lhs, 0), bb:$dst),
608 (BEQ CPURegs:$lhs, ZERO, bb:$dst)>;
610 def : Pat<(brcond (setge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
611 (BEQ (SLT CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
612 def : Pat<(brcond (setuge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
613 (BEQ (SLTu CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
614 def : Pat<(brcond (setge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
615 (BEQ (SLTi CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
616 def : Pat<(brcond (setuge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
617 (BEQ (SLTiu CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
619 def : Pat<(brcond (setle CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
620 (BEQ (SLT CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
621 def : Pat<(brcond (setule CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
622 (BEQ (SLTu CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
624 def : Pat<(brcond CPURegs:$cond, bb:$dst),
625 (BNE CPURegs:$cond, ZERO, bb:$dst)>;
628 multiclass MovzPats<RegisterClass RC, Instruction MOVZInst> {
629 def : Pat<(select (setge CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
630 (MOVZInst RC:$T, (SLT CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
631 def : Pat<(select (setuge CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
632 (MOVZInst RC:$T, (SLTu CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
633 def : Pat<(select (setge CPURegs:$lhs, immSExt16:$rhs), RC:$T, RC:$F),
634 (MOVZInst RC:$T, (SLTi CPURegs:$lhs, immSExt16:$rhs), RC:$F)>;
635 def : Pat<(select (setuge CPURegs:$lh, immSExt16:$rh), RC:$T, RC:$F),
636 (MOVZInst RC:$T, (SLTiu CPURegs:$lh, immSExt16:$rh), RC:$F)>;
637 def : Pat<(select (setle CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
638 (MOVZInst RC:$T, (SLT CPURegs:$rhs, CPURegs:$lhs), RC:$F)>;
639 def : Pat<(select (setule CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
640 (MOVZInst RC:$T, (SLTu CPURegs:$rhs, CPURegs:$lhs), RC:$F)>;
641 def : Pat<(select (seteq CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
642 (MOVZInst RC:$T, (XOR CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
643 def : Pat<(select (seteq CPURegs:$lhs, 0), RC:$T, RC:$F),
644 (MOVZInst RC:$T, CPURegs:$lhs, RC:$F)>;
647 multiclass MovnPats<RegisterClass RC, Instruction MOVNInst> {
648 def : Pat<(select (setne CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
649 (MOVNInst RC:$T, (XOR CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
650 def : Pat<(select CPURegs:$cond, RC:$T, RC:$F),
651 (MOVNInst RC:$T, CPURegs:$cond, RC:$F)>;
652 def : Pat<(select (setne CPURegs:$lhs, 0), RC:$T, RC:$F),
653 (MOVNInst RC:$T, CPURegs:$lhs, RC:$F)>;
656 defm : MovzPats<CPURegs, MOVZ_I>;
657 defm : MovnPats<CPURegs, MOVN_I>;
659 // select patterns with got access
660 let AddedComplexity = 10 in
661 def : Pat<(select (setne CPURegs:$lhs, CPURegs:$rhs),
662 (i32 tglobaladdr:$T), CPURegs:$F),
663 (MOVN_I CPURegs:$F, (ADDiu GP, tglobaladdr:$T),
664 (XOR CPURegs:$lhs, CPURegs:$rhs))>;
667 def : Pat<(seteq CPURegs:$lhs, CPURegs:$rhs),
668 (SLTu (XOR CPURegs:$lhs, CPURegs:$rhs), 1)>;
669 def : Pat<(setne CPURegs:$lhs, CPURegs:$rhs),
670 (SLTu ZERO, (XOR CPURegs:$lhs, CPURegs:$rhs))>;
672 def : Pat<(setle CPURegs:$lhs, CPURegs:$rhs),
673 (XORi (SLT CPURegs:$rhs, CPURegs:$lhs), 1)>;
674 def : Pat<(setule CPURegs:$lhs, CPURegs:$rhs),
675 (XORi (SLTu CPURegs:$rhs, CPURegs:$lhs), 1)>;
677 def : Pat<(setgt CPURegs:$lhs, CPURegs:$rhs),
678 (SLT CPURegs:$rhs, CPURegs:$lhs)>;
679 def : Pat<(setugt CPURegs:$lhs, CPURegs:$rhs),
680 (SLTu CPURegs:$rhs, CPURegs:$lhs)>;
682 def : Pat<(setge CPURegs:$lhs, CPURegs:$rhs),
683 (XORi (SLT CPURegs:$lhs, CPURegs:$rhs), 1)>;
684 def : Pat<(setuge CPURegs:$lhs, CPURegs:$rhs),
685 (XORi (SLTu CPURegs:$lhs, CPURegs:$rhs), 1)>;
687 def : Pat<(setge CPURegs:$lhs, immSExt16:$rhs),
688 (XORi (SLTi CPURegs:$lhs, immSExt16:$rhs), 1)>;
689 def : Pat<(setuge CPURegs:$lhs, immSExt16:$rhs),
690 (XORi (SLTiu CPURegs:$lhs, immSExt16:$rhs), 1)>;
692 //===----------------------------------------------------------------------===//
693 // Floating Point Support
694 //===----------------------------------------------------------------------===//
696 include "MipsInstrFPU.td"