1#ifndef LLVM_PROFILEDATA_MEMPROF_H_
2#define LLVM_PROFILEDATA_MEMPROF_H_
39#define MIBEntryDef(NameTag, Name, Type) NameTag,
59#define MIBEntryDef(NameTag, Name, Type) Name = Block.Name;
71 using namespace support;
73 for (
const Meta Id : Schema) {
75#define MIBEntryDef(NameTag, Name, Type) \
77 Name = endian::readNext<Type, llvm::endianness::little>(Ptr); \
83 "a newer version of the runtime?");
91 using namespace support;
94 for (
const Meta Id : Schema) {
96#define MIBEntryDef(NameTag, Name, Type) \
98 LE.write<Type>(Name); \
110 OS <<
" MemInfoBlock:\n";
111#define MIBEntryDef(NameTag, Name, Type) \
112 OS << " " << #Name << ": " << Name << "\n";
118#define MIBEntryDef(NameTag, Name, Type) \
119 Type get##Name() const { return Name; }
126#define MIBEntryDef(NameTag, Name, Type) \
127 if (Other.get##Name() != get##Name()) \
141 for (
const Meta Id : Schema) {
143#define MIBEntryDef(NameTag, Name, Type) \
145 Result += sizeof(Type); \
158#define MIBEntryDef(NameTag, Name, Type) Type Name = Type();
214 using namespace support;
220 static_assert(std::is_same<GlobalValue::GUID, uint64_t>::value,
221 "Expect GUID to be uint64_t.");
231 using namespace support;
234 endian::readNext<uint64_t, llvm::endianness::little>(
Ptr);
236 endian::readNext<uint32_t, llvm::endianness::little>(
Ptr);
238 endian::readNext<uint32_t, llvm::endianness::little>(
Ptr);
239 const bool I = endian::readNext<bool, llvm::endianness::little>(
Ptr);
253 <<
" Function: " <<
Function <<
"\n"
254 <<
" SymbolName: " <<
SymbolName.value_or(
"<None>") <<
"\n"
256 <<
" Column: " <<
Column <<
"\n"
264 auto HashCombine = [](
auto Value,
size_t Seed) {
265 std::hash<
decltype(
Value)> Hasher;
269 return Hasher(
Value) + 0x9e3779b97f4a7c15 + (
Seed << 6) + (
Seed >> 2);
273 Result ^= HashCombine(
Function, Result);
275 Result ^= HashCombine(
Column, Result);
277 return static_cast<FrameId>(Result);
299 const MemInfoBlock &MB)
333 CallStack.push_back(IdToFrameCallback(Id));
340 OS <<
" Callstack:\n";
398 const unsigned char *Buffer,
427 AllocSites.emplace_back(IndexedAI, IdToFrameCallback);
431 for (
const FrameId Id : Site) {
441 OS <<
" AllocSites:\n";
447 OS <<
" CallSites:\n";
449 for (
const Frame &
F : Frames) {
476 : Version(V), Schema(S) {}
484 static std::pair<offset_type, offset_type>
486 using namespace support;
489 endian::readNext<offset_type, llvm::endianness::little>(
D);
491 endian::readNext<offset_type, llvm::endianness::little>(
D);
492 return std::make_pair(KeyLen, DataLen);
496 using namespace support;
497 return endian::readNext<external_key_type, llvm::endianness::little>(
D);
537 : Schema(Schema), Version(V) {}
541 std::pair<offset_type, offset_type>
543 using namespace support;
548 offset_type M = V.serializedSize(*Schema, Version);
550 return std::make_pair(
N, M);
554 using namespace support;
561 assert(Schema !=
nullptr &&
"MemProf schema is not initialized!");
562 V.serialize(*Schema, Out, Version);
585 static std::pair<offset_type, offset_type>
587 using namespace support;
593 return std::make_pair(
N, M);
597 using namespace support;
625 static std::pair<offset_type, offset_type>
627 using namespace support;
630 endian::readNext<offset_type, llvm::endianness::little>(
D);
632 endian::readNext<offset_type, llvm::endianness::little>(
D);
633 return std::make_pair(KeyLen, DataLen);
637 using namespace support;
638 return endian::readNext<external_key_type, llvm::endianness::little>(
D);
661 static std::pair<offset_type, offset_type>
663 using namespace support;
669 return std::make_pair(
N, M);
673 using namespace support;
680 using namespace support;
706 static std::pair<offset_type, offset_type>
708 using namespace support;
713 endian::readNext<offset_type, llvm::endianness::little>(
D);
714 return std::make_pair(KeyLen, DataLen);
718 using namespace support;
719 return endian::readNext<external_key_type, llvm::endianness::little>(
D);
723 using namespace support;
729 for (
size_t I = 0;
I != NumFrames; ++
I) {
730 FrameId F = endian::readNext<FrameId, llvm::endianness::little>(
D);
750 &FunctionProfileData);
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
This file implements a map that provides insertion order iteration.
static ManagedStatic< cl::opt< uint64_t >, CreateSeed > Seed
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
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.
This class implements a map that also provides access to all stored values in a deterministic order.
void reserve(size_type N)
void push_back(const T &Elt)
StringRef - Represent a constant reference to a string, i.e.
LLVM Value Representation.
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)
CallStackId external_key_type
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)
std::pair< offset_type, offset_type > EmitKeyDataLength(raw_ostream &Out, key_type_ref K, data_type_ref V)
RecordWriterTrait(const MemProfSchema *Schema, IndexedVersion 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.
@ C
The default llvm calling convention, compatible with C.
void verifyIndexedMemProfRecord(const IndexedMemProfRecord &Record)
constexpr uint64_t MaximumSupportedVersion
MemProfSchema getHotColdSchema()
CallStackId hashCallStack(ArrayRef< FrameId > CS)
constexpr uint64_t MinimumSupportedVersion
MemProfSchema getFullSchema()
Expected< MemProfSchema > readMemProfSchema(const unsigned char *&Buffer)
void verifyFunctionProfileData(const llvm::MapVector< GlobalValue::GUID, IndexedMemProfRecord > &FunctionProfileData)
This is an optimization pass for GlobalISel generic memory operations.
AllocationInfo(const IndexedAllocationInfo &IndexedAI, llvm::function_ref< const Frame(const FrameId)> IdToFrameCallback)
PortableMemInfoBlock Info
llvm::SmallVector< Frame > CallStack
void printYAML(raw_ostream &OS) const
Frame & operator=(const Frame &Other)
Frame(const Frame &Other)
static constexpr size_t serializedSize()
void printYAML(raw_ostream &OS) const
GlobalValue::GUID Function
void serialize(raw_ostream &OS) const
std::optional< std::string > SymbolName
Frame(uint64_t Hash, uint32_t Off, uint32_t Col, bool Inline)
bool operator==(const Frame &Other) const
bool operator!=(const Frame &Other) const
static Frame deserialize(const unsigned char *Ptr)
bool operator==(const IndexedAllocationInfo &Other) const
bool operator!=(const IndexedAllocationInfo &Other) const
PortableMemInfoBlock Info
size_t serializedSize(const MemProfSchema &Schema, IndexedVersion Version) const
llvm::SmallVector< FrameId > CallStack
IndexedAllocationInfo(ArrayRef< FrameId > CS, CallStackId CSId, const MemInfoBlock &MB)
IndexedAllocationInfo()=default
llvm::SmallVector< CallStackId > CallSiteIds
llvm::SmallVector< IndexedAllocationInfo > AllocSites
size_t serializedSize(const MemProfSchema &Schema, IndexedVersion Version) const
static IndexedMemProfRecord deserialize(const MemProfSchema &Schema, const unsigned char *Buffer, IndexedVersion Version)
llvm::SmallVector< llvm::SmallVector< FrameId > > CallSites
MemProfRecord toMemProfRecord(std::function< const llvm::SmallVector< Frame >(const CallStackId)> Callback) const
bool operator==(const IndexedMemProfRecord &Other) const
void serialize(const MemProfSchema &Schema, raw_ostream &OS, IndexedVersion Version)
static GlobalValue::GUID getGUID(const StringRef FunctionName)
void merge(const IndexedMemProfRecord &Other)
llvm::SmallVector< AllocationInfo > AllocSites
void print(llvm::raw_ostream &OS) const
MemProfRecord(const IndexedMemProfRecord &Record, llvm::function_ref< const Frame(const FrameId Id)> IdToFrameCallback)
llvm::SmallVector< llvm::SmallVector< Frame > > CallSites
bool operator!=(const PortableMemInfoBlock &Other) const
PortableMemInfoBlock(const MemInfoBlock &Block)
PortableMemInfoBlock(const MemProfSchema &Schema, const unsigned char *Ptr)
PortableMemInfoBlock()=default
static size_t serializedSize(const MemProfSchema &Schema)
void deserialize(const MemProfSchema &Schema, const unsigned char *Ptr)
void printYAML(raw_ostream &OS) const
void serialize(const MemProfSchema &Schema, raw_ostream &OS) const
bool operator==(const PortableMemInfoBlock &Other) const
Adapter to write values to a stream in a particular byte order.