33 SMLoc getLoc()
const {
return getParser().
getTok().
getLoc(); }
37 bool matchAndEmitInstruction(SMLoc IDLoc,
unsigned &Opcode,
40 bool MatchingInlineAsm)
override;
42 bool parseRegister(MCRegister &Reo, SMLoc &StartLoc, SMLoc &EndLoc)
override;
43 ParseStatus tryParseRegister(MCRegister &
Reg, SMLoc &StartLoc,
44 SMLoc &EndLoc)
override;
46 bool parseInstruction(ParseInstructionInfo &
Info, StringRef Name,
51 bool equalIsAsmAssignment()
override {
return false; }
58#define GET_ASSEMBLER_HEADER
59#include "BPFGenAsmMatcher.inc"
66 enum BPFMatchResultTy {
67 Match_Dummy = FIRST_TARGET_MATCH_RESULT_TY,
68#define GET_OPERAND_DIAGNOSTIC_TYPES
69#include "BPFGenAsmMatcher.inc"
70#undef GET_OPERAND_DIAGNOSTIC_TYPES
73 BPFAsmParser(
const MCSubtargetInfo &STI, MCAsmParser &Parser,
74 const MCInstrInfo &MII,
const MCTargetOptions &
Options)
75 : MCTargetAsmParser(
Options, STI, MII) {
76 setAvailableFeatures(ComputeAvailableFeatures(STI.
getFeatureBits()));
98 SMLoc StartLoc, EndLoc;
105 BPFOperand(KindTy K) : Kind(
K) {}
108 BPFOperand(
const BPFOperand &o) : MCParsedAsmOperand() {
110 StartLoc =
o.StartLoc;
126 bool isToken()
const override {
return Kind == Token; }
127 bool isReg()
const override {
return Kind == Register; }
128 bool isImm()
const override {
return Kind == Immediate; }
129 bool isMem()
const override {
return false; }
131 bool isConstantImm()
const {
135 int64_t getConstantImm()
const {
136 const MCExpr *Val =
getImm();
137 return static_cast<const MCConstantExpr *
>(Val)->getValue();
140 bool isSImm16()
const {
141 return (isConstantImm() &&
isInt<16>(getConstantImm()));
146 bool isBrTarget()
const {
return isSymbolRef() || isSImm16(); }
149 SMLoc getStartLoc()
const override {
return StartLoc; }
151 SMLoc getEndLoc()
const override {
return EndLoc; }
153 MCRegister
getReg()
const override {
154 assert(Kind == Register &&
"Invalid type access!");
158 const MCExpr *
getImm()
const {
159 assert(Kind == Immediate &&
"Invalid type access!");
164 assert(Kind == Token &&
"Invalid type access!");
168 void print(raw_ostream &OS,
const MCAsmInfo &MAI)
const override {
183 void addExpr(MCInst &Inst,
const MCExpr *Expr)
const {
184 assert(Expr &&
"Expr shouldn't be null!");
193 void addRegOperands(MCInst &Inst,
unsigned N)
const {
194 assert(
N == 1 &&
"Invalid number of operands!");
198 void addImmOperands(MCInst &Inst,
unsigned N)
const {
199 assert(
N == 1 &&
"Invalid number of operands!");
203 static std::unique_ptr<BPFOperand> createToken(StringRef Str, SMLoc S) {
204 auto Op = std::make_unique<BPFOperand>(Token);
211 static std::unique_ptr<BPFOperand> createReg(MCRegister
Reg, SMLoc S,
213 auto Op = std::make_unique<BPFOperand>(Register);
214 Op->Reg.RegNum =
Reg;
220 static std::unique_ptr<BPFOperand> createImm(
const MCExpr *Val, SMLoc S,
222 auto Op = std::make_unique<BPFOperand>(Immediate);
230 static bool isValidIdAtStart(StringRef Name) {
231 return StringSwitch<bool>(
Name.lower())
238 .Case(
"may_goto",
true)
242 .Case(
"ld_pseudo",
true)
243 .Case(
"store_release",
true)
248 static bool isValidIdInMiddle(StringRef Name) {
249 return StringSwitch<bool>(
Name.lower())
263 .Case(
"bswap16",
true)
264 .Case(
"bswap32",
true)
265 .Case(
"bswap64",
true)
270 .Case(
"atomic_fetch_add",
true)
271 .Case(
"atomic_fetch_and",
true)
272 .Case(
"atomic_fetch_or",
true)
273 .Case(
"atomic_fetch_xor",
true)
274 .Case(
"xchg_64",
true)
275 .Case(
"xchg32_32",
true)
276 .Case(
"cmpxchg_64",
true)
277 .Case(
"cmpxchg32_32",
true)
278 .Case(
"addr_space_cast",
true)
279 .Case(
"load_acquire",
true)
285#define GET_REGISTER_MATCHER
286#define GET_MATCHER_IMPLEMENTATION
287#include "BPFGenAsmMatcher.inc"
294 BPFOperand &Op0 = (BPFOperand &)*
Operands[0];
295 BPFOperand &Op1 = (BPFOperand &)*
Operands[1];
296 BPFOperand &Op2 = (BPFOperand &)*
Operands[2];
297 BPFOperand &Op3 = (BPFOperand &)*
Operands[3];
298 if (Op0.isReg() && Op1.isToken() && Op2.isToken() && Op3.isReg()
299 && Op1.getToken() ==
"="
300 && (Op2.getToken() ==
"-" || Op2.getToken() ==
"be16"
301 || Op2.getToken() ==
"be32" || Op2.getToken() ==
"be64"
302 || Op2.getToken() ==
"le16" || Op2.getToken() ==
"le32"
303 || Op2.getToken() ==
"le64")
304 && Op0.getReg() != Op3.getReg())
311bool BPFAsmParser::matchAndEmitInstruction(SMLoc IDLoc,
unsigned &Opcode,
313 MCStreamer &Out, uint64_t &ErrorInfo,
314 bool MatchingInlineAsm) {
319 return Error(IDLoc,
"additional inst constraint not met");
321 switch (MatchInstructionImpl(
Operands, Inst, ErrorInfo, MatchingInlineAsm)) {
328 case Match_MissingFeature:
329 return Error(IDLoc,
"instruction use requires an option to be enabled");
330 case Match_MnemonicFail:
331 return Error(IDLoc,
"unrecognized instruction mnemonic");
332 case Match_InvalidOperand:
335 if (ErrorInfo != ~0U) {
337 return Error(ErrorLoc,
"too few operands for instruction");
339 ErrorLoc = ((BPFOperand &)*
Operands[ErrorInfo]).getStartLoc();
341 if (ErrorLoc == SMLoc())
345 return Error(ErrorLoc,
"invalid operand for instruction");
346 case Match_InvalidBrTarget:
348 "operand is not an identifier or 16-bit signed integer");
349 case Match_InvalidSImm16:
351 "operand is not a 16-bit signed integer");
352 case Match_InvalidTiedOperand:
354 "operand is not the same as the dst register");
360bool BPFAsmParser::parseRegister(MCRegister &
Reg, SMLoc &StartLoc,
362 if (!tryParseRegister(
Reg, StartLoc, EndLoc).isSuccess())
363 return Error(StartLoc,
"invalid register name");
367ParseStatus BPFAsmParser::tryParseRegister(MCRegister &
Reg, SMLoc &StartLoc,
369 const AsmToken &Tok = getParser().getTok();
372 Reg = BPF::NoRegister;
373 StringRef
Name = getLexer().getTok().getIdentifier();
387 StringRef
Name = getLexer().getTok().getIdentifier();
389 if (BPFOperand::isValidIdInMiddle(Name)) {
391 Operands.push_back(BPFOperand::createToken(Name, S));
398 switch (getLexer().getKind()) {
419 StringRef
Name = getLexer().getTok().getString();
421 Operands.push_back(BPFOperand::createToken(Name, S));
432 Operands.push_back(BPFOperand::createToken(
433 getLexer().getTok().getString().
substr(0, 1), S));
434 Operands.push_back(BPFOperand::createToken(
435 getLexer().getTok().getString().
substr(1, 1), S));
452 switch (getLexer().getKind()) {
456 StringRef
Name = getLexer().getTok().getIdentifier();
469 switch (getLexer().getKind()) {
484 if (getParser().parseExpression(IdVal))
488 Operands.push_back(BPFOperand::createImm(IdVal, S,
E));
494bool BPFAsmParser::parseInstruction(ParseInstructionInfo &
Info, StringRef Name,
501 Operands.push_back(BPFOperand::createReg(
Reg, NameLoc,
E));
502 }
else if (BPFOperand::isValidIdAtStart(Name))
503 Operands.push_back(BPFOperand::createToken(Name, NameLoc));
505 return Error(NameLoc,
"invalid register/token name");
509 if (parseOperandAsOperator(
Operands).isSuccess())
513 if (parseRegister(
Operands).isSuccess())
523 SMLoc Loc = getLexer().getLoc();
524 return Error(Loc,
"unexpected token");
529 SMLoc Loc = getLexer().getLoc();
531 getParser().eatToEndOfStatement();
533 return Error(Loc,
"unexpected token");
static MCRegister MatchRegisterName(StringRef Name)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static bool isNot(const MachineRegisterInfo &MRI, const MachineInstr &MI)
LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeBPFAsmParser()
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Analysis containing CSE Info
#define LLVM_EXTERNAL_VISIBILITY
mir Rename Register Operands
static unsigned getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
static bool isReg(const MCInst &MI, unsigned OpNo)
static StringRef substr(StringRef Str, uint64_t Len)
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")
bool parseImmediate(MCInst &MI, uint64_t &Size, ArrayRef< uint8_t > Bytes)
LLVM_ABI SMLoc getLoc() const
LLVM_ABI SMLoc getEndLoc() const
void printExpr(raw_ostream &, const MCExpr &) const
const AsmToken & getTok()
void addOperand(const MCOperand Op)
static MCOperand createExpr(const MCExpr *Val)
static MCOperand createReg(MCRegister Reg)
static MCOperand createImm(int64_t Val)
MCParsedAsmOperand - This abstract class represents a source-level assembly instruction operand.
virtual void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI)
Emit the given Instruction into the current section.
const FeatureBitset & getFeatureBits() const
MCTargetAsmParser - Generic interface to target specific assembly parsers.
Ternary parse status returned by various parse* methods.
static constexpr StatusTy Failure
static constexpr StatusTy Success
static constexpr StatusTy NoMatch
static SMLoc getFromPointer(const char *Ptr)
constexpr const char * getPointer() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ CE
Windows NT (Windows on ARM)
This is an optimization pass for GlobalISel generic memory operations.
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr, unsigned DynamicVGPRBlockSize=0)
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
static bool isMem(const MachineInstr &MI, unsigned Op)
LLVM_ABI std::pair< StringRef, StringRef > getToken(StringRef Source, StringRef Delimiters=" \t\n\v\f\r")
getToken - This function extracts one token from source, ignoring any leading characters that appear ...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Target & getTheBPFleTarget()
SmallVectorImpl< std::unique_ptr< MCParsedAsmOperand > > OperandVector
Target & getTheBPFbeTarget()
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
Target & getTheBPFTarget()
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...
DWARFExpression::Operation Op
RegisterMCAsmParser - Helper template for registering a target specific assembly parser,...