1 //===- MipsInstrInfo.td - Target Description for Mips Target -*- tablegen -*-=//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the Mips implementation of the TargetInstrInfo class.
12 //===----------------------------------------------------------------------===//
15 //===----------------------------------------------------------------------===//
16 // Mips profiles and nodes
17 //===----------------------------------------------------------------------===//
19 def SDT_MipsJmpLink : SDTypeProfile<0, 1, [SDTCisVT<0, iPTR>]>;
20 def SDT_MipsCMov : SDTypeProfile<1, 4, [SDTCisSameAs<0, 1>,
24 def SDT_MipsCallSeqStart : SDCallSeqStart<[SDTCisVT<0, i32>]>;
25 def SDT_MipsCallSeqEnd : SDCallSeqEnd<[SDTCisVT<0, i32>, SDTCisVT<1, i32>]>;
26 def SDT_MipsMAddMSub : SDTypeProfile<0, 4,
27 [SDTCisVT<0, i32>, SDTCisSameAs<0, 1>,
30 def SDT_MipsDivRem : SDTypeProfile<0, 2,
34 def SDT_MipsThreadPointer : SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>;
36 def SDT_MipsDynAlloc : SDTypeProfile<1, 1, [SDTCisVT<0, iPTR>,
38 def SDT_Sync : SDTypeProfile<0, 1, [SDTCisVT<0, i32>]>;
40 def SDT_Ext : SDTypeProfile<1, 3, [SDTCisInt<0>, SDTCisSameAs<0, 1>,
41 SDTCisVT<2, i32>, SDTCisSameAs<2, 3>]>;
42 def SDT_Ins : SDTypeProfile<1, 4, [SDTCisInt<0>, SDTCisSameAs<0, 1>,
43 SDTCisVT<2, i32>, SDTCisSameAs<2, 3>,
46 def SDTMipsLoadLR : SDTypeProfile<1, 2,
47 [SDTCisInt<0>, SDTCisPtrTy<1>,
51 def MipsJmpLink : SDNode<"MipsISD::JmpLink",SDT_MipsJmpLink,
52 [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue,
55 // Hi and Lo nodes are used to handle global addresses. Used on
56 // MipsISelLowering to lower stuff like GlobalAddress, ExternalSymbol
57 // static model. (nothing to do with Mips Registers Hi and Lo)
58 def MipsHi : SDNode<"MipsISD::Hi", SDTIntUnaryOp>;
59 def MipsLo : SDNode<"MipsISD::Lo", SDTIntUnaryOp>;
60 def MipsGPRel : SDNode<"MipsISD::GPRel", SDTIntUnaryOp>;
62 // TlsGd node is used to handle General Dynamic TLS
63 def MipsTlsGd : SDNode<"MipsISD::TlsGd", SDTIntUnaryOp>;
65 // TprelHi and TprelLo nodes are used to handle Local Exec TLS
66 def MipsTprelHi : SDNode<"MipsISD::TprelHi", SDTIntUnaryOp>;
67 def MipsTprelLo : SDNode<"MipsISD::TprelLo", SDTIntUnaryOp>;
70 def MipsThreadPointer: SDNode<"MipsISD::ThreadPointer", SDT_MipsThreadPointer>;
73 def MipsRet : SDNode<"MipsISD::Ret", SDTNone, [SDNPHasChain, SDNPOptInGlue]>;
75 // These are target-independent nodes, but have target-specific formats.
76 def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_MipsCallSeqStart,
77 [SDNPHasChain, SDNPSideEffect, SDNPOutGlue]>;
78 def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_MipsCallSeqEnd,
79 [SDNPHasChain, SDNPSideEffect,
80 SDNPOptInGlue, SDNPOutGlue]>;
83 def MipsMAdd : SDNode<"MipsISD::MAdd", SDT_MipsMAddMSub,
84 [SDNPOptInGlue, SDNPOutGlue]>;
85 def MipsMAddu : SDNode<"MipsISD::MAddu", SDT_MipsMAddMSub,
86 [SDNPOptInGlue, SDNPOutGlue]>;
87 def MipsMSub : SDNode<"MipsISD::MSub", SDT_MipsMAddMSub,
88 [SDNPOptInGlue, SDNPOutGlue]>;
89 def MipsMSubu : SDNode<"MipsISD::MSubu", SDT_MipsMAddMSub,
90 [SDNPOptInGlue, SDNPOutGlue]>;
93 def MipsDivRem : SDNode<"MipsISD::DivRem", SDT_MipsDivRem,
95 def MipsDivRemU : SDNode<"MipsISD::DivRemU", SDT_MipsDivRem,
98 // Target constant nodes that are not part of any isel patterns and remain
99 // unchanged can cause instructions with illegal operands to be emitted.
100 // Wrapper node patterns give the instruction selector a chance to replace
101 // target constant nodes that would otherwise remain unchanged with ADDiu
102 // nodes. Without these wrapper node patterns, the following conditional move
103 // instrucion is emitted when function cmov2 in test/CodeGen/Mips/cmov.ll is
105 // movn %got(d)($gp), %got(c)($gp), $4
106 // This instruction is illegal since movn can take only register operands.
108 def MipsWrapper : SDNode<"MipsISD::Wrapper", SDTIntBinOp>;
110 // Pointer to dynamically allocated stack area.
111 def MipsDynAlloc : SDNode<"MipsISD::DynAlloc", SDT_MipsDynAlloc,
112 [SDNPHasChain, SDNPInGlue]>;
114 def MipsSync : SDNode<"MipsISD::Sync", SDT_Sync, [SDNPHasChain,SDNPSideEffect]>;
116 def MipsExt : SDNode<"MipsISD::Ext", SDT_Ext>;
117 def MipsIns : SDNode<"MipsISD::Ins", SDT_Ins>;
119 def MipsLWL : SDNode<"MipsISD::LWL", SDTMipsLoadLR,
120 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
121 def MipsLWR : SDNode<"MipsISD::LWR", SDTMipsLoadLR,
122 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
123 def MipsSWL : SDNode<"MipsISD::SWL", SDTStore,
124 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
125 def MipsSWR : SDNode<"MipsISD::SWR", SDTStore,
126 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
127 def MipsLDL : SDNode<"MipsISD::LDL", SDTMipsLoadLR,
128 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
129 def MipsLDR : SDNode<"MipsISD::LDR", SDTMipsLoadLR,
130 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
131 def MipsSDL : SDNode<"MipsISD::SDL", SDTStore,
132 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
133 def MipsSDR : SDNode<"MipsISD::SDR", SDTStore,
134 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
136 //===----------------------------------------------------------------------===//
137 // Mips Instruction Predicate Definitions.
138 //===----------------------------------------------------------------------===//
139 def HasSEInReg : Predicate<"Subtarget.hasSEInReg()">,
140 AssemblerPredicate<"FeatureSEInReg">;
141 def HasBitCount : Predicate<"Subtarget.hasBitCount()">,
142 AssemblerPredicate<"FeatureBitCount">;
143 def HasSwap : Predicate<"Subtarget.hasSwap()">,
144 AssemblerPredicate<"FeatureSwap">;
145 def HasCondMov : Predicate<"Subtarget.hasCondMov()">,
146 AssemblerPredicate<"FeatureCondMov">;
147 def HasMips32 : Predicate<"Subtarget.hasMips32()">,
148 AssemblerPredicate<"FeatureMips32">;
149 def HasMips32r2 : Predicate<"Subtarget.hasMips32r2()">,
150 AssemblerPredicate<"FeatureMips32r2">;
151 def HasMips64 : Predicate<"Subtarget.hasMips64()">,
152 AssemblerPredicate<"FeatureMips64">;
153 def HasMips32r2Or64 : Predicate<"Subtarget.hasMips32r2Or64()">,
154 AssemblerPredicate<"FeatureMips32r2,FeatureMips64">;
155 def NotMips64 : Predicate<"!Subtarget.hasMips64()">,
156 AssemblerPredicate<"!FeatureMips64">;
157 def HasMips64r2 : Predicate<"Subtarget.hasMips64r2()">,
158 AssemblerPredicate<"FeatureMips64r2">;
159 def IsN64 : Predicate<"Subtarget.isABI_N64()">,
160 AssemblerPredicate<"FeatureN64">;
161 def NotN64 : Predicate<"!Subtarget.isABI_N64()">,
162 AssemblerPredicate<"!FeatureN64">;
163 def InMips16Mode : Predicate<"Subtarget.inMips16Mode()">,
164 AssemblerPredicate<"FeatureMips16">;
165 def RelocStatic : Predicate<"TM.getRelocationModel() == Reloc::Static">,
166 AssemblerPredicate<"FeatureMips32">;
167 def RelocPIC : Predicate<"TM.getRelocationModel() == Reloc::PIC_">,
168 AssemblerPredicate<"FeatureMips32">;
169 def NoNaNsFPMath : Predicate<"TM.Options.NoNaNsFPMath">,
170 AssemblerPredicate<"FeatureMips32">;
171 def HasStandardEncoding : Predicate<"Subtarget.hasStandardEncoding()">,
172 AssemblerPredicate<"!FeatureMips16">;
174 class MipsPat<dag pattern, dag result> : Pat<pattern, result> {
175 let Predicates = [HasStandardEncoding];
178 //===----------------------------------------------------------------------===//
179 // Instruction format superclass
180 //===----------------------------------------------------------------------===//
182 include "MipsInstrFormats.td"
184 //===----------------------------------------------------------------------===//
185 // Mips Operand, Complex Patterns and Transformations Definitions.
186 //===----------------------------------------------------------------------===//
188 // Instruction operand types
189 def jmptarget : Operand<OtherVT> {
190 let EncoderMethod = "getJumpTargetOpValue";
192 def brtarget : Operand<OtherVT> {
193 let EncoderMethod = "getBranchTargetOpValue";
194 let OperandType = "OPERAND_PCREL";
195 let DecoderMethod = "DecodeBranchTarget";
197 def calltarget : Operand<iPTR> {
198 let EncoderMethod = "getJumpTargetOpValue";
200 def calltarget64: Operand<i64>;
201 def simm16 : Operand<i32> {
202 let DecoderMethod= "DecodeSimm16";
204 def simm16_64 : Operand<i64>;
205 def shamt : Operand<i32>;
208 def uimm16 : Operand<i32> {
209 let PrintMethod = "printUnsignedImm";
212 def MipsMemAsmOperand : AsmOperandClass {
214 let ParserMethod = "parseMemOperand";
218 def mem : Operand<i32> {
219 let PrintMethod = "printMemOperand";
220 let MIOperandInfo = (ops CPURegs, simm16);
221 let EncoderMethod = "getMemEncoding";
222 let ParserMatchClass = MipsMemAsmOperand;
225 def mem64 : Operand<i64> {
226 let PrintMethod = "printMemOperand";
227 let MIOperandInfo = (ops CPU64Regs, simm16_64);
228 let EncoderMethod = "getMemEncoding";
229 let ParserMatchClass = MipsMemAsmOperand;
232 def mem_ea : Operand<i32> {
233 let PrintMethod = "printMemOperandEA";
234 let MIOperandInfo = (ops CPURegs, simm16);
235 let EncoderMethod = "getMemEncoding";
238 def mem_ea_64 : Operand<i64> {
239 let PrintMethod = "printMemOperandEA";
240 let MIOperandInfo = (ops CPU64Regs, simm16_64);
241 let EncoderMethod = "getMemEncoding";
244 // size operand of ext instruction
245 def size_ext : Operand<i32> {
246 let EncoderMethod = "getSizeExtEncoding";
247 let DecoderMethod = "DecodeExtSize";
250 // size operand of ins instruction
251 def size_ins : Operand<i32> {
252 let EncoderMethod = "getSizeInsEncoding";
253 let DecoderMethod = "DecodeInsSize";
256 // Transformation Function - get the lower 16 bits.
257 def LO16 : SDNodeXForm<imm, [{
258 return getImm(N, N->getZExtValue() & 0xFFFF);
261 // Transformation Function - get the higher 16 bits.
262 def HI16 : SDNodeXForm<imm, [{
263 return getImm(N, (N->getZExtValue() >> 16) & 0xFFFF);
266 // Node immediate fits as 16-bit sign extended on target immediate.
268 def immSExt16 : PatLeaf<(imm), [{ return isInt<16>(N->getSExtValue()); }]>;
270 // Node immediate fits as 16-bit zero extended on target immediate.
271 // The LO16 param means that only the lower 16 bits of the node
272 // immediate are caught.
274 def immZExt16 : PatLeaf<(imm), [{
275 if (N->getValueType(0) == MVT::i32)
276 return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
278 return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
281 // Immediate can be loaded with LUi (32-bit int with lower 16-bit cleared).
282 def immLow16Zero : PatLeaf<(imm), [{
283 int64_t Val = N->getSExtValue();
284 return isInt<32>(Val) && !(Val & 0xffff);
287 // shamt field must fit in 5 bits.
288 def immZExt5 : ImmLeaf<i32, [{return Imm == (Imm & 0x1f);}]>;
290 // Mips Address Mode! SDNode frameindex could possibily be a match
291 // since load and store instructions from stack used it.
293 ComplexPattern<iPTR, 2, "SelectAddr", [frameindex], [SDNPWantParent]>;
295 //===----------------------------------------------------------------------===//
296 // Instructions specific format
297 //===----------------------------------------------------------------------===//
299 // Arithmetic and logical instructions with 3 register operands.
300 class ArithLogicR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
301 InstrItinClass itin, RegisterClass RC, bit isComm = 0>:
302 FR<op, func, (outs RC:$rd), (ins RC:$rs, RC:$rt),
303 !strconcat(instr_asm, "\t$rd, $rs, $rt"),
304 [(set RC:$rd, (OpNode RC:$rs, RC:$rt))], itin> {
306 let isCommutable = isComm;
307 let isReMaterializable = 1;
310 class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm,
311 InstrItinClass itin, RegisterClass RC, bit isComm = 0>:
312 FR<op, func, (outs RC:$rd), (ins RC:$rs, RC:$rt),
313 !strconcat(instr_asm, "\t$rd, $rs, $rt"), [], itin> {
315 let isCommutable = isComm;
318 // Arithmetic and logical instructions with 2 register operands.
319 class ArithLogicI<bits<6> op, string instr_asm, SDNode OpNode,
320 Operand Od, PatLeaf imm_type, RegisterClass RC> :
321 FI<op, (outs RC:$rt), (ins RC:$rs, Od:$imm16),
322 !strconcat(instr_asm, "\t$rt, $rs, $imm16"),
323 [(set RC:$rt, (OpNode RC:$rs, imm_type:$imm16))], IIAlu> {
324 let isReMaterializable = 1;
327 class ArithOverflowI<bits<6> op, string instr_asm, SDNode OpNode,
328 Operand Od, PatLeaf imm_type, RegisterClass RC> :
329 FI<op, (outs RC:$rt), (ins RC:$rs, Od:$imm16),
330 !strconcat(instr_asm, "\t$rt, $rs, $imm16"), [], IIAlu>;
332 // Arithmetic Multiply ADD/SUB
333 let rd = 0, shamt = 0, Defs = [HI, LO], Uses = [HI, LO] in
334 class MArithR<bits<6> func, string instr_asm, SDNode op, bit isComm = 0> :
335 FR<0x1c, func, (outs), (ins CPURegs:$rs, CPURegs:$rt),
336 !strconcat(instr_asm, "\t$rs, $rt"),
337 [(op CPURegs:$rs, CPURegs:$rt, LO, HI)], IIImul> {
340 let isCommutable = isComm;
344 class LogicNOR<bits<6> op, bits<6> func, string instr_asm, RegisterClass RC>:
345 FR<op, func, (outs RC:$rd), (ins RC:$rs, RC:$rt),
346 !strconcat(instr_asm, "\t$rd, $rs, $rt"),
347 [(set RC:$rd, (not (or RC:$rs, RC:$rt)))], IIAlu> {
349 let isCommutable = 1;
353 class shift_rotate_imm<bits<6> func, bits<5> isRotate, string instr_asm,
354 SDNode OpNode, PatFrag PF, Operand ImmOpnd,
356 FR<0x00, func, (outs RC:$rd), (ins RC:$rt, ImmOpnd:$shamt),
357 !strconcat(instr_asm, "\t$rd, $rt, $shamt"),
358 [(set RC:$rd, (OpNode RC:$rt, PF:$shamt))], IIAlu> {
362 // 32-bit shift instructions.
363 class shift_rotate_imm32<bits<6> func, bits<5> isRotate, string instr_asm,
365 shift_rotate_imm<func, isRotate, instr_asm, OpNode, immZExt5, shamt, CPURegs>;
367 class shift_rotate_reg<bits<6> func, bits<5> isRotate, string instr_asm,
368 SDNode OpNode, RegisterClass RC>:
369 FR<0x00, func, (outs RC:$rd), (ins CPURegs:$rs, RC:$rt),
370 !strconcat(instr_asm, "\t$rd, $rt, $rs"),
371 [(set RC:$rd, (OpNode RC:$rt, CPURegs:$rs))], IIAlu> {
372 let shamt = isRotate;
375 // Load Upper Imediate
376 class LoadUpper<bits<6> op, string instr_asm, RegisterClass RC, Operand Imm>:
377 FI<op, (outs RC:$rt), (ins Imm:$imm16),
378 !strconcat(instr_asm, "\t$rt, $imm16"), [], IIAlu> {
380 let neverHasSideEffects = 1;
381 let isReMaterializable = 1;
384 class FMem<bits<6> op, dag outs, dag ins, string asmstr, list<dag> pattern,
385 InstrItinClass itin>: FFI<op, outs, ins, asmstr, pattern> {
387 let Inst{25-21} = addr{20-16};
388 let Inst{15-0} = addr{15-0};
389 let DecoderMethod = "DecodeMem";
393 let canFoldAsLoad = 1 in
394 class LoadM<bits<6> op, string instr_asm, PatFrag OpNode, RegisterClass RC,
395 Operand MemOpnd, bit Pseudo>:
396 FMem<op, (outs RC:$rt), (ins MemOpnd:$addr),
397 !strconcat(instr_asm, "\t$rt, $addr"),
398 [(set RC:$rt, (OpNode addr:$addr))], IILoad> {
399 let isPseudo = Pseudo;
402 class StoreM<bits<6> op, string instr_asm, PatFrag OpNode, RegisterClass RC,
403 Operand MemOpnd, bit Pseudo>:
404 FMem<op, (outs), (ins RC:$rt, MemOpnd:$addr),
405 !strconcat(instr_asm, "\t$rt, $addr"),
406 [(OpNode RC:$rt, addr:$addr)], IIStore> {
407 let isPseudo = Pseudo;
411 multiclass LoadM32<bits<6> op, string instr_asm, PatFrag OpNode,
413 def #NAME# : LoadM<op, instr_asm, OpNode, CPURegs, mem, Pseudo>,
414 Requires<[NotN64, HasStandardEncoding]>;
415 def _P8 : LoadM<op, instr_asm, OpNode, CPURegs, mem64, Pseudo>,
416 Requires<[IsN64, HasStandardEncoding]> {
417 let DecoderNamespace = "Mips64";
418 let isCodeGenOnly = 1;
423 multiclass LoadM64<bits<6> op, string instr_asm, PatFrag OpNode,
425 def #NAME# : LoadM<op, instr_asm, OpNode, CPU64Regs, mem, Pseudo>,
426 Requires<[NotN64, HasStandardEncoding]>;
427 def _P8 : LoadM<op, instr_asm, OpNode, CPU64Regs, mem64, Pseudo>,
428 Requires<[IsN64, HasStandardEncoding]> {
429 let DecoderNamespace = "Mips64";
430 let isCodeGenOnly = 1;
435 multiclass StoreM32<bits<6> op, string instr_asm, PatFrag OpNode,
437 def #NAME# : StoreM<op, instr_asm, OpNode, CPURegs, mem, Pseudo>,
438 Requires<[NotN64, HasStandardEncoding]>;
439 def _P8 : StoreM<op, instr_asm, OpNode, CPURegs, mem64, Pseudo>,
440 Requires<[IsN64, HasStandardEncoding]> {
441 let DecoderNamespace = "Mips64";
442 let isCodeGenOnly = 1;
447 multiclass StoreM64<bits<6> op, string instr_asm, PatFrag OpNode,
449 def #NAME# : StoreM<op, instr_asm, OpNode, CPU64Regs, mem, Pseudo>,
450 Requires<[NotN64, HasStandardEncoding]>;
451 def _P8 : StoreM<op, instr_asm, OpNode, CPU64Regs, mem64, Pseudo>,
452 Requires<[IsN64, HasStandardEncoding]> {
453 let DecoderNamespace = "Mips64";
454 let isCodeGenOnly = 1;
458 // Load/Store Left/Right
459 let canFoldAsLoad = 1 in
460 class LoadLeftRight<bits<6> op, string instr_asm, SDNode OpNode,
461 RegisterClass RC, Operand MemOpnd> :
462 FMem<op, (outs RC:$rt), (ins MemOpnd:$addr, RC:$src),
463 !strconcat(instr_asm, "\t$rt, $addr"),
464 [(set RC:$rt, (OpNode addr:$addr, RC:$src))], IILoad> {
465 string Constraints = "$src = $rt";
468 class StoreLeftRight<bits<6> op, string instr_asm, SDNode OpNode,
469 RegisterClass RC, Operand MemOpnd>:
470 FMem<op, (outs), (ins RC:$rt, MemOpnd:$addr),
471 !strconcat(instr_asm, "\t$rt, $addr"), [(OpNode RC:$rt, addr:$addr)],
474 // 32-bit load left/right.
475 multiclass LoadLeftRightM32<bits<6> op, string instr_asm, SDNode OpNode> {
476 def #NAME# : LoadLeftRight<op, instr_asm, OpNode, CPURegs, mem>,
477 Requires<[NotN64, HasStandardEncoding]>;
478 def _P8 : LoadLeftRight<op, instr_asm, OpNode, CPURegs, mem64>,
479 Requires<[IsN64, HasStandardEncoding]> {
480 let DecoderNamespace = "Mips64";
481 let isCodeGenOnly = 1;
485 // 64-bit load left/right.
486 multiclass LoadLeftRightM64<bits<6> op, string instr_asm, SDNode OpNode> {
487 def #NAME# : LoadLeftRight<op, instr_asm, OpNode, CPU64Regs, mem>,
488 Requires<[NotN64, HasStandardEncoding]>;
489 def _P8 : LoadLeftRight<op, instr_asm, OpNode, CPU64Regs, mem64>,
490 Requires<[IsN64, HasStandardEncoding]> {
491 let DecoderNamespace = "Mips64";
492 let isCodeGenOnly = 1;
496 // 32-bit store left/right.
497 multiclass StoreLeftRightM32<bits<6> op, string instr_asm, SDNode OpNode> {
498 def #NAME# : StoreLeftRight<op, instr_asm, OpNode, CPURegs, mem>,
499 Requires<[NotN64, HasStandardEncoding]>;
500 def _P8 : StoreLeftRight<op, instr_asm, OpNode, CPURegs, mem64>,
501 Requires<[IsN64, HasStandardEncoding]> {
502 let DecoderNamespace = "Mips64";
503 let isCodeGenOnly = 1;
507 // 64-bit store left/right.
508 multiclass StoreLeftRightM64<bits<6> op, string instr_asm, SDNode OpNode> {
509 def #NAME# : StoreLeftRight<op, instr_asm, OpNode, CPU64Regs, mem>,
510 Requires<[NotN64, HasStandardEncoding]>;
511 def _P8 : StoreLeftRight<op, instr_asm, OpNode, CPU64Regs, mem64>,
512 Requires<[IsN64, HasStandardEncoding]> {
513 let DecoderNamespace = "Mips64";
514 let isCodeGenOnly = 1;
518 // Conditional Branch
519 class CBranch<bits<6> op, string instr_asm, PatFrag cond_op, RegisterClass RC>:
520 BranchBase<op, (outs), (ins RC:$rs, RC:$rt, brtarget:$imm16),
521 !strconcat(instr_asm, "\t$rs, $rt, $imm16"),
522 [(brcond (i32 (cond_op RC:$rs, RC:$rt)), bb:$imm16)], IIBranch> {
524 let isTerminator = 1;
525 let hasDelaySlot = 1;
529 class CBranchZero<bits<6> op, bits<5> _rt, string instr_asm, PatFrag cond_op,
531 BranchBase<op, (outs), (ins RC:$rs, brtarget:$imm16),
532 !strconcat(instr_asm, "\t$rs, $imm16"),
533 [(brcond (i32 (cond_op RC:$rs, 0)), bb:$imm16)], IIBranch> {
536 let isTerminator = 1;
537 let hasDelaySlot = 1;
542 class SetCC_R<bits<6> op, bits<6> func, string instr_asm, PatFrag cond_op,
544 FR<op, func, (outs CPURegs:$rd), (ins RC:$rs, RC:$rt),
545 !strconcat(instr_asm, "\t$rd, $rs, $rt"),
546 [(set CPURegs:$rd, (cond_op RC:$rs, RC:$rt))],
551 class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op, Operand Od,
552 PatLeaf imm_type, RegisterClass RC>:
553 FI<op, (outs CPURegs:$rt), (ins RC:$rs, Od:$imm16),
554 !strconcat(instr_asm, "\t$rt, $rs, $imm16"),
555 [(set CPURegs:$rt, (cond_op RC:$rs, imm_type:$imm16))],
559 class JumpFJ<bits<6> op, string instr_asm>:
560 FJ<op, (outs), (ins jmptarget:$target),
561 !strconcat(instr_asm, "\t$target"), [(br bb:$target)], IIBranch> {
565 let hasDelaySlot = 1;
566 let Predicates = [RelocStatic, HasStandardEncoding];
567 let DecoderMethod = "DecodeJumpTarget";
571 // Unconditional branch
572 class UncondBranch<bits<6> op, string instr_asm>:
573 BranchBase<op, (outs), (ins brtarget:$imm16),
574 !strconcat(instr_asm, "\t$imm16"), [(br bb:$imm16)], IIBranch> {
578 let isTerminator = 1;
580 let hasDelaySlot = 1;
581 let Predicates = [RelocPIC, HasStandardEncoding];
585 // Base class for indirect branch and return instruction classes.
586 let isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
587 class JumpFR<RegisterClass RC, list<dag> pattern>:
588 FR<0, 0x8, (outs), (ins RC:$rs), "jr\t$rs", pattern, IIBranch> {
595 class IndirectBranch<RegisterClass RC>: JumpFR<RC, [(brind RC:$rs)]> {
597 let isIndirectBranch = 1;
600 // Return instruction
601 class RetBase<RegisterClass RC>: JumpFR<RC, []> {
603 let isCodeGenOnly = 1;
605 let hasExtraSrcRegAllocReq = 1;
608 // Jump and Link (Call)
609 let isCall=1, hasDelaySlot=1, Defs = [RA] in {
610 class JumpLink<bits<6> op, string instr_asm>:
611 FJ<op, (outs), (ins calltarget:$target),
612 !strconcat(instr_asm, "\t$target"), [(MipsJmpLink imm:$target)],
614 let DecoderMethod = "DecodeJumpTarget";
617 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm,
619 FR<op, func, (outs), (ins RC:$rs),
620 !strconcat(instr_asm, "\t$rs"), [(MipsJmpLink RC:$rs)], IIBranch> {
626 class BranchLink<string instr_asm, bits<5> _rt, RegisterClass RC>:
627 FI<0x1, (outs), (ins RC:$rs, brtarget:$imm16),
628 !strconcat(instr_asm, "\t$rs, $imm16"), [], IIBranch> {
634 class Mult<bits<6> func, string instr_asm, InstrItinClass itin,
635 RegisterClass RC, list<Register> DefRegs>:
636 FR<0x00, func, (outs), (ins RC:$rs, RC:$rt),
637 !strconcat(instr_asm, "\t$rs, $rt"), [], itin> {
640 let isCommutable = 1;
642 let neverHasSideEffects = 1;
645 class Mult32<bits<6> func, string instr_asm, InstrItinClass itin>:
646 Mult<func, instr_asm, itin, CPURegs, [HI, LO]>;
648 class Div<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin,
649 RegisterClass RC, list<Register> DefRegs>:
650 FR<0x00, func, (outs), (ins RC:$rs, RC:$rt),
651 !strconcat(instr_asm, "\t$$zero, $rs, $rt"),
652 [(op RC:$rs, RC:$rt)], itin> {
658 class Div32<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin>:
659 Div<op, func, instr_asm, itin, CPURegs, [HI, LO]>;
662 class MoveFromLOHI<bits<6> func, string instr_asm, RegisterClass RC,
663 list<Register> UseRegs>:
664 FR<0x00, func, (outs RC:$rd), (ins),
665 !strconcat(instr_asm, "\t$rd"), [], IIHiLo> {
670 let neverHasSideEffects = 1;
673 class MoveToLOHI<bits<6> func, string instr_asm, RegisterClass RC,
674 list<Register> DefRegs>:
675 FR<0x00, func, (outs), (ins RC:$rs),
676 !strconcat(instr_asm, "\t$rs"), [], IIHiLo> {
681 let neverHasSideEffects = 1;
684 class EffectiveAddress<bits<6> opc, string instr_asm, RegisterClass RC, Operand Mem> :
685 FMem<opc, (outs RC:$rt), (ins Mem:$addr),
686 instr_asm, [(set RC:$rt, addr:$addr)], IIAlu> {
687 let isCodeGenOnly = 1;
690 // Count Leading Ones/Zeros in Word
691 class CountLeading0<bits<6> func, string instr_asm, RegisterClass RC>:
692 FR<0x1c, func, (outs RC:$rd), (ins RC:$rs),
693 !strconcat(instr_asm, "\t$rd, $rs"),
694 [(set RC:$rd, (ctlz RC:$rs))], IIAlu>,
695 Requires<[HasBitCount, HasStandardEncoding]> {
700 class CountLeading1<bits<6> func, string instr_asm, RegisterClass RC>:
701 FR<0x1c, func, (outs RC:$rd), (ins RC:$rs),
702 !strconcat(instr_asm, "\t$rd, $rs"),
703 [(set RC:$rd, (ctlz (not RC:$rs)))], IIAlu>,
704 Requires<[HasBitCount, HasStandardEncoding]> {
709 // Sign Extend in Register.
710 class SignExtInReg<bits<5> sa, string instr_asm, ValueType vt,
712 FR<0x1f, 0x20, (outs RC:$rd), (ins RC:$rt),
713 !strconcat(instr_asm, "\t$rd, $rt"),
714 [(set RC:$rd, (sext_inreg RC:$rt, vt))], NoItinerary> {
717 let Predicates = [HasSEInReg, HasStandardEncoding];
721 class SubwordSwap<bits<6> func, bits<5> sa, string instr_asm, RegisterClass RC>:
722 FR<0x1f, func, (outs RC:$rd), (ins RC:$rt),
723 !strconcat(instr_asm, "\t$rd, $rt"), [], NoItinerary> {
726 let Predicates = [HasSwap, HasStandardEncoding];
727 let neverHasSideEffects = 1;
731 class ReadHardware<RegisterClass CPURegClass, RegisterClass HWRegClass>
732 : FR<0x1f, 0x3b, (outs CPURegClass:$rt), (ins HWRegClass:$rd),
733 "rdhwr\t$rt, $rd", [], IIAlu> {
739 class ExtBase<bits<6> _funct, string instr_asm, RegisterClass RC>:
740 FR<0x1f, _funct, (outs RC:$rt), (ins RC:$rs, uimm16:$pos, size_ext:$sz),
741 !strconcat(instr_asm, " $rt, $rs, $pos, $sz"),
742 [(set RC:$rt, (MipsExt RC:$rs, imm:$pos, imm:$sz))], NoItinerary> {
747 let Predicates = [HasMips32r2, HasStandardEncoding];
750 class InsBase<bits<6> _funct, string instr_asm, RegisterClass RC>:
751 FR<0x1f, _funct, (outs RC:$rt),
752 (ins RC:$rs, uimm16:$pos, size_ins:$sz, RC:$src),
753 !strconcat(instr_asm, " $rt, $rs, $pos, $sz"),
754 [(set RC:$rt, (MipsIns RC:$rs, imm:$pos, imm:$sz, RC:$src))],
760 let Predicates = [HasMips32r2, HasStandardEncoding];
761 let Constraints = "$src = $rt";
764 // Atomic instructions with 2 source operands (ATOMIC_SWAP & ATOMIC_LOAD_*).
765 class Atomic2Ops<PatFrag Op, string Opstr, RegisterClass DRC,
767 PseudoSE<(outs DRC:$dst), (ins PRC:$ptr, DRC:$incr),
768 !strconcat("atomic_", Opstr, "\t$dst, $ptr, $incr"),
769 [(set DRC:$dst, (Op PRC:$ptr, DRC:$incr))]>;
771 multiclass Atomic2Ops32<PatFrag Op, string Opstr> {
772 def #NAME# : Atomic2Ops<Op, Opstr, CPURegs, CPURegs>,
773 Requires<[NotN64, HasStandardEncoding]>;
774 def _P8 : Atomic2Ops<Op, Opstr, CPURegs, CPU64Regs>,
775 Requires<[IsN64, HasStandardEncoding]> {
776 let DecoderNamespace = "Mips64";
780 // Atomic Compare & Swap.
781 class AtomicCmpSwap<PatFrag Op, string Width, RegisterClass DRC,
783 PseudoSE<(outs DRC:$dst), (ins PRC:$ptr, DRC:$cmp, DRC:$swap),
784 !strconcat("atomic_cmp_swap_", Width, "\t$dst, $ptr, $cmp, $swap"),
785 [(set DRC:$dst, (Op PRC:$ptr, DRC:$cmp, DRC:$swap))]>;
787 multiclass AtomicCmpSwap32<PatFrag Op, string Width> {
788 def #NAME# : AtomicCmpSwap<Op, Width, CPURegs, CPURegs>,
789 Requires<[NotN64, HasStandardEncoding]>;
790 def _P8 : AtomicCmpSwap<Op, Width, CPURegs, CPU64Regs>,
791 Requires<[IsN64, HasStandardEncoding]> {
792 let DecoderNamespace = "Mips64";
796 class LLBase<bits<6> Opc, string opstring, RegisterClass RC, Operand Mem> :
797 FMem<Opc, (outs RC:$rt), (ins Mem:$addr),
798 !strconcat(opstring, "\t$rt, $addr"), [], IILoad> {
802 class SCBase<bits<6> Opc, string opstring, RegisterClass RC, Operand Mem> :
803 FMem<Opc, (outs RC:$dst), (ins RC:$rt, Mem:$addr),
804 !strconcat(opstring, "\t$rt, $addr"), [], IIStore> {
806 let Constraints = "$rt = $dst";
809 //===----------------------------------------------------------------------===//
810 // Pseudo instructions
811 //===----------------------------------------------------------------------===//
814 let isReturn=1, isTerminator=1, hasDelaySlot=1, isBarrier=1, hasCtrlDep=1 in
815 def RetRA : PseudoSE<(outs), (ins), "", [(MipsRet)]>;
817 let Defs = [SP], Uses = [SP], hasSideEffects = 1 in {
818 def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins i32imm:$amt),
819 "!ADJCALLSTACKDOWN $amt",
820 [(callseq_start timm:$amt)]>;
821 def ADJCALLSTACKUP : MipsPseudo<(outs), (ins i32imm:$amt1, i32imm:$amt2),
822 "!ADJCALLSTACKUP $amt1",
823 [(callseq_end timm:$amt1, timm:$amt2)]>;
826 // When handling PIC code the assembler needs .cpload and .cprestore
827 // directives. If the real instructions corresponding these directives
828 // are used, we have the same behavior, but get also a bunch of warnings
829 // from the assembler.
830 let neverHasSideEffects = 1 in
831 def CPRESTORE : PseudoSE<(outs), (ins i32imm:$loc, CPURegs:$gp),
832 ".cprestore\t$loc", []>;
834 let usesCustomInserter = 1 in {
835 defm ATOMIC_LOAD_ADD_I8 : Atomic2Ops32<atomic_load_add_8, "load_add_8">;
836 defm ATOMIC_LOAD_ADD_I16 : Atomic2Ops32<atomic_load_add_16, "load_add_16">;
837 defm ATOMIC_LOAD_ADD_I32 : Atomic2Ops32<atomic_load_add_32, "load_add_32">;
838 defm ATOMIC_LOAD_SUB_I8 : Atomic2Ops32<atomic_load_sub_8, "load_sub_8">;
839 defm ATOMIC_LOAD_SUB_I16 : Atomic2Ops32<atomic_load_sub_16, "load_sub_16">;
840 defm ATOMIC_LOAD_SUB_I32 : Atomic2Ops32<atomic_load_sub_32, "load_sub_32">;
841 defm ATOMIC_LOAD_AND_I8 : Atomic2Ops32<atomic_load_and_8, "load_and_8">;
842 defm ATOMIC_LOAD_AND_I16 : Atomic2Ops32<atomic_load_and_16, "load_and_16">;
843 defm ATOMIC_LOAD_AND_I32 : Atomic2Ops32<atomic_load_and_32, "load_and_32">;
844 defm ATOMIC_LOAD_OR_I8 : Atomic2Ops32<atomic_load_or_8, "load_or_8">;
845 defm ATOMIC_LOAD_OR_I16 : Atomic2Ops32<atomic_load_or_16, "load_or_16">;
846 defm ATOMIC_LOAD_OR_I32 : Atomic2Ops32<atomic_load_or_32, "load_or_32">;
847 defm ATOMIC_LOAD_XOR_I8 : Atomic2Ops32<atomic_load_xor_8, "load_xor_8">;
848 defm ATOMIC_LOAD_XOR_I16 : Atomic2Ops32<atomic_load_xor_16, "load_xor_16">;
849 defm ATOMIC_LOAD_XOR_I32 : Atomic2Ops32<atomic_load_xor_32, "load_xor_32">;
850 defm ATOMIC_LOAD_NAND_I8 : Atomic2Ops32<atomic_load_nand_8, "load_nand_8">;
851 defm ATOMIC_LOAD_NAND_I16 : Atomic2Ops32<atomic_load_nand_16, "load_nand_16">;
852 defm ATOMIC_LOAD_NAND_I32 : Atomic2Ops32<atomic_load_nand_32, "load_nand_32">;
854 defm ATOMIC_SWAP_I8 : Atomic2Ops32<atomic_swap_8, "swap_8">;
855 defm ATOMIC_SWAP_I16 : Atomic2Ops32<atomic_swap_16, "swap_16">;
856 defm ATOMIC_SWAP_I32 : Atomic2Ops32<atomic_swap_32, "swap_32">;
858 defm ATOMIC_CMP_SWAP_I8 : AtomicCmpSwap32<atomic_cmp_swap_8, "8">;
859 defm ATOMIC_CMP_SWAP_I16 : AtomicCmpSwap32<atomic_cmp_swap_16, "16">;
860 defm ATOMIC_CMP_SWAP_I32 : AtomicCmpSwap32<atomic_cmp_swap_32, "32">;
863 //===----------------------------------------------------------------------===//
864 // Instruction definition
865 //===----------------------------------------------------------------------===//
867 class LoadImm32< string instr_asm, Operand Od, RegisterClass RC> :
868 MipsAsmPseudoInst<(outs RC:$rt), (ins Od:$imm32),
869 !strconcat(instr_asm, "\t$rt, $imm32")> ;
870 def LoadImm32Reg : LoadImm32<"li",shamt,CPURegs>;
871 //===----------------------------------------------------------------------===//
872 // MipsI Instructions
873 //===----------------------------------------------------------------------===//
875 /// Arithmetic Instructions (ALU Immediate)
876 def ADDiu : ArithLogicI<0x09, "addiu", add, simm16, immSExt16, CPURegs>;
877 def ADDi : ArithOverflowI<0x08, "addi", add, simm16, immSExt16, CPURegs>;
878 def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16, CPURegs>;
879 def SLTiu : SetCC_I<0x0b, "sltiu", setult, simm16, immSExt16, CPURegs>;
880 def ANDi : ArithLogicI<0x0c, "andi", and, uimm16, immZExt16, CPURegs>;
881 def ORi : ArithLogicI<0x0d, "ori", or, uimm16, immZExt16, CPURegs>;
882 def XORi : ArithLogicI<0x0e, "xori", xor, uimm16, immZExt16, CPURegs>;
883 def LUi : LoadUpper<0x0f, "lui", CPURegs, uimm16>;
885 /// Arithmetic Instructions (3-Operand, R-Type)
886 def ADDu : ArithLogicR<0x00, 0x21, "addu", add, IIAlu, CPURegs, 1>;
887 def SUBu : ArithLogicR<0x00, 0x23, "subu", sub, IIAlu, CPURegs>;
888 def ADD : ArithOverflowR<0x00, 0x20, "add", IIAlu, CPURegs, 1>;
889 def SUB : ArithOverflowR<0x00, 0x22, "sub", IIAlu, CPURegs>;
890 def SLT : SetCC_R<0x00, 0x2a, "slt", setlt, CPURegs>;
891 def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult, CPURegs>;
892 def AND : ArithLogicR<0x00, 0x24, "and", and, IIAlu, CPURegs, 1>;
893 def OR : ArithLogicR<0x00, 0x25, "or", or, IIAlu, CPURegs, 1>;
894 def XOR : ArithLogicR<0x00, 0x26, "xor", xor, IIAlu, CPURegs, 1>;
895 def NOR : LogicNOR<0x00, 0x27, "nor", CPURegs>;
897 /// Shift Instructions
898 def SLL : shift_rotate_imm32<0x00, 0x00, "sll", shl>;
899 def SRL : shift_rotate_imm32<0x02, 0x00, "srl", srl>;
900 def SRA : shift_rotate_imm32<0x03, 0x00, "sra", sra>;
901 def SLLV : shift_rotate_reg<0x04, 0x00, "sllv", shl, CPURegs>;
902 def SRLV : shift_rotate_reg<0x06, 0x00, "srlv", srl, CPURegs>;
903 def SRAV : shift_rotate_reg<0x07, 0x00, "srav", sra, CPURegs>;
905 // Rotate Instructions
906 let Predicates = [HasMips32r2, HasStandardEncoding] in {
907 def ROTR : shift_rotate_imm32<0x02, 0x01, "rotr", rotr>;
908 def ROTRV : shift_rotate_reg<0x06, 0x01, "rotrv", rotr, CPURegs>;
911 /// Load and Store Instructions
913 defm LB : LoadM32<0x20, "lb", sextloadi8>;
914 defm LBu : LoadM32<0x24, "lbu", zextloadi8>;
915 defm LH : LoadM32<0x21, "lh", sextloadi16>;
916 defm LHu : LoadM32<0x25, "lhu", zextloadi16>;
917 defm LW : LoadM32<0x23, "lw", load>;
918 defm SB : StoreM32<0x28, "sb", truncstorei8>;
919 defm SH : StoreM32<0x29, "sh", truncstorei16>;
920 defm SW : StoreM32<0x2b, "sw", store>;
922 /// load/store left/right
923 defm LWL : LoadLeftRightM32<0x22, "lwl", MipsLWL>;
924 defm LWR : LoadLeftRightM32<0x26, "lwr", MipsLWR>;
925 defm SWL : StoreLeftRightM32<0x2a, "swl", MipsSWL>;
926 defm SWR : StoreLeftRightM32<0x2e, "swr", MipsSWR>;
928 let hasSideEffects = 1 in
929 def SYNC : InstSE<(outs), (ins i32imm:$stype), "sync $stype",
930 [(MipsSync imm:$stype)], NoItinerary, FrmOther>
935 let Inst{10-6} = stype;
939 /// Load-linked, Store-conditional
940 def LL : LLBase<0x30, "ll", CPURegs, mem>,
941 Requires<[NotN64, HasStandardEncoding]>;
942 def LL_P8 : LLBase<0x30, "ll", CPURegs, mem64>,
943 Requires<[IsN64, HasStandardEncoding]> {
944 let DecoderNamespace = "Mips64";
947 def SC : SCBase<0x38, "sc", CPURegs, mem>,
948 Requires<[NotN64, HasStandardEncoding]>;
949 def SC_P8 : SCBase<0x38, "sc", CPURegs, mem64>,
950 Requires<[IsN64, HasStandardEncoding]> {
951 let DecoderNamespace = "Mips64";
954 /// Jump and Branch Instructions
955 def J : JumpFJ<0x02, "j">;
956 def JR : IndirectBranch<CPURegs>;
957 def B : UncondBranch<0x04, "b">;
958 def BEQ : CBranch<0x04, "beq", seteq, CPURegs>;
959 def BNE : CBranch<0x05, "bne", setne, CPURegs>;
960 def BGEZ : CBranchZero<0x01, 1, "bgez", setge, CPURegs>;
961 def BGTZ : CBranchZero<0x07, 0, "bgtz", setgt, CPURegs>;
962 def BLEZ : CBranchZero<0x06, 0, "blez", setle, CPURegs>;
963 def BLTZ : CBranchZero<0x01, 0, "bltz", setlt, CPURegs>;
965 let rt = 0, rs = 0, isBranch = 1, isTerminator = 1, isBarrier = 1,
966 hasDelaySlot = 1, Defs = [RA] in
967 def BAL_BR: FI<0x1, (outs), (ins brtarget:$imm16), "bal\t$imm16", [], IIBranch>;
969 def JAL : JumpLink<0x03, "jal">;
970 def JALR : JumpLinkReg<0x00, 0x09, "jalr", CPURegs>;
971 def BGEZAL : BranchLink<"bgezal", 0x11, CPURegs>;
972 def BLTZAL : BranchLink<"bltzal", 0x10, CPURegs>;
974 def RET : RetBase<CPURegs>;
976 /// Multiply and Divide Instructions.
977 def MULT : Mult32<0x18, "mult", IIImul>;
978 def MULTu : Mult32<0x19, "multu", IIImul>;
979 def SDIV : Div32<MipsDivRem, 0x1a, "div", IIIdiv>;
980 def UDIV : Div32<MipsDivRemU, 0x1b, "divu", IIIdiv>;
982 def MTHI : MoveToLOHI<0x11, "mthi", CPURegs, [HI]>;
983 def MTLO : MoveToLOHI<0x13, "mtlo", CPURegs, [LO]>;
984 def MFHI : MoveFromLOHI<0x10, "mfhi", CPURegs, [HI]>;
985 def MFLO : MoveFromLOHI<0x12, "mflo", CPURegs, [LO]>;
987 /// Sign Ext In Register Instructions.
988 def SEB : SignExtInReg<0x10, "seb", i8, CPURegs>;
989 def SEH : SignExtInReg<0x18, "seh", i16, CPURegs>;
992 def CLZ : CountLeading0<0x20, "clz", CPURegs>;
993 def CLO : CountLeading1<0x21, "clo", CPURegs>;
995 /// Word Swap Bytes Within Halfwords
996 def WSBH : SubwordSwap<0x20, 0x2, "wsbh", CPURegs>;
1000 def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
1002 // FrameIndexes are legalized when they are operands from load/store
1003 // instructions. The same not happens for stack address copies, so an
1004 // add op with mem ComplexPattern is used and the stack address copy
1005 // can be matched. It's similar to Sparc LEA_ADDRi
1006 def LEA_ADDiu : EffectiveAddress<0x09,"addiu\t$rt, $addr", CPURegs, mem_ea>;
1008 // DynAlloc node points to dynamically allocated stack space.
1009 // $sp is added to the list of implicitly used registers to prevent dead code
1010 // elimination from removing instructions that modify $sp.
1012 def DynAlloc : EffectiveAddress<0x09,"addiu\t$rt, $addr", CPURegs, mem_ea>;
1015 def MADD : MArithR<0, "madd", MipsMAdd, 1>;
1016 def MADDU : MArithR<1, "maddu", MipsMAddu, 1>;
1017 def MSUB : MArithR<4, "msub", MipsMSub>;
1018 def MSUBU : MArithR<5, "msubu", MipsMSubu>;
1020 // MUL is a assembly macro in the current used ISAs. In recent ISA's
1021 // it is a real instruction.
1022 def MUL : ArithLogicR<0x1c, 0x02, "mul", mul, IIImul, CPURegs, 1>,
1023 Requires<[HasMips32, HasStandardEncoding]>;
1025 def RDHWR : ReadHardware<CPURegs, HWRegs>;
1027 def EXT : ExtBase<0, "ext", CPURegs>;
1028 def INS : InsBase<4, "ins", CPURegs>;
1030 //===----------------------------------------------------------------------===//
1031 // Instruction aliases
1032 //===----------------------------------------------------------------------===//
1033 def : InstAlias<"move $dst,$src", (ADD CPURegs:$dst,CPURegs:$src,ZERO)>;
1034 def : InstAlias<"bal $offset", (BGEZAL RA,brtarget:$offset)>;
1035 def : InstAlias<"addu $rs,$rt,$imm",
1036 (ADDiu CPURegs:$rs,CPURegs:$rt,simm16:$imm)>;
1037 def : InstAlias<"add $rs,$rt,$imm",
1038 (ADDi CPURegs:$rs,CPURegs:$rt,simm16:$imm)>;
1039 def : InstAlias<"and $rs,$rt,$imm",
1040 (ANDi CPURegs:$rs,CPURegs:$rt,simm16:$imm)>;
1041 def : InstAlias<"j $rs", (JR CPURegs:$rs)>;
1042 def : InstAlias<"not $rt,$rs", (NOR CPURegs:$rt,CPURegs:$rs,ZERO)>;
1043 def : InstAlias<"neg $rt,$rs", (SUB CPURegs:$rt,ZERO,CPURegs:$rs)>;
1044 def : InstAlias<"negu $rt,$rs", (SUBu CPURegs:$rt,ZERO,CPURegs:$rs)>;
1045 def : InstAlias<"slt $rs,$rt,$imm",
1046 (SLTi CPURegs:$rs,CPURegs:$rt,simm16:$imm)>;
1047 def : InstAlias<"xor $rs,$rt,$imm",
1048 (XORi CPURegs:$rs,CPURegs:$rt,simm16:$imm)>;
1050 //===----------------------------------------------------------------------===//
1051 // Arbitrary patterns that map to one or more instructions
1052 //===----------------------------------------------------------------------===//
1055 def : MipsPat<(i32 immSExt16:$in),
1056 (ADDiu ZERO, imm:$in)>;
1057 def : MipsPat<(i32 immZExt16:$in),
1058 (ORi ZERO, imm:$in)>;
1059 def : MipsPat<(i32 immLow16Zero:$in),
1060 (LUi (HI16 imm:$in))>;
1062 // Arbitrary immediates
1063 def : MipsPat<(i32 imm:$imm),
1064 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
1066 // Carry MipsPatterns
1067 def : MipsPat<(subc CPURegs:$lhs, CPURegs:$rhs),
1068 (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
1069 def : MipsPat<(addc CPURegs:$lhs, CPURegs:$rhs),
1070 (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
1071 def : MipsPat<(addc CPURegs:$src, immSExt16:$imm),
1072 (ADDiu CPURegs:$src, imm:$imm)>;
1075 def : MipsPat<(MipsJmpLink (i32 tglobaladdr:$dst)),
1076 (JAL tglobaladdr:$dst)>;
1077 def : MipsPat<(MipsJmpLink (i32 texternalsym:$dst)),
1078 (JAL texternalsym:$dst)>;
1079 //def : MipsPat<(MipsJmpLink CPURegs:$dst),
1080 // (JALR CPURegs:$dst)>;
1083 def : MipsPat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
1084 def : MipsPat<(MipsHi tblockaddress:$in), (LUi tblockaddress:$in)>;
1085 def : MipsPat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
1086 def : MipsPat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
1087 def : MipsPat<(MipsHi tglobaltlsaddr:$in), (LUi tglobaltlsaddr:$in)>;
1089 def : MipsPat<(MipsLo tglobaladdr:$in), (ADDiu ZERO, tglobaladdr:$in)>;
1090 def : MipsPat<(MipsLo tblockaddress:$in), (ADDiu ZERO, tblockaddress:$in)>;
1091 def : MipsPat<(MipsLo tjumptable:$in), (ADDiu ZERO, tjumptable:$in)>;
1092 def : MipsPat<(MipsLo tconstpool:$in), (ADDiu ZERO, tconstpool:$in)>;
1093 def : MipsPat<(MipsLo tglobaltlsaddr:$in), (ADDiu ZERO, tglobaltlsaddr:$in)>;
1095 def : MipsPat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
1096 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
1097 def : MipsPat<(add CPURegs:$hi, (MipsLo tblockaddress:$lo)),
1098 (ADDiu CPURegs:$hi, tblockaddress:$lo)>;
1099 def : MipsPat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
1100 (ADDiu CPURegs:$hi, tjumptable:$lo)>;
1101 def : MipsPat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)),
1102 (ADDiu CPURegs:$hi, tconstpool:$lo)>;
1103 def : MipsPat<(add CPURegs:$hi, (MipsLo tglobaltlsaddr:$lo)),
1104 (ADDiu CPURegs:$hi, tglobaltlsaddr:$lo)>;
1107 def : MipsPat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)),
1108 (ADDiu CPURegs:$gp, tglobaladdr:$in)>;
1109 def : MipsPat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)),
1110 (ADDiu CPURegs:$gp, tconstpool:$in)>;
1113 class WrapperPat<SDNode node, Instruction ADDiuOp, RegisterClass RC>:
1114 MipsPat<(MipsWrapper RC:$gp, node:$in),
1115 (ADDiuOp RC:$gp, node:$in)>;
1117 def : WrapperPat<tglobaladdr, ADDiu, CPURegs>;
1118 def : WrapperPat<tconstpool, ADDiu, CPURegs>;
1119 def : WrapperPat<texternalsym, ADDiu, CPURegs>;
1120 def : WrapperPat<tblockaddress, ADDiu, CPURegs>;
1121 def : WrapperPat<tjumptable, ADDiu, CPURegs>;
1122 def : WrapperPat<tglobaltlsaddr, ADDiu, CPURegs>;
1124 // Mips does not have "not", so we expand our way
1125 def : MipsPat<(not CPURegs:$in),
1126 (NOR CPURegs:$in, ZERO)>;
1129 let Predicates = [NotN64, HasStandardEncoding] in {
1130 def : MipsPat<(i32 (extloadi1 addr:$src)), (LBu addr:$src)>;
1131 def : MipsPat<(i32 (extloadi8 addr:$src)), (LBu addr:$src)>;
1132 def : MipsPat<(i32 (extloadi16 addr:$src)), (LHu addr:$src)>;
1134 let Predicates = [IsN64, HasStandardEncoding] in {
1135 def : MipsPat<(i32 (extloadi1 addr:$src)), (LBu_P8 addr:$src)>;
1136 def : MipsPat<(i32 (extloadi8 addr:$src)), (LBu_P8 addr:$src)>;
1137 def : MipsPat<(i32 (extloadi16 addr:$src)), (LHu_P8 addr:$src)>;
1141 let Predicates = [NotN64, HasStandardEncoding] in {
1142 def : MipsPat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
1144 let Predicates = [IsN64, HasStandardEncoding] in {
1145 def : MipsPat<(store (i32 0), addr:$dst), (SW_P8 ZERO, addr:$dst)>;
1149 multiclass BrcondPats<RegisterClass RC, Instruction BEQOp, Instruction BNEOp,
1150 Instruction SLTOp, Instruction SLTuOp, Instruction SLTiOp,
1151 Instruction SLTiuOp, Register ZEROReg> {
1152 def : MipsPat<(brcond (i32 (setne RC:$lhs, 0)), bb:$dst),
1153 (BNEOp RC:$lhs, ZEROReg, bb:$dst)>;
1154 def : MipsPat<(brcond (i32 (seteq RC:$lhs, 0)), bb:$dst),
1155 (BEQOp RC:$lhs, ZEROReg, bb:$dst)>;
1157 def : MipsPat<(brcond (i32 (setge RC:$lhs, RC:$rhs)), bb:$dst),
1158 (BEQ (SLTOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>;
1159 def : MipsPat<(brcond (i32 (setuge RC:$lhs, RC:$rhs)), bb:$dst),
1160 (BEQ (SLTuOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>;
1161 def : MipsPat<(brcond (i32 (setge RC:$lhs, immSExt16:$rhs)), bb:$dst),
1162 (BEQ (SLTiOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
1163 def : MipsPat<(brcond (i32 (setuge RC:$lhs, immSExt16:$rhs)), bb:$dst),
1164 (BEQ (SLTiuOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
1166 def : MipsPat<(brcond (i32 (setle RC:$lhs, RC:$rhs)), bb:$dst),
1167 (BEQ (SLTOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>;
1168 def : MipsPat<(brcond (i32 (setule RC:$lhs, RC:$rhs)), bb:$dst),
1169 (BEQ (SLTuOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>;
1171 def : MipsPat<(brcond RC:$cond, bb:$dst),
1172 (BNEOp RC:$cond, ZEROReg, bb:$dst)>;
1175 defm : BrcondPats<CPURegs, BEQ, BNE, SLT, SLTu, SLTi, SLTiu, ZERO>;
1178 multiclass SeteqPats<RegisterClass RC, Instruction SLTiuOp, Instruction XOROp,
1179 Instruction SLTuOp, Register ZEROReg> {
1180 def : MipsPat<(seteq RC:$lhs, RC:$rhs),
1181 (SLTiuOp (XOROp RC:$lhs, RC:$rhs), 1)>;
1182 def : MipsPat<(setne RC:$lhs, RC:$rhs),
1183 (SLTuOp ZEROReg, (XOROp RC:$lhs, RC:$rhs))>;
1186 multiclass SetlePats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
1187 def : MipsPat<(setle RC:$lhs, RC:$rhs),
1188 (XORi (SLTOp RC:$rhs, RC:$lhs), 1)>;
1189 def : MipsPat<(setule RC:$lhs, RC:$rhs),
1190 (XORi (SLTuOp RC:$rhs, RC:$lhs), 1)>;
1193 multiclass SetgtPats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
1194 def : MipsPat<(setgt RC:$lhs, RC:$rhs),
1195 (SLTOp RC:$rhs, RC:$lhs)>;
1196 def : MipsPat<(setugt RC:$lhs, RC:$rhs),
1197 (SLTuOp RC:$rhs, RC:$lhs)>;
1200 multiclass SetgePats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
1201 def : MipsPat<(setge RC:$lhs, RC:$rhs),
1202 (XORi (SLTOp RC:$lhs, RC:$rhs), 1)>;
1203 def : MipsPat<(setuge RC:$lhs, RC:$rhs),
1204 (XORi (SLTuOp RC:$lhs, RC:$rhs), 1)>;
1207 multiclass SetgeImmPats<RegisterClass RC, Instruction SLTiOp,
1208 Instruction SLTiuOp> {
1209 def : MipsPat<(setge RC:$lhs, immSExt16:$rhs),
1210 (XORi (SLTiOp RC:$lhs, immSExt16:$rhs), 1)>;
1211 def : MipsPat<(setuge RC:$lhs, immSExt16:$rhs),
1212 (XORi (SLTiuOp RC:$lhs, immSExt16:$rhs), 1)>;
1215 defm : SeteqPats<CPURegs, SLTiu, XOR, SLTu, ZERO>;
1216 defm : SetlePats<CPURegs, SLT, SLTu>;
1217 defm : SetgtPats<CPURegs, SLT, SLTu>;
1218 defm : SetgePats<CPURegs, SLT, SLTu>;
1219 defm : SetgeImmPats<CPURegs, SLTi, SLTiu>;
1221 // select MipsDynAlloc
1222 def : MipsPat<(MipsDynAlloc addr:$f), (DynAlloc addr:$f)>;
1225 def : MipsPat<(bswap CPURegs:$rt), (ROTR (WSBH CPURegs:$rt), 16)>;
1227 //===----------------------------------------------------------------------===//
1228 // Floating Point Support
1229 //===----------------------------------------------------------------------===//
1231 include "MipsInstrFPU.td"
1232 include "Mips64InstrInfo.td"
1233 include "MipsCondMov.td"
1238 include "Mips16InstrFormats.td"
1239 include "Mips16InstrInfo.td"
1242 include "MipsDSPInstrFormats.td"
1243 include "MipsDSPInstrInfo.td"