62 #define DEBUG_TYPE "mips-asm-parser" 74 class MipsAssemblerOptions {
76 MipsAssemblerOptions(
const FeatureBitset &Features_) : Features(Features_) {}
78 MipsAssemblerOptions(
const MipsAssemblerOptions *Opts) {
79 ATReg = Opts->getATRegIndex();
80 Reorder = Opts->isReorder();
81 Macro = Opts->isMacro();
82 Features = Opts->getFeatures();
85 unsigned getATRegIndex()
const {
return ATReg; }
86 bool setATRegIndex(
unsigned Reg) {
94 bool isReorder()
const {
return Reorder; }
95 void setReorder() { Reorder =
true; }
96 void setNoReorder() { Reorder =
false; }
98 bool isMacro()
const {
return Macro; }
99 void setMacro() {
Macro =
true; }
100 void setNoMacro() {
Macro =
false; }
103 void setFeatures(
const FeatureBitset &Features_) { Features = Features_; }
121 const FeatureBitset MipsAssemblerOptions::AllArchRelatedMask = {
122 Mips::FeatureMips1, Mips::FeatureMips2, Mips::FeatureMips3,
123 Mips::FeatureMips3_32, Mips::FeatureMips3_32r2, Mips::FeatureMips4,
124 Mips::FeatureMips4_32, Mips::FeatureMips4_32r2, Mips::FeatureMips5,
125 Mips::FeatureMips5_32r2, Mips::FeatureMips32, Mips::FeatureMips32r2,
126 Mips::FeatureMips32r3, Mips::FeatureMips32r5, Mips::FeatureMips32r6,
127 Mips::FeatureMips64, Mips::FeatureMips64r2, Mips::FeatureMips64r3,
128 Mips::FeatureMips64r5, Mips::FeatureMips64r6, Mips::FeatureCnMips,
129 Mips::FeatureCnMipsP, Mips::FeatureFP64Bit, Mips::FeatureGP64Bit,
137 assert(getParser().getStreamer().getTargetStreamer() &&
138 "do not have a target streamer");
154 unsigned CpSaveLocation;
156 bool CpSaveLocationIsRegister;
162 void printWarningWithFixIt(
const Twine &Msg,
const Twine &FixMsg,
163 SMRange Range,
bool ShowColors =
true);
167 #define GET_ASSEMBLER_HEADER 168 #include "MipsGenAsmMatcher.inc" 171 checkEarlyTargetMatchPredicate(
MCInst &Inst,
173 unsigned checkTargetMatchPredicate(
MCInst &Inst)
override;
175 bool MatchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
178 bool MatchingInlineAsm)
override;
181 bool ParseRegister(
unsigned &RegNo,
SMLoc &StartLoc,
SMLoc &EndLoc)
override;
187 bool mnemonicIsValid(
StringRef Mnemonic,
unsigned VariantID);
192 bool ParseDirective(
AsmToken DirectiveID)
override;
213 enum MacroExpanderResultTy {
220 MacroExpanderResultTy tryExpandInstruction(
MCInst &Inst,
SMLoc IDLoc,
227 bool loadImmediate(int64_t ImmValue,
unsigned DstReg,
unsigned SrcReg,
228 bool Is32BitImm,
bool IsAddress,
SMLoc IDLoc,
231 bool loadAndAddSymbolAddress(
const MCExpr *SymExpr,
unsigned DstReg,
232 unsigned SrcReg,
bool Is32BitSym,
SMLoc IDLoc,
237 bool expandLoadImm(
MCInst &Inst,
bool Is32BitImm,
SMLoc IDLoc,
246 bool expandLoadDoubleImmToFPR(
MCInst &Inst,
bool Is64FPU,
SMLoc IDLoc,
249 bool expandLoadAddress(
unsigned DstReg,
unsigned BaseReg,
278 bool expandTrunc(
MCInst &Inst,
bool IsDouble,
bool Is64FPU,
SMLoc IDLoc,
341 bool reportParseError(
Twine ErrorMsg);
342 bool reportParseError(
SMLoc Loc,
Twine ErrorMsg);
344 bool parseMemOffset(
const MCExpr *&Res,
bool isParenExpr);
346 bool parseSetMips0Directive();
347 bool parseSetArchDirective();
348 bool parseSetFeature(uint64_t Feature);
349 bool isPicAndNotNxxAbi();
350 bool parseDirectiveCpLoad(
SMLoc Loc);
351 bool parseDirectiveCpLocal(
SMLoc Loc);
352 bool parseDirectiveCpRestore(
SMLoc Loc);
353 bool parseDirectiveCPSetup();
354 bool parseDirectiveCPReturn();
355 bool parseDirectiveNaN();
356 bool parseDirectiveSet();
357 bool parseDirectiveOption();
358 bool parseInsnDirective();
362 bool parseSetAtDirective();
363 bool parseSetNoAtDirective();
364 bool parseSetMacroDirective();
365 bool parseSetNoMacroDirective();
366 bool parseSetMsaDirective();
367 bool parseSetNoMsaDirective();
368 bool parseSetNoDspDirective();
369 bool parseSetReorderDirective();
370 bool parseSetNoReorderDirective();
371 bool parseSetMips16Directive();
372 bool parseSetNoMips16Directive();
373 bool parseSetFpDirective();
374 bool parseSetOddSPRegDirective();
375 bool parseSetNoOddSPRegDirective();
376 bool parseSetPopDirective();
377 bool parseSetPushDirective();
378 bool parseSetSoftFloatDirective();
379 bool parseSetHardFloatDirective();
380 bool parseSetMtDirective();
381 bool parseSetNoMtDirective();
382 bool parseSetNoCRCDirective();
383 bool parseSetNoVirtDirective();
384 bool parseSetNoGINVDirective();
386 bool parseSetAssignment();
388 bool parseDirectiveGpWord();
389 bool parseDirectiveGpDWord();
390 bool parseDirectiveDtpRelWord();
391 bool parseDirectiveDtpRelDWord();
392 bool parseDirectiveTpRelWord();
393 bool parseDirectiveTpRelDWord();
394 bool parseDirectiveModule();
395 bool parseDirectiveModuleFP();
399 bool parseInternalDirectiveReallowModule();
417 unsigned getReg(
int RC,
int RegNo);
422 unsigned getATReg(
SMLoc Loc);
432 bool validateMSAIndex(
int Val,
int RegKind);
459 FeatureBits &= ~MipsAssemblerOptions::AllArchRelatedMask;
461 setAvailableFeatures(
466 void setFeatureBits(uint64_t Feature,
StringRef FeatureString) {
467 if (!(getSTI().getFeatureBits()[Feature])) {
469 setAvailableFeatures(
475 void clearFeatureBits(uint64_t Feature,
StringRef FeatureString) {
476 if (getSTI().getFeatureBits()[Feature]) {
478 setAvailableFeatures(
484 void setModuleFeatureBits(uint64_t Feature,
StringRef FeatureString) {
485 setFeatureBits(Feature, FeatureString);
486 AssemblerOptions.
front()->setFeatures(getSTI().getFeatureBits());
489 void clearModuleFeatureBits(uint64_t Feature,
StringRef FeatureString) {
490 clearFeatureBits(Feature, FeatureString);
491 AssemblerOptions.
front()->setFeatures(getSTI().getFeatureBits());
495 enum MipsMatchResultTy {
496 Match_RequiresDifferentSrcAndDst = FIRST_TARGET_MATCH_RESULT_TY,
497 Match_RequiresDifferentOperands,
498 Match_RequiresNoZeroRegister,
499 Match_RequiresSameSrcAndDst,
500 Match_NoFCCRegisterForCurrentISA,
501 Match_NonZeroOperandForSync,
502 Match_NonZeroOperandForMTCX,
503 Match_RequiresPosSizeRange0_32,
504 Match_RequiresPosSizeRange33_64,
505 Match_RequiresPosSizeUImm6,
506 #define GET_OPERAND_DIAGNOSTIC_TYPES 507 #include "MipsGenAsmMatcher.inc" 508 #undef GET_OPERAND_DIAGNOSTIC_TYPES 524 setAvailableFeatures(ComputeAvailableFeatures(getSTI().getFeatureBits()));
528 std::make_unique<MipsAssemblerOptions>(getSTI().getFeatureBits()));
532 std::make_unique<MipsAssemblerOptions>(getSTI().getFeatureBits()));
534 getTargetStreamer().updateABIInfo(*
this);
536 if (!isABI_O32() && !useOddSPReg() != 0)
541 IsPicEnabled = getContext().getObjectFileInfo()->isPositionIndependent();
543 IsCpRestoreSet =
false;
544 CpRestoreOffset = -1;
550 if (getSTI().
getCPU() ==
"mips64r6" && inMicroMipsMode())
553 if (!isABI_O32() && inMicroMipsMode())
558 bool hasEightFccRegisters()
const {
return hasMips4() || hasMips32(); }
560 bool isGP64bit()
const {
561 return getSTI().getFeatureBits()[Mips::FeatureGP64Bit];
564 bool isFP64bit()
const {
565 return getSTI().getFeatureBits()[Mips::FeatureFP64Bit];
568 bool isJalrRelocAvailable(
const MCExpr *JalExpr) {
582 bool isABI_N32()
const {
return ABI.
IsN32(); }
583 bool isABI_N64()
const {
return ABI.
IsN64(); }
584 bool isABI_O32()
const {
return ABI.
IsO32(); }
585 bool isABI_FPXX()
const {
586 return getSTI().getFeatureBits()[Mips::FeatureFPXX];
589 bool useOddSPReg()
const {
590 return !(getSTI().getFeatureBits()[Mips::FeatureNoOddSPReg]);
593 bool inMicroMipsMode()
const {
594 return getSTI().getFeatureBits()[Mips::FeatureMicroMips];
597 bool hasMips1()
const {
598 return getSTI().getFeatureBits()[Mips::FeatureMips1];
601 bool hasMips2()
const {
602 return getSTI().getFeatureBits()[Mips::FeatureMips2];
605 bool hasMips3()
const {
606 return getSTI().getFeatureBits()[Mips::FeatureMips3];
609 bool hasMips4()
const {
610 return getSTI().getFeatureBits()[Mips::FeatureMips4];
613 bool hasMips5()
const {
614 return getSTI().getFeatureBits()[Mips::FeatureMips5];
617 bool hasMips32()
const {
618 return getSTI().getFeatureBits()[Mips::FeatureMips32];
621 bool hasMips64()
const {
622 return getSTI().getFeatureBits()[Mips::FeatureMips64];
625 bool hasMips32r2()
const {
626 return getSTI().getFeatureBits()[Mips::FeatureMips32r2];
629 bool hasMips64r2()
const {
630 return getSTI().getFeatureBits()[Mips::FeatureMips64r2];
633 bool hasMips32r3()
const {
634 return (getSTI().getFeatureBits()[Mips::FeatureMips32r3]);
637 bool hasMips64r3()
const {
638 return (getSTI().getFeatureBits()[Mips::FeatureMips64r3]);
641 bool hasMips32r5()
const {
642 return (getSTI().getFeatureBits()[Mips::FeatureMips32r5]);
645 bool hasMips64r5()
const {
646 return (getSTI().getFeatureBits()[Mips::FeatureMips64r5]);
649 bool hasMips32r6()
const {
650 return getSTI().getFeatureBits()[Mips::FeatureMips32r6];
653 bool hasMips64r6()
const {
654 return getSTI().getFeatureBits()[Mips::FeatureMips64r6];
657 bool hasDSP()
const {
658 return getSTI().getFeatureBits()[Mips::FeatureDSP];
661 bool hasDSPR2()
const {
662 return getSTI().getFeatureBits()[Mips::FeatureDSPR2];
665 bool hasDSPR3()
const {
666 return getSTI().getFeatureBits()[Mips::FeatureDSPR3];
669 bool hasMSA()
const {
670 return getSTI().getFeatureBits()[Mips::FeatureMSA];
673 bool hasCnMips()
const {
674 return (getSTI().getFeatureBits()[Mips::FeatureCnMips]);
677 bool hasCnMipsP()
const {
678 return (getSTI().getFeatureBits()[Mips::FeatureCnMipsP]);
685 bool inMips16Mode()
const {
686 return getSTI().getFeatureBits()[Mips::FeatureMips16];
689 bool useTraps()
const {
690 return getSTI().getFeatureBits()[Mips::FeatureUseTCCInDIV];
693 bool useSoftFloat()
const {
694 return getSTI().getFeatureBits()[Mips::FeatureSoftFloat];
697 return getSTI().getFeatureBits()[Mips::FeatureMT];
700 bool hasCRC()
const {
701 return getSTI().getFeatureBits()[Mips::FeatureCRC];
704 bool hasVirt()
const {
705 return getSTI().getFeatureBits()[Mips::FeatureVirt];
708 bool hasGINV()
const {
709 return getSTI().getFeatureBits()[Mips::FeatureGINV];
713 void warnIfRegIndexIsAT(
unsigned RegIndex,
SMLoc Loc);
715 void warnIfNoMacro(
SMLoc Loc);
717 bool isLittle()
const {
return IsLittleEndian; }
722 switch(OperatorToken) {
790 RegKind_MSACtrl = 16,
795 RegKind_HWRegs = 256,
799 RegKind_Numeric = RegKind_GPR | RegKind_FGR | RegKind_FCC | RegKind_MSA128 |
800 RegKind_MSACtrl | RegKind_COP2 | RegKind_ACC |
801 RegKind_CCR | RegKind_HWRegs | RegKind_COP3 | RegKind_COP0
814 MipsOperand(KindTy K, MipsAsmParser &Parser)
817 ~MipsOperand()
override {
826 case k_RegisterIndex:
834 MipsAsmParser &AsmParser;
863 struct RegIdxOp RegIdx;
866 struct RegListOp RegList;
869 SMLoc StartLoc, EndLoc;
872 static std::unique_ptr<MipsOperand> CreateReg(
unsigned Index,
StringRef Str,
876 MipsAsmParser &Parser) {
877 auto Op = std::make_unique<MipsOperand>(k_RegisterIndex, Parser);
879 Op->RegIdx.RegInfo = RegInfo;
881 Op->RegIdx.Tok.Data = Str.
data();
882 Op->RegIdx.Tok.Length = Str.
size();
891 unsigned getGPR32Reg()
const {
892 assert(isRegIdx() && (RegIdx.Kind & RegKind_GPR) &&
"Invalid access!");
893 AsmParser.warnIfRegIndexIsAT(RegIdx.Index, StartLoc);
894 unsigned ClassID = Mips::GPR32RegClassID;
895 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
900 unsigned getGPRMM16Reg()
const {
901 assert(isRegIdx() && (RegIdx.Kind & RegKind_GPR) &&
"Invalid access!");
902 unsigned ClassID = Mips::GPR32RegClassID;
903 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
908 unsigned getGPR64Reg()
const {
909 assert(isRegIdx() && (RegIdx.Kind & RegKind_GPR) &&
"Invalid access!");
910 unsigned ClassID = Mips::GPR64RegClassID;
911 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
917 unsigned getAFGR64Reg()
const {
918 assert(isRegIdx() && (RegIdx.Kind & RegKind_FGR) &&
"Invalid access!");
919 if (RegIdx.Index % 2 != 0)
920 AsmParser.Warning(StartLoc,
"Float register should be even.");
921 return RegIdx.RegInfo->getRegClass(Mips::AFGR64RegClassID)
922 .getRegister(RegIdx.Index / 2);
927 unsigned getFGR64Reg()
const {
928 assert(isRegIdx() && (RegIdx.Kind & RegKind_FGR) &&
"Invalid access!");
929 return RegIdx.RegInfo->getRegClass(Mips::FGR64RegClassID)
930 .getRegister(RegIdx.Index);
935 unsigned getFGR32Reg()
const {
936 assert(isRegIdx() && (RegIdx.Kind & RegKind_FGR) &&
"Invalid access!");
937 return RegIdx.RegInfo->getRegClass(Mips::FGR32RegClassID)
938 .getRegister(RegIdx.Index);
943 unsigned getFCCReg()
const {
944 assert(isRegIdx() && (RegIdx.Kind & RegKind_FCC) &&
"Invalid access!");
945 return RegIdx.RegInfo->getRegClass(Mips::FCCRegClassID)
946 .getRegister(RegIdx.Index);
951 unsigned getMSA128Reg()
const {
952 assert(isRegIdx() && (RegIdx.Kind & RegKind_MSA128) &&
"Invalid access!");
955 unsigned ClassID = Mips::MSA128BRegClassID;
956 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
961 unsigned getMSACtrlReg()
const {
962 assert(isRegIdx() && (RegIdx.Kind & RegKind_MSACtrl) &&
"Invalid access!");
963 unsigned ClassID = Mips::MSACtrlRegClassID;
964 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
969 unsigned getCOP0Reg()
const {
970 assert(isRegIdx() && (RegIdx.Kind & RegKind_COP0) &&
"Invalid access!");
971 unsigned ClassID = Mips::COP0RegClassID;
972 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
977 unsigned getCOP2Reg()
const {
978 assert(isRegIdx() && (RegIdx.Kind & RegKind_COP2) &&
"Invalid access!");
979 unsigned ClassID = Mips::COP2RegClassID;
980 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
985 unsigned getCOP3Reg()
const {
986 assert(isRegIdx() && (RegIdx.Kind & RegKind_COP3) &&
"Invalid access!");
987 unsigned ClassID = Mips::COP3RegClassID;
988 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
993 unsigned getACC64DSPReg()
const {
994 assert(isRegIdx() && (RegIdx.Kind & RegKind_ACC) &&
"Invalid access!");
995 unsigned ClassID = Mips::ACC64DSPRegClassID;
996 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
1001 unsigned getHI32DSPReg()
const {
1002 assert(isRegIdx() && (RegIdx.Kind & RegKind_ACC) &&
"Invalid access!");
1003 unsigned ClassID = Mips::HI32DSPRegClassID;
1004 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
1009 unsigned getLO32DSPReg()
const {
1010 assert(isRegIdx() && (RegIdx.Kind & RegKind_ACC) &&
"Invalid access!");
1011 unsigned ClassID = Mips::LO32DSPRegClassID;
1012 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
1017 unsigned getCCRReg()
const {
1018 assert(isRegIdx() && (RegIdx.Kind & RegKind_CCR) &&
"Invalid access!");
1019 unsigned ClassID = Mips::CCRRegClassID;
1020 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
1025 unsigned getHWRegsReg()
const {
1026 assert(isRegIdx() && (RegIdx.Kind & RegKind_HWRegs) &&
"Invalid access!");
1027 unsigned ClassID = Mips::HWRegsRegClassID;
1028 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
1036 else if (
const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
1042 void addRegOperands(
MCInst &Inst,
unsigned N)
const {
1049 void addGPR32ZeroAsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1050 assert(N == 1 &&
"Invalid number of operands!");
1054 void addGPR32NonZeroAsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1055 assert(N == 1 &&
"Invalid number of operands!");
1059 void addGPR32AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1060 assert(N == 1 &&
"Invalid number of operands!");
1064 void addGPRMM16AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1065 assert(N == 1 &&
"Invalid number of operands!");
1069 void addGPRMM16AsmRegZeroOperands(
MCInst &Inst,
unsigned N)
const {
1070 assert(N == 1 &&
"Invalid number of operands!");
1074 void addGPRMM16AsmRegMovePOperands(
MCInst &Inst,
unsigned N)
const {
1075 assert(N == 1 &&
"Invalid number of operands!");
1079 void addGPRMM16AsmRegMovePPairFirstOperands(
MCInst &Inst,
unsigned N)
const {
1080 assert(N == 1 &&
"Invalid number of operands!");
1084 void addGPRMM16AsmRegMovePPairSecondOperands(
MCInst &Inst,
1086 assert(N == 1 &&
"Invalid number of operands!");
1093 void addGPR64AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1094 assert(N == 1 &&
"Invalid number of operands!");
1098 void addAFGR64AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1099 assert(N == 1 &&
"Invalid number of operands!");
1103 void addStrictlyAFGR64AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1104 assert(N == 1 &&
"Invalid number of operands!");
1108 void addStrictlyFGR64AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1109 assert(N == 1 &&
"Invalid number of operands!");
1113 void addFGR64AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1114 assert(N == 1 &&
"Invalid number of operands!");
1118 void addFGR32AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1119 assert(N == 1 &&
"Invalid number of operands!");
1123 if (!AsmParser.useOddSPReg() && RegIdx.Index & 1)
1124 AsmParser.getParser().printError(
1125 StartLoc,
"-mno-odd-spreg prohibits the use of odd FPU " 1129 void addStrictlyFGR32AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1130 assert(N == 1 &&
"Invalid number of operands!");
1133 if (!AsmParser.useOddSPReg() && RegIdx.Index & 1)
1134 AsmParser.Error(StartLoc,
"-mno-odd-spreg prohibits the use of odd FPU " 1138 void addFCCAsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1139 assert(N == 1 &&
"Invalid number of operands!");
1143 void addMSA128AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1144 assert(N == 1 &&
"Invalid number of operands!");
1148 void addMSACtrlAsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1149 assert(N == 1 &&
"Invalid number of operands!");
1153 void addCOP0AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1154 assert(N == 1 &&
"Invalid number of operands!");
1158 void addCOP2AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1159 assert(N == 1 &&
"Invalid number of operands!");
1163 void addCOP3AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1164 assert(N == 1 &&
"Invalid number of operands!");
1168 void addACC64DSPAsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1169 assert(N == 1 &&
"Invalid number of operands!");
1173 void addHI32DSPAsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1174 assert(N == 1 &&
"Invalid number of operands!");
1178 void addLO32DSPAsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1179 assert(N == 1 &&
"Invalid number of operands!");
1183 void addCCRAsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1184 assert(N == 1 &&
"Invalid number of operands!");
1188 void addHWRegsAsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1189 assert(N == 1 &&
"Invalid number of operands!");
1193 template <
unsigned Bits,
int Offset = 0,
int AdjustOffset = 0>
1194 void addConstantUImmOperands(
MCInst &Inst,
unsigned N)
const {
1195 assert(N == 1 &&
"Invalid number of operands!");
1196 uint64_t Imm = getConstantImm() -
Offset;
1197 Imm &= (1ULL <<
Bits) - 1;
1199 Imm += AdjustOffset;
1203 template <
unsigned Bits>
1204 void addSImmOperands(
MCInst &Inst,
unsigned N)
const {
1205 if (isImm() && !isConstantImm()) {
1206 addExpr(Inst, getImm());
1209 addConstantSImmOperands<Bits, 0, 0>(Inst,
N);
1212 template <
unsigned Bits>
1213 void addUImmOperands(
MCInst &Inst,
unsigned N)
const {
1214 if (isImm() && !isConstantImm()) {
1215 addExpr(Inst, getImm());
1218 addConstantUImmOperands<Bits, 0, 0>(Inst,
N);
1221 template <
unsigned Bits,
int Offset = 0,
int AdjustOffset = 0>
1222 void addConstantSImmOperands(
MCInst &Inst,
unsigned N)
const {
1223 assert(N == 1 &&
"Invalid number of operands!");
1224 int64_t Imm = getConstantImm() -
Offset;
1225 Imm = SignExtend64<Bits>(Imm);
1227 Imm += AdjustOffset;
1231 void addImmOperands(
MCInst &Inst,
unsigned N)
const {
1232 assert(N == 1 &&
"Invalid number of operands!");
1233 const MCExpr *Expr = getImm();
1234 addExpr(Inst, Expr);
1237 void addMemOperands(
MCInst &Inst,
unsigned N)
const {
1238 assert(N == 2 &&
"Invalid number of operands!");
1241 ? getMemBase()->getGPR64Reg()
1242 : getMemBase()->getGPR32Reg()));
1244 const MCExpr *Expr = getMemOff();
1245 addExpr(Inst, Expr);
1248 void addMicroMipsMemOperands(
MCInst &Inst,
unsigned N)
const {
1249 assert(N == 2 &&
"Invalid number of operands!");
1253 const MCExpr *Expr = getMemOff();
1254 addExpr(Inst, Expr);
1257 void addRegListOperands(
MCInst &Inst,
unsigned N)
const {
1258 assert(N == 1 &&
"Invalid number of operands!");
1260 for (
auto RegNo : getRegList())
1264 bool isReg()
const override {
1267 return isGPRAsmReg() && RegIdx.Index == 0;
1270 bool isRegIdx()
const {
return Kind == k_RegisterIndex; }
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 {
1283 return isConstantImm() && isUInt<Bits>(getConstantImm() -
Offset);
1286 template <
unsigned Bits>
bool isSImm()
const {
1287 return isConstantImm() ? isInt<Bits>(getConstantImm()) : isImm();
1290 template <
unsigned Bits>
bool isUImm()
const {
1291 return isConstantImm() ? isUInt<Bits>(getConstantImm()) : isImm();
1294 template <
unsigned Bits>
bool isAnyImm()
const {
1295 return isConstantImm() ? (isInt<Bits>(getConstantImm()) ||
1296 isUInt<Bits>(getConstantImm()))
1300 template <
unsigned Bits,
int Offset = 0>
bool isConstantSImm()
const {
1301 return isConstantImm() && isInt<Bits>(getConstantImm() -
Offset);
1304 template <
unsigned Bottom,
unsigned Top>
bool isConstantUImmRange()
const {
1305 return isConstantImm() && getConstantImm() >= Bottom &&
1306 getConstantImm() <= Top;
1309 bool isToken()
const override {
1312 return Kind == k_Token;
1315 bool isMem()
const override {
return Kind == k_Memory; }
1317 bool isConstantMemOff()
const {
1318 return isMem() && isa<MCConstantExpr>(getMemOff());
1322 template <
unsigned Bits,
unsigned ShiftAmount = 0>
1323 bool isMemWithSimmOffset()
const {
1326 if (!getMemBase()->isGPRAsmReg())
1328 if (isa<MCTargetExpr>(getMemOff()) ||
1329 (isConstantMemOff() &&
1330 isShiftedInt<Bits, ShiftAmount>(getConstantMemOff())))
1333 bool IsReloc = getMemOff()->evaluateAsRelocatable(Res,
nullptr,
nullptr);
1334 return IsReloc && isShiftedInt<Bits, ShiftAmount>(Res.
getConstant());
1337 bool isMemWithPtrSizeOffset()
const {
1340 if (!getMemBase()->isGPRAsmReg())
1342 const unsigned PtrBits = AsmParser.getABI().ArePtrs64bit() ? 64 : 32;
1343 if (isa<MCTargetExpr>(getMemOff()) ||
1344 (isConstantMemOff() &&
isIntN(PtrBits, getConstantMemOff())))
1347 bool IsReloc = getMemOff()->evaluateAsRelocatable(Res,
nullptr,
nullptr);
1351 bool isMemWithGRPMM16Base()
const {
1352 return isMem() && getMemBase()->isMM16AsmReg();
1355 template <
unsigned Bits>
bool isMemWithUimmOffsetSP()
const {
1356 return isMem() && isConstantMemOff() && isUInt<Bits>(getConstantMemOff())
1357 && getMemBase()->isRegIdx() && (getMemBase()->getGPR32Reg() == Mips::SP);
1360 template <
unsigned Bits>
bool isMemWithUimmWordAlignedOffsetSP()
const {
1361 return isMem() && isConstantMemOff() && isUInt<Bits>(getConstantMemOff())
1362 && (getConstantMemOff() % 4 == 0) && getMemBase()->isRegIdx()
1363 && (getMemBase()->getGPR32Reg() == Mips::SP);
1366 template <
unsigned Bits>
bool isMemWithSimmWordAlignedOffsetGP()
const {
1367 return isMem() && isConstantMemOff() && isInt<Bits>(getConstantMemOff())
1368 && (getConstantMemOff() % 4 == 0) && getMemBase()->isRegIdx()
1369 && (getMemBase()->getGPR32Reg() == Mips::GP);
1372 template <
unsigned Bits,
unsigned ShiftLeftAmount>
1373 bool isScaledUImm()
const {
1374 return isConstantImm() &&
1375 isShiftedUInt<Bits, ShiftLeftAmount>(getConstantImm());
1378 template <
unsigned Bits,
unsigned ShiftLeftAmount>
1379 bool isScaledSImm()
const {
1380 if (isConstantImm() &&
1381 isShiftedInt<Bits, ShiftLeftAmount>(getConstantImm()))
1385 if (Kind != k_Immediate)
1388 bool Success = getImm()->evaluateAsRelocatable(Res,
nullptr,
nullptr);
1389 return Success && isShiftedInt<Bits, ShiftLeftAmount>(Res.
getConstant());
1392 bool isRegList16()
const {
1396 int Size = RegList.List->size();
1397 if (Size < 2 || Size > 5)
1400 unsigned R0 = RegList.List->front();
1401 unsigned R1 = RegList.List->back();
1402 if (!((R0 == Mips::S0 && R1 ==
Mips::RA) ||
1403 (R0 == Mips::S0_64 && R1 == Mips::RA_64)))
1406 int PrevReg = *RegList.List->begin();
1407 for (
int i = 1; i < Size - 1; i++) {
1408 int Reg = (*(RegList.List))[i];
1409 if ( Reg != PrevReg + 1)
1417 bool isInvNum()
const {
return Kind == k_Immediate; }
1419 bool isLSAImm()
const {
1420 if (!isConstantImm())
1422 int64_t Val = getConstantImm();
1423 return 1 <= Val && Val <= 4;
1426 bool isRegList()
const {
return Kind == k_RegList; }
1429 assert(Kind == k_Token &&
"Invalid access!");
1433 unsigned getReg()
const override {
1436 if (Kind == k_RegisterIndex && RegIdx.Index == 0 &&
1437 RegIdx.Kind & RegKind_GPR)
1438 return getGPR32Reg();
1444 const MCExpr *getImm()
const {
1445 assert((Kind == k_Immediate) &&
"Invalid access!");
1449 int64_t getConstantImm()
const {
1450 const MCExpr *Val = getImm();
1452 (void)Val->evaluateAsAbsolute(Value);
1456 MipsOperand *getMemBase()
const {
1457 assert((Kind == k_Memory) &&
"Invalid access!");
1461 const MCExpr *getMemOff()
const {
1462 assert((Kind == k_Memory) &&
"Invalid access!");
1466 int64_t getConstantMemOff()
const {
1467 return static_cast<const MCConstantExpr *
>(getMemOff())->getValue();
1471 assert((Kind == k_RegList) &&
"Invalid access!");
1472 return *(RegList.List);
1475 static std::unique_ptr<MipsOperand> CreateToken(
StringRef Str,
SMLoc S,
1476 MipsAsmParser &Parser) {
1477 auto Op = std::make_unique<MipsOperand>(k_Token, Parser);
1478 Op->Tok.Data = Str.
data();
1479 Op->Tok.Length = Str.
size();
1487 static std::unique_ptr<MipsOperand>
1490 LLVM_DEBUG(
dbgs() <<
"createNumericReg(" << Index <<
", ...)\n");
1491 return CreateReg(Index, Str, RegKind_Numeric, RegInfo, S, E, Parser);
1496 static std::unique_ptr<MipsOperand>
1499 return CreateReg(Index, Str, RegKind_GPR, RegInfo, S, E, Parser);
1504 static std::unique_ptr<MipsOperand>
1507 return CreateReg(Index, Str, RegKind_FGR, RegInfo, S, E, Parser);
1512 static std::unique_ptr<MipsOperand>
1515 return CreateReg(Index, Str, RegKind_HWRegs, RegInfo, S, E, Parser);
1520 static std::unique_ptr<MipsOperand>
1523 return CreateReg(Index, Str, RegKind_FCC, RegInfo, S, E, Parser);
1528 static std::unique_ptr<MipsOperand>
1531 return CreateReg(Index, Str, RegKind_ACC, RegInfo, S, E, Parser);
1536 static std::unique_ptr<MipsOperand>
1539 return CreateReg(Index, Str, RegKind_MSA128, RegInfo, S, E, Parser);
1544 static std::unique_ptr<MipsOperand>
1547 return CreateReg(Index, Str, RegKind_MSACtrl, RegInfo, S, E, Parser);
1550 static std::unique_ptr<MipsOperand>
1552 auto Op = std::make_unique<MipsOperand>(k_Immediate, Parser);
1559 static std::unique_ptr<MipsOperand>
1560 CreateMem(std::unique_ptr<MipsOperand>
Base,
const MCExpr *Off,
SMLoc S,
1561 SMLoc E, MipsAsmParser &Parser) {
1562 auto Op = std::make_unique<MipsOperand>(k_Memory, Parser);
1563 Op->Mem.Base = Base.release();
1570 static std::unique_ptr<MipsOperand>
1572 MipsAsmParser &Parser) {
1573 assert(Regs.
size() > 0 &&
"Empty list not allowed");
1575 auto Op = std::make_unique<MipsOperand>(k_RegList, Parser);
1577 Op->StartLoc = StartLoc;
1578 Op->EndLoc = EndLoc;
1582 bool isGPRZeroAsmReg()
const {
1583 return isRegIdx() && RegIdx.Kind & RegKind_GPR && RegIdx.Index == 0;
1586 bool isGPRNonZeroAsmReg()
const {
1587 return isRegIdx() && RegIdx.Kind & RegKind_GPR && RegIdx.Index > 0 &&
1591 bool isGPRAsmReg()
const {
1592 return isRegIdx() && RegIdx.Kind & RegKind_GPR && RegIdx.Index <= 31;
1595 bool isMM16AsmReg()
const {
1596 if (!(isRegIdx() && RegIdx.Kind))
1598 return ((RegIdx.Index >= 2 && RegIdx.Index <= 7)
1599 || RegIdx.Index == 16 || RegIdx.Index == 17);
1602 bool isMM16AsmRegZero()
const {
1603 if (!(isRegIdx() && RegIdx.Kind))
1605 return (RegIdx.Index == 0 ||
1606 (RegIdx.Index >= 2 && RegIdx.Index <= 7) ||
1607 RegIdx.Index == 17);
1610 bool isMM16AsmRegMoveP()
const {
1611 if (!(isRegIdx() && RegIdx.Kind))
1613 return (RegIdx.Index == 0 || (RegIdx.Index >= 2 && RegIdx.Index <= 3) ||
1614 (RegIdx.Index >= 16 && RegIdx.Index <= 20));
1617 bool isMM16AsmRegMovePPairFirst()
const {
1618 if (!(isRegIdx() && RegIdx.Kind))
1620 return RegIdx.Index >= 4 && RegIdx.Index <= 6;
1623 bool isMM16AsmRegMovePPairSecond()
const {
1624 if (!(isRegIdx() && RegIdx.Kind))
1626 return (RegIdx.Index == 21 || RegIdx.Index == 22 ||
1627 (RegIdx.Index >= 5 && RegIdx.Index <= 7));
1630 bool isFGRAsmReg()
const {
1632 return isRegIdx() && RegIdx.Kind & RegKind_FGR && RegIdx.Index <= 31;
1635 bool isStrictlyFGRAsmReg()
const {
1637 return isRegIdx() && RegIdx.Kind == RegKind_FGR && RegIdx.Index <= 31;
1640 bool isHWRegsAsmReg()
const {
1641 return isRegIdx() && RegIdx.Kind & RegKind_HWRegs && RegIdx.Index <= 31;
1644 bool isCCRAsmReg()
const {
1645 return isRegIdx() && RegIdx.Kind & RegKind_CCR && RegIdx.Index <= 31;
1648 bool isFCCAsmReg()
const {
1649 if (!(isRegIdx() && RegIdx.Kind & RegKind_FCC))
1651 return RegIdx.Index <= 7;
1654 bool isACCAsmReg()
const {
1655 return isRegIdx() && RegIdx.Kind & RegKind_ACC && RegIdx.Index <= 3;
1658 bool isCOP0AsmReg()
const {
1659 return isRegIdx() && RegIdx.Kind & RegKind_COP0 && RegIdx.Index <= 31;
1662 bool isCOP2AsmReg()
const {
1663 return isRegIdx() && RegIdx.Kind & RegKind_COP2 && RegIdx.Index <= 31;
1666 bool isCOP3AsmReg()
const {
1667 return isRegIdx() && RegIdx.Kind & RegKind_COP3 && RegIdx.Index <= 31;
1670 bool isMSA128AsmReg()
const {
1671 return isRegIdx() && RegIdx.Kind & RegKind_MSA128 && RegIdx.Index <= 31;
1674 bool isMSACtrlAsmReg()
const {
1675 return isRegIdx() && RegIdx.Kind & RegKind_MSACtrl && RegIdx.Index <= 7;
1679 SMLoc getStartLoc()
const override {
return StartLoc; }
1681 SMLoc getEndLoc()
const override {
return EndLoc; }
1692 Mem.Base->print(OS);
1697 case k_RegisterIndex:
1698 OS <<
"RegIdx<" << RegIdx.Index <<
":" << RegIdx.Kind <<
", " 1699 <<
StringRef(RegIdx.Tok.Data, RegIdx.Tok.Length) <<
">";
1706 for (
auto Reg : (*RegList.List))
1713 bool isValidForTie(
const MipsOperand &
Other)
const {
1714 if (Kind != Other.Kind)
1721 case k_RegisterIndex: {
1722 StringRef Token(RegIdx.Tok.Data, RegIdx.Tok.Length);
1723 StringRef OtherToken(Other.RegIdx.Tok.Data, Other.RegIdx.Tok.Length);
1724 return Token == OtherToken;
1750 case Mips::JRC16_MM:
1752 case Mips::JALRS_MM:
1753 case Mips::JALRS16_MM:
1754 case Mips::BGEZALS_MM:
1755 case Mips::BLTZALS_MM:
1765 if (
const MCSymbolRefExpr *SRExpr = dyn_cast<MCSymbolRefExpr>(Expr)) {
1766 return &SRExpr->getSymbol();
1769 if (
const MCBinaryExpr *BExpr = dyn_cast<MCBinaryExpr>(Expr)) {
1782 if (
const MCUnaryExpr *UExpr = dyn_cast<MCUnaryExpr>(Expr))
1789 if (isa<MCSymbolRefExpr>(Expr))
1792 if (
const MCBinaryExpr *BExpr = dyn_cast<MCBinaryExpr>(Expr))
1796 if (
const MCUnaryExpr *UExpr = dyn_cast<MCUnaryExpr>(Expr))
1815 return isEvaluated(cast<MCUnaryExpr>(Expr)->getSubExpr());
1826 if (NumOp != 3 && NumOp != 4)
1838 return !isInt<9>(Op.
getImm());
1856 bool MipsAsmParser::processInstruction(
MCInst &Inst,
SMLoc IDLoc,
1860 const unsigned Opcode = Inst.
getOpcode();
1862 bool ExpandedJalSym =
false;
1876 assert(hasCnMips() &&
"instruction only valid for octeon cpus");
1885 if (!Offset.isImm())
1887 if (!
isIntN(inMicroMipsMode() ? 17 : 18, Offset.getImm()))
1888 return Error(IDLoc,
"branch target out of range");
1891 return Error(IDLoc,
"branch to misaligned address");
1905 case Mips::BGEZAL_MM:
1906 case Mips::BLTZAL_MM:
1909 case Mips::BC1EQZC_MMR6:
1910 case Mips::BC1NEZC_MMR6:
1911 case Mips::BC2EQZC_MMR6:
1912 case Mips::BC2NEZC_MMR6:
1915 if (!Offset.isImm())
1917 if (!
isIntN(inMicroMipsMode() ? 17 : 18, Offset.getImm()))
1918 return Error(IDLoc,
"branch target out of range");
1921 return Error(IDLoc,
"branch to misaligned address");
1923 case Mips::BGEC:
case Mips::BGEC_MMR6:
1924 case Mips::BLTC:
case Mips::BLTC_MMR6:
1925 case Mips::BGEUC:
case Mips::BGEUC_MMR6:
1926 case Mips::BLTUC:
case Mips::BLTUC_MMR6:
1927 case Mips::BEQC:
case Mips::BEQC_MMR6:
1928 case Mips::BNEC:
case Mips::BNEC_MMR6:
1931 if (!Offset.isImm())
1933 if (!
isIntN(18, Offset.getImm()))
1934 return Error(IDLoc,
"branch target out of range");
1936 return Error(IDLoc,
"branch to misaligned address");
1938 case Mips::BLEZC:
case Mips::BLEZC_MMR6:
1939 case Mips::BGEZC:
case Mips::BGEZC_MMR6:
1940 case Mips::BGTZC:
case Mips::BGTZC_MMR6:
1941 case Mips::BLTZC:
case Mips::BLTZC_MMR6:
1944 if (!Offset.isImm())
1946 if (!
isIntN(18, Offset.getImm()))
1947 return Error(IDLoc,
"branch target out of range");
1949 return Error(IDLoc,
"branch to misaligned address");
1951 case Mips::BEQZC:
case Mips::BEQZC_MMR6:
1952 case Mips::BNEZC:
case Mips::BNEZC_MMR6:
1955 if (!Offset.isImm())
1957 if (!
isIntN(23, Offset.getImm()))
1958 return Error(IDLoc,
"branch target out of range");
1960 return Error(IDLoc,
"branch to misaligned address");
1962 case Mips::BEQZ16_MM:
1963 case Mips::BEQZC16_MMR6:
1964 case Mips::BNEZ16_MM:
1965 case Mips::BNEZC16_MMR6:
1968 if (!Offset.isImm())
1971 return Error(IDLoc,
"branch target out of range");
1973 return Error(IDLoc,
"branch to misaligned address");
1980 if (hasMips32r6() && Opcode == Mips::SSNOP) {
1981 std::string ISA = hasMips64r6() ?
"MIPS64r6" :
"MIPS32r6";
1982 Warning(IDLoc,
"ssnop is deprecated for " + ISA +
" and is equivalent to a " 2002 return Error(IDLoc,
"expected immediate operand kind");
2003 Imm = Opnd.getImm();
2004 if (Imm < 0 || Imm > (Opcode == Mips::BBIT0 ||
2005 Opcode == Mips::BBIT1 ? 63 : 31))
2006 return Error(IDLoc,
"immediate operand value out of range");
2008 Inst.
setOpcode(Opcode == Mips::BBIT0 ? Mips::BBIT032
2019 return Error(IDLoc,
"expected immediate operand kind");
2020 Imm = Opnd.getImm();
2021 if (!isInt<10>(Imm))
2022 return Error(IDLoc,
"immediate operand value out of range");
2034 unsigned FirstOp = 1;
2035 unsigned SecondOp = 2;
2039 case Mips::SDivIMacro:
2040 case Mips::UDivIMacro:
2041 case Mips::DSDivIMacro:
2042 case Mips::DUDivIMacro:
2046 Warning(IDLoc,
"dividing zero by zero");
2048 Warning(IDLoc,
"division by zero");
2060 case Mips::SDivMacro:
2061 case Mips::DSDivMacro:
2062 case Mips::UDivMacro:
2063 case Mips::DUDivMacro:
2068 case Mips::DIVU_MMR6:
2069 case Mips::DIV_MMR6:
2074 Warning(IDLoc,
"dividing zero by zero");
2076 Warning(IDLoc,
"division by zero");
2082 if ((Opcode == Mips::J || Opcode == Mips::J_MM) && inPicMode()) {
2084 BInst.
setOpcode(inMicroMipsMode() ? Mips::BEQ_MM : Mips::BEQ);
2093 if ((Opcode == Mips::JAL || Opcode == Mips::JAL_MM) && inPicMode()) {
2094 warnIfNoMacro(IDLoc);
2101 return Error(IDLoc,
"jal doesn't support multiple symbols in PIC mode");
2107 if (expandLoadAddress(Mips::T9, Mips::NoRegister, Inst.
getOperand(0),
2108 !isGP64bit(), IDLoc, Out, STI))
2112 if (inMicroMipsMode())
2113 JalrInst.
setOpcode(IsCpRestoreSet ? Mips::JALRS_MM : Mips::JALR_MM);
2119 if (isJalrRelocAvailable(JalExpr)) {
2123 MCSymbol *TmpLabel = getContext().createTempSymbol();
2125 const MCExpr *RelocJalrExpr =
2127 getContext(), IDLoc);
2130 inMicroMipsMode() ?
"R_MICROMIPS_JALR" :
"R_MIPS_JALR",
2131 RelocJalrExpr, IDLoc, *STI);
2136 ExpandedJalSym =
true;
2146 expandMem9Inst(Inst, IDLoc, Out, STI, MCID.
mayLoad());
2149 expandMem16Inst(Inst, IDLoc, Out, STI, MCID.
mayLoad());
2152 return getParser().hasPendingError();
2156 if (inMicroMipsMode()) {
2157 if (MCID.
mayLoad() && Opcode != Mips::LWP_MM) {
2165 int MemOffset = Op.
getImm();
2168 if (isInt<9>(MemOffset) && (MemOffset % 4 == 0) &&
2171 (BaseReg.
getReg() == Mips::GP ||
2172 BaseReg.
getReg() == Mips::GP_64)) {
2174 TOut.
emitRRI(Mips::LWGP_MM, DstReg.
getReg(), Mips::GP, MemOffset,
2191 case Mips::ADDIUSP_MM:
2194 return Error(IDLoc,
"expected immediate operand kind");
2196 if (Imm < -1032 || Imm > 1028 || (Imm < 8 && Imm > -12) ||
2198 return Error(IDLoc,
"immediate operand value out of range");
2200 case Mips::SLL16_MM:
2201 case Mips::SRL16_MM:
2204 return Error(IDLoc,
"expected immediate operand kind");
2206 if (Imm < 1 || Imm > 8)
2207 return Error(IDLoc,
"immediate operand value out of range");
2212 return Error(IDLoc,
"expected immediate operand kind");
2214 if (Imm < -1 || Imm > 126)
2215 return Error(IDLoc,
"immediate operand value out of range");
2217 case Mips::ADDIUR2_MM:
2220 return Error(IDLoc,
"expected immediate operand kind");
2222 if (!(Imm == 1 || Imm == -1 ||
2223 ((Imm % 4 == 0) && Imm < 28 && Imm > 0)))
2224 return Error(IDLoc,
"immediate operand value out of range");
2226 case Mips::ANDI16_MM:
2229 return Error(IDLoc,
"expected immediate operand kind");
2231 if (!(Imm == 128 || (Imm >= 1 && Imm <= 4) || Imm == 7 || Imm == 8 ||
2232 Imm == 15 || Imm == 16 || Imm == 31 || Imm == 32 || Imm == 63 ||
2233 Imm == 64 || Imm == 255 || Imm == 32768 || Imm == 65535))
2234 return Error(IDLoc,
"immediate operand value out of range");
2236 case Mips::LBU16_MM:
2239 return Error(IDLoc,
"expected immediate operand kind");
2241 if (Imm < -1 || Imm > 14)
2242 return Error(IDLoc,
"immediate operand value out of range");
2245 case Mips::SB16_MMR6:
2248 return Error(IDLoc,
"expected immediate operand kind");
2250 if (Imm < 0 || Imm > 15)
2251 return Error(IDLoc,
"immediate operand value out of range");
2253 case Mips::LHU16_MM:
2255 case Mips::SH16_MMR6:
2258 return Error(IDLoc,
"expected immediate operand kind");
2260 if (Imm < 0 || Imm > 30 || (Imm % 2 != 0))
2261 return Error(IDLoc,
"immediate operand value out of range");
2265 case Mips::SW16_MMR6:
2268 return Error(IDLoc,
"expected immediate operand kind");
2270 if (Imm < 0 || Imm > 60 || (Imm % 4 != 0))
2271 return Error(IDLoc,
"immediate operand value out of range");
2273 case Mips::ADDIUPC_MM:
2276 return Error(IDLoc,
"expected immediate operand kind");
2278 if ((Imm % 4 != 0) || !isInt<25>(Imm))
2279 return Error(IDLoc,
"immediate operand value out of range");
2284 return Error(IDLoc,
"invalid operand for instruction");
2286 case Mips::MOVEP_MM:
2287 case Mips::MOVEP_MMR6: {
2290 bool RegPair = ((R0 == Mips::A1 && R1 == Mips::A2) ||
2291 (R0 == Mips::A1 && R1 == Mips::A3) ||
2292 (R0 == Mips::A2 && R1 == Mips::A3) ||
2293 (R0 == Mips::A0 && R1 == Mips::S5) ||
2294 (R0 == Mips::A0 && R1 == Mips::S6) ||
2295 (R0 == Mips::A0 && R1 == Mips::A1) ||
2296 (R0 == Mips::A0 && R1 == Mips::A2) ||
2297 (R0 == Mips::A0 && R1 == Mips::A3));
2299 return Error(IDLoc,
"invalid operand for instruction");
2305 bool FillDelaySlot =
2310 MacroExpanderResultTy ExpandResult =
2311 tryExpandInstruction(Inst, IDLoc, Out, STI);
2312 switch (ExpandResult) {
2324 if (inMicroMipsMode()) {
2331 if (FillDelaySlot) {
2336 if ((Opcode == Mips::JalOneReg || Opcode == Mips::JalTwoReg ||
2338 isPicAndNotNxxAbi()) {
2339 if (IsCpRestoreSet) {
2343 if (!AssemblerOptions.
back()->isReorder())
2350 Warning(IDLoc,
"no .cprestore used in PIC mode");
2356 MipsAsmParser::MacroExpanderResultTy
2361 return MER_NotAMacro;
2362 case Mips::LoadImm32:
2363 return expandLoadImm(Inst,
true, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2364 case Mips::LoadImm64:
2365 return expandLoadImm(Inst,
false, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2366 case Mips::LoadAddrImm32:
2367 case Mips::LoadAddrImm64:
2370 "expected immediate operand kind");
2374 Inst.
getOpcode() == Mips::LoadAddrImm32, IDLoc,
2378 case Mips::LoadAddrReg32:
2379 case Mips::LoadAddrReg64:
2383 "expected immediate operand kind");
2387 Inst.
getOpcode() == Mips::LoadAddrReg32, IDLoc,
2391 case Mips::B_MM_Pseudo:
2392 case Mips::B_MMR6_Pseudo:
2393 return expandUncondBranchMMPseudo(Inst, IDLoc, Out, STI) ? MER_Fail
2397 return expandLoadStoreMultiple(Inst, IDLoc, Out, STI) ? MER_Fail
2399 case Mips::JalOneReg:
2400 case Mips::JalTwoReg:
2401 return expandJalWithRegs(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2404 case Mips::BEQLImmMacro:
2405 case Mips::BNELImmMacro:
2406 return expandBranchImm(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2423 case Mips::BLTImmMacro:
2424 case Mips::BLEImmMacro:
2425 case Mips::BGEImmMacro:
2426 case Mips::BGTImmMacro:
2427 case Mips::BLTUImmMacro:
2428 case Mips::BLEUImmMacro:
2429 case Mips::BGEUImmMacro:
2430 case Mips::BGTUImmMacro:
2431 case Mips::BLTLImmMacro:
2432 case Mips::BLELImmMacro:
2433 case Mips::BGELImmMacro:
2434 case Mips::BGTLImmMacro:
2435 case Mips::BLTULImmMacro:
2436 case Mips::BLEULImmMacro:
2437 case Mips::BGEULImmMacro:
2438 case Mips::BGTULImmMacro:
2439 return expandCondBranches(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2440 case Mips::SDivMacro:
2441 case Mips::SDivIMacro:
2442 case Mips::SRemMacro:
2443 case Mips::SRemIMacro:
2444 return expandDivRem(Inst, IDLoc, Out, STI,
false,
true) ? MER_Fail
2446 case Mips::DSDivMacro:
2447 case Mips::DSDivIMacro:
2448 case Mips::DSRemMacro:
2449 case Mips::DSRemIMacro:
2450 return expandDivRem(Inst, IDLoc, Out, STI,
true,
true) ? MER_Fail
2452 case Mips::UDivMacro:
2453 case Mips::UDivIMacro:
2454 case Mips::URemMacro:
2455 case Mips::URemIMacro:
2456 return expandDivRem(Inst, IDLoc, Out, STI,
false,
false) ? MER_Fail
2458 case Mips::DUDivMacro:
2459 case Mips::DUDivIMacro:
2460 case Mips::DURemMacro:
2461 case Mips::DURemIMacro:
2462 return expandDivRem(Inst, IDLoc, Out, STI,
true,
false) ? MER_Fail
2464 case Mips::PseudoTRUNC_W_S:
2465 return expandTrunc(Inst,
false,
false, IDLoc, Out, STI) ? MER_Fail
2467 case Mips::PseudoTRUNC_W_D32:
2468 return expandTrunc(Inst,
true,
false, IDLoc, Out, STI) ? MER_Fail
2470 case Mips::PseudoTRUNC_W_D:
2471 return expandTrunc(Inst,
true,
true, IDLoc, Out, STI) ? MER_Fail
2474 case Mips::LoadImmSingleGPR:
2475 return expandLoadSingleImmToGPR(Inst, IDLoc, Out, STI) ? MER_Fail
2477 case Mips::LoadImmSingleFGR:
2478 return expandLoadSingleImmToFPR(Inst, IDLoc, Out, STI) ? MER_Fail
2480 case Mips::LoadImmDoubleGPR:
2481 return expandLoadDoubleImmToGPR(Inst, IDLoc, Out, STI) ? MER_Fail
2483 case Mips::LoadImmDoubleFGR:
2484 return expandLoadDoubleImmToFPR(Inst,
true, IDLoc, Out, STI) ? MER_Fail
2486 case Mips::LoadImmDoubleFGR_32:
2487 return expandLoadDoubleImmToFPR(Inst,
false, IDLoc, Out, STI) ? MER_Fail
2491 return expandUlh(Inst,
true, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2493 return expandUlh(Inst,
false, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2495 return expandUsh(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2498 return expandUxw(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2500 case Mips::NORImm64:
2501 return expandAliasImmediate(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2504 return expandSge(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2507 case Mips::SGEImm64:
2508 case Mips::SGEUImm64:
2509 return expandSgeImm(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2512 case Mips::SGTImm64:
2513 case Mips::SGTUImm64:
2514 return expandSgtImm(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2515 case Mips::SLTImm64:
2518 return MER_NotAMacro;
2520 return expandAliasImmediate(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2521 case Mips::SLTUImm64:
2524 return MER_NotAMacro;
2526 return expandAliasImmediate(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2527 case Mips::ADDi:
case Mips::ADDi_MM:
2528 case Mips::ADDiu:
case Mips::ADDiu_MM:
2529 case Mips::SLTi:
case Mips::SLTi_MM:
2530 case Mips::SLTiu:
case Mips::SLTiu_MM:
2535 return MER_NotAMacro;
2536 return expandAliasImmediate(Inst, IDLoc, Out, STI) ? MER_Fail
2539 return MER_NotAMacro;
2540 case Mips::ANDi:
case Mips::ANDi_MM:
case Mips::ANDi64:
2541 case Mips::ORi:
case Mips::ORi_MM:
case Mips::ORi64:
2542 case Mips::XORi:
case Mips::XORi_MM:
case Mips::XORi64:
2547 return MER_NotAMacro;
2548 return expandAliasImmediate(Inst, IDLoc, Out, STI) ? MER_Fail
2551 return MER_NotAMacro;
2554 return expandRotation(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2557 return expandRotationImm(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2560 return expandDRotation(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2563 return expandDRotationImm(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2564 case Mips::ABSMacro:
2565 return expandAbs(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2566 case Mips::MULImmMacro:
2567 case Mips::DMULImmMacro:
2568 return expandMulImm(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2569 case Mips::MULOMacro:
2570 case Mips::DMULOMacro:
2571 return expandMulO(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2572 case Mips::MULOUMacro:
2573 case Mips::DMULOUMacro:
2574 return expandMulOU(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2575 case Mips::DMULMacro:
2576 return expandDMULMacro(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2579 return expandLoadStoreDMacro(Inst, IDLoc, Out, STI,
2584 return expandStoreDM1Macro(Inst, IDLoc, Out, STI)
2587 case Mips::SEQMacro:
2588 return expandSeq(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2589 case Mips::SEQIMacro:
2590 return expandSeqI(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2591 case Mips::MFTC0:
case Mips::MTTC0:
2592 case Mips::MFTGPR:
case Mips::MTTGPR:
2593 case Mips::MFTLO:
case Mips::MTTLO:
2594 case Mips::MFTHI:
case Mips::MTTHI:
2595 case Mips::MFTACX:
case Mips::MTTACX:
2596 case Mips::MFTDSP:
case Mips::MTTDSP:
2597 case Mips::MFTC1:
case Mips::MTTC1:
2598 case Mips::MFTHC1:
case Mips::MTTHC1:
2599 case Mips::CFTC1:
case Mips::CTTC1:
2600 return expandMXTRAlias(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2602 case Mips::SaadAddr:
2603 return expandSaaAddr(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2607 bool MipsAsmParser::expandJalWithRegs(
MCInst &Inst,
SMLoc IDLoc,
2616 const unsigned Opcode = Inst.
getOpcode();
2618 if (Opcode == Mips::JalOneReg) {
2620 if (IsCpRestoreSet && inMicroMipsMode()) {
2623 }
else if (inMicroMipsMode()) {
2624 JalrInst.
setOpcode(hasMips32r6() ? Mips::JALRC16_MMR6 : Mips::JALR16_MM);
2631 }
else if (Opcode == Mips::JalTwoReg) {
2633 if (IsCpRestoreSet && inMicroMipsMode())
2636 JalrInst.
setOpcode(inMicroMipsMode() ? Mips::JALR_MM : Mips::JALR);
2657 return (x == x >> BitNum << BitNum) && isUInt<N>(x >> BitNum);
2670 bool MipsAsmParser::loadImmediate(int64_t ImmValue,
unsigned DstReg,
2671 unsigned SrcReg,
bool Is32BitImm,
2676 if (!Is32BitImm && !isGP64bit()) {
2677 Error(IDLoc,
"instruction requires a 64-bit architecture");
2686 ImmValue = SignExtend64<32>(ImmValue);
2688 Error(IDLoc,
"instruction requires a 32-bit immediate");
2694 unsigned AdduOp = !Is32BitImm ? Mips::DADDu : Mips::ADDu;
2696 bool UseSrcReg =
false;
2697 if (SrcReg != Mips::NoRegister)
2700 unsigned TmpReg = DstReg;
2702 getContext().getRegisterInfo()->isSuperOrSubRegisterEq(DstReg, SrcReg)) {
2705 unsigned ATReg = getATReg(IDLoc);
2718 if (IsAddress && !Is32BitImm) {
2719 TOut.
emitRRI(Mips::DADDiu, DstReg, SrcReg, ImmValue, IDLoc, STI);
2723 TOut.
emitRRI(Mips::ADDiu, DstReg, SrcReg, ImmValue, IDLoc, STI);
2728 unsigned TmpReg = DstReg;
2729 if (SrcReg == DstReg) {
2730 TmpReg = getATReg(IDLoc);
2735 TOut.
emitRRI(Mips::ORi, TmpReg, ZeroReg, ImmValue, IDLoc, STI);
2742 warnIfNoMacro(IDLoc);
2744 uint16_t Bits31To16 = (ImmValue >> 16) & 0xffff;
2745 uint16_t Bits15To0 = ImmValue & 0xffff;
2746 if (!Is32BitImm && !
isInt<32>(ImmValue)) {
2749 if (ImmValue == 0xffffffff) {
2750 TOut.
emitRI(Mips::LUi, TmpReg, 0xffff, IDLoc, STI);
2751 TOut.
emitRRI(Mips::DSRL32, TmpReg, TmpReg, 0, IDLoc, STI);
2753 TOut.
emitRRR(AdduOp, DstReg, TmpReg, SrcReg, IDLoc, STI);
2759 TOut.
emitRRI(Mips::ORi, TmpReg, ZeroReg, Bits31To16, IDLoc, STI);
2760 TOut.
emitRRI(Mips::DSLL, TmpReg, TmpReg, 16, IDLoc, STI);
2762 TOut.
emitRRI(Mips::ORi, TmpReg, TmpReg, Bits15To0, IDLoc, STI);
2764 TOut.
emitRRR(AdduOp, DstReg, TmpReg, SrcReg, IDLoc, STI);
2768 TOut.
emitRI(Mips::LUi, TmpReg, Bits31To16, IDLoc, STI);
2770 TOut.
emitRRI(Mips::ORi, TmpReg, TmpReg, Bits15To0, IDLoc, STI);
2772 TOut.
emitRRR(AdduOp, DstReg, TmpReg, SrcReg, IDLoc, STI);
2776 if (isShiftedUIntAtAnyPosition<16>(ImmValue)) {
2778 Error(IDLoc,
"instruction requires a 32-bit immediate");
2785 unsigned LastSet =
findLastSet((uint64_t)ImmValue);
2786 unsigned ShiftAmount = FirstSet - (15 - (LastSet - FirstSet));
2788 TOut.
emitRRI(Mips::ORi, TmpReg, ZeroReg, Bits, IDLoc, STI);
2789 TOut.
emitRRI(Mips::DSLL, TmpReg, TmpReg, ShiftAmount, IDLoc, STI);
2792 TOut.
emitRRR(AdduOp, DstReg, TmpReg, SrcReg, IDLoc, STI);
2797 warnIfNoMacro(IDLoc);
2804 if (loadImmediate(ImmValue >> 32, TmpReg, Mips::NoRegister,
true,
false,
2810 unsigned ShiftCarriedForwards = 16;
2811 for (
int BitNum = 16; BitNum >= 0; BitNum -= 16) {
2812 uint16_t ImmChunk = (ImmValue >> BitNum) & 0xffff;
2814 if (ImmChunk != 0) {
2815 TOut.
emitDSLL(TmpReg, TmpReg, ShiftCarriedForwards, IDLoc, STI);
2816 TOut.
emitRRI(Mips::ORi, TmpReg, TmpReg, ImmChunk, IDLoc, STI);
2817 ShiftCarriedForwards = 0;
2820 ShiftCarriedForwards += 16;
2822 ShiftCarriedForwards -= 16;
2825 if (ShiftCarriedForwards)
2826 TOut.
emitDSLL(TmpReg, TmpReg, ShiftCarriedForwards, IDLoc, STI);
2829 TOut.
emitRRR(AdduOp, DstReg, TmpReg, SrcReg, IDLoc, STI);
2834 bool MipsAsmParser::expandLoadImm(
MCInst &Inst,
bool Is32BitImm,
SMLoc IDLoc,
2837 assert(ImmOp.
isImm() &&
"expected immediate operand kind");
2839 assert(DstRegOp.isReg() &&
"expected register operand kind");
2841 if (loadImmediate(ImmOp.
getImm(), DstRegOp.getReg(), Mips::NoRegister,
2842 Is32BitImm,
false, IDLoc, Out, STI))
2848 bool MipsAsmParser::expandLoadAddress(
unsigned DstReg,
unsigned BaseReg,
2850 bool Is32BitAddress,
SMLoc IDLoc,
2855 Warning(IDLoc,
"la used to load 64-bit address");
2857 Is32BitAddress =
false;
2861 if (!Is32BitAddress && !hasMips3()) {
2862 Error(IDLoc,
"instruction requires a 64-bit architecture");
2866 if (!Offset.
isImm())
2867 return loadAndAddSymbolAddress(Offset.
getExpr(), DstReg, BaseReg,
2868 Is32BitAddress, IDLoc, Out, STI);
2872 Is32BitAddress =
true;
2875 return loadImmediate(Offset.
getImm(), DstReg, BaseReg, Is32BitAddress,
true,
2879 bool MipsAsmParser::loadAndAddSymbolAddress(
const MCExpr *SymExpr,
2880 unsigned DstReg,
unsigned SrcReg,
2881 bool Is32BitSym,
SMLoc IDLoc,
2885 bool UseSrcReg = SrcReg != Mips::NoRegister && SrcReg != Mips::ZERO &&
2886 SrcReg != Mips::ZERO_64;
2887 warnIfNoMacro(IDLoc);
2892 Error(IDLoc,
"expected relocatable expression");
2895 if (Res.
getSymB() !=
nullptr) {
2896 Error(IDLoc,
"expected relocatable expression with only one symbol");
2907 bool UseXGOT = STI->
getFeatureBits()[Mips::FeatureXGOT] && !IsLocalSym;
2913 if ((DstReg == Mips::T9 || DstReg == Mips::T9_64) && !UseSrcReg &&
2917 SymExpr, getContext());
2919 SymExpr, getContext());
2922 TOut.
emitRRR(IsPtr64 ? Mips::DADDu : Mips::ADDu, DstReg, DstReg, GPReg,
2935 unsigned TmpReg = DstReg;
2937 getContext().getRegisterInfo()->isSuperOrSubRegisterEq(DstReg,
2941 unsigned ATReg = getATReg(IDLoc);
2960 const MCExpr *CallHiExpr =
2967 TOut.
emitRRR(IsPtr64 ? Mips::DADDu : Mips::ADDu, TmpReg, TmpReg, GPReg,
2973 TOut.
emitRRX(IsPtr64 ? Mips::DADDiu : Mips::ADDiu, TmpReg, TmpReg,
2979 TOut.
emitRRR(IsPtr64 ? Mips::DADDu : Mips::ADDu, DstReg, TmpReg, SrcReg,
2985 const MCExpr *LoExpr =
nullptr;
3005 Error(IDLoc,
"macro instruction uses large offset, which is not " 3006 "currently supported");
3040 TOut.
emitRRX(IsPtr64 ? Mips::DADDiu : Mips::ADDiu, TmpReg, TmpReg,
3044 TOut.
emitRRR(IsPtr64 ? Mips::DADDu : Mips::ADDu, DstReg, TmpReg, SrcReg,
3070 getContext().getRegisterInfo()->isSuperOrSubRegisterEq(DstReg, SrcReg);
3072 if (canUseATReg() && UseSrcReg && RdRegIsRsReg) {
3073 unsigned ATReg = getATReg(IDLoc);
3085 TOut.
emitRRX(Mips::DADDiu, ATReg, ATReg,
3087 TOut.
emitRRI(Mips::DSLL, ATReg, ATReg, 16, IDLoc, STI);
3090 TOut.
emitRRI(Mips::DSLL, ATReg, ATReg, 16, IDLoc, STI);
3093 TOut.
emitRRR(Mips::DADDu, DstReg, ATReg, SrcReg, IDLoc, STI);
3096 }
else if (canUseATReg() && !RdRegIsRsReg && DstReg != getATReg(IDLoc)) {
3097 unsigned ATReg = getATReg(IDLoc);
3113 TOut.
emitRRX(Mips::DADDiu, DstReg, DstReg,
3117 TOut.
emitRRI(Mips::DSLL32, DstReg, DstReg, 0, IDLoc, STI);
3118 TOut.
emitRRR(Mips::DADDu, DstReg, DstReg, ATReg, IDLoc, STI);
3120 TOut.
emitRRR(Mips::DADDu, DstReg, DstReg, SrcReg, IDLoc, STI);
3123 }
else if ((!canUseATReg() && !RdRegIsRsReg) ||
3124 (canUseATReg() && DstReg == getATReg(IDLoc))) {
3135 TOut.
emitRRX(Mips::DADDiu, DstReg, DstReg,
3137 TOut.
emitRRI(Mips::DSLL, DstReg, DstReg, 16, IDLoc, STI);
3138 TOut.
emitRRX(Mips::DADDiu, DstReg, DstReg,
3140 TOut.
emitRRI(Mips::DSLL, DstReg, DstReg, 16, IDLoc, STI);
3141 TOut.
emitRRX(Mips::DADDiu, DstReg, DstReg,
3144 TOut.
emitRRR(Mips::DADDu, DstReg, DstReg, SrcReg, IDLoc, STI);
3150 assert(SrcReg == DstReg && !canUseATReg() &&
3151 "Could have expanded dla but didn't?");
3152 reportParseError(IDLoc,
3153 "pseudo-instruction requires $at, which is not available");
3167 unsigned TmpReg = DstReg;
3169 getContext().getRegisterInfo()->isSuperOrSubRegisterEq(DstReg, SrcReg)) {
3172 unsigned ATReg = getATReg(IDLoc);
3183 TOut.
emitRRR(Mips::ADDu, DstReg, TmpReg, SrcReg, IDLoc, STI);
3186 getContext().getRegisterInfo()->isSuperOrSubRegisterEq(DstReg, TmpReg));
3195 if (MipsMCRegisterClasses[Mips::FGR32RegClassID].
contains(Reg))
3196 return Reg == (
unsigned)Mips::F31 ? (
unsigned)Mips::F0 : Reg + 1;
3198 default:
llvm_unreachable(
"Unknown register in assembly macro expansion!");
3199 case Mips::ZERO:
return Mips::AT;
3200 case Mips::AT:
return Mips::V0;
3201 case Mips::V0:
return Mips::V1;
3202 case Mips::V1:
return Mips::A0;
3203 case Mips::A0:
return Mips::A1;
3204 case Mips::A1:
return Mips::A2;
3205 case Mips::A2:
return Mips::A3;
3206 case Mips::A3:
return Mips::T0;
3209 case Mips::T2:
return Mips::T3;
3210 case Mips::T3:
return Mips::T4;
3211 case Mips::T4:
return Mips::T5;
3212 case Mips::T5:
return Mips::T6;
3213 case Mips::T6:
return Mips::T7;
3214 case Mips::T7:
return Mips::S0;
3215 case Mips::S0:
return Mips::S1;
3216 case Mips::S1:
return Mips::S2;
3217 case Mips::S2:
return Mips::S3;
3218 case Mips::S3:
return Mips::S4;
3219 case Mips::S4:
return Mips::S5;
3220 case Mips::S5:
return Mips::S6;
3221 case Mips::S6:
return Mips::S7;
3224 case Mips::T9:
return Mips::K0;
3225 case Mips::K0:
return Mips::K1;
3226 case Mips::K1:
return Mips::GP;
3227 case Mips::GP:
return Mips::SP;
3228 case Mips::SP:
return Mips::FP;
3231 case Mips::D0:
return Mips::F1;
3232 case Mips::D1:
return Mips::F3;
3233 case Mips::D2:
return Mips::F5;
3234 case Mips::D3:
return Mips::F7;
3235 case Mips::D4:
return Mips::F9;
3236 case Mips::D5:
return Mips::F11;
3237 case Mips::D6:
return Mips::F13;
3238 case Mips::D7:
return Mips::F15;
3239 case Mips::D8:
return Mips::F17;
3240 case Mips::D9:
return Mips::F19;
3241 case Mips::D10:
return Mips::F21;
3242 case Mips::D11:
return Mips::F23;
3243 case Mips::D12:
return Mips::F25;
3244 case Mips::D13:
return Mips::F27;
3245 case Mips::D14:
return Mips::F29;
3246 case Mips::D15:
return Mips::F31;
3258 unsigned ATReg = getATReg(IDLoc);
3268 if(isABI_O32() || isABI_N32()) {
3287 if(isABI_O32() || isABI_N32()) {
3290 const MCExpr *HighestSym =
3294 const MCExpr *HigherSym =
3301 TOut.
emitRRX(Mips::DADDiu, ATReg, ATReg,
3303 TOut.
emitRRI(Mips::DSLL, ATReg, ATReg, 16, IDLoc, STI);
3306 TOut.
emitRRI(Mips::DSLL, ATReg, ATReg, 16, IDLoc, STI);
3315 if ((
Hi_32(ImmOp64) & 0x7ff00000) == 0) {
3326 float TmpFloat =
static_cast<float>(DoubleImm);
3330 bool MipsAsmParser::expandLoadSingleImmToGPR(
MCInst &Inst,
SMLoc IDLoc,
3335 "Invalid instruction operand.");
3342 return loadImmediate(ImmOp32, FirstReg, Mips::NoRegister,
true,
false, IDLoc,
3346 bool MipsAsmParser::expandLoadSingleImmToFPR(
MCInst &Inst,
SMLoc IDLoc,
3352 "Invalid instruction operand.");
3361 unsigned TmpReg = Mips::ZERO;
3363 TmpReg = getATReg(IDLoc);
3368 if (
Lo_32(ImmOp64) == 0) {
3369 if (TmpReg != Mips::ZERO && loadImmediate(ImmOp32, TmpReg, Mips::NoRegister,
3370 true,
false, IDLoc, Out, STI))
3372 TOut.
emitRR(Mips::MTC1, FirstReg, TmpReg, IDLoc, STI);
3376 MCSection *CS = getStreamer().getCurrentSectionOnly();
3382 MCSymbol *Sym = getContext().createTempSymbol();
3388 getStreamer().SwitchSection(ReadOnlySection);
3389 getStreamer().EmitLabel(Sym, IDLoc);
3390 getStreamer().EmitIntValue(ImmOp32, 4);
3391 getStreamer().SwitchSection(CS);
3393 if (emitPartialAddress(TOut, IDLoc, Sym))
3400 bool MipsAsmParser::expandLoadDoubleImmToGPR(
MCInst &Inst,
SMLoc IDLoc,
3406 "Invalid instruction operand.");
3413 if (
Lo_32(ImmOp64) == 0) {
3415 if (loadImmediate(ImmOp64, FirstReg, Mips::NoRegister,
false,
false,
3419 if (loadImmediate(
Hi_32(ImmOp64), FirstReg, Mips::NoRegister,
true,
false,
3423 if (loadImmediate(0,
nextReg(FirstReg), Mips::NoRegister,
true,
false,
3430 MCSection *CS = getStreamer().getCurrentSectionOnly();
3434 MCSymbol *Sym = getContext().createTempSymbol();
3440 getStreamer().SwitchSection(ReadOnlySection);
3441 getStreamer().EmitLabel(Sym, IDLoc);
3442 getStreamer().EmitValueToAlignment(8);
3443 getStreamer().EmitIntValue(ImmOp64, 8);
3444 getStreamer().SwitchSection(CS);
3446 unsigned TmpReg = getATReg(IDLoc);
3450 if (emitPartialAddress(TOut, IDLoc, Sym))
3453 TOut.
emitRRX(isABI_N64() ? Mips::DADDiu : Mips::ADDiu, TmpReg, TmpReg,
3459 TOut.
emitRRI(Mips::LW, FirstReg, TmpReg, 0, IDLoc, STI);
3460 TOut.
emitRRI(Mips::LW,
nextReg(FirstReg), TmpReg, 4, IDLoc, STI);
3465 bool MipsAsmParser::expandLoadDoubleImmToFPR(
MCInst &Inst,
bool Is64FPU,
3471 "Invalid instruction operand.");
3478 unsigned TmpReg = Mips::ZERO;
3480 TmpReg = getATReg(IDLoc);
3485 if ((
Lo_32(ImmOp64) == 0) &&
3486 !((
Hi_32(ImmOp64) & 0xffff0000) && (
Hi_32(ImmOp64) & 0x0000ffff))) {
3488 if (TmpReg != Mips::ZERO &&
3489 loadImmediate(ImmOp64, TmpReg, Mips::NoRegister,
false,
false, IDLoc,
3492 TOut.
emitRR(Mips::DMTC1, FirstReg, TmpReg, IDLoc, STI);
3496 if (TmpReg != Mips::ZERO &&
3497 loadImmediate(
Hi_32(ImmOp64), TmpReg, Mips::NoRegister,
true,
false,
3501 if (hasMips32r2()) {
3502 TOut.
emitRR(Mips::MTC1, FirstReg, Mips::ZERO, IDLoc, STI);
3503 TOut.
emitRRR(Mips::MTHC1_D32, FirstReg, FirstReg, TmpReg, IDLoc, STI);
3505 TOut.
emitRR(Mips::MTC1,
nextReg(FirstReg), TmpReg, IDLoc, STI);
3506 TOut.
emitRR(Mips::MTC1, FirstReg, Mips::ZERO, IDLoc, STI);
3511 MCSection *CS = getStreamer().getCurrentSectionOnly();
3517 MCSymbol *Sym = getContext().createTempSymbol();
3523 getStreamer().SwitchSection(ReadOnlySection);
3524 getStreamer().EmitLabel(Sym, IDLoc);
3525 getStreamer().EmitValueToAlignment(8);
3526 getStreamer().EmitIntValue(ImmOp64, 8);
3527 getStreamer().SwitchSection(CS);
3529 if (emitPartialAddress(TOut, IDLoc, Sym))
3532 TOut.
emitRRX(Is64FPU ? Mips::LDC164 : Mips::LDC1, FirstReg, TmpReg,
3538 bool MipsAsmParser::expandUncondBranchMMPseudo(
MCInst &Inst,
SMLoc IDLoc,
3544 "unexpected number of operands");
3547 if (Offset.isExpr()) {
3554 assert(Offset.isImm() &&
"expected immediate operand kind");
3555 if (isInt<11>(Offset.getImm())) {
3558 if (inMicroMipsMode())
3559 Inst.
setOpcode(hasMips32r6() ? Mips::BC16_MMR6 : Mips::B16_MM);
3561 if (!isInt<17>(Offset.getImm()))
3562 return Error(IDLoc,
"branch target out of range");
3564 return Error(IDLoc,
"branch to misaligned address");
3587 assert(DstRegOp.
isReg() &&
"expected register operand kind");
3590 assert(ImmOp.isImm() &&
"expected immediate operand kind");
3593 assert((MemOffsetOp.isImm() || MemOffsetOp.isExpr()) &&
3594 "expected immediate or expression operand");
3596 bool IsLikely =
false;
3598 unsigned OpCode = 0;
3606 case Mips::BEQLImmMacro:
3607 OpCode = Mips::BEQL;
3610 case Mips::BNELImmMacro:
3611 OpCode = Mips::BNEL;
3619 int64_t ImmValue = ImmOp.getImm();
3620 if (ImmValue == 0) {
3624 TOut.
emitRRI(Mips::SLL, Mips::ZERO, Mips::ZERO, 0, IDLoc, STI);
3626 TOut.
emitRRX(OpCode, DstRegOp.
getReg(), Mips::ZERO, MemOffsetOp, IDLoc,
3629 warnIfNoMacro(IDLoc);
3631 unsigned ATReg = getATReg(IDLoc);
3635 if (loadImmediate(ImmValue, ATReg, Mips::NoRegister, !isGP64bit(),
true,
3642 TOut.
emitRRI(Mips::SLL, Mips::ZERO, Mips::ZERO, 0, IDLoc, STI);
3644 TOut.
emitRRX(OpCode, DstRegOp.
getReg(), ATReg, MemOffsetOp, IDLoc, STI);
3652 assert((NumOp == 3 || NumOp == 4) &&
"unexpected operands number");
3653 unsigned StartOp = NumOp == 3 ? 0 : 1;
3656 assert(DstRegOp.
isReg() &&
"expected register operand kind");
3658 assert(BaseRegOp.isReg() &&
"expected register operand kind");
3663 unsigned DstReg = DstRegOp.
getReg();
3664 unsigned BaseReg = BaseRegOp.getReg();
3665 unsigned TmpReg = DstReg;
3669 unsigned DstRegClassID =
3670 getContext().getRegisterInfo()->getRegClass(DstRegClass).getID();
3671 bool IsGPR = (DstRegClassID == Mips::GPR32RegClassID) ||
3672 (DstRegClassID == Mips::GPR64RegClassID);
3674 if (!IsLoad || !IsGPR || (BaseReg == DstReg)) {
3677 TmpReg = getATReg(IDLoc);
3682 auto emitInstWithOffset = [&](
const MCOperand &Off) {
3684 TOut.
emitRRX(OpCode, DstReg, TmpReg, Off, IDLoc, STI);
3686 TOut.
emitRRRX(OpCode, DstReg, DstReg, TmpReg, Off, IDLoc, STI);
3689 if (OffsetOp.isImm()) {
3690 int64_t LoOffset = OffsetOp.getImm() & 0xffff;
3691 int64_t HiOffset = OffsetOp.getImm() & ~0xffff;
3695 if (LoOffset & 0x8000)
3696 HiOffset += 0x10000;
3698 bool IsLargeOffset = HiOffset != 0;
3700 if (IsLargeOffset) {
3701 bool Is32BitImm =
isInt<32>(OffsetOp.getImm());
3702 if (loadImmediate(HiOffset, TmpReg, Mips::NoRegister, Is32BitImm,
true,
3707 if (BaseReg != Mips::ZERO && BaseReg != Mips::ZERO_64)
3709 TmpReg, BaseReg, IDLoc, STI);
3714 if (OffsetOp.isExpr()) {
3723 if (!OffsetOp.getExpr()->evaluateAsRelocatable(Res,
nullptr,
nullptr)) {
3724 Error(IDLoc,
"expected relocatable expression");
3727 if (Res.
getSymB() !=
nullptr) {
3728 Error(IDLoc,
"expected relocatable expression with only one symbol");
3732 loadAndAddSymbolAddress(Res.
getSymA(), TmpReg, BaseReg,
3741 const MCExpr *OffExpr = OffsetOp.getExpr();
3753 TOut.
emitRX(Mips::LUi, TmpReg, HighestOperand, IDLoc, STI);
3754 TOut.
emitRRX(Mips::DADDiu, TmpReg, TmpReg, HigherOperand, IDLoc, STI);
3755 TOut.
emitRRI(Mips::DSLL, TmpReg, TmpReg, 16, IDLoc, STI);
3756 TOut.
emitRRX(Mips::DADDiu, TmpReg, TmpReg, HiOperand, IDLoc, STI);
3757 TOut.
emitRRI(Mips::DSLL, TmpReg, TmpReg, 16, IDLoc, STI);
3758 if (BaseReg != Mips::ZERO && BaseReg != Mips::ZERO_64)
3759 TOut.
emitRRR(Mips::DADDu, TmpReg, TmpReg, BaseReg, IDLoc, STI);
3760 emitInstWithOffset(LoOperand);
3763 TOut.
emitRX(Mips::LUi, TmpReg, HiOperand, IDLoc, STI);
3764 if (BaseReg != Mips::ZERO)
3765 TOut.
emitRRR(Mips::ADDu, TmpReg, TmpReg, BaseReg, IDLoc, STI);
3767 emitInstWithOffset(LoOperand);
3779 assert((NumOp == 3 || NumOp == 4) &&
"unexpected operands number");
3780 unsigned StartOp = NumOp == 3 ? 0 : 1;
3783 assert(DstRegOp.
isReg() &&
"expected register operand kind");
3785 assert(BaseRegOp.isReg() &&
"expected register operand kind");
3790 unsigned DstReg = DstRegOp.
getReg();
3791 unsigned BaseReg = BaseRegOp.getReg();
3792 unsigned TmpReg = DstReg;
3796 unsigned DstRegClassID =
3797 getContext().getRegisterInfo()->getRegClass(DstRegClass).getID();
3798 bool IsGPR = (DstRegClassID == Mips::GPR32RegClassID) ||
3799 (DstRegClassID == Mips::GPR64RegClassID);
3801 if (!IsLoad || !IsGPR || (BaseReg == DstReg)) {
3804 TmpReg = getATReg(IDLoc);
3809 auto emitInst = [&]() {
3817 if (OffsetOp.isImm()) {
3818 loadImmediate(OffsetOp.getImm(), TmpReg, BaseReg, !ABI.
ArePtrs64bit(),
true,
3824 if (OffsetOp.isExpr()) {
3825 loadAndAddSymbolAddress(OffsetOp.getExpr(), TmpReg, BaseReg,
3834 bool MipsAsmParser::expandLoadStoreMultiple(
MCInst &Inst,
SMLoc IDLoc,
3839 unsigned NewOpcode = Opcode == Mips::SWM_MM ? Mips::SWM32_MM : Mips::LWM32_MM;
3843 Inst.
getOperand(OpNum - 3).
isReg() &&
"Invalid instruction operand.");
3852 if (inMicroMipsMode() && hasMips32r6())
3853 NewOpcode = Opcode == Mips::SWM_MM ? Mips::SWM16_MMR6 : Mips::LWM16_MMR6;
3855 NewOpcode = Opcode == Mips::SWM_MM ? Mips::SWM16_MM : Mips::LWM16_MM;
3863 bool MipsAsmParser::expandCondBranches(
MCInst &Inst,
SMLoc IDLoc,
3867 bool EmittedNoMacroWarning =
false;
3868 unsigned PseudoOpcode = Inst.
getOpcode();
3873 unsigned ZeroSrcOpcode, ZeroTrgOpcode;
3874 bool ReverseOrderSLT, IsUnsigned, IsLikely, AcceptsEquality;
3879 else if (TrgOp.
isImm()) {
3880 warnIfNoMacro(IDLoc);
3881 EmittedNoMacroWarning =
true;
3883 TrgReg = getATReg(IDLoc);
3887 switch(PseudoOpcode) {
3890 case Mips::BLTImmMacro:
3891 PseudoOpcode = Mips::BLT;
3893 case Mips::BLEImmMacro:
3894 PseudoOpcode = Mips::BLE;
3896 case Mips::BGEImmMacro:
3897 PseudoOpcode = Mips::BGE;
3899 case Mips::BGTImmMacro:
3900 PseudoOpcode = Mips::BGT;
3902 case Mips::BLTUImmMacro:
3903 PseudoOpcode = Mips::BLTU;
3905 case Mips::BLEUImmMacro:
3906 PseudoOpcode = Mips::BLEU;
3908 case Mips::BGEUImmMacro:
3909 PseudoOpcode = Mips::BGEU;
3911 case Mips::BGTUImmMacro:
3912 PseudoOpcode = Mips::BGTU;
3914 case Mips::BLTLImmMacro:
3915 PseudoOpcode = Mips::BLTL;
3917 case Mips::BLELImmMacro:
3918 PseudoOpcode = Mips::BLEL;
3920 case Mips::BGELImmMacro:
3921 PseudoOpcode = Mips::BGEL;
3923 case Mips::BGTLImmMacro:
3924 PseudoOpcode = Mips::BGTL;
3926 case Mips::BLTULImmMacro:
3927 PseudoOpcode = Mips::BLTUL;
3929 case Mips::BLEULImmMacro:
3930 PseudoOpcode = Mips::BLEUL;
3932 case Mips::BGEULImmMacro:
3933 PseudoOpcode = Mips::BGEUL;
3935 case Mips::BGTULImmMacro:
3936 PseudoOpcode = Mips::BGTUL;
3940 if (loadImmediate(TrgOp.
getImm(), TrgReg, Mips::NoRegister, !isGP64bit(),
3941 false, IDLoc, Out, STI))
3945 switch (PseudoOpcode) {
3950 AcceptsEquality =
false;
3951 ReverseOrderSLT =
false;
3953 ((PseudoOpcode == Mips::BLTU) || (PseudoOpcode == Mips::BLTUL));
3954 IsLikely = ((PseudoOpcode == Mips::BLTL) || (PseudoOpcode == Mips::BLTUL));
3955 ZeroSrcOpcode = Mips::BGTZ;
3956 ZeroTrgOpcode = Mips::BLTZ;
3962 AcceptsEquality =
true;
3963 ReverseOrderSLT =
true;
3965 ((PseudoOpcode == Mips::BLEU) || (PseudoOpcode == Mips::BLEUL));
3966 IsLikely = ((PseudoOpcode == Mips::BLEL) || (PseudoOpcode == Mips::BLEUL));
3967 ZeroSrcOpcode = Mips::BGEZ;
3968 ZeroTrgOpcode = Mips::BLEZ;
3974 AcceptsEquality =
true;
3975 ReverseOrderSLT =
false;
3977 ((PseudoOpcode == Mips::BGEU) || (PseudoOpcode == Mips::BGEUL));
3978 IsLikely = ((PseudoOpcode == Mips::BGEL) || (PseudoOpcode == Mips::BGEUL));
3979 ZeroSrcOpcode = Mips::BLEZ;
3980 ZeroTrgOpcode = Mips::BGEZ;
3986 AcceptsEquality =
false;
3987 ReverseOrderSLT =
true;
3989 ((PseudoOpcode == Mips::BGTU) || (PseudoOpcode == Mips::BGTUL));
3990 IsLikely = ((PseudoOpcode == Mips::BGTL) || (PseudoOpcode == Mips::BGTUL));
3991 ZeroSrcOpcode = Mips::BLTZ;
3992 ZeroTrgOpcode = Mips::BGTZ;
3998 bool IsTrgRegZero = (TrgReg == Mips::ZERO);
3999 bool IsSrcRegZero = (SrcReg == Mips::ZERO);
4000 if (IsSrcRegZero && IsTrgRegZero) {
4004 if (PseudoOpcode == Mips::BLT) {
4009 if (PseudoOpcode == Mips::BLE) {
4012 Warning(IDLoc,
"branch is always taken");
4015 if (PseudoOpcode == Mips::BGE) {
4018 Warning(IDLoc,
"branch is always taken");
4021 if (PseudoOpcode == Mips::BGT) {
4026 if (PseudoOpcode == Mips::BGTU) {
4027 TOut.
emitRRX(Mips::BNE, Mips::ZERO, Mips::ZERO,
4031 if (AcceptsEquality) {
4034 TOut.
emitRRX(Mips::BEQ, Mips::ZERO, Mips::ZERO,
4036 Warning(IDLoc,
"branch is always taken");
4043 if (IsSrcRegZero || IsTrgRegZero) {
4044 if ((IsSrcRegZero && PseudoOpcode == Mips::BGTU) ||
4045 (IsTrgRegZero && PseudoOpcode == Mips::BLTU)) {
4052 if ((IsSrcRegZero && PseudoOpcode == Mips::BLEU) ||
4053 (IsTrgRegZero && PseudoOpcode == Mips::BGEU)) {
4059 TOut.
emitRRX(Mips::BEQ, Mips::ZERO, Mips::ZERO,
4061 Warning(IDLoc,
"branch is always taken");
4077 TOut.
emitRRX(AcceptsEquality ? Mips::BEQ : Mips::BNE,
4078 IsSrcRegZero ? TrgReg : SrcReg, Mips::ZERO,
4085 TOut.
emitRX(IsSrcRegZero ? ZeroSrcOpcode : ZeroTrgOpcode,
4086 IsSrcRegZero ? TrgReg : SrcReg,
4093 unsigned ATRegNum = getATReg(IDLoc);
4097 if (!EmittedNoMacroWarning)
4098 warnIfNoMacro(IDLoc);
4115 TOut.
emitRRR(IsUnsigned ? Mips::SLTu : Mips::SLT, ATRegNum,
4116 ReverseOrderSLT ? TrgReg : SrcReg,
4117 ReverseOrderSLT ? SrcReg : TrgReg, IDLoc, STI);
4119 TOut.
emitRRX(IsLikely ? (AcceptsEquality ? Mips::BEQL : Mips::BNEL)
4120 : (AcceptsEquality ? Mips::BEQ : Mips::BNE),
4136 const bool IsMips64,
const bool Signed) {
4139 warnIfNoMacro(IDLoc);
4142 assert(RdRegOp.
isReg() &&
"expected register operand kind");
4143 unsigned RdReg = RdRegOp.
getReg();
4146 assert(RsRegOp.
isReg() &&
"expected register operand kind");
4147 unsigned RsReg = RsRegOp.
getReg();
4154 "expected register or immediate operand kind");
4158 ImmValue = RtOp.
getImm();
4165 DivOp = Signed ? Mips::DSDIV : Mips::DUDIV;
4166 ZeroReg = Mips::ZERO_64;
4170 ZeroReg = Mips::ZERO;
4174 bool UseTraps = useTraps();
4177 bool isDiv = Opcode == Mips::SDivMacro || Opcode == Mips::SDivIMacro ||
4178 Opcode == Mips::UDivMacro || Opcode == Mips::UDivIMacro ||
4179 Opcode == Mips::DSDivMacro || Opcode == Mips::DSDivIMacro ||
4180 Opcode == Mips::DUDivMacro || Opcode == Mips::DUDivIMacro;
4182 bool isRem = Opcode == Mips::SRemMacro || Opcode == Mips::SRemIMacro ||
4183 Opcode == Mips::URemMacro || Opcode == Mips::URemIMacro ||
4184 Opcode == Mips::DSRemMacro || Opcode == Mips::DSRemIMacro ||
4185 Opcode == Mips::DURemMacro || Opcode == Mips::DURemIMacro;
4188 unsigned ATReg = getATReg(IDLoc);
4192 if (ImmValue == 0) {
4194 TOut.
emitRRI(Mips::TEQ, ZeroReg, ZeroReg, 0x7, IDLoc, STI);
4196 TOut.
emitII(Mips::BREAK, 0x7, 0, IDLoc, STI);
4200 if (isRem && (ImmValue == 1 || (Signed && (ImmValue == -1)))) {
4203 }
else if (isDiv && ImmValue == 1) {
4206 }
else if (isDiv && Signed && ImmValue == -1) {
4207 TOut.
emitRRR(SubOp, RdReg, ZeroReg, RsReg, IDLoc, STI);
4210 if (loadImmediate(ImmValue, ATReg, Mips::NoRegister,
isInt<32>(ImmValue),
4211 false, Inst.
getLoc(), Out, STI))
4213 TOut.
emitRR(DivOp, RsReg, ATReg, IDLoc, STI);
4224 if (RtReg == Mips::ZERO || RtReg == Mips::ZERO_64) {
4226 TOut.
emitRRI(Mips::TEQ, ZeroReg, ZeroReg, 0x7, IDLoc, STI);
4229 TOut.
emitII(Mips::BREAK, 0x7, 0, IDLoc, STI);
4235 if (isRem && (RdReg == Mips::ZERO || RdReg == Mips::ZERO_64)) {
4236 TOut.
emitRR(DivOp, RsReg, RtReg, IDLoc, STI);
4246 TOut.
emitRRI(Mips::TEQ, RtReg, ZeroReg, 0x7, IDLoc, STI);
4251 TOut.
emitRRX(Mips::BNE, RtReg, ZeroReg, LabelOp, IDLoc, STI);
4254 TOut.
emitRR(DivOp, RsReg, RtReg, IDLoc, STI);
4257 TOut.
emitII(Mips::BREAK, 0x7, 0, IDLoc, STI);
4267 unsigned ATReg = getATReg(IDLoc);
4274 TOut.
emitRRI(Mips::ADDiu, ATReg, ZeroReg, -1, IDLoc, STI);
4282 TOut.
emitRRX(Mips::BNE, RtReg, ATReg, LabelOpEnd, IDLoc, STI);
4285 TOut.
emitRRI(Mips::ADDiu, ATReg, ZeroReg, 1, IDLoc, STI);
4286 TOut.
emitDSLL(ATReg, ATReg, 63, IDLoc, STI);
4292 TOut.
emitRRI(Mips::TEQ, RsReg, ATReg, 0x6, IDLoc, STI);
4295 TOut.
emitRRX(Mips::BNE, RsReg, ATReg, LabelOpEnd, IDLoc, STI);
4297 TOut.
emitII(Mips::BREAK, 0x6, 0, IDLoc, STI);
4305 bool MipsAsmParser::expandTrunc(
MCInst &Inst,
bool IsDouble,
bool Is64FPU,
4318 if (hasMips1() && !hasMips2()) {
4319 unsigned ATReg = getATReg(IDLoc);
4325 TOut.
emitRRI(Mips::ORi, ATReg, ThirdReg, 0x3, IDLoc, STI);
4326 TOut.
emitRRI(Mips::XORi, ATReg, ATReg, 0x2, IDLoc, STI);
4329 TOut.
emitRR(IsDouble ? (Is64FPU ? Mips::CVT_W_D64 : Mips::CVT_W_D32)
4331 FirstReg, SecondReg, IDLoc, STI);
4337 TOut.
emitRR(IsDouble ? (Is64FPU ? Mips::TRUNC_W_D64 : Mips::TRUNC_W_D32)
4339 FirstReg, SecondReg, IDLoc, STI);
4344 bool MipsAsmParser::expandUlh(
MCInst &Inst,
bool Signed,
SMLoc IDLoc,
4346 if (hasMips32r6() || hasMips64r6()) {
4347 return Error(IDLoc,
"instruction not supported on mips32r6 or mips64r6");
4351 assert(DstRegOp.
isReg() &&
"expected register operand kind");
4353 assert(SrcRegOp.isReg() &&
"expected register operand kind");
4355 assert(OffsetImmOp.isImm() &&
"expected immediate operand kind");
4358 unsigned DstReg = DstRegOp.
getReg();
4359 unsigned SrcReg = SrcRegOp.getReg();
4360 int64_t OffsetValue = OffsetImmOp.getImm();
4364 warnIfNoMacro(IDLoc);
4365 unsigned ATReg = getATReg(IDLoc);
4370 if (IsLargeOffset) {
4371 if (loadImmediate(OffsetValue, ATReg, SrcReg, !ABI.
ArePtrs64bit(),
true,
4376 int64_t FirstOffset = IsLargeOffset ? 0 : OffsetValue;
4377 int64_t SecondOffset = IsLargeOffset ? 1 : (OffsetValue + 1);
4381 unsigned FirstLbuDstReg = IsLargeOffset ? DstReg : ATReg;
4382 unsigned SecondLbuDstReg = IsLargeOffset ? ATReg : DstReg;
4384 unsigned LbuSrcReg = IsLargeOffset ? ATReg : SrcReg;
4385 unsigned SllReg = IsLargeOffset ? DstReg : ATReg;
4387 TOut.emitRRI(Signed ? Mips::LB : Mips::LBu, FirstLbuDstReg, LbuSrcReg,
4388 FirstOffset, IDLoc, STI);
4389 TOut.emitRRI(Mips::LBu, SecondLbuDstReg, LbuSrcReg, SecondOffset, IDLoc, STI);
4390 TOut.emitRRI(Mips::SLL, SllReg, SllReg, 8, IDLoc, STI);
4391 TOut.emitRRR(
Mips::OR, DstReg, DstReg, ATReg, IDLoc, STI);
4398 if (hasMips32r6() || hasMips64r6()) {
4399 return Error(IDLoc,
"instruction not supported on mips32r6 or mips64r6");
4403 assert(DstRegOp.
isReg() &&
"expected register operand kind");
4405 assert(SrcRegOp.isReg() &&
"expected register operand kind");
4407 assert(OffsetImmOp.isImm() &&
"expected immediate operand kind");
4410 unsigned DstReg = DstRegOp.
getReg();
4411 unsigned SrcReg = SrcRegOp.getReg();
4412 int64_t OffsetValue = OffsetImmOp.getImm();
4414 warnIfNoMacro(IDLoc);
4415 unsigned ATReg = getATReg(IDLoc);
4420 if (IsLargeOffset) {
4421 if (loadImmediate(OffsetValue, ATReg, SrcReg, !ABI.
ArePtrs64bit(),
true,
4426 int64_t FirstOffset = IsLargeOffset ? 1 : (OffsetValue + 1);
4427 int64_t SecondOffset = IsLargeOffset ? 0 : OffsetValue;
4431 if (IsLargeOffset) {
4432 TOut.emitRRI(Mips::SB, DstReg, ATReg, FirstOffset, IDLoc, STI);
4433 TOut.emitRRI(
Mips::SRL, DstReg, DstReg, 8, IDLoc, STI);
4434 TOut.emitRRI(Mips::SB, DstReg, ATReg, SecondOffset, IDLoc, STI);
4435 TOut.emitRRI(Mips::LBu, ATReg, ATReg, 0, IDLoc, STI);
4436 TOut.emitRRI(Mips::SLL, DstReg, DstReg, 8, IDLoc, STI);
4437 TOut.emitRRR(
Mips::OR, DstReg, DstReg, ATReg, IDLoc, STI);
4439 TOut.emitRRI(Mips::SB, DstReg, SrcReg, FirstOffset, IDLoc, STI);
4440 TOut.emitRRI(
Mips::SRL, ATReg, DstReg, 8, IDLoc, STI);
4441 TOut.emitRRI(Mips::SB, ATReg, SrcReg, SecondOffset, IDLoc, STI);
4449 if (hasMips32r6() || hasMips64r6()) {
4450 return Error(IDLoc,
"instruction not supported on mips32r6 or mips64r6");
4454 assert(DstRegOp.
isReg() &&
"expected register operand kind");
4456 assert(SrcRegOp.isReg() &&
"expected register operand kind");
4458 assert(OffsetImmOp.isImm() &&
"expected immediate operand kind");
4461 unsigned DstReg = DstRegOp.
getReg();
4462 unsigned SrcReg = SrcRegOp.getReg();
4463 int64_t OffsetValue = OffsetImmOp.getImm();
4467 int64_t LxlOffset = IsLargeOffset ? 0 : OffsetValue;
4468 int64_t LxrOffset = IsLargeOffset ? 3 : (OffsetValue + 3);
4472 bool IsLoadInst = (Inst.
getOpcode() == Mips::Ulw);
4473 bool DoMove = IsLoadInst && (SrcReg == DstReg) && !IsLargeOffset;
4474 unsigned TmpReg = SrcReg;
4475 if (IsLargeOffset || DoMove) {
4476 warnIfNoMacro(IDLoc);
4477 TmpReg = getATReg(IDLoc);
4482 if (IsLargeOffset) {
4483 if (loadImmediate(OffsetValue, TmpReg, SrcReg, !ABI.
ArePtrs64bit(),
true,
4493 TOut.emitRRI(XWL, DstReg, TmpReg, LxlOffset, IDLoc, STI);
4494 TOut.emitRRI(XWR, DstReg, TmpReg, LxrOffset, IDLoc, STI);
4497 TOut.emitRRR(
Mips::OR, TmpReg, DstReg, Mips::ZERO, IDLoc, STI);
4516 warnIfNoMacro(IDLoc);
4523 OpCode = Mips::SLTu;
4530 TOut.
emitRRR(OpCode, DstReg, SrcReg, OpReg, IDLoc, STI);
4531 TOut.
emitRRI(Mips::XORi, DstReg, DstReg, 1, IDLoc, STI);
4548 unsigned OpRegCode, OpImmCode;
4550 warnIfNoMacro(IDLoc);
4554 case Mips::SGEImm64:
4555 OpRegCode = Mips::SLT;
4556 OpImmCode = Mips::SLTi;
4559 case Mips::SGEUImm64:
4560 OpRegCode = Mips::SLTu;
4561 OpImmCode = Mips::SLTiu;
4570 TOut.
emitRRI(OpImmCode, DstReg, SrcReg, ImmValue, IDLoc, STI);
4571 TOut.
emitRRI(Mips::XORi, DstReg, DstReg, 1, IDLoc, STI);
4573 unsigned ImmReg = DstReg;
4574 if (DstReg == SrcReg) {
4575 unsigned ATReg = getATReg(Inst.
getLoc());
4581 if (loadImmediate(ImmValue, ImmReg, Mips::NoRegister,
isInt<32>(ImmValue),
4582 false, IDLoc, Out, STI))
4585 TOut.
emitRRR(OpRegCode, DstReg, SrcReg, ImmReg, IDLoc, STI);
4586 TOut.
emitRRI(Mips::XORi, DstReg, DstReg, 1, IDLoc, STI);
4603 unsigned ImmReg = DstReg;
4607 warnIfNoMacro(IDLoc);
4611 case Mips::SGTImm64:
4615 case Mips::SGTUImm64:
4616 OpCode = Mips::SLTu;
4622 if (DstReg == SrcReg) {
4623 unsigned ATReg = getATReg(Inst.
getLoc());
4629 if (loadImmediate(ImmValue, ImmReg, Mips::NoRegister,
isInt<32>(ImmValue),
4630 false, IDLoc, Out, STI))
4634 TOut.
emitRRR(OpCode, DstReg, ImmReg, SrcReg, IDLoc, STI);
4639 bool MipsAsmParser::expandAliasImmediate(
MCInst &Inst,
SMLoc IDLoc,
4649 unsigned ATReg = Mips::NoRegister;
4650 unsigned FinalDstReg = Mips::NoRegister;
4657 unsigned FinalOpcode = Inst.
getOpcode();
4659 if (DstReg == SrcReg) {
4660 ATReg = getATReg(Inst.
getLoc());
4663 FinalDstReg = DstReg;
4667 if (!loadImmediate(ImmValue, DstReg, Mips::NoRegister, Is32Bit,
false,
4668 Inst.
getLoc(), Out, STI)) {
4669 switch (FinalOpcode) {
4676 FinalOpcode = Mips::ADDu;
4682 FinalOpcode = Mips::NOR;
4688 FinalOpcode = Mips::SLT;
4691 FinalOpcode = Mips::SLTu;
4697 FinalOpcode = Mips::ADD_MM;
4699 case Mips::ADDiu_MM:
4700 FinalOpcode = Mips::ADDu_MM;
4703 FinalOpcode = Mips::AND_MM;
4706 FinalOpcode = Mips::OR_MM;
4709 FinalOpcode = Mips::SLT_MM;
4711 case Mips::SLTiu_MM:
4712 FinalOpcode = Mips::SLTu_MM;
4715 FinalOpcode = Mips::XOR_MM;
4718 FinalOpcode = Mips::AND64;
4720 case Mips::NORImm64:
4721 FinalOpcode = Mips::NOR64;
4724 FinalOpcode = Mips::OR64;
4726 case Mips::SLTImm64:
4727 FinalOpcode = Mips::SLT64;
4729 case Mips::SLTUImm64:
4730 FinalOpcode = Mips::SLTu64;
4733 FinalOpcode = Mips::XOR64;
4737 if (FinalDstReg == Mips::NoRegister)
4738 TOut.
emitRRR(FinalOpcode, DstReg, DstReg, SrcReg, IDLoc, STI);
4740 TOut.
emitRRR(FinalOpcode, FinalDstReg, FinalDstReg, DstReg, IDLoc, STI);
4749 unsigned ATReg = Mips::NoRegister;
4753 unsigned TmpReg = DReg;
4755 unsigned FirstShift = Mips::NOP;
4756 unsigned SecondShift = Mips::NOP;
4758 if (hasMips32r2()) {
4760 TmpReg = getATReg(Inst.
getLoc());
4766 TOut.
emitRRR(Mips::SUBu, TmpReg, Mips::ZERO, TReg, Inst.
getLoc(), STI);
4767 TOut.
emitRRR(Mips::ROTRV, DReg, SReg, TmpReg, Inst.
getLoc(), STI);
4772 TOut.
emitRRR(Mips::ROTRV, DReg, SReg, TReg, Inst.
getLoc(), STI);
4784 FirstShift = Mips::SRLV;
4785 SecondShift = Mips::SLLV;
4788 FirstShift = Mips::SLLV;
4789 SecondShift = Mips::SRLV;
4793 ATReg = getATReg(Inst.
getLoc());
4797 TOut.
emitRRR(Mips::SUBu, ATReg, Mips::ZERO, TReg, Inst.
getLoc(), STI);
4798 TOut.
emitRRR(FirstShift, ATReg, SReg, ATReg, Inst.
getLoc(), STI);
4799 TOut.
emitRRR(SecondShift, DReg, SReg, TReg, Inst.
getLoc(), STI);
4808 bool MipsAsmParser::expandRotationImm(
MCInst &Inst,
SMLoc IDLoc,
4812 unsigned ATReg = Mips::NoRegister;
4817 unsigned FirstShift = Mips::NOP;
4818 unsigned SecondShift = Mips::NOP;
4820 if (hasMips32r2()) {
4822 uint64_t MaxShift = 32;
4823 uint64_t ShiftValue = ImmValue;
4825 ShiftValue = MaxShift - ImmValue;
4839 if (ImmValue == 0) {
4848 FirstShift = Mips::SLL;
4853 SecondShift = Mips::SLL;
4857 ATReg = getATReg(Inst.
getLoc());
4861 TOut.
emitRRI(FirstShift, ATReg, SReg, ImmValue, Inst.
getLoc(), STI);
4862 TOut.
emitRRI(SecondShift, DReg, SReg, 32 - ImmValue, Inst.
getLoc(), STI);
4874 unsigned ATReg = Mips::NoRegister;
4878 unsigned TmpReg = DReg;
4880 unsigned FirstShift = Mips::NOP;
4881 unsigned SecondShift = Mips::NOP;
4883 if (hasMips64r2()) {
4884 if (TmpReg == SReg) {
4885 TmpReg = getATReg(Inst.
getLoc());
4891 TOut.
emitRRR(Mips::DSUBu, TmpReg, Mips::ZERO, TReg, Inst.
getLoc(), STI);
4892 TOut.
emitRRR(Mips::DROTRV, DReg, SReg, TmpReg, Inst.
getLoc(), STI);
4897 TOut.
emitRRR(Mips::DROTRV, DReg, SReg, TReg, Inst.
getLoc(), STI);
4909 FirstShift = Mips::DSRLV;
4910 SecondShift = Mips::DSLLV;
4913 FirstShift = Mips::DSLLV;
4914 SecondShift = Mips::DSRLV;
4918 ATReg = getATReg(Inst.
getLoc());
4922 TOut.
emitRRR(Mips::DSUBu, ATReg, Mips::ZERO, TReg, Inst.
getLoc(), STI);
4923 TOut.
emitRRR(FirstShift, ATReg, SReg, ATReg, Inst.
getLoc(), STI);
4924 TOut.
emitRRR(SecondShift, DReg, SReg, TReg, Inst.
getLoc(), STI);
4933 bool MipsAsmParser::expandDRotationImm(
MCInst &Inst,
SMLoc IDLoc,
4937 unsigned ATReg = Mips::NoRegister;
4942 unsigned FirstShift = Mips::NOP;
4943 unsigned SecondShift = Mips::NOP;
4947 if (hasMips64r2()) {
4948 unsigned FinalOpcode = Mips::NOP;
4950 FinalOpcode = Mips::DROTR;
4951 else if (ImmValue % 32 == 0)
4952 FinalOpcode = Mips::DROTR32;
4953 else if ((ImmValue >= 1) && (ImmValue <= 32)) {
4955 FinalOpcode = Mips::DROTR32;
4957 FinalOpcode = Mips::DROTR;
4958 }
else if (ImmValue >= 33) {
4960 FinalOpcode = Mips::DROTR;
4962 FinalOpcode = Mips::DROTR32;
4965 uint64_t ShiftValue = ImmValue % 32;
4967 ShiftValue = (32 - ImmValue % 32) % 32;
4969 TOut.
emitRRI(FinalOpcode, DReg, SReg, ShiftValue, Inst.
getLoc(), STI);
4975 if (ImmValue == 0) {
4976 TOut.
emitRRI(Mips::DSRL, DReg, SReg, 0, Inst.
getLoc(), STI);
4984 if ((ImmValue >= 1) && (ImmValue <= 31)) {
4985 FirstShift = Mips::DSLL;
4986 SecondShift = Mips::DSRL32;
4988 if (ImmValue == 32) {
4989 FirstShift = Mips::DSLL32;
4990 SecondShift = Mips::DSRL32;
4992 if ((ImmValue >= 33) && (ImmValue <= 63)) {
4993 FirstShift = Mips::DSLL32;
4994 SecondShift = Mips::DSRL;
4998 if ((ImmValue >= 1) && (ImmValue <= 31)) {
4999 FirstShift = Mips::DSRL;
5000 SecondShift = Mips::DSLL32;
5002 if (ImmValue == 32) {
5003 FirstShift = Mips::DSRL32;
5004 SecondShift = Mips::DSLL32;
5006 if ((ImmValue >= 33) && (ImmValue <= 63)) {
5007 FirstShift = Mips::DSRL32;
5008 SecondShift = Mips::DSLL;
5013 ATReg = getATReg(Inst.
getLoc());
5017 TOut.
emitRRI(FirstShift, ATReg, SReg, ImmValue % 32, Inst.
getLoc(), STI);
5018 TOut.
emitRRI(SecondShift, DReg, SReg, (32 - ImmValue % 32) % 32,
5034 TOut.
emitRI(Mips::BGEZ, SecondRegOp, 8, IDLoc, STI);
5035 if (FirstRegOp != SecondRegOp)
5036 TOut.
emitRRR(Mips::ADDu, FirstRegOp, SecondRegOp, Mips::ZERO, IDLoc, STI);
5047 unsigned ATReg = Mips::NoRegister;
5052 ATReg = getATReg(IDLoc);
5056 loadImmediate(ImmValue, ATReg, Mips::NoRegister,
true,
false, IDLoc, Out,
5060 SrcReg, ATReg, IDLoc, STI);
5070 unsigned ATReg = Mips::NoRegister;
5075 ATReg = getATReg(Inst.
getLoc());
5080 SrcReg, TmpReg, IDLoc, STI);
5085 DstReg, DstReg, 0x1F, IDLoc, STI);
5090 TOut.
emitRRI(Mips::TNE, DstReg, ATReg, 6, IDLoc, STI);
5097 TOut.
emitRRX(Mips::BEQ, DstReg, ATReg, LabelOp, IDLoc, STI);
5098 if (AssemblerOptions.
back()->isReorder())
5100 TOut.
emitII(Mips::BREAK, 6, 0, IDLoc, STI);
5112 unsigned ATReg = Mips::NoRegister;
5117 ATReg = getATReg(IDLoc);
5121 TOut.
emitRR(Inst.
getOpcode() == Mips::MULOUMacro ? Mips::MULTu : Mips::DMULTu,
5122 SrcReg, TmpReg, IDLoc, STI);
5127 TOut.
emitRRI(Mips::TNE, ATReg, Mips::ZERO, 6, IDLoc, STI);
5134 TOut.
emitRRX(Mips::BEQ, ATReg, Mips::ZERO, LabelOp, IDLoc, STI);
5135 if (AssemblerOptions.
back()->isReorder())
5137 TOut.
emitII(Mips::BREAK, 6, 0, IDLoc, STI);
5152 TOut.
emitRR(Mips::DMULTu, SrcReg, TmpReg, IDLoc, STI);
5163 bool MipsAsmParser::expandLoadStoreDMacro(
MCInst &Inst,
SMLoc IDLoc,
5170 warnIfNoMacro(IDLoc);
5173 unsigned Opcode = IsLoad ? Mips::LW : Mips::SW;
5175 unsigned SecondReg =
nextReg(FirstReg);
5180 warnIfRegIndexIsAT(FirstReg, IDLoc);
5183 "Offset for load macro is not immediate!");
5186 signed NextOffset = FirstOffset.
getImm() + 4;
5194 if (FirstReg != BaseReg || !IsLoad) {
5195 TOut.
emitRRX(Opcode, FirstReg, BaseReg, FirstOffset, IDLoc, STI);
5196 TOut.
emitRRX(Opcode, SecondReg, BaseReg, SecondOffset, IDLoc, STI);
5198 TOut.
emitRRX(Opcode, SecondReg, BaseReg, SecondOffset, IDLoc, STI);
5199 TOut.
emitRRX(Opcode, FirstReg, BaseReg, FirstOffset, IDLoc, STI);
5211 bool MipsAsmParser::expandStoreDM1Macro(
MCInst &Inst,
SMLoc IDLoc,
5217 warnIfNoMacro(IDLoc);
5220 unsigned Opcode = Mips::SWC1;
5222 unsigned SecondReg =
nextReg(FirstReg);
5227 warnIfRegIndexIsAT(FirstReg, IDLoc);
5230 "Offset for macro is not immediate!");
5233 signed NextOffset = FirstOffset.
getImm() + 4;
5239 if (!IsLittleEndian)
5242 TOut.
emitRRX(Opcode, FirstReg, BaseReg, FirstOffset, IDLoc, STI);
5243 TOut.
emitRRX(Opcode, SecondReg, BaseReg, SecondOffset, IDLoc, STI);
5261 warnIfNoMacro(IDLoc);
5263 if (SrcReg != Mips::ZERO && OpReg != Mips::ZERO) {
5265 TOut.
emitRRI(Mips::SLTiu, DstReg, DstReg, 1, IDLoc, STI);
5269 unsigned Reg = SrcReg == Mips::ZERO ? OpReg : SrcReg;
5270 TOut.
emitRRI(Mips::SLTiu, DstReg, Reg, 1, IDLoc, STI);
5287 warnIfNoMacro(IDLoc);
5290 TOut.
emitRRI(Mips::SLTiu, DstReg, SrcReg, 1, IDLoc, STI);
5294 if (SrcReg == Mips::ZERO) {
5295 Warning(IDLoc,
"comparison is always false");
5296 TOut.
emitRRR(isGP64bit() ? Mips::DADDu : Mips::ADDu,
5297 DstReg, SrcReg, SrcReg, IDLoc, STI);
5302 if (Imm > -0x8000 && Imm < 0) {
5304 Opc = isGP64bit() ? Mips::DADDiu : Mips::ADDiu;
5310 unsigned ATReg = getATReg(IDLoc);
5314 if (loadImmediate(Imm, ATReg, Mips::NoRegister,
true, isGP64bit(), IDLoc,
5319 TOut.
emitRRI(Mips::SLTiu, DstReg, DstReg, 1, IDLoc, STI);
5323 TOut.
emitRRI(Opc, DstReg, SrcReg, Imm, IDLoc, STI);
5324 TOut.
emitRRI(Mips::SLTiu, DstReg, DstReg, 1, IDLoc, STI);
5387 case Mips::F0:
return Mips::ZERO;
5388 case Mips::F1:
return Mips::AT;
5389 case Mips::F2:
return Mips::V0;
5390 case Mips::F3:
return Mips::V1;
5391 case Mips::F4:
return Mips::A0;
5392 case Mips::F5:
return Mips::A1;
5393 case Mips::F6:
return Mips::A2;
5394 case Mips::F7:
return Mips::A3;
5395 case Mips::F8:
return Mips::T0;
5397 case Mips::F10:
return Mips::T2;
5398 case Mips::F11:
return Mips::T3;
5399 case Mips::F12:
return Mips::T4;
5400 case Mips::F13:
return Mips::T5;
5401 case Mips::F14:
return Mips::T6;
5402 case Mips::F15:
return Mips::T7;
5403 case Mips::F16:
return Mips::S0;
5404 case Mips::F17:
return Mips::S1;
5405 case Mips::F18:
return Mips::S2;
5406 case Mips::F19:
return Mips::S3;
5407 case Mips::F20:
return Mips::S4;
5408 case Mips::F21:
return Mips::S5;
5409 case Mips::F22:
return Mips::S6;
5410 case Mips::F23:
return Mips::S7;
5412 case Mips::F25:
return Mips::T9;
5413 case Mips::F26:
return Mips::K0;
5414 case Mips::F27:
return Mips::K1;
5415 case Mips::F28:
return Mips::GP;
5416 case Mips::F29:
return Mips::SP;
5417 case Mips::F30:
return Mips::FP;
5426 case Mips::COP00:
return Mips::ZERO;
5427 case Mips::COP01:
return Mips::AT;
5428 case Mips::COP02:
return Mips::V0;
5429 case Mips::COP03:
return Mips::V1;
5430 case Mips::COP04:
return Mips::A0;
5431 case Mips::COP05:
return Mips::A1;
5432 case Mips::COP06:
return Mips::A2;
5433 case Mips::COP07:
return Mips::A3;
5434 case Mips::COP08:
return Mips::T0;
5436 case Mips::COP010:
return Mips::T2;
5437 case Mips::COP011:
return Mips::T3;
5438 case Mips::COP012:
return Mips::T4;
5439 case Mips::COP013:
return Mips::T5;
5440 case Mips::COP014:
return Mips::T6;
5441 case Mips::COP015:
return Mips::T7;
5442 case Mips::COP016:
return Mips::S0;
5443 case Mips::COP017:
return Mips::S1;
5444 case Mips::COP018:
return Mips::S2;
5445 case Mips::COP019:
return Mips::S3;
5446 case Mips::COP020:
return Mips::S4;
5447 case Mips::COP021:
return Mips::S5;
5448 case Mips::COP022:
return Mips::S6;
5449 case Mips::COP023:
return Mips::S7;
5450 case Mips::COP024:
return Mips::T8;
5451 case Mips::COP025:
return Mips::T9;
5452 case Mips::COP026:
return Mips::K0;
5453 case Mips::COP027:
return Mips::K1;
5454 case Mips::COP028:
return Mips::GP;
5455 case Mips::COP029:
return Mips::SP;
5456 case Mips::COP030:
return Mips::FP;
5457 case Mips::COP031:
return Mips::RA;
5471 bool IsMFTR =
false;
5529 TOut.
emitRRIII(IsMFTR ? Mips::MFTR : Mips::MTTR, Op0, Op1, u, sel, h, IDLoc,
5540 warnIfNoMacro(IDLoc);
5543 unsigned Opcode = Inst.
getOpcode() == Mips::SaaAddr ? Mips::SAA : Mips::SAAD;
5548 if (BaseOp.
isImm()) {
5549 int64_t ImmValue = BaseOp.
getImm();
5550 if (ImmValue == 0) {
5551 TOut.
emitRR(Opcode, RtReg, BaseReg, IDLoc, STI);
5556 unsigned ATReg = getATReg(IDLoc);
5560 if (expandLoadAddress(ATReg, BaseReg, BaseOp, !isGP64bit(), IDLoc, Out, STI))
5563 TOut.
emitRR(Opcode, RtReg, ATReg, IDLoc, STI);
5568 MipsAsmParser::checkEarlyTargetMatchPredicate(
MCInst &Inst,
5572 return Match_Success;
5575 if (static_cast<MipsOperand &>(*Operands[1])
5576 .isValidForTie(static_cast<MipsOperand &>(*Operands[2])))
5577 return Match_Success;
5578 return Match_RequiresSameSrcAndDst;
5582 unsigned MipsAsmParser::checkTargetMatchPredicate(
MCInst &Inst) {
5589 return Match_RequiresNoZeroRegister;
5590 return Match_Success;
5596 case Mips::JALR_HB64:
5597 case Mips::JALRC_HB_MMR6:
5598 case Mips::JALRC_MMR6:
5600 return Match_RequiresDifferentSrcAndDst;
5601 return Match_Success;
5604 return Match_RequiresDifferentSrcAndDst;
5605 return Match_Success;
5608 return Match_NonZeroOperandForSync;
5609 return Match_Success;
5615 return Match_NonZeroOperandForMTCX;
5616 return Match_Success;
5629 case Mips::BLEZC:
case Mips::BLEZC_MMR6:
5630 case Mips::BGEZC:
case Mips::BGEZC_MMR6:
5631 case Mips::BGTZC:
case Mips::BGTZC_MMR6:
5632 case Mips::BLTZC:
case Mips::BLTZC_MMR6:
5633 case Mips::BEQZC:
case Mips::BEQZC_MMR6:
5634 case Mips::BNEZC:
case Mips::BNEZC_MMR6:
5643 return Match_RequiresNoZeroRegister;
5644 return Match_Success;
5645 case Mips::BGEC:
case Mips::BGEC_MMR6:
5646 case Mips::BLTC:
case Mips::BLTC_MMR6:
5647 case Mips::BGEUC:
case Mips::BGEUC_MMR6:
5648 case Mips::BLTUC:
case Mips::BLTUC_MMR6:
5649 case Mips::BEQC:
case Mips::BEQC_MMR6:
5650 case Mips::BNEC:
case Mips::BNEC_MMR6:
5659 return Match_RequiresNoZeroRegister;
5662 return Match_RequiresNoZeroRegister;
5664 return Match_RequiresDifferentOperands;
5665 return Match_Success;
5668 "Operands must be immediates for dins!");
5671 if ((0 > (Pos + Size)) || ((Pos + Size) > 32))
5672 return Match_RequiresPosSizeRange0_32;
5673 return Match_Success;
5678 "Operands must be immediates for dinsm/dinsu!");
5681 if ((32 >= (Pos + Size)) || ((Pos + Size) > 64))
5682 return Match_RequiresPosSizeRange33_64;
5683 return Match_Success;
5687 "Operands must be immediates for DEXTM!");
5690 if ((1 > (Pos + Size)) || ((Pos + Size) > 63))
5691 return Match_RequiresPosSizeUImm6;
5692 return Match_Success;
5697 "Operands must be immediates for dextm/dextu!");
5700 if ((32 > (Pos + Size)) || ((Pos + Size) > 64))
5701 return Match_RequiresPosSizeRange33_64;
5702 return Match_Success;
5704 case Mips::CRC32B:
case Mips::CRC32CB:
5705 case Mips::CRC32H:
case Mips::CRC32CH:
5706 case Mips::CRC32W:
case Mips::CRC32CW:
5707 case Mips::CRC32D:
case Mips::CRC32CD:
5709 return Match_RequiresSameSrcAndDst;
5710 return Match_Success;
5716 return Match_NoFCCRegisterForCurrentISA;
5718 return Match_Success;
5724 if (ErrorInfo != ~0ULL && ErrorInfo < Operands.
size()) {
5725 SMLoc ErrorLoc = Operands[ErrorInfo]->getStartLoc();
5726 if (ErrorLoc ==
SMLoc())
5733 bool MipsAsmParser::MatchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
5737 bool MatchingInlineAsm) {
5739 unsigned MatchResult =
5740 MatchInstructionImpl(Operands, Inst, ErrorInfo, MatchingInlineAsm);
5742 switch (MatchResult) {
5744 if (processInstruction(Inst, IDLoc, Out, STI))
5747 case Match_MissingFeature:
5748 Error(IDLoc,
"instruction requires a CPU feature not currently enabled");
5750 case Match_InvalidOperand: {
5751 SMLoc ErrorLoc = IDLoc;
5752 if (ErrorInfo != ~0ULL) {
5753 if (ErrorInfo >= Operands.
size())
5754 return Error(IDLoc,
"too few operands for instruction");
5756 ErrorLoc = Operands[ErrorInfo]->getStartLoc();
5757 if (ErrorLoc ==
SMLoc())
5761 return Error(ErrorLoc,
"invalid operand for instruction");
5763 case Match_NonZeroOperandForSync:
5765 "s-type must be zero or unspecified for pre-MIPS32 ISAs");
5766 case Match_NonZeroOperandForMTCX:
5767 return Error(IDLoc,
"selector must be zero for pre-MIPS32 ISAs");
5768 case Match_MnemonicFail:
5769 return Error(IDLoc,
"invalid instruction");
5770 case Match_RequiresDifferentSrcAndDst:
5771 return Error(IDLoc,
"source and destination must be different");
5772 case Match_RequiresDifferentOperands:
5773 return Error(IDLoc,
"registers must be different");
5774 case Match_RequiresNoZeroRegister:
5775 return Error(IDLoc,
"invalid operand ($zero) for instruction");
5776 case Match_RequiresSameSrcAndDst:
5777 return Error(IDLoc,
"source and destination must match");
5778 case Match_NoFCCRegisterForCurrentISA:
5780 "non-zero fcc register doesn't exist in current ISA level");
5785 "expected 1-bit unsigned immediate");
5788 "expected 2-bit unsigned immediate");
5791 "expected immediate in range 1 .. 4");
5794 "expected 3-bit unsigned immediate");
5797 "expected 4-bit unsigned immediate");
5800 "expected 4-bit signed immediate");
5803 "expected 5-bit unsigned immediate");
5806 "expected 5-bit signed immediate");
5809 "expected immediate in range 1 .. 32");
5810 case Match_UImm5_32:
5812 "expected immediate in range 32 .. 63");
5813 case Match_UImm5_33:
5815 "expected immediate in range 33 .. 64");
5816 case Match_UImm5_0_Report_UImm6:
5820 "expected 6-bit unsigned immediate");
5821 case Match_UImm5_Lsl2:
5823 "expected both 7-bit unsigned immediate and multiple of 4");
5824 case Match_UImmRange2_64:
5826 "expected immediate in range 2 .. 64");
5829 "expected 6-bit unsigned immediate");
5830 case Match_UImm6_Lsl2:
5832 "expected both 8-bit unsigned immediate and multiple of 4");
5835 "expected 6-bit signed immediate");
5838 "expected 7-bit unsigned immediate");
5839 case Match_UImm7_N1:
5841 "expected immediate in range -1 .. 126");
5842 case Match_SImm7_Lsl2:
5844 "expected both 9-bit signed immediate and multiple of 4");
5847 "expected 8-bit unsigned immediate");
5848 case Match_UImm10_0:
5850 "expected 10-bit unsigned immediate");
5851 case Match_SImm10_0:
5853 "expected 10-bit signed immediate");
5854 case Match_SImm11_0:
5856 "expected 11-bit signed immediate");
5858 case Match_UImm16_Relaxed:
5859 case Match_UImm16_AltRelaxed:
5861 "expected 16-bit unsigned immediate");
5863 case Match_SImm16_Relaxed:
5865 "expected 16-bit signed immediate");
5866 case Match_SImm19_Lsl2:
5868 "expected both 19-bit signed immediate and multiple of 4");
5869 case Match_UImm20_0:
5871 "expected 20-bit unsigned immediate");
5872 case Match_UImm26_0:
5874 "expected 26-bit unsigned immediate");
5876 case Match_SImm32_Relaxed:
5878 "expected 32-bit signed immediate");
5879 case Match_UImm32_Coerced:
5881 "expected 32-bit immediate");
5882 case Match_MemSImm9:
5884 "expected memory with 9-bit signed offset");
5885 case Match_MemSImm10:
5887 "expected memory with 10-bit signed offset");
5888 case Match_MemSImm10Lsl1:
5890 "expected memory with 11-bit signed offset and multiple of 2");
5891 case Match_MemSImm10Lsl2:
5893 "expected memory with 12-bit signed offset and multiple of 4");
5894 case Match_MemSImm10Lsl3:
5896 "expected memory with 13-bit signed offset and multiple of 8");
5897 case Match_MemSImm11:
5899 "expected memory with 11-bit signed offset");
5900 case Match_MemSImm12:
5902 "expected memory with 12-bit signed offset");
5903 case Match_MemSImm16:
5905 "expected memory with 16-bit signed offset");
5906 case Match_MemSImmPtr:
5908 "expected memory with 32-bit signed offset");
5909 case Match_RequiresPosSizeRange0_32: {
5910 SMLoc ErrorStart = Operands[3]->getStartLoc();
5911 SMLoc ErrorEnd = Operands[4]->getEndLoc();
5912 return Error(ErrorStart,
"size plus position are not in the range 0 .. 32",
5913 SMRange(ErrorStart, ErrorEnd));
5915 case Match_RequiresPosSizeUImm6: {
5916 SMLoc ErrorStart = Operands[3]->getStartLoc();
5917 SMLoc ErrorEnd = Operands[4]->getEndLoc();
5918 return Error(ErrorStart,
"size plus position are not in the range 1 .. 63",
5919 SMRange(ErrorStart, ErrorEnd));
5921 case Match_RequiresPosSizeRange33_64: {
5922 SMLoc ErrorStart = Operands[3]->getStartLoc();
5923 SMLoc ErrorEnd = Operands[4]->getEndLoc();
5924 return Error(ErrorStart,
"size plus position are not in the range 33 .. 64",
5925 SMRange(ErrorStart, ErrorEnd));
5932 void MipsAsmParser::warnIfRegIndexIsAT(
unsigned RegIndex,
SMLoc Loc) {
5933 if (RegIndex != 0 && AssemblerOptions.
back()->getATRegIndex() == RegIndex)
5934 Warning(Loc,
"used $at (currently $" +
Twine(RegIndex) +
5935 ") without \".set noat\"");
5938 void MipsAsmParser::warnIfNoMacro(
SMLoc Loc) {
5939 if (!AssemblerOptions.
back()->isMacro())
5940 Warning(Loc,
"macro instruction expanded into multiple instructions");
5943 void MipsAsmParser::ConvertXWPOperands(
MCInst &Inst,
5947 "Unexpected instruction!");
5948 ((MipsOperand &)*Operands[1]).addGPR32ZeroAsmRegOperands(Inst, 1);
5949 int NextReg =
nextReg(((MipsOperand &)*Operands[1]).getGPR32Reg());
5951 ((MipsOperand &)*Operands[2]).addMemOperands(Inst, 2);
5955 MipsAsmParser::printWarningWithFixIt(
const Twine &Msg,
const Twine &FixMsg,
5956 SMRange Range,
bool ShowColors) {
5958 Range,
SMFixIt(Range, FixMsg),
5967 .
Cases(
"at",
"AT", 1)
6001 if (!(isABI_N32() || isABI_N64()))
6004 if (12 <= CC && CC <= 15) {
6006 AsmToken RegTok = getLexer().peekTok();
6015 assert(FixedName !=
"" &&
"Register name is not one of t4-t7.");
6017 printWarningWithFixIt(
"register names $t4-$t7 are only available in O32.",
6018 "Did you mean $" + FixedName +
"?", RegRange);
6024 if (8 <= CC && CC <= 11)
6040 int MipsAsmParser::matchHWRegsRegisterName(
StringRef Name) {
6044 .Case(
"hwr_cpunum", 0)
6045 .
Case(
"hwr_synci_step", 1)
6047 .
Case(
"hwr_ccres", 3)
6048 .
Case(
"hwr_ulr", 29)
6054 int MipsAsmParser::matchFPURegisterName(
StringRef Name) {
6055 if (Name[0] ==
'f') {
6067 int MipsAsmParser::matchFCCRegisterName(
StringRef Name) {
6080 int MipsAsmParser::matchACRegisterName(
StringRef Name) {
6093 int MipsAsmParser::matchMSA128RegisterName(
StringRef Name) {
6105 int MipsAsmParser::matchMSA128CtrlRegisterName(
StringRef Name) {
6111 .
Case(
"msaaccess", 2)
6113 .
Case(
"msamodify", 4)
6114 .
Case(
"msarequest", 5)
6116 .
Case(
"msaunmap", 7)
6122 bool MipsAsmParser::canUseATReg() {
6123 return AssemblerOptions.
back()->getATRegIndex() != 0;
6126 unsigned MipsAsmParser::getATReg(
SMLoc Loc) {
6127 unsigned ATIndex = AssemblerOptions.
back()->getATRegIndex();
6129 reportParseError(Loc,
6130 "pseudo-instruction requires $at, which is not available");
6134 (isGP64bit()) ? Mips::GPR64RegClassID : Mips::GPR32RegClassID, ATIndex);
6139 return *(getContext().getRegisterInfo()->getRegClass(RC).begin() + RegNo);
6159 switch (getLexer().getKind()) {
6178 MCSymbol *Sym = getContext().getOrCreateSymbol(
"$" + Identifier);
6183 Operands.
push_back(MipsOperand::CreateImm(Res, S, E, *
this));
6191 if (getParser().parseExpression(Expr))
6196 Operands.
push_back(MipsOperand::CreateImm(Expr, S, E, *
this));
6203 bool MipsAsmParser::ParseRegister(
unsigned &RegNo,
SMLoc &StartLoc,
6209 MipsOperand &Operand =
static_cast<MipsOperand &
>(*Operands.
front());
6210 StartLoc = Operand.getStartLoc();
6211 EndLoc = Operand.getEndLoc();
6217 if (Operand.isGPRAsmReg()) {
6219 RegNo = isGP64bit() ? Operand.getGPR64Reg() : Operand.getGPR32Reg();
6222 return (RegNo == (
unsigned)-1);
6226 return (RegNo == (
unsigned)-1);
6229 bool MipsAsmParser::parseMemOffset(
const MCExpr *&Res,
bool isParenExpr) {
6233 return getParser().parseParenExprOfDepth(0, Res, S);
6234 return getParser().parseExpression(Res);
6241 const MCExpr *IdVal =
nullptr;
6243 bool isParenExpr =
false;
6254 if (parseMemOffset(IdVal, isParenExpr))
6259 MipsOperand &Mnemonic =
static_cast<MipsOperand &
>(*Operands[0]);
6260 if (Mnemonic.getToken() ==
"la" || Mnemonic.getToken() ==
"dla") {
6263 Operands.
push_back(MipsOperand::CreateImm(IdVal, S, E, *
this));
6272 auto Base = MipsOperand::createGPRReg(
6273 0,
"0", getContext().getRegisterInfo(), S, E, *
this);
6275 MipsOperand::CreateMem(std::move(Base), IdVal, S, E, *
this));
6329 if (getParser().parseExpression(NextExpr))
6337 Res = parseAnyRegister(Operands);
6354 std::unique_ptr<MipsOperand>
op(
6355 static_cast<MipsOperand *>(Operands.
back().release()));
6360 if (
const MCBinaryExpr *BE = dyn_cast<MCBinaryExpr>(IdVal)) {
6362 if (IdVal->evaluateAsAbsolute(Imm))
6369 Operands.
push_back(MipsOperand::CreateMem(std::move(op), IdVal, S, E, *
this));
6373 bool MipsAsmParser::searchSymbolAlias(
OperandVector &Operands) {
6387 matchAnyRegisterNameWithoutDollar(Operands, DefSymbol.
substr(1), S);
6403 matchAnyRegisterWithoutDollar(Operands,
Entry->getValue(), S);
6415 MipsAsmParser::matchAnyRegisterNameWithoutDollar(
OperandVector &Operands,
6418 int Index = matchCPURegisterName(Identifier);
6420 Operands.
push_back(MipsOperand::createGPRReg(
6421 Index, Identifier, getContext().getRegisterInfo(), S,
6422 getLexer().getLoc(), *
this));
6426 Index = matchHWRegsRegisterName(Identifier);
6428 Operands.
push_back(MipsOperand::createHWRegsReg(
6429 Index, Identifier, getContext().getRegisterInfo(), S,
6430 getLexer().getLoc(), *
this));
6434 Index = matchFPURegisterName(Identifier);
6436 Operands.
push_back(MipsOperand::createFGRReg(
6437 Index, Identifier, getContext().getRegisterInfo(), S,
6438 getLexer().getLoc(), *
this));
6442 Index = matchFCCRegisterName(Identifier);
6444 Operands.
push_back(MipsOperand::createFCCReg(
6445 Index, Identifier, getContext().getRegisterInfo(), S,
6446 getLexer().getLoc(), *
this));
6450 Index = matchACRegisterName(Identifier);
6452 Operands.
push_back(MipsOperand::createACCReg(
6453 Index, Identifier, getContext().getRegisterInfo(), S,
6454 getLexer().getLoc(), *
this));
6458 Index = matchMSA128RegisterName(Identifier);
6460 Operands.
push_back(MipsOperand::createMSA128Reg(
6461 Index, Identifier, getContext().getRegisterInfo(), S,
6462 getLexer().getLoc(), *
this));
6466 Index = matchMSA128CtrlRegisterName(Identifier);
6468 Operands.
push_back(MipsOperand::createMSACtrlReg(
6469 Index, Identifier, getContext().getRegisterInfo(), S,
6470 getLexer().getLoc(), *
this));
6478 MipsAsmParser::matchAnyRegisterWithoutDollar(
OperandVector &Operands,
6484 matchAnyRegisterNameWithoutDollar(Operands, Identifier, S);
6489 if (RegNum < 0 || RegNum > 31) {
6493 Error(getLexer().getLoc(),
"invalid register number");
6495 Operands.
push_back(MipsOperand::createNumericReg(
6496 RegNum, Token.
getString(), getContext().getRegisterInfo(), S,
6508 auto Token = getLexer().peekTok(
false);
6509 return matchAnyRegisterWithoutDollar(Operands, Token, S);
6517 auto Token = Parser.
getTok();
6524 if (searchSymbolAlias(Operands))
6545 SMLoc S = getLexer().getLoc();
6553 const MCExpr *Expr =
nullptr;
6559 MipsOperand::CreateImm(Expr, S, getLexer().getLoc(), *
this));
6577 if (getParser().parseExpression(IdVal))
6584 Operands.
push_back(MipsOperand::CreateImm(
6594 unsigned PrevReg = Mips::NoRegister;
6595 bool RegRange =
false;
6603 SMLoc E = getLexer().getLoc();
6604 MipsOperand &
Reg =
static_cast<MipsOperand &
>(*TmpOperands.
back());
6605 RegNo = isGP64bit() ? Reg.getGPR64Reg() : Reg.getGPR32Reg();
6609 if ((isGP64bit() && RegNo == Mips::RA_64) ||
6610 (!isGP64bit() && RegNo ==
Mips::RA)) {
6613 unsigned TmpReg = PrevReg + 1;
6614 while (TmpReg <= RegNo) {
6615 if ((((TmpReg < Mips::S0) || (TmpReg > Mips::S7)) && !isGP64bit()) ||
6616 (((TmpReg < Mips::S0_64) || (TmpReg > Mips::S7_64)) &&
6618 Error(E,
"invalid register operand");
6629 if ((PrevReg == Mips::NoRegister) &&
6630 ((isGP64bit() && (RegNo != Mips::S0_64) && (RegNo != Mips::RA_64)) ||
6631 (!isGP64bit() && (RegNo != Mips::S0) && (RegNo !=
Mips::RA)))) {
6632 Error(E,
"$16 or $31 expected");
6634 }
else if (!(((RegNo == Mips::FP || RegNo ==
Mips::RA ||
6635 (RegNo >= Mips::S0 && RegNo <= Mips::S7)) &&
6637 ((RegNo == Mips::FP_64 || RegNo == Mips::RA_64 ||
6638 (RegNo >= Mips::S0_64 && RegNo <= Mips::S7_64)) &&
6640 Error(E,
"invalid register operand");
6642 }
else if ((PrevReg != Mips::NoRegister) && (RegNo != PrevReg + 1) &&
6643 ((RegNo != Mips::FP && RegNo !=
Mips::RA && !isGP64bit()) ||
6644 (RegNo != Mips::FP_64 && RegNo != Mips::RA_64 &&
6646 Error(E,
"consecutive register numbers expected");
6658 Error(E,
"',' or '-' expected");
6670 Operands.
push_back(MipsOperand::CreateRegList(Regs, S, E, *
this));
6671 parseMemOperand(Operands);
6684 MipsOperand::CreateToken(
"(", getLexer().getLoc(), *
this));
6686 if (parseOperand(Operands, Name)) {
6687 SMLoc Loc = getLexer().getLoc();
6688 return Error(Loc,
"unexpected token in argument list");
6691 SMLoc Loc = getLexer().getLoc();
6692 return Error(Loc,
"unexpected token, expected ')'");
6695 MipsOperand::CreateToken(
")", getLexer().getLoc(), *
this));
6707 bool MipsAsmParser::parseBracketSuffix(
StringRef Name,
6712 MipsOperand::CreateToken(
"[", getLexer().getLoc(), *
this));
6714 if (parseOperand(Operands, Name)) {
6715 SMLoc Loc = getLexer().getLoc();
6716 return Error(Loc,
"unexpected token in argument list");
6719 SMLoc Loc = getLexer().getLoc();
6720 return Error(Loc,
"unexpected token, expected ']'");
6723 MipsOperand::CreateToken(
"]", getLexer().getLoc(), *
this));
6730 unsigned VariantID = 0);
6738 getTargetStreamer().forbidModuleDirective();
6741 if (!mnemonicIsValid(Name, 0)) {
6742 FeatureBitset FBS = ComputeAvailableFeatures(getSTI().getFeatureBits());
6744 return Error(NameLoc,
"unknown instruction" + Suggestion);
6747 Operands.
push_back(MipsOperand::CreateToken(Name, NameLoc, *
this));
6752 if (parseOperand(Operands, Name)) {
6753 SMLoc Loc = getLexer().getLoc();
6754 return Error(Loc,
"unexpected token in argument list");
6756 if (getLexer().is(
AsmToken::LBrac) && parseBracketSuffix(Name, Operands))
6763 if (parseOperand(Operands, Name)) {
6764 SMLoc Loc = getLexer().getLoc();
6765 return Error(Loc,
"unexpected token in argument list");
6769 if (parseBracketSuffix(Name, Operands))
6772 parseParenSuffix(Name, Operands))
6777 SMLoc Loc = getLexer().getLoc();
6778 return Error(Loc,
"unexpected token in argument list");
6786 bool MipsAsmParser::reportParseError(
Twine ErrorMsg) {
6787 SMLoc Loc = getLexer().getLoc();
6788 return Error(Loc, ErrorMsg);
6791 bool MipsAsmParser::reportParseError(
SMLoc Loc,
Twine ErrorMsg) {
6792 return Error(Loc, ErrorMsg);
6795 bool MipsAsmParser::parseSetNoAtDirective() {
6800 AssemblerOptions.
back()->setATRegIndex(0);
6806 reportParseError(
"unexpected token, expected end of statement");
6810 getTargetStreamer().emitDirectiveSetNoAt();
6815 bool MipsAsmParser::parseSetAtDirective() {
6823 AssemblerOptions.
back()->setATRegIndex(1);
6825 getTargetStreamer().emitDirectiveSetAt();
6831 reportParseError(
"unexpected token, expected equals sign");
6838 reportParseError(
"no register specified");
6841 reportParseError(
"unexpected token, expected dollar sign '$'");
6855 reportParseError(
"unexpected token, expected identifier or integer");
6860 if (!AssemblerOptions.
back()->setATRegIndex(AtRegNo)) {
6861 reportParseError(
"invalid register");
6868 reportParseError(
"unexpected token, expected end of statement");
6872 getTargetStreamer().emitDirectiveSetAtWithArg(AtRegNo);
6878 bool MipsAsmParser::parseSetReorderDirective() {
6883 reportParseError(
"unexpected token, expected end of statement");
6886 AssemblerOptions.
back()->setReorder();
6887 getTargetStreamer().emitDirectiveSetReorder();
6892 bool MipsAsmParser::parseSetNoReorderDirective() {
6897 reportParseError(
"unexpected token, expected end of statement");
6900 AssemblerOptions.
back()->setNoReorder();
6901 getTargetStreamer().emitDirectiveSetNoReorder();
6906 bool MipsAsmParser::parseSetMacroDirective() {
6911 reportParseError(
"unexpected token, expected end of statement");
6914 AssemblerOptions.
back()->setMacro();
6915 getTargetStreamer().emitDirectiveSetMacro();
6920 bool MipsAsmParser::parseSetNoMacroDirective() {
6925 reportParseError(
"unexpected token, expected end of statement");
6928 if (AssemblerOptions.
back()->isReorder()) {
6929 reportParseError(
"`noreorder' must be set before `nomacro'");
6932 AssemblerOptions.
back()->setNoMacro();
6933 getTargetStreamer().emitDirectiveSetNoMacro();
6938 bool MipsAsmParser::parseSetMsaDirective() {
6944 return reportParseError(
"unexpected token, expected end of statement");
6946 setFeatureBits(Mips::FeatureMSA,
"msa");
6947 getTargetStreamer().emitDirectiveSetMsa();
6951 bool MipsAsmParser::parseSetNoMsaDirective() {
6957 return reportParseError(
"unexpected token, expected end of statement");
6959 clearFeatureBits(Mips::FeatureMSA,
"msa");
6960 getTargetStreamer().emitDirectiveSetNoMsa();
6964 bool MipsAsmParser::parseSetNoDspDirective() {
6970 reportParseError(
"unexpected token, expected end of statement");
6974 clearFeatureBits(Mips::FeatureDSP,
"dsp");
6975 getTargetStreamer().emitDirectiveSetNoDsp();
6979 bool MipsAsmParser::parseSetMips16Directive() {
6985 reportParseError(
"unexpected token, expected end of statement");
6989 setFeatureBits(Mips::FeatureMips16,
"mips16");
6990 getTargetStreamer().emitDirectiveSetMips16();
6995 bool MipsAsmParser::parseSetNoMips16Directive() {
7001 reportParseError(
"unexpected token, expected end of statement");
7005 clearFeatureBits(Mips::FeatureMips16,
"mips16");
7006 getTargetStreamer().emitDirectiveSetNoMips16();
7011 bool MipsAsmParser::parseSetFpDirective() {
7020 reportParseError(
"unexpected token, expected equals sign '='");
7026 if (!parseFpABIValue(FpAbiVal,
".set"))
7030 reportParseError(
"unexpected token, expected end of statement");
7033 getTargetStreamer().emitDirectiveSetFp(FpAbiVal);
7038 bool MipsAsmParser::parseSetOddSPRegDirective() {
7043 reportParseError(
"unexpected token, expected end of statement");
7047 clearFeatureBits(Mips::FeatureNoOddSPReg,
"nooddspreg");
7048 getTargetStreamer().emitDirectiveSetOddSPReg();
7052 bool MipsAsmParser::parseSetNoOddSPRegDirective() {
7057 reportParseError(
"unexpected token, expected end of statement");
7061 setFeatureBits(Mips::FeatureNoOddSPReg,
"nooddspreg");
7062 getTargetStreamer().emitDirectiveSetNoOddSPReg();
7066 bool MipsAsmParser::parseSetMtDirective() {
7072 reportParseError(
"unexpected token, expected end of statement");
7076 setFeatureBits(Mips::FeatureMT,
"mt");
7077 getTargetStreamer().emitDirectiveSetMt();
7082 bool MipsAsmParser::parseSetNoMtDirective() {
7088 reportParseError(
"unexpected token, expected end of statement");
7092 clearFeatureBits(Mips::FeatureMT,
"mt");
7094 getTargetStreamer().emitDirectiveSetNoMt();
7099 bool MipsAsmParser::parseSetNoCRCDirective() {
7105 reportParseError(
"unexpected token, expected end of statement");
7109 clearFeatureBits(Mips::FeatureCRC,
"crc");
7111 getTargetStreamer().emitDirectiveSetNoCRC();
7116 bool MipsAsmParser::parseSetNoVirtDirective() {
7122 reportParseError(
"unexpected token, expected end of statement");
7126 clearFeatureBits(Mips::FeatureVirt,
"virt");
7128 getTargetStreamer().emitDirectiveSetNoVirt();
7133 bool MipsAsmParser::parseSetNoGINVDirective() {
7139 reportParseError(
"unexpected token, expected end of statement");
7143 clearFeatureBits(Mips::FeatureGINV,
"ginv");
7145 getTargetStreamer().emitDirectiveSetNoGINV();
7150 bool MipsAsmParser::parseSetPopDirective() {
7152 SMLoc Loc = getLexer().getLoc();
7156 return reportParseError(
"unexpected token, expected end of statement");
7160 if (AssemblerOptions.
size() == 2)
7161 return reportParseError(Loc,
".set pop with no .set push");
7165 setAvailableFeatures(
7166 ComputeAvailableFeatures(AssemblerOptions.
back()->getFeatures()));
7169 getTargetStreamer().emitDirectiveSetPop();
7173 bool MipsAsmParser::parseSetPushDirective() {
7177 return reportParseError(
"unexpected token, expected end of statement");
7181 std::make_unique<MipsAssemblerOptions>(AssemblerOptions.
back().get()));
7183 getTargetStreamer().emitDirectiveSetPush();
7187 bool MipsAsmParser::parseSetSoftFloatDirective() {
7191 return reportParseError(
"unexpected token, expected end of statement");
7193 setFeatureBits(Mips::FeatureSoftFloat,
"soft-float");
7194 getTargetStreamer().emitDirectiveSetSoftFloat();
7198 bool MipsAsmParser::parseSetHardFloatDirective() {
7202 return reportParseError(
"unexpected token, expected end of statement");
7204 clearFeatureBits(Mips::FeatureSoftFloat,
"soft-float");
7205 getTargetStreamer().emitDirectiveSetHardFloat();
7209 bool MipsAsmParser::parseSetAssignment() {
7214 return reportParseError(
"expected identifier after .set");
7217 return reportParseError(
"unexpected token, expected comma");
7227 getContext().getOrCreateSymbol(Name);
7234 Parser, Sym, Value))
7241 bool MipsAsmParser::parseSetMips0Directive() {
7245 return reportParseError(
"unexpected token, expected end of statement");
7249 setAvailableFeatures(
7250 ComputeAvailableFeatures(AssemblerOptions.
front()->getFeatures()));
7252 AssemblerOptions.
back()->setFeatures(AssemblerOptions.
front()->getFeatures());
7254 getTargetStreamer().emitDirectiveSetMips0();
7258 bool MipsAsmParser::parseSetArchDirective() {
7262 return reportParseError(
"unexpected token, expected equals sign");
7265 StringRef Arch = getParser().parseStringToEndOfStatement().
trim();
7267 return reportParseError(
"expected arch identifier");
7271 .Case(
"mips1",
"mips1")
7272 .
Case(
"mips2",
"mips2")
7273 .
Case(
"mips3",
"mips3")
7274 .
Case(
"mips4",
"mips4")
7275 .
Case(
"mips5",
"mips5")
7276 .
Case(
"mips32",
"mips32")
7277 .
Case(
"mips32r2",
"mips32r2")
7278 .
Case(
"mips32r3",
"mips32r3")
7279 .
Case(
"mips32r5",
"mips32r5")
7280 .
Case(
"mips32r6",
"mips32r6")
7281 .
Case(
"mips64",
"mips64")
7282 .
Case(
"mips64r2",
"mips64r2")
7283 .
Case(
"mips64r3",
"mips64r3")
7284 .
Case(
"mips64r5",
"mips64r5")
7285 .
Case(
"mips64r6",
"mips64r6")
7286 .
Case(
"octeon",
"cnmips")
7287 .
Case(
"octeon+",
"cnmipsp")
7288 .
Case(
"r4000",
"mips3")
7291 if (ArchFeatureName.
empty())
7292 return reportParseError(
"unsupported architecture");
7294 if (ArchFeatureName ==
"mips64r6" && inMicroMipsMode())
7295 return reportParseError(
"mips64r6 does not support microMIPS");
7297 selectArch(ArchFeatureName);
7298 getTargetStreamer().emitDirectiveSetArch(Arch);
7302 bool MipsAsmParser::parseSetFeature(uint64_t Feature) {
7306 return reportParseError(
"unexpected token, expected end of statement");
7311 case Mips::FeatureDSP:
7312 setFeatureBits(Mips::FeatureDSP,
"dsp");
7313 getTargetStreamer().emitDirectiveSetDsp();
7315 case Mips::FeatureDSPR2:
7316 setFeatureBits(Mips::FeatureDSPR2,
"dspr2");
7317 getTargetStreamer().emitDirectiveSetDspr2();
7319 case Mips::FeatureMicroMips:
7320 setFeatureBits(Mips::FeatureMicroMips,
"micromips");
7321 getTargetStreamer().emitDirectiveSetMicroMips();
7323 case Mips::FeatureMips1:
7324 selectArch(
"mips1");
7325 getTargetStreamer().emitDirectiveSetMips1();
7327 case Mips::FeatureMips2:
7328 selectArch(
"mips2");
7329 getTargetStreamer().emitDirectiveSetMips2();
7331 case Mips::FeatureMips3:
7332 selectArch(
"mips3");
7333 getTargetStreamer().emitDirectiveSetMips3();
7335 case Mips::FeatureMips4:
7336 selectArch(
"mips4");
7337 getTargetStreamer().emitDirectiveSetMips4();
7339 case Mips::FeatureMips5:
7340 selectArch(
"mips5");
7341 getTargetStreamer().emitDirectiveSetMips5();
7343 case Mips::FeatureMips32:
7344 selectArch(
"mips32");
7345 getTargetStreamer().emitDirectiveSetMips32();
7347 case Mips::FeatureMips32r2:
7348 selectArch(
"mips32r2");
7349 getTargetStreamer().emitDirectiveSetMips32R2();
7351 case Mips::FeatureMips32r3:
7352 selectArch(
"mips32r3");
7353 getTargetStreamer().emitDirectiveSetMips32R3();
7355 case Mips::FeatureMips32r5:
7356 selectArch(
"mips32r5");
7357 getTargetStreamer().emitDirectiveSetMips32R5();
7359 case Mips::FeatureMips32r6:
7360 selectArch(
"mips32r6");
7361 getTargetStreamer().emitDirectiveSetMips32R6();
7363 case Mips::FeatureMips64:
7364 selectArch(
"mips64");
7365 getTargetStreamer().emitDirectiveSetMips64();
7367 case Mips::FeatureMips64r2:
7368 selectArch(
"mips64r2");
7369 getTargetStreamer().emitDirectiveSetMips64R2();
7371 case Mips::FeatureMips64r3:
7372 selectArch(
"mips64r3");
7373 getTargetStreamer().emitDirectiveSetMips64R3();
7375 case Mips::FeatureMips64r5:
7376 selectArch(
"mips64r5");
7377 getTargetStreamer().emitDirectiveSetMips64R5();
7379 case Mips::FeatureMips64r6:
7380 selectArch(
"mips64r6");
7381 getTargetStreamer().emitDirectiveSetMips64R6();
7383 case Mips::FeatureCRC:
7384 setFeatureBits(Mips::FeatureCRC,
"crc");
7385 getTargetStreamer().emitDirectiveSetCRC();
7387 case Mips::FeatureVirt:
7388 setFeatureBits(Mips::FeatureVirt,
"virt");
7389 getTargetStreamer().emitDirectiveSetVirt();
7391 case Mips::FeatureGINV:
7392 setFeatureBits(Mips::FeatureGINV,
"ginv");
7393 getTargetStreamer().emitDirectiveSetGINV();
7399 bool MipsAsmParser::eatComma(
StringRef ErrorStr) {
7402 SMLoc Loc = getLexer().getLoc();
7403 return Error(Loc, ErrorStr);
7414 bool MipsAsmParser::isPicAndNotNxxAbi() {
7415 return inPicMode() && !(isABI_N32() || isABI_N64());
7418 bool MipsAsmParser::parseDirectiveCpLoad(
SMLoc Loc) {
7419 if (AssemblerOptions.
back()->isReorder())
7420 Warning(Loc,
".cpload should be inside a noreorder section");
7422 if (inMips16Mode()) {
7423 reportParseError(
".cpload is not supported in Mips16 mode");
7430 reportParseError(
"expected register containing function address");
7434 MipsOperand &RegOpnd =
static_cast<MipsOperand &
>(*Reg[0]);
7435 if (!RegOpnd.isGPRAsmReg()) {
7436 reportParseError(RegOpnd.getStartLoc(),
"invalid register");
7442 reportParseError(
"unexpected token, expected end of statement");
7446 getTargetStreamer().emitDirectiveCpLoad(RegOpnd.getGPR32Reg());
7450 bool MipsAsmParser::parseDirectiveCpLocal(
SMLoc Loc) {
7451 if (!isABI_N32() && !isABI_N64()) {
7452 reportParseError(
".cplocal is allowed only in N32 or N64 mode");
7459 reportParseError(
"expected register containing global pointer");
7463 MipsOperand &RegOpnd =
static_cast<MipsOperand &
>(*Reg[0]);
7464 if (!RegOpnd.isGPRAsmReg()) {
7465 reportParseError(RegOpnd.getStartLoc(),
"invalid register");
7471 reportParseError(
"unexpected token, expected end of statement");
7476 unsigned NewReg = RegOpnd.getGPR32Reg();
7480 getTargetStreamer().emitDirectiveCpLocal(NewReg);
7484 bool MipsAsmParser::parseDirectiveCpRestore(
SMLoc Loc) {
7490 if (inMips16Mode()) {
7491 reportParseError(
".cprestore is not supported in Mips16 mode");
7497 int64_t StackOffsetVal;
7499 reportParseError(
"expected stack offset value");
7503 if (!StackOffset->evaluateAsAbsolute(StackOffsetVal)) {
7504 reportParseError(
"stack offset is not an absolute expression");
7508 if (StackOffsetVal < 0) {
7509 Warning(Loc,
".cprestore with negative stack offset has no effect");
7510 IsCpRestoreSet =
false;
7512 IsCpRestoreSet =
true;
7513 CpRestoreOffset = StackOffsetVal;
7518 reportParseError(
"unexpected token, expected end of statement");
7522 if (!getTargetStreamer().emitDirectiveCpRestore(
7523 CpRestoreOffset, [&]() {
return getATReg(Loc); }, Loc, STI))
7529 bool MipsAsmParser::parseDirectiveCPSetup() {
7533 bool SaveIsReg =
true;
7538 reportParseError(
"expected register containing function address");
7542 MipsOperand &FuncRegOpnd =
static_cast<MipsOperand &
>(*TmpReg[0]);
7543 if (!FuncRegOpnd.isGPRAsmReg()) {
7544 reportParseError(FuncRegOpnd.getStartLoc(),
"invalid register");
7548 FuncReg = FuncRegOpnd.getGPR32Reg();
7551 if (!eatComma(
"unexpected token, expected comma"))
7554 ResTy = parseAnyRegister(TmpReg);
7556 const MCExpr *OffsetExpr;
7558 SMLoc ExprLoc = getLexer().getLoc();
7561 !OffsetExpr->evaluateAsAbsolute(OffsetVal)) {
7562 reportParseError(ExprLoc,
"expected save register or stack offset");
7569 MipsOperand &SaveOpnd =
static_cast<MipsOperand &
>(*TmpReg[0]);
7570 if (!SaveOpnd.isGPRAsmReg()) {
7571 reportParseError(SaveOpnd.getStartLoc(),
"invalid register");
7574 Save = SaveOpnd.getGPR32Reg();
7577 if (!eatComma(
"unexpected token, expected comma"))
7582 reportParseError(
"expected expression");
7587 reportParseError(
"expected symbol");
7592 CpSaveLocation = Save;
7593 CpSaveLocationIsRegister = SaveIsReg;
7595 getTargetStreamer().emitDirectiveCpsetup(FuncReg, Save, Ref->
getSymbol(),
7600 bool MipsAsmParser::parseDirectiveCPReturn() {
7601 getTargetStreamer().emitDirectiveCpreturn(CpSaveLocation,
7602 CpSaveLocationIsRegister);
7606 bool MipsAsmParser::parseDirectiveNaN() {
7613 getTargetStreamer().emitDirectiveNaN2008();
7615 }
else if (Tok.
getString() ==
"legacy") {
7617 getTargetStreamer().emitDirectiveNaNLegacy();
7623 reportParseError(
"invalid option in .nan directive");
7627 bool MipsAsmParser::parseDirectiveSet() {
7628 const AsmToken &Tok = getParser().getTok();
7632 if (IdVal ==
"noat")
7633 return parseSetNoAtDirective();
7635 return parseSetAtDirective();
7636 if (IdVal ==
"arch")
7637 return parseSetArchDirective();
7638 if (IdVal ==
"bopt") {
7639 Warning(Loc,
"'bopt' feature is unsupported");
7643 if (IdVal ==
"nobopt") {
7649 return parseSetFpDirective();
7650 if (IdVal ==
"oddspreg")
7651 return parseSetOddSPRegDirective();
7652 if (IdVal ==
"nooddspreg")
7653 return parseSetNoOddSPRegDirective();
7655 return parseSetPopDirective();
7656 if (IdVal ==
"push")
7657 return parseSetPushDirective();
7658 if (IdVal ==
"reorder")
7659 return parseSetReorderDirective();
7660 if (IdVal ==
"noreorder")
7661 return parseSetNoReorderDirective();
7662 if (IdVal ==
"macro")
7663 return parseSetMacroDirective();
7664 if (IdVal ==
"nomacro")
7665 return parseSetNoMacroDirective();
7666 if (IdVal ==
"mips16")
7667 return parseSetMips16Directive();
7668 if (IdVal ==
"nomips16")
7669 return parseSetNoMips16Directive();
7670 if (IdVal ==
"nomicromips") {
7671 clearFeatureBits(Mips::FeatureMicroMips,
"micromips");
7672 getTargetStreamer().emitDirectiveSetNoMicroMips();
7673 getParser().eatToEndOfStatement();
7676 if (IdVal ==
"micromips") {
7677 if (hasMips64r6()) {
7678 Error(Loc,
".set micromips directive is not supported with MIPS64R6");
7681 return parseSetFeature(Mips::FeatureMicroMips);
7683 if (IdVal ==
"mips0")
7684 return parseSetMips0Directive();
7685 if (IdVal ==
"mips1")
7686 return parseSetFeature(Mips::FeatureMips1);
7687 if (IdVal ==
"mips2")
7688 return parseSetFeature(Mips::FeatureMips2);
7689 if (IdVal ==
"mips3")
7690 return parseSetFeature(Mips::FeatureMips3);
7691 if (IdVal ==
"mips4")
7692 return parseSetFeature(Mips::FeatureMips4);
7693 if (IdVal ==
"mips5")
7694 return parseSetFeature(Mips::FeatureMips5);
7695 if (IdVal ==
"mips32")
7696 return parseSetFeature(Mips::FeatureMips32);
7697 if (IdVal ==
"mips32r2")
7698 return parseSetFeature(Mips::FeatureMips32r2);
7699 if (IdVal ==
"mips32r3")
7700 return parseSetFeature(Mips::FeatureMips32r3);
7701 if (IdVal ==
"mips32r5")
7702 return parseSetFeature(Mips::FeatureMips32r5);
7703 if (IdVal ==
"mips32r6")
7704 return parseSetFeature(Mips::FeatureMips32r6);
7705 if (IdVal ==
"mips64")
7706 return parseSetFeature(Mips::FeatureMips64);
7707 if (IdVal ==
"mips64r2")
7708 return parseSetFeature(Mips::FeatureMips64r2);
7709 if (IdVal ==
"mips64r3")
7710 return parseSetFeature(Mips::FeatureMips64r3);
7711 if (IdVal ==
"mips64r5")
7712 return parseSetFeature(Mips::FeatureMips64r5);
7713 if (IdVal ==
"mips64r6") {
7714 if (inMicroMipsMode()) {
7715 Error(Loc,
"MIPS64R6 is not supported with microMIPS");
7718 return parseSetFeature(Mips::FeatureMips64r6);
7721 return parseSetFeature(Mips::FeatureDSP);
7722 if (IdVal ==
"dspr2")
7723 return parseSetFeature(Mips::FeatureDSPR2);
7724 if (IdVal ==
"nodsp")
7725 return parseSetNoDspDirective();
7727 return parseSetMsaDirective();
7728 if (IdVal ==
"nomsa")
7729 return parseSetNoMsaDirective();
7731 return parseSetMtDirective();
7732 if (IdVal ==
"nomt")
7733 return parseSetNoMtDirective();
7734 if (IdVal ==
"softfloat")
7735 return parseSetSoftFloatDirective();
7736 if (IdVal ==
"hardfloat")
7737 return parseSetHardFloatDirective();
7739 return parseSetFeature(Mips::FeatureCRC);
7740 if (IdVal ==
"nocrc")
7741 return parseSetNoCRCDirective();
7742 if (IdVal ==
"virt")
7743 return parseSetFeature(Mips::FeatureVirt);
7744 if (IdVal ==
"novirt")
7745 return parseSetNoVirtDirective();
7746 if (IdVal ==
"ginv")
7747 return parseSetFeature(Mips::FeatureGINV);
7748 if (IdVal ==
"noginv")
7749 return parseSetNoGINVDirective();
7752 return parseSetAssignment();
7757 bool MipsAsmParser::parseDirectiveGpWord() {
7762 if (getParser().parseExpression(Value))
7764 getParser().getStreamer().EmitGPRel32Value(Value);
7767 return Error(getLexer().getLoc(),
7768 "unexpected token, expected end of statement");
7775 bool MipsAsmParser::parseDirectiveGpDWord() {
7780 if (getParser().parseExpression(Value))
7782 getParser().getStreamer().EmitGPRel64Value(Value);
7785 return Error(getLexer().getLoc(),
7786 "unexpected token, expected end of statement");
7793 bool MipsAsmParser::parseDirectiveDtpRelWord() {
7798 if (getParser().parseExpression(Value))
7800 getParser().getStreamer().EmitDTPRel32Value(Value);
7803 return Error(getLexer().getLoc(),
7804 "unexpected token, expected end of statement");
7811 bool MipsAsmParser::parseDirectiveDtpRelDWord() {
7816 if (getParser().parseExpression(Value))
7818 getParser().getStreamer().EmitDTPRel64Value(Value);
7821 return Error(getLexer().getLoc(),
7822 "unexpected token, expected end of statement");
7829 bool MipsAsmParser::parseDirectiveTpRelWord() {
7834 if (getParser().parseExpression(Value))
7836 getParser().getStreamer().EmitTPRel32Value(Value);
7839 return Error(getLexer().getLoc(),
7840 "unexpected token, expected end of statement");
7847 bool MipsAsmParser::parseDirectiveTpRelDWord() {
7852 if (getParser().parseExpression(Value))
7854 getParser().getStreamer().EmitTPRel64Value(Value);
7857 return Error(getLexer().getLoc(),
7858 "unexpected token, expected end of statement");
7863 bool MipsAsmParser::parseDirectiveOption() {
7870 "unexpected token, expected identifier");
7875 if (Option ==
"pic0") {
7877 IsPicEnabled =
false;
7879 getTargetStreamer().emitDirectiveOptionPic0();
7883 "unexpected token, expected end of statement");
7888 if (Option ==
"pic2") {
7890 IsPicEnabled =
true;
7892 getTargetStreamer().emitDirectiveOptionPic2();
7896 "unexpected token, expected end of statement");
7903 "unknown option, expected 'pic0' or 'pic2'");
7910 bool MipsAsmParser::parseInsnDirective() {
7913 reportParseError(
"unexpected token, expected end of statement");
7919 getTargetStreamer().emitDirectiveInsn();
7930 reportParseError(
"unexpected token, expected end of statement");
7934 MCSection *ELFSection = getContext().getELFSection(
7936 getParser().getStreamer().SwitchSection(ELFSection);
7945 bool MipsAsmParser::parseSSectionDirective(
StringRef Section,
unsigned Type) {
7948 reportParseError(
"unexpected token, expected end of statement");
7952 MCSection *ELFSection = getContext().getELFSection(
7954 getParser().getStreamer().SwitchSection(ELFSection);
7973 bool MipsAsmParser::parseDirectiveModule() {
7978 if (!getTargetStreamer().isModuleDirectiveAllowed()) {
7980 reportParseError(
".module directive must appear before any code");
7986 reportParseError(
"expected .module option identifier");
7990 if (Option ==
"oddspreg") {
7991 clearModuleFeatureBits(Mips::FeatureNoOddSPReg,
"nooddspreg");
7995 getTargetStreamer().updateABIInfo(*
this);
8000 getTargetStreamer().emitDirectiveModuleOddSPReg();
8004 reportParseError(
"unexpected token, expected end of statement");
8009 }
else if (Option ==
"nooddspreg") {
8011 return Error(L,
"'.module nooddspreg' requires the O32 ABI");
8014 setModuleFeatureBits(Mips::FeatureNoOddSPReg,
"nooddspreg");
8018 getTargetStreamer().updateABIInfo(*
this);
8023 getTargetStreamer().emitDirectiveModuleOddSPReg();
8027 reportParseError(
"unexpected token, expected end of statement");
8032 }
else if (Option ==
"fp") {
8033 return parseDirectiveModuleFP();
8034 }
else if (Option ==
"softfloat") {
8035 setModuleFeatureBits(Mips::FeatureSoftFloat,
"soft-float");
8039 getTargetStreamer().updateABIInfo(*
this);
8044 getTargetStreamer().emitDirectiveModuleSoftFloat();
8048 reportParseError(
"unexpected token, expected end of statement");
8053 }
else if (Option ==
"hardfloat") {
8054 clearModuleFeatureBits(Mips::FeatureSoftFloat,
"soft-float");
8058 getTargetStreamer().updateABIInfo(*
this);
8063 getTargetStreamer().emitDirectiveModuleHardFloat();
8067 reportParseError(
"unexpected token, expected end of statement");
8072 }
else if (Option ==
"mt") {
8073 setModuleFeatureBits(Mips::FeatureMT,
"mt");
8077 getTargetStreamer().updateABIInfo(*
this);
8082 getTargetStreamer().emitDirectiveModuleMT();
8086 reportParseError(
"unexpected token, expected end of statement");
8091 }
else if (Option ==
"crc") {
8092 setModuleFeatureBits(Mips::FeatureCRC,
"crc");
8096 getTargetStreamer().updateABIInfo(*
this);
8101 getTargetStreamer().emitDirectiveModuleCRC();
8105 reportParseError(
"unexpected token, expected end of statement");
8110 }
else if (Option ==
"nocrc") {
8111 clearModuleFeatureBits(Mips::FeatureCRC,
"crc");
8115 getTargetStreamer().updateABIInfo(*
this);
8120 getTargetStreamer().emitDirectiveModuleNoCRC();
8124 reportParseError(
"unexpected token, expected end of statement");
8129 }
else if (Option ==
"virt") {
8130 setModuleFeatureBits(Mips::FeatureVirt,
"virt");
8134 getTargetStreamer().updateABIInfo(*
this);
8139 getTargetStreamer().emitDirectiveModuleVirt();
8143 reportParseError(
"unexpected token, expected end of statement");
8148 }
else if (Option ==
"novirt") {
8149 clearModuleFeatureBits(Mips::FeatureVirt,
"virt");
8153 getTargetStreamer().updateABIInfo(*
this);
8158 getTargetStreamer().emitDirectiveModuleNoVirt();
8162 reportParseError(
"unexpected token, expected end of statement");
8167 }
else if (Option ==
"ginv") {
8168 setModuleFeatureBits(Mips::FeatureGINV,
"ginv");
8172 getTargetStreamer().updateABIInfo(*
this);
8177 getTargetStreamer().emitDirectiveModuleGINV();
8181 reportParseError(
"unexpected token, expected end of statement");
8186 }
else if (Option ==
"noginv") {
8187 clearModuleFeatureBits(Mips::FeatureGINV,
"ginv");
8191 getTargetStreamer().updateABIInfo(*
this);
8196 getTargetStreamer().emitDirectiveModuleNoGINV();
8200 reportParseError(
"unexpected token, expected end of statement");
8206 return Error(L,
"'" +
Twine(Option) +
"' is not a valid .module option.");
8214 bool MipsAsmParser::parseDirectiveModuleFP() {
8219 reportParseError(
"unexpected token, expected equals sign '='");
8225 if (!parseFpABIValue(FpABI,
".module"))
8229 reportParseError(
"unexpected token, expected end of statement");
8235 getTargetStreamer().updateABIInfo(*
this);
8240 getTargetStreamer().emitDirectiveModuleFP();
8250 bool ModuleLevelOptions = Directive ==
".module";
8256 if (Value !=
"xx") {
8257 reportParseError(
"unsupported value, expected 'xx', '32' or '64'");
8262 reportParseError(
"'" + Directive +
" fp=xx' requires the O32 ABI");
8267 if (ModuleLevelOptions) {
8268 setModuleFeatureBits(Mips::FeatureFPXX,
"fpxx");
8269 clearModuleFeatureBits(Mips::FeatureFP64Bit,
"fp64");
8271 setFeatureBits(Mips::FeatureFPXX,
"fpxx");
8272 clearFeatureBits(Mips::FeatureFP64Bit,
"fp64");
8281 if (Value != 32 && Value != 64) {
8282 reportParseError(
"unsupported value, expected 'xx', '32' or '64'");
8288 reportParseError(
"'" + Directive +
" fp=32' requires the O32 ABI");
8293 if (ModuleLevelOptions) {
8294 clearModuleFeatureBits(Mips::FeatureFPXX,
"fpxx");
8295 clearModuleFeatureBits(Mips::FeatureFP64Bit,
"fp64");
8297 clearFeatureBits(Mips::FeatureFPXX,
"fpxx");
8298 clearFeatureBits(Mips::FeatureFP64Bit,
"fp64");
8302 if (ModuleLevelOptions) {
8303 clearModuleFeatureBits(Mips::FeatureFPXX,
"fpxx");
8304 setModuleFeatureBits(Mips::FeatureFP64Bit,
"fp64");
8306 clearFeatureBits(Mips::FeatureFPXX,
"fpxx");
8307 setFeatureBits(Mips::FeatureFP64Bit,
"fp64");
8317 bool MipsAsmParser::ParseDirective(
AsmToken DirectiveID) {
8326 if (IDVal ==
".cpload") {
8327 parseDirectiveCpLoad(DirectiveID.
getLoc());
8330 if (IDVal ==
".cprestore") {
8331 parseDirectiveCpRestore(DirectiveID.
getLoc());
8334 if (IDVal ==
".cplocal") {
8335 parseDirectiveCpLocal(DirectiveID.
getLoc());
8338 if (IDVal ==
".ent") {
8342 reportParseError(
"expected identifier after .ent");
8356 reportParseError(
"unexpected token, expected end of statement");
8360 const MCExpr *DummyNumber;
8361 int64_t DummyNumberVal;
8365 reportParseError(
"expected number after comma");
8368 if (!DummyNumber->evaluateAsAbsolute(DummyNumberVal)) {
8369 reportParseError(
"expected an absolute expression after comma");
8376 reportParseError(
"unexpected token, expected end of statement");
8380 MCSymbol *Sym = getContext().getOrCreateSymbol(SymbolName);
8382 getTargetStreamer().emitDirectiveEnt(*Sym);
8384 IsCpRestoreSet =
false;
8388 if (IDVal ==
".end") {
8392 reportParseError(
"expected identifier after .end");
8397 reportParseError(
"unexpected token, expected end of statement");
8401 if (CurrentFn ==
nullptr) {
8402 reportParseError(
".end used without .ent");
8406 if ((SymbolName != CurrentFn->
getName())) {
8407 reportParseError(
".end symbol does not match .ent symbol");
8411 getTargetStreamer().emitDirectiveEnd(SymbolName);
8412 CurrentFn =
nullptr;
8413 IsCpRestoreSet =
false;
8417 if (IDVal ==
".frame") {
8422 reportParseError(
"expected stack register");
8426 MipsOperand &StackRegOpnd =
static_cast<MipsOperand &
>(*TmpReg[0]);
8427 if (!StackRegOpnd.isGPRAsmReg()) {
8428 reportParseError(StackRegOpnd.getStartLoc(),
8429 "expected general purpose register");
8432 unsigned StackReg = StackRegOpnd.getGPR32Reg();
8437 reportParseError(
"unexpected token, expected comma");
8443 int64_t FrameSizeVal;
8446 reportParseError(
"expected frame size value");
8450 if (!FrameSize->evaluateAsAbsolute(FrameSizeVal)) {
8451 reportParseError(
"frame size not an absolute expression");
8458 reportParseError(
"unexpected token, expected comma");
8464 ResTy = parseAnyRegister(TmpReg);
8466 reportParseError(
"expected return register");
8470 MipsOperand &ReturnRegOpnd =
static_cast<MipsOperand &
>(*TmpReg[0]);
8471 if (!ReturnRegOpnd.isGPRAsmReg()) {
8472 reportParseError(ReturnRegOpnd.getStartLoc(),
8473 "expected general purpose register");
8479 reportParseError(
"unexpected token, expected end of statement");
8483 getTargetStreamer().emitFrame(StackReg, FrameSizeVal,
8484 ReturnRegOpnd.getGPR32Reg());
8485 IsCpRestoreSet =
false;
8489 if (IDVal ==
".set") {
8490 parseDirectiveSet();
8494 if (IDVal ==
".mask" || IDVal ==
".fmask") {
8509 reportParseError(
"expected bitmask value");
8513 if (!BitMask->evaluateAsAbsolute(BitMaskVal)) {
8514 reportParseError(
"bitmask not an absolute expression");
8521 reportParseError(
"unexpected token, expected comma");
8526 const MCExpr *FrameOffset;
8527 int64_t FrameOffsetVal;
8530 reportParseError(
"expected frame offset value");
8534 if (!FrameOffset->evaluateAsAbsolute(FrameOffsetVal)) {
8535 reportParseError(
"frame offset not an absolute expression");
8541 reportParseError(
"unexpected token, expected end of statement");
8545 if (IDVal ==
".mask")
8546 getTargetStreamer().emitMask(BitMaskVal, FrameOffsetVal);
8548 getTargetStreamer().emitFMask(BitMaskVal, FrameOffsetVal);
8552 if (IDVal ==
".nan")
8553 return parseDirectiveNaN();
8555 if (IDVal ==
".gpword") {
8556 parseDirectiveGpWord();
8560 if (IDVal ==
".gpdword") {
8561 parseDirectiveGpDWord();
8565 if (IDVal ==
".dtprelword") {
8566 parseDirectiveDtpRelWord();
8570 if (IDVal ==
".dtpreldword") {
8571 parseDirectiveDtpRelDWord();
8575 if (IDVal ==
".tprelword") {
8576 parseDirectiveTpRelWord();
8580 if (IDVal ==
".tpreldword") {
8581 parseDirectiveTpRelDWord();
8585 if (IDVal ==
".option") {
8586 parseDirectiveOption();
8590 if (IDVal ==
".abicalls") {
8591 getTargetStreamer().emitDirectiveAbiCalls();
8594 "unexpected token, expected end of statement");
8599 if (IDVal ==
".cpsetup") {
8600 parseDirectiveCPSetup();
8603 if (IDVal ==
".cpreturn") {
8604 parseDirectiveCPReturn();
8607 if (IDVal ==
".module") {
8608 parseDirectiveModule();
8611 if (IDVal ==
".llvm_internal_mips_reallow_module_directive") {
8612 parseInternalDirectiveReallowModule();
8615 if (IDVal ==
".insn") {
8616 parseInsnDirective();
8619 if (IDVal ==
".rdata") {
8620 parseRSectionDirective(
".rodata");
8623 if (IDVal ==
".sbss") {
8627 if (IDVal ==
".sdata") {
8635 bool MipsAsmParser::parseInternalDirectiveReallowModule() {
8638 reportParseError(
"unexpected token, expected end of statement");
8642 getTargetStreamer().reallowModuleDirective();
8655 #define GET_REGISTER_MATCHER 8656 #define GET_MATCHER_IMPLEMENTATION 8657 #define GET_MNEMONIC_SPELL_CHECKER 8658 #include "MipsGenAsmMatcher.inc" 8660 bool MipsAsmParser::mnemonicIsValid(
StringRef Mnemonic,
unsigned VariantID) {
8662 const MatchEntry *Start, *End;
8663 switch (VariantID) {
8668 auto MnemonicRange = std::equal_range(Start, End, Mnemonic, LessOpcode());
8669 return MnemonicRange.first != MnemonicRange.second;
static bool isReg(const MCInst &MI, unsigned OpNo)
void emitRR(unsigned Opcode, unsigned Reg0, unsigned Reg1, SMLoc IDLoc, const MCSubtargetInfo *STI)
constexpr bool isUInt< 32 >(uint64_t x)
Represents a range in source code.
Instances of this class represent a uniqued identifier for a section in the current translation unit...
const_iterator end(StringRef path)
Get end iterator over path.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
static ARMBaseTargetMachine::ARMABI computeTargetABI(const Triple &TT, StringRef CPU, const TargetOptions &Options)
void emitRRIII(unsigned Opcode, unsigned Reg0, unsigned Reg1, int16_t Imm0, int16_t Imm1, int16_t Imm2, SMLoc IDLoc, const MCSubtargetInfo *STI)
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
StringRef getString() const
Get the string for the current token, this includes all characters (for example, the quotes on string...
T findLastSet(T Val, ZeroBehavior ZB=ZB_Max)
Get the index of the last set bit starting from the least significant bit.
unsigned GetPtrAdduOp() const
uint64_t getZExtValue() const
Get zero extended value.
StackOffset is a wrapper around scalable and non-scalable offsets and is used in several functions su...
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
bool isVariable() const
isVariable - Check if this is a variable symbol.
void setFeatureBits(const FeatureBitset &FeatureBits_)
This represents an "assembler immediate".
bool is(AsmToken::TokenKind K) const
Check if the current token has kind K.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
VariantKind getKind() const
Generic assembler parser interface, for use by target specific assembly parsers.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
virtual void Initialize(MCAsmParser &Parser)
Initialize the extension for parsing using the given Parser.
static MCOperand createExpr(const MCExpr *Val)
constexpr uint32_t Lo_32(uint64_t Value)
Return the low 32 bits of a 64 bit value.
bool ArePtrs64bit() const
MCTargetAsmParser - Generic interface to target specific assembly parsers.
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
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...
void push_back(const T &Elt)
Describe properties that are true of each instruction in the target description file.
Target specific streamer interface.
bool isNot(TokenKind K) const
Target & getTheMipselTarget()
iterator find(StringRef Key)
virtual void emitDirectiveSetNoReorder()
constexpr bool isInt< 8 >(int64_t x)
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
virtual const AsmToken & Lex()=0
Get the next AsmToken in the stream, possibly handling file inclusion first.
constexpr bool isInt< 16 >(int64_t x)
void emitGPRestore(int Offset, SMLoc IDLoc, const MCSubtargetInfo *STI)
Emit the $gp restore operation for .cprestore.
static const MCInstrDesc & getInstDesc(unsigned Opcode)
static SMLoc RefineErrorLoc(const SMLoc Loc, const OperandVector &Operands, uint64_t ErrorInfo)
const AsmToken & getTok() const
Get the current AsmToken from the stream.
bool mayLoad() const
Return true if this instruction could possibly read memory.
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...
virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI)
Emit the given Instruction into the current section.
StringSwitch & Case(StringLiteral S, T Value)
SMRange getLocRange() const
return AArch64::GPR64RegClass contains(Reg)
bool isBranch() const
Returns true if this is a conditional, unconditional, or indirect branch.
const Triple & getTargetTriple() const
SI optimize exec mask operations pre RA
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
MCContext & getContext() const
StringRef getIdentifier() const
Get the identifier string for the current token, which should be an identifier or a string...
int64_t getConstant() const
SMLoc getLoc() const
Get the current source location.
const MCSymbolRefExpr * getSymB() const
static bool isEvaluated(const MCExpr *Expr)
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
static MCOperand createReg(unsigned Reg)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
const FeatureBitset & getFeatureBits() const
Generic assembler lexer interface, for use by target specific assembly lexers.
LLVM_NODISCARD StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Base class for the full range of assembler expressions which are needed for parsing.
bool isInSection() const
isInSection - Check if this symbol is defined in some section (i.e., it is defined but not absolute)...
The access may reference the value stored in memory.
LLVM_NODISCARD R Default(T Value)
static bool needsExpandMemInst(MCInst &Inst)
HasFCCRegOperand - Instruction uses an $fcc<x> register.
Target independent representation for an assembler token.
static int getRegClass(RegisterKind Is, unsigned RegWidth)
Represent a reference to a symbol from inside an expression.
mir Rename Register Operands
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
static std::string MipsMnemonicSpellCheck(StringRef S, const FeatureBitset &FBS, unsigned VariantID=0)
unsigned GetGlobalPtr() const
static bool isMem(const MachineInstr &MI, unsigned Op)
MCParsedAsmOperand - This abstract class represents a source-level assembly instruction operand...
virtual bool parseExpression(const MCExpr *&Res, SMLoc &EndLoc)=0
Parse an arbitrary expression.
unsigned getReg() const
Returns the register number.
Context object for machine code objects.
void emitNop(SMLoc IDLoc, const MCSubtargetInfo *STI)
std::pair< StringRef, StringRef > getToken(StringRef Source, StringRef Delimiters=" \\\)
getToken - This function extracts one token from source, ignoring any leading characters that appear ...
uint8_t OperandType
Information about the type of the operand.
RegisterMCAsmParser - Helper template for registering a target specific assembly parser, for use in the target machine initialization function.
bool evaluateAsRelocatable(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const
Try to evaluate the expression to a relocatable value, i.e.
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
void emitRRRX(unsigned Opcode, unsigned Reg0, unsigned Reg1, unsigned Reg2, MCOperand Op3, SMLoc IDLoc, const MCSubtargetInfo *STI)
Target & getTheMips64Target()
Directive
IDs for all OpenMP directives.
Unary assembler expressions.
Simple integer binary arithmetic operators.
static unsigned getRegisterForMxtrFP(MCInst &Inst, bool IsMFTC1)
static uint32_t covertDoubleImmToSingleImm(uint64_t ImmOp64)
LLVM_NODISCARD size_t size() const
size - Get the string size.
const MCExpr * getExpr() const
static const fltSemantics & IEEEdouble() LLVM_READNONE
static bool isShiftedUIntAtAnyPosition(uint64_t x)
Can the value be represented by a unsigned N-bit value and a shift left?
Analysis containing CSE Info
Instances of this class represent a single low-level machine instruction.
static const MCBinaryExpr * create(Opcode Op, const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
virtual void eatToEndOfStatement()=0
Skip to the end of the current statement, for error recovery.
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false)
void emitRX(unsigned Opcode, unsigned Reg0, MCOperand Op1, SMLoc IDLoc, const MCSubtargetInfo *STI)
uint32_t FloatToBits(float Float)
This function takes a float and returns the bit equivalent 32-bit integer.
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
virtual void addAliasForDirective(StringRef Directive, StringRef Alias)=0
virtual void setUsesMicroMips()
FeatureBitset ToggleFeature(uint64_t FB)
Toggle a feature and return the re-computed feature bits.
const char * getPointer() const
A switch()-like statement whose cases are string literals.
Streaming machine code generation interface.
StringSwitch & Cases(StringLiteral S0, StringLiteral S1, T Value)
MCSymbol * createTempSymbol(bool CanBeUnnamed=true)
Create and return a new assembler temporary symbol with a unique but unspecified name.
Target & getTheMips64elTarget()
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
MCTargetStreamer * getTargetStreamer()
Container class for subtarget features.
static FeatureBitset getFeatures(StringRef CPU, StringRef FS, ArrayRef< SubtargetSubTypeKV > ProcDesc, ArrayRef< SubtargetFeatureKV > ProcFeatures)
bool isLittleEndian() const
Tests whether the target triple is little endian.
LLVM_NODISCARD StringRef trim(char Char) const
Return string with consecutive Char characters starting from the left and right removed.
static bool hasShortDelaySlot(MCInst &Inst)
The instances of the Type class are immutable: once they are created, they are never changed...
static uint64_t convertIntToDoubleImm(uint64_t ImmOp64)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static unsigned getRegisterForMxtrC0(MCInst &Inst, bool IsMFTC0)
Interface to description of machine instruction set.
static unsigned countMCSymbolRefExpr(const MCExpr *Expr)
virtual MCAsmLexer & getLexer()=0
void emitRI(unsigned Opcode, unsigned Reg0, int32_t Imm, SMLoc IDLoc, const MCSubtargetInfo *STI)
This file declares a class to represent arbitrary precision floating point values and provide a varie...
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
void emitR(unsigned Opcode, unsigned Reg0, SMLoc IDLoc, const MCSubtargetInfo *STI)
const MCSymbolRefExpr * getSymA() const
static const MCSymbol * getSingleMCSymbol(const MCExpr *Expr)
static unsigned nextReg(unsigned Reg)
int64_t getIntVal() const
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
unsigned getNumOperands() const
const AsmToken peekTok(bool ShouldSkipSpace=true)
Look ahead at the next token to be lexed.
Represents a single fixit, a replacement of one range of text with another.
bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
Binary assembler expressions.
T findFirstSet(T Val, ZeroBehavior ZB=ZB_Max)
Get the index of the first set bit starting from the least significant bit.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Triple - Helper class for working with autoconf configuration names.
std::enable_if< std::numeric_limits< T >::is_signed, bool >::type getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
void emitRRR(unsigned Opcode, unsigned Reg0, unsigned Reg1, unsigned Reg2, SMLoc IDLoc, const MCSubtargetInfo *STI)
MCStreamer & getStreamer()
void setOpcode(unsigned Op)
constexpr bool isInt< 32 >(int64_t x)
void emitDSLL(unsigned DstReg, unsigned SrcReg, int16_t ShiftAmount, SMLoc IDLoc, const MCSubtargetInfo *STI)
const MCSymbol & getSymbol() const
bool hasDelaySlot() const
Returns true if the specified instruction has a delay slot which must be filled by the code generator...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
const MCOperand & getOperand(unsigned i) const
static unsigned getRegisterForMxtrDSP(MCInst &Inst, bool IsMFDSP)
virtual bool EmitRelocDirective(const MCExpr &Offset, StringRef Name, const MCExpr *Expr, SMLoc Loc, const MCSubtargetInfo &STI)
Emit a .reloc directive.
void emitEmptyDelaySlot(bool hasShortDelaySlot, SMLoc IDLoc, const MCSubtargetInfo *STI)
#define LLVM_EXTERNAL_VISIBILITY
void setVariableValue(const MCExpr *Value)
double BitsToDouble(uint64_t Bits)
This function takes a 64-bit integer and returns the bit equivalent double.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
bool is(TokenKind K) const
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
Base class for user error types.
bool mayStore() const
Return true if this instruction could possibly modify memory.
static const MipsMCExpr * create(MipsExprKind Kind, const MCExpr *Expr, MCContext &Ctx)
Target & getTheMipsTarget()
static SMLoc getFromPointer(const char *Ptr)
cl::opt< bool > EmitJalrReloc
void updateABIInfo(const PredicateLibrary &P)
Bitwise operators - logical and, logical or, logical xor.
int16_t RegClass
This specifies the register class enumeration of the operand if the operand is a register.
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeMipsAsmParser()
bool isCall() const
Return true if the instruction is a call.
Generic base class for all target subtargets.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
References to labels and assigned expressions.
constexpr bool isUInt< 16 >(uint64_t x)
bool isNot(AsmToken::TokenKind K) const
Check if the current token has kind K.
unsigned GetZeroReg() const
const MCInstrDesc MipsInsts[]
StringRef getName() const
getName - Get the symbol name.
static StringRef getCPU(StringRef CPU)
Processes a CPU name.
void emitRRI(unsigned Opcode, unsigned Reg0, unsigned Reg1, int16_t Imm, SMLoc IDLoc, const MCSubtargetInfo *STI)
LLVM_NODISCARD const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
void emitRRX(unsigned Opcode, unsigned Reg0, unsigned Reg1, MCOperand Op2, SMLoc IDLoc, const MCSubtargetInfo *STI)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM_NODISCARD char front() const
front - Get the first character in the string.
const MCExpr * getVariableValue(bool SetUsed=true) const
getVariableValue - Get the value for variable symbols.
virtual void emitDirectiveSetReorder()
constexpr uint32_t Hi_32(uint64_t Value)
Return the high 32 bits of a 64 bit value.
LLVM Value Representation.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
const MCOperandInfo * OpInfo
virtual void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
void emitII(unsigned Opcode, int16_t Imm1, int16_t Imm2, SMLoc IDLoc, const MCSubtargetInfo *STI)
This class implements an extremely fast bulk output stream that can only output to a stream...
void addOperand(const MCOperand &Op)
StringRef - Represent a constant reference to a string, i.e.
virtual bool parseIdentifier(StringRef &Res)=0
Parse an identifier or string (as a quoted identifier) and set Res to the identifier contents...
APInt bitcastToAPInt() const
Target specific expression.
unsigned GetNullPtr() const
Represents a location in source code.
This holds information about one operand of a machine instruction, indicating the register class for ...
unsigned getOpcode() const
Instances of this class represent operands of the MCInst class.
static MCOperand createImm(int64_t Val)
TokenKind getKind() const