LLVM: include/llvm/ProfileData/MemProf.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14#ifndef LLVM_PROFILEDATA_MEMPROF_H
15#define LLVM_PROFILEDATA_MEMPROF_H
16
28
29#include
30#include
34template struct CustomMappingTraits;
35}
57
59 return "___memprof_default_options_str";
60}
61
67
70#define MIBEntryDef(NameTag, Name, Type) NameTag,
72#undef MIBEntryDef
74};
75
77
78
80
81
83
84
85
86
91 for (const Meta Id : IncomingSchema)
93#define MIBEntryDef(NameTag, Name, Type) Name = Block.Name;
95#undef MIBEntryDef
105 const unsigned char *Ptr) {
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); \
116#undef MIBEntryDef
119 "a newer version of the runtime?");
123 }
124 }
125
126
127
130
132 for (const Meta Id : Schema) {
133 switch (Id) {
134#define MIBEntryDef(NameTag, Name, Type) \
135 case Meta::Name: { \
136 LE.write(Name); \
137 } break;
139#undef MIBEntryDef
140 default:
142 }
143 }
144 }
145
146
148 OS << " MemInfoBlock:\n";
149#define MIBEntryDef(NameTag, Name, Type) \
150 OS << " " << #Name << ": " << Name << "\n";
152#undef MIBEntryDef
154 OS << " " << "AccessHistogramValues" << ":";
157 }
158 OS << "\n";
159 }
160 }
161
162
166
167
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
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
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
203
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:
217 }
218 }
219
220 return Result;
221 }
222
223
225
226private:
227
228 std::bitsetllvm::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
237
239
240
241
243
244
246
247
249
251
252
254
256
261 ? std::make_uniquestd::string(*Other.SymbolName)
262 : nullptr;
266 }
267
270
277
281 ? std::make_uniquestd::string(*Other.SymbolName)
282 : nullptr;
286 return *this;
287 }
288
290
292
297
301
302
305
307
308
309
310 static_assert(std::is_same<GlobalValue::GUID, uint64_t>::value,
311 "Expect GUID to be uint64_t.");
313
317 }
318
319
322
331 I);
332 }
333
334
339
340
342 OS << " -\n"
343 << " Function: " << Function << "\n"
345 << " LineOffset: " << LineOffset << "\n"
346 << " Column: " << Column << "\n"
348 }
349};
350
351
353
354
356
357
359
361
363
369
373
377};
378
379
380
382
383
385
387
394
395
398
401 return false;
402
404 return false;
405 return true;
406 }
407
411};
412
413
414
416
418
420
422
424 OS << " -\n";
425 OS << " Callstack:\n";
426
427
429 F.printYAML(OS);
430 }
431 Info.printYAML(OS);
432 }
433};
434
435
436
437
439
440
442
443
444
445
446
448
450
456
459
462 return false;
463
465 return false;
466 return true;
467 }
468
469
470
474 *MemProfCallStackIndexes = nullptr) const;
475
476
478 const unsigned char *Buffer,
480
481
482
485};
486
487
488
489
491
492
494
496
497
499
505
509
513};
514
515
516
517
519
521
523
525
526
529 OS << " AllocSites:\n";
531 N.printYAML(OS);
532 }
533
535 OS << " CallSites:\n";
537 for (const Frame &F : CS.Frames) {
538 OS << " -\n";
539 F.printYAML(OS);
540 }
541 }
542 }
543 }
544};
545
546
547
548
549
550
553
554
556public:
562
565 : Version(V), Schema(S) {}
566
570
572
573 static std::pair<offset_type, offset_type>
576
581 return std::make_pair(KeyLen, DataLen);
582 }
583
588
594
595private:
596
598
600
602};
603
604
606public:
609
612
615
616private:
617
619
621
622
624
625public:
626
631 : Schema(Schema), Version(V),
632 MemProfCallStackIndexes(MemProfCallStackIndexes) {}
633
635
636 std::pair<offset_type, offset_type>
639
643 offset_type M = V.serializedSize(*Schema, Version);
645 return std::make_pair(N, M);
646 }
647
653
656 assert(Schema != nullptr && "MemProf schema is not initialized!");
657 V.serialize(*Schema, Out, Version, MemProfCallStackIndexes);
658
659
660
661
662 V.clear();
663 }
664};
665
666
668public:
671
674
677
679
680 static std::pair<offset_type, offset_type>
688 return std::make_pair(N, M);
689 }
690
696
699 V.serialize(Out);
700 }
701};
702
703
705public:
711
717
719
720 static std::pair<offset_type, offset_type>
723
728 return std::make_pair(KeyLen, DataLen);
729 }
730
735
740};
741
742
744public:
747
750
753
755
756 static std::pair<offset_type, offset_type>
760
764 return std::make_pair(N, M);
765 }
766
772
782};
783
784
786public:
792
798
800
801 static std::pair<offset_type, offset_type>
804
805
809 return std::make_pair(KeyLen, DataLen);
810 }
811
816
820
824 for (size_t I = 0; I != NumFrames; ++I) {
827 }
828 return CS;
829 }
830};
831
834
836 return std::tie(LineOffset, Column) < std::tie(O.LineOffset, O.Column);
837 }
838
842
846
848
851};
852
853
854using CallEdgeTy = std::pair<LineLocation, uint64_t>;
855}
856}
857#endif
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")
static StringRef getSymbolName(SymbolKind SymKind)
This file defines the DenseMap class.
bool operator==(const MergedFunctionsInfo &LHS, const MergedFunctionsInfo &RHS)
This file contains library features backported from future STL versions.
This file defines the SmallVector class.
Tagged union holding either a T or a Error.
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.
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
An efficient, type-erasing, non-owning reference to a callable.
uint64_t offset_type
Definition MemProf.h:791
CallStackId internal_key_type
Definition MemProf.h:788
static uint64_t GetInternalKey(internal_key_type K)
Definition MemProf.h:796
hash_value_type ComputeHash(internal_key_type K)
Definition MemProf.h:799
static bool EqualKey(internal_key_type A, internal_key_type B)
Definition MemProf.h:793
static std::pair< offset_type, offset_type > ReadKeyDataLength(const unsigned char *&D)
Definition MemProf.h:802
const llvm::SmallVector< FrameId > data_type
Definition MemProf.h:787
CallStackId external_key_type
Definition MemProf.h:789
uint64_t ReadKey(const unsigned char *D, offset_type)
Definition MemProf.h:812
data_type ReadData(uint64_t K, const unsigned char *D, offset_type Length)
Definition MemProf.h:817
CallStackId hash_value_type
Definition MemProf.h:790
static uint64_t GetExternalKey(external_key_type K)
Definition MemProf.h:797
llvm::SmallVector< FrameId > & data_type_ref
Definition MemProf.h:749
static hash_value_type ComputeHash(key_type_ref K)
Definition MemProf.h:754
CallStackId key_type
Definition MemProf.h:745
static std::pair< offset_type, offset_type > EmitKeyDataLength(raw_ostream &Out, key_type_ref K, data_type_ref V)
Definition MemProf.h:757
uint64_t offset_type
Definition MemProf.h:752
void EmitData(raw_ostream &Out, key_type_ref, data_type_ref V, offset_type)
Definition MemProf.h:773
CallStackId hash_value_type
Definition MemProf.h:751
llvm::SmallVector< FrameId > data_type
Definition MemProf.h:748
CallStackId key_type_ref
Definition MemProf.h:746
void EmitKey(raw_ostream &Out, key_type_ref K, offset_type)
Definition MemProf.h:767
FrameId external_key_type
Definition MemProf.h:708
data_type ReadData(uint64_t K, const unsigned char *D, offset_type)
Definition MemProf.h:736
static uint64_t GetExternalKey(external_key_type K)
Definition MemProf.h:716
static bool EqualKey(internal_key_type A, internal_key_type B)
Definition MemProf.h:712
FrameId internal_key_type
Definition MemProf.h:707
const Frame data_type
Definition MemProf.h:706
uint64_t offset_type
Definition MemProf.h:710
static uint64_t GetInternalKey(internal_key_type K)
Definition MemProf.h:715
static std::pair< offset_type, offset_type > ReadKeyDataLength(const unsigned char *&D)
Definition MemProf.h:721
hash_value_type ComputeHash(internal_key_type K)
Definition MemProf.h:718
uint64_t ReadKey(const unsigned char *D, offset_type)
Definition MemProf.h:731
FrameId hash_value_type
Definition MemProf.h:709
static hash_value_type ComputeHash(key_type_ref K)
Definition MemProf.h:678
void EmitKey(raw_ostream &Out, key_type_ref K, offset_type)
Definition MemProf.h:691
uint64_t offset_type
Definition MemProf.h:676
void EmitData(raw_ostream &Out, key_type_ref, data_type_ref V, offset_type)
Definition MemProf.h:697
Frame data_type
Definition MemProf.h:672
Frame & data_type_ref
Definition MemProf.h:673
FrameId hash_value_type
Definition MemProf.h:675
FrameId key_type_ref
Definition MemProf.h:670
FrameId key_type
Definition MemProf.h:669
static std::pair< offset_type, offset_type > EmitKeyDataLength(raw_ostream &Out, key_type_ref K, data_type_ref V)
Definition MemProf.h:681
const IndexedMemProfRecord & data_type
Definition MemProf.h:557
static bool EqualKey(uint64_t A, uint64_t B)
Definition MemProf.h:567
uint64_t ReadKey(const unsigned char *D, offset_type)
Definition MemProf.h:584
uint64_t offset_type
Definition MemProf.h:561
data_type ReadData(uint64_t K, const unsigned char *D, offset_type)
Definition MemProf.h:589
uint64_t hash_value_type
Definition MemProf.h:560
static std::pair< offset_type, offset_type > ReadKeyDataLength(const unsigned char *&D)
Definition MemProf.h:574
uint64_t internal_key_type
Definition MemProf.h:558
static uint64_t GetInternalKey(uint64_t K)
Definition MemProf.h:568
hash_value_type ComputeHash(uint64_t K)
Definition MemProf.h:571
static uint64_t GetExternalKey(uint64_t K)
Definition MemProf.h:569
uint64_t external_key_type
Definition MemProf.h:559
RecordLookupTrait(IndexedVersion V, const MemProfSchema &S)
Definition MemProf.h:564
RecordLookupTrait()=delete
static hash_value_type ComputeHash(key_type_ref K)
Definition MemProf.h:634
RecordWriterTrait(const MemProfSchema *Schema, IndexedVersion V, llvm::DenseMap< CallStackId, LinearCallStackId > *MemProfCallStackIndexes)
Definition MemProf.h:628
IndexedMemProfRecord data_type
Definition MemProf.h:610
uint64_t key_type
Definition MemProf.h:607
uint64_t offset_type
Definition MemProf.h:614
std::pair< offset_type, offset_type > EmitKeyDataLength(raw_ostream &Out, key_type_ref K, data_type_ref V)
Definition MemProf.h:637
uint64_t key_type_ref
Definition MemProf.h:608
uint64_t hash_value_type
Definition MemProf.h:613
RecordWriterTrait()=delete
IndexedMemProfRecord & data_type_ref
Definition MemProf.h:611
void EmitKey(raw_ostream &Out, key_type_ref K, offset_type)
Definition MemProf.h:648
void EmitData(raw_ostream &Out, key_type_ref, data_type_ref V, offset_type)
Definition MemProf.h:654
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
IndexedVersion
Definition MemProf.h:42
@ Version4
Definition MemProf.h:49
@ Version2
Definition MemProf.h:44
@ Version3
Definition MemProf.h:47
constexpr uint64_t MaximumSupportedVersion
Definition MemProf.h:53
uint32_t LinearCallStackId
Definition MemProf.h:355
LLVM_ABI MemProfSchema getHotColdSchema()
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:854
LLVM_ABI MemProfSchema getFullSchema()
LLVM_ABI GlobalValue::GUID getGUID(const StringRef FunctionName)
LLVM_ABI Expected< MemProfSchema > readMemProfSchema(const unsigned char *&Buffer)
Meta
Definition MemProf.h:68
@ Start
Definition MemProf.h:69
uint32_t LinearFrameId
Definition MemProf.h:238
uint64_t CallStackId
Definition MemProf.h:352
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.
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr uintptr_t uintptr_t Version
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...
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Implement std::hash so that hash_code can be used in STL containers.
std::vector< Frame > CallStack
Definition MemProf.h:417
PortableMemInfoBlock Info
Definition MemProf.h:419
void printYAML(raw_ostream &OS) const
Definition MemProf.h:423
bool operator!=(const CallSiteInfo &Other) const
Definition MemProf.h:510
CallSiteInfo(std::vector< Frame > Frames)
Definition MemProf.h:501
std::vector< Frame > Frames
Definition MemProf.h:495
bool operator==(const CallSiteInfo &Other) const
Definition MemProf.h:506
SmallVector< GlobalValue::GUID, 1 > CalleeGuids
Definition MemProf.h:498
CallSiteInfo(std::vector< Frame > Frames, SmallVector< GlobalValue::GUID, 1 > CalleeGuids)
Definition MemProf.h:502
Frame & operator=(const Frame &Other)
Definition MemProf.h:278
Frame(const Frame &Other)
Definition MemProf.h:258
static constexpr size_t serializedSize()
Definition MemProf.h:335
void printYAML(raw_ostream &OS) const
Definition MemProf.h:341
uint32_t Column
Definition MemProf.h:253
GlobalValue::GUID Function
Definition MemProf.h:245
void serialize(raw_ostream &OS) const
Definition MemProf.h:303
bool hasSymbolName() const
Definition MemProf.h:291
bool IsInlineFrame
Definition MemProf.h:255
std::string getSymbolNameOr(StringRef Alt) const
Definition MemProf.h:298
StringRef getSymbolName() const
Definition MemProf.h:293
bool operator==(const Frame &Other) const
Definition MemProf.h:271
bool operator!=(const Frame &Other) const
Definition MemProf.h:289
static Frame deserialize(const unsigned char *Ptr)
Definition MemProf.h:320
Frame(GlobalValue::GUID Hash, uint32_t Off, uint32_t Col, bool Inline)
Definition MemProf.h:268
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:389
bool operator==(const IndexedAllocationInfo &Other) const
Definition MemProf.h:399
bool operator!=(const IndexedAllocationInfo &Other) const
Definition MemProf.h:408
PortableMemInfoBlock Info
Definition MemProf.h:386
IndexedAllocationInfo(CallStackId CSId, const PortableMemInfoBlock &MB)
Definition MemProf.h:392
CallStackId CSId
Definition MemProf.h:384
IndexedAllocationInfo()=default
bool operator!=(const IndexedCallSiteInfo &Other) const
Definition MemProf.h:374
IndexedCallSiteInfo(CallStackId CSId, SmallVector< GlobalValue::GUID, 1 > CalleeGuids)
Definition MemProf.h:366
CallStackId CSId
Definition MemProf.h:360
IndexedCallSiteInfo(CallStackId CSId)
Definition MemProf.h:365
IndexedCallSiteInfo()=default
SmallVector< GlobalValue::GUID, 1 > CalleeGuids
Definition MemProf.h:362
bool operator==(const IndexedCallSiteInfo &Other) const
Definition MemProf.h:370
void clear()
Definition MemProf.h:449
llvm::SmallVector< IndexedAllocationInfo > AllocSites
Definition MemProf.h:441
static LLVM_ABI IndexedMemProfRecord deserialize(const MemProfSchema &Schema, const unsigned char *Buffer, IndexedVersion Version)
bool operator==(const IndexedMemProfRecord &Other) const
Definition MemProf.h:460
void merge(const IndexedMemProfRecord &Other)
Definition MemProf.h:451
llvm::SmallVector< IndexedCallSiteInfo > CallSites
Definition MemProf.h:447
LineLocation(uint32_t L, uint32_t D)
Definition MemProf.h:833
uint32_t LineOffset
Definition MemProf.h:849
bool operator!=(const LineLocation &O) const
Definition MemProf.h:843
bool operator==(const LineLocation &O) const
Definition MemProf.h:839
bool operator<(const LineLocation &O) const
Definition MemProf.h:835
uint64_t getHashCode() const
Definition MemProf.h:847
uint32_t Column
Definition MemProf.h:850
llvm::SmallVector< CallSiteInfo > CallSites
Definition MemProf.h:522
llvm::SmallVector< AllocationInfo > AllocSites
Definition MemProf.h:520
void print(llvm::raw_ostream &OS) const
Definition MemProf.h:527
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
PortableMemInfoBlock()=default
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
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...