blob: c14dc9cd0136388c3d37cc1d0273b31745279060 [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_MipsCMov : SDTypeProfile<1, 4, [SDTCisSameAs<0, 1>,
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +000023 SDTCisSameAs<1, 2>, SDTCisSameAs<3, 4>,
24 SDTCisInt<4>]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000025def SDT_MipsCallSeqStart : SDCallSeqStart<[SDTCisVT<0, i32>]>;
26def SDT_MipsCallSeqEnd : SDCallSeqEnd<[SDTCisVT<0, i32>, SDTCisVT<1, i32>]>;
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +000027def SDT_MipsMAddMSub : SDTypeProfile<0, 4,
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +000028 [SDTCisVT<0, i32>, SDTCisSameAs<0, 1>,
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +000029 SDTCisSameAs<1, 2>,
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +000030 SDTCisSameAs<2, 3>]>;
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +000031def SDT_MipsDivRem : SDTypeProfile<0, 2,
32 [SDTCisVT<0, i32>,
33 SDTCisSameAs<0, 1>]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000034
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000035// Call
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000036def MipsJmpLink : SDNode<"MipsISD::JmpLink",SDT_MipsJmpLink,
Chris Lattner036609b2010-12-23 18:28:41 +000037 [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue,
Chris Lattner60e9eac2010-03-19 05:33:51 +000038 SDNPVariadic]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000039
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000040// Hi and Lo nodes are used to handle global addresses. Used on
41// MipsISelLowering to lower stuff like GlobalAddress, ExternalSymbol
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +000042// static model. (nothing to do with Mips Registers Hi and Lo)
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +000043def MipsHi : SDNode<"MipsISD::Hi", SDTIntUnaryOp>;
44def MipsLo : SDNode<"MipsISD::Lo", SDTIntUnaryOp>;
45def MipsGPRel : SDNode<"MipsISD::GPRel", SDTIntUnaryOp>;
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +000046
Eric Christopher3c999a22007-10-26 04:00:13 +000047// Return
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000048def MipsRet : SDNode<"MipsISD::Ret", SDT_MipsRet, [SDNPHasChain,
Chris Lattner036609b2010-12-23 18:28:41 +000049 SDNPOptInGlue]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000050
51// These are target-independent nodes, but have target-specific formats.
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000052def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_MipsCallSeqStart,
Chris Lattner036609b2010-12-23 18:28:41 +000053 [SDNPHasChain, SDNPOutGlue]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000054def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_MipsCallSeqEnd,
Chris Lattner036609b2010-12-23 18:28:41 +000055 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
Bill Wendling0f8d9c02007-11-13 00:44:25 +000056
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +000057// MAdd*/MSub* nodes
58def MipsMAdd : SDNode<"MipsISD::MAdd", SDT_MipsMAddMSub,
59 [SDNPOptInGlue, SDNPOutGlue]>;
60def MipsMAddu : SDNode<"MipsISD::MAddu", SDT_MipsMAddMSub,
61 [SDNPOptInGlue, SDNPOutGlue]>;
62def MipsMSub : SDNode<"MipsISD::MSub", SDT_MipsMAddMSub,
63 [SDNPOptInGlue, SDNPOutGlue]>;
64def MipsMSubu : SDNode<"MipsISD::MSubu", SDT_MipsMAddMSub,
65 [SDNPOptInGlue, SDNPOutGlue]>;
66
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +000067// DivRem(u) nodes
68def MipsDivRem : SDNode<"MipsISD::DivRem", SDT_MipsDivRem,
69 [SDNPOutGlue]>;
70def MipsDivRemU : SDNode<"MipsISD::DivRemU", SDT_MipsDivRem,
71 [SDNPOutGlue]>;
72
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +000073//===----------------------------------------------------------------------===//
74// Mips Instruction Predicate Definitions.
75//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +000076def HasSEInReg : Predicate<"Subtarget.hasSEInReg()">;
77def HasBitCount : Predicate<"Subtarget.hasBitCount()">;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +000078def HasSwap : Predicate<"Subtarget.hasSwap()">;
79def HasCondMov : Predicate<"Subtarget.hasCondMov()">;
Bruno Cardoso Lopes7d5652d2010-11-12 00:38:32 +000080def IsMips32 : Predicate<"Subtarget.isMips32()">;
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +000081def IsMips32r2 : Predicate<"Subtarget.isMips32r2()">;
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +000082
83//===----------------------------------------------------------------------===//
84// Mips Operand, Complex Patterns and Transformations Definitions.
85//===----------------------------------------------------------------------===//
86
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000087// Instruction operand types
88def brtarget : Operand<OtherVT>;
89def calltarget : Operand<i32>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000090def simm16 : Operand<i32>;
Eric Christopher3c999a22007-10-26 04:00:13 +000091def shamt : Operand<i32>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000092
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +000093// Unsigned Operand
94def uimm16 : Operand<i32> {
95 let PrintMethod = "printUnsignedImm";
96}
97
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000098// Address operand
99def mem : Operand<i32> {
100 let PrintMethod = "printMemOperand";
101 let MIOperandInfo = (ops simm16, CPURegs);
102}
103
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000104// Transformation Function - get the lower 16 bits.
105def LO16 : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000106 return getI32Imm((unsigned)N->getZExtValue() & 0xFFFF);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000107}]>;
108
109// Transformation Function - get the higher 16 bits.
110def HI16 : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000111 return getI32Imm((unsigned)N->getZExtValue() >> 16);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000112}]>;
113
114// Node immediate fits as 16-bit sign extended on target immediate.
115// e.g. addi, andi
Jakob Stoklund Olesen7552a3d2010-08-18 23:56:46 +0000116def immSExt16 : PatLeaf<(imm), [{ return isInt<16>(N->getSExtValue()); }]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000117
118// Node immediate fits as 16-bit zero extended on target immediate.
119// The LO16 param means that only the lower 16 bits of the node
120// immediate are caught.
121// e.g. addiu, sltiu
122def immZExt16 : PatLeaf<(imm), [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000123 if (N->getValueType(0) == MVT::i32)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000124 return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Eric Christopher3c999a22007-10-26 04:00:13 +0000125 else
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000126 return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000127}], LO16>;
128
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000129// shamt field must fit in 5 bits.
130def immZExt5 : PatLeaf<(imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000131 return N->getZExtValue() == ((N->getZExtValue()) & 0x1f) ;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000132}]>;
133
Eric Christopher3c999a22007-10-26 04:00:13 +0000134// Mips Address Mode! SDNode frameindex could possibily be a match
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000135// since load and store instructions from stack used it.
Chris Lattnereb079a32010-02-14 21:53:19 +0000136def addr : ComplexPattern<iPTR, 2, "SelectAddr", [frameindex], []>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000137
138//===----------------------------------------------------------------------===//
139// Instructions specific format
140//===----------------------------------------------------------------------===//
141
142// Arithmetic 3 register operands
Eric Christopher3c999a22007-10-26 04:00:13 +0000143let isCommutable = 1 in
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000144class ArithR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
Eric Christopher3c999a22007-10-26 04:00:13 +0000145 InstrItinClass itin>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000146 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
147 !strconcat(instr_asm, "\t$dst, $b, $c"),
148 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], itin>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000149
Eric Christopher3c999a22007-10-26 04:00:13 +0000150let isCommutable = 1 in
151class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000152 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
153 !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000154
155// Arithmetic 2 register operands
Eric Christopher3c999a22007-10-26 04:00:13 +0000156class ArithI<bits<6> op, string instr_asm, SDNode OpNode,
157 Operand Od, PatLeaf imm_type> :
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000158 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
159 !strconcat(instr_asm, "\t$dst, $b, $c"),
160 [(set CPURegs:$dst, (OpNode CPURegs:$b, imm_type:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000161
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000162class ArithOverflowI<bits<6> op, string instr_asm, SDNode OpNode,
163 Operand Od, PatLeaf imm_type> :
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000164 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
165 !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000166
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000167// Arithmetic Multiply ADD/SUB
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000168let rd = 0, shamt = 0, Defs = [HI, LO], Uses = [HI, LO] in
169class MArithR<bits<6> func, string instr_asm, SDNode op> :
170 FR<0x1c, func, (outs), (ins CPURegs:$rs, CPURegs:$rt),
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000171 !strconcat(instr_asm, "\t$rs, $rt"),
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000172 [(op CPURegs:$rs, CPURegs:$rt, LO, HI)], IIImul>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000173
174// Logical
175class LogicR<bits<6> func, string instr_asm, SDNode OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000176 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
177 !strconcat(instr_asm, "\t$dst, $b, $c"),
178 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000179
180class LogicI<bits<6> op, string instr_asm, SDNode OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000181 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, uimm16:$c),
182 !strconcat(instr_asm, "\t$dst, $b, $c"),
183 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt16:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000184
185class LogicNOR<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000186 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
187 !strconcat(instr_asm, "\t$dst, $b, $c"),
188 [(set CPURegs:$dst, (not (or CPURegs:$b, CPURegs:$c)))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000189
190// Shifts
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000191class LogicR_shift_rotate_imm<bits<6> func, bits<5> _rs, string instr_asm,
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000192 SDNode OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000193 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, shamt:$c),
194 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000195 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt5:$c))], IIAlu> {
196 let rs = _rs;
197}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000198
Bruno Cardoso Lopes81092dc2011-03-04 17:51:39 +0000199class LogicR_shift_rotate_reg<bits<6> func, bits<5> _shamt, string instr_asm,
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000200 SDNode OpNode>:
201 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$c, CPURegs:$b),
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000202 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000203 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu> {
204 let shamt = _shamt;
205}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000206
207// Load Upper Imediate
208class LoadUpper<bits<6> op, string instr_asm>:
209 FI< op,
Evan Cheng64d80e32007-07-19 01:14:50 +0000210 (outs CPURegs:$dst),
211 (ins uimm16:$imm),
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000212 !strconcat(instr_asm, "\t$dst, $imm"),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000213 [], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000214
Eric Christopher3c999a22007-10-26 04:00:13 +0000215// Memory Load/Store
Dan Gohman15511cf2008-12-03 18:15:48 +0000216let canFoldAsLoad = 1, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000217class LoadM<bits<6> op, string instr_asm, PatFrag OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000218 FI<op, (outs CPURegs:$dst), (ins mem:$addr),
219 !strconcat(instr_asm, "\t$dst, $addr"),
220 [(set CPURegs:$dst, (OpNode addr:$addr))], IILoad>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000221
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000222class StoreM<bits<6> op, string instr_asm, PatFrag OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000223 FI<op, (outs), (ins CPURegs:$dst, mem:$addr),
224 !strconcat(instr_asm, "\t$dst, $addr"),
225 [(OpNode CPURegs:$dst, addr:$addr)], IIStore>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000226
227// Conditional Branch
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000228let isBranch = 1, isTerminator=1, hasDelaySlot = 1 in {
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000229class CBranch<bits<6> op, string instr_asm, PatFrag cond_op>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000230 FI<op, (outs), (ins CPURegs:$a, CPURegs:$b, brtarget:$offset),
231 !strconcat(instr_asm, "\t$a, $b, $offset"),
232 [(brcond (cond_op CPURegs:$a, CPURegs:$b), bb:$offset)],
233 IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000234
235class CBranchZero<bits<6> op, string instr_asm, PatFrag cond_op>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000236 FI<op, (outs), (ins CPURegs:$src, brtarget:$offset),
237 !strconcat(instr_asm, "\t$src, $offset"),
238 [(brcond (cond_op CPURegs:$src, 0), bb:$offset)],
239 IIBranch>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000240}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000241
Eric Christopher3c999a22007-10-26 04:00:13 +0000242// SetCC
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000243class SetCC_R<bits<6> op, bits<6> func, string instr_asm,
244 PatFrag cond_op>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000245 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
246 !strconcat(instr_asm, "\t$dst, $b, $c"),
247 [(set CPURegs:$dst, (cond_op CPURegs:$b, CPURegs:$c))],
248 IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000249
250class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op,
251 Operand Od, PatLeaf imm_type>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000252 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
253 !strconcat(instr_asm, "\t$dst, $b, $c"),
254 [(set CPURegs:$dst, (cond_op CPURegs:$b, imm_type:$c))],
255 IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000256
257// Unconditional branch
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000258let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000259class JumpFJ<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000260 FJ<op, (outs), (ins brtarget:$target),
261 !strconcat(instr_asm, "\t$target"), [(br bb:$target)], IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000262
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000263let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000264class JumpFR<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000265 FR<op, func, (outs), (ins CPURegs:$target),
266 !strconcat(instr_asm, "\t$target"), [(brind CPURegs:$target)], IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000267
268// Jump and Link (Call)
Eric Christopher3c999a22007-10-26 04:00:13 +0000269let isCall=1, hasDelaySlot=1,
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000270 // All calls clobber the non-callee saved registers...
Jakob Stoklund Olesende12e432010-02-17 20:18:50 +0000271 Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9,
272 K0, K1, D0, D1, D2, D3, D4, D5, D6, D7, D8, D9], Uses = [GP] in {
Eric Christopher3c999a22007-10-26 04:00:13 +0000273 class JumpLink<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000274 FJ<op, (outs), (ins calltarget:$target, variable_ops),
275 !strconcat(instr_asm, "\t$target"), [(MipsJmpLink imm:$target)],
276 IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000277
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000278 let rd=31 in
279 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000280 FR<op, func, (outs), (ins CPURegs:$rs, variable_ops),
281 !strconcat(instr_asm, "\t$rs"), [(MipsJmpLink CPURegs:$rs)], IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000282
283 class BranchLink<string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000284 FI<0x1, (outs), (ins CPURegs:$rs, brtarget:$target, variable_ops),
285 !strconcat(instr_asm, "\t$rs, $target"), [], IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000286}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000287
Eric Christopher3c999a22007-10-26 04:00:13 +0000288// Mul, Div
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000289let Defs = [HI, LO] in {
290 class Mul<bits<6> func, string instr_asm, InstrItinClass itin>:
291 FR<0x00, func, (outs), (ins CPURegs:$a, CPURegs:$b),
292 !strconcat(instr_asm, "\t$a, $b"), [], itin>;
293
294 class Div<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin>:
295 FR<0x00, func, (outs), (ins CPURegs:$a, CPURegs:$b),
296 !strconcat(instr_asm, "\t$$zero, $a, $b"),
297 [(op CPURegs:$a, CPURegs:$b)], itin>;
298}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000299
Eric Christopher3c999a22007-10-26 04:00:13 +0000300// Move from Hi/Lo
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000301class MoveFromLOHI<bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000302 FR<0x00, func, (outs CPURegs:$dst), (ins),
303 !strconcat(instr_asm, "\t$dst"), [], IIHiLo>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000304
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000305class MoveToLOHI<bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000306 FR<0x00, func, (outs), (ins CPURegs:$src),
307 !strconcat(instr_asm, "\t$src"), [], IIHiLo>;
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000308
Eric Christopher3c999a22007-10-26 04:00:13 +0000309class EffectiveAddress<string instr_asm> :
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000310 FI<0x09, (outs CPURegs:$dst), (ins mem:$addr),
311 instr_asm, [(set CPURegs:$dst, addr:$addr)], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000312
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000313// Count Leading Ones/Zeros in Word
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000314class CountLeading<bits<6> func, string instr_asm, list<dag> pattern>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000315 FR<0x1c, func, (outs CPURegs:$dst), (ins CPURegs:$src),
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000316 !strconcat(instr_asm, "\t$dst, $src"), pattern, IIAlu>,
317 Requires<[HasBitCount]> {
318 let shamt = 0;
319 let rt = rd;
320}
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000321
322// Sign Extend in Register.
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000323class SignExtInReg<bits<6> func, string instr_asm, ValueType vt>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000324 FR<0x3f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
325 !strconcat(instr_asm, "\t$dst, $src"),
326 [(set CPURegs:$dst, (sext_inreg CPURegs:$src, vt))], NoItinerary>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000327
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000328// Byte Swap
329class ByteSwap<bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000330 FR<0x1f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
331 !strconcat(instr_asm, "\t$dst, $src"),
332 [(set CPURegs:$dst, (bswap CPURegs:$src))], NoItinerary>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000333
334// Conditional Move
335class CondMov<bits<6> func, string instr_asm, PatLeaf MovCode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000336 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$F, CPURegs:$T,
337 CPURegs:$cond), !strconcat(instr_asm, "\t$dst, $T, $cond"),
Bruno Cardoso Lopesbd3af09c2010-12-07 19:04:14 +0000338 [], NoItinerary>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000339
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000340//===----------------------------------------------------------------------===//
341// Pseudo instructions
342//===----------------------------------------------------------------------===//
343
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000344// As stack alignment is always done with addiu, we need a 16-bit immediate
Evan Cheng071a2792007-09-11 19:55:27 +0000345let Defs = [SP], Uses = [SP] in {
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000346def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000347 "!ADJCALLSTACKDOWN $amt",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000348 [(callseq_start timm:$amt)]>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000349def ADJCALLSTACKUP : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000350 "!ADJCALLSTACKUP $amt1",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000351 [(callseq_end timm:$amt1, timm:$amt2)]>;
Evan Cheng071a2792007-09-11 19:55:27 +0000352}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000353
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000354// Some assembly macros need to avoid pseudoinstructions and assembler
355// automatic reodering, we should reorder ourselves.
356def MACRO : MipsPseudo<(outs), (ins), ".set\tmacro", []>;
357def REORDER : MipsPseudo<(outs), (ins), ".set\treorder", []>;
358def NOMACRO : MipsPseudo<(outs), (ins), ".set\tnomacro", []>;
359def NOREORDER : MipsPseudo<(outs), (ins), ".set\tnoreorder", []>;
360
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000361// These macros are inserted to prevent GAS from complaining
Bruno Cardoso Lopes99027d72011-03-04 20:48:08 +0000362// when using the AT register.
363def NOAT : MipsPseudo<(outs), (ins), ".set\tnoat", []>;
364def ATMACRO : MipsPseudo<(outs), (ins), ".set\tat", []>;
365
Eric Christopher3c999a22007-10-26 04:00:13 +0000366// When handling PIC code the assembler needs .cpload and .cprestore
367// directives. If the real instructions corresponding these directives
368// are used, we have the same behavior, but get also a bunch of warnings
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000369// from the assembler.
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000370def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$picreg), ".cpload\t$picreg", []>;
371def CPRESTORE : MipsPseudo<(outs), (ins uimm16:$loc), ".cprestore\t$loc\n", []>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000372
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000373//===----------------------------------------------------------------------===//
374// Instruction definition
375//===----------------------------------------------------------------------===//
376
377//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000378// MipsI Instructions
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000379//===----------------------------------------------------------------------===//
380
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000381/// Arithmetic Instructions (ALU Immediate)
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000382def ADDiu : ArithI<0x09, "addiu", add, simm16, immSExt16>;
383def ADDi : ArithOverflowI<0x08, "addi", add, simm16, immSExt16>;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000384def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000385def SLTiu : SetCC_I<0x0b, "sltiu", setult, simm16, immSExt16>;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000386def ANDi : LogicI<0x0c, "andi", and>;
387def ORi : LogicI<0x0d, "ori", or>;
388def XORi : LogicI<0x0e, "xori", xor>;
389def LUi : LoadUpper<0x0f, "lui">;
390
391/// Arithmetic Instructions (3-Operand, R-Type)
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000392def ADDu : ArithR<0x00, 0x21, "addu", add, IIAlu>;
393def SUBu : ArithR<0x00, 0x23, "subu", sub, IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000394def ADD : ArithOverflowR<0x00, 0x20, "add">;
395def SUB : ArithOverflowR<0x00, 0x22, "sub">;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000396def SLT : SetCC_R<0x00, 0x2a, "slt", setlt>;
397def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000398def AND : LogicR<0x24, "and", and>;
399def OR : LogicR<0x25, "or", or>;
400def XOR : LogicR<0x26, "xor", xor>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000401def NOR : LogicNOR<0x00, 0x27, "nor">;
402
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000403/// Shift Instructions
Bruno Cardoso Lopes908b6dd2010-12-09 17:32:30 +0000404def SLL : LogicR_shift_rotate_imm<0x00, 0x00, "sll", shl>;
405def SRL : LogicR_shift_rotate_imm<0x02, 0x00, "srl", srl>;
406def SRA : LogicR_shift_rotate_imm<0x03, 0x00, "sra", sra>;
407def SLLV : LogicR_shift_rotate_reg<0x04, 0x00, "sllv", shl>;
408def SRLV : LogicR_shift_rotate_reg<0x06, 0x00, "srlv", srl>;
409def SRAV : LogicR_shift_rotate_reg<0x07, 0x00, "srav", sra>;
410
411// Rotate Instructions
412let Predicates = [IsMips32r2] in {
413 def ROTR : LogicR_shift_rotate_imm<0x02, 0x01, "rotr", rotr>;
414 def ROTRV : LogicR_shift_rotate_reg<0x06, 0x01, "rotrv", rotr>;
415}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000416
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000417/// Load and Store Instructions
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000418def LB : LoadM<0x20, "lb", sextloadi8>;
419def LBu : LoadM<0x24, "lbu", zextloadi8>;
420def LH : LoadM<0x21, "lh", sextloadi16>;
421def LHu : LoadM<0x25, "lhu", zextloadi16>;
422def LW : LoadM<0x23, "lw", load>;
423def SB : StoreM<0x28, "sb", truncstorei8>;
424def SH : StoreM<0x29, "sh", truncstorei16>;
425def SW : StoreM<0x2b, "sw", store>;
426
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000427/// Jump and Branch Instructions
428def J : JumpFJ<0x02, "j">;
429def JR : JumpFR<0x00, 0x08, "jr">;
430def JAL : JumpLink<0x03, "jal">;
431def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000432def BEQ : CBranch<0x04, "beq", seteq>;
433def BNE : CBranch<0x05, "bne", setne>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000434
Eric Christopher3c999a22007-10-26 04:00:13 +0000435let rt=1 in
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000436 def BGEZ : CBranchZero<0x01, "bgez", setge>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000437
438let rt=0 in {
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000439 def BGTZ : CBranchZero<0x07, "bgtz", setgt>;
440 def BLEZ : CBranchZero<0x07, "blez", setle>;
441 def BLTZ : CBranchZero<0x01, "bltz", setlt>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000442}
443
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000444def BGEZAL : BranchLink<"bgezal">;
445def BLTZAL : BranchLink<"bltzal">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000446
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000447let isReturn=1, isTerminator=1, hasDelaySlot=1,
448 isBarrier=1, hasCtrlDep=1, rs=0, rt=0, shamt=0 in
449 def RET : FR <0x00, 0x02, (outs), (ins CPURegs:$target),
450 "jr\t$target", [(MipsRet CPURegs:$target)], IIBranch>;
451
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000452/// Multiply and Divide Instructions.
Bruno Cardoso Lopes38b5e862011-03-04 21:03:24 +0000453def MULT : Mul<0x18, "mult", IIImul>;
454def MULTu : Mul<0x19, "multu", IIImul>;
455def SDIV : Div<MipsDivRem, 0x1a, "div", IIIdiv>;
456def UDIV : Div<MipsDivRemU, 0x1b, "divu", IIIdiv>;
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000457
458let Defs = [HI] in
459 def MTHI : MoveToLOHI<0x11, "mthi">;
460let Defs = [LO] in
461 def MTLO : MoveToLOHI<0x13, "mtlo">;
462
463let Uses = [HI] in
464 def MFHI : MoveFromLOHI<0x10, "mfhi">;
465let Uses = [LO] in
466 def MFLO : MoveFromLOHI<0x12, "mflo">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000467
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000468/// Sign Ext In Register Instructions.
469let Predicates = [HasSEInReg] in {
Bruno Cardoso Lopesd3bdf192009-05-27 17:23:44 +0000470 let shamt = 0x10, rs = 0 in
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000471 def SEB : SignExtInReg<0x21, "seb", i8>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000472
Bruno Cardoso Lopesd3bdf192009-05-27 17:23:44 +0000473 let shamt = 0x18, rs = 0 in
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000474 def SEH : SignExtInReg<0x20, "seh", i16>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000475}
476
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000477/// Count Leading
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000478def CLZ : CountLeading<0b100000, "clz",
479 [(set CPURegs:$dst, (ctlz CPURegs:$src))]>;
480def CLO : CountLeading<0b100001, "clo",
481 [(set CPURegs:$dst, (ctlz (not CPURegs:$src)))]>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000482
483/// Byte Swap
484let Predicates = [HasSwap] in {
485 let shamt = 0x3, rs = 0 in
486 def WSBW : ByteSwap<0x20, "wsbw">;
487}
488
489/// Conditional Move
490def MIPS_CMOV_ZERO : PatLeaf<(i32 0)>;
491def MIPS_CMOV_NZERO : PatLeaf<(i32 1)>;
492
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000493// Conditional moves:
494// These instructions are expanded in MipsISelLowering::EmitInstrWithCustomInserter
495// if target does not have conditional move instructions.
496// flag:int, data:int
497let usesCustomInserter = 1, shamt = 0, Constraints = "$F = $dst" in
498 class CondMovIntInt<bits<6> funct, string instr_asm> :
499 FR<0, funct, (outs CPURegs:$dst),
500 (ins CPURegs:$T, CPURegs:$cond, CPURegs:$F),
501 !strconcat(instr_asm, "\t$dst, $T, $cond"), [], NoItinerary>;
502
503def MOVZ_I : CondMovIntInt<0x0a, "movz">;
504def MOVN_I : CondMovIntInt<0x0b, "movn">;
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000505
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000506/// No operation
507let addr=0 in
508 def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
509
Eric Christopher3c999a22007-10-26 04:00:13 +0000510// FrameIndexes are legalized when they are operands from load/store
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000511// instructions. The same not happens for stack address copies, so an
512// add op with mem ComplexPattern is used and the stack address copy
513// can be matched. It's similar to Sparc LEA_ADDRi
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000514def LEA_ADDiu : EffectiveAddress<"addiu\t$dst, ${addr:stackloc}">;
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000515
Bruno Cardoso Lopes8be76112011-01-18 19:29:17 +0000516// MADD*/MSUB*
517def MADD : MArithR<0, "madd", MipsMAdd>;
518def MADDU : MArithR<1, "maddu", MipsMAddu>;
519def MSUB : MArithR<4, "msub", MipsMSub>;
520def MSUBU : MArithR<5, "msubu", MipsMSubu>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000521
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000522// MUL is a assembly macro in the current used ISAs. In recent ISA's
523// it is a real instruction.
Bruno Cardoso Lopes7d5652d2010-11-12 00:38:32 +0000524def MUL : ArithR<0x1c, 0x02, "mul", mul, IIImul>, Requires<[IsMips32]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000525
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000526//===----------------------------------------------------------------------===//
527// Arbitrary patterns that map to one or more instructions
528//===----------------------------------------------------------------------===//
529
530// Small immediates
Eric Christopher3c999a22007-10-26 04:00:13 +0000531def : Pat<(i32 immSExt16:$in),
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000532 (ADDiu ZERO, imm:$in)>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000533def : Pat<(i32 immZExt16:$in),
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000534 (ORi ZERO, imm:$in)>;
535
536// Arbitrary immediates
537def : Pat<(i32 imm:$imm),
538 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
539
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000540// Carry patterns
541def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
542 (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
543def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
544 (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
Bruno Cardoso Lopes911a9922011-03-04 17:59:18 +0000545def : Pat<(addc CPURegs:$src, immSExt16:$imm),
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000546 (ADDiu CPURegs:$src, imm:$imm)>;
547
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000548// Call
549def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
550 (JAL tglobaladdr:$dst)>;
551def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
552 (JAL texternalsym:$dst)>;
Chris Lattnere0d27532010-02-28 07:23:21 +0000553//def : Pat<(MipsJmpLink CPURegs:$dst),
554// (JALR CPURegs:$dst)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000555
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000556// hi/lo relocs
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000557def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000558def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000559 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
Bruno Cardoso Lopesca8a2aa2011-03-04 20:01:52 +0000560def : Pat<(add CPURegs:$hi, (MipsLo tblockaddress:$lo)),
561 (ADDiu CPURegs:$hi, tblockaddress:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000562
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000563def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000564def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
565 (ADDiu CPURegs:$hi, tjumptable:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000566
567def : Pat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
568def : Pat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)),
569 (ADDiu CPURegs:$hi, tconstpool:$lo)>;
570
571// gp_rel relocs
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000572def : Pat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)),
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +0000573 (ADDiu CPURegs:$gp, tglobaladdr:$in)>;
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000574def : Pat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)),
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000575 (ADDiu CPURegs:$gp, tconstpool:$in)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000576
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000577// Mips does not have "not", so we expand our way
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000578def : Pat<(not CPURegs:$in),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000579 (NOR CPURegs:$in, ZERO)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000580
Eric Christopher3c999a22007-10-26 04:00:13 +0000581// extended load and stores
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000582def : Pat<(extloadi1 addr:$src), (LBu addr:$src)>;
583def : Pat<(extloadi8 addr:$src), (LBu addr:$src)>;
584def : Pat<(extloadi16 addr:$src), (LHu addr:$src)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000585
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000586// peepholes
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000587def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
588
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000589// brcond patterns
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000590def : Pat<(brcond (setne CPURegs:$lhs, 0), bb:$dst),
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000591 (BNE CPURegs:$lhs, ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000592def : Pat<(brcond (seteq CPURegs:$lhs, 0), bb:$dst),
593 (BEQ CPURegs:$lhs, ZERO, bb:$dst)>;
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000594
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000595def : Pat<(brcond (setge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000596 (BEQ (SLT CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000597def : Pat<(brcond (setuge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000598 (BEQ (SLTu CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
599def : Pat<(brcond (setge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
600 (BEQ (SLTi CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
601def : Pat<(brcond (setuge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
602 (BEQ (SLTiu CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000603
604def : Pat<(brcond (setle CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000605 (BEQ (SLT CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000606def : Pat<(brcond (setule CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000607 (BEQ (SLTu CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000608
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000609def : Pat<(brcond CPURegs:$cond, bb:$dst),
610 (BNE CPURegs:$cond, ZERO, bb:$dst)>;
611
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000612// select patterns
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000613multiclass MovzPats<RegisterClass RC, Instruction MOVZInst> {
614 def : Pat<(select (setge CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
615 (MOVZInst RC:$T, (SLT CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
616 def : Pat<(select (setuge CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
617 (MOVZInst RC:$T, (SLTu CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
618 def : Pat<(select (setge CPURegs:$lhs, immSExt16:$rhs), RC:$T, RC:$F),
619 (MOVZInst RC:$T, (SLTi CPURegs:$lhs, immSExt16:$rhs), RC:$F)>;
620 def : Pat<(select (setuge CPURegs:$lh, immSExt16:$rh), RC:$T, RC:$F),
621 (MOVZInst RC:$T, (SLTiu CPURegs:$lh, immSExt16:$rh), RC:$F)>;
622 def : Pat<(select (setle CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
623 (MOVZInst RC:$T, (SLT CPURegs:$rhs, CPURegs:$lhs), RC:$F)>;
624 def : Pat<(select (setule CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
625 (MOVZInst RC:$T, (SLTu CPURegs:$rhs, CPURegs:$lhs), RC:$F)>;
626 def : Pat<(select (seteq CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
627 (MOVZInst RC:$T, (XOR CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
628 def : Pat<(select (seteq CPURegs:$lhs, 0), RC:$T, RC:$F),
629 (MOVZInst RC:$T, CPURegs:$lhs, RC:$F)>;
630}
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000631
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000632multiclass MovnPats<RegisterClass RC, Instruction MOVNInst> {
633 def : Pat<(select (setne CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
634 (MOVNInst RC:$T, (XOR CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
635 def : Pat<(select CPURegs:$cond, RC:$T, RC:$F),
636 (MOVNInst RC:$T, CPURegs:$cond, RC:$F)>;
637 def : Pat<(select (setne CPURegs:$lhs, 0), RC:$T, RC:$F),
638 (MOVNInst RC:$T, CPURegs:$lhs, RC:$F)>;
639}
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000640
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000641defm : MovzPats<CPURegs, MOVZ_I>;
642defm : MovnPats<CPURegs, MOVN_I>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000643
Bruno Cardoso Lopesab8d53a2010-12-07 19:00:20 +0000644// select patterns with got access
Akira Hatanaka1d6b38d2011-03-31 18:26:17 +0000645let AddedComplexity = 10 in
646 def : Pat<(select (setne CPURegs:$lhs, CPURegs:$rhs),
647 (i32 tglobaladdr:$T), CPURegs:$F),
648 (MOVN_I CPURegs:$F, (ADDiu GP, tglobaladdr:$T),
649 (XOR CPURegs:$lhs, CPURegs:$rhs))>;
Bruno Cardoso Lopesab8d53a2010-12-07 19:00:20 +0000650
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000651// setcc patterns
652def : Pat<(seteq CPURegs:$lhs, CPURegs:$rhs),
653 (SLTu (XOR CPURegs:$lhs, CPURegs:$rhs), 1)>;
654def : Pat<(setne CPURegs:$lhs, CPURegs:$rhs),
655 (SLTu ZERO, (XOR CPURegs:$lhs, CPURegs:$rhs))>;
656
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000657def : Pat<(setle CPURegs:$lhs, CPURegs:$rhs),
658 (XORi (SLT CPURegs:$rhs, CPURegs:$lhs), 1)>;
659def : Pat<(setule CPURegs:$lhs, CPURegs:$rhs),
660 (XORi (SLTu CPURegs:$rhs, CPURegs:$lhs), 1)>;
661
662def : Pat<(setgt CPURegs:$lhs, CPURegs:$rhs),
663 (SLT CPURegs:$rhs, CPURegs:$lhs)>;
664def : Pat<(setugt CPURegs:$lhs, CPURegs:$rhs),
665 (SLTu CPURegs:$rhs, CPURegs:$lhs)>;
666
667def : Pat<(setge CPURegs:$lhs, CPURegs:$rhs),
668 (XORi (SLT CPURegs:$lhs, CPURegs:$rhs), 1)>;
669def : Pat<(setuge CPURegs:$lhs, CPURegs:$rhs),
670 (XORi (SLTu CPURegs:$lhs, CPURegs:$rhs), 1)>;
671
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000672def : Pat<(setge CPURegs:$lhs, immSExt16:$rhs),
673 (XORi (SLTi CPURegs:$lhs, immSExt16:$rhs), 1)>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000674def : Pat<(setuge CPURegs:$lhs, immSExt16:$rhs),
675 (XORi (SLTiu CPURegs:$lhs, immSExt16:$rhs), 1)>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000676
677//===----------------------------------------------------------------------===//
678// Floating Point Support
679//===----------------------------------------------------------------------===//
680
681include "MipsInstrFPU.td"
682