LLVM 23.0.0git
MemProf.h
Go to the documentation of this file.
1//===- MemProf.h - MemProf support ------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains common definitions used in the reading and writing of
10// memory profile data.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_PROFILEDATA_MEMPROF_H
15#define LLVM_PROFILEDATA_MEMPROF_H
16
17#include "llvm/ADT/DenseMap.h"
21#include "llvm/ADT/StringRef.h"
22#include "llvm/IR/GlobalValue.h"
25#include "llvm/Support/Endian.h"
28
29#include <bitset>
30#include <cstdint>
32namespace llvm {
33namespace yaml {
34template <typename T> struct CustomMappingTraits;
35} // namespace yaml
37namespace memprof {
41// The versions of the indexed MemProf format
43 // Version 2: Added a call stack table.
45 // Version 3: Added a radix tree for call stacks. Switched to linear IDs for
46 // frames and call stacks.
48 // Version 4: Added CalleeGuids to call site info.
50};
55// Verify that the minimum and maximum satisfy the obvious constraint.
57
59 return "___memprof_default_options_str";
60}
61
63 // Darwin linkage names are prefixed with an extra "_". See
64 // DataLayout::getGlobalPrefix().
66}
67
68enum class Meta : uint64_t {
69 Start = 0,
70#define MIBEntryDef(NameTag, Name, Type) NameTag,
72#undef MIBEntryDef
73 Size
74};
75
77
78// Returns the full schema currently in use.
80
81// Returns the schema consisting of the fields used for hot cold memory hinting.
83
84// Holds the actual MemInfoBlock data with all fields. Contents may be read or
85// written partially by providing an appropriate schema to the serialize and
86// deserialize methods.
89 explicit PortableMemInfoBlock(const MemInfoBlock &Block,
90 const MemProfSchema &IncomingSchema) {
91 for (const Meta Id : IncomingSchema)
92 Schema.set(llvm::to_underlying(Id));
93#define MIBEntryDef(NameTag, Name, Type) Name = Block.Name;
95#undef MIBEntryDef
96 }
98 PortableMemInfoBlock(const MemProfSchema &Schema, const unsigned char *Ptr) {
99 deserialize(Schema, Ptr);
102 // Read the contents of \p Ptr based on the \p Schema to populate the
103 // MemInfoBlock member.
104 void deserialize(const MemProfSchema &IncomingSchema,
105 const unsigned char *Ptr) {
106 using namespace support;
108 Schema.reset();
109 for (const Meta Id : IncomingSchema) {
110 switch (Id) {
111#define MIBEntryDef(NameTag, Name, Type) \
112 case Meta::Name: { \
113 Name = endian::readNext<Type, llvm::endianness::little>(Ptr); \
114 } break;
116#undef MIBEntryDef
117 default:
118 llvm_unreachable("Unknown meta type id, is the profile collected from "
119 "a newer version of the runtime?");
122 Schema.set(llvm::to_underlying(Id));
123 }
124 }
125
126 // Write the contents of the MemInfoBlock based on the \p Schema provided to
127 // the raw_ostream \p OS.
128 void serialize(const MemProfSchema &Schema, raw_ostream &OS) const {
129 using namespace support;
130
132 for (const Meta Id : Schema) {
133 switch (Id) {
134#define MIBEntryDef(NameTag, Name, Type) \
135 case Meta::Name: { \
136 LE.write<Type>(Name); \
137 } break;
139#undef MIBEntryDef
140 default:
141 llvm_unreachable("Unknown meta type id, invalid input?");
142 }
143 }
144 }
145
146 // Print out the contents of the MemInfoBlock in YAML format.
147 void printYAML(raw_ostream &OS) const {
148 OS << " MemInfoBlock:\n";
149#define MIBEntryDef(NameTag, Name, Type) \
150 OS << " " << #Name << ": " << Name << "\n";
152#undef MIBEntryDef
153 if (AccessHistogramSize > 0) {
154 OS << " " << "AccessHistogramValues" << ":";
155 for (uint32_t I = 0; I < AccessHistogramSize; ++I) {
156 OS << " " << ((uint64_t *)AccessHistogram)[I];
157 }
158 OS << "\n";
159 }
160 }
161
162 // Return the schema, only for unit tests.
163 std::bitset<llvm::to_underlying(Meta::Size)> getSchema() const {
164 return Schema;
165 }
166
167 // Define getters for each type which can be called by analyses.
168#define MIBEntryDef(NameTag, Name, Type) \
169 Type get##Name() const { \
170 assert(Schema[llvm::to_underlying(Meta::Name)]); \
171 return Name; \
172 }
174#undef MIBEntryDef
175
176 // Define setters for each type which can be called by the writer.
177#define MIBEntryDef(NameTag, Name, Type) \
178 void set##Name(Type NewVal) { \
179 assert(Schema[llvm::to_underlying(Meta::Name)]); \
180 Name = NewVal; \
181 }
183#undef MIBEntryDef
184
185 void clear() { *this = PortableMemInfoBlock(); }
186
188 if (Other.Schema != Schema)
189 return false;
190
191#define MIBEntryDef(NameTag, Name, Type) \
192 if (Schema[llvm::to_underlying(Meta::Name)] && \
193 Other.get##Name() != get##Name()) \
194 return false;
196#undef MIBEntryDef
197 return true;
198 }
199
201 return !operator==(Other);
202 }
203
204 static size_t serializedSize(const MemProfSchema &Schema) {
205 size_t Result = 0;
206
207 for (const Meta Id : Schema) {
208 switch (Id) {
209#define MIBEntryDef(NameTag, Name, Type) \
210 case Meta::Name: { \
211 Result += sizeof(Type); \
212 } break;
214#undef MIBEntryDef
215 default:
216 llvm_unreachable("Unknown meta type id, invalid input?");
217 }
218 }
219
220 return Result;
221 }
222
223 // Give YAML access to the individual MIB fields.
225
226private:
227 // The set of available fields, indexed by Meta::Name.
228 std::bitset<llvm::to_underlying(Meta::Size)> Schema;
229
230#define MIBEntryDef(NameTag, Name, Type) Type Name = Type();
231#include "llvm/ProfileData/MIBEntryDef.inc"
232#undef MIBEntryDef
233};
234
235// A type representing the id generated by hashing the contents of the Frame.
237// A type representing the id to index into the frame array.
239// Describes a call frame for a dynamic allocation context. The contents of
240// the frame are populated by symbolizing the stack depot call frame from the
241// compiler runtime.
242struct Frame {
243 // A uuid (uint64_t) identifying the function. It is obtained by
244 // llvm::md5(FunctionName) which returns the lower 64 bits.
246 // The symbol name for the function. Only populated in the Frame by the reader
247 // if requested during initialization. This field should not be serialized.
248 std::unique_ptr<std::string> SymbolName;
249 // The source line offset of the call from the beginning of parent function.
251 // The source column number of the call to help distinguish multiple calls
252 // on the same line.
254 // Whether the current frame is inlined.
255 bool IsInlineFrame = false;
256
257 Frame() = default;
258 Frame(Frame &&) = default;
259 Frame &operator=(Frame &&) = default;
260
261 Frame(const Frame &Other) {
262 Function = Other.Function;
263 SymbolName = Other.SymbolName
264 ? std::make_unique<std::string>(*Other.SymbolName)
265 : nullptr;
266 LineOffset = Other.LineOffset;
267 Column = Other.Column;
268 IsInlineFrame = Other.IsInlineFrame;
269 }
270
271 Frame(GlobalValue::GUID Hash, uint32_t Off, uint32_t Col, bool Inline)
272 : Function(Hash), LineOffset(Off), Column(Col), IsInlineFrame(Inline) {}
273
274 bool operator==(const Frame &Other) const {
275 // Ignore the SymbolName field to avoid a string compare. Comparing the
276 // function hash serves the same purpose.
277 return Other.Function == Function && Other.LineOffset == LineOffset &&
278 Other.Column == Column && Other.IsInlineFrame == IsInlineFrame;
279 }
280
282 Function = Other.Function;
283 SymbolName = Other.SymbolName
284 ? std::make_unique<std::string>(*Other.SymbolName)
285 : nullptr;
286 LineOffset = Other.LineOffset;
287 Column = Other.Column;
288 IsInlineFrame = Other.IsInlineFrame;
289 return *this;
290 }
291
292 bool operator!=(const Frame &Other) const { return !operator==(Other); }
293
294 bool hasSymbolName() const { return !!SymbolName; }
295
298 return *SymbolName;
299 }
300
301 std::string getSymbolNameOr(StringRef Alt) const {
302 return std::string(hasSymbolName() ? getSymbolName() : Alt);
303 }
304
305 // Write the contents of the frame to the ostream \p OS.
306 void serialize(raw_ostream &OS) const {
307 using namespace support;
308
310
311 // If the type of the GlobalValue::GUID changes, then we need to update
312 // the reader and the writer.
313 static_assert(std::is_same<GlobalValue::GUID, uint64_t>::value,
314 "Expect GUID to be uint64_t.");
315 LE.write<uint64_t>(Function);
316
317 LE.write<uint32_t>(LineOffset);
318 LE.write<uint32_t>(Column);
319 LE.write<bool>(IsInlineFrame);
320 }
321
322 // Read a frame from char data which has been serialized as little endian.
323 static Frame deserialize(const unsigned char *Ptr) {
324 using namespace support;
325
326 const uint64_t F =
328 const uint32_t L =
330 const uint32_t C =
333 return Frame(/*Function=*/F, /*LineOffset=*/L, /*Column=*/C,
334 /*IsInlineFrame=*/I);
335 }
336
337 // Returns the size of the frame information.
338 static constexpr size_t serializedSize() {
339 return sizeof(Frame::Function) + sizeof(Frame::LineOffset) +
340 sizeof(Frame::Column) + sizeof(Frame::IsInlineFrame);
341 }
342
343 // Print the frame information in YAML format.
344 void printYAML(raw_ostream &OS) const {
345 OS << " -\n"
346 << " Function: " << Function << "\n"
347 << " SymbolName: " << getSymbolNameOr("<None>") << "\n"
348 << " LineOffset: " << LineOffset << "\n"
349 << " Column: " << Column << "\n"
350 << " Inline: " << IsInlineFrame << "\n";
351 }
352};
353
354// A type representing the index into the table of call stacks.
356
357// A type representing the index into the call stack array.
359
360// Holds call site information with indexed frame contents.
362 // The call stack ID for this call site
364 // The GUIDs of the callees at this call site
366
372
374 return CSId == Other.CSId && CalleeGuids == Other.CalleeGuids;
375 }
376
378 return !operator==(Other);
379 }
380};
381
382// Holds allocation information in a space efficient format where frames are
383// represented using unique identifiers.
385 // The dynamic calling context for the allocation in bottom-up (leaf-to-root)
386 // order. Frame contents are stored out-of-line.
388 // The statistics obtained from the runtime for the allocation.
390
392 IndexedAllocationInfo(CallStackId CSId, const MemInfoBlock &MB,
393 const MemProfSchema &Schema = getFullSchema())
394 : CSId(CSId), Info(MB, Schema) {}
397
398 // Returns the size in bytes when this allocation info struct is serialized.
399 LLVM_ABI size_t serializedSize(const MemProfSchema &Schema,
400 IndexedVersion Version) const;
401
403 if (Other.Info != Info)
404 return false;
405
406 if (Other.CSId != CSId)
407 return false;
408 return true;
409 }
410
412 return !operator==(Other);
413 }
414};
415
416// Holds allocation information with frame contents inline. The type should
417// be used for temporary in-memory instances.
419 // Same as IndexedAllocationInfo::CallStack with the frame contents inline.
420 std::vector<Frame> CallStack;
421 // Same as IndexedAllocationInfo::Info;
423
424 AllocationInfo() = default;
425
426 void printYAML(raw_ostream &OS) const {
427 OS << " -\n";
428 OS << " Callstack:\n";
429 // TODO: Print out the frame on one line with to make it easier for deep
430 // callstacks once we have a test to check valid YAML is generated.
431 for (const Frame &F : CallStack) {
432 F.printYAML(OS);
433 }
434 Info.printYAML(OS);
435 }
436};
437
438// Holds the memprof profile information for a function. The internal
439// representation stores frame ids for efficiency. This representation should
440// be used in the profile conversion and manipulation tools.
442 // Memory allocation sites in this function for which we have memory
443 // profiling data.
445 // Holds call sites in this function which are part of some memory
446 // allocation context. We store this as a list of locations, each with its
447 // list of inline locations in bottom-up order i.e. from leaf to root. The
448 // inline location list may include additional entries, users should pick
449 // the last entry in the list with the same function GUID.
451
452 void clear() { *this = IndexedMemProfRecord(); }
453
455 // TODO: Filter out duplicates which may occur if multiple memprof
456 // profiles are merged together using llvm-profdata.
457 AllocSites.append(Other.AllocSites);
458 }
459
460 LLVM_ABI size_t serializedSize(const MemProfSchema &Schema,
461 IndexedVersion Version) const;
462
464 if (Other.AllocSites != AllocSites)
465 return false;
466
467 if (Other.CallSites != CallSites)
468 return false;
469 return true;
470 }
471
472 // Serializes the memprof records in \p Records to the ostream \p OS based
473 // on the schema provided in \p Schema.
474 LLVM_ABI void serialize(const MemProfSchema &Schema, raw_ostream &OS,
477 *MemProfCallStackIndexes = nullptr) const;
478
479 // Deserializes memprof records from the Buffer.
480 LLVM_ABI static IndexedMemProfRecord deserialize(const MemProfSchema &Schema,
481 const unsigned char *Buffer,
483
484 // Convert IndexedMemProfRecord to MemProfRecord. Callback is used to
485 // translate CallStackId to call stacks with frames inline.
486 LLVM_ABI MemProfRecord toMemProfRecord(
487 llvm::function_ref<std::vector<Frame>(const CallStackId)> Callback) const;
488};
489
490// Returns the GUID for the function name after canonicalization. For
491// memprof, we remove any .llvm suffix added by LTO. MemProfRecords are
492// mapped to functions using this GUID.
493LLVM_ABI GlobalValue::GUID getGUID(const StringRef FunctionName);
494
495// Holds call site information with frame contents inline.
497 // The frames in the call stack
498 std::vector<Frame> Frames;
499
500 // The GUIDs of the callees at this call site
502
503 CallSiteInfo() = default;
504 CallSiteInfo(std::vector<Frame> Frames) : Frames(std::move(Frames)) {}
508
509 bool operator==(const CallSiteInfo &Other) const {
510 return Frames == Other.Frames && CalleeGuids == Other.CalleeGuids;
511 }
512
513 bool operator!=(const CallSiteInfo &Other) const {
514 return !operator==(Other);
515 }
516};
517
518// Holds the memprof profile information for a function. The internal
519// representation stores frame contents inline. This representation should
520// be used for small amount of temporary, in memory instances.
522 // Same as IndexedMemProfRecord::AllocSites with frame contents inline.
524 // Same as IndexedMemProfRecord::CallSites with frame contents inline.
526
527 MemProfRecord() = default;
528
529 // Prints out the contents of the memprof record in YAML.
530 void print(llvm::raw_ostream &OS) const {
531 if (!AllocSites.empty()) {
532 OS << " AllocSites:\n";
533 for (const AllocationInfo &N : AllocSites)
534 N.printYAML(OS);
535 }
536
537 if (!CallSites.empty()) {
538 OS << " CallSites:\n";
539 for (const CallSiteInfo &CS : CallSites) {
540 for (const Frame &F : CS.Frames) {
541 OS << " -\n";
542 F.printYAML(OS);
543 }
544 }
545 }
546 }
547};
548
549// Reads a memprof schema from a buffer. All entries in the buffer are
550// interpreted as uint64_t. The first entry in the buffer denotes the number of
551// ids in the schema. Subsequent entries are integers which map to memprof::Meta
552// enum class entries. After successfully reading the schema, the pointer is one
553// byte past the schema contents.
555readMemProfSchema(const unsigned char *&Buffer);
556
557// Trait for reading IndexedMemProfRecord data from the on-disk hash table.
559public:
565
568 : Version(V), Schema(S) {}
569
570 static bool EqualKey(uint64_t A, uint64_t B) { return A == B; }
571 static uint64_t GetInternalKey(uint64_t K) { return K; }
572 static uint64_t GetExternalKey(uint64_t K) { return K; }
573
575
576 static std::pair<offset_type, offset_type>
577 ReadKeyDataLength(const unsigned char *&D) {
578 using namespace support;
579
580 offset_type KeyLen =
582 offset_type DataLen =
584 return std::make_pair(KeyLen, DataLen);
585 }
586
587 uint64_t ReadKey(const unsigned char *D, offset_type /*Unused*/) {
588 using namespace support;
590 }
591
592 data_type ReadData(uint64_t K, const unsigned char *D,
593 offset_type /*Unused*/) {
594 Record = IndexedMemProfRecord::deserialize(Schema, D, Version);
595 return Record;
596 }
597
598private:
599 // Holds the MemProf version.
601 // Holds the memprof schema used to deserialize records.
602 MemProfSchema Schema;
603 // Holds the records from one function deserialized from the indexed format.
605};
606
607// Trait for writing IndexedMemProfRecord data to the on-disk hash table.
609public:
612
615
618
619private:
620 // Pointer to the memprof schema to use for the generator.
621 const MemProfSchema *Schema;
622 // The MemProf version to use for the serialization.
623 IndexedVersion Version;
624
625 // Mappings from CallStackId to the indexes into the call stack array.
626 llvm::DenseMap<CallStackId, LinearCallStackId> *MemProfCallStackIndexes;
627
628public:
629 // We do not support the default constructor, which does not set Version.
632 const MemProfSchema *Schema, IndexedVersion V,
633 llvm::DenseMap<CallStackId, LinearCallStackId> *MemProfCallStackIndexes)
634 : Schema(Schema), Version(V),
635 MemProfCallStackIndexes(MemProfCallStackIndexes) {}
636
638
639 std::pair<offset_type, offset_type>
641 using namespace support;
642
644 offset_type N = sizeof(K);
645 LE.write<offset_type>(N);
646 offset_type M = V.serializedSize(*Schema, Version);
647 LE.write<offset_type>(M);
648 return std::make_pair(N, M);
649 }
650
651 void EmitKey(raw_ostream &Out, key_type_ref K, offset_type /*Unused*/) {
652 using namespace support;
654 LE.write<uint64_t>(K);
655 }
656
658 offset_type /*Unused*/) {
659 assert(Schema != nullptr && "MemProf schema is not initialized!");
660 V.serialize(*Schema, Out, Version, MemProfCallStackIndexes);
661 // Clear the IndexedMemProfRecord which results in clearing/freeing its
662 // vectors of allocs and callsites. This is owned by the associated on-disk
663 // hash table, but unused after this point. See also the comment added to
664 // the client which constructs the on-disk hash table for this trait.
665 V.clear();
666 }
667};
668
669// Trait for writing frame mappings to the on-disk hash table.
671public:
674
677
680
682
683 static std::pair<offset_type, offset_type>
685 using namespace support;
687 offset_type N = sizeof(K);
688 LE.write<offset_type>(N);
689 offset_type M = V.serializedSize();
690 LE.write<offset_type>(M);
691 return std::make_pair(N, M);
692 }
693
694 void EmitKey(raw_ostream &Out, key_type_ref K, offset_type /*Unused*/) {
695 using namespace support;
697 LE.write<key_type>(K);
698 }
699
701 offset_type /*Unused*/) {
702 V.serialize(Out);
703 }
704};
705
706// Trait for reading frame mappings from the on-disk hash table.
708public:
709 using data_type = const Frame;
714
716 return A == B;
717 }
720
722
723 static std::pair<offset_type, offset_type>
724 ReadKeyDataLength(const unsigned char *&D) {
725 using namespace support;
726
727 offset_type KeyLen =
729 offset_type DataLen =
731 return std::make_pair(KeyLen, DataLen);
732 }
733
734 uint64_t ReadKey(const unsigned char *D, offset_type /*Unused*/) {
735 using namespace support;
737 }
738
739 data_type ReadData(uint64_t K, const unsigned char *D,
740 offset_type /*Unused*/) {
741 return Frame::deserialize(D);
742 }
743};
744
745// Trait for writing call stacks to the on-disk hash table.
747public:
750
753
756
758
759 static std::pair<offset_type, offset_type>
761 using namespace support;
763 // We do not explicitly emit the key length because it is a constant.
764 offset_type N = sizeof(K);
765 offset_type M = sizeof(FrameId) * V.size();
766 LE.write<offset_type>(M);
767 return std::make_pair(N, M);
768 }
769
770 void EmitKey(raw_ostream &Out, key_type_ref K, offset_type /*Unused*/) {
771 using namespace support;
773 LE.write<key_type>(K);
774 }
775
777 offset_type /*Unused*/) {
778 using namespace support;
780 // Emit the frames. We do not explicitly emit the length of the vector
781 // because it can be inferred from the data length.
782 for (FrameId F : V)
783 LE.write<FrameId>(F);
784 }
785};
786
787// Trait for reading call stack mappings from the on-disk hash table.
789public:
795
797 return A == B;
798 }
801
803
804 static std::pair<offset_type, offset_type>
805 ReadKeyDataLength(const unsigned char *&D) {
806 using namespace support;
807
808 // We do not explicitly read the key length because it is a constant.
809 offset_type KeyLen = sizeof(external_key_type);
810 offset_type DataLen =
812 return std::make_pair(KeyLen, DataLen);
813 }
814
815 uint64_t ReadKey(const unsigned char *D, offset_type /*Unused*/) {
816 using namespace support;
818 }
819
820 data_type ReadData(uint64_t K, const unsigned char *D, offset_type Length) {
821 using namespace support;
823 // Derive the number of frames from the data length.
824 uint64_t NumFrames = Length / sizeof(FrameId);
825 assert(Length % sizeof(FrameId) == 0);
826 CS.reserve(NumFrames);
827 for (size_t I = 0; I != NumFrames; ++I) {
829 CS.push_back(F);
830 }
831 return CS;
832 }
833};
834
837
838 bool operator<(const LineLocation &O) const {
839 return std::tie(LineOffset, Column) < std::tie(O.LineOffset, O.Column);
840 }
841
842 bool operator==(const LineLocation &O) const {
843 return LineOffset == O.LineOffset && Column == O.Column;
844 }
845
846 bool operator!=(const LineLocation &O) const {
847 return LineOffset != O.LineOffset || Column != O.Column;
848 }
849
850 uint64_t getHashCode() const { return ((uint64_t)Column << 32) | LineOffset; }
851
854};
855
856// A pair of a call site location and its corresponding callee GUID.
857using CallEdgeTy = std::pair<LineLocation, uint64_t>;
858} // namespace memprof
859
860template <> struct DenseMapInfo<memprof::LineLocation> {
861 static unsigned getHashValue(const memprof::LineLocation &Val) {
863 }
864
866 const memprof::LineLocation &RHS) {
867 return LHS == RHS;
868 }
869};
870
871} // namespace llvm
872#endif // LLVM_PROFILEDATA_MEMPROF_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:215
This file defines the DenseMap class.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
bool operator==(const MergedFunctionsInfo &LHS, const MergedFunctionsInfo &RHS)
This file contains library features backported from future STL versions.
This file defines the SmallVector class.
Value * RHS
Value * LHS
Tagged union holding either a T or a Error.
Definition Error.h:485
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.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
Definition StringRef.h:635
An efficient, type-erasing, non-owning reference to a callable.
static uint64_t GetInternalKey(internal_key_type K)
Definition MemProf.h:799
hash_value_type ComputeHash(internal_key_type K)
Definition MemProf.h:802
static bool EqualKey(internal_key_type A, internal_key_type B)
Definition MemProf.h:796
static std::pair< offset_type, offset_type > ReadKeyDataLength(const unsigned char *&D)
Definition MemProf.h:805
const llvm::SmallVector< FrameId > data_type
Definition MemProf.h:790
uint64_t ReadKey(const unsigned char *D, offset_type)
Definition MemProf.h:815
data_type ReadData(uint64_t K, const unsigned char *D, offset_type Length)
Definition MemProf.h:820
static uint64_t GetExternalKey(external_key_type K)
Definition MemProf.h:800
llvm::SmallVector< FrameId > & data_type_ref
Definition MemProf.h:752
static hash_value_type ComputeHash(key_type_ref K)
Definition MemProf.h:757
static std::pair< offset_type, offset_type > EmitKeyDataLength(raw_ostream &Out, key_type_ref K, data_type_ref V)
Definition MemProf.h:760
void EmitData(raw_ostream &Out, key_type_ref, data_type_ref V, offset_type)
Definition MemProf.h:776
llvm::SmallVector< FrameId > data_type
Definition MemProf.h:751
void EmitKey(raw_ostream &Out, key_type_ref K, offset_type)
Definition MemProf.h:770
data_type ReadData(uint64_t K, const unsigned char *D, offset_type)
Definition MemProf.h:739
static uint64_t GetExternalKey(external_key_type K)
Definition MemProf.h:719
static bool EqualKey(internal_key_type A, internal_key_type B)
Definition MemProf.h:715
static uint64_t GetInternalKey(internal_key_type K)
Definition MemProf.h:718
static std::pair< offset_type, offset_type > ReadKeyDataLength(const unsigned char *&D)
Definition MemProf.h:724
hash_value_type ComputeHash(internal_key_type K)
Definition MemProf.h:721
uint64_t ReadKey(const unsigned char *D, offset_type)
Definition MemProf.h:734
static hash_value_type ComputeHash(key_type_ref K)
Definition MemProf.h:681
void EmitKey(raw_ostream &Out, key_type_ref K, offset_type)
Definition MemProf.h:694
void EmitData(raw_ostream &Out, key_type_ref, data_type_ref V, offset_type)
Definition MemProf.h:700
static std::pair< offset_type, offset_type > EmitKeyDataLength(raw_ostream &Out, key_type_ref K, data_type_ref V)
Definition MemProf.h:684
const IndexedMemProfRecord & data_type
Definition MemProf.h:560
static bool EqualKey(uint64_t A, uint64_t B)
Definition MemProf.h:570
uint64_t ReadKey(const unsigned char *D, offset_type)
Definition MemProf.h:587
data_type ReadData(uint64_t K, const unsigned char *D, offset_type)
Definition MemProf.h:592
static std::pair< offset_type, offset_type > ReadKeyDataLength(const unsigned char *&D)
Definition MemProf.h:577
static uint64_t GetInternalKey(uint64_t K)
Definition MemProf.h:571
hash_value_type ComputeHash(uint64_t K)
Definition MemProf.h:574
static uint64_t GetExternalKey(uint64_t K)
Definition MemProf.h:572
RecordLookupTrait(IndexedVersion V, const MemProfSchema &S)
Definition MemProf.h:567
static hash_value_type ComputeHash(key_type_ref K)
Definition MemProf.h:637
RecordWriterTrait(const MemProfSchema *Schema, IndexedVersion V, llvm::DenseMap< CallStackId, LinearCallStackId > *MemProfCallStackIndexes)
Definition MemProf.h:631
IndexedMemProfRecord data_type
Definition MemProf.h:613
std::pair< offset_type, offset_type > EmitKeyDataLength(raw_ostream &Out, key_type_ref K, data_type_ref V)
Definition MemProf.h:640
IndexedMemProfRecord & data_type_ref
Definition MemProf.h:614
void EmitKey(raw_ostream &Out, key_type_ref K, offset_type)
Definition MemProf.h:651
void EmitData(raw_ostream &Out, key_type_ref, data_type_ref V, offset_type)
Definition MemProf.h:657
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
constexpr uint64_t MaximumSupportedVersion
Definition MemProf.h:53
uint32_t LinearCallStackId
Definition MemProf.h:358
LLVM_ABI MemProfSchema getHotColdSchema()
Definition MemProf.cpp:19
llvm::StringRef getMemprofOptionsSymbolName()
Definition MemProf.h:62
llvm::SmallVector< Meta, static_cast< int >(Meta::Size)> MemProfSchema
Definition MemProf.h:76
constexpr uint64_t MinimumSupportedVersion
Definition MemProf.h:52
std::pair< LineLocation, uint64_t > CallEdgeTy
Definition MemProf.h:857
LLVM_ABI MemProfSchema getFullSchema()
Definition MemProf.cpp:11
LLVM_ABI GlobalValue::GUID getGUID(const StringRef FunctionName)
Definition MemProf.cpp:344
LLVM_ABI Expected< MemProfSchema > readMemProfSchema(const unsigned char *&Buffer)
Definition MemProf.cpp:360
uint32_t LinearFrameId
Definition MemProf.h:238
uint64_t CallStackId
Definition MemProf.h:355
llvm::StringRef getMemprofOptionsSymbolDarwinLinkageName()
Definition MemProf.h:58
uint64_t FrameId
Definition MemProf.h:236
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.
Definition Endian.h:81
This is an optimization pass for GlobalISel generic memory operations.
@ Length
Definition DWP.cpp:573
constexpr std::underlying_type_t< Enum > to_underlying(Enum E)
Returns underlying integer value of an enum.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
@ Other
Any other memory.
Definition ModRef.h:68
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1917
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:860
#define N
static unsigned getHashValue(const memprof::LineLocation &Val)
Definition MemProf.h:861
static bool isEqual(const memprof::LineLocation &LHS, const memprof::LineLocation &RHS)
Definition MemProf.h:865
An information struct used to provide DenseMap with the various necessary components for a given valu...
std::vector< Frame > CallStack
Definition MemProf.h:420
PortableMemInfoBlock Info
Definition MemProf.h:422
void printYAML(raw_ostream &OS) const
Definition MemProf.h:426
bool operator!=(const CallSiteInfo &Other) const
Definition MemProf.h:513
CallSiteInfo(std::vector< Frame > Frames)
Definition MemProf.h:504
std::vector< Frame > Frames
Definition MemProf.h:498
bool operator==(const CallSiteInfo &Other) const
Definition MemProf.h:509
SmallVector< GlobalValue::GUID, 1 > CalleeGuids
Definition MemProf.h:501
CallSiteInfo(std::vector< Frame > Frames, SmallVector< GlobalValue::GUID, 1 > CalleeGuids)
Definition MemProf.h:505
Frame & operator=(const Frame &Other)
Definition MemProf.h:281
Frame(const Frame &Other)
Definition MemProf.h:261
static constexpr size_t serializedSize()
Definition MemProf.h:338
void printYAML(raw_ostream &OS) const
Definition MemProf.h:344
GlobalValue::GUID Function
Definition MemProf.h:245
void serialize(raw_ostream &OS) const
Definition MemProf.h:306
bool hasSymbolName() const
Definition MemProf.h:294
std::string getSymbolNameOr(StringRef Alt) const
Definition MemProf.h:301
Frame(Frame &&)=default
Frame & operator=(Frame &&)=default
StringRef getSymbolName() const
Definition MemProf.h:296
bool operator==(const Frame &Other) const
Definition MemProf.h:274
bool operator!=(const Frame &Other) const
Definition MemProf.h:292
static Frame deserialize(const unsigned char *Ptr)
Definition MemProf.h:323
Frame(GlobalValue::GUID Hash, uint32_t Off, uint32_t Col, bool Inline)
Definition MemProf.h:271
uint32_t LineOffset
Definition MemProf.h:250
std::unique_ptr< std::string > SymbolName
Definition MemProf.h:248
IndexedAllocationInfo(CallStackId CSId, const MemInfoBlock &MB, const MemProfSchema &Schema=getFullSchema())
Definition MemProf.h:392
bool operator==(const IndexedAllocationInfo &Other) const
Definition MemProf.h:402
bool operator!=(const IndexedAllocationInfo &Other) const
Definition MemProf.h:411
IndexedAllocationInfo(CallStackId CSId, const PortableMemInfoBlock &MB)
Definition MemProf.h:395
bool operator!=(const IndexedCallSiteInfo &Other) const
Definition MemProf.h:377
IndexedCallSiteInfo(CallStackId CSId, SmallVector< GlobalValue::GUID, 1 > CalleeGuids)
Definition MemProf.h:369
IndexedCallSiteInfo(CallStackId CSId)
Definition MemProf.h:368
SmallVector< GlobalValue::GUID, 1 > CalleeGuids
Definition MemProf.h:365
bool operator==(const IndexedCallSiteInfo &Other) const
Definition MemProf.h:373
llvm::SmallVector< IndexedAllocationInfo > AllocSites
Definition MemProf.h:444
static LLVM_ABI IndexedMemProfRecord deserialize(const MemProfSchema &Schema, const unsigned char *Buffer, IndexedVersion Version)
Definition MemProf.cpp:309
bool operator==(const IndexedMemProfRecord &Other) const
Definition MemProf.h:463
void merge(const IndexedMemProfRecord &Other)
Definition MemProf.h:454
llvm::SmallVector< IndexedCallSiteInfo > CallSites
Definition MemProf.h:450
LineLocation(uint32_t L, uint32_t D)
Definition MemProf.h:836
bool operator!=(const LineLocation &O) const
Definition MemProf.h:846
bool operator==(const LineLocation &O) const
Definition MemProf.h:842
bool operator<(const LineLocation &O) const
Definition MemProf.h:838
uint64_t getHashCode() const
Definition MemProf.h:850
llvm::SmallVector< CallSiteInfo > CallSites
Definition MemProf.h:525
llvm::SmallVector< AllocationInfo > AllocSites
Definition MemProf.h:523
void print(llvm::raw_ostream &OS) const
Definition MemProf.h:530
bool operator!=(const PortableMemInfoBlock &Other) const
Definition MemProf.h:200
void deserialize(const MemProfSchema &IncomingSchema, const unsigned char *Ptr)
Definition MemProf.h:104
uint64_t uint64_t uint32_t uint32_t uint64_t uint32_t uint32_t uint32_t uint32_t uint64_t uint32_t uint32_t AccessHistogramSize
Definition MemProf.h:55
std::bitset< llvm::to_underlying(Meta::Size)> getSchema() const
Definition MemProf.h:163
static size_t serializedSize(const MemProfSchema &Schema)
Definition MemProf.h:204
void printYAML(raw_ostream &OS) const
Definition MemProf.h:147
void serialize(const MemProfSchema &Schema, raw_ostream &OS) const
Definition MemProf.h:128
PortableMemInfoBlock(const MemInfoBlock &Block, const MemProfSchema &IncomingSchema)
Definition MemProf.h:89
uint64_t uint64_t uint32_t uint32_t uint64_t uint32_t uint32_t uint32_t uint32_t uint64_t uint32_t uint32_t uint32_t uint32_t uint64_t uint64_t uint32_t uint32_t uint32_t uint32_t uint32_t uint32_t uint64_t uint32_t uint64_t uint32_t uintptr_t void clear()
Definition MemProf.h:185
bool operator==(const PortableMemInfoBlock &Other) const
Definition MemProf.h:187
uint64_t uint64_t uint32_t uint32_t uint64_t uint32_t uint32_t uint32_t uint32_t uint64_t uint32_t uint32_t uint32_t uint32_t uint64_t uint64_t uint32_t uint32_t uint32_t uint32_t uint32_t uint32_t uint64_t uint32_t uint64_t uint32_t AccessHistogram
Definition MemProf.h:121
Represents the relative location of an instruction.
Definition SampleProf.h:289
Adapter to write values to a stream in a particular byte order.
This class should be specialized by any type that needs to be converted to/from a YAML mapping in the...
Definition YAMLTraits.h:274