#include "MCTargetDesc/RISCVAsmBackend.h"
#include "MCTargetDesc/RISCVBaseInfo.h"
#include "MCTargetDesc/RISCVInstPrinter.h"
#include "MCTargetDesc/RISCVMCExpr.h"
#include "MCTargetDesc/RISCVMCTargetDesc.h"
#include "MCTargetDesc/RISCVMatInt.h"
#include "MCTargetDesc/RISCVTargetStreamer.h"
#include "TargetInfo/RISCVTargetInfo.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallBitVector.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/MC/MCAssembler.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCInstBuilder.h"
#include "llvm/MC/MCInstrInfo.h"
#include "llvm/MC/MCObjectFileInfo.h"
#include "llvm/MC/MCParser/MCAsmLexer.h"
#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
#include "llvm/MC/MCParser/MCTargetAsmParser.h"
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/MC/MCValue.h"
#include "llvm/MC/TargetRegistry.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/RISCVAttributes.h"
#include "llvm/TargetParser/RISCVISAInfo.h"
#include <limits>
usingnamespacellvm;
#define DEBUG_TYPE …
STATISTIC(RISCVNumInstrsCompressed,
"Number of RISC-V Compressed instructions emitted");
static cl::opt<bool> AddBuildAttributes("riscv-add-build-attributes",
cl::init(false));
namespace llvm {
extern const SubtargetFeatureKV RISCVFeatureKV[RISCV::NumSubtargetFeatures];
}
namespace {
struct RISCVOperand;
struct ParserOptionsSet { … };
class RISCVAsmParser : public MCTargetAsmParser { … };
struct RISCVOperand final : public MCParsedAsmOperand { … };
}
#define GET_REGISTER_MATCHER
#define GET_SUBTARGET_FEATURE_NAME
#define GET_MATCHER_IMPLEMENTATION
#define GET_MNEMONIC_SPELL_CHECKER
#include "RISCVGenAsmMatcher.inc"
static MCRegister convertFPR64ToFPR16(MCRegister Reg) { … }
static MCRegister convertFPR64ToFPR32(MCRegister Reg) { … }
static MCRegister convertVRToVRMx(const MCRegisterInfo &RI, MCRegister Reg,
unsigned Kind) { … }
unsigned RISCVAsmParser::validateTargetOperandClass(MCParsedAsmOperand &AsmOp,
unsigned Kind) { … }
bool RISCVAsmParser::generateImmOutOfRangeError(
SMLoc ErrorLoc, int64_t Lower, int64_t Upper,
const Twine &Msg = "immediate must be an integer in the range") { … }
bool RISCVAsmParser::generateImmOutOfRangeError(
OperandVector &Operands, uint64_t ErrorInfo, int64_t Lower, int64_t Upper,
const Twine &Msg = "immediate must be an integer in the range") { … }
bool RISCVAsmParser::matchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
OperandVector &Operands,
MCStreamer &Out,
uint64_t &ErrorInfo,
bool MatchingInlineAsm) { … }
MCRegister RISCVAsmParser::matchRegisterNameHelper(StringRef Name) const { … }
bool RISCVAsmParser::parseRegister(MCRegister &Reg, SMLoc &StartLoc,
SMLoc &EndLoc) { … }
ParseStatus RISCVAsmParser::tryParseRegister(MCRegister &Reg, SMLoc &StartLoc,
SMLoc &EndLoc) { … }
ParseStatus RISCVAsmParser::parseRegister(OperandVector &Operands,
bool AllowParens) { … }
ParseStatus RISCVAsmParser::parseInsnDirectiveOpcode(OperandVector &Operands) { … }
ParseStatus RISCVAsmParser::parseInsnCDirectiveOpcode(OperandVector &Operands) { … }
ParseStatus RISCVAsmParser::parseCSRSystemRegister(OperandVector &Operands) { … }
ParseStatus RISCVAsmParser::parseFPImm(OperandVector &Operands) { … }
ParseStatus RISCVAsmParser::parseImmediate(OperandVector &Operands) { … }
ParseStatus RISCVAsmParser::parseOperandWithModifier(OperandVector &Operands) { … }
ParseStatus RISCVAsmParser::parseBareSymbol(OperandVector &Operands) { … }
ParseStatus RISCVAsmParser::parseCallSymbol(OperandVector &Operands) { … }
ParseStatus RISCVAsmParser::parsePseudoJumpSymbol(OperandVector &Operands) { … }
ParseStatus RISCVAsmParser::parseJALOffset(OperandVector &Operands) { … }
bool RISCVAsmParser::parseVTypeToken(const AsmToken &Tok, VTypeState &State,
unsigned &Sew, unsigned &Lmul,
bool &Fractional, bool &TailAgnostic,
bool &MaskAgnostic) { … }
ParseStatus RISCVAsmParser::parseVTypeI(OperandVector &Operands) { … }
bool RISCVAsmParser::generateVTypeError(SMLoc ErrorLoc) { … }
ParseStatus RISCVAsmParser::parseMaskReg(OperandVector &Operands) { … }
ParseStatus RISCVAsmParser::parseGPRAsFPR64(OperandVector &Operands) { … }
ParseStatus RISCVAsmParser::parseGPRAsFPR(OperandVector &Operands) { … }
ParseStatus RISCVAsmParser::parseGPRPairAsFPR64(OperandVector &Operands) { … }
template <bool IsRV64>
ParseStatus RISCVAsmParser::parseGPRPair(OperandVector &Operands) { … }
ParseStatus RISCVAsmParser::parseGPRPair(OperandVector &Operands,
bool IsRV64Inst) { … }
ParseStatus RISCVAsmParser::parseFRMArg(OperandVector &Operands) { … }
ParseStatus RISCVAsmParser::parseFenceArg(OperandVector &Operands) { … }
ParseStatus RISCVAsmParser::parseMemOpBaseReg(OperandVector &Operands) { … }
ParseStatus RISCVAsmParser::parseZeroOffsetMemOp(OperandVector &Operands) { … }
ParseStatus RISCVAsmParser::parseRegReg(OperandVector &Operands) { … }
ParseStatus RISCVAsmParser::parseReglist(OperandVector &Operands) { … }
ParseStatus RISCVAsmParser::parseZcmpStackAdj(OperandVector &Operands,
bool ExpectNegative) { … }
bool RISCVAsmParser::parseOperand(OperandVector &Operands, StringRef Mnemonic) { … }
bool RISCVAsmParser::parseInstruction(ParseInstructionInfo &Info,
StringRef Name, SMLoc NameLoc,
OperandVector &Operands) { … }
bool RISCVAsmParser::classifySymbolRef(const MCExpr *Expr,
RISCVMCExpr::VariantKind &Kind) { … }
bool RISCVAsmParser::isSymbolDiff(const MCExpr *Expr) { … }
ParseStatus RISCVAsmParser::parseDirective(AsmToken DirectiveID) { … }
bool RISCVAsmParser::resetToArch(StringRef Arch, SMLoc Loc, std::string &Result,
bool FromOptionDirective) { … }
bool RISCVAsmParser::parseDirectiveOption() { … }
bool RISCVAsmParser::parseDirectiveAttribute() { … }
bool isValidInsnFormat(StringRef Format, bool AllowC) { … }
bool RISCVAsmParser::parseDirectiveInsn(SMLoc L) { … }
bool RISCVAsmParser::parseDirectiveVariantCC() { … }
void RISCVAsmParser::emitToStreamer(MCStreamer &S, const MCInst &Inst) { … }
void RISCVAsmParser::emitLoadImm(MCRegister DestReg, int64_t Value,
MCStreamer &Out) { … }
void RISCVAsmParser::emitAuipcInstPair(MCOperand DestReg, MCOperand TmpReg,
const MCExpr *Symbol,
RISCVMCExpr::VariantKind VKHi,
unsigned SecondOpcode, SMLoc IDLoc,
MCStreamer &Out) { … }
void RISCVAsmParser::emitLoadLocalAddress(MCInst &Inst, SMLoc IDLoc,
MCStreamer &Out) { … }
void RISCVAsmParser::emitLoadGlobalAddress(MCInst &Inst, SMLoc IDLoc,
MCStreamer &Out) { … }
void RISCVAsmParser::emitLoadAddress(MCInst &Inst, SMLoc IDLoc,
MCStreamer &Out) { … }
void RISCVAsmParser::emitLoadTLSIEAddress(MCInst &Inst, SMLoc IDLoc,
MCStreamer &Out) { … }
void RISCVAsmParser::emitLoadTLSGDAddress(MCInst &Inst, SMLoc IDLoc,
MCStreamer &Out) { … }
void RISCVAsmParser::emitLoadStoreSymbol(MCInst &Inst, unsigned Opcode,
SMLoc IDLoc, MCStreamer &Out,
bool HasTmpReg) { … }
void RISCVAsmParser::emitPseudoExtend(MCInst &Inst, bool SignExtend,
int64_t Width, SMLoc IDLoc,
MCStreamer &Out) { … }
void RISCVAsmParser::emitVMSGE(MCInst &Inst, unsigned Opcode, SMLoc IDLoc,
MCStreamer &Out) { … }
bool RISCVAsmParser::checkPseudoAddTPRel(MCInst &Inst,
OperandVector &Operands) { … }
bool RISCVAsmParser::checkPseudoTLSDESCCall(MCInst &Inst,
OperandVector &Operands) { … }
std::unique_ptr<RISCVOperand> RISCVAsmParser::defaultMaskRegOp() const { … }
std::unique_ptr<RISCVOperand> RISCVAsmParser::defaultFRMArgOp() const { … }
std::unique_ptr<RISCVOperand> RISCVAsmParser::defaultFRMArgLegacyOp() const { … }
bool RISCVAsmParser::validateInstruction(MCInst &Inst,
OperandVector &Operands) { … }
bool RISCVAsmParser::processInstruction(MCInst &Inst, SMLoc IDLoc,
OperandVector &Operands,
MCStreamer &Out) { … }
extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeRISCVAsmParser() { … }