From 839b759c38182af8d151db10923c2a6cc7dd5b3d Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Thu, 17 Jan 2008 02:08:17 +0000 Subject: When a live virtual register is being clobbered by an implicit def, it is spilled and the spill is its kill. However, if the local allocator has determined the register has not been modified (possible when its value was reloaded), it would not issue a restore. In that case, mark the last use of the virtual register as kill. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@46111 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/RegAllocLocal.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'lib/CodeGen/RegAllocLocal.cpp') diff --git a/lib/CodeGen/RegAllocLocal.cpp b/lib/CodeGen/RegAllocLocal.cpp index 3654efd22b..4ed1849be6 100644 --- a/lib/CodeGen/RegAllocLocal.cpp +++ b/lib/CodeGen/RegAllocLocal.cpp @@ -86,6 +86,16 @@ namespace { // std::vector PhysRegsUseOrder; + // Virt2LastUseMap - This maps each virtual register to its last use + // (MachineInstr*, operand index pair). + IndexedMap, VirtReg2IndexFunctor> + Virt2LastUseMap; + + std::pair& getVirtRegLastUse(unsigned Reg) { + assert(MRegisterInfo::isVirtualRegister(Reg) && "Illegal VirtReg!"); + return Virt2LastUseMap[Reg]; + } + // VirtRegModified - This bitset contains information about which virtual // registers need to be spilled back to memory when their registers are // scavenged. If a virtual register has simply been rematerialized, there @@ -282,8 +292,12 @@ void RALocal::spillVirtReg(MachineBasicBlock &MBB, const TargetInstrInfo* TII = MBB.getParent()->getTarget().getInstrInfo(); - if (!isVirtRegModified(VirtReg)) + if (!isVirtRegModified(VirtReg)) { DOUT << " which has not been modified, so no store necessary!"; + std::pair &LastUse = getVirtRegLastUse(VirtReg); + if (LastUse.first) + LastUse.first->getOperand(LastUse.second).setIsKill(); + } // Otherwise, there is a virtual register corresponding to this physical // register. We only need to spill it into its stack slot if it has been @@ -507,6 +521,7 @@ MachineInstr *RALocal::reloadVirtReg(MachineBasicBlock &MBB, MachineInstr *MI, MF->getRegInfo().setPhysRegUsed(PhysReg); MI->getOperand(OpNum).setReg(PhysReg); // Assign the input register + getVirtRegLastUse(VirtReg) = std::make_pair(MI, OpNum); return MI; } @@ -722,6 +737,7 @@ void RALocal::AllocateBasicBlock(MachineBasicBlock &MBB) { DestPhysReg = getReg(MBB, MI, DestVirtReg); MF->getRegInfo().setPhysRegUsed(DestPhysReg); markVirtRegModified(DestVirtReg); + getVirtRegLastUse(DestVirtReg) = std::make_pair((MachineInstr*)0, 0); MI->getOperand(i).setReg(DestPhysReg); // Assign the output register } } @@ -823,7 +839,8 @@ bool RALocal::runOnMachineFunction(MachineFunction &Fn) { // mapping for all virtual registers unsigned LastVirtReg = MF->getRegInfo().getLastVirtReg(); Virt2PhysRegMap.grow(LastVirtReg); - VirtRegModified.resize(LastVirtReg-MRegisterInfo::FirstVirtualRegister); + Virt2LastUseMap.grow(LastVirtReg); + VirtRegModified.resize(LastVirtReg+1-MRegisterInfo::FirstVirtualRegister); // Loop over all of the basic blocks, eliminating virtual register references for (MachineFunction::iterator MBB = Fn.begin(), MBBe = Fn.end(); @@ -834,6 +851,7 @@ bool RALocal::runOnMachineFunction(MachineFunction &Fn) { PhysRegsUsed.clear(); VirtRegModified.clear(); Virt2PhysRegMap.clear(); + Virt2LastUseMap.clear(); return true; } -- cgit v1.2.3-18-g5258