1 /* Title: RegClass.h -*- C++ -*-
2 Author: Ruchira Sasanka
4 Purpose: Contains machine independent methods for register coloring.
11 #include "llvm/CodeGen/InterferenceGraph.h"
12 #include "llvm/Target/MachineRegInfo.h"
14 class MachineRegClassInfo;
16 typedef std::vector<unsigned> ReservedColorListType;
19 //-----------------------------------------------------------------------------
22 // Implements a machine independant register class.
24 // This is the class that contains all data structures and common algos
25 // for coloring a particular register class (e.g., int class, fp class).
26 // This class is hardware independent. This class accepts a hardware
27 // dependent description of machine registers (MachineRegInfo class) to
28 // get hardware specific info and to color an individual IG node.
30 // This class contains the InterferenceGraph (IG).
31 // Also it contains an IGNode stack that can be used for coloring.
32 // The class provides some easy access methods to the IG methods, since these
33 // methods are called thru a register class.
35 //-----------------------------------------------------------------------------
37 const Function *const Meth; // Function we are working on
38 const MachineRegClassInfo *const MRC; // corresponding MRC
39 const unsigned RegClassID; // my int ID
41 InterferenceGraph IG; // Interference graph - constructed by
42 // buildInterferenceGraph
43 std::stack<IGNode *> IGNodeStack; // the stack used for coloring
45 const ReservedColorListType *const ReservedColorList;
47 // for passing registers that are pre-allocated and cannot be used by the
48 // register allocator for this function.
52 // An array used for coloring each node. This array must be of size
53 // MRC->getNumOfAllRegs(). Allocated once in the constructor
57 //--------------------------- private methods ------------------------------
59 void pushAllIGNodes();
61 bool pushUnconstrainedIGNodes();
63 IGNode * getIGNodeWithMinSpillCost();
65 void colorIGNode(IGNode *const Node);
70 RegClass(const Function *M,
71 const MachineRegClassInfo *MRC,
72 const ReservedColorListType *RCL = 0);
74 ~RegClass() { delete[] IsColorUsedArr; }
76 inline void createInterferenceGraph() { IG.createGraph(); }
78 inline InterferenceGraph &getIG() { return IG; }
80 inline const unsigned getID() const { return RegClassID; }
82 // main method called for coloring regs
86 inline unsigned getNumOfAvailRegs() const
87 { return MRC->getNumOfAvailRegs(); }
90 // --- following methods are provided to access the IG contained within this
91 // ---- RegClass easilly.
93 inline void addLRToIG(LiveRange *const LR)
96 inline void setInterference(const LiveRange *const LR1,
97 const LiveRange *const LR2)
98 { IG.setInterference(LR1, LR2); }
100 inline unsigned getInterference(const LiveRange *const LR1,
101 const LiveRange *const LR2) const
102 { return IG.getInterference(LR1, LR2); }
104 inline void mergeIGNodesOfLRs(const LiveRange *const LR1,
105 LiveRange *const LR2)
106 { IG.mergeIGNodesOfLRs(LR1, LR2); }
109 inline bool * getIsColorUsedArr() { return IsColorUsedArr; }
112 inline void printIGNodeList() const {
113 std::cerr << "IG Nodes for Register Class " << RegClassID << ":" << "\n";
114 IG.printIGNodeList();
117 inline void printIG() {
118 std::cerr << "IG for Register Class " << RegClassID << ":" << "\n";