1 /* Title: RegClass.h -*- C++ -*-
2 Author: Ruchira Sasanka
4 Purpose: Contains machine independent methods for register coloring.
11 #include "llvm/CodeGen/IGNode.h"
12 #include "llvm/CodeGen/InterferenceGraph.h"
13 #include "llvm/Target/TargetMachine.h"
14 #include "llvm/Target/MachineRegInfo.h"
17 typedef vector<unsigned int> ReservedColorListType;
20 //-----------------------------------------------------------------------------
23 // Implements a machine independant register class.
25 // This is the class that contains all data structures and common algos
26 // for coloring a particular register class (e.g., int class, fp class).
27 // This class is hardware independent. This class accepts a hardware
28 // dependent description of machine registers (MachineRegInfo class) to
29 // get hardware specific info and to color an individual IG node.
31 // This class contains the InterferenceGraph (IG).
32 // Also it contains an IGNode stack that can be used for coloring.
33 // The class provides some easy access methods to the IG methods, since these
34 // methods are called thru a register class.
36 //-----------------------------------------------------------------------------
41 const Method *const Meth; // Method we are working on
43 const MachineRegClassInfo *const MRC; // corresponding MRC
45 const unsigned RegClassID; // my int ID
47 InterferenceGraph IG; // Interference graph - constructed by
48 // buildInterferenceGraph
49 stack <IGNode *> IGNodeStack; // the stack used for coloring
51 const ReservedColorListType *const ReservedColorList;
53 // for passing registers that are pre-allocated and cannot be used by the
54 // register allocator for this method.
58 // An array used for coloring each node. This array must be of size
59 // MRC->getNumOfAllRegs(). Allocated once in the constructor
63 //--------------------------- private methods ------------------------------
65 void pushAllIGNodes();
67 bool pushUnconstrainedIGNodes();
69 IGNode * getIGNodeWithMinSpillCost();
71 void colorIGNode(IGNode *const Node);
76 RegClass(const Method *const M,
77 const MachineRegClassInfo *const MRC,
78 const ReservedColorListType *const RCL = NULL);
80 ~RegClass() { delete[] IsColorUsedArr; };
82 inline void createInterferenceGraph()
85 inline InterferenceGraph &getIG() { return IG; }
87 inline const unsigned getID() const { return RegClassID; }
89 // main method called for coloring regs
93 inline unsigned getNumOfAvailRegs() const
94 { return MRC->getNumOfAvailRegs(); }
97 // --- following methods are provided to access the IG contained within this
98 // ---- RegClass easilly.
100 inline void addLRToIG(LiveRange *const LR)
101 { IG.addLRToIG(LR); }
103 inline void setInterference(const LiveRange *const LR1,
104 const LiveRange *const LR2)
105 { IG.setInterference(LR1, LR2); }
107 inline unsigned getInterference(const LiveRange *const LR1,
108 const LiveRange *const LR2) const
109 { return IG.getInterference(LR1, LR2); }
111 inline void mergeIGNodesOfLRs(const LiveRange *const LR1,
112 LiveRange *const LR2)
113 { IG.mergeIGNodesOfLRs(LR1, LR2); }
116 inline bool * getIsColorUsedArr() { return IsColorUsedArr; }
119 inline void printIGNodeList() const {
120 cerr << "IG Nodes for Register Class " << RegClassID << ":" << endl;
121 IG.printIGNodeList();
124 inline void printIG() {
125 cerr << "IG for Register Class " << RegClassID << ":" << endl;