LLVM  15.0.0git
SampleProfWriter.cpp
Go to the documentation of this file.
1 //===- SampleProfWriter.cpp - Write LLVM sample profile data --------------===//
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 implements the class that writes LLVM sample profiles. It
10 // supports two file formats: text and binary. The textual representation
11 // is useful for debugging and testing purposes. The binary representation
12 // is more compact, resulting in smaller file sizes. However, they can
13 // both be used interchangeably.
14 //
15 // See lib/ProfileData/SampleProfReader.cpp for documentation on each of the
16 // supported formats.
17 //
18 //===----------------------------------------------------------------------===//
19 
21 #include "llvm/ADT/StringRef.h"
25 #include "llvm/Support/Endian.h"
27 #include "llvm/Support/ErrorOr.h"
29 #include "llvm/Support/LEB128.h"
30 #include "llvm/Support/MD5.h"
32 #include <algorithm>
33 #include <cstdint>
34 #include <memory>
35 #include <set>
36 #include <system_error>
37 #include <utility>
38 #include <vector>
39 
40 using namespace llvm;
41 using namespace sampleprof;
42 
43 std::error_code
45  std::vector<NameFunctionSamples> V;
46  sortFuncProfiles(ProfileMap, V);
47  for (const auto &I : V) {
48  if (std::error_code EC = writeSample(*I.second))
49  return EC;
50  }
52 }
53 
54 std::error_code SampleProfileWriter::write(const SampleProfileMap &ProfileMap) {
55  if (std::error_code EC = writeHeader(ProfileMap))
56  return EC;
57 
58  if (std::error_code EC = writeFuncProfiles(ProfileMap))
59  return EC;
60 
62 }
63 
64 /// Return the current position and prepare to use it as the start
65 /// position of a section given the section type \p Type and its position
66 /// \p LayoutIdx in SectionHdrLayout.
69  uint32_t LayoutIdx) {
70  uint64_t SectionStart = OutputStream->tell();
71  assert(LayoutIdx < SectionHdrLayout.size() && "LayoutIdx out of range");
72  const auto &Entry = SectionHdrLayout[LayoutIdx];
73  assert(Entry.Type == Type && "Unexpected section type");
74  // Use LocalBuf as a temporary output for writting data.
76  LocalBufStream.swap(OutputStream);
77  return SectionStart;
78 }
79 
80 std::error_code SampleProfileWriterExtBinaryBase::compressAndOutput() {
83  std::string &UncompressedStrings =
84  static_cast<raw_string_ostream *>(LocalBufStream.get())->str();
85  if (UncompressedStrings.size() == 0)
87  auto &OS = *OutputStream;
88  SmallString<128> CompressedStrings;
89  zlib::compress(UncompressedStrings, CompressedStrings,
91  encodeULEB128(UncompressedStrings.size(), OS);
92  encodeULEB128(CompressedStrings.size(), OS);
93  OS << CompressedStrings.str();
94  UncompressedStrings.clear();
96 }
97 
98 /// Add a new section into section header table given the section type
99 /// \p Type, its position \p LayoutIdx in SectionHdrLayout and the
100 /// location \p SectionStart where the section should be written to.
102  SecType Type, uint32_t LayoutIdx, uint64_t SectionStart) {
103  assert(LayoutIdx < SectionHdrLayout.size() && "LayoutIdx out of range");
104  const auto &Entry = SectionHdrLayout[LayoutIdx];
105  assert(Entry.Type == Type && "Unexpected section type");
107  LocalBufStream.swap(OutputStream);
108  if (std::error_code EC = compressAndOutput())
109  return EC;
110  }
111  SecHdrTable.push_back({Type, Entry.Flags, SectionStart - FileStart,
112  OutputStream->tell() - SectionStart, LayoutIdx});
114 }
115 
116 std::error_code
118  if (std::error_code EC = writeHeader(ProfileMap))
119  return EC;
120 
121  std::string LocalBuf;
122  LocalBufStream = std::make_unique<raw_string_ostream>(LocalBuf);
123  if (std::error_code EC = writeSections(ProfileMap))
124  return EC;
125 
126  if (std::error_code EC = writeSecHdrTable())
127  return EC;
128 
130 }
131 
133  const SampleContext &Context) {
134  if (Context.hasContext())
135  return writeCSNameIdx(Context);
136  else
138 }
139 
140 std::error_code
142  const auto &Ret = CSNameTable.find(Context);
143  if (Ret == CSNameTable.end())
145  encodeULEB128(Ret->second, *OutputStream);
147 }
148 
149 std::error_code
151  uint64_t Offset = OutputStream->tell();
152  auto &Context = S.getContext();
153  FuncOffsetTable[Context] = Offset - SecLBRProfileStart;
154  encodeULEB128(S.getHeadSamples(), *OutputStream);
155  return writeBody(S);
156 }
157 
159  auto &OS = *OutputStream;
160 
161  // Write out the table size.
162  encodeULEB128(FuncOffsetTable.size(), OS);
163 
164  // Write out FuncOffsetTable.
165  auto WriteItem = [&](const SampleContext &Context, uint64_t Offset) {
166  if (std::error_code EC = writeContextIdx(Context))
167  return EC;
168  encodeULEB128(Offset, OS);
169  return (std::error_code)sampleprof_error::success;
170  };
171 
173  // Sort the contexts before writing them out. This is to help fast load all
174  // context profiles for a function as well as their callee contexts which
175  // can help profile-guided importing for ThinLTO.
176  std::map<SampleContext, uint64_t> OrderedFuncOffsetTable(
177  FuncOffsetTable.begin(), FuncOffsetTable.end());
178  for (const auto &Entry : OrderedFuncOffsetTable) {
179  if (std::error_code EC = WriteItem(Entry.first, Entry.second))
180  return EC;
181  }
183  } else {
184  for (const auto &Entry : FuncOffsetTable) {
185  if (std::error_code EC = WriteItem(Entry.first, Entry.second))
186  return EC;
187  }
188  }
189 
190  FuncOffsetTable.clear();
192 }
193 
195  const FunctionSamples &FunctionProfile) {
196  auto &OS = *OutputStream;
197  if (std::error_code EC = writeContextIdx(FunctionProfile.getContext()))
198  return EC;
199 
201  encodeULEB128(FunctionProfile.getFunctionHash(), OS);
203  encodeULEB128(FunctionProfile.getContext().getAllAttributes(), OS);
204  }
205 
207  // Recursively emit attributes for all callee samples.
208  uint64_t NumCallsites = 0;
209  for (const auto &J : FunctionProfile.getCallsiteSamples())
210  NumCallsites += J.second.size();
211  encodeULEB128(NumCallsites, OS);
212  for (const auto &J : FunctionProfile.getCallsiteSamples()) {
213  for (const auto &FS : J.second) {
214  LineLocation Loc = J.first;
215  encodeULEB128(Loc.LineOffset, OS);
216  encodeULEB128(Loc.Discriminator, OS);
217  if (std::error_code EC = writeFuncMetadata(FS.second))
218  return EC;
219  }
220  }
221  }
222 
224 }
225 
227  const SampleProfileMap &Profiles) {
231  for (const auto &Entry : Profiles) {
232  if (std::error_code EC = writeFuncMetadata(Entry.second))
233  return EC;
234  }
236 }
237 
239  if (!UseMD5)
241 
242  auto &OS = *OutputStream;
243  std::set<StringRef> V;
245 
246  // Write out the MD5 name table. We wrote unencoded MD5 so reader can
247  // retrieve the name using the name index without having to read the
248  // whole name table.
249  encodeULEB128(NameTable.size(), OS);
251  for (auto N : V)
252  Writer.write(MD5Hash(N));
254 }
255 
257  const SampleProfileMap &ProfileMap) {
258  for (const auto &I : ProfileMap) {
259  assert(I.first == I.second.getContext() && "Inconsistent profile map");
260  addContext(I.second.getContext());
261  addNames(I.second);
262  }
263 
264  // If NameTable contains ".__uniq." suffix, set SecFlagUniqSuffix flag
265  // so compiler won't strip the suffix during profile matching after
266  // seeing the flag in the profile.
267  for (const auto &I : NameTable) {
268  if (I.first.contains(FunctionSamples::UniqSuffix)) {
270  break;
271  }
272  }
273 
274  if (auto EC = writeNameTable())
275  return EC;
277 }
278 
280  // Sort the names to make CSNameTable deterministic.
281  std::set<SampleContext> OrderedContexts;
282  for (const auto &I : CSNameTable)
283  OrderedContexts.insert(I.first);
284  assert(OrderedContexts.size() == CSNameTable.size() &&
285  "Unmatched ordered and unordered contexts");
286  uint64_t I = 0;
287  for (auto &Context : OrderedContexts)
288  CSNameTable[Context] = I++;
289 
290  auto &OS = *OutputStream;
291  encodeULEB128(OrderedContexts.size(), OS);
293  for (auto Context : OrderedContexts) {
294  auto Frames = Context.getContextFrames();
295  encodeULEB128(Frames.size(), OS);
296  for (auto &Callsite : Frames) {
297  if (std::error_code EC = writeNameIdx(Callsite.FuncName))
298  return EC;
299  encodeULEB128(Callsite.Location.LineOffset, OS);
300  encodeULEB128(Callsite.Location.Discriminator, OS);
301  }
302  }
303 
305 }
306 
307 std::error_code
309  if (ProfSymList && ProfSymList->size() > 0)
310  if (std::error_code EC = ProfSymList->write(*OutputStream))
311  return EC;
312 
314 }
315 
317  SecType Type, uint32_t LayoutIdx, const SampleProfileMap &ProfileMap) {
318  // The setting of SecFlagCompress should happen before markSectionStart.
319  if (Type == SecProfileSymbolList && ProfSymList && ProfSymList->toCompress())
323  if (Type == SecFuncMetadata &&
332 
333  uint64_t SectionStart = markSectionStart(Type, LayoutIdx);
334  switch (Type) {
335  case SecProfSummary:
336  computeSummary(ProfileMap);
337  if (auto EC = writeSummary())
338  return EC;
339  break;
340  case SecNameTable:
341  if (auto EC = writeNameTableSection(ProfileMap))
342  return EC;
343  break;
344  case SecCSNameTable:
345  if (auto EC = writeCSNameTableSection())
346  return EC;
347  break;
348  case SecLBRProfile:
350  if (std::error_code EC = writeFuncProfiles(ProfileMap))
351  return EC;
352  break;
353  case SecFuncOffsetTable:
354  if (auto EC = writeFuncOffsetTable())
355  return EC;
356  break;
357  case SecFuncMetadata:
358  if (std::error_code EC = writeFuncMetadata(ProfileMap))
359  return EC;
360  break;
362  if (auto EC = writeProfileSymbolListSection())
363  return EC;
364  break;
365  default:
366  if (auto EC = writeCustomSection(Type))
367  return EC;
368  break;
369  }
370  if (std::error_code EC = addNewSection(Type, LayoutIdx, SectionStart))
371  return EC;
373 }
374 
375 std::error_code SampleProfileWriterExtBinary::writeDefaultLayout(
376  const SampleProfileMap &ProfileMap) {
377  // The const indices passed to writeOneSection below are specifying the
378  // positions of the sections in SectionHdrLayout. Look at
379  // initSectionHdrLayout to find out where each section is located in
380  // SectionHdrLayout.
381  if (auto EC = writeOneSection(SecProfSummary, 0, ProfileMap))
382  return EC;
383  if (auto EC = writeOneSection(SecNameTable, 1, ProfileMap))
384  return EC;
385  if (auto EC = writeOneSection(SecCSNameTable, 2, ProfileMap))
386  return EC;
387  if (auto EC = writeOneSection(SecLBRProfile, 4, ProfileMap))
388  return EC;
389  if (auto EC = writeOneSection(SecProfileSymbolList, 5, ProfileMap))
390  return EC;
391  if (auto EC = writeOneSection(SecFuncOffsetTable, 3, ProfileMap))
392  return EC;
393  if (auto EC = writeOneSection(SecFuncMetadata, 6, ProfileMap))
394  return EC;
396 }
397 
398 static void splitProfileMapToTwo(const SampleProfileMap &ProfileMap,
399  SampleProfileMap &ContextProfileMap,
400  SampleProfileMap &NoContextProfileMap) {
401  for (const auto &I : ProfileMap) {
402  if (I.second.getCallsiteSamples().size())
403  ContextProfileMap.insert({I.first, I.second});
404  else
405  NoContextProfileMap.insert({I.first, I.second});
406  }
407 }
408 
409 std::error_code SampleProfileWriterExtBinary::writeCtxSplitLayout(
410  const SampleProfileMap &ProfileMap) {
411  SampleProfileMap ContextProfileMap, NoContextProfileMap;
412  splitProfileMapToTwo(ProfileMap, ContextProfileMap, NoContextProfileMap);
413 
414  if (auto EC = writeOneSection(SecProfSummary, 0, ProfileMap))
415  return EC;
416  if (auto EC = writeOneSection(SecNameTable, 1, ProfileMap))
417  return EC;
418  if (auto EC = writeOneSection(SecLBRProfile, 3, ContextProfileMap))
419  return EC;
420  if (auto EC = writeOneSection(SecFuncOffsetTable, 2, ContextProfileMap))
421  return EC;
422  // Mark the section to have no context. Note section flag needs to be set
423  // before writing the section.
425  if (auto EC = writeOneSection(SecLBRProfile, 5, NoContextProfileMap))
426  return EC;
427  // Mark the section to have no context. Note section flag needs to be set
428  // before writing the section.
430  if (auto EC = writeOneSection(SecFuncOffsetTable, 4, NoContextProfileMap))
431  return EC;
432  if (auto EC = writeOneSection(SecProfileSymbolList, 6, ProfileMap))
433  return EC;
434  if (auto EC = writeOneSection(SecFuncMetadata, 7, ProfileMap))
435  return EC;
436 
438 }
439 
440 std::error_code SampleProfileWriterExtBinary::writeSections(
441  const SampleProfileMap &ProfileMap) {
442  std::error_code EC;
443  if (SecLayout == DefaultLayout)
444  EC = writeDefaultLayout(ProfileMap);
445  else if (SecLayout == CtxSplitLayout)
446  EC = writeCtxSplitLayout(ProfileMap);
447  else
448  llvm_unreachable("Unsupported layout");
449  return EC;
450 }
451 
452 std::error_code
454  if (std::error_code EC = SampleProfileWriter::write(ProfileMap))
455  return EC;
456  if (std::error_code EC = writeFuncOffsetTable())
457  return EC;
459 }
460 
461 /// Write samples to a text file.
462 ///
463 /// Note: it may be tempting to implement this in terms of
464 /// FunctionSamples::print(). Please don't. The dump functionality is intended
465 /// for debugging and has no specified form.
466 ///
467 /// The format used here is more structured and deliberate because
468 /// it needs to be parsed by the SampleProfileReaderText class.
470  auto &OS = *OutputStream;
472  OS << "[" << S.getContext().toString() << "]:" << S.getTotalSamples();
473  else
474  OS << S.getName() << ":" << S.getTotalSamples();
475 
476  if (Indent == 0)
477  OS << ":" << S.getHeadSamples();
478  OS << "\n";
479 
480  SampleSorter<LineLocation, SampleRecord> SortedSamples(S.getBodySamples());
481  for (const auto &I : SortedSamples.get()) {
482  LineLocation Loc = I->first;
483  const SampleRecord &Sample = I->second;
484  OS.indent(Indent + 1);
485  if (Loc.Discriminator == 0)
486  OS << Loc.LineOffset << ": ";
487  else
488  OS << Loc.LineOffset << "." << Loc.Discriminator << ": ";
489 
490  OS << Sample.getSamples();
491 
492  for (const auto &J : Sample.getSortedCallTargets())
493  OS << " " << J.first << ":" << J.second;
494  OS << "\n";
495  }
496 
498  S.getCallsiteSamples());
499  Indent += 1;
500  for (const auto &I : SortedCallsiteSamples.get())
501  for (const auto &FS : I->second) {
502  LineLocation Loc = I->first;
503  const FunctionSamples &CalleeSamples = FS.second;
504  OS.indent(Indent);
505  if (Loc.Discriminator == 0)
506  OS << Loc.LineOffset << ": ";
507  else
508  OS << Loc.LineOffset << "." << Loc.Discriminator << ": ";
509  if (std::error_code EC = writeSample(CalleeSamples))
510  return EC;
511  }
512  Indent -= 1;
513 
515  OS.indent(Indent + 1);
516  OS << "!CFGChecksum: " << S.getFunctionHash() << "\n";
517  }
518 
519  if (S.getContext().getAllAttributes()) {
520  OS.indent(Indent + 1);
521  OS << "!Attributes: " << S.getContext().getAllAttributes() << "\n";
522  }
523 
525 }
526 
527 std::error_code
529  assert(!Context.hasContext() && "cs profile is not supported");
530  return writeNameIdx(Context.getName());
531 }
532 
534  auto &NTable = getNameTable();
535  const auto &Ret = NTable.find(FName);
536  if (Ret == NTable.end())
538  encodeULEB128(Ret->second, *OutputStream);
540 }
541 
543  auto &NTable = getNameTable();
544  NTable.insert(std::make_pair(FName, 0));
545 }
546 
548  addName(Context.getName());
549 }
550 
552  // Add all the names in indirect call targets.
553  for (const auto &I : S.getBodySamples()) {
554  const SampleRecord &Sample = I.second;
555  for (const auto &J : Sample.getCallTargets())
556  addName(J.first());
557  }
558 
559  // Recursively add all the names for inlined callsites.
560  for (const auto &J : S.getCallsiteSamples())
561  for (const auto &FS : J.second) {
562  const FunctionSamples &CalleeSamples = FS.second;
563  addName(CalleeSamples.getName());
564  addNames(CalleeSamples);
565  }
566 }
567 
569  const SampleContext &Context) {
570  if (Context.hasContext()) {
571  for (auto &Callsite : Context.getContextFrames())
572  SampleProfileWriterBinary::addName(Callsite.FuncName);
573  CSNameTable.insert(std::make_pair(Context, 0));
574  } else {
576  }
577 }
578 
580  MapVector<StringRef, uint32_t> &NameTable, std::set<StringRef> &V) {
581  // Sort the names to make NameTable deterministic.
582  for (const auto &I : NameTable)
583  V.insert(I.first);
584  int i = 0;
585  for (const StringRef &N : V)
586  NameTable[N] = i++;
587 }
588 
590  auto &OS = *OutputStream;
591  std::set<StringRef> V;
593 
594  // Write out the name table.
595  encodeULEB128(NameTable.size(), OS);
596  for (auto N : V) {
597  OS << N;
598  encodeULEB128(0, OS);
599  }
601 }
602 
604  auto &OS = *OutputStream;
605 
606  // Fill the slot remembered by TableOffset with the offset of FuncOffsetTable.
607  auto &OFS = static_cast<raw_fd_ostream &>(OS);
608  uint64_t FuncOffsetTableStart = OS.tell();
609  if (OFS.seek(TableOffset) == (uint64_t)-1)
612  Writer.write(FuncOffsetTableStart);
613  if (OFS.seek(FuncOffsetTableStart) == (uint64_t)-1)
615 
616  // Write out the table size.
617  encodeULEB128(FuncOffsetTable.size(), OS);
618 
619  // Write out FuncOffsetTable.
620  for (auto Entry : FuncOffsetTable) {
621  if (std::error_code EC = writeNameIdx(Entry.first))
622  return EC;
623  encodeULEB128(Entry.second, OS);
624  }
626 }
627 
629  auto &OS = *OutputStream;
630  std::set<StringRef> V;
632 
633  // Write out the name table.
634  encodeULEB128(NameTable.size(), OS);
635  for (auto N : V) {
636  encodeULEB128(MD5Hash(N), OS);
637  }
639 }
640 
641 std::error_code
643  auto &OS = *OutputStream;
644  // Write file magic identifier.
646  encodeULEB128(SPVersion(), OS);
648 }
649 
650 std::error_code
653 
654  computeSummary(ProfileMap);
655  if (auto EC = writeSummary())
656  return EC;
657 
658  // Generate the name table for all the functions referenced in the profile.
659  for (const auto &I : ProfileMap) {
660  assert(I.first == I.second.getContext() && "Inconsistent profile map");
661  addContext(I.first);
662  addNames(I.second);
663  }
664 
665  writeNameTable();
667 }
668 
670  for (auto &Entry : SectionHdrLayout)
672 }
673 
676 }
677 
678 void SampleProfileWriterExtBinaryBase::allocSecHdrTable() {
680 
681  Writer.write(static_cast<uint64_t>(SectionHdrLayout.size()));
682  SecHdrTableOffset = OutputStream->tell();
683  for (uint32_t i = 0; i < SectionHdrLayout.size(); i++) {
684  Writer.write(static_cast<uint64_t>(-1));
685  Writer.write(static_cast<uint64_t>(-1));
686  Writer.write(static_cast<uint64_t>(-1));
687  Writer.write(static_cast<uint64_t>(-1));
688  }
689 }
690 
691 std::error_code SampleProfileWriterExtBinaryBase::writeSecHdrTable() {
692  auto &OFS = static_cast<raw_fd_ostream &>(*OutputStream);
693  uint64_t Saved = OutputStream->tell();
694 
695  // Set OutputStream to the location saved in SecHdrTableOffset.
696  if (OFS.seek(SecHdrTableOffset) == (uint64_t)-1)
699 
700  assert(SecHdrTable.size() == SectionHdrLayout.size() &&
701  "SecHdrTable entries doesn't match SectionHdrLayout");
702  SmallVector<uint32_t, 16> IndexMap(SecHdrTable.size(), -1);
703  for (uint32_t TableIdx = 0; TableIdx < SecHdrTable.size(); TableIdx++) {
704  IndexMap[SecHdrTable[TableIdx].LayoutIndex] = TableIdx;
705  }
706 
707  // Write the section header table in the order specified in
708  // SectionHdrLayout. SectionHdrLayout specifies the sections
709  // order in which profile reader expect to read, so the section
710  // header table should be written in the order in SectionHdrLayout.
711  // Note that the section order in SecHdrTable may be different
712  // from the order in SectionHdrLayout, for example, SecFuncOffsetTable
713  // needs to be computed after SecLBRProfile (the order in SecHdrTable),
714  // but it needs to be read before SecLBRProfile (the order in
715  // SectionHdrLayout). So we use IndexMap above to switch the order.
716  for (uint32_t LayoutIdx = 0; LayoutIdx < SectionHdrLayout.size();
717  LayoutIdx++) {
718  assert(IndexMap[LayoutIdx] < SecHdrTable.size() &&
719  "Incorrect LayoutIdx in SecHdrTable");
720  auto Entry = SecHdrTable[IndexMap[LayoutIdx]];
721  Writer.write(static_cast<uint64_t>(Entry.Type));
722  Writer.write(static_cast<uint64_t>(Entry.Flags));
723  Writer.write(static_cast<uint64_t>(Entry.Offset));
724  Writer.write(static_cast<uint64_t>(Entry.Size));
725  }
726 
727  // Reset OutputStream.
728  if (OFS.seek(Saved) == (uint64_t)-1)
730 
732 }
733 
734 std::error_code SampleProfileWriterExtBinaryBase::writeHeader(
735  const SampleProfileMap &ProfileMap) {
736  auto &OS = *OutputStream;
737  FileStart = OS.tell();
739 
740  allocSecHdrTable();
742 }
743 
745  const SampleProfileMap &ProfileMap) {
747  if (auto EC = SampleProfileWriterBinary::writeHeader(ProfileMap))
748  return EC;
749 
750  // Reserve a slot for the offset of function offset table. The slot will
751  // be populated with the offset of FuncOffsetTable later.
752  TableOffset = OutputStream->tell();
753  Writer.write(static_cast<uint64_t>(-2));
755 }
756 
758  auto &OS = *OutputStream;
759  encodeULEB128(Summary->getTotalCount(), OS);
760  encodeULEB128(Summary->getMaxCount(), OS);
761  encodeULEB128(Summary->getMaxFunctionCount(), OS);
762  encodeULEB128(Summary->getNumCounts(), OS);
763  encodeULEB128(Summary->getNumFunctions(), OS);
764  const std::vector<ProfileSummaryEntry> &Entries =
765  Summary->getDetailedSummary();
766  encodeULEB128(Entries.size(), OS);
767  for (auto Entry : Entries) {
768  encodeULEB128(Entry.Cutoff, OS);
769  encodeULEB128(Entry.MinCount, OS);
770  encodeULEB128(Entry.NumCounts, OS);
771  }
773 }
775  auto &OS = *OutputStream;
776  if (std::error_code EC = writeContextIdx(S.getContext()))
777  return EC;
778 
779  encodeULEB128(S.getTotalSamples(), OS);
780 
781  // Emit all the body samples.
782  encodeULEB128(S.getBodySamples().size(), OS);
783  for (const auto &I : S.getBodySamples()) {
784  LineLocation Loc = I.first;
785  const SampleRecord &Sample = I.second;
786  encodeULEB128(Loc.LineOffset, OS);
787  encodeULEB128(Loc.Discriminator, OS);
788  encodeULEB128(Sample.getSamples(), OS);
789  encodeULEB128(Sample.getCallTargets().size(), OS);
790  for (const auto &J : Sample.getSortedCallTargets()) {
791  StringRef Callee = J.first;
792  uint64_t CalleeSamples = J.second;
793  if (std::error_code EC = writeNameIdx(Callee))
794  return EC;
795  encodeULEB128(CalleeSamples, OS);
796  }
797  }
798 
799  // Recursively emit all the callsite samples.
800  uint64_t NumCallsites = 0;
801  for (const auto &J : S.getCallsiteSamples())
802  NumCallsites += J.second.size();
803  encodeULEB128(NumCallsites, OS);
804  for (const auto &J : S.getCallsiteSamples())
805  for (const auto &FS : J.second) {
806  LineLocation Loc = J.first;
807  const FunctionSamples &CalleeSamples = FS.second;
808  encodeULEB128(Loc.LineOffset, OS);
809  encodeULEB128(Loc.Discriminator, OS);
810  if (std::error_code EC = writeBody(CalleeSamples))
811  return EC;
812  }
813 
815 }
816 
817 /// Write samples of a top-level function to a binary file.
818 ///
819 /// \returns true if the samples were written successfully, false otherwise.
820 std::error_code
822  encodeULEB128(S.getHeadSamples(), *OutputStream);
823  return writeBody(S);
824 }
825 
826 std::error_code
828  uint64_t Offset = OutputStream->tell();
829  StringRef Name = S.getName();
830  FuncOffsetTable[Name] = Offset;
831  encodeULEB128(S.getHeadSamples(), *OutputStream);
832  return writeBody(S);
833 }
834 
835 /// Create a sample profile file writer based on the specified format.
836 ///
837 /// \param Filename The file to create.
838 ///
839 /// \param Format Encoding format for the profile file.
840 ///
841 /// \returns an error code indicating the status of the created writer.
844  std::error_code EC;
845  std::unique_ptr<raw_ostream> OS;
846  if (Format == SPF_Binary || Format == SPF_Ext_Binary ||
848  OS.reset(new raw_fd_ostream(Filename, EC, sys::fs::OF_None));
849  else
850  OS.reset(new raw_fd_ostream(Filename, EC, sys::fs::OF_TextWithCRLF));
851  if (EC)
852  return EC;
853 
854  return create(OS, Format);
855 }
856 
857 /// Create a sample profile stream writer based on the specified format.
858 ///
859 /// \param OS The output stream to store the profile data to.
860 ///
861 /// \param Format Encoding format for the profile file.
862 ///
863 /// \returns an error code indicating the status of the created writer.
865 SampleProfileWriter::create(std::unique_ptr<raw_ostream> &OS,
866  SampleProfileFormat Format) {
867  std::error_code EC;
868  std::unique_ptr<SampleProfileWriter> Writer;
869 
870  // Currently only Text and Extended Binary format are supported for CSSPGO.
874 
875  if (Format == SPF_Binary)
876  Writer.reset(new SampleProfileWriterRawBinary(OS));
877  else if (Format == SPF_Ext_Binary)
878  Writer.reset(new SampleProfileWriterExtBinary(OS));
879  else if (Format == SPF_Compact_Binary)
880  Writer.reset(new SampleProfileWriterCompactBinary(OS));
881  else if (Format == SPF_Text)
882  Writer.reset(new SampleProfileWriterText(OS));
883  else if (Format == SPF_GCC)
885  else
887 
888  if (EC)
889  return EC;
890 
891  Writer->Format = Format;
892  return std::move(Writer);
893 }
894 
897  Summary = Builder.computeSummaryForProfiles(ProfileMap);
898 }
i
i
Definition: README.txt:29
llvm::sampleprof::SampleProfileWriter::OutputStream
std::unique_ptr< raw_ostream > OutputStream
Output stream where to emit the profile to.
Definition: SampleProfWriter.h:83
llvm::sampleprof::SampleProfileWriterBinary::NameTable
MapVector< StringRef, uint32_t > NameTable
Definition: SampleProfWriter.h:140
Compression.h
llvm::sampleprof::SampleProfileWriterText
Sample-based profile writer (text format).
Definition: SampleProfWriter.h:96
llvm::sampleprof::SampleProfileWriter::create
static ErrorOr< std::unique_ptr< SampleProfileWriter > > create(StringRef Filename, SampleProfileFormat Format)
Profile writer factory.
Definition: SampleProfWriter.cpp:843
llvm::sampleprof::CtxSplitLayout
@ CtxSplitLayout
Definition: SampleProfWriter.h:34
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::sampleprof::SecFuncMetadataFlags::SecFlagHasAttribute
@ SecFlagHasAttribute
llvm::sampleprof::SampleProfileWriterBinary::stablizeNameTable
void stablizeNameTable(MapVector< StringRef, uint32_t > &NameTable, std::set< StringRef > &V)
Definition: SampleProfWriter.cpp:579
llvm::sampleprof::SampleProfileWriterExtBinaryBase::writeNameTable
virtual std::error_code writeNameTable() override
Definition: SampleProfWriter.cpp:238
llvm::sampleprof::SecProfSummaryFlags::SecFlagFSDiscriminator
@ SecFlagFSDiscriminator
SecFlagFSDiscriminator means this profile uses flow-sensitive discriminators.
llvm::sampleprof::SampleSorter::get
const SamplesWithLocList & get() const
Definition: SampleProf.h:1217
FileSystem.h
llvm::sys::fs::OF_None
@ OF_None
Definition: FileSystem.h:757
llvm::sampleprof::FunctionSamples::ProfileIsProbeBased
static bool ProfileIsProbeBased
Definition: SampleProf.h:1112
llvm::sampleprof::SampleProfileWriter::Format
SampleProfileFormat Format
Profile format.
Definition: SampleProfWriter.h:92
llvm::sampleprof::FunctionSamples::ProfileIsCS
static bool ProfileIsCS
Definition: SampleProf.h:1114
llvm::sampleprof::SampleProfileWriterBinary::writeBody
std::error_code writeBody(const FunctionSamples &S)
Definition: SampleProfWriter.cpp:774
llvm::sampleprof::SampleProfileWriterExtBinaryBase::writeFuncOffsetTable
std::error_code writeFuncOffsetTable()
Definition: SampleProfWriter.cpp:158
StringRef.h
llvm::raw_string_ostream
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:632
llvm::SmallVector< uint32_t, 16 >
llvm::sampleprof::ProfileSymbolList::size
unsigned size()
Definition: SampleProf.h:1305
splitProfileMapToTwo
static void splitProfileMapToTwo(const SampleProfileMap &ProfileMap, SampleProfileMap &ContextProfileMap, SampleProfileMap &NoContextProfileMap)
Definition: SampleProfWriter.cpp:398
llvm::sampleprof::DefaultLayout
@ DefaultLayout
Definition: SampleProfWriter.h:30
llvm::sampleprof::SecProfSummaryFlags::SecFlagFullContext
@ SecFlagFullContext
SecFlagContext means this is context-sensitive flat profile for CSSPGO.
llvm::sampleprof::SampleProfileMap
std::unordered_map< SampleContext, FunctionSamples, SampleContext::Hash > SampleProfileMap
Definition: SampleProf.h:1193
llvm::sampleprof::hasSecFlag
static bool hasSecFlag(const SecHdrTableEntry &Entry, SecFlagType Flag)
Definition: SampleProf.h:266
Saved
Fixup Statepoint Caller Saved
Definition: FixupStatepointCallerSaved.cpp:89
llvm::sampleprof::SPF_GCC
@ SPF_GCC
Definition: SampleProf.h:93
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::sampleprof::SampleProfileWriterBinary::addName
void addName(StringRef FName)
Definition: SampleProfWriter.cpp:542
llvm::sampleprof::SecFuncOffsetTable
@ SecFuncOffsetTable
Definition: SampleProf.h:125
llvm::sampleprof::SampleProfileWriter::computeSummary
void computeSummary(const SampleProfileMap &ProfileMap)
Compute summary for this profile.
Definition: SampleProfWriter.cpp:895
llvm::sampleprof::addSecFlag
static void addSecFlag(SecHdrTableEntry &Entry, SecFlagType Flag)
Definition: SampleProf.h:250
llvm::sampleprof::SecCommonFlags::SecFlagCompress
@ SecFlagCompress
llvm::sampleprof::SampleProfileWriterCompactBinary::writeFuncOffsetTable
std::error_code writeFuncOffsetTable()
Definition: SampleProfWriter.cpp:603
llvm::MapVector
This class implements a map that also provides access to all stored values in a deterministic order.
Definition: MapVector.h:37
llvm::sampleprof::SampleContext::getAllAttributes
uint32_t getAllAttributes()
Definition: SampleProf.h:592
llvm::sampleprof::SampleProfileWriterCompactBinary::writeHeader
virtual std::error_code writeHeader(const SampleProfileMap &ProfileMap) override
Write a file header for the profile file.
Definition: SampleProfWriter.cpp:744
llvm::sampleprof::SampleProfileWriterExtBinaryBase::writeNameTableSection
std::error_code writeNameTableSection(const SampleProfileMap &ProfileMap)
Definition: SampleProfWriter.cpp:256
llvm::MipsISD::Ret
@ Ret
Definition: MipsISelLowering.h:119
llvm::sampleprof::FunctionSamples::getName
StringRef getName() const
Return the function name.
Definition: SampleProf.h:1011
llvm::sampleprof::SampleProfileWriter::writeFuncProfiles
virtual std::error_code writeFuncProfiles(const SampleProfileMap &ProfileMap)
Definition: SampleProfWriter.cpp:44
llvm::sampleprof::SampleProfileWriterExtBinaryBase::setToCompressAllSections
virtual void setToCompressAllSections() override
Definition: SampleProfWriter.cpp:669
llvm::support::endian::Writer
Adapter to write values to a stream in a particular byte order.
Definition: EndianStream.h:52
ProfileCommon.h
llvm::sampleprof::SampleProfileWriterBinary::writeSample
virtual std::error_code writeSample(const FunctionSamples &S) override
Write samples of a top-level function to a binary file.
Definition: SampleProfWriter.cpp:821
llvm::SampleProfileSummaryBuilder
Definition: ProfileCommon.h:88
llvm::sampleprof::SPF_Binary
@ SPF_Binary
Definition: SampleProf.h:95
llvm::sampleprof::SampleProfileWriterExtBinaryBase::writeSample
virtual std::error_code writeSample(const FunctionSamples &S) override
Write samples of a top-level function to a binary file.
Definition: SampleProfWriter.cpp:150
llvm::sampleprof::LineLocation::Discriminator
uint32_t Discriminator
Definition: SampleProf.h:302
llvm::sampleprof::LineLocation::LineOffset
uint32_t LineOffset
Definition: SampleProf.h:301
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
llvm::sampleprof::SampleProfileWriterExtBinaryBase::writeCustomSection
virtual std::error_code writeCustomSection(SecType Type)=0
llvm::sampleprof::SampleProfileWriter::Summary
std::unique_ptr< ProfileSummary > Summary
Profile summary.
Definition: SampleProfWriter.h:86
llvm::sampleprof::SecFuncMetadataFlags::SecFlagIsProbeBased
@ SecFlagIsProbeBased
llvm::sampleprof_error::unsupported_writing_format
@ unsupported_writing_format
llvm::sampleprof::SampleProfileFormat
SampleProfileFormat
Definition: SampleProf.h:89
llvm::sampleprof::SampleProfileWriterExtBinaryBase::writeSections
virtual std::error_code writeSections(const SampleProfileMap &ProfileMap)=0
MD5.h
llvm::sampleprof::SampleProfileWriterBinary::addNames
void addNames(const FunctionSamples &S)
Definition: SampleProfWriter.cpp:551
llvm::zlib::BestSizeCompression
static constexpr int BestSizeCompression
Definition: Compression.h:28
llvm::support::little
@ little
Definition: Endian.h:27
llvm::zlib::compress
void compress(StringRef InputBuffer, SmallVectorImpl< char > &CompressedBuffer, int Level=DefaultCompression)
Definition: Compression.cpp:49
llvm::sampleprof::SampleProfileWriter::write
virtual std::error_code write(const SampleProfileMap &ProfileMap)
Write all the sample profiles in the given map of samples.
Definition: SampleProfWriter.cpp:54
llvm::sampleprof::SampleProfileWriterRawBinary
Definition: SampleProfWriter.h:152
llvm::sampleprof::SampleProfileWriterBinary::writeHeader
virtual std::error_code writeHeader(const SampleProfileMap &ProfileMap) override
Write a file header for the profile file.
Definition: SampleProfWriter.cpp:651
llvm::sampleprof::SampleProfileWriterExtBinaryBase::addContext
virtual void addContext(const SampleContext &Context) override
Definition: SampleProfWriter.cpp:568
llvm::sampleprof::SampleProfileWriterBinary::writeNameTable
virtual std::error_code writeNameTable()
Definition: SampleProfWriter.cpp:589
SampleProf.h
llvm::sampleprof::SampleProfileWriter::writeSample
virtual std::error_code writeSample(const FunctionSamples &S)=0
Write sample profiles in S.
llvm::sampleprof::SPMagic
static uint64_t SPMagic(SampleProfileFormat Format=SPF_Binary)
Definition: SampleProf.h:98
llvm::sampleprof::SampleProfileWriterExtBinaryBase::SectionHdrLayout
SmallVector< SecHdrTableEntry, 8 > SectionHdrLayout
Definition: SampleProfWriter.h:280
llvm::sampleprof::SampleProfileWriterCompactBinary::TableOffset
uint64_t TableOffset
The offset of the slot to be filled with the offset of FuncOffsetTable towards profile start.
Definition: SampleProfWriter.h:393
llvm::sampleprof::SampleProfileWriterExtBinaryBase::write
virtual std::error_code write(const SampleProfileMap &ProfileMap) override
Write all the sample profiles in the given map of samples.
Definition: SampleProfWriter.cpp:117
llvm::sampleprof::SampleContext
Definition: SampleProf.h:501
llvm::sampleprof::sortFuncProfiles
void sortFuncProfiles(const SampleProfileMap &ProfileMap, std::vector< NameFunctionSamples > &SortedProfiles)
Definition: SampleProf.cpp:203
llvm::sampleprof::FunctionSamples::ProfileIsFS
static bool ProfileIsFS
If this profile uses flow sensitive discriminators.
Definition: SampleProf.h:1129
llvm::SmallString< 128 >
llvm::sys::fs::OF_TextWithCRLF
@ OF_TextWithCRLF
The file should be opened in text mode and use a carriage linefeed '\r '.
Definition: FileSystem.h:770
llvm::sampleprof::SampleProfileWriterCompactBinary::writeNameTable
virtual std::error_code writeNameTable() override
Definition: SampleProfWriter.cpp:628
llvm::sampleprof::SampleProfileWriterCompactBinary::FuncOffsetTable
MapVector< StringRef, uint64_t > FuncOffsetTable
The table mapping from function name to the offset of its FunctionSample towards profile start.
Definition: SampleProfWriter.h:390
llvm::sampleprof::SampleProfileWriterExtBinaryBase::markSectionStart
uint64_t markSectionStart(SecType Type, uint32_t LayoutIdx)
Return the current position and prepare to use it as the start position of a section given the sectio...
Definition: SampleProfWriter.cpp:68
llvm::sampleprof::FunctionSamples::getCallsiteSamples
const CallsiteSampleMap & getCallsiteSamples() const
Return all the callsite samples collected in the body of the function.
Definition: SampleProf.h:923
llvm::sampleprof::SPF_Compact_Binary
@ SPF_Compact_Binary
Definition: SampleProf.h:92
llvm::sampleprof::SecProfSummary
@ SecProfSummary
Definition: SampleProf.h:122
llvm::sampleprof::SampleProfileWriterBinary::getNameTable
virtual MapVector< StringRef, uint32_t > & getNameTable()
Definition: SampleProfWriter.h:128
uint64_t
llvm::sampleprof::SampleProfileWriterCompactBinary::write
virtual std::error_code write(const SampleProfileMap &ProfileMap) override
Write all the sample profiles in the given map of samples.
Definition: SampleProfWriter.cpp:453
llvm::sampleprof::FunctionSamples
Representation of the samples collected for a function.
Definition: SampleProf.h:720
LEB128.h
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::sampleprof::SPF_Ext_Binary
@ SPF_Ext_Binary
Definition: SampleProf.h:94
ErrorOr.h
llvm::sampleprof::SampleProfileWriterExtBinaryBase::writeCSNameIdx
std::error_code writeCSNameIdx(const SampleContext &Context)
Definition: SampleProfWriter.cpp:141
llvm::sampleprof::SecLBRProfile
@ SecLBRProfile
Definition: SampleProf.h:130
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::sampleprof::FunctionSamples::getFunctionHash
uint64_t getFunctionHash() const
Definition: SampleProf.h:1018
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::sampleprof::SampleProfileWriterBinary::addContext
virtual void addContext(const SampleContext &Context)
Definition: SampleProfWriter.cpp:547
llvm::sampleprof::SampleProfileWriterExtBinaryBase::addSectionFlag
void addSectionFlag(SecType Type, SecFlagType Flag)
Definition: SampleProfWriter.h:234
llvm::codeview::CompileSym2Flags::EC
@ EC
llvm::sampleprof::SampleProfileWriterText::writeSample
std::error_code writeSample(const FunctionSamples &S) override
Write samples to a text file.
Definition: SampleProfWriter.cpp:469
llvm::sampleprof::SampleProfileWriterBinary::writeNameIdx
std::error_code writeNameIdx(StringRef FName)
Definition: SampleProfWriter.cpp:533
llvm::zlib::isAvailable
bool isAvailable()
Definition: Compression.cpp:47
llvm::sampleprof::LineLocation
Represents the relative location of an instruction.
Definition: SampleProf.h:282
Builder
assume Assume Builder
Definition: AssumeBundleBuilder.cpp:651
llvm::sampleprof::SampleProfileWriterExtBinaryBase::addNewSection
std::error_code addNewSection(SecType Sec, uint32_t LayoutIdx, uint64_t SectionStart)
Add a new section into section header table given the section type Type, its position LayoutIdx in Se...
Definition: SampleProfWriter.cpp:101
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::sampleprof::SampleSorter
Sort a LocationT->SampleT map by LocationT.
Definition: SampleProf.h:1204
llvm::support::endian::Writer::write
void write(ArrayRef< value_type > Val)
Definition: EndianStream.h:56
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
llvm::sampleprof_error::unrecognized_format
@ unrecognized_format
uint32_t
llvm::sampleprof::SampleProfileWriterExtBinaryBase::writeFuncMetadata
std::error_code writeFuncMetadata(const SampleProfileMap &Profiles)
Definition: SampleProfWriter.cpp:226
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::sampleprof::SPF_Text
@ SPF_Text
Definition: SampleProf.h:91
llvm::sampleprof::SecFuncOffsetFlags::SecFlagOrdered
@ SecFlagOrdered
llvm::raw_fd_ostream
A raw_ostream that writes to a file descriptor.
Definition: raw_ostream.h:444
llvm::sampleprof::ProfileSymbolList::toCompress
bool toCompress()
Definition: SampleProf.h:1308
llvm::sampleprof::SampleProfileWriter::writeHeader
virtual std::error_code writeHeader(const SampleProfileMap &ProfileMap)=0
Write a file header for the profile file.
Callee
amdgpu Simplify well known AMD library false FunctionCallee Callee
Definition: AMDGPULibCalls.cpp:186
llvm::sampleprof_error::ostream_seek_unsupported
@ ostream_seek_unsupported
llvm::sampleprof::SampleProfileWriterExtBinary
Definition: SampleProfWriter.h:328
llvm::sampleprof::SampleProfileWriterExtBinaryBase::writeOneSection
virtual std::error_code writeOneSection(SecType Type, uint32_t LayoutIdx, const SampleProfileMap &ProfileMap)
Definition: SampleProfWriter.cpp:316
llvm::sampleprof::ProfileSymbolList::write
std::error_code write(raw_ostream &OS)
Definition: SampleProf.cpp:441
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
EndianStream.h
llvm::sampleprof::SPVersion
static uint64_t SPVersion()
Definition: SampleProf.h:115
llvm::sampleprof::SampleProfileWriterBinary::writeSummary
std::error_code writeSummary()
Definition: SampleProfWriter.cpp:757
llvm::sampleprof::SampleProfileWriterExtBinaryBase::setToCompressSection
void setToCompressSection(SecType Type)
Definition: SampleProfWriter.cpp:674
llvm::sampleprof::SecProfileSymbolList
@ SecProfileSymbolList
Definition: SampleProf.h:124
llvm::sampleprof::SampleProfileWriterExtBinaryBase::SecLBRProfileStart
uint64_t SecLBRProfileStart
Definition: SampleProfWriter.h:286
llvm::sampleprof::SecType
SecType
Definition: SampleProf.h:120
llvm::sampleprof::SampleProfileWriterExtBinaryBase::writeCSNameTableSection
std::error_code writeCSNameTableSection()
Definition: SampleProfWriter.cpp:279
llvm::sampleprof::SampleRecord
Representation of a single sample record.
Definition: SampleProf.h:317
llvm::sampleprof::SampleProfileWriterExtBinaryBase::writeProfileSymbolListSection
std::error_code writeProfileSymbolListSection()
Definition: SampleProfWriter.cpp:308
llvm::sampleprof::SampleProfileWriterBinary::writeContextIdx
virtual std::error_code writeContextIdx(const SampleContext &Context)
Definition: SampleProfWriter.cpp:528
llvm::sampleprof_error::zlib_unavailable
@ zlib_unavailable
llvm::SmallString::str
StringRef str() const
Explicit conversion to StringRef.
Definition: SmallString.h:260
llvm::sampleprof::FunctionSamples::getContext
SampleContext & getContext() const
Definition: SampleProf.h:1118
llvm::sampleprof_error::success
@ success
llvm::sampleprof::SecNameTableFlags::SecFlagUniqSuffix
@ SecFlagUniqSuffix
llvm::sampleprof::SampleProfileWriterExtBinaryBase::writeContextIdx
virtual std::error_code writeContextIdx(const SampleContext &Context) override
Definition: SampleProfWriter.cpp:132
llvm::sampleprof::SampleProfileWriterCompactBinary::writeSample
virtual std::error_code writeSample(const FunctionSamples &S) override
Write samples of a top-level function to a binary file.
Definition: SampleProfWriter.cpp:827
llvm::sampleprof::SecCommonFlags::SecFlagFlat
@ SecFlagFlat
llvm::sampleprof::FunctionSamples::UniqSuffix
static constexpr const char * UniqSuffix
Definition: SampleProf.h:1032
SampleProfWriter.h
N
#define N
llvm::sampleprof::SecCSNameTable
@ SecCSNameTable
Definition: SampleProf.h:127
llvm::ErrorOr
Represents either an error or a value T.
Definition: ErrorOr.h:56
llvm::sampleprof::SecProfSummaryFlags::SecFlagIsPreInlined
@ SecFlagIsPreInlined
SecFlagIsPreInlined means this profile contains ShouldBeInlined contexts thus this is CS preinliner c...
llvm::encodeULEB128
unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
Definition: LEB128.h:80
llvm::sampleprof::SecNameTable
@ SecNameTable
Definition: SampleProf.h:123
llvm::sampleprof::SampleProfileWriterBinary::writeMagicIdent
virtual std::error_code writeMagicIdent(SampleProfileFormat Format)
Definition: SampleProfWriter.cpp:642
llvm::sampleprof::SecFuncMetadata
@ SecFuncMetadata
Definition: SampleProf.h:126
llvm::sampleprof_error::truncated_name_table
@ truncated_name_table
raw_ostream.h
llvm::X86AS::FS
@ FS
Definition: X86.h:188
Endian.h
llvm::sampleprof::SampleProfileWriterCompactBinary
Definition: SampleProfWriter.h:380
llvm::ProfileSummaryBuilder::DefaultCutoffs
static const ArrayRef< uint32_t > DefaultCutoffs
A vector of useful cutoff values for detailed summary.
Definition: ProfileCommon.h:65
llvm::sampleprof::SampleProfileWriterExtBinaryBase::SecLayout
SectionLayout SecLayout
Definition: SampleProfWriter.h:275
llvm::MD5Hash
uint64_t MD5Hash(StringRef Str)
Helper to compute and return lower 64 bits of the given string's MD5 hash.
Definition: MD5.h:109
llvm::sampleprof::FunctionSamples::ProfileIsPreInlined
static bool ProfileIsPreInlined
Definition: SampleProf.h:1116