65#define DEBUG_TYPE "mips-asm-parser"
75class MipsAssemblerOptions {
77 MipsAssemblerOptions(
const FeatureBitset &Features_) : Features(Features_) {}
79 MipsAssemblerOptions(
const MipsAssemblerOptions *Opts) {
80 ATReg = Opts->getATRegIndex();
81 Reorder = Opts->isReorder();
82 Macro = Opts->isMacro();
83 Features = Opts->getFeatures();
86 unsigned getATRegIndex()
const {
return ATReg; }
87 bool setATRegIndex(
unsigned Reg) {
95 bool isReorder()
const {
return Reorder; }
96 void setReorder() { Reorder =
true; }
97 void setNoReorder() { Reorder =
false; }
99 bool isMacro()
const {
return Macro; }
100 void setMacro() {
Macro =
true; }
101 void setNoMacro() {
Macro =
false; }
103 const FeatureBitset &
getFeatures()
const {
return Features; }
104 void setFeatures(
const FeatureBitset &Features_) { Features = Features_; }
111 static const FeatureBitset AllArchRelatedMask;
117 FeatureBitset Features;
122const FeatureBitset MipsAssemblerOptions::AllArchRelatedMask = {
123 Mips::FeatureMips1, Mips::FeatureMips2, Mips::FeatureMips3,
124 Mips::FeatureMips3_32, Mips::FeatureMips3_32r2, Mips::FeatureMips4,
125 Mips::FeatureMips4_32, Mips::FeatureMips4_32r2, Mips::FeatureMips5,
126 Mips::FeatureMips5_32r2, Mips::FeatureMips32, Mips::FeatureMips32r2,
127 Mips::FeatureMips32r3, Mips::FeatureMips32r5, Mips::FeatureMips32r6,
128 Mips::FeatureMips64, Mips::FeatureMips64r2, Mips::FeatureMips64r3,
129 Mips::FeatureMips64r5, Mips::FeatureMips64r6, Mips::FeatureCnMips,
130 Mips::FeatureCnMipsP, Mips::FeatureFP64Bit, Mips::FeatureGP64Bit,
131 Mips::FeatureNaN2008, Mips::FeatureNanoMips};
136 MipsTargetStreamer &getTargetStreamer() {
137 assert(getParser().getStreamer().getTargetStreamer() &&
138 "do not have a target streamer");
139 MCTargetStreamer &TS = *getParser().getStreamer().getTargetStreamer();
140 return static_cast<MipsTargetStreamer &
>(TS);
143 const MipsMCOptions &CLOpts;
153 bool CurForbiddenSlotAttr;
156 unsigned CpSaveLocation;
158 bool CpSaveLocationIsRegister;
161 StringMap<AsmToken> RegisterSets;
164 void printWarningWithFixIt(
const Twine &
Msg,
const Twine &FixMsg,
165 SMRange
Range,
bool ShowColors =
true);
168 template <
unsigned Opcode,
bool IsMFTR>
169 void ConvertMTTransferCOP0Operands(MCInst &Inst,
172 ConvertMTTransferCOP0Operands<Mips::MFTR, true>(Inst,
Operands);
175 ConvertMTTransferCOP0Operands<Mips::MTTR, false>(Inst,
Operands);
178#define GET_ASSEMBLER_HEADER
179#include "MipsGenAsmMatcher.inc"
182 checkEarlyTargetMatchPredicate(
MCInst &Inst,
184 unsigned checkTargetMatchPredicate(
MCInst &Inst)
override;
186 bool matchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
189 bool MatchingInlineAsm)
override;
194 SMLoc &EndLoc)
override;
200 bool mnemonicIsValid(
StringRef Mnemonic,
unsigned VariantID);
205 bool ParseDirective(
AsmToken DirectiveID)
override;
209 const MCExpr *parseMemOffset();
220 const MCExpr *parseRelocExpr();
221 bool parsePrimaryExpr(
const MCExpr *&Res,
SMLoc &EndLoc)
override;
227 enum MacroExpanderResultTy {
234 MacroExpanderResultTy tryExpandInstruction(MCInst &Inst, SMLoc IDLoc,
236 const MCSubtargetInfo *STI);
238 bool expandJalWithRegs(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
239 const MCSubtargetInfo *STI);
241 bool loadImmediate(int64_t ImmValue, MCRegister DstReg, MCRegister SrcReg,
242 bool Is32BitImm,
bool IsAddress, SMLoc IDLoc,
243 MCStreamer &Out,
const MCSubtargetInfo *STI);
245 bool canDeferGOTLoad(
const MCSymbol *Sym);
247 bool loadAndAddSymbolAddress(
const MCExpr *SymExpr, MCRegister DstReg,
248 MCRegister SrcReg,
bool Is32BitSym, SMLoc IDLoc,
249 MCStreamer &Out,
const MCSubtargetInfo *STI);
251 bool emitPartialAddress(MipsTargetStreamer &TOut, SMLoc IDLoc, MCSymbol *Sym);
253 bool expandLoadImm(MCInst &Inst,
bool Is32BitImm, SMLoc IDLoc,
254 MCStreamer &Out,
const MCSubtargetInfo *STI);
256 bool expandLoadSingleImmToGPR(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
257 const MCSubtargetInfo *STI);
258 bool expandLoadSingleImmToFPR(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
259 const MCSubtargetInfo *STI);
260 bool expandLoadDoubleImmToGPR(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
261 const MCSubtargetInfo *STI);
262 bool expandLoadDoubleImmToFPR(MCInst &Inst,
bool Is64FPU, SMLoc IDLoc,
263 MCStreamer &Out,
const MCSubtargetInfo *STI);
265 bool expandLoadAddress(MCRegister DstReg, MCRegister BaseReg,
266 const MCOperand &
Offset,
bool Is32BitAddress,
267 SMLoc IDLoc, MCStreamer &Out,
268 const MCSubtargetInfo *STI);
270 bool expandUncondBranchMMPseudo(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
271 const MCSubtargetInfo *STI);
273 void expandMem16Inst(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
274 const MCSubtargetInfo *STI,
bool IsLoad);
275 void expandMem9Inst(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
276 const MCSubtargetInfo *STI,
bool IsLoad);
278 bool expandLoadStoreMultiple(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
279 const MCSubtargetInfo *STI);
281 bool expandAliasImmediate(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
282 const MCSubtargetInfo *STI);
284 bool expandBranchImm(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
285 const MCSubtargetInfo *STI);
287 bool expandCondBranches(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
288 const MCSubtargetInfo *STI);
290 bool expandDivRem(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
291 const MCSubtargetInfo *STI,
const bool IsMips64,
294 bool expandTrunc(MCInst &Inst,
bool IsDouble,
bool Is64FPU, SMLoc IDLoc,
295 MCStreamer &Out,
const MCSubtargetInfo *STI);
297 bool expandUlh(MCInst &Inst,
bool Signed, SMLoc IDLoc, MCStreamer &Out,
298 const MCSubtargetInfo *STI);
300 bool expandUsh(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
301 const MCSubtargetInfo *STI);
303 bool expandUxw(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
304 const MCSubtargetInfo *STI);
306 bool expandSge(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
307 const MCSubtargetInfo *STI);
309 bool expandSgeImm(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
310 const MCSubtargetInfo *STI);
312 bool expandSgtImm(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
313 const MCSubtargetInfo *STI);
315 bool expandSle(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
316 const MCSubtargetInfo *STI);
318 bool expandSleImm(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
319 const MCSubtargetInfo *STI);
321 bool expandRotation(MCInst &Inst, SMLoc IDLoc,
322 MCStreamer &Out,
const MCSubtargetInfo *STI);
323 bool expandRotationImm(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
324 const MCSubtargetInfo *STI);
325 bool expandDRotation(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
326 const MCSubtargetInfo *STI);
327 bool expandDRotationImm(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
328 const MCSubtargetInfo *STI);
330 bool expandAbs(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
331 const MCSubtargetInfo *STI);
333 bool expandMulImm(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
334 const MCSubtargetInfo *STI);
336 bool expandMulO(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
337 const MCSubtargetInfo *STI);
339 bool expandMulOU(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
340 const MCSubtargetInfo *STI);
342 bool expandDMULMacro(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
343 const MCSubtargetInfo *STI);
345 bool expandLoadStoreDMacro(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
346 const MCSubtargetInfo *STI,
bool IsLoad);
348 bool expandLoadStoreDM1Macro(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
349 const MCSubtargetInfo *STI,
bool IsLoad);
351 bool expandSeq(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
352 const MCSubtargetInfo *STI);
354 bool expandSeqI(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
355 const MCSubtargetInfo *STI);
357 bool expandSne(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
358 const MCSubtargetInfo *STI);
360 bool expandSneI(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
361 const MCSubtargetInfo *STI);
363 bool expandMXTRAlias(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
364 const MCSubtargetInfo *STI);
366 bool expandSaaAddr(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
367 const MCSubtargetInfo *STI);
369 bool reportParseError(
const Twine &ErrorMsg);
370 bool reportParseError(SMLoc Loc,
const Twine &ErrorMsg);
372 bool parseSetMips0Directive();
373 bool parseSetArchDirective();
374 bool parseSetFeature(
uint64_t Feature);
375 bool isPicAndNotNxxAbi();
376 bool parseDirectiveCpAdd(SMLoc Loc);
377 bool parseDirectiveCpLoad(SMLoc Loc);
378 bool parseDirectiveCpLocal(SMLoc Loc);
379 bool parseDirectiveCpRestore(SMLoc Loc);
380 bool parseDirectiveCPSetup();
381 bool parseDirectiveCPReturn();
382 bool parseDirectiveNaN();
383 bool parseDirectiveSet();
384 bool parseDirectiveOption();
385 bool parseInsnDirective();
386 bool parseRSectionDirective(StringRef Section);
387 bool parseSSectionDirective(StringRef Section,
unsigned Type);
389 bool parseSetAtDirective();
390 bool parseSetNoAtDirective();
391 bool parseSetMacroDirective();
392 bool parseSetNoMacroDirective();
393 bool parseSetMsaDirective();
394 bool parseSetNoMsaDirective();
395 bool parseSetNoDspDirective();
396 bool parseSetNoMips3DDirective();
397 bool parseSetReorderDirective();
398 bool parseSetNoReorderDirective();
399 bool parseSetMips16Directive();
400 bool parseSetNoMips16Directive();
401 bool parseSetFpDirective();
402 bool parseSetOddSPRegDirective();
403 bool parseSetNoOddSPRegDirective();
404 bool parseSetPopDirective();
405 bool parseSetPushDirective();
406 bool parseSetSoftFloatDirective();
407 bool parseSetHardFloatDirective();
408 bool parseSetMtDirective();
409 bool parseSetNoMtDirective();
410 bool parseSetNoCRCDirective();
411 bool parseSetNoVirtDirective();
412 bool parseSetNoGINVDirective();
413 bool parseSetNoEVADirective();
415 bool parseSetAssignment();
417 bool parseDirectiveGpWord();
418 bool parseDirectiveGpDWord();
419 bool parseDirectiveDtpRelWord();
420 bool parseDirectiveDtpRelDWord();
421 bool parseDirectiveTpRelWord();
422 bool parseDirectiveTpRelDWord();
423 bool parseDirectiveModule();
424 bool parseDirectiveModuleFP();
426 StringRef Directive);
428 bool parseInternalDirectiveReallowModule();
430 bool eatComma(StringRef ErrorStr);
432 int matchCPURegisterName(StringRef Symbol);
434 int matchHWRegsRegisterName(StringRef Symbol);
436 int matchFPURegisterName(StringRef Name);
438 int matchFCCRegisterName(StringRef Name);
440 int matchACRegisterName(StringRef Name);
442 int matchMSA128RegisterName(StringRef Name);
444 int matchMSA128CtrlRegisterName(StringRef Name);
446 MCRegister
getReg(
int RC,
int RegNo);
451 MCRegister getATReg(SMLoc Loc);
455 bool processInstruction(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
456 const MCSubtargetInfo *STI);
480 void selectArch(StringRef ArchFeature) {
481 MCSubtargetInfo &STI = copySTI();
483 FeatureBits &= ~MipsAssemblerOptions::AllArchRelatedMask;
485 setAvailableFeatures(
490 void setFeatureBits(
uint64_t Feature, StringRef FeatureString) {
492 MCSubtargetInfo &STI = copySTI();
493 setAvailableFeatures(
499 void clearFeatureBits(
uint64_t Feature, StringRef FeatureString) {
501 MCSubtargetInfo &STI = copySTI();
502 setAvailableFeatures(
508 void setModuleFeatureBits(
uint64_t Feature, StringRef FeatureString) {
509 setFeatureBits(Feature, FeatureString);
510 AssemblerOptions.front()->setFeatures(getSTI().getFeatureBits());
513 void clearModuleFeatureBits(
uint64_t Feature, StringRef FeatureString) {
514 clearFeatureBits(Feature, FeatureString);
515 AssemblerOptions.front()->setFeatures(getSTI().getFeatureBits());
519 enum MipsMatchResultTy {
520 Match_RequiresDifferentSrcAndDst = FIRST_TARGET_MATCH_RESULT_TY,
521 Match_RequiresDifferentOperands,
522 Match_RequiresNoZeroRegister,
523 Match_RequiresSameSrcAndDst,
524 Match_NoFCCRegisterForCurrentISA,
525 Match_NonZeroOperandForSync,
526 Match_NonZeroOperandForMTCX,
527 Match_RequiresPosSizeRange0_32,
528 Match_RequiresPosSizeRange33_64,
529 Match_RequiresPosSizeUImm6,
530#define GET_OPERAND_DIAGNOSTIC_TYPES
531#include "MipsGenAsmMatcher.inc"
532#undef GET_OPERAND_DIAGNOSTIC_TYPES
535 MipsAsmParser(
const MCSubtargetInfo &sti, MCAsmParser &parser,
536 const MCInstrInfo &MII)
537 : MCTargetAsmParser(sti, MII),
540 sti.getTargetTriple(),
550 setAvailableFeatures(ComputeAvailableFeatures(getSTI().getFeatureBits()));
553 AssemblerOptions.push_back(
554 std::make_unique<MipsAssemblerOptions>(getSTI().getFeatureBits()));
557 AssemblerOptions.push_back(
558 std::make_unique<MipsAssemblerOptions>(getSTI().getFeatureBits()));
560 getTargetStreamer().updateABIInfo(*
this);
562 if (!isABI_O32() && !useOddSPReg() != 0)
567 CurForbiddenSlotAttr =
false;
568 IsPicEnabled =
getContext().getObjectFileInfo()->isPositionIndependent();
570 IsCpRestoreSet =
false;
571 CpRestoreOffset = -1;
572 GPReg = ABI.GetGlobalPtr();
577 if (getSTI().
getCPU() ==
"mips64r6" && inMicroMipsMode())
580 if (!isABI_O32() && inMicroMipsMode())
585 bool hasEightFccRegisters()
const {
return hasMips4() || hasMips32(); }
587 bool isGP64bit()
const {
588 return getSTI().hasFeature(Mips::FeatureGP64Bit);
591 bool isFP64bit()
const {
592 return getSTI().hasFeature(Mips::FeatureFP64Bit);
595 bool isJalrRelocAvailable(
const MCExpr *JalExpr) {
596 if (!CLOpts.jalr_reloc)
604 return ABI.IsN32() || ABI.IsN64();
608 const MipsABIInfo &
getABI()
const {
return ABI; }
609 bool isABI_N32()
const {
return ABI.IsN32(); }
610 bool isABI_N64()
const {
return ABI.IsN64(); }
611 bool isABI_O32()
const {
return ABI.IsO32(); }
612 bool isABI_FPXX()
const {
613 return getSTI().hasFeature(Mips::FeatureFPXX);
616 bool useOddSPReg()
const {
617 return !(getSTI().hasFeature(Mips::FeatureNoOddSPReg));
620 bool inMicroMipsMode()
const {
621 return getSTI().hasFeature(Mips::FeatureMicroMips);
624 bool hasMips1()
const {
625 return getSTI().hasFeature(Mips::FeatureMips1);
628 bool hasMips2()
const {
629 return getSTI().hasFeature(Mips::FeatureMips2);
632 bool hasMips3()
const {
633 return getSTI().hasFeature(Mips::FeatureMips3);
636 bool hasMips4()
const {
637 return getSTI().hasFeature(Mips::FeatureMips4);
640 bool hasMips5()
const {
641 return getSTI().hasFeature(Mips::FeatureMips5);
644 bool hasMips32()
const {
645 return getSTI().hasFeature(Mips::FeatureMips32);
648 bool hasMips64()
const {
649 return getSTI().hasFeature(Mips::FeatureMips64);
652 bool hasMips32r2()
const {
653 return getSTI().hasFeature(Mips::FeatureMips32r2);
656 bool hasMips64r2()
const {
657 return getSTI().hasFeature(Mips::FeatureMips64r2);
660 bool hasMips32r3()
const {
661 return (getSTI().
hasFeature(Mips::FeatureMips32r3));
664 bool hasMips64r3()
const {
665 return (getSTI().
hasFeature(Mips::FeatureMips64r3));
668 bool hasMips32r5()
const {
669 return (getSTI().
hasFeature(Mips::FeatureMips32r5));
672 bool hasMips64r5()
const {
673 return (getSTI().
hasFeature(Mips::FeatureMips64r5));
676 bool hasMips32r6()
const {
677 return getSTI().hasFeature(Mips::FeatureMips32r6);
680 bool hasMips64r6()
const {
681 return getSTI().hasFeature(Mips::FeatureMips64r6);
684 bool hasNanoMips()
const {
685 return getSTI().hasFeature(Mips::FeatureNanoMips);
688 bool hasDSP()
const {
689 return getSTI().hasFeature(Mips::FeatureDSP);
692 bool hasDSPR2()
const {
693 return getSTI().hasFeature(Mips::FeatureDSPR2);
696 bool hasDSPR3()
const {
697 return getSTI().hasFeature(Mips::FeatureDSPR3);
700 bool hasMSA()
const {
701 return getSTI().hasFeature(Mips::FeatureMSA);
704 bool hasCnMips()
const {
705 return (getSTI().
hasFeature(Mips::FeatureCnMips));
708 bool hasCnMipsP()
const {
709 return (getSTI().
hasFeature(Mips::FeatureCnMipsP));
712 bool isR5900()
const {
return (getSTI().
hasFeature(Mips::FeatureR5900)); }
718 bool inMips16Mode()
const {
719 return getSTI().hasFeature(Mips::FeatureMips16);
722 bool useTraps()
const {
723 return getSTI().hasFeature(Mips::FeatureUseTCCInDIV);
726 bool useSoftFloat()
const {
727 return getSTI().hasFeature(Mips::FeatureSoftFloat);
730 bool isSingleFloat()
const {
731 return getSTI().hasFeature(Mips::FeatureSingleFloat);
735 return getSTI().hasFeature(Mips::FeatureMT);
738 bool hasCRC()
const {
739 return getSTI().hasFeature(Mips::FeatureCRC);
742 bool hasVirt()
const {
743 return getSTI().hasFeature(Mips::FeatureVirt);
746 bool hasGINV()
const {
747 return getSTI().hasFeature(Mips::FeatureGINV);
750 bool hasForbiddenSlot(
const MCInstrDesc &MCID)
const {
754 bool SafeInForbiddenSlot(
const MCInstrDesc &MCID)
const {
758 void onEndOfFile()
override;
761 void warnIfRegIndexIsAT(MCRegister RegIndex, SMLoc Loc);
763 void warnIfNoMacro(SMLoc Loc);
765 bool isLittle()
const {
return IsLittleEndian; }
767 bool areEqualRegs(
const MCParsedAsmOperand &Op1,
768 const MCParsedAsmOperand &Op2)
const override;
783 RegKind_MSACtrl = 16,
788 RegKind_HWRegs = 256,
792 RegKind_Numeric = RegKind_GPR | RegKind_FGR | RegKind_FCC | RegKind_MSA128 |
793 RegKind_MSACtrl | RegKind_COP2 | RegKind_ACC |
794 RegKind_CCR | RegKind_HWRegs | RegKind_COP3 | RegKind_COP0
807 MipsOperand(KindTy K, MipsAsmParser &Parser) : Kind(
K), AsmParser(Parser) {}
809 ~MipsOperand()
override {
818 case k_RegisterIndex:
826 MipsAsmParser &AsmParser;
837 const MCRegisterInfo *RegInfo;
855 struct RegIdxOp RegIdx;
858 struct RegListOp RegList;
861 SMLoc StartLoc, EndLoc;
864 static std::unique_ptr<MipsOperand> CreateReg(
unsigned Index, StringRef Str,
866 const MCRegisterInfo *RegInfo,
868 MipsAsmParser &Parser) {
869 auto Op = std::make_unique<MipsOperand>(k_RegisterIndex, Parser);
871 Op->RegIdx.RegInfo = RegInfo;
872 Op->RegIdx.Kind = RegKind;
873 Op->RegIdx.Tok.Data = Str.data();
874 Op->RegIdx.Tok.Length = Str.size();
883 MCRegister getGPR32Reg()
const {
884 assert(isRegIdx() && (RegIdx.Kind & RegKind_GPR) &&
"Invalid access!");
885 AsmParser.warnIfRegIndexIsAT(RegIdx.Index, StartLoc);
886 unsigned ClassID = Mips::GPR32RegClassID;
887 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
892 MCRegister getGPRMM16Reg()
const {
893 assert(isRegIdx() && (RegIdx.Kind & RegKind_GPR) &&
"Invalid access!");
894 unsigned ClassID = Mips::GPR32RegClassID;
895 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
900 MCRegister getGPR64Reg()
const {
901 assert(isRegIdx() && (RegIdx.Kind & RegKind_GPR) &&
"Invalid access!");
902 unsigned ClassID = Mips::GPR64RegClassID;
903 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
909 MCRegister getAFGR64Reg()
const {
910 assert(isRegIdx() && (RegIdx.Kind & RegKind_FGR) &&
"Invalid access!");
911 if (RegIdx.Index % 2 != 0)
912 AsmParser.Warning(StartLoc,
"Float register should be even.");
913 return RegIdx.RegInfo->getRegClass(Mips::AFGR64RegClassID)
914 .getRegister(RegIdx.Index / 2);
919 MCRegister getFGR64Reg()
const {
920 assert(isRegIdx() && (RegIdx.Kind & RegKind_FGR) &&
"Invalid access!");
921 return RegIdx.RegInfo->getRegClass(Mips::FGR64RegClassID)
922 .getRegister(RegIdx.Index);
927 MCRegister getFGR32Reg()
const {
928 assert(isRegIdx() && (RegIdx.Kind & RegKind_FGR) &&
"Invalid access!");
929 return RegIdx.RegInfo->getRegClass(Mips::FGR32RegClassID)
930 .getRegister(RegIdx.Index);
935 MCRegister getFCCReg()
const {
936 assert(isRegIdx() && (RegIdx.Kind & RegKind_FCC) &&
"Invalid access!");
937 return RegIdx.RegInfo->getRegClass(Mips::FCCRegClassID)
938 .getRegister(RegIdx.Index);
943 MCRegister getMSA128Reg()
const {
944 assert(isRegIdx() && (RegIdx.Kind & RegKind_MSA128) &&
"Invalid access!");
947 unsigned ClassID = Mips::MSA128BRegClassID;
948 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
953 MCRegister getMSACtrlReg()
const {
954 assert(isRegIdx() && (RegIdx.Kind & RegKind_MSACtrl) &&
"Invalid access!");
955 unsigned ClassID = Mips::MSACtrlRegClassID;
956 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
961 MCRegister getCOP0Reg()
const {
967 MCRegister getCOP2Reg()
const {
968 assert(isRegIdx() && (RegIdx.Kind & RegKind_COP2) &&
"Invalid access!");
969 unsigned ClassID = Mips::COP2RegClassID;
970 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
975 MCRegister getCOP3Reg()
const {
976 assert(isRegIdx() && (RegIdx.Kind & RegKind_COP3) &&
"Invalid access!");
977 unsigned ClassID = Mips::COP3RegClassID;
978 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
983 MCRegister getACC64DSPReg()
const {
984 assert(isRegIdx() && (RegIdx.Kind & RegKind_ACC) &&
"Invalid access!");
985 unsigned ClassID = Mips::ACC64DSPRegClassID;
986 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
991 MCRegister getHI32DSPReg()
const {
992 assert(isRegIdx() && (RegIdx.Kind & RegKind_ACC) &&
"Invalid access!");
993 unsigned ClassID = Mips::HI32DSPRegClassID;
994 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
999 MCRegister getLO32DSPReg()
const {
1000 assert(isRegIdx() && (RegIdx.Kind & RegKind_ACC) &&
"Invalid access!");
1001 unsigned ClassID = Mips::LO32DSPRegClassID;
1002 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
1007 MCRegister getCCRReg()
const {
1008 assert(isRegIdx() && (RegIdx.Kind & RegKind_CCR) &&
"Invalid access!");
1009 unsigned ClassID = Mips::CCRRegClassID;
1010 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
1015 MCRegister getHWRegsReg()
const {
1016 assert(isRegIdx() && (RegIdx.Kind & RegKind_HWRegs) &&
"Invalid access!");
1017 unsigned ClassID = Mips::HWRegsRegClassID;
1018 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
1022 void addExpr(MCInst &Inst,
const MCExpr *Expr)
const {
1032 void addRegOperands(MCInst &Inst,
unsigned N)
const {
1039 void addGPR32ZeroAsmRegOperands(MCInst &Inst,
unsigned N)
const {
1040 assert(
N == 1 &&
"Invalid number of operands!");
1044 void addGPR32NonZeroAsmRegOperands(MCInst &Inst,
unsigned N)
const {
1045 assert(
N == 1 &&
"Invalid number of operands!");
1049 void addGPR32AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1050 assert(
N == 1 &&
"Invalid number of operands!");
1054 void addGPRMM16AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1055 assert(
N == 1 &&
"Invalid number of operands!");
1059 void addGPRMM16AsmRegZeroOperands(MCInst &Inst,
unsigned N)
const {
1060 assert(
N == 1 &&
"Invalid number of operands!");
1064 void addGPRMM16AsmRegMovePOperands(MCInst &Inst,
unsigned N)
const {
1065 assert(
N == 1 &&
"Invalid number of operands!");
1069 void addGPRMM16AsmRegMovePPairFirstOperands(MCInst &Inst,
unsigned N)
const {
1070 assert(
N == 1 &&
"Invalid number of operands!");
1074 void addGPRMM16AsmRegMovePPairSecondOperands(MCInst &Inst,
1076 assert(
N == 1 &&
"Invalid number of operands!");
1083 void addGPR64AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1084 assert(
N == 1 &&
"Invalid number of operands!");
1088 void addAFGR64AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1089 assert(
N == 1 &&
"Invalid number of operands!");
1093 void addStrictlyAFGR64AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1094 assert(
N == 1 &&
"Invalid number of operands!");
1098 void addStrictlyFGR64AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1099 assert(
N == 1 &&
"Invalid number of operands!");
1103 void addFGR64AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1104 assert(
N == 1 &&
"Invalid number of operands!");
1108 void addFGR32AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1109 assert(
N == 1 &&
"Invalid number of operands!");
1113 if (!AsmParser.useOddSPReg() && RegIdx.Index & 1)
1114 AsmParser.getParser().printError(
1115 StartLoc,
"-mno-odd-spreg prohibits the use of odd FPU "
1119 void addStrictlyFGR32AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1120 assert(
N == 1 &&
"Invalid number of operands!");
1123 if (!AsmParser.useOddSPReg() && RegIdx.Index & 1)
1124 AsmParser.Error(StartLoc,
"-mno-odd-spreg prohibits the use of odd FPU "
1128 void addFCCAsmRegOperands(MCInst &Inst,
unsigned N)
const {
1129 assert(
N == 1 &&
"Invalid number of operands!");
1133 void addMSA128AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1134 assert(
N == 1 &&
"Invalid number of operands!");
1138 void addMSACtrlAsmRegOperands(MCInst &Inst,
unsigned N)
const {
1139 assert(
N == 1 &&
"Invalid number of operands!");
1143 void addCOP0AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1144 assert(
N == 1 &&
"Invalid number of operands!");
1148 void addCOP2AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1149 assert(
N == 1 &&
"Invalid number of operands!");
1153 void addCOP3AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1154 assert(
N == 1 &&
"Invalid number of operands!");
1158 void addACC64DSPAsmRegOperands(MCInst &Inst,
unsigned N)
const {
1159 assert(
N == 1 &&
"Invalid number of operands!");
1163 void addHI32DSPAsmRegOperands(MCInst &Inst,
unsigned N)
const {
1164 assert(
N == 1 &&
"Invalid number of operands!");
1168 void addLO32DSPAsmRegOperands(MCInst &Inst,
unsigned N)
const {
1169 assert(
N == 1 &&
"Invalid number of operands!");
1173 void addCCRAsmRegOperands(MCInst &Inst,
unsigned N)
const {
1174 assert(
N == 1 &&
"Invalid number of operands!");
1178 void addHWRegsAsmRegOperands(MCInst &Inst,
unsigned N)
const {
1179 assert(
N == 1 &&
"Invalid number of operands!");
1183 template <
unsigned Bits,
int Offset = 0,
int AdjustOffset = 0>
1184 void addConstantUImmOperands(MCInst &Inst,
unsigned N)
const {
1185 assert(
N == 1 &&
"Invalid number of operands!");
1189 Imm += AdjustOffset;
1193 template <
unsigned Bits>
1194 void addSImmOperands(MCInst &Inst,
unsigned N)
const {
1195 if (isImm() && !isConstantImm()) {
1199 addConstantSImmOperands<Bits, 0, 0>(Inst,
N);
1202 template <
unsigned Bits>
1203 void addUImmOperands(MCInst &Inst,
unsigned N)
const {
1204 if (isImm() && !isConstantImm()) {
1208 addConstantUImmOperands<Bits, 0, 0>(Inst,
N);
1211 template <
unsigned Bits,
int Offset = 0,
int AdjustOffset = 0>
1212 void addConstantSImmOperands(MCInst &Inst,
unsigned N)
const {
1213 assert(
N == 1 &&
"Invalid number of operands!");
1214 int64_t
Imm = getConstantImm() -
Offset;
1217 Imm += AdjustOffset;
1221 void addImmOperands(MCInst &Inst,
unsigned N)
const {
1222 assert(
N == 1 &&
"Invalid number of operands!");
1223 const MCExpr *Expr =
getImm();
1224 addExpr(Inst, Expr);
1227 void addPtrRegOperands(MCInst &Inst,
unsigned N)
const {
1228 assert(
N == 1 &&
"Invalid number of operands!");
1230 AsmParser.getABI().ArePtrs64bit() ? getGPR64Reg() : getGPR32Reg()));
1233 void addMemOperands(MCInst &Inst,
unsigned N)
const {
1234 assert(
N == 2 &&
"Invalid number of operands!");
1235 getMemBase()->addPtrRegOperands(Inst, 1);
1236 addExpr(Inst, getMemOff());
1239 bool isSPAsmReg()
const {
return isGPRAsmReg() && RegIdx.Index == 29; }
1240 bool isGPAsmReg()
const {
return isGPRAsmReg() && RegIdx.Index == 28; }
1242 bool isSImmPtr()
const {
1243 return AsmParser.getABI().ArePtrs64bit() ? isScaledSImm<64, 0>()
1244 : isScaledSImm<32, 0>();
1247 void addRegListOperands(MCInst &Inst,
unsigned N)
const {
1248 assert(
N == 1 &&
"Invalid number of operands!");
1250 for (
auto RegNo : getRegList())
1254 bool isReg()
const override {
1257 return isGPRAsmReg() && RegIdx.Index == 0;
1260 bool isRegIdx()
const {
return Kind == k_RegisterIndex; }
1262 bool isNumericReg()
const {
1263 return isRegIdx() && RegIdx.Kind == RegKind_Numeric && RegIdx.Index < 32;
1266 unsigned getNumericRegIndex()
const {
1267 assert(isNumericReg() &&
"Invalid numeric register");
1268 return RegIdx.Index;
1271 bool isImm()
const override {
return Kind == k_Immediate; }
1273 bool isConstantImm()
const {
1275 return isImm() &&
getImm()->evaluateAsAbsolute(Res);
1278 bool isConstantImmz()
const {
1279 return isConstantImm() && getConstantImm() == 0;
1282 template <
unsigned Bits,
int Offset = 0>
bool isConstantUImm()
const {
1286 template <
unsigned Bits>
bool isSImm()
const {
1290 if (
getImm()->evaluateAsAbsolute(Res))
1296 template <
unsigned Bits>
bool isUImm()
const {
1300 if (
getImm()->evaluateAsAbsolute(Res))
1306 template <
unsigned Bits>
bool isAnyImm()
const {
1307 return isConstantImm() ? (
isInt<Bits>(getConstantImm()) ||
1312 template <
unsigned Bits,
int Offset = 0>
bool isConstantSImm()
const {
1316 template <
unsigned Bottom,
unsigned Top>
bool isConstantUImmRange()
const {
1317 return isConstantImm() && getConstantImm() >= Bottom &&
1318 getConstantImm() <= Top;
1321 bool isToken()
const override {
1324 return Kind == k_Token;
1327 bool isMem()
const override {
return Kind == k_Memory; }
1332 template <
unsigned Bits,
unsigned ShiftLeftAmount,
int Bias = 0>
1333 bool isScaledUImm()
const {
1335 uint64_t(getConstantImm()) - Bias);
1338 template <
unsigned Bits,
unsigned ShiftLeftAmount>
1339 bool isScaledSImm()
const {
1340 if (isConstantImm() &&
1345 if (Kind != k_Immediate)
1350 bool Success =
getImm()->evaluateAsRelocatable(Res,
nullptr);
1354 bool isRegList16()
const {
1358 int Size = RegList.List->size();
1362 MCRegister R0 = RegList.List->front();
1363 MCRegister R1 = RegList.List->back();
1364 if (!((R0 == Mips::R16 && R1 ==
Mips::RA) ||
1368 MCRegister PrevReg = RegList.List->front();
1369 for (
int i = 1; i <
Size - 1; i++) {
1370 MCRegister
Reg = (*(RegList.List))[i];
1371 if (
Reg != PrevReg + 1)
1379 bool isInvNum()
const {
return Kind == k_Immediate; }
1381 bool isLSAImm()
const {
1382 if (!isConstantImm())
1384 int64_t Val = getConstantImm();
1385 return 1 <= Val && Val <= 4;
1388 bool isRegList()
const {
return Kind == k_RegList; }
1391 assert(Kind == k_Token &&
"Invalid access!");
1392 return StringRef(Tok.Data, Tok.Length);
1395 MCRegister
getReg()
const override {
1398 if (Kind == k_RegisterIndex && RegIdx.Index == 0 &&
1399 RegIdx.Kind & RegKind_GPR)
1400 return getGPR32Reg();
1406 const MCExpr *
getImm()
const {
1407 assert((Kind == k_Immediate) &&
"Invalid access!");
1411 int64_t getConstantImm()
const {
1412 const MCExpr *Val =
getImm();
1414 (void)Val->evaluateAsAbsolute(
Value);
1418 MipsOperand *getMemBase()
const {
1419 assert((Kind == k_Memory) &&
"Invalid access!");
1423 const MCExpr *getMemOff()
const {
1424 assert((Kind == k_Memory) &&
"Invalid access!");
1428 const SmallVectorImpl<MCRegister> &getRegList()
const {
1429 assert((Kind == k_RegList) &&
"Invalid access!");
1430 return *(RegList.List);
1433 static std::unique_ptr<MipsOperand> CreateToken(StringRef Str, SMLoc S,
1434 MipsAsmParser &Parser) {
1435 auto Op = std::make_unique<MipsOperand>(k_Token, Parser);
1436 Op->Tok.Data = Str.data();
1437 Op->Tok.Length = Str.size();
1445 static std::unique_ptr<MipsOperand>
1446 createNumericReg(
unsigned Index, StringRef Str,
const MCRegisterInfo *RegInfo,
1447 SMLoc S, SMLoc
E, MipsAsmParser &Parser) {
1448 LLVM_DEBUG(
dbgs() <<
"createNumericReg(" << Index <<
", ...)\n");
1449 return CreateReg(Index, Str, RegKind_Numeric, RegInfo, S,
E, Parser);
1454 static std::unique_ptr<MipsOperand>
1455 createGPRReg(
unsigned Index, StringRef Str,
const MCRegisterInfo *RegInfo,
1456 SMLoc S, SMLoc
E, MipsAsmParser &Parser) {
1457 return CreateReg(Index, Str, RegKind_GPR, RegInfo, S,
E, Parser);
1462 static std::unique_ptr<MipsOperand>
1463 createFGRReg(
unsigned Index, StringRef Str,
const MCRegisterInfo *RegInfo,
1464 SMLoc S, SMLoc
E, MipsAsmParser &Parser) {
1465 return CreateReg(Index, Str, RegKind_FGR, RegInfo, S,
E, Parser);
1468 static std::unique_ptr<MipsOperand>
1469 createCOP0Reg(
unsigned Encoding, StringRef Str,
const MCRegisterInfo *RegInfo,
1470 SMLoc S, SMLoc
E, MipsAsmParser &Parser) {
1473 "Invalid COP0 register encoding");
1474 return CreateReg(Encoding, Str, RegKind_COP0, RegInfo, S,
E, Parser);
1479 static std::unique_ptr<MipsOperand>
1480 createHWRegsReg(
unsigned Index, StringRef Str,
const MCRegisterInfo *RegInfo,
1481 SMLoc S, SMLoc
E, MipsAsmParser &Parser) {
1482 return CreateReg(Index, Str, RegKind_HWRegs, RegInfo, S,
E, Parser);
1487 static std::unique_ptr<MipsOperand>
1488 createFCCReg(
unsigned Index, StringRef Str,
const MCRegisterInfo *RegInfo,
1489 SMLoc S, SMLoc
E, MipsAsmParser &Parser) {
1490 return CreateReg(Index, Str, RegKind_FCC, RegInfo, S,
E, Parser);
1495 static std::unique_ptr<MipsOperand>
1496 createACCReg(
unsigned Index, StringRef Str,
const MCRegisterInfo *RegInfo,
1497 SMLoc S, SMLoc
E, MipsAsmParser &Parser) {
1498 return CreateReg(Index, Str, RegKind_ACC, RegInfo, S,
E, Parser);
1503 static std::unique_ptr<MipsOperand>
1504 createMSA128Reg(
unsigned Index, StringRef Str,
const MCRegisterInfo *RegInfo,
1505 SMLoc S, SMLoc
E, MipsAsmParser &Parser) {
1506 return CreateReg(Index, Str, RegKind_MSA128, RegInfo, S,
E, Parser);
1511 static std::unique_ptr<MipsOperand>
1512 createMSACtrlReg(
unsigned Index, StringRef Str,
const MCRegisterInfo *RegInfo,
1513 SMLoc S, SMLoc
E, MipsAsmParser &Parser) {
1514 return CreateReg(Index, Str, RegKind_MSACtrl, RegInfo, S,
E, Parser);
1517 static std::unique_ptr<MipsOperand>
1518 CreateImm(
const MCExpr *Val, SMLoc S, SMLoc
E, MipsAsmParser &Parser) {
1519 auto Op = std::make_unique<MipsOperand>(k_Immediate, Parser);
1526 static std::unique_ptr<MipsOperand>
1527 CreateMem(std::unique_ptr<MipsOperand>
Base,
const MCExpr *
Off, SMLoc S,
1528 SMLoc
E, MipsAsmParser &Parser) {
1529 auto Op = std::make_unique<MipsOperand>(k_Memory, Parser);
1530 Op->Mem.Base =
Base.release();
1537 static std::unique_ptr<MipsOperand>
1538 CreateRegList(SmallVectorImpl<MCRegister> &Regs, SMLoc StartLoc, SMLoc EndLoc,
1539 MipsAsmParser &Parser) {
1540 assert(!Regs.
empty() &&
"Empty list not allowed");
1542 auto Op = std::make_unique<MipsOperand>(k_RegList, Parser);
1545 Op->StartLoc = StartLoc;
1546 Op->EndLoc = EndLoc;
1550 bool isGPRZeroAsmReg()
const {
1551 return isRegIdx() && RegIdx.Kind & RegKind_GPR && RegIdx.Index == 0;
1554 bool isGPRNonZeroAsmReg()
const {
1555 return isRegIdx() && RegIdx.Kind & RegKind_GPR && RegIdx.Index > 0 &&
1559 bool isGPRAsmReg()
const {
1560 return isRegIdx() && RegIdx.Kind & RegKind_GPR && RegIdx.Index <= 31;
1563 bool isMM16AsmReg()
const {
1566 return ((RegIdx.Index >= 2 && RegIdx.Index <= 7)
1567 || RegIdx.Index == 16 || RegIdx.Index == 17);
1570 bool isMM16AsmRegZero()
const {
1573 return (RegIdx.Index == 0 ||
1574 (RegIdx.Index >= 2 && RegIdx.Index <= 7) ||
1575 RegIdx.Index == 17);
1578 bool isMM16AsmRegMoveP()
const {
1579 if (!(isRegIdx() && RegIdx.Kind))
1581 return (RegIdx.Index == 0 || (RegIdx.Index >= 2 && RegIdx.Index <= 3) ||
1582 (RegIdx.Index >= 16 && RegIdx.Index <= 20));
1585 bool isMM16AsmRegMovePPairFirst()
const {
1586 if (!(isRegIdx() && RegIdx.Kind))
1588 return RegIdx.Index >= 4 && RegIdx.Index <= 6;
1591 bool isMM16AsmRegMovePPairSecond()
const {
1592 if (!(isRegIdx() && RegIdx.Kind))
1594 return (RegIdx.Index == 21 || RegIdx.Index == 22 ||
1595 (RegIdx.Index >= 5 && RegIdx.Index <= 7));
1598 bool isFGRAsmReg()
const {
1600 return isRegIdx() && RegIdx.Kind & RegKind_FGR && RegIdx.Index <= 31;
1603 bool isStrictlyFGRAsmReg()
const {
1605 return isRegIdx() && RegIdx.Kind == RegKind_FGR && RegIdx.Index <= 31;
1608 bool isHWRegsAsmReg()
const {
1609 return isRegIdx() && RegIdx.Kind & RegKind_HWRegs && RegIdx.Index <= 31;
1612 bool isCCRAsmReg()
const {
1613 return isRegIdx() && RegIdx.Kind & RegKind_CCR && RegIdx.Index <= 31;
1616 bool isFCCAsmReg()
const {
1617 if (!(isRegIdx() && RegIdx.Kind & RegKind_FCC))
1619 return RegIdx.Index <= 7;
1622 bool isACCAsmReg()
const {
1623 return isRegIdx() && RegIdx.Kind & RegKind_ACC && RegIdx.Index <= 3;
1626 bool isCOP0AsmReg()
const {
1627 return isRegIdx() && RegIdx.Kind == RegKind_COP0;
1630 unsigned getCOP0Encoding()
const {
1631 assert(isCOP0AsmReg() &&
"Invalid COP0 register");
1632 return RegIdx.Index;
1635 bool isCOP2AsmReg()
const {
1636 return isRegIdx() && RegIdx.Kind & RegKind_COP2 && RegIdx.Index <= 31;
1639 bool isCOP3AsmReg()
const {
1640 return isRegIdx() && RegIdx.Kind & RegKind_COP3 && RegIdx.Index <= 31;
1643 bool isMSA128AsmReg()
const {
1644 return isRegIdx() && RegIdx.Kind & RegKind_MSA128 && RegIdx.Index <= 31;
1647 bool isMSACtrlAsmReg()
const {
1648 return isRegIdx() && RegIdx.Kind & RegKind_MSACtrl && RegIdx.Index <= 7;
1651 bool isNM16AsmReg()
const {
1652 if (!(isRegIdx() && RegIdx.Kind))
1654 return ((RegIdx.Index >= 4 && RegIdx.Index <= 7) ||
1655 (RegIdx.Index >= 16 && RegIdx.Index <= 19));
1658 bool isNM16ZeroAsmReg()
const {
1659 if (!(isRegIdx() && RegIdx.Kind))
1661 return ((RegIdx.Index == 0) || (RegIdx.Index >= 4 && RegIdx.Index <= 7) ||
1662 (RegIdx.Index >= 17 && RegIdx.Index <= 19));
1665 bool isNM4AsmReg()
const {
1666 if (!(isRegIdx() && RegIdx.Kind))
1668 return ((RegIdx.Index >= 4 && RegIdx.Index <= 11) ||
1669 (RegIdx.Index >= 16 && RegIdx.Index <= 23));
1672 bool isNM4ZeroAsmReg()
const {
1673 if (!(isRegIdx() && RegIdx.Kind))
1675 return ((RegIdx.Index == 0) || (RegIdx.Index >= 4 && RegIdx.Index <= 10) ||
1676 (RegIdx.Index >= 16 && RegIdx.Index <= 23));
1679 bool isNM2R1AsmReg()
const {
1680 if (!(isRegIdx() && RegIdx.Kind))
1682 return RegIdx.Index >= 4 && RegIdx.Index <= 7;
1685 bool isNM2R2AsmReg()
const {
1686 if (!(isRegIdx() && RegIdx.Kind))
1688 return RegIdx.Index >= 5 && RegIdx.Index <= 8;
1691 bool isNM1R1AsmReg()
const {
1692 if (!(isRegIdx() && RegIdx.Kind))
1694 return RegIdx.Index == 4 || RegIdx.Index == 5;
1697 template <
unsigned RegClassID = Mips::GPR32RegClassID>
1698 bool isGPRNMAsmReg()
const {
1699 if (!(isRegIdx() && RegIdx.Kind))
1701 switch (RegClassID) {
1702 case Mips::GP32RegClassID:
1703 return (RegIdx.Index == 28);
1704 case Mips::SP32RegClassID:
1705 return (RegIdx.Index == 29);
1706 case Mips::GPRNMRARegClassID:
1707 return (RegIdx.Index == 31);
1708 case Mips::GPR32NONZERORegClassID:
1709 return (RegIdx.Index > 0 && RegIdx.Index < 32);
1710 case Mips::GPRNM3RegClassID:
1711 return isNM16AsmReg();
1712 case Mips::GPRNM3ZRegClassID:
1713 return isNM16ZeroAsmReg();
1714 case Mips::GPRNM4RegClassID:
1715 return isNM4AsmReg();
1716 case Mips::GPRNM4ZRegClassID:
1717 return isNM4ZeroAsmReg();
1718 case Mips::GPRNM2R1RegClassID:
1719 return isNM2R1AsmReg();
1720 case Mips::GPRNM2R2RegClassID:
1721 return isNM2R2AsmReg();
1722 case Mips::GPRNM1R1RegClassID:
1723 return isNM1R1AsmReg();
1725 return RegIdx.Index < 32;
1730 SMLoc getStartLoc()
const override {
return StartLoc; }
1732 SMLoc getEndLoc()
const override {
return EndLoc; }
1734 void print(raw_ostream &OS,
const MCAsmInfo &MAI)
const override {
1743 Mem.Base->print(OS, MAI);
1748 case k_RegisterIndex:
1749 OS <<
"RegIdx<" << RegIdx.Index <<
":" << RegIdx.Kind <<
", "
1750 << StringRef(RegIdx.Tok.Data, RegIdx.Tok.Length) <<
">";
1757 for (
auto Reg : (*RegList.List))
1758 OS <<
Reg.
id() <<
" ";
1764 bool isValidForTie(
const MipsOperand &
Other)
const {
1765 if (Kind !=
Other.Kind)
1772 case k_RegisterIndex: {
1773 StringRef Token(RegIdx.Tok.Data, RegIdx.Tok.Length);
1774 StringRef OtherToken(
Other.RegIdx.Tok.Data,
Other.RegIdx.Tok.Length);
1775 return Token == OtherToken;
1791 case Mips::JRC16_MM:
1793 case Mips::JALRS_MM:
1794 case Mips::JALRS16_MM:
1795 case Mips::BGEZALS_MM:
1796 case Mips::BLTZALS_MM:
1807 return &SRExpr->getSymbol();
1866 unsigned NumOp =
MCID.getNumOperands();
1867 if (NumOp != 3 && NumOp != 4)
1897bool MipsAsmParser::processInstruction(
MCInst &Inst,
SMLoc IDLoc,
1900 MipsTargetStreamer &TOut = getTargetStreamer();
1901 const unsigned Opcode = Inst.
getOpcode();
1902 const MCInstrDesc &MCID = MII.get(Opcode);
1903 bool ExpandedJalSym =
false;
1917 assert(hasCnMips() &&
"instruction only valid for octeon cpus");
1928 if (!
isIntN(inMicroMipsMode() ? 17 : 18,
Offset.getImm()))
1929 return Error(IDLoc,
"branch target out of range");
1932 return Error(IDLoc,
"branch to misaligned address");
1946 case Mips::BGEZAL_MM:
1947 case Mips::BLTZAL_MM:
1950 case Mips::BC1EQZC_MMR6:
1951 case Mips::BC1NEZC_MMR6:
1952 case Mips::BC2EQZC_MMR6:
1953 case Mips::BC2NEZC_MMR6:
1958 if (!
isIntN(inMicroMipsMode() ? 17 : 18,
Offset.getImm()))
1959 return Error(IDLoc,
"branch target out of range");
1962 return Error(IDLoc,
"branch to misaligned address");
1964 case Mips::BGEC:
case Mips::BGEC_MMR6:
1965 case Mips::BLTC:
case Mips::BLTC_MMR6:
1966 case Mips::BGEUC:
case Mips::BGEUC_MMR6:
1967 case Mips::BLTUC:
case Mips::BLTUC_MMR6:
1968 case Mips::BEQC:
case Mips::BEQC_MMR6:
1969 case Mips::BNEC:
case Mips::BNEC_MMR6:
1975 return Error(IDLoc,
"branch target out of range");
1977 return Error(IDLoc,
"branch to misaligned address");
1979 case Mips::BLEZC:
case Mips::BLEZC_MMR6:
1980 case Mips::BGEZC:
case Mips::BGEZC_MMR6:
1981 case Mips::BGTZC:
case Mips::BGTZC_MMR6:
1982 case Mips::BLTZC:
case Mips::BLTZC_MMR6:
1988 return Error(IDLoc,
"branch target out of range");
1990 return Error(IDLoc,
"branch to misaligned address");
1992 case Mips::BEQZC:
case Mips::BEQZC_MMR6:
1993 case Mips::BNEZC:
case Mips::BNEZC_MMR6:
1999 return Error(IDLoc,
"branch target out of range");
2001 return Error(IDLoc,
"branch to misaligned address");
2003 case Mips::BEQZ16_MM:
2004 case Mips::BEQZC16_MMR6:
2005 case Mips::BNEZ16_MM:
2006 case Mips::BNEZC16_MMR6:
2012 return Error(IDLoc,
"branch target out of range");
2014 return Error(IDLoc,
"branch to misaligned address");
2021 if (hasMips32r6() && Opcode == Mips::SSNOP) {
2022 std::string
ISA = hasMips64r6() ?
"MIPS64r6" :
"MIPS32r6";
2023 Warning(IDLoc,
"ssnop is deprecated for " + ISA +
" and is equivalent to a "
2043 return Error(IDLoc,
"expected immediate operand kind");
2046 Opcode == Mips::BBIT1 ? 63 : 31))
2047 return Error(IDLoc,
"immediate operand value out of range");
2049 Inst.
setOpcode(Opcode == Mips::BBIT0 ? Mips::BBIT032
2060 return Error(IDLoc,
"expected immediate operand kind");
2063 return Error(IDLoc,
"immediate operand value out of range");
2075 unsigned FirstOp = 1;
2076 unsigned SecondOp = 2;
2080 case Mips::SDivIMacro:
2081 case Mips::UDivIMacro:
2082 case Mips::DSDivIMacro:
2083 case Mips::DUDivIMacro:
2085 return Error(IDLoc,
"expected immediate operand kind");
2089 Warning(IDLoc,
"dividing zero by zero");
2091 Warning(IDLoc,
"division by zero");
2103 case Mips::SDivMacro:
2104 case Mips::DSDivMacro:
2105 case Mips::UDivMacro:
2106 case Mips::DUDivMacro:
2111 case Mips::DIVU_MMR6:
2112 case Mips::DIV_MMR6:
2117 Warning(IDLoc,
"dividing zero by zero");
2119 Warning(IDLoc,
"division by zero");
2125 if ((Opcode == Mips::J || Opcode == Mips::J_MM) && inPicMode()) {
2127 BInst.
setOpcode(inMicroMipsMode() ? Mips::BEQ_MM : Mips::BEQ);
2136 if ((Opcode == Mips::JAL || Opcode == Mips::JAL_MM) && inPicMode()) {
2137 warnIfNoMacro(IDLoc);
2140 return Error(IDLoc,
"unsupported constant in relocation");
2148 return Error(IDLoc,
"jal doesn't support multiple symbols in PIC mode");
2154 if (expandLoadAddress(
getABI().getTempReg(9), MCRegister(),
2155 Inst.
getOperand(0), !isGP64bit(), IDLoc, Out, STI))
2159 if (inMicroMipsMode())
2160 JalrInst.
setOpcode(IsCpRestoreSet ? Mips::JALRS_MM : Mips::JALR_MM);
2166 if (isJalrRelocAvailable(JalExpr)) {
2172 const MCExpr *RelocJalrExpr =
2176 *TmpExpr, inMicroMipsMode() ?
"R_MICROMIPS_JALR" :
"R_MIPS_JALR",
2182 ExpandedJalSym =
true;
2191 expandMem9Inst(Inst, IDLoc, Out, STI, MCID.
mayLoad());
2194 expandMem16Inst(Inst, IDLoc, Out, STI, MCID.
mayLoad());
2197 return getParser().hasPendingError();
2201 if (inMicroMipsMode()) {
2202 if (Opcode == Mips::LW_MM || Opcode == Mips::LW_MMR6) {
2205 const MCOperandInfo &OpInfo = MCID.
operands()[i];
2210 int MemOffset =
Op.getImm();
2213 if (
isInt<9>(MemOffset) && (MemOffset % 4 == 0) &&
2236 case Mips::ADDIUSP_MM:
2239 return Error(IDLoc,
"expected immediate operand kind");
2243 return Error(IDLoc,
"immediate operand value out of range");
2245 case Mips::SLL16_MM:
2246 case Mips::SRL16_MM:
2249 return Error(IDLoc,
"expected immediate operand kind");
2252 return Error(IDLoc,
"immediate operand value out of range");
2257 return Error(IDLoc,
"expected immediate operand kind");
2260 return Error(IDLoc,
"immediate operand value out of range");
2262 case Mips::ADDIUR2_MM:
2265 return Error(IDLoc,
"expected immediate operand kind");
2267 if (!(
Imm == 1 ||
Imm == -1 ||
2269 return Error(IDLoc,
"immediate operand value out of range");
2271 case Mips::ANDI16_MM:
2274 return Error(IDLoc,
"expected immediate operand kind");
2278 Imm == 64 ||
Imm == 255 ||
Imm == 32768 ||
Imm == 65535))
2279 return Error(IDLoc,
"immediate operand value out of range");
2281 case Mips::LBU16_MM:
2284 return Error(IDLoc,
"expected immediate operand kind");
2287 return Error(IDLoc,
"immediate operand value out of range");
2290 case Mips::SB16_MMR6:
2293 return Error(IDLoc,
"expected immediate operand kind");
2296 return Error(IDLoc,
"immediate operand value out of range");
2298 case Mips::LHU16_MM:
2300 case Mips::SH16_MMR6:
2303 return Error(IDLoc,
"expected immediate operand kind");
2306 return Error(IDLoc,
"immediate operand value out of range");
2310 case Mips::SW16_MMR6:
2313 return Error(IDLoc,
"expected immediate operand kind");
2316 return Error(IDLoc,
"immediate operand value out of range");
2318 case Mips::ADDIUPC_MM:
2321 return Error(IDLoc,
"expected immediate operand kind");
2324 return Error(IDLoc,
"immediate operand value out of range");
2329 return Error(IDLoc,
"invalid operand for instruction");
2331 case Mips::MOVEP_MM:
2332 case Mips::MOVEP_MMR6: {
2335 bool RegPair = ((R0 == Mips::R5 && R1 == Mips::R6) ||
2336 (R0 == Mips::R5 && R1 == Mips::R7) ||
2337 (R0 == Mips::R6 && R1 == Mips::R7) ||
2338 (R0 == Mips::R4 && R1 == Mips::R21) ||
2339 (R0 == Mips::R4 && R1 == Mips::R22) ||
2340 (R0 == Mips::R4 && R1 == Mips::R5) ||
2341 (R0 == Mips::R4 && R1 == Mips::R6) ||
2342 (R0 == Mips::R4 && R1 == Mips::R7));
2344 return Error(IDLoc,
"invalid operand for instruction");
2350 bool FillDelaySlot =
2355 bool PrevForbiddenSlotAttr = CurForbiddenSlotAttr;
2358 bool SetReorderAfterNop =
false;
2363 if (PrevForbiddenSlotAttr && !SafeInForbiddenSlot(MCID)) {
2373 if (AssemblerOptions.
back()->isReorder() && !FillDelaySlot) {
2374 SetReorderAfterNop =
true;
2383 CurForbiddenSlotAttr =
2384 hasForbiddenSlot(MCID) && AssemblerOptions.
back()->isReorder();
2386 if (FillDelaySlot || CurForbiddenSlotAttr)
2389 MacroExpanderResultTy ExpandResult =
2390 tryExpandInstruction(Inst, IDLoc, Out, STI);
2391 switch (ExpandResult) {
2393 Out.emitInstruction(Inst, *STI);
2407 if (PrevForbiddenSlotAttr && !SetReorderAfterNop && !FillDelaySlot &&
2408 AssemblerOptions.
back()->isReorder()) {
2414 if (inMicroMipsMode()) {
2429 if (FillDelaySlot) {
2434 if ((Opcode == Mips::JalOneReg || Opcode == Mips::JalTwoReg ||
2436 isPicAndNotNxxAbi()) {
2437 if (IsCpRestoreSet) {
2441 if (!AssemblerOptions.
back()->isReorder())
2448 Warning(IDLoc,
"no .cprestore used in PIC mode");
2454void MipsAsmParser::onEndOfFile() {
2455 MipsTargetStreamer &TOut = getTargetStreamer();
2456 SMLoc IDLoc = SMLoc();
2458 if (CurForbiddenSlotAttr) {
2460 if (AssemblerOptions.
back()->isReorder())
2465MipsAsmParser::MacroExpanderResultTy
2466MipsAsmParser::tryExpandInstruction(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
2467 const MCSubtargetInfo *STI) {
2470 return MER_NotAMacro;
2471 case Mips::LoadImm32:
2472 return expandLoadImm(Inst,
true, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2473 case Mips::LoadImm64:
2474 return expandLoadImm(Inst,
false, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2475 case Mips::LoadAddrImm32:
2476 case Mips::LoadAddrImm64:
2479 "expected immediate operand kind");
2481 return expandLoadAddress(
2483 Inst.
getOpcode() == Mips::LoadAddrImm32, IDLoc, Out, STI)
2486 case Mips::LoadAddrReg32:
2487 case Mips::LoadAddrReg64:
2491 "expected immediate operand kind");
2495 Inst.
getOpcode() == Mips::LoadAddrReg32, IDLoc,
2499 case Mips::B_MM_Pseudo:
2500 case Mips::B_MMR6_Pseudo:
2501 return expandUncondBranchMMPseudo(Inst, IDLoc, Out, STI) ? MER_Fail
2505 return expandLoadStoreMultiple(Inst, IDLoc, Out, STI) ? MER_Fail
2507 case Mips::JalOneReg:
2508 case Mips::JalTwoReg:
2509 return expandJalWithRegs(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2512 case Mips::BEQLImmMacro:
2513 case Mips::BNELImmMacro:
2514 return expandBranchImm(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2531 case Mips::BLTImmMacro:
2532 case Mips::BLEImmMacro:
2533 case Mips::BGEImmMacro:
2534 case Mips::BGTImmMacro:
2535 case Mips::BLTUImmMacro:
2536 case Mips::BLEUImmMacro:
2537 case Mips::BGEUImmMacro:
2538 case Mips::BGTUImmMacro:
2539 case Mips::BLTLImmMacro:
2540 case Mips::BLELImmMacro:
2541 case Mips::BGELImmMacro:
2542 case Mips::BGTLImmMacro:
2543 case Mips::BLTULImmMacro:
2544 case Mips::BLEULImmMacro:
2545 case Mips::BGEULImmMacro:
2546 case Mips::BGTULImmMacro:
2547 return expandCondBranches(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2548 case Mips::SDivMacro:
2549 case Mips::SDivIMacro:
2550 case Mips::SRemMacro:
2551 case Mips::SRemIMacro:
2552 return expandDivRem(Inst, IDLoc, Out, STI,
false,
true) ? MER_Fail
2554 case Mips::DSDivMacro:
2555 case Mips::DSDivIMacro:
2556 case Mips::DSRemMacro:
2557 case Mips::DSRemIMacro:
2558 return expandDivRem(Inst, IDLoc, Out, STI,
true,
true) ? MER_Fail
2560 case Mips::UDivMacro:
2561 case Mips::UDivIMacro:
2562 case Mips::URemMacro:
2563 case Mips::URemIMacro:
2564 return expandDivRem(Inst, IDLoc, Out, STI,
false,
false) ? MER_Fail
2566 case Mips::DUDivMacro:
2567 case Mips::DUDivIMacro:
2568 case Mips::DURemMacro:
2569 case Mips::DURemIMacro:
2570 return expandDivRem(Inst, IDLoc, Out, STI,
true,
false) ? MER_Fail
2572 case Mips::PseudoTRUNC_W_S:
2573 return expandTrunc(Inst,
false,
false, IDLoc, Out, STI) ? MER_Fail
2575 case Mips::PseudoTRUNC_W_D32:
2576 return expandTrunc(Inst,
true,
false, IDLoc, Out, STI) ? MER_Fail
2578 case Mips::PseudoTRUNC_W_D:
2579 return expandTrunc(Inst,
true,
true, IDLoc, Out, STI) ? MER_Fail
2582 case Mips::LoadImmSingleGPR:
2583 return expandLoadSingleImmToGPR(Inst, IDLoc, Out, STI) ? MER_Fail
2585 case Mips::LoadImmSingleFGR:
2586 return expandLoadSingleImmToFPR(Inst, IDLoc, Out, STI) ? MER_Fail
2588 case Mips::LoadImmDoubleGPR:
2589 return expandLoadDoubleImmToGPR(Inst, IDLoc, Out, STI) ? MER_Fail
2591 case Mips::LoadImmDoubleFGR:
2592 return expandLoadDoubleImmToFPR(Inst,
true, IDLoc, Out, STI) ? MER_Fail
2594 case Mips::LoadImmDoubleFGR_32:
2595 return expandLoadDoubleImmToFPR(Inst,
false, IDLoc, Out, STI) ? MER_Fail
2599 return expandUlh(Inst,
true, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2601 return expandUlh(Inst,
false, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2603 return expandUsh(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2606 return expandUxw(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2608 case Mips::NORImm64:
2609 return expandAliasImmediate(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2612 return expandSge(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2615 case Mips::SGEImm64:
2616 case Mips::SGEUImm64:
2617 return expandSgeImm(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2620 case Mips::SGTImm64:
2621 case Mips::SGTUImm64:
2622 return expandSgtImm(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2625 return expandSle(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2628 case Mips::SLEImm64:
2629 case Mips::SLEUImm64:
2630 return expandSleImm(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2631 case Mips::SLTImm64:
2634 return MER_NotAMacro;
2636 return expandAliasImmediate(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2637 case Mips::SLTUImm64:
2640 return MER_NotAMacro;
2642 return expandAliasImmediate(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2643 case Mips::ADDi:
case Mips::ADDi_MM:
2644 case Mips::ADDiu:
case Mips::ADDiu_MM:
2645 case Mips::SLTi:
case Mips::SLTi_MM:
2646 case Mips::SLTiu:
case Mips::SLTiu_MM:
2651 return MER_NotAMacro;
2652 return expandAliasImmediate(Inst, IDLoc, Out, STI) ? MER_Fail
2655 return MER_NotAMacro;
2656 case Mips::ANDi:
case Mips::ANDi_MM:
case Mips::ANDi64:
2657 case Mips::ORi:
case Mips::ORi_MM:
case Mips::ORi64:
2658 case Mips::XORi:
case Mips::XORi_MM:
case Mips::XORi64:
2663 return MER_NotAMacro;
2664 return expandAliasImmediate(Inst, IDLoc, Out, STI) ? MER_Fail
2667 return MER_NotAMacro;
2670 return expandRotation(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2673 return expandRotationImm(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2676 return expandDRotation(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2679 return expandDRotationImm(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2680 case Mips::ABSMacro:
2681 return expandAbs(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2682 case Mips::MULImmMacro:
2683 case Mips::DMULImmMacro:
2684 return expandMulImm(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2685 case Mips::MULOMacro:
2686 case Mips::DMULOMacro:
2687 return expandMulO(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2688 case Mips::MULOUMacro:
2689 case Mips::DMULOUMacro:
2690 return expandMulOU(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2691 case Mips::DMULMacro:
2692 return expandDMULMacro(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2695 return expandLoadStoreDMacro(Inst, IDLoc, Out, STI,
2701 return expandLoadStoreDM1Macro(Inst, IDLoc, Out, STI,
2705 case Mips::SEQMacro:
2706 return expandSeq(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2707 case Mips::SEQIMacro:
2708 return expandSeqI(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2709 case Mips::SNEMacro:
2710 return expandSne(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2711 case Mips::SNEIMacro:
2712 return expandSneI(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2713 case Mips::MFTGPR:
case Mips::MTTGPR:
2714 case Mips::MFTLO:
case Mips::MTTLO:
2715 case Mips::MFTHI:
case Mips::MTTHI:
2716 case Mips::MFTACX:
case Mips::MTTACX:
2717 case Mips::MFTDSP:
case Mips::MTTDSP:
2718 case Mips::MFTC1:
case Mips::MTTC1:
2719 case Mips::MFTHC1:
case Mips::MTTHC1:
2720 case Mips::CFTC1:
case Mips::CTTC1:
2721 return expandMXTRAlias(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2723 case Mips::SaadAddr:
2724 return expandSaaAddr(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2728bool MipsAsmParser::expandJalWithRegs(MCInst &Inst, SMLoc IDLoc,
2730 const MCSubtargetInfo *STI) {
2731 MipsTargetStreamer &TOut = getTargetStreamer();
2736 const MCOperand FirstRegOp = Inst.
getOperand(0);
2737 const unsigned Opcode = Inst.
getOpcode();
2739 if (Opcode == Mips::JalOneReg) {
2741 if (IsCpRestoreSet && inMicroMipsMode()) {
2744 }
else if (inMicroMipsMode()) {
2745 JalrInst.
setOpcode(hasMips32r6() ? Mips::JALRC16_MMR6 : Mips::JALR16_MM);
2752 }
else if (Opcode == Mips::JalTwoReg) {
2754 if (IsCpRestoreSet && inMicroMipsMode())
2757 JalrInst.
setOpcode(inMicroMipsMode() ? Mips::JALR_MM : Mips::JALR);
2759 const MCOperand SecondRegOp = Inst.
getOperand(1);
2762 Out.emitInstruction(JalrInst, *STI);
2766 const MCInstrDesc &MCID = MII.get(JalrInst.
getOpcode());
2789bool MipsAsmParser::loadImmediate(int64_t ImmValue, MCRegister DstReg,
2790 MCRegister SrcReg,
bool Is32BitImm,
2791 bool IsAddress, SMLoc IDLoc, MCStreamer &Out,
2792 const MCSubtargetInfo *STI) {
2793 MipsTargetStreamer &TOut = getTargetStreamer();
2795 if (!Is32BitImm && !isGP64bit()) {
2796 Error(IDLoc,
"instruction requires a 64-bit architecture");
2807 Error(IDLoc,
"instruction requires a 32-bit immediate");
2812 MCRegister ZeroReg = IsAddress ?
ABI.GetNullPtr() :
ABI.GetZeroReg();
2813 unsigned AdduOp = !Is32BitImm ? Mips::DADDu : Mips::ADDu;
2815 bool UseSrcReg =
false;
2819 MCRegister TmpReg = DstReg;
2821 getContext().getRegisterInfo()->isSuperOrSubRegisterEq(DstReg, SrcReg)) {
2824 MCRegister ATReg = getATReg(IDLoc);
2837 if (IsAddress && !Is32BitImm) {
2838 TOut.
emitRRI(Mips::DADDiu, DstReg, SrcReg, ImmValue, IDLoc, STI);
2842 TOut.
emitRRI(Mips::ADDiu, DstReg, SrcReg, ImmValue, IDLoc, STI);
2847 MCRegister TmpReg = DstReg;
2848 if (SrcReg == DstReg) {
2849 TmpReg = getATReg(IDLoc);
2854 TOut.
emitRRI(Mips::ORi, TmpReg, ZeroReg, ImmValue, IDLoc, STI);
2856 TOut.
emitRRR(
ABI.GetPtrAdduOp(), DstReg, TmpReg, SrcReg, IDLoc, STI);
2861 warnIfNoMacro(IDLoc);
2863 uint16_t Bits31To16 = (ImmValue >> 16) & 0xffff;
2864 uint16_t Bits15To0 = ImmValue & 0xffff;
2865 if (!Is32BitImm && !
isInt<32>(ImmValue)) {
2868 if (ImmValue == 0xffffffff) {
2869 TOut.
emitRI(Mips::LUi, TmpReg, 0xffff, IDLoc, STI);
2870 TOut.
emitRRI(Mips::DSRL32, TmpReg, TmpReg, 0, IDLoc, STI);
2872 TOut.
emitRRR(AdduOp, DstReg, TmpReg, SrcReg, IDLoc, STI);
2878 TOut.
emitRRI(Mips::ORi, TmpReg, ZeroReg, Bits31To16, IDLoc, STI);
2879 TOut.
emitRRI(Mips::DSLL, TmpReg, TmpReg, 16, IDLoc, STI);
2881 TOut.
emitRRI(Mips::ORi, TmpReg, TmpReg, Bits15To0, IDLoc, STI);
2883 TOut.
emitRRR(AdduOp, DstReg, TmpReg, SrcReg, IDLoc, STI);
2887 TOut.
emitRI(Mips::LUi, TmpReg, Bits31To16, IDLoc, STI);
2889 TOut.
emitRRI(Mips::ORi, TmpReg, TmpReg, Bits15To0, IDLoc, STI);
2891 TOut.
emitRRR(AdduOp, DstReg, TmpReg, SrcReg, IDLoc, STI);
2897 Error(IDLoc,
"instruction requires a 32-bit immediate");
2904 assert(
BitWidth >= 17 &&
"ImmValue must be at least 17-bit wide");
2908 unsigned ShiftAmount =
BitWidth - 16;
2909 uint16_t
Bits = (ImmValue >> ShiftAmount) & 0xffff;
2910 TOut.
emitRRI(Mips::ORi, TmpReg, ZeroReg, Bits, IDLoc, STI);
2911 TOut.
emitRRI(Mips::DSLL, TmpReg, TmpReg, ShiftAmount, IDLoc, STI);
2914 TOut.
emitRRR(AdduOp, DstReg, TmpReg, SrcReg, IDLoc, STI);
2919 warnIfNoMacro(IDLoc);
2926 if (loadImmediate(ImmValue >> 32, TmpReg, MCRegister(),
true,
false, IDLoc,
2932 unsigned ShiftCarriedForwards = 16;
2933 for (
int BitNum = 16; BitNum >= 0; BitNum -= 16) {
2934 uint16_t ImmChunk = (ImmValue >> BitNum) & 0xffff;
2936 if (ImmChunk != 0) {
2937 TOut.
emitDSLL(TmpReg, TmpReg, ShiftCarriedForwards, IDLoc, STI);
2938 TOut.
emitRRI(Mips::ORi, TmpReg, TmpReg, ImmChunk, IDLoc, STI);
2939 ShiftCarriedForwards = 0;
2942 ShiftCarriedForwards += 16;
2944 ShiftCarriedForwards -= 16;
2947 if (ShiftCarriedForwards)
2948 TOut.
emitDSLL(TmpReg, TmpReg, ShiftCarriedForwards, IDLoc, STI);
2951 TOut.
emitRRR(AdduOp, DstReg, TmpReg, SrcReg, IDLoc, STI);
2956bool MipsAsmParser::expandLoadImm(MCInst &Inst,
bool Is32BitImm, SMLoc IDLoc,
2957 MCStreamer &Out,
const MCSubtargetInfo *STI) {
2959 assert(ImmOp.
isImm() &&
"expected immediate operand kind");
2960 const MCOperand &DstRegOp = Inst.
getOperand(0);
2961 assert(DstRegOp.
isReg() &&
"expected register operand kind");
2963 if (loadImmediate(ImmOp.
getImm(), DstRegOp.
getReg(), MCRegister(), Is32BitImm,
2964 false, IDLoc, Out, STI))
2970bool MipsAsmParser::expandLoadAddress(MCRegister DstReg, MCRegister BaseReg,
2972 bool Is32BitAddress, SMLoc IDLoc,
2974 const MCSubtargetInfo *STI) {
2976 if (Is32BitAddress &&
ABI.ArePtrs64bit()) {
2977 Warning(IDLoc,
"la used to load 64-bit address");
2979 Is32BitAddress =
false;
2983 if (!Is32BitAddress && !hasMips3()) {
2984 Error(IDLoc,
"instruction requires a 64-bit architecture");
2989 return loadAndAddSymbolAddress(
Offset.getExpr(), DstReg, BaseReg,
2990 Is32BitAddress, IDLoc, Out, STI);
2992 if (!
ABI.ArePtrs64bit()) {
2994 Is32BitAddress =
true;
2997 return loadImmediate(
Offset.getImm(), DstReg, BaseReg, Is32BitAddress,
true,
3006bool MipsAsmParser::canDeferGOTLoad(
const MCSymbol *Sym) {
3008 static_cast<const MCSymbolELF *
>(Sym)->isBindingSet())
3013 MCAssembler *
Asm = getStreamer().getAssemblerPtr();
3014 return Asm && !
Asm->getRelaxAll() && !
Asm->isBundlingEnabled();
3017bool MipsAsmParser::loadAndAddSymbolAddress(
const MCExpr *SymExpr,
3019 MCRegister SrcReg,
bool Is32BitSym,
3020 SMLoc IDLoc, MCStreamer &Out,
3021 const MCSubtargetInfo *STI) {
3022 MipsTargetStreamer &TOut = getTargetStreamer();
3024 SrcReg.
isValid() && SrcReg != Mips::R0 && SrcReg != Mips::R0_64;
3025 warnIfNoMacro(IDLoc);
3030 Error(IDLoc,
"expected relocatable expression");
3034 Error(IDLoc,
"expected relocatable expression with only one symbol");
3038 bool IsPtr64 =
ABI.ArePtrs64bit();
3041 ?
static_cast<const MCSymbolELF *
>(Res.
getAddSym())
3049 bool UseXGOT = STI->
hasFeature(Mips::FeatureXGOT) && !IsLocalSym;
3057 !IsLocalSym && !UseXGOT && canDeferGOTLoad(Res.
getAddSym());
3058 auto EmitDeferredGOTLoad = [&](MCRegister
Reg,
unsigned Flags) {
3060 Inst.
setOpcode(Mips::PseudoGOTLoadGlobal);
3066 Out.emitInstruction(Inst, *STI);
3073 if ((DstReg ==
getABI().getTempReg(9,
false) ||
3074 DstReg ==
getABI().getTempReg(9,
true)) &&
3075 !UseSrcReg && Res.
getConstant() == 0 && !IsLocalSym) {
3077 const MCExpr *CallHiExpr =
3079 const MCExpr *CallLoExpr =
3083 TOut.
emitRRR(IsPtr64 ? Mips::DADDu : Mips::ADDu, DstReg, DstReg, GPReg,
3085 TOut.
emitRRX(IsPtr64 ? Mips::LD : Mips::LW, DstReg, DstReg,
3087 }
else if (DeferLocal) {
3089 if (
ABI.IsN32() ||
ABI.IsN64())
3093 EmitDeferredGOTLoad(DstReg, Flags);
3095 const MCExpr *CallExpr =
3097 TOut.
emitRRX(IsPtr64 ? Mips::LD : Mips::LW, DstReg, GPReg,
3103 MCRegister TmpReg = DstReg;
3105 getContext().getRegisterInfo()->isSuperOrSubRegisterEq(DstReg,
3109 MCRegister ATReg = getATReg(IDLoc);
3117 if (DeferLocal &&
ABI.IsO32()) {
3118 EmitDeferredGOTLoad(TmpReg, 0);
3120 TOut.
emitRRR(Mips::ADDu, DstReg, TmpReg, SrcReg, IDLoc, STI);
3137 const MCExpr *CallHiExpr =
3144 TOut.
emitRRR(IsPtr64 ? Mips::DADDu : Mips::ADDu, TmpReg, TmpReg, GPReg,
3146 TOut.
emitRRX(IsPtr64 ? Mips::LD : Mips::LW, TmpReg, TmpReg,
3150 TOut.
emitRRX(IsPtr64 ? Mips::DADDiu : Mips::ADDiu, TmpReg, TmpReg,
3156 TOut.
emitRRR(IsPtr64 ? Mips::DADDu : Mips::ADDu, DstReg, TmpReg, SrcReg,
3161 const MCSpecifierExpr *GotExpr =
nullptr;
3162 const MCExpr *LoExpr =
nullptr;
3163 if (
ABI.IsN32() ||
ABI.IsN64()) {
3182 Error(IDLoc,
"macro instruction uses large offset, which is not "
3183 "currently supported");
3212 TOut.
emitRRX(IsPtr64 ? Mips::LD : Mips::LW, TmpReg, GPReg,
3216 TOut.
emitRRX(IsPtr64 ? Mips::DADDiu : Mips::ADDiu, TmpReg, TmpReg,
3220 TOut.
emitRRR(IsPtr64 ? Mips::DADDu : Mips::ADDu, DstReg, TmpReg, SrcReg,
3226 const auto *HiExpr =
3228 const auto *LoExpr =
3232 if (
ABI.ArePtrs64bit() && isGP64bit()) {
3240 const auto *HighestExpr =
3242 const auto *HigherExpr =
3247 getContext().getRegisterInfo()->isSuperOrSubRegisterEq(DstReg, SrcReg);
3249 if (canUseATReg() && UseSrcReg && RdRegIsRsReg) {
3250 MCRegister ATReg = getATReg(IDLoc);
3262 TOut.
emitRRX(Mips::DADDiu, ATReg, ATReg,
3264 TOut.
emitRRI(Mips::DSLL, ATReg, ATReg, 16, IDLoc, STI);
3267 TOut.
emitRRI(Mips::DSLL, ATReg, ATReg, 16, IDLoc, STI);
3270 TOut.
emitRRR(Mips::DADDu, DstReg, ATReg, SrcReg, IDLoc, STI);
3273 }
else if (canUseATReg() && !RdRegIsRsReg && DstReg != getATReg(IDLoc)) {
3274 MCRegister ATReg = getATReg(IDLoc);
3290 TOut.
emitRRX(Mips::DADDiu, DstReg, DstReg,
3294 TOut.
emitRRI(Mips::DSLL32, DstReg, DstReg, 0, IDLoc, STI);
3295 TOut.
emitRRR(Mips::DADDu, DstReg, DstReg, ATReg, IDLoc, STI);
3297 TOut.
emitRRR(Mips::DADDu, DstReg, DstReg, SrcReg, IDLoc, STI);
3300 }
else if ((!canUseATReg() && !RdRegIsRsReg) ||
3301 (canUseATReg() && DstReg == getATReg(IDLoc))) {
3312 TOut.
emitRRX(Mips::DADDiu, DstReg, DstReg,
3314 TOut.
emitRRI(Mips::DSLL, DstReg, DstReg, 16, IDLoc, STI);
3315 TOut.
emitRRX(Mips::DADDiu, DstReg, DstReg,
3317 TOut.
emitRRI(Mips::DSLL, DstReg, DstReg, 16, IDLoc, STI);
3318 TOut.
emitRRX(Mips::DADDiu, DstReg, DstReg,
3321 TOut.
emitRRR(Mips::DADDu, DstReg, DstReg, SrcReg, IDLoc, STI);
3327 assert(SrcReg == DstReg && !canUseATReg() &&
3328 "Could have expanded dla but didn't?");
3329 reportParseError(IDLoc,
3330 "pseudo-instruction requires $at, which is not available");
3344 MCRegister TmpReg = DstReg;
3346 getContext().getRegisterInfo()->isSuperOrSubRegisterEq(DstReg, SrcReg)) {
3349 MCRegister ATReg = getATReg(IDLoc);
3360 TOut.
emitRRR(Mips::ADDu, DstReg, TmpReg, SrcReg, IDLoc, STI);
3363 getContext().getRegisterInfo()->isSuperOrSubRegisterEq(DstReg, TmpReg));
3372 if (getMipsMCRegisterClass(Mips::FGR32RegClassID).
contains(
Reg))
3373 return Reg == (
unsigned)Mips::F31 ? (
unsigned)Mips::F0 :
Reg + 1;
3375 default:
llvm_unreachable(
"Unknown register in assembly macro expansion!");
3440 case Mips::D0:
return Mips::F1;
3441 case Mips::D1:
return Mips::F3;
3442 case Mips::D2:
return Mips::F5;
3443 case Mips::D3:
return Mips::F7;
3444 case Mips::D4:
return Mips::F9;
3445 case Mips::D5:
return Mips::F11;
3446 case Mips::D6:
return Mips::F13;
3447 case Mips::D7:
return Mips::F15;
3448 case Mips::D8:
return Mips::F17;
3449 case Mips::D9:
return Mips::F19;
3471bool MipsAsmParser::emitPartialAddress(MipsTargetStreamer &TOut, SMLoc IDLoc,
3473 MCRegister ATReg = getATReg(IDLoc);
3479 const auto *GotExpr =
3482 if(isABI_O32() || isABI_N32()) {
3491 const auto *HiExpr =
3500 if(isABI_O32() || isABI_N32()) {
3504 const auto *HighestExpr =
3507 const auto *HigherExpr =
3512 TOut.
emitRRX(Mips::DADDiu, ATReg, ATReg,
3514 TOut.
emitRRI(Mips::DSLL, ATReg, ATReg, 16, IDLoc, STI);
3517 TOut.
emitRRI(Mips::DSLL, ATReg, ATReg, 16, IDLoc, STI);
3526 if ((
Hi_32(ImmOp64) & 0x7ff00000) == 0) {
3537 float TmpFloat =
static_cast<float>(DoubleImm);
3541bool MipsAsmParser::expandLoadSingleImmToGPR(MCInst &Inst, SMLoc IDLoc,
3543 const MCSubtargetInfo *STI) {
3546 "Invalid instruction operand.");
3553 return loadImmediate(ImmOp32, FirstReg, MCRegister(),
true,
false, IDLoc, Out,
3557bool MipsAsmParser::expandLoadSingleImmToFPR(MCInst &Inst, SMLoc IDLoc,
3559 const MCSubtargetInfo *STI) {
3560 MipsTargetStreamer &TOut = getTargetStreamer();
3563 "Invalid instruction operand.");
3572 MCRegister TmpReg = Mips::R0;
3574 TmpReg = getATReg(IDLoc);
3579 if (
Lo_32(ImmOp64) == 0) {
3580 if (TmpReg != Mips::R0 && loadImmediate(ImmOp32, TmpReg, MCRegister(),
true,
3581 false, IDLoc, Out, STI))
3583 TOut.
emitRR(Mips::MTC1, FirstReg, TmpReg, IDLoc, STI);
3587 MCSection *CS = getStreamer().getCurrentSectionOnly();
3590 MCSection *ReadOnlySection =
3597 getStreamer().switchSection(ReadOnlySection);
3598 getStreamer().emitLabel(Sym, IDLoc);
3599 getStreamer().emitInt32(ImmOp32);
3600 getStreamer().switchSection(CS);
3602 if (emitPartialAddress(TOut, IDLoc, Sym))
3609bool MipsAsmParser::expandLoadDoubleImmToGPR(MCInst &Inst, SMLoc IDLoc,
3611 const MCSubtargetInfo *STI) {
3612 MipsTargetStreamer &TOut = getTargetStreamer();
3615 "Invalid instruction operand.");
3622 if (
Lo_32(ImmOp64) == 0) {
3624 if (loadImmediate(ImmOp64, FirstReg, MCRegister(),
false,
false, IDLoc,
3628 if (loadImmediate(
Hi_32(ImmOp64), FirstReg, MCRegister(),
true,
false,
3632 if (loadImmediate(0,
nextReg(FirstReg), MCRegister(),
true,
false, IDLoc,
3639 MCSection *CS = getStreamer().getCurrentSectionOnly();
3640 MCSection *ReadOnlySection =
3647 getStreamer().switchSection(ReadOnlySection);
3648 getStreamer().emitLabel(Sym, IDLoc);
3649 getStreamer().emitValueToAlignment(
Align(8));
3650 getStreamer().emitIntValue(ImmOp64, 8);
3651 getStreamer().switchSection(CS);
3653 MCRegister TmpReg = getATReg(IDLoc);
3657 if (emitPartialAddress(TOut, IDLoc, Sym))
3660 TOut.
emitRRX(isABI_N64() ? Mips::DADDiu : Mips::ADDiu, TmpReg, TmpReg,
3664 TOut.
emitRRI(Mips::LD, FirstReg, TmpReg, 0, IDLoc, STI);
3666 TOut.
emitRRI(Mips::LW, FirstReg, TmpReg, 0, IDLoc, STI);
3667 TOut.
emitRRI(Mips::LW,
nextReg(FirstReg), TmpReg, 4, IDLoc, STI);
3672bool MipsAsmParser::expandLoadDoubleImmToFPR(MCInst &Inst,
bool Is64FPU,
3673 SMLoc IDLoc, MCStreamer &Out,
3674 const MCSubtargetInfo *STI) {
3675 MipsTargetStreamer &TOut = getTargetStreamer();
3678 "Invalid instruction operand.");
3685 MCRegister TmpReg = Mips::R0;
3687 TmpReg = getATReg(IDLoc);
3692 if ((
Lo_32(ImmOp64) == 0) &&
3693 !((
Hi_32(ImmOp64) & 0xffff0000) && (
Hi_32(ImmOp64) & 0x0000ffff))) {
3695 if (TmpReg != Mips::R0 && loadImmediate(ImmOp64, TmpReg, MCRegister(),
3696 false,
false, IDLoc, Out, STI))
3698 TOut.
emitRR(Mips::DMTC1, FirstReg, TmpReg, IDLoc, STI);
3702 if (TmpReg != Mips::R0 &&
3703 loadImmediate(
Hi_32(ImmOp64), TmpReg, MCRegister(),
true,
false, IDLoc,
3707 if (hasMips32r2()) {
3708 TOut.
emitRR(Mips::MTC1, FirstReg, Mips::R0, IDLoc, STI);
3709 TOut.
emitRRR(Mips::MTHC1_D32, FirstReg, FirstReg, TmpReg, IDLoc, STI);
3711 TOut.
emitRR(Mips::MTC1,
nextReg(FirstReg), TmpReg, IDLoc, STI);
3712 TOut.
emitRR(Mips::MTC1, FirstReg, Mips::R0, IDLoc, STI);
3717 MCSection *CS = getStreamer().getCurrentSectionOnly();
3720 MCSection *ReadOnlySection =
3727 getStreamer().switchSection(ReadOnlySection);
3728 getStreamer().emitLabel(Sym, IDLoc);
3729 getStreamer().emitValueToAlignment(
Align(8));
3730 getStreamer().emitIntValue(ImmOp64, 8);
3731 getStreamer().switchSection(CS);
3733 if (emitPartialAddress(TOut, IDLoc, Sym))
3737 if (!Is64FPU && !hasMips2()) {
3738 MCRegister FirstWordReg = FirstReg;
3739 MCRegister SecondWordReg =
nextReg(FirstReg);
3740 if (!IsLittleEndian)
3745 const auto *SecondWordExpr =
3747 TOut.
emitRRX(Mips::LWC1, FirstWordReg, TmpReg,
3749 TOut.
emitRRX(Mips::LWC1, SecondWordReg, TmpReg,
3754 TOut.
emitRRX(Is64FPU ? Mips::LDC164 : Mips::LDC1, FirstReg, TmpReg,
3760bool MipsAsmParser::expandUncondBranchMMPseudo(MCInst &Inst, SMLoc IDLoc,
3762 const MCSubtargetInfo *STI) {
3763 MipsTargetStreamer &TOut = getTargetStreamer();
3766 "unexpected number of operands");
3776 assert(
Offset.isImm() &&
"expected immediate operand kind");
3780 if (inMicroMipsMode())
3781 Inst.
setOpcode(hasMips32r6() ? Mips::BC16_MMR6 : Mips::B16_MM);
3784 return Error(IDLoc,
"branch target out of range");
3786 return Error(IDLoc,
"branch to misaligned address");
3794 Out.emitInstruction(Inst, *STI);
3798 const MCInstrDesc &MCID = MII.get(Inst.
getOpcode());
3805bool MipsAsmParser::expandBranchImm(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
3806 const MCSubtargetInfo *STI) {
3807 MipsTargetStreamer &TOut = getTargetStreamer();
3808 const MCOperand &DstRegOp = Inst.
getOperand(0);
3809 assert(DstRegOp.
isReg() &&
"expected register operand kind");
3812 assert(ImmOp.
isImm() &&
"expected immediate operand kind");
3814 const MCOperand &MemOffsetOp = Inst.
getOperand(2);
3816 "expected immediate or expression operand");
3818 bool IsLikely =
false;
3828 case Mips::BEQLImmMacro:
3832 case Mips::BNELImmMacro:
3841 int64_t ImmValue = ImmOp.
getImm();
3842 if (ImmValue == 0) {
3846 TOut.
emitRRI(Mips::SLL, Mips::R0, Mips::R0, 0, IDLoc, STI);
3848 TOut.
emitRRX(OpCode, DstRegOp.
getReg(), Mips::R0, MemOffsetOp, IDLoc,
3851 warnIfNoMacro(IDLoc);
3853 MCRegister ATReg = getATReg(IDLoc);
3857 if (loadImmediate(ImmValue, ATReg, MCRegister(), !isGP64bit(),
true, IDLoc,
3861 if (IsLikely && MemOffsetOp.
isExpr()) {
3864 TOut.
emitRRI(Mips::SLL, Mips::R0, Mips::R0, 0, IDLoc, STI);
3866 TOut.
emitRRX(OpCode, DstRegOp.
getReg(), ATReg, MemOffsetOp, IDLoc, STI);
3871void MipsAsmParser::expandMem16Inst(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
3872 const MCSubtargetInfo *STI,
bool IsLoad) {
3874 assert((NumOp == 3 || NumOp == 4) &&
"unexpected operands number");
3875 unsigned StartOp = NumOp == 3 ? 0 : 1;
3877 const MCOperand &DstRegOp = Inst.
getOperand(StartOp);
3878 assert(DstRegOp.
isReg() &&
"expected register operand kind");
3879 const MCOperand &BaseRegOp = Inst.
getOperand(StartOp + 1);
3880 assert(BaseRegOp.
isReg() &&
"expected register operand kind");
3883 MipsTargetStreamer &TOut = getTargetStreamer();
3885 MCRegister DstReg = DstRegOp.
getReg();
3887 MCRegister TmpReg = DstReg;
3889 const MCInstrDesc &
Desc = MII.get(OpCode);
3890 int16_t DstRegClass =
3891 MII.getOpRegClassID(
Desc.operands()[StartOp],
3893 unsigned DstRegClassID =
3894 getContext().getRegisterInfo()->getRegClass(DstRegClass).getID();
3895 bool IsGPR = (DstRegClassID == Mips::GPR32RegClassID) ||
3896 (DstRegClassID == Mips::GPR64RegClassID);
3898 if (!IsLoad || !IsGPR || (BaseReg == DstReg)) {
3901 TmpReg = getATReg(IDLoc);
3906 auto emitInstWithOffset = [&](
const MCOperand &
Off) {
3908 TOut.
emitRRX(OpCode, DstReg, TmpReg,
Off, IDLoc, STI);
3910 TOut.
emitRRRX(OpCode, DstReg, DstReg, TmpReg,
Off, IDLoc, STI);
3914 int64_t LoOffset =
OffsetOp.getImm() & 0xffff;
3915 int64_t HiOffset =
OffsetOp.getImm() & ~0xffff;
3919 if (LoOffset & 0x8000)
3920 HiOffset += 0x10000;
3922 bool IsLargeOffset = HiOffset != 0;
3924 if (IsLargeOffset) {
3926 if (loadImmediate(HiOffset, TmpReg, MCRegister(), Is32BitImm,
true, IDLoc,
3931 if (BaseReg != Mips::R0 && BaseReg != Mips::R0_64)
3932 TOut.
emitRRR(
ABI.ArePtrs64bit() ? Mips::DADDu : Mips::ADDu, TmpReg,
3933 TmpReg, BaseReg, IDLoc, STI);
3947 if (!
OffsetOp.getExpr()->evaluateAsRelocatable(Res,
nullptr)) {
3948 Error(IDLoc,
"expected relocatable expression");
3952 Error(IDLoc,
"expected relocatable expression with only one symbol");
3956 loadAndAddSymbolAddress(
3958 BaseReg, !
ABI.ArePtrs64bit(), IDLoc, Out, STI);
3966 const MCExpr *OffExpr =
OffsetOp.getExpr();
3978 TOut.
emitRX(Mips::LUi, TmpReg, HighestOperand, IDLoc, STI);
3979 TOut.
emitRRX(Mips::DADDiu, TmpReg, TmpReg, HigherOperand, IDLoc, STI);
3980 TOut.
emitRRI(Mips::DSLL, TmpReg, TmpReg, 16, IDLoc, STI);
3981 TOut.
emitRRX(Mips::DADDiu, TmpReg, TmpReg, HiOperand, IDLoc, STI);
3982 TOut.
emitRRI(Mips::DSLL, TmpReg, TmpReg, 16, IDLoc, STI);
3983 if (BaseReg != Mips::R0 && BaseReg != Mips::R0_64)
3984 TOut.
emitRRR(Mips::DADDu, TmpReg, TmpReg, BaseReg, IDLoc, STI);
3985 emitInstWithOffset(LoOperand);
3988 TOut.
emitRX(Mips::LUi, TmpReg, HiOperand, IDLoc, STI);
3989 if (BaseReg != Mips::R0)
3990 TOut.
emitRRR(Mips::ADDu, TmpReg, TmpReg, BaseReg, IDLoc, STI);
3992 emitInstWithOffset(LoOperand);
4001void MipsAsmParser::expandMem9Inst(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
4002 const MCSubtargetInfo *STI,
bool IsLoad) {
4004 assert((NumOp == 3 || NumOp == 4) &&
"unexpected operands number");
4005 unsigned StartOp = NumOp == 3 ? 0 : 1;
4007 const MCOperand &DstRegOp = Inst.
getOperand(StartOp);
4008 assert(DstRegOp.
isReg() &&
"expected register operand kind");
4009 const MCOperand &BaseRegOp = Inst.
getOperand(StartOp + 1);
4010 assert(BaseRegOp.
isReg() &&
"expected register operand kind");
4013 MipsTargetStreamer &TOut = getTargetStreamer();
4015 MCRegister DstReg = DstRegOp.
getReg();
4017 MCRegister TmpReg = DstReg;
4019 const MCInstrDesc &
Desc = MII.get(OpCode);
4020 int16_t DstRegClass =
4021 MII.getOpRegClassID(
Desc.operands()[StartOp],
4024 unsigned DstRegClassID =
4025 getContext().getRegisterInfo()->getRegClass(DstRegClass).getID();
4026 bool IsGPR = (DstRegClassID == Mips::GPR32RegClassID) ||
4027 (DstRegClassID == Mips::GPR64RegClassID);
4029 if (!IsLoad || !IsGPR || (BaseReg == DstReg)) {
4032 TmpReg = getATReg(IDLoc);
4037 auto emitInst = [&]() {
4046 loadImmediate(
OffsetOp.getImm(), TmpReg, BaseReg, !
ABI.ArePtrs64bit(),
true,
4053 loadAndAddSymbolAddress(
OffsetOp.getExpr(), TmpReg, BaseReg,
4054 !
ABI.ArePtrs64bit(), IDLoc, Out, STI);
4062bool MipsAsmParser::expandLoadStoreMultiple(MCInst &Inst, SMLoc IDLoc,
4064 const MCSubtargetInfo *STI) {
4067 unsigned NewOpcode = Opcode == Mips::SWM_MM ? Mips::SWM32_MM : Mips::LWM32_MM;
4071 Inst.
getOperand(OpNum - 3).
isReg() &&
"Invalid instruction operand.");
4080 if (inMicroMipsMode() && hasMips32r6())
4081 NewOpcode = Opcode == Mips::SWM_MM ? Mips::SWM16_MMR6 : Mips::LWM16_MMR6;
4083 NewOpcode = Opcode == Mips::SWM_MM ? Mips::SWM16_MM : Mips::LWM16_MM;
4087 Out.emitInstruction(Inst, *STI);
4091bool MipsAsmParser::expandCondBranches(MCInst &Inst, SMLoc IDLoc,
4093 const MCSubtargetInfo *STI) {
4094 MipsTargetStreamer &TOut = getTargetStreamer();
4095 bool EmittedNoMacroWarning =
false;
4096 unsigned PseudoOpcode = Inst.
getOpcode();
4101 unsigned ZeroSrcOpcode, ZeroTrgOpcode;
4102 bool ReverseOrderSLT, IsUnsigned, IsLikely, AcceptsEquality;
4107 else if (TrgOp.
isImm()) {
4108 warnIfNoMacro(IDLoc);
4109 EmittedNoMacroWarning =
true;
4111 TrgReg = getATReg(IDLoc);
4115 switch(PseudoOpcode) {
4118 case Mips::BLTImmMacro:
4119 PseudoOpcode = Mips::BLT;
4121 case Mips::BLEImmMacro:
4122 PseudoOpcode = Mips::BLE;
4124 case Mips::BGEImmMacro:
4125 PseudoOpcode = Mips::BGE;
4127 case Mips::BGTImmMacro:
4128 PseudoOpcode = Mips::BGT;
4130 case Mips::BLTUImmMacro:
4131 PseudoOpcode = Mips::BLTU;
4133 case Mips::BLEUImmMacro:
4134 PseudoOpcode = Mips::BLEU;
4136 case Mips::BGEUImmMacro:
4137 PseudoOpcode = Mips::BGEU;
4139 case Mips::BGTUImmMacro:
4140 PseudoOpcode = Mips::BGTU;
4142 case Mips::BLTLImmMacro:
4143 PseudoOpcode = Mips::BLTL;
4145 case Mips::BLELImmMacro:
4146 PseudoOpcode = Mips::BLEL;
4148 case Mips::BGELImmMacro:
4149 PseudoOpcode = Mips::BGEL;
4151 case Mips::BGTLImmMacro:
4152 PseudoOpcode = Mips::BGTL;
4154 case Mips::BLTULImmMacro:
4155 PseudoOpcode = Mips::BLTUL;
4157 case Mips::BLEULImmMacro:
4158 PseudoOpcode = Mips::BLEUL;
4160 case Mips::BGEULImmMacro:
4161 PseudoOpcode = Mips::BGEUL;
4163 case Mips::BGTULImmMacro:
4164 PseudoOpcode = Mips::BGTUL;
4168 if (loadImmediate(TrgOp.
getImm(), TrgReg, MCRegister(), !isGP64bit(),
false,
4173 switch (PseudoOpcode) {
4178 AcceptsEquality =
false;
4179 ReverseOrderSLT =
false;
4181 ((PseudoOpcode == Mips::BLTU) || (PseudoOpcode == Mips::BLTUL));
4182 IsLikely = ((PseudoOpcode == Mips::BLTL) || (PseudoOpcode == Mips::BLTUL));
4183 ZeroSrcOpcode = Mips::BGTZ;
4184 ZeroTrgOpcode = Mips::BLTZ;
4190 AcceptsEquality =
true;
4191 ReverseOrderSLT =
true;
4193 ((PseudoOpcode == Mips::BLEU) || (PseudoOpcode == Mips::BLEUL));
4194 IsLikely = ((PseudoOpcode == Mips::BLEL) || (PseudoOpcode == Mips::BLEUL));
4195 ZeroSrcOpcode = Mips::BGEZ;
4196 ZeroTrgOpcode = Mips::BLEZ;
4202 AcceptsEquality =
true;
4203 ReverseOrderSLT =
false;
4205 ((PseudoOpcode == Mips::BGEU) || (PseudoOpcode == Mips::BGEUL));
4206 IsLikely = ((PseudoOpcode == Mips::BGEL) || (PseudoOpcode == Mips::BGEUL));
4207 ZeroSrcOpcode = Mips::BLEZ;
4208 ZeroTrgOpcode = Mips::BGEZ;
4214 AcceptsEquality =
false;
4215 ReverseOrderSLT =
true;
4217 ((PseudoOpcode == Mips::BGTU) || (PseudoOpcode == Mips::BGTUL));
4218 IsLikely = ((PseudoOpcode == Mips::BGTL) || (PseudoOpcode == Mips::BGTUL));
4219 ZeroSrcOpcode = Mips::BLTZ;
4220 ZeroTrgOpcode = Mips::BGTZ;
4226 bool IsTrgRegZero = (TrgReg == Mips::R0);
4227 bool IsSrcRegZero = (SrcReg == Mips::R0);
4228 if (IsSrcRegZero && IsTrgRegZero) {
4232 if (PseudoOpcode == Mips::BLT) {
4237 if (PseudoOpcode == Mips::BLE) {
4240 Warning(IDLoc,
"branch is always taken");
4243 if (PseudoOpcode == Mips::BGE) {
4246 Warning(IDLoc,
"branch is always taken");
4249 if (PseudoOpcode == Mips::BGT) {
4254 if (PseudoOpcode == Mips::BGTU) {
4255 TOut.
emitRRX(Mips::BNE, Mips::R0, Mips::R0,
4259 if (AcceptsEquality) {
4262 TOut.
emitRRX(Mips::BEQ, Mips::R0, Mips::R0,
4264 Warning(IDLoc,
"branch is always taken");
4271 if (IsSrcRegZero || IsTrgRegZero) {
4272 if ((IsSrcRegZero && PseudoOpcode == Mips::BGTU) ||
4273 (IsTrgRegZero && PseudoOpcode == Mips::BLTU)) {
4280 if ((IsSrcRegZero && PseudoOpcode == Mips::BLEU) ||
4281 (IsTrgRegZero && PseudoOpcode == Mips::BGEU)) {
4287 TOut.
emitRRX(Mips::BEQ, Mips::R0, Mips::R0,
4289 Warning(IDLoc,
"branch is always taken");
4305 TOut.
emitRRX(AcceptsEquality ? Mips::BEQ : Mips::BNE,
4306 IsSrcRegZero ? TrgReg : SrcReg, Mips::R0,
4313 TOut.
emitRX(IsSrcRegZero ? ZeroSrcOpcode : ZeroTrgOpcode,
4314 IsSrcRegZero ? TrgReg : SrcReg,
4321 MCRegister ATRegNum = getATReg(IDLoc);
4325 if (!EmittedNoMacroWarning)
4326 warnIfNoMacro(IDLoc);
4343 TOut.
emitRRR(IsUnsigned ? Mips::SLTu : Mips::SLT, ATRegNum,
4344 ReverseOrderSLT ? TrgReg : SrcReg,
4345 ReverseOrderSLT ? SrcReg : TrgReg, IDLoc, STI);
4347 TOut.
emitRRX(IsLikely ? (AcceptsEquality ? Mips::BEQL : Mips::BNEL)
4348 : (AcceptsEquality ? Mips::BEQ : Mips::BNE),
4362bool MipsAsmParser::expandDivRem(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
4363 const MCSubtargetInfo *STI,
4364 const bool IsMips64,
const bool Signed) {
4365 MipsTargetStreamer &TOut = getTargetStreamer();
4367 warnIfNoMacro(IDLoc);
4369 const MCOperand &RdRegOp = Inst.
getOperand(0);
4370 assert(RdRegOp.
isReg() &&
"expected register operand kind");
4371 MCRegister RdReg = RdRegOp.
getReg();
4373 const MCOperand &RsRegOp = Inst.
getOperand(1);
4374 assert(RsRegOp.
isReg() &&
"expected register operand kind");
4375 MCRegister RsReg = RsRegOp.
getReg();
4382 "expected register or immediate operand kind");
4386 ImmValue = RtOp.
getImm();
4393 DivOp =
Signed ? Mips::DSDIV : Mips::DUDIV;
4394 ZeroReg = Mips::R0_64;
4397 DivOp =
Signed ? Mips::SDIV : Mips::UDIV;
4402 bool UseTraps = useTraps();
4405 bool isDiv = Opcode == Mips::SDivMacro || Opcode == Mips::SDivIMacro ||
4406 Opcode == Mips::UDivMacro || Opcode == Mips::UDivIMacro ||
4407 Opcode == Mips::DSDivMacro || Opcode == Mips::DSDivIMacro ||
4408 Opcode == Mips::DUDivMacro || Opcode == Mips::DUDivIMacro;
4410 bool isRem = Opcode == Mips::SRemMacro || Opcode == Mips::SRemIMacro ||
4411 Opcode == Mips::URemMacro || Opcode == Mips::URemIMacro ||
4412 Opcode == Mips::DSRemMacro || Opcode == Mips::DSRemIMacro ||
4413 Opcode == Mips::DURemMacro || Opcode == Mips::DURemIMacro;
4416 MCRegister ATReg = getATReg(IDLoc);
4420 if (!CLOpts.mno_check_zero_division && ImmValue == 0) {
4422 TOut.
emitRRI(Mips::TEQ, ZeroReg, ZeroReg, 0x7, IDLoc, STI);
4424 TOut.
emitII(Mips::BREAK, 0x7, 0, IDLoc, STI);
4428 if (isRem && (ImmValue == 1 || (
Signed && (ImmValue == -1)))) {
4429 TOut.
emitRRR(Mips::OR, RdReg, ZeroReg, ZeroReg, IDLoc, STI);
4431 }
else if (isDiv && ImmValue == 1) {
4432 TOut.
emitRRR(Mips::OR, RdReg, RsReg, Mips::R0, IDLoc, STI);
4434 }
else if (isDiv &&
Signed && ImmValue == -1) {
4435 TOut.
emitRRR(SubOp, RdReg, ZeroReg, RsReg, IDLoc, STI);
4438 if (loadImmediate(ImmValue, ATReg, MCRegister(),
isInt<32>(ImmValue),
4439 false, Inst.
getLoc(), Out, STI))
4441 TOut.
emitRR(DivOp, RsReg, ATReg, IDLoc, STI);
4442 TOut.
emitR(isDiv ? Mips::MFLO : Mips::MFHI, RdReg, IDLoc, STI);
4452 if (!CLOpts.mno_check_zero_division &&
4453 (RtReg == Mips::R0 || RtReg == Mips::R0_64)) {
4455 TOut.
emitRRI(Mips::TEQ, ZeroReg, ZeroReg, 0x7, IDLoc, STI);
4458 TOut.
emitII(Mips::BREAK, 0x7, 0, IDLoc, STI);
4464 if (isRem && (RdReg == Mips::R0 || RdReg == Mips::R0_64)) {
4465 TOut.
emitRR(DivOp, RsReg, RtReg, IDLoc, STI);
4474 TOut.
emitRR(DivOp, RsReg, RtReg, IDLoc, STI);
4475 if (!CLOpts.mno_check_zero_division) {
4477 TOut.
emitRRI(Mips::TEQ, RtReg, ZeroReg, 0x7, IDLoc, STI);
4480 BrTarget =
Context.createTempSymbol();
4483 TOut.
emitRRX(Mips::BNE, RtReg, ZeroReg, LabelOp, IDLoc, STI);
4488 TOut.
emitII(Mips::BREAK, 0x7, 0, IDLoc, STI);
4494 TOut.
emitR(isDiv ? Mips::MFLO : Mips::MFHI, RdReg, IDLoc, STI);
4498bool MipsAsmParser::expandTrunc(MCInst &Inst,
bool IsDouble,
bool Is64FPU,
4499 SMLoc IDLoc, MCStreamer &Out,
4500 const MCSubtargetInfo *STI) {
4501 MipsTargetStreamer &TOut = getTargetStreamer();
4511 if (hasMips1() && !hasMips2()) {
4512 MCRegister ATReg = getATReg(IDLoc);
4515 TOut.
emitRR(Mips::CFC1, ThirdReg, Mips::FCR31, IDLoc, STI);
4516 TOut.
emitRR(Mips::CFC1, ThirdReg, Mips::FCR31, IDLoc, STI);
4518 TOut.
emitRRI(Mips::ORi, ATReg, ThirdReg, 0x3, IDLoc, STI);
4519 TOut.
emitRRI(Mips::XORi, ATReg, ATReg, 0x2, IDLoc, STI);
4520 TOut.
emitRR(Mips::CTC1, Mips::FCR31, ATReg, IDLoc, STI);
4522 TOut.
emitRR(IsDouble ? (Is64FPU ? Mips::CVT_W_D64 : Mips::CVT_W_D32)
4524 FirstReg, SecondReg, IDLoc, STI);
4525 TOut.
emitRR(Mips::CTC1, Mips::FCR31, ThirdReg, IDLoc, STI);
4530 TOut.
emitRR(IsDouble ? (Is64FPU ? Mips::TRUNC_W_D64 : Mips::TRUNC_W_D32)
4532 FirstReg, SecondReg, IDLoc, STI);
4537bool MipsAsmParser::expandUlh(MCInst &Inst,
bool Signed, SMLoc IDLoc,
4538 MCStreamer &Out,
const MCSubtargetInfo *STI) {
4539 if (hasMips32r6() || hasMips64r6()) {
4540 return Error(IDLoc,
"instruction not supported on mips32r6 or mips64r6");
4543 const MCOperand &DstRegOp = Inst.
getOperand(0);
4544 assert(DstRegOp.
isReg() &&
"expected register operand kind");
4545 const MCOperand &SrcRegOp = Inst.
getOperand(1);
4546 assert(SrcRegOp.
isReg() &&
"expected register operand kind");
4547 const MCOperand &OffsetImmOp = Inst.
getOperand(2);
4548 assert(OffsetImmOp.
isImm() &&
"expected immediate operand kind");
4550 MipsTargetStreamer &TOut = getTargetStreamer();
4551 MCRegister DstReg = DstRegOp.
getReg();
4552 MCRegister SrcReg = SrcRegOp.
getReg();
4553 int64_t OffsetValue = OffsetImmOp.
getImm();
4557 warnIfNoMacro(IDLoc);
4558 MCRegister ATReg = getATReg(IDLoc);
4563 if (IsLargeOffset) {
4564 if (loadImmediate(OffsetValue, ATReg, SrcReg, !
ABI.ArePtrs64bit(),
true,
4569 int64_t FirstOffset = IsLargeOffset ? 0 : OffsetValue;
4570 int64_t SecondOffset = IsLargeOffset ? 1 : (OffsetValue + 1);
4574 MCRegister FirstLbuDstReg = IsLargeOffset ? DstReg : ATReg;
4575 MCRegister SecondLbuDstReg = IsLargeOffset ? ATReg : DstReg;
4577 MCRegister LbuSrcReg = IsLargeOffset ? ATReg : SrcReg;
4578 MCRegister SllReg = IsLargeOffset ? DstReg : ATReg;
4580 TOut.
emitRRI(
Signed ? Mips::LB : Mips::LBu, FirstLbuDstReg, LbuSrcReg,
4581 FirstOffset, IDLoc, STI);
4582 TOut.
emitRRI(Mips::LBu, SecondLbuDstReg, LbuSrcReg, SecondOffset, IDLoc, STI);
4583 TOut.
emitRRI(Mips::SLL, SllReg, SllReg, 8, IDLoc, STI);
4584 TOut.
emitRRR(Mips::OR, DstReg, DstReg, ATReg, IDLoc, STI);
4589bool MipsAsmParser::expandUsh(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
4590 const MCSubtargetInfo *STI) {
4591 if (hasMips32r6() || hasMips64r6()) {
4592 return Error(IDLoc,
"instruction not supported on mips32r6 or mips64r6");
4595 const MCOperand &DstRegOp = Inst.
getOperand(0);
4596 assert(DstRegOp.
isReg() &&
"expected register operand kind");
4597 const MCOperand &SrcRegOp = Inst.
getOperand(1);
4598 assert(SrcRegOp.
isReg() &&
"expected register operand kind");
4599 const MCOperand &OffsetImmOp = Inst.
getOperand(2);
4600 assert(OffsetImmOp.
isImm() &&
"expected immediate operand kind");
4602 MipsTargetStreamer &TOut = getTargetStreamer();
4603 MCRegister DstReg = DstRegOp.
getReg();
4604 MCRegister SrcReg = SrcRegOp.
getReg();
4605 int64_t OffsetValue = OffsetImmOp.
getImm();
4607 warnIfNoMacro(IDLoc);
4608 MCRegister ATReg = getATReg(IDLoc);
4613 if (IsLargeOffset) {
4614 if (loadImmediate(OffsetValue, ATReg, SrcReg, !
ABI.ArePtrs64bit(),
true,
4619 int64_t FirstOffset = IsLargeOffset ? 1 : (OffsetValue + 1);
4620 int64_t SecondOffset = IsLargeOffset ? 0 : OffsetValue;
4624 if (IsLargeOffset) {
4625 TOut.
emitRRI(Mips::SB, DstReg, ATReg, FirstOffset, IDLoc, STI);
4626 TOut.
emitRRI(Mips::SRL, DstReg, DstReg, 8, IDLoc, STI);
4627 TOut.
emitRRI(Mips::SB, DstReg, ATReg, SecondOffset, IDLoc, STI);
4628 TOut.
emitRRI(Mips::LBu, ATReg, ATReg, 0, IDLoc, STI);
4629 TOut.
emitRRI(Mips::SLL, DstReg, DstReg, 8, IDLoc, STI);
4630 TOut.
emitRRR(Mips::OR, DstReg, DstReg, ATReg, IDLoc, STI);
4632 TOut.
emitRRI(Mips::SB, DstReg, SrcReg, FirstOffset, IDLoc, STI);
4633 TOut.
emitRRI(Mips::SRL, ATReg, DstReg, 8, IDLoc, STI);
4634 TOut.
emitRRI(Mips::SB, ATReg, SrcReg, SecondOffset, IDLoc, STI);
4640bool MipsAsmParser::expandUxw(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
4641 const MCSubtargetInfo *STI) {
4642 if (hasMips32r6() || hasMips64r6()) {
4643 return Error(IDLoc,
"instruction not supported on mips32r6 or mips64r6");
4646 const MCOperand &DstRegOp = Inst.
getOperand(0);
4647 assert(DstRegOp.
isReg() &&
"expected register operand kind");
4648 const MCOperand &SrcRegOp = Inst.
getOperand(1);
4649 assert(SrcRegOp.
isReg() &&
"expected register operand kind");
4650 const MCOperand &OffsetImmOp = Inst.
getOperand(2);
4651 assert(OffsetImmOp.
isImm() &&
"expected immediate operand kind");
4653 MipsTargetStreamer &TOut = getTargetStreamer();
4654 MCRegister DstReg = DstRegOp.
getReg();
4655 MCRegister SrcReg = SrcRegOp.
getReg();
4656 int64_t OffsetValue = OffsetImmOp.
getImm();
4660 int64_t LxlOffset = IsLargeOffset ? 0 : OffsetValue;
4661 int64_t LxrOffset = IsLargeOffset ? 3 : (OffsetValue + 3);
4665 bool IsLoadInst = (Inst.
getOpcode() == Mips::Ulw);
4666 bool DoMove = IsLoadInst && (SrcReg == DstReg) && !IsLargeOffset;
4667 MCRegister TmpReg = SrcReg;
4668 if (IsLargeOffset || DoMove) {
4669 warnIfNoMacro(IDLoc);
4670 TmpReg = getATReg(IDLoc);
4675 if (IsLargeOffset) {
4676 if (loadImmediate(OffsetValue, TmpReg, SrcReg, !
ABI.ArePtrs64bit(),
true,
4684 unsigned XWL = IsLoadInst ? Mips::LWL : Mips::SWL;
4685 unsigned XWR = IsLoadInst ? Mips::LWR : Mips::SWR;
4686 TOut.
emitRRI(XWL, DstReg, TmpReg, LxlOffset, IDLoc, STI);
4687 TOut.
emitRRI(XWR, DstReg, TmpReg, LxrOffset, IDLoc, STI);
4690 TOut.
emitRRR(Mips::OR, TmpReg, DstReg, Mips::R0, IDLoc, STI);
4695bool MipsAsmParser::expandSge(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
4696 const MCSubtargetInfo *STI) {
4697 MipsTargetStreamer &TOut = getTargetStreamer();
4709 warnIfNoMacro(IDLoc);
4723 TOut.
emitRRR(OpCode, DstReg, SrcReg, OpReg, IDLoc, STI);
4724 TOut.
emitRRI(Mips::XORi, DstReg, DstReg, 1, IDLoc, STI);
4729bool MipsAsmParser::expandSgeImm(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
4730 const MCSubtargetInfo *STI) {
4731 MipsTargetStreamer &TOut = getTargetStreamer();
4741 unsigned OpRegCode, OpImmCode;
4743 warnIfNoMacro(IDLoc);
4747 case Mips::SGEImm64:
4748 OpRegCode = Mips::SLT;
4749 OpImmCode = Mips::SLTi;
4752 case Mips::SGEUImm64:
4753 OpRegCode = Mips::SLTu;
4754 OpImmCode = Mips::SLTiu;
4763 TOut.
emitRRI(OpImmCode, DstReg, SrcReg, ImmValue, IDLoc, STI);
4764 TOut.
emitRRI(Mips::XORi, DstReg, DstReg, 1, IDLoc, STI);
4766 MCRegister ImmReg = DstReg;
4767 if (DstReg == SrcReg) {
4768 MCRegister ATReg = getATReg(Inst.
getLoc());
4774 if (loadImmediate(ImmValue, ImmReg, MCRegister(),
isInt<32>(ImmValue),
4775 false, IDLoc, Out, STI))
4778 TOut.
emitRRR(OpRegCode, DstReg, SrcReg, ImmReg, IDLoc, STI);
4779 TOut.
emitRRI(Mips::XORi, DstReg, DstReg, 1, IDLoc, STI);
4785bool MipsAsmParser::expandSgtImm(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
4786 const MCSubtargetInfo *STI) {
4787 MipsTargetStreamer &TOut = getTargetStreamer();
4796 MCRegister ImmReg = DstReg;
4800 warnIfNoMacro(IDLoc);
4804 case Mips::SGTImm64:
4808 case Mips::SGTUImm64:
4815 if (DstReg == SrcReg) {
4816 MCRegister ATReg = getATReg(Inst.
getLoc());
4822 if (loadImmediate(ImmValue, ImmReg, MCRegister(),
isInt<32>(ImmValue),
false,
4827 TOut.
emitRRR(OpCode, DstReg, ImmReg, SrcReg, IDLoc, STI);
4832bool MipsAsmParser::expandSle(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
4833 const MCSubtargetInfo *STI) {
4834 MipsTargetStreamer &TOut = getTargetStreamer();
4846 warnIfNoMacro(IDLoc);
4860 TOut.
emitRRR(OpCode, DstReg, OpReg, SrcReg, IDLoc, STI);
4861 TOut.
emitRRI(Mips::XORi, DstReg, DstReg, 1, IDLoc, STI);
4866bool MipsAsmParser::expandSleImm(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
4867 const MCSubtargetInfo *STI) {
4868 MipsTargetStreamer &TOut = getTargetStreamer();
4880 warnIfNoMacro(IDLoc);
4884 case Mips::SLEImm64:
4885 OpRegCode = Mips::SLT;
4888 case Mips::SLEUImm64:
4889 OpRegCode = Mips::SLTu;
4896 MCRegister ImmReg = DstReg;
4897 if (DstReg == SrcReg) {
4898 MCRegister ATReg = getATReg(Inst.
getLoc());
4904 if (loadImmediate(ImmValue, ImmReg, MCRegister(),
isInt<32>(ImmValue),
false,
4908 TOut.
emitRRR(OpRegCode, DstReg, ImmReg, SrcReg, IDLoc, STI);
4909 TOut.
emitRRI(Mips::XORi, DstReg, DstReg, 1, IDLoc, STI);
4914bool MipsAsmParser::expandAliasImmediate(MCInst &Inst, SMLoc IDLoc,
4916 const MCSubtargetInfo *STI) {
4917 MipsTargetStreamer &TOut = getTargetStreamer();
4925 MCRegister FinalDstReg;
4932 unsigned FinalOpcode = Inst.
getOpcode();
4934 if (DstReg == SrcReg) {
4935 ATReg = getATReg(Inst.
getLoc());
4938 FinalDstReg = DstReg;
4942 if (!loadImmediate(ImmValue, DstReg, MCRegister(), Is32Bit,
false,
4943 Inst.
getLoc(), Out, STI)) {
4944 switch (FinalOpcode) {
4948 FinalOpcode = Mips::ADD;
4951 FinalOpcode = Mips::ADDu;
4954 FinalOpcode = Mips::AND;
4957 FinalOpcode = Mips::NOR;
4960 FinalOpcode = Mips::OR;
4963 FinalOpcode = Mips::SLT;
4966 FinalOpcode = Mips::SLTu;
4969 FinalOpcode = Mips::XOR;
4972 FinalOpcode = Mips::ADD_MM;
4974 case Mips::ADDiu_MM:
4975 FinalOpcode = Mips::ADDu_MM;
4978 FinalOpcode = Mips::AND_MM;
4981 FinalOpcode = Mips::OR_MM;
4984 FinalOpcode = Mips::SLT_MM;
4986 case Mips::SLTiu_MM:
4987 FinalOpcode = Mips::SLTu_MM;
4990 FinalOpcode = Mips::XOR_MM;
4993 FinalOpcode = Mips::AND64;
4995 case Mips::NORImm64:
4996 FinalOpcode = Mips::NOR64;
4999 FinalOpcode = Mips::OR64;
5001 case Mips::SLTImm64:
5002 FinalOpcode = Mips::SLT64;
5004 case Mips::SLTUImm64:
5005 FinalOpcode = Mips::SLTu64;
5008 FinalOpcode = Mips::XOR64;
5013 TOut.
emitRRR(FinalOpcode, DstReg, DstReg, SrcReg, IDLoc, STI);
5015 TOut.
emitRRR(FinalOpcode, FinalDstReg, FinalDstReg, DstReg, IDLoc, STI);
5021bool MipsAsmParser::expandRotation(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
5022 const MCSubtargetInfo *STI) {
5023 MipsTargetStreamer &TOut = getTargetStreamer();
5028 MCRegister TmpReg =
DReg;
5030 unsigned FirstShift = Mips::NOP;
5031 unsigned SecondShift = Mips::NOP;
5033 if (hasMips32r2()) {
5035 TmpReg = getATReg(Inst.
getLoc());
5041 TOut.
emitRRR(Mips::SUBu, TmpReg, Mips::R0, TReg, Inst.
getLoc(), STI);
5042 TOut.
emitRRR(Mips::ROTRV, DReg, SReg, TmpReg, Inst.
getLoc(), STI);
5047 TOut.
emitRRR(Mips::ROTRV, DReg, SReg, TReg, Inst.
getLoc(), STI);
5059 FirstShift = Mips::SRLV;
5060 SecondShift = Mips::SLLV;
5063 FirstShift = Mips::SLLV;
5064 SecondShift = Mips::SRLV;
5068 ATReg = getATReg(Inst.
getLoc());
5072 TOut.
emitRRR(Mips::SUBu, ATReg, Mips::R0, TReg, Inst.
getLoc(), STI);
5073 TOut.
emitRRR(FirstShift, ATReg, SReg, ATReg, Inst.
getLoc(), STI);
5074 TOut.
emitRRR(SecondShift, DReg, SReg, TReg, Inst.
getLoc(), STI);
5075 TOut.
emitRRR(Mips::OR, DReg, DReg, ATReg, Inst.
getLoc(), STI);
5083bool MipsAsmParser::expandRotationImm(MCInst &Inst, SMLoc IDLoc,
5085 const MCSubtargetInfo *STI) {
5086 MipsTargetStreamer &TOut = getTargetStreamer();
5092 unsigned FirstShift = Mips::NOP;
5093 unsigned SecondShift = Mips::NOP;
5095 if (hasMips32r2()) {
5100 ShiftValue = MaxShift - ImmValue;
5101 TOut.
emitRRI(Mips::ROTR, DReg, SReg, ShiftValue, Inst.
getLoc(), STI);
5106 TOut.
emitRRI(Mips::ROTR, DReg, SReg, ImmValue, Inst.
getLoc(), STI);
5114 if (ImmValue == 0) {
5123 FirstShift = Mips::SLL;
5124 SecondShift = Mips::SRL;
5127 FirstShift = Mips::SRL;
5128 SecondShift = Mips::SLL;
5132 ATReg = getATReg(Inst.
getLoc());
5136 TOut.
emitRRI(FirstShift, ATReg, SReg, ImmValue, Inst.
getLoc(), STI);
5137 TOut.
emitRRI(SecondShift, DReg, SReg, 32 - ImmValue, Inst.
getLoc(), STI);
5138 TOut.
emitRRR(Mips::OR, DReg, DReg, ATReg, Inst.
getLoc(), STI);
5146bool MipsAsmParser::expandDRotation(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
5147 const MCSubtargetInfo *STI) {
5148 MipsTargetStreamer &TOut = getTargetStreamer();
5153 MCRegister TmpReg =
DReg;
5155 unsigned FirstShift = Mips::NOP;
5156 unsigned SecondShift = Mips::NOP;
5158 if (hasMips64r2()) {
5159 if (TmpReg == SReg) {
5160 TmpReg = getATReg(Inst.
getLoc());
5166 TOut.
emitRRR(Mips::DSUBu, TmpReg, Mips::R0, TReg, Inst.
getLoc(), STI);
5167 TOut.
emitRRR(Mips::DROTRV, DReg, SReg, TmpReg, Inst.
getLoc(), STI);
5172 TOut.
emitRRR(Mips::DROTRV, DReg, SReg, TReg, Inst.
getLoc(), STI);
5184 FirstShift = Mips::DSRLV;
5185 SecondShift = Mips::DSLLV;
5188 FirstShift = Mips::DSLLV;
5189 SecondShift = Mips::DSRLV;
5193 ATReg = getATReg(Inst.
getLoc());
5197 TOut.
emitRRR(Mips::DSUBu, ATReg, Mips::R0, TReg, Inst.
getLoc(), STI);
5198 TOut.
emitRRR(FirstShift, ATReg, SReg, ATReg, Inst.
getLoc(), STI);
5199 TOut.
emitRRR(SecondShift, DReg, SReg, TReg, Inst.
getLoc(), STI);
5200 TOut.
emitRRR(Mips::OR, DReg, DReg, ATReg, Inst.
getLoc(), STI);
5208bool MipsAsmParser::expandDRotationImm(MCInst &Inst, SMLoc IDLoc,
5210 const MCSubtargetInfo *STI) {
5211 MipsTargetStreamer &TOut = getTargetStreamer();
5217 unsigned FirstShift = Mips::NOP;
5218 unsigned SecondShift = Mips::NOP;
5220 if (hasMips64r2()) {
5221 unsigned FinalOpcode = Mips::NOP;
5223 FinalOpcode = Mips::DROTR;
5224 else if (ImmValue % 32 == 0)
5225 FinalOpcode = Mips::DROTR32;
5226 else if ((ImmValue >= 1) && (ImmValue <= 32)) {
5228 FinalOpcode = Mips::DROTR32;
5230 FinalOpcode = Mips::DROTR;
5231 }
else if (ImmValue >= 33) {
5233 FinalOpcode = Mips::DROTR;
5235 FinalOpcode = Mips::DROTR32;
5238 uint64_t ShiftValue = ImmValue % 32;
5240 ShiftValue = (32 - ImmValue % 32) % 32;
5242 TOut.
emitRRI(FinalOpcode, DReg, SReg, ShiftValue, Inst.
getLoc(), STI);
5248 if (ImmValue == 0) {
5249 TOut.
emitRRI(Mips::DSRL, DReg, SReg, 0, Inst.
getLoc(), STI);
5257 if ((ImmValue >= 1) && (ImmValue <= 31)) {
5258 FirstShift = Mips::DSLL;
5259 SecondShift = Mips::DSRL32;
5261 if (ImmValue == 32) {
5262 FirstShift = Mips::DSLL32;
5263 SecondShift = Mips::DSRL32;
5265 if ((ImmValue >= 33) && (ImmValue <= 63)) {
5266 FirstShift = Mips::DSLL32;
5267 SecondShift = Mips::DSRL;
5271 if ((ImmValue >= 1) && (ImmValue <= 31)) {
5272 FirstShift = Mips::DSRL;
5273 SecondShift = Mips::DSLL32;
5275 if (ImmValue == 32) {
5276 FirstShift = Mips::DSRL32;
5277 SecondShift = Mips::DSLL32;
5279 if ((ImmValue >= 33) && (ImmValue <= 63)) {
5280 FirstShift = Mips::DSRL32;
5281 SecondShift = Mips::DSLL;
5286 ATReg = getATReg(Inst.
getLoc());
5290 TOut.
emitRRI(FirstShift, ATReg, SReg, ImmValue % 32, Inst.
getLoc(), STI);
5291 TOut.
emitRRI(SecondShift, DReg, SReg, (32 - ImmValue % 32) % 32,
5293 TOut.
emitRRR(Mips::OR, DReg, DReg, ATReg, Inst.
getLoc(), STI);
5301bool MipsAsmParser::expandAbs(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
5302 const MCSubtargetInfo *STI) {
5303 MipsTargetStreamer &TOut = getTargetStreamer();
5307 TOut.
emitRI(Mips::BGEZ, SecondRegOp, 8, IDLoc, STI);
5308 if (FirstRegOp != SecondRegOp)
5309 TOut.
emitRRR(Mips::ADDu, FirstRegOp, SecondRegOp, Mips::R0, IDLoc, STI);
5312 TOut.
emitRRR(Mips::SUB, FirstRegOp, Mips::R0, SecondRegOp, IDLoc, STI);
5317bool MipsAsmParser::expandMulImm(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
5318 const MCSubtargetInfo *STI) {
5319 MipsTargetStreamer &TOut = getTargetStreamer();
5325 ATReg = getATReg(IDLoc);
5329 loadImmediate(ImmValue, ATReg, MCRegister(),
true,
false, IDLoc, Out, STI);
5331 TOut.
emitRR(Inst.
getOpcode() == Mips::MULImmMacro ? Mips::MULT : Mips::DMULT,
5332 SrcReg, ATReg, IDLoc, STI);
5334 TOut.
emitR(Mips::MFLO, DstReg, IDLoc, STI);
5339bool MipsAsmParser::expandMulO(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
5340 const MCSubtargetInfo *STI) {
5341 MipsTargetStreamer &TOut = getTargetStreamer();
5347 ATReg = getATReg(Inst.
getLoc());
5351 TOut.
emitRR(Inst.
getOpcode() == Mips::MULOMacro ? Mips::MULT : Mips::DMULT,
5352 SrcReg, TmpReg, IDLoc, STI);
5354 TOut.
emitR(Mips::MFLO, DstReg, IDLoc, STI);
5356 TOut.
emitRRI(Inst.
getOpcode() == Mips::MULOMacro ? Mips::SRA : Mips::DSRA32,
5357 DstReg, DstReg, 0x1F, IDLoc, STI);
5359 TOut.
emitR(Mips::MFHI, ATReg, IDLoc, STI);
5362 TOut.
emitRRI(Mips::TNE, DstReg, ATReg, 6, IDLoc, STI);
5369 TOut.
emitRRX(Mips::BEQ, DstReg, ATReg, LabelOp, IDLoc, STI);
5370 if (AssemblerOptions.
back()->isReorder())
5372 TOut.
emitII(Mips::BREAK, 6, 0, IDLoc, STI);
5376 TOut.
emitR(Mips::MFLO, DstReg, IDLoc, STI);
5381bool MipsAsmParser::expandMulOU(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
5382 const MCSubtargetInfo *STI) {
5383 MipsTargetStreamer &TOut = getTargetStreamer();
5389 ATReg = getATReg(IDLoc);
5393 TOut.
emitRR(Inst.
getOpcode() == Mips::MULOUMacro ? Mips::MULTu : Mips::DMULTu,
5394 SrcReg, TmpReg, IDLoc, STI);
5396 TOut.
emitR(Mips::MFHI, ATReg, IDLoc, STI);
5397 TOut.
emitR(Mips::MFLO, DstReg, IDLoc, STI);
5399 TOut.
emitRRI(Mips::TNE, ATReg, Mips::R0, 6, IDLoc, STI);
5406 TOut.
emitRRX(Mips::BEQ, ATReg, Mips::R0, LabelOp, IDLoc, STI);
5407 if (AssemblerOptions.
back()->isReorder())
5409 TOut.
emitII(Mips::BREAK, 6, 0, IDLoc, STI);
5417bool MipsAsmParser::expandDMULMacro(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
5418 const MCSubtargetInfo *STI) {
5419 MipsTargetStreamer &TOut = getTargetStreamer();
5424 TOut.
emitRR(Mips::DMULTu, SrcReg, TmpReg, IDLoc, STI);
5425 TOut.
emitR(Mips::MFLO, DstReg, IDLoc, STI);
5435bool MipsAsmParser::expandLoadStoreDMacro(MCInst &Inst, SMLoc IDLoc,
5437 const MCSubtargetInfo *STI,
5442 warnIfNoMacro(IDLoc);
5444 MipsTargetStreamer &TOut = getTargetStreamer();
5445 unsigned Opcode = IsLoad ? Mips::LW : Mips::SW;
5447 MCRegister SecondReg =
nextReg(FirstReg);
5452 warnIfRegIndexIsAT(FirstReg, IDLoc);
5455 "Offset for load macro is not immediate!");
5458 signed NextOffset = FirstOffset.
getImm() + 4;
5466 if (FirstReg != BaseReg || !IsLoad) {
5467 TOut.
emitRRX(Opcode, FirstReg, BaseReg, FirstOffset, IDLoc, STI);
5468 TOut.
emitRRX(Opcode, SecondReg, BaseReg, SecondOffset, IDLoc, STI);
5470 TOut.
emitRRX(Opcode, SecondReg, BaseReg, SecondOffset, IDLoc, STI);
5471 TOut.
emitRRX(Opcode, FirstReg, BaseReg, FirstOffset, IDLoc, STI);
5483bool MipsAsmParser::expandLoadStoreDM1Macro(MCInst &Inst, SMLoc IDLoc,
5485 const MCSubtargetInfo *STI,
5490 warnIfNoMacro(IDLoc);
5492 MipsTargetStreamer &TOut = getTargetStreamer();
5493 unsigned Opcode = IsLoad ? Mips::LWC1 : Mips::SWC1;
5495 MCRegister SecondReg =
nextReg(FirstReg);
5500 warnIfRegIndexIsAT(FirstReg, IDLoc);
5503 "Offset for macro is not immediate!");
5506 signed NextOffset = FirstOffset.
getImm() + 4;
5512 if (!IsLittleEndian)
5515 TOut.
emitRRX(Opcode, FirstReg, BaseReg, FirstOffset, IDLoc, STI);
5516 TOut.
emitRRX(Opcode, SecondReg, BaseReg, SecondOffset, IDLoc, STI);
5521bool MipsAsmParser::expandSeq(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
5522 const MCSubtargetInfo *STI) {
5523 MipsTargetStreamer &TOut = getTargetStreamer();
5534 warnIfNoMacro(IDLoc);
5536 if (SrcReg != Mips::R0 && OpReg != Mips::R0) {
5537 TOut.
emitRRR(Mips::XOR, DstReg, SrcReg, OpReg, IDLoc, STI);
5538 TOut.
emitRRI(Mips::SLTiu, DstReg, DstReg, 1, IDLoc, STI);
5542 MCRegister
Reg = SrcReg == Mips::R0 ? OpReg : SrcReg;
5543 TOut.
emitRRI(Mips::SLTiu, DstReg,
Reg, 1, IDLoc, STI);
5547bool MipsAsmParser::expandSeqI(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
5548 const MCSubtargetInfo *STI) {
5549 MipsTargetStreamer &TOut = getTargetStreamer();
5560 warnIfNoMacro(IDLoc);
5563 TOut.
emitRRI(Mips::SLTiu, DstReg, SrcReg, 1, IDLoc, STI);
5567 if (SrcReg == Mips::R0) {
5568 Warning(IDLoc,
"comparison is always false");
5569 TOut.
emitRRR(isGP64bit() ? Mips::DADDu : Mips::ADDu,
5570 DstReg, SrcReg, SrcReg, IDLoc, STI);
5575 if (
Imm > -0x8000 &&
Imm < 0) {
5577 Opc = isGP64bit() ? Mips::DADDiu : Mips::ADDiu;
5583 MCRegister ATReg = getATReg(IDLoc);
5587 if (loadImmediate(
Imm, ATReg, MCRegister(),
true, isGP64bit(), IDLoc, Out,
5591 TOut.
emitRRR(Mips::XOR, DstReg, SrcReg, ATReg, IDLoc, STI);
5592 TOut.
emitRRI(Mips::SLTiu, DstReg, DstReg, 1, IDLoc, STI);
5597 TOut.
emitRRI(Mips::SLTiu, DstReg, DstReg, 1, IDLoc, STI);
5601bool MipsAsmParser::expandSne(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
5602 const MCSubtargetInfo *STI) {
5604 MipsTargetStreamer &TOut = getTargetStreamer();
5615 warnIfNoMacro(IDLoc);
5617 if (SrcReg != Mips::R0 && OpReg != Mips::R0) {
5618 TOut.
emitRRR(Mips::XOR, DstReg, SrcReg, OpReg, IDLoc, STI);
5619 TOut.
emitRRR(Mips::SLTu, DstReg, Mips::R0, DstReg, IDLoc, STI);
5623 MCRegister
Reg = SrcReg == Mips::R0 ? OpReg : SrcReg;
5624 TOut.
emitRRR(Mips::SLTu, DstReg, Mips::R0,
Reg, IDLoc, STI);
5628bool MipsAsmParser::expandSneI(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
5629 const MCSubtargetInfo *STI) {
5630 MipsTargetStreamer &TOut = getTargetStreamer();
5641 warnIfNoMacro(IDLoc);
5643 if (ImmValue == 0) {
5644 TOut.
emitRRR(Mips::SLTu, DstReg, Mips::R0, SrcReg, IDLoc, STI);
5648 if (SrcReg == Mips::R0) {
5649 Warning(IDLoc,
"comparison is always true");
5650 if (loadImmediate(1, DstReg, MCRegister(),
true,
false, IDLoc, Out, STI))
5656 if (ImmValue > -0x8000 && ImmValue < 0) {
5657 ImmValue = -ImmValue;
5658 Opc = isGP64bit() ? Mips::DADDiu : Mips::ADDiu;
5664 TOut.
emitRRI(
Opc, DstReg, SrcReg, ImmValue, IDLoc, STI);
5665 TOut.
emitRRR(Mips::SLTu, DstReg, Mips::R0, DstReg, IDLoc, STI);
5669 MCRegister ATReg = getATReg(IDLoc);
5673 if (loadImmediate(ImmValue, ATReg, MCRegister(),
isInt<32>(ImmValue),
false,
5677 TOut.
emitRRR(Mips::XOR, DstReg, SrcReg, ATReg, IDLoc, STI);
5678 TOut.
emitRRR(Mips::SLTu, DstReg, Mips::R0, DstReg, IDLoc, STI);
5812bool MipsAsmParser::expandMXTRAlias(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
5813 const MCSubtargetInfo *STI) {
5814 MipsTargetStreamer &TOut = getTargetStreamer();
5818 bool IsMFTR =
false;
5864 IsMFTR ? MCRegister(rd)
5866 : Inst.getOperand(0).
getReg());
5868 TOut.
emitRRIII(IsMFTR ? Mips::MFTR : Mips::MTTR, Op0, Op1, 1, sel, h, IDLoc,
5873bool MipsAsmParser::expandSaaAddr(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
5874 const MCSubtargetInfo *STI) {
5879 warnIfNoMacro(IDLoc);
5881 MipsTargetStreamer &TOut = getTargetStreamer();
5882 unsigned Opcode = Inst.
getOpcode() == Mips::SaaAddr ? Mips::SAA : Mips::SAAD;
5885 const MCOperand &BaseOp = Inst.
getOperand(2);
5887 if (BaseOp.
isImm()) {
5888 int64_t ImmValue = BaseOp.
getImm();
5889 if (ImmValue == 0) {
5890 TOut.
emitRR(Opcode, RtReg, BaseReg, IDLoc, STI);
5895 MCRegister ATReg = getATReg(IDLoc);
5899 if (expandLoadAddress(ATReg, BaseReg, BaseOp, !isGP64bit(), IDLoc, Out, STI))
5902 TOut.
emitRR(Opcode, RtReg, ATReg, IDLoc, STI);
5907MipsAsmParser::checkEarlyTargetMatchPredicate(MCInst &Inst,
5911 return Match_Success;
5914 if (
static_cast<MipsOperand &
>(*
Operands[1])
5915 .isValidForTie(
static_cast<MipsOperand &
>(*
Operands[2])))
5916 return Match_Success;
5917 return Match_RequiresSameSrcAndDst;
5921unsigned MipsAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
5928 return Match_RequiresNoZeroRegister;
5929 return Match_Success;
5935 case Mips::JALR_HB64:
5936 case Mips::JALRC_HB_MMR6:
5937 case Mips::JALRC_MMR6:
5939 return Match_RequiresDifferentSrcAndDst;
5940 return Match_Success;
5943 return Match_RequiresDifferentSrcAndDst;
5944 return Match_Success;
5947 return Match_NonZeroOperandForSync;
5948 return Match_Success;
5952 return Match_NonZeroOperandForMTCX;
5953 return Match_Success;
5966 case Mips::BLEZC:
case Mips::BLEZC_MMR6:
5967 case Mips::BGEZC:
case Mips::BGEZC_MMR6:
5968 case Mips::BGTZC:
case Mips::BGTZC_MMR6:
5969 case Mips::BLTZC:
case Mips::BLTZC_MMR6:
5970 case Mips::BEQZC:
case Mips::BEQZC_MMR6:
5971 case Mips::BNEZC:
case Mips::BNEZC_MMR6:
5980 return Match_RequiresNoZeroRegister;
5981 return Match_Success;
5982 case Mips::BGEC:
case Mips::BGEC_MMR6:
5983 case Mips::BLTC:
case Mips::BLTC_MMR6:
5984 case Mips::BGEUC:
case Mips::BGEUC_MMR6:
5985 case Mips::BLTUC:
case Mips::BLTUC_MMR6:
5986 case Mips::BEQC:
case Mips::BEQC_MMR6:
5987 case Mips::BNEC:
case Mips::BNEC_MMR6:
5996 return Match_RequiresNoZeroRegister;
5999 return Match_RequiresNoZeroRegister;
6001 return Match_RequiresDifferentOperands;
6002 return Match_Success;
6005 "Operands must be immediates for dins!");
6008 if ((0 > (Pos +
Size)) || ((Pos +
Size) > 32))
6009 return Match_RequiresPosSizeRange0_32;
6010 return Match_Success;
6015 "Operands must be immediates for dinsm/dinsu!");
6018 if ((32 >= (Pos +
Size)) || ((Pos +
Size) > 64))
6019 return Match_RequiresPosSizeRange33_64;
6020 return Match_Success;
6024 "Operands must be immediates for DEXTM!");
6027 if ((1 > (Pos +
Size)) || ((Pos +
Size) > 63))
6028 return Match_RequiresPosSizeUImm6;
6029 return Match_Success;
6034 "Operands must be immediates for dextm/dextu!");
6037 if ((32 > (Pos +
Size)) || ((Pos +
Size) > 64))
6038 return Match_RequiresPosSizeRange33_64;
6039 return Match_Success;
6041 case Mips::CRC32B:
case Mips::CRC32CB:
6042 case Mips::CRC32H:
case Mips::CRC32CH:
6043 case Mips::CRC32W:
case Mips::CRC32CW:
6044 case Mips::CRC32D:
case Mips::CRC32CD:
6046 return Match_RequiresSameSrcAndDst;
6047 return Match_Success;
6053 return Match_NoFCCRegisterForCurrentISA;
6055 return Match_Success;
6063 if (ErrorLoc ==
SMLoc())
6070bool MipsAsmParser::matchAndEmitInstruction(SMLoc IDLoc,
unsigned &Opcode,
6074 bool MatchingInlineAsm) {
6076 unsigned MatchResult =
6077 MatchInstructionImpl(
Operands, Inst, ErrorInfo, MatchingInlineAsm);
6079 switch (MatchResult) {
6081 if (processInstruction(Inst, IDLoc, Out, STI))
6084 case Match_MissingFeature:
6085 Error(IDLoc,
"instruction requires a CPU feature not currently enabled");
6087 case Match_InvalidTiedOperand:
6088 Error(IDLoc,
"operand must match destination register");
6090 case Match_InvalidOperand: {
6091 SMLoc ErrorLoc = IDLoc;
6092 if (ErrorInfo != ~0ULL) {
6094 return Error(IDLoc,
"too few operands for instruction");
6096 ErrorLoc =
Operands[ErrorInfo]->getStartLoc();
6098 ErrorLoc =
static_cast<MipsOperand &
>(*
Operands[ErrorInfo])
6101 if (ErrorLoc == SMLoc())
6105 return Error(ErrorLoc,
"invalid operand for instruction");
6107 case Match_NonZeroOperandForSync:
6109 "s-type must be zero or unspecified for pre-MIPS32 ISAs");
6110 case Match_NonZeroOperandForMTCX:
6111 return Error(IDLoc,
"selector must be zero for pre-MIPS32 ISAs");
6112 case Match_MnemonicFail:
6113 return Error(IDLoc,
"invalid instruction");
6114 case Match_RequiresDifferentSrcAndDst:
6115 return Error(IDLoc,
"source and destination must be different");
6116 case Match_RequiresDifferentOperands:
6117 return Error(IDLoc,
"registers must be different");
6118 case Match_RequiresNoZeroRegister:
6119 return Error(IDLoc,
"invalid operand ($zero) for instruction");
6120 case Match_RequiresSameSrcAndDst:
6121 return Error(IDLoc,
"source and destination must match");
6122 case Match_NoFCCRegisterForCurrentISA:
6124 "non-zero fcc register doesn't exist in current ISA level");
6129 "expected 1-bit unsigned immediate");
6132 "expected 2-bit unsigned immediate");
6135 "expected immediate in range 1 .. 4");
6138 "expected 3-bit unsigned immediate");
6141 "expected 4-bit unsigned immediate");
6144 "expected 4-bit signed immediate");
6147 "expected 5-bit unsigned immediate");
6150 "expected 5-bit signed immediate");
6153 "expected immediate in range 1 .. 32");
6154 case Match_UImm5_32:
6156 "expected immediate in range 32 .. 63");
6157 case Match_UImm5_33:
6159 "expected immediate in range 33 .. 64");
6160 case Match_UImm5_0_Report_UImm6:
6164 "expected 6-bit unsigned immediate");
6165 case Match_ConstantMemOffset:
6167 !
static_cast<MipsOperand &
>(*
Operands[ErrorInfo]).isConstantImm())
6169 "expected immediate operand kind");
6171 "immediate operand value out of range");
6172 case Match_UImm5_Lsl2:
6174 "expected both 7-bit unsigned immediate and multiple of 4");
6175 case Match_UImmRange2_64:
6177 "expected immediate in range 2 .. 64");
6180 "expected 6-bit unsigned immediate");
6181 case Match_UImm6_Lsl2:
6183 "expected both 8-bit unsigned immediate and multiple of 4");
6186 "expected 6-bit signed immediate");
6189 "expected 7-bit unsigned immediate");
6190 case Match_UImm7_N1:
6192 "expected immediate in range -1 .. 126");
6193 case Match_SImm7_Lsl2:
6195 "expected both 9-bit signed immediate and multiple of 4");
6198 "expected 8-bit unsigned immediate");
6199 case Match_UImm10_0:
6201 "expected 10-bit unsigned immediate");
6202 case Match_SImm10_0:
6204 "expected 10-bit signed immediate");
6205 case Match_SImm11_0:
6207 "expected 11-bit signed immediate");
6209 case Match_UImm16_Relaxed:
6210 case Match_UImm16_AltRelaxed:
6212 "expected 16-bit unsigned immediate");
6214 case Match_SImm16_Relaxed:
6216 "expected 16-bit signed immediate");
6217 case Match_SImm18_Lsl3:
6219 "expected both 18-bit signed immediate and multiple of 8");
6220 case Match_SImm19_Lsl2:
6222 "expected both 19-bit signed immediate and multiple of 4");
6223 case Match_UImm20_0:
6225 "expected 20-bit unsigned immediate");
6226 case Match_UImm26_0:
6228 "expected 26-bit unsigned immediate");
6230 case Match_SImm32_Relaxed:
6232 "expected 32-bit signed immediate");
6233 case Match_UImm32_Coerced:
6235 "expected 32-bit immediate");
6236 case Match_MemSImm9:
6238 "expected memory with 9-bit signed offset");
6239 case Match_MemSImm10:
6241 "expected memory with 10-bit signed offset");
6242 case Match_MemSImm10Lsl1:
6244 "expected memory with 11-bit signed offset and multiple of 2");
6245 case Match_MemSImm10Lsl2:
6247 "expected memory with 12-bit signed offset and multiple of 4");
6248 case Match_MemSImm10Lsl3:
6250 "expected memory with 13-bit signed offset and multiple of 8");
6251 case Match_MemSImm11:
6253 "expected memory with 11-bit signed offset");
6254 case Match_MemSImm12:
6256 "expected memory with 12-bit signed offset");
6257 case Match_MemSImm16:
6259 "expected memory with 16-bit signed offset");
6260 case Match_MemSImmPtr:
6262 "expected memory with 32-bit signed offset");
6263 case Match_RequiresPosSizeRange0_32: {
6264 SMLoc ErrorStart =
Operands[3]->getStartLoc();
6265 SMLoc ErrorEnd =
Operands[4]->getEndLoc();
6266 return Error(ErrorStart,
"size plus position are not in the range 0 .. 32",
6267 SMRange(ErrorStart, ErrorEnd));
6269 case Match_RequiresPosSizeUImm6: {
6270 SMLoc ErrorStart =
Operands[3]->getStartLoc();
6271 SMLoc ErrorEnd =
Operands[4]->getEndLoc();
6272 return Error(ErrorStart,
"size plus position are not in the range 1 .. 63",
6273 SMRange(ErrorStart, ErrorEnd));
6275 case Match_RequiresPosSizeRange33_64: {
6276 SMLoc ErrorStart =
Operands[3]->getStartLoc();
6277 SMLoc ErrorEnd =
Operands[4]->getEndLoc();
6278 return Error(ErrorStart,
"size plus position are not in the range 33 .. 64",
6279 SMRange(ErrorStart, ErrorEnd));
6286void MipsAsmParser::warnIfRegIndexIsAT(MCRegister RegIndex, SMLoc Loc) {
6287 if (RegIndex && AssemblerOptions.
back()->getATRegIndex() == RegIndex)
6288 Warning(Loc,
"used $at (currently $" + Twine(RegIndex.
id()) +
6289 ") without \".set noat\"");
6292void MipsAsmParser::warnIfNoMacro(SMLoc Loc) {
6293 if (!AssemblerOptions.
back()->isMacro())
6294 Warning(Loc,
"macro instruction expanded into multiple instructions");
6297void MipsAsmParser::ConvertXWPOperands(MCInst &Inst,
6301 "Unexpected instruction!");
6302 ((MipsOperand &)*
Operands[1]).addGPR32ZeroAsmRegOperands(Inst, 1);
6303 MCRegister NextReg =
nextReg(((MipsOperand &)*
Operands[1]).getGPR32Reg());
6305 static_cast<MipsOperand &
>(*
Operands[4]).addPtrRegOperands(Inst, 1);
6306 static_cast<MipsOperand &
>(*
Operands[2]).addImmOperands(Inst, 1);
6309template <
unsigned Opcode,
bool IsMFTR>
6310void MipsAsmParser::ConvertMTTransferCOP0Operands(
6312 MCRegister GPR =
static_cast<const MipsOperand &
>(*
Operands[1]).getGPR32Reg();
6314 static_cast<const MipsOperand &
>(*
Operands[2]).getCOP0Encoding();
6318 ->getRegClass(Mips::GPR32RegClassID)
6329MipsAsmParser::printWarningWithFixIt(
const Twine &
Msg,
const Twine &FixMsg,
6330 SMRange
Range,
bool ShowColors) {
6336int MipsAsmParser::matchCPURegisterName(StringRef Name) {
6337 const MCRegisterInfo &
MRI = *
getContext().getRegisterInfo();
6343 AsmToken RegTok = getLexer().peekTok();
6344 StringRef FixedName =
6346 printWarningWithFixIt(
"register names $t4-$t7 are only available in O32.",
6347 "Did you mean $" + FixedName +
"?",
6353int MipsAsmParser::matchHWRegsRegisterName(StringRef Name) {
6354 const MCRegisterInfo &
MRI = *
getContext().getRegisterInfo();
6356 Mips::RegAliasName);
6357 return Reg ?
MRI.getEncodingValue(
Reg) : -1;
6360int MipsAsmParser::matchFPURegisterName(StringRef Name) {
6361 if (Name[0] ==
'f') {
6362 StringRef NumString =
Name.substr(1);
6373int MipsAsmParser::matchFCCRegisterName(StringRef Name) {
6374 if (
Name.starts_with(
"fcc")) {
6375 StringRef NumString =
Name.substr(3);
6386int MipsAsmParser::matchACRegisterName(StringRef Name) {
6387 if (
Name.starts_with(
"ac")) {
6388 StringRef NumString =
Name.substr(2);
6399int MipsAsmParser::matchMSA128RegisterName(StringRef Name) {
6402 if (
Name.front() !=
'w' ||
Name.drop_front(1).getAsInteger(10, IntVal))
6411int MipsAsmParser::matchMSA128CtrlRegisterName(StringRef Name) {
6412 const MCRegisterInfo &
MRI = *
getContext().getRegisterInfo();
6414 Name,
MRI, Mips::MSACtrlRegClassID, Mips::RegAliasName);
6415 return Reg ?
MRI.getEncodingValue(
Reg) : -1;
6418bool MipsAsmParser::canUseATReg() {
6419 return AssemblerOptions.
back()->getATRegIndex() != 0;
6422MCRegister MipsAsmParser::getATReg(SMLoc Loc) {
6423 unsigned ATIndex = AssemblerOptions.
back()->getATRegIndex();
6425 reportParseError(Loc,
6426 "pseudo-instruction requires $at, which is not available");
6430 (isGP64bit()) ? Mips::GPR64RegClassID : Mips::GPR32RegClassID, ATIndex);
6434MCRegister MipsAsmParser::getReg(
int RC,
int RegNo) {
6435 return getContext().getRegisterInfo()->getRegClass(RC).getRegister(RegNo);
6440bool MipsAsmParser::parsePrimaryExpr(
const MCExpr *&Res, SMLoc &EndLoc) {
6442 return getParser().parsePrimaryExpr(Res, EndLoc);
6443 Res = parseRelocExpr();
6444 EndLoc = getLexer().getLoc();
6450const MCExpr *MipsAsmParser::parseRelocExpr() {
6451 auto getOp = [](StringRef
Op) {
6452 return StringSwitch<Mips::Specifier>(
Op)
6480 MCAsmParser &Parser = getParser();
6482 const MCExpr *Res =
nullptr;
6488 auto Op = getOp(Name);
6497 while (
Ops.size()) {
6506 MCAsmParser &Parser = getParser();
6516 ParseStatus Res = MatchOperandParserImpl(
Operands, Mnemonic,
true);
6527 switch (getLexer().getKind()) {
6537 if (!parseAnyRegister(
Operands).isNoMatch())
6550 Operands.push_back(MipsOperand::CreateImm(SymRef, S,
E, *
this));
6555 const MCExpr *Expr = parseRelocExpr();
6559 Operands.push_back(MipsOperand::CreateImm(Expr, S,
E, *
this));
6566bool MipsAsmParser::parseRegister(MCRegister &
Reg, SMLoc &StartLoc,
6568 return !tryParseRegister(
Reg, StartLoc, EndLoc).isSuccess();
6571ParseStatus MipsAsmParser::tryParseRegister(MCRegister &
Reg, SMLoc &StartLoc,
6574 ParseStatus Res = parseAnyRegister(
Operands);
6577 MipsOperand &Operand =
static_cast<MipsOperand &
>(*
Operands.front());
6578 StartLoc = Operand.getStartLoc();
6579 EndLoc = Operand.getEndLoc();
6585 if (Operand.isGPRAsmReg()) {
6587 Reg = isGP64bit() ? Operand.getGPR64Reg() : Operand.getGPR32Reg();
6597const MCExpr *MipsAsmParser::parseMemOffset() {
6604 if (getParser().parseExpression(
Offset))
6613 SMLoc S = getLexer().getLoc();
6614 const MCExpr *
Offset = parseMemOffset();
6618 SMLoc
E = getLexer().getLoc();
6630 Operands.push_back(MipsOperand::CreateToken(
"(",
E, *
this));
6631 Operands.push_back(MipsOperand::createGPRReg(
6633 Operands.push_back(MipsOperand::CreateToken(
")",
E, *
this));
6638 MCAsmParser &Parser = getParser();
6640 const MCExpr *
Address = parseMemOffset();
6657 std::unique_ptr<MipsOperand>
Base(
6658 static_cast<MipsOperand *
>(
Operands.back().release()));
6660 E =
Base->getEndLoc();
6662 MipsOperand::CreateMem(std::move(
Base),
Address, S,
E, *
this));
6667 MCAsmParser &Parser = getParser();
6676 const MCSymbolRefExpr *
Ref =
static_cast<const MCSymbolRefExpr *
>(Expr);
6677 StringRef DefSymbol =
Ref->getSymbol().getName();
6680 matchAnyRegisterNameWithoutDollar(
Operands, DefSymbol.
substr(1), S);
6694 if (Entry != RegisterSets.
end()) {
6696 matchAnyRegisterWithoutDollar(
Operands,
Entry->getValue(), S);
6707ParseStatus MipsAsmParser::matchAnyRegisterNameWithoutDollar(
6709 int Index = matchCPURegisterName(Identifier);
6711 Operands.push_back(MipsOperand::createGPRReg(
6712 Index, Identifier,
getContext().getRegisterInfo(), S,
6713 getLexer().getLoc(), *
this));
6717 Index = matchHWRegsRegisterName(Identifier);
6719 Operands.push_back(MipsOperand::createHWRegsReg(
6720 Index, Identifier,
getContext().getRegisterInfo(), S,
6721 getLexer().getLoc(), *
this));
6725 const MCRegisterInfo &
MRI = *
getContext().getRegisterInfo();
6727 Identifier,
MRI, Mips::COP0RegClassID, Mips::RegAliasName)) {
6728 Operands.push_back(MipsOperand::createCOP0Reg(
MRI.getEncodingValue(
Reg),
6729 Identifier, &
MRI, S,
6730 getLexer().getLoc(), *
this));
6734 Index = matchFPURegisterName(Identifier);
6736 Operands.push_back(MipsOperand::createFGRReg(
6737 Index, Identifier,
getContext().getRegisterInfo(), S,
6738 getLexer().getLoc(), *
this));
6742 Index = matchFCCRegisterName(Identifier);
6744 Operands.push_back(MipsOperand::createFCCReg(
6745 Index, Identifier,
getContext().getRegisterInfo(), S,
6746 getLexer().getLoc(), *
this));
6750 Index = matchACRegisterName(Identifier);
6752 Operands.push_back(MipsOperand::createACCReg(
6753 Index, Identifier,
getContext().getRegisterInfo(), S,
6754 getLexer().getLoc(), *
this));
6758 Index = matchMSA128RegisterName(Identifier);
6760 Operands.push_back(MipsOperand::createMSA128Reg(
6761 Index, Identifier,
getContext().getRegisterInfo(), S,
6762 getLexer().getLoc(), *
this));
6766 Index = matchMSA128CtrlRegisterName(Identifier);
6768 Operands.push_back(MipsOperand::createMSACtrlReg(
6769 Index, Identifier,
getContext().getRegisterInfo(), S,
6770 getLexer().getLoc(), *
this));
6779 const AsmToken &Token, SMLoc S) {
6783 return matchAnyRegisterNameWithoutDollar(
Operands, Identifier, S);
6788 if (RegNum < 0 || RegNum > 31) {
6792 Error(getLexer().getLoc(),
"invalid register number");
6794 Operands.push_back(MipsOperand::createNumericReg(
6807 auto Token = getLexer().peekTok(
false);
6808 return matchAnyRegisterWithoutDollar(
Operands, Token, S);
6812 SMLoc S = getLexer().getLoc();
6814 ParseStatus Res = parseAnyRegister(RegOperands);
6817 const auto &
Op =
static_cast<const MipsOperand &
>(*RegOperands.
back());
6819 if (
Op.isCOP0AsmReg()) {
6820 Encoding =
Op.getCOP0Encoding();
6822 return Error(getLexer().getLoc(),
6823 "explicit selector is not allowed for named COP0 register");
6824 }
else if (
Op.isNumericReg()) {
6828 SMLoc SelLoc = getLexer().getLoc();
6830 if (getParser().parseExpression(Expr))
6832 if (!Expr->evaluateAsAbsolute(Sel) || !
isUInt<3>(Sel))
6833 return Error(SelLoc,
"expected 3-bit unsigned immediate");
6837 return Error(S,
"invalid operand for instruction");
6840 return Error(S,
"selector must be zero for pre-MIPS32 ISAs");
6842 const MCRegisterInfo &
MRI = *
getContext().getRegisterInfo();
6843 Operands.push_back(MipsOperand::createCOP0Reg(Encoding,
"", &
MRI, S,
6844 getLexer().getLoc(), *
this));
6849 MCAsmParser &Parser = getParser();
6852 auto Token = Parser.
getTok();
6854 SMLoc S = Token.
getLoc();
6867 ParseStatus Res = matchAnyRegisterWithoutDollar(
Operands, S);
6876 MCAsmParser &Parser = getParser();
6879 SMLoc S = getLexer().getLoc();
6882 ParseStatus Res = parseAnyRegister(
Operands);
6887 const MCExpr *Expr =
nullptr;
6893 MipsOperand::CreateImm(Expr, S, getLexer().getLoc(), *
this));
6898 MCAsmParser &Parser = getParser();
6899 const MCExpr *IdVal;
6910 if (getParser().parseExpression(IdVal))
6917 Operands.push_back(MipsOperand::CreateImm(
6923 MCAsmParser &Parser = getParser();
6927 bool RegRange =
false;
6934 while (parseAnyRegister(TmpOperands).isSuccess()) {
6935 SMLoc
E = getLexer().getLoc();
6936 MipsOperand &RegOpnd =
static_cast<MipsOperand &
>(*TmpOperands.
back());
6937 Reg = isGP64bit() ? RegOpnd.getGPR64Reg() : RegOpnd.getGPR32Reg();
6945 MCRegister TmpReg = PrevReg + 1;
6946 while (TmpReg <=
Reg) {
6947 if ((((TmpReg < Mips::R16) || (TmpReg > Mips::R23)) &&
6949 (((TmpReg < Mips::R16_64) || (TmpReg > Mips::R23_64)) &&
6951 return Error(
E,
"invalid register operand");
6955 TmpReg = TmpReg.
id() + 1;
6964 return Error(
E,
"$16 or $31 expected");
6966 (
Reg >= Mips::R16 &&
Reg <= Mips::R23)) &&
6969 (
Reg >= Mips::R16_64 &&
Reg <= Mips::R23_64)) &&
6971 return Error(
E,
"invalid register operand");
6972 if (PrevReg.
isValid() && (
Reg != PrevReg + 1) &&
6975 return Error(
E,
"consecutive register numbers expected");
6985 return Error(
E,
"',' or '-' expected");
6995 Operands.push_back(MipsOperand::CreateRegList(Regs, S,
E, *
this));
6996 return parseMemOffsetOperand(
Operands);
7005 MCAsmParser &Parser = getParser();
7008 MipsOperand::CreateToken(
"(", getLexer().getLoc(), *
this));
7010 if (parseOperand(
Operands, Name)) {
7011 SMLoc Loc = getLexer().getLoc();
7012 return Error(Loc,
"unexpected token in argument list");
7015 SMLoc Loc = getLexer().getLoc();
7016 return Error(Loc,
"unexpected token, expected ')'");
7019 MipsOperand::CreateToken(
")", getLexer().getLoc(), *
this));
7031bool MipsAsmParser::parseBracketSuffix(StringRef Name,
7033 MCAsmParser &Parser = getParser();
7036 MipsOperand::CreateToken(
"[", getLexer().getLoc(), *
this));
7038 if (parseOperand(
Operands, Name)) {
7039 SMLoc Loc = getLexer().getLoc();
7040 return Error(Loc,
"unexpected token in argument list");
7043 SMLoc Loc = getLexer().getLoc();
7044 return Error(Loc,
"unexpected token, expected ']'");
7047 MipsOperand::CreateToken(
"]", getLexer().getLoc(), *
this));
7054 unsigned VariantID = 0);
7069bool MipsAsmParser::parseInstruction(ParseInstructionInfo &Info, StringRef Name,
7071 MCAsmParser &Parser = getParser();
7075 getTargetStreamer().forbidModuleDirective();
7078 if (!mnemonicIsValid(Name, 0)) {
7079 FeatureBitset FBS = ComputeAvailableFeatures(getSTI().getFeatureBits());
7081 return Error(NameLoc,
"unknown instruction" + Suggestion);
7084 Operands.push_back(MipsOperand::CreateToken(Name, NameLoc, *
this));
7089 bool IsFirstOperand =
Operands.size() == 1;
7091 if (parseOperand(
Operands, Name)) {
7092 SMLoc Loc = getLexer().getLoc();
7093 return Error(Loc,
"unexpected token in argument list");
7098 if (parseBracketSuffix(Name,
Operands))
7106 SMLoc Loc = getLexer().getLoc();
7107 return Error(Loc,
"unexpected token in argument list");
7115bool MipsAsmParser::reportParseError(
const Twine &ErrorMsg) {
7116 SMLoc Loc = getLexer().getLoc();
7117 return Error(Loc, ErrorMsg);
7120bool MipsAsmParser::reportParseError(SMLoc Loc,
const Twine &ErrorMsg) {
7121 return Error(Loc, ErrorMsg);
7124bool MipsAsmParser::parseSetNoAtDirective() {
7125 MCAsmParser &Parser = getParser();
7129 AssemblerOptions.
back()->setATRegIndex(0);
7135 reportParseError(
"unexpected token, expected end of statement");
7139 getTargetStreamer().emitDirectiveSetNoAt();
7144bool MipsAsmParser::parseSetAtDirective() {
7147 MCAsmParser &Parser = getParser();
7152 AssemblerOptions.
back()->setATRegIndex(1);
7154 getTargetStreamer().emitDirectiveSetAt();
7160 reportParseError(
"unexpected token, expected equals sign");
7167 reportParseError(
"no register specified");
7170 reportParseError(
"unexpected token, expected dollar sign '$'");
7180 AtRegNo = matchCPURegisterName(
Reg.getIdentifier());
7182 AtRegNo =
Reg.getIntVal();
7184 reportParseError(
"unexpected token, expected identifier or integer");
7189 if (!AssemblerOptions.
back()->setATRegIndex(AtRegNo)) {
7190 reportParseError(
"invalid register");
7197 reportParseError(
"unexpected token, expected end of statement");
7201 getTargetStreamer().emitDirectiveSetAtWithArg(AtRegNo);
7207bool MipsAsmParser::parseSetReorderDirective() {
7208 MCAsmParser &Parser = getParser();
7212 reportParseError(
"unexpected token, expected end of statement");
7215 AssemblerOptions.
back()->setReorder();
7216 getTargetStreamer().emitDirectiveSetReorder();
7221bool MipsAsmParser::parseSetNoReorderDirective() {
7222 MCAsmParser &Parser = getParser();
7226 reportParseError(
"unexpected token, expected end of statement");
7229 AssemblerOptions.
back()->setNoReorder();
7230 getTargetStreamer().emitDirectiveSetNoReorder();
7235bool MipsAsmParser::parseSetMacroDirective() {
7236 MCAsmParser &Parser = getParser();
7240 reportParseError(
"unexpected token, expected end of statement");
7243 AssemblerOptions.
back()->setMacro();
7244 getTargetStreamer().emitDirectiveSetMacro();
7249bool MipsAsmParser::parseSetNoMacroDirective() {
7250 MCAsmParser &Parser = getParser();
7254 reportParseError(
"unexpected token, expected end of statement");
7257 if (AssemblerOptions.
back()->isReorder()) {
7258 reportParseError(
"`noreorder' must be set before `nomacro'");
7261 AssemblerOptions.
back()->setNoMacro();
7262 getTargetStreamer().emitDirectiveSetNoMacro();
7267bool MipsAsmParser::parseSetMsaDirective() {
7268 MCAsmParser &Parser = getParser();
7273 return reportParseError(
"unexpected token, expected end of statement");
7275 setFeatureBits(Mips::FeatureMSA,
"msa");
7276 getTargetStreamer().emitDirectiveSetMsa();
7280bool MipsAsmParser::parseSetNoMsaDirective() {
7281 MCAsmParser &Parser = getParser();
7286 return reportParseError(
"unexpected token, expected end of statement");
7288 clearFeatureBits(Mips::FeatureMSA,
"msa");
7289 getTargetStreamer().emitDirectiveSetNoMsa();
7293bool MipsAsmParser::parseSetNoDspDirective() {
7294 MCAsmParser &Parser = getParser();
7299 reportParseError(
"unexpected token, expected end of statement");
7303 clearFeatureBits(Mips::FeatureDSP,
"dsp");
7304 getTargetStreamer().emitDirectiveSetNoDsp();
7308bool MipsAsmParser::parseSetNoMips3DDirective() {
7309 MCAsmParser &Parser = getParser();
7314 reportParseError(
"unexpected token, expected end of statement");
7318 clearFeatureBits(Mips::FeatureMips3D,
"mips3d");
7319 getTargetStreamer().emitDirectiveSetNoMips3D();
7323bool MipsAsmParser::parseSetMips16Directive() {
7324 MCAsmParser &Parser = getParser();
7329 reportParseError(
"unexpected token, expected end of statement");
7333 clearFeatureBits(Mips::FeatureMicroMips,
"micromips");
7334 setFeatureBits(Mips::FeatureMips16,
"mips16");
7335 getTargetStreamer().emitDirectiveSetMips16();
7340bool MipsAsmParser::parseSetNoMips16Directive() {
7341 MCAsmParser &Parser = getParser();
7346 reportParseError(
"unexpected token, expected end of statement");
7350 clearFeatureBits(Mips::FeatureMips16,
"mips16");
7351 getTargetStreamer().emitDirectiveSetNoMips16();
7356bool MipsAsmParser::parseSetFpDirective() {
7357 MCAsmParser &Parser = getParser();
7363 AsmToken Tok = Parser.
getTok();
7365 reportParseError(
"unexpected token, expected equals sign '='");
7371 if (!parseFpABIValue(FpAbiVal,
".set"))
7375 reportParseError(
"unexpected token, expected end of statement");
7378 getTargetStreamer().emitDirectiveSetFp(FpAbiVal);
7383bool MipsAsmParser::parseSetOddSPRegDirective() {
7384 MCAsmParser &Parser = getParser();
7388 reportParseError(
"unexpected token, expected end of statement");
7392 clearFeatureBits(Mips::FeatureNoOddSPReg,
"nooddspreg");
7393 getTargetStreamer().emitDirectiveSetOddSPReg();
7397bool MipsAsmParser::parseSetNoOddSPRegDirective() {
7398 MCAsmParser &Parser = getParser();
7402 reportParseError(
"unexpected token, expected end of statement");
7406 setFeatureBits(Mips::FeatureNoOddSPReg,
"nooddspreg");
7407 getTargetStreamer().emitDirectiveSetNoOddSPReg();
7411bool MipsAsmParser::parseSetMtDirective() {
7412 MCAsmParser &Parser = getParser();
7417 reportParseError(
"unexpected token, expected end of statement");
7421 setFeatureBits(Mips::FeatureMT,
"mt");
7422 getTargetStreamer().emitDirectiveSetMt();
7427bool MipsAsmParser::parseSetNoMtDirective() {
7428 MCAsmParser &Parser = getParser();
7433 reportParseError(
"unexpected token, expected end of statement");
7437 clearFeatureBits(Mips::FeatureMT,
"mt");
7439 getTargetStreamer().emitDirectiveSetNoMt();
7444bool MipsAsmParser::parseSetNoCRCDirective() {
7445 MCAsmParser &Parser = getParser();
7450 reportParseError(
"unexpected token, expected end of statement");
7454 clearFeatureBits(Mips::FeatureCRC,
"crc");
7456 getTargetStreamer().emitDirectiveSetNoCRC();
7461bool MipsAsmParser::parseSetNoVirtDirective() {
7462 MCAsmParser &Parser = getParser();
7467 reportParseError(
"unexpected token, expected end of statement");
7471 clearFeatureBits(Mips::FeatureVirt,
"virt");
7473 getTargetStreamer().emitDirectiveSetNoVirt();
7478bool MipsAsmParser::parseSetNoGINVDirective() {
7479 MCAsmParser &Parser = getParser();
7484 reportParseError(
"unexpected token, expected end of statement");
7488 clearFeatureBits(Mips::FeatureGINV,
"ginv");
7490 getTargetStreamer().emitDirectiveSetNoGINV();
7495bool MipsAsmParser::parseSetNoEVADirective() {
7496 MCAsmParser &Parser = getParser();
7501 reportParseError(
"unexpected token, expected end of statement");
7505 clearFeatureBits(Mips::FeatureEVA,
"eva");
7507 getTargetStreamer().emitDirectiveSetNoEVA();
7512bool MipsAsmParser::parseSetPopDirective() {
7513 MCAsmParser &Parser = getParser();
7514 SMLoc Loc = getLexer().getLoc();
7518 return reportParseError(
"unexpected token, expected end of statement");
7522 if (AssemblerOptions.
size() == 2)
7523 return reportParseError(Loc,
".set pop with no .set push");
7525 MCSubtargetInfo &STI = copySTI();
7527 setAvailableFeatures(
7528 ComputeAvailableFeatures(AssemblerOptions.
back()->getFeatures()));
7531 getTargetStreamer().emitDirectiveSetPop();
7535bool MipsAsmParser::parseSetPushDirective() {
7536 MCAsmParser &Parser = getParser();
7539 return reportParseError(
"unexpected token, expected end of statement");
7543 std::make_unique<MipsAssemblerOptions>(AssemblerOptions.
back().get()));
7545 getTargetStreamer().emitDirectiveSetPush();
7549bool MipsAsmParser::parseSetSoftFloatDirective() {
7550 MCAsmParser &Parser = getParser();
7553 return reportParseError(
"unexpected token, expected end of statement");
7555 setFeatureBits(Mips::FeatureSoftFloat,
"soft-float");
7556 getTargetStreamer().emitDirectiveSetSoftFloat();
7560bool MipsAsmParser::parseSetHardFloatDirective() {
7561 MCAsmParser &Parser = getParser();
7564 return reportParseError(
"unexpected token, expected end of statement");
7566 clearFeatureBits(Mips::FeatureSoftFloat,
"soft-float");
7567 getTargetStreamer().emitDirectiveSetHardFloat();
7571bool MipsAsmParser::parseSetAssignment() {
7573 MCAsmParser &Parser = getParser();
7576 return reportParseError(
"expected identifier after .set");
7579 return reportParseError(
"unexpected token, expected comma");
7594 const MCExpr *
Value;
7596 Parser, Sym,
Value))
7598 getStreamer().emitAssignment(Sym,
Value);
7603bool MipsAsmParser::parseSetMips0Directive() {
7604 MCAsmParser &Parser = getParser();
7607 return reportParseError(
"unexpected token, expected end of statement");
7610 MCSubtargetInfo &STI = copySTI();
7611 setAvailableFeatures(
7612 ComputeAvailableFeatures(AssemblerOptions.
front()->getFeatures()));
7614 AssemblerOptions.
back()->setFeatures(AssemblerOptions.
front()->getFeatures());
7616 getTargetStreamer().emitDirectiveSetMips0();
7620bool MipsAsmParser::parseSetArchDirective() {
7621 MCAsmParser &Parser = getParser();
7624 return reportParseError(
"unexpected token, expected equals sign");
7627 StringRef Arch = getParser().parseStringToEndOfStatement().trim();
7629 return reportParseError(
"expected arch identifier");
7631 StringRef ArchFeatureName =
7632 StringSwitch<StringRef>(Arch)
7633 .Case(
"mips1",
"mips1")
7634 .Case(
"mips2",
"mips2")
7635 .Case(
"mips3",
"mips3")
7636 .Case(
"mips4",
"mips4")
7637 .Case(
"mips5",
"mips5")
7638 .Case(
"mips32",
"mips32")
7639 .Case(
"mips32r2",
"mips32r2")
7640 .Case(
"mips32r3",
"mips32r3")
7641 .Case(
"mips32r5",
"mips32r5")
7642 .Case(
"mips32r6",
"mips32r6")
7643 .Case(
"mips64",
"mips64")
7644 .Case(
"mips64r2",
"mips64r2")
7645 .Case(
"mips64r3",
"mips64r3")
7646 .Case(
"mips64r5",
"mips64r5")
7647 .Case(
"mips64r6",
"mips64r6")
7648 .Case(
"octeon",
"cnmips")
7649 .Case(
"octeon+",
"cnmipsp")
7650 .Case(
"r4000",
"mips3")
7653 if (ArchFeatureName.
empty())
7654 return reportParseError(
"unsupported architecture");
7656 if (ArchFeatureName ==
"mips64r6" && inMicroMipsMode())
7657 return reportParseError(
"mips64r6 does not support microMIPS");
7659 selectArch(ArchFeatureName);
7660 getTargetStreamer().emitDirectiveSetArch(Arch);
7664bool MipsAsmParser::parseSetFeature(
uint64_t Feature) {
7665 MCAsmParser &Parser = getParser();
7668 return reportParseError(
"unexpected token, expected end of statement");
7673 case Mips::FeatureMips3D:
7674 setFeatureBits(Mips::FeatureMips3D,
"mips3d");
7675 getTargetStreamer().emitDirectiveSetMips3D();
7677 case Mips::FeatureDSP:
7678 setFeatureBits(Mips::FeatureDSP,
"dsp");
7679 getTargetStreamer().emitDirectiveSetDsp();
7681 case Mips::FeatureDSPR2:
7682 setFeatureBits(Mips::FeatureDSPR2,
"dspr2");
7683 getTargetStreamer().emitDirectiveSetDspr2();
7685 case Mips::FeatureMicroMips:
7686 clearFeatureBits(Mips::FeatureMips16,
"mips16");
7687 setFeatureBits(Mips::FeatureMicroMips,
"micromips");
7688 getTargetStreamer().emitDirectiveSetMicroMips();
7690 case Mips::FeatureMips1:
7691 selectArch(
"mips1");
7692 getTargetStreamer().emitDirectiveSetMips1();
7694 case Mips::FeatureMips2:
7695 selectArch(
"mips2");
7696 getTargetStreamer().emitDirectiveSetMips2();
7698 case Mips::FeatureMips3:
7699 selectArch(
"mips3");
7700 getTargetStreamer().emitDirectiveSetMips3();
7702 case Mips::FeatureMips4:
7703 selectArch(
"mips4");
7704 getTargetStreamer().emitDirectiveSetMips4();
7706 case Mips::FeatureMips5:
7707 selectArch(
"mips5");
7708 getTargetStreamer().emitDirectiveSetMips5();
7710 case Mips::FeatureMips32:
7711 selectArch(
"mips32");
7712 getTargetStreamer().emitDirectiveSetMips32();
7714 case Mips::FeatureMips32r2:
7715 selectArch(
"mips32r2");
7716 getTargetStreamer().emitDirectiveSetMips32R2();
7718 case Mips::FeatureMips32r3:
7719 selectArch(
"mips32r3");
7720 getTargetStreamer().emitDirectiveSetMips32R3();
7722 case Mips::FeatureMips32r5:
7723 selectArch(
"mips32r5");
7724 getTargetStreamer().emitDirectiveSetMips32R5();
7726 case Mips::FeatureMips32r6:
7727 selectArch(
"mips32r6");
7728 getTargetStreamer().emitDirectiveSetMips32R6();
7730 case Mips::FeatureMips64:
7731 selectArch(
"mips64");
7732 getTargetStreamer().emitDirectiveSetMips64();
7734 case Mips::FeatureMips64r2:
7735 selectArch(
"mips64r2");
7736 getTargetStreamer().emitDirectiveSetMips64R2();
7738 case Mips::FeatureMips64r3:
7739 selectArch(
"mips64r3");
7740 getTargetStreamer().emitDirectiveSetMips64R3();
7742 case Mips::FeatureMips64r5:
7743 selectArch(
"mips64r5");
7744 getTargetStreamer().emitDirectiveSetMips64R5();
7746 case Mips::FeatureMips64r6:
7747 selectArch(
"mips64r6");
7748 getTargetStreamer().emitDirectiveSetMips64R6();
7750 case Mips::FeatureCRC:
7751 setFeatureBits(Mips::FeatureCRC,
"crc");
7752 getTargetStreamer().emitDirectiveSetCRC();
7754 case Mips::FeatureVirt:
7755 setFeatureBits(Mips::FeatureVirt,
"virt");
7756 getTargetStreamer().emitDirectiveSetVirt();
7758 case Mips::FeatureGINV:
7759 setFeatureBits(Mips::FeatureGINV,
"ginv");
7760 getTargetStreamer().emitDirectiveSetGINV();
7762 case Mips::FeatureEVA:
7763 setFeatureBits(Mips::FeatureEVA,
"eva");
7764 getTargetStreamer().emitDirectiveSetEVA();
7770bool MipsAsmParser::eatComma(StringRef ErrorStr) {
7771 MCAsmParser &Parser = getParser();
7773 SMLoc Loc = getLexer().getLoc();
7774 return Error(Loc, ErrorStr);
7785bool MipsAsmParser::isPicAndNotNxxAbi() {
7786 return inPicMode() && !(isABI_N32() || isABI_N64());
7789bool MipsAsmParser::parseDirectiveCpAdd(SMLoc Loc) {
7791 ParseStatus Res = parseAnyRegister(
Reg);
7793 reportParseError(
"expected register");
7797 MipsOperand &RegOpnd =
static_cast<MipsOperand &
>(*
Reg[0]);
7798 if (!RegOpnd.isGPRAsmReg()) {
7799 reportParseError(RegOpnd.getStartLoc(),
"invalid register");
7805 reportParseError(
"unexpected token, expected end of statement");
7810 getTargetStreamer().emitDirectiveCpAdd(RegOpnd.getGPR32Reg());
7814bool MipsAsmParser::parseDirectiveCpLoad(SMLoc Loc) {
7815 if (AssemblerOptions.
back()->isReorder())
7816 Warning(Loc,
".cpload should be inside a noreorder section");
7818 if (inMips16Mode()) {
7819 reportParseError(
".cpload is not supported in Mips16 mode");
7824 ParseStatus Res = parseAnyRegister(
Reg);
7826 reportParseError(
"expected register containing function address");
7830 MipsOperand &RegOpnd =
static_cast<MipsOperand &
>(*
Reg[0]);
7831 if (!RegOpnd.isGPRAsmReg()) {
7832 reportParseError(RegOpnd.getStartLoc(),
"invalid register");
7838 reportParseError(
"unexpected token, expected end of statement");
7842 getTargetStreamer().emitDirectiveCpLoad(RegOpnd.getGPR32Reg());
7846bool MipsAsmParser::parseDirectiveCpLocal(SMLoc Loc) {
7847 if (!isABI_N32() && !isABI_N64()) {
7848 reportParseError(
".cplocal is allowed only in N32 or N64 mode");
7853 ParseStatus Res = parseAnyRegister(
Reg);
7855 reportParseError(
"expected register containing global pointer");
7859 MipsOperand &RegOpnd =
static_cast<MipsOperand &
>(*
Reg[0]);
7860 if (!RegOpnd.isGPRAsmReg()) {
7861 reportParseError(RegOpnd.getStartLoc(),
"invalid register");
7867 reportParseError(
"unexpected token, expected end of statement");
7872 MCRegister NewReg = RegOpnd.getGPR32Reg();
7876 getTargetStreamer().emitDirectiveCpLocal(NewReg);
7880bool MipsAsmParser::parseDirectiveCpRestore(SMLoc Loc) {
7881 MCAsmParser &Parser = getParser();
7886 if (inMips16Mode()) {
7887 reportParseError(
".cprestore is not supported in Mips16 mode");
7892 const MCExpr *StackOffset;
7893 int64_t StackOffsetVal;
7895 reportParseError(
"expected stack offset value");
7899 if (!StackOffset->evaluateAsAbsolute(StackOffsetVal)) {
7900 reportParseError(
"stack offset is not an absolute expression");
7904 if (StackOffsetVal < 0) {
7905 Warning(Loc,
".cprestore with negative stack offset has no effect");
7906 IsCpRestoreSet =
false;
7908 IsCpRestoreSet =
true;
7909 CpRestoreOffset = StackOffsetVal;
7914 reportParseError(
"unexpected token, expected end of statement");
7918 if (!getTargetStreamer().emitDirectiveCpRestore(
7919 CpRestoreOffset, [&]() {
return getATReg(Loc); }, Loc, STI))
7925bool MipsAsmParser::parseDirectiveCPSetup() {
7926 MCAsmParser &Parser = getParser();
7928 bool SaveIsReg =
true;
7931 ParseStatus Res = parseAnyRegister(TmpReg);
7933 reportParseError(
"expected register containing function address");
7937 MipsOperand &FuncRegOpnd =
static_cast<MipsOperand &
>(*TmpReg[0]);
7938 if (!FuncRegOpnd.isGPRAsmReg()) {
7939 reportParseError(FuncRegOpnd.getStartLoc(),
"invalid register");
7943 MCRegister FuncReg = FuncRegOpnd.getGPR32Reg();
7946 if (!eatComma(
"unexpected token, expected comma"))
7949 Res = parseAnyRegister(TmpReg);
7951 const MCExpr *OffsetExpr;
7953 SMLoc ExprLoc = getLexer().
getLoc();
7956 !OffsetExpr->evaluateAsAbsolute(OffsetVal)) {
7957 reportParseError(ExprLoc,
"expected save register or stack offset");
7964 MipsOperand &SaveOpnd =
static_cast<MipsOperand &
>(*TmpReg[0]);
7965 if (!SaveOpnd.isGPRAsmReg()) {
7966 reportParseError(SaveOpnd.getStartLoc(),
"invalid register");
7969 Save = SaveOpnd.getGPR32Reg().id();
7972 if (!eatComma(
"unexpected token, expected comma"))
7977 reportParseError(
"expected expression");
7982 reportParseError(
"expected symbol");
7985 const MCSymbolRefExpr *
Ref =
static_cast<const MCSymbolRefExpr *
>(Expr);
7987 CpSaveLocation = Save;
7988 CpSaveLocationIsRegister = SaveIsReg;
7990 getTargetStreamer().emitDirectiveCpsetup(FuncReg, Save,
Ref->getSymbol(),
7995bool MipsAsmParser::parseDirectiveCPReturn() {
7996 getTargetStreamer().emitDirectiveCpreturn(CpSaveLocation,
7997 CpSaveLocationIsRegister);
8001bool MipsAsmParser::parseDirectiveNaN() {
8002 MCAsmParser &Parser = getParser();
8004 const AsmToken &Tok = Parser.
getTok();
8008 getTargetStreamer().emitDirectiveNaN2008();
8010 }
else if (Tok.
getString() ==
"legacy") {
8012 getTargetStreamer().emitDirectiveNaNLegacy();
8018 reportParseError(
"invalid option in .nan directive");
8022bool MipsAsmParser::parseDirectiveSet() {
8023 const AsmToken &Tok = getParser().getTok();
8025 SMLoc Loc = Tok.
getLoc();
8027 if (IdVal ==
"noat")
8028 return parseSetNoAtDirective();
8030 return parseSetAtDirective();
8031 if (IdVal ==
"arch")
8032 return parseSetArchDirective();
8033 if (IdVal ==
"bopt") {
8034 Warning(Loc,
"'bopt' feature is unsupported");
8038 if (IdVal ==
"nobopt") {
8044 return parseSetFpDirective();
8045 if (IdVal ==
"oddspreg")
8046 return parseSetOddSPRegDirective();
8047 if (IdVal ==
"nooddspreg")
8048 return parseSetNoOddSPRegDirective();
8050 return parseSetPopDirective();
8051 if (IdVal ==
"push")
8052 return parseSetPushDirective();
8053 if (IdVal ==
"reorder")
8054 return parseSetReorderDirective();
8055 if (IdVal ==
"noreorder")
8056 return parseSetNoReorderDirective();
8057 if (IdVal ==
"macro")
8058 return parseSetMacroDirective();
8059 if (IdVal ==
"nomacro")
8060 return parseSetNoMacroDirective();
8061 if (IdVal ==
"mips16")
8062 return parseSetMips16Directive();
8063 if (IdVal ==
"nomips16")
8064 return parseSetNoMips16Directive();
8065 if (IdVal ==
"nomicromips") {
8066 clearFeatureBits(Mips::FeatureMicroMips,
"micromips");
8067 getTargetStreamer().emitDirectiveSetNoMicroMips();
8068 getParser().eatToEndOfStatement();
8071 if (IdVal ==
"micromips") {
8072 if (hasMips64r6()) {
8073 Error(Loc,
".set micromips directive is not supported with MIPS64R6");
8076 return parseSetFeature(Mips::FeatureMicroMips);
8078 if (IdVal ==
"mips0")
8079 return parseSetMips0Directive();
8080 if (IdVal ==
"mips1")
8081 return parseSetFeature(Mips::FeatureMips1);
8082 if (IdVal ==
"mips2")
8083 return parseSetFeature(Mips::FeatureMips2);
8084 if (IdVal ==
"mips3")
8085 return parseSetFeature(Mips::FeatureMips3);
8086 if (IdVal ==
"mips4")
8087 return parseSetFeature(Mips::FeatureMips4);
8088 if (IdVal ==
"mips5")
8089 return parseSetFeature(Mips::FeatureMips5);
8090 if (IdVal ==
"mips32")
8091 return parseSetFeature(Mips::FeatureMips32);
8092 if (IdVal ==
"mips32r2")
8093 return parseSetFeature(Mips::FeatureMips32r2);
8094 if (IdVal ==
"mips32r3")
8095 return parseSetFeature(Mips::FeatureMips32r3);
8096 if (IdVal ==
"mips32r5")
8097 return parseSetFeature(Mips::FeatureMips32r5);
8098 if (IdVal ==
"mips32r6")
8099 return parseSetFeature(Mips::FeatureMips32r6);
8100 if (IdVal ==
"mips64")
8101 return parseSetFeature(Mips::FeatureMips64);
8102 if (IdVal ==
"mips64r2")
8103 return parseSetFeature(Mips::FeatureMips64r2);
8104 if (IdVal ==
"mips64r3")
8105 return parseSetFeature(Mips::FeatureMips64r3);
8106 if (IdVal ==
"mips64r5")
8107 return parseSetFeature(Mips::FeatureMips64r5);
8108 if (IdVal ==
"mips64r6") {
8109 if (inMicroMipsMode()) {
8110 Error(Loc,
"MIPS64R6 is not supported with microMIPS");
8113 return parseSetFeature(Mips::FeatureMips64r6);
8116 return parseSetFeature(Mips::FeatureDSP);
8117 if (IdVal ==
"dspr2")
8118 return parseSetFeature(Mips::FeatureDSPR2);
8119 if (IdVal ==
"nodsp")
8120 return parseSetNoDspDirective();
8121 if (IdVal ==
"mips3d")
8122 return parseSetFeature(Mips::FeatureMips3D);
8123 if (IdVal ==
"nomips3d")
8124 return parseSetNoMips3DDirective();
8126 return parseSetMsaDirective();
8127 if (IdVal ==
"nomsa")
8128 return parseSetNoMsaDirective();
8130 return parseSetMtDirective();
8131 if (IdVal ==
"nomt")
8132 return parseSetNoMtDirective();
8133 if (IdVal ==
"softfloat")
8134 return parseSetSoftFloatDirective();
8135 if (IdVal ==
"hardfloat")
8136 return parseSetHardFloatDirective();
8138 return parseSetFeature(Mips::FeatureCRC);
8139 if (IdVal ==
"nocrc")
8140 return parseSetNoCRCDirective();
8141 if (IdVal ==
"virt")
8142 return parseSetFeature(Mips::FeatureVirt);
8143 if (IdVal ==
"novirt")
8144 return parseSetNoVirtDirective();
8145 if (IdVal ==
"ginv")
8146 return parseSetFeature(Mips::FeatureGINV);
8147 if (IdVal ==
"noginv")
8148 return parseSetNoGINVDirective();
8150 return parseSetFeature(Mips::FeatureEVA);
8151 if (IdVal ==
"noeva")
8152 return parseSetNoEVADirective();
8155 return parseSetAssignment();
8160bool MipsAsmParser::parseDirectiveGpWord() {
8161 const MCExpr *
Value;
8162 if (getParser().parseExpression(
Value))
8164 getTargetStreamer().emitGPRel32Value(
Value);
8170bool MipsAsmParser::parseDirectiveGpDWord() {
8171 const MCExpr *
Value;
8172 if (getParser().parseExpression(
Value))
8174 getTargetStreamer().emitGPRel64Value(
Value);
8180bool MipsAsmParser::parseDirectiveDtpRelWord() {
8181 const MCExpr *
Value;
8182 if (getParser().parseExpression(
Value))
8184 getTargetStreamer().emitDTPRel32Value(
Value);
8190bool MipsAsmParser::parseDirectiveDtpRelDWord() {
8191 const MCExpr *
Value;
8192 if (getParser().parseExpression(
Value))
8194 getTargetStreamer().emitDTPRel64Value(
Value);
8200bool MipsAsmParser::parseDirectiveTpRelWord() {
8201 const MCExpr *
Value;
8202 if (getParser().parseExpression(
Value))
8204 getTargetStreamer().emitTPRel32Value(
Value);
8210bool MipsAsmParser::parseDirectiveTpRelDWord() {
8211 const MCExpr *
Value;
8212 if (getParser().parseExpression(
Value))
8214 getTargetStreamer().emitTPRel64Value(
Value);
8218bool MipsAsmParser::parseDirectiveOption() {
8219 MCAsmParser &Parser = getParser();
8221 AsmToken Tok = Parser.
getTok();
8225 "unexpected token, expected identifier");
8230 if (Option ==
"pic0") {
8232 IsPicEnabled =
false;
8234 getTargetStreamer().emitDirectiveOptionPic0();
8238 "unexpected token, expected end of statement");
8243 if (Option ==
"pic2") {
8245 IsPicEnabled =
true;
8247 getTargetStreamer().emitDirectiveOptionPic2();
8251 "unexpected token, expected end of statement");
8258 "unknown option, expected 'pic0' or 'pic2'");
8265bool MipsAsmParser::parseInsnDirective() {
8268 reportParseError(
"unexpected token, expected end of statement");
8274 getTargetStreamer().emitDirectiveInsn();
8282bool MipsAsmParser::parseRSectionDirective(StringRef Section) {
8285 reportParseError(
"unexpected token, expected end of statement");
8289 MCSection *ELFSection =
getContext().getELFSection(
8291 getParser().getStreamer().switchSection(ELFSection);
8300bool MipsAsmParser::parseSSectionDirective(StringRef Section,
unsigned Type) {
8303 reportParseError(
"unexpected token, expected end of statement");
8307 MCSection *ELFSection =
getContext().getELFSection(
8309 getParser().getStreamer().switchSection(ELFSection);
8328bool MipsAsmParser::parseDirectiveModule() {
8329 MCAsmParser &Parser = getParser();
8330 AsmLexer &Lexer = getLexer();
8333 if (!getTargetStreamer().isModuleDirectiveAllowed()) {
8335 reportParseError(
".module directive must appear before any code");
8341 reportParseError(
"expected .module option identifier");
8345 if (Option ==
"oddspreg") {
8346 clearModuleFeatureBits(Mips::FeatureNoOddSPReg,
"nooddspreg");
8350 getTargetStreamer().updateABIInfo(*
this);
8355 getTargetStreamer().emitDirectiveModuleOddSPReg();
8359 reportParseError(
"unexpected token, expected end of statement");
8364 }
else if (Option ==
"nooddspreg") {
8366 return Error(L,
"'.module nooddspreg' requires the O32 ABI");
8369 setModuleFeatureBits(Mips::FeatureNoOddSPReg,
"nooddspreg");
8373 getTargetStreamer().updateABIInfo(*
this);
8378 getTargetStreamer().emitDirectiveModuleOddSPReg();
8382 reportParseError(
"unexpected token, expected end of statement");
8387 }
else if (Option ==
"fp") {
8388 return parseDirectiveModuleFP();
8389 }
else if (Option ==
"softfloat") {
8390 setModuleFeatureBits(Mips::FeatureSoftFloat,
"soft-float");
8394 getTargetStreamer().updateABIInfo(*
this);
8399 getTargetStreamer().emitDirectiveModuleSoftFloat();
8403 reportParseError(
"unexpected token, expected end of statement");
8408 }
else if (Option ==
"hardfloat") {
8409 clearModuleFeatureBits(Mips::FeatureSoftFloat,
"soft-float");
8413 getTargetStreamer().updateABIInfo(*
this);
8418 getTargetStreamer().emitDirectiveModuleHardFloat();
8422 reportParseError(
"unexpected token, expected end of statement");
8427 }
else if (Option ==
"mt") {
8428 setModuleFeatureBits(Mips::FeatureMT,
"mt");
8432 getTargetStreamer().updateABIInfo(*
this);
8437 getTargetStreamer().emitDirectiveModuleMT();
8441 reportParseError(
"unexpected token, expected end of statement");
8446 }
else if (Option ==
"crc") {
8447 setModuleFeatureBits(Mips::FeatureCRC,
"crc");
8451 getTargetStreamer().updateABIInfo(*
this);
8456 getTargetStreamer().emitDirectiveModuleCRC();
8460 reportParseError(
"unexpected token, expected end of statement");
8465 }
else if (Option ==
"nocrc") {
8466 clearModuleFeatureBits(Mips::FeatureCRC,
"crc");
8470 getTargetStreamer().updateABIInfo(*
this);
8475 getTargetStreamer().emitDirectiveModuleNoCRC();
8479 reportParseError(
"unexpected token, expected end of statement");
8484 }
else if (Option ==
"virt") {
8485 setModuleFeatureBits(Mips::FeatureVirt,
"virt");
8489 getTargetStreamer().updateABIInfo(*
this);
8494 getTargetStreamer().emitDirectiveModuleVirt();
8498 reportParseError(
"unexpected token, expected end of statement");
8503 }
else if (Option ==
"novirt") {
8504 clearModuleFeatureBits(Mips::FeatureVirt,
"virt");
8508 getTargetStreamer().updateABIInfo(*
this);
8513 getTargetStreamer().emitDirectiveModuleNoVirt();
8517 reportParseError(
"unexpected token, expected end of statement");
8522 }
else if (Option ==
"ginv") {
8523 setModuleFeatureBits(Mips::FeatureGINV,
"ginv");
8527 getTargetStreamer().updateABIInfo(*
this);
8532 getTargetStreamer().emitDirectiveModuleGINV();
8536 reportParseError(
"unexpected token, expected end of statement");
8541 }
else if (Option ==
"noginv") {
8542 clearModuleFeatureBits(Mips::FeatureGINV,
"ginv");
8546 getTargetStreamer().updateABIInfo(*
this);
8551 getTargetStreamer().emitDirectiveModuleNoGINV();
8555 reportParseError(
"unexpected token, expected end of statement");
8561 return Error(L,
"'" + Twine(Option) +
"' is not a valid .module option.");
8569bool MipsAsmParser::parseDirectiveModuleFP() {
8570 MCAsmParser &Parser = getParser();
8571 AsmLexer &Lexer = getLexer();
8574 reportParseError(
"unexpected token, expected equals sign '='");
8580 if (!parseFpABIValue(FpABI,
".module"))
8584 reportParseError(
"unexpected token, expected end of statement");
8590 getTargetStreamer().updateABIInfo(*
this);
8595 getTargetStreamer().emitDirectiveModuleFP();
8602 StringRef Directive) {
8603 MCAsmParser &Parser = getParser();
8604 AsmLexer &Lexer = getLexer();
8605 bool ModuleLevelOptions = Directive ==
".module";
8611 if (
Value !=
"xx") {
8612 reportParseError(
"unsupported value, expected 'xx', '32' or '64'");
8617 reportParseError(
"'" + Directive +
" fp=xx' requires the O32 ABI");
8621 FpABI = MipsABIFlagsSection::FpABIKind::XX;
8622 if (ModuleLevelOptions) {
8623 setModuleFeatureBits(Mips::FeatureFPXX,
"fpxx");
8624 clearModuleFeatureBits(Mips::FeatureFP64Bit,
"fp64");
8626 setFeatureBits(Mips::FeatureFPXX,
"fpxx");
8627 clearFeatureBits(Mips::FeatureFP64Bit,
"fp64");
8637 reportParseError(
"unsupported value, expected 'xx', '32' or '64'");
8643 reportParseError(
"'" + Directive +
" fp=32' requires the O32 ABI");
8647 FpABI = MipsABIFlagsSection::FpABIKind::S32;
8648 if (ModuleLevelOptions) {
8649 clearModuleFeatureBits(Mips::FeatureFPXX,
"fpxx");
8650 clearModuleFeatureBits(Mips::FeatureFP64Bit,
"fp64");
8652 clearFeatureBits(Mips::FeatureFPXX,
"fpxx");
8653 clearFeatureBits(Mips::FeatureFP64Bit,
"fp64");
8656 FpABI = MipsABIFlagsSection::FpABIKind::S64;
8657 if (ModuleLevelOptions) {
8658 clearModuleFeatureBits(Mips::FeatureFPXX,
"fpxx");
8659 setModuleFeatureBits(Mips::FeatureFP64Bit,
"fp64");
8661 clearFeatureBits(Mips::FeatureFPXX,
"fpxx");
8662 setFeatureBits(Mips::FeatureFP64Bit,
"fp64");
8672bool MipsAsmParser::ParseDirective(AsmToken DirectiveID) {
8678 MCAsmParser &Parser = getParser();
8679 StringRef IDVal = DirectiveID.
getString();
8681 if (IDVal ==
".cpadd") {
8682 parseDirectiveCpAdd(DirectiveID.
getLoc());
8685 if (IDVal ==
".cpload") {
8686 parseDirectiveCpLoad(DirectiveID.
getLoc());
8689 if (IDVal ==
".cprestore") {
8690 parseDirectiveCpRestore(DirectiveID.
getLoc());
8693 if (IDVal ==
".cplocal") {
8694 parseDirectiveCpLocal(DirectiveID.
getLoc());
8697 if (IDVal ==
".ent") {
8701 reportParseError(
"expected identifier after .ent");
8715 reportParseError(
"unexpected token, expected end of statement");
8719 const MCExpr *DummyNumber;
8720 int64_t DummyNumberVal;
8724 reportParseError(
"expected number after comma");
8727 if (!DummyNumber->evaluateAsAbsolute(DummyNumberVal)) {
8728 reportParseError(
"expected an absolute expression after comma");
8735 reportParseError(
"unexpected token, expected end of statement");
8741 getTargetStreamer().emitDirectiveEnt(*Sym);
8743 IsCpRestoreSet =
false;
8747 if (IDVal ==
".end") {
8751 reportParseError(
"expected identifier after .end");
8756 reportParseError(
"unexpected token, expected end of statement");
8760 if (CurrentFn ==
nullptr) {
8761 reportParseError(
".end used without .ent");
8765 if ((SymbolName != CurrentFn->
getName())) {
8766 reportParseError(
".end symbol does not match .ent symbol");
8770 getTargetStreamer().emitDirectiveEnd(SymbolName);
8771 CurrentFn =
nullptr;
8772 IsCpRestoreSet =
false;
8776 if (IDVal ==
".frame") {
8779 ParseStatus Res = parseAnyRegister(TmpReg);
8781 reportParseError(
"expected stack register");
8785 MipsOperand &StackRegOpnd =
static_cast<MipsOperand &
>(*TmpReg[0]);
8786 if (!StackRegOpnd.isGPRAsmReg()) {
8787 reportParseError(StackRegOpnd.getStartLoc(),
8788 "expected general purpose register");
8791 MCRegister StackReg = StackRegOpnd.getGPR32Reg();
8796 reportParseError(
"unexpected token, expected comma");
8801 const MCExpr *FrameSize;
8802 int64_t FrameSizeVal;
8805 reportParseError(
"expected frame size value");
8809 if (!FrameSize->evaluateAsAbsolute(FrameSizeVal)) {
8810 reportParseError(
"frame size not an absolute expression");
8817 reportParseError(
"unexpected token, expected comma");
8823 Res = parseAnyRegister(TmpReg);
8825 reportParseError(
"expected return register");
8829 MipsOperand &ReturnRegOpnd =
static_cast<MipsOperand &
>(*TmpReg[0]);
8830 if (!ReturnRegOpnd.isGPRAsmReg()) {
8831 reportParseError(ReturnRegOpnd.getStartLoc(),
8832 "expected general purpose register");
8838 reportParseError(
"unexpected token, expected end of statement");
8842 getTargetStreamer().emitFrame(StackReg, FrameSizeVal,
8843 ReturnRegOpnd.getGPR32Reg());
8844 IsCpRestoreSet =
false;
8848 if (IDVal ==
".set") {
8849 parseDirectiveSet();
8853 if (IDVal ==
".mask" || IDVal ==
".fmask") {
8864 const MCExpr *BitMask;
8868 reportParseError(
"expected bitmask value");
8872 if (!BitMask->evaluateAsAbsolute(BitMaskVal)) {
8873 reportParseError(
"bitmask not an absolute expression");
8880 reportParseError(
"unexpected token, expected comma");
8885 const MCExpr *FrameOffset;
8886 int64_t FrameOffsetVal;
8889 reportParseError(
"expected frame offset value");
8893 if (!FrameOffset->evaluateAsAbsolute(FrameOffsetVal)) {
8894 reportParseError(
"frame offset not an absolute expression");
8900 reportParseError(
"unexpected token, expected end of statement");
8904 if (IDVal ==
".mask")
8905 getTargetStreamer().emitMask(BitMaskVal, FrameOffsetVal);
8907 getTargetStreamer().emitFMask(BitMaskVal, FrameOffsetVal);
8911 if (IDVal ==
".nan")
8912 return parseDirectiveNaN();
8914 if (IDVal ==
".gpword") {
8915 parseDirectiveGpWord();
8919 if (IDVal ==
".gpdword") {
8920 parseDirectiveGpDWord();
8924 if (IDVal ==
".dtprelword") {
8925 parseDirectiveDtpRelWord();
8929 if (IDVal ==
".dtpreldword") {
8930 parseDirectiveDtpRelDWord();
8934 if (IDVal ==
".tprelword") {
8935 parseDirectiveTpRelWord();
8939 if (IDVal ==
".tpreldword") {
8940 parseDirectiveTpRelDWord();
8944 if (IDVal ==
".option") {
8945 parseDirectiveOption();
8949 if (IDVal ==
".abicalls") {
8950 getTargetStreamer().emitDirectiveAbiCalls();
8953 "unexpected token, expected end of statement");
8958 if (IDVal ==
".cpsetup") {
8959 parseDirectiveCPSetup();
8962 if (IDVal ==
".cpreturn") {
8963 parseDirectiveCPReturn();
8966 if (IDVal ==
".module") {
8967 parseDirectiveModule();
8970 if (IDVal ==
".llvm_internal_mips_reallow_module_directive") {
8971 parseInternalDirectiveReallowModule();
8974 if (IDVal ==
".insn") {
8975 parseInsnDirective();
8978 if (IDVal ==
".rdata") {
8979 parseRSectionDirective(
".rodata");
8982 if (IDVal ==
".sbss") {
8986 if (IDVal ==
".sdata") {
8994bool MipsAsmParser::parseInternalDirectiveReallowModule() {
8997 reportParseError(
"unexpected token, expected end of statement");
9001 getTargetStreamer().reallowModuleDirective();
9015#define GET_REGISTER_MATCHER
9016#define GET_MATCHER_IMPLEMENTATION
9017#define GET_MNEMONIC_SPELL_CHECKER
9018#include "MipsGenAsmMatcher.inc"
9020bool MipsAsmParser::mnemonicIsValid(
StringRef Mnemonic,
unsigned VariantID) {
9022 const MatchEntry *Start, *
End;
9023 switch (VariantID) {
9025 case 0: Start = std::begin(MatchTable0);
End = std::end(MatchTable0);
break;
9028 auto MnemonicRange = std::equal_range(Start,
End, Mnemonic, LessOpcode());
9029 return MnemonicRange.first != MnemonicRange.second;
static const TargetRegisterClass * getRegClass(const MachineInstr &MI, Register Reg)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static bool isNot(const MachineRegisterInfo &MRI, const MachineInstr &MI)
This file declares a class to represent arbitrary precision floating point values and provide a varie...
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_EXTERNAL_VISIBILITY
static Value * expandAbs(CallInst *Orig)
std::pair< Instruction::BinaryOps, Value * > OffsetOp
Find all possible pairs (BinOp, RHS) that BinOp V, RHS can be simplified.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
static FeatureBitset getFeatures(MCSubtargetInfo &STI, StringRef CPU, StringRef TuneCPU, StringRef FS, StringTable ProcNames, ArrayRef< SubtargetSubTypeKV > ProcDesc, ArrayRef< SubtargetFeatureKV > ProcFeatures)
static bool hasFeature(StringRef Feature, const FeatureBitset &FeatureBits, ArrayRef< SubtargetFeatureKV > ProcFeatures)
static unsigned countMCSymbolRefExpr(const MCExpr *Expr)
static std::string MipsMnemonicSpellCheck(StringRef S, const FeatureBitset &FBS, unsigned VariantID=0)
static uint64_t convertIntToDoubleImm(uint64_t ImmOp64)
static uint32_t covertDoubleImmToSingleImm(uint64_t ImmOp64)
static unsigned getRegisterForMxtrDSP(MCInst &Inst, bool IsMFDSP)
static bool hasShortDelaySlot(MCInst &Inst)
LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeMipsAsmParser()
static bool needsExpandMemInst(MCInst &Inst, const MCInstrDesc &MCID)
static bool isShiftedUIntAtAnyPosition(uint64_t x)
Can the value be represented by a unsigned N-bit value and a shift left?
static bool isEvaluated(const MCExpr *Expr)
static const MCSymbol * getSingleMCSymbol(const MCExpr *Expr)
static MCRegister nextReg(MCRegister Reg)
static unsigned getRegisterForMxtrFP(MCInst &Inst, bool IsMFTC1)
static SMLoc RefineErrorLoc(const SMLoc Loc, const OperandVector &Operands, uint64_t ErrorInfo)
static MCRegister getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
static bool isReg(const MCInst &MI, unsigned OpNo)
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
MachineRegisterInfo & MRI
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
This file defines the SmallVector class.
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
static bool isMemOperand(const MCInst &MI, unsigned Op, unsigned RegClassID)
static constexpr const fltSemantics & IEEEdouble()
APInt bitcastToAPInt() const
uint64_t getZExtValue() const
Get zero extended value.
SMLoc getLoc() const
Get the current source location.
const AsmToken peekTok(bool ShouldSkipSpace=true)
Look ahead at the next token to be lexed.
bool is(AsmToken::TokenKind K) const
Check if the current token has kind K.
bool isNot(AsmToken::TokenKind K) const
Check if the current token has kind K.
Target independent representation for an assembler token.
LLVM_ABI SMLoc getLoc() const
int64_t getIntVal() const
bool isNot(TokenKind K) const
StringRef getString() const
Get the string for the current token, this includes all characters (for example, the quotes on string...
bool is(TokenKind K) const
TokenKind getKind() const
LLVM_ABI SMRange getLocRange() const
StringRef getIdentifier() const
Get the identifier string for the current token, which should be an identifier or a string.
Base class for user error types.
Container class for subtarget features.
void printExpr(raw_ostream &, const MCExpr &) const
virtual void Initialize(MCAsmParser &Parser)
Initialize the extension for parsing using the given Parser.
virtual void eatToEndOfStatement()=0
Skip to the end of the current statement, for error recovery.
bool parseToken(AsmToken::TokenKind T, const Twine &Msg="unexpected token")
virtual bool parseExpression(const MCExpr *&Res, SMLoc &EndLoc)=0
Parse an arbitrary expression.
const AsmToken & getTok() const
Get the current AsmToken from the stream.
virtual bool parseIdentifier(StringRef &Res)=0
Parse an identifier or string (as a quoted identifier) and set Res to the identifier contents.
virtual const AsmToken & Lex()=0
Get the next AsmToken in the stream, possibly handling file inclusion first.
virtual void addAliasForDirective(StringRef Directive, StringRef Alias)=0
Binary assembler expressions.
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Base class for the full range of assembler expressions which are needed for parsing.
LLVM_ABI bool evaluateAsRelocatable(MCValue &Res, const MCAssembler *Asm) const
Try to evaluate the expression to a relocatable value, i.e.
@ Unary
Unary expressions.
@ Constant
Constant expressions.
@ SymbolRef
References to labels and assigned expressions.
@ Target
Target specific expression.
@ Specifier
Expression with a relocation specifier.
@ Binary
Binary expressions.
Instances of this class represent a single low-level machine instruction.
unsigned getNumOperands() const
unsigned getOpcode() const
void addOperand(const MCOperand Op)
void setOpcode(unsigned Op)
const MCOperand & getOperand(unsigned i) const
Describe properties that are true of each instruction in the target description file.
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
ArrayRef< MCOperandInfo > operands() const
bool mayStore() const
Return true if this instruction could possibly modify memory.
bool mayLoad() const
Return true if this instruction could possibly read memory.
bool isBranch() const
Returns true if this is a conditional, unconditional, or indirect branch.
bool isCall() const
Return true if the instruction is a call.
bool hasDelaySlot() const
Returns true if the specified instruction has a delay slot which must be filled by the code generator...
Interface to description of machine instruction set.
This holds information about one operand of a machine instruction, indicating the register class for ...
uint8_t OperandType
Information about the type of the operand.
Instances of this class represent operands of the MCInst class.
static MCOperand createExpr(const MCExpr *Val)
static MCOperand createReg(MCRegister Reg)
static MCOperand createImm(int64_t Val)
MCRegister getReg() const
Returns the register number.
const MCExpr * getExpr() const
MCParsedAsmOperand - This abstract class represents a source-level assembly instruction operand.
virtual bool isReg() const =0
isReg - Is this a register operand?
virtual MCRegister getReg() const =0
MCRegister getRegister(unsigned i) const
getRegister - Return the specified register in the class.
Wrapper class representing physical registers. Should be passed by value.
constexpr bool isValid() const
constexpr unsigned id() const
static const MCSpecifierExpr * create(const MCExpr *Expr, Spec S, MCContext &Ctx, SMLoc Loc=SMLoc())
Streaming machine code generation interface.
virtual void emitRelocDirective(const MCExpr &Offset, StringRef Name, const MCExpr *Expr, SMLoc Loc={})
Record a relocation described by the .reloc directive.
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
Generic base class for all target subtargets.
bool hasFeature(unsigned Feature) const
void setFeatureBits(const FeatureBitset &FeatureBits_)
const Triple & getTargetTriple() const
const FeatureBitset & getFeatureBits() const
const FeatureBitset & ToggleFeature(uint64_t FB)
Toggle a feature and return the re-computed feature bits.
virtual unsigned getHwMode(enum HwModeType type=HwMode_Default) const
HwMode ID corresponding to the 'type' parameter is retrieved from the HwMode bit set of the current s...
Represent a reference to a symbol from inside an expression.
uint16_t getSpecifier() const
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
bool isInSection() const
isInSection - Check if this symbol is defined in some section (i.e., it is defined but not absolute).
bool isUndefined() const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
StringRef getName() const
getName - Get the symbol name.
bool isVariable() const
isVariable - Check if this is a variable symbol.
const MCExpr * getVariableValue() const
Get the expression of the variable symbol.
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
MCTargetAsmParser - Generic interface to target specific assembly parsers.
MCStreamer & getStreamer()
Unary assembler expressions.
const MCSymbol * getAddSym() const
int64_t getConstant() const
const MCSymbol * getSubSym() const
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
static const char * getRegisterName(MCRegister Reg, unsigned AltIdx=Mips::NoRegAltName)
void emitRRX(unsigned Opcode, MCRegister Reg0, MCRegister Reg1, MCOperand Op2, SMLoc IDLoc, const MCSubtargetInfo *STI)
virtual void emitDirectiveSetReorder()
void emitRRRX(unsigned Opcode, MCRegister Reg0, MCRegister Reg1, MCRegister Reg2, MCOperand Op3, SMLoc IDLoc, const MCSubtargetInfo *STI)
void emitRX(unsigned Opcode, MCRegister Reg0, MCOperand Op1, SMLoc IDLoc, const MCSubtargetInfo *STI)
void emitR(unsigned Opcode, MCRegister Reg0, SMLoc IDLoc, const MCSubtargetInfo *STI)
virtual void setUsesMicroMips()
void emitRRI(unsigned Opcode, MCRegister Reg0, MCRegister Reg1, int16_t Imm, SMLoc IDLoc, const MCSubtargetInfo *STI)
void emitEmptyDelaySlot(bool hasShortDelaySlot, SMLoc IDLoc, const MCSubtargetInfo *STI)
void emitRI(unsigned Opcode, MCRegister Reg0, int32_t Imm, SMLoc IDLoc, const MCSubtargetInfo *STI)
void emitII(unsigned Opcode, int16_t Imm1, int16_t Imm2, SMLoc IDLoc, const MCSubtargetInfo *STI)
void emitRR(unsigned Opcode, MCRegister Reg0, MCRegister Reg1, SMLoc IDLoc, const MCSubtargetInfo *STI)
void updateABIInfo(const PredicateLibrary &P)
void emitRRIII(unsigned Opcode, MCRegister Reg0, MCRegister Reg1, int16_t Imm0, int16_t Imm1, int16_t Imm2, SMLoc IDLoc, const MCSubtargetInfo *STI)
void emitDSLL(MCRegister DstReg, MCRegister SrcReg, int16_t ShiftAmount, SMLoc IDLoc, const MCSubtargetInfo *STI)
void emitGPRestore(int Offset, SMLoc IDLoc, const MCSubtargetInfo *STI)
Emit the $gp restore operation for .cprestore.
void emitNop(SMLoc IDLoc, const MCSubtargetInfo *STI)
void emitRRR(unsigned Opcode, MCRegister Reg0, MCRegister Reg1, MCRegister Reg2, SMLoc IDLoc, const MCSubtargetInfo *STI)
virtual void emitDirectiveSetNoReorder()
Ternary parse status returned by various parse* methods.
constexpr bool isFailure() const
static constexpr StatusTy Failure
constexpr bool isSuccess() const
static constexpr StatusTy Success
static constexpr StatusTy NoMatch
constexpr bool isNoMatch() const
constexpr unsigned id() const
Represents a location in source code.
static SMLoc getFromPointer(const char *Ptr)
constexpr const char * getPointer() const
void push_back(const T &Elt)
LLVM_NO_SANITIZE_CFI_UNRELATED_CAST iterator begin()
iterator find(StringRef Key)
Represent a constant reference to a string, i.e.
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr bool empty() const
Check if the string is empty.
LLVM_ABI bool isLittleEndian() const
Tests whether the target triple is little endian.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
const AArch64MCOptions & getCLOpts(const MCTargetOptions &Options)
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
LLVM_ABI LLVM_READONLY ARMABI computeTargetABI(const Triple &TT, StringRef ABIName="")
LLVM_ABI bool parseAssignmentExpression(StringRef Name, bool allow_redef, MCAsmParser &Parser, MCSymbol *&Symbol, const MCExpr *&Value)
Parse a value expression and return whether it can be assigned to a symbol with the given name.
constexpr unsigned encodeCOP0Register(unsigned Reg, unsigned Sel)
COP0 hardware encodings reserve five bits each for REG and SEL.
MCRegister getCOP0Register(const MCRegisterInfo &MRI, unsigned Encoding)
MCRegister matchRegisterName(StringRef Name, const MCRegisterInfo &MRI, unsigned RegClassID, unsigned AltIdx)
Match a symbolic name in RegClassID, or return an invalid register.
constexpr unsigned getCOP0RegNum(unsigned Encoding)
int getCPURegisterIndex(StringRef Name, const MCRegisterInfo &MRI, unsigned AltIdx, bool *IsDeprecated=nullptr)
Return a GPR name's hardware index, or -1 if unknown.
constexpr unsigned getCOP0Sel(unsigned Encoding)
constexpr MCPhysReg FP_64
constexpr MCPhysReg GP_64
constexpr MCPhysReg RA_64
constexpr MCPhysReg SP_64
WebAssemblyABI getABI(StringRef Name)
Parse an ABI name into the corresponding enum.
@ CE
Windows NT (Windows on ARM)
LLVM_ABI TargetOptions getTargetOptions(const cl::LibraryOptionsContext &LibraryOptions, const llvm::Triple &TheTriple)
Common utility function tightly tied to the options listed here.
LLVM_ABI StringRef getABIName(const cl::LibraryOptionsContext &C)
BaseReg
Stack frame base register. Bit 0 of FREInfo.Info.
unsigned getOpcode(const VPValue *V)
Return the instruction opcode for the recipe defining V or 0 for unsupported recipes and VPValues not...
This is an optimization pass for GlobalISel generic memory operations.
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr, unsigned DynamicVGPRBlockSize=0)
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
Target & getTheMips64Target()
static bool isMem(const MachineInstr &MI, unsigned Op)
LLVM_ABI std::pair< StringRef, StringRef > getToken(StringRef Source, StringRef Delimiters=" \t\n\v\f\r")
getToken - This function extracts one token from source, ignoring any leading characters that appear ...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
static StringRef getCPU(StringRef CPU)
Processes a CPU name.
int bit_width(T Value)
Returns the number of bits needed to represent Value if Value is nonzero.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
SmallVectorImpl< std::unique_ptr< MCParsedAsmOperand > > OperandVector
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
constexpr uint32_t Hi_32(uint64_t Value)
Return the high 32 bits of a 64 bit value.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
constexpr uint32_t Lo_32(uint64_t Value)
Return the low 32 bits of a 64 bit value.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
@ Success
The lock was released successfully.
Target & getTheMips64elTarget()
uint64_t offsetToAlignment(uint64_t Value, Align Alignment)
Returns the offset to the next integer (mod 2**64) that is greater than or equal to Value and is a mu...
@ Ref
The access may reference the value stored in memory.
To bit_cast(const From &from) noexcept
Target & getTheMipselTarget()
DWARFExpression::Operation Op
constexpr bool isShiftedInt(int64_t x)
Checks if a signed integer is an N bit number shifted left by S.
constexpr unsigned BitWidth
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
constexpr bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
static uint16_t getSpecifier(const MCSymbolRefExpr *SRE)
constexpr int64_t SignExtend64(uint64_t x)
Sign-extend the number in the bottom B bits of X to a 64-bit integer.
Target & getTheMipsTarget()
@ End
Run the machine verifier once, at the end of the pipeline.
constexpr bool isShiftedUInt(uint64_t x)
Checks if a unsigned integer is an N bit number shifted left by S.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
RegisterMCAsmParser - Helper template for registering a target specific assembly parser,...