[llvm-commits] [llvm] r103764 - /llvm/trunk/lib/CodeGen/RegAllocFast.cpp
Jakob Stoklund Olesen
stoklund at 2pi.dk
Thu May 13 21:30:51 PDT 2010
Author: stoklund
Date: Thu May 13 23:30:51 2010
New Revision: 103764
URL: http://llvm.org/viewvc/llvm-project?rev=103764&view=rev
Log:
Enable opportunistic coalescing
Modified:
llvm/trunk/lib/CodeGen/RegAllocFast.cpp
Modified: llvm/trunk/lib/CodeGen/RegAllocFast.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/RegAllocFast.cpp?rev=103764&r1=103763&r2=103764&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/RegAllocFast.cpp (original)
+++ llvm/trunk/lib/CodeGen/RegAllocFast.cpp Thu May 13 23:30:51 2010
@@ -603,6 +603,7 @@
reservePhysReg(MBB, MII, *I);
SmallVector<unsigned, 8> VirtKills, PhysKills, PhysDefs;
+ SmallVector<MachineInstr*, 32> Coalesced;
// Otherwise, sequentially allocate each instruction in the MBB.
while (MII != MBB.end()) {
@@ -706,8 +707,7 @@
if (!Reg || TargetRegisterInfo::isPhysicalRegister(Reg)) continue;
if (MO.isUse()) {
unsigned PhysReg = reloadVirtReg(MBB, MI, i, Reg, CopyDst);
- if (CopySrc == Reg)
- CopySrc = PhysReg;
+ CopySrc = (CopySrc == Reg || CopySrc == PhysReg) ? PhysReg : 0;
setPhysReg(MO, PhysReg);
if (MO.isKill())
VirtKills.push_back(Reg);
@@ -757,11 +757,12 @@
PhysKills.push_back(Reg);
continue;
}
- if (MO.isDead())
- VirtKills.push_back(Reg);
unsigned PhysReg = defineVirtReg(MBB, MI, i, Reg, CopySrc);
- if (CopyDst == Reg)
- CopyDst = PhysReg;
+ if (MO.isDead()) {
+ VirtKills.push_back(Reg);
+ CopyDst = 0; // cancel coalescing;
+ } else
+ CopyDst = (CopyDst == Reg || CopyDst == PhysReg) ? PhysReg : 0;
setPhysReg(MO, PhysReg);
}
@@ -783,7 +784,12 @@
MRI->addPhysRegsUsed(UsedInInstr);
- DEBUG(dbgs() << "<< " << *MI);
+ if (CopyDst && CopyDst == CopySrc && CopyDstSub == CopySrcSub) {
+ DEBUG(dbgs() << "-- coalescing: " << *MI);
+ Coalesced.push_back(MI);
+ } else {
+ DEBUG(dbgs() << "<< " << *MI);
+ }
}
// Spill all physical registers holding virtual registers now.
@@ -795,6 +801,11 @@
spillVirtReg(MBB, MI, i, true);
LiveVirtRegs.clear();
+ // Erase all the coalesced copies. We are delaying it until now because
+ // LiveVirtsRegs might refer to the instrs.
+ for (unsigned i = 0, e = Coalesced.size(); i != e; ++i)
+ MBB.erase(Coalesced[i]);
+
DEBUG(MBB.dump());
}
More information about the llvm-commits
mailing list