blob: e6ac6fbbf312173c2494843c5004cd22913d0a9b [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===- MipsInstrInfo.td - Mips Register defs --------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
8//===----------------------------------------------------------------------===//
9
10//===----------------------------------------------------------------------===//
11// Instruction format superclass
12//===----------------------------------------------------------------------===//
13
14include "MipsInstrFormats.td"
15
16//===----------------------------------------------------------------------===//
17// Mips profiles and nodes
18//===----------------------------------------------------------------------===//
19
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +000020def SDT_MipsRet : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
21def SDT_MipsJmpLink : SDTypeProfile<0, 1, [SDTCisVT<0, iPTR>]>;
Bruno Cardoso Lopesda54c7d2008-07-29 19:05:28 +000022def SDT_MipsSelectCC : SDTypeProfile<1, 3, [SDTCisSameAs<0, 2>,
23 SDTCisSameAs<2, 3>, SDTCisInt<1>]>;
Bruno Cardoso Lopes60f3e052008-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 Lopes4fb1f542008-07-05 19:05:21 +000027def SDT_MipsCallSeqStart : SDCallSeqStart<[SDTCisVT<0, i32>]>;
28def SDT_MipsCallSeqEnd : SDCallSeqEnd<[SDTCisVT<0, i32>, SDTCisVT<1, i32>]>;
29
Dan Gohmanf17a25c2007-07-18 16:29:46 +000030// Call
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +000031def MipsJmpLink : SDNode<"MipsISD::JmpLink",SDT_MipsJmpLink, [SDNPHasChain,
32 SDNPOutFlag]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000033
Bruno Cardoso Lopes218d5822007-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 Lopes12355a82008-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 Lopes2cacce92007-10-09 02:55:31 +000040
Eric Christopher7300ac12007-10-26 04:00:13 +000041// Return
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +000042def MipsRet : SDNode<"MipsISD::Ret", SDT_MipsRet, [SDNPHasChain,
43 SDNPOptInFlag]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000044
45// These are target-independent nodes, but have target-specific formats.
Bruno Cardoso Lopes4fb1f542008-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 Wendling22f8deb2007-11-13 00:44:25 +000050
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +000051// Select Condition Code
52def MipsSelectCC : SDNode<"MipsISD::SelectCC", SDT_MipsSelectCC>;
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +000053
Bruno Cardoso Lopes60f3e052008-08-13 07:13:40 +000054// Conditional Move
55def MipsCMov : SDNode<"MipsISD::CMov", SDT_MipsCMov>;
56
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +000057//===----------------------------------------------------------------------===//
58// Mips Instruction Predicate Definitions.
59//===----------------------------------------------------------------------===//
Bruno Cardoso Lopesea4fc382008-08-08 06:16:31 +000060def HasSEInReg : Predicate<"Subtarget.hasSEInReg()">;
61def HasBitCount : Predicate<"Subtarget.hasBitCount()">;
Bruno Cardoso Lopes60f3e052008-08-13 07:13:40 +000062def HasSwap : Predicate<"Subtarget.hasSwap()">;
63def HasCondMov : Predicate<"Subtarget.hasCondMov()">;
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +000064
65//===----------------------------------------------------------------------===//
66// Mips Operand, Complex Patterns and Transformations Definitions.
67//===----------------------------------------------------------------------===//
68
Dan Gohmanf17a25c2007-07-18 16:29:46 +000069// Instruction operand types
70def brtarget : Operand<OtherVT>;
71def calltarget : Operand<i32>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000072def simm16 : Operand<i32>;
Eric Christopher7300ac12007-10-26 04:00:13 +000073def shamt : Operand<i32>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000074
Bruno Cardoso Lopes60f3e052008-08-13 07:13:40 +000075// Unsigned Operand
76def uimm16 : Operand<i32> {
77 let PrintMethod = "printUnsignedImm";
78}
79
Dan Gohmanf17a25c2007-07-18 16:29:46 +000080// Address operand
81def mem : Operand<i32> {
82 let PrintMethod = "printMemOperand";
83 let MIOperandInfo = (ops simm16, CPURegs);
84}
85
Dan Gohmanf17a25c2007-07-18 16:29:46 +000086// Transformation Function - get the lower 16 bits.
87def LO16 : SDNodeXForm<imm, [{
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000088 return getI32Imm((unsigned)N->getZExtValue() & 0xFFFF);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000089}]>;
90
91// Transformation Function - get the higher 16 bits.
92def HI16 : SDNodeXForm<imm, [{
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000093 return getI32Imm((unsigned)N->getZExtValue() >> 16);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000094}]>;
95
96// Node immediate fits as 16-bit sign extended on target immediate.
97// e.g. addi, andi
98def immSExt16 : PatLeaf<(imm), [{
99 if (N->getValueType(0) == MVT::i32)
Dan Gohmanfaeb4a32008-09-12 16:56:44 +0000100 return (int32_t)N->getZExtValue() == (short)N->getZExtValue();
Eric Christopher7300ac12007-10-26 04:00:13 +0000101 else
Dan Gohmanfaeb4a32008-09-12 16:56:44 +0000102 return (int64_t)N->getZExtValue() == (short)N->getZExtValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +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), [{
110 if (N->getValueType(0) == MVT::i32)
Dan Gohmanfaeb4a32008-09-12 16:56:44 +0000111 return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Eric Christopher7300ac12007-10-26 04:00:13 +0000112 else
Dan Gohmanfaeb4a32008-09-12 16:56:44 +0000113 return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000114}], LO16>;
115
116// shamt field must fit in 5 bits.
117def immZExt5 : PatLeaf<(imm), [{
Dan Gohmanfaeb4a32008-09-12 16:56:44 +0000118 return N->getZExtValue() == ((N->getZExtValue()) & 0x1f) ;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000119}]>;
120
Eric Christopher7300ac12007-10-26 04:00:13 +0000121// Mips Address Mode! SDNode frameindex could possibily be a match
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000122// since load and store instructions from stack used it.
123def addr : ComplexPattern<i32, 2, "SelectAddr", [frameindex], []>;
124
125//===----------------------------------------------------------------------===//
126// Instructions specific format
127//===----------------------------------------------------------------------===//
128
129// Arithmetic 3 register operands
Eric Christopher7300ac12007-10-26 04:00:13 +0000130let isCommutable = 1 in
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000131class ArithR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
Eric Christopher7300ac12007-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 Lopes29c15352008-07-14 14:42:54 +0000137 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000138 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], itin>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000139
Eric Christopher7300ac12007-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 Lopes29c15352008-07-14 14:42:54 +0000146 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000147 [], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000148
149// Arithmetic 2 register operands
Eric Christopher7300ac12007-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 Lopes29c15352008-07-14 14:42:54 +0000155 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000156 [(set CPURegs:$dst, (OpNode CPURegs:$b, imm_type:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000157
Bruno Cardoso Lopes60f3e052008-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
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000166// Arithmetic Multiply ADD/SUB
167let rd=0 in
Eric Christopher7300ac12007-10-26 04:00:13 +0000168class MArithR<bits<6> func, string instr_asm> :
169 FR< 0x1c,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000170 func,
Eric Christopher7300ac12007-10-26 04:00:13 +0000171 (outs CPURegs:$rs),
172 (ins CPURegs:$rt),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000173 !strconcat(instr_asm, "\t$rs, $rt"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000174 [], IIImul>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000175
176// Logical
177class LogicR<bits<6> func, string instr_asm, SDNode OpNode>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000178 FR< 0x00,
179 func,
180 (outs CPURegs:$dst),
181 (ins CPURegs:$b, CPURegs:$c),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000182 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000183 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000184
185class LogicI<bits<6> op, string instr_asm, SDNode OpNode>:
186 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000187 (outs CPURegs:$dst),
188 (ins CPURegs:$b, uimm16:$c),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000189 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopesf2377552008-06-06 06:37:31 +0000190 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt16:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000191
192class LogicNOR<bits<6> op, bits<6> func, string instr_asm>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000193 FR< op,
194 func,
195 (outs CPURegs:$dst),
196 (ins CPURegs:$b, CPURegs:$c),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000197 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000198 [(set CPURegs:$dst, (not (or CPURegs:$b, CPURegs:$c)))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000199
200// Shifts
201let rt = 0 in
202class LogicR_shift_imm<bits<6> func, string instr_asm, SDNode OpNode>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000203 FR< 0x00,
204 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000205 (outs CPURegs:$dst),
206 (ins CPURegs:$b, shamt:$c),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000207 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000208 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt5:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000209
210class LogicR_shift_reg<bits<6> func, string instr_asm, SDNode OpNode>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000211 FR< 0x00,
212 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000213 (outs CPURegs:$dst),
214 (ins CPURegs:$b, CPURegs:$c),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000215 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000216 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000217
218// Load Upper Imediate
219class LoadUpper<bits<6> op, string instr_asm>:
220 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000221 (outs CPURegs:$dst),
222 (ins uimm16:$imm),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000223 !strconcat(instr_asm, "\t$dst, $imm"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000224 [], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000225
Eric Christopher7300ac12007-10-26 04:00:13 +0000226// Memory Load/Store
Chris Lattner1a1932c2008-01-06 23:38:27 +0000227let isSimpleLoad = 1, hasDelaySlot = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000228class LoadM<bits<6> op, string instr_asm, PatFrag OpNode>:
229 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000230 (outs CPURegs:$dst),
231 (ins mem:$addr),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000232 !strconcat(instr_asm, "\t$dst, $addr"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000233 [(set CPURegs:$dst, (OpNode addr:$addr))], IILoad>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000234
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000235class StoreM<bits<6> op, string instr_asm, PatFrag OpNode>:
236 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000237 (outs),
238 (ins CPURegs:$dst, mem:$addr),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000239 !strconcat(instr_asm, "\t$dst, $addr"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000240 [(OpNode CPURegs:$dst, addr:$addr)], IIStore>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000241
242// Conditional Branch
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000243let isBranch = 1, isTerminator=1, hasDelaySlot = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000244class CBranch<bits<6> op, string instr_asm, PatFrag cond_op>:
245 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000246 (outs),
247 (ins CPURegs:$a, CPURegs:$b, brtarget:$offset),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000248 !strconcat(instr_asm, "\t$a, $b, $offset"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000249 [(brcond (cond_op CPURegs:$a, CPURegs:$b), bb:$offset)],
250 IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000251
Bruno Cardoso Lopes34190552007-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 Lopes29c15352008-07-14 14:42:54 +0000257 !strconcat(instr_asm, "\t$src, $offset"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000258 [(brcond (cond_op CPURegs:$src, 0), bb:$offset)],
259 IIBranch>;
Eric Christopher7300ac12007-10-26 04:00:13 +0000260}
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000261
Eric Christopher7300ac12007-10-26 04:00:13 +0000262// SetCC
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000263class SetCC_R<bits<6> op, bits<6> func, string instr_asm,
264 PatFrag cond_op>:
265 FR< op,
266 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000267 (outs CPURegs:$dst),
268 (ins CPURegs:$b, CPURegs:$c),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000269 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000270 [(set CPURegs:$dst, (cond_op CPURegs:$b, CPURegs:$c))],
271 IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000272
273class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op,
274 Operand Od, PatLeaf imm_type>:
275 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000276 (outs CPURegs:$dst),
277 (ins CPURegs:$b, Od:$c),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000278 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000279 [(set CPURegs:$dst, (cond_op CPURegs:$b, imm_type:$c))],
280 IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000281
282// Unconditional branch
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000283let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000284class JumpFJ<bits<6> op, string instr_asm>:
285 FJ< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000286 (outs),
287 (ins brtarget:$target),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000288 !strconcat(instr_asm, "\t$target"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000289 [(br bb:$target)], IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000290
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000291let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000292class JumpFR<bits<6> op, bits<6> func, string instr_asm>:
293 FR< op,
294 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000295 (outs),
296 (ins CPURegs:$target),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000297 !strconcat(instr_asm, "\t$target"),
Bruno Cardoso Lopesea377302007-11-12 19:49:57 +0000298 [(brind CPURegs:$target)], IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000299
300// Jump and Link (Call)
Eric Christopher7300ac12007-10-26 04:00:13 +0000301let isCall=1, hasDelaySlot=1,
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000302 // All calls clobber the non-callee saved registers...
Bruno Cardoso Lopesf046f872008-08-06 06:14:43 +0000303 Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9,
304 K0, K1, F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13,
305 F14, F15, F16, F17, F18, F19], Uses = [GP] in {
Eric Christopher7300ac12007-10-26 04:00:13 +0000306 class JumpLink<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000307 FJ< op,
308 (outs),
309 (ins calltarget:$target),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000310 !strconcat(instr_asm, "\t$target"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000311 [(MipsJmpLink imm:$target)], IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000312
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000313 let rd=31 in
314 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
315 FR< op,
316 func,
317 (outs),
318 (ins CPURegs:$rs),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000319 !strconcat(instr_asm, "\t$rs"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000320 [(MipsJmpLink CPURegs:$rs)], IIBranch>;
321
322 class BranchLink<string instr_asm>:
323 FI< 0x1,
324 (outs),
325 (ins CPURegs:$rs, brtarget:$target),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000326 !strconcat(instr_asm, "\t$rs, $target"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000327 [], IIBranch>;
328}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000329
Eric Christopher7300ac12007-10-26 04:00:13 +0000330// Mul, Div
331class MulDiv<bits<6> func, string instr_asm, InstrItinClass itin>:
332 FR< 0x00,
333 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000334 (outs),
Eric Christopher7300ac12007-10-26 04:00:13 +0000335 (ins CPURegs:$a, CPURegs:$b),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000336 !strconcat(instr_asm, "\t$a, $b"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000337 [], itin>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000338
Eric Christopher7300ac12007-10-26 04:00:13 +0000339// Move from Hi/Lo
Bruno Cardoso Lopes4f0bb3c2008-08-02 19:42:36 +0000340class MoveFromLOHI<bits<6> func, string instr_asm>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000341 FR< 0x00,
342 func,
343 (outs CPURegs:$dst),
Evan Chengb783fa32007-07-19 01:14:50 +0000344 (ins),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000345 !strconcat(instr_asm, "\t$dst"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000346 [], IIHiLo>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000347
Bruno Cardoso Lopes4f0bb3c2008-08-02 19:42:36 +0000348class MoveToLOHI<bits<6> func, string instr_asm>:
349 FR< 0x00,
350 func,
351 (outs),
352 (ins CPURegs:$src),
353 !strconcat(instr_asm, "\t$src"),
354 [], IIHiLo>;
355
Eric Christopher7300ac12007-10-26 04:00:13 +0000356class EffectiveAddress<string instr_asm> :
357 FI<0x09,
358 (outs CPURegs:$dst),
Bruno Cardoso Lopes96433662007-09-24 20:15:11 +0000359 (ins mem:$addr),
360 instr_asm,
361 [(set CPURegs:$dst, addr:$addr)], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000362
Bruno Cardoso Lopesea4fc382008-08-08 06:16:31 +0000363// Count Leading Ones/Zeros in Word
364class CountLeading<bits<6> func, string instr_asm, SDNode CountOp>:
365 FR< 0x1c, func, (outs CPURegs:$dst), (ins CPURegs:$src),
366 !strconcat(instr_asm, "\t$dst, $src"),
367 [(set CPURegs:$dst, (CountOp CPURegs:$src))], IIAlu>;
368
369// Sign Extend in Register.
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000370class SignExtInReg<bits<6> func, string instr_asm, ValueType vt>:
371 FR< 0x3f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000372 !strconcat(instr_asm, "\t$dst, $src"),
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000373 [(set CPURegs:$dst, (sext_inreg CPURegs:$src, vt))], NoItinerary>;
374
Bruno Cardoso Lopes60f3e052008-08-13 07:13:40 +0000375// Byte Swap
376class ByteSwap<bits<6> func, string instr_asm>:
377 FR< 0x1f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
378 !strconcat(instr_asm, "\t$dst, $src"),
379 [(set CPURegs:$dst, (bswap CPURegs:$src))], NoItinerary>;
380
381// Conditional Move
382class CondMov<bits<6> func, string instr_asm, PatLeaf MovCode>:
383 FR< 0x00, func, (outs CPURegs:$dst), (ins CPURegs:$F, CPURegs:$T,
384 CPURegs:$cond), !strconcat(instr_asm, "\t$dst, $T, $cond"),
385 [(set CPURegs:$dst, (MipsCMov CPURegs:$F, CPURegs:$T,
386 CPURegs:$cond, MovCode))], NoItinerary>;
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000387
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000388//===----------------------------------------------------------------------===//
389// Pseudo instructions
390//===----------------------------------------------------------------------===//
391
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000392// As stack alignment is always done with addiu, we need a 16-bit immediate
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000393let Defs = [SP], Uses = [SP] in {
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +0000394def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000395 "!ADJCALLSTACKDOWN $amt",
Chris Lattnerfe5d4022008-10-11 22:08:30 +0000396 [(callseq_start timm:$amt)]>;
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +0000397def ADJCALLSTACKUP : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000398 "!ADJCALLSTACKUP $amt1",
Chris Lattnerfe5d4022008-10-11 22:08:30 +0000399 [(callseq_end timm:$amt1, timm:$amt2)]>;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000400}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000401
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000402// Some assembly macros need to avoid pseudoinstructions and assembler
403// automatic reodering, we should reorder ourselves.
404def MACRO : MipsPseudo<(outs), (ins), ".set\tmacro", []>;
405def REORDER : MipsPseudo<(outs), (ins), ".set\treorder", []>;
406def NOMACRO : MipsPseudo<(outs), (ins), ".set\tnomacro", []>;
407def NOREORDER : MipsPseudo<(outs), (ins), ".set\tnoreorder", []>;
408
Eric Christopher7300ac12007-10-26 04:00:13 +0000409// When handling PIC code the assembler needs .cpload and .cprestore
410// directives. If the real instructions corresponding these directives
411// are used, we have the same behavior, but get also a bunch of warnings
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +0000412// from the assembler.
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000413def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$picreg), ".cpload\t$picreg", []>;
414def CPRESTORE : MipsPseudo<(outs), (ins uimm16:$loc), ".cprestore\t$loc\n", []>;
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +0000415
416// The supported Mips ISAs dont have any instruction close to the SELECT_CC
417// operation. The solution is to create a Mips pseudo SELECT_CC instruction
418// (MipsSelectCC), use LowerSELECT_CC to generate this instruction and finally
419// replace it for real supported nodes into EmitInstrWithCustomInserter
420let usesCustomDAGSchedInserter = 1 in {
Bruno Cardoso Lopesda54c7d2008-07-29 19:05:28 +0000421 class PseudoSelCC<RegisterClass RC, string asmstr>:
422 MipsPseudo<(outs RC:$dst), (ins CPURegs:$CmpRes, RC:$T, RC:$F), asmstr,
423 [(set RC:$dst, (MipsSelectCC CPURegs:$CmpRes, RC:$T, RC:$F))]>;
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +0000424}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000425
Bruno Cardoso Lopesda54c7d2008-07-29 19:05:28 +0000426def Select_CC : PseudoSelCC<CPURegs, "# MipsSelect_CC_i32">;
427
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000428//===----------------------------------------------------------------------===//
429// Instruction definition
430//===----------------------------------------------------------------------===//
431
432//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000433// MipsI Instructions
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000434//===----------------------------------------------------------------------===//
435
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000436/// Arithmetic Instructions (ALU Immediate)
Bruno Cardoso Lopes60f3e052008-08-13 07:13:40 +0000437def ADDiu : ArithI<0x09, "addiu", add, simm16, immSExt16>;
438def ADDi : ArithOverflowI<0x08, "addi", add, simm16, immSExt16>;
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000439def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16>;
Bruno Cardoso Lopes60f3e052008-08-13 07:13:40 +0000440def SLTiu : SetCC_I<0x0b, "sltiu", setult, simm16, immSExt16>;
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000441def ANDi : LogicI<0x0c, "andi", and>;
442def ORi : LogicI<0x0d, "ori", or>;
443def XORi : LogicI<0x0e, "xori", xor>;
444def LUi : LoadUpper<0x0f, "lui">;
445
446/// Arithmetic Instructions (3-Operand, R-Type)
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000447def ADDu : ArithR<0x00, 0x21, "addu", add, IIAlu>;
448def SUBu : ArithR<0x00, 0x23, "subu", sub, IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000449def ADD : ArithOverflowR<0x00, 0x20, "add">;
450def SUB : ArithOverflowR<0x00, 0x22, "sub">;
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000451def SLT : SetCC_R<0x00, 0x2a, "slt", setlt>;
452def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000453def AND : LogicR<0x24, "and", and>;
454def OR : LogicR<0x25, "or", or>;
455def XOR : LogicR<0x26, "xor", xor>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000456def NOR : LogicNOR<0x00, 0x27, "nor">;
457
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000458/// Shift Instructions
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000459def SLL : LogicR_shift_imm<0x00, "sll", shl>;
460def SRL : LogicR_shift_imm<0x02, "srl", srl>;
461def SRA : LogicR_shift_imm<0x03, "sra", sra>;
462def SLLV : LogicR_shift_reg<0x04, "sllv", shl>;
463def SRLV : LogicR_shift_reg<0x06, "srlv", srl>;
464def SRAV : LogicR_shift_reg<0x07, "srav", sra>;
465
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000466/// Load and Store Instructions
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000467def LB : LoadM<0x20, "lb", sextloadi8>;
468def LBu : LoadM<0x24, "lbu", zextloadi8>;
469def LH : LoadM<0x21, "lh", sextloadi16>;
470def LHu : LoadM<0x25, "lhu", zextloadi16>;
471def LW : LoadM<0x23, "lw", load>;
472def SB : StoreM<0x28, "sb", truncstorei8>;
473def SH : StoreM<0x29, "sh", truncstorei16>;
474def SW : StoreM<0x2b, "sw", store>;
475
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000476/// Jump and Branch Instructions
477def J : JumpFJ<0x02, "j">;
478def JR : JumpFR<0x00, 0x08, "jr">;
479def JAL : JumpLink<0x03, "jal">;
480def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000481def BEQ : CBranch<0x04, "beq", seteq>;
482def BNE : CBranch<0x05, "bne", setne>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000483
Eric Christopher7300ac12007-10-26 04:00:13 +0000484let rt=1 in
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000485 def BGEZ : CBranchZero<0x01, "bgez", setge>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000486
487let rt=0 in {
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000488 def BGTZ : CBranchZero<0x07, "bgtz", setgt>;
489 def BLEZ : CBranchZero<0x07, "blez", setle>;
490 def BLTZ : CBranchZero<0x01, "bltz", setlt>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000491}
492
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000493def BGEZAL : BranchLink<"bgezal">;
494def BLTZAL : BranchLink<"bltzal">;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000495
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000496let isReturn=1, isTerminator=1, hasDelaySlot=1,
497 isBarrier=1, hasCtrlDep=1, rs=0, rt=0, shamt=0 in
498 def RET : FR <0x00, 0x02, (outs), (ins CPURegs:$target),
499 "jr\t$target", [(MipsRet CPURegs:$target)], IIBranch>;
500
501/// Multiply and Divide Instructions.
Bruno Cardoso Lopes4f0bb3c2008-08-02 19:42:36 +0000502let Defs = [HI, LO] in {
503 def MULT : MulDiv<0x18, "mult", IIImul>;
504 def MULTu : MulDiv<0x19, "multu", IIImul>;
505 def DIV : MulDiv<0x1a, "div", IIIdiv>;
506 def DIVu : MulDiv<0x1b, "divu", IIIdiv>;
507}
508
509let Defs = [HI] in
510 def MTHI : MoveToLOHI<0x11, "mthi">;
511let Defs = [LO] in
512 def MTLO : MoveToLOHI<0x13, "mtlo">;
513
514let Uses = [HI] in
515 def MFHI : MoveFromLOHI<0x10, "mfhi">;
516let Uses = [LO] in
517 def MFLO : MoveFromLOHI<0x12, "mflo">;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000518
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000519/// Sign Ext In Register Instructions.
520let Predicates = [HasSEInReg] in {
521 let shamt = 0x10, rs = 0 in
522 def SEB : SignExtInReg<0x21, "seb", i8>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000523
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000524 let shamt = 0x18, rs = 0 in
525 def SEH : SignExtInReg<0x20, "seh", i16>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000526}
527
Bruno Cardoso Lopesea4fc382008-08-08 06:16:31 +0000528/// Count Leading
529let Predicates = [HasBitCount] in {
Bruno Cardoso Lopes60f3e052008-08-13 07:13:40 +0000530 let rt = 0 in
531 def CLZ : CountLeading<0b010110, "clz", ctlz>;
532}
533
534/// Byte Swap
535let Predicates = [HasSwap] in {
536 let shamt = 0x3, rs = 0 in
537 def WSBW : ByteSwap<0x20, "wsbw">;
538}
539
540/// Conditional Move
541def MIPS_CMOV_ZERO : PatLeaf<(i32 0)>;
542def MIPS_CMOV_NZERO : PatLeaf<(i32 1)>;
543
544let Predicates = [HasCondMov], isTwoAddress = 1 in {
545 def MOVN : CondMov<0x0a, "movn", MIPS_CMOV_NZERO>;
546 def MOVZ : CondMov<0x0b, "movz", MIPS_CMOV_ZERO>;
Bruno Cardoso Lopesea4fc382008-08-08 06:16:31 +0000547}
548
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000549/// No operation
550let addr=0 in
551 def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
552
Eric Christopher7300ac12007-10-26 04:00:13 +0000553// FrameIndexes are legalized when they are operands from load/store
Bruno Cardoso Lopes96433662007-09-24 20:15:11 +0000554// instructions. The same not happens for stack address copies, so an
555// add op with mem ComplexPattern is used and the stack address copy
556// can be matched. It's similar to Sparc LEA_ADDRi
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000557def LEA_ADDiu : EffectiveAddress<"addiu\t$dst, ${addr:stackloc}">;
Bruno Cardoso Lopes96433662007-09-24 20:15:11 +0000558
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000559// MADD*/MSUB* are not part of MipsI either.
560//def MADD : MArithR<0x00, "madd">;
561//def MADDU : MArithR<0x01, "maddu">;
562//def MSUB : MArithR<0x04, "msub">;
563//def MSUBU : MArithR<0x05, "msubu">;
564
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000565// MUL is a assembly macro in the current used ISAs. In recent ISA's
566// it is a real instruction.
567//def MUL : ArithR<0x1c, 0x02, "mul", mul, IIImul>;
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000568
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000569//===----------------------------------------------------------------------===//
570// Arbitrary patterns that map to one or more instructions
571//===----------------------------------------------------------------------===//
572
573// Small immediates
Eric Christopher7300ac12007-10-26 04:00:13 +0000574def : Pat<(i32 immSExt16:$in),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000575 (ADDiu ZERO, imm:$in)>;
Eric Christopher7300ac12007-10-26 04:00:13 +0000576def : Pat<(i32 immZExt16:$in),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000577 (ORi ZERO, imm:$in)>;
578
579// Arbitrary immediates
580def : Pat<(i32 imm:$imm),
581 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
582
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +0000583// Carry patterns
584def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
585 (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
586def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
587 (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
588def : Pat<(addc CPURegs:$src, imm:$imm),
589 (ADDiu CPURegs:$src, imm:$imm)>;
590
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000591// Call
592def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
593 (JAL tglobaladdr:$dst)>;
594def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
595 (JAL texternalsym:$dst)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000596def : Pat<(MipsJmpLink CPURegs:$dst),
597 (JALR CPURegs:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000598
Bruno Cardoso Lopes69ca2ca2008-07-23 16:01:50 +0000599// hi/lo relocs
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000600def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
Bruno Cardoso Lopes218d5822007-11-05 03:02:32 +0000601def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000602 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
Bruno Cardoso Lopes69ca2ca2008-07-23 16:01:50 +0000603
Bruno Cardoso Lopesea377302007-11-12 19:49:57 +0000604def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
Bruno Cardoso Lopesea377302007-11-12 19:49:57 +0000605def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
606 (ADDiu CPURegs:$hi, tjumptable:$lo)>;
Bruno Cardoso Lopes69ca2ca2008-07-23 16:01:50 +0000607
608def : Pat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
609def : Pat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)),
610 (ADDiu CPURegs:$hi, tconstpool:$lo)>;
611
612// gp_rel relocs
Bruno Cardoso Lopes12355a82008-07-21 18:52:34 +0000613def : Pat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)),
614 (ADDiu CPURegs:$gp, tglobaladdr:$in)>;
Bruno Cardoso Lopes69ca2ca2008-07-23 16:01:50 +0000615def : Pat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)),
616 (ADDiu CPURegs:$gp, tconstpool:$in)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000617
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000618// Mips does not have "not", so we expand our way
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000619def : Pat<(not CPURegs:$in),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000620 (NOR CPURegs:$in, ZERO)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000621
Eric Christopher7300ac12007-10-26 04:00:13 +0000622// extended load and stores
Bruno Cardoso Lopes60f3e052008-08-13 07:13:40 +0000623def : Pat<(extloadi1 addr:$src), (LBu addr:$src)>;
624def : Pat<(extloadi8 addr:$src), (LBu addr:$src)>;
625def : Pat<(extloadi16 addr:$src), (LHu addr:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000626
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +0000627// peepholes
Bruno Cardoso Lopes218d5822007-11-05 03:02:32 +0000628def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
629
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000630// brcond patterns
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000631def : Pat<(brcond (setne CPURegs:$lhs, 0), bb:$dst),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000632 (BNE CPURegs:$lhs, ZERO, bb:$dst)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000633def : Pat<(brcond (seteq CPURegs:$lhs, 0), bb:$dst),
634 (BEQ CPURegs:$lhs, ZERO, bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000635
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000636def : Pat<(brcond (setge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes60f3e052008-08-13 07:13:40 +0000637 (BEQ (SLT CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000638def : Pat<(brcond (setuge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes60f3e052008-08-13 07:13:40 +0000639 (BEQ (SLTu CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
640def : Pat<(brcond (setge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
641 (BEQ (SLTi CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
642def : Pat<(brcond (setuge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
643 (BEQ (SLTiu CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000644
645def : Pat<(brcond (setle CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes60f3e052008-08-13 07:13:40 +0000646 (BEQ (SLT CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000647def : Pat<(brcond (setule CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes60f3e052008-08-13 07:13:40 +0000648 (BEQ (SLTu CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000649
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000650def : Pat<(brcond CPURegs:$cond, bb:$dst),
651 (BNE CPURegs:$cond, ZERO, bb:$dst)>;
652
Bruno Cardoso Lopes60f3e052008-08-13 07:13:40 +0000653// select patterns
654def : Pat<(select (setge CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
655 (MOVZ CPURegs:$F, CPURegs:$T, (SLT CPURegs:$lhs, CPURegs:$rhs))>;
656def : Pat<(select (setuge CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
657 (MOVZ CPURegs:$F, CPURegs:$T, (SLTu CPURegs:$lhs, CPURegs:$rhs))>;
658def : Pat<(select (setge CPURegs:$lhs, immSExt16:$rhs), CPURegs:$T, CPURegs:$F),
659 (MOVZ CPURegs:$F, CPURegs:$T, (SLTi CPURegs:$lhs, immSExt16:$rhs))>;
660def : Pat<(select (setuge CPURegs:$lh, immSExt16:$rh), CPURegs:$T, CPURegs:$F),
661 (MOVZ CPURegs:$F, CPURegs:$T, (SLTiu CPURegs:$lh, immSExt16:$rh))>;
662
663def : Pat<(select (setle CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
664 (MOVZ CPURegs:$F, CPURegs:$T, (SLT CPURegs:$rhs, CPURegs:$lhs))>;
665def : Pat<(select (setule CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
666 (MOVZ CPURegs:$F, CPURegs:$T, (SLTu CPURegs:$rhs, CPURegs:$lhs))>;
667
668def : Pat<(select (seteq CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
669 (MOVZ CPURegs:$F, CPURegs:$T, (XOR CPURegs:$lhs, CPURegs:$rhs))>;
670def : Pat<(select (setne CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
671 (MOVN CPURegs:$F, CPURegs:$T, (XOR CPURegs:$lhs, CPURegs:$rhs))>;
672
673def : Pat<(select CPURegs:$cond, CPURegs:$T, CPURegs:$F),
674 (MOVN CPURegs:$F, CPURegs:$T, CPURegs:$cond)>;
675
676// setcc patterns
677def : Pat<(seteq CPURegs:$lhs, CPURegs:$rhs),
678 (SLTu (XOR CPURegs:$lhs, CPURegs:$rhs), 1)>;
679def : Pat<(setne CPURegs:$lhs, CPURegs:$rhs),
680 (SLTu ZERO, (XOR CPURegs:$lhs, CPURegs:$rhs))>;
681
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000682def : Pat<(setle CPURegs:$lhs, CPURegs:$rhs),
683 (XORi (SLT CPURegs:$rhs, CPURegs:$lhs), 1)>;
684def : Pat<(setule CPURegs:$lhs, CPURegs:$rhs),
685 (XORi (SLTu CPURegs:$rhs, CPURegs:$lhs), 1)>;
686
687def : Pat<(setgt CPURegs:$lhs, CPURegs:$rhs),
688 (SLT CPURegs:$rhs, CPURegs:$lhs)>;
689def : Pat<(setugt CPURegs:$lhs, CPURegs:$rhs),
690 (SLTu CPURegs:$rhs, CPURegs:$lhs)>;
691
692def : Pat<(setge CPURegs:$lhs, CPURegs:$rhs),
693 (XORi (SLT CPURegs:$lhs, CPURegs:$rhs), 1)>;
694def : Pat<(setuge CPURegs:$lhs, CPURegs:$rhs),
695 (XORi (SLTu CPURegs:$lhs, CPURegs:$rhs), 1)>;
696
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000697def : Pat<(setge CPURegs:$lhs, immSExt16:$rhs),
698 (XORi (SLTi CPURegs:$lhs, immSExt16:$rhs), 1)>;
Bruno Cardoso Lopes60f3e052008-08-13 07:13:40 +0000699def : Pat<(setuge CPURegs:$lhs, immSExt16:$rhs),
700 (XORi (SLTiu CPURegs:$lhs, immSExt16:$rhs), 1)>;
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000701
702//===----------------------------------------------------------------------===//
703// Floating Point Support
704//===----------------------------------------------------------------------===//
705
706include "MipsInstrFPU.td"
707