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, 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;
207 const uint64_t F = endian::readNext<uint64_t, little, unaligned>(
Ptr);
208 const uint32_t L = endian::readNext<uint32_t, little, unaligned>(
Ptr);
209 const uint32_t C = endian::readNext<uint32_t, little, unaligned>(
Ptr);
210 const bool I = endian::readNext<bool, little, unaligned>(
Ptr);
224 <<
" Function: " <<
Function <<
"\n"
225 <<
" SymbolName: " <<
SymbolName.value_or(
"<None>") <<
"\n"
227 <<
" Column: " <<
Column <<
"\n"
235 auto HashCombine = [](
auto Value,
size_t Seed) {
236 std::hash<
decltype(
Value)> Hasher;
240 return Hasher(
Value) + 0x9e3779b97f4a7c15 + (
Seed << 6) + (
Seed >> 2);
244 Result ^= HashCombine(
Function, Result);
246 Result ^= HashCombine(
Column, Result);
248 return static_cast<FrameId>(Result);
279 for (
size_t J = 0; J <
Other.CallStack.size(); J++) {
304 CallStack.push_back(IdToFrameCallback(Id));
311 OS <<
" Callstack:\n";
350 Result +=
N.serializedSize();
357 Result += Frames.size() *
sizeof(
FrameId);
387 const unsigned char *Buffer);
409 AllocSites.emplace_back(IndexedAI, IdToFrameCallback);
413 for (
const FrameId Id : Site) {
423 OS <<
" AllocSites:\n";
429 OS <<
" CallSites:\n";
431 for (
const Frame &
F : Frames) {
465 static std::pair<offset_type, offset_type>
467 using namespace support;
469 offset_type KeyLen = endian::readNext<offset_type, little, unaligned>(
D);
470 offset_type DataLen = endian::readNext<offset_type, little, unaligned>(
D);
471 return std::make_pair(KeyLen, DataLen);
475 using namespace support;
476 return endian::readNext<external_key_type, little, unaligned>(
D);
513 static std::pair<offset_type, offset_type>
515 using namespace support;
522 return std::make_pair(
N, M);
526 using namespace support;
533 assert(
Schema !=
nullptr &&
"MemProf schema is not initialized!");
534 V.serialize(*
Schema, Out);
552 static std::pair<offset_type, offset_type>
554 using namespace support;
560 return std::make_pair(
N, M);
564 using namespace support;
592 static std::pair<offset_type, offset_type>
594 using namespace support;
596 offset_type KeyLen = endian::readNext<offset_type, little, unaligned>(
D);
597 offset_type DataLen = endian::readNext<offset_type, little, unaligned>(
D);
598 return std::make_pair(KeyLen, DataLen);
602 using namespace support;
603 return endian::readNext<external_key_type, little, unaligned>(
D);
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 defines the DenseMap class.
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.
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...
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(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.
Expected< MemProfSchema > readMemProfSchema(const unsigned char *&Buffer)
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, 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.