mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-30 17:33:24 +00:00
Use an IndexedMap for LiveVariables::VirtRegInfo.
Provide MRI::getNumVirtRegs() and TRI::index2VirtReg() functions to allow iteration over virtual registers without depending on the representation of virtual register numbers. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123098 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
56e4d89642
commit
b421c566f5
@ -32,8 +32,10 @@
|
||||
#include "llvm/CodeGen/MachineBasicBlock.h"
|
||||
#include "llvm/CodeGen/MachineFunctionPass.h"
|
||||
#include "llvm/CodeGen/MachineInstr.h"
|
||||
#include "llvm/Target/TargetRegisterInfo.h"
|
||||
#include "llvm/ADT/BitVector.h"
|
||||
#include "llvm/ADT/DenseMap.h"
|
||||
#include "llvm/ADT/IndexedMap.h"
|
||||
#include "llvm/ADT/SmallSet.h"
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/ADT/SparseBitVector.h"
|
||||
@ -121,10 +123,9 @@ public:
|
||||
|
||||
private:
|
||||
/// VirtRegInfo - This list is a mapping from virtual register number to
|
||||
/// variable information. FirstVirtualRegister is subtracted from the virtual
|
||||
/// register number before indexing into this list.
|
||||
/// variable information.
|
||||
///
|
||||
std::vector<VarInfo> VirtRegInfo;
|
||||
IndexedMap<VarInfo, VirtReg2IndexFunctor> VirtRegInfo;
|
||||
|
||||
/// PHIJoins - list of virtual registers that are PHI joins. These registers
|
||||
/// may have multiple definitions, and they require special handling when
|
||||
|
@ -216,10 +216,14 @@ public:
|
||||
///
|
||||
unsigned createVirtualRegister(const TargetRegisterClass *RegClass);
|
||||
|
||||
/// getNumVirtRegs - Return the number of virtual registers created.
|
||||
///
|
||||
unsigned getNumVirtRegs() const { return VRegInfo.size(); }
|
||||
|
||||
/// getLastVirtReg - Return the highest currently assigned virtual register.
|
||||
///
|
||||
unsigned getLastVirtReg() const {
|
||||
return (unsigned)VRegInfo.size()+TargetRegisterInfo::FirstVirtualRegister-1;
|
||||
return TargetRegisterInfo::index2VirtReg(getNumVirtRegs() - 1);
|
||||
}
|
||||
|
||||
/// getRegClassVirtRegs - Return the list of virtual registers of the given
|
||||
|
@ -321,6 +321,12 @@ public:
|
||||
return Reg >= FirstVirtualRegister;
|
||||
}
|
||||
|
||||
/// index2VirtReg - Convert a 0-based index to a virtual register number.
|
||||
/// This is the inverse operation of VirtReg2IndexFunctor below.
|
||||
static unsigned index2VirtReg(unsigned Index) {
|
||||
return Index + FirstVirtualRegister;
|
||||
}
|
||||
|
||||
/// printReg - Print a virtual or physical register on OS.
|
||||
void printReg(unsigned Reg, raw_ostream &OS) const;
|
||||
|
||||
|
@ -31,7 +31,6 @@
|
||||
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
||||
#include "llvm/CodeGen/Passes.h"
|
||||
#include "llvm/Support/Debug.h"
|
||||
#include "llvm/Target/TargetRegisterInfo.h"
|
||||
#include "llvm/Target/TargetInstrInfo.h"
|
||||
#include "llvm/Target/TargetMachine.h"
|
||||
#include "llvm/ADT/DepthFirstIterator.h"
|
||||
@ -82,13 +81,7 @@ void LiveVariables::VarInfo::dump() const {
|
||||
LiveVariables::VarInfo &LiveVariables::getVarInfo(unsigned RegIdx) {
|
||||
assert(TargetRegisterInfo::isVirtualRegister(RegIdx) &&
|
||||
"getVarInfo: not a virtual register!");
|
||||
RegIdx -= TargetRegisterInfo::FirstVirtualRegister;
|
||||
if (RegIdx >= VirtRegInfo.size()) {
|
||||
if (RegIdx >= 2*VirtRegInfo.size())
|
||||
VirtRegInfo.resize(RegIdx*2);
|
||||
else
|
||||
VirtRegInfo.resize(2*VirtRegInfo.size());
|
||||
}
|
||||
VirtRegInfo.grow(RegIdx);
|
||||
return VirtRegInfo[RegIdx];
|
||||
}
|
||||
|
||||
@ -501,9 +494,6 @@ bool LiveVariables::runOnMachineFunction(MachineFunction &mf) {
|
||||
std::fill(PhysRegUse, PhysRegUse + NumRegs, (MachineInstr*)0);
|
||||
PHIJoins.clear();
|
||||
|
||||
/// Get some space for a respectable number of registers.
|
||||
VirtRegInfo.resize(64);
|
||||
|
||||
analyzePHINodes(mf);
|
||||
|
||||
// Calculate live variable information in depth first order on the CFG of the
|
||||
@ -631,19 +621,14 @@ bool LiveVariables::runOnMachineFunction(MachineFunction &mf) {
|
||||
|
||||
// Convert and transfer the dead / killed information we have gathered into
|
||||
// VirtRegInfo onto MI's.
|
||||
for (unsigned i = 0, e1 = VirtRegInfo.size(); i != e1; ++i)
|
||||
for (unsigned j = 0, e2 = VirtRegInfo[i].Kills.size(); j != e2; ++j)
|
||||
if (VirtRegInfo[i].Kills[j] ==
|
||||
MRI->getVRegDef(i + TargetRegisterInfo::FirstVirtualRegister))
|
||||
VirtRegInfo[i]
|
||||
.Kills[j]->addRegisterDead(i +
|
||||
TargetRegisterInfo::FirstVirtualRegister,
|
||||
TRI);
|
||||
for (unsigned i = 0, e1 = VirtRegInfo.size(); i != e1; ++i) {
|
||||
const unsigned Reg = TargetRegisterInfo::index2VirtReg(i);
|
||||
for (unsigned j = 0, e2 = VirtRegInfo[Reg].Kills.size(); j != e2; ++j)
|
||||
if (VirtRegInfo[Reg].Kills[j] == MRI->getVRegDef(Reg))
|
||||
VirtRegInfo[Reg].Kills[j]->addRegisterDead(Reg, TRI);
|
||||
else
|
||||
VirtRegInfo[i]
|
||||
.Kills[j]->addRegisterKilled(i +
|
||||
TargetRegisterInfo::FirstVirtualRegister,
|
||||
TRI);
|
||||
VirtRegInfo[Reg].Kills[j]->addRegisterKilled(Reg, TRI);
|
||||
}
|
||||
|
||||
// Check to make sure there are no unreachable blocks in the MC CFG for the
|
||||
// function. If so, it is due to a bug in the instruction selector or some
|
||||
@ -778,8 +763,8 @@ void LiveVariables::addNewBlock(MachineBasicBlock *BB,
|
||||
getVarInfo(BBI->getOperand(i).getReg()).AliveBlocks.set(NumNew);
|
||||
|
||||
// Update info for all live variables
|
||||
for (unsigned Reg = TargetRegisterInfo::FirstVirtualRegister,
|
||||
E = MRI->getLastVirtReg()+1; Reg != E; ++Reg) {
|
||||
for (unsigned i = 0, e = MRI->getNumVirtRegs(); i != e; ++i) {
|
||||
unsigned Reg = TargetRegisterInfo::index2VirtReg(i);
|
||||
VarInfo &VI = getVarInfo(Reg);
|
||||
if (!VI.AliveBlocks.test(NumNew) && VI.isLiveIn(*SuccBB, Reg, *MRI))
|
||||
VI.AliveBlocks.set(NumNew);
|
||||
|
Loading…
Reference in New Issue
Block a user