Skip to content

Commit 4b91b83

Browse files
committed
Updated the MBB-liveins to track liveRegUnits's Root registers and their
respective use-sites
1 parent fbb6a9b commit 4b91b83

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+164
-267
lines changed

llvm/include/llvm/CodeGen/LivePhysRegs.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,12 @@ bool isPhysRegUsedAfter(Register Reg, MachineBasicBlock::iterator MBI);
202202
/// any changes were made.
203203
static inline bool recomputeLiveIns(MachineBasicBlock &MBB) {
204204
LivePhysRegs LPR;
205-
std::vector<MachineBasicBlock::RegisterMaskPair> OldLiveIns;
205+
DenseSet<MCRegister> OldLiveIns;
206206

207207
MBB.clearLiveIns(OldLiveIns);
208208
computeAndAddLiveIns(LPR, MBB);
209-
MBB.sortUniqueLiveIns();
210209

211-
const std::vector<MachineBasicBlock::RegisterMaskPair> &NewLiveIns =
212-
MBB.getLiveIns();
210+
const DenseSet<MCRegister> &NewLiveIns = MBB.getLiveIns();
213211
return OldLiveIns != NewLiveIns;
214212
}
215213

llvm/include/llvm/CodeGen/MachineBasicBlock.h

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "llvm/ADT/BitVector.h"
1717
#include "llvm/ADT/DenseMapInfo.h"
18+
#include "llvm/ADT/DenseSet.h"
1819
#include "llvm/ADT/GraphTraits.h"
1920
#include "llvm/ADT/SparseBitVector.h"
2021
#include "llvm/ADT/ilist.h"
@@ -175,12 +176,7 @@ class MachineBasicBlock
175176
std::optional<uint64_t> IrrLoopHeaderWeight;
176177

177178
/// Keep track of the physical registers that are livein of the basicblock.
178-
using LiveInVector = std::vector<RegisterMaskPair>;
179-
LiveInVector LiveIns;
180-
181-
/// Keeps track of live register units for those physical registers which
182-
/// are livein of the basicblock.
183-
BitVector LiveInRegUnits;
179+
DenseSet<MCRegister> LiveIns;
184180

185181
/// Alignment of the basic block. One if the basic block does not need to be
186182
/// aligned.
@@ -466,34 +462,17 @@ class MachineBasicBlock
466462

467463
// LiveIn management methods.
468464

469-
/// Adds the specified register as a live in. Note that it is an error to add
470-
/// the same register to the same set more than once unless the intention is
471-
/// to call sortUniqueLiveIns after all registers are added.
465+
/// Adds the live regUnits(both of its roots registers) as the live in, based
466+
/// on the LaneMask.
472467
void addLiveIn(MCRegister PhysReg,
473-
LaneBitmask LaneMask = LaneBitmask::getAll()) {
474-
LiveIns.push_back(RegisterMaskPair(PhysReg, LaneMask));
475-
addLiveInRegUnit(PhysReg, LaneMask);
476-
}
477-
void addLiveIn(const RegisterMaskPair &RegMaskPair) {
478-
LiveIns.push_back(RegMaskPair);
479-
addLiveInRegUnit(RegMaskPair.PhysReg, RegMaskPair.LaneMask);
480-
}
481-
482-
// Sets the register units for Reg based on the LaneMask in the
483-
// LiveInRegUnits.
484-
void addLiveInRegUnit(MCRegister Reg, LaneBitmask LaneMask);
485-
486-
/// Sorts and uniques the LiveIns vector. It can be significantly faster to do
487-
/// this than repeatedly calling isLiveIn before calling addLiveIn for every
488-
/// LiveIn insertion.
489-
void sortUniqueLiveIns();
468+
LaneBitmask LaneMask = LaneBitmask::getAll());
490469

491470
/// Clear live in list.
492471
void clearLiveIns();
493472

494473
/// Clear the live in list, and return the removed live in's in \p OldLiveIns.
495474
/// Requires that the vector \p OldLiveIns is empty.
496-
void clearLiveIns(std::vector<RegisterMaskPair> &OldLiveIns);
475+
void clearLiveIns(DenseSet<MCRegister> &OldLiveIns);
497476

