|
25 | 25 | #include "llvm/Support/ErrorHandling.h"
|
26 | 26 | #include "llvm/Support/ErrorOr.h"
|
27 | 27 | #include "llvm/Support/MD5.h"
|
| 28 | +#include "llvm/Support/MathExtras.h" |
28 | 29 | #include <cstdint>
|
29 | 30 | #include <list>
|
30 | 31 | #include <map>
|
@@ -410,13 +411,17 @@ struct InstrProfRecord {
|
410 | 411 | /// site: Site.
|
411 | 412 | inline uint32_t getNumValueDataForSite(uint32_t ValueKind,
|
412 | 413 | uint32_t Site) const;
|
413 |
| - /// Return the array of profiled values at \p Site. |
| 414 | + /// Return the array of profiled values at \p Site. If \p TotalC |
| 415 | + /// is not null, the total count of all target values at this site |
| 416 | + /// will be stored in \c *TotalC. |
414 | 417 | inline std::unique_ptr<InstrProfValueData[]>
|
415 | 418 | getValueForSite(uint32_t ValueKind, uint32_t Site,
|
416 |
| - uint64_t (*ValueMapper)(uint32_t, uint64_t) = nullptr) const; |
417 |
| - inline void |
418 |
| - getValueForSite(InstrProfValueData Dest[], uint32_t ValueKind, uint32_t Site, |
419 |
| - uint64_t (*ValueMapper)(uint32_t, uint64_t) = nullptr) const; |
| 419 | + uint64_t *TotalC = 0) const; |
| 420 | + /// Get the target value/counts of kind \p ValueKind collected at site |
| 421 | + /// \p Site and store the result in array \p Dest. Return the total |
| 422 | + /// counts of all target values at this site. |
| 423 | + inline uint64_t getValueForSite(InstrProfValueData Dest[], uint32_t ValueKind, |
| 424 | + uint32_t Site) const; |
420 | 425 | /// Reserve space for NumValueSites sites.
|
421 | 426 | inline void reserveSites(uint32_t ValueKind, uint32_t NumValueSites);
|
422 | 427 | /// Add ValueData for ValueKind at value Site.
|
@@ -505,29 +510,35 @@ uint32_t InstrProfRecord::getNumValueDataForSite(uint32_t ValueKind,
|
505 | 510 | return getValueSitesForKind(ValueKind)[Site].ValueData.size();
|
506 | 511 | }
|
507 | 512 |
|
508 |
| -std::unique_ptr<InstrProfValueData[]> InstrProfRecord::getValueForSite( |
509 |
| - uint32_t ValueKind, uint32_t Site, |
510 |
| - uint64_t (*ValueMapper)(uint32_t, uint64_t)) const { |
| 513 | +std::unique_ptr<InstrProfValueData[]> |
| 514 | +InstrProfRecord::getValueForSite(uint32_t ValueKind, uint32_t Site, |
| 515 | + uint64_t *TotalC) const { |
| 516 | + uint64_t Dummy; |
| 517 | + uint64_t &TotalCount = (TotalC == 0 ? Dummy : *TotalC); |
511 | 518 | uint32_t N = getNumValueDataForSite(ValueKind, Site);
|
512 |
| - if (N == 0) |
| 519 | + if (N == 0) { |
| 520 | + TotalCount = 0; |
513 | 521 | return std::unique_ptr<InstrProfValueData[]>(nullptr);
|
| 522 | + } |
514 | 523 |
|
515 | 524 | auto VD = llvm::make_unique<InstrProfValueData[]>(N);
|
516 |
| - getValueForSite(VD.get(), ValueKind, Site, ValueMapper); |
| 525 | + TotalCount = getValueForSite(VD.get(), ValueKind, Site); |
517 | 526 |
|
518 | 527 | return VD;
|
519 | 528 | }
|
520 | 529 |
|
521 |
| -void InstrProfRecord::getValueForSite(InstrProfValueData Dest[], |
522 |
| - uint32_t ValueKind, uint32_t Site, |
523 |
| - uint64_t (*ValueMapper)(uint32_t, |
524 |
| - uint64_t)) const { |
| 530 | +uint64_t InstrProfRecord::getValueForSite(InstrProfValueData Dest[], |
| 531 | + uint32_t ValueKind, |
| 532 | + uint32_t Site) const { |
525 | 533 | uint32_t I = 0;
|
| 534 | + uint64_t TotalCount = 0; |
526 | 535 | for (auto V : getValueSitesForKind(ValueKind)[Site].ValueData) {
|
527 |
| - Dest[I].Value = ValueMapper ? ValueMapper(ValueKind, V.Value) : V.Value; |
| 536 | + Dest[I].Value = V.Value; |
528 | 537 | Dest[I].Count = V.Count;
|
| 538 | + TotalCount = SaturatingAdd(TotalCount, V.Count); |
529 | 539 | I++;
|
530 | 540 | }
|
| 541 | + return TotalCount; |
531 | 542 | }
|
532 | 543 |
|
533 | 544 | void InstrProfRecord::reserveSites(uint32_t ValueKind, uint32_t NumValueSites) {
|
|
0 commit comments