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 CPURegs, simm16);
140 def mem_ea : Operand<i32> {
141 let PrintMethod = "printMemOperandEA";
142 let MIOperandInfo = (ops CPURegs, simm16);
145 // Transformation Function - get the lower 16 bits.
146 def LO16 : SDNodeXForm<imm, [{
147 return getI32Imm((unsigned)N->getZExtValue() & 0xFFFF);
150 // Transformation Function - get the higher 16 bits.
151 def HI16 : SDNodeXForm<imm, [{
152 return getI32Imm((unsigned)N->getZExtValue() >> 16);
155 // Node immediate fits as 16-bit sign extended on target immediate.
157 def immSExt16 : PatLeaf<(imm), [{ return isInt<16>(N->getSExtValue()); }]>;
159 // Node immediate fits as 16-bit zero extended on target immediate.
160 // The LO16 param means that only the lower 16 bits of the node
161 // immediate are caught.
163 def immZExt16 : PatLeaf<(imm), [{
164 if (N->getValueType(0) == MVT::i32)
165 return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
167 return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
170 // shamt field must fit in 5 bits.
171 def immZExt5 : PatLeaf<(imm), [{
172 return N->getZExtValue() == ((N->getZExtValue()) & 0x1f) ;
175 // Mips Address Mode! SDNode frameindex could possibily be a match
176 // since load and store instructions from stack used it.
177 def addr : ComplexPattern<iPTR, 2, "SelectAddr", [frameindex], []>;
179 //===----------------------------------------------------------------------===//
180 // Instructions specific format
181 //===----------------------------------------------------------------------===//
183 // Arithmetic 3 register operands
184 class ArithR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
185 InstrItinClass itin, bit isComm = 0>:
186 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
187 !strconcat(instr_asm, "\t$dst, $b, $c"),
188 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], itin> {
189 let isCommutable = isComm;
192 class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm,
194 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
195 !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu> {
196 let isCommutable = isComm;
199 // Arithmetic 2 register operands
200 class ArithI<bits<6> op, string instr_asm, SDNode OpNode,
201 Operand Od, PatLeaf imm_type> :
202 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
203 !strconcat(instr_asm, "\t$dst, $b, $c"),
204 [(set CPURegs:$dst, (OpNode CPURegs:$b, imm_type:$c))], IIAlu>;
206 class ArithOverflowI<bits<6> op, string instr_asm, SDNode OpNode,
207 Operand Od, PatLeaf imm_type> :
208 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
209 !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu>;
211 // Arithmetic Multiply ADD/SUB
212 let rd = 0, shamt = 0, Defs = [HI, LO], Uses = [HI, LO] in
213 class MArithR<bits<6> func, string instr_asm, SDNode op, bit isComm = 0> :
214 FR<0x1c, func, (outs), (ins CPURegs:$rs, CPURegs:$rt),
215 !strconcat(instr_asm, "\t$rs, $rt"),
216 [(op CPURegs:$rs, CPURegs:$rt, LO, HI)], IIImul> {
217 let isCommutable = isComm;
221 let isCommutable = 1 in
222 class LogicR<bits<6> func, string instr_asm, SDNode OpNode>:
223 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
224 !strconcat(instr_asm, "\t$dst, $b, $c"),
225 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
227 class LogicI<bits<6> op, string instr_asm, SDNode OpNode>:
228 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, uimm16:$c),
229 !strconcat(instr_asm, "\t$dst, $b, $c"),
230 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt16:$c))], IIAlu>;
232 let isCommutable = 1 in
233 class LogicNOR<bits<6> op, bits<6> func, string instr_asm>:
234 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
235 !strconcat(instr_asm, "\t$dst, $b, $c"),
236 [(set CPURegs:$dst, (not (or CPURegs:$b, CPURegs:$c)))], IIAlu>;
239 class LogicR_shift_rotate_imm<bits<6> func, bits<5> _rs, string instr_asm,
241 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, shamt:$c),
242 !strconcat(instr_asm, "\t$dst, $b, $c"),
243 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt5:$c))], IIAlu> {
247 class LogicR_shift_rotate_reg<bits<6> func, bits<5> _shamt, string instr_asm,
249 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$c, CPURegs:$b),
250 !strconcat(instr_asm, "\t$dst, $b, $c"),
251 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu> {
255 // Load Upper Imediate
256 class LoadUpper<bits<6> op, string instr_asm>:
260 !strconcat(instr_asm, "\t$dst, $imm"),
264 let canFoldAsLoad = 1, hasDelaySlot = 1 in
265 class LoadM<bits<6> op, string instr_asm, PatFrag OpNode>:
266 FI<op, (outs CPURegs:$dst), (ins mem:$addr),
267 !strconcat(instr_asm, "\t$dst, $addr"),
268 [(set CPURegs:$dst, (OpNode addr:$addr))], IILoad>;
270 class StoreM<bits<6> op, string instr_asm, PatFrag OpNode>:
271 FI<op, (outs), (ins CPURegs:$dst, mem:$addr),
272 !strconcat(instr_asm, "\t$dst, $addr"),
273 [(OpNode CPURegs:$dst, addr:$addr)], IIStore>;
275 // Conditional Branch
276 let isBranch = 1, isTerminator=1, hasDelaySlot = 1 in {
277 class CBranch<bits<6> op, string instr_asm, PatFrag cond_op>:
278 FI<op, (outs), (ins CPURegs:$a, CPURegs:$b, brtarget:$offset),
279 !strconcat(instr_asm, "\t$a, $b, $offset"),
280 [(brcond (cond_op CPURegs:$a, CPURegs:$b), bb:$offset)],
283 class CBranchZero<bits<6> op, string instr_asm, PatFrag cond_op>:
284 FI<op, (outs), (ins CPURegs:$src, brtarget:$offset),
285 !strconcat(instr_asm, "\t$src, $offset"),
286 [(brcond (cond_op CPURegs:$src, 0), bb:$offset)],
291 class SetCC_R<bits<6> op, bits<6> func, string instr_asm,
293 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
294 !strconcat(instr_asm, "\t$dst, $b, $c"),
295 [(set CPURegs:$dst, (cond_op CPURegs:$b, CPURegs:$c))],
298 class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op,
299 Operand Od, PatLeaf imm_type>:
300 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
301 !strconcat(instr_asm, "\t$dst, $b, $c"),
302 [(set CPURegs:$dst, (cond_op CPURegs:$b, imm_type:$c))],
305 // Unconditional branch
306 let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
307 class JumpFJ<bits<6> op, string instr_asm>:
308 FJ<op, (outs), (ins brtarget:$target),
309 !strconcat(instr_asm, "\t$target"), [(br bb:$target)], IIBranch>;
311 let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in
312 class JumpFR<bits<6> op, bits<6> func, string instr_asm>:
313 FR<op, func, (outs), (ins CPURegs:$target),
314 !strconcat(instr_asm, "\t$target"), [(brind CPURegs:$target)], IIBranch>;
316 // Jump and Link (Call)
317 let isCall=1, hasDelaySlot=1,
318 // All calls clobber the non-callee saved registers...
319 Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9,
320 K0, K1, D0, D1, D2, D3, D4, D5, D6, D7, D8, D9], Uses = [GP] in {
321 class JumpLink<bits<6> op, string instr_asm>:
322 FJ<op, (outs), (ins calltarget:$target, variable_ops),
323 !strconcat(instr_asm, "\t$target"), [(MipsJmpLink imm:$target)],
327 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
328 FR<op, func, (outs), (ins CPURegs:$rs, variable_ops),
329 !strconcat(instr_asm, "\t$rs"), [(MipsJmpLink CPURegs:$rs)], IIBranch>;
331 class BranchLink<string instr_asm>:
332 FI<0x1, (outs), (ins CPURegs:$rs, brtarget:$target, variable_ops),
333 !strconcat(instr_asm, "\t$rs, $target"), [], IIBranch>;
337 let Defs = [HI, LO] in {
338 let isCommutable = 1 in
339 class Mul<bits<6> func, string instr_asm, InstrItinClass itin>:
340 FR<0x00, func, (outs), (ins CPURegs:$a, CPURegs:$b),
341 !strconcat(instr_asm, "\t$a, $b"), [], itin>;
343 class Div<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin>:
344 FR<0x00, func, (outs), (ins CPURegs:$a, CPURegs:$b),
345 !strconcat(instr_asm, "\t$$zero, $a, $b"),
346 [(op CPURegs:$a, CPURegs:$b)], itin>;
350 class MoveFromLOHI<bits<6> func, string instr_asm>:
351 FR<0x00, func, (outs CPURegs:$dst), (ins),
352 !strconcat(instr_asm, "\t$dst"), [], IIHiLo>;
354 class MoveToLOHI<bits<6> func, string instr_asm>:
355 FR<0x00, func, (outs), (ins CPURegs:$src),
356 !strconcat(instr_asm, "\t$src"), [], IIHiLo>;
358 class EffectiveAddress<string instr_asm> :
359 FI<0x09, (outs CPURegs:$dst), (ins mem_ea:$addr),
360 instr_asm, [(set CPURegs:$dst, addr:$addr)], IIAlu>;
362 // Count Leading Ones/Zeros in Word
363 class CountLeading<bits<6> func, string instr_asm, list<dag> pattern>:
364 FR<0x1c, func, (outs CPURegs:$dst), (ins CPURegs:$src),
365 !strconcat(instr_asm, "\t$dst, $src"), pattern, IIAlu>,
366 Requires<[HasBitCount]> {
371 // Sign Extend in Register.
372 class SignExtInReg<bits<6> func, string instr_asm, ValueType vt>:
373 FR<0x3f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
374 !strconcat(instr_asm, "\t$dst, $src"),
375 [(set CPURegs:$dst, (sext_inreg CPURegs:$src, vt))], NoItinerary>;
378 class ByteSwap<bits<6> func, string instr_asm>:
379 FR<0x1f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
380 !strconcat(instr_asm, "\t$dst, $src"),
381 [(set CPURegs:$dst, (bswap CPURegs:$src))], NoItinerary>;
384 class CondMov<bits<6> func, string instr_asm, PatLeaf MovCode>:
385 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$F, CPURegs:$T,
386 CPURegs:$cond), !strconcat(instr_asm, "\t$dst, $T, $cond"),
390 class ReadHardware: FR<0x1f, 0x3b, (outs CPURegs:$dst), (ins HWRegs:$src),
391 "rdhwr\t$dst, $src", [], IIAlu> {
396 //===----------------------------------------------------------------------===//
397 // Pseudo instructions
398 //===----------------------------------------------------------------------===//
400 // As stack alignment is always done with addiu, we need a 16-bit immediate
401 let Defs = [SP], Uses = [SP] in {
402 def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
403 "!ADJCALLSTACKDOWN $amt",
404 [(callseq_start timm:$amt)]>;
405 def ADJCALLSTACKUP : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
406 "!ADJCALLSTACKUP $amt1",
407 [(callseq_end timm:$amt1, timm:$amt2)]>;
410 // Some assembly macros need to avoid pseudoinstructions and assembler
411 // automatic reodering, we should reorder ourselves.
412 def MACRO : MipsPseudo<(outs), (ins), ".set\tmacro", []>;
413 def REORDER : MipsPseudo<(outs), (ins), ".set\treorder", []>;
414 def NOMACRO : MipsPseudo<(outs), (ins), ".set\tnomacro", []>;
415 def NOREORDER : MipsPseudo<(outs), (ins), ".set\tnoreorder", []>;
417 // These macros are inserted to prevent GAS from complaining
418 // when using the AT register.
419 def NOAT : MipsPseudo<(outs), (ins), ".set\tnoat", []>;
420 def ATMACRO : MipsPseudo<(outs), (ins), ".set\tat", []>;
422 // When handling PIC code the assembler needs .cpload and .cprestore
423 // directives. If the real instructions corresponding these directives
424 // are used, we have the same behavior, but get also a bunch of warnings
425 // from the assembler.
426 def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$picreg), ".cpload\t$picreg", []>;
427 def CPRESTORE : MipsPseudo<(outs), (ins i32imm:$loc), ".cprestore\t$loc", []>;
429 let usesCustomInserter = 1 in {
430 def ATOMIC_LOAD_ADD_I8 : MipsPseudo<
431 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
432 "atomic_load_add_8\t$dst, $ptr, $incr",
433 [(set CPURegs:$dst, (atomic_load_add_8 CPURegs:$ptr, CPURegs:$incr))]>;
434 def ATOMIC_LOAD_ADD_I16 : MipsPseudo<
435 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
436 "atomic_load_add_16\t$dst, $ptr, $incr",
437 [(set CPURegs:$dst, (atomic_load_add_16 CPURegs:$ptr, CPURegs:$incr))]>;
438 def ATOMIC_LOAD_ADD_I32 : MipsPseudo<
439 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
440 "atomic_load_add_32\t$dst, $ptr, $incr",
441 [(set CPURegs:$dst, (atomic_load_add_32 CPURegs:$ptr, CPURegs:$incr))]>;
443 def ATOMIC_LOAD_SUB_I8 : MipsPseudo<
444 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
445 "atomic_load_sub_8\t$dst, $ptr, $incr",
446 [(set CPURegs:$dst, (atomic_load_sub_8 CPURegs:$ptr, CPURegs:$incr))]>;
447 def ATOMIC_LOAD_SUB_I16 : MipsPseudo<
448 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
449 "atomic_load_sub_16\t$dst, $ptr, $incr",
450 [(set CPURegs:$dst, (atomic_load_sub_16 CPURegs:$ptr, CPURegs:$incr))]>;
451 def ATOMIC_LOAD_SUB_I32 : MipsPseudo<
452 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
453 "atomic_load_sub_32\t$dst, $ptr, $incr",
454 [(set CPURegs:$dst, (atomic_load_sub_32 CPURegs:$ptr, CPURegs:$incr))]>;
456 def ATOMIC_LOAD_AND_I8 : MipsPseudo<
457 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
458 "atomic_load_and_8\t$dst, $ptr, $incr",
459 [(set CPURegs:$dst, (atomic_load_and_8 CPURegs:$ptr, CPURegs:$incr))]>;
460 def ATOMIC_LOAD_AND_I16 : MipsPseudo<
461 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
462 "atomic_load_and_16\t$dst, $ptr, $incr",
463 [(set CPURegs:$dst, (atomic_load_and_16 CPURegs:$ptr, CPURegs:$incr))]>;
464 def ATOMIC_LOAD_AND_I32 : MipsPseudo<
465 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
466 "atomic_load_and_32\t$dst, $ptr, $incr",
467 [(set CPURegs:$dst, (atomic_load_and_32 CPURegs:$ptr, CPURegs:$incr))]>;
469 def ATOMIC_LOAD_OR_I8 : MipsPseudo<
470 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
471 "atomic_load_or_8\t$dst, $ptr, $incr",
472 [(set CPURegs:$dst, (atomic_load_or_8 CPURegs:$ptr, CPURegs:$incr))]>;
473 def ATOMIC_LOAD_OR_I16 : MipsPseudo<
474 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
475 "atomic_load_or_16\t$dst, $ptr, $incr",
476 [(set CPURegs:$dst, (atomic_load_or_16 CPURegs:$ptr, CPURegs:$incr))]>;
477 def ATOMIC_LOAD_OR_I32 : MipsPseudo<
478 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
479 "atomic_load_or_32\t$dst, $ptr, $incr",
480 [(set CPURegs:$dst, (atomic_load_or_32 CPURegs:$ptr, CPURegs:$incr))]>;
482 def ATOMIC_LOAD_XOR_I8 : MipsPseudo<
483 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
484 "atomic_load_xor_8\t$dst, $ptr, $incr",
485 [(set CPURegs:$dst, (atomic_load_xor_8 CPURegs:$ptr, CPURegs:$incr))]>;
486 def ATOMIC_LOAD_XOR_I16 : MipsPseudo<
487 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
488 "atomic_load_xor_16\t$dst, $ptr, $incr",
489 [(set CPURegs:$dst, (atomic_load_xor_16 CPURegs:$ptr, CPURegs:$incr))]>;
490 def ATOMIC_LOAD_XOR_I32 : MipsPseudo<
491 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
492 "atomic_load_xor_32\t$dst, $ptr, $incr",
493 [(set CPURegs:$dst, (atomic_load_xor_32 CPURegs:$ptr, CPURegs:$incr))]>;
495 def ATOMIC_LOAD_NAND_I8 : MipsPseudo<
496 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
497 "atomic_load_nand_8\t$dst, $ptr, $incr",
498 [(set CPURegs:$dst, (atomic_load_nand_8 CPURegs:$ptr, CPURegs:$incr))]>;
499 def ATOMIC_LOAD_NAND_I16 : MipsPseudo<
500 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
501 "atomic_load_nand_16\t$dst, $ptr, $incr",
502 [(set CPURegs:$dst, (atomic_load_nand_16 CPURegs:$ptr, CPURegs:$incr))]>;
503 def ATOMIC_LOAD_NAND_I32 : MipsPseudo<
504 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
505 "atomic_load_nand_32\t$dst, $ptr, $incr",
506 [(set CPURegs:$dst, (atomic_load_nand_32 CPURegs:$ptr, CPURegs:$incr))]>;
508 def ATOMIC_SWAP_I8 : MipsPseudo<
509 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$val),
510 "atomic_swap_8\t$dst, $ptr, $val",
511 [(set CPURegs:$dst, (atomic_swap_8 CPURegs:$ptr, CPURegs:$val))]>;
512 def ATOMIC_SWAP_I16 : MipsPseudo<
513 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$val),
514 "atomic_swap_16\t$dst, $ptr, $val",
515 [(set CPURegs:$dst, (atomic_swap_16 CPURegs:$ptr, CPURegs:$val))]>;
516 def ATOMIC_SWAP_I32 : MipsPseudo<
517 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$val),
518 "atomic_swap_32\t$dst, $ptr, $val",
519 [(set CPURegs:$dst, (atomic_swap_32 CPURegs:$ptr, CPURegs:$val))]>;
521 def ATOMIC_CMP_SWAP_I8 : MipsPseudo<
522 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval),
523 "atomic_cmp_swap_8\t$dst, $ptr, $oldval, $newval",
525 (atomic_cmp_swap_8 CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval))]>;
526 def ATOMIC_CMP_SWAP_I16 : MipsPseudo<
527 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval),
528 "atomic_cmp_swap_16\t$dst, $ptr, $oldval, $newval",
530 (atomic_cmp_swap_16 CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval))]>;
531 def ATOMIC_CMP_SWAP_I32 : MipsPseudo<
532 (outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval),
533 "atomic_cmp_swap_32\t$dst, $ptr, $oldval, $newval",
535 (atomic_cmp_swap_32 CPURegs:$ptr, CPURegs:$oldval, CPURegs:$newval))]>;
538 //===----------------------------------------------------------------------===//
539 // Instruction definition
540 //===----------------------------------------------------------------------===//
542 //===----------------------------------------------------------------------===//
543 // MipsI Instructions
544 //===----------------------------------------------------------------------===//
546 /// Arithmetic Instructions (ALU Immediate)
547 def ADDiu : ArithI<0x09, "addiu", add, simm16, immSExt16>;
548 def ADDi : ArithOverflowI<0x08, "addi", add, simm16, immSExt16>;
549 def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16>;
550 def SLTiu : SetCC_I<0x0b, "sltiu", setult, simm16, immSExt16>;
551 def ANDi : LogicI<0x0c, "andi", and>;
552 def ORi : LogicI<0x0d, "ori", or>;
553 def XORi : LogicI<0x0e, "xori", xor>;
554 def LUi : LoadUpper<0x0f, "lui">;
556 /// Arithmetic Instructions (3-Operand, R-Type)
557 def ADDu : ArithR<0x00, 0x21, "addu", add, IIAlu, 1>;
558 def SUBu : ArithR<0x00, 0x23, "subu", sub, IIAlu>;
559 def ADD : ArithOverflowR<0x00, 0x20, "add", 1>;
560 def SUB : ArithOverflowR<0x00, 0x22, "sub">;
561 def SLT : SetCC_R<0x00, 0x2a, "slt", setlt>;
562 def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult>;
563 def AND : LogicR<0x24, "and", and>;
564 def OR : LogicR<0x25, "or", or>;
565 def XOR : LogicR<0x26, "xor", xor>;
566 def NOR : LogicNOR<0x00, 0x27, "nor">;
568 /// Shift Instructions
569 def SLL : LogicR_shift_rotate_imm<0x00, 0x00, "sll", shl>;
570 def SRL : LogicR_shift_rotate_imm<0x02, 0x00, "srl", srl>;
571 def SRA : LogicR_shift_rotate_imm<0x03, 0x00, "sra", sra>;
572 def SLLV : LogicR_shift_rotate_reg<0x04, 0x00, "sllv", shl>;
573 def SRLV : LogicR_shift_rotate_reg<0x06, 0x00, "srlv", srl>;
574 def SRAV : LogicR_shift_rotate_reg<0x07, 0x00, "srav", sra>;
576 // Rotate Instructions
577 let Predicates = [IsMips32r2] in {
578 def ROTR : LogicR_shift_rotate_imm<0x02, 0x01, "rotr", rotr>;
579 def ROTRV : LogicR_shift_rotate_reg<0x06, 0x01, "rotrv", rotr>;
582 /// Load and Store Instructions
583 def LB : LoadM<0x20, "lb", sextloadi8>;
584 def LBu : LoadM<0x24, "lbu", zextloadi8>;
585 def LH : LoadM<0x21, "lh", sextloadi16>;
586 def LHu : LoadM<0x25, "lhu", zextloadi16>;
587 def LW : LoadM<0x23, "lw", load>;
588 def SB : StoreM<0x28, "sb", truncstorei8>;
589 def SH : StoreM<0x29, "sh", truncstorei16>;
590 def SW : StoreM<0x2b, "sw", store>;
592 /// Load-linked, Store-conditional
593 let hasDelaySlot = 1 in
594 def LL : FI<0x30, (outs CPURegs:$dst), (ins mem:$addr),
595 "ll\t$dst, $addr", [], IILoad>;
596 let Constraints = "$src = $dst" in
597 def SC : FI<0x38, (outs CPURegs:$dst), (ins CPURegs:$src, mem:$addr),
598 "sc\t$src, $addr", [], IIStore>;
600 /// Jump and Branch Instructions
601 def J : JumpFJ<0x02, "j">;
602 def JR : JumpFR<0x00, 0x08, "jr">;
603 def JAL : JumpLink<0x03, "jal">;
604 def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
605 def BEQ : CBranch<0x04, "beq", seteq>;
606 def BNE : CBranch<0x05, "bne", setne>;
609 def BGEZ : CBranchZero<0x01, "bgez", setge>;
612 def BGTZ : CBranchZero<0x07, "bgtz", setgt>;
613 def BLEZ : CBranchZero<0x07, "blez", setle>;
614 def BLTZ : CBranchZero<0x01, "bltz", setlt>;
617 def BGEZAL : BranchLink<"bgezal">;
618 def BLTZAL : BranchLink<"bltzal">;
620 let isReturn=1, isTerminator=1, hasDelaySlot=1,
621 isBarrier=1, hasCtrlDep=1, rs=0, rt=0, shamt=0 in
622 def RET : FR <0x00, 0x02, (outs), (ins CPURegs:$target),
623 "jr\t$target", [(MipsRet CPURegs:$target)], IIBranch>;
625 /// Multiply and Divide Instructions.
626 def MULT : Mul<0x18, "mult", IIImul>;
627 def MULTu : Mul<0x19, "multu", IIImul>;
628 def SDIV : Div<MipsDivRem, 0x1a, "div", IIIdiv>;
629 def UDIV : Div<MipsDivRemU, 0x1b, "divu", IIIdiv>;
632 def MTHI : MoveToLOHI<0x11, "mthi">;
634 def MTLO : MoveToLOHI<0x13, "mtlo">;
637 def MFHI : MoveFromLOHI<0x10, "mfhi">;
639 def MFLO : MoveFromLOHI<0x12, "mflo">;
641 /// Sign Ext In Register Instructions.
642 let Predicates = [HasSEInReg] in {
643 let shamt = 0x10, rs = 0 in
644 def SEB : SignExtInReg<0x21, "seb", i8>;
646 let shamt = 0x18, rs = 0 in
647 def SEH : SignExtInReg<0x20, "seh", i16>;
651 def CLZ : CountLeading<0b100000, "clz",
652 [(set CPURegs:$dst, (ctlz CPURegs:$src))]>;
653 def CLO : CountLeading<0b100001, "clo",
654 [(set CPURegs:$dst, (ctlz (not CPURegs:$src)))]>;
657 let Predicates = [HasSwap] in {
658 let shamt = 0x3, rs = 0 in
659 def WSBW : ByteSwap<0x20, "wsbw">;
663 def MIPS_CMOV_ZERO : PatLeaf<(i32 0)>;
664 def MIPS_CMOV_NZERO : PatLeaf<(i32 1)>;
666 // Conditional moves:
667 // These instructions are expanded in
668 // MipsISelLowering::EmitInstrWithCustomInserter if target does not have
669 // conditional move instructions.
670 // flag:int, data:int
671 let usesCustomInserter = 1, shamt = 0, Constraints = "$F = $dst" in
672 class CondMovIntInt<bits<6> funct, string instr_asm> :
673 FR<0, funct, (outs CPURegs:$dst),
674 (ins CPURegs:$T, CPURegs:$cond, CPURegs:$F),
675 !strconcat(instr_asm, "\t$dst, $T, $cond"), [], NoItinerary>;
677 def MOVZ_I : CondMovIntInt<0x0a, "movz">;
678 def MOVN_I : CondMovIntInt<0x0b, "movn">;
682 def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
684 // FrameIndexes are legalized when they are operands from load/store
685 // instructions. The same not happens for stack address copies, so an
686 // add op with mem ComplexPattern is used and the stack address copy
687 // can be matched. It's similar to Sparc LEA_ADDRi
688 def LEA_ADDiu : EffectiveAddress<"addiu\t$dst, $addr">;
690 // DynAlloc node points to dynamically allocated stack space.
691 // $sp is added to the list of implicitly used registers to prevent dead code
692 // elimination from removing instructions that modify $sp.
694 def DynAlloc : EffectiveAddress<"addiu\t$dst, $addr">;
697 def MADD : MArithR<0, "madd", MipsMAdd, 1>;
698 def MADDU : MArithR<1, "maddu", MipsMAddu, 1>;
699 def MSUB : MArithR<4, "msub", MipsMSub>;
700 def MSUBU : MArithR<5, "msubu", MipsMSubu>;
702 // MUL is a assembly macro in the current used ISAs. In recent ISA's
703 // it is a real instruction.
704 def MUL : ArithR<0x1c, 0x02, "mul", mul, IIImul, 1>, Requires<[IsMips32]>;
706 def RDHWR : ReadHardware;
708 //===----------------------------------------------------------------------===//
709 // Arbitrary patterns that map to one or more instructions
710 //===----------------------------------------------------------------------===//
713 def : Pat<(i32 immSExt16:$in),
714 (ADDiu ZERO, imm:$in)>;
715 def : Pat<(i32 immZExt16:$in),
716 (ORi ZERO, imm:$in)>;
718 // Arbitrary immediates
719 def : Pat<(i32 imm:$imm),
720 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
723 def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
724 (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
725 def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
726 (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
727 def : Pat<(addc CPURegs:$src, immSExt16:$imm),
728 (ADDiu CPURegs:$src, imm:$imm)>;
731 def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
732 (JAL tglobaladdr:$dst)>;
733 def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
734 (JAL texternalsym:$dst)>;
735 //def : Pat<(MipsJmpLink CPURegs:$dst),
736 // (JALR CPURegs:$dst)>;
739 def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
740 def : Pat<(MipsHi tblockaddress:$in), (LUi tblockaddress:$in)>;
741 def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
742 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
743 def : Pat<(add CPURegs:$hi, (MipsLo tblockaddress:$lo)),
744 (ADDiu CPURegs:$hi, tblockaddress:$lo)>;
746 def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
747 def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
748 (ADDiu CPURegs:$hi, tjumptable:$lo)>;
750 def : Pat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
751 def : Pat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)),
752 (ADDiu CPURegs:$hi, tconstpool:$lo)>;
755 def : Pat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)),
756 (ADDiu CPURegs:$gp, tglobaladdr:$in)>;
757 def : Pat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)),
758 (ADDiu CPURegs:$gp, tconstpool:$in)>;
761 def : Pat<(add CPURegs:$gp, (MipsTlsGd tglobaltlsaddr:$in)),
762 (ADDiu CPURegs:$gp, tglobaltlsaddr:$in)>;
765 def : Pat<(MipsTprelHi tglobaltlsaddr:$in), (LUi tglobaltlsaddr:$in)>;
766 def : Pat<(add CPURegs:$hi, (MipsTprelLo tglobaltlsaddr:$lo)),
767 (ADDiu CPURegs:$hi, tglobaltlsaddr:$lo)>;
770 class WrapperPICPat<SDNode node>:
771 Pat<(MipsWrapperPIC node:$in),
772 (ADDiu GP, node:$in)>;
774 def : WrapperPICPat<tglobaladdr>;
775 def : WrapperPICPat<tconstpool>;
776 def : WrapperPICPat<texternalsym>;
777 def : WrapperPICPat<tblockaddress>;
778 def : WrapperPICPat<tjumptable>;
780 // Mips does not have "not", so we expand our way
781 def : Pat<(not CPURegs:$in),
782 (NOR CPURegs:$in, ZERO)>;
784 // extended load and stores
785 def : Pat<(extloadi1 addr:$src), (LBu addr:$src)>;
786 def : Pat<(extloadi8 addr:$src), (LBu addr:$src)>;
787 def : Pat<(extloadi16 addr:$src), (LHu addr:$src)>;
790 def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
793 def : Pat<(brcond (setne CPURegs:$lhs, 0), bb:$dst),
794 (BNE CPURegs:$lhs, ZERO, bb:$dst)>;
795 def : Pat<(brcond (seteq CPURegs:$lhs, 0), bb:$dst),
796 (BEQ CPURegs:$lhs, ZERO, bb:$dst)>;
798 def : Pat<(brcond (setge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
799 (BEQ (SLT CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
800 def : Pat<(brcond (setuge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
801 (BEQ (SLTu CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
802 def : Pat<(brcond (setge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
803 (BEQ (SLTi CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
804 def : Pat<(brcond (setuge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
805 (BEQ (SLTiu CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
807 def : Pat<(brcond (setle CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
808 (BEQ (SLT CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
809 def : Pat<(brcond (setule CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
810 (BEQ (SLTu CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
812 def : Pat<(brcond CPURegs:$cond, bb:$dst),
813 (BNE CPURegs:$cond, ZERO, bb:$dst)>;
816 multiclass MovzPats<RegisterClass RC, Instruction MOVZInst> {
817 def : Pat<(select (setge CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
818 (MOVZInst RC:$T, (SLT CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
819 def : Pat<(select (setuge CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
820 (MOVZInst RC:$T, (SLTu CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
821 def : Pat<(select (setge CPURegs:$lhs, immSExt16:$rhs), RC:$T, RC:$F),
822 (MOVZInst RC:$T, (SLTi CPURegs:$lhs, immSExt16:$rhs), RC:$F)>;
823 def : Pat<(select (setuge CPURegs:$lh, immSExt16:$rh), RC:$T, RC:$F),
824 (MOVZInst RC:$T, (SLTiu CPURegs:$lh, immSExt16:$rh), RC:$F)>;
825 def : Pat<(select (setle CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
826 (MOVZInst RC:$T, (SLT CPURegs:$rhs, CPURegs:$lhs), RC:$F)>;
827 def : Pat<(select (setule CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
828 (MOVZInst RC:$T, (SLTu CPURegs:$rhs, CPURegs:$lhs), RC:$F)>;
829 def : Pat<(select (seteq CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
830 (MOVZInst RC:$T, (XOR CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
831 def : Pat<(select (seteq CPURegs:$lhs, 0), RC:$T, RC:$F),
832 (MOVZInst RC:$T, CPURegs:$lhs, RC:$F)>;
835 multiclass MovnPats<RegisterClass RC, Instruction MOVNInst> {
836 def : Pat<(select (setne CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
837 (MOVNInst RC:$T, (XOR CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
838 def : Pat<(select CPURegs:$cond, RC:$T, RC:$F),
839 (MOVNInst RC:$T, CPURegs:$cond, RC:$F)>;
840 def : Pat<(select (setne CPURegs:$lhs, 0), RC:$T, RC:$F),
841 (MOVNInst RC:$T, CPURegs:$lhs, RC:$F)>;
844 defm : MovzPats<CPURegs, MOVZ_I>;
845 defm : MovnPats<CPURegs, MOVN_I>;
848 def : Pat<(seteq CPURegs:$lhs, CPURegs:$rhs),
849 (SLTu (XOR CPURegs:$lhs, CPURegs:$rhs), 1)>;
850 def : Pat<(setne CPURegs:$lhs, CPURegs:$rhs),
851 (SLTu ZERO, (XOR CPURegs:$lhs, CPURegs:$rhs))>;
853 def : Pat<(setle CPURegs:$lhs, CPURegs:$rhs),
854 (XORi (SLT CPURegs:$rhs, CPURegs:$lhs), 1)>;
855 def : Pat<(setule CPURegs:$lhs, CPURegs:$rhs),
856 (XORi (SLTu CPURegs:$rhs, CPURegs:$lhs), 1)>;
858 def : Pat<(setgt CPURegs:$lhs, CPURegs:$rhs),
859 (SLT CPURegs:$rhs, CPURegs:$lhs)>;
860 def : Pat<(setugt CPURegs:$lhs, CPURegs:$rhs),
861 (SLTu CPURegs:$rhs, CPURegs:$lhs)>;
863 def : Pat<(setge CPURegs:$lhs, CPURegs:$rhs),
864 (XORi (SLT CPURegs:$lhs, CPURegs:$rhs), 1)>;
865 def : Pat<(setuge CPURegs:$lhs, CPURegs:$rhs),
866 (XORi (SLTu CPURegs:$lhs, CPURegs:$rhs), 1)>;
868 def : Pat<(setge CPURegs:$lhs, immSExt16:$rhs),
869 (XORi (SLTi CPURegs:$lhs, immSExt16:$rhs), 1)>;
870 def : Pat<(setuge CPURegs:$lhs, immSExt16:$rhs),
871 (XORi (SLTiu CPURegs:$lhs, immSExt16:$rhs), 1)>;
873 // select MipsDynAlloc
874 def : Pat<(MipsDynAlloc addr:$f), (DynAlloc addr:$f)>;
876 //===----------------------------------------------------------------------===//
877 // Floating Point Support
878 //===----------------------------------------------------------------------===//
880 include "MipsInstrFPU.td"