forked from OSchip/llvm-project
[llvm-mca] Speedup the default resource selection strategy.
This patch removes a (potentially) slow while loop in DefaultResourceStrategy::select(). A better (and faster) approach is to do some bit manipulation in order to shrink the range of candidate resources. On a release build, this change gives an average speedup of ~10%. llvm-svn: 348007
This commit is contained in:
parent
e9870c0c91
commit
7e695b97d7
|
@ -119,8 +119,6 @@ class DefaultResourceStrategy final : public ResourceStrategy {
|
|||
/// on the overall performance of the tool.
|
||||
uint64_t RemovedFromNextInSequence;
|
||||
|
||||
void skipMask(uint64_t Mask);
|
||||
|
||||
public:
|
||||
DefaultResourceStrategy(uint64_t UnitMask)
|
||||
: ResourceStrategy(), ResourceUnitMask(UnitMask),
|
||||
|
@ -183,6 +181,8 @@ class ResourceState {
|
|||
/// underlying units (i.e. pipelines) until the resource is released.
|
||||
bool Unavailable;
|
||||
|
||||
const bool IsAGroup;
|
||||
|
||||
/// Checks for the availability of unit 'SubResMask' in the group.
|
||||
bool isSubResourceReady(uint64_t SubResMask) const {
|
||||
return ReadyMask & SubResMask;
|
||||
|
@ -210,7 +210,7 @@ public:
|
|||
/// `NumUnits` available units.
|
||||
bool isReady(unsigned NumUnits = 1) const;
|
||||
|
||||
bool isAResourceGroup() const { return countPopulation(ResourceMask) > 1; }
|
||||
bool isAResourceGroup() const { return IsAGroup; }
|
||||
|
||||
bool containsResource(uint64_t ID) const { return ResourceMask & ID; }
|
||||
|
||||
|
|
|
@ -24,21 +24,28 @@ namespace mca {
|
|||
#define DEBUG_TYPE "llvm-mca"
|
||||
ResourceStrategy::~ResourceStrategy() = default;
|
||||
|
||||
void DefaultResourceStrategy::skipMask(uint64_t Mask) {
|
||||
NextInSequenceMask &= (~Mask);
|
||||
if (!NextInSequenceMask) {
|
||||
NextInSequenceMask = ResourceUnitMask ^ RemovedFromNextInSequence;
|
||||
RemovedFromNextInSequence = 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t DefaultResourceStrategy::select(uint64_t ReadyMask) {
|
||||
// This method assumes that ReadyMask cannot be zero.
|
||||
uint64_t CandidateMask = PowerOf2Floor(NextInSequenceMask);
|
||||
while (!(ReadyMask & CandidateMask)) {
|
||||
skipMask(CandidateMask);
|
||||
CandidateMask = PowerOf2Floor(NextInSequenceMask);
|
||||
uint64_t CandidateMask = ReadyMask & NextInSequenceMask;
|
||||
if (CandidateMask) {
|
||||
CandidateMask = PowerOf2Floor(CandidateMask);
|
||||
NextInSequenceMask &= (CandidateMask | (CandidateMask - 1));
|
||||
return CandidateMask;
|
||||
}
|
||||
|
||||
NextInSequenceMask = ResourceUnitMask ^ RemovedFromNextInSequence;
|
||||
RemovedFromNextInSequence = 0;
|
||||
CandidateMask = ReadyMask & NextInSequenceMask;
|
||||
|
||||
if (CandidateMask) {
|
||||
CandidateMask = PowerOf2Floor(CandidateMask);
|
||||
NextInSequenceMask &= (CandidateMask | (CandidateMask - 1));
|
||||
return CandidateMask;
|
||||
}
|
||||
|
||||
NextInSequenceMask = ResourceUnitMask;
|
||||
CandidateMask = PowerOf2Floor(ReadyMask & NextInSequenceMask);
|
||||
NextInSequenceMask &= (CandidateMask | (CandidateMask - 1));
|
||||
return CandidateMask;
|
||||
}
|
||||
|
||||
|
@ -47,14 +54,20 @@ void DefaultResourceStrategy::used(uint64_t Mask) {
|
|||
RemovedFromNextInSequence |= Mask;
|
||||
return;
|
||||
}
|
||||
skipMask(Mask);
|
||||
|
||||
NextInSequenceMask &= (~Mask);
|
||||
if (NextInSequenceMask)
|
||||
return;
|
||||
|
||||
NextInSequenceMask = ResourceUnitMask ^ RemovedFromNextInSequence;
|
||||
RemovedFromNextInSequence = 0;
|
||||
}
|
||||
|
||||
ResourceState::ResourceState(const MCProcResourceDesc &Desc, unsigned Index,
|
||||
uint64_t Mask)
|
||||
: ProcResourceDescIndex(Index), ResourceMask(Mask),
|
||||
BufferSize(Desc.BufferSize) {
|
||||
if (countPopulation(ResourceMask) > 1)
|
||||
BufferSize(Desc.BufferSize), IsAGroup(countPopulation(ResourceMask)>1) {
|
||||
if (IsAGroup)
|
||||
ResourceSizeMask = ResourceMask ^ PowerOf2Floor(ResourceMask);
|
||||
else
|
||||
ResourceSizeMask = (1ULL << Desc.NumUnits) - 1;
|
||||
|
|
Loading…
Reference in New Issue