64#define DEBUG_TYPE "mips-asm-parser"
74class MipsAssemblerOptions {
76 MipsAssemblerOptions(
const FeatureBitset &Features_) : Features(Features_) {}
78 MipsAssemblerOptions(
const MipsAssemblerOptions *Opts) {
79 ATReg = Opts->getATRegIndex();
80 Reorder = Opts->isReorder();
81 Macro = Opts->isMacro();
82 Features = Opts->getFeatures();
85 unsigned getATRegIndex()
const {
return ATReg; }
86 bool setATRegIndex(
unsigned Reg) {
94 bool isReorder()
const {
return Reorder; }
95 void setReorder() { Reorder =
true; }
96 void setNoReorder() { Reorder =
false; }
98 bool isMacro()
const {
return Macro; }
99 void setMacro() {
Macro =
true; }
100 void setNoMacro() {
Macro =
false; }
102 const FeatureBitset &
getFeatures()
const {
return Features; }
103 void setFeatures(
const FeatureBitset &Features_) { Features = Features_; }
110 static const FeatureBitset AllArchRelatedMask;
116 FeatureBitset Features;
121const FeatureBitset MipsAssemblerOptions::AllArchRelatedMask = {
122 Mips::FeatureMips1, Mips::FeatureMips2, Mips::FeatureMips3,
123 Mips::FeatureMips3_32, Mips::FeatureMips3_32r2, Mips::FeatureMips4,
124 Mips::FeatureMips4_32, Mips::FeatureMips4_32r2, Mips::FeatureMips5,
125 Mips::FeatureMips5_32r2, Mips::FeatureMips32, Mips::FeatureMips32r2,
126 Mips::FeatureMips32r3, Mips::FeatureMips32r5, Mips::FeatureMips32r6,
127 Mips::FeatureMips64, Mips::FeatureMips64r2, Mips::FeatureMips64r3,
128 Mips::FeatureMips64r5, Mips::FeatureMips64r6, Mips::FeatureCnMips,
129 Mips::FeatureCnMipsP, Mips::FeatureFP64Bit, Mips::FeatureGP64Bit,
130 Mips::FeatureNaN2008, Mips::FeatureNanoMips};
135 MipsTargetStreamer &getTargetStreamer() {
136 assert(getParser().getStreamer().getTargetStreamer() &&
137 "do not have a target streamer");
138 MCTargetStreamer &TS = *getParser().getStreamer().getTargetStreamer();
139 return static_cast<MipsTargetStreamer &
>(TS);
142 const MipsMCOptions &CLOpts;
152 bool CurForbiddenSlotAttr;
155 unsigned CpSaveLocation;
157 bool CpSaveLocationIsRegister;
160 StringMap<AsmToken> RegisterSets;
163 void printWarningWithFixIt(
const Twine &
Msg,
const Twine &FixMsg,
164 SMRange
Range,
bool ShowColors =
true);
167 template <
unsigned Opcode,
bool IsMFTR>
168 void ConvertMTTransferCOP0Operands(MCInst &Inst,
171 ConvertMTTransferCOP0Operands<Mips::MFTR, true>(Inst,
Operands);
174 ConvertMTTransferCOP0Operands<Mips::MTTR, false>(Inst,
Operands);
177#define GET_ASSEMBLER_HEADER
178#include "MipsGenAsmMatcher.inc"
181 checkEarlyTargetMatchPredicate(
MCInst &Inst,
183 unsigned checkTargetMatchPredicate(
MCInst &Inst)
override;
185 bool matchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
188 bool MatchingInlineAsm)
override;
193 SMLoc &EndLoc)
override;
199 bool mnemonicIsValid(
StringRef Mnemonic,
unsigned VariantID);
204 bool ParseDirective(
AsmToken DirectiveID)
override;
208 const MCExpr *parseMemOffset();
219 const MCExpr *parseRelocExpr();
220 bool parsePrimaryExpr(
const MCExpr *&Res,
SMLoc &EndLoc)
override;
226 enum MacroExpanderResultTy {
233 MacroExpanderResultTy tryExpandInstruction(MCInst &Inst, SMLoc IDLoc,
235 const MCSubtargetInfo *STI);
237 bool expandJalWithRegs(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
238 const MCSubtargetInfo *STI);
240 bool loadImmediate(int64_t ImmValue, MCRegister DstReg, MCRegister SrcReg,
241 bool Is32BitImm,
bool IsAddress, SMLoc IDLoc,
242 MCStreamer &Out,
const MCSubtargetInfo *STI);
244 bool loadAndAddSymbolAddress(
const MCExpr *SymExpr, MCRegister DstReg,
245 MCRegister SrcReg,
bool Is32BitSym, SMLoc IDLoc,
246 MCStreamer &Out,
const MCSubtargetInfo *STI);
248 bool emitPartialAddress(MipsTargetStreamer &TOut, SMLoc IDLoc, MCSymbol *Sym);
250 bool expandLoadImm(MCInst &Inst,
bool Is32BitImm, SMLoc IDLoc,
251 MCStreamer &Out,
const MCSubtargetInfo *STI);
253 bool expandLoadSingleImmToGPR(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
254 const MCSubtargetInfo *STI);
255 bool expandLoadSingleImmToFPR(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
256 const MCSubtargetInfo *STI);
257 bool expandLoadDoubleImmToGPR(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
258 const MCSubtargetInfo *STI);
259 bool expandLoadDoubleImmToFPR(MCInst &Inst,
bool Is64FPU, SMLoc IDLoc,
260 MCStreamer &Out,
const MCSubtargetInfo *STI);
262 bool expandLoadAddress(MCRegister DstReg, MCRegister BaseReg,
263 const MCOperand &
Offset,
bool Is32BitAddress,
264 SMLoc IDLoc, MCStreamer &Out,
265 const MCSubtargetInfo *STI);
267 bool expandUncondBranchMMPseudo(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
268 const MCSubtargetInfo *STI);
270 void expandMem16Inst(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
271 const MCSubtargetInfo *STI,
bool IsLoad);
272 void expandMem9Inst(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
273 const MCSubtargetInfo *STI,
bool IsLoad);
275 bool expandLoadStoreMultiple(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
276 const MCSubtargetInfo *STI);
278 bool expandAliasImmediate(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
279 const MCSubtargetInfo *STI);
281 bool expandBranchImm(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
282 const MCSubtargetInfo *STI);
284 bool expandCondBranches(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
285 const MCSubtargetInfo *STI);
287 bool expandDivRem(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
288 const MCSubtargetInfo *STI,
const bool IsMips64,
291 bool expandTrunc(MCInst &Inst,
bool IsDouble,
bool Is64FPU, SMLoc IDLoc,
292 MCStreamer &Out,
const MCSubtargetInfo *STI);
294 bool expandUlh(MCInst &Inst,
bool Signed, SMLoc IDLoc, MCStreamer &Out,
295 const MCSubtargetInfo *STI);
297 bool expandUsh(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
298 const MCSubtargetInfo *STI);
300 bool expandUxw(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
301 const MCSubtargetInfo *STI);
303 bool expandSge(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
304 const MCSubtargetInfo *STI);
306 bool expandSgeImm(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
307 const MCSubtargetInfo *STI);
309 bool expandSgtImm(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
310 const MCSubtargetInfo *STI);
312 bool expandSle(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
313 const MCSubtargetInfo *STI);
315 bool expandSleImm(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
316 const MCSubtargetInfo *STI);
318 bool expandRotation(MCInst &Inst, SMLoc IDLoc,
319 MCStreamer &Out,
const MCSubtargetInfo *STI);
320 bool expandRotationImm(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
321 const MCSubtargetInfo *STI);
322 bool expandDRotation(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
323 const MCSubtargetInfo *STI);
324 bool expandDRotationImm(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
325 const MCSubtargetInfo *STI);
327 bool expandAbs(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
328 const MCSubtargetInfo *STI);
330 bool expandMulImm(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
331 const MCSubtargetInfo *STI);
333 bool expandMulO(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
334 const MCSubtargetInfo *STI);
336 bool expandMulOU(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
337 const MCSubtargetInfo *STI);
339 bool expandDMULMacro(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
340 const MCSubtargetInfo *STI);
342 bool expandLoadStoreDMacro(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
343 const MCSubtargetInfo *STI,
bool IsLoad);
345 bool expandStoreDM1Macro(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
346 const MCSubtargetInfo *STI);
348 bool expandSeq(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
349 const MCSubtargetInfo *STI);
351 bool expandSeqI(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
352 const MCSubtargetInfo *STI);
354 bool expandSne(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
355 const MCSubtargetInfo *STI);
357 bool expandSneI(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
358 const MCSubtargetInfo *STI);
360 bool expandMXTRAlias(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
361 const MCSubtargetInfo *STI);
363 bool expandSaaAddr(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
364 const MCSubtargetInfo *STI);
366 bool reportParseError(
const Twine &ErrorMsg);
367 bool reportParseError(SMLoc Loc,
const Twine &ErrorMsg);
369 bool parseSetMips0Directive();
370 bool parseSetArchDirective();
371 bool parseSetFeature(
uint64_t Feature);
372 bool isPicAndNotNxxAbi();
373 bool parseDirectiveCpAdd(SMLoc Loc);
374 bool parseDirectiveCpLoad(SMLoc Loc);
375 bool parseDirectiveCpLocal(SMLoc Loc);
376 bool parseDirectiveCpRestore(SMLoc Loc);
377 bool parseDirectiveCPSetup();
378 bool parseDirectiveCPReturn();
379 bool parseDirectiveNaN();
380 bool parseDirectiveSet();
381 bool parseDirectiveOption();
382 bool parseInsnDirective();
383 bool parseRSectionDirective(StringRef Section);
384 bool parseSSectionDirective(StringRef Section,
unsigned Type);
386 bool parseSetAtDirective();
387 bool parseSetNoAtDirective();
388 bool parseSetMacroDirective();
389 bool parseSetNoMacroDirective();
390 bool parseSetMsaDirective();
391 bool parseSetNoMsaDirective();
392 bool parseSetNoDspDirective();
393 bool parseSetNoMips3DDirective();
394 bool parseSetReorderDirective();
395 bool parseSetNoReorderDirective();
396 bool parseSetMips16Directive();
397 bool parseSetNoMips16Directive();
398 bool parseSetFpDirective();
399 bool parseSetOddSPRegDirective();
400 bool parseSetNoOddSPRegDirective();
401 bool parseSetPopDirective();
402 bool parseSetPushDirective();
403 bool parseSetSoftFloatDirective();
404 bool parseSetHardFloatDirective();
405 bool parseSetMtDirective();
406 bool parseSetNoMtDirective();
407 bool parseSetNoCRCDirective();
408 bool parseSetNoVirtDirective();
409 bool parseSetNoGINVDirective();
410 bool parseSetNoEVADirective();
412 bool parseSetAssignment();
414 bool parseDirectiveGpWord();
415 bool parseDirectiveGpDWord();
416 bool parseDirectiveDtpRelWord();
417 bool parseDirectiveDtpRelDWord();
418 bool parseDirectiveTpRelWord();
419 bool parseDirectiveTpRelDWord();
420 bool parseDirectiveModule();
421 bool parseDirectiveModuleFP();
423 StringRef Directive);
425 bool parseInternalDirectiveReallowModule();
427 bool eatComma(StringRef ErrorStr);
429 int matchCPURegisterName(StringRef Symbol);
431 int matchHWRegsRegisterName(StringRef Symbol);
433 int matchFPURegisterName(StringRef Name);
435 int matchFCCRegisterName(StringRef Name);
437 int matchACRegisterName(StringRef Name);
439 int matchMSA128RegisterName(StringRef Name);
441 int matchMSA128CtrlRegisterName(StringRef Name);
443 MCRegister
getReg(
int RC,
int RegNo);
448 MCRegister getATReg(SMLoc Loc);
452 bool processInstruction(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
453 const MCSubtargetInfo *STI);
477 void selectArch(StringRef ArchFeature) {
478 MCSubtargetInfo &STI = copySTI();
480 FeatureBits &= ~MipsAssemblerOptions::AllArchRelatedMask;
482 setAvailableFeatures(
487 void setFeatureBits(
uint64_t Feature, StringRef FeatureString) {
489 MCSubtargetInfo &STI = copySTI();
490 setAvailableFeatures(
496 void clearFeatureBits(
uint64_t Feature, StringRef FeatureString) {
498 MCSubtargetInfo &STI = copySTI();
499 setAvailableFeatures(
505 void setModuleFeatureBits(
uint64_t Feature, StringRef FeatureString) {
506 setFeatureBits(Feature, FeatureString);
507 AssemblerOptions.front()->setFeatures(getSTI().getFeatureBits());
510 void clearModuleFeatureBits(
uint64_t Feature, StringRef FeatureString) {
511 clearFeatureBits(Feature, FeatureString);
512 AssemblerOptions.front()->setFeatures(getSTI().getFeatureBits());
516 enum MipsMatchResultTy {
517 Match_RequiresDifferentSrcAndDst = FIRST_TARGET_MATCH_RESULT_TY,
518 Match_RequiresDifferentOperands,
519 Match_RequiresNoZeroRegister,
520 Match_RequiresSameSrcAndDst,
521 Match_NoFCCRegisterForCurrentISA,
522 Match_NonZeroOperandForSync,
523 Match_NonZeroOperandForMTCX,
524 Match_RequiresPosSizeRange0_32,
525 Match_RequiresPosSizeRange33_64,
526 Match_RequiresPosSizeUImm6,
527#define GET_OPERAND_DIAGNOSTIC_TYPES
528#include "MipsGenAsmMatcher.inc"
529#undef GET_OPERAND_DIAGNOSTIC_TYPES
532 MipsAsmParser(
const MCSubtargetInfo &sti, MCAsmParser &parser,
533 const MCInstrInfo &MII)
534 : MCTargetAsmParser(sti, MII),
537 sti.getTargetTriple(),
547 setAvailableFeatures(ComputeAvailableFeatures(getSTI().getFeatureBits()));
550 AssemblerOptions.push_back(
551 std::make_unique<MipsAssemblerOptions>(getSTI().getFeatureBits()));
554 AssemblerOptions.push_back(
555 std::make_unique<MipsAssemblerOptions>(getSTI().getFeatureBits()));
557 getTargetStreamer().updateABIInfo(*
this);
559 if (!isABI_O32() && !useOddSPReg() != 0)
564 CurForbiddenSlotAttr =
false;
565 IsPicEnabled =
getContext().getObjectFileInfo()->isPositionIndependent();
567 IsCpRestoreSet =
false;
568 CpRestoreOffset = -1;
569 GPReg = ABI.GetGlobalPtr();
574 if (getSTI().
getCPU() ==
"mips64r6" && inMicroMipsMode())
577 if (!isABI_O32() && inMicroMipsMode())
582 bool hasEightFccRegisters()
const {
return hasMips4() || hasMips32(); }
584 bool isGP64bit()
const {
585 return getSTI().hasFeature(Mips::FeatureGP64Bit);
588 bool isFP64bit()
const {
589 return getSTI().hasFeature(Mips::FeatureFP64Bit);
592 bool isJalrRelocAvailable(
const MCExpr *JalExpr) {
593 if (!CLOpts.jalr_reloc)
601 return ABI.IsN32() || ABI.IsN64();
605 const MipsABIInfo &
getABI()
const {
return ABI; }
606 bool isABI_N32()
const {
return ABI.IsN32(); }
607 bool isABI_N64()
const {
return ABI.IsN64(); }
608 bool isABI_O32()
const {
return ABI.IsO32(); }
609 bool isABI_FPXX()
const {
610 return getSTI().hasFeature(Mips::FeatureFPXX);
613 bool useOddSPReg()
const {
614 return !(getSTI().hasFeature(Mips::FeatureNoOddSPReg));
617 bool inMicroMipsMode()
const {
618 return getSTI().hasFeature(Mips::FeatureMicroMips);
621 bool hasMips1()
const {
622 return getSTI().hasFeature(Mips::FeatureMips1);
625 bool hasMips2()
const {
626 return getSTI().hasFeature(Mips::FeatureMips2);
629 bool hasMips3()
const {
630 return getSTI().hasFeature(Mips::FeatureMips3);
633 bool hasMips4()
const {
634 return getSTI().hasFeature(Mips::FeatureMips4);
637 bool hasMips5()
const {
638 return getSTI().hasFeature(Mips::FeatureMips5);
641 bool hasMips32()
const {
642 return getSTI().hasFeature(Mips::FeatureMips32);
645 bool hasMips64()
const {
646 return getSTI().hasFeature(Mips::FeatureMips64);
649 bool hasMips32r2()
const {
650 return getSTI().hasFeature(Mips::FeatureMips32r2);
653 bool hasMips64r2()
const {
654 return getSTI().hasFeature(Mips::FeatureMips64r2);
657 bool hasMips32r3()
const {
658 return (getSTI().
hasFeature(Mips::FeatureMips32r3));
661 bool hasMips64r3()
const {
662 return (getSTI().
hasFeature(Mips::FeatureMips64r3));
665 bool hasMips32r5()
const {
666 return (getSTI().
hasFeature(Mips::FeatureMips32r5));
669 bool hasMips64r5()
const {
670 return (getSTI().
hasFeature(Mips::FeatureMips64r5));
673 bool hasMips32r6()
const {
674 return getSTI().hasFeature(Mips::FeatureMips32r6);
677 bool hasMips64r6()
const {
678 return getSTI().hasFeature(Mips::FeatureMips64r6);
681 bool hasNanoMips()
const {
682 return getSTI().hasFeature(Mips::FeatureNanoMips);
685 bool hasDSP()
const {
686 return getSTI().hasFeature(Mips::FeatureDSP);
689 bool hasDSPR2()
const {
690 return getSTI().hasFeature(Mips::FeatureDSPR2);
693 bool hasDSPR3()
const {
694 return getSTI().hasFeature(Mips::FeatureDSPR3);
697 bool hasMSA()
const {
698 return getSTI().hasFeature(Mips::FeatureMSA);
701 bool hasCnMips()
const {
702 return (getSTI().
hasFeature(Mips::FeatureCnMips));
705 bool hasCnMipsP()
const {
706 return (getSTI().
hasFeature(Mips::FeatureCnMipsP));
709 bool isR5900()
const {
return (getSTI().
hasFeature(Mips::FeatureR5900)); }
715 bool inMips16Mode()
const {
716 return getSTI().hasFeature(Mips::FeatureMips16);
719 bool useTraps()
const {
720 return getSTI().hasFeature(Mips::FeatureUseTCCInDIV);
723 bool useSoftFloat()
const {
724 return getSTI().hasFeature(Mips::FeatureSoftFloat);
727 bool isSingleFloat()
const {
728 return getSTI().hasFeature(Mips::FeatureSingleFloat);
732 return getSTI().hasFeature(Mips::FeatureMT);
735 bool hasCRC()
const {
736 return getSTI().hasFeature(Mips::FeatureCRC);
739 bool hasVirt()
const {
740 return getSTI().hasFeature(Mips::FeatureVirt);
743 bool hasGINV()
const {
744 return getSTI().hasFeature(Mips::FeatureGINV);
747 bool hasForbiddenSlot(
const MCInstrDesc &MCID)
const {
751 bool SafeInForbiddenSlot(
const MCInstrDesc &MCID)
const {
755 void onEndOfFile()
override;
758 void warnIfRegIndexIsAT(MCRegister RegIndex, SMLoc Loc);
760 void warnIfNoMacro(SMLoc Loc);
762 bool isLittle()
const {
return IsLittleEndian; }
764 bool areEqualRegs(
const MCParsedAsmOperand &Op1,
765 const MCParsedAsmOperand &Op2)
const override;
780 RegKind_MSACtrl = 16,
785 RegKind_HWRegs = 256,
789 RegKind_Numeric = RegKind_GPR | RegKind_FGR | RegKind_FCC | RegKind_MSA128 |
790 RegKind_MSACtrl | RegKind_COP2 | RegKind_ACC |
791 RegKind_CCR | RegKind_HWRegs | RegKind_COP3 | RegKind_COP0
804 MipsOperand(KindTy K, MipsAsmParser &Parser) : Kind(
K), AsmParser(Parser) {}
806 ~MipsOperand()
override {
815 case k_RegisterIndex:
823 MipsAsmParser &AsmParser;
834 const MCRegisterInfo *RegInfo;
852 struct RegIdxOp RegIdx;
855 struct RegListOp RegList;
858 SMLoc StartLoc, EndLoc;
861 static std::unique_ptr<MipsOperand> CreateReg(
unsigned Index, StringRef Str,
863 const MCRegisterInfo *RegInfo,
865 MipsAsmParser &Parser) {
866 auto Op = std::make_unique<MipsOperand>(k_RegisterIndex, Parser);
868 Op->RegIdx.RegInfo = RegInfo;
869 Op->RegIdx.Kind = RegKind;
870 Op->RegIdx.Tok.Data = Str.data();
871 Op->RegIdx.Tok.Length = Str.size();
880 MCRegister getGPR32Reg()
const {
881 assert(isRegIdx() && (RegIdx.Kind & RegKind_GPR) &&
"Invalid access!");
882 AsmParser.warnIfRegIndexIsAT(RegIdx.Index, StartLoc);
883 unsigned ClassID = Mips::GPR32RegClassID;
884 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
889 MCRegister getGPRMM16Reg()
const {
890 assert(isRegIdx() && (RegIdx.Kind & RegKind_GPR) &&
"Invalid access!");
891 unsigned ClassID = Mips::GPR32RegClassID;
892 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
897 MCRegister getGPR64Reg()
const {
898 assert(isRegIdx() && (RegIdx.Kind & RegKind_GPR) &&
"Invalid access!");
899 unsigned ClassID = Mips::GPR64RegClassID;
900 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
906 MCRegister getAFGR64Reg()
const {
907 assert(isRegIdx() && (RegIdx.Kind & RegKind_FGR) &&
"Invalid access!");
908 if (RegIdx.Index % 2 != 0)
909 AsmParser.Warning(StartLoc,
"Float register should be even.");
910 return RegIdx.RegInfo->getRegClass(Mips::AFGR64RegClassID)
911 .getRegister(RegIdx.Index / 2);
916 MCRegister getFGR64Reg()
const {
917 assert(isRegIdx() && (RegIdx.Kind & RegKind_FGR) &&
"Invalid access!");
918 return RegIdx.RegInfo->getRegClass(Mips::FGR64RegClassID)
919 .getRegister(RegIdx.Index);
924 MCRegister getFGR32Reg()
const {
925 assert(isRegIdx() && (RegIdx.Kind & RegKind_FGR) &&
"Invalid access!");
926 return RegIdx.RegInfo->getRegClass(Mips::FGR32RegClassID)
927 .getRegister(RegIdx.Index);
932 MCRegister getFCCReg()
const {
933 assert(isRegIdx() && (RegIdx.Kind & RegKind_FCC) &&
"Invalid access!");
934 return RegIdx.RegInfo->getRegClass(Mips::FCCRegClassID)
935 .getRegister(RegIdx.Index);
940 MCRegister getMSA128Reg()
const {
941 assert(isRegIdx() && (RegIdx.Kind & RegKind_MSA128) &&
"Invalid access!");
944 unsigned ClassID = Mips::MSA128BRegClassID;
945 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
950 MCRegister getMSACtrlReg()
const {
951 assert(isRegIdx() && (RegIdx.Kind & RegKind_MSACtrl) &&
"Invalid access!");
952 unsigned ClassID = Mips::MSACtrlRegClassID;
953 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
958 MCRegister getCOP0Reg()
const {
964 MCRegister getCOP2Reg()
const {
965 assert(isRegIdx() && (RegIdx.Kind & RegKind_COP2) &&
"Invalid access!");
966 unsigned ClassID = Mips::COP2RegClassID;
967 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
972 MCRegister getCOP3Reg()
const {
973 assert(isRegIdx() && (RegIdx.Kind & RegKind_COP3) &&
"Invalid access!");
974 unsigned ClassID = Mips::COP3RegClassID;
975 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
980 MCRegister getACC64DSPReg()
const {
981 assert(isRegIdx() && (RegIdx.Kind & RegKind_ACC) &&
"Invalid access!");
982 unsigned ClassID = Mips::ACC64DSPRegClassID;
983 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
988 MCRegister getHI32DSPReg()
const {
989 assert(isRegIdx() && (RegIdx.Kind & RegKind_ACC) &&
"Invalid access!");
990 unsigned ClassID = Mips::HI32DSPRegClassID;
991 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
996 MCRegister getLO32DSPReg()
const {
997 assert(isRegIdx() && (RegIdx.Kind & RegKind_ACC) &&
"Invalid access!");
998 unsigned ClassID = Mips::LO32DSPRegClassID;
999 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
1004 MCRegister getCCRReg()
const {
1005 assert(isRegIdx() && (RegIdx.Kind & RegKind_CCR) &&
"Invalid access!");
1006 unsigned ClassID = Mips::CCRRegClassID;
1007 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
1012 MCRegister getHWRegsReg()
const {
1013 assert(isRegIdx() && (RegIdx.Kind & RegKind_HWRegs) &&
"Invalid access!");
1014 unsigned ClassID = Mips::HWRegsRegClassID;
1015 return RegIdx.RegInfo->getRegClass(ClassID).getRegister(RegIdx.Index);
1019 void addExpr(MCInst &Inst,
const MCExpr *Expr)
const {
1029 void addRegOperands(MCInst &Inst,
unsigned N)
const {
1036 void addGPR32ZeroAsmRegOperands(MCInst &Inst,
unsigned N)
const {
1037 assert(
N == 1 &&
"Invalid number of operands!");
1041 void addGPR32NonZeroAsmRegOperands(MCInst &Inst,
unsigned N)
const {
1042 assert(
N == 1 &&
"Invalid number of operands!");
1046 void addGPR32AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1047 assert(
N == 1 &&
"Invalid number of operands!");
1051 void addGPRMM16AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1052 assert(
N == 1 &&
"Invalid number of operands!");
1056 void addGPRMM16AsmRegZeroOperands(MCInst &Inst,
unsigned N)
const {
1057 assert(
N == 1 &&
"Invalid number of operands!");
1061 void addGPRMM16AsmRegMovePOperands(MCInst &Inst,
unsigned N)
const {
1062 assert(
N == 1 &&
"Invalid number of operands!");
1066 void addGPRMM16AsmRegMovePPairFirstOperands(MCInst &Inst,
unsigned N)
const {
1067 assert(
N == 1 &&
"Invalid number of operands!");
1071 void addGPRMM16AsmRegMovePPairSecondOperands(MCInst &Inst,
1073 assert(
N == 1 &&
"Invalid number of operands!");
1080 void addGPR64AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1081 assert(
N == 1 &&
"Invalid number of operands!");
1085 void addAFGR64AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1086 assert(
N == 1 &&
"Invalid number of operands!");
1090 void addStrictlyAFGR64AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1091 assert(
N == 1 &&
"Invalid number of operands!");
1095 void addStrictlyFGR64AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1096 assert(
N == 1 &&
"Invalid number of operands!");
1100 void addFGR64AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1101 assert(
N == 1 &&
"Invalid number of operands!");
1105 void addFGR32AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1106 assert(
N == 1 &&
"Invalid number of operands!");
1110 if (!AsmParser.useOddSPReg() && RegIdx.Index & 1)
1111 AsmParser.getParser().printError(
1112 StartLoc,
"-mno-odd-spreg prohibits the use of odd FPU "
1116 void addStrictlyFGR32AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1117 assert(
N == 1 &&
"Invalid number of operands!");
1120 if (!AsmParser.useOddSPReg() && RegIdx.Index & 1)
1121 AsmParser.Error(StartLoc,
"-mno-odd-spreg prohibits the use of odd FPU "
1125 void addFCCAsmRegOperands(MCInst &Inst,
unsigned N)
const {
1126 assert(
N == 1 &&
"Invalid number of operands!");
1130 void addMSA128AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1131 assert(
N == 1 &&
"Invalid number of operands!");
1135 void addMSACtrlAsmRegOperands(MCInst &Inst,
unsigned N)
const {
1136 assert(
N == 1 &&
"Invalid number of operands!");
1140 void addCOP0AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1141 assert(
N == 1 &&
"Invalid number of operands!");
1145 void addCOP2AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1146 assert(
N == 1 &&
"Invalid number of operands!");
1150 void addCOP3AsmRegOperands(MCInst &Inst,
unsigned N)
const {
1151 assert(
N == 1 &&
"Invalid number of operands!");
1155 void addACC64DSPAsmRegOperands(MCInst &Inst,
unsigned N)
const {
1156 assert(
N == 1 &&
"Invalid number of operands!");
1160 void addHI32DSPAsmRegOperands(MCInst &Inst,
unsigned N)
const {
1161 assert(
N == 1 &&
"Invalid number of operands!");
1165 void addLO32DSPAsmRegOperands(MCInst &Inst,
unsigned N)
const {
1166 assert(
N == 1 &&
"Invalid number of operands!");
1170 void addCCRAsmRegOperands(MCInst &Inst,
unsigned N)
const {
1171 assert(
N == 1 &&
"Invalid number of operands!");
1175 void addHWRegsAsmRegOperands(MCInst &Inst,
unsigned N)
const {
1176 assert(
N == 1 &&
"Invalid number of operands!");
1180 template <
unsigned Bits,
int Offset = 0,
int AdjustOffset = 0>
1181 void addConstantUImmOperands(MCInst &Inst,
unsigned N)
const {
1182 assert(
N == 1 &&
"Invalid number of operands!");
1186 Imm += AdjustOffset;
1190 template <
unsigned Bits>
1191 void addSImmOperands(MCInst &Inst,
unsigned N)
const {
1192 if (isImm() && !isConstantImm()) {
1196 addConstantSImmOperands<Bits, 0, 0>(Inst,
N);
1199 template <
unsigned Bits>
1200 void addUImmOperands(MCInst &Inst,
unsigned N)
const {
1201 if (isImm() && !isConstantImm()) {
1205 addConstantUImmOperands<Bits, 0, 0>(Inst,
N);
1208 template <
unsigned Bits,
int Offset = 0,
int AdjustOffset = 0>
1209 void addConstantSImmOperands(MCInst &Inst,
unsigned N)
const {
1210 assert(
N == 1 &&
"Invalid number of operands!");
1211 int64_t
Imm = getConstantImm() -
Offset;
1214 Imm += AdjustOffset;
1218 void addImmOperands(MCInst &Inst,
unsigned N)
const {
1219 assert(
N == 1 &&
"Invalid number of operands!");
1220 const MCExpr *Expr =
getImm();
1221 addExpr(Inst, Expr);
1224 void addPtrRegOperands(MCInst &Inst,
unsigned N)
const {
1225 assert(
N == 1 &&
"Invalid number of operands!");
1227 AsmParser.getABI().ArePtrs64bit() ? getGPR64Reg() : getGPR32Reg()));
1230 void addMemOperands(MCInst &Inst,
unsigned N)
const {
1231 assert(
N == 2 &&
"Invalid number of operands!");
1232 getMemBase()->addPtrRegOperands(Inst, 1);
1233 addExpr(Inst, getMemOff());
1236 bool isSPAsmReg()
const {
return isGPRAsmReg() && RegIdx.Index == 29; }
1237 bool isGPAsmReg()
const {
return isGPRAsmReg() && RegIdx.Index == 28; }
1239 bool isSImmPtr()
const {
1240 return AsmParser.getABI().ArePtrs64bit() ? isScaledSImm<64, 0>()
1241 : isScaledSImm<32, 0>();
1244 void addRegListOperands(MCInst &Inst,
unsigned N)
const {
1245 assert(
N == 1 &&
"Invalid number of operands!");
1247 for (
auto RegNo : getRegList())
1251 bool isReg()
const override {
1254 return isGPRAsmReg() && RegIdx.Index == 0;
1257 bool isRegIdx()
const {
return Kind == k_RegisterIndex; }
1259 bool isNumericReg()
const {
1260 return isRegIdx() && RegIdx.Kind == RegKind_Numeric && RegIdx.Index < 32;
1263 unsigned getNumericRegIndex()
const {
1264 assert(isNumericReg() &&
"Invalid numeric register");
1265 return RegIdx.Index;
1268 bool isImm()
const override {
return Kind == k_Immediate; }
1270 bool isConstantImm()
const {
1272 return isImm() &&
getImm()->evaluateAsAbsolute(Res);
1275 bool isConstantImmz()
const {
1276 return isConstantImm() && getConstantImm() == 0;
1279 template <
unsigned Bits,
int Offset = 0>
bool isConstantUImm()
const {
1283 template <
unsigned Bits>
bool isSImm()
const {
1287 if (
getImm()->evaluateAsAbsolute(Res))
1293 template <
unsigned Bits>
bool isUImm()
const {
1297 if (
getImm()->evaluateAsAbsolute(Res))
1303 template <
unsigned Bits>
bool isAnyImm()
const {
1304 return isConstantImm() ? (
isInt<Bits>(getConstantImm()) ||
1309 template <
unsigned Bits,
int Offset = 0>
bool isConstantSImm()
const {
1313 template <
unsigned Bottom,
unsigned Top>
bool isConstantUImmRange()
const {
1314 return isConstantImm() && getConstantImm() >= Bottom &&
1315 getConstantImm() <= Top;
1318 bool isToken()
const override {
1321 return Kind == k_Token;
1324 bool isMem()
const override {
return Kind == k_Memory; }
1329 template <
unsigned Bits,
unsigned ShiftLeftAmount,
int Bias = 0>
1330 bool isScaledUImm()
const {
1332 uint64_t(getConstantImm()) - Bias);
1335 template <
unsigned Bits,
unsigned ShiftLeftAmount>
1336 bool isScaledSImm()
const {
1337 if (isConstantImm() &&
1342 if (Kind != k_Immediate)
1347 bool Success =
getImm()->evaluateAsRelocatable(Res,
nullptr);
1351 bool isRegList16()
const {
1355 int Size = RegList.List->size();
1359 MCRegister R0 = RegList.List->front();
1360 MCRegister R1 = RegList.List->back();
1361 if (!((R0 == Mips::R16 && R1 ==
Mips::RA) ||
1365 MCRegister PrevReg = RegList.List->front();
1366 for (
int i = 1; i <
Size - 1; i++) {
1367 MCRegister
Reg = (*(RegList.List))[i];
1368 if (
Reg != PrevReg + 1)
1376 bool isInvNum()
const {
return Kind == k_Immediate; }
1378 bool isLSAImm()
const {
1379 if (!isConstantImm())
1381 int64_t Val = getConstantImm();
1382 return 1 <= Val && Val <= 4;
1385 bool isRegList()
const {
return Kind == k_RegList; }
1388 assert(Kind == k_Token &&
"Invalid access!");
1389 return StringRef(Tok.Data, Tok.Length);
1392 MCRegister
getReg()
const override {
1395 if (Kind == k_RegisterIndex && RegIdx.Index == 0 &&
1396 RegIdx.Kind & RegKind_GPR)
1397 return getGPR32Reg();
1403 const MCExpr *
getImm()
const {
1404 assert((Kind == k_Immediate) &&
"Invalid access!");
1408 int64_t getConstantImm()
const {
1409 const MCExpr *Val =
getImm();
1411 (void)Val->evaluateAsAbsolute(
Value);
1415 MipsOperand *getMemBase()
const {
1416 assert((Kind == k_Memory) &&
"Invalid access!");
1420 const MCExpr *getMemOff()
const {
1421 assert((Kind == k_Memory) &&
"Invalid access!");
1425 const SmallVectorImpl<MCRegister> &getRegList()
const {
1426 assert((Kind == k_RegList) &&
"Invalid access!");
1427 return *(RegList.List);
1430 static std::unique_ptr<MipsOperand> CreateToken(StringRef Str, SMLoc S,
1431 MipsAsmParser &Parser) {
1432 auto Op = std::make_unique<MipsOperand>(k_Token, Parser);
1433 Op->Tok.Data = Str.data();
1434 Op->Tok.Length = Str.size();
1442 static std::unique_ptr<MipsOperand>
1443 createNumericReg(
unsigned Index, StringRef Str,
const MCRegisterInfo *RegInfo,
1444 SMLoc S, SMLoc
E, MipsAsmParser &Parser) {
1445 LLVM_DEBUG(
dbgs() <<
"createNumericReg(" << Index <<
", ...)\n");
1446 return CreateReg(Index, Str, RegKind_Numeric, RegInfo, S,
E, Parser);
1451 static std::unique_ptr<MipsOperand>
1452 createGPRReg(
unsigned Index, StringRef Str,
const MCRegisterInfo *RegInfo,
1453 SMLoc S, SMLoc
E, MipsAsmParser &Parser) {
1454 return CreateReg(Index, Str, RegKind_GPR, RegInfo, S,
E, Parser);
1459 static std::unique_ptr<MipsOperand>
1460 createFGRReg(
unsigned Index, StringRef Str,
const MCRegisterInfo *RegInfo,
1461 SMLoc S, SMLoc
E, MipsAsmParser &Parser) {
1462 return CreateReg(Index, Str, RegKind_FGR, RegInfo, S,
E, Parser);
1465 static std::unique_ptr<MipsOperand>
1466 createCOP0Reg(
unsigned Encoding, StringRef Str,
const MCRegisterInfo *RegInfo,
1467 SMLoc S, SMLoc
E, MipsAsmParser &Parser) {
1470 "Invalid COP0 register encoding");
1471 return CreateReg(Encoding, Str, RegKind_COP0, RegInfo, S,
E, Parser);
1476 static std::unique_ptr<MipsOperand>
1477 createHWRegsReg(
unsigned Index, StringRef Str,
const MCRegisterInfo *RegInfo,
1478 SMLoc S, SMLoc
E, MipsAsmParser &Parser) {
1479 return CreateReg(Index, Str, RegKind_HWRegs, RegInfo, S,
E, Parser);
1484 static std::unique_ptr<MipsOperand>
1485 createFCCReg(
unsigned Index, StringRef Str,
const MCRegisterInfo *RegInfo,
1486 SMLoc S, SMLoc
E, MipsAsmParser &Parser) {
1487 return CreateReg(Index, Str, RegKind_FCC, RegInfo, S,
E, Parser);
1492 static std::unique_ptr<MipsOperand>
1493 createACCReg(
unsigned Index, StringRef Str,
const MCRegisterInfo *RegInfo,
1494 SMLoc S, SMLoc
E, MipsAsmParser &Parser) {
1495 return CreateReg(Index, Str, RegKind_ACC, RegInfo, S,
E, Parser);
1500 static std::unique_ptr<MipsOperand>
1501 createMSA128Reg(
unsigned Index, StringRef Str,
const MCRegisterInfo *RegInfo,
1502 SMLoc S, SMLoc
E, MipsAsmParser &Parser) {
1503 return CreateReg(Index, Str, RegKind_MSA128, RegInfo, S,
E, Parser);
1508 static std::unique_ptr<MipsOperand>
1509 createMSACtrlReg(
unsigned Index, StringRef Str,
const MCRegisterInfo *RegInfo,
1510 SMLoc S, SMLoc
E, MipsAsmParser &Parser) {
1511 return CreateReg(Index, Str, RegKind_MSACtrl, RegInfo, S,
E, Parser);
1514 static std::unique_ptr<MipsOperand>
1515 CreateImm(
const MCExpr *Val, SMLoc S, SMLoc
E, MipsAsmParser &Parser) {
1516 auto Op = std::make_unique<MipsOperand>(k_Immediate, Parser);
1523 static std::unique_ptr<MipsOperand>
1524 CreateMem(std::unique_ptr<MipsOperand>
Base,
const MCExpr *
Off, SMLoc S,
1525 SMLoc
E, MipsAsmParser &Parser) {
1526 auto Op = std::make_unique<MipsOperand>(k_Memory, Parser);
1527 Op->Mem.Base =
Base.release();
1534 static std::unique_ptr<MipsOperand>
1535 CreateRegList(SmallVectorImpl<MCRegister> &Regs, SMLoc StartLoc, SMLoc EndLoc,
1536 MipsAsmParser &Parser) {
1537 assert(!Regs.
empty() &&
"Empty list not allowed");
1539 auto Op = std::make_unique<MipsOperand>(k_RegList, Parser);
1542 Op->StartLoc = StartLoc;
1543 Op->EndLoc = EndLoc;
1547 bool isGPRZeroAsmReg()
const {
1548 return isRegIdx() && RegIdx.Kind & RegKind_GPR && RegIdx.Index == 0;
1551 bool isGPRNonZeroAsmReg()
const {
1552 return isRegIdx() && RegIdx.Kind & RegKind_GPR && RegIdx.Index > 0 &&
1556 bool isGPRAsmReg()
const {
1557 return isRegIdx() && RegIdx.Kind & RegKind_GPR && RegIdx.Index <= 31;
1560 bool isMM16AsmReg()
const {
1563 return ((RegIdx.Index >= 2 && RegIdx.Index <= 7)
1564 || RegIdx.Index == 16 || RegIdx.Index == 17);
1567 bool isMM16AsmRegZero()
const {
1570 return (RegIdx.Index == 0 ||
1571 (RegIdx.Index >= 2 && RegIdx.Index <= 7) ||
1572 RegIdx.Index == 17);
1575 bool isMM16AsmRegMoveP()
const {
1576 if (!(isRegIdx() && RegIdx.Kind))
1578 return (RegIdx.Index == 0 || (RegIdx.Index >= 2 && RegIdx.Index <= 3) ||
1579 (RegIdx.Index >= 16 && RegIdx.Index <= 20));
1582 bool isMM16AsmRegMovePPairFirst()
const {
1583 if (!(isRegIdx() && RegIdx.Kind))
1585 return RegIdx.Index >= 4 && RegIdx.Index <= 6;
1588 bool isMM16AsmRegMovePPairSecond()
const {
1589 if (!(isRegIdx() && RegIdx.Kind))
1591 return (RegIdx.Index == 21 || RegIdx.Index == 22 ||
1592 (RegIdx.Index >= 5 && RegIdx.Index <= 7));
1595 bool isFGRAsmReg()
const {
1597 return isRegIdx() && RegIdx.Kind & RegKind_FGR && RegIdx.Index <= 31;
1600 bool isStrictlyFGRAsmReg()
const {
1602 return isRegIdx() && RegIdx.Kind == RegKind_FGR && RegIdx.Index <= 31;
1605 bool isHWRegsAsmReg()
const {
1606 return isRegIdx() && RegIdx.Kind & RegKind_HWRegs && RegIdx.Index <= 31;
1609 bool isCCRAsmReg()
const {
1610 return isRegIdx() && RegIdx.Kind & RegKind_CCR && RegIdx.Index <= 31;
1613 bool isFCCAsmReg()
const {
1614 if (!(isRegIdx() && RegIdx.Kind & RegKind_FCC))
1616 return RegIdx.Index <= 7;
1619 bool isACCAsmReg()
const {
1620 return isRegIdx() && RegIdx.Kind & RegKind_ACC && RegIdx.Index <= 3;
1623 bool isCOP0AsmReg()
const {
1624 return isRegIdx() && RegIdx.Kind == RegKind_COP0;
1627 unsigned getCOP0Encoding()
const {
1628 assert(isCOP0AsmReg() &&
"Invalid COP0 register");
1629 return RegIdx.Index;
1632 bool isCOP2AsmReg()
const {
1633 return isRegIdx() && RegIdx.Kind & RegKind_COP2 && RegIdx.Index <= 31;
1636 bool isCOP3AsmReg()
const {
1637 return isRegIdx() && RegIdx.Kind & RegKind_COP3 && RegIdx.Index <= 31;
1640 bool isMSA128AsmReg()
const {
1641 return isRegIdx() && RegIdx.Kind & RegKind_MSA128 && RegIdx.Index <= 31;
1644 bool isMSACtrlAsmReg()
const {
1645 return isRegIdx() && RegIdx.Kind & RegKind_MSACtrl && RegIdx.Index <= 7;
1648 bool isNM16AsmReg()
const {
1649 if (!(isRegIdx() && RegIdx.Kind))
1651 return ((RegIdx.Index >= 4 && RegIdx.Index <= 7) ||
1652 (RegIdx.Index >= 16 && RegIdx.Index <= 19));
1655 bool isNM16ZeroAsmReg()
const {
1656 if (!(isRegIdx() && RegIdx.Kind))
1658 return ((RegIdx.Index == 0) || (RegIdx.Index >= 4 && RegIdx.Index <= 7) ||
1659 (RegIdx.Index >= 17 && RegIdx.Index <= 19));
1662 bool isNM4AsmReg()
const {
1663 if (!(isRegIdx() && RegIdx.Kind))
1665 return ((RegIdx.Index >= 4 && RegIdx.Index <= 11) ||
1666 (RegIdx.Index >= 16 && RegIdx.Index <= 23));
1669 bool isNM4ZeroAsmReg()
const {
1670 if (!(isRegIdx() && RegIdx.Kind))
1672 return ((RegIdx.Index == 0) || (RegIdx.Index >= 4 && RegIdx.Index <= 10) ||
1673 (RegIdx.Index >= 16 && RegIdx.Index <= 23));
1676 bool isNM2R1AsmReg()
const {
1677 if (!(isRegIdx() && RegIdx.Kind))
1679 return RegIdx.Index >= 4 && RegIdx.Index <= 7;
1682 bool isNM2R2AsmReg()
const {
1683 if (!(isRegIdx() && RegIdx.Kind))
1685 return RegIdx.Index >= 5 && RegIdx.Index <= 8;
1688 bool isNM1R1AsmReg()
const {
1689 if (!(isRegIdx() && RegIdx.Kind))
1691 return RegIdx.Index == 4 || RegIdx.Index == 5;
1694 template <
unsigned RegClassID = Mips::GPR32RegClassID>
1695 bool isGPRNMAsmReg()
const {
1696 if (!(isRegIdx() && RegIdx.Kind))
1698 switch (RegClassID) {
1699 case Mips::GP32RegClassID:
1700 return (RegIdx.Index == 28);
1701 case Mips::SP32RegClassID:
1702 return (RegIdx.Index == 29);
1703 case Mips::GPRNMRARegClassID:
1704 return (RegIdx.Index == 31);
1705 case Mips::GPR32NONZERORegClassID:
1706 return (RegIdx.Index > 0 && RegIdx.Index < 32);
1707 case Mips::GPRNM3RegClassID:
1708 return isNM16AsmReg();
1709 case Mips::GPRNM3ZRegClassID:
1710 return isNM16ZeroAsmReg();
1711 case Mips::GPRNM4RegClassID:
1712 return isNM4AsmReg();
1713 case Mips::GPRNM4ZRegClassID:
1714 return isNM4ZeroAsmReg();
1715 case Mips::GPRNM2R1RegClassID:
1716 return isNM2R1AsmReg();
1717 case Mips::GPRNM2R2RegClassID:
1718 return isNM2R2AsmReg();
1719 case Mips::GPRNM1R1RegClassID:
1720 return isNM1R1AsmReg();
1722 return RegIdx.Index < 32;
1727 SMLoc getStartLoc()
const override {
return StartLoc; }
1729 SMLoc getEndLoc()
const override {
return EndLoc; }
1731 void print(raw_ostream &OS,
const MCAsmInfo &MAI)
const override {
1740 Mem.Base->print(OS, MAI);
1745 case k_RegisterIndex:
1746 OS <<
"RegIdx<" << RegIdx.Index <<
":" << RegIdx.Kind <<
", "
1747 << StringRef(RegIdx.Tok.Data, RegIdx.Tok.Length) <<
">";
1754 for (
auto Reg : (*RegList.List))
1755 OS <<
Reg.
id() <<
" ";
1761 bool isValidForTie(
const MipsOperand &
Other)
const {
1762 if (Kind !=
Other.Kind)
1769 case k_RegisterIndex: {
1770 StringRef Token(RegIdx.Tok.Data, RegIdx.Tok.Length);
1771 StringRef OtherToken(
Other.RegIdx.Tok.Data,
Other.RegIdx.Tok.Length);
1772 return Token == OtherToken;
1788 case Mips::JRC16_MM:
1790 case Mips::JALRS_MM:
1791 case Mips::JALRS16_MM:
1792 case Mips::BGEZALS_MM:
1793 case Mips::BLTZALS_MM:
1804 return &SRExpr->getSymbol();
1863 unsigned NumOp =
MCID.getNumOperands();
1864 if (NumOp != 3 && NumOp != 4)
1894bool MipsAsmParser::processInstruction(
MCInst &Inst,
SMLoc IDLoc,
1897 MipsTargetStreamer &TOut = getTargetStreamer();
1898 const unsigned Opcode = Inst.
getOpcode();
1899 const MCInstrDesc &MCID = MII.get(Opcode);
1900 bool ExpandedJalSym =
false;
1914 assert(hasCnMips() &&
"instruction only valid for octeon cpus");
1925 if (!
isIntN(inMicroMipsMode() ? 17 : 18,
Offset.getImm()))
1926 return Error(IDLoc,
"branch target out of range");
1929 return Error(IDLoc,
"branch to misaligned address");
1943 case Mips::BGEZAL_MM:
1944 case Mips::BLTZAL_MM:
1947 case Mips::BC1EQZC_MMR6:
1948 case Mips::BC1NEZC_MMR6:
1949 case Mips::BC2EQZC_MMR6:
1950 case Mips::BC2NEZC_MMR6:
1955 if (!
isIntN(inMicroMipsMode() ? 17 : 18,
Offset.getImm()))
1956 return Error(IDLoc,
"branch target out of range");
1959 return Error(IDLoc,
"branch to misaligned address");
1961 case Mips::BGEC:
case Mips::BGEC_MMR6:
1962 case Mips::BLTC:
case Mips::BLTC_MMR6:
1963 case Mips::BGEUC:
case Mips::BGEUC_MMR6:
1964 case Mips::BLTUC:
case Mips::BLTUC_MMR6:
1965 case Mips::BEQC:
case Mips::BEQC_MMR6:
1966 case Mips::BNEC:
case Mips::BNEC_MMR6:
1972 return Error(IDLoc,
"branch target out of range");
1974 return Error(IDLoc,
"branch to misaligned address");
1976 case Mips::BLEZC:
case Mips::BLEZC_MMR6:
1977 case Mips::BGEZC:
case Mips::BGEZC_MMR6:
1978 case Mips::BGTZC:
case Mips::BGTZC_MMR6:
1979 case Mips::BLTZC:
case Mips::BLTZC_MMR6:
1985 return Error(IDLoc,
"branch target out of range");
1987 return Error(IDLoc,
"branch to misaligned address");
1989 case Mips::BEQZC:
case Mips::BEQZC_MMR6:
1990 case Mips::BNEZC:
case Mips::BNEZC_MMR6:
1996 return Error(IDLoc,
"branch target out of range");
1998 return Error(IDLoc,
"branch to misaligned address");
2000 case Mips::BEQZ16_MM:
2001 case Mips::BEQZC16_MMR6:
2002 case Mips::BNEZ16_MM:
2003 case Mips::BNEZC16_MMR6:
2009 return Error(IDLoc,
"branch target out of range");
2011 return Error(IDLoc,
"branch to misaligned address");
2018 if (hasMips32r6() && Opcode == Mips::SSNOP) {
2019 std::string
ISA = hasMips64r6() ?
"MIPS64r6" :
"MIPS32r6";
2020 Warning(IDLoc,
"ssnop is deprecated for " + ISA +
" and is equivalent to a "
2040 return Error(IDLoc,
"expected immediate operand kind");
2043 Opcode == Mips::BBIT1 ? 63 : 31))
2044 return Error(IDLoc,
"immediate operand value out of range");
2046 Inst.
setOpcode(Opcode == Mips::BBIT0 ? Mips::BBIT032
2057 return Error(IDLoc,
"expected immediate operand kind");
2060 return Error(IDLoc,
"immediate operand value out of range");
2072 unsigned FirstOp = 1;
2073 unsigned SecondOp = 2;
2077 case Mips::SDivIMacro:
2078 case Mips::UDivIMacro:
2079 case Mips::DSDivIMacro:
2080 case Mips::DUDivIMacro:
2082 return Error(IDLoc,
"expected immediate operand kind");
2086 Warning(IDLoc,
"dividing zero by zero");
2088 Warning(IDLoc,
"division by zero");
2100 case Mips::SDivMacro:
2101 case Mips::DSDivMacro:
2102 case Mips::UDivMacro:
2103 case Mips::DUDivMacro:
2108 case Mips::DIVU_MMR6:
2109 case Mips::DIV_MMR6:
2114 Warning(IDLoc,
"dividing zero by zero");
2116 Warning(IDLoc,
"division by zero");
2122 if ((Opcode == Mips::J || Opcode == Mips::J_MM) && inPicMode()) {
2124 BInst.
setOpcode(inMicroMipsMode() ? Mips::BEQ_MM : Mips::BEQ);
2133 if ((Opcode == Mips::JAL || Opcode == Mips::JAL_MM) && inPicMode()) {
2134 warnIfNoMacro(IDLoc);
2137 return Error(IDLoc,
"unsupported constant in relocation");
2145 return Error(IDLoc,
"jal doesn't support multiple symbols in PIC mode");
2151 if (expandLoadAddress(
getABI().getTempReg(9), MCRegister(),
2152 Inst.
getOperand(0), !isGP64bit(), IDLoc, Out, STI))
2156 if (inMicroMipsMode())
2157 JalrInst.
setOpcode(IsCpRestoreSet ? Mips::JALRS_MM : Mips::JALR_MM);
2163 if (isJalrRelocAvailable(JalExpr)) {
2169 const MCExpr *RelocJalrExpr =
2173 *TmpExpr, inMicroMipsMode() ?
"R_MICROMIPS_JALR" :
"R_MIPS_JALR",
2179 ExpandedJalSym =
true;
2188 expandMem9Inst(Inst, IDLoc, Out, STI, MCID.
mayLoad());
2191 expandMem16Inst(Inst, IDLoc, Out, STI, MCID.
mayLoad());
2194 return getParser().hasPendingError();
2198 if (inMicroMipsMode()) {
2199 if (Opcode == Mips::LW_MM || Opcode == Mips::LW_MMR6) {
2202 const MCOperandInfo &OpInfo = MCID.
operands()[i];
2207 int MemOffset =
Op.getImm();
2210 if (
isInt<9>(MemOffset) && (MemOffset % 4 == 0) &&
2233 case Mips::ADDIUSP_MM:
2236 return Error(IDLoc,
"expected immediate operand kind");
2240 return Error(IDLoc,
"immediate operand value out of range");
2242 case Mips::SLL16_MM:
2243 case Mips::SRL16_MM:
2246 return Error(IDLoc,
"expected immediate operand kind");
2249 return Error(IDLoc,
"immediate operand value out of range");
2254 return Error(IDLoc,
"expected immediate operand kind");
2257 return Error(IDLoc,
"immediate operand value out of range");
2259 case Mips::ADDIUR2_MM:
2262 return Error(IDLoc,
"expected immediate operand kind");
2264 if (!(
Imm == 1 ||
Imm == -1 ||
2266 return Error(IDLoc,
"immediate operand value out of range");
2268 case Mips::ANDI16_MM:
2271 return Error(IDLoc,
"expected immediate operand kind");
2275 Imm == 64 ||
Imm == 255 ||
Imm == 32768 ||
Imm == 65535))
2276 return Error(IDLoc,
"immediate operand value out of range");
2278 case Mips::LBU16_MM:
2281 return Error(IDLoc,
"expected immediate operand kind");
2284 return Error(IDLoc,
"immediate operand value out of range");
2287 case Mips::SB16_MMR6:
2290 return Error(IDLoc,
"expected immediate operand kind");
2293 return Error(IDLoc,
"immediate operand value out of range");
2295 case Mips::LHU16_MM:
2297 case Mips::SH16_MMR6:
2300 return Error(IDLoc,
"expected immediate operand kind");
2303 return Error(IDLoc,
"immediate operand value out of range");
2307 case Mips::SW16_MMR6:
2310 return Error(IDLoc,
"expected immediate operand kind");
2313 return Error(IDLoc,
"immediate operand value out of range");
2315 case Mips::ADDIUPC_MM:
2318 return Error(IDLoc,
"expected immediate operand kind");
2321 return Error(IDLoc,
"immediate operand value out of range");
2326 return Error(IDLoc,
"invalid operand for instruction");
2328 case Mips::MOVEP_MM:
2329 case Mips::MOVEP_MMR6: {
2332 bool RegPair = ((R0 == Mips::R5 && R1 == Mips::R6) ||
2333 (R0 == Mips::R5 && R1 == Mips::R7) ||
2334 (R0 == Mips::R6 && R1 == Mips::R7) ||
2335 (R0 == Mips::R4 && R1 == Mips::R21) ||
2336 (R0 == Mips::R4 && R1 == Mips::R22) ||
2337 (R0 == Mips::R4 && R1 == Mips::R5) ||
2338 (R0 == Mips::R4 && R1 == Mips::R6) ||
2339 (R0 == Mips::R4 && R1 == Mips::R7));
2341 return Error(IDLoc,
"invalid operand for instruction");
2347 bool FillDelaySlot =
2352 bool PrevForbiddenSlotAttr = CurForbiddenSlotAttr;
2355 bool SetReorderAfterNop =
false;
2360 if (PrevForbiddenSlotAttr && !SafeInForbiddenSlot(MCID)) {
2370 if (AssemblerOptions.
back()->isReorder() && !FillDelaySlot) {
2371 SetReorderAfterNop =
true;
2380 CurForbiddenSlotAttr =
2381 hasForbiddenSlot(MCID) && AssemblerOptions.
back()->isReorder();
2383 if (FillDelaySlot || CurForbiddenSlotAttr)
2386 MacroExpanderResultTy ExpandResult =
2387 tryExpandInstruction(Inst, IDLoc, Out, STI);
2388 switch (ExpandResult) {
2390 Out.emitInstruction(Inst, *STI);
2404 if (PrevForbiddenSlotAttr && !SetReorderAfterNop && !FillDelaySlot &&
2405 AssemblerOptions.
back()->isReorder()) {
2411 if (inMicroMipsMode()) {
2426 if (FillDelaySlot) {
2431 if ((Opcode == Mips::JalOneReg || Opcode == Mips::JalTwoReg ||
2433 isPicAndNotNxxAbi()) {
2434 if (IsCpRestoreSet) {
2438 if (!AssemblerOptions.
back()->isReorder())
2445 Warning(IDLoc,
"no .cprestore used in PIC mode");
2451void MipsAsmParser::onEndOfFile() {
2452 MipsTargetStreamer &TOut = getTargetStreamer();
2453 SMLoc IDLoc = SMLoc();
2455 if (CurForbiddenSlotAttr) {
2457 if (AssemblerOptions.
back()->isReorder())
2462MipsAsmParser::MacroExpanderResultTy
2463MipsAsmParser::tryExpandInstruction(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
2464 const MCSubtargetInfo *STI) {
2467 return MER_NotAMacro;
2468 case Mips::LoadImm32:
2469 return expandLoadImm(Inst,
true, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2470 case Mips::LoadImm64:
2471 return expandLoadImm(Inst,
false, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2472 case Mips::LoadAddrImm32:
2473 case Mips::LoadAddrImm64:
2476 "expected immediate operand kind");
2478 return expandLoadAddress(
2480 Inst.
getOpcode() == Mips::LoadAddrImm32, IDLoc, Out, STI)
2483 case Mips::LoadAddrReg32:
2484 case Mips::LoadAddrReg64:
2488 "expected immediate operand kind");
2492 Inst.
getOpcode() == Mips::LoadAddrReg32, IDLoc,
2496 case Mips::B_MM_Pseudo:
2497 case Mips::B_MMR6_Pseudo:
2498 return expandUncondBranchMMPseudo(Inst, IDLoc, Out, STI) ? MER_Fail
2502 return expandLoadStoreMultiple(Inst, IDLoc, Out, STI) ? MER_Fail
2504 case Mips::JalOneReg:
2505 case Mips::JalTwoReg:
2506 return expandJalWithRegs(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2509 case Mips::BEQLImmMacro:
2510 case Mips::BNELImmMacro:
2511 return expandBranchImm(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2528 case Mips::BLTImmMacro:
2529 case Mips::BLEImmMacro:
2530 case Mips::BGEImmMacro:
2531 case Mips::BGTImmMacro:
2532 case Mips::BLTUImmMacro:
2533 case Mips::BLEUImmMacro:
2534 case Mips::BGEUImmMacro:
2535 case Mips::BGTUImmMacro:
2536 case Mips::BLTLImmMacro:
2537 case Mips::BLELImmMacro:
2538 case Mips::BGELImmMacro:
2539 case Mips::BGTLImmMacro:
2540 case Mips::BLTULImmMacro:
2541 case Mips::BLEULImmMacro:
2542 case Mips::BGEULImmMacro:
2543 case Mips::BGTULImmMacro:
2544 return expandCondBranches(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2545 case Mips::SDivMacro:
2546 case Mips::SDivIMacro:
2547 case Mips::SRemMacro:
2548 case Mips::SRemIMacro:
2549 return expandDivRem(Inst, IDLoc, Out, STI,
false,
true) ? MER_Fail
2551 case Mips::DSDivMacro:
2552 case Mips::DSDivIMacro:
2553 case Mips::DSRemMacro:
2554 case Mips::DSRemIMacro:
2555 return expandDivRem(Inst, IDLoc, Out, STI,
true,
true) ? MER_Fail
2557 case Mips::UDivMacro:
2558 case Mips::UDivIMacro:
2559 case Mips::URemMacro:
2560 case Mips::URemIMacro:
2561 return expandDivRem(Inst, IDLoc, Out, STI,
false,
false) ? MER_Fail
2563 case Mips::DUDivMacro:
2564 case Mips::DUDivIMacro:
2565 case Mips::DURemMacro:
2566 case Mips::DURemIMacro:
2567 return expandDivRem(Inst, IDLoc, Out, STI,
true,
false) ? MER_Fail
2569 case Mips::PseudoTRUNC_W_S:
2570 return expandTrunc(Inst,
false,
false, IDLoc, Out, STI) ? MER_Fail
2572 case Mips::PseudoTRUNC_W_D32:
2573 return expandTrunc(Inst,
true,
false, IDLoc, Out, STI) ? MER_Fail
2575 case Mips::PseudoTRUNC_W_D:
2576 return expandTrunc(Inst,
true,
true, IDLoc, Out, STI) ? MER_Fail
2579 case Mips::LoadImmSingleGPR:
2580 return expandLoadSingleImmToGPR(Inst, IDLoc, Out, STI) ? MER_Fail
2582 case Mips::LoadImmSingleFGR:
2583 return expandLoadSingleImmToFPR(Inst, IDLoc, Out, STI) ? MER_Fail
2585 case Mips::LoadImmDoubleGPR:
2586 return expandLoadDoubleImmToGPR(Inst, IDLoc, Out, STI) ? MER_Fail
2588 case Mips::LoadImmDoubleFGR:
2589 return expandLoadDoubleImmToFPR(Inst,
true, IDLoc, Out, STI) ? MER_Fail
2591 case Mips::LoadImmDoubleFGR_32:
2592 return expandLoadDoubleImmToFPR(Inst,
false, IDLoc, Out, STI) ? MER_Fail
2596 return expandUlh(Inst,
true, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2598 return expandUlh(Inst,
false, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2600 return expandUsh(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2603 return expandUxw(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2605 case Mips::NORImm64:
2606 return expandAliasImmediate(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2609 return expandSge(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2612 case Mips::SGEImm64:
2613 case Mips::SGEUImm64:
2614 return expandSgeImm(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2617 case Mips::SGTImm64:
2618 case Mips::SGTUImm64:
2619 return expandSgtImm(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2622 return expandSle(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2625 case Mips::SLEImm64:
2626 case Mips::SLEUImm64:
2627 return expandSleImm(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2628 case Mips::SLTImm64:
2631 return MER_NotAMacro;
2633 return expandAliasImmediate(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2634 case Mips::SLTUImm64:
2637 return MER_NotAMacro;
2639 return expandAliasImmediate(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2640 case Mips::ADDi:
case Mips::ADDi_MM:
2641 case Mips::ADDiu:
case Mips::ADDiu_MM:
2642 case Mips::SLTi:
case Mips::SLTi_MM:
2643 case Mips::SLTiu:
case Mips::SLTiu_MM:
2648 return MER_NotAMacro;
2649 return expandAliasImmediate(Inst, IDLoc, Out, STI) ? MER_Fail
2652 return MER_NotAMacro;
2653 case Mips::ANDi:
case Mips::ANDi_MM:
case Mips::ANDi64:
2654 case Mips::ORi:
case Mips::ORi_MM:
case Mips::ORi64:
2655 case Mips::XORi:
case Mips::XORi_MM:
case Mips::XORi64:
2660 return MER_NotAMacro;
2661 return expandAliasImmediate(Inst, IDLoc, Out, STI) ? MER_Fail
2664 return MER_NotAMacro;
2667 return expandRotation(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2670 return expandRotationImm(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2673 return expandDRotation(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2676 return expandDRotationImm(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2677 case Mips::ABSMacro:
2678 return expandAbs(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2679 case Mips::MULImmMacro:
2680 case Mips::DMULImmMacro:
2681 return expandMulImm(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2682 case Mips::MULOMacro:
2683 case Mips::DMULOMacro:
2684 return expandMulO(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2685 case Mips::MULOUMacro:
2686 case Mips::DMULOUMacro:
2687 return expandMulOU(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2688 case Mips::DMULMacro:
2689 return expandDMULMacro(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2692 return expandLoadStoreDMacro(Inst, IDLoc, Out, STI,
2697 return expandStoreDM1Macro(Inst, IDLoc, Out, STI)
2700 case Mips::SEQMacro:
2701 return expandSeq(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2702 case Mips::SEQIMacro:
2703 return expandSeqI(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2704 case Mips::SNEMacro:
2705 return expandSne(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2706 case Mips::SNEIMacro:
2707 return expandSneI(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2708 case Mips::MFTGPR:
case Mips::MTTGPR:
2709 case Mips::MFTLO:
case Mips::MTTLO:
2710 case Mips::MFTHI:
case Mips::MTTHI:
2711 case Mips::MFTACX:
case Mips::MTTACX:
2712 case Mips::MFTDSP:
case Mips::MTTDSP:
2713 case Mips::MFTC1:
case Mips::MTTC1:
2714 case Mips::MFTHC1:
case Mips::MTTHC1:
2715 case Mips::CFTC1:
case Mips::CTTC1:
2716 return expandMXTRAlias(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2718 case Mips::SaadAddr:
2719 return expandSaaAddr(Inst, IDLoc, Out, STI) ? MER_Fail : MER_Success;
2723bool MipsAsmParser::expandJalWithRegs(MCInst &Inst, SMLoc IDLoc,
2725 const MCSubtargetInfo *STI) {
2726 MipsTargetStreamer &TOut = getTargetStreamer();
2731 const MCOperand FirstRegOp = Inst.
getOperand(0);
2732 const unsigned Opcode = Inst.
getOpcode();
2734 if (Opcode == Mips::JalOneReg) {
2736 if (IsCpRestoreSet && inMicroMipsMode()) {
2739 }
else if (inMicroMipsMode()) {
2740 JalrInst.
setOpcode(hasMips32r6() ? Mips::JALRC16_MMR6 : Mips::JALR16_MM);
2747 }
else if (Opcode == Mips::JalTwoReg) {
2749 if (IsCpRestoreSet && inMicroMipsMode())
2752 JalrInst.
setOpcode(inMicroMipsMode() ? Mips::JALR_MM : Mips::JALR);
2754 const MCOperand SecondRegOp = Inst.
getOperand(1);
2757 Out.emitInstruction(JalrInst, *STI);
2761 const MCInstrDesc &MCID = MII.get(JalrInst.
getOpcode());
2784bool MipsAsmParser::loadImmediate(int64_t ImmValue, MCRegister DstReg,
2785 MCRegister SrcReg,
bool Is32BitImm,
2786 bool IsAddress, SMLoc IDLoc, MCStreamer &Out,
2787 const MCSubtargetInfo *STI) {
2788 MipsTargetStreamer &TOut = getTargetStreamer();
2790 if (!Is32BitImm && !isGP64bit()) {
2791 Error(IDLoc,
"instruction requires a 64-bit architecture");
2802 Error(IDLoc,
"instruction requires a 32-bit immediate");
2807 MCRegister ZeroReg = IsAddress ?
ABI.GetNullPtr() :
ABI.GetZeroReg();
2808 unsigned AdduOp = !Is32BitImm ? Mips::DADDu : Mips::ADDu;
2810 bool UseSrcReg =
false;
2814 MCRegister TmpReg = DstReg;
2816 getContext().getRegisterInfo()->isSuperOrSubRegisterEq(DstReg, SrcReg)) {
2819 MCRegister ATReg = getATReg(IDLoc);
2832 if (IsAddress && !Is32BitImm) {
2833 TOut.
emitRRI(Mips::DADDiu, DstReg, SrcReg, ImmValue, IDLoc, STI);
2837 TOut.
emitRRI(Mips::ADDiu, DstReg, SrcReg, ImmValue, IDLoc, STI);
2842 MCRegister TmpReg = DstReg;
2843 if (SrcReg == DstReg) {
2844 TmpReg = getATReg(IDLoc);
2849 TOut.
emitRRI(Mips::ORi, TmpReg, ZeroReg, ImmValue, IDLoc, STI);
2851 TOut.
emitRRR(
ABI.GetPtrAdduOp(), DstReg, TmpReg, SrcReg, IDLoc, STI);
2856 warnIfNoMacro(IDLoc);
2858 uint16_t Bits31To16 = (ImmValue >> 16) & 0xffff;
2859 uint16_t Bits15To0 = ImmValue & 0xffff;
2860 if (!Is32BitImm && !
isInt<32>(ImmValue)) {
2863 if (ImmValue == 0xffffffff) {
2864 TOut.
emitRI(Mips::LUi, TmpReg, 0xffff, IDLoc, STI);
2865 TOut.
emitRRI(Mips::DSRL32, TmpReg, TmpReg, 0, IDLoc, STI);
2867 TOut.
emitRRR(AdduOp, DstReg, TmpReg, SrcReg, IDLoc, STI);
2873 TOut.
emitRRI(Mips::ORi, TmpReg, ZeroReg, Bits31To16, IDLoc, STI);
2874 TOut.
emitRRI(Mips::DSLL, TmpReg, TmpReg, 16, IDLoc, STI);
2876 TOut.
emitRRI(Mips::ORi, TmpReg, TmpReg, Bits15To0, IDLoc, STI);
2878 TOut.
emitRRR(AdduOp, DstReg, TmpReg, SrcReg, IDLoc, STI);
2882 TOut.
emitRI(Mips::LUi, TmpReg, Bits31To16, IDLoc, STI);
2884 TOut.
emitRRI(Mips::ORi, TmpReg, TmpReg, Bits15To0, IDLoc, STI);
2886 TOut.
emitRRR(AdduOp, DstReg, TmpReg, SrcReg, IDLoc, STI);
2892 Error(IDLoc,
"instruction requires a 32-bit immediate");
2899 assert(
BitWidth >= 17 &&
"ImmValue must be at least 17-bit wide");
2903 unsigned ShiftAmount =
BitWidth - 16;
2904 uint16_t
Bits = (ImmValue >> ShiftAmount) & 0xffff;
2905 TOut.
emitRRI(Mips::ORi, TmpReg, ZeroReg, Bits, IDLoc, STI);
2906 TOut.
emitRRI(Mips::DSLL, TmpReg, TmpReg, ShiftAmount, IDLoc, STI);
2909 TOut.
emitRRR(AdduOp, DstReg, TmpReg, SrcReg, IDLoc, STI);
2914 warnIfNoMacro(IDLoc);
2921 if (loadImmediate(ImmValue >> 32, TmpReg, MCRegister(),
true,
false, IDLoc,
2927 unsigned ShiftCarriedForwards = 16;
2928 for (
int BitNum = 16; BitNum >= 0; BitNum -= 16) {
2929 uint16_t ImmChunk = (ImmValue >> BitNum) & 0xffff;
2931 if (ImmChunk != 0) {
2932 TOut.
emitDSLL(TmpReg, TmpReg, ShiftCarriedForwards, IDLoc, STI);
2933 TOut.
emitRRI(Mips::ORi, TmpReg, TmpReg, ImmChunk, IDLoc, STI);
2934 ShiftCarriedForwards = 0;
2937 ShiftCarriedForwards += 16;
2939 ShiftCarriedForwards -= 16;
2942 if (ShiftCarriedForwards)
2943 TOut.
emitDSLL(TmpReg, TmpReg, ShiftCarriedForwards, IDLoc, STI);
2946 TOut.
emitRRR(AdduOp, DstReg, TmpReg, SrcReg, IDLoc, STI);
2951bool MipsAsmParser::expandLoadImm(MCInst &Inst,
bool Is32BitImm, SMLoc IDLoc,
2952 MCStreamer &Out,
const MCSubtargetInfo *STI) {
2954 assert(ImmOp.
isImm() &&
"expected immediate operand kind");
2955 const MCOperand &DstRegOp = Inst.
getOperand(0);
2956 assert(DstRegOp.
isReg() &&
"expected register operand kind");
2958 if (loadImmediate(ImmOp.
getImm(), DstRegOp.
getReg(), MCRegister(), Is32BitImm,
2959 false, IDLoc, Out, STI))
2965bool MipsAsmParser::expandLoadAddress(MCRegister DstReg, MCRegister BaseReg,
2967 bool Is32BitAddress, SMLoc IDLoc,
2969 const MCSubtargetInfo *STI) {
2971 if (Is32BitAddress &&
ABI.ArePtrs64bit()) {
2972 Warning(IDLoc,
"la used to load 64-bit address");
2974 Is32BitAddress =
false;
2978 if (!Is32BitAddress && !hasMips3()) {
2979 Error(IDLoc,
"instruction requires a 64-bit architecture");
2984 return loadAndAddSymbolAddress(
Offset.getExpr(), DstReg, BaseReg,
2985 Is32BitAddress, IDLoc, Out, STI);
2987 if (!
ABI.ArePtrs64bit()) {
2989 Is32BitAddress =
true;
2992 return loadImmediate(
Offset.getImm(), DstReg, BaseReg, Is32BitAddress,
true,
2996bool MipsAsmParser::loadAndAddSymbolAddress(
const MCExpr *SymExpr,
2998 MCRegister SrcReg,
bool Is32BitSym,
2999 SMLoc IDLoc, MCStreamer &Out,
3000 const MCSubtargetInfo *STI) {
3001 MipsTargetStreamer &TOut = getTargetStreamer();
3003 SrcReg.
isValid() && SrcReg != Mips::R0 && SrcReg != Mips::R0_64;
3004 warnIfNoMacro(IDLoc);
3009 Error(IDLoc,
"expected relocatable expression");
3013 Error(IDLoc,
"expected relocatable expression with only one symbol");
3017 bool IsPtr64 =
ABI.ArePtrs64bit();
3020 ?
static_cast<const MCSymbolELF *
>(Res.
getAddSym())
3028 bool UseXGOT = STI->
hasFeature(Mips::FeatureXGOT) && !IsLocalSym;
3034 if ((DstReg ==
getABI().getTempReg(9,
false) ||
3035 DstReg ==
getABI().getTempReg(9,
true)) &&
3036 !UseSrcReg && Res.
getConstant() == 0 && !IsLocalSym) {
3038 const MCExpr *CallHiExpr =
3040 const MCExpr *CallLoExpr =
3044 TOut.
emitRRR(IsPtr64 ? Mips::DADDu : Mips::ADDu, DstReg, DstReg, GPReg,
3046 TOut.
emitRRX(IsPtr64 ? Mips::LD : Mips::LW, DstReg, DstReg,
3049 const MCExpr *CallExpr =
3051 TOut.
emitRRX(IsPtr64 ? Mips::LD : Mips::LW, DstReg, GPReg,
3057 MCRegister TmpReg = DstReg;
3059 getContext().getRegisterInfo()->isSuperOrSubRegisterEq(DstReg,
3063 MCRegister ATReg = getATReg(IDLoc);
3082 const MCExpr *CallHiExpr =
3089 TOut.
emitRRR(IsPtr64 ? Mips::DADDu : Mips::ADDu, TmpReg, TmpReg, GPReg,
3091 TOut.
emitRRX(IsPtr64 ? Mips::LD : Mips::LW, TmpReg, TmpReg,
3095 TOut.
emitRRX(IsPtr64 ? Mips::DADDiu : Mips::ADDiu, TmpReg, TmpReg,
3101 TOut.
emitRRR(IsPtr64 ? Mips::DADDu : Mips::ADDu, DstReg, TmpReg, SrcReg,
3106 const MCSpecifierExpr *GotExpr =
nullptr;
3107 const MCExpr *LoExpr =
nullptr;
3108 if (
ABI.IsN32() ||
ABI.IsN64()) {
3127 Error(IDLoc,
"macro instruction uses large offset, which is not "
3128 "currently supported");
3157 TOut.
emitRRX(IsPtr64 ? Mips::LD : Mips::LW, TmpReg, GPReg,
3161 TOut.
emitRRX(IsPtr64 ? Mips::DADDiu : Mips::ADDiu, TmpReg, TmpReg,
3165 TOut.
emitRRR(IsPtr64 ? Mips::DADDu : Mips::ADDu, DstReg, TmpReg, SrcReg,
3171 const auto *HiExpr =
3173 const auto *LoExpr =
3177 if (
ABI.ArePtrs64bit() && isGP64bit()) {
3185 const auto *HighestExpr =
3187 const auto *HigherExpr =
3192 getContext().getRegisterInfo()->isSuperOrSubRegisterEq(DstReg, SrcReg);
3194 if (canUseATReg() && UseSrcReg && RdRegIsRsReg) {
3195 MCRegister ATReg = getATReg(IDLoc);
3207 TOut.
emitRRX(Mips::DADDiu, ATReg, ATReg,
3209 TOut.
emitRRI(Mips::DSLL, ATReg, ATReg, 16, IDLoc, STI);
3212 TOut.
emitRRI(Mips::DSLL, ATReg, ATReg, 16, IDLoc, STI);
3215 TOut.
emitRRR(Mips::DADDu, DstReg, ATReg, SrcReg, IDLoc, STI);
3218 }
else if (canUseATReg() && !RdRegIsRsReg && DstReg != getATReg(IDLoc)) {
3219 MCRegister ATReg = getATReg(IDLoc);
3235 TOut.
emitRRX(Mips::DADDiu, DstReg, DstReg,
3239 TOut.
emitRRI(Mips::DSLL32, DstReg, DstReg, 0, IDLoc, STI);
3240 TOut.
emitRRR(Mips::DADDu, DstReg, DstReg, ATReg, IDLoc, STI);
3242 TOut.
emitRRR(Mips::DADDu, DstReg, DstReg, SrcReg, IDLoc, STI);
3245 }
else if ((!canUseATReg() && !RdRegIsRsReg) ||
3246 (canUseATReg() && DstReg == getATReg(IDLoc))) {
3257 TOut.
emitRRX(Mips::DADDiu, DstReg, DstReg,
3259 TOut.
emitRRI(Mips::DSLL, DstReg, DstReg, 16, IDLoc, STI);
3260 TOut.
emitRRX(Mips::DADDiu, DstReg, DstReg,
3262 TOut.
emitRRI(Mips::DSLL, DstReg, DstReg, 16, IDLoc, STI);
3263 TOut.
emitRRX(Mips::DADDiu, DstReg, DstReg,
3266 TOut.
emitRRR(Mips::DADDu, DstReg, DstReg, SrcReg, IDLoc, STI);
3272 assert(SrcReg == DstReg && !canUseATReg() &&
3273 "Could have expanded dla but didn't?");
3274 reportParseError(IDLoc,
3275 "pseudo-instruction requires $at, which is not available");
3289 MCRegister TmpReg = DstReg;
3291 getContext().getRegisterInfo()->isSuperOrSubRegisterEq(DstReg, SrcReg)) {
3294 MCRegister ATReg = getATReg(IDLoc);
3305 TOut.
emitRRR(Mips::ADDu, DstReg, TmpReg, SrcReg, IDLoc, STI);
3308 getContext().getRegisterInfo()->isSuperOrSubRegisterEq(DstReg, TmpReg));
3317 if (getMipsMCRegisterClass(Mips::FGR32RegClassID).
contains(
Reg))
3318 return Reg == (
unsigned)Mips::F31 ? (
unsigned)Mips::F0 :
Reg + 1;
3320 default:
llvm_unreachable(
"Unknown register in assembly macro expansion!");
3385 case Mips::D0:
return Mips::F1;
3386 case Mips::D1:
return Mips::F3;
3387 case Mips::D2:
return Mips::F5;
3388 case Mips::D3:
return Mips::F7;
3389 case Mips::D4:
return Mips::F9;
3390 case Mips::D5:
return Mips::F11;
3391 case Mips::D6:
return Mips::F13;
3392 case Mips::D7:
return Mips::F15;
3393 case Mips::D8:
return Mips::F17;
3394 case Mips::D9:
return Mips::F19;
3416bool MipsAsmParser::emitPartialAddress(MipsTargetStreamer &TOut, SMLoc IDLoc,
3418 MCRegister ATReg = getATReg(IDLoc);
3424 const auto *GotExpr =
3427 if(isABI_O32() || isABI_N32()) {
3436 const auto *HiExpr =
3445 if(isABI_O32() || isABI_N32()) {
3449 const auto *HighestExpr =
3452 const auto *HigherExpr =
3457 TOut.
emitRRX(Mips::DADDiu, ATReg, ATReg,
3459 TOut.
emitRRI(Mips::DSLL, ATReg, ATReg, 16, IDLoc, STI);
3462 TOut.
emitRRI(Mips::DSLL, ATReg, ATReg, 16, IDLoc, STI);
3471 if ((
Hi_32(ImmOp64) & 0x7ff00000) == 0) {
3482 float TmpFloat =
static_cast<float>(DoubleImm);
3486bool MipsAsmParser::expandLoadSingleImmToGPR(MCInst &Inst, SMLoc IDLoc,
3488 const MCSubtargetInfo *STI) {
3491 "Invalid instruction operand.");
3498 return loadImmediate(ImmOp32, FirstReg, MCRegister(),
true,
false, IDLoc, Out,
3502bool MipsAsmParser::expandLoadSingleImmToFPR(MCInst &Inst, SMLoc IDLoc,
3504 const MCSubtargetInfo *STI) {
3505 MipsTargetStreamer &TOut = getTargetStreamer();
3508 "Invalid instruction operand.");
3517 MCRegister TmpReg = Mips::R0;
3519 TmpReg = getATReg(IDLoc);
3524 if (
Lo_32(ImmOp64) == 0) {
3525 if (TmpReg != Mips::R0 && loadImmediate(ImmOp32, TmpReg, MCRegister(),
true,
3526 false, IDLoc, Out, STI))
3528 TOut.
emitRR(Mips::MTC1, FirstReg, TmpReg, IDLoc, STI);
3532 MCSection *CS = getStreamer().getCurrentSectionOnly();
3535 MCSection *ReadOnlySection =
3542 getStreamer().switchSection(ReadOnlySection);
3543 getStreamer().emitLabel(Sym, IDLoc);
3544 getStreamer().emitInt32(ImmOp32);
3545 getStreamer().switchSection(CS);
3547 if (emitPartialAddress(TOut, IDLoc, Sym))
3554bool MipsAsmParser::expandLoadDoubleImmToGPR(MCInst &Inst, SMLoc IDLoc,
3556 const MCSubtargetInfo *STI) {
3557 MipsTargetStreamer &TOut = getTargetStreamer();
3560 "Invalid instruction operand.");
3567 if (
Lo_32(ImmOp64) == 0) {
3569 if (loadImmediate(ImmOp64, FirstReg, MCRegister(),
false,
false, IDLoc,
3573 if (loadImmediate(
Hi_32(ImmOp64), FirstReg, MCRegister(),
true,
false,
3577 if (loadImmediate(0,
nextReg(FirstReg), MCRegister(),
true,
false, IDLoc,
3584 MCSection *CS = getStreamer().getCurrentSectionOnly();
3585 MCSection *ReadOnlySection =
3592 getStreamer().switchSection(ReadOnlySection);
3593 getStreamer().emitLabel(Sym, IDLoc);
3594 getStreamer().emitValueToAlignment(
Align(8));
3595 getStreamer().emitIntValue(ImmOp64, 8);
3596 getStreamer().switchSection(CS);
3598 MCRegister TmpReg = getATReg(IDLoc);
3602 if (emitPartialAddress(TOut, IDLoc, Sym))
3605 TOut.
emitRRX(isABI_N64() ? Mips::DADDiu : Mips::ADDiu, TmpReg, TmpReg,
3609 TOut.
emitRRI(Mips::LD, FirstReg, TmpReg, 0, IDLoc, STI);
3611 TOut.
emitRRI(Mips::LW, FirstReg, TmpReg, 0, IDLoc, STI);
3612 TOut.
emitRRI(Mips::LW,
nextReg(FirstReg), TmpReg, 4, IDLoc, STI);
3617bool MipsAsmParser::expandLoadDoubleImmToFPR(MCInst &Inst,
bool Is64FPU,
3618 SMLoc IDLoc, MCStreamer &Out,
3619 const MCSubtargetInfo *STI) {
3620 MipsTargetStreamer &TOut = getTargetStreamer();
3623 "Invalid instruction operand.");
3630 MCRegister TmpReg = Mips::R0;
3632 TmpReg = getATReg(IDLoc);
3637 if ((
Lo_32(ImmOp64) == 0) &&
3638 !((
Hi_32(ImmOp64) & 0xffff0000) && (
Hi_32(ImmOp64) & 0x0000ffff))) {
3640 if (TmpReg != Mips::R0 && loadImmediate(ImmOp64, TmpReg, MCRegister(),
3641 false,
false, IDLoc, Out, STI))
3643 TOut.
emitRR(Mips::DMTC1, FirstReg, TmpReg, IDLoc, STI);
3647 if (TmpReg != Mips::R0 &&
3648 loadImmediate(
Hi_32(ImmOp64), TmpReg, MCRegister(),
true,
false, IDLoc,
3652 if (hasMips32r2()) {
3653 TOut.
emitRR(Mips::MTC1, FirstReg, Mips::R0, IDLoc, STI);
3654 TOut.
emitRRR(Mips::MTHC1_D32, FirstReg, FirstReg, TmpReg, IDLoc, STI);
3656 TOut.
emitRR(Mips::MTC1,
nextReg(FirstReg), TmpReg, IDLoc, STI);
3657 TOut.
emitRR(Mips::MTC1, FirstReg, Mips::R0, IDLoc, STI);
3662 MCSection *CS = getStreamer().getCurrentSectionOnly();
3665 MCSection *ReadOnlySection =
3672 getStreamer().switchSection(ReadOnlySection);
3673 getStreamer().emitLabel(Sym, IDLoc);
3674 getStreamer().emitValueToAlignment(
Align(8));
3675 getStreamer().emitIntValue(ImmOp64, 8);
3676 getStreamer().switchSection(CS);
3678 if (emitPartialAddress(TOut, IDLoc, Sym))
3681 TOut.
emitRRX(Is64FPU ? Mips::LDC164 : Mips::LDC1, FirstReg, TmpReg,
3687bool MipsAsmParser::expandUncondBranchMMPseudo(MCInst &Inst, SMLoc IDLoc,
3689 const MCSubtargetInfo *STI) {
3690 MipsTargetStreamer &TOut = getTargetStreamer();
3693 "unexpected number of operands");
3703 assert(
Offset.isImm() &&
"expected immediate operand kind");
3707 if (inMicroMipsMode())
3708 Inst.
setOpcode(hasMips32r6() ? Mips::BC16_MMR6 : Mips::B16_MM);
3711 return Error(IDLoc,
"branch target out of range");
3713 return Error(IDLoc,
"branch to misaligned address");
3721 Out.emitInstruction(Inst, *STI);
3725 const MCInstrDesc &MCID = MII.get(Inst.
getOpcode());
3732bool MipsAsmParser::expandBranchImm(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
3733 const MCSubtargetInfo *STI) {
3734 MipsTargetStreamer &TOut = getTargetStreamer();
3735 const MCOperand &DstRegOp = Inst.
getOperand(0);
3736 assert(DstRegOp.
isReg() &&
"expected register operand kind");
3739 assert(ImmOp.
isImm() &&
"expected immediate operand kind");
3741 const MCOperand &MemOffsetOp = Inst.
getOperand(2);
3743 "expected immediate or expression operand");
3745 bool IsLikely =
false;
3755 case Mips::BEQLImmMacro:
3759 case Mips::BNELImmMacro:
3768 int64_t ImmValue = ImmOp.
getImm();
3769 if (ImmValue == 0) {
3773 TOut.
emitRRI(Mips::SLL, Mips::R0, Mips::R0, 0, IDLoc, STI);
3775 TOut.
emitRRX(OpCode, DstRegOp.
getReg(), Mips::R0, MemOffsetOp, IDLoc,
3778 warnIfNoMacro(IDLoc);
3780 MCRegister ATReg = getATReg(IDLoc);
3784 if (loadImmediate(ImmValue, ATReg, MCRegister(), !isGP64bit(),
true, IDLoc,
3788 if (IsLikely && MemOffsetOp.
isExpr()) {
3791 TOut.
emitRRI(Mips::SLL, Mips::R0, Mips::R0, 0, IDLoc, STI);
3793 TOut.
emitRRX(OpCode, DstRegOp.
getReg(), ATReg, MemOffsetOp, IDLoc, STI);
3798void MipsAsmParser::expandMem16Inst(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
3799 const MCSubtargetInfo *STI,
bool IsLoad) {
3801 assert((NumOp == 3 || NumOp == 4) &&
"unexpected operands number");
3802 unsigned StartOp = NumOp == 3 ? 0 : 1;
3804 const MCOperand &DstRegOp = Inst.
getOperand(StartOp);
3805 assert(DstRegOp.
isReg() &&
"expected register operand kind");
3806 const MCOperand &BaseRegOp = Inst.
getOperand(StartOp + 1);
3807 assert(BaseRegOp.
isReg() &&
"expected register operand kind");
3810 MipsTargetStreamer &TOut = getTargetStreamer();
3812 MCRegister DstReg = DstRegOp.
getReg();
3814 MCRegister TmpReg = DstReg;
3816 const MCInstrDesc &
Desc = MII.get(OpCode);
3817 int16_t DstRegClass =
3818 MII.getOpRegClassID(
Desc.operands()[StartOp],
3820 unsigned DstRegClassID =
3821 getContext().getRegisterInfo()->getRegClass(DstRegClass).getID();
3822 bool IsGPR = (DstRegClassID == Mips::GPR32RegClassID) ||
3823 (DstRegClassID == Mips::GPR64RegClassID);
3825 if (!IsLoad || !IsGPR || (BaseReg == DstReg)) {
3828 TmpReg = getATReg(IDLoc);
3833 auto emitInstWithOffset = [&](
const MCOperand &
Off) {
3835 TOut.
emitRRX(OpCode, DstReg, TmpReg,
Off, IDLoc, STI);
3837 TOut.
emitRRRX(OpCode, DstReg, DstReg, TmpReg,
Off, IDLoc, STI);
3841 int64_t LoOffset =
OffsetOp.getImm() & 0xffff;
3842 int64_t HiOffset =
OffsetOp.getImm() & ~0xffff;
3846 if (LoOffset & 0x8000)
3847 HiOffset += 0x10000;
3849 bool IsLargeOffset = HiOffset != 0;
3851 if (IsLargeOffset) {
3853 if (loadImmediate(HiOffset, TmpReg, MCRegister(), Is32BitImm,
true, IDLoc,
3858 if (BaseReg != Mips::R0 && BaseReg != Mips::R0_64)
3859 TOut.
emitRRR(
ABI.ArePtrs64bit() ? Mips::DADDu : Mips::ADDu, TmpReg,
3860 TmpReg, BaseReg, IDLoc, STI);
3874 if (!
OffsetOp.getExpr()->evaluateAsRelocatable(Res,
nullptr)) {
3875 Error(IDLoc,
"expected relocatable expression");
3879 Error(IDLoc,
"expected relocatable expression with only one symbol");
3883 loadAndAddSymbolAddress(
3885 BaseReg, !
ABI.ArePtrs64bit(), IDLoc, Out, STI);
3893 const MCExpr *OffExpr =
OffsetOp.getExpr();
3905 TOut.
emitRX(Mips::LUi, TmpReg, HighestOperand, IDLoc, STI);
3906 TOut.
emitRRX(Mips::DADDiu, TmpReg, TmpReg, HigherOperand, IDLoc, STI);
3907 TOut.
emitRRI(Mips::DSLL, TmpReg, TmpReg, 16, IDLoc, STI);
3908 TOut.
emitRRX(Mips::DADDiu, TmpReg, TmpReg, HiOperand, IDLoc, STI);
3909 TOut.
emitRRI(Mips::DSLL, TmpReg, TmpReg, 16, IDLoc, STI);
3910 if (BaseReg != Mips::R0 && BaseReg != Mips::R0_64)
3911 TOut.
emitRRR(Mips::DADDu, TmpReg, TmpReg, BaseReg, IDLoc, STI);
3912 emitInstWithOffset(LoOperand);
3915 TOut.
emitRX(Mips::LUi, TmpReg, HiOperand, IDLoc, STI);
3916 if (BaseReg != Mips::R0)
3917 TOut.
emitRRR(Mips::ADDu, TmpReg, TmpReg, BaseReg, IDLoc, STI);
3919 emitInstWithOffset(LoOperand);
3928void MipsAsmParser::expandMem9Inst(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
3929 const MCSubtargetInfo *STI,
bool IsLoad) {
3931 assert((NumOp == 3 || NumOp == 4) &&
"unexpected operands number");
3932 unsigned StartOp = NumOp == 3 ? 0 : 1;
3934 const MCOperand &DstRegOp = Inst.
getOperand(StartOp);
3935 assert(DstRegOp.
isReg() &&
"expected register operand kind");
3936 const MCOperand &BaseRegOp = Inst.
getOperand(StartOp + 1);
3937 assert(BaseRegOp.
isReg() &&
"expected register operand kind");
3940 MipsTargetStreamer &TOut = getTargetStreamer();
3942 MCRegister DstReg = DstRegOp.
getReg();
3944 MCRegister TmpReg = DstReg;
3946 const MCInstrDesc &
Desc = MII.get(OpCode);
3947 int16_t DstRegClass =
3948 MII.getOpRegClassID(
Desc.operands()[StartOp],
3951 unsigned DstRegClassID =
3952 getContext().getRegisterInfo()->getRegClass(DstRegClass).getID();
3953 bool IsGPR = (DstRegClassID == Mips::GPR32RegClassID) ||
3954 (DstRegClassID == Mips::GPR64RegClassID);
3956 if (!IsLoad || !IsGPR || (BaseReg == DstReg)) {
3959 TmpReg = getATReg(IDLoc);
3964 auto emitInst = [&]() {
3973 loadImmediate(
OffsetOp.getImm(), TmpReg, BaseReg, !
ABI.ArePtrs64bit(),
true,
3980 loadAndAddSymbolAddress(
OffsetOp.getExpr(), TmpReg, BaseReg,
3981 !
ABI.ArePtrs64bit(), IDLoc, Out, STI);
3989bool MipsAsmParser::expandLoadStoreMultiple(MCInst &Inst, SMLoc IDLoc,
3991 const MCSubtargetInfo *STI) {
3994 unsigned NewOpcode = Opcode == Mips::SWM_MM ? Mips::SWM32_MM : Mips::LWM32_MM;
3998 Inst.
getOperand(OpNum - 3).
isReg() &&
"Invalid instruction operand.");
4007 if (inMicroMipsMode() && hasMips32r6())
4008 NewOpcode = Opcode == Mips::SWM_MM ? Mips::SWM16_MMR6 : Mips::LWM16_MMR6;
4010 NewOpcode = Opcode == Mips::SWM_MM ? Mips::SWM16_MM : Mips::LWM16_MM;
4014 Out.emitInstruction(Inst, *STI);
4018bool MipsAsmParser::expandCondBranches(MCInst &Inst, SMLoc IDLoc,
4020 const MCSubtargetInfo *STI) {
4021 MipsTargetStreamer &TOut = getTargetStreamer();
4022 bool EmittedNoMacroWarning =
false;
4023 unsigned PseudoOpcode = Inst.
getOpcode();
4028 unsigned ZeroSrcOpcode, ZeroTrgOpcode;
4029 bool ReverseOrderSLT, IsUnsigned, IsLikely, AcceptsEquality;
4034 else if (TrgOp.
isImm()) {
4035 warnIfNoMacro(IDLoc);
4036 EmittedNoMacroWarning =
true;
4038 TrgReg = getATReg(IDLoc);
4042 switch(PseudoOpcode) {
4045 case Mips::BLTImmMacro:
4046 PseudoOpcode = Mips::BLT;
4048 case Mips::BLEImmMacro:
4049 PseudoOpcode = Mips::BLE;
4051 case Mips::BGEImmMacro:
4052 PseudoOpcode = Mips::BGE;
4054 case Mips::BGTImmMacro:
4055 PseudoOpcode = Mips::BGT;
4057 case Mips::BLTUImmMacro:
4058 PseudoOpcode = Mips::BLTU;
4060 case Mips::BLEUImmMacro:
4061 PseudoOpcode = Mips::BLEU;
4063 case Mips::BGEUImmMacro:
4064 PseudoOpcode = Mips::BGEU;
4066 case Mips::BGTUImmMacro:
4067 PseudoOpcode = Mips::BGTU;
4069 case Mips::BLTLImmMacro:
4070 PseudoOpcode = Mips::BLTL;
4072 case Mips::BLELImmMacro:
4073 PseudoOpcode = Mips::BLEL;
4075 case Mips::BGELImmMacro:
4076 PseudoOpcode = Mips::BGEL;
4078 case Mips::BGTLImmMacro:
4079 PseudoOpcode = Mips::BGTL;
4081 case Mips::BLTULImmMacro:
4082 PseudoOpcode = Mips::BLTUL;
4084 case Mips::BLEULImmMacro:
4085 PseudoOpcode = Mips::BLEUL;
4087 case Mips::BGEULImmMacro:
4088 PseudoOpcode = Mips::BGEUL;
4090 case Mips::BGTULImmMacro:
4091 PseudoOpcode = Mips::BGTUL;
4095 if (loadImmediate(TrgOp.
getImm(), TrgReg, MCRegister(), !isGP64bit(),
false,
4100 switch (PseudoOpcode) {
4105 AcceptsEquality =
false;
4106 ReverseOrderSLT =
false;
4108 ((PseudoOpcode == Mips::BLTU) || (PseudoOpcode == Mips::BLTUL));
4109 IsLikely = ((PseudoOpcode == Mips::BLTL) || (PseudoOpcode == Mips::BLTUL));
4110 ZeroSrcOpcode = Mips::BGTZ;
4111 ZeroTrgOpcode = Mips::BLTZ;
4117 AcceptsEquality =
true;
4118 ReverseOrderSLT =
true;
4120 ((PseudoOpcode == Mips::BLEU) || (PseudoOpcode == Mips::BLEUL));
4121 IsLikely = ((PseudoOpcode == Mips::BLEL) || (PseudoOpcode == Mips::BLEUL));
4122 ZeroSrcOpcode = Mips::BGEZ;
4123 ZeroTrgOpcode = Mips::BLEZ;
4129 AcceptsEquality =
true;
4130 ReverseOrderSLT =
false;
4132 ((PseudoOpcode == Mips::BGEU) || (PseudoOpcode == Mips::BGEUL));
4133 IsLikely = ((PseudoOpcode == Mips::BGEL) || (PseudoOpcode == Mips::BGEUL));
4134 ZeroSrcOpcode = Mips::BLEZ;
4135 ZeroTrgOpcode = Mips::BGEZ;
4141 AcceptsEquality =
false;
4142 ReverseOrderSLT =
true;
4144 ((PseudoOpcode == Mips::BGTU) || (PseudoOpcode == Mips::BGTUL));
4145 IsLikely = ((PseudoOpcode == Mips::BGTL) || (PseudoOpcode == Mips::BGTUL));
4146 ZeroSrcOpcode = Mips::BLTZ;
4147 ZeroTrgOpcode = Mips::BGTZ;
4153 bool IsTrgRegZero = (TrgReg == Mips::R0);
4154 bool IsSrcRegZero = (SrcReg == Mips::R0);
4155 if (IsSrcRegZero && IsTrgRegZero) {
4159 if (PseudoOpcode == Mips::BLT) {
4164 if (PseudoOpcode == Mips::BLE) {
4167 Warning(IDLoc,
"branch is always taken");
4170 if (PseudoOpcode == Mips::BGE) {
4173 Warning(IDLoc,
"branch is always taken");
4176 if (PseudoOpcode == Mips::BGT) {
4181 if (PseudoOpcode == Mips::BGTU) {
4182 TOut.
emitRRX(Mips::BNE, Mips::R0, Mips::R0,
4186 if (AcceptsEquality) {
4189 TOut.
emitRRX(Mips::BEQ, Mips::R0, Mips::R0,
4191 Warning(IDLoc,
"branch is always taken");
4198 if (IsSrcRegZero || IsTrgRegZero) {
4199 if ((IsSrcRegZero && PseudoOpcode == Mips::BGTU) ||
4200 (IsTrgRegZero && PseudoOpcode == Mips::BLTU)) {
4207 if ((IsSrcRegZero && PseudoOpcode == Mips::BLEU) ||
4208 (IsTrgRegZero && PseudoOpcode == Mips::BGEU)) {
4214 TOut.
emitRRX(Mips::BEQ, Mips::R0, Mips::R0,
4216 Warning(IDLoc,
"branch is always taken");
4232 TOut.
emitRRX(AcceptsEquality ? Mips::BEQ : Mips::BNE,
4233 IsSrcRegZero ? TrgReg : SrcReg, Mips::R0,
4240 TOut.
emitRX(IsSrcRegZero ? ZeroSrcOpcode : ZeroTrgOpcode,
4241 IsSrcRegZero ? TrgReg : SrcReg,
4248 MCRegister ATRegNum = getATReg(IDLoc);
4252 if (!EmittedNoMacroWarning)
4253 warnIfNoMacro(IDLoc);
4270 TOut.
emitRRR(IsUnsigned ? Mips::SLTu : Mips::SLT, ATRegNum,
4271 ReverseOrderSLT ? TrgReg : SrcReg,
4272 ReverseOrderSLT ? SrcReg : TrgReg, IDLoc, STI);
4274 TOut.
emitRRX(IsLikely ? (AcceptsEquality ? Mips::BEQL : Mips::BNEL)
4275 : (AcceptsEquality ? Mips::BEQ : Mips::BNE),
4289bool MipsAsmParser::expandDivRem(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
4290 const MCSubtargetInfo *STI,
4291 const bool IsMips64,
const bool Signed) {
4292 MipsTargetStreamer &TOut = getTargetStreamer();
4294 warnIfNoMacro(IDLoc);
4296 const MCOperand &RdRegOp = Inst.
getOperand(0);
4297 assert(RdRegOp.
isReg() &&
"expected register operand kind");
4298 MCRegister RdReg = RdRegOp.
getReg();
4300 const MCOperand &RsRegOp = Inst.
getOperand(1);
4301 assert(RsRegOp.
isReg() &&
"expected register operand kind");
4302 MCRegister RsReg = RsRegOp.
getReg();
4309 "expected register or immediate operand kind");
4313 ImmValue = RtOp.
getImm();
4320 DivOp =
Signed ? Mips::DSDIV : Mips::DUDIV;
4321 ZeroReg = Mips::R0_64;
4324 DivOp =
Signed ? Mips::SDIV : Mips::UDIV;
4329 bool UseTraps = useTraps();
4332 bool isDiv = Opcode == Mips::SDivMacro || Opcode == Mips::SDivIMacro ||
4333 Opcode == Mips::UDivMacro || Opcode == Mips::UDivIMacro ||
4334 Opcode == Mips::DSDivMacro || Opcode == Mips::DSDivIMacro ||
4335 Opcode == Mips::DUDivMacro || Opcode == Mips::DUDivIMacro;
4337 bool isRem = Opcode == Mips::SRemMacro || Opcode == Mips::SRemIMacro ||
4338 Opcode == Mips::URemMacro || Opcode == Mips::URemIMacro ||
4339 Opcode == Mips::DSRemMacro || Opcode == Mips::DSRemIMacro ||
4340 Opcode == Mips::DURemMacro || Opcode == Mips::DURemIMacro;
4343 MCRegister ATReg = getATReg(IDLoc);
4347 if (!CLOpts.mno_check_zero_division && ImmValue == 0) {
4349 TOut.
emitRRI(Mips::TEQ, ZeroReg, ZeroReg, 0x7, IDLoc, STI);
4351 TOut.
emitII(Mips::BREAK, 0x7, 0, IDLoc, STI);
4355 if (isRem && (ImmValue == 1 || (
Signed && (ImmValue == -1)))) {
4356 TOut.
emitRRR(Mips::OR, RdReg, ZeroReg, ZeroReg, IDLoc, STI);
4358 }
else if (isDiv && ImmValue == 1) {
4359 TOut.
emitRRR(Mips::OR, RdReg, RsReg, Mips::R0, IDLoc, STI);
4361 }
else if (isDiv &&
Signed && ImmValue == -1) {
4362 TOut.
emitRRR(SubOp, RdReg, ZeroReg, RsReg, IDLoc, STI);
4365 if (loadImmediate(ImmValue, ATReg, MCRegister(),
isInt<32>(ImmValue),
4366 false, Inst.
getLoc(), Out, STI))
4368 TOut.
emitRR(DivOp, RsReg, ATReg, IDLoc, STI);
4369 TOut.
emitR(isDiv ? Mips::MFLO : Mips::MFHI, RdReg, IDLoc, STI);
4379 if (!CLOpts.mno_check_zero_division &&
4380 (RtReg == Mips::R0 || RtReg == Mips::R0_64)) {
4382 TOut.
emitRRI(Mips::TEQ, ZeroReg, ZeroReg, 0x7, IDLoc, STI);
4385 TOut.
emitII(Mips::BREAK, 0x7, 0, IDLoc, STI);
4391 if (isRem && (RdReg == Mips::R0 || RdReg == Mips::R0_64)) {
4392 TOut.
emitRR(DivOp, RsReg, RtReg, IDLoc, STI);
4401 TOut.
emitRR(DivOp, RsReg, RtReg, IDLoc, STI);
4402 if (!CLOpts.mno_check_zero_division) {
4404 TOut.
emitRRI(Mips::TEQ, RtReg, ZeroReg, 0x7, IDLoc, STI);
4407 BrTarget =
Context.createTempSymbol();
4410 TOut.
emitRRX(Mips::BNE, RtReg, ZeroReg, LabelOp, IDLoc, STI);
4415 TOut.
emitII(Mips::BREAK, 0x7, 0, IDLoc, STI);
4421 TOut.
emitR(isDiv ? Mips::MFLO : Mips::MFHI, RdReg, IDLoc, STI);
4425bool MipsAsmParser::expandTrunc(MCInst &Inst,
bool IsDouble,
bool Is64FPU,
4426 SMLoc IDLoc, MCStreamer &Out,
4427 const MCSubtargetInfo *STI) {
4428 MipsTargetStreamer &TOut = getTargetStreamer();
4438 if (hasMips1() && !hasMips2()) {
4439 MCRegister ATReg = getATReg(IDLoc);
4445 TOut.
emitRRI(Mips::ORi, ATReg, ThirdReg, 0x3, IDLoc, STI);
4446 TOut.
emitRRI(Mips::XORi, ATReg, ATReg, 0x2, IDLoc, STI);
4449 TOut.
emitRR(IsDouble ? (Is64FPU ? Mips::CVT_W_D64 : Mips::CVT_W_D32)
4451 FirstReg, SecondReg, IDLoc, STI);
4457 TOut.
emitRR(IsDouble ? (Is64FPU ? Mips::TRUNC_W_D64 : Mips::TRUNC_W_D32)
4459 FirstReg, SecondReg, IDLoc, STI);
4464bool MipsAsmParser::expandUlh(MCInst &Inst,
bool Signed, SMLoc IDLoc,
4465 MCStreamer &Out,
const MCSubtargetInfo *STI) {
4466 if (hasMips32r6() || hasMips64r6()) {
4467 return Error(IDLoc,
"instruction not supported on mips32r6 or mips64r6");
4470 const MCOperand &DstRegOp = Inst.
getOperand(0);
4471 assert(DstRegOp.
isReg() &&
"expected register operand kind");
4472 const MCOperand &SrcRegOp = Inst.
getOperand(1);
4473 assert(SrcRegOp.
isReg() &&
"expected register operand kind");
4474 const MCOperand &OffsetImmOp = Inst.
getOperand(2);
4475 assert(OffsetImmOp.
isImm() &&
"expected immediate operand kind");
4477 MipsTargetStreamer &TOut = getTargetStreamer();
4478 MCRegister DstReg = DstRegOp.
getReg();
4479 MCRegister SrcReg = SrcRegOp.
getReg();
4480 int64_t OffsetValue = OffsetImmOp.
getImm();
4484 warnIfNoMacro(IDLoc);
4485 MCRegister ATReg = getATReg(IDLoc);
4490 if (IsLargeOffset) {
4491 if (loadImmediate(OffsetValue, ATReg, SrcReg, !
ABI.ArePtrs64bit(),
true,
4496 int64_t FirstOffset = IsLargeOffset ? 0 : OffsetValue;
4497 int64_t SecondOffset = IsLargeOffset ? 1 : (OffsetValue + 1);
4501 MCRegister FirstLbuDstReg = IsLargeOffset ? DstReg : ATReg;
4502 MCRegister SecondLbuDstReg = IsLargeOffset ? ATReg : DstReg;
4504 MCRegister LbuSrcReg = IsLargeOffset ? ATReg : SrcReg;
4505 MCRegister SllReg = IsLargeOffset ? DstReg : ATReg;
4507 TOut.
emitRRI(
Signed ? Mips::LB : Mips::LBu, FirstLbuDstReg, LbuSrcReg,
4508 FirstOffset, IDLoc, STI);
4509 TOut.
emitRRI(Mips::LBu, SecondLbuDstReg, LbuSrcReg, SecondOffset, IDLoc, STI);
4510 TOut.
emitRRI(Mips::SLL, SllReg, SllReg, 8, IDLoc, STI);
4511 TOut.
emitRRR(Mips::OR, DstReg, DstReg, ATReg, IDLoc, STI);
4516bool MipsAsmParser::expandUsh(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
4517 const MCSubtargetInfo *STI) {
4518 if (hasMips32r6() || hasMips64r6()) {
4519 return Error(IDLoc,
"instruction not supported on mips32r6 or mips64r6");
4522 const MCOperand &DstRegOp = Inst.
getOperand(0);
4523 assert(DstRegOp.
isReg() &&
"expected register operand kind");
4524 const MCOperand &SrcRegOp = Inst.
getOperand(1);
4525 assert(SrcRegOp.
isReg() &&
"expected register operand kind");
4526 const MCOperand &OffsetImmOp = Inst.
getOperand(2);
4527 assert(OffsetImmOp.
isImm() &&
"expected immediate operand kind");
4529 MipsTargetStreamer &TOut = getTargetStreamer();
4530 MCRegister DstReg = DstRegOp.
getReg();
4531 MCRegister SrcReg = SrcRegOp.
getReg();
4532 int64_t OffsetValue = OffsetImmOp.
getImm();
4534 warnIfNoMacro(IDLoc);
4535 MCRegister ATReg = getATReg(IDLoc);
4540 if (IsLargeOffset) {
4541 if (loadImmediate(OffsetValue, ATReg, SrcReg, !
ABI.ArePtrs64bit(),
true,
4546 int64_t FirstOffset = IsLargeOffset ? 1 : (OffsetValue + 1);
4547 int64_t SecondOffset = IsLargeOffset ? 0 : OffsetValue;
4551 if (IsLargeOffset) {
4552 TOut.
emitRRI(Mips::SB, DstReg, ATReg, FirstOffset, IDLoc, STI);
4553 TOut.
emitRRI(Mips::SRL, DstReg, DstReg, 8, IDLoc, STI);
4554 TOut.
emitRRI(Mips::SB, DstReg, ATReg, SecondOffset, IDLoc, STI);
4555 TOut.
emitRRI(Mips::LBu, ATReg, ATReg, 0, IDLoc, STI);
4556 TOut.
emitRRI(Mips::SLL, DstReg, DstReg, 8, IDLoc, STI);
4557 TOut.
emitRRR(Mips::OR, DstReg, DstReg, ATReg, IDLoc, STI);
4559 TOut.
emitRRI(Mips::SB, DstReg, SrcReg, FirstOffset, IDLoc, STI);
4560 TOut.
emitRRI(Mips::SRL, ATReg, DstReg, 8, IDLoc, STI);
4561 TOut.
emitRRI(Mips::SB, ATReg, SrcReg, SecondOffset, IDLoc, STI);
4567bool MipsAsmParser::expandUxw(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
4568 const MCSubtargetInfo *STI) {
4569 if (hasMips32r6() || hasMips64r6()) {
4570 return Error(IDLoc,
"instruction not supported on mips32r6 or mips64r6");
4573 const MCOperand &DstRegOp = Inst.
getOperand(0);
4574 assert(DstRegOp.
isReg() &&
"expected register operand kind");
4575 const MCOperand &SrcRegOp = Inst.
getOperand(1);
4576 assert(SrcRegOp.
isReg() &&
"expected register operand kind");
4577 const MCOperand &OffsetImmOp = Inst.
getOperand(2);
4578 assert(OffsetImmOp.
isImm() &&
"expected immediate operand kind");
4580 MipsTargetStreamer &TOut = getTargetStreamer();
4581 MCRegister DstReg = DstRegOp.
getReg();
4582 MCRegister SrcReg = SrcRegOp.
getReg();
4583 int64_t OffsetValue = OffsetImmOp.
getImm();
4587 int64_t LxlOffset = IsLargeOffset ? 0 : OffsetValue;
4588 int64_t LxrOffset = IsLargeOffset ? 3 : (OffsetValue + 3);
4592 bool IsLoadInst = (Inst.
getOpcode() == Mips::Ulw);
4593 bool DoMove = IsLoadInst && (SrcReg == DstReg) && !IsLargeOffset;
4594 MCRegister TmpReg = SrcReg;
4595 if (IsLargeOffset || DoMove) {
4596 warnIfNoMacro(IDLoc);
4597 TmpReg = getATReg(IDLoc);
4602 if (IsLargeOffset) {
4603 if (loadImmediate(OffsetValue, TmpReg, SrcReg, !
ABI.ArePtrs64bit(),
true,
4611 unsigned XWL = IsLoadInst ? Mips::LWL : Mips::SWL;
4612 unsigned XWR = IsLoadInst ? Mips::LWR : Mips::SWR;
4613 TOut.
emitRRI(XWL, DstReg, TmpReg, LxlOffset, IDLoc, STI);
4614 TOut.
emitRRI(XWR, DstReg, TmpReg, LxrOffset, IDLoc, STI);
4617 TOut.
emitRRR(Mips::OR, TmpReg, DstReg, Mips::R0, IDLoc, STI);
4622bool MipsAsmParser::expandSge(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
4623 const MCSubtargetInfo *STI) {
4624 MipsTargetStreamer &TOut = getTargetStreamer();
4636 warnIfNoMacro(IDLoc);
4650 TOut.
emitRRR(OpCode, DstReg, SrcReg, OpReg, IDLoc, STI);
4651 TOut.
emitRRI(Mips::XORi, DstReg, DstReg, 1, IDLoc, STI);
4656bool MipsAsmParser::expandSgeImm(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
4657 const MCSubtargetInfo *STI) {
4658 MipsTargetStreamer &TOut = getTargetStreamer();
4668 unsigned OpRegCode, OpImmCode;
4670 warnIfNoMacro(IDLoc);
4674 case Mips::SGEImm64:
4675 OpRegCode = Mips::SLT;
4676 OpImmCode = Mips::SLTi;
4679 case Mips::SGEUImm64:
4680 OpRegCode = Mips::SLTu;
4681 OpImmCode = Mips::SLTiu;
4690 TOut.
emitRRI(OpImmCode, DstReg, SrcReg, ImmValue, IDLoc, STI);
4691 TOut.
emitRRI(Mips::XORi, DstReg, DstReg, 1, IDLoc, STI);
4693 MCRegister ImmReg = DstReg;
4694 if (DstReg == SrcReg) {
4695 MCRegister ATReg = getATReg(Inst.
getLoc());
4701 if (loadImmediate(ImmValue, ImmReg, MCRegister(),
isInt<32>(ImmValue),
4702 false, IDLoc, Out, STI))
4705 TOut.
emitRRR(OpRegCode, DstReg, SrcReg, ImmReg, IDLoc, STI);
4706 TOut.
emitRRI(Mips::XORi, DstReg, DstReg, 1, IDLoc, STI);
4712bool MipsAsmParser::expandSgtImm(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
4713 const MCSubtargetInfo *STI) {
4714 MipsTargetStreamer &TOut = getTargetStreamer();
4723 MCRegister ImmReg = DstReg;
4727 warnIfNoMacro(IDLoc);
4731 case Mips::SGTImm64:
4735 case Mips::SGTUImm64:
4742 if (DstReg == SrcReg) {
4743 MCRegister ATReg = getATReg(Inst.
getLoc());
4749 if (loadImmediate(ImmValue, ImmReg, MCRegister(),
isInt<32>(ImmValue),
false,
4754 TOut.
emitRRR(OpCode, DstReg, ImmReg, SrcReg, IDLoc, STI);
4759bool MipsAsmParser::expandSle(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
4760 const MCSubtargetInfo *STI) {
4761 MipsTargetStreamer &TOut = getTargetStreamer();
4773 warnIfNoMacro(IDLoc);
4787 TOut.
emitRRR(OpCode, DstReg, OpReg, SrcReg, IDLoc, STI);
4788 TOut.
emitRRI(Mips::XORi, DstReg, DstReg, 1, IDLoc, STI);
4793bool MipsAsmParser::expandSleImm(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
4794 const MCSubtargetInfo *STI) {
4795 MipsTargetStreamer &TOut = getTargetStreamer();
4807 warnIfNoMacro(IDLoc);
4811 case Mips::SLEImm64:
4812 OpRegCode = Mips::SLT;
4815 case Mips::SLEUImm64:
4816 OpRegCode = Mips::SLTu;
4823 MCRegister ImmReg = DstReg;
4824 if (DstReg == SrcReg) {
4825 MCRegister ATReg = getATReg(Inst.
getLoc());
4831 if (loadImmediate(ImmValue, ImmReg, MCRegister(),
isInt<32>(ImmValue),
false,
4835 TOut.
emitRRR(OpRegCode, DstReg, ImmReg, SrcReg, IDLoc, STI);
4836 TOut.
emitRRI(Mips::XORi, DstReg, DstReg, 1, IDLoc, STI);
4841bool MipsAsmParser::expandAliasImmediate(MCInst &Inst, SMLoc IDLoc,
4843 const MCSubtargetInfo *STI) {
4844 MipsTargetStreamer &TOut = getTargetStreamer();
4852 MCRegister FinalDstReg;
4859 unsigned FinalOpcode = Inst.
getOpcode();
4861 if (DstReg == SrcReg) {
4862 ATReg = getATReg(Inst.
getLoc());
4865 FinalDstReg = DstReg;
4869 if (!loadImmediate(ImmValue, DstReg, MCRegister(), Is32Bit,
false,
4870 Inst.
getLoc(), Out, STI)) {
4871 switch (FinalOpcode) {
4875 FinalOpcode = Mips::ADD;
4878 FinalOpcode = Mips::ADDu;
4881 FinalOpcode = Mips::AND;
4884 FinalOpcode = Mips::NOR;
4887 FinalOpcode = Mips::OR;
4890 FinalOpcode = Mips::SLT;
4893 FinalOpcode = Mips::SLTu;
4896 FinalOpcode = Mips::XOR;
4899 FinalOpcode = Mips::ADD_MM;
4901 case Mips::ADDiu_MM:
4902 FinalOpcode = Mips::ADDu_MM;
4905 FinalOpcode = Mips::AND_MM;
4908 FinalOpcode = Mips::OR_MM;
4911 FinalOpcode = Mips::SLT_MM;
4913 case Mips::SLTiu_MM:
4914 FinalOpcode = Mips::SLTu_MM;
4917 FinalOpcode = Mips::XOR_MM;
4920 FinalOpcode = Mips::AND64;
4922 case Mips::NORImm64:
4923 FinalOpcode = Mips::NOR64;
4926 FinalOpcode = Mips::OR64;
4928 case Mips::SLTImm64:
4929 FinalOpcode = Mips::SLT64;
4931 case Mips::SLTUImm64:
4932 FinalOpcode = Mips::SLTu64;
4935 FinalOpcode = Mips::XOR64;
4940 TOut.
emitRRR(FinalOpcode, DstReg, DstReg, SrcReg, IDLoc, STI);
4942 TOut.
emitRRR(FinalOpcode, FinalDstReg, FinalDstReg, DstReg, IDLoc, STI);
4948bool MipsAsmParser::expandRotation(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
4949 const MCSubtargetInfo *STI) {
4950 MipsTargetStreamer &TOut = getTargetStreamer();
4955 MCRegister TmpReg =
DReg;
4957 unsigned FirstShift = Mips::NOP;
4958 unsigned SecondShift = Mips::NOP;
4960 if (hasMips32r2()) {
4962 TmpReg = getATReg(Inst.
getLoc());
4968 TOut.
emitRRR(Mips::SUBu, TmpReg, Mips::R0, TReg, Inst.
getLoc(), STI);
4969 TOut.
emitRRR(Mips::ROTRV, DReg, SReg, TmpReg, Inst.
getLoc(), STI);
4974 TOut.
emitRRR(Mips::ROTRV, DReg, SReg, TReg, Inst.
getLoc(), STI);
4986 FirstShift = Mips::SRLV;
4987 SecondShift = Mips::SLLV;
4990 FirstShift = Mips::SLLV;
4991 SecondShift = Mips::SRLV;
4995 ATReg = getATReg(Inst.
getLoc());
4999 TOut.
emitRRR(Mips::SUBu, ATReg, Mips::R0, TReg, Inst.
getLoc(), STI);
5000 TOut.
emitRRR(FirstShift, ATReg, SReg, ATReg, Inst.
getLoc(), STI);
5001 TOut.
emitRRR(SecondShift, DReg, SReg, TReg, Inst.
getLoc(), STI);
5002 TOut.
emitRRR(Mips::OR, DReg, DReg, ATReg, Inst.
getLoc(), STI);
5010bool MipsAsmParser::expandRotationImm(MCInst &Inst, SMLoc IDLoc,
5012 const MCSubtargetInfo *STI) {
5013 MipsTargetStreamer &TOut = getTargetStreamer();
5019 unsigned FirstShift = Mips::NOP;
5020 unsigned SecondShift = Mips::NOP;
5022 if (hasMips32r2()) {
5027 ShiftValue = MaxShift - ImmValue;
5028 TOut.
emitRRI(Mips::ROTR, DReg, SReg, ShiftValue, Inst.
getLoc(), STI);
5033 TOut.
emitRRI(Mips::ROTR, DReg, SReg, ImmValue, Inst.
getLoc(), STI);
5041 if (ImmValue == 0) {
5050 FirstShift = Mips::SLL;
5051 SecondShift = Mips::SRL;
5054 FirstShift = Mips::SRL;
5055 SecondShift = Mips::SLL;
5059 ATReg = getATReg(Inst.
getLoc());
5063 TOut.
emitRRI(FirstShift, ATReg, SReg, ImmValue, Inst.
getLoc(), STI);
5064 TOut.
emitRRI(SecondShift, DReg, SReg, 32 - ImmValue, Inst.
getLoc(), STI);
5065 TOut.
emitRRR(Mips::OR, DReg, DReg, ATReg, Inst.
getLoc(), STI);
5073bool MipsAsmParser::expandDRotation(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
5074 const MCSubtargetInfo *STI) {
5075 MipsTargetStreamer &TOut = getTargetStreamer();
5080 MCRegister TmpReg =
DReg;
5082 unsigned FirstShift = Mips::NOP;
5083 unsigned SecondShift = Mips::NOP;
5085 if (hasMips64r2()) {
5086 if (TmpReg == SReg) {
5087 TmpReg = getATReg(Inst.
getLoc());
5093 TOut.
emitRRR(Mips::DSUBu, TmpReg, Mips::R0, TReg, Inst.
getLoc(), STI);
5094 TOut.
emitRRR(Mips::DROTRV, DReg, SReg, TmpReg, Inst.
getLoc(), STI);
5099 TOut.
emitRRR(Mips::DROTRV, DReg, SReg, TReg, Inst.
getLoc(), STI);
5111 FirstShift = Mips::DSRLV;
5112 SecondShift = Mips::DSLLV;
5115 FirstShift = Mips::DSLLV;
5116 SecondShift = Mips::DSRLV;
5120 ATReg = getATReg(Inst.
getLoc());
5124 TOut.
emitRRR(Mips::DSUBu, ATReg, Mips::R0, TReg, Inst.
getLoc(), STI);
5125 TOut.
emitRRR(FirstShift, ATReg, SReg, ATReg, Inst.
getLoc(), STI);
5126 TOut.
emitRRR(SecondShift, DReg, SReg, TReg, Inst.
getLoc(), STI);
5127 TOut.
emitRRR(Mips::OR, DReg, DReg, ATReg, Inst.
getLoc(), STI);
5135bool MipsAsmParser::expandDRotationImm(MCInst &Inst, SMLoc IDLoc,
5137 const MCSubtargetInfo *STI) {
5138 MipsTargetStreamer &TOut = getTargetStreamer();
5144 unsigned FirstShift = Mips::NOP;
5145 unsigned SecondShift = Mips::NOP;
5147 if (hasMips64r2()) {
5148 unsigned FinalOpcode = Mips::NOP;
5150 FinalOpcode = Mips::DROTR;
5151 else if (ImmValue % 32 == 0)
5152 FinalOpcode = Mips::DROTR32;
5153 else if ((ImmValue >= 1) && (ImmValue <= 32)) {
5155 FinalOpcode = Mips::DROTR32;
5157 FinalOpcode = Mips::DROTR;
5158 }
else if (ImmValue >= 33) {
5160 FinalOpcode = Mips::DROTR;
5162 FinalOpcode = Mips::DROTR32;
5165 uint64_t ShiftValue = ImmValue % 32;
5167 ShiftValue = (32 - ImmValue % 32) % 32;
5169 TOut.
emitRRI(FinalOpcode, DReg, SReg, ShiftValue, Inst.
getLoc(), STI);
5175 if (ImmValue == 0) {
5176 TOut.
emitRRI(Mips::DSRL, DReg, SReg, 0, Inst.
getLoc(), STI);
5184 if ((ImmValue >= 1) && (ImmValue <= 31)) {
5185 FirstShift = Mips::DSLL;
5186 SecondShift = Mips::DSRL32;
5188 if (ImmValue == 32) {
5189 FirstShift = Mips::DSLL32;
5190 SecondShift = Mips::DSRL32;
5192 if ((ImmValue >= 33) && (ImmValue <= 63)) {
5193 FirstShift = Mips::DSLL32;
5194 SecondShift = Mips::DSRL;
5198 if ((ImmValue >= 1) && (ImmValue <= 31)) {
5199 FirstShift = Mips::DSRL;
5200 SecondShift = Mips::DSLL32;
5202 if (ImmValue == 32) {
5203 FirstShift = Mips::DSRL32;
5204 SecondShift = Mips::DSLL32;
5206 if ((ImmValue >= 33) && (ImmValue <= 63)) {
5207 FirstShift = Mips::DSRL32;
5208 SecondShift = Mips::DSLL;
5213 ATReg = getATReg(Inst.
getLoc());
5217 TOut.
emitRRI(FirstShift, ATReg, SReg, ImmValue % 32, Inst.
getLoc(), STI);
5218 TOut.
emitRRI(SecondShift, DReg, SReg, (32 - ImmValue % 32) % 32,
5220 TOut.
emitRRR(Mips::OR, DReg, DReg, ATReg, Inst.
getLoc(), STI);
5228bool MipsAsmParser::expandAbs(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
5229 const MCSubtargetInfo *STI) {
5230 MipsTargetStreamer &TOut = getTargetStreamer();
5234 TOut.
emitRI(Mips::BGEZ, SecondRegOp, 8, IDLoc, STI);
5235 if (FirstRegOp != SecondRegOp)
5236 TOut.
emitRRR(Mips::ADDu, FirstRegOp, SecondRegOp, Mips::R0, IDLoc, STI);
5239 TOut.
emitRRR(Mips::SUB, FirstRegOp, Mips::R0, SecondRegOp, IDLoc, STI);
5244bool MipsAsmParser::expandMulImm(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
5245 const MCSubtargetInfo *STI) {
5246 MipsTargetStreamer &TOut = getTargetStreamer();
5252 ATReg = getATReg(IDLoc);
5256 loadImmediate(ImmValue, ATReg, MCRegister(),
true,
false, IDLoc, Out, STI);
5258 TOut.
emitRR(Inst.
getOpcode() == Mips::MULImmMacro ? Mips::MULT : Mips::DMULT,
5259 SrcReg, ATReg, IDLoc, STI);
5261 TOut.
emitR(Mips::MFLO, DstReg, IDLoc, STI);
5266bool MipsAsmParser::expandMulO(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
5267 const MCSubtargetInfo *STI) {
5268 MipsTargetStreamer &TOut = getTargetStreamer();
5274 ATReg = getATReg(Inst.
getLoc());
5278 TOut.
emitRR(Inst.
getOpcode() == Mips::MULOMacro ? Mips::MULT : Mips::DMULT,
5279 SrcReg, TmpReg, IDLoc, STI);
5281 TOut.
emitR(Mips::MFLO, DstReg, IDLoc, STI);
5283 TOut.
emitRRI(Inst.
getOpcode() == Mips::MULOMacro ? Mips::SRA : Mips::DSRA32,
5284 DstReg, DstReg, 0x1F, IDLoc, STI);
5286 TOut.
emitR(Mips::MFHI, ATReg, IDLoc, STI);
5289 TOut.
emitRRI(Mips::TNE, DstReg, ATReg, 6, IDLoc, STI);
5296 TOut.
emitRRX(Mips::BEQ, DstReg, ATReg, LabelOp, IDLoc, STI);
5297 if (AssemblerOptions.
back()->isReorder())
5299 TOut.
emitII(Mips::BREAK, 6, 0, IDLoc, STI);
5303 TOut.
emitR(Mips::MFLO, DstReg, IDLoc, STI);
5308bool MipsAsmParser::expandMulOU(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
5309 const MCSubtargetInfo *STI) {
5310 MipsTargetStreamer &TOut = getTargetStreamer();
5316 ATReg = getATReg(IDLoc);
5320 TOut.
emitRR(Inst.
getOpcode() == Mips::MULOUMacro ? Mips::MULTu : Mips::DMULTu,
5321 SrcReg, TmpReg, IDLoc, STI);
5323 TOut.
emitR(Mips::MFHI, ATReg, IDLoc, STI);
5324 TOut.
emitR(Mips::MFLO, DstReg, IDLoc, STI);
5326 TOut.
emitRRI(Mips::TNE, ATReg, Mips::R0, 6, IDLoc, STI);
5333 TOut.
emitRRX(Mips::BEQ, ATReg, Mips::R0, LabelOp, IDLoc, STI);
5334 if (AssemblerOptions.
back()->isReorder())
5336 TOut.
emitII(Mips::BREAK, 6, 0, IDLoc, STI);
5344bool MipsAsmParser::expandDMULMacro(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
5345 const MCSubtargetInfo *STI) {
5346 MipsTargetStreamer &TOut = getTargetStreamer();
5351 TOut.
emitRR(Mips::DMULTu, SrcReg, TmpReg, IDLoc, STI);
5352 TOut.
emitR(Mips::MFLO, DstReg, IDLoc, STI);
5362bool MipsAsmParser::expandLoadStoreDMacro(MCInst &Inst, SMLoc IDLoc,
5364 const MCSubtargetInfo *STI,
5369 warnIfNoMacro(IDLoc);
5371 MipsTargetStreamer &TOut = getTargetStreamer();
5372 unsigned Opcode = IsLoad ? Mips::LW : Mips::SW;
5374 MCRegister SecondReg =
nextReg(FirstReg);
5379 warnIfRegIndexIsAT(FirstReg, IDLoc);
5382 "Offset for load macro is not immediate!");
5385 signed NextOffset = FirstOffset.
getImm() + 4;
5393 if (FirstReg != BaseReg || !IsLoad) {
5394 TOut.
emitRRX(Opcode, FirstReg, BaseReg, FirstOffset, IDLoc, STI);
5395 TOut.
emitRRX(Opcode, SecondReg, BaseReg, SecondOffset, IDLoc, STI);
5397 TOut.
emitRRX(Opcode, SecondReg, BaseReg, SecondOffset, IDLoc, STI);
5398 TOut.
emitRRX(Opcode, FirstReg, BaseReg, FirstOffset, IDLoc, STI);
5410bool MipsAsmParser::expandStoreDM1Macro(MCInst &Inst, SMLoc IDLoc,
5412 const MCSubtargetInfo *STI) {
5416 warnIfNoMacro(IDLoc);
5418 MipsTargetStreamer &TOut = getTargetStreamer();
5419 unsigned Opcode = Mips::SWC1;
5421 MCRegister SecondReg =
nextReg(FirstReg);
5426 warnIfRegIndexIsAT(FirstReg, IDLoc);
5429 "Offset for macro is not immediate!");
5432 signed NextOffset = FirstOffset.
getImm() + 4;
5438 if (!IsLittleEndian)
5441 TOut.
emitRRX(Opcode, FirstReg, BaseReg, FirstOffset, IDLoc, STI);
5442 TOut.
emitRRX(Opcode, SecondReg, BaseReg, SecondOffset, IDLoc, STI);
5447bool MipsAsmParser::expandSeq(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
5448 const MCSubtargetInfo *STI) {
5449 MipsTargetStreamer &TOut = getTargetStreamer();
5460 warnIfNoMacro(IDLoc);
5462 if (SrcReg != Mips::R0 && OpReg != Mips::R0) {
5463 TOut.
emitRRR(Mips::XOR, DstReg, SrcReg, OpReg, IDLoc, STI);
5464 TOut.
emitRRI(Mips::SLTiu, DstReg, DstReg, 1, IDLoc, STI);
5468 MCRegister
Reg = SrcReg == Mips::R0 ? OpReg : SrcReg;
5469 TOut.
emitRRI(Mips::SLTiu, DstReg,
Reg, 1, IDLoc, STI);
5473bool MipsAsmParser::expandSeqI(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
5474 const MCSubtargetInfo *STI) {
5475 MipsTargetStreamer &TOut = getTargetStreamer();
5486 warnIfNoMacro(IDLoc);
5489 TOut.
emitRRI(Mips::SLTiu, DstReg, SrcReg, 1, IDLoc, STI);
5493 if (SrcReg == Mips::R0) {
5494 Warning(IDLoc,
"comparison is always false");
5495 TOut.
emitRRR(isGP64bit() ? Mips::DADDu : Mips::ADDu,
5496 DstReg, SrcReg, SrcReg, IDLoc, STI);
5501 if (
Imm > -0x8000 &&
Imm < 0) {
5503 Opc = isGP64bit() ? Mips::DADDiu : Mips::ADDiu;
5509 MCRegister ATReg = getATReg(IDLoc);
5513 if (loadImmediate(
Imm, ATReg, MCRegister(),
true, isGP64bit(), IDLoc, Out,
5517 TOut.
emitRRR(Mips::XOR, DstReg, SrcReg, ATReg, IDLoc, STI);
5518 TOut.
emitRRI(Mips::SLTiu, DstReg, DstReg, 1, IDLoc, STI);
5523 TOut.
emitRRI(Mips::SLTiu, DstReg, DstReg, 1, IDLoc, STI);
5527bool MipsAsmParser::expandSne(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
5528 const MCSubtargetInfo *STI) {
5530 MipsTargetStreamer &TOut = getTargetStreamer();
5541 warnIfNoMacro(IDLoc);
5543 if (SrcReg != Mips::R0 && OpReg != Mips::R0) {
5544 TOut.
emitRRR(Mips::XOR, DstReg, SrcReg, OpReg, IDLoc, STI);
5545 TOut.
emitRRR(Mips::SLTu, DstReg, Mips::R0, DstReg, IDLoc, STI);
5549 MCRegister
Reg = SrcReg == Mips::R0 ? OpReg : SrcReg;
5550 TOut.
emitRRR(Mips::SLTu, DstReg, Mips::R0,
Reg, IDLoc, STI);
5554bool MipsAsmParser::expandSneI(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
5555 const MCSubtargetInfo *STI) {
5556 MipsTargetStreamer &TOut = getTargetStreamer();
5567 warnIfNoMacro(IDLoc);
5569 if (ImmValue == 0) {
5570 TOut.
emitRRR(Mips::SLTu, DstReg, Mips::R0, SrcReg, IDLoc, STI);
5574 if (SrcReg == Mips::R0) {
5575 Warning(IDLoc,
"comparison is always true");
5576 if (loadImmediate(1, DstReg, MCRegister(),
true,
false, IDLoc, Out, STI))
5582 if (ImmValue > -0x8000 && ImmValue < 0) {
5583 ImmValue = -ImmValue;
5584 Opc = isGP64bit() ? Mips::DADDiu : Mips::ADDiu;
5590 TOut.
emitRRI(
Opc, DstReg, SrcReg, ImmValue, IDLoc, STI);
5591 TOut.
emitRRR(Mips::SLTu, DstReg, Mips::R0, DstReg, IDLoc, STI);
5595 MCRegister ATReg = getATReg(IDLoc);
5599 if (loadImmediate(ImmValue, ATReg, MCRegister(),
isInt<32>(ImmValue),
false,
5603 TOut.
emitRRR(Mips::XOR, DstReg, SrcReg, ATReg, IDLoc, STI);
5604 TOut.
emitRRR(Mips::SLTu, DstReg, Mips::R0, DstReg, IDLoc, STI);
5738bool MipsAsmParser::expandMXTRAlias(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
5739 const MCSubtargetInfo *STI) {
5740 MipsTargetStreamer &TOut = getTargetStreamer();
5744 bool IsMFTR =
false;
5790 IsMFTR ? MCRegister(rd)
5792 : Inst.getOperand(0).
getReg());
5794 TOut.
emitRRIII(IsMFTR ? Mips::MFTR : Mips::MTTR, Op0, Op1, 1, sel, h, IDLoc,
5799bool MipsAsmParser::expandSaaAddr(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
5800 const MCSubtargetInfo *STI) {
5805 warnIfNoMacro(IDLoc);
5807 MipsTargetStreamer &TOut = getTargetStreamer();
5808 unsigned Opcode = Inst.
getOpcode() == Mips::SaaAddr ? Mips::SAA : Mips::SAAD;
5811 const MCOperand &BaseOp = Inst.
getOperand(2);
5813 if (BaseOp.
isImm()) {
5814 int64_t ImmValue = BaseOp.
getImm();
5815 if (ImmValue == 0) {
5816 TOut.
emitRR(Opcode, RtReg, BaseReg, IDLoc, STI);
5821 MCRegister ATReg = getATReg(IDLoc);
5825 if (expandLoadAddress(ATReg, BaseReg, BaseOp, !isGP64bit(), IDLoc, Out, STI))
5828 TOut.
emitRR(Opcode, RtReg, ATReg, IDLoc, STI);
5833MipsAsmParser::checkEarlyTargetMatchPredicate(MCInst &Inst,
5837 return Match_Success;
5840 if (
static_cast<MipsOperand &
>(*
Operands[1])
5841 .isValidForTie(
static_cast<MipsOperand &
>(*
Operands[2])))
5842 return Match_Success;
5843 return Match_RequiresSameSrcAndDst;
5847unsigned MipsAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
5854 return Match_RequiresNoZeroRegister;
5855 return Match_Success;
5861 case Mips::JALR_HB64:
5862 case Mips::JALRC_HB_MMR6:
5863 case Mips::JALRC_MMR6:
5865 return Match_RequiresDifferentSrcAndDst;
5866 return Match_Success;
5869 return Match_RequiresDifferentSrcAndDst;
5870 return Match_Success;
5873 return Match_NonZeroOperandForSync;
5874 return Match_Success;
5878 return Match_NonZeroOperandForMTCX;
5879 return Match_Success;
5892 case Mips::BLEZC:
case Mips::BLEZC_MMR6:
5893 case Mips::BGEZC:
case Mips::BGEZC_MMR6:
5894 case Mips::BGTZC:
case Mips::BGTZC_MMR6:
5895 case Mips::BLTZC:
case Mips::BLTZC_MMR6:
5896 case Mips::BEQZC:
case Mips::BEQZC_MMR6:
5897 case Mips::BNEZC:
case Mips::BNEZC_MMR6:
5906 return Match_RequiresNoZeroRegister;
5907 return Match_Success;
5908 case Mips::BGEC:
case Mips::BGEC_MMR6:
5909 case Mips::BLTC:
case Mips::BLTC_MMR6:
5910 case Mips::BGEUC:
case Mips::BGEUC_MMR6:
5911 case Mips::BLTUC:
case Mips::BLTUC_MMR6:
5912 case Mips::BEQC:
case Mips::BEQC_MMR6:
5913 case Mips::BNEC:
case Mips::BNEC_MMR6:
5922 return Match_RequiresNoZeroRegister;
5925 return Match_RequiresNoZeroRegister;
5927 return Match_RequiresDifferentOperands;
5928 return Match_Success;
5931 "Operands must be immediates for dins!");
5934 if ((0 > (Pos +
Size)) || ((Pos +
Size) > 32))
5935 return Match_RequiresPosSizeRange0_32;
5936 return Match_Success;
5941 "Operands must be immediates for dinsm/dinsu!");
5944 if ((32 >= (Pos +
Size)) || ((Pos +
Size) > 64))
5945 return Match_RequiresPosSizeRange33_64;
5946 return Match_Success;
5950 "Operands must be immediates for DEXTM!");
5953 if ((1 > (Pos +
Size)) || ((Pos +
Size) > 63))
5954 return Match_RequiresPosSizeUImm6;
5955 return Match_Success;
5960 "Operands must be immediates for dextm/dextu!");
5963 if ((32 > (Pos +
Size)) || ((Pos +
Size) > 64))
5964 return Match_RequiresPosSizeRange33_64;
5965 return Match_Success;
5967 case Mips::CRC32B:
case Mips::CRC32CB:
5968 case Mips::CRC32H:
case Mips::CRC32CH:
5969 case Mips::CRC32W:
case Mips::CRC32CW:
5970 case Mips::CRC32D:
case Mips::CRC32CD:
5972 return Match_RequiresSameSrcAndDst;
5973 return Match_Success;
5979 return Match_NoFCCRegisterForCurrentISA;
5981 return Match_Success;
5989 if (ErrorLoc ==
SMLoc())
5996bool MipsAsmParser::matchAndEmitInstruction(SMLoc IDLoc,
unsigned &Opcode,
6000 bool MatchingInlineAsm) {
6002 unsigned MatchResult =
6003 MatchInstructionImpl(
Operands, Inst, ErrorInfo, MatchingInlineAsm);
6005 switch (MatchResult) {
6007 if (processInstruction(Inst, IDLoc, Out, STI))
6010 case Match_MissingFeature:
6011 Error(IDLoc,
"instruction requires a CPU feature not currently enabled");
6013 case Match_InvalidTiedOperand:
6014 Error(IDLoc,
"operand must match destination register");
6016 case Match_InvalidOperand: {
6017 SMLoc ErrorLoc = IDLoc;
6018 if (ErrorInfo != ~0ULL) {
6020 return Error(IDLoc,
"too few operands for instruction");
6022 ErrorLoc =
Operands[ErrorInfo]->getStartLoc();
6024 ErrorLoc =
static_cast<MipsOperand &
>(*
Operands[ErrorInfo])
6027 if (ErrorLoc == SMLoc())
6031 return Error(ErrorLoc,
"invalid operand for instruction");
6033 case Match_NonZeroOperandForSync:
6035 "s-type must be zero or unspecified for pre-MIPS32 ISAs");
6036 case Match_NonZeroOperandForMTCX:
6037 return Error(IDLoc,
"selector must be zero for pre-MIPS32 ISAs");
6038 case Match_MnemonicFail:
6039 return Error(IDLoc,
"invalid instruction");
6040 case Match_RequiresDifferentSrcAndDst:
6041 return Error(IDLoc,
"source and destination must be different");
6042 case Match_RequiresDifferentOperands:
6043 return Error(IDLoc,
"registers must be different");
6044 case Match_RequiresNoZeroRegister:
6045 return Error(IDLoc,
"invalid operand ($zero) for instruction");
6046 case Match_RequiresSameSrcAndDst:
6047 return Error(IDLoc,
"source and destination must match");
6048 case Match_NoFCCRegisterForCurrentISA:
6050 "non-zero fcc register doesn't exist in current ISA level");
6055 "expected 1-bit unsigned immediate");
6058 "expected 2-bit unsigned immediate");
6061 "expected immediate in range 1 .. 4");
6064 "expected 3-bit unsigned immediate");
6067 "expected 4-bit unsigned immediate");
6070 "expected 4-bit signed immediate");
6073 "expected 5-bit unsigned immediate");
6076 "expected 5-bit signed immediate");
6079 "expected immediate in range 1 .. 32");
6080 case Match_UImm5_32:
6082 "expected immediate in range 32 .. 63");
6083 case Match_UImm5_33:
6085 "expected immediate in range 33 .. 64");
6086 case Match_UImm5_0_Report_UImm6:
6090 "expected 6-bit unsigned immediate");
6091 case Match_ConstantMemOffset:
6093 !
static_cast<MipsOperand &
>(*
Operands[ErrorInfo]).isConstantImm())
6095 "expected immediate operand kind");
6097 "immediate operand value out of range");
6098 case Match_UImm5_Lsl2:
6100 "expected both 7-bit unsigned immediate and multiple of 4");
6101 case Match_UImmRange2_64:
6103 "expected immediate in range 2 .. 64");
6106 "expected 6-bit unsigned immediate");
6107 case Match_UImm6_Lsl2:
6109 "expected both 8-bit unsigned immediate and multiple of 4");
6112 "expected 6-bit signed immediate");
6115 "expected 7-bit unsigned immediate");
6116 case Match_UImm7_N1:
6118 "expected immediate in range -1 .. 126");
6119 case Match_SImm7_Lsl2:
6121 "expected both 9-bit signed immediate and multiple of 4");
6124 "expected 8-bit unsigned immediate");
6125 case Match_UImm10_0:
6127 "expected 10-bit unsigned immediate");
6128 case Match_SImm10_0:
6130 "expected 10-bit signed immediate");
6131 case Match_SImm11_0:
6133 "expected 11-bit signed immediate");
6135 case Match_UImm16_Relaxed:
6136 case Match_UImm16_AltRelaxed:
6138 "expected 16-bit unsigned immediate");
6140 case Match_SImm16_Relaxed:
6142 "expected 16-bit signed immediate");
6143 case Match_SImm18_Lsl3:
6145 "expected both 18-bit signed immediate and multiple of 8");
6146 case Match_SImm19_Lsl2:
6148 "expected both 19-bit signed immediate and multiple of 4");
6149 case Match_UImm20_0:
6151 "expected 20-bit unsigned immediate");
6152 case Match_UImm26_0:
6154 "expected 26-bit unsigned immediate");
6156 case Match_SImm32_Relaxed:
6158 "expected 32-bit signed immediate");
6159 case Match_UImm32_Coerced:
6161 "expected 32-bit immediate");
6162 case Match_MemSImm9:
6164 "expected memory with 9-bit signed offset");
6165 case Match_MemSImm10:
6167 "expected memory with 10-bit signed offset");
6168 case Match_MemSImm10Lsl1:
6170 "expected memory with 11-bit signed offset and multiple of 2");
6171 case Match_MemSImm10Lsl2:
6173 "expected memory with 12-bit signed offset and multiple of 4");
6174 case Match_MemSImm10Lsl3:
6176 "expected memory with 13-bit signed offset and multiple of 8");
6177 case Match_MemSImm11:
6179 "expected memory with 11-bit signed offset");
6180 case Match_MemSImm12:
6182 "expected memory with 12-bit signed offset");
6183 case Match_MemSImm16:
6185 "expected memory with 16-bit signed offset");
6186 case Match_MemSImmPtr:
6188 "expected memory with 32-bit signed offset");
6189 case Match_RequiresPosSizeRange0_32: {
6190 SMLoc ErrorStart =
Operands[3]->getStartLoc();
6191 SMLoc ErrorEnd =
Operands[4]->getEndLoc();
6192 return Error(ErrorStart,
"size plus position are not in the range 0 .. 32",
6193 SMRange(ErrorStart, ErrorEnd));
6195 case Match_RequiresPosSizeUImm6: {
6196 SMLoc ErrorStart =
Operands[3]->getStartLoc();
6197 SMLoc ErrorEnd =
Operands[4]->getEndLoc();
6198 return Error(ErrorStart,
"size plus position are not in the range 1 .. 63",
6199 SMRange(ErrorStart, ErrorEnd));
6201 case Match_RequiresPosSizeRange33_64: {
6202 SMLoc ErrorStart =
Operands[3]->getStartLoc();
6203 SMLoc ErrorEnd =
Operands[4]->getEndLoc();
6204 return Error(ErrorStart,
"size plus position are not in the range 33 .. 64",
6205 SMRange(ErrorStart, ErrorEnd));
6212void MipsAsmParser::warnIfRegIndexIsAT(MCRegister RegIndex, SMLoc Loc) {
6213 if (RegIndex && AssemblerOptions.
back()->getATRegIndex() == RegIndex)
6214 Warning(Loc,
"used $at (currently $" + Twine(RegIndex.
id()) +
6215 ") without \".set noat\"");
6218void MipsAsmParser::warnIfNoMacro(SMLoc Loc) {
6219 if (!AssemblerOptions.
back()->isMacro())
6220 Warning(Loc,
"macro instruction expanded into multiple instructions");
6223void MipsAsmParser::ConvertXWPOperands(MCInst &Inst,
6227 "Unexpected instruction!");
6228 ((MipsOperand &)*
Operands[1]).addGPR32ZeroAsmRegOperands(Inst, 1);
6229 MCRegister NextReg =
nextReg(((MipsOperand &)*
Operands[1]).getGPR32Reg());
6231 static_cast<MipsOperand &
>(*
Operands[4]).addPtrRegOperands(Inst, 1);
6232 static_cast<MipsOperand &
>(*
Operands[2]).addImmOperands(Inst, 1);
6235template <
unsigned Opcode,
bool IsMFTR>
6236void MipsAsmParser::ConvertMTTransferCOP0Operands(
6238 MCRegister GPR =
static_cast<const MipsOperand &
>(*
Operands[1]).getGPR32Reg();
6240 static_cast<const MipsOperand &
>(*
Operands[2]).getCOP0Encoding();
6244 ->getRegClass(Mips::GPR32RegClassID)
6255MipsAsmParser::printWarningWithFixIt(
const Twine &
Msg,
const Twine &FixMsg,
6256 SMRange
Range,
bool ShowColors) {
6262int MipsAsmParser::matchCPURegisterName(StringRef Name) {
6263 const MCRegisterInfo &
MRI = *
getContext().getRegisterInfo();
6269 AsmToken RegTok = getLexer().peekTok();
6270 StringRef FixedName =
6272 printWarningWithFixIt(
"register names $t4-$t7 are only available in O32.",
6273 "Did you mean $" + FixedName +
"?",
6279int MipsAsmParser::matchHWRegsRegisterName(StringRef Name) {
6280 const MCRegisterInfo &
MRI = *
getContext().getRegisterInfo();
6282 Mips::RegAliasName);
6283 return Reg ?
MRI.getEncodingValue(
Reg) : -1;
6286int MipsAsmParser::matchFPURegisterName(StringRef Name) {
6287 if (Name[0] ==
'f') {
6288 StringRef NumString =
Name.substr(1);
6299int MipsAsmParser::matchFCCRegisterName(StringRef Name) {
6300 if (
Name.starts_with(
"fcc")) {
6301 StringRef NumString =
Name.substr(3);
6312int MipsAsmParser::matchACRegisterName(StringRef Name) {
6313 if (
Name.starts_with(
"ac")) {
6314 StringRef NumString =
Name.substr(2);
6325int MipsAsmParser::matchMSA128RegisterName(StringRef Name) {
6328 if (
Name.front() !=
'w' ||
Name.drop_front(1).getAsInteger(10, IntVal))
6337int MipsAsmParser::matchMSA128CtrlRegisterName(StringRef Name) {
6338 const MCRegisterInfo &
MRI = *
getContext().getRegisterInfo();
6340 Name,
MRI, Mips::MSACtrlRegClassID, Mips::RegAliasName);
6341 return Reg ?
MRI.getEncodingValue(
Reg) : -1;
6344bool MipsAsmParser::canUseATReg() {
6345 return AssemblerOptions.
back()->getATRegIndex() != 0;
6348MCRegister MipsAsmParser::getATReg(SMLoc Loc) {
6349 unsigned ATIndex = AssemblerOptions.
back()->getATRegIndex();
6351 reportParseError(Loc,
6352 "pseudo-instruction requires $at, which is not available");
6356 (isGP64bit()) ? Mips::GPR64RegClassID : Mips::GPR32RegClassID, ATIndex);
6360MCRegister MipsAsmParser::getReg(
int RC,
int RegNo) {
6361 return getContext().getRegisterInfo()->getRegClass(RC).getRegister(RegNo);
6366bool MipsAsmParser::parsePrimaryExpr(
const MCExpr *&Res, SMLoc &EndLoc) {
6368 return getParser().parsePrimaryExpr(Res, EndLoc);
6369 Res = parseRelocExpr();
6370 EndLoc = getLexer().getLoc();
6376const MCExpr *MipsAsmParser::parseRelocExpr() {
6377 auto getOp = [](StringRef
Op) {
6378 return StringSwitch<Mips::Specifier>(
Op)
6406 MCAsmParser &Parser = getParser();
6408 const MCExpr *Res =
nullptr;
6414 auto Op = getOp(Name);
6423 while (
Ops.size()) {
6432 MCAsmParser &Parser = getParser();
6442 ParseStatus Res = MatchOperandParserImpl(
Operands, Mnemonic,
true);
6453 switch (getLexer().getKind()) {
6463 if (!parseAnyRegister(
Operands).isNoMatch())
6476 Operands.push_back(MipsOperand::CreateImm(SymRef, S,
E, *
this));
6481 const MCExpr *Expr = parseRelocExpr();
6485 Operands.push_back(MipsOperand::CreateImm(Expr, S,
E, *
this));
6492bool MipsAsmParser::parseRegister(MCRegister &
Reg, SMLoc &StartLoc,
6494 return !tryParseRegister(
Reg, StartLoc, EndLoc).isSuccess();
6497ParseStatus MipsAsmParser::tryParseRegister(MCRegister &
Reg, SMLoc &StartLoc,
6500 ParseStatus Res = parseAnyRegister(
Operands);
6503 MipsOperand &Operand =
static_cast<MipsOperand &
>(*
Operands.front());
6504 StartLoc = Operand.getStartLoc();
6505 EndLoc = Operand.getEndLoc();
6511 if (Operand.isGPRAsmReg()) {
6513 Reg = isGP64bit() ? Operand.getGPR64Reg() : Operand.getGPR32Reg();
6523const MCExpr *MipsAsmParser::parseMemOffset() {
6530 if (getParser().parseExpression(
Offset))
6539 SMLoc S = getLexer().getLoc();
6540 const MCExpr *
Offset = parseMemOffset();
6544 SMLoc
E = getLexer().getLoc();
6556 Operands.push_back(MipsOperand::CreateToken(
"(",
E, *
this));
6557 Operands.push_back(MipsOperand::createGPRReg(
6559 Operands.push_back(MipsOperand::CreateToken(
")",
E, *
this));
6564 MCAsmParser &Parser = getParser();
6566 const MCExpr *
Address = parseMemOffset();
6583 std::unique_ptr<MipsOperand>
Base(
6584 static_cast<MipsOperand *
>(
Operands.back().release()));
6586 E =
Base->getEndLoc();
6588 MipsOperand::CreateMem(std::move(
Base),
Address, S,
E, *
this));
6593 MCAsmParser &Parser = getParser();
6602 const MCSymbolRefExpr *
Ref =
static_cast<const MCSymbolRefExpr *
>(Expr);
6603 StringRef DefSymbol =
Ref->getSymbol().getName();
6606 matchAnyRegisterNameWithoutDollar(
Operands, DefSymbol.
substr(1), S);
6620 if (Entry != RegisterSets.
end()) {
6622 matchAnyRegisterWithoutDollar(
Operands,
Entry->getValue(), S);
6633ParseStatus MipsAsmParser::matchAnyRegisterNameWithoutDollar(
6635 int Index = matchCPURegisterName(Identifier);
6637 Operands.push_back(MipsOperand::createGPRReg(
6638 Index, Identifier,
getContext().getRegisterInfo(), S,
6639 getLexer().getLoc(), *
this));
6643 Index = matchHWRegsRegisterName(Identifier);
6645 Operands.push_back(MipsOperand::createHWRegsReg(
6646 Index, Identifier,
getContext().getRegisterInfo(), S,
6647 getLexer().getLoc(), *
this));
6651 const MCRegisterInfo &
MRI = *
getContext().getRegisterInfo();
6653 Identifier,
MRI, Mips::COP0RegClassID, Mips::RegAliasName)) {
6654 Operands.push_back(MipsOperand::createCOP0Reg(
MRI.getEncodingValue(
Reg),
6655 Identifier, &
MRI, S,
6656 getLexer().getLoc(), *
this));
6660 Index = matchFPURegisterName(Identifier);
6662 Operands.push_back(MipsOperand::createFGRReg(
6663 Index, Identifier,
getContext().getRegisterInfo(), S,
6664 getLexer().getLoc(), *
this));
6668 Index = matchFCCRegisterName(Identifier);
6670 Operands.push_back(MipsOperand::createFCCReg(
6671 Index, Identifier,
getContext().getRegisterInfo(), S,
6672 getLexer().getLoc(), *
this));
6676 Index = matchACRegisterName(Identifier);
6678 Operands.push_back(MipsOperand::createACCReg(
6679 Index, Identifier,
getContext().getRegisterInfo(), S,
6680 getLexer().getLoc(), *
this));
6684 Index = matchMSA128RegisterName(Identifier);
6686 Operands.push_back(MipsOperand::createMSA128Reg(
6687 Index, Identifier,
getContext().getRegisterInfo(), S,
6688 getLexer().getLoc(), *
this));
6692 Index = matchMSA128CtrlRegisterName(Identifier);
6694 Operands.push_back(MipsOperand::createMSACtrlReg(
6695 Index, Identifier,
getContext().getRegisterInfo(), S,
6696 getLexer().getLoc(), *
this));
6705 const AsmToken &Token, SMLoc S) {
6709 return matchAnyRegisterNameWithoutDollar(
Operands, Identifier, S);
6714 if (RegNum < 0 || RegNum > 31) {
6718 Error(getLexer().getLoc(),
"invalid register number");
6720 Operands.push_back(MipsOperand::createNumericReg(
6733 auto Token = getLexer().peekTok(
false);
6734 return matchAnyRegisterWithoutDollar(
Operands, Token, S);
6738 SMLoc S = getLexer().getLoc();
6740 ParseStatus Res = parseAnyRegister(RegOperands);
6743 const auto &
Op =
static_cast<const MipsOperand &
>(*RegOperands.
back());
6745 if (
Op.isCOP0AsmReg()) {
6746 Encoding =
Op.getCOP0Encoding();
6748 return Error(getLexer().getLoc(),
6749 "explicit selector is not allowed for named COP0 register");
6750 }
else if (
Op.isNumericReg()) {
6754 SMLoc SelLoc = getLexer().getLoc();
6756 if (getParser().parseExpression(Expr))
6758 if (!Expr->evaluateAsAbsolute(Sel) || !
isUInt<3>(Sel))
6759 return Error(SelLoc,
"expected 3-bit unsigned immediate");
6763 return Error(S,
"invalid operand for instruction");
6766 return Error(S,
"selector must be zero for pre-MIPS32 ISAs");
6768 const MCRegisterInfo &
MRI = *
getContext().getRegisterInfo();
6769 Operands.push_back(MipsOperand::createCOP0Reg(Encoding,
"", &
MRI, S,
6770 getLexer().getLoc(), *
this));
6775 MCAsmParser &Parser = getParser();
6778 auto Token = Parser.
getTok();
6780 SMLoc S = Token.
getLoc();
6793 ParseStatus Res = matchAnyRegisterWithoutDollar(
Operands, S);
6802 MCAsmParser &Parser = getParser();
6805 SMLoc S = getLexer().getLoc();
6808 ParseStatus Res = parseAnyRegister(
Operands);
6813 const MCExpr *Expr =
nullptr;
6819 MipsOperand::CreateImm(Expr, S, getLexer().getLoc(), *
this));
6824 MCAsmParser &Parser = getParser();
6825 const MCExpr *IdVal;
6836 if (getParser().parseExpression(IdVal))
6843 Operands.push_back(MipsOperand::CreateImm(
6849 MCAsmParser &Parser = getParser();
6853 bool RegRange =
false;
6860 while (parseAnyRegister(TmpOperands).isSuccess()) {
6861 SMLoc
E = getLexer().getLoc();
6862 MipsOperand &RegOpnd =
static_cast<MipsOperand &
>(*TmpOperands.
back());
6863 Reg = isGP64bit() ? RegOpnd.getGPR64Reg() : RegOpnd.getGPR32Reg();
6871 MCRegister TmpReg = PrevReg + 1;
6872 while (TmpReg <=
Reg) {
6873 if ((((TmpReg < Mips::R16) || (TmpReg > Mips::R23)) &&
6875 (((TmpReg < Mips::R16_64) || (TmpReg > Mips::R23_64)) &&
6877 return Error(
E,
"invalid register operand");
6881 TmpReg = TmpReg.
id() + 1;
6890 return Error(
E,
"$16 or $31 expected");
6892 (
Reg >= Mips::R16 &&
Reg <= Mips::R23)) &&
6895 (
Reg >= Mips::R16_64 &&
Reg <= Mips::R23_64)) &&
6897 return Error(
E,
"invalid register operand");
6898 if (PrevReg.
isValid() && (
Reg != PrevReg + 1) &&
6901 return Error(
E,
"consecutive register numbers expected");
6911 return Error(
E,
"',' or '-' expected");
6921 Operands.push_back(MipsOperand::CreateRegList(Regs, S,
E, *
this));
6922 return parseMemOffsetOperand(
Operands);
6931 MCAsmParser &Parser = getParser();
6934 MipsOperand::CreateToken(
"(", getLexer().getLoc(), *
this));
6936 if (parseOperand(
Operands, Name)) {
6937 SMLoc Loc = getLexer().getLoc();
6938 return Error(Loc,
"unexpected token in argument list");
6941 SMLoc Loc = getLexer().getLoc();
6942 return Error(Loc,
"unexpected token, expected ')'");
6945 MipsOperand::CreateToken(
")", getLexer().getLoc(), *
this));
6957bool MipsAsmParser::parseBracketSuffix(StringRef Name,
6959 MCAsmParser &Parser = getParser();
6962 MipsOperand::CreateToken(
"[", getLexer().getLoc(), *
this));
6964 if (parseOperand(
Operands, Name)) {
6965 SMLoc Loc = getLexer().getLoc();
6966 return Error(Loc,
"unexpected token in argument list");
6969 SMLoc Loc = getLexer().getLoc();
6970 return Error(Loc,
"unexpected token, expected ']'");
6973 MipsOperand::CreateToken(
"]", getLexer().getLoc(), *
this));
6980 unsigned VariantID = 0);
6995bool MipsAsmParser::parseInstruction(ParseInstructionInfo &Info, StringRef Name,
6997 MCAsmParser &Parser = getParser();
7001 getTargetStreamer().forbidModuleDirective();
7004 if (!mnemonicIsValid(Name, 0)) {
7005 FeatureBitset FBS = ComputeAvailableFeatures(getSTI().getFeatureBits());
7007 return Error(NameLoc,
"unknown instruction" + Suggestion);
7010 Operands.push_back(MipsOperand::CreateToken(Name, NameLoc, *
this));
7015 bool IsFirstOperand =
Operands.size() == 1;
7017 if (parseOperand(
Operands, Name)) {
7018 SMLoc Loc = getLexer().getLoc();
7019 return Error(Loc,
"unexpected token in argument list");
7024 if (parseBracketSuffix(Name,
Operands))
7032 SMLoc Loc = getLexer().getLoc();
7033 return Error(Loc,
"unexpected token in argument list");
7041bool MipsAsmParser::reportParseError(
const Twine &ErrorMsg) {
7042 SMLoc Loc = getLexer().getLoc();
7043 return Error(Loc, ErrorMsg);
7046bool MipsAsmParser::reportParseError(SMLoc Loc,
const Twine &ErrorMsg) {
7047 return Error(Loc, ErrorMsg);
7050bool MipsAsmParser::parseSetNoAtDirective() {
7051 MCAsmParser &Parser = getParser();
7055 AssemblerOptions.
back()->setATRegIndex(0);
7061 reportParseError(
"unexpected token, expected end of statement");
7065 getTargetStreamer().emitDirectiveSetNoAt();
7070bool MipsAsmParser::parseSetAtDirective() {
7073 MCAsmParser &Parser = getParser();
7078 AssemblerOptions.
back()->setATRegIndex(1);
7080 getTargetStreamer().emitDirectiveSetAt();
7086 reportParseError(
"unexpected token, expected equals sign");
7093 reportParseError(
"no register specified");
7096 reportParseError(
"unexpected token, expected dollar sign '$'");
7106 AtRegNo = matchCPURegisterName(
Reg.getIdentifier());
7108 AtRegNo =
Reg.getIntVal();
7110 reportParseError(
"unexpected token, expected identifier or integer");
7115 if (!AssemblerOptions.
back()->setATRegIndex(AtRegNo)) {
7116 reportParseError(
"invalid register");
7123 reportParseError(
"unexpected token, expected end of statement");
7127 getTargetStreamer().emitDirectiveSetAtWithArg(AtRegNo);
7133bool MipsAsmParser::parseSetReorderDirective() {
7134 MCAsmParser &Parser = getParser();
7138 reportParseError(
"unexpected token, expected end of statement");
7141 AssemblerOptions.
back()->setReorder();
7142 getTargetStreamer().emitDirectiveSetReorder();
7147bool MipsAsmParser::parseSetNoReorderDirective() {
7148 MCAsmParser &Parser = getParser();
7152 reportParseError(
"unexpected token, expected end of statement");
7155 AssemblerOptions.
back()->setNoReorder();
7156 getTargetStreamer().emitDirectiveSetNoReorder();
7161bool MipsAsmParser::parseSetMacroDirective() {
7162 MCAsmParser &Parser = getParser();
7166 reportParseError(
"unexpected token, expected end of statement");
7169 AssemblerOptions.
back()->setMacro();
7170 getTargetStreamer().emitDirectiveSetMacro();
7175bool MipsAsmParser::parseSetNoMacroDirective() {
7176 MCAsmParser &Parser = getParser();
7180 reportParseError(
"unexpected token, expected end of statement");
7183 if (AssemblerOptions.
back()->isReorder()) {
7184 reportParseError(
"`noreorder' must be set before `nomacro'");
7187 AssemblerOptions.
back()->setNoMacro();
7188 getTargetStreamer().emitDirectiveSetNoMacro();
7193bool MipsAsmParser::parseSetMsaDirective() {
7194 MCAsmParser &Parser = getParser();
7199 return reportParseError(
"unexpected token, expected end of statement");
7201 setFeatureBits(Mips::FeatureMSA,
"msa");
7202 getTargetStreamer().emitDirectiveSetMsa();
7206bool MipsAsmParser::parseSetNoMsaDirective() {
7207 MCAsmParser &Parser = getParser();
7212 return reportParseError(
"unexpected token, expected end of statement");
7214 clearFeatureBits(Mips::FeatureMSA,
"msa");
7215 getTargetStreamer().emitDirectiveSetNoMsa();
7219bool MipsAsmParser::parseSetNoDspDirective() {
7220 MCAsmParser &Parser = getParser();
7225 reportParseError(
"unexpected token, expected end of statement");
7229 clearFeatureBits(Mips::FeatureDSP,
"dsp");
7230 getTargetStreamer().emitDirectiveSetNoDsp();
7234bool MipsAsmParser::parseSetNoMips3DDirective() {
7235 MCAsmParser &Parser = getParser();
7240 reportParseError(
"unexpected token, expected end of statement");
7244 clearFeatureBits(Mips::FeatureMips3D,
"mips3d");
7245 getTargetStreamer().emitDirectiveSetNoMips3D();
7249bool MipsAsmParser::parseSetMips16Directive() {
7250 MCAsmParser &Parser = getParser();
7255 reportParseError(
"unexpected token, expected end of statement");
7259 clearFeatureBits(Mips::FeatureMicroMips,
"micromips");
7260 setFeatureBits(Mips::FeatureMips16,
"mips16");
7261 getTargetStreamer().emitDirectiveSetMips16();
7266bool MipsAsmParser::parseSetNoMips16Directive() {
7267 MCAsmParser &Parser = getParser();
7272 reportParseError(
"unexpected token, expected end of statement");
7276 clearFeatureBits(Mips::FeatureMips16,
"mips16");
7277 getTargetStreamer().emitDirectiveSetNoMips16();
7282bool MipsAsmParser::parseSetFpDirective() {
7283 MCAsmParser &Parser = getParser();
7289 AsmToken Tok = Parser.
getTok();
7291 reportParseError(
"unexpected token, expected equals sign '='");
7297 if (!parseFpABIValue(FpAbiVal,
".set"))
7301 reportParseError(
"unexpected token, expected end of statement");
7304 getTargetStreamer().emitDirectiveSetFp(FpAbiVal);
7309bool MipsAsmParser::parseSetOddSPRegDirective() {
7310 MCAsmParser &Parser = getParser();
7314 reportParseError(
"unexpected token, expected end of statement");
7318 clearFeatureBits(Mips::FeatureNoOddSPReg,
"nooddspreg");
7319 getTargetStreamer().emitDirectiveSetOddSPReg();
7323bool MipsAsmParser::parseSetNoOddSPRegDirective() {
7324 MCAsmParser &Parser = getParser();
7328 reportParseError(
"unexpected token, expected end of statement");
7332 setFeatureBits(Mips::FeatureNoOddSPReg,
"nooddspreg");
7333 getTargetStreamer().emitDirectiveSetNoOddSPReg();
7337bool MipsAsmParser::parseSetMtDirective() {
7338 MCAsmParser &Parser = getParser();
7343 reportParseError(
"unexpected token, expected end of statement");
7347 setFeatureBits(Mips::FeatureMT,
"mt");
7348 getTargetStreamer().emitDirectiveSetMt();
7353bool MipsAsmParser::parseSetNoMtDirective() {
7354 MCAsmParser &Parser = getParser();
7359 reportParseError(
"unexpected token, expected end of statement");
7363 clearFeatureBits(Mips::FeatureMT,
"mt");
7365 getTargetStreamer().emitDirectiveSetNoMt();
7370bool MipsAsmParser::parseSetNoCRCDirective() {
7371 MCAsmParser &Parser = getParser();
7376 reportParseError(
"unexpected token, expected end of statement");
7380 clearFeatureBits(Mips::FeatureCRC,
"crc");
7382 getTargetStreamer().emitDirectiveSetNoCRC();
7387bool MipsAsmParser::parseSetNoVirtDirective() {
7388 MCAsmParser &Parser = getParser();
7393 reportParseError(
"unexpected token, expected end of statement");
7397 clearFeatureBits(Mips::FeatureVirt,
"virt");
7399 getTargetStreamer().emitDirectiveSetNoVirt();
7404bool MipsAsmParser::parseSetNoGINVDirective() {
7405 MCAsmParser &Parser = getParser();
7410 reportParseError(
"unexpected token, expected end of statement");
7414 clearFeatureBits(Mips::FeatureGINV,
"ginv");
7416 getTargetStreamer().emitDirectiveSetNoGINV();
7421bool MipsAsmParser::parseSetNoEVADirective() {
7422 MCAsmParser &Parser = getParser();
7427 reportParseError(
"unexpected token, expected end of statement");
7431 clearFeatureBits(Mips::FeatureEVA,
"eva");
7433 getTargetStreamer().emitDirectiveSetNoEVA();
7438bool MipsAsmParser::parseSetPopDirective() {
7439 MCAsmParser &Parser = getParser();
7440 SMLoc Loc = getLexer().getLoc();
7444 return reportParseError(
"unexpected token, expected end of statement");
7448 if (AssemblerOptions.
size() == 2)
7449 return reportParseError(Loc,
".set pop with no .set push");
7451 MCSubtargetInfo &STI = copySTI();
7453 setAvailableFeatures(
7454 ComputeAvailableFeatures(AssemblerOptions.
back()->getFeatures()));
7457 getTargetStreamer().emitDirectiveSetPop();
7461bool MipsAsmParser::parseSetPushDirective() {
7462 MCAsmParser &Parser = getParser();
7465 return reportParseError(
"unexpected token, expected end of statement");
7469 std::make_unique<MipsAssemblerOptions>(AssemblerOptions.
back().get()));
7471 getTargetStreamer().emitDirectiveSetPush();
7475bool MipsAsmParser::parseSetSoftFloatDirective() {
7476 MCAsmParser &Parser = getParser();
7479 return reportParseError(
"unexpected token, expected end of statement");
7481 setFeatureBits(Mips::FeatureSoftFloat,
"soft-float");
7482 getTargetStreamer().emitDirectiveSetSoftFloat();
7486bool MipsAsmParser::parseSetHardFloatDirective() {
7487 MCAsmParser &Parser = getParser();
7490 return reportParseError(
"unexpected token, expected end of statement");
7492 clearFeatureBits(Mips::FeatureSoftFloat,
"soft-float");
7493 getTargetStreamer().emitDirectiveSetHardFloat();
7497bool MipsAsmParser::parseSetAssignment() {
7499 MCAsmParser &Parser = getParser();
7502 return reportParseError(
"expected identifier after .set");
7505 return reportParseError(
"unexpected token, expected comma");
7520 const MCExpr *
Value;
7522 Parser, Sym,
Value))
7524 getStreamer().emitAssignment(Sym,
Value);
7529bool MipsAsmParser::parseSetMips0Directive() {
7530 MCAsmParser &Parser = getParser();
7533 return reportParseError(
"unexpected token, expected end of statement");
7536 MCSubtargetInfo &STI = copySTI();
7537 setAvailableFeatures(
7538 ComputeAvailableFeatures(AssemblerOptions.
front()->getFeatures()));
7540 AssemblerOptions.
back()->setFeatures(AssemblerOptions.
front()->getFeatures());
7542 getTargetStreamer().emitDirectiveSetMips0();
7546bool MipsAsmParser::parseSetArchDirective() {
7547 MCAsmParser &Parser = getParser();
7550 return reportParseError(
"unexpected token, expected equals sign");
7553 StringRef Arch = getParser().parseStringToEndOfStatement().trim();
7555 return reportParseError(
"expected arch identifier");
7557 StringRef ArchFeatureName =
7558 StringSwitch<StringRef>(Arch)
7559 .Case(
"mips1",
"mips1")
7560 .Case(
"mips2",
"mips2")
7561 .Case(
"mips3",
"mips3")
7562 .Case(
"mips4",
"mips4")
7563 .Case(
"mips5",
"mips5")
7564 .Case(
"mips32",
"mips32")
7565 .Case(
"mips32r2",
"mips32r2")
7566 .Case(
"mips32r3",
"mips32r3")
7567 .Case(
"mips32r5",
"mips32r5")
7568 .Case(
"mips32r6",
"mips32r6")
7569 .Case(
"mips64",
"mips64")
7570 .Case(
"mips64r2",
"mips64r2")
7571 .Case(
"mips64r3",
"mips64r3")
7572 .Case(
"mips64r5",
"mips64r5")
7573 .Case(
"mips64r6",
"mips64r6")
7574 .Case(
"octeon",
"cnmips")
7575 .Case(
"octeon+",
"cnmipsp")
7576 .Case(
"r4000",
"mips3")
7579 if (ArchFeatureName.
empty())
7580 return reportParseError(
"unsupported architecture");
7582 if (ArchFeatureName ==
"mips64r6" && inMicroMipsMode())
7583 return reportParseError(
"mips64r6 does not support microMIPS");
7585 selectArch(ArchFeatureName);
7586 getTargetStreamer().emitDirectiveSetArch(Arch);
7590bool MipsAsmParser::parseSetFeature(
uint64_t Feature) {
7591 MCAsmParser &Parser = getParser();
7594 return reportParseError(
"unexpected token, expected end of statement");
7599 case Mips::FeatureMips3D:
7600 setFeatureBits(Mips::FeatureMips3D,
"mips3d");
7601 getTargetStreamer().emitDirectiveSetMips3D();
7603 case Mips::FeatureDSP:
7604 setFeatureBits(Mips::FeatureDSP,
"dsp");
7605 getTargetStreamer().emitDirectiveSetDsp();
7607 case Mips::FeatureDSPR2:
7608 setFeatureBits(Mips::FeatureDSPR2,
"dspr2");
7609 getTargetStreamer().emitDirectiveSetDspr2();
7611 case Mips::FeatureMicroMips:
7612 clearFeatureBits(Mips::FeatureMips16,
"mips16");
7613 setFeatureBits(Mips::FeatureMicroMips,
"micromips");
7614 getTargetStreamer().emitDirectiveSetMicroMips();
7616 case Mips::FeatureMips1:
7617 selectArch(
"mips1");
7618 getTargetStreamer().emitDirectiveSetMips1();
7620 case Mips::FeatureMips2:
7621 selectArch(
"mips2");
7622 getTargetStreamer().emitDirectiveSetMips2();
7624 case Mips::FeatureMips3:
7625 selectArch(
"mips3");
7626 getTargetStreamer().emitDirectiveSetMips3();
7628 case Mips::FeatureMips4:
7629 selectArch(
"mips4");
7630 getTargetStreamer().emitDirectiveSetMips4();
7632 case Mips::FeatureMips5:
7633 selectArch(
"mips5");
7634 getTargetStreamer().emitDirectiveSetMips5();
7636 case Mips::FeatureMips32:
7637 selectArch(
"mips32");
7638 getTargetStreamer().emitDirectiveSetMips32();
7640 case Mips::FeatureMips32r2:
7641 selectArch(
"mips32r2");
7642 getTargetStreamer().emitDirectiveSetMips32R2();
7644 case Mips::FeatureMips32r3:
7645 selectArch(
"mips32r3");
7646 getTargetStreamer().emitDirectiveSetMips32R3();
7648 case Mips::FeatureMips32r5:
7649 selectArch(
"mips32r5");
7650 getTargetStreamer().emitDirectiveSetMips32R5();
7652 case Mips::FeatureMips32r6:
7653 selectArch(
"mips32r6");
7654 getTargetStreamer().emitDirectiveSetMips32R6();
7656 case Mips::FeatureMips64:
7657 selectArch(
"mips64");
7658 getTargetStreamer().emitDirectiveSetMips64();
7660 case Mips::FeatureMips64r2:
7661 selectArch(
"mips64r2");
7662 getTargetStreamer().emitDirectiveSetMips64R2();
7664 case Mips::FeatureMips64r3:
7665 selectArch(
"mips64r3");
7666 getTargetStreamer().emitDirectiveSetMips64R3();
7668 case Mips::FeatureMips64r5:
7669 selectArch(
"mips64r5");
7670 getTargetStreamer().emitDirectiveSetMips64R5();
7672 case Mips::FeatureMips64r6:
7673 selectArch(
"mips64r6");
7674 getTargetStreamer().emitDirectiveSetMips64R6();
7676 case Mips::FeatureCRC:
7677 setFeatureBits(Mips::FeatureCRC,
"crc");
7678 getTargetStreamer().emitDirectiveSetCRC();
7680 case Mips::FeatureVirt:
7681 setFeatureBits(Mips::FeatureVirt,
"virt");
7682 getTargetStreamer().emitDirectiveSetVirt();
7684 case Mips::FeatureGINV:
7685 setFeatureBits(Mips::FeatureGINV,
"ginv");
7686 getTargetStreamer().emitDirectiveSetGINV();
7688 case Mips::FeatureEVA:
7689 setFeatureBits(Mips::FeatureEVA,
"eva");
7690 getTargetStreamer().emitDirectiveSetEVA();
7696bool MipsAsmParser::eatComma(StringRef ErrorStr) {
7697 MCAsmParser &Parser = getParser();
7699 SMLoc Loc = getLexer().getLoc();
7700 return Error(Loc, ErrorStr);
7711bool MipsAsmParser::isPicAndNotNxxAbi() {
7712 return inPicMode() && !(isABI_N32() || isABI_N64());
7715bool MipsAsmParser::parseDirectiveCpAdd(SMLoc Loc) {
7717 ParseStatus Res = parseAnyRegister(
Reg);
7719 reportParseError(
"expected register");
7723 MipsOperand &RegOpnd =
static_cast<MipsOperand &
>(*
Reg[0]);
7724 if (!RegOpnd.isGPRAsmReg()) {
7725 reportParseError(RegOpnd.getStartLoc(),
"invalid register");
7731 reportParseError(
"unexpected token, expected end of statement");
7736 getTargetStreamer().emitDirectiveCpAdd(RegOpnd.getGPR32Reg());
7740bool MipsAsmParser::parseDirectiveCpLoad(SMLoc Loc) {
7741 if (AssemblerOptions.
back()->isReorder())
7742 Warning(Loc,
".cpload should be inside a noreorder section");
7744 if (inMips16Mode()) {
7745 reportParseError(
".cpload is not supported in Mips16 mode");
7750 ParseStatus Res = parseAnyRegister(
Reg);
7752 reportParseError(
"expected register containing function address");
7756 MipsOperand &RegOpnd =
static_cast<MipsOperand &
>(*
Reg[0]);
7757 if (!RegOpnd.isGPRAsmReg()) {
7758 reportParseError(RegOpnd.getStartLoc(),
"invalid register");
7764 reportParseError(
"unexpected token, expected end of statement");
7768 getTargetStreamer().emitDirectiveCpLoad(RegOpnd.getGPR32Reg());
7772bool MipsAsmParser::parseDirectiveCpLocal(SMLoc Loc) {
7773 if (!isABI_N32() && !isABI_N64()) {
7774 reportParseError(
".cplocal is allowed only in N32 or N64 mode");
7779 ParseStatus Res = parseAnyRegister(
Reg);
7781 reportParseError(
"expected register containing global pointer");
7785 MipsOperand &RegOpnd =
static_cast<MipsOperand &
>(*
Reg[0]);
7786 if (!RegOpnd.isGPRAsmReg()) {
7787 reportParseError(RegOpnd.getStartLoc(),
"invalid register");
7793 reportParseError(
"unexpected token, expected end of statement");
7798 MCRegister NewReg = RegOpnd.getGPR32Reg();
7802 getTargetStreamer().emitDirectiveCpLocal(NewReg);
7806bool MipsAsmParser::parseDirectiveCpRestore(SMLoc Loc) {
7807 MCAsmParser &Parser = getParser();
7812 if (inMips16Mode()) {
7813 reportParseError(
".cprestore is not supported in Mips16 mode");
7818 const MCExpr *StackOffset;
7819 int64_t StackOffsetVal;
7821 reportParseError(
"expected stack offset value");
7825 if (!StackOffset->evaluateAsAbsolute(StackOffsetVal)) {
7826 reportParseError(
"stack offset is not an absolute expression");
7830 if (StackOffsetVal < 0) {
7831 Warning(Loc,
".cprestore with negative stack offset has no effect");
7832 IsCpRestoreSet =
false;
7834 IsCpRestoreSet =
true;
7835 CpRestoreOffset = StackOffsetVal;
7840 reportParseError(
"unexpected token, expected end of statement");
7844 if (!getTargetStreamer().emitDirectiveCpRestore(
7845 CpRestoreOffset, [&]() {
return getATReg(Loc); }, Loc, STI))
7851bool MipsAsmParser::parseDirectiveCPSetup() {
7852 MCAsmParser &Parser = getParser();
7854 bool SaveIsReg =
true;
7857 ParseStatus Res = parseAnyRegister(TmpReg);
7859 reportParseError(
"expected register containing function address");
7863 MipsOperand &FuncRegOpnd =
static_cast<MipsOperand &
>(*TmpReg[0]);
7864 if (!FuncRegOpnd.isGPRAsmReg()) {
7865 reportParseError(FuncRegOpnd.getStartLoc(),
"invalid register");
7869 MCRegister FuncReg = FuncRegOpnd.getGPR32Reg();
7872 if (!eatComma(
"unexpected token, expected comma"))
7875 Res = parseAnyRegister(TmpReg);
7877 const MCExpr *OffsetExpr;
7879 SMLoc ExprLoc = getLexer().
getLoc();
7882 !OffsetExpr->evaluateAsAbsolute(OffsetVal)) {
7883 reportParseError(ExprLoc,
"expected save register or stack offset");
7890 MipsOperand &SaveOpnd =
static_cast<MipsOperand &
>(*TmpReg[0]);
7891 if (!SaveOpnd.isGPRAsmReg()) {
7892 reportParseError(SaveOpnd.getStartLoc(),
"invalid register");
7895 Save = SaveOpnd.getGPR32Reg().id();
7898 if (!eatComma(
"unexpected token, expected comma"))
7903 reportParseError(
"expected expression");
7908 reportParseError(
"expected symbol");
7911 const MCSymbolRefExpr *
Ref =
static_cast<const MCSymbolRefExpr *
>(Expr);
7913 CpSaveLocation = Save;
7914 CpSaveLocationIsRegister = SaveIsReg;
7916 getTargetStreamer().emitDirectiveCpsetup(FuncReg, Save,
Ref->getSymbol(),
7921bool MipsAsmParser::parseDirectiveCPReturn() {
7922 getTargetStreamer().emitDirectiveCpreturn(CpSaveLocation,
7923 CpSaveLocationIsRegister);
7927bool MipsAsmParser::parseDirectiveNaN() {
7928 MCAsmParser &Parser = getParser();
7930 const AsmToken &Tok = Parser.
getTok();
7934 getTargetStreamer().emitDirectiveNaN2008();
7936 }
else if (Tok.
getString() ==
"legacy") {
7938 getTargetStreamer().emitDirectiveNaNLegacy();
7944 reportParseError(
"invalid option in .nan directive");
7948bool MipsAsmParser::parseDirectiveSet() {
7949 const AsmToken &Tok = getParser().getTok();
7951 SMLoc Loc = Tok.
getLoc();
7953 if (IdVal ==
"noat")
7954 return parseSetNoAtDirective();
7956 return parseSetAtDirective();
7957 if (IdVal ==
"arch")
7958 return parseSetArchDirective();
7959 if (IdVal ==
"bopt") {
7960 Warning(Loc,
"'bopt' feature is unsupported");
7964 if (IdVal ==
"nobopt") {
7970 return parseSetFpDirective();
7971 if (IdVal ==
"oddspreg")
7972 return parseSetOddSPRegDirective();
7973 if (IdVal ==
"nooddspreg")
7974 return parseSetNoOddSPRegDirective();
7976 return parseSetPopDirective();
7977 if (IdVal ==
"push")
7978 return parseSetPushDirective();
7979 if (IdVal ==
"reorder")
7980 return parseSetReorderDirective();
7981 if (IdVal ==
"noreorder")
7982 return parseSetNoReorderDirective();
7983 if (IdVal ==
"macro")
7984 return parseSetMacroDirective();
7985 if (IdVal ==
"nomacro")
7986 return parseSetNoMacroDirective();
7987 if (IdVal ==
"mips16")
7988 return parseSetMips16Directive();
7989 if (IdVal ==
"nomips16")
7990 return parseSetNoMips16Directive();
7991 if (IdVal ==
"nomicromips") {
7992 clearFeatureBits(Mips::FeatureMicroMips,
"micromips");
7993 getTargetStreamer().emitDirectiveSetNoMicroMips();
7994 getParser().eatToEndOfStatement();
7997 if (IdVal ==
"micromips") {
7998 if (hasMips64r6()) {
7999 Error(Loc,
".set micromips directive is not supported with MIPS64R6");
8002 return parseSetFeature(Mips::FeatureMicroMips);
8004 if (IdVal ==
"mips0")
8005 return parseSetMips0Directive();
8006 if (IdVal ==
"mips1")
8007 return parseSetFeature(Mips::FeatureMips1);
8008 if (IdVal ==
"mips2")
8009 return parseSetFeature(Mips::FeatureMips2);
8010 if (IdVal ==
"mips3")
8011 return parseSetFeature(Mips::FeatureMips3);
8012 if (IdVal ==
"mips4")
8013 return parseSetFeature(Mips::FeatureMips4);
8014 if (IdVal ==
"mips5")
8015 return parseSetFeature(Mips::FeatureMips5);
8016 if (IdVal ==
"mips32")
8017 return parseSetFeature(Mips::FeatureMips32);
8018 if (IdVal ==
"mips32r2")
8019 return parseSetFeature(Mips::FeatureMips32r2);
8020 if (IdVal ==
"mips32r3")
8021 return parseSetFeature(Mips::FeatureMips32r3);
8022 if (IdVal ==
"mips32r5")
8023 return parseSetFeature(Mips::FeatureMips32r5);
8024 if (IdVal ==
"mips32r6")
8025 return parseSetFeature(Mips::FeatureMips32r6);
8026 if (IdVal ==
"mips64")
8027 return parseSetFeature(Mips::FeatureMips64);
8028 if (IdVal ==
"mips64r2")
8029 return parseSetFeature(Mips::FeatureMips64r2);
8030 if (IdVal ==
"mips64r3")
8031 return parseSetFeature(Mips::FeatureMips64r3);
8032 if (IdVal ==
"mips64r5")
8033 return parseSetFeature(Mips::FeatureMips64r5);
8034 if (IdVal ==
"mips64r6") {
8035 if (inMicroMipsMode()) {
8036 Error(Loc,
"MIPS64R6 is not supported with microMIPS");
8039 return parseSetFeature(Mips::FeatureMips64r6);
8042 return parseSetFeature(Mips::FeatureDSP);
8043 if (IdVal ==
"dspr2")
8044 return parseSetFeature(Mips::FeatureDSPR2);
8045 if (IdVal ==
"nodsp")
8046 return parseSetNoDspDirective();
8047 if (IdVal ==
"mips3d")
8048 return parseSetFeature(Mips::FeatureMips3D);
8049 if (IdVal ==
"nomips3d")
8050 return parseSetNoMips3DDirective();
8052 return parseSetMsaDirective();
8053 if (IdVal ==
"nomsa")
8054 return parseSetNoMsaDirective();
8056 return parseSetMtDirective();
8057 if (IdVal ==
"nomt")
8058 return parseSetNoMtDirective();
8059 if (IdVal ==
"softfloat")
8060 return parseSetSoftFloatDirective();
8061 if (IdVal ==
"hardfloat")
8062 return parseSetHardFloatDirective();
8064 return parseSetFeature(Mips::FeatureCRC);
8065 if (IdVal ==
"nocrc")
8066 return parseSetNoCRCDirective();
8067 if (IdVal ==
"virt")
8068 return parseSetFeature(Mips::FeatureVirt);
8069 if (IdVal ==
"novirt")
8070 return parseSetNoVirtDirective();
8071 if (IdVal ==
"ginv")
8072 return parseSetFeature(Mips::FeatureGINV);
8073 if (IdVal ==
"noginv")
8074 return parseSetNoGINVDirective();
8076 return parseSetFeature(Mips::FeatureEVA);
8077 if (IdVal ==
"noeva")
8078 return parseSetNoEVADirective();
8081 return parseSetAssignment();
8086bool MipsAsmParser::parseDirectiveGpWord() {
8087 const MCExpr *
Value;
8088 if (getParser().parseExpression(
Value))
8090 getTargetStreamer().emitGPRel32Value(
Value);
8096bool MipsAsmParser::parseDirectiveGpDWord() {
8097 const MCExpr *
Value;
8098 if (getParser().parseExpression(
Value))
8100 getTargetStreamer().emitGPRel64Value(
Value);
8106bool MipsAsmParser::parseDirectiveDtpRelWord() {
8107 const MCExpr *
Value;
8108 if (getParser().parseExpression(
Value))
8110 getTargetStreamer().emitDTPRel32Value(
Value);
8116bool MipsAsmParser::parseDirectiveDtpRelDWord() {
8117 const MCExpr *
Value;
8118 if (getParser().parseExpression(
Value))
8120 getTargetStreamer().emitDTPRel64Value(
Value);
8126bool MipsAsmParser::parseDirectiveTpRelWord() {
8127 const MCExpr *
Value;
8128 if (getParser().parseExpression(
Value))
8130 getTargetStreamer().emitTPRel32Value(
Value);
8136bool MipsAsmParser::parseDirectiveTpRelDWord() {
8137 const MCExpr *
Value;
8138 if (getParser().parseExpression(
Value))
8140 getTargetStreamer().emitTPRel64Value(
Value);
8144bool MipsAsmParser::parseDirectiveOption() {
8145 MCAsmParser &Parser = getParser();
8147 AsmToken Tok = Parser.
getTok();
8151 "unexpected token, expected identifier");
8156 if (Option ==
"pic0") {
8158 IsPicEnabled =
false;
8160 getTargetStreamer().emitDirectiveOptionPic0();
8164 "unexpected token, expected end of statement");
8169 if (Option ==
"pic2") {
8171 IsPicEnabled =
true;
8173 getTargetStreamer().emitDirectiveOptionPic2();
8177 "unexpected token, expected end of statement");
8184 "unknown option, expected 'pic0' or 'pic2'");
8191bool MipsAsmParser::parseInsnDirective() {
8194 reportParseError(
"unexpected token, expected end of statement");
8200 getTargetStreamer().emitDirectiveInsn();
8208bool MipsAsmParser::parseRSectionDirective(StringRef Section) {
8211 reportParseError(
"unexpected token, expected end of statement");
8215 MCSection *ELFSection =
getContext().getELFSection(
8217 getParser().getStreamer().switchSection(ELFSection);
8226bool MipsAsmParser::parseSSectionDirective(StringRef Section,
unsigned Type) {
8229 reportParseError(
"unexpected token, expected end of statement");
8233 MCSection *ELFSection =
getContext().getELFSection(
8235 getParser().getStreamer().switchSection(ELFSection);
8254bool MipsAsmParser::parseDirectiveModule() {
8255 MCAsmParser &Parser = getParser();
8256 AsmLexer &Lexer = getLexer();
8259 if (!getTargetStreamer().isModuleDirectiveAllowed()) {
8261 reportParseError(
".module directive must appear before any code");
8267 reportParseError(
"expected .module option identifier");
8271 if (Option ==
"oddspreg") {
8272 clearModuleFeatureBits(Mips::FeatureNoOddSPReg,
"nooddspreg");
8276 getTargetStreamer().updateABIInfo(*
this);
8281 getTargetStreamer().emitDirectiveModuleOddSPReg();
8285 reportParseError(
"unexpected token, expected end of statement");
8290 }
else if (Option ==
"nooddspreg") {
8292 return Error(L,
"'.module nooddspreg' requires the O32 ABI");
8295 setModuleFeatureBits(Mips::FeatureNoOddSPReg,
"nooddspreg");
8299 getTargetStreamer().updateABIInfo(*
this);
8304 getTargetStreamer().emitDirectiveModuleOddSPReg();
8308 reportParseError(
"unexpected token, expected end of statement");
8313 }
else if (Option ==
"fp") {
8314 return parseDirectiveModuleFP();
8315 }
else if (Option ==
"softfloat") {
8316 setModuleFeatureBits(Mips::FeatureSoftFloat,
"soft-float");
8320 getTargetStreamer().updateABIInfo(*
this);
8325 getTargetStreamer().emitDirectiveModuleSoftFloat();
8329 reportParseError(
"unexpected token, expected end of statement");
8334 }
else if (Option ==
"hardfloat") {
8335 clearModuleFeatureBits(Mips::FeatureSoftFloat,
"soft-float");
8339 getTargetStreamer().updateABIInfo(*
this);
8344 getTargetStreamer().emitDirectiveModuleHardFloat();
8348 reportParseError(
"unexpected token, expected end of statement");
8353 }
else if (Option ==
"mt") {
8354 setModuleFeatureBits(Mips::FeatureMT,
"mt");
8358 getTargetStreamer().updateABIInfo(*
this);
8363 getTargetStreamer().emitDirectiveModuleMT();
8367 reportParseError(
"unexpected token, expected end of statement");
8372 }
else if (Option ==
"crc") {
8373 setModuleFeatureBits(Mips::FeatureCRC,
"crc");
8377 getTargetStreamer().updateABIInfo(*
this);
8382 getTargetStreamer().emitDirectiveModuleCRC();
8386 reportParseError(
"unexpected token, expected end of statement");
8391 }
else if (Option ==
"nocrc") {
8392 clearModuleFeatureBits(Mips::FeatureCRC,
"crc");
8396 getTargetStreamer().updateABIInfo(*
this);
8401 getTargetStreamer().emitDirectiveModuleNoCRC();
8405 reportParseError(
"unexpected token, expected end of statement");
8410 }
else if (Option ==
"virt") {
8411 setModuleFeatureBits(Mips::FeatureVirt,
"virt");
8415 getTargetStreamer().updateABIInfo(*
this);
8420 getTargetStreamer().emitDirectiveModuleVirt();
8424 reportParseError(
"unexpected token, expected end of statement");
8429 }
else if (Option ==
"novirt") {
8430 clearModuleFeatureBits(Mips::FeatureVirt,
"virt");
8434 getTargetStreamer().updateABIInfo(*
this);
8439 getTargetStreamer().emitDirectiveModuleNoVirt();
8443 reportParseError(
"unexpected token, expected end of statement");
8448 }
else if (Option ==
"ginv") {
8449 setModuleFeatureBits(Mips::FeatureGINV,
"ginv");
8453 getTargetStreamer().updateABIInfo(*
this);
8458 getTargetStreamer().emitDirectiveModuleGINV();
8462 reportParseError(
"unexpected token, expected end of statement");
8467 }
else if (Option ==
"noginv") {
8468 clearModuleFeatureBits(Mips::FeatureGINV,
"ginv");
8472 getTargetStreamer().updateABIInfo(*
this);
8477 getTargetStreamer().emitDirectiveModuleNoGINV();
8481 reportParseError(
"unexpected token, expected end of statement");
8487 return Error(L,
"'" + Twine(Option) +
"' is not a valid .module option.");
8495bool MipsAsmParser::parseDirectiveModuleFP() {
8496 MCAsmParser &Parser = getParser();
8497 AsmLexer &Lexer = getLexer();
8500 reportParseError(
"unexpected token, expected equals sign '='");
8506 if (!parseFpABIValue(FpABI,
".module"))
8510 reportParseError(
"unexpected token, expected end of statement");
8516 getTargetStreamer().updateABIInfo(*
this);
8521 getTargetStreamer().emitDirectiveModuleFP();
8528 StringRef Directive) {
8529 MCAsmParser &Parser = getParser();
8530 AsmLexer &Lexer = getLexer();
8531 bool ModuleLevelOptions = Directive ==
".module";
8537 if (
Value !=
"xx") {
8538 reportParseError(
"unsupported value, expected 'xx', '32' or '64'");
8543 reportParseError(
"'" + Directive +
" fp=xx' requires the O32 ABI");
8547 FpABI = MipsABIFlagsSection::FpABIKind::XX;
8548 if (ModuleLevelOptions) {
8549 setModuleFeatureBits(Mips::FeatureFPXX,
"fpxx");
8550 clearModuleFeatureBits(Mips::FeatureFP64Bit,
"fp64");
8552 setFeatureBits(Mips::FeatureFPXX,
"fpxx");
8553 clearFeatureBits(Mips::FeatureFP64Bit,
"fp64");
8563 reportParseError(
"unsupported value, expected 'xx', '32' or '64'");
8569 reportParseError(
"'" + Directive +
" fp=32' requires the O32 ABI");
8573 FpABI = MipsABIFlagsSection::FpABIKind::S32;
8574 if (ModuleLevelOptions) {
8575 clearModuleFeatureBits(Mips::FeatureFPXX,
"fpxx");
8576 clearModuleFeatureBits(Mips::FeatureFP64Bit,
"fp64");
8578 clearFeatureBits(Mips::FeatureFPXX,
"fpxx");
8579 clearFeatureBits(Mips::FeatureFP64Bit,
"fp64");
8582 FpABI = MipsABIFlagsSection::FpABIKind::S64;
8583 if (ModuleLevelOptions) {
8584 clearModuleFeatureBits(Mips::FeatureFPXX,
"fpxx");
8585 setModuleFeatureBits(Mips::FeatureFP64Bit,
"fp64");
8587 clearFeatureBits(Mips::FeatureFPXX,
"fpxx");
8588 setFeatureBits(Mips::FeatureFP64Bit,
"fp64");
8598bool MipsAsmParser::ParseDirective(AsmToken DirectiveID) {
8604 MCAsmParser &Parser = getParser();
8605 StringRef IDVal = DirectiveID.
getString();
8607 if (IDVal ==
".cpadd") {
8608 parseDirectiveCpAdd(DirectiveID.
getLoc());
8611 if (IDVal ==
".cpload") {
8612 parseDirectiveCpLoad(DirectiveID.
getLoc());
8615 if (IDVal ==
".cprestore") {
8616 parseDirectiveCpRestore(DirectiveID.
getLoc());
8619 if (IDVal ==
".cplocal") {
8620 parseDirectiveCpLocal(DirectiveID.
getLoc());
8623 if (IDVal ==
".ent") {
8627 reportParseError(
"expected identifier after .ent");
8641 reportParseError(
"unexpected token, expected end of statement");
8645 const MCExpr *DummyNumber;
8646 int64_t DummyNumberVal;
8650 reportParseError(
"expected number after comma");
8653 if (!DummyNumber->evaluateAsAbsolute(DummyNumberVal)) {
8654 reportParseError(
"expected an absolute expression after comma");
8661 reportParseError(
"unexpected token, expected end of statement");
8667 getTargetStreamer().emitDirectiveEnt(*Sym);
8669 IsCpRestoreSet =
false;
8673 if (IDVal ==
".end") {
8677 reportParseError(
"expected identifier after .end");
8682 reportParseError(
"unexpected token, expected end of statement");
8686 if (CurrentFn ==
nullptr) {
8687 reportParseError(
".end used without .ent");
8691 if ((SymbolName != CurrentFn->
getName())) {
8692 reportParseError(
".end symbol does not match .ent symbol");
8696 getTargetStreamer().emitDirectiveEnd(SymbolName);
8697 CurrentFn =
nullptr;
8698 IsCpRestoreSet =
false;
8702 if (IDVal ==
".frame") {
8705 ParseStatus Res = parseAnyRegister(TmpReg);
8707 reportParseError(
"expected stack register");
8711 MipsOperand &StackRegOpnd =
static_cast<MipsOperand &
>(*TmpReg[0]);
8712 if (!StackRegOpnd.isGPRAsmReg()) {
8713 reportParseError(StackRegOpnd.getStartLoc(),
8714 "expected general purpose register");
8717 MCRegister StackReg = StackRegOpnd.getGPR32Reg();
8722 reportParseError(
"unexpected token, expected comma");
8727 const MCExpr *FrameSize;
8728 int64_t FrameSizeVal;
8731 reportParseError(
"expected frame size value");
8735 if (!FrameSize->evaluateAsAbsolute(FrameSizeVal)) {
8736 reportParseError(
"frame size not an absolute expression");
8743 reportParseError(
"unexpected token, expected comma");
8749 Res = parseAnyRegister(TmpReg);
8751 reportParseError(
"expected return register");
8755 MipsOperand &ReturnRegOpnd =
static_cast<MipsOperand &
>(*TmpReg[0]);
8756 if (!ReturnRegOpnd.isGPRAsmReg()) {
8757 reportParseError(ReturnRegOpnd.getStartLoc(),
8758 "expected general purpose register");
8764 reportParseError(
"unexpected token, expected end of statement");
8768 getTargetStreamer().emitFrame(StackReg, FrameSizeVal,
8769 ReturnRegOpnd.getGPR32Reg());
8770 IsCpRestoreSet =
false;
8774 if (IDVal ==
".set") {
8775 parseDirectiveSet();
8779 if (IDVal ==
".mask" || IDVal ==
".fmask") {
8790 const MCExpr *BitMask;
8794 reportParseError(
"expected bitmask value");
8798 if (!BitMask->evaluateAsAbsolute(BitMaskVal)) {
8799 reportParseError(
"bitmask not an absolute expression");
8806 reportParseError(
"unexpected token, expected comma");
8811 const MCExpr *FrameOffset;
8812 int64_t FrameOffsetVal;
8815 reportParseError(
"expected frame offset value");
8819 if (!FrameOffset->evaluateAsAbsolute(FrameOffsetVal)) {
8820 reportParseError(
"frame offset not an absolute expression");
8826 reportParseError(
"unexpected token, expected end of statement");
8830 if (IDVal ==
".mask")
8831 getTargetStreamer().emitMask(BitMaskVal, FrameOffsetVal);
8833 getTargetStreamer().emitFMask(BitMaskVal, FrameOffsetVal);
8837 if (IDVal ==
".nan")
8838 return parseDirectiveNaN();
8840 if (IDVal ==
".gpword") {
8841 parseDirectiveGpWord();
8845 if (IDVal ==
".gpdword") {
8846 parseDirectiveGpDWord();
8850 if (IDVal ==
".dtprelword") {
8851 parseDirectiveDtpRelWord();
8855 if (IDVal ==
".dtpreldword") {
8856 parseDirectiveDtpRelDWord();
8860 if (IDVal ==
".tprelword") {
8861 parseDirectiveTpRelWord();
8865 if (IDVal ==
".tpreldword") {
8866 parseDirectiveTpRelDWord();
8870 if (IDVal ==
".option") {
8871 parseDirectiveOption();
8875 if (IDVal ==
".abicalls") {
8876 getTargetStreamer().emitDirectiveAbiCalls();
8879 "unexpected token, expected end of statement");
8884 if (IDVal ==
".cpsetup") {
8885 parseDirectiveCPSetup();
8888 if (IDVal ==
".cpreturn") {
8889 parseDirectiveCPReturn();
8892 if (IDVal ==
".module") {
8893 parseDirectiveModule();
8896 if (IDVal ==
".llvm_internal_mips_reallow_module_directive") {
8897 parseInternalDirectiveReallowModule();
8900 if (IDVal ==
".insn") {
8901 parseInsnDirective();
8904 if (IDVal ==
".rdata") {
8905 parseRSectionDirective(
".rodata");
8908 if (IDVal ==
".sbss") {
8912 if (IDVal ==
".sdata") {
8920bool MipsAsmParser::parseInternalDirectiveReallowModule() {
8923 reportParseError(
"unexpected token, expected end of statement");
8927 getTargetStreamer().reallowModuleDirective();
8941#define GET_REGISTER_MATCHER
8942#define GET_MATCHER_IMPLEMENTATION
8943#define GET_MNEMONIC_SPELL_CHECKER
8944#include "MipsGenAsmMatcher.inc"
8946bool MipsAsmParser::mnemonicIsValid(
StringRef Mnemonic,
unsigned VariantID) {
8948 const MatchEntry *Start, *
End;
8949 switch (VariantID) {
8951 case 0: Start = std::begin(MatchTable0);
End = std::end(MatchTable0);
break;
8954 auto MnemonicRange = std::equal_range(Start,
End, Mnemonic, LessOpcode());
8955 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 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,...