From 97a60aa37a048155fec0c560fc51ed52dbd84e44 Mon Sep 17 00:00:00 2001 From: Sergei Barannikov Date: Sun, 16 Nov 2025 20:46:44 +0300 Subject: [CodeGen] Turn MCRegUnit into an enum class (NFC) (#167943) This changes `MCRegUnit` type from `unsigned` to `enum class : unsigned` and inserts necessary casts. The added `MCRegUnitToIndex` functor is used with `SparseSet`, `SparseMultiSet` and `IndexedMap` in a few places. `MCRegUnit` is opaque to users, so it didn't seem worth making it a full-fledged class like `Register`. Static type checking has detected one issue in `PrologueEpilogueInserter.cpp`, where `BitVector` created for `MCRegister` is indexed by both `MCRegister` and `MCRegUnit`. The number of casts could be reduced by using `IndexedMap` in more places and/or adding a `BitVector` adaptor, but the number of casts *per file* is still small and `IndexedMap` has limitations, so it didn't seem worth the effort. Pull Request: https://github.com/llvm/llvm-project/pull/167943 --- llvm/lib/CodeGen/InterferenceCache.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'llvm/lib/CodeGen/InterferenceCache.cpp') diff --git a/llvm/lib/CodeGen/InterferenceCache.cpp b/llvm/lib/CodeGen/InterferenceCache.cpp index ebdf0506bb22..466070b312b2 100644 --- a/llvm/lib/CodeGen/InterferenceCache.cpp +++ b/llvm/lib/CodeGen/InterferenceCache.cpp @@ -93,7 +93,7 @@ void InterferenceCache::Entry::revalidate(LiveIntervalUnion *LIUArray, PrevPos = SlotIndex(); unsigned i = 0; for (MCRegUnit Unit : TRI->regunits(PhysReg)) - RegUnits[i++].VirtTag = LIUArray[Unit].getTag(); + RegUnits[i++].VirtTag = LIUArray[static_cast(Unit)].getTag(); } void InterferenceCache::Entry::reset(MCRegister physReg, @@ -110,7 +110,7 @@ void InterferenceCache::Entry::reset(MCRegister physReg, PrevPos = SlotIndex(); RegUnits.clear(); for (MCRegUnit Unit : TRI->regunits(PhysReg)) { - RegUnits.push_back(LIUArray[Unit]); + RegUnits.push_back(LIUArray[static_cast(Unit)]); RegUnits.back().Fixed = &LIS->getRegUnit(Unit); } } @@ -121,7 +121,7 @@ bool InterferenceCache::Entry::valid(LiveIntervalUnion *LIUArray, for (MCRegUnit Unit : TRI->regunits(PhysReg)) { if (i == e) return false; - if (LIUArray[Unit].changedSince(RegUnits[i].VirtTag)) + if (LIUArray[static_cast(Unit)].changedSince(RegUnits[i].VirtTag)) return false; ++i; } -- cgit v1.2.3