[llvm-commits] [llvm] r53049 - /llvm/trunk/lib/CodeGen/TwoAddressInstructionPass.cpp
Owen Anderson
resistor at mac.com
Wed Jul 2 14:29:03 PDT 2008
Author: resistor
Date: Wed Jul 2 16:28:58 2008
New Revision: 53049
URL: http://llvm.org/viewvc/llvm-project?rev=53049&view=rev
Log:
TwoAddressInstructionPass doesn't really require LiveVariables, it just needs to update it if it's already around.
Modified:
llvm/trunk/lib/CodeGen/TwoAddressInstructionPass.cpp
Modified: llvm/trunk/lib/CodeGen/TwoAddressInstructionPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TwoAddressInstructionPass.cpp?rev=53049&r1=53048&r2=53049&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/TwoAddressInstructionPass.cpp (original)
+++ llvm/trunk/lib/CodeGen/TwoAddressInstructionPass.cpp Wed Jul 2 16:28:58 2008
@@ -74,7 +74,6 @@
TwoAddressInstructionPass() : MachineFunctionPass((intptr_t)&ID) {}
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
- AU.addRequired<LiveVariables>();
AU.addPreserved<LiveVariables>();
AU.addPreservedID(MachineLoopInfoID);
AU.addPreservedID(MachineDominatorsID);
@@ -184,9 +183,12 @@
KillMO->setIsKill(false);
KillMO = MI->findRegisterUseOperand(SavedReg, false, TRI);
KillMO->setIsKill(true);
- LiveVariables::VarInfo& VarInfo = LV->getVarInfo(SavedReg);
- VarInfo.removeKill(KillMI);
- VarInfo.Kills.push_back(MI);
+
+ if (LV) {
+ LiveVariables::VarInfo& VarInfo = LV->getVarInfo(SavedReg);
+ VarInfo.removeKill(KillMI);
+ VarInfo.Kills.push_back(MI);
+ }
// Move instruction to its destination.
MBB->remove(MI);
@@ -283,7 +285,7 @@
MRI = &MF.getRegInfo();
TII = TM.getInstrInfo();
TRI = TM.getRegisterInfo();
- LV = &getAnalysis<LiveVariables>();
+ LV = getAnalysisToUpdate<LiveVariables>();
bool MadeChange = false;
@@ -373,7 +375,32 @@
DOUT << "2addr: COMMUTED TO: " << *NewMI;
// If the instruction changed to commute it, update livevar.
if (NewMI != mi) {
- LV->instructionChanged(mi, NewMI); // Update live variables
+ if (LV) {
+ // Update live variables
+ LV->instructionChanged(mi, NewMI);
+ } else {
+ // Update flags manually
+ for (unsigned i = 0, e = mi->getNumOperands();
+ i != e; ++i) {
+ MachineOperand &MO = mi->getOperand(i);
+ if (MO.isRegister() && MO.getReg() &&
+ TargetRegisterInfo::isVirtualRegister(MO.getReg())) {
+ unsigned Reg = MO.getReg();
+ if (MO.isDef()) {
+ if (MO.isDead()) {
+ MO.setIsDead(false);
+ NewMI->addRegisterDead(Reg, TRI);
+ }
+ }
+
+ if (MO.isKill()) {
+ MO.setIsKill(false);
+ NewMI->addRegisterKilled(Reg, TRI);
+ }
+ }
+ }
+ }
+
mbbi->insert(mi, NewMI); // Insert the new inst
mbbi->erase(mi); // Nuke the old inst.
mi = NewMI;
@@ -443,17 +470,43 @@
DOUT << "\t\tprepend:\t"; DEBUG(prevMi->print(*cerr.stream(), &TM));
// Update live variables for regB.
- LiveVariables::VarInfo& varInfoB = LV->getVarInfo(regB);
-
- // regB is used in this BB.
- varInfoB.UsedBlocks[mbbi->getNumber()] = true;
+ if (LV) {
+ LiveVariables::VarInfo& varInfoB = LV->getVarInfo(regB);
- if (LV->removeVirtualRegisterKilled(regB, mbbi, mi))
- LV->addVirtualRegisterKilled(regB, prevMi);
+ // regB is used in this BB.
+ varInfoB.UsedBlocks[mbbi->getNumber()] = true;
- if (LV->removeVirtualRegisterDead(regB, mbbi, mi))
- LV->addVirtualRegisterDead(regB, prevMi);
+ if (LV->removeVirtualRegisterKilled(regB, mbbi, mi))
+ LV->addVirtualRegisterKilled(regB, prevMi);
+ if (LV->removeVirtualRegisterDead(regB, mbbi, mi))
+ LV->addVirtualRegisterDead(regB, prevMi);
+ } else {
+ // Manually update kill/dead flags.
+ bool RemovedKill = false;
+ bool RemovedDead = false;
+ for (unsigned i = 0, e = mi->getNumOperands(); i != e; ++i) {
+ MachineOperand &MO = mi->getOperand(i);
+ if (MO.isRegister() && MO.isKill() && MO.getReg() == regB) {
+ MO.setIsKill(false);
+ RemovedKill = true;
+ break;
+ }
+
+ if (MO.isRegister() && MO.isDef() && MO.getReg() == regB) {
+ MO.setIsDead(false);
+ RemovedDead = true;
+ }
+
+ if (RemovedKill && RemovedDead) break;
+ }
+
+ if (RemovedKill)
+ prevMi->addRegisterKilled(regB, TRI);
+ if (RemovedDead)
+ prevMi->addRegisterDead(regB, TRI);
+ }
+
// Replace all occurences of regB with regA.
for (unsigned i = 0, e = mi->getNumOperands(); i != e; ++i) {
if (mi->getOperand(i).isRegister() &&
More information about the llvm-commits
mailing list