summaryrefslogtreecommitdiff
path: root/lib/CodeGen
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-05-23 15:50:03 +0000
committerChris Lattner <sabre@nondot.org>2002-05-23 15:50:03 +0000
commit85c5465e072b3bbebb1f5e112fb2db46f7fba148 (patch)
tree180e26923207d78d82621158e9f5476d9554008d /lib/CodeGen
parent195755ced7b7fb8b941e5d085fe5bd82f36f481e (diff)
downloadllvm-85c5465e072b3bbebb1f5e112fb2db46f7fba148.tar.gz
llvm-85c5465e072b3bbebb1f5e112fb2db46f7fba148.tar.bz2
llvm-85c5465e072b3bbebb1f5e112fb2db46f7fba148.tar.xz
Convert RegClass::IsColorUsedArr from a dynamically allocated array to
a vector. This makes asserting on array bounds easier. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2731 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r--lib/CodeGen/RegAlloc/PhyRegAlloc.cpp41
-rw-r--r--lib/CodeGen/RegAlloc/RegClass.cpp9
-rw-r--r--lib/CodeGen/RegAlloc/RegClass.h19
3 files changed, 30 insertions, 39 deletions
diff --git a/lib/CodeGen/RegAlloc/PhyRegAlloc.cpp b/lib/CodeGen/RegAlloc/PhyRegAlloc.cpp
index bd0db117f0..6a7031bab5 100644
--- a/lib/CodeGen/RegAlloc/PhyRegAlloc.cpp
+++ b/lib/CodeGen/RegAlloc/PhyRegAlloc.cpp
@@ -797,7 +797,7 @@ int PhyRegAlloc::getUnusedUniRegAtMI(RegClass *RC,
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;
@@ -822,16 +822,11 @@ int PhyRegAlloc::getUnusedUniRegAtMI(RegClass *RC,
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;
}
@@ -840,9 +835,9 @@ int PhyRegAlloc::getUnusedUniRegAtMI(RegClass *RC,
// 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();
@@ -851,14 +846,11 @@ int PhyRegAlloc::getUniRegNotUsedByThisInst(RegClass *RC,
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;
}
@@ -871,7 +863,7 @@ int PhyRegAlloc::getUniRegNotUsedByThisInst(RegClass *RC,
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) {
@@ -886,7 +878,7 @@ void PhyRegAlloc::setRelRegsUsedByThisInst(RegClass *RC,
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
@@ -895,13 +887,14 @@ void PhyRegAlloc::setRelRegsUsedByThisInst(RegClass *RC,
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;
}
}
diff --git a/lib/CodeGen/RegAlloc/RegClass.cpp b/lib/CodeGen/RegAlloc/RegClass.cpp
index c680bbfc31..5998f1fd66 100644
--- a/lib/CodeGen/RegAlloc/RegClass.cpp
+++ b/lib/CodeGen/RegAlloc/RegClass.cpp
@@ -14,7 +14,7 @@ RegClass::RegClass(const Function *M,
if( DEBUG_RA)
cerr << "Created Reg Class: " << RegClassID << "\n";
- IsColorUsedArr = new bool[ Mrc->getNumOfAllRegs() ];
+ IsColorUsedArr.resize(Mrc->getNumOfAllRegs());
}
@@ -200,14 +200,13 @@ void RegClass::colorIGNode(IGNode *const Node)
// 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
diff --git a/lib/CodeGen/RegAlloc/RegClass.h b/lib/CodeGen/RegAlloc/RegClass.h
index c93d6961e0..4584a5f7a1 100644
--- a/lib/CodeGen/RegAlloc/RegClass.h
+++ b/lib/CodeGen/RegAlloc/RegClass.h
@@ -42,16 +42,17 @@ class RegClass {
// 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 ------------------------------
@@ -71,8 +72,6 @@ class RegClass {
const MachineRegClassInfo *MRC,
const ReservedColorListType *RCL = 0);
- ~RegClass() { delete[] IsColorUsedArr; }
-
inline void createInterferenceGraph() { IG.createGraph(); }
inline InterferenceGraph &getIG() { return IG; }
@@ -106,7 +105,7 @@ class RegClass {
{ IG.mergeIGNodesOfLRs(LR1, LR2); }
- inline bool * getIsColorUsedArr() { return IsColorUsedArr; }
+ inline std::vector<bool> &getIsColorUsedArr() { return IsColorUsedArr; }
inline void printIGNodeList() const {