15#define MIBEntryDef(NameTag, Name, Type) List.push_back(Meta::Name);
22 return {Meta::AllocCount, Meta::TotalSize, Meta::TotalLifetime,
23 Meta::TotalLifetimeAccessDensity};
62 Result +=
N.serializedSize(Schema,
Version2);
76 Result +=
N.serializedSize(Schema,
Version3);
98 using namespace support;
105 N.Info.serialize(Schema,
OS);
110 for (
const auto &CSId :
Record.CallSiteIds)
118 using namespace support;
126 N.Info.serialize(Schema,
OS);
131 for (
const auto &CSId :
Record.CallSiteIds) {
153 const unsigned char *
Ptr) {
154 using namespace support;
160 endian::readNext<uint64_t, llvm::endianness::little>(
Ptr);
161 Record.AllocSites.reserve(NumNodes);
164 Node.CSId = endian::readNext<CallStackId, llvm::endianness::little>(
Ptr);
165 Node.Info.deserialize(Schema,
Ptr);
172 endian::readNext<uint64_t, llvm::endianness::little>(
Ptr);
173 Record.CallSiteIds.reserve(NumCtxs);
174 for (
uint64_t J = 0; J < NumCtxs; J++) {
176 endian::readNext<CallStackId, llvm::endianness::little>(
Ptr);
177 Record.CallSiteIds.push_back(CSId);
184 const unsigned char *
Ptr) {
185 using namespace support;
191 endian::readNext<uint64_t, llvm::endianness::little>(
Ptr);
192 Record.AllocSites.reserve(NumNodes);
196 endian::readNext<LinearCallStackId, llvm::endianness::little>(
Ptr);
197 Node.Info.deserialize(Schema,
Ptr);
204 endian::readNext<uint64_t, llvm::endianness::little>(
Ptr);
205 Record.CallSiteIds.reserve(NumCtxs);
206 for (
uint64_t J = 0; J < NumCtxs; J++) {
212 endian::readNext<LinearCallStackId, llvm::endianness::little>(
Ptr);
213 Record.CallSiteIds.push_back(CSId);
221 const unsigned char *
Ptr,
239 AI.
Info = IndexedAI.Info;
241 Record.AllocSites.push_back(std::move(AI));
246 Record.CallSites.push_back(Callback(CSId));
268 using namespace support;
270 const unsigned char *
Ptr = Buffer;
272 endian::readNext<uint64_t, llvm::endianness::little>(
Ptr);
275 "memprof schema invalid");
279 for (
size_t I = 0;
I < NumSchemaIds;
I++) {
281 endian::readNext<uint64_t, llvm::endianness::little>(
Ptr);
284 "memprof schema invalid");
286 Result.push_back(
static_cast<Meta>(
Tag));
300 std::memcpy(&CSId, Hash.data(),
sizeof(Hash));
334template <
typename FrameIdTy>
344 CommonLen = std::distance(CallStack->
rbegin(), Pos.second);
348 assert(CommonLen <= Indexes.size());
349 Indexes.resize(CommonLen);
353 uint32_t CurrentIndex = RadixArray.size();
354 uint32_t ParentIndex = Indexes.back();
357 assert(ParentIndex < CurrentIndex);
358 RadixArray.push_back(ParentIndex - CurrentIndex);
365 Indexes.push_back(RadixArray.size());
366 RadixArray.push_back(
367 MemProfFrameIndexes ? MemProfFrameIndexes->
find(
F)->second :
F);
372 RadixArray.push_back(CallStack->
size());
376 return RadixArray.size() - 1;
379template <
typename FrameIdTy>
382 &&MemProfCallStackData,
390 if (CallStacks.
empty()) {
392 CallStackPos.clear();
431 llvm::sort(CallStacks, [&](
const CSIdPair &L,
const CSIdPair &R) {
434 return std::lexicographical_compare(
435 L.second.rbegin(), L.second.rend(), R.second.rbegin(), R.second.rend(),
436 [&](FrameIdTy F1, FrameIdTy F2) {
437 uint64_t H1 = FrameHistogram[F1].Count;
438 uint64_t H2 = FrameHistogram[F2].Count;
450 RadixArray.reserve(CallStacks.
size() * 8);
454 Indexes.reserve(512);
457 CallStackPos.clear();
458 CallStackPos.reserve(CallStacks.
size());
489 encodeCallStack(&
CallStack, Prev, MemProfFrameIndexes);
490 CallStackPos.insert({CSId, Pos});
495 assert(!RadixArray.empty());
501 for (
size_t I = 0, J = RadixArray.size() - 1;
I < J; ++
I, --J)
505 for (
auto &[K, V] : CallStackPos)
506 V = RadixArray.size() - 1 - V;
513template <
typename FrameIdTy>
516 &MemProfCallStackData) {
519 for (
const auto &KV : MemProfCallStackData) {
520 const auto &CS = KV.second;
521 for (
unsigned I = 0,
E = CS.size();
I !=
E; ++
I) {
522 auto &S = Histogram[CS[
I]];
533 &MemProfCallStackData);
537 &MemProfCallStackData);
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
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),...
iterator find(const_arg_type_t< KeyT > Val)
bool contains(const_arg_type_t< KeyT > Val) const
Return true if the specified key is in the map, false otherwise.
Tagged union holding either a T or a Error.
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
HashResultTy< HasherT_ > final()
Forward to HasherT::final() if available.
Interface to help hash various types through a hasher type.
std::enable_if_t< hashbuilder_detail::IsHashableData< T >::value, HashBuilder & > add(T Value)
Implement hashing for hashable data types, e.g. integral or enum values.
This class implements a map that also provides access to all stored values in a deterministic order.
reverse_iterator rbegin()
StringRef - Represent a constant reference to a string, i.e.
An efficient, type-erasing, non-owning reference to a callable.
void build(llvm::MapVector< CallStackId, llvm::SmallVector< FrameIdTy > > &&MemProfCallStackData, const llvm::DenseMap< FrameIdTy, LinearFrameId > *MemProfFrameIndexes, llvm::DenseMap< FrameIdTy, FrameStat > &FrameHistogram)
Helper class to iterate through stack ids in both metadata (memprof MIB and callsite) and the corresp...
This class implements an extremely fast bulk output stream that can only output to a stream.
static StringRef getCanonicalFnName(const Function &F)
Return the canonical name for a function, taking into account suffix elision policy attributes.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static IndexedMemProfRecord deserializeV3(const MemProfSchema &Schema, const unsigned char *Ptr)
static void serializeV3(const IndexedMemProfRecord &Record, const MemProfSchema &Schema, raw_ostream &OS, llvm::DenseMap< CallStackId, LinearCallStackId > &MemProfCallStackIndexes)
MemProfSchema getHotColdSchema()
uint32_t LinearCallStackId
static size_t serializedSizeV2(const IndexedAllocationInfo &IAI, const MemProfSchema &Schema)
static size_t serializedSizeV3(const IndexedAllocationInfo &IAI, const MemProfSchema &Schema)
template llvm::DenseMap< FrameId, FrameStat > computeFrameHistogram< FrameId >(llvm::MapVector< CallStackId, llvm::SmallVector< FrameId > > &MemProfCallStackData)
MemProfSchema getFullSchema()
Expected< MemProfSchema > readMemProfSchema(const unsigned char *&Buffer)
static void serializeV2(const IndexedMemProfRecord &Record, const MemProfSchema &Schema, raw_ostream &OS)
template llvm::DenseMap< LinearFrameId, FrameStat > computeFrameHistogram< LinearFrameId >(llvm::MapVector< CallStackId, llvm::SmallVector< LinearFrameId > > &MemProfCallStackData)
static IndexedMemProfRecord deserializeV2(const MemProfSchema &Schema, const unsigned char *Ptr)
llvm::DenseMap< FrameIdTy, FrameStat > computeFrameHistogram(llvm::MapVector< CallStackId, llvm::SmallVector< FrameIdTy > > &MemProfCallStackData)
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
std::array< uint8_t, NumBytes > BLAKE3Result
The constant LLVM_BLAKE3_OUT_LEN provides the default output length, 32 bytes, which is recommended f...
auto reverse(ContainerTy &&C)
void sort(IteratorTy Start, IteratorTy End)
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
std::vector< Frame > CallStack
PortableMemInfoBlock Info
size_t serializedSize(const MemProfSchema &Schema, IndexedVersion Version) const
llvm::SmallVector< CallStackId > CallSiteIds
llvm::SmallVector< IndexedAllocationInfo > AllocSites
size_t serializedSize(const MemProfSchema &Schema, IndexedVersion Version) const
void serialize(const MemProfSchema &Schema, raw_ostream &OS, IndexedVersion Version, llvm::DenseMap< CallStackId, LinearCallStackId > *MemProfCallStackIndexes=nullptr) const
static IndexedMemProfRecord deserialize(const MemProfSchema &Schema, const unsigned char *Buffer, IndexedVersion Version)
static GlobalValue::GUID getGUID(const StringRef FunctionName)
MemProfRecord toMemProfRecord(llvm::function_ref< std::vector< Frame >(const CallStackId)> Callback) const
static size_t serializedSize(const MemProfSchema &Schema)
Adapter to write values to a stream in a particular byte order.