[llvm] r353706 - [MCA] Return a mask of busy resources from method ResourceManager::checkAvailability(). NFCI
Andrea Di Biagio via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 11 06:53:04 PST 2019
Author: adibiagio
Date: Mon Feb 11 06:53:04 2019
New Revision: 353706
URL: http://llvm.org/viewvc/llvm-project?rev=353706&view=rev
Log:
[MCA] Return a mask of busy resources from method ResourceManager::checkAvailability(). NFCI
In case of bottlenecks caused by pipeline pressure, we want to be able to
correctly report the set of problematic pipelines. This is a first step towards
adding support for bottleneck hints in llvm-mca (see PR37494). No functional
change intended.
Modified:
llvm/trunk/include/llvm/MCA/HardwareUnits/ResourceManager.h
llvm/trunk/include/llvm/MCA/HardwareUnits/Scheduler.h
llvm/trunk/lib/MCA/HardwareUnits/ResourceManager.cpp
llvm/trunk/lib/MCA/HardwareUnits/Scheduler.cpp
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=353706&r1=353705&r2=353706&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MCA/HardwareUnits/ResourceManager.h (original)
+++ llvm/trunk/include/llvm/MCA/HardwareUnits/ResourceManager.h Mon Feb 11 06:53:04 2019
@@ -341,6 +341,12 @@ class ResourceManager {
// before those become usable again.
SmallDenseMap<ResourceRef, unsigned> BusyResources;
+ // Set of processor resource units available on the target.
+ uint64_t ProcResUnitMask;
+
+ // Set of processor resource units that are available during this cycle.
+ uint64_t AvailableProcResUnits;
+
// Returns the actual resource unit that will be used.
ResourceRef selectPipe(uint64_t ResourceID);
@@ -388,7 +394,14 @@ public:
// Release a previously reserved processor resource.
void releaseResource(uint64_t ResourceID);
- bool canBeIssued(const InstrDesc &Desc) const;
+ // Returns a zero mask if resources requested by Desc are all available during
+ // this cycle. It returns a non-zero mask value only if there are unavailable
+ // processor resources; each bit set in the mask represents a busy processor
+ // resource unit.
+ uint64_t checkAvailability(const InstrDesc &Desc) const;
+
+ uint64_t getProcResUnitMask() const { return ProcResUnitMask; }
+ uint64_t getAvailableProcResUnits() const { return AvailableProcResUnits; }
void issueInstruction(
const InstrDesc &Desc,
Modified: llvm/trunk/include/llvm/MCA/HardwareUnits/Scheduler.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MCA/HardwareUnits/Scheduler.h?rev=353706&r1=353705&r2=353706&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MCA/HardwareUnits/Scheduler.h (original)
+++ llvm/trunk/include/llvm/MCA/HardwareUnits/Scheduler.h Mon Feb 11 06:53:04 2019
@@ -194,6 +194,12 @@ public:
/// resources are not available.
InstRef select();
+ bool arePipelinesFullyUsed() const {
+ return !Resources->getAvailableProcResUnits();
+ }
+ bool isReadySetEmpty() const { return ReadySet.empty(); }
+ bool isWaitSetEmpty() const { return WaitSet.empty(); }
+
#ifndef NDEBUG
// Update the ready queues.
void dump() const;
Modified: llvm/trunk/lib/MCA/HardwareUnits/ResourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MCA/HardwareUnits/ResourceManager.cpp?rev=353706&r1=353705&r2=353706&view=diff
==============================================================================
--- llvm/trunk/lib/MCA/HardwareUnits/ResourceManager.cpp (original)
+++ llvm/trunk/lib/MCA/HardwareUnits/ResourceManager.cpp Mon Feb 11 06:53:04 2019
@@ -118,7 +118,8 @@ ResourceManager::ResourceManager(const M
: Resources(SM.getNumProcResourceKinds()),
Strategies(SM.getNumProcResourceKinds()),
Resource2Groups(SM.getNumProcResourceKinds(), 0),
- ProcResID2Mask(SM.getNumProcResourceKinds()) {
+ ProcResID2Mask(SM.getNumProcResourceKinds()),
+ ProcResUnitMask(0) {
computeProcResourceMasks(SM, ProcResID2Mask);
for (unsigned I = 0, E = SM.getNumProcResourceKinds(); I < E; ++I) {
@@ -133,8 +134,10 @@ ResourceManager::ResourceManager(const M
uint64_t Mask = ProcResID2Mask[I];
unsigned Index = getResourceStateIndex(Mask);
const ResourceState &RS = *Resources[Index];
- if (!RS.isAResourceGroup())
+ if (!RS.isAResourceGroup()) {
+ ProcResUnitMask |= Mask;
continue;
+ }
uint64_t GroupMaskIdx = 1ULL << (Index - 1);
Mask -= GroupMaskIdx;
@@ -146,6 +149,8 @@ ResourceManager::ResourceManager(const M
Mask ^= Unit;
}
}
+
+ AvailableProcResUnits = ProcResUnitMask;
}
void ResourceManager::setCustomStrategyImpl(std::unique_ptr<ResourceStrategy> S,
@@ -199,6 +204,8 @@ void ResourceManager::use(const Resource
if (RS.isReady())
return;
+ AvailableProcResUnits ^= RR.first;
+
// Notify groups that RR.first is no longer available.
uint64_t Users = Resource2Groups[RSID];
while (Users) {
@@ -220,6 +227,8 @@ void ResourceManager::release(const Reso
if (!WasFullyUsed)
return;
+ AvailableProcResUnits ^= RR.first;
+
// Notify groups that RR.first is now available again.
uint64_t Users = Resource2Groups[RSID];
while (Users) {
@@ -260,13 +269,16 @@ void ResourceManager::releaseBuffers(Arr
Resources[getResourceStateIndex(R)]->releaseBuffer();
}
-bool ResourceManager::canBeIssued(const InstrDesc &Desc) const {
- return all_of(
- Desc.Resources, [&](const std::pair<uint64_t, const ResourceUsage> &E) {
- unsigned NumUnits = E.second.isReserved() ? 0U : E.second.NumUnits;
- unsigned Index = getResourceStateIndex(E.first);
- return Resources[Index]->isReady(NumUnits);
- });
+uint64_t ResourceManager::checkAvailability(const InstrDesc &Desc) const {
+ uint64_t BusyResourceMask = 0;
+ for (const std::pair<uint64_t, const ResourceUsage> &E : Desc.Resources) {
+ unsigned NumUnits = E.second.isReserved() ? 0U : E.second.NumUnits;
+ unsigned Index = getResourceStateIndex(E.first);
+ if (!Resources[Index]->isReady(NumUnits))
+ BusyResourceMask |= E.first;
+ }
+
+ return BusyResourceMask & ProcResUnitMask;
}
void ResourceManager::issueInstruction(
Modified: llvm/trunk/lib/MCA/HardwareUnits/Scheduler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MCA/HardwareUnits/Scheduler.cpp?rev=353706&r1=353705&r2=353706&view=diff
==============================================================================
--- llvm/trunk/lib/MCA/HardwareUnits/Scheduler.cpp (original)
+++ llvm/trunk/lib/MCA/HardwareUnits/Scheduler.cpp Mon Feb 11 06:53:04 2019
@@ -139,7 +139,8 @@ InstRef Scheduler::select() {
if (QueueIndex == ReadySet.size() ||
Strategy->compare(IR, ReadySet[QueueIndex])) {
const InstrDesc &D = IR.getInstruction()->getDesc();
- if (Resources->canBeIssued(D))
+ uint64_t BusyResourceMask = Resources->checkAvailability(D);
+ if (!BusyResourceMask)
QueueIndex = I;
}
}
More information about the llvm-commits
mailing list