blob: a7ac2419d9fe2146230cb828129b5d8eec846907 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===- MipsInstrInfo.td - Mips Register defs --------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Bruno Cardoso Lopes and is distributed under the
6// 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
25// 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]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000030def MipsLo : SDNode<"MipsISD::Lo", SDTIntUnaryOp>;
31
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +000032// Necessary to generate glued instructions when loading GlobalAddress
33// into registers.
34def MipsAdd : SDNode<"MipsISD::Add", SDTIntBinOp, [SDNPCommutative,
35 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
Dan Gohmanf17a25c2007-07-18 16:29:46 +000040// Return
41def SDT_MipsRet : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
42def MipsRet : SDNode<"MipsISD::Ret", SDT_MipsRet, [SDNPHasChain,
43 SDNPOptInFlag]>;
44
45// These are target-independent nodes, but have target-specific formats.
46def SDT_MipsCallSeq : SDTypeProfile<0, 1, [SDTCisVT<0, i32>]>;
47def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_MipsCallSeq,
48 [SDNPHasChain, SDNPOutFlag]>;
49def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_MipsCallSeq,
50 [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>;
66def 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();
90 else
91 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();
101 else
102 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
115// Mips Address Mode! SDNode frameindex could possibily be a match
116// 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
124let isCommutable = 1 in
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000125class ArithR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
126 InstrItinClass itin>:
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000127 FR< op,
128 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000129 (outs CPURegs:$dst),
130 (ins CPURegs:$b, CPURegs:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000131 !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
134let isCommutable = 1 in
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000135class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm>:
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000136 FR< op,
137 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000138 (outs CPURegs:$dst),
139 (ins CPURegs:$b, CPURegs:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000140 !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
145class ArithI<bits<6> op, string instr_asm, SDNode OpNode,
146 Operand Od, PatLeaf imm_type> :
147 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000148 (outs CPURegs:$dst),
149 (ins CPURegs:$b, Od:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000150 !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
155class MArithR<bits<6> func, string instr_asm> :
156 FR< 0x1c,
157 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000158 (outs CPURegs:$rs),
159 (ins CPURegs:$rt),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000160 !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>:
165 FR< 0x00,
166 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000167 (outs CPURegs:$dst),
168 (ins CPURegs:$b, CPURegs:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000169 !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>:
180 FR< op,
181 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000182 (outs CPURegs:$dst),
183 (ins CPURegs:$b, CPURegs:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000184 !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>:
190 FR< 0x00,
191 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000192 (outs CPURegs:$dst),
193 (ins CPURegs:$b, shamt:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +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>:
198 FR< 0x00,
199 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000200 (outs CPURegs:$dst),
201 (ins CPURegs:$b, CPURegs:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +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
213// 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>;
248}
249
250// 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)
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000289let isCall=1, hasDelaySlot=1,
290 // All calls clobber the non-callee saved registers...
291 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 {
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000293 class JumpLink<bits<6> op, string instr_asm>:
294 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
317// Mul, Div
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000318class MulDiv<bits<6> func, string instr_asm, InstrItinClass itin>:
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000319 FR< 0x00,
320 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000321 (outs),
322 (ins CPURegs:$a, CPURegs:$b),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000323 !strconcat(instr_asm, " $a, $b"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000324 [], itin>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000325
326// Move from Hi/Lo
327class MoveFromTo<bits<6> func, string instr_asm>:
328 FR< 0x00,
329 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000330 (outs CPURegs:$dst),
331 (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +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>:
337 FR< 0x1c,
338 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000339 (outs CPURegs:$dst),
340 (ins CPURegs:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000341 !strconcat(instr_asm, " $dst, $src"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000342 [], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000343
Bruno Cardoso Lopes96433662007-09-24 20:15:11 +0000344class EffectiveAddress<string instr_asm> :
345 FI<0x09,
346 (outs CPURegs:$dst),
347 (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
369// 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
372// from the assembler.
373def CPLOAD: PseudoInstMips<(outs), (ins CPURegs:$reg),
374 ".set noreorder\n\t.cpload $reg\n\t.set reorder", []>;
375def CPRESTORE: PseudoInstMips<(outs), (ins uimm16:$loc),
376 ".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".
381def LA: PseudoInstMips<(outs CPURegs:$dst), (ins addrlabel:$label),
382 "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
417// Shifts
418def 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
442let rt=1 in
443def 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
475// Move From Hi/Lo
476def MFHI : MoveFromTo<0x10, "mfhi">;
477def MFLO : MoveFromTo<0x12, "mflo">;
478def MTHI : MoveFromTo<0x11, "mthi">;
479def MTLO : MoveFromTo<0x13, "mtlo">;
480
481// Count Leading
482def CLO : CountLeading<0x21, "clo">;
483def CLZ : CountLeading<0x20, "clz">;
484
485// No operation
486let addr=0 in
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000487def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000488
489// Ret instruction - as mips does not have "ret" a
490// jr $ra must be generated.
Evan Cheng37e7c752007-07-21 00:34:19 +0000491let isReturn=1, isTerminator=1, hasDelaySlot=1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000492 isBarrier=1, hasCtrlDep=1, rs=0, rt=0, shamt=0 in
493{
Evan Chengb783fa32007-07-19 01:14:50 +0000494 def RET : FR <0x00, 0x02, (outs), (ins CPURegs:$target),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000495 "jr $target", [(MipsRet CPURegs:$target)], IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000496}
497
Bruno Cardoso Lopes96433662007-09-24 20:15:11 +0000498// FrameIndexes are legalized when they are operands from load/store
499// instructions. The same not happens for stack address copies, so an
500// add op with mem ComplexPattern is used and the stack address copy
501// can be matched. It's similar to Sparc LEA_ADDRi
502def LEA_ADDiu : EffectiveAddress<"addiu $dst, ${addr:stackloc}">;
503
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000504//===----------------------------------------------------------------------===//
505// Arbitrary patterns that map to one or more instructions
506//===----------------------------------------------------------------------===//
507
508// Small immediates
509def : Pat<(i32 immSExt16:$in),
510 (ADDiu ZERO, imm:$in)>;
511def : Pat<(i32 immZExt16:$in),
512 (ORi ZERO, imm:$in)>;
513
514// Arbitrary immediates
515def : Pat<(i32 imm:$imm),
516 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
517
518// Call
519def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
520 (JAL tglobaladdr:$dst)>;
521def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
522 (JAL texternalsym:$dst)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000523def : Pat<(MipsJmpLink CPURegs:$dst),
524 (JALR CPURegs:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000525
526// GlobalAddress, Constant Pool, ExternalSymbol, and JumpTable
527def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
528def : Pat<(MipsLo tglobaladdr:$in), (ADDiu ZERO, tglobaladdr:$in)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000529def : Pat<(MipsAdd CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
530 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +0000531def : Pat<(MipsLoadAddr tglobaladdr:$in), (LA tglobaladdr:$in)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000532
533// Mips does not have not, so we increase the operation
534def : Pat<(not CPURegs:$in),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000535 (NOR CPURegs:$in, ZERO)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000536
537// extended load and stores
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000538def : Pat<(i32 (extloadi1 addr:$src)), (LBu addr:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000539def : Pat<(i32 (extloadi8 addr:$src)), (LBu addr:$src)>;
540def : Pat<(i32 (extloadi16 addr:$src)), (LHu addr:$src)>;
541def : Pat<(truncstorei1 CPURegs:$src, addr:$addr),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000542 (SB CPURegs:$src, addr:$addr)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000543
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000544///
545/// brcond patterns
546///
547
548// direct match equal/notequal zero branches
549def : Pat<(brcond (setne CPURegs:$lhs, 0), bb:$dst),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000550 (BNE CPURegs:$lhs, ZERO, bb:$dst)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000551def : Pat<(brcond (seteq CPURegs:$lhs, 0), bb:$dst),
552 (BEQ CPURegs:$lhs, ZERO, bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000553
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000554def : Pat<(brcond (setge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000555 (BGEZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000556def : Pat<(brcond (setuge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000557 (BGEZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000558
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000559def : Pat<(brcond (setgt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
560 (BGTZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
561def : Pat<(brcond (setugt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
562 (BGTZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
563
564def : Pat<(brcond (setle CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
565 (BLEZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
566def : Pat<(brcond (setule CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
567 (BLEZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
568
569def : Pat<(brcond (setlt CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000570 (BNE (SLTi CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000571def : Pat<(brcond (setult CPURegs:$lhs, immZExt16:$rhs), bb:$dst),
572 (BNE (SLTiu CPURegs:$lhs, immZExt16:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000573def : Pat<(brcond (setlt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
574 (BNE (SLT CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
575def : Pat<(brcond (setult CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
576 (BNE (SLTu CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
577
578def : Pat<(brcond (setlt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
579 (BLTZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
580def : Pat<(brcond (setult CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
581 (BLTZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
582
583// generic brcond pattern
584def : Pat<(brcond CPURegs:$cond, bb:$dst),
585 (BNE CPURegs:$cond, ZERO, bb:$dst)>;
586
587///
588/// setcc patterns, only matched when there
589/// is no brcond following a setcc operation
590///
591
592// setcc 2 register operands
593def : Pat<(setle CPURegs:$lhs, CPURegs:$rhs),
594 (XORi (SLT CPURegs:$rhs, CPURegs:$lhs), 1)>;
595def : Pat<(setule CPURegs:$lhs, CPURegs:$rhs),
596 (XORi (SLTu CPURegs:$rhs, CPURegs:$lhs), 1)>;
597
598def : Pat<(setgt CPURegs:$lhs, CPURegs:$rhs),
599 (SLT CPURegs:$rhs, CPURegs:$lhs)>;
600def : Pat<(setugt CPURegs:$lhs, CPURegs:$rhs),
601 (SLTu CPURegs:$rhs, CPURegs:$lhs)>;
602
603def : Pat<(setge CPURegs:$lhs, CPURegs:$rhs),
604 (XORi (SLT CPURegs:$lhs, CPURegs:$rhs), 1)>;
605def : Pat<(setuge CPURegs:$lhs, CPURegs:$rhs),
606 (XORi (SLTu CPURegs:$lhs, CPURegs:$rhs), 1)>;
607
608def : Pat<(setne CPURegs:$lhs, CPURegs:$rhs),
609 (OR (SLT CPURegs:$lhs, CPURegs:$rhs),
610 (SLT CPURegs:$rhs, CPURegs:$lhs))>;
611
612def : Pat<(seteq CPURegs:$lhs, CPURegs:$rhs),
613 (XORi (OR (SLT CPURegs:$lhs, CPURegs:$rhs),
614 (SLT CPURegs:$rhs, CPURegs:$lhs)), 1)>;
615
616// setcc reg/imm operands
617def : Pat<(setge CPURegs:$lhs, immSExt16:$rhs),
618 (XORi (SLTi CPURegs:$lhs, immSExt16:$rhs), 1)>;
619def : Pat<(setuge CPURegs:$lhs, immZExt16:$rhs),
620 (XORi (SLTiu CPURegs:$lhs, immZExt16:$rhs), 1)>;
621