[llvm] r354470 - [MCA][ResourceManager] Add a table that maps processor resource indices to processor resource identifiers.
Andrea Di Biagio via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 20 06:53:18 PST 2019
Author: adibiagio
Date: Wed Feb 20 06:53:18 2019
New Revision: 354470
URL: http://llvm.org/viewvc/llvm-project?rev=354470&view=rev
Log:
[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.
Modified:
llvm/trunk/include/llvm/MCA/HardwareUnits/ResourceManager.h
llvm/trunk/include/llvm/MCA/Support.h
llvm/trunk/lib/MCA/HardwareUnits/ResourceManager.cpp
llvm/trunk/tools/llvm-mca/Views/SummaryView.cpp
llvm/trunk/tools/llvm-mca/Views/SummaryView.h
Modified: llvm/trunk/include/llvm/MCA/HardwareUnits/ResourceManager.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MCA/HardwareUnits/ResourceManager.h?rev=354470&r1=354469&r2=354470&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MCA/HardwareUnits/ResourceManager.h (original)
+++ llvm/trunk/include/llvm/MCA/HardwareUnits/ResourceManager.h Wed Feb 20 06:53:18 2019
@@ -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;
Modified: llvm/trunk/include/llvm/MCA/Support.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MCA/Support.h?rev=354470&r1=354469&r2=354470&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MCA/Support.h (original)
+++ llvm/trunk/include/llvm/MCA/Support.h Wed Feb 20 06:53:18 2019
@@ -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
Modified: llvm/trunk/lib/MCA/HardwareUnits/ResourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MCA/HardwareUnits/ResourceManager.cpp?rev=354470&r1=354469&r2=354470&view=diff
==============================================================================
--- llvm/trunk/lib/MCA/HardwareUnits/ResourceManager.cpp (original)
+++ llvm/trunk/lib/MCA/HardwareUnits/ResourceManager.cpp Wed Feb 20 06:53:18 2019
@@ -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 MCPro
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 M
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 M
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::setCustomStrategyI
}
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(SmallVe
}
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
Modified: llvm/trunk/tools/llvm-mca/Views/SummaryView.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/Views/SummaryView.cpp?rev=354470&r1=354469&r2=354470&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/Views/SummaryView.cpp (original)
+++ llvm/trunk/tools/llvm-mca/Views/SummaryView.cpp Wed Feb 20 06:53:18 2019
@@ -27,8 +27,13 @@ SummaryView::SummaryView(const MCSchedMo
: 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 HWInstru
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();
}
}
}
Modified: llvm/trunk/tools/llvm-mca/Views/SummaryView.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/Views/SummaryView.h?rev=354470&r1=354469&r2=354470&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/Views/SummaryView.h (original)
+++ llvm/trunk/tools/llvm-mca/Views/SummaryView.h Wed Feb 20 06:53:18 2019
@@ -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
More information about the llvm-commits
mailing list