38 bool MatchingInlineAsm)
override;
42 SMLoc &EndLoc)
override;
54#define GET_ASSEMBLER_HEADER
55#include "BPFGenAsmMatcher.inc"
62 enum BPFMatchResultTy {
64#define GET_OPERAND_DIAGNOSTIC_TYPES
65#include "BPFGenAsmMatcher.inc"
66#undef GET_OPERAND_DIAGNOSTIC_TYPES
94 SMLoc StartLoc, EndLoc;
101 BPFOperand(KindTy K) :
Kind(
K) {}
106 StartLoc =
o.StartLoc;
122 bool isToken()
const override {
return Kind == Token; }
124 bool isImm()
const override {
return Kind == Immediate; }
125 bool isMem()
const override {
return false; }
127 bool isConstantImm()
const {
128 return isImm() && isa<MCConstantExpr>(getImm());
131 int64_t getConstantImm()
const {
132 const MCExpr *Val = getImm();
136 bool isSImm16()
const {
137 return (isConstantImm() && isInt<16>(getConstantImm()));
140 bool isSymbolRef()
const {
return isImm() && isa<MCSymbolRefExpr>(getImm()); }
142 bool isBrTarget()
const {
return isSymbolRef() || isSImm16(); }
145 SMLoc getStartLoc()
const override {
return StartLoc; }
147 SMLoc getEndLoc()
const override {
return EndLoc; }
154 const MCExpr *getImm()
const {
155 assert(Kind == Immediate &&
"Invalid type access!");
160 assert(Kind == Token &&
"Invalid type access!");
174 OS <<
"'" << getToken() <<
"'";
180 assert(Expr &&
"Expr shouldn't be null!");
182 if (
auto *CE = dyn_cast<MCConstantExpr>(Expr))
189 void addRegOperands(
MCInst &Inst,
unsigned N)
const {
190 assert(
N == 1 &&
"Invalid number of operands!");
194 void addImmOperands(
MCInst &Inst,
unsigned N)
const {
195 assert(
N == 1 &&
"Invalid number of operands!");
196 addExpr(Inst, getImm());
199 static std::unique_ptr<BPFOperand> createToken(
StringRef Str,
SMLoc S) {
200 auto Op = std::make_unique<BPFOperand>(Token);
209 auto Op = std::make_unique<BPFOperand>(
Register);
210 Op->Reg.RegNum =
Reg;
216 static std::unique_ptr<BPFOperand> createImm(
const MCExpr *Val,
SMLoc S,
218 auto Op = std::make_unique<BPFOperand>(Immediate);
233 .
Case(
"may_goto",
true)
237 .
Case(
"ld_pseudo",
true)
257 .
Case(
"bswap16",
true)
258 .
Case(
"bswap32",
true)
259 .
Case(
"bswap64",
true)
265 .
Case(
"atomic_fetch_add",
true)
266 .
Case(
"atomic_fetch_and",
true)
267 .
Case(
"atomic_fetch_or",
true)
268 .
Case(
"atomic_fetch_xor",
true)
269 .
Case(
"xchg_64",
true)
270 .
Case(
"xchg32_32",
true)
271 .
Case(
"cmpxchg_64",
true)
272 .
Case(
"cmpxchg32_32",
true)
273 .
Case(
"addr_space_cast",
true)
279#define GET_REGISTER_MATCHER
280#define GET_MATCHER_IMPLEMENTATION
281#include "BPFGenAsmMatcher.inc"
288 BPFOperand &Op0 = (BPFOperand &)*
Operands[0];
289 BPFOperand &Op1 = (BPFOperand &)*
Operands[1];
290 BPFOperand &Op2 = (BPFOperand &)*
Operands[2];
291 BPFOperand &Op3 = (BPFOperand &)*
Operands[3];
292 if (Op0.isReg() && Op1.isToken() && Op2.isToken() && Op3.isReg()
293 && Op1.getToken() ==
"="
294 && (Op2.getToken() ==
"-" || Op2.getToken() ==
"be16"
295 || Op2.getToken() ==
"be32" || Op2.getToken() ==
"be64"
296 || Op2.getToken() ==
"le16" || Op2.getToken() ==
"le32"
297 || Op2.getToken() ==
"le64")
298 && Op0.getReg() != Op3.getReg())
305bool BPFAsmParser::matchAndEmitInstruction(
SMLoc IDLoc,
unsigned &Opcode,
308 bool MatchingInlineAsm) {
313 return Error(IDLoc,
"additional inst constraint not met");
322 case Match_MissingFeature:
323 return Error(IDLoc,
"instruction use requires an option to be enabled");
324 case Match_MnemonicFail:
325 return Error(IDLoc,
"unrecognized instruction mnemonic");
326 case Match_InvalidOperand:
331 return Error(ErrorLoc,
"too few operands for instruction");
335 if (ErrorLoc ==
SMLoc())
339 return Error(ErrorLoc,
"invalid operand for instruction");
340 case Match_InvalidBrTarget:
342 "operand is not an identifier or 16-bit signed integer");
343 case Match_InvalidSImm16:
345 "operand is not a 16-bit signed integer");
353 if (!tryParseRegister(Reg, StartLoc, EndLoc).isSuccess())
354 return Error(StartLoc,
"invalid register name");
360 const AsmToken &Tok = getParser().getTok();
363 Reg = BPF::NoRegister;
380 if (BPFOperand::isValidIdInMiddle(
Name)) {
389 switch (getLexer().getKind()) {
423 Operands.push_back(BPFOperand::createToken(
424 getLexer().getTok().getString().
substr(0, 1), S));
425 Operands.push_back(BPFOperand::createToken(
426 getLexer().getTok().getString().
substr(1, 1), S));
443 switch (getLexer().getKind()) {
454 Operands.push_back(BPFOperand::createReg(Reg, S, E));
460 switch (getLexer().getKind()) {
475 if (getParser().parseExpression(IdVal))
479 Operands.push_back(BPFOperand::createImm(IdVal, S, E));
492 Operands.push_back(BPFOperand::createReg(Reg, NameLoc, E));
493 }
else if (BPFOperand::isValidIdAtStart(
Name))
494 Operands.push_back(BPFOperand::createToken(
Name, NameLoc));
496 return Error(NameLoc,
"invalid register/token name");
500 if (parseOperandAsOperator(
Operands).isSuccess())
504 if (parseRegister(
Operands).isSuccess())
514 SMLoc Loc = getLexer().getLoc();
515 return Error(Loc,
"unexpected token");
520 SMLoc Loc = getLexer().getLoc();
522 getParser().eatToEndOfStatement();
524 return Error(Loc,
"unexpected token");
static MCRegister MatchRegisterName(StringRef Name)
static bool isNot(const MachineRegisterInfo &MRI, const MachineInstr &MI)
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
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")
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool isImm(const MachineOperand &MO, MachineRegisterInfo *MRI)
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.
This class represents an Operation in the Expression.
Base class for user error types.
Lightweight error class with error context and mandatory checking.
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 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 starIsStartOfStatement()
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()
Target & getTheBPFTarget()
DWARFExpression::Operation Op
RegisterMCAsmParser - Helper template for registering a target specific assembly parser,...