Skip to content

Commit 64bf6e4

Browse files
committed
Use MCRegUnitMaskIterator instead
1 parent 473ce09 commit 64bf6e4

File tree

3 files changed

+17
-50
lines changed

3 files changed

+17
-50
lines changed

llvm/include/llvm/CodeGen/TargetRegisterInfo.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -745,15 +745,6 @@ class TargetRegisterInfo : public MCRegisterInfo {
745745
return reverseComposeSubRegIndexLaneMaskImpl(IdxA, LaneMask);
746746
}
747747

748-
/// Returns the number of allocatable sub registers for R, which is the
749-
/// number of register units that are not artificial and part of an
750-
/// allocatable register class. For a register like D0_D1, which consists of
751-
/// D0 and D1, this function would return '2'. For an architecture where
752-
/// D0=S0_S1 and D1=S2_S3, this would return '4' for S0, S1, S2, S3.
753-
unsigned getNumAllocatableSubRegs(MCPhysReg R) const {
754-
return getNumAllocatableSubRegsImpl(R);
755-
}
756-
757748
/// Debugging helper: dump register in human readable form to dbgs() stream.
758749
static void dumpReg(Register Reg, unsigned SubRegIndex = 0,
759750
const TargetRegisterInfo *TRI = nullptr);
@@ -783,10 +774,6 @@ class TargetRegisterInfo : public MCRegisterInfo {
783774
llvm_unreachable("Target has no sub-registers");
784775
}
785776

786-
virtual unsigned getNumAllocatableSubRegsImpl(MCPhysReg) const {
787-
llvm_unreachable("Target has no sub-registers");
788-
}
789-
790777
/// Return the register cost table index. This implementation is sufficient
791778
/// for most architectures and can be overriden by targets in case there are
792779
/// multiple cost values associated with each register.

