From 2623df180b9e86512fe69b8f90563fbd8add89c3 Mon Sep 17 00:00:00 2001 From: Richard-Qin-X Date: Fri, 28 Aug 2026 23:59:37 +0800 Subject: [CodeGen] Complete LaneMask bitwise operations --- backend/include/rcc/CodeGen/MachineIRTypes.h | 14 ++++++++++++++ backend/lib/CodeGen/LiveIntervals.cpp | 6 +----- backend/lib/CodeGen/LiveRegUnits.cpp | 8 ++------ backend/lib/CodeGen/LiveVariables.cpp | 8 ++------ 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/backend/include/rcc/CodeGen/MachineIRTypes.h b/backend/include/rcc/CodeGen/MachineIRTypes.h index 66369e0..abd547e 100644 --- a/backend/include/rcc/CodeGen/MachineIRTypes.h +++ b/backend/include/rcc/CodeGen/MachineIRTypes.h @@ -173,6 +173,20 @@ public: return RawValue; } + [[nodiscard]] constexpr LaneMask operator~() const noexcept { + return LaneMask(~RawValue); + } + + constexpr LaneMask &operator|=(LaneMask Other) noexcept { + RawValue |= Other.RawValue; + return *this; + } + + constexpr LaneMask &operator&=(LaneMask Other) noexcept { + RawValue &= Other.RawValue; + return *this; + } + friend constexpr bool operator==(LaneMask Left, LaneMask Right) noexcept = default; friend constexpr LaneMask operator|(LaneMask Left, LaneMask Right) noexcept { diff --git a/backend/lib/CodeGen/LiveIntervals.cpp b/backend/lib/CodeGen/LiveIntervals.cpp index 5a01693..dc25af8 100644 --- a/backend/lib/CodeGen/LiveIntervals.cpp +++ b/backend/lib/CodeGen/LiveIntervals.cpp @@ -23,10 +23,6 @@ namespace rcc { namespace { -[[nodiscard]] LaneMask subtractLanes(LaneMask Left, LaneMask Right) noexcept { - return LaneMask::fromRaw(Left.rawValue() & ~Right.rawValue()); -} - [[nodiscard]] bool maskIntersects(LaneMask Access, std::optional Filter) noexcept { return !Filter || Access.intersects(*Filter); } @@ -242,7 +238,7 @@ partitionVirtualRegisterLanes(Register Reg, MachineFunction &Function, std::vector Refined; for (const LaneMask Group : Groups) { const LaneMask Intersection = Group & Access; - const LaneMask Difference = subtractLanes(Group, Access); + const LaneMask Difference = Group & ~Access; if (!Intersection.empty()) Refined.push_back(Intersection); if (!Difference.empty()) diff --git a/backend/lib/CodeGen/LiveRegUnits.cpp b/backend/lib/CodeGen/LiveRegUnits.cpp index e0aa992..935478e 100644 --- a/backend/lib/CodeGen/LiveRegUnits.cpp +++ b/backend/lib/CodeGen/LiveRegUnits.cpp @@ -21,10 +21,6 @@ namespace rcc { namespace { -[[nodiscard]] LaneMask subtractLanes(LaneMask Left, LaneMask Right) noexcept { - return LaneMask::fromRaw(Left.rawValue() & ~Right.rawValue()); -} - template void addLanes(std::unordered_map &Values, KeyT Key, LaneMask Lanes) { if (Lanes.empty()) @@ -34,7 +30,7 @@ void addLanes(std::unordered_map &Values, KeyT Key, LaneMask Lan Values.emplace(Key, Lanes); return; } - Position->second = Position->second | Lanes; + Position->second |= Lanes; } template @@ -42,7 +38,7 @@ void removeLanes(std::unordered_map &Values, KeyT Key, LaneMask const auto Position = Values.find(Key); if (Position == Values.end() || Lanes.empty()) return; - Position->second = subtractLanes(Position->second, Lanes); + Position->second &= ~Lanes; if (Position->second.empty()) Values.erase(Position); } diff --git a/backend/lib/CodeGen/LiveVariables.cpp b/backend/lib/CodeGen/LiveVariables.cpp index 5efdbd4..4f65f72 100644 --- a/backend/lib/CodeGen/LiveVariables.cpp +++ b/backend/lib/CodeGen/LiveVariables.cpp @@ -33,10 +33,6 @@ namespace rcc { namespace { -[[nodiscard]] LaneMask subtractLanes(LaneMask Left, LaneMask Right) noexcept { - return LaneMask::fromRaw(Left.rawValue() & ~Right.rawValue()); -} - template void addLanes(std::unordered_map &Values, KeyT Key, LaneMask Lanes) { if (Lanes.empty()) @@ -46,7 +42,7 @@ void addLanes(std::unordered_map &Values, KeyT Key, LaneMask Lan Values.emplace(Key, Lanes); return; } - Position->second = Position->second | Lanes; + Position->second |= Lanes; } template @@ -54,7 +50,7 @@ void removeLanes(std::unordered_map &Values, KeyT Key, LaneMask const auto Position = Values.find(Key); if (Position == Values.end() || Lanes.empty()) return; - Position->second = subtractLanes(Position->second, Lanes); + Position->second &= ~Lanes; if (Position->second.empty()) Values.erase(Position); } -- cgit v1.2.3