13#ifndef LLVM_ANALYSIS_MEMORYPROFILEINFO_H
14#define LLVM_ANALYSIS_MEMORYPROFILEINFO_H
23class OptimizationRemarkEmitter;
69 struct CallStackTrieNode {
77 std::vector<ContextTotalSize> ContextSizeInfo;
79 std::map<uint64_t, CallStackTrieNode *> Callers;
86 AllocTypes &= ~static_cast<uint8_t>(
AllocType);
94 CallStackTrieNode *Alloc =
nullptr;
109 bool BuiltFromExistingMetadata =
false;
111 void deleteTrieNode(CallStackTrieNode *
Node) {
114 for (
auto C :
Node->Callers)
115 deleteTrieNode(
C.second);
121 void collectContextSizeInfo(CallStackTrieNode *
Node,
122 std::vector<ContextTotalSize> &ContextSizeInfo);
127 void convertHotToNotCold(CallStackTrieNode *
Node);
131 std::vector<uint64_t> &MIBCallStack,
132 std::vector<Metadata *> &MIBNodes,
133 bool CalleeHasAmbiguousCallerContext,
uint64_t &TotalBytes,
139 : ORE(ORE), MaxColdSize(MaxColdSize) {}
142 bool empty()
const {
return Alloc ==
nullptr; }
151 std::vector<ContextTotalSize> ContextSizeInfo = {});
178template <
class NodeT,
class IteratorT>
class CallStack {
187 const NodeT *
N =
nullptr;
196 bool empty()
const {
return N ==
nullptr; }
198 CallStackIterator
begin()
const;
204 const NodeT *N =
nullptr;
207template <
class NodeT,
class IteratorT>
209 const NodeT *
N,
bool End)
215 Iter =
End ?
N->StackIdIndices.end() :
N->StackIdIndices.begin();
218template <
class NodeT,
class IteratorT>
220 assert(Iter != N->StackIdIndices.end());
224template <
class NodeT,
class IteratorT>
227 return N->StackIdIndices.back();
230template <
class NodeT,
class IteratorT>
236template <
class NodeT,
class IteratorT>
241 Cur !=
end() && OtherCur !=
Other.end(); ++Cur, ++OtherCur)
242 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.
Class to build a trie of call stack contexts for a particular profiled allocation call,...
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 MDNode * buildContextSizeMetadata(ArrayRef< ContextTotalSize > ContextSizeInfo, LLVMContext &Ctx)
Build metadata from the provided list of full stack id and profiled size, to use when reporting of hi...
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.
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)