[llvm-commits] [llvm] r41067 - /llvm/trunk/lib/CodeGen/VirtRegMap.cpp
Evan Cheng
evan.cheng at apple.com
Mon Aug 13 22:42:54 PDT 2007
Author: evancheng
Date: Tue Aug 14 00:42:54 2007
New Revision: 41067
URL: http://llvm.org/viewvc/llvm-project?rev=41067&view=rev
Log:
If a rematerializable def is not deleted, i.e. it is also spilled, check if the
spilled value is available for reuse.
Modified:
llvm/trunk/lib/CodeGen/VirtRegMap.cpp
Modified: llvm/trunk/lib/CodeGen/VirtRegMap.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/VirtRegMap.cpp?rev=41067&r1=41066&r2=41067&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/VirtRegMap.cpp (original)
+++ llvm/trunk/lib/CodeGen/VirtRegMap.cpp Tue Aug 14 00:42:54 2007
@@ -744,10 +744,19 @@
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 @@
// 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 @@
// 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 @@
// 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 @@
// 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;
More information about the llvm-commits
mailing list