mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-19 04:26:05 +00:00
Eliminate uneeded lookups by passing a Virt2PhysMap::iterator instead
of the virtual register to certain functions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11143 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -176,12 +176,13 @@ namespace {
|
|||||||
|
|
||||||
/// assignVirt2PhysReg - assigns the free physical register to
|
/// assignVirt2PhysReg - assigns the free physical register to
|
||||||
/// the virtual register passed as arguments
|
/// the virtual register passed as arguments
|
||||||
void assignVirt2PhysReg(unsigned virtReg, unsigned physReg);
|
Virt2PhysMap::iterator
|
||||||
|
assignVirt2PhysReg(unsigned virtReg, unsigned physReg);
|
||||||
|
|
||||||
/// clearVirtReg - free the physical register associated with this
|
/// clearVirtReg - free the physical register associated with this
|
||||||
/// virtual register and disassociate virtual->physical and
|
/// virtual register and disassociate virtual->physical and
|
||||||
/// physical->virtual mappings
|
/// physical->virtual mappings
|
||||||
void clearVirtReg(unsigned virtReg);
|
void clearVirtReg(Virt2PhysMap::iterator it);
|
||||||
|
|
||||||
/// assignVirt2StackSlot - assigns this virtual register to a
|
/// assignVirt2StackSlot - assigns this virtual register to a
|
||||||
/// stack slot
|
/// stack slot
|
||||||
@@ -192,12 +193,13 @@ namespace {
|
|||||||
int getStackSlot(unsigned virtReg);
|
int getStackSlot(unsigned virtReg);
|
||||||
|
|
||||||
/// spillVirtReg - spills the virtual register
|
/// spillVirtReg - spills the virtual register
|
||||||
void spillVirtReg(unsigned virtReg);
|
void spillVirtReg(Virt2PhysMap::iterator it);
|
||||||
|
|
||||||
/// loadPhysReg - loads to the physical register the value of
|
/// loadPhysReg - loads to the physical register the value of
|
||||||
/// the virtual register specifed. Virtual register must have
|
/// the virtual register specifed. Virtual register must have
|
||||||
/// an assigned stack slot
|
/// an assigned stack slot
|
||||||
void loadVirt2PhysReg(unsigned virtReg, unsigned physReg);
|
Virt2PhysMap::iterator
|
||||||
|
loadVirt2PhysReg(unsigned virtReg, unsigned physReg);
|
||||||
|
|
||||||
void printVirtRegAssignment() const {
|
void printVirtRegAssignment() const {
|
||||||
std::cerr << "register assignment:\n";
|
std::cerr << "register assignment:\n";
|
||||||
@@ -460,7 +462,7 @@ bool RA::runOnMachineFunction(MachineFunction &fn) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef std::vector<unsigned> Regs;
|
typedef std::vector<Virt2PhysMap::iterator> Regs;
|
||||||
Regs toClear;
|
Regs toClear;
|
||||||
Regs toSpill;
|
Regs toSpill;
|
||||||
|
|
||||||
@@ -473,19 +475,19 @@ bool RA::runOnMachineFunction(MachineFunction &fn) {
|
|||||||
if (op.isVirtualRegister() && op.isUse()) {
|
if (op.isVirtualRegister() && op.isUse()) {
|
||||||
unsigned virtReg = op.getAllocatedRegNum();
|
unsigned virtReg = op.getAllocatedRegNum();
|
||||||
unsigned physReg = 0;
|
unsigned physReg = 0;
|
||||||
Virt2PhysMap::const_iterator it = v2pMap_.find(virtReg);
|
Virt2PhysMap::iterator it = v2pMap_.find(virtReg);
|
||||||
if (it != v2pMap_.end()) {
|
if (it != v2pMap_.end()) {
|
||||||
physReg = it->second;
|
physReg = it->second;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
physReg = getFreeTempPhysReg(virtReg);
|
physReg = getFreeTempPhysReg(virtReg);
|
||||||
loadVirt2PhysReg(virtReg, physReg);
|
it = loadVirt2PhysReg(virtReg, physReg);
|
||||||
// we will clear uses that are not also defs
|
// we will clear uses that are not also defs
|
||||||
// before we allocate registers the defs
|
// before we allocate registers the defs
|
||||||
if (op.isDef())
|
if (op.isDef())
|
||||||
toSpill.push_back(virtReg);
|
toSpill.push_back(it);
|
||||||
else
|
else
|
||||||
toClear.push_back(virtReg);
|
toClear.push_back(it);
|
||||||
}
|
}
|
||||||
(*currentInstr_)->SetMachineOperandReg(i, physReg);
|
(*currentInstr_)->SetMachineOperandReg(i, physReg);
|
||||||
}
|
}
|
||||||
@@ -504,16 +506,16 @@ bool RA::runOnMachineFunction(MachineFunction &fn) {
|
|||||||
assert(!op.isUse() && "we should not have uses here!");
|
assert(!op.isUse() && "we should not have uses here!");
|
||||||
unsigned virtReg = op.getAllocatedRegNum();
|
unsigned virtReg = op.getAllocatedRegNum();
|
||||||
unsigned physReg = 0;
|
unsigned physReg = 0;
|
||||||
Virt2PhysMap::const_iterator it = v2pMap_.find(virtReg);
|
Virt2PhysMap::iterator it = v2pMap_.find(virtReg);
|
||||||
if (it != v2pMap_.end()) {
|
if (it != v2pMap_.end()) {
|
||||||
physReg = it->second;
|
physReg = it->second;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
physReg = getFreeTempPhysReg(virtReg);
|
physReg = getFreeTempPhysReg(virtReg);
|
||||||
assignVirt2PhysReg(virtReg, physReg);
|
it = assignVirt2PhysReg(virtReg, physReg);
|
||||||
// need to spill this after we are done with
|
// need to spill this after we are done with
|
||||||
// this instruction
|
// this instruction
|
||||||
toSpill.push_back(virtReg);
|
toSpill.push_back(it);
|
||||||
}
|
}
|
||||||
(*currentInstr_)->SetMachineOperandReg(i, physReg);
|
(*currentInstr_)->SetMachineOperandReg(i, physReg);
|
||||||
}
|
}
|
||||||
@@ -774,17 +776,20 @@ unsigned RA::getFreeTempPhysReg(unsigned virtReg)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RA::assignVirt2PhysReg(unsigned virtReg, unsigned physReg)
|
RA::Virt2PhysMap::iterator
|
||||||
|
RA::assignVirt2PhysReg(unsigned virtReg, unsigned physReg)
|
||||||
{
|
{
|
||||||
bool inserted = v2pMap_.insert(std::make_pair(virtReg, physReg)).second;
|
bool inserted;
|
||||||
|
Virt2PhysMap::iterator it;
|
||||||
|
tie(it, inserted) = v2pMap_.insert(std::make_pair(virtReg, physReg));
|
||||||
assert(inserted && "attempting to assign a virt->phys mapping to an "
|
assert(inserted && "attempting to assign a virt->phys mapping to an "
|
||||||
"already mapped register");
|
"already mapped register");
|
||||||
prt_.addPhysRegUse(physReg);
|
prt_.addPhysRegUse(physReg);
|
||||||
|
return it;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RA::clearVirtReg(unsigned virtReg)
|
void RA::clearVirtReg(Virt2PhysMap::iterator it)
|
||||||
{
|
{
|
||||||
Virt2PhysMap::iterator it = v2pMap_.find(virtReg);
|
|
||||||
assert(it != v2pMap_.end() &&
|
assert(it != v2pMap_.end() &&
|
||||||
"attempting to clear a not allocated virtual register");
|
"attempting to clear a not allocated virtual register");
|
||||||
unsigned physReg = it->second;
|
unsigned physReg = it->second;
|
||||||
@@ -804,8 +809,9 @@ void RA::assignVirt2StackSlot(unsigned virtReg)
|
|||||||
"attempt to assign stack slot to already assigned register?");
|
"attempt to assign stack slot to already assigned register?");
|
||||||
// if the virtual register was previously assigned clear the mapping
|
// if the virtual register was previously assigned clear the mapping
|
||||||
// and free the virtual register
|
// and free the virtual register
|
||||||
if (v2pMap_.count(virtReg)) {
|
Virt2PhysMap::iterator it = v2pMap_.find(virtReg);
|
||||||
clearVirtReg(virtReg);
|
if (it != v2pMap_.end()) {
|
||||||
|
clearVirtReg(it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -817,19 +823,23 @@ int RA::getStackSlot(unsigned virtReg)
|
|||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RA::spillVirtReg(unsigned virtReg)
|
void RA::spillVirtReg(Virt2PhysMap::iterator it)
|
||||||
{
|
{
|
||||||
|
assert(it != v2pMap_.end() &&
|
||||||
|
"attempt to spill a not allocated virtual register");
|
||||||
|
unsigned virtReg = it->first;
|
||||||
DEBUG(std::cerr << "\t\t\tspilling register: " << virtReg);
|
DEBUG(std::cerr << "\t\t\tspilling register: " << virtReg);
|
||||||
const TargetRegisterClass* rc = mf_->getSSARegMap()->getRegClass(virtReg);
|
const TargetRegisterClass* rc = mf_->getSSARegMap()->getRegClass(virtReg);
|
||||||
int frameIndex = getStackSlot(virtReg);
|
int frameIndex = getStackSlot(virtReg);
|
||||||
DEBUG(std::cerr << " to stack slot #" << frameIndex << '\n');
|
DEBUG(std::cerr << " to stack slot #" << frameIndex << '\n');
|
||||||
++numSpilled;
|
++numSpilled;
|
||||||
instrAdded_ += mri_->storeRegToStackSlot(*currentMbb_, currentInstr_,
|
instrAdded_ += mri_->storeRegToStackSlot(*currentMbb_, currentInstr_,
|
||||||
v2pMap_[virtReg], frameIndex, rc);
|
it->second, frameIndex, rc);
|
||||||
clearVirtReg(virtReg);
|
clearVirtReg(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RA::loadVirt2PhysReg(unsigned virtReg, unsigned physReg)
|
RA::Virt2PhysMap::iterator
|
||||||
|
RA::loadVirt2PhysReg(unsigned virtReg, unsigned physReg)
|
||||||
{
|
{
|
||||||
DEBUG(std::cerr << "\t\t\tloading register: " << virtReg);
|
DEBUG(std::cerr << "\t\t\tloading register: " << virtReg);
|
||||||
const TargetRegisterClass* rc = mf_->getSSARegMap()->getRegClass(virtReg);
|
const TargetRegisterClass* rc = mf_->getSSARegMap()->getRegClass(virtReg);
|
||||||
@@ -838,7 +848,7 @@ void RA::loadVirt2PhysReg(unsigned virtReg, unsigned physReg)
|
|||||||
++numReloaded;
|
++numReloaded;
|
||||||
instrAdded_ += mri_->loadRegFromStackSlot(*currentMbb_, currentInstr_,
|
instrAdded_ += mri_->loadRegFromStackSlot(*currentMbb_, currentInstr_,
|
||||||
physReg, frameIndex, rc);
|
physReg, frameIndex, rc);
|
||||||
assignVirt2PhysReg(virtReg, physReg);
|
return assignVirt2PhysReg(virtReg, physReg);
|
||||||
}
|
}
|
||||||
|
|
||||||
FunctionPass* llvm::createLinearScanRegisterAllocator() {
|
FunctionPass* llvm::createLinearScanRegisterAllocator() {
|
||||||
|
Reference in New Issue
Block a user