Use getNumVirtualRegs().

Whitespace cleanups.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11389 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Alkis Evlogimenos
2004-02-13 18:20:47 +00:00
parent 87af94b291
commit 4de473bc59

View File

@@ -58,12 +58,6 @@ namespace {
&& "VirtReg not in map!");
return Virt2PhysRegMap[VirtReg-MRegisterInfo::FirstVirtualRegister];
}
unsigned &getOrInsertVirt2PhysRegMapSlot(unsigned VirtReg) {
assert(VirtReg >= MRegisterInfo::FirstVirtualRegister &&"Illegal VREG #");
if (VirtReg-MRegisterInfo::FirstVirtualRegister >= Virt2PhysRegMap.size())
Virt2PhysRegMap.resize(VirtReg-MRegisterInfo::FirstVirtualRegister+1);
return Virt2PhysRegMap[VirtReg-MRegisterInfo::FirstVirtualRegister];
}
// PhysRegsUsed - This array is effectively a map, containing entries for
// each physical register that currently has a value (ie, it is in
@@ -73,7 +67,7 @@ namespace {
// because it is used by a future instruction. If the entry for a physical
// register is -1, then the physical register is "not in the map".
//
int PhysRegsUsed[MRegisterInfo::FirstVirtualRegister];
std::vector<int> PhysRegsUsed;
// PhysRegsUseOrder - This contains a list of the physical registers that
// currently have a virtual register value in them. This list provides an
@@ -102,7 +96,7 @@ namespace {
bool isVirtRegModified(unsigned Reg) const {
assert(MRegisterInfo::isVirtualRegister(Reg) && "Illegal VirtReg!");
assert(Reg - MRegisterInfo::FirstVirtualRegister < VirtRegModified.size()
&& "Illegal virtual register!");
&& "Illegal virtual register!");
return VirtRegModified[Reg - MRegisterInfo::FirstVirtualRegister];
}
@@ -111,14 +105,14 @@ namespace {
if (PhysRegsUseOrder.back() == Reg) return; // Already most recently used
for (unsigned i = PhysRegsUseOrder.size(); i != 0; --i)
if (areRegsEqual(Reg, PhysRegsUseOrder[i-1])) {
unsigned RegMatch = PhysRegsUseOrder[i-1]; // remove from middle
PhysRegsUseOrder.erase(PhysRegsUseOrder.begin()+i-1);
// Add it to the end of the list
PhysRegsUseOrder.push_back(RegMatch);
if (RegMatch == Reg)
return; // Found an exact match, exit early
}
if (areRegsEqual(Reg, PhysRegsUseOrder[i-1])) {
unsigned RegMatch = PhysRegsUseOrder[i-1]; // remove from middle
PhysRegsUseOrder.erase(PhysRegsUseOrder.begin()+i-1);
// Add it to the end of the list
PhysRegsUseOrder.push_back(RegMatch);
if (RegMatch == Reg)
return; // Found an exact match, exit early
}
}
public:
@@ -128,7 +122,7 @@ namespace {
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
if (!DisableKill)
AU.addRequired<LiveVariables>();
AU.addRequired<LiveVariables>();
AU.addRequiredID(PHIEliminationID);
AU.addRequiredID(TwoAddressInstructionPassID);
MachineFunctionPass::getAnalysisUsage(AU);
@@ -190,7 +184,7 @@ namespace {
/// the way or spilled to memory.
///
void liberatePhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator &I,
unsigned PhysReg);
unsigned PhysReg);
/// isPhysRegAvailable - Return true if the specified physical register is
/// free and available for use. This also includes checking to see if
@@ -209,7 +203,7 @@ namespace {
/// register.
///
unsigned getReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator &I,
unsigned VirtReg);
unsigned VirtReg);
/// reloadVirtReg - This method loads the specified virtual register into a
/// physical register, returning the physical register chosen. This updates
@@ -319,7 +313,7 @@ void RA::assignVirtToPhysReg(unsigned VirtReg, unsigned PhysReg) {
// Update information to note the fact that this register was just used, and
// it holds VirtReg.
PhysRegsUsed[PhysReg] = VirtReg;
getOrInsertVirt2PhysRegMapSlot(VirtReg) = PhysReg;
getVirt2PhysRegMapSlot(VirtReg) = PhysReg;
PhysRegsUseOrder.push_back(PhysReg); // New use of PhysReg
}
@@ -364,7 +358,7 @@ unsigned RA::getFreeReg(const TargetRegisterClass *RC) {
/// or spilled to memory.
///
void RA::liberatePhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator &I,
unsigned PhysReg) {
unsigned PhysReg) {
// FIXME: This code checks to see if a register is available, but it really
// wants to know if a reg is available BEFORE the instruction executes. If
// called after killed operands are freed, it runs the risk of reallocating a
@@ -407,7 +401,7 @@ void RA::liberatePhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator &I,
/// the last used virtual register to the stack, and uses that register.
///
unsigned RA::getReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator &I,
unsigned VirtReg) {
unsigned VirtReg) {
const TargetRegisterClass *RC = MF->getSSARegMap()->getRegClass(VirtReg);
// First check to see if we have a free register of the requested type...
@@ -471,7 +465,7 @@ unsigned RA::getReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator &I,
unsigned RA::reloadVirtReg(MachineBasicBlock &MBB,
MachineBasicBlock::iterator &I,
unsigned VirtReg) {
if (unsigned PR = getOrInsertVirt2PhysRegMapSlot(VirtReg)) {
if (unsigned PR = getVirt2PhysRegMapSlot(VirtReg)) {
MarkPhysRegRecentlyUsed(PR);
return PR; // Already have this value available!
}
@@ -594,7 +588,7 @@ void RA::AllocateBasicBlock(MachineBasicBlock &MBB) {
unsigned DestPhysReg;
// If DestVirtReg already has a value, use it.
if (!(DestPhysReg = getOrInsertVirt2PhysRegMapSlot(DestVirtReg)))
if (!(DestPhysReg = getVirt2PhysRegMapSlot(DestVirtReg)))
DestPhysReg = getReg(MBB, MI, DestVirtReg);
markVirtRegModified(DestVirtReg);
MI->SetMachineOperandReg(i, DestPhysReg); // Assign the output register
@@ -664,12 +658,11 @@ bool RA::runOnMachineFunction(MachineFunction &Fn) {
TM = &Fn.getTarget();
RegInfo = TM->getRegisterInfo();
memset(PhysRegsUsed, -1, RegInfo->getNumRegs()*sizeof(unsigned));
PhysRegsUsed.assign(RegInfo->getNumRegs(), -1);
// Reserve some space for a moderate number of registers. If we know what the
// max virtual register number was we could use that instead and save some
// runtime overhead...
Virt2PhysRegMap.resize(1024);
// initialize the virtual->physical register map to have a 'null'
// mapping for all virtual registers
Virt2PhysRegMap.assign(MF->getSSARegMap()->getNumVirtualRegs(), 0);
if (!DisableKill)
LV = &getAnalysis<LiveVariables>();
@@ -680,6 +673,7 @@ bool RA::runOnMachineFunction(MachineFunction &Fn) {
AllocateBasicBlock(*MBB);
StackSlotForVirtReg.clear();
PhysRegsUsed.clear();
VirtRegModified.clear();
Virt2PhysRegMap.clear();
return true;
@@ -688,4 +682,3 @@ bool RA::runOnMachineFunction(MachineFunction &Fn) {
FunctionPass *llvm::createLocalRegisterAllocator() {
return new RA();
}