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_MFLOHI : SDTypeProfile<1, 1, [SDTCisInt<0>, SDTCisVT<1, untyped>]>;
27 def SDT_MTLOHI : SDTypeProfile<1, 2, [SDTCisVT<0, untyped>,
28 SDTCisInt<1>, SDTCisSameAs<1, 2>]>;
29 def SDT_MipsMultDiv : SDTypeProfile<1, 2, [SDTCisVT<0, untyped>, SDTCisInt<1>,
31 def SDT_MipsMAddMSub : SDTypeProfile<1, 3,
32 [SDTCisVT<0, untyped>, SDTCisSameAs<0, 3>,
33 SDTCisVT<1, i32>, SDTCisSameAs<1, 2>]>;
34 def SDT_MipsDivRem16 : SDTypeProfile<0, 2, [SDTCisInt<0>, SDTCisSameAs<0, 1>]>;
36 def SDT_MipsThreadPointer : SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>;
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,
56 def MipsTailCall : SDNode<"MipsISD::TailCall", SDT_MipsJmpLink,
57 [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
59 // Hi and Lo nodes are used to handle global addresses. Used on
60 // MipsISelLowering to lower stuff like GlobalAddress, ExternalSymbol
61 // static model. (nothing to do with Mips Registers Hi and Lo)
62 def MipsHi : SDNode<"MipsISD::Hi", SDTIntUnaryOp>;
63 def MipsLo : SDNode<"MipsISD::Lo", SDTIntUnaryOp>;
64 def MipsGPRel : SDNode<"MipsISD::GPRel", SDTIntUnaryOp>;
66 // TlsGd node is used to handle General Dynamic TLS
67 def MipsTlsGd : SDNode<"MipsISD::TlsGd", SDTIntUnaryOp>;
69 // TprelHi and TprelLo nodes are used to handle Local Exec TLS
70 def MipsTprelHi : SDNode<"MipsISD::TprelHi", SDTIntUnaryOp>;
71 def MipsTprelLo : SDNode<"MipsISD::TprelLo", SDTIntUnaryOp>;
74 def MipsThreadPointer: SDNode<"MipsISD::ThreadPointer", SDT_MipsThreadPointer>;
77 def MipsRet : SDNode<"MipsISD::Ret", SDTNone,
78 [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
80 def MipsERet : SDNode<"MipsISD::ERet", SDTNone,
81 [SDNPHasChain, SDNPOptInGlue, SDNPSideEffect]>;
83 // These are target-independent nodes, but have target-specific formats.
84 def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_MipsCallSeqStart,
85 [SDNPHasChain, SDNPSideEffect, SDNPOutGlue]>;
86 def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_MipsCallSeqEnd,
87 [SDNPHasChain, SDNPSideEffect,
88 SDNPOptInGlue, SDNPOutGlue]>;
90 // Nodes used to extract LO/HI registers.
91 def MipsMFHI : SDNode<"MipsISD::MFHI", SDT_MFLOHI>;
92 def MipsMFLO : SDNode<"MipsISD::MFLO", SDT_MFLOHI>;
94 // Node used to insert 32-bit integers to LOHI register pair.
95 def MipsMTLOHI : SDNode<"MipsISD::MTLOHI", SDT_MTLOHI>;
98 def MipsMult : SDNode<"MipsISD::Mult", SDT_MipsMultDiv>;
99 def MipsMultu : SDNode<"MipsISD::Multu", SDT_MipsMultDiv>;
102 def MipsMAdd : SDNode<"MipsISD::MAdd", SDT_MipsMAddMSub>;
103 def MipsMAddu : SDNode<"MipsISD::MAddu", SDT_MipsMAddMSub>;
104 def MipsMSub : SDNode<"MipsISD::MSub", SDT_MipsMAddMSub>;
105 def MipsMSubu : SDNode<"MipsISD::MSubu", SDT_MipsMAddMSub>;
108 def MipsDivRem : SDNode<"MipsISD::DivRem", SDT_MipsMultDiv>;
109 def MipsDivRemU : SDNode<"MipsISD::DivRemU", SDT_MipsMultDiv>;
110 def MipsDivRem16 : SDNode<"MipsISD::DivRem16", SDT_MipsDivRem16,
112 def MipsDivRemU16 : SDNode<"MipsISD::DivRemU16", SDT_MipsDivRem16,
115 // Target constant nodes that are not part of any isel patterns and remain
116 // unchanged can cause instructions with illegal operands to be emitted.
117 // Wrapper node patterns give the instruction selector a chance to replace
118 // target constant nodes that would otherwise remain unchanged with ADDiu
119 // nodes. Without these wrapper node patterns, the following conditional move
120 // instruction is emitted when function cmov2 in test/CodeGen/Mips/cmov.ll is
122 // movn %got(d)($gp), %got(c)($gp), $4
123 // This instruction is illegal since movn can take only register operands.
125 def MipsWrapper : SDNode<"MipsISD::Wrapper", SDTIntBinOp>;
127 def MipsSync : SDNode<"MipsISD::Sync", SDT_Sync, [SDNPHasChain,SDNPSideEffect]>;
129 def MipsExt : SDNode<"MipsISD::Ext", SDT_Ext>;
130 def MipsIns : SDNode<"MipsISD::Ins", SDT_Ins>;
132 def MipsLWL : SDNode<"MipsISD::LWL", SDTMipsLoadLR,
133 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
134 def MipsLWR : SDNode<"MipsISD::LWR", SDTMipsLoadLR,
135 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
136 def MipsSWL : SDNode<"MipsISD::SWL", SDTStore,
137 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
138 def MipsSWR : SDNode<"MipsISD::SWR", SDTStore,
139 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
140 def MipsLDL : SDNode<"MipsISD::LDL", SDTMipsLoadLR,
141 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
142 def MipsLDR : SDNode<"MipsISD::LDR", SDTMipsLoadLR,
143 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
144 def MipsSDL : SDNode<"MipsISD::SDL", SDTStore,
145 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
146 def MipsSDR : SDNode<"MipsISD::SDR", SDTStore,
147 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
149 //===----------------------------------------------------------------------===//
150 // Mips Instruction Predicate Definitions.
151 //===----------------------------------------------------------------------===//
152 def HasMips2 : Predicate<"Subtarget->hasMips2()">,
153 AssemblerPredicate<"FeatureMips2">;
154 def HasMips3_32 : Predicate<"Subtarget->hasMips3_32()">,
155 AssemblerPredicate<"FeatureMips3_32">;
156 def HasMips3_32r2 : Predicate<"Subtarget->hasMips3_32r2()">,
157 AssemblerPredicate<"FeatureMips3_32r2">;
158 def HasMips3 : Predicate<"Subtarget->hasMips3()">,
159 AssemblerPredicate<"FeatureMips3">;
160 def HasMips4_32 : Predicate<"Subtarget->hasMips4_32()">,
161 AssemblerPredicate<"FeatureMips4_32">;
162 def NotMips4_32 : Predicate<"!Subtarget->hasMips4_32()">,
163 AssemblerPredicate<"!FeatureMips4_32">;
164 def HasMips4_32r2 : Predicate<"Subtarget->hasMips4_32r2()">,
165 AssemblerPredicate<"FeatureMips4_32r2">;
166 def HasMips5_32r2 : Predicate<"Subtarget->hasMips5_32r2()">,
167 AssemblerPredicate<"FeatureMips5_32r2">;
168 def HasMips32 : Predicate<"Subtarget->hasMips32()">,
169 AssemblerPredicate<"FeatureMips32">;
170 def HasMips32r2 : Predicate<"Subtarget->hasMips32r2()">,
171 AssemblerPredicate<"FeatureMips32r2">;
172 def HasMips32r5 : Predicate<"Subtarget->hasMips32r5()">,
173 AssemblerPredicate<"FeatureMips32r5">;
174 def HasMips32r6 : Predicate<"Subtarget->hasMips32r6()">,
175 AssemblerPredicate<"FeatureMips32r6">;
176 def NotMips32r6 : Predicate<"!Subtarget->hasMips32r6()">,
177 AssemblerPredicate<"!FeatureMips32r6">;
178 def IsGP64bit : Predicate<"Subtarget->isGP64bit()">,
179 AssemblerPredicate<"FeatureGP64Bit">;
180 def IsGP32bit : Predicate<"!Subtarget->isGP64bit()">,
181 AssemblerPredicate<"!FeatureGP64Bit">;
182 def HasMips64 : Predicate<"Subtarget->hasMips64()">,
183 AssemblerPredicate<"FeatureMips64">;
184 def NotMips64 : Predicate<"!Subtarget->hasMips64()">,
185 AssemblerPredicate<"!FeatureMips64">;
186 def HasMips64r2 : Predicate<"Subtarget->hasMips64r2()">,
187 AssemblerPredicate<"FeatureMips64r2">;
188 def HasMips64r6 : Predicate<"Subtarget->hasMips64r6()">,
189 AssemblerPredicate<"FeatureMips64r6">;
190 def NotMips64r6 : Predicate<"!Subtarget->hasMips64r6()">,
191 AssemblerPredicate<"!FeatureMips64r6">;
192 def HasMicroMips32r6 : Predicate<"Subtarget->inMicroMips32r6Mode()">,
193 AssemblerPredicate<"FeatureMicroMips,FeatureMips32r6">;
194 def HasMicroMips64r6 : Predicate<"Subtarget->inMicroMips64r6Mode()">,
195 AssemblerPredicate<"FeatureMicroMips,FeatureMips64r6">;
196 def InMips16Mode : Predicate<"Subtarget->inMips16Mode()">,
197 AssemblerPredicate<"FeatureMips16">;
198 def HasCnMips : Predicate<"Subtarget->hasCnMips()">,
199 AssemblerPredicate<"FeatureCnMips">;
200 def RelocStatic : Predicate<"TM.getRelocationModel() == Reloc::Static">;
201 def RelocPIC : Predicate<"TM.getRelocationModel() == Reloc::PIC_">;
202 def NoNaNsFPMath : Predicate<"TM.Options.NoNaNsFPMath">;
203 def HasStdEnc : Predicate<"Subtarget->hasStandardEncoding()">,
204 AssemblerPredicate<"!FeatureMips16">;
205 def NotDSP : Predicate<"!Subtarget->hasDSP()">;
206 def InMicroMips : Predicate<"Subtarget->inMicroMipsMode()">,
207 AssemblerPredicate<"FeatureMicroMips">;
208 def NotInMicroMips : Predicate<"!Subtarget->inMicroMipsMode()">,
209 AssemblerPredicate<"!FeatureMicroMips">;
210 def IsLE : Predicate<"Subtarget->isLittle()">;
211 def IsBE : Predicate<"!Subtarget->isLittle()">;
212 def IsNotNaCl : Predicate<"!Subtarget->isTargetNaCl()">;
213 def UseTCCInDIV : AssemblerPredicate<"FeatureUseTCCInDIV">;
214 def HasEVA : Predicate<"Subtarget->hasEVA()">,
215 AssemblerPredicate<"FeatureEVA,FeatureMips32r2">;
216 def HasMSA : Predicate<"Subtarget->hasMSA()">,
217 AssemblerPredicate<"FeatureMSA">;
220 //===----------------------------------------------------------------------===//
221 // Mips GPR size adjectives.
222 // They are mutually exclusive.
223 //===----------------------------------------------------------------------===//
225 class GPR_32 { list<Predicate> GPRPredicates = [IsGP32bit]; }
226 class GPR_64 { list<Predicate> GPRPredicates = [IsGP64bit]; }
228 //===----------------------------------------------------------------------===//
229 // Mips ISA/ASE membership and instruction group membership adjectives.
230 // They are mutually exclusive.
231 //===----------------------------------------------------------------------===//
233 // FIXME: I'd prefer to use additive predicates to build the instruction sets
234 // but we are short on assembler feature bits at the moment. Using a
235 // subtractive predicate will hopefully keep us under the 32 predicate
236 // limit long enough to develop an alternative way to handle P1||P2
238 class ISA_MIPS1_NOT_4_32 {
239 list<Predicate> InsnPredicates = [NotMips4_32];
241 class ISA_MIPS1_NOT_32R6_64R6 {
242 list<Predicate> InsnPredicates = [NotMips32r6, NotMips64r6];
244 class ISA_MIPS2 { list<Predicate> InsnPredicates = [HasMips2]; }
245 class ISA_MIPS2_NOT_32R6_64R6 {
246 list<Predicate> InsnPredicates = [HasMips2, NotMips32r6, NotMips64r6];
248 class ISA_MIPS3 { list<Predicate> InsnPredicates = [HasMips3]; }
249 class ISA_MIPS3_NOT_32R6_64R6 {
250 list<Predicate> InsnPredicates = [HasMips3, NotMips32r6, NotMips64r6];
252 class ISA_MIPS32 { list<Predicate> InsnPredicates = [HasMips32]; }
253 class ISA_MIPS32_NOT_32R6_64R6 {
254 list<Predicate> InsnPredicates = [HasMips32, NotMips32r6, NotMips64r6];
256 class ISA_MIPS32R2 { list<Predicate> InsnPredicates = [HasMips32r2]; }
257 class ISA_MIPS32R2_NOT_32R6_64R6 {
258 list<Predicate> InsnPredicates = [HasMips32r2, NotMips32r6, NotMips64r6];
260 class ISA_MIPS32R5 { list<Predicate> InsnPredicates = [HasMips32r5]; }
261 class ISA_MIPS64 { list<Predicate> InsnPredicates = [HasMips64]; }
262 class ISA_MIPS64_NOT_64R6 {
263 list<Predicate> InsnPredicates = [HasMips64, NotMips64r6];
265 class ISA_MIPS64R2 { list<Predicate> InsnPredicates = [HasMips64r2]; }
266 class ISA_MIPS32R6 { list<Predicate> InsnPredicates = [HasMips32r6]; }
267 class ISA_MIPS64R6 { list<Predicate> InsnPredicates = [HasMips64r6]; }
268 class ISA_MICROMIPS { list<Predicate> InsnPredicates = [InMicroMips]; }
269 class ISA_MICROMIPS32R6 {
270 list<Predicate> InsnPredicates = [HasMicroMips32r6];
272 class ISA_MICROMIPS64R6 {
273 list<Predicate> InsnPredicates = [HasMicroMips64r6];
275 class ISA_MICROMIPS32_NOT_MIPS32R6 {
276 list<Predicate> InsnPredicates = [InMicroMips, NotMips32r6];
279 class INSN_EVA { list<Predicate> InsnPredicates = [HasEVA]; }
280 class INSN_EVA_NOT_32R6_64R6 {
281 list<Predicate> InsnPredicates = [NotMips32r6, NotMips64r6, HasEVA];
284 // The portions of MIPS-III that were also added to MIPS32
285 class INSN_MIPS3_32 { list<Predicate> InsnPredicates = [HasMips3_32]; }
287 // The portions of MIPS-III that were also added to MIPS32 but were removed in
288 // MIPS32r6 and MIPS64r6.
289 class INSN_MIPS3_32_NOT_32R6_64R6 {
290 list<Predicate> InsnPredicates = [HasMips3_32, NotMips32r6, NotMips64r6];
293 // The portions of MIPS-III that were also added to MIPS32
294 class INSN_MIPS3_32R2 { list<Predicate> InsnPredicates = [HasMips3_32r2]; }
296 // The portions of MIPS-IV that were also added to MIPS32 but were removed in
297 // MIPS32r6 and MIPS64r6.
298 class INSN_MIPS4_32_NOT_32R6_64R6 {
299 list<Predicate> InsnPredicates = [HasMips4_32, NotMips32r6, NotMips64r6];
302 // The portions of MIPS-IV that were also added to MIPS32r2 but were removed in
303 // MIPS32r6 and MIPS64r6.
304 class INSN_MIPS4_32R2_NOT_32R6_64R6 {
305 list<Predicate> InsnPredicates = [HasMips4_32r2, NotMips32r6, NotMips64r6];
308 // The portions of MIPS-V that were also added to MIPS32r2 but were removed in
309 // MIPS32r6 and MIPS64r6.
310 class INSN_MIPS5_32R2_NOT_32R6_64R6 {
311 list<Predicate> InsnPredicates = [HasMips5_32r2, NotMips32r6, NotMips64r6];
315 list<Predicate> InsnPredicates = [HasCnMips];
319 list<Predicate> InsnPredicates = [HasMSA];
322 class ASE_MSA_NOT_MSA64 {
323 list<Predicate> InsnPredicates = [HasMSA, NotMips64];
327 list<Predicate> InsnPredicates = [HasMSA, HasMips64];
330 // Class used for separating microMIPSr6 and microMIPS (r3) instruction.
331 // It can be used only on instructions that doesn't inherit PredicateControl.
332 class ISA_MICROMIPS_NOT_32R6_64R6 : PredicateControl {
333 let InsnPredicates = [InMicroMips, NotMips32r6, NotMips64r6];
336 //===----------------------------------------------------------------------===//
338 class MipsPat<dag pattern, dag result> : Pat<pattern, result>, PredicateControl {
339 let EncodingPredicates = [HasStdEnc];
342 class MipsInstAlias<string Asm, dag Result, bit Emit = 0b1> :
343 InstAlias<Asm, Result, Emit>, PredicateControl;
346 bit isCommutable = 1;
363 bit isTerminator = 1;
366 bit hasExtraSrcRegAllocReq = 1;
367 bit isCodeGenOnly = 1;
370 class IsAsCheapAsAMove {
371 bit isAsCheapAsAMove = 1;
374 class NeverHasSideEffects {
375 bit hasSideEffects = 0;
378 //===----------------------------------------------------------------------===//
379 // Instruction format superclass
380 //===----------------------------------------------------------------------===//
382 include "MipsInstrFormats.td"
384 //===----------------------------------------------------------------------===//
385 // Mips Operand, Complex Patterns and Transformations Definitions.
386 //===----------------------------------------------------------------------===//
388 class ConstantUImmAsmOperandClass<int Bits, list<AsmOperandClass> Supers = [],
389 int Offset = 0> : AsmOperandClass {
390 let Name = "ConstantUImm" # Bits # "_" # Offset;
391 let RenderMethod = "addConstantUImmOperands<" # Bits # ", " # Offset # ">";
392 let PredicateMethod = "isConstantUImm<" # Bits # ", " # Offset # ">";
393 let SuperClasses = Supers;
394 let DiagnosticType = "UImm" # Bits # "_" # Offset;
397 def ConstantUImm5Plus32NormalizeAsmOperandClass
398 : ConstantUImmAsmOperandClass<5, [], 32> {
399 // We must also subtract 32 when we render the operand.
400 let RenderMethod = "addConstantUImmOperands<5, 32, -32>";
402 def ConstantUImm5Lsl2AsmOperandClass : AsmOperandClass {
403 let Name = "UImm5Lsl2";
404 let RenderMethod = "addImmOperands";
405 let PredicateMethod = "isScaledUImm<5, 2>";
406 let SuperClasses = [];
407 let DiagnosticType = "UImm5_Lsl2";
409 def ConstantUImm5ReportUImm6AsmOperandClass
410 : ConstantUImmAsmOperandClass<5, []> {
411 let Name = "ConstantUImm5_0_Report_UImm6";
412 let DiagnosticType = "UImm5_0_Report_UImm6";
414 def ConstantUImm5AsmOperandClass
415 : ConstantUImmAsmOperandClass<5, []>;
416 def ConstantUImm4AsmOperandClass
417 : ConstantUImmAsmOperandClass<
418 4, [ConstantUImm5AsmOperandClass,
419 ConstantUImm5Plus32NormalizeAsmOperandClass]>;
420 def ConstantUImm3AsmOperandClass
421 : ConstantUImmAsmOperandClass<3, [ConstantUImm4AsmOperandClass]>;
422 def ConstantUImm2Plus1AsmOperandClass
423 : ConstantUImmAsmOperandClass<2, [ConstantUImm3AsmOperandClass], 1>;
424 def ConstantUImm2AsmOperandClass
425 : ConstantUImmAsmOperandClass<2, [ConstantUImm3AsmOperandClass]>;
426 def ConstantUImm1AsmOperandClass
427 : ConstantUImmAsmOperandClass<1, [ConstantUImm2AsmOperandClass]>;
428 def ConstantImmzAsmOperandClass : AsmOperandClass {
429 let Name = "ConstantImmz";
430 let RenderMethod = "addConstantUImmOperands<1>";
431 let PredicateMethod = "isConstantImmz";
432 let SuperClasses = [ConstantUImm1AsmOperandClass];
433 let DiagnosticType = "Immz";
436 def MipsJumpTargetAsmOperand : AsmOperandClass {
437 let Name = "JumpTarget";
438 let ParserMethod = "parseJumpTarget";
439 let PredicateMethod = "isImm";
440 let RenderMethod = "addImmOperands";
443 // Instruction operand types
444 def jmptarget : Operand<OtherVT> {
445 let EncoderMethod = "getJumpTargetOpValue";
446 let ParserMatchClass = MipsJumpTargetAsmOperand;
448 def brtarget : Operand<OtherVT> {
449 let EncoderMethod = "getBranchTargetOpValue";
450 let OperandType = "OPERAND_PCREL";
451 let DecoderMethod = "DecodeBranchTarget";
452 let ParserMatchClass = MipsJumpTargetAsmOperand;
454 def calltarget : Operand<iPTR> {
455 let EncoderMethod = "getJumpTargetOpValue";
456 let ParserMatchClass = MipsJumpTargetAsmOperand;
459 def imm64: Operand<i64>;
461 def simm9 : Operand<i32>;
462 def simm10 : Operand<i32>;
463 def simm11 : Operand<i32>;
465 def simm16 : Operand<i32> {
466 let DecoderMethod= "DecodeSimm16";
469 def simm19_lsl2 : Operand<i32> {
470 let EncoderMethod = "getSimm19Lsl2Encoding";
471 let DecoderMethod = "DecodeSimm19Lsl2";
472 let ParserMatchClass = MipsJumpTargetAsmOperand;
475 def simm18_lsl3 : Operand<i32> {
476 let EncoderMethod = "getSimm18Lsl3Encoding";
477 let DecoderMethod = "DecodeSimm18Lsl3";
478 let ParserMatchClass = MipsJumpTargetAsmOperand;
481 def simm20 : Operand<i32>;
482 def simm32 : Operand<i32>;
484 def uimm20 : Operand<i32> {
487 def MipsUImm10AsmOperand : AsmOperandClass {
489 let RenderMethod = "addImmOperands";
490 let ParserMethod = "parseImm";
491 let PredicateMethod = "isUImm<10>";
494 def uimm10 : Operand<i32> {
495 let ParserMatchClass = MipsUImm10AsmOperand;
498 def simm16_64 : Operand<i64> {
499 let DecoderMethod = "DecodeSimm16";
503 def uimmz : Operand<i32> {
504 let PrintMethod = "printUnsignedImm";
505 let ParserMatchClass = ConstantImmzAsmOperandClass;
509 foreach I = {1, 2, 3, 4, 5} in
510 def uimm # I : Operand<i32> {
511 let PrintMethod = "printUnsignedImm";
512 let ParserMatchClass =
513 !cast<AsmOperandClass>("ConstantUImm" # I # "AsmOperandClass");
516 def uimm2_plus1 : Operand<i32> {
517 let PrintMethod = "printUnsignedImm";
518 let EncoderMethod = "getUImmWithOffsetEncoding<2, 1>";
519 let DecoderMethod = "DecodeUImmWithOffset<2, 1>";
520 let ParserMatchClass = ConstantUImm2Plus1AsmOperandClass;
523 def uimm5_plus32_normalize : Operand<i32> {
524 let PrintMethod = "printUnsignedImm";
525 let ParserMatchClass = ConstantUImm5Plus32NormalizeAsmOperandClass;
528 def uimm5_lsl2 : Operand<OtherVT> {
529 let EncoderMethod = "getUImm5Lsl2Encoding";
530 let DecoderMethod = "DecodeUImm5lsl2";
531 let ParserMatchClass = ConstantUImm5Lsl2AsmOperandClass;
534 def uimm5_plus32_normalize_64 : Operand<i64> {
535 let PrintMethod = "printUnsignedImm";
536 let ParserMatchClass = ConstantUImm5Plus32NormalizeAsmOperandClass;
540 def uimm # I # _64 : Operand<i64> {
541 let PrintMethod = "printUnsignedImm";
542 let ParserMatchClass =
543 !cast<AsmOperandClass>("ConstantUImm" # I # "AsmOperandClass");
546 // Like uimm5_64 but reports a less confusing error for 32-63 when
547 // an instruction alias permits that.
548 def uimm5_64_report_uimm6 : Operand<i64> {
549 let PrintMethod = "printUnsignedImm";
550 let ParserMatchClass = ConstantUImm5ReportUImm6AsmOperandClass;
553 def uimm6 : Operand<i32> {
554 let PrintMethod = "printUnsignedImm";
557 def uimm16 : Operand<i32> {
558 let PrintMethod = "printUnsignedImm";
561 def pcrel16 : Operand<i32> {
564 def MipsMemAsmOperand : AsmOperandClass {
566 let ParserMethod = "parseMemOperand";
569 def MipsMemSimm9AsmOperand : AsmOperandClass {
570 let Name = "MemOffsetSimm9";
571 let SuperClasses = [MipsMemAsmOperand];
572 let RenderMethod = "addMemOperands";
573 let ParserMethod = "parseMemOperand";
574 let PredicateMethod = "isMemWithSimmOffset<9>";
577 def MipsMemSimm9GPRAsmOperand : AsmOperandClass {
578 let Name = "MemOffsetSimm9GPR";
579 let SuperClasses = [MipsMemAsmOperand];
580 let RenderMethod = "addMemOperands";
581 let ParserMethod = "parseMemOperand";
582 let PredicateMethod = "isMemWithSimmOffsetGPR<9>";
585 def MipsMemSimm11AsmOperand : AsmOperandClass {
586 let Name = "MemOffsetSimm11";
587 let SuperClasses = [MipsMemAsmOperand];
588 let RenderMethod = "addMemOperands";
589 let ParserMethod = "parseMemOperand";
590 let PredicateMethod = "isMemWithSimmOffset<11>";
593 def MipsMemSimm16AsmOperand : AsmOperandClass {
594 let Name = "MemOffsetSimm16";
595 let SuperClasses = [MipsMemAsmOperand];
596 let RenderMethod = "addMemOperands";
597 let ParserMethod = "parseMemOperand";
598 let PredicateMethod = "isMemWithSimmOffset<16>";
601 def MipsMemSimm16GPRAsmOperand : AsmOperandClass {
602 let Name = "MemOffsetSimm16GPR";
603 let SuperClasses = [MipsMemAsmOperand];
604 let RenderMethod = "addMemOperands";
605 let ParserMethod = "parseMemOperand";
606 let PredicateMethod = "isMemWithSimmOffsetGPR<16>";
609 def MipsInvertedImmoperand : AsmOperandClass {
611 let RenderMethod = "addImmOperands";
612 let ParserMethod = "parseInvNum";
615 def InvertedImOperand : Operand<i32> {
616 let ParserMatchClass = MipsInvertedImmoperand;
619 def InvertedImOperand64 : Operand<i64> {
620 let ParserMatchClass = MipsInvertedImmoperand;
623 class mem_generic : Operand<iPTR> {
624 let PrintMethod = "printMemOperand";
625 let MIOperandInfo = (ops ptr_rc, simm16);
626 let EncoderMethod = "getMemEncoding";
627 let ParserMatchClass = MipsMemAsmOperand;
628 let OperandType = "OPERAND_MEMORY";
632 def mem : mem_generic;
634 // MSA specific address operand
635 def mem_msa : mem_generic {
636 let MIOperandInfo = (ops ptr_rc, simm10);
637 let EncoderMethod = "getMSAMemEncoding";
640 def mem_simm9 : mem_generic {
641 let MIOperandInfo = (ops ptr_rc, simm9);
642 let EncoderMethod = "getMemEncoding";
643 let ParserMatchClass = MipsMemSimm9AsmOperand;
646 def mem_simm9gpr : mem_generic {
647 let MIOperandInfo = (ops ptr_rc, simm9);
648 let EncoderMethod = "getMemEncoding";
649 let ParserMatchClass = MipsMemSimm9GPRAsmOperand;
652 def mem_simm11 : mem_generic {
653 let MIOperandInfo = (ops ptr_rc, simm11);
654 let EncoderMethod = "getMemEncoding";
655 let ParserMatchClass = MipsMemSimm11AsmOperand;
658 def mem_simm16 : mem_generic {
659 let MIOperandInfo = (ops ptr_rc, simm16);
660 let EncoderMethod = "getMemEncoding";
661 let ParserMatchClass = MipsMemSimm16AsmOperand;
664 def mem_simm16gpr : mem_generic {
665 let MIOperandInfo = (ops ptr_rc, simm16);
666 let EncoderMethod = "getMemEncoding";
667 let ParserMatchClass = MipsMemSimm16GPRAsmOperand;
670 def mem_ea : Operand<iPTR> {
671 let PrintMethod = "printMemOperandEA";
672 let MIOperandInfo = (ops ptr_rc, simm16);
673 let EncoderMethod = "getMemEncoding";
674 let OperandType = "OPERAND_MEMORY";
677 def PtrRC : Operand<iPTR> {
678 let MIOperandInfo = (ops ptr_rc);
679 let DecoderMethod = "DecodePtrRegisterClass";
680 let ParserMatchClass = GPR32AsmOperand;
683 // size operand of ext instruction
684 def size_ext : Operand<i32> {
685 let EncoderMethod = "getSizeExtEncoding";
686 let DecoderMethod = "DecodeExtSize";
689 // size operand of ins instruction
690 def size_ins : Operand<i32> {
691 let EncoderMethod = "getSizeInsEncoding";
692 let DecoderMethod = "DecodeInsSize";
695 // Transformation Function - get the lower 16 bits.
696 def LO16 : SDNodeXForm<imm, [{
697 return getImm(N, N->getZExtValue() & 0xFFFF);
700 // Transformation Function - get the higher 16 bits.
701 def HI16 : SDNodeXForm<imm, [{
702 return getImm(N, (N->getZExtValue() >> 16) & 0xFFFF);
706 def Plus1 : SDNodeXForm<imm, [{ return getImm(N, N->getSExtValue() + 1); }]>;
708 // Node immediate is zero (e.g. insve.d)
709 def immz : PatLeaf<(imm), [{ return N->getSExtValue() == 0; }]>;
711 // Node immediate fits as 16-bit sign extended on target immediate.
713 def immSExt8 : PatLeaf<(imm), [{ return isInt<8>(N->getSExtValue()); }]>;
715 // Node immediate fits as 16-bit sign extended on target immediate.
717 def immSExt16 : PatLeaf<(imm), [{ return isInt<16>(N->getSExtValue()); }]>;
719 // Node immediate fits as 15-bit sign extended on target immediate.
721 def immSExt15 : PatLeaf<(imm), [{ return isInt<15>(N->getSExtValue()); }]>;
723 // Node immediate fits as 16-bit zero extended on target immediate.
724 // The LO16 param means that only the lower 16 bits of the node
725 // immediate are caught.
727 def immZExt16 : PatLeaf<(imm), [{
728 if (N->getValueType(0) == MVT::i32)
729 return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
731 return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
734 // Immediate can be loaded with LUi (32-bit int with lower 16-bit cleared).
735 def immLow16Zero : PatLeaf<(imm), [{
736 int64_t Val = N->getSExtValue();
737 return isInt<32>(Val) && !(Val & 0xffff);
740 // shamt field must fit in 5 bits.
741 def immZExt5 : ImmLeaf<i32, [{return Imm == (Imm & 0x1f);}]>;
743 // True if (N + 1) fits in 16-bit field.
744 def immSExt16Plus1 : PatLeaf<(imm), [{
745 return isInt<17>(N->getSExtValue()) && isInt<16>(N->getSExtValue() + 1);
748 // Mips Address Mode! SDNode frameindex could possibily be a match
749 // since load and store instructions from stack used it.
751 ComplexPattern<iPTR, 2, "selectIntAddr", [frameindex]>;
754 ComplexPattern<iPTR, 2, "selectAddrRegImm", [frameindex]>;
757 ComplexPattern<iPTR, 2, "selectAddrRegReg", [frameindex]>;
760 ComplexPattern<iPTR, 2, "selectAddrDefault", [frameindex]>;
762 def addrimm10 : ComplexPattern<iPTR, 2, "selectIntAddrMSA", [frameindex]>;
764 //===----------------------------------------------------------------------===//
765 // Instructions specific format
766 //===----------------------------------------------------------------------===//
768 // Arithmetic and logical instructions with 3 register operands.
769 class ArithLogicR<string opstr, RegisterOperand RO, bit isComm = 0,
770 InstrItinClass Itin = NoItinerary,
771 SDPatternOperator OpNode = null_frag>:
772 InstSE<(outs RO:$rd), (ins RO:$rs, RO:$rt),
773 !strconcat(opstr, "\t$rd, $rs, $rt"),
774 [(set RO:$rd, (OpNode RO:$rs, RO:$rt))], Itin, FrmR, opstr> {
775 let isCommutable = isComm;
776 let isReMaterializable = 1;
777 let TwoOperandAliasConstraint = "$rd = $rs";
780 // Arithmetic and logical instructions with 2 register operands.
781 class ArithLogicI<string opstr, Operand Od, RegisterOperand RO,
782 InstrItinClass Itin = NoItinerary,
783 SDPatternOperator imm_type = null_frag,
784 SDPatternOperator OpNode = null_frag> :
785 InstSE<(outs RO:$rt), (ins RO:$rs, Od:$imm16),
786 !strconcat(opstr, "\t$rt, $rs, $imm16"),
787 [(set RO:$rt, (OpNode RO:$rs, imm_type:$imm16))],
789 let isReMaterializable = 1;
790 let TwoOperandAliasConstraint = "$rs = $rt";
793 // Arithmetic Multiply ADD/SUB
794 class MArithR<string opstr, InstrItinClass itin, bit isComm = 0> :
795 InstSE<(outs), (ins GPR32Opnd:$rs, GPR32Opnd:$rt),
796 !strconcat(opstr, "\t$rs, $rt"), [], itin, FrmR, opstr> {
797 let Defs = [HI0, LO0];
798 let Uses = [HI0, LO0];
799 let isCommutable = isComm;
803 class LogicNOR<string opstr, RegisterOperand RO>:
804 InstSE<(outs RO:$rd), (ins RO:$rs, RO:$rt),
805 !strconcat(opstr, "\t$rd, $rs, $rt"),
806 [(set RO:$rd, (not (or RO:$rs, RO:$rt)))], II_NOR, FrmR, opstr> {
807 let isCommutable = 1;
811 class shift_rotate_imm<string opstr, Operand ImmOpnd,
812 RegisterOperand RO, InstrItinClass itin,
813 SDPatternOperator OpNode = null_frag,
814 SDPatternOperator PF = null_frag> :
815 InstSE<(outs RO:$rd), (ins RO:$rt, ImmOpnd:$shamt),
816 !strconcat(opstr, "\t$rd, $rt, $shamt"),
817 [(set RO:$rd, (OpNode RO:$rt, PF:$shamt))], itin, FrmR, opstr> {
818 let TwoOperandAliasConstraint = "$rt = $rd";
821 class shift_rotate_reg<string opstr, RegisterOperand RO, InstrItinClass itin,
822 SDPatternOperator OpNode = null_frag>:
823 InstSE<(outs RO:$rd), (ins RO:$rt, GPR32Opnd:$rs),
824 !strconcat(opstr, "\t$rd, $rt, $rs"),
825 [(set RO:$rd, (OpNode RO:$rt, GPR32Opnd:$rs))], itin, FrmR,
828 // Load Upper Immediate
829 class LoadUpper<string opstr, RegisterOperand RO, Operand Imm>:
830 InstSE<(outs RO:$rt), (ins Imm:$imm16), !strconcat(opstr, "\t$rt, $imm16"),
831 [], II_LUI, FrmI, opstr>, IsAsCheapAsAMove {
832 let hasSideEffects = 0;
833 let isReMaterializable = 1;
837 class LoadMemory<string opstr, DAGOperand RO, DAGOperand MO,
838 SDPatternOperator OpNode = null_frag,
839 InstrItinClass Itin = NoItinerary,
840 ComplexPattern Addr = addr> :
841 InstSE<(outs RO:$rt), (ins MO:$addr), !strconcat(opstr, "\t$rt, $addr"),
842 [(set RO:$rt, (OpNode Addr:$addr))], Itin, FrmI, opstr> {
843 let DecoderMethod = "DecodeMem";
844 let canFoldAsLoad = 1;
848 class Load<string opstr, DAGOperand RO, SDPatternOperator OpNode = null_frag,
849 InstrItinClass Itin = NoItinerary, ComplexPattern Addr = addr> :
850 LoadMemory<opstr, RO, mem, OpNode, Itin, Addr>;
852 class StoreMemory<string opstr, DAGOperand RO, DAGOperand MO,
853 SDPatternOperator OpNode = null_frag,
854 InstrItinClass Itin = NoItinerary, ComplexPattern Addr = addr> :
855 InstSE<(outs), (ins RO:$rt, MO:$addr), !strconcat(opstr, "\t$rt, $addr"),
856 [(OpNode RO:$rt, Addr:$addr)], Itin, FrmI, opstr> {
857 let DecoderMethod = "DecodeMem";
861 class Store<string opstr, DAGOperand RO, SDPatternOperator OpNode = null_frag,
862 InstrItinClass Itin = NoItinerary, ComplexPattern Addr = addr> :
863 StoreMemory<opstr, RO, mem, OpNode, Itin, Addr>;
865 // Load/Store Left/Right
866 let canFoldAsLoad = 1 in
867 class LoadLeftRight<string opstr, SDNode OpNode, RegisterOperand RO,
868 InstrItinClass Itin> :
869 InstSE<(outs RO:$rt), (ins mem:$addr, RO:$src),
870 !strconcat(opstr, "\t$rt, $addr"),
871 [(set RO:$rt, (OpNode addr:$addr, RO:$src))], Itin, FrmI> {
872 let DecoderMethod = "DecodeMem";
873 string Constraints = "$src = $rt";
876 class StoreLeftRight<string opstr, SDNode OpNode, RegisterOperand RO,
877 InstrItinClass Itin> :
878 InstSE<(outs), (ins RO:$rt, mem:$addr), !strconcat(opstr, "\t$rt, $addr"),
879 [(OpNode RO:$rt, addr:$addr)], Itin, FrmI> {
880 let DecoderMethod = "DecodeMem";
884 class LW_FT2<string opstr, RegisterOperand RC, InstrItinClass Itin,
885 SDPatternOperator OpNode= null_frag> :
886 InstSE<(outs RC:$rt), (ins mem:$addr), !strconcat(opstr, "\t$rt, $addr"),
887 [(set RC:$rt, (OpNode addrDefault:$addr))], Itin, FrmFI, opstr> {
888 let DecoderMethod = "DecodeFMem2";
892 class SW_FT2<string opstr, RegisterOperand RC, InstrItinClass Itin,
893 SDPatternOperator OpNode= null_frag> :
894 InstSE<(outs), (ins RC:$rt, mem:$addr), !strconcat(opstr, "\t$rt, $addr"),
895 [(OpNode RC:$rt, addrDefault:$addr)], Itin, FrmFI, opstr> {
896 let DecoderMethod = "DecodeFMem2";
901 class LW_FT3<string opstr, RegisterOperand RC, InstrItinClass Itin,
902 SDPatternOperator OpNode= null_frag> :
903 InstSE<(outs RC:$rt), (ins mem:$addr), !strconcat(opstr, "\t$rt, $addr"),
904 [(set RC:$rt, (OpNode addrDefault:$addr))], Itin, FrmFI, opstr> {
905 let DecoderMethod = "DecodeFMem3";
909 class SW_FT3<string opstr, RegisterOperand RC, InstrItinClass Itin,
910 SDPatternOperator OpNode= null_frag> :
911 InstSE<(outs), (ins RC:$rt, mem:$addr), !strconcat(opstr, "\t$rt, $addr"),
912 [(OpNode RC:$rt, addrDefault:$addr)], Itin, FrmFI, opstr> {
913 let DecoderMethod = "DecodeFMem3";
917 // Conditional Branch
918 class CBranch<string opstr, DAGOperand opnd, PatFrag cond_op,
919 RegisterOperand RO, bit DelaySlot = 1> :
920 InstSE<(outs), (ins RO:$rs, RO:$rt, opnd:$offset),
921 !strconcat(opstr, "\t$rs, $rt, $offset"),
922 [(brcond (i32 (cond_op RO:$rs, RO:$rt)), bb:$offset)], II_BCC,
925 let isTerminator = 1;
926 let hasDelaySlot = DelaySlot;
930 class CBranchZero<string opstr, DAGOperand opnd, PatFrag cond_op,
931 RegisterOperand RO, bit DelaySlot = 1> :
932 InstSE<(outs), (ins RO:$rs, opnd:$offset),
933 !strconcat(opstr, "\t$rs, $offset"),
934 [(brcond (i32 (cond_op RO:$rs, 0)), bb:$offset)], II_BCCZ,
937 let isTerminator = 1;
938 let hasDelaySlot = DelaySlot;
943 class SetCC_R<string opstr, PatFrag cond_op, RegisterOperand RO> :
944 InstSE<(outs GPR32Opnd:$rd), (ins RO:$rs, RO:$rt),
945 !strconcat(opstr, "\t$rd, $rs, $rt"),
946 [(set GPR32Opnd:$rd, (cond_op RO:$rs, RO:$rt))],
947 II_SLT_SLTU, FrmR, opstr>;
949 class SetCC_I<string opstr, PatFrag cond_op, Operand Od, PatLeaf imm_type,
951 InstSE<(outs GPR32Opnd:$rt), (ins RO:$rs, Od:$imm16),
952 !strconcat(opstr, "\t$rt, $rs, $imm16"),
953 [(set GPR32Opnd:$rt, (cond_op RO:$rs, imm_type:$imm16))],
954 II_SLTI_SLTIU, FrmI, opstr>;
957 class JumpFJ<DAGOperand opnd, string opstr, SDPatternOperator operator,
958 SDPatternOperator targetoperator, string bopstr> :
959 InstSE<(outs), (ins opnd:$target), !strconcat(opstr, "\t$target"),
960 [(operator targetoperator:$target)], II_J, FrmJ, bopstr> {
963 let hasDelaySlot = 1;
964 let DecoderMethod = "DecodeJumpTarget";
968 // Unconditional branch
969 class UncondBranch<Instruction BEQInst> :
970 PseudoSE<(outs), (ins brtarget:$offset), [(br bb:$offset)], II_B>,
971 PseudoInstExpansion<(BEQInst ZERO, ZERO, brtarget:$offset)> {
973 let isTerminator = 1;
975 let hasDelaySlot = 1;
976 let AdditionalPredicates = [RelocPIC];
980 // Base class for indirect branch and return instruction classes.
981 let isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
982 class JumpFR<string opstr, RegisterOperand RO,
983 SDPatternOperator operator = null_frag>:
984 InstSE<(outs), (ins RO:$rs), "jr\t$rs", [(operator RO:$rs)], II_JR,
988 class IndirectBranch<string opstr, RegisterOperand RO> : JumpFR<opstr, RO> {
990 let isIndirectBranch = 1;
993 // Jump and Link (Call)
994 let isCall=1, hasDelaySlot=1, Defs = [RA] in {
995 class JumpLink<string opstr, DAGOperand opnd> :
996 InstSE<(outs), (ins opnd:$target), !strconcat(opstr, "\t$target"),
997 [(MipsJmpLink imm:$target)], II_JAL, FrmJ, opstr> {
998 let DecoderMethod = "DecodeJumpTarget";
1001 class JumpLinkRegPseudo<RegisterOperand RO, Instruction JALRInst,
1002 Register RetReg, RegisterOperand ResRO = RO>:
1003 PseudoSE<(outs), (ins RO:$rs), [(MipsJmpLink RO:$rs)], II_JALR>,
1004 PseudoInstExpansion<(JALRInst RetReg, ResRO:$rs)>;
1006 class JumpLinkReg<string opstr, RegisterOperand RO>:
1007 InstSE<(outs RO:$rd), (ins RO:$rs), !strconcat(opstr, "\t$rd, $rs"),
1008 [], II_JALR, FrmR, opstr>;
1010 class BGEZAL_FT<string opstr, DAGOperand opnd,
1011 RegisterOperand RO, bit DelaySlot = 1> :
1012 InstSE<(outs), (ins RO:$rs, opnd:$offset),
1013 !strconcat(opstr, "\t$rs, $offset"), [], II_BCCZAL, FrmI, opstr> {
1014 let hasDelaySlot = DelaySlot;
1019 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1, hasDelaySlot = 1,
1020 hasExtraSrcRegAllocReq = 1, Defs = [AT] in {
1021 class TailCall<Instruction JumpInst> :
1022 PseudoSE<(outs), (ins calltarget:$target), [], II_J>,
1023 PseudoInstExpansion<(JumpInst jmptarget:$target)>;
1025 class TailCallReg<RegisterOperand RO, Instruction JRInst,
1026 RegisterOperand ResRO = RO> :
1027 PseudoSE<(outs), (ins RO:$rs), [(MipsTailCall RO:$rs)], II_JR>,
1028 PseudoInstExpansion<(JRInst ResRO:$rs)>;
1031 class BAL_BR_Pseudo<Instruction RealInst> :
1032 PseudoSE<(outs), (ins brtarget:$offset), [], II_BCCZAL>,
1033 PseudoInstExpansion<(RealInst ZERO, brtarget:$offset)> {
1035 let isTerminator = 1;
1037 let hasDelaySlot = 1;
1042 class SYS_FT<string opstr> :
1043 InstSE<(outs), (ins uimm20:$code_),
1044 !strconcat(opstr, "\t$code_"), [], NoItinerary, FrmI, opstr>;
1046 class BRK_FT<string opstr> :
1047 InstSE<(outs), (ins uimm10:$code_1, uimm10:$code_2),
1048 !strconcat(opstr, "\t$code_1, $code_2"), [], NoItinerary,
1052 class ER_FT<string opstr> :
1053 InstSE<(outs), (ins),
1054 opstr, [], NoItinerary, FrmOther, opstr>;
1057 class DEI_FT<string opstr, RegisterOperand RO> :
1058 InstSE<(outs RO:$rt), (ins),
1059 !strconcat(opstr, "\t$rt"), [], NoItinerary, FrmOther, opstr>;
1062 class WAIT_FT<string opstr> :
1063 InstSE<(outs), (ins), opstr, [], NoItinerary, FrmOther, opstr>;
1066 let hasSideEffects = 1 in
1067 class SYNC_FT<string opstr> :
1068 InstSE<(outs), (ins i32imm:$stype), "sync $stype", [(MipsSync imm:$stype)],
1069 NoItinerary, FrmOther, opstr>;
1071 class SYNCI_FT<string opstr> :
1072 InstSE<(outs), (ins mem_simm16:$addr), !strconcat(opstr, "\t$addr"), [],
1073 NoItinerary, FrmOther, opstr> {
1074 let hasSideEffects = 1;
1075 let DecoderMethod = "DecodeSyncI";
1078 let hasSideEffects = 1 in
1079 class TEQ_FT<string opstr, RegisterOperand RO> :
1080 InstSE<(outs), (ins RO:$rs, RO:$rt, uimm16:$code_),
1081 !strconcat(opstr, "\t$rs, $rt, $code_"), [], NoItinerary,
1084 class TEQI_FT<string opstr, RegisterOperand RO> :
1085 InstSE<(outs), (ins RO:$rs, uimm16:$imm16),
1086 !strconcat(opstr, "\t$rs, $imm16"), [], NoItinerary, FrmOther, opstr>;
1088 class Mult<string opstr, InstrItinClass itin, RegisterOperand RO,
1089 list<Register> DefRegs> :
1090 InstSE<(outs), (ins RO:$rs, RO:$rt), !strconcat(opstr, "\t$rs, $rt"), [],
1091 itin, FrmR, opstr> {
1092 let isCommutable = 1;
1094 let hasSideEffects = 0;
1097 // Pseudo multiply/divide instruction with explicit accumulator register
1099 class MultDivPseudo<Instruction RealInst, RegisterClass R0, RegisterOperand R1,
1100 SDPatternOperator OpNode, InstrItinClass Itin,
1101 bit IsComm = 1, bit HasSideEffects = 0,
1102 bit UsesCustomInserter = 0> :
1103 PseudoSE<(outs R0:$ac), (ins R1:$rs, R1:$rt),
1104 [(set R0:$ac, (OpNode R1:$rs, R1:$rt))], Itin>,
1105 PseudoInstExpansion<(RealInst R1:$rs, R1:$rt)> {
1106 let isCommutable = IsComm;
1107 let hasSideEffects = HasSideEffects;
1108 let usesCustomInserter = UsesCustomInserter;
1111 // Pseudo multiply add/sub instruction with explicit accumulator register
1113 class MAddSubPseudo<Instruction RealInst, SDPatternOperator OpNode,
1114 InstrItinClass itin>
1115 : PseudoSE<(outs ACC64:$ac),
1116 (ins GPR32Opnd:$rs, GPR32Opnd:$rt, ACC64:$acin),
1118 (OpNode GPR32Opnd:$rs, GPR32Opnd:$rt, ACC64:$acin))],
1120 PseudoInstExpansion<(RealInst GPR32Opnd:$rs, GPR32Opnd:$rt)> {
1121 string Constraints = "$acin = $ac";
1124 class Div<string opstr, InstrItinClass itin, RegisterOperand RO,
1125 list<Register> DefRegs> :
1126 InstSE<(outs), (ins RO:$rs, RO:$rt), !strconcat(opstr, "\t$$zero, $rs, $rt"),
1127 [], itin, FrmR, opstr> {
1132 class PseudoMFLOHI<RegisterClass DstRC, RegisterClass SrcRC, SDNode OpNode>
1133 : PseudoSE<(outs DstRC:$rd), (ins SrcRC:$hilo),
1134 [(set DstRC:$rd, (OpNode SrcRC:$hilo))], II_MFHI_MFLO>;
1136 class MoveFromLOHI<string opstr, RegisterOperand RO, Register UseReg>:
1137 InstSE<(outs RO:$rd), (ins), !strconcat(opstr, "\t$rd"), [], II_MFHI_MFLO,
1139 let Uses = [UseReg];
1140 let hasSideEffects = 0;
1143 class PseudoMTLOHI<RegisterClass DstRC, RegisterClass SrcRC>
1144 : PseudoSE<(outs DstRC:$lohi), (ins SrcRC:$lo, SrcRC:$hi),
1145 [(set DstRC:$lohi, (MipsMTLOHI SrcRC:$lo, SrcRC:$hi))],
1148 class MoveToLOHI<string opstr, RegisterOperand RO, list<Register> DefRegs>:
1149 InstSE<(outs), (ins RO:$rs), !strconcat(opstr, "\t$rs"), [], II_MTHI_MTLO,
1152 let hasSideEffects = 0;
1155 class EffectiveAddress<string opstr, RegisterOperand RO> :
1156 InstSE<(outs RO:$rt), (ins mem_ea:$addr), !strconcat(opstr, "\t$rt, $addr"),
1157 [(set RO:$rt, addr:$addr)], NoItinerary, FrmI,
1158 !strconcat(opstr, "_lea")> {
1159 let isCodeGenOnly = 1;
1160 let DecoderMethod = "DecodeMem";
1163 // Count Leading Ones/Zeros in Word
1164 class CountLeading0<string opstr, RegisterOperand RO>:
1165 InstSE<(outs RO:$rd), (ins RO:$rs), !strconcat(opstr, "\t$rd, $rs"),
1166 [(set RO:$rd, (ctlz RO:$rs))], II_CLZ, FrmR, opstr>;
1168 class CountLeading1<string opstr, RegisterOperand RO>:
1169 InstSE<(outs RO:$rd), (ins RO:$rs), !strconcat(opstr, "\t$rd, $rs"),
1170 [(set RO:$rd, (ctlz (not RO:$rs)))], II_CLO, FrmR, opstr>;
1172 // Sign Extend in Register.
1173 class SignExtInReg<string opstr, ValueType vt, RegisterOperand RO,
1174 InstrItinClass itin> :
1175 InstSE<(outs RO:$rd), (ins RO:$rt), !strconcat(opstr, "\t$rd, $rt"),
1176 [(set RO:$rd, (sext_inreg RO:$rt, vt))], itin, FrmR, opstr>;
1179 class SubwordSwap<string opstr, RegisterOperand RO,
1180 InstrItinClass itin = NoItinerary>:
1181 InstSE<(outs RO:$rd), (ins RO:$rt), !strconcat(opstr, "\t$rd, $rt"), [], itin,
1183 let hasSideEffects = 0;
1187 class ReadHardware<RegisterOperand CPURegOperand, RegisterOperand RO> :
1188 InstSE<(outs CPURegOperand:$rt), (ins RO:$rd), "rdhwr\t$rt, $rd", [],
1189 II_RDHWR, FrmR, "rdhwr">;
1192 class ExtBase<string opstr, RegisterOperand RO, Operand PosOpnd,
1193 SDPatternOperator Op = null_frag>:
1194 InstSE<(outs RO:$rt), (ins RO:$rs, PosOpnd:$pos, size_ext:$size),
1195 !strconcat(opstr, " $rt, $rs, $pos, $size"),
1196 [(set RO:$rt, (Op RO:$rs, imm:$pos, imm:$size))], II_EXT,
1197 FrmR, opstr>, ISA_MIPS32R2;
1199 class InsBase<string opstr, RegisterOperand RO, Operand PosOpnd,
1200 SDPatternOperator Op = null_frag>:
1201 InstSE<(outs RO:$rt), (ins RO:$rs, PosOpnd:$pos, size_ins:$size, RO:$src),
1202 !strconcat(opstr, " $rt, $rs, $pos, $size"),
1203 [(set RO:$rt, (Op RO:$rs, imm:$pos, imm:$size, RO:$src))],
1204 II_INS, FrmR, opstr>, ISA_MIPS32R2 {
1205 let Constraints = "$src = $rt";
1208 // Atomic instructions with 2 source operands (ATOMIC_SWAP & ATOMIC_LOAD_*).
1209 class Atomic2Ops<PatFrag Op, RegisterClass DRC> :
1210 PseudoSE<(outs DRC:$dst), (ins PtrRC:$ptr, DRC:$incr),
1211 [(set DRC:$dst, (Op iPTR:$ptr, DRC:$incr))]>;
1213 // Atomic Compare & Swap.
1214 class AtomicCmpSwap<PatFrag Op, RegisterClass DRC> :
1215 PseudoSE<(outs DRC:$dst), (ins PtrRC:$ptr, DRC:$cmp, DRC:$swap),
1216 [(set DRC:$dst, (Op iPTR:$ptr, DRC:$cmp, DRC:$swap))]>;
1218 class LLBase<string opstr, RegisterOperand RO> :
1219 InstSE<(outs RO:$rt), (ins mem:$addr), !strconcat(opstr, "\t$rt, $addr"),
1220 [], NoItinerary, FrmI> {
1221 let DecoderMethod = "DecodeMem";
1225 class SCBase<string opstr, RegisterOperand RO> :
1226 InstSE<(outs RO:$dst), (ins RO:$rt, mem:$addr),
1227 !strconcat(opstr, "\t$rt, $addr"), [], NoItinerary, FrmI> {
1228 let DecoderMethod = "DecodeMem";
1230 let Constraints = "$rt = $dst";
1233 class MFC3OP<string asmstr, RegisterOperand RO, RegisterOperand RD> :
1234 InstSE<(outs RO:$rt), (ins RD:$rd, uimm16:$sel),
1235 !strconcat(asmstr, "\t$rt, $rd, $sel"), [], NoItinerary, FrmFR>;
1237 class MTC3OP<string asmstr, RegisterOperand RO, RegisterOperand RD> :
1238 InstSE<(outs RO:$rd), (ins RD:$rt, uimm16:$sel),
1239 !strconcat(asmstr, "\t$rt, $rd, $sel"), [], NoItinerary, FrmFR>;
1241 class TrapBase<Instruction RealInst>
1242 : PseudoSE<(outs), (ins), [(trap)], NoItinerary>,
1243 PseudoInstExpansion<(RealInst 0, 0)> {
1245 let isTerminator = 1;
1246 let isCodeGenOnly = 1;
1249 //===----------------------------------------------------------------------===//
1250 // Pseudo instructions
1251 //===----------------------------------------------------------------------===//
1254 let isReturn=1, isTerminator=1, hasDelaySlot=1, isBarrier=1, hasCtrlDep=1 in
1255 def RetRA : PseudoSE<(outs), (ins), [(MipsRet)]>;
1257 let isReturn=1, isTerminator=1, isBarrier=1, hasCtrlDep=1, hasSideEffects=1 in
1258 def ERet : PseudoSE<(outs), (ins), [(MipsERet)]>;
1260 let Defs = [SP], Uses = [SP], hasSideEffects = 1 in {
1261 def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins i32imm:$amt),
1262 [(callseq_start timm:$amt)]>;
1263 def ADJCALLSTACKUP : MipsPseudo<(outs), (ins i32imm:$amt1, i32imm:$amt2),
1264 [(callseq_end timm:$amt1, timm:$amt2)]>;
1267 let usesCustomInserter = 1 in {
1268 def ATOMIC_LOAD_ADD_I8 : Atomic2Ops<atomic_load_add_8, GPR32>;
1269 def ATOMIC_LOAD_ADD_I16 : Atomic2Ops<atomic_load_add_16, GPR32>;
1270 def ATOMIC_LOAD_ADD_I32 : Atomic2Ops<atomic_load_add_32, GPR32>;
1271 def ATOMIC_LOAD_SUB_I8 : Atomic2Ops<atomic_load_sub_8, GPR32>;
1272 def ATOMIC_LOAD_SUB_I16 : Atomic2Ops<atomic_load_sub_16, GPR32>;
1273 def ATOMIC_LOAD_SUB_I32 : Atomic2Ops<atomic_load_sub_32, GPR32>;
1274 def ATOMIC_LOAD_AND_I8 : Atomic2Ops<atomic_load_and_8, GPR32>;
1275 def ATOMIC_LOAD_AND_I16 : Atomic2Ops<atomic_load_and_16, GPR32>;
1276 def ATOMIC_LOAD_AND_I32 : Atomic2Ops<atomic_load_and_32, GPR32>;
1277 def ATOMIC_LOAD_OR_I8 : Atomic2Ops<atomic_load_or_8, GPR32>;
1278 def ATOMIC_LOAD_OR_I16 : Atomic2Ops<atomic_load_or_16, GPR32>;
1279 def ATOMIC_LOAD_OR_I32 : Atomic2Ops<atomic_load_or_32, GPR32>;
1280 def ATOMIC_LOAD_XOR_I8 : Atomic2Ops<atomic_load_xor_8, GPR32>;
1281 def ATOMIC_LOAD_XOR_I16 : Atomic2Ops<atomic_load_xor_16, GPR32>;
1282 def ATOMIC_LOAD_XOR_I32 : Atomic2Ops<atomic_load_xor_32, GPR32>;
1283 def ATOMIC_LOAD_NAND_I8 : Atomic2Ops<atomic_load_nand_8, GPR32>;
1284 def ATOMIC_LOAD_NAND_I16 : Atomic2Ops<atomic_load_nand_16, GPR32>;
1285 def ATOMIC_LOAD_NAND_I32 : Atomic2Ops<atomic_load_nand_32, GPR32>;
1287 def ATOMIC_SWAP_I8 : Atomic2Ops<atomic_swap_8, GPR32>;
1288 def ATOMIC_SWAP_I16 : Atomic2Ops<atomic_swap_16, GPR32>;
1289 def ATOMIC_SWAP_I32 : Atomic2Ops<atomic_swap_32, GPR32>;
1291 def ATOMIC_CMP_SWAP_I8 : AtomicCmpSwap<atomic_cmp_swap_8, GPR32>;
1292 def ATOMIC_CMP_SWAP_I16 : AtomicCmpSwap<atomic_cmp_swap_16, GPR32>;
1293 def ATOMIC_CMP_SWAP_I32 : AtomicCmpSwap<atomic_cmp_swap_32, GPR32>;
1296 /// Pseudo instructions for loading and storing accumulator registers.
1297 let isPseudo = 1, isCodeGenOnly = 1 in {
1298 def LOAD_ACC64 : Load<"", ACC64>;
1299 def STORE_ACC64 : Store<"", ACC64>;
1302 // We need these two pseudo instructions to avoid offset calculation for long
1303 // branches. See the comment in file MipsLongBranch.cpp for detailed
1306 // Expands to: lui $dst, %hi($tgt - $baltgt)
1307 def LONG_BRANCH_LUi : PseudoSE<(outs GPR32Opnd:$dst),
1308 (ins brtarget:$tgt, brtarget:$baltgt), []>;
1310 // Expands to: addiu $dst, $src, %lo($tgt - $baltgt)
1311 def LONG_BRANCH_ADDiu : PseudoSE<(outs GPR32Opnd:$dst),
1312 (ins GPR32Opnd:$src, brtarget:$tgt, brtarget:$baltgt), []>;
1314 //===----------------------------------------------------------------------===//
1315 // Instruction definition
1316 //===----------------------------------------------------------------------===//
1317 //===----------------------------------------------------------------------===//
1318 // MipsI Instructions
1319 //===----------------------------------------------------------------------===//
1321 /// Arithmetic Instructions (ALU Immediate)
1322 let AdditionalPredicates = [NotInMicroMips] in {
1323 def ADDiu : MMRel, StdMMR6Rel, ArithLogicI<"addiu", simm16, GPR32Opnd,
1324 II_ADDIU, immSExt16, add>,
1325 ADDI_FM<0x9>, IsAsCheapAsAMove;
1327 def ADDi : MMRel, ArithLogicI<"addi", simm16, GPR32Opnd>, ADDI_FM<0x8>,
1328 ISA_MIPS1_NOT_32R6_64R6;
1329 def SLTi : MMRel, SetCC_I<"slti", setlt, simm16, immSExt16, GPR32Opnd>,
1331 def SLTiu : MMRel, SetCC_I<"sltiu", setult, simm16, immSExt16, GPR32Opnd>,
1333 let AdditionalPredicates = [NotInMicroMips] in {
1334 def ANDi : MMRel, StdMMR6Rel,
1335 ArithLogicI<"andi", uimm16, GPR32Opnd, II_ANDI, immZExt16, and>,
1338 def ORi : MMRel, StdMMR6Rel,
1339 ArithLogicI<"ori", uimm16, GPR32Opnd, II_ORI, immZExt16, or>,
1341 def XORi : MMRel, StdMMR6Rel,
1342 ArithLogicI<"xori", uimm16, GPR32Opnd, II_XORI, immZExt16, xor>,
1344 def LUi : MMRel, LoadUpper<"lui", GPR32Opnd, uimm16>, LUI_FM;
1345 let AdditionalPredicates = [NotInMicroMips] in {
1346 /// Arithmetic Instructions (3-Operand, R-Type)
1347 def ADDu : MMRel, StdMMR6Rel, ArithLogicR<"addu", GPR32Opnd, 1, II_ADDU, add>,
1349 def SUBu : MMRel, ArithLogicR<"subu", GPR32Opnd, 0, II_SUBU, sub>,
1352 let Defs = [HI0, LO0] in
1353 def MUL : MMRel, ArithLogicR<"mul", GPR32Opnd, 1, II_MUL, mul>,
1354 ADD_FM<0x1c, 2>, ISA_MIPS32_NOT_32R6_64R6;
1355 def ADD : MMRel, StdMMR6Rel, ArithLogicR<"add", GPR32Opnd>, ADD_FM<0, 0x20>;
1356 def SUB : MMRel, ArithLogicR<"sub", GPR32Opnd>, ADD_FM<0, 0x22>;
1357 def SLT : MMRel, SetCC_R<"slt", setlt, GPR32Opnd>, ADD_FM<0, 0x2a>;
1358 def SLTu : MMRel, SetCC_R<"sltu", setult, GPR32Opnd>, ADD_FM<0, 0x2b>;
1359 let AdditionalPredicates = [NotInMicroMips] in {
1360 def AND : MMRel, StdMMR6Rel, ArithLogicR<"and", GPR32Opnd, 1, II_AND, and>,
1362 def OR : MMRel, StdMMR6Rel, ArithLogicR<"or", GPR32Opnd, 1, II_OR, or>,
1364 def XOR : MMRel, StdMMR6Rel, ArithLogicR<"xor", GPR32Opnd, 1, II_XOR, xor>,
1367 def NOR : MMRel, StdMMR6Rel, LogicNOR<"nor", GPR32Opnd>, ADD_FM<0, 0x27>;
1369 /// Shift Instructions
1370 let AdditionalPredicates = [NotInMicroMips] in {
1371 def SLL : MMRel, shift_rotate_imm<"sll", uimm5, GPR32Opnd, II_SLL, shl,
1372 immZExt5>, SRA_FM<0, 0>;
1373 def SRL : MMRel, shift_rotate_imm<"srl", uimm5, GPR32Opnd, II_SRL, srl,
1374 immZExt5>, SRA_FM<2, 0>;
1376 def SRA : MMRel, shift_rotate_imm<"sra", uimm5, GPR32Opnd, II_SRA, sra,
1377 immZExt5>, SRA_FM<3, 0>;
1378 def SLLV : MMRel, shift_rotate_reg<"sllv", GPR32Opnd, II_SLLV, shl>,
1380 def SRLV : MMRel, shift_rotate_reg<"srlv", GPR32Opnd, II_SRLV, srl>,
1382 def SRAV : MMRel, shift_rotate_reg<"srav", GPR32Opnd, II_SRAV, sra>,
1385 // Rotate Instructions
1386 def ROTR : MMRel, shift_rotate_imm<"rotr", uimm5, GPR32Opnd, II_ROTR, rotr,
1388 SRA_FM<2, 1>, ISA_MIPS32R2;
1389 def ROTRV : MMRel, shift_rotate_reg<"rotrv", GPR32Opnd, II_ROTRV, rotr>,
1390 SRLV_FM<6, 1>, ISA_MIPS32R2;
1392 /// Load and Store Instructions
1394 def LB : Load<"lb", GPR32Opnd, sextloadi8, II_LB>, MMRel, LW_FM<0x20>;
1395 def LBu : Load<"lbu", GPR32Opnd, zextloadi8, II_LBU, addrDefault>, MMRel,
1397 let AdditionalPredicates = [NotInMicroMips] in {
1398 def LH : LoadMemory<"lh", GPR32Opnd, mem_simm16gpr, sextloadi16, II_LH,
1399 addrDefault>, MMRel, LW_FM<0x21>;
1400 def LHu : LoadMemory<"lhu", GPR32Opnd, mem_simm16gpr, zextloadi16, II_LHU>,
1403 let AdditionalPredicates = [NotInMicroMips] in {
1404 def LW : StdMMR6Rel, Load<"lw", GPR32Opnd, load, II_LW, addrDefault>, MMRel,
1407 def SB : StdMMR6Rel, Store<"sb", GPR32Opnd, truncstorei8, II_SB>, MMRel,
1409 def SH : Store<"sh", GPR32Opnd, truncstorei16, II_SH>, MMRel, LW_FM<0x29>;
1410 let AdditionalPredicates = [NotInMicroMips] in {
1411 def SW : Store<"sw", GPR32Opnd, store, II_SW>, MMRel, LW_FM<0x2b>;
1414 /// load/store left/right
1415 let EncodingPredicates = []<Predicate>, // FIXME: Lack of HasStdEnc is probably a bug
1416 AdditionalPredicates = [NotInMicroMips] in {
1417 def LWL : LoadLeftRight<"lwl", MipsLWL, GPR32Opnd, II_LWL>, LW_FM<0x22>,
1418 ISA_MIPS1_NOT_32R6_64R6;
1419 def LWR : LoadLeftRight<"lwr", MipsLWR, GPR32Opnd, II_LWR>, LW_FM<0x26>,
1420 ISA_MIPS1_NOT_32R6_64R6;
1421 def SWL : StoreLeftRight<"swl", MipsSWL, GPR32Opnd, II_SWL>, LW_FM<0x2a>,
1422 ISA_MIPS1_NOT_32R6_64R6;
1423 def SWR : StoreLeftRight<"swr", MipsSWR, GPR32Opnd, II_SWR>, LW_FM<0x2e>,
1424 ISA_MIPS1_NOT_32R6_64R6;
1427 let AdditionalPredicates = [NotInMicroMips] in {
1428 // COP2 Memory Instructions
1429 def LWC2 : LW_FT2<"lwc2", COP2Opnd, NoItinerary, load>, LW_FM<0x32>,
1430 ISA_MIPS1_NOT_32R6_64R6;
1431 def SWC2 : SW_FT2<"swc2", COP2Opnd, NoItinerary, store>, LW_FM<0x3a>,
1432 ISA_MIPS1_NOT_32R6_64R6;
1433 def LDC2 : LW_FT2<"ldc2", COP2Opnd, NoItinerary, load>, LW_FM<0x36>,
1434 ISA_MIPS2_NOT_32R6_64R6;
1435 def SDC2 : SW_FT2<"sdc2", COP2Opnd, NoItinerary, store>, LW_FM<0x3e>,
1436 ISA_MIPS2_NOT_32R6_64R6;
1438 // COP3 Memory Instructions
1439 let DecoderNamespace = "COP3_" in {
1440 def LWC3 : LW_FT3<"lwc3", COP3Opnd, NoItinerary, load>, LW_FM<0x33>;
1441 def SWC3 : SW_FT3<"swc3", COP3Opnd, NoItinerary, store>, LW_FM<0x3b>;
1442 def LDC3 : LW_FT3<"ldc3", COP3Opnd, NoItinerary, load>, LW_FM<0x37>,
1444 def SDC3 : SW_FT3<"sdc3", COP3Opnd, NoItinerary, store>, LW_FM<0x3f>,
1449 def SYNC : MMRel, StdMMR6Rel, SYNC_FT<"sync">, SYNC_FM, ISA_MIPS32;
1450 def SYNCI : MMRel, StdMMR6Rel, SYNCI_FT<"synci">, SYNCI_FM, ISA_MIPS32R2;
1452 let AdditionalPredicates = [NotInMicroMips] in {
1453 def TEQ : MMRel, TEQ_FT<"teq", GPR32Opnd>, TEQ_FM<0x34>, ISA_MIPS2;
1454 def TGE : MMRel, TEQ_FT<"tge", GPR32Opnd>, TEQ_FM<0x30>, ISA_MIPS2;
1455 def TGEU : MMRel, TEQ_FT<"tgeu", GPR32Opnd>, TEQ_FM<0x31>, ISA_MIPS2;
1456 def TLT : MMRel, TEQ_FT<"tlt", GPR32Opnd>, TEQ_FM<0x32>, ISA_MIPS2;
1457 def TLTU : MMRel, TEQ_FT<"tltu", GPR32Opnd>, TEQ_FM<0x33>, ISA_MIPS2;
1458 def TNE : MMRel, TEQ_FT<"tne", GPR32Opnd>, TEQ_FM<0x36>, ISA_MIPS2;
1461 def TEQI : MMRel, TEQI_FT<"teqi", GPR32Opnd>, TEQI_FM<0xc>,
1462 ISA_MIPS2_NOT_32R6_64R6;
1463 def TGEI : MMRel, TEQI_FT<"tgei", GPR32Opnd>, TEQI_FM<0x8>,
1464 ISA_MIPS2_NOT_32R6_64R6;
1465 def TGEIU : MMRel, TEQI_FT<"tgeiu", GPR32Opnd>, TEQI_FM<0x9>,
1466 ISA_MIPS2_NOT_32R6_64R6;
1467 def TLTI : MMRel, TEQI_FT<"tlti", GPR32Opnd>, TEQI_FM<0xa>,
1468 ISA_MIPS2_NOT_32R6_64R6;
1469 def TTLTIU : MMRel, TEQI_FT<"tltiu", GPR32Opnd>, TEQI_FM<0xb>,
1470 ISA_MIPS2_NOT_32R6_64R6;
1471 def TNEI : MMRel, TEQI_FT<"tnei", GPR32Opnd>, TEQI_FM<0xe>,
1472 ISA_MIPS2_NOT_32R6_64R6;
1474 let AdditionalPredicates = [NotInMicroMips] in {
1475 def BREAK : MMRel, StdMMR6Rel, BRK_FT<"break">, BRK_FM<0xd>;
1477 def SYSCALL : MMRel, SYS_FT<"syscall">, SYS_FM<0xc>;
1478 def TRAP : TrapBase<BREAK>;
1479 def SDBBP : MMRel, SYS_FT<"sdbbp">, SDBBP_FM, ISA_MIPS32_NOT_32R6_64R6;
1481 let AdditionalPredicates = [NotInMicroMips] in {
1482 def ERET : MMRel, ER_FT<"eret">, ER_FM<0x18, 0x0>, INSN_MIPS3_32;
1483 def ERETNC : MMRel, ER_FT<"eretnc">, ER_FM<0x18, 0x1>, ISA_MIPS32R5;
1485 def DERET : MMRel, ER_FT<"deret">, ER_FM<0x1f, 0x0>, ISA_MIPS32;
1487 let AdditionalPredicates = [NotInMicroMips] in {
1488 def EI : MMRel, StdMMR6Rel, DEI_FT<"ei", GPR32Opnd>, EI_FM<1>, ISA_MIPS32R2;
1490 def DI : MMRel, DEI_FT<"di", GPR32Opnd>, EI_FM<0>, ISA_MIPS32R2;
1492 let EncodingPredicates = []<Predicate>, // FIXME: Lack of HasStdEnc is probably a bug
1493 AdditionalPredicates = [NotInMicroMips] in {
1494 def WAIT : WAIT_FT<"wait">, WAIT_FM;
1496 /// Load-linked, Store-conditional
1497 def LL : LLBase<"ll", GPR32Opnd>, LW_FM<0x30>, ISA_MIPS2_NOT_32R6_64R6;
1498 def SC : SCBase<"sc", GPR32Opnd>, LW_FM<0x38>, ISA_MIPS2_NOT_32R6_64R6;
1501 /// Jump and Branch Instructions
1502 def J : MMRel, JumpFJ<jmptarget, "j", br, bb, "j">, FJ<2>,
1503 AdditionalRequires<[RelocStatic]>, IsBranch;
1504 def JR : MMRel, IndirectBranch<"jr", GPR32Opnd>, MTLO_FM<8>;
1505 def BEQ : MMRel, CBranch<"beq", brtarget, seteq, GPR32Opnd>, BEQ_FM<4>;
1506 def BEQL : MMRel, CBranch<"beql", brtarget, seteq, GPR32Opnd, 0>,
1507 BEQ_FM<20>, ISA_MIPS2_NOT_32R6_64R6;
1508 def BNE : MMRel, CBranch<"bne", brtarget, setne, GPR32Opnd>, BEQ_FM<5>;
1509 def BNEL : MMRel, CBranch<"bnel", brtarget, setne, GPR32Opnd, 0>,
1510 BEQ_FM<21>, ISA_MIPS2_NOT_32R6_64R6;
1511 def BGEZ : MMRel, CBranchZero<"bgez", brtarget, setge, GPR32Opnd>,
1513 def BGEZL : MMRel, CBranchZero<"bgezl", brtarget, setge, GPR32Opnd, 0>,
1514 BGEZ_FM<1, 3>, ISA_MIPS2_NOT_32R6_64R6;
1515 def BGTZ : MMRel, CBranchZero<"bgtz", brtarget, setgt, GPR32Opnd>,
1517 def BGTZL : MMRel, CBranchZero<"bgtzl", brtarget, setgt, GPR32Opnd, 0>,
1518 BGEZ_FM<23, 0>, ISA_MIPS2_NOT_32R6_64R6;
1519 def BLEZ : MMRel, CBranchZero<"blez", brtarget, setle, GPR32Opnd>,
1521 def BLEZL : MMRel, CBranchZero<"blezl", brtarget, setle, GPR32Opnd, 0>,
1522 BGEZ_FM<22, 0>, ISA_MIPS2_NOT_32R6_64R6;
1523 def BLTZ : MMRel, CBranchZero<"bltz", brtarget, setlt, GPR32Opnd>,
1525 def BLTZL : MMRel, CBranchZero<"bltzl", brtarget, setlt, GPR32Opnd, 0>,
1526 BGEZ_FM<1, 2>, ISA_MIPS2_NOT_32R6_64R6;
1527 def B : UncondBranch<BEQ>;
1529 def JAL : MMRel, JumpLink<"jal", calltarget>, FJ<3>;
1530 let AdditionalPredicates = [NotInMicroMips] in {
1531 def JALR : JumpLinkReg<"jalr", GPR32Opnd>, JALR_FM;
1532 def JALRPseudo : JumpLinkRegPseudo<GPR32Opnd, JALR, RA>;
1535 def JALX : MMRel, JumpLink<"jalx", calltarget>, FJ<0x1D>,
1536 ISA_MIPS32_NOT_32R6_64R6;
1537 def BGEZAL : MMRel, BGEZAL_FT<"bgezal", brtarget, GPR32Opnd>, BGEZAL_FM<0x11>,
1538 ISA_MIPS1_NOT_32R6_64R6;
1539 def BGEZALL : MMRel, BGEZAL_FT<"bgezall", brtarget, GPR32Opnd, 0>,
1540 BGEZAL_FM<0x13>, ISA_MIPS2_NOT_32R6_64R6;
1541 def BLTZAL : MMRel, BGEZAL_FT<"bltzal", brtarget, GPR32Opnd>, BGEZAL_FM<0x10>,
1542 ISA_MIPS1_NOT_32R6_64R6;
1543 def BLTZALL : MMRel, BGEZAL_FT<"bltzall", brtarget, GPR32Opnd, 0>,
1544 BGEZAL_FM<0x12>, ISA_MIPS2_NOT_32R6_64R6;
1545 def BAL_BR : BAL_BR_Pseudo<BGEZAL>;
1546 def TAILCALL : TailCall<J>;
1547 def TAILCALL_R : TailCallReg<GPR32Opnd, JR>;
1549 // Indirect branches are matched as PseudoIndirectBranch/PseudoIndirectBranch64
1550 // then are expanded to JR, JR64, JALR, or JALR64 depending on the ISA.
1551 class PseudoIndirectBranchBase<RegisterOperand RO> :
1552 MipsPseudo<(outs), (ins RO:$rs), [(brind RO:$rs)],
1553 II_IndirectBranchPseudo> {
1556 let hasDelaySlot = 1;
1558 let isIndirectBranch = 1;
1561 def PseudoIndirectBranch : PseudoIndirectBranchBase<GPR32Opnd>;
1563 // Return instructions are matched as a RetRA instruction, then are expanded
1564 // into PseudoReturn/PseudoReturn64 after register allocation. Finally,
1565 // MipsAsmPrinter expands this into JR, JR64, JALR, or JALR64 depending on the
1567 class PseudoReturnBase<RegisterOperand RO> : MipsPseudo<(outs), (ins RO:$rs),
1568 [], II_ReturnPseudo> {
1569 let isTerminator = 1;
1571 let hasDelaySlot = 1;
1573 let isCodeGenOnly = 1;
1575 let hasExtraSrcRegAllocReq = 1;
1578 def PseudoReturn : PseudoReturnBase<GPR32Opnd>;
1580 // Exception handling related node and instructions.
1581 // The conversion sequence is:
1582 // ISD::EH_RETURN -> MipsISD::EH_RETURN ->
1583 // MIPSeh_return -> (stack change + indirect branch)
1585 // MIPSeh_return takes the place of regular return instruction
1586 // but takes two arguments (V1, V0) which are used for storing
1587 // the offset and return address respectively.
1588 def SDT_MipsEHRET : SDTypeProfile<0, 2, [SDTCisInt<0>, SDTCisPtrTy<1>]>;
1590 def MIPSehret : SDNode<"MipsISD::EH_RETURN", SDT_MipsEHRET,
1591 [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
1593 let Uses = [V0, V1], isTerminator = 1, isReturn = 1, isBarrier = 1 in {
1594 def MIPSeh_return32 : MipsPseudo<(outs), (ins GPR32:$spoff, GPR32:$dst),
1595 [(MIPSehret GPR32:$spoff, GPR32:$dst)]>;
1596 def MIPSeh_return64 : MipsPseudo<(outs), (ins GPR64:$spoff,
1598 [(MIPSehret GPR64:$spoff, GPR64:$dst)]>;
1601 /// Multiply and Divide Instructions.
1602 def MULT : MMRel, Mult<"mult", II_MULT, GPR32Opnd, [HI0, LO0]>,
1603 MULT_FM<0, 0x18>, ISA_MIPS1_NOT_32R6_64R6;
1604 def MULTu : MMRel, Mult<"multu", II_MULTU, GPR32Opnd, [HI0, LO0]>,
1605 MULT_FM<0, 0x19>, ISA_MIPS1_NOT_32R6_64R6;
1606 def SDIV : MMRel, Div<"div", II_DIV, GPR32Opnd, [HI0, LO0]>,
1607 MULT_FM<0, 0x1a>, ISA_MIPS1_NOT_32R6_64R6;
1608 def UDIV : MMRel, Div<"divu", II_DIVU, GPR32Opnd, [HI0, LO0]>,
1609 MULT_FM<0, 0x1b>, ISA_MIPS1_NOT_32R6_64R6;
1611 def MTHI : MMRel, MoveToLOHI<"mthi", GPR32Opnd, [HI0]>, MTLO_FM<0x11>,
1612 ISA_MIPS1_NOT_32R6_64R6;
1613 def MTLO : MMRel, MoveToLOHI<"mtlo", GPR32Opnd, [LO0]>, MTLO_FM<0x13>,
1614 ISA_MIPS1_NOT_32R6_64R6;
1615 let EncodingPredicates = []<Predicate>, // FIXME: Lack of HasStdEnc is probably a bug
1616 AdditionalPredicates = [NotInMicroMips] in {
1617 def MFHI : MMRel, MoveFromLOHI<"mfhi", GPR32Opnd, AC0>, MFLO_FM<0x10>,
1618 ISA_MIPS1_NOT_32R6_64R6;
1619 def MFLO : MMRel, MoveFromLOHI<"mflo", GPR32Opnd, AC0>, MFLO_FM<0x12>,
1620 ISA_MIPS1_NOT_32R6_64R6;
1623 /// Sign Ext In Register Instructions.
1624 def SEB : MMRel, StdMMR6Rel, SignExtInReg<"seb", i8, GPR32Opnd, II_SEB>,
1625 SEB_FM<0x10, 0x20>, ISA_MIPS32R2;
1626 def SEH : MMRel, StdMMR6Rel, SignExtInReg<"seh", i16, GPR32Opnd, II_SEH>,
1627 SEB_FM<0x18, 0x20>, ISA_MIPS32R2;
1630 def CLZ : MMRel, CountLeading0<"clz", GPR32Opnd>, CLO_FM<0x20>,
1631 ISA_MIPS32_NOT_32R6_64R6;
1632 def CLO : MMRel, CountLeading1<"clo", GPR32Opnd>, CLO_FM<0x21>,
1633 ISA_MIPS32_NOT_32R6_64R6;
1635 let AdditionalPredicates = [NotInMicroMips] in {
1636 /// Word Swap Bytes Within Halfwords
1637 def WSBH : MMRel, SubwordSwap<"wsbh", GPR32Opnd, II_WSBH>, SEB_FM<2, 0x20>,
1642 def NOP : PseudoSE<(outs), (ins), []>, PseudoInstExpansion<(SLL ZERO, ZERO, 0)>;
1644 // FrameIndexes are legalized when they are operands from load/store
1645 // instructions. The same not happens for stack address copies, so an
1646 // add op with mem ComplexPattern is used and the stack address copy
1647 // can be matched. It's similar to Sparc LEA_ADDRi
1648 def LEA_ADDiu : MMRel, EffectiveAddress<"addiu", GPR32Opnd>, LW_FM<9>;
1651 def MADD : MMRel, MArithR<"madd", II_MADD, 1>, MULT_FM<0x1c, 0>,
1652 ISA_MIPS32_NOT_32R6_64R6;
1653 def MADDU : MMRel, MArithR<"maddu", II_MADDU, 1>, MULT_FM<0x1c, 1>,
1654 ISA_MIPS32_NOT_32R6_64R6;
1655 def MSUB : MMRel, MArithR<"msub", II_MSUB>, MULT_FM<0x1c, 4>,
1656 ISA_MIPS32_NOT_32R6_64R6;
1657 def MSUBU : MMRel, MArithR<"msubu", II_MSUBU>, MULT_FM<0x1c, 5>,
1658 ISA_MIPS32_NOT_32R6_64R6;
1660 let AdditionalPredicates = [NotDSP] in {
1661 def PseudoMULT : MultDivPseudo<MULT, ACC64, GPR32Opnd, MipsMult, II_MULT>,
1662 ISA_MIPS1_NOT_32R6_64R6;
1663 def PseudoMULTu : MultDivPseudo<MULTu, ACC64, GPR32Opnd, MipsMultu, II_MULTU>,
1664 ISA_MIPS1_NOT_32R6_64R6;
1665 def PseudoMFHI : PseudoMFLOHI<GPR32, ACC64, MipsMFHI>, ISA_MIPS1_NOT_32R6_64R6;
1666 def PseudoMFLO : PseudoMFLOHI<GPR32, ACC64, MipsMFLO>, ISA_MIPS1_NOT_32R6_64R6;
1667 def PseudoMTLOHI : PseudoMTLOHI<ACC64, GPR32>, ISA_MIPS1_NOT_32R6_64R6;
1668 def PseudoMADD : MAddSubPseudo<MADD, MipsMAdd, II_MADD>,
1669 ISA_MIPS32_NOT_32R6_64R6;
1670 def PseudoMADDU : MAddSubPseudo<MADDU, MipsMAddu, II_MADDU>,
1671 ISA_MIPS32_NOT_32R6_64R6;
1672 def PseudoMSUB : MAddSubPseudo<MSUB, MipsMSub, II_MSUB>,
1673 ISA_MIPS32_NOT_32R6_64R6;
1674 def PseudoMSUBU : MAddSubPseudo<MSUBU, MipsMSubu, II_MSUBU>,
1675 ISA_MIPS32_NOT_32R6_64R6;
1678 def PseudoSDIV : MultDivPseudo<SDIV, ACC64, GPR32Opnd, MipsDivRem, II_DIV,
1679 0, 1, 1>, ISA_MIPS1_NOT_32R6_64R6;
1680 def PseudoUDIV : MultDivPseudo<UDIV, ACC64, GPR32Opnd, MipsDivRemU, II_DIVU,
1681 0, 1, 1>, ISA_MIPS1_NOT_32R6_64R6;
1682 let AdditionalPredicates = [NotInMicroMips] in {
1683 def RDHWR : MMRel, ReadHardware<GPR32Opnd, HWRegsOpnd>, RDHWR_FM;
1685 def EXT : MMRel, ExtBase<"ext", GPR32Opnd, uimm5, MipsExt>, EXT_FM<0>;
1686 def INS : MMRel, InsBase<"ins", GPR32Opnd, uimm5, MipsIns>, EXT_FM<4>;
1688 /// Move Control Registers From/To CPU Registers
1689 def MFC0 : MFC3OP<"mfc0", GPR32Opnd, COP0Opnd>, MFC3OP_FM<0x10, 0>, ISA_MIPS32;
1690 def MTC0 : MTC3OP<"mtc0", COP0Opnd, GPR32Opnd>, MFC3OP_FM<0x10, 4>, ISA_MIPS32;
1691 def MFC2 : MFC3OP<"mfc2", GPR32Opnd, COP2Opnd>, MFC3OP_FM<0x12, 0>;
1692 def MTC2 : MTC3OP<"mtc2", COP2Opnd, GPR32Opnd>, MFC3OP_FM<0x12, 4>;
1694 class Barrier<string asmstr> : InstSE<(outs), (ins), asmstr, [], NoItinerary,
1696 def SSNOP : MMRel, StdMMR6Rel, Barrier<"ssnop">, BARRIER_FM<1>;
1697 def EHB : MMRel, Barrier<"ehb">, BARRIER_FM<3>;
1698 def PAUSE : MMRel, StdMMR6Rel, Barrier<"pause">, BARRIER_FM<5>, ISA_MIPS32R2;
1700 // JR_HB and JALR_HB are defined here using the new style naming
1701 // scheme because some of this code is shared with Mips32r6InstrInfo.td
1702 // and because of that it doesn't follow the naming convention of the
1703 // rest of the file. To avoid a mixture of old vs new style, the new
1704 // style was chosen.
1705 class JR_HB_DESC_BASE<string instr_asm, RegisterOperand GPROpnd> {
1706 dag OutOperandList = (outs);
1707 dag InOperandList = (ins GPROpnd:$rs);
1708 string AsmString = !strconcat(instr_asm, "\t$rs");
1709 list<dag> Pattern = [];
1712 class JALR_HB_DESC_BASE<string instr_asm, RegisterOperand GPROpnd> {
1713 dag OutOperandList = (outs GPROpnd:$rd);
1714 dag InOperandList = (ins GPROpnd:$rs);
1715 string AsmString = !strconcat(instr_asm, "\t$rd, $rs");
1716 list<dag> Pattern = [];
1719 class JR_HB_DESC : InstSE<(outs), (ins), "", [], NoItinerary, FrmJ>,
1720 JR_HB_DESC_BASE<"jr.hb", GPR32Opnd> {
1722 let isIndirectBranch=1;
1728 class JALR_HB_DESC : InstSE<(outs), (ins), "", [], NoItinerary, FrmJ>,
1729 JALR_HB_DESC_BASE<"jalr.hb", GPR32Opnd> {
1730 let isIndirectBranch=1;
1734 class JR_HB_ENC : JR_HB_FM<8>;
1735 class JALR_HB_ENC : JALR_HB_FM<9>;
1737 def JR_HB : JR_HB_DESC, JR_HB_ENC, ISA_MIPS32_NOT_32R6_64R6;
1738 def JALR_HB : JALR_HB_DESC, JALR_HB_ENC, ISA_MIPS32;
1740 class TLB<string asmstr> : InstSE<(outs), (ins), asmstr, [], NoItinerary,
1742 def TLBP : MMRel, TLB<"tlbp">, COP0_TLB_FM<0x08>;
1743 def TLBR : MMRel, TLB<"tlbr">, COP0_TLB_FM<0x01>;
1744 def TLBWI : MMRel, TLB<"tlbwi">, COP0_TLB_FM<0x02>;
1745 def TLBWR : MMRel, TLB<"tlbwr">, COP0_TLB_FM<0x06>;
1747 class CacheOp<string instr_asm, Operand MemOpnd> :
1748 InstSE<(outs), (ins MemOpnd:$addr, uimm5:$hint),
1749 !strconcat(instr_asm, "\t$hint, $addr"), [], NoItinerary, FrmOther,
1751 let DecoderMethod = "DecodeCacheOp";
1754 def CACHE : MMRel, CacheOp<"cache", mem>, CACHEOP_FM<0b101111>,
1755 INSN_MIPS3_32_NOT_32R6_64R6;
1756 def PREF : MMRel, CacheOp<"pref", mem>, CACHEOP_FM<0b110011>,
1757 INSN_MIPS3_32_NOT_32R6_64R6;
1759 def ROL : MipsAsmPseudoInst<(outs),
1760 (ins GPR32Opnd:$rs, GPR32Opnd:$rt, GPR32Opnd:$rd),
1761 "rol\t$rs, $rt, $rd">;
1762 def ROLImm : MipsAsmPseudoInst<(outs),
1763 (ins GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm),
1764 "rol\t$rs, $rt, $imm">;
1765 def : MipsInstAlias<"rol $rd, $rs",
1766 (ROL GPR32Opnd:$rd, GPR32Opnd:$rd, GPR32Opnd:$rs), 0>;
1767 def : MipsInstAlias<"rol $rd, $imm",
1768 (ROLImm GPR32Opnd:$rd, GPR32Opnd:$rd, simm16:$imm), 0>;
1770 def ROR : MipsAsmPseudoInst<(outs),
1771 (ins GPR32Opnd:$rs, GPR32Opnd:$rt, GPR32Opnd:$rd),
1772 "ror\t$rs, $rt, $rd">;
1773 def RORImm : MipsAsmPseudoInst<(outs),
1774 (ins GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm),
1775 "ror\t$rs, $rt, $imm">;
1776 def : MipsInstAlias<"ror $rd, $rs",
1777 (ROR GPR32Opnd:$rd, GPR32Opnd:$rd, GPR32Opnd:$rs), 0>;
1778 def : MipsInstAlias<"ror $rd, $imm",
1779 (RORImm GPR32Opnd:$rd, GPR32Opnd:$rd, simm16:$imm), 0>;
1781 def DROL : MipsAsmPseudoInst<(outs),
1782 (ins GPR32Opnd:$rs, GPR32Opnd:$rt, GPR32Opnd:$rd),
1783 "drol\t$rs, $rt, $rd">, ISA_MIPS64;
1784 def DROLImm : MipsAsmPseudoInst<(outs),
1785 (ins GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm),
1786 "drol\t$rs, $rt, $imm">, ISA_MIPS64;
1787 def : MipsInstAlias<"drol $rd, $rs",
1788 (DROL GPR32Opnd:$rd, GPR32Opnd:$rd, GPR32Opnd:$rs), 0>, ISA_MIPS64;
1789 def : MipsInstAlias<"drol $rd, $imm",
1790 (DROLImm GPR32Opnd:$rd, GPR32Opnd:$rd, simm16:$imm), 0>, ISA_MIPS64;
1792 def DROR : MipsAsmPseudoInst<(outs),
1793 (ins GPR32Opnd:$rs, GPR32Opnd:$rt, GPR32Opnd:$rd),
1794 "dror\t$rs, $rt, $rd">, ISA_MIPS64;
1795 def DRORImm : MipsAsmPseudoInst<(outs),
1796 (ins GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm),
1797 "dror\t$rs, $rt, $imm">, ISA_MIPS64;
1798 def : MipsInstAlias<"dror $rd, $rs",
1799 (DROR GPR32Opnd:$rd, GPR32Opnd:$rd, GPR32Opnd:$rs), 0>, ISA_MIPS64;
1800 def : MipsInstAlias<"dror $rd, $imm",
1801 (DRORImm GPR32Opnd:$rd, GPR32Opnd:$rd, simm16:$imm), 0>, ISA_MIPS64;
1803 //===----------------------------------------------------------------------===//
1804 // Instruction aliases
1805 //===----------------------------------------------------------------------===//
1806 def : MipsInstAlias<"move $dst, $src",
1807 (OR GPR32Opnd:$dst, GPR32Opnd:$src, ZERO), 1>,
1809 let AdditionalPredicates = [NotInMicroMips];
1811 def : MipsInstAlias<"move $dst, $src",
1812 (ADDu GPR32Opnd:$dst, GPR32Opnd:$src, ZERO), 1>,
1814 let AdditionalPredicates = [NotInMicroMips];
1816 def : MipsInstAlias<"bal $offset", (BGEZAL ZERO, brtarget:$offset), 0>,
1817 ISA_MIPS1_NOT_32R6_64R6;
1818 def : MipsInstAlias<"addu $rs, $rt, $imm",
1819 (ADDiu GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm), 0>;
1820 def : MipsInstAlias<"addu $rs, $imm",
1821 (ADDiu GPR32Opnd:$rs, GPR32Opnd:$rs, simm16:$imm), 0>;
1822 def : MipsInstAlias<"add $rs, $rt, $imm",
1823 (ADDi GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm), 0>,
1824 ISA_MIPS1_NOT_32R6_64R6;
1825 def : MipsInstAlias<"add $rs, $imm",
1826 (ADDi GPR32Opnd:$rs, GPR32Opnd:$rs, simm16:$imm), 0>,
1827 ISA_MIPS1_NOT_32R6_64R6;
1828 def : MipsInstAlias<"and $rs, $rt, $imm",
1829 (ANDi GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm), 0>;
1830 def : MipsInstAlias<"and $rs, $imm",
1831 (ANDi GPR32Opnd:$rs, GPR32Opnd:$rs, simm16:$imm), 0>;
1832 def : MipsInstAlias<"j $rs", (JR GPR32Opnd:$rs), 0>;
1833 let Predicates = [NotInMicroMips] in {
1834 def : MipsInstAlias<"jalr $rs", (JALR RA, GPR32Opnd:$rs), 0>;
1836 def : MipsInstAlias<"jalr.hb $rs", (JALR_HB RA, GPR32Opnd:$rs), 1>, ISA_MIPS32;
1837 def : MipsInstAlias<"not $rt, $rs",
1838 (NOR GPR32Opnd:$rt, GPR32Opnd:$rs, ZERO), 0>;
1839 def : MipsInstAlias<"neg $rt, $rs",
1840 (SUB GPR32Opnd:$rt, ZERO, GPR32Opnd:$rs), 1>;
1841 def : MipsInstAlias<"negu $rt",
1842 (SUBu GPR32Opnd:$rt, ZERO, GPR32Opnd:$rt), 0>;
1843 def : MipsInstAlias<"negu $rt, $rs",
1844 (SUBu GPR32Opnd:$rt, ZERO, GPR32Opnd:$rs), 1>;
1845 def : MipsInstAlias<"slt $rs, $rt, $imm",
1846 (SLTi GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm), 0>;
1847 def : MipsInstAlias<"sltu $rt, $rs, $imm",
1848 (SLTiu GPR32Opnd:$rt, GPR32Opnd:$rs, simm16:$imm), 0>;
1849 def : MipsInstAlias<"xor $rs, $rt, $imm",
1850 (XORi GPR32Opnd:$rs, GPR32Opnd:$rt, uimm16:$imm), 0>;
1851 def : MipsInstAlias<"xor $rs, $imm",
1852 (XORi GPR32Opnd:$rs, GPR32Opnd:$rs, uimm16:$imm), 0>;
1853 def : MipsInstAlias<"or $rs, $rt, $imm",
1854 (ORi GPR32Opnd:$rs, GPR32Opnd:$rt, uimm16:$imm), 0>;
1855 def : MipsInstAlias<"or $rs, $imm",
1856 (ORi GPR32Opnd:$rs, GPR32Opnd:$rs, uimm16:$imm), 0>;
1857 let AdditionalPredicates = [NotInMicroMips] in {
1858 def : MipsInstAlias<"nop", (SLL ZERO, ZERO, 0), 1>;
1860 def : MipsInstAlias<"mfc0 $rt, $rd", (MFC0 GPR32Opnd:$rt, COP0Opnd:$rd, 0), 0>;
1861 def : MipsInstAlias<"mtc0 $rt, $rd", (MTC0 COP0Opnd:$rd, GPR32Opnd:$rt, 0), 0>;
1862 def : MipsInstAlias<"mfc2 $rt, $rd", (MFC2 GPR32Opnd:$rt, COP2Opnd:$rd, 0), 0>;
1863 def : MipsInstAlias<"mtc2 $rt, $rd", (MTC2 COP2Opnd:$rd, GPR32Opnd:$rt, 0), 0>;
1864 let AdditionalPredicates = [NotInMicroMips] in {
1865 def : MipsInstAlias<"b $offset", (BEQ ZERO, ZERO, brtarget:$offset), 0>;
1867 def : MipsInstAlias<"bnez $rs,$offset",
1868 (BNE GPR32Opnd:$rs, ZERO, brtarget:$offset), 0>;
1869 def : MipsInstAlias<"bnezl $rs,$offset",
1870 (BNEL GPR32Opnd:$rs, ZERO, brtarget:$offset), 0>;
1871 def : MipsInstAlias<"beqz $rs,$offset",
1872 (BEQ GPR32Opnd:$rs, ZERO, brtarget:$offset), 0>;
1873 def : MipsInstAlias<"beqzl $rs,$offset",
1874 (BEQL GPR32Opnd:$rs, ZERO, brtarget:$offset), 0>;
1875 def : MipsInstAlias<"syscall", (SYSCALL 0), 1>;
1877 def : MipsInstAlias<"break", (BREAK 0, 0), 1>;
1878 def : MipsInstAlias<"break $imm", (BREAK uimm10:$imm, 0), 1>;
1879 let AdditionalPredicates = [NotInMicroMips] in {
1880 def : MipsInstAlias<"ei", (EI ZERO), 1>, ISA_MIPS32R2;
1882 def : MipsInstAlias<"di", (DI ZERO), 1>, ISA_MIPS32R2;
1883 let AdditionalPredicates = [NotInMicroMips] in {
1884 def : MipsInstAlias<"teq $rs, $rt",
1885 (TEQ GPR32Opnd:$rs, GPR32Opnd:$rt, 0), 1>, ISA_MIPS2;
1886 def : MipsInstAlias<"tge $rs, $rt",
1887 (TGE GPR32Opnd:$rs, GPR32Opnd:$rt, 0), 1>, ISA_MIPS2;
1888 def : MipsInstAlias<"tgeu $rs, $rt",
1889 (TGEU GPR32Opnd:$rs, GPR32Opnd:$rt, 0), 1>, ISA_MIPS2;
1890 def : MipsInstAlias<"tlt $rs, $rt",
1891 (TLT GPR32Opnd:$rs, GPR32Opnd:$rt, 0), 1>, ISA_MIPS2;
1892 def : MipsInstAlias<"tltu $rs, $rt",
1893 (TLTU GPR32Opnd:$rs, GPR32Opnd:$rt, 0), 1>, ISA_MIPS2;
1894 def : MipsInstAlias<"tne $rs, $rt",
1895 (TNE GPR32Opnd:$rs, GPR32Opnd:$rt, 0), 1>, ISA_MIPS2;
1897 def : MipsInstAlias<"sll $rd, $rt, $rs",
1898 (SLLV GPR32Opnd:$rd, GPR32Opnd:$rt, GPR32Opnd:$rs), 0>;
1899 def : MipsInstAlias<"sub, $rd, $rs, $imm",
1900 (ADDi GPR32Opnd:$rd, GPR32Opnd:$rs,
1901 InvertedImOperand:$imm), 0>, ISA_MIPS1_NOT_32R6_64R6;
1902 def : MipsInstAlias<"sub $rs, $imm",
1903 (ADDi GPR32Opnd:$rs, GPR32Opnd:$rs, InvertedImOperand:$imm),
1904 0>, ISA_MIPS1_NOT_32R6_64R6;
1905 def : MipsInstAlias<"subu, $rd, $rs, $imm",
1906 (ADDiu GPR32Opnd:$rd, GPR32Opnd:$rs,
1907 InvertedImOperand:$imm), 0>;
1908 def : MipsInstAlias<"subu $rs, $imm", (ADDiu GPR32Opnd:$rs, GPR32Opnd:$rs,
1909 InvertedImOperand:$imm), 0>;
1910 def : MipsInstAlias<"sra $rd, $rt, $rs",
1911 (SRAV GPR32Opnd:$rd, GPR32Opnd:$rt, GPR32Opnd:$rs), 0>;
1912 def : MipsInstAlias<"srl $rd, $rt, $rs",
1913 (SRLV GPR32Opnd:$rd, GPR32Opnd:$rt, GPR32Opnd:$rs), 0>;
1914 def : MipsInstAlias<"sdbbp", (SDBBP 0)>, ISA_MIPS32_NOT_32R6_64R6;
1915 def : MipsInstAlias<"sync",
1916 (SYNC 0), 1>, ISA_MIPS2;
1917 //===----------------------------------------------------------------------===//
1918 // Assembler Pseudo Instructions
1919 //===----------------------------------------------------------------------===//
1921 class LoadImmediate32<string instr_asm, Operand Od, RegisterOperand RO> :
1922 MipsAsmPseudoInst<(outs RO:$rt), (ins Od:$imm32),
1923 !strconcat(instr_asm, "\t$rt, $imm32")> ;
1924 def LoadImm32 : LoadImmediate32<"li", simm32, GPR32Opnd>;
1926 class LoadAddressFromReg32<string instr_asm, Operand MemOpnd,
1927 RegisterOperand RO> :
1928 MipsAsmPseudoInst<(outs RO:$rt), (ins MemOpnd:$addr),
1929 !strconcat(instr_asm, "\t$rt, $addr")> ;
1930 def LoadAddrReg32 : LoadAddressFromReg32<"la", mem, GPR32Opnd>;
1932 class LoadAddressFromImm32<string instr_asm, Operand Od, RegisterOperand RO> :
1933 MipsAsmPseudoInst<(outs RO:$rt), (ins Od:$imm32),
1934 !strconcat(instr_asm, "\t$rt, $imm32")> ;
1935 def LoadAddrImm32 : LoadAddressFromImm32<"la", simm32, GPR32Opnd>;
1937 def JalTwoReg : MipsAsmPseudoInst<(outs GPR32Opnd:$rd), (ins GPR32Opnd:$rs),
1939 def JalOneReg : MipsAsmPseudoInst<(outs), (ins GPR32Opnd:$rs),
1942 def NORImm : MipsAsmPseudoInst<(outs), (ins GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm),
1943 "nor\t$rs, $rt, $imm"> ;
1945 let hasDelaySlot = 1 in {
1946 def BneImm : MipsAsmPseudoInst<(outs GPR32Opnd:$rt),
1947 (ins imm64:$imm64, brtarget:$offset),
1948 "bne\t$rt, $imm64, $offset">;
1949 def BeqImm : MipsAsmPseudoInst<(outs GPR32Opnd:$rt),
1950 (ins imm64:$imm64, brtarget:$offset),
1951 "beq\t$rt, $imm64, $offset">;
1953 class CondBranchPseudo<string instr_asm> :
1954 MipsAsmPseudoInst<(outs), (ins GPR32Opnd:$rs, GPR32Opnd:$rt,
1956 !strconcat(instr_asm, "\t$rs, $rt, $offset")>;
1959 def BLT : CondBranchPseudo<"blt">;
1960 def BLE : CondBranchPseudo<"ble">;
1961 def BGE : CondBranchPseudo<"bge">;
1962 def BGT : CondBranchPseudo<"bgt">;
1963 def BLTU : CondBranchPseudo<"bltu">;
1964 def BLEU : CondBranchPseudo<"bleu">;
1965 def BGEU : CondBranchPseudo<"bgeu">;
1966 def BGTU : CondBranchPseudo<"bgtu">;
1967 def BLTL : CondBranchPseudo<"bltl">, ISA_MIPS2_NOT_32R6_64R6;
1968 def BLEL : CondBranchPseudo<"blel">, ISA_MIPS2_NOT_32R6_64R6;
1969 def BGEL : CondBranchPseudo<"bgel">, ISA_MIPS2_NOT_32R6_64R6;
1970 def BGTL : CondBranchPseudo<"bgtl">, ISA_MIPS2_NOT_32R6_64R6;
1971 def BLTUL: CondBranchPseudo<"bltul">, ISA_MIPS2_NOT_32R6_64R6;
1972 def BLEUL: CondBranchPseudo<"bleul">, ISA_MIPS2_NOT_32R6_64R6;
1973 def BGEUL: CondBranchPseudo<"bgeul">, ISA_MIPS2_NOT_32R6_64R6;
1974 def BGTUL: CondBranchPseudo<"bgtul">, ISA_MIPS2_NOT_32R6_64R6;
1976 class CondBranchImmPseudo<string instr_asm> :
1977 MipsAsmPseudoInst<(outs), (ins GPR32Opnd:$rs, imm64:$imm, brtarget:$offset),
1978 !strconcat(instr_asm, "\t$rs, $imm, $offset")>;
1980 def BLTImmMacro : CondBranchImmPseudo<"blt">;
1981 def BLEImmMacro : CondBranchImmPseudo<"ble">;
1982 def BGEImmMacro : CondBranchImmPseudo<"bge">;
1983 def BGTImmMacro : CondBranchImmPseudo<"bgt">;
1984 def BLTUImmMacro : CondBranchImmPseudo<"bltu">;
1985 def BLEUImmMacro : CondBranchImmPseudo<"bleu">;
1986 def BGEUImmMacro : CondBranchImmPseudo<"bgeu">;
1987 def BGTUImmMacro : CondBranchImmPseudo<"bgtu">;
1988 def BLTLImmMacro : CondBranchImmPseudo<"bltl">, ISA_MIPS2_NOT_32R6_64R6;
1989 def BLELImmMacro : CondBranchImmPseudo<"blel">, ISA_MIPS2_NOT_32R6_64R6;
1990 def BGELImmMacro : CondBranchImmPseudo<"bgel">, ISA_MIPS2_NOT_32R6_64R6;
1991 def BGTLImmMacro : CondBranchImmPseudo<"bgtl">, ISA_MIPS2_NOT_32R6_64R6;
1992 def BLTULImmMacro : CondBranchImmPseudo<"bltul">, ISA_MIPS2_NOT_32R6_64R6;
1993 def BLEULImmMacro : CondBranchImmPseudo<"bleul">, ISA_MIPS2_NOT_32R6_64R6;
1994 def BGEULImmMacro : CondBranchImmPseudo<"bgeul">, ISA_MIPS2_NOT_32R6_64R6;
1995 def BGTULImmMacro : CondBranchImmPseudo<"bgtul">, ISA_MIPS2_NOT_32R6_64R6;
1997 // FIXME: Predicates are removed because instructions are matched regardless of
1998 // predicates, because PredicateControl was not in the hierarchy. This was
1999 // done to emit more precise error message from expansion function.
2000 // Once the tablegen-erated errors are made better, this needs to be fixed and
2001 // predicates needs to be restored.
2003 def SDivMacro : MipsAsmPseudoInst<(outs), (ins GPR32Opnd:$rs, GPR32Opnd:$rt),
2004 "div\t$rs, $rt">; //, ISA_MIPS1_NOT_32R6_64R6;
2006 def UDivMacro : MipsAsmPseudoInst<(outs), (ins GPR32Opnd:$rs, GPR32Opnd:$rt),
2007 "divu\t$rs, $rt">; //, ISA_MIPS1_NOT_32R6_64R6;
2009 def DSDivMacro : MipsAsmPseudoInst<(outs), (ins GPR32Opnd:$rs, GPR32Opnd:$rt),
2010 "ddiv\t$rs, $rt">; //, ISA_MIPS64_NOT_64R6;
2012 def DUDivMacro : MipsAsmPseudoInst<(outs), (ins GPR32Opnd:$rs, GPR32Opnd:$rt),
2013 "ddivu\t$rs, $rt">; //, ISA_MIPS64_NOT_64R6;
2015 def Ulh : MipsAsmPseudoInst<(outs GPR32Opnd:$rt), (ins mem:$addr),
2016 "ulh\t$rt, $addr">; //, ISA_MIPS1_NOT_32R6_64R6;
2018 def Ulhu : MipsAsmPseudoInst<(outs GPR32Opnd:$rt), (ins mem:$addr),
2019 "ulhu\t$rt, $addr">; //, ISA_MIPS1_NOT_32R6_64R6;
2021 def Ulw : MipsAsmPseudoInst<(outs GPR32Opnd:$rt), (ins mem:$addr),
2022 "ulw\t$rt, $addr">; //, ISA_MIPS1_NOT_32R6_64R6;
2024 //===----------------------------------------------------------------------===//
2025 // Arbitrary patterns that map to one or more instructions
2026 //===----------------------------------------------------------------------===//
2028 // Load/store pattern templates.
2029 class LoadRegImmPat<Instruction LoadInst, ValueType ValTy, PatFrag Node> :
2030 MipsPat<(ValTy (Node addrRegImm:$a)), (LoadInst addrRegImm:$a)>;
2032 class StoreRegImmPat<Instruction StoreInst, ValueType ValTy> :
2033 MipsPat<(store ValTy:$v, addrRegImm:$a), (StoreInst ValTy:$v, addrRegImm:$a)>;
2036 let AdditionalPredicates = [NotInMicroMips] in {
2037 def : MipsPat<(i32 immSExt16:$in),
2038 (ADDiu ZERO, imm:$in)>;
2039 def : MipsPat<(i32 immZExt16:$in),
2040 (ORi ZERO, imm:$in)>;
2042 def : MipsPat<(i32 immLow16Zero:$in),
2043 (LUi (HI16 imm:$in))>;
2045 // Arbitrary immediates
2046 def : MipsPat<(i32 imm:$imm),
2047 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
2049 // Carry MipsPatterns
2050 def : MipsPat<(subc GPR32:$lhs, GPR32:$rhs),
2051 (SUBu GPR32:$lhs, GPR32:$rhs)>;
2052 let AdditionalPredicates = [NotDSP] in {
2053 def : MipsPat<(addc GPR32:$lhs, GPR32:$rhs),
2054 (ADDu GPR32:$lhs, GPR32:$rhs)>;
2055 def : MipsPat<(addc GPR32:$src, immSExt16:$imm),
2056 (ADDiu GPR32:$src, imm:$imm)>;
2059 // Support multiplication for pre-Mips32 targets that don't have
2060 // the MUL instruction.
2061 def : MipsPat<(mul GPR32:$lhs, GPR32:$rhs),
2062 (PseudoMFLO (PseudoMULT GPR32:$lhs, GPR32:$rhs))>,
2063 ISA_MIPS1_NOT_32R6_64R6;
2066 def : MipsPat<(MipsSync (i32 immz)),
2067 (SYNC 0)>, ISA_MIPS2;
2070 def : MipsPat<(MipsJmpLink (i32 tglobaladdr:$dst)),
2071 (JAL tglobaladdr:$dst)>;
2072 def : MipsPat<(MipsJmpLink (i32 texternalsym:$dst)),
2073 (JAL texternalsym:$dst)>;
2074 //def : MipsPat<(MipsJmpLink GPR32:$dst),
2075 // (JALR GPR32:$dst)>;
2078 def : MipsPat<(MipsTailCall (iPTR tglobaladdr:$dst)),
2079 (TAILCALL tglobaladdr:$dst)>;
2080 def : MipsPat<(MipsTailCall (iPTR texternalsym:$dst)),
2081 (TAILCALL texternalsym:$dst)>;
2083 def : MipsPat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
2084 def : MipsPat<(MipsHi tblockaddress:$in), (LUi tblockaddress:$in)>;
2085 def : MipsPat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
2086 def : MipsPat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
2087 def : MipsPat<(MipsHi tglobaltlsaddr:$in), (LUi tglobaltlsaddr:$in)>;
2088 def : MipsPat<(MipsHi texternalsym:$in), (LUi texternalsym:$in)>;
2090 def : MipsPat<(MipsLo tglobaladdr:$in), (ADDiu ZERO, tglobaladdr:$in)>;
2091 def : MipsPat<(MipsLo tblockaddress:$in), (ADDiu ZERO, tblockaddress:$in)>;
2092 def : MipsPat<(MipsLo tjumptable:$in), (ADDiu ZERO, tjumptable:$in)>;
2093 def : MipsPat<(MipsLo tconstpool:$in), (ADDiu ZERO, tconstpool:$in)>;
2094 def : MipsPat<(MipsLo tglobaltlsaddr:$in), (ADDiu ZERO, tglobaltlsaddr:$in)>;
2095 def : MipsPat<(MipsLo texternalsym:$in), (ADDiu ZERO, texternalsym:$in)>;
2097 def : MipsPat<(add GPR32:$hi, (MipsLo tglobaladdr:$lo)),
2098 (ADDiu GPR32:$hi, tglobaladdr:$lo)>;
2099 def : MipsPat<(add GPR32:$hi, (MipsLo tblockaddress:$lo)),
2100 (ADDiu GPR32:$hi, tblockaddress:$lo)>;
2101 def : MipsPat<(add GPR32:$hi, (MipsLo tjumptable:$lo)),
2102 (ADDiu GPR32:$hi, tjumptable:$lo)>;
2103 def : MipsPat<(add GPR32:$hi, (MipsLo tconstpool:$lo)),
2104 (ADDiu GPR32:$hi, tconstpool:$lo)>;
2105 def : MipsPat<(add GPR32:$hi, (MipsLo tglobaltlsaddr:$lo)),
2106 (ADDiu GPR32:$hi, tglobaltlsaddr:$lo)>;
2109 def : MipsPat<(add GPR32:$gp, (MipsGPRel tglobaladdr:$in)),
2110 (ADDiu GPR32:$gp, tglobaladdr:$in)>;
2111 def : MipsPat<(add GPR32:$gp, (MipsGPRel tconstpool:$in)),
2112 (ADDiu GPR32:$gp, tconstpool:$in)>;
2115 class WrapperPat<SDNode node, Instruction ADDiuOp, RegisterClass RC>:
2116 MipsPat<(MipsWrapper RC:$gp, node:$in),
2117 (ADDiuOp RC:$gp, node:$in)>;
2119 def : WrapperPat<tglobaladdr, ADDiu, GPR32>;
2120 def : WrapperPat<tconstpool, ADDiu, GPR32>;
2121 def : WrapperPat<texternalsym, ADDiu, GPR32>;
2122 def : WrapperPat<tblockaddress, ADDiu, GPR32>;
2123 def : WrapperPat<tjumptable, ADDiu, GPR32>;
2124 def : WrapperPat<tglobaltlsaddr, ADDiu, GPR32>;
2126 let AdditionalPredicates = [NotInMicroMips] in {
2127 // Mips does not have "not", so we expand our way
2128 def : MipsPat<(not GPR32:$in),
2129 (NOR GPR32Opnd:$in, ZERO)>;
2133 def : MipsPat<(i32 (extloadi1 addr:$src)), (LBu addr:$src)>;
2134 def : MipsPat<(i32 (extloadi8 addr:$src)), (LBu addr:$src)>;
2135 def : MipsPat<(i32 (extloadi16 addr:$src)), (LHu addr:$src)>;
2138 def : MipsPat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
2141 multiclass BrcondPats<RegisterClass RC, Instruction BEQOp, Instruction BNEOp,
2142 Instruction SLTOp, Instruction SLTuOp, Instruction SLTiOp,
2143 Instruction SLTiuOp, Register ZEROReg> {
2144 def : MipsPat<(brcond (i32 (setne RC:$lhs, 0)), bb:$dst),
2145 (BNEOp RC:$lhs, ZEROReg, bb:$dst)>;
2146 def : MipsPat<(brcond (i32 (seteq RC:$lhs, 0)), bb:$dst),
2147 (BEQOp RC:$lhs, ZEROReg, bb:$dst)>;
2149 def : MipsPat<(brcond (i32 (setge RC:$lhs, RC:$rhs)), bb:$dst),
2150 (BEQ (SLTOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>;
2151 def : MipsPat<(brcond (i32 (setuge RC:$lhs, RC:$rhs)), bb:$dst),
2152 (BEQ (SLTuOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>;
2153 def : MipsPat<(brcond (i32 (setge RC:$lhs, immSExt16:$rhs)), bb:$dst),
2154 (BEQ (SLTiOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
2155 def : MipsPat<(brcond (i32 (setuge RC:$lhs, immSExt16:$rhs)), bb:$dst),
2156 (BEQ (SLTiuOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
2157 def : MipsPat<(brcond (i32 (setgt RC:$lhs, immSExt16Plus1:$rhs)), bb:$dst),
2158 (BEQ (SLTiOp RC:$lhs, (Plus1 imm:$rhs)), ZERO, bb:$dst)>;
2159 def : MipsPat<(brcond (i32 (setugt RC:$lhs, immSExt16Plus1:$rhs)), bb:$dst),
2160 (BEQ (SLTiuOp RC:$lhs, (Plus1 imm:$rhs)), ZERO, bb:$dst)>;
2162 def : MipsPat<(brcond (i32 (setle RC:$lhs, RC:$rhs)), bb:$dst),
2163 (BEQ (SLTOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>;
2164 def : MipsPat<(brcond (i32 (setule RC:$lhs, RC:$rhs)), bb:$dst),
2165 (BEQ (SLTuOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>;
2167 def : MipsPat<(brcond RC:$cond, bb:$dst),
2168 (BNEOp RC:$cond, ZEROReg, bb:$dst)>;
2171 defm : BrcondPats<GPR32, BEQ, BNE, SLT, SLTu, SLTi, SLTiu, ZERO>;
2173 def : MipsPat<(brcond (i32 (setlt i32:$lhs, 1)), bb:$dst),
2174 (BLEZ i32:$lhs, bb:$dst)>;
2175 def : MipsPat<(brcond (i32 (setgt i32:$lhs, -1)), bb:$dst),
2176 (BGEZ i32:$lhs, bb:$dst)>;
2179 multiclass SeteqPats<RegisterClass RC, Instruction SLTiuOp, Instruction XOROp,
2180 Instruction SLTuOp, Register ZEROReg> {
2181 def : MipsPat<(seteq RC:$lhs, 0),
2182 (SLTiuOp RC:$lhs, 1)>;
2183 def : MipsPat<(setne RC:$lhs, 0),
2184 (SLTuOp ZEROReg, RC:$lhs)>;
2185 def : MipsPat<(seteq RC:$lhs, RC:$rhs),
2186 (SLTiuOp (XOROp RC:$lhs, RC:$rhs), 1)>;
2187 def : MipsPat<(setne RC:$lhs, RC:$rhs),
2188 (SLTuOp ZEROReg, (XOROp RC:$lhs, RC:$rhs))>;
2191 multiclass SetlePats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
2192 def : MipsPat<(setle RC:$lhs, RC:$rhs),
2193 (XORi (SLTOp RC:$rhs, RC:$lhs), 1)>;
2194 def : MipsPat<(setule RC:$lhs, RC:$rhs),
2195 (XORi (SLTuOp RC:$rhs, RC:$lhs), 1)>;
2198 multiclass SetgtPats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
2199 def : MipsPat<(setgt RC:$lhs, RC:$rhs),
2200 (SLTOp RC:$rhs, RC:$lhs)>;
2201 def : MipsPat<(setugt RC:$lhs, RC:$rhs),
2202 (SLTuOp RC:$rhs, RC:$lhs)>;
2205 multiclass SetgePats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> {
2206 def : MipsPat<(setge RC:$lhs, RC:$rhs),
2207 (XORi (SLTOp RC:$lhs, RC:$rhs), 1)>;
2208 def : MipsPat<(setuge RC:$lhs, RC:$rhs),
2209 (XORi (SLTuOp RC:$lhs, RC:$rhs), 1)>;
2212 multiclass SetgeImmPats<RegisterClass RC, Instruction SLTiOp,
2213 Instruction SLTiuOp> {
2214 def : MipsPat<(setge RC:$lhs, immSExt16:$rhs),
2215 (XORi (SLTiOp RC:$lhs, immSExt16:$rhs), 1)>;
2216 def : MipsPat<(setuge RC:$lhs, immSExt16:$rhs),
2217 (XORi (SLTiuOp RC:$lhs, immSExt16:$rhs), 1)>;
2220 defm : SeteqPats<GPR32, SLTiu, XOR, SLTu, ZERO>;
2221 defm : SetlePats<GPR32, SLT, SLTu>;
2222 defm : SetgtPats<GPR32, SLT, SLTu>;
2223 defm : SetgePats<GPR32, SLT, SLTu>;
2224 defm : SetgeImmPats<GPR32, SLTi, SLTiu>;
2227 def : MipsPat<(bswap GPR32:$rt), (ROTR (WSBH GPR32:$rt), 16)>;
2229 // Load halfword/word patterns.
2230 let AddedComplexity = 40 in {
2231 def : LoadRegImmPat<LBu, i32, zextloadi8>;
2232 def : LoadRegImmPat<LH, i32, sextloadi16>;
2233 let AdditionalPredicates = [NotInMicroMips] in {
2234 def : LoadRegImmPat<LW, i32, load>;
2238 // Atomic load patterns.
2239 def : MipsPat<(atomic_load_8 addr:$a), (LB addr:$a)>;
2240 def : MipsPat<(atomic_load_16 addr:$a), (LH addr:$a)>;
2241 def : MipsPat<(atomic_load_32 addr:$a), (LW addr:$a)>;
2243 // Atomic store patterns.
2244 def : MipsPat<(atomic_store_8 addr:$a, GPR32:$v), (SB GPR32:$v, addr:$a)>;
2245 def : MipsPat<(atomic_store_16 addr:$a, GPR32:$v), (SH GPR32:$v, addr:$a)>;
2246 def : MipsPat<(atomic_store_32 addr:$a, GPR32:$v), (SW GPR32:$v, addr:$a)>;
2248 //===----------------------------------------------------------------------===//
2249 // Floating Point Support
2250 //===----------------------------------------------------------------------===//
2252 include "MipsInstrFPU.td"
2253 include "Mips64InstrInfo.td"
2254 include "MipsCondMov.td"
2256 include "Mips32r6InstrInfo.td"
2257 include "Mips64r6InstrInfo.td"
2262 include "Mips16InstrFormats.td"
2263 include "Mips16InstrInfo.td"
2266 include "MipsDSPInstrFormats.td"
2267 include "MipsDSPInstrInfo.td"
2270 include "MipsMSAInstrFormats.td"
2271 include "MipsMSAInstrInfo.td"
2274 include "MipsEVAInstrFormats.td"
2275 include "MipsEVAInstrInfo.td"
2278 include "MicroMipsInstrFormats.td"
2279 include "MicroMipsInstrInfo.td"
2280 include "MicroMipsInstrFPU.td"
2283 include "MicroMips32r6InstrFormats.td"
2284 include "MicroMips32r6InstrInfo.td"
2287 include "MicroMips64r6InstrFormats.td"
2288 include "MicroMips64r6InstrInfo.td"
2291 include "MicroMipsDSPInstrFormats.td"
2292 include "MicroMipsDSPInstrInfo.td"