29#define DEBUG_TYPE "bpf-preserve-di-type"
39static bool BPFPreserveDITypeImpl(
Function &
F) {
40 LLVM_DEBUG(
dbgs() <<
"********** preserve debuginfo type **********\n");
45 if (
M->debug_compile_units().empty())
48 std::vector<CallInst *> PreserveDITypeCalls;
52 auto *
Call = dyn_cast<CallInst>(&
I);
56 const auto *GV = dyn_cast<GlobalValue>(
Call->getCalledOperand());
60 if (GV->getName().starts_with(
"llvm.bpf.btf.type.id")) {
61 if (!
Call->getMetadata(LLVMContext::MD_preserve_access_index))
63 "Missing metadata for llvm.bpf.btf.type.id intrinsic");
64 PreserveDITypeCalls.push_back(Call);
69 if (PreserveDITypeCalls.empty())
72 std::string BaseName =
"llvm.btf_type_id.";
74 for (
auto *Call : PreserveDITypeCalls) {
82 MDNode *MD =
Call->getMetadata(LLVMContext::MD_preserve_access_index);
90 DIType *Ty = cast<DIType>(MD);
91 while (
auto *DTy = dyn_cast<DIDerivedType>(Ty)) {
92 unsigned Tag = DTy->getTag();
93 if (
Tag != dwarf::DW_TAG_const_type &&
Tag != dwarf::DW_TAG_volatile_type)
95 Ty = DTy->getBaseType();
100 if (isa<DISubroutineType>(Ty))
102 "SubroutineType not supported for BTF_TYPE_ID_REMOTE reloc");
112 BaseName + std::to_string(Count) +
"$" + std::to_string(Reloc);
114 *M, VarType,
false, GlobalVariable::ExternalLinkage,
nullptr, GVName);
116 GV->
setMetadata(LLVMContext::MD_preserve_access_index, MD);
120 Call->getIterator());
123 Call->replaceAllUsesWith(PassThroughInst);
124 Call->eraseFromParent();
This file contains the layout of .BTF and .BTF.ext ELF sections.
This file contains constants used for implementing Dwarf debug support.
Module.h This file contains the declarations for the Module class.
This header defines various interfaces for pass management in LLVM.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A container for analyses that lazily runs them and caches their results.
static constexpr StringRef TypeIdAttr
The attribute attached to globals representing a type id.
static Instruction * insertPassThrough(Module *M, BasicBlock *BB, Instruction *Input, Instruction *Before)
Insert a bpf passthrough builtin function.
@ BTF_TYPE_ID_LOCAL_RELOC
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
LLVM Basic Block Representation.
LLVMContext & getContext() const
Get the context in which this basic block lives.
This is the shared class of boolean and integer constants.
StringRef getName() const
void setMetadata(unsigned KindID, MDNode *Node)
Set a particular kind of metadata attachment.
void addAttribute(Attribute::AttrKind Kind)
Add attribute to this global.
Class to represent integer types.
An instruction for reading from memory.
A Module instance is used to store all the information related to an LLVM module.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
static IntegerType * getInt64Ty(LLVMContext &C)
Flag
These should be considered private to the implementation of the MCInstrDesc class.
This is an optimization pass for GlobalISel generic memory operations.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.