LLVM  14.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 "
121  "without zlib support";
122  }
123  llvm_unreachable("A value of instrprof_error has no message.");
124 }
125 
126 namespace {
127 
128 // FIXME: This class is only here to support the transition to llvm::Error. It
129 // will be removed once this transition is complete. Clients should prefer to
130 // deal with the Error value directly, rather than converting to error_code.
131 class InstrProfErrorCategoryType : public std::error_category {
132  const char *name() const noexcept override { return "llvm.instrprof"; }
133 
134  std::string message(int IE) const override {
135  return getInstrProfErrString(static_cast<instrprof_error>(IE));
136  }
137 };
138 
139 } // end anonymous namespace
140 
142 
144  return *ErrorCategory;
145 }
146 
147 namespace {
148 
149 const char *InstrProfSectNameCommon[] = {
150 #define INSTR_PROF_SECT_ENTRY(Kind, SectNameCommon, SectNameCoff, Prefix) \
151  SectNameCommon,
153 };
154 
155 const char *InstrProfSectNameCoff[] = {
156 #define INSTR_PROF_SECT_ENTRY(Kind, SectNameCommon, SectNameCoff, Prefix) \
157  SectNameCoff,
159 };
160 
161 const char *InstrProfSectNamePrefix[] = {
162 #define INSTR_PROF_SECT_ENTRY(Kind, SectNameCommon, SectNameCoff, Prefix) \
163  Prefix,
165 };
166 
167 } // namespace
168 
169 namespace llvm {
170 
172  "enable-name-compression",
173  cl::desc("Enable name/filename string compression"), cl::init(true));
174 
177  bool AddSegmentInfo) {
178  std::string SectName;
179 
180  if (OF == Triple::MachO && AddSegmentInfo)
181  SectName = InstrProfSectNamePrefix[IPSK];
182 
183  if (OF == Triple::COFF)
184  SectName += InstrProfSectNameCoff[IPSK];
185  else
186  SectName += InstrProfSectNameCommon[IPSK];
187 
188  if (OF == Triple::MachO && IPSK == IPSK_data && AddSegmentInfo)
189  SectName += ",regular,live_support";
190 
191  return SectName;
192 }
193 
196  return;
197 
198  if (FirstError == instrprof_error::success)
199  FirstError = IE;
200 
201  switch (IE) {
203  ++NumHashMismatches;
204  break;
206  ++NumCountMismatches;
207  break;
209  ++NumCounterOverflows;
210  break;
212  ++NumValueSiteCountMismatches;
213  break;
214  default:
215  llvm_unreachable("Not a soft error");
216  }
217 }
218 
219 std::string InstrProfError::message() const {
220  return getInstrProfErrString(Err);
221 }
222 
223 char InstrProfError::ID = 0;
224 
225 std::string getPGOFuncName(StringRef RawFuncName,
227  StringRef FileName,
229  return GlobalValue::getGlobalIdentifier(RawFuncName, Linkage, FileName);
230 }
231 
232 // Strip NumPrefix level of directory name from PathNameStr. If the number of
233 // directory separators is less than NumPrefix, strip all the directories and
234 // leave base file name only.
235 static StringRef stripDirPrefix(StringRef PathNameStr, uint32_t NumPrefix) {
236  uint32_t Count = NumPrefix;
237  uint32_t Pos = 0, LastPos = 0;
238  for (auto & CI : PathNameStr) {
239  ++Pos;
241  LastPos = Pos;
242  --Count;
243  }
244  if (Count == 0)
245  break;
246  }
247  return PathNameStr.substr(LastPos);
248 }
249 
250 // Return the PGOFuncName. This function has some special handling when called
251 // in LTO optimization. The following only applies when calling in LTO passes
252 // (when \c InLTO is true): LTO's internalization privatizes many global linkage
253 // symbols. This happens after value profile annotation, but those internal
254 // linkage functions should not have a source prefix.
255 // Additionally, for ThinLTO mode, exported internal functions are promoted
256 // and renamed. We need to ensure that the original internal PGO name is
257 // used when computing the GUID that is compared against the profiled GUIDs.
258 // To differentiate compiler generated internal symbols from original ones,
259 // PGOFuncName meta data are created and attached to the original internal
260 // symbols in the value profile annotation step
261 // (PGOUseFunc::annotateIndirectCallSites). If a symbol does not have the meta
262 // data, its original linkage must be non-internal.
263 std::string getPGOFuncName(const Function &F, bool InLTO, uint64_t Version) {
264  if (!InLTO) {
265  StringRef FileName(F.getParent()->getSourceFileName());
266  uint32_t StripLevel = StaticFuncFullModulePrefix ? 0 : (uint32_t)-1;
267  if (StripLevel < StaticFuncStripDirNamePrefix)
268  StripLevel = StaticFuncStripDirNamePrefix;
269  if (StripLevel)
270  FileName = stripDirPrefix(FileName, StripLevel);
271  return getPGOFuncName(F.getName(), F.getLinkage(), FileName, Version);
272  }
273 
274  // In LTO mode (when InLTO is true), first check if there is a meta data.
275  if (MDNode *MD = getPGOFuncNameMetadata(F)) {
276  StringRef S = cast<MDString>(MD->getOperand(0))->getString();
277  return S.str();
278  }
279 
280  // If there is no meta data, the function must be a global before the value
281  // profile annotation pass. Its current linkage may be internal if it is
282  // internalized in LTO mode.
283  return getPGOFuncName(F.getName(), GlobalValue::ExternalLinkage, "");
284 }
285 
287  if (FileName.empty())
288  return PGOFuncName;
289  // Drop the file name including ':'. See also getPGOFuncName.
290  if (PGOFuncName.startswith(FileName))
291  PGOFuncName = PGOFuncName.drop_front(FileName.size() + 1);
292  return PGOFuncName;
293 }
294 
295 // \p FuncName is the string used as profile lookup key for the function. A
296 // symbol is created to hold the name. Return the legalized symbol name.
297 std::string getPGOFuncNameVarName(StringRef FuncName,
299  std::string VarName = std::string(getInstrProfNameVarPrefix());
300  VarName += FuncName;
301 
303  return VarName;
304 
305  // Now fix up illegal chars in local VarName that may upset the assembler.
306  const char *InvalidChars = "-:<>/\"'";
307  size_t found = VarName.find_first_of(InvalidChars);
308  while (found != std::string::npos) {
309  VarName[found] = '_';
310  found = VarName.find_first_of(InvalidChars, found + 1);
311  }
312  return VarName;
313 }
314 
317  StringRef PGOFuncName) {
318  // We generally want to match the function's linkage, but available_externally
319  // and extern_weak both have the wrong semantics, and anything that doesn't
320  // need to link across compilation units doesn't need to be visible at all.
328 
329  auto *Value =
330  ConstantDataArray::getString(M.getContext(), PGOFuncName, false);
331  auto FuncNameVar =
332  new GlobalVariable(M, Value->getType(), true, Linkage, Value,
333  getPGOFuncNameVarName(PGOFuncName, Linkage));
334 
335  // Hide the symbol so that we correctly get a copy for each executable.
336  if (!GlobalValue::isLocalLinkage(FuncNameVar->getLinkage()))
337  FuncNameVar->setVisibility(GlobalValue::HiddenVisibility);
338 
339  return FuncNameVar;
340 }
341 
343  return createPGOFuncNameVar(*F.getParent(), F.getLinkage(), PGOFuncName);
344 }
345 
347  for (Function &F : M) {
348  // Function may not have a name: like using asm("") to overwrite the name.
349  // Ignore in this case.
350  if (!F.hasName())
351  continue;
352  const std::string &PGOFuncName = getPGOFuncName(F, InLTO);
353  if (Error E = addFuncName(PGOFuncName))
354  return E;
355  MD5FuncMap.emplace_back(Function::getGUID(PGOFuncName), &F);
356  // In ThinLTO, local function may have been promoted to global and have
357  // suffix ".llvm." added to the function name. We need to add the
358  // stripped function name to the symbol table so that we can find a match
359  // from profile.
360  //
361  // We may have other suffixes similar as ".llvm." which are needed to
362  // be stripped before the matching, but ".__uniq." suffix which is used
363  // to differentiate internal linkage functions in different modules
364  // should be kept. Now this is the only suffix with the pattern ".xxx"
365  // which is kept before matching.
366  const std::string UniqSuffix = ".__uniq.";
367  auto pos = PGOFuncName.find(UniqSuffix);
368  // Search '.' after ".__uniq." if ".__uniq." exists, otherwise
369  // search '.' from the beginning.
370  if (pos != std::string::npos)
371  pos += UniqSuffix.length();
372  else
373  pos = 0;
374  pos = PGOFuncName.find('.', pos);
375  if (pos != std::string::npos && pos != 0) {
376  const std::string &OtherFuncName = PGOFuncName.substr(0, pos);
377  if (Error E = addFuncName(OtherFuncName))
378  return E;
379  MD5FuncMap.emplace_back(Function::getGUID(OtherFuncName), &F);
380  }
381  }
382  Sorted = false;
383  finalizeSymtab();
384  return Error::success();
385 }
386 
388  finalizeSymtab();
389  auto It = partition_point(AddrToMD5Map, [=](std::pair<uint64_t, uint64_t> A) {
390  return A.first < Address;
391  });
392  // Raw function pointer collected by value profiler may be from
393  // external functions that are not instrumented. They won't have
394  // mapping data to be used by the deserializer. Force the value to
395  // be 0 in this case.
396  if (It != AddrToMD5Map.end() && It->first == Address)
397  return (uint64_t)It->second;
398  return 0;
399 }
400 
402  bool doCompression, std::string &Result) {
403  assert(!NameStrs.empty() && "No name data to emit");
404 
405  uint8_t Header[16], *P = Header;
406  std::string UncompressedNameStrings =
407  join(NameStrs.begin(), NameStrs.end(), getInstrProfNameSeparator());
408 
409  assert(StringRef(UncompressedNameStrings)
410  .count(getInstrProfNameSeparator()) == (NameStrs.size() - 1) &&
411  "PGO name is invalid (contains separator token)");
412 
413  unsigned EncLen = encodeULEB128(UncompressedNameStrings.length(), P);
414  P += EncLen;
415 
416  auto WriteStringToResult = [&](size_t CompressedLen, StringRef InputStr) {
417  EncLen = encodeULEB128(CompressedLen, P);
418  P += EncLen;
419  char *HeaderStr = reinterpret_cast<char *>(&Header[0]);
420  unsigned HeaderLen = P - &Header[0];
421  Result.append(HeaderStr, HeaderLen);
422  Result += InputStr;
423  return Error::success();
424  };
425 
426  if (!doCompression) {
427  return WriteStringToResult(0, UncompressedNameStrings);
428  }
429 
430  SmallString<128> CompressedNameStrings;
431  Error E = zlib::compress(StringRef(UncompressedNameStrings),
432  CompressedNameStrings, zlib::BestSizeCompression);
433  if (E) {
435  return make_error<InstrProfError>(instrprof_error::compress_failed);
436  }
437 
438  return WriteStringToResult(CompressedNameStrings.size(),
439  CompressedNameStrings);
440 }
441 
443  auto *Arr = cast<ConstantDataArray>(NameVar->getInitializer());
444  StringRef NameStr =
445  Arr->isCString() ? Arr->getAsCString() : Arr->getAsString();
446  return NameStr;
447 }
448 
450  std::string &Result, bool doCompression) {
451  std::vector<std::string> NameStrs;
452  for (auto *NameVar : NameVars) {
453  NameStrs.push_back(std::string(getPGOFuncNameVarInitializer(NameVar)));
454  }
456  NameStrs, zlib::isAvailable() && doCompression, Result);
457 }
458 
460  const uint8_t *P = NameStrings.bytes_begin();
461  const uint8_t *EndP = NameStrings.bytes_end();
462  while (P < EndP) {
463  uint32_t N;
464  uint64_t UncompressedSize = decodeULEB128(P, &N);
465  P += N;
466  uint64_t CompressedSize = decodeULEB128(P, &N);
467  P += N;
468  bool isCompressed = (CompressedSize != 0);
469  SmallString<128> UncompressedNameStrings;
470  StringRef NameStrings;
471  if (isCompressed) {
473  return make_error<InstrProfError>(instrprof_error::zlib_unavailable);
474 
475  StringRef CompressedNameStrings(reinterpret_cast<const char *>(P),
476  CompressedSize);
477  if (Error E =
478  zlib::uncompress(CompressedNameStrings, UncompressedNameStrings,
479  UncompressedSize)) {
481  return make_error<InstrProfError>(instrprof_error::uncompress_failed);
482  }
483  P += CompressedSize;
484  NameStrings = StringRef(UncompressedNameStrings.data(),
485  UncompressedNameStrings.size());
486  } else {
487  NameStrings =
488  StringRef(reinterpret_cast<const char *>(P), UncompressedSize);
489  P += UncompressedSize;
490  }
491  // Now parse the name strings.
493  NameStrings.split(Names, getInstrProfNameSeparator());
494  for (StringRef &Name : Names)
495  if (Error E = Symtab.addFuncName(Name))
496  return E;
497 
498  while (P < EndP && *P == 0)
499  P++;
500  }
501  return Error::success();
502 }
503 
505  uint64_t FuncSum = 0;
506  Sum.NumEntries += Counts.size();
507  for (size_t F = 0, E = Counts.size(); F < E; ++F)
508  FuncSum += Counts[F];
509  Sum.CountSum += FuncSum;
510 
511  for (uint32_t VK = IPVK_First; VK <= IPVK_Last; ++VK) {
512  uint64_t KindSum = 0;
513  uint32_t NumValueSites = getNumValueSites(VK);
514  for (size_t I = 0; I < NumValueSites; ++I) {
516  std::unique_ptr<InstrProfValueData[]> VD = getValueForSite(VK, I);
517  for (uint32_t V = 0; V < NV; V++)
518  KindSum += VD[V].Count;
519  }
520  Sum.ValueCounts[VK] += KindSum;
521  }
522 }
523 
526  OverlapStats &Overlap,
527  OverlapStats &FuncLevelOverlap) {
528  this->sortByTargetValues();
529  Input.sortByTargetValues();
530  double Score = 0.0f, FuncLevelScore = 0.0f;
531  auto I = ValueData.begin();
532  auto IE = ValueData.end();
533  auto J = Input.ValueData.begin();
534  auto JE = Input.ValueData.end();
535  while (I != IE && J != JE) {
536  if (I->Value == J->Value) {
537  Score += OverlapStats::score(I->Count, J->Count,
538  Overlap.Base.ValueCounts[ValueKind],
539  Overlap.Test.ValueCounts[ValueKind]);
540  FuncLevelScore += OverlapStats::score(
541  I->Count, J->Count, FuncLevelOverlap.Base.ValueCounts[ValueKind],
542  FuncLevelOverlap.Test.ValueCounts[ValueKind]);
543  ++I;
544  } else if (I->Value < J->Value) {
545  ++I;
546  continue;
547  }
548  ++J;
549  }
550  Overlap.Overlap.ValueCounts[ValueKind] += Score;
551  FuncLevelOverlap.Overlap.ValueCounts[ValueKind] += FuncLevelScore;
552 }
553 
554 // Return false on mismatch.
556  InstrProfRecord &Other,
557  OverlapStats &Overlap,
558  OverlapStats &FuncLevelOverlap) {
559  uint32_t ThisNumValueSites = getNumValueSites(ValueKind);
560  assert(ThisNumValueSites == Other.getNumValueSites(ValueKind));
561  if (!ThisNumValueSites)
562  return;
563 
564  std::vector<InstrProfValueSiteRecord> &ThisSiteRecords =
565  getOrCreateValueSitesForKind(ValueKind);
567  Other.getValueSitesForKind(ValueKind);
568  for (uint32_t I = 0; I < ThisNumValueSites; I++)
569  ThisSiteRecords[I].overlap(OtherSiteRecords[I], ValueKind, Overlap,
570  FuncLevelOverlap);
571 }
572 
574  OverlapStats &FuncLevelOverlap,
575  uint64_t ValueCutoff) {
576  // FuncLevel CountSum for other should already computed and nonzero.
577  assert(FuncLevelOverlap.Test.CountSum >= 1.0f);
578  accumulateCounts(FuncLevelOverlap.Base);
579  bool Mismatch = (Counts.size() != Other.Counts.size());
580 
581  // Check if the value profiles mismatch.
582  if (!Mismatch) {
583  for (uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind) {
584  uint32_t ThisNumValueSites = getNumValueSites(Kind);
585  uint32_t OtherNumValueSites = Other.getNumValueSites(Kind);
586  if (ThisNumValueSites != OtherNumValueSites) {
587  Mismatch = true;
588  break;
589  }
590  }
591  }
592  if (Mismatch) {
593  Overlap.addOneMismatch(FuncLevelOverlap.Test);
594  return;
595  }
596 
597  // Compute overlap for value counts.
598  for (uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind)
599  overlapValueProfData(Kind, Other, Overlap, FuncLevelOverlap);
600 
601  double Score = 0.0;
602  uint64_t MaxCount = 0;
603  // Compute overlap for edge counts.
604  for (size_t I = 0, E = Other.Counts.size(); I < E; ++I) {
605  Score += OverlapStats::score(Counts[I], Other.Counts[I],
606  Overlap.Base.CountSum, Overlap.Test.CountSum);
607  MaxCount = std::max(Other.Counts[I], MaxCount);
608  }
609  Overlap.Overlap.CountSum += Score;
610  Overlap.Overlap.NumEntries += 1;
611 
612  if (MaxCount >= ValueCutoff) {
613  double FuncScore = 0.0;
614  for (size_t I = 0, E = Other.Counts.size(); I < E; ++I)
615  FuncScore += OverlapStats::score(Counts[I], Other.Counts[I],
616  FuncLevelOverlap.Base.CountSum,
617  FuncLevelOverlap.Test.CountSum);
618  FuncLevelOverlap.Overlap.CountSum = FuncScore;
619  FuncLevelOverlap.Overlap.NumEntries = Other.Counts.size();
620  FuncLevelOverlap.Valid = true;
621  }
622 }
623 
625  uint64_t Weight,
626  function_ref<void(instrprof_error)> Warn) {
627  this->sortByTargetValues();
628  Input.sortByTargetValues();
629  auto I = ValueData.begin();
630  auto IE = ValueData.end();
631  for (auto J = Input.ValueData.begin(), JE = Input.ValueData.end(); J != JE;
632  ++J) {
633  while (I != IE && I->Value < J->Value)
634  ++I;
635  if (I != IE && I->Value == J->Value) {
636  bool Overflowed;
637  I->Count = SaturatingMultiplyAdd(J->Count, Weight, I->Count, &Overflowed);
638  if (Overflowed)
640  ++I;
641  continue;
642  }
643  ValueData.insert(I, *J);
644  }
645 }
646 
648  function_ref<void(instrprof_error)> Warn) {
649  for (auto I = ValueData.begin(), IE = ValueData.end(); I != IE; ++I) {
650  bool Overflowed;
651  I->Count = SaturatingMultiply(I->Count, N, &Overflowed) / D;
652  if (Overflowed)
654  }
655 }
656 
657 // Merge Value Profile data from Src record to this record for ValueKind.
658 // Scale merged value counts by \p Weight.
659 void InstrProfRecord::mergeValueProfData(
661  function_ref<void(instrprof_error)> Warn) {
662  uint32_t ThisNumValueSites = getNumValueSites(ValueKind);
663  uint32_t OtherNumValueSites = Src.getNumValueSites(ValueKind);
664  if (ThisNumValueSites != OtherNumValueSites) {
666  return;
667  }
668  if (!ThisNumValueSites)
669  return;
670  std::vector<InstrProfValueSiteRecord> &ThisSiteRecords =
671  getOrCreateValueSitesForKind(ValueKind);
673  Src.getValueSitesForKind(ValueKind);
674  for (uint32_t I = 0; I < ThisNumValueSites; I++)
675  ThisSiteRecords[I].merge(OtherSiteRecords[I], Weight, Warn);
676 }
677 
679  function_ref<void(instrprof_error)> Warn) {
680  // If the number of counters doesn't match we either have bad data
681  // or a hash collision.
682  if (Counts.size() != Other.Counts.size()) {
684  return;
685  }
686 
687  for (size_t I = 0, E = Other.Counts.size(); I < E; ++I) {
688  bool Overflowed;
689  Counts[I] =
690  SaturatingMultiplyAdd(Other.Counts[I], Weight, Counts[I], &Overflowed);
691  if (Overflowed)
693  }
694 
695  for (uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind)
696  mergeValueProfData(Kind, Other, Weight, Warn);
697 }
698 
699 void InstrProfRecord::scaleValueProfData(
701  function_ref<void(instrprof_error)> Warn) {
702  for (auto &R : getValueSitesForKind(ValueKind))
703  R.scale(N, D, Warn);
704 }
705 
707  function_ref<void(instrprof_error)> Warn) {
708  assert(D != 0 && "D cannot be 0");
709  for (auto &Count : this->Counts) {
710  bool Overflowed;
711  Count = SaturatingMultiply(Count, N, &Overflowed) / D;
712  if (Overflowed)
714  }
715  for (uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind)
716  scaleValueProfData(Kind, N, D, Warn);
717 }
718 
719 // Map indirect call target name hash to name string.
720 uint64_t InstrProfRecord::remapValue(uint64_t Value, uint32_t ValueKind,
721  InstrProfSymtab *SymTab) {
722  if (!SymTab)
723  return Value;
724 
725  if (ValueKind == IPVK_IndirectCallTarget)
726  return SymTab->getFunctionHashFromAddress(Value);
727 
728  return Value;
729 }
730 
732  InstrProfValueData *VData, uint32_t N,
734  for (uint32_t I = 0; I < N; I++) {
735  VData[I].Value = remapValue(VData[I].Value, ValueKind, ValueMap);
736  }
737  std::vector<InstrProfValueSiteRecord> &ValueSites =
738  getOrCreateValueSitesForKind(ValueKind);
739  if (N == 0)
740  ValueSites.emplace_back();
741  else
742  ValueSites.emplace_back(VData, VData + N);
743 }
744 
745 #define INSTR_PROF_COMMON_API_IMPL
747 
748 /*!
749  * ValueProfRecordClosure Interface implementation for InstrProfRecord
750  * class. These C wrappers are used as adaptors so that C++ code can be
751  * invoked as callbacks.
752  */
754  return reinterpret_cast<const InstrProfRecord *>(Record)->getNumValueKinds();
755 }
756 
758  return reinterpret_cast<const InstrProfRecord *>(Record)
759  ->getNumValueSites(VKind);
760 }
761 
763  return reinterpret_cast<const InstrProfRecord *>(Record)
764  ->getNumValueData(VKind);
765 }
766 
768  uint32_t S) {
769  return reinterpret_cast<const InstrProfRecord *>(R)
770  ->getNumValueDataForSite(VK, S);
771 }
772 
773 void getValueForSiteInstrProf(const void *R, InstrProfValueData *Dst,
774  uint32_t K, uint32_t S) {
775  reinterpret_cast<const InstrProfRecord *>(R)->getValueForSite(Dst, K, S);
776 }
777 
778 ValueProfData *allocValueProfDataInstrProf(size_t TotalSizeInBytes) {
779  ValueProfData *VD =
780  (ValueProfData *)(new (::operator new(TotalSizeInBytes)) ValueProfData());
781  memset(VD, 0, TotalSizeInBytes);
782  return VD;
783 }
784 
785 static ValueProfRecordClosure InstrProfRecordClosure = {
786  nullptr,
791  nullptr,
794 
795 // Wrapper implementation using the closure mechanism.
796 uint32_t ValueProfData::getSize(const InstrProfRecord &Record) {
797  auto Closure = InstrProfRecordClosure;
798  Closure.Record = &Record;
799  return getValueProfDataSize(&Closure);
800 }
801 
802 // Wrapper implementation using the closure mechanism.
803 std::unique_ptr<ValueProfData>
804 ValueProfData::serializeFrom(const InstrProfRecord &Record) {
805  InstrProfRecordClosure.Record = &Record;
806 
807  std::unique_ptr<ValueProfData> VPD(
808  serializeValueProfDataFrom(&InstrProfRecordClosure, nullptr));
809  return VPD;
810 }
811 
812 void ValueProfRecord::deserializeTo(InstrProfRecord &Record,
813  InstrProfSymtab *SymTab) {
814  Record.reserveSites(Kind, NumValueSites);
815 
816  InstrProfValueData *ValueData = getValueProfRecordValueData(this);
817  for (uint64_t VSite = 0; VSite < NumValueSites; ++VSite) {
818  uint8_t ValueDataCount = this->SiteCountArray[VSite];
819  Record.addValueData(Kind, VSite, ValueData, ValueDataCount, SymTab);
820  ValueData += ValueDataCount;
821  }
822 }
823 
824 // For writing/serializing, Old is the host endianness, and New is
825 // byte order intended on disk. For Reading/deserialization, Old
826 // is the on-disk source endianness, and New is the host endianness.
827 void ValueProfRecord::swapBytes(support::endianness Old,
828  support::endianness New) {
829  using namespace support;
830 
831  if (Old == New)
832  return;
833 
834  if (getHostEndianness() != Old) {
835  sys::swapByteOrder<uint32_t>(NumValueSites);
836  sys::swapByteOrder<uint32_t>(Kind);
837  }
838  uint32_t ND = getValueProfRecordNumValueData(this);
839  InstrProfValueData *VD = getValueProfRecordValueData(this);
840 
841  // No need to swap byte array: SiteCountArrray.
842  for (uint32_t I = 0; I < ND; I++) {
843  sys::swapByteOrder<uint64_t>(VD[I].Value);
844  sys::swapByteOrder<uint64_t>(VD[I].Count);
845  }
846  if (getHostEndianness() == Old) {
847  sys::swapByteOrder<uint32_t>(NumValueSites);
848  sys::swapByteOrder<uint32_t>(Kind);
849  }
850 }
851 
852 void ValueProfData::deserializeTo(InstrProfRecord &Record,
853  InstrProfSymtab *SymTab) {
854  if (NumValueKinds == 0)
855  return;
856 
857  ValueProfRecord *VR = getFirstValueProfRecord(this);
858  for (uint32_t K = 0; K < NumValueKinds; K++) {
859  VR->deserializeTo(Record, SymTab);
860  VR = getValueProfRecordNext(VR);
861  }
862 }
863 
864 template <class T>
865 static T swapToHostOrder(const unsigned char *&D, support::endianness Orig) {
866  using namespace support;
867 
868  if (Orig == little)
869  return endian::readNext<T, little, unaligned>(D);
870  else
871  return endian::readNext<T, big, unaligned>(D);
872 }
873 
874 static std::unique_ptr<ValueProfData> allocValueProfData(uint32_t TotalSize) {
875  return std::unique_ptr<ValueProfData>(new (::operator new(TotalSize))
876  ValueProfData());
877 }
878 
879 Error ValueProfData::checkIntegrity() {
880  if (NumValueKinds > IPVK_Last + 1)
881  return make_error<InstrProfError>(instrprof_error::malformed);
882  // Total size needs to be mulltiple of quadword size.
883  if (TotalSize % sizeof(uint64_t))
884  return make_error<InstrProfError>(instrprof_error::malformed);
885 
886  ValueProfRecord *VR = getFirstValueProfRecord(this);
887  for (uint32_t K = 0; K < this->NumValueKinds; K++) {
888  if (VR->Kind > IPVK_Last)
889  return make_error<InstrProfError>(instrprof_error::malformed);
890  VR = getValueProfRecordNext(VR);
891  if ((char *)VR - (char *)this > (ptrdiff_t)TotalSize)
892  return make_error<InstrProfError>(instrprof_error::malformed);
893  }
894  return Error::success();
895 }
896 
898 ValueProfData::getValueProfData(const unsigned char *D,
899  const unsigned char *const BufferEnd,
901  using namespace support;
902 
903  if (D + sizeof(ValueProfData) > BufferEnd)
904  return make_error<InstrProfError>(instrprof_error::truncated);
905 
906  const unsigned char *Header = D;
907  uint32_t TotalSize = swapToHostOrder<uint32_t>(Header, Endianness);
908  if (D + TotalSize > BufferEnd)
909  return make_error<InstrProfError>(instrprof_error::too_large);
910 
911  std::unique_ptr<ValueProfData> VPD = allocValueProfData(TotalSize);
912  memcpy(VPD.get(), D, TotalSize);
913  // Byte swap.
914  VPD->swapBytesToHost(Endianness);
915 
916  Error E = VPD->checkIntegrity();
917  if (E)
918  return std::move(E);
919 
920  return std::move(VPD);
921 }
922 
923 void ValueProfData::swapBytesToHost(support::endianness Endianness) {
924  using namespace support;
925 
926  if (Endianness == getHostEndianness())
927  return;
928 
929  sys::swapByteOrder<uint32_t>(TotalSize);
930  sys::swapByteOrder<uint32_t>(NumValueKinds);
931 
932  ValueProfRecord *VR = getFirstValueProfRecord(this);
933  for (uint32_t K = 0; K < NumValueKinds; K++) {
934  VR->swapBytes(Endianness, getHostEndianness());
935  VR = getValueProfRecordNext(VR);
936  }
937 }
938 
939 void ValueProfData::swapBytesFromHost(support::endianness Endianness) {
940  using namespace support;
941 
942  if (Endianness == getHostEndianness())
943  return;
944 
945  ValueProfRecord *VR = getFirstValueProfRecord(this);
946  for (uint32_t K = 0; K < NumValueKinds; K++) {
947  ValueProfRecord *NVR = getValueProfRecordNext(VR);
948  VR->swapBytes(getHostEndianness(), Endianness);
949  VR = NVR;
950  }
951  sys::swapByteOrder<uint32_t>(TotalSize);
952  sys::swapByteOrder<uint32_t>(NumValueKinds);
953 }
954 
956  const InstrProfRecord &InstrProfR,
958  uint32_t MaxMDCount) {
959  uint32_t NV = InstrProfR.getNumValueDataForSite(ValueKind, SiteIdx);
960  if (!NV)
961  return;
962 
963  uint64_t Sum = 0;
964  std::unique_ptr<InstrProfValueData[]> VD =
965  InstrProfR.getValueForSite(ValueKind, SiteIdx, &Sum);
966 
967  ArrayRef<InstrProfValueData> VDs(VD.get(), NV);
968  annotateValueSite(M, Inst, VDs, Sum, ValueKind, MaxMDCount);
969 }
970 
974  uint32_t MaxMDCount) {
975  LLVMContext &Ctx = M.getContext();
976  MDBuilder MDHelper(Ctx);
978  // Tag
979  Vals.push_back(MDHelper.createString("VP"));
980  // Value Kind
981  Vals.push_back(MDHelper.createConstant(
983  // Total Count
984  Vals.push_back(
985  MDHelper.createConstant(ConstantInt::get(Type::getInt64Ty(Ctx), Sum)));
986 
987  // Value Profile Data
988  uint32_t MDCount = MaxMDCount;
989  for (auto &VD : VDs) {
990  Vals.push_back(MDHelper.createConstant(
991  ConstantInt::get(Type::getInt64Ty(Ctx), VD.Value)));
992  Vals.push_back(MDHelper.createConstant(
993  ConstantInt::get(Type::getInt64Ty(Ctx), VD.Count)));
994  if (--MDCount == 0)
995  break;
996  }
997  Inst.setMetadata(LLVMContext::MD_prof, MDNode::get(Ctx, Vals));
998 }
999 
1002  uint32_t MaxNumValueData,
1003  InstrProfValueData ValueData[],
1004  uint32_t &ActualNumValueData, uint64_t &TotalC,
1005  bool GetNoICPValue) {
1006  MDNode *MD = Inst.getMetadata(LLVMContext::MD_prof);
1007  if (!MD)
1008  return false;
1009 
1010  unsigned NOps = MD->getNumOperands();
1011 
1012  if (NOps < 5)
1013  return false;
1014 
1015  // Operand 0 is a string tag "VP":
1016  MDString *Tag = cast<MDString>(MD->getOperand(0));
1017  if (!Tag)
1018  return false;
1019 
1020  if (!Tag->getString().equals("VP"))
1021  return false;
1022 
1023  // Now check kind:
1024  ConstantInt *KindInt = mdconst::dyn_extract<ConstantInt>(MD->getOperand(1));
1025  if (!KindInt)
1026  return false;
1027  if (KindInt->getZExtValue() != ValueKind)
1028  return false;
1029 
1030  // Get total count
1031  ConstantInt *TotalCInt = mdconst::dyn_extract<ConstantInt>(MD->getOperand(2));
1032  if (!TotalCInt)
1033  return false;
1034  TotalC = TotalCInt->getZExtValue();
1035 
1036  ActualNumValueData = 0;
1037 
1038  for (unsigned I = 3; I < NOps; I += 2) {
1039  if (ActualNumValueData >= MaxNumValueData)
1040  break;
1041  ConstantInt *Value = mdconst::dyn_extract<ConstantInt>(MD->getOperand(I));
1042  ConstantInt *Count =
1043  mdconst::dyn_extract<ConstantInt>(MD->getOperand(I + 1));
1044  if (!Value || !Count)
1045  return false;
1046  uint64_t CntValue = Count->getZExtValue();
1047  if (!GetNoICPValue && (CntValue == NOMORE_ICP_MAGICNUM))
1048  continue;
1049  ValueData[ActualNumValueData].Value = Value->getZExtValue();
1050  ValueData[ActualNumValueData].Count = CntValue;
1051  ActualNumValueData++;
1052  }
1053  return true;
1054 }
1055 
1057  return F.getMetadata(getPGOFuncNameMetadataName());
1058 }
1059 
1061  // Only for internal linkage functions.
1062  if (PGOFuncName == F.getName())
1063  return;
1064  // Don't create duplicated meta-data.
1066  return;
1067  LLVMContext &C = F.getContext();
1068  MDNode *N = MDNode::get(C, MDString::get(C, PGOFuncName));
1069  F.setMetadata(getPGOFuncNameMetadataName(), N);
1070 }
1071 
1072 bool needsComdatForCounter(const Function &F, const Module &M) {
1073  if (F.hasComdat())
1074  return true;
1075 
1076  if (!Triple(M.getTargetTriple()).supportsCOMDAT())
1077  return false;
1078 
1079  // See createPGOFuncNameVar for more details. To avoid link errors, profile
1080  // counters for function with available_externally linkage needs to be changed
1081  // to linkonce linkage. On ELF based systems, this leads to weak symbols to be
1082  // created. Without using comdat, duplicate entries won't be removed by the
1083  // linker leading to increased data segement size and raw profile size. Even
1084  // worse, since the referenced counter from profile per-function data object
1085  // will be resolved to the common strong definition, the profile counts for
1086  // available_externally functions will end up being duplicated in raw profile
1087  // data. This can result in distorted profile as the counts of those dups
1088  // will be accumulated by the profile merger.
1089  GlobalValue::LinkageTypes Linkage = F.getLinkage();
1092  return false;
1093 
1094  return true;
1095 }
1096 
1097 // Check if INSTR_PROF_RAW_VERSION_VAR is defined.
1098 bool isIRPGOFlagSet(const Module *M) {
1099  auto IRInstrVar =
1100  M->getNamedGlobal(INSTR_PROF_QUOTE(INSTR_PROF_RAW_VERSION_VAR));
1101  if (!IRInstrVar || IRInstrVar->hasLocalLinkage())
1102  return false;
1103 
1104  // For CSPGO+LTO, this variable might be marked as non-prevailing and we only
1105  // have the decl.
1106  if (IRInstrVar->isDeclaration())
1107  return true;
1108 
1109  // Check if the flag is set.
1110  if (!IRInstrVar->hasInitializer())
1111  return false;
1112 
1113  auto *InitVal = dyn_cast_or_null<ConstantInt>(IRInstrVar->getInitializer());
1114  if (!InitVal)
1115  return false;
1116  return (InitVal->getZExtValue() & VARIANT_MASK_IR_PROF) != 0;
1117 }
1118 
1119 // Check if we can safely rename this Comdat function.
1120 bool canRenameComdatFunc(const Function &F, bool CheckAddressTaken) {
1121  if (F.getName().empty())
1122  return false;
1123  if (!needsComdatForCounter(F, *(F.getParent())))
1124  return false;
1125  // Unsafe to rename the address-taken function (which can be used in
1126  // function comparison).
1127  if (CheckAddressTaken && F.hasAddressTaken())
1128  return false;
1129  // Only safe to do if this function may be discarded if it is not used
1130  // in the compilation unit.
1131  if (!GlobalValue::isDiscardableIfUnused(F.getLinkage()))
1132  return false;
1133 
1134  // For AvailableExternallyLinkage functions.
1135  if (!F.hasComdat()) {
1137  return true;
1138  }
1139  return true;
1140 }
1141 
1142 // Create a COMDAT variable INSTR_PROF_RAW_VERSION_VAR to make the runtime
1143 // aware this is an ir_level profile so it can set the version flag.
1145  bool InstrEntryBBEnabled) {
1146  const StringRef VarName(INSTR_PROF_QUOTE(INSTR_PROF_RAW_VERSION_VAR));
1147  Type *IntTy64 = Type::getInt64Ty(M.getContext());
1148  uint64_t ProfileVersion = (INSTR_PROF_RAW_VERSION | VARIANT_MASK_IR_PROF);
1149  if (IsCS)
1150  ProfileVersion |= VARIANT_MASK_CSIR_PROF;
1151  if (InstrEntryBBEnabled)
1152  ProfileVersion |= VARIANT_MASK_INSTR_ENTRY;
1153  auto IRLevelVersionVariable = new GlobalVariable(
1154  M, IntTy64, true, GlobalValue::WeakAnyLinkage,
1155  Constant::getIntegerValue(IntTy64, APInt(64, ProfileVersion)), VarName);
1156  IRLevelVersionVariable->setVisibility(GlobalValue::DefaultVisibility);
1157  Triple TT(M.getTargetTriple());
1158  if (TT.supportsCOMDAT()) {
1159  IRLevelVersionVariable->setLinkage(GlobalValue::ExternalLinkage);
1160  IRLevelVersionVariable->setComdat(M.getOrInsertComdat(VarName));
1161  }
1162  return IRLevelVersionVariable;
1163 }
1164 
1165 // Create the variable for the profile file name.
1166 void createProfileFileNameVar(Module &M, StringRef InstrProfileOutput) {
1167  if (InstrProfileOutput.empty())
1168  return;
1169  Constant *ProfileNameConst =
1170  ConstantDataArray::getString(M.getContext(), InstrProfileOutput, true);
1171  GlobalVariable *ProfileNameVar = new GlobalVariable(
1172  M, ProfileNameConst->getType(), true, GlobalValue::WeakAnyLinkage,
1173  ProfileNameConst, INSTR_PROF_QUOTE(INSTR_PROF_PROFILE_NAME_VAR));
1174  Triple TT(M.getTargetTriple());
1175  if (TT.supportsCOMDAT()) {
1176  ProfileNameVar->setLinkage(GlobalValue::ExternalLinkage);
1177  ProfileNameVar->setComdat(M.getOrInsertComdat(
1178  StringRef(INSTR_PROF_QUOTE(INSTR_PROF_PROFILE_NAME_VAR))));
1179  }
1180 }
1181 
1182 Error OverlapStats::accumulateCounts(const std::string &BaseFilename,
1183  const std::string &TestFilename,
1184  bool IsCS) {
1185  auto getProfileSum = [IsCS](const std::string &Filename,
1186  CountSumOrPercent &Sum) -> Error {
1187  auto ReaderOrErr = InstrProfReader::create(Filename);
1188  if (Error E = ReaderOrErr.takeError()) {
1189  return E;
1190  }
1191  auto Reader = std::move(ReaderOrErr.get());
1192  Reader->accumulateCounts(Sum, IsCS);
1193  return Error::success();
1194  };
1195  auto Ret = getProfileSum(BaseFilename, Base);
1196  if (Ret)
1197  return Ret;
1198  Ret = getProfileSum(TestFilename, Test);
1199  if (Ret)
1200  return Ret;
1201  this->BaseFilename = &BaseFilename;
1202  this->TestFilename = &TestFilename;
1203  Valid = true;
1204  return Error::success();
1205 }
1206 
1208  Mismatch.NumEntries += 1;
1209  Mismatch.CountSum += MismatchFunc.CountSum / Test.CountSum;
1210  for (unsigned I = 0; I < IPVK_Last - IPVK_First + 1; I++) {
1211  if (Test.ValueCounts[I] >= 1.0f)
1212  Mismatch.ValueCounts[I] +=
1213  MismatchFunc.ValueCounts[I] / Test.ValueCounts[I];
1214  }
1215 }
1216 
1218  Unique.NumEntries += 1;
1219  Unique.CountSum += UniqueFunc.CountSum / Test.CountSum;
1220  for (unsigned I = 0; I < IPVK_Last - IPVK_First + 1; I++) {
1221  if (Test.ValueCounts[I] >= 1.0f)
1222  Unique.ValueCounts[I] += UniqueFunc.ValueCounts[I] / Test.ValueCounts[I];
1223  }
1224 }
1225 
1227  if (!Valid)
1228  return;
1229 
1230  const char *EntryName =
1231  (Level == ProgramLevel ? "functions" : "edge counters");
1232  if (Level == ProgramLevel) {
1233  OS << "Profile overlap infomation for base_profile: " << *BaseFilename
1234  << " and test_profile: " << *TestFilename << "\nProgram level:\n";
1235  } else {
1236  OS << "Function level:\n"
1237  << " Function: " << FuncName << " (Hash=" << FuncHash << ")\n";
1238  }
1239 
1240  OS << " # of " << EntryName << " overlap: " << Overlap.NumEntries << "\n";
1241  if (Mismatch.NumEntries)
1242  OS << " # of " << EntryName << " mismatch: " << Mismatch.NumEntries
1243  << "\n";
1244  if (Unique.NumEntries)
1245  OS << " # of " << EntryName
1246  << " only in test_profile: " << Unique.NumEntries << "\n";
1247 
1248  OS << " Edge profile overlap: " << format("%.3f%%", Overlap.CountSum * 100)
1249  << "\n";
1250  if (Mismatch.NumEntries)
1251  OS << " Mismatched count percentage (Edge): "
1252  << format("%.3f%%", Mismatch.CountSum * 100) << "\n";
1253  if (Unique.NumEntries)
1254  OS << " Percentage of Edge profile only in test_profile: "
1255  << format("%.3f%%", Unique.CountSum * 100) << "\n";
1256  OS << " Edge profile base count sum: " << format("%.0f", Base.CountSum)
1257  << "\n"
1258  << " Edge profile test count sum: " << format("%.0f", Test.CountSum)
1259  << "\n";
1260 
1261  for (unsigned I = 0; I < IPVK_Last - IPVK_First + 1; I++) {
1262  if (Base.ValueCounts[I] < 1.0f && Test.ValueCounts[I] < 1.0f)
1263  continue;
1264  char ProfileKindName[20];
1265  switch (I) {
1266  case IPVK_IndirectCallTarget:
1267  strncpy(ProfileKindName, "IndirectCall", 19);
1268  break;
1269  case IPVK_MemOPSize:
1270  strncpy(ProfileKindName, "MemOP", 19);
1271  break;
1272  default:
1273  snprintf(ProfileKindName, 19, "VP[%d]", I);
1274  break;
1275  }
1276  OS << " " << ProfileKindName
1277  << " profile overlap: " << format("%.3f%%", Overlap.ValueCounts[I] * 100)
1278  << "\n";
1279  if (Mismatch.NumEntries)
1280  OS << " Mismatched count percentage (" << ProfileKindName
1281  << "): " << format("%.3f%%", Mismatch.ValueCounts[I] * 100) << "\n";
1282  if (Unique.NumEntries)
1283  OS << " Percentage of " << ProfileKindName
1284  << " profile only in test_profile: "
1285  << format("%.3f%%", Unique.ValueCounts[I] * 100) << "\n";
1286  OS << " " << ProfileKindName
1287  << " profile base count sum: " << format("%.0f", Base.ValueCounts[I])
1288  << "\n"
1289  << " " << ProfileKindName
1290  << " profile test count sum: " << format("%.0f", Test.ValueCounts[I])
1291  << "\n";
1292  }
1293 }
1294 
1295 } // 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::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:1060
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:874
llvm::StringRef::startswith
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:286
llvm::instrprof_error::bad_header
@ bad_header
MathExtras.h
llvm
---------------------— PointerInfo ------------------------------------—
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:153
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:219
llvm::getNumValueKindsInstrProf
uint32_t getNumValueKindsInstrProf(const void *Record)
ValueProfRecordClosure Interface implementation for InstrProfRecord class.
Definition: InstrProf.cpp:753
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:1072
llvm::getPGOFuncNameVarInitializer
StringRef getPGOFuncNameVarInitializer(GlobalVariable *NameVar)
Return the initializer in string of the PGO name var NameVar.
Definition: InstrProf.cpp:442
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:263
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:1226
ManagedStatic.h
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:331
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:773
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:342
llvm::tgtok::VarName
@ VarName
Definition: TGLexer.h:71
llvm::cl::Hidden
@ Hidden
Definition: CommandLine.h:143
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:45
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:647
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:573
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:136
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:297
llvm::createProfileFileNameVar
void createProfileFileNameVar(Module &M, StringRef InstrProfileOutput)
Definition: InstrProf.cpp:1166
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:1035
llvm::Type::getInt32Ty
static IntegerType * getInt32Ty(LLVMContext &C)
Definition: Type.cpp:203
llvm::ArrayRef::empty
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:160
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:1203
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:1336
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:624
llvm::MDNode::getNumOperands
unsigned getNumOperands() const
Return number of MDNode operands.
Definition: Metadata.h:1113
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:79
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:307
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:749
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::InstrProfRecordClosure
static ValueProfRecordClosure InstrProfRecordClosure
Definition: InstrProf.cpp:785
llvm::canRenameComdatFunc
bool canRenameComdatFunc(const Function &F, bool CheckAddressTaken=false)
Check if we can safely rename this Comdat function.
Definition: InstrProf.cpp:1120
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:778
llvm::Triple::supportsCOMDAT
bool supportsCOMDAT() const
Tests whether the target supports comdat.
Definition: Triple.h:815
llvm::stripDirPrefix
static StringRef stripDirPrefix(StringRef PathNameStr, uint32_t NumPrefix)
Definition: InstrProf.cpp:235
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:865
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:900
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
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
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:282
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:168
llvm::MDNode::getOperand
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1107
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:1630
uint64_t
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:194
llvm::getNumValueSitesInstrProf
uint32_t getNumValueSitesInstrProf(const void *Record, uint32_t VKind)
Definition: InstrProf.cpp:757
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:1098
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:125
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:443
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:473
message
message(STATUS "Targeting ${t}") add_subdirectory($
Definition: CMakeLists.txt:33
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:901
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:401
llvm::getNumValueDataInstrProf
uint32_t getNumValueDataInstrProf(const void *Record, uint32_t VKind)
Definition: InstrProf.cpp:762
llvm::StringRef::bytes_begin
const unsigned char * bytes_begin() const
Definition: StringRef.h:132
llvm::APInt
Class for arbitrary precision integers.
Definition: APInt.h:75
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:387
Triple.h
llvm::InstrProfRecord::accumulateCounts
void accumulateCounts(CountSumOrPercent &Sum) const
Compute the sums of all counts and store in Sum.
Definition: InstrProf.cpp:504
llvm::OverlapStats::addOneUnique
void addOneUnique(const CountSumOrPercent &UniqueFunc)
Definition: InstrProf.cpp:1217
llvm::ArrayRef< std::string >
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
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:141
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:3041
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:443
llvm::instrprof_category
const std::error_category & instrprof_category()
Definition: InstrProf.cpp:143
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:955
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:142
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:678
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:555
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:459
name
static const char * name
Definition: SVEIntrinsicOpts.cpp:78
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:1695
Constant.h
llvm::Type::getInt64Ty
static IntegerType * getInt64Ty(LLVMContext &C)
Definition: Type.cpp:204
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:653
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:524
llvm::ArrayRef::begin
iterator begin() const
Definition: ArrayRef.h:153
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:767
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:731
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:175
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:165
llvm::max
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:340
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:286
llvm::OverlapStats::accumulateCounts
Error accumulateCounts(const std::string &BaseFilename, const std::string &TestFilename, bool IsCS)
Definition: InstrProf.cpp:1182
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:1000
LLVMContext.h
llvm::cl::desc
Definition: CommandLine.h:414
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:157
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:1207
llvm::InstrProfRecord::Counts
std::vector< uint64_t > Counts
Definition: InstrProf.h:692
llvm::ArrayRef::end
iterator end() const
Definition: ArrayRef.h:154
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:1172
llvm::getPGOFuncNameMetadata
MDNode * getPGOFuncNameMetadata(const Function &F)
Return the PGOFuncName meta data associated with a function.
Definition: InstrProf.cpp:1056
llvm::StringRef::bytes_end
const unsigned char * bytes_end() const
Definition: StringRef.h:135
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:706
llvm::createIRLevelProfileFlagVar
GlobalVariable * createIRLevelProfileFlagVar(Module &M, bool IsCS, bool InstrEntryBBEnabled)
Definition: InstrProf.cpp:1144