59 #define DEBUG_TYPE "mips-asm-parser" 69 class MipsAssemblerOptions {
73 MipsAssemblerOptions(
const MipsAssemblerOptions *Opts) {
74 ATReg = Opts->getATRegIndex();
75 Reorder = Opts->isReorder();
76 Macro = Opts->isMacro();
80 unsigned getATRegIndex()
const {
return ATReg; }
81 bool setATRegIndex(
unsigned Reg) {
89 bool isReorder()
const {
return Reorder; }
90 void setReorder() { Reorder =
true; }
91 void setNoReorder() { Reorder =
false; }
93 bool isMacro()
const {
return Macro; }
94 void setMacro() {
Macro =
true; }
95 void setNoMacro() {
Macro =
false; }
116 const FeatureBitset MipsAssemblerOptions::AllArchRelatedMask = {
117 Mips::FeatureMips1, Mips::FeatureMips2, Mips::FeatureMips3,
118 Mips::FeatureMips3_32, Mips::FeatureMips3_32r2, Mips::FeatureMips4,
119 Mips::FeatureMips4_32, Mips::FeatureMips4_32r2, Mips::FeatureMips5,
120 Mips::FeatureMips5_32r2, Mips::FeatureMips32, Mips::FeatureMips32r2,
121 Mips::FeatureMips32r3, Mips::FeatureMips32r5, Mips::FeatureMips32r6,
122 Mips::FeatureMips64, Mips::FeatureMips64r2, Mips::FeatureMips64r3,
123 Mips::FeatureMips64r5, Mips::FeatureMips64r6, Mips::FeatureCnMips,
124 Mips::FeatureFP64Bit, Mips::FeatureGP64Bit, Mips::FeatureNaN2008
145 unsigned CpSaveLocation;
147 bool CpSaveLocationIsRegister;
153 void printWarningWithFixIt(
const Twine &Msg,
const Twine &FixMsg,
154 SMRange Range,
bool ShowColors =
true);
158 #define GET_ASSEMBLER_HEADER 159 #include "MipsGenAsmMatcher.inc" 162 checkEarlyTargetMatchPredicate(
MCInst &Inst,
164 unsigned checkTargetMatchPredicate(
MCInst &Inst)
override;
166 bool MatchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
169 bool MatchingInlineAsm)
override;
172 bool ParseRegister(
unsigned &RegNo,
SMLoc &StartLoc,
SMLoc &EndLoc)
override;
178 bool mnemonicIsValid(
StringRef Mnemonic,
unsigned VariantID);
183 bool ParseDirective(
AsmToken DirectiveID)
override;
205 enum MacroExpanderResultTy {
212 MacroExpanderResultTy tryExpandInstruction(
MCInst &Inst,
SMLoc IDLoc,
219 bool loadImmediate(int64_t ImmValue,
unsigned DstReg,
unsigned SrcReg,
220 bool Is32BitImm,
bool IsAddress,
SMLoc IDLoc,
223 bool loadAndAddSymbolAddress(
const MCExpr *SymExpr,
unsigned DstReg,
224 unsigned SrcReg,
bool Is32BitSym,
SMLoc IDLoc,
229 bool expandLoadImm(
MCInst &Inst,
bool Is32BitImm,
SMLoc IDLoc,
232 bool expandLoadImmReal(
MCInst &Inst,
bool IsSingle,
bool IsGPR,
bool Is64FPU,
236 bool expandLoadAddress(
unsigned DstReg,
unsigned BaseReg,
263 bool expandTrunc(
MCInst &Inst,
bool IsDouble,
bool Is64FPU,
SMLoc IDLoc,
311 bool reportParseError(
Twine ErrorMsg);
312 bool reportParseError(
SMLoc Loc,
Twine ErrorMsg);
314 bool parseMemOffset(
const MCExpr *&Res,
bool isParenExpr);
316 bool isEvaluated(
const MCExpr *Expr);
317 bool parseSetMips0Directive();
318 bool parseSetArchDirective();
319 bool parseSetFeature(uint64_t Feature);
320 bool isPicAndNotNxxAbi();
321 bool parseDirectiveCpLoad(
SMLoc Loc);
322 bool parseDirectiveCpRestore(
SMLoc Loc);
323 bool parseDirectiveCPSetup();
324 bool parseDirectiveCPReturn();
325 bool parseDirectiveNaN();
326 bool parseDirectiveSet();
327 bool parseDirectiveOption();
328 bool parseInsnDirective();
332 bool parseSetAtDirective();
333 bool parseSetNoAtDirective();
334 bool parseSetMacroDirective();
335 bool parseSetNoMacroDirective();
336 bool parseSetMsaDirective();
337 bool parseSetNoMsaDirective();
338 bool parseSetNoDspDirective();
339 bool parseSetReorderDirective();
340 bool parseSetNoReorderDirective();
341 bool parseSetMips16Directive();
342 bool parseSetNoMips16Directive();
343 bool parseSetFpDirective();
344 bool parseSetOddSPRegDirective();
345 bool parseSetNoOddSPRegDirective();
346 bool parseSetPopDirective();
347 bool parseSetPushDirective();
348 bool parseSetSoftFloatDirective();
349 bool parseSetHardFloatDirective();
350 bool parseSetMtDirective();
351 bool parseSetNoMtDirective();
352 bool parseSetNoCRCDirective();
353 bool parseSetNoVirtDirective();
354 bool parseSetNoGINVDirective();
356 bool parseSetAssignment();
358 bool parseDirectiveGpWord();
359 bool parseDirectiveGpDWord();
360 bool parseDirectiveDtpRelWord();
361 bool parseDirectiveDtpRelDWord();
362 bool parseDirectiveTpRelWord();
363 bool parseDirectiveTpRelDWord();
364 bool parseDirectiveModule();
365 bool parseDirectiveModuleFP();
369 bool parseInternalDirectiveReallowModule();
387 unsigned getReg(
int RC,
int RegNo);
392 unsigned getATReg(
SMLoc Loc);
402 bool validateMSAIndex(
int Val,
int RegKind);
429 FeatureBits &= ~MipsAssemblerOptions::AllArchRelatedMask;
431 setAvailableFeatures(
436 void setFeatureBits(uint64_t Feature,
StringRef FeatureString) {
437 if (!(getSTI().getFeatureBits()[Feature])) {
439 setAvailableFeatures(
445 void clearFeatureBits(uint64_t Feature,
StringRef FeatureString) {
446 if (getSTI().getFeatureBits()[Feature]) {
448 setAvailableFeatures(
454 void setModuleFeatureBits(uint64_t Feature,
StringRef FeatureString) {
455 setFeatureBits(Feature, FeatureString);
456 AssemblerOptions.
front()->setFeatures(getSTI().getFeatureBits());
459 void clearModuleFeatureBits(uint64_t Feature,
StringRef FeatureString) {
460 clearFeatureBits(Feature, FeatureString);
461 AssemblerOptions.
front()->setFeatures(getSTI().getFeatureBits());
465 enum MipsMatchResultTy {
466 Match_RequiresDifferentSrcAndDst = FIRST_TARGET_MATCH_RESULT_TY,
467 Match_RequiresDifferentOperands,
468 Match_RequiresNoZeroRegister,
469 Match_RequiresSameSrcAndDst,
470 Match_NoFCCRegisterForCurrentISA,
471 Match_NonZeroOperandForSync,
472 Match_NonZeroOperandForMTCX,
473 Match_RequiresPosSizeRange0_32,
474 Match_RequiresPosSizeRange33_64,
475 Match_RequiresPosSizeUImm6,
476 #define GET_OPERAND_DIAGNOSTIC_TYPES 477 #include "MipsGenAsmMatcher.inc" 478 #undef GET_OPERAND_DIAGNOSTIC_TYPES 494 setAvailableFeatures(ComputeAvailableFeatures(getSTI().getFeatureBits()));
498 llvm::make_unique<MipsAssemblerOptions>(getSTI().getFeatureBits()));
502 llvm::make_unique<MipsAssemblerOptions>(getSTI().getFeatureBits()));
504 getTargetStreamer().updateABIInfo(*
this);
506 if (!isABI_O32() && !useOddSPReg() != 0)
511 IsPicEnabled = getContext().getObjectFileInfo()->isPositionIndependent();
513 IsCpRestoreSet =
false;
514 CpRestoreOffset = -1;
519 if (getSTI().
getCPU() ==
"mips64r6" && inMicroMipsMode())
522 if (!isABI_O32() && inMicroMipsMode())
527 bool hasEightFccRegisters()
const {
return hasMips4() || hasMips32(); }
529 bool isGP64bit()
const {
530 return getSTI().getFeatureBits()[Mips::FeatureGP64Bit];
533 bool isFP64bit()
const {
534 return getSTI().getFeatureBits()[Mips::FeatureFP64Bit];
538 bool isABI_N32()
const {
return ABI.
IsN32(); }
539 bool isABI_N64()
const {
return ABI.
IsN64(); }
540 bool isABI_O32()
const {
return ABI.
IsO32(); }
541 bool isABI_FPXX()
const {
542 return getSTI().getFeatureBits()[Mips::FeatureFPXX];
545 bool useOddSPReg()
const {
546 return !(getSTI().getFeatureBits()[Mips::FeatureNoOddSPReg]);
549 bool inMicroMipsMode()
const {
550 return getSTI().getFeatureBits()[Mips::FeatureMicroMips];
553 bool hasMips1()
const {
554 return getSTI().getFeatureBits()[Mips::FeatureMips1];
557 bool hasMips2()
const {
558 return getSTI().getFeatureBits()[Mips::FeatureMips2];
561 bool hasMips3()
const {
562 return getSTI().getFeatureBits()[Mips::FeatureMips3];
565 bool hasMips4()
const {
566 return getSTI().getFeatureBits()[Mips::FeatureMips4];
569 bool hasMips5()
const {
570 return getSTI().getFeatureBits()[Mips::FeatureMips5];
573 bool hasMips32()
const {
574 return getSTI().getFeatureBits()[Mips::FeatureMips32];
577 bool hasMips64()
const {
578 return getSTI().getFeatureBits()[Mips::FeatureMips64];
581 bool hasMips32r2()
const {
582 return getSTI().getFeatureBits()[Mips::FeatureMips32r2];
585 bool hasMips64r2()
const {
586 return getSTI().getFeatureBits()[Mips::FeatureMips64r2];
589 bool hasMips32r3()
const {
590 return (getSTI().getFeatureBits()[Mips::FeatureMips32r3]);
593 bool hasMips64r3()
const {
594 return (getSTI().getFeatureBits()[Mips::FeatureMips64r3]);
597 bool hasMips32r5()
const {
598 return (getSTI().getFeatureBits()[Mips::FeatureMips32r5]);
601 bool hasMips64r5()
const {
602 return (getSTI().getFeatureBits()[Mips::FeatureMips64r5]);
605 bool hasMips32r6()
const {
606 return getSTI().getFeatureBits()[Mips::FeatureMips32r6];
609 bool hasMips64r6()
const {
610 return getSTI().getFeatureBits()[Mips::FeatureMips64r6];
613 bool hasDSP()
const {
614 return getSTI().getFeatureBits()[Mips::FeatureDSP];
617 bool hasDSPR2()
const {
618 return getSTI().getFeatureBits()[Mips::FeatureDSPR2];
621 bool hasDSPR3()
const {
622 return getSTI().getFeatureBits()[Mips::FeatureDSPR3];
625 bool hasMSA()
const {
626 return getSTI().getFeatureBits()[Mips::FeatureMSA];
629 bool hasCnMips()
const {
630 return (getSTI().getFeatureBits()[Mips::FeatureCnMips]);
637 bool inMips16Mode()
const {
638 return getSTI().getFeatureBits()[Mips::FeatureMips16];
641 bool useTraps()
const {
642 return getSTI().getFeatureBits()[Mips::FeatureUseTCCInDIV];
645 bool useSoftFloat()
const {
646 return getSTI().getFeatureBits()[Mips::FeatureSoftFloat];
649 return getSTI().getFeatureBits()[Mips::FeatureMT];
652 bool hasCRC()
const {
653 return getSTI().getFeatureBits()[Mips::FeatureCRC];
656 bool hasVirt()
const {
657 return getSTI().getFeatureBits()[Mips::FeatureVirt];
660 bool hasGINV()
const {
661 return getSTI().getFeatureBits()[Mips::FeatureGINV];
665 void warnIfRegIndexIsAT(
unsigned RegIndex,
SMLoc Loc);
667 void warnIfNoMacro(
SMLoc Loc);
669 bool isLittle()
const {
return IsLittleEndian; }
674 switch(OperatorToken) {
742 RegKind_MSACtrl = 16,
747 RegKind_HWRegs = 256,
751 RegKind_Numeric = RegKind_GPR | RegKind_FGR | RegKind_FCC | RegKind_MSA128 |
752 RegKind_MSACtrl | RegKind_COP2 | RegKind_ACC |
753 RegKind_CCR | RegKind_HWRegs | RegKind_COP3 | RegKind_COP0
767 MipsOperand(KindTy K, MipsAsmParser &Parser)
770 ~MipsOperand()
override {
779 case k_RegisterIndex:
788 MipsAsmParser &AsmParser;
817 struct RegIdxOp RegIdx;
820 struct RegListOp RegList;
823 SMLoc StartLoc, EndLoc;
826 static std::unique_ptr<MipsOperand> CreateReg(
unsigned Index,
StringRef Str,
830 MipsAsmParser &Parser) {
831 auto Op = llvm::make_unique<MipsOperand>(k_RegisterIndex, Parser);
833 Op->RegIdx.RegInfo = RegInfo;
835 Op->RegIdx.Tok.Data = Str.
data();
836 Op->RegIdx.Tok.Length = Str.
size();
845 unsigned getGPR32Reg()
const {
846 assert(isRegIdx() && (RegIdx.Kind & RegKind_GPR) &&
"Invalid access!");
847 AsmParser.warnIfRegIndexIsAT(RegIdx.Index, StartLoc);
848 unsigned ClassID = Mips::GPR32RegClassID;
849 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
854 unsigned getGPRMM16Reg()
const {
855 assert(isRegIdx() && (RegIdx.Kind & RegKind_GPR) &&
"Invalid access!");
856 unsigned ClassID = Mips::GPR32RegClassID;
857 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
862 unsigned getGPR64Reg()
const {
863 assert(isRegIdx() && (RegIdx.Kind & RegKind_GPR) &&
"Invalid access!");
864 unsigned ClassID = Mips::GPR64RegClassID;
865 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
871 unsigned getAFGR64Reg()
const {
872 assert(isRegIdx() && (RegIdx.Kind & RegKind_FGR) &&
"Invalid access!");
873 if (RegIdx.Index % 2 != 0)
874 AsmParser.Warning(StartLoc,
"Float register should be even.");
875 return RegIdx.RegInfo->getRegClass(Mips::AFGR64RegClassID)
876 .getRegister(RegIdx.Index / 2);
881 unsigned getFGR64Reg()
const {
882 assert(isRegIdx() && (RegIdx.Kind & RegKind_FGR) &&
"Invalid access!");
883 return RegIdx.RegInfo->getRegClass(Mips::FGR64RegClassID)
884 .getRegister(RegIdx.Index);
889 unsigned getFGR32Reg()
const {
890 assert(isRegIdx() && (RegIdx.Kind & RegKind_FGR) &&
"Invalid access!");
891 return RegIdx.RegInfo->getRegClass(Mips::FGR32RegClassID)
892 .getRegister(RegIdx.Index);
897 unsigned getFGRH32Reg()
const {
898 assert(isRegIdx() && (RegIdx.Kind & RegKind_FGR) &&
"Invalid access!");
899 return RegIdx.RegInfo->getRegClass(Mips::FGRH32RegClassID)
900 .getRegister(RegIdx.Index);
905 unsigned getFCCReg()
const {
906 assert(isRegIdx() && (RegIdx.Kind & RegKind_FCC) &&
"Invalid access!");
907 return RegIdx.RegInfo->getRegClass(Mips::FCCRegClassID)
908 .getRegister(RegIdx.Index);
913 unsigned getMSA128Reg()
const {
914 assert(isRegIdx() && (RegIdx.Kind & RegKind_MSA128) &&
"Invalid access!");
917 unsigned ClassID = Mips::MSA128BRegClassID;
918 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
923 unsigned getMSACtrlReg()
const {
924 assert(isRegIdx() && (RegIdx.Kind & RegKind_MSACtrl) &&
"Invalid access!");
925 unsigned ClassID = Mips::MSACtrlRegClassID;
926 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
931 unsigned getCOP0Reg()
const {
932 assert(isRegIdx() && (RegIdx.Kind & RegKind_COP0) &&
"Invalid access!");
933 unsigned ClassID = Mips::COP0RegClassID;
934 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
939 unsigned getCOP2Reg()
const {
940 assert(isRegIdx() && (RegIdx.Kind & RegKind_COP2) &&
"Invalid access!");
941 unsigned ClassID = Mips::COP2RegClassID;
942 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
947 unsigned getCOP3Reg()
const {
948 assert(isRegIdx() && (RegIdx.Kind & RegKind_COP3) &&
"Invalid access!");
949 unsigned ClassID = Mips::COP3RegClassID;
950 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
955 unsigned getACC64DSPReg()
const {
956 assert(isRegIdx() && (RegIdx.Kind & RegKind_ACC) &&
"Invalid access!");
957 unsigned ClassID = Mips::ACC64DSPRegClassID;
958 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
963 unsigned getHI32DSPReg()
const {
964 assert(isRegIdx() && (RegIdx.Kind & RegKind_ACC) &&
"Invalid access!");
965 unsigned ClassID = Mips::HI32DSPRegClassID;
966 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
971 unsigned getLO32DSPReg()
const {
972 assert(isRegIdx() && (RegIdx.Kind & RegKind_ACC) &&
"Invalid access!");
973 unsigned ClassID = Mips::LO32DSPRegClassID;
974 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
979 unsigned getCCRReg()
const {
980 assert(isRegIdx() && (RegIdx.Kind & RegKind_CCR) &&
"Invalid access!");
981 unsigned ClassID = Mips::CCRRegClassID;
982 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
987 unsigned getHWRegsReg()
const {
988 assert(isRegIdx() && (RegIdx.Kind & RegKind_HWRegs) &&
"Invalid access!");
989 unsigned ClassID = Mips::HWRegsRegClassID;
990 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
998 else if (
const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
1004 void addRegOperands(
MCInst &Inst,
unsigned N)
const {
1011 void addGPR32ZeroAsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1012 assert(N == 1 &&
"Invalid number of operands!");
1016 void addGPR32NonZeroAsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1017 assert(N == 1 &&
"Invalid number of operands!");
1021 void addGPR32AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1022 assert(N == 1 &&
"Invalid number of operands!");
1026 void addGPRMM16AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1027 assert(N == 1 &&
"Invalid number of operands!");
1031 void addGPRMM16AsmRegZeroOperands(
MCInst &Inst,
unsigned N)
const {
1032 assert(N == 1 &&
"Invalid number of operands!");
1036 void addGPRMM16AsmRegMovePOperands(
MCInst &Inst,
unsigned N)
const {
1037 assert(N == 1 &&
"Invalid number of operands!");
1044 void addGPR64AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1045 assert(N == 1 &&
"Invalid number of operands!");
1049 void addAFGR64AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1050 assert(N == 1 &&
"Invalid number of operands!");
1054 void addStrictlyAFGR64AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1055 assert(N == 1 &&
"Invalid number of operands!");
1059 void addStrictlyFGR64AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1060 assert(N == 1 &&
"Invalid number of operands!");
1064 void addFGR64AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1065 assert(N == 1 &&
"Invalid number of operands!");
1069 void addFGR32AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1070 assert(N == 1 &&
"Invalid number of operands!");
1074 if (!AsmParser.useOddSPReg() && RegIdx.Index & 1)
1075 AsmParser.getParser().printError(
1076 StartLoc,
"-mno-odd-spreg prohibits the use of odd FPU " 1080 void addStrictlyFGR32AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1081 assert(N == 1 &&
"Invalid number of operands!");
1084 if (!AsmParser.useOddSPReg() && RegIdx.Index & 1)
1085 AsmParser.Error(StartLoc,
"-mno-odd-spreg prohibits the use of odd FPU " 1089 void addFGRH32AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1090 assert(N == 1 &&
"Invalid number of operands!");
1094 void addFCCAsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1095 assert(N == 1 &&
"Invalid number of operands!");
1099 void addMSA128AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1100 assert(N == 1 &&
"Invalid number of operands!");
1104 void addMSACtrlAsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1105 assert(N == 1 &&
"Invalid number of operands!");
1109 void addCOP0AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1110 assert(N == 1 &&
"Invalid number of operands!");
1114 void addCOP2AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1115 assert(N == 1 &&
"Invalid number of operands!");
1119 void addCOP3AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1120 assert(N == 1 &&
"Invalid number of operands!");
1124 void addACC64DSPAsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1125 assert(N == 1 &&
"Invalid number of operands!");
1129 void addHI32DSPAsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1130 assert(N == 1 &&
"Invalid number of operands!");
1134 void addLO32DSPAsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1135 assert(N == 1 &&
"Invalid number of operands!");
1139 void addCCRAsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1140 assert(N == 1 &&
"Invalid number of operands!");
1144 void addHWRegsAsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1145 assert(N == 1 &&
"Invalid number of operands!");
1149 template <
unsigned Bits,
int Offset = 0,
int AdjustOffset = 0>
1150 void addConstantUImmOperands(
MCInst &Inst,
unsigned N)
const {
1151 assert(N == 1 &&
"Invalid number of operands!");
1152 uint64_t Imm = getConstantImm() -
Offset;
1153 Imm &= (1ULL <<
Bits) - 1;
1155 Imm += AdjustOffset;
1159 template <
unsigned Bits>
1160 void addSImmOperands(
MCInst &Inst,
unsigned N)
const {
1161 if (isImm() && !isConstantImm()) {
1162 addExpr(Inst, getImm());
1165 addConstantSImmOperands<Bits, 0, 0>(Inst,
N);
1168 template <
unsigned Bits>
1169 void addUImmOperands(
MCInst &Inst,
unsigned N)
const {
1170 if (isImm() && !isConstantImm()) {
1171 addExpr(Inst, getImm());
1174 addConstantUImmOperands<Bits, 0, 0>(Inst,
N);
1177 template <
unsigned Bits,
int Offset = 0,
int AdjustOffset = 0>
1178 void addConstantSImmOperands(
MCInst &Inst,
unsigned N)
const {
1179 assert(N == 1 &&
"Invalid number of operands!");
1180 int64_t Imm = getConstantImm() -
Offset;
1181 Imm = SignExtend64<Bits>(Imm);
1183 Imm += AdjustOffset;
1187 void addImmOperands(
MCInst &Inst,
unsigned N)
const {
1188 assert(N == 1 &&
"Invalid number of operands!");
1189 const MCExpr *Expr = getImm();
1190 addExpr(Inst, Expr);
1193 void addMemOperands(
MCInst &Inst,
unsigned N)
const {
1194 assert(N == 2 &&
"Invalid number of operands!");
1197 ? getMemBase()->getGPR64Reg()
1198 : getMemBase()->getGPR32Reg()));
1200 const MCExpr *Expr = getMemOff();
1201 addExpr(Inst, Expr);
1204 void addMicroMipsMemOperands(
MCInst &Inst,
unsigned N)
const {
1205 assert(N == 2 &&
"Invalid number of operands!");
1209 const MCExpr *Expr = getMemOff();
1210 addExpr(Inst, Expr);
1213 void addRegListOperands(
MCInst &Inst,
unsigned N)
const {
1214 assert(N == 1 &&
"Invalid number of operands!");
1216 for (
auto RegNo : getRegList())
1220 void addRegPairOperands(
MCInst &Inst,
unsigned N)
const {
1221 assert(N == 2 &&
"Invalid number of operands!");
1222 assert((RegIdx.Kind & RegKind_GPR) &&
"Invalid access!");
1223 unsigned RegNo = getRegPair();
1224 AsmParser.warnIfRegIndexIsAT(RegNo, StartLoc);
1226 RegIdx.RegInfo->getRegClass(
1227 AsmParser.getABI().AreGprs64bit()
1228 ? Mips::GPR64RegClassID
1229 : Mips::GPR32RegClassID).getRegister(RegNo++)));
1231 RegIdx.RegInfo->getRegClass(
1232 AsmParser.getABI().AreGprs64bit()
1233 ? Mips::GPR64RegClassID
1234 : Mips::GPR32RegClassID).getRegister(RegNo)));
1237 void addMovePRegPairOperands(
MCInst &Inst,
unsigned N)
const {
1238 assert(N == 2 &&
"Invalid number of operands!");
1239 for (
auto RegNo : getRegList())
1243 bool isReg()
const override {
1246 return isGPRAsmReg() && RegIdx.Index == 0;
1249 bool isRegIdx()
const {
return Kind == k_RegisterIndex; }
1250 bool isImm()
const override {
return Kind == k_Immediate; }
1252 bool isConstantImm()
const {
1254 return isImm() && getImm()->evaluateAsAbsolute(Res);
1257 bool isConstantImmz()
const {
1258 return isConstantImm() && getConstantImm() == 0;
1261 template <
unsigned Bits,
int Offset = 0>
bool isConstantUImm()
const {
1262 return isConstantImm() && isUInt<Bits>(getConstantImm() -
Offset);
1265 template <
unsigned Bits>
bool isSImm()
const {
1266 return isConstantImm() ? isInt<Bits>(getConstantImm()) : isImm();
1269 template <
unsigned Bits>
bool isUImm()
const {
1270 return isConstantImm() ? isUInt<Bits>(getConstantImm()) : isImm();
1273 template <
unsigned Bits>
bool isAnyImm()
const {
1274 return isConstantImm() ? (isInt<Bits>(getConstantImm()) ||
1275 isUInt<Bits>(getConstantImm()))
1279 template <
unsigned Bits,
int Offset = 0>
bool isConstantSImm()
const {
1280 return isConstantImm() && isInt<Bits>(getConstantImm() -
Offset);
1283 template <
unsigned Bottom,
unsigned Top>
bool isConstantUImmRange()
const {
1284 return isConstantImm() && getConstantImm() >= Bottom &&
1285 getConstantImm() <= Top;
1288 bool isToken()
const override {
1291 return Kind == k_Token;
1294 bool isMem()
const override {
return Kind == k_Memory; }
1296 bool isConstantMemOff()
const {
1297 return isMem() && isa<MCConstantExpr>(getMemOff());
1303 template <
unsigned Bits,
unsigned ShiftAmount = 0>
1304 bool isMemWithSimmOffset()
const {
1307 if (!getMemBase()->isGPRAsmReg())
1309 if (isa<MCTargetExpr>(getMemOff()) ||
1310 (isConstantMemOff() &&
1311 isShiftedInt<Bits, ShiftAmount>(getConstantMemOff())))
1314 bool IsReloc = getMemOff()->evaluateAsRelocatable(Res,
nullptr,
nullptr);
1315 return IsReloc && isShiftedInt<Bits, ShiftAmount>(Res.
getConstant());
1318 bool isMemWithPtrSizeOffset()
const {
1321 if (!getMemBase()->isGPRAsmReg())
1323 const unsigned PtrBits = AsmParser.getABI().ArePtrs64bit() ? 64 : 32;
1324 if (isa<MCTargetExpr>(getMemOff()) ||
1325 (isConstantMemOff() &&
isIntN(PtrBits, getConstantMemOff())))
1328 bool IsReloc = getMemOff()->evaluateAsRelocatable(Res,
nullptr,
nullptr);
1332 bool isMemWithGRPMM16Base()
const {
1333 return isMem() && getMemBase()->isMM16AsmReg();
1336 template <
unsigned Bits>
bool isMemWithUimmOffsetSP()
const {
1337 return isMem() && isConstantMemOff() && isUInt<Bits>(getConstantMemOff())
1338 && getMemBase()->isRegIdx() && (getMemBase()->getGPR32Reg() == Mips::SP);
1341 template <
unsigned Bits>
bool isMemWithUimmWordAlignedOffsetSP()
const {
1342 return isMem() && isConstantMemOff() && isUInt<Bits>(getConstantMemOff())
1343 && (getConstantMemOff() % 4 == 0) && getMemBase()->isRegIdx()
1344 && (getMemBase()->getGPR32Reg() == Mips::SP);
1347 template <
unsigned Bits>
bool isMemWithSimmWordAlignedOffsetGP()
const {
1348 return isMem() && isConstantMemOff() && isInt<Bits>(getConstantMemOff())
1349 && (getConstantMemOff() % 4 == 0) && getMemBase()->isRegIdx()
1350 && (getMemBase()->getGPR32Reg() == Mips::GP);
1353 template <
unsigned Bits,
unsigned ShiftLeftAmount>
1354 bool isScaledUImm()
const {
1355 return isConstantImm() &&
1356 isShiftedUInt<Bits, ShiftLeftAmount>(getConstantImm());
1359 template <
unsigned Bits,
unsigned ShiftLeftAmount>
1360 bool isScaledSImm()
const {
1361 if (isConstantImm() &&
1362 isShiftedInt<Bits, ShiftLeftAmount>(getConstantImm()))
1366 if (Kind != k_Immediate)
1369 bool Success = getImm()->evaluateAsRelocatable(Res,
nullptr,
nullptr);
1370 return Success && isShiftedInt<Bits, ShiftLeftAmount>(Res.
getConstant());
1373 bool isRegList16()
const {
1377 int Size = RegList.List->size();
1378 if (Size < 2 || Size > 5)
1381 unsigned R0 = RegList.List->front();
1382 unsigned R1 = RegList.List->back();
1383 if (!((R0 == Mips::S0 && R1 ==
Mips::RA) ||
1384 (R0 == Mips::S0_64 && R1 == Mips::RA_64)))
1387 int PrevReg = *RegList.List->begin();
1388 for (
int i = 1; i < Size - 1; i++) {
1389 int Reg = (*(RegList.List))[i];
1390 if ( Reg != PrevReg + 1)
1398 bool isInvNum()
const {
return Kind == k_Immediate; }
1400 bool isLSAImm()
const {
1401 if (!isConstantImm())
1403 int64_t Val = getConstantImm();
1404 return 1 <= Val && Val <= 4;
1407 bool isRegList()
const {
return Kind == k_RegList; }
1409 bool isMovePRegPair()
const {
1410 if (Kind != k_RegList || RegList.List->size() != 2)
1413 unsigned R0 = RegList.List->front();
1414 unsigned R1 = RegList.List->back();
1416 if ((R0 == Mips::A1 && R1 == Mips::A2) ||
1417 (R0 == Mips::A1 && R1 == Mips::A3) ||
1418 (R0 == Mips::A2 && R1 == Mips::A3) ||
1419 (R0 == Mips::A0 && R1 == Mips::S5) ||
1420 (R0 == Mips::A0 && R1 == Mips::S6) ||
1421 (R0 == Mips::A0 && R1 == Mips::A1) ||
1422 (R0 == Mips::A0 && R1 == Mips::A2) ||
1423 (R0 == Mips::A0 && R1 == Mips::A3) ||
1424 (R0 == Mips::A1_64 && R1 == Mips::A2_64) ||
1425 (R0 == Mips::A1_64 && R1 == Mips::A3_64) ||
1426 (R0 == Mips::A2_64 && R1 == Mips::A3_64) ||
1427 (R0 == Mips::A0_64 && R1 == Mips::S5_64) ||
1428 (R0 == Mips::A0_64 && R1 == Mips::S6_64) ||
1429 (R0 == Mips::A0_64 && R1 == Mips::A1_64) ||
1430 (R0 == Mips::A0_64 && R1 == Mips::A2_64) ||
1431 (R0 == Mips::A0_64 && R1 == Mips::A3_64))
1438 assert(Kind == k_Token &&
"Invalid access!");
1442 unsigned getReg()
const override {
1445 if (Kind == k_RegisterIndex && RegIdx.Index == 0 &&
1446 RegIdx.Kind & RegKind_GPR)
1447 return getGPR32Reg();
1453 const MCExpr *getImm()
const {
1454 assert((Kind == k_Immediate) &&
"Invalid access!");
1458 int64_t getConstantImm()
const {
1459 const MCExpr *Val = getImm();
1461 (void)Val->evaluateAsAbsolute(Value);
1465 MipsOperand *getMemBase()
const {
1466 assert((Kind == k_Memory) &&
"Invalid access!");
1470 const MCExpr *getMemOff()
const {
1471 assert((Kind == k_Memory) &&
"Invalid access!");
1475 int64_t getConstantMemOff()
const {
1476 return static_cast<const MCConstantExpr *
>(getMemOff())->getValue();
1480 assert((Kind == k_RegList) &&
"Invalid access!");
1481 return *(RegList.List);
1484 unsigned getRegPair()
const {
1485 assert((Kind == k_RegPair) &&
"Invalid access!");
1486 return RegIdx.Index;
1489 static std::unique_ptr<MipsOperand> CreateToken(
StringRef Str,
SMLoc S,
1490 MipsAsmParser &Parser) {
1491 auto Op = llvm::make_unique<MipsOperand>(k_Token, Parser);
1492 Op->Tok.Data = Str.
data();
1493 Op->Tok.Length = Str.
size();
1501 static std::unique_ptr<MipsOperand>
1504 LLVM_DEBUG(
dbgs() <<
"createNumericReg(" << Index <<
", ...)\n");
1505 return CreateReg(Index, Str, RegKind_Numeric, RegInfo, S, E, Parser);
1510 static std::unique_ptr<MipsOperand>
1513 return CreateReg(Index, Str, RegKind_GPR, RegInfo, S, E, Parser);
1518 static std::unique_ptr<MipsOperand>
1521 return CreateReg(Index, Str, RegKind_FGR, RegInfo, S, E, Parser);
1526 static std::unique_ptr<MipsOperand>
1529 return CreateReg(Index, Str, RegKind_HWRegs, RegInfo, S, E, Parser);
1534 static std::unique_ptr<MipsOperand>
1537 return CreateReg(Index, Str, RegKind_FCC, RegInfo, S, E, Parser);
1542 static std::unique_ptr<MipsOperand>
1545 return CreateReg(Index, Str, RegKind_ACC, RegInfo, S, E, Parser);
1550 static std::unique_ptr<MipsOperand>
1553 return CreateReg(Index, Str, RegKind_MSA128, RegInfo, S, E, Parser);
1558 static std::unique_ptr<MipsOperand>
1561 return CreateReg(Index, Str, RegKind_MSACtrl, RegInfo, S, E, Parser);
1564 static std::unique_ptr<MipsOperand>
1566 auto Op = llvm::make_unique<MipsOperand>(k_Immediate, Parser);
1573 static std::unique_ptr<MipsOperand>
1574 CreateMem(std::unique_ptr<MipsOperand>
Base,
const MCExpr *Off,
SMLoc S,
1575 SMLoc E, MipsAsmParser &Parser) {
1576 auto Op = llvm::make_unique<MipsOperand>(k_Memory, Parser);
1577 Op->Mem.Base = Base.release();
1584 static std::unique_ptr<MipsOperand>
1586 MipsAsmParser &Parser) {
1587 assert(Regs.
size() > 0 &&
"Empty list not allowed");
1589 auto Op = llvm::make_unique<MipsOperand>(k_RegList, Parser);
1591 Op->StartLoc = StartLoc;
1592 Op->EndLoc = EndLoc;
1596 static std::unique_ptr<MipsOperand> CreateRegPair(
const MipsOperand &MOP,
1598 MipsAsmParser &Parser) {
1599 auto Op = llvm::make_unique<MipsOperand>(k_RegPair, Parser);
1600 Op->RegIdx.Index = MOP.RegIdx.Index;
1601 Op->RegIdx.RegInfo = MOP.RegIdx.RegInfo;
1602 Op->RegIdx.Kind = MOP.RegIdx.Kind;
1608 bool isGPRZeroAsmReg()
const {
1609 return isRegIdx() && RegIdx.Kind & RegKind_GPR && RegIdx.Index == 0;
1612 bool isGPRNonZeroAsmReg()
const {
1613 return isRegIdx() && RegIdx.Kind & RegKind_GPR && RegIdx.Index > 0 &&
1617 bool isGPRAsmReg()
const {
1618 return isRegIdx() && RegIdx.Kind & RegKind_GPR && RegIdx.Index <= 31;
1621 bool isMM16AsmReg()
const {
1622 if (!(isRegIdx() && RegIdx.Kind))
1624 return ((RegIdx.Index >= 2 && RegIdx.Index <= 7)
1625 || RegIdx.Index == 16 || RegIdx.Index == 17);
1628 bool isMM16AsmRegZero()
const {
1629 if (!(isRegIdx() && RegIdx.Kind))
1631 return (RegIdx.Index == 0 ||
1632 (RegIdx.Index >= 2 && RegIdx.Index <= 7) ||
1633 RegIdx.Index == 17);
1636 bool isMM16AsmRegMoveP()
const {
1637 if (!(isRegIdx() && RegIdx.Kind))
1639 return (RegIdx.Index == 0 || (RegIdx.Index >= 2 && RegIdx.Index <= 3) ||
1640 (RegIdx.Index >= 16 && RegIdx.Index <= 20));
1643 bool isFGRAsmReg()
const {
1645 return isRegIdx() && RegIdx.Kind & RegKind_FGR && RegIdx.Index <= 31;
1648 bool isStrictlyFGRAsmReg()
const {
1650 return isRegIdx() && RegIdx.Kind == RegKind_FGR && RegIdx.Index <= 31;
1653 bool isHWRegsAsmReg()
const {
1654 return isRegIdx() && RegIdx.Kind & RegKind_HWRegs && RegIdx.Index <= 31;
1657 bool isCCRAsmReg()
const {
1658 return isRegIdx() && RegIdx.Kind & RegKind_CCR && RegIdx.Index <= 31;
1661 bool isFCCAsmReg()
const {
1662 if (!(isRegIdx() && RegIdx.Kind & RegKind_FCC))
1664 return RegIdx.Index <= 7;
1667 bool isACCAsmReg()
const {
1668 return isRegIdx() && RegIdx.Kind & RegKind_ACC && RegIdx.Index <= 3;
1671 bool isCOP0AsmReg()
const {
1672 return isRegIdx() && RegIdx.Kind & RegKind_COP0 && RegIdx.Index <= 31;
1675 bool isCOP2AsmReg()
const {
1676 return isRegIdx() && RegIdx.Kind & RegKind_COP2 && RegIdx.Index <= 31;
1679 bool isCOP3AsmReg()
const {
1680 return isRegIdx() && RegIdx.Kind & RegKind_COP3 && RegIdx.Index <= 31;
1683 bool isMSA128AsmReg()
const {
1684 return isRegIdx() && RegIdx.Kind & RegKind_MSA128 && RegIdx.Index <= 31;
1687 bool isMSACtrlAsmReg()
const {
1688 return isRegIdx() && RegIdx.Kind & RegKind_MSACtrl && RegIdx.Index <= 7;
1692 SMLoc getStartLoc()
const override {
return StartLoc; }
1694 SMLoc getEndLoc()
const override {
return EndLoc; }
1705 Mem.Base->print(OS);
1710 case k_RegisterIndex:
1711 OS <<
"RegIdx<" << RegIdx.Index <<
":" << RegIdx.Kind <<
", " 1712 <<
StringRef(RegIdx.Tok.Data, RegIdx.Tok.Length) <<
">";
1719 for (
auto Reg : (*RegList.List))
1724 OS <<
"RegPair<" << RegIdx.Index <<
"," << RegIdx.Index + 1 <<
">";
1729 bool isValidForTie(
const MipsOperand &
Other)
const {
1730 if (Kind != Other.Kind)
1737 case k_RegisterIndex: {
1738 StringRef Token(RegIdx.Tok.Data, RegIdx.Tok.Length);
1739 StringRef OtherToken(Other.RegIdx.Tok.Data, Other.RegIdx.Tok.Length);
1740 return Token == OtherToken;
1761 case Mips::JALRS_MM:
1762 case Mips::JALRS16_MM:
1763 case Mips::BGEZALS_MM:
1764 case Mips::BLTZALS_MM:
1772 if (
const MCSymbolRefExpr *SRExpr = dyn_cast<MCSymbolRefExpr>(Expr)) {
1773 return &SRExpr->getSymbol();
1776 if (
const MCBinaryExpr *BExpr = dyn_cast<MCBinaryExpr>(Expr)) {
1789 if (
const MCUnaryExpr *UExpr = dyn_cast<MCUnaryExpr>(Expr))
1796 if (isa<MCSymbolRefExpr>(Expr))
1799 if (
const MCBinaryExpr *BExpr = dyn_cast<MCBinaryExpr>(Expr))
1803 if (
const MCUnaryExpr *UExpr = dyn_cast<MCUnaryExpr>(Expr))
1809 bool MipsAsmParser::processInstruction(
MCInst &Inst,
SMLoc IDLoc,
1814 bool ExpandedJalSym =
false;
1819 const unsigned Opcode = Inst.
getOpcode();
1829 assert(hasCnMips() &&
"instruction only valid for octeon cpus");
1838 if (!Offset.isImm())
1840 if (!
isIntN(inMicroMipsMode() ? 17 : 18, Offset.getImm()))
1841 return Error(IDLoc,
"branch target out of range");
1843 1LL << (inMicroMipsMode() ? 1 : 2)))
1844 return Error(IDLoc,
"branch to misaligned address");
1858 case Mips::BGEZAL_MM:
1859 case Mips::BLTZAL_MM:
1862 case Mips::BC1EQZC_MMR6:
1863 case Mips::BC1NEZC_MMR6:
1864 case Mips::BC2EQZC_MMR6:
1865 case Mips::BC2NEZC_MMR6:
1868 if (!Offset.isImm())
1870 if (!
isIntN(inMicroMipsMode() ? 17 : 18, Offset.getImm()))
1871 return Error(IDLoc,
"branch target out of range");
1873 1LL << (inMicroMipsMode() ? 1 : 2)))
1874 return Error(IDLoc,
"branch to misaligned address");
1876 case Mips::BGEC:
case Mips::BGEC_MMR6:
1877 case Mips::BLTC:
case Mips::BLTC_MMR6:
1878 case Mips::BGEUC:
case Mips::BGEUC_MMR6:
1879 case Mips::BLTUC:
case Mips::BLTUC_MMR6:
1880 case Mips::BEQC:
case Mips::BEQC_MMR6:
1881 case Mips::BNEC:
case Mips::BNEC_MMR6:
1884 if (!Offset.isImm())
1886 if (!
isIntN(18, Offset.getImm()))
1887 return Error(IDLoc,
"branch target out of range");
1889 return Error(IDLoc,
"branch to misaligned address");
1891 case Mips::BLEZC:
case Mips::BLEZC_MMR6:
1892 case Mips::BGEZC:
case Mips::BGEZC_MMR6:
1893 case Mips::BGTZC:
case Mips::BGTZC_MMR6:
1894 case Mips::BLTZC:
case Mips::BLTZC_MMR6:
1897 if (!Offset.isImm())
1899 if (!
isIntN(18, Offset.getImm()))
1900 return Error(IDLoc,
"branch target out of range");
1902 return Error(IDLoc,
"branch to misaligned address");
1904 case Mips::BEQZC:
case Mips::BEQZC_MMR6:
1905 case Mips::BNEZC:
case Mips::BNEZC_MMR6:
1908 if (!Offset.isImm())
1910 if (!
isIntN(23, Offset.getImm()))
1911 return Error(IDLoc,
"branch target out of range");
1913 return Error(IDLoc,
"branch to misaligned address");
1915 case Mips::BEQZ16_MM:
1916 case Mips::BEQZC16_MMR6:
1917 case Mips::BNEZ16_MM:
1918 case Mips::BNEZC16_MMR6:
1921 if (!Offset.isImm())
1924 return Error(IDLoc,
"branch target out of range");
1926 return Error(IDLoc,
"branch to misaligned address");
1933 if (hasMips32r6() && Inst.
getOpcode() == Mips::SSNOP) {
1934 std::string ISA = hasMips64r6() ?
"MIPS64r6" :
"MIPS32r6";
1935 Warning(IDLoc,
"ssnop is deprecated for " + ISA +
" and is equivalent to a " 1940 const unsigned Opcode = Inst.
getOpcode();
1956 return Error(IDLoc,
"expected immediate operand kind");
1957 Imm = Opnd.getImm();
1958 if (Imm < 0 || Imm > (Opcode == Mips::BBIT0 ||
1959 Opcode == Mips::BBIT1 ? 63 : 31))
1960 return Error(IDLoc,
"immediate operand value out of range");
1962 Inst.
setOpcode(Opcode == Mips::BBIT0 ? Mips::BBIT032
1973 return Error(IDLoc,
"expected immediate operand kind");
1974 Imm = Opnd.getImm();
1975 if (!isInt<10>(Imm))
1976 return Error(IDLoc,
"immediate operand value out of range");
1988 unsigned FirstOp = 1;
1989 unsigned SecondOp = 2;
1993 case Mips::SDivIMacro:
1994 case Mips::UDivIMacro:
1995 case Mips::DSDivIMacro:
1996 case Mips::DUDivIMacro:
2000 Warning(IDLoc,
"dividing zero by zero");
2002 Warning(IDLoc,
"division by zero");
2014 case Mips::SDivMacro:
2015 case Mips::DSDivMacro:
2016 case Mips::UDivMacro:
2017 case Mips::DUDivMacro:
2022 case Mips::DIVU_MMR6:
2023 case Mips::DIV_MMR6:
2028 Warning(IDLoc,
"dividing zero by zero");
2030 Warning(IDLoc,
"division by zero");
2039 BInst.
setOpcode(inMicroMipsMode() ? Mips::BEQ_MM : Mips::BEQ);
2050 warnIfNoMacro(IDLoc);
2057 return Error(IDLoc,
"jal doesn't support multiple symbols in PIC mode");
2076 const MCExpr *Got16RelocExpr =
2078 const MCExpr *Lo16RelocExpr =
2081 TOut.
emitRRX(Mips::LW, Mips::T9, Mips::GP,
2083 TOut.
emitRRX(Mips::ADDiu, Mips::T9, Mips::T9,
2085 }
else if (isABI_N32() || isABI_N64()) {
2091 const MCExpr *GotDispRelocExpr =
2103 const MCExpr *Call16RelocExpr =
2111 if (IsCpRestoreSet && inMicroMipsMode())
2114 JalrInst.
setOpcode(inMicroMipsMode() ? Mips::JALR_MM : Mips::JALR);
2123 ExpandedJalSym =
true;
2136 int64_t MemOffset = Op.
getImm();
2137 if (MemOffset < -32768 || MemOffset > 32767) {
2139 expandMemInst(Inst, IDLoc, Out, STI, MCID.
mayLoad());
2140 return getParser().hasPendingError();
2142 }
else if (Op.
isExpr()) {
2149 expandMemInst(Inst, IDLoc, Out, STI, MCID.
mayLoad());
2150 return getParser().hasPendingError();
2152 }
else if (!isEvaluated(Expr)) {
2153 expandMemInst(Inst, IDLoc, Out, STI, MCID.
mayLoad());
2154 return getParser().hasPendingError();
2161 if (inMicroMipsMode()) {
2170 int MemOffset = Op.
getImm();
2173 if (isInt<9>(MemOffset) && (MemOffset % 4 == 0) &&
2176 (BaseReg.
getReg() == Mips::GP ||
2177 BaseReg.
getReg() == Mips::GP_64)) {
2179 TOut.
emitRRI(Mips::LWGP_MM, DstReg.
getReg(), Mips::GP, MemOffset,
2196 case Mips::ADDIUSP_MM:
2199 return Error(IDLoc,
"expected immediate operand kind");
2201 if (Imm < -1032 || Imm > 1028 || (Imm < 8 && Imm > -12) ||
2203 return Error(IDLoc,
"immediate operand value out of range");
2205 case Mips::SLL16_MM:
2206 case Mips::SRL16_MM:
2209 return Error(IDLoc,
"expected immediate operand kind");
2211 if (Imm < 1 || Imm > 8)
2212 return Error(IDLoc,
"immediate operand value out of range");
2217 return Error(IDLoc,
"expected immediate operand kind");
2219 if (Imm < -1 || Imm > 126)
2220 return Error(IDLoc,
"immediate operand value out of range");
2222 case Mips::ADDIUR2_MM:
2225 return Error(IDLoc,
"expected immediate operand kind");
2227 if (!(Imm == 1 || Imm == -1 ||
2228 ((Imm % 4 == 0) && Imm < 28 && Imm > 0)))
2229 return Error(IDLoc,
"immediate operand value out of range");
2231 case Mips::ANDI16_MM:
2234 return Error(IDLoc,
"expected immediate operand kind");
2236 if (!(Imm == 128 || (Imm >= 1 && Imm <= 4) || Imm == 7 || Imm == 8 ||
2237 Imm == 15 || Imm == 16 || Imm == 31 || Imm == 32 || Imm == 63 ||
2238 Imm == 64 || Imm == 255 || Imm == 32768 || Imm == 65535))
2239 return Error(IDLoc,
"immediate operand value out of range");
2241 case Mips::LBU16_MM:
2244 return Error(IDLoc,
"expected immediate operand kind");
2246 if (Imm < -1 || Imm > 14)
2247 return Error(IDLoc,
"immediate operand value out of range");
2250 case Mips::SB16_MMR6:
2253 return Error(IDLoc,
"expected immediate operand kind");
2255 if (Imm < 0 || Imm > 15)
2256 return Error(IDLoc,
"immediate operand value out of range");
2258 case Mips::LHU16_MM:
2260 case Mips::SH16_MMR6:
2263 return Error(IDLoc,
"expected immediate operand kind");
2265 if (Imm < 0 || Imm > 30 || (Imm % 2 != 0))
2266 return Error(IDLoc,
"immediate operand value out of range");
2270 case Mips::SW16_MMR6:
2273 return Error(IDLoc,
"expected immediate operand kind");
2275 if (Imm < 0 || Imm > 60 || (Imm % 4 != 0))
2276 return Error(IDLoc,
"immediate operand value out of range");
2278 case Mips::ADDIUPC_MM:
2281 return Error(IDLoc,
"expected immediate operand kind");
2283 if ((Imm % 4 != 0) || !isInt<25>(Imm))
2284 return Error(IDLoc,
"immediate operand value out of range");
2289 return Error(IDLoc,
"invalid operand for instruction");
2294 bool FillDelaySlot =
2299 MacroExpanderResultTy ExpandResult =
2300 tryExpandInstruction(Inst, IDLoc, Out, STI);
2301 switch (ExpandResult) {
2313 if (inMicroMipsMode()) {
2320 if (FillDelaySlot) {
2325 if ((Inst.
getOpcode() == Mips::JalOneReg ||
2326 Inst.
getOpcode() == Mips::JalTwoReg || ExpandedJalSym) &&
2327 isPicAndNotNxxAbi()) {
2328 if (IsCpRestoreSet) {
2332 if (!AssemblerOptions.
back()->isReorder())
2339 Warning(IDLoc,
"no .cprestore used in PIC mode");
2345 MipsAsmParser::MacroExpanderResultTy
2350 return MER_NotAMacro;
2351 case Mips::LoadImm32:
2352 return expandLoadImm(Inst,
true, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2353 case Mips::LoadImm64:
2354 return expandLoadImm(Inst,
false, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2355 case Mips::LoadAddrImm32:
2356 case Mips::LoadAddrImm64:
2359 "expected immediate operand kind");
2363 Inst.
getOpcode() == Mips::LoadAddrImm32, IDLoc,
2367 case Mips::LoadAddrReg32:
2368 case Mips::LoadAddrReg64:
2372 "expected immediate operand kind");
2376 Inst.
getOpcode() == Mips::LoadAddrReg32, IDLoc,
2380 case Mips::B_MM_Pseudo:
2381 case Mips::B_MMR6_Pseudo:
2382 return expandUncondBranchMMPseudo(Inst, IDLoc, Out, STI) ? MER_Fail
2386 return expandLoadStoreMultiple(Inst, IDLoc, Out, STI) ? MER_Fail
2388 case Mips::JalOneReg:
2389 case Mips::JalTwoReg:
2390 return expandJalWithRegs(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2393 case Mips::BEQLImmMacro:
2394 case Mips::BNELImmMacro:
2395 return expandBranchImm(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2412 case Mips::BLTImmMacro:
2413 case Mips::BLEImmMacro:
2414 case Mips::BGEImmMacro:
2415 case Mips::BGTImmMacro:
2416 case Mips::BLTUImmMacro:
2417 case Mips::BLEUImmMacro:
2418 case Mips::BGEUImmMacro:
2419 case Mips::BGTUImmMacro:
2420 case Mips::BLTLImmMacro:
2421 case Mips::BLELImmMacro:
2422 case Mips::BGELImmMacro:
2423 case Mips::BGTLImmMacro:
2424 case Mips::BLTULImmMacro:
2425 case Mips::BLEULImmMacro:
2426 case Mips::BGEULImmMacro:
2427 case Mips::BGTULImmMacro:
2428 return expandCondBranches(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2429 case Mips::SDivMacro:
2430 case Mips::SDivIMacro:
2431 case Mips::SRemMacro:
2432 case Mips::SRemIMacro:
2433 return expandDivRem(Inst, IDLoc, Out, STI,
false,
true) ? MER_Fail
2435 case Mips::DSDivMacro:
2436 case Mips::DSDivIMacro:
2437 case Mips::DSRemMacro:
2438 case Mips::DSRemIMacro:
2439 return expandDivRem(Inst, IDLoc, Out, STI,
true,
true) ? MER_Fail
2441 case Mips::UDivMacro:
2442 case Mips::UDivIMacro:
2443 case Mips::URemMacro:
2444 case Mips::URemIMacro:
2445 return expandDivRem(Inst, IDLoc, Out, STI,
false,
false) ? MER_Fail
2447 case Mips::DUDivMacro:
2448 case Mips::DUDivIMacro:
2449 case Mips::DURemMacro:
2450 case Mips::DURemIMacro:
2451 return expandDivRem(Inst, IDLoc, Out, STI,
true,
false) ? MER_Fail
2453 case Mips::PseudoTRUNC_W_S:
2454 return expandTrunc(Inst,
false,
false, IDLoc, Out, STI) ? MER_Fail
2456 case Mips::PseudoTRUNC_W_D32:
2457 return expandTrunc(Inst,
true,
false, IDLoc, Out, STI) ? MER_Fail
2459 case Mips::PseudoTRUNC_W_D:
2460 return expandTrunc(Inst,
true,
true, IDLoc, Out, STI) ? MER_Fail
2463 case Mips::LoadImmSingleGPR:
2464 return expandLoadImmReal(Inst,
true,
true,
false, IDLoc, Out, STI)
2467 case Mips::LoadImmSingleFGR:
2468 return expandLoadImmReal(Inst,
true,
false,
false, IDLoc, Out, STI)
2471 case Mips::LoadImmDoubleGPR:
2472 return expandLoadImmReal(Inst,
false,
true,
false, IDLoc, Out, STI)
2475 case Mips::LoadImmDoubleFGR:
2476 return expandLoadImmReal(Inst,
false,
false,
true, IDLoc, Out, STI)
2479 case Mips::LoadImmDoubleFGR_32:
2480 return expandLoadImmReal(Inst,
false,
false,
false, IDLoc, Out, STI)
2484 return expandUlh(Inst,
true, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2486 return expandUlh(Inst,
false, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2488 return expandUsh(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2491 return expandUxw(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2493 case Mips::NORImm64:
2494 return expandAliasImmediate(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2495 case Mips::SLTImm64:
2498 return MER_NotAMacro;
2500 return expandAliasImmediate(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2501 case Mips::SLTUImm64:
2504 return MER_NotAMacro;
2506 return expandAliasImmediate(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2507 case Mips::ADDi:
case Mips::ADDi_MM:
2508 case Mips::ADDiu:
case Mips::ADDiu_MM:
2509 case Mips::SLTi:
case Mips::SLTi_MM:
2510 case Mips::SLTiu:
case Mips::SLTiu_MM:
2515 return MER_NotAMacro;
2516 return expandAliasImmediate(Inst, IDLoc, Out, STI) ? MER_Fail
2519 return MER_NotAMacro;
2520 case Mips::ANDi:
case Mips::ANDi_MM:
case Mips::ANDi64:
2521 case Mips::ORi:
case Mips::ORi_MM:
case Mips::ORi64:
2522 case Mips::XORi:
case Mips::XORi_MM:
case Mips::XORi64:
2527 return MER_NotAMacro;
2528 return expandAliasImmediate(Inst, IDLoc, Out, STI) ? MER_Fail
2531 return MER_NotAMacro;
2534 return expandRotation(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2537 return expandRotationImm(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2540 return expandDRotation(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2543 return expandDRotationImm(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2544 case Mips::ABSMacro:
2545 return expandAbs(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2546 case Mips::MULImmMacro:
2547 case Mips::DMULImmMacro:
2548 return expandMulImm(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2549 case Mips::MULOMacro:
2550 case Mips::DMULOMacro:
2551 return expandMulO(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2552 case Mips::MULOUMacro:
2553 case Mips::DMULOUMacro:
2554 return expandMulOU(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2555 case Mips::DMULMacro:
2556 return expandDMULMacro(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2559 return expandLoadStoreDMacro(Inst, IDLoc, Out, STI,
2563 case Mips::SEQMacro:
2564 return expandSeq(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2565 case Mips::SEQIMacro:
2566 return expandSeqI(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2567 case Mips::MFTC0:
case Mips::MTTC0:
2568 case Mips::MFTGPR:
case Mips::MTTGPR:
2569 case Mips::MFTLO:
case Mips::MTTLO:
2570 case Mips::MFTHI:
case Mips::MTTHI:
2571 case Mips::MFTACX:
case Mips::MTTACX:
2572 case Mips::MFTDSP:
case Mips::MTTDSP:
2573 case Mips::MFTC1:
case Mips::MTTC1:
2574 case Mips::MFTHC1:
case Mips::MTTHC1:
2575 case Mips::CFTC1:
case Mips::CTTC1:
2576 return expandMXTRAlias(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2580 bool MipsAsmParser::expandJalWithRegs(
MCInst &Inst,
SMLoc IDLoc,
2589 const unsigned Opcode = Inst.
getOpcode();
2591 if (Opcode == Mips::JalOneReg) {
2593 if (IsCpRestoreSet && inMicroMipsMode()) {
2596 }
else if (inMicroMipsMode()) {
2597 JalrInst.
setOpcode(hasMips32r6() ? Mips::JALRC16_MMR6 : Mips::JALR16_MM);
2604 }
else if (Opcode == Mips::JalTwoReg) {
2606 if (IsCpRestoreSet && inMicroMipsMode())
2609 JalrInst.
setOpcode(inMicroMipsMode() ? Mips::JALR_MM : Mips::JALR);
2630 return (x == x >> BitNum << BitNum) && isUInt<N>(x >> BitNum);
2643 bool MipsAsmParser::loadImmediate(int64_t ImmValue,
unsigned DstReg,
2644 unsigned SrcReg,
bool Is32BitImm,
2649 if (!Is32BitImm && !isGP64bit()) {
2650 Error(IDLoc,
"instruction requires a 64-bit architecture");
2659 ImmValue = SignExtend64<32>(ImmValue);
2661 Error(IDLoc,
"instruction requires a 32-bit immediate");
2667 unsigned AdduOp = !Is32BitImm ? Mips::DADDu : Mips::ADDu;
2669 bool UseSrcReg =
false;
2670 if (SrcReg != Mips::NoRegister)
2673 unsigned TmpReg = DstReg;
2675 getContext().getRegisterInfo()->isSuperOrSubRegisterEq(DstReg, SrcReg)) {
2678 unsigned ATReg = getATReg(IDLoc);
2691 if (IsAddress && !Is32BitImm) {
2692 TOut.
emitRRI(Mips::DADDiu, DstReg, SrcReg, ImmValue, IDLoc, STI);
2696 TOut.
emitRRI(Mips::ADDiu, DstReg, SrcReg, ImmValue, IDLoc, STI);
2701 unsigned TmpReg = DstReg;
2702 if (SrcReg == DstReg) {
2703 TmpReg = getATReg(IDLoc);
2708 TOut.
emitRRI(Mips::ORi, TmpReg, ZeroReg, ImmValue, IDLoc, STI);
2715 warnIfNoMacro(IDLoc);
2717 uint16_t Bits31To16 = (ImmValue >> 16) & 0xffff;
2718 uint16_t Bits15To0 = ImmValue & 0xffff;
2719 if (!Is32BitImm && !
isInt<32>(ImmValue)) {
2722 if (ImmValue == 0xffffffff) {
2723 TOut.
emitRI(Mips::LUi, TmpReg, 0xffff, IDLoc, STI);
2724 TOut.
emitRRI(Mips::DSRL32, TmpReg, TmpReg, 0, IDLoc, STI);
2726 TOut.
emitRRR(AdduOp, DstReg, TmpReg, SrcReg, IDLoc, STI);
2732 TOut.
emitRRI(Mips::ORi, TmpReg, ZeroReg, Bits31To16, IDLoc, STI);
2733 TOut.
emitRRI(Mips::DSLL, TmpReg, TmpReg, 16, IDLoc, STI);
2735 TOut.
emitRRI(Mips::ORi, TmpReg, TmpReg, Bits15To0, IDLoc, STI);
2737 TOut.
emitRRR(AdduOp, DstReg, TmpReg, SrcReg, IDLoc, STI);
2741 TOut.
emitRI(Mips::LUi, TmpReg, Bits31To16, IDLoc, STI);
2743 TOut.
emitRRI(Mips::ORi, TmpReg, TmpReg, Bits15To0, IDLoc, STI);
2745 TOut.
emitRRR(AdduOp, DstReg, TmpReg, SrcReg, IDLoc, STI);
2749 if (isShiftedUIntAtAnyPosition<16>(ImmValue)) {
2751 Error(IDLoc,
"instruction requires a 32-bit immediate");
2758 unsigned LastSet =
findLastSet((uint64_t)ImmValue);
2759 unsigned ShiftAmount = FirstSet - (15 - (LastSet - FirstSet));
2760 uint16_t
Bits = (ImmValue >> ShiftAmount) & 0xffff;
2761 TOut.
emitRRI(Mips::ORi, TmpReg, ZeroReg, Bits, IDLoc, STI);
2762 TOut.
emitRRI(Mips::DSLL, TmpReg, TmpReg, ShiftAmount, IDLoc, STI);
2765 TOut.
emitRRR(AdduOp, DstReg, TmpReg, SrcReg, IDLoc, STI);
2770 warnIfNoMacro(IDLoc);
2777 if (loadImmediate(ImmValue >> 32, TmpReg, Mips::NoRegister,
true,
false,
2783 unsigned ShiftCarriedForwards = 16;
2784 for (
int BitNum = 16; BitNum >= 0; BitNum -= 16) {
2785 uint16_t ImmChunk = (ImmValue >> BitNum) & 0xffff;
2787 if (ImmChunk != 0) {
2788 TOut.
emitDSLL(TmpReg, TmpReg, ShiftCarriedForwards, IDLoc, STI);
2789 TOut.
emitRRI(Mips::ORi, TmpReg, TmpReg, ImmChunk, IDLoc, STI);
2790 ShiftCarriedForwards = 0;
2793 ShiftCarriedForwards += 16;
2795 ShiftCarriedForwards -= 16;
2798 if (ShiftCarriedForwards)
2799 TOut.
emitDSLL(TmpReg, TmpReg, ShiftCarriedForwards, IDLoc, STI);
2802 TOut.
emitRRR(AdduOp, DstReg, TmpReg, SrcReg, IDLoc, STI);
2807 bool MipsAsmParser::expandLoadImm(
MCInst &Inst,
bool Is32BitImm,
SMLoc IDLoc,
2810 assert(ImmOp.
isImm() &&
"expected immediate operand kind");
2812 assert(DstRegOp.isReg() &&
"expected register operand kind");
2814 if (loadImmediate(ImmOp.
getImm(), DstRegOp.getReg(), Mips::NoRegister,
2815 Is32BitImm,
false, IDLoc, Out, STI))
2821 bool MipsAsmParser::expandLoadAddress(
unsigned DstReg,
unsigned BaseReg,
2823 bool Is32BitAddress,
SMLoc IDLoc,
2831 Error(IDLoc,
"la used to load 64-bit address");
2833 Is32BitAddress =
false;
2838 if (!Is32BitAddress && !hasMips3()) {
2839 Error(IDLoc,
"instruction requires a 64-bit architecture");
2843 if (!Offset.
isImm())
2844 return loadAndAddSymbolAddress(Offset.
getExpr(), DstReg, BaseReg,
2845 Is32BitAddress, IDLoc, Out, STI);
2849 Is32BitAddress =
true;
2852 return loadImmediate(Offset.
getImm(), DstReg, BaseReg, Is32BitAddress,
true,
2856 bool MipsAsmParser::loadAndAddSymbolAddress(
const MCExpr *SymExpr,
2857 unsigned DstReg,
unsigned SrcReg,
2858 bool Is32BitSym,
SMLoc IDLoc,
2863 bool UseSrcReg = SrcReg != Mips::NoRegister;
2864 warnIfNoMacro(IDLoc);
2866 if (inPicMode() && ABI.
IsO32()) {
2869 Error(IDLoc,
"expected relocatable expression");
2872 if (Res.
getSymB() !=
nullptr) {
2873 Error(IDLoc,
"expected relocatable expression with only one symbol");
2880 if ((DstReg == Mips::T9 || DstReg == Mips::T9_64) && !UseSrcReg &&
2906 const MCExpr *LoExpr =
nullptr;
2917 unsigned TmpReg = DstReg;
2919 getContext().getRegisterInfo()->isSuperOrSubRegisterEq(DstReg,
2923 unsigned ATReg = getATReg(IDLoc);
2937 TOut.
emitRRR(Mips::ADDu, DstReg, TmpReg, SrcReg, IDLoc, STI);
2945 Error(IDLoc,
"expected relocatable expression");
2948 if (Res.
getSymB() !=
nullptr) {
2949 Error(IDLoc,
"expected relocatable expression with only one symbol");
2956 if ((DstReg == Mips::T9 || DstReg == Mips::T9_64) && !UseSrcReg &&
2980 const MCExpr *LoExpr =
nullptr;
2990 Error(IDLoc,
"macro instruction uses large offset, which is not " 2991 "currently supported");
2996 unsigned TmpReg = DstReg;
2998 getContext().getRegisterInfo()->isSuperOrSubRegisterEq(DstReg,
3002 unsigned ATReg = getATReg(IDLoc);
3016 TOut.
emitRRR(Mips::DADDu, DstReg, TmpReg, SrcReg, IDLoc, STI);
3041 getContext().getRegisterInfo()->isSuperOrSubRegisterEq(DstReg, SrcReg);
3043 if (canUseATReg() && UseSrcReg && RdRegIsRsReg) {
3044 unsigned ATReg = getATReg(IDLoc);
3056 TOut.
emitRRX(Mips::DADDiu, ATReg, ATReg,
3058 TOut.
emitRRI(Mips::DSLL, ATReg, ATReg, 16, IDLoc, STI);
3061 TOut.
emitRRI(Mips::DSLL, ATReg, ATReg, 16, IDLoc, STI);
3064 TOut.
emitRRR(Mips::DADDu, DstReg, ATReg, SrcReg, IDLoc, STI);
3067 }
else if (canUseATReg() && !RdRegIsRsReg) {
3068 unsigned ATReg = getATReg(IDLoc);
3084 TOut.
emitRRX(Mips::DADDiu, DstReg, DstReg,
3088 TOut.
emitRRI(Mips::DSLL32, DstReg, DstReg, 0, IDLoc, STI);
3089 TOut.
emitRRR(Mips::DADDu, DstReg, DstReg, ATReg, IDLoc, STI);
3091 TOut.
emitRRR(Mips::DADDu, DstReg, DstReg, SrcReg, IDLoc, STI);
3094 }
else if (!canUseATReg() && !RdRegIsRsReg) {
3105 TOut.
emitRRX(Mips::DADDiu, DstReg, DstReg,
3107 TOut.
emitRRI(Mips::DSLL, DstReg, DstReg, 16, IDLoc, STI);
3108 TOut.
emitRRX(Mips::DADDiu, DstReg, DstReg,
3110 TOut.
emitRRI(Mips::DSLL, DstReg, DstReg, 16, IDLoc, STI);
3111 TOut.
emitRRX(Mips::DADDiu, DstReg, DstReg,
3114 TOut.
emitRRR(Mips::DADDu, DstReg, DstReg, SrcReg, IDLoc, STI);
3120 assert(SrcReg == DstReg && !canUseATReg() &&
3121 "Could have expanded dla but didn't?");
3122 reportParseError(IDLoc,
3123 "pseudo-instruction requires $at, which is not available");
3137 unsigned TmpReg = DstReg;
3139 getContext().getRegisterInfo()->isSuperOrSubRegisterEq(DstReg, SrcReg)) {
3142 unsigned ATReg = getATReg(IDLoc);
3153 TOut.
emitRRR(Mips::ADDu, DstReg, TmpReg, SrcReg, IDLoc, STI);
3156 getContext().getRegisterInfo()->isSuperOrSubRegisterEq(DstReg, TmpReg));
3165 if (MipsMCRegisterClasses[Mips::FGR32RegClassID].
contains(Reg))
3166 return Reg == (
unsigned)Mips::F31 ? (
unsigned)Mips::F0 : Reg + 1;
3168 default:
llvm_unreachable(
"Unknown register in assembly macro expansion!");
3169 case Mips::ZERO:
return Mips::AT;
3170 case Mips::AT:
return Mips::V0;
3171 case Mips::V0:
return Mips::V1;
3172 case Mips::V1:
return Mips::A0;
3173 case Mips::A0:
return Mips::A1;
3174 case Mips::A1:
return Mips::A2;
3175 case Mips::A2:
return Mips::A3;
3176 case Mips::A3:
return Mips::T0;
3179 case Mips::T2:
return Mips::T3;
3180 case Mips::T3:
return Mips::T4;
3181 case Mips::T4:
return Mips::T5;
3182 case Mips::T5:
return Mips::T6;
3183 case Mips::T6:
return Mips::T7;
3184 case Mips::T7:
return Mips::S0;
3185 case Mips::S0:
return Mips::S1;
3186 case Mips::S1:
return Mips::S2;
3187 case Mips::S2:
return Mips::S3;
3188 case Mips::S3:
return Mips::S4;
3189 case Mips::S4:
return Mips::S5;
3190 case Mips::S5:
return Mips::S6;
3191 case Mips::S6:
return Mips::S7;
3194 case Mips::T9:
return Mips::K0;
3195 case Mips::K0:
return Mips::K1;
3196 case Mips::K1:
return Mips::GP;
3197 case Mips::GP:
return Mips::SP;
3198 case Mips::SP:
return Mips::FP;
3201 case Mips::D0:
return Mips::F1;
3202 case Mips::D1:
return Mips::F3;
3203 case Mips::D2:
return Mips::F5;
3204 case Mips::D3:
return Mips::F7;
3205 case Mips::D4:
return Mips::F9;
3206 case Mips::D5:
return Mips::F11;
3207 case Mips::D6:
return Mips::F13;
3208 case Mips::D7:
return Mips::F15;
3209 case Mips::D8:
return Mips::F17;
3210 case Mips::D9:
return Mips::F19;
3211 case Mips::D10:
return Mips::F21;
3212 case Mips::D11:
return Mips::F23;
3213 case Mips::D12:
return Mips::F25;
3214 case Mips::D13:
return Mips::F27;
3215 case Mips::D14:
return Mips::F29;
3216 case Mips::D15:
return Mips::F31;
3228 unsigned ATReg = getATReg(IDLoc);
3238 if(isABI_O32() || isABI_N32()) {
3257 if(isABI_O32() || isABI_N32()) {
3260 const MCExpr *HighestSym =
3264 const MCExpr *HigherSym =
3271 TOut.
emitRRX(Mips::DADDiu, ATReg, ATReg,
3273 TOut.
emitRRI(Mips::DSLL, ATReg, ATReg, 16, IDLoc, STI);
3276 TOut.
emitRRI(Mips::DSLL, ATReg, ATReg, 16, IDLoc, STI);
3282 bool MipsAsmParser::expandLoadImmReal(
MCInst &Inst,
bool IsSingle,
bool IsGPR,
3283 bool Is64FPU,
SMLoc IDLoc,
3289 "Invalid instruction operand.");
3294 uint32_t HiImmOp64 = (ImmOp64 & 0xffffffff00000000) >> 32;
3297 if ((HiImmOp64 & 0x7ff00000) == 0) {
3302 uint32_t LoImmOp64 = ImmOp64 & 0xffffffff;
3303 HiImmOp64 = (ImmOp64 & 0xffffffff00000000) >> 32;
3310 float tmp_float =
static_cast<float>(doubleImm);
3314 if (loadImmediate(ImmOp32, FirstReg, Mips::NoRegister,
true,
true, IDLoc,
3319 unsigned ATReg = getATReg(IDLoc);
3322 if (LoImmOp64 == 0) {
3323 if (loadImmediate(ImmOp32, ATReg, Mips::NoRegister,
true,
true, IDLoc,
3326 TOut.
emitRR(Mips::MTC1, FirstReg, ATReg, IDLoc, STI);
3330 MCSection *CS = getStreamer().getCurrentSectionOnly();
3333 MCSection *ReadOnlySection = getContext().getELFSection(
3336 MCSymbol *Sym = getContext().createTempSymbol();
3342 getStreamer().SwitchSection(ReadOnlySection);
3343 getStreamer().EmitLabel(Sym, IDLoc);
3344 getStreamer().EmitIntValue(ImmOp32, 4);
3345 getStreamer().SwitchSection(CS);
3347 if(emitPartialAddress(TOut, IDLoc, Sym))
3349 TOut.
emitRRX(Mips::LWC1, FirstReg, ATReg,
3356 unsigned ATReg = getATReg(IDLoc);
3361 if (LoImmOp64 == 0) {
3362 if(isABI_N32() || isABI_N64()) {
3363 if (loadImmediate(HiImmOp64, FirstReg, Mips::NoRegister,
false,
true,
3368 if (loadImmediate(HiImmOp64, FirstReg, Mips::NoRegister,
true,
true,
3372 if (loadImmediate(0,
nextReg(FirstReg), Mips::NoRegister,
true,
true,
3379 MCSection *CS = getStreamer().getCurrentSectionOnly();
3380 MCSection *ReadOnlySection = getContext().getELFSection(
3383 MCSymbol *Sym = getContext().createTempSymbol();
3389 getStreamer().SwitchSection(ReadOnlySection);
3390 getStreamer().EmitLabel(Sym, IDLoc);
3391 getStreamer().EmitIntValue(HiImmOp64, 4);
3392 getStreamer().EmitIntValue(LoImmOp64, 4);
3393 getStreamer().SwitchSection(CS);
3395 if(emitPartialAddress(TOut, IDLoc, Sym))
3398 TOut.
emitRRX(Mips::DADDiu, ATReg, ATReg,
3401 TOut.
emitRRX(Mips::ADDiu, ATReg, ATReg,
3404 if(isABI_N32() || isABI_N64())
3407 TOut.
emitRRI(Mips::LW, FirstReg, ATReg, 0, IDLoc, STI);
3412 if ((LoImmOp64 == 0) &&
3413 !((HiImmOp64 & 0xffff0000) && (HiImmOp64 & 0x0000ffff))) {
3416 if (loadImmediate(HiImmOp64, ATReg, Mips::NoRegister,
true,
true, IDLoc,
3419 if (isABI_N32() || isABI_N64())
3420 TOut.
emitRR(Mips::DMTC1, FirstReg, ATReg, IDLoc, STI);
3421 else if (hasMips32r2()) {
3422 TOut.
emitRR(Mips::MTC1, FirstReg, Mips::ZERO, IDLoc, STI);
3423 TOut.
emitRRR(Mips::MTHC1_D32, FirstReg, FirstReg, ATReg, IDLoc, STI);
3425 TOut.
emitRR(Mips::MTC1,
nextReg(FirstReg), ATReg, IDLoc, STI);
3426 TOut.
emitRR(Mips::MTC1, FirstReg, Mips::ZERO, IDLoc, STI);
3431 MCSection *CS = getStreamer().getCurrentSectionOnly();
3434 MCSection *ReadOnlySection = getContext().getELFSection(
3437 MCSymbol *Sym = getContext().createTempSymbol();
3443 getStreamer().SwitchSection(ReadOnlySection);
3444 getStreamer().EmitLabel(Sym, IDLoc);
3445 getStreamer().EmitIntValue(HiImmOp64, 4);
3446 getStreamer().EmitIntValue(LoImmOp64, 4);
3447 getStreamer().SwitchSection(CS);
3449 if(emitPartialAddress(TOut, IDLoc, Sym))
3451 TOut.
emitRRX(Is64FPU ? Mips::LDC164 : Mips::LDC1, FirstReg, ATReg,
3457 bool MipsAsmParser::expandUncondBranchMMPseudo(
MCInst &Inst,
SMLoc IDLoc,
3463 "unexpected number of operands");
3466 if (Offset.isExpr()) {
3473 assert(Offset.isImm() &&
"expected immediate operand kind");
3474 if (isInt<11>(Offset.getImm())) {
3477 if (inMicroMipsMode())
3478 Inst.
setOpcode(hasMips32r6() ? Mips::BC16_MMR6 : Mips::B16_MM);
3480 if (!isInt<17>(Offset.getImm()))
3481 return Error(IDLoc,
"branch target out of range");
3483 return Error(IDLoc,
"branch to misaligned address");
3506 assert(DstRegOp.
isReg() &&
"expected register operand kind");
3509 assert(ImmOp.isImm() &&
"expected immediate operand kind");
3512 assert((MemOffsetOp.isImm() || MemOffsetOp.isExpr()) &&
3513 "expected immediate or expression operand");
3515 bool IsLikely =
false;
3517 unsigned OpCode = 0;
3525 case Mips::BEQLImmMacro:
3526 OpCode = Mips::BEQL;
3529 case Mips::BNELImmMacro:
3530 OpCode = Mips::BNEL;
3538 int64_t ImmValue = ImmOp.getImm();
3539 if (ImmValue == 0) {
3543 TOut.
emitRRI(Mips::SLL, Mips::ZERO, Mips::ZERO, 0, IDLoc, STI);
3545 TOut.
emitRRX(OpCode, DstRegOp.
getReg(), Mips::ZERO, MemOffsetOp, IDLoc,
3548 warnIfNoMacro(IDLoc);
3550 unsigned ATReg = getATReg(IDLoc);
3554 if (loadImmediate(ImmValue, ATReg, Mips::NoRegister, !isGP64bit(),
true,
3561 TOut.
emitRRI(Mips::SLL, Mips::ZERO, Mips::ZERO, 0, IDLoc, STI);
3563 TOut.
emitRRX(OpCode, DstRegOp.
getReg(), ATReg, MemOffsetOp, IDLoc, STI);
3571 assert(DstRegOp.
isReg() &&
"expected register operand kind");
3573 assert(BaseRegOp.isReg() &&
"expected register operand kind");
3577 unsigned DstReg = DstRegOp.
getReg();
3578 unsigned BaseReg = BaseRegOp.getReg();
3579 unsigned TmpReg = DstReg;
3583 unsigned DstRegClassID =
3584 getContext().getRegisterInfo()->getRegClass(DstRegClass).getID();
3585 bool IsGPR = (DstRegClassID == Mips::GPR32RegClassID) ||
3586 (DstRegClassID == Mips::GPR64RegClassID);
3588 if (!IsLoad || !IsGPR || (BaseReg == DstReg)) {
3591 TmpReg = getATReg(IDLoc);
3596 if (OffsetOp.isImm()) {
3597 int64_t LoOffset = OffsetOp.getImm() & 0xffff;
3598 int64_t HiOffset = OffsetOp.getImm() & ~0xffff;
3602 if (LoOffset & 0x8000)
3603 HiOffset += 0x10000;
3605 bool IsLargeOffset = HiOffset != 0;
3607 if (IsLargeOffset) {
3608 bool Is32BitImm = (HiOffset >> 32) == 0;
3609 if (loadImmediate(HiOffset, TmpReg, Mips::NoRegister, Is32BitImm,
true,
3614 if (BaseReg != Mips::ZERO && BaseReg != Mips::ZERO_64)
3615 TOut.
emitRRR(isGP64bit() ? Mips::DADDu : Mips::ADDu, TmpReg, TmpReg,
3616 BaseReg, IDLoc, STI);
3619 assert(OffsetOp.isExpr() &&
"expected expression operand kind");
3620 const MCExpr *ExprOffset = OffsetOp.getExpr();
3628 LoOperand, TmpReg, IDLoc, STI);
3631 LoOperand, TmpReg, IDLoc, STI);
3635 bool MipsAsmParser::expandLoadStoreMultiple(
MCInst &Inst,
SMLoc IDLoc,
3640 unsigned NewOpcode = Opcode == Mips::SWM_MM ? Mips::SWM32_MM : Mips::LWM32_MM;
3644 Inst.
getOperand(OpNum - 3).
isReg() &&
"Invalid instruction operand.");
3653 if (inMicroMipsMode() && hasMips32r6())
3654 NewOpcode = Opcode == Mips::SWM_MM ? Mips::SWM16_MMR6 : Mips::LWM16_MMR6;
3656 NewOpcode = Opcode == Mips::SWM_MM ? Mips::SWM16_MM : Mips::LWM16_MM;
3664 bool MipsAsmParser::expandCondBranches(
MCInst &Inst,
SMLoc IDLoc,
3668 bool EmittedNoMacroWarning =
false;
3669 unsigned PseudoOpcode = Inst.
getOpcode();
3674 unsigned ZeroSrcOpcode, ZeroTrgOpcode;
3675 bool ReverseOrderSLT, IsUnsigned, IsLikely, AcceptsEquality;
3680 else if (TrgOp.
isImm()) {
3681 warnIfNoMacro(IDLoc);
3682 EmittedNoMacroWarning =
true;
3684 TrgReg = getATReg(IDLoc);
3688 switch(PseudoOpcode) {
3691 case Mips::BLTImmMacro:
3692 PseudoOpcode = Mips::BLT;
3694 case Mips::BLEImmMacro:
3695 PseudoOpcode = Mips::BLE;
3697 case Mips::BGEImmMacro:
3698 PseudoOpcode = Mips::BGE;
3700 case Mips::BGTImmMacro:
3701 PseudoOpcode = Mips::BGT;
3703 case Mips::BLTUImmMacro:
3704 PseudoOpcode = Mips::BLTU;
3706 case Mips::BLEUImmMacro:
3707 PseudoOpcode = Mips::BLEU;
3709 case Mips::BGEUImmMacro:
3710 PseudoOpcode = Mips::BGEU;
3712 case Mips::BGTUImmMacro:
3713 PseudoOpcode = Mips::BGTU;
3715 case Mips::BLTLImmMacro:
3716 PseudoOpcode = Mips::BLTL;
3718 case Mips::BLELImmMacro:
3719 PseudoOpcode = Mips::BLEL;
3721 case Mips::BGELImmMacro:
3722 PseudoOpcode = Mips::BGEL;
3724 case Mips::BGTLImmMacro:
3725 PseudoOpcode = Mips::BGTL;
3727 case Mips::BLTULImmMacro:
3728 PseudoOpcode = Mips::BLTUL;
3730 case Mips::BLEULImmMacro:
3731 PseudoOpcode = Mips::BLEUL;
3733 case Mips::BGEULImmMacro:
3734 PseudoOpcode = Mips::BGEUL;
3736 case Mips::BGTULImmMacro:
3737 PseudoOpcode = Mips::BGTUL;
3741 if (loadImmediate(TrgOp.
getImm(), TrgReg, Mips::NoRegister, !isGP64bit(),
3742 false, IDLoc, Out, STI))
3746 switch (PseudoOpcode) {
3751 AcceptsEquality =
false;
3752 ReverseOrderSLT =
false;
3754 ((PseudoOpcode == Mips::BLTU) || (PseudoOpcode == Mips::BLTUL));
3755 IsLikely = ((PseudoOpcode == Mips::BLTL) || (PseudoOpcode == Mips::BLTUL));
3756 ZeroSrcOpcode = Mips::BGTZ;
3757 ZeroTrgOpcode = Mips::BLTZ;
3763 AcceptsEquality =
true;
3764 ReverseOrderSLT =
true;
3766 ((PseudoOpcode == Mips::BLEU) || (PseudoOpcode == Mips::BLEUL));
3767 IsLikely = ((PseudoOpcode == Mips::BLEL) || (PseudoOpcode == Mips::BLEUL));
3768 ZeroSrcOpcode = Mips::BGEZ;
3769 ZeroTrgOpcode = Mips::BLEZ;
3775 AcceptsEquality =
true;
3776 ReverseOrderSLT =
false;
3778 ((PseudoOpcode == Mips::BGEU) || (PseudoOpcode == Mips::BGEUL));
3779 IsLikely = ((PseudoOpcode == Mips::BGEL) || (PseudoOpcode == Mips::BGEUL));
3780 ZeroSrcOpcode = Mips::BLEZ;
3781 ZeroTrgOpcode = Mips::BGEZ;
3787 AcceptsEquality =
false;
3788 ReverseOrderSLT =
true;
3790 ((PseudoOpcode == Mips::BGTU) || (PseudoOpcode == Mips::BGTUL));
3791 IsLikely = ((PseudoOpcode == Mips::BGTL) || (PseudoOpcode == Mips::BGTUL));
3792 ZeroSrcOpcode = Mips::BLTZ;
3793 ZeroTrgOpcode = Mips::BGTZ;
3799 bool IsTrgRegZero = (TrgReg == Mips::ZERO);
3800 bool IsSrcRegZero = (SrcReg == Mips::ZERO);
3801 if (IsSrcRegZero && IsTrgRegZero) {
3805 if (PseudoOpcode == Mips::BLT) {
3810 if (PseudoOpcode == Mips::BLE) {
3813 Warning(IDLoc,
"branch is always taken");
3816 if (PseudoOpcode == Mips::BGE) {
3819 Warning(IDLoc,
"branch is always taken");
3822 if (PseudoOpcode == Mips::BGT) {
3827 if (PseudoOpcode == Mips::BGTU) {
3828 TOut.
emitRRX(Mips::BNE, Mips::ZERO, Mips::ZERO,
3832 if (AcceptsEquality) {
3835 TOut.
emitRRX(Mips::BEQ, Mips::ZERO, Mips::ZERO,
3837 Warning(IDLoc,
"branch is always taken");
3844 if (IsSrcRegZero || IsTrgRegZero) {
3845 if ((IsSrcRegZero && PseudoOpcode == Mips::BGTU) ||
3846 (IsTrgRegZero && PseudoOpcode == Mips::BLTU)) {
3853 if ((IsSrcRegZero && PseudoOpcode == Mips::BLEU) ||
3854 (IsTrgRegZero && PseudoOpcode == Mips::BGEU)) {
3860 TOut.
emitRRX(Mips::BEQ, Mips::ZERO, Mips::ZERO,
3862 Warning(IDLoc,
"branch is always taken");
3878 TOut.
emitRRX(AcceptsEquality ? Mips::BEQ : Mips::BNE,
3879 IsSrcRegZero ? TrgReg : SrcReg, Mips::ZERO,
3886 TOut.
emitRX(IsSrcRegZero ? ZeroSrcOpcode : ZeroTrgOpcode,
3887 IsSrcRegZero ? TrgReg : SrcReg,
3894 unsigned ATRegNum = getATReg(IDLoc);
3898 if (!EmittedNoMacroWarning)
3899 warnIfNoMacro(IDLoc);
3916 TOut.
emitRRR(IsUnsigned ? Mips::SLTu : Mips::SLT, ATRegNum,
3917 ReverseOrderSLT ? TrgReg : SrcReg,
3918 ReverseOrderSLT ? SrcReg : TrgReg, IDLoc, STI);
3920 TOut.
emitRRX(IsLikely ? (AcceptsEquality ? Mips::BEQL : Mips::BNEL)
3921 : (AcceptsEquality ? Mips::BEQ : Mips::BNE),
3940 warnIfNoMacro(IDLoc);
3943 assert(RdRegOp.
isReg() &&
"expected register operand kind");
3944 unsigned RdReg = RdRegOp.
getReg();
3947 assert(RsRegOp.
isReg() &&
"expected register operand kind");
3948 unsigned RsReg = RsRegOp.
getReg();
3955 "expected register or immediate operand kind");
3959 ImmValue = RtOp.
getImm();
3966 DivOp = Signed ? Mips::DSDIV : Mips::DUDIV;
3967 ZeroReg = Mips::ZERO_64;
3971 ZeroReg = Mips::ZERO;
3975 bool UseTraps = useTraps();
3978 bool isDiv = Opcode == Mips::SDivMacro || Opcode == Mips::SDivIMacro ||
3979 Opcode == Mips::UDivMacro || Opcode == Mips::UDivIMacro ||
3980 Opcode == Mips::DSDivMacro || Opcode == Mips::DSDivIMacro ||
3981 Opcode == Mips::DUDivMacro || Opcode == Mips::DUDivIMacro;
3983 bool isRem = Opcode == Mips::SRemMacro || Opcode == Mips::SRemIMacro ||
3984 Opcode == Mips::URemMacro || Opcode == Mips::URemIMacro ||
3985 Opcode == Mips::DSRemMacro || Opcode == Mips::DSRemIMacro ||
3986 Opcode == Mips::DURemMacro || Opcode == Mips::DURemIMacro;
3989 unsigned ATReg = getATReg(IDLoc);
3993 if (ImmValue == 0) {
3995 TOut.
emitRRI(Mips::TEQ, ZeroReg, ZeroReg, 0x7, IDLoc, STI);
3997 TOut.
emitII(Mips::BREAK, 0x7, 0, IDLoc, STI);
4001 if (isRem && (ImmValue == 1 || (Signed && (ImmValue == -1)))) {
4004 }
else if (isDiv && ImmValue == 1) {
4007 }
else if (isDiv && Signed && ImmValue == -1) {
4008 TOut.
emitRRR(SubOp, RdReg, ZeroReg, RsReg, IDLoc, STI);
4011 if (loadImmediate(ImmValue, ATReg, Mips::NoRegister,
isInt<32>(ImmValue),
4012 false, Inst.
getLoc(), Out, STI))
4014 TOut.
emitRR(DivOp, RsReg, ATReg, IDLoc, STI);
4025 if (RtReg == Mips::ZERO || RtReg == Mips::ZERO_64) {
4027 TOut.
emitRRI(Mips::TEQ, ZeroReg, ZeroReg, 0x7, IDLoc, STI);
4030 TOut.
emitII(Mips::BREAK, 0x7, 0, IDLoc, STI);
4036 if (isRem && (RdReg == Mips::ZERO || RdReg == Mips::ZERO_64)) {
4037 TOut.
emitRR(DivOp, RsReg, RtReg, IDLoc, STI);
4047 TOut.
emitRRI(Mips::TEQ, RtReg, ZeroReg, 0x7, IDLoc, STI);
4052 TOut.
emitRRX(Mips::BNE, RtReg, ZeroReg, LabelOp, IDLoc, STI);
4055 TOut.
emitRR(DivOp, RsReg, RtReg, IDLoc, STI);
4058 TOut.
emitII(Mips::BREAK, 0x7, 0, IDLoc, STI);
4068 unsigned ATReg = getATReg(IDLoc);
4075 TOut.
emitRRI(Mips::ADDiu, ATReg, ZeroReg, -1, IDLoc, STI);
4083 TOut.
emitRRX(Mips::BNE, RtReg, ATReg, LabelOpEnd, IDLoc, STI);
4086 TOut.
emitRRI(Mips::ADDiu, ATReg, ZeroReg, 1, IDLoc, STI);
4087 TOut.
emitDSLL(ATReg, ATReg, 63, IDLoc, STI);
4089 TOut.
emitRI(Mips::LUi, ATReg, (uint16_t)0x8000, IDLoc, STI);
4093 TOut.
emitRRI(Mips::TEQ, RsReg, ATReg, 0x6, IDLoc, STI);
4096 TOut.
emitRRX(Mips::BNE, RsReg, ATReg, LabelOpEnd, IDLoc, STI);
4098 TOut.
emitII(Mips::BREAK, 0x6, 0, IDLoc, STI);
4106 bool MipsAsmParser::expandTrunc(
MCInst &Inst,
bool IsDouble,
bool Is64FPU,
4119 if (hasMips1() && !hasMips2()) {
4120 unsigned ATReg = getATReg(IDLoc);
4126 TOut.
emitRRI(Mips::ORi, ATReg, ThirdReg, 0x3, IDLoc, STI);
4127 TOut.
emitRRI(Mips::XORi, ATReg, ATReg, 0x2, IDLoc, STI);
4130 TOut.
emitRR(IsDouble ? (Is64FPU ? Mips::CVT_W_D64 : Mips::CVT_W_D32)
4132 FirstReg, SecondReg, IDLoc, STI);
4138 TOut.
emitRR(IsDouble ? (Is64FPU ? Mips::TRUNC_W_D64 : Mips::TRUNC_W_D32)
4140 FirstReg, SecondReg, IDLoc, STI);
4145 bool MipsAsmParser::expandUlh(
MCInst &Inst,
bool Signed,
SMLoc IDLoc,
4147 if (hasMips32r6() || hasMips64r6()) {
4148 return Error(IDLoc,
"instruction not supported on mips32r6 or mips64r6");
4152 assert(DstRegOp.
isReg() &&
"expected register operand kind");
4154 assert(SrcRegOp.isReg() &&
"expected register operand kind");
4156 assert(OffsetImmOp.isImm() &&
"expected immediate operand kind");
4159 unsigned DstReg = DstRegOp.
getReg();
4160 unsigned SrcReg = SrcRegOp.getReg();
4161 int64_t OffsetValue = OffsetImmOp.getImm();
4165 warnIfNoMacro(IDLoc);
4166 unsigned ATReg = getATReg(IDLoc);
4171 if (IsLargeOffset) {
4172 if (loadImmediate(OffsetValue, ATReg, SrcReg, !ABI.
ArePtrs64bit(),
true,
4177 int64_t FirstOffset = IsLargeOffset ? 0 : OffsetValue;
4178 int64_t SecondOffset = IsLargeOffset ? 1 : (OffsetValue + 1);
4182 unsigned FirstLbuDstReg = IsLargeOffset ? DstReg : ATReg;
4183 unsigned SecondLbuDstReg = IsLargeOffset ? ATReg : DstReg;
4185 unsigned LbuSrcReg = IsLargeOffset ? ATReg : SrcReg;
4186 unsigned SllReg = IsLargeOffset ? DstReg : ATReg;
4188 TOut.emitRRI(Signed ? Mips::LB : Mips::LBu, FirstLbuDstReg, LbuSrcReg,
4189 FirstOffset, IDLoc, STI);
4190 TOut.emitRRI(Mips::LBu, SecondLbuDstReg, LbuSrcReg, SecondOffset, IDLoc, STI);
4191 TOut.emitRRI(Mips::SLL, SllReg, SllReg, 8, IDLoc, STI);
4192 TOut.emitRRR(
Mips::OR, DstReg, DstReg, ATReg, IDLoc, STI);
4199 if (hasMips32r6() || hasMips64r6()) {
4200 return Error(IDLoc,
"instruction not supported on mips32r6 or mips64r6");
4204 assert(DstRegOp.
isReg() &&
"expected register operand kind");
4206 assert(SrcRegOp.isReg() &&
"expected register operand kind");
4208 assert(OffsetImmOp.isImm() &&
"expected immediate operand kind");
4211 unsigned DstReg = DstRegOp.
getReg();
4212 unsigned SrcReg = SrcRegOp.getReg();
4213 int64_t OffsetValue = OffsetImmOp.getImm();
4215 warnIfNoMacro(IDLoc);
4216 unsigned ATReg = getATReg(IDLoc);
4221 if (IsLargeOffset) {
4222 if (loadImmediate(OffsetValue, ATReg, SrcReg, !ABI.
ArePtrs64bit(),
true,
4227 int64_t FirstOffset = IsLargeOffset ? 1 : (OffsetValue + 1);
4228 int64_t SecondOffset = IsLargeOffset ? 0 : OffsetValue;
4232 if (IsLargeOffset) {
4233 TOut.emitRRI(Mips::SB, DstReg, ATReg, FirstOffset, IDLoc, STI);
4234 TOut.emitRRI(
Mips::SRL, DstReg, DstReg, 8, IDLoc, STI);
4235 TOut.emitRRI(Mips::SB, DstReg, ATReg, SecondOffset, IDLoc, STI);
4236 TOut.emitRRI(Mips::LBu, ATReg, ATReg, 0, IDLoc, STI);
4237 TOut.emitRRI(Mips::SLL, DstReg, DstReg, 8, IDLoc, STI);
4238 TOut.emitRRR(
Mips::OR, DstReg, DstReg, ATReg, IDLoc, STI);
4240 TOut.emitRRI(Mips::SB, DstReg, SrcReg, FirstOffset, IDLoc, STI);
4241 TOut.emitRRI(
Mips::SRL, ATReg, DstReg, 8, IDLoc, STI);
4242 TOut.emitRRI(Mips::SB, ATReg, SrcReg, SecondOffset, IDLoc, STI);
4250 if (hasMips32r6() || hasMips64r6()) {
4251 return Error(IDLoc,
"instruction not supported on mips32r6 or mips64r6");
4255 assert(DstRegOp.
isReg() &&
"expected register operand kind");
4257 assert(SrcRegOp.isReg() &&
"expected register operand kind");
4259 assert(OffsetImmOp.isImm() &&
"expected immediate operand kind");
4262 unsigned DstReg = DstRegOp.
getReg();
4263 unsigned SrcReg = SrcRegOp.getReg();
4264 int64_t OffsetValue = OffsetImmOp.getImm();
4268 int64_t LxlOffset = IsLargeOffset ? 0 : OffsetValue;
4269 int64_t LxrOffset = IsLargeOffset ? 3 : (OffsetValue + 3);
4273 bool IsLoadInst = (Inst.
getOpcode() == Mips::Ulw);
4274 bool DoMove = IsLoadInst && (SrcReg == DstReg) && !IsLargeOffset;
4275 unsigned TmpReg = SrcReg;
4276 if (IsLargeOffset || DoMove) {
4277 warnIfNoMacro(IDLoc);
4278 TmpReg = getATReg(IDLoc);
4283 if (IsLargeOffset) {
4284 if (loadImmediate(OffsetValue, TmpReg, SrcReg, !ABI.
ArePtrs64bit(),
true,
4294 TOut.emitRRI(XWL, DstReg, TmpReg, LxlOffset, IDLoc, STI);
4295 TOut.emitRRI(XWR, DstReg, TmpReg, LxrOffset, IDLoc, STI);
4298 TOut.emitRRR(
Mips::OR, TmpReg, DstReg, Mips::ZERO, IDLoc, STI);
4303 bool MipsAsmParser::expandAliasImmediate(
MCInst &Inst,
SMLoc IDLoc,
4313 unsigned ATReg = Mips::NoRegister;
4314 unsigned FinalDstReg = Mips::NoRegister;
4321 unsigned FinalOpcode = Inst.
getOpcode();
4323 if (DstReg == SrcReg) {
4324 ATReg = getATReg(Inst.
getLoc());
4327 FinalDstReg = DstReg;
4331 if (!loadImmediate(ImmValue, DstReg, Mips::NoRegister, Is32Bit,
false,
4332 Inst.
getLoc(), Out, STI)) {
4333 switch (FinalOpcode) {
4340 FinalOpcode = Mips::ADDu;
4346 FinalOpcode = Mips::NOR;
4352 FinalOpcode = Mips::SLT;
4355 FinalOpcode = Mips::SLTu;
4361 FinalOpcode = Mips::ADD_MM;
4363 case Mips::ADDiu_MM:
4364 FinalOpcode = Mips::ADDu_MM;
4367 FinalOpcode = Mips::AND_MM;
4370 FinalOpcode = Mips::OR_MM;
4373 FinalOpcode = Mips::SLT_MM;
4375 case Mips::SLTiu_MM:
4376 FinalOpcode = Mips::SLTu_MM;
4379 FinalOpcode = Mips::XOR_MM;
4382 FinalOpcode = Mips::AND64;
4384 case Mips::NORImm64:
4385 FinalOpcode = Mips::NOR64;
4388 FinalOpcode = Mips::OR64;
4390 case Mips::SLTImm64:
4391 FinalOpcode = Mips::SLT64;
4393 case Mips::SLTUImm64:
4394 FinalOpcode = Mips::SLTu64;
4397 FinalOpcode = Mips::XOR64;
4401 if (FinalDstReg == Mips::NoRegister)
4402 TOut.
emitRRR(FinalOpcode, DstReg, DstReg, SrcReg, IDLoc, STI);
4404 TOut.
emitRRR(FinalOpcode, FinalDstReg, FinalDstReg, DstReg, IDLoc, STI);
4413 unsigned ATReg = Mips::NoRegister;
4417 unsigned TmpReg = DReg;
4419 unsigned FirstShift = Mips::NOP;
4420 unsigned SecondShift = Mips::NOP;
4422 if (hasMips32r2()) {
4424 TmpReg = getATReg(Inst.
getLoc());
4430 TOut.
emitRRR(Mips::SUBu, TmpReg, Mips::ZERO, TReg, Inst.
getLoc(), STI);
4431 TOut.
emitRRR(Mips::ROTRV, DReg, SReg, TmpReg, Inst.
getLoc(), STI);
4436 TOut.
emitRRR(Mips::ROTRV, DReg, SReg, TReg, Inst.
getLoc(), STI);
4448 FirstShift = Mips::SRLV;
4449 SecondShift = Mips::SLLV;
4452 FirstShift = Mips::SLLV;
4453 SecondShift = Mips::SRLV;
4457 ATReg = getATReg(Inst.
getLoc());
4461 TOut.
emitRRR(Mips::SUBu, ATReg, Mips::ZERO, TReg, Inst.
getLoc(), STI);
4462 TOut.
emitRRR(FirstShift, ATReg, SReg, ATReg, Inst.
getLoc(), STI);
4463 TOut.
emitRRR(SecondShift, DReg, SReg, TReg, Inst.
getLoc(), STI);
4472 bool MipsAsmParser::expandRotationImm(
MCInst &Inst,
SMLoc IDLoc,
4476 unsigned ATReg = Mips::NoRegister;
4481 unsigned FirstShift = Mips::NOP;
4482 unsigned SecondShift = Mips::NOP;
4484 if (hasMips32r2()) {
4486 uint64_t MaxShift = 32;
4487 uint64_t ShiftValue = ImmValue;
4489 ShiftValue = MaxShift - ImmValue;
4503 if (ImmValue == 0) {
4512 FirstShift = Mips::SLL;
4517 SecondShift = Mips::SLL;
4521 ATReg = getATReg(Inst.
getLoc());
4525 TOut.
emitRRI(FirstShift, ATReg, SReg, ImmValue, Inst.
getLoc(), STI);
4526 TOut.
emitRRI(SecondShift, DReg, SReg, 32 - ImmValue, Inst.
getLoc(), STI);
4538 unsigned ATReg = Mips::NoRegister;
4542 unsigned TmpReg = DReg;
4544 unsigned FirstShift = Mips::NOP;
4545 unsigned SecondShift = Mips::NOP;
4547 if (hasMips64r2()) {
4548 if (TmpReg == SReg) {
4549 TmpReg = getATReg(Inst.
getLoc());
4555 TOut.
emitRRR(Mips::DSUBu, TmpReg, Mips::ZERO, TReg, Inst.
getLoc(), STI);
4556 TOut.
emitRRR(Mips::DROTRV, DReg, SReg, TmpReg, Inst.
getLoc(), STI);
4561 TOut.
emitRRR(Mips::DROTRV, DReg, SReg, TReg, Inst.
getLoc(), STI);
4573 FirstShift = Mips::DSRLV;
4574 SecondShift = Mips::DSLLV;
4577 FirstShift = Mips::DSLLV;
4578 SecondShift = Mips::DSRLV;
4582 ATReg = getATReg(Inst.
getLoc());
4586 TOut.
emitRRR(Mips::DSUBu, ATReg, Mips::ZERO, TReg, Inst.
getLoc(), STI);
4587 TOut.
emitRRR(FirstShift, ATReg, SReg, ATReg, Inst.
getLoc(), STI);
4588 TOut.
emitRRR(SecondShift, DReg, SReg, TReg, Inst.
getLoc(), STI);
4597 bool MipsAsmParser::expandDRotationImm(
MCInst &Inst,
SMLoc IDLoc,
4601 unsigned ATReg = Mips::NoRegister;
4606 unsigned FirstShift = Mips::NOP;
4607 unsigned SecondShift = Mips::NOP;
4611 if (hasMips64r2()) {
4612 unsigned FinalOpcode = Mips::NOP;
4614 FinalOpcode = Mips::DROTR;
4615 else if (ImmValue % 32 == 0)
4616 FinalOpcode = Mips::DROTR32;
4617 else if ((ImmValue >= 1) && (ImmValue <= 32)) {
4619 FinalOpcode = Mips::DROTR32;
4621 FinalOpcode = Mips::DROTR;
4622 }
else if (ImmValue >= 33) {
4624 FinalOpcode = Mips::DROTR;
4626 FinalOpcode = Mips::DROTR32;
4629 uint64_t ShiftValue = ImmValue % 32;
4631 ShiftValue = (32 - ImmValue % 32) % 32;
4633 TOut.
emitRRI(FinalOpcode, DReg, SReg, ShiftValue, Inst.
getLoc(), STI);
4639 if (ImmValue == 0) {
4640 TOut.
emitRRI(Mips::DSRL, DReg, SReg, 0, Inst.
getLoc(), STI);
4648 if ((ImmValue >= 1) && (ImmValue <= 31)) {
4649 FirstShift = Mips::DSLL;
4650 SecondShift = Mips::DSRL32;
4652 if (ImmValue == 32) {
4653 FirstShift = Mips::DSLL32;
4654 SecondShift = Mips::DSRL32;
4656 if ((ImmValue >= 33) && (ImmValue <= 63)) {
4657 FirstShift = Mips::DSLL32;
4658 SecondShift = Mips::DSRL;
4662 if ((ImmValue >= 1) && (ImmValue <= 31)) {
4663 FirstShift = Mips::DSRL;
4664 SecondShift = Mips::DSLL32;
4666 if (ImmValue == 32) {
4667 FirstShift = Mips::DSRL32;
4668 SecondShift = Mips::DSLL32;
4670 if ((ImmValue >= 33) && (ImmValue <= 63)) {
4671 FirstShift = Mips::DSRL32;
4672 SecondShift = Mips::DSLL;
4677 ATReg = getATReg(Inst.
getLoc());
4681 TOut.
emitRRI(FirstShift, ATReg, SReg, ImmValue % 32, Inst.
getLoc(), STI);
4682 TOut.
emitRRI(SecondShift, DReg, SReg, (32 - ImmValue % 32) % 32,
4698 TOut.
emitRI(Mips::BGEZ, SecondRegOp, 8, IDLoc, STI);
4699 if (FirstRegOp != SecondRegOp)
4700 TOut.
emitRRR(Mips::ADDu, FirstRegOp, SecondRegOp, Mips::ZERO, IDLoc, STI);
4711 unsigned ATReg = Mips::NoRegister;
4716 ATReg = getATReg(IDLoc);
4720 loadImmediate(ImmValue, ATReg, Mips::NoRegister,
true,
false, IDLoc, Out,
4724 SrcReg, ATReg, IDLoc, STI);
4734 unsigned ATReg = Mips::NoRegister;
4739 ATReg = getATReg(Inst.
getLoc());
4744 SrcReg, TmpReg, IDLoc, STI);
4749 DstReg, DstReg, 0x1F, IDLoc, STI);
4754 TOut.
emitRRI(Mips::TNE, DstReg, ATReg, 6, IDLoc, STI);
4761 TOut.
emitRRX(Mips::BEQ, DstReg, ATReg, LabelOp, IDLoc, STI);
4762 if (AssemblerOptions.
back()->isReorder())
4764 TOut.
emitII(Mips::BREAK, 6, 0, IDLoc, STI);
4776 unsigned ATReg = Mips::NoRegister;
4781 ATReg = getATReg(IDLoc);
4785 TOut.
emitRR(Inst.
getOpcode() == Mips::MULOUMacro ? Mips::MULTu : Mips::DMULTu,
4786 SrcReg, TmpReg, IDLoc, STI);
4791 TOut.
emitRRI(Mips::TNE, ATReg, Mips::ZERO, 6, IDLoc, STI);
4798 TOut.
emitRRX(Mips::BEQ, ATReg, Mips::ZERO, LabelOp, IDLoc, STI);
4799 if (AssemblerOptions.
back()->isReorder())
4801 TOut.
emitII(Mips::BREAK, 6, 0, IDLoc, STI);
4816 TOut.
emitRR(Mips::DMULTu, SrcReg, TmpReg, IDLoc, STI);
4827 bool MipsAsmParser::expandLoadStoreDMacro(
MCInst &Inst,
SMLoc IDLoc,
4834 warnIfNoMacro(IDLoc);
4837 unsigned Opcode = IsLoad ? Mips::LW : Mips::SW;
4839 unsigned SecondReg =
nextReg(FirstReg);
4844 warnIfRegIndexIsAT(FirstReg, IDLoc);
4847 "Offset for load macro is not immediate!");
4850 signed NextOffset = FirstOffset.
getImm() + 4;
4858 if (FirstReg != BaseReg || !IsLoad) {
4859 TOut.
emitRRX(Opcode, FirstReg, BaseReg, FirstOffset, IDLoc, STI);
4860 TOut.
emitRRX(Opcode, SecondReg, BaseReg, SecondOffset, IDLoc, STI);
4862 TOut.
emitRRX(Opcode, SecondReg, BaseReg, SecondOffset, IDLoc, STI);
4863 TOut.
emitRRX(Opcode, FirstReg, BaseReg, FirstOffset, IDLoc, STI);
4872 warnIfNoMacro(IDLoc);
4897 warnIfNoMacro(IDLoc);
4910 if (Reg == Mips::ZERO) {
4911 Warning(IDLoc,
"comparison is always false");
4912 TOut.
emitRRR(isGP64bit() ? Mips::DADDu : Mips::ADDu,
4917 if (Imm > -0x8000 && Imm < 0) {
4919 Opc = isGP64bit() ? Mips::DADDiu : Mips::ADDiu;
4925 unsigned ATReg = getATReg(IDLoc);
4929 if (loadImmediate(Imm, ATReg, Mips::NoRegister,
true, isGP64bit(), IDLoc,
5006 case Mips::F0:
return Mips::ZERO;
5007 case Mips::F1:
return Mips::AT;
5008 case Mips::F2:
return Mips::V0;
5009 case Mips::F3:
return Mips::V1;
5010 case Mips::F4:
return Mips::A0;
5011 case Mips::F5:
return Mips::A1;
5012 case Mips::F6:
return Mips::A2;
5013 case Mips::F7:
return Mips::A3;
5014 case Mips::F8:
return Mips::T0;
5016 case Mips::F10:
return Mips::T2;
5017 case Mips::F11:
return Mips::T3;
5018 case Mips::F12:
return Mips::T4;
5019 case Mips::F13:
return Mips::T5;
5020 case Mips::F14:
return Mips::T6;
5021 case Mips::F15:
return Mips::T7;
5022 case Mips::F16:
return Mips::S0;
5023 case Mips::F17:
return Mips::S1;
5024 case Mips::F18:
return Mips::S2;
5025 case Mips::F19:
return Mips::S3;
5026 case Mips::F20:
return Mips::S4;
5027 case Mips::F21:
return Mips::S5;
5028 case Mips::F22:
return Mips::S6;
5029 case Mips::F23:
return Mips::S7;
5031 case Mips::F25:
return Mips::T9;
5032 case Mips::F26:
return Mips::K0;
5033 case Mips::F27:
return Mips::K1;
5034 case Mips::F28:
return Mips::GP;
5035 case Mips::F29:
return Mips::SP;
5036 case Mips::F30:
return Mips::FP;
5045 case Mips::COP00:
return Mips::ZERO;
5046 case Mips::COP01:
return Mips::AT;
5047 case Mips::COP02:
return Mips::V0;
5048 case Mips::COP03:
return Mips::V1;
5049 case Mips::COP04:
return Mips::A0;
5050 case Mips::COP05:
return Mips::A1;
5051 case Mips::COP06:
return Mips::A2;
5052 case Mips::COP07:
return Mips::A3;
5053 case Mips::COP08:
return Mips::T0;
5055 case Mips::COP010:
return Mips::T2;
5056 case Mips::COP011:
return Mips::T3;
5057 case Mips::COP012:
return Mips::T4;
5058 case Mips::COP013:
return Mips::T5;
5059 case Mips::COP014:
return Mips::T6;
5060 case Mips::COP015:
return Mips::T7;
5061 case Mips::COP016:
return Mips::S0;
5062 case Mips::COP017:
return Mips::S1;
5063 case Mips::COP018:
return Mips::S2;
5064 case Mips::COP019:
return Mips::S3;
5065 case Mips::COP020:
return Mips::S4;
5066 case Mips::COP021:
return Mips::S5;
5067 case Mips::COP022:
return Mips::S6;
5068 case Mips::COP023:
return Mips::S7;
5069 case Mips::COP024:
return Mips::T8;
5070 case Mips::COP025:
return Mips::T9;
5071 case Mips::COP026:
return Mips::K0;
5072 case Mips::COP027:
return Mips::K1;
5073 case Mips::COP028:
return Mips::GP;
5074 case Mips::COP029:
return Mips::SP;
5075 case Mips::COP030:
return Mips::FP;
5076 case Mips::COP031:
return Mips::RA;
5090 bool IsMFTR =
false;
5148 TOut.
emitRRIII(IsMFTR ? Mips::MFTR : Mips::MTTR, Op0, Op1, u, sel, h, IDLoc,
5154 MipsAsmParser::checkEarlyTargetMatchPredicate(
MCInst &Inst,
5158 return Match_Success;
5161 if (static_cast<MipsOperand &>(*Operands[1])
5162 .isValidForTie(static_cast<MipsOperand &>(*Operands[2])))
5163 return Match_Success;
5164 return Match_RequiresSameSrcAndDst;
5168 unsigned MipsAsmParser::checkTargetMatchPredicate(
MCInst &Inst) {
5175 return Match_RequiresNoZeroRegister;
5176 return Match_Success;
5182 case Mips::JALR_HB64:
5183 case Mips::JALRC_HB_MMR6:
5184 case Mips::JALRC_MMR6:
5186 return Match_RequiresDifferentSrcAndDst;
5187 return Match_Success;
5190 return Match_RequiresDifferentSrcAndDst;
5191 return Match_Success;
5194 return Match_NonZeroOperandForSync;
5195 return Match_Success;
5201 return Match_NonZeroOperandForMTCX;
5202 return Match_Success;
5215 case Mips::BLEZC:
case Mips::BLEZC_MMR6:
5216 case Mips::BGEZC:
case Mips::BGEZC_MMR6:
5217 case Mips::BGTZC:
case Mips::BGTZC_MMR6:
5218 case Mips::BLTZC:
case Mips::BLTZC_MMR6:
5219 case Mips::BEQZC:
case Mips::BEQZC_MMR6:
5220 case Mips::BNEZC:
case Mips::BNEZC_MMR6:
5229 return Match_RequiresNoZeroRegister;
5230 return Match_Success;
5231 case Mips::BGEC:
case Mips::BGEC_MMR6:
5232 case Mips::BLTC:
case Mips::BLTC_MMR6:
5233 case Mips::BGEUC:
case Mips::BGEUC_MMR6:
5234 case Mips::BLTUC:
case Mips::BLTUC_MMR6:
5235 case Mips::BEQC:
case Mips::BEQC_MMR6:
5236 case Mips::BNEC:
case Mips::BNEC_MMR6:
5245 return Match_RequiresNoZeroRegister;
5248 return Match_RequiresNoZeroRegister;
5250 return Match_RequiresDifferentOperands;
5251 return Match_Success;
5254 "Operands must be immediates for dins!");
5257 if ((0 > (Pos + Size)) || ((Pos + Size) > 32))
5258 return Match_RequiresPosSizeRange0_32;
5259 return Match_Success;
5264 "Operands must be immediates for dinsm/dinsu!");
5267 if ((32 >= (Pos + Size)) || ((Pos + Size) > 64))
5268 return Match_RequiresPosSizeRange33_64;
5269 return Match_Success;
5273 "Operands must be immediates for DEXTM!");
5276 if ((1 > (Pos + Size)) || ((Pos + Size) > 63))
5277 return Match_RequiresPosSizeUImm6;
5278 return Match_Success;
5283 "Operands must be immediates for dextm/dextu!");
5286 if ((32 > (Pos + Size)) || ((Pos + Size) > 64))
5287 return Match_RequiresPosSizeRange33_64;
5288 return Match_Success;
5290 case Mips::CRC32B:
case Mips::CRC32CB:
5291 case Mips::CRC32H:
case Mips::CRC32CH:
5292 case Mips::CRC32W:
case Mips::CRC32CW:
5293 case Mips::CRC32D:
case Mips::CRC32CD:
5295 return Match_RequiresSameSrcAndDst;
5296 return Match_Success;
5302 return Match_NoFCCRegisterForCurrentISA;
5304 return Match_Success;
5310 if (ErrorInfo != ~0ULL && ErrorInfo < Operands.
size()) {
5311 SMLoc ErrorLoc = Operands[ErrorInfo]->getStartLoc();
5312 if (ErrorLoc ==
SMLoc())
5319 bool MipsAsmParser::MatchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
5323 bool MatchingInlineAsm) {
5325 unsigned MatchResult =
5326 MatchInstructionImpl(Operands, Inst, ErrorInfo, MatchingInlineAsm);
5328 switch (MatchResult) {
5330 if (processInstruction(Inst, IDLoc, Out, STI))
5333 case Match_MissingFeature:
5334 Error(IDLoc,
"instruction requires a CPU feature not currently enabled");
5336 case Match_InvalidOperand: {
5337 SMLoc ErrorLoc = IDLoc;
5338 if (ErrorInfo != ~0ULL) {
5339 if (ErrorInfo >= Operands.
size())
5340 return Error(IDLoc,
"too few operands for instruction");
5342 ErrorLoc = Operands[ErrorInfo]->getStartLoc();
5343 if (ErrorLoc ==
SMLoc())
5347 return Error(ErrorLoc,
"invalid operand for instruction");
5349 case Match_NonZeroOperandForSync:
5351 "s-type must be zero or unspecified for pre-MIPS32 ISAs");
5352 case Match_NonZeroOperandForMTCX:
5353 return Error(IDLoc,
"selector must be zero for pre-MIPS32 ISAs");
5354 case Match_MnemonicFail:
5355 return Error(IDLoc,
"invalid instruction");
5356 case Match_RequiresDifferentSrcAndDst:
5357 return Error(IDLoc,
"source and destination must be different");
5358 case Match_RequiresDifferentOperands:
5359 return Error(IDLoc,
"registers must be different");
5360 case Match_RequiresNoZeroRegister:
5361 return Error(IDLoc,
"invalid operand ($zero) for instruction");
5362 case Match_RequiresSameSrcAndDst:
5363 return Error(IDLoc,
"source and destination must match");
5364 case Match_NoFCCRegisterForCurrentISA:
5366 "non-zero fcc register doesn't exist in current ISA level");
5371 "expected 1-bit unsigned immediate");
5374 "expected 2-bit unsigned immediate");
5377 "expected immediate in range 1 .. 4");
5380 "expected 3-bit unsigned immediate");
5383 "expected 4-bit unsigned immediate");
5386 "expected 4-bit signed immediate");
5389 "expected 5-bit unsigned immediate");
5392 "expected 5-bit signed immediate");
5395 "expected immediate in range 1 .. 32");
5396 case Match_UImm5_32:
5398 "expected immediate in range 32 .. 63");
5399 case Match_UImm5_33:
5401 "expected immediate in range 33 .. 64");
5402 case Match_UImm5_0_Report_UImm6:
5406 "expected 6-bit unsigned immediate");
5407 case Match_UImm5_Lsl2:
5409 "expected both 7-bit unsigned immediate and multiple of 4");
5410 case Match_UImmRange2_64:
5412 "expected immediate in range 2 .. 64");
5415 "expected 6-bit unsigned immediate");
5416 case Match_UImm6_Lsl2:
5418 "expected both 8-bit unsigned immediate and multiple of 4");
5421 "expected 6-bit signed immediate");
5424 "expected 7-bit unsigned immediate");
5425 case Match_UImm7_N1:
5427 "expected immediate in range -1 .. 126");
5428 case Match_SImm7_Lsl2:
5430 "expected both 9-bit signed immediate and multiple of 4");
5433 "expected 8-bit unsigned immediate");
5434 case Match_UImm10_0:
5436 "expected 10-bit unsigned immediate");
5437 case Match_SImm10_0:
5439 "expected 10-bit signed immediate");
5440 case Match_SImm11_0:
5442 "expected 11-bit signed immediate");
5444 case Match_UImm16_Relaxed:
5445 case Match_UImm16_AltRelaxed:
5447 "expected 16-bit unsigned immediate");
5449 case Match_SImm16_Relaxed:
5451 "expected 16-bit signed immediate");
5452 case Match_SImm19_Lsl2:
5454 "expected both 19-bit signed immediate and multiple of 4");
5455 case Match_UImm20_0:
5457 "expected 20-bit unsigned immediate");
5458 case Match_UImm26_0:
5460 "expected 26-bit unsigned immediate");
5462 case Match_SImm32_Relaxed:
5464 "expected 32-bit signed immediate");
5465 case Match_UImm32_Coerced:
5467 "expected 32-bit immediate");
5468 case Match_MemSImm9:
5470 "expected memory with 9-bit signed offset");
5471 case Match_MemSImm10:
5473 "expected memory with 10-bit signed offset");
5474 case Match_MemSImm10Lsl1:
5476 "expected memory with 11-bit signed offset and multiple of 2");
5477 case Match_MemSImm10Lsl2:
5479 "expected memory with 12-bit signed offset and multiple of 4");
5480 case Match_MemSImm10Lsl3:
5482 "expected memory with 13-bit signed offset and multiple of 8");
5483 case Match_MemSImm11:
5485 "expected memory with 11-bit signed offset");
5486 case Match_MemSImm12:
5488 "expected memory with 12-bit signed offset");
5489 case Match_MemSImm16:
5491 "expected memory with 16-bit signed offset");
5492 case Match_MemSImmPtr:
5494 "expected memory with 32-bit signed offset");
5495 case Match_RequiresPosSizeRange0_32: {
5496 SMLoc ErrorStart = Operands[3]->getStartLoc();
5497 SMLoc ErrorEnd = Operands[4]->getEndLoc();
5498 return Error(ErrorStart,
"size plus position are not in the range 0 .. 32",
5499 SMRange(ErrorStart, ErrorEnd));
5501 case Match_RequiresPosSizeUImm6: {
5502 SMLoc ErrorStart = Operands[3]->getStartLoc();
5503 SMLoc ErrorEnd = Operands[4]->getEndLoc();
5504 return Error(ErrorStart,
"size plus position are not in the range 1 .. 63",
5505 SMRange(ErrorStart, ErrorEnd));
5507 case Match_RequiresPosSizeRange33_64: {
5508 SMLoc ErrorStart = Operands[3]->getStartLoc();
5509 SMLoc ErrorEnd = Operands[4]->getEndLoc();
5510 return Error(ErrorStart,
"size plus position are not in the range 33 .. 64",
5511 SMRange(ErrorStart, ErrorEnd));
5518 void MipsAsmParser::warnIfRegIndexIsAT(
unsigned RegIndex,
SMLoc Loc) {
5519 if (RegIndex != 0 && AssemblerOptions.
back()->getATRegIndex() == RegIndex)
5520 Warning(Loc,
"used $at (currently $" +
Twine(RegIndex) +
5521 ") without \".set noat\"");
5524 void MipsAsmParser::warnIfNoMacro(
SMLoc Loc) {
5525 if (!AssemblerOptions.
back()->isMacro())
5526 Warning(Loc,
"macro instruction expanded into multiple instructions");
5529 void MipsAsmParser::ConvertXWPOperands(
MCInst &Inst,
5533 "Unexpected instruction!");
5534 ((MipsOperand &)*Operands[1]).addGPR32ZeroAsmRegOperands(Inst, 1);
5535 int NextReg =
nextReg(((MipsOperand &)*Operands[1]).getGPR32Reg());
5537 ((MipsOperand &)*Operands[2]).addMemOperands(Inst, 2);
5541 MipsAsmParser::printWarningWithFixIt(
const Twine &Msg,
const Twine &FixMsg,
5542 SMRange Range,
bool ShowColors) {
5544 Range,
SMFixIt(Range, FixMsg),
5553 .
Cases(
"at",
"AT", 1)
5587 if (!(isABI_N32() || isABI_N64()))
5590 if (12 <= CC && CC <= 15) {
5592 AsmToken RegTok = getLexer().peekTok();
5601 assert(FixedName !=
"" &&
"Register name is not one of t4-t7.");
5603 printWarningWithFixIt(
"register names $t4-$t7 are only available in O32.",
5604 "Did you mean $" + FixedName +
"?", RegRange);
5610 if (8 <= CC && CC <= 11)
5626 int MipsAsmParser::matchHWRegsRegisterName(
StringRef Name) {
5630 .Case(
"hwr_cpunum", 0)
5631 .
Case(
"hwr_synci_step", 1)
5633 .
Case(
"hwr_ccres", 3)
5634 .
Case(
"hwr_ulr", 29)
5640 int MipsAsmParser::matchFPURegisterName(
StringRef Name) {
5641 if (Name[0] ==
'f') {
5653 int MipsAsmParser::matchFCCRegisterName(
StringRef Name) {
5666 int MipsAsmParser::matchACRegisterName(
StringRef Name) {
5679 int MipsAsmParser::matchMSA128RegisterName(
StringRef Name) {
5691 int MipsAsmParser::matchMSA128CtrlRegisterName(
StringRef Name) {
5697 .
Case(
"msaaccess", 2)
5699 .
Case(
"msamodify", 4)
5700 .
Case(
"msarequest", 5)
5702 .
Case(
"msaunmap", 7)
5708 bool MipsAsmParser::canUseATReg() {
5709 return AssemblerOptions.
back()->getATRegIndex() != 0;
5712 unsigned MipsAsmParser::getATReg(
SMLoc Loc) {
5713 unsigned ATIndex = AssemblerOptions.
back()->getATRegIndex();
5715 reportParseError(Loc,
5716 "pseudo-instruction requires $at, which is not available");
5720 (isGP64bit()) ? Mips::GPR64RegClassID : Mips::GPR32RegClassID, ATIndex);
5725 return *(getContext().getRegisterInfo()->getRegClass(RC).begin() + RegNo);
5745 switch (getLexer().getKind()) {
5764 MCSymbol *Sym = getContext().getOrCreateSymbol(
"$" + Identifier);
5769 Operands.
push_back(MipsOperand::CreateImm(Res, S, E, *
this));
5777 if (getParser().parseExpression(Expr))
5782 Operands.
push_back(MipsOperand::CreateImm(Expr, S, E, *
this));
5789 bool MipsAsmParser::isEvaluated(
const MCExpr *Expr) {
5797 if (!isEvaluated(BE->
getLHS()))
5799 return isEvaluated(BE->
getRHS());
5802 return isEvaluated(cast<MCUnaryExpr>(Expr)->getSubExpr());
5809 bool MipsAsmParser::ParseRegister(
unsigned &RegNo,
SMLoc &StartLoc,
5815 MipsOperand &Operand =
static_cast<MipsOperand &
>(*Operands.
front());
5816 StartLoc = Operand.getStartLoc();
5817 EndLoc = Operand.getEndLoc();
5823 if (Operand.isGPRAsmReg()) {
5825 RegNo = isGP64bit() ? Operand.getGPR64Reg() : Operand.getGPR32Reg();
5828 return (RegNo == (
unsigned)-1);
5832 return (RegNo == (
unsigned)-1);
5835 bool MipsAsmParser::parseMemOffset(
const MCExpr *&Res,
bool isParenExpr) {
5839 return getParser().parseParenExprOfDepth(0, Res, S);
5840 return getParser().parseExpression(Res);
5847 const MCExpr *IdVal =
nullptr;
5849 bool isParenExpr =
false;
5860 if (parseMemOffset(IdVal, isParenExpr))
5865 MipsOperand &Mnemonic =
static_cast<MipsOperand &
>(*Operands[0]);
5866 if (Mnemonic.getToken() ==
"la" || Mnemonic.getToken() ==
"dla") {
5869 Operands.
push_back(MipsOperand::CreateImm(IdVal, S, E, *
this));
5878 auto Base = MipsOperand::createGPRReg(
5879 0,
"0", getContext().getRegisterInfo(), S, E, *
this);
5881 MipsOperand::CreateMem(std::move(Base), IdVal, S, E, *
this));
5935 if (getParser().parseExpression(NextExpr))
5943 Res = parseAnyRegister(Operands);
5960 std::unique_ptr<MipsOperand>
op(
5961 static_cast<MipsOperand *>(Operands.
back().release()));
5966 if (
const MCBinaryExpr *BE = dyn_cast<MCBinaryExpr>(IdVal)) {
5968 if (IdVal->evaluateAsAbsolute(Imm))
5975 Operands.
push_back(MipsOperand::CreateMem(std::move(op), IdVal, S, E, *
this));
5979 bool MipsAsmParser::searchSymbolAlias(
OperandVector &Operands) {
5993 matchAnyRegisterNameWithoutDollar(Operands, DefSymbol.
substr(1), S);
6007 if (Entry != RegisterSets.
end()) {
6009 matchAnyRegisterWithoutDollar(Operands, Entry->getValue(), S);
6021 MipsAsmParser::matchAnyRegisterNameWithoutDollar(
OperandVector &Operands,
6024 int Index = matchCPURegisterName(Identifier);
6026 Operands.
push_back(MipsOperand::createGPRReg(
6027 Index, Identifier, getContext().getRegisterInfo(), S,
6028 getLexer().getLoc(), *
this));
6032 Index = matchHWRegsRegisterName(Identifier);
6034 Operands.
push_back(MipsOperand::createHWRegsReg(
6035 Index, Identifier, getContext().getRegisterInfo(), S,
6036 getLexer().getLoc(), *
this));
6040 Index = matchFPURegisterName(Identifier);
6042 Operands.
push_back(MipsOperand::createFGRReg(
6043 Index, Identifier, getContext().getRegisterInfo(), S,
6044 getLexer().getLoc(), *
this));
6048 Index = matchFCCRegisterName(Identifier);
6050 Operands.
push_back(MipsOperand::createFCCReg(
6051 Index, Identifier, getContext().getRegisterInfo(), S,
6052 getLexer().getLoc(), *
this));
6056 Index = matchACRegisterName(Identifier);
6058 Operands.
push_back(MipsOperand::createACCReg(
6059 Index, Identifier, getContext().getRegisterInfo(), S,
6060 getLexer().getLoc(), *
this));
6064 Index = matchMSA128RegisterName(Identifier);
6066 Operands.
push_back(MipsOperand::createMSA128Reg(
6067 Index, Identifier, getContext().getRegisterInfo(), S,
6068 getLexer().getLoc(), *
this));
6072 Index = matchMSA128CtrlRegisterName(Identifier);
6074 Operands.
push_back(MipsOperand::createMSACtrlReg(
6075 Index, Identifier, getContext().getRegisterInfo(), S,
6076 getLexer().getLoc(), *
this));
6084 MipsAsmParser::matchAnyRegisterWithoutDollar(
OperandVector &Operands,
6090 matchAnyRegisterNameWithoutDollar(Operands, Identifier, S);
6095 if (RegNum < 0 || RegNum > 31) {
6099 Error(getLexer().getLoc(),
"invalid register number");
6101 Operands.
push_back(MipsOperand::createNumericReg(
6102 RegNum, Token.
getString(), getContext().getRegisterInfo(), S,
6114 auto Token = getLexer().peekTok(
false);
6115 return matchAnyRegisterWithoutDollar(Operands, Token, S);
6123 auto Token = Parser.
getTok();
6130 if (searchSymbolAlias(Operands))
6151 SMLoc S = getLexer().getLoc();
6159 const MCExpr *Expr =
nullptr;
6165 MipsOperand::CreateImm(Expr, S, getLexer().getLoc(), *
this));
6183 if (getParser().parseExpression(IdVal))
6190 Operands.
push_back(MipsOperand::CreateImm(
6200 unsigned PrevReg = Mips::NoRegister;
6201 bool RegRange =
false;
6209 SMLoc E = getLexer().getLoc();
6210 MipsOperand &
Reg =
static_cast<MipsOperand &
>(*TmpOperands.
back());
6211 RegNo = isGP64bit() ? Reg.getGPR64Reg() : Reg.getGPR32Reg();
6215 if ((isGP64bit() && RegNo == Mips::RA_64) ||
6216 (!isGP64bit() && RegNo ==
Mips::RA)) {
6219 unsigned TmpReg = PrevReg + 1;
6220 while (TmpReg <= RegNo) {
6221 if ((((TmpReg < Mips::S0) || (TmpReg > Mips::S7)) && !isGP64bit()) ||
6222 (((TmpReg < Mips::S0_64) || (TmpReg > Mips::S7_64)) &&
6224 Error(E,
"invalid register operand");
6235 if ((PrevReg == Mips::NoRegister) &&
6236 ((isGP64bit() && (RegNo != Mips::S0_64) && (RegNo != Mips::RA_64)) ||
6237 (!isGP64bit() && (RegNo != Mips::S0) && (RegNo !=
Mips::RA)))) {
6238 Error(E,
"$16 or $31 expected");
6240 }
else if (!(((RegNo == Mips::FP || RegNo ==
Mips::RA ||
6241 (RegNo >= Mips::S0 && RegNo <= Mips::S7)) &&
6243 ((RegNo == Mips::FP_64 || RegNo == Mips::RA_64 ||
6244 (RegNo >= Mips::S0_64 && RegNo <= Mips::S7_64)) &&
6246 Error(E,
"invalid register operand");
6248 }
else if ((PrevReg != Mips::NoRegister) && (RegNo != PrevReg + 1) &&
6249 ((RegNo != Mips::FP && RegNo !=
Mips::RA && !isGP64bit()) ||
6250 (RegNo != Mips::FP_64 && RegNo != Mips::RA_64 &&
6252 Error(E,
"consecutive register numbers expected");
6264 Error(E,
"',' or '-' expected");
6276 Operands.
push_back(MipsOperand::CreateRegList(Regs, S, E, *
this));
6277 parseMemOperand(Operands);
6295 MipsOperand *
Reg = &
static_cast<MipsOperand &
>(*TmpOperands.
back());
6296 unsigned RegNo = isGP64bit() ? Reg->getGPR64Reg() : Reg->getGPR32Reg();
6301 Error(E,
"',' expected");
6311 Reg = &
static_cast<MipsOperand &
>(*TmpOperands.
back());
6312 RegNo = isGP64bit() ? Reg->getGPR64Reg() : Reg->getGPR32Reg();
6315 Operands.
push_back(MipsOperand::CreateRegList(Regs, S, E, *
this));
6329 MipsOperand::CreateToken(
"(", getLexer().getLoc(), *
this));
6331 if (parseOperand(Operands, Name)) {
6332 SMLoc Loc = getLexer().getLoc();
6333 return Error(Loc,
"unexpected token in argument list");
6336 SMLoc Loc = getLexer().getLoc();
6337 return Error(Loc,
"unexpected token, expected ')'");
6340 MipsOperand::CreateToken(
")", getLexer().getLoc(), *
this));
6352 bool MipsAsmParser::parseBracketSuffix(
StringRef Name,
6357 MipsOperand::CreateToken(
"[", getLexer().getLoc(), *
this));
6359 if (parseOperand(Operands, Name)) {
6360 SMLoc Loc = getLexer().getLoc();
6361 return Error(Loc,
"unexpected token in argument list");
6364 SMLoc Loc = getLexer().getLoc();
6365 return Error(Loc,
"unexpected token, expected ']'");
6368 MipsOperand::CreateToken(
"]", getLexer().getLoc(), *
this));
6380 getTargetStreamer().forbidModuleDirective();
6383 if (!mnemonicIsValid(Name, 0)) {
6384 return Error(NameLoc,
"unknown instruction");
6387 Operands.
push_back(MipsOperand::CreateToken(Name, NameLoc, *
this));
6392 if (parseOperand(Operands, Name)) {
6393 SMLoc Loc = getLexer().getLoc();
6394 return Error(Loc,
"unexpected token in argument list");
6396 if (getLexer().is(
AsmToken::LBrac) && parseBracketSuffix(Name, Operands))
6403 if (parseOperand(Operands, Name)) {
6404 SMLoc Loc = getLexer().getLoc();
6405 return Error(Loc,
"unexpected token in argument list");
6409 if (parseBracketSuffix(Name, Operands))
6412 parseParenSuffix(Name, Operands))
6417 SMLoc Loc = getLexer().getLoc();
6418 return Error(Loc,
"unexpected token in argument list");
6426 bool MipsAsmParser::reportParseError(
Twine ErrorMsg) {
6427 SMLoc Loc = getLexer().getLoc();
6428 return Error(Loc, ErrorMsg);
6431 bool MipsAsmParser::reportParseError(
SMLoc Loc,
Twine ErrorMsg) {
6432 return Error(Loc, ErrorMsg);
6435 bool MipsAsmParser::parseSetNoAtDirective() {
6440 AssemblerOptions.
back()->setATRegIndex(0);
6446 reportParseError(
"unexpected token, expected end of statement");
6450 getTargetStreamer().emitDirectiveSetNoAt();
6455 bool MipsAsmParser::parseSetAtDirective() {
6463 AssemblerOptions.
back()->setATRegIndex(1);
6465 getTargetStreamer().emitDirectiveSetAt();
6471 reportParseError(
"unexpected token, expected equals sign");
6478 reportParseError(
"no register specified");
6481 reportParseError(
"unexpected token, expected dollar sign '$'");
6495 reportParseError(
"unexpected token, expected identifier or integer");
6500 if (!AssemblerOptions.
back()->setATRegIndex(AtRegNo)) {
6501 reportParseError(
"invalid register");
6508 reportParseError(
"unexpected token, expected end of statement");
6512 getTargetStreamer().emitDirectiveSetAtWithArg(AtRegNo);
6518 bool MipsAsmParser::parseSetReorderDirective() {
6523 reportParseError(
"unexpected token, expected end of statement");
6526 AssemblerOptions.
back()->setReorder();
6527 getTargetStreamer().emitDirectiveSetReorder();
6532 bool MipsAsmParser::parseSetNoReorderDirective() {
6537 reportParseError(
"unexpected token, expected end of statement");
6540 AssemblerOptions.
back()->setNoReorder();
6541 getTargetStreamer().emitDirectiveSetNoReorder();
6546 bool MipsAsmParser::parseSetMacroDirective() {
6551 reportParseError(
"unexpected token, expected end of statement");
6554 AssemblerOptions.
back()->setMacro();
6555 getTargetStreamer().emitDirectiveSetMacro();
6560 bool MipsAsmParser::parseSetNoMacroDirective() {
6565 reportParseError(
"unexpected token, expected end of statement");
6568 if (AssemblerOptions.
back()->isReorder()) {
6569 reportParseError(
"`noreorder' must be set before `nomacro'");
6572 AssemblerOptions.
back()->setNoMacro();
6573 getTargetStreamer().emitDirectiveSetNoMacro();
6578 bool MipsAsmParser::parseSetMsaDirective() {
6584 return reportParseError(
"unexpected token, expected end of statement");
6586 setFeatureBits(Mips::FeatureMSA,
"msa");
6587 getTargetStreamer().emitDirectiveSetMsa();
6591 bool MipsAsmParser::parseSetNoMsaDirective() {
6597 return reportParseError(
"unexpected token, expected end of statement");
6599 clearFeatureBits(Mips::FeatureMSA,
"msa");
6600 getTargetStreamer().emitDirectiveSetNoMsa();
6604 bool MipsAsmParser::parseSetNoDspDirective() {
6610 reportParseError(
"unexpected token, expected end of statement");
6614 clearFeatureBits(Mips::FeatureDSP,
"dsp");
6615 getTargetStreamer().emitDirectiveSetNoDsp();
6619 bool MipsAsmParser::parseSetMips16Directive() {
6625 reportParseError(
"unexpected token, expected end of statement");
6629 setFeatureBits(Mips::FeatureMips16,
"mips16");
6630 getTargetStreamer().emitDirectiveSetMips16();
6635 bool MipsAsmParser::parseSetNoMips16Directive() {
6641 reportParseError(
"unexpected token, expected end of statement");
6645 clearFeatureBits(Mips::FeatureMips16,
"mips16");
6646 getTargetStreamer().emitDirectiveSetNoMips16();
6651 bool MipsAsmParser::parseSetFpDirective() {
6660 reportParseError(
"unexpected token, expected equals sign '='");
6666 if (!parseFpABIValue(FpAbiVal,
".set"))
6670 reportParseError(
"unexpected token, expected end of statement");
6673 getTargetStreamer().emitDirectiveSetFp(FpAbiVal);
6678 bool MipsAsmParser::parseSetOddSPRegDirective() {
6683 reportParseError(
"unexpected token, expected end of statement");
6687 clearFeatureBits(Mips::FeatureNoOddSPReg,
"nooddspreg");
6688 getTargetStreamer().emitDirectiveSetOddSPReg();
6692 bool MipsAsmParser::parseSetNoOddSPRegDirective() {
6697 reportParseError(
"unexpected token, expected end of statement");
6701 setFeatureBits(Mips::FeatureNoOddSPReg,
"nooddspreg");
6702 getTargetStreamer().emitDirectiveSetNoOddSPReg();
6706 bool MipsAsmParser::parseSetMtDirective() {
6712 reportParseError(
"unexpected token, expected end of statement");
6716 setFeatureBits(Mips::FeatureMT,
"mt");
6717 getTargetStreamer().emitDirectiveSetMt();
6722 bool MipsAsmParser::parseSetNoMtDirective() {
6728 reportParseError(
"unexpected token, expected end of statement");
6732 clearFeatureBits(Mips::FeatureMT,
"mt");
6734 getTargetStreamer().emitDirectiveSetNoMt();
6739 bool MipsAsmParser::parseSetNoCRCDirective() {
6745 reportParseError(
"unexpected token, expected end of statement");
6749 clearFeatureBits(Mips::FeatureCRC,
"crc");
6751 getTargetStreamer().emitDirectiveSetNoCRC();
6756 bool MipsAsmParser::parseSetNoVirtDirective() {
6762 reportParseError(
"unexpected token, expected end of statement");
6766 clearFeatureBits(Mips::FeatureVirt,
"virt");
6768 getTargetStreamer().emitDirectiveSetNoVirt();
6773 bool MipsAsmParser::parseSetNoGINVDirective() {
6779 reportParseError(
"unexpected token, expected end of statement");
6783 clearFeatureBits(Mips::FeatureGINV,
"ginv");
6785 getTargetStreamer().emitDirectiveSetNoGINV();
6790 bool MipsAsmParser::parseSetPopDirective() {
6792 SMLoc Loc = getLexer().getLoc();
6796 return reportParseError(
"unexpected token, expected end of statement");
6800 if (AssemblerOptions.
size() == 2)
6801 return reportParseError(Loc,
".set pop with no .set push");
6805 setAvailableFeatures(
6806 ComputeAvailableFeatures(AssemblerOptions.
back()->getFeatures()));
6809 getTargetStreamer().emitDirectiveSetPop();
6813 bool MipsAsmParser::parseSetPushDirective() {
6817 return reportParseError(
"unexpected token, expected end of statement");
6821 llvm::make_unique<MipsAssemblerOptions>(AssemblerOptions.
back().get()));
6823 getTargetStreamer().emitDirectiveSetPush();
6827 bool MipsAsmParser::parseSetSoftFloatDirective() {
6831 return reportParseError(
"unexpected token, expected end of statement");
6833 setFeatureBits(Mips::FeatureSoftFloat,
"soft-float");
6834 getTargetStreamer().emitDirectiveSetSoftFloat();
6838 bool MipsAsmParser::parseSetHardFloatDirective() {
6842 return reportParseError(
"unexpected token, expected end of statement");
6844 clearFeatureBits(Mips::FeatureSoftFloat,
"soft-float");
6845 getTargetStreamer().emitDirectiveSetHardFloat();
6849 bool MipsAsmParser::parseSetAssignment() {
6855 return reportParseError(
"expected identifier after .set");
6858 return reportParseError(
"unexpected token, expected comma");
6868 getContext().getOrCreateSymbol(Name);
6874 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
6877 return reportParseError(
"expected valid expression after comma");
6883 bool MipsAsmParser::parseSetMips0Directive() {
6887 return reportParseError(
"unexpected token, expected end of statement");
6891 setAvailableFeatures(
6892 ComputeAvailableFeatures(AssemblerOptions.
front()->getFeatures()));
6894 AssemblerOptions.
back()->setFeatures(AssemblerOptions.
front()->getFeatures());
6896 getTargetStreamer().emitDirectiveSetMips0();
6900 bool MipsAsmParser::parseSetArchDirective() {
6904 return reportParseError(
"unexpected token, expected equals sign");
6909 return reportParseError(
"expected arch identifier");
6913 .Case(
"mips1",
"mips1")
6914 .
Case(
"mips2",
"mips2")
6915 .
Case(
"mips3",
"mips3")
6916 .
Case(
"mips4",
"mips4")
6917 .
Case(
"mips5",
"mips5")
6918 .
Case(
"mips32",
"mips32")
6919 .
Case(
"mips32r2",
"mips32r2")
6920 .
Case(
"mips32r3",
"mips32r3")
6921 .
Case(
"mips32r5",
"mips32r5")
6922 .
Case(
"mips32r6",
"mips32r6")
6923 .
Case(
"mips64",
"mips64")
6924 .
Case(
"mips64r2",
"mips64r2")
6925 .
Case(
"mips64r3",
"mips64r3")
6926 .
Case(
"mips64r5",
"mips64r5")
6927 .
Case(
"mips64r6",
"mips64r6")
6928 .
Case(
"octeon",
"cnmips")
6929 .
Case(
"r4000",
"mips3")
6932 if (ArchFeatureName.
empty())
6933 return reportParseError(
"unsupported architecture");
6935 if (ArchFeatureName ==
"mips64r6" && inMicroMipsMode())
6936 return reportParseError(
"mips64r6 does not support microMIPS");
6938 selectArch(ArchFeatureName);
6939 getTargetStreamer().emitDirectiveSetArch(Arch);
6943 bool MipsAsmParser::parseSetFeature(uint64_t Feature) {
6947 return reportParseError(
"unexpected token, expected end of statement");
6952 case Mips::FeatureDSP:
6953 setFeatureBits(Mips::FeatureDSP,
"dsp");
6954 getTargetStreamer().emitDirectiveSetDsp();
6956 case Mips::FeatureDSPR2:
6957 setFeatureBits(Mips::FeatureDSPR2,
"dspr2");
6958 getTargetStreamer().emitDirectiveSetDspr2();
6960 case Mips::FeatureMicroMips:
6961 setFeatureBits(Mips::FeatureMicroMips,
"micromips");
6962 getTargetStreamer().emitDirectiveSetMicroMips();
6964 case Mips::FeatureMips1:
6965 selectArch(
"mips1");
6966 getTargetStreamer().emitDirectiveSetMips1();
6968 case Mips::FeatureMips2:
6969 selectArch(
"mips2");
6970 getTargetStreamer().emitDirectiveSetMips2();
6972 case Mips::FeatureMips3:
6973 selectArch(
"mips3");
6974 getTargetStreamer().emitDirectiveSetMips3();
6976 case Mips::FeatureMips4:
6977 selectArch(
"mips4");
6978 getTargetStreamer().emitDirectiveSetMips4();
6980 case Mips::FeatureMips5:
6981 selectArch(
"mips5");
6982 getTargetStreamer().emitDirectiveSetMips5();
6984 case Mips::FeatureMips32:
6985 selectArch(
"mips32");
6986 getTargetStreamer().emitDirectiveSetMips32();
6988 case Mips::FeatureMips32r2:
6989 selectArch(
"mips32r2");
6990 getTargetStreamer().emitDirectiveSetMips32R2();
6992 case Mips::FeatureMips32r3:
6993 selectArch(
"mips32r3");
6994 getTargetStreamer().emitDirectiveSetMips32R3();
6996 case Mips::FeatureMips32r5:
6997 selectArch(
"mips32r5");
6998 getTargetStreamer().emitDirectiveSetMips32R5();
7000 case Mips::FeatureMips32r6:
7001 selectArch(
"mips32r6");
7002 getTargetStreamer().emitDirectiveSetMips32R6();
7004 case Mips::FeatureMips64:
7005 selectArch(
"mips64");
7006 getTargetStreamer().emitDirectiveSetMips64();
7008 case Mips::FeatureMips64r2:
7009 selectArch(
"mips64r2");
7010 getTargetStreamer().emitDirectiveSetMips64R2();
7012 case Mips::FeatureMips64r3:
7013 selectArch(
"mips64r3");
7014 getTargetStreamer().emitDirectiveSetMips64R3();
7016 case Mips::FeatureMips64r5:
7017 selectArch(
"mips64r5");
7018 getTargetStreamer().emitDirectiveSetMips64R5();
7020 case Mips::FeatureMips64r6:
7021 selectArch(
"mips64r6");
7022 getTargetStreamer().emitDirectiveSetMips64R6();
7024 case Mips::FeatureCRC:
7025 setFeatureBits(Mips::FeatureCRC,
"crc");
7026 getTargetStreamer().emitDirectiveSetCRC();
7028 case Mips::FeatureVirt:
7029 setFeatureBits(Mips::FeatureVirt,
"virt");
7030 getTargetStreamer().emitDirectiveSetVirt();
7032 case Mips::FeatureGINV:
7033 setFeatureBits(Mips::FeatureGINV,
"ginv");
7034 getTargetStreamer().emitDirectiveSetGINV();
7040 bool MipsAsmParser::eatComma(
StringRef ErrorStr) {
7043 SMLoc Loc = getLexer().getLoc();
7044 return Error(Loc, ErrorStr);
7055 bool MipsAsmParser::isPicAndNotNxxAbi() {
7056 return inPicMode() && !(isABI_N32() || isABI_N64());
7059 bool MipsAsmParser::parseDirectiveCpLoad(
SMLoc Loc) {
7060 if (AssemblerOptions.
back()->isReorder())
7061 Warning(Loc,
".cpload should be inside a noreorder section");
7063 if (inMips16Mode()) {
7064 reportParseError(
".cpload is not supported in Mips16 mode");
7071 reportParseError(
"expected register containing function address");
7075 MipsOperand &RegOpnd =
static_cast<MipsOperand &
>(*Reg[0]);
7076 if (!RegOpnd.isGPRAsmReg()) {
7077 reportParseError(RegOpnd.getStartLoc(),
"invalid register");
7083 reportParseError(
"unexpected token, expected end of statement");
7087 getTargetStreamer().emitDirectiveCpLoad(RegOpnd.getGPR32Reg());
7091 bool MipsAsmParser::parseDirectiveCpRestore(
SMLoc Loc) {
7097 if (inMips16Mode()) {
7098 reportParseError(
".cprestore is not supported in Mips16 mode");
7103 const MCExpr *StackOffset;
7104 int64_t StackOffsetVal;
7106 reportParseError(
"expected stack offset value");
7110 if (!StackOffset->evaluateAsAbsolute(StackOffsetVal)) {
7111 reportParseError(
"stack offset is not an absolute expression");
7115 if (StackOffsetVal < 0) {
7116 Warning(Loc,
".cprestore with negative stack offset has no effect");
7117 IsCpRestoreSet =
false;
7119 IsCpRestoreSet =
true;
7120 CpRestoreOffset = StackOffsetVal;
7125 reportParseError(
"unexpected token, expected end of statement");
7129 if (!getTargetStreamer().emitDirectiveCpRestore(
7130 CpRestoreOffset, [&]() {
return getATReg(Loc); }, Loc, STI))
7136 bool MipsAsmParser::parseDirectiveCPSetup() {
7140 bool SaveIsReg =
true;
7145 reportParseError(
"expected register containing function address");
7149 MipsOperand &FuncRegOpnd =
static_cast<MipsOperand &
>(*TmpReg[0]);
7150 if (!FuncRegOpnd.isGPRAsmReg()) {
7151 reportParseError(FuncRegOpnd.getStartLoc(),
"invalid register");
7155 FuncReg = FuncRegOpnd.getGPR32Reg();
7158 if (!eatComma(
"unexpected token, expected comma"))
7161 ResTy = parseAnyRegister(TmpReg);
7163 const MCExpr *OffsetExpr;
7165 SMLoc ExprLoc = getLexer().getLoc();
7168 !OffsetExpr->evaluateAsAbsolute(OffsetVal)) {
7169 reportParseError(ExprLoc,
"expected save register or stack offset");
7176 MipsOperand &SaveOpnd =
static_cast<MipsOperand &
>(*TmpReg[0]);
7177 if (!SaveOpnd.isGPRAsmReg()) {
7178 reportParseError(SaveOpnd.getStartLoc(),
"invalid register");
7181 Save = SaveOpnd.getGPR32Reg();
7184 if (!eatComma(
"unexpected token, expected comma"))
7189 reportParseError(
"expected expression");
7194 reportParseError(
"expected symbol");
7199 CpSaveLocation = Save;
7200 CpSaveLocationIsRegister = SaveIsReg;
7202 getTargetStreamer().emitDirectiveCpsetup(FuncReg, Save, Ref->
getSymbol(),
7207 bool MipsAsmParser::parseDirectiveCPReturn() {
7208 getTargetStreamer().emitDirectiveCpreturn(CpSaveLocation,
7209 CpSaveLocationIsRegister);
7213 bool MipsAsmParser::parseDirectiveNaN() {
7220 getTargetStreamer().emitDirectiveNaN2008();
7222 }
else if (Tok.
getString() ==
"legacy") {
7224 getTargetStreamer().emitDirectiveNaNLegacy();
7230 reportParseError(
"invalid option in .nan directive");
7234 bool MipsAsmParser::parseDirectiveSet() {
7235 const AsmToken &Tok = getParser().getTok();
7239 if (IdVal ==
"noat")
7240 return parseSetNoAtDirective();
7242 return parseSetAtDirective();
7243 if (IdVal ==
"arch")
7244 return parseSetArchDirective();
7245 if (IdVal ==
"bopt") {
7246 Warning(Loc,
"'bopt' feature is unsupported");
7250 if (IdVal ==
"nobopt") {
7256 return parseSetFpDirective();
7257 if (IdVal ==
"oddspreg")
7258 return parseSetOddSPRegDirective();
7259 if (IdVal ==
"nooddspreg")
7260 return parseSetNoOddSPRegDirective();
7262 return parseSetPopDirective();
7263 if (IdVal ==
"push")
7264 return parseSetPushDirective();
7265 if (IdVal ==
"reorder")
7266 return parseSetReorderDirective();
7267 if (IdVal ==
"noreorder")
7268 return parseSetNoReorderDirective();
7269 if (IdVal ==
"macro")
7270 return parseSetMacroDirective();
7271 if (IdVal ==
"nomacro")
7272 return parseSetNoMacroDirective();
7273 if (IdVal ==
"mips16")
7274 return parseSetMips16Directive();
7275 if (IdVal ==
"nomips16")
7276 return parseSetNoMips16Directive();
7277 if (IdVal ==
"nomicromips") {
7278 clearFeatureBits(Mips::FeatureMicroMips,
"micromips");
7279 getTargetStreamer().emitDirectiveSetNoMicroMips();
7280 getParser().eatToEndOfStatement();
7283 if (IdVal ==
"micromips") {
7284 if (hasMips64r6()) {
7285 Error(Loc,
".set micromips directive is not supported with MIPS64R6");
7288 return parseSetFeature(Mips::FeatureMicroMips);
7290 if (IdVal ==
"mips0")
7291 return parseSetMips0Directive();
7292 if (IdVal ==
"mips1")
7293 return parseSetFeature(Mips::FeatureMips1);
7294 if (IdVal ==
"mips2")
7295 return parseSetFeature(Mips::FeatureMips2);
7296 if (IdVal ==
"mips3")
7297 return parseSetFeature(Mips::FeatureMips3);
7298 if (IdVal ==
"mips4")
7299 return parseSetFeature(Mips::FeatureMips4);
7300 if (IdVal ==
"mips5")
7301 return parseSetFeature(Mips::FeatureMips5);
7302 if (IdVal ==
"mips32")
7303 return parseSetFeature(Mips::FeatureMips32);
7304 if (IdVal ==
"mips32r2")
7305 return parseSetFeature(Mips::FeatureMips32r2);
7306 if (IdVal ==
"mips32r3")
7307 return parseSetFeature(Mips::FeatureMips32r3);
7308 if (IdVal ==
"mips32r5")
7309 return parseSetFeature(Mips::FeatureMips32r5);
7310 if (IdVal ==
"mips32r6")
7311 return parseSetFeature(Mips::FeatureMips32r6);
7312 if (IdVal ==
"mips64")
7313 return parseSetFeature(Mips::FeatureMips64);
7314 if (IdVal ==
"mips64r2")
7315 return parseSetFeature(Mips::FeatureMips64r2);
7316 if (IdVal ==
"mips64r3")
7317 return parseSetFeature(Mips::FeatureMips64r3);
7318 if (IdVal ==
"mips64r5")
7319 return parseSetFeature(Mips::FeatureMips64r5);
7320 if (IdVal ==
"mips64r6") {
7321 if (inMicroMipsMode()) {
7322 Error(Loc,
"MIPS64R6 is not supported with microMIPS");
7325 return parseSetFeature(Mips::FeatureMips64r6);
7328 return parseSetFeature(Mips::FeatureDSP);
7329 if (IdVal ==
"dspr2")
7330 return parseSetFeature(Mips::FeatureDSPR2);
7331 if (IdVal ==
"nodsp")
7332 return parseSetNoDspDirective();
7334 return parseSetMsaDirective();
7335 if (IdVal ==
"nomsa")
7336 return parseSetNoMsaDirective();
7338 return parseSetMtDirective();
7339 if (IdVal ==
"nomt")
7340 return parseSetNoMtDirective();
7341 if (IdVal ==
"softfloat")
7342 return parseSetSoftFloatDirective();
7343 if (IdVal ==
"hardfloat")
7344 return parseSetHardFloatDirective();
7346 return parseSetFeature(Mips::FeatureCRC);
7347 if (IdVal ==
"nocrc")
7348 return parseSetNoCRCDirective();
7349 if (IdVal ==
"virt")
7350 return parseSetFeature(Mips::FeatureVirt);
7351 if (IdVal ==
"novirt")
7352 return parseSetNoVirtDirective();
7353 if (IdVal ==
"ginv")
7354 return parseSetFeature(Mips::FeatureGINV);
7355 if (IdVal ==
"noginv")
7356 return parseSetNoGINVDirective();
7359 return parseSetAssignment();
7364 bool MipsAsmParser::parseDirectiveGpWord() {
7369 if (getParser().parseExpression(Value))
7371 getParser().getStreamer().EmitGPRel32Value(Value);
7374 return Error(getLexer().getLoc(),
7375 "unexpected token, expected end of statement");
7382 bool MipsAsmParser::parseDirectiveGpDWord() {
7387 if (getParser().parseExpression(Value))
7389 getParser().getStreamer().EmitGPRel64Value(Value);
7392 return Error(getLexer().getLoc(),
7393 "unexpected token, expected end of statement");
7400 bool MipsAsmParser::parseDirectiveDtpRelWord() {
7405 if (getParser().parseExpression(Value))
7407 getParser().getStreamer().EmitDTPRel32Value(Value);
7410 return Error(getLexer().getLoc(),
7411 "unexpected token, expected end of statement");
7418 bool MipsAsmParser::parseDirectiveDtpRelDWord() {
7423 if (getParser().parseExpression(Value))
7425 getParser().getStreamer().EmitDTPRel64Value(Value);
7428 return Error(getLexer().getLoc(),
7429 "unexpected token, expected end of statement");
7436 bool MipsAsmParser::parseDirectiveTpRelWord() {
7441 if (getParser().parseExpression(Value))
7443 getParser().getStreamer().EmitTPRel32Value(Value);
7446 return Error(getLexer().getLoc(),
7447 "unexpected token, expected end of statement");
7454 bool MipsAsmParser::parseDirectiveTpRelDWord() {
7459 if (getParser().parseExpression(Value))
7461 getParser().getStreamer().EmitTPRel64Value(Value);
7464 return Error(getLexer().getLoc(),
7465 "unexpected token, expected end of statement");
7470 bool MipsAsmParser::parseDirectiveOption() {
7477 "unexpected token, expected identifier");
7482 if (Option ==
"pic0") {
7484 IsPicEnabled =
false;
7486 getTargetStreamer().emitDirectiveOptionPic0();
7490 "unexpected token, expected end of statement");
7495 if (Option ==
"pic2") {
7497 IsPicEnabled =
true;
7499 getTargetStreamer().emitDirectiveOptionPic2();
7503 "unexpected token, expected end of statement");
7510 "unknown option, expected 'pic0' or 'pic2'");
7517 bool MipsAsmParser::parseInsnDirective() {
7520 reportParseError(
"unexpected token, expected end of statement");
7526 getTargetStreamer().emitDirectiveInsn();
7537 reportParseError(
"unexpected token, expected end of statement");
7541 MCSection *ELFSection = getContext().getELFSection(
7543 getParser().getStreamer().SwitchSection(ELFSection);
7552 bool MipsAsmParser::parseSSectionDirective(
StringRef Section,
unsigned Type) {
7555 reportParseError(
"unexpected token, expected end of statement");
7559 MCSection *ELFSection = getContext().getELFSection(
7561 getParser().getStreamer().SwitchSection(ELFSection);
7580 bool MipsAsmParser::parseDirectiveModule() {
7585 if (!getTargetStreamer().isModuleDirectiveAllowed()) {
7587 reportParseError(
".module directive must appear before any code");
7593 reportParseError(
"expected .module option identifier");
7597 if (Option ==
"oddspreg") {
7598 clearModuleFeatureBits(Mips::FeatureNoOddSPReg,
"nooddspreg");
7602 getTargetStreamer().updateABIInfo(*
this);
7607 getTargetStreamer().emitDirectiveModuleOddSPReg();
7611 reportParseError(
"unexpected token, expected end of statement");
7616 }
else if (Option ==
"nooddspreg") {
7618 return Error(L,
"'.module nooddspreg' requires the O32 ABI");
7621 setModuleFeatureBits(Mips::FeatureNoOddSPReg,
"nooddspreg");
7625 getTargetStreamer().updateABIInfo(*
this);
7630 getTargetStreamer().emitDirectiveModuleOddSPReg();
7634 reportParseError(
"unexpected token, expected end of statement");
7639 }
else if (Option ==
"fp") {
7640 return parseDirectiveModuleFP();
7641 }
else if (Option ==
"softfloat") {
7642 setModuleFeatureBits(Mips::FeatureSoftFloat,
"soft-float");
7646 getTargetStreamer().updateABIInfo(*
this);
7651 getTargetStreamer().emitDirectiveModuleSoftFloat();
7655 reportParseError(
"unexpected token, expected end of statement");
7660 }
else if (Option ==
"hardfloat") {
7661 clearModuleFeatureBits(Mips::FeatureSoftFloat,
"soft-float");
7665 getTargetStreamer().updateABIInfo(*
this);
7670 getTargetStreamer().emitDirectiveModuleHardFloat();
7674 reportParseError(
"unexpected token, expected end of statement");
7679 }
else if (Option ==
"mt") {
7680 setModuleFeatureBits(Mips::FeatureMT,
"mt");
7684 getTargetStreamer().updateABIInfo(*
this);
7689 getTargetStreamer().emitDirectiveModuleMT();
7693 reportParseError(
"unexpected token, expected end of statement");
7698 }
else if (Option ==
"crc") {
7699 setModuleFeatureBits(Mips::FeatureCRC,
"crc");
7703 getTargetStreamer().updateABIInfo(*
this);
7708 getTargetStreamer().emitDirectiveModuleCRC();
7712 reportParseError(
"unexpected token, expected end of statement");
7717 }
else if (Option ==
"nocrc") {
7718 clearModuleFeatureBits(Mips::FeatureCRC,
"crc");
7722 getTargetStreamer().updateABIInfo(*
this);
7727 getTargetStreamer().emitDirectiveModuleNoCRC();
7731 reportParseError(
"unexpected token, expected end of statement");
7736 }
else if (Option ==
"virt") {
7737 setModuleFeatureBits(Mips::FeatureVirt,
"virt");
7741 getTargetStreamer().updateABIInfo(*
this);
7746 getTargetStreamer().emitDirectiveModuleVirt();
7750 reportParseError(
"unexpected token, expected end of statement");
7755 }
else if (Option ==
"novirt") {
7756 clearModuleFeatureBits(Mips::FeatureVirt,
"virt");
7760 getTargetStreamer().updateABIInfo(*
this);
7765 getTargetStreamer().emitDirectiveModuleNoVirt();
7769 reportParseError(
"unexpected token, expected end of statement");
7774 }
else if (Option ==
"ginv") {
7775 setModuleFeatureBits(Mips::FeatureGINV,
"ginv");
7779 getTargetStreamer().updateABIInfo(*
this);
7784 getTargetStreamer().emitDirectiveModuleGINV();
7788 reportParseError(
"unexpected token, expected end of statement");
7793 }
else if (Option ==
"noginv") {
7794 clearModuleFeatureBits(Mips::FeatureGINV,
"ginv");
7798 getTargetStreamer().updateABIInfo(*
this);
7803 getTargetStreamer().emitDirectiveModuleNoGINV();
7807 reportParseError(
"unexpected token, expected end of statement");
7813 return Error(L,
"'" +
Twine(Option) +
"' is not a valid .module option.");
7821 bool MipsAsmParser::parseDirectiveModuleFP() {
7826 reportParseError(
"unexpected token, expected equals sign '='");
7832 if (!parseFpABIValue(FpABI,
".module"))
7836 reportParseError(
"unexpected token, expected end of statement");
7842 getTargetStreamer().updateABIInfo(*
this);
7847 getTargetStreamer().emitDirectiveModuleFP();
7857 bool ModuleLevelOptions = Directive ==
".module";
7863 if (Value !=
"xx") {
7864 reportParseError(
"unsupported value, expected 'xx', '32' or '64'");
7869 reportParseError(
"'" + Directive +
" fp=xx' requires the O32 ABI");
7874 if (ModuleLevelOptions) {
7875 setModuleFeatureBits(Mips::FeatureFPXX,
"fpxx");
7876 clearModuleFeatureBits(Mips::FeatureFP64Bit,
"fp64");
7878 setFeatureBits(Mips::FeatureFPXX,
"fpxx");
7879 clearFeatureBits(Mips::FeatureFP64Bit,
"fp64");
7888 if (Value != 32 && Value != 64) {
7889 reportParseError(
"unsupported value, expected 'xx', '32' or '64'");
7895 reportParseError(
"'" + Directive +
" fp=32' requires the O32 ABI");
7900 if (ModuleLevelOptions) {
7901 clearModuleFeatureBits(Mips::FeatureFPXX,
"fpxx");
7902 clearModuleFeatureBits(Mips::FeatureFP64Bit,
"fp64");
7904 clearFeatureBits(Mips::FeatureFPXX,
"fpxx");
7905 clearFeatureBits(Mips::FeatureFP64Bit,
"fp64");
7909 if (ModuleLevelOptions) {
7910 clearModuleFeatureBits(Mips::FeatureFPXX,
"fpxx");
7911 setModuleFeatureBits(Mips::FeatureFP64Bit,
"fp64");
7913 clearFeatureBits(Mips::FeatureFPXX,
"fpxx");
7914 setFeatureBits(Mips::FeatureFP64Bit,
"fp64");
7924 bool MipsAsmParser::ParseDirective(
AsmToken DirectiveID) {
7933 if (IDVal ==
".cpload") {
7934 parseDirectiveCpLoad(DirectiveID.
getLoc());
7937 if (IDVal ==
".cprestore") {
7938 parseDirectiveCpRestore(DirectiveID.
getLoc());
7941 if (IDVal ==
".ent") {
7945 reportParseError(
"expected identifier after .ent");
7959 reportParseError(
"unexpected token, expected end of statement");
7963 const MCExpr *DummyNumber;
7964 int64_t DummyNumberVal;
7968 reportParseError(
"expected number after comma");
7971 if (!DummyNumber->evaluateAsAbsolute(DummyNumberVal)) {
7972 reportParseError(
"expected an absolute expression after comma");
7979 reportParseError(
"unexpected token, expected end of statement");
7983 MCSymbol *Sym = getContext().getOrCreateSymbol(SymbolName);
7985 getTargetStreamer().emitDirectiveEnt(*Sym);
7987 IsCpRestoreSet =
false;
7991 if (IDVal ==
".end") {
7995 reportParseError(
"expected identifier after .end");
8000 reportParseError(
"unexpected token, expected end of statement");
8004 if (CurrentFn ==
nullptr) {
8005 reportParseError(
".end used without .ent");
8009 if ((SymbolName != CurrentFn->
getName())) {
8010 reportParseError(
".end symbol does not match .ent symbol");
8014 getTargetStreamer().emitDirectiveEnd(SymbolName);
8015 CurrentFn =
nullptr;
8016 IsCpRestoreSet =
false;
8020 if (IDVal ==
".frame") {
8025 reportParseError(
"expected stack register");
8029 MipsOperand &StackRegOpnd =
static_cast<MipsOperand &
>(*TmpReg[0]);
8030 if (!StackRegOpnd.isGPRAsmReg()) {
8031 reportParseError(StackRegOpnd.getStartLoc(),
8032 "expected general purpose register");
8035 unsigned StackReg = StackRegOpnd.getGPR32Reg();
8040 reportParseError(
"unexpected token, expected comma");
8046 int64_t FrameSizeVal;
8049 reportParseError(
"expected frame size value");
8053 if (!FrameSize->evaluateAsAbsolute(FrameSizeVal)) {
8054 reportParseError(
"frame size not an absolute expression");
8061 reportParseError(
"unexpected token, expected comma");
8067 ResTy = parseAnyRegister(TmpReg);
8069 reportParseError(
"expected return register");
8073 MipsOperand &ReturnRegOpnd =
static_cast<MipsOperand &
>(*TmpReg[0]);
8074 if (!ReturnRegOpnd.isGPRAsmReg()) {
8075 reportParseError(ReturnRegOpnd.getStartLoc(),
8076 "expected general purpose register");
8082 reportParseError(
"unexpected token, expected end of statement");
8086 getTargetStreamer().emitFrame(StackReg, FrameSizeVal,
8087 ReturnRegOpnd.getGPR32Reg());
8088 IsCpRestoreSet =
false;
8092 if (IDVal ==
".set") {
8093 parseDirectiveSet();
8097 if (IDVal ==
".mask" || IDVal ==
".fmask") {
8112 reportParseError(
"expected bitmask value");
8116 if (!BitMask->evaluateAsAbsolute(BitMaskVal)) {
8117 reportParseError(
"bitmask not an absolute expression");
8124 reportParseError(
"unexpected token, expected comma");
8129 const MCExpr *FrameOffset;
8130 int64_t FrameOffsetVal;
8133 reportParseError(
"expected frame offset value");
8137 if (!FrameOffset->evaluateAsAbsolute(FrameOffsetVal)) {
8138 reportParseError(
"frame offset not an absolute expression");
8144 reportParseError(
"unexpected token, expected end of statement");
8148 if (IDVal ==
".mask")
8149 getTargetStreamer().emitMask(BitMaskVal, FrameOffsetVal);
8151 getTargetStreamer().emitFMask(BitMaskVal, FrameOffsetVal);
8155 if (IDVal ==
".nan")
8156 return parseDirectiveNaN();
8158 if (IDVal ==
".gpword") {
8159 parseDirectiveGpWord();
8163 if (IDVal ==
".gpdword") {
8164 parseDirectiveGpDWord();
8168 if (IDVal ==
".dtprelword") {
8169 parseDirectiveDtpRelWord();
8173 if (IDVal ==
".dtpreldword") {
8174 parseDirectiveDtpRelDWord();
8178 if (IDVal ==
".tprelword") {
8179 parseDirectiveTpRelWord();
8183 if (IDVal ==
".tpreldword") {
8184 parseDirectiveTpRelDWord();
8188 if (IDVal ==
".option") {
8189 parseDirectiveOption();
8193 if (IDVal ==
".abicalls") {
8194 getTargetStreamer().emitDirectiveAbiCalls();
8197 "unexpected token, expected end of statement");
8202 if (IDVal ==
".cpsetup") {
8203 parseDirectiveCPSetup();
8206 if (IDVal ==
".cpreturn") {
8207 parseDirectiveCPReturn();
8210 if (IDVal ==
".module") {
8211 parseDirectiveModule();
8214 if (IDVal ==
".llvm_internal_mips_reallow_module_directive") {
8215 parseInternalDirectiveReallowModule();
8218 if (IDVal ==
".insn") {
8219 parseInsnDirective();
8222 if (IDVal ==
".rdata") {
8223 parseRSectionDirective(
".rodata");
8226 if (IDVal ==
".sbss") {
8230 if (IDVal ==
".sdata") {
8238 bool MipsAsmParser::parseInternalDirectiveReallowModule() {
8241 reportParseError(
"unexpected token, expected end of statement");
8245 getTargetStreamer().reallowModuleDirective();
8258 #define GET_REGISTER_MATCHER 8259 #define GET_MATCHER_IMPLEMENTATION 8260 #include "MipsGenAsmMatcher.inc" 8262 bool MipsAsmParser::mnemonicIsValid(
StringRef Mnemonic,
unsigned VariantID) {
8264 const MatchEntry *Start, *End;
8265 switch (VariantID) {
8270 auto MnemonicRange = std::equal_range(Start, End, Mnemonic, LessOpcode());
8271 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...
void push_back(const T &Elt)
const_iterator end(StringRef path)
Get end iterator over path.
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.
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.
Compute iterated dominance frontiers using a linear time algorithm.
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.
virtual void Initialize(MCAsmParser &Parser)
Initialize the extension for parsing using the given Parser.
static MCOperand createExpr(const MCExpr *Val)
bool ArePtrs64bit() const
MCTargetAsmParser - Generic interface to target specific assembly parsers.
Describe properties that are true of each instruction in the target description file.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
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)
IsPCRelativeLoad - A Load instruction with implicit source register ($pc) with explicit offset and de...
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.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
SMRange getLocRange() const
virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI, bool PrintSchedInfo=false)
Emit the given Instruction into the current section.
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
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.
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.
Target independent representation for an assembler token.
static int getRegClass(RegisterKind Is, unsigned RegWidth)
Represent a reference to a symbol from inside an expression.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE R Default(T Value)
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.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
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.
Target & getTheMips64Target()
Unary assembler expressions.
Simple integer binary arithmetic operators.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
static unsigned getRegisterForMxtrFP(MCInst &Inst, bool IsMFTC1)
const MCExpr * getExpr() const
static const fltSemantics & IEEEdouble() LLVM_READNONE
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
static bool isShiftedUIntAtAnyPosition(uint64_t x)
Can the value be represented by a unsigned N-bit value and a shift left?
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.
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.
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.
bool isLittleEndian() const
Tests whether the target triple is little endian.
The instances of the Type class are immutable: once they are created, they are never changed...
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
static ManagedStatic< OptionRegistry > OR
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.
HasFCCRegOperand - Instruction uses an $fcc<x> register.
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.
void emitLoadWithSymOffset(unsigned Opcode, unsigned DstReg, unsigned BaseReg, MCOperand &HiOperand, MCOperand &LoOperand, unsigned ATReg, SMLoc IDLoc, const MCSubtargetInfo *STI)
Emit a load instruction with an symbol offset.
#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.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
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)
void emitEmptyDelaySlot(bool hasShortDelaySlot, SMLoc IDLoc, const MCSubtargetInfo *STI)
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)
LLVM_ATTRIBUTE_ALWAYS_INLINE StringSwitch & Case(StringLiteral S, T Value)
Target & getTheMipsTarget()
static SMLoc getFromPointer(const char *Ptr)
void updateABIInfo(const PredicateLibrary &P)
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
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.
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.
LLVM_ATTRIBUTE_ALWAYS_INLINE StringSwitch & Cases(StringLiteral S0, StringLiteral S1, T Value)
constexpr bool isUInt< 16 >(uint64_t x)
static bool hasShortDelaySlot(unsigned Opcode)
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)
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()
LLVM Value Representation.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
const FeatureBitset Features
const MCOperandInfo * OpInfo
virtual void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
uint64_t OffsetToAlignment(uint64_t Value, uint64_t Align)
Returns the offset to the next integer (mod 2**64) that is greater than or equal to Value and is a mu...
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...
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
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
static FeatureBitset getFeatures(StringRef CPU, StringRef FS, ArrayRef< SubtargetFeatureKV > ProcDesc, ArrayRef< SubtargetFeatureKV > ProcFeatures)
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)
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
void emitStoreWithSymOffset(unsigned Opcode, unsigned SrcReg, unsigned BaseReg, MCOperand &HiOperand, MCOperand &LoOperand, unsigned ATReg, SMLoc IDLoc, const MCSubtargetInfo *STI)
Emit a store instruction with an symbol offset.
void LLVMInitializeMipsAsmParser()
TokenKind getKind() const