LLVM: include/llvm/Analysis/MemoryProfileInfo.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef LLVM_ANALYSIS_MEMORYPROFILEINFO_H
14#define LLVM_ANALYSIS_MEMORYPROFILEINFO_H
15
19#include
20
21namespace llvm {
22
24
26
27
28
30
31
32
34
35
36
38
39
40
43
44
45
49
50
52
53
55
56
58
59
61
62
63
65
66
67
69
70
71
72
73
74
76private:
77 struct CallStackTrieNode {
78
79
81
82
83
84
85 std::vector ContextSizeInfo;
86
87 std::map<uint64_t, CallStackTrieNode *> Callers;
89 : AllocTypes(static_cast<uint8_t>(Type)) {}
92 }
94 AllocTypes &= ~static_cast<uint8_t>(AllocType);
95 }
98 }
99 };
100
101
102 CallStackTrieNode *Alloc = nullptr;
103
105
106
107
109
110
112
113
114
115
116
117 bool BuiltFromExistingMetadata = false;
118
119 void deleteTrieNode(CallStackTrieNode *Node) {
121 return;
122 for (auto C : Node->Callers)
123 deleteTrieNode(C.second);
125 }
126
127
128
129 void collectContextSizeInfo(CallStackTrieNode *Node,
130 std::vector &ContextSizeInfo);
131
132
133
134
135 void convertHotToNotCold(CallStackTrieNode *Node);
136
137
138 bool buildMIBNodes(CallStackTrieNode *Node, LLVMContext &Ctx,
139 std::vector<uint64_t> &MIBCallStack,
140 std::vector<Metadata *> &MIBNodes,
141 bool CalleeHasAmbiguousCallerContext, uint64_t &TotalBytes,
143
144public:
147 : ORE(ORE), MaxColdSize(MaxColdSize) {}
149
150 bool empty() const { return Alloc == nullptr; }
151
152
153
154
155
156
159 std::vector ContextSizeInfo = {});
160
161
162
164
165
166
167
168
169
170
171
173
174
175
176
179};
180
181
182
183
184
185
186template <class NodeT, class IteratorT> class CallStack {
187public:
188 CallStack(const NodeT *N = nullptr) : N(N) {}
189
190
191
192
193
202 };
203
204 bool empty() const { return N == nullptr; }
205
206 CallStackIterator begin() const;
210
211private:
212 const NodeT *N = nullptr;
213};
214
215template <class NodeT, class IteratorT>
217 const NodeT *N, bool End)
219 if () {
220 Iter = nullptr;
221 return;
222 }
223 Iter = End ? N->StackIdIndices.end() : N->StackIdIndices.begin();
224}
225
226template <class NodeT, class IteratorT>
231
232template <class NodeT, class IteratorT>
235 return N->StackIdIndices.back();
236}
237
238template <class NodeT, class IteratorT>
243
244template <class NodeT, class IteratorT>
249 Cur != end() && OtherCur != Other.end(); ++Cur, ++OtherCur)
250 assert(*Cur == *OtherCur);
251 return Cur;
252}
253
254
255template <>
258 const MDNode *N, bool End);
259template <>
262template <>
264
265}
266}
267
268#endif
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.
bool empty() const
Definition MemoryProfileInfo.h:150
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()
Definition MemoryProfileInfo.h:148
CallStackTrie(OptimizationRemarkEmitter *ORE=nullptr, uint64_t MaxColdSize=0)
Definition MemoryProfileInfo.h:145
Helper class to iterate through stack ids in both metadata (memprof MIB and callsite) and the corresp...
Definition MemoryProfileInfo.h:186
CallStack(const NodeT *N=nullptr)
Definition MemoryProfileInfo.h:188
CallStackIterator begin() const
Definition MemoryProfileInfo.h:240
CallStackIterator beginAfterSharedPrefix(const CallStack &Other)
Definition MemoryProfileInfo.h:246
CallStackIterator end() const
Definition MemoryProfileInfo.h:207
uint64_t back() const
Definition MemoryProfileInfo.h:233
bool empty() const
Definition MemoryProfileInfo.h:204
@ C
The default llvm calling convention, compatible with C.
Definition MemoryProfileInfo.h:25
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)
Definition MemoryProfileInfo.h:200
void operator++()
Definition MemoryProfileInfo.h:201
IteratorT Iter
Definition MemoryProfileInfo.h:196
const NodeT * N
Definition MemoryProfileInfo.h:195
bool operator==(const CallStackIterator &rhs)
Definition MemoryProfileInfo.h:199
CallStackIterator(const NodeT *N, bool End)
Definition MemoryProfileInfo.h:216
uint64_t operator*()
Definition MemoryProfileInfo.h:227