blob: 7441c78a0330bb8ce8034044d8b36c0331194cb0 [file] [log] [blame]
Akira Hatanakadf98a7a2012-05-24 18:32:33 +00001//===- Mips16InstrInfo.td - Target Description for Mips16 -*- tablegen -*-=//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file describes Mips16 instructions.
11//
12//===----------------------------------------------------------------------===//
Reed Kotler24032212012-10-05 18:27:54 +000013//
Reed Kotler3589dd72012-10-28 06:02:37 +000014//
15// Mips Address
16//
17def addr16 :
Akira Hatanaka040d2252013-03-14 18:33:23 +000018 ComplexPattern<iPTR, 3, "selectAddr16", [frameindex], [SDNPWantParent]>;
Akira Hatanaka26e9ecb2012-07-23 23:45:54 +000019
20//
Reed Kotler0f2e44a2012-10-10 01:58:16 +000021// Address operand
22def mem16 : Operand<i32> {
23 let PrintMethod = "printMemOperand";
Reed Kotler30cedf62013-08-04 01:13:25 +000024 let MIOperandInfo = (ops CPU16Regs, simm16, CPU16RegsPlusSP);
Reed Kotler3589dd72012-10-28 06:02:37 +000025 let EncoderMethod = "getMemEncoding";
26}
27
28def mem16_ea : Operand<i32> {
29 let PrintMethod = "printMemOperandEA";
Reed Kotler30cedf62013-08-04 01:13:25 +000030 let MIOperandInfo = (ops CPU16RegsPlusSP, simm16);
Reed Kotler0f2e44a2012-10-10 01:58:16 +000031 let EncoderMethod = "getMemEncoding";
Akira Hatanaka22bec282012-08-03 22:57:02 +000032}
33
Reed Kotler0f2e44a2012-10-10 01:58:16 +000034//
Reed Kotlerf0e69682013-11-12 02:27:12 +000035// I-type instruction format
36//
37// this is only used by bimm. the actual assembly value is a 12 bit signed
38// number
39//
40class FI16_ins<bits<5> op, string asmstr, InstrItinClass itin>:
41 FI16<op, (outs), (ins brtarget:$imm16),
42 !strconcat(asmstr, "\t$imm16 # 16 bit inst"), [], itin>;
43
44//
Reed Kotlerf662cff2013-02-13 20:28:27 +000045//
46// I8 instruction format
47//
48
49class FI816_ins_base<bits<3> _func, string asmstr,
50 string asmstr2, InstrItinClass itin>:
51 FI816<_func, (outs), (ins simm16:$imm), !strconcat(asmstr, asmstr2),
52 [], itin>;
53
Reed Kotler09e59152013-11-15 02:21:52 +000054class FI816_ins<bits<3> _func, string asmstr,
55 InstrItinClass itin>:
56 FI816_ins_base<_func, asmstr, "\t$imm # 16 bit inst", itin>;
57
Reed Kotlerf662cff2013-02-13 20:28:27 +000058class FI816_SP_ins<bits<3> _func, string asmstr,
59 InstrItinClass itin>:
60 FI816_ins_base<_func, asmstr, "\t$$sp, $imm # 16 bit inst", itin>;
61
62//
Reed Kotlerb9bf8dc2013-02-08 21:42:56 +000063// RI instruction format
64//
65
66
Reed Kotlerd8217192013-02-19 00:20:58 +000067class FRI16_ins_base<bits<5> op, string asmstr, string asmstr2,
68 InstrItinClass itin>:
69 FRI16<op, (outs CPU16Regs:$rx), (ins simm16:$imm),
70 !strconcat(asmstr, asmstr2), [], itin>;
71
72class FRI16_ins<bits<5> op, string asmstr,
73 InstrItinClass itin>:
74 FRI16_ins_base<op, asmstr, "\t$rx, $imm \t# 16 bit inst", itin>;
Reed Kotler7b503c22013-02-20 05:45:15 +000075
Reed Kotler0f007fc2013-11-05 08:14:14 +000076class FRI16_TCP_ins<bits<5> _op, string asmstr,
77 InstrItinClass itin>:
78 FRI16<_op, (outs CPU16Regs:$rx), (ins pcrel16:$imm, i32imm:$size),
79 !strconcat(asmstr, "\t$rx, $imm\t# 16 bit inst"), [], itin>;
80
Reed Kotler7b503c22013-02-20 05:45:15 +000081class FRI16R_ins_base<bits<5> op, string asmstr, string asmstr2,
82 InstrItinClass itin>:
83 FRI16<op, (outs), (ins CPU16Regs:$rx, simm16:$imm),
84 !strconcat(asmstr, asmstr2), [], itin>;
85
86class FRI16R_ins<bits<5> op, string asmstr,
87 InstrItinClass itin>:
88 FRI16R_ins_base<op, asmstr, "\t$rx, $imm \t# 16 bit inst", itin>;
89
Reed Kotlerb9bf8dc2013-02-08 21:42:56 +000090class F2RI16_ins<bits<5> _op, string asmstr,
91 InstrItinClass itin>:
92 FRI16<_op, (outs CPU16Regs:$rx), (ins CPU16Regs:$rx_, simm16:$imm),
93 !strconcat(asmstr, "\t$rx, $imm\t# 16 bit inst"), [], itin> {
94 let Constraints = "$rx_ = $rx";
95}
96
Reed Kotler97ba5f22013-02-21 04:22:38 +000097class FRI16_B_ins<bits<5> _op, string asmstr,
98 InstrItinClass itin>:
99 FRI16<_op, (outs), (ins CPU16Regs:$rx, brtarget:$imm),
100 !strconcat(asmstr, "\t$rx, $imm # 16 bit inst"), [], itin>;
Reed Kotlerb9bf8dc2013-02-08 21:42:56 +0000101//
Reed Kotler164bb372012-10-23 01:35:48 +0000102// Compare a register and immediate and place result in CC
103// Implicit use of T8
104//
105// EXT-CCRR Instruction format
106//
Reed Kotler61b474f2013-02-16 23:39:52 +0000107class FEXT_CCRXI16_ins<string asmstr>:
108 MipsPseudo16<(outs CPU16Regs:$cc), (ins CPU16Regs:$rx, simm16:$imm),
109 !strconcat(asmstr, "\t$rx, $imm\n\tmove\t$cc, $$t8"), []> {
Reed Kotler164bb372012-10-23 01:35:48 +0000110 let isCodeGenOnly=1;
Reed Kotlerbd1058a2013-02-25 02:25:47 +0000111 let usesCustomInserter = 1;
Reed Kotler164bb372012-10-23 01:35:48 +0000112}
113
Reed Kotlerf8933f82013-02-02 04:07:35 +0000114// JAL and JALX instruction format
115//
116class FJAL16_ins<bits<1> _X, string asmstr,
117 InstrItinClass itin>:
118 FJAL16<_X, (outs), (ins simm20:$imm),
119 !strconcat(asmstr, "\t$imm\n\tnop"),[],
120 itin> {
121 let isCodeGenOnly=1;
122}
Reed Kotler164bb372012-10-23 01:35:48 +0000123//
Reed Kotler67439242012-10-17 22:29:54 +0000124// EXT-I instruction format
125//
126class FEXT_I16_ins<bits<5> eop, string asmstr, InstrItinClass itin> :
127 FEXT_I16<eop, (outs), (ins brtarget:$imm16),
128 !strconcat(asmstr, "\t$imm16"),[], itin>;
129
130//
131// EXT-I8 instruction format
132//
133
134class FEXT_I816_ins_base<bits<3> _func, string asmstr,
135 string asmstr2, InstrItinClass itin>:
Reed Kotlerd019dbf2012-12-20 04:07:42 +0000136 FEXT_I816<_func, (outs), (ins simm16:$imm), !strconcat(asmstr, asmstr2),
Reed Kotler67439242012-10-17 22:29:54 +0000137 [], itin>;
138
139class FEXT_I816_ins<bits<3> _func, string asmstr,
140 InstrItinClass itin>:
141 FEXT_I816_ins_base<_func, asmstr, "\t$imm", itin>;
142
Reed Kotlerd019dbf2012-12-20 04:07:42 +0000143class FEXT_I816_SP_ins<bits<3> _func, string asmstr,
144 InstrItinClass itin>:
145 FEXT_I816_ins_base<_func, asmstr, "\t$$sp, $imm", itin>;
146
Reed Kotler67439242012-10-17 22:29:54 +0000147//
Reed Kotler0f2e44a2012-10-10 01:58:16 +0000148// Assembler formats in alphabetical order.
149// Natural and pseudos are mixed together.
150//
Reed Kotler164bb372012-10-23 01:35:48 +0000151// Compare two registers and place result in CC
152// Implicit use of T8
153//
154// CC-RR Instruction format
155//
Reed Kotler61b474f2013-02-16 23:39:52 +0000156class FCCRR16_ins<string asmstr> :
157 MipsPseudo16<(outs CPU16Regs:$cc), (ins CPU16Regs:$rx, CPU16Regs:$ry),
158 !strconcat(asmstr, "\t$rx, $ry\n\tmove\t$cc, $$t8"), []> {
Reed Kotler164bb372012-10-23 01:35:48 +0000159 let isCodeGenOnly=1;
Reed Kotlerbd1058a2013-02-25 02:25:47 +0000160 let usesCustomInserter = 1;
Reed Kotler164bb372012-10-23 01:35:48 +0000161}
162
Akira Hatanaka26e9ecb2012-07-23 23:45:54 +0000163//
Reed Kotler210ebe92012-09-28 02:26:24 +0000164// EXT-RI instruction format
165//
166
167class FEXT_RI16_ins_base<bits<5> _op, string asmstr, string asmstr2,
168 InstrItinClass itin>:
169 FEXT_RI16<_op, (outs CPU16Regs:$rx), (ins simm16:$imm),
170 !strconcat(asmstr, asmstr2), [], itin>;
171
172class FEXT_RI16_ins<bits<5> _op, string asmstr,
173 InstrItinClass itin>:
174 FEXT_RI16_ins_base<_op, asmstr, "\t$rx, $imm", itin>;
175
Reed Kotler7b503c22013-02-20 05:45:15 +0000176class FEXT_RI16R_ins_base<bits<5> _op, string asmstr, string asmstr2,
177 InstrItinClass itin>:
178 FEXT_RI16<_op, (outs ), (ins CPU16Regs:$rx, simm16:$imm),
179 !strconcat(asmstr, asmstr2), [], itin>;
180
181class FEXT_RI16R_ins<bits<5> _op, string asmstr,
182 InstrItinClass itin>:
183 FEXT_RI16R_ins_base<_op, asmstr, "\t$rx, $imm", itin>;
184
Reed Kotler210ebe92012-09-28 02:26:24 +0000185class FEXT_RI16_PC_ins<bits<5> _op, string asmstr, InstrItinClass itin>:
186 FEXT_RI16_ins_base<_op, asmstr, "\t$rx, $$pc, $imm", itin>;
187
Reed Kotler67439242012-10-17 22:29:54 +0000188class FEXT_RI16_B_ins<bits<5> _op, string asmstr,
189 InstrItinClass itin>:
190 FEXT_RI16<_op, (outs), (ins CPU16Regs:$rx, brtarget:$imm),
191 !strconcat(asmstr, "\t$rx, $imm"), [], itin>;
192
Reed Kotler91ae9822013-10-27 21:57:36 +0000193class FEXT_RI16_TCP_ins<bits<5> _op, string asmstr,
194 InstrItinClass itin>:
Reed Kotler0f007fc2013-11-05 08:14:14 +0000195 FEXT_RI16<_op, (outs CPU16Regs:$rx), (ins pcrel16:$imm, i32imm:$size),
Reed Kotler91ae9822013-10-27 21:57:36 +0000196 !strconcat(asmstr, "\t$rx, $imm"), [], itin>;
197
Reed Kotler210ebe92012-09-28 02:26:24 +0000198class FEXT_2RI16_ins<bits<5> _op, string asmstr,
199 InstrItinClass itin>:
200 FEXT_RI16<_op, (outs CPU16Regs:$rx), (ins CPU16Regs:$rx_, simm16:$imm),
201 !strconcat(asmstr, "\t$rx, $imm"), [], itin> {
202 let Constraints = "$rx_ = $rx";
203}
Reed Kotler24032212012-10-05 18:27:54 +0000204
Reed Kotler67439242012-10-17 22:29:54 +0000205
Reed Kotler210ebe92012-09-28 02:26:24 +0000206// this has an explicit sp argument that we ignore to work around a problem
207// in the compiler
208class FEXT_RI16_SP_explicit_ins<bits<5> _op, string asmstr,
209 InstrItinClass itin>:
210 FEXT_RI16<_op, (outs CPU16Regs:$rx), (ins CPUSPReg:$ry, simm16:$imm),
Reed Kotler24032212012-10-05 18:27:54 +0000211 !strconcat(asmstr, "\t$rx, $imm ( $ry ); "), [], itin>;
Reed Kotler210ebe92012-09-28 02:26:24 +0000212
Reed Kotler30cedf62013-08-04 01:13:25 +0000213class FEXT_RI16_SP_Store_explicit_ins<bits<5> _op, string asmstr,
214 InstrItinClass itin>:
215 FEXT_RI16<_op, (outs), (ins CPU16Regs:$rx, CPUSPReg:$ry, simm16:$imm),
216 !strconcat(asmstr, "\t$rx, $imm ( $ry ); "), [], itin>;
217
Reed Kotler210ebe92012-09-28 02:26:24 +0000218//
Akira Hatanaka26e9ecb2012-07-23 23:45:54 +0000219// EXT-RRI instruction format
220//
221
222class FEXT_RRI16_mem_ins<bits<5> op, string asmstr, Operand MemOpnd,
223 InstrItinClass itin>:
224 FEXT_RRI16<op, (outs CPU16Regs:$ry), (ins MemOpnd:$addr),
225 !strconcat(asmstr, "\t$ry, $addr"), [], itin>;
226
Akira Hatanaka22bec282012-08-03 22:57:02 +0000227class FEXT_RRI16_mem2_ins<bits<5> op, string asmstr, Operand MemOpnd,
228 InstrItinClass itin>:
229 FEXT_RRI16<op, (outs ), (ins CPU16Regs:$ry, MemOpnd:$addr),
230 !strconcat(asmstr, "\t$ry, $addr"), [], itin>;
231
Akira Hatanaka26e9ecb2012-07-23 23:45:54 +0000232//
Reed Kotler3589dd72012-10-28 06:02:37 +0000233//
234// EXT-RRI-A instruction format
235//
236
237class FEXT_RRI_A16_mem_ins<bits<1> op, string asmstr, Operand MemOpnd,
238 InstrItinClass itin>:
239 FEXT_RRI_A16<op, (outs CPU16Regs:$ry), (ins MemOpnd:$addr),
240 !strconcat(asmstr, "\t$ry, $addr"), [], itin>;
241
242//
Akira Hatanaka26e9ecb2012-07-23 23:45:54 +0000243// EXT-SHIFT instruction format
244//
245class FEXT_SHIFT16_ins<bits<2> _f, string asmstr, InstrItinClass itin>:
Akira Hatanaka31213532013-09-07 00:02:02 +0000246 FEXT_SHIFT16<_f, (outs CPU16Regs:$rx), (ins CPU16Regs:$ry, uimm5:$sa),
Akira Hatanaka26e9ecb2012-07-23 23:45:54 +0000247 !strconcat(asmstr, "\t$rx, $ry, $sa"), [], itin>;
248
Reed Kotler67439242012-10-17 22:29:54 +0000249//
250// EXT-T8I8
251//
Reed Kotler61b474f2013-02-16 23:39:52 +0000252class FEXT_T8I816_ins<string asmstr, string asmstr2>:
253 MipsPseudo16<(outs),
254 (ins CPU16Regs:$rx, CPU16Regs:$ry, brtarget:$imm),
255 !strconcat(asmstr2, !strconcat("\t$rx, $ry\n\t",
256 !strconcat(asmstr, "\t$imm"))),[]> {
Reed Kotler67439242012-10-17 22:29:54 +0000257 let isCodeGenOnly=1;
Reed Kotlere2bead72013-02-24 06:16:39 +0000258 let usesCustomInserter = 1;
Reed Kotler67439242012-10-17 22:29:54 +0000259}
260
261//
262// EXT-T8I8I
263//
Reed Kotler61b474f2013-02-16 23:39:52 +0000264class FEXT_T8I8I16_ins<string asmstr, string asmstr2>:
265 MipsPseudo16<(outs),
266 (ins CPU16Regs:$rx, simm16:$imm, brtarget:$targ),
267 !strconcat(asmstr2, !strconcat("\t$rx, $imm\n\t",
268 !strconcat(asmstr, "\t$targ"))), []> {
Reed Kotler67439242012-10-17 22:29:54 +0000269 let isCodeGenOnly=1;
Reed Kotler7a86b3d2013-02-24 23:17:51 +0000270 let usesCustomInserter = 1;
Reed Kotler67439242012-10-17 22:29:54 +0000271}
272//
273
Reed Kotler0f2e44a2012-10-10 01:58:16 +0000274
Akira Hatanaka26e9ecb2012-07-23 23:45:54 +0000275//
Reed Kotler0f2e44a2012-10-10 01:58:16 +0000276// I8_MOVR32 instruction format (used only by the MOVR32 instructio
277//
278class FI8_MOVR3216_ins<string asmstr, InstrItinClass itin>:
Akira Hatanaka13e6ccf2013-08-06 23:08:38 +0000279 FI8_MOVR3216<(outs CPU16Regs:$rz), (ins GPR32:$r32),
Reed Kotler0f2e44a2012-10-10 01:58:16 +0000280 !strconcat(asmstr, "\t$rz, $r32"), [], itin>;
281
282//
283// I8_MOV32R instruction format (used only by MOV32R instruction)
284//
285
286class FI8_MOV32R16_ins<string asmstr, InstrItinClass itin>:
Akira Hatanaka13e6ccf2013-08-06 23:08:38 +0000287 FI8_MOV32R16<(outs GPR32:$r32), (ins CPU16Regs:$rz),
Reed Kotler0f2e44a2012-10-10 01:58:16 +0000288 !strconcat(asmstr, "\t$r32, $rz"), [], itin>;
289
290//
291// This are pseudo formats for multiply
292// This first one can be changed to non pseudo now.
293//
294// MULT
295//
296class FMULT16_ins<string asmstr, InstrItinClass itin> :
297 MipsPseudo16<(outs), (ins CPU16Regs:$rx, CPU16Regs:$ry),
298 !strconcat(asmstr, "\t$rx, $ry"), []>;
299
300//
301// MULT-LO
302//
303class FMULT16_LO_ins<string asmstr, InstrItinClass itin> :
304 MipsPseudo16<(outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
305 !strconcat(asmstr, "\t$rx, $ry\n\tmflo\t$rz"), []> {
306 let isCodeGenOnly=1;
Akira Hatanaka26e9ecb2012-07-23 23:45:54 +0000307}
308
309//
Reed Kotler0f2e44a2012-10-10 01:58:16 +0000310// RR-type instruction format
311//
312
313class FRR16_ins<bits<5> f, string asmstr, InstrItinClass itin> :
314 FRR16<f, (outs CPU16Regs:$rx), (ins CPU16Regs:$ry),
315 !strconcat(asmstr, "\t$rx, $ry"), [], itin> {
316}
Reed Kotlercf11c592012-10-12 02:01:09 +0000317
Reed Kotlerbb870e22013-08-07 04:00:26 +0000318class FRRBreakNull16_ins<string asmstr, InstrItinClass itin> :
319 FRRBreak16<(outs), (ins), asmstr, [], itin> {
320 let Code=0;
321}
322
Reed Kotler80070bd2013-02-23 23:37:03 +0000323class FRR16R_ins<bits<5> f, string asmstr, InstrItinClass itin> :
324 FRR16<f, (outs), (ins CPU16Regs:$rx, CPU16Regs:$ry),
325 !strconcat(asmstr, "\t$rx, $ry"), [], itin> {
326}
327
Reed Kotler61b474f2013-02-16 23:39:52 +0000328class FRRTR16_ins<string asmstr> :
329 MipsPseudo16<(outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
330 !strconcat(asmstr, "\t$rx, $ry\n\tmove\t$rz, $$t8"), []> ;
Reed Kotler287f0442012-10-26 04:46:26 +0000331
Reed Kotlercf11c592012-10-12 02:01:09 +0000332//
333// maybe refactor but need a $zero as a dummy first parameter
334//
335class FRR16_div_ins<bits<5> f, string asmstr, InstrItinClass itin> :
336 FRR16<f, (outs ), (ins CPU16Regs:$rx, CPU16Regs:$ry),
337 !strconcat(asmstr, "\t$$zero, $rx, $ry"), [], itin> ;
338
Reed Kotler4e1c6292012-10-26 16:18:19 +0000339class FUnaryRR16_ins<bits<5> f, string asmstr, InstrItinClass itin> :
340 FRR16<f, (outs CPU16Regs:$rx), (ins CPU16Regs:$ry),
341 !strconcat(asmstr, "\t$rx, $ry"), [], itin> ;
342
343
Reed Kotler0f2e44a2012-10-10 01:58:16 +0000344class FRR16_M_ins<bits<5> f, string asmstr,
345 InstrItinClass itin> :
346 FRR16<f, (outs CPU16Regs:$rx), (ins),
347 !strconcat(asmstr, "\t$rx"), [], itin>;
348
349class FRxRxRy16_ins<bits<5> f, string asmstr,
350 InstrItinClass itin> :
351 FRR16<f, (outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
352 !strconcat(asmstr, "\t$rz, $ry"),
353 [], itin> {
354 let Constraints = "$rx = $rz";
355}
356
357let rx=0 in
358class FRR16_JALRC_RA_only_ins<bits<1> nd_, bits<1> l_,
359 string asmstr, InstrItinClass itin>:
360 FRR16_JALRC<nd_, l_, 1, (outs), (ins), !strconcat(asmstr, "\t $$ra"),
361 [], itin> ;
362
Reed Kotlere6c31572012-10-28 23:08:07 +0000363
364class FRR16_JALRC_ins<bits<1> nd, bits<1> l, bits<1> ra,
365 string asmstr, InstrItinClass itin>:
Jack Carter7ab15fa2013-01-19 02:00:40 +0000366 FRR16_JALRC<nd, l, ra, (outs), (ins CPU16Regs:$rx),
Reed Kotlere6c31572012-10-28 23:08:07 +0000367 !strconcat(asmstr, "\t $rx"), [], itin> ;
368
Reed Kotler445d0ad2013-10-07 20:46:19 +0000369class FRR_SF16_ins
370 <bits<5> _funct, bits<3> _subfunc,
371 string asmstr, InstrItinClass itin>:
372 FRR_SF16<_funct, _subfunc, (outs CPU16Regs:$rx), (ins CPU16Regs:$rx_),
373 !strconcat(asmstr, "\t $rx"),
374 [], itin> {
375 let Constraints = "$rx_ = $rx";
376 }
Reed Kotler0f2e44a2012-10-10 01:58:16 +0000377//
378// RRR-type instruction format
379//
380
381class FRRR16_ins<bits<2> _f, string asmstr, InstrItinClass itin> :
382 FRRR16<_f, (outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
383 !strconcat(asmstr, "\t$rz, $rx, $ry"), [], itin>;
384
385//
Reed Kotler097556d2012-10-25 21:33:30 +0000386// These Sel patterns support the generation of conditional move
387// pseudo instructions.
388//
389// The nomenclature uses the components making up the pseudo and may
390// be a bit counter intuitive when compared with the end result we seek.
391// For example using a bqez in the example directly below results in the
392// conditional move being done if the tested register is not zero.
393// I considered in easier to check by keeping the pseudo consistent with
394// it's components but it could have been done differently.
395//
396// The simplest case is when can test and operand directly and do the
397// conditional move based on a simple mips16 conditional
398// branch instruction.
399// for example:
400// if $op == beqz or bnez:
401//
402// $op1 $rt, .+4
403// move $rd, $rs
404//
405// if $op == beqz, then if $rt != 0, then the conditional assignment
406// $rd = $rs is done.
407
408// if $op == bnez, then if $rt == 0, then the conditional assignment
409// $rd = $rs is done.
410//
411// So this pseudo class only has one operand, i.e. op
412//
Reed Kotler61b474f2013-02-16 23:39:52 +0000413class Sel<string op>:
414 MipsPseudo16<(outs CPU16Regs:$rd_), (ins CPU16Regs:$rd, CPU16Regs:$rs,
415 CPU16Regs:$rt),
416 !strconcat(op, "\t$rt, .+4\n\t\n\tmove $rd, $rs"), []> {
417 //let isCodeGenOnly=1;
Reed Kotler097556d2012-10-25 21:33:30 +0000418 let Constraints = "$rd = $rd_";
Reed Kotler97ba5f22013-02-21 04:22:38 +0000419 let usesCustomInserter = 1;
Reed Kotler097556d2012-10-25 21:33:30 +0000420}
421
422//
423// The next two instruction classes allow for an operand which tests
424// two operands and returns a value in register T8 and
425//then does a conditional branch based on the value of T8
426//
427
428// op2 can be cmpi or slti/sltiu
429// op1 can bteqz or btnez
430// the operands for op2 are a register and a signed constant
431//
432// $op2 $t, $imm ;test register t and branch conditionally
433// $op1 .+4 ;op1 is a conditional branch
434// move $rd, $rs
435//
436//
Reed Kotler61b474f2013-02-16 23:39:52 +0000437class SeliT<string op1, string op2>:
438 MipsPseudo16<(outs CPU16Regs:$rd_), (ins CPU16Regs:$rd, CPU16Regs:$rs,
439 CPU16Regs:$rl, simm16:$imm),
440 !strconcat(op2,
441 !strconcat("\t$rl, $imm\n\t",
442 !strconcat(op1, "\t.+4\n\tmove $rd, $rs"))), []> {
Reed Kotler097556d2012-10-25 21:33:30 +0000443 let isCodeGenOnly=1;
444 let Constraints = "$rd = $rd_";
Reed Kotler4416cda2013-02-22 05:10:51 +0000445 let usesCustomInserter = 1;
Reed Kotler097556d2012-10-25 21:33:30 +0000446}
447
448//
449// op2 can be cmp or slt/sltu
450// op1 can be bteqz or btnez
451// the operands for op2 are two registers
452// op1 is a conditional branch
453//
454//
455// $op2 $rl, $rr ;test registers rl,rr
456// $op1 .+4 ;op2 is a conditional branch
457// move $rd, $rs
458//
459//
Reed Kotler61b474f2013-02-16 23:39:52 +0000460class SelT<string op1, string op2>:
Reed Kotler7b503c22013-02-20 05:45:15 +0000461 MipsPseudo16<(outs CPU16Regs:$rd_),
Reed Kotler61b474f2013-02-16 23:39:52 +0000462 (ins CPU16Regs:$rd, CPU16Regs:$rs,
Reed Kotler097556d2012-10-25 21:33:30 +0000463 CPU16Regs:$rl, CPU16Regs:$rr),
Reed Kotler61b474f2013-02-16 23:39:52 +0000464 !strconcat(op2,
465 !strconcat("\t$rl, $rr\n\t",
466 !strconcat(op1, "\t.+4\n\tmove $rd, $rs"))), []> {
Reed Kotler097556d2012-10-25 21:33:30 +0000467 let isCodeGenOnly=1;
468 let Constraints = "$rd = $rd_";
Reed Kotlerdacee2b2013-02-23 03:09:56 +0000469 let usesCustomInserter = 1;
Reed Kotler097556d2012-10-25 21:33:30 +0000470}
471
Reed Kotlerd019dbf2012-12-20 04:07:42 +0000472//
473// 32 bit constant
474//
475def imm32: Operand<i32>;
476
477def Constant32:
478 MipsPseudo16<(outs), (ins imm32:$imm), "\t.word $imm", []>;
Jack Carter7ab15fa2013-01-19 02:00:40 +0000479
Reed Kotlerd019dbf2012-12-20 04:07:42 +0000480def LwConstant32:
Reed Kotler91ae9822013-10-27 21:57:36 +0000481 MipsPseudo16<(outs CPU16Regs:$rx), (ins imm32:$imm, imm32:$constid),
Reed Kotlerd019dbf2012-12-20 04:07:42 +0000482 "lw\t$rx, 1f\n\tb\t2f\n\t.align\t2\n1: \t.word\t$imm\n2:", []>;
483
Reed Kotler097556d2012-10-25 21:33:30 +0000484
485//
Akira Hatanaka22bec282012-08-03 22:57:02 +0000486// Some general instruction class info
487//
488//
489
490class ArithLogic16Defs<bit isCom=0> {
491 bits<5> shamt = 0;
492 bit isCommutable = isCom;
493 bit isReMaterializable = 1;
494 bit neverHasSideEffects = 1;
495}
496
Reed Kotler67439242012-10-17 22:29:54 +0000497class branch16 {
498 bit isBranch = 1;
499 bit isTerminator = 1;
500 bit isBarrier = 1;
501}
502
503class cbranch16 {
504 bit isBranch = 1;
505 bit isTerminator = 1;
506}
507
Reed Kotler210ebe92012-09-28 02:26:24 +0000508class MayLoad {
509 bit mayLoad = 1;
510}
511
512class MayStore {
513 bit mayStore = 1;
514}
Akira Hatanaka22bec282012-08-03 22:57:02 +0000515//
Akira Hatanaka64626fc2012-07-26 02:24:43 +0000516
Reed Kotler61b474f2013-02-16 23:39:52 +0000517
Akira Hatanaka64626fc2012-07-26 02:24:43 +0000518// Format: ADDIU rx, immediate MIPS16e
519// Purpose: Add Immediate Unsigned Word (2-Operand, Extended)
520// To add a constant to a 32-bit integer.
521//
Akira Hatanaka22bec282012-08-03 22:57:02 +0000522def AddiuRxImmX16: FEXT_RI16_ins<0b01001, "addiu", IIAlu>;
Akira Hatanaka64626fc2012-07-26 02:24:43 +0000523
Reed Kotlerb9bf8dc2013-02-08 21:42:56 +0000524def AddiuRxRxImm16: F2RI16_ins<0b01001, "addiu", IIAlu>,
525 ArithLogic16Defs<0> {
526 let AddedComplexity = 5;
527}
Akira Hatanaka22bec282012-08-03 22:57:02 +0000528def AddiuRxRxImmX16: FEXT_2RI16_ins<0b01001, "addiu", IIAlu>,
Reed Kotlerec8a5492013-02-14 03:05:25 +0000529 ArithLogic16Defs<0> {
530 let isCodeGenOnly = 1;
531}
Akira Hatanaka64626fc2012-07-26 02:24:43 +0000532
Reed Kotler3589dd72012-10-28 06:02:37 +0000533def AddiuRxRyOffMemX16:
534 FEXT_RRI_A16_mem_ins<0, "addiu", mem16_ea, IIAlu>;
535
Akira Hatanaka64626fc2012-07-26 02:24:43 +0000536//
537
Akira Hatanaka26e9ecb2012-07-23 23:45:54 +0000538// Format: ADDIU rx, pc, immediate MIPS16e
539// Purpose: Add Immediate Unsigned Word (3-Operand, PC-Relative, Extended)
540// To add a constant to the program counter.
541//
Akira Hatanaka22bec282012-08-03 22:57:02 +0000542def AddiuRxPcImmX16: FEXT_RI16_PC_ins<0b00001, "addiu", IIAlu>;
Reed Kotlerd019dbf2012-12-20 04:07:42 +0000543
544//
545// Format: ADDIU sp, immediate MIPS16e
546// Purpose: Add Immediate Unsigned Word (2-Operand, SP-Relative, Extended)
547// To add a constant to the stack pointer.
548//
Reed Kotlerf662cff2013-02-13 20:28:27 +0000549def AddiuSpImm16
550 : FI816_SP_ins<0b011, "addiu", IIAlu> {
551 let Defs = [SP];
552 let Uses = [SP];
553 let AddedComplexity = 5;
554}
555
Reed Kotlerd019dbf2012-12-20 04:07:42 +0000556def AddiuSpImmX16
557 : FEXT_I816_SP_ins<0b011, "addiu", IIAlu> {
558 let Defs = [SP];
559 let Uses = [SP];
Jack Carter7ab15fa2013-01-19 02:00:40 +0000560}
Reed Kotlerd019dbf2012-12-20 04:07:42 +0000561
Akira Hatanaka26e9ecb2012-07-23 23:45:54 +0000562//
563// Format: ADDU rz, rx, ry MIPS16e
564// Purpose: Add Unsigned Word (3-Operand)
565// To add 32-bit integers.
566//
567
Akira Hatanaka22bec282012-08-03 22:57:02 +0000568def AdduRxRyRz16: FRRR16_ins<01, "addu", IIAlu>, ArithLogic16Defs<1>;
569
570//
571// Format: AND rx, ry MIPS16e
572// Purpose: AND
573// To do a bitwise logical AND.
574
575def AndRxRxRy16: FRxRxRy16_ins<0b01100, "and", IIAlu>, ArithLogic16Defs<1>;
Reed Kotler67439242012-10-17 22:29:54 +0000576
577
578//
579// Format: BEQZ rx, offset MIPS16e
Reed Kotler97ba5f22013-02-21 04:22:38 +0000580// Purpose: Branch on Equal to Zero
581// To test a GPR then do a PC-relative conditional branch.
582//
583def BeqzRxImm16: FRI16_B_ins<0b00100, "beqz", IIAlu>, cbranch16;
584
585
586//
587// Format: BEQZ rx, offset MIPS16e
Reed Kotler67439242012-10-17 22:29:54 +0000588// Purpose: Branch on Equal to Zero (Extended)
589// To test a GPR then do a PC-relative conditional branch.
590//
591def BeqzRxImmX16: FEXT_RI16_B_ins<0b00100, "beqz", IIAlu>, cbranch16;
592
Reed Kotlerf0e69682013-11-12 02:27:12 +0000593//
594// Format: B offset MIPS16e
595// Purpose: Unconditional Branch (Extended)
596// To do an unconditional PC-relative branch.
597//
598
599def Bimm16: FI16_ins<0b00010, "b", IIAlu>, branch16;
600
Reed Kotler67439242012-10-17 22:29:54 +0000601// Format: B offset MIPS16e
602// Purpose: Unconditional Branch
603// To do an unconditional PC-relative branch.
604//
605def BimmX16: FEXT_I16_ins<0b00010, "b", IIAlu>, branch16;
606
607//
608// Format: BNEZ rx, offset MIPS16e
Reed Kotler97ba5f22013-02-21 04:22:38 +0000609// Purpose: Branch on Not Equal to Zero
610// To test a GPR then do a PC-relative conditional branch.
611//
612def BnezRxImm16: FRI16_B_ins<0b00101, "bnez", IIAlu>, cbranch16;
613
614//
615// Format: BNEZ rx, offset MIPS16e
Reed Kotler67439242012-10-17 22:29:54 +0000616// Purpose: Branch on Not Equal to Zero (Extended)
617// To test a GPR then do a PC-relative conditional branch.
618//
619def BnezRxImmX16: FEXT_RI16_B_ins<0b00101, "bnez", IIAlu>, cbranch16;
620
Reed Kotlerbb870e22013-08-07 04:00:26 +0000621
622//
623//Format: BREAK immediate
624// Purpose: Breakpoint
625// To cause a Breakpoint exception.
626
627def Break16: FRRBreakNull16_ins<"break 0", NoItinerary>;
Reed Kotler67439242012-10-17 22:29:54 +0000628//
629// Format: BTEQZ offset MIPS16e
630// Purpose: Branch on T Equal to Zero (Extended)
631// To test special register T then do a PC-relative conditional branch.
632//
Reed Kotler09e59152013-11-15 02:21:52 +0000633def Bteqz16: FI816_ins<0b000, "bteqz", IIAlu>, cbranch16 {
634 let Uses = [T8];
635}
636
Reed Kotlercb374092013-02-18 00:59:04 +0000637def BteqzX16: FEXT_I816_ins<0b000, "bteqz", IIAlu>, cbranch16 {
638 let Uses = [T8];
639}
Reed Kotler67439242012-10-17 22:29:54 +0000640
Reed Kotler61b474f2013-02-16 23:39:52 +0000641def BteqzT8CmpX16: FEXT_T8I816_ins<"bteqz", "cmp">, cbranch16;
Reed Kotler67439242012-10-17 22:29:54 +0000642
Reed Kotler61b474f2013-02-16 23:39:52 +0000643def BteqzT8CmpiX16: FEXT_T8I8I16_ins<"bteqz", "cmpi">,
Reed Kotler67439242012-10-17 22:29:54 +0000644 cbranch16;
645
Reed Kotler61b474f2013-02-16 23:39:52 +0000646def BteqzT8SltX16: FEXT_T8I816_ins<"bteqz", "slt">, cbranch16;
Reed Kotler67439242012-10-17 22:29:54 +0000647
Reed Kotler61b474f2013-02-16 23:39:52 +0000648def BteqzT8SltuX16: FEXT_T8I816_ins<"bteqz", "sltu">, cbranch16;
Reed Kotler67439242012-10-17 22:29:54 +0000649
Reed Kotler61b474f2013-02-16 23:39:52 +0000650def BteqzT8SltiX16: FEXT_T8I8I16_ins<"bteqz", "slti">, cbranch16;
Reed Kotler67439242012-10-17 22:29:54 +0000651
Reed Kotler61b474f2013-02-16 23:39:52 +0000652def BteqzT8SltiuX16: FEXT_T8I8I16_ins<"bteqz", "sltiu">,
Reed Kotler67439242012-10-17 22:29:54 +0000653 cbranch16;
654
655//
656// Format: BTNEZ offset MIPS16e
657// Purpose: Branch on T Not Equal to Zero (Extended)
658// To test special register T then do a PC-relative conditional branch.
659//
Reed Kotler09e59152013-11-15 02:21:52 +0000660
661def Btnez16: FI816_ins<0b001, "btnez", IIAlu>, cbranch16 {
662 let Uses = [T8];
663}
664
Reed Kotlercb374092013-02-18 00:59:04 +0000665def BtnezX16: FEXT_I816_ins<0b001, "btnez", IIAlu> ,cbranch16 {
666 let Uses = [T8];
667}
Reed Kotler67439242012-10-17 22:29:54 +0000668
Reed Kotler61b474f2013-02-16 23:39:52 +0000669def BtnezT8CmpX16: FEXT_T8I816_ins<"btnez", "cmp">, cbranch16;
Reed Kotler67439242012-10-17 22:29:54 +0000670
Reed Kotler61b474f2013-02-16 23:39:52 +0000671def BtnezT8CmpiX16: FEXT_T8I8I16_ins<"btnez", "cmpi">, cbranch16;
Reed Kotler67439242012-10-17 22:29:54 +0000672
Reed Kotler61b474f2013-02-16 23:39:52 +0000673def BtnezT8SltX16: FEXT_T8I816_ins<"btnez", "slt">, cbranch16;
Reed Kotler67439242012-10-17 22:29:54 +0000674
Reed Kotler61b474f2013-02-16 23:39:52 +0000675def BtnezT8SltuX16: FEXT_T8I816_ins<"btnez", "sltu">, cbranch16;
Reed Kotler67439242012-10-17 22:29:54 +0000676
Reed Kotler61b474f2013-02-16 23:39:52 +0000677def BtnezT8SltiX16: FEXT_T8I8I16_ins<"btnez", "slti">, cbranch16;
Reed Kotler67439242012-10-17 22:29:54 +0000678
Reed Kotler61b474f2013-02-16 23:39:52 +0000679def BtnezT8SltiuX16: FEXT_T8I8I16_ins<"btnez", "sltiu">,
Reed Kotler67439242012-10-17 22:29:54 +0000680 cbranch16;
681
Reed Kotlercf11c592012-10-12 02:01:09 +0000682//
Reed Kotlercb374092013-02-18 00:59:04 +0000683// Format: CMP rx, ry MIPS16e
684// Purpose: Compare
685// To compare the contents of two GPRs.
686//
Reed Kotler80070bd2013-02-23 23:37:03 +0000687def CmpRxRy16: FRR16R_ins<0b01010, "cmp", IIAlu> {
Reed Kotlercb374092013-02-18 00:59:04 +0000688 let Defs = [T8];
689}
690
Reed Kotlerd8217192013-02-19 00:20:58 +0000691//
692// Format: CMPI rx, immediate MIPS16e
693// Purpose: Compare Immediate
694// To compare a constant with the contents of a GPR.
695//
Reed Kotler80070bd2013-02-23 23:37:03 +0000696def CmpiRxImm16: FRI16R_ins<0b01110, "cmpi", IIAlu> {
Reed Kotlerd8217192013-02-19 00:20:58 +0000697 let Defs = [T8];
698}
699
700//
701// Format: CMPI rx, immediate MIPS16e
702// Purpose: Compare Immediate (Extended)
703// To compare a constant with the contents of a GPR.
704//
Reed Kotler80070bd2013-02-23 23:37:03 +0000705def CmpiRxImmX16: FEXT_RI16R_ins<0b01110, "cmpi", IIAlu> {
Reed Kotlerd8217192013-02-19 00:20:58 +0000706 let Defs = [T8];
707}
708
Reed Kotlercb374092013-02-18 00:59:04 +0000709
710//
Reed Kotlercf11c592012-10-12 02:01:09 +0000711// Format: DIV rx, ry MIPS16e
712// Purpose: Divide Word
713// To divide 32-bit signed integers.
714//
715def DivRxRy16: FRR16_div_ins<0b11010, "div", IIAlu> {
Akira Hatanaka8002a3f2013-08-14 00:47:08 +0000716 let Defs = [HI0, LO0];
Reed Kotlercf11c592012-10-12 02:01:09 +0000717}
718
719//
720// Format: DIVU rx, ry MIPS16e
721// Purpose: Divide Unsigned Word
722// To divide 32-bit unsigned integers.
723//
724def DivuRxRy16: FRR16_div_ins<0b11011, "divu", IIAlu> {
Akira Hatanaka8002a3f2013-08-14 00:47:08 +0000725 let Defs = [HI0, LO0];
Reed Kotlercf11c592012-10-12 02:01:09 +0000726}
Reed Kotlerf8933f82013-02-02 04:07:35 +0000727//
728// Format: JAL target MIPS16e
729// Purpose: Jump and Link
730// To execute a procedure call within the current 256 MB-aligned
731// region and preserve the current ISA.
732//
Reed Kotlercf11c592012-10-12 02:01:09 +0000733
Reed Kotlerf8933f82013-02-02 04:07:35 +0000734def Jal16 : FJAL16_ins<0b0, "jal", IIAlu> {
Reed Kotlerf8933f82013-02-02 04:07:35 +0000735 let hasDelaySlot = 0; // not true, but we add the nop for now
Reed Kotlerfd132b92013-08-01 00:59:06 +0000736 let isCall=1;
Reed Kotlerf8933f82013-02-02 04:07:35 +0000737}
Akira Hatanaka26e9ecb2012-07-23 23:45:54 +0000738
739//
740// Format: JR ra MIPS16e
741// Purpose: Jump Register Through Register ra
742// To execute a branch to the instruction address in the return
743// address register.
744//
745
Reed Kotler3589dd72012-10-28 06:02:37 +0000746def JrRa16: FRR16_JALRC_RA_only_ins<0, 0, "jr", IIAlu> {
747 let isBranch = 1;
748 let isIndirectBranch = 1;
749 let hasDelaySlot = 1;
750 let isTerminator=1;
751 let isBarrier=1;
752}
Reed Kotlere6c31572012-10-28 23:08:07 +0000753
Reed Kotlerec8a5492013-02-14 03:05:25 +0000754def JrcRa16: FRR16_JALRC_RA_only_ins<1, 1, "jrc", IIAlu> {
Reed Kotlera8117532012-10-30 00:54:49 +0000755 let isBranch = 1;
756 let isIndirectBranch = 1;
757 let isTerminator=1;
758 let isBarrier=1;
759}
760
Reed Kotlere6c31572012-10-28 23:08:07 +0000761def JrcRx16: FRR16_JALRC_ins<1, 1, 0, "jrc", IIAlu> {
762 let isBranch = 1;
763 let isIndirectBranch = 1;
764 let isTerminator=1;
765 let isBarrier=1;
766}
Akira Hatanaka26e9ecb2012-07-23 23:45:54 +0000767//
Akira Hatanaka22bec282012-08-03 22:57:02 +0000768// Format: LB ry, offset(rx) MIPS16e
769// Purpose: Load Byte (Extended)
770// To load a byte from memory as a signed value.
771//
Reed Kotlerec8a5492013-02-14 03:05:25 +0000772def LbRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10011, "lb", mem16, IILoad>, MayLoad{
773 let isCodeGenOnly = 1;
774}
Akira Hatanaka22bec282012-08-03 22:57:02 +0000775
776//
777// Format: LBU ry, offset(rx) MIPS16e
778// Purpose: Load Byte Unsigned (Extended)
779// To load a byte from memory as a unsigned value.
780//
Reed Kotler210ebe92012-09-28 02:26:24 +0000781def LbuRxRyOffMemX16:
Reed Kotlerec8a5492013-02-14 03:05:25 +0000782 FEXT_RRI16_mem_ins<0b10100, "lbu", mem16, IILoad>, MayLoad {
783 let isCodeGenOnly = 1;
784}
Akira Hatanaka22bec282012-08-03 22:57:02 +0000785
786//
787// Format: LH ry, offset(rx) MIPS16e
788// Purpose: Load Halfword signed (Extended)
789// To load a halfword from memory as a signed value.
790//
Reed Kotlerec8a5492013-02-14 03:05:25 +0000791def LhRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10100, "lh", mem16, IILoad>, MayLoad{
792 let isCodeGenOnly = 1;
793}
Akira Hatanaka22bec282012-08-03 22:57:02 +0000794
795//
796// Format: LHU ry, offset(rx) MIPS16e
797// Purpose: Load Halfword unsigned (Extended)
798// To load a halfword from memory as an unsigned value.
799//
Reed Kotler210ebe92012-09-28 02:26:24 +0000800def LhuRxRyOffMemX16:
Reed Kotlerec8a5492013-02-14 03:05:25 +0000801 FEXT_RRI16_mem_ins<0b10100, "lhu", mem16, IILoad>, MayLoad {
802 let isCodeGenOnly = 1;
803}
Akira Hatanaka22bec282012-08-03 22:57:02 +0000804
805//
Akira Hatanaka26e9ecb2012-07-23 23:45:54 +0000806// Format: LI rx, immediate MIPS16e
Reed Kotler7b503c22013-02-20 05:45:15 +0000807// Purpose: Load Immediate
808// To load a constant into a GPR.
809//
810def LiRxImm16: FRI16_ins<0b01101, "li", IIAlu>;
811
812//
813// Format: LI rx, immediate MIPS16e
Akira Hatanaka26e9ecb2012-07-23 23:45:54 +0000814// Purpose: Load Immediate (Extended)
815// To load a constant into a GPR.
816//
817def LiRxImmX16: FEXT_RI16_ins<0b01101, "li", IIAlu>;
818
Reed Kotlerd6aadc72013-09-18 22:46:09 +0000819def LiRxImmAlignX16: FEXT_RI16_ins<0b01101, ".align 2\n\tli", IIAlu> {
820 let isCodeGenOnly = 1;
821}
822
Akira Hatanaka26e9ecb2012-07-23 23:45:54 +0000823//
824// Format: LW ry, offset(rx) MIPS16e
825// Purpose: Load Word (Extended)
826// To load a word from memory as a signed value.
827//
Reed Kotlerec8a5492013-02-14 03:05:25 +0000828def LwRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10011, "lw", mem16, IILoad>, MayLoad{
829 let isCodeGenOnly = 1;
830}
Reed Kotler210ebe92012-09-28 02:26:24 +0000831
832// Format: LW rx, offset(sp) MIPS16e
833// Purpose: Load Word (SP-Relative, Extended)
834// To load an SP-relative word from memory as a signed value.
835//
Reed Kotler91ae9822013-10-27 21:57:36 +0000836def LwRxSpImmX16: FEXT_RI16_SP_explicit_ins<0b10010, "lw", IILoad>, MayLoad{
Reed Kotler3aad7622012-12-19 04:06:15 +0000837 let Uses = [SP];
838}
Akira Hatanaka26e9ecb2012-07-23 23:45:54 +0000839
Reed Kotler0f007fc2013-11-05 08:14:14 +0000840def LwRxPcTcp16: FRI16_TCP_ins<0b10110, "lw", IILoad>, MayLoad;
841
Reed Kotler91ae9822013-10-27 21:57:36 +0000842def LwRxPcTcpX16: FEXT_RI16_TCP_ins<0b10110, "lw", IILoad>, MayLoad;
Akira Hatanaka26e9ecb2012-07-23 23:45:54 +0000843//
844// Format: MOVE r32, rz MIPS16e
845// Purpose: Move
846// To move the contents of a GPR to a GPR.
847//
Akira Hatanaka0fbaec22012-09-14 03:21:56 +0000848def Move32R16: FI8_MOV32R16_ins<"move", IIAlu>;
849
850//
851// Format: MOVE ry, r32 MIPS16e
852//Purpose: Move
853// To move the contents of a GPR to a GPR.
854//
855def MoveR3216: FI8_MOVR3216_ins<"move", IIAlu>;
Akira Hatanaka22bec282012-08-03 22:57:02 +0000856
857//
Reed Kotler24032212012-10-05 18:27:54 +0000858// Format: MFHI rx MIPS16e
859// Purpose: Move From HI Register
860// To copy the special purpose HI register to a GPR.
861//
862def Mfhi16: FRR16_M_ins<0b10000, "mfhi", IIAlu> {
Akira Hatanaka8002a3f2013-08-14 00:47:08 +0000863 let Uses = [HI0];
Reed Kotler24032212012-10-05 18:27:54 +0000864 let neverHasSideEffects = 1;
865}
866
867//
868// Format: MFLO rx MIPS16e
869// Purpose: Move From LO Register
870// To copy the special purpose LO register to a GPR.
871//
872def Mflo16: FRR16_M_ins<0b10010, "mflo", IIAlu> {
Akira Hatanaka8002a3f2013-08-14 00:47:08 +0000873 let Uses = [LO0];
Reed Kotler24032212012-10-05 18:27:54 +0000874 let neverHasSideEffects = 1;
875}
876
877//
878// Pseudo Instruction for mult
879//
880def MultRxRy16: FMULT16_ins<"mult", IIAlu> {
881 let isCommutable = 1;
882 let neverHasSideEffects = 1;
Akira Hatanaka8002a3f2013-08-14 00:47:08 +0000883 let Defs = [HI0, LO0];
Reed Kotler24032212012-10-05 18:27:54 +0000884}
885
886def MultuRxRy16: FMULT16_ins<"multu", IIAlu> {
887 let isCommutable = 1;
888 let neverHasSideEffects = 1;
Akira Hatanaka8002a3f2013-08-14 00:47:08 +0000889 let Defs = [HI0, LO0];
Reed Kotler24032212012-10-05 18:27:54 +0000890}
891
892//
893// Format: MULT rx, ry MIPS16e
894// Purpose: Multiply Word
895// To multiply 32-bit signed integers.
896//
897def MultRxRyRz16: FMULT16_LO_ins<"mult", IIAlu> {
898 let isCommutable = 1;
899 let neverHasSideEffects = 1;
Akira Hatanaka8002a3f2013-08-14 00:47:08 +0000900 let Defs = [HI0, LO0];
Reed Kotler24032212012-10-05 18:27:54 +0000901}
902
903//
904// Format: MULTU rx, ry MIPS16e
905// Purpose: Multiply Unsigned Word
906// To multiply 32-bit unsigned integers.
907//
908def MultuRxRyRz16: FMULT16_LO_ins<"multu", IIAlu> {
909 let isCommutable = 1;
910 let neverHasSideEffects = 1;
Akira Hatanaka8002a3f2013-08-14 00:47:08 +0000911 let Defs = [HI0, LO0];
Reed Kotler24032212012-10-05 18:27:54 +0000912}
913
914//
Akira Hatanaka22bec282012-08-03 22:57:02 +0000915// Format: NEG rx, ry MIPS16e
916// Purpose: Negate
917// To negate an integer value.
918//
Reed Kotler4e1c6292012-10-26 16:18:19 +0000919def NegRxRy16: FUnaryRR16_ins<0b11101, "neg", IIAlu>;
Akira Hatanaka22bec282012-08-03 22:57:02 +0000920
921//
922// Format: NOT rx, ry MIPS16e
923// Purpose: Not
924// To complement an integer value
925//
Reed Kotler4e1c6292012-10-26 16:18:19 +0000926def NotRxRy16: FUnaryRR16_ins<0b01111, "not", IIAlu>;
Akira Hatanaka22bec282012-08-03 22:57:02 +0000927
928//
929// Format: OR rx, ry MIPS16e
930// Purpose: Or
931// To do a bitwise logical OR.
932//
933def OrRxRxRy16: FRxRxRy16_ins<0b01101, "or", IIAlu>, ArithLogic16Defs<1>;
934
Akira Hatanaka26e9ecb2012-07-23 23:45:54 +0000935//
936// Format: RESTORE {ra,}{s0/s1/s0-1,}{framesize}
937// (All args are optional) MIPS16e
938// Purpose: Restore Registers and Deallocate Stack Frame
939// To deallocate a stack frame before exit from a subroutine,
940// restoring return address and static registers, and adjusting
941// stack
942//
943
944// fixed form for restoring RA and the frame
945// for direct object emitter, encoding needs to be adjusted for the
946// frame size
947//
Akira Hatanakacd04e2b2012-09-21 01:08:16 +0000948let ra=1, s=0,s0=1,s1=1 in
Akira Hatanaka26e9ecb2012-07-23 23:45:54 +0000949def RestoreRaF16:
950 FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
Reed Kotler9c285b32013-08-04 23:56:53 +0000951 "restore\t$$ra, $$s0, $$s1, $$s2, $frame_size", [], IILoad >, MayLoad {
Reed Kotler27a72292012-10-31 05:21:10 +0000952 let isCodeGenOnly = 1;
Reed Kotler9c285b32013-08-04 23:56:53 +0000953 let Defs = [S0, S1, S2, RA, SP];
Reed Kotler3aad7622012-12-19 04:06:15 +0000954 let Uses = [SP];
Reed Kotler27a72292012-10-31 05:21:10 +0000955}
956
957// Use Restore to increment SP since SP is not a Mip 16 register, this
958// is an easy way to do that which does not require a register.
959//
960let ra=0, s=0,s0=0,s1=0 in
961def RestoreIncSpF16:
962 FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
963 "restore\t$frame_size", [], IILoad >, MayLoad {
Akira Hatanakacd04e2b2012-09-21 01:08:16 +0000964 let isCodeGenOnly = 1;
Reed Kotler3aad7622012-12-19 04:06:15 +0000965 let Defs = [SP];
966 let Uses = [SP];
Akira Hatanakacd04e2b2012-09-21 01:08:16 +0000967}
Akira Hatanaka26e9ecb2012-07-23 23:45:54 +0000968
969//
970// Format: SAVE {ra,}{s0/s1/s0-1,}{framesize} (All arguments are optional)
971// MIPS16e
972// Purpose: Save Registers and Set Up Stack Frame
973// To set up a stack frame on entry to a subroutine,
974// saving return address and static registers, and adjusting stack
975//
Akira Hatanakacd04e2b2012-09-21 01:08:16 +0000976let ra=1, s=1,s0=1,s1=1 in
Akira Hatanaka26e9ecb2012-07-23 23:45:54 +0000977def SaveRaF16:
978 FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
Reed Kotler9c285b32013-08-04 23:56:53 +0000979 "save\t$$ra, $$s0, $$s1, $$s2, $frame_size", [], IIStore >, MayStore {
Reed Kotler27a72292012-10-31 05:21:10 +0000980 let isCodeGenOnly = 1;
Reed Kotler9c285b32013-08-04 23:56:53 +0000981 let Uses = [RA, SP, S0, S1, S2];
Reed Kotler3aad7622012-12-19 04:06:15 +0000982 let Defs = [SP];
Reed Kotler27a72292012-10-31 05:21:10 +0000983}
984
985//
986// Use Save to decrement the SP by a constant since SP is not
987// a Mips16 register.
988//
989let ra=0, s=0,s0=0,s1=0 in
990def SaveDecSpF16:
991 FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
992 "save\t$frame_size", [], IIStore >, MayStore {
Akira Hatanakacd04e2b2012-09-21 01:08:16 +0000993 let isCodeGenOnly = 1;
Reed Kotler3aad7622012-12-19 04:06:15 +0000994 let Uses = [SP];
995 let Defs = [SP];
Akira Hatanakacd04e2b2012-09-21 01:08:16 +0000996}
Akira Hatanaka26e9ecb2012-07-23 23:45:54 +0000997//
Akira Hatanaka22bec282012-08-03 22:57:02 +0000998// Format: SB ry, offset(rx) MIPS16e
999// Purpose: Store Byte (Extended)
1000// To store a byte to memory.
1001//
Reed Kotler210ebe92012-09-28 02:26:24 +00001002def SbRxRyOffMemX16:
1003 FEXT_RRI16_mem2_ins<0b11000, "sb", mem16, IIStore>, MayStore;
Akira Hatanaka22bec282012-08-03 22:57:02 +00001004
1005//
Reed Kotler445d0ad2013-10-07 20:46:19 +00001006// Format: SEB rx MIPS16e
1007// Purpose: Sign-Extend Byte
1008// Sign-extend least significant byte in register rx.
1009//
1010def SebRx16
1011 : FRR_SF16_ins<0b10001, 0b100, "seb", IIAlu>;
1012
1013//
1014// Format: SEH rx MIPS16e
1015// Purpose: Sign-Extend Halfword
1016// Sign-extend least significant word in register rx.
1017//
1018def SehRx16
1019 : FRR_SF16_ins<0b10001, 0b101, "seh", IIAlu>;
1020
1021//
Reed Kotler097556d2012-10-25 21:33:30 +00001022// The Sel(T) instructions are pseudos
1023// T means that they use T8 implicitly.
1024//
1025//
1026// Format: SelBeqZ rd, rs, rt
1027// Purpose: if rt==0, do nothing
1028// else rs = rt
1029//
Reed Kotler61b474f2013-02-16 23:39:52 +00001030def SelBeqZ: Sel<"beqz">;
Reed Kotler097556d2012-10-25 21:33:30 +00001031
1032//
1033// Format: SelTBteqZCmp rd, rs, rl, rr
1034// Purpose: b = Cmp rl, rr.
1035// If b==0 then do nothing.
1036// if b!=0 then rd = rs
1037//
Reed Kotler61b474f2013-02-16 23:39:52 +00001038def SelTBteqZCmp: SelT<"bteqz", "cmp">;
Reed Kotler097556d2012-10-25 21:33:30 +00001039
1040//
1041// Format: SelTBteqZCmpi rd, rs, rl, rr
1042// Purpose: b = Cmpi rl, imm.
1043// If b==0 then do nothing.
1044// if b!=0 then rd = rs
1045//
Reed Kotler61b474f2013-02-16 23:39:52 +00001046def SelTBteqZCmpi: SeliT<"bteqz", "cmpi">;
Reed Kotler097556d2012-10-25 21:33:30 +00001047
1048//
1049// Format: SelTBteqZSlt rd, rs, rl, rr
1050// Purpose: b = Slt rl, rr.
1051// If b==0 then do nothing.
1052// if b!=0 then rd = rs
1053//
Reed Kotler61b474f2013-02-16 23:39:52 +00001054def SelTBteqZSlt: SelT<"bteqz", "slt">;
Reed Kotler097556d2012-10-25 21:33:30 +00001055
1056//
1057// Format: SelTBteqZSlti rd, rs, rl, rr
1058// Purpose: b = Slti rl, imm.
1059// If b==0 then do nothing.
1060// if b!=0 then rd = rs
1061//
Reed Kotler61b474f2013-02-16 23:39:52 +00001062def SelTBteqZSlti: SeliT<"bteqz", "slti">;
Reed Kotler097556d2012-10-25 21:33:30 +00001063
1064//
1065// Format: SelTBteqZSltu rd, rs, rl, rr
1066// Purpose: b = Sltu rl, rr.
1067// If b==0 then do nothing.
1068// if b!=0 then rd = rs
1069//
Reed Kotler61b474f2013-02-16 23:39:52 +00001070def SelTBteqZSltu: SelT<"bteqz", "sltu">;
Reed Kotler097556d2012-10-25 21:33:30 +00001071
1072//
1073// Format: SelTBteqZSltiu rd, rs, rl, rr
1074// Purpose: b = Sltiu rl, imm.
1075// If b==0 then do nothing.
1076// if b!=0 then rd = rs
1077//
Reed Kotler61b474f2013-02-16 23:39:52 +00001078def SelTBteqZSltiu: SeliT<"bteqz", "sltiu">;
Reed Kotler097556d2012-10-25 21:33:30 +00001079
1080//
1081// Format: SelBnez rd, rs, rt
1082// Purpose: if rt!=0, do nothing
1083// else rs = rt
1084//
Reed Kotler61b474f2013-02-16 23:39:52 +00001085def SelBneZ: Sel<"bnez">;
Reed Kotler097556d2012-10-25 21:33:30 +00001086
1087//
1088// Format: SelTBtneZCmp rd, rs, rl, rr
1089// Purpose: b = Cmp rl, rr.
1090// If b!=0 then do nothing.
1091// if b0=0 then rd = rs
1092//
Reed Kotler61b474f2013-02-16 23:39:52 +00001093def SelTBtneZCmp: SelT<"btnez", "cmp">;
Reed Kotler097556d2012-10-25 21:33:30 +00001094
1095//
1096// Format: SelTBtnezCmpi rd, rs, rl, rr
1097// Purpose: b = Cmpi rl, imm.
1098// If b!=0 then do nothing.
1099// if b==0 then rd = rs
1100//
Reed Kotler61b474f2013-02-16 23:39:52 +00001101def SelTBtneZCmpi: SeliT<"btnez", "cmpi">;
Reed Kotler097556d2012-10-25 21:33:30 +00001102
1103//
1104// Format: SelTBtneZSlt rd, rs, rl, rr
1105// Purpose: b = Slt rl, rr.
1106// If b!=0 then do nothing.
1107// if b==0 then rd = rs
1108//
Reed Kotler61b474f2013-02-16 23:39:52 +00001109def SelTBtneZSlt: SelT<"btnez", "slt">;
Reed Kotler097556d2012-10-25 21:33:30 +00001110
1111//
1112// Format: SelTBtneZSlti rd, rs, rl, rr
1113// Purpose: b = Slti rl, imm.
1114// If b!=0 then do nothing.
1115// if b==0 then rd = rs
1116//
Reed Kotler61b474f2013-02-16 23:39:52 +00001117def SelTBtneZSlti: SeliT<"btnez", "slti">;
Reed Kotler097556d2012-10-25 21:33:30 +00001118
1119//
1120// Format: SelTBtneZSltu rd, rs, rl, rr
1121// Purpose: b = Sltu rl, rr.
1122// If b!=0 then do nothing.
1123// if b==0 then rd = rs
1124//
Reed Kotler61b474f2013-02-16 23:39:52 +00001125def SelTBtneZSltu: SelT<"btnez", "sltu">;
Reed Kotler097556d2012-10-25 21:33:30 +00001126
1127//
1128// Format: SelTBtneZSltiu rd, rs, rl, rr
1129// Purpose: b = Slti rl, imm.
1130// If b!=0 then do nothing.
1131// if b==0 then rd = rs
1132//
Reed Kotler61b474f2013-02-16 23:39:52 +00001133def SelTBtneZSltiu: SeliT<"btnez", "sltiu">;
Reed Kotler097556d2012-10-25 21:33:30 +00001134//
1135//
Akira Hatanaka22bec282012-08-03 22:57:02 +00001136// Format: SH ry, offset(rx) MIPS16e
1137// Purpose: Store Halfword (Extended)
1138// To store a halfword to memory.
1139//
Reed Kotler210ebe92012-09-28 02:26:24 +00001140def ShRxRyOffMemX16:
1141 FEXT_RRI16_mem2_ins<0b11001, "sh", mem16, IIStore>, MayStore;
Akira Hatanaka22bec282012-08-03 22:57:02 +00001142
1143//
Akira Hatanaka26e9ecb2012-07-23 23:45:54 +00001144// Format: SLL rx, ry, sa MIPS16e
1145// Purpose: Shift Word Left Logical (Extended)
NAKAMURA Takumi8a046432013-10-28 04:07:38 +00001146// To execute a left-shift of a word by a fixed number of bits-0 to 31 bits.
Akira Hatanaka26e9ecb2012-07-23 23:45:54 +00001147//
1148def SllX16: FEXT_SHIFT16_ins<0b00, "sll", IIAlu>;
1149
1150//
Akira Hatanaka22bec282012-08-03 22:57:02 +00001151// Format: SLLV ry, rx MIPS16e
1152// Purpose: Shift Word Left Logical Variable
1153// To execute a left-shift of a word by a variable number of bits.
1154//
1155def SllvRxRy16 : FRxRxRy16_ins<0b00100, "sllv", IIAlu>;
1156
Reed Kotler3e457f52013-02-19 03:56:57 +00001157// Format: SLTI rx, immediate MIPS16e
1158// Purpose: Set on Less Than Immediate
1159// To record the result of a less-than comparison with a constant.
1160//
1161//
Reed Kotler7b503c22013-02-20 05:45:15 +00001162def SltiRxImm16: FRI16R_ins<0b01010, "slti", IIAlu> {
Reed Kotler3e457f52013-02-19 03:56:57 +00001163 let Defs = [T8];
1164}
1165
Reed Kotler164bb372012-10-23 01:35:48 +00001166//
1167// Format: SLTI rx, immediate MIPS16e
1168// Purpose: Set on Less Than Immediate (Extended)
1169// To record the result of a less-than comparison with a constant.
1170//
Reed Kotler3e457f52013-02-19 03:56:57 +00001171//
Reed Kotler7b503c22013-02-20 05:45:15 +00001172def SltiRxImmX16: FEXT_RI16R_ins<0b01010, "slti", IIAlu> {
Reed Kotler3e457f52013-02-19 03:56:57 +00001173 let Defs = [T8];
1174}
1175
Reed Kotler61b474f2013-02-16 23:39:52 +00001176def SltiCCRxImmX16: FEXT_CCRXI16_ins<"slti">;
Akira Hatanaka22bec282012-08-03 22:57:02 +00001177
Reed Kotler3e457f52013-02-19 03:56:57 +00001178// Format: SLTIU rx, immediate MIPS16e
1179// Purpose: Set on Less Than Immediate Unsigned
1180// To record the result of a less-than comparison with a constant.
1181//
1182//
Reed Kotler7b503c22013-02-20 05:45:15 +00001183def SltiuRxImm16: FRI16R_ins<0b01011, "sltiu", IIAlu> {
Reed Kotler3e457f52013-02-19 03:56:57 +00001184 let Defs = [T8];
1185}
1186
1187//
1188// Format: SLTI rx, immediate MIPS16e
1189// Purpose: Set on Less Than Immediate Unsigned (Extended)
1190// To record the result of a less-than comparison with a constant.
1191//
1192//
Reed Kotler7b503c22013-02-20 05:45:15 +00001193def SltiuRxImmX16: FEXT_RI16R_ins<0b01011, "sltiu", IIAlu> {
Reed Kotler3e457f52013-02-19 03:56:57 +00001194 let Defs = [T8];
1195}
Akira Hatanaka22bec282012-08-03 22:57:02 +00001196//
Reed Kotler164bb372012-10-23 01:35:48 +00001197// Format: SLTIU rx, immediate MIPS16e
1198// Purpose: Set on Less Than Immediate Unsigned (Extended)
1199// To record the result of a less-than comparison with a constant.
1200//
Reed Kotler61b474f2013-02-16 23:39:52 +00001201def SltiuCCRxImmX16: FEXT_CCRXI16_ins<"sltiu">;
Reed Kotler164bb372012-10-23 01:35:48 +00001202
1203//
1204// Format: SLT rx, ry MIPS16e
1205// Purpose: Set on Less Than
1206// To record the result of a less-than comparison.
1207//
Reed Kotler80070bd2013-02-23 23:37:03 +00001208def SltRxRy16: FRR16R_ins<0b00010, "slt", IIAlu>{
Reed Kotler7b503c22013-02-20 05:45:15 +00001209 let Defs = [T8];
1210}
Reed Kotler164bb372012-10-23 01:35:48 +00001211
Reed Kotler61b474f2013-02-16 23:39:52 +00001212def SltCCRxRy16: FCCRR16_ins<"slt">;
Reed Kotler164bb372012-10-23 01:35:48 +00001213
1214// Format: SLTU rx, ry MIPS16e
1215// Purpose: Set on Less Than Unsigned
1216// To record the result of an unsigned less-than comparison.
1217//
Reed Kotler80070bd2013-02-23 23:37:03 +00001218def SltuRxRy16: FRR16R_ins<0b00011, "sltu", IIAlu>{
Reed Kotler7b503c22013-02-20 05:45:15 +00001219 let Defs = [T8];
1220}
Reed Kotler6879e562013-02-18 04:55:38 +00001221
Reed Kotler61b474f2013-02-16 23:39:52 +00001222def SltuRxRyRz16: FRRTR16_ins<"sltu"> {
Reed Kotler287f0442012-10-26 04:46:26 +00001223 let isCodeGenOnly=1;
Reed Kotler7b503c22013-02-20 05:45:15 +00001224 let Defs = [T8];
Reed Kotler287f0442012-10-26 04:46:26 +00001225}
Reed Kotler164bb372012-10-23 01:35:48 +00001226
1227
Reed Kotler61b474f2013-02-16 23:39:52 +00001228def SltuCCRxRy16: FCCRR16_ins<"sltu">;
Reed Kotler164bb372012-10-23 01:35:48 +00001229//
Akira Hatanaka22bec282012-08-03 22:57:02 +00001230// Format: SRAV ry, rx MIPS16e
1231// Purpose: Shift Word Right Arithmetic Variable
1232// To execute an arithmetic right-shift of a word by a variable
1233// number of bits.
1234//
1235def SravRxRy16: FRxRxRy16_ins<0b00111, "srav", IIAlu>;
1236
1237
1238//
1239// Format: SRA rx, ry, sa MIPS16e
1240// Purpose: Shift Word Right Arithmetic (Extended)
1241// To execute an arithmetic right-shift of a word by a fixed
NAKAMURA Takumi8a046432013-10-28 04:07:38 +00001242// number of bits-1 to 8 bits.
Akira Hatanaka22bec282012-08-03 22:57:02 +00001243//
1244def SraX16: FEXT_SHIFT16_ins<0b11, "sra", IIAlu>;
1245
1246
1247//
1248// Format: SRLV ry, rx MIPS16e
1249// Purpose: Shift Word Right Logical Variable
1250// To execute a logical right-shift of a word by a variable
1251// number of bits.
1252//
1253def SrlvRxRy16: FRxRxRy16_ins<0b00110, "srlv", IIAlu>;
1254
1255
1256//
1257// Format: SRL rx, ry, sa MIPS16e
1258// Purpose: Shift Word Right Logical (Extended)
1259// To execute a logical right-shift of a word by a fixed
NAKAMURA Takumi8a046432013-10-28 04:07:38 +00001260// number of bits-1 to 31 bits.
Akira Hatanaka22bec282012-08-03 22:57:02 +00001261//
1262def SrlX16: FEXT_SHIFT16_ins<0b10, "srl", IIAlu>;
1263
1264//
1265// Format: SUBU rz, rx, ry MIPS16e
1266// Purpose: Subtract Unsigned Word
1267// To subtract 32-bit integers
1268//
1269def SubuRxRyRz16: FRRR16_ins<0b11, "subu", IIAlu>, ArithLogic16Defs<0>;
1270
1271//
Akira Hatanaka26e9ecb2012-07-23 23:45:54 +00001272// Format: SW ry, offset(rx) MIPS16e
1273// Purpose: Store Word (Extended)
1274// To store a word to memory.
1275//
Reed Kotler210ebe92012-09-28 02:26:24 +00001276def SwRxRyOffMemX16:
1277 FEXT_RRI16_mem2_ins<0b11011, "sw", mem16, IIStore>, MayStore;
Akira Hatanaka22bec282012-08-03 22:57:02 +00001278
1279//
Reed Kotler210ebe92012-09-28 02:26:24 +00001280// Format: SW rx, offset(sp) MIPS16e
1281// Purpose: Store Word rx (SP-Relative)
1282// To store an SP-relative word to memory.
1283//
Reed Kotler30cedf62013-08-04 01:13:25 +00001284def SwRxSpImmX16: FEXT_RI16_SP_Store_explicit_ins
1285 <0b11010, "sw", IIStore>, MayStore;
Reed Kotler210ebe92012-09-28 02:26:24 +00001286
1287//
1288//
Akira Hatanaka22bec282012-08-03 22:57:02 +00001289// Format: XOR rx, ry MIPS16e
1290// Purpose: Xor
1291// To do a bitwise logical XOR.
1292//
1293def XorRxRxRy16: FRxRxRy16_ins<0b01110, "xor", IIAlu>, ArithLogic16Defs<1>;
Akira Hatanaka26e9ecb2012-07-23 23:45:54 +00001294
Akira Hatanaka765c3122012-06-21 20:39:10 +00001295class Mips16Pat<dag pattern, dag result> : Pat<pattern, result> {
1296 let Predicates = [InMips16Mode];
1297}
1298
Akira Hatanaka22bec282012-08-03 22:57:02 +00001299// Unary Arith/Logic
1300//
1301class ArithLogicU_pat<PatFrag OpNode, Instruction I> :
1302 Mips16Pat<(OpNode CPU16Regs:$r),
1303 (I CPU16Regs:$r)>;
Akira Hatanakabff8e312012-05-31 02:59:44 +00001304
Akira Hatanaka22bec282012-08-03 22:57:02 +00001305def: ArithLogicU_pat<not, NotRxRy16>;
1306def: ArithLogicU_pat<ineg, NegRxRy16>;
Akira Hatanaka26e9ecb2012-07-23 23:45:54 +00001307
Akira Hatanaka22bec282012-08-03 22:57:02 +00001308class ArithLogic16_pat<SDNode OpNode, Instruction I> :
1309 Mips16Pat<(OpNode CPU16Regs:$l, CPU16Regs:$r),
1310 (I CPU16Regs:$l, CPU16Regs:$r)>;
Akira Hatanaka26e9ecb2012-07-23 23:45:54 +00001311
Akira Hatanaka22bec282012-08-03 22:57:02 +00001312def: ArithLogic16_pat<add, AdduRxRyRz16>;
1313def: ArithLogic16_pat<and, AndRxRxRy16>;
Reed Kotler24032212012-10-05 18:27:54 +00001314def: ArithLogic16_pat<mul, MultRxRyRz16>;
Akira Hatanaka22bec282012-08-03 22:57:02 +00001315def: ArithLogic16_pat<or, OrRxRxRy16>;
1316def: ArithLogic16_pat<sub, SubuRxRyRz16>;
1317def: ArithLogic16_pat<xor, XorRxRxRy16>;
Akira Hatanaka26e9ecb2012-07-23 23:45:54 +00001318
Akira Hatanaka22bec282012-08-03 22:57:02 +00001319// Arithmetic and logical instructions with 2 register operands.
Akira Hatanaka26e9ecb2012-07-23 23:45:54 +00001320
Akira Hatanaka22bec282012-08-03 22:57:02 +00001321class ArithLogicI16_pat<SDNode OpNode, PatFrag imm_type, Instruction I> :
1322 Mips16Pat<(OpNode CPU16Regs:$in, imm_type:$imm),
1323 (I CPU16Regs:$in, imm_type:$imm)>;
Akira Hatanaka26e9ecb2012-07-23 23:45:54 +00001324
Reed Kotlerb9bf8dc2013-02-08 21:42:56 +00001325def: ArithLogicI16_pat<add, immSExt8, AddiuRxRxImm16>;
Akira Hatanaka22bec282012-08-03 22:57:02 +00001326def: ArithLogicI16_pat<add, immSExt16, AddiuRxRxImmX16>;
1327def: ArithLogicI16_pat<shl, immZExt5, SllX16>;
1328def: ArithLogicI16_pat<srl, immZExt5, SrlX16>;
1329def: ArithLogicI16_pat<sra, immZExt5, SraX16>;
Akira Hatanaka26e9ecb2012-07-23 23:45:54 +00001330
Akira Hatanaka22bec282012-08-03 22:57:02 +00001331class shift_rotate_reg16_pat<SDNode OpNode, Instruction I> :
1332 Mips16Pat<(OpNode CPU16Regs:$r, CPU16Regs:$ra),
1333 (I CPU16Regs:$r, CPU16Regs:$ra)>;
Akira Hatanaka26e9ecb2012-07-23 23:45:54 +00001334
Akira Hatanaka22bec282012-08-03 22:57:02 +00001335def: shift_rotate_reg16_pat<shl, SllvRxRy16>;
1336def: shift_rotate_reg16_pat<sra, SravRxRy16>;
1337def: shift_rotate_reg16_pat<srl, SrlvRxRy16>;
1338
1339class LoadM16_pat<PatFrag OpNode, Instruction I> :
Reed Kotler3589dd72012-10-28 06:02:37 +00001340 Mips16Pat<(OpNode addr16:$addr), (I addr16:$addr)>;
Akira Hatanaka22bec282012-08-03 22:57:02 +00001341
1342def: LoadM16_pat<sextloadi8, LbRxRyOffMemX16>;
1343def: LoadM16_pat<zextloadi8, LbuRxRyOffMemX16>;
Akira Hatanaka3e7ba762012-09-15 01:52:08 +00001344def: LoadM16_pat<sextloadi16, LhRxRyOffMemX16>;
1345def: LoadM16_pat<zextloadi16, LhuRxRyOffMemX16>;
1346def: LoadM16_pat<load, LwRxRyOffMemX16>;
Akira Hatanaka22bec282012-08-03 22:57:02 +00001347
1348class StoreM16_pat<PatFrag OpNode, Instruction I> :
Reed Kotler3589dd72012-10-28 06:02:37 +00001349 Mips16Pat<(OpNode CPU16Regs:$r, addr16:$addr),
1350 (I CPU16Regs:$r, addr16:$addr)>;
Akira Hatanaka22bec282012-08-03 22:57:02 +00001351
1352def: StoreM16_pat<truncstorei8, SbRxRyOffMemX16>;
Akira Hatanaka3e7ba762012-09-15 01:52:08 +00001353def: StoreM16_pat<truncstorei16, ShRxRyOffMemX16>;
1354def: StoreM16_pat<store, SwRxRyOffMemX16>;
Akira Hatanaka22bec282012-08-03 22:57:02 +00001355
Reed Kotler67439242012-10-17 22:29:54 +00001356// Unconditional branch
1357class UncondBranch16_pat<SDNode OpNode, Instruction I>:
1358 Mips16Pat<(OpNode bb:$imm16), (I bb:$imm16)> {
Reed Kotlerec60f7d2013-02-07 03:49:51 +00001359 let Predicates = [InMips16Mode];
Reed Kotler67439242012-10-17 22:29:54 +00001360 }
Akira Hatanakabff8e312012-05-31 02:59:44 +00001361
Reed Kotlerf8933f82013-02-02 04:07:35 +00001362def : Mips16Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
1363 (Jal16 tglobaladdr:$dst)>;
1364
Reed Kotler4a230ff2013-02-07 04:34:51 +00001365def : Mips16Pat<(MipsJmpLink (i32 texternalsym:$dst)),
1366 (Jal16 texternalsym:$dst)>;
1367
Reed Kotlere6c31572012-10-28 23:08:07 +00001368// Indirect branch
1369def: Mips16Pat<
Jack Carter7ab15fa2013-01-19 02:00:40 +00001370 (brind CPU16Regs:$rs),
1371 (JrcRx16 CPU16Regs:$rs)>;
Reed Kotlere6c31572012-10-28 23:08:07 +00001372
Akira Hatanakabff8e312012-05-31 02:59:44 +00001373// Jump and Link (Call)
Reed Kotlera8117532012-10-30 00:54:49 +00001374let isCall=1, hasDelaySlot=0 in
Akira Hatanakabff8e312012-05-31 02:59:44 +00001375def JumpLinkReg16:
Akira Hatanakaf640f042012-07-17 22:55:34 +00001376 FRR16_JALRC<0, 0, 0, (outs), (ins CPU16Regs:$rs),
Reed Kotlera8117532012-10-30 00:54:49 +00001377 "jalrc \t$rs", [(MipsJmpLink CPU16Regs:$rs)], IIBranch>;
Akira Hatanakaf640f042012-07-17 22:55:34 +00001378
Akira Hatanaka26e9ecb2012-07-23 23:45:54 +00001379// Mips16 pseudos
1380let isReturn=1, isTerminator=1, hasDelaySlot=1, isBarrier=1, hasCtrlDep=1,
1381 hasExtraSrcRegAllocReq = 1 in
1382def RetRA16 : MipsPseudo16<(outs), (ins), "", [(MipsRet)]>;
1383
Reed Kotler67439242012-10-17 22:29:54 +00001384
Reed Kotler164bb372012-10-23 01:35:48 +00001385// setcc patterns
1386
1387class SetCC_R16<PatFrag cond_op, Instruction I>:
1388 Mips16Pat<(cond_op CPU16Regs:$rx, CPU16Regs:$ry),
1389 (I CPU16Regs:$rx, CPU16Regs:$ry)>;
1390
1391class SetCC_I16<PatFrag cond_op, PatLeaf imm_type, Instruction I>:
1392 Mips16Pat<(cond_op CPU16Regs:$rx, imm_type:$imm16),
Reed Kotler097556d2012-10-25 21:33:30 +00001393 (I CPU16Regs:$rx, imm_type:$imm16)>;
Reed Kotler164bb372012-10-23 01:35:48 +00001394
Reed Kotler3589dd72012-10-28 06:02:37 +00001395
1396def: Mips16Pat<(i32 addr16:$addr),
1397 (AddiuRxRyOffMemX16 addr16:$addr)>;
1398
1399
Reed Kotlere47873a2012-10-26 03:09:34 +00001400// Large (>16 bit) immediate loads
Reed Kotler91ae9822013-10-27 21:57:36 +00001401def : Mips16Pat<(i32 imm:$imm), (LwConstant32 imm:$imm, -1)>;
Reed Kotler164bb372012-10-23 01:35:48 +00001402
Reed Kotler287f0442012-10-26 04:46:26 +00001403// Carry MipsPatterns
1404def : Mips16Pat<(subc CPU16Regs:$lhs, CPU16Regs:$rhs),
1405 (SubuRxRyRz16 CPU16Regs:$lhs, CPU16Regs:$rhs)>;
1406def : Mips16Pat<(addc CPU16Regs:$lhs, CPU16Regs:$rhs),
1407 (AdduRxRyRz16 CPU16Regs:$lhs, CPU16Regs:$rhs)>;
1408def : Mips16Pat<(addc CPU16Regs:$src, immSExt16:$imm),
1409 (AddiuRxRxImmX16 CPU16Regs:$src, imm:$imm)>;
1410
Reed Kotler67439242012-10-17 22:29:54 +00001411//
1412// Some branch conditional patterns are not generated by llvm at this time.
1413// Some are for seemingly arbitrary reasons not used: i.e. with signed number
1414// comparison they are used and for unsigned a different pattern is used.
1415// I am pushing upstream from the full mips16 port and it seemed that I needed
1416// these earlier and the mips32 port has these but now I cannot create test
1417// cases that use these patterns. While I sort this all out I will leave these
1418// extra patterns commented out and if I can be sure they are really not used,
1419// I will delete the code. I don't want to check the code in uncommented without
1420// a valid test case. In some cases, the compiler is generating patterns with
1421// setcc instead and earlier I had implemented setcc first so may have masked
1422// the problem. The setcc variants are suboptimal for mips16 so I may wantto
1423// figure out how to enable the brcond patterns or else possibly new
1424// combinations of of brcond and setcc.
1425//
1426//
1427// bcond-seteq
1428//
1429def: Mips16Pat
1430 <(brcond (i32 (seteq CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1431 (BteqzT8CmpX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1432 >;
1433
1434
1435def: Mips16Pat
1436 <(brcond (i32 (seteq CPU16Regs:$rx, immZExt16:$imm)), bb:$targ16),
1437 (BteqzT8CmpiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$targ16)
1438 >;
1439
1440def: Mips16Pat
1441 <(brcond (i32 (seteq CPU16Regs:$rx, 0)), bb:$targ16),
Reed Kotler09e59152013-11-15 02:21:52 +00001442 (BeqzRxImm16 CPU16Regs:$rx, bb:$targ16)
Reed Kotler67439242012-10-17 22:29:54 +00001443 >;
1444
1445//
1446// bcond-setgt (do we need to have this pair of setlt, setgt??)
1447//
1448def: Mips16Pat
1449 <(brcond (i32 (setgt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1450 (BtnezT8SltX16 CPU16Regs:$ry, CPU16Regs:$rx, bb:$imm16)
1451 >;
1452
1453//
1454// bcond-setge
1455//
1456def: Mips16Pat
1457 <(brcond (i32 (setge CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1458 (BteqzT8SltX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1459 >;
1460
1461//
1462// never called because compiler transforms a >= k to a > (k-1)
Reed Kotler164bb372012-10-23 01:35:48 +00001463def: Mips16Pat
1464 <(brcond (i32 (setge CPU16Regs:$rx, immSExt16:$imm)), bb:$imm16),
1465 (BteqzT8SltiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$imm16)
1466 >;
Reed Kotler67439242012-10-17 22:29:54 +00001467
1468//
1469// bcond-setlt
1470//
1471def: Mips16Pat
1472 <(brcond (i32 (setlt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1473 (BtnezT8SltX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1474 >;
1475
1476def: Mips16Pat
1477 <(brcond (i32 (setlt CPU16Regs:$rx, immSExt16:$imm)), bb:$imm16),
1478 (BtnezT8SltiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$imm16)
1479 >;
1480
1481//
1482// bcond-setle
1483//
1484def: Mips16Pat
1485 <(brcond (i32 (setle CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1486 (BteqzT8SltX16 CPU16Regs:$ry, CPU16Regs:$rx, bb:$imm16)
1487 >;
1488
1489//
1490// bcond-setne
1491//
1492def: Mips16Pat
1493 <(brcond (i32 (setne CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1494 (BtnezT8CmpX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1495 >;
1496
1497def: Mips16Pat
1498 <(brcond (i32 (setne CPU16Regs:$rx, immZExt16:$imm)), bb:$targ16),
1499 (BtnezT8CmpiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$targ16)
1500 >;
1501
1502def: Mips16Pat
1503 <(brcond (i32 (setne CPU16Regs:$rx, 0)), bb:$targ16),
Reed Kotler09e59152013-11-15 02:21:52 +00001504 (BnezRxImm16 CPU16Regs:$rx, bb:$targ16)
Reed Kotler67439242012-10-17 22:29:54 +00001505 >;
1506
1507//
1508// This needs to be there but I forget which code will generate it
1509//
1510def: Mips16Pat
1511 <(brcond CPU16Regs:$rx, bb:$targ16),
Reed Kotler09e59152013-11-15 02:21:52 +00001512 (BnezRxImm16 CPU16Regs:$rx, bb:$targ16)
Reed Kotler67439242012-10-17 22:29:54 +00001513 >;
1514
1515//
1516
1517//
1518// bcond-setugt
1519//
1520//def: Mips16Pat
1521// <(brcond (i32 (setugt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1522// (BtnezT8SltuX16 CPU16Regs:$ry, CPU16Regs:$rx, bb:$imm16)
1523// >;
1524
1525//
1526// bcond-setuge
1527//
1528//def: Mips16Pat
1529// <(brcond (i32 (setuge CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1530// (BteqzT8SltuX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1531// >;
1532
1533
1534//
1535// bcond-setult
1536//
1537//def: Mips16Pat
1538// <(brcond (i32 (setult CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1539// (BtnezT8SltuX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1540// >;
1541
Reed Kotlerf0e69682013-11-12 02:27:12 +00001542def: UncondBranch16_pat<br, Bimm16>;
Reed Kotler67439242012-10-17 22:29:54 +00001543
Akira Hatanaka765c3122012-06-21 20:39:10 +00001544// Small immediates
Reed Kotler67439242012-10-17 22:29:54 +00001545def: Mips16Pat<(i32 immSExt16:$in),
1546 (AddiuRxRxImmX16 (Move32R16 ZERO), immSExt16:$in)>;
1547
Akira Hatanaka22bec282012-08-03 22:57:02 +00001548def: Mips16Pat<(i32 immZExt16:$in), (LiRxImmX16 immZExt16:$in)>;
Akira Hatanaka64626fc2012-07-26 02:24:43 +00001549
Reed Kotlercf11c592012-10-12 02:01:09 +00001550//
1551// MipsDivRem
1552//
1553def: Mips16Pat
Akira Hatanakabe8612f2013-03-30 01:36:35 +00001554 <(MipsDivRem16 CPU16Regs:$rx, CPU16Regs:$ry),
Reed Kotlercf11c592012-10-12 02:01:09 +00001555 (DivRxRy16 CPU16Regs:$rx, CPU16Regs:$ry)>;
1556
1557//
1558// MipsDivRemU
1559//
1560def: Mips16Pat
Akira Hatanakabe8612f2013-03-30 01:36:35 +00001561 <(MipsDivRemU16 CPU16Regs:$rx, CPU16Regs:$ry),
Reed Kotlercf11c592012-10-12 02:01:09 +00001562 (DivuRxRy16 CPU16Regs:$rx, CPU16Regs:$ry)>;
1563
Reed Kotler097556d2012-10-25 21:33:30 +00001564// signed a,b
1565// x = (a>=b)?x:y
1566//
1567// if !(a < b) x = y
1568//
1569def : Mips16Pat<(select (i32 (setge CPU16Regs:$a, CPU16Regs:$b)),
1570 CPU16Regs:$x, CPU16Regs:$y),
1571 (SelTBteqZSlt CPU16Regs:$x, CPU16Regs:$y,
1572 CPU16Regs:$a, CPU16Regs:$b)>;
1573
1574// signed a,b
1575// x = (a>b)?x:y
1576//
1577// if (b < a) x = y
1578//
1579def : Mips16Pat<(select (i32 (setgt CPU16Regs:$a, CPU16Regs:$b)),
1580 CPU16Regs:$x, CPU16Regs:$y),
1581 (SelTBtneZSlt CPU16Regs:$x, CPU16Regs:$y,
1582 CPU16Regs:$b, CPU16Regs:$a)>;
1583
1584// unsigned a,b
1585// x = (a>=b)?x:y
1586//
1587// if !(a < b) x = y;
1588//
1589def : Mips16Pat<
1590 (select (i32 (setuge CPU16Regs:$a, CPU16Regs:$b)),
1591 CPU16Regs:$x, CPU16Regs:$y),
1592 (SelTBteqZSltu CPU16Regs:$x, CPU16Regs:$y,
1593 CPU16Regs:$a, CPU16Regs:$b)>;
1594
1595// unsigned a,b
1596// x = (a>b)?x:y
1597//
1598// if (b < a) x = y
1599//
1600def : Mips16Pat<(select (i32 (setugt CPU16Regs:$a, CPU16Regs:$b)),
1601 CPU16Regs:$x, CPU16Regs:$y),
1602 (SelTBtneZSltu CPU16Regs:$x, CPU16Regs:$y,
1603 CPU16Regs:$b, CPU16Regs:$a)>;
1604
1605// signed
1606// x = (a >= k)?x:y
1607// due to an llvm optimization, i don't think that this will ever
1608// be used. This is transformed into x = (a > k-1)?x:y
1609//
1610//
1611
1612//def : Mips16Pat<
1613// (select (i32 (setge CPU16Regs:$lhs, immSExt16:$rhs)),
1614// CPU16Regs:$T, CPU16Regs:$F),
1615// (SelTBteqZSlti CPU16Regs:$T, CPU16Regs:$F,
1616// CPU16Regs:$lhs, immSExt16:$rhs)>;
1617
1618//def : Mips16Pat<
1619// (select (i32 (setuge CPU16Regs:$lhs, immSExt16:$rhs)),
1620// CPU16Regs:$T, CPU16Regs:$F),
1621// (SelTBteqZSltiu CPU16Regs:$T, CPU16Regs:$F,
1622// CPU16Regs:$lhs, immSExt16:$rhs)>;
1623
1624// signed
1625// x = (a < k)?x:y
1626//
1627// if !(a < k) x = y;
1628//
1629def : Mips16Pat<
1630 (select (i32 (setlt CPU16Regs:$a, immSExt16:$b)),
1631 CPU16Regs:$x, CPU16Regs:$y),
1632 (SelTBtneZSlti CPU16Regs:$x, CPU16Regs:$y,
1633 CPU16Regs:$a, immSExt16:$b)>;
1634
1635
1636//
1637//
1638// signed
1639// x = (a <= b)? x : y
1640//
1641// if (b < a) x = y
1642//
1643def : Mips16Pat<(select (i32 (setle CPU16Regs:$a, CPU16Regs:$b)),
1644 CPU16Regs:$x, CPU16Regs:$y),
1645 (SelTBteqZSlt CPU16Regs:$x, CPU16Regs:$y,
1646 CPU16Regs:$b, CPU16Regs:$a)>;
1647
1648//
1649// unnsigned
1650// x = (a <= b)? x : y
1651//
1652// if (b < a) x = y
1653//
1654def : Mips16Pat<(select (i32 (setule CPU16Regs:$a, CPU16Regs:$b)),
1655 CPU16Regs:$x, CPU16Regs:$y),
1656 (SelTBteqZSltu CPU16Regs:$x, CPU16Regs:$y,
1657 CPU16Regs:$b, CPU16Regs:$a)>;
1658
1659//
1660// signed/unsigned
1661// x = (a == b)? x : y
1662//
1663// if (a != b) x = y
1664//
1665def : Mips16Pat<(select (i32 (seteq CPU16Regs:$a, CPU16Regs:$b)),
1666 CPU16Regs:$x, CPU16Regs:$y),
1667 (SelTBteqZCmp CPU16Regs:$x, CPU16Regs:$y,
1668 CPU16Regs:$b, CPU16Regs:$a)>;
1669
1670//
1671// signed/unsigned
1672// x = (a == 0)? x : y
1673//
1674// if (a != 0) x = y
1675//
1676def : Mips16Pat<(select (i32 (seteq CPU16Regs:$a, 0)),
1677 CPU16Regs:$x, CPU16Regs:$y),
1678 (SelBeqZ CPU16Regs:$x, CPU16Regs:$y,
1679 CPU16Regs:$a)>;
1680
1681
1682//
1683// signed/unsigned
1684// x = (a == k)? x : y
1685//
1686// if (a != k) x = y
1687//
1688def : Mips16Pat<(select (i32 (seteq CPU16Regs:$a, immZExt16:$k)),
1689 CPU16Regs:$x, CPU16Regs:$y),
1690 (SelTBteqZCmpi CPU16Regs:$x, CPU16Regs:$y,
1691 CPU16Regs:$a, immZExt16:$k)>;
1692
1693
1694//
1695// signed/unsigned
1696// x = (a != b)? x : y
1697//
1698// if (a == b) x = y
1699//
1700//
1701def : Mips16Pat<(select (i32 (setne CPU16Regs:$a, CPU16Regs:$b)),
1702 CPU16Regs:$x, CPU16Regs:$y),
1703 (SelTBtneZCmp CPU16Regs:$x, CPU16Regs:$y,
1704 CPU16Regs:$b, CPU16Regs:$a)>;
1705
1706//
1707// signed/unsigned
1708// x = (a != 0)? x : y
1709//
1710// if (a == 0) x = y
1711//
1712def : Mips16Pat<(select (i32 (setne CPU16Regs:$a, 0)),
1713 CPU16Regs:$x, CPU16Regs:$y),
1714 (SelBneZ CPU16Regs:$x, CPU16Regs:$y,
1715 CPU16Regs:$a)>;
1716
1717// signed/unsigned
1718// x = (a)? x : y
1719//
1720// if (!a) x = y
1721//
1722def : Mips16Pat<(select CPU16Regs:$a,
1723 CPU16Regs:$x, CPU16Regs:$y),
1724 (SelBneZ CPU16Regs:$x, CPU16Regs:$y,
1725 CPU16Regs:$a)>;
1726
1727
1728//
1729// signed/unsigned
1730// x = (a != k)? x : y
1731//
1732// if (a == k) x = y
1733//
1734def : Mips16Pat<(select (i32 (setne CPU16Regs:$a, immZExt16:$k)),
1735 CPU16Regs:$x, CPU16Regs:$y),
1736 (SelTBtneZCmpi CPU16Regs:$x, CPU16Regs:$y,
1737 CPU16Regs:$a, immZExt16:$k)>;
Reed Kotlercf11c592012-10-12 02:01:09 +00001738
Reed Kotler164bb372012-10-23 01:35:48 +00001739//
1740// When writing C code to test setxx these patterns,
1741// some will be transformed into
1742// other things. So we test using C code but using -O3 and -O0
1743//
1744// seteq
1745//
1746def : Mips16Pat
1747 <(seteq CPU16Regs:$lhs,CPU16Regs:$rhs),
1748 (SltiuCCRxImmX16 (XorRxRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs), 1)>;
1749
1750def : Mips16Pat
1751 <(seteq CPU16Regs:$lhs, 0),
1752 (SltiuCCRxImmX16 CPU16Regs:$lhs, 1)>;
1753
1754
1755//
1756// setge
1757//
1758
1759def: Mips16Pat
1760 <(setge CPU16Regs:$lhs, CPU16Regs:$rhs),
1761 (XorRxRxRy16 (SltCCRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs),
1762 (LiRxImmX16 1))>;
1763
1764//
1765// For constants, llvm transforms this to:
1766// x > (k -1) and then reverses the operands to use setlt. So this pattern
1767// is not used now by the compiler. (Presumably checking that k-1 does not
1768// overflow). The compiler never uses this at a the current time, due to
1769// other optimizations.
1770//
1771//def: Mips16Pat
1772// <(setge CPU16Regs:$lhs, immSExt16:$rhs),
1773// (XorRxRxRy16 (SltiCCRxImmX16 CPU16Regs:$lhs, immSExt16:$rhs),
1774// (LiRxImmX16 1))>;
1775
1776// This catches the x >= -32768 case by transforming it to x > -32769
1777//
1778def: Mips16Pat
1779 <(setgt CPU16Regs:$lhs, -32769),
1780 (XorRxRxRy16 (SltiCCRxImmX16 CPU16Regs:$lhs, -32768),
1781 (LiRxImmX16 1))>;
1782
1783//
1784// setgt
1785//
1786//
1787
1788def: Mips16Pat
1789 <(setgt CPU16Regs:$lhs, CPU16Regs:$rhs),
1790 (SltCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs)>;
1791
1792//
1793// setle
1794//
1795def: Mips16Pat
1796 <(setle CPU16Regs:$lhs, CPU16Regs:$rhs),
Reed Kotler7b503c22013-02-20 05:45:15 +00001797 (XorRxRxRy16 (SltCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs), (LiRxImm16 1))>;
Reed Kotler164bb372012-10-23 01:35:48 +00001798
1799//
1800// setlt
1801//
1802def: SetCC_R16<setlt, SltCCRxRy16>;
1803
1804def: SetCC_I16<setlt, immSExt16, SltiCCRxImmX16>;
1805
1806//
1807// setne
1808//
1809def : Mips16Pat
1810 <(setne CPU16Regs:$lhs,CPU16Regs:$rhs),
1811 (SltuCCRxRy16 (LiRxImmX16 0),
1812 (XorRxRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs))>;
1813
1814
1815//
1816// setuge
1817//
1818def: Mips16Pat
1819 <(setuge CPU16Regs:$lhs, CPU16Regs:$rhs),
1820 (XorRxRxRy16 (SltuCCRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs),
1821 (LiRxImmX16 1))>;
1822
1823// this pattern will never be used because the compiler will transform
1824// x >= k to x > (k - 1) and then use SLT
1825//
1826//def: Mips16Pat
1827// <(setuge CPU16Regs:$lhs, immZExt16:$rhs),
1828// (XorRxRxRy16 (SltiuCCRxImmX16 CPU16Regs:$lhs, immZExt16:$rhs),
Reed Kotler097556d2012-10-25 21:33:30 +00001829// (LiRxImmX16 1))>;
Reed Kotler164bb372012-10-23 01:35:48 +00001830
1831//
1832// setugt
1833//
1834def: Mips16Pat
1835 <(setugt CPU16Regs:$lhs, CPU16Regs:$rhs),
1836 (SltuCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs)>;
1837
1838//
1839// setule
1840//
1841def: Mips16Pat
1842 <(setule CPU16Regs:$lhs, CPU16Regs:$rhs),
1843 (XorRxRxRy16 (SltuCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs), (LiRxImmX16 1))>;
1844
1845//
1846// setult
1847//
1848def: SetCC_R16<setult, SltuCCRxRy16>;
1849
1850def: SetCC_I16<setult, immSExt16, SltiuCCRxImmX16>;
1851
Reed Kotler7e4d9962012-10-27 00:57:14 +00001852def: Mips16Pat<(add CPU16Regs:$hi, (MipsLo tglobaladdr:$lo)),
1853 (AddiuRxRxImmX16 CPU16Regs:$hi, tglobaladdr:$lo)>;
1854
1855// hi/lo relocs
Reed Kotler1b5b5c92013-10-04 22:01:40 +00001856def : Mips16Pat<(MipsHi tblockaddress:$in),
1857 (SllX16 (LiRxImmX16 tblockaddress:$in), 16)>;
Reed Kotler7b503c22013-02-20 05:45:15 +00001858def : Mips16Pat<(MipsHi tglobaladdr:$in),
Reed Kotlerf8933f82013-02-02 04:07:35 +00001859 (SllX16 (LiRxImmX16 tglobaladdr:$in), 16)>;
Reed Kotler9cb8e7b2013-02-13 08:32:14 +00001860def : Mips16Pat<(MipsHi tjumptable:$in),
1861 (SllX16 (LiRxImmX16 tjumptable:$in), 16)>;
Jack Carter7ab15fa2013-01-19 02:00:40 +00001862def : Mips16Pat<(MipsHi tglobaltlsaddr:$in),
Reed Kotler7e4d9962012-10-27 00:57:14 +00001863 (SllX16 (LiRxImmX16 tglobaltlsaddr:$in), 16)>;
1864
Reed Kotler1b5b5c92013-10-04 22:01:40 +00001865def : Mips16Pat<(MipsLo tblockaddress:$in), (LiRxImmX16 tblockaddress:$in)>;
1866
Reed Kotlerb650f6b2012-10-26 22:57:32 +00001867// wrapper_pic
1868class Wrapper16Pat<SDNode node, Instruction ADDiuOp, RegisterClass RC>:
1869 Mips16Pat<(MipsWrapper RC:$gp, node:$in),
1870 (ADDiuOp RC:$gp, node:$in)>;
1871
1872
Reed Kotler3589dd72012-10-28 06:02:37 +00001873def : Wrapper16Pat<tglobaladdr, AddiuRxRxImmX16, CPU16Regs>;
Reed Kotlerb650f6b2012-10-26 22:57:32 +00001874def : Wrapper16Pat<tglobaltlsaddr, AddiuRxRxImmX16, CPU16Regs>;
1875
Reed Kotler740981e2012-10-29 19:39:04 +00001876def : Mips16Pat<(i32 (extloadi8 addr16:$src)),
1877 (LbuRxRyOffMemX16 addr16:$src)>;
1878def : Mips16Pat<(i32 (extloadi16 addr16:$src)),
Chandler Carruthf12e3a62012-11-30 11:45:22 +00001879 (LhuRxRyOffMemX16 addr16:$src)>;
Reed Kotlerbb870e22013-08-07 04:00:26 +00001880
1881def: Mips16Pat<(trap), (Break16)>;
1882
Reed Kotler445d0ad2013-10-07 20:46:19 +00001883def : Mips16Pat<(sext_inreg CPU16Regs:$val, i8),
1884 (SebRx16 CPU16Regs:$val)>;
1885
1886def : Mips16Pat<(sext_inreg CPU16Regs:$val, i16),
1887 (SehRx16 CPU16Regs:$val)>;
1888
Reed Kotlerd6aadc72013-09-18 22:46:09 +00001889def GotPrologue16:
1890 MipsPseudo16<
1891 (outs CPU16Regs:$rh, CPU16Regs:$rl),
1892 (ins simm16:$immHi, simm16:$immLo),
1893 ".align 2\n\tli\t$rh, $immHi\n\taddiu\t$rl, $$pc, $immLo\n ",[]> ;
Reed Kotler91ae9822013-10-27 21:57:36 +00001894
1895// An operand for the CONSTPOOL_ENTRY pseudo-instruction.
1896def cpinst_operand : Operand<i32> {
1897 // let PrintMethod = "printCPInstOperand";
1898}
1899
1900// CONSTPOOL_ENTRY - This instruction represents a floating constant pool in
1901// the function. The first operand is the ID# for this instruction, the second
1902// is the index into the MachineConstantPool that this is, the third is the
1903// size in bytes of this constant pool entry.
1904//
1905let neverHasSideEffects = 1, isNotDuplicable = 1 in
1906def CONSTPOOL_ENTRY :
1907MipsPseudo16<(outs), (ins cpinst_operand:$instid, cpinst_operand:$cpidx,
1908 i32imm:$size), "foo", []>;
Reed Kotler0f007fc2013-11-05 08:14:14 +00001909