diff options
author | Chris Lattner <sabre@nondot.org> | 2004-01-09 06:17:12 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-01-09 06:17:12 +0000 |
commit | 75e260990d81fdddd8660bbee854cb2c0d4c42c9 (patch) | |
tree | 072ba6fe423815512af7093859c0a6ae38689c24 | |
parent | f7703df4968084c18c248c1feea9961c19a32e6a (diff) |
Move lib/Codegen/RegAlloc into lib/Target/Sparc, as it is sparc specific
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10728 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/Makefile | 2 | ||||
-rw-r--r-- | lib/CodeGen/RegAlloc/AllocInfo.h | 84 | ||||
-rw-r--r-- | lib/CodeGen/RegAlloc/IGNode.cpp | 62 | ||||
-rw-r--r-- | lib/CodeGen/RegAlloc/IGNode.h | 123 | ||||
-rw-r--r-- | lib/CodeGen/RegAlloc/InterferenceGraph.cpp | 252 | ||||
-rw-r--r-- | lib/CodeGen/RegAlloc/InterferenceGraph.h | 75 | ||||
-rw-r--r-- | lib/CodeGen/RegAlloc/LiveRange.h | 184 | ||||
-rw-r--r-- | lib/CodeGen/RegAlloc/LiveRangeInfo.cpp | 416 | ||||
-rw-r--r-- | lib/CodeGen/RegAlloc/LiveRangeInfo.h | 128 | ||||
-rw-r--r-- | lib/CodeGen/RegAlloc/Makefile | 17 | ||||
-rw-r--r-- | lib/CodeGen/RegAlloc/PhyRegAlloc.cpp | 1397 | ||||
-rw-r--r-- | lib/CodeGen/RegAlloc/PhyRegAlloc.h | 186 | ||||
-rw-r--r-- | lib/CodeGen/RegAlloc/RegAllocCommon.h | 32 | ||||
-rw-r--r-- | lib/CodeGen/RegAlloc/RegClass.cpp | 250 | ||||
-rw-r--r-- | lib/CodeGen/RegAlloc/RegClass.h | 147 | ||||
-rw-r--r-- | lib/Target/SparcV9/Makefile | 1 | ||||
-rw-r--r-- | lib/Target/SparcV9/RegAlloc/Makefile | 2 |
17 files changed, 3 insertions, 3355 deletions
diff --git a/lib/CodeGen/Makefile b/lib/CodeGen/Makefile index 4463921d47..e5c81e8193 100644 --- a/lib/CodeGen/Makefile +++ b/lib/CodeGen/Makefile @@ -7,7 +7,7 @@ # ##===----------------------------------------------------------------------===## LEVEL = ../.. -PARALLEL_DIRS = InstrSelection InstrSched RegAlloc SelectionDAG +PARALLEL_DIRS = InstrSelection InstrSched SelectionDAG LIBRARYNAME = codegen include $(LEVEL)/Makefile.common diff --git a/lib/CodeGen/RegAlloc/AllocInfo.h b/lib/CodeGen/RegAlloc/AllocInfo.h deleted file mode 100644 index 67f58a7ed0..0000000000 --- a/lib/CodeGen/RegAlloc/AllocInfo.h +++ /dev/null @@ -1,84 +0,0 @@ -//===-- AllocInfo.h - Store info about regalloc decisions -------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file was developed by the LLVM research group and is distributed under -// the University of Illinois Open Source License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This header file contains the data structure used to save the state -// of the global, graph-coloring register allocator. -// -//===----------------------------------------------------------------------===// - -#ifndef ALLOCINFO_H -#define ALLOCINFO_H - -#include "llvm/Type.h" -#include "llvm/DerivedTypes.h" -#include "llvm/Constants.h" - -namespace llvm { - -/// AllocInfo - Structure representing one instruction's operand's-worth of -/// register allocation state. We create tables made out of these data -/// structures to generate mapping information for this register allocator. -/// -struct AllocInfo { - unsigned Instruction; - int Operand; // (-1 if Instruction, or 0...n-1 for an operand.) - enum AllocStateTy { NotAllocated = 0, Allocated, Spilled }; - AllocStateTy AllocState; - int Placement; - - AllocInfo (unsigned Instruction_, unsigned Operand_, - AllocStateTy AllocState_, int Placement_) : - Instruction (Instruction_), Operand (Operand_), - AllocState (AllocState_), Placement (Placement_) { } - - /// getConstantType - Return a StructType representing an AllocInfo object. - /// - static StructType *getConstantType () { - std::vector<const Type *> TV; - TV.push_back (Type::UIntTy); - TV.push_back (Type::IntTy); - TV.push_back (Type::UIntTy); - TV.push_back (Type::IntTy); - return StructType::get (TV); - } - - /// toConstant - Convert this AllocInfo into an LLVM Constant of type - /// getConstantType(), and return the Constant. - /// - Constant *toConstant () const { - StructType *ST = getConstantType (); - std::vector<Constant *> CV; - CV.push_back (ConstantUInt::get (Type::UIntTy, Instruction)); - CV.push_back (ConstantSInt::get (Type::IntTy, Operand)); - CV.push_back (ConstantUInt::get (Type::UIntTy, AllocState)); - CV.push_back (ConstantSInt::get (Type::IntTy, Placement)); - return ConstantStruct::get (ST, CV); - } - - /// AllocInfos compare equal if the allocation placements are equal - /// (i.e., they can be equal even if they refer to operands from two - /// different instructions.) - /// - bool operator== (const AllocInfo &X) const { - return (X.AllocState == AllocState) && (X.Placement == Placement); - } - bool operator!= (const AllocInfo &X) const { return !(*this == X); } - - /// Returns a human-readable string representation of the AllocState member. - /// - const std::string allocStateToString () const { - static const char *AllocStateNames[] = - { "NotAllocated", "Allocated", "Spilled" }; - return std::string (AllocStateNames[AllocState]); - } -}; - -} // End llvm namespace - -#endif // ALLOCINFO_H diff --git a/lib/CodeGen/RegAlloc/IGNode.cpp b/lib/CodeGen/RegAlloc/IGNode.cpp deleted file mode 100644 index a76fdeaa03..0000000000 --- a/lib/CodeGen/RegAlloc/IGNode.cpp +++ /dev/null @@ -1,62 +0,0 @@ -//===-- IGNode.cpp --------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file was developed by the LLVM research group and is distributed under -// the University of Illinois Open Source License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file implements an Interference graph node for coloring-based register -// allocation. -// -//===----------------------------------------------------------------------===// - -#include "IGNode.h" -#include <algorithm> -#include <iostream> - -namespace llvm { - -//----------------------------------------------------------------------------- -// Sets this IGNode on stack and reduce the degree of neighbors -//----------------------------------------------------------------------------- - -void IGNode::pushOnStack() { - OnStack = true; - int neighs = AdjList.size(); - - if (neighs < 0) { - std::cerr << "\nAdj List size = " << neighs; - assert(0 && "Invalid adj list size"); - } - - for (int i=0; i < neighs; i++) - AdjList[i]->decCurDegree(); -} - -//----------------------------------------------------------------------------- -// Deletes an adjacency node. IGNodes are deleted when coalescing merges -// two IGNodes together. -//----------------------------------------------------------------------------- - -void IGNode::delAdjIGNode(const IGNode *Node) { - std::vector<IGNode *>::iterator It=find(AdjList.begin(), AdjList.end(), Node); - assert(It != AdjList.end() && "The node must be there!"); - AdjList.erase(It); -} - -//----------------------------------------------------------------------------- -// Get the number of unique neighbors if these two nodes are merged -//----------------------------------------------------------------------------- - -unsigned -IGNode::getCombinedDegree(const IGNode* otherNode) const { - std::vector<IGNode*> nbrs(AdjList); - nbrs.insert(nbrs.end(), otherNode->AdjList.begin(), otherNode->AdjList.end()); - sort(nbrs.begin(), nbrs.end()); - std::vector<IGNode*>::iterator new_end = unique(nbrs.begin(), nbrs.end()); - return new_end - nbrs.begin(); -} - -} // End llvm namespace diff --git a/lib/CodeGen/RegAlloc/IGNode.h b/lib/CodeGen/RegAlloc/IGNode.h deleted file mode 100644 index 9fdc7a6ac0..0000000000 --- a/lib/CodeGen/RegAlloc/IGNode.h +++ /dev/null @@ -1,123 +0,0 @@ -//===-- IGNode.h - Represent a node in an interference graph ----*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file was developed by the LLVM research group and is distributed under -// the University of Illinois Open Source License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file represents a node in an interference graph. -// -// For efficiency, the AdjList is updated only once - ie. we can add but not -// remove nodes from AdjList. -// -// The removal of nodes from IG is simulated by decrementing the CurDegree. -// If this node is put on stack (that is removed from IG), the CurDegree of all -// the neighbors are decremented and this node is marked OnStack. Hence -// the effective neighbors in the AdjList are the ones that do not have the -// OnStack flag set (therefore, they are in the IG). -// -// The methods that modify/use the CurDegree must be called only -// after all modifications to the IG are over (i.e., all neighbors are fixed). -// -// The vector representation is the most efficient one for adj list. -// Though nodes are removed when coalescing is done, we access it in sequence -// for far many times when coloring (colorNode()). -// -//===----------------------------------------------------------------------===// - -#ifndef IGNODE_H -#define IGNODE_H - -#include "LiveRange.h" -#include <vector> - -namespace llvm { - -class RegClass; - -//---------------------------------------------------------------------------- -// Class IGNode -// -// Represents a node in an interference graph. -//---------------------------------------------------------------------------- - -class IGNode { - const unsigned Index; // index within IGNodeList - bool OnStack; // this has been pushed on to stack for coloring - std::vector<IGNode *> AdjList;// adjacency list for this live range - - int CurDegree; - // - // set by InterferenceGraph::setCurDegreeOfIGNodes() after calculating - // all adjacency lists. - // Decremented when a neighbor is pushed on to the stack. - // After that, never incremented/set again nor used. - - LiveRange *const ParentLR; -public: - - IGNode(LiveRange *LR, unsigned index) : Index(index), ParentLR(LR) { - OnStack = false; - CurDegree = -1; - ParentLR->setUserIGNode(this); - } - - inline unsigned int getIndex() const { return Index; } - - // adjLists must be updated only once. However, the CurDegree can be changed - // - inline void addAdjIGNode(IGNode *AdjNode) { AdjList.push_back(AdjNode); } - - inline IGNode *getAdjIGNode(unsigned ind) const - { assert ( ind < AdjList.size()); return AdjList[ind]; } - - // delete a node in AdjList - node must be in the list - // should not be called often - // - void delAdjIGNode(const IGNode *Node); - - inline unsigned getNumOfNeighbors() const { return AdjList.size(); } - - // Get the number of unique neighbors if these two nodes are merged - unsigned getCombinedDegree(const IGNode* otherNode) const; - - inline bool isOnStack() const { return OnStack; } - - // remove form IG and pushes on to stack (reduce the degree of neighbors) - // - void pushOnStack(); - - // CurDegree is the effective number of neighbors when neighbors are - // pushed on to the stack during the coloring phase. Must be called - // after all modifications to the IG are over (i.e., all neighbors are - // fixed). - // - inline void setCurDegree() { - assert(CurDegree == -1); - CurDegree = AdjList.size(); - } - - inline int getCurDegree() const { return CurDegree; } - - // called when a neigh is pushed on to stack - // - inline void decCurDegree() { assert(CurDegree > 0); --CurDegree; } - - // The following methods call the methods in ParentLR - // They are added to this class for convenience - // If many of these are called within a single scope, - // consider calling the methods directly on LR - inline bool hasColor() const { return ParentLR->hasColor(); } - - inline unsigned int getColor() const { return ParentLR->getColor(); } - - inline void setColor(unsigned Col) { ParentLR->setColor(Col); } - - inline LiveRange *getParentLR() const { return ParentLR; } -}; - -} // End llvm namespace - -#endif diff --git a/lib/CodeGen/RegAlloc/InterferenceGraph.cpp b/lib/CodeGen/RegAlloc/InterferenceGraph.cpp deleted file mode 100644 index 3cef19ea0e..0000000000 --- a/lib/CodeGen/RegAlloc/InterferenceGraph.cpp +++ /dev/null @@ -1,252 +0,0 @@ -//===-- InterferenceGraph.cpp ---------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file was developed by the LLVM research group and is distributed under -// the University of Illinois Open Source License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// Interference graph for coloring-based register allocation for LLVM. -// -//===----------------------------------------------------------------------===// - -#include "IGNode.h" -#include "InterferenceGraph.h" -#include "RegAllocCommon.h" -#include "Support/STLExtras.h" -#include <algorithm> - -namespace llvm { - -// for asserting this IG node is infact in the IGNodeList of this class -inline static void assertIGNode(const InterferenceGraph *IG, - const IGNode *Node) { - assert(IG->getIGNodeList()[Node->getIndex()] == Node); -} - -//----------------------------------------------------------------------------- -// Constructor: Records the RegClass and initalizes IGNodeList. -// The matrix is NOT yet created by the constructor. Call createGraph() -// to create it after adding all IGNodes to the IGNodeList. -//----------------------------------------------------------------------------- -InterferenceGraph::InterferenceGraph(RegClass *const RC) : RegCl(RC) { - IG = NULL; - Size = 0; - if( DEBUG_RA >= RA_DEBUG_Interference) - std::cerr << "Interference graph created!\n"; -} - - -//----------------------------------------------------------------------------- -// destructor. Deletes the bit matrix and all IGNodes -//----------------------------------------------------------------------------- -InterferenceGraph:: ~InterferenceGraph() { - // delete the matrix - for(unsigned int r=0; r < IGNodeList.size(); ++r) - delete[] IG[r]; - delete[] IG; - - // delete all IGNodes in the IGNodeList - for_each(IGNodeList.begin(), IGNodeList.end(), deleter<IGNode>); -} - - - -//----------------------------------------------------------------------------- -// Creates (dynamically allocates) the bit matrix necessary to hold the -// interference graph. -//----------------------------------------------------------------------------- -void InterferenceGraph::createGraph() -{ - Size = IGNodeList.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++) - IG[i][j] = 0; -} - -//----------------------------------------------------------------------------- -// creates a new IGNode for the given live range and add to IG -//----------------------------------------------------------------------------- -void InterferenceGraph::addLRToIG(LiveRange *const LR) -{ - IGNodeList.push_back(new IGNode(LR, IGNodeList.size())); -} - - -//----------------------------------------------------------------------------- -// set interference for two live ranges -// update both the matrix and AdjLists of nodes. -// If there is already an interference between LR1 and LR2, adj lists -// are not updated. LR1 and LR2 must be distinct since if not, it suggests -// that there is some wrong logic in some other method. -//----------------------------------------------------------------------------- -void InterferenceGraph::setInterference(const LiveRange *const LR1, - const LiveRange *const LR2 ) { - assert(LR1 != LR2); - - IGNode *IGNode1 = LR1->getUserIGNode(); - IGNode *IGNode2 = LR2->getUserIGNode(); - - assertIGNode(this, IGNode1); - assertIGNode(this, IGNode2); - - unsigned row = IGNode1->getIndex(); - unsigned col = IGNode2->getIndex(); - - char *val; - - if( DEBUG_RA >= RA_DEBUG_Interference) - std::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 ); - } - -} - - -//---------------------------------------------------------------------------- -// return whether two live ranges interfere -//---------------------------------------------------------------------------- -unsigned InterferenceGraph::getInterference(const LiveRange *const LR1, - const LiveRange *const LR2) const { - assert(LR1 != LR2); - assertIGNode(this, LR1->getUserIGNode()); - assertIGNode(this, LR2->getUserIGNode()); - - const unsigned int row = LR1->getUserIGNode()->getIndex(); - const unsigned int col = LR2->getUserIGNode()->getIndex(); - - char ret; - if (row > col) - ret = IG[row][col]; - else - ret = IG[col][row]; - return ret; - -} - - -//---------------------------------------------------------------------------- -// Merge 2 IGNodes. The neighbors of the SrcNode will be added to the DestNode. -// Then the IGNode2L will be deleted. Necessary for coalescing. -// IMPORTANT: The live ranges are NOT merged by this method. Use -// LiveRangeInfo::unionAndUpdateLRs for that purpose. -//---------------------------------------------------------------------------- - -void InterferenceGraph::mergeIGNodesOfLRs(const LiveRange *LR1, - LiveRange *LR2) { - - assert( LR1 != LR2); // cannot merge the same live range - - IGNode *const DestNode = LR1->getUserIGNode(); - IGNode *SrcNode = LR2->getUserIGNode(); - - assertIGNode(this, DestNode); - assertIGNode(this, SrcNode); - - if( DEBUG_RA >= RA_DEBUG_Interference) { - std::cerr << "Merging LRs: \""; printSet(*LR1); - std::cerr << "\" and \""; printSet(*LR2); - std::cerr << "\"\n"; - } - - unsigned SrcDegree = SrcNode->getNumOfNeighbors(); - const unsigned SrcInd = SrcNode->getIndex(); - - - // for all neighs of SrcNode - for(unsigned i=0; i < SrcDegree; i++) { - IGNode *NeighNode = SrcNode->getAdjIGNode(i); - - LiveRange *const LROfNeigh = NeighNode->getParentLR(); - - // delete edge between src and neigh - even neigh == dest - NeighNode->delAdjIGNode(SrcNode); - - // set the matrix posn to 0 betn src and neigh - even neigh == dest - const unsigned NInd = NeighNode->getIndex(); - ( SrcInd > NInd) ? (IG[SrcInd][NInd]=0) : (IG[NInd][SrcInd]=0) ; - - - if( LR1 != LROfNeigh) { // if the neigh != dest - - // add edge betwn Dest and Neigh - if there is no current edge - setInterference(LR1, LROfNeigh ); - } - - } - - IGNodeList[ SrcInd ] = NULL; - - // SrcNode is no longer necessary - LR2 must be deleted by the caller - delete( SrcNode ); - -} - - -//---------------------------------------------------------------------------- -// must be called after modifications to the graph are over but before -// pushing IGNodes on to the stack for coloring. -//---------------------------------------------------------------------------- -void InterferenceGraph::setCurDegreeOfIGNodes() -{ - unsigned Size = IGNodeList.size(); - - for( unsigned i=0; i < Size; i++) { - IGNode *Node = IGNodeList[i]; - if( Node ) - Node->setCurDegree(); - } -} - - - - - -//--------------------- debugging (Printing) methods ----------------------- - -//---------------------------------------------------------------------------- -// Print the IGnodes -//---------------------------------------------------------------------------- -void InterferenceGraph::printIG() const { - for(unsigned i=0; i < Size; i++) { - const IGNode *const Node = IGNodeList[i]; - if(Node) { - std::cerr << " [" << i << "] "; - - for( unsigned int j=0; j < Size; j++) - if(IG[i][j]) - std::cerr << "(" << i << "," << j << ") "; - std::cerr << "\n"; - } - } -} - -//---------------------------------------------------------------------------- -// Print the IGnodes in the IGNode List -//---------------------------------------------------------------------------- -void InterferenceGraph::printIGNodeList() const { - for(unsigned i=0; i < IGNodeList.size() ; ++i) { - const IGNode *const Node = IGNodeList[i]; - - if (Node) { - std::cerr << " [" << Node->getIndex() << "] "; - printSet(*Node->getParentLR()); - //int Deg = Node->getCurDegree(); - std::cerr << "\t <# of Neighs: " << Node->getNumOfNeighbors() << ">\n"; - } - } -} - -} // End llvm namespace diff --git a/lib/CodeGen/RegAlloc/InterferenceGraph.h b/lib/CodeGen/RegAlloc/InterferenceGraph.h deleted file mode 100644 index 79850c1fcf..0000000000 --- a/lib/CodeGen/RegAlloc/InterferenceGraph.h +++ /dev/null @@ -1,75 +0,0 @@ -//===-- InterferenceGraph.h - Interference graph for register coloring -*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file was developed by the LLVM research group and is distributed under -// the University of Illinois Open Source License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -/* Title: InterferenceGraph.h -*- C++ -*- - Author: Ruchira Sasanka - Date: July 20, 01 - Purpose: Interference Graph used for register coloring. - - Notes: - Adj Info is stored in the lower trangular matrix (i.e., row > col ) - - This class must be used in the following way: - - * Construct class - * call addLRToIG as many times to add ALL LRs to this IG - * call createGraph to create the actual matrix - * Then setInterference, getInterference, mergeIGNodesOfLRs can be - called as desired to modify the graph. - * Once the modifications to the graph are over, call - setCurDegreeOfIGNodes() before pushing IGNodes on to stack for coloring. -*/ - -#ifndef INTERFERENCEGRAPH_H -#define INTERFERENCEGRAPH_H - -#include <vector> - -namespace llvm { - -class LiveRange; -class RegClass; -class IGNode; - -class InterferenceGraph { - char **IG; // a poiner to the interference graph - unsigned int Size; // size of a side of the IG - RegClass *const RegCl; // RegCl contains this IG - std::vector<IGNode *> IGNodeList; // a list of all IGNodes in a reg class - - public: - // the matrix is not yet created by the constructor. Call createGraph() - // to create it after adding all IGNodes to the IGNodeList - InterferenceGraph(RegClass *RC); - ~InterferenceGraph(); - - void createGraph(); - - void addLRToIG(LiveRange *LR); - - void setInterference(const LiveRange *LR1, - const LiveRange *LR2); - - unsigned getInterference(const LiveRange *LR1, - const LiveRange *LR2) const ; - - void mergeIGNodesOfLRs(const LiveRange *LR1, LiveRange *LR2); - - std::vector<IGNode *> &getIGNodeList() { return IGNodeList; } - const std::vector<IGNode *> &getIGNodeList() const { return IGNodeList; } - - void setCurDegreeOfIGNodes(); - - void printIG() const; - void printIGNodeList() const; -}; - -} // End llvm namespace - -#endif diff --git a/lib/CodeGen/RegAlloc/LiveRange.h b/lib/CodeGen/RegAlloc/LiveRange.h deleted file mode 100644 index d6e2cf6307..0000000000 --- a/lib/CodeGen/RegAlloc/LiveRange.h +++ /dev/null @@ -1,184 +0,0 @@ -//===-- LiveRange.h - Store info about a live range -------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file was developed by the LLVM research group and is distributed under -// the University of Illinois Open Source License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// Implements a live range using a ValueSet. A LiveRange is a simple set -// of Values. -// -// Since the Value pointed by a use is the same as of its def, it is sufficient -// to keep only defs in a LiveRange. -// -//===----------------------------------------------------------------------===// - -#ifndef LIVERANGE_H -#define LIVERANGE_H - -#include "llvm/Value.h" -#include "llvm/CodeGen/ValueSet.h" - -namespace llvm { - -class RegClass; -class IGNode; - -class LiveRange : public ValueSet { - RegClass *MyRegClass; // register class (e.g., int, FP) for this LR - - /// doesSpanAcrossCalls - Does this live range span across calls? - /// This information is used by graph coloring algo to avoid allocating - /// volatile colors to live ranges that span across calls (since they have to - /// be saved/restored) - /// - bool doesSpanAcrossCalls; - - IGNode *UserIGNode; // IGNode which uses this LR - int Color; // color assigned to this live range - bool mustSpill; // whether this LR must be spilt - - /// mustSaveAcrossCalls - whether this LR must be saved accross calls - /// ***TODO REMOVE this - /// - bool mustSaveAcrossCalls; - - /// SuggestedColor - if this LR has a suggested color, can it be - /// really alloated? A suggested color cannot be allocated when the - /// suggested color is volatile and when there are call - /// interferences. - /// - int SuggestedColor; // The suggested color for this LR - - /// CanUseSuggestedCol - It is possible that a suggested color for - /// this live range is not available before graph coloring (e.g., it - /// can be allocated to another live range which interferes with - /// this) - /// - bool CanUseSuggestedCol; - - /// SpilledStackOffsetFromFP - If this LR is spilled, its stack - /// offset from *FP*. The spilled offsets must always be relative to - /// the FP. - /// - int SpilledStackOffsetFromFP; - - /// HasSpillOffset 0 Whether this live range has a spill offset - /// - bool HasSpillOffset; - - /// The spill cost of this live range. Calculated using loop depth of - /// each reference to each Value in the live range - /// - unsigned SpillCost; - -public: - LiveRange() { - Color = SuggestedColor = -1; // not yet colored - mustSpill = mustSaveAcrossCalls = false; - MyRegClass = 0; - UserIGNode = 0; - doesSpanAcrossCalls = false; - CanUseSuggestedCol = true; - HasSpillOffset = false; - SpillCost = 0; - } - - void setRegClass(RegClass *RC) { MyRegClass = RC; } - - RegClass *getRegClass() const { assert(MyRegClass); return MyRegClass; } - unsigned getRegClassID() const; - - bool hasColor() const { return Color != -1; } - - unsigned getColor() const { assert(Color != -1); return (unsigned)Color; } - - void setColor(unsigned Col) { Color = (int)Col; } - - inline void setCallInterference() { - doesSpanAcrossCalls = 1; - } - inline void clearCallInterference() { - doesSpanAcrossCalls = 0; - } - - inline bool isCallInterference() const { - return doesSpanAcrossCalls == 1; - } - - inline void markForSpill() { mustSpill = true; } - - inline bool isMarkedForSpill() const { return mustSpill; } - - inline void setSpillOffFromFP(int StackOffset) { - assert(mustSpill && "This LR is not spilled"); - SpilledStackOffsetFromFP = StackOffset; - HasSpillOffset = true; - } - - inline void modifySpillOffFromFP(int StackOffset) { - assert(mustSpill && "This LR is not spilled"); - SpilledStackOffsetFromFP = StackOffset; - HasSpillOffset = true; - } - - inline bool hasSpillOffset() const { - return HasSpillOffset; - } - - inline int getSpillOffFromFP() const { - assert(HasSpillOffset && "This LR is not spilled"); - return SpilledStackOffsetFromFP; - } - - inline void markForSaveAcrossCalls() { mustSaveAcrossCalls = true; } - - inline void setUserIGNode(IGNode *IGN) { - assert(!UserIGNode); UserIGNode = IGN; - } - - // getUserIGNode - NULL if the user is not allocated - inline IGNode *getUserIGNode() const { return UserIGNode; } - - inline const Type *getType() const { - return (*begin())->getType(); // set's don't have a front - } - - inline void setSuggestedColor(int Col) { - if (SuggestedColor == -1) - SuggestedColor = Col; - } - - inline unsigned getSuggestedColor() const { - assert(SuggestedColor != -1); // only a valid color is obtained - return (unsigned)SuggestedColor; - } - - inline bool hasSuggestedColor() const { - return SuggestedColor != -1; - } - - inline bool isSuggestedColorUsable() const { - assert(hasSuggestedColor() && "No suggested color"); - return CanUseSuggestedCol; - } - - inline void setSuggestedColorUsable(bool val) { - assert(hasSuggestedColor() && "No suggested color"); - CanUseSuggestedCol = val; - } - - inline void addSpillCost(unsigned cost) { - SpillCost += cost; - } - - inline unsigned getSpillCost() const { - return SpillCost; - } -}; - -} // End llvm namespace - -#endif diff --git a/lib/CodeGen/RegAlloc/LiveRangeInfo.cpp b/lib/CodeGen/RegAlloc/LiveRangeInfo.cpp deleted file mode 100644 index 380680448d..0000000000 --- a/lib/CodeGen/RegAlloc/LiveRangeInfo.cpp +++ /dev/null @@ -1,416 +0,0 @@ -//===-- LiveRangeInfo.cpp -------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file was developed by the LLVM research group and is distributed under -// the University of Illinois Open Source License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// Live range construction for coloring-based register allocation for LLVM. -// -//===----------------------------------------------------------------------===// - -#include "IGNode.h" -#include "LiveRangeInfo.h" -#include "RegAllocCommon.h" -#include "RegClass.h" -#include "llvm/Function.h" -#include "llvm/CodeGen/MachineInstr.h" -#include "llvm/CodeGen/MachineFunction.h" -#include "llvm/Target/TargetMachine.h" -#include "llvm/Target/TargetInstrInfo.h" -#include "llvm/Target/TargetRegInfo.h" -#include "Support/SetOperations.h" - -namespace llvm { - -unsigned LiveRange::getRegClassID() const { return getRegClass()->getID(); } - -LiveRangeInfo::LiveRangeInfo(const Function *F, const TargetMachine &tm, - std::vector<RegClass *> &RCL) - : Meth(F), TM(tm), RegClassList(RCL), MRI(tm.getRegInfo()) { } - - -LiveRangeInfo::~LiveRangeInfo() { - for (LiveRangeMapType::iterator MI = LiveRangeMap.begin(); - MI != LiveRangeMap.end(); ++MI) { - - if (MI->first && MI->second) { - LiveRange *LR = MI->second; - - // 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. - - for (LiveRange::iterator LI = LR->begin(); LI != LR->end(); ++LI) - LiveRangeMap[*LI] = 0; - - delete LR; - } - } -} - - -//--------------------------------------------------------------------------- -// union two live ranges into one. The 2nd LR is deleted. Used for coalescing. -// Note: the caller must make sure that L1 and L2 are distinct and both -// LRs don't have suggested colors -//--------------------------------------------------------------------------- - -void LiveRangeInfo::unionAndUpdateLRs(LiveRange *L1, LiveRange *L2) { - assert(L1 != L2 && (!L1->hasSuggestedColor() || !L2->hasSuggestedColor())); - assert(! (L1->hasColor() && L2->hasColor()) || - L1->getColor() == L2->getColor()); - - set_union(*L1, *L2); // add elements of L2 to L1 - - for(ValueSet::iterator L2It = L2->begin(); L2It != L2->e |