Skip to content

LiveVariables: Use Register #120204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 17, 2024
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
8 changes: 4 additions & 4 deletions llvm/include/llvm/CodeGen/LiveVariables.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ class LiveVariables {

void HandlePhysRegUse(Register Reg, MachineInstr &MI);
void HandlePhysRegDef(Register Reg, MachineInstr *MI,
SmallVectorImpl<unsigned> &Defs);
void UpdatePhysRegDefs(MachineInstr &MI, SmallVectorImpl<unsigned> &Defs);
SmallVectorImpl<Register> &Defs);
void UpdatePhysRegDefs(MachineInstr &MI, SmallVectorImpl<Register> &Defs);

/// FindLastRefOrPartRef - Return the last reference or partial reference of
/// the specified register.
Expand All @@ -167,15 +167,15 @@ class LiveVariables {
/// register. Also returns the sub-registers that're defined by the
/// instruction.
MachineInstr *FindLastPartialDef(Register Reg,
SmallSet<unsigned, 4> &PartDefRegs);
SmallSet<Register, 4> &PartDefRegs);

/// analyzePHINodes - Gather information about the PHI nodes in here. In
/// particular, we want to map the variable information of a virtual
/// register which is used in a PHI node. We map that to the BB the vreg
/// is coming from.
void analyzePHINodes(const MachineFunction& Fn);

void runOnInstr(MachineInstr &MI, SmallVectorImpl<unsigned> &Defs,
void runOnInstr(MachineInstr &MI, SmallVectorImpl<Register> &Defs,
unsigned NumRegs);

void runOnBlock(MachineBasicBlock *MBB, unsigned NumRegs);
Expand Down
30 changes: 15 additions & 15 deletions llvm/lib/CodeGen/LiveVariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ void LiveVariables::HandleVirtRegDef(Register Reg, MachineInstr &MI) {
/// Also returns the sub-registers that're defined by the instruction.
MachineInstr *
LiveVariables::FindLastPartialDef(Register Reg,
SmallSet<unsigned, 4> &PartDefRegs) {
unsigned LastDefReg = 0;
SmallSet<Register, 4> &PartDefRegs) {
Register LastDefReg = 0;
unsigned LastDefDist = 0;
MachineInstr *LastDef = nullptr;
for (MCPhysReg SubReg : TRI->subregs(Reg)) {
Expand Down Expand Up @@ -264,14 +264,14 @@ void LiveVariables::HandlePhysRegUse(Register Reg, MachineInstr &MI) {
// ...
// = EAX
// All of the sub-registers must have been defined before the use of Reg!
SmallSet<unsigned, 4> PartDefRegs;
SmallSet<Register, 4> PartDefRegs;
MachineInstr *LastPartialDef = FindLastPartialDef(Reg, PartDefRegs);
// If LastPartialDef is NULL, it must be using a livein register.
if (LastPartialDef) {
LastPartialDef->addOperand(MachineOperand::CreateReg(Reg, true/*IsDef*/,
true/*IsImp*/));
PhysRegDef[Reg] = LastPartialDef;
SmallSet<unsigned, 8> Processed;
SmallSet<MCPhysReg, 8> Processed;
for (MCPhysReg SubReg : TRI->subregs(Reg)) {
if (Processed.count(SubReg))
continue;
Expand Down Expand Up @@ -460,7 +460,7 @@ void LiveVariables::HandleRegMask(const MachineOperand &MO, unsigned NumRegs) {
}

void LiveVariables::HandlePhysRegDef(Register Reg, MachineInstr *MI,
SmallVectorImpl<unsigned> &Defs) {
SmallVectorImpl<Register> &Defs) {
// What parts of the register are previously defined?
SmallSet<unsigned, 32> Live;
if (PhysRegDef[Reg] || PhysRegUse[Reg]) {
Expand Down Expand Up @@ -499,7 +499,7 @@ void LiveVariables::HandlePhysRegDef(Register Reg, MachineInstr *MI,
}

void LiveVariables::UpdatePhysRegDefs(MachineInstr &MI,
SmallVectorImpl<unsigned> &Defs) {
SmallVectorImpl<Register> &Defs) {
while (!Defs.empty()) {
Register Reg = Defs.pop_back_val();
for (MCPhysReg SubReg : TRI->subregs_inclusive(Reg)) {
Expand All @@ -510,7 +510,7 @@ void LiveVariables::UpdatePhysRegDefs(MachineInstr &MI,
}

void LiveVariables::runOnInstr(MachineInstr &MI,
SmallVectorImpl<unsigned> &Defs,
SmallVectorImpl<Register> &Defs,
unsigned NumRegs) {
assert(!MI.isDebugOrPseudoInstr());
// Process all of the operands of the instruction...
Expand All @@ -522,16 +522,16 @@ void LiveVariables::runOnInstr(MachineInstr &MI,
NumOperandsToProcess = 1;

// Clear kill and dead markers. LV will recompute them.
SmallVector<unsigned, 4> UseRegs;
SmallVector<unsigned, 4> DefRegs;
SmallVector<Register, 4> UseRegs;
SmallVector<Register, 4> DefRegs;
SmallVector<unsigned, 1> RegMasks;
for (unsigned i = 0; i != NumOperandsToProcess; ++i) {
MachineOperand &MO = MI.getOperand(i);
if (MO.isRegMask()) {
RegMasks.push_back(i);
continue;
}
if (!MO.isReg() || MO.getReg() == 0)
if (!MO.isReg() || !MO.getReg())
continue;
Register MOReg = MO.getReg();
if (MO.isUse()) {
Expand All @@ -551,8 +551,8 @@ void LiveVariables::runOnInstr(MachineInstr &MI,

MachineBasicBlock *MBB = MI.getParent();
// Process all uses.
for (unsigned MOReg : UseRegs) {
if (Register::isVirtualRegister(MOReg))
for (Register MOReg : UseRegs) {
if (MOReg.isVirtual())
HandleVirtRegUse(MOReg, MBB, MI);
else if (!MRI->isReserved(MOReg))
HandlePhysRegUse(MOReg, MI);
Expand All @@ -563,8 +563,8 @@ void LiveVariables::runOnInstr(MachineInstr &MI,
HandleRegMask(MI.getOperand(Mask), NumRegs);

// Process all defs.
for (unsigned MOReg : DefRegs) {
if (Register::isVirtualRegister(MOReg))
for (Register MOReg : DefRegs) {
if (MOReg.isVirtual())
HandleVirtRegDef(MOReg, MI);
else if (!MRI->isReserved(MOReg))
HandlePhysRegDef(MOReg, &MI, Defs);
Expand All @@ -574,7 +574,7 @@ void LiveVariables::runOnInstr(MachineInstr &MI,

void LiveVariables::runOnBlock(MachineBasicBlock *MBB, unsigned NumRegs) {
// Mark live-in registers as live-in.
SmallVector<unsigned, 4> Defs;
SmallVector<Register, 4> Defs;
for (const auto &LI : MBB->liveins()) {
assert(Register::isPhysicalRegister(LI.PhysReg) &&
"Cannot have a live-in virtual register!");
Expand Down
Loading