[llvm-commits] CVS: llvm/lib/CodeGen/VirtRegMap.h VirtRegMap.cpp RegAllocLocal.cpp
Alkis Evlogimenos
alkis at niobe.cs.uiuc.edu
Wed Feb 25 15:56:34 PST 2004
Changes in directory llvm/lib/CodeGen:
VirtRegMap.h updated: 1.5 -> 1.6
VirtRegMap.cpp updated: 1.2 -> 1.3
RegAllocLocal.cpp updated: 1.57 -> 1.58
---
Log message:
Add DenseMap template and actually use it for for mapping virtual regs
to objects.
---
Diffs of the changes: (+29 -36)
Index: llvm/lib/CodeGen/VirtRegMap.h
diff -u llvm/lib/CodeGen/VirtRegMap.h:1.5 llvm/lib/CodeGen/VirtRegMap.h:1.6
--- llvm/lib/CodeGen/VirtRegMap.h:1.5 Tue Feb 24 02:58:29 2004
+++ llvm/lib/CodeGen/VirtRegMap.h Wed Feb 25 15:55:44 2004
@@ -20,14 +20,15 @@
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/SSARegMap.h"
+#include "Support/DenseMap.h"
#include <climits>
namespace llvm {
class VirtRegMap {
public:
- typedef std::vector<unsigned> Virt2PhysMap;
- typedef std::vector<int> Virt2StackSlotMap;
+ typedef DenseMap<unsigned, VirtReg2IndexFunctor> Virt2PhysMap;
+ typedef DenseMap<int, VirtReg2IndexFunctor> Virt2StackSlotMap;
private:
MachineFunction* mf_;
@@ -38,13 +39,6 @@
VirtRegMap(const VirtRegMap& rhs);
const VirtRegMap& operator=(const VirtRegMap& rhs);
- static unsigned toIndex(unsigned virtReg) {
- return virtReg - MRegisterInfo::FirstVirtualRegister;
- }
- static unsigned fromIndex(unsigned index) {
- return index + MRegisterInfo::FirstVirtualRegister;
- }
-
enum {
NO_PHYS_REG = 0,
NO_STACK_SLOT = INT_MAX
@@ -53,8 +47,10 @@
public:
VirtRegMap(MachineFunction& mf)
: mf_(&mf),
- v2pMap_(mf.getSSARegMap()->getNumVirtualRegs(), NO_PHYS_REG),
- v2ssMap_(mf.getSSARegMap()->getNumVirtualRegs(), NO_STACK_SLOT) {
+ v2pMap_(NO_PHYS_REG),
+ v2ssMap_(NO_STACK_SLOT) {
+ v2pMap_.grow(mf.getSSARegMap()->getLastVirtReg());
+ v2ssMap_.grow(mf.getSSARegMap()->getLastVirtReg());
}
bool hasPhys(unsigned virtReg) const {
@@ -63,23 +59,23 @@
unsigned getPhys(unsigned virtReg) const {
assert(MRegisterInfo::isVirtualRegister(virtReg));
- return v2pMap_[toIndex(virtReg)];
+ return v2pMap_[virtReg];
}
void assignVirt2Phys(unsigned virtReg, unsigned physReg) {
assert(MRegisterInfo::isVirtualRegister(virtReg) &&
MRegisterInfo::isPhysicalRegister(physReg));
- assert(v2pMap_[toIndex(virtReg)] == NO_PHYS_REG &&
+ assert(v2pMap_[virtReg] == NO_PHYS_REG &&
"attempt to assign physical register to already mapped "
"virtual register");
- v2pMap_[toIndex(virtReg)] = physReg;
+ v2pMap_[virtReg] = physReg;
}
void clearVirtReg(unsigned virtReg) {
assert(MRegisterInfo::isVirtualRegister(virtReg));
- assert(v2pMap_[toIndex(virtReg)] != NO_PHYS_REG &&
+ assert(v2pMap_[virtReg] != NO_PHYS_REG &&
"attempt to clear a not assigned virtual register");
- v2pMap_[toIndex(virtReg)] = NO_PHYS_REG;
+ v2pMap_[virtReg] = NO_PHYS_REG;
}
bool hasStackSlot(unsigned virtReg) const {
@@ -88,7 +84,7 @@
int getStackSlot(unsigned virtReg) const {
assert(MRegisterInfo::isVirtualRegister(virtReg));
- return v2ssMap_[toIndex(virtReg)];
+ return v2ssMap_[virtReg];
}
int assignVirt2StackSlot(unsigned virtReg);
Index: llvm/lib/CodeGen/VirtRegMap.cpp
diff -u llvm/lib/CodeGen/VirtRegMap.cpp:1.2 llvm/lib/CodeGen/VirtRegMap.cpp:1.3
--- llvm/lib/CodeGen/VirtRegMap.cpp:1.2 Tue Feb 24 02:58:29 2004
+++ llvm/lib/CodeGen/VirtRegMap.cpp Wed Feb 25 15:55:44 2004
@@ -38,12 +38,12 @@
int VirtRegMap::assignVirt2StackSlot(unsigned virtReg)
{
assert(MRegisterInfo::isVirtualRegister(virtReg));
- assert(v2ssMap_[toIndex(virtReg)] == NO_STACK_SLOT &&
+ assert(v2ssMap_[virtReg] == NO_STACK_SLOT &&
"attempt to assign stack slot to already spilled register");
const TargetRegisterClass* rc =
mf_->getSSARegMap()->getRegClass(virtReg);
int frameIndex = mf_->getFrameInfo()->CreateStackObject(rc);
- v2ssMap_[toIndex(virtReg)] = frameIndex;
+ v2ssMap_[virtReg] = frameIndex;
++numSpills;
return frameIndex;
}
@@ -53,14 +53,16 @@
const MRegisterInfo* mri = vrm.mf_->getTarget().getRegisterInfo();
std::cerr << "********** REGISTER MAP **********\n";
- for (unsigned i = 0, e = vrm.v2pMap_.size(); i != e; ++i) {
+ for (unsigned i = MRegisterInfo::FirstVirtualRegister,
+ e = vrm.mf_->getSSARegMap()->getLastVirtReg(); i <= e; ++i) {
if (vrm.v2pMap_[i] != VirtRegMap::NO_PHYS_REG)
- std::cerr << "[reg" << VirtRegMap::fromIndex(i) << " -> "
+ std::cerr << "[reg" << i << " -> "
<< mri->getName(vrm.v2pMap_[i]) << "]\n";
}
- for (unsigned i = 0, e = vrm.v2ssMap_.size(); i != e; ++i) {
+ for (unsigned i = MRegisterInfo::FirstVirtualRegister,
+ e = vrm.mf_->getSSARegMap()->getLastVirtReg(); i <= e; ++i) {
if (vrm.v2ssMap_[i] != VirtRegMap::NO_STACK_SLOT)
- std::cerr << "[reg" << VirtRegMap::fromIndex(i) << " -> fi#"
+ std::cerr << "[reg" << i << " -> fi#"
<< vrm.v2ssMap_[i] << "]\n";
}
return std::cerr << '\n';
Index: llvm/lib/CodeGen/RegAllocLocal.cpp
diff -u llvm/lib/CodeGen/RegAllocLocal.cpp:1.57 llvm/lib/CodeGen/RegAllocLocal.cpp:1.58
--- llvm/lib/CodeGen/RegAllocLocal.cpp:1.57 Mon Feb 23 12:14:48 2004
+++ llvm/lib/CodeGen/RegAllocLocal.cpp Wed Feb 25 15:55:44 2004
@@ -23,6 +23,7 @@
#include "llvm/Target/TargetMachine.h"
#include "Support/CommandLine.h"
#include "Support/Debug.h"
+#include "Support/DenseMap.h"
#include "Support/Statistic.h"
#include <iostream>
using namespace llvm;
@@ -43,19 +44,11 @@
std::map<unsigned, int> StackSlotForVirtReg;
// Virt2PhysRegMap - This map contains entries for each virtual register
- // that is currently available in a physical register. This is "logically"
- // a map from virtual register numbers to physical register numbers.
- // Instead of using a map, however, which is slow, we use a vector. The
- // index is the VREG number - FirstVirtualRegister. If the entry is zero,
- // then it is logically "not in the map".
- //
- std::vector<unsigned> Virt2PhysRegMap;
+ // that is currently available in a physical register.
+ DenseMap<unsigned, VirtReg2IndexFunctor> Virt2PhysRegMap;
unsigned &getVirt2PhysRegMapSlot(unsigned VirtReg) {
- assert(MRegisterInfo::isVirtualRegister(VirtReg) &&"Illegal VREG #");
- assert(VirtReg-MRegisterInfo::FirstVirtualRegister <Virt2PhysRegMap.size()
- && "VirtReg not in map!");
- return Virt2PhysRegMap[VirtReg-MRegisterInfo::FirstVirtualRegister];
+ return Virt2PhysRegMap[VirtReg];
}
// PhysRegsUsed - This array is effectively a map, containing entries for
@@ -661,7 +654,8 @@
#ifndef NDEBUG
bool AllOk = true;
- for (unsigned i = 0, e = Virt2PhysRegMap.size(); i != e; ++i)
+ for (unsigned i = MRegisterInfo::FirstVirtualRegister,
+ e = MF->getSSARegMap()->getLastVirtReg(); i <= e; ++i)
if (unsigned PR = Virt2PhysRegMap[i]) {
std::cerr << "Register still mapped: " << i << " -> " << PR << "\n";
AllOk = false;
@@ -689,7 +683,8 @@
// initialize the virtual->physical register map to have a 'null'
// mapping for all virtual registers
- Virt2PhysRegMap.assign(MF->getSSARegMap()->getNumVirtualRegs(), 0);
+ Virt2PhysRegMap.clear();
+ Virt2PhysRegMap.grow(MF->getSSARegMap()->getLastVirtReg());
// Loop over all of the basic blocks, eliminating virtual register references
for (MachineFunction::iterator MBB = Fn.begin(), MBBe = Fn.end();
More information about the llvm-commits
mailing list