14#ifndef LLVM_PROFILEDATA_MEMPROF_H
15#define LLVM_PROFILEDATA_MEMPROF_H
59 return "___memprof_default_options_str";
70#define MIBEntryDef(NameTag, Name, Type) NameTag,
91 for (
const Meta Id : IncomingSchema)
93#define MIBEntryDef(NameTag, Name, Type) Name = Block.Name;
105 const unsigned char *
Ptr) {
106 using namespace support;
109 for (
const Meta Id : IncomingSchema) {
111#define MIBEntryDef(NameTag, Name, Type) \
113 Name = endian::readNext<Type, llvm::endianness::little>(Ptr); \
119 "a newer version of the runtime?");
129 using namespace support;
132 for (
const Meta Id : Schema) {
134#define MIBEntryDef(NameTag, Name, Type) \
136 LE.write<Type>(Name); \
148 OS <<
" MemInfoBlock:\n";
149#define MIBEntryDef(NameTag, Name, Type) \
150 OS << " " << #Name << ": " << Name << "\n";
153 if (AccessHistogramSize > 0) {
154 OS <<
" " <<
"AccessHistogramValues" <<
":";
155 for (
uint32_t I = 0;
I < AccessHistogramSize; ++
I) {
168#define MIBEntryDef(NameTag, Name, Type) \
169 Type get##Name() const { \
170 assert(Schema[llvm::to_underlying(Meta::Name)]); \
177#define MIBEntryDef(NameTag, Name, Type) \
178 void set##Name(Type NewVal) { \
179 assert(Schema[llvm::to_underlying(Meta::Name)]); \
188 if (
Other.Schema != Schema)
191#define MIBEntryDef(NameTag, Name, Type) \
192 if (Schema[llvm::to_underlying(Meta::Name)] && \
193 Other.get##Name() != get##Name()) \
207 for (
const Meta Id : Schema) {
209#define MIBEntryDef(NameTag, Name, Type) \
211 Result += sizeof(Type); \
228 std::bitset<llvm::to_underlying(Meta::Size)> Schema;
230#define MIBEntryDef(NameTag, Name, Type) Type Name = Type();
231#include "llvm/ProfileData/MIBEntryDef.inc"
255 bool IsInlineFrame =
false;
260 SymbolName =
Other.SymbolName
261 ? std::make_unique<std::string>(*
Other.SymbolName)
263 LineOffset =
Other.LineOffset;
264 Column =
Other.Column;
265 IsInlineFrame =
Other.IsInlineFrame;
269 :
Function(Hash), LineOffset(Off), Column(Col), IsInlineFrame(Inline) {}
275 Other.Column == Column &&
Other.IsInlineFrame == IsInlineFrame;
280 SymbolName =
Other.SymbolName
281 ? std::make_unique<std::string>(*
Other.SymbolName)
283 LineOffset =
Other.LineOffset;
284 Column =
Other.Column;
285 IsInlineFrame =
Other.IsInlineFrame;
304 using namespace support;
310 static_assert(std::is_same<GlobalValue::GUID, uint64_t>::value,
311 "Expect GUID to be uint64_t.");
316 LE.write<
bool>(IsInlineFrame);
321 using namespace support;
324 endian::readNext<uint64_t, llvm::endianness::little>(
Ptr);
326 endian::readNext<uint32_t, llvm::endianness::little>(
Ptr);
328 endian::readNext<uint32_t, llvm::endianness::little>(
Ptr);
329 const bool I = endian::readNext<bool, llvm::endianness::little>(
Ptr);
336 return sizeof(Frame::Function) +
sizeof(Frame::LineOffset) +
337 sizeof(Frame::Column) +
sizeof(Frame::IsInlineFrame);
343 <<
" Function: " <<
Function <<
"\n"
344 <<
" SymbolName: " << getSymbolNameOr(
"<None>") <<
"\n"
345 <<
" LineOffset: " << LineOffset <<
"\n"
346 <<
" Column: " << Column <<
"\n"
347 <<
" Inline: " << IsInlineFrame <<
"\n";
368 : CSId(CSId), CalleeGuids(
std::
move(CalleeGuids)) {}
371 return CSId ==
Other.CSId && CalleeGuids ==
Other.CalleeGuids;
391 : CSId(CSId),
Info(MB, Schema) {}
393 : CSId(CSId),
Info(MB) {}
403 if (
Other.CSId != CSId)
425 OS <<
" Callstack:\n";
461 if (
Other.AllocSites != AllocSites)
464 if (
Other.CallSites != CallSites)
474 *MemProfCallStackIndexes =
nullptr)
const;
478 const unsigned char *Buffer,
504 : Frames(
std::
move(Frames)), CalleeGuids(
std::
move(CalleeGuids)) {}
507 return Frames ==
Other.Frames && CalleeGuids ==
Other.CalleeGuids;
528 if (!AllocSites.
empty()) {
529 OS <<
" AllocSites:\n";
534 if (!CallSites.
empty()) {
535 OS <<
" CallSites:\n";
537 for (
const Frame &
F : CS.Frames) {
565 : Version(V), Schema(S) {}
573 static std::pair<offset_type, offset_type>
575 using namespace support;
578 endian::readNext<offset_type, llvm::endianness::little>(
D);
580 endian::readNext<offset_type, llvm::endianness::little>(
D);
581 return std::make_pair(KeyLen, DataLen);
585 using namespace support;
586 return endian::readNext<external_key_type, llvm::endianness::little>(
D);
591 Record = IndexedMemProfRecord::deserialize(Schema,
D, Version);
631 : Schema(Schema), Version(V),
632 MemProfCallStackIndexes(MemProfCallStackIndexes) {}
636 std::pair<offset_type, offset_type>
638 using namespace support;
643 offset_type M = V.serializedSize(*Schema, Version);
645 return std::make_pair(
N, M);
649 using namespace support;
656 assert(Schema !=
nullptr &&
"MemProf schema is not initialized!");
657 V.serialize(*Schema, Out, Version, MemProfCallStackIndexes);
680 static std::pair<offset_type, offset_type>
682 using namespace support;
688 return std::make_pair(
N, M);
692 using namespace support;
720 static std::pair<offset_type, offset_type>
722 using namespace support;
725 endian::readNext<offset_type, llvm::endianness::little>(
D);
727 endian::readNext<offset_type, llvm::endianness::little>(
D);
728 return std::make_pair(KeyLen, DataLen);
732 using namespace support;
733 return endian::readNext<external_key_type, llvm::endianness::little>(
D);
738 return Frame::deserialize(
D);
756 static std::pair<offset_type, offset_type>
758 using namespace support;
764 return std::make_pair(
N, M);
768 using namespace support;
775 using namespace support;
801 static std::pair<offset_type, offset_type>
803 using namespace support;
808 endian::readNext<offset_type, llvm::endianness::little>(
D);
809 return std::make_pair(KeyLen, DataLen);
813 using namespace support;
814 return endian::readNext<external_key_type, llvm::endianness::little>(
D);
818 using namespace support;
824 for (
size_t I = 0;
I != NumFrames; ++
I) {
825 FrameId F = endian::readNext<FrameId, llvm::endianness::little>(
D);
836 return std::tie(LineOffset, Column) < std::tie(O.LineOffset, O.Column);
840 return LineOffset == O.LineOffset && Column == O.Column;
844 return LineOffset != O.LineOffset || Column != O.Column;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
Analysis containing CSE Info
static StringRef getSymbolName(SymbolKind SymKind)
This file defines the DenseMap class.
std::optional< std::vector< StOtherPiece > > Other
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.
void reserve(size_type N)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
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.
static uint64_t GetInternalKey(internal_key_type K)
hash_value_type ComputeHash(internal_key_type K)
static bool EqualKey(internal_key_type A, internal_key_type B)
static std::pair< offset_type, offset_type > ReadKeyDataLength(const unsigned char *&D)
uint64_t ReadKey(const unsigned char *D, offset_type)
data_type ReadData(uint64_t K, const unsigned char *D, offset_type Length)
static uint64_t GetExternalKey(external_key_type K)
static hash_value_type ComputeHash(key_type_ref K)
static std::pair< offset_type, offset_type > EmitKeyDataLength(raw_ostream &Out, key_type_ref K, data_type_ref V)
void EmitData(raw_ostream &Out, key_type_ref, data_type_ref V, offset_type)
void EmitKey(raw_ostream &Out, key_type_ref K, offset_type)
Helper class to iterate through stack ids in both metadata (memprof MIB and callsite) and the corresp...
data_type ReadData(uint64_t K, const unsigned char *D, offset_type)
static uint64_t GetExternalKey(external_key_type K)
static bool EqualKey(internal_key_type A, internal_key_type B)
static uint64_t GetInternalKey(internal_key_type K)
static std::pair< offset_type, offset_type > ReadKeyDataLength(const unsigned char *&D)
hash_value_type ComputeHash(internal_key_type K)
uint64_t ReadKey(const unsigned char *D, offset_type)
static hash_value_type ComputeHash(key_type_ref K)
void EmitKey(raw_ostream &Out, key_type_ref K, offset_type)
void EmitData(raw_ostream &Out, key_type_ref, data_type_ref V, offset_type)
static std::pair< offset_type, offset_type > EmitKeyDataLength(raw_ostream &Out, key_type_ref K, data_type_ref V)
static bool EqualKey(uint64_t A, uint64_t B)
uint64_t ReadKey(const unsigned char *D, offset_type)
data_type ReadData(uint64_t K, const unsigned char *D, offset_type)
static std::pair< offset_type, offset_type > ReadKeyDataLength(const unsigned char *&D)
static uint64_t GetInternalKey(uint64_t K)
hash_value_type ComputeHash(uint64_t K)
static uint64_t GetExternalKey(uint64_t K)
RecordLookupTrait(IndexedVersion V, const MemProfSchema &S)
RecordLookupTrait()=delete
static hash_value_type ComputeHash(key_type_ref K)
RecordWriterTrait(const MemProfSchema *Schema, IndexedVersion V, llvm::DenseMap< CallStackId, LinearCallStackId > *MemProfCallStackIndexes)
std::pair< offset_type, offset_type > EmitKeyDataLength(raw_ostream &Out, key_type_ref K, data_type_ref V)
RecordWriterTrait()=delete
void EmitKey(raw_ostream &Out, key_type_ref K, offset_type)
void EmitData(raw_ostream &Out, key_type_ref, data_type_ref V, offset_type)
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.
constexpr uint64_t MaximumSupportedVersion
LLVM_ABI MemProfSchema getHotColdSchema()
uint32_t LinearCallStackId
llvm::StringRef getMemprofOptionsSymbolName()
constexpr uint64_t MinimumSupportedVersion
std::pair< LineLocation, uint64_t > CallEdgeTy
LLVM_ABI MemProfSchema getFullSchema()
LLVM_ABI GlobalValue::GUID getGUID(const StringRef FunctionName)
LLVM_ABI Expected< MemProfSchema > readMemProfSchema(const unsigned char *&Buffer)
llvm::StringRef getMemprofOptionsSymbolDarwinLinkageName()
This is an optimization pass for GlobalISel generic memory operations.
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
constexpr std::underlying_type_t< Enum > to_underlying(Enum E)
Returns underlying integer value of an enum.
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
PortableMemInfoBlock Info
void printYAML(raw_ostream &OS) const
bool operator!=(const CallSiteInfo &Other) const
CallSiteInfo(std::vector< Frame > Frames)
std::vector< Frame > Frames
bool operator==(const CallSiteInfo &Other) const
SmallVector< GlobalValue::GUID, 1 > CalleeGuids
CallSiteInfo(std::vector< Frame > Frames, SmallVector< GlobalValue::GUID, 1 > CalleeGuids)
Frame & operator=(const Frame &Other)
Frame(const Frame &Other)
static constexpr size_t serializedSize()
void printYAML(raw_ostream &OS) const
void serialize(raw_ostream &OS) const
bool hasSymbolName() const
std::string getSymbolNameOr(StringRef Alt) const
StringRef getSymbolName() const
bool operator==(const Frame &Other) const
bool operator!=(const Frame &Other) const
static Frame deserialize(const unsigned char *Ptr)
Frame(GlobalValue::GUID Hash, uint32_t Off, uint32_t Col, bool Inline)
std::unique_ptr< std::string > SymbolName
IndexedAllocationInfo(CallStackId CSId, const MemInfoBlock &MB, const MemProfSchema &Schema=getFullSchema())
bool operator==(const IndexedAllocationInfo &Other) const
bool operator!=(const IndexedAllocationInfo &Other) const
PortableMemInfoBlock Info
IndexedAllocationInfo(CallStackId CSId, const PortableMemInfoBlock &MB)
IndexedAllocationInfo()=default
bool operator!=(const IndexedCallSiteInfo &Other) const
IndexedCallSiteInfo(CallStackId CSId, SmallVector< GlobalValue::GUID, 1 > CalleeGuids)
IndexedCallSiteInfo(CallStackId CSId)
IndexedCallSiteInfo()=default
SmallVector< GlobalValue::GUID, 1 > CalleeGuids
bool operator==(const IndexedCallSiteInfo &Other) const
llvm::SmallVector< IndexedAllocationInfo > AllocSites
bool operator==(const IndexedMemProfRecord &Other) const
void merge(const IndexedMemProfRecord &Other)
llvm::SmallVector< IndexedCallSiteInfo > CallSites
LineLocation(uint32_t L, uint32_t D)
bool operator!=(const LineLocation &O) const
bool operator==(const LineLocation &O) const
bool operator<(const LineLocation &O) const
uint64_t getHashCode() const
llvm::SmallVector< CallSiteInfo > CallSites
llvm::SmallVector< AllocationInfo > AllocSites
void print(llvm::raw_ostream &OS) const
bool operator!=(const PortableMemInfoBlock &Other) const
void deserialize(const MemProfSchema &IncomingSchema, const unsigned char *Ptr)
PortableMemInfoBlock(const MemProfSchema &Schema, const unsigned char *Ptr)
PortableMemInfoBlock()=default
std::bitset< llvm::to_underlying(Meta::Size)> getSchema() const
static size_t serializedSize(const MemProfSchema &Schema)
void printYAML(raw_ostream &OS) const
void serialize(const MemProfSchema &Schema, raw_ostream &OS) const
PortableMemInfoBlock(const MemInfoBlock &Block, const MemProfSchema &IncomingSchema)
bool operator==(const PortableMemInfoBlock &Other) const
Adapter to write values to a stream in a particular byte order.