[llvm-commits] CVS: llvm/lib/CodeGen/PhysRegTracker.h RegAllocLinearScan.cpp
Alkis Evlogimenos
alkis at cs.uiuc.edu
Mon Feb 23 00:11:03 PST 2004
Changes in directory llvm/lib/CodeGen:
PhysRegTracker.h updated: 1.3 -> 1.4
RegAllocLinearScan.cpp updated: 1.58 -> 1.59
---
Log message:
Improved PhysRegTracker interface. RegAlloc lazily allocates the register tracker using a std::auto_ptr
---
Diffs of the changes: (+21 -23)
Index: llvm/lib/CodeGen/PhysRegTracker.h
diff -u llvm/lib/CodeGen/PhysRegTracker.h:1.3 llvm/lib/CodeGen/PhysRegTracker.h:1.4
--- llvm/lib/CodeGen/PhysRegTracker.h:1.3 Sun Feb 22 19:57:39 2004
+++ llvm/lib/CodeGen/PhysRegTracker.h Mon Feb 23 00:10:13 2004
@@ -17,7 +17,7 @@
#ifndef LLVM_CODEGEN_PHYSREGTRACKER_H
#define LLVM_CODEGEN_PHYSREGTRACKER_H
-#include "llvm/CodeGen/MachineFunction.h"
+#include "llvm/Target/MRegisterInfo.h"
namespace llvm {
@@ -26,11 +26,9 @@
std::vector<unsigned> regUse_;
public:
- PhysRegTracker(MachineFunction* mf)
- : mri_(mf ? mf->getTarget().getRegisterInfo() : NULL) {
- if (mri_) {
- regUse_.assign(mri_->getNumRegs(), 0);
- }
+ PhysRegTracker(const MRegisterInfo& mri)
+ : mri_(&mri),
+ regUse_(mri_->getNumRegs(), 0) {
}
PhysRegTracker(const PhysRegTracker& rhs)
Index: llvm/lib/CodeGen/RegAllocLinearScan.cpp
diff -u llvm/lib/CodeGen/RegAllocLinearScan.cpp:1.58 llvm/lib/CodeGen/RegAllocLinearScan.cpp:1.59
--- llvm/lib/CodeGen/RegAllocLinearScan.cpp:1.58 Sun Feb 22 19:25:05 2004
+++ llvm/lib/CodeGen/RegAllocLinearScan.cpp Mon Feb 23 00:10:13 2004
@@ -45,7 +45,7 @@
typedef std::list<LiveIntervals::Interval*> IntervalPtrs;
IntervalPtrs unhandled_, fixed_, active_, inactive_, handled_;
- PhysRegTracker prt_;
+ std::auto_ptr<PhysRegTracker> prt_;
typedef std::map<unsigned, unsigned> Virt2PhysMap;
Virt2PhysMap v2pMap_;
@@ -198,7 +198,7 @@
tii_ = &tm_->getInstrInfo();
mri_ = tm_->getRegisterInfo();
li_ = &getAnalysis<LiveIntervals>();
- prt_ = PhysRegTracker(mf_);
+ if (!prt_.get()) prt_.reset(new PhysRegTracker(*mri_));
initIntervalSets(li_->getIntervals());
@@ -239,7 +239,7 @@
// if this register is fixed we are done
if (MRegisterInfo::isPhysicalRegister(cur->reg)) {
- prt_.addRegUse(cur->reg);
+ prt_->addRegUse(cur->reg);
active_.push_back(cur);
handled_.push_back(cur);
}
@@ -262,7 +262,7 @@
if (MRegisterInfo::isVirtualRegister(reg)) {
reg = v2pMap_[reg];
}
- prt_.delRegUse(reg);
+ prt_->delRegUse(reg);
}
DEBUG(printVirtRegAssignment());
@@ -355,7 +355,7 @@
if (MRegisterInfo::isVirtualRegister(reg)) {
reg = v2pMap_[reg];
}
- prt_.delRegUse(reg);
+ prt_->delRegUse(reg);
// remove from active
i = active_.erase(i);
}
@@ -365,7 +365,7 @@
if (MRegisterInfo::isVirtualRegister(reg)) {
reg = v2pMap_[reg];
}
- prt_.delRegUse(reg);
+ prt_->delRegUse(reg);
// add to inactive
inactive_.push_back(*i);
// remove from active
@@ -395,7 +395,7 @@
if (MRegisterInfo::isVirtualRegister(reg)) {
reg = v2pMap_[reg];
}
- prt_.addRegUse(reg);
+ prt_->addRegUse(reg);
// add to active
active_.push_back(*i);
// remove from inactive
@@ -418,7 +418,7 @@
{
DEBUG(std::cerr << "\tallocating current interval: ");
- PhysRegTracker backupPrt = prt_;
+ PhysRegTracker backupPrt = *prt_;
spillWeights_.assign(mri_->getNumRegs(), 0.0);
@@ -439,7 +439,7 @@
unsigned reg = (*i)->reg;
if (MRegisterInfo::isVirtualRegister(reg))
reg = v2pMap_[reg];
- prt_.addRegUse(reg);
+ prt_->addRegUse(reg);
updateSpillWeights(reg, (*i)->weight);
}
}
@@ -450,14 +450,14 @@
e = fixed_.end(); i != e; ++i) {
if (cur->overlaps(**i)) {
unsigned reg = (*i)->reg;
- prt_.addRegUse(reg);
+ prt_->addRegUse(reg);
updateSpillWeights(reg, (*i)->weight);
}
}
unsigned physReg = getFreePhysReg(cur);
// restore the physical register tracker
- prt_ = backupPrt;
+ *prt_ = backupPrt;
// if we find a free register, we are done: assign this virtual to
// the free physical register and add this interval to the active
// list.
@@ -565,12 +565,12 @@
active_.erase(it);
if (MRegisterInfo::isPhysicalRegister(i->reg)) {
fixed_.push_front(i);
- prt_.delRegUse(i->reg);
+ prt_->delRegUse(i->reg);
}
else {
Virt2PhysMap::iterator v2pIt = v2pMap_.find(i->reg);
clearVirtReg(v2pIt);
- prt_.delRegUse(v2pIt->second);
+ prt_->delRegUse(v2pIt->second);
if (i->spilled()) {
if (!i->empty()) {
IntervalPtrs::iterator it = unhandled_.begin();
@@ -625,10 +625,10 @@
DEBUG(std::cerr << "\t\t\tundo changes for: " << **i << '\n');
active_.push_back(*i);
if (MRegisterInfo::isPhysicalRegister((*i)->reg))
- prt_.addRegUse((*i)->reg);
+ prt_->addRegUse((*i)->reg);
else {
assert(v2pMap_.count((*i)->reg));
- prt_.addRegUse(v2pMap_.find((*i)->reg)->second);
+ prt_->addRegUse(v2pMap_.find((*i)->reg)->second);
}
}
}
@@ -706,7 +706,7 @@
for (TargetRegisterClass::iterator i = rc->allocation_order_begin(*mf_);
i != rc->allocation_order_end(*mf_); ++i) {
unsigned reg = *i;
- if (prt_.isRegAvail(reg))
+ if (prt_->isRegAvail(reg))
return reg;
}
return 0;
@@ -720,7 +720,7 @@
tie(it, inserted) = v2pMap_.insert(std::make_pair(virtReg, physReg));
assert(inserted && "attempting to assign a virt->phys mapping to an "
"already mapped register");
- prt_.addRegUse(physReg);
+ prt_->addRegUse(physReg);
return it;
}
More information about the llvm-commits
mailing list