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,
90 // Target constant nodes that are not part of any isel patterns and remain
91 // unchanged can cause instructions with illegal operands to be emitted.
92 // Wrapper node patterns give the instruction selector a chance to replace
93 // target constant nodes that would otherwise remain unchanged with ADDiu
94 // nodes. Without these wrapper node patterns, the following conditional move
95 // instrucion is emitted when function cmov2 in test/CodeGen/Mips/cmov.ll is
97 // movn %got(d)($gp), %got(c)($gp), $4
98 // This instruction is illegal since movn can take only register operands.
100 def MipsWrapperPIC : SDNode<"MipsISD::WrapperPIC", SDTIntUnaryOp>;
102 //===----------------------------------------------------------------------===//
103 // Mips Instruction Predicate Definitions.
104 //===----------------------------------------------------------------------===//
105 def HasSEInReg : Predicate<"Subtarget.hasSEInReg()">;
106 def HasBitCount : Predicate<"Subtarget.hasBitCount()">;
107 def HasSwap : Predicate<"Subtarget.hasSwap()">;
108 def HasCondMov : Predicate<"Subtarget.hasCondMov()">;
109 def IsMips32 : Predicate<"Subtarget.isMips32()">;
110 def IsMips32r2 : Predicate<"Subtarget.isMips32r2()">;
112 //===----------------------------------------------------------------------===//
113 // Mips Operand, Complex Patterns and Transformations Definitions.
114 //===----------------------------------------------------------------------===//
116 // Instruction operand types
117 def brtarget : Operand<OtherVT>;
118 def calltarget : Operand<i32>;
119 def simm16 : Operand<i32>;
120 def shamt : Operand<i32>;
123 def uimm16 : Operand<i32> {
124 let PrintMethod = "printUnsignedImm";
128 def mem : Operand<i32> {
129 let PrintMethod = "printMemOperand";
130 let MIOperandInfo = (ops simm16, CPURegs);
133 // Transformation Function - get the lower 16 bits.
134 def LO16 : SDNodeXForm<imm, [{
135 return getI32Imm((unsigned)N->getZExtValue() & 0xFFFF);
138 // Transformation Function - get the higher 16 bits.
139 def HI16 : SDNodeXForm<imm, [{
140 return getI32Imm((unsigned)N->getZExtValue() >> 16);
143 // Node immediate fits as 16-bit sign extended on target immediate.
145 def immSExt16 : PatLeaf<(imm), [{ return isInt<16>(N->getSExtValue()); }]>;
147 // Node immediate fits as 16-bit zero extended on target immediate.
148 // The LO16 param means that only the lower 16 bits of the node
149 // immediate are caught.
151 def immZExt16 : PatLeaf<(imm), [{
152 if (N->getValueType(0) == MVT::i32)
153 return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
155 return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
158 // shamt field must fit in 5 bits.
159 def immZExt5 : PatLeaf<(imm), [{
160 return N->getZExtValue() == ((N->getZExtValue()) & 0x1f) ;
163 // Mips Address Mode! SDNode frameindex could possibily be a match
164 // since load and store instructions from stack used it.
165 def addr : ComplexPattern<iPTR, 2, "SelectAddr", [frameindex], []>;
167 //===----------------------------------------------------------------------===//
168 // Instructions specific format
169 //===----------------------------------------------------------------------===//
171 // Arithmetic 3 register operands
172 class ArithR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
173 InstrItinClass itin, bit isComm = 0>:
174 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
175 !strconcat(instr_asm, "\t$dst, $b, $c"),
176 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], itin> {
177 let isCommutable = isComm;
180 class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm,
182 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
183 !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu> {
184 let isCommutable = isComm;
187 // Arithmetic 2 register operands
188 class ArithI<bits<6> op, string instr_asm, SDNode OpNode,
189 Operand Od, PatLeaf imm_type> :
190 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
191 !strconcat(instr_asm, "\t$dst, $b, $c"),
192 [(set CPURegs:$dst, (OpNode CPURegs:$b, imm_type:$c))], IIAlu>;
194 class ArithOverflowI<bits<6> op, string instr_asm, SDNode OpNode,
195 Operand Od, PatLeaf imm_type> :
196 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
197 !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu>;
199 // Arithmetic Multiply ADD/SUB
200 let rd = 0, shamt = 0, Defs = [HI, LO], Uses = [HI, LO] in
201 class MArithR<bits<6> func, string instr_asm, SDNode op, bit isComm = 0> :
202 FR<0x1c, func, (outs), (ins CPURegs:$rs, CPURegs:$rt),
203 !strconcat(instr_asm, "\t$rs, $rt"),
204 [(op CPURegs:$rs, CPURegs:$rt, LO, HI)], IIImul> {
205 let isCommutable = isComm;
209 let isCommutable = 1 in
210 class LogicR<bits<6> func, string instr_asm, SDNode OpNode>:
211 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
212 !strconcat(instr_asm, "\t$dst, $b, $c"),
213 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
215 class LogicI<bits<6> op, string instr_asm, SDNode OpNode>:
216 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, uimm16:$c),
217 !strconcat(instr_asm, "\t$dst, $b, $c"),
218 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt16:$c))], IIAlu>;
220 let isCommutable = 1 in
221 class LogicNOR<bits<6> op, bits<6> func, string instr_asm>:
222 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
223 !strconcat(instr_asm, "\t$dst, $b, $c"),
224 [(set CPURegs:$dst, (not (or CPURegs:$b, CPURegs:$c)))], IIAlu>;
227 class LogicR_shift_rotate_imm<bits<6> func, bits<5> _rs, string instr_asm,
229 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, shamt:$c),
230 !strconcat(instr_asm, "\t$dst, $b, $c"),
231 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt5:$c))], IIAlu> {
235 class LogicR_shift_rotate_reg<bits<6> func, bits<5> _shamt, string instr_asm,
237 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$c, CPURegs:$b),
238 !strconcat(instr_asm, "\t$dst, $b, $c"),
239 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu> {
243 // Load Upper Imediate
244 class LoadUpper<bits<6> op, string instr_asm>:
248 !strconcat(instr_asm, "\t$dst, $imm"),
252 let canFoldAsLoad = 1, hasDelaySlot = 1 in
253 class LoadM<bits<6> op, string instr_asm, PatFrag OpNode>:
254 FI<op, (outs CPURegs:$dst), (ins mem:$addr),
255 !strconcat(instr_asm, "\t$dst, $addr"),
256 [(set CPURegs:$dst, (OpNode addr:$addr))], IILoad>;
258 class StoreM<bits<6> op, string instr_asm, PatFrag OpNode>:
259 FI<op, (outs), (ins CPURegs:$dst, mem:$addr),
260 !strconcat(instr_asm, "\t$dst, $addr"),
261 [(OpNode CPURegs:$dst, addr:$addr)], IIStore>;
263 // Conditional Branch
264 let isBranch = 1, isTerminator=1, hasDelaySlot = 1 in {
265 class CBranch<bits<6> op, string instr_asm, PatFrag cond_op>:
266 FI<op, (outs), (ins CPURegs:$a, CPURegs:$b, brtarget:$offset),
267 !strconcat(instr_asm, "\t$a, $b, $offset"),
268 [(brcond (cond_op CPURegs:$a, CPURegs:$b), bb:$offset)],
271 class CBranchZero<bits<6> op, string instr_asm, PatFrag cond_op>:
272 FI<op, (outs), (ins CPURegs:$src, brtarget:$offset),
273 !strconcat(instr_asm, "\t$src, $offset"),
274 [(brcond (cond_op CPURegs:$src, 0), bb:$offset)],
279 class SetCC_R<bits<6> op, bits<6> func, string instr_asm,
281 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
282 !strconcat(instr_asm, "\t$dst, $b, $c"),
283 [(set CPURegs:$dst, (cond_op CPURegs:$b, CPURegs:$c))],
286 class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op,
287 Operand Od, PatLeaf imm_type>:
288 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
289 !strconcat(instr_asm, "\t$dst, $b, $c"),
290 [(set CPURegs:$dst, (cond_op CPURegs:$b, imm_type:$c))],
293 // Unconditional branch
294 let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
295 class JumpFJ<bits<6> op, string instr_asm>:
296 FJ<op, (outs), (ins brtarget:$target),
297 !strconcat(instr_asm, "\t$target"), [(br bb:$target)], IIBranch>;
299 let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in
300 class JumpFR<bits<6> op, bits<6> func, string instr_asm>:
301 FR<op, func, (outs), (ins CPURegs:$target),
302 !strconcat(instr_asm, "\t$target"), [(brind CPURegs:$target)], IIBranch>;
304 // Jump and Link (Call)
305 let isCall=1, hasDelaySlot=1,
306 // All calls clobber the non-callee saved registers...
307 Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9,
308 K0, K1, D0, D1, D2, D3, D4, D5, D6, D7, D8, D9], Uses = [GP] in {
309 class JumpLink<bits<6> op, string instr_asm>:
310 FJ<op, (outs), (ins calltarget:$target, variable_ops),
311 !strconcat(instr_asm, "\t$target"), [(MipsJmpLink imm:$target)],
315 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
316 FR<op, func, (outs), (ins CPURegs:$rs, variable_ops),
317 !strconcat(instr_asm, "\t$rs"), [(MipsJmpLink CPURegs:$rs)], IIBranch>;
319 class BranchLink<string instr_asm>:
320 FI<0x1, (outs), (ins CPURegs:$rs, brtarget:$target, variable_ops),
321 !strconcat(instr_asm, "\t$rs, $target"), [], IIBranch>;
325 let Defs = [HI, LO] in {
326 let isCommutable = 1 in
327 class Mul<bits<6> func, string instr_asm, InstrItinClass itin>:
328 FR<0x00, func, (outs), (ins CPURegs:$a, CPURegs:$b),
329 !strconcat(instr_asm, "\t$a, $b"), [], itin>;
331 class Div<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin>:
332 FR<0x00, func, (outs), (ins CPURegs:$a, CPURegs:$b),
333 !strconcat(instr_asm, "\t$$zero, $a, $b"),
334 [(op CPURegs:$a, CPURegs:$b)], itin>;
338 class MoveFromLOHI<bits<6> func, string instr_asm>:
339 FR<0x00, func, (outs CPURegs:$dst), (ins),
340 !strconcat(instr_asm, "\t$dst"), [], IIHiLo>;
342 class MoveToLOHI<bits<6> func, string instr_asm>:
343 FR<0x00, func, (outs), (ins CPURegs:$src),
344 !strconcat(instr_asm, "\t$src"), [], IIHiLo>;
346 class EffectiveAddress<string instr_asm> :
347 FI<0x09, (outs CPURegs:$dst), (ins mem:$addr),
348 instr_asm, [(set CPURegs:$dst, addr:$addr)], IIAlu>;
350 // Count Leading Ones/Zeros in Word
351 class CountLeading<bits<6> func, string instr_asm, list<dag> pattern>:
352 FR<0x1c, func, (outs CPURegs:$dst), (ins CPURegs:$src),
353 !strconcat(instr_asm, "\t$dst, $src"), pattern, IIAlu>,
354 Requires<[HasBitCount]> {
359 // Sign Extend in Register.
360 class SignExtInReg<bits<6> func, string instr_asm, ValueType vt>:
361 FR<0x3f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
362 !strconcat(instr_asm, "\t$dst, $src"),
363 [(set CPURegs:$dst, (sext_inreg CPURegs:$src, vt))], NoItinerary>;
366 class ByteSwap<bits<6> func, string instr_asm>:
367 FR<0x1f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
368 !strconcat(instr_asm, "\t$dst, $src"),
369 [(set CPURegs:$dst, (bswap CPURegs:$src))], NoItinerary>;
372 class CondMov<bits<6> func, string instr_asm, PatLeaf MovCode>:
373 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$F, CPURegs:$T,
374 CPURegs:$cond), !strconcat(instr_asm, "\t$dst, $T, $cond"),
378 class ReadHardware: FR<0x1f, 0x3b, (outs CPURegs:$dst), (ins HWRegs:$src),
379 "rdhwr\t$dst, $src", [], IIAlu> {
384 //===----------------------------------------------------------------------===//
385 // Pseudo instructions
386 //===----------------------------------------------------------------------===//
388 // As stack alignment is always done with addiu, we need a 16-bit immediate
389 let Defs = [SP], Uses = [SP] in {
390 def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
391 "!ADJCALLSTACKDOWN $amt",
392 [(callseq_start timm:$amt)]>;
393 def ADJCALLSTACKUP : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
394 "!ADJCALLSTACKUP $amt1",
395 [(callseq_end timm:$amt1, timm:$amt2)]>;
398 // Some assembly macros need to avoid pseudoinstructions and assembler
399 // automatic reodering, we should reorder ourselves.
400 def MACRO : MipsPseudo<(outs), (ins), ".set\tmacro", []>;
401 def REORDER : MipsPseudo<(outs), (ins), ".set\treorder", []>;
402 def NOMACRO : MipsPseudo<(outs), (ins), ".set\tnomacro", []>;
403 def NOREORDER : MipsPseudo<(outs), (ins), ".set\tnoreorder", []>;
405 // These macros are inserted to prevent GAS from complaining
406 // when using the AT register.
407 def NOAT : MipsPseudo<(outs), (ins), ".set\tnoat", []>;
408 def ATMACRO : MipsPseudo<(outs), (ins), ".set\tat", []>;
410 // When handling PIC code the assembler needs .cpload and .cprestore
411 // directives. If the real instructions corresponding these directives
412 // are used, we have the same behavior, but get also a bunch of warnings
413 // from the assembler.
414 def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$picreg), ".cpload\t$picreg", []>;
415 def CPRESTORE : MipsPseudo<(outs), (ins i32imm:$loc), ".cprestore\t$loc\n", []>;
417 let usesCustomInserter = 1 in {
418 def ATOMIC_LOAD_ADD_I8 : MipsPseudo<
419 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
420 "atomic_load_add_8\t$dst, $ptr, $incr",
421 [(set CPURegs:$dst, (atomic_load_add_8 CPURegs:$ptr, CPURegs:$incr))]>;
422 def ATOMIC_LOAD_ADD_I16 : MipsPseudo<
423 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
424 "atomic_load_add_16\t$dst, $ptr, $incr",
425 [(set CPURegs:$dst, (atomic_load_add_16 CPURegs:$ptr, CPURegs:$incr))]>;
426 def ATOMIC_LOAD_ADD_I32 : MipsPseudo<
427 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
428 "atomic_load_add_32\t$dst, $ptr, $incr",
429 [(set CPURegs:$dst, (atomic_load_add_32 CPURegs:$ptr, CPURegs:$incr))]>;
431 def ATOMIC_LOAD_SUB_I8 : MipsPseudo<
432 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
433 "atomic_load_sub_8\t$dst, $ptr, $incr",
434 [(set CPURegs:$dst, (atomic_load_sub_8 CPURegs:$ptr, CPURegs:$incr))]>;
435 def ATOMIC_LOAD_SUB_I16 : MipsPseudo<
436 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
437 "atomic_load_sub_16\t$dst, $ptr, $incr",
438 [(set CPURegs:$dst, (atomic_load_sub_16 CPURegs:$ptr, CPURegs:$incr))]>;
439 def ATOMIC_LOAD_SUB_I32 : MipsPseudo<
440 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
441 "atomic_load_sub_32\t$dst, $ptr, $incr",
442 [(set CPURegs:$dst, (atomic_load_sub_32 CPURegs:$ptr, CPURegs:$incr))]>;
444 def ATOMIC_LOAD_AND_I8 : MipsPseudo<
445 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
446 "atomic_load_and_8\t$dst, $ptr, $incr",
447 [(set CPURegs:$dst, (atomic_load_and_8 CPURegs:$ptr, CPURegs:$incr))]>;
448 def ATOMIC_LOAD_AND_I16 : MipsPseudo<
449 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
450 "atomic_load_and_16\t$dst, $ptr, $incr",
451 [(set CPURegs:$dst, (atomic_load_and_16 CPURegs:$ptr, CPURegs:$incr))]>;
452 def ATOMIC_LOAD_AND_I32 : MipsPseudo<
453 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
454 "atomic_load_and_32\t$dst, $ptr, $incr",
455 [(set CPURegs:$dst, (atomic_load_and_32 CPURegs:$ptr, CPURegs:$incr))]>;
457 def ATOMIC_LOAD_OR_I8 : MipsPseudo<
458 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
459 "atomic_load_or_8\t$dst, $ptr, $incr",
460 [(set CPURegs:$dst, (atomic_load_or_8 CPURegs:$ptr, CPURegs:$incr))]>;
461 def ATOMIC_LOAD_OR_I16 : MipsPseudo<
462 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
463 "atomic_load_or_16\t$dst, $ptr, $incr",
464 [(set CPURegs:$dst, (atomic_load_or_16 CPURegs:$ptr, CPURegs:$incr))]>;
465 def ATOMIC_LOAD_OR_I32 : MipsPseudo<
466 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
467 "atomic_load_or_32\t$dst, $ptr, $incr",
468 [(set CPURegs:$dst, (atomic_load_or_32 CPURegs:$ptr, CPURegs:$incr))]>;
470 def ATOMIC_LOAD_XOR_I8 : MipsPseudo<
471 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
472 "atomic_load_xor_8\t$dst, $ptr, $incr",
473 [(set CPURegs:$dst, (atomic_load_xor_8 CPURegs:$ptr, CPURegs:$incr))]>;
474 def ATOMIC_LOAD_XOR_I16 : MipsPseudo<
475 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
476 "atomic_load_xor_16\t$dst, $ptr, $incr",
477 [(set CPURegs:$dst, (atomic_load_xor_16 CPURegs:$ptr, CPURegs:$incr))]>;
478 def ATOMIC_LOAD_XOR_I32 : MipsPseudo<
479 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
480 "atomic_load_xor_32\t$dst, $ptr, $incr",
481 [(set CPURegs:$dst, (atomic_load_xor_32 CPURegs:$ptr, CPURegs:$incr))]>;
483 def ATOMIC_LOAD_NAND_I8 : MipsPseudo<
484 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
485 "atomic_load_nand_8\t$dst, $ptr, $incr",
486 [(set CPURegs:$dst, (atomic_load_nand_8 CPURegs:$ptr, CPURegs:$incr))]>;
487 def ATOMIC_LOAD_NAND_I16 : MipsPseudo<
488 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
489 "atomic_load_nand_16\t$dst, $ptr, $incr",
490 [(set CPURegs:$dst, (atomic_load_nand_16 CPURegs:$ptr, CPURegs:$incr))]>;
491 def ATOMIC_LOAD_NAND_I32 : MipsPseudo<
492 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
493 "atomic_load_nand_32\t$dst, $ptr, $incr",
494 [(set CPURegs:$dst, (atomic_load_nand_32 CPURegs:$ptr, CPURegs:$incr))]>;
496 def ATOMIC_SWAP_I8 : MipsPseudo<
497 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$val),
498 "atomic_swap_8\t$dst, $ptr, $val",
499 [(set CPURegs:$dst, (atomic_swap_8 CPURegs:$ptr, CPURegs:$val))]>;
500 def ATOMIC_SWAP_I16 : MipsPseudo<
501 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$val),
502 "atomic_swap_16\t$dst, $ptr, $val",
503 [(set CPURegs:$dst, (atomic_swap_16 CPURegs:$ptr, CPURegs:$val))]>;
504 def ATOMIC_SWAP_I32 : MipsPseudo<
505 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$val),
506 "atomic_swap_32\t$dst, $ptr, $val",
507 [(set CPURegs:$dst, (atomic_swap_32 CPURegs:$ptr, CPURegs:$val))]>;
509 def ATOMIC_CMP_SWAP_I8 : MipsPseudo<
510 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval),
511 "atomic_cmp_swap_8\t$dst, $ptr, $oldval, $newval",
513 (atomic_cmp_swap_8 CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval))]>;
514 def ATOMIC_CMP_SWAP_I16 : MipsPseudo<
515 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval),
516 "atomic_cmp_swap_16\t$dst, $ptr, $oldval, $newval",
518 (atomic_cmp_swap_16 CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval))]>;
519 def ATOMIC_CMP_SWAP_I32 : MipsPseudo<
520 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval),
521 "atomic_cmp_swap_32\t$dst, $ptr, $oldval, $newval",
523 (atomic_cmp_swap_32 CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval))]>;
526 //===----------------------------------------------------------------------===//
527 // Instruction definition
528 //===----------------------------------------------------------------------===//
530 //===----------------------------------------------------------------------===//
531 // MipsI Instructions
532 //===----------------------------------------------------------------------===//
534 /// Arithmetic Instructions (ALU Immediate)
535 def ADDiu : ArithI<0x09, "addiu", add, simm16, immSExt16>;
536 def ADDi : ArithOverflowI<0x08, "addi", add, simm16, immSExt16>;
537 def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16>;
538 def SLTiu : SetCC_I<0x0b, "sltiu", setult, simm16, immSExt16>;
539 def ANDi : LogicI<0x0c, "andi", and>;
540 def ORi : LogicI<0x0d, "ori", or>;
541 def XORi : LogicI<0x0e, "xori", xor>;
542 def LUi : LoadUpper<0x0f, "lui">;
544 /// Arithmetic Instructions (3-Operand, R-Type)
545 def ADDu : ArithR<0x00, 0x21, "addu", add, IIAlu, 1>;
546 def SUBu : ArithR<0x00, 0x23, "subu", sub, IIAlu>;
547 def ADD : ArithOverflowR<0x00, 0x20, "add", 1>;
548 def SUB : ArithOverflowR<0x00, 0x22, "sub">;
549 def SLT : SetCC_R<0x00, 0x2a, "slt", setlt>;
550 def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult>;
551 def AND : LogicR<0x24, "and", and>;
552 def OR : LogicR<0x25, "or", or>;
553 def XOR : LogicR<0x26, "xor", xor>;
554 def NOR : LogicNOR<0x00, 0x27, "nor">;
556 /// Shift Instructions
557 def SLL : LogicR_shift_rotate_imm<0x00, 0x00, "sll", shl>;
558 def SRL : LogicR_shift_rotate_imm<0x02, 0x00, "srl", srl>;
559 def SRA : LogicR_shift_rotate_imm<0x03, 0x00, "sra", sra>;
560 def SLLV : LogicR_shift_rotate_reg<0x04, 0x00, "sllv", shl>;
561 def SRLV : LogicR_shift_rotate_reg<0x06, 0x00, "srlv", srl>;
562 def SRAV : LogicR_shift_rotate_reg<0x07, 0x00, "srav", sra>;
564 // Rotate Instructions
565 let Predicates = [IsMips32r2] in {
566 def ROTR : LogicR_shift_rotate_imm<0x02, 0x01, "rotr", rotr>;
567 def ROTRV : LogicR_shift_rotate_reg<0x06, 0x01, "rotrv", rotr>;
570 /// Load and Store Instructions
571 def LB : LoadM<0x20, "lb", sextloadi8>;
572 def LBu : LoadM<0x24, "lbu", zextloadi8>;
573 def LH : LoadM<0x21, "lh", sextloadi16>;
574 def LHu : LoadM<0x25, "lhu", zextloadi16>;
575 def LW : LoadM<0x23, "lw", load>;
576 def SB : StoreM<0x28, "sb", truncstorei8>;
577 def SH : StoreM<0x29, "sh", truncstorei16>;
578 def SW : StoreM<0x2b, "sw", store>;
580 /// Load-linked, Store-conditional
581 let hasDelaySlot = 1 in
582 def LL : FI<0x30, (outs CPURegs:$dst), (ins mem:$addr),
583 "ll\t$dst, $addr", [], IILoad>;
584 let Constraints = "$src = $dst" in
585 def SC : FI<0x38, (outs CPURegs:$dst), (ins CPURegs:$src, mem:$addr),
586 "sc\t$src, $addr", [], IIStore>;
588 /// Jump and Branch Instructions
589 def J : JumpFJ<0x02, "j">;
590 def JR : JumpFR<0x00, 0x08, "jr">;
591 def JAL : JumpLink<0x03, "jal">;
592 def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
593 def BEQ : CBranch<0x04, "beq", seteq>;
594 def BNE : CBranch<0x05, "bne", setne>;
597 def BGEZ : CBranchZero<0x01, "bgez", setge>;
600 def BGTZ : CBranchZero<0x07, "bgtz", setgt>;
601 def BLEZ : CBranchZero<0x07, "blez", setle>;
602 def BLTZ : CBranchZero<0x01, "bltz", setlt>;
605 def BGEZAL : BranchLink<"bgezal">;
606 def BLTZAL : BranchLink<"bltzal">;
608 let isReturn=1, isTerminator=1, hasDelaySlot=1,
609 isBarrier=1, hasCtrlDep=1, rs=0, rt=0, shamt=0 in
610 def RET : FR <0x00, 0x02, (outs), (ins CPURegs:$target),
611 "jr\t$target", [(MipsRet CPURegs:$target)], IIBranch>;
613 /// Multiply and Divide Instructions.
614 def MULT : Mul<0x18, "mult", IIImul>;
615 def MULTu : Mul<0x19, "multu", IIImul>;
616 def SDIV : Div<MipsDivRem, 0x1a, "div", IIIdiv>;
617 def UDIV : Div<MipsDivRemU, 0x1b, "divu", IIIdiv>;
620 def MTHI : MoveToLOHI<0x11, "mthi">;
622 def MTLO : MoveToLOHI<0x13, "mtlo">;
625 def MFHI : MoveFromLOHI<0x10, "mfhi">;
627 def MFLO : MoveFromLOHI<0x12, "mflo">;
629 /// Sign Ext In Register Instructions.
630 let Predicates = [HasSEInReg] in {
631 let shamt = 0x10, rs = 0 in
632 def SEB : SignExtInReg<0x21, "seb", i8>;
634 let shamt = 0x18, rs = 0 in
635 def SEH : SignExtInReg<0x20, "seh", i16>;
639 def CLZ : CountLeading<0b100000, "clz",
640 [(set CPURegs:$dst, (ctlz CPURegs:$src))]>;
641 def CLO : CountLeading<0b100001, "clo",
642 [(set CPURegs:$dst, (ctlz (not CPURegs:$src)))]>;
645 let Predicates = [HasSwap] in {
646 let shamt = 0x3, rs = 0 in
647 def WSBW : ByteSwap<0x20, "wsbw">;
651 def MIPS_CMOV_ZERO : PatLeaf<(i32 0)>;
652 def MIPS_CMOV_NZERO : PatLeaf<(i32 1)>;
654 // Conditional moves:
655 // These instructions are expanded in
656 // MipsISelLowering::EmitInstrWithCustomInserter if target does not have
657 // conditional move instructions.
658 // flag:int, data:int
659 let usesCustomInserter = 1, shamt = 0, Constraints = "$F = $dst" in
660 class CondMovIntInt<bits<6> funct, string instr_asm> :
661 FR<0, funct, (outs CPURegs:$dst),
662 (ins CPURegs:$T, CPURegs:$cond, CPURegs:$F),
663 !strconcat(instr_asm, "\t$dst, $T, $cond"), [], NoItinerary>;
665 def MOVZ_I : CondMovIntInt<0x0a, "movz">;
666 def MOVN_I : CondMovIntInt<0x0b, "movn">;
670 def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
672 // FrameIndexes are legalized when they are operands from load/store
673 // instructions. The same not happens for stack address copies, so an
674 // add op with mem ComplexPattern is used and the stack address copy
675 // can be matched. It's similar to Sparc LEA_ADDRi
676 def LEA_ADDiu : EffectiveAddress<"addiu\t$dst, ${addr:stackloc}">;
679 def MADD : MArithR<0, "madd", MipsMAdd, 1>;
680 def MADDU : MArithR<1, "maddu", MipsMAddu, 1>;
681 def MSUB : MArithR<4, "msub", MipsMSub>;
682 def MSUBU : MArithR<5, "msubu", MipsMSubu>;
684 // MUL is a assembly macro in the current used ISAs. In recent ISA's
685 // it is a real instruction.
686 def MUL : ArithR<0x1c, 0x02, "mul", mul, IIImul, 1>, Requires<[IsMips32]>;
688 def RDHWR : ReadHardware;
690 //===----------------------------------------------------------------------===//
691 // Arbitrary patterns that map to one or more instructions
692 //===----------------------------------------------------------------------===//
695 def : Pat<(i32 immSExt16:$in),
696 (ADDiu ZERO, imm:$in)>;
697 def : Pat<(i32 immZExt16:$in),
698 (ORi ZERO, imm:$in)>;
700 // Arbitrary immediates
701 def : Pat<(i32 imm:$imm),
702 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
705 def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
706 (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
707 def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
708 (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
709 def : Pat<(addc CPURegs:$src, immSExt16:$imm),
710 (ADDiu CPURegs:$src, imm:$imm)>;
713 def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
714 (JAL tglobaladdr:$dst)>;
715 def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
716 (JAL texternalsym:$dst)>;
717 //def : Pat<(MipsJmpLink CPURegs:$dst),
718 // (JALR CPURegs:$dst)>;
721 def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
722 def : Pat<(MipsHi tblockaddress:$in), (LUi tblockaddress:$in)>;
723 def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
724 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
725 def : Pat<(add CPURegs:$hi, (MipsLo tblockaddress:$lo)),
726 (ADDiu CPURegs:$hi, tblockaddress:$lo)>;
728 def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
729 def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
730 (ADDiu CPURegs:$hi, tjumptable:$lo)>;
732 def : Pat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
733 def : Pat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)),
734 (ADDiu CPURegs:$hi, tconstpool:$lo)>;
737 def : Pat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)),
738 (ADDiu CPURegs:$gp, tglobaladdr:$in)>;
739 def : Pat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)),
740 (ADDiu CPURegs:$gp, tconstpool:$in)>;
743 def : Pat<(add CPURegs:$gp, (MipsTlsGd tglobaltlsaddr:$in)),
744 (ADDiu CPURegs:$gp, tglobaltlsaddr:$in)>;
747 def : Pat<(MipsTprelHi tglobaltlsaddr:$in), (LUi tglobaltlsaddr:$in)>;
748 def : Pat<(add CPURegs:$hi, (MipsTprelLo tglobaltlsaddr:$lo)),
749 (ADDiu CPURegs:$hi, tglobaltlsaddr:$lo)>;
752 class WrapperPICPat<SDNode node>:
753 Pat<(MipsWrapperPIC node:$in),
754 (ADDiu GP, node:$in)>;
756 def : WrapperPICPat<tglobaladdr>;
757 def : WrapperPICPat<tconstpool>;
758 def : WrapperPICPat<texternalsym>;
759 def : WrapperPICPat<tblockaddress>;
760 def : WrapperPICPat<tjumptable>;
762 // Mips does not have "not", so we expand our way
763 def : Pat<(not CPURegs:$in),
764 (NOR CPURegs:$in, ZERO)>;
766 // extended load and stores
767 def : Pat<(extloadi1 addr:$src), (LBu addr:$src)>;
768 def : Pat<(extloadi8 addr:$src), (LBu addr:$src)>;
769 def : Pat<(extloadi16 addr:$src), (LHu addr:$src)>;
772 def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
775 def : Pat<(brcond (setne CPURegs:$lhs, 0), bb:$dst),
776 (BNE CPURegs:$lhs, ZERO, bb:$dst)>;
777 def : Pat<(brcond (seteq CPURegs:$lhs, 0), bb:$dst),
778 (BEQ CPURegs:$lhs, ZERO, bb:$dst)>;
780 def : Pat<(brcond (setge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
781 (BEQ (SLT CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
782 def : Pat<(brcond (setuge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
783 (BEQ (SLTu CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
784 def : Pat<(brcond (setge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
785 (BEQ (SLTi CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
786 def : Pat<(brcond (setuge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
787 (BEQ (SLTiu CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
789 def : Pat<(brcond (setle CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
790 (BEQ (SLT CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
791 def : Pat<(brcond (setule CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
792 (BEQ (SLTu CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
794 def : Pat<(brcond CPURegs:$cond, bb:$dst),
795 (BNE CPURegs:$cond, ZERO, bb:$dst)>;
798 multiclass MovzPats<RegisterClass RC, Instruction MOVZInst> {
799 def : Pat<(select (setge CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
800 (MOVZInst RC:$T, (SLT CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
801 def : Pat<(select (setuge CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
802 (MOVZInst RC:$T, (SLTu CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
803 def : Pat<(select (setge CPURegs:$lhs, immSExt16:$rhs), RC:$T, RC:$F),
804 (MOVZInst RC:$T, (SLTi CPURegs:$lhs, immSExt16:$rhs), RC:$F)>;
805 def : Pat<(select (setuge CPURegs:$lh, immSExt16:$rh), RC:$T, RC:$F),
806 (MOVZInst RC:$T, (SLTiu CPURegs:$lh, immSExt16:$rh), RC:$F)>;
807 def : Pat<(select (setle CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
808 (MOVZInst RC:$T, (SLT CPURegs:$rhs, CPURegs:$lhs), RC:$F)>;
809 def : Pat<(select (setule CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
810 (MOVZInst RC:$T, (SLTu CPURegs:$rhs, CPURegs:$lhs), RC:$F)>;
811 def : Pat<(select (seteq CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
812 (MOVZInst RC:$T, (XOR CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
813 def : Pat<(select (seteq CPURegs:$lhs, 0), RC:$T, RC:$F),
814 (MOVZInst RC:$T, CPURegs:$lhs, RC:$F)>;
817 multiclass MovnPats<RegisterClass RC, Instruction MOVNInst> {
818 def : Pat<(select (setne CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
819 (MOVNInst RC:$T, (XOR CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
820 def : Pat<(select CPURegs:$cond, RC:$T, RC:$F),
821 (MOVNInst RC:$T, CPURegs:$cond, RC:$F)>;
822 def : Pat<(select (setne CPURegs:$lhs, 0), RC:$T, RC:$F),
823 (MOVNInst RC:$T, CPURegs:$lhs, RC:$F)>;
826 defm : MovzPats<CPURegs, MOVZ_I>;
827 defm : MovnPats<CPURegs, MOVN_I>;
830 def : Pat<(seteq CPURegs:$lhs, CPURegs:$rhs),
831 (SLTu (XOR CPURegs:$lhs, CPURegs:$rhs), 1)>;
832 def : Pat<(setne CPURegs:$lhs, CPURegs:$rhs),
833 (SLTu ZERO, (XOR CPURegs:$lhs, CPURegs:$rhs))>;
835 def : Pat<(setle CPURegs:$lhs, CPURegs:$rhs),
836 (XORi (SLT CPURegs:$rhs, CPURegs:$lhs), 1)>;
837 def : Pat<(setule CPURegs:$lhs, CPURegs:$rhs),
838 (XORi (SLTu CPURegs:$rhs, CPURegs:$lhs), 1)>;
840 def : Pat<(setgt CPURegs:$lhs, CPURegs:$rhs),
841 (SLT CPURegs:$rhs, CPURegs:$lhs)>;
842 def : Pat<(setugt CPURegs:$lhs, CPURegs:$rhs),
843 (SLTu CPURegs:$rhs, CPURegs:$lhs)>;
845 def : Pat<(setge CPURegs:$lhs, CPURegs:$rhs),
846 (XORi (SLT CPURegs:$lhs, CPURegs:$rhs), 1)>;
847 def : Pat<(setuge CPURegs:$lhs, CPURegs:$rhs),
848 (XORi (SLTu CPURegs:$lhs, CPURegs:$rhs), 1)>;
850 def : Pat<(setge CPURegs:$lhs, immSExt16:$rhs),
851 (XORi (SLTi CPURegs:$lhs, immSExt16:$rhs), 1)>;
852 def : Pat<(setuge CPURegs:$lhs, immSExt16:$rhs),
853 (XORi (SLTiu CPURegs:$lhs, immSExt16:$rhs), 1)>;
855 //===----------------------------------------------------------------------===//
856 // Floating Point Support
857 //===----------------------------------------------------------------------===//
859 include "MipsInstrFPU.td"