diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2018-07-30 16:33:32 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2018-07-30 16:33:32 +0000 | 
| commit | 51315c45ff5643a27f9c84b816db54ee870ba29b (patch) | |
| tree | 1d87443fa0e53d3e6b315ce25787e64be0906bf7 /contrib/llvm/lib/ProfileData/SampleProf.cpp | |
| parent | 6dfd050075216be8538ae375a22d30db72916f7e (diff) | |
| parent | eb11fae6d08f479c0799db45860a98af528fa6e7 (diff) | |
Notes
Diffstat (limited to 'contrib/llvm/lib/ProfileData/SampleProf.cpp')
| -rw-r--r-- | contrib/llvm/lib/ProfileData/SampleProf.cpp | 32 | 
1 files changed, 30 insertions, 2 deletions
diff --git a/contrib/llvm/lib/ProfileData/SampleProf.cpp b/contrib/llvm/lib/ProfileData/SampleProf.cpp index eafdd2154b7b..30438ba7962a 100644 --- a/contrib/llvm/lib/ProfileData/SampleProf.cpp +++ b/contrib/llvm/lib/ProfileData/SampleProf.cpp @@ -13,6 +13,8 @@  //===----------------------------------------------------------------------===//  #include "llvm/ProfileData/SampleProf.h" +#include "llvm/Config/llvm-config.h" +#include "llvm/IR/DebugInfoMetadata.h"  #include "llvm/Support/Compiler.h"  #include "llvm/Support/Debug.h"  #include "llvm/Support/ErrorHandling.h" @@ -86,7 +88,7 @@ raw_ostream &llvm::sampleprof::operator<<(raw_ostream &OS,  LLVM_DUMP_METHOD void LineLocation::dump() const { print(dbgs()); }  #endif -/// \brief Print the sample record to the stream \p OS indented by \p Indent. +/// Print the sample record to the stream \p OS indented by \p Indent.  void SampleRecord::print(raw_ostream &OS, unsigned Indent) const {    OS << NumSamples;    if (hasCalls()) { @@ -107,7 +109,7 @@ raw_ostream &llvm::sampleprof::operator<<(raw_ostream &OS,    return OS;  } -/// \brief Print the samples collected for a function on stream \p OS. +/// Print the samples collected for a function on stream \p OS.  void FunctionSamples::print(raw_ostream &OS, unsigned Indent) const {    OS << TotalSamples << ", " << TotalHeadSamples << ", " << BodySamples.size()       << " sampled lines\n"; @@ -150,6 +152,32 @@ raw_ostream &llvm::sampleprof::operator<<(raw_ostream &OS,    return OS;  } +unsigned FunctionSamples::getOffset(const DILocation *DIL) { +  return (DIL->getLine() - DIL->getScope()->getSubprogram()->getLine()) & +      0xffff; +} + +const FunctionSamples * +FunctionSamples::findFunctionSamples(const DILocation *DIL) const { +  assert(DIL); +  SmallVector<std::pair<LineLocation, StringRef>, 10> S; + +  const DILocation *PrevDIL = DIL; +  for (DIL = DIL->getInlinedAt(); DIL; DIL = DIL->getInlinedAt()) { +    S.push_back(std::make_pair( +        LineLocation(getOffset(DIL), DIL->getBaseDiscriminator()), +        PrevDIL->getScope()->getSubprogram()->getLinkageName())); +    PrevDIL = DIL; +  } +  if (S.size() == 0) +    return this; +  const FunctionSamples *FS = this; +  for (int i = S.size() - 1; i >= 0 && FS != nullptr; i--) { +    FS = FS->findFunctionSamplesAt(S[i].first, S[i].second); +  } +  return FS; +} +  #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)  LLVM_DUMP_METHOD void FunctionSamples::dump() const { print(dbgs(), 0); }  #endif  | 
