1#ifndef LLVM_PROFILEDATA_MEMPROF_H_
2#define LLVM_PROFILEDATA_MEMPROF_H_
41#define MIBEntryDef(NameTag, Name, Type) NameTag,
62 for (
const Meta Id : IncomingSchema)
64#define MIBEntryDef(NameTag, Name, Type) Name = Block.Name;
76 const unsigned char *
Ptr) {
77 using namespace support;
80 for (
const Meta Id : IncomingSchema) {
82#define MIBEntryDef(NameTag, Name, Type) \
84 Name = endian::readNext<Type, llvm::endianness::little>(Ptr); \
90 "a newer version of the runtime?");
100 using namespace support;
103 for (
const Meta Id : Schema) {
105#define MIBEntryDef(NameTag, Name, Type) \
107 LE.write<Type>(Name); \
119 OS <<
" MemInfoBlock:\n";
120#define MIBEntryDef(NameTag, Name, Type) \
121 OS << " " << #Name << ": " << Name << "\n";
132#define MIBEntryDef(NameTag, Name, Type) \
133 Type get##Name() const { \
134 assert(Schema[llvm::to_underlying(Meta::Name)]); \
143 if (
Other.Schema != Schema)
146#define MIBEntryDef(NameTag, Name, Type) \
147 if (Schema[llvm::to_underlying(Meta::Name)] && \
148 Other.get##Name() != get##Name()) \
162 for (
const Meta Id : Schema) {
164#define MIBEntryDef(NameTag, Name, Type) \
166 Result += sizeof(Type); \
182#define MIBEntryDef(NameTag, Name, Type) Type Name = Type();
238 using namespace support;
244 static_assert(std::is_same<GlobalValue::GUID, uint64_t>::value,
245 "Expect GUID to be uint64_t.");
255 using namespace support;
258 endian::readNext<uint64_t, llvm::endianness::little>(
Ptr);
260 endian::readNext<uint32_t, llvm::endianness::little>(
Ptr);
262 endian::readNext<uint32_t, llvm::endianness::little>(
Ptr);
263 const bool I = endian::readNext<bool, llvm::endianness::little>(
Ptr);
277 <<
" Function: " <<
Function <<
"\n"
278 <<
" SymbolName: " <<
SymbolName.value_or(
"<None>") <<
"\n"
280 <<
" Column: " <<
Column <<
"\n"
288 auto HashCombine = [](
auto Value,
size_t Seed) {
289 std::hash<
decltype(
Value)> Hasher;
293 return Hasher(
Value) + 0x9e3779b97f4a7c15 + (
Seed << 6) + (
Seed >> 2);
297 Result ^= HashCombine(
Function, Result);
299 Result ^= HashCombine(
Column, Result);
301 return static_cast<FrameId>(Result);
323 const MemInfoBlock &MB,
358 CallStack.push_back(IdToFrameCallback(Id));
365 OS <<
" Callstack:\n";
423 const unsigned char *Buffer,
452 AllocSites.emplace_back(IndexedAI, IdToFrameCallback);
456 for (
const FrameId Id : Site) {
466 OS <<
" AllocSites:\n";
472 OS <<
" CallSites:\n";
474 for (
const Frame &
F : Frames) {
501 : Version(V), Schema(S) {}
509 static std::pair<offset_type, offset_type>
511 using namespace support;
514 endian::readNext<offset_type, llvm::endianness::little>(
D);
516 endian::readNext<offset_type, llvm::endianness::little>(
D);
517 return std::make_pair(KeyLen, DataLen);
521 using namespace support;
522 return endian::readNext<external_key_type, llvm::endianness::little>(
D);
562 : Schema(Schema), Version(V) {}
566 std::pair<offset_type, offset_type>
568 using namespace support;
573 offset_type M = V.serializedSize(*Schema, Version);
575 return std::make_pair(
N, M);
579 using namespace support;
586 assert(Schema !=
nullptr &&
"MemProf schema is not initialized!");
587 V.serialize(*Schema, Out, Version);
610 static std::pair<offset_type, offset_type>
612 using namespace support;
618 return std::make_pair(
N, M);
622 using namespace support;
650 static std::pair<offset_type, offset_type>
652 using namespace support;
655 endian::readNext<offset_type, llvm::endianness::little>(
D);
657 endian::readNext<offset_type, llvm::endianness::little>(
D);
658 return std::make_pair(KeyLen, DataLen);
662 using namespace support;
663 return endian::readNext<external_key_type, llvm::endianness::little>(
D);
686 static std::pair<offset_type, offset_type>
688 using namespace support;
694 return std::make_pair(
N, M);
698 using namespace support;
705 using namespace support;
731 static std::pair<offset_type, offset_type>
733 using namespace support;
738 endian::readNext<offset_type, llvm::endianness::little>(
D);
739 return std::make_pair(KeyLen, DataLen);
743 using namespace support;
744 return endian::readNext<external_key_type, llvm::endianness::little>(
D);
748 using namespace support;
754 for (
size_t I = 0;
I != NumFrames; ++
I) {
755 FrameId F = endian::readNext<FrameId, llvm::endianness::little>(
D);
769template <
typename value_type,
typename IterTy>
772 if constexpr (std::is_same_v<deref_type, value_type>)
788 auto Iter =
Map.find(Id);
789 if (Iter ==
Map.end()) {
791 return Frame(0, 0, 0,
false);
793 return detail::DerefIterator<Frame>(Iter);
809 auto CSIter =
Map.find(CSId);
810 if (CSIter ==
Map.end()) {
814 detail::DerefIterator<llvm::SmallVector<FrameId>>(CSIter);
833 &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 contains library features backported from future STL versions.
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.
value_type DerefIterator(IterTy Iter)
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.
constexpr std::underlying_type_t< Enum > to_underlying(Enum E)
Returns underlying integer value of an enum.
typename llvm::remove_cvref< T >::type remove_cvref_t
AllocationInfo(const IndexedAllocationInfo &IndexedAI, llvm::function_ref< const Frame(const FrameId)> IdToFrameCallback)
PortableMemInfoBlock Info
llvm::SmallVector< Frame > CallStack
void printYAML(raw_ostream &OS) const
CallStackIdConverter()=delete
llvm::SmallVector< Frame > operator()(CallStackId CSId)
std::optional< CallStackId > LastUnmappedId
std::function< Frame(FrameId)> FrameIdToFrame
CallStackIdConverter(MapTy &Map, std::function< Frame(FrameId)> FrameIdToFrame)
Frame operator()(FrameId Id)
FrameIdConverter(MapTy &Map)
std::optional< FrameId > LastUnmappedId
FrameIdConverter()=delete
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)
IndexedAllocationInfo(ArrayRef< FrameId > CS, CallStackId CSId, const MemInfoBlock &MB, const MemProfSchema &Schema=getFullSchema())
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()=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
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.