blob: 1d08502445dca865bb82423345d4fbdc9ebd5959 [file] [log] [blame]
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +00001/* Title: RegClass.h
2 Author: Ruchira Sasanka
3 Date: Aug 20, 01
4 Purpose: Contains machine independent methods for register coloring.
5
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.
11
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.
16
17*/
18
19
20
21#ifndef REG_CLASS_H
22#define REG_CLASS_H
23
24#include "llvm/CodeGen/IGNode.h"
25#include "llvm/CodeGen/InterferenceGraph.h"
26#include "llvm/CodeGen/TargetMachine.h"
27
28
29#include <stack>
30
31
32typedef vector<unsigned int> ReservedColorListType;
33
34
35class RegClass
36{
37
38 private:
39 const Method *const Meth; // Method we are working on
40
41 const MachineRegClassInfo *const MRC; // corresponding MRC
42
43 const unsigned RegClassID; // my int ID
44
45 InterferenceGraph IG; // Interference graph - constructed by
46 // buildInterferenceGraph
47 stack <IGNode *> IGNodeStack; // the stack used for coloring
48
49 // for passing registered that are pre-allocated (e.g., %g's)
50 const ReservedColorListType *const ReservedColorList;
51
52 // An array used for coloring each node. This array must be of size
53 // MRC->getNumOfAllRegs(). Allocated once in the constructor
54 // for efficiency.
55 bool *IsColorUsedArr;
56
57
58 //------------ private methods ------------------
59
60 void pushAllIGNodes();
61 bool pushUnconstrainedIGNodes();
62 IGNode * getIGNodeWithMinSpillCost();
63 void colorIGNode(IGNode *const Node);
64
65 public:
66
67 RegClass(const Method *const M,
68 const MachineRegClassInfo *const MRC,
69 const ReservedColorListType *const RCL = NULL);
70
71 inline void createInterferenceGraph()
72 { IG.createGraph(); }
73
74 inline InterferenceGraph &getIG() { return IG; }
75
76 inline const unsigned getID() const { return RegClassID; }
77
78 void colorAllRegs(); // main method called for coloring regs
79
80 inline unsigned getNumOfAvailRegs() const
81 { return MRC->getNumOfAvailRegs(); }
82
83 ~RegClass() { delete[] IsColorUsedArr; };
84
85
86
87 // --- following methods are provided to access the IG contained within this
88 // ---- RegClass easilly.
89
90
91 inline void addLRToIG(LiveRange *const LR)
92 { IG.addLRToIG(LR); }
93
94 inline void setInterference(const LiveRange *const LR1,
95 const LiveRange *const LR2)
96 { IG.setInterference(LR1, LR2); }
97
98 inline unsigned getInterference(const LiveRange *const LR1,
99 const LiveRange *const LR2) const
100 { return IG.getInterference(LR1, LR2); }
101
102 inline void mergeIGNodesOfLRs(const LiveRange *const LR1,
103 LiveRange *const LR2)
104 { IG.mergeIGNodesOfLRs(LR1, LR2); }
105
106
107 inline void printIGNodeList() const {
108 cout << "IG Nodes for Register Class " << RegClassID << ":" << endl;
109 IG.printIGNodeList();
110 }
111
112 inline void printIG() {
113 cout << "IG for Register Class " << RegClassID << ":" << endl;
114 IG.printIG();
115 }
116
117};
118
119
120
121
122
123
124
125#endif