13#ifndef LLVM_ANALYSIS_MEMORYPROFILEINFO_H
14#define LLVM_ANALYSIS_MEMORYPROFILEINFO_H
71 struct CallStackTrieNode {
79 std::vector<ContextTotalSize> ContextSizeInfo;
81 std::map<uint64_t, CallStackTrieNode *> Callers;
88 AllocTypes &= ~static_cast<uint8_t>(
AllocType);
96 CallStackTrieNode *Alloc =
nullptr;
111 bool BuiltFromExistingMetadata =
false;
113 void deleteTrieNode(CallStackTrieNode *
Node) {
116 for (
auto C :
Node->Callers)
117 deleteTrieNode(
C.second);
123 void collectContextSizeInfo(CallStackTrieNode *
Node,
124 std::vector<ContextTotalSize> &ContextSizeInfo);
129 void convertHotToNotCold(CallStackTrieNode *
Node);
133 std::vector<uint64_t> &MIBCallStack,
134 std::vector<Metadata *> &MIBNodes,
135 bool CalleeHasAmbiguousCallerContext,
uint64_t &TotalBytes,
141 : ORE(ORE), MaxColdSize(MaxColdSize) {}
144 bool empty()
const {
return Alloc ==
nullptr; }
153 std::vector<ContextTotalSize> ContextSizeInfo = {});
180template <
class NodeT,
class IteratorT>
class CallStack {
189 const NodeT *
N =
nullptr;
198 bool empty()
const {
return N ==
nullptr; }
200 CallStackIterator
begin()
const;
206 const NodeT *
N =
nullptr;
209template <
class NodeT,
class IteratorT>
211 const NodeT *
N,
bool End)
217 Iter = End ?
N->StackIdIndices.end() :
N->StackIdIndices.begin();
220template <
class NodeT,
class IteratorT>
226template <
class NodeT,
class IteratorT>
229 return N->StackIdIndices.back();
232template <
class NodeT,
class IteratorT>
238template <
class NodeT,
class IteratorT>
243 Cur !=
end() && OtherCur !=
Other.end(); ++Cur, ++OtherCur)
244 assert(*Cur == *OtherCur);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
This is an important class for using LLVM in a threaded context.
StringRef - Represent a constant reference to a string, i.e.
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM_ABI void addCallStack(AllocationType AllocType, ArrayRef< uint64_t > StackIds, std::vector< ContextTotalSize > ContextSizeInfo={})
Add a call stack context with the given allocation type to the Trie.
LLVM_ABI void addSingleAllocTypeAttribute(CallBase *CI, AllocationType AT, StringRef Descriptor)
Add an attribute for the given allocation type to the call instruction.
LLVM_ABI bool buildAndAttachMIBMetadata(CallBase *CI)
Build and attach the minimal necessary MIB metadata.
CallStackTrie(OptimizationRemarkEmitter *ORE=nullptr, uint64_t MaxColdSize=0)
Helper class to iterate through stack ids in both metadata (memprof MIB and callsite) and the corresp...
CallStack(const NodeT *N=nullptr)
CallStackIterator begin() const
CallStackIterator beginAfterSharedPrefix(const CallStack &Other)
CallStackIterator end() const
@ C
The default llvm calling convention, compatible with C.
LLVM_ABI MDNode * buildCallstackMetadata(ArrayRef< uint64_t > CallStack, LLVMContext &Ctx)
Build callstack metadata from the provided list of call stack ids.
LLVM_ABI bool recordContextSizeInfoForAnalysis()
Whether we need to record the context size info in the alloc trie used to build metadata.
LLVM_ABI bool metadataIncludesAllContextSizeInfo()
Whether the alloc memeprof metadata will include context size info for all MIBs.
LLVM_ABI AllocationType getMIBAllocType(const MDNode *MIB)
Returns the allocation type from an MIB metadata node.
LLVM_ABI bool metadataMayIncludeContextSizeInfo()
Whether the alloc memprof metadata may include context size info for some MIBs (but possibly not all)...
LLVM_ABI bool hasSingleAllocType(uint8_t AllocTypes)
True if the AllocTypes bitmask contains just a single type.
LLVM_ABI std::string getAllocTypeAttributeString(AllocationType Type)
Returns the string to use in attributes with the given type.
LLVM_ABI MDNode * getMIBStackNode(const MDNode *MIB)
Returns the stack node from an MIB metadata node.
LLVM_ABI void removeAnyExistingAmbiguousAttribute(CallBase *CB)
Removes any existing "ambiguous" memprof attribute.
LLVM_ABI void addAmbiguousAttribute(CallBase *CB)
Adds an "ambiguous" memprof attribute to call with a matched allocation profile but that we haven't y...
This is an optimization pass for GlobalISel generic memory operations.
bool operator!=(const CallStackIterator &rhs)
bool operator==(const CallStackIterator &rhs)
CallStackIterator(const NodeT *N, bool End)