[mips][mips64r6] [sl][duw]xc1 are not available on MIPS32r6/MIPS64r6
[oota-llvm.git] / lib / Target / Mips / Mips32r6InstrInfo.td
1 //=- Mips32r6InstrInfo.td - Mips32r6 Instruction Information -*- 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 Mips32r6 instructions.
11 //
12 //===----------------------------------------------------------------------===//
13
14 include "Mips32r6InstrFormats.td"
15
16 // Notes about removals/changes from MIPS32r6:
17 // Unclear: ssnop
18 // Reencoded: cache, pref
19 // Reencoded: clo, clz
20 // Reencoded: jr -> jalr
21 // Reencoded: jr.hb -> jalr.hb
22 // Reencoded: ldc2
23 // Reencoded: ll, sc
24 // Reencoded: lwc2
25 // Reencoded: sdbbp
26 // Reencoded: sdc2
27 // Reencoded: swc2
28 // Removed: bc1any2, bc1any4
29 // Removed: bc2[ft]
30 // Removed: bc2f, bc2t
31 // Removed: bgezal
32 // Removed: bltzal
33 // Removed: bc1[ft]
34 // Rencoded: [ls][wd]c2
35
36 def brtarget21 : Operand<OtherVT> {
37   let EncoderMethod = "getBranchTarget21OpValue";
38   let OperandType = "OPERAND_PCREL";
39   let DecoderMethod = "DecodeBranchTarget21";
40   let ParserMatchClass = MipsJumpTargetAsmOperand;
41 }
42
43 def brtarget26 : Operand<OtherVT> {
44   let EncoderMethod = "getBranchTarget26OpValue";
45   let OperandType = "OPERAND_PCREL";
46   let DecoderMethod = "DecodeBranchTarget26";
47   let ParserMatchClass = MipsJumpTargetAsmOperand;
48 }
49
50 def jmpoffset16 : Operand<OtherVT> {
51   let EncoderMethod = "getJumpOffset16OpValue";
52   let ParserMatchClass = MipsJumpTargetAsmOperand;
53 }
54
55 def calloffset16 : Operand<iPTR> {
56   let EncoderMethod = "getJumpOffset16OpValue";
57   let ParserMatchClass = MipsJumpTargetAsmOperand;
58 }
59
60 //===----------------------------------------------------------------------===//
61 //
62 // Instruction Encodings
63 //
64 //===----------------------------------------------------------------------===//
65
66 class ADDIUPC_ENC : PCREL19_FM<OPCODE2_ADDIUPC>;
67 class ALIGN_ENC  : SPECIAL3_ALIGN_FM<OPCODE6_ALIGN>;
68 class ALUIPC_ENC : PCREL16_FM<OPCODE5_ALUIPC>;
69 class AUI_ENC    : AUI_FM;
70 class AUIPC_ENC  : PCREL16_FM<OPCODE5_AUIPC>;
71
72 class BALC_ENC  : BRANCH_OFF26_FM<0b111010>;
73 class BC_ENC    : BRANCH_OFF26_FM<0b110010>;
74 class BEQC_ENC  : CMP_BRANCH_2R_OFF16_FM<OPGROUP_ADDI>,
75                   DecodeDisambiguates<"AddiGroupBranch">;
76 class BEQZALC_ENC : CMP_BRANCH_1R_RT_OFF16_FM<OPGROUP_ADDI>,
77                     DecodeDisambiguatedBy<"DaddiGroupBranch">;
78 class BNEC_ENC  : CMP_BRANCH_2R_OFF16_FM<OPGROUP_DADDI>,
79                   DecodeDisambiguates<"DaddiGroupBranch">;
80 class BNEZALC_ENC : CMP_BRANCH_1R_RT_OFF16_FM<OPGROUP_DADDI>,
81                     DecodeDisambiguatedBy<"DaddiGroupBranch">;
82
83 class BLTZC_ENC : CMP_BRANCH_1R_BOTH_OFF16_FM<OPGROUP_BGTZL>,
84                   DecodeDisambiguates<"BgtzlGroupBranch">;
85 class BGEC_ENC  : CMP_BRANCH_2R_OFF16_FM<OPGROUP_BLEZL>,
86                   DecodeDisambiguatedBy<"BlezlGroupBranch">;
87 class BGEUC_ENC : CMP_BRANCH_2R_OFF16_FM<OPGROUP_BLEZ>,
88                   DecodeDisambiguatedBy<"BlezGroupBranch">;
89 class BGEZC_ENC : CMP_BRANCH_1R_BOTH_OFF16_FM<OPGROUP_BLEZL>,
90                   DecodeDisambiguates<"BlezlGroupBranch">;
91 class BGTZALC_ENC : CMP_BRANCH_1R_RT_OFF16_FM<OPGROUP_BGTZ>,
92                     DecodeDisambiguatedBy<"BgtzGroupBranch">;
93
94 class BLEZC_ENC : CMP_BRANCH_1R_RT_OFF16_FM<OPGROUP_BLEZL>,
95                   DecodeDisambiguatedBy<"BlezlGroupBranch">;
96 class BLTZALC_ENC : CMP_BRANCH_1R_BOTH_OFF16_FM<OPGROUP_BGTZ>,
97                     DecodeDisambiguates<"BgtzGroupBranch">;
98 class BGTZC_ENC : CMP_BRANCH_1R_RT_OFF16_FM<OPGROUP_BGTZL>,
99                   DecodeDisambiguatedBy<"BgtzlGroupBranch">;
100
101 class BEQZC_ENC : CMP_BRANCH_OFF21_FM<0b110110>;
102 class BGEZALC_ENC : CMP_BRANCH_1R_BOTH_OFF16_FM<OPGROUP_BLEZ>,
103                     DecodeDisambiguates<"BlezGroupBranch">;
104 class BNEZC_ENC : CMP_BRANCH_OFF21_FM<0b111110>;
105
106 class BC1EQZ_ENC : COP1_BCCZ_FM<OPCODE5_BC1EQZ>;
107 class BC1NEZ_ENC : COP1_BCCZ_FM<OPCODE5_BC1NEZ>;
108 class BC2EQZ_ENC : COP2_BCCZ_FM<OPCODE5_BC2EQZ>;
109 class BC2NEZ_ENC : COP2_BCCZ_FM<OPCODE5_BC2NEZ>;
110
111 class JIALC_ENC : JMP_IDX_COMPACT_FM<0b111110>;
112 class JIC_ENC   : JMP_IDX_COMPACT_FM<0b110110>;
113 class JR_HB_R6_ENC : JR_HB_R6_FM<OPCODE6_JALR>;
114 class BITSWAP_ENC : SPECIAL3_2R_FM<OPCODE6_BITSWAP>;
115 class BLEZALC_ENC : CMP_BRANCH_1R_RT_OFF16_FM<OPGROUP_BLEZ>,
116                     DecodeDisambiguatedBy<"BlezGroupBranch">;
117 class BNVC_ENC   : CMP_BRANCH_2R_OFF16_FM<OPGROUP_DADDI>,
118                    DecodeDisambiguatedBy<"DaddiGroupBranch">;
119 class BOVC_ENC   : CMP_BRANCH_2R_OFF16_FM<OPGROUP_ADDI>,
120                    DecodeDisambiguatedBy<"AddiGroupBranch">;
121 class DIV_ENC    : SPECIAL_3R_FM<0b00010, 0b011010>;
122 class DIVU_ENC   : SPECIAL_3R_FM<0b00010, 0b011011>;
123 class MOD_ENC    : SPECIAL_3R_FM<0b00011, 0b011010>;
124 class MODU_ENC   : SPECIAL_3R_FM<0b00011, 0b011011>;
125 class MUH_ENC    : SPECIAL_3R_FM<0b00011, 0b011000>;
126 class MUHU_ENC   : SPECIAL_3R_FM<0b00011, 0b011001>;
127 class MUL_R6_ENC : SPECIAL_3R_FM<0b00010, 0b011000>;
128 class MULU_ENC   : SPECIAL_3R_FM<0b00010, 0b011001>;
129
130 class MADDF_S_ENC  : COP1_3R_FM<0b011000, FIELD_FMT_S>;
131 class MADDF_D_ENC  : COP1_3R_FM<0b011000, FIELD_FMT_D>;
132 class MSUBF_S_ENC  : COP1_3R_FM<0b011001, FIELD_FMT_S>;
133 class MSUBF_D_ENC  : COP1_3R_FM<0b011001, FIELD_FMT_D>;
134
135 class SEL_D_ENC  : COP1_3R_FM<0b010000, FIELD_FMT_D>;
136 class SEL_S_ENC  : COP1_3R_FM<0b010000, FIELD_FMT_S>;
137
138 class SELEQZ_ENC : SPECIAL_3R_FM<0b00000, 0b110101>;
139 class SELNEZ_ENC : SPECIAL_3R_FM<0b00000, 0b110111>;
140
141 class LWPC_ENC   : PCREL19_FM<OPCODE2_LWPC>;
142 class LWUPC_ENC  : PCREL19_FM<OPCODE2_LWUPC>;
143
144 class MAX_S_ENC : COP1_3R_FM<0b011101, FIELD_FMT_S>;
145 class MAX_D_ENC : COP1_3R_FM<0b011101, FIELD_FMT_D>;
146 class MIN_S_ENC : COP1_3R_FM<0b011100, FIELD_FMT_S>;
147 class MIN_D_ENC : COP1_3R_FM<0b011100, FIELD_FMT_D>;
148
149 class MAXA_S_ENC : COP1_3R_FM<0b011111, FIELD_FMT_S>;
150 class MAXA_D_ENC : COP1_3R_FM<0b011111, FIELD_FMT_D>;
151 class MINA_S_ENC : COP1_3R_FM<0b011110, FIELD_FMT_S>;
152 class MINA_D_ENC : COP1_3R_FM<0b011110, FIELD_FMT_D>;
153
154 class SELEQZ_S_ENC : COP1_3R_FM<0b010100, FIELD_FMT_S>;
155 class SELEQZ_D_ENC : COP1_3R_FM<0b010100, FIELD_FMT_D>;
156 class SELNEZ_S_ENC : COP1_3R_FM<0b010111, FIELD_FMT_S>;
157 class SELNEZ_D_ENC : COP1_3R_FM<0b010111, FIELD_FMT_D>;
158
159 class RINT_S_ENC : COP1_2R_FM<0b011010, FIELD_FMT_S>;
160 class RINT_D_ENC : COP1_2R_FM<0b011010, FIELD_FMT_D>;
161 class CLASS_S_ENC : COP1_2R_FM<0b011011, FIELD_FMT_S>;
162 class CLASS_D_ENC : COP1_2R_FM<0b011011, FIELD_FMT_D>;
163
164 class CMP_CONDN_DESC_BASE<string CondStr, string Typestr,
165                           RegisterOperand FGROpnd,
166                           SDPatternOperator Op = null_frag> {
167   dag OutOperandList = (outs FGRCCOpnd:$fd);
168   dag InOperandList = (ins FGROpnd:$fs, FGROpnd:$ft);
169   string AsmString = !strconcat("cmp.", CondStr, ".", Typestr, "\t$fd, $fs, $ft");
170   list<dag> Pattern = [(set FGRCCOpnd:$fd, (Op FGROpnd:$fs, FGROpnd:$ft))];
171 }
172
173 //===----------------------------------------------------------------------===//
174 //
175 // Instruction Multiclasses
176 //
177 //===----------------------------------------------------------------------===//
178
179 multiclass CMP_CC_M <FIELD_CMP_FORMAT Format, string Typestr,
180                      RegisterOperand FGROpnd>{
181   def CMP_F_#NAME : COP1_CMP_CONDN_FM<Format, FIELD_CMP_COND_F>,
182                     CMP_CONDN_DESC_BASE<"f", Typestr, FGROpnd>,
183                     ISA_MIPS32R6;
184   def CMP_UN_#NAME : COP1_CMP_CONDN_FM<Format, FIELD_CMP_COND_UN>,
185                      CMP_CONDN_DESC_BASE<"un", Typestr, FGROpnd, setuo>,
186                      ISA_MIPS32R6;
187   def CMP_EQ_#NAME : COP1_CMP_CONDN_FM<Format, FIELD_CMP_COND_EQ>,
188                      CMP_CONDN_DESC_BASE<"eq", Typestr, FGROpnd, setoeq>,
189                      ISA_MIPS32R6;
190   def CMP_UEQ_#NAME : COP1_CMP_CONDN_FM<Format, FIELD_CMP_COND_UEQ>,
191                       CMP_CONDN_DESC_BASE<"ueq", Typestr, FGROpnd, setueq>,
192                       ISA_MIPS32R6;
193   def CMP_OLT_#NAME : COP1_CMP_CONDN_FM<Format, FIELD_CMP_COND_OLT>,
194                       CMP_CONDN_DESC_BASE<"olt", Typestr, FGROpnd, setolt>,
195                       ISA_MIPS32R6;
196   def CMP_ULT_#NAME : COP1_CMP_CONDN_FM<Format, FIELD_CMP_COND_ULT>,
197                       CMP_CONDN_DESC_BASE<"ult", Typestr, FGROpnd, setult>,
198                       ISA_MIPS32R6;
199   def CMP_OLE_#NAME : COP1_CMP_CONDN_FM<Format, FIELD_CMP_COND_OLE>,
200                       CMP_CONDN_DESC_BASE<"ole", Typestr, FGROpnd, setole>,
201                       ISA_MIPS32R6;
202   def CMP_ULE_#NAME : COP1_CMP_CONDN_FM<Format, FIELD_CMP_COND_ULE>,
203                       CMP_CONDN_DESC_BASE<"ule", Typestr, FGROpnd, setule>,
204                       ISA_MIPS32R6;
205   def CMP_SF_#NAME : COP1_CMP_CONDN_FM<Format, FIELD_CMP_COND_SF>,
206                      CMP_CONDN_DESC_BASE<"sf", Typestr, FGROpnd>,
207                      ISA_MIPS32R6;
208   def CMP_NGLE_#NAME : COP1_CMP_CONDN_FM<Format, FIELD_CMP_COND_NGLE>,
209                        CMP_CONDN_DESC_BASE<"ngle", Typestr, FGROpnd>,
210                        ISA_MIPS32R6;
211   def CMP_SEQ_#NAME : COP1_CMP_CONDN_FM<Format, FIELD_CMP_COND_SEQ>,
212                       CMP_CONDN_DESC_BASE<"seq", Typestr, FGROpnd>,
213                       ISA_MIPS32R6;
214   def CMP_NGL_#NAME : COP1_CMP_CONDN_FM<Format, FIELD_CMP_COND_NGL>,
215                       CMP_CONDN_DESC_BASE<"ngl", Typestr, FGROpnd>,
216                       ISA_MIPS32R6;
217   def CMP_LT_#NAME : COP1_CMP_CONDN_FM<Format, FIELD_CMP_COND_LT>,
218                      CMP_CONDN_DESC_BASE<"lt", Typestr, FGROpnd>,
219                      ISA_MIPS32R6;
220   def CMP_NGE_#NAME : COP1_CMP_CONDN_FM<Format, FIELD_CMP_COND_NGE>,
221                       CMP_CONDN_DESC_BASE<"nge", Typestr, FGROpnd>,
222                       ISA_MIPS32R6;
223   def CMP_LE_#NAME : COP1_CMP_CONDN_FM<Format, FIELD_CMP_COND_LE>,
224                      CMP_CONDN_DESC_BASE<"le", Typestr, FGROpnd>,
225                      ISA_MIPS32R6;
226   def CMP_NGT_#NAME : COP1_CMP_CONDN_FM<Format, FIELD_CMP_COND_NGT>,
227                       CMP_CONDN_DESC_BASE<"ngt", Typestr, FGROpnd>,
228                       ISA_MIPS32R6;
229 }
230
231 //===----------------------------------------------------------------------===//
232 //
233 // Instruction Descriptions
234 //
235 //===----------------------------------------------------------------------===//
236
237 class PCREL_DESC_BASE<string instr_asm, RegisterOperand GPROpnd,
238                       Operand ImmOpnd> {
239   dag OutOperandList = (outs GPROpnd:$rs);
240   dag InOperandList = (ins ImmOpnd:$imm);
241   string AsmString = !strconcat(instr_asm, "\t$rs, $imm");
242   list<dag> Pattern = [];
243 }
244
245 class ADDIUPC_DESC : PCREL_DESC_BASE<"addiupc", GPR32Opnd, simm19_lsl2>;
246 class LWPC_DESC: PCREL_DESC_BASE<"lwpc", GPR32Opnd, simm19_lsl2>;
247 class LWUPC_DESC: PCREL_DESC_BASE<"lwupc", GPR32Opnd, simm19_lsl2>;
248
249 class ALIGN_DESC_BASE<string instr_asm, RegisterOperand GPROpnd,
250                       Operand ImmOpnd> {
251   dag OutOperandList = (outs GPROpnd:$rd);
252   dag InOperandList = (ins GPROpnd:$rs, GPROpnd:$rt, ImmOpnd:$bp);
253   string AsmString = !strconcat(instr_asm, "\t$rd, $rs, $rt, $bp");
254   list<dag> Pattern = [];
255 }
256
257 class ALIGN_DESC : ALIGN_DESC_BASE<"align", GPR32Opnd, uimm2>;
258
259 class ALUIPC_DESC_BASE<string instr_asm, RegisterOperand GPROpnd> {
260   dag OutOperandList = (outs GPROpnd:$rs);
261   dag InOperandList = (ins simm16:$imm);
262   string AsmString = !strconcat(instr_asm, "\t$rs, $imm");
263   list<dag> Pattern = [];
264 }
265
266 class ALUIPC_DESC : ALUIPC_DESC_BASE<"aluipc", GPR32Opnd>;
267 class AUIPC_DESC : ALUIPC_DESC_BASE<"auipc", GPR32Opnd>;
268
269 class AUI_DESC_BASE<string instr_asm, RegisterOperand GPROpnd> {
270   dag OutOperandList = (outs GPROpnd:$rs);
271   dag InOperandList = (ins GPROpnd:$rt, simm16:$imm);
272   string AsmString = !strconcat(instr_asm, "\t$rs, $rt, $imm");
273   list<dag> Pattern = [];
274 }
275
276 class AUI_DESC : AUI_DESC_BASE<"aui", GPR32Opnd>;
277
278 class BRANCH_DESC_BASE {
279   bit isBranch = 1;
280   bit isTerminator = 1;
281   bit hasDelaySlot = 0;
282 }
283
284 class BC_DESC_BASE<string instr_asm, DAGOperand opnd> : BRANCH_DESC_BASE {
285   dag InOperandList = (ins opnd:$offset);
286   dag OutOperandList = (outs);
287   string AsmString = !strconcat(instr_asm, "\t$offset");
288   bit isBarrier = 1;
289 }
290
291 class CMP_BC_DESC_BASE<string instr_asm, DAGOperand opnd,
292                        RegisterOperand GPROpnd> : BRANCH_DESC_BASE {
293   dag InOperandList = (ins GPROpnd:$rs, GPROpnd:$rt, opnd:$offset);
294   dag OutOperandList = (outs);
295   string AsmString = !strconcat(instr_asm, "\t$rs, $rt, $offset");
296   list<Register> Defs = [AT];
297 }
298
299 class CMP_CBR_EQNE_Z_DESC_BASE<string instr_asm, DAGOperand opnd,
300                                RegisterOperand GPROpnd> : BRANCH_DESC_BASE {
301   dag InOperandList = (ins GPROpnd:$rs, opnd:$offset);
302   dag OutOperandList = (outs);
303   string AsmString = !strconcat(instr_asm, "\t$rs, $offset");
304   list<Register> Defs = [AT];
305 }
306
307 class CMP_CBR_RT_Z_DESC_BASE<string instr_asm, DAGOperand opnd,
308                              RegisterOperand GPROpnd> : BRANCH_DESC_BASE {
309   dag InOperandList = (ins GPROpnd:$rt, opnd:$offset);
310   dag OutOperandList = (outs);
311   string AsmString = !strconcat(instr_asm, "\t$rt, $offset");
312   list<Register> Defs = [AT];
313 }
314
315 class BALC_DESC : BC_DESC_BASE<"balc", brtarget26> {
316   bit isCall = 1;
317   list<Register> Defs = [RA];
318 }
319
320 class BC_DESC : BC_DESC_BASE<"bc", brtarget26>;
321 class BGEC_DESC : CMP_BC_DESC_BASE<"bgec", brtarget, GPR32Opnd>;
322 class BGEUC_DESC : CMP_BC_DESC_BASE<"bgeuc", brtarget, GPR32Opnd>;
323 class BEQC_DESC : CMP_BC_DESC_BASE<"beqc", brtarget, GPR32Opnd>;
324 class BNEC_DESC : CMP_BC_DESC_BASE<"bnec", brtarget, GPR32Opnd>;
325
326 class BLTZC_DESC : CMP_CBR_RT_Z_DESC_BASE<"bltzc", brtarget, GPR32Opnd>;
327 class BGEZC_DESC : CMP_CBR_RT_Z_DESC_BASE<"bgezc", brtarget, GPR32Opnd>;
328
329 class BLEZC_DESC : CMP_CBR_RT_Z_DESC_BASE<"blezc", brtarget, GPR32Opnd>;
330 class BGTZC_DESC : CMP_CBR_RT_Z_DESC_BASE<"bgtzc", brtarget, GPR32Opnd>;
331
332 class BEQZC_DESC : CMP_CBR_EQNE_Z_DESC_BASE<"beqzc", brtarget21, GPR32Opnd>;
333 class BNEZC_DESC : CMP_CBR_EQNE_Z_DESC_BASE<"bnezc", brtarget21, GPR32Opnd>;
334
335 class COP1_BCCZ_DESC_BASE<string instr_asm> : BRANCH_DESC_BASE {
336   dag InOperandList = (ins FGR64Opnd:$ft, brtarget:$offset);
337   dag OutOperandList = (outs);
338   string AsmString = instr_asm;
339   bit hasDelaySlot = 1;
340 }
341
342 class BC1EQZ_DESC : COP1_BCCZ_DESC_BASE<"bc1eqz $ft, $offset">;
343 class BC1NEZ_DESC : COP1_BCCZ_DESC_BASE<"bc1nez $ft, $offset">;
344
345 class COP2_BCCZ_DESC_BASE<string instr_asm> : BRANCH_DESC_BASE {
346   dag InOperandList = (ins COP2Opnd:$ct, brtarget:$offset);
347   dag OutOperandList = (outs);
348   string AsmString = instr_asm;
349   bit hasDelaySlot = 1;
350 }
351
352 class BC2EQZ_DESC : COP2_BCCZ_DESC_BASE<"bc2eqz $ct, $offset">;
353 class BC2NEZ_DESC : COP2_BCCZ_DESC_BASE<"bc2nez $ct, $offset">;
354
355 class BOVC_DESC   : CMP_BC_DESC_BASE<"bovc", brtarget, GPR32Opnd>;
356 class BNVC_DESC   : CMP_BC_DESC_BASE<"bnvc", brtarget, GPR32Opnd>;
357
358 class JMP_IDX_COMPACT_DESC_BASE<string opstr, DAGOperand opnd,
359                                 RegisterOperand GPROpnd> {
360   dag InOperandList = (ins GPROpnd:$rt, opnd:$offset);
361   string AsmString = !strconcat(opstr, "\t$rt, $offset");
362   list<dag> Pattern = [];
363   bit isTerminator = 1;
364   bit hasDelaySlot = 0;
365   string DecoderMethod = "DecodeSimm16";
366 }
367
368 class JIALC_DESC : JMP_IDX_COMPACT_DESC_BASE<"jialc", calloffset16,
369                                              GPR32Opnd> {
370   bit isCall = 1;
371   list<Register> Defs = [RA];
372 }
373
374 class JIC_DESC : JMP_IDX_COMPACT_DESC_BASE<"jic", jmpoffset16, GPR32Opnd> {
375   bit isBarrier = 1;
376   list<Register> Defs = [AT];
377 }
378
379 class JR_HB_R6_DESC : JR_HB_DESC_BASE<"jr.hb", GPR32Opnd> {
380   bit isBranch = 1;
381   bit isIndirectBranch = 1;
382   bit hasDelaySlot = 1;
383   bit isTerminator=1;
384   bit isBarrier=1;
385 }
386
387 class BITSWAP_DESC_BASE<string instr_asm, RegisterOperand GPROpnd> {
388   dag OutOperandList = (outs GPROpnd:$rd);
389   dag InOperandList = (ins GPROpnd:$rt);
390   string AsmString = !strconcat(instr_asm, "\t$rd, $rt");
391   list<dag> Pattern = [];
392 }
393
394 class BITSWAP_DESC : BITSWAP_DESC_BASE<"bitswap", GPR32Opnd>;
395
396 class DIVMOD_DESC_BASE<string instr_asm, RegisterOperand GPROpnd,
397                        SDPatternOperator Op=null_frag> {
398   dag OutOperandList = (outs GPROpnd:$rd);
399   dag InOperandList = (ins GPROpnd:$rs, GPROpnd:$rt);
400   string AsmString = !strconcat(instr_asm, "\t$rd, $rs, $rt");
401   list<dag> Pattern = [(set GPROpnd:$rd, (Op GPROpnd:$rs, GPROpnd:$rt))];
402
403   // This instruction doesn't trap division by zero itself. We must insert
404   // teq instructions as well.
405   bit usesCustomInserter = 1;
406 }
407
408 class DIV_DESC  : DIVMOD_DESC_BASE<"div", GPR32Opnd, sdiv>;
409 class DIVU_DESC : DIVMOD_DESC_BASE<"divu", GPR32Opnd, udiv>;
410 class MOD_DESC  : DIVMOD_DESC_BASE<"mod", GPR32Opnd, srem>;
411 class MODU_DESC : DIVMOD_DESC_BASE<"modu", GPR32Opnd, urem>;
412
413 class BEQZALC_DESC : CMP_CBR_RT_Z_DESC_BASE<"beqzalc", brtarget, GPR32Opnd> {
414   list<Register> Defs = [RA];
415 }
416
417 class BGEZALC_DESC : CMP_CBR_RT_Z_DESC_BASE<"bgezalc", brtarget, GPR32Opnd> {
418   list<Register> Defs = [RA];
419 }
420
421 class BGTZALC_DESC : CMP_CBR_RT_Z_DESC_BASE<"bgtzalc", brtarget, GPR32Opnd> {
422   list<Register> Defs = [RA];
423 }
424
425 class BLEZALC_DESC : CMP_CBR_RT_Z_DESC_BASE<"blezalc", brtarget, GPR32Opnd> {
426   list<Register> Defs = [RA];
427 }
428
429 class BLTZALC_DESC : CMP_CBR_RT_Z_DESC_BASE<"bltzalc", brtarget, GPR32Opnd> {
430   list<Register> Defs = [RA];
431 }
432
433 class BNEZALC_DESC : CMP_CBR_RT_Z_DESC_BASE<"bnezalc", brtarget, GPR32Opnd> {
434   list<Register> Defs = [RA];
435 }
436
437 class MUL_R6_DESC_BASE<string instr_asm, RegisterOperand GPROpnd,
438                        SDPatternOperator Op=null_frag> {
439   dag OutOperandList = (outs GPROpnd:$rd);
440   dag InOperandList = (ins GPROpnd:$rs, GPROpnd:$rt);
441   string AsmString = !strconcat(instr_asm, "\t$rd, $rs, $rt");
442   list<dag> Pattern = [(set GPROpnd:$rd, (Op GPROpnd:$rs, GPROpnd:$rt))];
443 }
444
445 class MUH_DESC    : MUL_R6_DESC_BASE<"muh", GPR32Opnd, mulhs>;
446 class MUHU_DESC   : MUL_R6_DESC_BASE<"muhu", GPR32Opnd, mulhu>;
447 class MUL_R6_DESC : MUL_R6_DESC_BASE<"mul", GPR32Opnd, mul>;
448 class MULU_DESC   : MUL_R6_DESC_BASE<"mulu", GPR32Opnd>;
449
450 class COP1_SEL_DESC_BASE<string instr_asm, RegisterOperand FGROpnd> {
451   dag OutOperandList = (outs FGROpnd:$fd);
452   dag InOperandList = (ins FGRCCOpnd:$fd_in, FGROpnd:$fs, FGROpnd:$ft);
453   string AsmString = !strconcat(instr_asm, "\t$fd, $fs, $ft");
454   list<dag> Pattern = [(set FGROpnd:$fd, (select FGRCCOpnd:$fd_in,
455                                                  FGROpnd:$ft,
456                                                  FGROpnd:$fs))];
457   string Constraints = "$fd_in = $fd";
458 }
459
460 class SEL_D_DESC : COP1_SEL_DESC_BASE<"sel.d", FGR64Opnd> {
461   // We must insert a SUBREG_TO_REG around $fd_in
462   bit usesCustomInserter = 1;
463 }
464 class SEL_S_DESC : COP1_SEL_DESC_BASE<"sel.s", FGR32Opnd>;
465
466 class SELEQNE_Z_DESC_BASE<string instr_asm, RegisterOperand GPROpnd> {
467   dag OutOperandList = (outs GPROpnd:$rd);
468   dag InOperandList = (ins GPROpnd:$rs, GPROpnd:$rt);
469   string AsmString = !strconcat(instr_asm, "\t$rd, $rs, $rt");
470   list<dag> Pattern = [];
471 }
472
473 class SELEQZ_DESC : SELEQNE_Z_DESC_BASE<"seleqz", GPR32Opnd>;
474 class SELNEZ_DESC : SELEQNE_Z_DESC_BASE<"selnez", GPR32Opnd>;
475
476 class COP1_4R_DESC_BASE<string instr_asm, RegisterOperand FGROpnd> {
477   dag OutOperandList = (outs FGROpnd:$fd);
478   dag InOperandList = (ins FGROpnd:$fd_in, FGROpnd:$fs, FGROpnd:$ft);
479   string AsmString = !strconcat(instr_asm, "\t$fd, $fs, $ft");
480   list<dag> Pattern = [];
481   string Constraints = "$fd_in = $fd";
482 }
483
484 class MADDF_S_DESC  : COP1_4R_DESC_BASE<"maddf.s", FGR32Opnd>;
485 class MADDF_D_DESC  : COP1_4R_DESC_BASE<"maddf.d", FGR64Opnd>;
486 class MSUBF_S_DESC  : COP1_4R_DESC_BASE<"msubf.s", FGR32Opnd>;
487 class MSUBF_D_DESC  : COP1_4R_DESC_BASE<"msubf.d", FGR64Opnd>;
488
489 class MAX_MIN_DESC_BASE<string instr_asm, RegisterOperand FGROpnd> {
490   dag OutOperandList = (outs FGROpnd:$fd);
491   dag InOperandList = (ins FGROpnd:$fs, FGROpnd:$ft);
492   string AsmString = !strconcat(instr_asm, "\t$fd, $fs, $ft");
493   list<dag> Pattern = [];
494 }
495
496 class MAX_S_DESC : MAX_MIN_DESC_BASE<"max.s", FGR32Opnd>;
497 class MAX_D_DESC : MAX_MIN_DESC_BASE<"max.d", FGR64Opnd>;
498 class MIN_S_DESC : MAX_MIN_DESC_BASE<"min.s", FGR32Opnd>;
499 class MIN_D_DESC : MAX_MIN_DESC_BASE<"min.d", FGR64Opnd>;
500
501 class MAXA_S_DESC : MAX_MIN_DESC_BASE<"maxa.s", FGR32Opnd>;
502 class MAXA_D_DESC : MAX_MIN_DESC_BASE<"maxa.d", FGR64Opnd>;
503 class MINA_S_DESC : MAX_MIN_DESC_BASE<"mina.s", FGR32Opnd>;
504 class MINA_D_DESC : MAX_MIN_DESC_BASE<"mina.d", FGR64Opnd>;
505
506 class SELEQNEZ_DESC_BASE<string instr_asm, RegisterOperand FGROpnd> {
507   dag OutOperandList = (outs FGROpnd:$fd);
508   dag InOperandList = (ins FGROpnd:$fs, FGROpnd:$ft);
509   string AsmString = !strconcat(instr_asm, "\t$fd, $fs, $ft");
510   list<dag> Pattern = [];
511 }
512
513 class SELEQZ_S_DESC : SELEQNEZ_DESC_BASE<"seleqz.s", FGR32Opnd>;
514 class SELEQZ_D_DESC : SELEQNEZ_DESC_BASE<"seleqz.d", FGR64Opnd>;
515 class SELNEZ_S_DESC : SELEQNEZ_DESC_BASE<"selnez.s", FGR32Opnd>;
516 class SELNEZ_D_DESC : SELEQNEZ_DESC_BASE<"selnez.d", FGR64Opnd>;
517
518 class CLASS_RINT_DESC_BASE<string instr_asm, RegisterOperand FGROpnd> {
519   dag OutOperandList = (outs FGROpnd:$fd);
520   dag InOperandList = (ins FGROpnd:$fs);
521   string AsmString = !strconcat(instr_asm, "\t$fd, $fs");
522   list<dag> Pattern = [];
523 }
524
525 class RINT_S_DESC : CLASS_RINT_DESC_BASE<"rint.s", FGR32Opnd>;
526 class RINT_D_DESC : CLASS_RINT_DESC_BASE<"rint.d", FGR64Opnd>;
527 class CLASS_S_DESC : CLASS_RINT_DESC_BASE<"class.s", FGR32Opnd>;
528 class CLASS_D_DESC : CLASS_RINT_DESC_BASE<"class.d", FGR64Opnd>;
529
530 //===----------------------------------------------------------------------===//
531 //
532 // Instruction Definitions
533 //
534 //===----------------------------------------------------------------------===//
535
536 def ADDIUPC : ADDIUPC_ENC, ADDIUPC_DESC, ISA_MIPS32R6;
537 def ALIGN : ALIGN_ENC, ALIGN_DESC, ISA_MIPS32R6;
538 def ALUIPC : ALUIPC_ENC, ALUIPC_DESC, ISA_MIPS32R6;
539 def AUI : AUI_ENC, AUI_DESC, ISA_MIPS32R6;
540 def AUIPC : AUIPC_ENC, AUIPC_DESC, ISA_MIPS32R6;
541 def BALC : BALC_ENC, BALC_DESC, ISA_MIPS32R6;
542 def BC1EQZ : BC1EQZ_ENC, BC1EQZ_DESC, ISA_MIPS32R6;
543 def BC1NEZ : BC1NEZ_ENC, BC1NEZ_DESC, ISA_MIPS32R6;
544 def BC2EQZ : BC2EQZ_ENC, BC2EQZ_DESC, ISA_MIPS32R6;
545 def BC2NEZ : BC2NEZ_ENC, BC2NEZ_DESC, ISA_MIPS32R6;
546 def BC : BC_ENC, BC_DESC, ISA_MIPS32R6;
547 def BEQC : BEQC_ENC, BEQC_DESC, ISA_MIPS32R6;
548 def BEQZALC : BEQZALC_ENC, BEQZALC_DESC, ISA_MIPS32R6;
549 def BEQZC : BEQZC_ENC, BEQZC_DESC, ISA_MIPS32R6;
550 def BGEC : BGEC_ENC, BGEC_DESC, ISA_MIPS32R6;
551 def BGEUC : BGEUC_ENC, BGEUC_DESC, ISA_MIPS32R6;
552 def BGEZALC : BGEZALC_ENC, BGEZALC_DESC, ISA_MIPS32R6;
553 def BGEZC : BGEZC_ENC, BGEZC_DESC, ISA_MIPS32R6;
554 def BGTZALC : BGTZALC_ENC, BGTZALC_DESC, ISA_MIPS32R6;
555 def BGTZC : BGTZC_ENC, BGTZC_DESC, ISA_MIPS32R6;
556 def BITSWAP : BITSWAP_ENC, BITSWAP_DESC, ISA_MIPS32R6;
557 def BLEZALC : BLEZALC_ENC, BLEZALC_DESC, ISA_MIPS32R6;
558 def BLEZC : BLEZC_ENC, BLEZC_DESC, ISA_MIPS32R6;
559 def BLTC; // Also aliased to bgtc with operands swapped
560 def BLTUC; // Also aliased to bgtuc with operands swapped
561 def BLTZALC : BLTZALC_ENC, BLTZALC_DESC, ISA_MIPS32R6;
562 def BLTZC : BLTZC_ENC, BLTZC_DESC, ISA_MIPS32R6;
563 def BNEC : BNEC_ENC, BNEC_DESC, ISA_MIPS32R6;
564 def BNEZALC : BNEZALC_ENC, BNEZALC_DESC, ISA_MIPS32R6;
565 def BNEZC : BNEZC_ENC, BNEZC_DESC, ISA_MIPS32R6;
566 def BNVC : BNVC_ENC, BNVC_DESC, ISA_MIPS32R6;
567 def BOVC : BOVC_ENC, BOVC_DESC, ISA_MIPS32R6;
568 def CLASS_D : CLASS_D_ENC, CLASS_D_DESC, ISA_MIPS32R6;
569 def CLASS_S : CLASS_S_ENC, CLASS_S_DESC, ISA_MIPS32R6;
570 defm S : CMP_CC_M<FIELD_CMP_FORMAT_S, "s", FGR32Opnd>;
571 defm D : CMP_CC_M<FIELD_CMP_FORMAT_D, "d", FGR64Opnd>;
572 def DIV : DIV_ENC, DIV_DESC, ISA_MIPS32R6;
573 def DIVU : DIVU_ENC, DIVU_DESC, ISA_MIPS32R6;
574 def JIALC : JIALC_ENC, JIALC_DESC, ISA_MIPS32R6;
575 def JIC : JIC_ENC, JIC_DESC, ISA_MIPS32R6;
576 def JR_HB_R6 : JR_HB_R6_ENC, JR_HB_R6_DESC, ISA_MIPS32R6;
577 // def LSA; // See MSA
578 def LWPC : LWPC_ENC, LWPC_DESC, ISA_MIPS32R6;
579 def LWUPC : LWUPC_ENC, LWUPC_DESC, ISA_MIPS32R6;
580 def MADDF_S : MADDF_S_ENC, MADDF_S_DESC, ISA_MIPS32R6;
581 def MADDF_D : MADDF_D_ENC, MADDF_D_DESC, ISA_MIPS32R6;
582 def MAXA_D : MAXA_D_ENC, MAXA_D_DESC, ISA_MIPS32R6;
583 def MAXA_S : MAXA_S_ENC, MAXA_S_DESC, ISA_MIPS32R6;
584 def MAX_D : MAX_D_ENC, MAX_D_DESC, ISA_MIPS32R6;
585 def MAX_S : MAX_S_ENC, MAX_S_DESC, ISA_MIPS32R6;
586 def MINA_D : MINA_D_ENC, MINA_D_DESC, ISA_MIPS32R6;
587 def MINA_S : MINA_S_ENC, MINA_S_DESC, ISA_MIPS32R6;
588 def MIN_D : MIN_D_ENC, MIN_D_DESC, ISA_MIPS32R6;
589 def MIN_S : MIN_S_ENC, MIN_S_DESC, ISA_MIPS32R6;
590 def MOD : MOD_ENC, MOD_DESC, ISA_MIPS32R6;
591 def MODU : MODU_ENC, MODU_DESC, ISA_MIPS32R6;
592 def MSUBF_S : MSUBF_S_ENC, MSUBF_S_DESC, ISA_MIPS32R6;
593 def MSUBF_D : MSUBF_D_ENC, MSUBF_D_DESC, ISA_MIPS32R6;
594 def MUH    : MUH_ENC, MUH_DESC, ISA_MIPS32R6;
595 def MUHU   : MUHU_ENC, MUHU_DESC, ISA_MIPS32R6;
596 def MUL_R6 : MUL_R6_ENC, MUL_R6_DESC, ISA_MIPS32R6;
597 def MULU   : MULU_ENC, MULU_DESC, ISA_MIPS32R6;
598 def NAL; // BAL with rd=0
599 def RINT_D : RINT_D_ENC, RINT_D_DESC, ISA_MIPS32R6;
600 def RINT_S : RINT_S_ENC, RINT_S_DESC, ISA_MIPS32R6;
601 def SELEQZ : SELEQZ_ENC, SELEQZ_DESC, ISA_MIPS32R6, GPR_32;
602 def SELEQZ_D : SELEQZ_D_ENC, SELEQZ_D_DESC, ISA_MIPS32R6;
603 def SELEQZ_S : SELEQZ_S_ENC, SELEQZ_S_DESC, ISA_MIPS32R6;
604 def SELNEZ : SELNEZ_ENC, SELNEZ_DESC, ISA_MIPS32R6, GPR_32;
605 def SELNEZ_D : SELNEZ_D_ENC, SELNEZ_D_DESC, ISA_MIPS32R6;
606 def SELNEZ_S : SELNEZ_S_ENC, SELNEZ_S_DESC, ISA_MIPS32R6;
607 def SEL_D : SEL_D_ENC, SEL_D_DESC, ISA_MIPS32R6;
608 def SEL_S : SEL_S_ENC, SEL_S_DESC, ISA_MIPS32R6;
609
610 //===----------------------------------------------------------------------===//
611 //
612 // Patterns and Pseudo Instructions
613 //
614 //===----------------------------------------------------------------------===//
615
616 // f32 comparisons supported via another comparison
617 def : MipsPat<(setone f32:$lhs, f32:$rhs),
618               (NOR (CMP_UEQ_S f32:$lhs, f32:$rhs), ZERO)>, ISA_MIPS32R6;
619 def : MipsPat<(seto f32:$lhs, f32:$rhs),
620               (NOR (CMP_UN_S f32:$lhs, f32:$rhs), ZERO)>, ISA_MIPS32R6;
621 def : MipsPat<(setune f32:$lhs, f32:$rhs),
622               (NOR (CMP_EQ_S f32:$lhs, f32:$rhs), ZERO)>, ISA_MIPS32R6;
623 def : MipsPat<(seteq f32:$lhs, f32:$rhs), (CMP_EQ_S f32:$lhs, f32:$rhs)>,
624       ISA_MIPS32R6;
625 def : MipsPat<(setgt f32:$lhs, f32:$rhs), (CMP_LE_S f32:$rhs, f32:$lhs)>,
626       ISA_MIPS32R6;
627 def : MipsPat<(setge f32:$lhs, f32:$rhs), (CMP_LT_S f32:$rhs, f32:$lhs)>,
628       ISA_MIPS32R6;
629 def : MipsPat<(setlt f32:$lhs, f32:$rhs), (CMP_OLT_S f32:$lhs, f32:$rhs)>,
630       ISA_MIPS32R6;
631 def : MipsPat<(setlt f32:$lhs, f32:$rhs), (CMP_OLE_S f32:$lhs, f32:$rhs)>,
632       ISA_MIPS32R6;
633 def : MipsPat<(setne f32:$lhs, f32:$rhs),
634               (NOR (CMP_EQ_S f32:$lhs, f32:$rhs), ZERO)>, ISA_MIPS32R6;
635
636 // f64 comparisons supported via another comparison
637 def : MipsPat<(setone f64:$lhs, f64:$rhs),
638               (NOR (CMP_UEQ_D f64:$lhs, f64:$rhs), ZERO)>, ISA_MIPS32R6;
639 def : MipsPat<(seto f64:$lhs, f64:$rhs),
640               (NOR (CMP_UN_D f64:$lhs, f64:$rhs), ZERO)>, ISA_MIPS32R6;
641 def : MipsPat<(setune f64:$lhs, f64:$rhs),
642               (NOR (CMP_EQ_D f64:$lhs, f64:$rhs), ZERO)>, ISA_MIPS32R6;
643 def : MipsPat<(seteq f64:$lhs, f64:$rhs), (CMP_EQ_D f64:$lhs, f64:$rhs)>,
644       ISA_MIPS32R6;
645 def : MipsPat<(setgt f64:$lhs, f64:$rhs), (CMP_LE_D f64:$rhs, f64:$lhs)>,
646       ISA_MIPS32R6;
647 def : MipsPat<(setge f64:$lhs, f64:$rhs), (CMP_LT_D f64:$rhs, f64:$lhs)>,
648       ISA_MIPS32R6;
649 def : MipsPat<(setlt f64:$lhs, f64:$rhs), (CMP_OLT_D f64:$lhs, f64:$rhs)>,
650       ISA_MIPS32R6;
651 def : MipsPat<(setlt f64:$lhs, f64:$rhs), (CMP_OLE_D f64:$lhs, f64:$rhs)>,
652       ISA_MIPS32R6;
653 def : MipsPat<(setne f64:$lhs, f64:$rhs),
654               (NOR (CMP_EQ_D f64:$lhs, f64:$rhs), ZERO)>, ISA_MIPS32R6;
655
656 // i32 selects
657 def : MipsPat<(select i32:$cond, i32:$t, i32:$f),
658               (OR (SELNEZ i32:$t, i32:$cond), (SELEQZ i32:$f, i32:$cond))>,
659               ISA_MIPS32R6;
660 def : MipsPat<(select (i32 (seteq i32:$cond, immz)), i32:$t, i32:$f),
661               (OR (SELNEZ i32:$t, i32:$cond), (SELEQZ i32:$f, i32:$cond))>,
662               ISA_MIPS32R6;
663 def : MipsPat<(select (i32 (setne i32:$cond, immz)), i32:$t, i32:$f),
664               (OR (SELNEZ i32:$f, i32:$cond), (SELEQZ i32:$t, i32:$cond))>,
665               ISA_MIPS32R6;
666 def : MipsPat<(select (i32 (seteq i32:$cond, immZExt16:$imm)), i32:$t, i32:$f),
667               (OR (SELNEZ i32:$t, (XORi i32:$cond, immZExt16:$imm)),
668                   (SELEQZ i32:$f, (XORi i32:$cond, immZExt16:$imm)))>,
669               ISA_MIPS32R6;
670 def : MipsPat<(select (i32 (setne i32:$cond, immZExt16:$imm)), i32:$t, i32:$f),
671               (OR (SELNEZ i32:$f, (XORi i32:$cond, immZExt16:$imm)),
672                   (SELEQZ i32:$t, (XORi i32:$cond, immZExt16:$imm)))>,
673               ISA_MIPS32R6;
674 def : MipsPat<(select (i32 (setgt i32:$cond, immSExt16Plus1:$imm)), i32:$t,
675                       i32:$f),
676               (OR (SELNEZ i32:$t, (SLTi i32:$cond, (Plus1 imm:$imm))),
677                   (SELEQZ i32:$f, (SLTi i32:$cond, (Plus1 imm:$imm))))>,
678               ISA_MIPS32R6;
679 def : MipsPat<(select (i32 (setugt i32:$cond, immSExt16Plus1:$imm)),
680                       i32:$t, i32:$f),
681               (OR (SELNEZ i32:$t, (SLTiu i32:$cond, (Plus1 imm:$imm))),
682                   (SELEQZ i32:$f, (SLTiu i32:$cond, (Plus1 imm:$imm))))>,
683               ISA_MIPS32R6;
684
685 def : MipsPat<(select i32:$cond, i32:$t, immz),
686               (SELNEZ i32:$t, i32:$cond)>, ISA_MIPS32R6;
687 def : MipsPat<(select (i32 (setne i32:$cond, immz)), i32:$t, immz),
688               (SELNEZ i32:$t, i32:$cond)>, ISA_MIPS32R6;
689 def : MipsPat<(select (i32 (seteq i32:$cond, immz)), i32:$t, immz),
690               (SELEQZ i32:$t, i32:$cond)>, ISA_MIPS32R6;
691 def : MipsPat<(select i32:$cond, immz, i32:$f),
692               (SELEQZ i32:$f, i32:$cond)>, ISA_MIPS32R6;
693 def : MipsPat<(select (i32 (setne i32:$cond, immz)), immz, i32:$f),
694               (SELEQZ i32:$f, i32:$cond)>, ISA_MIPS32R6;
695 def : MipsPat<(select (i32 (seteq i32:$cond, immz)), immz, i32:$f),
696               (SELNEZ i32:$f, i32:$cond)>, ISA_MIPS32R6;