43#define DEBUG_TYPE "asm-printer"
46 std::unique_ptr<MCStreamer> Streamer)
55 if (
MAI.doesSupportDebugInformation() && !M.debug_compile_units().empty()) {
57 Handlers.push_back(std::unique_ptr<BTFDebug>(BTF));
69 const BPFSubtarget *Subtarget = getBTM().getSubtargetImpl();
71 std::vector<GlobalVariable *> Targets;
89 Targets.push_back(&
Global);
94 GV->dropAllReferences();
95 GV->eraseFromParent();
100 if (!GO.hasExternalWeakLinkage())
103 if (!SawTrapCall && GO.getName() ==
BPF_TRAP) {
104 GO.eraseFromParent();
152 if (ExtraCode && ExtraCode[0])
160 unsigned OpNum,
const char *ExtraCode,
162 assert(OpNum + 1 <
MI->getNumOperands() &&
"Insufficient operands");
165 assert(BaseMO.
isReg() &&
"Unexpected base pointer for inline asm memory operand.");
166 assert(OffsetMO.
isImm() &&
"Unexpected offset for inline asm memory operand.");
191 BPF_MC::verifyInstructionPredicates(
MI->getOpcode(),
196 if (!BTF || !BTF->InstLower(
MI, TmpInst)) {
198 MCInstLowering.
Lower(
MI, TmpInst);
206 const std::vector<LandingPadInfo> &LandingPads =
MF->getLandingPads();
207 if (LandingPads.empty())
215 const auto &TypeInfos =
MF->getTypeInfos();
225 for (
int TId : LP.TypeIds) {
226 if (TId > 0 && TypeInfos[TId - 1] !=
nullptr) {
228 F,
"BPF does not support type-specific exception catches yet"));
233 F,
"BPF does not support exception filters yet"));
238 MCSymbol *LPLabel = LP.LandingPadLabel;
241 for (
unsigned i = 0, e = LP.BeginLabels.size(); i != e; ++i) {
242 MCSymbol *Begin = LP.BeginLabels[i];
261 <<
"BPF.JT." <<
MF->getFunctionNumber() <<
'.' << JTI;
275 const std::vector<MachineJumpTableEntry> &JT = MJTI->
getJumpTables();
289 for (
unsigned JTI = 0; JTI < JT.size(); JTI++) {
315LLVMInitializeBPFAsmPrinter() {
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file contains support for writing BTF debug info.
#define LLVM_EXTERNAL_VISIBILITY
Module.h This file contains the declarations for the Module class.
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
This file describes how to lower LLVM code to machine code.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
bool empty() const
Check if the array is empty.
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
MCSymbol * getSymbol(const GlobalValue *GV) const
void EmitToStreamer(MCStreamer &S, const MCInst &Inst)
TargetMachine & TM
Target machine description.
SmallVector< std::unique_ptr< AsmPrinterHandler >, 2 > Handlers
MachineFunction * MF
The current machine function.
bool doInitialization(Module &M) override
Set up the AsmPrinter when we are working on a new module.
AsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > Streamer, char &ID=AsmPrinter::ID)
MCContext & OutContext
This is the context for the output file that we are streaming.
bool doFinalization(Module &M) override
Shut down the asmprinter.
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
const MCAsmInfo & MAI
Target Asm Printer information.
MCSymbol * GetBlockAddressSymbol(const BlockAddress *BA) const
Return the MCSymbol used to satisfy BlockAddress uses of the specified basic block.
const DataLayout & getDataLayout() const
Return information about data layout.
MCSymbol * GetExternalSymbolSymbol(const Twine &Sym) const
Return the MCSymbol for the specified ExternalSymbol.
const MCSubtargetInfo & getSubtargetInfo() const
Return information about subtarget.
virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &OS)
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant.
MCSymbol * getJTPublicSymbol(unsigned JTI)
void printOperand(const MachineInstr *MI, int OpNum, raw_ostream &O)
bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum, const char *ExtraCode, raw_ostream &O) override
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant as...
BPFAsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > Streamer)
bool doFinalization(Module &M) override
Shut down the asmprinter.
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &O) override
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant.
void emitFunctionBodyEnd() override
Targets can override this to emit stuff after the last basic block in the function.
~BPFAsmPrinter() override
bool doInitialization(Module &M) override
Set up the AsmPrinter when we are working on a new module.
void emitJumpTableInfo() override
Print assembly representations of the jump tables used by the current function to the current output ...
void emitInstruction(const MachineInstr *MI) override
Targets should implement this to emit instructions.
static const char * getRegisterName(MCRegister Reg)
void Lower(const MachineInstr *MI, MCInst &OutMI) const
Collect and emit BTF information.
ConstantArray - Constant Array Declarations.
This is an important base class in LLVM.
Diagnostic information for unsupported feature in backend.
@ PrivateLinkage
Like Internal, but omit from symbol table.
This is an important class for using LLVM in a threaded context.
LLVM_ABI void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Context object for machine code objects.
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.
Instances of this class represent a uniqued identifier for a section in the current translation unit.
MCSymbol * getBeginSymbol()
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
StringRef getName() const
getName - Get the symbol name.
LLVM_ABI MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
Representation of each machine instruction.
LLVM_ABI unsigned getEntrySize(const DataLayout &TD) const
getEntrySize - Return the size of each entry in the jump table.
@ EK_BlockAddress
EK_BlockAddress - Each entry is a plain address of block, e.g.: .word LBB123.
JTEntryKind getEntryKind() const
const std::vector< MachineJumpTableEntry > & getJumpTables() const
MachineOperand class - Representation of each machine instruction operand.
const GlobalValue * getGlobal() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
MachineBasicBlock * getMBB() const
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
const BlockAddress * getBlockAddress() const
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
const char * getSymbolName() const
Register getReg() const
getReg - Returns the register number.
@ MO_Immediate
Immediate operand.
@ MO_ConstantPoolIndex
Address of indexed Constant in Constant Pool.
@ MO_GlobalAddress
Address of a global value.
@ MO_BlockAddress
Address of a basic block.
@ MO_MachineBasicBlock
MachineBasicBlock reference.
@ MO_Register
Register operand.
@ MO_ExternalSymbol
Name of external global symbol.
@ MO_JumpTableIndex
Address of indexed Jump Table for switch.
A Module instance is used to store all the information related to an LLVM module.
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
virtual MCSection * getSectionForJumpTable(const Function &F, const TargetMachine &TM) const
Primary interface to the complete machine description for the target machine.
Value * getOperand(unsigned i) const
unsigned getNumOperands() const
This class implements an extremely fast bulk output stream that can only output to a stream.
A raw_ostream that writes to an SmallVector or SmallString.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Target & getTheBPFleTarget()
Target & getTheBPFbeTarget()
Target & getTheBPFTarget()
@ Global
Append to llvm.global_dtors.
DWARFExpression::Operation Op
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Implement std::hash so that hash_code can be used in STL containers.
This structure is used to retain landing pad info for the current function.
RegisterAsmPrinter - Helper template for registering a target specific assembly printer,...