65#define DEBUG_TYPE "mips-asm-parser"
75class MipsAssemblerOptions {
77 MipsAssemblerOptions(
const FeatureBitset &Features_) : Features(Features_) {}
79 MipsAssemblerOptions(
const MipsAssemblerOptions *Opts) {
80 ATReg = Opts->getATRegIndex();
81 Reorder = Opts->isReorder();
82 Macro = Opts->isMacro();
83 Features = Opts->getFeatures();
86 unsigned getATRegIndex()
const {
return ATReg; }
87 bool setATRegIndex(
unsigned Reg) {
95 bool isReorder()
const {
return Reorder; }
96 void setReorder() { Reorder =
true; }
97 void setNoReorder() { Reorder =
false; }
99 bool isMacro()
const {
return Macro; }
100 void setMacro() {
Macro =
true; }
101 void setNoMacro() {
Macro =
false; }
103 const FeatureBitset &
getFeatures()
const {
return Features; }
104 void setFeatures(
const FeatureBitset &Features_) { Features = Features_; }
111 static const FeatureBitset AllArchRelatedMask;
117 FeatureBitset Features;
122const FeatureBitset MipsAssemblerOptions::AllArchRelatedMask = {
123 Mips::FeatureMips1, Mips::FeatureMips2, Mips::FeatureMips3,
124 Mips::FeatureMips3_32, Mips::FeatureMips3_32r2, Mips::FeatureMips4,
125 Mips::FeatureMips4_32, Mips::FeatureMips4_32r2, Mips::FeatureMips5,
126 Mips::FeatureMips5_32r2, Mips::FeatureMips32, Mips::FeatureMips32r2,
127 Mips::FeatureMips32r3, Mips::FeatureMips32r5, Mips::FeatureMips32r6,
128 Mips::FeatureMips64, Mips::FeatureMips64r2, Mips::FeatureMips64r3,
129 Mips::FeatureMips64r5, Mips::FeatureMips64r6, Mips::FeatureCnMips,
130 Mips::FeatureCnMipsP, Mips::FeatureFP64Bit, Mips::FeatureGP64Bit,
131 Mips::FeatureNaN2008, Mips::FeatureNanoMips};
136 MipsTargetStreamer &getTargetStreamer() {
137 assert(getParser().getStreamer().getTargetStreamer() &&
138 "do not have a target streamer");
139 MCTargetStreamer &TS = *getParser().getStreamer().getTargetStreamer();
140 return static_cast<MipsTargetStreamer &
>(TS);
143 const MipsMCOptions &CLOpts;
153 bool CurForbiddenSlotAttr;
156 unsigned CpSaveLocation;
158 bool CpSaveLocationIsRegister;
161 StringMap<AsmToken> RegisterSets;
164 void printWarningWithFixIt(
const Twine &
Msg,
const Twine &FixMsg,
165 SMRange
Range,
bool ShowColors =
true);
168 template <
unsigned Opcode,
bool IsMFTR>
169 void ConvertMTTransferCOP0Operands(MCInst &Inst,
172 ConvertMTTransferCOP0Operands<Mips::MFTR, true>(Inst,
Operands);
175 ConvertMTTransferCOP0Operands<Mips::MTTR, false>(Inst,
Operands);
178#define GET_ASSEMBLER_HEADER
179#include "MipsGenAsmMatcher.inc"
182 checkEarlyTargetMatchPredicate(
MCInst &Inst,
184 unsigned checkTargetMatchPredicate(
MCInst &Inst)
override;
186 bool matchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
189 bool MatchingInlineAsm)
override;
194 SMLoc &EndLoc)
override;
200 bool mnemonicIsValid(
StringRef Mnemonic,
unsigned VariantID);
205 bool ParseDirective(
AsmToken DirectiveID)
override;
209 const MCExpr *parseMemOffset();
220 const MCExpr *parseRelocExpr();
221 bool parsePrimaryExpr(
const MCExpr *&Res,
SMLoc &EndLoc)
override;
227 enum MacroExpanderResultTy {
234 MacroExpanderResultTy tryExpandInstruction(MCInst &Inst, SMLoc IDLoc,
236 const MCSubtargetInfo *STI);
238 bool expandJalWithRegs(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
239 const MCSubtargetInfo *STI);
241 bool loadImmediate(int64_t ImmValue, MCRegister DstReg, MCRegister SrcReg,
242 bool Is32BitImm,
bool IsAddress, SMLoc IDLoc,
243 MCStreamer &Out,
const MCSubtargetInfo *STI);
245 bool canDeferGOTLoad(
const MCSymbol *Sym);
247 bool loadAndAddSymbolAddress(
const MCExpr *SymExpr, MCRegister DstReg,
248 MCRegister SrcReg,
bool Is32BitSym, SMLoc IDLoc,
249 MCStreamer &Out,
const MCSubtargetInfo *STI);
251 bool emitPartialAddress(MipsTargetStreamer &TOut, SMLoc IDLoc, MCSymbol *Sym);
253 bool expandLoadImm(MCInst &Inst,
bool Is32BitImm, SMLoc IDLoc,
254 MCStreamer &Out,
const MCSubtargetInfo *STI);
256 bool expandLoadSingleImmToGPR(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
257 const MCSubtargetInfo *STI);
258 bool expandLoadSingleImmToFPR(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
259 const MCSubtargetInfo *STI);
260 bool expandLoadDoubleImmToGPR(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
261 const MCSubtargetInfo *STI);
262 bool expandLoadDoubleImmToFPR(MCInst &Inst,
bool Is64FPU, SMLoc IDLoc,
263 MCStreamer &Out,
const MCSubtargetInfo *STI);
265 bool expandLoadAddress(MCRegister DstReg, MCRegister BaseReg,
266 const MCOperand &
Offset,
bool Is32BitAddress,
267 SMLoc IDLoc, MCStreamer &Out,
268 const MCSubtargetInfo *STI);
270 bool expandUncondBranchMMPseudo(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
271 const MCSubtargetInfo *STI);
273 void expandMem16Inst(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
274 const MCSubtargetInfo *STI,
bool IsLoad);
275 void expandMem9Inst(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
276 const MCSubtargetInfo *STI,
bool IsLoad);
278 bool expandLoadStoreMultiple(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
279 const MCSubtargetInfo *STI);
281 bool expandAliasImmediate(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
282 const MCSubtargetInfo *STI);
284 bool expandBranchImm(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
285 const MCSubtargetInfo *STI);
287 bool expandCondBranches(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
288 const MCSubtargetInfo *STI);
290 bool expandDivRem(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
291 const MCSubtargetInfo *STI,
const bool IsMips64,
294 bool expandTrunc(MCInst &Inst,
bool IsDouble,
bool Is64FPU, SMLoc IDLoc,
295 MCStreamer &Out,
const MCSubtargetInfo *STI);
297 bool expandUlh(MCInst &Inst,
bool Signed, SMLoc IDLoc, MCStreamer &Out,
298 const MCSubtargetInfo *STI);
300 bool expandUsh(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
301 const MCSubtargetInfo *STI);
303 bool expandUxw(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
304 const MCSubtargetInfo *STI);
306 bool expandSge(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
307 const MCSubtargetInfo *STI);
309 bool expandSgeImm(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
310 const MCSubtargetInfo *STI);
312 bool expandSgtImm(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
313 const MCSubtargetInfo *STI);
315 bool expandSle(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
316 const MCSubtargetInfo *STI);
318 bool expandSleImm(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
319 const MCSubtargetInfo *STI);
321 bool expandRotation(MCInst &Inst, SMLoc IDLoc,
322 MCStreamer &Out,
const MCSubtargetInfo *STI);
323 bool expandRotationImm(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
324 const MCSubtargetInfo *STI);
325 bool expandDRotation(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
326 const MCSubtargetInfo *STI);
327 bool expandDRotationImm(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
328 const MCSubtargetInfo *STI);
330 bool expandAbs(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
331 const MCSubtargetInfo *STI);
333 bool expandMulImm(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
334 const MCSubtargetInfo *STI);
336 bool expandMulO(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
337 const MCSubtargetInfo *STI);
339 bool expandMulOU(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
340 const MCSubtargetInfo *STI);
342 bool expandDMULMacro(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
343 const MCSubtargetInfo *STI);
345 bool expandLoadStoreDMacro(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
346 const MCSubtargetInfo *STI,
bool IsLoad);
348 bool expandStoreDM1Macro(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
349 const MCSubtargetInfo *STI);
351 bool expandSeq(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
352 const MCSubtargetInfo *STI);
354 bool expandSeqI(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
355 const MCSubtargetInfo *STI);
357 bool expandSne(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
358 const MCSubtargetInfo *STI);
360 bool expandSneI(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
361 const MCSubtargetInfo *STI);
363 bool expandMXTRAlias(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
364 const MCSubtargetInfo *STI);
366 bool expandSaaAddr(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
367 const MCSubtargetInfo *STI);
369 bool reportParseError(
const Twine &ErrorMsg);
370 bool reportParseError(SMLoc Loc,
const Twine &ErrorMsg);
372 bool parseSetMips0Directive();
373 bool parseSetArchDirective();
374 bool parseSetFeature(
uint64_t Feature);
375 bool isPicAndNotNxxAbi();
376 bool parseDirectiveCpAdd(SMLoc Loc);
377 bool parseDirectiveCpLoad(SMLoc Loc);
378 bool parseDirectiveCpLocal(SMLoc Loc);
379 bool parseDirectiveCpRestore(SMLoc Loc);
380 bool parseDirectiveCPSetup();
381 bool parseDirectiveCPReturn();
382 bool parseDirectiveNaN();
383 bool parseDirectiveSet();
384 bool parseDirectiveOption();
385 bool parseInsnDirective();
386 bool parseRSectionDirective(StringRef Section);
387 bool parseSSectionDirective(StringRef Section,
unsigned Type);
389 bool parseSetAtDirective();
390 bool parseSetNoAtDirective();
391 bool parseSetMacroDirective();
392 bool parseSetNoMacroDirective();
393 bool parseSetMsaDirective();
394 bool parseSetNoMsaDirective();
395 bool parseSetNoDspDirective();
396 bool parseSetNoMips3DDirective();
397 bool parseSetReorderDirective();
398 bool parseSetNoReorderDirective();
399 bool parseSetMips16Directive();
400 bool parseSetNoMips16Directive();
401 bool parseSetFpDirective();
402 bool parseSetOddSPRegDirective();
403 bool parseSetNoOddSPRegDirective();
404 bool parseSetPopDirective();
405 bool parseSetPushDirective();
406 bool parseSetSoftFloatDirective();
407 bool parseSetHardFloatDirective();
408 bool parseSetMtDirective();
409 bool parseSetNoMtDirective();
410 bool parseSetNoCRCDirective();
411 bool parseSetNoVirtDirective();
412 bool parseSetNoGINVDirective();
413 bool parseSetNoEVADirective();
415 bool parseSetAssignment();
417 bool parseDirectiveGpWord();
418 bool parseDirectiveGpDWord();
419 bool parseDirectiveDtpRelWord();
420 bool parseDirectiveDtpRelDWord();
421 bool parseDirectiveTpRelWord();
422 bool parseDirectiveTpRelDWord();
423 bool parseDirectiveModule();
424 bool parseDirectiveModuleFP();
426 StringRef Directive);
428 bool parseInternalDirectiveReallowModule();
430 bool eatComma(StringRef ErrorStr);
432 int matchCPURegisterName(StringRef Symbol);
434 int matchHWRegsRegisterName(StringRef Symbol);
436 int matchFPURegisterName(StringRef Name);
438 int matchFCCRegisterName(StringRef Name);
440 int matchACRegisterName(StringRef Name);
442 int matchMSA128RegisterName(StringRef Name);
444 int matchMSA128CtrlRegisterName(StringRef Name);
446 MCRegister
getReg(
int RC,
int RegNo);
451 MCRegister getATReg(SMLoc Loc);
455 bool processInstruction(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
456 const MCSubtargetInfo *STI);
480 void selectArch(StringRef ArchFeature) {
481 MCSubtargetInfo &STI = copySTI();
483 FeatureBits &= ~MipsAssemblerOptions::AllArchRelatedMask;
485 setAvailableFeatures(
490 void setFeatureBits(
uint64_t Feature, StringRef FeatureString) {
492 MCSubtargetInfo &STI = copySTI();
493 setAvailableFeatures(
499 void clearFeatureBits(
uint64_t Feature, StringRef FeatureString) {
501 MCSubtargetInfo &STI = copySTI();
502 setAvailableFeatures(
508 void setModuleFeatureBits(
uint64_t Feature, StringRef FeatureString) {
509 setFeatureBits(Feature, FeatureString);
510 AssemblerOptions.front()->setFeatures(getSTI().getFeatureBits());
513 void clearModuleFeatureBits(
uint64_t Feature, StringRef FeatureString) {
514 clearFeatureBits(Feature, FeatureString);
515 AssemblerOptions.front()->setFeatures(getSTI().getFeatureBits());
519 enum MipsMatchResultTy {
520 Match_RequiresDifferentSrcAndDst = FIRST_TARGET_MATCH_RESULT_TY,
521 Match_RequiresDifferentOperands,
522 Match_RequiresNoZeroRegister,
523 Match_RequiresSameSrcAndDst,
524 Match_NoFCCRegisterForCurrentISA,
525 Match_NonZeroOperandForSync,
526 Match_NonZeroOperandForMTCX,
527 Match_RequiresPosSizeRange0_32,
528 Match_RequiresPosSizeRange33_64,
529 Match_RequiresPosSizeUImm6,
530#define GET_OPERAND_DIAGNOSTIC_TYPES
531#include "MipsGenAsmMatcher.inc"
532#undef GET_OPERAND_DIAGNOSTIC_TYPES
535 MipsAsmParser(
const MCSubtargetInfo &sti, MCAsmParser &parser,
536 const MCInstrInfo &MII)
537 : MCTargetAsmParser(sti, MII),
540 sti.getTargetTriple(),
550 setAvailableFeatures(ComputeAvailableFeatures(getSTI().getFeatureBits()));
553 AssemblerOptions.push_back(
554 std::make_unique<MipsAssemblerOptions>(getSTI().getFeatureBits()));
557 AssemblerOptions.push_back(
558 std::make_unique<MipsAssemblerOptions>(getSTI().getFeatureBits()));
560 getTargetStreamer().updateABIInfo(*
this);
562 if (!isABI_O32() && !useOddSPReg() != 0)
567 CurForbiddenSlotAttr =
false;
568 IsPicEnabled =
getContext().getObjectFileInfo()->isPositionIndependent();
570 IsCpRestoreSet =
false;
571 CpRestoreOffset = -1;
572 GPReg = ABI.GetGlobalPtr();
577 if (getSTI().
getCPU() ==
"mips64r6" && inMicroMipsMode())
580 if (!isABI_O32() && inMicroMipsMode())
585 bool hasEightFccRegisters()
const {
return hasMips4() || hasMips32(); }
587 bool isGP64bit()
const {
588 return getSTI().hasFeature(Mips::FeatureGP64Bit);
591 bool isFP64bit()
const {
592 return getSTI().hasFeature(Mips::FeatureFP64Bit);
595 bool isJalrRelocAvailable(
const MCExpr *JalExpr) {
596 if (!CLOpts.jalr_reloc)
604 return ABI.IsN32() || ABI.IsN64();
608 const MipsABIInfo &
getABI()
const {
return ABI; }
609 bool isABI_N32()
const {
return ABI.IsN32(); }
610 bool isABI_N64()
const {
return ABI.IsN64(); }
611 bool isABI_O32()
const {
return ABI.IsO32(); }
612 bool isABI_FPXX()
const {
613 return getSTI().hasFeature(Mips::FeatureFPXX);
616 bool useOddSPReg()
const {
617 return !(getSTI().hasFeature(Mips::FeatureNoOddSPReg));
620 bool inMicroMipsMode()
const {
621 return getSTI().hasFeature(Mips::FeatureMicroMips);
624 bool hasMips1()
const {
625 return getSTI().hasFeature(Mips::FeatureMips1);
628 bool hasMips2()
const {
629 return getSTI().hasFeature(Mips::FeatureMips2);
632 bool hasMips3()
const {
633 return getSTI().hasFeature(Mips::FeatureMips3);
636 bool hasMips4()
const {
637 return getSTI().hasFeature(Mips::FeatureMips4);
640 bool hasMips5()
const {
641 return getSTI().hasFeature(Mips::FeatureMips5);
644 bool hasMips32()
const {
645 return getSTI().hasFeature(Mips::FeatureMips32);
648 bool hasMips64()
const {
649 return getSTI().hasFeature(Mips::FeatureMips64);
652 bool hasMips32r2()
const {
653 return getSTI().hasFeature(Mips::FeatureMips32r2);
656 bool hasMips64r2()
const {
657 return getSTI().hasFeature(Mips::FeatureMips64r2);
660 bool hasMips32r3()
const {
661 return (getSTI().
hasFeature(Mips::FeatureMips32r3));
664 bool hasMips64r3()
const {
665 return (getSTI().
hasFeature(Mips::FeatureMips64r3));
668 bool hasMips32r5()
const {
669 return (getSTI().
hasFeature(Mips::FeatureMips32r5));
672 bool hasMips64r5()
const {
673 return (getSTI().
hasFeature(Mips::FeatureMips64r5));
676 bool hasMips32r6()
const {
677 return getSTI().hasFeature(Mips::FeatureMips32r6);
680 bool hasMips64r6()
const {
681 return getSTI().hasFeature(Mips::FeatureMips64r6);
684 bool hasNanoMips()
const {
685 return getSTI().hasFeature(Mips::FeatureNanoMips);
688 bool hasDSP()
const {
689 return getSTI().hasFeature(Mips::FeatureDSP);
692 bool hasDSPR2()
const {
693 return getSTI().hasFeature(Mips::FeatureDSPR2);
696 bool hasDSPR3()
const {
697 return getSTI().hasFeature(Mips::FeatureDSPR3);
700 bool hasMSA()
const {
701 return getSTI().hasFeature(Mips::FeatureMSA);
704 bool hasCnMips()
const {
705 return (getSTI().
hasFeature(Mips::FeatureCnMips));
708 bool hasCnMipsP()
const {
709 return (getSTI().
hasFeature(Mips::FeatureCnMipsP));
712 bool isR5900()
const {
return (getSTI().
hasFeature(Mips::FeatureR5900)); }
718 bool inMips16Mode()
const {
719 return getSTI().hasFeature(Mips::FeatureMips16);
722 bool useTraps()
const {
723 return getSTI().hasFeature(Mips::FeatureUseTCCInDIV);
726 bool useSoftFloat()
const {
727 return getSTI().hasFeature(Mips::FeatureSoftFloat);
730 bool isSingleFloat()
const {
731 return getSTI().hasFeature(Mips::FeatureSingleFloat);
735 return getSTI().hasFeature(Mips::FeatureMT);
738 bool hasCRC()
const {
739 return getSTI().hasFeature(Mips::FeatureCRC);
742 bool hasVirt()
const {
743 return getSTI().hasFeature(Mips::FeatureVirt);
746 bool hasGINV()
const {
747 return getSTI().hasFeature(Mips::FeatureGINV);
750 bool hasForbiddenSlot(
const MCInstrDesc &MCID)
const {
754 bool SafeInForbiddenSlot(
const MCInstrDesc &MCID)
const {
758 void onEndOfFile()
override;
761 void warnIfRegIndexIsAT(MCRegister RegIndex, SMLoc Loc);
763 void warnIfNoMacro(SMLoc Loc);
765 bool isLittle()
const {
return IsLittleEndian; }
767 bool areEqualRegs(
const MCParsedAsmOperand &Op1,
768 const MCParsedAsmOperand &Op2)
const override;
783 RegKind_MSACtrl = 16,
788 RegKind_HWRegs = 256,
792 RegKind_Numeric = RegKind_GPR | RegKind_FGR | RegKind_FCC | RegKind_MSA128 |
793 RegKind_MSACtrl | RegKind_COP2 | RegKind_ACC |
794 RegKind_CCR | RegKind_HWRegs | RegKind_COP3 | RegKind_COP0
807 MipsOperand(KindTy K, MipsAsmParser &Parser) : Kind(
K), AsmParser(Parser) {}
809 ~MipsOperand()
override {
818 case k_RegisterIndex:
826 MipsAsmParser &AsmParser;
837 const MCRegisterInfo *RegInfo;
855 struct RegIdxOp RegIdx;
858 struct RegListOp RegList;
861 SMLoc StartLoc, EndLoc;
864 static std::unique_ptr<MipsOperand> CreateReg(
unsigned Index, StringRef Str,
866 const MCRegisterInfo *RegInfo,
868 MipsAsmParser &Parser) {
869 auto Op = std::make_unique<MipsOperand>(k_RegisterIndex, Parser);
871 Op->RegIdx.RegInfo = RegInfo;
872 Op->RegIdx.Kind = RegKind;
873 Op->RegIdx.Tok.Data = Str.data();
874 Op->RegIdx.Tok.Length = Str.size();
883 MCRegister getGPR32Reg()
const {
884 assert(isRegIdx() && (RegIdx.Kind & RegKind_GPR) &&
"Invalid access!");
885 AsmParser.warnIfRegIndexIsAT(RegIdx.Index, StartLoc);
886 unsigned ClassID = Mips::GPR32RegClassID;
887 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
892 MCRegister getGPRMM16Reg()
const {
893 assert(isRegIdx() && (RegIdx.Kind & RegKind_GPR) &&
"Invalid access!");
894 unsigned ClassID = Mips::GPR32RegClassID;
895 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
900 MCRegister getGPR64Reg()
const {
901 assert(isRegIdx() && (RegIdx.Kind & RegKind_GPR) &&
"Invalid access!");
902 unsigned ClassID = Mips::GPR64RegClassID;
903 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
909 MCRegister getAFGR64Reg()
const {
910 assert(isRegIdx() && (RegIdx.Kind & RegKind_FGR) &&
"Invalid access!");
911 if (RegIdx.Index % 2 != 0)
912 AsmParser.Warning(StartLoc,
"Float register should be even.");
913 return RegIdx.RegInfo->getRegClass(Mips::AFGR64RegClassID)
914 .getRegister(RegIdx.Index / 2);
919 MCRegister getFGR64Reg()
const {
920 assert(isRegIdx() && (RegIdx.Kind & RegKind_FGR) &&
"Invalid access!");
921 return RegIdx.RegInfo->getRegClass(Mips::FGR64RegClassID)
922 .getRegister(RegIdx.Index);
927 MCRegister getFGR32Reg()
const {
928 assert(isRegIdx() && (RegIdx.Kind & RegKind_FGR) &&
"Invalid access!");
929 return RegIdx.RegInfo->getRegClass(Mips::FGR32RegClassID)
930 .getRegister(RegIdx.Index);
935 MCRegister getFCCReg()
const {
936 assert(isRegIdx() && (RegIdx.Kind & RegKind_FCC) &&
"Invalid access!");
937 return RegIdx.RegInfo->getRegClass(Mips::FCCRegClassID)
938 .getRegister(RegIdx.Index);
943 MCRegister getMSA128Reg()
const {
944 assert(isRegIdx() && (RegIdx.Kind & RegKind_MSA128) &&
"Invalid access!");
947 unsigned ClassID = Mips::MSA128BRegClassID;
948 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
953 MCRegister getMSACtrlReg()
const {
954 assert(isRegIdx() && (RegIdx.Kind & RegKind_MSACtrl) &&
"Invalid access!");
955 unsigned ClassID = Mips::MSACtrlRegClassID;
956 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
961 MCRegister getCOP0Reg()
const {
967 MCRegister getCOP2Reg()
const {
968 assert(isRegIdx() && (RegIdx.Kind & RegKind_COP2) &&
"Invalid access!");
969 unsigned ClassID = Mips::COP2RegClassID;
970 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
975 MCRegister getCOP3Reg()
const {
976 assert(isRegIdx() && (RegIdx.Kind & RegKind_COP3) &&
"Invalid access!");
977 unsigned ClassID = Mips::COP3RegClassID;
978 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
983 MCRegister getACC64DSPReg()
const {
984 assert(isRegIdx() && (RegIdx.Kind & RegKind_ACC) &&
"Invalid access!");
985 unsigned ClassID = Mips::ACC64DSPRegClassID;
986 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
991 MCRegister getHI32DSPReg()
const {
992 assert(isRegIdx() && (RegIdx.Kind & RegKind_ACC) &&
"Invalid access!");
993 unsigned ClassID = Mips::HI32DSPRegClassID;
994 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
999 MCRegister getLO32DSPReg()
const {
1000 assert(isRegIdx() && (RegIdx.Kind & RegKind_ACC) &&
"Invalid access!");
1001 unsigned ClassID = Mips::LO32DSPRegClassID;
1002 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
1007 MCRegister getCCRReg()
const {
1008 assert(isRegIdx() && (RegIdx.Kind & RegKind_CCR) &&
"Invalid access!");
1009 unsigned ClassID = Mips::CCRRegClassID;
1010 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
1015 MCRegister getHWRegsReg()
const {
1016 assert(isRegIdx() && (RegIdx.Kind & RegKind_HWRegs) &&
"Invalid access!");
1017 unsigned ClassID = Mips::HWRegsRegClassID;
1018 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
1022 void addExpr(MCInst &Inst,
const MCExpr *Expr)
const {
1032 void addRegOperands(MCInst &Inst,
unsigned N)
const {
1039 void addGPR32ZeroAsmRegOperands(MCInst &Inst,
unsigned N)
const {
1040 assert(
N == 1 &&
"Invalid number of operands!");
1044 void addGPR32NonZeroAsmRegOperands(MCInst &Inst,
unsigned N)
const {
1045 assert(
N == 1 &&
"Invalid number of operands!");
1049 void addGPR32AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1050 assert(
N == 1 &&
"Invalid number of operands!");
1054 void addGPRMM16AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1055 assert(
N == 1 &&
"Invalid number of operands!");
1059 void addGPRMM16AsmRegZeroOperands(MCInst &Inst,
unsigned N)
const {
1060 assert(
N == 1 &&
"Invalid number of operands!");
1064 void addGPRMM16AsmRegMovePOperands(MCInst &Inst,
unsigned N)
const {
1065 assert(
N == 1 &&
"Invalid number of operands!");
1069 void addGPRMM16AsmRegMovePPairFirstOperands(MCInst &Inst,
unsigned N)
const {
1070 assert(
N == 1 &&
"Invalid number of operands!");
1074 void addGPRMM16AsmRegMovePPairSecondOperands(MCInst &Inst,
1076 assert(
N == 1 &&
"Invalid number of operands!");
1083 void addGPR64AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1084 assert(
N == 1 &&
"Invalid number of operands!");
1088 void addAFGR64AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1089 assert(
N == 1 &&
"Invalid number of operands!");
1093 void addStrictlyAFGR64AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1094 assert(
N == 1 &&
"Invalid number of operands!");
1098 void addStrictlyFGR64AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1099 assert(
N == 1 &&
"Invalid number of operands!");
1103 void addFGR64AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1104 assert(
N == 1 &&
"Invalid number of operands!");
1108 void addFGR32AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1109 assert(
N == 1 &&
"Invalid number of operands!");
1113 if (!AsmParser.useOddSPReg() && RegIdx.Index & 1)
1114 AsmParser.getParser().printError(
1115 StartLoc,
"-mno-odd-spreg prohibits the use of odd FPU "
1119 void addStrictlyFGR32AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1120 assert(
N == 1 &&
"Invalid number of operands!");
1123 if (!AsmParser.useOddSPReg() && RegIdx.Index & 1)
1124 AsmParser.Error(StartLoc,
"-mno-odd-spreg prohibits the use of odd FPU "
1128 void addFCCAsmRegOperands(MCInst &Inst,
unsigned N)
const {
1129 assert(
N == 1 &&
"Invalid number of operands!");
1133 void addMSA128AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1134 assert(
N == 1 &&
"Invalid number of operands!");
1138 void addMSACtrlAsmRegOperands(MCInst &Inst,
unsigned N)
const {
1139 assert(
N == 1 &&
"Invalid number of operands!");
1143 void addCOP0AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1144 assert(
N == 1 &&
"Invalid number of operands!");
1148 void addCOP2AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1149 assert(
N == 1 &&
"Invalid number of operands!");
1153 void addCOP3AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1154 assert(
N == 1 &&
"Invalid number of operands!");
1158 void addACC64DSPAsmRegOperands(MCInst &Inst,
unsigned N)
const {
1159 assert(
N == 1 &&
"Invalid number of operands!");
1163 void addHI32DSPAsmRegOperands(MCInst &Inst,
unsigned N)
const {
1164 assert(
N == 1 &&
"Invalid number of operands!");
1168 void addLO32DSPAsmRegOperands(MCInst &Inst,
unsigned N)
const {
1169 assert(
N == 1 &&
"Invalid number of operands!");
1173 void addCCRAsmRegOperands(MCInst &Inst,
unsigned N)
const {
1174 assert(
N == 1 &&
"Invalid number of operands!");
1178 void addHWRegsAsmRegOperands(MCInst &Inst,
unsigned N)
const {
1179 assert(
N == 1 &&
"Invalid number of operands!");
1183 template <
unsigned Bits,
int Offset = 0,
int AdjustOffset = 0>
1184 void addConstantUImmOperands(MCInst &Inst,
unsigned N)
const {
1185 assert(
N == 1 &&
"Invalid number of operands!");
1189 Imm += AdjustOffset;
1193 template <
unsigned Bits>
1194 void addSImmOperands(MCInst &Inst,
unsigned N)
const {
1195 if (isImm() && !isConstantImm()) {
1199 addConstantSImmOperands<Bits, 0, 0>(Inst,
N);
1202 template <
unsigned Bits>
1203 void addUImmOperands(MCInst &Inst,
unsigned N)
const {
1204 if (isImm() && !isConstantImm()) {
1208 addConstantUImmOperands<Bits, 0, 0>(Inst,
N);
1211 template <
unsigned Bits,
int Offset = 0,
int AdjustOffset = 0>
1212 void addConstantSImmOperands(MCInst &Inst,
unsigned N)
const {
1213 assert(
N == 1 &&
"Invalid number of operands!");
1214 int64_t
Imm = getConstantImm() -
Offset;
1217 Imm += AdjustOffset;
1221 void addImmOperands(MCInst &Inst,
unsigned N)
const {
1222 assert(
N == 1 &&
"Invalid number of operands!");
1223 const MCExpr *Expr =
getImm();
1224 addExpr(Inst, Expr);
1227 void addPtrRegOperands(MCInst &Inst,
unsigned N)
const {
1228 assert(
N == 1 &&
"Invalid number of operands!");
1230 AsmParser.getABI().ArePtrs64bit() ? getGPR64Reg() : getGPR32Reg()));
1233 void addMemOperands(MCInst &Inst,
unsigned N)
const {
1234 assert(
N == 2 &&
"Invalid number of operands!");
1235 getMemBase()->addPtrRegOperands(Inst, 1);
1236 addExpr(Inst, getMemOff());
1239 bool isSPAsmReg()
const {
return isGPRAsmReg() && RegIdx.Index == 29; }
1240 bool isGPAsmReg()
const {
return isGPRAsmReg() && RegIdx.Index == 28; }
1242 bool isSImmPtr()
const {
1243 return AsmParser.getABI().ArePtrs64bit() ? isScaledSImm<64, 0>()
1244 : isScaledSImm<32, 0>();
1247 void addRegListOperands(MCInst &Inst,
unsigned N)
const {
1248 assert(
N == 1 &&
"Invalid number of operands!");
1250 for (
auto RegNo : getRegList())
1254 bool isReg()
const override {
1257 return isGPRAsmReg() && RegIdx.Index == 0;
1260 bool isRegIdx()
const {
return Kind == k_RegisterIndex; }
1262 bool isNumericReg()
const {
1263 return isRegIdx() && RegIdx.Kind == RegKind_Numeric && RegIdx.Index < 32;
1266 unsigned getNumericRegIndex()
const {
1267 assert(isNumericReg() &&
"Invalid numeric register");
1268 return RegIdx.Index;
1271 bool isImm()
const override {
return Kind == k_Immediate; }
1273 bool isConstantImm()
const {
1275 return isImm() &&
getImm()->evaluateAsAbsolute(Res);
1278 bool isConstantImmz()
const {
1279 return isConstantImm() && getConstantImm() == 0;
1282 template <
unsigned Bits,
int Offset = 0>
bool isConstantUImm()
const {
1286 template <
unsigned Bits>
bool isSImm()
const {
1290 if (
getImm()->evaluateAsAbsolute(Res))
1296 template <
unsigned Bits>
bool isUImm()
const {
1300 if (
getImm()->evaluateAsAbsolute(Res))
1306 template <
unsigned Bits>
bool isAnyImm()
const {
1307 return isConstantImm() ? (
isInt<Bits>(getConstantImm()) ||
1312 template <
unsigned Bits,
int Offset = 0>
bool isConstantSImm()
const {
1316 template <
unsigned Bottom,
unsigned Top>
bool isConstantUImmRange()
const {
1317 return isConstantImm() && getConstantImm() >= Bottom &&
1318 getConstantImm() <= Top;
1321 bool isToken()
const override {
1324 return Kind == k_Token;
1327 bool isMem()
const override {
return Kind == k_Memory; }
1332 template <
unsigned Bits,
unsigned ShiftLeftAmount,
int Bias = 0>
1333 bool isScaledUImm()
const {
1335 uint64_t(getConstantImm()) - Bias);
1338 template <
unsigned Bits,
unsigned ShiftLeftAmount>
1339 bool isScaledSImm()
const {
1340 if (isConstantImm() &&
1345 if (Kind != k_Immediate)
1350 bool Success =
getImm()->evaluateAsRelocatable(Res,
nullptr);
1354 bool isRegList16()
const {
1358 int Size = RegList.List->size();
1362 MCRegister R0 = RegList.List->front();
1363 MCRegister R1 = RegList.List->back();
1364 if (!((R0 == Mips::R16 && R1 ==
Mips::RA) ||
1368 MCRegister PrevReg = RegList.List->front();
1369 for (
int i = 1; i <
Size - 1; i++) {
1370 MCRegister
Reg = (*(RegList.List))[i];
1371 if (
Reg != PrevReg + 1)
1379 bool isInvNum()
const {
return Kind == k_Immediate; }
1381 bool isLSAImm()
const {
1382 if (!isConstantImm())
1384 int64_t Val = getConstantImm();
1385 return 1 <= Val && Val <= 4;
1388 bool isRegList()
const {
return Kind == k_RegList; }
1391 assert(Kind == k_Token &&
"Invalid access!");
1392 return StringRef(Tok.Data, Tok.Length);
1395 MCRegister
getReg()
const override {
1398 if (Kind == k_RegisterIndex && RegIdx.Index == 0 &&
1399 RegIdx.Kind & RegKind_GPR)
1400 return getGPR32Reg();
1406 const MCExpr *
getImm()
const {
1407 assert((Kind == k_Immediate) &&
"Invalid access!");
1411 int64_t getConstantImm()
const {
1412 const MCExpr *Val =
getImm();
1414 (void)Val->evaluateAsAbsolute(
Value);
1418 MipsOperand *getMemBase()
const {
1419 assert((Kind == k_Memory) &&
"Invalid access!");
1423 const MCExpr *getMemOff()
const {
1424 assert((Kind == k_Memory) &&
"Invalid access!");
1428 const SmallVectorImpl<MCRegister> &getRegList()
const {
1429 assert((Kind == k_RegList) &&
"Invalid access!");
1430 return *(RegList.List);
1433 static std::unique_ptr<MipsOperand> CreateToken(StringRef Str, SMLoc S,
1434 MipsAsmParser &Parser) {
1435 auto Op = std::make_unique<MipsOperand>(k_Token, Parser);
1436 Op->Tok.Data = Str.data();
1437 Op->Tok.Length = Str.size();
1445 static std::unique_ptr<MipsOperand>
1446 createNumericReg(
unsigned Index, StringRef Str,
const MCRegisterInfo *RegInfo,
1447 SMLoc S, SMLoc
E, MipsAsmParser &Parser) {
1448 LLVM_DEBUG(
dbgs() <<
"createNumericReg(" << Index <<
", ...)\n");
1449 return CreateReg(Index, Str, RegKind_Numeric, RegInfo, S,
E, Parser);
1454 static std::unique_ptr<MipsOperand>
1455 createGPRReg(
unsigned Index, StringRef Str,
const MCRegisterInfo *RegInfo,
1456 SMLoc S, SMLoc
E, MipsAsmParser &Parser) {
1457 return CreateReg(Index, Str, RegKind_GPR, RegInfo, S,
E, Parser);
1462 static std::unique_ptr<MipsOperand>
1463 createFGRReg(
unsigned Index, StringRef Str,
const MCRegisterInfo *RegInfo,
1464 SMLoc S, SMLoc
E, MipsAsmParser &Parser) {
1465 return CreateReg(Index, Str, RegKind_FGR, RegInfo, S,
E, Parser);
1468 static std::unique_ptr<MipsOperand>
1469 createCOP0Reg(
unsigned Encoding, StringRef Str,
const MCRegisterInfo *RegInfo,
1470 SMLoc S, SMLoc
E, MipsAsmParser &Parser) {
1473 "Invalid COP0 register encoding");
1474 return CreateReg(Encoding, Str, RegKind_COP0, RegInfo, S,
E, Parser);
1479 static std::unique_ptr<MipsOperand>
1480 createHWRegsReg(
unsigned Index, StringRef Str,
const MCRegisterInfo *RegInfo,
1481 SMLoc S, SMLoc
E, MipsAsmParser &Parser) {
1482 return CreateReg(Index, Str, RegKind_HWRegs, RegInfo, S,
E, Parser);
1487 static std::unique_ptr<MipsOperand>
1488 createFCCReg(
unsigned Index, StringRef Str,
const MCRegisterInfo *RegInfo,
1489 SMLoc S, SMLoc
E, MipsAsmParser &Parser) {
1490 return CreateReg(Index, Str, RegKind_FCC, RegInfo, S,
E, Parser);
1495 static std::unique_ptr<MipsOperand>
1496 createACCReg(
unsigned Index, StringRef Str,
const MCRegisterInfo *RegInfo,
1497 SMLoc S, SMLoc
E, MipsAsmParser &Parser) {
1498 return CreateReg(Index, Str, RegKind_ACC, RegInfo, S,
E, Parser);
1503 static std::unique_ptr<MipsOperand>
1504 createMSA128Reg(
unsigned Index, StringRef Str,
const MCRegisterInfo *RegInfo,
1505 SMLoc S, SMLoc
E, MipsAsmParser &Parser) {
1506 return CreateReg(Index, Str, RegKind_MSA128, RegInfo, S,
E, Parser);
1511 static std::unique_ptr<MipsOperand>
1512 createMSACtrlReg(
unsigned Index, StringRef Str,
const MCRegisterInfo *RegInfo,
1513 SMLoc S, SMLoc
E, MipsAsmParser &Parser) {
1514 return CreateReg(Index, Str, RegKind_MSACtrl, RegInfo, S,
E, Parser);
1517 static std::unique_ptr<MipsOperand>
1518 CreateImm(
const MCExpr *Val, SMLoc S, SMLoc
E, MipsAsmParser &Parser) {
1519 auto Op = std::make_unique<MipsOperand>(k_Immediate, Parser);
1526 static std::unique_ptr<MipsOperand>
1527 CreateMem(std::unique_ptr<MipsOperand>
Base,
const MCExpr *
Off, SMLoc S,
1528 SMLoc
E, MipsAsmParser &Parser) {
1529 auto Op = std::make_unique<MipsOperand>(k_Memory, Parser);
1530 Op->Mem.Base =
Base.release();
1537 static std::unique_ptr<MipsOperand>
1538 CreateRegList(SmallVectorImpl<MCRegister> &Regs, SMLoc StartLoc, SMLoc EndLoc,
1539 MipsAsmParser &Parser) {
1540 assert(!Regs.
empty() &&
"Empty list not allowed");
1542 auto Op = std::make_unique<MipsOperand>(k_RegList, Parser);
1545 Op->StartLoc = StartLoc;
1546 Op->EndLoc = EndLoc;
1550 bool isGPRZeroAsmReg()
const {
1551 return isRegIdx() && RegIdx.Kind & RegKind_GPR && RegIdx.Index == 0;
1554 bool isGPRNonZeroAsmReg()
const {
1555 return isRegIdx() && RegIdx.Kind & RegKind_GPR && RegIdx.Index > 0 &&
1559 bool isGPRAsmReg()
const {
1560 return isRegIdx() && RegIdx.Kind & RegKind_GPR && RegIdx.Index <= 31;
1563 bool isMM16AsmReg()
const {
1566 return ((RegIdx.Index >= 2 && RegIdx.Index <= 7)
1567 || RegIdx.Index == 16 || RegIdx.Index == 17);
1570 bool isMM16AsmRegZero()
const {
1573 return (RegIdx.Index == 0 ||
1574 (RegIdx.Index >= 2 && RegIdx.Index <= 7) ||
1575 RegIdx.Index == 17);
1578 bool isMM16AsmRegMoveP()
const {
1579 if (!(isRegIdx() && RegIdx.Kind))
1581 return (RegIdx.Index == 0 || (RegIdx.Index >= 2 && RegIdx.Index <= 3) ||
1582 (RegIdx.Index >= 16 && RegIdx.Index <= 20));
1585 bool isMM16AsmRegMovePPairFirst()
const {
1586 if (!(isRegIdx() && RegIdx.Kind))
1588 return RegIdx.Index >= 4 && RegIdx.Index <= 6;
1591 bool isMM16AsmRegMovePPairSecond()
const {
1592 if (!(isRegIdx() && RegIdx.Kind))
1594 return (RegIdx.Index == 21 || RegIdx.Index == 22 ||
1595 (RegIdx.Index >= 5 && RegIdx.Index <= 7));
1598 bool isFGRAsmReg()
const {
1600 return isRegIdx() && RegIdx.Kind & RegKind_FGR && RegIdx.Index <= 31;
1603 bool isStrictlyFGRAsmReg()
const {
1605 return isRegIdx() && RegIdx.Kind == RegKind_FGR && RegIdx.Index <= 31;
1608 bool isHWRegsAsmReg()
const {
1609 return isRegIdx() && RegIdx.Kind & RegKind_HWRegs && RegIdx.Index <= 31;
1612 bool isCCRAsmReg()
const {
1613 return isRegIdx() && RegIdx.Kind & RegKind_CCR && RegIdx.Index <= 31;
1616 bool isFCCAsmReg()
const {
1617 if (!(isRegIdx() && RegIdx.Kind & RegKind_FCC))
1619 return RegIdx.Index <= 7;
1622 bool isACCAsmReg()
const {
1623 return isRegIdx() && RegIdx.Kind & RegKind_ACC && RegIdx.Index <= 3;
1626 bool isCOP0AsmReg()
const {
1627 return isRegIdx() && RegIdx.Kind == RegKind_COP0;
1630 unsigned getCOP0Encoding()
const {
1631 assert(isCOP0AsmReg() &&
"Invalid COP0 register");
1632 return RegIdx.Index;
1635 bool isCOP2AsmReg()
const {
1636 return isRegIdx() && RegIdx.Kind & RegKind_COP2 && RegIdx.Index <= 31;
1639 bool isCOP3AsmReg()
const {
1640 return isRegIdx() && RegIdx.Kind & RegKind_COP3 && RegIdx.Index <= 31;
1643 bool isMSA128AsmReg()
const {
1644 return isRegIdx() && RegIdx.Kind & RegKind_MSA128 && RegIdx.Index <= 31;
1647 bool isMSACtrlAsmReg()
const {
1648 return isRegIdx() && RegIdx.Kind & RegKind_MSACtrl && RegIdx.Index <= 7;
1651 bool isNM16AsmReg()
const {
1652 if (!(isRegIdx() && RegIdx.Kind))
1654 return ((RegIdx.Index >= 4 && RegIdx.Index <= 7) ||
1655 (RegIdx.Index >= 16 && RegIdx.Index <= 19));
1658 bool isNM16ZeroAsmReg()
const {
1659 if (!(isRegIdx() && RegIdx.Kind))
1661 return ((RegIdx.Index == 0) || (RegIdx.Index >= 4 && RegIdx.Index <= 7) ||
1662 (RegIdx.Index >= 17 && RegIdx.Index <= 19));
1665 bool isNM4AsmReg()
const {
1666 if (!(isRegIdx() && RegIdx.Kind))
1668 return ((RegIdx.Index >= 4 && RegIdx.Index <= 11) ||
1669 (RegIdx.Index >= 16 && RegIdx.Index <= 23));
1672 bool isNM4ZeroAsmReg()
const {
1673 if (!(isRegIdx() && RegIdx.Kind))
1675 return ((RegIdx.Index == 0) || (RegIdx.Index >= 4 && RegIdx.Index <= 10) ||
1676 (RegIdx.Index >= 16 && RegIdx.Index <= 23));
1679 bool isNM2R1AsmReg()
const {
1680 if (!(isRegIdx() && RegIdx.Kind))
1682 return RegIdx.Index >= 4 && RegIdx.Index <= 7;
1685 bool isNM2R2AsmReg()
const {
1686 if (!(isRegIdx() && RegIdx.Kind))
1688 return RegIdx.Index >= 5 && RegIdx.Index <= 8;
1691 bool isNM1R1AsmReg()
const {
1692 if (!(isRegIdx() && RegIdx.Kind))
1694 return RegIdx.Index == 4 || RegIdx.Index == 5;
1697 template <
unsigned RegClassID = Mips::GPR32RegClassID>
1698 bool isGPRNMAsmReg()
const {
1699 if (!(isRegIdx() && RegIdx.Kind))
1701 switch (RegClassID) {
1702 case Mips::GP32RegClassID:
1703 return (RegIdx.Index == 28);
1704 case Mips::SP32RegClassID:
1705 return (RegIdx.Index == 29);
1706 case Mips::GPRNMRARegClassID:
1707 return (RegIdx.Index == 31);
1708 case Mips::GPR32NONZERORegClassID:
1709 return (RegIdx.Index > 0 && RegIdx.Index < 32);
1710 case Mips::GPRNM3RegClassID:
1711 return isNM16AsmReg();
1712 case Mips::GPRNM3ZRegClassID:
1713 return isNM16ZeroAsmReg();
1714 case Mips::GPRNM4RegClassID:
1715 return isNM4AsmReg();
1716 case Mips::GPRNM4ZRegClassID:
1717 return isNM4ZeroAsmReg();
1718 case Mips::GPRNM2R1RegClassID:
1719 return isNM2R1AsmReg();
1720 case Mips::GPRNM2R2RegClassID:
1721 return isNM2R2AsmReg();
1722 case Mips::GPRNM1R1RegClassID:
1723 return isNM1R1AsmReg();
1725 return RegIdx.Index < 32;
1730 SMLoc getStartLoc()
const override {
return StartLoc; }
1732 SMLoc getEndLoc()
const override {
return EndLoc; }
1734 void print(raw_ostream &OS,
const MCAsmInfo &MAI)
const override {
1743 Mem.Base->print(OS, MAI);
1748 case k_RegisterIndex:
1749 OS <<
"RegIdx<" << RegIdx.Index <<
":" << RegIdx.Kind <<
", "
1750 << StringRef(RegIdx.Tok.Data, RegIdx.Tok.Length) <<
">";
1757 for (
auto Reg : (*RegList.List))
1758 OS <<
Reg.
id() <<
" ";
1764 bool isValidForTie(
const MipsOperand &
Other)
const {
1765 if (Kind !=
Other.Kind)
1772 case k_RegisterIndex: {
1773 StringRef Token(RegIdx.Tok.Data, RegIdx.Tok.Length);
1774 StringRef OtherToken(
Other.RegIdx.Tok.Data,
Other.RegIdx.Tok.Length);
1775 return Token == OtherToken;
1791 case Mips::JRC16_MM:
1793 case Mips::JALRS_MM:
1794 case Mips::JALRS16_MM:
1795 case Mips::BGEZALS_MM:
1796 case Mips::BLTZALS_MM:
1807 return &SRExpr->getSymbol();
1866 unsigned NumOp =
MCID.getNumOperands();
1867 if (NumOp != 3 && NumOp != 4)
1897bool MipsAsmParser::processInstruction(
MCInst &Inst,
SMLoc IDLoc,
1900 MipsTargetStreamer &TOut = getTargetStreamer();
1901 const unsigned Opcode = Inst.
getOpcode();
1902 const MCInstrDesc &MCID = MII.get(Opcode);
1903 bool ExpandedJalSym =
false;
1917 assert(hasCnMips() &&
"instruction only valid for octeon cpus");
1928 if (!
isIntN(inMicroMipsMode() ? 17 : 18,
Offset.getImm()))
1929 return Error(IDLoc,
"branch target out of range");
1932 return Error(IDLoc,
"branch to misaligned address");
1946 case Mips::BGEZAL_MM:
1947 case Mips::BLTZAL_MM:
1950 case Mips::BC1EQZC_MMR6:
1951 case Mips::BC1NEZC_MMR6:
1952 case Mips::BC2EQZC_MMR6:
1953 case Mips::BC2NEZC_MMR6:
1958 if (!
isIntN(inMicroMipsMode() ? 17 : 18,
Offset.getImm()))
1959 return Error(IDLoc,
"branch target out of range");
1962 return Error(IDLoc,
"branch to misaligned address");
1964 case Mips::BGEC:
case Mips::BGEC_MMR6:
1965 case Mips::BLTC:
case Mips::BLTC_MMR6:
1966 case Mips::BGEUC:
case Mips::BGEUC_MMR6:
1967 case Mips::BLTUC:
case Mips::BLTUC_MMR6:
1968 case Mips::BEQC:
case Mips::BEQC_MMR6:
1969 case Mips::BNEC:
case Mips::BNEC_MMR6:
1975 return Error(IDLoc,
"branch target out of range");
1977 return Error(IDLoc,
"branch to misaligned address");
1979 case Mips::BLEZC:
case Mips::BLEZC_MMR6:
1980 case Mips::BGEZC:
case Mips::BGEZC_MMR6:
1981 case Mips::BGTZC:
case Mips::BGTZC_MMR6:
1982 case Mips::BLTZC:
case Mips::BLTZC_MMR6:
1988 return Error(IDLoc,
"branch target out of range");
1990 return Error(IDLoc,
"branch to misaligned address");
1992 case Mips::BEQZC:
case Mips::BEQZC_MMR6:
1993 case Mips::BNEZC:
case Mips::BNEZC_MMR6:
1999 return Error(IDLoc,
"branch target out of range");
2001 return Error(IDLoc,
"branch to misaligned address");
2003 case Mips::BEQZ16_MM:
2004 case Mips::BEQZC16_MMR6:
2005 case Mips::BNEZ16_MM:
2006 case Mips::BNEZC16_MMR6:
2012 return Error(IDLoc,
"branch target out of range");
2014 return Error(IDLoc,
"branch to misaligned address");
2021 if (hasMips32r6() && Opcode == Mips::SSNOP) {
2022 std::string
ISA = hasMips64r6() ?
"MIPS64r6" :
"MIPS32r6";
2023 Warning(IDLoc,
"ssnop is deprecated for " + ISA +
" and is equivalent to a "
2043 return Error(IDLoc,
"expected immediate operand kind");
2046 Opcode == Mips::BBIT1 ? 63 : 31))
2047 return Error(IDLoc,
"immediate operand value out of range");
2049 Inst.
setOpcode(Opcode == Mips::BBIT0 ? Mips::BBIT032
2060 return Error(IDLoc,
"expected immediate operand kind");
2063 return Error(IDLoc,
"immediate operand value out of range");
2075 unsigned FirstOp = 1;
2076 unsigned SecondOp = 2;
2080 case Mips::SDivIMacro:
2081 case Mips::UDivIMacro:
2082 case Mips::DSDivIMacro:
2083 case Mips::DUDivIMacro:
2085 return Error(IDLoc,
"expected immediate operand kind");
2089 Warning(IDLoc,
"dividing zero by zero");
2091 Warning(IDLoc,
"division by zero");
2103 case Mips::SDivMacro:
2104 case Mips::DSDivMacro:
2105 case Mips::UDivMacro:
2106 case Mips::DUDivMacro:
2111 case Mips::DIVU_MMR6:
2112 case Mips::DIV_MMR6:
2117 Warning(IDLoc,
"dividing zero by zero");
2119 Warning(IDLoc,
"division by zero");
2125 if ((Opcode == Mips::J || Opcode == Mips::J_MM) && inPicMode()) {
2127 BInst.
setOpcode(inMicroMipsMode() ? Mips::BEQ_MM : Mips::BEQ);
2136 if ((Opcode == Mips::JAL || Opcode == Mips::JAL_MM) && inPicMode()) {
2137 warnIfNoMacro(IDLoc);
2140 return Error(IDLoc,
"unsupported constant in relocation");
2148 return Error(IDLoc,
"jal doesn't support multiple symbols in PIC mode");
2154 if (expandLoadAddress(
getABI().getTempReg(9), MCRegister(),
2155 Inst.
getOperand(0), !isGP64bit(), IDLoc, Out, STI))
2159 if (inMicroMipsMode())
2160 JalrInst.
setOpcode(IsCpRestoreSet ? Mips::JALRS_MM : Mips::JALR_MM);
2166 if (isJalrRelocAvailable(JalExpr)) {
2172 const MCExpr *RelocJalrExpr =
2176 *TmpExpr, inMicroMipsMode() ?
"R_MICROMIPS_JALR" :
"R_MIPS_JALR",
2182 ExpandedJalSym =
true;
2191 expandMem9Inst(Inst, IDLoc, Out, STI, MCID.
mayLoad());
2194 expandMem16Inst(Inst, IDLoc, Out, STI, MCID.
mayLoad());
2197 return getParser().hasPendingError();
2201 if (inMicroMipsMode()) {
2202 if (Opcode == Mips::LW_MM || Opcode == Mips::LW_MMR6) {
2205 const MCOperandInfo &OpInfo = MCID.
operands()[i];
2210 int MemOffset =
Op.getImm();
2213 if (
isInt<9>(MemOffset) && (MemOffset % 4 == 0) &&
2236 case Mips::ADDIUSP_MM:
2239 return Error(IDLoc,
"expected immediate operand kind");
2243 return Error(IDLoc,
"immediate operand value out of range");
2245 case Mips::SLL16_MM:
2246 case Mips::SRL16_MM:
2249 return Error(IDLoc,
"expected immediate operand kind");
2252 return Error(IDLoc,
"immediate operand value out of range");
2257 return Error(IDLoc,
"expected immediate operand kind");
2260 return Error(IDLoc,
"immediate operand value out of range");
2262 case Mips::ADDIUR2_MM:
2265 return Error(IDLoc,
"expected immediate operand kind");
2267 if (!(
Imm == 1 ||
Imm == -1 ||
2269 return Error(IDLoc,
"immediate operand value out of range");
2271 case Mips::ANDI16_MM:
2274 return Error(IDLoc,
"expected immediate operand kind");
2278 Imm == 64 ||
Imm == 255 ||
Imm == 32768 ||
Imm == 65535))
2279 return Error(IDLoc,
"immediate operand value out of range");
2281 case Mips::LBU16_MM:
2284 return Error(IDLoc,
"expected immediate operand kind");
2287 return Error(IDLoc,
"immediate operand value out of range");
2290 case Mips::SB16_MMR6:
2293 return Error(IDLoc,
"expected immediate operand kind");
2296 return Error(IDLoc,
"immediate operand value out of range");
2298 case Mips::LHU16_MM:
2300 case Mips::SH16_MMR6:
2303 return Error(IDLoc,
"expected immediate operand kind");
2306 return Error(IDLoc,
"immediate operand value out of range");
2310 case Mips::SW16_MMR6:
2313 return Error(IDLoc,
"expected immediate operand kind");
2316 return Error(IDLoc,
"immediate operand value out of range");
2318 case Mips::ADDIUPC_MM:
2321 return Error(IDLoc,
"expected immediate operand kind");
2324 return Error(IDLoc,
"immediate operand value out of range");
2329 return Error(IDLoc,
"invalid operand for instruction");
2331 case Mips::MOVEP_MM:
2332 case Mips::MOVEP_MMR6: {
2335 bool RegPair = ((R0 == Mips::R5 && R1 == Mips::R6) ||
2336 (R0 == Mips::R5 && R1 == Mips::R7) ||
2337 (R0 == Mips::R6 && R1 == Mips::R7) ||
2338 (R0 == Mips::R4 && R1 == Mips::R21) ||
2339 (R0 == Mips::R4 && R1 == Mips::R22) ||
2340 (R0 == Mips::R4 && R1 == Mips::R5) ||
2341 (R0 == Mips::R4 && R1 == Mips::R6) ||
2342 (R0 == Mips::R4 && R1 == Mips::R7));
2344 return Error(IDLoc,
"invalid operand for instruction");
2350 bool FillDelaySlot =
2355 bool PrevForbiddenSlotAttr = CurForbiddenSlotAttr;
2358 bool SetReorderAfterNop =
false;
2363 if (PrevForbiddenSlotAttr && !SafeInForbiddenSlot(MCID)) {
2373 if (AssemblerOptions.
back()->isReorder() && !FillDelaySlot) {
2374 SetReorderAfterNop =
true;
2383 CurForbiddenSlotAttr =
2384 hasForbiddenSlot(MCID) && AssemblerOptions.
back()->isReorder();
2386 if (FillDelaySlot || CurForbiddenSlotAttr)
2389 MacroExpanderResultTy ExpandResult =
2390 tryExpandInstruction(Inst, IDLoc, Out, STI);
2391 switch (ExpandResult) {
2393 Out.emitInstruction(Inst, *STI);
2407 if (PrevForbiddenSlotAttr && !SetReorderAfterNop && !FillDelaySlot &&
2408 AssemblerOptions.
back()->isReorder()) {
2414 if (inMicroMipsMode()) {
2429 if (FillDelaySlot) {
2434 if ((Opcode == Mips::JalOneReg || Opcode == Mips::JalTwoReg ||
2436 isPicAndNotNxxAbi()) {
2437 if (IsCpRestoreSet) {
2441 if (!AssemblerOptions.
back()->isReorder())
2448 Warning(IDLoc,
"no .cprestore used in PIC mode");
2454void MipsAsmParser::onEndOfFile() {
2455 MipsTargetStreamer &TOut = getTargetStreamer();
2456 SMLoc IDLoc = SMLoc();
2458 if (CurForbiddenSlotAttr) {
2460 if (AssemblerOptions.
back()->isReorder())
2465MipsAsmParser::MacroExpanderResultTy
2466MipsAsmParser::tryExpandInstruction(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
2467 const MCSubtargetInfo *STI) {
2470 return MER_NotAMacro;
2471 case Mips::LoadImm32:
2472 return expandLoadImm(Inst,
true, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2473 case Mips::LoadImm64:
2474 return expandLoadImm(Inst,
false, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2475 case Mips::LoadAddrImm32:
2476 case Mips::LoadAddrImm64:
2479 "expected immediate operand kind");
2481 return expandLoadAddress(
2483 Inst.
getOpcode() == Mips::LoadAddrImm32, IDLoc, Out, STI)
2486 case Mips::LoadAddrReg32:
2487 case Mips::LoadAddrReg64:
2491 "expected immediate operand kind");
2495 Inst.
getOpcode() == Mips::LoadAddrReg32, IDLoc,
2499 case Mips::B_MM_Pseudo:
2500 case Mips::B_MMR6_Pseudo:
2501 return expandUncondBranchMMPseudo(Inst, IDLoc, Out, STI) ? MER_Fail
2505 return expandLoadStoreMultiple(Inst, IDLoc, Out, STI) ? MER_Fail
2507 case Mips::JalOneReg:
2508 case Mips::JalTwoReg:
2509 return expandJalWithRegs(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2512 case Mips::BEQLImmMacro:
2513 case Mips::BNELImmMacro:
2514 return expandBranchImm(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2531 case Mips::BLTImmMacro:
2532 case Mips::BLEImmMacro:
2533 case Mips::BGEImmMacro:
2534 case Mips::BGTImmMacro:
2535 case Mips::BLTUImmMacro:
2536 case Mips::BLEUImmMacro:
2537 case Mips::BGEUImmMacro:
2538 case Mips::BGTUImmMacro:
2539 case Mips::BLTLImmMacro:
2540 case Mips::BLELImmMacro:
2541 case Mips::BGELImmMacro:
2542 case Mips::BGTLImmMacro:
2543 case Mips::BLTULImmMacro:
2544 case Mips::BLEULImmMacro:
2545 case Mips::BGEULImmMacro:
2546 case Mips::BGTULImmMacro:
2547 return expandCondBranches(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2548 case Mips::SDivMacro:
2549 case Mips::SDivIMacro:
2550 case Mips::SRemMacro:
2551 case Mips::SRemIMacro:
2552 return expandDivRem(Inst, IDLoc, Out, STI,
false,
true) ? MER_Fail
2554 case Mips::DSDivMacro:
2555 case Mips::DSDivIMacro:
2556 case Mips::DSRemMacro:
2557 case Mips::DSRemIMacro:
2558 return expandDivRem(Inst, IDLoc, Out, STI,
true,
true) ? MER_Fail
2560 case Mips::UDivMacro:
2561 case Mips::UDivIMacro:
2562 case Mips::URemMacro:
2563 case Mips::URemIMacro:
2564 return expandDivRem(Inst, IDLoc, Out, STI,
false,
false) ? MER_Fail
2566 case Mips::DUDivMacro:
2567 case Mips::DUDivIMacro:
2568 case Mips::DURemMacro:
2569 case Mips::DURemIMacro:
2570 return expandDivRem(Inst, IDLoc, Out, STI,
true,
false) ? MER_Fail
2572 case Mips::PseudoTRUNC_W_S:
2573 return expandTrunc(Inst,
false,
false, IDLoc, Out, STI) ? MER_Fail
2575 case Mips::PseudoTRUNC_W_D32:
2576 return expandTrunc(Inst,
true,
false, IDLoc, Out, STI) ? MER_Fail
2578 case Mips::PseudoTRUNC_W_D:
2579 return expandTrunc(Inst,
true,
true, IDLoc, Out, STI) ? MER_Fail
2582 case Mips::LoadImmSingleGPR:
2583 return expandLoadSingleImmToGPR(Inst, IDLoc, Out, STI) ? MER_Fail
2585 case Mips::LoadImmSingleFGR:
2586 return expandLoadSingleImmToFPR(Inst, IDLoc, Out, STI) ? MER_Fail
2588 case Mips::LoadImmDoubleGPR:
2589 return expandLoadDoubleImmToGPR(Inst, IDLoc, Out, STI) ? MER_Fail
2591 case Mips::LoadImmDoubleFGR:
2592 return expandLoadDoubleImmToFPR(Inst,
true, IDLoc, Out, STI) ? MER_Fail
2594 case Mips::LoadImmDoubleFGR_32:
2595 return expandLoadDoubleImmToFPR(Inst,
false, IDLoc, Out, STI) ? MER_Fail
2599 return expandUlh(Inst,
true, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2601 return expandUlh(Inst,
false, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2603 return expandUsh(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2606 return expandUxw(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2608 case Mips::NORImm64:
2609 return expandAliasImmediate(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2612 return expandSge(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2615 case Mips::SGEImm64:
2616 case Mips::SGEUImm64:
2617 return expandSgeImm(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2620 case Mips::SGTImm64:
2621 case Mips::SGTUImm64:
2622 return expandSgtImm(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2625 return expandSle(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2628 case Mips::SLEImm64:
2629 case Mips::SLEUImm64:
2630 return expandSleImm(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2631 case Mips::SLTImm64:
2634 return MER_NotAMacro;
2636 return expandAliasImmediate(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2637 case Mips::SLTUImm64:
2640 return MER_NotAMacro;
2642 return expandAliasImmediate(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2643 case Mips::ADDi:
case Mips::ADDi_MM:
2644 case Mips::ADDiu:
case Mips::ADDiu_MM:
2645 case Mips::SLTi:
case Mips::SLTi_MM:
2646 case Mips::SLTiu:
case Mips::SLTiu_MM:
2651 return MER_NotAMacro;
2652 return expandAliasImmediate(Inst, IDLoc, Out, STI) ? MER_Fail
2655 return MER_NotAMacro;
2656 case Mips::ANDi:
case Mips::ANDi_MM:
case Mips::ANDi64:
2657 case Mips::ORi:
case Mips::ORi_MM:
case Mips::ORi64:
2658 case Mips::XORi:
case Mips::XORi_MM:
case Mips::XORi64:
2663 return MER_NotAMacro;
2664 return expandAliasImmediate(Inst, IDLoc, Out, STI) ? MER_Fail
2667 return MER_NotAMacro;
2670 return expandRotation(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2673 return expandRotationImm(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2676 return expandDRotation(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2679 return expandDRotationImm(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2680 case Mips::ABSMacro:
2681 return expandAbs(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2682 case Mips::MULImmMacro:
2683 case Mips::DMULImmMacro:
2684 return expandMulImm(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2685 case Mips::MULOMacro:
2686 case Mips::DMULOMacro:
2687 return expandMulO(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2688 case Mips::MULOUMacro:
2689 case Mips::DMULOUMacro:
2690 return expandMulOU(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2691 case Mips::DMULMacro:
2692 return expandDMULMacro(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2695 return expandLoadStoreDMacro(Inst, IDLoc, Out, STI,
2700 return expandStoreDM1Macro(Inst, IDLoc, Out, STI)
2703 case Mips::SEQMacro:
2704 return expandSeq(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2705 case Mips::SEQIMacro:
2706 return expandSeqI(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2707 case Mips::SNEMacro:
2708 return expandSne(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2709 case Mips::SNEIMacro:
2710 return expandSneI(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2711 case Mips::MFTGPR:
case Mips::MTTGPR:
2712 case Mips::MFTLO:
case Mips::MTTLO:
2713 case Mips::MFTHI:
case Mips::MTTHI:
2714 case Mips::MFTACX:
case Mips::MTTACX:
2715 case Mips::MFTDSP:
case Mips::MTTDSP:
2716 case Mips::MFTC1:
case Mips::MTTC1:
2717 case Mips::MFTHC1:
case Mips::MTTHC1:
2718 case Mips::CFTC1:
case Mips::CTTC1:
2719 return expandMXTRAlias(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2721 case Mips::SaadAddr:
2722 return expandSaaAddr(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2726bool MipsAsmParser::expandJalWithRegs(MCInst &Inst, SMLoc IDLoc,
2728 const MCSubtargetInfo *STI) {
2729 MipsTargetStreamer &TOut = getTargetStreamer();
2734 const MCOperand FirstRegOp = Inst.
getOperand(0);
2735 const unsigned Opcode = Inst.
getOpcode();
2737 if (Opcode == Mips::JalOneReg) {
2739 if (IsCpRestoreSet && inMicroMipsMode()) {
2742 }
else if (inMicroMipsMode()) {
2743 JalrInst.
setOpcode(hasMips32r6() ? Mips::JALRC16_MMR6 : Mips::JALR16_MM);
2750 }
else if (Opcode == Mips::JalTwoReg) {
2752 if (IsCpRestoreSet && inMicroMipsMode())
2755 JalrInst.
setOpcode(inMicroMipsMode() ? Mips::JALR_MM : Mips::JALR);
2757 const MCOperand SecondRegOp = Inst.
getOperand(1);
2760 Out.emitInstruction(JalrInst, *STI);
2764 const MCInstrDesc &MCID = MII.get(JalrInst.
getOpcode());
2787bool MipsAsmParser::loadImmediate(int64_t ImmValue, MCRegister DstReg,
2788 MCRegister SrcReg,
bool Is32BitImm,
2789 bool IsAddress, SMLoc IDLoc, MCStreamer &Out,
2790 const MCSubtargetInfo *STI) {
2791 MipsTargetStreamer &TOut = getTargetStreamer();
2793 if (!Is32BitImm && !isGP64bit()) {
2794 Error(IDLoc,
"instruction requires a 64-bit architecture");
2805 Error(IDLoc,
"instruction requires a 32-bit immediate");
2810 MCRegister ZeroReg = IsAddress ?
ABI.GetNullPtr() :
ABI.GetZeroReg();
2811 unsigned AdduOp = !Is32BitImm ? Mips::DADDu : Mips::ADDu;
2813 bool UseSrcReg =
false;
2817 MCRegister TmpReg = DstReg;
2819 getContext().getRegisterInfo()->isSuperOrSubRegisterEq(DstReg, SrcReg)) {
2822 MCRegister ATReg = getATReg(IDLoc);
2835 if (IsAddress && !Is32BitImm) {
2836 TOut.
emitRRI(Mips::DADDiu, DstReg, SrcReg, ImmValue, IDLoc, STI);
2840 TOut.
emitRRI(Mips::ADDiu, DstReg, SrcReg, ImmValue, IDLoc, STI);
2845 MCRegister TmpReg = DstReg;
2846 if (SrcReg == DstReg) {
2847 TmpReg = getATReg(IDLoc);
2852 TOut.
emitRRI(Mips::ORi, TmpReg, ZeroReg, ImmValue, IDLoc, STI);
2854 TOut.
emitRRR(
ABI.GetPtrAdduOp(), DstReg, TmpReg, SrcReg, IDLoc, STI);
2859 warnIfNoMacro(IDLoc);
2861 uint16_t Bits31To16 = (ImmValue >> 16) & 0xffff;
2862 uint16_t Bits15To0 = ImmValue & 0xffff;
2863 if (!Is32BitImm && !
isInt<32>(ImmValue)) {
2866 if (ImmValue == 0xffffffff) {
2867 TOut.
emitRI(Mips::LUi, TmpReg, 0xffff, IDLoc, STI);
2868 TOut.
emitRRI(Mips::DSRL32, TmpReg, TmpReg, 0, IDLoc, STI);
2870 TOut.
emitRRR(AdduOp, DstReg, TmpReg, SrcReg, IDLoc, STI);
2876 TOut.
emitRRI(Mips::ORi, TmpReg, ZeroReg, Bits31To16, IDLoc, STI);
2877 TOut.
emitRRI(Mips::DSLL, TmpReg, TmpReg, 16, IDLoc, STI);
2879 TOut.
emitRRI(Mips::ORi, TmpReg, TmpReg, Bits15To0, IDLoc, STI);
2881 TOut.
emitRRR(AdduOp, DstReg, TmpReg, SrcReg, IDLoc, STI);
2885 TOut.
emitRI(Mips::LUi, TmpReg, Bits31To16, IDLoc, STI);
2887 TOut.
emitRRI(Mips::ORi, TmpReg, TmpReg, Bits15To0, IDLoc, STI);
2889 TOut.
emitRRR(AdduOp, DstReg, TmpReg, SrcReg, IDLoc, STI);
2895 Error(IDLoc,
"instruction requires a 32-bit immediate");
2902 assert(
BitWidth >= 17 &&
"ImmValue must be at least 17-bit wide");
2906 unsigned ShiftAmount =
BitWidth - 16;
2907 uint16_t
Bits = (ImmValue >> ShiftAmount) & 0xffff;
2908 TOut.
emitRRI(Mips::ORi, TmpReg, ZeroReg, Bits, IDLoc, STI);
2909 TOut.
emitRRI(Mips::DSLL, TmpReg, TmpReg, ShiftAmount, IDLoc, STI);
2912 TOut.
emitRRR(AdduOp, DstReg, TmpReg, SrcReg, IDLoc, STI);
2917 warnIfNoMacro(IDLoc);
2924 if (loadImmediate(ImmValue >> 32, TmpReg, MCRegister(),
true,
false, IDLoc,
2930 unsigned ShiftCarriedForwards = 16;
2931 for (
int BitNum = 16; BitNum >= 0; BitNum -= 16) {
2932 uint16_t ImmChunk = (ImmValue >> BitNum) & 0xffff;
2934 if (ImmChunk != 0) {
2935 TOut.
emitDSLL(TmpReg, TmpReg, ShiftCarriedForwards, IDLoc, STI);
2936 TOut.
emitRRI(Mips::ORi, TmpReg, TmpReg, ImmChunk, IDLoc, STI);
2937 ShiftCarriedForwards = 0;
2940 ShiftCarriedForwards += 16;
2942 ShiftCarriedForwards -= 16;
2945 if (ShiftCarriedForwards)
2946 TOut.
emitDSLL(TmpReg, TmpReg, ShiftCarriedForwards, IDLoc, STI);
2949 TOut.
emitRRR(AdduOp, DstReg, TmpReg, SrcReg, IDLoc, STI);
2954bool MipsAsmParser::expandLoadImm(MCInst &Inst,
bool Is32BitImm, SMLoc IDLoc,
2955 MCStreamer &Out,
const MCSubtargetInfo *STI) {
2957 assert(ImmOp.
isImm() &&
"expected immediate operand kind");
2958 const MCOperand &DstRegOp = Inst.
getOperand(0);
2959 assert(DstRegOp.
isReg() &&
"expected register operand kind");
2961 if (loadImmediate(ImmOp.
getImm(), DstRegOp.
getReg(), MCRegister(), Is32BitImm,
2962 false, IDLoc, Out, STI))
2968bool MipsAsmParser::expandLoadAddress(MCRegister DstReg, MCRegister BaseReg,
2970 bool Is32BitAddress, SMLoc IDLoc,
2972 const MCSubtargetInfo *STI) {
2974 if (Is32BitAddress &&
ABI.ArePtrs64bit()) {
2975 Warning(IDLoc,
"la used to load 64-bit address");
2977 Is32BitAddress =
false;
2981 if (!Is32BitAddress && !hasMips3()) {
2982 Error(IDLoc,
"instruction requires a 64-bit architecture");
2987 return loadAndAddSymbolAddress(
Offset.getExpr(), DstReg, BaseReg,
2988 Is32BitAddress, IDLoc, Out, STI);
2990 if (!
ABI.ArePtrs64bit()) {
2992 Is32BitAddress =
true;
2995 return loadImmediate(
Offset.getImm(), DstReg, BaseReg, Is32BitAddress,
true,
3004bool MipsAsmParser::canDeferGOTLoad(
const MCSymbol *Sym) {
3006 static_cast<const MCSymbolELF *
>(Sym)->isBindingSet())
3011 MCAssembler *
Asm = getStreamer().getAssemblerPtr();
3012 return Asm && !
Asm->getRelaxAll() && !
Asm->isBundlingEnabled();
3015bool MipsAsmParser::loadAndAddSymbolAddress(
const MCExpr *SymExpr,
3017 MCRegister SrcReg,
bool Is32BitSym,
3018 SMLoc IDLoc, MCStreamer &Out,
3019 const MCSubtargetInfo *STI) {
3020 MipsTargetStreamer &TOut = getTargetStreamer();
3022 SrcReg.
isValid() && SrcReg != Mips::R0 && SrcReg != Mips::R0_64;
3023 warnIfNoMacro(IDLoc);
3028 Error(IDLoc,
"expected relocatable expression");
3032 Error(IDLoc,
"expected relocatable expression with only one symbol");
3036 bool IsPtr64 =
ABI.ArePtrs64bit();
3039 ?
static_cast<const MCSymbolELF *
>(Res.
getAddSym())
3047 bool UseXGOT = STI->
hasFeature(Mips::FeatureXGOT) && !IsLocalSym;
3055 !IsLocalSym && !UseXGOT && canDeferGOTLoad(Res.
getAddSym());
3056 auto EmitDeferredGOTLoad = [&](MCRegister
Reg,
unsigned Flags) {
3058 Inst.
setOpcode(Mips::PseudoGOTLoadGlobal);
3064 Out.emitInstruction(Inst, *STI);
3071 if ((DstReg ==
getABI().getTempReg(9,
false) ||
3072 DstReg ==
getABI().getTempReg(9,
true)) &&
3073 !UseSrcReg && Res.
getConstant() == 0 && !IsLocalSym) {
3075 const MCExpr *CallHiExpr =
3077 const MCExpr *CallLoExpr =
3081 TOut.
emitRRR(IsPtr64 ? Mips::DADDu : Mips::ADDu, DstReg, DstReg, GPReg,
3083 TOut.
emitRRX(IsPtr64 ? Mips::LD : Mips::LW, DstReg, DstReg,
3085 }
else if (DeferLocal) {
3087 if (
ABI.IsN32() ||
ABI.IsN64())
3091 EmitDeferredGOTLoad(DstReg, Flags);
3093 const MCExpr *CallExpr =
3095 TOut.
emitRRX(IsPtr64 ? Mips::LD : Mips::LW, DstReg, GPReg,
3101 MCRegister TmpReg = DstReg;
3103 getContext().getRegisterInfo()->isSuperOrSubRegisterEq(DstReg,
3107 MCRegister ATReg = getATReg(IDLoc);
3115 if (DeferLocal &&
ABI.IsO32()) {
3116 EmitDeferredGOTLoad(TmpReg, 0);
3118 TOut.
emitRRR(Mips::ADDu, DstReg, TmpReg, SrcReg, IDLoc, STI);
3135 const MCExpr *CallHiExpr =
3142 TOut.
emitRRR(IsPtr64 ? Mips::DADDu : Mips::ADDu, TmpReg, TmpReg, GPReg,
3144 TOut.
emitRRX(IsPtr64 ? Mips::LD : Mips::LW, TmpReg, TmpReg,
3148 TOut.
emitRRX(IsPtr64 ? Mips::DADDiu : Mips::ADDiu, TmpReg, TmpReg,
3154 TOut.
emitRRR(IsPtr64 ? Mips::DADDu : Mips::ADDu, DstReg, TmpReg, SrcReg,
3159 const MCSpecifierExpr *GotExpr =
nullptr;
3160 const MCExpr *LoExpr =
nullptr;
3161 if (
ABI.IsN32() ||
ABI.IsN64()) {
3180 Error(IDLoc,
"macro instruction uses large offset, which is not "
3181 "currently supported");
3210 TOut.
emitRRX(IsPtr64 ? Mips::LD : Mips::LW, TmpReg, GPReg,
3214 TOut.
emitRRX(IsPtr64 ? Mips::DADDiu : Mips::ADDiu, TmpReg, TmpReg,
3218 TOut.
emitRRR(IsPtr64 ? Mips::DADDu : Mips::ADDu, DstReg, TmpReg, SrcReg,
3224 const auto *HiExpr =
3226 const auto *LoExpr =
3230 if (
ABI.ArePtrs64bit() && isGP64bit()) {
3238 const auto *HighestExpr =
3240 const auto *HigherExpr =
3245 getContext().getRegisterInfo()->isSuperOrSubRegisterEq(DstReg, SrcReg);
3247 if (canUseATReg() && UseSrcReg && RdRegIsRsReg) {
3248 MCRegister ATReg = getATReg(IDLoc);
3260 TOut.
emitRRX(Mips::DADDiu, ATReg, ATReg,
3262 TOut.
emitRRI(Mips::DSLL, ATReg, ATReg, 16, IDLoc, STI);
3265 TOut.
emitRRI(Mips::DSLL, ATReg, ATReg, 16, IDLoc, STI);
3268 TOut.
emitRRR(Mips::DADDu, DstReg, ATReg, SrcReg, IDLoc, STI);
3271 }
else if (canUseATReg() && !RdRegIsRsReg && DstReg != getATReg(IDLoc)) {
3272 MCRegister ATReg = getATReg(IDLoc);
3288 TOut.
emitRRX(Mips::DADDiu, DstReg, DstReg,
3292 TOut.
emitRRI(Mips::DSLL32, DstReg, DstReg, 0, IDLoc, STI);
3293 TOut.
emitRRR(Mips::DADDu, DstReg, DstReg, ATReg, IDLoc, STI);
3295 TOut.
emitRRR(Mips::DADDu, DstReg, DstReg, SrcReg, IDLoc, STI);
3298 }
else if ((!canUseATReg() && !RdRegIsRsReg) ||
3299 (canUseATReg() && DstReg == getATReg(IDLoc))) {
3310 TOut.
emitRRX(Mips::DADDiu, DstReg, DstReg,
3312 TOut.
emitRRI(Mips::DSLL, DstReg, DstReg, 16, IDLoc, STI);
3313 TOut.
emitRRX(Mips::DADDiu, DstReg, DstReg,
3315 TOut.
emitRRI(Mips::DSLL, DstReg, DstReg, 16, IDLoc, STI);
3316 TOut.
emitRRX(Mips::DADDiu, DstReg, DstReg,
3319 TOut.
emitRRR(Mips::DADDu, DstReg, DstReg, SrcReg, IDLoc, STI);
3325 assert(SrcReg == DstReg && !canUseATReg() &&
3326 "Could have expanded dla but didn't?");
3327 reportParseError(IDLoc,
3328 "pseudo-instruction requires $at, which is not available");
3342 MCRegister TmpReg = DstReg;
3344 getContext().getRegisterInfo()->isSuperOrSubRegisterEq(DstReg, SrcReg)) {
3347 MCRegister ATReg = getATReg(IDLoc);
3358 TOut.
emitRRR(Mips::ADDu, DstReg, TmpReg, SrcReg, IDLoc, STI);
3361 getContext().getRegisterInfo()->isSuperOrSubRegisterEq(DstReg, TmpReg));
3370 if (getMipsMCRegisterClass(Mips::FGR32RegClassID).
contains(
Reg))
3371 return Reg == (
unsigned)Mips::F31 ? (
unsigned)Mips::F0 :
Reg + 1;
3373 default:
llvm_unreachable(
"Unknown register in assembly macro expansion!");
3438 case Mips::D0:
return Mips::F1;
3439 case Mips::D1:
return Mips::F3;
3440 case Mips::D2:
return Mips::F5;
3441 case Mips::D3:
return Mips::F7;
3442 case Mips::D4:
return Mips::F9;
3443 case Mips::D5:
return Mips::F11;
3444 case Mips::D6:
return Mips::F13;
3445 case Mips::D7:
return Mips::F15;
3446 case Mips::D8:
return Mips::F17;
3447 case Mips::D9:
return Mips::F19;
3469bool MipsAsmParser::emitPartialAddress(MipsTargetStreamer &TOut, SMLoc IDLoc,
3471 MCRegister ATReg = getATReg(IDLoc);
3477 const auto *GotExpr =
3480 if(isABI_O32() || isABI_N32()) {
3489 const auto *HiExpr =
3498 if(isABI_O32() || isABI_N32()) {
3502 const auto *HighestExpr =
3505 const auto *HigherExpr =
3510 TOut.
emitRRX(Mips::DADDiu, ATReg, ATReg,
3512 TOut.
emitRRI(Mips::DSLL, ATReg, ATReg, 16, IDLoc, STI);
3515 TOut.
emitRRI(Mips::DSLL, ATReg, ATReg, 16, IDLoc, STI);
3524 if ((
Hi_32(ImmOp64) & 0x7ff00000) == 0) {
3535 float TmpFloat =
static_cast<float>(DoubleImm);
3539bool MipsAsmParser::expandLoadSingleImmToGPR(MCInst &Inst, SMLoc IDLoc,
3541 const MCSubtargetInfo *STI) {
3544 "Invalid instruction operand.");
3551 return loadImmediate(ImmOp32, FirstReg, MCRegister(),
true,
false, IDLoc, Out,
3555bool MipsAsmParser::expandLoadSingleImmToFPR(MCInst &Inst, SMLoc IDLoc,
3557 const MCSubtargetInfo *STI) {
3558 MipsTargetStreamer &TOut = getTargetStreamer();
3561 "Invalid instruction operand.");
3570 MCRegister TmpReg = Mips::R0;
3572 TmpReg = getATReg(IDLoc);
3577 if (
Lo_32(ImmOp64) == 0) {
3578 if (TmpReg != Mips::R0 && loadImmediate(ImmOp32, TmpReg, MCRegister(),
true,
3579 false, IDLoc, Out, STI))
3581 TOut.
emitRR(Mips::MTC1, FirstReg, TmpReg, IDLoc, STI);
3585 MCSection *CS = getStreamer().getCurrentSectionOnly();
3588 MCSection *ReadOnlySection =
3595 getStreamer().switchSection(ReadOnlySection);
3596 getStreamer().emitLabel(Sym, IDLoc);
3597 getStreamer().emitInt32(ImmOp32);
3598 getStreamer().switchSection(CS);
3600 if (emitPartialAddress(TOut, IDLoc, Sym))
3607bool MipsAsmParser::expandLoadDoubleImmToGPR(MCInst &Inst, SMLoc IDLoc,
3609 const MCSubtargetInfo *STI) {
3610 MipsTargetStreamer &TOut = getTargetStreamer();
3613 "Invalid instruction operand.");
3620 if (
Lo_32(ImmOp64) == 0) {
3622 if (loadImmediate(ImmOp64, FirstReg, MCRegister(),
false,
false, IDLoc,
3626 if (loadImmediate(
Hi_32(ImmOp64), FirstReg, MCRegister(),
true,
false,
3630 if (loadImmediate(0,
nextReg(FirstReg), MCRegister(),
true,
false, IDLoc,
3637 MCSection *CS = getStreamer().getCurrentSectionOnly();
3638 MCSection *ReadOnlySection =
3645 getStreamer().switchSection(ReadOnlySection);
3646 getStreamer().emitLabel(Sym, IDLoc);
3647 getStreamer().emitValueToAlignment(
Align(8));
3648 getStreamer().emitIntValue(ImmOp64, 8);
3649 getStreamer().switchSection(CS);
3651 MCRegister TmpReg = getATReg(IDLoc);
3655 if (emitPartialAddress(TOut, IDLoc, Sym))
3658 TOut.
emitRRX(isABI_N64() ? Mips::DADDiu : Mips::ADDiu, TmpReg, TmpReg,
3662 TOut.
emitRRI(Mips::LD, FirstReg, TmpReg, 0, IDLoc, STI);
3664 TOut.
emitRRI(Mips::LW, FirstReg, TmpReg, 0, IDLoc, STI);
3665 TOut.
emitRRI(Mips::LW,
nextReg(FirstReg), TmpReg, 4, IDLoc, STI);
3670bool MipsAsmParser::expandLoadDoubleImmToFPR(MCInst &Inst,
bool Is64FPU,
3671 SMLoc IDLoc, MCStreamer &Out,
3672 const MCSubtargetInfo *STI) {
3673 MipsTargetStreamer &TOut = getTargetStreamer();
3676 "Invalid instruction operand.");
3683 MCRegister TmpReg = Mips::R0;
3685 TmpReg = getATReg(IDLoc);
3690 if ((
Lo_32(ImmOp64) == 0) &&
3691 !((
Hi_32(ImmOp64) & 0xffff0000) && (
Hi_32(ImmOp64) & 0x0000ffff))) {
3693 if (TmpReg != Mips::R0 && loadImmediate(ImmOp64, TmpReg, MCRegister(),
3694 false,
false, IDLoc, Out, STI))
3696 TOut.
emitRR(Mips::DMTC1, FirstReg, TmpReg, IDLoc, STI);
3700 if (TmpReg != Mips::R0 &&
3701 loadImmediate(
Hi_32(ImmOp64), TmpReg, MCRegister(),
true,
false, IDLoc,
3705 if (hasMips32r2()) {
3706 TOut.
emitRR(Mips::MTC1, FirstReg, Mips::R0, IDLoc, STI);
3707 TOut.
emitRRR(Mips::MTHC1_D32, FirstReg, FirstReg, TmpReg, IDLoc, STI);
3709 TOut.
emitRR(Mips::MTC1,
nextReg(FirstReg), TmpReg, IDLoc, STI);
3710 TOut.
emitRR(Mips::MTC1, FirstReg, Mips::R0, IDLoc, STI);
3715 MCSection *CS = getStreamer().getCurrentSectionOnly();
3718 MCSection *ReadOnlySection =
3725 getStreamer().switchSection(ReadOnlySection);
3726 getStreamer().emitLabel(Sym, IDLoc);
3727 getStreamer().emitValueToAlignment(
Align(8));
3728 getStreamer().emitIntValue(ImmOp64, 8);
3729 getStreamer().switchSection(CS);
3731 if (emitPartialAddress(TOut, IDLoc, Sym))
3734 TOut.
emitRRX(Is64FPU ? Mips::LDC164 : Mips::LDC1, FirstReg, TmpReg,
3740bool MipsAsmParser::expandUncondBranchMMPseudo(MCInst &Inst, SMLoc IDLoc,
3742 const MCSubtargetInfo *STI) {
3743 MipsTargetStreamer &TOut = getTargetStreamer();
3746 "unexpected number of operands");
3756 assert(
Offset.isImm() &&
"expected immediate operand kind");
3760 if (inMicroMipsMode())
3761 Inst.
setOpcode(hasMips32r6() ? Mips::BC16_MMR6 : Mips::B16_MM);
3764 return Error(IDLoc,
"branch target out of range");
3766 return Error(IDLoc,
"branch to misaligned address");
3774 Out.emitInstruction(Inst, *STI);
3778 const MCInstrDesc &MCID = MII.get(Inst.
getOpcode());
3785bool MipsAsmParser::expandBranchImm(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
3786 const MCSubtargetInfo *STI) {
3787 MipsTargetStreamer &TOut = getTargetStreamer();
3788 const MCOperand &DstRegOp = Inst.
getOperand(0);
3789 assert(DstRegOp.
isReg() &&
"expected register operand kind");
3792 assert(ImmOp.
isImm() &&
"expected immediate operand kind");
3794 const MCOperand &MemOffsetOp = Inst.
getOperand(2);
3796 "expected immediate or expression operand");
3798 bool IsLikely =
false;
3808 case Mips::BEQLImmMacro:
3812 case Mips::BNELImmMacro:
3821 int64_t ImmValue = ImmOp.
getImm();
3822 if (ImmValue == 0) {
3826 TOut.
emitRRI(Mips::SLL, Mips::R0, Mips::R0, 0, IDLoc, STI);
3828 TOut.
emitRRX(OpCode, DstRegOp.
getReg(), Mips::R0, MemOffsetOp, IDLoc,
3831 warnIfNoMacro(IDLoc);
3833 MCRegister ATReg = getATReg(IDLoc);
3837 if (loadImmediate(ImmValue, ATReg, MCRegister(), !isGP64bit(),
true, IDLoc,
3841 if (IsLikely && MemOffsetOp.
isExpr()) {
3844 TOut.
emitRRI(Mips::SLL, Mips::R0, Mips::R0, 0, IDLoc, STI);
3846 TOut.
emitRRX(OpCode, DstRegOp.
getReg(), ATReg, MemOffsetOp, IDLoc, STI);
3851void MipsAsmParser::expandMem16Inst(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
3852 const MCSubtargetInfo *STI,
bool IsLoad) {
3854 assert((NumOp == 3 || NumOp == 4) &&
"unexpected operands number");
3855 unsigned StartOp = NumOp == 3 ? 0 : 1;
3857 const MCOperand &DstRegOp = Inst.
getOperand(StartOp);
3858 assert(DstRegOp.
isReg() &&
"expected register operand kind");
3859 const MCOperand &BaseRegOp = Inst.
getOperand(StartOp + 1);
3860 assert(BaseRegOp.
isReg() &&
"expected register operand kind");
3863 MipsTargetStreamer &TOut = getTargetStreamer();
3865 MCRegister DstReg = DstRegOp.
getReg();
3867 MCRegister TmpReg = DstReg;
3869 const MCInstrDesc &
Desc = MII.get(OpCode);
3870 int16_t DstRegClass =
3871 MII.getOpRegClassID(
Desc.operands()[StartOp],
3873 unsigned DstRegClassID =
3874 getContext().getRegisterInfo()->getRegClass(DstRegClass).getID();
3875 bool IsGPR = (DstRegClassID == Mips::GPR32RegClassID) ||
3876 (DstRegClassID == Mips::GPR64RegClassID);
3878 if (!IsLoad || !IsGPR || (BaseReg == DstReg)) {
3881 TmpReg = getATReg(IDLoc);
3886 auto emitInstWithOffset = [&](
const MCOperand &
Off) {
3888 TOut.
emitRRX(OpCode, DstReg, TmpReg,
Off, IDLoc, STI);
3890 TOut.
emitRRRX(OpCode, DstReg, DstReg, TmpReg,
Off, IDLoc, STI);
3894 int64_t LoOffset =
OffsetOp.getImm() & 0xffff;
3895 int64_t HiOffset =
OffsetOp.getImm() & ~0xffff;
3899 if (LoOffset & 0x8000)
3900 HiOffset += 0x10000;
3902 bool IsLargeOffset = HiOffset != 0;
3904 if (IsLargeOffset) {
3906 if (loadImmediate(HiOffset, TmpReg, MCRegister(), Is32BitImm,
true, IDLoc,
3911 if (BaseReg != Mips::R0 && BaseReg != Mips::R0_64)
3912 TOut.
emitRRR(
ABI.ArePtrs64bit() ? Mips::DADDu : Mips::ADDu, TmpReg,
3913 TmpReg, BaseReg, IDLoc, STI);
3927 if (!
OffsetOp.getExpr()->evaluateAsRelocatable(Res,
nullptr)) {
3928 Error(IDLoc,
"expected relocatable expression");
3932 Error(IDLoc,
"expected relocatable expression with only one symbol");
3936 loadAndAddSymbolAddress(
3938 BaseReg, !
ABI.ArePtrs64bit(), IDLoc, Out, STI);
3946 const MCExpr *OffExpr =
OffsetOp.getExpr();
3958 TOut.
emitRX(Mips::LUi, TmpReg, HighestOperand, IDLoc, STI);
3959 TOut.
emitRRX(Mips::DADDiu, TmpReg, TmpReg, HigherOperand, IDLoc, STI);
3960 TOut.
emitRRI(Mips::DSLL, TmpReg, TmpReg, 16, IDLoc, STI);
3961 TOut.
emitRRX(Mips::DADDiu, TmpReg, TmpReg, HiOperand, IDLoc, STI);
3962 TOut.
emitRRI(Mips::DSLL, TmpReg, TmpReg, 16, IDLoc, STI);
3963 if (BaseReg != Mips::R0 && BaseReg != Mips::R0_64)
3964 TOut.
emitRRR(Mips::DADDu, TmpReg, TmpReg, BaseReg, IDLoc, STI);
3965 emitInstWithOffset(LoOperand);
3968 TOut.
emitRX(Mips::LUi, TmpReg, HiOperand, IDLoc, STI);
3969 if (BaseReg != Mips::R0)
3970 TOut.
emitRRR(Mips::ADDu, TmpReg, TmpReg, BaseReg, IDLoc, STI);
3972 emitInstWithOffset(LoOperand);
3981void MipsAsmParser::expandMem9Inst(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
3982 const MCSubtargetInfo *STI,
bool IsLoad) {
3984 assert((NumOp == 3 || NumOp == 4) &&
"unexpected operands number");
3985 unsigned StartOp = NumOp == 3 ? 0 : 1;
3987 const MCOperand &DstRegOp = Inst.
getOperand(StartOp);
3988 assert(DstRegOp.
isReg() &&
"expected register operand kind");
3989 const MCOperand &BaseRegOp = Inst.
getOperand(StartOp + 1);
3990 assert(BaseRegOp.
isReg() &&
"expected register operand kind");
3993 MipsTargetStreamer &TOut = getTargetStreamer();
3995 MCRegister DstReg = DstRegOp.
getReg();
3997 MCRegister TmpReg = DstReg;
3999 const MCInstrDesc &
Desc = MII.get(OpCode);
4000 int16_t DstRegClass =
4001 MII.getOpRegClassID(
Desc.operands()[StartOp],
4004 unsigned DstRegClassID =
4005 getContext().getRegisterInfo()->getRegClass(DstRegClass).getID();
4006 bool IsGPR = (DstRegClassID == Mips::GPR32RegClassID) ||
4007 (DstRegClassID == Mips::GPR64RegClassID);
4009 if (!IsLoad || !IsGPR || (BaseReg == DstReg)) {
4012 TmpReg = getATReg(IDLoc);
4017 auto emitInst = [&]() {
4026 loadImmediate(
OffsetOp.getImm(), TmpReg, BaseReg, !
ABI.ArePtrs64bit(),
true,
4033 loadAndAddSymbolAddress(
OffsetOp.getExpr(), TmpReg, BaseReg,
4034 !
ABI.ArePtrs64bit(), IDLoc, Out, STI);
4042bool MipsAsmParser::expandLoadStoreMultiple(MCInst &Inst, SMLoc IDLoc,
4044 const MCSubtargetInfo *STI) {
4047 unsigned NewOpcode = Opcode == Mips::SWM_MM ? Mips::SWM32_MM : Mips::LWM32_MM;
4051 Inst.
getOperand(OpNum - 3).
isReg() &&
"Invalid instruction operand.");
4060 if (inMicroMipsMode() && hasMips32r6())
4061 NewOpcode = Opcode == Mips::SWM_MM ? Mips::SWM16_MMR6 : Mips::LWM16_MMR6;
4063 NewOpcode = Opcode == Mips::SWM_MM ? Mips::SWM16_MM : Mips::LWM16_MM;
4067 Out.emitInstruction(Inst, *STI);
4071bool MipsAsmParser::expandCondBranches(MCInst &Inst, SMLoc IDLoc,
4073 const MCSubtargetInfo *STI) {
4074 MipsTargetStreamer &TOut = getTargetStreamer();
4075 bool EmittedNoMacroWarning =
false;
4076 unsigned PseudoOpcode = Inst.
getOpcode();
4081 unsigned ZeroSrcOpcode, ZeroTrgOpcode;
4082 bool ReverseOrderSLT, IsUnsigned, IsLikely, AcceptsEquality;
4087 else if (TrgOp.
isImm()) {
4088 warnIfNoMacro(IDLoc);
4089 EmittedNoMacroWarning =
true;
4091 TrgReg = getATReg(IDLoc);
4095 switch(PseudoOpcode) {
4098 case Mips::BLTImmMacro:
4099 PseudoOpcode = Mips::BLT;
4101 case Mips::BLEImmMacro:
4102 PseudoOpcode = Mips::BLE;
4104 case Mips::BGEImmMacro:
4105 PseudoOpcode = Mips::BGE;
4107 case Mips::BGTImmMacro:
4108 PseudoOpcode = Mips::BGT;
4110 case Mips::BLTUImmMacro:
4111 PseudoOpcode = Mips::BLTU;
4113 case Mips::BLEUImmMacro:
4114 PseudoOpcode = Mips::BLEU;
4116 case Mips::BGEUImmMacro:
4117 PseudoOpcode = Mips::BGEU;
4119 case Mips::BGTUImmMacro:
4120 PseudoOpcode = Mips::BGTU;
4122 case Mips::BLTLImmMacro:
4123 PseudoOpcode = Mips::BLTL;
4125 case Mips::BLELImmMacro:
4126 PseudoOpcode = Mips::BLEL;
4128 case Mips::BGELImmMacro:
4129 PseudoOpcode = Mips::BGEL;
4131 case Mips::BGTLImmMacro:
4132 PseudoOpcode = Mips::BGTL;
4134 case Mips::BLTULImmMacro:
4135 PseudoOpcode = Mips::BLTUL;
4137 case Mips::BLEULImmMacro:
4138 PseudoOpcode = Mips::BLEUL;
4140 case Mips::BGEULImmMacro:
4141 PseudoOpcode = Mips::BGEUL;
4143 case Mips::BGTULImmMacro:
4144 PseudoOpcode = Mips::BGTUL;
4148 if (loadImmediate(TrgOp.
getImm(), TrgReg, MCRegister(), !isGP64bit(),
false,
4153 switch (PseudoOpcode) {
4158 AcceptsEquality =
false;
4159 ReverseOrderSLT =
false;
4161 ((PseudoOpcode == Mips::BLTU) || (PseudoOpcode == Mips::BLTUL));
4162 IsLikely = ((PseudoOpcode == Mips::BLTL) || (PseudoOpcode == Mips::BLTUL));
4163 ZeroSrcOpcode = Mips::BGTZ;
4164 ZeroTrgOpcode = Mips::BLTZ;
4170 AcceptsEquality =
true;
4171 ReverseOrderSLT =
true;
4173 ((PseudoOpcode == Mips::BLEU) || (PseudoOpcode == Mips::BLEUL));
4174 IsLikely = ((PseudoOpcode == Mips::BLEL) || (PseudoOpcode == Mips::BLEUL));
4175 ZeroSrcOpcode = Mips::BGEZ;
4176 ZeroTrgOpcode = Mips::BLEZ;
4182 AcceptsEquality =
true;
4183 ReverseOrderSLT =
false;
4185 ((PseudoOpcode == Mips::BGEU) || (PseudoOpcode == Mips::BGEUL));
4186 IsLikely = ((PseudoOpcode == Mips::BGEL) || (PseudoOpcode == Mips::BGEUL));
4187 ZeroSrcOpcode = Mips::BLEZ;
4188 ZeroTrgOpcode = Mips::BGEZ;
4194 AcceptsEquality =
false;
4195 ReverseOrderSLT =
true;
4197 ((PseudoOpcode == Mips::BGTU) || (PseudoOpcode == Mips::BGTUL));
4198 IsLikely = ((PseudoOpcode == Mips::BGTL) || (PseudoOpcode == Mips::BGTUL));
4199 ZeroSrcOpcode = Mips::BLTZ;
4200 ZeroTrgOpcode = Mips::BGTZ;
4206 bool IsTrgRegZero = (TrgReg == Mips::R0);
4207 bool IsSrcRegZero = (SrcReg == Mips::R0);
4208 if (IsSrcRegZero && IsTrgRegZero) {
4212 if (PseudoOpcode == Mips::BLT) {
4217 if (PseudoOpcode == Mips::BLE) {
4220 Warning(IDLoc,
"branch is always taken");
4223 if (PseudoOpcode == Mips::BGE) {
4226 Warning(IDLoc,
"branch is always taken");
4229 if (PseudoOpcode == Mips::BGT) {
4234 if (PseudoOpcode == Mips::BGTU) {
4235 TOut.
emitRRX(Mips::BNE, Mips::R0, Mips::R0,
4239 if (AcceptsEquality) {
4242 TOut.
emitRRX(Mips::BEQ, Mips::R0, Mips::R0,
4244 Warning(IDLoc,
"branch is always taken");
4251 if (IsSrcRegZero || IsTrgRegZero) {
4252 if ((IsSrcRegZero && PseudoOpcode == Mips::BGTU) ||
4253 (IsTrgRegZero && PseudoOpcode == Mips::BLTU)) {
4260 if ((IsSrcRegZero && PseudoOpcode == Mips::BLEU) ||
4261 (IsTrgRegZero && PseudoOpcode == Mips::BGEU)) {
4267 TOut.
emitRRX(Mips::BEQ, Mips::R0, Mips::R0,
4269 Warning(IDLoc,
"branch is always taken");
4285 TOut.
emitRRX(AcceptsEquality ? Mips::BEQ : Mips::BNE,
4286 IsSrcRegZero ? TrgReg : SrcReg, Mips::R0,
4293 TOut.
emitRX(IsSrcRegZero ? ZeroSrcOpcode : ZeroTrgOpcode,
4294 IsSrcRegZero ? TrgReg : SrcReg,
4301 MCRegister ATRegNum = getATReg(IDLoc);
4305 if (!EmittedNoMacroWarning)
4306 warnIfNoMacro(IDLoc);
4323 TOut.
emitRRR(IsUnsigned ? Mips::SLTu : Mips::SLT, ATRegNum,
4324 ReverseOrderSLT ? TrgReg : SrcReg,
4325 ReverseOrderSLT ? SrcReg : TrgReg, IDLoc, STI);
4327 TOut.
emitRRX(IsLikely ? (AcceptsEquality ? Mips::BEQL : Mips::BNEL)
4328 : (AcceptsEquality ? Mips::BEQ : Mips::BNE),
4342bool MipsAsmParser::expandDivRem(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
4343 const MCSubtargetInfo *STI,
4344 const bool IsMips64,
const bool Signed) {
4345 MipsTargetStreamer &TOut = getTargetStreamer();
4347 warnIfNoMacro(IDLoc);
4349 const MCOperand &RdRegOp = Inst.
getOperand(0);
4350 assert(RdRegOp.
isReg() &&
"expected register operand kind");
4351 MCRegister RdReg = RdRegOp.
getReg();
4353 const MCOperand &RsRegOp = Inst.
getOperand(1);
4354 assert(RsRegOp.
isReg() &&
"expected register operand kind");
4355 MCRegister RsReg = RsRegOp.
getReg();
4362 "expected register or immediate operand kind");
4366 ImmValue = RtOp.
getImm();
4373 DivOp =
Signed ? Mips::DSDIV : Mips::DUDIV;
4374 ZeroReg = Mips::R0_64;
4377 DivOp =
Signed ? Mips::SDIV : Mips::UDIV;
4382 bool UseTraps = useTraps();
4385 bool isDiv = Opcode == Mips::SDivMacro || Opcode == Mips::SDivIMacro ||
4386 Opcode == Mips::UDivMacro || Opcode == Mips::UDivIMacro ||
4387 Opcode == Mips::DSDivMacro || Opcode == Mips::DSDivIMacro ||
4388 Opcode == Mips::DUDivMacro || Opcode == Mips::DUDivIMacro;
4390 bool isRem = Opcode == Mips::SRemMacro || Opcode == Mips::SRemIMacro ||
4391 Opcode == Mips::URemMacro || Opcode == Mips::URemIMacro ||
4392 Opcode == Mips::DSRemMacro || Opcode == Mips::DSRemIMacro ||
4393 Opcode == Mips::DURemMacro || Opcode == Mips::DURemIMacro;
4396 MCRegister ATReg = getATReg(IDLoc);
4400 if (!CLOpts.mno_check_zero_division && ImmValue == 0) {
4402 TOut.
emitRRI(Mips::TEQ, ZeroReg, ZeroReg, 0x7, IDLoc, STI);
4404 TOut.
emitII(Mips::BREAK, 0x7, 0, IDLoc, STI);
4408 if (isRem && (ImmValue == 1 || (
Signed && (ImmValue == -1)))) {
4409 TOut.
emitRRR(Mips::OR, RdReg, ZeroReg, ZeroReg, IDLoc, STI);
4411 }
else if (isDiv && ImmValue == 1) {
4412 TOut.
emitRRR(Mips::OR, RdReg, RsReg, Mips::R0, IDLoc, STI);
4414 }
else if (isDiv &&
Signed && ImmValue == -1) {
4415 TOut.
emitRRR(SubOp, RdReg, ZeroReg, RsReg, IDLoc, STI);
4418 if (loadImmediate(ImmValue, ATReg, MCRegister(),
isInt<32>(ImmValue),
4419 false, Inst.
getLoc(), Out, STI))
4421 TOut.
emitRR(DivOp, RsReg, ATReg, IDLoc, STI);
4422 TOut.
emitR(isDiv ? Mips::MFLO : Mips::MFHI, RdReg, IDLoc, STI);
4432 if (!CLOpts.mno_check_zero_division &&
4433 (RtReg == Mips::R0 || RtReg == Mips::R0_64)) {
4435 TOut.
emitRRI(Mips::TEQ, ZeroReg, ZeroReg, 0x7, IDLoc, STI);
4438 TOut.
emitII(Mips::BREAK, 0x7, 0, IDLoc, STI);
4444 if (isRem && (RdReg == Mips::R0 || RdReg == Mips::R0_64)) {
4445 TOut.
emitRR(DivOp, RsReg, RtReg, IDLoc, STI);
4454 TOut.
emitRR(DivOp, RsReg, RtReg, IDLoc, STI);
4455 if (!CLOpts.mno_check_zero_division) {
4457 TOut.
emitRRI(Mips::TEQ, RtReg, ZeroReg, 0x7, IDLoc, STI);
4460 BrTarget =
Context.createTempSymbol();
4463 TOut.
emitRRX(Mips::BNE, RtReg, ZeroReg, LabelOp, IDLoc, STI);
4468 TOut.
emitII(Mips::BREAK, 0x7, 0, IDLoc, STI);
4474 TOut.
emitR(isDiv ? Mips::MFLO : Mips::MFHI, RdReg, IDLoc, STI);
4478bool MipsAsmParser::expandTrunc(MCInst &Inst,
bool IsDouble,
bool Is64FPU,
4479 SMLoc IDLoc, MCStreamer &Out,
4480 const MCSubtargetInfo *STI) {
4481 MipsTargetStreamer &TOut = getTargetStreamer();
4491 if (hasMips1() && !hasMips2()) {
4492 MCRegister ATReg = getATReg(IDLoc);
4498 TOut.
emitRRI(Mips::ORi, ATReg, ThirdReg, 0x3, IDLoc, STI);
4499 TOut.
emitRRI(Mips::XORi, ATReg, ATReg, 0x2, IDLoc, STI);
4502 TOut.
emitRR(IsDouble ? (Is64FPU ? Mips::CVT_W_D64 : Mips::CVT_W_D32)
4504 FirstReg, SecondReg, IDLoc, STI);
4510 TOut.
emitRR(IsDouble ? (Is64FPU ? Mips::TRUNC_W_D64 : Mips::TRUNC_W_D32)
4512 FirstReg, SecondReg, IDLoc, STI);
4517bool MipsAsmParser::expandUlh(MCInst &Inst,
bool Signed, SMLoc IDLoc,
4518 MCStreamer &Out,
const MCSubtargetInfo *STI) {
4519 if (hasMips32r6() || hasMips64r6()) {
4520 return Error(IDLoc,
"instruction not supported on mips32r6 or mips64r6");
4523 const MCOperand &DstRegOp = Inst.
getOperand(0);
4524 assert(DstRegOp.
isReg() &&
"expected register operand kind");
4525 const MCOperand &SrcRegOp = Inst.
getOperand(1);
4526 assert(SrcRegOp.
isReg() &&
"expected register operand kind");
4527 const MCOperand &OffsetImmOp = Inst.
getOperand(2);
4528 assert(OffsetImmOp.
isImm() &&
"expected immediate operand kind");
4530 MipsTargetStreamer &TOut = getTargetStreamer();
4531 MCRegister DstReg = DstRegOp.
getReg();
4532 MCRegister SrcReg = SrcRegOp.
getReg();
4533 int64_t OffsetValue = OffsetImmOp.
getImm();
4537 warnIfNoMacro(IDLoc);
4538 MCRegister ATReg = getATReg(IDLoc);
4543 if (IsLargeOffset) {
4544 if (loadImmediate(OffsetValue, ATReg, SrcReg, !
ABI.ArePtrs64bit(),
true,
4549 int64_t FirstOffset = IsLargeOffset ? 0 : OffsetValue;
4550 int64_t SecondOffset = IsLargeOffset ? 1 : (OffsetValue + 1);
4554 MCRegister FirstLbuDstReg = IsLargeOffset ? DstReg : ATReg;
4555 MCRegister SecondLbuDstReg = IsLargeOffset ? ATReg : DstReg;
4557 MCRegister LbuSrcReg = IsLargeOffset ? ATReg : SrcReg;
4558 MCRegister SllReg = IsLargeOffset ? DstReg : ATReg;
4560 TOut.
emitRRI(
Signed ? Mips::LB : Mips::LBu, FirstLbuDstReg, LbuSrcReg,
4561 FirstOffset, IDLoc, STI);
4562 TOut.
emitRRI(Mips::LBu, SecondLbuDstReg, LbuSrcReg, SecondOffset, IDLoc, STI);
4563 TOut.
emitRRI(Mips::SLL, SllReg, SllReg, 8, IDLoc, STI);
4564 TOut.
emitRRR(Mips::OR, DstReg, DstReg, ATReg, IDLoc, STI);
4569bool MipsAsmParser::expandUsh(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
4570 const MCSubtargetInfo *STI) {
4571 if (hasMips32r6() || hasMips64r6()) {
4572 return Error(IDLoc,
"instruction not supported on mips32r6 or mips64r6");
4575 const MCOperand &DstRegOp = Inst.
getOperand(0);
4576 assert(DstRegOp.
isReg() &&
"expected register operand kind");
4577 const MCOperand &SrcRegOp = Inst.
getOperand(1);
4578 assert(SrcRegOp.
isReg() &&
"expected register operand kind");
4579 const MCOperand &OffsetImmOp = Inst.
getOperand(2);
4580 assert(OffsetImmOp.
isImm() &&
"expected immediate operand kind");
4582 MipsTargetStreamer &TOut = getTargetStreamer();
4583 MCRegister DstReg = DstRegOp.
getReg();
4584 MCRegister SrcReg = SrcRegOp.
getReg();
4585 int64_t OffsetValue = OffsetImmOp.
getImm();
4587 warnIfNoMacro(IDLoc);
4588 MCRegister ATReg = getATReg(IDLoc);
4593 if (IsLargeOffset) {
4594 if (loadImmediate(OffsetValue, ATReg, SrcReg, !
ABI.ArePtrs64bit(),
true,
4599 int64_t FirstOffset = IsLargeOffset ? 1 : (OffsetValue + 1);
4600 int64_t SecondOffset = IsLargeOffset ? 0 : OffsetValue;
4604 if (IsLargeOffset) {
4605 TOut.
emitRRI(Mips::SB, DstReg, ATReg, FirstOffset, IDLoc, STI);
4606 TOut.
emitRRI(Mips::SRL, DstReg, DstReg, 8, IDLoc, STI);
4607 TOut.
emitRRI(Mips::SB, DstReg, ATReg, SecondOffset, IDLoc, STI);
4608 TOut.
emitRRI(Mips::LBu, ATReg, ATReg, 0, IDLoc, STI);
4609 TOut.
emitRRI(Mips::SLL, DstReg, DstReg, 8, IDLoc, STI);
4610 TOut.
emitRRR(Mips::OR, DstReg, DstReg, ATReg, IDLoc, STI);
4612 TOut.
emitRRI(Mips::SB, DstReg, SrcReg, FirstOffset, IDLoc, STI);
4613 TOut.
emitRRI(Mips::SRL, ATReg, DstReg, 8, IDLoc, STI);
4614 TOut.
emitRRI(Mips::SB, ATReg, SrcReg, SecondOffset, IDLoc, STI);
4620bool MipsAsmParser::expandUxw(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
4621 const MCSubtargetInfo *STI) {
4622 if (hasMips32r6() || hasMips64r6()) {
4623 return Error(IDLoc,
"instruction not supported on mips32r6 or mips64r6");
4626 const MCOperand &DstRegOp = Inst.
getOperand(0);
4627 assert(DstRegOp.
isReg() &&
"expected register operand kind");
4628 const MCOperand &SrcRegOp = Inst.
getOperand(1);
4629 assert(SrcRegOp.
isReg() &&
"expected register operand kind");
4630 const MCOperand &OffsetImmOp = Inst.
getOperand(2);
4631 assert(OffsetImmOp.
isImm() &&
"expected immediate operand kind");
4633 MipsTargetStreamer &TOut = getTargetStreamer();
4634 MCRegister DstReg = DstRegOp.
getReg();
4635 MCRegister SrcReg = SrcRegOp.
getReg();
4636 int64_t OffsetValue = OffsetImmOp.
getImm();
4640 int64_t LxlOffset = IsLargeOffset ? 0 : OffsetValue;
4641 int64_t LxrOffset = IsLargeOffset ? 3 : (OffsetValue + 3);
4645 bool IsLoadInst = (Inst.
getOpcode() == Mips::Ulw);
4646 bool DoMove = IsLoadInst && (SrcReg == DstReg) && !IsLargeOffset;
4647 MCRegister TmpReg = SrcReg;
4648 if (IsLargeOffset || DoMove) {
4649 warnIfNoMacro(IDLoc);
4650 TmpReg = getATReg(IDLoc);
4655 if (IsLargeOffset) {
4656 if (loadImmediate(OffsetValue, TmpReg, SrcReg, !
ABI.ArePtrs64bit(),
true,
4664 unsigned XWL = IsLoadInst ? Mips::LWL : Mips::SWL;
4665 unsigned XWR = IsLoadInst ? Mips::LWR : Mips::SWR;
4666 TOut.
emitRRI(XWL, DstReg, TmpReg, LxlOffset, IDLoc, STI);
4667 TOut.
emitRRI(XWR, DstReg, TmpReg, LxrOffset, IDLoc, STI);
4670 TOut.
emitRRR(Mips::OR, TmpReg, DstReg, Mips::R0, IDLoc, STI);
4675bool MipsAsmParser::expandSge(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
4676 const MCSubtargetInfo *STI) {
4677 MipsTargetStreamer &TOut = getTargetStreamer();
4689 warnIfNoMacro(IDLoc);
4703 TOut.
emitRRR(OpCode, DstReg, SrcReg, OpReg, IDLoc, STI);
4704 TOut.
emitRRI(Mips::XORi, DstReg, DstReg, 1, IDLoc, STI);
4709bool MipsAsmParser::expandSgeImm(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
4710 const MCSubtargetInfo *STI) {
4711 MipsTargetStreamer &TOut = getTargetStreamer();
4721 unsigned OpRegCode, OpImmCode;
4723 warnIfNoMacro(IDLoc);
4727 case Mips::SGEImm64:
4728 OpRegCode = Mips::SLT;
4729 OpImmCode = Mips::SLTi;
4732 case Mips::SGEUImm64:
4733 OpRegCode = Mips::SLTu;
4734 OpImmCode = Mips::SLTiu;
4743 TOut.
emitRRI(OpImmCode, DstReg, SrcReg, ImmValue, IDLoc, STI);
4744 TOut.
emitRRI(Mips::XORi, DstReg, DstReg, 1, IDLoc, STI);
4746 MCRegister ImmReg = DstReg;
4747 if (DstReg == SrcReg) {
4748 MCRegister ATReg = getATReg(Inst.
getLoc());
4754 if (loadImmediate(ImmValue, ImmReg, MCRegister(),
isInt<32>(ImmValue),
4755 false, IDLoc, Out, STI))
4758 TOut.
emitRRR(OpRegCode, DstReg, SrcReg, ImmReg, IDLoc, STI);
4759 TOut.
emitRRI(Mips::XORi, DstReg, DstReg, 1, IDLoc, STI);
4765bool MipsAsmParser::expandSgtImm(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
4766 const MCSubtargetInfo *STI) {
4767 MipsTargetStreamer &TOut = getTargetStreamer();
4776 MCRegister ImmReg = DstReg;
4780 warnIfNoMacro(IDLoc);
4784 case Mips::SGTImm64:
4788 case Mips::SGTUImm64:
4795 if (DstReg == SrcReg) {
4796 MCRegister ATReg = getATReg(Inst.
getLoc());
4802 if (loadImmediate(ImmValue, ImmReg, MCRegister(),
isInt<32>(ImmValue),
false,
4807 TOut.
emitRRR(OpCode, DstReg, ImmReg, SrcReg, IDLoc, STI);
4812bool MipsAsmParser::expandSle(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
4813 const MCSubtargetInfo *STI) {
4814 MipsTargetStreamer &TOut = getTargetStreamer();
4826 warnIfNoMacro(IDLoc);
4840 TOut.
emitRRR(OpCode, DstReg, OpReg, SrcReg, IDLoc, STI);
4841 TOut.
emitRRI(Mips::XORi, DstReg, DstReg, 1, IDLoc, STI);
4846bool MipsAsmParser::expandSleImm(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
4847 const MCSubtargetInfo *STI) {
4848 MipsTargetStreamer &TOut = getTargetStreamer();
4860 warnIfNoMacro(IDLoc);
4864 case Mips::SLEImm64:
4865 OpRegCode = Mips::SLT;
4868 case Mips::SLEUImm64:
4869 OpRegCode = Mips::SLTu;
4876 MCRegister ImmReg = DstReg;
4877 if (DstReg == SrcReg) {
4878 MCRegister ATReg = getATReg(Inst.
getLoc());
4884 if (loadImmediate(ImmValue, ImmReg, MCRegister(),
isInt<32>(ImmValue),
false,
4888 TOut.
emitRRR(OpRegCode, DstReg, ImmReg, SrcReg, IDLoc, STI);
4889 TOut.
emitRRI(Mips::XORi, DstReg, DstReg, 1, IDLoc, STI);
4894bool MipsAsmParser::expandAliasImmediate(MCInst &Inst, SMLoc IDLoc,
4896 const MCSubtargetInfo *STI) {
4897 MipsTargetStreamer &TOut = getTargetStreamer();
4905 MCRegister FinalDstReg;
4912 unsigned FinalOpcode = Inst.
getOpcode();
4914 if (DstReg == SrcReg) {
4915 ATReg = getATReg(Inst.
getLoc());
4918 FinalDstReg = DstReg;
4922 if (!loadImmediate(ImmValue, DstReg, MCRegister(), Is32Bit,
false,
4923 Inst.
getLoc(), Out, STI)) {
4924 switch (FinalOpcode) {
4928 FinalOpcode = Mips::ADD;
4931 FinalOpcode = Mips::ADDu;
4934 FinalOpcode = Mips::AND;
4937 FinalOpcode = Mips::NOR;
4940 FinalOpcode = Mips::OR;
4943 FinalOpcode = Mips::SLT;
4946 FinalOpcode = Mips::SLTu;
4949 FinalOpcode = Mips::XOR;
4952 FinalOpcode = Mips::ADD_MM;
4954 case Mips::ADDiu_MM:
4955 FinalOpcode = Mips::ADDu_MM;
4958 FinalOpcode = Mips::AND_MM;
4961 FinalOpcode = Mips::OR_MM;
4964 FinalOpcode = Mips::SLT_MM;
4966 case Mips::SLTiu_MM:
4967 FinalOpcode = Mips::SLTu_MM;
4970 FinalOpcode = Mips::XOR_MM;
4973 FinalOpcode = Mips::AND64;
4975 case Mips::NORImm64:
4976 FinalOpcode = Mips::NOR64;
4979 FinalOpcode = Mips::OR64;
4981 case Mips::SLTImm64:
4982 FinalOpcode = Mips::SLT64;
4984 case Mips::SLTUImm64:
4985 FinalOpcode = Mips::SLTu64;
4988 FinalOpcode = Mips::XOR64;
4993 TOut.
emitRRR(FinalOpcode, DstReg, DstReg, SrcReg, IDLoc, STI);
4995 TOut.
emitRRR(FinalOpcode, FinalDstReg, FinalDstReg, DstReg, IDLoc, STI);
5001bool MipsAsmParser::expandRotation(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
5002 const MCSubtargetInfo *STI) {
5003 MipsTargetStreamer &TOut = getTargetStreamer();
5008 MCRegister TmpReg =
DReg;
5010 unsigned FirstShift = Mips::NOP;
5011 unsigned SecondShift = Mips::NOP;
5013 if (hasMips32r2()) {
5015 TmpReg = getATReg(Inst.
getLoc());
5021 TOut.
emitRRR(Mips::SUBu, TmpReg, Mips::R0, TReg, Inst.
getLoc(), STI);
5022 TOut.
emitRRR(Mips::ROTRV, DReg, SReg, TmpReg, Inst.
getLoc(), STI);
5027 TOut.
emitRRR(Mips::ROTRV, DReg, SReg, TReg, Inst.
getLoc(), STI);
5039 FirstShift = Mips::SRLV;
5040 SecondShift = Mips::SLLV;
5043 FirstShift = Mips::SLLV;
5044 SecondShift = Mips::SRLV;
5048 ATReg = getATReg(Inst.
getLoc());
5052 TOut.
emitRRR(Mips::SUBu, ATReg, Mips::R0, TReg, Inst.
getLoc(), STI);
5053 TOut.
emitRRR(FirstShift, ATReg, SReg, ATReg, Inst.
getLoc(), STI);
5054 TOut.
emitRRR(SecondShift, DReg, SReg, TReg, Inst.
getLoc(), STI);
5055 TOut.
emitRRR(Mips::OR, DReg, DReg, ATReg, Inst.
getLoc(), STI);
5063bool MipsAsmParser::expandRotationImm(MCInst &Inst, SMLoc IDLoc,
5065 const MCSubtargetInfo *STI) {
5066 MipsTargetStreamer &TOut = getTargetStreamer();
5072 unsigned FirstShift = Mips::NOP;
5073 unsigned SecondShift = Mips::NOP;
5075 if (hasMips32r2()) {
5080 ShiftValue = MaxShift - ImmValue;
5081 TOut.
emitRRI(Mips::ROTR, DReg, SReg, ShiftValue, Inst.
getLoc(), STI);
5086 TOut.
emitRRI(Mips::ROTR, DReg, SReg, ImmValue, Inst.
getLoc(), STI);
5094 if (ImmValue == 0) {
5103 FirstShift = Mips::SLL;
5104 SecondShift = Mips::SRL;
5107 FirstShift = Mips::SRL;
5108 SecondShift = Mips::SLL;
5112 ATReg = getATReg(Inst.
getLoc());
5116 TOut.
emitRRI(FirstShift, ATReg, SReg, ImmValue, Inst.
getLoc(), STI);
5117 TOut.
emitRRI(SecondShift, DReg, SReg, 32 - ImmValue, Inst.
getLoc(), STI);
5118 TOut.
emitRRR(Mips::OR, DReg, DReg, ATReg, Inst.
getLoc(), STI);
5126bool MipsAsmParser::expandDRotation(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
5127 const MCSubtargetInfo *STI) {
5128 MipsTargetStreamer &TOut = getTargetStreamer();
5133 MCRegister TmpReg =
DReg;
5135 unsigned FirstShift = Mips::NOP;
5136 unsigned SecondShift = Mips::NOP;
5138 if (hasMips64r2()) {
5139 if (TmpReg == SReg) {
5140 TmpReg = getATReg(Inst.
getLoc());
5146 TOut.
emitRRR(Mips::DSUBu, TmpReg, Mips::R0, TReg, Inst.
getLoc(), STI);
5147 TOut.
emitRRR(Mips::DROTRV, DReg, SReg, TmpReg, Inst.
getLoc(), STI);
5152 TOut.
emitRRR(Mips::DROTRV, DReg, SReg, TReg, Inst.
getLoc(), STI);
5164 FirstShift = Mips::DSRLV;
5165 SecondShift = Mips::DSLLV;
5168 FirstShift = Mips::DSLLV;
5169 SecondShift = Mips::DSRLV;
5173 ATReg = getATReg(Inst.
getLoc());
5177 TOut.
emitRRR(Mips::DSUBu, ATReg, Mips::R0, TReg, Inst.
getLoc(), STI);
5178 TOut.
emitRRR(FirstShift, ATReg, SReg, ATReg, Inst.
getLoc(), STI);
5179 TOut.
emitRRR(SecondShift, DReg, SReg, TReg, Inst.
getLoc(), STI);
5180 TOut.
emitRRR(Mips::OR, DReg, DReg, ATReg, Inst.
getLoc(), STI);
5188bool MipsAsmParser::expandDRotationImm(MCInst &Inst, SMLoc IDLoc,
5190 const MCSubtargetInfo *STI) {
5191 MipsTargetStreamer &TOut = getTargetStreamer();
5197 unsigned FirstShift = Mips::NOP;
5198 unsigned SecondShift = Mips::NOP;
5200 if (hasMips64r2()) {
5201 unsigned FinalOpcode = Mips::NOP;
5203 FinalOpcode = Mips::DROTR;
5204 else if (ImmValue % 32 == 0)
5205 FinalOpcode = Mips::DROTR32;
5206 else if ((ImmValue >= 1) && (ImmValue <= 32)) {
5208 FinalOpcode = Mips::DROTR32;
5210 FinalOpcode = Mips::DROTR;
5211 }
else if (ImmValue >= 33) {
5213 FinalOpcode = Mips::DROTR;
5215 FinalOpcode = Mips::DROTR32;
5218 uint64_t ShiftValue = ImmValue % 32;
5220 ShiftValue = (32 - ImmValue % 32) % 32;
5222 TOut.
emitRRI(FinalOpcode, DReg, SReg, ShiftValue, Inst.
getLoc(), STI);
5228 if (ImmValue == 0) {
5229 TOut.
emitRRI(Mips::DSRL, DReg, SReg, 0, Inst.
getLoc(), STI);
5237 if ((ImmValue >= 1) && (ImmValue <= 31)) {
5238 FirstShift = Mips::DSLL;
5239 SecondShift = Mips::DSRL32;
5241 if (ImmValue == 32) {
5242 FirstShift = Mips::DSLL32;
5243 SecondShift = Mips::DSRL32;
5245 if ((ImmValue >= 33) && (ImmValue <= 63)) {
5246 FirstShift = Mips::DSLL32;
5247 SecondShift = Mips::DSRL;
5251 if ((ImmValue >= 1) && (ImmValue <= 31)) {
5252 FirstShift = Mips::DSRL;
5253 SecondShift = Mips::DSLL32;
5255 if (ImmValue == 32) {
5256 FirstShift = Mips::DSRL32;
5257 SecondShift = Mips::DSLL32;
5259 if ((ImmValue >= 33) && (ImmValue <= 63)) {
5260 FirstShift = Mips::DSRL32;
5261 SecondShift = Mips::DSLL;
5266 ATReg = getATReg(Inst.
getLoc());
5270 TOut.
emitRRI(FirstShift, ATReg, SReg, ImmValue % 32, Inst.
getLoc(), STI);
5271 TOut.
emitRRI(SecondShift, DReg, SReg, (32 - ImmValue % 32) % 32,
5273 TOut.
emitRRR(Mips::OR, DReg, DReg, ATReg, Inst.
getLoc(), STI);
5281bool MipsAsmParser::expandAbs(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
5282 const MCSubtargetInfo *STI) {
5283 MipsTargetStreamer &TOut = getTargetStreamer();
5287 TOut.
emitRI(Mips::BGEZ, SecondRegOp, 8, IDLoc, STI);
5288 if (FirstRegOp != SecondRegOp)
5289 TOut.
emitRRR(Mips::ADDu, FirstRegOp, SecondRegOp, Mips::R0, IDLoc, STI);
5292 TOut.
emitRRR(Mips::SUB, FirstRegOp, Mips::R0, SecondRegOp, IDLoc, STI);
5297bool MipsAsmParser::expandMulImm(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
5298 const MCSubtargetInfo *STI) {
5299 MipsTargetStreamer &TOut = getTargetStreamer();
5305 ATReg = getATReg(IDLoc);
5309 loadImmediate(ImmValue, ATReg, MCRegister(),
true,
false, IDLoc, Out, STI);
5311 TOut.
emitRR(Inst.
getOpcode() == Mips::MULImmMacro ? Mips::MULT : Mips::DMULT,
5312 SrcReg, ATReg, IDLoc, STI);
5314 TOut.
emitR(Mips::MFLO, DstReg, IDLoc, STI);
5319bool MipsAsmParser::expandMulO(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
5320 const MCSubtargetInfo *STI) {
5321 MipsTargetStreamer &TOut = getTargetStreamer();
5327 ATReg = getATReg(Inst.
getLoc());
5331 TOut.
emitRR(Inst.
getOpcode() == Mips::MULOMacro ? Mips::MULT : Mips::DMULT,
5332 SrcReg, TmpReg, IDLoc, STI);
5334 TOut.
emitR(Mips::MFLO, DstReg, IDLoc, STI);
5336 TOut.
emitRRI(Inst.
getOpcode() == Mips::MULOMacro ? Mips::SRA : Mips::DSRA32,
5337 DstReg, DstReg, 0x1F, IDLoc, STI);
5339 TOut.
emitR(Mips::MFHI, ATReg, IDLoc, STI);
5342 TOut.
emitRRI(Mips::TNE, DstReg, ATReg, 6, IDLoc, STI);
5349 TOut.
emitRRX(Mips::BEQ, DstReg, ATReg, LabelOp, IDLoc, STI);
5350 if (AssemblerOptions.
back()->isReorder())
5352 TOut.
emitII(Mips::BREAK, 6, 0, IDLoc, STI);
5356 TOut.
emitR(Mips::MFLO, DstReg, IDLoc, STI);
5361bool MipsAsmParser::expandMulOU(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
5362 const MCSubtargetInfo *STI) {
5363 MipsTargetStreamer &TOut = getTargetStreamer();
5369 ATReg = getATReg(IDLoc);
5373 TOut.
emitRR(Inst.
getOpcode() == Mips::MULOUMacro ? Mips::MULTu : Mips::DMULTu,
5374 SrcReg, TmpReg, IDLoc, STI);
5376 TOut.
emitR(Mips::MFHI, ATReg, IDLoc, STI);
5377 TOut.
emitR(Mips::MFLO, DstReg, IDLoc, STI);
5379 TOut.
emitRRI(Mips::TNE, ATReg, Mips::R0, 6, IDLoc, STI);
5386 TOut.
emitRRX(Mips::BEQ, ATReg, Mips::R0, LabelOp, IDLoc, STI);
5387 if (AssemblerOptions.
back()->isReorder())
5389 TOut.
emitII(Mips::BREAK, 6, 0, IDLoc, STI);
5397bool MipsAsmParser::expandDMULMacro(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
5398 const MCSubtargetInfo *STI) {
5399 MipsTargetStreamer &TOut = getTargetStreamer();
5404 TOut.
emitRR(Mips::DMULTu, SrcReg, TmpReg, IDLoc, STI);
5405 TOut.
emitR(Mips::MFLO, DstReg, IDLoc, STI);
5415bool MipsAsmParser::expandLoadStoreDMacro(MCInst &Inst, SMLoc IDLoc,
5417 const MCSubtargetInfo *STI,
5422 warnIfNoMacro(IDLoc);
5424 MipsTargetStreamer &TOut = getTargetStreamer();
5425 unsigned Opcode = IsLoad ? Mips::LW : Mips::SW;
5427 MCRegister SecondReg =
nextReg(FirstReg);
5432 warnIfRegIndexIsAT(FirstReg, IDLoc);
5435 "Offset for load macro is not immediate!");
5438 signed NextOffset = FirstOffset.
getImm() + 4;
5446 if (FirstReg != BaseReg || !IsLoad) {
5447 TOut.
emitRRX(Opcode, FirstReg, BaseReg, FirstOffset, IDLoc, STI);
5448 TOut.
emitRRX(Opcode, SecondReg, BaseReg, SecondOffset, IDLoc, STI);
5450 TOut.
emitRRX(Opcode, SecondReg, BaseReg, SecondOffset, IDLoc, STI);
5451 TOut.
emitRRX(Opcode, FirstReg, BaseReg, FirstOffset, IDLoc, STI);
5463bool MipsAsmParser::expandStoreDM1Macro(MCInst &Inst, SMLoc IDLoc,
5465 const MCSubtargetInfo *STI) {
5469 warnIfNoMacro(IDLoc);
5471 MipsTargetStreamer &TOut = getTargetStreamer();
5472 unsigned Opcode = Mips::SWC1;
5474 MCRegister SecondReg =
nextReg(FirstReg);
5479 warnIfRegIndexIsAT(FirstReg, IDLoc);
5482 "Offset for macro is not immediate!");
5485 signed NextOffset = FirstOffset.
getImm() + 4;
5491 if (!IsLittleEndian)
5494 TOut.
emitRRX(Opcode, FirstReg, BaseReg, FirstOffset, IDLoc, STI);
5495 TOut.
emitRRX(Opcode, SecondReg, BaseReg, SecondOffset, IDLoc, STI);
5500bool MipsAsmParser::expandSeq(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
5501 const MCSubtargetInfo *STI) {
5502 MipsTargetStreamer &TOut = getTargetStreamer();
5513 warnIfNoMacro(IDLoc);
5515 if (SrcReg != Mips::R0 && OpReg != Mips::R0) {
5516 TOut.
emitRRR(Mips::XOR, DstReg, SrcReg, OpReg, IDLoc, STI);
5517 TOut.
emitRRI(Mips::SLTiu, DstReg, DstReg, 1, IDLoc, STI);
5521 MCRegister
Reg = SrcReg == Mips::R0 ? OpReg : SrcReg;
5522 TOut.
emitRRI(Mips::SLTiu, DstReg,
Reg, 1, IDLoc, STI);
5526bool MipsAsmParser::expandSeqI(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
5527 const MCSubtargetInfo *STI) {
5528 MipsTargetStreamer &TOut = getTargetStreamer();
5539 warnIfNoMacro(IDLoc);
5542 TOut.
emitRRI(Mips::SLTiu, DstReg, SrcReg, 1, IDLoc, STI);
5546 if (SrcReg == Mips::R0) {
5547 Warning(IDLoc,
"comparison is always false");
5548 TOut.
emitRRR(isGP64bit() ? Mips::DADDu : Mips::ADDu,
5549 DstReg, SrcReg, SrcReg, IDLoc, STI);
5554 if (
Imm > -0x8000 &&
Imm < 0) {
5556 Opc = isGP64bit() ? Mips::DADDiu : Mips::ADDiu;
5562 MCRegister ATReg = getATReg(IDLoc);
5566 if (loadImmediate(
Imm, ATReg, MCRegister(),
true, isGP64bit(), IDLoc, Out,
5570 TOut.
emitRRR(Mips::XOR, DstReg, SrcReg, ATReg, IDLoc, STI);
5571 TOut.
emitRRI(Mips::SLTiu, DstReg, DstReg, 1, IDLoc, STI);
5576 TOut.
emitRRI(Mips::SLTiu, DstReg, DstReg, 1, IDLoc, STI);
5580bool MipsAsmParser::expandSne(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
5581 const MCSubtargetInfo *STI) {
5583 MipsTargetStreamer &TOut = getTargetStreamer();
5594 warnIfNoMacro(IDLoc);
5596 if (SrcReg != Mips::R0 && OpReg != Mips::R0) {
5597 TOut.
emitRRR(Mips::XOR, DstReg, SrcReg, OpReg, IDLoc, STI);
5598 TOut.
emitRRR(Mips::SLTu, DstReg, Mips::R0, DstReg, IDLoc, STI);
5602 MCRegister
Reg = SrcReg == Mips::R0 ? OpReg : SrcReg;
5603 TOut.
emitRRR(Mips::SLTu, DstReg, Mips::R0,
Reg, IDLoc, STI);
5607bool MipsAsmParser::expandSneI(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
5608 const MCSubtargetInfo *STI) {
5609 MipsTargetStreamer &TOut = getTargetStreamer();
5620 warnIfNoMacro(IDLoc);
5622 if (ImmValue == 0) {
5623 TOut.
emitRRR(Mips::SLTu, DstReg, Mips::R0, SrcReg, IDLoc, STI);
5627 if (SrcReg == Mips::R0) {
5628 Warning(IDLoc,
"comparison is always true");
5629 if (loadImmediate(1, DstReg, MCRegister(),
true,
false, IDLoc, Out, STI))
5635 if (ImmValue > -0x8000 && ImmValue < 0) {
5636 ImmValue = -ImmValue;
5637 Opc = isGP64bit() ? Mips::DADDiu : Mips::ADDiu;
5643 TOut.
emitRRI(
Opc, DstReg, SrcReg, ImmValue, IDLoc, STI);
5644 TOut.
emitRRR(Mips::SLTu, DstReg, Mips::R0, DstReg, IDLoc, STI);
5648 MCRegister ATReg = getATReg(IDLoc);
5652 if (loadImmediate(ImmValue, ATReg, MCRegister(),
isInt<32>(ImmValue),
false,
5656 TOut.
emitRRR(Mips::XOR, DstReg, SrcReg, ATReg, IDLoc, STI);
5657 TOut.
emitRRR(Mips::SLTu, DstReg, Mips::R0, DstReg, IDLoc, STI);
5791bool MipsAsmParser::expandMXTRAlias(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
5792 const MCSubtargetInfo *STI) {
5793 MipsTargetStreamer &TOut = getTargetStreamer();
5797 bool IsMFTR =
false;
5843 IsMFTR ? MCRegister(rd)
5845 : Inst.getOperand(0).
getReg());
5847 TOut.
emitRRIII(IsMFTR ? Mips::MFTR : Mips::MTTR, Op0, Op1, 1, sel, h, IDLoc,
5852bool MipsAsmParser::expandSaaAddr(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
5853 const MCSubtargetInfo *STI) {
5858 warnIfNoMacro(IDLoc);
5860 MipsTargetStreamer &TOut = getTargetStreamer();
5861 unsigned Opcode = Inst.
getOpcode() == Mips::SaaAddr ? Mips::SAA : Mips::SAAD;
5864 const MCOperand &BaseOp = Inst.
getOperand(2);
5866 if (BaseOp.
isImm()) {
5867 int64_t ImmValue = BaseOp.
getImm();
5868 if (ImmValue == 0) {
5869 TOut.
emitRR(Opcode, RtReg, BaseReg, IDLoc, STI);
5874 MCRegister ATReg = getATReg(IDLoc);
5878 if (expandLoadAddress(ATReg, BaseReg, BaseOp, !isGP64bit(), IDLoc, Out, STI))
5881 TOut.
emitRR(Opcode, RtReg, ATReg, IDLoc, STI);
5886MipsAsmParser::checkEarlyTargetMatchPredicate(MCInst &Inst,
5890 return Match_Success;
5893 if (
static_cast<MipsOperand &
>(*
Operands[1])
5894 .isValidForTie(
static_cast<MipsOperand &
>(*
Operands[2])))
5895 return Match_Success;
5896 return Match_RequiresSameSrcAndDst;
5900unsigned MipsAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
5907 return Match_RequiresNoZeroRegister;
5908 return Match_Success;
5914 case Mips::JALR_HB64:
5915 case Mips::JALRC_HB_MMR6:
5916 case Mips::JALRC_MMR6:
5918 return Match_RequiresDifferentSrcAndDst;
5919 return Match_Success;
5922 return Match_RequiresDifferentSrcAndDst;
5923 return Match_Success;
5926 return Match_NonZeroOperandForSync;
5927 return Match_Success;
5931 return Match_NonZeroOperandForMTCX;
5932 return Match_Success;
5945 case Mips::BLEZC:
case Mips::BLEZC_MMR6:
5946 case Mips::BGEZC:
case Mips::BGEZC_MMR6:
5947 case Mips::BGTZC:
case Mips::BGTZC_MMR6:
5948 case Mips::BLTZC:
case Mips::BLTZC_MMR6:
5949 case Mips::BEQZC:
case Mips::BEQZC_MMR6:
5950 case Mips::BNEZC:
case Mips::BNEZC_MMR6:
5959 return Match_RequiresNoZeroRegister;
5960 return Match_Success;
5961 case Mips::BGEC:
case Mips::BGEC_MMR6:
5962 case Mips::BLTC:
case Mips::BLTC_MMR6:
5963 case Mips::BGEUC:
case Mips::BGEUC_MMR6:
5964 case Mips::BLTUC:
case Mips::BLTUC_MMR6:
5965 case Mips::BEQC:
case Mips::BEQC_MMR6:
5966 case Mips::BNEC:
case Mips::BNEC_MMR6:
5975 return Match_RequiresNoZeroRegister;
5978 return Match_RequiresNoZeroRegister;
5980 return Match_RequiresDifferentOperands;
5981 return Match_Success;
5984 "Operands must be immediates for dins!");
5987 if ((0 > (Pos +
Size)) || ((Pos +
Size) > 32))
5988 return Match_RequiresPosSizeRange0_32;
5989 return Match_Success;
5994 "Operands must be immediates for dinsm/dinsu!");
5997 if ((32 >= (Pos +
Size)) || ((Pos +
Size) > 64))
5998 return Match_RequiresPosSizeRange33_64;
5999 return Match_Success;
6003 "Operands must be immediates for DEXTM!");
6006 if ((1 > (Pos +
Size)) || ((Pos +
Size) > 63))
6007 return Match_RequiresPosSizeUImm6;
6008 return Match_Success;
6013 "Operands must be immediates for dextm/dextu!");
6016 if ((32 > (Pos +
Size)) || ((Pos +
Size) > 64))
6017 return Match_RequiresPosSizeRange33_64;
6018 return Match_Success;
6020 case Mips::CRC32B:
case Mips::CRC32CB:
6021 case Mips::CRC32H:
case Mips::CRC32CH:
6022 case Mips::CRC32W:
case Mips::CRC32CW:
6023 case Mips::CRC32D:
case Mips::CRC32CD:
6025 return Match_RequiresSameSrcAndDst;
6026 return Match_Success;
6032 return Match_NoFCCRegisterForCurrentISA;
6034 return Match_Success;
6042 if (ErrorLoc ==
SMLoc())
6049bool MipsAsmParser::matchAndEmitInstruction(SMLoc IDLoc,
unsigned &Opcode,
6053 bool MatchingInlineAsm) {
6055 unsigned MatchResult =
6056 MatchInstructionImpl(
Operands, Inst, ErrorInfo, MatchingInlineAsm);
6058 switch (MatchResult) {
6060 if (processInstruction(Inst, IDLoc, Out, STI))
6063 case Match_MissingFeature:
6064 Error(IDLoc,
"instruction requires a CPU feature not currently enabled");
6066 case Match_InvalidTiedOperand:
6067 Error(IDLoc,
"operand must match destination register");
6069 case Match_InvalidOperand: {
6070 SMLoc ErrorLoc = IDLoc;
6071 if (ErrorInfo != ~0ULL) {
6073 return Error(IDLoc,
"too few operands for instruction");
6075 ErrorLoc =
Operands[ErrorInfo]->getStartLoc();
6077 ErrorLoc =
static_cast<MipsOperand &
>(*
Operands[ErrorInfo])
6080 if (ErrorLoc == SMLoc())
6084 return Error(ErrorLoc,
"invalid operand for instruction");
6086 case Match_NonZeroOperandForSync:
6088 "s-type must be zero or unspecified for pre-MIPS32 ISAs");
6089 case Match_NonZeroOperandForMTCX:
6090 return Error(IDLoc,
"selector must be zero for pre-MIPS32 ISAs");
6091 case Match_MnemonicFail:
6092 return Error(IDLoc,
"invalid instruction");
6093 case Match_RequiresDifferentSrcAndDst:
6094 return Error(IDLoc,
"source and destination must be different");
6095 case Match_RequiresDifferentOperands:
6096 return Error(IDLoc,
"registers must be different");
6097 case Match_RequiresNoZeroRegister:
6098 return Error(IDLoc,
"invalid operand ($zero) for instruction");
6099 case Match_RequiresSameSrcAndDst:
6100 return Error(IDLoc,
"source and destination must match");
6101 case Match_NoFCCRegisterForCurrentISA:
6103 "non-zero fcc register doesn't exist in current ISA level");
6108 "expected 1-bit unsigned immediate");
6111 "expected 2-bit unsigned immediate");
6114 "expected immediate in range 1 .. 4");
6117 "expected 3-bit unsigned immediate");
6120 "expected 4-bit unsigned immediate");
6123 "expected 4-bit signed immediate");
6126 "expected 5-bit unsigned immediate");
6129 "expected 5-bit signed immediate");
6132 "expected immediate in range 1 .. 32");
6133 case Match_UImm5_32:
6135 "expected immediate in range 32 .. 63");
6136 case Match_UImm5_33:
6138 "expected immediate in range 33 .. 64");
6139 case Match_UImm5_0_Report_UImm6:
6143 "expected 6-bit unsigned immediate");
6144 case Match_ConstantMemOffset:
6146 !
static_cast<MipsOperand &
>(*
Operands[ErrorInfo]).isConstantImm())
6148 "expected immediate operand kind");
6150 "immediate operand value out of range");
6151 case Match_UImm5_Lsl2:
6153 "expected both 7-bit unsigned immediate and multiple of 4");
6154 case Match_UImmRange2_64:
6156 "expected immediate in range 2 .. 64");
6159 "expected 6-bit unsigned immediate");
6160 case Match_UImm6_Lsl2:
6162 "expected both 8-bit unsigned immediate and multiple of 4");
6165 "expected 6-bit signed immediate");
6168 "expected 7-bit unsigned immediate");
6169 case Match_UImm7_N1:
6171 "expected immediate in range -1 .. 126");
6172 case Match_SImm7_Lsl2:
6174 "expected both 9-bit signed immediate and multiple of 4");
6177 "expected 8-bit unsigned immediate");
6178 case Match_UImm10_0:
6180 "expected 10-bit unsigned immediate");
6181 case Match_SImm10_0:
6183 "expected 10-bit signed immediate");
6184 case Match_SImm11_0:
6186 "expected 11-bit signed immediate");
6188 case Match_UImm16_Relaxed:
6189 case Match_UImm16_AltRelaxed:
6191 "expected 16-bit unsigned immediate");
6193 case Match_SImm16_Relaxed:
6195 "expected 16-bit signed immediate");
6196 case Match_SImm18_Lsl3:
6198 "expected both 18-bit signed immediate and multiple of 8");
6199 case Match_SImm19_Lsl2:
6201 "expected both 19-bit signed immediate and multiple of 4");
6202 case Match_UImm20_0:
6204 "expected 20-bit unsigned immediate");
6205 case Match_UImm26_0:
6207 "expected 26-bit unsigned immediate");
6209 case Match_SImm32_Relaxed:
6211 "expected 32-bit signed immediate");
6212 case Match_UImm32_Coerced:
6214 "expected 32-bit immediate");
6215 case Match_MemSImm9:
6217 "expected memory with 9-bit signed offset");
6218 case Match_MemSImm10:
6220 "expected memory with 10-bit signed offset");
6221 case Match_MemSImm10Lsl1:
6223 "expected memory with 11-bit signed offset and multiple of 2");
6224 case Match_MemSImm10Lsl2:
6226 "expected memory with 12-bit signed offset and multiple of 4");
6227 case Match_MemSImm10Lsl3:
6229 "expected memory with 13-bit signed offset and multiple of 8");
6230 case Match_MemSImm11:
6232 "expected memory with 11-bit signed offset");
6233 case Match_MemSImm12:
6235 "expected memory with 12-bit signed offset");
6236 case Match_MemSImm16:
6238 "expected memory with 16-bit signed offset");
6239 case Match_MemSImmPtr:
6241 "expected memory with 32-bit signed offset");
6242 case Match_RequiresPosSizeRange0_32: {
6243 SMLoc ErrorStart =
Operands[3]->getStartLoc();
6244 SMLoc ErrorEnd =
Operands[4]->getEndLoc();
6245 return Error(ErrorStart,
"size plus position are not in the range 0 .. 32",
6246 SMRange(ErrorStart, ErrorEnd));
6248 case Match_RequiresPosSizeUImm6: {
6249 SMLoc ErrorStart =
Operands[3]->getStartLoc();
6250 SMLoc ErrorEnd =
Operands[4]->getEndLoc();
6251 return Error(ErrorStart,
"size plus position are not in the range 1 .. 63",
6252 SMRange(ErrorStart, ErrorEnd));
6254 case Match_RequiresPosSizeRange33_64: {
6255 SMLoc ErrorStart =
Operands[3]->getStartLoc();
6256 SMLoc ErrorEnd =
Operands[4]->getEndLoc();
6257 return Error(ErrorStart,
"size plus position are not in the range 33 .. 64",
6258 SMRange(ErrorStart, ErrorEnd));
6265void MipsAsmParser::warnIfRegIndexIsAT(MCRegister RegIndex, SMLoc Loc) {
6266 if (RegIndex && AssemblerOptions.
back()->getATRegIndex() == RegIndex)
6267 Warning(Loc,
"used $at (currently $" + Twine(RegIndex.
id()) +
6268 ") without \".set noat\"");
6271void MipsAsmParser::warnIfNoMacro(SMLoc Loc) {
6272 if (!AssemblerOptions.
back()->isMacro())
6273 Warning(Loc,
"macro instruction expanded into multiple instructions");
6276void MipsAsmParser::ConvertXWPOperands(MCInst &Inst,
6280 "Unexpected instruction!");
6281 ((MipsOperand &)*
Operands[1]).addGPR32ZeroAsmRegOperands(Inst, 1);
6282 MCRegister NextReg =
nextReg(((MipsOperand &)*
Operands[1]).getGPR32Reg());
6284 static_cast<MipsOperand &
>(*
Operands[4]).addPtrRegOperands(Inst, 1);
6285 static_cast<MipsOperand &
>(*
Operands[2]).addImmOperands(Inst, 1);
6288template <
unsigned Opcode,
bool IsMFTR>
6289void MipsAsmParser::ConvertMTTransferCOP0Operands(
6291 MCRegister GPR =
static_cast<const MipsOperand &
>(*
Operands[1]).getGPR32Reg();
6293 static_cast<const MipsOperand &
>(*
Operands[2]).getCOP0Encoding();
6297 ->getRegClass(Mips::GPR32RegClassID)
6308MipsAsmParser::printWarningWithFixIt(
const Twine &
Msg,
const Twine &FixMsg,
6309 SMRange
Range,
bool ShowColors) {
6315int MipsAsmParser::matchCPURegisterName(StringRef Name) {
6316 const MCRegisterInfo &
MRI = *
getContext().getRegisterInfo();
6322 AsmToken RegTok = getLexer().peekTok();
6323 StringRef FixedName =
6325 printWarningWithFixIt(
"register names $t4-$t7 are only available in O32.",
6326 "Did you mean $" + FixedName +
"?",
6332int MipsAsmParser::matchHWRegsRegisterName(StringRef Name) {
6333 const MCRegisterInfo &
MRI = *
getContext().getRegisterInfo();
6335 Mips::RegAliasName);
6336 return Reg ?
MRI.getEncodingValue(
Reg) : -1;
6339int MipsAsmParser::matchFPURegisterName(StringRef Name) {
6340 if (Name[0] ==
'f') {
6341 StringRef NumString =
Name.substr(1);
6352int MipsAsmParser::matchFCCRegisterName(StringRef Name) {
6353 if (
Name.starts_with(
"fcc")) {
6354 StringRef NumString =
Name.substr(3);
6365int MipsAsmParser::matchACRegisterName(StringRef Name) {
6366 if (
Name.starts_with(
"ac")) {
6367 StringRef NumString =
Name.substr(2);
6378int MipsAsmParser::matchMSA128RegisterName(StringRef Name) {
6381 if (
Name.front() !=
'w' ||
Name.drop_front(1).getAsInteger(10, IntVal))
6390int MipsAsmParser::matchMSA128CtrlRegisterName(StringRef Name) {
6391 const MCRegisterInfo &
MRI = *
getContext().getRegisterInfo();
6393 Name,
MRI, Mips::MSACtrlRegClassID, Mips::RegAliasName);
6394 return Reg ?
MRI.getEncodingValue(
Reg) : -1;
6397bool MipsAsmParser::canUseATReg() {
6398 return AssemblerOptions.
back()->getATRegIndex() != 0;
6401MCRegister MipsAsmParser::getATReg(SMLoc Loc) {
6402 unsigned ATIndex = AssemblerOptions.
back()->getATRegIndex();
6404 reportParseError(Loc,
6405 "pseudo-instruction requires $at, which is not available");
6409 (isGP64bit()) ? Mips::GPR64RegClassID : Mips::GPR32RegClassID, ATIndex);
6413MCRegister MipsAsmParser::getReg(
int RC,
int RegNo) {
6414 return getContext().getRegisterInfo()->getRegClass(RC).getRegister(RegNo);
6419bool MipsAsmParser::parsePrimaryExpr(
const MCExpr *&Res, SMLoc &EndLoc) {
6421 return getParser().parsePrimaryExpr(Res, EndLoc);
6422 Res = parseRelocExpr();
6423 EndLoc = getLexer().getLoc();
6429const MCExpr *MipsAsmParser::parseRelocExpr() {
6430 auto getOp = [](StringRef
Op) {
6431 return StringSwitch<Mips::Specifier>(
Op)
6459 MCAsmParser &Parser = getParser();
6461 const MCExpr *Res =
nullptr;
6467 auto Op = getOp(Name);
6476 while (
Ops.size()) {
6485 MCAsmParser &Parser = getParser();
6495 ParseStatus Res = MatchOperandParserImpl(
Operands, Mnemonic,
true);
6506 switch (getLexer().getKind()) {
6516 if (!parseAnyRegister(
Operands).isNoMatch())
6529 Operands.push_back(MipsOperand::CreateImm(SymRef, S,
E, *
this));
6534 const MCExpr *Expr = parseRelocExpr();
6538 Operands.push_back(MipsOperand::CreateImm(Expr, S,
E, *
this));
6545bool MipsAsmParser::parseRegister(MCRegister &
Reg, SMLoc &StartLoc,
6547 return !tryParseRegister(
Reg, StartLoc, EndLoc).isSuccess();
6550ParseStatus MipsAsmParser::tryParseRegister(MCRegister &
Reg, SMLoc &StartLoc,
6553 ParseStatus Res = parseAnyRegister(
Operands);
6556 MipsOperand &Operand =
static_cast<MipsOperand &
>(*
Operands.front());
6557 StartLoc = Operand.getStartLoc();
6558 EndLoc = Operand.getEndLoc();
6564 if (Operand.isGPRAsmReg()) {
6566 Reg = isGP64bit() ? Operand.getGPR64Reg() : Operand.getGPR32Reg();
6576const MCExpr *MipsAsmParser::parseMemOffset() {
6583 if (getParser().parseExpression(
Offset))
6592 SMLoc S = getLexer().getLoc();
6593 const MCExpr *
Offset = parseMemOffset();
6597 SMLoc
E = getLexer().getLoc();
6609 Operands.push_back(MipsOperand::CreateToken(
"(",
E, *
this));
6610 Operands.push_back(MipsOperand::createGPRReg(
6612 Operands.push_back(MipsOperand::CreateToken(
")",
E, *
this));
6617 MCAsmParser &Parser = getParser();
6619 const MCExpr *
Address = parseMemOffset();
6636 std::unique_ptr<MipsOperand>
Base(
6637 static_cast<MipsOperand *
>(
Operands.back().release()));
6639 E =
Base->getEndLoc();
6641 MipsOperand::CreateMem(std::move(
Base),
Address, S,
E, *
this));
6646 MCAsmParser &Parser = getParser();
6655 const MCSymbolRefExpr *
Ref =
static_cast<const MCSymbolRefExpr *
>(Expr);
6656 StringRef DefSymbol =
Ref->getSymbol().getName();
6659 matchAnyRegisterNameWithoutDollar(
Operands, DefSymbol.
substr(1), S);
6673 if (Entry != RegisterSets.
end()) {
6675 matchAnyRegisterWithoutDollar(
Operands,
Entry->getValue(), S);
6686ParseStatus MipsAsmParser::matchAnyRegisterNameWithoutDollar(
6688 int Index = matchCPURegisterName(Identifier);
6690 Operands.push_back(MipsOperand::createGPRReg(
6691 Index, Identifier,
getContext().getRegisterInfo(), S,
6692 getLexer().getLoc(), *
this));
6696 Index = matchHWRegsRegisterName(Identifier);
6698 Operands.push_back(MipsOperand::createHWRegsReg(
6699 Index, Identifier,
getContext().getRegisterInfo(), S,
6700 getLexer().getLoc(), *
this));
6704 const MCRegisterInfo &
MRI = *
getContext().getRegisterInfo();
6706 Identifier,
MRI, Mips::COP0RegClassID, Mips::RegAliasName)) {
6707 Operands.push_back(MipsOperand::createCOP0Reg(
MRI.getEncodingValue(
Reg),
6708 Identifier, &
MRI, S,
6709 getLexer().getLoc(), *
this));
6713 Index = matchFPURegisterName(Identifier);
6715 Operands.push_back(MipsOperand::createFGRReg(
6716 Index, Identifier,
getContext().getRegisterInfo(), S,
6717 getLexer().getLoc(), *
this));
6721 Index = matchFCCRegisterName(Identifier);
6723 Operands.push_back(MipsOperand::createFCCReg(
6724 Index, Identifier,
getContext().getRegisterInfo(), S,
6725 getLexer().getLoc(), *
this));
6729 Index = matchACRegisterName(Identifier);
6731 Operands.push_back(MipsOperand::createACCReg(
6732 Index, Identifier,
getContext().getRegisterInfo(), S,
6733 getLexer().getLoc(), *
this));
6737 Index = matchMSA128RegisterName(Identifier);
6739 Operands.push_back(MipsOperand::createMSA128Reg(
6740 Index, Identifier,
getContext().getRegisterInfo(), S,
6741 getLexer().getLoc(), *
this));
6745 Index = matchMSA128CtrlRegisterName(Identifier);
6747 Operands.push_back(MipsOperand::createMSACtrlReg(
6748 Index, Identifier,
getContext().getRegisterInfo(), S,
6749 getLexer().getLoc(), *
this));
6758 const AsmToken &Token, SMLoc S) {
6762 return matchAnyRegisterNameWithoutDollar(
Operands, Identifier, S);
6767 if (RegNum < 0 || RegNum > 31) {
6771 Error(getLexer().getLoc(),
"invalid register number");
6773 Operands.push_back(MipsOperand::createNumericReg(
6786 auto Token = getLexer().peekTok(
false);
6787 return matchAnyRegisterWithoutDollar(
Operands, Token, S);
6791 SMLoc S = getLexer().getLoc();
6793 ParseStatus Res = parseAnyRegister(RegOperands);
6796 const auto &
Op =
static_cast<const MipsOperand &
>(*RegOperands.
back());
6798 if (
Op.isCOP0AsmReg()) {
6799 Encoding =
Op.getCOP0Encoding();
6801 return Error(getLexer().getLoc(),
6802 "explicit selector is not allowed for named COP0 register");
6803 }
else if (
Op.isNumericReg()) {
6807 SMLoc SelLoc = getLexer().getLoc();
6809 if (getParser().parseExpression(Expr))
6811 if (!Expr->evaluateAsAbsolute(Sel) || !
isUInt<3>(Sel))
6812 return Error(SelLoc,
"expected 3-bit unsigned immediate");
6816 return Error(S,
"invalid operand for instruction");
6819 return Error(S,
"selector must be zero for pre-MIPS32 ISAs");
6821 const MCRegisterInfo &
MRI = *
getContext().getRegisterInfo();
6822 Operands.push_back(MipsOperand::createCOP0Reg(Encoding,
"", &
MRI, S,
6823 getLexer().getLoc(), *
this));
6828 MCAsmParser &Parser = getParser();
6831 auto Token = Parser.
getTok();
6833 SMLoc S = Token.
getLoc();
6846 ParseStatus Res = matchAnyRegisterWithoutDollar(
Operands, S);
6855 MCAsmParser &Parser = getParser();
6858 SMLoc S = getLexer().getLoc();
6861 ParseStatus Res = parseAnyRegister(
Operands);
6866 const MCExpr *Expr =
nullptr;
6872 MipsOperand::CreateImm(Expr, S, getLexer().getLoc(), *
this));
6877 MCAsmParser &Parser = getParser();
6878 const MCExpr *IdVal;
6889 if (getParser().parseExpression(IdVal))
6896 Operands.push_back(MipsOperand::CreateImm(
6902 MCAsmParser &Parser = getParser();
6906 bool RegRange =
false;
6913 while (parseAnyRegister(TmpOperands).isSuccess()) {
6914 SMLoc
E = getLexer().getLoc();
6915 MipsOperand &RegOpnd =
static_cast<MipsOperand &
>(*TmpOperands.
back());
6916 Reg = isGP64bit() ? RegOpnd.getGPR64Reg() : RegOpnd.getGPR32Reg();
6924 MCRegister TmpReg = PrevReg + 1;
6925 while (TmpReg <=
Reg) {
6926 if ((((TmpReg < Mips::R16) || (TmpReg > Mips::R23)) &&
6928 (((TmpReg < Mips::R16_64) || (TmpReg > Mips::R23_64)) &&
6930 return Error(
E,
"invalid register operand");
6934 TmpReg = TmpReg.
id() + 1;
6943 return Error(
E,
"$16 or $31 expected");
6945 (
Reg >= Mips::R16 &&
Reg <= Mips::R23)) &&
6948 (
Reg >= Mips::R16_64 &&
Reg <= Mips::R23_64)) &&
6950 return Error(
E,
"invalid register operand");
6951 if (PrevReg.
isValid() && (
Reg != PrevReg + 1) &&
6954 return Error(
E,
"consecutive register numbers expected");
6964 return Error(
E,
"',' or '-' expected");
6974 Operands.push_back(MipsOperand::CreateRegList(Regs, S,
E, *
this));
6975 return parseMemOffsetOperand(
Operands);
6984 MCAsmParser &Parser = getParser();
6987 MipsOperand::CreateToken(
"(", getLexer().getLoc(), *
this));
6989 if (parseOperand(
Operands, Name)) {
6990 SMLoc Loc = getLexer().getLoc();
6991 return Error(Loc,
"unexpected token in argument list");
6994 SMLoc Loc = getLexer().getLoc();
6995 return Error(Loc,
"unexpected token, expected ')'");
6998 MipsOperand::CreateToken(
")", getLexer().getLoc(), *
this));
7010bool MipsAsmParser::parseBracketSuffix(StringRef Name,
7012 MCAsmParser &Parser = getParser();
7015 MipsOperand::CreateToken(
"[", getLexer().getLoc(), *
this));
7017 if (parseOperand(
Operands, Name)) {
7018 SMLoc Loc = getLexer().getLoc();
7019 return Error(Loc,
"unexpected token in argument list");
7022 SMLoc Loc = getLexer().getLoc();
7023 return Error(Loc,
"unexpected token, expected ']'");
7026 MipsOperand::CreateToken(
"]", getLexer().getLoc(), *
this));
7033 unsigned VariantID = 0);
7048bool MipsAsmParser::parseInstruction(ParseInstructionInfo &Info, StringRef Name,
7050 MCAsmParser &Parser = getParser();
7054 getTargetStreamer().forbidModuleDirective();
7057 if (!mnemonicIsValid(Name, 0)) {
7058 FeatureBitset FBS = ComputeAvailableFeatures(getSTI().getFeatureBits());
7060 return Error(NameLoc,
"unknown instruction" + Suggestion);
7063 Operands.push_back(MipsOperand::CreateToken(Name, NameLoc, *
this));
7068 bool IsFirstOperand =
Operands.size() == 1;
7070 if (parseOperand(
Operands, Name)) {
7071 SMLoc Loc = getLexer().getLoc();
7072 return Error(Loc,
"unexpected token in argument list");
7077 if (parseBracketSuffix(Name,
Operands))
7085 SMLoc Loc = getLexer().getLoc();
7086 return Error(Loc,
"unexpected token in argument list");
7094bool MipsAsmParser::reportParseError(
const Twine &ErrorMsg) {
7095 SMLoc Loc = getLexer().getLoc();
7096 return Error(Loc, ErrorMsg);
7099bool MipsAsmParser::reportParseError(SMLoc Loc,
const Twine &ErrorMsg) {
7100 return Error(Loc, ErrorMsg);
7103bool MipsAsmParser::parseSetNoAtDirective() {
7104 MCAsmParser &Parser = getParser();
7108 AssemblerOptions.
back()->setATRegIndex(0);
7114 reportParseError(
"unexpected token, expected end of statement");
7118 getTargetStreamer().emitDirectiveSetNoAt();
7123bool MipsAsmParser::parseSetAtDirective() {
7126 MCAsmParser &Parser = getParser();
7131 AssemblerOptions.
back()->setATRegIndex(1);
7133 getTargetStreamer().emitDirectiveSetAt();
7139 reportParseError(
"unexpected token, expected equals sign");
7146 reportParseError(
"no register specified");
7149 reportParseError(
"unexpected token, expected dollar sign '$'");
7159 AtRegNo = matchCPURegisterName(
Reg.getIdentifier());
7161 AtRegNo =
Reg.getIntVal();
7163 reportParseError(
"unexpected token, expected identifier or integer");
7168 if (!AssemblerOptions.
back()->setATRegIndex(AtRegNo)) {
7169 reportParseError(
"invalid register");
7176 reportParseError(
"unexpected token, expected end of statement");
7180 getTargetStreamer().emitDirectiveSetAtWithArg(AtRegNo);
7186bool MipsAsmParser::parseSetReorderDirective() {
7187 MCAsmParser &Parser = getParser();
7191 reportParseError(
"unexpected token, expected end of statement");
7194 AssemblerOptions.
back()->setReorder();
7195 getTargetStreamer().emitDirectiveSetReorder();
7200bool MipsAsmParser::parseSetNoReorderDirective() {
7201 MCAsmParser &Parser = getParser();
7205 reportParseError(
"unexpected token, expected end of statement");
7208 AssemblerOptions.
back()->setNoReorder();
7209 getTargetStreamer().emitDirectiveSetNoReorder();
7214bool MipsAsmParser::parseSetMacroDirective() {
7215 MCAsmParser &Parser = getParser();
7219 reportParseError(
"unexpected token, expected end of statement");
7222 AssemblerOptions.
back()->setMacro();
7223 getTargetStreamer().emitDirectiveSetMacro();
7228bool MipsAsmParser::parseSetNoMacroDirective() {
7229 MCAsmParser &Parser = getParser();
7233 reportParseError(
"unexpected token, expected end of statement");
7236 if (AssemblerOptions.
back()->isReorder()) {
7237 reportParseError(
"`noreorder' must be set before `nomacro'");
7240 AssemblerOptions.
back()->setNoMacro();
7241 getTargetStreamer().emitDirectiveSetNoMacro();
7246bool MipsAsmParser::parseSetMsaDirective() {
7247 MCAsmParser &Parser = getParser();
7252 return reportParseError(
"unexpected token, expected end of statement");
7254 setFeatureBits(Mips::FeatureMSA,
"msa");
7255 getTargetStreamer().emitDirectiveSetMsa();
7259bool MipsAsmParser::parseSetNoMsaDirective() {
7260 MCAsmParser &Parser = getParser();
7265 return reportParseError(
"unexpected token, expected end of statement");
7267 clearFeatureBits(Mips::FeatureMSA,
"msa");
7268 getTargetStreamer().emitDirectiveSetNoMsa();
7272bool MipsAsmParser::parseSetNoDspDirective() {
7273 MCAsmParser &Parser = getParser();
7278 reportParseError(
"unexpected token, expected end of statement");
7282 clearFeatureBits(Mips::FeatureDSP,
"dsp");
7283 getTargetStreamer().emitDirectiveSetNoDsp();
7287bool MipsAsmParser::parseSetNoMips3DDirective() {
7288 MCAsmParser &Parser = getParser();
7293 reportParseError(
"unexpected token, expected end of statement");
7297 clearFeatureBits(Mips::FeatureMips3D,
"mips3d");
7298 getTargetStreamer().emitDirectiveSetNoMips3D();
7302bool MipsAsmParser::parseSetMips16Directive() {
7303 MCAsmParser &Parser = getParser();
7308 reportParseError(
"unexpected token, expected end of statement");
7312 clearFeatureBits(Mips::FeatureMicroMips,
"micromips");
7313 setFeatureBits(Mips::FeatureMips16,
"mips16");
7314 getTargetStreamer().emitDirectiveSetMips16();
7319bool MipsAsmParser::parseSetNoMips16Directive() {
7320 MCAsmParser &Parser = getParser();
7325 reportParseError(
"unexpected token, expected end of statement");
7329 clearFeatureBits(Mips::FeatureMips16,
"mips16");
7330 getTargetStreamer().emitDirectiveSetNoMips16();
7335bool MipsAsmParser::parseSetFpDirective() {
7336 MCAsmParser &Parser = getParser();
7342 AsmToken Tok = Parser.
getTok();
7344 reportParseError(
"unexpected token, expected equals sign '='");
7350 if (!parseFpABIValue(FpAbiVal,
".set"))
7354 reportParseError(
"unexpected token, expected end of statement");
7357 getTargetStreamer().emitDirectiveSetFp(FpAbiVal);
7362bool MipsAsmParser::parseSetOddSPRegDirective() {
7363 MCAsmParser &Parser = getParser();
7367 reportParseError(
"unexpected token, expected end of statement");
7371 clearFeatureBits(Mips::FeatureNoOddSPReg,
"nooddspreg");
7372 getTargetStreamer().emitDirectiveSetOddSPReg();
7376bool MipsAsmParser::parseSetNoOddSPRegDirective() {
7377 MCAsmParser &Parser = getParser();
7381 reportParseError(
"unexpected token, expected end of statement");
7385 setFeatureBits(Mips::FeatureNoOddSPReg,
"nooddspreg");
7386 getTargetStreamer().emitDirectiveSetNoOddSPReg();
7390bool MipsAsmParser::parseSetMtDirective() {
7391 MCAsmParser &Parser = getParser();
7396 reportParseError(
"unexpected token, expected end of statement");
7400 setFeatureBits(Mips::FeatureMT,
"mt");
7401 getTargetStreamer().emitDirectiveSetMt();
7406bool MipsAsmParser::parseSetNoMtDirective() {
7407 MCAsmParser &Parser = getParser();
7412 reportParseError(
"unexpected token, expected end of statement");
7416 clearFeatureBits(Mips::FeatureMT,
"mt");
7418 getTargetStreamer().emitDirectiveSetNoMt();
7423bool MipsAsmParser::parseSetNoCRCDirective() {
7424 MCAsmParser &Parser = getParser();
7429 reportParseError(
"unexpected token, expected end of statement");
7433 clearFeatureBits(Mips::FeatureCRC,
"crc");
7435 getTargetStreamer().emitDirectiveSetNoCRC();
7440bool MipsAsmParser::parseSetNoVirtDirective() {
7441 MCAsmParser &Parser = getParser();
7446 reportParseError(
"unexpected token, expected end of statement");
7450 clearFeatureBits(Mips::FeatureVirt,
"virt");
7452 getTargetStreamer().emitDirectiveSetNoVirt();
7457bool MipsAsmParser::parseSetNoGINVDirective() {
7458 MCAsmParser &Parser = getParser();
7463 reportParseError(
"unexpected token, expected end of statement");
7467 clearFeatureBits(Mips::FeatureGINV,
"ginv");
7469 getTargetStreamer().emitDirectiveSetNoGINV();
7474bool MipsAsmParser::parseSetNoEVADirective() {
7475 MCAsmParser &Parser = getParser();
7480 reportParseError(
"unexpected token, expected end of statement");
7484 clearFeatureBits(Mips::FeatureEVA,
"eva");
7486 getTargetStreamer().emitDirectiveSetNoEVA();
7491bool MipsAsmParser::parseSetPopDirective() {
7492 MCAsmParser &Parser = getParser();
7493 SMLoc Loc = getLexer().getLoc();
7497 return reportParseError(
"unexpected token, expected end of statement");
7501 if (AssemblerOptions.
size() == 2)
7502 return reportParseError(Loc,
".set pop with no .set push");
7504 MCSubtargetInfo &STI = copySTI();
7506 setAvailableFeatures(
7507 ComputeAvailableFeatures(AssemblerOptions.
back()->getFeatures()));
7510 getTargetStreamer().emitDirectiveSetPop();
7514bool MipsAsmParser::parseSetPushDirective() {
7515 MCAsmParser &Parser = getParser();
7518 return reportParseError(
"unexpected token, expected end of statement");
7522 std::make_unique<MipsAssemblerOptions>(AssemblerOptions.
back().get()));
7524 getTargetStreamer().emitDirectiveSetPush();
7528bool MipsAsmParser::parseSetSoftFloatDirective() {
7529 MCAsmParser &Parser = getParser();
7532 return reportParseError(
"unexpected token, expected end of statement");
7534 setFeatureBits(Mips::FeatureSoftFloat,
"soft-float");
7535 getTargetStreamer().emitDirectiveSetSoftFloat();
7539bool MipsAsmParser::parseSetHardFloatDirective() {
7540 MCAsmParser &Parser = getParser();
7543 return reportParseError(
"unexpected token, expected end of statement");
7545 clearFeatureBits(Mips::FeatureSoftFloat,
"soft-float");
7546 getTargetStreamer().emitDirectiveSetHardFloat();
7550bool MipsAsmParser::parseSetAssignment() {
7552 MCAsmParser &Parser = getParser();
7555 return reportParseError(
"expected identifier after .set");
7558 return reportParseError(
"unexpected token, expected comma");
7573 const MCExpr *
Value;
7575 Parser, Sym,
Value))
7577 getStreamer().emitAssignment(Sym,
Value);
7582bool MipsAsmParser::parseSetMips0Directive() {
7583 MCAsmParser &Parser = getParser();
7586 return reportParseError(
"unexpected token, expected end of statement");
7589 MCSubtargetInfo &STI = copySTI();
7590 setAvailableFeatures(
7591 ComputeAvailableFeatures(AssemblerOptions.
front()->getFeatures()));
7593 AssemblerOptions.
back()->setFeatures(AssemblerOptions.
front()->getFeatures());
7595 getTargetStreamer().emitDirectiveSetMips0();
7599bool MipsAsmParser::parseSetArchDirective() {
7600 MCAsmParser &Parser = getParser();
7603 return reportParseError(
"unexpected token, expected equals sign");
7606 StringRef Arch = getParser().parseStringToEndOfStatement().trim();
7608 return reportParseError(
"expected arch identifier");
7610 StringRef ArchFeatureName =
7611 StringSwitch<StringRef>(Arch)
7612 .Case(
"mips1",
"mips1")
7613 .Case(
"mips2",
"mips2")
7614 .Case(
"mips3",
"mips3")
7615 .Case(
"mips4",
"mips4")
7616 .Case(
"mips5",
"mips5")
7617 .Case(
"mips32",
"mips32")
7618 .Case(
"mips32r2",
"mips32r2")
7619 .Case(
"mips32r3",
"mips32r3")
7620 .Case(
"mips32r5",
"mips32r5")
7621 .Case(
"mips32r6",
"mips32r6")
7622 .Case(
"mips64",
"mips64")
7623 .Case(
"mips64r2",
"mips64r2")
7624 .Case(
"mips64r3",
"mips64r3")
7625 .Case(
"mips64r5",
"mips64r5")
7626 .Case(
"mips64r6",
"mips64r6")
7627 .Case(
"octeon",
"cnmips")
7628 .Case(
"octeon+",
"cnmipsp")
7629 .Case(
"r4000",
"mips3")
7632 if (ArchFeatureName.
empty())
7633 return reportParseError(
"unsupported architecture");
7635 if (ArchFeatureName ==
"mips64r6" && inMicroMipsMode())
7636 return reportParseError(
"mips64r6 does not support microMIPS");
7638 selectArch(ArchFeatureName);
7639 getTargetStreamer().emitDirectiveSetArch(Arch);
7643bool MipsAsmParser::parseSetFeature(
uint64_t Feature) {
7644 MCAsmParser &Parser = getParser();
7647 return reportParseError(
"unexpected token, expected end of statement");
7652 case Mips::FeatureMips3D:
7653 setFeatureBits(Mips::FeatureMips3D,
"mips3d");
7654 getTargetStreamer().emitDirectiveSetMips3D();
7656 case Mips::FeatureDSP:
7657 setFeatureBits(Mips::FeatureDSP,
"dsp");
7658 getTargetStreamer().emitDirectiveSetDsp();
7660 case Mips::FeatureDSPR2:
7661 setFeatureBits(Mips::FeatureDSPR2,
"dspr2");
7662 getTargetStreamer().emitDirectiveSetDspr2();
7664 case Mips::FeatureMicroMips:
7665 clearFeatureBits(Mips::FeatureMips16,
"mips16");
7666 setFeatureBits(Mips::FeatureMicroMips,
"micromips");
7667 getTargetStreamer().emitDirectiveSetMicroMips();
7669 case Mips::FeatureMips1:
7670 selectArch(
"mips1");
7671 getTargetStreamer().emitDirectiveSetMips1();
7673 case Mips::FeatureMips2:
7674 selectArch(
"mips2");
7675 getTargetStreamer().emitDirectiveSetMips2();
7677 case Mips::FeatureMips3:
7678 selectArch(
"mips3");
7679 getTargetStreamer().emitDirectiveSetMips3();
7681 case Mips::FeatureMips4:
7682 selectArch(
"mips4");
7683 getTargetStreamer().emitDirectiveSetMips4();
7685 case Mips::FeatureMips5:
7686 selectArch(
"mips5");
7687 getTargetStreamer().emitDirectiveSetMips5();
7689 case Mips::FeatureMips32:
7690 selectArch(
"mips32");
7691 getTargetStreamer().emitDirectiveSetMips32();
7693 case Mips::FeatureMips32r2:
7694 selectArch(
"mips32r2");
7695 getTargetStreamer().emitDirectiveSetMips32R2();
7697 case Mips::FeatureMips32r3:
7698 selectArch(
"mips32r3");
7699 getTargetStreamer().emitDirectiveSetMips32R3();
7701 case Mips::FeatureMips32r5:
7702 selectArch(
"mips32r5");
7703 getTargetStreamer().emitDirectiveSetMips32R5();
7705 case Mips::FeatureMips32r6:
7706 selectArch(
"mips32r6");
7707 getTargetStreamer().emitDirectiveSetMips32R6();
7709 case Mips::FeatureMips64:
7710 selectArch(
"mips64");
7711 getTargetStreamer().emitDirectiveSetMips64();
7713 case Mips::FeatureMips64r2:
7714 selectArch(
"mips64r2");
7715 getTargetStreamer().emitDirectiveSetMips64R2();
7717 case Mips::FeatureMips64r3:
7718 selectArch(
"mips64r3");
7719 getTargetStreamer().emitDirectiveSetMips64R3();
7721 case Mips::FeatureMips64r5:
7722 selectArch(
"mips64r5");
7723 getTargetStreamer().emitDirectiveSetMips64R5();
7725 case Mips::FeatureMips64r6:
7726 selectArch(
"mips64r6");
7727 getTargetStreamer().emitDirectiveSetMips64R6();
7729 case Mips::FeatureCRC:
7730 setFeatureBits(Mips::FeatureCRC,
"crc");
7731 getTargetStreamer().emitDirectiveSetCRC();
7733 case Mips::FeatureVirt:
7734 setFeatureBits(Mips::FeatureVirt,
"virt");
7735 getTargetStreamer().emitDirectiveSetVirt();
7737 case Mips::FeatureGINV:
7738 setFeatureBits(Mips::FeatureGINV,
"ginv");
7739 getTargetStreamer().emitDirectiveSetGINV();
7741 case Mips::FeatureEVA:
7742 setFeatureBits(Mips::FeatureEVA,
"eva");
7743 getTargetStreamer().emitDirectiveSetEVA();
7749bool MipsAsmParser::eatComma(StringRef ErrorStr) {
7750 MCAsmParser &Parser = getParser();
7752 SMLoc Loc = getLexer().getLoc();
7753 return Error(Loc, ErrorStr);
7764bool MipsAsmParser::isPicAndNotNxxAbi() {
7765 return inPicMode() && !(isABI_N32() || isABI_N64());
7768bool MipsAsmParser::parseDirectiveCpAdd(SMLoc Loc) {
7770 ParseStatus Res = parseAnyRegister(
Reg);
7772 reportParseError(
"expected register");
7776 MipsOperand &RegOpnd =
static_cast<MipsOperand &
>(*
Reg[0]);
7777 if (!RegOpnd.isGPRAsmReg()) {
7778 reportParseError(RegOpnd.getStartLoc(),
"invalid register");
7784 reportParseError(
"unexpected token, expected end of statement");
7789 getTargetStreamer().emitDirectiveCpAdd(RegOpnd.getGPR32Reg());
7793bool MipsAsmParser::parseDirectiveCpLoad(SMLoc Loc) {
7794 if (AssemblerOptions.
back()->isReorder())
7795 Warning(Loc,
".cpload should be inside a noreorder section");
7797 if (inMips16Mode()) {
7798 reportParseError(
".cpload is not supported in Mips16 mode");
7803 ParseStatus Res = parseAnyRegister(
Reg);
7805 reportParseError(
"expected register containing function address");
7809 MipsOperand &RegOpnd =
static_cast<MipsOperand &
>(*
Reg[0]);
7810 if (!RegOpnd.isGPRAsmReg()) {
7811 reportParseError(RegOpnd.getStartLoc(),
"invalid register");
7817 reportParseError(
"unexpected token, expected end of statement");
7821 getTargetStreamer().emitDirectiveCpLoad(RegOpnd.getGPR32Reg());
7825bool MipsAsmParser::parseDirectiveCpLocal(SMLoc Loc) {
7826 if (!isABI_N32() && !isABI_N64()) {
7827 reportParseError(
".cplocal is allowed only in N32 or N64 mode");
7832 ParseStatus Res = parseAnyRegister(
Reg);
7834 reportParseError(
"expected register containing global pointer");
7838 MipsOperand &RegOpnd =
static_cast<MipsOperand &
>(*
Reg[0]);
7839 if (!RegOpnd.isGPRAsmReg()) {
7840 reportParseError(RegOpnd.getStartLoc(),
"invalid register");
7846 reportParseError(
"unexpected token, expected end of statement");
7851 MCRegister NewReg = RegOpnd.getGPR32Reg();
7855 getTargetStreamer().emitDirectiveCpLocal(NewReg);
7859bool MipsAsmParser::parseDirectiveCpRestore(SMLoc Loc) {
7860 MCAsmParser &Parser = getParser();
7865 if (inMips16Mode()) {
7866 reportParseError(
".cprestore is not supported in Mips16 mode");
7871 const MCExpr *StackOffset;
7872 int64_t StackOffsetVal;
7874 reportParseError(
"expected stack offset value");
7878 if (!StackOffset->evaluateAsAbsolute(StackOffsetVal)) {
7879 reportParseError(
"stack offset is not an absolute expression");
7883 if (StackOffsetVal < 0) {
7884 Warning(Loc,
".cprestore with negative stack offset has no effect");
7885 IsCpRestoreSet =
false;
7887 IsCpRestoreSet =
true;
7888 CpRestoreOffset = StackOffsetVal;
7893 reportParseError(
"unexpected token, expected end of statement");
7897 if (!getTargetStreamer().emitDirectiveCpRestore(
7898 CpRestoreOffset, [&]() {
return getATReg(Loc); }, Loc, STI))
7904bool MipsAsmParser::parseDirectiveCPSetup() {
7905 MCAsmParser &Parser = getParser();
7907 bool SaveIsReg =
true;
7910 ParseStatus Res = parseAnyRegister(TmpReg);
7912 reportParseError(
"expected register containing function address");
7916 MipsOperand &FuncRegOpnd =
static_cast<MipsOperand &
>(*TmpReg[0]);
7917 if (!FuncRegOpnd.isGPRAsmReg()) {
7918 reportParseError(FuncRegOpnd.getStartLoc(),
"invalid register");
7922 MCRegister FuncReg = FuncRegOpnd.getGPR32Reg();
7925 if (!eatComma(
"unexpected token, expected comma"))
7928 Res = parseAnyRegister(TmpReg);
7930 const MCExpr *OffsetExpr;
7932 SMLoc ExprLoc = getLexer().
getLoc();
7935 !OffsetExpr->evaluateAsAbsolute(OffsetVal)) {
7936 reportParseError(ExprLoc,
"expected save register or stack offset");
7943 MipsOperand &SaveOpnd =
static_cast<MipsOperand &
>(*TmpReg[0]);
7944 if (!SaveOpnd.isGPRAsmReg()) {
7945 reportParseError(SaveOpnd.getStartLoc(),
"invalid register");
7948 Save = SaveOpnd.getGPR32Reg().id();
7951 if (!eatComma(
"unexpected token, expected comma"))
7956 reportParseError(
"expected expression");
7961 reportParseError(
"expected symbol");
7964 const MCSymbolRefExpr *
Ref =
static_cast<const MCSymbolRefExpr *
>(Expr);
7966 CpSaveLocation = Save;
7967 CpSaveLocationIsRegister = SaveIsReg;
7969 getTargetStreamer().emitDirectiveCpsetup(FuncReg, Save,
Ref->getSymbol(),
7974bool MipsAsmParser::parseDirectiveCPReturn() {
7975 getTargetStreamer().emitDirectiveCpreturn(CpSaveLocation,
7976 CpSaveLocationIsRegister);
7980bool MipsAsmParser::parseDirectiveNaN() {
7981 MCAsmParser &Parser = getParser();
7983 const AsmToken &Tok = Parser.
getTok();
7987 getTargetStreamer().emitDirectiveNaN2008();
7989 }
else if (Tok.
getString() ==
"legacy") {
7991 getTargetStreamer().emitDirectiveNaNLegacy();
7997 reportParseError(
"invalid option in .nan directive");
8001bool MipsAsmParser::parseDirectiveSet() {
8002 const AsmToken &Tok = getParser().getTok();
8004 SMLoc Loc = Tok.
getLoc();
8006 if (IdVal ==
"noat")
8007 return parseSetNoAtDirective();
8009 return parseSetAtDirective();
8010 if (IdVal ==
"arch")
8011 return parseSetArchDirective();
8012 if (IdVal ==
"bopt") {
8013 Warning(Loc,
"'bopt' feature is unsupported");
8017 if (IdVal ==
"nobopt") {
8023 return parseSetFpDirective();
8024 if (IdVal ==
"oddspreg")
8025 return parseSetOddSPRegDirective();
8026 if (IdVal ==
"nooddspreg")
8027 return parseSetNoOddSPRegDirective();
8029 return parseSetPopDirective();
8030 if (IdVal ==
"push")
8031 return parseSetPushDirective();
8032 if (IdVal ==
"reorder")
8033 return parseSetReorderDirective();
8034 if (IdVal ==
"noreorder")
8035 return parseSetNoReorderDirective();
8036 if (IdVal ==
"macro")
8037 return parseSetMacroDirective();
8038 if (IdVal ==
"nomacro")
8039 return parseSetNoMacroDirective();
8040 if (IdVal ==
"mips16")
8041 return parseSetMips16Directive();
8042 if (IdVal ==
"nomips16")
8043 return parseSetNoMips16Directive();
8044 if (IdVal ==
"nomicromips") {
8045 clearFeatureBits(Mips::FeatureMicroMips,
"micromips");
8046 getTargetStreamer().emitDirectiveSetNoMicroMips();
8047 getParser().eatToEndOfStatement();
8050 if (IdVal ==
"micromips") {
8051 if (hasMips64r6()) {
8052 Error(Loc,
".set micromips directive is not supported with MIPS64R6");
8055 return parseSetFeature(Mips::FeatureMicroMips);
8057 if (IdVal ==
"mips0")
8058 return parseSetMips0Directive();
8059 if (IdVal ==
"mips1")
8060 return parseSetFeature(Mips::FeatureMips1);
8061 if (IdVal ==
"mips2")
8062 return parseSetFeature(Mips::FeatureMips2);
8063 if (IdVal ==
"mips3")
8064 return parseSetFeature(Mips::FeatureMips3);
8065 if (IdVal ==
"mips4")
8066 return parseSetFeature(Mips::FeatureMips4);
8067 if (IdVal ==
"mips5")
8068 return parseSetFeature(Mips::FeatureMips5);
8069 if (IdVal ==
"mips32")
8070 return parseSetFeature(Mips::FeatureMips32);
8071 if (IdVal ==
"mips32r2")
8072 return parseSetFeature(Mips::FeatureMips32r2);
8073 if (IdVal ==
"mips32r3")
8074 return parseSetFeature(Mips::FeatureMips32r3);
8075 if (IdVal ==
"mips32r5")
8076 return parseSetFeature(Mips::FeatureMips32r5);
8077 if (IdVal ==
"mips32r6")
8078 return parseSetFeature(Mips::FeatureMips32r6);
8079 if (IdVal ==
"mips64")
8080 return parseSetFeature(Mips::FeatureMips64);
8081 if (IdVal ==
"mips64r2")
8082 return parseSetFeature(Mips::FeatureMips64r2);
8083 if (IdVal ==
"mips64r3")
8084 return parseSetFeature(Mips::FeatureMips64r3);
8085 if (IdVal ==
"mips64r5")
8086 return parseSetFeature(Mips::FeatureMips64r5);
8087 if (IdVal ==
"mips64r6") {
8088 if (inMicroMipsMode()) {
8089 Error(Loc,
"MIPS64R6 is not supported with microMIPS");
8092 return parseSetFeature(Mips::FeatureMips64r6);
8095 return parseSetFeature(Mips::FeatureDSP);
8096 if (IdVal ==
"dspr2")
8097 return parseSetFeature(Mips::FeatureDSPR2);
8098 if (IdVal ==
"nodsp")
8099 return parseSetNoDspDirective();
8100 if (IdVal ==
"mips3d")
8101 return parseSetFeature(Mips::FeatureMips3D);
8102 if (IdVal ==
"nomips3d")
8103 return parseSetNoMips3DDirective();
8105 return parseSetMsaDirective();
8106 if (IdVal ==
"nomsa")
8107 return parseSetNoMsaDirective();
8109 return parseSetMtDirective();
8110 if (IdVal ==
"nomt")
8111 return parseSetNoMtDirective();
8112 if (IdVal ==
"softfloat")
8113 return parseSetSoftFloatDirective();
8114 if (IdVal ==
"hardfloat")
8115 return parseSetHardFloatDirective();
8117 return parseSetFeature(Mips::FeatureCRC);
8118 if (IdVal ==
"nocrc")
8119 return parseSetNoCRCDirective();
8120 if (IdVal ==
"virt")
8121 return parseSetFeature(Mips::FeatureVirt);
8122 if (IdVal ==
"novirt")
8123 return parseSetNoVirtDirective();
8124 if (IdVal ==
"ginv")
8125 return parseSetFeature(Mips::FeatureGINV);
8126 if (IdVal ==
"noginv")
8127 return parseSetNoGINVDirective();
8129 return parseSetFeature(Mips::FeatureEVA);
8130 if (IdVal ==
"noeva")
8131 return parseSetNoEVADirective();
8134 return parseSetAssignment();
8139bool MipsAsmParser::parseDirectiveGpWord() {
8140 const MCExpr *
Value;
8141 if (getParser().parseExpression(
Value))
8143 getTargetStreamer().emitGPRel32Value(
Value);
8149bool MipsAsmParser::parseDirectiveGpDWord() {
8150 const MCExpr *
Value;
8151 if (getParser().parseExpression(
Value))
8153 getTargetStreamer().emitGPRel64Value(
Value);
8159bool MipsAsmParser::parseDirectiveDtpRelWord() {
8160 const MCExpr *
Value;
8161 if (getParser().parseExpression(
Value))
8163 getTargetStreamer().emitDTPRel32Value(
Value);
8169bool MipsAsmParser::parseDirectiveDtpRelDWord() {
8170 const MCExpr *
Value;
8171 if (getParser().parseExpression(
Value))
8173 getTargetStreamer().emitDTPRel64Value(
Value);
8179bool MipsAsmParser::parseDirectiveTpRelWord() {
8180 const MCExpr *
Value;
8181 if (getParser().parseExpression(
Value))
8183 getTargetStreamer().emitTPRel32Value(
Value);
8189bool MipsAsmParser::parseDirectiveTpRelDWord() {
8190 const MCExpr *
Value;
8191 if (getParser().parseExpression(
Value))
8193 getTargetStreamer().emitTPRel64Value(
Value);
8197bool MipsAsmParser::parseDirectiveOption() {
8198 MCAsmParser &Parser = getParser();
8200 AsmToken Tok = Parser.
getTok();
8204 "unexpected token, expected identifier");
8209 if (Option ==
"pic0") {
8211 IsPicEnabled =
false;
8213 getTargetStreamer().emitDirectiveOptionPic0();
8217 "unexpected token, expected end of statement");
8222 if (Option ==
"pic2") {
8224 IsPicEnabled =
true;
8226 getTargetStreamer().emitDirectiveOptionPic2();
8230 "unexpected token, expected end of statement");
8237 "unknown option, expected 'pic0' or 'pic2'");
8244bool MipsAsmParser::parseInsnDirective() {
8247 reportParseError(
"unexpected token, expected end of statement");
8253 getTargetStreamer().emitDirectiveInsn();
8261bool MipsAsmParser::parseRSectionDirective(StringRef Section) {
8264 reportParseError(
"unexpected token, expected end of statement");
8268 MCSection *ELFSection =
getContext().getELFSection(
8270 getParser().getStreamer().switchSection(ELFSection);
8279bool MipsAsmParser::parseSSectionDirective(StringRef Section,
unsigned Type) {
8282 reportParseError(
"unexpected token, expected end of statement");
8286 MCSection *ELFSection =
getContext().getELFSection(
8288 getParser().getStreamer().switchSection(ELFSection);
8307bool MipsAsmParser::parseDirectiveModule() {
8308 MCAsmParser &Parser = getParser();
8309 AsmLexer &Lexer = getLexer();
8312 if (!getTargetStreamer().isModuleDirectiveAllowed()) {
8314 reportParseError(
".module directive must appear before any code");
8320 reportParseError(
"expected .module option identifier");
8324 if (Option ==
"oddspreg") {
8325 clearModuleFeatureBits(Mips::FeatureNoOddSPReg,
"nooddspreg");
8329 getTargetStreamer().updateABIInfo(*
this);
8334 getTargetStreamer().emitDirectiveModuleOddSPReg();
8338 reportParseError(
"unexpected token, expected end of statement");
8343 }
else if (Option ==
"nooddspreg") {
8345 return Error(L,
"'.module nooddspreg' requires the O32 ABI");
8348 setModuleFeatureBits(Mips::FeatureNoOddSPReg,
"nooddspreg");
8352 getTargetStreamer().updateABIInfo(*
this);
8357 getTargetStreamer().emitDirectiveModuleOddSPReg();
8361 reportParseError(
"unexpected token, expected end of statement");
8366 }
else if (Option ==
"fp") {
8367 return parseDirectiveModuleFP();
8368 }
else if (Option ==
"softfloat") {
8369 setModuleFeatureBits(Mips::FeatureSoftFloat,
"soft-float");
8373 getTargetStreamer().updateABIInfo(*
this);
8378 getTargetStreamer().emitDirectiveModuleSoftFloat();
8382 reportParseError(
"unexpected token, expected end of statement");
8387 }
else if (Option ==
"hardfloat") {
8388 clearModuleFeatureBits(Mips::FeatureSoftFloat,
"soft-float");
8392 getTargetStreamer().updateABIInfo(*
this);
8397 getTargetStreamer().emitDirectiveModuleHardFloat();
8401 reportParseError(
"unexpected token, expected end of statement");
8406 }
else if (Option ==
"mt") {
8407 setModuleFeatureBits(Mips::FeatureMT,
"mt");
8411 getTargetStreamer().updateABIInfo(*
this);
8416 getTargetStreamer().emitDirectiveModuleMT();
8420 reportParseError(
"unexpected token, expected end of statement");
8425 }
else if (Option ==
"crc") {
8426 setModuleFeatureBits(Mips::FeatureCRC,
"crc");
8430 getTargetStreamer().updateABIInfo(*
this);
8435 getTargetStreamer().emitDirectiveModuleCRC();
8439 reportParseError(
"unexpected token, expected end of statement");
8444 }
else if (Option ==
"nocrc") {
8445 clearModuleFeatureBits(Mips::FeatureCRC,
"crc");
8449 getTargetStreamer().updateABIInfo(*
this);
8454 getTargetStreamer().emitDirectiveModuleNoCRC();
8458 reportParseError(
"unexpected token, expected end of statement");
8463 }
else if (Option ==
"virt") {
8464 setModuleFeatureBits(Mips::FeatureVirt,
"virt");
8468 getTargetStreamer().updateABIInfo(*
this);
8473 getTargetStreamer().emitDirectiveModuleVirt();
8477 reportParseError(
"unexpected token, expected end of statement");
8482 }
else if (Option ==
"novirt") {
8483 clearModuleFeatureBits(Mips::FeatureVirt,
"virt");
8487 getTargetStreamer().updateABIInfo(*
this);
8492 getTargetStreamer().emitDirectiveModuleNoVirt();
8496 reportParseError(
"unexpected token, expected end of statement");
8501 }
else if (Option ==
"ginv") {
8502 setModuleFeatureBits(Mips::FeatureGINV,
"ginv");
8506 getTargetStreamer().updateABIInfo(*
this);
8511 getTargetStreamer().emitDirectiveModuleGINV();
8515 reportParseError(
"unexpected token, expected end of statement");
8520 }
else if (Option ==
"noginv") {
8521 clearModuleFeatureBits(Mips::FeatureGINV,
"ginv");
8525 getTargetStreamer().updateABIInfo(*
this);
8530 getTargetStreamer().emitDirectiveModuleNoGINV();
8534 reportParseError(
"unexpected token, expected end of statement");
8540 return Error(L,
"'" + Twine(Option) +
"' is not a valid .module option.");
8548bool MipsAsmParser::parseDirectiveModuleFP() {
8549 MCAsmParser &Parser = getParser();
8550 AsmLexer &Lexer = getLexer();
8553 reportParseError(
"unexpected token, expected equals sign '='");
8559 if (!parseFpABIValue(FpABI,
".module"))
8563 reportParseError(
"unexpected token, expected end of statement");
8569 getTargetStreamer().updateABIInfo(*
this);
8574 getTargetStreamer().emitDirectiveModuleFP();
8581 StringRef Directive) {
8582 MCAsmParser &Parser = getParser();
8583 AsmLexer &Lexer = getLexer();
8584 bool ModuleLevelOptions = Directive ==
".module";
8590 if (
Value !=
"xx") {
8591 reportParseError(
"unsupported value, expected 'xx', '32' or '64'");
8596 reportParseError(
"'" + Directive +
" fp=xx' requires the O32 ABI");
8600 FpABI = MipsABIFlagsSection::FpABIKind::XX;
8601 if (ModuleLevelOptions) {
8602 setModuleFeatureBits(Mips::FeatureFPXX,
"fpxx");
8603 clearModuleFeatureBits(Mips::FeatureFP64Bit,
"fp64");
8605 setFeatureBits(Mips::FeatureFPXX,
"fpxx");
8606 clearFeatureBits(Mips::FeatureFP64Bit,
"fp64");
8616 reportParseError(
"unsupported value, expected 'xx', '32' or '64'");
8622 reportParseError(
"'" + Directive +
" fp=32' requires the O32 ABI");
8626 FpABI = MipsABIFlagsSection::FpABIKind::S32;
8627 if (ModuleLevelOptions) {
8628 clearModuleFeatureBits(Mips::FeatureFPXX,
"fpxx");
8629 clearModuleFeatureBits(Mips::FeatureFP64Bit,
"fp64");
8631 clearFeatureBits(Mips::FeatureFPXX,
"fpxx");
8632 clearFeatureBits(Mips::FeatureFP64Bit,
"fp64");
8635 FpABI = MipsABIFlagsSection::FpABIKind::S64;
8636 if (ModuleLevelOptions) {
8637 clearModuleFeatureBits(Mips::FeatureFPXX,
"fpxx");
8638 setModuleFeatureBits(Mips::FeatureFP64Bit,
"fp64");
8640 clearFeatureBits(Mips::FeatureFPXX,
"fpxx");
8641 setFeatureBits(Mips::FeatureFP64Bit,
"fp64");
8651bool MipsAsmParser::ParseDirective(AsmToken DirectiveID) {
8657 MCAsmParser &Parser = getParser();
8658 StringRef IDVal = DirectiveID.
getString();
8660 if (IDVal ==
".cpadd") {
8661 parseDirectiveCpAdd(DirectiveID.
getLoc());
8664 if (IDVal ==
".cpload") {
8665 parseDirectiveCpLoad(DirectiveID.
getLoc());
8668 if (IDVal ==
".cprestore") {
8669 parseDirectiveCpRestore(DirectiveID.
getLoc());
8672 if (IDVal ==
".cplocal") {
8673 parseDirectiveCpLocal(DirectiveID.
getLoc());
8676 if (IDVal ==
".ent") {
8680 reportParseError(
"expected identifier after .ent");
8694 reportParseError(
"unexpected token, expected end of statement");
8698 const MCExpr *DummyNumber;
8699 int64_t DummyNumberVal;
8703 reportParseError(
"expected number after comma");
8706 if (!DummyNumber->evaluateAsAbsolute(DummyNumberVal)) {
8707 reportParseError(
"expected an absolute expression after comma");
8714 reportParseError(
"unexpected token, expected end of statement");
8720 getTargetStreamer().emitDirectiveEnt(*Sym);
8722 IsCpRestoreSet =
false;
8726 if (IDVal ==
".end") {
8730 reportParseError(
"expected identifier after .end");
8735 reportParseError(
"unexpected token, expected end of statement");
8739 if (CurrentFn ==
nullptr) {
8740 reportParseError(
".end used without .ent");
8744 if ((SymbolName != CurrentFn->
getName())) {
8745 reportParseError(
".end symbol does not match .ent symbol");
8749 getTargetStreamer().emitDirectiveEnd(SymbolName);
8750 CurrentFn =
nullptr;
8751 IsCpRestoreSet =
false;
8755 if (IDVal ==
".frame") {
8758 ParseStatus Res = parseAnyRegister(TmpReg);
8760 reportParseError(
"expected stack register");
8764 MipsOperand &StackRegOpnd =
static_cast<MipsOperand &
>(*TmpReg[0]);
8765 if (!StackRegOpnd.isGPRAsmReg()) {
8766 reportParseError(StackRegOpnd.getStartLoc(),
8767 "expected general purpose register");
8770 MCRegister StackReg = StackRegOpnd.getGPR32Reg();
8775 reportParseError(
"unexpected token, expected comma");
8780 const MCExpr *FrameSize;
8781 int64_t FrameSizeVal;
8784 reportParseError(
"expected frame size value");
8788 if (!FrameSize->evaluateAsAbsolute(FrameSizeVal)) {
8789 reportParseError(
"frame size not an absolute expression");
8796 reportParseError(
"unexpected token, expected comma");
8802 Res = parseAnyRegister(TmpReg);
8804 reportParseError(
"expected return register");
8808 MipsOperand &ReturnRegOpnd =
static_cast<MipsOperand &
>(*TmpReg[0]);
8809 if (!ReturnRegOpnd.isGPRAsmReg()) {
8810 reportParseError(ReturnRegOpnd.getStartLoc(),
8811 "expected general purpose register");
8817 reportParseError(
"unexpected token, expected end of statement");
8821 getTargetStreamer().emitFrame(StackReg, FrameSizeVal,
8822 ReturnRegOpnd.getGPR32Reg());
8823 IsCpRestoreSet =
false;
8827 if (IDVal ==
".set") {
8828 parseDirectiveSet();
8832 if (IDVal ==
".mask" || IDVal ==
".fmask") {
8843 const MCExpr *BitMask;
8847 reportParseError(
"expected bitmask value");
8851 if (!BitMask->evaluateAsAbsolute(BitMaskVal)) {
8852 reportParseError(
"bitmask not an absolute expression");
8859 reportParseError(
"unexpected token, expected comma");
8864 const MCExpr *FrameOffset;
8865 int64_t FrameOffsetVal;
8868 reportParseError(
"expected frame offset value");
8872 if (!FrameOffset->evaluateAsAbsolute(FrameOffsetVal)) {
8873 reportParseError(
"frame offset not an absolute expression");
8879 reportParseError(
"unexpected token, expected end of statement");
8883 if (IDVal ==
".mask")
8884 getTargetStreamer().emitMask(BitMaskVal, FrameOffsetVal);
8886 getTargetStreamer().emitFMask(BitMaskVal, FrameOffsetVal);
8890 if (IDVal ==
".nan")
8891 return parseDirectiveNaN();
8893 if (IDVal ==
".gpword") {
8894 parseDirectiveGpWord();
8898 if (IDVal ==
".gpdword") {
8899 parseDirectiveGpDWord();
8903 if (IDVal ==
".dtprelword") {
8904 parseDirectiveDtpRelWord();
8908 if (IDVal ==
".dtpreldword") {
8909 parseDirectiveDtpRelDWord();
8913 if (IDVal ==
".tprelword") {
8914 parseDirectiveTpRelWord();
8918 if (IDVal ==
".tpreldword") {
8919 parseDirectiveTpRelDWord();
8923 if (IDVal ==
".option") {
8924 parseDirectiveOption();
8928 if (IDVal ==
".abicalls") {
8929 getTargetStreamer().emitDirectiveAbiCalls();
8932 "unexpected token, expected end of statement");
8937 if (IDVal ==
".cpsetup") {
8938 parseDirectiveCPSetup();
8941 if (IDVal ==
".cpreturn") {
8942 parseDirectiveCPReturn();
8945 if (IDVal ==
".module") {
8946 parseDirectiveModule();
8949 if (IDVal ==
".llvm_internal_mips_reallow_module_directive") {
8950 parseInternalDirectiveReallowModule();
8953 if (IDVal ==
".insn") {
8954 parseInsnDirective();
8957 if (IDVal ==
".rdata") {
8958 parseRSectionDirective(
".rodata");
8961 if (IDVal ==
".sbss") {
8965 if (IDVal ==
".sdata") {
8973bool MipsAsmParser::parseInternalDirectiveReallowModule() {
8976 reportParseError(
"unexpected token, expected end of statement");
8980 getTargetStreamer().reallowModuleDirective();
8994#define GET_REGISTER_MATCHER
8995#define GET_MATCHER_IMPLEMENTATION
8996#define GET_MNEMONIC_SPELL_CHECKER
8997#include "MipsGenAsmMatcher.inc"
8999bool MipsAsmParser::mnemonicIsValid(
StringRef Mnemonic,
unsigned VariantID) {
9001 const MatchEntry *Start, *
End;
9002 switch (VariantID) {
9004 case 0: Start = std::begin(MatchTable0);
End = std::end(MatchTable0);
break;
9007 auto MnemonicRange = std::equal_range(Start,
End, Mnemonic, LessOpcode());
9008 return MnemonicRange.first != MnemonicRange.second;
static const TargetRegisterClass * getRegClass(const MachineInstr &MI, Register Reg)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static bool isNot(const MachineRegisterInfo &MRI, const MachineInstr &MI)
This file declares a class to represent arbitrary precision floating point values and provide a varie...
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_EXTERNAL_VISIBILITY
static Value * expandAbs(CallInst *Orig)
std::pair< Instruction::BinaryOps, Value * > OffsetOp
Find all possible pairs (BinOp, RHS) that BinOp V, RHS can be simplified.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
static FeatureBitset getFeatures(MCSubtargetInfo &STI, StringRef CPU, StringRef TuneCPU, StringRef FS, StringTable ProcNames, ArrayRef< SubtargetSubTypeKV > ProcDesc, ArrayRef< SubtargetFeatureKV > ProcFeatures)
static bool hasFeature(StringRef Feature, const FeatureBitset &FeatureBits, ArrayRef< SubtargetFeatureKV > ProcFeatures)
static unsigned countMCSymbolRefExpr(const MCExpr *Expr)
static std::string MipsMnemonicSpellCheck(StringRef S, const FeatureBitset &FBS, unsigned VariantID=0)
static uint64_t convertIntToDoubleImm(uint64_t ImmOp64)
static uint32_t covertDoubleImmToSingleImm(uint64_t ImmOp64)
static unsigned getRegisterForMxtrDSP(MCInst &Inst, bool IsMFDSP)
static bool hasShortDelaySlot(MCInst &Inst)
LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeMipsAsmParser()
static bool needsExpandMemInst(MCInst &Inst, const MCInstrDesc &MCID)
static bool isShiftedUIntAtAnyPosition(uint64_t x)
Can the value be represented by a unsigned N-bit value and a shift left?
static bool isEvaluated(const MCExpr *Expr)
static const MCSymbol * getSingleMCSymbol(const MCExpr *Expr)
static MCRegister nextReg(MCRegister Reg)
static unsigned getRegisterForMxtrFP(MCInst &Inst, bool IsMFTC1)
static SMLoc RefineErrorLoc(const SMLoc Loc, const OperandVector &Operands, uint64_t ErrorInfo)
static MCRegister getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
static bool isReg(const MCInst &MI, unsigned OpNo)
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
MachineRegisterInfo & MRI
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
This file defines the SmallVector class.
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
static bool isMemOperand(const MCInst &MI, unsigned Op, unsigned RegClassID)
static constexpr const fltSemantics & IEEEdouble()
APInt bitcastToAPInt() const
uint64_t getZExtValue() const
Get zero extended value.
SMLoc getLoc() const
Get the current source location.
const AsmToken peekTok(bool ShouldSkipSpace=true)
Look ahead at the next token to be lexed.
bool is(AsmToken::TokenKind K) const
Check if the current token has kind K.
bool isNot(AsmToken::TokenKind K) const
Check if the current token has kind K.
Target independent representation for an assembler token.
LLVM_ABI SMLoc getLoc() const
int64_t getIntVal() const
bool isNot(TokenKind K) const
StringRef getString() const
Get the string for the current token, this includes all characters (for example, the quotes on string...
bool is(TokenKind K) const
TokenKind getKind() const
LLVM_ABI SMRange getLocRange() const
StringRef getIdentifier() const
Get the identifier string for the current token, which should be an identifier or a string.
Base class for user error types.
Container class for subtarget features.
void printExpr(raw_ostream &, const MCExpr &) const
virtual void Initialize(MCAsmParser &Parser)
Initialize the extension for parsing using the given Parser.
virtual void eatToEndOfStatement()=0
Skip to the end of the current statement, for error recovery.
bool parseToken(AsmToken::TokenKind T, const Twine &Msg="unexpected token")
virtual bool parseExpression(const MCExpr *&Res, SMLoc &EndLoc)=0
Parse an arbitrary expression.
const AsmToken & getTok() const
Get the current AsmToken from the stream.
virtual bool parseIdentifier(StringRef &Res)=0
Parse an identifier or string (as a quoted identifier) and set Res to the identifier contents.
virtual const AsmToken & Lex()=0
Get the next AsmToken in the stream, possibly handling file inclusion first.
virtual void addAliasForDirective(StringRef Directive, StringRef Alias)=0
Binary assembler expressions.
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Base class for the full range of assembler expressions which are needed for parsing.
LLVM_ABI bool evaluateAsRelocatable(MCValue &Res, const MCAssembler *Asm) const
Try to evaluate the expression to a relocatable value, i.e.
@ Unary
Unary expressions.
@ Constant
Constant expressions.
@ SymbolRef
References to labels and assigned expressions.
@ Target
Target specific expression.
@ Specifier
Expression with a relocation specifier.
@ Binary
Binary expressions.
Instances of this class represent a single low-level machine instruction.
unsigned getNumOperands() const
unsigned getOpcode() const
void addOperand(const MCOperand Op)
void setOpcode(unsigned Op)
const MCOperand & getOperand(unsigned i) const
Describe properties that are true of each instruction in the target description file.
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
ArrayRef< MCOperandInfo > operands() const
bool mayStore() const
Return true if this instruction could possibly modify memory.
bool mayLoad() const
Return true if this instruction could possibly read memory.
bool isBranch() const
Returns true if this is a conditional, unconditional, or indirect branch.
bool isCall() const
Return true if the instruction is a call.
bool hasDelaySlot() const
Returns true if the specified instruction has a delay slot which must be filled by the code generator...
Interface to description of machine instruction set.
This holds information about one operand of a machine instruction, indicating the register class for ...
uint8_t OperandType
Information about the type of the operand.
Instances of this class represent operands of the MCInst class.
static MCOperand createExpr(const MCExpr *Val)
static MCOperand createReg(MCRegister Reg)
static MCOperand createImm(int64_t Val)
MCRegister getReg() const
Returns the register number.
const MCExpr * getExpr() const
MCParsedAsmOperand - This abstract class represents a source-level assembly instruction operand.
virtual bool isReg() const =0
isReg - Is this a register operand?
virtual MCRegister getReg() const =0
MCRegister getRegister(unsigned i) const
getRegister - Return the specified register in the class.
Wrapper class representing physical registers. Should be passed by value.
constexpr bool isValid() const
constexpr unsigned id() const
static const MCSpecifierExpr * create(const MCExpr *Expr, Spec S, MCContext &Ctx, SMLoc Loc=SMLoc())
Streaming machine code generation interface.
virtual void emitRelocDirective(const MCExpr &Offset, StringRef Name, const MCExpr *Expr, SMLoc Loc={})
Record a relocation described by the .reloc directive.
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
Generic base class for all target subtargets.
bool hasFeature(unsigned Feature) const
void setFeatureBits(const FeatureBitset &FeatureBits_)
const Triple & getTargetTriple() const
const FeatureBitset & getFeatureBits() const
const FeatureBitset & ToggleFeature(uint64_t FB)
Toggle a feature and return the re-computed feature bits.
virtual unsigned getHwMode(enum HwModeType type=HwMode_Default) const
HwMode ID corresponding to the 'type' parameter is retrieved from the HwMode bit set of the current s...
Represent a reference to a symbol from inside an expression.
uint16_t getSpecifier() const
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
bool isInSection() const
isInSection - Check if this symbol is defined in some section (i.e., it is defined but not absolute).
bool isUndefined() const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
StringRef getName() const
getName - Get the symbol name.
bool isVariable() const
isVariable - Check if this is a variable symbol.
const MCExpr * getVariableValue() const
Get the expression of the variable symbol.
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
MCTargetAsmParser - Generic interface to target specific assembly parsers.
MCStreamer & getStreamer()
Unary assembler expressions.
const MCSymbol * getAddSym() const
int64_t getConstant() const
const MCSymbol * getSubSym() const
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
static const char * getRegisterName(MCRegister Reg, unsigned AltIdx=Mips::NoRegAltName)
void emitRRX(unsigned Opcode, MCRegister Reg0, MCRegister Reg1, MCOperand Op2, SMLoc IDLoc, const MCSubtargetInfo *STI)
virtual void emitDirectiveSetReorder()
void emitRRRX(unsigned Opcode, MCRegister Reg0, MCRegister Reg1, MCRegister Reg2, MCOperand Op3, SMLoc IDLoc, const MCSubtargetInfo *STI)
void emitRX(unsigned Opcode, MCRegister Reg0, MCOperand Op1, SMLoc IDLoc, const MCSubtargetInfo *STI)
void emitR(unsigned Opcode, MCRegister Reg0, SMLoc IDLoc, const MCSubtargetInfo *STI)
virtual void setUsesMicroMips()
void emitRRI(unsigned Opcode, MCRegister Reg0, MCRegister Reg1, int16_t Imm, SMLoc IDLoc, const MCSubtargetInfo *STI)
void emitEmptyDelaySlot(bool hasShortDelaySlot, SMLoc IDLoc, const MCSubtargetInfo *STI)
void emitRI(unsigned Opcode, MCRegister Reg0, int32_t Imm, SMLoc IDLoc, const MCSubtargetInfo *STI)
void emitII(unsigned Opcode, int16_t Imm1, int16_t Imm2, SMLoc IDLoc, const MCSubtargetInfo *STI)
void emitRR(unsigned Opcode, MCRegister Reg0, MCRegister Reg1, SMLoc IDLoc, const MCSubtargetInfo *STI)
void updateABIInfo(const PredicateLibrary &P)
void emitRRIII(unsigned Opcode, MCRegister Reg0, MCRegister Reg1, int16_t Imm0, int16_t Imm1, int16_t Imm2, SMLoc IDLoc, const MCSubtargetInfo *STI)
void emitDSLL(MCRegister DstReg, MCRegister SrcReg, int16_t ShiftAmount, SMLoc IDLoc, const MCSubtargetInfo *STI)
void emitGPRestore(int Offset, SMLoc IDLoc, const MCSubtargetInfo *STI)
Emit the $gp restore operation for .cprestore.
void emitNop(SMLoc IDLoc, const MCSubtargetInfo *STI)
void emitRRR(unsigned Opcode, MCRegister Reg0, MCRegister Reg1, MCRegister Reg2, SMLoc IDLoc, const MCSubtargetInfo *STI)
virtual void emitDirectiveSetNoReorder()
Ternary parse status returned by various parse* methods.
constexpr bool isFailure() const
static constexpr StatusTy Failure
constexpr bool isSuccess() const
static constexpr StatusTy Success
static constexpr StatusTy NoMatch
constexpr bool isNoMatch() const
constexpr unsigned id() const
Represents a location in source code.
static SMLoc getFromPointer(const char *Ptr)
constexpr const char * getPointer() const
void push_back(const T &Elt)
LLVM_NO_SANITIZE_CFI_UNRELATED_CAST iterator begin()
iterator find(StringRef Key)
Represent a constant reference to a string, i.e.
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr bool empty() const
Check if the string is empty.
LLVM_ABI bool isLittleEndian() const
Tests whether the target triple is little endian.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
const AArch64MCOptions & getCLOpts(const MCTargetOptions &Options)
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
LLVM_ABI LLVM_READONLY ARMABI computeTargetABI(const Triple &TT, StringRef ABIName="")
LLVM_ABI bool parseAssignmentExpression(StringRef Name, bool allow_redef, MCAsmParser &Parser, MCSymbol *&Symbol, const MCExpr *&Value)
Parse a value expression and return whether it can be assigned to a symbol with the given name.
constexpr unsigned encodeCOP0Register(unsigned Reg, unsigned Sel)
COP0 hardware encodings reserve five bits each for REG and SEL.
MCRegister getCOP0Register(const MCRegisterInfo &MRI, unsigned Encoding)
MCRegister matchRegisterName(StringRef Name, const MCRegisterInfo &MRI, unsigned RegClassID, unsigned AltIdx)
Match a symbolic name in RegClassID, or return an invalid register.
constexpr unsigned getCOP0RegNum(unsigned Encoding)
int getCPURegisterIndex(StringRef Name, const MCRegisterInfo &MRI, unsigned AltIdx, bool *IsDeprecated=nullptr)
Return a GPR name's hardware index, or -1 if unknown.
constexpr unsigned getCOP0Sel(unsigned Encoding)
constexpr MCPhysReg FP_64
constexpr MCPhysReg GP_64
constexpr MCPhysReg RA_64
constexpr MCPhysReg SP_64
WebAssemblyABI getABI(StringRef Name)
Parse an ABI name into the corresponding enum.
@ CE
Windows NT (Windows on ARM)
LLVM_ABI TargetOptions getTargetOptions(const cl::LibraryOptionsContext &LibraryOptions, const llvm::Triple &TheTriple)
Common utility function tightly tied to the options listed here.
LLVM_ABI StringRef getABIName(const cl::LibraryOptionsContext &C)
BaseReg
Stack frame base register. Bit 0 of FREInfo.Info.
unsigned getOpcode(const VPValue *V)
Return the instruction opcode for the recipe defining V or 0 for unsupported recipes and VPValues not...
This is an optimization pass for GlobalISel generic memory operations.
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr, unsigned DynamicVGPRBlockSize=0)
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
Target & getTheMips64Target()
static bool isMem(const MachineInstr &MI, unsigned Op)
LLVM_ABI std::pair< StringRef, StringRef > getToken(StringRef Source, StringRef Delimiters=" \t\n\v\f\r")
getToken - This function extracts one token from source, ignoring any leading characters that appear ...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
static StringRef getCPU(StringRef CPU)
Processes a CPU name.
int bit_width(T Value)
Returns the number of bits needed to represent Value if Value is nonzero.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
SmallVectorImpl< std::unique_ptr< MCParsedAsmOperand > > OperandVector
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
constexpr uint32_t Hi_32(uint64_t Value)
Return the high 32 bits of a 64 bit value.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
constexpr uint32_t Lo_32(uint64_t Value)
Return the low 32 bits of a 64 bit value.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
@ Success
The lock was released successfully.
Target & getTheMips64elTarget()
uint64_t offsetToAlignment(uint64_t Value, Align Alignment)
Returns the offset to the next integer (mod 2**64) that is greater than or equal to Value and is a mu...
@ Ref
The access may reference the value stored in memory.
To bit_cast(const From &from) noexcept
Target & getTheMipselTarget()
DWARFExpression::Operation Op
constexpr bool isShiftedInt(int64_t x)
Checks if a signed integer is an N bit number shifted left by S.
constexpr unsigned BitWidth
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
constexpr bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
static uint16_t getSpecifier(const MCSymbolRefExpr *SRE)
constexpr int64_t SignExtend64(uint64_t x)
Sign-extend the number in the bottom B bits of X to a 64-bit integer.
Target & getTheMipsTarget()
@ End
Run the machine verifier once, at the end of the pipeline.
constexpr bool isShiftedUInt(uint64_t x)
Checks if a unsigned integer is an N bit number shifted left by S.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
RegisterMCAsmParser - Helper template for registering a target specific assembly parser,...