diff options
Diffstat (limited to 'lib/ProfileData')
| -rw-r--r-- | lib/ProfileData/Coverage/CoverageMapping.cpp | 54 | ||||
| -rw-r--r-- | lib/ProfileData/InstrProf.cpp | 20 | 
2 files changed, 30 insertions, 44 deletions
diff --git a/lib/ProfileData/Coverage/CoverageMapping.cpp b/lib/ProfileData/Coverage/CoverageMapping.cpp index 4534e086b39e..8c5f136ea270 100644 --- a/lib/ProfileData/Coverage/CoverageMapping.cpp +++ b/lib/ProfileData/Coverage/CoverageMapping.cpp @@ -54,26 +54,26 @@ Counter CounterExpressionBuilder::get(const CounterExpression &E) {    return Counter::getExpression(I);  } -void CounterExpressionBuilder::extractTerms( -    Counter C, int Sign, SmallVectorImpl<std::pair<unsigned, int>> &Terms) { +void CounterExpressionBuilder::extractTerms(Counter C, int Factor, +                                            SmallVectorImpl<Term> &Terms) {    switch (C.getKind()) {    case Counter::Zero:      break;    case Counter::CounterValueReference: -    Terms.push_back(std::make_pair(C.getCounterID(), Sign)); +    Terms.emplace_back(C.getCounterID(), Factor);      break;    case Counter::Expression:      const auto &E = Expressions[C.getExpressionID()]; -    extractTerms(E.LHS, Sign, Terms); -    extractTerms(E.RHS, E.Kind == CounterExpression::Subtract ? -Sign : Sign, -                 Terms); +    extractTerms(E.LHS, Factor, Terms); +    extractTerms( +        E.RHS, E.Kind == CounterExpression::Subtract ? -Factor : Factor, Terms);      break;    }  }  Counter CounterExpressionBuilder::simplify(Counter ExpressionTree) {    // Gather constant terms. -  SmallVector<std::pair<unsigned, int>, 32> Terms; +  SmallVector<Term, 32> Terms;    extractTerms(ExpressionTree, +1, Terms);    // If there are no terms, this is just a zero. The algorithm below assumes at @@ -82,17 +82,15 @@ Counter CounterExpressionBuilder::simplify(Counter ExpressionTree) {      return Counter::getZero();    // Group the terms by counter ID. -  std::sort(Terms.begin(), Terms.end(), -            [](const std::pair<unsigned, int> &LHS, -               const std::pair<unsigned, int> &RHS) { -    return LHS.first < RHS.first; +  std::sort(Terms.begin(), Terms.end(), [](const Term &LHS, const Term &RHS) { +    return LHS.CounterID < RHS.CounterID;    });    // Combine terms by counter ID to eliminate counters that sum to zero.    auto Prev = Terms.begin();    for (auto I = Prev + 1, E = Terms.end(); I != E; ++I) { -    if (I->first == Prev->first) { -      Prev->second += I->second; +    if (I->CounterID == Prev->CounterID) { +      Prev->Factor += I->Factor;        continue;      }      ++Prev; @@ -103,24 +101,24 @@ Counter CounterExpressionBuilder::simplify(Counter ExpressionTree) {    Counter C;    // Create additions. We do this before subtractions to avoid constructs like    // ((0 - X) + Y), as opposed to (Y - X). -  for (auto Term : Terms) { -    if (Term.second <= 0) +  for (auto T : Terms) { +    if (T.Factor <= 0)        continue; -    for (int I = 0; I < Term.second; ++I) +    for (int I = 0; I < T.Factor; ++I)        if (C.isZero()) -        C = Counter::getCounter(Term.first); +        C = Counter::getCounter(T.CounterID);        else          C = get(CounterExpression(CounterExpression::Add, C, -                                  Counter::getCounter(Term.first))); +                                  Counter::getCounter(T.CounterID)));    }    // Create subtractions. -  for (auto Term : Terms) { -    if (Term.second >= 0) +  for (auto T : Terms) { +    if (T.Factor >= 0)        continue; -    for (int I = 0; I < -Term.second; ++I) +    for (int I = 0; I < -T.Factor; ++I)        C = get(CounterExpression(CounterExpression::Subtract, C, -                                Counter::getCounter(Term.first))); +                                Counter::getCounter(T.CounterID)));    }    return C;  } @@ -247,18 +245,6 @@ Error CoverageMapping::loadFunctionRecord(    return Error::success();  } -Expected<std::unique_ptr<CoverageMapping>> -CoverageMapping::load(CoverageMappingReader &CoverageReader, -                      IndexedInstrProfReader &ProfileReader) { -  auto Coverage = std::unique_ptr<CoverageMapping>(new CoverageMapping()); - -  for (const auto &Record : CoverageReader) -    if (Error E = Coverage->loadFunctionRecord(Record, ProfileReader)) -      return std::move(E); - -  return std::move(Coverage); -} -  Expected<std::unique_ptr<CoverageMapping>> CoverageMapping::load(      ArrayRef<std::unique_ptr<CoverageMappingReader>> CoverageReaders,      IndexedInstrProfReader &ProfileReader) { diff --git a/lib/ProfileData/InstrProf.cpp b/lib/ProfileData/InstrProf.cpp index 005061c4f068..a1d18724fcd5 100644 --- a/lib/ProfileData/InstrProf.cpp +++ b/lib/ProfileData/InstrProf.cpp @@ -504,9 +504,11 @@ void InstrProfRecord::mergeValueProfData(uint32_t ValueKind,      SIPE.addError(instrprof_error::value_site_count_mismatch);      return;    } +  if (!ThisNumValueSites) +    return;    std::vector<InstrProfValueSiteRecord> &ThisSiteRecords = -      getValueSitesForKind(ValueKind); -  std::vector<InstrProfValueSiteRecord> &OtherSiteRecords = +      getOrCreateValueSitesForKind(ValueKind); +  MutableArrayRef<InstrProfValueSiteRecord> OtherSiteRecords =        Src.getValueSitesForKind(ValueKind);    for (uint32_t I = 0; I < ThisNumValueSites; I++)      ThisSiteRecords[I].merge(SIPE, OtherSiteRecords[I], Weight); @@ -533,11 +535,8 @@ void InstrProfRecord::merge(InstrProfRecord &Other, uint64_t Weight) {  }  void InstrProfRecord::scaleValueProfData(uint32_t ValueKind, uint64_t Weight) { -  uint32_t ThisNumValueSites = getNumValueSites(ValueKind); -  std::vector<InstrProfValueSiteRecord> &ThisSiteRecords = -      getValueSitesForKind(ValueKind); -  for (uint32_t I = 0; I < ThisNumValueSites; I++) -    ThisSiteRecords[I].scale(SIPE, Weight); +  for (auto &R : getValueSitesForKind(ValueKind)) +    R.scale(SIPE, Weight);  }  void InstrProfRecord::scale(uint64_t Weight) { @@ -583,7 +582,7 @@ void InstrProfRecord::addValueData(uint32_t ValueKind, uint32_t Site,      VData[I].Value = remapValue(VData[I].Value, ValueKind, ValueMap);    }    std::vector<InstrProfValueSiteRecord> &ValueSites = -      getValueSitesForKind(ValueKind); +      getOrCreateValueSitesForKind(ValueKind);    if (N == 0)      ValueSites.emplace_back();    else @@ -642,8 +641,9 @@ static ValueProfRecordClosure InstrProfRecordClosure = {  // Wrapper implementation using the closure mechanism.  uint32_t ValueProfData::getSize(const InstrProfRecord &Record) { -  InstrProfRecordClosure.Record = &Record; -  return getValueProfDataSize(&InstrProfRecordClosure); +  auto Closure = InstrProfRecordClosure; +  Closure.Record = &Record; +  return getValueProfDataSize(&Closure);  }  // Wrapper implementation using the closure mechanism.  | 
