diff options
author | Andrea Di Biagio <Andrea_DiBiagio@sn.scee.net> | 2019-02-20 14:53:18 +0000 |
---|---|---|
committer | Andrea Di Biagio <Andrea_DiBiagio@sn.scee.net> | 2019-02-20 14:53:18 +0000 |
commit | d882ad5e6efba7bc3059e450ec7c303acc40f0b0 (patch) | |
tree | 1eb637e7ce2895110d4c8aa42a2cd2dd096cda4c /llvm | |
parent | 14e15ec18dd23e75fe54a72dde203dc266390561 (diff) | |
download | bcm5719-llvm-d882ad5e6efba7bc3059e450ec7c303acc40f0b0.tar.gz bcm5719-llvm-d882ad5e6efba7bc3059e450ec7c303acc40f0b0.zip |
[MCA][ResourceManager] Add a table that maps processor resource indices to processor resource identifiers.
This patch adds a lookup table to speed up resource queries in the ResourceManager.
This patch also moves helper function 'getResourceStateIndex()' from
ResourceManager.cpp to Support.h, so that we can reuse that logic in the
SummaryView (and potentially other views in llvm-mca).
No functional change intended.
llvm-svn: 354470
Diffstat (limited to 'llvm')
-rw-r--r-- | llvm/include/llvm/MCA/HardwareUnits/ResourceManager.h | 6 | ||||
-rw-r--r-- | llvm/include/llvm/MCA/Support.h | 7 | ||||
-rw-r--r-- | llvm/lib/MCA/HardwareUnits/ResourceManager.cpp | 45 | ||||
-rw-r--r-- | llvm/tools/llvm-mca/Views/SummaryView.cpp | 14 | ||||
-rw-r--r-- | llvm/tools/llvm-mca/Views/SummaryView.h | 3 |
5 files changed, 47 insertions, 28 deletions
diff --git a/llvm/include/llvm/MCA/HardwareUnits/ResourceManager.h b/llvm/include/llvm/MCA/HardwareUnits/ResourceManager.h index 3addaaf4775..2f91185516f 100644 --- a/llvm/include/llvm/MCA/HardwareUnits/ResourceManager.h +++ b/llvm/include/llvm/MCA/HardwareUnits/ResourceManager.h @@ -334,9 +334,13 @@ class ResourceManager { // Used to quickly identify groups that own a particular resource unit. std::vector<uint64_t> Resource2Groups; - // A table to map processor resource IDs to processor resource masks. + // A table that maps processor resource IDs to processor resource masks. SmallVector<uint64_t, 8> ProcResID2Mask; + // A table that maps resource indices to actual processor resource IDs in the + // scheduling model. + SmallVector<unsigned, 8> ResIndex2ProcResID; + // Keeps track of which resources are busy, and how many cycles are left // before those become usable again. SmallDenseMap<ResourceRef, unsigned> BusyResources; diff --git a/llvm/include/llvm/MCA/Support.h b/llvm/include/llvm/MCA/Support.h index fc36ed492d1..1da097c9092 100644 --- a/llvm/include/llvm/MCA/Support.h +++ b/llvm/include/llvm/MCA/Support.h @@ -94,6 +94,13 @@ public: void computeProcResourceMasks(const MCSchedModel &SM, MutableArrayRef<uint64_t> Masks); +// Returns the index of the highest bit set. For resource masks, the position of +// the highest bit set can be used to construct a resource mask identifier. +inline unsigned getResourceStateIndex(uint64_t Mask) { + assert(Mask && "Processor Resource Mask cannot be zero!"); + return (std::numeric_limits<uint64_t>::digits - countLeadingZeros(Mask)) - 1; +} + /// Compute the reciprocal block throughput from a set of processor resource /// cycles. The reciprocal block throughput is computed as the MAX between: /// - NumMicroOps / DispatchWidth diff --git a/llvm/lib/MCA/HardwareUnits/ResourceManager.cpp b/llvm/lib/MCA/HardwareUnits/ResourceManager.cpp index 21e0271c852..06f2476353d 100644 --- a/llvm/lib/MCA/HardwareUnits/ResourceManager.cpp +++ b/llvm/lib/MCA/HardwareUnits/ResourceManager.cpp @@ -23,16 +23,10 @@ namespace mca { #define DEBUG_TYPE "llvm-mca" ResourceStrategy::~ResourceStrategy() = default; -// Returns the index of the highest bit set. For resource masks, the position of -// the highest bit set can be used to construct a resource mask identifier. -static unsigned getResourceStateIndex(uint64_t Mask) { - return std::numeric_limits<uint64_t>::digits - countLeadingZeros(Mask); -} - static uint64_t selectImpl(uint64_t CandidateMask, uint64_t &NextInSequenceMask) { // The upper bit set in CandidateMask identifies our next candidate resource. - CandidateMask = 1ULL << (getResourceStateIndex(CandidateMask) - 1); + CandidateMask = 1ULL << getResourceStateIndex(CandidateMask); NextInSequenceMask &= (CandidateMask | (CandidateMask - 1)); return CandidateMask; } @@ -74,7 +68,7 @@ ResourceState::ResourceState(const MCProcResourceDesc &Desc, unsigned Index, BufferSize(Desc.BufferSize), IsAGroup(countPopulation(ResourceMask) > 1) { if (IsAGroup) { ResourceSizeMask = - ResourceMask ^ 1ULL << (getResourceStateIndex(ResourceMask) - 1); + ResourceMask ^ 1ULL << getResourceStateIndex(ResourceMask); } else { ResourceSizeMask = (1ULL << Desc.NumUnits) - 1; } @@ -115,14 +109,21 @@ getStrategyFor(const ResourceState &RS) { } ResourceManager::ResourceManager(const MCSchedModel &SM) - : Resources(SM.getNumProcResourceKinds()), - Strategies(SM.getNumProcResourceKinds()), - Resource2Groups(SM.getNumProcResourceKinds(), 0), - ProcResID2Mask(SM.getNumProcResourceKinds()), ProcResUnitMask(0), - ReservedResourceGroups(0) { + : Resources(SM.getNumProcResourceKinds() - 1), + Strategies(SM.getNumProcResourceKinds() - 1), + Resource2Groups(SM.getNumProcResourceKinds() - 1, 0), + ProcResID2Mask(SM.getNumProcResourceKinds(), 0), + ResIndex2ProcResID(SM.getNumProcResourceKinds() - 1, 0), + ProcResUnitMask(0), ReservedResourceGroups(0) { computeProcResourceMasks(SM, ProcResID2Mask); - for (unsigned I = 0, E = SM.getNumProcResourceKinds(); I < E; ++I) { + // initialize vector ResIndex2ProcResID. + for (unsigned I = 1, E = SM.getNumProcResourceKinds(); I < E; ++I) { + unsigned Index = getResourceStateIndex(ProcResID2Mask[I]); + ResIndex2ProcResID[Index] = I; + } + + for (unsigned I = 1, E = SM.getNumProcResourceKinds(); I < E; ++I) { uint64_t Mask = ProcResID2Mask[I]; unsigned Index = getResourceStateIndex(Mask); Resources[Index] = @@ -130,7 +131,7 @@ ResourceManager::ResourceManager(const MCSchedModel &SM) Strategies[Index] = getStrategyFor(*Resources[Index]); } - for (unsigned I = 0, E = SM.getNumProcResourceKinds(); I < E; ++I) { + for (unsigned I = 1, E = SM.getNumProcResourceKinds(); I < E; ++I) { uint64_t Mask = ProcResID2Mask[I]; unsigned Index = getResourceStateIndex(Mask); const ResourceState &RS = *Resources[Index]; @@ -139,7 +140,7 @@ ResourceManager::ResourceManager(const MCSchedModel &SM) continue; } - uint64_t GroupMaskIdx = 1ULL << (Index - 1); + uint64_t GroupMaskIdx = 1ULL << Index; Mask -= GroupMaskIdx; while (Mask) { // Extract lowest set isolated bit. @@ -162,7 +163,7 @@ void ResourceManager::setCustomStrategyImpl(std::unique_ptr<ResourceStrategy> S, } unsigned ResourceManager::resolveResourceMask(uint64_t Mask) const { - return Resources[getResourceStateIndex(Mask)]->getProcResourceID(); + return ResIndex2ProcResID[getResourceStateIndex(Mask)]; } unsigned ResourceManager::getNumUnits(uint64_t ResourceID) const { @@ -332,18 +333,20 @@ void ResourceManager::cycleEvent(SmallVectorImpl<ResourceRef> &ResourcesFreed) { } void ResourceManager::reserveResource(uint64_t ResourceID) { - ResourceState &Resource = *Resources[getResourceStateIndex(ResourceID)]; + const unsigned Index = getResourceStateIndex(ResourceID); + ResourceState &Resource = *Resources[Index]; assert(Resource.isAResourceGroup() && !Resource.isReserved() && "Unexpected resource found!"); Resource.setReserved(); - ReservedResourceGroups ^= PowerOf2Floor(ResourceID); + ReservedResourceGroups ^= 1ULL << Index; } void ResourceManager::releaseResource(uint64_t ResourceID) { - ResourceState &Resource = *Resources[getResourceStateIndex(ResourceID)]; + const unsigned Index = getResourceStateIndex(ResourceID); + ResourceState &Resource = *Resources[Index]; Resource.clearReserved(); if (Resource.isAResourceGroup()) - ReservedResourceGroups ^= PowerOf2Floor(ResourceID); + ReservedResourceGroups ^= 1ULL << Index; } } // namespace mca diff --git a/llvm/tools/llvm-mca/Views/SummaryView.cpp b/llvm/tools/llvm-mca/Views/SummaryView.cpp index 55d73c6fcb1..1f14f3dcd91 100644 --- a/llvm/tools/llvm-mca/Views/SummaryView.cpp +++ b/llvm/tools/llvm-mca/Views/SummaryView.cpp @@ -27,8 +27,13 @@ SummaryView::SummaryView(const MCSchedModel &Model, ArrayRef<MCInst> S, : SM(Model), Source(S), DispatchWidth(Width), LastInstructionIdx(0), TotalCycles(0), NumMicroOps(0), ProcResourceUsage(Model.getNumProcResourceKinds(), 0), - ProcResourceMasks(Model.getNumProcResourceKinds()) { + ProcResourceMasks(Model.getNumProcResourceKinds()), + ResIdx2ProcResID(Model.getNumProcResourceKinds(), 0) { computeProcResourceMasks(SM, ProcResourceMasks); + for (unsigned I = 1, E = SM.getNumProcResourceKinds(); I < E; ++I) { + unsigned Index = getResourceStateIndex(ProcResourceMasks[I]); + ResIdx2ProcResID[Index] = I; + } } void SummaryView::onEvent(const HWInstructionEvent &Event) { @@ -50,11 +55,8 @@ void SummaryView::onEvent(const HWInstructionEvent &Event) { NumMicroOps += Desc.NumMicroOps; for (const std::pair<uint64_t, const ResourceUsage> &RU : Desc.Resources) { if (RU.second.size()) { - const auto It = find(ProcResourceMasks, RU.first); - assert(It != ProcResourceMasks.end() && - "Invalid processor resource mask!"); - ProcResourceUsage[std::distance(ProcResourceMasks.begin(), It)] += - RU.second.size(); + unsigned ProcResID = ResIdx2ProcResID[getResourceStateIndex(RU.first)]; + ProcResourceUsage[ProcResID] += RU.second.size(); } } } diff --git a/llvm/tools/llvm-mca/Views/SummaryView.h b/llvm/tools/llvm-mca/Views/SummaryView.h index d1d43d6818a..631e40964a0 100644 --- a/llvm/tools/llvm-mca/Views/SummaryView.h +++ b/llvm/tools/llvm-mca/Views/SummaryView.h @@ -55,6 +55,9 @@ class SummaryView : public View { // declared by the scheduling model. llvm::SmallVector<uint64_t, 8> ProcResourceMasks; + // Used to map resource indices to actual processor resource IDs. + llvm::SmallVector<unsigned, 8> ResIdx2ProcResID; + // Compute the reciprocal throughput for the analyzed code block. // The reciprocal block throughput is computed as the MAX between: // - NumMicroOps / DispatchWidth |