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, i32>,
46 def MipsJmpLink : SDNode<"MipsISD::JmpLink",SDT_MipsJmpLink,
47 [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue,
50 // Hi and Lo nodes are used to handle global addresses. Used on
51 // MipsISelLowering to lower stuff like GlobalAddress, ExternalSymbol
52 // static model. (nothing to do with Mips Registers Hi and Lo)
53 def MipsHi : SDNode<"MipsISD::Hi", SDTIntUnaryOp>;
54 def MipsLo : SDNode<"MipsISD::Lo", SDTIntUnaryOp>;
55 def MipsGPRel : SDNode<"MipsISD::GPRel", SDTIntUnaryOp>;
57 // TlsGd node is used to handle General Dynamic TLS
58 def MipsTlsGd : SDNode<"MipsISD::TlsGd", SDTIntUnaryOp>;
60 // TprelHi and TprelLo nodes are used to handle Local Exec TLS
61 def MipsTprelHi : SDNode<"MipsISD::TprelHi", SDTIntUnaryOp>;
62 def MipsTprelLo : SDNode<"MipsISD::TprelLo", SDTIntUnaryOp>;
65 def MipsThreadPointer: SDNode<"MipsISD::ThreadPointer", SDT_MipsThreadPointer>;
68 def MipsRet : SDNode<"MipsISD::Ret", SDT_MipsRet, [SDNPHasChain,
71 // These are target-independent nodes, but have target-specific formats.
72 def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_MipsCallSeqStart,
73 [SDNPHasChain, SDNPOutGlue]>;
74 def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_MipsCallSeqEnd,
75 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
78 def MipsMAdd : SDNode<"MipsISD::MAdd", SDT_MipsMAddMSub,
79 [SDNPOptInGlue, SDNPOutGlue]>;
80 def MipsMAddu : SDNode<"MipsISD::MAddu", SDT_MipsMAddMSub,
81 [SDNPOptInGlue, SDNPOutGlue]>;
82 def MipsMSub : SDNode<"MipsISD::MSub", SDT_MipsMAddMSub,
83 [SDNPOptInGlue, SDNPOutGlue]>;
84 def MipsMSubu : SDNode<"MipsISD::MSubu", SDT_MipsMAddMSub,
85 [SDNPOptInGlue, SDNPOutGlue]>;
88 def MipsDivRem : SDNode<"MipsISD::DivRem", SDT_MipsDivRem,
90 def MipsDivRemU : SDNode<"MipsISD::DivRemU", SDT_MipsDivRem,
93 // Target constant nodes that are not part of any isel patterns and remain
94 // unchanged can cause instructions with illegal operands to be emitted.
95 // Wrapper node patterns give the instruction selector a chance to replace
96 // target constant nodes that would otherwise remain unchanged with ADDiu
97 // nodes. Without these wrapper node patterns, the following conditional move
98 // instrucion is emitted when function cmov2 in test/CodeGen/Mips/cmov.ll is
100 // movn %got(d)($gp), %got(c)($gp), $4
101 // This instruction is illegal since movn can take only register operands.
103 def MipsWrapperPIC : SDNode<"MipsISD::WrapperPIC", SDTIntUnaryOp>;
105 // Pointer to dynamically allocated stack area.
106 def MipsDynAlloc : SDNode<"MipsISD::DynAlloc", SDT_MipsDynAlloc,
107 [SDNPHasChain, SDNPInGlue]>;
109 //===----------------------------------------------------------------------===//
110 // Mips Instruction Predicate Definitions.
111 //===----------------------------------------------------------------------===//
112 def HasSEInReg : Predicate<"Subtarget.hasSEInReg()">;
113 def HasBitCount : Predicate<"Subtarget.hasBitCount()">;
114 def HasSwap : Predicate<"Subtarget.hasSwap()">;
115 def HasCondMov : Predicate<"Subtarget.hasCondMov()">;
116 def IsMips32 : Predicate<"Subtarget.isMips32()">;
117 def IsMips32r2 : Predicate<"Subtarget.isMips32r2()">;
119 //===----------------------------------------------------------------------===//
120 // Mips Operand, Complex Patterns and Transformations Definitions.
121 //===----------------------------------------------------------------------===//
123 // Instruction operand types
124 def brtarget : Operand<OtherVT>;
125 def calltarget : Operand<i32>;
126 def simm16 : Operand<i32>;
127 def shamt : Operand<i32>;
130 def uimm16 : Operand<i32> {
131 let PrintMethod = "printUnsignedImm";
135 def mem : Operand<i32> {
136 let PrintMethod = "printMemOperand";
137 let MIOperandInfo = (ops simm16, CPURegs);
140 // Transformation Function - get the lower 16 bits.
141 def LO16 : SDNodeXForm<imm, [{
142 return getI32Imm((unsigned)N->getZExtValue() & 0xFFFF);
145 // Transformation Function - get the higher 16 bits.
146 def HI16 : SDNodeXForm<imm, [{
147 return getI32Imm((unsigned)N->getZExtValue() >> 16);
150 // Node immediate fits as 16-bit sign extended on target immediate.
152 def immSExt16 : PatLeaf<(imm), [{ return isInt<16>(N->getSExtValue()); }]>;
154 // Node immediate fits as 16-bit zero extended on target immediate.
155 // The LO16 param means that only the lower 16 bits of the node
156 // immediate are caught.
158 def immZExt16 : PatLeaf<(imm), [{
159 if (N->getValueType(0) == MVT::i32)
160 return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
162 return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
165 // shamt field must fit in 5 bits.
166 def immZExt5 : PatLeaf<(imm), [{
167 return N->getZExtValue() == ((N->getZExtValue()) & 0x1f) ;
170 // Mips Address Mode! SDNode frameindex could possibily be a match
171 // since load and store instructions from stack used it.
172 def addr : ComplexPattern<iPTR, 2, "SelectAddr", [frameindex], []>;
174 //===----------------------------------------------------------------------===//
175 // Instructions specific format
176 //===----------------------------------------------------------------------===//
178 // Arithmetic 3 register operands
179 class ArithR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
180 InstrItinClass itin, bit isComm = 0>:
181 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
182 !strconcat(instr_asm, "\t$dst, $b, $c"),
183 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], itin> {
184 let isCommutable = isComm;
187 class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm,
189 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
190 !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu> {
191 let isCommutable = isComm;
194 // Arithmetic 2 register operands
195 class ArithI<bits<6> op, string instr_asm, SDNode OpNode,
196 Operand Od, PatLeaf imm_type> :
197 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
198 !strconcat(instr_asm, "\t$dst, $b, $c"),
199 [(set CPURegs:$dst, (OpNode CPURegs:$b, imm_type:$c))], IIAlu>;
201 class ArithOverflowI<bits<6> op, string instr_asm, SDNode OpNode,
202 Operand Od, PatLeaf imm_type> :
203 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
204 !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu>;
206 // Arithmetic Multiply ADD/SUB
207 let rd = 0, shamt = 0, Defs = [HI, LO], Uses = [HI, LO] in
208 class MArithR<bits<6> func, string instr_asm, SDNode op, bit isComm = 0> :
209 FR<0x1c, func, (outs), (ins CPURegs:$rs, CPURegs:$rt),
210 !strconcat(instr_asm, "\t$rs, $rt"),
211 [(op CPURegs:$rs, CPURegs:$rt, LO, HI)], IIImul> {
212 let isCommutable = isComm;
216 let isCommutable = 1 in
217 class LogicR<bits<6> func, string instr_asm, SDNode OpNode>:
218 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
219 !strconcat(instr_asm, "\t$dst, $b, $c"),
220 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
222 class LogicI<bits<6> op, string instr_asm, SDNode OpNode>:
223 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, uimm16:$c),
224 !strconcat(instr_asm, "\t$dst, $b, $c"),
225 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt16:$c))], IIAlu>;
227 let isCommutable = 1 in
228 class LogicNOR<bits<6> op, bits<6> func, string instr_asm>:
229 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
230 !strconcat(instr_asm, "\t$dst, $b, $c"),
231 [(set CPURegs:$dst, (not (or CPURegs:$b, CPURegs:$c)))], IIAlu>;
234 class LogicR_shift_rotate_imm<bits<6> func, bits<5> _rs, string instr_asm,
236 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, shamt:$c),
237 !strconcat(instr_asm, "\t$dst, $b, $c"),
238 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt5:$c))], IIAlu> {
242 class LogicR_shift_rotate_reg<bits<6> func, bits<5> _shamt, string instr_asm,
244 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$c, CPURegs:$b),
245 !strconcat(instr_asm, "\t$dst, $b, $c"),
246 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu> {
250 // Load Upper Imediate
251 class LoadUpper<bits<6> op, string instr_asm>:
255 !strconcat(instr_asm, "\t$dst, $imm"),
259 let canFoldAsLoad = 1, hasDelaySlot = 1 in
260 class LoadM<bits<6> op, string instr_asm, PatFrag OpNode>:
261 FI<op, (outs CPURegs:$dst), (ins mem:$addr),
262 !strconcat(instr_asm, "\t$dst, $addr"),
263 [(set CPURegs:$dst, (OpNode addr:$addr))], IILoad>;
265 class StoreM<bits<6> op, string instr_asm, PatFrag OpNode>:
266 FI<op, (outs), (ins CPURegs:$dst, mem:$addr),
267 !strconcat(instr_asm, "\t$dst, $addr"),
268 [(OpNode CPURegs:$dst, addr:$addr)], IIStore>;
270 // Conditional Branch
271 let isBranch = 1, isTerminator=1, hasDelaySlot = 1 in {
272 class CBranch<bits<6> op, string instr_asm, PatFrag cond_op>:
273 FI<op, (outs), (ins CPURegs:$a, CPURegs:$b, brtarget:$offset),
274 !strconcat(instr_asm, "\t$a, $b, $offset"),
275 [(brcond (cond_op CPURegs:$a, CPURegs:$b), bb:$offset)],
278 class CBranchZero<bits<6> op, string instr_asm, PatFrag cond_op>:
279 FI<op, (outs), (ins CPURegs:$src, brtarget:$offset),
280 !strconcat(instr_asm, "\t$src, $offset"),
281 [(brcond (cond_op CPURegs:$src, 0), bb:$offset)],
286 class SetCC_R<bits<6> op, bits<6> func, string instr_asm,
288 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
289 !strconcat(instr_asm, "\t$dst, $b, $c"),
290 [(set CPURegs:$dst, (cond_op CPURegs:$b, CPURegs:$c))],
293 class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op,
294 Operand Od, PatLeaf imm_type>:
295 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
296 !strconcat(instr_asm, "\t$dst, $b, $c"),
297 [(set CPURegs:$dst, (cond_op CPURegs:$b, imm_type:$c))],
300 // Unconditional branch
301 let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
302 class JumpFJ<bits<6> op, string instr_asm>:
303 FJ<op, (outs), (ins brtarget:$target),
304 !strconcat(instr_asm, "\t$target"), [(br bb:$target)], IIBranch>;
306 let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in
307 class JumpFR<bits<6> op, bits<6> func, string instr_asm>:
308 FR<op, func, (outs), (ins CPURegs:$target),
309 !strconcat(instr_asm, "\t$target"), [(brind CPURegs:$target)], IIBranch>;
311 // Jump and Link (Call)
312 let isCall=1, hasDelaySlot=1,
313 // All calls clobber the non-callee saved registers...
314 Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9,
315 K0, K1, D0, D1, D2, D3, D4, D5, D6, D7, D8, D9], Uses = [GP] in {
316 class JumpLink<bits<6> op, string instr_asm>:
317 FJ<op, (outs), (ins calltarget:$target, variable_ops),
318 !strconcat(instr_asm, "\t$target"), [(MipsJmpLink imm:$target)],
322 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
323 FR<op, func, (outs), (ins CPURegs:$rs, variable_ops),
324 !strconcat(instr_asm, "\t$rs"), [(MipsJmpLink CPURegs:$rs)], IIBranch>;
326 class BranchLink<string instr_asm>:
327 FI<0x1, (outs), (ins CPURegs:$rs, brtarget:$target, variable_ops),
328 !strconcat(instr_asm, "\t$rs, $target"), [], IIBranch>;
332 let Defs = [HI, LO] in {
333 let isCommutable = 1 in
334 class Mul<bits<6> func, string instr_asm, InstrItinClass itin>:
335 FR<0x00, func, (outs), (ins CPURegs:$a, CPURegs:$b),
336 !strconcat(instr_asm, "\t$a, $b"), [], itin>;
338 class Div<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin>:
339 FR<0x00, func, (outs), (ins CPURegs:$a, CPURegs:$b),
340 !strconcat(instr_asm, "\t$$zero, $a, $b"),
341 [(op CPURegs:$a, CPURegs:$b)], itin>;
345 class MoveFromLOHI<bits<6> func, string instr_asm>:
346 FR<0x00, func, (outs CPURegs:$dst), (ins),
347 !strconcat(instr_asm, "\t$dst"), [], IIHiLo>;
349 class MoveToLOHI<bits<6> func, string instr_asm>:
350 FR<0x00, func, (outs), (ins CPURegs:$src),
351 !strconcat(instr_asm, "\t$src"), [], IIHiLo>;
353 class EffectiveAddress<string instr_asm> :
354 FI<0x09, (outs CPURegs:$dst), (ins mem:$addr),
355 instr_asm, [(set CPURegs:$dst, addr:$addr)], IIAlu>;
357 // Count Leading Ones/Zeros in Word
358 class CountLeading<bits<6> func, string instr_asm, list<dag> pattern>:
359 FR<0x1c, func, (outs CPURegs:$dst), (ins CPURegs:$src),
360 !strconcat(instr_asm, "\t$dst, $src"), pattern, IIAlu>,
361 Requires<[HasBitCount]> {
366 // Sign Extend in Register.
367 class SignExtInReg<bits<6> func, string instr_asm, ValueType vt>:
368 FR<0x3f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
369 !strconcat(instr_asm, "\t$dst, $src"),
370 [(set CPURegs:$dst, (sext_inreg CPURegs:$src, vt))], NoItinerary>;
373 class ByteSwap<bits<6> func, string instr_asm>:
374 FR<0x1f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
375 !strconcat(instr_asm, "\t$dst, $src"),
376 [(set CPURegs:$dst, (bswap CPURegs:$src))], NoItinerary>;
379 class CondMov<bits<6> func, string instr_asm, PatLeaf MovCode>:
380 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$F, CPURegs:$T,
381 CPURegs:$cond), !strconcat(instr_asm, "\t$dst, $T, $cond"),
385 class ReadHardware: FR<0x1f, 0x3b, (outs CPURegs:$dst), (ins HWRegs:$src),
386 "rdhwr\t$dst, $src", [], IIAlu> {
391 //===----------------------------------------------------------------------===//
392 // Pseudo instructions
393 //===----------------------------------------------------------------------===//
395 // As stack alignment is always done with addiu, we need a 16-bit immediate
396 let Defs = [SP], Uses = [SP] in {
397 def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
398 "!ADJCALLSTACKDOWN $amt",
399 [(callseq_start timm:$amt)]>;
400 def ADJCALLSTACKUP : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
401 "!ADJCALLSTACKUP $amt1",
402 [(callseq_end timm:$amt1, timm:$amt2)]>;
405 // Some assembly macros need to avoid pseudoinstructions and assembler
406 // automatic reodering, we should reorder ourselves.
407 def MACRO : MipsPseudo<(outs), (ins), ".set\tmacro", []>;
408 def REORDER : MipsPseudo<(outs), (ins), ".set\treorder", []>;
409 def NOMACRO : MipsPseudo<(outs), (ins), ".set\tnomacro", []>;
410 def NOREORDER : MipsPseudo<(outs), (ins), ".set\tnoreorder", []>;
412 // These macros are inserted to prevent GAS from complaining
413 // when using the AT register.
414 def NOAT : MipsPseudo<(outs), (ins), ".set\tnoat", []>;
415 def ATMACRO : MipsPseudo<(outs), (ins), ".set\tat", []>;
417 // When handling PIC code the assembler needs .cpload and .cprestore
418 // directives. If the real instructions corresponding these directives
419 // are used, we have the same behavior, but get also a bunch of warnings
420 // from the assembler.
421 def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$picreg), ".cpload\t$picreg", []>;
422 def CPRESTORE : MipsPseudo<(outs), (ins i32imm:$loc), ".cprestore\t$loc\n", []>;
424 let usesCustomInserter = 1 in {
425 def ATOMIC_LOAD_ADD_I8 : MipsPseudo<
426 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
427 "atomic_load_add_8\t$dst, $ptr, $incr",
428 [(set CPURegs:$dst, (atomic_load_add_8 CPURegs:$ptr, CPURegs:$incr))]>;
429 def ATOMIC_LOAD_ADD_I16 : MipsPseudo<
430 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
431 "atomic_load_add_16\t$dst, $ptr, $incr",
432 [(set CPURegs:$dst, (atomic_load_add_16 CPURegs:$ptr, CPURegs:$incr))]>;
433 def ATOMIC_LOAD_ADD_I32 : MipsPseudo<
434 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
435 "atomic_load_add_32\t$dst, $ptr, $incr",
436 [(set CPURegs:$dst, (atomic_load_add_32 CPURegs:$ptr, CPURegs:$incr))]>;
438 def ATOMIC_LOAD_SUB_I8 : MipsPseudo<
439 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
440 "atomic_load_sub_8\t$dst, $ptr, $incr",
441 [(set CPURegs:$dst, (atomic_load_sub_8 CPURegs:$ptr, CPURegs:$incr))]>;
442 def ATOMIC_LOAD_SUB_I16 : MipsPseudo<
443 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
444 "atomic_load_sub_16\t$dst, $ptr, $incr",
445 [(set CPURegs:$dst, (atomic_load_sub_16 CPURegs:$ptr, CPURegs:$incr))]>;
446 def ATOMIC_LOAD_SUB_I32 : MipsPseudo<
447 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
448 "atomic_load_sub_32\t$dst, $ptr, $incr",
449 [(set CPURegs:$dst, (atomic_load_sub_32 CPURegs:$ptr, CPURegs:$incr))]>;
451 def ATOMIC_LOAD_AND_I8 : MipsPseudo<
452 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
453 "atomic_load_and_8\t$dst, $ptr, $incr",
454 [(set CPURegs:$dst, (atomic_load_and_8 CPURegs:$ptr, CPURegs:$incr))]>;
455 def ATOMIC_LOAD_AND_I16 : MipsPseudo<
456 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
457 "atomic_load_and_16\t$dst, $ptr, $incr",
458 [(set CPURegs:$dst, (atomic_load_and_16 CPURegs:$ptr, CPURegs:$incr))]>;
459 def ATOMIC_LOAD_AND_I32 : MipsPseudo<
460 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
461 "atomic_load_and_32\t$dst, $ptr, $incr",
462 [(set CPURegs:$dst, (atomic_load_and_32 CPURegs:$ptr, CPURegs:$incr))]>;
464 def ATOMIC_LOAD_OR_I8 : MipsPseudo<
465 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
466 "atomic_load_or_8\t$dst, $ptr, $incr",
467 [(set CPURegs:$dst, (atomic_load_or_8 CPURegs:$ptr, CPURegs:$incr))]>;
468 def ATOMIC_LOAD_OR_I16 : MipsPseudo<
469 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
470 "atomic_load_or_16\t$dst, $ptr, $incr",
471 [(set CPURegs:$dst, (atomic_load_or_16 CPURegs:$ptr, CPURegs:$incr))]>;
472 def ATOMIC_LOAD_OR_I32 : MipsPseudo<
473 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
474 "atomic_load_or_32\t$dst, $ptr, $incr",
475 [(set CPURegs:$dst, (atomic_load_or_32 CPURegs:$ptr, CPURegs:$incr))]>;
477 def ATOMIC_LOAD_XOR_I8 : MipsPseudo<
478 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
479 "atomic_load_xor_8\t$dst, $ptr, $incr",
480 [(set CPURegs:$dst, (atomic_load_xor_8 CPURegs:$ptr, CPURegs:$incr))]>;
481 def ATOMIC_LOAD_XOR_I16 : MipsPseudo<
482 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
483 "atomic_load_xor_16\t$dst, $ptr, $incr",
484 [(set CPURegs:$dst, (atomic_load_xor_16 CPURegs:$ptr, CPURegs:$incr))]>;
485 def ATOMIC_LOAD_XOR_I32 : MipsPseudo<
486 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
487 "atomic_load_xor_32\t$dst, $ptr, $incr",
488 [(set CPURegs:$dst, (atomic_load_xor_32 CPURegs:$ptr, CPURegs:$incr))]>;
490 def ATOMIC_LOAD_NAND_I8 : MipsPseudo<
491 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
492 "atomic_load_nand_8\t$dst, $ptr, $incr",
493 [(set CPURegs:$dst, (atomic_load_nand_8 CPURegs:$ptr, CPURegs:$incr))]>;
494 def ATOMIC_LOAD_NAND_I16 : MipsPseudo<
495 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
496 "atomic_load_nand_16\t$dst, $ptr, $incr",
497 [(set CPURegs:$dst, (atomic_load_nand_16 CPURegs:$ptr, CPURegs:$incr))]>;
498 def ATOMIC_LOAD_NAND_I32 : MipsPseudo<
499 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
500 "atomic_load_nand_32\t$dst, $ptr, $incr",
501 [(set CPURegs:$dst, (atomic_load_nand_32 CPURegs:$ptr, CPURegs:$incr))]>;
503 def ATOMIC_SWAP_I8 : MipsPseudo<
504 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$val),
505 "atomic_swap_8\t$dst, $ptr, $val",
506 [(set CPURegs:$dst, (atomic_swap_8 CPURegs:$ptr, CPURegs:$val))]>;
507 def ATOMIC_SWAP_I16 : MipsPseudo<
508 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$val),
509 "atomic_swap_16\t$dst, $ptr, $val",
510 [(set CPURegs:$dst, (atomic_swap_16 CPURegs:$ptr, CPURegs:$val))]>;
511 def ATOMIC_SWAP_I32 : MipsPseudo<
512 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$val),
513 "atomic_swap_32\t$dst, $ptr, $val",
514 [(set CPURegs:$dst, (atomic_swap_32 CPURegs:$ptr, CPURegs:$val))]>;
516 def ATOMIC_CMP_SWAP_I8 : MipsPseudo<
517 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval),
518 "atomic_cmp_swap_8\t$dst, $ptr, $oldval, $newval",
520 (atomic_cmp_swap_8 CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval))]>;
521 def ATOMIC_CMP_SWAP_I16 : MipsPseudo<
522 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval),
523 "atomic_cmp_swap_16\t$dst, $ptr, $oldval, $newval",
525 (atomic_cmp_swap_16 CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval))]>;
526 def ATOMIC_CMP_SWAP_I32 : MipsPseudo<
527 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval),
528 "atomic_cmp_swap_32\t$dst, $ptr, $oldval, $newval",
530 (atomic_cmp_swap_32 CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval))]>;
533 //===----------------------------------------------------------------------===//
534 // Instruction definition
535 //===----------------------------------------------------------------------===//
537 //===----------------------------------------------------------------------===//
538 // MipsI Instructions
539 //===----------------------------------------------------------------------===//
541 /// Arithmetic Instructions (ALU Immediate)
542 def ADDiu : ArithI<0x09, "addiu", add, simm16, immSExt16>;
543 def ADDi : ArithOverflowI<0x08, "addi", add, simm16, immSExt16>;
544 def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16>;
545 def SLTiu : SetCC_I<0x0b, "sltiu", setult, simm16, immSExt16>;
546 def ANDi : LogicI<0x0c, "andi", and>;
547 def ORi : LogicI<0x0d, "ori", or>;
548 def XORi : LogicI<0x0e, "xori", xor>;
549 def LUi : LoadUpper<0x0f, "lui">;
551 /// Arithmetic Instructions (3-Operand, R-Type)
552 def ADDu : ArithR<0x00, 0x21, "addu", add, IIAlu, 1>;
553 def SUBu : ArithR<0x00, 0x23, "subu", sub, IIAlu>;
554 def ADD : ArithOverflowR<0x00, 0x20, "add", 1>;
555 def SUB : ArithOverflowR<0x00, 0x22, "sub">;
556 def SLT : SetCC_R<0x00, 0x2a, "slt", setlt>;
557 def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult>;
558 def AND : LogicR<0x24, "and", and>;
559 def OR : LogicR<0x25, "or", or>;
560 def XOR : LogicR<0x26, "xor", xor>;
561 def NOR : LogicNOR<0x00, 0x27, "nor">;
563 /// Shift Instructions
564 def SLL : LogicR_shift_rotate_imm<0x00, 0x00, "sll", shl>;
565 def SRL : LogicR_shift_rotate_imm<0x02, 0x00, "srl", srl>;
566 def SRA : LogicR_shift_rotate_imm<0x03, 0x00, "sra", sra>;
567 def SLLV : LogicR_shift_rotate_reg<0x04, 0x00, "sllv", shl>;
568 def SRLV : LogicR_shift_rotate_reg<0x06, 0x00, "srlv", srl>;
569 def SRAV : LogicR_shift_rotate_reg<0x07, 0x00, "srav", sra>;
571 // Rotate Instructions
572 let Predicates = [IsMips32r2] in {
573 def ROTR : LogicR_shift_rotate_imm<0x02, 0x01, "rotr", rotr>;
574 def ROTRV : LogicR_shift_rotate_reg<0x06, 0x01, "rotrv", rotr>;
577 /// Load and Store Instructions
578 def LB : LoadM<0x20, "lb", sextloadi8>;
579 def LBu : LoadM<0x24, "lbu", zextloadi8>;
580 def LH : LoadM<0x21, "lh", sextloadi16>;
581 def LHu : LoadM<0x25, "lhu", zextloadi16>;
582 def LW : LoadM<0x23, "lw", load>;
583 def SB : StoreM<0x28, "sb", truncstorei8>;
584 def SH : StoreM<0x29, "sh", truncstorei16>;
585 def SW : StoreM<0x2b, "sw", store>;
587 /// Load-linked, Store-conditional
588 let hasDelaySlot = 1 in
589 def LL : FI<0x30, (outs CPURegs:$dst), (ins mem:$addr),
590 "ll\t$dst, $addr", [], IILoad>;
591 let Constraints = "$src = $dst" in
592 def SC : FI<0x38, (outs CPURegs:$dst), (ins CPURegs:$src, mem:$addr),
593 "sc\t$src, $addr", [], IIStore>;
595 /// Jump and Branch Instructions
596 def J : JumpFJ<0x02, "j">;
597 def JR : JumpFR<0x00, 0x08, "jr">;
598 def JAL : JumpLink<0x03, "jal">;
599 def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
600 def BEQ : CBranch<0x04, "beq", seteq>;
601 def BNE : CBranch<0x05, "bne", setne>;
604 def BGEZ : CBranchZero<0x01, "bgez", setge>;
607 def BGTZ : CBranchZero<0x07, "bgtz", setgt>;
608 def BLEZ : CBranchZero<0x07, "blez", setle>;
609 def BLTZ : CBranchZero<0x01, "bltz", setlt>;
612 def BGEZAL : BranchLink<"bgezal">;
613 def BLTZAL : BranchLink<"bltzal">;
615 let isReturn=1, isTerminator=1, hasDelaySlot=1,
616 isBarrier=1, hasCtrlDep=1, rs=0, rt=0, shamt=0 in
617 def RET : FR <0x00, 0x02, (outs), (ins CPURegs:$target),
618 "jr\t$target", [(MipsRet CPURegs:$target)], IIBranch>;
620 /// Multiply and Divide Instructions.
621 def MULT : Mul<0x18, "mult", IIImul>;
622 def MULTu : Mul<0x19, "multu", IIImul>;
623 def SDIV : Div<MipsDivRem, 0x1a, "div", IIIdiv>;
624 def UDIV : Div<MipsDivRemU, 0x1b, "divu", IIIdiv>;
627 def MTHI : MoveToLOHI<0x11, "mthi">;
629 def MTLO : MoveToLOHI<0x13, "mtlo">;
632 def MFHI : MoveFromLOHI<0x10, "mfhi">;
634 def MFLO : MoveFromLOHI<0x12, "mflo">;
636 /// Sign Ext In Register Instructions.
637 let Predicates = [HasSEInReg] in {
638 let shamt = 0x10, rs = 0 in
639 def SEB : SignExtInReg<0x21, "seb", i8>;
641 let shamt = 0x18, rs = 0 in
642 def SEH : SignExtInReg<0x20, "seh", i16>;
646 def CLZ : CountLeading<0b100000, "clz",
647 [(set CPURegs:$dst, (ctlz CPURegs:$src))]>;
648 def CLO : CountLeading<0b100001, "clo",
649 [(set CPURegs:$dst, (ctlz (not CPURegs:$src)))]>;
652 let Predicates = [HasSwap] in {
653 let shamt = 0x3, rs = 0 in
654 def WSBW : ByteSwap<0x20, "wsbw">;
658 def MIPS_CMOV_ZERO : PatLeaf<(i32 0)>;
659 def MIPS_CMOV_NZERO : PatLeaf<(i32 1)>;
661 // Conditional moves:
662 // These instructions are expanded in
663 // MipsISelLowering::EmitInstrWithCustomInserter if target does not have
664 // conditional move instructions.
665 // flag:int, data:int
666 let usesCustomInserter = 1, shamt = 0, Constraints = "$F = $dst" in
667 class CondMovIntInt<bits<6> funct, string instr_asm> :
668 FR<0, funct, (outs CPURegs:$dst),
669 (ins CPURegs:$T, CPURegs:$cond, CPURegs:$F),
670 !strconcat(instr_asm, "\t$dst, $T, $cond"), [], NoItinerary>;
672 def MOVZ_I : CondMovIntInt<0x0a, "movz">;
673 def MOVN_I : CondMovIntInt<0x0b, "movn">;
677 def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
679 // FrameIndexes are legalized when they are operands from load/store
680 // instructions. The same not happens for stack address copies, so an
681 // add op with mem ComplexPattern is used and the stack address copy
682 // can be matched. It's similar to Sparc LEA_ADDRi
683 def LEA_ADDiu : EffectiveAddress<"addiu\t$dst, ${addr:stackloc}">;
685 // DynAlloc node points to dynamically allocated stack space.
686 // $sp is added to the list of implicitly used registers to prevent dead code
687 // elimination from removing instructions that modify $sp.
689 def DynAlloc : EffectiveAddress<"addiu\t$dst, ${addr:stackloc}">;
692 def MADD : MArithR<0, "madd", MipsMAdd, 1>;
693 def MADDU : MArithR<1, "maddu", MipsMAddu, 1>;
694 def MSUB : MArithR<4, "msub", MipsMSub>;
695 def MSUBU : MArithR<5, "msubu", MipsMSubu>;
697 // MUL is a assembly macro in the current used ISAs. In recent ISA's
698 // it is a real instruction.
699 def MUL : ArithR<0x1c, 0x02, "mul", mul, IIImul, 1>, Requires<[IsMips32]>;
701 def RDHWR : ReadHardware;
703 //===----------------------------------------------------------------------===//
704 // Arbitrary patterns that map to one or more instructions
705 //===----------------------------------------------------------------------===//
708 def : Pat<(i32 immSExt16:$in),
709 (ADDiu ZERO, imm:$in)>;
710 def : Pat<(i32 immZExt16:$in),
711 (ORi ZERO, imm:$in)>;
713 // Arbitrary immediates
714 def : Pat<(i32 imm:$imm),
715 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
718 def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
719 (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
720 def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
721 (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
722 def : Pat<(addc CPURegs:$src, immSExt16:$imm),
723 (ADDiu CPURegs:$src, imm:$imm)>;
726 def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
727 (JAL tglobaladdr:$dst)>;
728 def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
729 (JAL texternalsym:$dst)>;
730 //def : Pat<(MipsJmpLink CPURegs:$dst),
731 // (JALR CPURegs:$dst)>;
734 def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
735 def : Pat<(MipsHi tblockaddress:$in), (LUi tblockaddress:$in)>;
736 def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
737 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
738 def : Pat<(add CPURegs:$hi, (MipsLo tblockaddress:$lo)),
739 (ADDiu CPURegs:$hi, tblockaddress:$lo)>;
741 def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
742 def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
743 (ADDiu CPURegs:$hi, tjumptable:$lo)>;
745 def : Pat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
746 def : Pat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)),
747 (ADDiu CPURegs:$hi, tconstpool:$lo)>;
750 def : Pat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)),
751 (ADDiu CPURegs:$gp, tglobaladdr:$in)>;
752 def : Pat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)),
753 (ADDiu CPURegs:$gp, tconstpool:$in)>;
756 def : Pat<(add CPURegs:$gp, (MipsTlsGd tglobaltlsaddr:$in)),
757 (ADDiu CPURegs:$gp, tglobaltlsaddr:$in)>;
760 def : Pat<(MipsTprelHi tglobaltlsaddr:$in), (LUi tglobaltlsaddr:$in)>;
761 def : Pat<(add CPURegs:$hi, (MipsTprelLo tglobaltlsaddr:$lo)),
762 (ADDiu CPURegs:$hi, tglobaltlsaddr:$lo)>;
765 class WrapperPICPat<SDNode node>:
766 Pat<(MipsWrapperPIC node:$in),
767 (ADDiu GP, node:$in)>;
769 def : WrapperPICPat<tglobaladdr>;
770 def : WrapperPICPat<tconstpool>;
771 def : WrapperPICPat<texternalsym>;
772 def : WrapperPICPat<tblockaddress>;
773 def : WrapperPICPat<tjumptable>;
775 // Mips does not have "not", so we expand our way
776 def : Pat<(not CPURegs:$in),
777 (NOR CPURegs:$in, ZERO)>;
779 // extended load and stores
780 def : Pat<(extloadi1 addr:$src), (LBu addr:$src)>;
781 def : Pat<(extloadi8 addr:$src), (LBu addr:$src)>;
782 def : Pat<(extloadi16 addr:$src), (LHu addr:$src)>;
785 def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
788 def : Pat<(brcond (setne CPURegs:$lhs, 0), bb:$dst),
789 (BNE CPURegs:$lhs, ZERO, bb:$dst)>;
790 def : Pat<(brcond (seteq CPURegs:$lhs, 0), bb:$dst),
791 (BEQ CPURegs:$lhs, ZERO, bb:$dst)>;
793 def : Pat<(brcond (setge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
794 (BEQ (SLT CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
795 def : Pat<(brcond (setuge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
796 (BEQ (SLTu CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
797 def : Pat<(brcond (setge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
798 (BEQ (SLTi CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
799 def : Pat<(brcond (setuge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
800 (BEQ (SLTiu CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
802 def : Pat<(brcond (setle CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
803 (BEQ (SLT CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
804 def : Pat<(brcond (setule CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
805 (BEQ (SLTu CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
807 def : Pat<(brcond CPURegs:$cond, bb:$dst),
808 (BNE CPURegs:$cond, ZERO, bb:$dst)>;
811 multiclass MovzPats<RegisterClass RC, Instruction MOVZInst> {
812 def : Pat<(select (setge CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
813 (MOVZInst RC:$T, (SLT CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
814 def : Pat<(select (setuge CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
815 (MOVZInst RC:$T, (SLTu CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
816 def : Pat<(select (setge CPURegs:$lhs, immSExt16:$rhs), RC:$T, RC:$F),
817 (MOVZInst RC:$T, (SLTi CPURegs:$lhs, immSExt16:$rhs), RC:$F)>;
818 def : Pat<(select (setuge CPURegs:$lh, immSExt16:$rh), RC:$T, RC:$F),
819 (MOVZInst RC:$T, (SLTiu CPURegs:$lh, immSExt16:$rh), RC:$F)>;
820 def : Pat<(select (setle CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
821 (MOVZInst RC:$T, (SLT CPURegs:$rhs, CPURegs:$lhs), RC:$F)>;
822 def : Pat<(select (setule CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
823 (MOVZInst RC:$T, (SLTu CPURegs:$rhs, CPURegs:$lhs), RC:$F)>;
824 def : Pat<(select (seteq CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
825 (MOVZInst RC:$T, (XOR CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
826 def : Pat<(select (seteq CPURegs:$lhs, 0), RC:$T, RC:$F),
827 (MOVZInst RC:$T, CPURegs:$lhs, RC:$F)>;
830 multiclass MovnPats<RegisterClass RC, Instruction MOVNInst> {
831 def : Pat<(select (setne CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
832 (MOVNInst RC:$T, (XOR CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
833 def : Pat<(select CPURegs:$cond, RC:$T, RC:$F),
834 (MOVNInst RC:$T, CPURegs:$cond, RC:$F)>;
835 def : Pat<(select (setne CPURegs:$lhs, 0), RC:$T, RC:$F),
836 (MOVNInst RC:$T, CPURegs:$lhs, RC:$F)>;
839 defm : MovzPats<CPURegs, MOVZ_I>;
840 defm : MovnPats<CPURegs, MOVN_I>;
843 def : Pat<(seteq CPURegs:$lhs, CPURegs:$rhs),
844 (SLTu (XOR CPURegs:$lhs, CPURegs:$rhs), 1)>;
845 def : Pat<(setne CPURegs:$lhs, CPURegs:$rhs),
846 (SLTu ZERO, (XOR CPURegs:$lhs, CPURegs:$rhs))>;
848 def : Pat<(setle CPURegs:$lhs, CPURegs:$rhs),
849 (XORi (SLT CPURegs:$rhs, CPURegs:$lhs), 1)>;
850 def : Pat<(setule CPURegs:$lhs, CPURegs:$rhs),
851 (XORi (SLTu CPURegs:$rhs, CPURegs:$lhs), 1)>;
853 def : Pat<(setgt CPURegs:$lhs, CPURegs:$rhs),
854 (SLT CPURegs:$rhs, CPURegs:$lhs)>;
855 def : Pat<(setugt CPURegs:$lhs, CPURegs:$rhs),
856 (SLTu CPURegs:$rhs, CPURegs:$lhs)>;
858 def : Pat<(setge CPURegs:$lhs, CPURegs:$rhs),
859 (XORi (SLT CPURegs:$lhs, CPURegs:$rhs), 1)>;
860 def : Pat<(setuge CPURegs:$lhs, CPURegs:$rhs),
861 (XORi (SLTu CPURegs:$lhs, CPURegs:$rhs), 1)>;
863 def : Pat<(setge CPURegs:$lhs, immSExt16:$rhs),
864 (XORi (SLTi CPURegs:$lhs, immSExt16:$rhs), 1)>;
865 def : Pat<(setuge CPURegs:$lhs, immSExt16:$rhs),
866 (XORi (SLTiu CPURegs:$lhs, immSExt16:$rhs), 1)>;
868 // select MipsDynAlloc
869 def : Pat<(MipsDynAlloc addr:$f), (DynAlloc addr:$f)>;
871 //===----------------------------------------------------------------------===//
872 // Floating Point Support
873 //===----------------------------------------------------------------------===//
875 include "MipsInstrFPU.td"