39 #define GEN_COMPRESS_INSTR 40 #include "RISCVGenCompressInstEmitter.inc" 48 SMLoc getLoc()
const {
return getParser().getTok().getLoc(); }
49 bool isRV64()
const {
return getSTI().hasFeature(RISCV::Feature64Bit); }
57 unsigned Kind)
override;
62 bool MatchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
65 bool MatchingInlineAsm)
override;
67 bool ParseRegister(
unsigned &RegNo,
SMLoc &StartLoc,
SMLoc &EndLoc)
override;
72 bool ParseDirective(
AsmToken DirectiveID)
override;
92 #define GET_ASSEMBLER_HEADER 93 #include "RISCVGenAsmMatcher.inc" 98 bool AllowParens =
false);
106 bool parseDirectiveOption();
108 void setFeatureBits(uint64_t Feature,
StringRef FeatureString) {
109 if (!(getSTI().getFeatureBits()[Feature])) {
111 setAvailableFeatures(
116 void clearFeatureBits(uint64_t Feature,
StringRef FeatureString) {
117 if (getSTI().getFeatureBits()[Feature]) {
119 setAvailableFeatures(
124 void pushFeatureBits() {
125 FeatureBitStack.
push_back(getSTI().getFeatureBits());
128 bool popFeatureBits() {
129 if (FeatureBitStack.
empty())
133 copySTI().setFeatureBits(FeatureBits);
134 setAvailableFeatures(ComputeAvailableFeatures(FeatureBits));
139 enum RISCVMatchResultTy {
140 Match_Dummy = FIRST_TARGET_MATCH_RESULT_TY,
141 #define GET_OPERAND_DIAGNOSTIC_TYPES 142 #include "RISCVGenAsmMatcher.inc" 143 #undef GET_OPERAND_DIAGNOSTIC_TYPES 146 static bool classifySymbolRef(
const MCExpr *Expr,
157 setAvailableFeatures(ComputeAvailableFeatures(STI.
getFeatureBits()));
190 SMLoc StartLoc, EndLoc;
195 struct SysRegOp SysReg;
204 StartLoc = o.StartLoc;
222 bool isToken()
const override {
return Kind == Token; }
224 bool isImm()
const override {
return Kind == Immediate; }
225 bool isMem()
const override {
return false; }
226 bool isSystemRegister()
const {
return Kind == SystemRegister; }
228 static bool evaluateConstantImm(
const MCExpr *Expr, int64_t &Imm,
230 if (
auto *RE = dyn_cast<RISCVMCExpr>(Expr)) {
232 return RE->evaluateAsConstant(Imm);
235 if (
auto CE = dyn_cast<MCConstantExpr>(Expr)) {
237 Imm = CE->getValue();
246 template <
int N>
bool isBareSimmNLsb0()
const {
251 bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
254 IsValid = RISCVAsmParser::classifySymbolRef(getImm(), VK, Imm);
262 bool isBareSymbol()
const {
266 if (!isImm() || evaluateConstantImm(getImm(), Imm, VK))
268 return RISCVAsmParser::classifySymbolRef(getImm(), VK, Imm) &&
272 bool isCSRSystemRegister()
const {
return isSystemRegister(); }
276 bool isFenceArg()
const {
279 const MCExpr *Val = getImm();
284 StringRef Str = SVal->getSymbol().getName();
290 if (c !=
'i' && c !=
'o' && c !=
'r' && c !=
'w')
300 bool isFRMArg()
const {
303 const MCExpr *Val = getImm();
308 StringRef Str = SVal->getSymbol().getName();
313 bool isImmXLenLI()
const {
318 bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
327 bool isUImmLog2XLen()
const {
332 if (!evaluateConstantImm(getImm(), Imm, VK) ||
335 return (isRV64() && isUInt<6>(Imm)) || isUInt<5>(Imm);
338 bool isUImmLog2XLenNonZero()
const {
343 if (!evaluateConstantImm(getImm(), Imm, VK) ||
348 return (isRV64() && isUInt<6>(Imm)) || isUInt<5>(Imm);
351 bool isUImm5()
const {
356 bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
360 bool isUImm5NonZero()
const {
365 bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
366 return IsConstantImm && isUInt<5>(Imm) && (Imm != 0) &&
370 bool isSImm6()
const {
375 bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
376 return IsConstantImm && isInt<6>(Imm) &&
380 bool isSImm6NonZero()
const {
385 bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
386 return IsConstantImm && isInt<6>(Imm) && (Imm != 0) &&
390 bool isCLUIImm()
const {
395 bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
396 return IsConstantImm && (Imm != 0) &&
397 (isUInt<5>(Imm) || (Imm >= 0xfffe0 && Imm <= 0xfffff)) &&
401 bool isUImm7Lsb00()
const {
406 bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
407 return IsConstantImm && isShiftedUInt<5, 2>(Imm) &&
411 bool isUImm8Lsb00()
const {
416 bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
417 return IsConstantImm && isShiftedUInt<6, 2>(Imm) &&
421 bool isUImm8Lsb000()
const {
426 bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
427 return IsConstantImm && isShiftedUInt<5, 3>(Imm) &&
431 bool isSImm9Lsb0()
const {
return isBareSimmNLsb0<9>(); }
433 bool isUImm9Lsb000()
const {
438 bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
439 return IsConstantImm && isShiftedUInt<6, 3>(Imm) &&
443 bool isUImm10Lsb00NonZero()
const {
448 bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
449 return IsConstantImm && isShiftedUInt<8, 2>(Imm) && (Imm != 0) &&
453 bool isSImm12()
const {
459 bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
461 IsValid = RISCVAsmParser::classifySymbolRef(getImm(), VK, Imm);
463 IsValid = isInt<12>(Imm);
469 bool isSImm12Lsb0()
const {
return isBareSimmNLsb0<12>(); }
471 bool isSImm13Lsb0()
const {
return isBareSimmNLsb0<13>(); }
473 bool isSImm10Lsb0000NonZero()
const {
478 bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
479 return IsConstantImm && (Imm != 0) && isShiftedInt<6, 4>(Imm) &&
483 bool isUImm20LUI()
const {
489 bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
490 if (!IsConstantImm) {
491 IsValid = RISCVAsmParser::classifySymbolRef(getImm(), VK, Imm);
499 bool isUImm20AUIPC()
const {
505 bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
506 if (!IsConstantImm) {
507 IsValid = RISCVAsmParser::classifySymbolRef(getImm(), VK, Imm);
515 bool isSImm21Lsb0JAL()
const {
return isBareSimmNLsb0<21>(); }
518 SMLoc getStartLoc()
const override {
return StartLoc; }
520 SMLoc getEndLoc()
const override {
return EndLoc; }
522 bool isRV64()
const {
return IsRV64; }
524 unsigned getReg()
const override {
530 assert(Kind == SystemRegister &&
"Invalid access!");
531 return StringRef(SysReg.Data, SysReg.Length);
534 const MCExpr *getImm()
const {
535 assert(Kind == Immediate &&
"Invalid type access!");
540 assert(Kind == Token &&
"Invalid type access!");
557 OS <<
"<sysreg: " << getSysReg() <<
'>';
562 static std::unique_ptr<RISCVOperand> createToken(
StringRef Str,
SMLoc S,
564 auto Op = make_unique<RISCVOperand>(Token);
572 static std::unique_ptr<RISCVOperand> createReg(
unsigned RegNo,
SMLoc S,
574 auto Op = make_unique<RISCVOperand>(
Register);
575 Op->Reg.RegNum = RegNo;
582 static std::unique_ptr<RISCVOperand> createImm(
const MCExpr *Val,
SMLoc S,
584 auto Op = make_unique<RISCVOperand>(Immediate);
592 static std::unique_ptr<RISCVOperand>
593 createSysReg(
StringRef Str,
SMLoc S,
unsigned Encoding,
bool IsRV64) {
594 auto Op = make_unique<RISCVOperand>(SystemRegister);
595 Op->SysReg.Data = Str.
data();
596 Op->SysReg.Length = Str.
size();
597 Op->SysReg.Encoding = Encoding;
604 assert(Expr &&
"Expr shouldn't be null!");
607 bool IsConstant = evaluateConstantImm(Expr, Imm, VK);
616 void addRegOperands(
MCInst &Inst,
unsigned N)
const {
617 assert(N == 1 &&
"Invalid number of operands!");
621 void addImmOperands(
MCInst &Inst,
unsigned N)
const {
622 assert(N == 1 &&
"Invalid number of operands!");
623 addExpr(Inst, getImm());
626 void addFenceArgOperands(
MCInst &Inst,
unsigned N)
const {
627 assert(N == 1 &&
"Invalid number of operands!");
629 auto SE = cast<MCSymbolRefExpr>(getImm());
632 for (
char c : SE->getSymbol().getName()) {
645 void addCSRSystemRegisterOperands(
MCInst &Inst,
unsigned N)
const {
646 assert(N == 1 &&
"Invalid number of operands!");
654 auto SE = cast<MCSymbolRefExpr>(getImm());
661 void addFRMArgOperands(
MCInst &Inst,
unsigned N)
const {
662 assert(N == 1 &&
"Invalid number of operands!");
668 #define GET_REGISTER_MATCHER 669 #define GET_MATCHER_IMPLEMENTATION 670 #include "RISCVGenAsmMatcher.inc" 679 case RISCV::F0_32:
return RISCV::F0_64;
680 case RISCV::F1_32:
return RISCV::F1_64;
681 case RISCV::F2_32:
return RISCV::F2_64;
682 case RISCV::F3_32:
return RISCV::F3_64;
683 case RISCV::F4_32:
return RISCV::F4_64;
684 case RISCV::F5_32:
return RISCV::F5_64;
685 case RISCV::F6_32:
return RISCV::F6_64;
686 case RISCV::F7_32:
return RISCV::F7_64;
687 case RISCV::F8_32:
return RISCV::F8_64;
688 case RISCV::F9_32:
return RISCV::F9_64;
689 case RISCV::F10_32:
return RISCV::F10_64;
690 case RISCV::F11_32:
return RISCV::F11_64;
691 case RISCV::F12_32:
return RISCV::F12_64;
692 case RISCV::F13_32:
return RISCV::F13_64;
693 case RISCV::F14_32:
return RISCV::F14_64;
694 case RISCV::F15_32:
return RISCV::F15_64;
695 case RISCV::F16_32:
return RISCV::F16_64;
696 case RISCV::F17_32:
return RISCV::F17_64;
697 case RISCV::F18_32:
return RISCV::F18_64;
698 case RISCV::F19_32:
return RISCV::F19_64;
699 case RISCV::F20_32:
return RISCV::F20_64;
700 case RISCV::F21_32:
return RISCV::F21_64;
701 case RISCV::F22_32:
return RISCV::F22_64;
702 case RISCV::F23_32:
return RISCV::F23_64;
703 case RISCV::F24_32:
return RISCV::F24_64;
704 case RISCV::F25_32:
return RISCV::F25_64;
705 case RISCV::F26_32:
return RISCV::F26_64;
706 case RISCV::F27_32:
return RISCV::F27_64;
707 case RISCV::F28_32:
return RISCV::F28_64;
708 case RISCV::F29_32:
return RISCV::F29_64;
709 case RISCV::F30_32:
return RISCV::F30_64;
710 case RISCV::F31_32:
return RISCV::F31_64;
716 RISCVOperand &Op =
static_cast<RISCVOperand &
>(AsmOp);
718 return Match_InvalidOperand;
720 unsigned Reg = Op.getReg();
722 RISCVMCRegisterClasses[RISCV::FPR32RegClassID].contains(Reg);
724 RISCVMCRegisterClasses[RISCV::FPR32CRegClassID].contains(Reg);
728 if ((IsRegFPR32 && Kind == MCK_FPR64) ||
729 (IsRegFPR32C && Kind == MCK_FPR64C)) {
731 return Match_Success;
733 return Match_InvalidOperand;
736 bool RISCVAsmParser::generateImmOutOfRangeError(
737 OperandVector &Operands, uint64_t ErrorInfo, int64_t Lower, int64_t Upper,
738 Twine Msg =
"immediate must be an integer in the range") {
739 SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc();
740 return Error(ErrorLoc, Msg +
" [" +
Twine(Lower) +
", " +
Twine(Upper) +
"]");
743 bool RISCVAsmParser::MatchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
747 bool MatchingInlineAsm) {
751 MatchInstructionImpl(Operands, Inst, ErrorInfo, MatchingInlineAsm);
756 return processInstruction(Inst, IDLoc, Out);
757 case Match_MissingFeature:
758 return Error(IDLoc,
"instruction use requires an option to be enabled");
759 case Match_MnemonicFail:
760 return Error(IDLoc,
"unrecognized instruction mnemonic");
761 case Match_InvalidOperand: {
762 SMLoc ErrorLoc = IDLoc;
763 if (ErrorInfo != ~0U) {
764 if (ErrorInfo >= Operands.
size())
765 return Error(ErrorLoc,
"too few operands for instruction");
767 ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc();
768 if (ErrorLoc ==
SMLoc())
771 return Error(ErrorLoc,
"invalid operand for instruction");
778 if (Result > FIRST_TARGET_MATCH_RESULT_TY) {
779 SMLoc ErrorLoc = IDLoc;
780 if (ErrorInfo != ~0U && ErrorInfo >= Operands.
size())
781 return Error(ErrorLoc,
"too few operands for instruction");
787 case Match_InvalidImmXLenLI:
789 SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc();
790 return Error(ErrorLoc,
"operand must be a constant 64-bit integer");
792 return generateImmOutOfRangeError(Operands, ErrorInfo,
793 std::numeric_limits<int32_t>::min(),
795 case Match_InvalidUImmLog2XLen:
797 return generateImmOutOfRangeError(Operands, ErrorInfo, 0, (1 << 6) - 1);
798 return generateImmOutOfRangeError(Operands, ErrorInfo, 0, (1 << 5) - 1);
799 case Match_InvalidUImmLog2XLenNonZero:
801 return generateImmOutOfRangeError(Operands, ErrorInfo, 1, (1 << 6) - 1);
802 return generateImmOutOfRangeError(Operands, ErrorInfo, 1, (1 << 5) - 1);
803 case Match_InvalidUImm5:
804 return generateImmOutOfRangeError(Operands, ErrorInfo, 0, (1 << 5) - 1);
805 case Match_InvalidSImm6:
806 return generateImmOutOfRangeError(Operands, ErrorInfo, -(1 << 5),
808 case Match_InvalidSImm6NonZero:
809 return generateImmOutOfRangeError(
810 Operands, ErrorInfo, -(1 << 5), (1 << 5) - 1,
811 "immediate must be non-zero in the range");
812 case Match_InvalidCLUIImm:
813 return generateImmOutOfRangeError(
814 Operands, ErrorInfo, 1, (1 << 5) - 1,
815 "immediate must be in [0xfffe0, 0xfffff] or");
816 case Match_InvalidUImm7Lsb00:
817 return generateImmOutOfRangeError(
818 Operands, ErrorInfo, 0, (1 << 7) - 4,
819 "immediate must be a multiple of 4 bytes in the range");
820 case Match_InvalidUImm8Lsb00:
821 return generateImmOutOfRangeError(
822 Operands, ErrorInfo, 0, (1 << 8) - 4,
823 "immediate must be a multiple of 4 bytes in the range");
824 case Match_InvalidUImm8Lsb000:
825 return generateImmOutOfRangeError(
826 Operands, ErrorInfo, 0, (1 << 8) - 8,
827 "immediate must be a multiple of 8 bytes in the range");
828 case Match_InvalidSImm9Lsb0:
829 return generateImmOutOfRangeError(
830 Operands, ErrorInfo, -(1 << 8), (1 << 8) - 2,
831 "immediate must be a multiple of 2 bytes in the range");
832 case Match_InvalidUImm9Lsb000:
833 return generateImmOutOfRangeError(
834 Operands, ErrorInfo, 0, (1 << 9) - 8,
835 "immediate must be a multiple of 8 bytes in the range");
836 case Match_InvalidUImm10Lsb00NonZero:
837 return generateImmOutOfRangeError(
838 Operands, ErrorInfo, 4, (1 << 10) - 4,
839 "immediate must be a multiple of 4 bytes in the range");
840 case Match_InvalidSImm10Lsb0000NonZero:
841 return generateImmOutOfRangeError(
842 Operands, ErrorInfo, -(1 << 9), (1 << 9) - 16,
843 "immediate must be a multiple of 16 bytes and non-zero in the range");
844 case Match_InvalidSImm12:
845 return generateImmOutOfRangeError(
846 Operands, ErrorInfo, -(1 << 11), (1 << 11) - 1,
847 "operand must be a symbol with %lo/%pcrel_lo modifier or an integer in " 849 case Match_InvalidSImm12Lsb0:
850 return generateImmOutOfRangeError(
851 Operands, ErrorInfo, -(1 << 11), (1 << 11) - 2,
852 "immediate must be a multiple of 2 bytes in the range");
853 case Match_InvalidSImm13Lsb0:
854 return generateImmOutOfRangeError(
855 Operands, ErrorInfo, -(1 << 12), (1 << 12) - 2,
856 "immediate must be a multiple of 2 bytes in the range");
857 case Match_InvalidUImm20LUI:
858 return generateImmOutOfRangeError(Operands, ErrorInfo, 0, (1 << 20) - 1,
859 "operand must be a symbol with %hi() " 860 "modifier or an integer in the range");
861 case Match_InvalidUImm20AUIPC:
862 return generateImmOutOfRangeError(
863 Operands, ErrorInfo, 0, (1 << 20) - 1,
864 "operand must be a symbol with %pcrel_hi() modifier or an integer in " 866 case Match_InvalidSImm21Lsb0JAL:
867 return generateImmOutOfRangeError(
868 Operands, ErrorInfo, -(1 << 20), (1 << 20) - 2,
869 "immediate must be a multiple of 2 bytes in the range");
870 case Match_InvalidCSRSystemRegister: {
871 return generateImmOutOfRangeError(Operands, ErrorInfo, 0, (1 << 12) - 1,
872 "operand must be a valid system register " 873 "name or an integer in the range");
875 case Match_InvalidFenceArg: {
876 SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc();
879 "operand must be formed of letters selected in-order from 'iorw'");
881 case Match_InvalidFRMArg: {
882 SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc();
885 "operand must be a valid floating point rounding mode mnemonic");
887 case Match_InvalidBareSymbol: {
888 SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc();
889 return Error(ErrorLoc,
"operand must be a bare symbol name");
896 bool RISCVAsmParser::ParseRegister(
unsigned &RegNo,
SMLoc &StartLoc,
898 const AsmToken &Tok = getParser().getTok();
902 StringRef Name = getLexer().getTok().getIdentifier();
909 return Error(StartLoc,
"invalid register name");
914 SMLoc FirstS = getLoc();
915 bool HadParens =
false;
920 size_t ReadCount = getLexer().peekTokens(Buf);
927 switch (getLexer().getKind()) {
931 StringRef Name = getLexer().getTok().getIdentifier();
937 getLexer().UnLex(Buf[0]);
942 Operands.
push_back(RISCVOperand::createToken(
"(", FirstS, isRV64()));
946 Operands.
push_back(RISCVOperand::createReg(RegNo, S, E, isRV64()));
951 Operands.
push_back(RISCVOperand::createToken(
")", getLoc(), isRV64()));
958 RISCVAsmParser::parseCSRSystemRegister(
OperandVector &Operands) {
962 switch (getLexer().getKind()) {
970 if (getParser().parseExpression(Res))
975 int64_t Imm = CE->getValue();
976 if (isUInt<12>(Imm)) {
980 Operands.
push_back(RISCVOperand::createSysReg(
981 SysReg ? SysReg->Name :
"", S, Imm, isRV64()));
986 Twine Msg =
"immediate must be an integer in the range";
992 if (getParser().parseIdentifier(Identifier))
998 if (!SysReg->haveRequiredFeatures(getSTI().getFeatureBits())) {
999 Error(S,
"system register use requires an option to be enabled");
1002 Operands.
push_back(RISCVOperand::createSysReg(
1003 Identifier, S, SysReg->Encoding, isRV64()));
1007 Twine Msg =
"operand must be a valid system register name " 1008 "or an integer in the range";
1014 Twine Msg =
"immediate must be an integer in the range";
1028 switch (getLexer().getKind()) {
1037 if (getParser().parseExpression(Res))
1041 return parseOperandWithModifier(Operands);
1044 Operands.
push_back(RISCVOperand::createImm(Res, S, E, isRV64()));
1049 RISCVAsmParser::parseOperandWithModifier(
OperandVector &Operands) {
1054 Error(getLoc(),
"expected '%' for operand modifier");
1061 Error(getLoc(),
"expected valid identifier for operand modifier");
1067 Error(getLoc(),
"unrecognized operand modifier");
1073 Error(getLoc(),
"expected '('");
1079 if (getParser().parseParenExpression(SubExpr, E)) {
1084 Operands.
push_back(RISCVOperand::createImm(ModExpr, S, E, isRV64()));
1097 if (getParser().parseIdentifier(Identifier))
1100 MCSymbol *Sym = getContext().getOrCreateSymbol(Identifier);
1102 Operands.
push_back(RISCVOperand::createImm(Res, S, E, isRV64()));
1124 RISCVAsmParser::parseMemOpBaseReg(
OperandVector &Operands) {
1126 Error(getLoc(),
"expected '('");
1131 Operands.
push_back(RISCVOperand::createToken(
"(", getLoc(), isRV64()));
1134 Error(getLoc(),
"expected register");
1139 Error(getLoc(),
"expected ')'");
1144 Operands.
push_back(RISCVOperand::createToken(
")", getLoc(), isRV64()));
1156 MatchOperandParserImpl(Operands, Mnemonic,
true);
1175 Error(getLoc(),
"unknown operand");
1188 if (getSTI().getFeatureBits()[RISCV::FeatureRelax]) {
1189 auto *Assembler = getTargetStreamer().getStreamer().getAssemblerPtr();
1190 if (Assembler !=
nullptr) {
1198 Operands.
push_back(RISCVOperand::createToken(Name, NameLoc, isRV64()));
1205 if (parseOperand(Operands, Name))
1209 unsigned OperandIdx = 1;
1215 if (parseOperand(Operands, Name))
1222 SMLoc Loc = getLexer().getLoc();
1223 getParser().eatToEndOfStatement();
1224 return Error(Loc,
"unexpected token");
1231 bool RISCVAsmParser::classifySymbolRef(
const MCExpr *Expr,
1237 if (
const RISCVMCExpr *RE = dyn_cast<RISCVMCExpr>(Expr)) {
1238 Kind = RE->getKind();
1239 Expr = RE->getSubExpr();
1243 if (isa<MCConstantExpr>(Expr) || isa<MCSymbolRefExpr>(Expr))
1250 if (!isa<MCSymbolRefExpr>(BE->
getLHS()))
1259 isa<MCSymbolRefExpr>(BE->
getRHS()))
1276 bool RISCVAsmParser::ParseDirective(
AsmToken DirectiveID) {
1283 if (IDVal ==
".option")
1284 return parseDirectiveOption();
1289 bool RISCVAsmParser::parseDirectiveOption() {
1296 "unexpected token, expected identifier");
1300 if (Option ==
"push") {
1301 getTargetStreamer().emitDirectiveOptionPush();
1306 "unexpected token, expected end of statement");
1312 if (Option ==
"pop") {
1314 getTargetStreamer().emitDirectiveOptionPop();
1319 "unexpected token, expected end of statement");
1321 if (popFeatureBits())
1322 return Error(StartLoc,
".option pop with no .option push");
1327 if (Option ==
"rvc") {
1328 getTargetStreamer().emitDirectiveOptionRVC();
1333 "unexpected token, expected end of statement");
1335 setFeatureBits(RISCV::FeatureStdExtC,
"c");
1339 if (Option ==
"norvc") {
1340 getTargetStreamer().emitDirectiveOptionNoRVC();
1345 "unexpected token, expected end of statement");
1347 clearFeatureBits(RISCV::FeatureStdExtC,
"c");
1351 if (Option ==
"relax") {
1352 getTargetStreamer().emitDirectiveOptionRelax();
1357 "unexpected token, expected end of statement");
1359 setFeatureBits(RISCV::FeatureRelax,
"relax");
1363 if (Option ==
"norelax") {
1364 getTargetStreamer().emitDirectiveOptionNoRelax();
1369 "unexpected token, expected end of statement");
1371 clearFeatureBits(RISCV::FeatureRelax,
"relax");
1377 "unknown option, expected 'push', 'pop', 'rvc', 'norvc', 'relax' or " 1385 bool Res = compressInst(CInst, Inst, getSTI(), S.
getContext());
1390 void RISCVAsmParser::emitLoadImm(
unsigned DestReg, int64_t Value,
1395 unsigned SrcReg = RISCV::X0;
1397 if (Inst.Opc == RISCV::LUI) {
1399 Out,
MCInstBuilder(RISCV::LUI).addReg(DestReg).addImm(Inst.Imm));
1411 void RISCVAsmParser::emitLoadLocalAddress(
MCInst &Inst,
SMLoc IDLoc,
1422 "pcrel_hi",
true,
false);
1432 const MCExpr *RefToLinkTmpLabel =
1439 .addExpr(RefToLinkTmpLabel));
1442 bool RISCVAsmParser::processInstruction(
MCInst &Inst,
SMLoc IDLoc,
1446 if (Inst.
getOpcode() == RISCV::PseudoLI) {
1463 Imm = SignExtend64<32>(Imm);
1464 emitLoadImm(Reg, Imm, Out);
1466 }
else if (Inst.
getOpcode() == RISCV::PseudoLLA) {
1467 emitLoadLocalAddress(Inst, IDLoc, Out);
1471 emitToStreamer(Out, Inst);
static bool isReg(const MCInst &MI, unsigned OpNo)
constexpr bool isUInt< 32 >(uint64_t x)
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
StringRef getString() const
Get the string for the current token, this includes all characters (for example, the quotes on string...
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
This class represents lattice values for constants.
static unsigned MatchRegisterName(StringRef Name)
unsigned convertFPR32ToFPR64(unsigned Reg)
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Generic assembler parser interface, for use by target specific assembly parsers.
static MCOperand createExpr(const MCExpr *Val)
MCTargetAsmParser - Generic interface to target specific assembly parsers.
void push_back(const T &Elt)
static RoundingMode stringToRoundingMode(StringRef Str)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Target specific streamer interface.
bool isNot(TokenKind K) const
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
virtual const AsmToken & Lex()=0
Get the next AsmToken in the stream, possibly handling file inclusion first.
block Block Frequency true
const AsmToken & getTok() const
Get the current AsmToken from the stream.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI, bool PrintSchedInfo=false)
Emit the given Instruction into the current section.
static MCDisassembler::DecodeStatus addOperand(MCInst &Inst, const MCOperand &Opnd)
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
MCContext & getContext() const
StringRef getIdentifier() const
Get the identifier string for the current token, which should be an identifier or a string...
amdgpu Simplify well known AMD library false Value Value const Twine & Name
static MCOperand createReg(unsigned Reg)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
const FeatureBitset & getFeatureBits() const
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Base class for the full range of assembler expressions which are needed for parsing.
Target independent representation for an assembler token.
Represent a reference to a symbol from inside an expression.
Target & getTheRISCV32Target()
static bool isMem(const MachineInstr &MI, unsigned Op)
MCParsedAsmOperand - This abstract class represents a source-level assembly instruction operand...
unsigned getReg() const
Returns the register number.
Context object for machine code objects.
std::pair< StringRef, StringRef > getToken(StringRef Source, StringRef Delimiters=" \\\)
getToken - This function extracts one token from source, ignoring any leading characters that appear ...
RegisterMCAsmParser - Helper template for registering a target specific assembly parser, for use in the target machine initialization function.
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
const MCExpr * getExpr() const
Instances of this class represent a single low-level machine instruction.
Analysis containing CSE Info
virtual void eatToEndOfStatement()=0
Skip to the end of the current statement, for error recovery.
virtual void addAliasForDirective(StringRef Directive, StringRef Alias)=0
FeatureBitset ToggleFeature(uint64_t FB)
Toggle a feature and return the re-computed feature bits.
const char * getPointer() const
Streaming machine code generation interface.
MCInstBuilder & addReg(unsigned Reg)
Add a new register operand.
MCSymbol * createTempSymbol(bool CanBeUnnamed=true)
Create and return a new assembler temporary symbol with a unique but unspecified name.
MCTargetStreamer * getTargetStreamer()
Container class for subtarget features.
constexpr bool isShiftedInt(int64_t x)
Checks if a signed integer is an N bit number shifted left by S.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Target & getTheRISCV64Target()
Interface to description of machine instruction set.
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
MCInstBuilder & addImm(int64_t Val)
Add a new integer immediate operand.
Binary assembler expressions.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static unsigned MatchRegisterAltName(StringRef Name)
Maps from the set of all alternative registernames to a register number.
MCStreamer & getStreamer()
constexpr bool isInt< 32 >(int64_t x)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
void LLVMInitializeRISCVAsmParser()
const MCOperand & getOperand(unsigned i) const
Promote Memory to Register
LLVM_NODISCARD T pop_back_val()
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
const SysReg * lookupSysRegByName(StringRef)
Base class for user error types.
static SMLoc getFromPointer(const char *Ptr)
static VariantKind getVariantKindForName(StringRef name)
LLVM_NODISCARD bool empty() const
Generic base class for all target subtargets.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Opcode getOpcode() const
Get the kind of this binary expression.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
const SysReg * lookupSysRegByEncoding(uint16_t)
virtual void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
This class implements an extremely fast bulk output stream that can only output to a stream...
void addOperand(const MCOperand &Op)
StringRef - Represent a constant reference to a string, i.e.
void generateInstSeq(int64_t Val, bool Is64Bit, InstSeq &Res)
Represents a location in source code.
unsigned getOpcode() const
Instances of this class represent operands of the MCInst class.
static MCOperand createImm(int64_t Val)
static const RISCVMCExpr * create(const MCExpr *Expr, VariantKind Kind, MCContext &Ctx)
bool parseImmediate(MCInst &MI, uint64_t &Size, ArrayRef< uint8_t > Bytes)