From b487e7215c4f70f3d98f8fbc0a11eb119afc1f37 Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Thu, 24 Jan 2008 01:10:07 +0000 Subject: [PATCH] Move some functionality for adding flags to MachineInstr's into methods on MachineInstr rather than LiveVariables. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@46295 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/LiveVariables.h | 25 +----- include/llvm/CodeGen/MachineInstr.h | 19 +++++ lib/CodeGen/LiveIntervalAnalysis.cpp | 2 +- lib/CodeGen/LiveVariables.cpp | 120 ++++----------------------- lib/CodeGen/MachineInstr.cpp | 90 ++++++++++++++++++++ 5 files changed, 126 insertions(+), 130 deletions(-) diff --git a/include/llvm/CodeGen/LiveVariables.h b/include/llvm/CodeGen/LiveVariables.h index a392cdaffbd..5c714e308aa 100644 --- a/include/llvm/CodeGen/LiveVariables.h +++ b/include/llvm/CodeGen/LiveVariables.h @@ -196,26 +196,13 @@ public: /// the records for NewMI. void instructionChanged(MachineInstr *OldMI, MachineInstr *NewMI); - /// transferKillDeadInfo - Similar to instructionChanged except it does not - /// update live variables internal data structures. - static void transferKillDeadInfo(MachineInstr *OldMI, MachineInstr *NewMI, - const MRegisterInfo *RegInfo); - - /// addRegisterKilled - We have determined MI kills a register. Look for the - /// operand that uses it and mark it as IsKill. If AddIfNotFound is true, - /// add a implicit operand if it's not found. Returns true if the operand - /// exists / is added. - static bool addRegisterKilled(unsigned IncomingReg, MachineInstr *MI, - const MRegisterInfo *RegInfo, - bool AddIfNotFound = false); - /// addVirtualRegisterKilled - Add information about the fact that the /// specified register is killed after being used by the specified /// instruction. If AddIfNotFound is true, add a implicit operand if it's /// not found. void addVirtualRegisterKilled(unsigned IncomingReg, MachineInstr *MI, bool AddIfNotFound = false) { - if (addRegisterKilled(IncomingReg, MI, RegInfo, AddIfNotFound)) + if (MI->addRegisterKilled(IncomingReg, RegInfo, AddIfNotFound)) getVarInfo(IncomingReg).Kills.push_back(MI); } @@ -246,21 +233,13 @@ public: /// removeVirtualRegistersKilled - Remove all killed info for the specified /// instruction. void removeVirtualRegistersKilled(MachineInstr *MI); - - /// addRegisterDead - We have determined MI defined a register without a use. - /// Look for the operand that defines it and mark it as IsDead. If - /// AddIfNotFound is true, add a implicit operand if it's not found. Returns - /// true if the operand exists / is added. - static bool addRegisterDead(unsigned IncomingReg, MachineInstr *MI, - const MRegisterInfo *RegInfo, - bool AddIfNotFound = false); /// addVirtualRegisterDead - Add information about the fact that the specified /// register is dead after being used by the specified instruction. If /// AddIfNotFound is true, add a implicit operand if it's not found. void addVirtualRegisterDead(unsigned IncomingReg, MachineInstr *MI, bool AddIfNotFound = false) { - if (addRegisterDead(IncomingReg, MI, RegInfo, AddIfNotFound)) + if (MI->addRegisterDead(IncomingReg, RegInfo, AddIfNotFound)) getVarInfo(IncomingReg).Kills.push_back(MI); } diff --git a/include/llvm/CodeGen/MachineInstr.h b/include/llvm/CodeGen/MachineInstr.h index 749d1f9a9ae..068c335c7d1 100644 --- a/include/llvm/CodeGen/MachineInstr.h +++ b/include/llvm/CodeGen/MachineInstr.h @@ -21,6 +21,7 @@ namespace llvm { class TargetInstrDesc; +class MRegisterInfo; template struct ilist_traits; template struct ilist; @@ -144,6 +145,24 @@ public: /// copyPredicates - Copies predicate operand(s) from MI. void copyPredicates(const MachineInstr *MI); + /// addRegisterKilled - We have determined MI kills a register. Look for the + /// operand that uses it and mark it as IsKill. If AddIfNotFound is true, + /// add a implicit operand if it's not found. Returns true if the operand + /// exists / is added. + bool addRegisterKilled(unsigned IncomingReg, const MRegisterInfo *RegInfo, + bool AddIfNotFound = false); + + /// addRegisterDead - We have determined MI defined a register without a use. + /// Look for the operand that defines it and mark it as IsDead. If + /// AddIfNotFound is true, add a implicit operand if it's not found. Returns + /// true if the operand exists / is added. + bool addRegisterDead(unsigned IncomingReg, const MRegisterInfo *RegInfo, + bool AddIfNotFound = false); + + /// copyKillDeadInfo - copies killed/dead information from one instr to another + void copyKillDeadInfo(MachineInstr *OldMI, + const MRegisterInfo *RegInfo); + // // Debugging support // diff --git a/lib/CodeGen/LiveIntervalAnalysis.cpp b/lib/CodeGen/LiveIntervalAnalysis.cpp index da76269c68f..5ac8b346012 100644 --- a/lib/CodeGen/LiveIntervalAnalysis.cpp +++ b/lib/CodeGen/LiveIntervalAnalysis.cpp @@ -717,7 +717,7 @@ bool LiveIntervals::tryFoldMemoryOperand(MachineInstr* &MI, if (lv_) lv_->instructionChanged(MI, fmi); else - LiveVariables::transferKillDeadInfo(MI, fmi, mri_); + fmi->copyKillDeadInfo(MI, mri_); MachineBasicBlock &MBB = *MI->getParent(); if (isSS && !mf_->getFrameInfo()->isImmutableObjectIndex(Slot)) vrm.virtFolded(Reg, MI, fmi, (VirtRegMap::ModRef)MRInfo); diff --git a/lib/CodeGen/LiveVariables.cpp b/lib/CodeGen/LiveVariables.cpp index 79c3192fdfd..b39e48d4423 100644 --- a/lib/CodeGen/LiveVariables.cpp +++ b/lib/CodeGen/LiveVariables.cpp @@ -192,73 +192,6 @@ void LiveVariables::HandleVirtRegUse(unsigned reg, MachineBasicBlock *MBB, MarkVirtRegAliveInBlock(VRInfo, MRI.getVRegDef(reg)->getParent(), *PI); } -bool LiveVariables::addRegisterKilled(unsigned IncomingReg, MachineInstr *MI, - const MRegisterInfo *RegInfo, - bool AddIfNotFound) { - bool Found = false; - for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { - MachineOperand &MO = MI->getOperand(i); - if (MO.isRegister() && MO.isUse()) { - unsigned Reg = MO.getReg(); - if (!Reg) - continue; - if (Reg == IncomingReg) { - MO.setIsKill(); - Found = true; - break; - } else if (MRegisterInfo::isPhysicalRegister(Reg) && - MRegisterInfo::isPhysicalRegister(IncomingReg) && - RegInfo->isSuperRegister(IncomingReg, Reg) && - MO.isKill()) - // A super-register kill already exists. - Found = true; - } - } - - // If not found, this means an alias of one of the operand is killed. Add a - // new implicit operand if required. - if (!Found && AddIfNotFound) { - MI->addOperand(MachineOperand::CreateReg(IncomingReg, false/*IsDef*/, - true/*IsImp*/,true/*IsKill*/)); - return true; - } - return Found; -} - -bool LiveVariables::addRegisterDead(unsigned IncomingReg, MachineInstr *MI, - const MRegisterInfo *RegInfo, - bool AddIfNotFound) { - bool Found = false; - for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { - MachineOperand &MO = MI->getOperand(i); - if (MO.isRegister() && MO.isDef()) { - unsigned Reg = MO.getReg(); - if (!Reg) - continue; - if (Reg == IncomingReg) { - MO.setIsDead(); - Found = true; - break; - } else if (MRegisterInfo::isPhysicalRegister(Reg) && - MRegisterInfo::isPhysicalRegister(IncomingReg) && - RegInfo->isSuperRegister(IncomingReg, Reg) && - MO.isDead()) - // There exists a super-register that's marked dead. - return true; - } - } - - // If not found, this means an alias of one of the operand is dead. Add a - // new implicit operand. - if (!Found && AddIfNotFound) { - MI->addOperand(MachineOperand::CreateReg(IncomingReg, true/*IsDef*/, - true/*IsImp*/,false/*IsKill*/, - true/*IsDead*/)); - return true; - } - return Found; -} - void LiveVariables::HandlePhysRegUse(unsigned Reg, MachineInstr *MI) { // Turn previous partial def's into read/mod/write. for (unsigned i = 0, e = PhysRegPartDef[Reg].size(); i != e; ++i) { @@ -337,7 +270,7 @@ bool LiveVariables::HandlePhysRegKill(unsigned Reg, MachineInstr *RefMI, void LiveVariables::addRegisterKills(unsigned Reg, MachineInstr *MI, SmallSet &SubKills) { if (SubKills.count(Reg) == 0) - addRegisterKilled(Reg, MI, RegInfo, true); + MI->addRegisterKilled(Reg, RegInfo, true); else { for (const unsigned *SubRegs = RegInfo->getImmediateSubRegisters(Reg); unsigned SubReg = *SubRegs; ++SubRegs) @@ -348,7 +281,7 @@ void LiveVariables::addRegisterKills(unsigned Reg, MachineInstr *MI, bool LiveVariables::HandlePhysRegKill(unsigned Reg, MachineInstr *RefMI) { SmallSet SubKills; if (HandlePhysRegKill(Reg, RefMI, SubKills)) { - addRegisterKilled(Reg, RefMI, RegInfo, true); + RefMI->addRegisterKilled(Reg, RegInfo, true); return true; } else { // Some sub-registers are killed by another MI. @@ -365,15 +298,15 @@ void LiveVariables::HandlePhysRegDef(unsigned Reg, MachineInstr *MI) { if (PhysRegUsed[Reg]) { if (!HandlePhysRegKill(Reg, LastRef)) { if (PhysRegPartUse[Reg]) - addRegisterKilled(Reg, PhysRegPartUse[Reg], RegInfo, true); + PhysRegPartUse[Reg]->addRegisterKilled(Reg, RegInfo, true); } } else if (PhysRegPartUse[Reg]) // Add implicit use / kill to last partial use. - addRegisterKilled(Reg, PhysRegPartUse[Reg], RegInfo, true); + PhysRegPartUse[Reg]->addRegisterKilled(Reg, RegInfo, true); else if (LastRef != MI) // Defined, but not used. However, watch out for cases where a super-reg // is also defined on the same MI. - addRegisterDead(Reg, LastRef, RegInfo); + LastRef->addRegisterDead(Reg, RegInfo); } for (const unsigned *SubRegs = RegInfo->getSubRegisters(Reg); @@ -382,14 +315,14 @@ void LiveVariables::HandlePhysRegDef(unsigned Reg, MachineInstr *MI) { if (PhysRegUsed[SubReg]) { if (!HandlePhysRegKill(SubReg, LastRef)) { if (PhysRegPartUse[SubReg]) - addRegisterKilled(SubReg, PhysRegPartUse[SubReg], RegInfo, true); + PhysRegPartUse[SubReg]->addRegisterKilled(SubReg, RegInfo, true); } } else if (PhysRegPartUse[SubReg]) // Add implicit use / kill to last use of a sub-register. - addRegisterKilled(SubReg, PhysRegPartUse[SubReg], RegInfo, true); + PhysRegPartUse[SubReg]->addRegisterKilled(SubReg, RegInfo, true); else if (LastRef != MI) // This must be a def of the subreg on the same MI. - addRegisterDead(SubReg, LastRef, RegInfo); + LastRef->addRegisterDead(SubReg, RegInfo); } } @@ -565,11 +498,13 @@ bool LiveVariables::runOnMachineFunction(MachineFunction &mf) { for (unsigned j = 0, e2 = VirtRegInfo[i].Kills.size(); j != e2; ++j) { if (VirtRegInfo[i].Kills[j] == MRI.getVRegDef(i + MRegisterInfo::FirstVirtualRegister)) - addRegisterDead(i + MRegisterInfo::FirstVirtualRegister, - VirtRegInfo[i].Kills[j], RegInfo); + VirtRegInfo[i].Kills[j]->addRegisterDead(i + + MRegisterInfo::FirstVirtualRegister, + RegInfo); else - addRegisterKilled(i + MRegisterInfo::FirstVirtualRegister, - VirtRegInfo[i].Kills[j], RegInfo); + VirtRegInfo[i].Kills[j]->addRegisterKilled(i + + MRegisterInfo::FirstVirtualRegister, + RegInfo); } // Check to make sure there are no unreachable blocks in the MC CFG for the @@ -620,33 +555,6 @@ void LiveVariables::instructionChanged(MachineInstr *OldMI, } } -/// transferKillDeadInfo - Similar to instructionChanged except it does not -/// update live variables internal data structures. -void LiveVariables::transferKillDeadInfo(MachineInstr *OldMI, - MachineInstr *NewMI, - const MRegisterInfo *RegInfo) { - // If the instruction defines any virtual registers, update the VarInfo, - // kill and dead information for the instruction. - for (unsigned i = 0, e = OldMI->getNumOperands(); i != e; ++i) { - MachineOperand &MO = OldMI->getOperand(i); - if (MO.isRegister() && MO.getReg() && - MRegisterInfo::isVirtualRegister(MO.getReg())) { - unsigned Reg = MO.getReg(); - if (MO.isDef()) { - if (MO.isDead()) { - MO.setIsDead(false); - addRegisterDead(Reg, NewMI, RegInfo); - } - } - if (MO.isKill()) { - MO.setIsKill(false); - addRegisterKilled(Reg, NewMI, RegInfo); - } - } - } -} - - /// removeVirtualRegistersKilled - Remove all killed info for the specified /// instruction. void LiveVariables::removeVirtualRegistersKilled(MachineInstr *MI) { diff --git a/lib/CodeGen/MachineInstr.cpp b/lib/CodeGen/MachineInstr.cpp index 6d7f729ac83..757b3bdbc2d 100644 --- a/lib/CodeGen/MachineInstr.cpp +++ b/lib/CodeGen/MachineInstr.cpp @@ -623,3 +623,93 @@ void MachineInstr::print(std::ostream &OS, const TargetMachine *TM) const { OS << "\n"; } +bool MachineInstr::addRegisterKilled(unsigned IncomingReg, + const MRegisterInfo *RegInfo, + bool AddIfNotFound) { + bool Found = false; + for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { + MachineOperand &MO = getOperand(i); + if (MO.isRegister() && MO.isUse()) { + unsigned Reg = MO.getReg(); + if (!Reg) + continue; + if (Reg == IncomingReg) { + MO.setIsKill(); + Found = true; + break; + } else if (MRegisterInfo::isPhysicalRegister(Reg) && + MRegisterInfo::isPhysicalRegister(IncomingReg) && + RegInfo->isSuperRegister(IncomingReg, Reg) && + MO.isKill()) + // A super-register kill already exists. + Found = true; + } + } + + // If not found, this means an alias of one of the operand is killed. Add a + // new implicit operand if required. + if (!Found && AddIfNotFound) { + addOperand(MachineOperand::CreateReg(IncomingReg, false/*IsDef*/, + true/*IsImp*/,true/*IsKill*/)); + return true; + } + return Found; +} + +bool MachineInstr::addRegisterDead(unsigned IncomingReg, + const MRegisterInfo *RegInfo, + bool AddIfNotFound) { + bool Found = false; + for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { + MachineOperand &MO = getOperand(i); + if (MO.isRegister() && MO.isDef()) { + unsigned Reg = MO.getReg(); + if (!Reg) + continue; + if (Reg == IncomingReg) { + MO.setIsDead(); + Found = true; + break; + } else if (MRegisterInfo::isPhysicalRegister(Reg) && + MRegisterInfo::isPhysicalRegister(IncomingReg) && + RegInfo->isSuperRegister(IncomingReg, Reg) && + MO.isDead()) + // There exists a super-register that's marked dead. + return true; + } + } + + // If not found, this means an alias of one of the operand is dead. Add a + // new implicit operand. + if (!Found && AddIfNotFound) { + addOperand(MachineOperand::CreateReg(IncomingReg, true/*IsDef*/, + true/*IsImp*/,false/*IsKill*/, + true/*IsDead*/)); + return true; + } + return Found; +} + +/// copyKillDeadInfo - copies killed/dead information from one instr to another +void MachineInstr::copyKillDeadInfo(MachineInstr *OldMI, + const MRegisterInfo *RegInfo) { + // If the instruction defines any virtual registers, update the VarInfo, + // kill and dead information for the instruction. + for (unsigned i = 0, e = OldMI->getNumOperands(); i != e; ++i) { + MachineOperand &MO = OldMI->getOperand(i); + if (MO.isRegister() && MO.getReg() && + MRegisterInfo::isVirtualRegister(MO.getReg())) { + unsigned Reg = MO.getReg(); + if (MO.isDef()) { + if (MO.isDead()) { + MO.setIsDead(false); + addRegisterDead(Reg, RegInfo); + } + } + if (MO.isKill()) { + MO.setIsKill(false); + addRegisterKilled(Reg, RegInfo); + } + } + } +} -- 2.34.1