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 // ReservedColorList - for passing registers that are pre-allocated and cannot
46 // be used by the register allocator for this function.
48 const ReservedColorListType *const ReservedColorList;
50 // IsColorUsedArr - An array used for coloring each node. This array must be
51 // of size MRC->getNumOfAllRegs(). Allocated once in the constructor for
54 std::vector<bool> IsColorUsedArr;
58 //--------------------------- private methods ------------------------------
60 void pushAllIGNodes();
62 bool pushUnconstrainedIGNodes();
64 IGNode * getIGNodeWithMinSpillCost();
66 void colorIGNode(IGNode *const Node);
71 RegClass(const Function *M,
72 const MachineRegClassInfo *MRC,
73 const ReservedColorListType *RCL = 0);
75 inline void createInterferenceGraph() { IG.createGraph(); }
77 inline InterferenceGraph &getIG() { return IG; }
79 inline const unsigned getID() const { return RegClassID; }
81 // main method called for coloring regs
85 inline unsigned getNumOfAvailRegs() const
86 { return MRC->getNumOfAvailRegs(); }
89 // --- following methods are provided to access the IG contained within this
90 // ---- RegClass easilly.
92 inline void addLRToIG(LiveRange *const LR)
95 inline void setInterference(const LiveRange *const LR1,
96 const LiveRange *const LR2)
97 { IG.setInterference(LR1, LR2); }
99 inline unsigned getInterference(const LiveRange *const LR1,
100 const LiveRange *const LR2) const
101 { return IG.getInterference(LR1, LR2); }
103 inline void mergeIGNodesOfLRs(const LiveRange *const LR1,
104 LiveRange *const LR2)
105 { IG.mergeIGNodesOfLRs(LR1, LR2); }
108 inline std::vector<bool> &getIsColorUsedArr() { return IsColorUsedArr; }
111 inline void printIGNodeList() const {
112 std::cerr << "IG Nodes for Register Class " << RegClassID << ":" << "\n";
113 IG.printIGNodeList();
116 inline void printIG() {
117 std::cerr << "IG for Register Class " << RegClassID << ":" << "\n";