LLVM: lib/ExecutionEngine/Orc/Debugging/VTuneSupportPlugin.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

15

16using namespace llvm;

19

22 "llvm_orc_unregisterVTuneImpl";

24 "llvm_orc_test_registerVTuneImpl";

25

28 std::unique_ptr DC;

30 if (EmitDebugInfo) {

32 if (!EDC) {

33 EmitDebugInfo = false;

34 } else {

35 DC = std::move(EDC->first);

36 DCBacking = std::move(EDC->second);

37 }

38 }

39

42 auto [I, Inserted] = Deduplicator.try_emplace(S);

43 if (Inserted) {

44 Batch.Strings.push_back(S.str());

45 I->second = Batch.Strings.size();

46 }

47 return I->second;

48 };

49 for (auto Sym : G.defined_symbols()) {

50 if (!Sym->isCallable())

51 continue;

52

54 auto &Method = Batch.Methods.back();

55 Method.MethodID = 0;

56 Method.ParentMI = 0;

57 Method.LoadAddr = Sym->getAddress();

58 Method.LoadSize = Sym->getSize();

59 Method.NameSI = GetStringIdx(*Sym->getName());

60 Method.ClassFileSI = 0;

61 Method.SourceFileSI = 0;

62

63 if (!EmitDebugInfo)

64 continue;

65

66 auto &Section = Sym->getSection();

67 auto Addr = Sym->getAddress();

68 auto SAddr =

70 DILineInfoTable LinesInfo = DC->getLineInfoForAddressRange(

71 SAddr, Sym->getSize(),

73 Method.SourceFileSI = Batch.Strings.size();

75 DC->getLineInfoForAddress(SAddr).value_or(DILineInfo()).FileName);

76 for (auto &LInfo : LinesInfo) {

77 Method.LineTable.push_back(

78 std::pair<unsigned, unsigned>{ Sym->getOffset(),

79 LInfo.second.Line});

80 }

81 }

82 return Batch;

83}

84

89

91 if (Batch.Methods.empty()) {

93 }

94 {

95 std::lock_guardstd::mutex Lock(PluginMutex);

96 uint64_t Allocated = Batch.Methods.size();

97 uint64_t Start = NextMethodID;

98 NextMethodID += Allocated;

99 for (size_t i = Start; i < NextMethodID; ++i) {

100 Batch.Methods[i - Start].MethodID = i;

101 }

102 this->PendingMethodIDs[MR] = {Start, Allocated};

103 }

104 G.allocActions().push_back(

107 RegisterVTuneImplAddr, Batch)),

108 {}});

110 });

111}

112

115 std::lock_guardstd::mutex Lock(PluginMutex);

116 auto I = PendingMethodIDs.find(MR);

117 if (I == PendingMethodIDs.end())

118 return;

119

120 LoadedMethodIDs[K].push_back(I->second);

121 PendingMethodIDs.erase(I);

122 })) {

123 return Err;

124 }

126}

127

129 std::lock_guardstd::mutex Lock(PluginMutex);

130 PendingMethodIDs.erase(&MR);

132}

133

135

136 if (!UnregisterVTuneImplAddr) {

138 }

140 {

141 std::lock_guardstd::mutex Lock(PluginMutex);

142 auto I = LoadedMethodIDs.find(K);

143 if (I == LoadedMethodIDs.end())

145

146 UnloadedIDs = std::move(I->second);

147 LoadedMethodIDs.erase(I);

148 }

150 UnregisterVTuneImplAddr, UnloadedIDs))

151 return Err;

152

154}

155

159 std::lock_guardstd::mutex Lock(PluginMutex);

160 auto I = LoadedMethodIDs.find(SrcKey);

161 if (I == LoadedMethodIDs.end())

162 return;

163

164 auto &Dest = LoadedMethodIDs[DstKey];

166 LoadedMethodIDs.erase(SrcKey);

167}

168

171 bool EmitDebugInfo, bool TestMode) {

172 auto &ES = EPC.getExecutionSession();

173 auto RegisterImplName =

176 SymbolLookupSet SLS{RegisterImplName, UnregisterImplName};

178 if (!Res)

179 return Res.takeError();

181 Res->find(RegisterImplName)->second.getAddress());

183 Res->find(UnregisterImplName)->second.getAddress());

184 return std::make_unique(

185 EPC, RegisterImplAddr, UnregisterImplAddr, EmitDebugInfo);

186}

static constexpr StringRef RegisterVTuneImplName

Definition VTuneSupportPlugin.cpp:20

static constexpr StringRef RegisterTestVTuneImplName

Definition VTuneSupportPlugin.cpp:23

static constexpr StringRef UnregisterVTuneImplName

Definition VTuneSupportPlugin.cpp:21

static VTuneMethodBatch getMethodBatch(LinkGraph &G, bool EmitDebugInfo)

Definition VTuneSupportPlugin.cpp:26

Lightweight error class with error context and mandatory checking.

static ErrorSuccess success()

Create a success value.

Tagged union holding either a T or a Error.

StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...

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

Represents an object file section.

SectionOrdinal getOrdinal() const

Returns the ordinal for this section.

Represents an address in the executor process.

ExecutorProcessControl supports interaction with a JIT target process.

Represents a JIT'd dynamic library.

Tracks responsibility for materialization, and mediates interactions between MaterializationUnits and...

Error withResourceKeyDo(Func &&F) const

Runs the given callback under the session lock, passing in the associated ResourceKey.

A set of symbols to look up, each associated with a SymbolLookupFlags value.

void notifyTransferringResources(JITDylib &JD, ResourceKey DstKey, ResourceKey SrcKey) override

Definition VTuneSupportPlugin.cpp:156

static Expected< std::unique_ptr< VTuneSupportPlugin > > Create(ExecutorProcessControl &EPC, JITDylib &JD, bool EmitDebugInfo, bool TestMode=false)

Definition VTuneSupportPlugin.cpp:170

Error notifyEmitted(MaterializationResponsibility &MR) override

Definition VTuneSupportPlugin.cpp:113

void modifyPassConfig(MaterializationResponsibility &MR, jitlink::LinkGraph &G, jitlink::PassConfiguration &Config) override

Definition VTuneSupportPlugin.cpp:85

Error notifyFailed(MaterializationResponsibility &MR) override

Definition VTuneSupportPlugin.cpp:128

Error notifyRemovingResources(JITDylib &JD, ResourceKey K) override

Definition VTuneSupportPlugin.cpp:134

JITDylibSearchOrder makeJITDylibSearchOrder(ArrayRef< JITDylib * > JDs, JITDylibLookupFlags Flags=JITDylibLookupFlags::MatchExportedSymbolsOnly)

Convenience function for creating a search order from an ArrayRef of JITDylib*, all with the same fla...

SmallVector< std::pair< uint64_t, uint64_t > > VTuneUnloadedMethodIDs

LLVM_ABI Expected< std::pair< std::unique_ptr< DWARFContext >, StringMap< std::unique_ptr< MemoryBuffer > > > > createDWARFContext(jitlink::LinkGraph &G)

This is an optimization pass for GlobalISel generic memory operations.

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

void append_range(Container &C, Range &&R)

Wrapper function to append range R to container C.

void cantFail(Error Err, const char *Msg=nullptr)

Report a fatal error if Err is a failure value.

A format-neutral container for source line information.

An LinkGraph pass configuration, consisting of a list of pre-prune, post-prune, and post-fixup passes...

LinkGraphPassList PostFixupPasses

Post-fixup passes.