498477
/// Add PhysReg as live in to this block, and ensure that there is a copy of
499478
/// PhysReg to a virtual register of class RC. Return the virtual register
@@ -504,16 +483,13 @@ class MachineBasicBlock
504483
void removeLiveIn(MCRegister Reg,
505484
LaneBitmask LaneMask = LaneBitmask::getAll());
506485

507-
/// Resets the register units from LiveInRegUnits for the specified regsiters.
508-
void removeLiveInRegUnit(MCRegister Reg);
509-
510486
/// Return true if the specified register is in the live in set.
511487
bool isLiveIn(MCRegister Reg,
512488
LaneBitmask LaneMask = LaneBitmask::getAll()) const;
513489

514490
// Iteration support for live in sets. These sets are kept in sorted
515491
// order by their register number.
516-
using livein_iterator = LiveInVector::const_iterator;
492+
using livein_iterator = DenseSet<MCRegister>::const_iterator;
517493

518494
/// Unlike livein_begin, this method does not check that the liveness
519495
/// information is accurate. Still for debug purposes it may be useful
@@ -534,15 +510,15 @@ class MachineBasicBlock
534510
/// Remove entry from the livein set and return iterator to the next.
535511
livein_iterator removeLiveIn(livein_iterator I);
536512

537-
const std::vector<RegisterMaskPair> &getLiveIns() const { return LiveIns; }
513+
const DenseSet<MCRegister> &getLiveIns() const { return LiveIns; }
538514

539515
class liveout_iterator {
540516
public:
541517
using iterator_category = std::input_iterator_tag;
542518
using difference_type = std::ptrdiff_t;
543-
using value_type = RegisterMaskPair;
544-
using pointer = const RegisterMaskPair *;
545-
using reference = const RegisterMaskPair &;
519+
using value_type = MCRegister;
520+
using pointer = const MCRegister *;
521+
using reference = const MCRegister &;
546522

547523
liveout_iterator(const MachineBasicBlock &MBB, MCPhysReg ExceptionPointer,
548524
MCPhysReg ExceptionSelector, bool End)
@@ -555,8 +531,7 @@ class MachineBasicBlock
555531
LiveRegI = (*BlockI)->livein_begin();
556532
if (!advanceToValidPosition())
557533
return;
558-
if (LiveRegI->PhysReg == ExceptionPointer ||
559-
LiveRegI->PhysReg == ExceptionSelector)
534+
if (*LiveRegI == ExceptionPointer || *LiveRegI == ExceptionSelector)
560535
++(*this);
561536
}
562537
}
@@ -566,9 +541,8 @@ class MachineBasicBlock
566541
++LiveRegI;
567542
if (!advanceToValidPosition())
568543
return *this;
569-
} while ((*BlockI)->isEHPad() &&
570-
(LiveRegI->PhysReg == ExceptionPointer ||
571-
LiveRegI->PhysReg == ExceptionSelector));
544+
} while ((*BlockI)->isEHPad() && (*LiveRegI == ExceptionPointer ||
545+
*LiveRegI == ExceptionSelector));
572546
return *this;
573547
}
574548

