LLVM 22.0.0git
MemoryProfileInfo.cpp
Go to the documentation of this file.
1//===-- MemoryProfileInfo.cpp - memory profile info ------------------------==//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains utilities to analyze memory profile information.
10//
11//===----------------------------------------------------------------------===//
12
15#include "llvm/IR/Constants.h"
18#include "llvm/Support/Format.h"
19
20using namespace llvm;
21using namespace llvm::memprof;
22
23#define DEBUG_TYPE "memory-profile-info"
24
26 "memprof-report-hinted-sizes", cl::init(false), cl::Hidden,
27 cl::desc("Report total allocation sizes of hinted allocations"));
28
29// This is useful if we have enabled reporting of hinted sizes, and want to get
30// information from the indexing step for all contexts (especially for testing),
31// or have specified a value less than 100% for -memprof-cloning-cold-threshold.
33 "memprof-keep-all-not-cold-contexts", cl::init(false), cl::Hidden,
34 cl::desc("Keep all non-cold contexts (increases cloning overheads)"));
35
37 "memprof-cloning-cold-threshold", cl::init(100), cl::Hidden,
38 cl::desc("Min percent of cold bytes to hint alloc cold during cloning"));
39
40// Discard non-cold contexts if they overlap with much larger cold contexts,
41// specifically, if all contexts reaching a given callsite are at least this
42// percent cold byte allocations. This reduces the amount of cloning required
43// to expose the cold contexts when they greatly dominate non-cold contexts.
45 "memprof-callsite-cold-threshold", cl::init(100), cl::Hidden,
46 cl::desc("Min percent of cold bytes at a callsite to discard non-cold "
47 "contexts"));
48
49// Enable saving context size information for largest cold contexts, which can
50// be used to flag contexts for more aggressive cloning and reporting.
52 "memprof-min-percent-max-cold-size", cl::init(100), cl::Hidden,
53 cl::desc("Min percent of max cold bytes for critical cold context"));
54
58
62
67
69 LLVMContext &Ctx) {
71 StackVals.reserve(CallStack.size());
72 for (auto Id : CallStack) {
73 auto *StackValMD =
74 ValueAsMetadata::get(ConstantInt::get(Type::getInt64Ty(Ctx), Id));
75 StackVals.push_back(StackValMD);
76 }
77 return MDNode::get(Ctx, StackVals);
78}
79
81 assert(MIB->getNumOperands() >= 2);
82 // The stack metadata is the first operand of each memprof MIB metadata.
83 return cast<MDNode>(MIB->getOperand(0));
84}
85
87 assert(MIB->getNumOperands() >= 2);
88 // The allocation type is currently the second operand of each memprof
89 // MIB metadata. This will need to change as we add additional allocation
90 // types that can be applied based on the allocation profile data.
91 auto *MDS = dyn_cast<MDString>(MIB->getOperand(1));
92 assert(MDS);
93 if (MDS->getString() == "cold") {
95 } else if (MDS->getString() == "hot") {
97 }
99}
100
102 switch (Type) {
104 return "notcold";
105 break;
107 return "cold";
108 break;
110 return "hot";
111 break;
112 default:
113 assert(false && "Unexpected alloc type");
114 }
115 llvm_unreachable("invalid alloc type");
116}
117
119 const unsigned NumAllocTypes = llvm::popcount(AllocTypes);
120 assert(NumAllocTypes != 0);
121 return NumAllocTypes == 1;
122}
123
125 if (!CB->hasFnAttr("memprof"))
126 return;
127 assert(CB->getFnAttr("memprof").getValueAsString() == "ambiguous");
128 CB->removeFnAttr("memprof");
129}
130
132 // We may have an existing ambiguous attribute if we are reanalyzing
133 // after inlining.
134 if (CB->hasFnAttr("memprof")) {
135 assert(CB->getFnAttr("memprof").getValueAsString() == "ambiguous");
136 } else {
137 auto A = llvm::Attribute::get(CB->getContext(), "memprof", "ambiguous");
138 CB->addFnAttr(A);
139 }
140}
141
143 AllocationType AllocType, ArrayRef<uint64_t> StackIds,
144 std::vector<ContextTotalSize> ContextSizeInfo) {
145 bool First = true;
146 CallStackTrieNode *Curr = nullptr;
147 for (auto StackId : StackIds) {
148 // If this is the first stack frame, add or update alloc node.
149 if (First) {
150 First = false;
151 if (Alloc) {
152 assert(AllocStackId == StackId);
153 Alloc->addAllocType(AllocType);
154 } else {
155 AllocStackId = StackId;
156 Alloc = new CallStackTrieNode(AllocType);
157 }
158 Curr = Alloc;
159 continue;
160 }
161 // Update existing caller node if it exists.
162 auto [Next, Inserted] = Curr->Callers.try_emplace(StackId);
163 if (!Inserted) {
164 Curr = Next->second;
165 Curr->addAllocType(AllocType);
166 continue;
167 }
168 // Otherwise add a new caller node.
169 auto *New = new CallStackTrieNode(AllocType);
170 Next->second = New;
171 Curr = New;
172 }
173 assert(Curr);
174 llvm::append_range(Curr->ContextSizeInfo, ContextSizeInfo);
175}
176
178 // Note that we are building this from existing MD_memprof metadata.
179 BuiltFromExistingMetadata = true;
180 MDNode *StackMD = getMIBStackNode(MIB);
181 assert(StackMD);
182 std::vector<uint64_t> CallStack;
183 CallStack.reserve(StackMD->getNumOperands());
184 for (const auto &MIBStackIter : StackMD->operands()) {
185 auto *StackId = mdconst::dyn_extract<ConstantInt>(MIBStackIter);
186 assert(StackId);
187 CallStack.push_back(StackId->getZExtValue());
188 }
189 std::vector<ContextTotalSize> ContextSizeInfo;
190 // Collect the context size information if it exists.
191 if (MIB->getNumOperands() > 2) {
192 for (unsigned I = 2; I < MIB->getNumOperands(); I++) {
193 MDNode *ContextSizePair = dyn_cast<MDNode>(MIB->getOperand(I));
194 assert(ContextSizePair->getNumOperands() == 2);
195 uint64_t FullStackId =
197 ->getZExtValue();
198 uint64_t TotalSize =
200 ->getZExtValue();
201 ContextSizeInfo.push_back({FullStackId, TotalSize});
202 }
203 }
204 addCallStack(getMIBAllocType(MIB), CallStack, std::move(ContextSizeInfo));
205}
206
209 ArrayRef<ContextTotalSize> ContextSizeInfo,
210 const uint64_t MaxColdSize,
211 bool BuiltFromExistingMetadata,
212 uint64_t &TotalBytes, uint64_t &ColdBytes) {
213 SmallVector<Metadata *> MIBPayload(
214 {buildCallstackMetadata(MIBCallStack, Ctx)});
215 MIBPayload.push_back(
217
218 if (ContextSizeInfo.empty()) {
219 // The profile matcher should have provided context size info if there was a
220 // MinCallsiteColdBytePercent < 100. Here we check >=100 to gracefully
221 // handle a user-provided percent larger than 100. However, we may not have
222 // this information if we built the Trie from existing MD_memprof metadata.
223 assert(BuiltFromExistingMetadata || MinCallsiteColdBytePercent >= 100);
224 return MDNode::get(Ctx, MIBPayload);
225 }
226
227 for (const auto &[FullStackId, TotalSize] : ContextSizeInfo) {
228 TotalBytes += TotalSize;
229 bool LargeColdContext = false;
231 ColdBytes += TotalSize;
232 // If we have the max cold context size from summary information and have
233 // requested identification of contexts above a percentage of the max, see
234 // if this context qualifies.
235 if (MaxColdSize > 0 && MinPercentMaxColdSize < 100 &&
236 TotalSize * 100 >= MaxColdSize * MinPercentMaxColdSize)
237 LargeColdContext = true;
238 }
239 // Only add the context size info as metadata if we need it in the thin
240 // link (currently if reporting of hinted sizes is enabled, we have
241 // specified a threshold for marking allocations cold after cloning, or we
242 // have identified this as a large cold context of interest above).
243 if (metadataIncludesAllContextSizeInfo() || LargeColdContext) {
244 auto *FullStackIdMD = ValueAsMetadata::get(
245 ConstantInt::get(Type::getInt64Ty(Ctx), FullStackId));
246 auto *TotalSizeMD = ValueAsMetadata::get(
247 ConstantInt::get(Type::getInt64Ty(Ctx), TotalSize));
248 auto *ContextSizeMD = MDNode::get(Ctx, {FullStackIdMD, TotalSizeMD});
249 MIBPayload.push_back(ContextSizeMD);
250 }
251 }
252 assert(TotalBytes > 0);
253 return MDNode::get(Ctx, MIBPayload);
254}
255
256void CallStackTrie::collectContextSizeInfo(
257 CallStackTrieNode *Node, std::vector<ContextTotalSize> &ContextSizeInfo) {
258 llvm::append_range(ContextSizeInfo, Node->ContextSizeInfo);
259 for (auto &Caller : Node->Callers)
260 collectContextSizeInfo(Caller.second, ContextSizeInfo);
261}
262
263void CallStackTrie::convertHotToNotCold(CallStackTrieNode *Node) {
264 if (Node->hasAllocType(AllocationType::Hot)) {
265 Node->removeAllocType(AllocationType::Hot);
266 Node->addAllocType(AllocationType::NotCold);
267 }
268 for (auto &Caller : Node->Callers)
269 convertHotToNotCold(Caller.second);
270}
271
272// Copy over some or all of NewMIBNodes to the SavedMIBNodes vector, depending
273// on options that enable filtering out some NotCold contexts.
274static void saveFilteredNewMIBNodes(std::vector<Metadata *> &NewMIBNodes,
275 std::vector<Metadata *> &SavedMIBNodes,
276 unsigned CallerContextLength,
277 uint64_t TotalBytes, uint64_t ColdBytes,
278 bool BuiltFromExistingMetadata) {
279 const bool MostlyCold =
280 // If we have built the Trie from existing MD_memprof metadata, we may or
281 // may not have context size information (in which case ColdBytes and
282 // TotalBytes are 0, which is not also guarded against below). Even if we
283 // do have some context size information from the the metadata, we have
284 // already gone through a round of discarding of small non-cold contexts
285 // during matching, and it would be overly aggressive to do it again, and
286 // we also want to maintain the same behavior with and without reporting
287 // of hinted bytes enabled.
288 !BuiltFromExistingMetadata && MinCallsiteColdBytePercent < 100 &&
289 ColdBytes > 0 &&
290 ColdBytes * 100 >= MinCallsiteColdBytePercent * TotalBytes;
291
292 // In the simplest case, with pruning disabled, keep all the new MIB nodes.
293 if (MemProfKeepAllNotColdContexts && !MostlyCold) {
294 append_range(SavedMIBNodes, NewMIBNodes);
295 return;
296 }
297
298 auto EmitMessageForRemovedContexts = [](const MDNode *MIBMD, StringRef Tag,
299 StringRef Extra) {
300 assert(MIBMD->getNumOperands() > 2);
301 for (unsigned I = 2; I < MIBMD->getNumOperands(); I++) {
302 MDNode *ContextSizePair = dyn_cast<MDNode>(MIBMD->getOperand(I));
303 assert(ContextSizePair->getNumOperands() == 2);
304 uint64_t FullStackId =
306 ->getZExtValue();
307 uint64_t TS =
309 ->getZExtValue();
310 errs() << "MemProf hinting: Total size for " << Tag
311 << " non-cold full allocation context hash " << FullStackId
312 << Extra << ": " << TS << "\n";
313 }
314 };
315
316 // If the cold bytes at the current callsite exceed the given threshold, we
317 // discard all non-cold contexts so do not need any of the later pruning
318 // handling. We can simply copy over all the cold contexts and return early.
319 if (MostlyCold) {
320 auto NewColdMIBNodes =
321 make_filter_range(NewMIBNodes, [&](const Metadata *M) {
322 auto MIBMD = cast<MDNode>(M);
323 // Only append cold contexts.
325 return true;
327 const float PercentCold = ColdBytes * 100.0 / TotalBytes;
328 std::string PercentStr;
329 llvm::raw_string_ostream OS(PercentStr);
330 OS << format(" for %5.2f%% cold bytes", PercentCold);
331 EmitMessageForRemovedContexts(MIBMD, "discarded", OS.str());
332 }
333 return false;
334 });
335 for (auto *M : NewColdMIBNodes)
336 SavedMIBNodes.push_back(M);
337 return;
338 }
339
340 // Prune unneeded NotCold contexts, taking advantage of the fact
341 // that we later will only clone Cold contexts, as NotCold is the allocation
342 // default. We only need to keep as metadata the NotCold contexts that
343 // overlap the longest with Cold allocations, so that we know how deeply we
344 // need to clone. For example, assume we add the following contexts to the
345 // trie:
346 // 1 3 (notcold)
347 // 1 2 4 (cold)
348 // 1 2 5 (notcold)
349 // 1 2 6 (notcold)
350 // the trie looks like:
351 // 1
352 // / \
353 // 2 3
354 // /|\
355 // 4 5 6
356 //
357 // It is sufficient to prune all but one not-cold contexts (either 1,2,5 or
358 // 1,2,6, we arbitrarily keep the first one we encounter which will be
359 // 1,2,5).
360 //
361 // To do this pruning, we first check if there were any not-cold
362 // contexts kept for a deeper caller, which will have a context length larger
363 // than the CallerContextLength being handled here (i.e. kept by a deeper
364 // recursion step). If so, none of the not-cold MIB nodes added for the
365 // immediate callers need to be kept. If not, we keep the first (created
366 // for the immediate caller) not-cold MIB node.
367 bool LongerNotColdContextKept = false;
368 for (auto *MIB : NewMIBNodes) {
369 auto MIBMD = cast<MDNode>(MIB);
371 continue;
372 MDNode *StackMD = getMIBStackNode(MIBMD);
373 assert(StackMD);
374 if (StackMD->getNumOperands() > CallerContextLength) {
375 LongerNotColdContextKept = true;
376 break;
377 }
378 }
379 // Don't need to emit any for the immediate caller if we already have
380 // longer overlapping contexts;
381 bool KeepFirstNewNotCold = !LongerNotColdContextKept;
382 auto NewColdMIBNodes = make_filter_range(NewMIBNodes, [&](const Metadata *M) {
383 auto MIBMD = cast<MDNode>(M);
384 // Only keep cold contexts and first (longest non-cold context).
386 MDNode *StackMD = getMIBStackNode(MIBMD);
387 assert(StackMD);
388 // Keep any already kept for longer contexts.
389 if (StackMD->getNumOperands() > CallerContextLength)
390 return true;
391 // Otherwise keep the first one added by the immediate caller if there
392 // were no longer contexts.
393 if (KeepFirstNewNotCold) {
394 KeepFirstNewNotCold = false;
395 return true;
396 }
398 EmitMessageForRemovedContexts(MIBMD, "pruned", "");
399 return false;
400 }
401 return true;
402 });
403 for (auto *M : NewColdMIBNodes)
404 SavedMIBNodes.push_back(M);
405}
406
407// Recursive helper to trim contexts and create metadata nodes.
408// Caller should have pushed Node's loc to MIBCallStack. Doing this in the
409// caller makes it simpler to handle the many early returns in this method.
410// Updates the total and cold profiled bytes in the subtrie rooted at this node.
411bool CallStackTrie::buildMIBNodes(CallStackTrieNode *Node, LLVMContext &Ctx,
412 std::vector<uint64_t> &MIBCallStack,
413 std::vector<Metadata *> &MIBNodes,
414 bool CalleeHasAmbiguousCallerContext,
415 uint64_t &TotalBytes, uint64_t &ColdBytes) {
416 // Trim context below the first node in a prefix with a single alloc type.
417 // Add an MIB record for the current call stack prefix.
418 if (hasSingleAllocType(Node->AllocTypes)) {
419 std::vector<ContextTotalSize> ContextSizeInfo;
420 collectContextSizeInfo(Node, ContextSizeInfo);
421 MIBNodes.push_back(createMIBNode(
422 Ctx, MIBCallStack, (AllocationType)Node->AllocTypes, ContextSizeInfo,
423 MaxColdSize, BuiltFromExistingMetadata, TotalBytes, ColdBytes));
424 return true;
425 }
426
427 // We don't have a single allocation for all the contexts sharing this prefix,
428 // so recursively descend into callers in trie.
429 if (!Node->Callers.empty()) {
430 bool NodeHasAmbiguousCallerContext = Node->Callers.size() > 1;
431 bool AddedMIBNodesForAllCallerContexts = true;
432 // Accumulate all new MIB nodes by the recursive calls below into a vector
433 // that will later be filtered before adding to the caller's MIBNodes
434 // vector.
435 std::vector<Metadata *> NewMIBNodes;
436 // Determine the total and cold byte counts for all callers, then add to the
437 // caller's counts further below.
438 uint64_t CallerTotalBytes = 0;
439 uint64_t CallerColdBytes = 0;
440 for (auto &Caller : Node->Callers) {
441 MIBCallStack.push_back(Caller.first);
442 AddedMIBNodesForAllCallerContexts &= buildMIBNodes(
443 Caller.second, Ctx, MIBCallStack, NewMIBNodes,
444 NodeHasAmbiguousCallerContext, CallerTotalBytes, CallerColdBytes);
445 // Remove Caller.
446 MIBCallStack.pop_back();
447 }
448 // Pass in the stack length of the MIB nodes added for the immediate caller,
449 // which is the current stack length plus 1.
450 saveFilteredNewMIBNodes(NewMIBNodes, MIBNodes, MIBCallStack.size() + 1,
451 CallerTotalBytes, CallerColdBytes,
452 BuiltFromExistingMetadata);
453 TotalBytes += CallerTotalBytes;
454 ColdBytes += CallerColdBytes;
455
456 if (AddedMIBNodesForAllCallerContexts)
457 return true;
458 // We expect that the callers should be forced to add MIBs to disambiguate
459 // the context in this case (see below).
460 assert(!NodeHasAmbiguousCallerContext);
461 }
462
463 // If we reached here, then this node does not have a single allocation type,
464 // and we didn't add metadata for a longer call stack prefix including any of
465 // Node's callers. That means we never hit a single allocation type along all
466 // call stacks with this prefix. This can happen due to recursion collapsing
467 // or the stack being deeper than tracked by the profiler runtime, leading to
468 // contexts with different allocation types being merged. In that case, we
469 // trim the context just below the deepest context split, which is this
470 // node if the callee has an ambiguous caller context (multiple callers),
471 // since the recursive calls above returned false. Conservatively give it
472 // non-cold allocation type.
473 if (!CalleeHasAmbiguousCallerContext)
474 return false;
475 std::vector<ContextTotalSize> ContextSizeInfo;
476 collectContextSizeInfo(Node, ContextSizeInfo);
477 MIBNodes.push_back(createMIBNode(
478 Ctx, MIBCallStack, AllocationType::NotCold, ContextSizeInfo, MaxColdSize,
479 BuiltFromExistingMetadata, TotalBytes, ColdBytes));
480 return true;
481}
482
484 StringRef Descriptor) {
485 auto AllocTypeString = getAllocTypeAttributeString(AT);
486 auto A = llvm::Attribute::get(CI->getContext(), "memprof", AllocTypeString);
487 // After inlining we may be able to convert an existing ambiguous allocation
488 // to an unambiguous one.
490 CI->addFnAttr(A);
492 std::vector<ContextTotalSize> ContextSizeInfo;
493 collectContextSizeInfo(Alloc, ContextSizeInfo);
494 for (const auto &[FullStackId, TotalSize] : ContextSizeInfo) {
495 errs() << "MemProf hinting: Total size for full allocation context hash "
496 << FullStackId << " and " << Descriptor << " alloc type "
497 << getAllocTypeAttributeString(AT) << ": " << TotalSize << "\n";
498 }
499 }
500 if (ORE)
501 ORE->emit(OptimizationRemark(DEBUG_TYPE, "MemprofAttribute", CI)
502 << ore::NV("AllocationCall", CI) << " in function "
503 << ore::NV("Caller", CI->getFunction())
504 << " marked with memprof allocation attribute "
505 << ore::NV("Attribute", AllocTypeString));
506}
507
508// Build and attach the minimal necessary MIB metadata. If the alloc has a
509// single allocation type, add a function attribute instead. Returns true if
510// memprof metadata attached, false if not (attribute added).
512 if (hasSingleAllocType(Alloc->AllocTypes)) {
513 addSingleAllocTypeAttribute(CI, (AllocationType)Alloc->AllocTypes,
514 "single");
515 return false;
516 }
517 // If there were any hot allocation contexts, the Alloc trie node would have
518 // the Hot type set. If so, because we don't currently support cloning for hot
519 // contexts, they should be converted to NotCold. This happens in the cloning
520 // support anyway, however, doing this now enables more aggressive context
521 // trimming when building the MIB metadata (and possibly may make the
522 // allocation have a single NotCold allocation type), greatly reducing
523 // overheads in bitcode, cloning memory and cloning time.
524 if (Alloc->hasAllocType(AllocationType::Hot)) {
525 convertHotToNotCold(Alloc);
526 // Check whether we now have a single alloc type.
527 if (hasSingleAllocType(Alloc->AllocTypes)) {
528 addSingleAllocTypeAttribute(CI, (AllocationType)Alloc->AllocTypes,
529 "single");
530 return false;
531 }
532 }
533 auto &Ctx = CI->getContext();
534 std::vector<uint64_t> MIBCallStack;
535 MIBCallStack.push_back(AllocStackId);
536 std::vector<Metadata *> MIBNodes;
537 uint64_t TotalBytes = 0;
538 uint64_t ColdBytes = 0;
539 assert(!Alloc->Callers.empty() && "addCallStack has not been called yet");
540 // The CalleeHasAmbiguousCallerContext flag is meant to say whether the
541 // callee of the given node has more than one caller. Here the node being
542 // passed in is the alloc and it has no callees. So it's false.
543 if (buildMIBNodes(Alloc, Ctx, MIBCallStack, MIBNodes,
544 /*CalleeHasAmbiguousCallerContext=*/false, TotalBytes,
545 ColdBytes)) {
546 assert(MIBCallStack.size() == 1 &&
547 "Should only be left with Alloc's location in stack");
548 CI->setMetadata(LLVMContext::MD_memprof, MDNode::get(Ctx, MIBNodes));
550 return true;
551 }
552 // If there exists corner case that CallStackTrie has one chain to leaf
553 // and all node in the chain have multi alloc type, conservatively give
554 // it non-cold allocation type.
555 // FIXME: Avoid this case before memory profile created. Alternatively, select
556 // hint based on fraction cold.
558 return false;
559}
560
561template <>
563 const MDNode *N, bool End)
564 : N(N) {
565 if (!N)
566 return;
567 Iter = End ? N->op_end() : N->op_begin();
568}
569
570template <>
573 assert(Iter != N->op_end());
575 assert(StackIdCInt);
576 return StackIdCInt->getZExtValue();
577}
578
580 assert(N);
581 return mdconst::dyn_extract<ConstantInt>(N->operands().back())
582 ->getZExtValue();
583}
584
586 // TODO: Support more sophisticated merging, such as selecting the one with
587 // more bytes allocated, or implement support for carrying multiple allocation
588 // leaf contexts. For now, keep the first one.
589 if (A)
590 return A;
591 return B;
592}
593
595 // TODO: Support more sophisticated merging, which will require support for
596 // carrying multiple contexts. For now, keep the first one.
597 if (A)
598 return A;
599 return B;
600}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:213
This file contains the declarations for the subclasses of Constant, which represent the different fla...
#define DEBUG_TYPE
#define I(x, y, z)
Definition MD5.cpp:58
AllocType
LLVM_ABI cl::opt< bool > MemProfKeepAllNotColdContexts("memprof-keep-all-not-cold-contexts", cl::init(false), cl::Hidden, cl::desc("Keep all non-cold contexts (increases cloning overheads)"))
cl::opt< unsigned > MinPercentMaxColdSize("memprof-min-percent-max-cold-size", cl::init(100), cl::Hidden, cl::desc("Min percent of max cold bytes for critical cold context"))
cl::opt< bool > MemProfReportHintedSizes("memprof-report-hinted-sizes", cl::init(false), cl::Hidden, cl::desc("Report total allocation sizes of hinted allocations"))
cl::opt< unsigned > MinCallsiteColdBytePercent("memprof-callsite-cold-threshold", cl::init(100), cl::Hidden, cl::desc("Min percent of cold bytes at a callsite to discard non-cold " "contexts"))
static MDNode * createMIBNode(LLVMContext &Ctx, ArrayRef< uint64_t > MIBCallStack, AllocationType AllocType, ArrayRef< ContextTotalSize > ContextSizeInfo, const uint64_t MaxColdSize, bool BuiltFromExistingMetadata, uint64_t &TotalBytes, uint64_t &ColdBytes)
static void saveFilteredNewMIBNodes(std::vector< Metadata * > &NewMIBNodes, std::vector< Metadata * > &SavedMIBNodes, unsigned CallerContextLength, uint64_t TotalBytes, uint64_t ColdBytes, bool BuiltFromExistingMetadata)
cl::opt< unsigned > MinClonedColdBytePercent("memprof-cloning-cold-threshold", cl::init(100), cl::Hidden, cl::desc("Min percent of cold bytes to hint alloc cold during cloning"))
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
bool empty() const
empty - Check if the array is empty.
Definition ArrayRef.h:142
static LLVM_ABI Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
LLVM_ABI StringRef getValueAsString() const
Return the attribute's value as a string.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
void addFnAttr(Attribute::AttrKind Kind)
Adds the attribute to the function.
bool hasFnAttr(Attribute::AttrKind Kind) const
Determine whether this call has the given attribute.
Attribute getFnAttr(StringRef Kind) const
Get the attribute of a given kind for the function.
void removeFnAttr(Attribute::AttrKind Kind)
Removes the attribute from the function.
This is the shared class of boolean and integer constants.
Definition Constants.h:87
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
Definition Constants.h:163
LLVM_ABI const Function * getFunction() const
Return the function this instruction belongs to.
LLVM_ABI void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
Metadata node.
Definition Metadata.h:1077
static LLVM_ABI MDNode * getMergedCallsiteMetadata(MDNode *A, MDNode *B)
const MDOperand & getOperand(unsigned I) const
Definition Metadata.h:1445
ArrayRef< MDOperand > operands() const
Definition Metadata.h:1443
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1565
unsigned getNumOperands() const
Return number of MDNode operands.
Definition Metadata.h:1451
LLVM_ABI MDNode(LLVMContext &Context, unsigned ID, StorageType Storage, ArrayRef< Metadata * > Ops1, ArrayRef< Metadata * > Ops2={})
Definition Metadata.cpp:651
static LLVM_ABI MDNode * getMergedMemProfMetadata(MDNode *A, MDNode *B)
static LLVM_ABI MDString * get(LLVMContext &Context, StringRef Str)
Definition Metadata.cpp:607
void push_back(Metadata *MD)
Append an element to the tuple. This will resize the node.
Definition Metadata.h:1551
Root of the metadata hierarchy.
Definition Metadata.h:63
Diagnostic information for applied optimization remarks.
void reserve(size_type N)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
Definition Type.cpp:298
static LLVM_ABI ValueAsMetadata * get(Value *V)
Definition Metadata.cpp:502
LLVM_ABI LLVMContext & getContext() const
All values hold a context through their type.
Definition Value.cpp:1101
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.
Helper class to iterate through stack ids in both metadata (memprof MIB and callsite) and the corresp...
A raw_ostream that writes to an std::string.
std::string & str()
Returns the string's reference.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
initializer< Ty > init(const Ty &Val)
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > dyn_extract(Y &&MD)
Extract a Value from Metadata, if any.
Definition Metadata.h:694
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 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...
DiagnosticInfoOptimizationBase::Argument NV
NodeAddr< NodeBase * > Node
Definition RDFGraph.h:381
This is an optimization pass for GlobalISel generic memory operations.
int popcount(T Value) noexcept
Count the number of set bits in a value.
Definition bit.h:307
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:649
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Definition STLExtras.h:2138
iterator_range< filter_iterator< detail::IterOfRange< RangeT >, PredicateT > > make_filter_range(RangeT &&Range, PredicateT Pred)
Convenience function that takes a range of elements and a predicate, and return a new filter_iterator...
Definition STLExtras.h:564
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition Format.h:126
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
Definition ModRef.h:71
FunctionAddr VTableAddr Next
Definition InstrProf.h:141
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:565
#define N