diff options
Diffstat (limited to 'lib/CodeGen/RegAlloc')
-rw-r--r-- | lib/CodeGen/RegAlloc/IGNode.cpp | 24 | ||||
-rw-r--r-- | lib/CodeGen/RegAlloc/IGNode.h | 13 | ||||
-rw-r--r-- | lib/CodeGen/RegAlloc/InterferenceGraph.cpp | 76 | ||||
-rw-r--r-- | lib/CodeGen/RegAlloc/InterferenceGraph.h | 12 | ||||
-rw-r--r-- | lib/CodeGen/RegAlloc/LiveRange.h | 5 | ||||
-rw-r--r-- | lib/CodeGen/RegAlloc/LiveRangeInfo.cpp | 124 | ||||
-rw-r--r-- | lib/CodeGen/RegAlloc/LiveRangeInfo.h | 10 | ||||
-rw-r--r-- | lib/CodeGen/RegAlloc/PhyRegAlloc.cpp | 170 | ||||
-rw-r--r-- | lib/CodeGen/RegAlloc/PhyRegAlloc.h | 18 | ||||
-rw-r--r-- | lib/CodeGen/RegAlloc/RegClass.cpp | 25 | ||||
-rw-r--r-- | lib/CodeGen/RegAlloc/RegClass.h | 16 |
11 files changed, 204 insertions, 289 deletions
diff --git a/lib/CodeGen/RegAlloc/IGNode.cpp b/lib/CodeGen/RegAlloc/IGNode.cpp index 4e66d9a762..a225742052 100644 --- a/lib/CodeGen/RegAlloc/IGNode.cpp +++ b/lib/CodeGen/RegAlloc/IGNode.cpp @@ -1,12 +1,13 @@ #include "llvm/CodeGen/IGNode.h" - +#include <algorithm> +#include <iostream> +using std::cerr; //----------------------------------------------------------------------------- // Constructor //----------------------------------------------------------------------------- -IGNode::IGNode(LiveRange *const PLR, unsigned int Ind): Index(Ind), - AdjList(), - ParentLR(PLR) +IGNode::IGNode(LiveRange *const PLR, unsigned int Ind) : Index(Ind), + ParentLR(PLR) { OnStack = false; CurDegree = -1 ; @@ -23,11 +24,12 @@ void IGNode::pushOnStack() int neighs = AdjList.size(); if( neighs < 0) { - cout << "\nAdj List size = " << neighs; + cerr << "\nAdj List size = " << neighs; assert(0 && "Invalid adj list size"); } - for(int i=0; i < neighs; i++) (AdjList[i])->decCurDegree(); + for(int i=0; i < neighs; i++) + AdjList[i]->decCurDegree(); } //----------------------------------------------------------------------------- @@ -35,11 +37,9 @@ void IGNode::pushOnStack() // two IGNodes together. //----------------------------------------------------------------------------- void IGNode::delAdjIGNode(const IGNode *const Node) { - vector <IGNode *>::iterator It = AdjList.begin(); - - // find Node - for( ; It != AdjList.end() && (*It != Node); It++ ) ; + std::vector<IGNode *>::iterator It = + find(AdjList.begin(), AdjList.end(), Node); assert( It != AdjList.end() ); // the node must be there - - AdjList.erase( It ); + + AdjList.erase(It); } diff --git a/lib/CodeGen/RegAlloc/IGNode.h b/lib/CodeGen/RegAlloc/IGNode.h index 0f4cf9c82a..b89aea32b1 100644 --- a/lib/CodeGen/RegAlloc/IGNode.h +++ b/lib/CodeGen/RegAlloc/IGNode.h @@ -29,8 +29,6 @@ #include "llvm/CodeGen/RegAllocCommon.h" #include "llvm/CodeGen/LiveRange.h" - - //---------------------------------------------------------------------------- // Class IGNode // @@ -39,13 +37,11 @@ class IGNode { - private: - const int Index; // index within IGNodeList bool OnStack; // this has been pushed on to stack for coloring - vector<IGNode *> AdjList; // adjacency list for this live range + std::vector<IGNode *> AdjList; // adjacency list for this live range int CurDegree; // @@ -54,7 +50,6 @@ class IGNode // Decremented when a neighbor is pushed on to the stack. // After that, never incremented/set again nor used. - LiveRange *const ParentLR; // parent LR (cannot be a const) @@ -152,10 +147,4 @@ class IGNode }; - - - - - - #endif diff --git a/lib/CodeGen/RegAlloc/InterferenceGraph.cpp b/lib/CodeGen/RegAlloc/InterferenceGraph.cpp index e18c9a7a34..0de7275acf 100644 --- a/lib/CodeGen/RegAlloc/InterferenceGraph.cpp +++ b/lib/CodeGen/RegAlloc/InterferenceGraph.cpp @@ -1,4 +1,7 @@ #include "llvm/CodeGen/InterferenceGraph.h" +#include "Support/STLExtras.h" +#include <iostream> +using std::cerr; //----------------------------------------------------------------------------- // Constructor: Records the RegClass and initalizes IGNodeList. @@ -11,7 +14,7 @@ InterferenceGraph::InterferenceGraph(RegClass *const RC) : RegCl(RC), IG = NULL; Size = 0; if( DEBUG_RA) { - cout << "Interference graph created!" << endl; + cerr << "Interference graph created!\n"; } } @@ -22,19 +25,12 @@ InterferenceGraph::InterferenceGraph(RegClass *const RC) : RegCl(RC), InterferenceGraph:: ~InterferenceGraph() { // delete the matrix - // - if( IG ) - delete []IG; + for(unsigned int r=0; r < IGNodeList.size(); ++r) + delete[] IG[r]; + delete[] IG; // delete all IGNodes in the IGNodeList - // - vector<IGNode *>::const_iterator IGIt = IGNodeList.begin(); - for(unsigned i=0; i < IGNodeList.size() ; ++i) { - - const IGNode *const Node = IGNodeList[i]; - if( Node ) delete Node; - } - + for_each(IGNodeList.begin(), IGNodeList.end(), deleter<IGNode>); } @@ -46,13 +42,13 @@ InterferenceGraph:: ~InterferenceGraph() { void InterferenceGraph::createGraph() { Size = IGNodeList.size(); - IG = (char **) new char *[Size]; + IG = new char*[Size]; for( unsigned int r=0; r < Size; ++r) IG[r] = new char[Size]; // init IG matrix for(unsigned int i=0; i < Size; i++) - for( unsigned int j=0; j < Size ; j++) + for(unsigned int j=0; j < Size; j++) IG[i][j] = 0; } @@ -61,9 +57,7 @@ void InterferenceGraph::createGraph() //----------------------------------------------------------------------------- void InterferenceGraph::addLRToIG(LiveRange *const LR) { - IGNode *Node = new IGNode(LR, IGNodeList.size() ); - IGNodeList.push_back( Node ); - + IGNodeList.push_back(new IGNode(LR, IGNodeList.size())); } @@ -92,12 +86,11 @@ void InterferenceGraph::setInterference(const LiveRange *const LR1, char *val; if( DEBUG_RA > 1) - cout << "setting intf for: [" << row << "][" << col << "]" << endl; + cerr << "setting intf for: [" << row << "][" << col << "]\n"; ( row > col) ? val = &IG[row][col]: val = &IG[col][row]; if( ! (*val) ) { // if this interf is not previously set - *val = 1; // add edges between nodes IGNode1->addAdjIGNode( IGNode2 ); IGNode2->addAdjIGNode( IGNode1 ); @@ -123,7 +116,10 @@ unsigned InterferenceGraph::getInterference(const LiveRange *const LR1, const unsigned int col = LR2->getUserIGNode()->getIndex(); char ret; - ( row > col) ? (ret = IG[row][col]) : (ret = IG[col][row]) ; + if (row > col) + ret = IG[row][col]; + else + ret = IG[col][row]; return ret; } @@ -148,9 +144,9 @@ void InterferenceGraph::mergeIGNodesOfLRs(const LiveRange *const LR1, assertIGNode( SrcNode ); if( DEBUG_RA > 1) { - cout << "Merging LRs: \""; LR1->printSet(); - cout << "\" and \""; LR2->printSet(); - cout << "\"" << endl; + cerr << "Merging LRs: \""; LR1->printSet(); + cerr << "\" and \""; LR2->printSet(); + cerr << "\"\n"; } unsigned SrcDegree = SrcNode->getNumOfNeighbors(); @@ -217,17 +213,16 @@ void InterferenceGraph::printIG() const for(unsigned int i=0; i < Size; i++) { const IGNode *const Node = IGNodeList[i]; - if( ! Node ) - continue; // skip empty rows - - cout << " [" << i << "] "; + if(Node) { + cerr << " [" << i << "] "; - for( unsigned int j=0; j < Size; j++) { - if( j >= i) break; - if( IG[i][j] ) cout << "(" << i << "," << j << ") "; + for( unsigned int j=0; j < i; j++) { + if(IG[i][j]) + cerr << "(" << i << "," << j << ") "; } - cout << endl; + cerr << "\n"; } + } } //---------------------------------------------------------------------------- @@ -235,21 +230,14 @@ void InterferenceGraph::printIG() const //---------------------------------------------------------------------------- void InterferenceGraph::printIGNodeList() const { - vector<IGNode *>::const_iterator IGIt = IGNodeList.begin(); // hash map iter - for(unsigned i=0; i < IGNodeList.size() ; ++i) { - const IGNode *const Node = IGNodeList[i]; - if( ! Node ) - continue; - - cout << " [" << Node->getIndex() << "] "; - (Node->getParentLR())->printSet(); - //int Deg = Node->getCurDegree(); - cout << "\t <# of Neighs: " << Node->getNumOfNeighbors() << ">" << endl; - + if (Node) { + cerr << " [" << Node->getIndex() << "] "; + Node->getParentLR()->printSet(); + //int Deg = Node->getCurDegree(); + cerr << "\t <# of Neighs: " << Node->getNumOfNeighbors() << ">\n"; + } } } - - diff --git a/lib/CodeGen/RegAlloc/InterferenceGraph.h b/lib/CodeGen/RegAlloc/InterferenceGraph.h index 99dea8fbe0..408bee4558 100644 --- a/lib/CodeGen/RegAlloc/InterferenceGraph.h +++ b/lib/CodeGen/RegAlloc/InterferenceGraph.h @@ -1,4 +1,4 @@ -/* Title: InterferenceGraph.h +/* Title: InterferenceGraph.h -*- C++ -*- Author: Ruchira Sasanka Date: July 20, 01 Purpose: Interference Graph used for register coloring. @@ -24,7 +24,7 @@ #include "llvm/CodeGen/IGNode.h" -typedef vector <IGNode *> IGNodeListType; +typedef std::vector <IGNode *> IGNodeListType; class InterferenceGraph @@ -47,6 +47,8 @@ class InterferenceGraph // to create it after adding all IGNodes to the IGNodeList InterferenceGraph(RegClass *const RC); + ~InterferenceGraph(); + void createGraph(); void addLRToIG(LiveRange *const LR); @@ -65,12 +67,6 @@ class InterferenceGraph void printIG() const; void printIGNodeList() const; - - ~InterferenceGraph(); - - }; - #endif - diff --git a/lib/CodeGen/RegAlloc/LiveRange.h b/lib/CodeGen/RegAlloc/LiveRange.h index 778e070046..8034751da9 100644 --- a/lib/CodeGen/RegAlloc/LiveRange.h +++ b/lib/CodeGen/RegAlloc/LiveRange.h @@ -1,4 +1,4 @@ -/* Title: LiveRange.h +/* Title: LiveRange.h -*- C++ -*- Author: Ruchira Sasanka Date: July 25, 01 Purpose: To keep info about a live range. @@ -13,6 +13,7 @@ #include "llvm/Analysis/LiveVar/ValueSet.h" #include "llvm/Type.h" +#include <iostream> class RegClass; class IGNode; @@ -176,7 +177,7 @@ class LiveRange : public ValueSet if(SuggestedColor == -1 ) SuggestedColor = Col; else if (DEBUG_RA) - cerr << "Already has a suggested color " << Col << endl; + std::cerr << "Already has a suggested color " << Col << "\n"; } inline unsigned getSuggestedColor() const { diff --git a/lib/CodeGen/RegAlloc/LiveRangeInfo.cpp b/lib/CodeGen/RegAlloc/LiveRangeInfo.cpp index 7fb688f55e..b66e6ef308 100644 --- a/lib/CodeGen/RegAlloc/LiveRangeInfo.cpp +++ b/lib/CodeGen/RegAlloc/LiveRangeInfo.cpp @@ -1,15 +1,15 @@ #include "llvm/CodeGen/LiveRangeInfo.h" +#include <iostream> +using std::cerr; //--------------------------------------------------------------------------- // Constructor //--------------------------------------------------------------------------- LiveRangeInfo::LiveRangeInfo(const Method *const M, const TargetMachine& tm, - vector<RegClass *> &RCL) - : Meth(M), LiveRangeMap(), - TM(tm), RegClassList(RCL), - MRI( tm.getRegInfo()), - CallRetInstrList() + std::vector<RegClass *> &RCL) + : Meth(M), LiveRangeMap(), TM(tm), + RegClassList(RCL), MRI(tm.getRegInfo()) { } @@ -17,33 +17,25 @@ LiveRangeInfo::LiveRangeInfo(const Method *const M, // Destructor: Deletes all LiveRanges in the LiveRangeMap //--------------------------------------------------------------------------- LiveRangeInfo::~LiveRangeInfo() { - LiveRangeMapType::iterator MI = LiveRangeMap.begin(); for( ; MI != LiveRangeMap.end() ; ++MI) { - if( (*MI).first ) { - - LiveRange *LR = (*MI).second; - - if( LR ) { - - // we need to be careful in deleting LiveRanges in LiveRangeMap - // since two/more Values in the live range map can point to the same - // live range. We have to make the other entries NULL when we delete - // a live range. - - LiveRange::iterator LI = LR->begin(); - - for( ; LI != LR->end() ; ++LI) { - LiveRangeMap[*LI] = NULL; - } + if (MI->first && MI->second) { + LiveRange *LR = MI->second; - delete LR; + // we need to be careful in deleting LiveRanges in LiveRangeMap + // since two/more Values in the live range map can point to the same + // live range. We have to make the other entries NULL when we delete + // a live range. - } + LiveRange::iterator LI = LR->begin(); + + for( ; LI != LR->end() ; ++LI) + LiveRangeMap[*LI] = 0; + + delete LR; } } - } @@ -82,7 +74,7 @@ void LiveRangeInfo::unionAndUpdateLRs(LiveRange *const L1, LiveRange *L2) L1->addSpillCost( L2->getSpillCost() ); // add the spill costs - delete ( L2 ); // delete L2 as it is no longer needed + delete L2; // delete L2 as it is no longer needed } @@ -96,7 +88,7 @@ void LiveRangeInfo::constructLiveRanges() { if( DEBUG_RA) - cout << "Consturcting Live Ranges ..." << endl; + cerr << "Consturcting Live Ranges ...\n"; // first find the live ranges for all incoming args of the method since // those LRs start from the start of the method @@ -108,14 +100,13 @@ void LiveRangeInfo::constructLiveRanges() for( ; ArgIt != ArgList.end() ; ++ArgIt) { // for each argument - LiveRange * ArgRange = new LiveRange(); // creates a new LR and const Value *const Val = (const Value *) *ArgIt; assert( Val); - ArgRange->add( Val ); // add the arg (def) to it - LiveRangeMap[ Val ] = ArgRange; + ArgRange->add(Val); // add the arg (def) to it + LiveRangeMap[Val] = ArgRange; // create a temp machine op to find the register class of value //const MachineOperand Op(MachineOperand::MO_VirtualRegister); @@ -125,8 +116,8 @@ void LiveRangeInfo::constructLiveRanges() if( DEBUG_RA > 1) { - cout << " adding LiveRange for argument "; - printValue( (const Value *) *ArgIt); cout << endl; + cerr << " adding LiveRange for argument "; + printValue((const Value *) *ArgIt); cerr << "\n"; } } @@ -140,7 +131,6 @@ void LiveRangeInfo::constructLiveRanges() Method::const_iterator BBI = Meth->begin(); // random iterator for BBs - for( ; BBI != Meth->end(); ++BBI) { // go thru BBs in random order // Now find all LRs for machine the instructions. A new LR will be created @@ -150,8 +140,7 @@ void LiveRangeInfo::constructLiveRanges() // get the iterator for machine instructions const MachineCodeForBasicBlock& MIVec = (*BBI)->getMachineInstrVec(); - MachineCodeForBasicBlock::const_iterator - MInstIterator = MIVec.begin(); + MachineCodeForBasicBlock::const_iterator MInstIterator = MIVec.begin(); // iterate over all the machine instructions in BB for( ; MInstIterator != MIVec.end(); MInstIterator++) { @@ -161,53 +150,46 @@ void LiveRangeInfo::constructLiveRanges() // Now if the machine instruction is a call/return instruction, // add it to CallRetInstrList for processing its implicit operands - if( (TM.getInstrInfo()).isReturn( MInst->getOpCode()) || - (TM.getInstrInfo()).isCall( MInst->getOpCode()) ) + if(TM.getInstrInfo().isReturn(MInst->getOpCode()) || + TM.getInstrInfo().isCall(MInst->getOpCode())) CallRetInstrList.push_back( MInst ); // iterate over MI operands to find defs - for( MachineInstr::val_const_op_iterator OpI(MInst);!OpI.done(); ++OpI) { - - if( DEBUG_RA) { + for (MachineInstr::val_const_op_iterator OpI(MInst); !OpI.done(); ++OpI) { + if(DEBUG_RA) { MachineOperand::MachineOperandType OpTyp = OpI.getMachineOperand().getOperandType(); - if ( OpTyp == MachineOperand::MO_CCRegister) { - cout << "\n**CC reg found. Is Def=" << OpI.isDef() << " Val:"; + if (OpTyp == MachineOperand::MO_CCRegister) { + cerr << "\n**CC reg found. Is Def=" << OpI.isDef() << " Val:"; printValue( OpI.getMachineOperand().getVRegValue() ); - cout << endl; + cerr << "\n"; } } // create a new LR iff this operand is a def if( OpI.isDef() ) { - const Value *const Def = *OpI; - // Only instruction values are accepted for live ranges here - if( Def->getValueType() != Value::InstructionVal ) { - cout << "\n**%%Error: Def is not an instruction val. Def="; - printValue( Def ); cout << endl; + cerr << "\n**%%Error: Def is not an instruction val. Def="; + printValue( Def ); cerr << "\n"; continue; } - LiveRange *DefRange = LiveRangeMap[Def]; // see LR already there (because of multiple defs) - if( !DefRange) { // if it is not in LiveRangeMap - DefRange = new LiveRange(); // creates a new live range and DefRange->add( Def ); // add the instruction (def) to it LiveRangeMap[ Def ] = DefRange; // update the map if( DEBUG_RA > 1) { - cout << " creating a LR for def: "; - printValue(Def); cout << endl; + cerr << " creating a LR for def: "; + printValue(Def); cerr << "\n"; } // set the register class of the new live range @@ -221,7 +203,7 @@ void LiveRangeInfo::constructLiveRanges() if(isCC && DEBUG_RA) { - cout << "\a**created a LR for a CC reg:"; + cerr << "\a**created a LR for a CC reg:"; printValue( OpI.getMachineOperand().getVRegValue() ); } @@ -235,8 +217,8 @@ void LiveRangeInfo::constructLiveRanges() LiveRangeMap[ Def ] = DefRange; if( DEBUG_RA > 1) { - cout << " added to an existing LR for def: "; - printValue( Def ); cout << endl; + cerr << " added to an existing LR for def: "; + printValue( Def ); cerr << "\n"; } } @@ -256,7 +238,7 @@ void LiveRangeInfo::constructLiveRanges() suggestRegs4CallRets(); if( DEBUG_RA) - cout << "Initial Live Ranges constructed!" << endl; + cerr << "Initial Live Ranges constructed!\n"; } @@ -312,11 +294,8 @@ void LiveRangeInfo::suggestRegs4CallRets() //--------------------------------------------------------------------------- void LiveRangeInfo::coalesceLRs() { - - - if( DEBUG_RA) - cout << endl << "Coalscing LRs ..." << endl; + cerr << "\nCoalscing LRs ...\n"; Method::const_iterator BBI = Meth->begin(); // random iterator for BBs @@ -324,8 +303,7 @@ void LiveRangeInfo::coalesceLRs() // get the iterator for machine instructions const MachineCodeForBasicBlock& MIVec = (*BBI)->getMachineInstrVec(); - MachineCodeForBasicBlock::const_iterator - MInstIterator = MIVec.begin(); + MachineCodeForBasicBlock::const_iterator MInstIterator = MIVec.begin(); // iterate over all the machine instructions in BB for( ; MInstIterator != MIVec.end(); ++MInstIterator) { @@ -333,9 +311,9 @@ void LiveRangeInfo::coalesceLRs() const MachineInstr * MInst = *MInstIterator; if( DEBUG_RA > 1) { - cout << " *Iterating over machine instr "; + cerr << " *Iterating over machine instr "; MInst->dump(); - cout << endl; + cerr << "\n"; } @@ -357,8 +335,8 @@ void LiveRangeInfo::coalesceLRs() //don't warn about labels if (!((*UseI)->getType())->isLabelType() && DEBUG_RA) { - cout<<" !! Warning: No LR for use "; printValue(*UseI); - cout << endl; + cerr<<" !! Warning: No LR for use "; printValue(*UseI); + cerr << "\n"; } continue; // ignore and continue } @@ -407,7 +385,7 @@ void LiveRangeInfo::coalesceLRs() } // for all BBs if( DEBUG_RA) - cout << endl << "Coalscing Done!" << endl; + cerr << "\nCoalscing Done!\n"; } @@ -421,11 +399,11 @@ void LiveRangeInfo::coalesceLRs() void LiveRangeInfo::printLiveRanges() { LiveRangeMapType::iterator HMI = LiveRangeMap.begin(); // hash map iterator - cout << endl << "Printing Live Ranges from Hash Map:" << endl; - for( ; HMI != LiveRangeMap.end() ; HMI ++ ) { - if( (*HMI).first && (*HMI).second ) { - cout <<" "; printValue((*HMI).first); cout << "\t: "; - ((*HMI).second)->printSet(); cout << endl; + cerr << "\nPrinting Live Ranges from Hash Map:\n"; + for( ; HMI != LiveRangeMap.end() ; ++HMI) { + if( HMI->first && HMI->second ) { + cerr <<" "; printValue((*HMI).first); cerr << "\t: "; + HMI->second->printSet(); cerr << "\n"; } } } diff --git a/lib/CodeGen/RegAlloc/LiveRangeInfo.h b/lib/CodeGen/RegAlloc/LiveRangeInfo.h index 1eee1aea5e..9e7ef06fe2 100644 --- a/lib/CodeGen/RegAlloc/LiveRangeInfo.h +++ b/lib/CodeGen/RegAlloc/LiveRangeInfo.h @@ -1,4 +1,4 @@ -/* Title: LiveRangeInfo.h +/* Title: LiveRangeInfo.h -*- C++ -*- Author: Ruchira Sasanka Date: Jun 30, 01 Purpose: @@ -34,8 +34,8 @@ #include "llvm/CodeGen/RegClass.h" -typedef hash_map <const Value *, LiveRange *, hashFuncValue> LiveRangeMapType; -typedef vector <const MachineInstr *> CallRetInstrListType; +typedef std::hash_map<const Value*, LiveRange*> LiveRangeMapType; +typedef std::vector<const MachineInstr*> CallRetInstrListType; @@ -59,7 +59,7 @@ private: const TargetMachine& TM; // target machine description - vector<RegClass *> & RegClassList;// a vector containing register classess + std::vector<RegClass *> & RegClassList;// vector containing register classess const MachineRegInfo& MRI; // machine reg info @@ -82,7 +82,7 @@ public: LiveRangeInfo(const Method *const M, const TargetMachine& tm, - vector<RegClass *> & RCList); + std::vector<RegClass *> & RCList); // Destructor to destroy all LiveRanges in the LiveRange Map diff --git a/lib/CodeGen/RegAlloc/PhyRegAlloc.cpp b/lib/CodeGen/RegAlloc/PhyRegAlloc.cpp index 7d6fbb7cc9..e2d455bad9 100644 --- a/lib/CodeGen/RegAlloc/PhyRegAlloc.cpp +++ b/lib/CodeGen/RegAlloc/PhyRegAlloc.cpp @@ -14,7 +14,9 @@ #include "llvm/CodeGen/MachineInstr.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Target/MachineFrameInfo.h" +#include <iostream> #include <math.h> +using std::cerr; // ***TODO: There are several places we add instructions. Validate the order @@ -35,18 +37,16 @@ cl::Enum<RegAllocDebugLevel_t> DEBUG_RA("dregalloc", cl::NoFlags, PhyRegAlloc::PhyRegAlloc(Method *M, const TargetMachine& tm, MethodLiveVarInfo *const Lvi) - : RegClassList(), - TM(tm), - Meth(M), + : TM(tm), Meth(M), mcInfo(MachineCodeForMethod::get(M)), LVI(Lvi), LRI(M, tm, RegClassList), MRI( tm.getRegInfo() ), NumOfRegClasses(MRI.getNumOfRegClasses()), - AddedInstrMap(), LoopDepthCalc(M), ResColList() { + LoopDepthCalc(M) { // create each RegisterClass and put in RegClassList // - for( unsigned int rc=0; rc < NumOfRegClasses; rc++) + for(unsigned int rc=0; rc < NumOfRegClasses; rc++) RegClassList.push_back( new RegClass(M, MRI.getMachineRegClass(rc), &ResColList) ); } @@ -69,7 +69,7 @@ PhyRegAlloc::~PhyRegAlloc() { //---------------------------------------------------------------------------- void PhyRegAlloc::createIGNodeListsAndIGs() { - if(DEBUG_RA ) cout << "Creating LR lists ..." << endl; + if(DEBUG_RA ) cerr << "Creating LR lists ...\n"; // hash map iterator LiveRangeMapType::const_iterator HMI = (LRI.getLiveRangeMap())->begin(); @@ -85,8 +85,8 @@ void PhyRegAlloc::createIGNodeListsAndIGs() if( !L) { if( DEBUG_RA) { - cout << "\n*?!?Warning: Null liver range found for: "; - printValue( (*HMI).first) ; cout << endl; + cerr << "\n*?!?Warning: Null liver range found for: "; + printValue(HMI->first); cerr << "\n"; } continue; } @@ -108,7 +108,7 @@ void PhyRegAlloc::createIGNodeListsAndIGs() RegClassList[ rc ]->createInterferenceGraph(); if( DEBUG_RA) - cout << "LRLists Created!" << endl; + cerr << "LRLists Created!\n"; } @@ -140,8 +140,8 @@ void PhyRegAlloc::addInterference(const Value *const Def, for( ; LIt != LVSet->end(); ++LIt) { if( DEBUG_RA > 1) { - cout << "< Def="; printValue(Def); - cout << ", Lvar="; printValue( *LIt); cout << "> "; + cerr << "< Def="; printValue(Def); + cerr << ", Lvar="; printValue( *LIt); cerr << "> "; } // get the live range corresponding to live var @@ -166,8 +166,8 @@ void PhyRegAlloc::addInterference(const Value *const Def, else if(DEBUG_RA > 1) { // we will not have LRs for values not explicitly allocated in the // instruction stream (e.g., constants) - cout << " warning: no live range for " ; - printValue( *LIt); cout << endl; } + cerr << " warning: no live range for " ; + printValue(*LIt); cerr << "\n"; } } @@ -203,7 +203,7 @@ void PhyRegAlloc::setCallInterferences(const MachineInstr *MInst, } if( DEBUG_RA) - cout << "\n For call inst: " << *MInst; + cerr << "\n For call inst: " << *MInst; LiveVarSet::const_iterator LIt = LVSetAft->begin(); @@ -216,7 +216,7 @@ void PhyRegAlloc::setCallInterferences(const MachineInstr *MInst, LiveRange *const LR = LRI.getLiveRangeForValue(*LIt ); if( LR && DEBUG_RA) { - cout << "\n\tLR Aft Call: "; + cerr << "\n\tLR Aft Call: "; LR->printSet(); } @@ -227,7 +227,7 @@ void PhyRegAlloc::setCallInterferences(const MachineInstr *MInst, if( LR && (LR != RetValLR) ) { LR->setCallInterference(); if( DEBUG_RA) { - cout << "\n ++Added call interf for LR: " ; + cerr << "\n ++Added call interf for LR: " ; LR->printSet(); } } @@ -247,7 +247,7 @@ void PhyRegAlloc::setCallInterferences(const MachineInstr *MInst, void PhyRegAlloc::buildInterferenceGraphs() { - if(DEBUG_RA) cout << "Creating interference graphs ..." << endl; + if(DEBUG_RA) cerr << "Creating interference graphs ...\n"; unsigned BBLoopDepthCost; Method::const_iterator BBI = Meth->begin(); // random iterator for BBs @@ -333,7 +333,7 @@ void PhyRegAlloc::buildInterferenceGraphs() addInterferencesForArgs(); if( DEBUG_RA) - cout << "Interference graphs calculted!" << endl; + cerr << "Interference graphs calculted!\n"; } @@ -411,8 +411,8 @@ void PhyRegAlloc::addInterferencesForArgs() addInterference( *ArgIt, InSet, false ); // add interferences between // args and LVars at start if( DEBUG_RA > 1) { - cout << " - %% adding interference for argument "; - printValue( (const Value *) *ArgIt); cout << endl; + cerr << " - %% adding interference for argument "; + printValue((const Value *)*ArgIt); cerr << "\n"; } } } @@ -510,7 +510,7 @@ void PhyRegAlloc::updateMachineCode() // delete this condition checking later (must assert if Val is null) if( !Val) { if (DEBUG_RA) - cout << "Warning: NULL Value found for operand" << endl; + cerr << "Warning: NULL Value found for operand\n"; continue; } assert( Val && "Value is NULL"); @@ -522,9 +522,9 @@ void PhyRegAlloc::updateMachineCode() // nothing to worry if it's a const or a label if (DEBUG_RA) { - cout << "*NO LR for operand : " << Op ; - cout << " [reg:" << Op.getAllocatedRegNum() << "]"; - cout << " in inst:\t" << *MInst << endl; + cerr << "*NO LR for operand : " << Op ; + cerr << " [reg:" << Op.getAllocatedRegNum() << "]"; + cerr << " in inst:\t" << *MInst << "\n"; } // if register is not allocated, mark register as invalid @@ -563,18 +563,16 @@ void PhyRegAlloc::updateMachineCode() // instruction, add them now. // if( AddedInstrMap[ MInst ] ) { - - deque<MachineInstr *> &IBef = (AddedInstrMap[MInst])->InstrnsBefore; + std::deque<MachineInstr *> &IBef = AddedInstrMap[MInst]->InstrnsBefore; if( ! IBef.empty() ) { - - deque<MachineInstr *>::iterator AdIt; + std::deque<MachineInstr *>::iterator AdIt; for( AdIt = IBef.begin(); AdIt != IBef.end() ; ++AdIt ) { if( DEBUG_RA) { cerr << "For inst " << *MInst; - cerr << " PREPENDed instr: " << **AdIt << endl; + cerr << " PREPENDed instr: " << **AdIt << "\n"; } MInstIterator = MIVec.insert( MInstIterator, *AdIt ); @@ -600,7 +598,7 @@ void PhyRegAlloc::updateMachineCode() if((delay=TM.getInstrInfo().getNumDelaySlots(MInst->getOpCode())) >0){ move2DelayedInstr(MInst, *(MInstIterator+delay) ); - if(DEBUG_RA) cout<< "\nMoved an added instr after the delay slot"; + if(DEBUG_RA) cerr<< "\nMoved an added instr after the delay slot"; } else { @@ -609,11 +607,11 @@ void PhyRegAlloc::updateMachineCode() // Here we can add the "instructions after" to the current // instruction since there are no delay slots for this instruction - deque<MachineInstr *> &IAft = (AddedInstrMap[MInst])->InstrnsAfter; + std::deque<MachineInstr *> &IAft = AddedInstrMap[MInst]->InstrnsAfter; if( ! IAft.empty() ) { - deque<MachineInstr *>::iterator AdIt; + std::deque<MachineInstr *>::iterator AdIt; ++MInstIterator; // advance to the next instruction @@ -621,7 +619,7 @@ void PhyRegAlloc::updateMachineCode() if(DEBUG_RA) { cerr << "For inst " << *MInst; - cerr << " APPENDed instr: " << **AdIt << endl; + cerr << " APPENDed instr: " << **AdIt << "\n"; } MInstIterator = MIVec.insert( MInstIterator, *AdIt ); @@ -669,9 +667,7 @@ void PhyRegAlloc::insertCode4SpilledLR(const LiveRange *LR, RegClass *RC = LR->getRegClass(); const LiveVarSet *LVSetBef = LVI->getLiveVarSetBeforeMInst(MInst, BB); - - int TmpOff = - mcInfo.pushTempValue(TM, MRI.getSpilledRegSize(RegType) ); + mcInfo.pushTempValue(TM, MRI.getSpilledRegSize(RegType) ); MachineInstr *MIBef=NULL, *AdIMid=NULL, *MIAft=NULL; @@ -854,13 +850,10 @@ int PhyRegAlloc::getUniRegNotUsedByThisInst(RegClass *RC, return MRI.getUnifiedRegNum(RC->getID(), c); else assert( 0 && "FATAL: No free register could be found in reg class!!"); - + return 0; } - - - //---------------------------------------------------------------------------- // This method modifies the IsColorUsedArr of the register class passed to it. // It sets the bits corresponding to the registers used by this machine @@ -909,14 +902,10 @@ void PhyRegAlloc::setRelRegsUsedByThisInst(RegClass *RC, LiveRange *const LRofImpRef = LRI.getLiveRangeForValue( MInst->getImplicitRef(z) ); - - if( LRofImpRef ) - if( LRofImpRef->hasColor() ) - IsColorUsedArr[ LRofImpRef-> |