<div dir="ltr">I've attached the patch.</div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Apr 21, 2016 at 6:11 PM, Justin Bogner <span dir="ltr"><<a href="mailto:mail@justinbogner.com" target="_blank">mail@justinbogner.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">Easwaran Raman <<a href="mailto:eraman@google.com">eraman@google.com</a>> writes:<br>
> eraman created this revision.<br>
> eraman added reviewers: bogner, vsk, davidxl.<br>
> eraman added a subscriber: llvm-commits.<br>
><br>
> Recently, I ran into a circular dependency problem when I made<br>
> Analysis depend on ProfileData.  See<br>
> <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-April/098400.html" rel="noreferrer" target="_blank">http://lists.llvm.org/pipermail/llvm-dev/2016-April/098400.html</a> for<br>
> more context. ProfileData has an existing dependence on Analysis<br>
> through Object and Bitcode. Only the Coverage code depends on<br>
> Object. Splitting Coverage data into its own library removes the<br>
> ProfileData->Analysis dependence. Does this seem reasonable?<br>
><br>
> Notes:<br>
> * I have modeled this on Codegen which has some files underneath as<br>
> well as subdirs that correspond to separate libraries.<br>
> * Clang code that includes coverage headers need to be changed as<br>
> well. Will send a patch once there is a general agreement on this<br>
> patch.<br>
> * I have used "svn mv" to move coverage related code into the new<br>
> directory to preserver history.<br>
> * I have not split the ProfileData unittest to a separate Coverage<br>
> directory thinking there will be only one file there, but perhaps that<br>
> also needs to be split?<br>
> * check-all runs successfully, but it's quite likely that I have<br>
> overlooked something.<br>
<br>
</span>It seems like phab corrupted this patch - it doesn't apply at all. Could<br>
you attach it to the email thread please?<br>
<div><div class="h5"><br>
> <a href="http://reviews.llvm.org/D19333" rel="noreferrer" target="_blank">http://reviews.llvm.org/D19333</a><br>
><br>
> Files:<br>
>   include/llvm/ProfileData/Coverage/CoverageMappingReader.h<br>
>   include/llvm/ProfileData/Coverage/CoverageMappingWriter.h<br>
>   include/llvm/ProfileData/CoverageMapping.h<br>
>   include/llvm/ProfileData/CoverageMappingReader.h<br>
>   include/llvm/ProfileData/CoverageMappingWriter.h<br>
>   lib/ProfileData/CMakeLists.txt<br>
>   lib/ProfileData/Coverage/CMakeLists.txt<br>
>   lib/ProfileData/Coverage/CoverageMapping.cpp<br>
>   lib/ProfileData/Coverage/CoverageMappingReader.cpp<br>
>   lib/ProfileData/Coverage/CoverageMappingWriter.cpp<br>
>   lib/ProfileData/Coverage/LLVMBuild.txt<br>
>   lib/ProfileData/CoverageMapping.cpp<br>
>   lib/ProfileData/CoverageMappingReader.cpp<br>
>   lib/ProfileData/CoverageMappingWriter.cpp<br>
>   lib/ProfileData/LLVMBuild.txt<br>
>   tools/llvm-cov/CMakeLists.txt<br>
>   tools/llvm-cov/CodeCoverage.cpp<br>
>   tools/llvm-cov/CoverageFilters.h<br>
>   tools/llvm-cov/CoverageSummaryInfo.h<br>
>   tools/llvm-cov/LLVMBuild.txt<br>
>   tools/llvm-cov/SourceCoverageView.h<br>
>   unittests/ProfileData/CMakeLists.txt<br>
>   unittests/ProfileData/CoverageMappingTest.cpp<br>
><br>
</div></div>> Index: unittests/ProfileData/CoverageMappingTest.cpp<br>
> ===================================================================<br>
> --- unittests/ProfileData/CoverageMappingTest.cpp<br>
> +++ unittests/ProfileData/CoverageMappingTest.cpp<br>
> @@ -7,9 +7,9 @@<br>
>  //<br>
>  //===----------------------------------------------------------------------===//<br>
><br>
> -#include "llvm/ProfileData/CoverageMapping.h"<br>
> -#include "llvm/ProfileData/CoverageMappingReader.h"<br>
> -#include "llvm/ProfileData/CoverageMappingWriter.h"<br>
> +#include "llvm/ProfileData/Coverage/CoverageMapping.h"<br>
> +#include "llvm/ProfileData/Coverage/CoverageMappingReader.h"<br>
> +#include "llvm/ProfileData/Coverage/CoverageMappingWriter.h"<br>
>  #include "llvm/ProfileData/InstrProfReader.h"<br>
>  #include "llvm/ProfileData/InstrProfWriter.h"<br>
>  #include "llvm/Support/raw_ostream.h"<br>
> Index: unittests/ProfileData/CMakeLists.txt<br>
> ===================================================================<br>
> --- unittests/ProfileData/CMakeLists.txt<br>
> +++ unittests/ProfileData/CMakeLists.txt<br>
> @@ -1,5 +1,6 @@<br>
>  set(LLVM_LINK_COMPONENTS<br>
>    Core<br>
> +  Coverage<br>
>    ProfileData<br>
>    Support<br>
>    )<br>
> Index: tools/llvm-cov/SourceCoverageView.h<br>
> ===================================================================<br>
> --- tools/llvm-cov/SourceCoverageView.h<br>
> +++ tools/llvm-cov/SourceCoverageView.h<br>
> @@ -15,7 +15,7 @@<br>
>  #define LLVM_COV_SOURCECOVERAGEVIEW_H<br>
><br>
>  #include "CoverageViewOptions.h"<br>
> -#include "llvm/ProfileData/CoverageMapping.h"<br>
> +#include "llvm/ProfileData/Coverage/CoverageMapping.h"<br>
>  #include "llvm/Support/MemoryBuffer.h"<br>
>  #include <vector><br>
><br>
> Index: tools/llvm-cov/LLVMBuild.txt<br>
> ===================================================================<br>
> --- tools/llvm-cov/LLVMBuild.txt<br>
> +++ tools/llvm-cov/LLVMBuild.txt<br>
> @@ -19,4 +19,4 @@<br>
>  type = Tool<br>
>  name = llvm-cov<br>
>  parent = Tools<br>
> -required_libraries = ProfileData Support Instrumentation<br>
> +required_libraries = Coverage Support Instrumentation<br>
> Index: tools/llvm-cov/CoverageSummaryInfo.h<br>
> ===================================================================<br>
> --- tools/llvm-cov/CoverageSummaryInfo.h<br>
> +++ tools/llvm-cov/CoverageSummaryInfo.h<br>
> @@ -15,7 +15,7 @@<br>
>  #ifndef LLVM_COV_COVERAGESUMMARYINFO_H<br>
>  #define LLVM_COV_COVERAGESUMMARYINFO_H<br>
><br>
> -#include "llvm/ProfileData/CoverageMapping.h"<br>
> +#include "llvm/ProfileData/Coverage/CoverageMapping.h"<br>
>  #include "llvm/Support/raw_ostream.h"<br>
><br>
>  namespace llvm {<br>
> Index: tools/llvm-cov/CoverageFilters.h<br>
> ===================================================================<br>
> --- tools/llvm-cov/CoverageFilters.h<br>
> +++ tools/llvm-cov/CoverageFilters.h<br>
> @@ -14,7 +14,7 @@<br>
>  #ifndef LLVM_COV_COVERAGEFILTERS_H<br>
>  #define LLVM_COV_COVERAGEFILTERS_H<br>
><br>
> -#include "llvm/ProfileData/CoverageMapping.h"<br>
> +#include "llvm/ProfileData/Coverage/CoverageMapping.h"<br>
>  #include <memory><br>
>  #include <vector><br>
><br>
> Index: tools/llvm-cov/CodeCoverage.cpp<br>
> ===================================================================<br>
> --- tools/llvm-cov/CodeCoverage.cpp<br>
> +++ tools/llvm-cov/CodeCoverage.cpp<br>
> @@ -13,15 +13,15 @@<br>
>  //<br>
>  //===----------------------------------------------------------------------===//<br>
><br>
> -#include "RenderingSupport.h"<br>
>  #include "CoverageFilters.h"<br>
>  #include "CoverageReport.h"<br>
>  #include "CoverageViewOptions.h"<br>
> +#include "RenderingSupport.h"<br>
>  #include "SourceCoverageView.h"<br>
>  #include "llvm/ADT/SmallString.h"<br>
>  #include "llvm/ADT/StringRef.h"<br>
>  #include "llvm/ADT/Triple.h"<br>
> -#include "llvm/ProfileData/CoverageMapping.h"<br>
> +#include "llvm/ProfileData/Coverage/CoverageMapping.h"<br>
>  #include "llvm/ProfileData/InstrProfReader.h"<br>
>  #include "llvm/Support/CommandLine.h"<br>
>  #include "llvm/Support/FileSystem.h"<br>
> Index: tools/llvm-cov/CMakeLists.txt<br>
> ===================================================================<br>
> --- tools/llvm-cov/CMakeLists.txt<br>
> +++ tools/llvm-cov/CMakeLists.txt<br>
> @@ -1,4 +1,4 @@<br>
> -set(LLVM_LINK_COMPONENTS core support object profiledata)<br>
> +set(LLVM_LINK_COMPONENTS core support object coverage profiledata)<br>
><br>
>  add_llvm_tool(llvm-cov<br>
>    llvm-cov.cpp<br>
> Index: lib/ProfileData/LLVMBuild.txt<br>
> ===================================================================<br>
> --- lib/ProfileData/LLVMBuild.txt<br>
> +++ lib/ProfileData/LLVMBuild.txt<br>
> @@ -15,8 +15,11 @@<br>
>  ;<br>
>  ;===------------------------------------------------------------------------===;<br>
><br>
> +[common]<br>
> +subdirectories = Coverage<br>
> +<br>
>  [component_0]<br>
>  type = Library<br>
>  name = ProfileData<br>
>  parent = Libraries<br>
> -required_libraries = Core Support Object<br>
> +required_libraries = Core Support<br>
> Index: lib/ProfileData/CoverageMappingWriter.cpp<br>
> ===================================================================<br>
> --- lib/ProfileData/CoverageMappingWriter.cpp<br>
> +++ lib/ProfileData/CoverageMappingWriter.cpp<br>
> @@ -1,183 +0,0 @@<br>
> -//=-- CoverageMappingWriter.cpp - Code coverage mapping writer -------------=//<br>
> -//<br>
> -//                     The LLVM Compiler Infrastructure<br>
> -//<br>
> -// This file is distributed under the University of Illinois Open Source<br>
> -// License. See LICENSE.TXT for details.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -//<br>
> -// This file contains support for writing coverage mapping data for<br>
> -// instrumentation based coverage.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -<br>
> -#include "llvm/ProfileData/CoverageMappingWriter.h"<br>
> -#include "llvm/Support/LEB128.h"<br>
> -<br>
> -using namespace llvm;<br>
> -using namespace coverage;<br>
> -<br>
> -void CoverageFilenamesSectionWriter::write(raw_ostream &OS) {<br>
> -  encodeULEB128(Filenames.size(), OS);<br>
> -  for (const auto &Filename : Filenames) {<br>
> -    encodeULEB128(Filename.size(), OS);<br>
> -    OS << Filename;<br>
> -  }<br>
> -}<br>
> -<br>
> -namespace {<br>
> -/// \brief Gather only the expressions that are used by the mapping<br>
> -/// regions in this function.<br>
> -class CounterExpressionsMinimizer {<br>
> -  ArrayRef<CounterExpression> Expressions;<br>
> -  llvm::SmallVector<CounterExpression, 16> UsedExpressions;<br>
> -  std::vector<unsigned> AdjustedExpressionIDs;<br>
> -<br>
> -public:<br>
> -  void mark(Counter C) {<br>
> -    if (!C.isExpression())<br>
> -      return;<br>
> -    unsigned ID = C.getExpressionID();<br>
> -    AdjustedExpressionIDs[ID] = 1;<br>
> -    mark(Expressions[ID].LHS);<br>
> -    mark(Expressions[ID].RHS);<br>
> -  }<br>
> -<br>
> -  void gatherUsed(Counter C) {<br>
> -    if (!C.isExpression() || !AdjustedExpressionIDs[C.getExpressionID()])<br>
> -      return;<br>
> -    AdjustedExpressionIDs[C.getExpressionID()] = UsedExpressions.size();<br>
> -    const auto &E = Expressions[C.getExpressionID()];<br>
> -    UsedExpressions.push_back(E);<br>
> -    gatherUsed(E.LHS);<br>
> -    gatherUsed(E.RHS);<br>
> -  }<br>
> -<br>
> -  CounterExpressionsMinimizer(ArrayRef<CounterExpression> Expressions,<br>
> -                              ArrayRef<CounterMappingRegion> MappingRegions)<br>
> -      : Expressions(Expressions) {<br>
> -    AdjustedExpressionIDs.resize(Expressions.size(), 0);<br>
> -    for (const auto &I : MappingRegions)<br>
> -      mark(I.Count);<br>
> -    for (const auto &I : MappingRegions)<br>
> -      gatherUsed(I.Count);<br>
> -  }<br>
> -<br>
> -  ArrayRef<CounterExpression> getExpressions() const { return UsedExpressions; }<br>
> -<br>
> -  /// \brief Adjust the given counter to correctly transition from the old<br>
> -  /// expression ids to the new expression ids.<br>
> -  Counter adjust(Counter C) const {<br>
> -    if (C.isExpression())<br>
> -      C = Counter::getExpression(AdjustedExpressionIDs[C.getExpressionID()]);<br>
> -    return C;<br>
> -  }<br>
> -};<br>
> -}<br>
> -<br>
> -/// \brief Encode the counter.<br>
> -///<br>
> -/// The encoding uses the following format:<br>
> -/// Low 2 bits - Tag:<br>
> -///   Counter::Zero(0) - A Counter with kind Counter::Zero<br>
> -///   Counter::CounterValueReference(1) - A counter with kind<br>
> -///     Counter::CounterValueReference<br>
> -///   Counter::Expression(2) + CounterExpression::Subtract(0) -<br>
> -///     A counter with kind Counter::Expression and an expression<br>
> -///     with kind CounterExpression::Subtract<br>
> -///   Counter::Expression(2) + CounterExpression::Add(1) -<br>
> -///     A counter with kind Counter::Expression and an expression<br>
> -///     with kind CounterExpression::Add<br>
> -/// Remaining bits - Counter/Expression ID.<br>
> -static unsigned encodeCounter(ArrayRef<CounterExpression> Expressions,<br>
> -                              Counter C) {<br>
> -  unsigned Tag = unsigned(C.getKind());<br>
> -  if (C.isExpression())<br>
> -    Tag += Expressions[C.getExpressionID()].Kind;<br>
> -  unsigned ID = C.getCounterID();<br>
> -  assert(ID <=<br>
> -         (std::numeric_limits<unsigned>::max() >> Counter::EncodingTagBits));<br>
> -  return Tag | (ID << Counter::EncodingTagBits);<br>
> -}<br>
> -<br>
> -static void writeCounter(ArrayRef<CounterExpression> Expressions, Counter C,<br>
> -                         raw_ostream &OS) {<br>
> -  encodeULEB128(encodeCounter(Expressions, C), OS);<br>
> -}<br>
> -<br>
> -void CoverageMappingWriter::write(raw_ostream &OS) {<br>
> -  // Sort the regions in an ascending order by the file id and the starting<br>
> -  // location.<br>
> -  std::stable_sort(MappingRegions.begin(), MappingRegions.end());<br>
> -<br>
> -  // Write out the fileid -> filename mapping.<br>
> -  encodeULEB128(VirtualFileMapping.size(), OS);<br>
> -  for (const auto &FileID : VirtualFileMapping)<br>
> -    encodeULEB128(FileID, OS);<br>
> -<br>
> -  // Write out the expressions.<br>
> -  CounterExpressionsMinimizer Minimizer(Expressions, MappingRegions);<br>
> -  auto MinExpressions = Minimizer.getExpressions();<br>
> -  encodeULEB128(MinExpressions.size(), OS);<br>
> -  for (const auto &E : MinExpressions) {<br>
> -    writeCounter(MinExpressions, Minimizer.adjust(E.LHS), OS);<br>
> -    writeCounter(MinExpressions, Minimizer.adjust(E.RHS), OS);<br>
> -  }<br>
> -<br>
> -  // Write out the mapping regions.<br>
> -  // Split the regions into subarrays where each region in a<br>
> -  // subarray has a fileID which is the index of that subarray.<br>
> -  unsigned PrevLineStart = 0;<br>
> -  unsigned CurrentFileID = ~0U;<br>
> -  for (auto I = MappingRegions.begin(), E = MappingRegions.end(); I != E; ++I) {<br>
> -    if (I->FileID != CurrentFileID) {<br>
> -      // Ensure that all file ids have at least one mapping region.<br>
> -      assert(I->FileID == (CurrentFileID + 1));<br>
> -      // Find the number of regions with this file id.<br>
> -      unsigned RegionCount = 1;<br>
> -      for (auto J = I + 1; J != E && I->FileID == J->FileID; ++J)<br>
> -        ++RegionCount;<br>
> -      // Start a new region sub-array.<br>
> -      encodeULEB128(RegionCount, OS);<br>
> -<br>
> -      CurrentFileID = I->FileID;<br>
> -      PrevLineStart = 0;<br>
> -    }<br>
> -    Counter Count = Minimizer.adjust(I->Count);<br>
> -    switch (I->Kind) {<br>
> -    case CounterMappingRegion::CodeRegion:<br>
> -      writeCounter(MinExpressions, Count, OS);<br>
> -      break;<br>
> -    case CounterMappingRegion::ExpansionRegion: {<br>
> -      assert(Count.isZero());<br>
> -      assert(I->ExpandedFileID <=<br>
> -             (std::numeric_limits<unsigned>::max() >><br>
> -              Counter::EncodingCounterTagAndExpansionRegionTagBits));<br>
> -      // Mark an expansion region with a set bit that follows the counter tag,<br>
> -      // and pack the expanded file id into the remaining bits.<br>
> -      unsigned EncodedTagExpandedFileID =<br>
> -          (1 << Counter::EncodingTagBits) |<br>
> -          (I->ExpandedFileID<br>
> -           << Counter::EncodingCounterTagAndExpansionRegionTagBits);<br>
> -      encodeULEB128(EncodedTagExpandedFileID, OS);<br>
> -      break;<br>
> -    }<br>
> -    case CounterMappingRegion::SkippedRegion:<br>
> -      assert(Count.isZero());<br>
> -      encodeULEB128(unsigned(I->Kind)<br>
> -                        << Counter::EncodingCounterTagAndExpansionRegionTagBits,<br>
> -                    OS);<br>
> -      break;<br>
> -    }<br>
> -    assert(I->LineStart >= PrevLineStart);<br>
> -    encodeULEB128(I->LineStart - PrevLineStart, OS);<br>
> -    encodeULEB128(I->ColumnStart, OS);<br>
> -    assert(I->LineEnd >= I->LineStart);<br>
> -    encodeULEB128(I->LineEnd - I->LineStart, OS);<br>
> -    encodeULEB128(I->ColumnEnd, OS);<br>
> -    PrevLineStart = I->LineStart;<br>
> -  }<br>
> -  // Ensure that all file ids have at least one mapping region.<br>
> -  assert(CurrentFileID == (VirtualFileMapping.size() - 1));<br>
> -}<br>
> Index: lib/ProfileData/CoverageMappingReader.cpp<br>
> ===================================================================<br>
> --- lib/ProfileData/CoverageMappingReader.cpp<br>
> +++ lib/ProfileData/CoverageMappingReader.cpp<br>
> @@ -1,619 +0,0 @@<br>
> -//=-- CoverageMappingReader.cpp - Code coverage mapping reader ----*- C++ -*-=//<br>
> -//<br>
> -//                     The LLVM Compiler Infrastructure<br>
> -//<br>
> -// This file is distributed under the University of Illinois Open Source<br>
> -// License. See LICENSE.TXT for details.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -//<br>
> -// This file contains support for reading coverage mapping data for<br>
> -// instrumentation based coverage.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -<br>
> -#include "llvm/ProfileData/CoverageMappingReader.h"<br>
> -#include "llvm/ADT/DenseSet.h"<br>
> -#include "llvm/Object/MachOUniversal.h"<br>
> -#include "llvm/Object/ObjectFile.h"<br>
> -#include "llvm/Support/Debug.h"<br>
> -#include "llvm/Support/Endian.h"<br>
> -#include "llvm/Support/LEB128.h"<br>
> -#include "llvm/Support/MathExtras.h"<br>
> -#include "llvm/Support/raw_ostream.h"<br>
> -<br>
> -using namespace llvm;<br>
> -using namespace coverage;<br>
> -using namespace object;<br>
> -<br>
> -#define DEBUG_TYPE "coverage-mapping"<br>
> -<br>
> -void CoverageMappingIterator::increment() {<br>
> -  // Check if all the records were read or if an error occurred while reading<br>
> -  // the next record.<br>
> -  if (Reader->readNextRecord(Record))<br>
> -    *this = CoverageMappingIterator();<br>
> -}<br>
> -<br>
> -std::error_code RawCoverageReader::readULEB128(uint64_t &Result) {<br>
> -  if (Data.size() < 1)<br>
> -    return coveragemap_error::truncated;<br>
> -  unsigned N = 0;<br>
> -  Result = decodeULEB128(reinterpret_cast<const uint8_t *>(Data.data()), &N);<br>
> -  if (N > Data.size())<br>
> -    return coveragemap_error::malformed;<br>
> -  Data = Data.substr(N);<br>
> -  return std::error_code();<br>
> -}<br>
> -<br>
> -std::error_code RawCoverageReader::readIntMax(uint64_t &Result,<br>
> -                                              uint64_t MaxPlus1) {<br>
> -  if (auto Err = readULEB128(Result))<br>
> -    return Err;<br>
> -  if (Result >= MaxPlus1)<br>
> -    return coveragemap_error::malformed;<br>
> -  return std::error_code();<br>
> -}<br>
> -<br>
> -std::error_code RawCoverageReader::readSize(uint64_t &Result) {<br>
> -  if (auto Err = readULEB128(Result))<br>
> -    return Err;<br>
> -  // Sanity check the number.<br>
> -  if (Result > Data.size())<br>
> -    return coveragemap_error::malformed;<br>
> -  return std::error_code();<br>
> -}<br>
> -<br>
> -std::error_code RawCoverageReader::readString(StringRef &Result) {<br>
> -  uint64_t Length;<br>
> -  if (auto Err = readSize(Length))<br>
> -    return Err;<br>
> -  Result = Data.substr(0, Length);<br>
> -  Data = Data.substr(Length);<br>
> -  return std::error_code();<br>
> -}<br>
> -<br>
> -std::error_code RawCoverageFilenamesReader::read() {<br>
> -  uint64_t NumFilenames;<br>
> -  if (auto Err = readSize(NumFilenames))<br>
> -    return Err;<br>
> -  for (size_t I = 0; I < NumFilenames; ++I) {<br>
> -    StringRef Filename;<br>
> -    if (auto Err = readString(Filename))<br>
> -      return Err;<br>
> -    Filenames.push_back(Filename);<br>
> -  }<br>
> -  return std::error_code();<br>
> -}<br>
> -<br>
> -std::error_code RawCoverageMappingReader::decodeCounter(unsigned Value,<br>
> -                                                        Counter &C) {<br>
> -  auto Tag = Value & Counter::EncodingTagMask;<br>
> -  switch (Tag) {<br>
> -  case Counter::Zero:<br>
> -    C = Counter::getZero();<br>
> -    return std::error_code();<br>
> -  case Counter::CounterValueReference:<br>
> -    C = Counter::getCounter(Value >> Counter::EncodingTagBits);<br>
> -    return std::error_code();<br>
> -  default:<br>
> -    break;<br>
> -  }<br>
> -  Tag -= Counter::Expression;<br>
> -  switch (Tag) {<br>
> -  case CounterExpression::Subtract:<br>
> -  case CounterExpression::Add: {<br>
> -    auto ID = Value >> Counter::EncodingTagBits;<br>
> -    if (ID >= Expressions.size())<br>
> -      return coveragemap_error::malformed;<br>
> -    Expressions[ID].Kind = CounterExpression::ExprKind(Tag);<br>
> -    C = Counter::getExpression(ID);<br>
> -    break;<br>
> -  }<br>
> -  default:<br>
> -    return coveragemap_error::malformed;<br>
> -  }<br>
> -  return std::error_code();<br>
> -}<br>
> -<br>
> -std::error_code RawCoverageMappingReader::readCounter(Counter &C) {<br>
> -  uint64_t EncodedCounter;<br>
> -  if (auto Err =<br>
> -          readIntMax(EncodedCounter, std::numeric_limits<unsigned>::max()))<br>
> -    return Err;<br>
> -  if (auto Err = decodeCounter(EncodedCounter, C))<br>
> -    return Err;<br>
> -  return std::error_code();<br>
> -}<br>
> -<br>
> -static const unsigned EncodingExpansionRegionBit = 1<br>
> -                                                   << Counter::EncodingTagBits;<br>
> -<br>
> -/// \brief Read the sub-array of regions for the given inferred file id.<br>
> -/// \param NumFileIDs the number of file ids that are defined for this<br>
> -/// function.<br>
> -std::error_code RawCoverageMappingReader::readMappingRegionsSubArray(<br>
> -    std::vector<CounterMappingRegion> &MappingRegions, unsigned InferredFileID,<br>
> -    size_t NumFileIDs) {<br>
> -  uint64_t NumRegions;<br>
> -  if (auto Err = readSize(NumRegions))<br>
> -    return Err;<br>
> -  unsigned LineStart = 0;<br>
> -  for (size_t I = 0; I < NumRegions; ++I) {<br>
> -    Counter C;<br>
> -    CounterMappingRegion::RegionKind Kind = CounterMappingRegion::CodeRegion;<br>
> -<br>
> -    // Read the combined counter + region kind.<br>
> -    uint64_t EncodedCounterAndRegion;<br>
> -    if (auto Err = readIntMax(EncodedCounterAndRegion,<br>
> -                              std::numeric_limits<unsigned>::max()))<br>
> -      return Err;<br>
> -    unsigned Tag = EncodedCounterAndRegion & Counter::EncodingTagMask;<br>
> -    uint64_t ExpandedFileID = 0;<br>
> -    if (Tag != Counter::Zero) {<br>
> -      if (auto Err = decodeCounter(EncodedCounterAndRegion, C))<br>
> -        return Err;<br>
> -    } else {<br>
> -      // Is it an expansion region?<br>
> -      if (EncodedCounterAndRegion & EncodingExpansionRegionBit) {<br>
> -        Kind = CounterMappingRegion::ExpansionRegion;<br>
> -        ExpandedFileID = EncodedCounterAndRegion >><br>
> -                         Counter::EncodingCounterTagAndExpansionRegionTagBits;<br>
> -        if (ExpandedFileID >= NumFileIDs)<br>
> -          return coveragemap_error::malformed;<br>
> -      } else {<br>
> -        switch (EncodedCounterAndRegion >><br>
> -                Counter::EncodingCounterTagAndExpansionRegionTagBits) {<br>
> -        case CounterMappingRegion::CodeRegion:<br>
> -          // Don't do anything when we have a code region with a zero counter.<br>
> -          break;<br>
> -        case CounterMappingRegion::SkippedRegion:<br>
> -          Kind = CounterMappingRegion::SkippedRegion;<br>
> -          break;<br>
> -        default:<br>
> -          return coveragemap_error::malformed;<br>
> -        }<br>
> -      }<br>
> -    }<br>
> -<br>
> -    // Read the source range.<br>
> -    uint64_t LineStartDelta, ColumnStart, NumLines, ColumnEnd;<br>
> -    if (auto Err =<br>
> -            readIntMax(LineStartDelta, std::numeric_limits<unsigned>::max()))<br>
> -      return Err;<br>
> -    if (auto Err = readULEB128(ColumnStart))<br>
> -      return Err;<br>
> -    if (ColumnStart > std::numeric_limits<unsigned>::max())<br>
> -      return coveragemap_error::malformed;<br>
> -    if (auto Err = readIntMax(NumLines, std::numeric_limits<unsigned>::max()))<br>
> -      return Err;<br>
> -    if (auto Err = readIntMax(ColumnEnd, std::numeric_limits<unsigned>::max()))<br>
> -      return Err;<br>
> -    LineStart += LineStartDelta;<br>
> -    // Adjust the column locations for the empty regions that are supposed to<br>
> -    // cover whole lines. Those regions should be encoded with the<br>
> -    // column range (1 -> std::numeric_limits<unsigned>::max()), but because<br>
> -    // the encoded std::numeric_limits<unsigned>::max() is several bytes long,<br>
> -    // we set the column range to (0 -> 0) to ensure that the column start and<br>
> -    // column end take up one byte each.<br>
> -    // The std::numeric_limits<unsigned>::max() is used to represent a column<br>
> -    // position at the end of the line without knowing the length of that line.<br>
> -    if (ColumnStart == 0 && ColumnEnd == 0) {<br>
> -      ColumnStart = 1;<br>
> -      ColumnEnd = std::numeric_limits<unsigned>::max();<br>
> -    }<br>
> -<br>
> -    DEBUG({<br>
> -      dbgs() << "Counter in file " << InferredFileID << " " << LineStart << ":"<br>
> -             << ColumnStart << " -> " << (LineStart + NumLines) << ":"<br>
> -             << ColumnEnd << ", ";<br>
> -      if (Kind == CounterMappingRegion::ExpansionRegion)<br>
> -        dbgs() << "Expands to file " << ExpandedFileID;<br>
> -      else<br>
> -        CounterMappingContext(Expressions).dump(C, dbgs());<br>
> -      dbgs() << "\n";<br>
> -    });<br>
> -<br>
> -    MappingRegions.push_back(CounterMappingRegion(<br>
> -        C, InferredFileID, ExpandedFileID, LineStart, ColumnStart,<br>
> -        LineStart + NumLines, ColumnEnd, Kind));<br>
> -  }<br>
> -  return std::error_code();<br>
> -}<br>
> -<br>
> -std::error_code RawCoverageMappingReader::read() {<br>
> -<br>
> -  // Read the virtual file mapping.<br>
> -  llvm::SmallVector<unsigned, 8> VirtualFileMapping;<br>
> -  uint64_t NumFileMappings;<br>
> -  if (auto Err = readSize(NumFileMappings))<br>
> -    return Err;<br>
> -  for (size_t I = 0; I < NumFileMappings; ++I) {<br>
> -    uint64_t FilenameIndex;<br>
> -    if (auto Err = readIntMax(FilenameIndex, TranslationUnitFilenames.size()))<br>
> -      return Err;<br>
> -    VirtualFileMapping.push_back(FilenameIndex);<br>
> -  }<br>
> -<br>
> -  // Construct the files using unique filenames and virtual file mapping.<br>
> -  for (auto I : VirtualFileMapping) {<br>
> -    Filenames.push_back(TranslationUnitFilenames[I]);<br>
> -  }<br>
> -<br>
> -  // Read the expressions.<br>
> -  uint64_t NumExpressions;<br>
> -  if (auto Err = readSize(NumExpressions))<br>
> -    return Err;<br>
> -  // Create an array of dummy expressions that get the proper counters<br>
> -  // when the expressions are read, and the proper kinds when the counters<br>
> -  // are decoded.<br>
> -  Expressions.resize(<br>
> -      NumExpressions,<br>
> -      CounterExpression(CounterExpression::Subtract, Counter(), Counter()));<br>
> -  for (size_t I = 0; I < NumExpressions; ++I) {<br>
> -    if (auto Err = readCounter(Expressions[I].LHS))<br>
> -      return Err;<br>
> -    if (auto Err = readCounter(Expressions[I].RHS))<br>
> -      return Err;<br>
> -  }<br>
> -<br>
> -  // Read the mapping regions sub-arrays.<br>
> -  for (unsigned InferredFileID = 0, S = VirtualFileMapping.size();<br>
> -       InferredFileID < S; ++InferredFileID) {<br>
> -    if (auto Err = readMappingRegionsSubArray(MappingRegions, InferredFileID,<br>
> -                                              VirtualFileMapping.size()))<br>
> -      return Err;<br>
> -  }<br>
> -<br>
> -  // Set the counters for the expansion regions.<br>
> -  // i.e. Counter of expansion region = counter of the first region<br>
> -  // from the expanded file.<br>
> -  // Perform multiple passes to correctly propagate the counters through<br>
> -  // all the nested expansion regions.<br>
> -  SmallVector<CounterMappingRegion *, 8> FileIDExpansionRegionMapping;<br>
> -  FileIDExpansionRegionMapping.resize(VirtualFileMapping.size(), nullptr);<br>
> -  for (unsigned Pass = 1, S = VirtualFileMapping.size(); Pass < S; ++Pass) {<br>
> -    for (auto &R : MappingRegions) {<br>
> -      if (R.Kind != CounterMappingRegion::ExpansionRegion)<br>
> -        continue;<br>
> -      assert(!FileIDExpansionRegionMapping[R.ExpandedFileID]);<br>
> -      FileIDExpansionRegionMapping[R.ExpandedFileID] = &R;<br>
> -    }<br>
> -    for (auto &R : MappingRegions) {<br>
> -      if (FileIDExpansionRegionMapping[R.FileID]) {<br>
> -        FileIDExpansionRegionMapping[R.FileID]->Count = R.Count;<br>
> -        FileIDExpansionRegionMapping[R.FileID] = nullptr;<br>
> -      }<br>
> -    }<br>
> -  }<br>
> -<br>
> -  return std::error_code();<br>
> -}<br>
> -<br>
> -std::error_code InstrProfSymtab::create(SectionRef &Section) {<br>
> -  if (auto Err = Section.getContents(Data))<br>
> -    return Err;<br>
> -  Address = Section.getAddress();<br>
> -  return std::error_code();<br>
> -}<br>
> -<br>
> -StringRef InstrProfSymtab::getFuncName(uint64_t Pointer, size_t Size) {<br>
> -  if (Pointer < Address)<br>
> -    return StringRef();<br>
> -  auto Offset = Pointer - Address;<br>
> -  if (Offset + Size > Data.size())<br>
> -    return StringRef();<br>
> -  return Data.substr(Pointer - Address, Size);<br>
> -}<br>
> -<br>
> -namespace {<br>
> -struct CovMapFuncRecordReader {<br>
> -  // The interface to read coverage mapping function records for<br>
> -  // a module. \p Buf is a reference to the buffer pointer pointing<br>
> -  // to the \c CovHeader of coverage mapping data associated with<br>
> -  // the module.<br>
> -  virtual std::error_code readFunctionRecords(const char *&Buf,<br>
> -                                              const char *End) = 0;<br>
> -  virtual ~CovMapFuncRecordReader() {}<br>
> -  template <class IntPtrT, support::endianness Endian><br>
> -  static std::unique_ptr<CovMapFuncRecordReader><br>
> -  get(coverage::CovMapVersion Version, InstrProfSymtab &P,<br>
> -      std::vector<BinaryCoverageReader::ProfileMappingRecord> &R,<br>
> -      std::vector<StringRef> &F);<br>
> -};<br>
> -<br>
> -// A class for reading coverage mapping function records for a module.<br>
> -template <coverage::CovMapVersion Version, class IntPtrT,<br>
> -          support::endianness Endian><br>
> -class VersionedCovMapFuncRecordReader : public CovMapFuncRecordReader {<br>
> -  typedef typename coverage::CovMapTraits<<br>
> -      Version, IntPtrT>::CovMapFuncRecordType FuncRecordType;<br>
> -  typedef typename coverage::CovMapTraits<Version, IntPtrT>::NameRefType<br>
> -      NameRefType;<br>
> -<br>
> -  llvm::DenseSet<NameRefType> UniqueFunctionMappingData;<br>
> -  InstrProfSymtab &ProfileNames;<br>
> -  std::vector<StringRef> &Filenames;<br>
> -  std::vector<BinaryCoverageReader::ProfileMappingRecord> &Records;<br>
> -<br>
> -public:<br>
> -  VersionedCovMapFuncRecordReader(<br>
> -      InstrProfSymtab &P,<br>
> -      std::vector<BinaryCoverageReader::ProfileMappingRecord> &R,<br>
> -      std::vector<StringRef> &F)<br>
> -      : ProfileNames(P), Filenames(F), Records(R) {}<br>
> -  ~VersionedCovMapFuncRecordReader() override {}<br>
> -<br>
> -  std::error_code readFunctionRecords(const char *&Buf,<br>
> -                                      const char *End) override {<br>
> -    using namespace support;<br>
> -    if (Buf + sizeof(CovMapHeader) > End)<br>
> -      return coveragemap_error::malformed;<br>
> -    auto CovHeader = reinterpret_cast<const coverage::CovMapHeader *>(Buf);<br>
> -    uint32_t NRecords = CovHeader->getNRecords<Endian>();<br>
> -    uint32_t FilenamesSize = CovHeader->getFilenamesSize<Endian>();<br>
> -    uint32_t CoverageSize = CovHeader->getCoverageSize<Endian>();<br>
> -    assert((CovMapVersion)CovHeader->getVersion<Endian>() == Version);<br>
> -    Buf = reinterpret_cast<const char *>(CovHeader + 1);<br>
> -<br>
> -    // Skip past the function records, saving the start and end for later.<br>
> -    const char *FunBuf = Buf;<br>
> -    Buf += NRecords * sizeof(FuncRecordType);<br>
> -    const char *FunEnd = Buf;<br>
> -<br>
> -    // Get the filenames.<br>
> -    if (Buf + FilenamesSize > End)<br>
> -      return coveragemap_error::malformed;<br>
> -    size_t FilenamesBegin = Filenames.size();<br>
> -    RawCoverageFilenamesReader Reader(StringRef(Buf, FilenamesSize), Filenames);<br>
> -    if (auto Err = Reader.read())<br>
> -      return Err;<br>
> -    Buf += FilenamesSize;<br>
> -<br>
> -    // We'll read the coverage mapping records in the loop below.<br>
> -    const char *CovBuf = Buf;<br>
> -    Buf += CoverageSize;<br>
> -    const char *CovEnd = Buf;<br>
> -<br>
> -    if (Buf > End)<br>
> -      return coveragemap_error::malformed;<br>
> -    // Each coverage map has an alignment of 8, so we need to adjust alignment<br>
> -    // before reading the next map.<br>
> -    Buf += alignmentAdjustment(Buf, 8);<br>
> -<br>
> -    auto CFR = reinterpret_cast<const FuncRecordType *>(FunBuf);<br>
> -    while ((const char *)CFR < FunEnd) {<br>
> -      // Read the function information<br>
> -      uint32_t DataSize = CFR->template getDataSize<Endian>();<br>
> -      uint64_t FuncHash = CFR->template getFuncHash<Endian>();<br>
> -<br>
> -      // Now use that to read the coverage data.<br>
> -      if (CovBuf + DataSize > CovEnd)<br>
> -        return coveragemap_error::malformed;<br>
> -      auto Mapping = StringRef(CovBuf, DataSize);<br>
> -      CovBuf += DataSize;<br>
> -<br>
> -      // Ignore this record if we already have a record that points to the same<br>
> -      // function name. This is useful to ignore the redundant records for the<br>
> -      // functions with ODR linkage.<br>
> -      NameRefType NameRef = CFR->template getFuncNameRef<Endian>();<br>
> -      if (!UniqueFunctionMappingData.insert(NameRef).second) {<br>
> -        CFR++;<br>
> -        continue;<br>
> -      }<br>
> -<br>
> -      StringRef FuncName;<br>
> -      if (std::error_code EC =<br>
> -              CFR->template getFuncName<Endian>(ProfileNames, FuncName))<br>
> -        return EC;<br>
> -      Records.push_back(BinaryCoverageReader::ProfileMappingRecord(<br>
> -          Version, FuncName, FuncHash, Mapping, FilenamesBegin,<br>
> -          Filenames.size() - FilenamesBegin));<br>
> -      CFR++;<br>
> -    }<br>
> -    return std::error_code();<br>
> -  }<br>
> -};<br>
> -} // end anonymous namespace<br>
> -<br>
> -template <class IntPtrT, support::endianness Endian><br>
> -std::unique_ptr<CovMapFuncRecordReader> CovMapFuncRecordReader::get(<br>
> -    coverage::CovMapVersion Version, InstrProfSymtab &P,<br>
> -    std::vector<BinaryCoverageReader::ProfileMappingRecord> &R,<br>
> -    std::vector<StringRef> &F) {<br>
> -  using namespace coverage;<br>
> -  switch (Version) {<br>
> -  case CovMapVersion::Version1:<br>
> -    return llvm::make_unique<VersionedCovMapFuncRecordReader<<br>
> -        CovMapVersion::Version1, IntPtrT, Endian>>(P, R, F);<br>
> -  case CovMapVersion::Version2:<br>
> -    // Decompress the name data.<br>
> -    P.create(P.getNameData());<br>
> -    return llvm::make_unique<VersionedCovMapFuncRecordReader<<br>
> -        CovMapVersion::Version2, IntPtrT, Endian>>(P, R, F);<br>
> -  }<br>
> -  llvm_unreachable("Unsupported version");<br>
> -}<br>
> -<br>
> -template <typename T, support::endianness Endian><br>
> -static std::error_code readCoverageMappingData(<br>
> -    InstrProfSymtab &ProfileNames, StringRef Data,<br>
> -    std::vector<BinaryCoverageReader::ProfileMappingRecord> &Records,<br>
> -    std::vector<StringRef> &Filenames) {<br>
> -  using namespace coverage;<br>
> -  // Read the records in the coverage data section.<br>
> -  auto CovHeader =<br>
> -      reinterpret_cast<const coverage::CovMapHeader *>(Data.data());<br>
> -  CovMapVersion Version = (CovMapVersion)CovHeader->getVersion<Endian>();<br>
> -  if (Version > coverage::CovMapVersion::CurrentVersion)<br>
> -    return coveragemap_error::unsupported_version;<br>
> -  std::unique_ptr<CovMapFuncRecordReader> Reader =<br>
> -      CovMapFuncRecordReader::get<T, Endian>(Version, ProfileNames, Records,<br>
> -                                             Filenames);<br>
> -  for (const char *Buf = Data.data(), *End = Buf + Data.size(); Buf < End;) {<br>
> -    if (std::error_code EC = Reader->readFunctionRecords(Buf, End))<br>
> -      return EC;<br>
> -  }<br>
> -  return std::error_code();<br>
> -}<br>
> -static const char *TestingFormatMagic = "llvmcovmtestdata";<br>
> -<br>
> -static std::error_code loadTestingFormat(StringRef Data,<br>
> -                                         InstrProfSymtab &ProfileNames,<br>
> -                                         StringRef &CoverageMapping,<br>
> -                                         uint8_t &BytesInAddress,<br>
> -                                         support::endianness &Endian) {<br>
> -  BytesInAddress = 8;<br>
> -  Endian = support::endianness::little;<br>
> -<br>
> -  Data = Data.substr(StringRef(TestingFormatMagic).size());<br>
> -  if (Data.size() < 1)<br>
> -    return coveragemap_error::truncated;<br>
> -  unsigned N = 0;<br>
> -  auto ProfileNamesSize =<br>
> -      decodeULEB128(reinterpret_cast<const uint8_t *>(Data.data()), &N);<br>
> -  if (N > Data.size())<br>
> -    return coveragemap_error::malformed;<br>
> -  Data = Data.substr(N);<br>
> -  if (Data.size() < 1)<br>
> -    return coveragemap_error::truncated;<br>
> -  N = 0;<br>
> -  uint64_t Address =<br>
> -      decodeULEB128(reinterpret_cast<const uint8_t *>(Data.data()), &N);<br>
> -  if (N > Data.size())<br>
> -    return coveragemap_error::malformed;<br>
> -  Data = Data.substr(N);<br>
> -  if (Data.size() < ProfileNamesSize)<br>
> -    return coveragemap_error::malformed;<br>
> -  ProfileNames.create(Data.substr(0, ProfileNamesSize), Address);<br>
> -  CoverageMapping = Data.substr(ProfileNamesSize);<br>
> -  return std::error_code();<br>
> -}<br>
> -<br>
> -static ErrorOr<SectionRef> lookupSection(ObjectFile &OF, StringRef Name) {<br>
> -  StringRef FoundName;<br>
> -  for (const auto &Section : OF.sections()) {<br>
> -    if (auto EC = Section.getName(FoundName))<br>
> -      return EC;<br>
> -    if (FoundName == Name)<br>
> -      return Section;<br>
> -  }<br>
> -  return coveragemap_error::no_data_found;<br>
> -}<br>
> -<br>
> -static std::error_code<br>
> -loadBinaryFormat(MemoryBufferRef ObjectBuffer, InstrProfSymtab &ProfileNames,<br>
> -                 StringRef &CoverageMapping, uint8_t &BytesInAddress,<br>
> -                 support::endianness &Endian, StringRef Arch) {<br>
> -  auto BinOrErr = object::createBinary(ObjectBuffer);<br>
> -  if (!BinOrErr)<br>
> -    return errorToErrorCode(BinOrErr.takeError());<br>
> -  auto Bin = std::move(BinOrErr.get());<br>
> -  std::unique_ptr<ObjectFile> OF;<br>
> -  if (auto *Universal = dyn_cast<object::MachOUniversalBinary>(Bin.get())) {<br>
> -    // If we have a universal binary, try to look up the object for the<br>
> -    // appropriate architecture.<br>
> -    auto ObjectFileOrErr = Universal->getObjectForArch(Arch);<br>
> -    if (std::error_code EC = ObjectFileOrErr.getError())<br>
> -      return EC;<br>
> -    OF = std::move(ObjectFileOrErr.get());<br>
> -  } else if (isa<object::ObjectFile>(Bin.get())) {<br>
> -    // For any other object file, upcast and take ownership.<br>
> -    OF.reset(cast<object::ObjectFile>(Bin.release()));<br>
> -    // If we've asked for a particular arch, make sure they match.<br>
> -    if (!Arch.empty() && OF->getArch() != Triple(Arch).getArch())<br>
> -      return object_error::arch_not_found;<br>
> -  } else<br>
> -    // We can only handle object files.<br>
> -    return coveragemap_error::malformed;<br>
> -<br>
> -  // The coverage uses native pointer sizes for the object it's written in.<br>
> -  BytesInAddress = OF->getBytesInAddress();<br>
> -  Endian = OF->isLittleEndian() ? support::endianness::little<br>
> -                                : support::endianness::big;<br>
> -<br>
> -  // Look for the sections that we are interested in.<br>
> -  auto NamesSection = lookupSection(*OF, getInstrProfNameSectionName(false));<br>
> -  if (auto EC = NamesSection.getError())<br>
> -    return EC;<br>
> -  auto CoverageSection =<br>
> -      lookupSection(*OF, getInstrProfCoverageSectionName(false));<br>
> -  if (auto EC = CoverageSection.getError())<br>
> -    return EC;<br>
> -<br>
> -  // Get the contents of the given sections.<br>
> -  if (std::error_code EC = CoverageSection->getContents(CoverageMapping))<br>
> -    return EC;<br>
> -  if (std::error_code EC = ProfileNames.create(*NamesSection))<br>
> -    return EC;<br>
> -<br>
> -  return std::error_code();<br>
> -}<br>
> -<br>
> -ErrorOr<std::unique_ptr<BinaryCoverageReader>><br>
> -BinaryCoverageReader::create(std::unique_ptr<MemoryBuffer> &ObjectBuffer,<br>
> -                             StringRef Arch) {<br>
> -  std::unique_ptr<BinaryCoverageReader> Reader(new BinaryCoverageReader());<br>
> -<br>
> -  StringRef Coverage;<br>
> -  uint8_t BytesInAddress;<br>
> -  support::endianness Endian;<br>
> -  std::error_code EC;<br>
> -  if (ObjectBuffer->getBuffer().startswith(TestingFormatMagic))<br>
> -    // This is a special format used for testing.<br>
> -    EC = loadTestingFormat(ObjectBuffer->getBuffer(), Reader->ProfileNames,<br>
> -                           Coverage, BytesInAddress, Endian);<br>
> -  else<br>
> -    EC = loadBinaryFormat(ObjectBuffer->getMemBufferRef(), Reader->ProfileNames,<br>
> -                          Coverage, BytesInAddress, Endian, Arch);<br>
> -  if (EC)<br>
> -    return EC;<br>
> -<br>
> -  if (BytesInAddress == 4 && Endian == support::endianness::little)<br>
> -    EC = readCoverageMappingData<uint32_t, support::endianness::little>(<br>
> -        Reader->ProfileNames, Coverage, Reader->MappingRecords,<br>
> -        Reader->Filenames);<br>
> -  else if (BytesInAddress == 4 && Endian == support::endianness::big)<br>
> -    EC = readCoverageMappingData<uint32_t, support::endianness::big>(<br>
> -        Reader->ProfileNames, Coverage, Reader->MappingRecords,<br>
> -        Reader->Filenames);<br>
> -  else if (BytesInAddress == 8 && Endian == support::endianness::little)<br>
> -    EC = readCoverageMappingData<uint64_t, support::endianness::little>(<br>
> -        Reader->ProfileNames, Coverage, Reader->MappingRecords,<br>
> -        Reader->Filenames);<br>
> -  else if (BytesInAddress == 8 && Endian == support::endianness::big)<br>
> -    EC = readCoverageMappingData<uint64_t, support::endianness::big>(<br>
> -        Reader->ProfileNames, Coverage, Reader->MappingRecords,<br>
> -        Reader->Filenames);<br>
> -  else<br>
> -    return coveragemap_error::malformed;<br>
> -  if (EC)<br>
> -    return EC;<br>
> -  return std::move(Reader);<br>
> -}<br>
> -<br>
> -std::error_code<br>
> -BinaryCoverageReader::readNextRecord(CoverageMappingRecord &Record) {<br>
> -  if (CurrentRecord >= MappingRecords.size())<br>
> -    return coveragemap_error::eof;<br>
> -<br>
> -  FunctionsFilenames.clear();<br>
> -  Expressions.clear();<br>
> -  MappingRegions.clear();<br>
> -  auto &R = MappingRecords[CurrentRecord];<br>
> -  RawCoverageMappingReader Reader(<br>
> -      R.CoverageMapping,<br>
> -      makeArrayRef(Filenames).slice(R.FilenamesBegin, R.FilenamesSize),<br>
> -      FunctionsFilenames, Expressions, MappingRegions);<br>
> -  if (auto Err = Reader.read())<br>
> -    return Err;<br>
> -<br>
> -  Record.FunctionName = R.FunctionName;<br>
> -  Record.FunctionHash = R.FunctionHash;<br>
> -  Record.Filenames = FunctionsFilenames;<br>
> -  Record.Expressions = Expressions;<br>
> -  Record.MappingRegions = MappingRegions;<br>
> -<br>
> -  ++CurrentRecord;<br>
> -  return std::error_code();<br>
> -}<br>
> Index: lib/ProfileData/CoverageMapping.cpp<br>
> ===================================================================<br>
> --- lib/ProfileData/CoverageMapping.cpp<br>
> +++ lib/ProfileData/CoverageMapping.cpp<br>
> @@ -1,527 +0,0 @@<br>
> -//=-- CoverageMapping.cpp - Code coverage mapping support ---------*- C++ -*-=//<br>
> -//<br>
> -//                     The LLVM Compiler Infrastructure<br>
> -//<br>
> -// This file is distributed under the University of Illinois Open Source<br>
> -// License. See LICENSE.TXT for details.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -//<br>
> -// This file contains support for clang's and llvm's instrumentation based<br>
> -// code coverage.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -<br>
> -#include "llvm/ProfileData/CoverageMapping.h"<br>
> -#include "llvm/ADT/DenseMap.h"<br>
> -#include "llvm/ADT/Optional.h"<br>
> -#include "llvm/ADT/SmallBitVector.h"<br>
> -#include "llvm/ProfileData/CoverageMappingReader.h"<br>
> -#include "llvm/ProfileData/InstrProfReader.h"<br>
> -#include "llvm/Support/Debug.h"<br>
> -#include "llvm/Support/Errc.h"<br>
> -#include "llvm/Support/ErrorHandling.h"<br>
> -#include "llvm/Support/ManagedStatic.h"<br>
> -#include "llvm/Support/Path.h"<br>
> -#include "llvm/Support/raw_ostream.h"<br>
> -<br>
> -using namespace llvm;<br>
> -using namespace coverage;<br>
> -<br>
> -#define DEBUG_TYPE "coverage-mapping"<br>
> -<br>
> -Counter CounterExpressionBuilder::get(const CounterExpression &E) {<br>
> -  auto It = ExpressionIndices.find(E);<br>
> -  if (It != ExpressionIndices.end())<br>
> -    return Counter::getExpression(It->second);<br>
> -  unsigned I = Expressions.size();<br>
> -  Expressions.push_back(E);<br>
> -  ExpressionIndices[E] = I;<br>
> -  return Counter::getExpression(I);<br>
> -}<br>
> -<br>
> -void CounterExpressionBuilder::extractTerms(<br>
> -    Counter C, int Sign, SmallVectorImpl<std::pair<unsigned, int>> &Terms) {<br>
> -  switch (C.getKind()) {<br>
> -  case Counter::Zero:<br>
> -    break;<br>
> -  case Counter::CounterValueReference:<br>
> -    Terms.push_back(std::make_pair(C.getCounterID(), Sign));<br>
> -    break;<br>
> -  case Counter::Expression:<br>
> -    const auto &E = Expressions[C.getExpressionID()];<br>
> -    extractTerms(E.LHS, Sign, Terms);<br>
> -    extractTerms(E.RHS, E.Kind == CounterExpression::Subtract ? -Sign : Sign,<br>
> -                 Terms);<br>
> -    break;<br>
> -  }<br>
> -}<br>
> -<br>
> -Counter CounterExpressionBuilder::simplify(Counter ExpressionTree) {<br>
> -  // Gather constant terms.<br>
> -  llvm::SmallVector<std::pair<unsigned, int>, 32> Terms;<br>
> -  extractTerms(ExpressionTree, +1, Terms);<br>
> -<br>
> -  // If there are no terms, this is just a zero. The algorithm below assumes at<br>
> -  // least one term.<br>
> -  if (Terms.size() == 0)<br>
> -    return Counter::getZero();<br>
> -<br>
> -  // Group the terms by counter ID.<br>
> -  std::sort(Terms.begin(), Terms.end(),<br>
> -            [](const std::pair<unsigned, int> &LHS,<br>
> -               const std::pair<unsigned, int> &RHS) {<br>
> -    return LHS.first < RHS.first;<br>
> -  });<br>
> -<br>
> -  // Combine terms by counter ID to eliminate counters that sum to zero.<br>
> -  auto Prev = Terms.begin();<br>
> -  for (auto I = Prev + 1, E = Terms.end(); I != E; ++I) {<br>
> -    if (I->first == Prev->first) {<br>
> -      Prev->second += I->second;<br>
> -      continue;<br>
> -    }<br>
> -    ++Prev;<br>
> -    *Prev = *I;<br>
> -  }<br>
> -  Terms.erase(++Prev, Terms.end());<br>
> -<br>
> -  Counter C;<br>
> -  // Create additions. We do this before subtractions to avoid constructs like<br>
> -  // ((0 - X) + Y), as opposed to (Y - X).<br>
> -  for (auto Term : Terms) {<br>
> -    if (Term.second <= 0)<br>
> -      continue;<br>
> -    for (int I = 0; I < Term.second; ++I)<br>
> -      if (C.isZero())<br>
> -        C = Counter::getCounter(Term.first);<br>
> -      else<br>
> -        C = get(CounterExpression(CounterExpression::Add, C,<br>
> -                                  Counter::getCounter(Term.first)));<br>
> -  }<br>
> -<br>
> -  // Create subtractions.<br>
> -  for (auto Term : Terms) {<br>
> -    if (Term.second >= 0)<br>
> -      continue;<br>
> -    for (int I = 0; I < -Term.second; ++I)<br>
> -      C = get(CounterExpression(CounterExpression::Subtract, C,<br>
> -                                Counter::getCounter(Term.first)));<br>
> -  }<br>
> -  return C;<br>
> -}<br>
> -<br>
> -Counter CounterExpressionBuilder::add(Counter LHS, Counter RHS) {<br>
> -  return simplify(get(CounterExpression(CounterExpression::Add, LHS, RHS)));<br>
> -}<br>
> -<br>
> -Counter CounterExpressionBuilder::subtract(Counter LHS, Counter RHS) {<br>
> -  return simplify(<br>
> -      get(CounterExpression(CounterExpression::Subtract, LHS, RHS)));<br>
> -}<br>
> -<br>
> -void CounterMappingContext::dump(const Counter &C,<br>
> -                                 llvm::raw_ostream &OS) const {<br>
> -  switch (C.getKind()) {<br>
> -  case Counter::Zero:<br>
> -    OS << '0';<br>
> -    return;<br>
> -  case Counter::CounterValueReference:<br>
> -    OS << '#' << C.getCounterID();<br>
> -    break;<br>
> -  case Counter::Expression: {<br>
> -    if (C.getExpressionID() >= Expressions.size())<br>
> -      return;<br>
> -    const auto &E = Expressions[C.getExpressionID()];<br>
> -    OS << '(';<br>
> -    dump(E.LHS, OS);<br>
> -    OS << (E.Kind == CounterExpression::Subtract ? " - " : " + ");<br>
> -    dump(E.RHS, OS);<br>
> -    OS << ')';<br>
> -    break;<br>
> -  }<br>
> -  }<br>
> -  if (CounterValues.empty())<br>
> -    return;<br>
> -  ErrorOr<int64_t> Value = evaluate(C);<br>
> -  if (!Value)<br>
> -    return;<br>
> -  OS << '[' << *Value << ']';<br>
> -}<br>
> -<br>
> -ErrorOr<int64_t> CounterMappingContext::evaluate(const Counter &C) const {<br>
> -  switch (C.getKind()) {<br>
> -  case Counter::Zero:<br>
> -    return 0;<br>
> -  case Counter::CounterValueReference:<br>
> -    if (C.getCounterID() >= CounterValues.size())<br>
> -      return make_error_code(errc::argument_out_of_domain);<br>
> -    return CounterValues[C.getCounterID()];<br>
> -  case Counter::Expression: {<br>
> -    if (C.getExpressionID() >= Expressions.size())<br>
> -      return make_error_code(errc::argument_out_of_domain);<br>
> -    const auto &E = Expressions[C.getExpressionID()];<br>
> -    ErrorOr<int64_t> LHS = evaluate(E.LHS);<br>
> -    if (!LHS)<br>
> -      return LHS;<br>
> -    ErrorOr<int64_t> RHS = evaluate(E.RHS);<br>
> -    if (!RHS)<br>
> -      return RHS;<br>
> -    return E.Kind == CounterExpression::Subtract ? *LHS - *RHS : *LHS + *RHS;<br>
> -  }<br>
> -  }<br>
> -  llvm_unreachable("Unhandled CounterKind");<br>
> -}<br>
> -<br>
> -void FunctionRecordIterator::skipOtherFiles() {<br>
> -  while (Current != Records.end() && !Filename.empty() &&<br>
> -         Filename != Current->Filenames[0])<br>
> -    ++Current;<br>
> -  if (Current == Records.end())<br>
> -    *this = FunctionRecordIterator();<br>
> -}<br>
> -<br>
> -ErrorOr<std::unique_ptr<CoverageMapping>><br>
> -CoverageMapping::load(CoverageMappingReader &CoverageReader,<br>
> -                      IndexedInstrProfReader &ProfileReader) {<br>
> -  auto Coverage = std::unique_ptr<CoverageMapping>(new CoverageMapping());<br>
> -<br>
> -  std::vector<uint64_t> Counts;<br>
> -  for (const auto &Record : CoverageReader) {<br>
> -    CounterMappingContext Ctx(Record.Expressions);<br>
> -<br>
> -    Counts.clear();<br>
> -    if (std::error_code EC = ProfileReader.getFunctionCounts(<br>
> -            Record.FunctionName, Record.FunctionHash, Counts)) {<br>
> -      if (EC == instrprof_error::hash_mismatch) {<br>
> -        Coverage->MismatchedFunctionCount++;<br>
> -        continue;<br>
> -      } else if (EC != instrprof_error::unknown_function)<br>
> -        return EC;<br>
> -      Counts.assign(Record.MappingRegions.size(), 0);<br>
> -    }<br>
> -    Ctx.setCounts(Counts);<br>
> -<br>
> -    assert(!Record.MappingRegions.empty() && "Function has no regions");<br>
> -<br>
> -    StringRef OrigFuncName = Record.FunctionName;<br>
> -    if (Record.Filenames.empty())<br>
> -      OrigFuncName = getFuncNameWithoutPrefix(OrigFuncName);<br>
> -    else<br>
> -      OrigFuncName =<br>
> -          getFuncNameWithoutPrefix(OrigFuncName, Record.Filenames[0]);<br>
> -    FunctionRecord Function(OrigFuncName, Record.Filenames);<br>
> -    for (const auto &Region : Record.MappingRegions) {<br>
> -      ErrorOr<int64_t> ExecutionCount = Ctx.evaluate(Region.Count);<br>
> -      if (!ExecutionCount)<br>
> -        break;<br>
> -      Function.pushRegion(Region, *ExecutionCount);<br>
> -    }<br>
> -    if (Function.CountedRegions.size() != Record.MappingRegions.size()) {<br>
> -      Coverage->MismatchedFunctionCount++;<br>
> -      continue;<br>
> -    }<br>
> -<br>
> -    Coverage->Functions.push_back(std::move(Function));<br>
> -  }<br>
> -<br>
> -  return std::move(Coverage);<br>
> -}<br>
> -<br>
> -ErrorOr<std::unique_ptr<CoverageMapping>><br>
> -CoverageMapping::load(StringRef ObjectFilename, StringRef ProfileFilename,<br>
> -                      StringRef Arch) {<br>
> -  auto CounterMappingBuff = MemoryBuffer::getFileOrSTDIN(ObjectFilename);<br>
> -  if (std::error_code EC = CounterMappingBuff.getError())<br>
> -    return EC;<br>
> -  auto CoverageReaderOrErr =<br>
> -      BinaryCoverageReader::create(CounterMappingBuff.get(), Arch);<br>
> -  if (std::error_code EC = CoverageReaderOrErr.getError())<br>
> -    return EC;<br>
> -  auto CoverageReader = std::move(CoverageReaderOrErr.get());<br>
> -  auto ProfileReaderOrErr = IndexedInstrProfReader::create(ProfileFilename);<br>
> -  if (auto EC = ProfileReaderOrErr.getError())<br>
> -    return EC;<br>
> -  auto ProfileReader = std::move(ProfileReaderOrErr.get());<br>
> -  return load(*CoverageReader, *ProfileReader);<br>
> -}<br>
> -<br>
> -namespace {<br>
> -/// \brief Distributes functions into instantiation sets.<br>
> -///<br>
> -/// An instantiation set is a collection of functions that have the same source<br>
> -/// code, ie, template functions specializations.<br>
> -class FunctionInstantiationSetCollector {<br>
> -  typedef DenseMap<std::pair<unsigned, unsigned>,<br>
> -                   std::vector<const FunctionRecord *>> MapT;<br>
> -  MapT InstantiatedFunctions;<br>
> -<br>
> -public:<br>
> -  void insert(const FunctionRecord &Function, unsigned FileID) {<br>
> -    auto I = Function.CountedRegions.begin(), E = Function.CountedRegions.end();<br>
> -    while (I != E && I->FileID != FileID)<br>
> -      ++I;<br>
> -    assert(I != E && "function does not cover the given file");<br>
> -    auto &Functions = InstantiatedFunctions[I->startLoc()];<br>
> -    Functions.push_back(&Function);<br>
> -  }<br>
> -<br>
> -  MapT::iterator begin() { return InstantiatedFunctions.begin(); }<br>
> -<br>
> -  MapT::iterator end() { return InstantiatedFunctions.end(); }<br>
> -};<br>
> -<br>
> -class SegmentBuilder {<br>
> -  std::vector<CoverageSegment> &Segments;<br>
> -  SmallVector<const CountedRegion *, 8> ActiveRegions;<br>
> -<br>
> -  SegmentBuilder(std::vector<CoverageSegment> &Segments) : Segments(Segments) {}<br>
> -<br>
> -  /// Start a segment with no count specified.<br>
> -  void startSegment(unsigned Line, unsigned Col) {<br>
> -    DEBUG(dbgs() << "Top level segment at " << Line << ":" << Col << "\n");<br>
> -    Segments.emplace_back(Line, Col, /*IsRegionEntry=*/false);<br>
> -  }<br>
> -<br>
> -  /// Start a segment with the given Region's count.<br>
> -  void startSegment(unsigned Line, unsigned Col, bool IsRegionEntry,<br>
> -                    const CountedRegion &Region) {<br>
> -    if (Segments.empty())<br>
> -      Segments.emplace_back(Line, Col, IsRegionEntry);<br>
> -    CoverageSegment S = Segments.back();<br>
> -    // Avoid creating empty regions.<br>
> -    if (S.Line != Line || S.Col != Col) {<br>
> -      Segments.emplace_back(Line, Col, IsRegionEntry);<br>
> -      S = Segments.back();<br>
> -    }<br>
> -    DEBUG(dbgs() << "Segment at " << Line << ":" << Col);<br>
> -    // Set this region's count.<br>
> -    if (Region.Kind != coverage::CounterMappingRegion::SkippedRegion) {<br>
> -      DEBUG(dbgs() << " with count " << Region.ExecutionCount);<br>
> -      Segments.back().setCount(Region.ExecutionCount);<br>
> -    }<br>
> -    DEBUG(dbgs() << "\n");<br>
> -  }<br>
> -<br>
> -  /// Start a segment for the given region.<br>
> -  void startSegment(const CountedRegion &Region) {<br>
> -    startSegment(Region.LineStart, Region.ColumnStart, true, Region);<br>
> -  }<br>
> -<br>
> -  /// Pop the top region off of the active stack, starting a new segment with<br>
> -  /// the containing Region's count.<br>
> -  void popRegion() {<br>
> -    const CountedRegion *Active = ActiveRegions.back();<br>
> -    unsigned Line = Active->LineEnd, Col = Active->ColumnEnd;<br>
> -    ActiveRegions.pop_back();<br>
> -    if (ActiveRegions.empty())<br>
> -      startSegment(Line, Col);<br>
> -    else<br>
> -      startSegment(Line, Col, false, *ActiveRegions.back());<br>
> -  }<br>
> -<br>
> -  void buildSegmentsImpl(ArrayRef<CountedRegion> Regions) {<br>
> -    const CountedRegion *PrevRegion = nullptr;<br>
> -    for (const auto &Region : Regions) {<br>
> -      // Pop any regions that end before this one starts.<br>
> -      while (!ActiveRegions.empty() &&<br>
> -             ActiveRegions.back()->endLoc() <= Region.startLoc())<br>
> -        popRegion();<br>
> -      if (PrevRegion && PrevRegion->startLoc() == Region.startLoc() &&<br>
> -          PrevRegion->endLoc() == Region.endLoc()) {<br>
> -        if (Region.Kind == coverage::CounterMappingRegion::CodeRegion)<br>
> -          Segments.back().addCount(Region.ExecutionCount);<br>
> -      } else {<br>
> -        // Add this region to the stack.<br>
> -        ActiveRegions.push_back(&Region);<br>
> -        startSegment(Region);<br>
> -      }<br>
> -      PrevRegion = &Region;<br>
> -    }<br>
> -    // Pop any regions that are left in the stack.<br>
> -    while (!ActiveRegions.empty())<br>
> -      popRegion();<br>
> -  }<br>
> -<br>
> -public:<br>
> -  /// Build a list of CoverageSegments from a sorted list of Regions.<br>
> -  static std::vector<CoverageSegment><br>
> -  buildSegments(ArrayRef<CountedRegion> Regions) {<br>
> -    std::vector<CoverageSegment> Segments;<br>
> -    SegmentBuilder Builder(Segments);<br>
> -    Builder.buildSegmentsImpl(Regions);<br>
> -    return Segments;<br>
> -  }<br>
> -};<br>
> -}<br>
> -<br>
> -std::vector<StringRef> CoverageMapping::getUniqueSourceFiles() const {<br>
> -  std::vector<StringRef> Filenames;<br>
> -  for (const auto &Function : getCoveredFunctions())<br>
> -    Filenames.insert(Filenames.end(), Function.Filenames.begin(),<br>
> -                     Function.Filenames.end());<br>
> -  std::sort(Filenames.begin(), Filenames.end());<br>
> -  auto Last = std::unique(Filenames.begin(), Filenames.end());<br>
> -  Filenames.erase(Last, Filenames.end());<br>
> -  return Filenames;<br>
> -}<br>
> -<br>
> -static SmallBitVector gatherFileIDs(StringRef SourceFile,<br>
> -                                    const FunctionRecord &Function) {<br>
> -  SmallBitVector FilenameEquivalence(Function.Filenames.size(), false);<br>
> -  for (unsigned I = 0, E = Function.Filenames.size(); I < E; ++I)<br>
> -    if (SourceFile == Function.Filenames[I])<br>
> -      FilenameEquivalence[I] = true;<br>
> -  return FilenameEquivalence;<br>
> -}<br>
> -<br>
> -/// Return the ID of the file where the definition of the function is located.<br>
> -static Optional<unsigned> findMainViewFileID(const FunctionRecord &Function) {<br>
> -  SmallBitVector IsNotExpandedFile(Function.Filenames.size(), true);<br>
> -  for (const auto &CR : Function.CountedRegions)<br>
> -    if (CR.Kind == CounterMappingRegion::ExpansionRegion)<br>
> -      IsNotExpandedFile[CR.ExpandedFileID] = false;<br>
> -  int I = IsNotExpandedFile.find_first();<br>
> -  if (I == -1)<br>
> -    return None;<br>
> -  return I;<br>
> -}<br>
> -<br>
> -/// Check if SourceFile is the file that contains the definition of<br>
> -/// the Function. Return the ID of the file in that case or None otherwise.<br>
> -static Optional<unsigned> findMainViewFileID(StringRef SourceFile,<br>
> -                                             const FunctionRecord &Function) {<br>
> -  Optional<unsigned> I = findMainViewFileID(Function);<br>
> -  if (I && SourceFile == Function.Filenames[*I])<br>
> -    return I;<br>
> -  return None;<br>
> -}<br>
> -<br>
> -/// Sort a nested sequence of regions from a single file.<br>
> -template <class It> static void sortNestedRegions(It First, It Last) {<br>
> -  std::sort(First, Last,<br>
> -            [](const CountedRegion &LHS, const CountedRegion &RHS) {<br>
> -    if (LHS.startLoc() == RHS.startLoc())<br>
> -      // When LHS completely contains RHS, we sort LHS first.<br>
> -      return RHS.endLoc() < LHS.endLoc();<br>
> -    return LHS.startLoc() < RHS.startLoc();<br>
> -  });<br>
> -}<br>
> -<br>
> -static bool isExpansion(const CountedRegion &R, unsigned FileID) {<br>
> -  return R.Kind == CounterMappingRegion::ExpansionRegion && R.FileID == FileID;<br>
> -}<br>
> -<br>
> -CoverageData CoverageMapping::getCoverageForFile(StringRef Filename) {<br>
> -  CoverageData FileCoverage(Filename);<br>
> -  std::vector<coverage::CountedRegion> Regions;<br>
> -<br>
> -  for (const auto &Function : Functions) {<br>
> -    auto MainFileID = findMainViewFileID(Filename, Function);<br>
> -    auto FileIDs = gatherFileIDs(Filename, Function);<br>
> -    for (const auto &CR : Function.CountedRegions)<br>
> -      if (FileIDs.test(CR.FileID)) {<br>
> -        Regions.push_back(CR);<br>
> -        if (MainFileID && isExpansion(CR, *MainFileID))<br>
> -          FileCoverage.Expansions.emplace_back(CR, Function);<br>
> -      }<br>
> -  }<br>
> -<br>
> -  sortNestedRegions(Regions.begin(), Regions.end());<br>
> -  DEBUG(dbgs() << "Emitting segments for file: " << Filename << "\n");<br>
> -  FileCoverage.Segments = SegmentBuilder::buildSegments(Regions);<br>
> -<br>
> -  return FileCoverage;<br>
> -}<br>
> -<br>
> -std::vector<const FunctionRecord *><br>
> -CoverageMapping::getInstantiations(StringRef Filename) {<br>
> -  FunctionInstantiationSetCollector InstantiationSetCollector;<br>
> -  for (const auto &Function : Functions) {<br>
> -    auto MainFileID = findMainViewFileID(Filename, Function);<br>
> -    if (!MainFileID)<br>
> -      continue;<br>
> -    InstantiationSetCollector.insert(Function, *MainFileID);<br>
> -  }<br>
> -<br>
> -  std::vector<const FunctionRecord *> Result;<br>
> -  for (const auto &InstantiationSet : InstantiationSetCollector) {<br>
> -    if (InstantiationSet.second.size() < 2)<br>
> -      continue;<br>
> -    Result.insert(Result.end(), InstantiationSet.second.begin(),<br>
> -                  InstantiationSet.second.end());<br>
> -  }<br>
> -  return Result;<br>
> -}<br>
> -<br>
> -CoverageData<br>
> -CoverageMapping::getCoverageForFunction(const FunctionRecord &Function) {<br>
> -  auto MainFileID = findMainViewFileID(Function);<br>
> -  if (!MainFileID)<br>
> -    return CoverageData();<br>
> -<br>
> -  CoverageData FunctionCoverage(Function.Filenames[*MainFileID]);<br>
> -  std::vector<coverage::CountedRegion> Regions;<br>
> -  for (const auto &CR : Function.CountedRegions)<br>
> -    if (CR.FileID == *MainFileID) {<br>
> -      Regions.push_back(CR);<br>
> -      if (isExpansion(CR, *MainFileID))<br>
> -        FunctionCoverage.Expansions.emplace_back(CR, Function);<br>
> -    }<br>
> -<br>
> -  sortNestedRegions(Regions.begin(), Regions.end());<br>
> -  DEBUG(dbgs() << "Emitting segments for function: " << Function.Name << "\n");<br>
> -  FunctionCoverage.Segments = SegmentBuilder::buildSegments(Regions);<br>
> -<br>
> -  return FunctionCoverage;<br>
> -}<br>
> -<br>
> -CoverageData<br>
> -CoverageMapping::getCoverageForExpansion(const ExpansionRecord &Expansion) {<br>
> -  CoverageData ExpansionCoverage(<br>
> -      Expansion.Function.Filenames[Expansion.FileID]);<br>
> -  std::vector<coverage::CountedRegion> Regions;<br>
> -  for (const auto &CR : Expansion.Function.CountedRegions)<br>
> -    if (CR.FileID == Expansion.FileID) {<br>
> -      Regions.push_back(CR);<br>
> -      if (isExpansion(CR, Expansion.FileID))<br>
> -        ExpansionCoverage.Expansions.emplace_back(CR, Expansion.Function);<br>
> -    }<br>
> -<br>
> -  sortNestedRegions(Regions.begin(), Regions.end());<br>
> -  DEBUG(dbgs() << "Emitting segments for expansion of file " << Expansion.FileID<br>
> -               << "\n");<br>
> -  ExpansionCoverage.Segments = SegmentBuilder::buildSegments(Regions);<br>
> -<br>
> -  return ExpansionCoverage;<br>
> -}<br>
> -<br>
> -namespace {<br>
> -class CoverageMappingErrorCategoryType : public std::error_category {<br>
> -  const char *name() const LLVM_NOEXCEPT override { return "llvm.coveragemap"; }<br>
> -  std::string message(int IE) const override {<br>
> -    auto E = static_cast<coveragemap_error>(IE);<br>
> -    switch (E) {<br>
> -    case coveragemap_error::success:<br>
> -      return "Success";<br>
> -    case coveragemap_error::eof:<br>
> -      return "End of File";<br>
> -    case coveragemap_error::no_data_found:<br>
> -      return "No coverage data found";<br>
> -    case coveragemap_error::unsupported_version:<br>
> -      return "Unsupported coverage format version";<br>
> -    case coveragemap_error::truncated:<br>
> -      return "Truncated coverage data";<br>
> -    case coveragemap_error::malformed:<br>
> -      return "Malformed coverage data";<br>
> -    }<br>
> -    llvm_unreachable("A value of coveragemap_error has no message.");<br>
> -  }<br>
> -};<br>
> -}<br>
> -<br>
> -static ManagedStatic<CoverageMappingErrorCategoryType> ErrorCategory;<br>
> -<br>
> -const std::error_category &llvm::coverage::coveragemap_category() {<br>
> -  return *ErrorCategory;<br>
> -}<br>
> Index: lib/ProfileData/Coverage/LLVMBuild.txt<br>
> ===================================================================<br>
> --- lib/ProfileData/Coverage/LLVMBuild.txt<br>
> +++ lib/ProfileData/Coverage/LLVMBuild.txt<br>
> @@ -0,0 +1,23 @@<br>
> +;===- ./lib/ProfileData/Coverage/LLVMBuild.txt -----------------*- Conf -*--===;<br>
> +;<br>
> +;                     The LLVM Compiler Infrastructure<br>
> +;<br>
> +; This file is distributed under the University of Illinois Open Source<br>
> +; License. See LICENSE.TXT for details.<br>
> +;<br>
> +;===------------------------------------------------------------------------===;<br>
> +;<br>
> +; This is an LLVMBuild description file for the components in this subdirectory.<br>
> +;<br>
> +; For more information on the LLVMBuild system, please see:<br>
> +;<br>
> +;   <a href="http://llvm.org/docs/LLVMBuild.html" rel="noreferrer" target="_blank">http://llvm.org/docs/LLVMBuild.html</a><br>
> +;<br>
> +;===------------------------------------------------------------------------===;<br>
> +<br>
> +[component_0]<br>
> +type = Library<br>
> +name = Coverage<br>
> +parent = ProfileData<br>
> +required_libraries = Core Object ProfileData Support<br>
> +<br>
> Index: lib/ProfileData/Coverage/CoverageMappingWriter.cpp<br>
> ===================================================================<br>
> --- lib/ProfileData/Coverage/CoverageMappingWriter.cpp<br>
> +++ lib/ProfileData/Coverage/CoverageMappingWriter.cpp<br>
> @@ -12,7 +12,7 @@<br>
>  //<br>
>  //===----------------------------------------------------------------------===//<br>
><br>
> -#include "llvm/ProfileData/CoverageMappingWriter.h"<br>
> +#include "llvm/ProfileData/Coverage/CoverageMappingWriter.h"<br>
>  #include "llvm/Support/LEB128.h"<br>
><br>
>  using namespace llvm;<br>
> Index: lib/ProfileData/Coverage/CoverageMappingReader.cpp<br>
> ===================================================================<br>
> --- lib/ProfileData/Coverage/CoverageMappingReader.cpp<br>
> +++ lib/ProfileData/Coverage/CoverageMappingReader.cpp<br>
> @@ -12,7 +12,7 @@<br>
>  //<br>
>  //===----------------------------------------------------------------------===//<br>
><br>
> -#include "llvm/ProfileData/CoverageMappingReader.h"<br>
> +#include "llvm/ProfileData/Coverage/CoverageMappingReader.h"<br>
>  #include "llvm/ADT/DenseSet.h"<br>
>  #include "llvm/Object/MachOUniversal.h"<br>
>  #include "llvm/Object/ObjectFile.h"<br>
> Index: lib/ProfileData/Coverage/CoverageMapping.cpp<br>
> ===================================================================<br>
> --- lib/ProfileData/Coverage/CoverageMapping.cpp<br>
> +++ lib/ProfileData/Coverage/CoverageMapping.cpp<br>
> @@ -12,11 +12,11 @@<br>
>  //<br>
>  //===----------------------------------------------------------------------===//<br>
><br>
> -#include "llvm/ProfileData/CoverageMapping.h"<br>
> +#include "llvm/ProfileData/Coverage/CoverageMapping.h"<br>
>  #include "llvm/ADT/DenseMap.h"<br>
>  #include "llvm/ADT/Optional.h"<br>
>  #include "llvm/ADT/SmallBitVector.h"<br>
> -#include "llvm/ProfileData/CoverageMappingReader.h"<br>
> +#include "llvm/ProfileData/Coverage/CoverageMappingReader.h"<br>
>  #include "llvm/ProfileData/InstrProfReader.h"<br>
>  #include "llvm/Support/Debug.h"<br>
>  #include "llvm/Support/Errc.h"<br>
> Index: lib/ProfileData/Coverage/CMakeLists.txt<br>
> ===================================================================<br>
> --- lib/ProfileData/Coverage/CMakeLists.txt<br>
> +++ lib/ProfileData/Coverage/CMakeLists.txt<br>
> @@ -0,0 +1,11 @@<br>
> +add_llvm_library(LLVMCoverage<br>
> +  CoverageMapping.cpp<br>
> +  CoverageMappingWriter.cpp<br>
> +  CoverageMappingReader.cpp<br>
> +<br>
> +  ADDITIONAL_HEADER_DIRS<br>
> +  ${LLVM_MAIN_INCLUDE_DIR}/llvm/ProfileData/Coverage<br>
> +<br>
> +  DEPENDS<br>
> +  intrinsics_gen<br>
> +  )<br>
> Index: lib/ProfileData/CMakeLists.txt<br>
> ===================================================================<br>
> --- lib/ProfileData/CMakeLists.txt<br>
> +++ lib/ProfileData/CMakeLists.txt<br>
> @@ -2,9 +2,6 @@<br>
>    InstrProf.cpp<br>
>    InstrProfReader.cpp<br>
>    InstrProfWriter.cpp<br>
> -  CoverageMapping.cpp<br>
> -  CoverageMappingWriter.cpp<br>
> -  CoverageMappingReader.cpp<br>
>    ProfileSummary.cpp<br>
>    SampleProf.cpp<br>
>    SampleProfReader.cpp<br>
> @@ -16,3 +13,5 @@<br>
>    DEPENDS<br>
>    intrinsics_gen<br>
>    )<br>
> +<br>
> +add_subdirectory(Coverage)<br>
> Index: include/llvm/ProfileData/CoverageMappingWriter.h<br>
> ===================================================================<br>
> --- include/llvm/ProfileData/CoverageMappingWriter.h<br>
> +++ include/llvm/ProfileData/CoverageMappingWriter.h<br>
> @@ -1,63 +0,0 @@<br>
> -//=-- CoverageMappingWriter.h - Code coverage mapping writer ------*- C++ -*-=//<br>
> -//<br>
> -//                     The LLVM Compiler Infrastructure<br>
> -//<br>
> -// This file is distributed under the University of Illinois Open Source<br>
> -// License. See LICENSE.TXT for details.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -//<br>
> -// This file contains support for writing coverage mapping data for<br>
> -// instrumentation based coverage.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -<br>
> -#ifndef LLVM_PROFILEDATA_COVERAGEMAPPINGWRITER_H<br>
> -#define LLVM_PROFILEDATA_COVERAGEMAPPINGWRITER_H<br>
> -<br>
> -#include "llvm/ADT/ArrayRef.h"<br>
> -#include "llvm/ADT/StringMap.h"<br>
> -#include "llvm/ProfileData/CoverageMapping.h"<br>
> -#include "llvm/Support/raw_ostream.h"<br>
> -<br>
> -namespace llvm {<br>
> -namespace coverage {<br>
> -<br>
> -/// \brief Writer of the filenames section for the instrumentation<br>
> -/// based code coverage.<br>
> -class CoverageFilenamesSectionWriter {<br>
> -  ArrayRef<StringRef> Filenames;<br>
> -<br>
> -public:<br>
> -  CoverageFilenamesSectionWriter(ArrayRef<StringRef> Filenames)<br>
> -      : Filenames(Filenames) {}<br>
> -<br>
> -  /// \brief Write encoded filenames to the given output stream.<br>
> -  void write(raw_ostream &OS);<br>
> -};<br>
> -<br>
> -/// \brief Writer for instrumentation based coverage mapping data.<br>
> -class CoverageMappingWriter {<br>
> -  ArrayRef<unsigned> VirtualFileMapping;<br>
> -  ArrayRef<CounterExpression> Expressions;<br>
> -  MutableArrayRef<CounterMappingRegion> MappingRegions;<br>
> -<br>
> -public:<br>
> -  CoverageMappingWriter(ArrayRef<unsigned> VirtualFileMapping,<br>
> -                        ArrayRef<CounterExpression> Expressions,<br>
> -                        MutableArrayRef<CounterMappingRegion> MappingRegions)<br>
> -      : VirtualFileMapping(VirtualFileMapping), Expressions(Expressions),<br>
> -        MappingRegions(MappingRegions) {}<br>
> -<br>
> -  CoverageMappingWriter(ArrayRef<CounterExpression> Expressions,<br>
> -                        MutableArrayRef<CounterMappingRegion> MappingRegions)<br>
> -      : Expressions(Expressions), MappingRegions(MappingRegions) {}<br>
> -<br>
> -  /// \brief Write encoded coverage mapping data to the given output stream.<br>
> -  void write(raw_ostream &OS);<br>
> -};<br>
> -<br>
> -} // end namespace coverage<br>
> -} // end namespace llvm<br>
> -<br>
> -#endif<br>
> Index: include/llvm/ProfileData/CoverageMappingReader.h<br>
> ===================================================================<br>
> --- include/llvm/ProfileData/CoverageMappingReader.h<br>
> +++ include/llvm/ProfileData/CoverageMappingReader.h<br>
> @@ -1,183 +0,0 @@<br>
> -//=-- CoverageMappingReader.h - Code coverage mapping reader ------*- C++ -*-=//<br>
> -//<br>
> -//                     The LLVM Compiler Infrastructure<br>
> -//<br>
> -// This file is distributed under the University of Illinois Open Source<br>
> -// License. See LICENSE.TXT for details.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -//<br>
> -// This file contains support for reading coverage mapping data for<br>
> -// instrumentation based coverage.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -<br>
> -#ifndef LLVM_PROFILEDATA_COVERAGEMAPPINGREADER_H<br>
> -#define LLVM_PROFILEDATA_COVERAGEMAPPINGREADER_H<br>
> -<br>
> -#include "llvm/ADT/ArrayRef.h"<br>
> -#include "llvm/ADT/StringRef.h"<br>
> -#include "llvm/ADT/Triple.h"<br>
> -#include "llvm/Object/ObjectFile.h"<br>
> -#include "llvm/ProfileData/CoverageMapping.h"<br>
> -#include "llvm/ProfileData/InstrProf.h"<br>
> -#include "llvm/Support/FileSystem.h"<br>
> -#include "llvm/Support/MemoryBuffer.h"<br>
> -#include <iterator><br>
> -<br>
> -namespace llvm {<br>
> -namespace coverage {<br>
> -<br>
> -class CoverageMappingReader;<br>
> -<br>
> -/// \brief Coverage mapping information for a single function.<br>
> -struct CoverageMappingRecord {<br>
> -  StringRef FunctionName;<br>
> -  uint64_t FunctionHash;<br>
> -  ArrayRef<StringRef> Filenames;<br>
> -  ArrayRef<CounterExpression> Expressions;<br>
> -  ArrayRef<CounterMappingRegion> MappingRegions;<br>
> -};<br>
> -<br>
> -/// \brief A file format agnostic iterator over coverage mapping data.<br>
> -class CoverageMappingIterator<br>
> -    : public std::iterator<std::input_iterator_tag, CoverageMappingRecord> {<br>
> -  CoverageMappingReader *Reader;<br>
> -  CoverageMappingRecord Record;<br>
> -<br>
> -  void increment();<br>
> -<br>
> -public:<br>
> -  CoverageMappingIterator() : Reader(nullptr) {}<br>
> -  CoverageMappingIterator(CoverageMappingReader *Reader) : Reader(Reader) {<br>
> -    increment();<br>
> -  }<br>
> -<br>
> -  CoverageMappingIterator &operator++() {<br>
> -    increment();<br>
> -    return *this;<br>
> -  }<br>
> -  bool operator==(const CoverageMappingIterator &RHS) {<br>
> -    return Reader == RHS.Reader;<br>
> -  }<br>
> -  bool operator!=(const CoverageMappingIterator &RHS) {<br>
> -    return Reader != RHS.Reader;<br>
> -  }<br>
> -  CoverageMappingRecord &operator*() { return Record; }<br>
> -  CoverageMappingRecord *operator->() { return &Record; }<br>
> -};<br>
> -<br>
> -class CoverageMappingReader {<br>
> -public:<br>
> -  virtual std::error_code readNextRecord(CoverageMappingRecord &Record) = 0;<br>
> -  CoverageMappingIterator begin() { return CoverageMappingIterator(this); }<br>
> -  CoverageMappingIterator end() { return CoverageMappingIterator(); }<br>
> -  virtual ~CoverageMappingReader() {}<br>
> -};<br>
> -<br>
> -/// \brief Base class for the raw coverage mapping and filenames data readers.<br>
> -class RawCoverageReader {<br>
> -protected:<br>
> -  StringRef Data;<br>
> -<br>
> -  RawCoverageReader(StringRef Data) : Data(Data) {}<br>
> -<br>
> -  std::error_code readULEB128(uint64_t &Result);<br>
> -  std::error_code readIntMax(uint64_t &Result, uint64_t MaxPlus1);<br>
> -  std::error_code readSize(uint64_t &Result);<br>
> -  std::error_code readString(StringRef &Result);<br>
> -};<br>
> -<br>
> -/// \brief Reader for the raw coverage filenames.<br>
> -class RawCoverageFilenamesReader : public RawCoverageReader {<br>
> -  std::vector<StringRef> &Filenames;<br>
> -<br>
> -  RawCoverageFilenamesReader(const RawCoverageFilenamesReader &) = delete;<br>
> -  RawCoverageFilenamesReader &<br>
> -  operator=(const RawCoverageFilenamesReader &) = delete;<br>
> -<br>
> -public:<br>
> -  RawCoverageFilenamesReader(StringRef Data, std::vector<StringRef> &Filenames)<br>
> -      : RawCoverageReader(Data), Filenames(Filenames) {}<br>
> -<br>
> -  std::error_code read();<br>
> -};<br>
> -<br>
> -/// \brief Reader for the raw coverage mapping data.<br>
> -class RawCoverageMappingReader : public RawCoverageReader {<br>
> -  ArrayRef<StringRef> TranslationUnitFilenames;<br>
> -  std::vector<StringRef> &Filenames;<br>
> -  std::vector<CounterExpression> &Expressions;<br>
> -  std::vector<CounterMappingRegion> &MappingRegions;<br>
> -<br>
> -  RawCoverageMappingReader(const RawCoverageMappingReader &) = delete;<br>
> -  RawCoverageMappingReader &<br>
> -  operator=(const RawCoverageMappingReader &) = delete;<br>
> -<br>
> -public:<br>
> -  RawCoverageMappingReader(StringRef MappingData,<br>
> -                           ArrayRef<StringRef> TranslationUnitFilenames,<br>
> -                           std::vector<StringRef> &Filenames,<br>
> -                           std::vector<CounterExpression> &Expressions,<br>
> -                           std::vector<CounterMappingRegion> &MappingRegions)<br>
> -      : RawCoverageReader(MappingData),<br>
> -        TranslationUnitFilenames(TranslationUnitFilenames),<br>
> -        Filenames(Filenames), Expressions(Expressions),<br>
> -        MappingRegions(MappingRegions) {}<br>
> -<br>
> -  std::error_code read();<br>
> -<br>
> -private:<br>
> -  std::error_code decodeCounter(unsigned Value, Counter &C);<br>
> -  std::error_code readCounter(Counter &C);<br>
> -  std::error_code<br>
> -  readMappingRegionsSubArray(std::vector<CounterMappingRegion> &MappingRegions,<br>
> -                             unsigned InferredFileID, size_t NumFileIDs);<br>
> -};<br>
> -<br>
> -/// \brief Reader for the coverage mapping data that is emitted by the<br>
> -/// frontend and stored in an object file.<br>
> -class BinaryCoverageReader : public CoverageMappingReader {<br>
> -public:<br>
> -  struct ProfileMappingRecord {<br>
> -    CovMapVersion Version;<br>
> -    StringRef FunctionName;<br>
> -    uint64_t FunctionHash;<br>
> -    StringRef CoverageMapping;<br>
> -    size_t FilenamesBegin;<br>
> -    size_t FilenamesSize;<br>
> -<br>
> -    ProfileMappingRecord(CovMapVersion Version, StringRef FunctionName,<br>
> -                         uint64_t FunctionHash, StringRef CoverageMapping,<br>
> -                         size_t FilenamesBegin, size_t FilenamesSize)<br>
> -        : Version(Version), FunctionName(FunctionName),<br>
> -          FunctionHash(FunctionHash), CoverageMapping(CoverageMapping),<br>
> -          FilenamesBegin(FilenamesBegin), FilenamesSize(FilenamesSize) {}<br>
> -  };<br>
> -<br>
> -private:<br>
> -  std::vector<StringRef> Filenames;<br>
> -  std::vector<ProfileMappingRecord> MappingRecords;<br>
> -  InstrProfSymtab ProfileNames;<br>
> -  size_t CurrentRecord;<br>
> -  std::vector<StringRef> FunctionsFilenames;<br>
> -  std::vector<CounterExpression> Expressions;<br>
> -  std::vector<CounterMappingRegion> MappingRegions;<br>
> -<br>
> -  BinaryCoverageReader(const BinaryCoverageReader &) = delete;<br>
> -  BinaryCoverageReader &operator=(const BinaryCoverageReader &) = delete;<br>
> -<br>
> -  BinaryCoverageReader() : CurrentRecord(0) {}<br>
> -<br>
> -public:<br>
> -  static ErrorOr<std::unique_ptr<BinaryCoverageReader>><br>
> -  create(std::unique_ptr<MemoryBuffer> &ObjectBuffer,<br>
> -         StringRef Arch);<br>
> -<br>
> -  std::error_code readNextRecord(CoverageMappingRecord &Record) override;<br>
> -};<br>
> -<br>
> -} // end namespace coverage<br>
> -} // end namespace llvm<br>
> -<br>
> -#endif<br>
> Index: include/llvm/ProfileData/CoverageMapping.h<br>
> ===================================================================<br>
> --- include/llvm/ProfileData/CoverageMapping.h<br>
> +++ include/llvm/ProfileData/CoverageMapping.h<br>
> @@ -1,621 +0,0 @@<br>
> -//=-- CoverageMapping.h - Code coverage mapping support ---------*- C++ -*-=//<br>
> -//<br>
> -//                     The LLVM Compiler Infrastructure<br>
> -//<br>
> -// This file is distributed under the University of Illinois Open Source<br>
> -// License. See LICENSE.TXT for details.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -//<br>
> -// Code coverage mapping data is generated by clang and read by<br>
> -// llvm-cov to show code coverage statistics for a file.<br>
> -//<br>
> -//===----------------------------------------------------------------------===//<br>
> -<br>
> -#ifndef LLVM_PROFILEDATA_COVERAGEMAPPING_H_<br>
> -#define LLVM_PROFILEDATA_COVERAGEMAPPING_H_<br>
> -<br>
> -#include "llvm/ADT/ArrayRef.h"<br>
> -#include "llvm/ADT/DenseMap.h"<br>
> -#include "llvm/ADT/Hashing.h"<br>
> -#include "llvm/ADT/Triple.h"<br>
> -#include "llvm/ADT/iterator.h"<br>
> -#include "llvm/ProfileData/InstrProf.h"<br>
> -#include "llvm/Support/Debug.h"<br>
> -#include "llvm/Support/Endian.h"<br>
> -#include "llvm/Support/ErrorOr.h"<br>
> -#include "llvm/Support/raw_ostream.h"<br>
> -#include <system_error><br>
> -#include <tuple><br>
> -<br>
> -namespace llvm {<br>
> -namespace coverage {<br>
> -enum class coveragemap_error {<br>
> -  success = 0,<br>
> -  eof,<br>
> -  no_data_found,<br>
> -  unsupported_version,<br>
> -  truncated,<br>
> -  malformed<br>
> -};<br>
> -} // end of coverage namespace.<br>
> -}<br>
> -<br>
> -namespace std {<br>
> -template <><br>
> -struct is_error_code_enum<llvm::coverage::coveragemap_error> : std::true_type {<br>
> -};<br>
> -}<br>
> -<br>
> -namespace llvm {<br>
> -class IndexedInstrProfReader;<br>
> -namespace coverage {<br>
> -<br>
> -class CoverageMappingReader;<br>
> -<br>
> -class CoverageMapping;<br>
> -struct CounterExpressions;<br>
> -<br>
> -/// \brief A Counter is an abstract value that describes how to compute the<br>
> -/// execution count for a region of code using the collected profile count data.<br>
> -struct Counter {<br>
> -  enum CounterKind { Zero, CounterValueReference, Expression };<br>
> -  static const unsigned EncodingTagBits = 2;<br>
> -  static const unsigned EncodingTagMask = 0x3;<br>
> -  static const unsigned EncodingCounterTagAndExpansionRegionTagBits =<br>
> -      EncodingTagBits + 1;<br>
> -<br>
> -private:<br>
> -  CounterKind Kind;<br>
> -  unsigned ID;<br>
> -<br>
> -  Counter(CounterKind Kind, unsigned ID) : Kind(Kind), ID(ID) {}<br>
> -<br>
> -public:<br>
> -  Counter() : Kind(Zero), ID(0) {}<br>
> -<br>
> -  CounterKind getKind() const { return Kind; }<br>
> -<br>
> -  bool isZero() const { return Kind == Zero; }<br>
> -<br>
> -  bool isExpression() const { return Kind == Expression; }<br>
> -<br>
> -  unsigned getCounterID() const { return ID; }<br>
> -<br>
> -  unsigned getExpressionID() const { return ID; }<br>
> -<br>
> -  friend bool operator==(const Counter &LHS, const Counter &RHS) {<br>
> -    return LHS.Kind == RHS.Kind && <a href="http://LHS.ID" rel="noreferrer" target="_blank">LHS.ID</a> == <a href="http://RHS.ID" rel="noreferrer" target="_blank">RHS.ID</a>;<br>
> -  }<br>
> -<br>
> -  friend bool operator!=(const Counter &LHS, const Counter &RHS) {<br>
> -    return !(LHS == RHS);<br>
> -  }<br>
> -<br>
> -  friend bool operator<(const Counter &LHS, const Counter &RHS) {<br>
> -    return std::tie(LHS.Kind, <a href="http://LHS.ID" rel="noreferrer" target="_blank">LHS.ID</a>) < std::tie(RHS.Kind, <a href="http://RHS.ID" rel="noreferrer" target="_blank">RHS.ID</a>);<br>
> -  }<br>
> -<br>
> -  /// \brief Return the counter that represents the number zero.<br>
> -  static Counter getZero() { return Counter(); }<br>
> -<br>
> -  /// \brief Return the counter that corresponds to a specific profile counter.<br>
> -  static Counter getCounter(unsigned CounterId) {<br>
> -    return Counter(CounterValueReference, CounterId);<br>
> -  }<br>
> -<br>
> -  /// \brief Return the counter that corresponds to a specific<br>
> -  /// addition counter expression.<br>
> -  static Counter getExpression(unsigned ExpressionId) {<br>
> -    return Counter(Expression, ExpressionId);<br>
> -  }<br>
> -};<br>
> -<br>
> -/// \brief A Counter expression is a value that represents an arithmetic<br>
> -/// operation with two counters.<br>
> -struct CounterExpression {<br>
> -  enum ExprKind { Subtract, Add };<br>
> -  ExprKind Kind;<br>
> -  Counter LHS, RHS;<br>
> -<br>
> -  CounterExpression(ExprKind Kind, Counter LHS, Counter RHS)<br>
> -      : Kind(Kind), LHS(LHS), RHS(RHS) {}<br>
> -};<br>
> -<br>
> -/// \brief A Counter expression builder is used to construct the<br>
> -/// counter expressions. It avoids unnecessary duplication<br>
> -/// and simplifies algebraic expressions.<br>
> -class CounterExpressionBuilder {<br>
> -  /// \brief A list of all the counter expressions<br>
> -  std::vector<CounterExpression> Expressions;<br>
> -  /// \brief A lookup table for the index of a given expression.<br>
> -  llvm::DenseMap<CounterExpression, unsigned> ExpressionIndices;<br>
> -<br>
> -  /// \brief Return the counter which corresponds to the given expression.<br>
> -  ///<br>
> -  /// If the given expression is already stored in the builder, a counter<br>
> -  /// that references that expression is returned. Otherwise, the given<br>
> -  /// expression is added to the builder's collection of expressions.<br>
> -  Counter get(const CounterExpression &E);<br>
> -<br>
> -  /// \brief Gather the terms of the expression tree for processing.<br>
> -  ///<br>
> -  /// This collects each addition and subtraction referenced by the counter into<br>
> -  /// a sequence that can be sorted and combined to build a simplified counter<br>
> -  /// expression.<br>
> -  void extractTerms(Counter C, int Sign,<br>
> -                    SmallVectorImpl<std::pair<unsigned, int>> &Terms);<br>
> -<br>
> -  /// \brief Simplifies the given expression tree<br>
> -  /// by getting rid of algebraically redundant operations.<br>
> -  Counter simplify(Counter ExpressionTree);<br>
> -<br>
> -public:<br>
> -  ArrayRef<CounterExpression> getExpressions() const { return Expressions; }<br>
> -<br>
> -  /// \brief Return a counter that represents the expression<br>
> -  /// that adds LHS and RHS.<br>
> -  Counter add(Counter LHS, Counter RHS);<br>
> -<br>
> -  /// \brief Return a counter that represents the expression<br>
> -  /// that subtracts RHS from LHS.<br>
> -  Counter subtract(Counter LHS, Counter RHS);<br>
> -};<br>
> -<br>
> -/// \brief A Counter mapping region associates a source range with<br>
> -/// a specific counter.<br>
> -struct CounterMappingRegion {<br>
> -  enum RegionKind {<br>
> -    /// \brief A CodeRegion associates some code with a counter<br>
> -    CodeRegion,<br>
> -<br>
> -    /// \brief An ExpansionRegion represents a file expansion region that<br>
> -    /// associates a source range with the expansion of a virtual source file,<br>
> -    /// such as for a macro instantiation or #include file.<br>
> -    ExpansionRegion,<br>
> -<br>
> -    /// \brief A SkippedRegion represents a source range with code that<br>
> -    /// was skipped by a preprocessor or similar means.<br>
> -    SkippedRegion<br>
> -  };<br>
> -<br>
> -  Counter Count;<br>
> -  unsigned FileID, ExpandedFileID;<br>
> -  unsigned LineStart, ColumnStart, LineEnd, ColumnEnd;<br>
> -  RegionKind Kind;<br>
> -<br>
> -  CounterMappingRegion(Counter Count, unsigned FileID, unsigned ExpandedFileID,<br>
> -                       unsigned LineStart, unsigned ColumnStart,<br>
> -                       unsigned LineEnd, unsigned ColumnEnd, RegionKind Kind)<br>
> -      : Count(Count), FileID(FileID), ExpandedFileID(ExpandedFileID),<br>
> -        LineStart(LineStart), ColumnStart(ColumnStart), LineEnd(LineEnd),<br>
> -        ColumnEnd(ColumnEnd), Kind(Kind) {}<br>
> -<br>
> -  static CounterMappingRegion<br>
> -  makeRegion(Counter Count, unsigned FileID, unsigned LineStart,<br>
> -             unsigned ColumnStart, unsigned LineEnd, unsigned ColumnEnd) {<br>
> -    return CounterMappingRegion(Count, FileID, 0, LineStart, ColumnStart,<br>
> -                                LineEnd, ColumnEnd, CodeRegion);<br>
> -  }<br>
> -<br>
> -  static CounterMappingRegion<br>
> -  makeExpansion(unsigned FileID, unsigned ExpandedFileID, unsigned LineStart,<br>
> -                unsigned ColumnStart, unsigned LineEnd, unsigned ColumnEnd) {<br>
> -    return CounterMappingRegion(Counter(), FileID, ExpandedFileID, LineStart,<br>
> -                                ColumnStart, LineEnd, ColumnEnd,<br>
> -                                ExpansionRegion);<br>
> -  }<br>
> -<br>
> -  static CounterMappingRegion<br>
> -  makeSkipped(unsigned FileID, unsigned LineStart, unsigned ColumnStart,<br>
> -              unsigned LineEnd, unsigned ColumnEnd) {<br>
> -    return CounterMappingRegion(Counter(), FileID, 0, LineStart, ColumnStart,<br>
> -                                LineEnd, ColumnEnd, SkippedRegion);<br>
> -  }<br>
> -<br>
> -<br>
> -  inline std::pair<unsigned, unsigned> startLoc() const {<br>
> -    return std::pair<unsigned, unsigned>(LineStart, ColumnStart);<br>
> -  }<br>
> -<br>
> -  inline std::pair<unsigned, unsigned> endLoc() const {<br>
> -    return std::pair<unsigned, unsigned>(LineEnd, ColumnEnd);<br>
> -  }<br>
> -<br>
> -  bool operator<(const CounterMappingRegion &Other) const {<br>
> -    if (FileID != Other.FileID)<br>
> -      return FileID < Other.FileID;<br>
> -    return startLoc() < Other.startLoc();<br>
> -  }<br>
> -<br>
> -  bool contains(const CounterMappingRegion &Other) const {<br>
> -    if (FileID != Other.FileID)<br>
> -      return false;<br>
> -    if (startLoc() > Other.startLoc())<br>
> -      return false;<br>
> -    if (endLoc() < Other.endLoc())<br>
> -      return false;<br>
> -    return true;<br>
> -  }<br>
> -};<br>
> -<br>
> -/// \brief Associates a source range with an execution count.<br>
> -struct CountedRegion : public CounterMappingRegion {<br>
> -  uint64_t ExecutionCount;<br>
> -<br>
> -  CountedRegion(const CounterMappingRegion &R, uint64_t ExecutionCount)<br>
> -      : CounterMappingRegion(R), ExecutionCount(ExecutionCount) {}<br>
> -};<br>
> -<br>
> -/// \brief A Counter mapping context is used to connect the counters,<br>
> -/// expressions and the obtained counter values.<br>
> -class CounterMappingContext {<br>
> -  ArrayRef<CounterExpression> Expressions;<br>
> -  ArrayRef<uint64_t> CounterValues;<br>
> -<br>
> -public:<br>
> -  CounterMappingContext(ArrayRef<CounterExpression> Expressions,<br>
> -                        ArrayRef<uint64_t> CounterValues = None)<br>
> -      : Expressions(Expressions), CounterValues(CounterValues) {}<br>
> -<br>
> -  void setCounts(ArrayRef<uint64_t> Counts) { CounterValues = Counts; }<br>
> -<br>
> -  void dump(const Counter &C, llvm::raw_ostream &OS) const;<br>
> -  void dump(const Counter &C) const { dump(C, dbgs()); }<br>
> -<br>
> -  /// \brief Return the number of times that a region of code associated with<br>
> -  /// this counter was executed.<br>
> -  ErrorOr<int64_t> evaluate(const Counter &C) const;<br>
> -};<br>
> -<br>
> -/// \brief Code coverage information for a single function.<br>
> -struct FunctionRecord {<br>
> -  /// \brief Raw function name.<br>
> -  std::string Name;<br>
> -  /// \brief Associated files.<br>
> -  std::vector<std::string> Filenames;<br>
> -  /// \brief Regions in the function along with their counts.<br>
> -  std::vector<CountedRegion> CountedRegions;<br>
> -  /// \brief The number of times this function was executed.<br>
> -  uint64_t ExecutionCount;<br>
> -<br>
> -  FunctionRecord(StringRef Name, ArrayRef<StringRef> Filenames)<br>
> -      : Name(Name), Filenames(Filenames.begin(), Filenames.end()) {}<br>
> -<br>
> -  void pushRegion(CounterMappingRegion Region, uint64_t Count) {<br>
> -    if (CountedRegions.empty())<br>
> -      ExecutionCount = Count;<br>
> -    CountedRegions.emplace_back(Region, Count);<br>
> -  }<br>
> -};<br>
> -<br>
> -/// \brief Iterator over Functions, optionally filtered to a single file.<br>
> -class FunctionRecordIterator<br>
> -    : public iterator_facade_base<FunctionRecordIterator,<br>
> -                                  std::forward_iterator_tag, FunctionRecord> {<br>
> -  ArrayRef<FunctionRecord> Records;<br>
> -  ArrayRef<FunctionRecord>::iterator Current;<br>
> -  StringRef Filename;<br>
> -<br>
> -  /// \brief Skip records whose primary file is not \c Filename.<br>
> -  void skipOtherFiles();<br>
> -<br>
> -public:<br>
> -  FunctionRecordIterator(ArrayRef<FunctionRecord> Records_,<br>
> -                         StringRef Filename = "")<br>
> -      : Records(Records_), Current(Records.begin()), Filename(Filename) {<br>
> -    skipOtherFiles();<br>
> -  }<br>
> -<br>
> -  FunctionRecordIterator() : Current(Records.begin()) {}<br>
> -<br>
> -  bool operator==(const FunctionRecordIterator &RHS) const {<br>
> -    return Current == RHS.Current && Filename == RHS.Filename;<br>
> -  }<br>
> -<br>
> -  const FunctionRecord &operator*() const { return *Current; }<br>
> -<br>
> -  FunctionRecordIterator &operator++() {<br>
> -    assert(Current != Records.end() && "incremented past end");<br>
> -    ++Current;<br>
> -    skipOtherFiles();<br>
> -    return *this;<br>
> -  }<br>
> -};<br>
> -<br>
> -/// \brief Coverage information for a macro expansion or #included file.<br>
> -///<br>
> -/// When covered code has pieces that can be expanded for more detail, such as a<br>
> -/// preprocessor macro use and its definition, these are represented as<br>
> -/// expansions whose coverage can be looked up independently.<br>
> -struct ExpansionRecord {<br>
> -  /// \brief The abstract file this expansion covers.<br>
> -  unsigned FileID;<br>
> -  /// \brief The region that expands to this record.<br>
> -  const CountedRegion &Region;<br>
> -  /// \brief Coverage for the expansion.<br>
> -  const FunctionRecord &Function;<br>
> -<br>
> -  ExpansionRecord(const CountedRegion &Region,<br>
> -                  const FunctionRecord &Function)<br>
> -      : FileID(Region.ExpandedFileID), Region(Region), Function(Function) {}<br>
> -};<br>
> -<br>
> -/// \brief The execution count information starting at a point in a file.<br>
> -///<br>
> -/// A sequence of CoverageSegments gives execution counts for a file in format<br>
> -/// that's simple to iterate through for processing.<br>
> -struct CoverageSegment {<br>
> -  /// \brief The line where this segment begins.<br>
> -  unsigned Line;<br>
> -  /// \brief The column where this segment begins.<br>
> -  unsigned Col;<br>
> -  /// \brief The execution count, or zero if no count was recorded.<br>
> -  uint64_t Count;<br>
> -  /// \brief When false, the segment was uninstrumented or skipped.<br>
> -  bool HasCount;<br>
> -  /// \brief Whether this enters a new region or returns to a previous count.<br>
> -  bool IsRegionEntry;<br>
> -<br>
> -  CoverageSegment(unsigned Line, unsigned Col, bool IsRegionEntry)<br>
> -      : Line(Line), Col(Col), Count(0), HasCount(false),<br>
> -        IsRegionEntry(IsRegionEntry) {}<br>
> -<br>
> -  CoverageSegment(unsigned Line, unsigned Col, uint64_t Count,<br>
> -                  bool IsRegionEntry)<br>
> -      : Line(Line), Col(Col), Count(Count), HasCount(true),<br>
> -        IsRegionEntry(IsRegionEntry) {}<br>
> -<br>
> -  friend bool operator==(const CoverageSegment &L, const CoverageSegment &R) {<br>
> -    return std::tie(L.Line, L.Col, L.Count, L.HasCount, L.IsRegionEntry) ==<br>
> -           std::tie(R.Line, R.Col, R.Count, R.HasCount, R.IsRegionEntry);<br>
> -  }<br>
> -<br>
> -  void setCount(uint64_t NewCount) {<br>
> -    Count = NewCount;<br>
> -    HasCount = true;<br>
> -  }<br>
> -<br>
> -  void addCount(uint64_t NewCount) { setCount(Count + NewCount); }<br>
> -};<br>
> -<br>
> -/// \brief Coverage information to be processed or displayed.<br>
> -///<br>
> -/// This represents the coverage of an entire file, expansion, or function. It<br>
> -/// provides a sequence of CoverageSegments to iterate through, as well as the<br>
> -/// list of expansions that can be further processed.<br>
> -class CoverageData {<br>
> -  std::string Filename;<br>
> -  std::vector<CoverageSegment> Segments;<br>
> -  std::vector<ExpansionRecord> Expansions;<br>
> -  friend class CoverageMapping;<br>
> -<br>
> -public:<br>
> -  CoverageData() {}<br>
> -<br>
> -  CoverageData(StringRef Filename) : Filename(Filename) {}<br>
> -<br>
> -  CoverageData(CoverageData &&RHS)<br>
> -      : Filename(std::move(RHS.Filename)), Segments(std::move(RHS.Segments)),<br>
> -        Expansions(std::move(RHS.Expansions)) {}<br>
> -<br>
> -  /// \brief Get the name of the file this data covers.<br>
> -  StringRef getFilename() { return Filename; }<br>
> -<br>
> -  std::vector<CoverageSegment>::iterator begin() { return Segments.begin(); }<br>
> -  std::vector<CoverageSegment>::iterator end() { return Segments.end(); }<br>
> -  bool empty() { return Segments.empty(); }<br>
> -<br>
> -  /// \brief Expansions that can be further processed.<br>
> -  std::vector<ExpansionRecord> getExpansions() { return Expansions; }<br>
> -};<br>
> -<br>
> -/// \brief The mapping of profile information to coverage data.<br>
> -///<br>
> -/// This is the main interface to get coverage information, using a profile to<br>
> -/// fill out execution counts.<br>
> -class CoverageMapping {<br>
> -  std::vector<FunctionRecord> Functions;<br>
> -  unsigned MismatchedFunctionCount;<br>
> -<br>
> -  CoverageMapping() : MismatchedFunctionCount(0) {}<br>
> -<br>
> -public:<br>
> -  /// \brief Load the coverage mapping using the given readers.<br>
> -  static ErrorOr<std::unique_ptr<CoverageMapping>><br>
> -  load(CoverageMappingReader &CoverageReader,<br>
> -       IndexedInstrProfReader &ProfileReader);<br>
> -<br>
> -  /// \brief Load the coverage mapping from the given files.<br>
> -  static ErrorOr<std::unique_ptr<CoverageMapping>><br>
> -  load(StringRef ObjectFilename, StringRef ProfileFilename,<br>
> -       StringRef Arch = StringRef());<br>
> -<br>
> -  /// \brief The number of functions that couldn't have their profiles mapped.<br>
> -  ///<br>
> -  /// This is a count of functions whose profile is out of date or otherwise<br>
> -  /// can't be associated with any coverage information.<br>
> -  unsigned getMismatchedCount() { return MismatchedFunctionCount; }<br>
> -<br>
> -  /// \brief Returns the list of files that are covered.<br>
> -  std::vector<StringRef> getUniqueSourceFiles() const;<br>
> -<br>
> -  /// \brief Get the coverage for a particular file.<br>
> -  ///<br>
> -  /// The given filename must be the name as recorded in the coverage<br>
> -  /// information. That is, only names returned from getUniqueSourceFiles will<br>
> -  /// yield a result.<br>
> -  CoverageData getCoverageForFile(StringRef Filename);<br>
> -<br>
> -  /// \brief Gets all of the functions covered by this profile.<br>
> -  iterator_range<FunctionRecordIterator> getCoveredFunctions() const {<br>
> -    return make_range(FunctionRecordIterator(Functions),<br>
> -                      FunctionRecordIterator());<br>
> -  }<br>
> -<br>
> -  /// \brief Gets all of the functions in a particular file.<br>
> -  iterator_range<FunctionRecordIterator><br>
> -  getCoveredFunctions(StringRef Filename) const {<br>
> -    return make_range(FunctionRecordIterator(Functions, Filename),<br>
> -                      FunctionRecordIterator());<br>
> -  }<br>
> -<br>
> -  /// \brief Get the list of function instantiations in the file.<br>
> -  ///<br>
> -  /// Functions that are instantiated more than once, such as C++ template<br>
> -  /// specializations, have distinct coverage records for each instantiation.<br>
> -  std::vector<const FunctionRecord *> getInstantiations(StringRef Filename);<br>
> -<br>
> -  /// \brief Get the coverage for a particular function.<br>
> -  CoverageData getCoverageForFunction(const FunctionRecord &Function);<br>
> -<br>
> -  /// \brief Get the coverage for an expansion within a coverage set.<br>
> -  CoverageData getCoverageForExpansion(const ExpansionRecord &Expansion);<br>
> -};<br>
> -<br>
> -const std::error_category &coveragemap_category();<br>
> -<br>
> -inline std::error_code make_error_code(coveragemap_error E) {<br>
> -  return std::error_code(static_cast<int>(E), coveragemap_category());<br>
> -}<br>
> -<br>
> -// Profile coverage map has the following layout:<br>
> -// [CoverageMapFileHeader]<br>
> -// [ArrayStart]<br>
> -//  [CovMapFunctionRecord]<br>
> -//  [CovMapFunctionRecord]<br>
> -//  ...<br>
> -// [ArrayEnd]<br>
> -// [Encoded Region Mapping Data]<br>
> -LLVM_PACKED_START<br>
> -template <class IntPtrT> struct CovMapFunctionRecordV1 {<br>
> -#define COVMAP_V1<br>
> -#define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Init) Type Name;<br>
> -#include "llvm/ProfileData/InstrProfData.inc"<br>
> -#undef COVMAP_V1<br>
> -<br>
> -  // Return the structural hash associated with the function.<br>
> -  template <support::endianness Endian> uint64_t getFuncHash() const {<br>
> -    return support::endian::byte_swap<uint64_t, Endian>(FuncHash);<br>
> -  }<br>
> -  // Return the coverage map data size for the funciton.<br>
> -  template <support::endianness Endian> uint32_t getDataSize() const {<br>
> -    return support::endian::byte_swap<uint32_t, Endian>(DataSize);<br>
> -  }<br>
> -  // Return function lookup key. The value is consider opaque.<br>
> -  template <support::endianness Endian> IntPtrT getFuncNameRef() const {<br>
> -    return support::endian::byte_swap<IntPtrT, Endian>(NamePtr);<br>
> -  }<br>
> -  // Return the PGO name of the function */<br>
> -  template <support::endianness Endian><br>
> -  std::error_code getFuncName(InstrProfSymtab &ProfileNames,<br>
> -                              StringRef &FuncName) const {<br>
> -    IntPtrT NameRef = getFuncNameRef<Endian>();<br>
> -    uint32_t NameS = support::endian::byte_swap<uint32_t, Endian>(NameSize);<br>
> -    FuncName = ProfileNames.getFuncName(NameRef, NameS);<br>
> -    if (NameS && FuncName.empty())<br>
> -      return coveragemap_error::malformed;<br>
> -    return std::error_code();<br>
> -  }<br>
> -};<br>
> -<br>
> -struct CovMapFunctionRecord {<br>
> -#define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Init) Type Name;<br>
> -#include "llvm/ProfileData/InstrProfData.inc"<br>
> -<br>
> -  // Return the structural hash associated with the function.<br>
> -  template <support::endianness Endian> uint64_t getFuncHash() const {<br>
> -    return support::endian::byte_swap<uint64_t, Endian>(FuncHash);<br>
> -  }<br>
> -  // Return the coverage map data size for the funciton.<br>
> -  template <support::endianness Endian> uint32_t getDataSize() const {<br>
> -    return support::endian::byte_swap<uint32_t, Endian>(DataSize);<br>
> -  }<br>
> -  // Return function lookup key. The value is consider opaque.<br>
> -  template <support::endianness Endian> uint64_t getFuncNameRef() const {<br>
> -    return support::endian::byte_swap<uint64_t, Endian>(NameRef);<br>
> -  }<br>
> -  // Return the PGO name of the function */<br>
> -  template <support::endianness Endian><br>
> -  std::error_code getFuncName(InstrProfSymtab &ProfileNames,<br>
> -                              StringRef &FuncName) const {<br>
> -    uint64_t NameRef = getFuncNameRef<Endian>();<br>
> -    FuncName = ProfileNames.getFuncName(NameRef);<br>
> -    return std::error_code();<br>
> -  }<br>
> -};<br>
> -<br>
> -// Per module coverage mapping data header, i.e. CoverageMapFileHeader<br>
> -// documented above.<br>
> -struct CovMapHeader {<br>
> -#define COVMAP_HEADER(Type, LLVMType, Name, Init) Type Name;<br>
> -#include "llvm/ProfileData/InstrProfData.inc"<br>
> -  template <support::endianness Endian> uint32_t getNRecords() const {<br>
> -    return support::endian::byte_swap<uint32_t, Endian>(NRecords);<br>
> -  }<br>
> -  template <support::endianness Endian> uint32_t getFilenamesSize() const {<br>
> -    return support::endian::byte_swap<uint32_t, Endian>(FilenamesSize);<br>
> -  }<br>
> -  template <support::endianness Endian> uint32_t getCoverageSize() const {<br>
> -    return support::endian::byte_swap<uint32_t, Endian>(CoverageSize);<br>
> -  }<br>
> -  template <support::endianness Endian> uint32_t getVersion() const {<br>
> -    return support::endian::byte_swap<uint32_t, Endian>(Version);<br>
> -  }<br>
> -};<br>
> -<br>
> -LLVM_PACKED_END<br>
> -<br>
> -enum CovMapVersion {<br>
> -  Version1 = 0,<br>
> -  // Function's name reference from CovMapFuncRecord is changed from raw<br>
> -  // name string pointer to MD5 to support name section compression. Name<br>
> -  // section is also compressed.<br>
> -  Version2 = 1,<br>
> -  // The current version is Version2<br>
> -  CurrentVersion = INSTR_PROF_COVMAP_VERSION<br>
> -};<br>
> -<br>
> -template <int CovMapVersion, class IntPtrT> struct CovMapTraits {<br>
> -  typedef CovMapFunctionRecord CovMapFuncRecordType;<br>
> -  typedef uint64_t NameRefType;<br>
> -};<br>
> -<br>
> -template <class IntPtrT> struct CovMapTraits<CovMapVersion::Version1, IntPtrT> {<br>
> -  typedef CovMapFunctionRecordV1<IntPtrT> CovMapFuncRecordType;<br>
> -  typedef IntPtrT NameRefType;<br>
> -};<br>
> -<br>
> -} // end namespace coverage<br>
> -<br>
> -/// \brief Provide DenseMapInfo for CounterExpression<br>
> -template<> struct DenseMapInfo<coverage::CounterExpression> {<br>
> -  static inline coverage::CounterExpression getEmptyKey() {<br>
> -    using namespace coverage;<br>
> -    return CounterExpression(CounterExpression::ExprKind::Subtract,<br>
> -                             Counter::getCounter(~0U),<br>
> -                             Counter::getCounter(~0U));<br>
> -  }<br>
> -<br>
> -  static inline coverage::CounterExpression getTombstoneKey() {<br>
> -    using namespace coverage;<br>
> -    return CounterExpression(CounterExpression::ExprKind::Add,<br>
> -                             Counter::getCounter(~0U),<br>
> -                             Counter::getCounter(~0U));<br>
> -  }<br>
> -<br>
> -  static unsigned getHashValue(const coverage::CounterExpression &V) {<br>
> -    return static_cast<unsigned>(<br>
> -        hash_combine(V.Kind, V.LHS.getKind(), V.LHS.getCounterID(),<br>
> -                     V.RHS.getKind(), V.RHS.getCounterID()));<br>
> -  }<br>
> -<br>
> -  static bool isEqual(const coverage::CounterExpression &LHS,<br>
> -                      const coverage::CounterExpression &RHS) {<br>
> -    return LHS.Kind == RHS.Kind && LHS.LHS == RHS.LHS && LHS.RHS == RHS.RHS;<br>
> -  }<br>
> -};<br>
> -<br>
> -} // end namespace llvm<br>
> -<br>
> -#endif // LLVM_PROFILEDATA_COVERAGEMAPPING_H_<br>
> Index: include/llvm/ProfileData/Coverage/CoverageMappingWriter.h<br>
> ===================================================================<br>
> --- include/llvm/ProfileData/Coverage/CoverageMappingWriter.h<br>
> +++ include/llvm/ProfileData/Coverage/CoverageMappingWriter.h<br>
> @@ -17,7 +17,7 @@<br>
><br>
>  #include "llvm/ADT/ArrayRef.h"<br>
>  #include "llvm/ADT/StringMap.h"<br>
> -#include "llvm/ProfileData/CoverageMapping.h"<br>
> +#include "llvm/ProfileData/Coverage/CoverageMapping.h"<br>
>  #include "llvm/Support/raw_ostream.h"<br>
><br>
>  namespace llvm {<br>
> Index: include/llvm/ProfileData/Coverage/CoverageMappingReader.h<br>
> ===================================================================<br>
> --- include/llvm/ProfileData/Coverage/CoverageMappingReader.h<br>
> +++ include/llvm/ProfileData/Coverage/CoverageMappingReader.h<br>
> @@ -19,7 +19,7 @@<br>
>  #include "llvm/ADT/StringRef.h"<br>
>  #include "llvm/ADT/Triple.h"<br>
>  #include "llvm/Object/ObjectFile.h"<br>
> -#include "llvm/ProfileData/CoverageMapping.h"<br>
> +#include "llvm/ProfileData/Coverage/CoverageMapping.h"<br>
>  #include "llvm/ProfileData/InstrProf.h"<br>
>  #include "llvm/Support/FileSystem.h"<br>
>  #include "llvm/Support/MemoryBuffer.h"<br>
</blockquote></div><br></div>