Skip to content

Commit 8cadfdf

Browse files
author
Krzysztof Parzyszek
committed
[TableGen] Fix CodeGenRegisterClass::hasType for simple-type arguments
The `hasType` function may be given a type that has been modified from its original form (in particular made "simple", due to a predicate). Make sure that such a type is still recognized as associated with a register class, if the class contains it under any hw-mode. This is somewhat optimistic though, since there is no information as to where that simple type originated from.
1 parent 6817031 commit 8cadfdf

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

llvm/utils/TableGen/CodeGenRegisters.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,26 @@ void CodeGenRegisterClass::inheritProperties(CodeGenRegBank &RegBank) {
861861
Orders[i].push_back(Super.Orders[i][j]);
862862
}
863863

864+
bool CodeGenRegisterClass::hasType(const ValueTypeByHwMode &VT) const {
865+
if (llvm::is_contained(VTs, VT))
866+
return true;
867+
868+
// If VT is not identical to any of this class's types, but is a simple
869+
// type, check if any of the types for this class contain it under some
870+
// mode.
871+
// The motivating example came from RISCV, where (likely because of being
872+
// guarded by "64-bit" predicate), the type of X5 was {*:[i64]}, but the
873+
// type in GRC was {*:[i32], m1:[i64]}.
874+
if (VT.isSimple()) {
875+
MVT T = VT.getSimple();
876+
for (const ValueTypeByHwMode &OurVT : VTs) {
877+
if (llvm::count_if(OurVT, [T](auto &&P) { return P.second == T; }))
878+
return true;
879+
}
880+
}
881+
return false;
882+
}
883+
864884
bool CodeGenRegisterClass::contains(const CodeGenRegister *Reg) const {
865885
return std::binary_search(Members.begin(), Members.end(), Reg,
866886
deref<std::less<>>());

llvm/utils/TableGen/CodeGenRegisters.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,7 @@ namespace llvm {
351351
std::string getQualifiedName() const;
352352
ArrayRef<ValueTypeByHwMode> getValueTypes() const { return VTs; }
353353
unsigned getNumValueTypes() const { return VTs.size(); }
354-
355-
bool hasType(const ValueTypeByHwMode &VT) const {
356-
return llvm::is_contained(VTs, VT);
357-
}
354+
bool hasType(const ValueTypeByHwMode &VT) const;
358355

359356
const ValueTypeByHwMode &getValueTypeNum(unsigned VTNum) const {
360357
if (VTNum < VTs.size())

0 commit comments

Comments
 (0)