[llvm] [WIP][CodeGen] Modifying MBB's liveins representation as into regUnits (PR #129847)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Fri May 16 03:34:56 PDT 2025
================
@@ -597,54 +596,67 @@ void MachineBasicBlock::printAsOperand(raw_ostream &OS,
printName(OS, 0);
}
-void MachineBasicBlock::removeLiveIn(MCRegister Reg, LaneBitmask LaneMask) {
- LiveInVector::iterator I = find_if(
- LiveIns, [Reg](const RegisterMaskPair &LI) { return LI.PhysReg == Reg; });
- if (I == LiveIns.end())
- return;
+void MachineBasicBlock::addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask) {
+ assert(PhysReg.isPhysical() && "live-in should be a physical register");
+ const TargetRegisterInfo *TRI = getParent()->getSubtarget().getRegisterInfo();
+ for (MCRegUnitMaskIterator U(PhysReg, TRI); U.isValid(); ++U) {
+ LaneBitmask Mask = (*U).second;
+ MCRegUnit Unit = (*U).first;
+ if ((Mask & LaneMask).any())
+ for (MCRegUnitRootIterator RootReg(Unit, TRI); RootReg.isValid();
+ ++RootReg)
+ LiveIns.insert(*RootReg);
+ }
+}
- I->LaneMask &= ~LaneMask;
- if (I->LaneMask.none())
- LiveIns.erase(I);
+void MachineBasicBlock::removeLiveIn(MCRegister Reg, LaneBitmask LaneMask) {
+ assert(Reg.isPhysical() && "live-in should be a physical register");
+ const TargetRegisterInfo *TRI = getParent()->getSubtarget().getRegisterInfo();
+ for (MCRegUnitMaskIterator U(Reg, TRI); U.isValid(); ++U) {
+ LaneBitmask Mask = (*U).second;
+ MCRegUnit Unit = (*U).first;
+ if ((Mask & LaneMask).any())
+ for (MCRegUnitRootIterator RootReg(Unit, TRI); RootReg.isValid();
+ ++RootReg)
+ LiveIns.erase(*RootReg);
+ }
}
MachineBasicBlock::livein_iterator
MachineBasicBlock::removeLiveIn(MachineBasicBlock::livein_iterator I) {
- // Get non-const version of iterator.
- LiveInVector::iterator LI = LiveIns.begin() + (I - LiveIns.begin());
- return LiveIns.erase(LI);
+ if (I == LiveIns.end())
+ return I;
+
+ DenseSet<MCRegister>::iterator start = LiveIns.begin();
+ while (start != I)
+ start++;
+ MachineBasicBlock::livein_iterator next = start;
+ LiveIns.erase(start);
+ return next++;
----------------
jayfoad wrote:
This is pretty horrible and I'm not sure it works.
**Either** leave liveins as a std::vector, in which case this code does not need to change.
**Or** remove this method altogether. It is only used in one place, in `X86FloatingPoint`, and that code can ber rewritten to do this in some other way.
https://github.com/llvm/llvm-project/pull/129847
More information about the llvm-commits
mailing list