// buildInterferenceGraph
std::stack<IGNode *> IGNodeStack; // the stack used for coloring
- const ReservedColorListType *const ReservedColorList;
+ // ReservedColorList - for passing registers that are pre-allocated and cannot
+ // be used by the register allocator for this function.
//
- // for passing registers that are pre-allocated and cannot be used by the
- // register allocator for this function.
+ const ReservedColorListType *const ReservedColorList;
- bool *IsColorUsedArr;
+ // IsColorUsedArr - An array used for coloring each node. This array must be
+ // of size MRC->getNumOfAllRegs(). Allocated once in the constructor for
+ // efficiency.
//
- // An array used for coloring each node. This array must be of size
- // MRC->getNumOfAllRegs(). Allocated once in the constructor
- // for efficiency.
+ std::vector<bool> IsColorUsedArr;
+
//--------------------------- private methods ------------------------------
const MachineRegClassInfo *MRC,
const ReservedColorListType *RCL = 0);
- ~RegClass() { delete[] IsColorUsedArr; }
-
inline void createInterferenceGraph() { IG.createGraph(); }
inline InterferenceGraph &getIG() { return IG; }
{ IG.mergeIGNodesOfLRs(LR1, LR2); }
- inline bool * getIsColorUsedArr() { return IsColorUsedArr; }
+ inline std::vector<bool> &getIsColorUsedArr() { return IsColorUsedArr; }
inline void printIGNodeList() const {
// This method should find a color which is not used by neighbors
// (i.e., a false position in IsColorUsedArr) and
- virtual void colorIGNode(IGNode *Node, bool IsColorUsedArr[]) const = 0;
+ virtual void colorIGNode(IGNode *Node,
+ std::vector<bool> &IsColorUsedArr) const = 0;
virtual bool isRegVolatile(int Reg) const = 0;
MachineRegClassInfo(unsigned ID, unsigned NVR, unsigned NAR)
unsigned NumAvailRegs = RC->getNumOfAvailRegs();
- bool *IsColorUsedArr = RC->getIsColorUsedArr();
+ std::vector<bool> &IsColorUsedArr = RC->getIsColorUsedArr();
for(unsigned i=0; i < NumAvailRegs; i++) // Reset array
IsColorUsedArr[i] = false;
setRelRegsUsedByThisInst(RC, MInst);
- unsigned c; // find first unused color
- for( c=0; c < NumAvailRegs; c++)
- if( ! IsColorUsedArr[ c ] ) break;
+ for(unsigned c=0; c < NumAvailRegs; c++) // find first unused color
+ if (!IsColorUsedArr[c])
+ return MRI.getUnifiedRegNum(RC->getID(), c);
- if(c < NumAvailRegs)
- return MRI.getUnifiedRegNum(RC->getID(), c);
- else
- return -1;
-
-
+ return -1;
}
// by operands of a machine instruction. Returns the unified reg number.
//----------------------------------------------------------------------------
int PhyRegAlloc::getUniRegNotUsedByThisInst(RegClass *RC,
- const MachineInstr *MInst) {
+ const MachineInstr *MInst) {
- bool *IsColorUsedArr = RC->getIsColorUsedArr();
+ vector<bool> &IsColorUsedArr = RC->getIsColorUsedArr();
unsigned NumAvailRegs = RC->getNumOfAvailRegs();
setRelRegsUsedByThisInst(RC, MInst);
- unsigned c; // find first unused color
- for( c=0; c < RC->getNumOfAvailRegs(); c++)
- if( ! IsColorUsedArr[ c ] ) break;
-
- if(c < NumAvailRegs)
- return MRI.getUnifiedRegNum(RC->getID(), c);
- else
- assert( 0 && "FATAL: No free register could be found in reg class!!");
+ for(unsigned c=0; c < RC->getNumOfAvailRegs(); c++)// find first unused color
+ if (!IsColorUsedArr[c])
+ return MRI.getUnifiedRegNum(RC->getID(), c);
+
+ assert(0 && "FATAL: No free register could be found in reg class!!");
return 0;
}
void PhyRegAlloc::setRelRegsUsedByThisInst(RegClass *RC,
const MachineInstr *MInst ) {
- bool *IsColorUsedArr = RC->getIsColorUsedArr();
+ vector<bool> &IsColorUsedArr = RC->getIsColorUsedArr();
for(unsigned OpNum=0; OpNum < MInst->getNumOperands(); ++OpNum) {
if( MRI.getRegClassIDOfValue(Val) == RC->getID() ) {
int Reg;
if( (Reg=Op.getAllocatedRegNum()) != -1) {
- IsColorUsedArr[ Reg ] = true;
+ IsColorUsedArr[Reg] = true;
}
else {
// it is possilbe that this operand still is not marked with
LiveRange *LROfVal = LRI.getLiveRangeForValue(Val);
if( LROfVal)
if( LROfVal->hasColor() )
- IsColorUsedArr[ LROfVal->getColor() ] = true;
+ IsColorUsedArr[LROfVal->getColor()] = true;
}
} // if reg classes are the same
}
else if (Op.getOperandType() == MachineOperand::MO_MachineRegister) {
- IsColorUsedArr[ Op.getMachineRegNum() ] = true;
+ assert((unsigned)Op.getMachineRegNum() < IsColorUsedArr.size());
+ IsColorUsedArr[Op.getMachineRegNum()] = true;
}
}
if( DEBUG_RA)
cerr << "Created Reg Class: " << RegClassID << "\n";
- IsColorUsedArr = new bool[ Mrc->getNumOfAllRegs() ];
+ IsColorUsedArr.resize(Mrc->getNumOfAllRegs());
}
// init all elements of to IsColorUsedAr false;
//
- for( unsigned i=0; i < MRC->getNumOfAllRegs(); i++) {
- IsColorUsedArr[ i ] = false;
- }
+ for (unsigned i=0; i < MRC->getNumOfAllRegs(); i++)
+ IsColorUsedArr[i] = false;
// init all reserved_regs to true - we can't use them
//
for( unsigned i=0; i < ReservedColorList->size() ; i++) {
- IsColorUsedArr[ (*ReservedColorList)[i] ] = true;
+ IsColorUsedArr[(*ReservedColorList)[i]] = true;
}
// initialize all colors used by neighbors of this node to true
// buildInterferenceGraph
std::stack<IGNode *> IGNodeStack; // the stack used for coloring
- const ReservedColorListType *const ReservedColorList;
+ // ReservedColorList - for passing registers that are pre-allocated and cannot
+ // be used by the register allocator for this function.
//
- // for passing registers that are pre-allocated and cannot be used by the
- // register allocator for this function.
+ const ReservedColorListType *const ReservedColorList;
- bool *IsColorUsedArr;
+ // IsColorUsedArr - An array used for coloring each node. This array must be
+ // of size MRC->getNumOfAllRegs(). Allocated once in the constructor for
+ // efficiency.
//
- // An array used for coloring each node. This array must be of size
- // MRC->getNumOfAllRegs(). Allocated once in the constructor
- // for efficiency.
+ std::vector<bool> IsColorUsedArr;
+
//--------------------------- private methods ------------------------------
const MachineRegClassInfo *MRC,
const ReservedColorListType *RCL = 0);
- ~RegClass() { delete[] IsColorUsedArr; }
-
inline void createInterferenceGraph() { IG.createGraph(); }
inline InterferenceGraph &getIG() { return IG; }
{ IG.mergeIGNodesOfLRs(LR1, LR2); }
- inline bool * getIsColorUsedArr() { return IsColorUsedArr; }
+ inline std::vector<bool> &getIsColorUsedArr() { return IsColorUsedArr; }
inline void printIGNodeList() const {
unsigned NumAvailRegs = RC->getNumOfAvailRegs();
- bool *IsColorUsedArr = RC->getIsColorUsedArr();
+ std::vector<bool> &IsColorUsedArr = RC->getIsColorUsedArr();
for(unsigned i=0; i < NumAvailRegs; i++) // Reset array
IsColorUsedArr[i] = false;
setRelRegsUsedByThisInst(RC, MInst);
- unsigned c; // find first unused color
- for( c=0; c < NumAvailRegs; c++)
- if( ! IsColorUsedArr[ c ] ) break;
+ for(unsigned c=0; c < NumAvailRegs; c++) // find first unused color
+ if (!IsColorUsedArr[c])
+ return MRI.getUnifiedRegNum(RC->getID(), c);
- if(c < NumAvailRegs)
- return MRI.getUnifiedRegNum(RC->getID(), c);
- else
- return -1;
-
-
+ return -1;
}
// by operands of a machine instruction. Returns the unified reg number.
//----------------------------------------------------------------------------
int PhyRegAlloc::getUniRegNotUsedByThisInst(RegClass *RC,
- const MachineInstr *MInst) {
+ const MachineInstr *MInst) {
- bool *IsColorUsedArr = RC->getIsColorUsedArr();
+ vector<bool> &IsColorUsedArr = RC->getIsColorUsedArr();
unsigned NumAvailRegs = RC->getNumOfAvailRegs();
setRelRegsUsedByThisInst(RC, MInst);
- unsigned c; // find first unused color
- for( c=0; c < RC->getNumOfAvailRegs(); c++)
- if( ! IsColorUsedArr[ c ] ) break;
-
- if(c < NumAvailRegs)
- return MRI.getUnifiedRegNum(RC->getID(), c);
- else
- assert( 0 && "FATAL: No free register could be found in reg class!!");
+ for(unsigned c=0; c < RC->getNumOfAvailRegs(); c++)// find first unused color
+ if (!IsColorUsedArr[c])
+ return MRI.getUnifiedRegNum(RC->getID(), c);
+
+ assert(0 && "FATAL: No free register could be found in reg class!!");
return 0;
}
void PhyRegAlloc::setRelRegsUsedByThisInst(RegClass *RC,
const MachineInstr *MInst ) {
- bool *IsColorUsedArr = RC->getIsColorUsedArr();
+ vector<bool> &IsColorUsedArr = RC->getIsColorUsedArr();
for(unsigned OpNum=0; OpNum < MInst->getNumOperands(); ++OpNum) {
if( MRI.getRegClassIDOfValue(Val) == RC->getID() ) {
int Reg;
if( (Reg=Op.getAllocatedRegNum()) != -1) {
- IsColorUsedArr[ Reg ] = true;
+ IsColorUsedArr[Reg] = true;
}
else {
// it is possilbe that this operand still is not marked with
LiveRange *LROfVal = LRI.getLiveRangeForValue(Val);
if( LROfVal)
if( LROfVal->hasColor() )
- IsColorUsedArr[ LROfVal->getColor() ] = true;
+ IsColorUsedArr[LROfVal->getColor()] = true;
}
} // if reg classes are the same
}
else if (Op.getOperandType() == MachineOperand::MO_MachineRegister) {
- IsColorUsedArr[ Op.getMachineRegNum() ] = true;
+ assert((unsigned)Op.getMachineRegNum() < IsColorUsedArr.size());
+ IsColorUsedArr[Op.getMachineRegNum()] = true;
}
}
if( DEBUG_RA)
cerr << "Created Reg Class: " << RegClassID << "\n";
- IsColorUsedArr = new bool[ Mrc->getNumOfAllRegs() ];
+ IsColorUsedArr.resize(Mrc->getNumOfAllRegs());
}
// init all elements of to IsColorUsedAr false;
//
- for( unsigned i=0; i < MRC->getNumOfAllRegs(); i++) {
- IsColorUsedArr[ i ] = false;
- }
+ for (unsigned i=0; i < MRC->getNumOfAllRegs(); i++)
+ IsColorUsedArr[i] = false;
// init all reserved_regs to true - we can't use them
//
for( unsigned i=0; i < ReservedColorList->size() ; i++) {
- IsColorUsedArr[ (*ReservedColorList)[i] ] = true;
+ IsColorUsedArr[(*ReservedColorList)[i]] = true;
}
// initialize all colors used by neighbors of this node to true
// buildInterferenceGraph
std::stack<IGNode *> IGNodeStack; // the stack used for coloring
- const ReservedColorListType *const ReservedColorList;
+ // ReservedColorList - for passing registers that are pre-allocated and cannot
+ // be used by the register allocator for this function.
//
- // for passing registers that are pre-allocated and cannot be used by the
- // register allocator for this function.
+ const ReservedColorListType *const ReservedColorList;
- bool *IsColorUsedArr;
+ // IsColorUsedArr - An array used for coloring each node. This array must be
+ // of size MRC->getNumOfAllRegs(). Allocated once in the constructor for
+ // efficiency.
//
- // An array used for coloring each node. This array must be of size
- // MRC->getNumOfAllRegs(). Allocated once in the constructor
- // for efficiency.
+ std::vector<bool> IsColorUsedArr;
+
//--------------------------- private methods ------------------------------
const MachineRegClassInfo *MRC,
const ReservedColorListType *RCL = 0);
- ~RegClass() { delete[] IsColorUsedArr; }
-
inline void createInterferenceGraph() { IG.createGraph(); }
inline InterferenceGraph &getIG() { return IG; }
{ IG.mergeIGNodesOfLRs(LR1, LR2); }
- inline bool * getIsColorUsedArr() { return IsColorUsedArr; }
+ inline std::vector<bool> &getIsColorUsedArr() { return IsColorUsedArr; }
inline void printIGNodeList() const {
// If both above fail, spill.
//
//-----------------------------------------------------------------------------
-void SparcIntRegClass::colorIGNode(IGNode * Node, bool IsColorUsedArr[]) const {
+void SparcIntRegClass::colorIGNode(IGNode * Node, vector<bool> &IsColorUsedArr) const {
LiveRange *LR = Node->getParentLR();
if( DEBUG_RA ) {
unsigned SugCol = LR->getSuggestedColor();
- if( ! IsColorUsedArr[ SugCol ] ) {
+ if (!IsColorUsedArr[SugCol]) {
if( LR->isSuggestedColorUsable() ) {
// find first unused color
for( c=SearchStart; c < SparcIntRegOrder::NumOfAvailRegs; c++) {
- if( ! IsColorUsedArr[ c ] ) { ColorFound = true; break; }
+ if(!IsColorUsedArr[c] ) { ColorFound = true; break; }
}
if( ColorFound) {
// If a color is still not fond, mark for spilling
//
//----------------------------------------------------------------------------
-void SparcFloatRegClass::colorIGNode(IGNode * Node,bool IsColorUsedArr[]) const{
+void SparcFloatRegClass::colorIGNode(IGNode * Node,
+ vector<bool> &IsColorUsedArr) const{
LiveRange *LR = Node->getParentLR();
// Mark the second color for double-precision registers:
int ColorFound = -1; // have we found a color yet?
bool isCallInterf = LR->isCallInterference();
- // if value is a double - search the double only reigon (f32 - f63)
+ // if value is a double - search the double only region (f32 - f63)
// i.e. we try to allocate f32 - f63 first for doubles since singles
// cannot go there. By doing that, we provide more space for singles
// in f0 - f31
int SparcFloatRegClass::findFloatColor(const LiveRange *LR,
unsigned Start, unsigned End,
- bool IsColorUsedArr[]) const {
+ vector<bool> &IsColorUsedArr) const {
bool ColorFound = false;
unsigned c;
SparcIntRegOrder::NumOfAvailRegs,
SparcIntRegOrder::NumOfAllRegs) { }
- void colorIGNode(IGNode *Node, bool IsColorUsedArr[]) const;
+ void colorIGNode(IGNode *Node, std::vector<bool> &IsColorUsedArr) const;
inline bool isRegVolatile(int Reg) const {
return (Reg < (int) SparcIntRegOrder::StartOfNonVolatileRegs);
class SparcFloatRegClass : public MachineRegClassInfo {
int findFloatColor(const LiveRange *LR, unsigned Start,
- unsigned End, bool IsColorUsedArr[]) const;
+ unsigned End, std::vector<bool> &IsColorUsedArr) const;
public:
SparcFloatRegClass(unsigned ID)
: MachineRegClassInfo(ID,
SparcFloatRegOrder::NumOfAvailRegs,
SparcFloatRegOrder::NumOfAllRegs) {}
- void colorIGNode(IGNode *Node, bool IsColorUsedArr[]) const;
+ void colorIGNode(IGNode *Node, std::vector<bool> &IsColorUsedArr) const;
// according to Sparc 64 ABI, all %fp regs are volatile
inline bool isRegVolatile(int Reg) const { return true; }
SparcIntCCRegClass(unsigned ID)
: MachineRegClassInfo(ID, 1, 2) { }
- inline void colorIGNode(IGNode *Node, bool IsColorUsedArr[]) const {
+ void colorIGNode(IGNode *Node, std::vector<bool> &IsColorUsedArr) const {
if (IsColorUsedArr[0])
Node->getParentLR()->markForSpill();
else
SparcFloatCCRegClass(unsigned ID)
: MachineRegClassInfo(ID, 4, 4) { }
- void colorIGNode(IGNode *Node, bool IsColorUsedArr[]) const {
- int c;
- for(c=0; c < 4 && IsColorUsedArr[c] ; ++c) ; // find unused color
- if (c < 4)
- Node->setColor(c);
- else
- Node->getParentLR()->markForSpill();
+ void colorIGNode(IGNode *Node, std::vector<bool> &IsColorUsedArr) const {
+ for(unsigned c = 0; c != 4; ++c)
+ if (!IsColorUsedArr[c]) { // find unused color
+ Node->setColor(c);
+ return;
+ }
+
+ Node->getParentLR()->markForSpill();
}
// according to Sparc 64 ABI, all %fp CC regs are volatile