2 Author: Ruchira Sasanka
4 Purpose: Contains machine independent methods for register coloring.
6 This is the class that contains all data structures and common algos
7 for coloring a particular register class (e.g., int class, fp class).
8 This class is hardware independent. This class accepts a hardware
9 dependent description of machine registers (MachineRegInfo class) to
10 get hardware specific info and color and indidual IG node.
12 This class contains the InterferenceGraph (IG).
13 Also it contains an IGNode stack that can be used for coloring.
14 The class provides some easy access methods to the IG methods, since these
15 methods are called thru a register class.
22 #include "llvm/CodeGen/IGNode.h"
23 #include "llvm/CodeGen/InterferenceGraph.h"
24 #include "llvm/Target/Machine.h"
27 typedef vector<unsigned int> ReservedColorListType;
34 const Method *const Meth; // Method we are working on
36 const MachineRegClassInfo *const MRC; // corresponding MRC
38 const unsigned RegClassID; // my int ID
40 InterferenceGraph IG; // Interference graph - constructed by
41 // buildInterferenceGraph
42 stack <IGNode *> IGNodeStack; // the stack used for coloring
44 // for passing registered that are pre-allocated (e.g., %g's)
45 const ReservedColorListType *const ReservedColorList;
47 // An array used for coloring each node. This array must be of size
48 // MRC->getNumOfAllRegs(). Allocated once in the constructor
53 //------------ private methods ------------------
55 void pushAllIGNodes();
56 bool pushUnconstrainedIGNodes();
57 IGNode * getIGNodeWithMinSpillCost();
58 void colorIGNode(IGNode *const Node);
62 RegClass(const Method *const M,
63 const MachineRegClassInfo *const MRC,
64 const ReservedColorListType *const RCL = NULL);
66 inline void createInterferenceGraph()
69 inline InterferenceGraph &getIG() { return IG; }
71 inline const unsigned getID() const { return RegClassID; }
73 void colorAllRegs(); // main method called for coloring regs
75 inline unsigned getNumOfAvailRegs() const
76 { return MRC->getNumOfAvailRegs(); }
78 ~RegClass() { delete[] IsColorUsedArr; };
82 // --- following methods are provided to access the IG contained within this
83 // ---- RegClass easilly.
86 inline void addLRToIG(LiveRange *const LR)
89 inline void setInterference(const LiveRange *const LR1,
90 const LiveRange *const LR2)
91 { IG.setInterference(LR1, LR2); }
93 inline unsigned getInterference(const LiveRange *const LR1,
94 const LiveRange *const LR2) const
95 { return IG.getInterference(LR1, LR2); }
97 inline void mergeIGNodesOfLRs(const LiveRange *const LR1,
99 { IG.mergeIGNodesOfLRs(LR1, LR2); }
102 inline void printIGNodeList() const {
103 cout << "IG Nodes for Register Class " << RegClassID << ":" << endl;
104 IG.printIGNodeList();
107 inline void printIG() {
108 cout << "IG for Register Class " << RegClassID << ":" << endl;