LLVM: lib/Target/BPF/BPFPreserveDIType.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

27

28#define DEBUG_TYPE "bpf-preserve-di-type"

29

30using namespace llvm;

31

32namespace {

33

34static bool BPFPreserveDITypeImpl(Function &F) {

35 LLVM_DEBUG(dbgs() << "********** preserve debuginfo type **********\n");

36

37 Module *M = F.getParent();

38

39

40 if (M->debug_compile_units().empty())

41 return false;

42

43 std::vector<CallInst *> PreserveDITypeCalls;

44

45 for (auto &BB : F) {

46 for (auto &I : BB) {

49 continue;

50

52 if (!GV)

53 continue;

54

55 if (GV->getName().starts_with("llvm.bpf.btf.type.id")) {

56 if (Call->getMetadata(LLVMContext::MD_preserve_access_index))

58 "Missing metadata for llvm.bpf.btf.type.id intrinsic");

59 PreserveDITypeCalls.push_back(Call);

60 }

61 }

62 }

63

64 if (PreserveDITypeCalls.empty())

65 return false;

66

67 std::string BaseName = "llvm.btf_type_id.";

68 static int Count = 0;

69 for (auto *Call : PreserveDITypeCalls) {

72 uint64_t FlagValue = Flag->getValue().getZExtValue();

73

75 report_fatal_error("Incorrect flag for llvm.bpf.btf.type.id intrinsic");

76

77 MDNode *MD = Call->getMetadata(LLVMContext::MD_preserve_access_index);

78

82 } else {

84 }

87 unsigned Tag = DTy->getTag();

88 if (Tag != dwarf::DW_TAG_const_type && Tag != dwarf::DW_TAG_volatile_type)

89 break;

90 Ty = DTy->getBaseType();

91 }

92

94 if (Ty->getName().empty()) {

97 "SubroutineType not supported for BTF_TYPE_ID_REMOTE reloc");

98 else

100 }

101 }

102 MD = Ty;

103

106 std::string GVName =

107 BaseName + std::to_string(Count) + "$" + std::to_string(Reloc);

111 GV->setMetadata(LLVMContext::MD_preserve_access_index, MD);

112

113

115 Call->getIterator());

118 Call->replaceAllUsesWith(PassThroughInst);

119 Call->eraseFromParent();

121 }

122

123 return true;

124}

125}

126

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

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.

PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)

Definition BPFPreserveDIType.cpp:127

LLVM Basic Block Representation.

LLVM_ABI LLVMContext & getContext() const

Get the context in which this basic block lives.

This is the shared class of boolean and integer constants.

LLVM_ABI void setMetadata(unsigned KindID, MDNode *Node)

Set a particular kind of metadata attachment.

@ ExternalLinkage

Externally visible function.

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.

static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)

This is an optimization pass for GlobalISel generic memory operations.

decltype(auto) dyn_cast(const From &Val)

dyn_cast - Return the argument parameter cast to the specified type.

LLVM_ABI raw_ostream & dbgs()

dbgs() - This returns a reference to a raw_ostream for debugging messages.

LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)

FunctionAddr VTableAddr Count

bool isa(const From &Val)

isa - Return true if the parameter to the template is an instance of one of the template type argu...

decltype(auto) cast(const From &Val)

cast - Return the argument parameter cast to the specified type.

AnalysisManager< Function > FunctionAnalysisManager

Convenience typedef for the Function analysis manager.