diff options
author | Evan Cheng <evan.cheng@apple.com> | 2007-08-14 05:42:54 +0000 |
---|---|---|
committer | Evan Cheng <evan.cheng@apple.com> | 2007-08-14 05:42:54 +0000 |
commit | 67cf11cdc1b014a2efea53510babeb8ac078c5de (patch) | |
tree | 2f35af0dd3e3031dd66fe2898eae69582cb25346 | |
parent | 2d88a7bdd84044a39611c50a8ea01d8e3c4040e5 (diff) | |
download | external_llvm-67cf11cdc1b014a2efea53510babeb8ac078c5de.zip external_llvm-67cf11cdc1b014a2efea53510babeb8ac078c5de.tar.gz external_llvm-67cf11cdc1b014a2efea53510babeb8ac078c5de.tar.bz2 |
If a rematerializable def is not deleted, i.e. it is also spilled, check if the
spilled value is available for reuse.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41067 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/VirtRegMap.cpp | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/lib/CodeGen/VirtRegMap.cpp b/lib/CodeGen/VirtRegMap.cpp index 9d57a0a..e996374 100644 --- a/lib/CodeGen/VirtRegMap.cpp +++ b/lib/CodeGen/VirtRegMap.cpp @@ -744,10 +744,19 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, VirtRegMap &VRM) { bool DoReMat = VRM.isReMaterialized(VirtReg); int SSorRMId = DoReMat ? VRM.getReMatId(VirtReg) : VRM.getStackSlot(VirtReg); - unsigned PhysReg; + int ReuseSlot = SSorRMId; // Check to see if this stack slot is available. - if ((PhysReg = Spills.getSpillSlotOrReMatPhysReg(SSorRMId))) { + unsigned PhysReg = Spills.getSpillSlotOrReMatPhysReg(SSorRMId); + if (!PhysReg && DoReMat) { + // This use is rematerializable. But perhaps the value is available in + // stack if the definition is not deleted. If so, check if we can + // reuse the value. + ReuseSlot = VRM.getStackSlot(VirtReg); + if (ReuseSlot != VirtRegMap::NO_STACK_SLOT) + PhysReg = Spills.getSpillSlotOrReMatPhysReg(ReuseSlot); + } + if (PhysReg) { // This spilled operand might be part of a two-address operand. If this // is the case, then changing it will necessarily require changing the // def part of the instruction as well. However, in some cases, we @@ -761,16 +770,16 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, VirtRegMap &VRM) { // Okay, we have a two address operand. We can reuse this physreg as // long as we are allowed to clobber the value and there isn't an // earlier def that has already clobbered the physreg. - CanReuse = Spills.canClobberPhysReg(SSorRMId) && + CanReuse = Spills.canClobberPhysReg(ReuseSlot) && !ReusedOperands.isClobbered(PhysReg); } if (CanReuse) { // If this stack slot value is already available, reuse it! - if (SSorRMId > VirtRegMap::MAX_STACK_SLOT) - DOUT << "Reusing RM#" << SSorRMId-VirtRegMap::MAX_STACK_SLOT-1; + if (ReuseSlot > VirtRegMap::MAX_STACK_SLOT) + DOUT << "Reusing RM#" << ReuseSlot-VirtRegMap::MAX_STACK_SLOT-1; else - DOUT << "Reusing SS#" << SSorRMId; + DOUT << "Reusing SS#" << ReuseSlot; DOUT << " from physreg " << MRI->getName(PhysReg) << " for vreg" << VirtReg <<" instead of reloading into physreg " @@ -791,7 +800,7 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, VirtRegMap &VRM) { // or R0 and R1 might not be compatible with each other. In this // case, we actually insert a reload for V1 in R1, ensuring that // we can get at R0 or its alias. - ReusedOperands.addReuse(i, SSorRMId, PhysReg, + ReusedOperands.addReuse(i, ReuseSlot, PhysReg, VRM.getPhys(VirtReg), VirtReg); if (ti != -1) // Only mark it clobbered if this is a use&def operand. @@ -825,10 +834,10 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, VirtRegMap &VRM) { // incoming, we don't need to inserted a dead copy. if (DesignatedReg == PhysReg) { // If this stack slot value is already available, reuse it! - if (SSorRMId > VirtRegMap::MAX_STACK_SLOT) - DOUT << "Reusing RM#" << SSorRMId-VirtRegMap::MAX_STACK_SLOT-1; + if (ReuseSlot > VirtRegMap::MAX_STACK_SLOT) + DOUT << "Reusing RM#" << ReuseSlot-VirtRegMap::MAX_STACK_SLOT-1; else - DOUT << "Reusing SS#" << SSorRMId; + DOUT << "Reusing SS#" << ReuseSlot; DOUT << " from physreg " << MRI->getName(PhysReg) << " for vreg" << VirtReg << " instead of reloading into same physreg.\n"; @@ -849,7 +858,7 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, VirtRegMap &VRM) { // This invalidates DesignatedReg. Spills.ClobberPhysReg(DesignatedReg); - Spills.addAvailable(SSorRMId, &MI, DesignatedReg); + Spills.addAvailable(ReuseSlot, &MI, DesignatedReg); MI.getOperand(i).setReg(DesignatedReg); DOUT << '\t' << *prior(MII); ++NumReused; |