LLVM  13.0.0git
InstrProf.cpp
Go to the documentation of this file.
1 //===- InstrProf.cpp - Instrumented 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 support for clang's instrumentation based PGO and
10 // coverage.
11 //
12 //===----------------------------------------------------------------------===//
13 
15 #include "llvm/ADT/ArrayRef.h"
16 #include "llvm/ADT/SmallString.h"
17 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/ADT/StringExtras.h"
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/ADT/Triple.h"
21 #include "llvm/Config/config.h"
22 #include "llvm/IR/Constant.h"
23 #include "llvm/IR/Constants.h"
24 #include "llvm/IR/Function.h"
25 #include "llvm/IR/GlobalValue.h"
26 #include "llvm/IR/GlobalVariable.h"
27 #include "llvm/IR/Instruction.h"
28 #include "llvm/IR/LLVMContext.h"
29 #include "llvm/IR/MDBuilder.h"
30 #include "llvm/IR/Metadata.h"
31 #include "llvm/IR/Module.h"
32 #include "llvm/IR/Type.h"
34 #include "llvm/Support/Casting.h"
36 #include "llvm/Support/Compiler.h"
38 #include "llvm/Support/Endian.h"
39 #include "llvm/Support/Error.h"
41 #include "llvm/Support/LEB128.h"
44 #include "llvm/Support/Path.h"
46 #include <algorithm>
47 #include <cassert>
48 #include <cstddef>
49 #include <cstdint>
50 #include <cstring>
51 #include <memory>
52 #include <string>
53 #include <system_error>
54 #include <utility>
55 #include <vector>
56 
57 using namespace llvm;
58 
60  "static-func-full-module-prefix", cl::init(true), cl::Hidden,
61  cl::desc("Use full module build paths in the profile counter names for "
62  "static functions."));
63 
64 // This option is tailored to users that have different top-level directory in
65 // profile-gen and profile-use compilation. Users need to specific the number
66 // of levels to strip. A value larger than the number of directories in the
67 // source file will strip all the directory names and only leave the basename.
68 //
69 // Note current ThinLTO module importing for the indirect-calls assumes
70 // the source directory name not being stripped. A non-zero option value here
71 // can potentially prevent some inter-module indirect-call-promotions.
73  "static-func-strip-dirname-prefix", cl::init(0), cl::Hidden,
74  cl::desc("Strip specified level of directory name from source path in "
75  "the profile counter name for static functions."));
76 
77 static std::string getInstrProfErrString(instrprof_error Err) {
78  switch (Err) {
80  return "Success";
82  return "End of File";
84  return "Unrecognized instrumentation profile encoding format";
86  return "Invalid instrumentation profile data (bad magic)";
88  return "Invalid instrumentation profile data (file header is corrupt)";
90  return "Unsupported instrumentation profile format version";
92  return "Unsupported instrumentation profile hash type";
94  return "Too much profile data";
96  return "Truncated profile data";
98  return "Malformed instrumentation profile data";
100  return "Invalid profile created. Please file a bug "
101  "at: " BUG_REPORT_URL
102  " and include the profraw files that caused this error.";
104  return "No profile data available for function";
106  return "Function control flow change detected (hash mismatch)";
108  return "Function basic block count change detected (counter mismatch)";
110  return "Counter overflow";
112  return "Function value site count change detected (counter mismatch)";
114  return "Failed to compress data (zlib)";
116  return "Failed to uncompress data (zlib)";
118  return "Empty raw profile file";
120  return "Profile uses zlib compression but the profile reader was built without zlib support";
121  }
122  llvm_unreachable("A value of instrprof_error has no message.");
123 }
124 
125 namespace {
126 
127 // FIXME: This class is only here to support the transition to llvm::Error. It
128 // will be removed once this transition is complete. Clients should prefer to
129 // deal with the Error value directly, rather than converting to error_code.
130 class InstrProfErrorCategoryType : public std::error_category {
131  const char *name() const noexcept override { return "llvm.instrprof"; }
132 
133  std::string message(int IE) const override {
134  return getInstrProfErrString(static_cast<instrprof_error>(IE));
135  }
136 };
137 
138 } // end anonymous namespace
139 
141 
143  return *ErrorCategory;
144 }
145 
146 namespace {
147 
148 const char *InstrProfSectNameCommon[] = {
149 #define INSTR_PROF_SECT_ENTRY(Kind, SectNameCommon, SectNameCoff, Prefix) \
150  SectNameCommon,
152 };
153 
154 const char *InstrProfSectNameCoff[] = {
155 #define INSTR_PROF_SECT_ENTRY(Kind, SectNameCommon, SectNameCoff, Prefix) \
156  SectNameCoff,
158 };
159 
160 const char *InstrProfSectNamePrefix[] = {
161 #define INSTR_PROF_SECT_ENTRY(Kind, SectNameCommon, SectNameCoff, Prefix) \
162  Prefix,
164 };
165 
166 } // namespace
167 
168 namespace llvm {
169 
171  "enable-name-compression",
172  cl::desc("Enable name/filename string compression"), cl::init(true));
173 
176  bool AddSegmentInfo) {
177  std::string SectName;
178 
179  if (OF == Triple::MachO && AddSegmentInfo)
180  SectName = InstrProfSectNamePrefix[IPSK];
181 
182  if (OF == Triple::COFF)
183  SectName += InstrProfSectNameCoff[IPSK];
184  else
185  SectName += InstrProfSectNameCommon[IPSK];
186 
187  if (OF == Triple::MachO && IPSK == IPSK_data && AddSegmentInfo)
188  SectName += ",regular,live_support";
189 
190  return SectName;
191 }
192 
195  return;
196 
197  if (FirstError == instrprof_error::success)
198  FirstError = IE;
199 
200  switch (IE) {
202  ++NumHashMismatches;
203  break;
205  ++NumCountMismatches;
206  break;
208  ++NumCounterOverflows;
209  break;
211  ++NumValueSiteCountMismatches;
212  break;
213  default:
214  llvm_unreachable("Not a soft error");
215  }
216 }
217 
218 std::string InstrProfError::message() const {
219  return getInstrProfErrString(Err);
220 }
221 
222 char InstrProfError::ID = 0;
223 
224 std::string getPGOFuncName(StringRef RawFuncName,
226  StringRef FileName,
227  uint64_t Version LLVM_ATTRIBUTE_UNUSED) {
228  return GlobalValue::getGlobalIdentifier(RawFuncName, Linkage, FileName);
229 }
230 
231 // Strip NumPrefix level of directory name from PathNameStr. If the number of
232 // directory separators is less than NumPrefix, strip all the directories and
233 // leave base file name only.
234 static StringRef stripDirPrefix(StringRef PathNameStr, uint32_t NumPrefix) {
235  uint32_t Count = NumPrefix;
236  uint32_t Pos = 0, LastPos = 0;
237  for (auto & CI : PathNameStr) {
238  ++Pos;
240  LastPos = Pos;
241  --Count;
242  }
243  if (Count == 0)
244  break;
245  }
246  return PathNameStr.substr(LastPos);
247 }
248 
249 // Return the PGOFuncName. This function has some special handling when called
250 // in LTO optimization. The following only applies when calling in LTO passes
251 // (when \c InLTO is true): LTO's internalization privatizes many global linkage
252 // symbols. This happens after value profile annotation, but those internal
253 // linkage functions should not have a source prefix.
254 // Additionally, for ThinLTO mode, exported internal functions are promoted
255 // and renamed. We need to ensure that the original internal PGO name is
256 // used when computing the GUID that is compared against the profiled GUIDs.
257 // To differentiate compiler generated internal symbols from original ones,
258 // PGOFuncName meta data are created and attached to the original internal
259 // symbols in the value profile annotation step
260 // (PGOUseFunc::annotateIndirectCallSites). If a symbol does not have the meta
261 // data, its original linkage must be non-internal.
262 std::string getPGOFuncName(const Function &F, bool InLTO, uint64_t Version) {
263  if (!InLTO) {
264  StringRef FileName(F.getParent()->getSourceFileName());
265  uint32_t StripLevel = StaticFuncFullModulePrefix ? 0 : (uint32_t)-1;
266  if (StripLevel < StaticFuncStripDirNamePrefix)
267  StripLevel = StaticFuncStripDirNamePrefix;
268  if (StripLevel)
269  FileName = stripDirPrefix(FileName, StripLevel);
270  return getPGOFuncName(F.getName(), F.getLinkage(), FileName, Version);
271  }
272 
273  // In LTO mode (when InLTO is true), first check if there is a meta data.
274  if (MDNode *MD = getPGOFuncNameMetadata(F)) {
275  StringRef S = cast<MDString>(MD->getOperand(0))->getString();
276  return S.str();
277  }
278 
279  // If there is no meta data, the function must be a global before the value
280  // profile annotation pass. Its current linkage may be internal if it is
281  // internalized in LTO mode.
282  return getPGOFuncName(F.getName(), GlobalValue::ExternalLinkage, "");
283 }
284 
286  if (FileName.empty())
287  return PGOFuncName;
288  // Drop the file name including ':'. See also getPGOFuncName.
289  if (PGOFuncName.startswith(FileName))
290  PGOFuncName = PGOFuncName.drop_front(FileName.size() + 1);
291  return PGOFuncName;
292 }
293 
294 // \p FuncName is the string used as profile lookup key for the function. A
295 // symbol is created to hold the name. Return the legalized symbol name.
296 std::string getPGOFuncNameVarName(StringRef FuncName,
298  std::string VarName = std::string(getInstrProfNameVarPrefix());
299  VarName += FuncName;
300 
302  return VarName;
303 
304  // Now fix up illegal chars in local VarName that may upset the assembler.
305  const char *InvalidChars = "-:<>/\"'";
306  size_t found = VarName.find_first_of(InvalidChars);
307  while (found != std::string::npos) {
308  VarName[found] = '_';
309  found = VarName.find_first_of(InvalidChars, found + 1);
310  }
311  return VarName;
312 }
313 
316  StringRef PGOFuncName) {
317  // We generally want to match the function's linkage, but available_externally
318  // and extern_weak both have the wrong semantics, and anything that doesn't
319  // need to link across compilation units doesn't need to be visible at all.
327 
328  auto *Value =
329  ConstantDataArray::getString(M.getContext(), PGOFuncName, false);
330  auto FuncNameVar =
331  new GlobalVariable(M, Value->getType(), true, Linkage, Value,
332  getPGOFuncNameVarName(PGOFuncName, Linkage));
333 
334  // Hide the symbol so that we correctly get a copy for each executable.
335  if (!GlobalValue::isLocalLinkage(FuncNameVar->getLinkage()))
336  FuncNameVar->setVisibility(GlobalValue::HiddenVisibility);
337 
338  return FuncNameVar;
339 }
340 
342  return createPGOFuncNameVar(*F.getParent(), F.getLinkage(), PGOFuncName);
343 }
344 
346  for (Function &F : M) {
347  // Function may not have a name: like using asm("") to overwrite the name.
348  // Ignore in this case.
349  if (!F.hasName())
350  continue;
351  const std::string &PGOFuncName = getPGOFuncName(F, InLTO);
352  if (Error E = addFuncName(PGOFuncName))
353  return E;
354  MD5FuncMap.emplace_back(Function::getGUID(PGOFuncName), &F);
355  // In ThinLTO, local function may have been promoted to global and have
356  // suffix ".llvm." added to the function name. We need to add the
357  // stripped function name to the symbol table so that we can find a match
358  // from profile.
359  //
360  // We may have other suffixes similar as ".llvm." which are needed to
361  // be stripped before the matching, but ".__uniq." suffix which is used
362  // to differentiate internal linkage functions in different modules
363  // should be kept. Now this is the only suffix with the pattern ".xxx"
364  // which is kept before matching.
365  const std::string UniqSuffix = ".__uniq.";
366  auto pos = PGOFuncName.find(UniqSuffix);
367  // Search '.' after ".__uniq." if ".__uniq." exists, otherwise
368  // search '.' from the beginning.
369  if (pos != std::string::npos)
370  pos += UniqSuffix.length();
371  else
372  pos = 0;
373  pos = PGOFuncName.find('.', pos);
374  if (pos != std::string::npos && pos != 0) {
375  const std::string &OtherFuncName = PGOFuncName.substr(0, pos);
376  if (Error E = addFuncName(OtherFuncName))
377  return E;
378  MD5FuncMap.emplace_back(Function::getGUID(OtherFuncName), &F);
379  }
380  }
381  Sorted = false;
382  finalizeSymtab();
383  return Error::success();
384 }
385 
387  finalizeSymtab();
388  auto It = partition_point(AddrToMD5Map, [=](std::pair<uint64_t, uint64_t> A) {
389  return A.first < Address;
390  });
391  // Raw function pointer collected by value profiler may be from
392  // external functions that are not instrumented. They won't have
393  // mapping data to be used by the deserializer. Force the value to
394  // be 0 in this case.
395  if (It != AddrToMD5Map.end() && It->first == Address)
396  return (uint64_t)It->second;
397  return 0;
398 }
399 
401  bool doCompression, std::string &Result) {
402  assert(!NameStrs.empty() && "No name data to emit");
403 
404  uint8_t Header[16], *P = Header;
405  std::string UncompressedNameStrings =
406  join(NameStrs.begin(), NameStrs.end(), getInstrProfNameSeparator());
407 
408  assert(StringRef(UncompressedNameStrings)
409  .count(getInstrProfNameSeparator()) == (NameStrs.size() - 1) &&
410  "PGO name is invalid (contains separator token)");
411 
412  unsigned EncLen = encodeULEB128(UncompressedNameStrings.length(), P);
413  P += EncLen;
414 
415  auto WriteStringToResult = [&](size_t CompressedLen, StringRef InputStr) {
416  EncLen = encodeULEB128(CompressedLen, P);
417  P += EncLen;
418  char *HeaderStr = reinterpret_cast<char *>(&Header[0]);
419  unsigned HeaderLen = P - &Header[0];
420  Result.append(HeaderStr, HeaderLen);
421  Result += InputStr;
422  return Error::success();
423  };
424 
425  if (!doCompression) {
426  return WriteStringToResult(0, UncompressedNameStrings);
427  }
428 
429  SmallString<128> CompressedNameStrings;
430  Error E = zlib::compress(StringRef(UncompressedNameStrings),
431  CompressedNameStrings, zlib::BestSizeCompression);
432  if (E) {
434  return make_error<InstrProfError>(instrprof_error::compress_failed);
435  }
436 
437  return WriteStringToResult(CompressedNameStrings.size(),
438  CompressedNameStrings);
439 }
440 
442  auto *Arr = cast<ConstantDataArray>(NameVar->getInitializer());
443  StringRef NameStr =
444  Arr->isCString() ? Arr->getAsCString() : Arr->getAsString();
445  return NameStr;
446 }
447 
449  std::string &Result, bool doCompression) {
450  std::vector<std::string> NameStrs;
451  for (auto *NameVar : NameVars) {
452  NameStrs.push_back(std::string(getPGOFuncNameVarInitializer(NameVar)));
453  }
455  NameStrs, zlib::isAvailable() && doCompression, Result);
456 }
457 
459  const uint8_t *P = NameStrings.bytes_begin();
460  const uint8_t *EndP = NameStrings.bytes_end();
461  while (P < EndP) {
462  uint32_t N;
463  uint64_t UncompressedSize = decodeULEB128(P, &N);
464  P += N;
465  uint64_t CompressedSize = decodeULEB128(P, &N);
466  P += N;
467  bool isCompressed = (CompressedSize != 0);
468  SmallString<128> UncompressedNameStrings;
469  StringRef NameStrings;
470  if (isCompressed) {
472  return make_error<InstrProfError>(instrprof_error::zlib_unavailable);
473 
474  StringRef CompressedNameStrings(reinterpret_cast<const char *>(P),
475  CompressedSize);
476  if (Error E =
477  zlib::uncompress(CompressedNameStrings, UncompressedNameStrings,
478  UncompressedSize)) {
480  return make_error<InstrProfError>(instrprof_error::uncompress_failed);
481  }
482  P += CompressedSize;
483  NameStrings = StringRef(UncompressedNameStrings.data(),
484  UncompressedNameStrings.size());
485  } else {
486  NameStrings =
487  StringRef(reinterpret_cast<const char *>(P), UncompressedSize);
488  P += UncompressedSize;
489  }
490  // Now parse the name strings.
492  NameStrings.split(Names, getInstrProfNameSeparator());
493  for (StringRef &Name : Names)
494  if (Error E = Symtab.addFuncName(Name))
495  return E;
496 
497  while (P < EndP && *P == 0)
498  P++;
499  }
500  return Error::success();
501 }
502 
504  uint64_t FuncSum = 0;
505  Sum.NumEntries += Counts.size();
506  for (size_t F = 0, E = Counts.size(); F < E; ++F)
507  FuncSum += Counts[F];
508  Sum.CountSum += FuncSum;
509 
510  for (uint32_t VK = IPVK_First; VK <= IPVK_Last; ++VK) {
511  uint64_t KindSum = 0;
512  uint32_t NumValueSites = getNumValueSites(VK);
513  for (size_t I = 0; I < NumValueSites; ++I) {
515  std::unique_ptr<InstrProfValueData[]> VD = getValueForSite(VK, I);
516  for (uint32_t V = 0; V < NV; V++)
517  KindSum += VD[V].Count;
518  }
519  Sum.ValueCounts[VK] += KindSum;
520  }
521 }
522 
525  OverlapStats &Overlap,
526  OverlapStats &FuncLevelOverlap) {
527  this->sortByTargetValues();
528  Input.sortByTargetValues();
529  double Score = 0.0f, FuncLevelScore = 0.0f;
530  auto I = ValueData.begin();
531  auto IE = ValueData.end();
532  auto J = Input.ValueData.begin();
533  auto JE = Input.ValueData.end();
534  while (I != IE && J != JE) {
535  if (I->Value == J->Value) {
536  Score += OverlapStats::score(I->Count, J->Count,
537  Overlap.Base.ValueCounts[ValueKind],
538  Overlap.Test.ValueCounts[ValueKind]);
539  FuncLevelScore += OverlapStats::score(
540  I->Count, J->Count, FuncLevelOverlap.Base.ValueCounts[ValueKind],
541  FuncLevelOverlap.Test.ValueCounts[ValueKind]);
542  ++I;
543  } else if (I->Value < J->Value) {
544  ++I;
545  continue;
546  }
547  ++J;
548  }
549  Overlap.Overlap.ValueCounts[ValueKind] += Score;
550  FuncLevelOverlap.Overlap.ValueCounts[ValueKind] += FuncLevelScore;
551 }
552 
553 // Return false on mismatch.
555  InstrProfRecord &Other,
556  OverlapStats &Overlap,
557  OverlapStats &FuncLevelOverlap) {
558  uint32_t ThisNumValueSites = getNumValueSites(ValueKind);
559  assert(ThisNumValueSites == Other.getNumValueSites(ValueKind));
560  if (!ThisNumValueSites)
561  return;
562 
563  std::vector<InstrProfValueSiteRecord> &ThisSiteRecords =
564  getOrCreateValueSitesForKind(ValueKind);
566  Other.getValueSitesForKind(ValueKind);
567  for (uint32_t I = 0; I < ThisNumValueSites; I++)
568  ThisSiteRecords[I].overlap(OtherSiteRecords[I], ValueKind, Overlap,
569  FuncLevelOverlap);
570 }
571 
573  OverlapStats &FuncLevelOverlap,
574  uint64_t ValueCutoff) {
575  // FuncLevel CountSum for other should already computed and nonzero.
576  assert(FuncLevelOverlap.Test.CountSum >= 1.0f);
577  accumulateCounts(FuncLevelOverlap.Base);
578  bool Mismatch = (Counts.size() != Other.Counts.size());
579 
580  // Check if the value profiles mismatch.
581  if (!Mismatch) {
582  for (uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind) {
583  uint32_t ThisNumValueSites = getNumValueSites(Kind);
584  uint32_t OtherNumValueSites = Other.getNumValueSites(Kind);
585  if (ThisNumValueSites != OtherNumValueSites) {
586  Mismatch = true;
587  break;
588  }
589  }
590  }
591  if (Mismatch) {
592  Overlap.addOneMismatch(FuncLevelOverlap.Test);
593  return;
594  }
595 
596  // Compute overlap for value counts.
597  for (uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind)
598  overlapValueProfData(Kind, Other, Overlap, FuncLevelOverlap);
599 
600  double Score = 0.0;
601  uint64_t MaxCount = 0;
602  // Compute overlap for edge counts.
603  for (size_t I = 0, E = Other.Counts.size(); I < E; ++I) {
604  Score += OverlapStats::score(Counts[I], Other.Counts[I],
605  Overlap.Base.CountSum, Overlap.Test.CountSum);
606  MaxCount = std::max(Other.Counts[I], MaxCount);
607  }
608  Overlap.Overlap.CountSum += Score;
609  Overlap.Overlap.NumEntries += 1;
610 
611  if (MaxCount >= ValueCutoff) {
612  double FuncScore = 0.0;
613  for (size_t I = 0, E = Other.Counts.size(); I < E; ++I)
614  FuncScore += OverlapStats::score(Counts[I], Other.Counts[I],
615  FuncLevelOverlap.Base.CountSum,
616  FuncLevelOverlap.Test.CountSum);
617  FuncLevelOverlap.Overlap.CountSum = FuncScore;
618  FuncLevelOverlap.Overlap.NumEntries = Other.Counts.size();
619  FuncLevelOverlap.Valid = true;
620  }
621 }
622 
624  uint64_t Weight,
625  function_ref<void(instrprof_error)> Warn) {
626  this->sortByTargetValues();
627  Input.sortByTargetValues();
628  auto I = ValueData.begin();
629  auto IE = ValueData.end();
630  for (auto J = Input.ValueData.begin(), JE = Input.ValueData.end(); J != JE;
631  ++J) {
632  while (I != IE && I->Value < J->Value)
633  ++I;
634  if (I != IE && I->Value == J->Value) {
635  bool Overflowed;
636  I->Count = SaturatingMultiplyAdd(J->Count, Weight, I->Count, &Overflowed);
637  if (Overflowed)
639  ++I;
640  continue;
641  }
642  ValueData.insert(I, *J);
643  }
644 }
645 
646 void InstrProfValueSiteRecord::scale(uint64_t N, uint64_t D,
647  function_ref<void(instrprof_error)> Warn) {
648  for (auto I = ValueData.begin(), IE = ValueData.end(); I != IE; ++I) {
649  bool Overflowed;
650  I->Count = SaturatingMultiply(I->Count, N, &Overflowed) / D;
651  if (Overflowed)
653  }
654 }
655 
656 // Merge Value Profile data from Src record to this record for ValueKind.
657 // Scale merged value counts by \p Weight.
658 void InstrProfRecord::mergeValueProfData(
659  uint32_t ValueKind, InstrProfRecord &Src, uint64_t Weight,
660  function_ref<void(instrprof_error)> Warn) {
661  uint32_t ThisNumValueSites = getNumValueSites(ValueKind);
662  uint32_t OtherNumValueSites = Src.getNumValueSites(ValueKind);
663  if (ThisNumValueSites != OtherNumValueSites) {
665  return;
666  }
667  if (!ThisNumValueSites)
668  return;
669  std::vector<InstrProfValueSiteRecord> &ThisSiteRecords =
670  getOrCreateValueSitesForKind(ValueKind);
672  Src.getValueSitesForKind(ValueKind);
673  for (uint32_t I = 0; I < ThisNumValueSites; I++)
674  ThisSiteRecords[I].merge(OtherSiteRecords[I], Weight, Warn);
675 }
676 
677 void InstrProfRecord::merge(InstrProfRecord &Other, uint64_t Weight,
678  function_ref<void(instrprof_error)> Warn) {
679  // If the number of counters doesn't match we either have bad data
680  // or a hash collision.
681  if (Counts.size() != Other.Counts.size()) {
683  return;
684  }
685 
686  for (size_t I = 0, E = Other.Counts.size(); I < E; ++I) {
687  bool Overflowed;
688  Counts[I] =
689  SaturatingMultiplyAdd(Other.Counts[I], Weight, Counts[I], &Overflowed);
690  if (Overflowed)
692  }
693 
694  for (uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind)
695  mergeValueProfData(Kind, Other, Weight, Warn);
696 }
697 
698 void InstrProfRecord::scaleValueProfData(
699  uint32_t ValueKind, uint64_t N, uint64_t D,
700  function_ref<void(instrprof_error)> Warn) {
701  for (auto &R : getValueSitesForKind(ValueKind))
702  R.scale(N, D, Warn);
703 }
704 
705 void InstrProfRecord::scale(uint64_t N, uint64_t D,
706  function_ref<void(instrprof_error)> Warn) {
707  assert(D != 0 && "D cannot be 0");
708  for (auto &Count : this->Counts) {
709  bool Overflowed;
710  Count = SaturatingMultiply(Count, N, &Overflowed) / D;
711  if (Overflowed)
713  }
714  for (uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind)
715  scaleValueProfData(Kind, N, D, Warn);
716 }
717 
718 // Map indirect call target name hash to name string.
719 uint64_t InstrProfRecord::remapValue(uint64_t Value, uint32_t ValueKind,
720  InstrProfSymtab *SymTab) {
721  if (!SymTab)
722  return Value;
723 
724  if (ValueKind == IPVK_IndirectCallTarget)
725  return SymTab->getFunctionHashFromAddress(Value);
726 
727  return Value;
728 }
729 
731  InstrProfValueData *VData, uint32_t N,
733  for (uint32_t I = 0; I < N; I++) {
734  VData[I].Value = remapValue(VData[I].Value, ValueKind, ValueMap);
735  }
736  std::vector<InstrProfValueSiteRecord> &ValueSites =
737  getOrCreateValueSitesForKind(ValueKind);
738  if (N == 0)
739  ValueSites.emplace_back();
740  else
741  ValueSites.emplace_back(VData, VData + N);
742 }
743 
744 #define INSTR_PROF_COMMON_API_IMPL
746 
747 /*!
748  * ValueProfRecordClosure Interface implementation for InstrProfRecord
749  * class. These C wrappers are used as adaptors so that C++ code can be
750  * invoked as callbacks.
751  */
753  return reinterpret_cast<const InstrProfRecord *>(Record)->getNumValueKinds();
754 }
755 
757  return reinterpret_cast<const InstrProfRecord *>(Record)
758  ->getNumValueSites(VKind);
759 }
760 
762  return reinterpret_cast<const InstrProfRecord *>(Record)
763  ->getNumValueData(VKind);
764 }
765 
767  uint32_t S) {
768  return reinterpret_cast<const InstrProfRecord *>(R)
769  ->getNumValueDataForSite(VK, S);
770 }
771 
772 void getValueForSiteInstrProf(const void *R, InstrProfValueData *Dst,
773  uint32_t K, uint32_t S) {
774  reinterpret_cast<const InstrProfRecord *>(R)->getValueForSite(Dst, K, S);
775 }
776 
777 ValueProfData *allocValueProfDataInstrProf(size_t TotalSizeInBytes) {
778  ValueProfData *VD =
779  (ValueProfData *)(new (::operator new(TotalSizeInBytes)) ValueProfData());
780  memset(VD, 0, TotalSizeInBytes);
781  return VD;
782 }
783 
784 static ValueProfRecordClosure InstrProfRecordClosure = {
785  nullptr,
790  nullptr,
793 
794 // Wrapper implementation using the closure mechanism.
795 uint32_t ValueProfData::getSize(const InstrProfRecord &Record) {
796  auto Closure = InstrProfRecordClosure;
797  Closure.Record = &Record;
798  return getValueProfDataSize(&Closure);
799 }
800 
801 // Wrapper implementation using the closure mechanism.
802 std::unique_ptr<ValueProfData>
803 ValueProfData::serializeFrom(const InstrProfRecord &Record) {
804  InstrProfRecordClosure.Record = &Record;
805 
806  std::unique_ptr<ValueProfData> VPD(
807  serializeValueProfDataFrom(&InstrProfRecordClosure, nullptr));
808  return VPD;
809 }
810 
811 void ValueProfRecord::deserializeTo(InstrProfRecord &Record,
812  InstrProfSymtab *SymTab) {
813  Record.reserveSites(Kind, NumValueSites);
814 
815  InstrProfValueData *ValueData = getValueProfRecordValueData(this);
816  for (uint64_t VSite = 0; VSite < NumValueSites; ++VSite) {
817  uint8_t ValueDataCount = this->SiteCountArray[VSite];
818  Record.addValueData(Kind, VSite, ValueData, ValueDataCount, SymTab);
819  ValueData += ValueDataCount;
820  }
821 }
822 
823 // For writing/serializing, Old is the host endianness, and New is
824 // byte order intended on disk. For Reading/deserialization, Old
825 // is the on-disk source endianness, and New is the host endianness.
826 void ValueProfRecord::swapBytes(support::endianness Old,
827  support::endianness New) {
828  using namespace support;
829 
830  if (Old == New)
831  return;
832 
833  if (getHostEndianness() != Old) {
834  sys::swapByteOrder<uint32_t>(NumValueSites);
835  sys::swapByteOrder<uint32_t>(Kind);
836  }
837  uint32_t ND = getValueProfRecordNumValueData(this);
838  InstrProfValueData *VD = getValueProfRecordValueData(this);
839 
840  // No need to swap byte array: SiteCountArrray.
841  for (uint32_t I = 0; I < ND; I++) {
842  sys::swapByteOrder<uint64_t>(VD[I].Value);
843  sys::swapByteOrder<uint64_t>(VD[I].Count);
844  }
845  if (getHostEndianness() == Old) {
846  sys::swapByteOrder<uint32_t>(NumValueSites);
847  sys::swapByteOrder<uint32_t>(Kind);
848  }
849 }
850 
851 void ValueProfData::deserializeTo(InstrProfRecord &Record,
852  InstrProfSymtab *SymTab) {
853  if (NumValueKinds == 0)
854  return;
855 
856  ValueProfRecord *VR = getFirstValueProfRecord(this);
857  for (uint32_t K = 0; K < NumValueKinds; K++) {
858  VR->deserializeTo(Record, SymTab);
859  VR = getValueProfRecordNext(VR);
860  }
861 }
862 
863 template <class T>
864 static T swapToHostOrder(const unsigned char *&D, support::endianness Orig) {
865  using namespace support;
866 
867  if (Orig == little)
868  return endian::readNext<T, little, unaligned>(D);
869  else
870  return endian::readNext<T, big, unaligned>(D);
871 }
872 
873 static std::unique_ptr<ValueProfData> allocValueProfData(uint32_t TotalSize) {
874  return std::unique_ptr<ValueProfData>(new (::operator new(TotalSize))
875  ValueProfData());
876 }
877 
878 Error ValueProfData::checkIntegrity() {
879  if (NumValueKinds > IPVK_Last + 1)
880  return make_error<InstrProfError>(instrprof_error::malformed);
881  // Total size needs to be mulltiple of quadword size.
882  if (TotalSize % sizeof(uint64_t))
883  return make_error<InstrProfError>(instrprof_error::malformed);
884 
885  ValueProfRecord *VR = getFirstValueProfRecord(this);
886  for (uint32_t K = 0; K < this->NumValueKinds; K++) {
887  if (VR->Kind > IPVK_Last)
888  return make_error<InstrProfError>(instrprof_error::malformed);
889  VR = getValueProfRecordNext(VR);
890  if ((char *)VR - (char *)this > (ptrdiff_t)TotalSize)
891  return make_error<InstrProfError>(instrprof_error::malformed);
892  }
893  return Error::success();
894 }
895 
897 ValueProfData::getValueProfData(const unsigned char *D,
898  const unsigned char *const BufferEnd,
900  using namespace support;
901 
902  if (D + sizeof(ValueProfData) > BufferEnd)
903  return make_error<InstrProfError>(instrprof_error::truncated);
904 
905  const unsigned char *Header = D;
906  uint32_t TotalSize = swapToHostOrder<uint32_t>(Header, Endianness);
907  if (D + TotalSize > BufferEnd)
908  return make_error<InstrProfError>(instrprof_error::too_large);
909 
910  std::unique_ptr<ValueProfData> VPD = allocValueProfData(TotalSize);
911  memcpy(VPD.get(), D, TotalSize);
912  // Byte swap.
913  VPD->swapBytesToHost(Endianness);
914 
915  Error E = VPD->checkIntegrity();
916  if (E)
917  return std::move(E);
918 
919  return std::move(VPD);
920 }
921 
922 void ValueProfData::swapBytesToHost(support::endianness Endianness) {
923  using namespace support;
924 
925  if (Endianness == getHostEndianness())
926  return;
927 
928  sys::swapByteOrder<uint32_t>(TotalSize);
929  sys::swapByteOrder<uint32_t>(NumValueKinds);
930 
931  ValueProfRecord *VR = getFirstValueProfRecord(this);
932  for (uint32_t K = 0; K < NumValueKinds; K++) {
933  VR->swapBytes(Endianness, getHostEndianness());
934  VR = getValueProfRecordNext(VR);
935  }
936 }
937 
938 void ValueProfData::swapBytesFromHost(support::endianness Endianness) {
939  using namespace support;
940 
941  if (Endianness == getHostEndianness())
942  return;
943 
944  ValueProfRecord *VR = getFirstValueProfRecord(this);
945  for (uint32_t K = 0; K < NumValueKinds; K++) {
946  ValueProfRecord *NVR = getValueProfRecordNext(VR);
947  VR->swapBytes(getHostEndianness(), Endianness);
948  VR = NVR;
949  }
950  sys::swapByteOrder<uint32_t>(TotalSize);
951  sys::swapByteOrder<uint32_t>(NumValueKinds);
952 }
953 
955  const InstrProfRecord &InstrProfR,
957  uint32_t MaxMDCount) {
958  uint32_t NV = InstrProfR.getNumValueDataForSite(ValueKind, SiteIdx);
959  if (!NV)
960  return;
961 
962  uint64_t Sum = 0;
963  std::unique_ptr<InstrProfValueData[]> VD =
964  InstrProfR.getValueForSite(ValueKind, SiteIdx, &Sum);
965 
966  ArrayRef<InstrProfValueData> VDs(VD.get(), NV);
967  annotateValueSite(M, Inst, VDs, Sum, ValueKind, MaxMDCount);
968 }
969 
972  uint64_t Sum, InstrProfValueKind ValueKind,
973  uint32_t MaxMDCount) {
974  LLVMContext &Ctx = M.getContext();
975  MDBuilder MDHelper(Ctx);
977  // Tag
978  Vals.push_back(MDHelper.createString("VP"));
979  // Value Kind
980  Vals.push_back(MDHelper.createConstant(
982  // Total Count
983  Vals.push_back(
984  MDHelper.createConstant(ConstantInt::get(Type::getInt64Ty(Ctx), Sum)));
985 
986  // Value Profile Data
987  uint32_t MDCount = MaxMDCount;
988  for (auto &VD : VDs) {
989  Vals.push_back(MDHelper.createConstant(
990  ConstantInt::get(Type::getInt64Ty(Ctx), VD.Value)));
991  Vals.push_back(MDHelper.createConstant(
992  ConstantInt::get(Type::getInt64Ty(Ctx), VD.Count)));
993  if (--MDCount == 0)
994  break;
995  }
996  Inst.setMetadata(LLVMContext::MD_prof, MDNode::get(Ctx, Vals));
997 }
998 
1001  uint32_t MaxNumValueData,
1002  InstrProfValueData ValueData[],
1003  uint32_t &ActualNumValueData, uint64_t &TotalC,
1004  bool GetNoICPValue) {
1005  MDNode *MD = Inst.getMetadata(LLVMContext::MD_prof);
1006  if (!MD)
1007  return false;
1008 
1009  unsigned NOps = MD->getNumOperands();
1010 
1011  if (NOps < 5)
1012  return false;
1013 
1014  // Operand 0 is a string tag "VP":
1015  MDString *Tag = cast<MDString>(MD->getOperand(0));
1016  if (!Tag)
1017  return false;
1018 
1019  if (!Tag->getString().equals("VP"))
1020  return false;
1021 
1022  // Now check kind:
1023  ConstantInt *KindInt = mdconst::dyn_extract<ConstantInt>(MD->getOperand(1));
1024  if (!KindInt)
1025  return false;
1026  if (KindInt->getZExtValue() != ValueKind)
1027  return false;
1028 
1029  // Get total count
1030  ConstantInt *TotalCInt = mdconst::dyn_extract<ConstantInt>(MD->getOperand(2));
1031  if (!TotalCInt)
1032  return false;
1033  TotalC = TotalCInt->getZExtValue();
1034 
1035  ActualNumValueData = 0;
1036 
1037  for (unsigned I = 3; I < NOps; I += 2) {
1038  if (ActualNumValueData >= MaxNumValueData)
1039  break;
1040  ConstantInt *Value = mdconst::dyn_extract<ConstantInt>(MD->getOperand(I));
1041  ConstantInt *Count =
1042  mdconst::dyn_extract<ConstantInt>(MD->getOperand(I + 1));
1043  if (!Value || !Count)
1044  return false;
1045  uint64_t CntValue = Count->getZExtValue();
1046  if (!GetNoICPValue && (CntValue == NOMORE_ICP_MAGICNUM))
1047  continue;
1048  ValueData[ActualNumValueData].Value = Value->getZExtValue();
1049  ValueData[ActualNumValueData].Count = CntValue;
1050  ActualNumValueData++;
1051  }
1052  return true;
1053 }
1054 
1056  return F.getMetadata(getPGOFuncNameMetadataName());
1057 }
1058 
1060  // Only for internal linkage functions.
1061  if (PGOFuncName == F.getName())
1062  return;
1063  // Don't create duplicated meta-data.
1065  return;
1066  LLVMContext &C = F.getContext();
1067  MDNode *N = MDNode::get(C, MDString::get(C, PGOFuncName));
1068  F.setMetadata(getPGOFuncNameMetadataName(), N);
1069 }
1070 
1071 bool needsComdatForCounter(const Function &F, const Module &M) {
1072  if (F.hasComdat())
1073  return true;
1074 
1075  if (!Triple(M.getTargetTriple()).supportsCOMDAT())
1076  return false;
1077 
1078  // See createPGOFuncNameVar for more details. To avoid link errors, profile
1079  // counters for function with available_externally linkage needs to be changed
1080  // to linkonce linkage. On ELF based systems, this leads to weak symbols to be
1081  // created. Without using comdat, duplicate entries won't be removed by the
1082  // linker leading to increased data segement size and raw profile size. Even
1083  // worse, since the referenced counter from profile per-function data object
1084  // will be resolved to the common strong definition, the profile counts for
1085  // available_externally functions will end up being duplicated in raw profile
1086  // data. This can result in distorted profile as the counts of those dups
1087  // will be accumulated by the profile merger.
1088  GlobalValue::LinkageTypes Linkage = F.getLinkage();
1091  return false;
1092 
1093  return true;
1094 }
1095 
1096 // Check if INSTR_PROF_RAW_VERSION_VAR is defined.
1097 bool isIRPGOFlagSet(const Module *M) {
1098  auto IRInstrVar =
1099  M->getNamedGlobal(INSTR_PROF_QUOTE(INSTR_PROF_RAW_VERSION_VAR));
1100  if (!IRInstrVar || IRInstrVar->isDeclaration() ||
1101  IRInstrVar->hasLocalLinkage())
1102  return false;
1103 
1104  // Check if the flag is set.
1105  if (!IRInstrVar->hasInitializer())
1106  return false;
1107 
1108  auto *InitVal = dyn_cast_or_null<ConstantInt>(IRInstrVar->getInitializer());
1109  if (!InitVal)
1110  return false;
1111  return (InitVal->getZExtValue() & VARIANT_MASK_IR_PROF) != 0;
1112 }
1113 
1114 // Check if we can safely rename this Comdat function.
1115 bool canRenameComdatFunc(const Function &F, bool CheckAddressTaken) {
1116  if (F.getName().empty())
1117  return false;
1118  if (!needsComdatForCounter(F, *(F.getParent())))
1119  return false;
1120  // Unsafe to rename the address-taken function (which can be used in
1121  // function comparison).
1122  if (CheckAddressTaken && F.hasAddressTaken())
1123  return false;
1124  // Only safe to do if this function may be discarded if it is not used
1125  // in the compilation unit.
1126  if (!GlobalValue::isDiscardableIfUnused(F.getLinkage()))
1127  return false;
1128 
1129  // For AvailableExternallyLinkage functions.
1130  if (!F.hasComdat()) {
1132  return true;
1133  }
1134  return true;
1135 }
1136 
1137 // Create a COMDAT variable INSTR_PROF_RAW_VERSION_VAR to make the runtime
1138 // aware this is an ir_level profile so it can set the version flag.
1140  bool InstrEntryBBEnabled) {
1141  const StringRef VarName(INSTR_PROF_QUOTE(INSTR_PROF_RAW_VERSION_VAR));
1142  Type *IntTy64 = Type::getInt64Ty(M.getContext());
1143  uint64_t ProfileVersion = (INSTR_PROF_RAW_VERSION | VARIANT_MASK_IR_PROF);
1144  if (IsCS)
1145  ProfileVersion |= VARIANT_MASK_CSIR_PROF;
1146  if (InstrEntryBBEnabled)
1147  ProfileVersion |= VARIANT_MASK_INSTR_ENTRY;
1148  auto IRLevelVersionVariable = new GlobalVariable(
1149  M, IntTy64, true, GlobalValue::WeakAnyLinkage,
1150  Constant::getIntegerValue(IntTy64, APInt(64, ProfileVersion)), VarName);
1151  IRLevelVersionVariable->setVisibility(GlobalValue::DefaultVisibility);
1152  Triple TT(M.getTargetTriple());
1153  if (TT.supportsCOMDAT()) {
1154  IRLevelVersionVariable->setLinkage(GlobalValue::ExternalLinkage);
1155  IRLevelVersionVariable->setComdat(M.getOrInsertComdat(VarName));
1156  }
1157 }
1158 
1159 // Create the variable for the profile file name.
1160 void createProfileFileNameVar(Module &M, StringRef InstrProfileOutput) {
1161  if (InstrProfileOutput.empty())
1162  return;
1163  Constant *ProfileNameConst =
1164  ConstantDataArray::getString(M.getContext(), InstrProfileOutput, true);
1165  GlobalVariable *ProfileNameVar = new GlobalVariable(
1166  M, ProfileNameConst->getType(), true, GlobalValue::WeakAnyLinkage,
1167  ProfileNameConst, INSTR_PROF_QUOTE(INSTR_PROF_PROFILE_NAME_VAR));
1168  Triple TT(M.getTargetTriple());
1169  if (TT.supportsCOMDAT()) {
1170  ProfileNameVar->setLinkage(GlobalValue::ExternalLinkage);
1171  ProfileNameVar->setComdat(M.getOrInsertComdat(
1172  StringRef(INSTR_PROF_QUOTE(INSTR_PROF_PROFILE_NAME_VAR))));
1173  }
1174 }
1175 
1176 Error OverlapStats::accumulateCounts(const std::string &BaseFilename,
1177  const std::string &TestFilename,
1178  bool IsCS) {
1179  auto getProfileSum = [IsCS](const std::string &Filename,
1180  CountSumOrPercent &Sum) -> Error {
1181  auto ReaderOrErr = InstrProfReader::create(Filename);
1182  if (Error E = ReaderOrErr.takeError()) {
1183  return E;
1184  }
1185  auto Reader = std::move(ReaderOrErr.get());
1186  Reader->accumulateCounts(Sum, IsCS);
1187  return Error::success();
1188  };
1189  auto Ret = getProfileSum(BaseFilename, Base);
1190  if (Ret)
1191  return Ret;
1192  Ret = getProfileSum(TestFilename, Test);
1193  if (Ret)
1194  return Ret;
1195  this->BaseFilename = &BaseFilename;
1196  this->TestFilename = &TestFilename;
1197  Valid = true;
1198  return Error::success();
1199 }
1200 
1202  Mismatch.NumEntries += 1;
1203  Mismatch.CountSum += MismatchFunc.CountSum / Test.CountSum;
1204  for (unsigned I = 0; I < IPVK_Last - IPVK_First + 1; I++) {
1205  if (Test.ValueCounts[I] >= 1.0f)
1206  Mismatch.ValueCounts[I] +=
1207  MismatchFunc.ValueCounts[I] / Test.ValueCounts[I];
1208  }
1209 }
1210 
1212  Unique.NumEntries += 1;
1213  Unique.CountSum += UniqueFunc.CountSum / Test.CountSum;
1214  for (unsigned I = 0; I < IPVK_Last - IPVK_First + 1; I++) {
1215  if (Test.ValueCounts[I] >= 1.0f)
1216  Unique.ValueCounts[I] += UniqueFunc.ValueCounts[I] / Test.ValueCounts[I];
1217  }
1218 }
1219 
1221  if (!Valid)
1222  return;
1223 
1224  const char *EntryName =
1225  (Level == ProgramLevel ? "functions" : "edge counters");
1226  if (Level == ProgramLevel) {
1227  OS << "Profile overlap infomation for base_profile: " << *BaseFilename
1228  << " and test_profile: " << *TestFilename << "\nProgram level:\n";
1229  } else {
1230  OS << "Function level:\n"
1231  << " Function: " << FuncName << " (Hash=" << FuncHash << ")\n";
1232  }
1233 
1234  OS << " # of " << EntryName << " overlap: " << Overlap.NumEntries << "\n";
1235  if (Mismatch.NumEntries)
1236  OS << " # of " << EntryName << " mismatch: " << Mismatch.NumEntries
1237  << "\n";
1238  if (Unique.NumEntries)
1239  OS << " # of " << EntryName
1240  << " only in test_profile: " << Unique.NumEntries << "\n";
1241 
1242  OS << " Edge profile overlap: " << format("%.3f%%", Overlap.CountSum * 100)
1243  << "\n";
1244  if (Mismatch.NumEntries)
1245  OS << " Mismatched count percentage (Edge): "
1246  << format("%.3f%%", Mismatch.CountSum * 100) << "\n";
1247  if (Unique.NumEntries)
1248  OS << " Percentage of Edge profile only in test_profile: "
1249  << format("%.3f%%", Unique.CountSum * 100) << "\n";
1250  OS << " Edge profile base count sum: " << format("%.0f", Base.CountSum)
1251  << "\n"
1252  << " Edge profile test count sum: " << format("%.0f", Test.CountSum)
1253  << "\n";
1254 
1255  for (unsigned I = 0; I < IPVK_Last - IPVK_First + 1; I++) {
1256  if (Base.ValueCounts[I] < 1.0f && Test.ValueCounts[I] < 1.0f)
1257  continue;
1258  char ProfileKindName[20];
1259  switch (I) {
1260  case IPVK_IndirectCallTarget:
1261  strncpy(ProfileKindName, "IndirectCall", 19);
1262  break;
1263  case IPVK_MemOPSize:
1264  strncpy(ProfileKindName, "MemOP", 19);
1265  break;
1266  default:
1267  snprintf(ProfileKindName, 19, "VP[%d]", I);
1268  break;
1269  }
1270  OS << " " << ProfileKindName
1271  << " profile overlap: " << format("%.3f%%", Overlap.ValueCounts[I] * 100)
1272  << "\n";
1273  if (Mismatch.NumEntries)
1274  OS << " Mismatched count percentage (" << ProfileKindName
1275  << "): " << format("%.3f%%", Mismatch.ValueCounts[I] * 100) << "\n";
1276  if (Unique.NumEntries)
1277  OS << " Percentage of " << ProfileKindName
1278  << " profile only in test_profile: "
1279  << format("%.3f%%", Unique.ValueCounts[I] * 100) << "\n";
1280  OS << " " << ProfileKindName
1281  << " profile base count sum: " << format("%.0f", Base.ValueCounts[I])
1282  << "\n"
1283  << " " << ProfileKindName
1284  << " profile test count sum: " << format("%.0f", Test.ValueCounts[I])
1285  << "\n";
1286  }
1287 }
1288 
1289 } // end namespace llvm
llvm::SaturatingMultiply
std::enable_if_t< std::is_unsigned< T >::value, T > SaturatingMultiply(T X, T Y, bool *ResultOverflowed=nullptr)
Multiply two unsigned integers, X and Y, of type T.
Definition: MathExtras.h:820
llvm::OverlapStats::Unique
CountSumOrPercent Unique
Definition: InstrProf.h:620
llvm::EngineKind::Kind
Kind
Definition: ExecutionEngine.h:524
llvm::OverlapStats::Level
OverlapStatsLevel Level
Definition: InstrProf.h:621
llvm::createPGOFuncNameMetadata
void createPGOFuncNameMetadata(Function &F, StringRef PGOFuncName)
Create the PGOFuncName meta data if PGOFuncName is different from function's raw name.
Definition: InstrProf.cpp:1059
Compression.h
llvm::OverlapStats::score
static double score(uint64_t Val1, uint64_t Val2, double Sum1, double Sum2)
Definition: InstrProf.h:644
llvm::allocValueProfData
static std::unique_ptr< ValueProfData > allocValueProfData(uint32_t TotalSize)
Definition: InstrProf.cpp:873
llvm::StringRef::startswith
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:289
llvm::instrprof_error::bad_header
@ bad_header
MathExtras.h
llvm
Definition: AllocatorList.h:23
llvm::MDBuilder::createConstant
ConstantAsMetadata * createConstant(Constant *C)
Return the given constant as metadata.
Definition: MDBuilder.cpp:24
llvm::msgpack::Endianness
constexpr support::endianness Endianness
The endianness of all multi-byte encoded values in MessagePack.
Definition: MsgPack.h:24
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::StringRef::empty
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:156
llvm::GlobalValue::getGlobalIdentifier
std::string getGlobalIdentifier() const
Return the modified name for this global value suitable to be used as the key for a global lookup (e....
Definition: Globals.cpp:157
llvm::GlobalValue::LinkOnceAnyLinkage
@ LinkOnceAnyLinkage
Keep one copy of function when linking (inline)
Definition: GlobalValue.h:50
Metadata.h
llvm::OverlapStats::Valid
bool Valid
Definition: InstrProf.h:626
llvm::InstrProfError::message
std::string message() const override
Return the error message as a string.
Definition: InstrProf.cpp:218
llvm::getNumValueKindsInstrProf
uint32_t getNumValueKindsInstrProf(const void *Record)
ValueProfRecordClosure Interface implementation for InstrProfRecord class.
Definition: InstrProf.cpp:752
llvm::instrprof_error::uncompress_failed
@ uncompress_failed
llvm::GlobalValue::HiddenVisibility
@ HiddenVisibility
The GV is hidden.
Definition: GlobalValue.h:64
llvm::Function
Definition: Function.h:61
StringRef.h
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
llvm::InstrProfRecord::getValueForSite
std::unique_ptr< InstrProfValueData[]> getValueForSite(uint32_t ValueKind, uint32_t Site, uint64_t *TotalC=nullptr) const
Return the array of profiled values at Site.
Definition: InstrProf.h:892
llvm::needsComdatForCounter
bool needsComdatForCounter(const Function &F, const Module &M)
Check if we can use Comdat for profile variables.
Definition: InstrProf.cpp:1071
llvm::getPGOFuncNameVarInitializer
StringRef getPGOFuncNameVarInitializer(GlobalVariable *NameVar)
Return the initializer in string of the PGO name var NameVar.
Definition: InstrProf.cpp:441
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
Path.h
llvm::GlobalValue::isLocalLinkage
static bool isLocalLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:329
llvm::getPGOFuncName
std::string getPGOFuncName(const Function &F, bool InLTO=false, uint64_t Version=INSTR_PROF_INDEX_VERSION)
Return the modified name for function F suitable to be used the key for profile lookup.
Definition: InstrProf.cpp:262
ErrorHandling.h
llvm::zlib::uncompress
Error uncompress(StringRef InputBuffer, char *UncompressedBuffer, size_t &UncompressedSize)
Definition: Compression.cpp:63
llvm::InstrProfSymtab::create
Error create(object::SectionRef &Section)
Create InstrProfSymtab from an object file section which contains function PGO names.
llvm::OverlapStats::dump
void dump(raw_fd_ostream &OS) const
Definition: InstrProf.cpp:1220
ManagedStatic.h
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:332
llvm::GlobalVariable
Definition: GlobalVariable.h:40
llvm::getInstrProfNameSeparator
StringRef getInstrProfNameSeparator()
Return the marker used to separate PGO names during serialization.
Definition: InstrProf.h:163
llvm::getValueForSiteInstrProf
void getValueForSiteInstrProf(const void *R, InstrProfValueData *Dst, uint32_t K, uint32_t S)
Definition: InstrProf.cpp:772
Error.h
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:45
SwapByteOrder.h
llvm::createPGOFuncNameVar
GlobalVariable * createPGOFuncNameVar(Function &F, StringRef PGOFuncName)
Create and return the global variable for function name used in PGO instrumentation.
Definition: InstrProf.cpp:341
llvm::tgtok::VarName
@ VarName
Definition: TGLexer.h:71
llvm::cl::Hidden
@ Hidden
Definition: CommandLine.h:140
StaticFuncFullModulePrefix
static cl::opt< bool > StaticFuncFullModulePrefix("static-func-full-module-prefix", cl::init(true), cl::Hidden, cl::desc("Use full module build paths in the profile counter names for " "static functions."))
llvm::instrprof_error::zlib_unavailable
@ zlib_unavailable
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:46
llvm::OverlapStats
Definition: InstrProf.h:611
Module.h
llvm::InstrProfValueSiteRecord::scale
void scale(uint64_t N, uint64_t D, function_ref< void(instrprof_error)> Warn)
Scale up value profile data counts by N (Numerator) / D (Denominator).
Definition: InstrProf.cpp:646
llvm::InstrProfRecord::overlap
void overlap(InstrProfRecord &Other, OverlapStats &Overlap, OverlapStats &FuncLevelOverlap, uint64_t ValueCutoff)
Compute the overlap b/w this IntrprofRecord and Other.
Definition: InstrProf.cpp:572
llvm::instrprof_error::value_site_count_mismatch
@ value_site_count_mismatch
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::GlobalValue::DefaultVisibility
@ DefaultVisibility
The GV is visible.
Definition: GlobalValue.h:63
llvm::ore::NV
DiagnosticInfoOptimizationBase::Argument NV
Definition: OptimizationRemarkEmitter.h:128
llvm::MipsISD::Ret
@ Ret
Definition: MipsISelLowering.h:116
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::GlobalValue::LinkageTypes
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition: GlobalValue.h:47
llvm::getPGOFuncNameVarName
std::string getPGOFuncNameVarName(StringRef FuncName, GlobalValue::LinkageTypes Linkage)
Return the name of the global variable used to store a function name in PGO instrumentation.
Definition: InstrProf.cpp:296
llvm::createProfileFileNameVar
void createProfileFileNameVar(Module &M, StringRef InstrProfileOutput)
Definition: InstrProf.cpp:1160
llvm::instrprof_error::invalid_prof
@ invalid_prof
LLVM_ATTRIBUTE_UNUSED
#define LLVM_ATTRIBUTE_UNUSED
Definition: Compiler.h:188
llvm::GlobalValue::isDiscardableIfUnused
bool isDiscardableIfUnused() const
Definition: GlobalValue.h:463
llvm::consumeError
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:1006
llvm::Type::getInt32Ty
static IntegerType * getInt32Ty(LLVMContext &C)
Definition: Type.cpp:204
llvm::ArrayRef::empty
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:158
llvm::InstrProfRecord
Profiling information for a single function.
Definition: InstrProf.h:691
llvm::MDNode::get
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1198
F
#define F(x, y, z)
Definition: MD5.cpp:56
InstrProfData.inc
llvm::Instruction::setMetadata
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
Definition: Metadata.cpp:1330
llvm::InstrProfValueSiteRecord::merge
void merge(InstrProfValueSiteRecord &Input, uint64_t Weight, function_ref< void(instrprof_error)> Warn)
Merge data from another InstrProfValueSiteRecord Optionally scale merged counts by Weight.
Definition: InstrProf.cpp:623
llvm::MDNode::getNumOperands
unsigned getNumOperands() const
Return number of MDNode operands.
Definition: Metadata.h:1108
llvm::OverlapStats::TestFilename
const std::string * TestFilename
Definition: InstrProf.h:623
Instruction.h
CommandLine.h
llvm::ConstantInt
This is the shared class of boolean and integer constants.
Definition: Constants.h:77
llvm::AMDGPU::HSAMD::ValueKind
ValueKind
Value kinds.
Definition: AMDGPUMetadata.h:73
llvm::decodeULEB128
uint64_t decodeULEB128(const uint8_t *p, unsigned *n=nullptr, const uint8_t *end=nullptr, const char **error=nullptr)
Utility function to decode a ULEB128 value.
Definition: LEB128.h:128
GlobalValue.h
llvm::InstrProfRecord::getNumValueDataForSite
uint32_t getNumValueDataForSite(uint32_t ValueKind, uint32_t Site) const
Return the number of value data collected for ValueKind at profiling site: Site.
Definition: InstrProf.h:886
llvm::MutableArrayRef
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:305
ptrdiff_t
Constants.h
llvm::CountSumOrPercent::CountSum
double CountSum
Definition: InstrProf.h:599
SmallString.h
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::zlib::BestSizeCompression
static constexpr int BestSizeCompression
Definition: Compression.h:28
llvm::support::little
@ little
Definition: Endian.h:27
llvm::StringRef::split
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition: StringRef.h:730
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::InstrProfRecordClosure
static ValueProfRecordClosure InstrProfRecordClosure
Definition: InstrProf.cpp:784
llvm::canRenameComdatFunc
bool canRenameComdatFunc(const Function &F, bool CheckAddressTaken=false)
Check if we can safely rename this Comdat function.
Definition: InstrProf.cpp:1115
llvm::ManagedStatic
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
Definition: ManagedStatic.h:83
llvm::instrprof_error::compress_failed
@ compress_failed
llvm::InstrProfRecord::getNumValueSites
uint32_t getNumValueSites(uint32_t ValueKind) const
Return the number of instrumented sites for ValueKind.
Definition: InstrProf.h:882
llvm::allocValueProfDataInstrProf
ValueProfData * allocValueProfDataInstrProf(size_t TotalSizeInBytes)
Definition: InstrProf.cpp:777
llvm::Triple::supportsCOMDAT
bool supportsCOMDAT() const
Tests whether the target supports comdat.
Definition: Triple.h:809
llvm::stripDirPrefix
static StringRef stripDirPrefix(StringRef PathNameStr, uint32_t NumPrefix)
Definition: InstrProf.cpp:234
llvm::InstrProfError::ID
static char ID
Definition: InstrProf.h:336
llvm::Instruction
Definition: Instruction.h:45
InstrProf.h
llvm::swapToHostOrder
static T swapToHostOrder(const unsigned char *&D, support::endianness Orig)
Definition: InstrProf.cpp:864
llvm::instrprof_error::truncated
@ truncated
MDBuilder.h
llvm::zlib::compress
Error compress(StringRef InputBuffer, SmallVectorImpl< char > &CompressedBuffer, int Level=DefaultCompression)
Definition: Compression.cpp:49
llvm::ConstantInt::get
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Definition: Constants.cpp:885
llvm::IndexedInstrProf::Version
const uint64_t Version
Definition: InstrProf.h:991
llvm::OverlapStats::FuncName
StringRef FuncName
Definition: InstrProf.h:624
StaticFuncStripDirNamePrefix
static cl::opt< unsigned > StaticFuncStripDirNamePrefix("static-func-strip-dirname-prefix", cl::init(0), cl::Hidden, cl::desc("Strip specified level of directory name from source path in " "the profile counter name for static functions."))
llvm::GlobalValue::InternalLinkage
@ InternalLinkage
Rename collisions when linking (static functions).
Definition: GlobalValue.h:55
llvm::instrprof_error::bad_magic
@ bad_magic
llvm::instrprof_error::unsupported_version
@ unsupported_version
Type.h
llvm::instrprof_error::too_large
@ too_large
llvm::InstrProfSectKind
InstrProfSectKind
Definition: InstrProf.h:57
llvm::Instruction::getMetadata
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
Definition: Instruction.h:277
llvm::SmallString< 128 >
llvm::ARM_PROC::IE
@ IE
Definition: ARMBaseInfo.h:27
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:176
llvm::MDNode::getOperand
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1102
llvm::MDBuilder::createString
MDString * createString(StringRef Str)
Return the given string as metadata.
Definition: MDBuilder.cpp:20
llvm::getHostEndianness
support::endianness getHostEndianness()
Definition: InstrProf.h:928
llvm::getInstrProfNameVarPrefix
StringRef getInstrProfNameVarPrefix()
Return the name prefix of variables containing instrumented function names.
Definition: InstrProf.h:84
llvm::instrprof_error::unsupported_hash_type
@ unsupported_hash_type
llvm::cl::opt< bool >
InstrProfReader.h
llvm::CountSumOrPercent::NumEntries
uint64_t NumEntries
Definition: InstrProf.h:598
llvm::GlobalVariable::getInitializer
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
Definition: GlobalVariable.h:136
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
getInstrProfErrString
static std::string getInstrProfErrString(instrprof_error Err)
Definition: InstrProf.cpp:77
llvm::count
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
Definition: STLExtras.h:1588
D
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
const
aarch64 promote const
Definition: AArch64PromoteConstant.cpp:232
llvm::GlobalValue::WeakAnyLinkage
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
Definition: GlobalValue.h:52
llvm::SoftInstrProfErrors::addError
void addError(instrprof_error IE)
Track a soft error (IE) and increment its associated counter.
Definition: InstrProf.cpp:193
llvm::getNumValueSitesInstrProf
uint32_t getNumValueSitesInstrProf(const void *Record, uint32_t VKind)
Definition: InstrProf.cpp:756
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::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
llvm::CountSumOrPercent
Definition: InstrProf.h:597
llvm::isIRPGOFlagSet
bool isIRPGOFlagSet(const Module *M)
Check if INSTR_PROF_RAW_VERSION_VAR is defined.
Definition: InstrProf.cpp:1097
llvm::instrprof_error::empty_raw_profile
@ empty_raw_profile
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::GlobalObject::setComdat
void setComdat(Comdat *C)
Definition: GlobalObject.h:127
StringExtras.h
llvm::instrprof_error
instrprof_error
Definition: InstrProf.h:282
llvm::instrprof_error::success
@ success
llvm::SaturatingMultiplyAdd
std::enable_if_t< std::is_unsigned< T >::value, T > SaturatingMultiplyAdd(T X, T Y, T A, bool *ResultOverflowed=nullptr)
Multiply two unsigned integers, X and Y, and add the unsigned integer, A to the product.
Definition: MathExtras.h:866
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:440
llvm::GlobalValue::setLinkage
void setLinkage(LinkageTypes LT)
Definition: GlobalValue.h:454
ArrayRef.h
llvm::HighlightColor::Address
@ Address
llvm::MDString::get
static MDString * get(LLVMContext &Context, StringRef Str)
Definition: Metadata.cpp:467
message
message(STATUS "Targeting ${t}") add_subdirectory($
Definition: CMakeLists.txt:31
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::instrprof_error::unknown_function
@ unknown_function
memcpy
<%struct.s * > cast struct s *S to sbyte *< sbyte * > sbyte uint cast struct s *agg result to sbyte *< sbyte * > sbyte uint cast struct s *memtmp to sbyte *< sbyte * > sbyte uint ret void llc ends up issuing two memcpy or custom lower memcpy(of small size) to be ldmia/stmia. I think option 2 is better but the current register allocator cannot allocate a chunk of registers at a time. A feasible temporary solution is to use specific physical registers at the lowering time for small(<
llvm::instrprof_error::unrecognized_format
@ unrecognized_format
llvm::zlib::isAvailable
bool isAvailable()
Definition: Compression.cpp:47
llvm::Record
Definition: Record.h:1472
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::InstrProfValueKind
InstrProfValueKind
Definition: InstrProf.h:238
llvm::MDNode
Metadata node.
Definition: Metadata.h:897
llvm::collectPGOFuncNameStrings
Error collectPGOFuncNameStrings(ArrayRef< std::string > NameStrs, bool doCompression, std::string &Result)
Given a vector of strings (function PGO names) NameStrs, the method generates a combined string Resul...
Definition: InstrProf.cpp:400
llvm::getNumValueDataInstrProf
uint32_t getNumValueDataInstrProf(const void *Record, uint32_t VKind)
Definition: InstrProf.cpp:761
llvm::StringRef::bytes_begin
const unsigned char * bytes_begin() const
Definition: StringRef.h:135
llvm::APInt
Class for arbitrary precision integers.
Definition: APInt.h:71
llvm::InstrProfSymtab::getFunctionHashFromAddress
uint64_t getFunctionHashFromAddress(uint64_t Address)
Return a function's hash, or 0, if the function isn't in this SymTab.
Definition: InstrProf.cpp:386
Triple.h
llvm::InstrProfRecord::accumulateCounts
void accumulateCounts(CountSumOrPercent &Sum) const
Compute the sums of all counts and store in Sum.
Definition: InstrProf.cpp:503
llvm::OverlapStats::addOneUnique
void addOneUnique(const CountSumOrPercent &UniqueFunc)
Definition: InstrProf.cpp:1211
llvm::ArrayRef< std::string >
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
llvm::Value::getType
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:256
ErrorCategory
static ManagedStatic< InstrProfErrorCategoryType > ErrorCategory
Definition: InstrProf.cpp:140
uint32_t
llvm::instrprof_error::eof
@ eof
Compiler.h
llvm::ConstantDataArray::getString
static Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true)
This method constructs a CDS and initializes it with a text string.
Definition: Constants.cpp:3040
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::format
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:124
llvm::GlobalValue::AvailableExternallyLinkage
@ AvailableExternallyLinkage
Available for inspection, not emission.
Definition: GlobalValue.h:49
llvm::instrprof_error::hash_mismatch
@ hash_mismatch
llvm::Triple::ObjectFormatType
ObjectFormatType
Definition: Triple.h:231
llvm::ValueMap
See the file comment.
Definition: ValueMap.h:85
llvm::InstrProfValueSiteRecord::ValueData
std::list< InstrProfValueData > ValueData
Value profiling data pairs at a given value site.
Definition: InstrProf.h:661
llvm::raw_fd_ostream
A raw_ostream that writes to a file descriptor.
Definition: raw_ostream.h:432
llvm::instrprof_category
const std::error_category & instrprof_category()
Definition: InstrProf.cpp:142
llvm::createIRLevelProfileFlagVar
void createIRLevelProfileFlagVar(Module &M, bool IsCS, bool InstrEntryBBEnabled)
Definition: InstrProf.cpp:1139
llvm::annotateValueSite
void annotateValueSite(Module &M, Instruction &Inst, const InstrProfRecord &InstrProfR, InstrProfValueKind ValueKind, uint32_t SiteIndx, uint32_t MaxMDCount=3)
Get the value profile data for value site SiteIdx from InstrProfR and annotate the instruction Inst w...
Definition: InstrProf.cpp:954
llvm::ConstantInt::getZExtValue
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:140
llvm::InstrProfRecord::merge
void merge(InstrProfRecord &Other, uint64_t Weight, function_ref< void(instrprof_error)> Warn)
Merge the counts in Other into this one.
Definition: InstrProf.cpp:677
llvm::DoInstrProfNameCompression
cl::opt< bool > DoInstrProfNameCompression
llvm::InstrProfRecord::overlapValueProfData
void overlapValueProfData(uint32_t ValueKind, InstrProfRecord &Src, OverlapStats &Overlap, OverlapStats &FuncLevelOverlap)
Compute the overlap of value profile counts.
Definition: InstrProf.cpp:554
llvm::readPGOFuncNameStrings
Error readPGOFuncNameStrings(StringRef NameStrings, InstrProfSymtab &Symtab)
NameStrings is a string composed of one of more sub-strings encoded in the format described above.
Definition: InstrProf.cpp:458
name
static const char * name
Definition: SVEIntrinsicOpts.cpp:93
llvm::partition_point
auto partition_point(R &&Range, Predicate P)
Binary search for the first iterator in a range where a predicate is false.
Definition: STLExtras.h:1653
Constant.h
llvm::Type::getInt64Ty
static IntegerType * getInt64Ty(LLVMContext &C)
Definition: Type.cpp:205
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
llvm::InstrProfSymtab
A symbol table used for function PGO name look-up with keys (such as pointers, md5hash values) to the...
Definition: InstrProf.h:414
llvm::StringRef::drop_front
LLVM_NODISCARD StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
Definition: StringRef.h:654
llvm::InstrProfValueSiteRecord::overlap
void overlap(InstrProfValueSiteRecord &Input, uint32_t ValueKind, OverlapStats &Overlap, OverlapStats &FuncLevelOverlap)
Compute the overlap b/w this record and Input record.
Definition: InstrProf.cpp:523
llvm::ArrayRef::begin
iterator begin() const
Definition: ArrayRef.h:151
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
GlobalVariable.h
llvm::GlobalValue::getGUID
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
Definition: GlobalValue.h:511
Casting.h
llvm::Triple::MachO
@ MachO
Definition: Triple.h:237
Function.h
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::OverlapStats::ProgramLevel
@ ProgramLevel
Definition: InstrProf.h:612
llvm::instrprof_error::count_mismatch
@ count_mismatch
llvm::NOMORE_ICP_MAGICNUM
const uint64_t NOMORE_ICP_MAGICNUM
Magic number in the value profile metadata showing a target has been promoted for the instruction and...
Definition: Metadata.h:57
llvm::OverlapStats::Overlap
CountSumOrPercent Overlap
Definition: InstrProf.h:618
llvm::getNumValueDataForSiteInstrProf
uint32_t getNumValueDataForSiteInstrProf(const void *R, uint32_t VK, uint32_t S)
Definition: InstrProf.cpp:766
llvm::OverlapStats::Mismatch
CountSumOrPercent Mismatch
Definition: InstrProf.h:619
llvm::getPGOFuncNameMetadataName
StringRef getPGOFuncNameMetadataName()
Definition: InstrProf.h:266
llvm::InstrProfRecord::addValueData
void addValueData(uint32_t ValueKind, uint32_t Site, InstrProfValueData *VData, uint32_t N, InstrProfSymtab *SymTab)
Add ValueData for ValueKind at value Site.
Definition: InstrProf.cpp:730
llvm::MDBuilder
Definition: MDBuilder.h:35
llvm::getInstrProfSectionName
std::string getInstrProfSectionName(InstrProfSectKind IPSK, Triple::ObjectFormatType OF, bool AddSegmentInfo=true)
Return the name of the profile section corresponding to IPSK.
Definition: InstrProf.cpp:174
llvm::GlobalValue::ExternalLinkage
@ ExternalLinkage
Externally visible function.
Definition: GlobalValue.h:48
llvm::sys::path::is_separator
bool is_separator(char value, Style style=Style::native)
Check whether the given char is a path separator on the host OS.
Definition: Path.cpp:599
llvm::InstrProfValueSiteRecord
Definition: InstrProf.h:659
llvm::InstrProfSymtab::addFuncName
Error addFuncName(StringRef FuncName)
Update the symtab by adding FuncName to the table.
Definition: InstrProf.h:475
llvm::Triple::COFF
@ COFF
Definition: Triple.h:234
llvm::GlobalValue::PrivateLinkage
@ PrivateLinkage
Like Internal, but omit from symbol table.
Definition: GlobalValue.h:56
llvm::Constant::getIntegerValue
static Constant * getIntegerValue(Type *Ty, const APInt &V)
Return the value for an integer or pointer constant, or a vector thereof, with the given scalar value...
Definition: Constants.cpp:388
SmallVector.h
llvm::OverlapStats::FuncHash
uint64_t FuncHash
Definition: InstrProf.h:625
N
#define N
llvm::OverlapStats::BaseFilename
const std::string * BaseFilename
Definition: InstrProf.h:622
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:163
llvm::max
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:350
support
Reimplement select in terms of SEL *We would really like to support but we need to prove that the add doesn t need to overflow between the two bit chunks *Implement pre post increment support(e.g. PR935) *Implement smarter const ant generation for binops with large immediates. A few ARMv6T2 ops should be pattern matched
Definition: README.txt:10
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::support::endianness
endianness
Definition: Endian.h:27
llvm::OverlapStats::Base
CountSumOrPercent Base
Definition: InstrProf.h:614
llvm::InstrProfValueSiteRecord::sortByTargetValues
void sortByTargetValues()
Sort ValueData ascending by Value.
Definition: InstrProf.h:669
llvm::instrprof_error::malformed
@ malformed
llvm::CountSumOrPercent::ValueCounts
double ValueCounts[IPVK_Last - IPVK_First+1]
Definition: InstrProf.h:600
llvm::getFuncNameWithoutPrefix
StringRef getFuncNameWithoutPrefix(StringRef PGOFuncName, StringRef FileName="<unknown>")
Given a PGO function name, remove the filename prefix and return the original (static) function name.
Definition: InstrProf.cpp:285
llvm::OverlapStats::accumulateCounts
Error accumulateCounts(const std::string &BaseFilename, const std::string &TestFilename, bool IsCS)
Definition: InstrProf.cpp:1176
llvm::getValueProfDataFromInst
bool getValueProfDataFromInst(const Instruction &Inst, InstrProfValueKind ValueKind, uint32_t MaxNumValueData, InstrProfValueData ValueData[], uint32_t &ActualNumValueData, uint64_t &TotalC, bool GetNoICPValue=false)
Extract the value profile data from Inst which is annotated with value profile meta data.
Definition: InstrProf.cpp:999
LLVMContext.h
llvm::cl::desc
Definition: CommandLine.h:411
llvm::GlobalValue::ExternalWeakLinkage
@ ExternalWeakLinkage
ExternalWeak linkage description.
Definition: GlobalValue.h:57
llvm::StringRef::size
LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:160
error_category
static ManagedStatic< _object_error_category > error_category
Definition: Error.cpp:76
Endian.h
llvm::MDString
A single uniqued string.
Definition: Metadata.h:611
llvm::GlobalValue::LinkOnceODRLinkage
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
Definition: GlobalValue.h:51
llvm::InstrProfReader::create
static Expected< std::unique_ptr< InstrProfReader > > create(const Twine &Path)
Factory method to create an appropriately typed reader for the given instrprof file.
Definition: InstrProfReader.cpp:55
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
llvm::OverlapStats::addOneMismatch
void addOneMismatch(const CountSumOrPercent &MismatchFunc)
Definition: InstrProf.cpp:1201
llvm::InstrProfRecord::Counts
std::vector< uint64_t > Counts
Definition: InstrProf.h:692
llvm::ArrayRef::end
iterator end() const
Definition: ArrayRef.h:152
llvm::instrprof_error::counter_overflow
@ counter_overflow
llvm::OverlapStats::Test
CountSumOrPercent Test
Definition: InstrProf.h:616
Other
Optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1163
llvm::getPGOFuncNameMetadata
MDNode * getPGOFuncNameMetadata(const Function &F)
Return the PGOFuncName meta data associated with a function.
Definition: InstrProf.cpp:1055
llvm::StringRef::bytes_end
const unsigned char * bytes_end() const
Definition: StringRef.h:138
llvm::InstrProfRecord::scale
void scale(uint64_t N, uint64_t D, function_ref< void(instrprof_error)> Warn)
Scale up profile counts (including value profile data) by a factor of (N / D).
Definition: InstrProf.cpp:705