1//===- MipsInstrInfo.td - Target Description for Mips Target -*- tablegen -*-=// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file contains the Mips implementation of the TargetInstrInfo class. 11// 12//===----------------------------------------------------------------------===// 13 14 15//===----------------------------------------------------------------------===// 16// Mips profiles and nodes 17//===----------------------------------------------------------------------===// 18 19def SDT_MipsJmpLink : SDTypeProfile<0, 1, [SDTCisVT<0, iPTR>]>; 20def SDT_MipsCMov : SDTypeProfile<1, 4, [SDTCisSameAs<0, 1>, 21 SDTCisSameAs<1, 2>, 22 SDTCisSameAs<3, 4>, 23 SDTCisInt<4>]>; 24def SDT_MipsCallSeqStart : SDCallSeqStart<[SDTCisVT<0, i32>]>; 25def SDT_MipsCallSeqEnd : SDCallSeqEnd<[SDTCisVT<0, i32>, SDTCisVT<1, i32>]>; 26def SDT_MFLOHI : SDTypeProfile<1, 1, [SDTCisInt<0>, SDTCisVT<1, untyped>]>; 27def SDT_MTLOHI : SDTypeProfile<1, 2, [SDTCisVT<0, untyped>, 28 SDTCisInt<1>, SDTCisSameAs<1, 2>]>; 29def SDT_MipsMultDiv : SDTypeProfile<1, 2, [SDTCisVT<0, untyped>, SDTCisInt<1>, 30 SDTCisSameAs<1, 2>]>; 31def SDT_MipsMAddMSub : SDTypeProfile<1, 3, 32 [SDTCisVT<0, untyped>, SDTCisSameAs<0, 3>, 33 SDTCisVT<1, i32>, SDTCisSameAs<1, 2>]>; 34def SDT_MipsDivRem16 : SDTypeProfile<0, 2, [SDTCisInt<0>, SDTCisSameAs<0, 1>]>; 35 36def SDT_MipsThreadPointer : SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>; 37 38def SDT_Sync : SDTypeProfile<0, 1, [SDTCisVT<0, i32>]>; 39 40def SDT_Ext : SDTypeProfile<1, 3, [SDTCisInt<0>, SDTCisSameAs<0, 1>, 41 SDTCisVT<2, i32>, SDTCisSameAs<2, 3>]>; 42def SDT_Ins : SDTypeProfile<1, 4, [SDTCisInt<0>, SDTCisSameAs<0, 1>, 43 SDTCisVT<2, i32>, SDTCisSameAs<2, 3>, 44 SDTCisSameAs<0, 4>]>; 45 46def SDTMipsLoadLR : SDTypeProfile<1, 2, 47 [SDTCisInt<0>, SDTCisPtrTy<1>, 48 SDTCisSameAs<0, 2>]>; 49 50// Call 51def MipsJmpLink : SDNode<"MipsISD::JmpLink",SDT_MipsJmpLink, 52 [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue, 53 SDNPVariadic]>; 54 55// Tail call 56def MipsTailCall : SDNode<"MipsISD::TailCall", SDT_MipsJmpLink, 57 [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>; 58 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) 62def MipsHi : SDNode<"MipsISD::Hi", SDTIntUnaryOp>; 63def MipsLo : SDNode<"MipsISD::Lo", SDTIntUnaryOp>; 64def MipsGPRel : SDNode<"MipsISD::GPRel", SDTIntUnaryOp>; 65 66// TlsGd node is used to handle General Dynamic TLS 67def MipsTlsGd : SDNode<"MipsISD::TlsGd", SDTIntUnaryOp>; 68 69// TprelHi and TprelLo nodes are used to handle Local Exec TLS 70def MipsTprelHi : SDNode<"MipsISD::TprelHi", SDTIntUnaryOp>; 71def MipsTprelLo : SDNode<"MipsISD::TprelLo", SDTIntUnaryOp>; 72 73// Thread pointer 74def MipsThreadPointer: SDNode<"MipsISD::ThreadPointer", SDT_MipsThreadPointer>; 75 76// Return 77def MipsRet : SDNode<"MipsISD::Ret", SDTNone, 78 [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>; 79 80def MipsERet : SDNode<"MipsISD::ERet", SDTNone, 81 [SDNPHasChain, SDNPOptInGlue, SDNPSideEffect]>; 82 83// These are target-independent nodes, but have target-specific formats. 84def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_MipsCallSeqStart, 85 [SDNPHasChain, SDNPSideEffect, SDNPOutGlue]>; 86def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_MipsCallSeqEnd, 87 [SDNPHasChain, SDNPSideEffect, 88 SDNPOptInGlue, SDNPOutGlue]>; 89 90// Nodes used to extract LO/HI registers. 91def MipsMFHI : SDNode<"MipsISD::MFHI", SDT_MFLOHI>; 92def MipsMFLO : SDNode<"MipsISD::MFLO", SDT_MFLOHI>; 93 94// Node used to insert 32-bit integers to LOHI register pair. 95def MipsMTLOHI : SDNode<"MipsISD::MTLOHI", SDT_MTLOHI>; 96 97// Mult nodes. 98def MipsMult : SDNode<"MipsISD::Mult", SDT_MipsMultDiv>; 99def MipsMultu : SDNode<"MipsISD::Multu", SDT_MipsMultDiv>; 100 101// MAdd*/MSub* nodes 102def MipsMAdd : SDNode<"MipsISD::MAdd", SDT_MipsMAddMSub>; 103def MipsMAddu : SDNode<"MipsISD::MAddu", SDT_MipsMAddMSub>; 104def MipsMSub : SDNode<"MipsISD::MSub", SDT_MipsMAddMSub>; 105def MipsMSubu : SDNode<"MipsISD::MSubu", SDT_MipsMAddMSub>; 106 107// DivRem(u) nodes 108def MipsDivRem : SDNode<"MipsISD::DivRem", SDT_MipsMultDiv>; 109def MipsDivRemU : SDNode<"MipsISD::DivRemU", SDT_MipsMultDiv>; 110def MipsDivRem16 : SDNode<"MipsISD::DivRem16", SDT_MipsDivRem16, 111 [SDNPOutGlue]>; 112def MipsDivRemU16 : SDNode<"MipsISD::DivRemU16", SDT_MipsDivRem16, 113 [SDNPOutGlue]>; 114 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 121// compiled: 122// movn %got(d)($gp), %got(c)($gp), $4 123// This instruction is illegal since movn can take only register operands. 124 125def MipsWrapper : SDNode<"MipsISD::Wrapper", SDTIntBinOp>; 126 127def MipsSync : SDNode<"MipsISD::Sync", SDT_Sync, [SDNPHasChain,SDNPSideEffect]>; 128 129def MipsExt : SDNode<"MipsISD::Ext", SDT_Ext>; 130def MipsIns : SDNode<"MipsISD::Ins", SDT_Ins>; 131 132def MipsLWL : SDNode<"MipsISD::LWL", SDTMipsLoadLR, 133 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>; 134def MipsLWR : SDNode<"MipsISD::LWR", SDTMipsLoadLR, 135 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>; 136def MipsSWL : SDNode<"MipsISD::SWL", SDTStore, 137 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>; 138def MipsSWR : SDNode<"MipsISD::SWR", SDTStore, 139 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>; 140def MipsLDL : SDNode<"MipsISD::LDL", SDTMipsLoadLR, 141 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>; 142def MipsLDR : SDNode<"MipsISD::LDR", SDTMipsLoadLR, 143 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>; 144def MipsSDL : SDNode<"MipsISD::SDL", SDTStore, 145 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>; 146def MipsSDR : SDNode<"MipsISD::SDR", SDTStore, 147 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>; 148 149//===----------------------------------------------------------------------===// 150// Mips Instruction Predicate Definitions. 151//===----------------------------------------------------------------------===// 152def HasMips2 : Predicate<"Subtarget->hasMips2()">, 153 AssemblerPredicate<"FeatureMips2">; 154def HasMips3_32 : Predicate<"Subtarget->hasMips3_32()">, 155 AssemblerPredicate<"FeatureMips3_32">; 156def HasMips3_32r2 : Predicate<"Subtarget->hasMips3_32r2()">, 157 AssemblerPredicate<"FeatureMips3_32r2">; 158def HasMips3 : Predicate<"Subtarget->hasMips3()">, 159 AssemblerPredicate<"FeatureMips3">; 160def HasMips4_32 : Predicate<"Subtarget->hasMips4_32()">, 161 AssemblerPredicate<"FeatureMips4_32">; 162def NotMips4_32 : Predicate<"!Subtarget->hasMips4_32()">, 163 AssemblerPredicate<"!FeatureMips4_32">; 164def HasMips4_32r2 : Predicate<"Subtarget->hasMips4_32r2()">, 165 AssemblerPredicate<"FeatureMips4_32r2">; 166def HasMips5_32r2 : Predicate<"Subtarget->hasMips5_32r2()">, 167 AssemblerPredicate<"FeatureMips5_32r2">; 168def HasMips32 : Predicate<"Subtarget->hasMips32()">, 169 AssemblerPredicate<"FeatureMips32">; 170def HasMips32r2 : Predicate<"Subtarget->hasMips32r2()">, 171 AssemblerPredicate<"FeatureMips32r2">; 172def HasMips32r5 : Predicate<"Subtarget->hasMips32r5()">, 173 AssemblerPredicate<"FeatureMips32r5">; 174def HasMips32r6 : Predicate<"Subtarget->hasMips32r6()">, 175 AssemblerPredicate<"FeatureMips32r6">; 176def NotMips32r6 : Predicate<"!Subtarget->hasMips32r6()">, 177 AssemblerPredicate<"!FeatureMips32r6">; 178def IsGP64bit : Predicate<"Subtarget->isGP64bit()">, 179 AssemblerPredicate<"FeatureGP64Bit">; 180def IsGP32bit : Predicate<"!Subtarget->isGP64bit()">, 181 AssemblerPredicate<"!FeatureGP64Bit">; 182def HasMips64 : Predicate<"Subtarget->hasMips64()">, 183 AssemblerPredicate<"FeatureMips64">; 184def NotMips64 : Predicate<"!Subtarget->hasMips64()">, 185 AssemblerPredicate<"!FeatureMips64">; 186def HasMips64r2 : Predicate<"Subtarget->hasMips64r2()">, 187 AssemblerPredicate<"FeatureMips64r2">; 188def HasMips64r6 : Predicate<"Subtarget->hasMips64r6()">, 189 AssemblerPredicate<"FeatureMips64r6">; 190def NotMips64r6 : Predicate<"!Subtarget->hasMips64r6()">, 191 AssemblerPredicate<"!FeatureMips64r6">; 192def HasMicroMips32r6 : Predicate<"Subtarget->inMicroMips32r6Mode()">, 193 AssemblerPredicate<"FeatureMicroMips,FeatureMips32r6">; 194def HasMicroMips64r6 : Predicate<"Subtarget->inMicroMips64r6Mode()">, 195 AssemblerPredicate<"FeatureMicroMips,FeatureMips64r6">; 196def InMips16Mode : Predicate<"Subtarget->inMips16Mode()">, 197 AssemblerPredicate<"FeatureMips16">; 198def HasCnMips : Predicate<"Subtarget->hasCnMips()">, 199 AssemblerPredicate<"FeatureCnMips">; 200def RelocStatic : Predicate<"TM.getRelocationModel() == Reloc::Static">; 201def RelocPIC : Predicate<"TM.getRelocationModel() == Reloc::PIC_">; 202def NoNaNsFPMath : Predicate<"TM.Options.NoNaNsFPMath">; 203def HasStdEnc : Predicate<"Subtarget->hasStandardEncoding()">, 204 AssemblerPredicate<"!FeatureMips16">; 205def NotDSP : Predicate<"!Subtarget->hasDSP()">; 206def InMicroMips : Predicate<"Subtarget->inMicroMipsMode()">, 207 AssemblerPredicate<"FeatureMicroMips">; 208def NotInMicroMips : Predicate<"!Subtarget->inMicroMipsMode()">, 209 AssemblerPredicate<"!FeatureMicroMips">; 210def IsLE : Predicate<"Subtarget->isLittle()">; 211def IsBE : Predicate<"!Subtarget->isLittle()">; 212def IsNotNaCl : Predicate<"!Subtarget->isTargetNaCl()">; 213def UseTCCInDIV : AssemblerPredicate<"FeatureUseTCCInDIV">; 214def HasEVA : Predicate<"Subtarget->hasEVA()">, 215 AssemblerPredicate<"FeatureEVA,FeatureMips32r2">; 216def HasMSA : Predicate<"Subtarget->hasMSA()">, 217 AssemblerPredicate<"FeatureMSA">; 218 219 220//===----------------------------------------------------------------------===// 221// Mips GPR size adjectives. 222// They are mutually exclusive. 223//===----------------------------------------------------------------------===// 224 225class GPR_32 { list<Predicate> GPRPredicates = [IsGP32bit]; } 226class GPR_64 { list<Predicate> GPRPredicates = [IsGP64bit]; } 227 228//===----------------------------------------------------------------------===// 229// Mips ISA/ASE membership and instruction group membership adjectives. 230// They are mutually exclusive. 231//===----------------------------------------------------------------------===// 232 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 237// predicates. 238class ISA_MIPS1_NOT_4_32 { 239 list<Predicate> InsnPredicates = [NotMips4_32]; 240} 241class ISA_MIPS1_NOT_32R6_64R6 { 242 list<Predicate> InsnPredicates = [NotMips32r6, NotMips64r6]; 243} 244class ISA_MIPS2 { list<Predicate> InsnPredicates = [HasMips2]; } 245class ISA_MIPS2_NOT_32R6_64R6 { 246 list<Predicate> InsnPredicates = [HasMips2, NotMips32r6, NotMips64r6]; 247} 248class ISA_MIPS3 { list<Predicate> InsnPredicates = [HasMips3]; } 249class ISA_MIPS3_NOT_32R6_64R6 { 250 list<Predicate> InsnPredicates = [HasMips3, NotMips32r6, NotMips64r6]; 251} 252class ISA_MIPS32 { list<Predicate> InsnPredicates = [HasMips32]; } 253class ISA_MIPS32_NOT_32R6_64R6 { 254 list<Predicate> InsnPredicates = [HasMips32, NotMips32r6, NotMips64r6]; 255} 256class ISA_MIPS32R2 { list<Predicate> InsnPredicates = [HasMips32r2]; } 257class ISA_MIPS32R2_NOT_32R6_64R6 { 258 list<Predicate> InsnPredicates = [HasMips32r2, NotMips32r6, NotMips64r6]; 259} 260class ISA_MIPS32R5 { list<Predicate> InsnPredicates = [HasMips32r5]; } 261class ISA_MIPS64 { list<Predicate> InsnPredicates = [HasMips64]; } 262class ISA_MIPS64_NOT_64R6 { 263 list<Predicate> InsnPredicates = [HasMips64, NotMips64r6]; 264} 265class ISA_MIPS64R2 { list<Predicate> InsnPredicates = [HasMips64r2]; } 266class ISA_MIPS32R6 { list<Predicate> InsnPredicates = [HasMips32r6]; } 267class ISA_MIPS64R6 { list<Predicate> InsnPredicates = [HasMips64r6]; } 268class ISA_MICROMIPS { list<Predicate> InsnPredicates = [InMicroMips]; } 269class ISA_MICROMIPS32R6 { 270 list<Predicate> InsnPredicates = [HasMicroMips32r6]; 271} 272class ISA_MICROMIPS64R6 { 273 list<Predicate> InsnPredicates = [HasMicroMips64r6]; 274} 275class ISA_MICROMIPS32_NOT_MIPS32R6 { 276 list<Predicate> InsnPredicates = [InMicroMips, NotMips32r6]; 277} 278 279class INSN_EVA { list<Predicate> InsnPredicates = [HasEVA]; } 280class INSN_EVA_NOT_32R6_64R6 { 281 list<Predicate> InsnPredicates = [NotMips32r6, NotMips64r6, HasEVA]; 282} 283 284// The portions of MIPS-III that were also added to MIPS32 285class INSN_MIPS3_32 { list<Predicate> InsnPredicates = [HasMips3_32]; } 286 287// The portions of MIPS-III that were also added to MIPS32 but were removed in 288// MIPS32r6 and MIPS64r6. 289class INSN_MIPS3_32_NOT_32R6_64R6 { 290 list<Predicate> InsnPredicates = [HasMips3_32, NotMips32r6, NotMips64r6]; 291} 292 293// The portions of MIPS-III that were also added to MIPS32 294class INSN_MIPS3_32R2 { list<Predicate> InsnPredicates = [HasMips3_32r2]; } 295 296// The portions of MIPS-IV that were also added to MIPS32 but were removed in 297// MIPS32r6 and MIPS64r6. 298class INSN_MIPS4_32_NOT_32R6_64R6 { 299 list<Predicate> InsnPredicates = [HasMips4_32, NotMips32r6, NotMips64r6]; 300} 301 302// The portions of MIPS-IV that were also added to MIPS32r2 but were removed in 303// MIPS32r6 and MIPS64r6. 304class INSN_MIPS4_32R2_NOT_32R6_64R6 { 305 list<Predicate> InsnPredicates = [HasMips4_32r2, NotMips32r6, NotMips64r6]; 306} 307 308// The portions of MIPS-V that were also added to MIPS32r2 but were removed in 309// MIPS32r6 and MIPS64r6. 310class INSN_MIPS5_32R2_NOT_32R6_64R6 { 311 list<Predicate> InsnPredicates = [HasMips5_32r2, NotMips32r6, NotMips64r6]; 312} 313 314class ASE_CNMIPS { 315 list<Predicate> InsnPredicates = [HasCnMips]; 316} 317 318class ASE_MSA { 319 list<Predicate> InsnPredicates = [HasMSA]; 320} 321 322class ASE_MSA_NOT_MSA64 { 323 list<Predicate> InsnPredicates = [HasMSA, NotMips64]; 324} 325 326class ASE_MSA64 { 327 list<Predicate> InsnPredicates = [HasMSA, HasMips64]; 328} 329 330// Class used for separating microMIPSr6 and microMIPS (r3) instruction. 331// It can be used only on instructions that doesn't inherit PredicateControl. 332class ISA_MICROMIPS_NOT_32R6_64R6 : PredicateControl { 333 let InsnPredicates = [InMicroMips, NotMips32r6, NotMips64r6]; 334} 335 336//===----------------------------------------------------------------------===// 337 338class MipsPat<dag pattern, dag result> : Pat<pattern, result>, PredicateControl { 339 let EncodingPredicates = [HasStdEnc]; 340} 341 342class MipsInstAlias<string Asm, dag Result, bit Emit = 0b1> : 343 InstAlias<Asm, Result, Emit>, PredicateControl; 344 345class IsCommutable { 346 bit isCommutable = 1; 347} 348 349class IsBranch { 350 bit isBranch = 1; 351} 352 353class IsReturn { 354 bit isReturn = 1; 355} 356 357class IsCall { 358 bit isCall = 1; 359} 360 361class IsTailCall { 362 bit isCall = 1; 363 bit isTerminator = 1; 364 bit isReturn = 1; 365 bit isBarrier = 1; 366 bit hasExtraSrcRegAllocReq = 1; 367 bit isCodeGenOnly = 1; 368} 369 370class IsAsCheapAsAMove { 371 bit isAsCheapAsAMove = 1; 372} 373 374class NeverHasSideEffects { 375 bit hasSideEffects = 0; 376} 377 378//===----------------------------------------------------------------------===// 379// Instruction format superclass 380//===----------------------------------------------------------------------===// 381 382include "MipsInstrFormats.td" 383 384//===----------------------------------------------------------------------===// 385// Mips Operand, Complex Patterns and Transformations Definitions. 386//===----------------------------------------------------------------------===// 387 388class ConstantSImmAsmOperandClass<int Bits, list<AsmOperandClass> Supers = []> 389 : AsmOperandClass { 390 let Name = "ConstantSImm" # Bits; 391 let RenderMethod = "addImmOperands"; 392 let PredicateMethod = "isConstantSImm<" # Bits # ">"; 393 let SuperClasses = Supers; 394 let DiagnosticType = "SImm" # Bits; 395} 396 397class ConstantUImmAsmOperandClass<int Bits, list<AsmOperandClass> Supers = [], 398 int Offset = 0> : AsmOperandClass { 399 let Name = "ConstantUImm" # Bits # "_" # Offset; 400 let RenderMethod = "addConstantUImmOperands<" # Bits # ", " # Offset # ">"; 401 let PredicateMethod = "isConstantUImm<" # Bits # ", " # Offset # ">"; 402 let SuperClasses = Supers; 403 let DiagnosticType = "UImm" # Bits # "_" # Offset; 404} 405 406def ConstantUImm10AsmOperandClass 407 : ConstantUImmAsmOperandClass<10, []>; 408def ConstantUImm8AsmOperandClass 409 : ConstantUImmAsmOperandClass<8, [ConstantUImm10AsmOperandClass]>; 410def ConstantUImm7AsmOperandClass 411 : ConstantUImmAsmOperandClass<7, [ConstantUImm8AsmOperandClass]>; 412def ConstantUImm6AsmOperandClass 413 : ConstantUImmAsmOperandClass<6, [ConstantUImm7AsmOperandClass]>; 414def ConstantSImm6AsmOperandClass 415 : ConstantSImmAsmOperandClass<6, [ConstantUImm7AsmOperandClass]>; 416def ConstantUImm5Plus1AsmOperandClass 417 : ConstantUImmAsmOperandClass<5, [ConstantUImm6AsmOperandClass], 1>; 418def ConstantUImm5Plus32AsmOperandClass 419 : ConstantUImmAsmOperandClass<5, [ConstantUImm6AsmOperandClass], 32>; 420def ConstantUImm5Plus33AsmOperandClass 421 : ConstantUImmAsmOperandClass<5, [ConstantUImm6AsmOperandClass], 33>; 422def ConstantUImm5Plus32NormalizeAsmOperandClass 423 : ConstantUImmAsmOperandClass<5, [ConstantUImm6AsmOperandClass], 32> { 424 let Name = "ConstantUImm5_32_Norm"; 425 // We must also subtract 32 when we render the operand. 426 let RenderMethod = "addConstantUImmOperands<5, 32, -32>"; 427} 428def ConstantUImm5Lsl2AsmOperandClass : AsmOperandClass { 429 let Name = "UImm5Lsl2"; 430 let RenderMethod = "addImmOperands"; 431 let PredicateMethod = "isScaledUImm<5, 2>"; 432 let SuperClasses = [ConstantUImm6AsmOperandClass]; 433 let DiagnosticType = "UImm5_Lsl2"; 434} 435def ConstantUImm5ReportUImm6AsmOperandClass 436 : ConstantUImmAsmOperandClass<5, [ConstantUImm6AsmOperandClass]> { 437 let Name = "ConstantUImm5_0_Report_UImm6"; 438 let DiagnosticType = "UImm5_0_Report_UImm6"; 439} 440def ConstantUImm5AsmOperandClass 441 : ConstantUImmAsmOperandClass<5, [ConstantUImm6AsmOperandClass]>; 442def ConstantUImm4AsmOperandClass 443 : ConstantUImmAsmOperandClass< 444 4, [ConstantUImm5AsmOperandClass, 445 ConstantUImm5Plus32AsmOperandClass, 446 ConstantUImm5Plus32NormalizeAsmOperandClass]>; 447def ConstantUImm3AsmOperandClass 448 : ConstantUImmAsmOperandClass<3, [ConstantUImm4AsmOperandClass]>; 449def ConstantUImm2Plus1AsmOperandClass 450 : ConstantUImmAsmOperandClass<2, [ConstantUImm3AsmOperandClass], 1>; 451def ConstantUImm2AsmOperandClass 452 : ConstantUImmAsmOperandClass<2, [ConstantUImm3AsmOperandClass]>; 453def ConstantUImm1AsmOperandClass 454 : ConstantUImmAsmOperandClass<1, [ConstantUImm2AsmOperandClass]>; 455def ConstantImmzAsmOperandClass : AsmOperandClass { 456 let Name = "ConstantImmz"; 457 let RenderMethod = "addConstantUImmOperands<1>"; 458 let PredicateMethod = "isConstantImmz"; 459 let SuperClasses = [ConstantUImm1AsmOperandClass]; 460 let DiagnosticType = "Immz"; 461} 462 463def MipsJumpTargetAsmOperand : AsmOperandClass { 464 let Name = "JumpTarget"; 465 let ParserMethod = "parseJumpTarget"; 466 let PredicateMethod = "isImm"; 467 let RenderMethod = "addImmOperands"; 468} 469 470// Instruction operand types 471def jmptarget : Operand<OtherVT> { 472 let EncoderMethod = "getJumpTargetOpValue"; 473 let ParserMatchClass = MipsJumpTargetAsmOperand; 474} 475def brtarget : Operand<OtherVT> { 476 let EncoderMethod = "getBranchTargetOpValue"; 477 let OperandType = "OPERAND_PCREL"; 478 let DecoderMethod = "DecodeBranchTarget"; 479 let ParserMatchClass = MipsJumpTargetAsmOperand; 480} 481def calltarget : Operand<iPTR> { 482 let EncoderMethod = "getJumpTargetOpValue"; 483 let ParserMatchClass = MipsJumpTargetAsmOperand; 484} 485 486def imm64: Operand<i64>; 487 488def simm6 : Operand<i32> { 489 let ParserMatchClass = ConstantSImm6AsmOperandClass; 490 let OperandType = "OPERAND_IMMEDIATE"; 491} 492def simm9 : Operand<i32>; 493def simm10 : Operand<i32>; 494def simm11 : Operand<i32>; 495 496def simm16 : Operand<i32> { 497 let DecoderMethod= "DecodeSimm16"; 498} 499 500def simm19_lsl2 : Operand<i32> { 501 let EncoderMethod = "getSimm19Lsl2Encoding"; 502 let DecoderMethod = "DecodeSimm19Lsl2"; 503 let ParserMatchClass = MipsJumpTargetAsmOperand; 504} 505 506def simm18_lsl3 : Operand<i32> { 507 let EncoderMethod = "getSimm18Lsl3Encoding"; 508 let DecoderMethod = "DecodeSimm18Lsl3"; 509 let ParserMatchClass = MipsJumpTargetAsmOperand; 510} 511 512def simm20 : Operand<i32>; 513def simm32 : Operand<i32>; 514 515def uimm20 : Operand<i32> { 516} 517 518def simm16_64 : Operand<i64> { 519 let DecoderMethod = "DecodeSimm16"; 520} 521 522// Zero 523def uimmz : Operand<i32> { 524 let PrintMethod = "printUnsignedImm"; 525 let ParserMatchClass = ConstantImmzAsmOperandClass; 526} 527 528// Unsigned Operands 529foreach I = {1, 2, 3, 4, 5, 6, 7, 8, 10} in 530 def uimm # I : Operand<i32> { 531 let PrintMethod = "printUnsignedImm"; 532 let ParserMatchClass = 533 !cast<AsmOperandClass>("ConstantUImm" # I # "AsmOperandClass"); 534 } 535 536def uimm2_plus1 : Operand<i32> { 537 let PrintMethod = "printUnsignedImm"; 538 let EncoderMethod = "getUImmWithOffsetEncoding<2, 1>"; 539 let DecoderMethod = "DecodeUImmWithOffset<2, 1>"; 540 let ParserMatchClass = ConstantUImm2Plus1AsmOperandClass; 541} 542 543def uimm5_plus1 : Operand<i32> { 544 let PrintMethod = "printUnsignedImm"; 545 let EncoderMethod = "getUImmWithOffsetEncoding<5, 1>"; 546 let DecoderMethod = "DecodeUImmWithOffset<5, 1>"; 547 let ParserMatchClass = ConstantUImm5Plus1AsmOperandClass; 548} 549 550def uimm5_plus32 : Operand<i32> { 551 let PrintMethod = "printUnsignedImm"; 552 let ParserMatchClass = ConstantUImm5Plus32AsmOperandClass; 553} 554 555def uimm5_plus33 : Operand<i32> { 556 let PrintMethod = "printUnsignedImm"; 557 let EncoderMethod = "getUImmWithOffsetEncoding<5, 1>"; 558 let DecoderMethod = "DecodeUImmWithOffset<5, 1>"; 559 let ParserMatchClass = ConstantUImm5Plus33AsmOperandClass; 560} 561 562def uimm5_plus32_normalize : Operand<i32> { 563 let PrintMethod = "printUnsignedImm"; 564 let ParserMatchClass = ConstantUImm5Plus32NormalizeAsmOperandClass; 565} 566 567def uimm5_lsl2 : Operand<OtherVT> { 568 let EncoderMethod = "getUImm5Lsl2Encoding"; 569 let DecoderMethod = "DecodeUImm5lsl2"; 570 let ParserMatchClass = ConstantUImm5Lsl2AsmOperandClass; 571} 572 573def uimm5_plus32_normalize_64 : Operand<i64> { 574 let PrintMethod = "printUnsignedImm"; 575 let ParserMatchClass = ConstantUImm5Plus32NormalizeAsmOperandClass; 576} 577 578foreach I = {5} in 579 def uimm # I # _64 : Operand<i64> { 580 let PrintMethod = "printUnsignedImm"; 581 let ParserMatchClass = 582 !cast<AsmOperandClass>("ConstantUImm" # I # "AsmOperandClass"); 583 } 584 585// Like uimm5_64 but reports a less confusing error for 32-63 when 586// an instruction alias permits that. 587def uimm5_64_report_uimm6 : Operand<i64> { 588 let PrintMethod = "printUnsignedImm"; 589 let ParserMatchClass = ConstantUImm5ReportUImm6AsmOperandClass; 590} 591 592def uimm16 : Operand<i32> { 593 let PrintMethod = "printUnsignedImm"; 594} 595 596def pcrel16 : Operand<i32> { 597} 598 599def MipsMemAsmOperand : AsmOperandClass { 600 let Name = "Mem"; 601 let ParserMethod = "parseMemOperand"; 602} 603 604def MipsMemSimm9AsmOperand : AsmOperandClass { 605 let Name = "MemOffsetSimm9"; 606 let SuperClasses = [MipsMemAsmOperand]; 607 let RenderMethod = "addMemOperands"; 608 let ParserMethod = "parseMemOperand"; 609 let PredicateMethod = "isMemWithSimmOffset<9>"; 610} 611 612def MipsMemSimm9GPRAsmOperand : AsmOperandClass { 613 let Name = "MemOffsetSimm9GPR"; 614 let SuperClasses = [MipsMemAsmOperand]; 615 let RenderMethod = "addMemOperands"; 616 let ParserMethod = "parseMemOperand"; 617 let PredicateMethod = "isMemWithSimmOffsetGPR<9>"; 618} 619 620def MipsMemSimm11AsmOperand : AsmOperandClass { 621 let Name = "MemOffsetSimm11"; 622 let SuperClasses = [MipsMemAsmOperand]; 623 let RenderMethod = "addMemOperands"; 624 let ParserMethod = "parseMemOperand"; 625 let PredicateMethod = "isMemWithSimmOffset<11>"; 626} 627 628def MipsMemSimm16AsmOperand : AsmOperandClass { 629 let Name = "MemOffsetSimm16"; 630 let SuperClasses = [MipsMemAsmOperand]; 631 let RenderMethod = "addMemOperands"; 632 let ParserMethod = "parseMemOperand"; 633 let PredicateMethod = "isMemWithSimmOffset<16>"; 634} 635 636def MipsInvertedImmoperand : AsmOperandClass { 637 let Name = "InvNum"; 638 let RenderMethod = "addImmOperands"; 639 let ParserMethod = "parseInvNum"; 640} 641 642def InvertedImOperand : Operand<i32> { 643 let ParserMatchClass = MipsInvertedImmoperand; 644} 645 646def InvertedImOperand64 : Operand<i64> { 647 let ParserMatchClass = MipsInvertedImmoperand; 648} 649 650class mem_generic : Operand<iPTR> { 651 let PrintMethod = "printMemOperand"; 652 let MIOperandInfo = (ops ptr_rc, simm16); 653 let EncoderMethod = "getMemEncoding"; 654 let ParserMatchClass = MipsMemAsmOperand; 655 let OperandType = "OPERAND_MEMORY"; 656} 657 658// Address operand 659def mem : mem_generic; 660 661// MSA specific address operand 662def mem_msa : mem_generic { 663 let MIOperandInfo = (ops ptr_rc, simm10); 664 let EncoderMethod = "getMSAMemEncoding"; 665} 666 667def mem_simm9 : mem_generic { 668 let MIOperandInfo = (ops ptr_rc, simm9); 669 let EncoderMethod = "getMemEncoding"; 670 let ParserMatchClass = MipsMemSimm9AsmOperand; 671} 672 673def mem_simm9gpr : mem_generic { 674 let MIOperandInfo = (ops ptr_rc, simm9); 675 let EncoderMethod = "getMemEncoding"; 676 let ParserMatchClass = MipsMemSimm9GPRAsmOperand; 677} 678 679def mem_simm11 : mem_generic { 680 let MIOperandInfo = (ops ptr_rc, simm11); 681 let EncoderMethod = "getMemEncoding"; 682 let ParserMatchClass = MipsMemSimm11AsmOperand; 683} 684 685def mem_simm16 : mem_generic { 686 let MIOperandInfo = (ops ptr_rc, simm16); 687 let EncoderMethod = "getMemEncoding"; 688 let ParserMatchClass = MipsMemSimm16AsmOperand; 689} 690 691def mem_ea : Operand<iPTR> { 692 let PrintMethod = "printMemOperandEA"; 693 let MIOperandInfo = (ops ptr_rc, simm16); 694 let EncoderMethod = "getMemEncoding"; 695 let OperandType = "OPERAND_MEMORY"; 696} 697 698def PtrRC : Operand<iPTR> { 699 let MIOperandInfo = (ops ptr_rc); 700 let DecoderMethod = "DecodePtrRegisterClass"; 701 let ParserMatchClass = GPR32AsmOperand; 702} 703 704// size operand of ins instruction 705def size_ins : Operand<i32> { 706 let EncoderMethod = "getSizeInsEncoding"; 707 let DecoderMethod = "DecodeInsSize"; 708} 709 710// Transformation Function - get the lower 16 bits. 711def LO16 : SDNodeXForm<imm, [{ 712 return getImm(N, N->getZExtValue() & 0xFFFF); 713}]>; 714 715// Transformation Function - get the higher 16 bits. 716def HI16 : SDNodeXForm<imm, [{ 717 return getImm(N, (N->getZExtValue() >> 16) & 0xFFFF); 718}]>; 719 720// Plus 1. 721def Plus1 : SDNodeXForm<imm, [{ return getImm(N, N->getSExtValue() + 1); }]>; 722 723// Node immediate is zero (e.g. insve.d) 724def immz : PatLeaf<(imm), [{ return N->getSExtValue() == 0; }]>; 725 726// Node immediate fits as 16-bit sign extended on target immediate. 727// e.g. addi, andi 728def immSExt8 : PatLeaf<(imm), [{ return isInt<8>(N->getSExtValue()); }]>; 729 730// Node immediate fits as 16-bit sign extended on target immediate. 731// e.g. addi, andi 732def immSExt16 : PatLeaf<(imm), [{ return isInt<16>(N->getSExtValue()); }]>; 733 734// Node immediate fits as 15-bit sign extended on target immediate. 735// e.g. addi, andi 736def immSExt15 : PatLeaf<(imm), [{ return isInt<15>(N->getSExtValue()); }]>; 737 738// Node immediate fits as 16-bit zero extended on target immediate. 739// The LO16 param means that only the lower 16 bits of the node 740// immediate are caught. 741// e.g. addiu, sltiu 742def immZExt16 : PatLeaf<(imm), [{ 743 if (N->getValueType(0) == MVT::i32) 744 return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue(); 745 else 746 return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue(); 747}], LO16>; 748 749// Immediate can be loaded with LUi (32-bit int with lower 16-bit cleared). 750def immLow16Zero : PatLeaf<(imm), [{ 751 int64_t Val = N->getSExtValue(); 752 return isInt<32>(Val) && !(Val & 0xffff); 753}]>; 754 755// shamt field must fit in 5 bits. 756def immZExt5 : ImmLeaf<i32, [{return Imm == (Imm & 0x1f);}]>; 757 758// True if (N + 1) fits in 16-bit field. 759def immSExt16Plus1 : PatLeaf<(imm), [{ 760 return isInt<17>(N->getSExtValue()) && isInt<16>(N->getSExtValue() + 1); 761}]>; 762 763// Mips Address Mode! SDNode frameindex could possibily be a match 764// since load and store instructions from stack used it. 765def addr : 766 ComplexPattern<iPTR, 2, "selectIntAddr", [frameindex]>; 767 768def addrRegImm : 769 ComplexPattern<iPTR, 2, "selectAddrRegImm", [frameindex]>; 770 771def addrRegReg : 772 ComplexPattern<iPTR, 2, "selectAddrRegReg", [frameindex]>; 773 774def addrDefault : 775 ComplexPattern<iPTR, 2, "selectAddrDefault", [frameindex]>; 776 777def addrimm10 : ComplexPattern<iPTR, 2, "selectIntAddrMSA", [frameindex]>; 778 779//===----------------------------------------------------------------------===// 780// Instructions specific format 781//===----------------------------------------------------------------------===// 782 783// Arithmetic and logical instructions with 3 register operands. 784class ArithLogicR<string opstr, RegisterOperand RO, bit isComm = 0, 785 InstrItinClass Itin = NoItinerary, 786 SDPatternOperator OpNode = null_frag>: 787 InstSE<(outs RO:$rd), (ins RO:$rs, RO:$rt), 788 !strconcat(opstr, "\t$rd, $rs, $rt"), 789 [(set RO:$rd, (OpNode RO:$rs, RO:$rt))], Itin, FrmR, opstr> { 790 let isCommutable = isComm; 791 let isReMaterializable = 1; 792 let TwoOperandAliasConstraint = "$rd = $rs"; 793} 794 795// Arithmetic and logical instructions with 2 register operands. 796class ArithLogicI<string opstr, Operand Od, RegisterOperand RO, 797 InstrItinClass Itin = NoItinerary, 798 SDPatternOperator imm_type = null_frag, 799 SDPatternOperator OpNode = null_frag> : 800 InstSE<(outs RO:$rt), (ins RO:$rs, Od:$imm16), 801 !strconcat(opstr, "\t$rt, $rs, $imm16"), 802 [(set RO:$rt, (OpNode RO:$rs, imm_type:$imm16))], 803 Itin, FrmI, opstr> { 804 let isReMaterializable = 1; 805 let TwoOperandAliasConstraint = "$rs = $rt"; 806} 807 808// Arithmetic Multiply ADD/SUB 809class MArithR<string opstr, InstrItinClass itin, bit isComm = 0> : 810 InstSE<(outs), (ins GPR32Opnd:$rs, GPR32Opnd:$rt), 811 !strconcat(opstr, "\t$rs, $rt"), [], itin, FrmR, opstr> { 812 let Defs = [HI0, LO0]; 813 let Uses = [HI0, LO0]; 814 let isCommutable = isComm; 815} 816 817// Logical 818class LogicNOR<string opstr, RegisterOperand RO>: 819 InstSE<(outs RO:$rd), (ins RO:$rs, RO:$rt), 820 !strconcat(opstr, "\t$rd, $rs, $rt"), 821 [(set RO:$rd, (not (or RO:$rs, RO:$rt)))], II_NOR, FrmR, opstr> { 822 let isCommutable = 1; 823} 824 825// Shifts 826class shift_rotate_imm<string opstr, Operand ImmOpnd, 827 RegisterOperand RO, InstrItinClass itin, 828 SDPatternOperator OpNode = null_frag, 829 SDPatternOperator PF = null_frag> : 830 InstSE<(outs RO:$rd), (ins RO:$rt, ImmOpnd:$shamt), 831 !strconcat(opstr, "\t$rd, $rt, $shamt"), 832 [(set RO:$rd, (OpNode RO:$rt, PF:$shamt))], itin, FrmR, opstr> { 833 let TwoOperandAliasConstraint = "$rt = $rd"; 834} 835 836class shift_rotate_reg<string opstr, RegisterOperand RO, InstrItinClass itin, 837 SDPatternOperator OpNode = null_frag>: 838 InstSE<(outs RO:$rd), (ins RO:$rt, GPR32Opnd:$rs), 839 !strconcat(opstr, "\t$rd, $rt, $rs"), 840 [(set RO:$rd, (OpNode RO:$rt, GPR32Opnd:$rs))], itin, FrmR, 841 opstr>; 842 843// Load Upper Immediate 844class LoadUpper<string opstr, RegisterOperand RO, Operand Imm>: 845 InstSE<(outs RO:$rt), (ins Imm:$imm16), !strconcat(opstr, "\t$rt, $imm16"), 846 [], II_LUI, FrmI, opstr>, IsAsCheapAsAMove { 847 let hasSideEffects = 0; 848 let isReMaterializable = 1; 849} 850 851// Memory Load/Store 852class Load<string opstr, DAGOperand RO, SDPatternOperator OpNode = null_frag, 853 InstrItinClass Itin = NoItinerary, ComplexPattern Addr = addr> : 854 InstSE<(outs RO:$rt), (ins mem:$addr), !strconcat(opstr, "\t$rt, $addr"), 855 [(set RO:$rt, (OpNode Addr:$addr))], Itin, FrmI, opstr> { 856 let DecoderMethod = "DecodeMem"; 857 let canFoldAsLoad = 1; 858 let mayLoad = 1; 859} 860 861class StoreMemory<string opstr, DAGOperand RO, DAGOperand MO, 862 SDPatternOperator OpNode = null_frag, 863 InstrItinClass Itin = NoItinerary, ComplexPattern Addr = addr> : 864 InstSE<(outs), (ins RO:$rt, MO:$addr), !strconcat(opstr, "\t$rt, $addr"), 865 [(OpNode RO:$rt, Addr:$addr)], Itin, FrmI, opstr> { 866 let DecoderMethod = "DecodeMem"; 867 let mayStore = 1; 868} 869 870class Store<string opstr, DAGOperand RO, SDPatternOperator OpNode = null_frag, 871 InstrItinClass Itin = NoItinerary, ComplexPattern Addr = addr> : 872 StoreMemory<opstr, RO, mem, OpNode, Itin, Addr>; 873 874// Load/Store Left/Right 875let canFoldAsLoad = 1 in 876class LoadLeftRight<string opstr, SDNode OpNode, RegisterOperand RO, 877 InstrItinClass Itin> : 878 InstSE<(outs RO:$rt), (ins mem:$addr, RO:$src), 879 !strconcat(opstr, "\t$rt, $addr"), 880 [(set RO:$rt, (OpNode addr:$addr, RO:$src))], Itin, FrmI> { 881 let DecoderMethod = "DecodeMem"; 882 string Constraints = "$src = $rt"; 883} 884 885class StoreLeftRight<string opstr, SDNode OpNode, RegisterOperand RO, 886 InstrItinClass Itin> : 887 InstSE<(outs), (ins RO:$rt, mem:$addr), !strconcat(opstr, "\t$rt, $addr"), 888 [(OpNode RO:$rt, addr:$addr)], Itin, FrmI> { 889 let DecoderMethod = "DecodeMem"; 890} 891 892// COP2 Load/Store 893class LW_FT2<string opstr, RegisterOperand RC, InstrItinClass Itin, 894 SDPatternOperator OpNode= null_frag> : 895 InstSE<(outs RC:$rt), (ins mem:$addr), !strconcat(opstr, "\t$rt, $addr"), 896 [(set RC:$rt, (OpNode addrDefault:$addr))], Itin, FrmFI, opstr> { 897 let DecoderMethod = "DecodeFMem2"; 898 let mayLoad = 1; 899} 900 901class SW_FT2<string opstr, RegisterOperand RC, InstrItinClass Itin, 902 SDPatternOperator OpNode= null_frag> : 903 InstSE<(outs), (ins RC:$rt, mem:$addr), !strconcat(opstr, "\t$rt, $addr"), 904 [(OpNode RC:$rt, addrDefault:$addr)], Itin, FrmFI, opstr> { 905 let DecoderMethod = "DecodeFMem2"; 906 let mayStore = 1; 907} 908 909// COP3 Load/Store 910class LW_FT3<string opstr, RegisterOperand RC, InstrItinClass Itin, 911 SDPatternOperator OpNode= null_frag> : 912 InstSE<(outs RC:$rt), (ins mem:$addr), !strconcat(opstr, "\t$rt, $addr"), 913 [(set RC:$rt, (OpNode addrDefault:$addr))], Itin, FrmFI, opstr> { 914 let DecoderMethod = "DecodeFMem3"; 915 let mayLoad = 1; 916} 917 918class SW_FT3<string opstr, RegisterOperand RC, InstrItinClass Itin, 919 SDPatternOperator OpNode= null_frag> : 920 InstSE<(outs), (ins RC:$rt, mem:$addr), !strconcat(opstr, "\t$rt, $addr"), 921 [(OpNode RC:$rt, addrDefault:$addr)], Itin, FrmFI, opstr> { 922 let DecoderMethod = "DecodeFMem3"; 923 let mayStore = 1; 924} 925 926// Conditional Branch 927class CBranch<string opstr, DAGOperand opnd, PatFrag cond_op, 928 RegisterOperand RO, bit DelaySlot = 1> : 929 InstSE<(outs), (ins RO:$rs, RO:$rt, opnd:$offset), 930 !strconcat(opstr, "\t$rs, $rt, $offset"), 931 [(brcond (i32 (cond_op RO:$rs, RO:$rt)), bb:$offset)], II_BCC, 932 FrmI, opstr> { 933 let isBranch = 1; 934 let isTerminator = 1; 935 let hasDelaySlot = DelaySlot; 936 let Defs = [AT]; 937} 938 939class CBranchZero<string opstr, DAGOperand opnd, PatFrag cond_op, 940 RegisterOperand RO, bit DelaySlot = 1> : 941 InstSE<(outs), (ins RO:$rs, opnd:$offset), 942 !strconcat(opstr, "\t$rs, $offset"), 943 [(brcond (i32 (cond_op RO:$rs, 0)), bb:$offset)], II_BCCZ, 944 FrmI, opstr> { 945 let isBranch = 1; 946 let isTerminator = 1; 947 let hasDelaySlot = DelaySlot; 948 let Defs = [AT]; 949} 950 951// SetCC 952class SetCC_R<string opstr, PatFrag cond_op, RegisterOperand RO> : 953 InstSE<(outs GPR32Opnd:$rd), (ins RO:$rs, RO:$rt), 954 !strconcat(opstr, "\t$rd, $rs, $rt"), 955 [(set GPR32Opnd:$rd, (cond_op RO:$rs, RO:$rt))], 956 II_SLT_SLTU, FrmR, opstr>; 957 958class SetCC_I<string opstr, PatFrag cond_op, Operand Od, PatLeaf imm_type, 959 RegisterOperand RO>: 960 InstSE<(outs GPR32Opnd:$rt), (ins RO:$rs, Od:$imm16), 961 !strconcat(opstr, "\t$rt, $rs, $imm16"), 962 [(set GPR32Opnd:$rt, (cond_op RO:$rs, imm_type:$imm16))], 963 II_SLTI_SLTIU, FrmI, opstr>; 964 965// Jump 966class JumpFJ<DAGOperand opnd, string opstr, SDPatternOperator operator, 967 SDPatternOperator targetoperator, string bopstr> : 968 InstSE<(outs), (ins opnd:$target), !strconcat(opstr, "\t$target"), 969 [(operator targetoperator:$target)], II_J, FrmJ, bopstr> { 970 let isTerminator=1; 971 let isBarrier=1; 972 let hasDelaySlot = 1; 973 let DecoderMethod = "DecodeJumpTarget"; 974 let Defs = [AT]; 975} 976 977// Unconditional branch 978class UncondBranch<Instruction BEQInst> : 979 PseudoSE<(outs), (ins brtarget:$offset), [(br bb:$offset)], II_B>, 980 PseudoInstExpansion<(BEQInst ZERO, ZERO, brtarget:$offset)> { 981 let isBranch = 1; 982 let isTerminator = 1; 983 let isBarrier = 1; 984 let hasDelaySlot = 1; 985 let AdditionalPredicates = [RelocPIC]; 986 let Defs = [AT]; 987} 988 989// Base class for indirect branch and return instruction classes. 990let isTerminator=1, isBarrier=1, hasDelaySlot = 1 in 991class JumpFR<string opstr, RegisterOperand RO, 992 SDPatternOperator operator = null_frag>: 993 InstSE<(outs), (ins RO:$rs), "jr\t$rs", [(operator RO:$rs)], II_JR, 994 FrmR, opstr>; 995 996// Indirect branch 997class IndirectBranch<string opstr, RegisterOperand RO> : JumpFR<opstr, RO> { 998 let isBranch = 1; 999 let isIndirectBranch = 1; 1000} 1001 1002// Jump and Link (Call) 1003let isCall=1, hasDelaySlot=1, Defs = [RA] in { 1004 class JumpLink<string opstr, DAGOperand opnd> : 1005 InstSE<(outs), (ins opnd:$target), !strconcat(opstr, "\t$target"), 1006 [(MipsJmpLink imm:$target)], II_JAL, FrmJ, opstr> { 1007 let DecoderMethod = "DecodeJumpTarget"; 1008 } 1009 1010 class JumpLinkRegPseudo<RegisterOperand RO, Instruction JALRInst, 1011 Register RetReg, RegisterOperand ResRO = RO>: 1012 PseudoSE<(outs), (ins RO:$rs), [(MipsJmpLink RO:$rs)], II_JALR>, 1013 PseudoInstExpansion<(JALRInst RetReg, ResRO:$rs)>; 1014 1015 class JumpLinkReg<string opstr, RegisterOperand RO>: 1016 InstSE<(outs RO:$rd), (ins RO:$rs), !strconcat(opstr, "\t$rd, $rs"), 1017 [], II_JALR, FrmR, opstr>; 1018 1019 class BGEZAL_FT<string opstr, DAGOperand opnd, 1020 RegisterOperand RO, bit DelaySlot = 1> : 1021 InstSE<(outs), (ins RO:$rs, opnd:$offset), 1022 !strconcat(opstr, "\t$rs, $offset"), [], II_BCCZAL, FrmI, opstr> { 1023 let hasDelaySlot = DelaySlot; 1024 } 1025 1026} 1027 1028let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1, hasDelaySlot = 1, 1029 hasExtraSrcRegAllocReq = 1, Defs = [AT] in { 1030 class TailCall<Instruction JumpInst> : 1031 PseudoSE<(outs), (ins calltarget:$target), [], II_J>, 1032 PseudoInstExpansion<(JumpInst jmptarget:$target)>; 1033 1034 class TailCallReg<RegisterOperand RO, Instruction JRInst, 1035 RegisterOperand ResRO = RO> : 1036 PseudoSE<(outs), (ins RO:$rs), [(MipsTailCall RO:$rs)], II_JR>, 1037 PseudoInstExpansion<(JRInst ResRO:$rs)>; 1038} 1039 1040class BAL_BR_Pseudo<Instruction RealInst> : 1041 PseudoSE<(outs), (ins brtarget:$offset), [], II_BCCZAL>, 1042 PseudoInstExpansion<(RealInst ZERO, brtarget:$offset)> { 1043 let isBranch = 1; 1044 let isTerminator = 1; 1045 let isBarrier = 1; 1046 let hasDelaySlot = 1; 1047 let Defs = [RA]; 1048} 1049 1050// Syscall 1051class SYS_FT<string opstr> : 1052 InstSE<(outs), (ins uimm20:$code_), 1053 !strconcat(opstr, "\t$code_"), [], NoItinerary, FrmI, opstr>; 1054// Break 1055class BRK_FT<string opstr> : 1056 InstSE<(outs), (ins uimm10:$code_1, uimm10:$code_2), 1057 !strconcat(opstr, "\t$code_1, $code_2"), [], NoItinerary, 1058 FrmOther, opstr>; 1059 1060// (D)Eret 1061class ER_FT<string opstr> : 1062 InstSE<(outs), (ins), 1063 opstr, [], NoItinerary, FrmOther, opstr>; 1064 1065// Interrupts 1066class DEI_FT<string opstr, RegisterOperand RO> : 1067 InstSE<(outs RO:$rt), (ins), 1068 !strconcat(opstr, "\t$rt"), [], NoItinerary, FrmOther, opstr>; 1069 1070// Wait 1071class WAIT_FT<string opstr> : 1072 InstSE<(outs), (ins), opstr, [], NoItinerary, FrmOther, opstr>; 1073 1074// Sync 1075let hasSideEffects = 1 in 1076class SYNC_FT<string opstr> : 1077 InstSE<(outs), (ins i32imm:$stype), "sync $stype", [(MipsSync imm:$stype)], 1078 NoItinerary, FrmOther, opstr>; 1079 1080class SYNCI_FT<string opstr> : 1081 InstSE<(outs), (ins mem_simm16:$addr), !strconcat(opstr, "\t$addr"), [], 1082 NoItinerary, FrmOther, opstr> { 1083 let hasSideEffects = 1; 1084 let DecoderMethod = "DecodeSyncI"; 1085} 1086 1087let hasSideEffects = 1 in 1088class TEQ_FT<string opstr, RegisterOperand RO> : 1089 InstSE<(outs), (ins RO:$rs, RO:$rt, uimm16:$code_), 1090 !strconcat(opstr, "\t$rs, $rt, $code_"), [], NoItinerary, 1091 FrmI, opstr>; 1092 1093class TEQI_FT<string opstr, RegisterOperand RO> : 1094 InstSE<(outs), (ins RO:$rs, uimm16:$imm16), 1095 !strconcat(opstr, "\t$rs, $imm16"), [], NoItinerary, FrmOther, opstr>; 1096// Mul, Div 1097class Mult<string opstr, InstrItinClass itin, RegisterOperand RO, 1098 list<Register> DefRegs> : 1099 InstSE<(outs), (ins RO:$rs, RO:$rt), !strconcat(opstr, "\t$rs, $rt"), [], 1100 itin, FrmR, opstr> { 1101 let isCommutable = 1; 1102 let Defs = DefRegs; 1103 let hasSideEffects = 0; 1104} 1105 1106// Pseudo multiply/divide instruction with explicit accumulator register 1107// operands. 1108class MultDivPseudo<Instruction RealInst, RegisterClass R0, RegisterOperand R1, 1109 SDPatternOperator OpNode, InstrItinClass Itin, 1110 bit IsComm = 1, bit HasSideEffects = 0, 1111 bit UsesCustomInserter = 0> : 1112 PseudoSE<(outs R0:$ac), (ins R1:$rs, R1:$rt), 1113 [(set R0:$ac, (OpNode R1:$rs, R1:$rt))], Itin>, 1114 PseudoInstExpansion<(RealInst R1:$rs, R1:$rt)> { 1115 let isCommutable = IsComm; 1116 let hasSideEffects = HasSideEffects; 1117 let usesCustomInserter = UsesCustomInserter; 1118} 1119 1120// Pseudo multiply add/sub instruction with explicit accumulator register 1121// operands. 1122class MAddSubPseudo<Instruction RealInst, SDPatternOperator OpNode, 1123 InstrItinClass itin> 1124 : PseudoSE<(outs ACC64:$ac), 1125 (ins GPR32Opnd:$rs, GPR32Opnd:$rt, ACC64:$acin), 1126 [(set ACC64:$ac, 1127 (OpNode GPR32Opnd:$rs, GPR32Opnd:$rt, ACC64:$acin))], 1128 itin>, 1129 PseudoInstExpansion<(RealInst GPR32Opnd:$rs, GPR32Opnd:$rt)> { 1130 string Constraints = "$acin = $ac"; 1131} 1132 1133class Div<string opstr, InstrItinClass itin, RegisterOperand RO, 1134 list<Register> DefRegs> : 1135 InstSE<(outs), (ins RO:$rs, RO:$rt), !strconcat(opstr, "\t$$zero, $rs, $rt"), 1136 [], itin, FrmR, opstr> { 1137 let Defs = DefRegs; 1138} 1139 1140// Move from Hi/Lo 1141class PseudoMFLOHI<RegisterClass DstRC, RegisterClass SrcRC, SDNode OpNode> 1142 : PseudoSE<(outs DstRC:$rd), (ins SrcRC:$hilo), 1143 [(set DstRC:$rd, (OpNode SrcRC:$hilo))], II_MFHI_MFLO>; 1144 1145class MoveFromLOHI<string opstr, RegisterOperand RO, Register UseReg>: 1146 InstSE<(outs RO:$rd), (ins), !strconcat(opstr, "\t$rd"), [], II_MFHI_MFLO, 1147 FrmR, opstr> { 1148 let Uses = [UseReg]; 1149 let hasSideEffects = 0; 1150} 1151 1152class PseudoMTLOHI<RegisterClass DstRC, RegisterClass SrcRC> 1153 : PseudoSE<(outs DstRC:$lohi), (ins SrcRC:$lo, SrcRC:$hi), 1154 [(set DstRC:$lohi, (MipsMTLOHI SrcRC:$lo, SrcRC:$hi))], 1155 II_MTHI_MTLO>; 1156 1157class MoveToLOHI<string opstr, RegisterOperand RO, list<Register> DefRegs>: 1158 InstSE<(outs), (ins RO:$rs), !strconcat(opstr, "\t$rs"), [], II_MTHI_MTLO, 1159 FrmR, opstr> { 1160 let Defs = DefRegs; 1161 let hasSideEffects = 0; 1162} 1163 1164class EffectiveAddress<string opstr, RegisterOperand RO> : 1165 InstSE<(outs RO:$rt), (ins mem_ea:$addr), !strconcat(opstr, "\t$rt, $addr"), 1166 [(set RO:$rt, addr:$addr)], NoItinerary, FrmI, 1167 !strconcat(opstr, "_lea")> { 1168 let isCodeGenOnly = 1; 1169 let DecoderMethod = "DecodeMem"; 1170} 1171 1172// Count Leading Ones/Zeros in Word 1173class CountLeading0<string opstr, RegisterOperand RO>: 1174 InstSE<(outs RO:$rd), (ins RO:$rs), !strconcat(opstr, "\t$rd, $rs"), 1175 [(set RO:$rd, (ctlz RO:$rs))], II_CLZ, FrmR, opstr>; 1176 1177class CountLeading1<string opstr, RegisterOperand RO>: 1178 InstSE<(outs RO:$rd), (ins RO:$rs), !strconcat(opstr, "\t$rd, $rs"), 1179 [(set RO:$rd, (ctlz (not RO:$rs)))], II_CLO, FrmR, opstr>; 1180 1181// Sign Extend in Register. 1182class SignExtInReg<string opstr, ValueType vt, RegisterOperand RO, 1183 InstrItinClass itin> : 1184 InstSE<(outs RO:$rd), (ins RO:$rt), !strconcat(opstr, "\t$rd, $rt"), 1185 [(set RO:$rd, (sext_inreg RO:$rt, vt))], itin, FrmR, opstr>; 1186 1187// Subword Swap 1188class SubwordSwap<string opstr, RegisterOperand RO, 1189 InstrItinClass itin = NoItinerary>: 1190 InstSE<(outs RO:$rd), (ins RO:$rt), !strconcat(opstr, "\t$rd, $rt"), [], itin, 1191 FrmR, opstr> { 1192 let hasSideEffects = 0; 1193} 1194 1195// Read Hardware 1196class ReadHardware<RegisterOperand CPURegOperand, RegisterOperand RO> : 1197 InstSE<(outs CPURegOperand:$rt), (ins RO:$rd), "rdhwr\t$rt, $rd", [], 1198 II_RDHWR, FrmR, "rdhwr">; 1199 1200// Ext and Ins 1201class ExtBase<string opstr, RegisterOperand RO, Operand PosOpnd, 1202 Operand SizeOpnd, SDPatternOperator Op = null_frag> : 1203 InstSE<(outs RO:$rt), (ins RO:$rs, PosOpnd:$pos, SizeOpnd:$size), 1204 !strconcat(opstr, " $rt, $rs, $pos, $size"), 1205 [(set RO:$rt, (Op RO:$rs, imm:$pos, imm:$size))], II_EXT, 1206 FrmR, opstr>, ISA_MIPS32R2; 1207 1208class InsBase<string opstr, RegisterOperand RO, Operand PosOpnd, 1209 SDPatternOperator Op = null_frag>: 1210 InstSE<(outs RO:$rt), (ins RO:$rs, PosOpnd:$pos, size_ins:$size, RO:$src), 1211 !strconcat(opstr, " $rt, $rs, $pos, $size"), 1212 [(set RO:$rt, (Op RO:$rs, imm:$pos, imm:$size, RO:$src))], 1213 II_INS, FrmR, opstr>, ISA_MIPS32R2 { 1214 let Constraints = "$src = $rt"; 1215} 1216 1217// Atomic instructions with 2 source operands (ATOMIC_SWAP & ATOMIC_LOAD_*). 1218class Atomic2Ops<PatFrag Op, RegisterClass DRC> : 1219 PseudoSE<(outs DRC:$dst), (ins PtrRC:$ptr, DRC:$incr), 1220 [(set DRC:$dst, (Op iPTR:$ptr, DRC:$incr))]>; 1221 1222// Atomic Compare & Swap. 1223class AtomicCmpSwap<PatFrag Op, RegisterClass DRC> : 1224 PseudoSE<(outs DRC:$dst), (ins PtrRC:$ptr, DRC:$cmp, DRC:$swap), 1225 [(set DRC:$dst, (Op iPTR:$ptr, DRC:$cmp, DRC:$swap))]>; 1226 1227class LLBase<string opstr, RegisterOperand RO> : 1228 InstSE<(outs RO:$rt), (ins mem:$addr), !strconcat(opstr, "\t$rt, $addr"), 1229 [], NoItinerary, FrmI> { 1230 let DecoderMethod = "DecodeMem"; 1231 let mayLoad = 1; 1232} 1233 1234class SCBase<string opstr, RegisterOperand RO> : 1235 InstSE<(outs RO:$dst), (ins RO:$rt, mem:$addr), 1236 !strconcat(opstr, "\t$rt, $addr"), [], NoItinerary, FrmI> { 1237 let DecoderMethod = "DecodeMem"; 1238 let mayStore = 1; 1239 let Constraints = "$rt = $dst"; 1240} 1241 1242class MFC3OP<string asmstr, RegisterOperand RO, RegisterOperand RD> : 1243 InstSE<(outs RO:$rt), (ins RD:$rd, uimm16:$sel), 1244 !strconcat(asmstr, "\t$rt, $rd, $sel"), [], NoItinerary, FrmFR>; 1245 1246class MTC3OP<string asmstr, RegisterOperand RO, RegisterOperand RD> : 1247 InstSE<(outs RO:$rd), (ins RD:$rt, uimm16:$sel), 1248 !strconcat(asmstr, "\t$rt, $rd, $sel"), [], NoItinerary, FrmFR>; 1249 1250class TrapBase<Instruction RealInst> 1251 : PseudoSE<(outs), (ins), [(trap)], NoItinerary>, 1252 PseudoInstExpansion<(RealInst 0, 0)> { 1253 let isBarrier = 1; 1254 let isTerminator = 1; 1255 let isCodeGenOnly = 1; 1256} 1257 1258//===----------------------------------------------------------------------===// 1259// Pseudo instructions 1260//===----------------------------------------------------------------------===// 1261 1262// Return RA. 1263let isReturn=1, isTerminator=1, hasDelaySlot=1, isBarrier=1, hasCtrlDep=1 in 1264def RetRA : PseudoSE<(outs), (ins), [(MipsRet)]>; 1265 1266let isReturn=1, isTerminator=1, isBarrier=1, hasCtrlDep=1, hasSideEffects=1 in 1267def ERet : PseudoSE<(outs), (ins), [(MipsERet)]>; 1268 1269let Defs = [SP], Uses = [SP], hasSideEffects = 1 in { 1270def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins i32imm:$amt), 1271 [(callseq_start timm:$amt)]>; 1272def ADJCALLSTACKUP : MipsPseudo<(outs), (ins i32imm:$amt1, i32imm:$amt2), 1273 [(callseq_end timm:$amt1, timm:$amt2)]>; 1274} 1275 1276let usesCustomInserter = 1 in { 1277 def ATOMIC_LOAD_ADD_I8 : Atomic2Ops<atomic_load_add_8, GPR32>; 1278 def ATOMIC_LOAD_ADD_I16 : Atomic2Ops<atomic_load_add_16, GPR32>; 1279 def ATOMIC_LOAD_ADD_I32 : Atomic2Ops<atomic_load_add_32, GPR32>; 1280 def ATOMIC_LOAD_SUB_I8 : Atomic2Ops<atomic_load_sub_8, GPR32>; 1281 def ATOMIC_LOAD_SUB_I16 : Atomic2Ops<atomic_load_sub_16, GPR32>; 1282 def ATOMIC_LOAD_SUB_I32 : Atomic2Ops<atomic_load_sub_32, GPR32>; 1283 def ATOMIC_LOAD_AND_I8 : Atomic2Ops<atomic_load_and_8, GPR32>; 1284 def ATOMIC_LOAD_AND_I16 : Atomic2Ops<atomic_load_and_16, GPR32>; 1285 def ATOMIC_LOAD_AND_I32 : Atomic2Ops<atomic_load_and_32, GPR32>; 1286 def ATOMIC_LOAD_OR_I8 : Atomic2Ops<atomic_load_or_8, GPR32>; 1287 def ATOMIC_LOAD_OR_I16 : Atomic2Ops<atomic_load_or_16, GPR32>; 1288 def ATOMIC_LOAD_OR_I32 : Atomic2Ops<atomic_load_or_32, GPR32>; 1289 def ATOMIC_LOAD_XOR_I8 : Atomic2Ops<atomic_load_xor_8, GPR32>; 1290 def ATOMIC_LOAD_XOR_I16 : Atomic2Ops<atomic_load_xor_16, GPR32>; 1291 def ATOMIC_LOAD_XOR_I32 : Atomic2Ops<atomic_load_xor_32, GPR32>; 1292 def ATOMIC_LOAD_NAND_I8 : Atomic2Ops<atomic_load_nand_8, GPR32>; 1293 def ATOMIC_LOAD_NAND_I16 : Atomic2Ops<atomic_load_nand_16, GPR32>; 1294 def ATOMIC_LOAD_NAND_I32 : Atomic2Ops<atomic_load_nand_32, GPR32>; 1295 1296 def ATOMIC_SWAP_I8 : Atomic2Ops<atomic_swap_8, GPR32>; 1297 def ATOMIC_SWAP_I16 : Atomic2Ops<atomic_swap_16, GPR32>; 1298 def ATOMIC_SWAP_I32 : Atomic2Ops<atomic_swap_32, GPR32>; 1299 1300 def ATOMIC_CMP_SWAP_I8 : AtomicCmpSwap<atomic_cmp_swap_8, GPR32>; 1301 def ATOMIC_CMP_SWAP_I16 : AtomicCmpSwap<atomic_cmp_swap_16, GPR32>; 1302 def ATOMIC_CMP_SWAP_I32 : AtomicCmpSwap<atomic_cmp_swap_32, GPR32>; 1303} 1304 1305/// Pseudo instructions for loading and storing accumulator registers. 1306let isPseudo = 1, isCodeGenOnly = 1 in { 1307 def LOAD_ACC64 : Load<"", ACC64>; 1308 def STORE_ACC64 : Store<"", ACC64>; 1309} 1310 1311// We need these two pseudo instructions to avoid offset calculation for long 1312// branches. See the comment in file MipsLongBranch.cpp for detailed 1313// explanation. 1314 1315// Expands to: lui $dst, %hi($tgt - $baltgt) 1316def LONG_BRANCH_LUi : PseudoSE<(outs GPR32Opnd:$dst), 1317 (ins brtarget:$tgt, brtarget:$baltgt), []>; 1318 1319// Expands to: addiu $dst, $src, %lo($tgt - $baltgt) 1320def LONG_BRANCH_ADDiu : PseudoSE<(outs GPR32Opnd:$dst), 1321 (ins GPR32Opnd:$src, brtarget:$tgt, brtarget:$baltgt), []>; 1322 1323//===----------------------------------------------------------------------===// 1324// Instruction definition 1325//===----------------------------------------------------------------------===// 1326//===----------------------------------------------------------------------===// 1327// MipsI Instructions 1328//===----------------------------------------------------------------------===// 1329 1330/// Arithmetic Instructions (ALU Immediate) 1331let AdditionalPredicates = [NotInMicroMips] in { 1332def ADDiu : MMRel, StdMMR6Rel, ArithLogicI<"addiu", simm16, GPR32Opnd, 1333 II_ADDIU, immSExt16, add>, 1334 ADDI_FM<0x9>, IsAsCheapAsAMove; 1335} 1336def ADDi : MMRel, ArithLogicI<"addi", simm16, GPR32Opnd>, ADDI_FM<0x8>, 1337 ISA_MIPS1_NOT_32R6_64R6; 1338def SLTi : MMRel, SetCC_I<"slti", setlt, simm16, immSExt16, GPR32Opnd>, 1339 SLTI_FM<0xa>; 1340def SLTiu : MMRel, SetCC_I<"sltiu", setult, simm16, immSExt16, GPR32Opnd>, 1341 SLTI_FM<0xb>; 1342let AdditionalPredicates = [NotInMicroMips] in { 1343def ANDi : MMRel, StdMMR6Rel, 1344 ArithLogicI<"andi", uimm16, GPR32Opnd, II_ANDI, immZExt16, and>, 1345 ADDI_FM<0xc>; 1346} 1347def ORi : MMRel, StdMMR6Rel, 1348 ArithLogicI<"ori", uimm16, GPR32Opnd, II_ORI, immZExt16, or>, 1349 ADDI_FM<0xd>; 1350def XORi : MMRel, StdMMR6Rel, 1351 ArithLogicI<"xori", uimm16, GPR32Opnd, II_XORI, immZExt16, xor>, 1352 ADDI_FM<0xe>; 1353def LUi : MMRel, LoadUpper<"lui", GPR32Opnd, uimm16>, LUI_FM; 1354let AdditionalPredicates = [NotInMicroMips] in { 1355/// Arithmetic Instructions (3-Operand, R-Type) 1356def ADDu : MMRel, StdMMR6Rel, ArithLogicR<"addu", GPR32Opnd, 1, II_ADDU, add>, 1357 ADD_FM<0, 0x21>; 1358def SUBu : MMRel, ArithLogicR<"subu", GPR32Opnd, 0, II_SUBU, sub>, 1359 ADD_FM<0, 0x23>; 1360} 1361let Defs = [HI0, LO0] in 1362def MUL : MMRel, ArithLogicR<"mul", GPR32Opnd, 1, II_MUL, mul>, 1363 ADD_FM<0x1c, 2>, ISA_MIPS32_NOT_32R6_64R6; 1364def ADD : MMRel, StdMMR6Rel, ArithLogicR<"add", GPR32Opnd>, ADD_FM<0, 0x20>; 1365def SUB : MMRel, ArithLogicR<"sub", GPR32Opnd>, ADD_FM<0, 0x22>; 1366def SLT : MMRel, SetCC_R<"slt", setlt, GPR32Opnd>, ADD_FM<0, 0x2a>; 1367def SLTu : MMRel, SetCC_R<"sltu", setult, GPR32Opnd>, ADD_FM<0, 0x2b>; 1368let AdditionalPredicates = [NotInMicroMips] in { 1369def AND : MMRel, StdMMR6Rel, ArithLogicR<"and", GPR32Opnd, 1, II_AND, and>, 1370 ADD_FM<0, 0x24>; 1371def OR : MMRel, StdMMR6Rel, ArithLogicR<"or", GPR32Opnd, 1, II_OR, or>, 1372 ADD_FM<0, 0x25>; 1373def XOR : MMRel, StdMMR6Rel, ArithLogicR<"xor", GPR32Opnd, 1, II_XOR, xor>, 1374 ADD_FM<0, 0x26>; 1375} 1376def NOR : MMRel, StdMMR6Rel, LogicNOR<"nor", GPR32Opnd>, ADD_FM<0, 0x27>; 1377 1378/// Shift Instructions 1379let AdditionalPredicates = [NotInMicroMips] in { 1380def SLL : MMRel, shift_rotate_imm<"sll", uimm5, GPR32Opnd, II_SLL, shl, 1381 immZExt5>, SRA_FM<0, 0>; 1382def SRL : MMRel, shift_rotate_imm<"srl", uimm5, GPR32Opnd, II_SRL, srl, 1383 immZExt5>, SRA_FM<2, 0>; 1384} 1385def SRA : MMRel, shift_rotate_imm<"sra", uimm5, GPR32Opnd, II_SRA, sra, 1386 immZExt5>, SRA_FM<3, 0>; 1387def SLLV : MMRel, shift_rotate_reg<"sllv", GPR32Opnd, II_SLLV, shl>, 1388 SRLV_FM<4, 0>; 1389def SRLV : MMRel, shift_rotate_reg<"srlv", GPR32Opnd, II_SRLV, srl>, 1390 SRLV_FM<6, 0>; 1391def SRAV : MMRel, shift_rotate_reg<"srav", GPR32Opnd, II_SRAV, sra>, 1392 SRLV_FM<7, 0>; 1393 1394// Rotate Instructions 1395def ROTR : MMRel, shift_rotate_imm<"rotr", uimm5, GPR32Opnd, II_ROTR, rotr, 1396 immZExt5>, 1397 SRA_FM<2, 1>, ISA_MIPS32R2; 1398def ROTRV : MMRel, shift_rotate_reg<"rotrv", GPR32Opnd, II_ROTRV, rotr>, 1399 SRLV_FM<6, 1>, ISA_MIPS32R2; 1400 1401/// Load and Store Instructions 1402/// aligned 1403def LB : Load<"lb", GPR32Opnd, sextloadi8, II_LB>, MMRel, LW_FM<0x20>; 1404def LBu : Load<"lbu", GPR32Opnd, zextloadi8, II_LBU, addrDefault>, MMRel, 1405 LW_FM<0x24>; 1406def LH : Load<"lh", GPR32Opnd, sextloadi16, II_LH, addrDefault>, MMRel, 1407 LW_FM<0x21>; 1408def LHu : Load<"lhu", GPR32Opnd, zextloadi16, II_LHU>, MMRel, LW_FM<0x25>; 1409let AdditionalPredicates = [NotInMicroMips] in { 1410def LW : StdMMR6Rel, Load<"lw", GPR32Opnd, load, II_LW, addrDefault>, MMRel, 1411 LW_FM<0x23>; 1412} 1413def SB : StdMMR6Rel, Store<"sb", GPR32Opnd, truncstorei8, II_SB>, MMRel, 1414 LW_FM<0x28>; 1415def SH : Store<"sh", GPR32Opnd, truncstorei16, II_SH>, MMRel, LW_FM<0x29>; 1416let AdditionalPredicates = [NotInMicroMips] in { 1417def SW : Store<"sw", GPR32Opnd, store, II_SW>, MMRel, LW_FM<0x2b>; 1418} 1419 1420/// load/store left/right 1421let EncodingPredicates = []<Predicate>, // FIXME: Lack of HasStdEnc is probably a bug 1422 AdditionalPredicates = [NotInMicroMips] in { 1423def LWL : LoadLeftRight<"lwl", MipsLWL, GPR32Opnd, II_LWL>, LW_FM<0x22>, 1424 ISA_MIPS1_NOT_32R6_64R6; 1425def LWR : LoadLeftRight<"lwr", MipsLWR, GPR32Opnd, II_LWR>, LW_FM<0x26>, 1426 ISA_MIPS1_NOT_32R6_64R6; 1427def SWL : StoreLeftRight<"swl", MipsSWL, GPR32Opnd, II_SWL>, LW_FM<0x2a>, 1428 ISA_MIPS1_NOT_32R6_64R6; 1429def SWR : StoreLeftRight<"swr", MipsSWR, GPR32Opnd, II_SWR>, LW_FM<0x2e>, 1430 ISA_MIPS1_NOT_32R6_64R6; 1431} 1432 1433let AdditionalPredicates = [NotInMicroMips] in { 1434// COP2 Memory Instructions 1435def LWC2 : LW_FT2<"lwc2", COP2Opnd, NoItinerary, load>, LW_FM<0x32>, 1436 ISA_MIPS1_NOT_32R6_64R6; 1437def SWC2 : SW_FT2<"swc2", COP2Opnd, NoItinerary, store>, LW_FM<0x3a>, 1438 ISA_MIPS1_NOT_32R6_64R6; 1439def LDC2 : LW_FT2<"ldc2", COP2Opnd, NoItinerary, load>, LW_FM<0x36>, 1440 ISA_MIPS2_NOT_32R6_64R6; 1441def SDC2 : SW_FT2<"sdc2", COP2Opnd, NoItinerary, store>, LW_FM<0x3e>, 1442 ISA_MIPS2_NOT_32R6_64R6; 1443 1444// COP3 Memory Instructions 1445let DecoderNamespace = "COP3_" in { 1446 def LWC3 : LW_FT3<"lwc3", COP3Opnd, NoItinerary, load>, LW_FM<0x33>; 1447 def SWC3 : SW_FT3<"swc3", COP3Opnd, NoItinerary, store>, LW_FM<0x3b>; 1448 def LDC3 : LW_FT3<"ldc3", COP3Opnd, NoItinerary, load>, LW_FM<0x37>, 1449 ISA_MIPS2; 1450 def SDC3 : SW_FT3<"sdc3", COP3Opnd, NoItinerary, store>, LW_FM<0x3f>, 1451 ISA_MIPS2; 1452} 1453} 1454 1455def SYNC : MMRel, StdMMR6Rel, SYNC_FT<"sync">, SYNC_FM, ISA_MIPS32; 1456def SYNCI : MMRel, StdMMR6Rel, SYNCI_FT<"synci">, SYNCI_FM, ISA_MIPS32R2; 1457 1458let AdditionalPredicates = [NotInMicroMips] in { 1459 def TEQ : MMRel, TEQ_FT<"teq", GPR32Opnd>, TEQ_FM<0x34>, ISA_MIPS2; 1460 def TGE : MMRel, TEQ_FT<"tge", GPR32Opnd>, TEQ_FM<0x30>, ISA_MIPS2; 1461 def TGEU : MMRel, TEQ_FT<"tgeu", GPR32Opnd>, TEQ_FM<0x31>, ISA_MIPS2; 1462 def TLT : MMRel, TEQ_FT<"tlt", GPR32Opnd>, TEQ_FM<0x32>, ISA_MIPS2; 1463 def TLTU : MMRel, TEQ_FT<"tltu", GPR32Opnd>, TEQ_FM<0x33>, ISA_MIPS2; 1464 def TNE : MMRel, TEQ_FT<"tne", GPR32Opnd>, TEQ_FM<0x36>, ISA_MIPS2; 1465} 1466 1467def TEQI : MMRel, TEQI_FT<"teqi", GPR32Opnd>, TEQI_FM<0xc>, 1468 ISA_MIPS2_NOT_32R6_64R6; 1469def TGEI : MMRel, TEQI_FT<"tgei", GPR32Opnd>, TEQI_FM<0x8>, 1470 ISA_MIPS2_NOT_32R6_64R6; 1471def TGEIU : MMRel, TEQI_FT<"tgeiu", GPR32Opnd>, TEQI_FM<0x9>, 1472 ISA_MIPS2_NOT_32R6_64R6; 1473def TLTI : MMRel, TEQI_FT<"tlti", GPR32Opnd>, TEQI_FM<0xa>, 1474 ISA_MIPS2_NOT_32R6_64R6; 1475def TTLTIU : MMRel, TEQI_FT<"tltiu", GPR32Opnd>, TEQI_FM<0xb>, 1476 ISA_MIPS2_NOT_32R6_64R6; 1477def TNEI : MMRel, TEQI_FT<"tnei", GPR32Opnd>, TEQI_FM<0xe>, 1478 ISA_MIPS2_NOT_32R6_64R6; 1479 1480let AdditionalPredicates = [NotInMicroMips] in { 1481def BREAK : MMRel, StdMMR6Rel, BRK_FT<"break">, BRK_FM<0xd>; 1482} 1483def SYSCALL : MMRel, SYS_FT<"syscall">, SYS_FM<0xc>; 1484def TRAP : TrapBase<BREAK>; 1485def SDBBP : MMRel, SYS_FT<"sdbbp">, SDBBP_FM, ISA_MIPS32_NOT_32R6_64R6; 1486 1487let AdditionalPredicates = [NotInMicroMips] in { 1488 def ERET : MMRel, ER_FT<"eret">, ER_FM<0x18, 0x0>, INSN_MIPS3_32; 1489 def ERETNC : MMRel, ER_FT<"eretnc">, ER_FM<0x18, 0x1>, ISA_MIPS32R5; 1490 def DERET : MMRel, ER_FT<"deret">, ER_FM<0x1f, 0x0>, ISA_MIPS32; 1491} 1492 1493let AdditionalPredicates = [NotInMicroMips] in { 1494 def EI : MMRel, StdMMR6Rel, DEI_FT<"ei", GPR32Opnd>, EI_FM<1>, ISA_MIPS32R2; 1495 def DI : MMRel, StdMMR6Rel, DEI_FT<"di", GPR32Opnd>, EI_FM<0>, ISA_MIPS32R2; 1496} 1497 1498let EncodingPredicates = []<Predicate>, // FIXME: Lack of HasStdEnc is probably a bug 1499 AdditionalPredicates = [NotInMicroMips] in { 1500def WAIT : WAIT_FT<"wait">, WAIT_FM; 1501 1502/// Load-linked, Store-conditional 1503def LL : LLBase<"ll", GPR32Opnd>, LW_FM<0x30>, ISA_MIPS2_NOT_32R6_64R6; 1504def SC : SCBase<"sc", GPR32Opnd>, LW_FM<0x38>, ISA_MIPS2_NOT_32R6_64R6; 1505} 1506 1507/// Jump and Branch Instructions 1508def J : MMRel, JumpFJ<jmptarget, "j", br, bb, "j">, FJ<2>, 1509 AdditionalRequires<[RelocStatic]>, IsBranch; 1510def JR : MMRel, IndirectBranch<"jr", GPR32Opnd>, MTLO_FM<8>; 1511def BEQ : MMRel, CBranch<"beq", brtarget, seteq, GPR32Opnd>, BEQ_FM<4>; 1512def BEQL : MMRel, CBranch<"beql", brtarget, seteq, GPR32Opnd, 0>, 1513 BEQ_FM<20>, ISA_MIPS2_NOT_32R6_64R6; 1514def BNE : MMRel, CBranch<"bne", brtarget, setne, GPR32Opnd>, BEQ_FM<5>; 1515def BNEL : MMRel, CBranch<"bnel", brtarget, setne, GPR32Opnd, 0>, 1516 BEQ_FM<21>, ISA_MIPS2_NOT_32R6_64R6; 1517def BGEZ : MMRel, CBranchZero<"bgez", brtarget, setge, GPR32Opnd>, 1518 BGEZ_FM<1, 1>; 1519def BGEZL : MMRel, CBranchZero<"bgezl", brtarget, setge, GPR32Opnd, 0>, 1520 BGEZ_FM<1, 3>, ISA_MIPS2_NOT_32R6_64R6; 1521def BGTZ : MMRel, CBranchZero<"bgtz", brtarget, setgt, GPR32Opnd>, 1522 BGEZ_FM<7, 0>; 1523def BGTZL : MMRel, CBranchZero<"bgtzl", brtarget, setgt, GPR32Opnd, 0>, 1524 BGEZ_FM<23, 0>, ISA_MIPS2_NOT_32R6_64R6; 1525def BLEZ : MMRel, CBranchZero<"blez", brtarget, setle, GPR32Opnd>, 1526 BGEZ_FM<6, 0>; 1527def BLEZL : MMRel, CBranchZero<"blezl", brtarget, setle, GPR32Opnd, 0>, 1528 BGEZ_FM<22, 0>, ISA_MIPS2_NOT_32R6_64R6; 1529def BLTZ : MMRel, CBranchZero<"bltz", brtarget, setlt, GPR32Opnd>, 1530 BGEZ_FM<1, 0>; 1531def BLTZL : MMRel, CBranchZero<"bltzl", brtarget, setlt, GPR32Opnd, 0>, 1532 BGEZ_FM<1, 2>, ISA_MIPS2_NOT_32R6_64R6; 1533def B : UncondBranch<BEQ>; 1534 1535def JAL : MMRel, JumpLink<"jal", calltarget>, FJ<3>; 1536let AdditionalPredicates = [NotInMicroMips] in { 1537 def JALR : JumpLinkReg<"jalr", GPR32Opnd>, JALR_FM; 1538 def JALRPseudo : JumpLinkRegPseudo<GPR32Opnd, JALR, RA>; 1539} 1540 1541def JALX : MMRel, JumpLink<"jalx", calltarget>, FJ<0x1D>, 1542 ISA_MIPS32_NOT_32R6_64R6; 1543def BGEZAL : MMRel, BGEZAL_FT<"bgezal", brtarget, GPR32Opnd>, BGEZAL_FM<0x11>, 1544 ISA_MIPS1_NOT_32R6_64R6; 1545def BGEZALL : MMRel, BGEZAL_FT<"bgezall", brtarget, GPR32Opnd, 0>, 1546 BGEZAL_FM<0x13>, ISA_MIPS2_NOT_32R6_64R6; 1547def BLTZAL : MMRel, BGEZAL_FT<"bltzal", brtarget, GPR32Opnd>, BGEZAL_FM<0x10>, 1548 ISA_MIPS1_NOT_32R6_64R6; 1549def BLTZALL : MMRel, BGEZAL_FT<"bltzall", brtarget, GPR32Opnd, 0>, 1550 BGEZAL_FM<0x12>, ISA_MIPS2_NOT_32R6_64R6; 1551def BAL_BR : BAL_BR_Pseudo<BGEZAL>; 1552def TAILCALL : TailCall<J>; 1553def TAILCALL_R : TailCallReg<GPR32Opnd, JR>; 1554 1555// Indirect branches are matched as PseudoIndirectBranch/PseudoIndirectBranch64 1556// then are expanded to JR, JR64, JALR, or JALR64 depending on the ISA. 1557class PseudoIndirectBranchBase<RegisterOperand RO> : 1558 MipsPseudo<(outs), (ins RO:$rs), [(brind RO:$rs)], 1559 II_IndirectBranchPseudo> { 1560 let isTerminator=1; 1561 let isBarrier=1; 1562 let hasDelaySlot = 1; 1563 let isBranch = 1; 1564 let isIndirectBranch = 1; 1565} 1566 1567def PseudoIndirectBranch : PseudoIndirectBranchBase<GPR32Opnd>; 1568 1569// Return instructions are matched as a RetRA instruction, then are expanded 1570// into PseudoReturn/PseudoReturn64 after register allocation. Finally, 1571// MipsAsmPrinter expands this into JR, JR64, JALR, or JALR64 depending on the 1572// ISA. 1573class PseudoReturnBase<RegisterOperand RO> : MipsPseudo<(outs), (ins RO:$rs), 1574 [], II_ReturnPseudo> { 1575 let isTerminator = 1; 1576 let isBarrier = 1; 1577 let hasDelaySlot = 1; 1578 let isReturn = 1; 1579 let isCodeGenOnly = 1; 1580 let hasCtrlDep = 1; 1581 let hasExtraSrcRegAllocReq = 1; 1582} 1583 1584def PseudoReturn : PseudoReturnBase<GPR32Opnd>; 1585 1586// Exception handling related node and instructions. 1587// The conversion sequence is: 1588// ISD::EH_RETURN -> MipsISD::EH_RETURN -> 1589// MIPSeh_return -> (stack change + indirect branch) 1590// 1591// MIPSeh_return takes the place of regular return instruction 1592// but takes two arguments (V1, V0) which are used for storing 1593// the offset and return address respectively. 1594def SDT_MipsEHRET : SDTypeProfile<0, 2, [SDTCisInt<0>, SDTCisPtrTy<1>]>; 1595 1596def MIPSehret : SDNode<"MipsISD::EH_RETURN", SDT_MipsEHRET, 1597 [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>; 1598 1599let Uses = [V0, V1], isTerminator = 1, isReturn = 1, isBarrier = 1 in { 1600 def MIPSeh_return32 : MipsPseudo<(outs), (ins GPR32:$spoff, GPR32:$dst), 1601 [(MIPSehret GPR32:$spoff, GPR32:$dst)]>; 1602 def MIPSeh_return64 : MipsPseudo<(outs), (ins GPR64:$spoff, 1603 GPR64:$dst), 1604 [(MIPSehret GPR64:$spoff, GPR64:$dst)]>; 1605} 1606 1607/// Multiply and Divide Instructions. 1608def MULT : MMRel, Mult<"mult", II_MULT, GPR32Opnd, [HI0, LO0]>, 1609 MULT_FM<0, 0x18>, ISA_MIPS1_NOT_32R6_64R6; 1610def MULTu : MMRel, Mult<"multu", II_MULTU, GPR32Opnd, [HI0, LO0]>, 1611 MULT_FM<0, 0x19>, ISA_MIPS1_NOT_32R6_64R6; 1612def SDIV : MMRel, Div<"div", II_DIV, GPR32Opnd, [HI0, LO0]>, 1613 MULT_FM<0, 0x1a>, ISA_MIPS1_NOT_32R6_64R6; 1614def UDIV : MMRel, Div<"divu", II_DIVU, GPR32Opnd, [HI0, LO0]>, 1615 MULT_FM<0, 0x1b>, ISA_MIPS1_NOT_32R6_64R6; 1616 1617def MTHI : MMRel, MoveToLOHI<"mthi", GPR32Opnd, [HI0]>, MTLO_FM<0x11>, 1618 ISA_MIPS1_NOT_32R6_64R6; 1619def MTLO : MMRel, MoveToLOHI<"mtlo", GPR32Opnd, [LO0]>, MTLO_FM<0x13>, 1620 ISA_MIPS1_NOT_32R6_64R6; 1621let EncodingPredicates = []<Predicate>, // FIXME: Lack of HasStdEnc is probably a bug 1622 AdditionalPredicates = [NotInMicroMips] in { 1623def MFHI : MMRel, MoveFromLOHI<"mfhi", GPR32Opnd, AC0>, MFLO_FM<0x10>, 1624 ISA_MIPS1_NOT_32R6_64R6; 1625def MFLO : MMRel, MoveFromLOHI<"mflo", GPR32Opnd, AC0>, MFLO_FM<0x12>, 1626 ISA_MIPS1_NOT_32R6_64R6; 1627} 1628 1629/// Sign Ext In Register Instructions. 1630def SEB : MMRel, StdMMR6Rel, SignExtInReg<"seb", i8, GPR32Opnd, II_SEB>, 1631 SEB_FM<0x10, 0x20>, ISA_MIPS32R2; 1632def SEH : MMRel, StdMMR6Rel, SignExtInReg<"seh", i16, GPR32Opnd, II_SEH>, 1633 SEB_FM<0x18, 0x20>, ISA_MIPS32R2; 1634 1635/// Count Leading 1636def CLZ : MMRel, CountLeading0<"clz", GPR32Opnd>, CLO_FM<0x20>, 1637 ISA_MIPS32_NOT_32R6_64R6; 1638def CLO : MMRel, CountLeading1<"clo", GPR32Opnd>, CLO_FM<0x21>, 1639 ISA_MIPS32_NOT_32R6_64R6; 1640 1641let AdditionalPredicates = [NotInMicroMips] in { 1642 /// Word Swap Bytes Within Halfwords 1643 def WSBH : MMRel, SubwordSwap<"wsbh", GPR32Opnd, II_WSBH>, SEB_FM<2, 0x20>, 1644 ISA_MIPS32R2; 1645} 1646 1647/// No operation. 1648def NOP : PseudoSE<(outs), (ins), []>, PseudoInstExpansion<(SLL ZERO, ZERO, 0)>; 1649 1650// FrameIndexes are legalized when they are operands from load/store 1651// instructions. The same not happens for stack address copies, so an 1652// add op with mem ComplexPattern is used and the stack address copy 1653// can be matched. It's similar to Sparc LEA_ADDRi 1654def LEA_ADDiu : MMRel, EffectiveAddress<"addiu", GPR32Opnd>, LW_FM<9>; 1655 1656// MADD*/MSUB* 1657def MADD : MMRel, MArithR<"madd", II_MADD, 1>, MULT_FM<0x1c, 0>, 1658 ISA_MIPS32_NOT_32R6_64R6; 1659def MADDU : MMRel, MArithR<"maddu", II_MADDU, 1>, MULT_FM<0x1c, 1>, 1660 ISA_MIPS32_NOT_32R6_64R6; 1661def MSUB : MMRel, MArithR<"msub", II_MSUB>, MULT_FM<0x1c, 4>, 1662 ISA_MIPS32_NOT_32R6_64R6; 1663def MSUBU : MMRel, MArithR<"msubu", II_MSUBU>, MULT_FM<0x1c, 5>, 1664 ISA_MIPS32_NOT_32R6_64R6; 1665 1666let AdditionalPredicates = [NotDSP] in { 1667def PseudoMULT : MultDivPseudo<MULT, ACC64, GPR32Opnd, MipsMult, II_MULT>, 1668 ISA_MIPS1_NOT_32R6_64R6; 1669def PseudoMULTu : MultDivPseudo<MULTu, ACC64, GPR32Opnd, MipsMultu, II_MULTU>, 1670 ISA_MIPS1_NOT_32R6_64R6; 1671def PseudoMFHI : PseudoMFLOHI<GPR32, ACC64, MipsMFHI>, ISA_MIPS1_NOT_32R6_64R6; 1672def PseudoMFLO : PseudoMFLOHI<GPR32, ACC64, MipsMFLO>, ISA_MIPS1_NOT_32R6_64R6; 1673def PseudoMTLOHI : PseudoMTLOHI<ACC64, GPR32>, ISA_MIPS1_NOT_32R6_64R6; 1674def PseudoMADD : MAddSubPseudo<MADD, MipsMAdd, II_MADD>, 1675 ISA_MIPS32_NOT_32R6_64R6; 1676def PseudoMADDU : MAddSubPseudo<MADDU, MipsMAddu, II_MADDU>, 1677 ISA_MIPS32_NOT_32R6_64R6; 1678def PseudoMSUB : MAddSubPseudo<MSUB, MipsMSub, II_MSUB>, 1679 ISA_MIPS32_NOT_32R6_64R6; 1680def PseudoMSUBU : MAddSubPseudo<MSUBU, MipsMSubu, II_MSUBU>, 1681 ISA_MIPS32_NOT_32R6_64R6; 1682} 1683 1684def PseudoSDIV : MultDivPseudo<SDIV, ACC64, GPR32Opnd, MipsDivRem, II_DIV, 1685 0, 1, 1>, ISA_MIPS1_NOT_32R6_64R6; 1686def PseudoUDIV : MultDivPseudo<UDIV, ACC64, GPR32Opnd, MipsDivRemU, II_DIVU, 1687 0, 1, 1>, ISA_MIPS1_NOT_32R6_64R6; 1688let AdditionalPredicates = [NotInMicroMips] in { 1689def RDHWR : MMRel, ReadHardware<GPR32Opnd, HWRegsOpnd>, RDHWR_FM; 1690} 1691// TODO: Add '0 < pos+size <= 32' constraint check to ext instruction 1692def EXT : MMRel, ExtBase<"ext", GPR32Opnd, uimm5, uimm5_plus1, MipsExt>, 1693 EXT_FM<0>; 1694def INS : MMRel, InsBase<"ins", GPR32Opnd, uimm5, MipsIns>, EXT_FM<4>; 1695 1696/// Move Control Registers From/To CPU Registers 1697def MFC0 : MFC3OP<"mfc0", GPR32Opnd, COP0Opnd>, MFC3OP_FM<0x10, 0>, ISA_MIPS32; 1698def MTC0 : MTC3OP<"mtc0", COP0Opnd, GPR32Opnd>, MFC3OP_FM<0x10, 4>, ISA_MIPS32; 1699def MFC2 : MFC3OP<"mfc2", GPR32Opnd, COP2Opnd>, MFC3OP_FM<0x12, 0>; 1700def MTC2 : MTC3OP<"mtc2", COP2Opnd, GPR32Opnd>, MFC3OP_FM<0x12, 4>; 1701 1702class Barrier<string asmstr> : InstSE<(outs), (ins), asmstr, [], NoItinerary, 1703 FrmOther, asmstr>; 1704def SSNOP : MMRel, StdMMR6Rel, Barrier<"ssnop">, BARRIER_FM<1>; 1705def EHB : MMRel, Barrier<"ehb">, BARRIER_FM<3>; 1706def PAUSE : MMRel, StdMMR6Rel, Barrier<"pause">, BARRIER_FM<5>, ISA_MIPS32R2; 1707 1708// JR_HB and JALR_HB are defined here using the new style naming 1709// scheme because some of this code is shared with Mips32r6InstrInfo.td 1710// and because of that it doesn't follow the naming convention of the 1711// rest of the file. To avoid a mixture of old vs new style, the new 1712// style was chosen. 1713class JR_HB_DESC_BASE<string instr_asm, RegisterOperand GPROpnd> { 1714 dag OutOperandList = (outs); 1715 dag InOperandList = (ins GPROpnd:$rs); 1716 string AsmString = !strconcat(instr_asm, "\t$rs"); 1717 list<dag> Pattern = []; 1718} 1719 1720class JALR_HB_DESC_BASE<string instr_asm, RegisterOperand GPROpnd> { 1721 dag OutOperandList = (outs GPROpnd:$rd); 1722 dag InOperandList = (ins GPROpnd:$rs); 1723 string AsmString = !strconcat(instr_asm, "\t$rd, $rs"); 1724 list<dag> Pattern = []; 1725} 1726 1727class JR_HB_DESC : InstSE<(outs), (ins), "", [], NoItinerary, FrmJ>, 1728 JR_HB_DESC_BASE<"jr.hb", GPR32Opnd> { 1729 let isBranch=1; 1730 let isIndirectBranch=1; 1731 let hasDelaySlot=1; 1732 let isTerminator=1; 1733 let isBarrier=1; 1734} 1735 1736class JALR_HB_DESC : InstSE<(outs), (ins), "", [], NoItinerary, FrmJ>, 1737 JALR_HB_DESC_BASE<"jalr.hb", GPR32Opnd> { 1738 let isIndirectBranch=1; 1739 let hasDelaySlot=1; 1740} 1741 1742class JR_HB_ENC : JR_HB_FM<8>; 1743class JALR_HB_ENC : JALR_HB_FM<9>; 1744 1745def JR_HB : JR_HB_DESC, JR_HB_ENC, ISA_MIPS32_NOT_32R6_64R6; 1746def JALR_HB : JALR_HB_DESC, JALR_HB_ENC, ISA_MIPS32; 1747 1748class TLB<string asmstr> : InstSE<(outs), (ins), asmstr, [], NoItinerary, 1749 FrmOther, asmstr>; 1750def TLBP : MMRel, TLB<"tlbp">, COP0_TLB_FM<0x08>; 1751def TLBR : MMRel, TLB<"tlbr">, COP0_TLB_FM<0x01>; 1752def TLBWI : MMRel, TLB<"tlbwi">, COP0_TLB_FM<0x02>; 1753def TLBWR : MMRel, TLB<"tlbwr">, COP0_TLB_FM<0x06>; 1754 1755class CacheOp<string instr_asm, Operand MemOpnd> : 1756 InstSE<(outs), (ins MemOpnd:$addr, uimm5:$hint), 1757 !strconcat(instr_asm, "\t$hint, $addr"), [], NoItinerary, FrmOther, 1758 instr_asm> { 1759 let DecoderMethod = "DecodeCacheOp"; 1760} 1761 1762def CACHE : MMRel, CacheOp<"cache", mem>, CACHEOP_FM<0b101111>, 1763 INSN_MIPS3_32_NOT_32R6_64R6; 1764def PREF : MMRel, CacheOp<"pref", mem>, CACHEOP_FM<0b110011>, 1765 INSN_MIPS3_32_NOT_32R6_64R6; 1766 1767def ROL : MipsAsmPseudoInst<(outs), 1768 (ins GPR32Opnd:$rs, GPR32Opnd:$rt, GPR32Opnd:$rd), 1769 "rol\t$rs, $rt, $rd">; 1770def ROLImm : MipsAsmPseudoInst<(outs), 1771 (ins GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm), 1772 "rol\t$rs, $rt, $imm">; 1773def : MipsInstAlias<"rol $rd, $rs", 1774 (ROL GPR32Opnd:$rd, GPR32Opnd:$rd, GPR32Opnd:$rs), 0>; 1775def : MipsInstAlias<"rol $rd, $imm", 1776 (ROLImm GPR32Opnd:$rd, GPR32Opnd:$rd, simm16:$imm), 0>; 1777 1778def ROR : MipsAsmPseudoInst<(outs), 1779 (ins GPR32Opnd:$rs, GPR32Opnd:$rt, GPR32Opnd:$rd), 1780 "ror\t$rs, $rt, $rd">; 1781def RORImm : MipsAsmPseudoInst<(outs), 1782 (ins GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm), 1783 "ror\t$rs, $rt, $imm">; 1784def : MipsInstAlias<"ror $rd, $rs", 1785 (ROR GPR32Opnd:$rd, GPR32Opnd:$rd, GPR32Opnd:$rs), 0>; 1786def : MipsInstAlias<"ror $rd, $imm", 1787 (RORImm GPR32Opnd:$rd, GPR32Opnd:$rd, simm16:$imm), 0>; 1788 1789def DROL : MipsAsmPseudoInst<(outs), 1790 (ins GPR32Opnd:$rs, GPR32Opnd:$rt, GPR32Opnd:$rd), 1791 "drol\t$rs, $rt, $rd">, ISA_MIPS64; 1792def DROLImm : MipsAsmPseudoInst<(outs), 1793 (ins GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm), 1794 "drol\t$rs, $rt, $imm">, ISA_MIPS64; 1795def : MipsInstAlias<"drol $rd, $rs", 1796 (DROL GPR32Opnd:$rd, GPR32Opnd:$rd, GPR32Opnd:$rs), 0>, ISA_MIPS64; 1797def : MipsInstAlias<"drol $rd, $imm", 1798 (DROLImm GPR32Opnd:$rd, GPR32Opnd:$rd, simm16:$imm), 0>, ISA_MIPS64; 1799 1800def DROR : MipsAsmPseudoInst<(outs), 1801 (ins GPR32Opnd:$rs, GPR32Opnd:$rt, GPR32Opnd:$rd), 1802 "dror\t$rs, $rt, $rd">, ISA_MIPS64; 1803def DRORImm : MipsAsmPseudoInst<(outs), 1804 (ins GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm), 1805 "dror\t$rs, $rt, $imm">, ISA_MIPS64; 1806def : MipsInstAlias<"dror $rd, $rs", 1807 (DROR GPR32Opnd:$rd, GPR32Opnd:$rd, GPR32Opnd:$rs), 0>, ISA_MIPS64; 1808def : MipsInstAlias<"dror $rd, $imm", 1809 (DRORImm GPR32Opnd:$rd, GPR32Opnd:$rd, simm16:$imm), 0>, ISA_MIPS64; 1810 1811//===----------------------------------------------------------------------===// 1812// Instruction aliases 1813//===----------------------------------------------------------------------===// 1814def : MipsInstAlias<"move $dst, $src", 1815 (OR GPR32Opnd:$dst, GPR32Opnd:$src, ZERO), 1>, 1816 GPR_32 { 1817 let AdditionalPredicates = [NotInMicroMips]; 1818} 1819def : MipsInstAlias<"move $dst, $src", 1820 (ADDu GPR32Opnd:$dst, GPR32Opnd:$src, ZERO), 1>, 1821 GPR_32 { 1822 let AdditionalPredicates = [NotInMicroMips]; 1823} 1824def : MipsInstAlias<"bal $offset", (BGEZAL ZERO, brtarget:$offset), 0>, 1825 ISA_MIPS1_NOT_32R6_64R6; 1826def : MipsInstAlias<"addu $rs, $rt, $imm", 1827 (ADDiu GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm), 0>; 1828def : MipsInstAlias<"addu $rs, $imm", 1829 (ADDiu GPR32Opnd:$rs, GPR32Opnd:$rs, simm16:$imm), 0>; 1830def : MipsInstAlias<"add $rs, $rt, $imm", 1831 (ADDi GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm), 0>, 1832 ISA_MIPS1_NOT_32R6_64R6; 1833def : MipsInstAlias<"add $rs, $imm", 1834 (ADDi GPR32Opnd:$rs, GPR32Opnd:$rs, simm16:$imm), 0>, 1835 ISA_MIPS1_NOT_32R6_64R6; 1836def : MipsInstAlias<"and $rs, $rt, $imm", 1837 (ANDi GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm), 0>; 1838def : MipsInstAlias<"and $rs, $imm", 1839 (ANDi GPR32Opnd:$rs, GPR32Opnd:$rs, simm16:$imm), 0>; 1840def : MipsInstAlias<"j $rs", (JR GPR32Opnd:$rs), 0>; 1841let Predicates = [NotInMicroMips] in { 1842def : MipsInstAlias<"jalr $rs", (JALR RA, GPR32Opnd:$rs), 0>; 1843} 1844def : MipsInstAlias<"jalr.hb $rs", (JALR_HB RA, GPR32Opnd:$rs), 1>, ISA_MIPS32; 1845def : MipsInstAlias<"not $rt, $rs", 1846 (NOR GPR32Opnd:$rt, GPR32Opnd:$rs, ZERO), 0>; 1847def : MipsInstAlias<"neg $rt, $rs", 1848 (SUB GPR32Opnd:$rt, ZERO, GPR32Opnd:$rs), 1>; 1849def : MipsInstAlias<"negu $rt", 1850 (SUBu GPR32Opnd:$rt, ZERO, GPR32Opnd:$rt), 0>; 1851def : MipsInstAlias<"negu $rt, $rs", 1852 (SUBu GPR32Opnd:$rt, ZERO, GPR32Opnd:$rs), 1>; 1853def : MipsInstAlias<"slt $rs, $rt, $imm", 1854 (SLTi GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm), 0>; 1855def : MipsInstAlias<"sltu $rt, $rs, $imm", 1856 (SLTiu GPR32Opnd:$rt, GPR32Opnd:$rs, simm16:$imm), 0>; 1857def : MipsInstAlias<"xor $rs, $rt, $imm", 1858 (XORi GPR32Opnd:$rs, GPR32Opnd:$rt, uimm16:$imm), 0>; 1859def : MipsInstAlias<"xor $rs, $imm", 1860 (XORi GPR32Opnd:$rs, GPR32Opnd:$rs, uimm16:$imm), 0>; 1861def : MipsInstAlias<"or $rs, $rt, $imm", 1862 (ORi GPR32Opnd:$rs, GPR32Opnd:$rt, uimm16:$imm), 0>; 1863def : MipsInstAlias<"or $rs, $imm", 1864 (ORi GPR32Opnd:$rs, GPR32Opnd:$rs, uimm16:$imm), 0>; 1865let AdditionalPredicates = [NotInMicroMips] in { 1866def : MipsInstAlias<"nop", (SLL ZERO, ZERO, 0), 1>; 1867} 1868def : MipsInstAlias<"mfc0 $rt, $rd", (MFC0 GPR32Opnd:$rt, COP0Opnd:$rd, 0), 0>; 1869def : MipsInstAlias<"mtc0 $rt, $rd", (MTC0 COP0Opnd:$rd, GPR32Opnd:$rt, 0), 0>; 1870def : MipsInstAlias<"mfc2 $rt, $rd", (MFC2 GPR32Opnd:$rt, COP2Opnd:$rd, 0), 0>; 1871def : MipsInstAlias<"mtc2 $rt, $rd", (MTC2 COP2Opnd:$rd, GPR32Opnd:$rt, 0), 0>; 1872let AdditionalPredicates = [NotInMicroMips] in { 1873def : MipsInstAlias<"b $offset", (BEQ ZERO, ZERO, brtarget:$offset), 0>; 1874} 1875def : MipsInstAlias<"bnez $rs,$offset", 1876 (BNE GPR32Opnd:$rs, ZERO, brtarget:$offset), 0>; 1877def : MipsInstAlias<"bnezl $rs,$offset", 1878 (BNEL GPR32Opnd:$rs, ZERO, brtarget:$offset), 0>; 1879def : MipsInstAlias<"beqz $rs,$offset", 1880 (BEQ GPR32Opnd:$rs, ZERO, brtarget:$offset), 0>; 1881def : MipsInstAlias<"beqzl $rs,$offset", 1882 (BEQL GPR32Opnd:$rs, ZERO, brtarget:$offset), 0>; 1883def : MipsInstAlias<"syscall", (SYSCALL 0), 1>; 1884 1885def : MipsInstAlias<"break", (BREAK 0, 0), 1>; 1886def : MipsInstAlias<"break $imm", (BREAK uimm10:$imm, 0), 1>; 1887let AdditionalPredicates = [NotInMicroMips] in { 1888 def : MipsInstAlias<"ei", (EI ZERO), 1>, ISA_MIPS32R2; 1889 def : MipsInstAlias<"di", (DI ZERO), 1>, ISA_MIPS32R2; 1890} 1891let AdditionalPredicates = [NotInMicroMips] in { 1892 def : MipsInstAlias<"teq $rs, $rt", 1893 (TEQ GPR32Opnd:$rs, GPR32Opnd:$rt, 0), 1>, ISA_MIPS2; 1894 def : MipsInstAlias<"tge $rs, $rt", 1895 (TGE GPR32Opnd:$rs, GPR32Opnd:$rt, 0), 1>, ISA_MIPS2; 1896 def : MipsInstAlias<"tgeu $rs, $rt", 1897 (TGEU GPR32Opnd:$rs, GPR32Opnd:$rt, 0), 1>, ISA_MIPS2; 1898 def : MipsInstAlias<"tlt $rs, $rt", 1899 (TLT GPR32Opnd:$rs, GPR32Opnd:$rt, 0), 1>, ISA_MIPS2; 1900 def : MipsInstAlias<"tltu $rs, $rt", 1901 (TLTU GPR32Opnd:$rs, GPR32Opnd:$rt, 0), 1>, ISA_MIPS2; 1902 def : MipsInstAlias<"tne $rs, $rt", 1903 (TNE GPR32Opnd:$rs, GPR32Opnd:$rt, 0), 1>, ISA_MIPS2; 1904} 1905def : MipsInstAlias<"sll $rd, $rt, $rs", 1906 (SLLV GPR32Opnd:$rd, GPR32Opnd:$rt, GPR32Opnd:$rs), 0>; 1907def : MipsInstAlias<"sub, $rd, $rs, $imm", 1908 (ADDi GPR32Opnd:$rd, GPR32Opnd:$rs, 1909 InvertedImOperand:$imm), 0>, ISA_MIPS1_NOT_32R6_64R6; 1910def : MipsInstAlias<"sub $rs, $imm", 1911 (ADDi GPR32Opnd:$rs, GPR32Opnd:$rs, InvertedImOperand:$imm), 1912 0>, ISA_MIPS1_NOT_32R6_64R6; 1913def : MipsInstAlias<"subu, $rd, $rs, $imm", 1914 (ADDiu GPR32Opnd:$rd, GPR32Opnd:$rs, 1915 InvertedImOperand:$imm), 0>; 1916def : MipsInstAlias<"subu $rs, $imm", (ADDiu GPR32Opnd:$rs, GPR32Opnd:$rs, 1917 InvertedImOperand:$imm), 0>; 1918def : MipsInstAlias<"sra $rd, $rt, $rs", 1919 (SRAV GPR32Opnd:$rd, GPR32Opnd:$rt, GPR32Opnd:$rs), 0>; 1920def : MipsInstAlias<"srl $rd, $rt, $rs", 1921 (SRLV GPR32Opnd:$rd, GPR32Opnd:$rt, GPR32Opnd:$rs), 0>; 1922def : MipsInstAlias<"sdbbp", (SDBBP 0)>, ISA_MIPS32_NOT_32R6_64R6; 1923def : MipsInstAlias<"sync", 1924 (SYNC 0), 1>, ISA_MIPS2; 1925//===----------------------------------------------------------------------===// 1926// Assembler Pseudo Instructions 1927//===----------------------------------------------------------------------===// 1928 1929class LoadImmediate32<string instr_asm, Operand Od, RegisterOperand RO> : 1930 MipsAsmPseudoInst<(outs RO:$rt), (ins Od:$imm32), 1931 !strconcat(instr_asm, "\t$rt, $imm32")> ; 1932def LoadImm32 : LoadImmediate32<"li", simm32, GPR32Opnd>; 1933 1934class LoadAddressFromReg32<string instr_asm, Operand MemOpnd, 1935 RegisterOperand RO> : 1936 MipsAsmPseudoInst<(outs RO:$rt), (ins MemOpnd:$addr), 1937 !strconcat(instr_asm, "\t$rt, $addr")> ; 1938def LoadAddrReg32 : LoadAddressFromReg32<"la", mem, GPR32Opnd>; 1939 1940class LoadAddressFromImm32<string instr_asm, Operand Od, RegisterOperand RO> : 1941 MipsAsmPseudoInst<(outs RO:$rt), (ins Od:$imm32), 1942 !strconcat(instr_asm, "\t$rt, $imm32")> ; 1943def LoadAddrImm32 : LoadAddressFromImm32<"la", simm32, GPR32Opnd>; 1944 1945def JalTwoReg : MipsAsmPseudoInst<(outs GPR32Opnd:$rd), (ins GPR32Opnd:$rs), 1946 "jal\t$rd, $rs"> ; 1947def JalOneReg : MipsAsmPseudoInst<(outs), (ins GPR32Opnd:$rs), 1948 "jal\t$rs"> ; 1949 1950def NORImm : MipsAsmPseudoInst<(outs), (ins GPR32Opnd:$rs, GPR32Opnd:$rt, simm16:$imm), 1951 "nor\t$rs, $rt, $imm"> ; 1952 1953let hasDelaySlot = 1 in { 1954def BneImm : MipsAsmPseudoInst<(outs GPR32Opnd:$rt), 1955 (ins imm64:$imm64, brtarget:$offset), 1956 "bne\t$rt, $imm64, $offset">; 1957def BeqImm : MipsAsmPseudoInst<(outs GPR32Opnd:$rt), 1958 (ins imm64:$imm64, brtarget:$offset), 1959 "beq\t$rt, $imm64, $offset">; 1960 1961class CondBranchPseudo<string instr_asm> : 1962 MipsAsmPseudoInst<(outs), (ins GPR32Opnd:$rs, GPR32Opnd:$rt, 1963 brtarget:$offset), 1964 !strconcat(instr_asm, "\t$rs, $rt, $offset")>; 1965} 1966 1967def BLT : CondBranchPseudo<"blt">; 1968def BLE : CondBranchPseudo<"ble">; 1969def BGE : CondBranchPseudo<"bge">; 1970def BGT : CondBranchPseudo<"bgt">; 1971def BLTU : CondBranchPseudo<"bltu">; 1972def BLEU : CondBranchPseudo<"bleu">; 1973def BGEU : CondBranchPseudo<"bgeu">; 1974def BGTU : CondBranchPseudo<"bgtu">; 1975def BLTL : CondBranchPseudo<"bltl">, ISA_MIPS2_NOT_32R6_64R6; 1976def BLEL : CondBranchPseudo<"blel">, ISA_MIPS2_NOT_32R6_64R6; 1977def BGEL : CondBranchPseudo<"bgel">, ISA_MIPS2_NOT_32R6_64R6; 1978def BGTL : CondBranchPseudo<"bgtl">, ISA_MIPS2_NOT_32R6_64R6; 1979def BLTUL: CondBranchPseudo<"bltul">, ISA_MIPS2_NOT_32R6_64R6; 1980def BLEUL: CondBranchPseudo<"bleul">, ISA_MIPS2_NOT_32R6_64R6; 1981def BGEUL: CondBranchPseudo<"bgeul">, ISA_MIPS2_NOT_32R6_64R6; 1982def BGTUL: CondBranchPseudo<"bgtul">, ISA_MIPS2_NOT_32R6_64R6; 1983 1984class CondBranchImmPseudo<string instr_asm> : 1985 MipsAsmPseudoInst<(outs), (ins GPR32Opnd:$rs, imm64:$imm, brtarget:$offset), 1986 !strconcat(instr_asm, "\t$rs, $imm, $offset")>; 1987 1988def BLTImmMacro : CondBranchImmPseudo<"blt">; 1989def BLEImmMacro : CondBranchImmPseudo<"ble">; 1990def BGEImmMacro : CondBranchImmPseudo<"bge">; 1991def BGTImmMacro : CondBranchImmPseudo<"bgt">; 1992def BLTUImmMacro : CondBranchImmPseudo<"bltu">; 1993def BLEUImmMacro : CondBranchImmPseudo<"bleu">; 1994def BGEUImmMacro : CondBranchImmPseudo<"bgeu">; 1995def BGTUImmMacro : CondBranchImmPseudo<"bgtu">; 1996def BLTLImmMacro : CondBranchImmPseudo<"bltl">, ISA_MIPS2_NOT_32R6_64R6; 1997def BLELImmMacro : CondBranchImmPseudo<"blel">, ISA_MIPS2_NOT_32R6_64R6; 1998def BGELImmMacro : CondBranchImmPseudo<"bgel">, ISA_MIPS2_NOT_32R6_64R6; 1999def BGTLImmMacro : CondBranchImmPseudo<"bgtl">, ISA_MIPS2_NOT_32R6_64R6; 2000def BLTULImmMacro : CondBranchImmPseudo<"bltul">, ISA_MIPS2_NOT_32R6_64R6; 2001def BLEULImmMacro : CondBranchImmPseudo<"bleul">, ISA_MIPS2_NOT_32R6_64R6; 2002def BGEULImmMacro : CondBranchImmPseudo<"bgeul">, ISA_MIPS2_NOT_32R6_64R6; 2003def BGTULImmMacro : CondBranchImmPseudo<"bgtul">, ISA_MIPS2_NOT_32R6_64R6; 2004 2005// FIXME: Predicates are removed because instructions are matched regardless of 2006// predicates, because PredicateControl was not in the hierarchy. This was 2007// done to emit more precise error message from expansion function. 2008// Once the tablegen-erated errors are made better, this needs to be fixed and 2009// predicates needs to be restored. 2010 2011def SDivMacro : MipsAsmPseudoInst<(outs), (ins GPR32Opnd:$rs, GPR32Opnd:$rt), 2012 "div\t$rs, $rt">; //, ISA_MIPS1_NOT_32R6_64R6; 2013 2014def UDivMacro : MipsAsmPseudoInst<(outs), (ins GPR32Opnd:$rs, GPR32Opnd:$rt), 2015 "divu\t$rs, $rt">; //, ISA_MIPS1_NOT_32R6_64R6; 2016 2017def DSDivMacro : MipsAsmPseudoInst<(outs), (ins GPR32Opnd:$rs, GPR32Opnd:$rt), 2018 "ddiv\t$rs, $rt">; //, ISA_MIPS64_NOT_64R6; 2019 2020def DUDivMacro : MipsAsmPseudoInst<(outs), (ins GPR32Opnd:$rs, GPR32Opnd:$rt), 2021 "ddivu\t$rs, $rt">; //, ISA_MIPS64_NOT_64R6; 2022 2023def Ulh : MipsAsmPseudoInst<(outs GPR32Opnd:$rt), (ins mem:$addr), 2024 "ulh\t$rt, $addr">; //, ISA_MIPS1_NOT_32R6_64R6; 2025 2026def Ulhu : MipsAsmPseudoInst<(outs GPR32Opnd:$rt), (ins mem:$addr), 2027 "ulhu\t$rt, $addr">; //, ISA_MIPS1_NOT_32R6_64R6; 2028 2029def Ulw : MipsAsmPseudoInst<(outs GPR32Opnd:$rt), (ins mem:$addr), 2030 "ulw\t$rt, $addr">; //, ISA_MIPS1_NOT_32R6_64R6; 2031 2032//===----------------------------------------------------------------------===// 2033// Arbitrary patterns that map to one or more instructions 2034//===----------------------------------------------------------------------===// 2035 2036// Load/store pattern templates. 2037class LoadRegImmPat<Instruction LoadInst, ValueType ValTy, PatFrag Node> : 2038 MipsPat<(ValTy (Node addrRegImm:$a)), (LoadInst addrRegImm:$a)>; 2039 2040class StoreRegImmPat<Instruction StoreInst, ValueType ValTy> : 2041 MipsPat<(store ValTy:$v, addrRegImm:$a), (StoreInst ValTy:$v, addrRegImm:$a)>; 2042 2043// Small immediates 2044let AdditionalPredicates = [NotInMicroMips] in { 2045def : MipsPat<(i32 immSExt16:$in), 2046 (ADDiu ZERO, imm:$in)>; 2047def : MipsPat<(i32 immZExt16:$in), 2048 (ORi ZERO, imm:$in)>; 2049} 2050def : MipsPat<(i32 immLow16Zero:$in), 2051 (LUi (HI16 imm:$in))>; 2052 2053// Arbitrary immediates 2054def : MipsPat<(i32 imm:$imm), 2055 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>; 2056 2057// Carry MipsPatterns 2058def : MipsPat<(subc GPR32:$lhs, GPR32:$rhs), 2059 (SUBu GPR32:$lhs, GPR32:$rhs)>; 2060let AdditionalPredicates = [NotDSP] in { 2061 def : MipsPat<(addc GPR32:$lhs, GPR32:$rhs), 2062 (ADDu GPR32:$lhs, GPR32:$rhs)>; 2063 def : MipsPat<(addc GPR32:$src, immSExt16:$imm), 2064 (ADDiu GPR32:$src, imm:$imm)>; 2065} 2066 2067// Support multiplication for pre-Mips32 targets that don't have 2068// the MUL instruction. 2069def : MipsPat<(mul GPR32:$lhs, GPR32:$rhs), 2070 (PseudoMFLO (PseudoMULT GPR32:$lhs, GPR32:$rhs))>, 2071 ISA_MIPS1_NOT_32R6_64R6; 2072 2073// SYNC 2074def : MipsPat<(MipsSync (i32 immz)), 2075 (SYNC 0)>, ISA_MIPS2; 2076 2077// Call 2078def : MipsPat<(MipsJmpLink (i32 tglobaladdr:$dst)), 2079 (JAL tglobaladdr:$dst)>; 2080def : MipsPat<(MipsJmpLink (i32 texternalsym:$dst)), 2081 (JAL texternalsym:$dst)>; 2082//def : MipsPat<(MipsJmpLink GPR32:$dst), 2083// (JALR GPR32:$dst)>; 2084 2085// Tail call 2086def : MipsPat<(MipsTailCall (iPTR tglobaladdr:$dst)), 2087 (TAILCALL tglobaladdr:$dst)>; 2088def : MipsPat<(MipsTailCall (iPTR texternalsym:$dst)), 2089 (TAILCALL texternalsym:$dst)>; 2090// hi/lo relocs 2091def : MipsPat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>; 2092def : MipsPat<(MipsHi tblockaddress:$in), (LUi tblockaddress:$in)>; 2093def : MipsPat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>; 2094def : MipsPat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>; 2095def : MipsPat<(MipsHi tglobaltlsaddr:$in), (LUi tglobaltlsaddr:$in)>; 2096def : MipsPat<(MipsHi texternalsym:$in), (LUi texternalsym:$in)>; 2097 2098def : MipsPat<(MipsLo tglobaladdr:$in), (ADDiu ZERO, tglobaladdr:$in)>; 2099def : MipsPat<(MipsLo tblockaddress:$in), (ADDiu ZERO, tblockaddress:$in)>; 2100def : MipsPat<(MipsLo tjumptable:$in), (ADDiu ZERO, tjumptable:$in)>; 2101def : MipsPat<(MipsLo tconstpool:$in), (ADDiu ZERO, tconstpool:$in)>; 2102def : MipsPat<(MipsLo tglobaltlsaddr:$in), (ADDiu ZERO, tglobaltlsaddr:$in)>; 2103def : MipsPat<(MipsLo texternalsym:$in), (ADDiu ZERO, texternalsym:$in)>; 2104 2105def : MipsPat<(add GPR32:$hi, (MipsLo tglobaladdr:$lo)), 2106 (ADDiu GPR32:$hi, tglobaladdr:$lo)>; 2107def : MipsPat<(add GPR32:$hi, (MipsLo tblockaddress:$lo)), 2108 (ADDiu GPR32:$hi, tblockaddress:$lo)>; 2109def : MipsPat<(add GPR32:$hi, (MipsLo tjumptable:$lo)), 2110 (ADDiu GPR32:$hi, tjumptable:$lo)>; 2111def : MipsPat<(add GPR32:$hi, (MipsLo tconstpool:$lo)), 2112 (ADDiu GPR32:$hi, tconstpool:$lo)>; 2113def : MipsPat<(add GPR32:$hi, (MipsLo tglobaltlsaddr:$lo)), 2114 (ADDiu GPR32:$hi, tglobaltlsaddr:$lo)>; 2115 2116// gp_rel relocs 2117def : MipsPat<(add GPR32:$gp, (MipsGPRel tglobaladdr:$in)), 2118 (ADDiu GPR32:$gp, tglobaladdr:$in)>; 2119def : MipsPat<(add GPR32:$gp, (MipsGPRel tconstpool:$in)), 2120 (ADDiu GPR32:$gp, tconstpool:$in)>; 2121 2122// wrapper_pic 2123class WrapperPat<SDNode node, Instruction ADDiuOp, RegisterClass RC>: 2124 MipsPat<(MipsWrapper RC:$gp, node:$in), 2125 (ADDiuOp RC:$gp, node:$in)>; 2126 2127def : WrapperPat<tglobaladdr, ADDiu, GPR32>; 2128def : WrapperPat<tconstpool, ADDiu, GPR32>; 2129def : WrapperPat<texternalsym, ADDiu, GPR32>; 2130def : WrapperPat<tblockaddress, ADDiu, GPR32>; 2131def : WrapperPat<tjumptable, ADDiu, GPR32>; 2132def : WrapperPat<tglobaltlsaddr, ADDiu, GPR32>; 2133 2134let AdditionalPredicates = [NotInMicroMips] in { 2135// Mips does not have "not", so we expand our way 2136def : MipsPat<(not GPR32:$in), 2137 (NOR GPR32Opnd:$in, ZERO)>; 2138} 2139 2140// extended loads 2141def : MipsPat<(i32 (extloadi1 addr:$src)), (LBu addr:$src)>; 2142def : MipsPat<(i32 (extloadi8 addr:$src)), (LBu addr:$src)>; 2143def : MipsPat<(i32 (extloadi16 addr:$src)), (LHu addr:$src)>; 2144 2145// peepholes 2146def : MipsPat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>; 2147 2148// brcond patterns 2149multiclass BrcondPats<RegisterClass RC, Instruction BEQOp, Instruction BNEOp, 2150 Instruction SLTOp, Instruction SLTuOp, Instruction SLTiOp, 2151 Instruction SLTiuOp, Register ZEROReg> { 2152def : MipsPat<(brcond (i32 (setne RC:$lhs, 0)), bb:$dst), 2153 (BNEOp RC:$lhs, ZEROReg, bb:$dst)>; 2154def : MipsPat<(brcond (i32 (seteq RC:$lhs, 0)), bb:$dst), 2155 (BEQOp RC:$lhs, ZEROReg, bb:$dst)>; 2156 2157def : MipsPat<(brcond (i32 (setge RC:$lhs, RC:$rhs)), bb:$dst), 2158 (BEQ (SLTOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>; 2159def : MipsPat<(brcond (i32 (setuge RC:$lhs, RC:$rhs)), bb:$dst), 2160 (BEQ (SLTuOp RC:$lhs, RC:$rhs), ZERO, bb:$dst)>; 2161def : MipsPat<(brcond (i32 (setge RC:$lhs, immSExt16:$rhs)), bb:$dst), 2162 (BEQ (SLTiOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>; 2163def : MipsPat<(brcond (i32 (setuge RC:$lhs, immSExt16:$rhs)), bb:$dst), 2164 (BEQ (SLTiuOp RC:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>; 2165def : MipsPat<(brcond (i32 (setgt RC:$lhs, immSExt16Plus1:$rhs)), bb:$dst), 2166 (BEQ (SLTiOp RC:$lhs, (Plus1 imm:$rhs)), ZERO, bb:$dst)>; 2167def : MipsPat<(brcond (i32 (setugt RC:$lhs, immSExt16Plus1:$rhs)), bb:$dst), 2168 (BEQ (SLTiuOp RC:$lhs, (Plus1 imm:$rhs)), ZERO, bb:$dst)>; 2169 2170def : MipsPat<(brcond (i32 (setle RC:$lhs, RC:$rhs)), bb:$dst), 2171 (BEQ (SLTOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>; 2172def : MipsPat<(brcond (i32 (setule RC:$lhs, RC:$rhs)), bb:$dst), 2173 (BEQ (SLTuOp RC:$rhs, RC:$lhs), ZERO, bb:$dst)>; 2174 2175def : MipsPat<(brcond RC:$cond, bb:$dst), 2176 (BNEOp RC:$cond, ZEROReg, bb:$dst)>; 2177} 2178 2179defm : BrcondPats<GPR32, BEQ, BNE, SLT, SLTu, SLTi, SLTiu, ZERO>; 2180 2181def : MipsPat<(brcond (i32 (setlt i32:$lhs, 1)), bb:$dst), 2182 (BLEZ i32:$lhs, bb:$dst)>; 2183def : MipsPat<(brcond (i32 (setgt i32:$lhs, -1)), bb:$dst), 2184 (BGEZ i32:$lhs, bb:$dst)>; 2185 2186// setcc patterns 2187multiclass SeteqPats<RegisterClass RC, Instruction SLTiuOp, Instruction XOROp, 2188 Instruction SLTuOp, Register ZEROReg> { 2189 def : MipsPat<(seteq RC:$lhs, 0), 2190 (SLTiuOp RC:$lhs, 1)>; 2191 def : MipsPat<(setne RC:$lhs, 0), 2192 (SLTuOp ZEROReg, RC:$lhs)>; 2193 def : MipsPat<(seteq RC:$lhs, RC:$rhs), 2194 (SLTiuOp (XOROp RC:$lhs, RC:$rhs), 1)>; 2195 def : MipsPat<(setne RC:$lhs, RC:$rhs), 2196 (SLTuOp ZEROReg, (XOROp RC:$lhs, RC:$rhs))>; 2197} 2198 2199multiclass SetlePats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> { 2200 def : MipsPat<(setle RC:$lhs, RC:$rhs), 2201 (XORi (SLTOp RC:$rhs, RC:$lhs), 1)>; 2202 def : MipsPat<(setule RC:$lhs, RC:$rhs), 2203 (XORi (SLTuOp RC:$rhs, RC:$lhs), 1)>; 2204} 2205 2206multiclass SetgtPats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> { 2207 def : MipsPat<(setgt RC:$lhs, RC:$rhs), 2208 (SLTOp RC:$rhs, RC:$lhs)>; 2209 def : MipsPat<(setugt RC:$lhs, RC:$rhs), 2210 (SLTuOp RC:$rhs, RC:$lhs)>; 2211} 2212 2213multiclass SetgePats<RegisterClass RC, Instruction SLTOp, Instruction SLTuOp> { 2214 def : MipsPat<(setge RC:$lhs, RC:$rhs), 2215 (XORi (SLTOp RC:$lhs, RC:$rhs), 1)>; 2216 def : MipsPat<(setuge RC:$lhs, RC:$rhs), 2217 (XORi (SLTuOp RC:$lhs, RC:$rhs), 1)>; 2218} 2219 2220multiclass SetgeImmPats<RegisterClass RC, Instruction SLTiOp, 2221 Instruction SLTiuOp> { 2222 def : MipsPat<(setge RC:$lhs, immSExt16:$rhs), 2223 (XORi (SLTiOp RC:$lhs, immSExt16:$rhs), 1)>; 2224 def : MipsPat<(setuge RC:$lhs, immSExt16:$rhs), 2225 (XORi (SLTiuOp RC:$lhs, immSExt16:$rhs), 1)>; 2226} 2227 2228defm : SeteqPats<GPR32, SLTiu, XOR, SLTu, ZERO>; 2229defm : SetlePats<GPR32, SLT, SLTu>; 2230defm : SetgtPats<GPR32, SLT, SLTu>; 2231defm : SetgePats<GPR32, SLT, SLTu>; 2232defm : SetgeImmPats<GPR32, SLTi, SLTiu>; 2233 2234// bswap pattern 2235def : MipsPat<(bswap GPR32:$rt), (ROTR (WSBH GPR32:$rt), 16)>; 2236 2237// Load halfword/word patterns. 2238let AddedComplexity = 40 in { 2239 def : LoadRegImmPat<LBu, i32, zextloadi8>; 2240 def : LoadRegImmPat<LH, i32, sextloadi16>; 2241 let AdditionalPredicates = [NotInMicroMips] in { 2242 def : LoadRegImmPat<LW, i32, load>; 2243 } 2244} 2245 2246// Atomic load patterns. 2247def : MipsPat<(atomic_load_8 addr:$a), (LB addr:$a)>; 2248def : MipsPat<(atomic_load_16 addr:$a), (LH addr:$a)>; 2249def : MipsPat<(atomic_load_32 addr:$a), (LW addr:$a)>; 2250 2251// Atomic store patterns. 2252def : MipsPat<(atomic_store_8 addr:$a, GPR32:$v), (SB GPR32:$v, addr:$a)>; 2253def : MipsPat<(atomic_store_16 addr:$a, GPR32:$v), (SH GPR32:$v, addr:$a)>; 2254def : MipsPat<(atomic_store_32 addr:$a, GPR32:$v), (SW GPR32:$v, addr:$a)>; 2255 2256//===----------------------------------------------------------------------===// 2257// Floating Point Support 2258//===----------------------------------------------------------------------===// 2259 2260include "MipsInstrFPU.td" 2261include "Mips64InstrInfo.td" 2262include "MipsCondMov.td" 2263 2264include "Mips32r6InstrInfo.td" 2265include "Mips64r6InstrInfo.td" 2266 2267// 2268// Mips16 2269 2270include "Mips16InstrFormats.td" 2271include "Mips16InstrInfo.td" 2272 2273// DSP 2274include "MipsDSPInstrFormats.td" 2275include "MipsDSPInstrInfo.td" 2276 2277// MSA 2278include "MipsMSAInstrFormats.td" 2279include "MipsMSAInstrInfo.td" 2280 2281// EVA 2282include "MipsEVAInstrFormats.td" 2283include "MipsEVAInstrInfo.td" 2284 2285// Micromips 2286include "MicroMipsInstrFormats.td" 2287include "MicroMipsInstrInfo.td" 2288include "MicroMipsInstrFPU.td" 2289 2290// Micromips r6 2291include "MicroMips32r6InstrFormats.td" 2292include "MicroMips32r6InstrInfo.td" 2293 2294// Micromips64 r6 2295include "MicroMips64r6InstrFormats.td" 2296include "MicroMips64r6InstrInfo.td" 2297 2298// Micromips DSP 2299include "MicroMipsDSPInstrFormats.td" 2300include "MicroMipsDSPInstrInfo.td" 2301