llvm/lib/CodeGen/LiveIntervals.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,16 @@ void LiveIntervals::addKillFlags(const VirtRegMap *VRM) {
730730
// Find the regunit intervals for the assigned register. They may overlap
731731
// the virtual register live range, cancelling any kills.
732732
RU.clear();
733-
for (MCRegUnit Unit : TRI->regunits(PhysReg)) {
733+
LaneBitmask ArtificialLanes = LaneBitmask::getNone();
734+
for (MCRegUnitMaskIterator UI(PhysReg, TRI); UI.isValid(); ++UI) {
735+
auto [Unit, Bitmask] = *UI;
736+
// Record lane mask for all artificial RegUnits for this physreg.
737+
for (MCRegUnitRootIterator Root(Unit, TRI); Root.isValid(); ++Root) {
738+
if (TRI->isArtificial(*Root)) {
739+
ArtificialLanes |= Bitmask;
740+
break;
741+
}
742+
}
734743
const LiveRange &RURange = getRegUnit(Unit);
735744
if (RURange.empty())
736745
continue;
@@ -770,9 +779,6 @@ void LiveIntervals::addKillFlags(const VirtRegMap *VRM) {
770779
if (MRI->subRegLivenessEnabled()) {
771780
// When reading a partial undefined value we must not add a kill flag.
772781
// The regalloc might have used the undef lane for something else.
773-
// If the register consists of a single allocatable subreg, then
774-
// we can assume the other (undef) lanes cannot be used.
775-
//
776782
// Example:
777783
// %1 = ... ; R32: %1
778784
// %2:high16 = ... ; R64: %2
@@ -783,9 +789,13 @@ void LiveIntervals::addKillFlags(const VirtRegMap *VRM) {
783789
// are actually never written by %2. After assignment the <kill>
784790
// flag at the read instruction is invalid.
785791
LaneBitmask DefinedLanesMask;
786-
if (LI.hasSubRanges() && TRI->getNumAllocatableSubRegs(PhysReg) > 1) {
792+
if (LI.hasSubRanges()) {
787793
// Compute a mask of lanes that are defined.
788-
DefinedLanesMask = LaneBitmask::getNone();
794+
// Artificial regunits are not independently allocatable so the
795+
// register allocator cannot have used them to represent any other
796+
// values. That's why we mark them as 'defined' here, as this
797+
// otherwise prevents kill flags from being added.
798+
DefinedLanesMask = ArtificialLanes;
789799
for (const LiveInterval::SubRange &SR : LI.subranges())
790800
for (const LiveRange::Segment &Segment : SR.segments) {
791801
if (Segment.start >= RI->end)

llvm/utils/TableGen/RegisterInfoEmitter.cpp

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ class RegisterInfoEmitter {
9393
void EmitRegUnitPressure(raw_ostream &OS, StringRef ClassName);
9494
void emitComposeSubRegIndices(raw_ostream &OS, StringRef ClassName);
9595
void emitComposeSubRegIndexLaneMask(raw_ostream &OS, StringRef ClassName);
96-
void emitNumAllocatableSubRegs(raw_ostream &OS, StringRef ClassName,
97-
llvm::BitVector &InAllocClass);
9896
};
9997

10098
} // end anonymous namespace
@@ -679,31 +677,6 @@ static bool combine(const CodeGenSubRegIndex *Idx,
679677
return true;
680678
}
681679

682-
void RegisterInfoEmitter::emitNumAllocatableSubRegs(
683-
raw_ostream &OS, StringRef ClassName, llvm::BitVector &InAllocClass) {
684-
OS << "unsigned " << ClassName
685-
<< "::getNumAllocatableSubRegsImpl(MCPhysReg R) const {\n";
686-
OS << " static unsigned numAllocatableSubRegsMap[] = { \n";
687-
OS << " 0, // NoRegister\n";
688-
const auto &Regs = RegBank.getRegisters();
689-
for (auto [I, R] : llvm::enumerate(Regs)) {
690-
unsigned NumAllocatableSubRegs = 0;
691-
for (unsigned U : R.getRegUnits()) {
692-
for (const CodeGenRegister *UR : RegBank.getRegUnit(U).getRoots())
693-
if (!UR->Artificial && InAllocClass[UR->EnumValue])
694-
NumAllocatableSubRegs++;
695-
}
696-
OS << " " << NumAllocatableSubRegs;
697-
if (I < Regs.size() - 1)
698-
OS << ",";
699-
OS << " // " << R.getName() << "\n";
700-
}
701-
OS << " };\n";
702-
OS << " assert(R <= " << Regs.size() << " && \"Unexpected physreg\");\n";
703-
OS << " return numAllocatableSubRegsMap[R];\n";
704-
OS << "};\n";
705-
}
706-
707680
void RegisterInfoEmitter::emitComposeSubRegIndices(raw_ostream &OS,
708681
StringRef ClassName) {
709682
const auto &SubRegIndices = RegBank.getSubRegIndices();
@@ -1149,9 +1122,7 @@ void RegisterInfoEmitter::runTargetHeader(raw_ostream &OS) {
11491122
<< " const TargetRegisterClass *getSubClassWithSubReg"
11501123
<< "(const TargetRegisterClass *, unsigned) const override;\n"
11511124
<< " const TargetRegisterClass *getSubRegisterClass"
1152-
<< "(const TargetRegisterClass *, unsigned) const override;\n"
1153-
<< " unsigned getNumAllocatableSubRegsImpl(MCPhysReg) const "
1154-
"override;\n";
1125+
<< "(const TargetRegisterClass *, unsigned) const override;\n";
11551126
}
11561127
OS << " const RegClassWeight &getRegClassWeight("
11571128
<< "const TargetRegisterClass *RC) const override;\n"
@@ -1512,7 +1483,6 @@ void RegisterInfoEmitter::runTargetDesc(raw_ostream &OS) {
15121483
if (!SubRegIndices.empty()) {
15131484
emitComposeSubRegIndices(OS, ClassName);
15141485
emitComposeSubRegIndexLaneMask(OS, ClassName);
1515-
emitNumAllocatableSubRegs(OS, ClassName, InAllocClass);
15161486
}
15171487

15181488
if (!SubRegIndices.empty()) {

0 commit comments

Comments
 (0)