1//=-- SampleProf.cpp - Sample profiling format support --------------------===//
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 common definitions used in the reading and writing of
10// sample profile data.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/ProfileData/SampleProf.h"
15#include "llvm/Config/llvm-config.h"
16#include "llvm/IR/DebugInfoMetadata.h"
17#include "llvm/IR/PseudoProbe.h"
18#include "llvm/ProfileData/SampleProfReader.h"
19#include "llvm/Support/CommandLine.h"
20#include "llvm/Support/Compiler.h"
21#include "llvm/Support/Debug.h"
22#include "llvm/Support/ErrorHandling.h"
23#include "llvm/Support/LEB128.h"
24#include "llvm/Support/raw_ostream.h"
25#include <algorithm>
26#include <cstdint>
27#include <string>
28#include <system_error>
29
30using namespace llvm;
31using namespace sampleprof;
32
33static cl::opt<uint64_t> ProfileSymbolListCutOff(
34 "profile-symbol-list-cutoff", cl::Hidden, cl::init(Val: -1),
35 cl::desc("Cutoff value about how many symbols in profile symbol list "
36 "will be used. This is very useful for performance debugging"));
37
38static cl::opt<bool> GenerateMergedBaseProfiles(
39 "generate-merged-base-profiles",
40 cl::desc("When generating nested context-sensitive profiles, always "
41 "generate extra base profile for function with all its context "
42 "profiles merged into it."));
43
44namespace llvm {
45namespace sampleprof {
46std::atomic<bool> FunctionSamples::ProfileIsProbeBased;
47std::atomic<bool> FunctionSamples::ProfileIsCS;
48std::atomic<bool> FunctionSamples::ProfileIsPreInlined;
49std::atomic<bool> FunctionSamples::UseMD5;
50std::atomic<bool> FunctionSamples::HasUniqSuffix = true;
51std::atomic<bool> FunctionSamples::ProfileIsFS;
52
53std::error_code
54serializeTypeMap(const TypeCountMap &Map,
55 const MapVector<FunctionId, uint32_t> &NameTable,
56 raw_ostream &OS) {
57 encodeULEB128(Value: Map.size(), OS);
58 for (const auto &[TypeName, SampleCount] : Map) {
59 if (auto NameIndexIter = NameTable.find(Key: TypeName);
60 NameIndexIter != NameTable.end()) {
61 encodeULEB128(Value: NameIndexIter->second, OS);
62 } else {
63 // If the type is not in the name table, we cannot serialize it.
64 return sampleprof_error::truncated_name_table;
65 }
66 encodeULEB128(Value: SampleCount, OS);
67 }
68 return sampleprof_error::success;
69}
70} // namespace sampleprof
71} // namespace llvm
72
73namespace {
74
75// FIXME: This class is only here to support the transition to llvm::Error. It
76// will be removed once this transition is complete. Clients should prefer to
77// deal with the Error value directly, rather than converting to error_code.
78class SampleProfErrorCategoryType : public std::error_category {
79 const char *name() const noexcept override { return "llvm.sampleprof"; }
80
81 std::string message(int IE) const override {
82 sampleprof_error E = static_cast<sampleprof_error>(IE);
83 switch (E) {
84 case sampleprof_error::success:
85 return "Success";
86 case sampleprof_error::bad_magic:
87 return "Invalid sample profile data (bad magic)";
88 case sampleprof_error::unsupported_version:
89 return "Unsupported sample profile format version";
90 case sampleprof_error::too_large:
91 return "Too much profile data";
92 case sampleprof_error::truncated:
93 return "Truncated profile data";
94 case sampleprof_error::malformed:
95 return "Malformed sample profile data";
96 case sampleprof_error::unrecognized_format:
97 return "Unrecognized sample profile encoding format";
98 case sampleprof_error::unsupported_writing_format:
99 return "Profile encoding format unsupported for writing operations";
100 case sampleprof_error::truncated_name_table:
101 return "Truncated function name table";
102 case sampleprof_error::not_implemented:
103 return "Unimplemented feature";
104 case sampleprof_error::counter_overflow:
105 return "Counter overflow";
106 case sampleprof_error::ostream_seek_unsupported:
107 return "Ostream does not support seek";
108 case sampleprof_error::uncompress_failed:
109 return "Uncompress failure";
110 case sampleprof_error::zlib_unavailable:
111 return "Zlib is unavailable";
112 case sampleprof_error::hash_mismatch:
113 return "Function hash mismatch";
114 case sampleprof_error::illegal_line_offset:
115 return "Illegal line offset in sample profile data";
116 }
117 llvm_unreachable("A value of sampleprof_error has no message.");
118 }
119};
120
121} // end anonymous namespace
122
123const std::error_category &llvm::sampleprof_category() {
124 static SampleProfErrorCategoryType ErrorCategory;
125 return ErrorCategory;
126}
127
128void LineLocation::print(raw_ostream &OS) const {
129 OS << LineOffset;
130 if (Discriminator > 0)
131 OS << "." << Discriminator;
132}
133
134raw_ostream &llvm::sampleprof::operator<<(raw_ostream &OS,
135 const LineLocation &Loc) {
136 Loc.print(OS);
137 return OS;
138}
139
140/// Merge the samples in \p Other into this record.
141/// Optionally scale sample counts by \p Weight.
142sampleprof_error SampleRecord::merge(const SampleRecord &Other,
143 uint64_t Weight) {
144 sampleprof_error Result;
145 Result = addSamples(S: Other.getSamples(), Weight);
146 CallTargets.reserve(Cap: CallTargets.size() + Other.getCallTargets().size());
147 for (const auto &I : Other.getCallTargets()) {
148 mergeSampleProfErrors(Accumulator&: Result, Result: addCalledTarget(F: I.first, S: I.second, Weight));
149 }
150 return Result;
151}
152
153std::error_code SampleRecord::serialize(
154 raw_ostream &OS, const MapVector<FunctionId, uint32_t> &NameTable) const {
155 encodeULEB128(Value: getSamples(), OS);
156 encodeULEB128(Value: getCallTargets().size(), OS);
157 for (const auto &J : getSortedCallTargets()) {
158 FunctionId Callee = J.first;
159 uint64_t CalleeSamples = J.second;
160 if (auto NameIndexIter = NameTable.find(Key: Callee);
161 NameIndexIter != NameTable.end()) {
162 encodeULEB128(Value: NameIndexIter->second, OS);
163 } else {
164 // If the callee is not in the name table, we cannot serialize it.
165 return sampleprof_error::truncated_name_table;
166 }
167 encodeULEB128(Value: CalleeSamples, OS);
168 }
169 return sampleprof_error::success;
170}
171
172#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
173LLVM_DUMP_METHOD void LineLocation::dump() const { print(dbgs()); }
174#endif
175
176void LineLocation::serialize(raw_ostream &OS) const {
177 encodeULEB128(Value: LineOffset, OS);
178 encodeULEB128(Value: Discriminator, OS);
179}
180
181/// Print the sample record to the stream \p OS indented by \p Indent.
182void SampleRecord::print(raw_ostream &OS, unsigned Indent) const {
183 OS << NumSamples;
184 if (hasCalls()) {
185 OS << ", calls:";
186 for (const auto &I : getSortedCallTargets())
187 OS << " " << I.first << ":" << I.second;
188 }
189 OS << "\n";
190}
191
192#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
193LLVM_DUMP_METHOD void SampleRecord::dump() const { print(dbgs(), 0); }
194#endif
195
196raw_ostream &llvm::sampleprof::operator<<(raw_ostream &OS,
197 const SampleRecord &Sample) {
198 Sample.print(OS, Indent: 0);
199 return OS;
200}
201
202static void printTypeCountMap(raw_ostream &OS, LineLocation Loc,
203 const TypeCountMap &TypeCountMap) {
204 if (TypeCountMap.empty()) {
205 return;
206 }
207 OS << Loc << ": vtables: ";
208 for (const auto &[Type, Count] : TypeCountMap)
209 OS << Type << ":" << Count << " ";
210 OS << "\n";
211}
212
213/// Print the samples collected for a function on stream \p OS.
214void FunctionSamples::print(raw_ostream &OS, unsigned Indent) const {
215 if (getFunctionHash())
216 OS << "CFG checksum " << getFunctionHash() << "\n";
217
218 OS << TotalSamples << ", " << TotalHeadSamples << ", " << BodySamples.size()
219 << " sampled lines\n";
220
221 OS.indent(NumSpaces: Indent);
222 if (!BodySamples.empty()) {
223 OS << "Samples collected in the function's body {\n";
224 for (const auto &[Loc, Record] : BodySamples) {
225 OS.indent(NumSpaces: Indent + 2);
226 OS << Loc << ": " << Record;
227 if (const TypeCountMap *TypeCountMap =
228 this->findCallsiteTypeSamplesAt(Loc)) {
229 OS.indent(NumSpaces: Indent + 2);
230 printTypeCountMap(OS, Loc, TypeCountMap: *TypeCountMap);
231 }
232 }
233 OS.indent(NumSpaces: Indent);
234 OS << "}\n";
235 } else {
236 OS << "No samples collected in the function's body\n";
237 }
238
239 OS.indent(NumSpaces: Indent);
240 if (!CallsiteSamples.empty()) {
241 OS << "Samples collected in inlined callsites {\n";
242 for (const auto &[Loc, FunctionSampleMap] : CallsiteSamples) {
243 for (const FunctionSamples &FuncSample :
244 llvm::make_second_range(c: FunctionSampleMap)) {
245 OS.indent(NumSpaces: Indent + 2);
246 OS << Loc << ": inlined callee: " << FuncSample.getFunction() << ": ";
247 FuncSample.print(OS, Indent: Indent + 4);
248 }
249 auto TypeSamplesIter = VirtualCallsiteTypeCounts.find(Key: Loc);
250 if (TypeSamplesIter != VirtualCallsiteTypeCounts.end()) {
251 OS.indent(NumSpaces: Indent + 2);
252 printTypeCountMap(OS, Loc, TypeCountMap: TypeSamplesIter->second);
253 }
254 }
255 OS.indent(NumSpaces: Indent);
256 OS << "}\n";
257 } else {
258 OS << "No inlined callsites in this function\n";
259 }
260}
261
262raw_ostream &llvm::sampleprof::operator<<(raw_ostream &OS,
263 const FunctionSamples &FS) {
264 FS.print(OS);
265 return OS;
266}
267
268void sampleprof::sortFuncProfiles(
269 const SampleProfileMap &ProfileMap,
270 std::vector<NameFunctionSamples> &SortedProfiles) {
271 for (const auto &I : ProfileMap) {
272 SortedProfiles.push_back(x: std::make_pair(x: I.first, y: &I.second));
273 }
274 llvm::stable_sort(Range&: SortedProfiles, C: [](const NameFunctionSamples &A,
275 const NameFunctionSamples &B) {
276 if (A.second->getTotalSamples() == B.second->getTotalSamples())
277 return A.second->getContext() < B.second->getContext();
278 return A.second->getTotalSamples() > B.second->getTotalSamples();
279 });
280}
281
282unsigned FunctionSamples::getOffset(const DILocation *DIL) {
283 return (DIL->getLine() - DIL->getScope()->getSubprogram()->getLine()) &
284 0xffff;
285}
286
287LineLocation FunctionSamples::getCallSiteIdentifier(const DILocation *DIL,
288 bool ProfileIsFS) {
289 if (FunctionSamples::ProfileIsProbeBased) {
290 // In a pseudo-probe based profile, a callsite is simply represented by the
291 // ID of the probe associated with the call instruction. The probe ID is
292 // encoded in the Discriminator field of the call instruction's debug
293 // metadata.
294 return LineLocation(PseudoProbeDwarfDiscriminator::extractProbeIndex(
295 Value: DIL->getDiscriminator()),
296 0);
297 } else {
298 unsigned Discriminator =
299 ProfileIsFS ? DIL->getDiscriminator() : DIL->getBaseDiscriminator();
300 return LineLocation(FunctionSamples::getOffset(DIL), Discriminator);
301 }
302}
303
304const FunctionSamples *FunctionSamples::findFunctionSamples(
305 const DILocation *DIL, SampleProfileReaderItaniumRemapper *Remapper,
306 const HashKeyMap<DenseMap, FunctionId, FunctionId> *FuncNameToProfNameMap)
307 const {
308 assert(DIL);
309 SmallVector<std::pair<LineLocation, StringRef>, 10> S;
310
311 const DILocation *PrevDIL = DIL;
312 for (DIL = DIL->getInlinedAt(); DIL; DIL = DIL->getInlinedAt()) {
313 // Use C++ linkage name if possible.
314 StringRef Name = PrevDIL->getScope()->getSubprogram()->getLinkageName();
315 if (Name.empty())
316 Name = PrevDIL->getScope()->getSubprogram()->getName();
317 S.emplace_back(Args: FunctionSamples::getCallSiteIdentifier(
318 DIL, ProfileIsFS: FunctionSamples::ProfileIsFS),
319 Args&: Name);
320 PrevDIL = DIL;
321 }
322
323 if (S.size() == 0)
324 return this;
325 const FunctionSamples *FS = this;
326 for (int i = S.size() - 1; i >= 0 && FS != nullptr; i--) {
327 FS = FS->findFunctionSamplesAt(Loc: S[i].first, CalleeName: S[i].second, Remapper,
328 FuncNameToProfNameMap);
329 }
330 return FS;
331}
332
333void FunctionSamples::findAllNames(DenseSet<FunctionId> &NameSet) const {
334 NameSet.insert(V: getFunction());
335 for (const auto &BS : BodySamples)
336 NameSet.insert_range(R: llvm::make_first_range(c: BS.second.getCallTargets()));
337
338 for (const auto &CS : CallsiteSamples) {
339 for (const auto &NameFS : CS.second) {
340 NameSet.insert(V: NameFS.first);
341 NameFS.second.findAllNames(NameSet);
342 }
343 }
344}
345
346const FunctionSamples *FunctionSamples::findFunctionSamplesAt(
347 const LineLocation &Loc, StringRef CalleeName,
348 SampleProfileReaderItaniumRemapper *Remapper,
349 const HashKeyMap<DenseMap, FunctionId, FunctionId> *FuncNameToProfNameMap)
350 const {
351 CalleeName = getCanonicalFnName(FnName: CalleeName);
352
353 auto I = CallsiteSamples.find(x: mapIRLocToProfileLoc(IRLoc: Loc));
354 if (I == CallsiteSamples.end())
355 return nullptr;
356 auto FS = I->second.find(x: getRepInFormat(Name: CalleeName));
357 if (FS != I->second.end())
358 return &FS->second;
359
360 if (FuncNameToProfNameMap && !FuncNameToProfNameMap->empty()) {
361 auto R = FuncNameToProfNameMap->find(Key: FunctionId(CalleeName));
362 if (R != FuncNameToProfNameMap->end()) {
363 CalleeName = R->second.stringRef();
364 auto FS = I->second.find(x: getRepInFormat(Name: CalleeName));
365 if (FS != I->second.end())
366 return &FS->second;
367 }
368 }
369
370 if (Remapper) {
371 if (auto NameInProfile = Remapper->lookUpNameInProfile(FunctionName: CalleeName)) {
372 auto FS = I->second.find(x: getRepInFormat(Name: *NameInProfile));
373 if (FS != I->second.end())
374 return &FS->second;
375 }
376 }
377 // If we cannot find exact match of the callee name, return the FS with
378 // the max total count. Only do this when CalleeName is not provided,
379 // i.e., only for indirect calls.
380 if (!CalleeName.empty())
381 return nullptr;
382 uint64_t MaxTotalSamples = 0;
383 const FunctionSamples *R = nullptr;
384 for (const auto &NameFS : I->second)
385 if (NameFS.second.getTotalSamples() >= MaxTotalSamples) {
386 MaxTotalSamples = NameFS.second.getTotalSamples();
387 R = &NameFS.second;
388 }
389 return R;
390}
391
392#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
393LLVM_DUMP_METHOD void FunctionSamples::dump() const { print(dbgs(), 0); }
394#endif
395
396std::error_code ProfileSymbolList::read(const uint8_t *Data,
397 uint64_t ListSize) {
398 // Scan forward to see how many elements we expect.
399 reserve(Size: std::min<uint64_t>(a: ProfileSymbolListCutOff,
400 b: std::count(first: Data, last: Data + ListSize, value: 0)));
401
402 const char *ListStart = reinterpret_cast<const char *>(Data);
403 uint64_t Size = 0;
404 uint64_t StrNum = 0;
405 while (Size < ListSize && StrNum < ProfileSymbolListCutOff) {
406 StringRef Str(ListStart + Size);
407 add(Name: Str);
408 Size += Str.size() + 1;
409 StrNum++;
410 }
411 if (Size != ListSize && StrNum != ProfileSymbolListCutOff)
412 return sampleprof_error::malformed;
413 return sampleprof_error::success;
414}
415
416void SampleContextTrimmer::trimAndMergeColdContextProfiles(
417 uint64_t ColdCountThreshold, bool TrimColdContext, bool MergeColdContext,
418 uint32_t ColdContextFrameLength, bool TrimBaseProfileOnly) {
419 if (!TrimColdContext && !MergeColdContext)
420 return;
421
422 // Nothing to merge if sample threshold is zero
423 if (ColdCountThreshold == 0)
424 return;
425
426 // Trimming base profiles only is mainly to honor the preinliner decsion. When
427 // MergeColdContext is true preinliner decsion is not honored anyway so turn
428 // off TrimBaseProfileOnly.
429 if (MergeColdContext)
430 TrimBaseProfileOnly = false;
431
432 // Filter the cold profiles from ProfileMap and move them into a tmp
433 // container
434 std::vector<std::pair<hash_code, const FunctionSamples *>> ColdProfiles;
435 for (const auto &I : ProfileMap) {
436 const SampleContext &Context = I.second.getContext();
437 const FunctionSamples &FunctionProfile = I.second;
438 if (FunctionProfile.getTotalSamples() < ColdCountThreshold &&
439 (!TrimBaseProfileOnly || Context.isBaseContext()))
440 ColdProfiles.emplace_back(args: I.first, args: &I.second);
441 }
442
443 // Remove the cold profile from ProfileMap and merge them into
444 // MergedProfileMap by the last K frames of context
445 SampleProfileMap MergedProfileMap;
446 for (const auto &I : ColdProfiles) {
447 if (MergeColdContext) {
448 auto MergedContext = I.second->getContext().getContextFrames();
449 if (ColdContextFrameLength < MergedContext.size())
450 MergedContext = MergedContext.take_back(N: ColdContextFrameLength);
451 // Need to set MergedProfile's context here otherwise it will be lost.
452 FunctionSamples &MergedProfile = MergedProfileMap.create(Ctx: MergedContext);
453 MergedProfile.merge(Other: *I.second);
454 }
455 ProfileMap.erase(Key: I.first);
456 }
457
458 // Move the merged profiles into ProfileMap;
459 for (const auto &I : MergedProfileMap) {
460 // Filter the cold merged profile
461 if (TrimColdContext && I.second.getTotalSamples() < ColdCountThreshold &&
462 ProfileMap.find(Ctx: I.second.getContext()) == ProfileMap.end())
463 continue;
464 // Merge the profile if the original profile exists, otherwise just insert
465 // as a new profile. If inserted as a new profile from MergedProfileMap, it
466 // already has the right context.
467 auto Ret = ProfileMap.emplace(Args&: I.second.getContext(), Args: FunctionSamples());
468 FunctionSamples &OrigProfile = Ret.first->second;
469 OrigProfile.merge(Other: I.second);
470 }
471}
472
473std::error_code ProfileSymbolList::write(raw_ostream &OS) {
474 // Sort the symbols before output. If doing compression.
475 // It will make the compression much more effective.
476 std::vector<StringRef> SortedList(Syms.begin(), Syms.end());
477 llvm::sort(C&: SortedList);
478
479 std::string OutputString;
480 for (auto &Sym : SortedList) {
481 OutputString.append(str: Sym.str());
482 OutputString.append(n: 1, c: '\0');
483 }
484
485 OS << OutputString;
486 return sampleprof_error::success;
487}
488
489void ProfileSymbolList::dump(raw_ostream &OS) const {
490 OS << "======== Dump profile symbol list ========\n";
491 std::vector<StringRef> SortedList(Syms.begin(), Syms.end());
492 llvm::sort(C&: SortedList);
493
494 for (auto &Sym : SortedList)
495 OS << Sym << "\n";
496}
497
498ProfileConverter::FrameNode *
499ProfileConverter::FrameNode::getOrCreateChildFrame(const LineLocation &CallSite,
500 FunctionId CalleeName) {
501 uint64_t Hash = FunctionSamples::getCallSiteHash(Callee: CalleeName, Callsite: CallSite);
502 auto It = AllChildFrames.find(x: Hash);
503 if (It != AllChildFrames.end()) {
504 assert(It->second.FuncName == CalleeName &&
505 "Hash collision for child context node");
506 return &It->second;
507 }
508
509 AllChildFrames[Hash] = FrameNode(CalleeName, nullptr, CallSite);
510 return &AllChildFrames[Hash];
511}
512
513ProfileConverter::ProfileConverter(SampleProfileMap &Profiles)
514 : ProfileMap(Profiles) {
515 for (auto &FuncSample : Profiles) {
516 FunctionSamples *FSamples = &FuncSample.second;
517 auto *NewNode = getOrCreateContextPath(Context: FSamples->getContext());
518 assert(!NewNode->FuncSamples && "New node cannot have sample profile");
519 NewNode->FuncSamples = FSamples;
520 }
521}
522
523ProfileConverter::FrameNode *
524ProfileConverter::getOrCreateContextPath(const SampleContext &Context) {
525 auto Node = &RootFrame;
526 LineLocation CallSiteLoc(0, 0);
527 for (auto &Callsite : Context.getContextFrames()) {
528 Node = Node->getOrCreateChildFrame(CallSite: CallSiteLoc, CalleeName: Callsite.Func);
529 CallSiteLoc = Callsite.Location;
530 }
531 return Node;
532}
533
534void ProfileConverter::convertCSProfiles(ProfileConverter::FrameNode &Node) {
535 // Process each child profile. Add each child profile to callsite profile map
536 // of the current node `Node` if `Node` comes with a profile. Otherwise
537 // promote the child profile to a standalone profile.
538 auto *NodeProfile = Node.FuncSamples;
539 for (auto &It : Node.AllChildFrames) {
540 auto &ChildNode = It.second;
541 convertCSProfiles(Node&: ChildNode);
542 auto *ChildProfile = ChildNode.FuncSamples;
543 if (!ChildProfile)
544 continue;
545 SampleContext OrigChildContext = ChildProfile->getContext();
546 uint64_t OrigChildContextHash = OrigChildContext.getHashCode();
547 // Reset the child context to be contextless.
548 ChildProfile->getContext().setFunction(OrigChildContext.getFunction());
549 if (NodeProfile) {
550 // Add child profile to the callsite profile map.
551 auto &SamplesMap = NodeProfile->functionSamplesAt(Loc: ChildNode.CallSiteLoc);
552 SamplesMap.emplace(args: OrigChildContext.getFunction(), args&: *ChildProfile);
553 NodeProfile->addTotalSamples(Num: ChildProfile->getTotalSamples());
554 // Remove the corresponding body sample for the callsite and update the
555 // total weight.
556 auto Count = NodeProfile->removeCalledTargetAndBodySample(
557 LineOffset: ChildNode.CallSiteLoc.LineOffset, Discriminator: ChildNode.CallSiteLoc.Discriminator,
558 Func: OrigChildContext.getFunction());
559 NodeProfile->removeTotalSamples(Num: Count);
560 }
561
562 uint64_t NewChildProfileHash = 0;
563 // Separate child profile to be a standalone profile, if the current parent
564 // profile doesn't exist. This is a duplicating operation when the child
565 // profile is already incorporated into the parent which is still useful and
566 // thus done optionally. It is seen that duplicating context profiles into
567 // base profiles improves the code quality for thinlto build by allowing a
568 // profile in the prelink phase for to-be-fully-inlined functions.
569 if (!NodeProfile) {
570 ProfileMap[ChildProfile->getContext()].merge(Other: *ChildProfile);
571 NewChildProfileHash = ChildProfile->getContext().getHashCode();
572 } else if (GenerateMergedBaseProfiles) {
573 ProfileMap[ChildProfile->getContext()].merge(Other: *ChildProfile);
574 NewChildProfileHash = ChildProfile->getContext().getHashCode();
575 auto &SamplesMap = NodeProfile->functionSamplesAt(Loc: ChildNode.CallSiteLoc);
576 SamplesMap[ChildProfile->getFunction()].getContext().setAttribute(
577 ContextDuplicatedIntoBase);
578 }
579
580 // Remove the original child profile. Check if MD5 of new child profile
581 // collides with old profile, in this case the [] operator already
582 // overwritten it without the need of erase.
583 if (NewChildProfileHash != OrigChildContextHash)
584 ProfileMap.erase(Key: OrigChildContextHash);
585 }
586}
587
588void ProfileConverter::convertCSProfiles() { convertCSProfiles(Node&: RootFrame); }
589