40 bool MatchingInlineAsm)
override;
44 SMLoc &EndLoc)
override;
58#define GET_ASSEMBLER_HEADER
59#include "BPFGenAsmMatcher.inc"
66 enum BPFMatchResultTy {
68#define GET_OPERAND_DIAGNOSTIC_TYPES
69#include "BPFGenAsmMatcher.inc"
70#undef GET_OPERAND_DIAGNOSTIC_TYPES
98 SMLoc StartLoc, EndLoc;
105 BPFOperand(KindTy K) :
Kind(
K) {}
110 StartLoc =
o.StartLoc;
126 bool isToken()
const override {
return Kind == Token; }
128 bool isImm()
const override {
return Kind == Immediate; }
129 bool isMem()
const override {
return false; }
131 bool isConstantImm()
const {
132 return isImm() && isa<MCConstantExpr>(
getImm());
135 int64_t getConstantImm()
const {
140 bool isSImm16()
const {
141 return (isConstantImm() && isInt<16>(getConstantImm()));
144 bool isSymbolRef()
const {
return isImm() && isa<MCSymbolRefExpr>(
getImm()); }
146 bool isBrTarget()
const {
return isSymbolRef() || isSImm16(); }
149 SMLoc getStartLoc()
const override {
return StartLoc; }
151 SMLoc getEndLoc()
const override {
return EndLoc; }
159 assert(Kind == Immediate &&
"Invalid type access!");
164 assert(Kind == Token &&
"Invalid type access!");
178 OS <<
"'" << getToken() <<
"'";
184 assert(Expr &&
"Expr shouldn't be null!");
186 if (
auto *CE = dyn_cast<MCConstantExpr>(Expr))
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);
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);
237 .
Case(
"may_goto",
true)
241 .
Case(
"ld_pseudo",
true)
242 .
Case(
"store_release",
true)
262 .
Case(
"bswap16",
true)
263 .
Case(
"bswap32",
true)
264 .
Case(
"bswap64",
true)
269 .
Case(
"atomic_fetch_add",
true)
270 .
Case(
"atomic_fetch_and",
true)
271 .
Case(
"atomic_fetch_or",
true)
272 .
Case(
"atomic_fetch_xor",
true)
273 .
Case(
"xchg_64",
true)
274 .
Case(
"xchg32_32",
true)
275 .
Case(
"cmpxchg_64",
true)
276 .
Case(
"cmpxchg32_32",
true)
277 .
Case(
"addr_space_cast",
true)
278 .
Case(
"load_acquire",
true)
284#define GET_REGISTER_MATCHER
285#define GET_MATCHER_IMPLEMENTATION
286#include "BPFGenAsmMatcher.inc"
293 BPFOperand &Op0 = (BPFOperand &)*
Operands[0];
294 BPFOperand &Op1 = (BPFOperand &)*
Operands[1];
295 BPFOperand &Op2 = (BPFOperand &)*
Operands[2];
296 BPFOperand &Op3 = (BPFOperand &)*
Operands[3];
297 if (Op0.isReg() && Op1.isToken() && Op2.isToken() && Op3.isReg()
298 && Op1.getToken() ==
"="
299 && (Op2.getToken() ==
"-" || Op2.getToken() ==
"be16"
300 || Op2.getToken() ==
"be32" || Op2.getToken() ==
"be64"
301 || Op2.getToken() ==
"le16" || Op2.getToken() ==
"le32"
302 || Op2.getToken() ==
"le64")
303 && Op0.getReg() != Op3.getReg())
310bool BPFAsmParser::matchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
313 bool MatchingInlineAsm) {
318 return Error(IDLoc,
"additional inst constraint not met");
327 case Match_MissingFeature:
328 return Error(IDLoc,
"instruction use requires an option to be enabled");
329 case Match_MnemonicFail:
330 return Error(IDLoc,
"unrecognized instruction mnemonic");
331 case Match_InvalidOperand:
336 return Error(ErrorLoc,
"too few operands for instruction");
340 if (ErrorLoc ==
SMLoc())
344 return Error(ErrorLoc,
"invalid operand for instruction");
345 case Match_InvalidBrTarget:
347 "operand is not an identifier or 16-bit signed integer");
348 case Match_InvalidSImm16:
350 "operand is not a 16-bit signed integer");
351 case Match_InvalidTiedOperand:
353 "operand is not the same as the dst register");
361 if (!tryParseRegister(Reg, StartLoc, EndLoc).isSuccess())
362 return Error(StartLoc,
"invalid register name");
368 const AsmToken &Tok = getParser().getTok();
371 Reg = BPF::NoRegister;
388 if (BPFOperand::isValidIdInMiddle(
Name)) {
397 switch (getLexer().getKind()) {
431 Operands.push_back(BPFOperand::createToken(
432 getLexer().getTok().getString().
substr(0, 1), S));
433 Operands.push_back(BPFOperand::createToken(
434 getLexer().getTok().getString().
substr(1, 1), S));
451 switch (getLexer().getKind()) {
462 Operands.push_back(BPFOperand::createReg(Reg, S, E));
468 switch (getLexer().getKind()) {
483 if (getParser().parseExpression(IdVal))
487 Operands.push_back(BPFOperand::createImm(IdVal, S, E));
500 Operands.push_back(BPFOperand::createReg(Reg, NameLoc, E));
501 }
else if (BPFOperand::isValidIdAtStart(
Name))
502 Operands.push_back(BPFOperand::createToken(
Name, NameLoc));
504 return Error(NameLoc,
"invalid register/token name");
508 if (parseOperandAsOperator(
Operands).isSuccess())
512 if (parseRegister(
Operands).isSuccess())
522 SMLoc Loc = getLexer().getLoc();
523 return Error(Loc,
"unexpected token");
528 SMLoc Loc = getLexer().getLoc();
530 getParser().eatToEndOfStatement();
532 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)
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeBPFAsmParser()
#define LLVM_EXTERNAL_VISIBILITY
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
mir Rename Register Operands
static unsigned getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
static bool isReg(const MCInst &MI, unsigned OpNo)
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
static StringRef substr(StringRef Str, uint64_t Len)
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
bool parseImmediate(MCInst &MI, uint64_t &Size, ArrayRef< uint8_t > Bytes)
Target independent representation for an assembler token.
LLVM_ABI SMLoc getLoc() const
LLVM_ABI SMLoc getEndLoc() const
This class represents an Operation in the Expression.
Base class for user error types.
Lightweight error class with error context and mandatory checking.
This class is intended to be used as a base class for asm properties and features specific to the tar...
void printExpr(raw_ostream &, const MCExpr &) const
MCAsmParser & getParser()
Generic assembler parser interface, for use by target specific assembly parsers.
const AsmToken & getTok() const
Get the current AsmToken from the stream.
Base class for the full range of assembler expressions which are needed for parsing.
Instances of this class represent a single low-level machine instruction.
void addOperand(const MCOperand Op)
Interface to description of machine instruction set.
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.
Wrapper class representing physical registers. Should be passed by value.
Streaming machine code generation interface.
virtual void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI)
Emit the given Instruction into the current section.
Generic base class for all target subtargets.
const FeatureBitset & getFeatureBits() const
MCTargetAsmParser - Generic interface to target specific assembly parsers.
virtual bool tokenIsStartOfStatement(AsmToken::TokenKind Token)
virtual bool parseInstruction(ParseInstructionInfo &Info, StringRef Name, SMLoc NameLoc, OperandVector &Operands)=0
Parse one assembly instruction.
virtual bool equalIsAsmAssignment()
@ FIRST_TARGET_MATCH_RESULT_TY
virtual bool parseRegister(MCRegister &Reg, SMLoc &StartLoc, SMLoc &EndLoc)=0
virtual ParseStatus tryParseRegister(MCRegister &Reg, SMLoc &StartLoc, SMLoc &EndLoc)=0
tryParseRegister - parse one register if possible
virtual bool matchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode, OperandVector &Operands, MCStreamer &Out, uint64_t &ErrorInfo, bool MatchingInlineAsm)=0
Recognize a series of operands of a parsed instruction as an actual MCInst and emit it to the specifi...
void setAvailableFeatures(const FeatureBitset &Value)
Ternary parse status returned by various parse* methods.
static constexpr StatusTy Failure
static constexpr StatusTy Success
static constexpr StatusTy NoMatch
Wrapper class representing virtual and physical registers.
Represents a location in source code.
static SMLoc getFromPointer(const char *Ptr)
constexpr const char * getPointer() const
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
StringRef - Represent a constant reference to a string, i.e.
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ CE
Windows NT (Windows on ARM)
Reg
All possible values of the reg field in the ModR/M byte.
This is an optimization pass for GlobalISel generic memory operations.
static bool isMem(const MachineInstr &MI, unsigned Op)
Target & getTheBPFleTarget()
Target & getTheBPFbeTarget()
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
Target & getTheBPFTarget()
DWARFExpression::Operation Op
RegisterMCAsmParser - Helper template for registering a target specific assembly parser,...