blob: 7733d6a27d927c76ac8a92557f82f6a75a2039d6 [file] [log] [blame]
Chris Lattner23e70eb2010-08-17 16:20:04 +00001//===- MipsInstrInfo.td - Mips Register defs ---------------*- tablegen -*-===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00007//
8//===----------------------------------------------------------------------===//
9
10//===----------------------------------------------------------------------===//
11// Instruction format superclass
12//===----------------------------------------------------------------------===//
13
14include "MipsInstrFormats.td"
15
16//===----------------------------------------------------------------------===//
17// Mips profiles and nodes
18//===----------------------------------------------------------------------===//
19
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000020def SDT_MipsRet : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
21def SDT_MipsJmpLink : SDTypeProfile<0, 1, [SDTCisVT<0, iPTR>]>;
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000022def SDT_MipsSelectCC : SDTypeProfile<1, 3, [SDTCisSameAs<0, 2>,
Bruno Cardoso Lopes6d399bd2008-07-29 19:05:28 +000023 SDTCisSameAs<2, 3>, SDTCisInt<1>]>;
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000024def SDT_MipsCMov : SDTypeProfile<1, 4, [SDTCisSameAs<0, 1>,
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +000025 SDTCisSameAs<1, 2>, SDTCisSameAs<3, 4>,
26 SDTCisInt<4>]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000027def SDT_MipsCallSeqStart : SDCallSeqStart<[SDTCisVT<0, i32>]>;
28def SDT_MipsCallSeqEnd : SDCallSeqEnd<[SDTCisVT<0, i32>, SDTCisVT<1, i32>]>;
29
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000030// Call
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000031def MipsJmpLink : SDNode<"MipsISD::JmpLink",SDT_MipsJmpLink,
Chris Lattner036609b2010-12-23 18:28:41 +000032 [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue,
Chris Lattner60e9eac2010-03-19 05:33:51 +000033 SDNPVariadic]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000034
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000035// Hi and Lo nodes are used to handle global addresses. Used on
36// MipsISelLowering to lower stuff like GlobalAddress, ExternalSymbol
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +000037// static model. (nothing to do with Mips Registers Hi and Lo)
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +000038def MipsHi : SDNode<"MipsISD::Hi", SDTIntUnaryOp>;
39def MipsLo : SDNode<"MipsISD::Lo", SDTIntUnaryOp>;
40def MipsGPRel : SDNode<"MipsISD::GPRel", SDTIntUnaryOp>;
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +000041
Eric Christopher3c999a22007-10-26 04:00:13 +000042// Return
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000043def MipsRet : SDNode<"MipsISD::Ret", SDT_MipsRet, [SDNPHasChain,
Chris Lattner036609b2010-12-23 18:28:41 +000044 SDNPOptInGlue]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000045
46// These are target-independent nodes, but have target-specific formats.
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000047def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_MipsCallSeqStart,
Chris Lattner036609b2010-12-23 18:28:41 +000048 [SDNPHasChain, SDNPOutGlue]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000049def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_MipsCallSeqEnd,
Chris Lattner036609b2010-12-23 18:28:41 +000050 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
Bill Wendling0f8d9c02007-11-13 00:44:25 +000051
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000052// Select Condition Code
53def MipsSelectCC : SDNode<"MipsISD::SelectCC", SDT_MipsSelectCC>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +000054
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +000055//===----------------------------------------------------------------------===//
56// Mips Instruction Predicate Definitions.
57//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +000058def HasSEInReg : Predicate<"Subtarget.hasSEInReg()">;
59def HasBitCount : Predicate<"Subtarget.hasBitCount()">;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +000060def HasSwap : Predicate<"Subtarget.hasSwap()">;
61def HasCondMov : Predicate<"Subtarget.hasCondMov()">;
Bruno Cardoso Lopes7d5652d2010-11-12 00:38:32 +000062def IsMips32 : Predicate<"Subtarget.isMips32()">;
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +000063def IsMips32r2 : Predicate<"Subtarget.isMips32r2()">;
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +000064
65//===----------------------------------------------------------------------===//
66// Mips Operand, Complex Patterns and Transformations Definitions.
67//===----------------------------------------------------------------------===//
68
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000069// Instruction operand types
70def brtarget : Operand<OtherVT>;
71def calltarget : Operand<i32>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000072def simm16 : Operand<i32>;
Eric Christopher3c999a22007-10-26 04:00:13 +000073def shamt : Operand<i32>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000074
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +000075// Unsigned Operand
76def uimm16 : Operand<i32> {
77 let PrintMethod = "printUnsignedImm";
78}
79
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000080// Address operand
81def mem : Operand<i32> {
82 let PrintMethod = "printMemOperand";
83 let MIOperandInfo = (ops simm16, CPURegs);
84}
85
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000086// Transformation Function - get the lower 16 bits.
87def LO16 : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000088 return getI32Imm((unsigned)N->getZExtValue() & 0xFFFF);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000089}]>;
90
91// Transformation Function - get the higher 16 bits.
92def HI16 : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000093 return getI32Imm((unsigned)N->getZExtValue() >> 16);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000094}]>;
95
96// Node immediate fits as 16-bit sign extended on target immediate.
97// e.g. addi, andi
Jakob Stoklund Olesen7552a3d2010-08-18 23:56:46 +000098def immSExt16 : PatLeaf<(imm), [{ return isInt<16>(N->getSExtValue()); }]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000099
100// Node immediate fits as 16-bit zero extended on target immediate.
101// The LO16 param means that only the lower 16 bits of the node
102// immediate are caught.
103// e.g. addiu, sltiu
104def immZExt16 : PatLeaf<(imm), [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000105 if (N->getValueType(0) == MVT::i32)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000106 return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Eric Christopher3c999a22007-10-26 04:00:13 +0000107 else
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000108 return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000109}], LO16>;
110
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000111// shamt field must fit in 5 bits.
112def immZExt5 : PatLeaf<(imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000113 return N->getZExtValue() == ((N->getZExtValue()) & 0x1f) ;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000114}]>;
115
Eric Christopher3c999a22007-10-26 04:00:13 +0000116// Mips Address Mode! SDNode frameindex could possibily be a match
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000117// since load and store instructions from stack used it.
Chris Lattnereb079a32010-02-14 21:53:19 +0000118def addr : ComplexPattern<iPTR, 2, "SelectAddr", [frameindex], []>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000119
120//===----------------------------------------------------------------------===//
121// Instructions specific format
122//===----------------------------------------------------------------------===//
123
124// Arithmetic 3 register operands
Eric Christopher3c999a22007-10-26 04:00:13 +0000125let isCommutable = 1 in
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000126class ArithR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
Eric Christopher3c999a22007-10-26 04:00:13 +0000127 InstrItinClass itin>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000128 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
129 !strconcat(instr_asm, "\t$dst, $b, $c"),
130 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], itin>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000131
Eric Christopher3c999a22007-10-26 04:00:13 +0000132let isCommutable = 1 in
133class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000134 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
135 !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000136
137// Arithmetic 2 register operands
Eric Christopher3c999a22007-10-26 04:00:13 +0000138class ArithI<bits<6> op, string instr_asm, SDNode OpNode,
139 Operand Od, PatLeaf imm_type> :
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000140 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
141 !strconcat(instr_asm, "\t$dst, $b, $c"),
142 [(set CPURegs:$dst, (OpNode CPURegs:$b, imm_type:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000143
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000144class ArithOverflowI<bits<6> op, string instr_asm, SDNode OpNode,
145 Operand Od, PatLeaf imm_type> :
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000146 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
147 !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000148
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000149// Arithmetic Multiply ADD/SUB
150let rd=0 in
Eric Christopher3c999a22007-10-26 04:00:13 +0000151class MArithR<bits<6> func, string instr_asm> :
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000152 FR<0x1c, func, (outs CPURegs:$rs), (ins CPURegs:$rt),
153 !strconcat(instr_asm, "\t$rs, $rt"), [], IIImul>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000154
155// Logical
156class LogicR<bits<6> func, string instr_asm, SDNode OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000157 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
158 !strconcat(instr_asm, "\t$dst, $b, $c"),
159 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000160
161class LogicI<bits<6> op, string instr_asm, SDNode OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000162 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, uimm16:$c),
163 !strconcat(instr_asm, "\t$dst, $b, $c"),
164 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt16:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000165
166class LogicNOR<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000167 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
168 !strconcat(instr_asm, "\t$dst, $b, $c"),
169 [(set CPURegs:$dst, (not (or CPURegs:$b, CPURegs:$c)))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000170
171// Shifts
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000172class LogicR_shift_rotate_imm<bits<6> func, bits<5> _rs, string instr_asm,
173 SDNode OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000174 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, shamt:$c),
175 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000176 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt5:$c))], IIAlu> {
177 let rs = _rs;
178}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000179
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000180class LogicR_shift_rotate_reg<bits<6> func, bits<5> _shamt, string instr_asm,
181 SDNode OpNode>:
182 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$c, CPURegs:$b),
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000183 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000184 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu> {
185 let shamt = _shamt;
186}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000187
188// Load Upper Imediate
189class LoadUpper<bits<6> op, string instr_asm>:
190 FI< op,
Evan Cheng64d80e32007-07-19 01:14:50 +0000191 (outs CPURegs:$dst),
192 (ins uimm16:$imm),
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000193 !strconcat(instr_asm, "\t$dst, $imm"),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000194 [], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000195
Eric Christopher3c999a22007-10-26 04:00:13 +0000196// Memory Load/Store
Dan Gohman15511cf2008-12-03 18:15:48 +0000197let canFoldAsLoad = 1, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000198class LoadM<bits<6> op, string instr_asm, PatFrag OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000199 FI<op, (outs CPURegs:$dst), (ins mem:$addr),
200 !strconcat(instr_asm, "\t$dst, $addr"),
201 [(set CPURegs:$dst, (OpNode addr:$addr))], IILoad>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000202
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000203class StoreM<bits<6> op, string instr_asm, PatFrag OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000204 FI<op, (outs), (ins CPURegs:$dst, mem:$addr),
205 !strconcat(instr_asm, "\t$dst, $addr"),
206 [(OpNode CPURegs:$dst, addr:$addr)], IIStore>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000207
208// Conditional Branch
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000209let isBranch = 1, isTerminator=1, hasDelaySlot = 1 in {
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000210class CBranch<bits<6> op, string instr_asm, PatFrag cond_op>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000211 FI<op, (outs), (ins CPURegs:$a, CPURegs:$b, brtarget:$offset),
212 !strconcat(instr_asm, "\t$a, $b, $offset"),
213 [(brcond (cond_op CPURegs:$a, CPURegs:$b), bb:$offset)],
214 IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000215
216class CBranchZero<bits<6> op, string instr_asm, PatFrag cond_op>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000217 FI<op, (outs), (ins CPURegs:$src, brtarget:$offset),
218 !strconcat(instr_asm, "\t$src, $offset"),
219 [(brcond (cond_op CPURegs:$src, 0), bb:$offset)],
220 IIBranch>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000221}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000222
Eric Christopher3c999a22007-10-26 04:00:13 +0000223// SetCC
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000224class SetCC_R<bits<6> op, bits<6> func, string instr_asm,
225 PatFrag cond_op>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000226 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
227 !strconcat(instr_asm, "\t$dst, $b, $c"),
228 [(set CPURegs:$dst, (cond_op CPURegs:$b, CPURegs:$c))],
229 IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000230
231class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op,
232 Operand Od, PatLeaf imm_type>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000233 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
234 !strconcat(instr_asm, "\t$dst, $b, $c"),
235 [(set CPURegs:$dst, (cond_op CPURegs:$b, imm_type:$c))],
236 IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000237
238// Unconditional branch
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000239let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000240class JumpFJ<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000241 FJ<op, (outs), (ins brtarget:$target),
242 !strconcat(instr_asm, "\t$target"), [(br bb:$target)], IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000243
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000244let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000245class JumpFR<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000246 FR<op, func, (outs), (ins CPURegs:$target),
247 !strconcat(instr_asm, "\t$target"), [(brind CPURegs:$target)], IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000248
249// Jump and Link (Call)
Eric Christopher3c999a22007-10-26 04:00:13 +0000250let isCall=1, hasDelaySlot=1,
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000251 // All calls clobber the non-callee saved registers...
Jakob Stoklund Olesende12e432010-02-17 20:18:50 +0000252 Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9,
253 K0, K1, D0, D1, D2, D3, D4, D5, D6, D7, D8, D9], Uses = [GP] in {
Eric Christopher3c999a22007-10-26 04:00:13 +0000254 class JumpLink<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000255 FJ<op, (outs), (ins calltarget:$target, variable_ops),
256 !strconcat(instr_asm, "\t$target"), [(MipsJmpLink imm:$target)],
257 IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000258
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000259 let rd=31 in
260 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000261 FR<op, func, (outs), (ins CPURegs:$rs, variable_ops),
262 !strconcat(instr_asm, "\t$rs"), [(MipsJmpLink CPURegs:$rs)], IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000263
264 class BranchLink<string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000265 FI<0x1, (outs), (ins CPURegs:$rs, brtarget:$target, variable_ops),
266 !strconcat(instr_asm, "\t$rs, $target"), [], IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000267}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000268
Eric Christopher3c999a22007-10-26 04:00:13 +0000269// Mul, Div
270class MulDiv<bits<6> func, string instr_asm, InstrItinClass itin>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000271 FR<0x00, func, (outs), (ins CPURegs:$a, CPURegs:$b),
272 !strconcat(instr_asm, "\t$a, $b"), [], itin>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000273
Eric Christopher3c999a22007-10-26 04:00:13 +0000274// Move from Hi/Lo
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000275class MoveFromLOHI<bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000276 FR<0x00, func, (outs CPURegs:$dst), (ins),
277 !strconcat(instr_asm, "\t$dst"), [], IIHiLo>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000278
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000279class MoveToLOHI<bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000280 FR<0x00, func, (outs), (ins CPURegs:$src),
281 !strconcat(instr_asm, "\t$src"), [], IIHiLo>;
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000282
Eric Christopher3c999a22007-10-26 04:00:13 +0000283class EffectiveAddress<string instr_asm> :
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000284 FI<0x09, (outs CPURegs:$dst), (ins mem:$addr),
285 instr_asm, [(set CPURegs:$dst, addr:$addr)], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000286
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000287// Count Leading Ones/Zeros in Word
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000288class CountLeading<bits<6> func, string instr_asm, list<dag> pattern>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000289 FR<0x1c, func, (outs CPURegs:$dst), (ins CPURegs:$src),
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000290 !strconcat(instr_asm, "\t$dst, $src"), pattern, IIAlu>,
291 Requires<[HasBitCount]> {
292 let shamt = 0;
293 let rt = rd;
294}
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000295
296// Sign Extend in Register.
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000297class SignExtInReg<bits<6> func, string instr_asm, ValueType vt>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000298 FR<0x3f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
299 !strconcat(instr_asm, "\t$dst, $src"),
300 [(set CPURegs:$dst, (sext_inreg CPURegs:$src, vt))], NoItinerary>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000301
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000302// Byte Swap
303class ByteSwap<bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000304 FR<0x1f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
305 !strconcat(instr_asm, "\t$dst, $src"),
306 [(set CPURegs:$dst, (bswap CPURegs:$src))], NoItinerary>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000307
308// Conditional Move
309class CondMov<bits<6> func, string instr_asm, PatLeaf MovCode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000310 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$F, CPURegs:$T,
311 CPURegs:$cond), !strconcat(instr_asm, "\t$dst, $T, $cond"),
Bruno Cardoso Lopesbd3af09c2010-12-07 19:04:14 +0000312 [], NoItinerary>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000313
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000314//===----------------------------------------------------------------------===//
315// Pseudo instructions
316//===----------------------------------------------------------------------===//
317
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000318// As stack alignment is always done with addiu, we need a 16-bit immediate
Evan Cheng071a2792007-09-11 19:55:27 +0000319let Defs = [SP], Uses = [SP] in {
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000320def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000321 "!ADJCALLSTACKDOWN $amt",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000322 [(callseq_start timm:$amt)]>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000323def ADJCALLSTACKUP : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000324 "!ADJCALLSTACKUP $amt1",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000325 [(callseq_end timm:$amt1, timm:$amt2)]>;
Evan Cheng071a2792007-09-11 19:55:27 +0000326}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000327
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000328// Some assembly macros need to avoid pseudoinstructions and assembler
329// automatic reodering, we should reorder ourselves.
330def MACRO : MipsPseudo<(outs), (ins), ".set\tmacro", []>;
331def REORDER : MipsPseudo<(outs), (ins), ".set\treorder", []>;
332def NOMACRO : MipsPseudo<(outs), (ins), ".set\tnomacro", []>;
333def NOREORDER : MipsPseudo<(outs), (ins), ".set\tnoreorder", []>;
334
Eric Christopher3c999a22007-10-26 04:00:13 +0000335// When handling PIC code the assembler needs .cpload and .cprestore
336// directives. If the real instructions corresponding these directives
337// are used, we have the same behavior, but get also a bunch of warnings
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000338// from the assembler.
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000339def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$picreg), ".cpload\t$picreg", []>;
340def CPRESTORE : MipsPseudo<(outs), (ins uimm16:$loc), ".cprestore\t$loc\n", []>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000341
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000342// The supported Mips ISAs dont have any instruction close to the SELECT_CC
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000343// operation. The solution is to create a Mips pseudo SELECT_CC instruction
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000344// (MipsSelectCC), use LowerSELECT_CC to generate this instruction and finally
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000345// replace it for real supported nodes into EmitInstrWithCustomInserter
Dan Gohman533297b2009-10-29 18:10:34 +0000346let usesCustomInserter = 1 in {
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000347 class PseudoSelCC<RegisterClass RC, string asmstr>:
348 MipsPseudo<(outs RC:$dst), (ins CPURegs:$CmpRes, RC:$T, RC:$F), asmstr,
Bruno Cardoso Lopes6d399bd2008-07-29 19:05:28 +0000349 [(set RC:$dst, (MipsSelectCC CPURegs:$CmpRes, RC:$T, RC:$F))]>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000350}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000351
Bruno Cardoso Lopes6d399bd2008-07-29 19:05:28 +0000352def Select_CC : PseudoSelCC<CPURegs, "# MipsSelect_CC_i32">;
353
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000354//===----------------------------------------------------------------------===//
355// Instruction definition
356//===----------------------------------------------------------------------===//
357
358//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000359// MipsI Instructions
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000360//===----------------------------------------------------------------------===//
361
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000362/// Arithmetic Instructions (ALU Immediate)
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000363def ADDiu : ArithI<0x09, "addiu", add, simm16, immSExt16>;
364def ADDi : ArithOverflowI<0x08, "addi", add, simm16, immSExt16>;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000365def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000366def SLTiu : SetCC_I<0x0b, "sltiu", setult, simm16, immSExt16>;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000367def ANDi : LogicI<0x0c, "andi", and>;
368def ORi : LogicI<0x0d, "ori", or>;
369def XORi : LogicI<0x0e, "xori", xor>;
370def LUi : LoadUpper<0x0f, "lui">;
371
372/// Arithmetic Instructions (3-Operand, R-Type)
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000373def ADDu : ArithR<0x00, 0x21, "addu", add, IIAlu>;
374def SUBu : ArithR<0x00, 0x23, "subu", sub, IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000375def ADD : ArithOverflowR<0x00, 0x20, "add">;
376def SUB : ArithOverflowR<0x00, 0x22, "sub">;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000377def SLT : SetCC_R<0x00, 0x2a, "slt", setlt>;
378def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000379def AND : LogicR<0x24, "and", and>;
380def OR : LogicR<0x25, "or", or>;
381def XOR : LogicR<0x26, "xor", xor>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000382def NOR : LogicNOR<0x00, 0x27, "nor">;
383
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000384/// Shift Instructions
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000385def SLL : LogicR_shift_rotate_imm<0x00, 0x00, "sll", shl>;
386def SRL : LogicR_shift_rotate_imm<0x02, 0x00, "srl", srl>;
387def SRA : LogicR_shift_rotate_imm<0x03, 0x00, "sra", sra>;
388def SLLV : LogicR_shift_rotate_reg<0x04, 0x00, "sllv", shl>;
389def SRLV : LogicR_shift_rotate_reg<0x06, 0x00, "srlv", srl>;
390def SRAV : LogicR_shift_rotate_reg<0x07, 0x00, "srav", sra>;
391
392// Rotate Instructions
393let Predicates = [IsMips32r2] in {
394 def ROTR : LogicR_shift_rotate_imm<0x02, 0x01, "rotr", rotr>;
395 def ROTRV : LogicR_shift_rotate_reg<0x06, 0x01, "rotrv", rotr>;
396}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000397
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000398/// Load and Store Instructions
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000399def LB : LoadM<0x20, "lb", sextloadi8>;
400def LBu : LoadM<0x24, "lbu", zextloadi8>;
401def LH : LoadM<0x21, "lh", sextloadi16>;
402def LHu : LoadM<0x25, "lhu", zextloadi16>;
403def LW : LoadM<0x23, "lw", load>;
404def SB : StoreM<0x28, "sb", truncstorei8>;
405def SH : StoreM<0x29, "sh", truncstorei16>;
406def SW : StoreM<0x2b, "sw", store>;
407
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000408/// Jump and Branch Instructions
409def J : JumpFJ<0x02, "j">;
410def JR : JumpFR<0x00, 0x08, "jr">;
411def JAL : JumpLink<0x03, "jal">;
412def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000413def BEQ : CBranch<0x04, "beq", seteq>;
414def BNE : CBranch<0x05, "bne", setne>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000415
Eric Christopher3c999a22007-10-26 04:00:13 +0000416let rt=1 in
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000417 def BGEZ : CBranchZero<0x01, "bgez", setge>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000418
419let rt=0 in {
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000420 def BGTZ : CBranchZero<0x07, "bgtz", setgt>;
421 def BLEZ : CBranchZero<0x07, "blez", setle>;
422 def BLTZ : CBranchZero<0x01, "bltz", setlt>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000423}
424
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000425def BGEZAL : BranchLink<"bgezal">;
426def BLTZAL : BranchLink<"bltzal">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000427
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000428let isReturn=1, isTerminator=1, hasDelaySlot=1,
429 isBarrier=1, hasCtrlDep=1, rs=0, rt=0, shamt=0 in
430 def RET : FR <0x00, 0x02, (outs), (ins CPURegs:$target),
431 "jr\t$target", [(MipsRet CPURegs:$target)], IIBranch>;
432
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000433/// Multiply and Divide Instructions.
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000434let Defs = [HI, LO] in {
435 def MULT : MulDiv<0x18, "mult", IIImul>;
436 def MULTu : MulDiv<0x19, "multu", IIImul>;
437 def DIV : MulDiv<0x1a, "div", IIIdiv>;
438 def DIVu : MulDiv<0x1b, "divu", IIIdiv>;
439}
440
441let Defs = [HI] in
442 def MTHI : MoveToLOHI<0x11, "mthi">;
443let Defs = [LO] in
444 def MTLO : MoveToLOHI<0x13, "mtlo">;
445
446let Uses = [HI] in
447 def MFHI : MoveFromLOHI<0x10, "mfhi">;
448let Uses = [LO] in
449 def MFLO : MoveFromLOHI<0x12, "mflo">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000450
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000451/// Sign Ext In Register Instructions.
452let Predicates = [HasSEInReg] in {
Bruno Cardoso Lopesd3bdf192009-05-27 17:23:44 +0000453 let shamt = 0x10, rs = 0 in
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000454 def SEB : SignExtInReg<0x21, "seb", i8>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000455
Bruno Cardoso Lopesd3bdf192009-05-27 17:23:44 +0000456 let shamt = 0x18, rs = 0 in
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000457 def SEH : SignExtInReg<0x20, "seh", i16>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000458}
459
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000460/// Count Leading
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000461def CLZ : CountLeading<0b100000, "clz",
462 [(set CPURegs:$dst, (ctlz CPURegs:$src))]>;
463def CLO : CountLeading<0b100001, "clo",
464 [(set CPURegs:$dst, (ctlz (not CPURegs:$src)))]>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000465
466/// Byte Swap
467let Predicates = [HasSwap] in {
468 let shamt = 0x3, rs = 0 in
469 def WSBW : ByteSwap<0x20, "wsbw">;
470}
471
472/// Conditional Move
473def MIPS_CMOV_ZERO : PatLeaf<(i32 0)>;
474def MIPS_CMOV_NZERO : PatLeaf<(i32 1)>;
475
Eric Christopherc452d792010-06-21 20:19:21 +0000476let Predicates = [HasCondMov], Constraints = "$F = $dst" in {
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000477 def MOVN : CondMov<0x0a, "movn", MIPS_CMOV_NZERO>;
478 def MOVZ : CondMov<0x0b, "movz", MIPS_CMOV_ZERO>;
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000479}
480
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000481/// No operation
482let addr=0 in
483 def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
484
Eric Christopher3c999a22007-10-26 04:00:13 +0000485// FrameIndexes are legalized when they are operands from load/store
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000486// instructions. The same not happens for stack address copies, so an
487// add op with mem ComplexPattern is used and the stack address copy
488// can be matched. It's similar to Sparc LEA_ADDRi
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000489def LEA_ADDiu : EffectiveAddress<"addiu\t$dst, ${addr:stackloc}">;
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000490
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000491// MADD*/MSUB* are not part of MipsI either.
492//def MADD : MArithR<0x00, "madd">;
493//def MADDU : MArithR<0x01, "maddu">;
494//def MSUB : MArithR<0x04, "msub">;
495//def MSUBU : MArithR<0x05, "msubu">;
496
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000497// MUL is a assembly macro in the current used ISAs. In recent ISA's
498// it is a real instruction.
Bruno Cardoso Lopes7d5652d2010-11-12 00:38:32 +0000499def MUL : ArithR<0x1c, 0x02, "mul", mul, IIImul>, Requires<[IsMips32]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000500
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000501//===----------------------------------------------------------------------===//
502// Arbitrary patterns that map to one or more instructions
503//===----------------------------------------------------------------------===//
504
505// Small immediates
Eric Christopher3c999a22007-10-26 04:00:13 +0000506def : Pat<(i32 immSExt16:$in),
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000507 (ADDiu ZERO, imm:$in)>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000508def : Pat<(i32 immZExt16:$in),
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000509 (ORi ZERO, imm:$in)>;
510
511// Arbitrary immediates
512def : Pat<(i32 imm:$imm),
513 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
514
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000515// Carry patterns
516def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
517 (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
518def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
519 (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
520def : Pat<(addc CPURegs:$src, imm:$imm),
521 (ADDiu CPURegs:$src, imm:$imm)>;
522
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000523// Call
524def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
525 (JAL tglobaladdr:$dst)>;
526def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
527 (JAL texternalsym:$dst)>;
Chris Lattnere0d27532010-02-28 07:23:21 +0000528//def : Pat<(MipsJmpLink CPURegs:$dst),
529// (JALR CPURegs:$dst)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000530
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000531// hi/lo relocs
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000532def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000533def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000534 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000535
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000536def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000537def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
538 (ADDiu CPURegs:$hi, tjumptable:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000539
540def : Pat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
541def : Pat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)),
542 (ADDiu CPURegs:$hi, tconstpool:$lo)>;
543
544// gp_rel relocs
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000545def : Pat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)),
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +0000546 (ADDiu CPURegs:$gp, tglobaladdr:$in)>;
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000547def : Pat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)),
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000548 (ADDiu CPURegs:$gp, tconstpool:$in)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000549
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000550// Mips does not have "not", so we expand our way
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000551def : Pat<(not CPURegs:$in),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000552 (NOR CPURegs:$in, ZERO)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000553
Eric Christopher3c999a22007-10-26 04:00:13 +0000554// extended load and stores
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000555def : Pat<(extloadi1 addr:$src), (LBu addr:$src)>;
556def : Pat<(extloadi8 addr:$src), (LBu addr:$src)>;
557def : Pat<(extloadi16 addr:$src), (LHu addr:$src)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000558
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000559// peepholes
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000560def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
561
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000562// brcond patterns
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000563def : Pat<(brcond (setne CPURegs:$lhs, 0), bb:$dst),
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000564 (BNE CPURegs:$lhs, ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000565def : Pat<(brcond (seteq CPURegs:$lhs, 0), bb:$dst),
566 (BEQ CPURegs:$lhs, ZERO, bb:$dst)>;
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000567
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000568def : Pat<(brcond (setge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000569 (BEQ (SLT CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000570def : Pat<(brcond (setuge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000571 (BEQ (SLTu CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
572def : Pat<(brcond (setge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
573 (BEQ (SLTi CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
574def : Pat<(brcond (setuge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
575 (BEQ (SLTiu CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000576
577def : Pat<(brcond (setle CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000578 (BEQ (SLT CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000579def : Pat<(brcond (setule CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000580 (BEQ (SLTu CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000581
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000582def : Pat<(brcond CPURegs:$cond, bb:$dst),
583 (BNE CPURegs:$cond, ZERO, bb:$dst)>;
584
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000585// select patterns
586def : Pat<(select (setge CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
587 (MOVZ CPURegs:$F, CPURegs:$T, (SLT CPURegs:$lhs, CPURegs:$rhs))>;
588def : Pat<(select (setuge CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
589 (MOVZ CPURegs:$F, CPURegs:$T, (SLTu CPURegs:$lhs, CPURegs:$rhs))>;
590def : Pat<(select (setge CPURegs:$lhs, immSExt16:$rhs), CPURegs:$T, CPURegs:$F),
591 (MOVZ CPURegs:$F, CPURegs:$T, (SLTi CPURegs:$lhs, immSExt16:$rhs))>;
592def : Pat<(select (setuge CPURegs:$lh, immSExt16:$rh), CPURegs:$T, CPURegs:$F),
593 (MOVZ CPURegs:$F, CPURegs:$T, (SLTiu CPURegs:$lh, immSExt16:$rh))>;
594
595def : Pat<(select (setle CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
596 (MOVZ CPURegs:$F, CPURegs:$T, (SLT CPURegs:$rhs, CPURegs:$lhs))>;
597def : Pat<(select (setule CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
598 (MOVZ CPURegs:$F, CPURegs:$T, (SLTu CPURegs:$rhs, CPURegs:$lhs))>;
599
600def : Pat<(select (seteq CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
601 (MOVZ CPURegs:$F, CPURegs:$T, (XOR CPURegs:$lhs, CPURegs:$rhs))>;
602def : Pat<(select (setne CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
603 (MOVN CPURegs:$F, CPURegs:$T, (XOR CPURegs:$lhs, CPURegs:$rhs))>;
604
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000605def : Pat<(select CPURegs:$cond, CPURegs:$T, CPURegs:$F),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000606 (MOVN CPURegs:$F, CPURegs:$T, CPURegs:$cond)>;
607
Bruno Cardoso Lopesab8d53a2010-12-07 19:00:20 +0000608// select patterns with got access
609def : Pat<(select (setne CPURegs:$lhs, CPURegs:$rhs),
610 (i32 tglobaladdr:$T), CPURegs:$F),
611 (MOVN CPURegs:$F, (ADDiu GP, tglobaladdr:$T),
612 (XOR CPURegs:$lhs, CPURegs:$rhs))>;
613
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000614// setcc patterns
615def : Pat<(seteq CPURegs:$lhs, CPURegs:$rhs),
616 (SLTu (XOR CPURegs:$lhs, CPURegs:$rhs), 1)>;
617def : Pat<(setne CPURegs:$lhs, CPURegs:$rhs),
618 (SLTu ZERO, (XOR CPURegs:$lhs, CPURegs:$rhs))>;
619
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000620def : Pat<(setle CPURegs:$lhs, CPURegs:$rhs),
621 (XORi (SLT CPURegs:$rhs, CPURegs:$lhs), 1)>;
622def : Pat<(setule CPURegs:$lhs, CPURegs:$rhs),
623 (XORi (SLTu CPURegs:$rhs, CPURegs:$lhs), 1)>;
624
625def : Pat<(setgt CPURegs:$lhs, CPURegs:$rhs),
626 (SLT CPURegs:$rhs, CPURegs:$lhs)>;
627def : Pat<(setugt CPURegs:$lhs, CPURegs:$rhs),
628 (SLTu CPURegs:$rhs, CPURegs:$lhs)>;
629
630def : Pat<(setge CPURegs:$lhs, CPURegs:$rhs),
631 (XORi (SLT CPURegs:$lhs, CPURegs:$rhs), 1)>;
632def : Pat<(setuge CPURegs:$lhs, CPURegs:$rhs),
633 (XORi (SLTu CPURegs:$lhs, CPURegs:$rhs), 1)>;
634
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000635def : Pat<(setge CPURegs:$lhs, immSExt16:$rhs),
636 (XORi (SLTi CPURegs:$lhs, immSExt16:$rhs), 1)>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000637def : Pat<(setuge CPURegs:$lhs, immSExt16:$rhs),
638 (XORi (SLTiu CPURegs:$lhs, immSExt16:$rhs), 1)>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000639
640//===----------------------------------------------------------------------===//
641// Floating Point Support
642//===----------------------------------------------------------------------===//
643
644include "MipsInstrFPU.td"
645