Skip to content

Commit 592e596

Browse files
authored
[TableGen] Move getSuperRegForSubReg into CodeGenRegBank. NFC. (#142979)
This method doesn't use anything from CodeGenTarget, so it seems to belong in CodeGenRegBank.
1 parent 66911b7 commit 592e596

File tree

5 files changed

+57
-56
lines changed

5 files changed

+57
-56
lines changed

llvm/utils/TableGen/Common/CodeGenRegisters.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2623,6 +2623,55 @@ CodeGenRegBank::getMinimalPhysRegClass(const Record *RegRecord,
26232623
return BestRC;
26242624
}
26252625

2626+
const CodeGenRegisterClass *
2627+
CodeGenRegBank::getSuperRegForSubReg(const ValueTypeByHwMode &ValueTy,
2628+
const CodeGenSubRegIndex *SubIdx,
2629+
bool MustBeAllocatable) const {
2630+
std::vector<const CodeGenRegisterClass *> Candidates;
2631+
auto &RegClasses = getRegClasses();
2632+
2633+
// Try to find a register class which supports ValueTy, and also contains
2634+
// SubIdx.
2635+
for (const CodeGenRegisterClass &RC : RegClasses) {
2636+
// Is there a subclass of this class which contains this subregister index?
2637+
const CodeGenRegisterClass *SubClassWithSubReg =
2638+
RC.getSubClassWithSubReg(SubIdx);
2639+
if (!SubClassWithSubReg)
2640+
continue;
2641+
2642+
// We have a class. Check if it supports this value type.
2643+
if (!llvm::is_contained(SubClassWithSubReg->VTs, ValueTy))
2644+
continue;
2645+
2646+
// If necessary, check that it is allocatable.
2647+
if (MustBeAllocatable && !SubClassWithSubReg->Allocatable)
2648+
continue;
2649+
2650+
// We have a register class which supports both the value type and
2651+
// subregister index. Remember it.
2652+
Candidates.push_back(SubClassWithSubReg);
2653+
}
2654+
2655+
// If we didn't find anything, we're done.
2656+
if (Candidates.empty())
2657+
return nullptr;
2658+
2659+
// Find and return the largest of our candidate classes.
2660+
llvm::stable_sort(Candidates, [&](const CodeGenRegisterClass *A,
2661+
const CodeGenRegisterClass *B) {
2662+
if (A->getMembers().size() > B->getMembers().size())
2663+
return true;
2664+
2665+
if (A->getMembers().size() < B->getMembers().size())
2666+
return false;
2667+
2668+
// Order by name as a tie-breaker.
2669+
return StringRef(A->getName()) < B->getName();
2670+
});
2671+
2672+
return Candidates[0];
2673+
}
2674+
26262675
BitVector
26272676
CodeGenRegBank::computeCoveredRegisters(ArrayRef<const Record *> Regs) {
26282677
SetVector<const CodeGenRegister *> Set;

llvm/utils/TableGen/Common/CodeGenRegisters.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,13 @@ class CodeGenRegBank {
831831
getMinimalPhysRegClass(const Record *RegRecord,
832832
ValueTypeByHwMode *VT = nullptr);
833833

834+
/// Return the largest register class which supports \p Ty and covers \p
835+
/// SubIdx if it exists.
836+
const CodeGenRegisterClass *
837+
getSuperRegForSubReg(const ValueTypeByHwMode &Ty,
838+
const CodeGenSubRegIndex *SubIdx,
839+
bool MustBeAllocatable = false) const;
840+
834841
// Get the sum of unit weights.
835842
unsigned getRegUnitSetWeight(const std::vector<unsigned> &Units) const {
836843
unsigned Weight = 0;

llvm/utils/TableGen/Common/CodeGenTarget.cpp

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -160,54 +160,6 @@ CodeGenRegBank &CodeGenTarget::getRegBank() const {
160160
return *RegBank;
161161
}
162162

163-
const CodeGenRegisterClass *CodeGenTarget::getSuperRegForSubReg(
164-
const ValueTypeByHwMode &ValueTy, CodeGenRegBank &RegBank,
165-
const CodeGenSubRegIndex *SubIdx, bool MustBeAllocatable) const {
166-
std::vector<const CodeGenRegisterClass *> Candidates;
167-
auto &RegClasses = RegBank.getRegClasses();
168-
169-
// Try to find a register class which supports ValueTy, and also contains
170-
// SubIdx.
171-
for (const CodeGenRegisterClass &RC : RegClasses) {
172-
// Is there a subclass of this class which contains this subregister index?
173-
const CodeGenRegisterClass *SubClassWithSubReg =
174-
RC.getSubClassWithSubReg(SubIdx);
175-
if (!SubClassWithSubReg)
176-
continue;
177-
178-
// We have a class. Check if it supports this value type.
179-
if (!llvm::is_contained(SubClassWithSubReg->VTs, ValueTy))
180-
continue;
181-
182-
// If necessary, check that it is allocatable.
183-
if (MustBeAllocatable && !SubClassWithSubReg->Allocatable)
184-
continue;
185-
186-
// We have a register class which supports both the value type and
187-
// subregister index. Remember it.
188-
Candidates.push_back(SubClassWithSubReg);
189-
}
190-
191-
// If we didn't find anything, we're done.
192-
if (Candidates.empty())
193-
return nullptr;
194-
195-
// Find and return the largest of our candidate classes.
196-
llvm::stable_sort(Candidates, [&](const CodeGenRegisterClass *A,
197-
const CodeGenRegisterClass *B) {
198-
if (A->getMembers().size() > B->getMembers().size())
199-
return true;
200-
201-
if (A->getMembers().size() < B->getMembers().size())
202-
return false;
203-
204-
// Order by name as a tie-breaker.
205-
return StringRef(A->getName()) < B->getName();
206-
});
207-
208-
return Candidates[0];
209-
}
210-
211163
/// getRegisterByName - If there is a register with the specific AsmName,
212164
/// return it.
213165
const CodeGenRegister *CodeGenTarget::getRegisterByName(StringRef Name) const {

llvm/utils/TableGen/Common/CodeGenTarget.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,6 @@ class CodeGenTarget {
122122
/// getRegBank - Return the register bank description.
123123
CodeGenRegBank &getRegBank() const;
124124

125-
/// Return the largest register class on \p RegBank which supports \p Ty and
126-
/// covers \p SubIdx if it exists.
127-
const CodeGenRegisterClass *
128-
getSuperRegForSubReg(const ValueTypeByHwMode &Ty, CodeGenRegBank &RegBank,
129-
const CodeGenSubRegIndex *SubIdx,
130-
bool MustBeAllocatable = false) const;
131-
132125
/// getRegisterByName - If there is a register with the specific AsmName,
133126
/// return it.
134127
const CodeGenRegister *getRegisterByName(StringRef Name) const;

llvm/utils/TableGen/GlobalISelEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2019,7 +2019,7 @@ const CodeGenRegisterClass *GlobalISelEmitter::inferSuperRegisterClass(
20192019

20202020
// Use the information we found above to find a minimal register class which
20212021
// supports the subregister and type we want.
2022-
return Target.getSuperRegForSubReg(Ty.getValueTypeByHwMode(), CGRegs, SubIdx,
2022+
return CGRegs.getSuperRegForSubReg(Ty.getValueTypeByHwMode(), SubIdx,
20232023
/*MustBeAllocatable=*/true);
20242024
}
20252025

0 commit comments

Comments
 (0)