blob: ba0a73699727c4131bc252d73fa377e6c7cc555c [file] [log] [blame]
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00001//===- MipsInstrInfo.td - Mips Register defs --------------------*- C++ -*-===//
2//
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 Lopes6d399bd2008-07-29 19:05:28 +000022def SDT_MipsSelectCC : SDTypeProfile<1, 3, [SDTCisSameAs<0, 2>,
23 SDTCisSameAs<2, 3>, SDTCisInt<1>]>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +000024def SDT_MipsCMov : SDTypeProfile<1, 4, [SDTCisSameAs<0, 1>,
25 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 Lopes9201b102010-01-19 17:00:43 +000031def MipsJmpLink : SDNode<"MipsISD::JmpLink",SDT_MipsJmpLink,
32 [SDNPHasChain, SDNPOutFlag, SDNPOptInFlag]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000033
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +000034// Hi and Lo nodes are used to handle global addresses. Used on
35// MipsISelLowering to lower stuff like GlobalAddress, ExternalSymbol
36// static model. (nothing to do with Mips Registers Hi and Lo)
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +000037def MipsHi : SDNode<"MipsISD::Hi", SDTIntUnaryOp>;
38def MipsLo : SDNode<"MipsISD::Lo", SDTIntUnaryOp>;
39def MipsGPRel : SDNode<"MipsISD::GPRel", SDTIntUnaryOp>;
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +000040
Eric Christopher3c999a22007-10-26 04:00:13 +000041// Return
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000042def MipsRet : SDNode<"MipsISD::Ret", SDT_MipsRet, [SDNPHasChain,
43 SDNPOptInFlag]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000044
45// These are target-independent nodes, but have target-specific formats.
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000046def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_MipsCallSeqStart,
47 [SDNPHasChain, SDNPOutFlag]>;
48def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_MipsCallSeqEnd,
49 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
Bill Wendling0f8d9c02007-11-13 00:44:25 +000050
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000051// Select Condition Code
52def MipsSelectCC : SDNode<"MipsISD::SelectCC", SDT_MipsSelectCC>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +000053
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +000054// Conditional Move
55def MipsCMov : SDNode<"MipsISD::CMov", SDT_MipsCMov>;
56
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +000057//===----------------------------------------------------------------------===//
58// Mips Instruction Predicate Definitions.
59//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +000060def HasSEInReg : Predicate<"Subtarget.hasSEInReg()">;
61def HasBitCount : Predicate<"Subtarget.hasBitCount()">;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +000062def HasSwap : Predicate<"Subtarget.hasSwap()">;
63def HasCondMov : Predicate<"Subtarget.hasCondMov()">;
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
98def immSExt16 : PatLeaf<(imm), [{
Owen Anderson825b72b2009-08-11 20:47:22 +000099 if (N->getValueType(0) == MVT::i32)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000100 return (int32_t)N->getZExtValue() == (short)N->getZExtValue();
Eric Christopher3c999a22007-10-26 04:00:13 +0000101 else
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000102 return (int64_t)N->getZExtValue() == (short)N->getZExtValue();
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000103}]>;
104
105// Node immediate fits as 16-bit zero extended on target immediate.
106// The LO16 param means that only the lower 16 bits of the node
107// immediate are caught.
108// e.g. addiu, sltiu
109def immZExt16 : PatLeaf<(imm), [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000110 if (N->getValueType(0) == MVT::i32)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000111 return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Eric Christopher3c999a22007-10-26 04:00:13 +0000112 else
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000113 return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000114}], LO16>;
115
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000116// shamt field must fit in 5 bits.
117def immZExt5 : PatLeaf<(imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000118 return N->getZExtValue() == ((N->getZExtValue()) & 0x1f) ;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000119}]>;
120
Eric Christopher3c999a22007-10-26 04:00:13 +0000121// Mips Address Mode! SDNode frameindex could possibily be a match
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000122// since load and store instructions from stack used it.
Chris Lattnereb079a32010-02-14 21:53:19 +0000123def addr : ComplexPattern<iPTR, 2, "SelectAddr", [frameindex], []>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000124
125//===----------------------------------------------------------------------===//
126// Instructions specific format
127//===----------------------------------------------------------------------===//
128
129// Arithmetic 3 register operands
Eric Christopher3c999a22007-10-26 04:00:13 +0000130let isCommutable = 1 in
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000131class ArithR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
Eric Christopher3c999a22007-10-26 04:00:13 +0000132 InstrItinClass itin>:
133 FR< op,
134 func,
135 (outs CPURegs:$dst),
136 (ins CPURegs:$b, CPURegs:$c),
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000137 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000138 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], itin>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000139
Eric Christopher3c999a22007-10-26 04:00:13 +0000140let isCommutable = 1 in
141class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm>:
142 FR< op,
143 func,
144 (outs CPURegs:$dst),
145 (ins CPURegs:$b, CPURegs:$c),
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000146 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000147 [], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000148
149// Arithmetic 2 register operands
Eric Christopher3c999a22007-10-26 04:00:13 +0000150class ArithI<bits<6> op, string instr_asm, SDNode OpNode,
151 Operand Od, PatLeaf imm_type> :
152 FI< op,
153 (outs CPURegs:$dst),
154 (ins CPURegs:$b, Od:$c),
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000155 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000156 [(set CPURegs:$dst, (OpNode CPURegs:$b, imm_type:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000157
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000158class ArithOverflowI<bits<6> op, string instr_asm, SDNode OpNode,
159 Operand Od, PatLeaf imm_type> :
160 FI< op,
161 (outs CPURegs:$dst),
162 (ins CPURegs:$b, Od:$c),
163 !strconcat(instr_asm, "\t$dst, $b, $c"),
164 [], IIAlu>;
165
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000166// Arithmetic Multiply ADD/SUB
167let rd=0 in
Eric Christopher3c999a22007-10-26 04:00:13 +0000168class MArithR<bits<6> func, string instr_asm> :
169 FR< 0x1c,
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000170 func,
Eric Christopher3c999a22007-10-26 04:00:13 +0000171 (outs CPURegs:$rs),
172 (ins CPURegs:$rt),
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000173 !strconcat(instr_asm, "\t$rs, $rt"),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000174 [], IIImul>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000175
176// Logical
177class LogicR<bits<6> func, string instr_asm, SDNode OpNode>:
Eric Christopher3c999a22007-10-26 04:00:13 +0000178 FR< 0x00,
179 func,
180 (outs CPURegs:$dst),
181 (ins CPURegs:$b, CPURegs:$c),
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000182 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000183 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000184
185class LogicI<bits<6> op, string instr_asm, SDNode OpNode>:
186 FI< op,
Evan Cheng64d80e32007-07-19 01:14:50 +0000187 (outs CPURegs:$dst),
188 (ins CPURegs:$b, uimm16:$c),
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000189 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes0af5e092008-06-06 06:37:31 +0000190 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt16:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000191
192class LogicNOR<bits<6> op, bits<6> func, string instr_asm>:
Eric Christopher3c999a22007-10-26 04:00:13 +0000193 FR< op,
194 func,
195 (outs CPURegs:$dst),
196 (ins CPURegs:$b, CPURegs:$c),
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000197 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000198 [(set CPURegs:$dst, (not (or CPURegs:$b, CPURegs:$c)))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000199
200// Shifts
201let rt = 0 in
202class LogicR_shift_imm<bits<6> func, string instr_asm, SDNode OpNode>:
Eric Christopher3c999a22007-10-26 04:00:13 +0000203 FR< 0x00,
204 func,
Evan Cheng64d80e32007-07-19 01:14:50 +0000205 (outs CPURegs:$dst),
206 (ins CPURegs:$b, shamt:$c),
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000207 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000208 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt5:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000209
210class LogicR_shift_reg<bits<6> func, string instr_asm, SDNode OpNode>:
Eric Christopher3c999a22007-10-26 04:00:13 +0000211 FR< 0x00,
212 func,
Evan Cheng64d80e32007-07-19 01:14:50 +0000213 (outs CPURegs:$dst),
214 (ins CPURegs:$b, CPURegs:$c),
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000215 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000216 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000217
218// Load Upper Imediate
219class LoadUpper<bits<6> op, string instr_asm>:
220 FI< op,
Evan Cheng64d80e32007-07-19 01:14:50 +0000221 (outs CPURegs:$dst),
222 (ins uimm16:$imm),
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000223 !strconcat(instr_asm, "\t$dst, $imm"),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000224 [], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000225
Eric Christopher3c999a22007-10-26 04:00:13 +0000226// Memory Load/Store
Dan Gohman15511cf2008-12-03 18:15:48 +0000227let canFoldAsLoad = 1, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000228class LoadM<bits<6> op, string instr_asm, PatFrag OpNode>:
229 FI< op,
Evan Cheng64d80e32007-07-19 01:14:50 +0000230 (outs CPURegs:$dst),
231 (ins mem:$addr),
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000232 !strconcat(instr_asm, "\t$dst, $addr"),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000233 [(set CPURegs:$dst, (OpNode addr:$addr))], IILoad>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000234
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000235class StoreM<bits<6> op, string instr_asm, PatFrag OpNode>:
236 FI< op,
Evan Cheng64d80e32007-07-19 01:14:50 +0000237 (outs),
238 (ins CPURegs:$dst, mem:$addr),
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000239 !strconcat(instr_asm, "\t$dst, $addr"),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000240 [(OpNode CPURegs:$dst, addr:$addr)], IIStore>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000241
242// Conditional Branch
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000243let isBranch = 1, isTerminator=1, hasDelaySlot = 1 in {
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000244class CBranch<bits<6> op, string instr_asm, PatFrag cond_op>:
245 FI< op,
Evan Cheng64d80e32007-07-19 01:14:50 +0000246 (outs),
247 (ins CPURegs:$a, CPURegs:$b, brtarget:$offset),
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000248 !strconcat(instr_asm, "\t$a, $b, $offset"),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000249 [(brcond (cond_op CPURegs:$a, CPURegs:$b), bb:$offset)],
250 IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000251
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000252
253class CBranchZero<bits<6> op, string instr_asm, PatFrag cond_op>:
254 FI< op,
255 (outs),
256 (ins CPURegs:$src, brtarget:$offset),
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000257 !strconcat(instr_asm, "\t$src, $offset"),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000258 [(brcond (cond_op CPURegs:$src, 0), bb:$offset)],
259 IIBranch>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000260}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000261
Eric Christopher3c999a22007-10-26 04:00:13 +0000262// SetCC
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000263class SetCC_R<bits<6> op, bits<6> func, string instr_asm,
264 PatFrag cond_op>:
265 FR< op,
266 func,
Evan Cheng64d80e32007-07-19 01:14:50 +0000267 (outs CPURegs:$dst),
268 (ins CPURegs:$b, CPURegs:$c),
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000269 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000270 [(set CPURegs:$dst, (cond_op CPURegs:$b, CPURegs:$c))],
271 IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000272
273class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op,
274 Operand Od, PatLeaf imm_type>:
275 FI< op,
Evan Cheng64d80e32007-07-19 01:14:50 +0000276 (outs CPURegs:$dst),
277 (ins CPURegs:$b, Od:$c),
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000278 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000279 [(set CPURegs:$dst, (cond_op CPURegs:$b, imm_type:$c))],
280 IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000281
282// Unconditional branch
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000283let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000284class JumpFJ<bits<6> op, string instr_asm>:
285 FJ< op,
Evan Cheng64d80e32007-07-19 01:14:50 +0000286 (outs),
287 (ins brtarget:$target),
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000288 !strconcat(instr_asm, "\t$target"),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000289 [(br bb:$target)], IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000290
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000291let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000292class JumpFR<bits<6> op, bits<6> func, string instr_asm>:
293 FR< op,
294 func,
Evan Cheng64d80e32007-07-19 01:14:50 +0000295 (outs),
296 (ins CPURegs:$target),
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000297 !strconcat(instr_asm, "\t$target"),
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000298 [(brind CPURegs:$target)], IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000299
300// Jump and Link (Call)
Eric Christopher3c999a22007-10-26 04:00:13 +0000301let isCall=1, hasDelaySlot=1,
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000302 // All calls clobber the non-callee saved registers...
Jakob Stoklund Olesende12e432010-02-17 20:18:50 +0000303 Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9,
304 K0, K1, D0, D1, D2, D3, D4, D5, D6, D7, D8, D9], Uses = [GP] in {
Eric Christopher3c999a22007-10-26 04:00:13 +0000305 class JumpLink<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000306 FJ< op,
307 (outs),
Bruno Cardoso Lopes9201b102010-01-19 17:00:43 +0000308 (ins calltarget:$target, variable_ops),
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000309 !strconcat(instr_asm, "\t$target"),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000310 [(MipsJmpLink imm:$target)], IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000311
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000312 let rd=31 in
313 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
314 FR< op,
315 func,
316 (outs),
Bruno Cardoso Lopes9201b102010-01-19 17:00:43 +0000317 (ins CPURegs:$rs, variable_ops),
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000318 !strconcat(instr_asm, "\t$rs"),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000319 [(MipsJmpLink CPURegs:$rs)], IIBranch>;
320
321 class BranchLink<string instr_asm>:
322 FI< 0x1,
323 (outs),
Bruno Cardoso Lopes9201b102010-01-19 17:00:43 +0000324 (ins CPURegs:$rs, brtarget:$target, variable_ops),
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000325 !strconcat(instr_asm, "\t$rs, $target"),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000326 [], IIBranch>;
327}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000328
Eric Christopher3c999a22007-10-26 04:00:13 +0000329// Mul, Div
330class MulDiv<bits<6> func, string instr_asm, InstrItinClass itin>:
331 FR< 0x00,
332 func,
Evan Cheng64d80e32007-07-19 01:14:50 +0000333 (outs),
Eric Christopher3c999a22007-10-26 04:00:13 +0000334 (ins CPURegs:$a, CPURegs:$b),
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000335 !strconcat(instr_asm, "\t$a, $b"),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000336 [], itin>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000337
Eric Christopher3c999a22007-10-26 04:00:13 +0000338// Move from Hi/Lo
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000339class MoveFromLOHI<bits<6> func, string instr_asm>:
Eric Christopher3c999a22007-10-26 04:00:13 +0000340 FR< 0x00,
341 func,
342 (outs CPURegs:$dst),
Evan Cheng64d80e32007-07-19 01:14:50 +0000343 (ins),
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000344 !strconcat(instr_asm, "\t$dst"),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000345 [], IIHiLo>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000346
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000347class MoveToLOHI<bits<6> func, string instr_asm>:
348 FR< 0x00,
349 func,
350 (outs),
351 (ins CPURegs:$src),
352 !strconcat(instr_asm, "\t$src"),
353 [], IIHiLo>;
354
Eric Christopher3c999a22007-10-26 04:00:13 +0000355class EffectiveAddress<string instr_asm> :
356 FI<0x09,
357 (outs CPURegs:$dst),
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000358 (ins mem:$addr),
359 instr_asm,
360 [(set CPURegs:$dst, addr:$addr)], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000361
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000362// Count Leading Ones/Zeros in Word
363class CountLeading<bits<6> func, string instr_asm, SDNode CountOp>:
364 FR< 0x1c, func, (outs CPURegs:$dst), (ins CPURegs:$src),
365 !strconcat(instr_asm, "\t$dst, $src"),
366 [(set CPURegs:$dst, (CountOp CPURegs:$src))], IIAlu>;
367
368// Sign Extend in Register.
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000369class SignExtInReg<bits<6> func, string instr_asm, ValueType vt>:
370 FR< 0x3f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000371 !strconcat(instr_asm, "\t$dst, $src"),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000372 [(set CPURegs:$dst, (sext_inreg CPURegs:$src, vt))], NoItinerary>;
373
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000374// Byte Swap
375class ByteSwap<bits<6> func, string instr_asm>:
376 FR< 0x1f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
377 !strconcat(instr_asm, "\t$dst, $src"),
378 [(set CPURegs:$dst, (bswap CPURegs:$src))], NoItinerary>;
379
380// Conditional Move
381class CondMov<bits<6> func, string instr_asm, PatLeaf MovCode>:
382 FR< 0x00, func, (outs CPURegs:$dst), (ins CPURegs:$F, CPURegs:$T,
383 CPURegs:$cond), !strconcat(instr_asm, "\t$dst, $T, $cond"),
384 [(set CPURegs:$dst, (MipsCMov CPURegs:$F, CPURegs:$T,
385 CPURegs:$cond, MovCode))], NoItinerary>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000386
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000387//===----------------------------------------------------------------------===//
388// Pseudo instructions
389//===----------------------------------------------------------------------===//
390
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000391// As stack alignment is always done with addiu, we need a 16-bit immediate
Evan Cheng071a2792007-09-11 19:55:27 +0000392let Defs = [SP], Uses = [SP] in {
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000393def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000394 "!ADJCALLSTACKDOWN $amt",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000395 [(callseq_start timm:$amt)]>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000396def ADJCALLSTACKUP : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000397 "!ADJCALLSTACKUP $amt1",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000398 [(callseq_end timm:$amt1, timm:$amt2)]>;
Evan Cheng071a2792007-09-11 19:55:27 +0000399}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000400
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000401// Some assembly macros need to avoid pseudoinstructions and assembler
402// automatic reodering, we should reorder ourselves.
403def MACRO : MipsPseudo<(outs), (ins), ".set\tmacro", []>;
404def REORDER : MipsPseudo<(outs), (ins), ".set\treorder", []>;
405def NOMACRO : MipsPseudo<(outs), (ins), ".set\tnomacro", []>;
406def NOREORDER : MipsPseudo<(outs), (ins), ".set\tnoreorder", []>;
407
Eric Christopher3c999a22007-10-26 04:00:13 +0000408// When handling PIC code the assembler needs .cpload and .cprestore
409// directives. If the real instructions corresponding these directives
410// are used, we have the same behavior, but get also a bunch of warnings
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000411// from the assembler.
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000412def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$picreg), ".cpload\t$picreg", []>;
413def CPRESTORE : MipsPseudo<(outs), (ins uimm16:$loc), ".cprestore\t$loc\n", []>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000414
415// The supported Mips ISAs dont have any instruction close to the SELECT_CC
416// operation. The solution is to create a Mips pseudo SELECT_CC instruction
417// (MipsSelectCC), use LowerSELECT_CC to generate this instruction and finally
418// replace it for real supported nodes into EmitInstrWithCustomInserter
Dan Gohman533297b2009-10-29 18:10:34 +0000419let usesCustomInserter = 1 in {
Bruno Cardoso Lopes6d399bd2008-07-29 19:05:28 +0000420 class PseudoSelCC<RegisterClass RC, string asmstr>:
421 MipsPseudo<(outs RC:$dst), (ins CPURegs:$CmpRes, RC:$T, RC:$F), asmstr,
422 [(set RC:$dst, (MipsSelectCC CPURegs:$CmpRes, RC:$T, RC:$F))]>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000423}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000424
Bruno Cardoso Lopes6d399bd2008-07-29 19:05:28 +0000425def Select_CC : PseudoSelCC<CPURegs, "# MipsSelect_CC_i32">;
426
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000427//===----------------------------------------------------------------------===//
428// Instruction definition
429//===----------------------------------------------------------------------===//
430
431//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000432// MipsI Instructions
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000433//===----------------------------------------------------------------------===//
434
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000435/// Arithmetic Instructions (ALU Immediate)
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000436def ADDiu : ArithI<0x09, "addiu", add, simm16, immSExt16>;
437def ADDi : ArithOverflowI<0x08, "addi", add, simm16, immSExt16>;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000438def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000439def SLTiu : SetCC_I<0x0b, "sltiu", setult, simm16, immSExt16>;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000440def ANDi : LogicI<0x0c, "andi", and>;
441def ORi : LogicI<0x0d, "ori", or>;
442def XORi : LogicI<0x0e, "xori", xor>;
443def LUi : LoadUpper<0x0f, "lui">;
444
445/// Arithmetic Instructions (3-Operand, R-Type)
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000446def ADDu : ArithR<0x00, 0x21, "addu", add, IIAlu>;
447def SUBu : ArithR<0x00, 0x23, "subu", sub, IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000448def ADD : ArithOverflowR<0x00, 0x20, "add">;
449def SUB : ArithOverflowR<0x00, 0x22, "sub">;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000450def SLT : SetCC_R<0x00, 0x2a, "slt", setlt>;
451def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000452def AND : LogicR<0x24, "and", and>;
453def OR : LogicR<0x25, "or", or>;
454def XOR : LogicR<0x26, "xor", xor>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000455def NOR : LogicNOR<0x00, 0x27, "nor">;
456
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000457/// Shift Instructions
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000458def SLL : LogicR_shift_imm<0x00, "sll", shl>;
459def SRL : LogicR_shift_imm<0x02, "srl", srl>;
460def SRA : LogicR_shift_imm<0x03, "sra", sra>;
461def SLLV : LogicR_shift_reg<0x04, "sllv", shl>;
462def SRLV : LogicR_shift_reg<0x06, "srlv", srl>;
463def SRAV : LogicR_shift_reg<0x07, "srav", sra>;
464
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000465/// Load and Store Instructions
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000466def LB : LoadM<0x20, "lb", sextloadi8>;
467def LBu : LoadM<0x24, "lbu", zextloadi8>;
468def LH : LoadM<0x21, "lh", sextloadi16>;
469def LHu : LoadM<0x25, "lhu", zextloadi16>;
470def LW : LoadM<0x23, "lw", load>;
471def SB : StoreM<0x28, "sb", truncstorei8>;
472def SH : StoreM<0x29, "sh", truncstorei16>;
473def SW : StoreM<0x2b, "sw", store>;
474
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000475/// Jump and Branch Instructions
476def J : JumpFJ<0x02, "j">;
477def JR : JumpFR<0x00, 0x08, "jr">;
478def JAL : JumpLink<0x03, "jal">;
479def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000480def BEQ : CBranch<0x04, "beq", seteq>;
481def BNE : CBranch<0x05, "bne", setne>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000482
Eric Christopher3c999a22007-10-26 04:00:13 +0000483let rt=1 in
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000484 def BGEZ : CBranchZero<0x01, "bgez", setge>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000485
486let rt=0 in {
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000487 def BGTZ : CBranchZero<0x07, "bgtz", setgt>;
488 def BLEZ : CBranchZero<0x07, "blez", setle>;
489 def BLTZ : CBranchZero<0x01, "bltz", setlt>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000490}
491
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000492def BGEZAL : BranchLink<"bgezal">;
493def BLTZAL : BranchLink<"bltzal">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000494
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000495let isReturn=1, isTerminator=1, hasDelaySlot=1,
496 isBarrier=1, hasCtrlDep=1, rs=0, rt=0, shamt=0 in
497 def RET : FR <0x00, 0x02, (outs), (ins CPURegs:$target),
498 "jr\t$target", [(MipsRet CPURegs:$target)], IIBranch>;
499
500/// Multiply and Divide Instructions.
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000501let Defs = [HI, LO] in {
502 def MULT : MulDiv<0x18, "mult", IIImul>;
503 def MULTu : MulDiv<0x19, "multu", IIImul>;
504 def DIV : MulDiv<0x1a, "div", IIIdiv>;
505 def DIVu : MulDiv<0x1b, "divu", IIIdiv>;
506}
507
508let Defs = [HI] in
509 def MTHI : MoveToLOHI<0x11, "mthi">;
510let Defs = [LO] in
511 def MTLO : MoveToLOHI<0x13, "mtlo">;
512
513let Uses = [HI] in
514 def MFHI : MoveFromLOHI<0x10, "mfhi">;
515let Uses = [LO] in
516 def MFLO : MoveFromLOHI<0x12, "mflo">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000517
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000518/// Sign Ext In Register Instructions.
519let Predicates = [HasSEInReg] in {
Bruno Cardoso Lopesd3bdf192009-05-27 17:23:44 +0000520 let shamt = 0x10, rs = 0 in
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000521 def SEB : SignExtInReg<0x21, "seb", i8>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000522
Bruno Cardoso Lopesd3bdf192009-05-27 17:23:44 +0000523 let shamt = 0x18, rs = 0 in
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000524 def SEH : SignExtInReg<0x20, "seh", i16>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000525}
526
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000527/// Count Leading
528let Predicates = [HasBitCount] in {
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000529 let rt = 0 in
530 def CLZ : CountLeading<0b010110, "clz", ctlz>;
531}
532
533/// Byte Swap
534let Predicates = [HasSwap] in {
535 let shamt = 0x3, rs = 0 in
536 def WSBW : ByteSwap<0x20, "wsbw">;
537}
538
539/// Conditional Move
540def MIPS_CMOV_ZERO : PatLeaf<(i32 0)>;
541def MIPS_CMOV_NZERO : PatLeaf<(i32 1)>;
542
543let Predicates = [HasCondMov], isTwoAddress = 1 in {
544 def MOVN : CondMov<0x0a, "movn", MIPS_CMOV_NZERO>;
545 def MOVZ : CondMov<0x0b, "movz", MIPS_CMOV_ZERO>;
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000546}
547
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000548/// No operation
549let addr=0 in
550 def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
551
Eric Christopher3c999a22007-10-26 04:00:13 +0000552// FrameIndexes are legalized when they are operands from load/store
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000553// instructions. The same not happens for stack address copies, so an
554// add op with mem ComplexPattern is used and the stack address copy
555// can be matched. It's similar to Sparc LEA_ADDRi
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000556def LEA_ADDiu : EffectiveAddress<"addiu\t$dst, ${addr:stackloc}">;
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000557
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000558// MADD*/MSUB* are not part of MipsI either.
559//def MADD : MArithR<0x00, "madd">;
560//def MADDU : MArithR<0x01, "maddu">;
561//def MSUB : MArithR<0x04, "msub">;
562//def MSUBU : MArithR<0x05, "msubu">;
563
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000564// MUL is a assembly macro in the current used ISAs. In recent ISA's
565// it is a real instruction.
566//def MUL : ArithR<0x1c, 0x02, "mul", mul, IIImul>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000567
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000568//===----------------------------------------------------------------------===//
569// Arbitrary patterns that map to one or more instructions
570//===----------------------------------------------------------------------===//
571
572// Small immediates
Eric Christopher3c999a22007-10-26 04:00:13 +0000573def : Pat<(i32 immSExt16:$in),
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000574 (ADDiu ZERO, imm:$in)>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000575def : Pat<(i32 immZExt16:$in),
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000576 (ORi ZERO, imm:$in)>;
577
578// Arbitrary immediates
579def : Pat<(i32 imm:$imm),
580 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
581
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000582// Carry patterns
583def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
584 (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
585def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
586 (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
587def : Pat<(addc CPURegs:$src, imm:$imm),
588 (ADDiu CPURegs:$src, imm:$imm)>;
589
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000590// Call
591def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
592 (JAL tglobaladdr:$dst)>;
593def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
594 (JAL texternalsym:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000595def : Pat<(MipsJmpLink CPURegs:$dst),
596 (JALR CPURegs:$dst)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000597
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000598// hi/lo relocs
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000599def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000600def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000601 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000602
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000603def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000604def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
605 (ADDiu CPURegs:$hi, tjumptable:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000606
607def : Pat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
608def : Pat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)),
609 (ADDiu CPURegs:$hi, tconstpool:$lo)>;
610
611// gp_rel relocs
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +0000612def : Pat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)),
613 (ADDiu CPURegs:$gp, tglobaladdr:$in)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000614def : Pat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)),
615 (ADDiu CPURegs:$gp, tconstpool:$in)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000616
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000617// Mips does not have "not", so we expand our way
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000618def : Pat<(not CPURegs:$in),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000619 (NOR CPURegs:$in, ZERO)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000620
Eric Christopher3c999a22007-10-26 04:00:13 +0000621// extended load and stores
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000622def : Pat<(extloadi1 addr:$src), (LBu addr:$src)>;
623def : Pat<(extloadi8 addr:$src), (LBu addr:$src)>;
624def : Pat<(extloadi16 addr:$src), (LHu addr:$src)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000625
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000626// peepholes
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000627def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
628
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000629// brcond patterns
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000630def : Pat<(brcond (setne CPURegs:$lhs, 0), bb:$dst),
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000631 (BNE CPURegs:$lhs, ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000632def : Pat<(brcond (seteq CPURegs:$lhs, 0), bb:$dst),
633 (BEQ CPURegs:$lhs, ZERO, bb:$dst)>;
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000634
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000635def : Pat<(brcond (setge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000636 (BEQ (SLT CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000637def : Pat<(brcond (setuge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000638 (BEQ (SLTu CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
639def : Pat<(brcond (setge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
640 (BEQ (SLTi CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
641def : Pat<(brcond (setuge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
642 (BEQ (SLTiu CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000643
644def : Pat<(brcond (setle CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000645 (BEQ (SLT CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000646def : Pat<(brcond (setule CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000647 (BEQ (SLTu CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000648
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000649def : Pat<(brcond CPURegs:$cond, bb:$dst),
650 (BNE CPURegs:$cond, ZERO, bb:$dst)>;
651
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000652// select patterns
653def : Pat<(select (setge CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
654 (MOVZ CPURegs:$F, CPURegs:$T, (SLT CPURegs:$lhs, CPURegs:$rhs))>;
655def : Pat<(select (setuge CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
656 (MOVZ CPURegs:$F, CPURegs:$T, (SLTu CPURegs:$lhs, CPURegs:$rhs))>;
657def : Pat<(select (setge CPURegs:$lhs, immSExt16:$rhs), CPURegs:$T, CPURegs:$F),
658 (MOVZ CPURegs:$F, CPURegs:$T, (SLTi CPURegs:$lhs, immSExt16:$rhs))>;
659def : Pat<(select (setuge CPURegs:$lh, immSExt16:$rh), CPURegs:$T, CPURegs:$F),
660 (MOVZ CPURegs:$F, CPURegs:$T, (SLTiu CPURegs:$lh, immSExt16:$rh))>;
661
662def : Pat<(select (setle CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
663 (MOVZ CPURegs:$F, CPURegs:$T, (SLT CPURegs:$rhs, CPURegs:$lhs))>;
664def : Pat<(select (setule CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
665 (MOVZ CPURegs:$F, CPURegs:$T, (SLTu CPURegs:$rhs, CPURegs:$lhs))>;
666
667def : Pat<(select (seteq CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
668 (MOVZ CPURegs:$F, CPURegs:$T, (XOR CPURegs:$lhs, CPURegs:$rhs))>;
669def : Pat<(select (setne CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
670 (MOVN CPURegs:$F, CPURegs:$T, (XOR CPURegs:$lhs, CPURegs:$rhs))>;
671
672def : Pat<(select CPURegs:$cond, CPURegs:$T, CPURegs:$F),
673 (MOVN CPURegs:$F, CPURegs:$T, CPURegs:$cond)>;
674
675// setcc patterns
676def : Pat<(seteq CPURegs:$lhs, CPURegs:$rhs),
677 (SLTu (XOR CPURegs:$lhs, CPURegs:$rhs), 1)>;
678def : Pat<(setne CPURegs:$lhs, CPURegs:$rhs),
679 (SLTu ZERO, (XOR CPURegs:$lhs, CPURegs:$rhs))>;
680
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000681def : Pat<(setle CPURegs:$lhs, CPURegs:$rhs),
682 (XORi (SLT CPURegs:$rhs, CPURegs:$lhs), 1)>;
683def : Pat<(setule CPURegs:$lhs, CPURegs:$rhs),
684 (XORi (SLTu CPURegs:$rhs, CPURegs:$lhs), 1)>;
685
686def : Pat<(setgt CPURegs:$lhs, CPURegs:$rhs),
687 (SLT CPURegs:$rhs, CPURegs:$lhs)>;
688def : Pat<(setugt CPURegs:$lhs, CPURegs:$rhs),
689 (SLTu CPURegs:$rhs, CPURegs:$lhs)>;
690
691def : Pat<(setge CPURegs:$lhs, CPURegs:$rhs),
692 (XORi (SLT CPURegs:$lhs, CPURegs:$rhs), 1)>;
693def : Pat<(setuge CPURegs:$lhs, CPURegs:$rhs),
694 (XORi (SLTu CPURegs:$lhs, CPURegs:$rhs), 1)>;
695
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000696def : Pat<(setge CPURegs:$lhs, immSExt16:$rhs),
697 (XORi (SLTi CPURegs:$lhs, immSExt16:$rhs), 1)>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000698def : Pat<(setuge CPURegs:$lhs, immSExt16:$rhs),
699 (XORi (SLTiu CPURegs:$lhs, immSExt16:$rhs), 1)>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000700
701//===----------------------------------------------------------------------===//
702// Floating Point Support
703//===----------------------------------------------------------------------===//
704
705include "MipsInstrFPU.td"
706