LLVM: lib/ExecutionEngine/OProfileJIT/OProfileJITEventListener.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

16#include "llvm/Config/config.h"

28#include <dirent.h>

29#include <fcntl.h>

30

31using namespace llvm;

33

34#define DEBUG_TYPE "oprofile-jit-event-listener"

35

36namespace {

37

39 std::unique_ptr Wrapper;

40

42 std::map<ObjectKey, OwningBinary> DebugObjects;

43

44public:

45 OProfileJITEventListener(std::unique_ptr LibraryWrapper)

46 : Wrapper(std::move(LibraryWrapper)) {

48 }

49

50 ~OProfileJITEventListener();

51

52 void notifyObjectLoaded(ObjectKey Key, const ObjectFile &Obj,

54

55 void notifyFreeingObject(ObjectKey Key) override;

56};

57

58void OProfileJITEventListener::initialize() {

59 if (Wrapper->op_open_agent()) {

61 LLVM_DEBUG(dbgs() << "Failed to connect to OProfile agent: " << err_str

62 << "\n");

63 } else {

64 LLVM_DEBUG(dbgs() << "Connected to OProfile agent.\n");

65 }

66}

67

68OProfileJITEventListener::~OProfileJITEventListener() {

69 if (Wrapper->isAgentAvailable()) {

70 if (Wrapper->op_close_agent() == -1) {

72 LLVM_DEBUG(dbgs() << "Failed to disconnect from OProfile agent: "

73 << err_str << "\n");

74 } else {

75 LLVM_DEBUG(dbgs() << "Disconnected from OProfile agent.\n");

76 }

77 }

78}

79

80void OProfileJITEventListener::notifyObjectLoaded(

83 if (Wrapper->isAgentAvailable()) {

84 return;

85 }

86

90

91

92 for (const std::pair<SymbolRef, uint64_t> &P : computeSymbolSizes(DebugObj)) {

95 continue;

96

98 if (!NameOrErr)

99 continue;

102 if (!AddrOrErr)

103 continue;

106

107 if (Wrapper->op_write_native_code(Name.data(), Addr, (void *)Addr, Size) ==

108 -1) {

109 LLVM_DEBUG(dbgs() << "Failed to tell OProfile about native function "

110 << Name << " at [" << (void *)Addr << "-"

111 << ((char *)Addr + Size) << "]\n");

112 continue;

113 }

114

116 size_t i = 0;

117 size_t num_entries = Lines.size();

118 struct debug_line_info *debug_line;

119 debug_line = (struct debug_line_info *)calloc(

120 num_entries, sizeof(struct debug_line_info));

121

122 for (auto& It : Lines) {

123 debug_line[i].vma = (unsigned long)It.first;

124 debug_line[i].lineno = It.second.Line;

125 debug_line[i].filename =

126 const_cast<char *>(Lines.front().second.FileName.c_str());

127 ++i;

128 }

129

130 if (Wrapper->op_write_debug_line_info((void *)Addr, num_entries,

131 debug_line) == -1) {

132 LLVM_DEBUG(dbgs() << "Failed to tell OProfiler about debug object at ["

133 << (void *)Addr << "-" << ((char *)Addr + Size)

134 << "]\n");

135 continue;

136 }

137 }

138

139 DebugObjects[Key] = std::move(DebugObjOwner);

140}

141

142void OProfileJITEventListener::notifyFreeingObject(ObjectKey Key) {

143 if (Wrapper->isAgentAvailable()) {

144

145

146

147 if (DebugObjects.find(Key) == DebugObjects.end())

148 return;

149

150 const ObjectFile &DebugObj = *DebugObjects[Key].getBinary();

151

152

155 I != E; ++I) {

158 if (!AddrOrErr)

159 continue;

161

162 if (Wrapper->op_unload_native_code(Addr) == -1) {

165 << "Failed to tell OProfile about unload of native function at "

166 << (void *)Addr << "\n");

167 continue;

168 }

169 }

170 }

171 }

172

173 DebugObjects.erase(Key);

174}

175

176}

177

178namespace llvm {

180 return new OProfileJITEventListener(std::make_unique());

181}

182

183}

184

amdgpu aa AMDGPU Address space based Alias Analysis Wrapper

static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")

static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, const llvm::StringTable &StandardNames, VectorLibrary VecLib)

Initialize the set of available library functions based on the specified target triple.

static std::unique_ptr< DWARFContext > create(const object::ObjectFile &Obj, ProcessDebugRelocations RelocAction=ProcessDebugRelocations::Process, const LoadedObjectInfo *L=nullptr, std::string DWPName="", std::function< void(Error)> RecoverableErrorHandler=WithColor::defaultErrorHandler, std::function< void(Error)> WarningHandler=WithColor::defaultWarningHandler, bool ThreadSafe=false)

Tagged union holding either a T or a Error.

JITEventListener - Abstract interface for use by the JIT to notify clients about significant events d...

static JITEventListener * createOProfileJITEventListener()

Information about the loaded object.

StringRef - Represent a constant reference to a string, i.e.

This class is the base class for all object file types.

This is a value type class that represents a single symbol in the list of symbols in the object file.

Expected< SymbolRef::Type > getType() const

Expected< StringRef > getName() const

Expected< uint64_t > getAddress() const

Returns the symbol virtual address (i.e.

virtual basic_symbol_iterator symbol_begin() const =0

virtual basic_symbol_iterator symbol_end() const =0

LLVM_C_ABI LLVMJITEventListenerRef LLVMCreateOProfileJITEventListener(void)

struct LLVMOpaqueJITEventListener * LLVMJITEventListenerRef

LLVM_ABI std::vector< std::pair< SymbolRef, uint64_t > > computeSymbolSizes(const ObjectFile &O)

LLVM_ABI std::string StrError()

Returns a string representation of the errno value, using whatever thread-safe variant of strerror() ...

This is an optimization pass for GlobalISel generic memory operations.

SmallVector< std::pair< uint64_t, DILineInfo >, 16 > DILineInfoTable

LLVM_ABI raw_ostream & dbgs()

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

LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key

LLVMAttributeRef wrap(Attribute Attr)