mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-14 11:39:35 +00:00
[MCA] Store a bitmask of used groups in the instruction descriptor.
This is to speedup 'checkAvailability' queries in class ResourceManager. No functional change intended. llvm-svn: 353949
This commit is contained in:
parent
a9a11aac0f
commit
245163ffd0
@ -347,6 +347,9 @@ class ResourceManager {
|
||||
// Set of processor resource units that are available during this cycle.
|
||||
uint64_t AvailableProcResUnits;
|
||||
|
||||
// Set of processor resource groups that are currently reserved.
|
||||
uint64_t ReservedResourceGroups;
|
||||
|
||||
// Returns the actual resource unit that will be used.
|
||||
ResourceRef selectPipe(uint64_t ResourceID);
|
||||
|
||||
@ -397,7 +400,7 @@ public:
|
||||
// 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.
|
||||
// resource unit or a reserved processor resource group.
|
||||
uint64_t checkAvailability(const InstrDesc &Desc) const;
|
||||
|
||||
uint64_t getProcResUnitMask() const { return ProcResUnitMask; }
|
||||
|
@ -338,6 +338,9 @@ struct InstrDesc {
|
||||
// A list of buffered resources consumed by this instruction.
|
||||
SmallVector<uint64_t, 4> Buffers;
|
||||
|
||||
unsigned UsedProcResUnits;
|
||||
unsigned UsedProcResGroups;
|
||||
|
||||
unsigned MaxLatency;
|
||||
// Number of MicroOps for this instruction.
|
||||
unsigned NumMicroOps;
|
||||
|
@ -118,8 +118,8 @@ ResourceManager::ResourceManager(const MCSchedModel &SM)
|
||||
: Resources(SM.getNumProcResourceKinds()),
|
||||
Strategies(SM.getNumProcResourceKinds()),
|
||||
Resource2Groups(SM.getNumProcResourceKinds(), 0),
|
||||
ProcResID2Mask(SM.getNumProcResourceKinds()),
|
||||
ProcResUnitMask(0) {
|
||||
ProcResID2Mask(SM.getNumProcResourceKinds()), ProcResUnitMask(0),
|
||||
ReservedResourceGroups(0) {
|
||||
computeProcResourceMasks(SM, ProcResID2Mask);
|
||||
|
||||
for (unsigned I = 0, E = SM.getNumProcResourceKinds(); I < E; ++I) {
|
||||
@ -278,7 +278,10 @@ uint64_t ResourceManager::checkAvailability(const InstrDesc &Desc) const {
|
||||
BusyResourceMask |= E.first;
|
||||
}
|
||||
|
||||
return BusyResourceMask & ProcResUnitMask;
|
||||
BusyResourceMask &= ProcResUnitMask;
|
||||
if (BusyResourceMask)
|
||||
return BusyResourceMask;
|
||||
return Desc.UsedProcResGroups & ReservedResourceGroups;
|
||||
}
|
||||
|
||||
void ResourceManager::issueInstruction(
|
||||
@ -330,13 +333,17 @@ void ResourceManager::cycleEvent(SmallVectorImpl<ResourceRef> &ResourcesFreed) {
|
||||
|
||||
void ResourceManager::reserveResource(uint64_t ResourceID) {
|
||||
ResourceState &Resource = *Resources[getResourceStateIndex(ResourceID)];
|
||||
assert(!Resource.isReserved());
|
||||
assert(Resource.isAResourceGroup() && !Resource.isReserved() &&
|
||||
"Unexpected resource found!");
|
||||
Resource.setReserved();
|
||||
ReservedResourceGroups ^= PowerOf2Floor(ResourceID);
|
||||
}
|
||||
|
||||
void ResourceManager::releaseResource(uint64_t ResourceID) {
|
||||
ResourceState &Resource = *Resources[getResourceStateIndex(ResourceID)];
|
||||
Resource.clearReserved();
|
||||
if (Resource.isAResourceGroup())
|
||||
ReservedResourceGroups ^= PowerOf2Floor(ResourceID);
|
||||
}
|
||||
|
||||
} // namespace mca
|
||||
|
@ -97,14 +97,14 @@ static void initializeUsedResources(InstrDesc &ID,
|
||||
});
|
||||
|
||||
uint64_t UsedResourceUnits = 0;
|
||||
uint64_t UsedResourceGroups = 0;
|
||||
|
||||
// Remove cycles contributed by smaller resources.
|
||||
for (unsigned I = 0, E = Worklist.size(); I < E; ++I) {
|
||||
ResourcePlusCycles &A = Worklist[I];
|
||||
if (!A.second.size()) {
|
||||
A.second.NumUnits = 0;
|
||||
A.second.setReserved();
|
||||
ID.Resources.emplace_back(A);
|
||||
assert(countPopulation(A.first) > 1 && "Expected a group!");
|
||||
UsedResourceGroups |= PowerOf2Floor(A.first);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -127,6 +127,9 @@ static void initializeUsedResources(InstrDesc &ID,
|
||||
}
|
||||
}
|
||||
|
||||
ID.UsedProcResUnits = UsedResourceUnits;
|
||||
ID.UsedProcResGroups = UsedResourceGroups;
|
||||
|
||||
// A SchedWrite may specify a number of cycles in which a resource group
|
||||
// is reserved. For example (on target x86; cpu Haswell):
|
||||
//
|
||||
@ -179,10 +182,14 @@ static void initializeUsedResources(InstrDesc &ID,
|
||||
|
||||
LLVM_DEBUG({
|
||||
for (const std::pair<uint64_t, ResourceUsage> &R : ID.Resources)
|
||||
dbgs() << "\t\tMask=" << format_hex(R.first, 16) << ", "
|
||||
dbgs() << "\t\tResource Mask=" << format_hex(R.first, 16) << ", "
|
||||
<< "Reserved=" << R.second.isReserved() << ", "
|
||||
<< "#Units=" << R.second.NumUnits << ", "
|
||||
<< "cy=" << R.second.size() << '\n';
|
||||
for (const uint64_t R : ID.Buffers)
|
||||
dbgs() << "\t\tBuffer Mask=" << format_hex(R, 16) << '\n';
|
||||
dbgs() << "\t\t Used Units=" << format_hex(ID.UsedProcResUnits, 16) << '\n';
|
||||
dbgs() << "\t\tUsed Groups=" << format_hex(ID.UsedProcResGroups, 16) << '\n';
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user