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;
150 void printWarningWithFixIt(
const Twine &Msg,
const Twine &FixMsg,
151 SMRange Range,
bool ShowColors =
true);
153 #define GET_ASSEMBLER_HEADER
154 #include "MipsGenAsmMatcher.inc"
157 checkEarlyTargetMatchPredicate(
MCInst &Inst,
159 unsigned checkTargetMatchPredicate(
MCInst &Inst)
override;
161 bool MatchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
164 bool MatchingInlineAsm)
override;
167 bool ParseRegister(
unsigned &RegNo,
SMLoc &StartLoc,
SMLoc &EndLoc)
override;
173 bool mnemonicIsValid(
StringRef Mnemonic,
unsigned VariantID);
178 bool ParseDirective(
AsmToken DirectiveID)
override;
198 enum MacroExpanderResultTy {
205 MacroExpanderResultTy tryExpandInstruction(
MCInst &Inst,
SMLoc IDLoc,
212 bool loadImmediate(int64_t ImmValue,
unsigned DstReg,
unsigned SrcReg,
213 bool Is32BitImm,
bool IsAddress,
SMLoc IDLoc,
216 bool loadAndAddSymbolAddress(
const MCExpr *SymExpr,
unsigned DstReg,
217 unsigned SrcReg,
bool Is32BitSym,
SMLoc IDLoc,
222 bool expandLoadImm(
MCInst &Inst,
bool Is32BitImm,
SMLoc IDLoc,
225 bool expandLoadImmReal(
MCInst &Inst,
bool IsSingle,
bool IsGPR,
bool Is64FPU,
229 bool expandLoadAddress(
unsigned DstReg,
unsigned BaseReg,
262 bool expandTrunc(
MCInst &Inst,
bool IsDouble,
bool Is64FPU,
SMLoc IDLoc,
307 bool reportParseError(
Twine ErrorMsg);
308 bool reportParseError(
SMLoc Loc,
Twine ErrorMsg);
310 bool parseMemOffset(
const MCExpr *&Res,
bool isParenExpr);
312 bool isEvaluated(
const MCExpr *Expr);
313 bool parseSetMips0Directive();
314 bool parseSetArchDirective();
315 bool parseSetFeature(uint64_t Feature);
316 bool isPicAndNotNxxAbi();
317 bool parseDirectiveCpLoad(
SMLoc Loc);
318 bool parseDirectiveCpRestore(
SMLoc Loc);
319 bool parseDirectiveCPSetup();
320 bool parseDirectiveCPReturn();
321 bool parseDirectiveNaN();
322 bool parseDirectiveSet();
323 bool parseDirectiveOption();
324 bool parseInsnDirective();
328 bool parseSetAtDirective();
329 bool parseSetNoAtDirective();
330 bool parseSetMacroDirective();
331 bool parseSetNoMacroDirective();
332 bool parseSetMsaDirective();
333 bool parseSetNoMsaDirective();
334 bool parseSetNoDspDirective();
335 bool parseSetReorderDirective();
336 bool parseSetNoReorderDirective();
337 bool parseSetMips16Directive();
338 bool parseSetNoMips16Directive();
339 bool parseSetFpDirective();
340 bool parseSetOddSPRegDirective();
341 bool parseSetNoOddSPRegDirective();
342 bool parseSetPopDirective();
343 bool parseSetPushDirective();
344 bool parseSetSoftFloatDirective();
345 bool parseSetHardFloatDirective();
346 bool parseSetMtDirective();
347 bool parseSetNoMtDirective();
349 bool parseSetAssignment();
351 bool parseDataDirective(
unsigned Size,
SMLoc L);
352 bool parseDirectiveGpWord();
353 bool parseDirectiveGpDWord();
354 bool parseDirectiveDtpRelWord();
355 bool parseDirectiveDtpRelDWord();
356 bool parseDirectiveTpRelWord();
357 bool parseDirectiveTpRelDWord();
358 bool parseDirectiveModule();
359 bool parseDirectiveModuleFP();
363 bool parseInternalDirectiveReallowModule();
381 unsigned getReg(
int RC,
int RegNo);
386 unsigned getATReg(
SMLoc Loc);
396 bool validateMSAIndex(
int Val,
int RegKind);
423 FeatureBits &= ~MipsAssemblerOptions::AllArchRelatedMask;
425 setAvailableFeatures(
430 void setFeatureBits(uint64_t Feature,
StringRef FeatureString) {
431 if (!(getSTI().getFeatureBits()[Feature])) {
433 setAvailableFeatures(
439 void clearFeatureBits(uint64_t Feature,
StringRef FeatureString) {
440 if (getSTI().getFeatureBits()[Feature]) {
442 setAvailableFeatures(
448 void setModuleFeatureBits(uint64_t Feature,
StringRef FeatureString) {
449 setFeatureBits(Feature, FeatureString);
450 AssemblerOptions.front()->setFeatures(getSTI().getFeatureBits());
453 void clearModuleFeatureBits(uint64_t Feature,
StringRef FeatureString) {
454 clearFeatureBits(Feature, FeatureString);
455 AssemblerOptions.front()->setFeatures(getSTI().getFeatureBits());
459 enum MipsMatchResultTy {
460 Match_RequiresDifferentSrcAndDst = FIRST_TARGET_MATCH_RESULT_TY,
461 Match_RequiresDifferentOperands,
462 Match_RequiresNoZeroRegister,
463 Match_RequiresSameSrcAndDst,
464 Match_NoFCCRegisterForCurrentISA,
465 Match_NonZeroOperandForSync,
466 #define GET_OPERAND_DIAGNOSTIC_TYPES
467 #include "MipsGenAsmMatcher.inc"
468 #undef GET_OPERAND_DIAGNOSTIC_TYPES
481 setAvailableFeatures(ComputeAvailableFeatures(getSTI().getFeatureBits()));
484 AssemblerOptions.push_back(
485 llvm::make_unique<MipsAssemblerOptions>(getSTI().getFeatureBits()));
488 AssemblerOptions.push_back(
489 llvm::make_unique<MipsAssemblerOptions>(getSTI().getFeatureBits()));
491 getTargetStreamer().updateABIInfo(*
this);
493 if (!isABI_O32() && !useOddSPReg() != 0)
498 IsPicEnabled = getContext().getObjectFileInfo()->isPositionIndependent();
500 IsCpRestoreSet =
false;
501 CpRestoreOffset = -1;
506 IsLittleEndian =
false;
508 IsLittleEndian =
true;
512 bool hasEightFccRegisters()
const {
return hasMips4() || hasMips32(); }
514 bool isGP64bit()
const {
515 return getSTI().getFeatureBits()[Mips::FeatureGP64Bit];
518 bool isFP64bit()
const {
519 return getSTI().getFeatureBits()[Mips::FeatureFP64Bit];
523 bool isABI_N32()
const {
return ABI.
IsN32(); }
524 bool isABI_N64()
const {
return ABI.IsN64(); }
525 bool isABI_O32()
const {
return ABI.IsO32(); }
526 bool isABI_FPXX()
const {
527 return getSTI().getFeatureBits()[Mips::FeatureFPXX];
530 bool useOddSPReg()
const {
531 return !(getSTI().getFeatureBits()[Mips::FeatureNoOddSPReg]);
534 bool inMicroMipsMode()
const {
535 return getSTI().getFeatureBits()[Mips::FeatureMicroMips];
538 bool hasMips1()
const {
539 return getSTI().getFeatureBits()[Mips::FeatureMips1];
542 bool hasMips2()
const {
543 return getSTI().getFeatureBits()[Mips::FeatureMips2];
546 bool hasMips3()
const {
547 return getSTI().getFeatureBits()[Mips::FeatureMips3];
550 bool hasMips4()
const {
551 return getSTI().getFeatureBits()[Mips::FeatureMips4];
554 bool hasMips5()
const {
555 return getSTI().getFeatureBits()[Mips::FeatureMips5];
558 bool hasMips32()
const {
559 return getSTI().getFeatureBits()[Mips::FeatureMips32];
562 bool hasMips64()
const {
563 return getSTI().getFeatureBits()[Mips::FeatureMips64];
566 bool hasMips32r2()
const {
567 return getSTI().getFeatureBits()[Mips::FeatureMips32r2];
570 bool hasMips64r2()
const {
571 return getSTI().getFeatureBits()[Mips::FeatureMips64r2];
574 bool hasMips32r3()
const {
575 return (getSTI().getFeatureBits()[Mips::FeatureMips32r3]);
578 bool hasMips64r3()
const {
579 return (getSTI().getFeatureBits()[Mips::FeatureMips64r3]);
582 bool hasMips32r5()
const {
583 return (getSTI().getFeatureBits()[Mips::FeatureMips32r5]);
586 bool hasMips64r5()
const {
587 return (getSTI().getFeatureBits()[Mips::FeatureMips64r5]);
590 bool hasMips32r6()
const {
591 return getSTI().getFeatureBits()[Mips::FeatureMips32r6];
594 bool hasMips64r6()
const {
595 return getSTI().getFeatureBits()[Mips::FeatureMips64r6];
598 bool hasDSP()
const {
599 return getSTI().getFeatureBits()[Mips::FeatureDSP];
602 bool hasDSPR2()
const {
603 return getSTI().getFeatureBits()[Mips::FeatureDSPR2];
606 bool hasDSPR3()
const {
607 return getSTI().getFeatureBits()[Mips::FeatureDSPR3];
610 bool hasMSA()
const {
611 return getSTI().getFeatureBits()[Mips::FeatureMSA];
614 bool hasCnMips()
const {
615 return (getSTI().getFeatureBits()[Mips::FeatureCnMips]);
622 bool inMips16Mode()
const {
623 return getSTI().getFeatureBits()[Mips::FeatureMips16];
626 bool useTraps()
const {
627 return getSTI().getFeatureBits()[Mips::FeatureUseTCCInDIV];
630 bool useSoftFloat()
const {
631 return getSTI().getFeatureBits()[Mips::FeatureSoftFloat];
634 return getSTI().getFeatureBits()[Mips::FeatureMT];
638 void warnIfRegIndexIsAT(
unsigned RegIndex,
SMLoc Loc);
640 void warnIfNoMacro(
SMLoc Loc);
642 bool isLittle()
const {
return IsLittleEndian; }
647 switch(OperatorToken) {
715 RegKind_MSACtrl = 16,
720 RegKind_HWRegs = 256,
724 RegKind_Numeric = RegKind_GPR | RegKind_FGR | RegKind_FCC | RegKind_MSA128 |
725 RegKind_MSACtrl | RegKind_COP2 | RegKind_ACC |
726 RegKind_CCR | RegKind_HWRegs | RegKind_COP3 | RegKind_COP0
740 MipsOperand(KindTy K, MipsAsmParser &Parser)
743 ~MipsOperand()
override {
752 case k_RegisterIndex:
761 MipsAsmParser &AsmParser;
790 struct RegIdxOp RegIdx;
793 struct RegListOp RegList;
796 SMLoc StartLoc, EndLoc;
799 static std::unique_ptr<MipsOperand> CreateReg(
unsigned Index,
StringRef Str,
803 MipsAsmParser &Parser) {
804 auto Op = llvm::make_unique<MipsOperand>(k_RegisterIndex, Parser);
805 Op->RegIdx.Index = Index;
806 Op->RegIdx.RegInfo = RegInfo;
807 Op->RegIdx.Kind = RegKind;
808 Op->RegIdx.Tok.Data = Str.
data();
809 Op->RegIdx.Tok.Length = Str.
size();
818 unsigned getGPR32Reg()
const {
819 assert(isRegIdx() && (RegIdx.Kind & RegKind_GPR) &&
"Invalid access!");
820 AsmParser.warnIfRegIndexIsAT(RegIdx.Index, StartLoc);
821 unsigned ClassID = Mips::GPR32RegClassID;
822 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
827 unsigned getGPRMM16Reg()
const {
828 assert(isRegIdx() && (RegIdx.Kind & RegKind_GPR) &&
"Invalid access!");
829 unsigned ClassID = Mips::GPR32RegClassID;
830 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
835 unsigned getGPR64Reg()
const {
836 assert(isRegIdx() && (RegIdx.Kind & RegKind_GPR) &&
"Invalid access!");
837 unsigned ClassID = Mips::GPR64RegClassID;
838 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
844 unsigned getAFGR64Reg()
const {
845 assert(isRegIdx() && (RegIdx.Kind & RegKind_FGR) &&
"Invalid access!");
846 if (RegIdx.Index % 2 != 0)
847 AsmParser.Warning(StartLoc,
"Float register should be even.");
848 return RegIdx.RegInfo->getRegClass(Mips::AFGR64RegClassID)
849 .getRegister(RegIdx.Index / 2);
854 unsigned getFGR64Reg()
const {
855 assert(isRegIdx() && (RegIdx.Kind & RegKind_FGR) &&
"Invalid access!");
856 return RegIdx.RegInfo->getRegClass(Mips::FGR64RegClassID)
857 .getRegister(RegIdx.Index);
862 unsigned getFGR32Reg()
const {
863 assert(isRegIdx() && (RegIdx.Kind & RegKind_FGR) &&
"Invalid access!");
864 return RegIdx.RegInfo->getRegClass(Mips::FGR32RegClassID)
865 .getRegister(RegIdx.Index);
870 unsigned getFGRH32Reg()
const {
871 assert(isRegIdx() && (RegIdx.Kind & RegKind_FGR) &&
"Invalid access!");
872 return RegIdx.RegInfo->getRegClass(Mips::FGRH32RegClassID)
873 .getRegister(RegIdx.Index);
878 unsigned getFCCReg()
const {
879 assert(isRegIdx() && (RegIdx.Kind & RegKind_FCC) &&
"Invalid access!");
880 return RegIdx.RegInfo->getRegClass(Mips::FCCRegClassID)
881 .getRegister(RegIdx.Index);
886 unsigned getMSA128Reg()
const {
887 assert(isRegIdx() && (RegIdx.Kind & RegKind_MSA128) &&
"Invalid access!");
890 unsigned ClassID = Mips::MSA128BRegClassID;
891 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
896 unsigned getMSACtrlReg()
const {
897 assert(isRegIdx() && (RegIdx.Kind & RegKind_MSACtrl) &&
"Invalid access!");
898 unsigned ClassID = Mips::MSACtrlRegClassID;
899 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
904 unsigned getCOP0Reg()
const {
905 assert(isRegIdx() && (RegIdx.Kind & RegKind_COP0) &&
"Invalid access!");
906 unsigned ClassID = Mips::COP0RegClassID;
907 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
912 unsigned getCOP2Reg()
const {
913 assert(isRegIdx() && (RegIdx.Kind & RegKind_COP2) &&
"Invalid access!");
914 unsigned ClassID = Mips::COP2RegClassID;
915 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
920 unsigned getCOP3Reg()
const {
921 assert(isRegIdx() && (RegIdx.Kind & RegKind_COP3) &&
"Invalid access!");
922 unsigned ClassID = Mips::COP3RegClassID;
923 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
928 unsigned getACC64DSPReg()
const {
929 assert(isRegIdx() && (RegIdx.Kind & RegKind_ACC) &&
"Invalid access!");
930 unsigned ClassID = Mips::ACC64DSPRegClassID;
931 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
936 unsigned getHI32DSPReg()
const {
937 assert(isRegIdx() && (RegIdx.Kind & RegKind_ACC) &&
"Invalid access!");
938 unsigned ClassID = Mips::HI32DSPRegClassID;
939 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
944 unsigned getLO32DSPReg()
const {
945 assert(isRegIdx() && (RegIdx.Kind & RegKind_ACC) &&
"Invalid access!");
946 unsigned ClassID = Mips::LO32DSPRegClassID;
947 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
952 unsigned getCCRReg()
const {
953 assert(isRegIdx() && (RegIdx.Kind & RegKind_CCR) &&
"Invalid access!");
954 unsigned ClassID = Mips::CCRRegClassID;
955 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
960 unsigned getHWRegsReg()
const {
961 assert(isRegIdx() && (RegIdx.Kind & RegKind_HWRegs) &&
"Invalid access!");
962 unsigned ClassID = Mips::HWRegsRegClassID;
963 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
971 else if (
const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
977 void addRegOperands(
MCInst &Inst,
unsigned N)
const {
984 void addGPR32ZeroAsmRegOperands(
MCInst &Inst,
unsigned N)
const {
985 assert(N == 1 &&
"Invalid number of operands!");
989 void addGPR32NonZeroAsmRegOperands(
MCInst &Inst,
unsigned N)
const {
990 assert(N == 1 &&
"Invalid number of operands!");
994 void addGPR32AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
995 assert(N == 1 &&
"Invalid number of operands!");
999 void addGPRMM16AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1000 assert(N == 1 &&
"Invalid number of operands!");
1004 void addGPRMM16AsmRegZeroOperands(
MCInst &Inst,
unsigned N)
const {
1005 assert(N == 1 &&
"Invalid number of operands!");
1009 void addGPRMM16AsmRegMovePOperands(
MCInst &Inst,
unsigned N)
const {
1010 assert(N == 1 &&
"Invalid number of operands!");
1017 void addGPR64AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1018 assert(N == 1 &&
"Invalid number of operands!");
1022 void addAFGR64AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1023 assert(N == 1 &&
"Invalid number of operands!");
1027 void addStrictlyAFGR64AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1028 assert(N == 1 &&
"Invalid number of operands!");
1032 void addStrictlyFGR64AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1033 assert(N == 1 &&
"Invalid number of operands!");
1037 void addFGR64AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1038 assert(N == 1 &&
"Invalid number of operands!");
1042 void addFGR32AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1043 assert(N == 1 &&
"Invalid number of operands!");
1047 if (!AsmParser.useOddSPReg() && RegIdx.Index & 1)
1048 AsmParser.getParser().printError(
1049 StartLoc,
"-mno-odd-spreg prohibits the use of odd FPU "
1053 void addStrictlyFGR32AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1054 assert(N == 1 &&
"Invalid number of operands!");
1057 if (!AsmParser.useOddSPReg() && RegIdx.Index & 1)
1058 AsmParser.Error(StartLoc,
"-mno-odd-spreg prohibits the use of odd FPU "
1062 void addFGRH32AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1063 assert(N == 1 &&
"Invalid number of operands!");
1067 void addFCCAsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1068 assert(N == 1 &&
"Invalid number of operands!");
1072 void addMSA128AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1073 assert(N == 1 &&
"Invalid number of operands!");
1077 void addMSACtrlAsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1078 assert(N == 1 &&
"Invalid number of operands!");
1082 void addCOP0AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1083 assert(N == 1 &&
"Invalid number of operands!");
1087 void addCOP2AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1088 assert(N == 1 &&
"Invalid number of operands!");
1092 void addCOP3AsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1093 assert(N == 1 &&
"Invalid number of operands!");
1097 void addACC64DSPAsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1098 assert(N == 1 &&
"Invalid number of operands!");
1102 void addHI32DSPAsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1103 assert(N == 1 &&
"Invalid number of operands!");
1107 void addLO32DSPAsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1108 assert(N == 1 &&
"Invalid number of operands!");
1112 void addCCRAsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1113 assert(N == 1 &&
"Invalid number of operands!");
1117 void addHWRegsAsmRegOperands(
MCInst &Inst,
unsigned N)
const {
1118 assert(N == 1 &&
"Invalid number of operands!");
1122 template <
unsigned Bits,
int Offset = 0,
int AdjustOffset = 0>
1123 void addConstantUImmOperands(
MCInst &Inst,
unsigned N)
const {
1124 assert(N == 1 &&
"Invalid number of operands!");
1125 uint64_t Imm = getConstantImm() -
Offset;
1126 Imm &= (1ULL <<
Bits) - 1;
1128 Imm += AdjustOffset;
1132 template <
unsigned Bits>
1133 void addSImmOperands(
MCInst &Inst,
unsigned N)
const {
1134 if (isImm() && !isConstantImm()) {
1135 addExpr(Inst, getImm());
1138 addConstantSImmOperands<Bits, 0, 0>(Inst,
N);
1141 template <
unsigned Bits>
1142 void addUImmOperands(
MCInst &Inst,
unsigned N)
const {
1143 if (isImm() && !isConstantImm()) {
1144 addExpr(Inst, getImm());
1147 addConstantUImmOperands<Bits, 0, 0>(Inst,
N);
1150 template <
unsigned Bits,
int Offset = 0,
int AdjustOffset = 0>
1151 void addConstantSImmOperands(
MCInst &Inst,
unsigned N)
const {
1152 assert(N == 1 &&
"Invalid number of operands!");
1153 int64_t Imm = getConstantImm() -
Offset;
1154 Imm = SignExtend64<Bits>(Imm);
1156 Imm += AdjustOffset;
1160 void addImmOperands(
MCInst &Inst,
unsigned N)
const {
1161 assert(N == 1 &&
"Invalid number of operands!");
1162 const MCExpr *Expr = getImm();
1163 addExpr(Inst, Expr);
1166 void addMemOperands(
MCInst &Inst,
unsigned N)
const {
1167 assert(N == 2 &&
"Invalid number of operands!");
1170 ? getMemBase()->getGPR64Reg()
1171 : getMemBase()->getGPR32Reg()));
1173 const MCExpr *Expr = getMemOff();
1174 addExpr(Inst, Expr);
1177 void addMicroMipsMemOperands(
MCInst &Inst,
unsigned N)
const {
1178 assert(N == 2 &&
"Invalid number of operands!");
1182 const MCExpr *Expr = getMemOff();
1183 addExpr(Inst, Expr);
1186 void addRegListOperands(
MCInst &Inst,
unsigned N)
const {
1187 assert(N == 1 &&
"Invalid number of operands!");
1189 for (
auto RegNo : getRegList())
1193 void addRegPairOperands(
MCInst &Inst,
unsigned N)
const {
1194 assert(N == 2 &&
"Invalid number of operands!");
1195 assert((RegIdx.Kind & RegKind_GPR) &&
"Invalid access!");
1196 unsigned RegNo = getRegPair();
1197 AsmParser.warnIfRegIndexIsAT(RegNo, StartLoc);
1199 RegIdx.RegInfo->getRegClass(
1200 AsmParser.getABI().AreGprs64bit()
1201 ? Mips::GPR64RegClassID
1202 : Mips::GPR32RegClassID).getRegister(RegNo++)));
1204 RegIdx.RegInfo->getRegClass(
1205 AsmParser.getABI().AreGprs64bit()
1206 ? Mips::GPR64RegClassID
1207 : Mips::GPR32RegClassID).getRegister(RegNo)));
1210 void addMovePRegPairOperands(
MCInst &Inst,
unsigned N)
const {
1211 assert(N == 2 &&
"Invalid number of operands!");
1212 for (
auto RegNo : getRegList())
1216 bool isReg()
const override {
1219 return isGPRAsmReg() && RegIdx.Index == 0;
1222 bool isRegIdx()
const {
return Kind == k_RegisterIndex; }
1223 bool isImm()
const override {
return Kind == k_Immediate; }
1225 bool isConstantImm()
const {
1227 return isImm() && getImm()->evaluateAsAbsolute(Res);
1230 bool isConstantImmz()
const {
1231 return isConstantImm() && getConstantImm() == 0;
1234 template <
unsigned Bits,
int Offset = 0>
bool isConstantUImm()
const {
1235 return isConstantImm() && isUInt<Bits>(getConstantImm() -
Offset);
1238 template <
unsigned Bits>
bool isSImm()
const {
1239 return isConstantImm() ? isInt<Bits>(getConstantImm()) : isImm();
1242 template <
unsigned Bits>
bool isUImm()
const {
1243 return isConstantImm() ? isUInt<Bits>(getConstantImm()) : isImm();
1246 template <
unsigned Bits>
bool isAnyImm()
const {
1247 return isConstantImm() ? (isInt<Bits>(getConstantImm()) ||
1248 isUInt<Bits>(getConstantImm()))
1252 template <
unsigned Bits,
int Offset = 0>
bool isConstantSImm()
const {
1253 return isConstantImm() && isInt<Bits>(getConstantImm() -
Offset);
1256 template <
unsigned Bottom,
unsigned Top>
bool isConstantUImmRange()
const {
1257 return isConstantImm() && getConstantImm() >= Bottom &&
1258 getConstantImm() <= Top;
1261 bool isToken()
const override {
1264 return Kind == k_Token;
1267 bool isMem()
const override {
return Kind == k_Memory; }
1269 bool isConstantMemOff()
const {
1270 return isMem() && isa<MCConstantExpr>(getMemOff());
1276 template <
unsigned Bits,
unsigned ShiftAmount = 0>
1277 bool isMemWithSimmOffset()
const {
1280 if (!getMemBase()->isGPRAsmReg())
1282 if (isa<MCTargetExpr>(getMemOff()) ||
1283 (isConstantMemOff() &&
1284 isShiftedInt<Bits, ShiftAmount>(getConstantMemOff())))
1287 bool IsReloc = getMemOff()->evaluateAsRelocatable(Res,
nullptr,
nullptr);
1288 return IsReloc && isShiftedInt<Bits, ShiftAmount>(Res.
getConstant());
1291 bool isMemWithGRPMM16Base()
const {
1292 return isMem() && getMemBase()->isMM16AsmReg();
1295 template <
unsigned Bits>
bool isMemWithUimmOffsetSP()
const {
1296 return isMem() && isConstantMemOff() && isUInt<Bits>(getConstantMemOff())
1297 && getMemBase()->isRegIdx() && (getMemBase()->getGPR32Reg() == Mips::SP);
1300 template <
unsigned Bits>
bool isMemWithUimmWordAlignedOffsetSP()
const {
1301 return isMem() && isConstantMemOff() && isUInt<Bits>(getConstantMemOff())
1302 && (getConstantMemOff() % 4 == 0) && getMemBase()->isRegIdx()
1303 && (getMemBase()->getGPR32Reg() == Mips::SP);
1306 template <
unsigned Bits>
bool isMemWithSimmWordAlignedOffsetGP()
const {
1307 return isMem() && isConstantMemOff() && isInt<Bits>(getConstantMemOff())
1308 && (getConstantMemOff() % 4 == 0) && getMemBase()->isRegIdx()
1309 && (getMemBase()->getGPR32Reg() == Mips::GP);
1312 template <
unsigned Bits,
unsigned ShiftLeftAmount>
1313 bool isScaledUImm()
const {
1314 return isConstantImm() &&
1315 isShiftedUInt<Bits, ShiftLeftAmount>(getConstantImm());
1318 template <
unsigned Bits,
unsigned ShiftLeftAmount>
1319 bool isScaledSImm()
const {
1320 if (isConstantImm() && isShiftedInt<Bits, ShiftLeftAmount>(getConstantImm()))
1323 if (
Kind != k_Immediate)
1326 bool Success = getImm()->evaluateAsRelocatable(Res,
nullptr,
nullptr);
1327 return Success && isShiftedInt<Bits, ShiftLeftAmount>(Res.
getConstant());
1330 bool isRegList16()
const {
1334 int Size = RegList.List->size();
1335 if (Size < 2 || Size > 5)
1338 unsigned R0 = RegList.List->front();
1339 unsigned R1 = RegList.List->back();
1340 if (!((R0 == Mips::S0 && R1 == Mips::RA) ||
1341 (R0 == Mips::S0_64 && R1 == Mips::RA_64)))
1344 int PrevReg = *RegList.List->begin();
1345 for (
int i = 1; i < Size - 1; i++) {
1346 int Reg = (*(RegList.List))[i];
1347 if ( Reg != PrevReg + 1)
1355 bool isInvNum()
const {
return Kind == k_Immediate; }
1357 bool isLSAImm()
const {
1358 if (!isConstantImm())
1360 int64_t Val = getConstantImm();
1361 return 1 <= Val && Val <= 4;
1364 bool isRegList()
const {
return Kind == k_RegList; }
1366 bool isMovePRegPair()
const {
1367 if (
Kind != k_RegList || RegList.List->size() != 2)
1370 unsigned R0 = RegList.List->front();
1371 unsigned R1 = RegList.List->back();
1373 if ((R0 == Mips::A1 && R1 == Mips::A2) ||
1374 (R0 == Mips::A1 && R1 == Mips::A3) ||
1375 (R0 == Mips::A2 && R1 == Mips::A3) ||
1376 (R0 == Mips::A0 && R1 == Mips::S5) ||
1377 (R0 == Mips::A0 && R1 == Mips::S6) ||
1378 (R0 == Mips::A0 && R1 == Mips::A1) ||
1379 (R0 == Mips::A0 && R1 == Mips::A2) ||
1380 (R0 == Mips::A0 && R1 == Mips::A3) ||
1381 (R0 == Mips::A1_64 && R1 == Mips::A2_64) ||
1382 (R0 == Mips::A1_64 && R1 == Mips::A3_64) ||
1383 (R0 == Mips::A2_64 && R1 == Mips::A3_64) ||
1384 (R0 == Mips::A0_64 && R1 == Mips::S5_64) ||
1385 (R0 == Mips::A0_64 && R1 == Mips::S6_64) ||
1386 (R0 == Mips::A0_64 && R1 == Mips::A1_64) ||
1387 (R0 == Mips::A0_64 && R1 == Mips::A2_64) ||
1388 (R0 == Mips::A0_64 && R1 == Mips::A3_64))
1395 assert(
Kind == k_Token &&
"Invalid access!");
1399 bool isRegPair()
const {
1400 return Kind == k_RegPair && RegIdx.Index <= 30;
1403 unsigned getReg()
const override {
1406 if (
Kind == k_RegisterIndex && RegIdx.Index == 0 &&
1407 RegIdx.Kind & RegKind_GPR)
1408 return getGPR32Reg();
1414 const MCExpr *getImm()
const {
1415 assert((
Kind == k_Immediate) &&
"Invalid access!");
1419 int64_t getConstantImm()
const {
1420 const MCExpr *Val = getImm();
1422 (void)Val->evaluateAsAbsolute(Value);
1426 MipsOperand *getMemBase()
const {
1427 assert((
Kind == k_Memory) &&
"Invalid access!");
1431 const MCExpr *getMemOff()
const {
1432 assert((
Kind == k_Memory) &&
"Invalid access!");
1436 int64_t getConstantMemOff()
const {
1437 return static_cast<const MCConstantExpr *
>(getMemOff())->getValue();
1441 assert((
Kind == k_RegList) &&
"Invalid access!");
1442 return *(RegList.List);
1445 unsigned getRegPair()
const {
1446 assert((
Kind == k_RegPair) &&
"Invalid access!");
1447 return RegIdx.Index;
1450 static std::unique_ptr<MipsOperand> CreateToken(
StringRef Str,
SMLoc S,
1451 MipsAsmParser &Parser) {
1452 auto Op = llvm::make_unique<MipsOperand>(k_Token, Parser);
1453 Op->Tok.Data = Str.
data();
1454 Op->Tok.Length = Str.
size();
1462 static std::unique_ptr<MipsOperand>
1465 DEBUG(
dbgs() <<
"createNumericReg(" << Index <<
", ...)\n");
1466 return CreateReg(Index, Str, RegKind_Numeric, RegInfo, S, E, Parser);
1471 static std::unique_ptr<MipsOperand>
1474 return CreateReg(Index, Str, RegKind_GPR, RegInfo, S, E, Parser);
1479 static std::unique_ptr<MipsOperand>
1482 return CreateReg(Index, Str, RegKind_FGR, RegInfo, S, E, Parser);
1487 static std::unique_ptr<MipsOperand>
1490 return CreateReg(Index, Str, RegKind_HWRegs, RegInfo, S, E, Parser);
1495 static std::unique_ptr<MipsOperand>
1498 return CreateReg(Index, Str, RegKind_FCC, RegInfo, S, E, Parser);
1503 static std::unique_ptr<MipsOperand>
1506 return CreateReg(Index, Str, RegKind_ACC, RegInfo, S, E, Parser);
1511 static std::unique_ptr<MipsOperand>
1514 return CreateReg(Index, Str, RegKind_MSA128, RegInfo, S, E, Parser);
1519 static std::unique_ptr<MipsOperand>
1522 return CreateReg(Index, Str, RegKind_MSACtrl, RegInfo, S, E, Parser);
1525 static std::unique_ptr<MipsOperand>
1527 auto Op = llvm::make_unique<MipsOperand>(k_Immediate, Parser);
1534 static std::unique_ptr<MipsOperand>
1535 CreateMem(std::unique_ptr<MipsOperand>
Base,
const MCExpr *Off,
SMLoc S,
1536 SMLoc E, MipsAsmParser &Parser) {
1537 auto Op = llvm::make_unique<MipsOperand>(k_Memory, Parser);
1538 Op->Mem.Base = Base.release();
1545 static std::unique_ptr<MipsOperand>
1547 MipsAsmParser &Parser) {
1548 assert(Regs.
size() > 0 &&
"Empty list not allowed");
1550 auto Op = llvm::make_unique<MipsOperand>(k_RegList, Parser);
1552 Op->StartLoc = StartLoc;
1553 Op->EndLoc = EndLoc;
1557 static std::unique_ptr<MipsOperand> CreateRegPair(
const MipsOperand &MOP,
1559 MipsAsmParser &Parser) {
1560 auto Op = llvm::make_unique<MipsOperand>(k_RegPair, Parser);
1561 Op->RegIdx.Index = MOP.RegIdx.Index;
1562 Op->RegIdx.RegInfo = MOP.RegIdx.RegInfo;
1563 Op->RegIdx.Kind = MOP.RegIdx.Kind;
1569 bool isGPRZeroAsmReg()
const {
1570 return isRegIdx() && RegIdx.Kind & RegKind_GPR && RegIdx.Index == 0;
1573 bool isGPRNonZeroAsmReg()
const {
1574 return isRegIdx() && RegIdx.Kind & RegKind_GPR && RegIdx.Index > 0 &&
1578 bool isGPRAsmReg()
const {
1579 return isRegIdx() && RegIdx.Kind & RegKind_GPR && RegIdx.Index <= 31;
1582 bool isMM16AsmReg()
const {
1583 if (!(isRegIdx() && RegIdx.Kind))
1585 return ((RegIdx.Index >= 2 && RegIdx.Index <= 7)
1586 || RegIdx.Index == 16 || RegIdx.Index == 17);
1589 bool isMM16AsmRegZero()
const {
1590 if (!(isRegIdx() && RegIdx.Kind))
1592 return (RegIdx.Index == 0 ||
1593 (RegIdx.Index >= 2 && RegIdx.Index <= 7) ||
1594 RegIdx.Index == 17);
1597 bool isMM16AsmRegMoveP()
const {
1598 if (!(isRegIdx() && RegIdx.Kind))
1600 return (RegIdx.Index == 0 || (RegIdx.Index >= 2 && RegIdx.Index <= 3) ||
1601 (RegIdx.Index >= 16 && RegIdx.Index <= 20));
1604 bool isFGRAsmReg()
const {
1606 return isRegIdx() && RegIdx.Kind & RegKind_FGR && RegIdx.Index <= 31;
1609 bool isStrictlyFGRAsmReg()
const {
1611 return isRegIdx() && RegIdx.Kind == RegKind_FGR && RegIdx.Index <= 31;
1614 bool isHWRegsAsmReg()
const {
1615 return isRegIdx() && RegIdx.Kind & RegKind_HWRegs && RegIdx.Index <= 31;
1618 bool isCCRAsmReg()
const {
1619 return isRegIdx() && RegIdx.Kind & RegKind_CCR && RegIdx.Index <= 31;
1622 bool isFCCAsmReg()
const {
1623 if (!(isRegIdx() && RegIdx.Kind & RegKind_FCC))
1625 return RegIdx.Index <= 7;
1628 bool isACCAsmReg()
const {
1629 return isRegIdx() && RegIdx.Kind & RegKind_ACC && RegIdx.Index <= 3;
1632 bool isCOP0AsmReg()
const {
1633 return isRegIdx() && RegIdx.Kind & RegKind_COP0 && RegIdx.Index <= 31;
1636 bool isCOP2AsmReg()
const {
1637 return isRegIdx() && RegIdx.Kind & RegKind_COP2 && RegIdx.Index <= 31;
1640 bool isCOP3AsmReg()
const {
1641 return isRegIdx() && RegIdx.Kind & RegKind_COP3 && RegIdx.Index <= 31;
1644 bool isMSA128AsmReg()
const {
1645 return isRegIdx() && RegIdx.Kind & RegKind_MSA128 && RegIdx.Index <= 31;
1648 bool isMSACtrlAsmReg()
const {
1649 return isRegIdx() && RegIdx.Kind & RegKind_MSACtrl && RegIdx.Index <= 7;
1653 SMLoc getStartLoc()
const override {
return StartLoc; }
1655 SMLoc getEndLoc()
const override {
return EndLoc; }
1666 Mem.Base->print(OS);
1671 case k_RegisterIndex:
1672 OS <<
"RegIdx<" << RegIdx.Index <<
":" << RegIdx.Kind <<
", "
1673 <<
StringRef(RegIdx.Tok.Data, RegIdx.Tok.Length) <<
">";
1680 for (
auto Reg : (*RegList.List))
1685 OS <<
"RegPair<" << RegIdx.Index <<
"," << RegIdx.Index + 1 <<
">";
1690 bool isValidForTie(
const MipsOperand &
Other)
const {
1691 if (
Kind != Other.Kind)
1698 case k_RegisterIndex: {
1699 StringRef Token(RegIdx.Tok.Data, RegIdx.Tok.Length);
1700 StringRef OtherToken(Other.RegIdx.Tok.Data, Other.RegIdx.Tok.Length);
1701 return Token == OtherToken;
1722 case Mips::JALRS_MM:
1723 case Mips::JALRS16_MM:
1724 case Mips::BGEZALS_MM:
1725 case Mips::BLTZALS_MM:
1733 if (
const MCSymbolRefExpr *SRExpr = dyn_cast<MCSymbolRefExpr>(Expr)) {
1734 return &SRExpr->getSymbol();
1737 if (
const MCBinaryExpr *BExpr = dyn_cast<MCBinaryExpr>(Expr)) {
1750 if (
const MCUnaryExpr *UExpr = dyn_cast<MCUnaryExpr>(Expr))
1757 if (isa<MCSymbolRefExpr>(Expr))
1760 if (
const MCBinaryExpr *BExpr = dyn_cast<MCBinaryExpr>(Expr))
1764 if (
const MCUnaryExpr *UExpr = dyn_cast<MCUnaryExpr>(Expr))
1770 bool MipsAsmParser::processInstruction(
MCInst &Inst,
SMLoc IDLoc,
1775 bool ExpandedJalSym =
false;
1780 const unsigned Opcode = Inst.
getOpcode();
1790 assert(hasCnMips() &&
"instruction only valid for octeon cpus");
1799 if (!Offset.isImm())
1801 if (!
isIntN(inMicroMipsMode() ? 17 : 18, Offset.getImm()))
1802 return Error(IDLoc,
"branch target out of range");
1804 1LL << (inMicroMipsMode() ? 1 : 2)))
1805 return Error(IDLoc,
"branch to misaligned address");
1819 case Mips::BGEZAL_MM:
1820 case Mips::BLTZAL_MM:
1823 case Mips::BC1EQZC_MMR6:
1824 case Mips::BC1NEZC_MMR6:
1825 case Mips::BC2EQZC_MMR6:
1826 case Mips::BC2NEZC_MMR6:
1829 if (!Offset.isImm())
1831 if (!
isIntN(inMicroMipsMode() ? 17 : 18, Offset.getImm()))
1832 return Error(IDLoc,
"branch target out of range");
1834 1LL << (inMicroMipsMode() ? 1 : 2)))
1835 return Error(IDLoc,
"branch to misaligned address");
1837 case Mips::BGEC:
case Mips::BGEC_MMR6:
1838 case Mips::BLTC:
case Mips::BLTC_MMR6:
1839 case Mips::BGEUC:
case Mips::BGEUC_MMR6:
1840 case Mips::BLTUC:
case Mips::BLTUC_MMR6:
1841 case Mips::BEQC:
case Mips::BEQC_MMR6:
1842 case Mips::BNEC:
case Mips::BNEC_MMR6:
1845 if (!Offset.isImm())
1847 if (!
isIntN(18, Offset.getImm()))
1848 return Error(IDLoc,
"branch target out of range");
1850 return Error(IDLoc,
"branch to misaligned address");
1852 case Mips::BLEZC:
case Mips::BLEZC_MMR6:
1853 case Mips::BGEZC:
case Mips::BGEZC_MMR6:
1854 case Mips::BGTZC:
case Mips::BGTZC_MMR6:
1855 case Mips::BLTZC:
case Mips::BLTZC_MMR6:
1858 if (!Offset.isImm())
1860 if (!
isIntN(18, Offset.getImm()))
1861 return Error(IDLoc,
"branch target out of range");
1863 return Error(IDLoc,
"branch to misaligned address");
1865 case Mips::BEQZC:
case Mips::BEQZC_MMR6:
1866 case Mips::BNEZC:
case Mips::BNEZC_MMR6:
1869 if (!Offset.isImm())
1871 if (!
isIntN(23, Offset.getImm()))
1872 return Error(IDLoc,
"branch target out of range");
1874 return Error(IDLoc,
"branch to misaligned address");
1876 case Mips::BEQZ16_MM:
1877 case Mips::BEQZC16_MMR6:
1878 case Mips::BNEZ16_MM:
1879 case Mips::BNEZC16_MMR6:
1882 if (!Offset.isImm())
1885 return Error(IDLoc,
"branch target out of range");
1887 return Error(IDLoc,
"branch to misaligned address");
1894 if (hasMips32r6() && Inst.
getOpcode() == Mips::SSNOP) {
1895 std::string ISA = hasMips64r6() ?
"MIPS64r6" :
"MIPS32r6";
1896 Warning(IDLoc,
"ssnop is deprecated for " + ISA +
" and is equivalent to a "
1901 const unsigned Opcode = Inst.
getOpcode();
1917 return Error(IDLoc,
"expected immediate operand kind");
1918 Imm = Opnd.getImm();
1919 if (Imm < 0 || Imm > (Opcode == Mips::BBIT0 ||
1920 Opcode == Mips::BBIT1 ? 63 : 31))
1921 return Error(IDLoc,
"immediate operand value out of range");
1923 Inst.
setOpcode(Opcode == Mips::BBIT0 ? Mips::BBIT032
1934 return Error(IDLoc,
"expected immediate operand kind");
1935 Imm = Opnd.getImm();
1936 if (!isInt<10>(Imm))
1937 return Error(IDLoc,
"immediate operand value out of range");
1949 unsigned FirstOp = 1;
1950 unsigned SecondOp = 2;
1954 case Mips::SDivIMacro:
1955 case Mips::UDivIMacro:
1956 case Mips::DSDivIMacro:
1957 case Mips::DUDivIMacro:
1961 Warning(IDLoc,
"dividing zero by zero");
1963 Warning(IDLoc,
"division by zero");
1975 case Mips::SDivMacro:
1976 case Mips::DSDivMacro:
1977 case Mips::UDivMacro:
1978 case Mips::DUDivMacro:
1983 case Mips::DIVU_MMR6:
1984 case Mips::DDIVU_MM64R6:
1985 case Mips::DIV_MMR6:
1986 case Mips::DDIV_MM64R6:
1991 Warning(IDLoc,
"dividing zero by zero");
1993 Warning(IDLoc,
"division by zero");
2002 BInst.
setOpcode(inMicroMipsMode() ? Mips::BEQ_MM : Mips::BEQ);
2013 warnIfNoMacro(IDLoc);
2020 return Error(IDLoc,
"jal doesn't support multiple symbols in PIC mode");
2038 const MCExpr *Got16RelocExpr =
2040 const MCExpr *Lo16RelocExpr =
2043 TOut.
emitRRX(Mips::LW, Mips::T9, Mips::GP,
2045 TOut.
emitRRX(Mips::ADDiu, Mips::T9, Mips::T9,
2047 }
else if (isABI_N32() || isABI_N64()) {
2053 const MCExpr *GotDispRelocExpr =
2065 const MCExpr *Call16RelocExpr =
2068 TOut.
emitRRX(ABI.ArePtrs64bit() ?
Mips::LD : Mips::LW, Mips::T9, Mips::GP,
2073 if (IsCpRestoreSet && inMicroMipsMode())
2076 JalrInst.
setOpcode(inMicroMipsMode() ? Mips::JALR_MM : Mips::JALR);
2085 ExpandedJalSym =
true;
2098 int MemOffset = Op.
getImm();
2099 if (MemOffset < -32768 || MemOffset > 32767) {
2101 expandMemInst(Inst, IDLoc, Out, STI, MCID.
mayLoad(),
true);
2102 return getParser().hasPendingError();
2104 }
else if (Op.
isExpr()) {
2111 expandMemInst(Inst, IDLoc, Out, STI, MCID.
mayLoad(),
false);
2112 return getParser().hasPendingError();
2114 }
else if (!isEvaluated(Expr)) {
2115 expandMemInst(Inst, IDLoc, Out, STI, MCID.
mayLoad(),
false);
2116 return getParser().hasPendingError();
2123 if (inMicroMipsMode()) {
2132 int MemOffset = Op.
getImm();
2135 if (isInt<9>(MemOffset) && (MemOffset % 4 == 0) &&
2138 (BaseReg.
getReg() == Mips::GP ||
2139 BaseReg.
getReg() == Mips::GP_64)) {
2141 TOut.
emitRRI(Mips::LWGP_MM, DstReg.
getReg(), Mips::GP, MemOffset,
2158 case Mips::ADDIUSP_MM:
2161 return Error(IDLoc,
"expected immediate operand kind");
2163 if (Imm < -1032 || Imm > 1028 || (Imm < 8 && Imm > -12) ||
2165 return Error(IDLoc,
"immediate operand value out of range");
2167 case Mips::SLL16_MM:
2168 case Mips::SRL16_MM:
2171 return Error(IDLoc,
"expected immediate operand kind");
2173 if (Imm < 1 || Imm > 8)
2174 return Error(IDLoc,
"immediate operand value out of range");
2179 return Error(IDLoc,
"expected immediate operand kind");
2181 if (Imm < -1 || Imm > 126)
2182 return Error(IDLoc,
"immediate operand value out of range");
2184 case Mips::ADDIUR2_MM:
2187 return Error(IDLoc,
"expected immediate operand kind");
2189 if (!(Imm == 1 || Imm == -1 ||
2190 ((Imm % 4 == 0) && Imm < 28 && Imm > 0)))
2191 return Error(IDLoc,
"immediate operand value out of range");
2193 case Mips::ANDI16_MM:
2196 return Error(IDLoc,
"expected immediate operand kind");
2198 if (!(Imm == 128 || (Imm >= 1 && Imm <= 4) || Imm == 7 || Imm == 8 ||
2199 Imm == 15 || Imm == 16 || Imm == 31 || Imm == 32 || Imm == 63 ||
2200 Imm == 64 || Imm == 255 || Imm == 32768 || Imm == 65535))
2201 return Error(IDLoc,
"immediate operand value out of range");
2203 case Mips::LBU16_MM:
2206 return Error(IDLoc,
"expected immediate operand kind");
2208 if (Imm < -1 || Imm > 14)
2209 return Error(IDLoc,
"immediate operand value out of range");
2212 case Mips::SB16_MMR6:
2215 return Error(IDLoc,
"expected immediate operand kind");
2217 if (Imm < 0 || Imm > 15)
2218 return Error(IDLoc,
"immediate operand value out of range");
2220 case Mips::LHU16_MM:
2222 case Mips::SH16_MMR6:
2225 return Error(IDLoc,
"expected immediate operand kind");
2227 if (Imm < 0 || Imm > 30 || (Imm % 2 != 0))
2228 return Error(IDLoc,
"immediate operand value out of range");
2232 case Mips::SW16_MMR6:
2235 return Error(IDLoc,
"expected immediate operand kind");
2237 if (Imm < 0 || Imm > 60 || (Imm % 4 != 0))
2238 return Error(IDLoc,
"immediate operand value out of range");
2240 case Mips::ADDIUPC_MM:
2243 return Error(IDLoc,
"expected immediate operand kind");
2245 if ((Imm % 4 != 0) || !isInt<25>(Imm))
2246 return Error(IDLoc,
"immediate operand value out of range");
2251 bool FillDelaySlot =
2252 MCID.
hasDelaySlot() && AssemblerOptions.back()->isReorder();
2256 MacroExpanderResultTy ExpandResult =
2257 tryExpandInstruction(Inst, IDLoc, Out, STI);
2258 switch (ExpandResult) {
2270 if (inMicroMipsMode())
2275 if (FillDelaySlot) {
2280 if ((Inst.
getOpcode() == Mips::JalOneReg ||
2281 Inst.
getOpcode() == Mips::JalTwoReg || ExpandedJalSym) &&
2282 isPicAndNotNxxAbi()) {
2283 if (IsCpRestoreSet) {
2287 if (!AssemblerOptions.back()->isReorder())
2294 Warning(IDLoc,
"no .cprestore used in PIC mode");
2300 MipsAsmParser::MacroExpanderResultTy
2305 return MER_NotAMacro;
2306 case Mips::LoadImm32:
2307 return expandLoadImm(Inst,
true, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2308 case Mips::LoadImm64:
2309 return expandLoadImm(Inst,
false, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2310 case Mips::LoadAddrImm32:
2311 case Mips::LoadAddrImm64:
2314 "expected immediate operand kind");
2318 Inst.
getOpcode() == Mips::LoadAddrImm32, IDLoc,
2322 case Mips::LoadAddrReg32:
2323 case Mips::LoadAddrReg64:
2327 "expected immediate operand kind");
2331 Inst.
getOpcode() == Mips::LoadAddrReg32, IDLoc,
2335 case Mips::B_MM_Pseudo:
2336 case Mips::B_MMR6_Pseudo:
2337 return expandUncondBranchMMPseudo(Inst, IDLoc, Out, STI) ? MER_Fail
2341 return expandLoadStoreMultiple(Inst, IDLoc, Out, STI) ? MER_Fail
2343 case Mips::JalOneReg:
2344 case Mips::JalTwoReg:
2345 return expandJalWithRegs(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2348 case Mips::BEQLImmMacro:
2349 case Mips::BNELImmMacro:
2350 return expandBranchImm(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2367 case Mips::BLTImmMacro:
2368 case Mips::BLEImmMacro:
2369 case Mips::BGEImmMacro:
2370 case Mips::BGTImmMacro:
2371 case Mips::BLTUImmMacro:
2372 case Mips::BLEUImmMacro:
2373 case Mips::BGEUImmMacro:
2374 case Mips::BGTUImmMacro:
2375 case Mips::BLTLImmMacro:
2376 case Mips::BLELImmMacro:
2377 case Mips::BGELImmMacro:
2378 case Mips::BGTLImmMacro:
2379 case Mips::BLTULImmMacro:
2380 case Mips::BLEULImmMacro:
2381 case Mips::BGEULImmMacro:
2382 case Mips::BGTULImmMacro:
2383 return expandCondBranches(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2384 case Mips::SDivMacro:
2385 case Mips::SDivIMacro:
2386 return expandDiv(Inst, IDLoc, Out, STI,
false,
true) ? MER_Fail
2388 case Mips::DSDivMacro:
2389 case Mips::DSDivIMacro:
2390 return expandDiv(Inst, IDLoc, Out, STI,
true,
true) ? MER_Fail
2392 case Mips::UDivMacro:
2393 case Mips::UDivIMacro:
2394 return expandDiv(Inst, IDLoc, Out, STI,
false,
false) ? MER_Fail
2396 case Mips::DUDivMacro:
2397 case Mips::DUDivIMacro:
2398 return expandDiv(Inst, IDLoc, Out, STI,
true,
false) ? MER_Fail
2400 case Mips::PseudoTRUNC_W_S:
2401 return expandTrunc(Inst,
false,
false, IDLoc, Out, STI) ? MER_Fail
2403 case Mips::PseudoTRUNC_W_D32:
2404 return expandTrunc(Inst,
true,
false, IDLoc, Out, STI) ? MER_Fail
2406 case Mips::PseudoTRUNC_W_D:
2407 return expandTrunc(Inst,
true,
true, IDLoc, Out, STI) ? MER_Fail
2410 case Mips::LoadImmSingleGPR:
2411 return expandLoadImmReal(Inst,
true,
true,
false, IDLoc, Out, STI)
2414 case Mips::LoadImmSingleFGR:
2415 return expandLoadImmReal(Inst,
true,
false,
false, IDLoc, Out, STI)
2418 case Mips::LoadImmDoubleGPR:
2419 return expandLoadImmReal(Inst,
false,
true,
false, IDLoc, Out, STI)
2422 case Mips::LoadImmDoubleFGR:
2423 return expandLoadImmReal(Inst,
false,
false,
true, IDLoc, Out, STI)
2426 case Mips::LoadImmDoubleFGR_32:
2427 return expandLoadImmReal(Inst,
false,
false,
false, IDLoc, Out, STI)
2431 return expandUlh(Inst,
true, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2433 return expandUlh(Inst,
false, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2435 return expandUsh(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2438 return expandUxw(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2440 case Mips::NORImm64:
2441 return expandAliasImmediate(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2442 case Mips::SLTImm64:
2445 return MER_NotAMacro;
2447 return expandAliasImmediate(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2448 case Mips::SLTUImm64:
2451 return MER_NotAMacro;
2453 return expandAliasImmediate(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2454 case Mips::ADDi:
case Mips::ADDi_MM:
2455 case Mips::ADDiu:
case Mips::ADDiu_MM:
2456 case Mips::SLTi:
case Mips::SLTi_MM:
2457 case Mips::SLTiu:
case Mips::SLTiu_MM:
2462 return MER_NotAMacro;
2463 return expandAliasImmediate(Inst, IDLoc, Out, STI) ? MER_Fail
2466 return MER_NotAMacro;
2467 case Mips::ANDi:
case Mips::ANDi_MM:
case Mips::ANDi64:
2468 case Mips::ORi:
case Mips::ORi_MM:
case Mips::ORi64:
2469 case Mips::XORi:
case Mips::XORi_MM:
case Mips::XORi64:
2474 return MER_NotAMacro;
2475 return expandAliasImmediate(Inst, IDLoc, Out, STI) ? MER_Fail
2478 return MER_NotAMacro;
2481 return expandRotation(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2484 return expandRotationImm(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2487 return expandDRotation(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2490 return expandDRotationImm(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2491 case Mips::ABSMacro:
2492 return expandAbs(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2493 case Mips::MULImmMacro:
2494 case Mips::DMULImmMacro:
2495 return expandMulImm(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2496 case Mips::MULOMacro:
2497 case Mips::DMULOMacro:
2498 return expandMulO(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2499 case Mips::MULOUMacro:
2500 case Mips::DMULOUMacro:
2501 return expandMulOU(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2502 case Mips::DMULMacro:
2503 return expandDMULMacro(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2506 return expandLoadStoreDMacro(Inst, IDLoc, Out, STI,
2510 case Mips::SEQMacro:
2511 return expandSeq(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2512 case Mips::SEQIMacro:
2513 return expandSeqI(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2517 bool MipsAsmParser::expandJalWithRegs(
MCInst &Inst,
SMLoc IDLoc,
2526 const unsigned Opcode = Inst.
getOpcode();
2528 if (Opcode == Mips::JalOneReg) {
2530 if (IsCpRestoreSet && inMicroMipsMode()) {
2533 }
else if (inMicroMipsMode()) {
2534 JalrInst.
setOpcode(hasMips32r6() ? Mips::JALRC16_MMR6 : Mips::JALR16_MM);
2541 }
else if (Opcode == Mips::JalTwoReg) {
2543 if (IsCpRestoreSet && inMicroMipsMode())
2546 JalrInst.
setOpcode(inMicroMipsMode() ? Mips::JALR_MM : Mips::JALR);
2556 if (MCID.
hasDelaySlot() && AssemblerOptions.back()->isReorder())
2567 return (x == x >> BitNum << BitNum) && isUInt<N>(x >> BitNum);
2580 bool MipsAsmParser::loadImmediate(int64_t ImmValue,
unsigned DstReg,
2581 unsigned SrcReg,
bool Is32BitImm,
2586 if (!Is32BitImm && !isGP64bit()) {
2587 Error(IDLoc,
"instruction requires a 64-bit architecture");
2596 ImmValue = SignExtend64<32>(ImmValue);
2598 Error(IDLoc,
"instruction requires a 32-bit immediate");
2603 unsigned ZeroReg = IsAddress ? ABI.GetNullPtr() : ABI.GetZeroReg();
2604 unsigned AdduOp = !Is32BitImm ? Mips::DADDu : Mips::ADDu;
2606 bool UseSrcReg =
false;
2607 if (SrcReg != Mips::NoRegister)
2610 unsigned TmpReg = DstReg;
2612 getContext().getRegisterInfo()->isSuperOrSubRegisterEq(DstReg, SrcReg)) {
2615 unsigned ATReg = getATReg(IDLoc);
2628 if (IsAddress && !Is32BitImm) {
2629 TOut.
emitRRI(Mips::DADDiu, DstReg, SrcReg, ImmValue, IDLoc, STI);
2633 TOut.
emitRRI(Mips::ADDiu, DstReg, SrcReg, ImmValue, IDLoc, STI);
2638 unsigned TmpReg = DstReg;
2639 if (SrcReg == DstReg) {
2640 TmpReg = getATReg(IDLoc);
2645 TOut.
emitRRI(Mips::ORi, TmpReg, ZeroReg, ImmValue, IDLoc, STI);
2647 TOut.
emitRRR(ABI.GetPtrAdduOp(), DstReg, TmpReg, SrcReg, IDLoc, STI);
2652 warnIfNoMacro(IDLoc);
2654 uint16_t Bits31To16 = (ImmValue >> 16) & 0xffff;
2655 uint16_t Bits15To0 = ImmValue & 0xffff;
2656 if (!Is32BitImm && !
isInt<32>(ImmValue)) {
2659 if (ImmValue == 0xffffffff) {
2660 TOut.
emitRI(Mips::LUi, TmpReg, 0xffff, IDLoc, STI);
2661 TOut.
emitRRI(Mips::DSRL32, TmpReg, TmpReg, 0, IDLoc, STI);
2663 TOut.
emitRRR(AdduOp, DstReg, TmpReg, SrcReg, IDLoc, STI);
2669 TOut.
emitRRI(Mips::ORi, TmpReg, ZeroReg, Bits31To16, IDLoc, STI);
2670 TOut.
emitRRI(Mips::DSLL, TmpReg, TmpReg, 16, IDLoc, STI);
2672 TOut.
emitRRI(Mips::ORi, TmpReg, TmpReg, Bits15To0, IDLoc, STI);
2674 TOut.
emitRRR(AdduOp, DstReg, TmpReg, SrcReg, IDLoc, STI);
2678 TOut.
emitRI(Mips::LUi, TmpReg, Bits31To16, IDLoc, STI);
2680 TOut.
emitRRI(Mips::ORi, TmpReg, TmpReg, Bits15To0, IDLoc, STI);
2682 TOut.
emitRRR(AdduOp, DstReg, TmpReg, SrcReg, IDLoc, STI);
2686 if (isShiftedUIntAtAnyPosition<16>(ImmValue)) {
2688 Error(IDLoc,
"instruction requires a 32-bit immediate");
2695 unsigned LastSet =
findLastSet((uint64_t)ImmValue);
2696 unsigned ShiftAmount = FirstSet - (15 - (LastSet - FirstSet));
2697 uint16_t
Bits = (ImmValue >> ShiftAmount) & 0xffff;
2698 TOut.
emitRRI(Mips::ORi, TmpReg, ZeroReg, Bits, IDLoc, STI);
2699 TOut.
emitRRI(Mips::DSLL, TmpReg, TmpReg, ShiftAmount, IDLoc, STI);
2702 TOut.
emitRRR(AdduOp, DstReg, TmpReg, SrcReg, IDLoc, STI);
2707 warnIfNoMacro(IDLoc);
2714 if (loadImmediate(ImmValue >> 32, TmpReg, Mips::NoRegister,
true,
false,
2720 unsigned ShiftCarriedForwards = 16;
2721 for (
int BitNum = 16; BitNum >= 0; BitNum -= 16) {
2722 uint16_t ImmChunk = (ImmValue >> BitNum) & 0xffff;
2724 if (ImmChunk != 0) {
2725 TOut.
emitDSLL(TmpReg, TmpReg, ShiftCarriedForwards, IDLoc, STI);
2726 TOut.
emitRRI(Mips::ORi, TmpReg, TmpReg, ImmChunk, IDLoc, STI);
2727 ShiftCarriedForwards = 0;
2730 ShiftCarriedForwards += 16;
2732 ShiftCarriedForwards -= 16;
2735 if (ShiftCarriedForwards)
2736 TOut.
emitDSLL(TmpReg, TmpReg, ShiftCarriedForwards, IDLoc, STI);
2739 TOut.
emitRRR(AdduOp, DstReg, TmpReg, SrcReg, IDLoc, STI);
2744 bool MipsAsmParser::expandLoadImm(
MCInst &Inst,
bool Is32BitImm,
SMLoc IDLoc,
2747 assert(ImmOp.
isImm() &&
"expected immediate operand kind");
2749 assert(DstRegOp.isReg() &&
"expected register operand kind");
2751 if (loadImmediate(ImmOp.
getImm(), DstRegOp.getReg(), Mips::NoRegister,
2752 Is32BitImm,
false, IDLoc, Out, STI))
2758 bool MipsAsmParser::expandLoadAddress(
unsigned DstReg,
unsigned BaseReg,
2760 bool Is32BitAddress,
SMLoc IDLoc,
2764 if (Is32BitAddress && ABI.ArePtrs64bit()) {
2768 Error(IDLoc,
"la used to load 64-bit address");
2770 Is32BitAddress =
false;
2775 if (!Is32BitAddress && !hasMips3()) {
2776 Error(IDLoc,
"instruction requires a 64-bit architecture");
2780 if (!Offset.
isImm())
2781 return loadAndAddSymbolAddress(Offset.
getExpr(), DstReg, BaseReg,
2782 Is32BitAddress, IDLoc, Out, STI);
2784 if (!ABI.ArePtrs64bit()) {
2786 Is32BitAddress =
true;
2789 return loadImmediate(Offset.
getImm(), DstReg, BaseReg, Is32BitAddress,
true,
2793 bool MipsAsmParser::loadAndAddSymbolAddress(
const MCExpr *SymExpr,
2794 unsigned DstReg,
unsigned SrcReg,
2795 bool Is32BitSym,
SMLoc IDLoc,
2800 bool UseSrcReg = SrcReg != Mips::NoRegister;
2801 warnIfNoMacro(IDLoc);
2803 if (inPicMode() && ABI.IsO32()) {
2806 Error(IDLoc,
"expected relocatable expression");
2809 if (Res.
getSymB() !=
nullptr) {
2810 Error(IDLoc,
"expected relocatable expression with only one symbol");
2817 if ((DstReg == Mips::T9 || DstReg == Mips::T9_64) && !UseSrcReg &&
2826 TOut.
emitRRX(Mips::LW, DstReg, ABI.GetGlobalPtr(),
2843 const MCExpr *LoExpr =
nullptr;
2854 unsigned TmpReg = DstReg;
2856 getContext().getRegisterInfo()->isSuperOrSubRegisterEq(DstReg,
2860 unsigned ATReg = getATReg(IDLoc);
2866 TOut.
emitRRX(Mips::LW, TmpReg, ABI.GetGlobalPtr(),
2874 TOut.
emitRRR(Mips::ADDu, DstReg, TmpReg, SrcReg, IDLoc, STI);
2879 if (inPicMode() && ABI.ArePtrs64bit()) {
2882 Error(IDLoc,
"expected relocatable expression");
2885 if (Res.
getSymB() !=
nullptr) {
2886 Error(IDLoc,
"expected relocatable expression with only one symbol");
2893 if ((DstReg == Mips::T9 || DstReg == Mips::T9_64) && !UseSrcReg &&
2917 const MCExpr *LoExpr =
nullptr;
2927 Error(IDLoc,
"macro instruction uses large offset, which is not "
2928 "currently supported");
2933 unsigned TmpReg = DstReg;
2935 getContext().getRegisterInfo()->isSuperOrSubRegisterEq(DstReg,
2939 unsigned ATReg = getATReg(IDLoc);
2953 TOut.
emitRRR(Mips::DADDu, DstReg, TmpReg, SrcReg, IDLoc, STI);
2964 if (ABI.ArePtrs64bit() && isGP64bit()) {
2978 getContext().getRegisterInfo()->isSuperOrSubRegisterEq(DstReg, SrcReg);
2980 if (canUseATReg() && UseSrcReg && RdRegIsRsReg) {
2981 unsigned ATReg = getATReg(IDLoc);
2993 TOut.
emitRRX(Mips::DADDiu, ATReg, ATReg,
2995 TOut.
emitRRI(Mips::DSLL, ATReg, ATReg, 16, IDLoc, STI);
2998 TOut.
emitRRI(Mips::DSLL, ATReg, ATReg, 16, IDLoc, STI);
3001 TOut.
emitRRR(Mips::DADDu, DstReg, ATReg, SrcReg, IDLoc, STI);
3004 }
else if (canUseATReg() && !RdRegIsRsReg) {
3005 unsigned ATReg = getATReg(IDLoc);
3021 TOut.
emitRRX(Mips::DADDiu, DstReg, DstReg,
3025 TOut.
emitRRI(Mips::DSLL32, DstReg, DstReg, 0, IDLoc, STI);
3026 TOut.
emitRRR(Mips::DADDu, DstReg, DstReg, ATReg, IDLoc, STI);
3028 TOut.
emitRRR(Mips::DADDu, DstReg, DstReg, SrcReg, IDLoc, STI);
3031 }
else if (!canUseATReg() && !RdRegIsRsReg) {
3042 TOut.
emitRRX(Mips::DADDiu, DstReg, DstReg,
3044 TOut.
emitRRI(Mips::DSLL, DstReg, DstReg, 16, IDLoc, STI);
3045 TOut.
emitRRX(Mips::DADDiu, DstReg, DstReg,
3047 TOut.
emitRRI(Mips::DSLL, DstReg, DstReg, 16, IDLoc, STI);
3048 TOut.
emitRRX(Mips::DADDiu, DstReg, DstReg,
3051 TOut.
emitRRR(Mips::DADDu, DstReg, DstReg, SrcReg, IDLoc, STI);
3057 assert(SrcReg == DstReg && !canUseATReg() &&
3058 "Could have expanded dla but didn't?");
3059 reportParseError(IDLoc,
3060 "pseudo-instruction requires $at, which is not available");
3074 unsigned TmpReg = DstReg;
3076 getContext().getRegisterInfo()->isSuperOrSubRegisterEq(DstReg, SrcReg)) {
3079 unsigned ATReg = getATReg(IDLoc);
3090 TOut.
emitRRR(Mips::ADDu, DstReg, TmpReg, SrcReg, IDLoc, STI);
3093 getContext().getRegisterInfo()->isSuperOrSubRegisterEq(DstReg, TmpReg));
3102 if (MipsMCRegisterClasses[Mips::FGR32RegClassID].
contains(Reg))
3103 return Reg == (
unsigned)Mips::F31 ? (
unsigned)Mips::F0 : Reg + 1;
3105 default:
llvm_unreachable(
"Unknown register in assembly macro expansion!");
3106 case Mips::ZERO:
return Mips::AT;
3107 case Mips::AT:
return Mips::V0;
3108 case Mips::V0:
return Mips::V1;
3109 case Mips::V1:
return Mips::A0;
3110 case Mips::A0:
return Mips::A1;
3111 case Mips::A1:
return Mips::A2;
3112 case Mips::A2:
return Mips::A3;
3113 case Mips::A3:
return Mips::T0;
3116 case Mips::T2:
return Mips::T3;
3117 case Mips::T3:
return Mips::T4;
3118 case Mips::T4:
return Mips::T5;
3119 case Mips::T5:
return Mips::T6;
3120 case Mips::T6:
return Mips::T7;
3121 case Mips::T7:
return Mips::S0;
3122 case Mips::S0:
return Mips::S1;
3123 case Mips::S1:
return Mips::S2;
3124 case Mips::S2:
return Mips::S3;
3125 case Mips::S3:
return Mips::S4;
3126 case Mips::S4:
return Mips::S5;
3127 case Mips::S5:
return Mips::S6;
3128 case Mips::S6:
return Mips::S7;
3131 case Mips::T9:
return Mips::K0;
3132 case Mips::K0:
return Mips::K1;
3133 case Mips::K1:
return Mips::GP;
3134 case Mips::GP:
return Mips::SP;
3135 case Mips::SP:
return Mips::FP;
3136 case Mips::FP:
return Mips::RA;
3137 case Mips::RA:
return Mips::ZERO;
3138 case Mips::D0:
return Mips::F1;
3139 case Mips::D1:
return Mips::F3;
3140 case Mips::D2:
return Mips::F5;
3141 case Mips::D3:
return Mips::F7;
3142 case Mips::D4:
return Mips::F9;
3143 case Mips::D5:
return Mips::F11;
3144 case Mips::D6:
return Mips::F13;
3145 case Mips::D7:
return Mips::F15;
3146 case Mips::D8:
return Mips::F17;
3147 case Mips::D9:
return Mips::F19;
3148 case Mips::D10:
return Mips::F21;
3149 case Mips::D11:
return Mips::F23;
3150 case Mips::D12:
return Mips::F25;
3151 case Mips::D13:
return Mips::F27;
3152 case Mips::D14:
return Mips::F29;
3153 case Mips::D15:
return Mips::F31;
3165 unsigned ATReg = getATReg(IDLoc);
3175 if(isABI_O32() || isABI_N32()) {
3194 if(isABI_O32() || isABI_N32()) {
3197 const MCExpr *HighestSym =
3201 const MCExpr *HigherSym =
3208 TOut.
emitRRX(Mips::DADDiu, ATReg, ATReg,
3210 TOut.
emitRRI(Mips::DSLL, ATReg, ATReg, 16, IDLoc, STI);
3213 TOut.
emitRRI(Mips::DSLL, ATReg, ATReg, 16, IDLoc, STI);
3219 bool MipsAsmParser::expandLoadImmReal(
MCInst &Inst,
bool IsSingle,
bool IsGPR,
3220 bool Is64FPU,
SMLoc IDLoc,
3226 "Invalid instruction operand.");
3231 uint32_t HiImmOp64 = (ImmOp64 & 0xffffffff00000000) >> 32;
3234 if ((HiImmOp64 & 0x7ff00000) == 0) {
3236 ImmOp64 = RealVal.bitcastToAPInt().getZExtValue();
3239 uint32_t LoImmOp64 = ImmOp64 & 0xffffffff;
3240 HiImmOp64 = (ImmOp64 & 0xffffffff00000000) >> 32;
3247 float tmp_float =
static_cast<float>(doubleImm);
3251 if (loadImmediate(ImmOp32, FirstReg, Mips::NoRegister,
true,
true, IDLoc,
3256 unsigned ATReg = getATReg(IDLoc);
3259 if (LoImmOp64 == 0) {
3260 if (loadImmediate(ImmOp32, ATReg, Mips::NoRegister,
true,
true, IDLoc,
3263 TOut.
emitRR(Mips::MTC1, FirstReg, ATReg, IDLoc, STI);
3267 MCSection *
CS = getStreamer().getCurrentSectionOnly();
3270 MCSection *ReadOnlySection = getContext().getELFSection(
3273 MCSymbol *Sym = getContext().createTempSymbol();
3279 getStreamer().SwitchSection(ReadOnlySection);
3280 getStreamer().EmitLabel(Sym, IDLoc);
3281 getStreamer().EmitIntValue(ImmOp32, 4);
3282 getStreamer().SwitchSection(CS);
3284 if(emitPartialAddress(TOut, IDLoc, Sym))
3286 TOut.
emitRRX(Mips::LWC1, FirstReg, ATReg,
3293 unsigned ATReg = getATReg(IDLoc);
3298 if (LoImmOp64 == 0) {
3299 if(isABI_N32() || isABI_N64()) {
3300 if (loadImmediate(HiImmOp64, FirstReg, Mips::NoRegister,
false,
true,
3305 if (loadImmediate(HiImmOp64, FirstReg, Mips::NoRegister,
true,
true,
3309 if (loadImmediate(0,
nextReg(FirstReg), Mips::NoRegister,
true,
true,
3316 MCSection *CS = getStreamer().getCurrentSectionOnly();
3317 MCSection *ReadOnlySection = getContext().getELFSection(
3320 MCSymbol *Sym = getContext().createTempSymbol();
3326 getStreamer().SwitchSection(ReadOnlySection);
3327 getStreamer().EmitLabel(Sym, IDLoc);
3328 getStreamer().EmitIntValue(HiImmOp64, 4);
3329 getStreamer().EmitIntValue(LoImmOp64, 4);
3330 getStreamer().SwitchSection(CS);
3332 if(emitPartialAddress(TOut, IDLoc, Sym))
3335 TOut.
emitRRX(Mips::DADDiu, ATReg, ATReg,
3338 TOut.
emitRRX(Mips::ADDiu, ATReg, ATReg,
3341 if(isABI_N32() || isABI_N64())
3344 TOut.
emitRRI(Mips::LW, FirstReg, ATReg, 0, IDLoc, STI);
3349 if ((LoImmOp64 == 0) &&
3350 !((HiImmOp64 & 0xffff0000) && (HiImmOp64 & 0x0000ffff))) {
3353 if (loadImmediate(HiImmOp64, ATReg, Mips::NoRegister,
true,
true, IDLoc,
3356 if (isABI_N32() || isABI_N64())
3357 TOut.
emitRR(Mips::DMTC1, FirstReg, ATReg, IDLoc, STI);
3358 else if (hasMips32r2()) {
3359 TOut.
emitRR(Mips::MTC1, FirstReg, Mips::ZERO, IDLoc, STI);
3360 TOut.
emitRRR(Mips::MTHC1_D32, FirstReg, FirstReg, ATReg, IDLoc, STI);
3362 TOut.
emitRR(Mips::MTC1,
nextReg(FirstReg), ATReg, IDLoc, STI);
3363 TOut.
emitRR(Mips::MTC1, FirstReg, Mips::ZERO, IDLoc, STI);
3368 MCSection *CS = getStreamer().getCurrentSectionOnly();
3371 MCSection *ReadOnlySection = getContext().getELFSection(
3374 MCSymbol *Sym = getContext().createTempSymbol();
3380 getStreamer().SwitchSection(ReadOnlySection);
3381 getStreamer().EmitLabel(Sym, IDLoc);
3382 getStreamer().EmitIntValue(HiImmOp64, 4);
3383 getStreamer().EmitIntValue(LoImmOp64, 4);
3384 getStreamer().SwitchSection(CS);
3386 if(emitPartialAddress(TOut, IDLoc, Sym))
3388 TOut.
emitRRX(Is64FPU ? Mips::LDC164 : Mips::LDC1, FirstReg, ATReg,
3394 bool MipsAsmParser::expandUncondBranchMMPseudo(
MCInst &Inst,
SMLoc IDLoc,
3400 "unexpected number of operands");
3403 if (Offset.isExpr()) {
3410 assert(Offset.isImm() &&
"expected immediate operand kind");
3411 if (isInt<11>(Offset.getImm())) {
3414 if (inMicroMipsMode())
3415 Inst.
setOpcode(hasMips32r6() ? Mips::BC16_MMR6 : Mips::B16_MM);
3417 if (!isInt<17>(Offset.getImm()))
3418 return Error(IDLoc,
"branch target out of range");
3420 return Error(IDLoc,
"branch to misaligned address");
3433 if (MCID.
hasDelaySlot() && AssemblerOptions.back()->isReorder())
3443 assert(DstRegOp.
isReg() &&
"expected register operand kind");
3446 assert(ImmOp.isImm() &&
"expected immediate operand kind");
3449 assert((MemOffsetOp.isImm() || MemOffsetOp.isExpr()) &&
3450 "expected immediate or expression operand");
3452 bool IsLikely =
false;
3454 unsigned OpCode = 0;
3462 case Mips::BEQLImmMacro:
3463 OpCode = Mips::BEQL;
3466 case Mips::BNELImmMacro:
3467 OpCode = Mips::BNEL;
3475 int64_t ImmValue = ImmOp.getImm();
3476 if (ImmValue == 0) {
3480 TOut.
emitRRI(Mips::SLL, Mips::ZERO, Mips::ZERO, 0, IDLoc, STI);
3482 TOut.
emitRRX(OpCode, DstRegOp.
getReg(), Mips::ZERO, MemOffsetOp, IDLoc,
3485 warnIfNoMacro(IDLoc);
3487 unsigned ATReg = getATReg(IDLoc);
3491 if (loadImmediate(ImmValue, ATReg, Mips::NoRegister, !isGP64bit(),
true,
3498 TOut.
emitRRI(Mips::SLL, Mips::ZERO, Mips::ZERO, 0, IDLoc, STI);
3500 TOut.
emitRRX(OpCode, DstRegOp.
getReg(), ATReg, MemOffsetOp, IDLoc, STI);
3509 expandLoadInst(Inst, IDLoc, Out, STI, IsImmOpnd);
3512 expandStoreInst(Inst, IDLoc, Out, STI, IsImmOpnd);
3524 unsigned DstRegClassID =
3525 getContext().getRegisterInfo()->getRegClass(DstRegClass).getID();
3526 bool IsGPR = (DstRegClassID == Mips::GPR32RegClassID) ||
3527 (DstRegClassID == Mips::GPR64RegClassID);
3531 if (IsGPR && (BaseReg != DstReg)) {
3540 unsigned ATReg = getATReg(IDLoc);
3556 if (IsGPR && (BaseReg != DstReg)) {
3558 LoOperand, DstReg, IDLoc, STI);
3564 unsigned ATReg = getATReg(IDLoc);
3569 LoOperand, ATReg, IDLoc, STI);
3583 [&]() {
return getATReg(IDLoc); }, IDLoc, STI);
3587 unsigned ATReg = getATReg(IDLoc);
3597 LoOperand, ATReg, IDLoc, STI);
3600 bool MipsAsmParser::expandLoadStoreMultiple(
MCInst &Inst,
SMLoc IDLoc,
3605 unsigned NewOpcode = Opcode == Mips::SWM_MM ? Mips::SWM32_MM : Mips::LWM32_MM;
3609 Inst.
getOperand(OpNum - 3).
isReg() &&
"Invalid instruction operand.");
3618 if (inMicroMipsMode() && hasMips32r6())
3619 NewOpcode = Opcode == Mips::SWM_MM ? Mips::SWM16_MMR6 : Mips::LWM16_MMR6;
3621 NewOpcode = Opcode == Mips::SWM_MM ? Mips::SWM16_MM : Mips::LWM16_MM;
3629 bool MipsAsmParser::expandCondBranches(
MCInst &Inst,
SMLoc IDLoc,
3633 bool EmittedNoMacroWarning =
false;
3634 unsigned PseudoOpcode = Inst.
getOpcode();
3639 unsigned ZeroSrcOpcode, ZeroTrgOpcode;
3640 bool ReverseOrderSLT, IsUnsigned, IsLikely, AcceptsEquality;
3645 else if (TrgOp.
isImm()) {
3646 warnIfNoMacro(IDLoc);
3647 EmittedNoMacroWarning =
true;
3649 TrgReg = getATReg(IDLoc);
3653 switch(PseudoOpcode) {
3656 case Mips::BLTImmMacro:
3657 PseudoOpcode = Mips::BLT;
3659 case Mips::BLEImmMacro:
3660 PseudoOpcode = Mips::BLE;
3662 case Mips::BGEImmMacro:
3663 PseudoOpcode = Mips::BGE;
3665 case Mips::BGTImmMacro:
3666 PseudoOpcode = Mips::BGT;
3668 case Mips::BLTUImmMacro:
3669 PseudoOpcode = Mips::BLTU;
3671 case Mips::BLEUImmMacro:
3672 PseudoOpcode = Mips::BLEU;
3674 case Mips::BGEUImmMacro:
3675 PseudoOpcode = Mips::BGEU;
3677 case Mips::BGTUImmMacro:
3678 PseudoOpcode = Mips::BGTU;
3680 case Mips::BLTLImmMacro:
3681 PseudoOpcode = Mips::BLTL;
3683 case Mips::BLELImmMacro:
3684 PseudoOpcode = Mips::BLEL;
3686 case Mips::BGELImmMacro:
3687 PseudoOpcode = Mips::BGEL;
3689 case Mips::BGTLImmMacro:
3690 PseudoOpcode = Mips::BGTL;
3692 case Mips::BLTULImmMacro:
3693 PseudoOpcode = Mips::BLTUL;
3695 case Mips::BLEULImmMacro:
3696 PseudoOpcode = Mips::BLEUL;
3698 case Mips::BGEULImmMacro:
3699 PseudoOpcode = Mips::BGEUL;
3701 case Mips::BGTULImmMacro:
3702 PseudoOpcode = Mips::BGTUL;
3706 if (loadImmediate(TrgOp.
getImm(), TrgReg, Mips::NoRegister, !isGP64bit(),
3707 false, IDLoc, Out, STI))
3711 switch (PseudoOpcode) {
3716 AcceptsEquality =
false;
3717 ReverseOrderSLT =
false;
3718 IsUnsigned = ((PseudoOpcode == Mips::BLTU) || (PseudoOpcode == Mips::BLTUL));
3719 IsLikely = ((PseudoOpcode == Mips::BLTL) || (PseudoOpcode == Mips::BLTUL));
3720 ZeroSrcOpcode = Mips::BGTZ;
3721 ZeroTrgOpcode = Mips::BLTZ;
3727 AcceptsEquality =
true;
3728 ReverseOrderSLT =
true;
3729 IsUnsigned = ((PseudoOpcode == Mips::BLEU) || (PseudoOpcode == Mips::BLEUL));
3730 IsLikely = ((PseudoOpcode == Mips::BLEL) || (PseudoOpcode == Mips::BLEUL));
3731 ZeroSrcOpcode = Mips::BGEZ;
3732 ZeroTrgOpcode = Mips::BLEZ;
3738 AcceptsEquality =
true;
3739 ReverseOrderSLT =
false;
3740 IsUnsigned = ((PseudoOpcode == Mips::BGEU) || (PseudoOpcode == Mips::BGEUL));
3741 IsLikely = ((PseudoOpcode == Mips::BGEL) || (PseudoOpcode == Mips::BGEUL));
3742 ZeroSrcOpcode = Mips::BLEZ;
3743 ZeroTrgOpcode = Mips::BGEZ;
3749 AcceptsEquality =
false;
3750 ReverseOrderSLT =
true;
3751 IsUnsigned = ((PseudoOpcode == Mips::BGTU) || (PseudoOpcode == Mips::BGTUL));
3752 IsLikely = ((PseudoOpcode == Mips::BGTL) || (PseudoOpcode == Mips::BGTUL));
3753 ZeroSrcOpcode = Mips::BLTZ;
3754 ZeroTrgOpcode = Mips::BGTZ;
3760 bool IsTrgRegZero = (TrgReg == Mips::ZERO);
3761 bool IsSrcRegZero = (SrcReg == Mips::ZERO);
3762 if (IsSrcRegZero && IsTrgRegZero) {
3766 if (PseudoOpcode == Mips::BLT) {
3771 if (PseudoOpcode == Mips::BLE) {
3774 Warning(IDLoc,
"branch is always taken");
3777 if (PseudoOpcode == Mips::BGE) {
3780 Warning(IDLoc,
"branch is always taken");
3783 if (PseudoOpcode == Mips::BGT) {
3788 if (PseudoOpcode == Mips::BGTU) {
3789 TOut.
emitRRX(Mips::BNE, Mips::ZERO, Mips::ZERO,
3793 if (AcceptsEquality) {
3796 TOut.
emitRRX(Mips::BEQ, Mips::ZERO, Mips::ZERO,
3798 Warning(IDLoc,
"branch is always taken");
3805 if (IsSrcRegZero || IsTrgRegZero) {
3806 if ((IsSrcRegZero && PseudoOpcode == Mips::BGTU) ||
3807 (IsTrgRegZero && PseudoOpcode == Mips::BLTU)) {
3814 if ((IsSrcRegZero && PseudoOpcode == Mips::BLEU) ||
3815 (IsTrgRegZero && PseudoOpcode == Mips::BGEU)) {
3821 TOut.
emitRRX(Mips::BEQ, Mips::ZERO, Mips::ZERO,
3823 Warning(IDLoc,
"branch is always taken");
3839 TOut.
emitRRX(AcceptsEquality ? Mips::BEQ : Mips::BNE,
3840 IsSrcRegZero ? TrgReg : SrcReg, Mips::ZERO,
3847 TOut.
emitRX(IsSrcRegZero ? ZeroSrcOpcode : ZeroTrgOpcode,
3848 IsSrcRegZero ? TrgReg : SrcReg,
3855 unsigned ATRegNum = getATReg(IDLoc);
3859 if (!EmittedNoMacroWarning)
3860 warnIfNoMacro(IDLoc);
3877 TOut.
emitRRR(IsUnsigned ? Mips::SLTu : Mips::SLT, ATRegNum,
3878 ReverseOrderSLT ? TrgReg : SrcReg,
3879 ReverseOrderSLT ? SrcReg : TrgReg, IDLoc, STI);
3881 TOut.
emitRRX(IsLikely ? (AcceptsEquality ? Mips::BEQL : Mips::BNEL)
3882 : (AcceptsEquality ? Mips::BEQ : Mips::BNE),
3901 warnIfNoMacro(IDLoc);
3904 assert(RdRegOp.
isReg() &&
"expected register operand kind");
3905 unsigned RdReg = RdRegOp.
getReg();
3908 assert(RsRegOp.
isReg() &&
"expected register operand kind");
3909 unsigned RsReg = RsRegOp.
getReg();
3916 "expected register or immediate operand kind");
3920 ImmValue = RtOp.
getImm();
3927 DivOp = Signed ? Mips::DSDIV : Mips::DUDIV;
3928 ZeroReg = Mips::ZERO_64;
3932 ZeroReg = Mips::ZERO;
3936 bool UseTraps = useTraps();
3939 unsigned ATReg = getATReg(IDLoc);
3943 if (ImmValue == 0) {
3945 TOut.
emitRRI(Mips::TEQ, ZeroReg, ZeroReg, 0x7, IDLoc, STI);
3947 TOut.
emitII(Mips::BREAK, 0x7, 0, IDLoc, STI);
3951 if (ImmValue == 1) {
3954 }
else if (Signed && ImmValue == -1) {
3955 TOut.
emitRRR(SubOp, RdReg, ZeroReg, RsReg, IDLoc, STI);
3958 if (loadImmediate(ImmValue, ATReg, Mips::NoRegister,
isInt<32>(ImmValue),
3959 false, Inst.
getLoc(), Out, STI))
3961 TOut.
emitRR(DivOp, RsReg, ATReg, IDLoc, STI);
3972 if (RtReg == Mips::ZERO || RtReg == Mips::ZERO_64) {
3974 TOut.
emitRRI(Mips::TEQ, ZeroReg, ZeroReg, 0x7, IDLoc, STI);
3977 TOut.
emitII(Mips::BREAK, 0x7, 0, IDLoc, STI);
3987 TOut.
emitRRI(Mips::TEQ, RtReg, ZeroReg, 0x7, IDLoc, STI);
3992 TOut.
emitRRX(Mips::BNE, RtReg, ZeroReg, LabelOp, IDLoc, STI);
3995 TOut.
emitRR(DivOp, RsReg, RtReg, IDLoc, STI);
3998 TOut.
emitII(Mips::BREAK, 0x7, 0, IDLoc, STI);
4008 unsigned ATReg = getATReg(IDLoc);
4015 TOut.
emitRRI(Mips::ADDiu, ATReg, ZeroReg, -1, IDLoc, STI);
4023 TOut.
emitRRX(Mips::BNE, RtReg, ATReg, LabelOpEnd, IDLoc, STI);
4026 TOut.
emitRRI(Mips::ADDiu, ATReg, ZeroReg, 1, IDLoc, STI);
4027 TOut.
emitRRI(Mips::DSLL32, ATReg, ATReg, 0x1f, IDLoc, STI);
4029 TOut.
emitRI(Mips::LUi, ATReg, (uint16_t)0x8000, IDLoc, STI);
4033 TOut.
emitRRI(Mips::TEQ, RsReg, ATReg, 0x6, IDLoc, STI);
4036 TOut.
emitRRX(Mips::BNE, RsReg, ATReg, LabelOpEnd, IDLoc, STI);
4037 TOut.
emitRRI(Mips::SLL, ZeroReg, ZeroReg, 0, IDLoc, STI);
4038 TOut.
emitII(Mips::BREAK, 0x6, 0, IDLoc, STI);
4046 bool MipsAsmParser::expandTrunc(
MCInst &Inst,
bool IsDouble,
bool Is64FPU,
4059 if (hasMips1() && !hasMips2()) {
4060 unsigned ATReg = getATReg(IDLoc);
4063 TOut.
emitRR(Mips::CFC1, ThirdReg, Mips::RA, IDLoc, STI);
4064 TOut.
emitRR(Mips::CFC1, ThirdReg, Mips::RA, IDLoc, STI);
4066 TOut.
emitRRI(Mips::ORi, ATReg, ThirdReg, 0x3, IDLoc, STI);
4067 TOut.
emitRRI(Mips::XORi, ATReg, ATReg, 0x2, IDLoc, STI);
4068 TOut.
emitRR(Mips::CTC1, Mips::RA, ATReg, IDLoc, STI);
4070 TOut.
emitRR(IsDouble ? (Is64FPU ? Mips::CVT_W_D64 : Mips::CVT_W_D32)
4072 FirstReg, SecondReg, IDLoc, STI);
4073 TOut.
emitRR(Mips::CTC1, Mips::RA, ThirdReg, IDLoc, STI);
4078 TOut.
emitRR(IsDouble ? (Is64FPU ? Mips::TRUNC_W_D64 : Mips::TRUNC_W_D32)
4080 FirstReg, SecondReg, IDLoc, STI);
4085 bool MipsAsmParser::expandUlh(
MCInst &Inst,
bool Signed,
SMLoc IDLoc,
4087 if (hasMips32r6() || hasMips64r6()) {
4088 return Error(IDLoc,
"instruction not supported on mips32r6 or mips64r6");
4092 assert(DstRegOp.
isReg() &&
"expected register operand kind");
4094 assert(SrcRegOp.isReg() &&
"expected register operand kind");
4096 assert(OffsetImmOp.isImm() &&
"expected immediate operand kind");
4099 unsigned DstReg = DstRegOp.
getReg();
4100 unsigned SrcReg = SrcRegOp.getReg();
4101 int64_t OffsetValue = OffsetImmOp.getImm();
4105 warnIfNoMacro(IDLoc);
4106 unsigned ATReg = getATReg(IDLoc);
4111 if (IsLargeOffset) {
4112 if (loadImmediate(OffsetValue, ATReg, SrcReg, !ABI.ArePtrs64bit(),
true,
4117 int64_t FirstOffset = IsLargeOffset ? 0 : OffsetValue;
4118 int64_t SecondOffset = IsLargeOffset ? 1 : (OffsetValue + 1);
4122 unsigned FirstLbuDstReg = IsLargeOffset ? DstReg : ATReg;
4123 unsigned SecondLbuDstReg = IsLargeOffset ? ATReg : DstReg;
4125 unsigned LbuSrcReg = IsLargeOffset ? ATReg : SrcReg;
4126 unsigned SllReg = IsLargeOffset ? DstReg : ATReg;
4128 TOut.emitRRI(Signed ? Mips::LB : Mips::LBu, FirstLbuDstReg, LbuSrcReg,
4129 FirstOffset, IDLoc, STI);
4130 TOut.emitRRI(Mips::LBu, SecondLbuDstReg, LbuSrcReg, SecondOffset, IDLoc, STI);
4131 TOut.emitRRI(Mips::SLL, SllReg, SllReg, 8, IDLoc, STI);
4132 TOut.emitRRR(
Mips::OR, DstReg, DstReg, ATReg, IDLoc, STI);
4139 if (hasMips32r6() || hasMips64r6()) {
4140 return Error(IDLoc,
"instruction not supported on mips32r6 or mips64r6");
4144 assert(DstRegOp.
isReg() &&
"expected register operand kind");
4146 assert(SrcRegOp.isReg() &&
"expected register operand kind");
4148 assert(OffsetImmOp.isImm() &&
"expected immediate operand kind");
4151 unsigned DstReg = DstRegOp.
getReg();
4152 unsigned SrcReg = SrcRegOp.getReg();
4153 int64_t OffsetValue = OffsetImmOp.getImm();
4155 warnIfNoMacro(IDLoc);
4156 unsigned ATReg = getATReg(IDLoc);
4161 if (IsLargeOffset) {
4162 if (loadImmediate(OffsetValue, ATReg, SrcReg, !ABI.ArePtrs64bit(),
true,
4167 int64_t FirstOffset = IsLargeOffset ? 1 : (OffsetValue + 1);
4168 int64_t SecondOffset = IsLargeOffset ? 0 : OffsetValue;
4172 if (IsLargeOffset) {
4173 TOut.emitRRI(
Mips::SB, DstReg, ATReg, FirstOffset, IDLoc, STI);
4174 TOut.emitRRI(
Mips::SRL, DstReg, DstReg, 8, IDLoc, STI);
4175 TOut.emitRRI(
Mips::SB, DstReg, ATReg, SecondOffset, IDLoc, STI);
4176 TOut.emitRRI(Mips::LBu, ATReg, ATReg, 0, IDLoc, STI);
4177 TOut.emitRRI(Mips::SLL, DstReg, DstReg, 8, IDLoc, STI);
4178 TOut.emitRRR(
Mips::OR, DstReg, DstReg, ATReg, IDLoc, STI);
4180 TOut.emitRRI(
Mips::SB, DstReg, SrcReg, FirstOffset, IDLoc, STI);
4181 TOut.emitRRI(
Mips::SRL, ATReg, DstReg, 8, IDLoc, STI);
4182 TOut.emitRRI(
Mips::SB, ATReg, SrcReg, SecondOffset, IDLoc, STI);
4190 if (hasMips32r6() || hasMips64r6()) {
4191 return Error(IDLoc,
"instruction not supported on mips32r6 or mips64r6");
4195 assert(DstRegOp.
isReg() &&
"expected register operand kind");
4197 assert(SrcRegOp.isReg() &&
"expected register operand kind");
4199 assert(OffsetImmOp.isImm() &&
"expected immediate operand kind");
4202 unsigned DstReg = DstRegOp.
getReg();
4203 unsigned SrcReg = SrcRegOp.getReg();
4204 int64_t OffsetValue = OffsetImmOp.getImm();
4208 int64_t LxlOffset = IsLargeOffset ? 0 : OffsetValue;
4209 int64_t LxrOffset = IsLargeOffset ? 3 : (OffsetValue + 3);
4213 bool IsLoadInst = (Inst.
getOpcode() == Mips::Ulw);
4214 bool DoMove = IsLoadInst && (SrcReg == DstReg) && !IsLargeOffset;
4215 unsigned TmpReg = SrcReg;
4216 if (IsLargeOffset || DoMove) {
4217 warnIfNoMacro(IDLoc);
4218 TmpReg = getATReg(IDLoc);
4223 if (IsLargeOffset) {
4224 if (loadImmediate(OffsetValue, TmpReg, SrcReg, !ABI.ArePtrs64bit(),
true,
4234 TOut.emitRRI(XWL, DstReg, TmpReg, LxlOffset, IDLoc, STI);
4235 TOut.emitRRI(XWR, DstReg, TmpReg, LxrOffset, IDLoc, STI);
4238 TOut.emitRRR(
Mips::OR, TmpReg, DstReg, Mips::ZERO, IDLoc, STI);
4243 bool MipsAsmParser::expandAliasImmediate(
MCInst &Inst,
SMLoc IDLoc,
4253 unsigned ATReg = Mips::NoRegister;
4254 unsigned FinalDstReg = Mips::NoRegister;
4261 unsigned FinalOpcode = Inst.
getOpcode();
4263 if (DstReg == SrcReg) {
4264 ATReg = getATReg(Inst.
getLoc());
4267 FinalDstReg = DstReg;
4271 if (!loadImmediate(ImmValue, DstReg, Mips::NoRegister, Is32Bit,
false, Inst.
getLoc(), Out, STI)) {
4272 switch (FinalOpcode) {
4279 FinalOpcode = Mips::ADDu;
4285 FinalOpcode = Mips::NOR;
4291 FinalOpcode = Mips::SLT;
4294 FinalOpcode = Mips::SLTu;
4300 FinalOpcode = Mips::ADD_MM;
4302 case Mips::ADDiu_MM:
4303 FinalOpcode = Mips::ADDu_MM;
4306 FinalOpcode = Mips::AND_MM;
4309 FinalOpcode = Mips::OR_MM;
4312 FinalOpcode = Mips::SLT_MM;
4314 case Mips::SLTiu_MM:
4315 FinalOpcode = Mips::SLTu_MM;
4318 FinalOpcode = Mips::XOR_MM;
4321 FinalOpcode = Mips::AND64;
4323 case Mips::NORImm64:
4324 FinalOpcode = Mips::NOR64;
4327 FinalOpcode = Mips::OR64;
4329 case Mips::SLTImm64:
4330 FinalOpcode = Mips::SLT64;
4332 case Mips::SLTUImm64:
4333 FinalOpcode = Mips::SLTu64;
4336 FinalOpcode = Mips::XOR64;
4340 if (FinalDstReg == Mips::NoRegister)
4341 TOut.
emitRRR(FinalOpcode, DstReg, DstReg, SrcReg, IDLoc, STI);
4343 TOut.
emitRRR(FinalOpcode, FinalDstReg, FinalDstReg, DstReg, IDLoc, STI);
4352 unsigned ATReg = Mips::NoRegister;
4356 unsigned TmpReg = DReg;
4358 unsigned FirstShift = Mips::NOP;
4359 unsigned SecondShift = Mips::NOP;
4361 if (hasMips32r2()) {
4363 TmpReg = getATReg(Inst.
getLoc());
4369 TOut.
emitRRR(Mips::SUBu, TmpReg, Mips::ZERO, TReg, Inst.
getLoc(), STI);
4370 TOut.
emitRRR(Mips::ROTRV, DReg, SReg, TmpReg, Inst.
getLoc(), STI);
4375 TOut.
emitRRR(Mips::ROTRV, DReg, SReg, TReg, Inst.
getLoc(), STI);
4387 FirstShift = Mips::SRLV;
4388 SecondShift = Mips::SLLV;
4391 FirstShift = Mips::SLLV;
4392 SecondShift = Mips::SRLV;
4396 ATReg = getATReg(Inst.
getLoc());
4400 TOut.
emitRRR(Mips::SUBu, ATReg, Mips::ZERO, TReg, Inst.
getLoc(), STI);
4401 TOut.
emitRRR(FirstShift, ATReg, SReg, ATReg, Inst.
getLoc(), STI);
4402 TOut.
emitRRR(SecondShift, DReg, SReg, TReg, Inst.
getLoc(), STI);
4411 bool MipsAsmParser::expandRotationImm(
MCInst &Inst,
SMLoc IDLoc,
4415 unsigned ATReg = Mips::NoRegister;
4420 unsigned FirstShift = Mips::NOP;
4421 unsigned SecondShift = Mips::NOP;
4423 if (hasMips32r2()) {
4425 uint64_t MaxShift = 32;
4426 uint64_t ShiftValue = ImmValue;
4428 ShiftValue = MaxShift - ImmValue;
4442 if (ImmValue == 0) {
4451 FirstShift = Mips::SLL;
4456 SecondShift = Mips::SLL;
4460 ATReg = getATReg(Inst.
getLoc());
4464 TOut.
emitRRI(FirstShift, ATReg, SReg, ImmValue, Inst.
getLoc(), STI);
4465 TOut.
emitRRI(SecondShift, DReg, SReg, 32 - ImmValue, Inst.
getLoc(), STI);
4477 unsigned ATReg = Mips::NoRegister;
4481 unsigned TmpReg = DReg;
4483 unsigned FirstShift = Mips::NOP;
4484 unsigned SecondShift = Mips::NOP;
4486 if (hasMips64r2()) {
4487 if (TmpReg == SReg) {
4488 TmpReg = getATReg(Inst.
getLoc());
4494 TOut.
emitRRR(Mips::DSUBu, TmpReg, Mips::ZERO, TReg, Inst.
getLoc(), STI);
4495 TOut.
emitRRR(Mips::DROTRV, DReg, SReg, TmpReg, Inst.
getLoc(), STI);
4500 TOut.
emitRRR(Mips::DROTRV, DReg, SReg, TReg, Inst.
getLoc(), STI);
4512 FirstShift = Mips::DSRLV;
4513 SecondShift = Mips::DSLLV;
4516 FirstShift = Mips::DSLLV;
4517 SecondShift = Mips::DSRLV;
4521 ATReg = getATReg(Inst.
getLoc());
4525 TOut.
emitRRR(Mips::DSUBu, ATReg, Mips::ZERO, TReg, Inst.
getLoc(), STI);
4526 TOut.
emitRRR(FirstShift, ATReg, SReg, ATReg, Inst.
getLoc(), STI);
4527 TOut.
emitRRR(SecondShift, DReg, SReg, TReg, Inst.
getLoc(), STI);
4536 bool MipsAsmParser::expandDRotationImm(
MCInst &Inst,
SMLoc IDLoc,
4540 unsigned ATReg = Mips::NoRegister;
4545 unsigned FirstShift = Mips::NOP;
4546 unsigned SecondShift = Mips::NOP;
4550 if (hasMips64r2()) {
4551 unsigned FinalOpcode = Mips::NOP;
4553 FinalOpcode = Mips::DROTR;
4554 else if (ImmValue % 32 == 0)
4555 FinalOpcode = Mips::DROTR32;
4556 else if ((ImmValue >= 1) && (ImmValue <= 32)) {
4558 FinalOpcode = Mips::DROTR32;
4560 FinalOpcode = Mips::DROTR;
4561 }
else if (ImmValue >= 33) {
4563 FinalOpcode = Mips::DROTR;
4565 FinalOpcode = Mips::DROTR32;
4568 uint64_t ShiftValue = ImmValue % 32;
4570 ShiftValue = (32 - ImmValue % 32) % 32;
4572 TOut.
emitRRI(FinalOpcode, DReg, SReg, ShiftValue, Inst.
getLoc(), STI);
4578 if (ImmValue == 0) {
4579 TOut.
emitRRI(Mips::DSRL, DReg, SReg, 0, Inst.
getLoc(), STI);
4587 if ((ImmValue >= 1) && (ImmValue <= 31)) {
4588 FirstShift = Mips::DSLL;
4589 SecondShift = Mips::DSRL32;
4591 if (ImmValue == 32) {
4592 FirstShift = Mips::DSLL32;
4593 SecondShift = Mips::DSRL32;
4595 if ((ImmValue >= 33) && (ImmValue <= 63)) {
4596 FirstShift = Mips::DSLL32;
4597 SecondShift = Mips::DSRL;
4601 if ((ImmValue >= 1) && (ImmValue <= 31)) {
4602 FirstShift = Mips::DSRL;
4603 SecondShift = Mips::DSLL32;
4605 if (ImmValue == 32) {
4606 FirstShift = Mips::DSRL32;
4607 SecondShift = Mips::DSLL32;
4609 if ((ImmValue >= 33) && (ImmValue <= 63)) {
4610 FirstShift = Mips::DSRL32;
4611 SecondShift = Mips::DSLL;
4616 ATReg = getATReg(Inst.
getLoc());
4620 TOut.
emitRRI(FirstShift, ATReg, SReg, ImmValue % 32, Inst.
getLoc(), STI);
4621 TOut.
emitRRI(SecondShift, DReg, SReg, (32 - ImmValue % 32) % 32,
4637 TOut.
emitRI(Mips::BGEZ, SecondRegOp, 8, IDLoc, STI);
4638 if (FirstRegOp != SecondRegOp)
4639 TOut.
emitRRR(Mips::ADDu, FirstRegOp, SecondRegOp, Mips::ZERO, IDLoc, STI);
4650 unsigned ATReg = Mips::NoRegister;
4655 ATReg = getATReg(IDLoc);
4659 loadImmediate(ImmValue, ATReg, Mips::NoRegister,
true,
false, IDLoc, Out, STI);
4662 SrcReg, ATReg, IDLoc, STI);
4672 unsigned ATReg = Mips::NoRegister;
4677 ATReg = getATReg(Inst.
getLoc());
4682 SrcReg, TmpReg, IDLoc, STI);
4687 DstReg, DstReg, 0x1F, IDLoc, STI);
4692 TOut.
emitRRI(Mips::TNE, DstReg, ATReg, 6, IDLoc, STI);
4699 TOut.
emitRRX(Mips::BEQ, DstReg, ATReg, LabelOp, IDLoc, STI);
4700 if (AssemblerOptions.back()->isReorder())
4702 TOut.
emitII(Mips::BREAK, 6, 0, IDLoc, STI);
4714 unsigned ATReg = Mips::NoRegister;
4719 ATReg = getATReg(IDLoc);
4723 TOut.
emitRR(Inst.
getOpcode() == Mips::MULOUMacro ? Mips::MULTu : Mips::DMULTu,
4724 SrcReg, TmpReg, IDLoc, STI);
4729 TOut.
emitRRI(Mips::TNE, ATReg, Mips::ZERO, 6, IDLoc, STI);
4736 TOut.
emitRRX(Mips::BEQ, ATReg, Mips::ZERO, LabelOp, IDLoc, STI);
4737 if (AssemblerOptions.back()->isReorder())
4739 TOut.
emitII(Mips::BREAK, 6, 0, IDLoc, STI);
4754 TOut.
emitRR(Mips::DMULTu, SrcReg, TmpReg, IDLoc, STI);
4765 bool MipsAsmParser::expandLoadStoreDMacro(
MCInst &Inst,
SMLoc IDLoc,
4772 warnIfNoMacro(IDLoc);
4775 unsigned Opcode = IsLoad ? Mips::LW : Mips::SW;
4777 unsigned SecondReg =
nextReg(FirstReg);
4782 warnIfRegIndexIsAT(FirstReg, IDLoc);
4785 "Offset for load macro is not immediate!");
4788 signed NextOffset = FirstOffset.
getImm() + 4;
4796 if (FirstReg != BaseReg || !IsLoad) {
4797 TOut.
emitRRX(Opcode, FirstReg, BaseReg, FirstOffset, IDLoc, STI);
4798 TOut.
emitRRX(Opcode, SecondReg, BaseReg, SecondOffset, IDLoc, STI);
4800 TOut.
emitRRX(Opcode, SecondReg, BaseReg, SecondOffset, IDLoc, STI);
4801 TOut.
emitRRX(Opcode, FirstReg, BaseReg, FirstOffset, IDLoc, STI);
4810 warnIfNoMacro(IDLoc);
4835 warnIfNoMacro(IDLoc);
4848 if (Reg == Mips::ZERO) {
4849 Warning(IDLoc,
"comparison is always false");
4850 TOut.
emitRRR(isGP64bit() ? Mips::DADDu : Mips::ADDu,
4855 if (Imm > -0x8000 && Imm < 0) {
4857 Opc = isGP64bit() ? Mips::DADDiu : Mips::ADDiu;
4863 unsigned ATReg = getATReg(IDLoc);
4867 if (loadImmediate(Imm, ATReg, Mips::NoRegister,
true, isGP64bit(), IDLoc,
4886 MipsAsmParser::checkEarlyTargetMatchPredicate(
MCInst &Inst,
4890 return Match_Success;
4893 case Mips::DATI_MM64R6:
4894 case Mips::DAHI_MM64R6:
4895 if (static_cast<MipsOperand &>(*Operands[1])
4896 .isValidForTie(static_cast<MipsOperand &>(*Operands[2])))
4897 return Match_Success;
4898 return Match_RequiresSameSrcAndDst;
4902 unsigned MipsAsmParser::checkTargetMatchPredicate(
MCInst &Inst) {
4907 case Mips::DAUI_MM64R6:
4910 return Match_RequiresNoZeroRegister;
4911 return Match_Success;
4917 case Mips::JALRC_HB_MMR6:
4918 case Mips::JALRC_MMR6:
4920 return Match_RequiresDifferentSrcAndDst;
4921 return Match_Success;
4923 case Mips::LWP_MMR6:
4925 return Match_RequiresDifferentSrcAndDst;
4926 return Match_Success;
4929 return Match_NonZeroOperandForSync;
4930 return Match_Success;
4943 case Mips::BLEZC:
case Mips::BLEZC_MMR6:
4944 case Mips::BGEZC:
case Mips::BGEZC_MMR6:
4945 case Mips::BGTZC:
case Mips::BGTZC_MMR6:
4946 case Mips::BLTZC:
case Mips::BLTZC_MMR6:
4947 case Mips::BEQZC:
case Mips::BEQZC_MMR6:
4948 case Mips::BNEZC:
case Mips::BNEZC_MMR6:
4957 return Match_RequiresNoZeroRegister;
4958 return Match_Success;
4959 case Mips::BGEC:
case Mips::BGEC_MMR6:
4960 case Mips::BLTC:
case Mips::BLTC_MMR6:
4961 case Mips::BGEUC:
case Mips::BGEUC_MMR6:
4962 case Mips::BLTUC:
case Mips::BLTUC_MMR6:
4963 case Mips::BEQC:
case Mips::BEQC_MMR6:
4964 case Mips::BNEC:
case Mips::BNEC_MMR6:
4973 return Match_RequiresNoZeroRegister;
4976 return Match_RequiresNoZeroRegister;
4978 return Match_RequiresDifferentOperands;
4979 return Match_Success;
4985 return Match_NoFCCRegisterForCurrentISA;
4987 return Match_Success;
4993 if (ErrorInfo != ~0ULL && ErrorInfo < Operands.
size()) {
4994 SMLoc ErrorLoc = Operands[ErrorInfo]->getStartLoc();
4995 if (ErrorLoc ==
SMLoc())
5002 bool MipsAsmParser::MatchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
5006 bool MatchingInlineAsm) {
5008 unsigned MatchResult =
5009 MatchInstructionImpl(Operands, Inst, ErrorInfo, MatchingInlineAsm);
5011 switch (MatchResult) {
5013 if (processInstruction(Inst, IDLoc, Out, STI))
5016 case Match_MissingFeature:
5017 Error(IDLoc,
"instruction requires a CPU feature not currently enabled");
5019 case Match_InvalidOperand: {
5020 SMLoc ErrorLoc = IDLoc;
5021 if (ErrorInfo != ~0ULL) {
5022 if (ErrorInfo >= Operands.
size())
5023 return Error(IDLoc,
"too few operands for instruction");
5025 ErrorLoc = Operands[ErrorInfo]->getStartLoc();
5026 if (ErrorLoc ==
SMLoc())
5030 return Error(ErrorLoc,
"invalid operand for instruction");
5032 case Match_NonZeroOperandForSync:
5033 return Error(IDLoc,
"s-type must be zero or unspecified for pre-MIPS32 ISAs");
5034 case Match_MnemonicFail:
5035 return Error(IDLoc,
"invalid instruction");
5036 case Match_RequiresDifferentSrcAndDst:
5037 return Error(IDLoc,
"source and destination must be different");
5038 case Match_RequiresDifferentOperands:
5039 return Error(IDLoc,
"registers must be different");
5040 case Match_RequiresNoZeroRegister:
5041 return Error(IDLoc,
"invalid operand ($zero) for instruction");
5042 case Match_RequiresSameSrcAndDst:
5043 return Error(IDLoc,
"source and destination must match");
5044 case Match_NoFCCRegisterForCurrentISA:
5046 "non-zero fcc register doesn't exist in current ISA level");
5051 "expected 1-bit unsigned immediate");
5054 "expected 2-bit unsigned immediate");
5057 "expected immediate in range 1 .. 4");
5060 "expected 3-bit unsigned immediate");
5063 "expected 4-bit unsigned immediate");
5066 "expected 4-bit signed immediate");
5069 "expected 5-bit unsigned immediate");
5072 "expected 5-bit signed immediate");
5075 "expected immediate in range 1 .. 32");
5076 case Match_UImm5_32:
5078 "expected immediate in range 32 .. 63");
5079 case Match_UImm5_33:
5081 "expected immediate in range 33 .. 64");
5082 case Match_UImm5_0_Report_UImm6:
5086 "expected 6-bit unsigned immediate");
5087 case Match_UImm5_Lsl2:
5089 "expected both 7-bit unsigned immediate and multiple of 4");
5090 case Match_UImmRange2_64:
5092 "expected immediate in range 2 .. 64");
5095 "expected 6-bit unsigned immediate");
5096 case Match_UImm6_Lsl2:
5098 "expected both 8-bit unsigned immediate and multiple of 4");
5101 "expected 6-bit signed immediate");
5104 "expected 7-bit unsigned immediate");
5105 case Match_UImm7_N1:
5107 "expected immediate in range -1 .. 126");
5108 case Match_SImm7_Lsl2:
5110 "expected both 9-bit signed immediate and multiple of 4");
5113 "expected 8-bit unsigned immediate");
5114 case Match_UImm10_0:
5116 "expected 10-bit unsigned immediate");
5117 case Match_SImm10_0:
5119 "expected 10-bit signed immediate");
5120 case Match_SImm11_0:
5122 "expected 11-bit signed immediate");
5124 case Match_UImm16_Relaxed:
5126 "expected 16-bit unsigned immediate");
5128 case Match_SImm16_Relaxed:
5130 "expected 16-bit signed immediate");
5131 case Match_SImm19_Lsl2:
5133 "expected both 19-bit signed immediate and multiple of 4");
5134 case Match_UImm20_0:
5136 "expected 20-bit unsigned immediate");
5137 case Match_UImm26_0:
5139 "expected 26-bit unsigned immediate");
5141 case Match_SImm32_Relaxed:
5143 "expected 32-bit signed immediate");
5144 case Match_UImm32_Coerced:
5146 "expected 32-bit immediate");
5147 case Match_MemSImm9:
5149 "expected memory with 9-bit signed offset");
5150 case Match_MemSImm10:
5152 "expected memory with 10-bit signed offset");
5153 case Match_MemSImm10Lsl1:
5155 "expected memory with 11-bit signed offset and multiple of 2");
5156 case Match_MemSImm10Lsl2:
5158 "expected memory with 12-bit signed offset and multiple of 4");
5159 case Match_MemSImm10Lsl3:
5161 "expected memory with 13-bit signed offset and multiple of 8");
5162 case Match_MemSImm11:
5164 "expected memory with 11-bit signed offset");
5165 case Match_MemSImm12:
5167 "expected memory with 12-bit signed offset");
5168 case Match_MemSImm16:
5170 "expected memory with 16-bit signed offset");
5176 void MipsAsmParser::warnIfRegIndexIsAT(
unsigned RegIndex,
SMLoc Loc) {
5177 if (RegIndex != 0 && AssemblerOptions.back()->getATRegIndex() == RegIndex)
5178 Warning(Loc,
"used $at (currently $" +
Twine(RegIndex) +
5179 ") without \".set noat\"");
5182 void MipsAsmParser::warnIfNoMacro(
SMLoc Loc) {
5183 if (!AssemblerOptions.back()->isMacro())
5184 Warning(Loc,
"macro instruction expanded into multiple instructions");
5188 MipsAsmParser::printWarningWithFixIt(
const Twine &Msg,
const Twine &FixMsg,
5189 SMRange Range,
bool ShowColors) {
5191 Range,
SMFixIt(Range, FixMsg),
5200 .
Cases(
"at",
"AT", 1)
5234 if (!(isABI_N32() || isABI_N64()))
5237 if (12 <= CC && CC <= 15) {
5239 AsmToken RegTok = getLexer().peekTok();
5248 assert(FixedName !=
"" &&
"Register name is not one of t4-t7.");
5250 printWarningWithFixIt(
"register names $t4-$t7 are only available in O32.",
5251 "Did you mean $" + FixedName +
"?", RegRange);
5257 if (8 <= CC && CC <= 11)
5273 int MipsAsmParser::matchHWRegsRegisterName(
StringRef Name) {
5277 .Case(
"hwr_cpunum", 0)
5278 .
Case(
"hwr_synci_step", 1)
5280 .
Case(
"hwr_ccres", 3)
5281 .
Case(
"hwr_ulr", 29)
5287 int MipsAsmParser::matchFPURegisterName(
StringRef Name) {
5288 if (Name[0] ==
'f') {
5300 int MipsAsmParser::matchFCCRegisterName(
StringRef Name) {
5313 int MipsAsmParser::matchACRegisterName(
StringRef Name) {
5326 int MipsAsmParser::matchMSA128RegisterName(
StringRef Name) {
5338 int MipsAsmParser::matchMSA128CtrlRegisterName(
StringRef Name) {
5344 .
Case(
"msaaccess", 2)
5346 .
Case(
"msamodify", 4)
5347 .
Case(
"msarequest", 5)
5349 .
Case(
"msaunmap", 7)
5355 bool MipsAsmParser::canUseATReg() {
5356 return AssemblerOptions.back()->getATRegIndex() != 0;
5359 unsigned MipsAsmParser::getATReg(
SMLoc Loc) {
5360 unsigned ATIndex = AssemblerOptions.back()->getATRegIndex();
5362 reportParseError(Loc,
5363 "pseudo-instruction requires $at, which is not available");
5367 (isGP64bit()) ? Mips::GPR64RegClassID : Mips::GPR32RegClassID, ATIndex);
5372 return *(getContext().getRegisterInfo()->getRegClass(RC).begin() + RegNo);
5392 switch (getLexer().getKind()) {
5411 MCSymbol *Sym = getContext().getOrCreateSymbol(
"$" + Identifier);
5416 Operands.
push_back(MipsOperand::CreateImm(Res, S, E, *
this));
5420 DEBUG(
dbgs() <<
".. generic integer expression\n");
5424 if (getParser().parseExpression(Expr))
5429 Operands.
push_back(MipsOperand::CreateImm(Expr, S, E, *
this));
5436 bool MipsAsmParser::isEvaluated(
const MCExpr *Expr) {
5443 if (
const MCBinaryExpr *BE = dyn_cast<MCBinaryExpr>(Expr)) {
5444 if (!isEvaluated(BE->getLHS()))
5446 return isEvaluated(BE->getRHS());
5449 return isEvaluated(cast<MCUnaryExpr>(Expr)->getSubExpr());
5456 bool MipsAsmParser::ParseRegister(
unsigned &RegNo,
SMLoc &StartLoc,
5462 MipsOperand &Operand =
static_cast<MipsOperand &
>(*Operands.
front());
5463 StartLoc = Operand.getStartLoc();
5464 EndLoc = Operand.getEndLoc();
5470 if (Operand.isGPRAsmReg()) {
5472 RegNo = isGP64bit() ? Operand.getGPR64Reg() : Operand.getGPR32Reg();
5475 return (RegNo == (
unsigned)-1);
5479 return (RegNo == (
unsigned)-1);
5482 bool MipsAsmParser::parseMemOffset(
const MCExpr *&Res,
bool isParenExpr) {
5486 return getParser().parseParenExprOfDepth(0, Res, S);
5487 return getParser().parseExpression(Res);
5494 const MCExpr *IdVal =
nullptr;
5496 bool isParenExpr =
false;
5507 if (parseMemOffset(IdVal, isParenExpr))
5512 MipsOperand &Mnemonic =
static_cast<MipsOperand &
>(*Operands[0]);
5513 if (Mnemonic.getToken() ==
"la" || Mnemonic.getToken() ==
"dla") {
5516 Operands.
push_back(MipsOperand::CreateImm(IdVal, S, E, *
this));
5525 auto Base = MipsOperand::createGPRReg(
5526 0,
"0", getContext().getRegisterInfo(), S, E, *
this);
5528 MipsOperand::CreateMem(std::move(Base), IdVal, S, E, *
this));
5582 if (getParser().parseExpression(NextExpr))
5590 Res = parseAnyRegister(Operands);
5607 std::unique_ptr<MipsOperand>
op(
5608 static_cast<MipsOperand *>(Operands.
back().release()));
5613 if (
const MCBinaryExpr *BE = dyn_cast<MCBinaryExpr>(IdVal)) {
5615 if (IdVal->evaluateAsAbsolute(Imm))
5622 Operands.
push_back(MipsOperand::CreateMem(std::move(
op), IdVal, S, E, *
this));
5626 bool MipsAsmParser::searchSymbolAlias(
OperandVector &Operands) {
5641 matchAnyRegisterNameWithoutDollar(Operands, DefSymbol.
substr(1), S);
5655 MipsAsmParser::matchAnyRegisterNameWithoutDollar(
OperandVector &Operands,
5658 int Index = matchCPURegisterName(Identifier);
5660 Operands.
push_back(MipsOperand::createGPRReg(
5661 Index, Identifier, getContext().getRegisterInfo(), S,
5662 getLexer().getLoc(), *
this));
5666 Index = matchHWRegsRegisterName(Identifier);
5668 Operands.
push_back(MipsOperand::createHWRegsReg(
5669 Index, Identifier, getContext().getRegisterInfo(), S,
5670 getLexer().getLoc(), *
this));
5674 Index = matchFPURegisterName(Identifier);
5676 Operands.
push_back(MipsOperand::createFGRReg(
5677 Index, Identifier, getContext().getRegisterInfo(), S,
5678 getLexer().getLoc(), *
this));
5682 Index = matchFCCRegisterName(Identifier);
5684 Operands.
push_back(MipsOperand::createFCCReg(
5685 Index, Identifier, getContext().getRegisterInfo(), S,
5686 getLexer().getLoc(), *
this));
5690 Index = matchACRegisterName(Identifier);
5692 Operands.
push_back(MipsOperand::createACCReg(
5693 Index, Identifier, getContext().getRegisterInfo(), S,
5694 getLexer().getLoc(), *
this));
5698 Index = matchMSA128RegisterName(Identifier);
5700 Operands.
push_back(MipsOperand::createMSA128Reg(
5701 Index, Identifier, getContext().getRegisterInfo(), S,
5702 getLexer().getLoc(), *
this));
5706 Index = matchMSA128CtrlRegisterName(Identifier);
5708 Operands.
push_back(MipsOperand::createMSACtrlReg(
5709 Index, Identifier, getContext().getRegisterInfo(), S,
5710 getLexer().getLoc(), *
this));
5724 StringRef Identifier = Token.getIdentifier();
5726 matchAnyRegisterNameWithoutDollar(Operands, Identifier, S);
5730 Operands.
push_back(MipsOperand::createNumericReg(
5731 Token.getIntVal(), Token.getString(), getContext().getRegisterInfo(), S,
5732 Token.getLoc(), *
this));
5746 auto Token = Parser.
getTok();
5748 SMLoc S = Token.getLoc();
5751 DEBUG(
dbgs() <<
".. !$ -> try sym aliasing\n");
5753 if (searchSymbolAlias(Operands))
5756 DEBUG(
dbgs() <<
".. !symalias -> NoMatch\n");
5774 SMLoc S = getLexer().getLoc();
5782 const MCExpr *Expr =
nullptr;
5788 MipsOperand::CreateImm(Expr, S, getLexer().getLoc(), *
this));
5800 if (getParser().parseExpression(IdVal))
5803 assert(MCE &&
"Unexpected MCExpr type.");
5806 Operands.
push_back(MipsOperand::CreateImm(
5816 unsigned PrevReg = Mips::NoRegister;
5817 bool RegRange =
false;
5825 SMLoc E = getLexer().getLoc();
5826 MipsOperand &Reg =
static_cast<MipsOperand &
>(*TmpOperands.
back());
5827 RegNo = isGP64bit() ? Reg.getGPR64Reg() : Reg.getGPR32Reg();
5831 if ((isGP64bit() && RegNo == Mips::RA_64) ||
5832 (!isGP64bit() && RegNo == Mips::RA)) {
5835 unsigned TmpReg = PrevReg + 1;
5836 while (TmpReg <= RegNo) {
5837 if ((((TmpReg < Mips::S0) || (TmpReg > Mips::S7)) && !isGP64bit()) ||
5838 (((TmpReg < Mips::S0_64) || (TmpReg > Mips::S7_64)) &&
5840 Error(E,
"invalid register operand");
5851 if ((PrevReg == Mips::NoRegister) &&
5852 ((isGP64bit() && (RegNo != Mips::S0_64) && (RegNo != Mips::RA_64)) ||
5853 (!isGP64bit() && (RegNo != Mips::S0) && (RegNo != Mips::RA)))) {
5854 Error(E,
"$16 or $31 expected");
5856 }
else if (!(((RegNo == Mips::FP || RegNo == Mips::RA ||
5857 (RegNo >= Mips::S0 && RegNo <= Mips::S7)) &&
5859 ((RegNo == Mips::FP_64 || RegNo == Mips::RA_64 ||
5860 (RegNo >= Mips::S0_64 && RegNo <= Mips::S7_64)) &&
5862 Error(E,
"invalid register operand");
5864 }
else if ((PrevReg != Mips::NoRegister) && (RegNo != PrevReg + 1) &&
5865 ((RegNo != Mips::FP && RegNo != Mips::RA && !isGP64bit()) ||
5866 (RegNo != Mips::FP_64 && RegNo != Mips::RA_64 &&
5868 Error(E,
"consecutive register numbers expected");
5880 Error(E,
"',' or '-' expected");
5892 Operands.
push_back(MipsOperand::CreateRegList(Regs, S, E, *
this));
5893 parseMemOperand(Operands);
5906 MipsOperand Op =
static_cast<MipsOperand &
>(*Operands.
back());
5909 Operands.
push_back(MipsOperand::CreateRegPair(Op, S, E, *
this));
5927 MipsOperand *Reg = &
static_cast<MipsOperand &
>(*TmpOperands.
back());
5928 unsigned RegNo = isGP64bit() ? Reg->getGPR64Reg() : Reg->getGPR32Reg();
5933 Error(E,
"',' expected");
5943 Reg = &
static_cast<MipsOperand &
>(*TmpOperands.
back());
5944 RegNo = isGP64bit() ? Reg->getGPR64Reg() : Reg->getGPR32Reg();
5947 Operands.
push_back(MipsOperand::CreateRegList(Regs, S, E, *
this));
5961 MipsOperand::CreateToken(
"(", getLexer().getLoc(), *
this));
5963 if (parseOperand(Operands, Name)) {
5964 SMLoc Loc = getLexer().getLoc();
5965 return Error(Loc,
"unexpected token in argument list");
5968 SMLoc Loc = getLexer().getLoc();
5969 return Error(Loc,
"unexpected token, expected ')'");
5972 MipsOperand::CreateToken(
")", getLexer().getLoc(), *
this));
5984 bool MipsAsmParser::parseBracketSuffix(
StringRef Name,
5989 MipsOperand::CreateToken(
"[", getLexer().getLoc(), *
this));
5991 if (parseOperand(Operands, Name)) {
5992 SMLoc Loc = getLexer().getLoc();
5993 return Error(Loc,
"unexpected token in argument list");
5996 SMLoc Loc = getLexer().getLoc();
5997 return Error(Loc,
"unexpected token, expected ']'");
6000 MipsOperand::CreateToken(
"]", getLexer().getLoc(), *
this));
6012 getTargetStreamer().forbidModuleDirective();
6015 if (!mnemonicIsValid(Name, 0)) {
6016 return Error(NameLoc,
"unknown instruction");
6019 Operands.
push_back(MipsOperand::CreateToken(Name, NameLoc, *
this));
6024 if (parseOperand(Operands, Name)) {
6025 SMLoc Loc = getLexer().getLoc();
6026 return Error(Loc,
"unexpected token in argument list");
6028 if (getLexer().is(
AsmToken::LBrac) && parseBracketSuffix(Name, Operands))
6035 if (parseOperand(Operands, Name)) {
6036 SMLoc Loc = getLexer().getLoc();
6037 return Error(Loc,
"unexpected token in argument list");
6041 if (parseBracketSuffix(Name, Operands))
6044 parseParenSuffix(Name, Operands))
6049 SMLoc Loc = getLexer().getLoc();
6050 return Error(Loc,
"unexpected token in argument list");
6058 bool MipsAsmParser::reportParseError(
Twine ErrorMsg) {
6059 SMLoc Loc = getLexer().getLoc();
6060 return Error(Loc, ErrorMsg);
6063 bool MipsAsmParser::reportParseError(
SMLoc Loc,
Twine ErrorMsg) {
6064 return Error(Loc, ErrorMsg);
6067 bool MipsAsmParser::parseSetNoAtDirective() {
6072 AssemblerOptions.back()->setATRegIndex(0);
6078 reportParseError(
"unexpected token, expected end of statement");
6082 getTargetStreamer().emitDirectiveSetNoAt();
6087 bool MipsAsmParser::parseSetAtDirective() {
6095 AssemblerOptions.back()->setATRegIndex(1);
6097 getTargetStreamer().emitDirectiveSetAt();
6103 reportParseError(
"unexpected token, expected equals sign");
6110 reportParseError(
"no register specified");
6113 reportParseError(
"unexpected token, expected dollar sign '$'");
6127 reportParseError(
"unexpected token, expected identifier or integer");
6132 if (!AssemblerOptions.back()->setATRegIndex(AtRegNo)) {
6133 reportParseError(
"invalid register");
6140 reportParseError(
"unexpected token, expected end of statement");
6144 getTargetStreamer().emitDirectiveSetAtWithArg(AtRegNo);
6150 bool MipsAsmParser::parseSetReorderDirective() {
6155 reportParseError(
"unexpected token, expected end of statement");
6158 AssemblerOptions.back()->setReorder();
6159 getTargetStreamer().emitDirectiveSetReorder();
6164 bool MipsAsmParser::parseSetNoReorderDirective() {
6169 reportParseError(
"unexpected token, expected end of statement");
6172 AssemblerOptions.back()->setNoReorder();
6173 getTargetStreamer().emitDirectiveSetNoReorder();
6178 bool MipsAsmParser::parseSetMacroDirective() {
6183 reportParseError(
"unexpected token, expected end of statement");
6186 AssemblerOptions.back()->setMacro();
6187 getTargetStreamer().emitDirectiveSetMacro();
6192 bool MipsAsmParser::parseSetNoMacroDirective() {
6197 reportParseError(
"unexpected token, expected end of statement");
6200 if (AssemblerOptions.back()->isReorder()) {
6201 reportParseError(
"`noreorder' must be set before `nomacro'");
6204 AssemblerOptions.back()->setNoMacro();
6205 getTargetStreamer().emitDirectiveSetNoMacro();
6210 bool MipsAsmParser::parseSetMsaDirective() {
6216 return reportParseError(
"unexpected token, expected end of statement");
6218 setFeatureBits(Mips::FeatureMSA,
"msa");
6219 getTargetStreamer().emitDirectiveSetMsa();
6223 bool MipsAsmParser::parseSetNoMsaDirective() {
6229 return reportParseError(
"unexpected token, expected end of statement");
6231 clearFeatureBits(Mips::FeatureMSA,
"msa");
6232 getTargetStreamer().emitDirectiveSetNoMsa();
6236 bool MipsAsmParser::parseSetNoDspDirective() {
6242 reportParseError(
"unexpected token, expected end of statement");
6246 clearFeatureBits(Mips::FeatureDSP,
"dsp");
6247 getTargetStreamer().emitDirectiveSetNoDsp();
6251 bool MipsAsmParser::parseSetMips16Directive() {
6257 reportParseError(
"unexpected token, expected end of statement");
6261 setFeatureBits(Mips::FeatureMips16,
"mips16");
6262 getTargetStreamer().emitDirectiveSetMips16();
6267 bool MipsAsmParser::parseSetNoMips16Directive() {
6273 reportParseError(
"unexpected token, expected end of statement");
6277 clearFeatureBits(Mips::FeatureMips16,
"mips16");
6278 getTargetStreamer().emitDirectiveSetNoMips16();
6283 bool MipsAsmParser::parseSetFpDirective() {
6292 reportParseError(
"unexpected token, expected equals sign '='");
6298 if (!parseFpABIValue(FpAbiVal,
".set"))
6302 reportParseError(
"unexpected token, expected end of statement");
6305 getTargetStreamer().emitDirectiveSetFp(FpAbiVal);
6310 bool MipsAsmParser::parseSetOddSPRegDirective() {
6315 reportParseError(
"unexpected token, expected end of statement");
6319 clearFeatureBits(Mips::FeatureNoOddSPReg,
"nooddspreg");
6320 getTargetStreamer().emitDirectiveSetOddSPReg();
6324 bool MipsAsmParser::parseSetNoOddSPRegDirective() {
6329 reportParseError(
"unexpected token, expected end of statement");
6333 setFeatureBits(Mips::FeatureNoOddSPReg,
"nooddspreg");
6334 getTargetStreamer().emitDirectiveSetNoOddSPReg();
6338 bool MipsAsmParser::parseSetMtDirective() {
6344 reportParseError(
"unexpected token, expected end of statement");
6348 setFeatureBits(Mips::FeatureMT,
"mt");
6349 getTargetStreamer().emitDirectiveSetMt();
6354 bool MipsAsmParser::parseSetNoMtDirective() {
6360 reportParseError(
"unexpected token, expected end of statement");
6364 clearFeatureBits(Mips::FeatureMT,
"mt");
6366 getTargetStreamer().emitDirectiveSetNoMt();
6371 bool MipsAsmParser::parseSetPopDirective() {
6373 SMLoc Loc = getLexer().getLoc();
6377 return reportParseError(
"unexpected token, expected end of statement");
6381 if (AssemblerOptions.size() == 2)
6382 return reportParseError(Loc,
".set pop with no .set push");
6385 AssemblerOptions.pop_back();
6386 setAvailableFeatures(
6387 ComputeAvailableFeatures(AssemblerOptions.back()->getFeatures()));
6390 getTargetStreamer().emitDirectiveSetPop();
6394 bool MipsAsmParser::parseSetPushDirective() {
6398 return reportParseError(
"unexpected token, expected end of statement");
6401 AssemblerOptions.push_back(
6402 llvm::make_unique<MipsAssemblerOptions>(AssemblerOptions.back().get()));
6404 getTargetStreamer().emitDirectiveSetPush();
6408 bool MipsAsmParser::parseSetSoftFloatDirective() {
6412 return reportParseError(
"unexpected token, expected end of statement");
6414 setFeatureBits(Mips::FeatureSoftFloat,
"soft-float");
6415 getTargetStreamer().emitDirectiveSetSoftFloat();
6419 bool MipsAsmParser::parseSetHardFloatDirective() {
6423 return reportParseError(
"unexpected token, expected end of statement");
6425 clearFeatureBits(Mips::FeatureSoftFloat,
"soft-float");
6426 getTargetStreamer().emitDirectiveSetHardFloat();
6430 bool MipsAsmParser::parseSetAssignment() {
6436 reportParseError(
"expected identifier after .set");
6439 return reportParseError(
"unexpected token, expected comma");
6443 return reportParseError(
"expected valid expression after comma");
6445 MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
6451 bool MipsAsmParser::parseSetMips0Directive() {
6455 return reportParseError(
"unexpected token, expected end of statement");
6459 setAvailableFeatures(
6460 ComputeAvailableFeatures(AssemblerOptions.front()->getFeatures()));
6462 AssemblerOptions.back()->setFeatures(AssemblerOptions.front()->getFeatures());
6464 getTargetStreamer().emitDirectiveSetMips0();
6468 bool MipsAsmParser::parseSetArchDirective() {
6472 return reportParseError(
"unexpected token, expected equals sign");
6477 return reportParseError(
"expected arch identifier");
6481 .Case(
"mips1",
"mips1")
6482 .
Case(
"mips2",
"mips2")
6483 .
Case(
"mips3",
"mips3")
6484 .
Case(
"mips4",
"mips4")
6485 .
Case(
"mips5",
"mips5")
6486 .
Case(
"mips32",
"mips32")
6487 .
Case(
"mips32r2",
"mips32r2")
6488 .
Case(
"mips32r3",
"mips32r3")
6489 .
Case(
"mips32r5",
"mips32r5")
6490 .
Case(
"mips32r6",
"mips32r6")
6491 .
Case(
"mips64",
"mips64")
6492 .
Case(
"mips64r2",
"mips64r2")
6493 .
Case(
"mips64r3",
"mips64r3")
6494 .
Case(
"mips64r5",
"mips64r5")
6495 .
Case(
"mips64r6",
"mips64r6")
6496 .
Case(
"octeon",
"cnmips")
6497 .
Case(
"r4000",
"mips3")
6500 if (ArchFeatureName.
empty())
6501 return reportParseError(
"unsupported architecture");
6503 selectArch(ArchFeatureName);
6504 getTargetStreamer().emitDirectiveSetArch(Arch);
6508 bool MipsAsmParser::parseSetFeature(uint64_t Feature) {
6512 return reportParseError(
"unexpected token, expected end of statement");
6517 case Mips::FeatureDSP:
6518 setFeatureBits(Mips::FeatureDSP,
"dsp");
6519 getTargetStreamer().emitDirectiveSetDsp();
6521 case Mips::FeatureMicroMips:
6522 setFeatureBits(Mips::FeatureMicroMips,
"micromips");
6523 getTargetStreamer().emitDirectiveSetMicroMips();
6525 case Mips::FeatureMips1:
6526 selectArch(
"mips1");
6527 getTargetStreamer().emitDirectiveSetMips1();
6529 case Mips::FeatureMips2:
6530 selectArch(
"mips2");
6531 getTargetStreamer().emitDirectiveSetMips2();
6533 case Mips::FeatureMips3:
6534 selectArch(
"mips3");
6535 getTargetStreamer().emitDirectiveSetMips3();
6537 case Mips::FeatureMips4:
6538 selectArch(
"mips4");
6539 getTargetStreamer().emitDirectiveSetMips4();
6541 case Mips::FeatureMips5:
6542 selectArch(
"mips5");
6543 getTargetStreamer().emitDirectiveSetMips5();
6545 case Mips::FeatureMips32:
6546 selectArch(
"mips32");
6547 getTargetStreamer().emitDirectiveSetMips32();
6549 case Mips::FeatureMips32r2:
6550 selectArch(
"mips32r2");
6551 getTargetStreamer().emitDirectiveSetMips32R2();
6553 case Mips::FeatureMips32r3:
6554 selectArch(
"mips32r3");
6555 getTargetStreamer().emitDirectiveSetMips32R3();
6557 case Mips::FeatureMips32r5:
6558 selectArch(
"mips32r5");
6559 getTargetStreamer().emitDirectiveSetMips32R5();
6561 case Mips::FeatureMips32r6:
6562 selectArch(
"mips32r6");
6563 getTargetStreamer().emitDirectiveSetMips32R6();
6565 case Mips::FeatureMips64:
6566 selectArch(
"mips64");
6567 getTargetStreamer().emitDirectiveSetMips64();
6569 case Mips::FeatureMips64r2:
6570 selectArch(
"mips64r2");
6571 getTargetStreamer().emitDirectiveSetMips64R2();
6573 case Mips::FeatureMips64r3:
6574 selectArch(
"mips64r3");
6575 getTargetStreamer().emitDirectiveSetMips64R3();
6577 case Mips::FeatureMips64r5:
6578 selectArch(
"mips64r5");
6579 getTargetStreamer().emitDirectiveSetMips64R5();
6581 case Mips::FeatureMips64r6:
6582 selectArch(
"mips64r6");
6583 getTargetStreamer().emitDirectiveSetMips64R6();
6589 bool MipsAsmParser::eatComma(
StringRef ErrorStr) {
6592 SMLoc Loc = getLexer().getLoc();
6593 return Error(Loc, ErrorStr);
6604 bool MipsAsmParser::isPicAndNotNxxAbi() {
6605 return inPicMode() && !(isABI_N32() || isABI_N64());
6608 bool MipsAsmParser::parseDirectiveCpLoad(
SMLoc Loc) {
6609 if (AssemblerOptions.back()->isReorder())
6610 Warning(Loc,
".cpload should be inside a noreorder section");
6612 if (inMips16Mode()) {
6613 reportParseError(
".cpload is not supported in Mips16 mode");
6620 reportParseError(
"expected register containing function address");
6624 MipsOperand &RegOpnd =
static_cast<MipsOperand &
>(*Reg[0]);
6625 if (!RegOpnd.isGPRAsmReg()) {
6626 reportParseError(RegOpnd.getStartLoc(),
"invalid register");
6632 reportParseError(
"unexpected token, expected end of statement");
6636 getTargetStreamer().emitDirectiveCpLoad(RegOpnd.getGPR32Reg());
6640 bool MipsAsmParser::parseDirectiveCpRestore(
SMLoc Loc) {
6646 if (inMips16Mode()) {
6647 reportParseError(
".cprestore is not supported in Mips16 mode");
6652 const MCExpr *StackOffset;
6653 int64_t StackOffsetVal;
6655 reportParseError(
"expected stack offset value");
6659 if (!StackOffset->evaluateAsAbsolute(StackOffsetVal)) {
6660 reportParseError(
"stack offset is not an absolute expression");
6664 if (StackOffsetVal < 0) {
6665 Warning(Loc,
".cprestore with negative stack offset has no effect");
6666 IsCpRestoreSet =
false;
6668 IsCpRestoreSet =
true;
6669 CpRestoreOffset = StackOffsetVal;
6674 reportParseError(
"unexpected token, expected end of statement");
6678 if (!getTargetStreamer().emitDirectiveCpRestore(
6679 CpRestoreOffset, [&]() {
return getATReg(Loc); }, Loc, STI))
6685 bool MipsAsmParser::parseDirectiveCPSetup() {
6689 bool SaveIsReg =
true;
6694 reportParseError(
"expected register containing function address");
6698 MipsOperand &FuncRegOpnd =
static_cast<MipsOperand &
>(*TmpReg[0]);
6699 if (!FuncRegOpnd.isGPRAsmReg()) {
6700 reportParseError(FuncRegOpnd.getStartLoc(),
"invalid register");
6704 FuncReg = FuncRegOpnd.getGPR32Reg();
6707 if (!eatComma(
"unexpected token, expected comma"))
6710 ResTy = parseAnyRegister(TmpReg);
6712 const MCExpr *OffsetExpr;
6714 SMLoc ExprLoc = getLexer().getLoc();
6717 !OffsetExpr->evaluateAsAbsolute(OffsetVal)) {
6718 reportParseError(ExprLoc,
"expected save register or stack offset");
6725 MipsOperand &SaveOpnd =
static_cast<MipsOperand &
>(*TmpReg[0]);
6726 if (!SaveOpnd.isGPRAsmReg()) {
6727 reportParseError(SaveOpnd.getStartLoc(),
"invalid register");
6730 Save = SaveOpnd.getGPR32Reg();
6733 if (!eatComma(
"unexpected token, expected comma"))
6738 reportParseError(
"expected expression");
6743 reportParseError(
"expected symbol");
6748 CpSaveLocation = Save;
6749 CpSaveLocationIsRegister = SaveIsReg;
6751 getTargetStreamer().emitDirectiveCpsetup(FuncReg, Save, Ref->
getSymbol(),
6756 bool MipsAsmParser::parseDirectiveCPReturn() {
6757 getTargetStreamer().emitDirectiveCpreturn(CpSaveLocation,
6758 CpSaveLocationIsRegister);
6762 bool MipsAsmParser::parseDirectiveNaN() {
6769 getTargetStreamer().emitDirectiveNaN2008();
6771 }
else if (Tok.
getString() ==
"legacy") {
6773 getTargetStreamer().emitDirectiveNaNLegacy();
6779 reportParseError(
"invalid option in .nan directive");
6783 bool MipsAsmParser::parseDirectiveSet() {
6789 return parseSetNoAtDirective();
6791 return parseSetAtDirective();
6793 return parseSetArchDirective();
6795 Warning(Tok.
getLoc(),
"'bopt' feature is unsupported");
6798 }
else if (Tok.
getString() ==
"nobopt") {
6803 return parseSetFpDirective();
6804 }
else if (Tok.
getString() ==
"oddspreg") {
6805 return parseSetOddSPRegDirective();
6806 }
else if (Tok.
getString() ==
"nooddspreg") {
6807 return parseSetNoOddSPRegDirective();
6809 return parseSetPopDirective();
6811 return parseSetPushDirective();
6812 }
else if (Tok.
getString() ==
"reorder") {
6813 return parseSetReorderDirective();
6814 }
else if (Tok.
getString() ==
"noreorder") {
6815 return parseSetNoReorderDirective();
6816 }
else if (Tok.
getString() ==
"macro") {
6817 return parseSetMacroDirective();
6818 }
else if (Tok.
getString() ==
"nomacro") {
6819 return parseSetNoMacroDirective();
6820 }
else if (Tok.
getString() ==
"mips16") {
6821 return parseSetMips16Directive();
6822 }
else if (Tok.
getString() ==
"nomips16") {
6823 return parseSetNoMips16Directive();
6824 }
else if (Tok.
getString() ==
"nomicromips") {
6825 clearFeatureBits(Mips::FeatureMicroMips,
"micromips");
6826 getTargetStreamer().emitDirectiveSetNoMicroMips();
6829 }
else if (Tok.
getString() ==
"micromips") {
6830 return parseSetFeature(Mips::FeatureMicroMips);
6831 }
else if (Tok.
getString() ==
"mips0") {
6832 return parseSetMips0Directive();
6833 }
else if (Tok.
getString() ==
"mips1") {
6834 return parseSetFeature(Mips::FeatureMips1);
6835 }
else if (Tok.
getString() ==
"mips2") {
6836 return parseSetFeature(Mips::FeatureMips2);
6837 }
else if (Tok.
getString() ==
"mips3") {
6838 return parseSetFeature(Mips::FeatureMips3);
6839 }
else if (Tok.
getString() ==
"mips4") {
6840 return parseSetFeature(Mips::FeatureMips4);
6841 }
else if (Tok.
getString() ==
"mips5") {
6842 return parseSetFeature(Mips::FeatureMips5);
6843 }
else if (Tok.
getString() ==
"mips32") {
6844 return parseSetFeature(Mips::FeatureMips32);
6845 }
else if (Tok.
getString() ==
"mips32r2") {
6846 return parseSetFeature(Mips::FeatureMips32r2);
6847 }
else if (Tok.
getString() ==
"mips32r3") {
6848 return parseSetFeature(Mips::FeatureMips32r3);
6849 }
else if (Tok.
getString() ==
"mips32r5") {
6850 return parseSetFeature(Mips::FeatureMips32r5);
6851 }
else if (Tok.
getString() ==
"mips32r6") {
6852 return parseSetFeature(Mips::FeatureMips32r6);
6853 }
else if (Tok.
getString() ==
"mips64") {
6854 return parseSetFeature(Mips::FeatureMips64);
6855 }
else if (Tok.
getString() ==
"mips64r2") {
6856 return parseSetFeature(Mips::FeatureMips64r2);
6857 }
else if (Tok.
getString() ==
"mips64r3") {
6858 return parseSetFeature(Mips::FeatureMips64r3);
6859 }
else if (Tok.
getString() ==
"mips64r5") {
6860 return parseSetFeature(Mips::FeatureMips64r5);
6861 }
else if (Tok.
getString() ==
"mips64r6") {
6862 return parseSetFeature(Mips::FeatureMips64r6);
6864 return parseSetFeature(Mips::FeatureDSP);
6865 }
else if (Tok.
getString() ==
"nodsp") {
6866 return parseSetNoDspDirective();
6868 return parseSetMsaDirective();
6869 }
else if (Tok.
getString() ==
"nomsa") {
6870 return parseSetNoMsaDirective();
6872 return parseSetMtDirective();
6874 return parseSetNoMtDirective();
6875 }
else if (Tok.
getString() ==
"softfloat") {
6876 return parseSetSoftFloatDirective();
6877 }
else if (Tok.
getString() ==
"hardfloat") {
6878 return parseSetHardFloatDirective();
6881 parseSetAssignment();
6890 bool MipsAsmParser::parseDataDirective(
unsigned Size,
SMLoc L) {
6895 if (getParser().parseExpression(Value))
6898 getParser().getStreamer().EmitValue(Value, Size);
6904 return Error(L,
"unexpected token, expected comma");
6915 bool MipsAsmParser::parseDirectiveGpWord() {
6920 if (getParser().parseExpression(Value))
6922 getParser().getStreamer().EmitGPRel32Value(Value);
6925 return Error(getLexer().getLoc(),
6926 "unexpected token, expected end of statement");
6933 bool MipsAsmParser::parseDirectiveGpDWord() {
6938 if (getParser().parseExpression(Value))
6940 getParser().getStreamer().EmitGPRel64Value(Value);
6943 return Error(getLexer().getLoc(),
6944 "unexpected token, expected end of statement");
6951 bool MipsAsmParser::parseDirectiveDtpRelWord() {
6956 if (getParser().parseExpression(Value))
6958 getParser().getStreamer().EmitDTPRel32Value(Value);
6961 return Error(getLexer().getLoc(),
6962 "unexpected token, expected end of statement");
6969 bool MipsAsmParser::parseDirectiveDtpRelDWord() {
6974 if (getParser().parseExpression(Value))
6976 getParser().getStreamer().EmitDTPRel64Value(Value);
6979 return Error(getLexer().getLoc(),
6980 "unexpected token, expected end of statement");
6987 bool MipsAsmParser::parseDirectiveTpRelWord() {
6992 if (getParser().parseExpression(Value))
6994 getParser().getStreamer().EmitTPRel32Value(Value);
6997 return Error(getLexer().getLoc(),
6998 "unexpected token, expected end of statement");
7005 bool MipsAsmParser::parseDirectiveTpRelDWord() {
7010 if (getParser().parseExpression(Value))
7012 getParser().getStreamer().EmitTPRel64Value(Value);
7015 return Error(getLexer().getLoc(),
7016 "unexpected token, expected end of statement");
7021 bool MipsAsmParser::parseDirectiveOption() {
7028 "unexpected token, expected identifier");
7033 if (Option ==
"pic0") {
7035 IsPicEnabled =
false;
7037 getTargetStreamer().emitDirectiveOptionPic0();
7041 "unexpected token, expected end of statement");
7046 if (Option ==
"pic2") {
7048 IsPicEnabled =
true;
7050 getTargetStreamer().emitDirectiveOptionPic2();
7054 "unexpected token, expected end of statement");
7061 "unknown option, expected 'pic0' or 'pic2'");
7068 bool MipsAsmParser::parseInsnDirective() {
7071 reportParseError(
"unexpected token, expected end of statement");
7077 getTargetStreamer().emitDirectiveInsn();
7088 reportParseError(
"unexpected token, expected end of statement");
7092 MCSection *ELFSection = getContext().getELFSection(
7094 getParser().getStreamer().SwitchSection(ELFSection);
7103 bool MipsAsmParser::parseSSectionDirective(
StringRef Section,
unsigned Type) {
7106 reportParseError(
"unexpected token, expected end of statement");
7110 MCSection *ELFSection = getContext().getELFSection(
7112 getParser().getStreamer().SwitchSection(ELFSection);
7125 bool MipsAsmParser::parseDirectiveModule() {
7130 if (!getTargetStreamer().isModuleDirectiveAllowed()) {
7132 reportParseError(
".module directive must appear before any code");
7138 reportParseError(
"expected .module option identifier");
7142 if (Option ==
"oddspreg") {
7143 clearModuleFeatureBits(Mips::FeatureNoOddSPReg,
"nooddspreg");
7147 getTargetStreamer().updateABIInfo(*
this);
7152 getTargetStreamer().emitDirectiveModuleOddSPReg();
7156 reportParseError(
"unexpected token, expected end of statement");
7161 }
else if (Option ==
"nooddspreg") {
7163 return Error(L,
"'.module nooddspreg' requires the O32 ABI");
7166 setModuleFeatureBits(Mips::FeatureNoOddSPReg,
"nooddspreg");
7170 getTargetStreamer().updateABIInfo(*
this);
7175 getTargetStreamer().emitDirectiveModuleOddSPReg();
7179 reportParseError(
"unexpected token, expected end of statement");
7184 }
else if (Option ==
"fp") {
7185 return parseDirectiveModuleFP();
7186 }
else if (Option ==
"softfloat") {
7187 setModuleFeatureBits(Mips::FeatureSoftFloat,
"soft-float");
7191 getTargetStreamer().updateABIInfo(*
this);
7196 getTargetStreamer().emitDirectiveModuleSoftFloat();
7200 reportParseError(
"unexpected token, expected end of statement");
7205 }
else if (Option ==
"hardfloat") {
7206 clearModuleFeatureBits(Mips::FeatureSoftFloat,
"soft-float");
7210 getTargetStreamer().updateABIInfo(*
this);
7215 getTargetStreamer().emitDirectiveModuleHardFloat();
7219 reportParseError(
"unexpected token, expected end of statement");
7224 }
else if (Option ==
"mt") {
7225 setModuleFeatureBits(Mips::FeatureMT,
"mt");
7229 getTargetStreamer().updateABIInfo(*
this);
7234 getTargetStreamer().emitDirectiveModuleMT();
7238 reportParseError(
"unexpected token, expected end of statement");
7244 return Error(L,
"'" +
Twine(Option) +
"' is not a valid .module option.");
7252 bool MipsAsmParser::parseDirectiveModuleFP() {
7257 reportParseError(
"unexpected token, expected equals sign '='");
7263 if (!parseFpABIValue(FpABI,
".module"))
7267 reportParseError(
"unexpected token, expected end of statement");
7273 getTargetStreamer().updateABIInfo(*
this);
7278 getTargetStreamer().emitDirectiveModuleFP();
7288 bool ModuleLevelOptions = Directive ==
".module";
7294 if (Value !=
"xx") {
7295 reportParseError(
"unsupported value, expected 'xx', '32' or '64'");
7300 reportParseError(
"'" + Directive +
" fp=xx' requires the O32 ABI");
7305 if (ModuleLevelOptions) {
7306 setModuleFeatureBits(Mips::FeatureFPXX,
"fpxx");
7307 clearModuleFeatureBits(Mips::FeatureFP64Bit,
"fp64");
7309 setFeatureBits(Mips::FeatureFPXX,
"fpxx");
7310 clearFeatureBits(Mips::FeatureFP64Bit,
"fp64");
7319 if (Value != 32 && Value != 64) {
7320 reportParseError(
"unsupported value, expected 'xx', '32' or '64'");
7326 reportParseError(
"'" + Directive +
" fp=32' requires the O32 ABI");
7331 if (ModuleLevelOptions) {
7332 clearModuleFeatureBits(Mips::FeatureFPXX,
"fpxx");
7333 clearModuleFeatureBits(Mips::FeatureFP64Bit,
"fp64");
7335 clearFeatureBits(Mips::FeatureFPXX,
"fpxx");
7336 clearFeatureBits(Mips::FeatureFP64Bit,
"fp64");
7340 if (ModuleLevelOptions) {
7341 clearModuleFeatureBits(Mips::FeatureFPXX,
"fpxx");
7342 setModuleFeatureBits(Mips::FeatureFP64Bit,
"fp64");
7344 clearFeatureBits(Mips::FeatureFPXX,
"fpxx");
7345 setFeatureBits(Mips::FeatureFP64Bit,
"fp64");
7355 bool MipsAsmParser::ParseDirective(
AsmToken DirectiveID) {
7364 if (IDVal ==
".cpload") {
7365 parseDirectiveCpLoad(DirectiveID.
getLoc());
7368 if (IDVal ==
".cprestore") {
7369 parseDirectiveCpRestore(DirectiveID.
getLoc());
7372 if (IDVal ==
".dword") {
7373 parseDataDirective(8, DirectiveID.
getLoc());
7376 if (IDVal ==
".ent") {
7380 reportParseError(
"expected identifier after .ent");
7394 reportParseError(
"unexpected token, expected end of statement");
7398 const MCExpr *DummyNumber;
7399 int64_t DummyNumberVal;
7403 reportParseError(
"expected number after comma");
7406 if (!DummyNumber->evaluateAsAbsolute(DummyNumberVal)) {
7407 reportParseError(
"expected an absolute expression after comma");
7414 reportParseError(
"unexpected token, expected end of statement");
7418 MCSymbol *Sym = getContext().getOrCreateSymbol(SymbolName);
7420 getTargetStreamer().emitDirectiveEnt(*Sym);
7422 IsCpRestoreSet =
false;
7426 if (IDVal ==
".end") {
7430 reportParseError(
"expected identifier after .end");
7435 reportParseError(
"unexpected token, expected end of statement");
7439 if (CurrentFn ==
nullptr) {
7440 reportParseError(
".end used without .ent");
7444 if ((SymbolName != CurrentFn->getName())) {
7445 reportParseError(
".end symbol does not match .ent symbol");
7449 getTargetStreamer().emitDirectiveEnd(SymbolName);
7450 CurrentFn =
nullptr;
7451 IsCpRestoreSet =
false;
7455 if (IDVal ==
".frame") {
7460 reportParseError(
"expected stack register");
7464 MipsOperand &StackRegOpnd =
static_cast<MipsOperand &
>(*TmpReg[0]);
7465 if (!StackRegOpnd.isGPRAsmReg()) {
7466 reportParseError(StackRegOpnd.getStartLoc(),
7467 "expected general purpose register");
7470 unsigned StackReg = StackRegOpnd.getGPR32Reg();
7475 reportParseError(
"unexpected token, expected comma");
7481 int64_t FrameSizeVal;
7484 reportParseError(
"expected frame size value");
7488 if (!FrameSize->evaluateAsAbsolute(FrameSizeVal)) {
7489 reportParseError(
"frame size not an absolute expression");
7496 reportParseError(
"unexpected token, expected comma");
7502 ResTy = parseAnyRegister(TmpReg);
7504 reportParseError(
"expected return register");
7508 MipsOperand &ReturnRegOpnd =
static_cast<MipsOperand &
>(*TmpReg[0]);
7509 if (!ReturnRegOpnd.isGPRAsmReg()) {
7510 reportParseError(ReturnRegOpnd.getStartLoc(),
7511 "expected general purpose register");
7517 reportParseError(
"unexpected token, expected end of statement");
7521 getTargetStreamer().emitFrame(StackReg, FrameSizeVal,
7522 ReturnRegOpnd.getGPR32Reg());
7523 IsCpRestoreSet =
false;
7527 if (IDVal ==
".set") {
7528 parseDirectiveSet();
7532 if (IDVal ==
".mask" || IDVal ==
".fmask") {
7547 reportParseError(
"expected bitmask value");
7551 if (!BitMask->evaluateAsAbsolute(BitMaskVal)) {
7552 reportParseError(
"bitmask not an absolute expression");
7559 reportParseError(
"unexpected token, expected comma");
7564 const MCExpr *FrameOffset;
7565 int64_t FrameOffsetVal;
7568 reportParseError(
"expected frame offset value");
7572 if (!FrameOffset->evaluateAsAbsolute(FrameOffsetVal)) {
7573 reportParseError(
"frame offset not an absolute expression");
7579 reportParseError(
"unexpected token, expected end of statement");
7583 if (IDVal ==
".mask")
7584 getTargetStreamer().emitMask(BitMaskVal, FrameOffsetVal);
7586 getTargetStreamer().emitFMask(BitMaskVal, FrameOffsetVal);
7590 if (IDVal ==
".nan")
7591 return parseDirectiveNaN();
7593 if (IDVal ==
".gpword") {
7594 parseDirectiveGpWord();
7598 if (IDVal ==
".gpdword") {
7599 parseDirectiveGpDWord();
7603 if (IDVal ==
".dtprelword") {
7604 parseDirectiveDtpRelWord();
7608 if (IDVal ==
".dtpreldword") {
7609 parseDirectiveDtpRelDWord();
7613 if (IDVal ==
".tprelword") {
7614 parseDirectiveTpRelWord();
7618 if (IDVal ==
".tpreldword") {
7619 parseDirectiveTpRelDWord();
7623 if (IDVal ==
".word") {
7624 parseDataDirective(4, DirectiveID.
getLoc());
7628 if (IDVal ==
".hword") {
7629 parseDataDirective(2, DirectiveID.
getLoc());
7633 if (IDVal ==
".option") {
7634 parseDirectiveOption();
7638 if (IDVal ==
".abicalls") {
7639 getTargetStreamer().emitDirectiveAbiCalls();
7642 "unexpected token, expected end of statement");
7647 if (IDVal ==
".cpsetup") {
7648 parseDirectiveCPSetup();
7651 if (IDVal ==
".cpreturn") {
7652 parseDirectiveCPReturn();
7655 if (IDVal ==
".module") {
7656 parseDirectiveModule();
7659 if (IDVal ==
".llvm_internal_mips_reallow_module_directive") {
7660 parseInternalDirectiveReallowModule();
7663 if (IDVal ==
".insn") {
7664 parseInsnDirective();
7667 if (IDVal ==
".rdata") {
7668 parseRSectionDirective(
".rodata");
7671 if (IDVal ==
".sbss") {
7675 if (IDVal ==
".sdata") {
7683 bool MipsAsmParser::parseInternalDirectiveReallowModule() {
7686 reportParseError(
"unexpected token, expected end of statement");
7690 getTargetStreamer().reallowModuleDirective();
7703 #define GET_REGISTER_MATCHER
7704 #define GET_MATCHER_IMPLEMENTATION
7705 #include "MipsGenAsmMatcher.inc"
7707 bool MipsAsmParser::mnemonicIsValid(
StringRef Mnemonic,
unsigned VariantID) {
7709 const MatchEntry *Start, *
End;
7710 switch (VariantID) {
7715 auto MnemonicRange = std::equal_range(Start, End, Mnemonic, LessOpcode());
7716 return MnemonicRange.first != MnemonicRange.second;
static bool isReg(const MCInst &MI, unsigned OpNo)
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 emitRR(unsigned Opcode, unsigned Reg0, unsigned Reg1, SMLoc IDLoc, const MCSubtargetInfo *STI)
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.
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)
T findLastSet(T Val, ZeroBehavior ZB=ZB_Max)
Get the index of the last set bit starting from the least significant bit.
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
const MCSymbol & getSymbol() const
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
const char * getPointer() const
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
TokenKind getKind() const
void setFeatureBits(const FeatureBitset &FeatureBits_)
setFeatureBits - Set the feature bits.
This represents an "assembler immediate".
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
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)
MCTargetAsmParser - Generic interface to target specific assembly parsers.
bool mayStore() const
Return true if this instruction could possibly modify memory.
Describe properties that are true of each instruction in the target description file.
MachineInstrBuilder MachineInstrBuilder &DefMI const MCInstrDesc & Desc
Target specific streamer interface.
StringRef getString() const
Get the string for the current token, this includes all characters (for example, the quotes on string...
Target & getTheMipselTarget()
virtual void emitDirectiveSetNoReorder()
constexpr bool isInt< 8 >(int64_t x)
virtual const AsmToken & Lex()=0
Get the next AsmToken in the stream, possibly handling file inclusion first.
bool isNot(TokenKind K) const
constexpr bool isInt< 16 >(int64_t x)
SMLoc getLoc() const
Get the current source location.
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)
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)
static MCOperand createReg(unsigned Reg)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
void emitLoadWithImmOffset(unsigned Opcode, unsigned DstReg, unsigned BaseReg, int64_t Offset, unsigned TmpReg, SMLoc IDLoc, const MCSubtargetInfo *STI)
Emit a load instruction with an immediate offset.
Generic assembler lexer interface, for use by target specific assembly lexers.
std::pair< StringRef, StringRef > getToken(StringRef Source, StringRef Delimiters=" \t\n\v\f\r")
getToken - This function extracts one token from source, ignoring any leading characters that appear ...
bool isBranch() const
Returns true if this is a conditional, unconditional, or indirect branch.
bool isCall() const
Return true if the instruction is a call.
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.
LLVM_ATTRIBUTE_ALWAYS_INLINE R Default(const T &Value) const
Reg
All possible values of the reg field in the ModR/M byte.
Target independent representation for an assembler token.
static int getRegClass(RegisterKind Is, unsigned RegWidth)
Represent a reference to a symbol from inside an expression.
Windows NT (Windows on ARM)
MCContext & getContext() 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.
Context object for machine code objects.
void emitNop(SMLoc IDLoc, const MCSubtargetInfo *STI)
uint8_t OperandType
Information about the type of the operand.
LLVM_ATTRIBUTE_ALWAYS_INLINE StringSwitch & Case(const char(&S)[N], const T &Value)
bool isNot(AsmToken::TokenKind K) const
Check if the current token has kind K.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
unsigned getReg() const
Returns the register number.
Target & getTheMips64Target()
Unary assembler expressions.
Simple integer binary arithmetic operators.
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
static const fltSemantics & IEEEdouble() LLVM_READNONE
LLVM_NODISCARD char front() const
front - Get the first character in the string.
int64_t getIntVal() const
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
static bool isShiftedUIntAtAnyPosition(uint64_t x)
Can the value be represented by a unsigned N-bit value and a shift left?
const AsmToken & getTok() const
Get the current AsmToken from the stream.
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()
INITIALIZE_PASS(HexagonEarlyIfConversion,"hexagon-eif","Hexagon early if conversion", false, false) bool HexagonEarlyIfConversion MachineBasicBlock * SB
FeatureBitset ToggleFeature(uint64_t FB)
ToggleFeature - Toggle a feature and returns the re-computed feature bits.
const MCExpr * getExpr() 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()
MCTargetStreamer * getTargetStreamer()
Container class for subtarget features.
The instances of the Type class are immutable: once they are created, they are never changed...
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
HasFCCRegOperand - Instruction uses an $fcc<x> register.
static ManagedStatic< OptionRegistry > OR
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).
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...
void emitR(unsigned Opcode, unsigned Reg0, SMLoc IDLoc, const MCSubtargetInfo *STI)
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
static const unsigned End
static const MCSymbol * getSingleMCSymbol(const MCExpr *Expr)
static unsigned nextReg(unsigned Reg)
const AsmToken peekTok(bool ShouldSkipSpace=true)
Look ahead at the next token to be lexed.
Represents a single fixit, a replacement of one range of text with another.
bool isInSection(bool SetUsed=true) const
isInSection - Check if this symbol is defined in some section (i.e., it is defined but not absolute)...
bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
const MCSymbolRefExpr * getSymB() const
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.
bool is(AsmToken::TokenKind K) const
Check if the current token has kind K.
Triple - Helper class for working with autoconf configuration names.
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)
const MCSymbolRefExpr * getSymA() const
SMRange getLocRange() const
void emitDSLL(unsigned DstReg, unsigned SrcReg, int16_t ShiftAmount, SMLoc IDLoc, const MCSubtargetInfo *STI)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
void emitEmptyDelaySlot(bool hasShortDelaySlot, SMLoc IDLoc, const MCSubtargetInfo *STI)
bool mayLoad() const
Return true if this instruction could possibly read memory.
const FeatureBitset & getFeatureBits() const
getFeatureBits - Return the feature bits.
bool is(TokenKind K) const
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.
bool evaluateAsRelocatable(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const
Try to evaluate the expression to a relocatable value, i.e.
unsigned getOpcode() const
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
const MCExpr * getVariableValue(bool SetUsed=true) const
getVariableValue - Get the value for variable symbols.
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
Base class for user error types.
static const MipsMCExpr * create(MipsExprKind Kind, const MCExpr *Expr, MCContext &Ctx)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Target & getTheMipsTarget()
void emitStoreWithImmOffset(unsigned Opcode, unsigned SrcReg, unsigned BaseReg, int64_t Offset, function_ref< unsigned()> GetATReg, SMLoc IDLoc, const MCSubtargetInfo *STI)
Emit a store instruction with an offset.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
static SMLoc getFromPointer(const char *Ptr)
llvm_unreachable("Unknown RegBank!")
LLVM_ATTRIBUTE_ALWAYS_INLINE StringSwitch & Cases(const char(&S0)[N0], const char(&S1)[N1], const T &Value)
StringRef getIdentifier() const
Get the identifier string for the current token, which should be an identifier or a string...
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
RegisterMCAsmParser - Helper template for registering a target specific assembly parser, for use in the target machine initialization function.
StringRef getName() const
getName - Get the symbol name.
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.
unsigned getNumOperands() const
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
MCSubtargetInfo - Generic base class for all target subtargets.
bool hasDelaySlot() const
Returns true if the specified instruction has a delay slot which must be filled by the code generator...
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.
const Triple & getTargetTriple() const
getTargetTriple - Return the target triple string.
constexpr bool isUInt< 16 >(uint64_t x)
static bool hasShortDelaySlot(unsigned Opcode)
const MCInstrDesc MipsInsts[]
bool isVariable() const
isVariable - Check if this is a variable symbol.
static StringRef getCPU(StringRef CPU)
Processes a CPU name.
IsPCRelativeLoad - A Load instruction with implicit source register ($pc) with explicit offset and de...
void emitRRI(unsigned Opcode, unsigned Reg0, unsigned Reg1, int16_t Imm, SMLoc IDLoc, const MCSubtargetInfo *STI)
VariantKind getKind() const
void emitRRX(unsigned Opcode, unsigned Reg0, unsigned Reg1, MCOperand Op2, SMLoc IDLoc, const MCSubtargetInfo *STI)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
int64_t getConstant() const
virtual void emitDirectiveSetReorder()
LLVM Value Representation.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
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...
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).
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...
static FeatureBitset getFeatures(StringRef CPU, StringRef FS, ArrayRef< SubtargetFeatureKV > ProcDesc, ArrayRef< SubtargetFeatureKV > ProcFeatures)
Target specific expression.
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml","ocaml 3.10-compatible collector")
Represents a location in source code.
This holds information about one operand of a machine instruction, indicating the register class for ...
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)
const MCOperand & getOperand(unsigned i) const
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()