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