From 748697d2421051b3ff1263d13cccaf410f3e7034 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 5 Feb 2002 04:20:12 +0000 Subject: [PATCH] Minor change: Methods that return ValueSet's that are guaranteed to be valid return references instead of pointers. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1719 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Analysis/LiveVar/FunctionLiveVarInfo.h | 8 ++--- include/llvm/CodeGen/FunctionLiveVarInfo.h | 8 ++--- lib/Analysis/LiveVar/BBLiveVar.cpp | 2 ++ lib/Analysis/LiveVar/BBLiveVar.h | 11 +++---- lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp | 20 ++++++------ lib/CodeGen/InstrSched/SchedPriorities.cpp | 12 +++---- lib/CodeGen/RegAlloc/IGNode.cpp | 25 ++++----------- lib/CodeGen/RegAlloc/IGNode.h | 18 +++++------ lib/CodeGen/RegAlloc/PhyRegAlloc.cpp | 18 +++++------ .../SparcV9/InstrSched/SchedPriorities.cpp | 12 +++---- lib/Target/SparcV9/LiveVar/BBLiveVar.cpp | 2 ++ lib/Target/SparcV9/LiveVar/BBLiveVar.h | 11 +++---- .../SparcV9/LiveVar/FunctionLiveVarInfo.cpp | 20 ++++++------ lib/Target/SparcV9/RegAlloc/IGNode.cpp | 25 ++++----------- lib/Target/SparcV9/RegAlloc/IGNode.h | 18 +++++------ lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp | 18 +++++------ lib/Target/SparcV9/SparcV9RegInfo.cpp | 32 +++++++++---------- 17 files changed, 114 insertions(+), 146 deletions(-) diff --git a/include/llvm/Analysis/LiveVar/FunctionLiveVarInfo.h b/include/llvm/Analysis/LiveVar/FunctionLiveVarInfo.h index 07cf225b2ca..d107350dab8 100644 --- a/include/llvm/Analysis/LiveVar/FunctionLiveVarInfo.h +++ b/include/llvm/Analysis/LiveVar/FunctionLiveVarInfo.h @@ -119,17 +119,17 @@ public: // --------- Functions to access analysis results ------------------- // gets OutSet of a BB - const ValueSet *getOutSetOfBB(const BasicBlock *BB) const; + const ValueSet &getOutSetOfBB(const BasicBlock *BB) const; // gets InSet of a BB - const ValueSet *getInSetOfBB(const BasicBlock *BB) const; + const ValueSet &getInSetOfBB(const BasicBlock *BB) const; // gets the Live var set BEFORE an instruction - const ValueSet *getLiveVarSetBeforeMInst(const MachineInstr *MI, + const ValueSet &getLiveVarSetBeforeMInst(const MachineInstr *MI, const BasicBlock *BB); // gets the Live var set AFTER an instruction - const ValueSet *getLiveVarSetAfterMInst(const MachineInstr *MI, + const ValueSet &getLiveVarSetAfterMInst(const MachineInstr *MI, const BasicBlock *BB); }; diff --git a/include/llvm/CodeGen/FunctionLiveVarInfo.h b/include/llvm/CodeGen/FunctionLiveVarInfo.h index 07cf225b2ca..d107350dab8 100644 --- a/include/llvm/CodeGen/FunctionLiveVarInfo.h +++ b/include/llvm/CodeGen/FunctionLiveVarInfo.h @@ -119,17 +119,17 @@ public: // --------- Functions to access analysis results ------------------- // gets OutSet of a BB - const ValueSet *getOutSetOfBB(const BasicBlock *BB) const; + const ValueSet &getOutSetOfBB(const BasicBlock *BB) const; // gets InSet of a BB - const ValueSet *getInSetOfBB(const BasicBlock *BB) const; + const ValueSet &getInSetOfBB(const BasicBlock *BB) const; // gets the Live var set BEFORE an instruction - const ValueSet *getLiveVarSetBeforeMInst(const MachineInstr *MI, + const ValueSet &getLiveVarSetBeforeMInst(const MachineInstr *MI, const BasicBlock *BB); // gets the Live var set AFTER an instruction - const ValueSet *getLiveVarSetAfterMInst(const MachineInstr *MI, + const ValueSet &getLiveVarSetAfterMInst(const MachineInstr *MI, const BasicBlock *BB); }; diff --git a/lib/Analysis/LiveVar/BBLiveVar.cpp b/lib/Analysis/LiveVar/BBLiveVar.cpp index dc0cbc14600..35548f6b2e7 100644 --- a/lib/Analysis/LiveVar/BBLiveVar.cpp +++ b/lib/Analysis/LiveVar/BBLiveVar.cpp @@ -18,6 +18,8 @@ using std::cerr; BBLiveVar::BBLiveVar(const BasicBlock *bb, unsigned id) : BB(bb), POID(id) { InSetChanged = OutSetChanged = false; + + calcDefUseSets(); } //----------------------------------------------------------------------------- diff --git a/lib/Analysis/LiveVar/BBLiveVar.h b/lib/Analysis/LiveVar/BBLiveVar.h index 1fc91f13300..442eb22c731 100644 --- a/lib/Analysis/LiveVar/BBLiveVar.h +++ b/lib/Analysis/LiveVar/BBLiveVar.h @@ -31,11 +31,12 @@ class BBLiveVar { const BasicBlock *PredBB); // To add an operand which is a def - void addDef(const Value *Op); + void addDef(const Value *Op); // To add an operand which is a use - void addUse(const Value *Op); + void addUse(const Value *Op); + void calcDefUseSets(); // calculates the Def & Use sets for this BB public: BBLiveVar(const BasicBlock *BB, unsigned POID); @@ -44,18 +45,16 @@ class BBLiveVar { inline unsigned getPOId() const { return POID; } - void calcDefUseSets(); // calculates the Def & Use sets for this BB bool applyTransferFunc(); // calcultes the In in terms of Out // calculates Out set using In sets of the predecessors bool applyFlowFunc(std::map &LVMap); - inline const ValueSet *getOutSet() const { return &OutSet; } - inline const ValueSet *getInSet() const { return &InSet; } + inline const ValueSet &getOutSet() const { return OutSet; } + inline const ValueSet &getInSet() const { return InSet; } void printAllSets() const; // for printing Def/In/Out sets void printInOutSets() const; // for printing In/Out sets }; #endif - diff --git a/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp b/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp index a4dbef1cf07..5205a19182d 100644 --- a/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp +++ b/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp @@ -20,12 +20,12 @@ AnalysisID MethodLiveVarInfo::ID(AnalysisID::create()); //----------------------------------------------------------------------------- // gets OutSet of a BB -const ValueSet *MethodLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) const { +const ValueSet &MethodLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) const { return BB2BBLVMap.find(BB)->second->getOutSet(); } // gets InSet of a BB -const ValueSet *MethodLiveVarInfo::getInSetOfBB(const BasicBlock *BB) const { +const ValueSet &MethodLiveVarInfo::getInSetOfBB(const BasicBlock *BB) const { return BB2BBLVMap.find(BB)->second->getInSet(); } @@ -65,8 +65,6 @@ void MethodLiveVarInfo::constructBBs(const Method *M) { BBLiveVar *LVBB = new BBLiveVar(BB, POId); BB2BBLVMap[BB] = LVBB; // insert the pair to Map - LVBB->calcDefUseSets(); // calculates the def and in set - if (DEBUG_LV) LVBB->printAllSets(); } @@ -155,14 +153,14 @@ void MethodLiveVarInfo::releaseMemory() { // Gives live variable information before a machine instruction //----------------------------------------------------------------------------- -const ValueSet * +const ValueSet & MethodLiveVarInfo::getLiveVarSetBeforeMInst(const MachineInstr *MInst, const BasicBlock *BB) { if (const ValueSet *LVSet = MInst2LVSetBI[MInst]) { - return LVSet; // if found, just return the set + return *LVSet; // if found, just return the set } else { calcLiveVarSetsForBB(BB); // else, calc for all instrs in BB - return MInst2LVSetBI[MInst]; + return *MInst2LVSetBI[MInst]; } } @@ -170,15 +168,15 @@ MethodLiveVarInfo::getLiveVarSetBeforeMInst(const MachineInstr *MInst, //----------------------------------------------------------------------------- // Gives live variable information after a machine instruction //----------------------------------------------------------------------------- -const ValueSet * +const ValueSet & MethodLiveVarInfo::getLiveVarSetAfterMInst(const MachineInstr *MI, const BasicBlock *BB) { if (const ValueSet *LVSet = MInst2LVSetAI[MI]) { - return LVSet; // if found, just return the set + return *LVSet; // if found, just return the set } else { calcLiveVarSetsForBB(BB); // else, calc for all instrs in BB - return MInst2LVSetAI[MI]; + return *MInst2LVSetAI[MI]; } } @@ -224,7 +222,7 @@ void MethodLiveVarInfo::calcLiveVarSetsForBB(const BasicBlock *BB) { const MachineCodeForBasicBlock &MIVec = BB->getMachineInstrVec(); ValueSet *CurSet = new ValueSet(); - const ValueSet *SetAI = getOutSetOfBB(BB); // init SetAI with OutSet + const ValueSet *SetAI = &getOutSetOfBB(BB); // init SetAI with OutSet set_union(*CurSet, *SetAI); // CurSet now contains OutSet // iterate over all the machine instructions in BB diff --git a/lib/CodeGen/InstrSched/SchedPriorities.cpp b/lib/CodeGen/InstrSched/SchedPriorities.cpp index 74f659993e2..fed3f941fef 100644 --- a/lib/CodeGen/InstrSched/SchedPriorities.cpp +++ b/lib/CodeGen/InstrSched/SchedPriorities.cpp @@ -276,16 +276,14 @@ SchedPriorities::instructionHasLastUse(MethodLiveVarInfo& methodLiveVarInfo, // else check if instruction is a last use and save it in the hash_map bool hasLastUse = false; const BasicBlock* bb = graphNode->getBB(); - const ValueSet *liveVars = - methodLiveVarInfo.getLiveVarSetBeforeMInst(minstr, bb); + const ValueSet &LVs = methodLiveVarInfo.getLiveVarSetBeforeMInst(minstr, bb); - for (MachineInstr::val_const_op_iterator vo(minstr); ! vo.done(); ++vo) - if (liveVars->find(*vo) == liveVars->end()) { + for (MachineInstr::val_const_op_iterator vo(minstr); !vo.done(); ++vo) + if (!LVs.count(*vo)) { hasLastUse = true; break; } - - lastUseMap[minstr] = hasLastUse; - return hasLastUse; + + return lastUseMap[minstr] = hasLastUse; } diff --git a/lib/CodeGen/RegAlloc/IGNode.cpp b/lib/CodeGen/RegAlloc/IGNode.cpp index a2257420529..795e8b71524 100644 --- a/lib/CodeGen/RegAlloc/IGNode.cpp +++ b/lib/CodeGen/RegAlloc/IGNode.cpp @@ -3,27 +3,15 @@ #include using std::cerr; -//----------------------------------------------------------------------------- -// Constructor -//----------------------------------------------------------------------------- -IGNode::IGNode(LiveRange *const PLR, unsigned int Ind) : Index(Ind), - ParentLR(PLR) -{ - OnStack = false; - CurDegree = -1 ; - ParentLR->setUserIGNode( this ); -} - - //----------------------------------------------------------------------------- // Sets this IGNode on stack and reduce the degree of neighbors //----------------------------------------------------------------------------- -void IGNode::pushOnStack() -{ + +void IGNode::pushOnStack() { OnStack = true; int neighs = AdjList.size(); - if( neighs < 0) { + if (neighs < 0) { cerr << "\nAdj List size = " << neighs; assert(0 && "Invalid adj list size"); } @@ -36,10 +24,9 @@ void IGNode::pushOnStack() // Deletes an adjacency node. IGNodes are deleted when coalescing merges // two IGNodes together. //----------------------------------------------------------------------------- -void IGNode::delAdjIGNode(const IGNode *const Node) { - std::vector::iterator It = - find(AdjList.begin(), AdjList.end(), Node); + +void IGNode::delAdjIGNode(const IGNode *Node) { + std::vector::iterator It=find(AdjList.begin(), AdjList.end(), Node); assert( It != AdjList.end() ); // the node must be there - AdjList.erase(It); } diff --git a/lib/CodeGen/RegAlloc/IGNode.h b/lib/CodeGen/RegAlloc/IGNode.h index bdaedf8c134..177800c5bb9 100644 --- a/lib/CodeGen/RegAlloc/IGNode.h +++ b/lib/CodeGen/RegAlloc/IGNode.h @@ -37,11 +37,9 @@ class RegClass; //---------------------------------------------------------------------------- class IGNode { - const int Index; // index within IGNodeList - - bool OnStack; // this has been pushed on to stack for coloring - - std::vector AdjList; // adjacency list for this live range + const unsigned Index; // index within IGNodeList + bool OnStack; // this has been pushed on to stack for coloring + std::vector AdjList;// adjacency list for this live range int CurDegree; // @@ -50,12 +48,14 @@ 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) + LiveRange *const ParentLR; public: - // constructor - // - IGNode(LiveRange *LR, unsigned index); + IGNode(LiveRange *LR, unsigned index) : Index(index), ParentLR(LR) { + OnStack = false; + CurDegree = -1; + ParentLR->setUserIGNode(this); + } inline unsigned int getIndex() const { return Index; } diff --git a/lib/CodeGen/RegAlloc/PhyRegAlloc.cpp b/lib/CodeGen/RegAlloc/PhyRegAlloc.cpp index 01e4879cf87..b296cae139f 100644 --- a/lib/CodeGen/RegAlloc/PhyRegAlloc.cpp +++ b/lib/CodeGen/RegAlloc/PhyRegAlloc.cpp @@ -290,11 +290,11 @@ void PhyRegAlloc::buildInterferenceGraphs() // for( ; MInstIterator != MIVec.end(); ++MInstIterator) { - const MachineInstr * MInst = *MInstIterator; + const MachineInstr *MInst = *MInstIterator; // get the LV set after the instruction // - const ValueSet *LVSetAI = LVI->getLiveVarSetAfterMInst(MInst, *BBI); + const ValueSet &LVSetAI = LVI->getLiveVarSetAfterMInst(MInst, *BBI); const bool isCallInst = TM.getInstrInfo().isCall(MInst->getOpCode()); @@ -304,7 +304,7 @@ void PhyRegAlloc::buildInterferenceGraphs() // coloring algo to avoid allocating volatile colors to live ranges // that span across calls (since they have to be saved/restored) // - setCallInterferences( MInst, LVSetAI); + setCallInterferences(MInst, &LVSetAI); } @@ -315,7 +315,7 @@ void PhyRegAlloc::buildInterferenceGraphs() if( OpI.isDef() ) { // create a new LR iff this operand is a def // - addInterference(*OpI, LVSetAI, isCallInst ); + addInterference(*OpI, &LVSetAI, isCallInst); } // Calculate the spill cost of each live range @@ -339,7 +339,7 @@ void PhyRegAlloc::buildInterferenceGraphs() if( NumOfImpRefs > 0 ) { for(unsigned z=0; z < NumOfImpRefs; z++) if( MInst->implicitRefIsDefined(z) ) - addInterference( MInst->getImplicitRef(z), LVSetAI, isCallInst ); + addInterference( MInst->getImplicitRef(z), &LVSetAI, isCallInst ); } @@ -418,7 +418,7 @@ void PhyRegAlloc::addInterf4PseudoInstr(const MachineInstr *MInst) { //---------------------------------------------------------------------------- void PhyRegAlloc::addInterferencesForArgs() { // get the InSet of root BB - const ValueSet *InSet = LVI->getInSetOfBB(Meth->front()); + const ValueSet &InSet = LVI->getInSetOfBB(Meth->front()); // get the argument list const Method::ArgumentListType& ArgList = Meth->getArgumentList(); @@ -428,7 +428,7 @@ void PhyRegAlloc::addInterferencesForArgs() { for( ; ArgIt != ArgList.end() ; ++ArgIt) { // for each argument - addInterference((Value*)*ArgIt, InSet, false); // add interferences between + addInterference((Value*)*ArgIt, &InSet, false);// add interferences between // args and LVars at start if( DEBUG_RA > 1) cerr << " - %% adding interference for argument " @@ -682,13 +682,13 @@ void PhyRegAlloc::insertCode4SpilledLR(const LiveRange *LR, unsigned RegType = MRI.getRegType( LR ); int SpillOff = LR->getSpillOffFromFP(); RegClass *RC = LR->getRegClass(); - const ValueSet *LVSetBef = LVI->getLiveVarSetBeforeMInst(MInst, BB); + const ValueSet &LVSetBef = LVI->getLiveVarSetBeforeMInst(MInst, BB); mcInfo.pushTempValue(TM, MRI.getSpilledRegSize(RegType) ); MachineInstr *MIBef=NULL, *AdIMid=NULL, *MIAft=NULL; - int TmpRegU = getUsableUniRegAtMI(RC, RegType, MInst,LVSetBef, MIBef, MIAft); + int TmpRegU = getUsableUniRegAtMI(RC, RegType, MInst,&LVSetBef, MIBef, MIAft); // get the added instructions for this instruciton AddedInstrns *AI = AddedInstrMap[ MInst ]; diff --git a/lib/Target/SparcV9/InstrSched/SchedPriorities.cpp b/lib/Target/SparcV9/InstrSched/SchedPriorities.cpp index 74f659993e2..fed3f941fef 100644 --- a/lib/Target/SparcV9/InstrSched/SchedPriorities.cpp +++ b/lib/Target/SparcV9/InstrSched/SchedPriorities.cpp @@ -276,16 +276,14 @@ SchedPriorities::instructionHasLastUse(MethodLiveVarInfo& methodLiveVarInfo, // else check if instruction is a last use and save it in the hash_map bool hasLastUse = false; const BasicBlock* bb = graphNode->getBB(); - const ValueSet *liveVars = - methodLiveVarInfo.getLiveVarSetBeforeMInst(minstr, bb); + const ValueSet &LVs = methodLiveVarInfo.getLiveVarSetBeforeMInst(minstr, bb); - for (MachineInstr::val_const_op_iterator vo(minstr); ! vo.done(); ++vo) - if (liveVars->find(*vo) == liveVars->end()) { + for (MachineInstr::val_const_op_iterator vo(minstr); !vo.done(); ++vo) + if (!LVs.count(*vo)) { hasLastUse = true; break; } - - lastUseMap[minstr] = hasLastUse; - return hasLastUse; + + return lastUseMap[minstr] = hasLastUse; } diff --git a/lib/Target/SparcV9/LiveVar/BBLiveVar.cpp b/lib/Target/SparcV9/LiveVar/BBLiveVar.cpp index dc0cbc14600..35548f6b2e7 100644 --- a/lib/Target/SparcV9/LiveVar/BBLiveVar.cpp +++ b/lib/Target/SparcV9/LiveVar/BBLiveVar.cpp @@ -18,6 +18,8 @@ using std::cerr; BBLiveVar::BBLiveVar(const BasicBlock *bb, unsigned id) : BB(bb), POID(id) { InSetChanged = OutSetChanged = false; + + calcDefUseSets(); } //----------------------------------------------------------------------------- diff --git a/lib/Target/SparcV9/LiveVar/BBLiveVar.h b/lib/Target/SparcV9/LiveVar/BBLiveVar.h index 1fc91f13300..442eb22c731 100644 --- a/lib/Target/SparcV9/LiveVar/BBLiveVar.h +++ b/lib/Target/SparcV9/LiveVar/BBLiveVar.h @@ -31,11 +31,12 @@ class BBLiveVar { const BasicBlock *PredBB); // To add an operand which is a def - void addDef(const Value *Op); + void addDef(const Value *Op); // To add an operand which is a use - void addUse(const Value *Op); + void addUse(const Value *Op); + void calcDefUseSets(); // calculates the Def & Use sets for this BB public: BBLiveVar(const BasicBlock *BB, unsigned POID); @@ -44,18 +45,16 @@ class BBLiveVar { inline unsigned getPOId() const { return POID; } - void calcDefUseSets(); // calculates the Def & Use sets for this BB bool applyTransferFunc(); // calcultes the In in terms of Out // calculates Out set using In sets of the predecessors bool applyFlowFunc(std::map &LVMap); - inline const ValueSet *getOutSet() const { return &OutSet; } - inline const ValueSet *getInSet() const { return &InSet; } + inline const ValueSet &getOutSet() const { return OutSet; } + inline const ValueSet &getInSet() const { return InSet; } void printAllSets() const; // for printing Def/In/Out sets void printInOutSets() const; // for printing In/Out sets }; #endif - diff --git a/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp b/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp index a4dbef1cf07..5205a19182d 100644 --- a/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp +++ b/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp @@ -20,12 +20,12 @@ AnalysisID MethodLiveVarInfo::ID(AnalysisID::create()); //----------------------------------------------------------------------------- // gets OutSet of a BB -const ValueSet *MethodLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) const { +const ValueSet &MethodLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) const { return BB2BBLVMap.find(BB)->second->getOutSet(); } // gets InSet of a BB -const ValueSet *MethodLiveVarInfo::getInSetOfBB(const BasicBlock *BB) const { +const ValueSet &MethodLiveVarInfo::getInSetOfBB(const BasicBlock *BB) const { return BB2BBLVMap.find(BB)->second->getInSet(); } @@ -65,8 +65,6 @@ void MethodLiveVarInfo::constructBBs(const Method *M) { BBLiveVar *LVBB = new BBLiveVar(BB, POId); BB2BBLVMap[BB] = LVBB; // insert the pair to Map - LVBB->calcDefUseSets(); // calculates the def and in set - if (DEBUG_LV) LVBB->printAllSets(); } @@ -155,14 +153,14 @@ void MethodLiveVarInfo::releaseMemory() { // Gives live variable information before a machine instruction //----------------------------------------------------------------------------- -const ValueSet * +const ValueSet & MethodLiveVarInfo::getLiveVarSetBeforeMInst(const MachineInstr *MInst, const BasicBlock *BB) { if (const ValueSet *LVSet = MInst2LVSetBI[MInst]) { - return LVSet; // if found, just return the set + return *LVSet; // if found, just return the set } else { calcLiveVarSetsForBB(BB); // else, calc for all instrs in BB - return MInst2LVSetBI[MInst]; + return *MInst2LVSetBI[MInst]; } } @@ -170,15 +168,15 @@ MethodLiveVarInfo::getLiveVarSetBeforeMInst(const MachineInstr *MInst, //----------------------------------------------------------------------------- // Gives live variable information after a machine instruction //----------------------------------------------------------------------------- -const ValueSet * +const ValueSet & MethodLiveVarInfo::getLiveVarSetAfterMInst(const MachineInstr *MI, const BasicBlock *BB) { if (const ValueSet *LVSet = MInst2LVSetAI[MI]) { - return LVSet; // if found, just return the set + return *LVSet; // if found, just return the set } else { calcLiveVarSetsForBB(BB); // else, calc for all instrs in BB - return MInst2LVSetAI[MI]; + return *MInst2LVSetAI[MI]; } } @@ -224,7 +222,7 @@ void MethodLiveVarInfo::calcLiveVarSetsForBB(const BasicBlock *BB) { const MachineCodeForBasicBlock &MIVec = BB->getMachineInstrVec(); ValueSet *CurSet = new ValueSet(); - const ValueSet *SetAI = getOutSetOfBB(BB); // init SetAI with OutSet + const ValueSet *SetAI = &getOutSetOfBB(BB); // init SetAI with OutSet set_union(*CurSet, *SetAI); // CurSet now contains OutSet // iterate over all the machine instructions in BB diff --git a/lib/Target/SparcV9/RegAlloc/IGNode.cpp b/lib/Target/SparcV9/RegAlloc/IGNode.cpp index a2257420529..795e8b71524 100644 --- a/lib/Target/SparcV9/RegAlloc/IGNode.cpp +++ b/lib/Target/SparcV9/RegAlloc/IGNode.cpp @@ -3,27 +3,15 @@ #include using std::cerr; -//----------------------------------------------------------------------------- -// Constructor -//----------------------------------------------------------------------------- -IGNode::IGNode(LiveRange *const PLR, unsigned int Ind) : Index(Ind), - ParentLR(PLR) -{ - OnStack = false; - CurDegree = -1 ; - ParentLR->setUserIGNode( this ); -} - - //----------------------------------------------------------------------------- // Sets this IGNode on stack and reduce the degree of neighbors //----------------------------------------------------------------------------- -void IGNode::pushOnStack() -{ + +void IGNode::pushOnStack() { OnStack = true; int neighs = AdjList.size(); - if( neighs < 0) { + if (neighs < 0) { cerr << "\nAdj List size = " << neighs; assert(0 && "Invalid adj list size"); } @@ -36,10 +24,9 @@ void IGNode::pushOnStack() // Deletes an adjacency node. IGNodes are deleted when coalescing merges // two IGNodes together. //----------------------------------------------------------------------------- -void IGNode::delAdjIGNode(const IGNode *const Node) { - std::vector::iterator It = - find(AdjList.begin(), AdjList.end(), Node); + +void IGNode::delAdjIGNode(const IGNode *Node) { + std::vector::iterator It=find(AdjList.begin(), AdjList.end(), Node); assert( It != AdjList.end() ); // the node must be there - AdjList.erase(It); } diff --git a/lib/Target/SparcV9/RegAlloc/IGNode.h b/lib/Target/SparcV9/RegAlloc/IGNode.h index bdaedf8c134..177800c5bb9 100644 --- a/lib/Target/SparcV9/RegAlloc/IGNode.h +++ b/lib/Target/SparcV9/RegAlloc/IGNode.h @@ -37,11 +37,9 @@ class RegClass; //---------------------------------------------------------------------------- class IGNode { - const int Index; // index within IGNodeList - - bool OnStack; // this has been pushed on to stack for coloring - - std::vector AdjList; // adjacency list for this live range + const unsigned Index; // index within IGNodeList + bool OnStack; // this has been pushed on to stack for coloring + std::vector AdjList;// adjacency list for this live range int CurDegree; // @@ -50,12 +48,14 @@ 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) + LiveRange *const ParentLR; public: - // constructor - // - IGNode(LiveRange *LR, unsigned index); + IGNode(LiveRange *LR, unsigned index) : Index(index), ParentLR(LR) { + OnStack = false; + CurDegree = -1; + ParentLR->setUserIGNode(this); + } inline unsigned int getIndex() const { return Index; } diff --git a/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp b/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp index 01e4879cf87..b296cae139f 100644 --- a/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp +++ b/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp @@ -290,11 +290,11 @@ void PhyRegAlloc::buildInterferenceGraphs() // for( ; MInstIterator != MIVec.end(); ++MInstIterator) { - const MachineInstr * MInst = *MInstIterator; + const MachineInstr *MInst = *MInstIterator; // get the LV set after the instruction // - const ValueSet *LVSetAI = LVI->getLiveVarSetAfterMInst(MInst, *BBI); + const ValueSet &LVSetAI = LVI->getLiveVarSetAfterMInst(MInst, *BBI); const bool isCallInst = TM.getInstrInfo().isCall(MInst->getOpCode()); @@ -304,7 +304,7 @@ void PhyRegAlloc::buildInterferenceGraphs() // coloring algo to avoid allocating volatile colors to live ranges // that span across calls (since they have to be saved/restored) // - setCallInterferences( MInst, LVSetAI); + setCallInterferences(MInst, &LVSetAI); } @@ -315,7 +315,7 @@ void PhyRegAlloc::buildInterferenceGraphs() if( OpI.isDef() ) { // create a new LR iff this operand is a def // - addInterference(*OpI, LVSetAI, isCallInst ); + addInterference(*OpI, &LVSetAI, isCallInst); } // Calculate the spill cost of each live range @@ -339,7 +339,7 @@ void PhyRegAlloc::buildInterferenceGraphs() if( NumOfImpRefs > 0 ) { for(unsigned z=0; z < NumOfImpRefs; z++) if( MInst->implicitRefIsDefined(z) ) - addInterference( MInst->getImplicitRef(z), LVSetAI, isCallInst ); + addInterference( MInst->getImplicitRef(z), &LVSetAI, isCallInst ); } @@ -418,7 +418,7 @@ void PhyRegAlloc::addInterf4PseudoInstr(const MachineInstr *MInst) { //---------------------------------------------------------------------------- void PhyRegAlloc::addInterferencesForArgs() { // get the InSet of root BB - const ValueSet *InSet = LVI->getInSetOfBB(Meth->front()); + const ValueSet &InSet = LVI->getInSetOfBB(Meth->front()); // get the argument list const Method::ArgumentListType& ArgList = Meth->getArgumentList(); @@ -428,7 +428,7 @@ void PhyRegAlloc::addInterferencesForArgs() { for( ; ArgIt != ArgList.end() ; ++ArgIt) { // for each argument - addInterference((Value*)*ArgIt, InSet, false); // add interferences between + addInterference((Value*)*ArgIt, &InSet, false);// add interferences between // args and LVars at start if( DEBUG_RA > 1) cerr << " - %% adding interference for argument " @@ -682,13 +682,13 @@ void PhyRegAlloc::insertCode4SpilledLR(const LiveRange *LR, unsigned RegType = MRI.getRegType( LR ); int SpillOff = LR->getSpillOffFromFP(); RegClass *RC = LR->getRegClass(); - const ValueSet *LVSetBef = LVI->getLiveVarSetBeforeMInst(MInst, BB); + const ValueSet &LVSetBef = LVI->getLiveVarSetBeforeMInst(MInst, BB); mcInfo.pushTempValue(TM, MRI.getSpilledRegSize(RegType) ); MachineInstr *MIBef=NULL, *AdIMid=NULL, *MIAft=NULL; - int TmpRegU = getUsableUniRegAtMI(RC, RegType, MInst,LVSetBef, MIBef, MIAft); + int TmpRegU = getUsableUniRegAtMI(RC, RegType, MInst,&LVSetBef, MIBef, MIAft); // get the added instructions for this instruciton AddedInstrns *AI = AddedInstrMap[ MInst ]; diff --git a/lib/Target/SparcV9/SparcV9RegInfo.cpp b/lib/Target/SparcV9/SparcV9RegInfo.cpp index 9af470aa012..f910c9b4415 100644 --- a/lib/Target/SparcV9/SparcV9RegInfo.cpp +++ b/lib/Target/SparcV9/SparcV9RegInfo.cpp @@ -1251,11 +1251,11 @@ void UltraSparcRegInfo::insertCallerSavingCode(const MachineInstr *MInst, } - const ValueSet *LVSetAft = PRA.LVI->getLiveVarSetAfterMInst(MInst, BB); - ValueSet::const_iterator LIt = LVSetAft->begin(); + const ValueSet &LVSetAft = PRA.LVI->getLiveVarSetAfterMInst(MInst, BB); + ValueSet::const_iterator LIt = LVSetAft.begin(); // for each live var in live variable set after machine inst - for( ; LIt != LVSetAft->end(); ++LIt) { + for( ; LIt != LVSetAft.end(); ++LIt) { // get the live range corresponding to live var LiveRange *const LR = PRA.LRI.getLiveRangeForValue(*LIt ); @@ -1302,25 +1302,25 @@ void UltraSparcRegInfo::insertCallerSavingCode(const MachineInstr *MInst, // Handle IntCCRegType specially since we cannot directly // push %ccr on to the stack - const ValueSet *LVSetBef = + const ValueSet &LVSetBef = PRA.LVI->getLiveVarSetBeforeMInst(MInst, BB); // get a free INTEGER register int FreeIntReg = PRA.getUsableUniRegAtMI(LR->getRegClass(), IntRegType, MInst, - LVSetBef, AdIBefCC, AdIAftCC); + &LVSetBef, AdIBefCC, AdIAftCC); // insert the instructions in reverse order since we are // adding them to the front of InstrnsBefore if(AdIAftCC) - (PRA.AddedInstrMap[MInst]->InstrnsBefore).push_front(AdIAftCC); + PRA.AddedInstrMap[MInst]->InstrnsBefore.push_front(AdIAftCC); AdICpCC = cpCCR2IntMI(FreeIntReg); - (PRA.AddedInstrMap[MInst]->InstrnsBefore).push_front(AdICpCC); + PRA.AddedInstrMap[MInst]->InstrnsBefore.push_front(AdICpCC); if(AdIBefCC) - (PRA.AddedInstrMap[MInst]->InstrnsBefore).push_front(AdIBefCC); + PRA.AddedInstrMap[MInst]->InstrnsBefore.push_front(AdIBefCC); if(DEBUG_RA) { cerr << "\n!! Inserted caller saving (push) inst for %ccr:"; @@ -1332,13 +1332,13 @@ void UltraSparcRegInfo::insertCallerSavingCode(const MachineInstr *MInst, } else { // for any other register type, just add the push inst AdIBef = cpReg2MemMI(Reg, getFramePointer(), StackOff, RegType ); - ((PRA.AddedInstrMap[MInst])->InstrnsBefore).push_front(AdIBef); + PRA.AddedInstrMap[MInst]->InstrnsBefore.push_front(AdIBef); } //---- Insert code for popping the reg from the stack ---------- - if( RegType == IntCCRegType ) { + if (RegType == IntCCRegType) { // Handle IntCCRegType specially since we cannot directly // pop %ccr on from the stack @@ -1346,16 +1346,16 @@ void UltraSparcRegInfo::insertCallerSavingCode(const MachineInstr *MInst, // get a free INT register int FreeIntReg = PRA.getUsableUniRegAtMI(LR->getRegClass(), IntRegType, MInst, - LVSetAft, AdIBefCC, AdIAftCC); + &LVSetAft, AdIBefCC, AdIAftCC); if(AdIBefCC) - (PRA.AddedInstrMap[MInst]->InstrnsAfter).push_back(AdIBefCC); + PRA.AddedInstrMap[MInst]->InstrnsAfter.push_back(AdIBefCC); AdICpCC = cpInt2CCRMI(FreeIntReg); - (PRA.AddedInstrMap[MInst]->InstrnsAfter).push_back(AdICpCC); + PRA.AddedInstrMap[MInst]->InstrnsAfter.push_back(AdICpCC); if(AdIAftCC) - (PRA.AddedInstrMap[MInst]->InstrnsAfter).push_back(AdIAftCC); + PRA.AddedInstrMap[MInst]->InstrnsAfter.push_back(AdIAftCC); if(DEBUG_RA) { @@ -1368,10 +1368,10 @@ void UltraSparcRegInfo::insertCallerSavingCode(const MachineInstr *MInst, } else { // for any other register type, just add the pop inst AdIAft = cpMem2RegMI(getFramePointer(), StackOff, Reg, RegType ); - ((PRA.AddedInstrMap[MInst])->InstrnsAfter).push_back(AdIAft); + PRA.AddedInstrMap[MInst]->InstrnsAfter.push_back(AdIAft); } - PushedRegSet.insert( Reg ); + PushedRegSet.insert(Reg); if(DEBUG_RA) { cerr << "\nFor call inst:" << *MInst; -- 2.34.1