TwoAddressInstructionPass.cpp (199481) | TwoAddressInstructionPass.cpp (199511) |
---|---|
1//===-- TwoAddressInstructionPass.cpp - Two-Address instruction pass ------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// --- 98 unchanged lines hidden (view full) --- 107 unsigned RegB, unsigned Dist); 108 109 typedef std::pair<std::pair<unsigned, bool>, MachineInstr*> NewKill; 110 bool canUpdateDeletedKills(SmallVector<unsigned, 4> &Kills, 111 SmallVector<NewKill, 4> &NewKills, 112 MachineBasicBlock *MBB, unsigned Dist); 113 bool DeleteUnusedInstr(MachineBasicBlock::iterator &mi, 114 MachineBasicBlock::iterator &nmi, | 1//===-- TwoAddressInstructionPass.cpp - Two-Address instruction pass ------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// --- 98 unchanged lines hidden (view full) --- 107 unsigned RegB, unsigned Dist); 108 109 typedef std::pair<std::pair<unsigned, bool>, MachineInstr*> NewKill; 110 bool canUpdateDeletedKills(SmallVector<unsigned, 4> &Kills, 111 SmallVector<NewKill, 4> &NewKills, 112 MachineBasicBlock *MBB, unsigned Dist); 113 bool DeleteUnusedInstr(MachineBasicBlock::iterator &mi, 114 MachineBasicBlock::iterator &nmi, |
115 MachineFunction::iterator &mbbi, 116 unsigned regB, unsigned regBIdx, unsigned Dist); | 115 MachineFunction::iterator &mbbi, unsigned Dist); |
117 118 bool TryInstructionTransform(MachineBasicBlock::iterator &mi, 119 MachineBasicBlock::iterator &nmi, 120 MachineFunction::iterator &mbbi, 121 unsigned SrcIdx, unsigned DstIdx, 122 unsigned Dist); 123 124 void ProcessCopy(MachineInstr *MI, MachineBasicBlock *MBB, --- 600 unchanged lines hidden (view full) --- 725 } 726 } 727 728 Processed.insert(MI); 729} 730 731/// isSafeToDelete - If the specified instruction does not produce any side 732/// effects and all of its defs are dead, then it's safe to delete. | 116 117 bool TryInstructionTransform(MachineBasicBlock::iterator &mi, 118 MachineBasicBlock::iterator &nmi, 119 MachineFunction::iterator &mbbi, 120 unsigned SrcIdx, unsigned DstIdx, 121 unsigned Dist); 122 123 void ProcessCopy(MachineInstr *MI, MachineBasicBlock *MBB, --- 600 unchanged lines hidden (view full) --- 724 } 725 } 726 727 Processed.insert(MI); 728} 729 730/// isSafeToDelete - If the specified instruction does not produce any side 731/// effects and all of its defs are dead, then it's safe to delete. |
733static bool isSafeToDelete(MachineInstr *MI, unsigned Reg, | 732static bool isSafeToDelete(MachineInstr *MI, |
734 const TargetInstrInfo *TII, 735 SmallVector<unsigned, 4> &Kills) { 736 const TargetInstrDesc &TID = MI->getDesc(); 737 if (TID.mayStore() || TID.isCall()) 738 return false; 739 if (TID.isTerminator() || TID.hasUnmodeledSideEffects()) 740 return false; 741 742 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { 743 MachineOperand &MO = MI->getOperand(i); 744 if (!MO.isReg()) 745 continue; 746 if (MO.isDef() && !MO.isDead()) 747 return false; | 733 const TargetInstrInfo *TII, 734 SmallVector<unsigned, 4> &Kills) { 735 const TargetInstrDesc &TID = MI->getDesc(); 736 if (TID.mayStore() || TID.isCall()) 737 return false; 738 if (TID.isTerminator() || TID.hasUnmodeledSideEffects()) 739 return false; 740 741 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { 742 MachineOperand &MO = MI->getOperand(i); 743 if (!MO.isReg()) 744 continue; 745 if (MO.isDef() && !MO.isDead()) 746 return false; |
748 if (MO.isUse() && MO.getReg() != Reg && MO.isKill()) | 747 if (MO.isUse() && MO.isKill()) |
749 Kills.push_back(MO.getReg()); 750 } | 748 Kills.push_back(MO.getReg()); 749 } |
751 | |
752 return true; 753} 754 755/// canUpdateDeletedKills - Check if all the registers listed in Kills are 756/// killed by instructions in MBB preceding the current instruction at 757/// position Dist. If so, return true and record information about the 758/// preceding kills in NewKills. 759bool TwoAddressInstructionPass:: --- 18 unchanged lines hidden (view full) --- 778} 779 780/// DeleteUnusedInstr - If an instruction with a tied register operand can 781/// be safely deleted, just delete it. 782bool 783TwoAddressInstructionPass::DeleteUnusedInstr(MachineBasicBlock::iterator &mi, 784 MachineBasicBlock::iterator &nmi, 785 MachineFunction::iterator &mbbi, | 750 return true; 751} 752 753/// canUpdateDeletedKills - Check if all the registers listed in Kills are 754/// killed by instructions in MBB preceding the current instruction at 755/// position Dist. If so, return true and record information about the 756/// preceding kills in NewKills. 757bool TwoAddressInstructionPass:: --- 18 unchanged lines hidden (view full) --- 776} 777 778/// DeleteUnusedInstr - If an instruction with a tied register operand can 779/// be safely deleted, just delete it. 780bool 781TwoAddressInstructionPass::DeleteUnusedInstr(MachineBasicBlock::iterator &mi, 782 MachineBasicBlock::iterator &nmi, 783 MachineFunction::iterator &mbbi, |
786 unsigned regB, unsigned regBIdx, | |
787 unsigned Dist) { 788 // Check if the instruction has no side effects and if all its defs are dead. 789 SmallVector<unsigned, 4> Kills; | 784 unsigned Dist) { 785 // Check if the instruction has no side effects and if all its defs are dead. 786 SmallVector<unsigned, 4> Kills; |
790 if (!isSafeToDelete(mi, regB, TII, Kills)) | 787 if (!isSafeToDelete(mi, TII, Kills)) |
791 return false; 792 793 // If this instruction kills some virtual registers, we need to 794 // update the kill information. If it's not possible to do so, 795 // then bail out. 796 SmallVector<NewKill, 4> NewKills; 797 if (!canUpdateDeletedKills(Kills, NewKills, &*mbbi, Dist)) 798 return false; --- 6 unchanged lines hidden (view full) --- 805 NewKills.pop_back(); 806 if (LV->removeVirtualRegisterKilled(Kill, mi)) { 807 if (isDead) 808 LV->addVirtualRegisterDead(Kill, NewKill); 809 else 810 LV->addVirtualRegisterKilled(Kill, NewKill); 811 } 812 } | 788 return false; 789 790 // If this instruction kills some virtual registers, we need to 791 // update the kill information. If it's not possible to do so, 792 // then bail out. 793 SmallVector<NewKill, 4> NewKills; 794 if (!canUpdateDeletedKills(Kills, NewKills, &*mbbi, Dist)) 795 return false; --- 6 unchanged lines hidden (view full) --- 802 NewKills.pop_back(); 803 if (LV->removeVirtualRegisterKilled(Kill, mi)) { 804 if (isDead) 805 LV->addVirtualRegisterDead(Kill, NewKill); 806 else 807 LV->addVirtualRegisterKilled(Kill, NewKill); 808 } 809 } |
813 814 // If regB was marked as a kill, update its Kills list. 815 if (mi->getOperand(regBIdx).isKill()) 816 LV->removeVirtualRegisterKilled(regB, mi); | |
817 } 818 819 mbbi->erase(mi); // Nuke the old inst. 820 mi = nmi; 821 return true; 822} 823 824/// TryInstructionTransform - For the case where an instruction has a single --- 12 unchanged lines hidden (view full) --- 837 838 assert(TargetRegisterInfo::isVirtualRegister(regB) && 839 "cannot make instruction into two-address form"); 840 841 // If regA is dead and the instruction can be deleted, just delete 842 // it so it doesn't clobber regB. 843 bool regBKilled = isKilled(*mi, regB, MRI, TII); 844 if (!regBKilled && mi->getOperand(DstIdx).isDead() && | 810 } 811 812 mbbi->erase(mi); // Nuke the old inst. 813 mi = nmi; 814 return true; 815} 816 817/// TryInstructionTransform - For the case where an instruction has a single --- 12 unchanged lines hidden (view full) --- 830 831 assert(TargetRegisterInfo::isVirtualRegister(regB) && 832 "cannot make instruction into two-address form"); 833 834 // If regA is dead and the instruction can be deleted, just delete 835 // it so it doesn't clobber regB. 836 bool regBKilled = isKilled(*mi, regB, MRI, TII); 837 if (!regBKilled && mi->getOperand(DstIdx).isDead() && |
845 DeleteUnusedInstr(mi, nmi, mbbi, regB, SrcIdx, Dist)) { | 838 DeleteUnusedInstr(mi, nmi, mbbi, Dist)) { |
846 ++NumDeletes; 847 return true; // Done with this instruction. 848 } 849 850 // Check if it is profitable to commute the operands. 851 unsigned SrcOp1, SrcOp2; 852 unsigned regC = 0; 853 unsigned regCIdx = ~0U; --- 263 unchanged lines hidden --- | 839 ++NumDeletes; 840 return true; // Done with this instruction. 841 } 842 843 // Check if it is profitable to commute the operands. 844 unsigned SrcOp1, SrcOp2; 845 unsigned regC = 0; 846 unsigned regCIdx = ~0U; --- 263 unchanged lines hidden --- |