llvm/lib/CodeGen/AggressiveAntiDepBreaker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ void AggressiveAntiDepBreaker::StartBlock(MachineBasicBlock *BB) {
153153
// Examine the live-in regs of all successors.
154154
for (MachineBasicBlock *Succ : BB->successors())
155155
for (const auto &LI : Succ->liveins()) {
156-
for (MCRegAliasIterator AI(LI.PhysReg, TRI, true); AI.isValid(); ++AI) {
156+
for (MCRegAliasIterator AI(LI, TRI, true); AI.isValid(); ++AI) {
157157
unsigned Reg = *AI;
158158
State->UnionGroups(Reg, 0);
159159
KillIndices[Reg] = BB->size();

llvm/lib/CodeGen/BranchFolding.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -401,12 +401,7 @@ void BranchFolder::replaceTailWithBranchTo(MachineBasicBlock::iterator OldInst,
401401
// Merging the tails may have switched some undef operand to non-undef ones.
402402
// Add IMPLICIT_DEFS into OldMBB as necessary to have a definition of the
403403
// register.
404-
for (MachineBasicBlock::RegisterMaskPair P : NewDest.liveins()) {
405-
// We computed the liveins with computeLiveIn earlier and should only see
406-
// full registers:
407-
assert(P.LaneMask == LaneBitmask::getAll() &&
408-
"Can only handle full register.");
409-
MCRegister Reg = P.PhysReg;
404+
for (MCRegister Reg : NewDest.liveins()) {
410405
if (!LiveRegs.available(*MRI, Reg))
411406
continue;
412407
DebugLoc DL;

llvm/lib/CodeGen/BranchRelaxation.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,11 +582,10 @@ bool BranchRelaxation::fixupUnconditionalBranch(MachineInstr &MI) {
582582

583583
// Add live outs.
584584
for (const MachineBasicBlock *Succ : MBB->successors()) {
585-
for (const MachineBasicBlock::RegisterMaskPair &LiveIn : Succ->liveins())
585+
for (const MCRegister LiveIn : Succ->liveins())
586586
BranchBB->addLiveIn(LiveIn);
587587
}
588588

589-
BranchBB->sortUniqueLiveIns();
590589
BranchBB->addSuccessor(DestBB);
591590
MBB->replaceSuccessor(DestBB, BranchBB);
592591
if (TrampolineInsertionPoint == MBB)

llvm/lib/CodeGen/CriticalAntiDepBreaker.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ void CriticalAntiDepBreaker::StartBlock(MachineBasicBlock *BB) {
6666
// Examine the live-in regs of all successors.
6767
for (const MachineBasicBlock *Succ : BB->successors())
6868
for (const auto &LI : Succ->liveins()) {
69-
for (MCRegAliasIterator AI(LI.PhysReg, TRI, true); AI.isValid(); ++AI) {
70-
MCRegister Reg = *AI;
71-
Classes[Reg.id()] = reinterpret_cast<TargetRegisterClass *>(-1);
72-
KillIndices[Reg.id()] = BBSize;
69+
for (MCRegAliasIterator AI(LI, TRI, true); AI.isValid(); ++AI) {
70+
unsigned Reg = (*AI).id();
71+
Classes[Reg] = reinterpret_cast<TargetRegisterClass *>(-1);
72+
KillIndices[Reg] = BBSize;
7373
DefIndices[Reg] = ~0u;
7474
}
7575
}

llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4181,9 +4181,8 @@ bool IRTranslator::runOnMachineFunction(MachineFunction &CurMF) {
41814181
EntryBB->end());
41824182

41834183
// Update the live-in information for the new entry block.
4184-
for (const MachineBasicBlock::RegisterMaskPair &LiveIn : EntryBB->liveins())
4184+
for (const MCRegister LiveIn : EntryBB->liveins())
41854185
NewEntryBB.addLiveIn(LiveIn);
4186-
NewEntryBB.sortUniqueLiveIns();
41874186

41884187
// Get rid of the now empty basic block.
41894188
EntryBB->removeSuccessor(&NewEntryBB);

llvm/lib/CodeGen/LiveIntervals.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ void LiveIntervals::computeLiveInRegUnits() {
370370
SlotIndex Begin = Indexes->getMBBStartIdx(&MBB);
371371
LLVM_DEBUG(dbgs() << Begin << "\t" << printMBBReference(MBB));
372372
for (const auto &LI : MBB.liveins()) {
373-
for (MCRegUnit Unit : TRI->regunits(LI.PhysReg)) {
373+
for (MCRegUnit Unit : TRI->regunits(LI)) {
374374
LiveRange *LR = RegUnitRanges[Unit];
375375
if (!LR) {
376376
// Use segment set to speed-up initial computation of the live range.

llvm/lib/CodeGen/LivePhysRegs.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -153,21 +153,8 @@ bool LivePhysRegs::available(const MachineRegisterInfo &MRI,
153153

154154
/// Add live-in registers of basic block \p MBB to \p LiveRegs.
155155
void LivePhysRegs::addBlockLiveIns(const MachineBasicBlock &MBB) {
156-
for (const auto &LI : MBB.liveins()) {
157-
MCRegister Reg = LI.PhysReg;
158-
LaneBitmask Mask = LI.LaneMask;
159-
MCSubRegIndexIterator S(Reg, TRI);
160-
assert(Mask.any() && "Invalid livein mask");
161-
if (Mask.all() || !S.isValid()) {
162-
addReg(Reg);
163-
continue;
164-
}
165-
for (; S.isValid(); ++S) {
166-
unsigned SI = S.getSubRegIndex();
167-
if ((Mask & TRI->getSubRegIndexLaneMask(SI)).any())
168-
addReg(S.getSubReg());
169-
}
170-
}
156+
for (const MCRegister Reg : MBB.liveins())
157+
addReg(Reg);
171158
}
172159

173160
/// Adds all callee saved registers to \p LiveRegs.

llvm/lib/CodeGen/LiveRegUnits.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void LiveRegUnits::accumulate(const MachineInstr &MI) {
8888
static void addBlockLiveIns(LiveRegUnits &LiveUnits,
8989
const MachineBasicBlock &MBB) {
9090
for (const auto &LI : MBB.liveins())
91-
LiveUnits.addRegMasked(LI.PhysReg, LI.LaneMask);
91+
LiveUnits.addRegMasked(LI, LaneBitmask::getAll());
9292
}
9393

9494
/// Adds all callee saved registers to \p LiveUnits.

llvm/lib/CodeGen/LiveVariables.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -570,9 +570,8 @@ void LiveVariables::runOnBlock(MachineBasicBlock *MBB, unsigned NumRegs) {
570570
// Mark live-in registers as live-in.
571571
SmallVector<Register, 4> Defs;
572572
for (const auto &LI : MBB->liveins()) {
573-
assert(LI.PhysReg.isPhysical() &&
574-
"Cannot have a live-in virtual register!");
575-
HandlePhysRegDef(LI.PhysReg, nullptr, Defs);
573+
assert(LI.isPhysical() && "Cannot have a live-in virtual register!");
574+
HandlePhysRegDef(LI, nullptr, Defs);
576575
}
577576

578577
// Loop over all of the instructions, processing them.
@@ -606,9 +605,9 @@ void LiveVariables::runOnBlock(MachineBasicBlock *MBB, unsigned NumRegs) {
606605
if (SuccMBB->isEHPad())
607606
continue;
608607
for (const auto &LI : SuccMBB->liveins()) {
609-
if (!TRI->isInAllocatableClass(LI.PhysReg))
608+
if (!TRI->isInAllocatableClass(LI))
610609
// Ignore other live-ins, e.g. those that are live into landing pads.
611-
LiveOuts.insert(LI.PhysReg);
610+
LiveOuts.insert(LI);
612611
}
613612
}
614613

llvm/lib/CodeGen/MIRPrinter.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -769,13 +769,11 @@ void MIPrinter::print(const MachineBasicBlock &MBB) {
769769
const TargetRegisterInfo &TRI = *MRI.getTargetRegisterInfo();
770770
OS.indent(2) << "liveins: ";
771771
bool First = true;
772-
for (const auto &LI : MBB.liveins_dbg()) {
772+
for (const Register Reg : MBB.liveins_dbg()) {
773773
if (!First)
774774
OS << ", ";
775775
First = false;
776-
OS << printReg(LI.PhysReg, &TRI);
777-
if (!LI.LaneMask.all())
778-
OS << ":0x" << PrintLaneMask(LI.LaneMask);
776+
OS << printReg(Reg, &TRI);
779777
}
780778
OS << "\n";
781779
HasLineAttributes = true;

0 commit comments

Comments
 (0)