14#ifndef LLVM_ANALYSIS_MEMORYPROFILEINFO_H
15#define LLVM_ANALYSIS_MEMORYPROFILEINFO_H
87 struct CallStackTrieNode {
96 std::vector<ContextSizeTypePair> ContextInfo;
98 std::map<uint64_t, CallStackTrieNode *> Callers;
105 AllocTypes &= ~static_cast<uint8_t>(
AllocType);
113 CallStackTrieNode *Alloc =
nullptr;
128 bool BuiltFromExistingMetadata =
false;
130 void deleteTrieNode(CallStackTrieNode *
Node) {
133 for (
auto C :
Node->Callers)
134 deleteTrieNode(
C.second);
141 void collectContextInfo(CallStackTrieNode *
Node,
142 std::vector<ContextSizeTypePair> &ContextInfo);
147 void convertHotToNotCold(CallStackTrieNode *
Node);
151 std::vector<uint64_t> &MIBCallStack,
152 std::vector<Metadata *> &MIBNodes,
153 bool CalleeHasAmbiguousCallerContext,
uint64_t &TotalBytes,
159 : ORE(ORE), MaxColdSize(MaxColdSize) {}
162 bool empty()
const {
return Alloc ==
nullptr; }
171 std::vector<ContextTotalSize> ContextSizeInfo = {});
198template <
class NodeT,
class IteratorT>
class CallStack {
207 const NodeT *
N =
nullptr;
216 bool empty()
const {
return N ==
nullptr; }
218 CallStackIterator
begin()
const;
224 const NodeT *
N =
nullptr;
227template <
class NodeT,
class IteratorT>
229 const NodeT *
N,
bool End)
235 Iter =
End ?
N->StackIdIndices.end() :
N->StackIdIndices.begin();
238template <
class NodeT,
class IteratorT>
244template <
class NodeT,
class IteratorT>
247 return N->StackIdIndices.back();
250template <
class NodeT,
class IteratorT>
256template <
class NodeT,
class IteratorT>
261 Cur !=
end() && OtherCur !=
Other.end(); ++Cur, ++OtherCur)
262 assert(*Cur == *OtherCur);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
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.
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
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.
std::pair< ContextTotalSize, AllocationType > ContextSizeTypePair
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 bool isAmbiguousAllocType(uint8_t AllocTypes)
True if the AllocTypes bitmask contains both NotCold and Cold, i.e.
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.
@ End
Run the machine verifier once, at the end of the pipeline.
bool operator!=(const CallStackIterator &rhs)
bool operator==(const CallStackIterator &rhs)
CallStackIterator(const NodeT *N, bool End)