[llvm-commits] CVS: llvm/lib/CodeGen/RegAllocIterativeScan.cpp RegAllocLinearScan.cpp VirtRegMap.cpp
Chris Lattner
lattner at cs.uiuc.edu
Sun Jan 23 14:45:28 PST 2005
Changes in directory llvm/lib/CodeGen:
RegAllocIterativeScan.cpp updated: 1.20 -> 1.21
RegAllocLinearScan.cpp updated: 1.106 -> 1.107
VirtRegMap.cpp updated: 1.34 -> 1.35
---
Log message:
Update these register allocators to set the PhysRegUsed info in MachineFunction.
---
Diffs of the changes: (+35 -11)
RegAllocIterativeScan.cpp | 10 +++++++++-
RegAllocLinearScan.cpp | 11 +++++++++--
VirtRegMap.cpp | 25 +++++++++++++++++--------
3 files changed, 35 insertions(+), 11 deletions(-)
Index: llvm/lib/CodeGen/RegAllocIterativeScan.cpp
diff -u llvm/lib/CodeGen/RegAllocIterativeScan.cpp:1.20 llvm/lib/CodeGen/RegAllocIterativeScan.cpp:1.21
--- llvm/lib/CodeGen/RegAllocIterativeScan.cpp:1.20 Sat Jan 8 13:53:50 2005
+++ llvm/lib/CodeGen/RegAllocIterativeScan.cpp Sun Jan 23 16:45:12 2005
@@ -51,6 +51,7 @@
const TargetMachine* tm_;
const MRegisterInfo* mri_;
LiveIntervals* li_;
+ bool *PhysRegsUsed;
typedef std::vector<LiveInterval*> IntervalPtrs;
IntervalPtrs unhandled_, fixed_, active_, inactive_, handled_, spilled_;
@@ -145,6 +146,11 @@
tm_ = &fn.getTarget();
mri_ = tm_->getRegisterInfo();
li_ = &getAnalysis<LiveIntervals>();
+
+ PhysRegsUsed = new bool[mri_->getNumRegs()];
+ std::fill(PhysRegsUsed, PhysRegsUsed+mri_->getNumRegs(), false);
+ fn.setUsedPhysRegs(PhysRegsUsed);
+
if (!prt_.get()) prt_.reset(new PhysRegTracker(*mri_));
vrm_.reset(new VirtRegMap(*mf_));
if (!spiller_.get()) spiller_.reset(createSpiller());
@@ -256,8 +262,10 @@
for (LiveIntervals::iterator i = li_->begin(), e = li_->end(); i != e; ++i){
unhandled_.push_back(&i->second);
- if (MRegisterInfo::isPhysicalRegister(i->second.reg))
+ if (MRegisterInfo::isPhysicalRegister(i->second.reg)) {
+ PhysRegsUsed[i->second.reg] = true;
fixed_.push_back(&i->second);
+ }
}
}
Index: llvm/lib/CodeGen/RegAllocLinearScan.cpp
diff -u llvm/lib/CodeGen/RegAllocLinearScan.cpp:1.106 llvm/lib/CodeGen/RegAllocLinearScan.cpp:1.107
--- llvm/lib/CodeGen/RegAllocLinearScan.cpp:1.106 Sat Jan 8 13:53:50 2005
+++ llvm/lib/CodeGen/RegAllocLinearScan.cpp Sun Jan 23 16:45:12 2005
@@ -48,6 +48,7 @@
const TargetMachine* tm_;
const MRegisterInfo* mri_;
LiveIntervals* li_;
+ bool *PhysRegsUsed;
/// handled_ - Intervals are added to the handled_ set in the order of their
/// start value. This is uses for backtracking.
@@ -139,6 +140,10 @@
mri_ = tm_->getRegisterInfo();
li_ = &getAnalysis<LiveIntervals>();
+ PhysRegsUsed = new bool[mri_->getNumRegs()];
+ std::fill(PhysRegsUsed, PhysRegsUsed+mri_->getNumRegs(), false);
+ fn.setUsedPhysRegs(PhysRegsUsed);
+
if (!prt_.get()) prt_.reset(new PhysRegTracker(*mri_));
vrm_.reset(new VirtRegMap(*mf_));
if (!spiller_.get()) spiller_.reset(createSpiller());
@@ -147,6 +152,7 @@
linearScan();
+ // Rewrite spill code and update the PhysRegsUsed set.
spiller_->runOnMachineFunction(*mf_, *vrm_);
vrm_.reset(); // Free the VirtRegMap
@@ -170,9 +176,10 @@
"interval sets should be empty on initialization");
for (LiveIntervals::iterator i = li_->begin(), e = li_->end(); i != e; ++i) {
- if (MRegisterInfo::isPhysicalRegister(i->second.reg))
+ if (MRegisterInfo::isPhysicalRegister(i->second.reg)) {
+ PhysRegsUsed[i->second.reg] = true;
fixed_.push_back(std::make_pair(&i->second, i->second.begin()));
- else
+ } else
unhandled_.push(&i->second);
}
}
Index: llvm/lib/CodeGen/VirtRegMap.cpp
diff -u llvm/lib/CodeGen/VirtRegMap.cpp:1.34 llvm/lib/CodeGen/VirtRegMap.cpp:1.35
--- llvm/lib/CodeGen/VirtRegMap.cpp:1.34 Fri Jan 14 09:54:24 2005
+++ llvm/lib/CodeGen/VirtRegMap.cpp Sun Jan 23 16:45:13 2005
@@ -133,13 +133,14 @@
};
}
-bool SimpleSpiller::runOnMachineFunction(MachineFunction& MF,
- const VirtRegMap& VRM) {
+bool SimpleSpiller::runOnMachineFunction(MachineFunction &MF,
+ const VirtRegMap &VRM) {
DEBUG(std::cerr << "********** REWRITE MACHINE CODE **********\n");
DEBUG(std::cerr << "********** Function: "
<< MF.getFunction()->getName() << '\n');
- const TargetMachine& TM = MF.getTarget();
- const MRegisterInfo& MRI = *TM.getRegisterInfo();
+ const TargetMachine &TM = MF.getTarget();
+ const MRegisterInfo &MRI = *TM.getRegisterInfo();
+ bool *PhysRegsUsed = MF.getUsedPhysregs();
// LoadedRegs - Keep track of which vregs are loaded, so that we only load
// each vreg once (in the case where a spilled vreg is used by multiple
@@ -177,6 +178,7 @@
++NumStores;
}
}
+ PhysRegsUsed[PhysReg] = true;
MI.SetMachineOperandReg(i, PhysReg);
}
}
@@ -296,6 +298,8 @@
// same stack slot, the original store is deleted.
std::map<int, MachineInstr*> MaybeDeadStores;
+ bool *PhysRegsUsed = MBB.getParent()->getUsedPhysregs();
+
for (MachineBasicBlock::iterator MII = MBB.begin(), E = MBB.end();
MII != E; ) {
MachineInstr &MI = *MII;
@@ -313,7 +317,9 @@
if (!VRM.hasStackSlot(VirtReg)) {
// This virtual register was assigned a physreg!
- MI.SetMachineOperandReg(i, VRM.getPhys(VirtReg));
+ unsigned Phys = VRM.getPhys(VirtReg);
+ PhysRegsUsed[Phys] = true;
+ MI.SetMachineOperandReg(i, Phys);
} else {
// Is this virtual register a spilled value?
if (MO.isUse()) {
@@ -397,7 +403,7 @@
}
}
ContinueReload:
-
+ PhysRegsUsed[PhysReg] = true;
MRI->loadRegFromStackSlot(MBB, &MI, PhysReg, StackSlot);
// This invalidates PhysReg.
ClobberPhysReg(PhysReg, SpillSlotsAvailable, PhysRegsAvailable);
@@ -429,9 +435,11 @@
// Loop over all of the implicit defs, clearing them from our available
// sets.
- const TargetInstrDescriptor &InstrDesc = TII->get(MI.getOpcode());
- for (const unsigned* ImpDef = InstrDesc.ImplicitDefs; *ImpDef; ++ImpDef)
+ for (const unsigned *ImpDef = TII->getImplicitDefs(MI.getOpcode());
+ *ImpDef; ++ImpDef) {
+ PhysRegsUsed[*ImpDef] = true;
ClobberPhysReg(*ImpDef, SpillSlotsAvailable, PhysRegsAvailable);
+ }
DEBUG(std::cerr << '\t' << MI);
@@ -516,6 +524,7 @@
else
PhysReg = MO.getReg();
+ PhysRegsUsed[PhysReg] = true;
MRI->storeRegToStackSlot(MBB, next(MII), PhysReg, StackSlot);
DEBUG(std::cerr << "Store:\t" << *next(MII));
MI.SetMachineOperandReg(i, PhysReg);
More information about the llvm-commits
mailing list