13#ifndef LLVM_ANALYSIS_MEMORYPROFILEINFO_H
14#define LLVM_ANALYSIS_MEMORYPROFILEINFO_H
77 struct CallStackTrieNode {
85 std::vector<ContextTotalSize> ContextSizeInfo;
87 std::map<uint64_t, CallStackTrieNode *> Callers;
94 AllocTypes &= ~static_cast<uint8_t>(
AllocType);
102 CallStackTrieNode *Alloc =
nullptr;
117 bool BuiltFromExistingMetadata =
false;
119 void deleteTrieNode(CallStackTrieNode *
Node) {
122 for (
auto C :
Node->Callers)
123 deleteTrieNode(
C.second);
129 void collectContextSizeInfo(CallStackTrieNode *
Node,
130 std::vector<ContextTotalSize> &ContextSizeInfo);
135 void convertHotToNotCold(CallStackTrieNode *
Node);
139 std::vector<uint64_t> &MIBCallStack,
140 std::vector<Metadata *> &MIBNodes,
141 bool CalleeHasAmbiguousCallerContext,
uint64_t &TotalBytes,
147 : ORE(ORE), MaxColdSize(MaxColdSize) {}
150 bool empty()
const {
return Alloc ==
nullptr; }
159 std::vector<ContextTotalSize> ContextSizeInfo = {});
186template <
class NodeT,
class IteratorT>
class CallStack {
195 const NodeT *
N =
nullptr;
204 bool empty()
const {
return N ==
nullptr; }
206 CallStackIterator
begin()
const;
212 const NodeT *
N =
nullptr;
215template <
class NodeT,
class IteratorT>
217 const NodeT *
N,
bool End)
223 Iter = End ?
N->StackIdIndices.end() :
N->StackIdIndices.begin();
226template <
class NodeT,
class IteratorT>
232template <
class NodeT,
class IteratorT>
235 return N->StackIdIndices.back();
238template <
class NodeT,
class IteratorT>
244template <
class NodeT,
class IteratorT>
249 Cur !=
end() && OtherCur !=
Other.end(); ++Cur, ++OtherCur)
250 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 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.
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)