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"
18 typedef std::vector<unsigned int> ReservedColorListType;
21 //-----------------------------------------------------------------------------
24 // Implements a machine independant register class.
26 // This is the class that contains all data structures and common algos
27 // for coloring a particular register class (e.g., int class, fp class).
28 // This class is hardware independent. This class accepts a hardware
29 // dependent description of machine registers (MachineRegInfo class) to
30 // get hardware specific info and to color an individual IG node.
32 // This class contains the InterferenceGraph (IG).
33 // Also it contains an IGNode stack that can be used for coloring.
34 // The class provides some easy access methods to the IG methods, since these
35 // methods are called thru a register class.
37 //-----------------------------------------------------------------------------
42 const Method *const Meth; // Method we are working on
44 const MachineRegClassInfo *const MRC; // corresponding MRC
46 const unsigned RegClassID; // my int ID
48 InterferenceGraph IG; // Interference graph - constructed by
49 // buildInterferenceGraph
50 std::stack<IGNode *> IGNodeStack; // the stack used for coloring
52 const ReservedColorListType *const ReservedColorList;
54 // for passing registers that are pre-allocated and cannot be used by the
55 // register allocator for this method.
59 // An array used for coloring each node. This array must be of size
60 // MRC->getNumOfAllRegs(). Allocated once in the constructor
64 //--------------------------- private methods ------------------------------
66 void pushAllIGNodes();
68 bool pushUnconstrainedIGNodes();
70 IGNode * getIGNodeWithMinSpillCost();
72 void colorIGNode(IGNode *const Node);
77 RegClass(const Method *const M,
78 const MachineRegClassInfo *const MRC,
79 const ReservedColorListType *const RCL = NULL);
81 ~RegClass() { delete[] IsColorUsedArr; };
83 inline void createInterferenceGraph()
86 inline InterferenceGraph &getIG() { return IG; }
88 inline const unsigned getID() const { return RegClassID; }
90 // main method called for coloring regs
94 inline unsigned getNumOfAvailRegs() const
95 { return MRC->getNumOfAvailRegs(); }
98 // --- following methods are provided to access the IG contained within this
99 // ---- RegClass easilly.
101 inline void addLRToIG(LiveRange *const LR)
102 { IG.addLRToIG(LR); }
104 inline void setInterference(const LiveRange *const LR1,
105 const LiveRange *const LR2)
106 { IG.setInterference(LR1, LR2); }
108 inline unsigned getInterference(const LiveRange *const LR1,
109 const LiveRange *const LR2) const
110 { return IG.getInterference(LR1, LR2); }
112 inline void mergeIGNodesOfLRs(const LiveRange *const LR1,
113 LiveRange *const LR2)
114 { IG.mergeIGNodesOfLRs(LR1, LR2); }
117 inline bool * getIsColorUsedArr() { return IsColorUsedArr; }
120 inline void printIGNodeList() const {
121 std::cerr << "IG Nodes for Register Class " << RegClassID << ":" << "\n";
122 IG.printIGNodeList();
125 inline void printIG() {
126 std::cerr << "IG for Register Class " << RegClassID << ":" << "\n";