LLVM: lib/ProfileData/MemProf.cpp Source File (original) (raw)
8
9namespace llvm {
13#define MIBEntryDef(NameTag, Name, Type) List.push_back(Meta::Name);
15#undef MIBEntryDef
17}
18
20 return {Meta::AllocCount, Meta::TotalSize, Meta::TotalLifetime,
21 Meta::TotalLifetimeAccessDensity};
22}
23
26 size_t Size = 0;
27
29
32}
33
36 size_t Size = 0;
37
39
42}
43
56
59
60 size_t Result = sizeof(uint64_t);
62 Result += N.serializedSize(Schema, Version2);
63
64
66
68 return Result;
69}
70
73
74 size_t Result = sizeof(uint64_t);
76 Result += N.serializedSize(Schema, Version3);
77
78
80
81
83 return Result;
84}
85
88
89 size_t Result = sizeof(uint64_t);
91 Result += N.serializedSize(Schema, Version4);
92
93
95 for (const auto &CS : Record.CallSites)
98 return Result;
99}
100
113
117
119
123 N.Info.serialize(Schema, OS);
124 }
125
126
128 for (const auto &CS : Record.CallSites)
130}
131
137
139
144 N.Info.serialize(Schema, OS);
145 }
146
147
149 for (const auto &CS : Record.CallSites) {
152 }
153}
154
160
162
167 N.Info.serialize(Schema, OS);
168 }
169
170
172 for (const auto &CS : Record.CallSites) {
175 LE.write<uint64_t>(CS.CalleeGuids.size());
176 for (const auto &Guid : CS.CalleeGuids)
178 }
179}
180
184 const {
188 return;
190 serializeV3(*this, Schema, OS, *MemProfCallStackIndexes);
191 return;
193 serializeV4(*this, Schema, OS, *MemProfCallStackIndexes);
194 return;
195 }
197}
198
200 const unsigned char *Ptr) {
202
204
205
208 Record.AllocSites.reserve(NumNodes);
209 for (uint64_t I = 0; I < NumNodes; I++) {
212 Node.Info.deserialize(Schema, Ptr);
215 }
216
217
220 Record.CallSites.reserve(NumCtxs);
221 for (uint64_t J = 0; J < NumCtxs; J++) {
224 Record.CallSites.emplace_back(CSId);
225 }
226
228}
229
231 const unsigned char *Ptr) {
233
235
236
239 Record.AllocSites.reserve(NumNodes);
241 for (uint64_t I = 0; I < NumNodes; I++) {
245 Node.Info.deserialize(Schema, Ptr);
246 Ptr += SerializedSize;
248 }
249
250
253 Record.CallSites.reserve(NumCtxs);
254 for (uint64_t J = 0; J < NumCtxs; J++) {
255
256
257
261 Record.CallSites.emplace_back(CSId);
262 }
263
265}
266
268 const unsigned char *Ptr) {
270
272
273
276 Record.AllocSites.reserve(NumNodes);
278 for (uint64_t I = 0; I < NumNodes; I++) {
282 Node.Info.deserialize(Schema, Ptr);
283 Ptr += SerializedSize;
285 }
286
287
290 Record.CallSites.reserve(NumCtxs);
291 for (uint64_t J = 0; J < NumCtxs; J++) {
299 for (uint64_t K = 0; K < NumGuids; ++K)
302 Record.CallSites.emplace_back(CSId, std::move(Guids));
303 }
304
306}
307
308IndexedMemProfRecord
310 const unsigned char *Ptr,
319 }
321}
322
326
330 AI.Info = IndexedAI.Info;
331 AI.CallStack = Callback(IndexedAI.CSId);
332 Record.AllocSites.push_back(std::move(AI));
333 }
334
337 std::vector Frames = Callback(CS.CSId);
338 Record.CallSites.emplace_back(std::move(Frames), CS.CalleeGuids);
339 }
340
342}
343
345
346
347
348
349
350
353
354
355
356
358}
359
362
363 const unsigned char *Ptr = Buffer;
364 const uint64_t NumSchemaIds =
366 if (NumSchemaIds > static_cast<uint64_t>(Meta::Size)) {
368 "memprof schema invalid");
369 }
370
372 for (size_t I = 0; I < NumSchemaIds; I++) {
375 if (Tag >= static_cast<uint64_t>(Meta::Size)) {
377 "memprof schema invalid");
378 }
379 Result.push_back(static_cast<Meta>(Tag));
380 }
381
382 Buffer = Ptr;
383 return Result;
384}
385}
386}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the SmallVector class.
bool contains(const_arg_type_t< KeyT > Val) const
Return true if the specified key is in the map, false otherwise.
Tagged union holding either a T or a Error.
static LLVM_ABI GUID getGUIDAssumingExternalLinkage(StringRef GlobalName)
Return a 64-bit global unique ID constructed from the name of a global symbol.
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
void reserve(size_type N)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
An efficient, type-erasing, non-owning reference to a callable.
This class implements an extremely fast bulk output stream that can only output to a stream.
static StringRef getCanonicalFnName(const Function &F)
Return the canonical name for a function, taking into account suffix elision policy attributes.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static IndexedMemProfRecord deserializeV4(const MemProfSchema &Schema, const unsigned char *Ptr)
Definition MemProf.cpp:267
uint32_t LinearCallStackId
static IndexedMemProfRecord deserializeV3(const MemProfSchema &Schema, const unsigned char *Ptr)
Definition MemProf.cpp:230
static void serializeV3(const IndexedMemProfRecord &Record, const MemProfSchema &Schema, raw_ostream &OS, llvm::DenseMap< CallStackId, LinearCallStackId > &MemProfCallStackIndexes)
Definition MemProf.cpp:132
LLVM_ABI MemProfSchema getHotColdSchema()
Definition MemProf.cpp:19
static size_t serializedSizeV2(const IndexedAllocationInfo &IAI, const MemProfSchema &Schema)
Definition MemProf.cpp:24
llvm::SmallVector< Meta, static_cast< int >(Meta::Size)> MemProfSchema
static size_t serializedSizeV3(const IndexedAllocationInfo &IAI, const MemProfSchema &Schema)
Definition MemProf.cpp:34
LLVM_ABI MemProfSchema getFullSchema()
Definition MemProf.cpp:11
LLVM_ABI GlobalValue::GUID getGUID(const StringRef FunctionName)
Definition MemProf.cpp:344
static void serializeV4(const IndexedMemProfRecord &Record, const MemProfSchema &Schema, raw_ostream &OS, llvm::DenseMap< CallStackId, LinearCallStackId > &MemProfCallStackIndexes)
Definition MemProf.cpp:155
LLVM_ABI Expected< MemProfSchema > readMemProfSchema(const unsigned char *&Buffer)
Definition MemProf.cpp:360
static void serializeV2(const IndexedMemProfRecord &Record, const MemProfSchema &Schema, raw_ostream &OS)
Definition MemProf.cpp:114
static IndexedMemProfRecord deserializeV2(const MemProfSchema &Schema, const unsigned char *Ptr)
Definition MemProf.cpp:199
static size_t serializedSizeV4(const IndexedMemProfRecord &Record, const MemProfSchema &Schema)
Definition MemProf.cpp:86
value_type readNext(const CharT *&memory, endianness endian)
Read a value of a particular endianness from a buffer, and increment the buffer past that value.
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr uintptr_t uintptr_t Version
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
std::vector< Frame > CallStack
PortableMemInfoBlock Info
LLVM_ABI size_t serializedSize(const MemProfSchema &Schema, IndexedVersion Version) const
Definition MemProf.cpp:44
llvm::SmallVector< IndexedAllocationInfo > AllocSites
LLVM_ABI size_t serializedSize(const MemProfSchema &Schema, IndexedVersion Version) const
Definition MemProf.cpp:101
LLVM_ABI void serialize(const MemProfSchema &Schema, raw_ostream &OS, IndexedVersion Version, llvm::DenseMap< CallStackId, LinearCallStackId > *MemProfCallStackIndexes=nullptr) const
Definition MemProf.cpp:181
static LLVM_ABI IndexedMemProfRecord deserialize(const MemProfSchema &Schema, const unsigned char *Buffer, IndexedVersion Version)
Definition MemProf.cpp:309
llvm::SmallVector< IndexedCallSiteInfo > CallSites
LLVM_ABI MemProfRecord toMemProfRecord(llvm::function_ref< std::vector< Frame >(const CallStackId)> Callback) const
Definition MemProf.cpp:323
static size_t serializedSize(const MemProfSchema &Schema)
Adapter to write values to a stream in a particular byte order.