#include "llvm/Analysis/MemoryProfileInfo.h"
#include "llvm/IR/Constants.h"
#include "llvm/Support/CommandLine.h"
usingnamespacellvm;
usingnamespacellvm::memprof;
#define DEBUG_TYPE …
cl::opt<float> MemProfLifetimeAccessDensityColdThreshold(
"memprof-lifetime-access-density-cold-threshold", cl::init(0.05),
cl::Hidden,
cl::desc("The threshold the lifetime access density (accesses per byte per "
"lifetime sec) must be under to consider an allocation cold"));
cl::opt<unsigned> MemProfAveLifetimeColdThreshold(
"memprof-ave-lifetime-cold-threshold", cl::init(200), cl::Hidden,
cl::desc("The average lifetime (s) for an allocation to be considered "
"cold"));
cl::opt<unsigned> MemProfMinAveLifetimeAccessDensityHotThreshold(
"memprof-min-ave-lifetime-access-density-hot-threshold", cl::init(1000),
cl::Hidden,
cl::desc("The minimum TotalLifetimeAccessDensity / AllocCount for an "
"allocation to be considered hot"));
cl::opt<bool> MemProfReportHintedSizes(
"memprof-report-hinted-sizes", cl::init(false), cl::Hidden,
cl::desc("Report total allocation sizes of hinted allocations"));
AllocationType llvm::memprof::getAllocType(uint64_t TotalLifetimeAccessDensity,
uint64_t AllocCount,
uint64_t TotalLifetime) { … }
MDNode *llvm::memprof::buildCallstackMetadata(ArrayRef<uint64_t> CallStack,
LLVMContext &Ctx) { … }
MDNode *llvm::memprof::getMIBStackNode(const MDNode *MIB) { … }
AllocationType llvm::memprof::getMIBAllocType(const MDNode *MIB) { … }
uint64_t llvm::memprof::getMIBTotalSize(const MDNode *MIB) { … }
std::string llvm::memprof::getAllocTypeAttributeString(AllocationType Type) { … }
static void addAllocTypeAttribute(LLVMContext &Ctx, CallBase *CI,
AllocationType AllocType) { … }
bool llvm::memprof::hasSingleAllocType(uint8_t AllocTypes) { … }
void CallStackTrie::addCallStack(AllocationType AllocType,
ArrayRef<uint64_t> StackIds,
uint64_t TotalSize) { … }
void CallStackTrie::addCallStack(MDNode *MIB) { … }
static MDNode *createMIBNode(LLVMContext &Ctx, ArrayRef<uint64_t> MIBCallStack,
AllocationType AllocType, uint64_t TotalSize) { … }
bool CallStackTrie::buildMIBNodes(CallStackTrieNode *Node, LLVMContext &Ctx,
std::vector<uint64_t> &MIBCallStack,
std::vector<Metadata *> &MIBNodes,
bool CalleeHasAmbiguousCallerContext) { … }
bool CallStackTrie::buildAndAttachMIBMetadata(CallBase *CI) { … }
template <>
CallStack<MDNode, MDNode::op_iterator>::CallStackIterator::CallStackIterator(
const MDNode *N, bool End)
: … { … }
template <>
uint64_t
CallStack<MDNode, MDNode::op_iterator>::CallStackIterator::operator*() { … }
template <> uint64_t CallStack<MDNode, MDNode::op_iterator>::back() const { … }