52#define DEBUG_TYPE "riscv-asm-parser"
55 "Number of RISC-V Compressed instructions emitted");
60struct ParserOptionsSet {
65 const RISCVMCOptions &CLOpts;
69 enum class VTypeState {
80 ParserOptionsSet ParserOptions;
82 SMLoc getLoc()
const {
return getParser().
getTok().
getLoc(); }
83 bool isRV64()
const {
return getSTI().hasFeature(RISCV::Feature64Bit); }
84 bool isRVE()
const {
return getSTI().hasFeature(RISCV::FeatureStdExtE); }
85 bool enableExperimentalExtension()
const {
86 return getSTI().hasFeature(RISCV::Experimental);
89 RISCVTargetStreamer &getTargetStreamer() {
90 assert(getParser().getStreamer().getTargetStreamer() &&
91 "do not have a target streamer");
92 MCTargetStreamer &TS = *getParser().getStreamer().getTargetStreamer();
93 return static_cast<RISCVTargetStreamer &
>(TS);
96 bool generateImmOutOfRangeError(SMLoc ErrorLoc, int64_t
Lower, int64_t
Upper,
99 struct NearMissMessage {
104 std::string getCustomOperandDiag(
unsigned MatchError);
106 void FilterNearMisses(SmallVectorImpl<NearMissInfo> &NearMissesIn,
107 SmallVectorImpl<NearMissMessage> &NearMissesOut,
109 void ReportNearMisses(SmallVectorImpl<NearMissInfo> &NearMisses, SMLoc IDLoc,
112 bool matchAndEmitInstruction(SMLoc IDLoc,
unsigned &Opcode,
115 bool MatchingInlineAsm)
override;
118 bool parseRegister(MCRegister &
Reg, SMLoc &StartLoc, SMLoc &EndLoc)
override;
119 ParseStatus tryParseRegister(MCRegister &
Reg, SMLoc &StartLoc,
120 SMLoc &EndLoc)
override;
122 bool parseInstruction(ParseInstructionInfo &Info, StringRef Name,
125 ParseStatus parseDirective(AsmToken DirectiveID)
override;
127 bool parseVTypeToken(
const AsmToken &Tok, VTypeState &State,
unsigned &Sew,
128 unsigned &Lmul,
bool &Fractional,
bool &TailAgnostic,
129 bool &MaskAgnostic,
bool &AltFmt);
130 bool generateVTypeError(SMLoc ErrorLoc);
132 bool generateXSfmmVTypeError(SMLoc ErrorLoc);
135 void emitToStreamer(MCStreamer &S,
const MCInst &Inst);
139 void emitLoadImm(MCRegister DestReg, int64_t
Value, MCStreamer &Out);
143 void emitAuipcInstPair(MCRegister DestReg, MCRegister TmpReg,
145 unsigned SecondOpcode, SMLoc IDLoc, MCStreamer &Out);
148 void emitLoadLocalAddress(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out);
151 void emitLoadGlobalAddress(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out);
154 void emitLoadAddress(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out);
158 void emitLoadTLSIEAddress(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out);
162 void emitLoadTLSGDAddress(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out);
165 void emitLoadStoreSymbol(MCInst &Inst,
unsigned Opcode, SMLoc IDLoc,
166 MCStreamer &Out,
bool HasTmpReg);
171 void emitQCELILoadStoreSymbol(MCInst &Inst,
unsigned Opcode, SMLoc IDLoc,
172 MCStreamer &Out,
bool HasTmpReg);
175 void emitPseudoExtend(MCInst &Inst,
bool SignExtend, int64_t Width,
176 SMLoc IDLoc, MCStreamer &Out);
179 void emitVMSGE(MCInst &Inst,
unsigned Opcode, SMLoc IDLoc, MCStreamer &Out);
204#define GET_ASSEMBLER_HEADER
205#include "RISCVGenAsmMatcher.inc"
230 return parseRegList(
Operands,
true);
236 bool ExpectNegative =
false);
238 return parseZcmpStackAdj(
Operands,
true);
242 bool parseExprWithSpecifier(
const MCExpr *&Res, SMLoc &
E);
243 bool parseDataExpr(
const MCExpr *&Res)
override;
245 bool parseDirectiveOption();
246 bool parseDirectiveAttribute();
247 bool parseDirectiveInsn(SMLoc L);
248 bool parseDirectiveVariantCC();
253 bool resetToArch(StringRef Arch, SMLoc Loc, std::string &Result,
254 bool FromOptionDirective);
256 void setFeatureBits(
uint64_t Feature, StringRef FeatureString) {
258 MCSubtargetInfo &STI = copySTI();
264 setAvailableFeatures(ComputeAvailableFeatures(STI.
getFeatureBits()));
268 void clearFeatureBits(
uint64_t Feature, StringRef FeatureString) {
270 MCSubtargetInfo &STI = copySTI();
271 setAvailableFeatures(
276 void pushFeatureBits() {
277 assert(FeatureBitStack.size() == ParserOptionsStack.size() &&
278 "These two stacks must be kept synchronized");
279 FeatureBitStack.push_back(getSTI().getFeatureBits());
280 ParserOptionsStack.push_back(ParserOptions);
283 bool popFeatureBits() {
284 assert(FeatureBitStack.size() == ParserOptionsStack.size() &&
285 "These two stacks must be kept synchronized");
286 if (FeatureBitStack.empty())
289 FeatureBitset FeatureBits = FeatureBitStack.pop_back_val();
290 copySTI().setFeatureBits(FeatureBits);
291 setAvailableFeatures(ComputeAvailableFeatures(FeatureBits));
293 ParserOptions = ParserOptionsStack.pop_back_val();
298 std::unique_ptr<RISCVOperand> defaultMaskRegOp()
const;
299 std::unique_ptr<RISCVOperand> defaultFRMArgOp()
const;
300 std::unique_ptr<RISCVOperand> defaultFRMArgLegacyOp()
const;
301 std::unique_ptr<RISCVOperand> defaultSMTVType();
302 std::unique_ptr<RISCVOperand> defaultZeroOffset();
305 enum RISCVMatchResultTy :
unsigned {
306 Match_Dummy = FIRST_TARGET_MATCH_RESULT_TY,
307#define GET_OPERAND_DIAGNOSTIC_TYPES
308#include "RISCVGenAsmMatcher.inc"
309#undef GET_OPERAND_DIAGNOSTIC_TYPES
313 static bool isSymbolDiff(
const MCExpr *Expr);
315 RISCVAsmParser(
const MCSubtargetInfo &STI, MCAsmParser &Parser,
316 const MCInstrInfo &MII)
317 : MCTargetAsmParser(STI, MII),
325 setAvailableFeatures(ComputeAvailableFeatures(STI.
getFeatureBits()));
330 if (CLOpts.add_build_attributes)
331 getTargetStreamer().emitTargetAttributes(STI,
false);
337 void onBeginOfFile()
override {
340 if (getTargetStreamer().hasTargetABI())
343 Expected<RISCVABI::ABI> ABIOrErr =
347 getTargetStreamer().setTargetABI(
351 getTargetStreamer().setTargetABI(*ABIOrErr);
417 MCRegister OffsetReg;
420 SMLoc StartLoc, EndLoc;
436 RISCVOperand(KindTy K) : Kind(
K) {}
439 RISCVOperand(
const RISCVOperand &o) : MCParsedAsmOperand() {
441 StartLoc =
o.StartLoc;
444 case KindTy::Register:
447 case KindTy::Expression:
450 case KindTy::FPImmediate:
456 case KindTy::SystemRegister:
462 case KindTy::SMTVType:
463 SMTVType =
o.SMTVType;
471 case KindTy::RegList:
474 case KindTy::StackAdj:
475 StackAdj =
o.StackAdj;
483 bool isToken()
const override {
return Kind == KindTy::Token; }
484 bool isReg()
const override {
return Kind == KindTy::Register; }
485 bool isExpr()
const {
return Kind == KindTy::Expression; }
486 bool isV0Reg()
const {
return Kind == KindTy::Register &&
Reg == RISCV::V0; }
487 bool isAnyReg()
const {
488 return Kind == KindTy::Register &&
489 (getRISCVMCRegisterClass(RISCV::GPRRegClassID).contains(
Reg) ||
490 getRISCVMCRegisterClass(RISCV::FPR64RegClassID).contains(
Reg) ||
491 getRISCVMCRegisterClass(RISCV::VRRegClassID).contains(
Reg));
493 bool isAnyRegC()
const {
494 return Kind == KindTy::Register &&
495 (getRISCVMCRegisterClass(RISCV::GPRCRegClassID).contains(
Reg) ||
496 getRISCVMCRegisterClass(RISCV::FPR64CRegClassID).contains(
Reg));
498 bool isImm()
const override {
return isExpr(); }
499 bool isMem()
const override {
return false; }
500 bool isSystemRegister()
const {
return Kind == KindTy::SystemRegister; }
501 bool isRegReg()
const {
return Kind == KindTy::RegReg; }
502 bool isRegList()
const {
return Kind == KindTy::RegList; }
503 bool isRegListS0()
const {
504 return Kind == KindTy::RegList && RegList.Encoding !=
RISCVZC::RA;
506 bool isStackAdj()
const {
return Kind == KindTy::StackAdj; }
509 return Kind == KindTy::Register &&
510 getRISCVMCRegisterClass(RISCV::GPRRegClassID).contains(
Reg);
513 bool isGPRForFP(
const MCSubtargetInfo &STI)
const {
517 return isGPR() && !STI.
hasFeature(RISCV::FeatureStdExtF);
520 bool isGPRForFP64(
const MCSubtargetInfo &STI)
const {
524 return isGPR() && !STI.
hasFeature(RISCV::FeatureStdExtF) &&
529 bool isEvenGPRForFP64(
const MCSubtargetInfo &STI)
const {
530 return isGPR() && (
Reg - RISCV::X0) % 2 == 0 &&
535 static bool evaluateConstantExpr(
const MCExpr *Expr, int64_t &
Imm) {
537 Imm =
CE->getValue();
546 template <
int N>
bool isBareSimmNLsb0()
const {
555 return RISCVAsmParser::classifySymbolRef(
getExpr(), VK) &&
561 template <
int N>
bool isBareSimmN()
const {
567 return isInt<N>(fixImmediateForRV32(
Imm, isRV64Expr()));
570 return RISCVAsmParser::classifySymbolRef(
getExpr(), VK) &&
576 bool isBareSymbol()
const {
579 if (!isExpr() || evaluateConstantExpr(
getExpr(),
Imm))
583 return RISCVAsmParser::classifySymbolRef(
getExpr(), VK) &&
587 bool isCallSymbol()
const {
590 if (!isExpr() || evaluateConstantExpr(
getExpr(),
Imm))
594 return RISCVAsmParser::classifySymbolRef(
getExpr(), VK) &&
598 bool isTailCallSymbol()
const {
return isCallSymbol(); }
600 bool isPseudoJumpSymbol()
const {
603 if (!isExpr() || evaluateConstantExpr(
getExpr(),
Imm))
607 return RISCVAsmParser::classifySymbolRef(
getExpr(), VK) &&
611 bool isTPRelAddSymbol()
const {
614 if (!isExpr() || evaluateConstantExpr(
getExpr(),
Imm))
618 return RISCVAsmParser::classifySymbolRef(
getExpr(), VK) &&
619 VK == ELF::R_RISCV_TPREL_ADD;
622 bool isTLSDESCCallSymbol()
const {
625 if (!isExpr() || evaluateConstantExpr(
getExpr(),
Imm))
629 return RISCVAsmParser::classifySymbolRef(
getExpr(), VK) &&
630 VK == ELF::R_RISCV_TLSDESC_CALL;
633 bool isQCAccessSymbol()
const {
636 if (!isExpr() || evaluateConstantExpr(
getExpr(),
Imm))
640 return RISCVAsmParser::classifySymbolRef(
getExpr(), VK) &&
644 bool isCSRSystemRegister()
const {
return isSystemRegister(); }
648 bool isVTypeI10()
const {
649 if (Kind == KindTy::VType)
653 bool isVTypeI11()
const {
654 if (Kind == KindTy::VType)
659 bool isXSfmmVType()
const {
663 bool isTileLambda()
const {
669 bool isFenceArg()
const {
return Kind == KindTy::Fence; }
672 bool isFRMArg()
const {
return Kind == KindTy::FRM; }
673 bool isFRMArgLegacy()
const {
return Kind == KindTy::FRM; }
678 bool isSMTVType()
const {
679 return Kind == KindTy::SMTVType &&
683 bool isSMTI8()
const {
688 bool isLoadFPImm()
const {
691 if (Kind != KindTy::FPImmediate)
694 APFloat(APFloat::IEEEdouble(), APInt(64, getFPConst())));
697 return Idx >= 0 &&
Idx != 1;
700 bool isImmXLenLI()
const {
709 return RISCVAsmParser::isSymbolDiff(
getExpr());
712 bool isImmXLenLI_Restricted()
const {
716 bool IsConstantImm = evaluateConstantExpr(
getExpr(),
Imm);
718 return IsConstantImm &&
722 template <
unsigned N>
bool isUImm()
const {
726 bool IsConstantImm = evaluateConstantExpr(
getExpr(),
Imm);
730 template <
unsigned N,
unsigned S>
bool isUImmShifted()
const {
734 bool IsConstantImm = evaluateConstantExpr(
getExpr(),
Imm);
738 template <
class Pred>
bool isUImmPred(
Pred p)
const {
742 bool IsConstantImm = evaluateConstantExpr(
getExpr(),
Imm);
743 return IsConstantImm &&
p(
Imm);
746 bool isUImmLog2XLen()
const {
747 if (isExpr() && isRV64Expr())
752 bool isUImmLog2XLenNonZero()
const {
753 if (isExpr() && isRV64Expr())
758 bool isUImmLog2XLenHalf()
const {
759 if (isExpr() && isRV64Expr())
764 bool isUImm5NonZero()
const {
768 bool isUImm5GT3()
const {
772 bool isUImm4Plus1()
const {
777 bool isUImm5Plus1()
const {
782 bool isUImm6Plus1()
const {
787 bool isUImm5GE6Plus1()
const {
792 bool isUImm5Slist()
const {
793 return isUImmPred([](int64_t
Imm) {
794 return (
Imm == 0) || (
Imm == 1) || (
Imm == 2) || (
Imm == 4) ||
795 (
Imm == 8) || (
Imm == 16) || (
Imm == 15) || (
Imm == 31);
799 bool isUImm8GE32()
const {
803 bool isRnumArg()
const {
805 [](int64_t
Imm) {
return Imm >= INT64_C(0) &&
Imm <= INT64_C(10); });
808 bool isRnumArg_0_7()
const {
810 [](int64_t
Imm) {
return Imm >= INT64_C(0) &&
Imm <= INT64_C(7); });
813 bool isRnumArg_1_10()
const {
815 [](int64_t
Imm) {
return Imm >= INT64_C(1) &&
Imm <= INT64_C(10); });
818 bool isRnumArg_2_14()
const {
820 [](int64_t
Imm) {
return Imm >= INT64_C(2) &&
Imm <= INT64_C(14); });
823 template <
unsigned N>
bool isSImm()
const {
827 bool IsConstantImm = evaluateConstantExpr(
getExpr(),
Imm);
828 return IsConstantImm &&
isInt<N>(fixImmediateForRV32(
Imm, isRV64Expr()));
831 bool isYBNDSWImm()
const {
836 bool IsConstantImm = evaluateConstantExpr(
getExpr(),
Imm);
840 template <
class Pred>
bool isSImmPred(
Pred p)
const {
844 bool IsConstantImm = evaluateConstantExpr(
getExpr(),
Imm);
845 return IsConstantImm &&
p(fixImmediateForRV32(
Imm, isRV64Expr()));
848 bool isSImm5NonZero()
const {
852 bool isSImm6NonZero()
const {
856 bool isCLUIImm()
const {
857 return isUImmPred([](int64_t
Imm) {
862 bool isUImm10Lsb00NonZero()
const {
869 static int64_t fixImmediateForRV32(int64_t
Imm,
bool IsRV64Imm) {
875 bool isSImm12LO()
const {
881 return isInt<12>(fixImmediateForRV32(
Imm, isRV64Expr()));
884 return RISCVAsmParser::classifySymbolRef(
getExpr(), VK) &&
887 VK == ELF::R_RISCV_TLSDESC_ADD_LO12);
895 template <
bool (RISCVOperand::*Pred)() const>
896 DiagnosticPredicate isOptionalMemOffset()
const {
900 : DiagnosticPredicate::NearMatch;
903 bool isSImm12Lsb00000()
const {
907 bool isSImm10Lsb0000NonZero()
const {
912 bool isSImm16NonZero()
const {
916 bool isUImm16NonZero()
const {
920 bool isSImm20LI()
const {
926 return isInt<20>(fixImmediateForRV32(
Imm, isRV64Expr()));
929 return RISCVAsmParser::classifySymbolRef(
getExpr(), VK) &&
933 bool isSImm8PLI_B()
const {
return isSImm<8>() || isUImm<8>(); }
934 bool isSImm10PLUI()
const {
return isSImm<10>() || isUImm<10>(); }
936 bool isSImm10PLI_H()
const {
937 return isSImm<10>() || isUImmPred([](int64_t
Imm) {
941 bool isSImm10PLI_W()
const {
942 return isSImm<10>() || isUImmPred([](int64_t
Imm) {
947 bool isUImm20LUI()
const {
956 return RISCVAsmParser::classifySymbolRef(
getExpr(), VK) &&
957 (VK == ELF::R_RISCV_HI20 || VK == ELF::R_RISCV_TPREL_HI20);
960 bool isUImm20AUIPC()
const {
969 return RISCVAsmParser::classifySymbolRef(
getExpr(), VK) &&
971 VK == ELF::R_RISCV_TLS_GOT_HI20 || VK == ELF::R_RISCV_TLS_GD_HI20 ||
972 VK == ELF::R_RISCV_TLSDESC_HI20);
975 bool isImmZero()
const {
976 return isUImmPred([](int64_t
Imm) {
return 0 ==
Imm; });
979 bool isImmThree()
const {
980 return isUImmPred([](int64_t
Imm) {
return 3 ==
Imm; });
983 bool isImmFour()
const {
984 return isUImmPred([](int64_t
Imm) {
return 4 ==
Imm; });
987 bool isImm5Zibi()
const {
992 bool isSImm5Plus1()
const {
997 bool isSImm18Lsb0()
const {
1001 bool isSImm19Lsb00()
const {
1005 bool isSImm20Lsb000()
const {
1009 bool isSImm32Lsb0()
const {
1014 SMLoc getStartLoc()
const override {
return StartLoc; }
1016 SMLoc getEndLoc()
const override {
return EndLoc; }
1019 bool isRV64Expr()
const {
1020 assert(Kind == KindTy::Expression &&
"Invalid type access!");
1024 MCRegister
getReg()
const override {
1025 assert(Kind == KindTy::Register &&
"Invalid type access!");
1029 StringRef getSysReg()
const {
1030 assert(Kind == KindTy::SystemRegister &&
"Invalid type access!");
1031 return StringRef(SysReg.Data, SysReg.Length);
1034 const MCExpr *
getExpr()
const {
1035 assert(Kind == KindTy::Expression &&
"Invalid type access!");
1040 assert(Kind == KindTy::FPImmediate &&
"Invalid type access!");
1045 assert(Kind == KindTy::Token &&
"Invalid type access!");
1049 unsigned getVType()
const {
1050 assert(Kind == KindTy::VType &&
"Invalid type access!");
1055 assert(Kind == KindTy::FRM &&
"Invalid type access!");
1059 unsigned getFence()
const {
1060 assert(Kind == KindTy::Fence &&
"Invalid type access!");
1065 assert(Kind == KindTy::SMTVType &&
"Invalid type access!");
1066 return SMTVType.SMTVType;
1069 void print(raw_ostream &OS,
const MCAsmInfo &MAI)
const override {
1079 case KindTy::Expression:
1082 OS <<
' ' << (Expr.IsRV64 ?
"rv64" :
"rv32") <<
'>';
1084 case KindTy::FPImmediate:
1085 OS <<
"<fpimm: " << FPImm.Val <<
">";
1087 case KindTy::Register:
1093 case KindTy::SystemRegister:
1094 OS <<
"<sysreg: " << getSysReg() <<
" (" << SysReg.Encoding <<
")>";
1103 OS << roundingModeToString(getFRM());
1106 case KindTy::SMTVType:
1107 OS <<
"<smtvtype: ";
1108 OS << SMTVTypeModeToString(getSMTVType());
1116 case KindTy::RegList:
1121 case KindTy::StackAdj:
1122 OS <<
"<stackadj: ";
1126 case KindTy::RegReg:
1127 OS <<
"<RegReg: BaseReg " <<
RegName(
RegReg.BaseReg) <<
" OffsetReg "
1133 static std::unique_ptr<RISCVOperand> createToken(StringRef Str, SMLoc S) {
1134 auto Op = std::make_unique<RISCVOperand>(KindTy::Token);
1141 static std::unique_ptr<RISCVOperand> createReg(MCRegister
Reg, SMLoc S,
1143 auto Op = std::make_unique<RISCVOperand>(KindTy::Register);
1150 static std::unique_ptr<RISCVOperand> createExpr(
const MCExpr *Val, SMLoc S,
1151 SMLoc
E,
bool IsRV64) {
1152 auto Op = std::make_unique<RISCVOperand>(KindTy::Expression);
1153 Op->Expr.Expr = Val;
1154 Op->Expr.IsRV64 = IsRV64;
1160 static std::unique_ptr<RISCVOperand> createFPImm(
uint64_t Val, SMLoc S) {
1161 auto Op = std::make_unique<RISCVOperand>(KindTy::FPImmediate);
1162 Op->FPImm.Val = Val;
1168 static std::unique_ptr<RISCVOperand> createSysReg(StringRef Str, SMLoc S,
1169 unsigned Encoding) {
1170 auto Op = std::make_unique<RISCVOperand>(KindTy::SystemRegister);
1171 Op->SysReg.Data = Str.data();
1172 Op->SysReg.Length = Str.size();
1179 static std::unique_ptr<RISCVOperand>
1181 auto Op = std::make_unique<RISCVOperand>(KindTy::FRM);
1188 static std::unique_ptr<RISCVOperand>
1190 auto Op = std::make_unique<RISCVOperand>(KindTy::SMTVType);
1191 Op->SMTVType.SMTVType = VType;
1197 static std::unique_ptr<RISCVOperand> createFenceArg(
unsigned Val, SMLoc S) {
1198 auto Op = std::make_unique<RISCVOperand>(KindTy::Fence);
1199 Op->Fence.Val = Val;
1205 static std::unique_ptr<RISCVOperand> createVType(
unsigned VTypeI, SMLoc S) {
1206 auto Op = std::make_unique<RISCVOperand>(KindTy::VType);
1207 Op->VType.Val = VTypeI;
1213 static std::unique_ptr<RISCVOperand> createRegList(
unsigned RlistEncode,
1215 auto Op = std::make_unique<RISCVOperand>(KindTy::RegList);
1221 static std::unique_ptr<RISCVOperand>
1222 createRegReg(MCRegister BaseReg, MCRegister OffsetReg, SMLoc S) {
1223 auto Op = std::make_unique<RISCVOperand>(KindTy::RegReg);
1225 Op->RegReg.OffsetReg = OffsetReg;
1231 static std::unique_ptr<RISCVOperand> createStackAdj(
unsigned StackAdj, SMLoc S) {
1232 auto Op = std::make_unique<RISCVOperand>(KindTy::StackAdj);
1233 Op->StackAdj.Val = StackAdj;
1238 static void addExpr(MCInst &Inst,
const MCExpr *Expr,
bool IsRV64Imm) {
1239 assert(Expr &&
"Expr shouldn't be null!");
1251 void addRegOperands(MCInst &Inst,
unsigned N)
const {
1252 assert(
N == 1 &&
"Invalid number of operands!");
1256 void addGPRAsFPR16Operands(MCInst &Inst,
unsigned N)
const {
1257 assert(
N == 1 &&
"Invalid number of operands!");
1261 void addGPRAsFPR32Operands(MCInst &Inst,
unsigned N)
const {
1262 assert(
N == 1 &&
"Invalid number of operands!");
1266 void addGPRPairOperands(MCInst &Inst,
unsigned N)
const;
1268 void addImmOperands(MCInst &Inst,
unsigned N)
const {
1269 assert(
N == 1 &&
"Invalid number of operands!");
1270 addExpr(Inst,
getExpr(), isRV64Expr());
1273 template <
unsigned Bits>
1274 void addSExtImmOperands(MCInst &Inst,
unsigned N)
const {
1275 assert(
N == 1 &&
"Invalid number of operands!");
1282 void addFPImmOperands(MCInst &Inst,
unsigned N)
const {
1283 assert(
N == 1 &&
"Invalid number of operands!");
1285 addExpr(Inst,
getExpr(), isRV64Expr());
1290 APFloat(APFloat::IEEEdouble(), APInt(64, getFPConst())));
1294 void addFenceArgOperands(MCInst &Inst,
unsigned N)
const {
1295 assert(
N == 1 &&
"Invalid number of operands!");
1299 void addCSRSystemRegisterOperands(MCInst &Inst,
unsigned N)
const {
1300 assert(
N == 1 &&
"Invalid number of operands!");
1307 void addVTypeIOperands(MCInst &Inst,
unsigned N)
const {
1308 assert(
N == 1 &&
"Invalid number of operands!");
1310 if (Kind == KindTy::Expression) {
1311 [[maybe_unused]]
bool IsConstantImm =
1313 assert(IsConstantImm &&
"Invalid VTypeI Operand!");
1320 void addRegListOperands(MCInst &Inst,
unsigned N)
const {
1321 assert(
N == 1 &&
"Invalid number of operands!");
1325 void addRegRegOperands(MCInst &Inst,
unsigned N)
const {
1326 assert(
N == 2 &&
"Invalid number of operands!");
1331 void addStackAdjOperands(MCInst &Inst,
unsigned N)
const {
1332 assert(
N == 1 &&
"Invalid number of operands!");
1336 void addFRMArgOperands(MCInst &Inst,
unsigned N)
const {
1337 assert(
N == 1 &&
"Invalid number of operands!");
1341 void addSMTVTypeOperand(MCInst &Inst,
unsigned N)
const {
1342 assert(
N == 1 &&
"Invalid number of operands!");
1348#define GET_REGISTER_MATCHER
1349#define GET_SUBTARGET_FEATURE_NAME
1350#define GET_MATCHER_IMPLEMENTATION
1351#define GET_MNEMONIC_SPELL_CHECKER
1352#include "RISCVGenAsmMatcher.inc"
1354void RISCVOperand::addGPRPairOperands(
MCInst &Inst,
unsigned N)
const {
1355 assert(
N == 1 &&
"Invalid number of operands!");
1359bool RISCVAsmParser::generateImmOutOfRangeError(
1360 SMLoc ErrorLoc, int64_t
Lower, int64_t
Upper,
1361 const Twine &
Msg =
"immediate must be an integer in the range") {
1368std::string RISCVAsmParser::getCustomOperandDiag(
unsigned MatchError) {
1370 StringRef
Msg =
"immediate must be an integer in the range") {
1371 return (
Msg +
" [" + Twine(
Lower) +
", " + Twine(
Upper) +
"]").str();
1374 switch (MatchError) {
1378 if (
const char *Diag = getMatchKindDiag((RISCVMatchResultTy)MatchError))
1380 return std::string();
1381 case Match_InvalidImmXLenLI:
1383 return "operand must be a constant 64-bit integer";
1384 return Range(std::numeric_limits<int32_t>::min(),
1385 std::numeric_limits<uint32_t>::max());
1386 case Match_InvalidImmXLenLI_Restricted:
1388 return "operand either must be a constant 64-bit integer "
1389 "or a bare symbol name";
1390 return Range(std::numeric_limits<int32_t>::min(),
1391 std::numeric_limits<uint32_t>::max(),
1392 "operand either must be a bare symbol name or an immediate "
1393 "integer in the range");
1394 case Match_InvalidUImmLog2XLen:
1396 return Range(0, (1 << 6) - 1);
1397 return Range(0, (1 << 5) - 1);
1398 case Match_InvalidUImmLog2XLenNonZero:
1400 return Range(1, (1 << 6) - 1);
1401 return Range(1, (1 << 5) - 1);
1402 case Match_InvalidUImm1:
1403 return Range(0, (1 << 1) - 1);
1404 case Match_InvalidUImm2:
1405 return Range(0, (1 << 2) - 1);
1406 case Match_InvalidUImm2Lsb0:
1407 return Range(0, 2,
"immediate must be one of");
1408 case Match_InvalidUImm3:
1409 return Range(0, (1 << 3) - 1);
1410 case Match_InvalidUImm4:
1411 return Range(0, (1 << 4) - 1);
1412 case Match_InvalidUImm4Plus1:
1413 return Range(1, (1 << 4));
1414 case Match_InvalidUImm5:
1415 return Range(0, (1 << 5) - 1);
1416 case Match_InvalidUImm5NonZero:
1417 return Range(1, (1 << 5) - 1);
1418 case Match_InvalidUImm5GT3:
1419 return Range(4, (1 << 5) - 1);
1420 case Match_InvalidUImm5Plus1:
1421 return Range(1, (1 << 5));
1422 case Match_InvalidUImm5GE6Plus1:
1423 return Range(6, (1 << 5));
1424 case Match_InvalidUImm5Slist:
1425 return "immediate must be one of: 0, 1, 2, 4, 8, 15, 16, 31";
1426 case Match_InvalidUImm6:
1427 return Range(0, (1 << 6) - 1);
1428 case Match_InvalidUImm6Plus1:
1429 return Range(1, (1 << 6));
1430 case Match_InvalidUImm7:
1431 return Range(0, (1 << 7) - 1);
1432 case Match_InvalidUImm8:
1433 return Range(0, (1 << 8) - 1);
1434 case Match_InvalidUImm8GE32:
1435 return Range(32, (1 << 8) - 1);
1436 case Match_InvalidSImm5:
1437 return Range(-(1 << 4), (1 << 4) - 1);
1438 case Match_InvalidSImm5NonZero:
1439 return Range(-(1 << 4), (1 << 4) - 1,
1440 "immediate must be non-zero in the range");
1441 case Match_InvalidSImm6:
1442 return Range(-(1 << 5), (1 << 5) - 1);
1443 case Match_InvalidSImm6NonZero:
1444 return Range(-(1 << 5), (1 << 5) - 1,
1445 "immediate must be non-zero in the range");
1446 case Match_InvalidCLUIImm:
1447 return Range(1, (1 << 5) - 1,
"immediate must be in [0xfffe0, 0xfffff] or");
1448 case Match_InvalidUImm5Lsb0:
1449 return Range(0, (1 << 5) - 2,
1450 "immediate must be a multiple of 2 bytes in the range");
1451 case Match_InvalidUImm6Lsb0:
1452 return Range(0, (1 << 6) - 2,
1453 "immediate must be a multiple of 2 bytes in the range");
1454 case Match_InvalidUImm6Lsb000:
1455 return Range(0, (1 << 6) - 8,
1456 "immediate must be a multiple of 8 in the range");
1457 case Match_InvalidUImm7Lsb00:
1458 return Range(0, (1 << 7) - 4,
1459 "immediate must be a multiple of 4 bytes in the range");
1460 case Match_InvalidUImm8Lsb00:
1461 return Range(0, (1 << 8) - 4,
1462 "immediate must be a multiple of 4 bytes in the range");
1463 case Match_InvalidUImm8Lsb000:
1464 return Range(0, (1 << 8) - 8,
1465 "immediate must be a multiple of 8 bytes in the range");
1466 case Match_InvalidUImm9:
1467 return Range(0, (1 << 9) - 1,
"immediate offset must be in the range");
1468 case Match_InvalidBareSImm9Lsb0:
1469 return Range(-(1 << 8), (1 << 8) - 2,
1470 "immediate must be a multiple of 2 bytes in the range");
1471 case Match_InvalidUImm9Lsb000:
1472 return Range(0, (1 << 9) - 8,
1473 "immediate must be a multiple of 8 bytes in the range");
1474 case Match_InvalidSImm8PLI_B:
1475 return Range(-(1 << 7), (1 << 8) - 1);
1476 case Match_InvalidSImm10:
1477 case Match_InvalidSImm10PLI_H:
1478 case Match_InvalidSImm10PLI_W:
1479 return Range(-(1 << 9), (1 << 9) - 1);
1480 case Match_InvalidSImm10PLUI:
1481 return Range(-(1 << 9), (1 << 10) - 1);
1482 case Match_InvalidUImm10Lsb00NonZero:
1483 return Range(4, (1 << 10) - 4,
1484 "immediate must be a multiple of 4 bytes in the range");
1485 case Match_InvalidSImm10Lsb0000NonZero:
1487 -(1 << 9), (1 << 9) - 16,
1488 "immediate must be a multiple of 16 bytes and non-zero in the range");
1489 case Match_InvalidSImm11:
1490 return Range(-(1 << 10), (1 << 10) - 1);
1491 case Match_InvalidBareSImm11Lsb0:
1492 return Range(-(1 << 10), (1 << 10) - 2,
1493 "immediate must be a multiple of 2 bytes in the range");
1494 case Match_InvalidUImm10:
1495 return Range(0, (1 << 10) - 1);
1496 case Match_InvalidUImm11:
1497 return Range(0, (1 << 11) - 1);
1498 case Match_InvalidUImm14Lsb00:
1499 return Range(0, (1 << 14) - 4,
1500 "immediate must be a multiple of 4 bytes in the range");
1501 case Match_InvalidUImm16NonZero:
1502 return Range(1, (1 << 16) - 1);
1503 case Match_InvalidSImm12:
1504 return Range(-(1 << 11), (1 << 11) - 1);
1505 case Match_InvalidSImm12LO:
1506 return Range(-(1 << 11), (1 << 11) - 1,
1507 "operand must be a symbol with %lo/%pcrel_lo/%tprel_lo "
1508 "specifier or an integer in the range");
1509 case Match_InvalidBareSImm12Lsb0:
1510 return Range(-(1 << 11), (1 << 11) - 2,
1511 "immediate must be a multiple of 2 bytes in the range");
1512 case Match_InvalidSImm12Lsb00000:
1513 return Range(-(1 << 11), (1 << 11) - 32,
1514 "immediate must be a multiple of 32 bytes in the range");
1515 case Match_InvalidBareSImm13Lsb0:
1516 return Range(-(1 << 12), (1 << 12) - 2,
1517 "immediate must be a multiple of 2 bytes in the range");
1518 case Match_InvalidSImm16:
1519 return Range(-(1 << 15), (1 << 15) - 1);
1520 case Match_InvalidSImm16NonZero:
1521 return Range(-(1 << 15), (1 << 15) - 1,
1522 "immediate must be non-zero in the range");
1523 case Match_InvalidSImm20LI:
1524 return Range(-(1 << 19), (1 << 19) - 1,
1525 "operand must be a symbol with a %qc.abs20 specifier or an "
1526 "integer in the range");
1527 case Match_InvalidUImm20LUI:
1528 return Range(0, (1 << 20) - 1,
1529 "operand must be a symbol with %hi/%tprel_hi specifier or an "
1530 "integer in the range");
1531 case Match_InvalidUImm20:
1532 return Range(0, (1 << 20) - 1);
1533 case Match_InvalidUImm20AUIPC:
1536 "operand must be a symbol with a "
1537 "%pcrel_hi/%got_pcrel_hi/%tls_ie_pcrel_hi/%tls_gd_pcrel_hi specifier "
1538 "or an integer in the range");
1539 case Match_InvalidBareSImm21Lsb0:
1540 return Range(-(1 << 20), (1 << 20) - 2,
1541 "immediate must be a multiple of 2 bytes in the range");
1542 case Match_InvalidCSRSystemRegister:
1543 return Range(0, (1 << 12) - 1,
1544 "operand must be a valid system register name or an integer "
1546 case Match_InvalidImm5Zibi:
1547 return Range(-1, (1 << 5) - 1,
"immediate must be non-zero in the range");
1548 case Match_InvalidVTypeI:
1549 return "operand must be "
1550 "e[8|8alt|16|16alt|32|64],m[1|2|4|8|f2|f4|f8],[ta|tu],[ma|mu]";
1551 case Match_InvalidSImm5Plus1:
1552 return Range(-(1 << 4) + 1, (1 << 4),
"immediate must be in the range");
1553 case Match_InvalidSImm18:
1554 return Range(-(1 << 17), (1 << 17) - 1);
1555 case Match_InvalidSImm18Lsb0:
1556 return Range(-(1 << 17), (1 << 17) - 2,
1557 "immediate must be a multiple of 2 bytes in the range");
1558 case Match_InvalidSImm19Lsb00:
1559 return Range(-(1 << 18), (1 << 18) - 4,
1560 "immediate must be a multiple of 4 bytes in the range");
1561 case Match_InvalidSImm20Lsb000:
1562 return Range(-(1 << 19), (1 << 19) - 8,
1563 "immediate must be a multiple of 8 bytes in the range");
1564 case Match_InvalidSImm26:
1565 return Range(-(1 << 25), (1 << 25) - 1);
1567 case Match_InvalidBareSymbolQC_E_LI:
1570 case Match_InvalidBareSImm32:
1571 return Range(std::numeric_limits<int32_t>::min(),
1572 std::numeric_limits<uint32_t>::max());
1573 case Match_InvalidBareSImm32Lsb0:
1574 return Range(std::numeric_limits<int32_t>::min(),
1575 std::numeric_limits<int32_t>::max() - 1,
1576 "operand must be a multiple of 2 bytes in the range");
1577 case Match_InvalidRnumArg:
1578 return Range(0, 10);
1579 case Match_InvalidStackAdj:
1580 return "stack adjustment is invalid for this instruction and register "
1582 case Match_InvalidYBNDSWImm:
1583 return "immediate must be an integer in the range "
1584 "[1, 255], a multiple of 8 in the range [256, 504], "
1585 "or a multiple of 16 in the range [512, 4096]";
1592void RISCVAsmParser::FilterNearMisses(
1593 SmallVectorImpl<NearMissInfo> &NearMissesIn,
1594 SmallVectorImpl<NearMissMessage> &NearMissesOut, SMLoc IDLoc,
1598 std::multimap<unsigned, unsigned> OperandMissesSeen;
1599 SmallSet<FeatureBitset, 4> FeatureMissesSeen;
1600 bool ReportedTooFewOperands =
false;
1601 bool ReportedTooManyOperands =
false;
1603 for (NearMissInfo &
I : NearMissesIn) {
1604 switch (
I.getKind()) {
1607 ((RISCVOperand &)*
Operands[
I.getOperandIndex()]).getStartLoc();
1612 if (
I.getOperandClass() == InvalidMatchClass) {
1613 if (!ReportedTooManyOperands) {
1615 OperandLoc,
"unexpected extra operand for instruction"});
1616 ReportedTooManyOperands =
true;
1621 std::string OperandDiag = getCustomOperandDiag(
I.getOperandError());
1625 unsigned DupCheckMatchClass =
1626 OperandDiag.empty() ? ~0
U :
I.getOperandClass();
1627 auto PrevReports = OperandMissesSeen.equal_range(
I.getOperandIndex());
1629 PrevReports.first, PrevReports.second,
1630 [DupCheckMatchClass](
const std::pair<unsigned, unsigned> Pair) {
1631 if (DupCheckMatchClass == ~0U || Pair.second == ~0U)
1632 return Pair.second == DupCheckMatchClass;
1633 return isSubclass((MatchClassKind)DupCheckMatchClass,
1634 (MatchClassKind)Pair.second);
1637 OperandMissesSeen.insert(
1638 std::make_pair(
I.getOperandIndex(), DupCheckMatchClass));
1640 NearMissMessage Message;
1641 Message.Loc = OperandLoc;
1642 if (!OperandDiag.empty()) {
1643 Message.Message = OperandDiag;
1645 Message.Message =
"invalid operand for instruction";
1647 dbgs() <<
"Missing diagnostic string for operand class "
1648 << getMatchClassName((MatchClassKind)
I.getOperandClass())
1649 <<
I.getOperandClass() <<
", error " <<
I.getOperandError()
1650 <<
", opcode " << MII.
getName(
I.getOpcode()) <<
"\n");
1656 const FeatureBitset &MissingFeatures =
I.getFeatures();
1658 if (!FeatureMissesSeen.
insert(MissingFeatures).second)
1661 NearMissMessage Message;
1662 Message.Loc = IDLoc;
1663 bool FirstFeature =
true;
1664 Message.Message =
"instruction requires the following:";
1665 for (
unsigned Feature : MissingFeatures) {
1666 Message.Message += FirstFeature ?
" " :
", ";
1668 FirstFeature =
false;
1678 if (!ReportedTooFewOperands) {
1679 SMLoc EndLoc = ((RISCVOperand &)*
Operands.back()).getEndLoc();
1681 NearMissMessage{EndLoc,
"too few operands for instruction"});
1682 ReportedTooFewOperands =
true;
1694void RISCVAsmParser::ReportNearMisses(SmallVectorImpl<NearMissInfo> &NearMisses,
1697 FilterNearMisses(NearMisses, Messages, IDLoc,
Operands);
1702 Error(IDLoc,
"invalid instruction");
1705 Error(Messages[0].Loc, Messages[0].Message);
1710 "invalid instruction, any one of the following would fix this:");
1711 for (
auto &M : Messages)
1716bool RISCVAsmParser::matchAndEmitInstruction(SMLoc IDLoc,
unsigned &Opcode,
1720 bool MatchingInlineAsm) {
1725 MatchInstructionImpl(
Operands, Inst, &NearMisses, MatchingInlineAsm);
1730 if (validateInstruction(Inst,
Operands))
1732 return processInstruction(Inst, IDLoc,
Operands, Out);
1733 case Match_MnemonicFail: {
1734 FeatureBitset FBS = ComputeAvailableFeatures(getSTI().getFeatureBits());
1735 std::string Suggestion = RISCVMnemonicSpellCheck(
1737 return Error(IDLoc,
"unrecognized instruction mnemonic" + Suggestion);
1739 case Match_NearMisses:
1740 ReportNearMisses(NearMisses, IDLoc,
Operands);
1751MCRegister RISCVAsmParser::matchRegisterNameHelper(StringRef Name)
const {
1760 static_assert(RISCV::F0_D < RISCV::F0_H,
"FPR matching must be updated");
1761 static_assert(RISCV::F0_D < RISCV::F0_F,
"FPR matching must be updated");
1762 static_assert(RISCV::F0_D < RISCV::F0_Q,
"FPR matching must be updated");
1765 if (
isRVE() &&
Reg >= RISCV::X16 &&
Reg <= RISCV::X31)
1770bool RISCVAsmParser::parseRegister(MCRegister &
Reg, SMLoc &StartLoc,
1772 if (!tryParseRegister(
Reg, StartLoc, EndLoc).isSuccess())
1773 return Error(StartLoc,
"invalid register name");
1777ParseStatus RISCVAsmParser::tryParseRegister(MCRegister &
Reg, SMLoc &StartLoc,
1779 const AsmToken &Tok = getParser().getTok();
1782 StringRef
Name = getLexer().getTok().getIdentifier();
1794 SMLoc FirstS = getLoc();
1795 bool HadParens =
false;
1802 size_t ReadCount = getLexer().peekTokens(Buf);
1805 LParen = getParser().getTok();
1810 switch (getLexer().getKind()) {
1813 getLexer().UnLex(LParen);
1816 StringRef
Name = getLexer().getTok().getIdentifier();
1821 getLexer().UnLex(LParen);
1825 Operands.push_back(RISCVOperand::createToken(
"(", FirstS));
1827 SMLoc
E = getTok().getEndLoc();
1829 Operands.push_back(RISCVOperand::createReg(
Reg, S,
E));
1834 Operands.push_back(RISCVOperand::createToken(
")", getLoc()));
1845 switch (getLexer().getKind()) {
1855 if (getParser().parseExpression(Res,
E))
1860 int64_t
Imm =
CE->getValue();
1862 Operands.push_back(RISCVOperand::createExpr(Res, S,
E, isRV64()));
1871 if (getParser().parseIdentifier(Identifier))
1874 auto Opcode = RISCVInsnOpcode::lookupRISCVOpcodeByName(Identifier);
1877 "Unexpected opcode");
1880 Operands.push_back(RISCVOperand::createExpr(Res, S,
E, isRV64()));
1890 return generateImmOutOfRangeError(
1892 "opcode must be a valid opcode name or an immediate in the range");
1900 switch (getLexer().getKind()) {
1910 if (getParser().parseExpression(Res,
E))
1915 int64_t
Imm =
CE->getValue();
1916 if (
Imm >= 0 &&
Imm <= 2) {
1917 Operands.push_back(RISCVOperand::createExpr(Res, S,
E, isRV64()));
1926 if (getParser().parseIdentifier(Identifier))
1930 if (Identifier ==
"C0")
1932 else if (Identifier ==
"C1")
1934 else if (Identifier ==
"C2")
1941 Operands.push_back(RISCVOperand::createExpr(Res, S,
E, isRV64()));
1950 return generateImmOutOfRangeError(
1952 "opcode must be a valid opcode name or an immediate in the range");
1959 auto SysRegFromConstantInt = [
this](
const MCExpr *
E, SMLoc S) {
1961 int64_t
Imm =
CE->getValue();
1963 auto Range = RISCVSysReg::lookupSysRegByEncoding(
Imm);
1967 if (
Reg.IsAltName ||
Reg.IsDeprecatedName)
1970 return RISCVOperand::createSysReg(
1971 RISCVSysReg::getSysRegStr(
Reg.Name), S,
Imm);
1975 return RISCVOperand::createSysReg(
"", S,
Imm);
1978 return std::unique_ptr<RISCVOperand>();
1981 switch (getLexer().getKind()) {
1991 if (getParser().parseExpression(Res))
1994 if (
auto SysOpnd = SysRegFromConstantInt(Res, S)) {
1995 Operands.push_back(std::move(SysOpnd));
1999 return generateImmOutOfRangeError(S, 0, (1 << 12) - 1);
2003 if (getParser().parseIdentifier(Identifier))
2006 const auto *SysReg = RISCVSysReg::lookupSysRegByName(Identifier);
2009 if (SysReg->IsDeprecatedName) {
2011 auto Range = RISCVSysReg::lookupSysRegByEncoding(SysReg->Encoding);
2013 if (
Reg.IsAltName ||
Reg.IsDeprecatedName)
2015 Warning(S,
"'" + Identifier +
"' is a deprecated alias for '" +
2016 RISCVSysReg::getSysRegStr(
Reg.Name) +
"'");
2021 const auto &FeatureBits = getSTI().getFeatureBits();
2022 const auto &
AllFeatures = getSTI().getAllProcessorFeatures();
2023 if (!SysReg->haveRequiredFeatures(FeatureBits)) {
2024 const auto *Feature =
2026 return SysReg->FeaturesRequired[Feature.Value];
2028 std::string ErrorMsg =
2029 std::string(
"system register '") +
2030 std::string(RISCVSysReg::getSysRegStr(SysReg->Name)) +
"' ";
2031 if (SysReg->IsRV32Only && FeatureBits[RISCV::Feature64Bit]) {
2032 ErrorMsg +=
"is RV32 only";
2034 ErrorMsg +=
" and ";
2038 "requires '" + std::string(Feature->key()) +
"' to be enabled";
2041 return Error(S, ErrorMsg);
2044 RISCVOperand::createSysReg(Identifier, S, SysReg->Encoding));
2054 Operands.push_back(std::move(SysOpnd));
2059 return generateImmOutOfRangeError(S, 0, (1 << 12) - 1,
2060 "operand must be a valid system register "
2061 "name or an integer in the range");
2065 return generateImmOutOfRangeError(S, 0, (1 << 12) - 1);
2077 StringRef
Identifier = getTok().getIdentifier();
2078 if (
Identifier.compare_insensitive(
"inf") == 0) {
2081 getTok().getEndLoc(), isRV64()));
2082 }
else if (
Identifier.compare_insensitive(
"nan") == 0) {
2085 getTok().getEndLoc(), isRV64()));
2086 }
else if (
Identifier.compare_insensitive(
"min") == 0) {
2089 getTok().getEndLoc(), isRV64()));
2091 return TokError(
"invalid floating point literal");
2102 const AsmToken &Tok = getTok();
2104 return TokError(
"invalid floating point immediate");
2107 APFloat RealVal(APFloat::IEEEdouble());
2109 RealVal.convertFromString(Tok.
getString(), APFloat::rmTowardZero);
2111 return TokError(
"invalid floating point representation");
2114 RealVal.changeSign();
2116 Operands.push_back(RISCVOperand::createFPImm(
2117 RealVal.bitcastToAPInt().getZExtValue(), S));
2129 switch (getLexer().getKind()) {
2141 if (getParser().parseExpression(Res,
E))
2145 return parseOperandWithSpecifier(
Operands);
2148 Operands.push_back(RISCVOperand::createExpr(Res, S,
E, isRV64()));
2158 const MCExpr *Expr =
nullptr;
2159 bool Failed = parseExprWithSpecifier(Expr,
E);
2161 Operands.push_back(RISCVOperand::createExpr(Expr, S,
E, isRV64()));
2165bool RISCVAsmParser::parseExprWithSpecifier(
const MCExpr *&Res, SMLoc &
E) {
2166 SMLoc Loc = getLoc();
2168 return TokError(
"expected '%' relocation specifier");
2169 StringRef
Identifier = getParser().getTok().getIdentifier();
2172 return TokError(
"invalid relocation specifier");
2178 const MCExpr *SubExpr;
2179 if (getParser().parseParenExpression(SubExpr,
E))
2186bool RISCVAsmParser::parseDataExpr(
const MCExpr *&Res) {
2189 return parseExprWithSpecifier(Res,
E);
2190 return getParser().parseExpression(Res);
2200 StringRef
Identifier = getTok().getIdentifier();
2210 if (getParser().parseExpression(Res,
E))
2213 Operands.push_back(RISCVOperand::createExpr(Res, S,
E, isRV64()));
2223 std::string
Identifier(getTok().getIdentifier());
2229 SMLoc Loc = getLoc();
2230 if (getParser().parseIdentifier(PLT) || PLT !=
"plt")
2231 return Error(Loc,
"@ (except the deprecated/ignored @plt) is disallowed");
2245 Operands.push_back(RISCVOperand::createExpr(Res, S,
E, isRV64()));
2257 std::string
Identifier(getTok().getIdentifier());
2263 SMLoc Loc = getLoc();
2264 if (getParser().parseIdentifier(PLT) || PLT !=
"plt")
2265 return Error(Loc,
"@ (except the deprecated/ignored @plt) is disallowed");
2279 Operands.push_back(RISCVOperand::createExpr(Res, S,
E, isRV64()));
2288 if (getParser().parseExpression(Res,
E))
2291 if (Res->
getKind() != MCExpr::ExprKind::SymbolRef)
2292 return Error(S,
"operand must be a valid jump target");
2295 Operands.push_back(RISCVOperand::createExpr(Res, S,
E, isRV64()));
2316bool RISCVAsmParser::parseVTypeToken(
const AsmToken &Tok, VTypeState &State,
2317 unsigned &Sew,
unsigned &Lmul,
2318 bool &Fractional,
bool &TailAgnostic,
2319 bool &MaskAgnostic,
bool &AltFmt) {
2324 if (State < VTypeState::SeenSew &&
Identifier.consume_front(
"e")) {
2326 if (Identifier ==
"16alt") {
2329 }
else if (Identifier ==
"8alt") {
2339 State = VTypeState::SeenSew;
2343 if (State < VTypeState::SeenLmul &&
Identifier.consume_front(
"m")) {
2346 if (Identifier ==
"a" || Identifier ==
"u") {
2348 State = VTypeState::SeenMaskPolicy;
2359 unsigned ELEN = STI->
hasFeature(RISCV::FeatureStdExtZve64x) ? 64 : 32;
2360 unsigned MinLMUL = ELEN / 8;
2363 "use of vtype encodings with LMUL < SEWMIN/ELEN == mf" +
2364 Twine(MinLMUL) +
" is reserved");
2367 State = VTypeState::SeenLmul;
2371 if (State < VTypeState::SeenTailPolicy &&
Identifier.starts_with(
"t")) {
2372 if (Identifier ==
"ta")
2373 TailAgnostic =
true;
2374 else if (Identifier ==
"tu")
2375 TailAgnostic =
false;
2379 State = VTypeState::SeenTailPolicy;
2383 if (State < VTypeState::SeenMaskPolicy &&
Identifier.starts_with(
"m")) {
2384 if (Identifier ==
"ma")
2385 MaskAgnostic =
true;
2386 else if (Identifier ==
"mu")
2387 MaskAgnostic =
false;
2391 State = VTypeState::SeenMaskPolicy;
2404 bool Fractional =
false;
2405 bool TailAgnostic =
false;
2406 bool MaskAgnostic =
false;
2409 VTypeState State = VTypeState::SeenNothingYet;
2411 if (parseVTypeToken(getTok(), State, Sew, Lmul, Fractional, TailAgnostic,
2412 MaskAgnostic, AltFmt)) {
2414 if (State == VTypeState::SeenNothingYet)
2423 State == VTypeState::SeenNothingYet)
2424 return generateVTypeError(S);
2428 unsigned ELEN = STI->
hasFeature(RISCV::FeatureStdExtZve64x) ? 64 : 32;
2429 unsigned MaxSEW = ELEN / Lmul;
2431 if (MaxSEW >= 8 && Sew > MaxSEW)
2432 Warning(S,
"use of vtype encodings with SEW > " + Twine(MaxSEW) +
2433 " and LMUL == mf" + Twine(Lmul) +
2434 " may not be compatible with all RVV implementations");
2439 Operands.push_back(RISCVOperand::createVType(VTypeI, S));
2443bool RISCVAsmParser::generateVTypeError(SMLoc ErrorLoc) {
2444 return Error(ErrorLoc,
2446 "e[8|8alt|16|16alt|32|64],m[1|2|4|8|f2|f4|f8],[ta|tu],[ma|mu]");
2466 if (Identifier !=
"16alt")
2495 Operands.push_back(RISCVOperand::createVType(
2501 return generateXSfmmVTypeError(S);
2504bool RISCVAsmParser::generateXSfmmVTypeError(SMLoc ErrorLoc) {
2505 return Error(ErrorLoc,
"operand must be e[8|16|16alt|32|64],w[1|2|4]");
2512 StringRef
Name = getLexer().getTok().getIdentifier();
2513 if (!
Name.consume_back(
".t")) {
2517 return Error(getLoc(),
"expected '.t' suffix");
2524 if (
Reg != RISCV::V0)
2527 SMLoc
E = getTok().getEndLoc();
2529 Operands.push_back(RISCVOperand::createReg(
Reg, S,
E));
2537 StringRef
Name = getLexer().getTok().getIdentifier();
2538 if (!
Name.consume_back(
".scale"))
2539 return Error(getLoc(),
"expected '.scale' suffix");
2544 if (
Reg != RISCV::V0)
2547 SMLoc
E = getTok().getEndLoc();
2549 Operands.push_back(RISCVOperand::createReg(
Reg, S,
E));
2558 StringRef
Name = getLexer().getTok().getIdentifier();
2559 if (!
Name.consume_front(
"L") && !
Name.consume_front(
"l"))
2564 return Error(S,
"operand must be L1, L2, L4, L8, L16, L32, or L64");
2566 unsigned EncodedLambda =
Log2_32(Lambda) + 1;
2568 SMLoc
E = getTok().getEndLoc();
2570 Operands.push_back(RISCVOperand::createExpr(
2578 "operand must be a valid SpacemiT's Integer Matrix VType mnemonic");
2580 StringRef Str = getLexer().getTok().getIdentifier();
2583 if (!isValidSMTVTypeMode(VType))
2584 return TokError(
"SpacemiT's Integer Matrix only supports [i4|i8] mode");
2586 Operands.push_back(RISCVOperand::createSMTVType(VType, getLoc()));
2594 "operand must be a valid floating point rounding mode mnemonic");
2596 StringRef Str = getLexer().getTok().getIdentifier();
2601 "operand must be a valid floating point rounding mode mnemonic");
2603 Operands.push_back(RISCVOperand::createFRMArg(FRM, getLoc()));
2608std::unique_ptr<RISCVOperand> RISCVAsmParser::defaultSMTVType() {
2609 return RISCVOperand::createSMTVType(XSMTVTypeMode::SMTVTypeMode::SMT_I8,
2614 const AsmToken &Tok = getLexer().getTok();
2620 Operands.push_back(RISCVOperand::createFenceArg(0, getLoc()));
2634 for (
char c : Str) {
2663 Operands.push_back(RISCVOperand::createFenceArg(
Imm, getLoc()));
2669 return TokError(
"operand must be formed of letters selected in-order from "
2676 Operands.push_back(RISCVOperand::createToken(
"(", getLoc()));
2678 if (!parseRegister(
Operands).isSuccess())
2679 return Error(getLoc(),
"expected register");
2683 Operands.push_back(RISCVOperand::createToken(
")", getLoc()));
2707 std::unique_ptr<RISCVOperand> OptionalImmOp;
2714 SMLoc ImmStart = getLoc();
2715 if (getParser().parseIntToken(ImmVal,
2716 "expected '(' or optional integer offset"))
2721 SMLoc ImmEnd = getLoc();
2724 ImmStart, ImmEnd, isRV64());
2728 OptionalImmOp ?
"expected '(' after optional integer offset"
2729 :
"expected '(' or optional integer offset"))
2732 if (!parseRegister(
Operands).isSuccess())
2733 return Error(getLoc(),
"expected register");
2739 if (OptionalImmOp && !OptionalImmOp->isImmZero())
2741 OptionalImmOp->getStartLoc(),
"optional integer offset must be 0",
2742 SMRange(OptionalImmOp->getStartLoc(), OptionalImmOp->getEndLoc()));
2753 StringRef OffsetRegName = getLexer().getTok().getIdentifier();
2756 !getRISCVMCRegisterClass(RISCV::GPRRegClassID).
contains(OffsetReg))
2757 return Error(getLoc(),
"expected GPR register");
2764 return Error(getLoc(),
"expected GPR register");
2766 StringRef BaseRegName = getLexer().getTok().getIdentifier();
2769 !getRISCVMCRegisterClass(RISCV::GPRRegClassID).
contains(BaseReg))
2770 return Error(getLoc(),
"expected GPR register");
2776 Operands.push_back(RISCVOperand::createRegReg(BaseReg, OffsetReg, S));
2789 bool MustIncludeS0) {
2801 return Error(getLoc(),
"invalid register");
2803 StringRef
RegName = getTok().getIdentifier();
2806 return Error(getLoc(),
"invalid register");
2809 UsesXRegs =
RegName[0] ==
'x';
2810 if (
Reg != RISCV::X1)
2811 return Error(getLoc(),
"register list must start from 'ra' or 'x1'");
2812 }
else if (RegEnd == RISCV::X1) {
2813 if (
Reg != RISCV::X8 || (UsesXRegs != (
RegName[0] ==
'x')))
2814 return Error(getLoc(), Twine(
"register must be '") +
2815 (UsesXRegs ?
"x8" :
"s0") +
"'");
2816 }
else if (RegEnd == RISCV::X9 && UsesXRegs) {
2817 if (
Reg != RISCV::X18 || (
RegName[0] !=
'x'))
2818 return Error(getLoc(),
"register must be 'x18'");
2820 return Error(getLoc(),
"too many register ranges");
2827 SMLoc MinusLoc = getLoc();
2829 if (RegEnd == RISCV::X1)
2830 return Error(MinusLoc, Twine(
"register '") + (UsesXRegs ?
"x1" :
"ra") +
2831 "' cannot start a multiple register range");
2834 return Error(getLoc(),
"invalid register");
2836 StringRef
RegName = getTok().getIdentifier();
2839 return Error(getLoc(),
"invalid register");
2841 if (RegEnd == RISCV::X8) {
2842 if ((
Reg != RISCV::X9 &&
2844 (UsesXRegs != (
RegName[0] ==
'x'))) {
2846 return Error(getLoc(),
"register must be 'x9'");
2847 return Error(getLoc(),
"register must be in the range 's1' to 's11'");
2849 }
else if (RegEnd == RISCV::X18) {
2851 return Error(getLoc(),
2852 "register must be in the range 'x19' to 'x27'");
2865 if (RegEnd == RISCV::X26)
2866 return Error(S,
"invalid register list, '{ra, s0-s10}' or '{x1, x8-x9, "
2867 "x18-x26}' is not supported");
2873 return Error(S,
"register list must include 's0' or 'x8'");
2875 Operands.push_back(RISCVOperand::createRegList(Encode, S));
2881 bool ExpectNegative) {
2890 auto *RegListOp =
static_cast<RISCVOperand *
>(
Operands.back().
get());
2891 if (!RegListOp->isRegList())
2894 unsigned RlistEncode = RegListOp->RegList.Encoding;
2898 if (Negative != ExpectNegative || StackAdjustment % 16 != 0 ||
2899 StackAdjustment < StackAdjBase || (StackAdjustment - StackAdjBase) > 48) {
2900 int64_t
Lower = StackAdjBase;
2901 int64_t
Upper = StackAdjBase + 48;
2902 if (ExpectNegative) {
2907 return generateImmOutOfRangeError(S,
Lower,
Upper,
2908 "stack adjustment for register list must "
2909 "be a multiple of 16 bytes in the range");
2913 Operands.push_back(RISCVOperand::createStackAdj(StackAdj, S));
2925 MatchOperandParserImpl(
Operands, Mnemonic,
true);
2932 if (parseRegister(
Operands,
true).isSuccess())
2936 if (parseExpression(
Operands).isSuccess()) {
2939 return !parseMemOpBaseReg(
Operands).isSuccess();
2944 Error(getLoc(),
"unknown operand");
2948bool RISCVAsmParser::parseInstruction(ParseInstructionInfo &Info,
2949 StringRef Name, SMLoc NameLoc,
2955 const FeatureBitset &AvailableFeatures = getAvailableFeatures();
2959 Operands.push_back(RISCVOperand::createToken(Name, NameLoc));
2978 if (getParser().parseEOL(
"unexpected token")) {
2979 getParser().eatToEndOfStatement();
2985bool RISCVAsmParser::classifySymbolRef(
const MCExpr *Expr,
2989 Kind = RE->getSpecifier();
2990 Expr = RE->getSubExpr();
2999bool RISCVAsmParser::isSymbolDiff(
const MCExpr *Expr) {
3008ParseStatus RISCVAsmParser::parseDirective(AsmToken DirectiveID) {
3009 StringRef IDVal = DirectiveID.
getString();
3011 if (IDVal ==
".option")
3012 return parseDirectiveOption();
3013 if (IDVal ==
".attribute")
3014 return parseDirectiveAttribute();
3015 if (IDVal ==
".insn")
3016 return parseDirectiveInsn(DirectiveID.
getLoc());
3017 if (IDVal ==
".variant_cc")
3018 return parseDirectiveVariantCC();
3023bool RISCVAsmParser::resetToArch(StringRef Arch, SMLoc Loc, std::string &Result,
3024 bool FromOptionDirective) {
3030 raw_string_ostream OutputErrMsg(Buffer);
3031 handleAllErrors(ParseResult.takeError(), [&](llvm::StringError &ErrMsg) {
3032 OutputErrMsg <<
"invalid arch name '" << Arch <<
"', "
3033 << ErrMsg.getMessage();
3036 return Error(Loc, OutputErrMsg.str());
3038 auto &ISAInfo = *ParseResult;
3040 if (FromOptionDirective) {
3041 if (ISAInfo->getXLen() == 32 && isRV64())
3042 return Error(Loc,
"bad arch string switching from rv64 to rv32");
3043 else if (ISAInfo->getXLen() == 64 && !isRV64())
3044 return Error(Loc,
"bad arch string switching from rv32 to rv64");
3046 if (ISAInfo->getXLen() != 32 && ISAInfo->getXLen() != 64)
3047 return Error(Loc,
"bad arch string " + Arch);
3053 MCSubtargetInfo &STI = copySTI();
3057 if (ISAInfo->hasExtension(Feature.key()) != STI.
hasFeature(Feature.Value))
3060 if ((ISAInfo->getXLen() == 64) != STI.
hasFeature(RISCV::Feature64Bit))
3062 setAvailableFeatures(ComputeAvailableFeatures(STI.
getFeatureBits()));
3064 Result = ISAInfo->toString();
3068bool RISCVAsmParser::parseDirectiveOption() {
3069 MCAsmParser &Parser = getParser();
3071 AsmToken Tok = Parser.
getTok();
3079 if (Option ==
"push") {
3083 getTargetStreamer().emitDirectiveOptionPush();
3088 if (Option ==
"pop") {
3093 getTargetStreamer().emitDirectiveOptionPop();
3094 if (popFeatureBits())
3095 return Error(StartLoc,
".option pop with no .option push");
3100 if (Option ==
"arch") {
3108 Type = RISCVOptionArchArgType::Plus;
3110 Type = RISCVOptionArchArgType::Minus;
3111 else if (!
Args.empty())
3113 "unexpected token, expected + or -");
3115 Type = RISCVOptionArchArgType::Full;
3119 "unexpected token, expected identifier");
3125 if (
Type == RISCVOptionArchArgType::Full) {
3127 if (resetToArch(Arch, Loc, Result,
true))
3136 Loc,
"extension version number parsing not currently implemented");
3139 if (!enableExperimentalExtension() &&
3141 return Error(Loc,
"unexpected experimental extensions");
3142 const auto &
AllFeatures = getSTI().getAllProcessorFeatures();
3144 if (Ext == std::end(
AllFeatures) || StringRef(Ext->key()) != Feature)
3145 return Error(Loc,
"unknown extension feature");
3147 if (Ext->Value == RISCV::FeatureStdExtY)
3148 return Error(Loc,
"passing '+y'/'-y' is not supported yet; specify a "
3149 "full arch string instead");
3153 if (
Type == RISCVOptionArchArgType::Plus) {
3156 setFeatureBits(Ext->Value, Ext->key());
3159 copySTI().setFeatureBits(OldFeatureBits);
3160 setAvailableFeatures(ComputeAvailableFeatures(OldFeatureBits));
3163 raw_string_ostream OutputErrMsg(Buffer);
3164 handleAllErrors(ParseResult.takeError(), [&](llvm::StringError &ErrMsg) {
3165 OutputErrMsg << ErrMsg.getMessage();
3168 return Error(Loc, OutputErrMsg.str());
3171 assert(
Type == RISCVOptionArchArgType::Minus);
3177 Feature.Implies.test(Ext->Value))
3178 return Error(Loc, Twine(
"can't disable ") + Ext->key() +
3179 " extension; " + Feature.key() +
3180 " extension requires " + Ext->key() +
3184 clearFeatureBits(Ext->Value, Ext->key());
3191 getTargetStreamer().emitDirectiveOptionArch(Args);
3194 getTargetStreamer().setArchString((*ParseResult)->toString());
3198 if (Option ==
"exact") {
3202 getTargetStreamer().emitDirectiveOptionExact();
3203 setFeatureBits(RISCV::FeatureExactAssembly,
"exact-asm");
3204 clearFeatureBits(RISCV::FeatureRelax,
"relax");
3208 if (Option ==
"noexact") {
3212 getTargetStreamer().emitDirectiveOptionNoExact();
3213 clearFeatureBits(RISCV::FeatureExactAssembly,
"exact-asm");
3214 setFeatureBits(RISCV::FeatureRelax,
"relax");
3218 if (Option ==
"rvc") {
3222 getTargetStreamer().emitDirectiveOptionRVC();
3223 setFeatureBits(RISCV::FeatureStdExtC,
"c");
3225 getTargetStreamer().setArchString((*ParseResult)->toString());
3229 if (Option ==
"norvc") {
3233 getTargetStreamer().emitDirectiveOptionNoRVC();
3234 clearFeatureBits(RISCV::FeatureStdExtC,
"c");
3235 clearFeatureBits(RISCV::FeatureStdExtZca,
"zca");
3237 getTargetStreamer().setArchString((*ParseResult)->toString());
3241 if (Option ==
"pic") {
3245 getTargetStreamer().emitDirectiveOptionPIC();
3246 ParserOptions.IsPicEnabled =
true;
3250 if (Option ==
"nopic") {
3254 getTargetStreamer().emitDirectiveOptionNoPIC();
3255 ParserOptions.IsPicEnabled =
false;
3259 if (Option ==
"relax") {
3263 getTargetStreamer().emitDirectiveOptionRelax();
3264 setFeatureBits(RISCV::FeatureRelax,
"relax");
3268 if (Option ==
"norelax") {
3272 getTargetStreamer().emitDirectiveOptionNoRelax();
3273 clearFeatureBits(RISCV::FeatureRelax,
"relax");
3279 "unknown option, expected 'push', 'pop', "
3280 "'rvc', 'norvc', 'arch', 'relax', 'norelax', "
3281 "'exact', or 'noexact'");
3289bool RISCVAsmParser::parseDirectiveAttribute() {
3290 MCAsmParser &Parser = getParser();
3296 std::optional<unsigned> Ret =
3299 return Error(TagLoc,
"attribute name not recognised: " + Name);
3303 const MCExpr *AttrExpr;
3310 if (check(!CE, TagLoc,
"expected numeric constant"))
3313 Tag =
CE->getValue();
3319 StringRef StringValue;
3320 int64_t IntegerValue = 0;
3321 bool IsIntegerValue =
true;
3326 IsIntegerValue =
false;
3329 if (IsIntegerValue) {
3330 const MCExpr *ValueExpr;
3336 return Error(ValueExprLoc,
"expected numeric constant");
3337 IntegerValue =
CE->getValue();
3350 getTargetStreamer().emitAttribute(
Tag, IntegerValue);
3352 getTargetStreamer().emitTextAttribute(
Tag, StringValue);
3355 if (resetToArch(StringValue, ValueExprLoc, Result,
false))
3359 getTargetStreamer().emitTextAttribute(
Tag, Result);
3363 getTargetStreamer().setArchString(Result);
3371 .
Cases({
"r",
"r4",
"i",
"b",
"sb",
"u",
"j",
"uj",
"s"},
true)
3372 .Cases({
"cr",
"ci",
"ciw",
"css",
"cl",
"cs",
"ca",
"cb",
"cj"},
3374 .
Cases({
"qc.eai",
"qc.ei",
"qc.eb",
"qc.ej",
"qc.es"},
3383bool RISCVAsmParser::parseDirectiveInsn(SMLoc L) {
3384 MCAsmParser &Parser = getParser();
3391 std::optional<int64_t>
Length;
3401 return Error(ErrorLoc,
3402 "instruction lengths must be a non-zero multiple of two");
3406 return Error(ErrorLoc,
3407 "instruction lengths over 64 bits are not supported");
3413 int64_t EncodingDerivedLength = ((
Value & 0b11) == 0b11) ? 4 : 2;
3418 if ((*
Length <= 4) && (*
Length != EncodingDerivedLength))
3419 return Error(ErrorLoc,
3420 "instruction length does not match the encoding");
3423 return Error(ErrorLoc,
"encoding value does not fit into instruction");
3426 return Error(ErrorLoc,
"encoding value does not fit into instruction");
3429 if (!getSTI().
hasFeature(RISCV::FeatureStdExtZca) &&
3430 (EncodingDerivedLength == 2))
3431 return Error(ErrorLoc,
"compressed instructions are not allowed");
3433 if (getParser().parseEOL(
"invalid operand for instruction")) {
3434 getParser().eatToEndOfStatement();
3442 Opcode = RISCV::Insn16;
3445 Opcode = RISCV::Insn32;
3448 Opcode = RISCV::Insn48;
3451 Opcode = RISCV::Insn64;
3457 Opcode = (EncodingDerivedLength == 2) ? RISCV::Insn16 : RISCV::Insn32;
3459 emitToStreamer(getStreamer(), MCInstBuilder(Opcode).addImm(
Value));
3464 return Error(ErrorLoc,
"invalid instruction format");
3466 std::string FormatName = (
".insn_" +
Format).str();
3468 ParseInstructionInfo
Info;
3471 if (parseInstruction(Info, FormatName, L,
Operands))
3483bool RISCVAsmParser::parseDirectiveVariantCC() {
3485 if (getParser().parseIdentifier(Name))
3486 return TokError(
"expected symbol name");
3489 getTargetStreamer().emitDirectiveVariantCC(
3494void RISCVAsmParser::emitToStreamer(MCStreamer &S,
const MCInst &Inst) {
3497 const MCSubtargetInfo &STI = getSTI();
3498 if (!STI.
hasFeature(RISCV::FeatureExactAssembly))
3501 ++RISCVNumInstrsCompressed;
3505void RISCVAsmParser::emitLoadImm(MCRegister DestReg, int64_t
Value,
3510 for (MCInst &Inst : Seq) {
3511 emitToStreamer(Out, Inst);
3515void RISCVAsmParser::emitAuipcInstPair(MCRegister DestReg, MCRegister TmpReg,
3516 const MCExpr *Symbol,
3518 unsigned SecondOpcode, SMLoc IDLoc,
3526 Out.emitLabel(TmpLabel);
3530 MCInstBuilder(RISCV::AUIPC).addReg(TmpReg).addExpr(SymbolHi));
3535 emitToStreamer(Out, MCInstBuilder(SecondOpcode)
3538 .addExpr(RefToLinkTmpLabel));
3541void RISCVAsmParser::emitLoadLocalAddress(MCInst &Inst, SMLoc IDLoc,
3552 STI->
hasFeature(RISCV::FeatureVendorXqcili) &&
3553 !ParserOptions.IsPicEnabled)
3555 Out, MCInstBuilder(RISCV::QC_E_LI).addReg(DestReg).addExpr(Symbol));
3561void RISCVAsmParser::emitLoadGlobalAddress(MCInst &Inst, SMLoc IDLoc,
3571 unsigned SecondOpcode = isRV64() ? RISCV::LD : RISCV::LW;
3572 emitAuipcInstPair(DestReg, DestReg, Symbol,
RISCV::S_GOT_HI, SecondOpcode,
3576void RISCVAsmParser::emitLoadAddress(MCInst &Inst, SMLoc IDLoc,
3585 if (ParserOptions.IsPicEnabled)
3586 emitLoadGlobalAddress(Inst, IDLoc, Out);
3588 emitLoadLocalAddress(Inst, IDLoc, Out);
3591void RISCVAsmParser::emitLoadTLSIEAddress(MCInst &Inst, SMLoc IDLoc,
3601 unsigned SecondOpcode = isRV64() ? RISCV::LD : RISCV::LW;
3602 emitAuipcInstPair(DestReg, DestReg, Symbol, ELF::R_RISCV_TLS_GOT_HI20,
3603 SecondOpcode, IDLoc, Out);
3606void RISCVAsmParser::emitLoadTLSGDAddress(MCInst &Inst, SMLoc IDLoc,
3616 emitAuipcInstPair(DestReg, DestReg, Symbol, ELF::R_RISCV_TLS_GD_HI20,
3617 RISCV::ADDI, IDLoc, Out);
3620void RISCVAsmParser::emitLoadStoreSymbol(MCInst &Inst,
unsigned Opcode,
3621 SMLoc IDLoc, MCStreamer &Out,
3630 unsigned DestRegOpIdx = HasTmpReg ? 1 : 0;
3632 unsigned SymbolOpIdx = HasTmpReg ? 2 : 1;
3636 if (getRISCVMCRegisterClass(RISCV::GPRPairRegClassID).
contains(TmpReg)) {
3637 const MCRegisterInfo *RI =
getContext().getRegisterInfo();
3638 TmpReg = RI->
getSubReg(TmpReg, RISCV::sub_gpr_even);
3646void RISCVAsmParser::emitQCELILoadStoreSymbol(MCInst &Inst,
unsigned Opcode,
3647 SMLoc IDLoc, MCStreamer &Out,
3657 unsigned SymbolOpIdx = HasTmpReg ? 2 : 1;
3661 MCInstBuilder(RISCV::QC_E_LI).addReg(AddrReg).addExpr(Symbol));
3664 const MCExpr *AccessExpr =
3670 struct CompressedForm {
3674 std::optional<CompressedForm> Compressed;
3678 case RISCV::PseudoQCAccessLBU:
3679 Compressed = {RISCV::PseudoQCAccessC_LBU, RISCV::FeatureStdExtZcb};
3681 case RISCV::PseudoQCAccessLH:
3682 Compressed = {RISCV::PseudoQCAccessC_LH, RISCV::FeatureStdExtZcb};
3684 case RISCV::PseudoQCAccessLHU:
3685 Compressed = {RISCV::PseudoQCAccessC_LHU, RISCV::FeatureStdExtZcb};
3687 case RISCV::PseudoQCAccessLW:
3688 Compressed = {RISCV::PseudoQCAccessC_LW, RISCV::FeatureStdExtZca};
3690 case RISCV::PseudoQCAccessSB:
3691 Compressed = {RISCV::PseudoQCAccessC_SB, RISCV::FeatureStdExtZcb};
3693 case RISCV::PseudoQCAccessSH:
3694 Compressed = {RISCV::PseudoQCAccessC_SH, RISCV::FeatureStdExtZcb};
3696 case RISCV::PseudoQCAccessSW:
3697 Compressed = {RISCV::PseudoQCAccessC_SW, RISCV::FeatureStdExtZca};
3704 getRISCVMCRegisterClass(RISCV::GPRCRegClassID).contains(AddrReg);
3705 if (HasTmpReg && CanUseGPRC) {
3708 getRISCVMCRegisterClass(RISCV::GPRCRegClassID).contains(DataReg);
3711 bool UseCompressed =
3712 Compressed && getSTI().hasFeature(Compressed->Feature) && CanUseGPRC;
3714 unsigned ActualOpcode = UseCompressed ? Compressed->Opcode : Opcode;
3717 emitToStreamer(Out, MCInstBuilder(ActualOpcode)
3721 .addExpr(AccessExpr));
3723 emitToStreamer(Out, MCInstBuilder(ActualOpcode)
3727 .addExpr(AccessExpr));
3731void RISCVAsmParser::emitPseudoExtend(MCInst &Inst,
bool SignExtend,
3732 int64_t Width, SMLoc IDLoc,
3741 const MCOperand &DestReg = Inst.
getOperand(0);
3742 const MCOperand &SourceReg = Inst.
getOperand(1);
3744 unsigned SecondOpcode = SignExtend ? RISCV::SRAI : RISCV::SRLI;
3745 int64_t ShAmt = (isRV64() ? 64 : 32) - Width;
3747 assert(ShAmt > 0 &&
"Shift amount must be non-zero.");
3749 emitToStreamer(Out, MCInstBuilder(RISCV::SLLI)
3754 emitToStreamer(Out, MCInstBuilder(SecondOpcode)
3760void RISCVAsmParser::emitVMSGE(MCInst &Inst,
unsigned Opcode, SMLoc IDLoc,
3767 emitToStreamer(Out, MCInstBuilder(Opcode)
3771 .addReg(MCRegister())
3773 emitToStreamer(Out, MCInstBuilder(RISCV::VMNAND_MM)
3784 "The destination register should not be V0.");
3786 emitToStreamer(Out, MCInstBuilder(Opcode)
3792 emitToStreamer(Out, MCInstBuilder(RISCV::VMXOR_MM)
3804 "The temporary vector register should not be V0.");
3805 emitToStreamer(Out, MCInstBuilder(Opcode)
3809 .addReg(MCRegister())
3811 emitToStreamer(Out, MCInstBuilder(RISCV::VMANDN_MM)
3823 "The temporary vector register should not be V0.");
3824 emitToStreamer(Out, MCInstBuilder(Opcode)
3828 .addReg(MCRegister())
3830 emitToStreamer(Out, MCInstBuilder(RISCV::VMANDN_MM)
3835 emitToStreamer(Out, MCInstBuilder(RISCV::VMANDN_MM)
3840 emitToStreamer(Out, MCInstBuilder(RISCV::VMOR_MM)
3848bool RISCVAsmParser::checkPseudoAddTPRel(MCInst &Inst,
3850 assert(Inst.
getOpcode() == RISCV::PseudoAddTPRel &&
"Invalid instruction");
3853 SMLoc ErrorLoc = ((RISCVOperand &)*
Operands[3]).getStartLoc();
3854 return Error(ErrorLoc,
"the second input operand must be tp/x4 when using "
3855 "%tprel_add specifier");
3861bool RISCVAsmParser::checkPseudoTLSDESCCall(MCInst &Inst,
3863 assert(Inst.
getOpcode() == RISCV::PseudoTLSDESCCall &&
"Invalid instruction");
3866 SMLoc ErrorLoc = ((RISCVOperand &)*
Operands[3]).getStartLoc();
3867 return Error(ErrorLoc,
"the output operand must be t0/x5 when using "
3868 "%tlsdesc_call specifier");
3874std::unique_ptr<RISCVOperand> RISCVAsmParser::defaultMaskRegOp()
const {
3875 return RISCVOperand::createReg(MCRegister(), llvm::SMLoc(), llvm::SMLoc());
3878std::unique_ptr<RISCVOperand> RISCVAsmParser::defaultFRMArgOp()
const {
3879 return RISCVOperand::createFRMArg(RISCVFPRndMode::RoundingMode::DYN,
3883std::unique_ptr<RISCVOperand> RISCVAsmParser::defaultFRMArgLegacyOp()
const {
3884 return RISCVOperand::createFRMArg(RISCVFPRndMode::RoundingMode::RNE,
3888std::unique_ptr<RISCVOperand> RISCVAsmParser::defaultZeroOffset() {
3890 llvm::SMLoc(), llvm::SMLoc(), isRV64());
3897 case RISCV::VLOXSEG2EI8_V:
3898 case RISCV::VLOXSEG2EI16_V:
3899 case RISCV::VLOXSEG2EI32_V:
3900 case RISCV::VLOXSEG2EI64_V:
3901 case RISCV::VLUXSEG2EI8_V:
3902 case RISCV::VLUXSEG2EI16_V:
3903 case RISCV::VLUXSEG2EI32_V:
3904 case RISCV::VLUXSEG2EI64_V:
3906 case RISCV::VLOXSEG3EI8_V:
3907 case RISCV::VLOXSEG3EI16_V:
3908 case RISCV::VLOXSEG3EI32_V:
3909 case RISCV::VLOXSEG3EI64_V:
3910 case RISCV::VLUXSEG3EI8_V:
3911 case RISCV::VLUXSEG3EI16_V:
3912 case RISCV::VLUXSEG3EI32_V:
3913 case RISCV::VLUXSEG3EI64_V:
3915 case RISCV::VLOXSEG4EI8_V:
3916 case RISCV::VLOXSEG4EI16_V:
3917 case RISCV::VLOXSEG4EI32_V:
3918 case RISCV::VLOXSEG4EI64_V:
3919 case RISCV::VLUXSEG4EI8_V:
3920 case RISCV::VLUXSEG4EI16_V:
3921 case RISCV::VLUXSEG4EI32_V:
3922 case RISCV::VLUXSEG4EI64_V:
3924 case RISCV::VLOXSEG5EI8_V:
3925 case RISCV::VLOXSEG5EI16_V:
3926 case RISCV::VLOXSEG5EI32_V:
3927 case RISCV::VLOXSEG5EI64_V:
3928 case RISCV::VLUXSEG5EI8_V:
3929 case RISCV::VLUXSEG5EI16_V:
3930 case RISCV::VLUXSEG5EI32_V:
3931 case RISCV::VLUXSEG5EI64_V:
3933 case RISCV::VLOXSEG6EI8_V:
3934 case RISCV::VLOXSEG6EI16_V:
3935 case RISCV::VLOXSEG6EI32_V:
3936 case RISCV::VLOXSEG6EI64_V:
3937 case RISCV::VLUXSEG6EI8_V:
3938 case RISCV::VLUXSEG6EI16_V:
3939 case RISCV::VLUXSEG6EI32_V:
3940 case RISCV::VLUXSEG6EI64_V:
3942 case RISCV::VLOXSEG7EI8_V:
3943 case RISCV::VLOXSEG7EI16_V:
3944 case RISCV::VLOXSEG7EI32_V:
3945 case RISCV::VLOXSEG7EI64_V:
3946 case RISCV::VLUXSEG7EI8_V:
3947 case RISCV::VLUXSEG7EI16_V:
3948 case RISCV::VLUXSEG7EI32_V:
3949 case RISCV::VLUXSEG7EI64_V:
3951 case RISCV::VLOXSEG8EI8_V:
3952 case RISCV::VLOXSEG8EI16_V:
3953 case RISCV::VLOXSEG8EI32_V:
3954 case RISCV::VLOXSEG8EI64_V:
3955 case RISCV::VLUXSEG8EI8_V:
3956 case RISCV::VLUXSEG8EI16_V:
3957 case RISCV::VLUXSEG8EI32_V:
3958 case RISCV::VLUXSEG8EI64_V:
3964 if (getRISCVMCRegisterClass(RISCV::VRM2RegClassID).
contains(
Reg))
3966 if (getRISCVMCRegisterClass(RISCV::VRM4RegClassID).
contains(
Reg))
3968 if (getRISCVMCRegisterClass(RISCV::VRM8RegClassID).
contains(
Reg))
3975 case RISCV::VFWMMACC_VV_SCALE:
3976 case RISCV::VFQMMACC_VV_SCALE:
3977 case RISCV::VF8WMMACC_VV_SCALE:
3978 case RISCV::VFWIMMACC_VV:
3979 case RISCV::VFQIMMACC_VV:
3980 case RISCV::VF8WIMMACC_VV:
3987bool RISCVAsmParser::validateInstruction(MCInst &Inst,
3991 if (Opcode == RISCV::PseudoVMSGEU_VX_M_T ||
3992 Opcode == RISCV::PseudoVMSGE_VX_M_T) {
3995 if (DestReg == TempReg) {
3996 SMLoc Loc =
Operands.back()->getStartLoc();
3997 return Error(Loc,
"the temporary vector register cannot be the same as "
3998 "the destination register");
4002 if (Opcode == RISCV::PseudoVMSGEU_VX_M || Opcode == RISCV::PseudoVMSGE_VX_M) {
4005 if (MaskReg == RISCV::V0 && DestReg == RISCV::V0) {
4006 SMLoc Loc =
Operands.back()->getStartLoc();
4007 return Error(Loc,
"the destination vector register cannot overlap the "
4008 "mask register unless a temporary register is "
4013 if (Opcode == RISCV::CV_INSERT &&
4016 "the sum of the immediate operands must be less than 32");
4021 case RISCV::TH_LBIA:
4022 case RISCV::TH_LBIB:
4023 case RISCV::TH_LBUIA:
4024 case RISCV::TH_LBUIB:
4025 case RISCV::TH_LHIA:
4026 case RISCV::TH_LHIB:
4027 case RISCV::TH_LHUIA:
4028 case RISCV::TH_LHUIB:
4029 case RISCV::TH_LWIA:
4030 case RISCV::TH_LWIB:
4031 case RISCV::TH_LWUIA:
4032 case RISCV::TH_LWUIB:
4033 case RISCV::TH_LDIA:
4034 case RISCV::TH_LDIB:
4036 return Error(
Operands[1]->getStartLoc(),
"rd and rs1 must be different");
4039 case RISCV::TH_LWUD:
4040 case RISCV::TH_LWD: {
4046 if (Rs1 == Rd1 || Rs1 == Rd2 || Rd1 == Rd2) {
4047 SMLoc Loc =
Operands[1]->getStartLoc();
4048 return Error(Loc,
"rs1, rd1, and rd2 cannot overlap");
4054 if (Opcode == RISCV::CM_MVSA01 || Opcode == RISCV::QC_CM_MVSA01) {
4058 SMLoc Loc =
Operands[1]->getStartLoc();
4059 return Error(Loc,
"rs1 and rs2 must be different");
4064 auto CheckOperandDoesNotOverlapV0 = [&](
int OperandIdx,
4065 unsigned ParsedIdx) {
4068 "vd, vs1, and vs2 cannot overlap v0.scale");
4073 RISCV::getNamedOperandIdx(Inst.
getOpcode(), RISCV::OpName::vd);
4075 RISCV::getNamedOperandIdx(Inst.
getOpcode(), RISCV::OpName::vs1);
4077 RISCV::getNamedOperandIdx(Inst.
getOpcode(), RISCV::OpName::vs2);
4078 assert(DestIdx >= 0 && VS1Idx >= 0 && VS2Idx >= 0 &&
4079 "Unexpected Zvvfmm scaled operand list");
4081 if (CheckOperandDoesNotOverlapV0(DestIdx, 1) ||
4082 CheckOperandDoesNotOverlapV0(VS1Idx, 2) ||
4083 CheckOperandDoesNotOverlapV0(VS2Idx, 3))
4087 const MCInstrDesc &MCID = MII.
get(Opcode);
4091 int DestIdx = RISCV::getNamedOperandIdx(Inst.
getOpcode(), RISCV::OpName::vd);
4095 const MCParsedAsmOperand *ParsedOp =
Operands[1].get();
4096 if (!ParsedOp->
isReg()) {
4101 const MCRegisterInfo *RI =
getContext().getRegisterInfo();
4104 "Can't find parsed dest operand");
4110 RISCV::getNamedOperandIdx(Inst.
getOpcode(), RISCV::OpName::vs2);
4111 assert(VS2Idx >= 0 &&
"No vs2 operand?");
4112 unsigned CheckEncoding =
4115 for (
unsigned i = 0; i < std::max(NF, Lmul); i++) {
4116 if ((DestEncoding + i) == CheckEncoding)
4117 return Error(Loc,
"the destination vector register group cannot overlap"
4118 " the source vector register group");
4123 RISCV::getNamedOperandIdx(Inst.
getOpcode(), RISCV::OpName::vs1);
4127 unsigned CheckEncoding =
4129 for (
unsigned i = 0; i < Lmul; i++) {
4130 if ((DestEncoding + i) == CheckEncoding)
4132 "the destination vector register group cannot overlap"
4133 " the source vector register group");
4139 int VMIdx = RISCV::getNamedOperandIdx(Inst.
getOpcode(), RISCV::OpName::vm);
4140 assert(VMIdx >= 0 &&
"No vm operand?");
4142 if (DestReg == RISCV::V0) {
4145 return Error(Loc,
"the destination vector register group cannot be V0");
4153 "Unexpected mask operand register");
4155 return Error(Loc,
"the destination vector register group cannot overlap"
4156 " the mask register");
4164 RISCV::getNamedOperandIdx(Inst.
getOpcode(), RISCV::OpName::vmask);
4166 if (MaskReg != RISCV::V0 && MaskReg != RISCV::V1)
4168 "vmask operand only supports v0 or v1");
4171 RISCV::OpName RegOps[] = {RISCV::OpName::vd, RISCV::OpName::vs1,
4172 RISCV::OpName::vs2};
4173 for (RISCV::OpName OpN : RegOps) {
4174 int Idx = RISCV::getNamedOperandIdx(Inst.
getOpcode(), OpN);
4180 for (
unsigned i = 0; i < RegLmul; i++) {
4181 if ((RegEnc + i) == MaskEnc) {
4184 Twine(
"register conflicts with vmask register ") +
4194bool RISCVAsmParser::processInstruction(MCInst &Inst, SMLoc IDLoc,
4202 case RISCV::MOP_RR_7: {
4214 case RISCV::MOP_R_28: {
4232 case RISCV::PseudoC_ADDI_NOP: {
4234 emitToStreamer(Out, MCInstBuilder(RISCV::C_NOP));
4244 if (getSTI().
hasFeature(RISCV::Feature64Bit))
4246 emitToStreamer(Out, MCInstBuilder(RISCV::ZEXT_H_RV32)
4251 case RISCV::PACKW: {
4255 emitToStreamer(Out, MCInstBuilder(RISCV::ZEXT_H_RV64)
4260 case RISCV::PseudoLLAImm:
4261 case RISCV::PseudoLAImm:
4262 case RISCV::PseudoLI: {
4268 emitToStreamer(Out, MCInstBuilder(RISCV::ADDI)
4280 emitLoadImm(
Reg,
Imm, Out);
4283 case RISCV::PseudoLLA:
4284 emitLoadLocalAddress(Inst, IDLoc, Out);
4286 case RISCV::PseudoLGA:
4287 emitLoadGlobalAddress(Inst, IDLoc, Out);
4289 case RISCV::PseudoLA:
4290 emitLoadAddress(Inst, IDLoc, Out);
4292 case RISCV::PseudoLA_TLS_IE:
4293 emitLoadTLSIEAddress(Inst, IDLoc, Out);
4295 case RISCV::PseudoLA_TLS_GD:
4296 emitLoadTLSGDAddress(Inst, IDLoc, Out);
4298 case RISCV::PseudoLB:
4299 emitLoadStoreSymbol(Inst, RISCV::LB, IDLoc, Out,
false);
4301 case RISCV::PseudoLBU:
4302 emitLoadStoreSymbol(Inst, RISCV::LBU, IDLoc, Out,
false);
4304 case RISCV::PseudoLH:
4305 emitLoadStoreSymbol(Inst, RISCV::LH, IDLoc, Out,
false);
4307 case RISCV::PseudoLHU:
4308 emitLoadStoreSymbol(Inst, RISCV::LHU, IDLoc, Out,
false);
4310 case RISCV::PseudoLW:
4311 emitLoadStoreSymbol(Inst, RISCV::LW, IDLoc, Out,
false);
4313 case RISCV::PseudoLWU:
4314 emitLoadStoreSymbol(Inst, RISCV::LWU, IDLoc, Out,
false);
4316 case RISCV::PseudoLD:
4317 emitLoadStoreSymbol(Inst, RISCV::LD, IDLoc, Out,
false);
4319 case RISCV::PseudoLD_RV32:
4320 emitLoadStoreSymbol(Inst, RISCV::LD_RV32, IDLoc, Out,
false);
4322 case RISCV::PseudoFLH:
4323 emitLoadStoreSymbol(Inst, RISCV::FLH, IDLoc, Out,
true);
4325 case RISCV::PseudoFLW:
4326 emitLoadStoreSymbol(Inst, RISCV::FLW, IDLoc, Out,
true);
4328 case RISCV::PseudoFLD:
4329 emitLoadStoreSymbol(Inst, RISCV::FLD, IDLoc, Out,
true);
4331 case RISCV::PseudoFLQ:
4332 emitLoadStoreSymbol(Inst, RISCV::FLQ, IDLoc, Out,
true);
4334 case RISCV::PseudoSB:
4335 emitLoadStoreSymbol(Inst, RISCV::SB, IDLoc, Out,
true);
4337 case RISCV::PseudoSH:
4338 emitLoadStoreSymbol(Inst, RISCV::SH, IDLoc, Out,
true);
4340 case RISCV::PseudoSW:
4341 emitLoadStoreSymbol(Inst, RISCV::SW, IDLoc, Out,
true);
4343 case RISCV::PseudoSD:
4344 emitLoadStoreSymbol(Inst, RISCV::SD, IDLoc, Out,
true);
4346 case RISCV::PseudoSD_RV32:
4347 emitLoadStoreSymbol(Inst, RISCV::SD_RV32, IDLoc, Out,
true);
4349 case RISCV::PseudoQC_E_LB:
4350 emitQCELILoadStoreSymbol(Inst, RISCV::PseudoQCAccessLB, IDLoc, Out,
4353 case RISCV::PseudoQC_E_LBU:
4354 emitQCELILoadStoreSymbol(Inst, RISCV::PseudoQCAccessLBU, IDLoc, Out,
4357 case RISCV::PseudoQC_E_LH:
4358 emitQCELILoadStoreSymbol(Inst, RISCV::PseudoQCAccessLH, IDLoc, Out,
4361 case RISCV::PseudoQC_E_LHU:
4362 emitQCELILoadStoreSymbol(Inst, RISCV::PseudoQCAccessLHU, IDLoc, Out,
4365 case RISCV::PseudoQC_E_LW:
4366 emitQCELILoadStoreSymbol(Inst, RISCV::PseudoQCAccessLW, IDLoc, Out,
4369 case RISCV::PseudoQC_E_SB:
4370 emitQCELILoadStoreSymbol(Inst, RISCV::PseudoQCAccessSB, IDLoc, Out,
4373 case RISCV::PseudoQC_E_SH:
4374 emitQCELILoadStoreSymbol(Inst, RISCV::PseudoQCAccessSH, IDLoc, Out,
4377 case RISCV::PseudoQC_E_SW:
4378 emitQCELILoadStoreSymbol(Inst, RISCV::PseudoQCAccessSW, IDLoc, Out,
4381 case RISCV::PseudoFSH:
4382 emitLoadStoreSymbol(Inst, RISCV::FSH, IDLoc, Out,
true);
4384 case RISCV::PseudoFSW:
4385 emitLoadStoreSymbol(Inst, RISCV::FSW, IDLoc, Out,
true);
4387 case RISCV::PseudoFSD:
4388 emitLoadStoreSymbol(Inst, RISCV::FSD, IDLoc, Out,
true);
4390 case RISCV::PseudoFSQ:
4391 emitLoadStoreSymbol(Inst, RISCV::FSQ, IDLoc, Out,
true);
4393 case RISCV::PseudoAddTPRel:
4394 if (checkPseudoAddTPRel(Inst,
Operands))
4397 case RISCV::PseudoTLSDESCCall:
4398 if (checkPseudoTLSDESCCall(Inst,
Operands))
4401 case RISCV::PseudoSEXT_B:
4402 emitPseudoExtend(Inst,
true, 8, IDLoc, Out);
4404 case RISCV::PseudoSEXT_H:
4405 emitPseudoExtend(Inst,
true, 16, IDLoc, Out);
4407 case RISCV::PseudoZEXT_H:
4408 emitPseudoExtend(Inst,
false, 16, IDLoc, Out);
4410 case RISCV::PseudoZEXT_W:
4411 emitPseudoExtend(Inst,
false, 32, IDLoc, Out);
4413 case RISCV::PseudoVMSGEU_VX_M:
4414 case RISCV::PseudoVMSGEU_VX_M_T:
4415 emitVMSGE(Inst, RISCV::VMSLTU_VX, IDLoc, Out);
4417 case RISCV::PseudoVMSGE_VX_M:
4418 case RISCV::PseudoVMSGE_VX_M_T:
4419 emitVMSGE(Inst, RISCV::VMSLT_VX, IDLoc, Out);
4421 case RISCV::PseudoVMSGE_VI:
4422 case RISCV::PseudoVMSLT_VI: {
4426 unsigned Opc = Inst.
getOpcode() == RISCV::PseudoVMSGE_VI ? RISCV::VMSGT_VI
4428 emitToStreamer(Out, MCInstBuilder(
Opc)
4436 case RISCV::PseudoVMSGEU_VI:
4437 case RISCV::PseudoVMSLTU_VI: {
4444 unsigned Opc = Inst.
getOpcode() == RISCV::PseudoVMSGEU_VI
4447 emitToStreamer(Out, MCInstBuilder(
Opc)
4455 unsigned Opc = Inst.
getOpcode() == RISCV::PseudoVMSGEU_VI
4458 emitToStreamer(Out, MCInstBuilder(
Opc)
4468 case RISCV::PseudoCV_ELW:
4469 emitLoadStoreSymbol(Inst, RISCV::CV_ELW, IDLoc, Out,
false);
4473 emitToStreamer(Out, Inst);
static MCRegister MatchRegisterName(StringRef Name)
static const char * getSubtargetFeatureName(uint64_t Val)
static SDValue Widen(SelectionDAG *CurDAG, SDValue N)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static void applyMnemonicAliases(StringRef &Mnemonic, const FeatureBitset &Features, unsigned VariantID)
static MCDisassembler::DecodeStatus addOperand(MCInst &Inst, const MCOperand &Opnd)
static bool isNot(const MachineRegisterInfo &MRI, const MachineInstr &MI)
static MCRegister MatchRegisterAltName(StringRef Name)
Maps from the set of all alternative registernames to a register number.
bpf unwind BPF Unwind Lower
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")
static bool matchRegisterNameHelper(const MCSubtargetInfo &STI, MCRegister &Reg, StringRef Name)
#define LLVM_EXTERNAL_VISIBILITY
const FeatureInfo AllFeatures[]
static bool hasFeature(StringRef Feature, const FeatureBitset &FeatureBits, ArrayRef< SubtargetFeatureKV > ProcFeatures)
Promote Memory to Register
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))
bool isValidInsnFormat(StringRef Format, const MCSubtargetInfo &STI)
static bool isZvvfmmScaleOpcode(unsigned Opcode)
LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeRISCVAsmParser()
static unsigned getNFforLXSEG(unsigned Opcode)
unsigned getLMULFromVectorRegister(MCRegister Reg)
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
This file implements the SmallBitVector class.
This file defines the SmallSet class.
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
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...
StringRef getStringContents() const
Get the contents of a string token (without quotes).
bool is(TokenKind K) const
LLVM_ABI SMLoc getEndLoc() const
StringRef getIdentifier() const
Get the identifier string for the current token, which should be an identifier or a string.
Encoding
Size and signedness of expression operations' operands.
Error takeError()
Take ownership of the stored error.
void printExpr(raw_ostream &, const MCExpr &) const
const MCTargetOptions & getTargetOptions() const
const AsmToken & getTok()
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.
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.
bool parseOptionalToken(AsmToken::TokenKind T)
Attempt to parse and consume token, returning true on success.
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
virtual bool parseAbsoluteExpression(int64_t &Res)=0
Parse an expression which must evaluate to an absolute value.
MCStreamer & getStreamer()
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
const MCObjectFileInfo * getObjectFileInfo() const
LLVM_ABI MCSymbol * createNamedTempSymbol()
Create a temporary symbol with a unique name whose name cannot be omitted in the symbol table.
LLVM_ABI bool evaluateAsRelocatable(MCValue &Res, const MCAssembler *Asm) const
Try to evaluate the expression to a relocatable value, i.e.
Instances of this class represent a single low-level machine instruction.
unsigned getNumOperands() const
unsigned getOpcode() const
void addOperand(const MCOperand Op)
const MCOperand & getOperand(unsigned i) const
ArrayRef< MCOperandInfo > operands() const
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode.
StringRef getName(unsigned Opcode) const
Returns the name for the instructions with the given opcode.
bool isPositionIndependent() const
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 SMLoc getStartLoc() const =0
getStartLoc - Get the location of the first token of this operand.
virtual bool isReg() const =0
isReg - Is this a register operand?
virtual MCRegister getReg() const =0
uint16_t getEncodingValue(MCRegister Reg) const
Returns the encoding for Reg.
MCRegister getSubReg(MCRegister Reg, unsigned Idx) const
Returns the physical register number of sub-register "Index" for physical register RegNo.
Wrapper class representing physical registers. Should be passed by value.
constexpr bool isValid() const
static const MCSpecifierExpr * create(const MCExpr *Expr, Spec S, MCContext &Ctx, SMLoc Loc=SMLoc())
virtual void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI)
Emit the given Instruction into the current section.
Generic base class for all target subtargets.
bool hasFeature(unsigned Feature) const
const FeatureBitset & getFeatureBits() const
const FeatureBitset & ToggleFeature(uint64_t FB)
Toggle a feature and return the re-computed feature bits.
ArrayRef< SubtargetFeatureKV > getAllProcessorFeatures() const
Return processor features.
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
bool isVariable() const
isVariable - Check if this is a variable symbol.
const MCExpr * getVariableValue() const
Get the expression of the variable symbol.
MCTargetAsmParser - Generic interface to target specific assembly parsers.
const MCSymbol * getAddSym() const
uint32_t getSpecifier() const
const MCSymbol * getSubSym() const
Ternary parse status returned by various parse* methods.
static constexpr StatusTy Failure
static constexpr StatusTy Success
static constexpr StatusTy NoMatch
static LLVM_ABI bool isSupportedExtensionFeature(StringRef Ext)
static LLVM_ABI std::string getTargetFeatureForExtension(StringRef Ext)
static LLVM_ABI llvm::Expected< std::unique_ptr< RISCVISAInfo > > parseArchString(StringRef Arch, bool EnableExperimentalExtension, bool ExperimentalExtensionVersionCheck=true)
Parse RISC-V ISA info from arch string.
static const char * getRegisterName(const RISCVMCOptions &CLOpts, MCRegister Reg)
constexpr unsigned id() const
static SMLoc getFromPointer(const char *Ptr)
constexpr const char * getPointer() const
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
reference emplace_back(ArgTypes &&... Args)
Represent a constant reference to a string, i.e.
std::string str() const
Get the contents as an std::string.
char back() const
Get the last character in the string.
A switch()-like statement whose cases are string literals.
StringSwitch & Cases(std::initializer_list< StringLiteral > CaseStrings, T Value)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
const AArch64MCOptions & getCLOpts(const MCTargetOptions &Options)
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
uint16_t StackAdjustment(const RuntimeFunction &RF)
StackAdjustment - calculated stack adjustment in words.
LLVM_ABI std::optional< unsigned > attrTypeFromString(StringRef tag, TagNameMap tagNameMap)
MCExpr const & getExpr(MCExpr const &Expr)
bool isRVE(ABI TargetABI)
Expected< ABI > computeTargetABI(const MCSubtargetInfo &STI, StringRef ABIName)
LLVM_ABI const TagNameMap & getRISCVAttributeTags()
static RoundingMode stringToRoundingMode(StringRef Str)
llvm::Expected< std::unique_ptr< RISCVISAInfo > > parseFeatureBits(const MCSubtargetInfo &STI)
int getLoadFPImm(APFloat FPImm)
getLoadFPImm - Return a 5-bit binary encoding of the floating-point immediate value.
void generateMCInstSeq(int64_t Val, const MCSubtargetInfo &STI, MCRegister DestReg, SmallVectorImpl< MCInst > &Insts)
bool compress(MCInst &OutInst, const MCInst &MI, const MCSubtargetInfo &STI)
static VLMUL encodeLMUL(unsigned LMUL, bool Fractional)
LLVM_ABI unsigned encodeXSfmmVType(unsigned SEW, unsigned Widen, bool AltFmt)
static bool isValidLMUL(unsigned LMUL, bool Fractional)
static bool isValidSEW(unsigned SEW)
LLVM_ABI void printVType(unsigned VType, raw_ostream &OS)
static bool isValidXSfmmVType(unsigned VTypeI)
LLVM_ABI unsigned encodeVTYPE(VLMUL VLMUL, unsigned SEW, bool TailAgnostic, bool MaskAgnostic, bool AltFmt=false)
unsigned encodeRegList(MCRegister EndReg, bool IsRVE=false)
static unsigned getStackAdjBase(unsigned RlistVal, bool IsRV64)
void printRegList(unsigned RlistEncode, raw_ostream &OS)
const RISCVMCOptions & getCLOpts(const MCTargetOptions &Options)
Specifier parseSpecifierName(StringRef name)
void updateCZceFeatureImplications(MCSubtargetInfo &STI)
bool isValidYBNDSWImm(int64_t Imm)
@ CE
Windows NT (Windows on ARM)
static SMTVTypeMode stringToSMTVTypeMode(StringRef Str)
static bool isValidSMTVTypeMode(unsigned Mode)
@ Valid
The data is already valid.
LLVM_ABI TargetOptions getTargetOptions(const cl::LibraryOptionsContext &LibraryOptions, const llvm::Triple &TheTriple)
Common utility function tightly tied to the options listed here.
std::function< llvm::json::Value()> Lambda
BaseReg
Stack frame base register. Bit 0 of FREInfo.Info.
This is an optimization pass for GlobalISel generic memory operations.
bool errorToBool(Error Err)
Helper for converting an Error to a bool.
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.
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.
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
testing::Matcher< const detail::ErrorHolder & > Failed()
Target & getTheRISCV32Target()
constexpr bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
Target & getTheRISCV64beTarget()
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
SmallVectorImpl< std::unique_ptr< MCParsedAsmOperand > > OperandVector
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isDigit(char C)
Checks if character C is one of the 10 decimal digits.
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...
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...
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
auto lower_bound(R &&Range, T &&Value)
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
DWARFExpression::Operation Op
Target & getTheRISCV64Target()
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
constexpr bool isShiftedInt(int64_t x)
Checks if a signed integer is an N bit number shifted left by S.
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
constexpr int64_t SignExtend64(uint64_t x)
Sign-extend the number in the bottom B bits of X to a 64-bit integer.
constexpr bool isShiftedUInt(uint64_t x)
Checks if a unsigned integer is an N bit number shifted left by S.
Target & getTheRISCV32beTarget()
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,...