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);
136 void validateInstructionPreEmit(
const MCInst &Inst,
137 const MCSubtargetInfo &STI);
141 void emitLoadImm(MCRegister DestReg, int64_t
Value, MCStreamer &Out);
145 void emitAuipcInstPair(MCRegister DestReg, MCRegister TmpReg,
147 unsigned SecondOpcode, SMLoc IDLoc, MCStreamer &Out);
150 void emitLoadLocalAddress(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out);
153 void emitLoadGlobalAddress(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out);
156 void emitLoadAddress(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out);
160 void emitLoadTLSIEAddress(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out);
164 void emitLoadTLSGDAddress(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out);
167 void emitLoadStoreSymbol(MCInst &Inst,
unsigned Opcode, SMLoc IDLoc,
168 MCStreamer &Out,
bool HasTmpReg);
173 void emitQCELILoadStoreSymbol(MCInst &Inst,
unsigned Opcode, SMLoc IDLoc,
174 MCStreamer &Out,
bool HasTmpReg);
177 void emitPseudoExtend(MCInst &Inst,
bool SignExtend, int64_t Width,
178 SMLoc IDLoc, MCStreamer &Out);
181 void emitVMSGE(MCInst &Inst,
unsigned Opcode, SMLoc IDLoc, MCStreamer &Out);
206#define GET_ASSEMBLER_HEADER
207#include "RISCVGenAsmMatcher.inc"
232 return parseRegList(
Operands,
true);
238 bool ExpectNegative =
false);
240 return parseZcmpStackAdj(
Operands,
true);
244 bool parseExprWithSpecifier(
const MCExpr *&Res, SMLoc &
E);
245 bool parseDataExpr(
const MCExpr *&Res)
override;
247 bool parseDirectiveOption();
248 bool parseDirectiveAttribute();
249 bool parseDirectiveInsn(SMLoc L);
250 bool parseDirectiveVariantCC();
255 bool resetToArch(StringRef Arch, SMLoc Loc, std::string &Result,
256 bool FromOptionDirective);
258 void setFeatureBits(
uint64_t Feature, StringRef FeatureString) {
260 MCSubtargetInfo &STI = copySTI();
266 setAvailableFeatures(ComputeAvailableFeatures(STI.
getFeatureBits()));
270 void clearFeatureBits(
uint64_t Feature, StringRef FeatureString) {
272 MCSubtargetInfo &STI = copySTI();
273 setAvailableFeatures(
278 void pushFeatureBits() {
279 assert(FeatureBitStack.size() == ParserOptionsStack.size() &&
280 "These two stacks must be kept synchronized");
281 FeatureBitStack.push_back(getSTI().getFeatureBits());
282 ParserOptionsStack.push_back(ParserOptions);
285 bool popFeatureBits() {
286 assert(FeatureBitStack.size() == ParserOptionsStack.size() &&
287 "These two stacks must be kept synchronized");
288 if (FeatureBitStack.empty())
291 FeatureBitset FeatureBits = FeatureBitStack.pop_back_val();
292 copySTI().setFeatureBits(FeatureBits);
293 setAvailableFeatures(ComputeAvailableFeatures(FeatureBits));
295 ParserOptions = ParserOptionsStack.pop_back_val();
300 std::unique_ptr<RISCVOperand> defaultMaskRegOp()
const;
301 std::unique_ptr<RISCVOperand> defaultFRMArgOp()
const;
302 std::unique_ptr<RISCVOperand> defaultFRMArgLegacyOp()
const;
303 std::unique_ptr<RISCVOperand> defaultSMTVType();
304 std::unique_ptr<RISCVOperand> defaultZeroOffset();
307 enum RISCVMatchResultTy :
unsigned {
308 Match_Dummy = FIRST_TARGET_MATCH_RESULT_TY,
309#define GET_OPERAND_DIAGNOSTIC_TYPES
310#include "RISCVGenAsmMatcher.inc"
311#undef GET_OPERAND_DIAGNOSTIC_TYPES
315 static bool isSymbolDiff(
const MCExpr *Expr);
317 RISCVAsmParser(
const MCSubtargetInfo &STI, MCAsmParser &Parser,
318 const MCInstrInfo &MII)
319 : MCTargetAsmParser(STI, MII),
327 setAvailableFeatures(ComputeAvailableFeatures(STI.
getFeatureBits()));
332 if (CLOpts.add_build_attributes)
333 getTargetStreamer().emitTargetAttributes(STI,
false);
339 void onBeginOfFile()
override {
342 if (getTargetStreamer().hasTargetABI())
345 Expected<RISCVABI::ABI> ABIOrErr =
349 getTargetStreamer().setTargetABI(
353 getTargetStreamer().setTargetABI(*ABIOrErr);
419 MCRegister OffsetReg;
422 SMLoc StartLoc, EndLoc;
438 RISCVOperand(KindTy K) : Kind(
K) {}
441 RISCVOperand(
const RISCVOperand &o) : MCParsedAsmOperand() {
443 StartLoc =
o.StartLoc;
446 case KindTy::Register:
449 case KindTy::Expression:
452 case KindTy::FPImmediate:
458 case KindTy::SystemRegister:
464 case KindTy::SMTVType:
465 SMTVType =
o.SMTVType;
473 case KindTy::RegList:
476 case KindTy::StackAdj:
477 StackAdj =
o.StackAdj;
485 bool isToken()
const override {
return Kind == KindTy::Token; }
486 bool isReg()
const override {
return Kind == KindTy::Register; }
487 bool isExpr()
const {
return Kind == KindTy::Expression; }
488 bool isV0Reg()
const {
return Kind == KindTy::Register &&
Reg == RISCV::V0; }
489 bool isAnyReg()
const {
490 return Kind == KindTy::Register &&
491 (getRISCVMCRegisterClass(RISCV::GPRRegClassID).contains(
Reg) ||
492 getRISCVMCRegisterClass(RISCV::FPR64RegClassID).contains(
Reg) ||
493 getRISCVMCRegisterClass(RISCV::VRRegClassID).contains(
Reg));
495 bool isAnyRegC()
const {
496 return Kind == KindTy::Register &&
497 (getRISCVMCRegisterClass(RISCV::GPRCRegClassID).contains(
Reg) ||
498 getRISCVMCRegisterClass(RISCV::FPR64CRegClassID).contains(
Reg));
500 bool isImm()
const override {
return isExpr(); }
501 bool isMem()
const override {
return false; }
502 bool isSystemRegister()
const {
return Kind == KindTy::SystemRegister; }
503 bool isRegReg()
const {
return Kind == KindTy::RegReg; }
504 bool isRegList()
const {
return Kind == KindTy::RegList; }
505 bool isRegListS0()
const {
506 return Kind == KindTy::RegList && RegList.Encoding !=
RISCVZC::RA;
508 bool isStackAdj()
const {
return Kind == KindTy::StackAdj; }
511 return Kind == KindTy::Register &&
512 getRISCVMCRegisterClass(RISCV::GPRRegClassID).contains(
Reg);
515 bool isGPRForFP(
const MCSubtargetInfo &STI)
const {
522 bool isGPRForFP64(
const MCSubtargetInfo &STI)
const {
531 bool isEvenGPRForFP64(
const MCSubtargetInfo &STI)
const {
532 return isGPR() && (
Reg - RISCV::X0) % 2 == 0 &&
537 static bool evaluateConstantExpr(
const MCExpr *Expr, int64_t &
Imm) {
539 Imm =
CE->getValue();
548 template <
int N>
bool isBareSimmNLsb0()
const {
557 return RISCVAsmParser::classifySymbolRef(
getExpr(), VK) &&
563 template <
int N>
bool isBareSimmN()
const {
569 return isInt<N>(fixImmediateForRV32(
Imm, isRV64Expr()));
572 return RISCVAsmParser::classifySymbolRef(
getExpr(), VK) &&
578 bool isBareSymbol()
const {
581 if (!isExpr() || evaluateConstantExpr(
getExpr(),
Imm))
585 return RISCVAsmParser::classifySymbolRef(
getExpr(), VK) &&
589 bool isCallSymbol()
const {
592 if (!isExpr() || evaluateConstantExpr(
getExpr(),
Imm))
596 return RISCVAsmParser::classifySymbolRef(
getExpr(), VK) &&
600 bool isTailCallSymbol()
const {
return isCallSymbol(); }
602 bool isPseudoJumpSymbol()
const {
605 if (!isExpr() || evaluateConstantExpr(
getExpr(),
Imm))
609 return RISCVAsmParser::classifySymbolRef(
getExpr(), VK) &&
613 bool isTPRelAddSymbol()
const {
616 if (!isExpr() || evaluateConstantExpr(
getExpr(),
Imm))
620 return RISCVAsmParser::classifySymbolRef(
getExpr(), VK) &&
621 VK == ELF::R_RISCV_TPREL_ADD;
624 bool isTLSDESCCallSymbol()
const {
627 if (!isExpr() || evaluateConstantExpr(
getExpr(),
Imm))
631 return RISCVAsmParser::classifySymbolRef(
getExpr(), VK) &&
632 VK == ELF::R_RISCV_TLSDESC_CALL;
635 bool isQCAccessSymbol()
const {
638 if (!isExpr() || evaluateConstantExpr(
getExpr(),
Imm))
642 return RISCVAsmParser::classifySymbolRef(
getExpr(), VK) &&
646 bool isCSRSystemRegister()
const {
return isSystemRegister(); }
650 bool isVTypeI10()
const {
651 if (Kind == KindTy::VType)
655 bool isVTypeI11()
const {
656 if (Kind == KindTy::VType)
661 bool isXSfmmVType()
const {
665 bool isTileLambda()
const {
671 bool isFenceArg()
const {
return Kind == KindTy::Fence; }
674 bool isFRMArg()
const {
return Kind == KindTy::FRM; }
675 bool isFRMArgLegacy()
const {
return Kind == KindTy::FRM; }
680 bool isSMTVType()
const {
681 return Kind == KindTy::SMTVType &&
685 bool isSMTI8()
const {
690 bool isLoadFPImm()
const {
693 if (Kind != KindTy::FPImmediate)
696 APFloat(APFloat::IEEEdouble(), APInt(64, getFPConst())));
699 return Idx >= 0 &&
Idx != 1;
702 bool isImmXLenLI()
const {
711 return RISCVAsmParser::isSymbolDiff(
getExpr());
714 bool isImmXLenLI_Restricted()
const {
718 bool IsConstantImm = evaluateConstantExpr(
getExpr(),
Imm);
720 return IsConstantImm &&
724 template <
unsigned N>
bool isUImm()
const {
728 bool IsConstantImm = evaluateConstantExpr(
getExpr(),
Imm);
732 template <
unsigned N,
unsigned S>
bool isUImmShifted()
const {
736 bool IsConstantImm = evaluateConstantExpr(
getExpr(),
Imm);
740 template <
class Pred>
bool isUImmPred(
Pred p)
const {
744 bool IsConstantImm = evaluateConstantExpr(
getExpr(),
Imm);
745 return IsConstantImm &&
p(
Imm);
748 bool isUImmLog2XLen()
const {
749 if (isExpr() && isRV64Expr())
754 bool isUImmLog2XLenNonZero()
const {
755 if (isExpr() && isRV64Expr())
760 bool isUImmLog2XLenHalf()
const {
761 if (isExpr() && isRV64Expr())
766 bool isUImm5NonZero()
const {
770 bool isUImm5GT3()
const {
774 bool isUImm4Plus1()
const {
779 bool isUImm5Plus1()
const {
784 bool isUImm6Plus1()
const {
789 bool isUImm5GE6Plus1()
const {
794 bool isUImm5Slist()
const {
795 return isUImmPred([](int64_t
Imm) {
796 return (
Imm == 0) || (
Imm == 1) || (
Imm == 2) || (
Imm == 4) ||
797 (
Imm == 8) || (
Imm == 16) || (
Imm == 15) || (
Imm == 31);
801 bool isUImm8GE32()
const {
805 bool isRnumArg()
const {
807 [](int64_t
Imm) {
return Imm >= INT64_C(0) &&
Imm <= INT64_C(10); });
810 bool isRnumArg_0_7()
const {
812 [](int64_t
Imm) {
return Imm >= INT64_C(0) &&
Imm <= INT64_C(7); });
815 bool isRnumArg_1_10()
const {
817 [](int64_t
Imm) {
return Imm >= INT64_C(1) &&
Imm <= INT64_C(10); });
820 bool isRnumArg_2_14()
const {
822 [](int64_t
Imm) {
return Imm >= INT64_C(2) &&
Imm <= INT64_C(14); });
825 template <
unsigned N>
bool isSImm()
const {
829 bool IsConstantImm = evaluateConstantExpr(
getExpr(),
Imm);
830 return IsConstantImm &&
isInt<N>(fixImmediateForRV32(
Imm, isRV64Expr()));
833 bool isYBNDSWImm()
const {
838 bool IsConstantImm = evaluateConstantExpr(
getExpr(),
Imm);
842 template <
class Pred>
bool isSImmPred(
Pred p)
const {
846 bool IsConstantImm = evaluateConstantExpr(
getExpr(),
Imm);
847 return IsConstantImm &&
p(fixImmediateForRV32(
Imm, isRV64Expr()));
850 bool isSImm5NonZero()
const {
854 bool isSImm6NonZero()
const {
858 bool isCLUIImm()
const {
859 return isUImmPred([](int64_t
Imm) {
864 bool isUImm10Lsb00NonZero()
const {
871 static int64_t fixImmediateForRV32(int64_t
Imm,
bool IsRV64Imm) {
877 bool isSImm12LO()
const {
883 return isInt<12>(fixImmediateForRV32(
Imm, isRV64Expr()));
886 return RISCVAsmParser::classifySymbolRef(
getExpr(), VK) &&
889 VK == ELF::R_RISCV_TLSDESC_ADD_LO12);
897 template <
bool (RISCVOperand::*Pred)() const>
898 DiagnosticPredicate isOptionalMemOffset()
const {
902 : DiagnosticPredicate::NearMatch;
905 bool isSImm12Lsb00000()
const {
909 bool isSImm10Lsb0000NonZero()
const {
914 bool isSImm16NonZero()
const {
918 bool isUImm16NonZero()
const {
922 bool isSImm20LI()
const {
928 return isInt<20>(fixImmediateForRV32(
Imm, isRV64Expr()));
931 return RISCVAsmParser::classifySymbolRef(
getExpr(), VK) &&
935 bool isSImm8PLI_B()
const {
return isSImm<8>() || isUImm<8>(); }
936 bool isSImm10PLUI()
const {
return isSImm<10>() || isUImm<10>(); }
938 bool isSImm10PLI_H()
const {
939 return isSImm<10>() || isUImmPred([](int64_t
Imm) {
943 bool isSImm10PLI_W()
const {
944 return isSImm<10>() || isUImmPred([](int64_t
Imm) {
949 bool isUImm20LUI()
const {
958 return RISCVAsmParser::classifySymbolRef(
getExpr(), VK) &&
959 (VK == ELF::R_RISCV_HI20 || VK == ELF::R_RISCV_TPREL_HI20);
962 bool isUImm20AUIPC()
const {
971 return RISCVAsmParser::classifySymbolRef(
getExpr(), VK) &&
973 VK == ELF::R_RISCV_TLS_GOT_HI20 || VK == ELF::R_RISCV_TLS_GD_HI20 ||
974 VK == ELF::R_RISCV_TLSDESC_HI20);
977 bool isImmZero()
const {
978 return isUImmPred([](int64_t
Imm) {
return 0 ==
Imm; });
981 bool isImmThree()
const {
982 return isUImmPred([](int64_t
Imm) {
return 3 ==
Imm; });
985 bool isImmFour()
const {
986 return isUImmPred([](int64_t
Imm) {
return 4 ==
Imm; });
989 bool isImm5Zibi()
const {
994 bool isSImm5Plus1()
const {
999 bool isSImm18Lsb0()
const {
1003 bool isSImm19Lsb00()
const {
1007 bool isSImm20Lsb000()
const {
1011 bool isSImm32Lsb0()
const {
1016 SMLoc getStartLoc()
const override {
return StartLoc; }
1018 SMLoc getEndLoc()
const override {
return EndLoc; }
1021 bool isRV64Expr()
const {
1022 assert(Kind == KindTy::Expression &&
"Invalid type access!");
1026 MCRegister
getReg()
const override {
1027 assert(Kind == KindTy::Register &&
"Invalid type access!");
1031 StringRef getSysReg()
const {
1032 assert(Kind == KindTy::SystemRegister &&
"Invalid type access!");
1033 return StringRef(SysReg.Data, SysReg.Length);
1036 const MCExpr *
getExpr()
const {
1037 assert(Kind == KindTy::Expression &&
"Invalid type access!");
1042 assert(Kind == KindTy::FPImmediate &&
"Invalid type access!");
1047 assert(Kind == KindTy::Token &&
"Invalid type access!");
1051 unsigned getVType()
const {
1052 assert(Kind == KindTy::VType &&
"Invalid type access!");
1057 assert(Kind == KindTy::FRM &&
"Invalid type access!");
1061 unsigned getFence()
const {
1062 assert(Kind == KindTy::Fence &&
"Invalid type access!");
1067 assert(Kind == KindTy::SMTVType &&
"Invalid type access!");
1068 return SMTVType.SMTVType;
1071 void print(raw_ostream &OS,
const MCAsmInfo &MAI)
const override {
1081 case KindTy::Expression:
1084 OS <<
' ' << (Expr.IsRV64 ?
"rv64" :
"rv32") <<
'>';
1086 case KindTy::FPImmediate:
1087 OS <<
"<fpimm: " << FPImm.Val <<
">";
1089 case KindTy::Register:
1095 case KindTy::SystemRegister:
1096 OS <<
"<sysreg: " << getSysReg() <<
" (" << SysReg.Encoding <<
")>";
1105 OS << roundingModeToString(getFRM());
1108 case KindTy::SMTVType:
1109 OS <<
"<smtvtype: ";
1110 OS << SMTVTypeModeToString(getSMTVType());
1118 case KindTy::RegList:
1123 case KindTy::StackAdj:
1124 OS <<
"<stackadj: ";
1128 case KindTy::RegReg:
1129 OS <<
"<RegReg: BaseReg " <<
RegName(
RegReg.BaseReg) <<
" OffsetReg "
1135 static std::unique_ptr<RISCVOperand> createToken(StringRef Str, SMLoc S) {
1136 auto Op = std::make_unique<RISCVOperand>(KindTy::Token);
1143 static std::unique_ptr<RISCVOperand> createReg(MCRegister
Reg, SMLoc S,
1145 auto Op = std::make_unique<RISCVOperand>(KindTy::Register);
1152 static std::unique_ptr<RISCVOperand> createExpr(
const MCExpr *Val, SMLoc S,
1153 SMLoc
E,
bool IsRV64) {
1154 auto Op = std::make_unique<RISCVOperand>(KindTy::Expression);
1155 Op->Expr.Expr = Val;
1156 Op->Expr.IsRV64 = IsRV64;
1162 static std::unique_ptr<RISCVOperand> createFPImm(
uint64_t Val, SMLoc S) {
1163 auto Op = std::make_unique<RISCVOperand>(KindTy::FPImmediate);
1164 Op->FPImm.Val = Val;
1170 static std::unique_ptr<RISCVOperand> createSysReg(StringRef Str, SMLoc S,
1171 unsigned Encoding) {
1172 auto Op = std::make_unique<RISCVOperand>(KindTy::SystemRegister);
1173 Op->SysReg.Data = Str.data();
1174 Op->SysReg.Length = Str.size();
1181 static std::unique_ptr<RISCVOperand>
1183 auto Op = std::make_unique<RISCVOperand>(KindTy::FRM);
1190 static std::unique_ptr<RISCVOperand>
1192 auto Op = std::make_unique<RISCVOperand>(KindTy::SMTVType);
1193 Op->SMTVType.SMTVType = VType;
1199 static std::unique_ptr<RISCVOperand> createFenceArg(
unsigned Val, SMLoc S) {
1200 auto Op = std::make_unique<RISCVOperand>(KindTy::Fence);
1201 Op->Fence.Val = Val;
1207 static std::unique_ptr<RISCVOperand> createVType(
unsigned VTypeI, SMLoc S) {
1208 auto Op = std::make_unique<RISCVOperand>(KindTy::VType);
1209 Op->VType.Val = VTypeI;
1215 static std::unique_ptr<RISCVOperand> createRegList(
unsigned RlistEncode,
1217 auto Op = std::make_unique<RISCVOperand>(KindTy::RegList);
1223 static std::unique_ptr<RISCVOperand>
1224 createRegReg(MCRegister BaseReg, MCRegister OffsetReg, SMLoc S) {
1225 auto Op = std::make_unique<RISCVOperand>(KindTy::RegReg);
1227 Op->RegReg.OffsetReg = OffsetReg;
1233 static std::unique_ptr<RISCVOperand> createStackAdj(
unsigned StackAdj, SMLoc S) {
1234 auto Op = std::make_unique<RISCVOperand>(KindTy::StackAdj);
1235 Op->StackAdj.Val = StackAdj;
1240 static void addExpr(MCInst &Inst,
const MCExpr *Expr,
bool IsRV64Imm) {
1241 assert(Expr &&
"Expr shouldn't be null!");
1253 void addRegOperands(MCInst &Inst,
unsigned N)
const {
1254 assert(
N == 1 &&
"Invalid number of operands!");
1258 void addGPRAsFPR16Operands(MCInst &Inst,
unsigned N)
const {
1259 assert(
N == 1 &&
"Invalid number of operands!");
1263 void addGPRAsFPR32Operands(MCInst &Inst,
unsigned N)
const {
1264 assert(
N == 1 &&
"Invalid number of operands!");
1268 void addGPRPairOperands(MCInst &Inst,
unsigned N)
const;
1270 void addImmOperands(MCInst &Inst,
unsigned N)
const {
1271 assert(
N == 1 &&
"Invalid number of operands!");
1272 addExpr(Inst,
getExpr(), isRV64Expr());
1275 template <
unsigned Bits>
1276 void addSExtImmOperands(MCInst &Inst,
unsigned N)
const {
1277 assert(
N == 1 &&
"Invalid number of operands!");
1284 void addFPImmOperands(MCInst &Inst,
unsigned N)
const {
1285 assert(
N == 1 &&
"Invalid number of operands!");
1287 addExpr(Inst,
getExpr(), isRV64Expr());
1292 APFloat(APFloat::IEEEdouble(), APInt(64, getFPConst())));
1296 void addFenceArgOperands(MCInst &Inst,
unsigned N)
const {
1297 assert(
N == 1 &&
"Invalid number of operands!");
1301 void addCSRSystemRegisterOperands(MCInst &Inst,
unsigned N)
const {
1302 assert(
N == 1 &&
"Invalid number of operands!");
1309 void addVTypeIOperands(MCInst &Inst,
unsigned N)
const {
1310 assert(
N == 1 &&
"Invalid number of operands!");
1312 if (Kind == KindTy::Expression) {
1313 [[maybe_unused]]
bool IsConstantImm =
1315 assert(IsConstantImm &&
"Invalid VTypeI Operand!");
1322 void addRegListOperands(MCInst &Inst,
unsigned N)
const {
1323 assert(
N == 1 &&
"Invalid number of operands!");
1327 void addRegRegOperands(MCInst &Inst,
unsigned N)
const {
1328 assert(
N == 2 &&
"Invalid number of operands!");
1333 void addStackAdjOperands(MCInst &Inst,
unsigned N)
const {
1334 assert(
N == 1 &&
"Invalid number of operands!");
1338 void addFRMArgOperands(MCInst &Inst,
unsigned N)
const {
1339 assert(
N == 1 &&
"Invalid number of operands!");
1343 void addSMTVTypeOperand(MCInst &Inst,
unsigned N)
const {
1344 assert(
N == 1 &&
"Invalid number of operands!");
1350#define GET_REGISTER_MATCHER
1351#define GET_SUBTARGET_FEATURE_NAME
1352#define GET_MATCHER_IMPLEMENTATION
1353#define GET_MNEMONIC_SPELL_CHECKER
1354#include "RISCVGenAsmMatcher.inc"
1356void RISCVOperand::addGPRPairOperands(
MCInst &Inst,
unsigned N)
const {
1357 assert(
N == 1 &&
"Invalid number of operands!");
1361bool RISCVAsmParser::generateImmOutOfRangeError(
1362 SMLoc ErrorLoc, int64_t
Lower, int64_t
Upper,
1363 const Twine &
Msg =
"immediate must be an integer in the range") {
1370std::string RISCVAsmParser::getCustomOperandDiag(
unsigned MatchError) {
1372 StringRef
Msg =
"immediate must be an integer in the range") {
1373 return (
Msg +
" [" + Twine(
Lower) +
", " + Twine(
Upper) +
"]").str();
1376 switch (MatchError) {
1380 if (
const char *Diag = getMatchKindDiag((RISCVMatchResultTy)MatchError))
1382 return std::string();
1383 case Match_InvalidImmXLenLI:
1385 return "operand must be a constant 64-bit integer";
1386 return Range(std::numeric_limits<int32_t>::min(),
1387 std::numeric_limits<uint32_t>::max());
1388 case Match_InvalidImmXLenLI_Restricted:
1390 return "operand either must be a constant 64-bit integer "
1391 "or a bare symbol name";
1392 return Range(std::numeric_limits<int32_t>::min(),
1393 std::numeric_limits<uint32_t>::max(),
1394 "operand either must be a bare symbol name or an immediate "
1395 "integer in the range");
1396 case Match_InvalidUImmLog2XLen:
1398 return Range(0, (1 << 6) - 1);
1399 return Range(0, (1 << 5) - 1);
1400 case Match_InvalidUImmLog2XLenNonZero:
1402 return Range(1, (1 << 6) - 1);
1403 return Range(1, (1 << 5) - 1);
1404 case Match_InvalidUImm1:
1405 return Range(0, (1 << 1) - 1);
1406 case Match_InvalidUImm2:
1407 return Range(0, (1 << 2) - 1);
1408 case Match_InvalidUImm2Lsb0:
1409 return Range(0, 2,
"immediate must be one of");
1410 case Match_InvalidUImm3:
1411 return Range(0, (1 << 3) - 1);
1412 case Match_InvalidUImm4:
1413 return Range(0, (1 << 4) - 1);
1414 case Match_InvalidUImm4Plus1:
1415 return Range(1, (1 << 4));
1416 case Match_InvalidUImm5:
1417 return Range(0, (1 << 5) - 1);
1418 case Match_InvalidUImm5NonZero:
1419 return Range(1, (1 << 5) - 1);
1420 case Match_InvalidUImm5GT3:
1421 return Range(4, (1 << 5) - 1);
1422 case Match_InvalidUImm5Plus1:
1423 return Range(1, (1 << 5));
1424 case Match_InvalidUImm5GE6Plus1:
1425 return Range(6, (1 << 5));
1426 case Match_InvalidUImm5Slist:
1427 return "immediate must be one of: 0, 1, 2, 4, 8, 15, 16, 31";
1428 case Match_InvalidUImm6:
1429 return Range(0, (1 << 6) - 1);
1430 case Match_InvalidUImm6Plus1:
1431 return Range(1, (1 << 6));
1432 case Match_InvalidUImm7:
1433 return Range(0, (1 << 7) - 1);
1434 case Match_InvalidUImm8:
1435 return Range(0, (1 << 8) - 1);
1436 case Match_InvalidUImm8GE32:
1437 return Range(32, (1 << 8) - 1);
1438 case Match_InvalidSImm5:
1439 return Range(-(1 << 4), (1 << 4) - 1);
1440 case Match_InvalidSImm5NonZero:
1441 return Range(-(1 << 4), (1 << 4) - 1,
1442 "immediate must be non-zero in the range");
1443 case Match_InvalidSImm6:
1444 return Range(-(1 << 5), (1 << 5) - 1);
1445 case Match_InvalidSImm6NonZero:
1446 return Range(-(1 << 5), (1 << 5) - 1,
1447 "immediate must be non-zero in the range");
1448 case Match_InvalidCLUIImm:
1449 return Range(1, (1 << 5) - 1,
"immediate must be in [0xfffe0, 0xfffff] or");
1450 case Match_InvalidUImm5Lsb0:
1451 return Range(0, (1 << 5) - 2,
1452 "immediate must be a multiple of 2 bytes in the range");
1453 case Match_InvalidUImm6Lsb0:
1454 return Range(0, (1 << 6) - 2,
1455 "immediate must be a multiple of 2 bytes in the range");
1456 case Match_InvalidUImm6Lsb000:
1457 return Range(0, (1 << 6) - 8,
1458 "immediate must be a multiple of 8 in the range");
1459 case Match_InvalidUImm7Lsb00:
1460 return Range(0, (1 << 7) - 4,
1461 "immediate must be a multiple of 4 bytes in the range");
1462 case Match_InvalidUImm8Lsb00:
1463 return Range(0, (1 << 8) - 4,
1464 "immediate must be a multiple of 4 bytes in the range");
1465 case Match_InvalidUImm8Lsb000:
1466 return Range(0, (1 << 8) - 8,
1467 "immediate must be a multiple of 8 bytes in the range");
1468 case Match_InvalidUImm9:
1469 return Range(0, (1 << 9) - 1,
"immediate offset must be in the range");
1470 case Match_InvalidBareSImm9Lsb0:
1471 return Range(-(1 << 8), (1 << 8) - 2,
1472 "immediate must be a multiple of 2 bytes in the range");
1473 case Match_InvalidUImm9Lsb000:
1474 return Range(0, (1 << 9) - 8,
1475 "immediate must be a multiple of 8 bytes in the range");
1476 case Match_InvalidUImm9Lsb0000:
1477 return Range(0, (1 << 9) - 16,
1478 "immediate must be a multiple of 16 bytes in the range");
1479 case Match_InvalidSImm8PLI_B:
1480 return Range(-(1 << 7), (1 << 8) - 1);
1481 case Match_InvalidSImm10:
1482 case Match_InvalidSImm10PLI_H:
1483 case Match_InvalidSImm10PLI_W:
1484 return Range(-(1 << 9), (1 << 9) - 1);
1485 case Match_InvalidSImm10PLUI:
1486 return Range(-(1 << 9), (1 << 10) - 1);
1487 case Match_InvalidUImm10Lsb00NonZero:
1488 return Range(4, (1 << 10) - 4,
1489 "immediate must be a multiple of 4 bytes in the range");
1490 case Match_InvalidUImm10Lsb0000:
1491 return Range(0, (1 << 10) - 16,
1492 "immediate must be a multiple of 16 bytes in the range");
1493 case Match_InvalidSImm10Lsb0000NonZero:
1495 -(1 << 9), (1 << 9) - 16,
1496 "immediate must be a multiple of 16 bytes and non-zero in the range");
1497 case Match_InvalidSImm11:
1498 return Range(-(1 << 10), (1 << 10) - 1);
1499 case Match_InvalidBareSImm11Lsb0:
1500 return Range(-(1 << 10), (1 << 10) - 2,
1501 "immediate must be a multiple of 2 bytes in the range");
1502 case Match_InvalidUImm10:
1503 return Range(0, (1 << 10) - 1);
1504 case Match_InvalidUImm11:
1505 return Range(0, (1 << 11) - 1);
1506 case Match_InvalidUImm14Lsb00:
1507 return Range(0, (1 << 14) - 4,
1508 "immediate must be a multiple of 4 bytes in the range");
1509 case Match_InvalidUImm16NonZero:
1510 return Range(1, (1 << 16) - 1);
1511 case Match_InvalidSImm12:
1512 return Range(-(1 << 11), (1 << 11) - 1);
1513 case Match_InvalidSImm12LO:
1514 return Range(-(1 << 11), (1 << 11) - 1,
1515 "operand must be a symbol with %lo/%pcrel_lo/%tprel_lo "
1516 "specifier or an integer in the range");
1517 case Match_InvalidBareSImm12Lsb0:
1518 return Range(-(1 << 11), (1 << 11) - 2,
1519 "immediate must be a multiple of 2 bytes in the range");
1520 case Match_InvalidSImm12Lsb00000:
1521 return Range(-(1 << 11), (1 << 11) - 32,
1522 "immediate must be a multiple of 32 bytes in the range");
1523 case Match_InvalidBareSImm13Lsb0:
1524 return Range(-(1 << 12), (1 << 12) - 2,
1525 "immediate must be a multiple of 2 bytes in the range");
1526 case Match_InvalidSImm16:
1527 return Range(-(1 << 15), (1 << 15) - 1);
1528 case Match_InvalidSImm16NonZero:
1529 return Range(-(1 << 15), (1 << 15) - 1,
1530 "immediate must be non-zero in the range");
1531 case Match_InvalidSImm20LI:
1532 return Range(-(1 << 19), (1 << 19) - 1,
1533 "operand must be a symbol with a %qc.abs20 specifier or an "
1534 "integer in the range");
1535 case Match_InvalidUImm20LUI:
1536 return Range(0, (1 << 20) - 1,
1537 "operand must be a symbol with %hi/%tprel_hi specifier or an "
1538 "integer in the range");
1539 case Match_InvalidUImm20:
1540 return Range(0, (1 << 20) - 1);
1541 case Match_InvalidUImm20AUIPC:
1544 "operand must be a symbol with a "
1545 "%pcrel_hi/%got_pcrel_hi/%tls_ie_pcrel_hi/%tls_gd_pcrel_hi specifier "
1546 "or an integer in the range");
1547 case Match_InvalidBareSImm21Lsb0:
1548 return Range(-(1 << 20), (1 << 20) - 2,
1549 "immediate must be a multiple of 2 bytes in the range");
1550 case Match_InvalidCSRSystemRegister:
1551 return Range(0, (1 << 12) - 1,
1552 "operand must be a valid system register name or an integer "
1554 case Match_InvalidImm5Zibi:
1555 return Range(-1, (1 << 5) - 1,
"immediate must be non-zero in the range");
1556 case Match_InvalidVTypeI:
1557 return "operand must be "
1558 "e[8|8alt|16|16alt|32|64],m[1|2|4|8|f2|f4|f8],[ta|tu],[ma|mu]";
1559 case Match_InvalidSImm5Plus1:
1560 return Range(-(1 << 4) + 1, (1 << 4),
"immediate must be in the range");
1561 case Match_InvalidSImm18:
1562 return Range(-(1 << 17), (1 << 17) - 1);
1563 case Match_InvalidSImm18Lsb0:
1564 return Range(-(1 << 17), (1 << 17) - 2,
1565 "immediate must be a multiple of 2 bytes in the range");
1566 case Match_InvalidSImm19Lsb00:
1567 return Range(-(1 << 18), (1 << 18) - 4,
1568 "immediate must be a multiple of 4 bytes in the range");
1569 case Match_InvalidSImm20Lsb000:
1570 return Range(-(1 << 19), (1 << 19) - 8,
1571 "immediate must be a multiple of 8 bytes in the range");
1572 case Match_InvalidSImm26:
1573 return Range(-(1 << 25), (1 << 25) - 1);
1575 case Match_InvalidBareSymbolQC_E_LI:
1578 case Match_InvalidBareSImm32:
1579 return Range(std::numeric_limits<int32_t>::min(),
1580 std::numeric_limits<uint32_t>::max());
1581 case Match_InvalidBareSImm32Lsb0:
1582 return Range(std::numeric_limits<int32_t>::min(),
1583 std::numeric_limits<int32_t>::max() - 1,
1584 "operand must be a multiple of 2 bytes in the range");
1585 case Match_InvalidRnumArg:
1586 return Range(0, 10);
1587 case Match_InvalidStackAdj:
1588 return "stack adjustment is invalid for this instruction and register "
1590 case Match_InvalidYBNDSWImm:
1591 return "immediate must be an integer in the range "
1592 "[1, 255], a multiple of 8 in the range [256, 504], "
1593 "or a multiple of 16 in the range [512, 4096]";
1600void RISCVAsmParser::FilterNearMisses(
1601 SmallVectorImpl<NearMissInfo> &NearMissesIn,
1602 SmallVectorImpl<NearMissMessage> &NearMissesOut, SMLoc IDLoc,
1606 std::multimap<unsigned, unsigned> OperandMissesSeen;
1607 SmallSet<FeatureBitset, 4> FeatureMissesSeen;
1608 bool ReportedTooFewOperands =
false;
1609 bool ReportedTooManyOperands =
false;
1611 for (NearMissInfo &
I : NearMissesIn) {
1612 switch (
I.getKind()) {
1615 ((RISCVOperand &)*
Operands[
I.getOperandIndex()]).getStartLoc();
1620 if (
I.getOperandClass() == InvalidMatchClass) {
1621 if (!ReportedTooManyOperands) {
1623 OperandLoc,
"unexpected extra operand for instruction"});
1624 ReportedTooManyOperands =
true;
1629 std::string OperandDiag = getCustomOperandDiag(
I.getOperandError());
1633 unsigned DupCheckMatchClass =
1634 OperandDiag.empty() ? ~0
U :
I.getOperandClass();
1635 auto PrevReports = OperandMissesSeen.equal_range(
I.getOperandIndex());
1637 PrevReports.first, PrevReports.second,
1638 [DupCheckMatchClass](
const std::pair<unsigned, unsigned> Pair) {
1639 if (DupCheckMatchClass == ~0U || Pair.second == ~0U)
1640 return Pair.second == DupCheckMatchClass;
1641 return isSubclass((MatchClassKind)DupCheckMatchClass,
1642 (MatchClassKind)Pair.second);
1645 OperandMissesSeen.insert(
1646 std::make_pair(
I.getOperandIndex(), DupCheckMatchClass));
1648 NearMissMessage Message;
1649 Message.Loc = OperandLoc;
1650 if (!OperandDiag.empty()) {
1651 Message.Message = OperandDiag;
1653 Message.Message =
"invalid operand for instruction";
1655 dbgs() <<
"Missing diagnostic string for operand class "
1656 << getMatchClassName((MatchClassKind)
I.getOperandClass())
1657 <<
I.getOperandClass() <<
", error " <<
I.getOperandError()
1658 <<
", opcode " << MII.
getName(
I.getOpcode()) <<
"\n");
1664 const FeatureBitset &MissingFeatures =
I.getFeatures();
1666 if (!FeatureMissesSeen.
insert(MissingFeatures).second)
1669 NearMissMessage Message;
1670 Message.Loc = IDLoc;
1671 bool FirstFeature =
true;
1672 Message.Message =
"instruction requires the following:";
1673 for (
unsigned Feature : MissingFeatures) {
1674 Message.Message += FirstFeature ?
" " :
", ";
1676 FirstFeature =
false;
1686 if (!ReportedTooFewOperands) {
1687 SMLoc EndLoc = ((RISCVOperand &)*
Operands.back()).getEndLoc();
1689 NearMissMessage{EndLoc,
"too few operands for instruction"});
1690 ReportedTooFewOperands =
true;
1702void RISCVAsmParser::ReportNearMisses(SmallVectorImpl<NearMissInfo> &NearMisses,
1705 FilterNearMisses(NearMisses, Messages, IDLoc,
Operands);
1710 Error(IDLoc,
"invalid instruction");
1713 Error(Messages[0].Loc, Messages[0].Message);
1718 "invalid instruction, any one of the following would fix this:");
1719 for (
auto &M : Messages)
1724bool RISCVAsmParser::matchAndEmitInstruction(SMLoc IDLoc,
unsigned &Opcode,
1728 bool MatchingInlineAsm) {
1733 MatchInstructionImpl(
Operands, Inst, &NearMisses, MatchingInlineAsm);
1738 if (validateInstruction(Inst,
Operands))
1740 return processInstruction(Inst, IDLoc,
Operands, Out);
1741 case Match_MnemonicFail: {
1742 FeatureBitset FBS = ComputeAvailableFeatures(getSTI().getFeatureBits());
1743 std::string Suggestion = RISCVMnemonicSpellCheck(
1745 return Error(IDLoc,
"unrecognized instruction mnemonic" + Suggestion);
1747 case Match_NearMisses:
1748 ReportNearMisses(NearMisses, IDLoc,
Operands);
1759MCRegister RISCVAsmParser::matchRegisterNameHelper(StringRef Name)
const {
1768 static_assert(RISCV::F0_D < RISCV::F0_H,
"FPR matching must be updated");
1769 static_assert(RISCV::F0_D < RISCV::F0_F,
"FPR matching must be updated");
1770 static_assert(RISCV::F0_D < RISCV::F0_Q,
"FPR matching must be updated");
1773 if (
isRVE() &&
Reg >= RISCV::X16 &&
Reg <= RISCV::X31)
1778bool RISCVAsmParser::parseRegister(MCRegister &
Reg, SMLoc &StartLoc,
1780 if (!tryParseRegister(
Reg, StartLoc, EndLoc).isSuccess())
1781 return Error(StartLoc,
"invalid register name");
1785ParseStatus RISCVAsmParser::tryParseRegister(MCRegister &
Reg, SMLoc &StartLoc,
1787 const AsmToken &Tok = getParser().getTok();
1790 StringRef
Name = getLexer().getTok().getIdentifier();
1802 SMLoc FirstS = getLoc();
1803 bool HadParens =
false;
1810 size_t ReadCount = getLexer().peekTokens(Buf);
1813 LParen = getParser().getTok();
1818 switch (getLexer().getKind()) {
1821 getLexer().UnLex(LParen);
1824 StringRef
Name = getLexer().getTok().getIdentifier();
1829 getLexer().UnLex(LParen);
1833 Operands.push_back(RISCVOperand::createToken(
"(", FirstS));
1835 SMLoc
E = getTok().getEndLoc();
1837 Operands.push_back(RISCVOperand::createReg(
Reg, S,
E));
1842 Operands.push_back(RISCVOperand::createToken(
")", getLoc()));
1853 switch (getLexer().getKind()) {
1863 if (getParser().parseExpression(Res,
E))
1868 int64_t
Imm =
CE->getValue();
1870 Operands.push_back(RISCVOperand::createExpr(Res, S,
E, isRV64()));
1879 if (getParser().parseIdentifier(Identifier))
1882 auto Opcode = RISCVInsnOpcode::lookupRISCVOpcodeByName(Identifier);
1885 "Unexpected opcode");
1888 Operands.push_back(RISCVOperand::createExpr(Res, S,
E, isRV64()));
1898 return generateImmOutOfRangeError(
1900 "opcode must be a valid opcode name or an immediate in the range");
1908 switch (getLexer().getKind()) {
1918 if (getParser().parseExpression(Res,
E))
1923 int64_t
Imm =
CE->getValue();
1924 if (
Imm >= 0 &&
Imm <= 2) {
1925 Operands.push_back(RISCVOperand::createExpr(Res, S,
E, isRV64()));
1934 if (getParser().parseIdentifier(Identifier))
1938 if (Identifier ==
"C0")
1940 else if (Identifier ==
"C1")
1942 else if (Identifier ==
"C2")
1949 Operands.push_back(RISCVOperand::createExpr(Res, S,
E, isRV64()));
1958 return generateImmOutOfRangeError(
1960 "opcode must be a valid opcode name or an immediate in the range");
1967 auto SysRegFromConstantInt = [
this](
const MCExpr *
E, SMLoc S) {
1969 int64_t
Imm =
CE->getValue();
1971 auto Range = RISCVSysReg::lookupSysRegByEncoding(
Imm);
1975 if (
Reg.IsAltName ||
Reg.IsDeprecatedName)
1978 return RISCVOperand::createSysReg(
1979 RISCVSysReg::getSysRegStr(
Reg.Name), S,
Imm);
1983 return RISCVOperand::createSysReg(
"", S,
Imm);
1986 return std::unique_ptr<RISCVOperand>();
1989 switch (getLexer().getKind()) {
1999 if (getParser().parseExpression(Res))
2002 if (
auto SysOpnd = SysRegFromConstantInt(Res, S)) {
2003 Operands.push_back(std::move(SysOpnd));
2007 return generateImmOutOfRangeError(S, 0, (1 << 12) - 1);
2011 if (getParser().parseIdentifier(Identifier))
2014 const auto *SysReg = RISCVSysReg::lookupSysRegByName(Identifier);
2017 if (SysReg->IsDeprecatedName) {
2019 auto Range = RISCVSysReg::lookupSysRegByEncoding(SysReg->Encoding);
2021 if (
Reg.IsAltName ||
Reg.IsDeprecatedName)
2023 Warning(S,
"'" + Identifier +
"' is a deprecated alias for '" +
2024 RISCVSysReg::getSysRegStr(
Reg.Name) +
"'");
2029 const auto &FeatureBits = getSTI().getFeatureBits();
2030 const auto &
AllFeatures = getSTI().getAllProcessorFeatures();
2031 if (!SysReg->haveRequiredFeatures(FeatureBits)) {
2032 const auto *Feature =
2034 return SysReg->FeaturesRequired[Feature.Value];
2036 std::string ErrorMsg =
2037 std::string(
"system register '") +
2038 std::string(RISCVSysReg::getSysRegStr(SysReg->Name)) +
"' ";
2039 if (SysReg->IsRV32Only && FeatureBits[RISCV::Feature64Bit]) {
2040 ErrorMsg +=
"is RV32 only";
2042 ErrorMsg +=
" and ";
2046 "requires '" + std::string(Feature->key()) +
"' to be enabled";
2049 return Error(S, ErrorMsg);
2052 RISCVOperand::createSysReg(Identifier, S, SysReg->Encoding));
2062 Operands.push_back(std::move(SysOpnd));
2067 return generateImmOutOfRangeError(S, 0, (1 << 12) - 1,
2068 "operand must be a valid system register "
2069 "name or an integer in the range");
2073 return generateImmOutOfRangeError(S, 0, (1 << 12) - 1);
2085 StringRef
Identifier = getTok().getIdentifier();
2086 if (
Identifier.compare_insensitive(
"inf") == 0) {
2089 getTok().getEndLoc(), isRV64()));
2090 }
else if (
Identifier.compare_insensitive(
"nan") == 0) {
2093 getTok().getEndLoc(), isRV64()));
2094 }
else if (
Identifier.compare_insensitive(
"min") == 0) {
2097 getTok().getEndLoc(), isRV64()));
2099 return TokError(
"invalid floating point literal");
2110 const AsmToken &Tok = getTok();
2112 return TokError(
"invalid floating point immediate");
2115 APFloat RealVal(APFloat::IEEEdouble());
2117 RealVal.convertFromString(Tok.
getString(), APFloat::rmTowardZero);
2119 return TokError(
"invalid floating point representation");
2122 RealVal.changeSign();
2124 Operands.push_back(RISCVOperand::createFPImm(
2125 RealVal.bitcastToAPInt().getZExtValue(), S));
2137 switch (getLexer().getKind()) {
2149 if (getParser().parseExpression(Res,
E))
2153 return parseOperandWithSpecifier(
Operands);
2156 Operands.push_back(RISCVOperand::createExpr(Res, S,
E, isRV64()));
2166 const MCExpr *Expr =
nullptr;
2167 bool Failed = parseExprWithSpecifier(Expr,
E);
2169 Operands.push_back(RISCVOperand::createExpr(Expr, S,
E, isRV64()));
2173bool RISCVAsmParser::parseExprWithSpecifier(
const MCExpr *&Res, SMLoc &
E) {
2174 SMLoc Loc = getLoc();
2176 return TokError(
"expected '%' relocation specifier");
2177 StringRef
Identifier = getParser().getTok().getIdentifier();
2180 return TokError(
"invalid relocation specifier");
2186 const MCExpr *SubExpr;
2187 if (getParser().parseParenExpression(SubExpr,
E))
2194bool RISCVAsmParser::parseDataExpr(
const MCExpr *&Res) {
2197 return parseExprWithSpecifier(Res,
E);
2198 return getParser().parseExpression(Res);
2208 StringRef
Identifier = getTok().getIdentifier();
2218 if (getParser().parseExpression(Res,
E))
2221 Operands.push_back(RISCVOperand::createExpr(Res, S,
E, isRV64()));
2231 std::string
Identifier(getTok().getIdentifier());
2237 SMLoc Loc = getLoc();
2238 if (getParser().parseIdentifier(PLT) || PLT !=
"plt")
2239 return Error(Loc,
"@ (except the deprecated/ignored @plt) is disallowed");
2253 Operands.push_back(RISCVOperand::createExpr(Res, S,
E, isRV64()));
2265 std::string
Identifier(getTok().getIdentifier());
2271 SMLoc Loc = getLoc();
2272 if (getParser().parseIdentifier(PLT) || PLT !=
"plt")
2273 return Error(Loc,
"@ (except the deprecated/ignored @plt) is disallowed");
2287 Operands.push_back(RISCVOperand::createExpr(Res, S,
E, isRV64()));
2296 if (getParser().parseExpression(Res,
E))
2299 if (Res->
getKind() != MCExpr::ExprKind::SymbolRef)
2300 return Error(S,
"operand must be a valid jump target");
2303 Operands.push_back(RISCVOperand::createExpr(Res, S,
E, isRV64()));
2324bool RISCVAsmParser::parseVTypeToken(
const AsmToken &Tok, VTypeState &State,
2325 unsigned &Sew,
unsigned &Lmul,
2326 bool &Fractional,
bool &TailAgnostic,
2327 bool &MaskAgnostic,
bool &AltFmt) {
2332 if (State < VTypeState::SeenSew &&
Identifier.consume_front(
"e")) {
2334 if (Identifier ==
"16alt") {
2337 }
else if (Identifier ==
"8alt") {
2347 State = VTypeState::SeenSew;
2351 if (State < VTypeState::SeenLmul &&
Identifier.consume_front(
"m")) {
2354 if (Identifier ==
"a" || Identifier ==
"u") {
2356 State = VTypeState::SeenMaskPolicy;
2367 unsigned ELEN = STI->
hasFeature(RISCV::FeatureStdExtZve64x) ? 64 : 32;
2368 unsigned MinLMUL = ELEN / 8;
2371 "use of vtype encodings with LMUL < SEWMIN/ELEN == mf" +
2372 Twine(MinLMUL) +
" is reserved");
2375 State = VTypeState::SeenLmul;
2379 if (State < VTypeState::SeenTailPolicy &&
Identifier.starts_with(
"t")) {
2380 if (Identifier ==
"ta")
2381 TailAgnostic =
true;
2382 else if (Identifier ==
"tu")
2383 TailAgnostic =
false;
2387 State = VTypeState::SeenTailPolicy;
2391 if (State < VTypeState::SeenMaskPolicy &&
Identifier.starts_with(
"m")) {
2392 if (Identifier ==
"ma")
2393 MaskAgnostic =
true;
2394 else if (Identifier ==
"mu")
2395 MaskAgnostic =
false;
2399 State = VTypeState::SeenMaskPolicy;
2412 bool Fractional =
false;
2413 bool TailAgnostic =
false;
2414 bool MaskAgnostic =
false;
2417 VTypeState State = VTypeState::SeenNothingYet;
2419 if (parseVTypeToken(getTok(), State, Sew, Lmul, Fractional, TailAgnostic,
2420 MaskAgnostic, AltFmt)) {
2422 if (State == VTypeState::SeenNothingYet)
2431 State == VTypeState::SeenNothingYet)
2432 return generateVTypeError(S);
2436 unsigned ELEN = STI->
hasFeature(RISCV::FeatureStdExtZve64x) ? 64 : 32;
2437 unsigned MaxSEW = ELEN / Lmul;
2439 if (MaxSEW >= 8 && Sew > MaxSEW)
2440 Warning(S,
"use of vtype encodings with SEW > " + Twine(MaxSEW) +
2441 " and LMUL == mf" + Twine(Lmul) +
2442 " may not be compatible with all RVV implementations");
2447 Operands.push_back(RISCVOperand::createVType(VTypeI, S));
2451bool RISCVAsmParser::generateVTypeError(SMLoc ErrorLoc) {
2452 return Error(ErrorLoc,
2454 "e[8|8alt|16|16alt|32|64],m[1|2|4|8|f2|f4|f8],[ta|tu],[ma|mu]");
2474 if (Identifier !=
"16alt")
2503 Operands.push_back(RISCVOperand::createVType(
2509 return generateXSfmmVTypeError(S);
2512bool RISCVAsmParser::generateXSfmmVTypeError(SMLoc ErrorLoc) {
2513 return Error(ErrorLoc,
"operand must be e[8|16|16alt|32|64],w[1|2|4]");
2520 StringRef
Name = getLexer().getTok().getIdentifier();
2521 if (!
Name.consume_back(
".t")) {
2525 return Error(getLoc(),
"expected '.t' suffix");
2532 if (
Reg != RISCV::V0)
2535 SMLoc
E = getTok().getEndLoc();
2537 Operands.push_back(RISCVOperand::createReg(
Reg, S,
E));
2545 StringRef
Name = getLexer().getTok().getIdentifier();
2546 if (!
Name.consume_back(
".scale"))
2547 return Error(getLoc(),
"expected '.scale' suffix");
2552 if (
Reg != RISCV::V0)
2555 SMLoc
E = getTok().getEndLoc();
2557 Operands.push_back(RISCVOperand::createReg(
Reg, S,
E));
2566 StringRef
Name = getLexer().getTok().getIdentifier();
2567 if (!
Name.consume_front(
"L") && !
Name.consume_front(
"l"))
2572 return Error(S,
"operand must be L1, L2, L4, L8, L16, L32, or L64");
2574 unsigned EncodedLambda =
Log2_32(Lambda) + 1;
2576 SMLoc
E = getTok().getEndLoc();
2578 Operands.push_back(RISCVOperand::createExpr(
2586 "operand must be a valid SpacemiT's Integer Matrix VType mnemonic");
2588 StringRef Str = getLexer().getTok().getIdentifier();
2591 if (!isValidSMTVTypeMode(VType))
2592 return TokError(
"SpacemiT's Integer Matrix only supports [i4|i8] mode");
2594 Operands.push_back(RISCVOperand::createSMTVType(VType, getLoc()));
2602 "operand must be a valid floating point rounding mode mnemonic");
2604 StringRef Str = getLexer().getTok().getIdentifier();
2609 "operand must be a valid floating point rounding mode mnemonic");
2611 Operands.push_back(RISCVOperand::createFRMArg(FRM, getLoc()));
2616std::unique_ptr<RISCVOperand> RISCVAsmParser::defaultSMTVType() {
2617 return RISCVOperand::createSMTVType(XSMTVTypeMode::SMTVTypeMode::SMT_I8,
2622 const AsmToken &Tok = getLexer().getTok();
2628 Operands.push_back(RISCVOperand::createFenceArg(0, getLoc()));
2642 for (
char c : Str) {
2671 Operands.push_back(RISCVOperand::createFenceArg(
Imm, getLoc()));
2677 return TokError(
"operand must be formed of letters selected in-order from "
2684 Operands.push_back(RISCVOperand::createToken(
"(", getLoc()));
2686 if (!parseRegister(
Operands).isSuccess())
2687 return Error(getLoc(),
"expected register");
2691 Operands.push_back(RISCVOperand::createToken(
")", getLoc()));
2715 std::unique_ptr<RISCVOperand> OptionalImmOp;
2722 SMLoc ImmStart = getLoc();
2723 if (getParser().parseIntToken(ImmVal,
2724 "expected '(' or optional integer offset"))
2729 SMLoc ImmEnd = getLoc();
2732 ImmStart, ImmEnd, isRV64());
2736 OptionalImmOp ?
"expected '(' after optional integer offset"
2737 :
"expected '(' or optional integer offset"))
2740 if (!parseRegister(
Operands).isSuccess())
2741 return Error(getLoc(),
"expected register");
2747 if (OptionalImmOp && !OptionalImmOp->isImmZero())
2749 OptionalImmOp->getStartLoc(),
"optional integer offset must be 0",
2750 SMRange(OptionalImmOp->getStartLoc(), OptionalImmOp->getEndLoc()));
2761 StringRef OffsetRegName = getLexer().getTok().getIdentifier();
2764 !getRISCVMCRegisterClass(RISCV::GPRRegClassID).
contains(OffsetReg))
2765 return Error(getLoc(),
"expected GPR register");
2772 return Error(getLoc(),
"expected GPR register");
2774 StringRef BaseRegName = getLexer().getTok().getIdentifier();
2777 !getRISCVMCRegisterClass(RISCV::GPRRegClassID).
contains(BaseReg))
2778 return Error(getLoc(),
"expected GPR register");
2784 Operands.push_back(RISCVOperand::createRegReg(BaseReg, OffsetReg, S));
2797 bool MustIncludeS0) {
2809 return Error(getLoc(),
"invalid register");
2811 StringRef
RegName = getTok().getIdentifier();
2814 return Error(getLoc(),
"invalid register");
2817 UsesXRegs =
RegName[0] ==
'x';
2818 if (
Reg != RISCV::X1)
2819 return Error(getLoc(),
"register list must start from 'ra' or 'x1'");
2820 }
else if (RegEnd == RISCV::X1) {
2821 if (
Reg != RISCV::X8 || (UsesXRegs != (
RegName[0] ==
'x')))
2822 return Error(getLoc(), Twine(
"register must be '") +
2823 (UsesXRegs ?
"x8" :
"s0") +
"'");
2824 }
else if (RegEnd == RISCV::X9 && UsesXRegs) {
2825 if (
Reg != RISCV::X18 || (
RegName[0] !=
'x'))
2826 return Error(getLoc(),
"register must be 'x18'");
2828 return Error(getLoc(),
"too many register ranges");
2835 SMLoc MinusLoc = getLoc();
2837 if (RegEnd == RISCV::X1)
2838 return Error(MinusLoc, Twine(
"register '") + (UsesXRegs ?
"x1" :
"ra") +
2839 "' cannot start a multiple register range");
2842 return Error(getLoc(),
"invalid register");
2844 StringRef
RegName = getTok().getIdentifier();
2847 return Error(getLoc(),
"invalid register");
2849 if (RegEnd == RISCV::X8) {
2850 if ((
Reg != RISCV::X9 &&
2852 (UsesXRegs != (
RegName[0] ==
'x'))) {
2854 return Error(getLoc(),
"register must be 'x9'");
2855 return Error(getLoc(),
"register must be in the range 's1' to 's11'");
2857 }
else if (RegEnd == RISCV::X18) {
2859 return Error(getLoc(),
2860 "register must be in the range 'x19' to 'x27'");
2873 if (RegEnd == RISCV::X26)
2874 return Error(S,
"invalid register list, '{ra, s0-s10}' or '{x1, x8-x9, "
2875 "x18-x26}' is not supported");
2881 return Error(S,
"register list must include 's0' or 'x8'");
2883 Operands.push_back(RISCVOperand::createRegList(Encode, S));
2889 bool ExpectNegative) {
2898 auto *RegListOp =
static_cast<RISCVOperand *
>(
Operands.back().
get());
2899 if (!RegListOp->isRegList())
2902 unsigned RlistEncode = RegListOp->RegList.Encoding;
2906 if (Negative != ExpectNegative || StackAdjustment % 16 != 0 ||
2907 StackAdjustment < StackAdjBase || (StackAdjustment - StackAdjBase) > 48) {
2908 int64_t
Lower = StackAdjBase;
2909 int64_t
Upper = StackAdjBase + 48;
2910 if (ExpectNegative) {
2915 return generateImmOutOfRangeError(S,
Lower,
Upper,
2916 "stack adjustment for register list must "
2917 "be a multiple of 16 bytes in the range");
2921 Operands.push_back(RISCVOperand::createStackAdj(StackAdj, S));
2933 MatchOperandParserImpl(
Operands, Mnemonic,
true);
2940 if (parseRegister(
Operands,
true).isSuccess())
2944 if (parseExpression(
Operands).isSuccess()) {
2947 return !parseMemOpBaseReg(
Operands).isSuccess();
2952 Error(getLoc(),
"unknown operand");
2956bool RISCVAsmParser::parseInstruction(ParseInstructionInfo &Info,
2957 StringRef Name, SMLoc NameLoc,
2963 const FeatureBitset &AvailableFeatures = getAvailableFeatures();
2967 Operands.push_back(RISCVOperand::createToken(Name, NameLoc));
2986 if (getParser().parseEOL(
"unexpected token")) {
2987 getParser().eatToEndOfStatement();
2993bool RISCVAsmParser::classifySymbolRef(
const MCExpr *Expr,
2997 Kind = RE->getSpecifier();
2998 Expr = RE->getSubExpr();
3007bool RISCVAsmParser::isSymbolDiff(
const MCExpr *Expr) {
3016ParseStatus RISCVAsmParser::parseDirective(AsmToken DirectiveID) {
3017 StringRef IDVal = DirectiveID.
getString();
3019 if (IDVal ==
".option")
3020 return parseDirectiveOption();
3021 if (IDVal ==
".attribute")
3022 return parseDirectiveAttribute();
3023 if (IDVal ==
".insn")
3024 return parseDirectiveInsn(DirectiveID.
getLoc());
3025 if (IDVal ==
".variant_cc")
3026 return parseDirectiveVariantCC();
3031bool RISCVAsmParser::resetToArch(StringRef Arch, SMLoc Loc, std::string &Result,
3032 bool FromOptionDirective) {
3038 raw_string_ostream OutputErrMsg(Buffer);
3039 handleAllErrors(ParseResult.takeError(), [&](llvm::StringError &ErrMsg) {
3040 OutputErrMsg <<
"invalid arch name '" << Arch <<
"', "
3041 << ErrMsg.getMessage();
3044 return Error(Loc, OutputErrMsg.str());
3046 auto &ISAInfo = *ParseResult;
3048 if (FromOptionDirective) {
3049 if (ISAInfo->getXLen() == 32 && isRV64())
3050 return Error(Loc,
"bad arch string switching from rv64 to rv32");
3051 else if (ISAInfo->getXLen() == 64 && !isRV64())
3052 return Error(Loc,
"bad arch string switching from rv32 to rv64");
3054 if (ISAInfo->getXLen() != 32 && ISAInfo->getXLen() != 64)
3055 return Error(Loc,
"bad arch string " + Arch);
3061 MCSubtargetInfo &STI = copySTI();
3065 if (ISAInfo->hasExtension(Feature.key()) != STI.
hasFeature(Feature.Value))
3068 if ((ISAInfo->getXLen() == 64) != STI.
hasFeature(RISCV::Feature64Bit))
3070 setAvailableFeatures(ComputeAvailableFeatures(STI.
getFeatureBits()));
3072 Result = ISAInfo->toString();
3076bool RISCVAsmParser::parseDirectiveOption() {
3077 MCAsmParser &Parser = getParser();
3079 AsmToken Tok = Parser.
getTok();
3087 if (Option ==
"push") {
3091 getTargetStreamer().emitDirectiveOptionPush();
3096 if (Option ==
"pop") {
3101 getTargetStreamer().emitDirectiveOptionPop();
3102 if (popFeatureBits())
3103 return Error(StartLoc,
".option pop with no .option push");
3108 if (Option ==
"arch") {
3116 Type = RISCVOptionArchArgType::Plus;
3118 Type = RISCVOptionArchArgType::Minus;
3119 else if (!
Args.empty())
3121 "unexpected token, expected + or -");
3123 Type = RISCVOptionArchArgType::Full;
3127 "unexpected token, expected identifier");
3133 if (
Type == RISCVOptionArchArgType::Full) {
3135 if (resetToArch(Arch, Loc, Result,
true))
3144 Loc,
"extension version number parsing not currently implemented");
3147 if (!enableExperimentalExtension() &&
3149 return Error(Loc,
"unexpected experimental extensions");
3150 const auto &
AllFeatures = getSTI().getAllProcessorFeatures();
3152 if (Ext == std::end(
AllFeatures) || StringRef(Ext->key()) != Feature)
3153 return Error(Loc,
"unknown extension feature");
3155 if (Ext->Value == RISCV::FeatureStdExtY)
3156 return Error(Loc,
"passing '+y'/'-y' is not supported yet; specify a "
3157 "full arch string instead");
3161 if (
Type == RISCVOptionArchArgType::Plus) {
3164 setFeatureBits(Ext->Value, Ext->key());
3167 copySTI().setFeatureBits(OldFeatureBits);
3168 setAvailableFeatures(ComputeAvailableFeatures(OldFeatureBits));
3171 raw_string_ostream OutputErrMsg(Buffer);
3172 handleAllErrors(ParseResult.takeError(), [&](llvm::StringError &ErrMsg) {
3173 OutputErrMsg << ErrMsg.getMessage();
3176 return Error(Loc, OutputErrMsg.str());
3179 assert(
Type == RISCVOptionArchArgType::Minus);
3185 Feature.Implies.test(Ext->Value))
3186 return Error(Loc, Twine(
"can't disable ") + Ext->key() +
3187 " extension; " + Feature.key() +
3188 " extension requires " + Ext->key() +
3192 clearFeatureBits(Ext->Value, Ext->key());
3199 getTargetStreamer().emitDirectiveOptionArch(Args);
3202 getTargetStreamer().setArchString((*ParseResult)->toString());
3206 if (Option ==
"exact") {
3210 getTargetStreamer().emitDirectiveOptionExact();
3211 setFeatureBits(RISCV::FeatureExactAssembly,
"exact-asm");
3212 clearFeatureBits(RISCV::FeatureRelax,
"relax");
3216 if (Option ==
"noexact") {
3220 getTargetStreamer().emitDirectiveOptionNoExact();
3221 clearFeatureBits(RISCV::FeatureExactAssembly,
"exact-asm");
3222 setFeatureBits(RISCV::FeatureRelax,
"relax");
3226 if (Option ==
"rvc") {
3230 getTargetStreamer().emitDirectiveOptionRVC();
3231 setFeatureBits(RISCV::FeatureStdExtC,
"c");
3233 getTargetStreamer().setArchString((*ParseResult)->toString());
3237 if (Option ==
"norvc") {
3241 getTargetStreamer().emitDirectiveOptionNoRVC();
3242 clearFeatureBits(RISCV::FeatureStdExtC,
"c");
3243 clearFeatureBits(RISCV::FeatureStdExtZca,
"zca");
3245 getTargetStreamer().setArchString((*ParseResult)->toString());
3249 if (Option ==
"pic") {
3253 getTargetStreamer().emitDirectiveOptionPIC();
3254 ParserOptions.IsPicEnabled =
true;
3258 if (Option ==
"nopic") {
3262 getTargetStreamer().emitDirectiveOptionNoPIC();
3263 ParserOptions.IsPicEnabled =
false;
3267 if (Option ==
"relax") {
3271 getTargetStreamer().emitDirectiveOptionRelax();
3272 setFeatureBits(RISCV::FeatureRelax,
"relax");
3276 if (Option ==
"norelax") {
3280 getTargetStreamer().emitDirectiveOptionNoRelax();
3281 clearFeatureBits(RISCV::FeatureRelax,
"relax");
3287 "unknown option, expected 'push', 'pop', "
3288 "'rvc', 'norvc', 'arch', 'relax', 'norelax', "
3289 "'exact', or 'noexact'");
3297bool RISCVAsmParser::parseDirectiveAttribute() {
3298 MCAsmParser &Parser = getParser();
3304 std::optional<unsigned> Ret =
3307 return Error(TagLoc,
"attribute name not recognised: " + Name);
3311 const MCExpr *AttrExpr;
3318 if (check(!CE, TagLoc,
"expected numeric constant"))
3321 Tag =
CE->getValue();
3327 StringRef StringValue;
3328 int64_t IntegerValue = 0;
3329 bool IsIntegerValue =
true;
3334 IsIntegerValue =
false;
3337 if (IsIntegerValue) {
3338 const MCExpr *ValueExpr;
3344 return Error(ValueExprLoc,
"expected numeric constant");
3345 IntegerValue =
CE->getValue();
3358 getTargetStreamer().emitAttribute(
Tag, IntegerValue);
3360 getTargetStreamer().emitTextAttribute(
Tag, StringValue);
3363 if (resetToArch(StringValue, ValueExprLoc, Result,
false))
3367 getTargetStreamer().emitTextAttribute(
Tag, Result);
3371 getTargetStreamer().setArchString(Result);
3379 .
Cases({
"r",
"r4",
"i",
"b",
"sb",
"u",
"j",
"uj",
"s"},
true)
3380 .Cases({
"cr",
"ci",
"ciw",
"css",
"cl",
"cs",
"ca",
"cb",
"cj"},
3382 .
Cases({
"qc.eai",
"qc.ei",
"qc.eb",
"qc.ej",
"qc.es"},
3391bool RISCVAsmParser::parseDirectiveInsn(SMLoc L) {
3392 MCAsmParser &Parser = getParser();
3399 std::optional<int64_t>
Length;
3409 return Error(ErrorLoc,
3410 "instruction lengths must be a non-zero multiple of two");
3414 return Error(ErrorLoc,
3415 "instruction lengths over 64 bits are not supported");
3421 int64_t EncodingDerivedLength = ((
Value & 0b11) == 0b11) ? 4 : 2;
3426 if ((*
Length <= 4) && (*
Length != EncodingDerivedLength))
3427 return Error(ErrorLoc,
3428 "instruction length does not match the encoding");
3431 return Error(ErrorLoc,
"encoding value does not fit into instruction");
3434 return Error(ErrorLoc,
"encoding value does not fit into instruction");
3437 if (!getSTI().
hasFeature(RISCV::FeatureStdExtZca) &&
3438 (EncodingDerivedLength == 2))
3439 return Error(ErrorLoc,
"compressed instructions are not allowed");
3441 if (getParser().parseEOL(
"invalid operand for instruction")) {
3442 getParser().eatToEndOfStatement();
3450 Opcode = RISCV::Insn16;
3453 Opcode = RISCV::Insn32;
3456 Opcode = RISCV::Insn48;
3459 Opcode = RISCV::Insn64;
3465 Opcode = (EncodingDerivedLength == 2) ? RISCV::Insn16 : RISCV::Insn32;
3467 emitToStreamer(getStreamer(), MCInstBuilder(Opcode).addImm(
Value));
3472 return Error(ErrorLoc,
"invalid instruction format");
3474 std::string FormatName = (
".insn_" +
Format).str();
3476 ParseInstructionInfo
Info;
3479 if (parseInstruction(Info, FormatName, L,
Operands))
3491bool RISCVAsmParser::parseDirectiveVariantCC() {
3493 if (getParser().parseIdentifier(Name))
3494 return TokError(
"expected symbol name");
3497 getTargetStreamer().emitDirectiveVariantCC(
3502void RISCVAsmParser::validateInstructionPreEmit(
const MCInst &Inst,
3503 const MCSubtargetInfo &STI) {
3512 if (
I <
Desc.getNumOperands() &&
Op.isReg() &&
Op.getReg().isValid()) {
3520 getParser().printError(
3522 " register " +
MRI->getName(
Op.getReg()) +
3523 " is not a member of register class " +
3524 MRI->getRegClassName(&RegClass));
3526 "Incorrect pseudo expansion?");
3532void RISCVAsmParser::emitToStreamer(MCStreamer &S,
const MCInst &Inst) {
3535 const MCSubtargetInfo &STI = getSTI();
3536#ifdef EXPENSIVE_CHECKS
3537 constexpr bool VerifyByDefault =
true;
3539 constexpr bool VerifyByDefault =
false;
3541 bool VerifyMCInst =
valueOr(CLOpts.verify_mcinst, VerifyByDefault);
3543 validateInstructionPreEmit(Inst, STI);
3544 if (!STI.
hasFeature(RISCV::FeatureExactAssembly))
3547 ++RISCVNumInstrsCompressed;
3549 validateInstructionPreEmit(CInst, STI);
3554void RISCVAsmParser::emitLoadImm(MCRegister DestReg, int64_t
Value,
3559 for (MCInst &Inst : Seq) {
3560 emitToStreamer(Out, Inst);
3564void RISCVAsmParser::emitAuipcInstPair(MCRegister DestReg, MCRegister TmpReg,
3565 const MCExpr *Symbol,
3567 unsigned SecondOpcode, SMLoc IDLoc,
3575 Out.emitLabel(TmpLabel);
3579 MCInstBuilder(RISCV::AUIPC).addReg(TmpReg).addExpr(SymbolHi));
3584 emitToStreamer(Out, MCInstBuilder(SecondOpcode)
3587 .addExpr(RefToLinkTmpLabel));
3590void RISCVAsmParser::emitLoadLocalAddress(MCInst &Inst, SMLoc IDLoc,
3601 STI->
hasFeature(RISCV::FeatureVendorXqcili) &&
3602 !ParserOptions.IsPicEnabled)
3604 Out, MCInstBuilder(RISCV::QC_E_LI).addReg(DestReg).addExpr(Symbol));
3610void RISCVAsmParser::emitLoadGlobalAddress(MCInst &Inst, SMLoc IDLoc,
3620 unsigned SecondOpcode = isRV64() ? RISCV::LD : RISCV::LW;
3621 emitAuipcInstPair(DestReg, DestReg, Symbol,
RISCV::S_GOT_HI, SecondOpcode,
3625void RISCVAsmParser::emitLoadAddress(MCInst &Inst, SMLoc IDLoc,
3634 if (ParserOptions.IsPicEnabled)
3635 emitLoadGlobalAddress(Inst, IDLoc, Out);
3637 emitLoadLocalAddress(Inst, IDLoc, Out);
3640void RISCVAsmParser::emitLoadTLSIEAddress(MCInst &Inst, SMLoc IDLoc,
3650 unsigned SecondOpcode = isRV64() ? RISCV::LD : RISCV::LW;
3651 emitAuipcInstPair(DestReg, DestReg, Symbol, ELF::R_RISCV_TLS_GOT_HI20,
3652 SecondOpcode, IDLoc, Out);
3655void RISCVAsmParser::emitLoadTLSGDAddress(MCInst &Inst, SMLoc IDLoc,
3665 emitAuipcInstPair(DestReg, DestReg, Symbol, ELF::R_RISCV_TLS_GD_HI20,
3666 RISCV::ADDI, IDLoc, Out);
3669void RISCVAsmParser::emitLoadStoreSymbol(MCInst &Inst,
unsigned Opcode,
3670 SMLoc IDLoc, MCStreamer &Out,
3679 unsigned DestRegOpIdx = HasTmpReg ? 1 : 0;
3681 unsigned SymbolOpIdx = HasTmpReg ? 2 : 1;
3685 if (getRISCVMCRegisterClass(RISCV::GPRPairRegClassID).
contains(TmpReg)) {
3686 const MCRegisterInfo *RI =
getContext().getRegisterInfo();
3687 TmpReg = RI->
getSubReg(TmpReg, RISCV::sub_gpr_even);
3695void RISCVAsmParser::emitQCELILoadStoreSymbol(MCInst &Inst,
unsigned Opcode,
3696 SMLoc IDLoc, MCStreamer &Out,
3706 unsigned SymbolOpIdx = HasTmpReg ? 2 : 1;
3710 MCInstBuilder(RISCV::QC_E_LI).addReg(AddrReg).addExpr(Symbol));
3713 const MCExpr *AccessExpr =
3719 struct CompressedForm {
3723 std::optional<CompressedForm> Compressed;
3727 case RISCV::PseudoQCAccessLBU:
3728 Compressed = {RISCV::PseudoQCAccessC_LBU, RISCV::FeatureStdExtZcb};
3730 case RISCV::PseudoQCAccessLH:
3731 Compressed = {RISCV::PseudoQCAccessC_LH, RISCV::FeatureStdExtZcb};
3733 case RISCV::PseudoQCAccessLHU:
3734 Compressed = {RISCV::PseudoQCAccessC_LHU, RISCV::FeatureStdExtZcb};
3736 case RISCV::PseudoQCAccessLW:
3737 Compressed = {RISCV::PseudoQCAccessC_LW, RISCV::FeatureStdExtZca};
3739 case RISCV::PseudoQCAccessSB:
3740 Compressed = {RISCV::PseudoQCAccessC_SB, RISCV::FeatureStdExtZcb};
3742 case RISCV::PseudoQCAccessSH:
3743 Compressed = {RISCV::PseudoQCAccessC_SH, RISCV::FeatureStdExtZcb};
3745 case RISCV::PseudoQCAccessSW:
3746 Compressed = {RISCV::PseudoQCAccessC_SW, RISCV::FeatureStdExtZca};
3753 getRISCVMCRegisterClass(RISCV::GPRCRegClassID).contains(AddrReg);
3754 if (HasTmpReg && CanUseGPRC) {
3757 getRISCVMCRegisterClass(RISCV::GPRCRegClassID).contains(DataReg);
3760 bool UseCompressed =
3761 Compressed && getSTI().hasFeature(Compressed->Feature) && CanUseGPRC;
3763 unsigned ActualOpcode = UseCompressed ? Compressed->Opcode : Opcode;
3766 emitToStreamer(Out, MCInstBuilder(ActualOpcode)
3770 .addExpr(AccessExpr));
3772 emitToStreamer(Out, MCInstBuilder(ActualOpcode)
3776 .addExpr(AccessExpr));
3780void RISCVAsmParser::emitPseudoExtend(MCInst &Inst,
bool SignExtend,
3781 int64_t Width, SMLoc IDLoc,
3790 const MCOperand &DestReg = Inst.
getOperand(0);
3791 const MCOperand &SourceReg = Inst.
getOperand(1);
3793 unsigned SecondOpcode = SignExtend ? RISCV::SRAI : RISCV::SRLI;
3794 int64_t ShAmt = (isRV64() ? 64 : 32) - Width;
3796 assert(ShAmt > 0 &&
"Shift amount must be non-zero.");
3798 emitToStreamer(Out, MCInstBuilder(RISCV::SLLI)
3803 emitToStreamer(Out, MCInstBuilder(SecondOpcode)
3809void RISCVAsmParser::emitVMSGE(MCInst &Inst,
unsigned Opcode, SMLoc IDLoc,
3816 emitToStreamer(Out, MCInstBuilder(Opcode)
3820 .addReg(MCRegister())
3822 emitToStreamer(Out, MCInstBuilder(RISCV::VMNAND_MM)
3833 "The destination register should not be V0.");
3835 emitToStreamer(Out, MCInstBuilder(Opcode)
3841 emitToStreamer(Out, MCInstBuilder(RISCV::VMXOR_MM)
3853 "The temporary vector register should not be V0.");
3854 emitToStreamer(Out, MCInstBuilder(Opcode)
3858 .addReg(MCRegister())
3860 emitToStreamer(Out, MCInstBuilder(RISCV::VMANDN_MM)
3872 "The temporary vector register should not be V0.");
3873 emitToStreamer(Out, MCInstBuilder(Opcode)
3877 .addReg(MCRegister())
3879 emitToStreamer(Out, MCInstBuilder(RISCV::VMANDN_MM)
3884 emitToStreamer(Out, MCInstBuilder(RISCV::VMANDN_MM)
3889 emitToStreamer(Out, MCInstBuilder(RISCV::VMOR_MM)
3897bool RISCVAsmParser::checkPseudoAddTPRel(MCInst &Inst,
3899 assert(Inst.
getOpcode() == RISCV::PseudoAddTPRel &&
"Invalid instruction");
3902 SMLoc ErrorLoc = ((RISCVOperand &)*
Operands[3]).getStartLoc();
3903 return Error(ErrorLoc,
"the second input operand must be tp/x4 when using "
3904 "%tprel_add specifier");
3910bool RISCVAsmParser::checkPseudoTLSDESCCall(MCInst &Inst,
3912 assert(Inst.
getOpcode() == RISCV::PseudoTLSDESCCall &&
"Invalid instruction");
3915 SMLoc ErrorLoc = ((RISCVOperand &)*
Operands[3]).getStartLoc();
3916 return Error(ErrorLoc,
"the output operand must be t0/x5 when using "
3917 "%tlsdesc_call specifier");
3923std::unique_ptr<RISCVOperand> RISCVAsmParser::defaultMaskRegOp()
const {
3924 return RISCVOperand::createReg(MCRegister(), llvm::SMLoc(), llvm::SMLoc());
3927std::unique_ptr<RISCVOperand> RISCVAsmParser::defaultFRMArgOp()
const {
3928 return RISCVOperand::createFRMArg(RISCVFPRndMode::RoundingMode::DYN,
3932std::unique_ptr<RISCVOperand> RISCVAsmParser::defaultFRMArgLegacyOp()
const {
3933 return RISCVOperand::createFRMArg(RISCVFPRndMode::RoundingMode::RNE,
3937std::unique_ptr<RISCVOperand> RISCVAsmParser::defaultZeroOffset() {
3939 llvm::SMLoc(), llvm::SMLoc(), isRV64());
3946 case RISCV::VLOXSEG2EI8_V:
3947 case RISCV::VLOXSEG2EI16_V:
3948 case RISCV::VLOXSEG2EI32_V:
3949 case RISCV::VLOXSEG2EI64_V:
3950 case RISCV::VLUXSEG2EI8_V:
3951 case RISCV::VLUXSEG2EI16_V:
3952 case RISCV::VLUXSEG2EI32_V:
3953 case RISCV::VLUXSEG2EI64_V:
3955 case RISCV::VLOXSEG3EI8_V:
3956 case RISCV::VLOXSEG3EI16_V:
3957 case RISCV::VLOXSEG3EI32_V:
3958 case RISCV::VLOXSEG3EI64_V:
3959 case RISCV::VLUXSEG3EI8_V:
3960 case RISCV::VLUXSEG3EI16_V:
3961 case RISCV::VLUXSEG3EI32_V:
3962 case RISCV::VLUXSEG3EI64_V:
3964 case RISCV::VLOXSEG4EI8_V:
3965 case RISCV::VLOXSEG4EI16_V:
3966 case RISCV::VLOXSEG4EI32_V:
3967 case RISCV::VLOXSEG4EI64_V:
3968 case RISCV::VLUXSEG4EI8_V:
3969 case RISCV::VLUXSEG4EI16_V:
3970 case RISCV::VLUXSEG4EI32_V:
3971 case RISCV::VLUXSEG4EI64_V:
3973 case RISCV::VLOXSEG5EI8_V:
3974 case RISCV::VLOXSEG5EI16_V:
3975 case RISCV::VLOXSEG5EI32_V:
3976 case RISCV::VLOXSEG5EI64_V:
3977 case RISCV::VLUXSEG5EI8_V:
3978 case RISCV::VLUXSEG5EI16_V:
3979 case RISCV::VLUXSEG5EI32_V:
3980 case RISCV::VLUXSEG5EI64_V:
3982 case RISCV::VLOXSEG6EI8_V:
3983 case RISCV::VLOXSEG6EI16_V:
3984 case RISCV::VLOXSEG6EI32_V:
3985 case RISCV::VLOXSEG6EI64_V:
3986 case RISCV::VLUXSEG6EI8_V:
3987 case RISCV::VLUXSEG6EI16_V:
3988 case RISCV::VLUXSEG6EI32_V:
3989 case RISCV::VLUXSEG6EI64_V:
3991 case RISCV::VLOXSEG7EI8_V:
3992 case RISCV::VLOXSEG7EI16_V:
3993 case RISCV::VLOXSEG7EI32_V:
3994 case RISCV::VLOXSEG7EI64_V:
3995 case RISCV::VLUXSEG7EI8_V:
3996 case RISCV::VLUXSEG7EI16_V:
3997 case RISCV::VLUXSEG7EI32_V:
3998 case RISCV::VLUXSEG7EI64_V:
4000 case RISCV::VLOXSEG8EI8_V:
4001 case RISCV::VLOXSEG8EI16_V:
4002 case RISCV::VLOXSEG8EI32_V:
4003 case RISCV::VLOXSEG8EI64_V:
4004 case RISCV::VLUXSEG8EI8_V:
4005 case RISCV::VLUXSEG8EI16_V:
4006 case RISCV::VLUXSEG8EI32_V:
4007 case RISCV::VLUXSEG8EI64_V:
4013 if (getRISCVMCRegisterClass(RISCV::VRM2RegClassID).
contains(
Reg))
4015 if (getRISCVMCRegisterClass(RISCV::VRM4RegClassID).
contains(
Reg))
4017 if (getRISCVMCRegisterClass(RISCV::VRM8RegClassID).
contains(
Reg))
4024 case RISCV::VFWMMACC_VV_SCALE:
4025 case RISCV::VFQMMACC_VV_SCALE:
4026 case RISCV::VF8WMMACC_VV_SCALE:
4027 case RISCV::VFWIMMACC_VV:
4028 case RISCV::VFQIMMACC_VV:
4029 case RISCV::VF8WIMMACC_VV:
4036bool RISCVAsmParser::validateInstruction(MCInst &Inst,
4040 if (Opcode == RISCV::PseudoVMSGEU_VX_M_T ||
4041 Opcode == RISCV::PseudoVMSGE_VX_M_T) {
4044 if (DestReg == TempReg) {
4045 SMLoc Loc =
Operands.back()->getStartLoc();
4046 return Error(Loc,
"the temporary vector register cannot be the same as "
4047 "the destination register");
4051 if (Opcode == RISCV::PseudoVMSGEU_VX_M || Opcode == RISCV::PseudoVMSGE_VX_M) {
4054 if (MaskReg == RISCV::V0 && DestReg == RISCV::V0) {
4055 SMLoc Loc =
Operands.back()->getStartLoc();
4056 return Error(Loc,
"the destination vector register cannot overlap the "
4057 "mask register unless a temporary register is "
4062 if (Opcode == RISCV::CV_INSERT &&
4065 "the sum of the immediate operands must be less than 32");
4070 case RISCV::TH_LBIA:
4071 case RISCV::TH_LBIB:
4072 case RISCV::TH_LBUIA:
4073 case RISCV::TH_LBUIB:
4074 case RISCV::TH_LHIA:
4075 case RISCV::TH_LHIB:
4076 case RISCV::TH_LHUIA:
4077 case RISCV::TH_LHUIB:
4078 case RISCV::TH_LWIA:
4079 case RISCV::TH_LWIB:
4080 case RISCV::TH_LWUIA:
4081 case RISCV::TH_LWUIB:
4082 case RISCV::TH_LDIA:
4083 case RISCV::TH_LDIB:
4085 return Error(
Operands[1]->getStartLoc(),
"rd and rs1 must be different");
4088 case RISCV::TH_LWUD:
4089 case RISCV::TH_LWD: {
4095 if (Rs1 == Rd1 || Rs1 == Rd2 || Rd1 == Rd2) {
4096 SMLoc Loc =
Operands[1]->getStartLoc();
4097 return Error(Loc,
"rs1, rd1, and rd2 cannot overlap");
4103 if (Opcode == RISCV::CM_MVSA01 || Opcode == RISCV::QC_CM_MVSA01) {
4107 SMLoc Loc =
Operands[1]->getStartLoc();
4108 return Error(Loc,
"rs1 and rs2 must be different");
4113 auto CheckOperandDoesNotOverlapV0 = [&](
int OperandIdx,
4114 unsigned ParsedIdx) {
4117 "vd, vs1, and vs2 cannot overlap v0.scale");
4122 RISCV::getNamedOperandIdx(Inst.
getOpcode(), RISCV::OpName::vd);
4124 RISCV::getNamedOperandIdx(Inst.
getOpcode(), RISCV::OpName::vs1);
4126 RISCV::getNamedOperandIdx(Inst.
getOpcode(), RISCV::OpName::vs2);
4127 assert(DestIdx >= 0 && VS1Idx >= 0 && VS2Idx >= 0 &&
4128 "Unexpected Zvvfmm scaled operand list");
4130 if (CheckOperandDoesNotOverlapV0(DestIdx, 1) ||
4131 CheckOperandDoesNotOverlapV0(VS1Idx, 2) ||
4132 CheckOperandDoesNotOverlapV0(VS2Idx, 3))
4136 const MCInstrDesc &MCID = MII.
get(Opcode);
4140 int DestIdx = RISCV::getNamedOperandIdx(Inst.
getOpcode(), RISCV::OpName::vd);
4144 const MCParsedAsmOperand *ParsedOp =
Operands[1].get();
4145 if (!ParsedOp->
isReg()) {
4150 const MCRegisterInfo *RI =
getContext().getRegisterInfo();
4153 "Can't find parsed dest operand");
4159 RISCV::getNamedOperandIdx(Inst.
getOpcode(), RISCV::OpName::vs2);
4160 assert(VS2Idx >= 0 &&
"No vs2 operand?");
4161 unsigned CheckEncoding =
4164 for (
unsigned i = 0; i < std::max(NF, Lmul); i++) {
4165 if ((DestEncoding + i) == CheckEncoding)
4166 return Error(Loc,
"the destination vector register group cannot overlap"
4167 " the source vector register group");
4172 RISCV::getNamedOperandIdx(Inst.
getOpcode(), RISCV::OpName::vs1);
4176 unsigned CheckEncoding =
4178 for (
unsigned i = 0; i < Lmul; i++) {
4179 if ((DestEncoding + i) == CheckEncoding)
4181 "the destination vector register group cannot overlap"
4182 " the source vector register group");
4188 int VMIdx = RISCV::getNamedOperandIdx(Inst.
getOpcode(), RISCV::OpName::vm);
4189 assert(VMIdx >= 0 &&
"No vm operand?");
4191 if (DestReg == RISCV::V0) {
4194 return Error(Loc,
"the destination vector register group cannot be V0");
4202 "Unexpected mask operand register");
4204 return Error(Loc,
"the destination vector register group cannot overlap"
4205 " the mask register");
4213 RISCV::getNamedOperandIdx(Inst.
getOpcode(), RISCV::OpName::vmask);
4215 if (MaskReg != RISCV::V0 && MaskReg != RISCV::V1)
4217 "vmask operand only supports v0 or v1");
4220 RISCV::OpName RegOps[] = {RISCV::OpName::vd, RISCV::OpName::vs1,
4221 RISCV::OpName::vs2};
4222 for (RISCV::OpName OpN : RegOps) {
4223 int Idx = RISCV::getNamedOperandIdx(Inst.
getOpcode(), OpN);
4229 for (
unsigned i = 0; i < RegLmul; i++) {
4230 if ((RegEnc + i) == MaskEnc) {
4233 Twine(
"register conflicts with vmask register ") +
4243bool RISCVAsmParser::processInstruction(MCInst &Inst, SMLoc IDLoc,
4251 case RISCV::MOP_RR_7: {
4263 case RISCV::MOP_R_28: {
4281 case RISCV::PseudoC_ADDI_NOP: {
4283 emitToStreamer(Out, MCInstBuilder(RISCV::C_NOP));
4293 if (getSTI().
hasFeature(RISCV::Feature64Bit))
4295 emitToStreamer(Out, MCInstBuilder(RISCV::ZEXT_H_RV32)
4300 case RISCV::PACKW: {
4304 emitToStreamer(Out, MCInstBuilder(RISCV::ZEXT_H_RV64)
4309 case RISCV::PseudoLLAImm:
4310 case RISCV::PseudoLAImm:
4311 case RISCV::PseudoLI: {
4317 emitToStreamer(Out, MCInstBuilder(RISCV::ADDI)
4329 emitLoadImm(
Reg,
Imm, Out);
4332 case RISCV::PseudoLLA:
4333 emitLoadLocalAddress(Inst, IDLoc, Out);
4335 case RISCV::PseudoLGA:
4336 emitLoadGlobalAddress(Inst, IDLoc, Out);
4338 case RISCV::PseudoLA:
4339 emitLoadAddress(Inst, IDLoc, Out);
4341 case RISCV::PseudoLA_TLS_IE:
4342 emitLoadTLSIEAddress(Inst, IDLoc, Out);
4344 case RISCV::PseudoLA_TLS_GD:
4345 emitLoadTLSGDAddress(Inst, IDLoc, Out);
4347 case RISCV::PseudoLB:
4348 emitLoadStoreSymbol(Inst, RISCV::LB, IDLoc, Out,
false);
4350 case RISCV::PseudoLBU:
4351 emitLoadStoreSymbol(Inst, RISCV::LBU, IDLoc, Out,
false);
4353 case RISCV::PseudoLH:
4354 emitLoadStoreSymbol(Inst, RISCV::LH, IDLoc, Out,
false);
4356 case RISCV::PseudoLHU:
4357 emitLoadStoreSymbol(Inst, RISCV::LHU, IDLoc, Out,
false);
4359 case RISCV::PseudoLW:
4360 emitLoadStoreSymbol(Inst, RISCV::LW, IDLoc, Out,
false);
4362 case RISCV::PseudoLWU:
4363 emitLoadStoreSymbol(Inst, RISCV::LWU, IDLoc, Out,
false);
4365 case RISCV::PseudoLD:
4366 emitLoadStoreSymbol(Inst, RISCV::LD, IDLoc, Out,
false);
4368 case RISCV::PseudoLD_RV32:
4369 emitLoadStoreSymbol(Inst, RISCV::LD_RV32, IDLoc, Out,
false);
4371 case RISCV::PseudoFLH:
4372 emitLoadStoreSymbol(Inst, RISCV::FLH, IDLoc, Out,
true);
4374 case RISCV::PseudoFLW:
4375 emitLoadStoreSymbol(Inst, RISCV::FLW, IDLoc, Out,
true);
4377 case RISCV::PseudoFLD:
4378 emitLoadStoreSymbol(Inst, RISCV::FLD, IDLoc, Out,
true);
4380 case RISCV::PseudoFLQ:
4381 emitLoadStoreSymbol(Inst, RISCV::FLQ, IDLoc, Out,
true);
4383 case RISCV::PseudoSB:
4384 emitLoadStoreSymbol(Inst, RISCV::SB, IDLoc, Out,
true);
4386 case RISCV::PseudoSH:
4387 emitLoadStoreSymbol(Inst, RISCV::SH, IDLoc, Out,
true);
4389 case RISCV::PseudoSW:
4390 emitLoadStoreSymbol(Inst, RISCV::SW, IDLoc, Out,
true);
4392 case RISCV::PseudoSD:
4393 emitLoadStoreSymbol(Inst, RISCV::SD, IDLoc, Out,
true);
4395 case RISCV::PseudoSD_RV32:
4396 emitLoadStoreSymbol(Inst, RISCV::SD_RV32, IDLoc, Out,
true);
4398 case RISCV::PseudoQC_E_LB:
4399 emitQCELILoadStoreSymbol(Inst, RISCV::PseudoQCAccessLB, IDLoc, Out,
4402 case RISCV::PseudoQC_E_LBU:
4403 emitQCELILoadStoreSymbol(Inst, RISCV::PseudoQCAccessLBU, IDLoc, Out,
4406 case RISCV::PseudoQC_E_LH:
4407 emitQCELILoadStoreSymbol(Inst, RISCV::PseudoQCAccessLH, IDLoc, Out,
4410 case RISCV::PseudoQC_E_LHU:
4411 emitQCELILoadStoreSymbol(Inst, RISCV::PseudoQCAccessLHU, IDLoc, Out,
4414 case RISCV::PseudoQC_E_LW:
4415 emitQCELILoadStoreSymbol(Inst, RISCV::PseudoQCAccessLW, IDLoc, Out,
4418 case RISCV::PseudoQC_E_SB:
4419 emitQCELILoadStoreSymbol(Inst, RISCV::PseudoQCAccessSB, IDLoc, Out,
4422 case RISCV::PseudoQC_E_SH:
4423 emitQCELILoadStoreSymbol(Inst, RISCV::PseudoQCAccessSH, IDLoc, Out,
4426 case RISCV::PseudoQC_E_SW:
4427 emitQCELILoadStoreSymbol(Inst, RISCV::PseudoQCAccessSW, IDLoc, Out,
4430 case RISCV::PseudoFSH:
4431 emitLoadStoreSymbol(Inst, RISCV::FSH, IDLoc, Out,
true);
4433 case RISCV::PseudoFSW:
4434 emitLoadStoreSymbol(Inst, RISCV::FSW, IDLoc, Out,
true);
4436 case RISCV::PseudoFSD:
4437 emitLoadStoreSymbol(Inst, RISCV::FSD, IDLoc, Out,
true);
4439 case RISCV::PseudoFSQ:
4440 emitLoadStoreSymbol(Inst, RISCV::FSQ, IDLoc, Out,
true);
4442 case RISCV::PseudoAddTPRel:
4443 if (checkPseudoAddTPRel(Inst,
Operands))
4446 case RISCV::PseudoTLSDESCCall:
4447 if (checkPseudoTLSDESCCall(Inst,
Operands))
4450 case RISCV::PseudoSEXT_B:
4451 emitPseudoExtend(Inst,
true, 8, IDLoc, Out);
4453 case RISCV::PseudoSEXT_H:
4454 emitPseudoExtend(Inst,
true, 16, IDLoc, Out);
4456 case RISCV::PseudoZEXT_H:
4457 emitPseudoExtend(Inst,
false, 16, IDLoc, Out);
4459 case RISCV::PseudoZEXT_W:
4460 emitPseudoExtend(Inst,
false, 32, IDLoc, Out);
4462 case RISCV::PseudoVMSGEU_VX_M:
4463 case RISCV::PseudoVMSGEU_VX_M_T:
4464 emitVMSGE(Inst, RISCV::VMSLTU_VX, IDLoc, Out);
4466 case RISCV::PseudoVMSGE_VX_M:
4467 case RISCV::PseudoVMSGE_VX_M_T:
4468 emitVMSGE(Inst, RISCV::VMSLT_VX, IDLoc, Out);
4470 case RISCV::PseudoVMSGE_VI:
4471 case RISCV::PseudoVMSLT_VI: {
4475 unsigned Opc = Inst.
getOpcode() == RISCV::PseudoVMSGE_VI ? RISCV::VMSGT_VI
4477 emitToStreamer(Out, MCInstBuilder(
Opc)
4485 case RISCV::PseudoVMSGEU_VI:
4486 case RISCV::PseudoVMSLTU_VI: {
4493 unsigned Opc = Inst.
getOpcode() == RISCV::PseudoVMSGEU_VI
4496 emitToStreamer(Out, MCInstBuilder(
Opc)
4504 unsigned Opc = Inst.
getOpcode() == RISCV::PseudoVMSGEU_VI
4507 emitToStreamer(Out, MCInstBuilder(
Opc)
4517 case RISCV::PseudoCV_ELW:
4518 emitLoadStoreSymbol(Inst, RISCV::CV_ELW, IDLoc, Out,
false);
4522 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 bool isGPR(MCRegister Reg, const MCRegisterInfo &MRI)
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)
MachineRegisterInfo & MRI
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
ArrayRef< MCOperand > getOperands() 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.
int16_t getOpRegClassID(const MCOperandInfo &OpInfo, unsigned HwModeId) const
Return the ID of the register class to use for OpInfo, for the active HwMode HwModeId.
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
bool contains(MCRegister Reg) const
contains - Return true if the specified register is included in this register class.
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 and target specific virtual registers.
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.
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...
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
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
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
constexpr bool isValid() 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 ...
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
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()
LLVM_ABI void reportFatalInternalError(Error Err)
Report a fatal error that indicates a bug in LLVM.
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 valueOr(BoolOrDefault X, bool Default)
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,...