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>]>;
43 def MipsJmpLink : SDNode<"MipsISD::JmpLink",SDT_MipsJmpLink,
44 [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue,
47 // Hi and Lo nodes are used to handle global addresses. Used on
48 // MipsISelLowering to lower stuff like GlobalAddress, ExternalSymbol
49 // static model. (nothing to do with Mips Registers Hi and Lo)
50 def MipsHi : SDNode<"MipsISD::Hi", SDTIntUnaryOp>;
51 def MipsLo : SDNode<"MipsISD::Lo", SDTIntUnaryOp>;
52 def MipsGPRel : SDNode<"MipsISD::GPRel", SDTIntUnaryOp>;
54 // TlsGd node is used to handle General Dynamic TLS
55 def MipsTlsGd : SDNode<"MipsISD::TlsGd", SDTIntUnaryOp>;
57 // TprelHi and TprelLo nodes are used to handle Local Exec TLS
58 def MipsTprelHi : SDNode<"MipsISD::TprelHi", SDTIntUnaryOp>;
59 def MipsTprelLo : SDNode<"MipsISD::TprelLo", SDTIntUnaryOp>;
62 def MipsThreadPointer: SDNode<"MipsISD::ThreadPointer", SDT_MipsThreadPointer>;
65 def MipsRet : SDNode<"MipsISD::Ret", SDT_MipsRet, [SDNPHasChain,
68 // These are target-independent nodes, but have target-specific formats.
69 def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_MipsCallSeqStart,
70 [SDNPHasChain, SDNPOutGlue]>;
71 def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_MipsCallSeqEnd,
72 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
75 def MipsMAdd : SDNode<"MipsISD::MAdd", SDT_MipsMAddMSub,
76 [SDNPOptInGlue, SDNPOutGlue]>;
77 def MipsMAddu : SDNode<"MipsISD::MAddu", SDT_MipsMAddMSub,
78 [SDNPOptInGlue, SDNPOutGlue]>;
79 def MipsMSub : SDNode<"MipsISD::MSub", SDT_MipsMAddMSub,
80 [SDNPOptInGlue, SDNPOutGlue]>;
81 def MipsMSubu : SDNode<"MipsISD::MSubu", SDT_MipsMAddMSub,
82 [SDNPOptInGlue, SDNPOutGlue]>;
85 def MipsDivRem : SDNode<"MipsISD::DivRem", SDT_MipsDivRem,
87 def MipsDivRemU : SDNode<"MipsISD::DivRemU", SDT_MipsDivRem,
91 def MipsWrapperPIC : SDNode<"MipsISD::WrapperPIC", SDTIntUnaryOp>;
93 //===----------------------------------------------------------------------===//
94 // Mips Instruction Predicate Definitions.
95 //===----------------------------------------------------------------------===//
96 def HasSEInReg : Predicate<"Subtarget.hasSEInReg()">;
97 def HasBitCount : Predicate<"Subtarget.hasBitCount()">;
98 def HasSwap : Predicate<"Subtarget.hasSwap()">;
99 def HasCondMov : Predicate<"Subtarget.hasCondMov()">;
100 def IsMips32 : Predicate<"Subtarget.isMips32()">;
101 def IsMips32r2 : Predicate<"Subtarget.isMips32r2()">;
103 //===----------------------------------------------------------------------===//
104 // Mips Operand, Complex Patterns and Transformations Definitions.
105 //===----------------------------------------------------------------------===//
107 // Instruction operand types
108 def brtarget : Operand<OtherVT>;
109 def calltarget : Operand<i32>;
110 def simm16 : Operand<i32>;
111 def shamt : Operand<i32>;
114 def uimm16 : Operand<i32> {
115 let PrintMethod = "printUnsignedImm";
119 def mem : Operand<i32> {
120 let PrintMethod = "printMemOperand";
121 let MIOperandInfo = (ops simm16, CPURegs);
124 // Transformation Function - get the lower 16 bits.
125 def LO16 : SDNodeXForm<imm, [{
126 return getI32Imm((unsigned)N->getZExtValue() & 0xFFFF);
129 // Transformation Function - get the higher 16 bits.
130 def HI16 : SDNodeXForm<imm, [{
131 return getI32Imm((unsigned)N->getZExtValue() >> 16);
134 // Node immediate fits as 16-bit sign extended on target immediate.
136 def immSExt16 : PatLeaf<(imm), [{ return isInt<16>(N->getSExtValue()); }]>;
138 // Node immediate fits as 16-bit zero extended on target immediate.
139 // The LO16 param means that only the lower 16 bits of the node
140 // immediate are caught.
142 def immZExt16 : PatLeaf<(imm), [{
143 if (N->getValueType(0) == MVT::i32)
144 return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
146 return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
149 // shamt field must fit in 5 bits.
150 def immZExt5 : PatLeaf<(imm), [{
151 return N->getZExtValue() == ((N->getZExtValue()) & 0x1f) ;
154 // Mips Address Mode! SDNode frameindex could possibily be a match
155 // since load and store instructions from stack used it.
156 def addr : ComplexPattern<iPTR, 2, "SelectAddr", [frameindex], []>;
158 //===----------------------------------------------------------------------===//
159 // Instructions specific format
160 //===----------------------------------------------------------------------===//
162 // Arithmetic 3 register operands
163 class ArithR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
164 InstrItinClass itin, bit isComm = 0>:
165 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
166 !strconcat(instr_asm, "\t$dst, $b, $c"),
167 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], itin> {
168 let isCommutable = isComm;
171 class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm,
173 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
174 !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu> {
175 let isCommutable = isComm;
178 // Arithmetic 2 register operands
179 class ArithI<bits<6> op, string instr_asm, SDNode OpNode,
180 Operand Od, PatLeaf imm_type> :
181 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
182 !strconcat(instr_asm, "\t$dst, $b, $c"),
183 [(set CPURegs:$dst, (OpNode CPURegs:$b, imm_type:$c))], IIAlu>;
185 class ArithOverflowI<bits<6> op, string instr_asm, SDNode OpNode,
186 Operand Od, PatLeaf imm_type> :
187 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
188 !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu>;
190 // Arithmetic Multiply ADD/SUB
191 let rd = 0, shamt = 0, Defs = [HI, LO], Uses = [HI, LO] in
192 class MArithR<bits<6> func, string instr_asm, SDNode op, bit isComm = 0> :
193 FR<0x1c, func, (outs), (ins CPURegs:$rs, CPURegs:$rt),
194 !strconcat(instr_asm, "\t$rs, $rt"),
195 [(op CPURegs:$rs, CPURegs:$rt, LO, HI)], IIImul> {
196 let isCommutable = isComm;
200 let isCommutable = 1 in
201 class LogicR<bits<6> func, string instr_asm, SDNode OpNode>:
202 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
203 !strconcat(instr_asm, "\t$dst, $b, $c"),
204 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
206 class LogicI<bits<6> op, string instr_asm, SDNode OpNode>:
207 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, uimm16:$c),
208 !strconcat(instr_asm, "\t$dst, $b, $c"),
209 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt16:$c))], IIAlu>;
211 let isCommutable = 1 in
212 class LogicNOR<bits<6> op, bits<6> func, string instr_asm>:
213 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
214 !strconcat(instr_asm, "\t$dst, $b, $c"),
215 [(set CPURegs:$dst, (not (or CPURegs:$b, CPURegs:$c)))], IIAlu>;
218 class LogicR_shift_rotate_imm<bits<6> func, bits<5> _rs, string instr_asm,
220 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, shamt:$c),
221 !strconcat(instr_asm, "\t$dst, $b, $c"),
222 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt5:$c))], IIAlu> {
226 class LogicR_shift_rotate_reg<bits<6> func, bits<5> _shamt, string instr_asm,
228 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$c, CPURegs:$b),
229 !strconcat(instr_asm, "\t$dst, $b, $c"),
230 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu> {
234 // Load Upper Imediate
235 class LoadUpper<bits<6> op, string instr_asm>:
239 !strconcat(instr_asm, "\t$dst, $imm"),
243 let canFoldAsLoad = 1, hasDelaySlot = 1 in
244 class LoadM<bits<6> op, string instr_asm, PatFrag OpNode>:
245 FI<op, (outs CPURegs:$dst), (ins mem:$addr),
246 !strconcat(instr_asm, "\t$dst, $addr"),
247 [(set CPURegs:$dst, (OpNode addr:$addr))], IILoad>;
249 class StoreM<bits<6> op, string instr_asm, PatFrag OpNode>:
250 FI<op, (outs), (ins CPURegs:$dst, mem:$addr),
251 !strconcat(instr_asm, "\t$dst, $addr"),
252 [(OpNode CPURegs:$dst, addr:$addr)], IIStore>;
254 // Conditional Branch
255 let isBranch = 1, isTerminator=1, hasDelaySlot = 1 in {
256 class CBranch<bits<6> op, string instr_asm, PatFrag cond_op>:
257 FI<op, (outs), (ins CPURegs:$a, CPURegs:$b, brtarget:$offset),
258 !strconcat(instr_asm, "\t$a, $b, $offset"),
259 [(brcond (cond_op CPURegs:$a, CPURegs:$b), bb:$offset)],
262 class CBranchZero<bits<6> op, string instr_asm, PatFrag cond_op>:
263 FI<op, (outs), (ins CPURegs:$src, brtarget:$offset),
264 !strconcat(instr_asm, "\t$src, $offset"),
265 [(brcond (cond_op CPURegs:$src, 0), bb:$offset)],
270 class SetCC_R<bits<6> op, bits<6> func, string instr_asm,
272 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
273 !strconcat(instr_asm, "\t$dst, $b, $c"),
274 [(set CPURegs:$dst, (cond_op CPURegs:$b, CPURegs:$c))],
277 class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op,
278 Operand Od, PatLeaf imm_type>:
279 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
280 !strconcat(instr_asm, "\t$dst, $b, $c"),
281 [(set CPURegs:$dst, (cond_op CPURegs:$b, imm_type:$c))],
284 // Unconditional branch
285 let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
286 class JumpFJ<bits<6> op, string instr_asm>:
287 FJ<op, (outs), (ins brtarget:$target),
288 !strconcat(instr_asm, "\t$target"), [(br bb:$target)], IIBranch>;
290 let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in
291 class JumpFR<bits<6> op, bits<6> func, string instr_asm>:
292 FR<op, func, (outs), (ins CPURegs:$target),
293 !strconcat(instr_asm, "\t$target"), [(brind CPURegs:$target)], IIBranch>;
295 // Jump and Link (Call)
296 let isCall=1, hasDelaySlot=1,
297 // All calls clobber the non-callee saved registers...
298 Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9,
299 K0, K1, D0, D1, D2, D3, D4, D5, D6, D7, D8, D9], Uses = [GP] in {
300 class JumpLink<bits<6> op, string instr_asm>:
301 FJ<op, (outs), (ins calltarget:$target, variable_ops),
302 !strconcat(instr_asm, "\t$target"), [(MipsJmpLink imm:$target)],
306 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
307 FR<op, func, (outs), (ins CPURegs:$rs, variable_ops),
308 !strconcat(instr_asm, "\t$rs"), [(MipsJmpLink CPURegs:$rs)], IIBranch>;
310 class BranchLink<string instr_asm>:
311 FI<0x1, (outs), (ins CPURegs:$rs, brtarget:$target, variable_ops),
312 !strconcat(instr_asm, "\t$rs, $target"), [], IIBranch>;
316 let Defs = [HI, LO] in {
317 let isCommutable = 1 in
318 class Mul<bits<6> func, string instr_asm, InstrItinClass itin>:
319 FR<0x00, func, (outs), (ins CPURegs:$a, CPURegs:$b),
320 !strconcat(instr_asm, "\t$a, $b"), [], itin>;
322 class Div<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin>:
323 FR<0x00, func, (outs), (ins CPURegs:$a, CPURegs:$b),
324 !strconcat(instr_asm, "\t$$zero, $a, $b"),
325 [(op CPURegs:$a, CPURegs:$b)], itin>;
329 class MoveFromLOHI<bits<6> func, string instr_asm>:
330 FR<0x00, func, (outs CPURegs:$dst), (ins),
331 !strconcat(instr_asm, "\t$dst"), [], IIHiLo>;
333 class MoveToLOHI<bits<6> func, string instr_asm>:
334 FR<0x00, func, (outs), (ins CPURegs:$src),
335 !strconcat(instr_asm, "\t$src"), [], IIHiLo>;
337 class EffectiveAddress<string instr_asm> :
338 FI<0x09, (outs CPURegs:$dst), (ins mem:$addr),
339 instr_asm, [(set CPURegs:$dst, addr:$addr)], IIAlu>;
341 // Count Leading Ones/Zeros in Word
342 class CountLeading<bits<6> func, string instr_asm, list<dag> pattern>:
343 FR<0x1c, func, (outs CPURegs:$dst), (ins CPURegs:$src),
344 !strconcat(instr_asm, "\t$dst, $src"), pattern, IIAlu>,
345 Requires<[HasBitCount]> {
350 // Sign Extend in Register.
351 class SignExtInReg<bits<6> func, string instr_asm, ValueType vt>:
352 FR<0x3f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
353 !strconcat(instr_asm, "\t$dst, $src"),
354 [(set CPURegs:$dst, (sext_inreg CPURegs:$src, vt))], NoItinerary>;
357 class ByteSwap<bits<6> func, string instr_asm>:
358 FR<0x1f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
359 !strconcat(instr_asm, "\t$dst, $src"),
360 [(set CPURegs:$dst, (bswap CPURegs:$src))], NoItinerary>;
363 class CondMov<bits<6> func, string instr_asm, PatLeaf MovCode>:
364 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$F, CPURegs:$T,
365 CPURegs:$cond), !strconcat(instr_asm, "\t$dst, $T, $cond"),
369 class ReadHardware: FR<0x1f, 0x3b, (outs CPURegs:$dst), (ins HWRegs:$src),
370 "rdhwr\t$dst, $src", [], IIAlu> {
375 //===----------------------------------------------------------------------===//
376 // Pseudo instructions
377 //===----------------------------------------------------------------------===//
379 // As stack alignment is always done with addiu, we need a 16-bit immediate
380 let Defs = [SP], Uses = [SP] in {
381 def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
382 "!ADJCALLSTACKDOWN $amt",
383 [(callseq_start timm:$amt)]>;
384 def ADJCALLSTACKUP : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
385 "!ADJCALLSTACKUP $amt1",
386 [(callseq_end timm:$amt1, timm:$amt2)]>;
389 // Some assembly macros need to avoid pseudoinstructions and assembler
390 // automatic reodering, we should reorder ourselves.
391 def MACRO : MipsPseudo<(outs), (ins), ".set\tmacro", []>;
392 def REORDER : MipsPseudo<(outs), (ins), ".set\treorder", []>;
393 def NOMACRO : MipsPseudo<(outs), (ins), ".set\tnomacro", []>;
394 def NOREORDER : MipsPseudo<(outs), (ins), ".set\tnoreorder", []>;
396 // These macros are inserted to prevent GAS from complaining
397 // when using the AT register.
398 def NOAT : MipsPseudo<(outs), (ins), ".set\tnoat", []>;
399 def ATMACRO : MipsPseudo<(outs), (ins), ".set\tat", []>;
401 // When handling PIC code the assembler needs .cpload and .cprestore
402 // directives. If the real instructions corresponding these directives
403 // are used, we have the same behavior, but get also a bunch of warnings
404 // from the assembler.
405 def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$picreg), ".cpload\t$picreg", []>;
406 def CPRESTORE : MipsPseudo<(outs), (ins i32imm:$loc), ".cprestore\t$loc\n", []>;
408 //===----------------------------------------------------------------------===//
409 // Instruction definition
410 //===----------------------------------------------------------------------===//
412 //===----------------------------------------------------------------------===//
413 // MipsI Instructions
414 //===----------------------------------------------------------------------===//
416 /// Arithmetic Instructions (ALU Immediate)
417 def ADDiu : ArithI<0x09, "addiu", add, simm16, immSExt16>;
418 def ADDi : ArithOverflowI<0x08, "addi", add, simm16, immSExt16>;
419 def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16>;
420 def SLTiu : SetCC_I<0x0b, "sltiu", setult, simm16, immSExt16>;
421 def ANDi : LogicI<0x0c, "andi", and>;
422 def ORi : LogicI<0x0d, "ori", or>;
423 def XORi : LogicI<0x0e, "xori", xor>;
424 def LUi : LoadUpper<0x0f, "lui">;
426 /// Arithmetic Instructions (3-Operand, R-Type)
427 def ADDu : ArithR<0x00, 0x21, "addu", add, IIAlu, 1>;
428 def SUBu : ArithR<0x00, 0x23, "subu", sub, IIAlu>;
429 def ADD : ArithOverflowR<0x00, 0x20, "add", 1>;
430 def SUB : ArithOverflowR<0x00, 0x22, "sub">;
431 def SLT : SetCC_R<0x00, 0x2a, "slt", setlt>;
432 def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult>;
433 def AND : LogicR<0x24, "and", and>;
434 def OR : LogicR<0x25, "or", or>;
435 def XOR : LogicR<0x26, "xor", xor>;
436 def NOR : LogicNOR<0x00, 0x27, "nor">;
438 /// Shift Instructions
439 def SLL : LogicR_shift_rotate_imm<0x00, 0x00, "sll", shl>;
440 def SRL : LogicR_shift_rotate_imm<0x02, 0x00, "srl", srl>;
441 def SRA : LogicR_shift_rotate_imm<0x03, 0x00, "sra", sra>;
442 def SLLV : LogicR_shift_rotate_reg<0x04, 0x00, "sllv", shl>;
443 def SRLV : LogicR_shift_rotate_reg<0x06, 0x00, "srlv", srl>;
444 def SRAV : LogicR_shift_rotate_reg<0x07, 0x00, "srav", sra>;
446 // Rotate Instructions
447 let Predicates = [IsMips32r2] in {
448 def ROTR : LogicR_shift_rotate_imm<0x02, 0x01, "rotr", rotr>;
449 def ROTRV : LogicR_shift_rotate_reg<0x06, 0x01, "rotrv", rotr>;
452 /// Load and Store Instructions
453 def LB : LoadM<0x20, "lb", sextloadi8>;
454 def LBu : LoadM<0x24, "lbu", zextloadi8>;
455 def LH : LoadM<0x21, "lh", sextloadi16>;
456 def LHu : LoadM<0x25, "lhu", zextloadi16>;
457 def LW : LoadM<0x23, "lw", load>;
458 def SB : StoreM<0x28, "sb", truncstorei8>;
459 def SH : StoreM<0x29, "sh", truncstorei16>;
460 def SW : StoreM<0x2b, "sw", store>;
462 /// Jump and Branch Instructions
463 def J : JumpFJ<0x02, "j">;
464 def JR : JumpFR<0x00, 0x08, "jr">;
465 def JAL : JumpLink<0x03, "jal">;
466 def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
467 def BEQ : CBranch<0x04, "beq", seteq>;
468 def BNE : CBranch<0x05, "bne", setne>;
471 def BGEZ : CBranchZero<0x01, "bgez", setge>;
474 def BGTZ : CBranchZero<0x07, "bgtz", setgt>;
475 def BLEZ : CBranchZero<0x07, "blez", setle>;
476 def BLTZ : CBranchZero<0x01, "bltz", setlt>;
479 def BGEZAL : BranchLink<"bgezal">;
480 def BLTZAL : BranchLink<"bltzal">;
482 let isReturn=1, isTerminator=1, hasDelaySlot=1,
483 isBarrier=1, hasCtrlDep=1, rs=0, rt=0, shamt=0 in
484 def RET : FR <0x00, 0x02, (outs), (ins CPURegs:$target),
485 "jr\t$target", [(MipsRet CPURegs:$target)], IIBranch>;
487 /// Multiply and Divide Instructions.
488 def MULT : Mul<0x18, "mult", IIImul>;
489 def MULTu : Mul<0x19, "multu", IIImul>;
490 def SDIV : Div<MipsDivRem, 0x1a, "div", IIIdiv>;
491 def UDIV : Div<MipsDivRemU, 0x1b, "divu", IIIdiv>;
494 def MTHI : MoveToLOHI<0x11, "mthi">;
496 def MTLO : MoveToLOHI<0x13, "mtlo">;
499 def MFHI : MoveFromLOHI<0x10, "mfhi">;
501 def MFLO : MoveFromLOHI<0x12, "mflo">;
503 /// Sign Ext In Register Instructions.
504 let Predicates = [HasSEInReg] in {
505 let shamt = 0x10, rs = 0 in
506 def SEB : SignExtInReg<0x21, "seb", i8>;
508 let shamt = 0x18, rs = 0 in
509 def SEH : SignExtInReg<0x20, "seh", i16>;
513 def CLZ : CountLeading<0b100000, "clz",
514 [(set CPURegs:$dst, (ctlz CPURegs:$src))]>;
515 def CLO : CountLeading<0b100001, "clo",
516 [(set CPURegs:$dst, (ctlz (not CPURegs:$src)))]>;
519 let Predicates = [HasSwap] in {
520 let shamt = 0x3, rs = 0 in
521 def WSBW : ByteSwap<0x20, "wsbw">;
525 def MIPS_CMOV_ZERO : PatLeaf<(i32 0)>;
526 def MIPS_CMOV_NZERO : PatLeaf<(i32 1)>;
528 // Conditional moves:
529 // These instructions are expanded in
530 // MipsISelLowering::EmitInstrWithCustomInserter if target does not have
531 // conditional move instructions.
532 // flag:int, data:int
533 let usesCustomInserter = 1, shamt = 0, Constraints = "$F = $dst" in
534 class CondMovIntInt<bits<6> funct, string instr_asm> :
535 FR<0, funct, (outs CPURegs:$dst),
536 (ins CPURegs:$T, CPURegs:$cond, CPURegs:$F),
537 !strconcat(instr_asm, "\t$dst, $T, $cond"), [], NoItinerary>;
539 def MOVZ_I : CondMovIntInt<0x0a, "movz">;
540 def MOVN_I : CondMovIntInt<0x0b, "movn">;
544 def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
546 // FrameIndexes are legalized when they are operands from load/store
547 // instructions. The same not happens for stack address copies, so an
548 // add op with mem ComplexPattern is used and the stack address copy
549 // can be matched. It's similar to Sparc LEA_ADDRi
550 def LEA_ADDiu : EffectiveAddress<"addiu\t$dst, ${addr:stackloc}">;
553 def MADD : MArithR<0, "madd", MipsMAdd, 1>;
554 def MADDU : MArithR<1, "maddu", MipsMAddu, 1>;
555 def MSUB : MArithR<4, "msub", MipsMSub>;
556 def MSUBU : MArithR<5, "msubu", MipsMSubu>;
558 // MUL is a assembly macro in the current used ISAs. In recent ISA's
559 // it is a real instruction.
560 def MUL : ArithR<0x1c, 0x02, "mul", mul, IIImul, 1>, Requires<[IsMips32]>;
562 def RDHWR : ReadHardware;
564 //===----------------------------------------------------------------------===//
565 // Arbitrary patterns that map to one or more instructions
566 //===----------------------------------------------------------------------===//
569 def : Pat<(i32 immSExt16:$in),
570 (ADDiu ZERO, imm:$in)>;
571 def : Pat<(i32 immZExt16:$in),
572 (ORi ZERO, imm:$in)>;
574 // Arbitrary immediates
575 def : Pat<(i32 imm:$imm),
576 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
579 def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
580 (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
581 def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
582 (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
583 def : Pat<(addc CPURegs:$src, immSExt16:$imm),
584 (ADDiu CPURegs:$src, imm:$imm)>;
587 def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
588 (JAL tglobaladdr:$dst)>;
589 def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
590 (JAL texternalsym:$dst)>;
591 //def : Pat<(MipsJmpLink CPURegs:$dst),
592 // (JALR CPURegs:$dst)>;
595 def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
596 def : Pat<(MipsHi tblockaddress:$in), (LUi tblockaddress:$in)>;
597 def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
598 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
599 def : Pat<(add CPURegs:$hi, (MipsLo tblockaddress:$lo)),
600 (ADDiu CPURegs:$hi, tblockaddress:$lo)>;
602 def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
603 def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
604 (ADDiu CPURegs:$hi, tjumptable:$lo)>;
606 def : Pat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
607 def : Pat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)),
608 (ADDiu CPURegs:$hi, tconstpool:$lo)>;
611 def : Pat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)),
612 (ADDiu CPURegs:$gp, tglobaladdr:$in)>;
613 def : Pat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)),
614 (ADDiu CPURegs:$gp, tconstpool:$in)>;
617 def : Pat<(add CPURegs:$gp, (MipsTlsGd tglobaltlsaddr:$in)),
618 (ADDiu CPURegs:$gp, tglobaltlsaddr:$in)>;
621 def : Pat<(MipsTprelHi tglobaltlsaddr:$in), (LUi tglobaltlsaddr:$in)>;
622 def : Pat<(add CPURegs:$hi, (MipsTprelLo tglobaltlsaddr:$lo)),
623 (ADDiu CPURegs:$hi, tglobaltlsaddr:$lo)>;
626 class WrapperPICPat<SDNode node>:
627 Pat<(MipsWrapperPIC node:$in),
628 (ADDiu GP, node:$in)>;
630 def : WrapperPICPat<tglobaladdr>;
631 def : WrapperPICPat<tconstpool>;
632 def : WrapperPICPat<texternalsym>;
633 def : WrapperPICPat<tblockaddress>;
634 def : WrapperPICPat<tjumptable>;
636 // Mips does not have "not", so we expand our way
637 def : Pat<(not CPURegs:$in),
638 (NOR CPURegs:$in, ZERO)>;
640 // extended load and stores
641 def : Pat<(extloadi1 addr:$src), (LBu addr:$src)>;
642 def : Pat<(extloadi8 addr:$src), (LBu addr:$src)>;
643 def : Pat<(extloadi16 addr:$src), (LHu addr:$src)>;
646 def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
649 def : Pat<(brcond (setne CPURegs:$lhs, 0), bb:$dst),
650 (BNE CPURegs:$lhs, ZERO, bb:$dst)>;
651 def : Pat<(brcond (seteq CPURegs:$lhs, 0), bb:$dst),
652 (BEQ CPURegs:$lhs, ZERO, bb:$dst)>;
654 def : Pat<(brcond (setge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
655 (BEQ (SLT CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
656 def : Pat<(brcond (setuge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
657 (BEQ (SLTu CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
658 def : Pat<(brcond (setge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
659 (BEQ (SLTi CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
660 def : Pat<(brcond (setuge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
661 (BEQ (SLTiu CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
663 def : Pat<(brcond (setle CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
664 (BEQ (SLT CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
665 def : Pat<(brcond (setule CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
666 (BEQ (SLTu CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
668 def : Pat<(brcond CPURegs:$cond, bb:$dst),
669 (BNE CPURegs:$cond, ZERO, bb:$dst)>;
672 multiclass MovzPats<RegisterClass RC, Instruction MOVZInst> {
673 def : Pat<(select (setge CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
674 (MOVZInst RC:$T, (SLT CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
675 def : Pat<(select (setuge CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
676 (MOVZInst RC:$T, (SLTu CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
677 def : Pat<(select (setge CPURegs:$lhs, immSExt16:$rhs), RC:$T, RC:$F),
678 (MOVZInst RC:$T, (SLTi CPURegs:$lhs, immSExt16:$rhs), RC:$F)>;
679 def : Pat<(select (setuge CPURegs:$lh, immSExt16:$rh), RC:$T, RC:$F),
680 (MOVZInst RC:$T, (SLTiu CPURegs:$lh, immSExt16:$rh), RC:$F)>;
681 def : Pat<(select (setle CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
682 (MOVZInst RC:$T, (SLT CPURegs:$rhs, CPURegs:$lhs), RC:$F)>;
683 def : Pat<(select (setule CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
684 (MOVZInst RC:$T, (SLTu CPURegs:$rhs, CPURegs:$lhs), RC:$F)>;
685 def : Pat<(select (seteq CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
686 (MOVZInst RC:$T, (XOR CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
687 def : Pat<(select (seteq CPURegs:$lhs, 0), RC:$T, RC:$F),
688 (MOVZInst RC:$T, CPURegs:$lhs, RC:$F)>;
691 multiclass MovnPats<RegisterClass RC, Instruction MOVNInst> {
692 def : Pat<(select (setne CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
693 (MOVNInst RC:$T, (XOR CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
694 def : Pat<(select CPURegs:$cond, RC:$T, RC:$F),
695 (MOVNInst RC:$T, CPURegs:$cond, RC:$F)>;
696 def : Pat<(select (setne CPURegs:$lhs, 0), RC:$T, RC:$F),
697 (MOVNInst RC:$T, CPURegs:$lhs, RC:$F)>;
700 defm : MovzPats<CPURegs, MOVZ_I>;
701 defm : MovnPats<CPURegs, MOVN_I>;
704 def : Pat<(seteq CPURegs:$lhs, CPURegs:$rhs),
705 (SLTu (XOR CPURegs:$lhs, CPURegs:$rhs), 1)>;
706 def : Pat<(setne CPURegs:$lhs, CPURegs:$rhs),
707 (SLTu ZERO, (XOR CPURegs:$lhs, CPURegs:$rhs))>;
709 def : Pat<(setle CPURegs:$lhs, CPURegs:$rhs),
710 (XORi (SLT CPURegs:$rhs, CPURegs:$lhs), 1)>;
711 def : Pat<(setule CPURegs:$lhs, CPURegs:$rhs),
712 (XORi (SLTu CPURegs:$rhs, CPURegs:$lhs), 1)>;
714 def : Pat<(setgt CPURegs:$lhs, CPURegs:$rhs),
715 (SLT CPURegs:$rhs, CPURegs:$lhs)>;
716 def : Pat<(setugt CPURegs:$lhs, CPURegs:$rhs),
717 (SLTu CPURegs:$rhs, CPURegs:$lhs)>;
719 def : Pat<(setge CPURegs:$lhs, CPURegs:$rhs),
720 (XORi (SLT CPURegs:$lhs, CPURegs:$rhs), 1)>;
721 def : Pat<(setuge CPURegs:$lhs, CPURegs:$rhs),
722 (XORi (SLTu CPURegs:$lhs, CPURegs:$rhs), 1)>;
724 def : Pat<(setge CPURegs:$lhs, immSExt16:$rhs),
725 (XORi (SLTi CPURegs:$lhs, immSExt16:$rhs), 1)>;
726 def : Pat<(setuge CPURegs:$lhs, immSExt16:$rhs),
727 (XORi (SLTiu CPURegs:$lhs, immSExt16:$rhs), 1)>;
729 //===----------------------------------------------------------------------===//
730 // Floating Point Support
731 //===----------------------------------------------------------------------===//
733 include "MipsInstrFPU.td"