blob: 70bc7dd59c12645e1e671dcaec64c8060e0f085a [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===- MipsInstrInfo.td - Mips Register defs --------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Eric Christopher7300ac12007-10-26 04:00:13 +00005// This file was developed by Bruno Cardoso Lopes and is distributed under the
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006// University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10//===----------------------------------------------------------------------===//
11// Instruction format superclass
12//===----------------------------------------------------------------------===//
13
14include "MipsInstrFormats.td"
15
16//===----------------------------------------------------------------------===//
17// Mips profiles and nodes
18//===----------------------------------------------------------------------===//
19
20// Call
21def SDT_MipsJmpLink : SDTypeProfile<0, 1, [SDTCisVT<0, iPTR>]>;
22def MipsJmpLink : SDNode<"MipsISD::JmpLink",SDT_MipsJmpLink, [SDNPHasChain,
23 SDNPOutFlag]>;
24
Eric Christopher7300ac12007-10-26 04:00:13 +000025// Hi and Lo nodes are created to let easy manipulation of 16-bit when
26// handling 32-bit immediates. They are used on MipsISelLowering to
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +000027// lower stuff like GlobalAddress, ExternalSymbol, ... on static model
Dan Gohmanf17a25c2007-07-18 16:29:46 +000028// This two nodes have nothing to do with Mips Registers Hi and Lo.
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +000029def MipsHi : SDNode<"MipsISD::Hi", SDTIntUnaryOp, [SDNPOutFlag]>;
Eric Christopher7300ac12007-10-26 04:00:13 +000030def MipsLo : SDNode<"MipsISD::Lo", SDTIntUnaryOp>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000031
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +000032// Necessary to generate glued instructions when loading GlobalAddress
33// into registers.
Eric Christopher7300ac12007-10-26 04:00:13 +000034def MipsAdd : SDNode<"MipsISD::Add", SDTIntBinOp, [SDNPCommutative,
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +000035 SDNPAssociative, SDNPOptInFlag]>;
36
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +000037// Used to Load Addresses on PIC code.
38def MipsLoadAddr: SDNode<"MipsISD::LoadAddr", SDTIntUnaryOp>;
39
Eric Christopher7300ac12007-10-26 04:00:13 +000040// Return
41def SDT_MipsRet : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
42def MipsRet : SDNode<"MipsISD::Ret", SDT_MipsRet, [SDNPHasChain,
Dan Gohmanf17a25c2007-07-18 16:29:46 +000043 SDNPOptInFlag]>;
44
45// These are target-independent nodes, but have target-specific formats.
46def SDT_MipsCallSeq : SDTypeProfile<0, 1, [SDTCisVT<0, i32>]>;
Eric Christopher7300ac12007-10-26 04:00:13 +000047def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_MipsCallSeq,
Dan Gohmanf17a25c2007-07-18 16:29:46 +000048 [SDNPHasChain, SDNPOutFlag]>;
Eric Christopher7300ac12007-10-26 04:00:13 +000049def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_MipsCallSeq,
Dan Gohmanf17a25c2007-07-18 16:29:46 +000050 [SDNPHasChain, SDNPOutFlag]>;
51
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +000052//===----------------------------------------------------------------------===//
53// Mips Instruction Predicate Definitions.
54//===----------------------------------------------------------------------===//
55def IsStatic : Predicate<"TM.getRelocationModel() == Reloc::Static">;
56
57//===----------------------------------------------------------------------===//
58// Mips Operand, Complex Patterns and Transformations Definitions.
59//===----------------------------------------------------------------------===//
60
Dan Gohmanf17a25c2007-07-18 16:29:46 +000061// Instruction operand types
62def brtarget : Operand<OtherVT>;
63def calltarget : Operand<i32>;
64def uimm16 : Operand<i32>;
65def simm16 : Operand<i32>;
Eric Christopher7300ac12007-10-26 04:00:13 +000066def shamt : Operand<i32>;
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +000067def addrlabel : Operand<i32>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000068
69// Address operand
70def mem : Operand<i32> {
71 let PrintMethod = "printMemOperand";
72 let MIOperandInfo = (ops simm16, CPURegs);
73}
74
Dan Gohmanf17a25c2007-07-18 16:29:46 +000075// Transformation Function - get the lower 16 bits.
76def LO16 : SDNodeXForm<imm, [{
77 return getI32Imm((unsigned)N->getValue() & 0xFFFF);
78}]>;
79
80// Transformation Function - get the higher 16 bits.
81def HI16 : SDNodeXForm<imm, [{
82 return getI32Imm((unsigned)N->getValue() >> 16);
83}]>;
84
85// Node immediate fits as 16-bit sign extended on target immediate.
86// e.g. addi, andi
87def immSExt16 : PatLeaf<(imm), [{
88 if (N->getValueType(0) == MVT::i32)
89 return (int32_t)N->getValue() == (short)N->getValue();
Eric Christopher7300ac12007-10-26 04:00:13 +000090 else
Dan Gohmanf17a25c2007-07-18 16:29:46 +000091 return (int64_t)N->getValue() == (short)N->getValue();
92}]>;
93
94// Node immediate fits as 16-bit zero extended on target immediate.
95// The LO16 param means that only the lower 16 bits of the node
96// immediate are caught.
97// e.g. addiu, sltiu
98def immZExt16 : PatLeaf<(imm), [{
99 if (N->getValueType(0) == MVT::i32)
100 return (uint32_t)N->getValue() == (unsigned short)N->getValue();
Eric Christopher7300ac12007-10-26 04:00:13 +0000101 else
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000102 return (uint64_t)N->getValue() == (unsigned short)N->getValue();
103}], LO16>;
104
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000105// Node immediate fits as 32-bit zero extended on target immediate.
106//def immZExt32 : PatLeaf<(imm), [{
107// return (uint64_t)N->getValue() == (uint32_t)N->getValue();
108//}], LO16>;
109
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000110// shamt field must fit in 5 bits.
111def immZExt5 : PatLeaf<(imm), [{
112 return N->getValue() == ((N->getValue()) & 0x1f) ;
113}]>;
114
Eric Christopher7300ac12007-10-26 04:00:13 +0000115// Mips Address Mode! SDNode frameindex could possibily be a match
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000116// since load and store instructions from stack used it.
117def addr : ComplexPattern<i32, 2, "SelectAddr", [frameindex], []>;
118
119//===----------------------------------------------------------------------===//
120// Instructions specific format
121//===----------------------------------------------------------------------===//
122
123// Arithmetic 3 register operands
Eric Christopher7300ac12007-10-26 04:00:13 +0000124let isCommutable = 1 in
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000125class ArithR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
Eric Christopher7300ac12007-10-26 04:00:13 +0000126 InstrItinClass itin>:
127 FR< op,
128 func,
129 (outs CPURegs:$dst),
130 (ins CPURegs:$b, CPURegs:$c),
131 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000132 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], itin>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000133
Eric Christopher7300ac12007-10-26 04:00:13 +0000134let isCommutable = 1 in
135class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm>:
136 FR< op,
137 func,
138 (outs CPURegs:$dst),
139 (ins CPURegs:$b, CPURegs:$c),
140 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000141 [], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000142
143// Arithmetic 2 register operands
144let isCommutable = 1 in
Eric Christopher7300ac12007-10-26 04:00:13 +0000145class ArithI<bits<6> op, string instr_asm, SDNode OpNode,
146 Operand Od, PatLeaf imm_type> :
147 FI< op,
148 (outs CPURegs:$dst),
149 (ins CPURegs:$b, Od:$c),
150 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000151 [(set CPURegs:$dst, (OpNode CPURegs:$b, imm_type:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000152
153// Arithmetic Multiply ADD/SUB
154let rd=0 in
Eric Christopher7300ac12007-10-26 04:00:13 +0000155class MArithR<bits<6> func, string instr_asm> :
156 FR< 0x1c,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000157 func,
Eric Christopher7300ac12007-10-26 04:00:13 +0000158 (outs CPURegs:$rs),
159 (ins CPURegs:$rt),
160 !strconcat(instr_asm, " $rs, $rt"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000161 [], IIImul>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000162
163// Logical
164class LogicR<bits<6> func, string instr_asm, SDNode OpNode>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000165 FR< 0x00,
166 func,
167 (outs CPURegs:$dst),
168 (ins CPURegs:$b, CPURegs:$c),
169 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000170 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000171
172class LogicI<bits<6> op, string instr_asm, SDNode OpNode>:
173 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000174 (outs CPURegs:$dst),
175 (ins CPURegs:$b, uimm16:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000176 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000177 [(set CPURegs:$dst, (OpNode CPURegs:$b, immSExt16:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000178
179class LogicNOR<bits<6> op, bits<6> func, string instr_asm>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000180 FR< op,
181 func,
182 (outs CPURegs:$dst),
183 (ins CPURegs:$b, CPURegs:$c),
184 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000185 [(set CPURegs:$dst, (not (or CPURegs:$b, CPURegs:$c)))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000186
187// Shifts
188let rt = 0 in
189class LogicR_shift_imm<bits<6> func, string instr_asm, SDNode OpNode>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000190 FR< 0x00,
191 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000192 (outs CPURegs:$dst),
193 (ins CPURegs:$b, shamt:$c),
Eric Christopher7300ac12007-10-26 04:00:13 +0000194 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000195 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt5:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000196
197class LogicR_shift_reg<bits<6> func, string instr_asm, SDNode OpNode>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000198 FR< 0x00,
199 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000200 (outs CPURegs:$dst),
201 (ins CPURegs:$b, CPURegs:$c),
Eric Christopher7300ac12007-10-26 04:00:13 +0000202 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000203 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000204
205// Load Upper Imediate
206class LoadUpper<bits<6> op, string instr_asm>:
207 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000208 (outs CPURegs:$dst),
209 (ins uimm16:$imm),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000210 !strconcat(instr_asm, " $dst, $imm"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000211 [], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000212
Eric Christopher7300ac12007-10-26 04:00:13 +0000213// Memory Load/Store
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000214let isLoad = 1, hasDelaySlot = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000215class LoadM<bits<6> op, string instr_asm, PatFrag OpNode>:
216 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000217 (outs CPURegs:$dst),
218 (ins mem:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000219 !strconcat(instr_asm, " $dst, $addr"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000220 [(set CPURegs:$dst, (OpNode addr:$addr))], IILoad>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000221
222let isStore = 1 in
223class StoreM<bits<6> op, string instr_asm, PatFrag OpNode>:
224 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000225 (outs),
226 (ins CPURegs:$dst, mem:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000227 !strconcat(instr_asm, " $dst, $addr"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000228 [(OpNode CPURegs:$dst, addr:$addr)], IIStore>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000229
230// Conditional Branch
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000231let isBranch = 1, isTerminator=1, hasDelaySlot = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000232class CBranch<bits<6> op, string instr_asm, PatFrag cond_op>:
233 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000234 (outs),
235 (ins CPURegs:$a, CPURegs:$b, brtarget:$offset),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000236 !strconcat(instr_asm, " $a, $b, $offset"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000237 [(brcond (cond_op CPURegs:$a, CPURegs:$b), bb:$offset)],
238 IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000239
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000240
241class CBranchZero<bits<6> op, string instr_asm, PatFrag cond_op>:
242 FI< op,
243 (outs),
244 (ins CPURegs:$src, brtarget:$offset),
245 !strconcat(instr_asm, " $src, $offset"),
246 [(brcond (cond_op CPURegs:$src, 0), bb:$offset)],
247 IIBranch>;
Eric Christopher7300ac12007-10-26 04:00:13 +0000248}
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000249
Eric Christopher7300ac12007-10-26 04:00:13 +0000250// SetCC
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000251class SetCC_R<bits<6> op, bits<6> func, string instr_asm,
252 PatFrag cond_op>:
253 FR< op,
254 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000255 (outs CPURegs:$dst),
256 (ins CPURegs:$b, CPURegs:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000257 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000258 [(set CPURegs:$dst, (cond_op CPURegs:$b, CPURegs:$c))],
259 IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000260
261class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op,
262 Operand Od, PatLeaf imm_type>:
263 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000264 (outs CPURegs:$dst),
265 (ins CPURegs:$b, Od:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000266 !strconcat(instr_asm, " $dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000267 [(set CPURegs:$dst, (cond_op CPURegs:$b, imm_type:$c))],
268 IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000269
270// Unconditional branch
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000271let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000272class JumpFJ<bits<6> op, string instr_asm>:
273 FJ< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000274 (outs),
275 (ins brtarget:$target),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000276 !strconcat(instr_asm, " $target"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000277 [(br bb:$target)], IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000278
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000279let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000280class JumpFR<bits<6> op, bits<6> func, string instr_asm>:
281 FR< op,
282 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000283 (outs),
284 (ins CPURegs:$target),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000285 !strconcat(instr_asm, " $target"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000286 [], IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000287
288// Jump and Link (Call)
Eric Christopher7300ac12007-10-26 04:00:13 +0000289let isCall=1, hasDelaySlot=1,
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000290 // All calls clobber the non-callee saved registers...
Eric Christopher7300ac12007-10-26 04:00:13 +0000291 Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2,
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +0000292 T3, T4, T5, T6, T7, T8, T9, K0, K1] in {
Eric Christopher7300ac12007-10-26 04:00:13 +0000293 class JumpLink<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000294 FJ< op,
295 (outs),
296 (ins calltarget:$target),
297 !strconcat(instr_asm, " $target"),
298 [(MipsJmpLink imm:$target)], IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000299
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000300 let rd=31 in
301 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
302 FR< op,
303 func,
304 (outs),
305 (ins CPURegs:$rs),
306 !strconcat(instr_asm, " $rs"),
307 [(MipsJmpLink CPURegs:$rs)], IIBranch>;
308
309 class BranchLink<string instr_asm>:
310 FI< 0x1,
311 (outs),
312 (ins CPURegs:$rs, brtarget:$target),
313 !strconcat(instr_asm, " $rs, $target"),
314 [], IIBranch>;
315}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000316
Eric Christopher7300ac12007-10-26 04:00:13 +0000317// Mul, Div
318class MulDiv<bits<6> func, string instr_asm, InstrItinClass itin>:
319 FR< 0x00,
320 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000321 (outs),
Eric Christopher7300ac12007-10-26 04:00:13 +0000322 (ins CPURegs:$a, CPURegs:$b),
323 !strconcat(instr_asm, " $a, $b"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000324 [], itin>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000325
Eric Christopher7300ac12007-10-26 04:00:13 +0000326// Move from Hi/Lo
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000327class MoveFromTo<bits<6> func, string instr_asm>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000328 FR< 0x00,
329 func,
330 (outs CPURegs:$dst),
Evan Chengb783fa32007-07-19 01:14:50 +0000331 (ins),
Eric Christopher7300ac12007-10-26 04:00:13 +0000332 !strconcat(instr_asm, " $dst"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000333 [], IIHiLo>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000334
335// Count Leading Ones/Zeros in Word
336class CountLeading<bits<6> func, string instr_asm>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000337 FR< 0x1c,
338 func,
339 (outs CPURegs:$dst),
340 (ins CPURegs:$src),
341 !strconcat(instr_asm, " $dst, $src"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000342 [], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000343
Eric Christopher7300ac12007-10-26 04:00:13 +0000344class EffectiveAddress<string instr_asm> :
345 FI<0x09,
346 (outs CPURegs:$dst),
Bruno Cardoso Lopes96433662007-09-24 20:15:11 +0000347 (ins mem:$addr),
348 instr_asm,
349 [(set CPURegs:$dst, addr:$addr)], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000350
351//===----------------------------------------------------------------------===//
352// Pseudo instructions
353//===----------------------------------------------------------------------===//
354
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000355// As stack alignment is always done with addiu, we need a 16-bit immediate
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000356let Defs = [SP], Uses = [SP] in {
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +0000357def ADJCALLSTACKDOWN : PseudoInstMips<(outs), (ins uimm16:$amt),
358 "!ADJCALLSTACKDOWN $amt",
359 [(callseq_start imm:$amt)]>;
360def ADJCALLSTACKUP : PseudoInstMips<(outs), (ins uimm16:$amt),
361 "!ADJCALLSTACKUP $amt",
362 [(callseq_end imm:$amt)]>;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000363}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000364
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +0000365def IMPLICIT_DEF_CPURegs : PseudoInstMips<(outs CPURegs:$dst), (ins),
366 "!IMPLICIT_DEF $dst",
367 [(set CPURegs:$dst, (undef))]>;
368
Eric Christopher7300ac12007-10-26 04:00:13 +0000369// When handling PIC code the assembler needs .cpload and .cprestore
370// directives. If the real instructions corresponding these directives
371// are used, we have the same behavior, but get also a bunch of warnings
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +0000372// from the assembler.
Eric Christopher7300ac12007-10-26 04:00:13 +0000373def CPLOAD: PseudoInstMips<(outs), (ins CPURegs:$reg),
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +0000374 ".set noreorder\n\t.cpload $reg\n\t.set reorder", []>;
Eric Christopher7300ac12007-10-26 04:00:13 +0000375def CPRESTORE: PseudoInstMips<(outs), (ins uimm16:$loc),
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +0000376 ".cprestore $loc", []>;
377
378// Used on PIC code only, it loads the address of label into register reg. The
379// address is calculated from the global pointer ($gp) and is expanded by the
380// assembler into two instructions "lw" and "addiu".
Eric Christopher7300ac12007-10-26 04:00:13 +0000381def LA: PseudoInstMips<(outs CPURegs:$dst), (ins addrlabel:$label),
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +0000382 "la $dst, $label", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000383
384//===----------------------------------------------------------------------===//
385// Instruction definition
386//===----------------------------------------------------------------------===//
387
388//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000389// MipsI Instructions
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000390//===----------------------------------------------------------------------===//
391
392// Arithmetic
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000393
394// ADDiu just accept 16-bit immediates but we handle this on Pat's.
395// immZExt32 is used here so it can match GlobalAddress immediates.
396def ADDiu : ArithI<0x09, "addiu", MipsAdd, uimm16, immZExt16>;
397def ADDi : ArithI<0x08, "addi", add, simm16, immSExt16>;
398def MUL : ArithR<0x1c, 0x02, "mul", mul, IIImul>;
399def ADDu : ArithR<0x00, 0x21, "addu", add, IIAlu>;
400def SUBu : ArithR<0x00, 0x23, "subu", sub, IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000401def ADD : ArithOverflowR<0x00, 0x20, "add">;
402def SUB : ArithOverflowR<0x00, 0x22, "sub">;
403def MADD : MArithR<0x00, "madd">;
404def MADDU : MArithR<0x01, "maddu">;
405def MSUB : MArithR<0x04, "msub">;
406def MSUBU : MArithR<0x05, "msubu">;
407
408// Logical
409def AND : LogicR<0x24, "and", and>;
410def OR : LogicR<0x25, "or", or>;
411def XOR : LogicR<0x26, "xor", xor>;
412def ANDi : LogicI<0x0c, "andi", and>;
413def ORi : LogicI<0x0d, "ori", or>;
414def XORi : LogicI<0x0e, "xori", xor>;
415def NOR : LogicNOR<0x00, 0x27, "nor">;
416
Eric Christopher7300ac12007-10-26 04:00:13 +0000417// Shifts
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000418def SLL : LogicR_shift_imm<0x00, "sll", shl>;
419def SRL : LogicR_shift_imm<0x02, "srl", srl>;
420def SRA : LogicR_shift_imm<0x03, "sra", sra>;
421def SLLV : LogicR_shift_reg<0x04, "sllv", shl>;
422def SRLV : LogicR_shift_reg<0x06, "srlv", srl>;
423def SRAV : LogicR_shift_reg<0x07, "srav", sra>;
424
425// Load Upper Immediate
426def LUi : LoadUpper<0x0f, "lui">;
427
428// Load/Store
429def LB : LoadM<0x20, "lb", sextloadi8>;
430def LBu : LoadM<0x24, "lbu", zextloadi8>;
431def LH : LoadM<0x21, "lh", sextloadi16>;
432def LHu : LoadM<0x25, "lhu", zextloadi16>;
433def LW : LoadM<0x23, "lw", load>;
434def SB : StoreM<0x28, "sb", truncstorei8>;
435def SH : StoreM<0x29, "sh", truncstorei16>;
436def SW : StoreM<0x2b, "sw", store>;
437
438// Conditional Branch
439def BEQ : CBranch<0x04, "beq", seteq>;
440def BNE : CBranch<0x05, "bne", setne>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000441
Eric Christopher7300ac12007-10-26 04:00:13 +0000442let rt=1 in
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000443def BGEZ : CBranchZero<0x01, "bgez", setge>;
444
445let rt=0 in {
446def BGTZ : CBranchZero<0x07, "bgtz", setgt>;
447def BLEZ : CBranchZero<0x07, "blez", setle>;
448def BLTZ : CBranchZero<0x01, "bltz", setlt>;
449}
450
451// Set Condition Code
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000452def SLT : SetCC_R<0x00, 0x2a, "slt", setlt>;
453def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult>;
454def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16>;
455def SLTiu : SetCC_I<0x0b, "sltiu", setult, uimm16, immZExt16>;
456
457// Unconditional jump
458def J : JumpFJ<0x02, "j">;
459def JR : JumpFR<0x00, 0x08, "jr">;
460
461// Jump and Link (Call)
462def JAL : JumpLink<0x03, "jal">;
463def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000464def BGEZAL : BranchLink<"bgezal">;
465def BLTZAL : BranchLink<"bltzal">;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000466
467// MulDiv and Move From Hi/Lo operations, have
468// their correpondent SDNodes created on ISelDAG.
469// Special Mul, Div operations
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000470def MULT : MulDiv<0x18, "mult", IIImul>;
471def MULTu : MulDiv<0x19, "multu", IIImul>;
472def DIV : MulDiv<0x1a, "div", IIIdiv>;
473def DIVu : MulDiv<0x1b, "divu", IIIdiv>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000474
Eric Christopher7300ac12007-10-26 04:00:13 +0000475// Move From Hi/Lo
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000476def MFHI : MoveFromTo<0x10, "mfhi">;
477def MFLO : MoveFromTo<0x12, "mflo">;
478def MTHI : MoveFromTo<0x11, "mthi">;
479def MTLO : MoveFromTo<0x13, "mtlo">;
480
481// Count Leading
Eric Christopher7300ac12007-10-26 04:00:13 +0000482// CLO/CLZ are part of the newer MIPS32(tm) instruction
483// set and not older Mips I keep this for future use
484// though.
485//def CLO : CountLeading<0x21, "clo">;
486//def CLZ : CountLeading<0x20, "clz">;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000487
488// No operation
489let addr=0 in
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000490def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000491
Eric Christopher7300ac12007-10-26 04:00:13 +0000492// Ret instruction - as mips does not have "ret" a
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000493// jr $ra must be generated.
Evan Cheng37e7c752007-07-21 00:34:19 +0000494let isReturn=1, isTerminator=1, hasDelaySlot=1,
Eric Christopher7300ac12007-10-26 04:00:13 +0000495 isBarrier=1, hasCtrlDep=1, rs=0, rt=0, shamt=0 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000496{
Evan Chengb783fa32007-07-19 01:14:50 +0000497 def RET : FR <0x00, 0x02, (outs), (ins CPURegs:$target),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000498 "jr $target", [(MipsRet CPURegs:$target)], IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000499}
500
Eric Christopher7300ac12007-10-26 04:00:13 +0000501// FrameIndexes are legalized when they are operands from load/store
Bruno Cardoso Lopes96433662007-09-24 20:15:11 +0000502// instructions. The same not happens for stack address copies, so an
503// add op with mem ComplexPattern is used and the stack address copy
504// can be matched. It's similar to Sparc LEA_ADDRi
505def LEA_ADDiu : EffectiveAddress<"addiu $dst, ${addr:stackloc}">;
506
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000507//===----------------------------------------------------------------------===//
508// Arbitrary patterns that map to one or more instructions
509//===----------------------------------------------------------------------===//
510
511// Small immediates
Eric Christopher7300ac12007-10-26 04:00:13 +0000512def : Pat<(i32 immSExt16:$in),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000513 (ADDiu ZERO, imm:$in)>;
Eric Christopher7300ac12007-10-26 04:00:13 +0000514def : Pat<(i32 immZExt16:$in),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000515 (ORi ZERO, imm:$in)>;
516
517// Arbitrary immediates
518def : Pat<(i32 imm:$imm),
519 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
520
521// Call
522def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
523 (JAL tglobaladdr:$dst)>;
524def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
525 (JAL texternalsym:$dst)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000526def : Pat<(MipsJmpLink CPURegs:$dst),
527 (JALR CPURegs:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000528
529// GlobalAddress, Constant Pool, ExternalSymbol, and JumpTable
530def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
531def : Pat<(MipsLo tglobaladdr:$in), (ADDiu ZERO, tglobaladdr:$in)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000532def : Pat<(MipsAdd CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
533 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
Eric Christopher7300ac12007-10-26 04:00:13 +0000534def : Pat<(MipsLoadAddr tglobaladdr:$in), (LA tglobaladdr:$in)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000535
Eric Christopher7300ac12007-10-26 04:00:13 +0000536// Mips does not have not, so we increase the operation
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000537def : Pat<(not CPURegs:$in),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000538 (NOR CPURegs:$in, ZERO)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000539
Eric Christopher7300ac12007-10-26 04:00:13 +0000540// extended load and stores
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000541def : Pat<(i32 (extloadi1 addr:$src)), (LBu addr:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000542def : Pat<(i32 (extloadi8 addr:$src)), (LBu addr:$src)>;
543def : Pat<(i32 (extloadi16 addr:$src)), (LHu addr:$src)>;
Eric Christopher7300ac12007-10-26 04:00:13 +0000544def : Pat<(truncstorei1 CPURegs:$src, addr:$addr),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000545 (SB CPURegs:$src, addr:$addr)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000546
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000547///
548/// brcond patterns
549///
550
551// direct match equal/notequal zero branches
552def : Pat<(brcond (setne CPURegs:$lhs, 0), bb:$dst),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000553 (BNE CPURegs:$lhs, ZERO, bb:$dst)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000554def : Pat<(brcond (seteq CPURegs:$lhs, 0), bb:$dst),
555 (BEQ CPURegs:$lhs, ZERO, bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000556
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000557def : Pat<(brcond (setge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000558 (BGEZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000559def : Pat<(brcond (setuge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000560 (BGEZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000561
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000562def : Pat<(brcond (setgt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
563 (BGTZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
564def : Pat<(brcond (setugt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
565 (BGTZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
566
567def : Pat<(brcond (setle CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
568 (BLEZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
569def : Pat<(brcond (setule CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
570 (BLEZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
571
572def : Pat<(brcond (setlt CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000573 (BNE (SLTi CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000574def : Pat<(brcond (setult CPURegs:$lhs, immZExt16:$rhs), bb:$dst),
575 (BNE (SLTiu CPURegs:$lhs, immZExt16:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000576def : Pat<(brcond (setlt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
577 (BNE (SLT CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
578def : Pat<(brcond (setult CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
579 (BNE (SLTu CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
580
581def : Pat<(brcond (setlt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
582 (BLTZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
583def : Pat<(brcond (setult CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
584 (BLTZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
585
586// generic brcond pattern
587def : Pat<(brcond CPURegs:$cond, bb:$dst),
588 (BNE CPURegs:$cond, ZERO, bb:$dst)>;
589
590///
Eric Christopher7300ac12007-10-26 04:00:13 +0000591/// setcc patterns, only matched when there
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000592/// is no brcond following a setcc operation
593///
594
595// setcc 2 register operands
596def : Pat<(setle CPURegs:$lhs, CPURegs:$rhs),
597 (XORi (SLT CPURegs:$rhs, CPURegs:$lhs), 1)>;
598def : Pat<(setule CPURegs:$lhs, CPURegs:$rhs),
599 (XORi (SLTu CPURegs:$rhs, CPURegs:$lhs), 1)>;
600
601def : Pat<(setgt CPURegs:$lhs, CPURegs:$rhs),
602 (SLT CPURegs:$rhs, CPURegs:$lhs)>;
603def : Pat<(setugt CPURegs:$lhs, CPURegs:$rhs),
604 (SLTu CPURegs:$rhs, CPURegs:$lhs)>;
605
606def : Pat<(setge CPURegs:$lhs, CPURegs:$rhs),
607 (XORi (SLT CPURegs:$lhs, CPURegs:$rhs), 1)>;
608def : Pat<(setuge CPURegs:$lhs, CPURegs:$rhs),
609 (XORi (SLTu CPURegs:$lhs, CPURegs:$rhs), 1)>;
610
611def : Pat<(setne CPURegs:$lhs, CPURegs:$rhs),
Eric Christopher7300ac12007-10-26 04:00:13 +0000612 (OR (SLT CPURegs:$lhs, CPURegs:$rhs),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000613 (SLT CPURegs:$rhs, CPURegs:$lhs))>;
614
615def : Pat<(seteq CPURegs:$lhs, CPURegs:$rhs),
Eric Christopher7300ac12007-10-26 04:00:13 +0000616 (XORi (OR (SLT CPURegs:$lhs, CPURegs:$rhs),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000617 (SLT CPURegs:$rhs, CPURegs:$lhs)), 1)>;
Eric Christopher7300ac12007-10-26 04:00:13 +0000618
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000619// setcc reg/imm operands
620def : Pat<(setge CPURegs:$lhs, immSExt16:$rhs),
621 (XORi (SLTi CPURegs:$lhs, immSExt16:$rhs), 1)>;
622def : Pat<(setuge CPURegs:$lhs, immZExt16:$rhs),
623 (XORi (SLTiu CPURegs:$lhs, immZExt16:$rhs), 1)>;