blob: d6cbaf892bb8c5d8570482a1b4f01e4a4053be6d [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
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +00006*/
7
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +00008#ifndef REG_CLASS_H
9#define REG_CLASS_H
10
11#include "llvm/CodeGen/IGNode.h"
12#include "llvm/CodeGen/InterferenceGraph.h"
Vikram S. Adve4bc86972001-09-18 12:41:43 +000013#include "llvm/Target/TargetMachine.h"
14#include "llvm/Target/MachineRegInfo.h"
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000015#include <stack>
16
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000017typedef vector<unsigned int> ReservedColorListType;
18
19
Ruchira Sasanka42bd1772002-01-07 19:16:26 +000020//-----------------------------------------------------------------------------
21// Class RegClass
22//
23// Implements a machine independant register class.
24//
25// This is the class that contains all data structures and common algos
26// for coloring a particular register class (e.g., int class, fp class).
27// This class is hardware independent. This class accepts a hardware
28// dependent description of machine registers (MachineRegInfo class) to
29// get hardware specific info and to color an individual IG node.
30//
31// This class contains the InterferenceGraph (IG).
32// Also it contains an IGNode stack that can be used for coloring.
33// The class provides some easy access methods to the IG methods, since these
34// methods are called thru a register class.
35//
36//-----------------------------------------------------------------------------
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000037class RegClass
38{
39
40 private:
41 const Method *const Meth; // Method we are working on
42
43 const MachineRegClassInfo *const MRC; // corresponding MRC
44
45 const unsigned RegClassID; // my int ID
46
47 InterferenceGraph IG; // Interference graph - constructed by
48 // buildInterferenceGraph
49 stack <IGNode *> IGNodeStack; // the stack used for coloring
50
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000051 const ReservedColorListType *const ReservedColorList;
Ruchira Sasanka42bd1772002-01-07 19:16:26 +000052 //
53 // for passing registers that are pre-allocated and cannot be used by the
54 // register allocator for this method.
55
56 bool *IsColorUsedArr;
57 //
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000058 // An array used for coloring each node. This array must be of size
59 // MRC->getNumOfAllRegs(). Allocated once in the constructor
60 // for efficiency.
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000061
62
Ruchira Sasanka42bd1772002-01-07 19:16:26 +000063 //--------------------------- private methods ------------------------------
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000064
65 void pushAllIGNodes();
Ruchira Sasanka42bd1772002-01-07 19:16:26 +000066
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000067 bool pushUnconstrainedIGNodes();
Ruchira Sasanka42bd1772002-01-07 19:16:26 +000068
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000069 IGNode * getIGNodeWithMinSpillCost();
Ruchira Sasanka42bd1772002-01-07 19:16:26 +000070
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000071 void colorIGNode(IGNode *const Node);
72
Ruchira Sasanka42bd1772002-01-07 19:16:26 +000073
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000074 public:
75
76 RegClass(const Method *const M,
77 const MachineRegClassInfo *const MRC,
78 const ReservedColorListType *const RCL = NULL);
79
Ruchira Sasanka42bd1772002-01-07 19:16:26 +000080 ~RegClass() { delete[] IsColorUsedArr; };
81
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000082 inline void createInterferenceGraph()
83 { IG.createGraph(); }
84
85 inline InterferenceGraph &getIG() { return IG; }
86
87 inline const unsigned getID() const { return RegClassID; }
88
Ruchira Sasanka42bd1772002-01-07 19:16:26 +000089 // main method called for coloring regs
90 //
91 void colorAllRegs();
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000092
93 inline unsigned getNumOfAvailRegs() const
94 { return MRC->getNumOfAvailRegs(); }
95
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000096
97 // --- following methods are provided to access the IG contained within this
98 // ---- RegClass easilly.
99
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +0000100 inline void addLRToIG(LiveRange *const LR)
101 { IG.addLRToIG(LR); }
102
103 inline void setInterference(const LiveRange *const LR1,
104 const LiveRange *const LR2)
105 { IG.setInterference(LR1, LR2); }
106
107 inline unsigned getInterference(const LiveRange *const LR1,
108 const LiveRange *const LR2) const
109 { return IG.getInterference(LR1, LR2); }
110
111 inline void mergeIGNodesOfLRs(const LiveRange *const LR1,
112 LiveRange *const LR2)
113 { IG.mergeIGNodesOfLRs(LR1, LR2); }
114
115
Ruchira Sasanka20c82b12001-10-28 18:15:12 +0000116 inline bool * getIsColorUsedArr() { return IsColorUsedArr; }
117
118
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +0000119 inline void printIGNodeList() const {
Chris Lattner634b3522001-10-15 18:30:06 +0000120 cerr << "IG Nodes for Register Class " << RegClassID << ":" << endl;
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +0000121 IG.printIGNodeList();
122 }
123
124 inline void printIG() {
Chris Lattner634b3522001-10-15 18:30:06 +0000125 cerr << "IG for Register Class " << RegClassID << ":" << endl;
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +0000126 IG.printIG();
127 }
128
129};
130
131
132
133
134
135
136
137#endif