llvm.org GIT mirror llvm / 2735936
[MCA] Minor refactoring of method DefaultResourceStrategy::select. NFCI Common code used by the default resource strategy to select pipeline resources has been moved to an helper function. The new selection logic has been slightly rewritten to get rid of a redundant zero check on the `ReadyMask` value. Before this patch, method select internally called function `PowerOf2Floor` to compute the next ready pipeline resource. However, `PowerOf2Floor` forces an implicit (redundant) zero check on the input value. By construction, `ReadyMask` can never be zero. This patch replaces the call to `PowerOf2Floor` with an equivalent block of code which avoids the redundant zero check. This gives a minor 3-3.5% speedup on a release build. No functional change intended. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350218 91177308-0d34-0410-b5e6-96231b3b80d8 Andrea Di Biagio 1 year, 11 months ago
1 changed file(s) with 21 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
2323 #define DEBUG_TYPE "llvm-mca"
2424 ResourceStrategy::~ResourceStrategy() = default;
2525
26 static uint64_t selectImpl(uint64_t CandidateMask,
27 uint64_t &NextInSequenceMask) {
28 CandidateMask = 1ULL << (countLeadingZeros(CandidateMask) ^
29 (std::numeric_limits::digits - 1));
30 NextInSequenceMask &= (CandidateMask ^ (CandidateMask - 1));
31 return CandidateMask;
32 }
33
2634 uint64_t DefaultResourceStrategy::select(uint64_t ReadyMask) {
2735 // This method assumes that ReadyMask cannot be zero.
2836 uint64_t CandidateMask = ReadyMask & NextInSequenceMask;
29 if (CandidateMask) {
30 CandidateMask = PowerOf2Floor(CandidateMask);
31 NextInSequenceMask &= (CandidateMask | (CandidateMask - 1));
32 return CandidateMask;
33 }
37 if (CandidateMask)
38 return selectImpl(CandidateMask, NextInSequenceMask);
3439
3540 NextInSequenceMask = ResourceUnitMask ^ RemovedFromNextInSequence;
3641 RemovedFromNextInSequence = 0;
3742 CandidateMask = ReadyMask & NextInSequenceMask;
38
39 if (CandidateMask) {
40 CandidateMask = PowerOf2Floor(CandidateMask);
41 NextInSequenceMask &= (CandidateMask | (CandidateMask - 1));
42 return CandidateMask;
43 }
43 if (CandidateMask)
44 return selectImpl(CandidateMask, NextInSequenceMask);
4445
4546 NextInSequenceMask = ResourceUnitMask;
46 CandidateMask = PowerOf2Floor(ReadyMask & NextInSequenceMask);
47 NextInSequenceMask &= (CandidateMask | (CandidateMask - 1));
48 return CandidateMask;
47 CandidateMask = ReadyMask & NextInSequenceMask;
48 return selectImpl(CandidateMask, NextInSequenceMask);
4949 }
5050
5151 void DefaultResourceStrategy::used(uint64_t Mask) {
6565 ResourceState::ResourceState(const MCProcResourceDesc &Desc, unsigned Index,
6666 uint64_t Mask)
6767 : ProcResourceDescIndex(Index), ResourceMask(Mask),
68 BufferSize(Desc.BufferSize), IsAGroup(countPopulation(ResourceMask)>1) {
69 if (IsAGroup)
70 ResourceSizeMask = ResourceMask ^ PowerOf2Floor(ResourceMask);
71 else
68 BufferSize(Desc.BufferSize), IsAGroup(countPopulation(ResourceMask) > 1) {
69 if (IsAGroup) {
70 ResourceSizeMask =
71 ResourceMask ^ (1ULL << (countLeadingZeros(ResourceMask) ^
72 (std::numeric_limits::digits - 1)));
73 } else {
7274 ResourceSizeMask = (1ULL << Desc.NumUnits) - 1;
75 }
7376 ReadyMask = ResourceSizeMask;
7477 AvailableSlots = BufferSize == -1 ? 0U : static_cast(BufferSize);
7578 Unavailable = false;