https://github.com/tomershafir updated https://github.com/llvm/llvm-project/pull/189453
>From a6fb52d2ed1f7694e9b098a9f5a839e8547c9ba7 Mon Sep 17 00:00:00 2001
From: tomershafir <tomer.shafir8 at gmail.com>
Date: Mon, 30 Mar 2026 21:55:55 +0300
Subject: [PATCH] [MCA] Make `ResourceSizeMask` const
This patch marks the already effectively constant `ResourceSizeMask` as `const`. It adds a helper `computeResourceSizeMask()` to initialize it in the member initializer list.
---
.../llvm/MCA/HardwareUnits/ResourceManager.h | 6 +++---
llvm/lib/MCA/HardwareUnits/ResourceManager.cpp | 17 ++++++++++-------
2 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/llvm/include/llvm/MCA/HardwareUnits/ResourceManager.h b/llvm/include/llvm/MCA/HardwareUnits/ResourceManager.h
index 958911d2c0f27..5d26687613ebb 100644
--- a/llvm/include/llvm/MCA/HardwareUnits/ResourceManager.h
+++ b/llvm/include/llvm/MCA/HardwareUnits/ResourceManager.h
@@ -163,6 +163,8 @@ class ResourceState {
/// That is because MSB(B) and MSB(C) are both contained within Group(D).
const uint64_t ResourceMask;
+ const bool IsAGroup;
+
/// A ProcResource can have multiple units.
///
/// For processor resource groups this field is a mask of contained resource
@@ -173,7 +175,7 @@ class ResourceState {
/// For normal (i.e. non-group) resources, the number of bits set in this mask
/// is equivalent to the number of units declared by the processor model (see
/// field 'NumUnits' in 'ProcResourceUnits').
- uint64_t ResourceSizeMask;
+ const uint64_t ResourceSizeMask;
/// A mask of ready units.
uint64_t ReadyMask;
@@ -204,8 +206,6 @@ 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;
diff --git a/llvm/lib/MCA/HardwareUnits/ResourceManager.cpp b/llvm/lib/MCA/HardwareUnits/ResourceManager.cpp
index e45bd00f1a292..0429f7b6970d6 100644
--- a/llvm/lib/MCA/HardwareUnits/ResourceManager.cpp
+++ b/llvm/lib/MCA/HardwareUnits/ResourceManager.cpp
@@ -62,16 +62,19 @@ void DefaultResourceStrategy::used(uint64_t Mask) {
RemovedFromNextInSequence = 0;
}
+static uint64_t computeResourceSizeMask(uint64_t Mask, bool IsAGroup,
+ unsigned NumUnits) {
+ if (IsAGroup)
+ return Mask ^ (1ULL << getResourceStateIndex(Mask));
+ return (1ULL << NumUnits) - 1;
+}
+
ResourceState::ResourceState(const MCProcResourceDesc &Desc, unsigned Index,
uint64_t Mask)
: ProcResourceDescIndex(Index), ResourceMask(Mask),
- BufferSize(Desc.BufferSize), IsAGroup(llvm::popcount(ResourceMask) > 1) {
- if (IsAGroup) {
- ResourceSizeMask =
- ResourceMask ^ 1ULL << getResourceStateIndex(ResourceMask);
- } else {
- ResourceSizeMask = (1ULL << Desc.NumUnits) - 1;
- }
+ IsAGroup(llvm::popcount(ResourceMask) > 1),
+ ResourceSizeMask(computeResourceSizeMask(Mask, IsAGroup, Desc.NumUnits)),
+ BufferSize(Desc.BufferSize) {
ReadyMask = ResourceSizeMask;
AvailableSlots = BufferSize == -1 ? 0U : static_cast<unsigned>(BufferSize);
Unavailable = false;