Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions llvm/utils/TableGen/Common/CodeGenRegisters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,11 +701,13 @@ CodeGenRegisterClass::CodeGenRegisterClass(CodeGenRegBank &RegBank,
Orders.resize(1 + AltOrders->size());

// Default allocation order always contains all registers.
MemberBV.resize(RegBank.getRegisters().size());
Artificial = true;
for (const Record *Element : *Elements) {
Orders[0].push_back(Element);
const CodeGenRegister *Reg = RegBank.getReg(Element);
Members.push_back(Reg);
MemberBV.set(CodeGenRegBank::getRegIndex(Reg));
Artificial &= Reg->Artificial;
if (!Reg->getSuperRegs().empty())
RegsWithSuperRegsTopoSigs.set(Reg->getTopoSig());
Expand Down Expand Up @@ -767,9 +769,11 @@ CodeGenRegisterClass::CodeGenRegisterClass(CodeGenRegBank &RegBank,
RegsWithSuperRegsTopoSigs(RegBank.getNumTopoSigs()), EnumValue(-1),
RSI(Props.RSI), CopyCost(0), Allocatable(true), AllocationPriority(0),
GlobalPriority(false), TSFlags(0) {
MemberBV.resize(RegBank.getRegisters().size());
Artificial = true;
GeneratePressureSet = false;
for (const auto R : Members) {
MemberBV.set(CodeGenRegBank::getRegIndex(R));
if (!R->getSuperRegs().empty())
RegsWithSuperRegsTopoSigs.set(R->getTopoSig());
Artificial &= R->Artificial;
Expand Down Expand Up @@ -833,7 +837,7 @@ bool CodeGenRegisterClass::hasType(const ValueTypeByHwMode &VT) const {
}

bool CodeGenRegisterClass::contains(const CodeGenRegister *Reg) const {
return llvm::binary_search(Members, Reg, deref<std::less<>>());
return MemberBV.test(CodeGenRegBank::getRegIndex(Reg));
}

unsigned CodeGenRegisterClass::getWeight(const CodeGenRegBank &RegBank) const {
Expand Down Expand Up @@ -2332,8 +2336,7 @@ void CodeGenRegBank::inferMatchingSuperRegClass(
CodeGenRegisterClass *RC,
std::list<CodeGenRegisterClass>::iterator FirstSubRegRC) {
DenseSet<const CodeGenSubRegIndex *> ImpliedSubRegIndices;
std::vector<std::pair<const CodeGenRegister *, const CodeGenRegister *>>
SubToSuperRegs;
std::vector<const CodeGenRegister *> SubRegs;
BitVector TopoSigs(getNumTopoSigs());

// Iterate subregister indices in topological order to visit larger indices
Expand All @@ -2351,15 +2354,14 @@ void CodeGenRegBank::inferMatchingSuperRegClass(

// Build list of (Sub, Super) pairs for this SubIdx, sorted by Sub. Note
// that the list may contain entries with the same Sub but different Supers.
SubToSuperRegs.clear();
SubRegs.clear();
TopoSigs.reset();
for (const CodeGenRegister *Super : RC->getMembers()) {
const CodeGenRegister *Sub = Super->getSubRegs().find(SubIdx)->second;
assert(Sub && "Missing sub-register");
SubToSuperRegs.emplace_back(Sub, Super);
SubRegs.push_back(Sub);
TopoSigs.set(Sub->getTopoSig());
}
sort(SubToSuperRegs, on_first<deref<std::less<>>>());

// Iterate over sub-register class candidates. Ignore classes created by
// this loop. They will never be useful.
Expand All @@ -2374,24 +2376,17 @@ void CodeGenRegBank::inferMatchingSuperRegClass(
// Topological shortcut: SubRC members have the wrong shape.
if (!TopoSigs.anyCommon(SubRC.getRegsWithSuperRegsTopoSigs()))
continue;
// Compute the subset of RC that maps into SubRC with a single linear scan
// through SubToSuperRegs and the members of SubRC.
// Compute the subset of RC that maps into SubRC.
CodeGenRegister::Vec SubSetVec;
auto SubI = SubRC.getMembers().begin(), SubE = SubRC.getMembers().end();
for (auto &[Sub, Super] : SubToSuperRegs) {
while (SubI != SubE && **SubI < *Sub)
++SubI;
if (SubI == SubE)
break;
if (**SubI == *Sub)
for (const auto &[Sub, Super] : zip_equal(SubRegs, RC->getMembers())) {
if (SubRC.contains(Sub))
SubSetVec.push_back(Super);
}

if (SubSetVec.empty())
continue;

// RC injects completely into SubRC.
sortAndUniqueRegisters(SubSetVec);
if (SubSetVec.size() == RC->getMembers().size()) {
SubRC.addSuperRegClass(SubIdx, RC);

Expand Down
4 changes: 3 additions & 1 deletion llvm/utils/TableGen/Common/CodeGenRegisters.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ inline bool operator==(const CodeGenRegister &A, const CodeGenRegister &B) {

class CodeGenRegisterClass {
CodeGenRegister::Vec Members;
// Bit mask of members, indexed by getRegIndex.
BitVector MemberBV;
// Allocation orders. Order[0] always contains all registers in Members.
std::vector<SmallVector<const Record *, 16>> Orders;
// Bit mask of sub-classes including this, indexed by their EnumValue.
Expand Down Expand Up @@ -752,7 +754,7 @@ class CodeGenRegBank {
CodeGenRegister *getReg(const Record *);

// Get a Register's index into the Registers array.
unsigned getRegIndex(const CodeGenRegister *Reg) const {
static unsigned getRegIndex(const CodeGenRegister *Reg) {
return Reg->EnumValue - 1;
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/utils/TableGen/RegisterInfoEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1644,7 +1644,7 @@ void RegisterInfoEmitter::runTargetDesc(raw_ostream &OS) {
for (const CodeGenRegister &Reg : Regs) {
const CodeGenRegisterClass *BaseRC = nullptr;
for (const CodeGenRegisterClass *RC : BaseClasses) {
if (is_contained(RC->getMembers(), &Reg)) {
if (RC->contains(&Reg)) {
BaseRC = RC;
break;
}
Expand Down
Loading