1#ifndef LLVM_PROFILEDATA_MEMPROF_H_
2#define LLVM_PROFILEDATA_MEMPROF_H_
21#define MIBEntryDef(NameTag, Name, Type) NameTag,
35#define MIBEntryDef(NameTag, Name, Type) Name = Block.Name;
47 using namespace support;
49 for (
const Meta Id : Schema) {
51#define MIBEntryDef(NameTag, Name, Type) \
53 Name = endian::readNext<Type, llvm::endianness::little, unaligned>(Ptr); \
59 "a newer version of the runtime?");
67 using namespace support;
70 for (
const Meta Id : Schema) {
72#define MIBEntryDef(NameTag, Name, Type) \
74 LE.write<Type>(Name); \
86 OS <<
" MemInfoBlock:\n";
87#define MIBEntryDef(NameTag, Name, Type) \
88 OS << " " << #Name << ": " << Name << "\n";
94#define MIBEntryDef(NameTag, Name, Type) \
95 Type get##Name() const { return Name; }
104#define MIBEntryDef(NameTag, Name, Type) List.push_back(Meta::Name);
111#define MIBEntryDef(NameTag, Name, Type) \
112 if (Other.get##Name() != get##Name()) \
125#define MIBEntryDef(NameTag, Name, Type) Result += sizeof(Type);
132#define MIBEntryDef(NameTag, Name, Type) Type Name = Type();
188 using namespace support;
194 static_assert(std::is_same<GlobalValue::GUID, uint64_t>::value,
195 "Expect GUID to be uint64_t.");
205 using namespace support;
208 endian::readNext<uint64_t, llvm::endianness::little, unaligned>(
Ptr);
210 endian::readNext<uint32_t, llvm::endianness::little, unaligned>(
Ptr);
212 endian::readNext<uint32_t, llvm::endianness::little, unaligned>(
Ptr);
214 endian::readNext<bool, llvm::endianness::little, unaligned>(
Ptr);
228 <<
" Function: " <<
Function <<
"\n"
229 <<
" SymbolName: " <<
SymbolName.value_or(
"<None>") <<
"\n"
231 <<
" Column: " <<
Column <<
"\n"
239 auto HashCombine = [](
auto Value,
size_t Seed) {
240 std::hash<
decltype(
Value)> Hasher;
244 return Hasher(
Value) + 0x9e3779b97f4a7c15 + (
Seed << 6) + (
Seed >> 2);
248 Result ^= HashCombine(
Function, Result);
250 Result ^= HashCombine(
Column, Result);
252 return static_cast<FrameId>(Result);
274 const MemInfoBlock &MB)
291 for (
size_t J = 0; J <
Other.CallStack.size(); J++) {
316 CallStack.push_back(IdToFrameCallback(Id));
323 OS <<
" Callstack:\n";
362 Result +=
N.serializedSize();
369 Result += Frames.size() *
sizeof(
FrameId);
399 const unsigned char *Buffer);
421 AllocSites.emplace_back(IndexedAI, IdToFrameCallback);
425 for (
const FrameId Id : Site) {
435 OS <<
" AllocSites:\n";
441 OS <<
" CallSites:\n";
443 for (
const Frame &
F : Frames) {
477 static std::pair<offset_type, offset_type>
479 using namespace support;
482 endian::readNext<offset_type, llvm::endianness::little, unaligned>(
D);
484 endian::readNext<offset_type, llvm::endianness::little, unaligned>(
D);
485 return std::make_pair(KeyLen, DataLen);
489 using namespace support;
528 static std::pair<offset_type, offset_type>
530 using namespace support;
537 return std::make_pair(
N, M);
541 using namespace support;
548 assert(
Schema !=
nullptr &&
"MemProf schema is not initialized!");
549 V.serialize(*
Schema, Out);
572 static std::pair<offset_type, offset_type>
574 using namespace support;
580 return std::make_pair(
N, M);
584 using namespace support;
612 static std::pair<offset_type, offset_type>
614 using namespace support;
617 endian::readNext<offset_type, llvm::endianness::little, unaligned>(
D);
619 endian::readNext<offset_type, llvm::endianness::little, unaligned>(
D);
620 return std::make_pair(KeyLen, DataLen);
624 using namespace support;
648 &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 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.
Helper class to iterate through stack ids in both metadata (memprof MIB and callsite) and the corresp...
FrameId external_key_type
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)
uint64_t external_key_type
RecordLookupTrait(const MemProfSchema &S)
RecordLookupTrait()=delete
static std::pair< offset_type, offset_type > EmitKeyDataLength(raw_ostream &Out, key_type_ref K, data_type_ref V)
static hash_value_type ComputeHash(key_type_ref K)
RecordWriterTrait()=default
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)
CallStackId hashCallStack(ArrayRef< FrameId > CS)
Expected< MemProfSchema > readMemProfSchema(const unsigned char *&Buffer)
void verifyFunctionProfileData(const llvm::MapVector< GlobalValue::GUID, IndexedMemProfRecord > &FunctionProfileData)
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.
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)
size_t serializedSize() const
bool operator==(const IndexedAllocationInfo &Other) const
bool operator!=(const IndexedAllocationInfo &Other) const
PortableMemInfoBlock Info
llvm::SmallVector< FrameId > CallStack
IndexedAllocationInfo(ArrayRef< FrameId > CS, CallStackId CSId, const MemInfoBlock &MB)
IndexedAllocationInfo()=default
llvm::SmallVector< IndexedAllocationInfo > AllocSites
void serialize(const MemProfSchema &Schema, raw_ostream &OS)
size_t serializedSize() const
llvm::SmallVector< llvm::SmallVector< FrameId > > CallSites
bool operator==(const IndexedMemProfRecord &Other) const
static GlobalValue::GUID getGUID(const StringRef FunctionName)
static IndexedMemProfRecord deserialize(const MemProfSchema &Schema, const unsigned char *Buffer)
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 MemProfSchema getSchema()
void deserialize(const MemProfSchema &Schema, const unsigned char *Ptr)
static constexpr size_t serializedSize()
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.