diff options
author | Owen Anderson <resistor@mac.com> | 2008-07-02 21:28:58 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2008-07-02 21:28:58 +0000 |
commit | 802af11460f090fe53710c44c061a70e5bd7aa2d (patch) | |
tree | 5e399bac4bcedc5f41d0bcbf7094c17bd2922a3b /lib/CodeGen | |
parent | d3f506a53a290aa1cc9cd341de7679c8106da543 (diff) |
TwoAddressInstructionPass doesn't really require LiveVariables, it just needs to update it if it's already around.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53049 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r-- | lib/CodeGen/TwoAddressInstructionPass.cpp | 81 |
1 files changed, 67 insertions, 14 deletions
diff --git a/lib/CodeGen/TwoAddressInstructionPass.cpp b/lib/CodeGen/TwoAddressInstructionPass.cpp index 59ad13781c..f6e2f55b30 100644 --- a/lib/CodeGen/TwoAddressInstructionPass.cpp +++ b/lib/CodeGen/TwoAddressInstructionPass.cpp @@ -74,7 +74,6 @@ namespace { 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 @@ bool TwoAddressInstructionPass::Sink3AddrInstruction(MachineBasicBlock *MBB, 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 @@ bool TwoAddressInstructionPass::runOnMachineFunction(MachineFunction &MF) { MRI = &MF.getRegInfo(); TII = TM.getInstrInfo(); TRI = TM.getRegisterInfo(); - LV = &getAnalysis<LiveVariables>(); + LV = getAnalysisToUpdate<LiveVariables>(); bool MadeChange = false; @@ -373,7 +375,32 @@ bool TwoAddressInstructionPass::runOnMachineFunction(MachineFunction &MF) { 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 @@ bool TwoAddressInstructionPass::runOnMachineFunction(MachineFunction &MF) { 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() && |