blob: fcf28320cc70758a58afe70dab2b1a4618ef4726 [file] [log] [blame]
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +00001/* Title: PhyRegAlloc.h
2 Author: Ruchira Sasanka
3 Date: Aug 20, 01
4 Purpose: This is the main entry point for register allocation.
5
6 Notes:
7
8 * RegisterClasses: Each RegClass accepts a
9 MachineRegClass which contains machine specific info about that register
10 class. The code in the RegClass is machine independent and they use
11 access functions in the MachineRegClass object passed into it to get
12 machine specific info.
13
14 * Machine dependent work: All parts of the register coloring algorithm
15 except coloring of an individual node are machine independent.
16
17 Register allocation must be done as:
18
19 static const MachineRegInfo MRI = MachineRegInfo(); // machine reg info
20
21 MethodLiveVarInfo LVI(*MethodI ); // compute LV info
22 LVI.analyze();
23
24 PhyRegAlloc PRA(*MethodI, &MRI, &LVI); // allocate regs
25 PRA.allocateRegisters();
26
27 Assumptions:
28 All values in a live range will be of the same physical reg class.
29
30*/
31
32
33
34#ifndef PHY_REG_ALLOC_H
35#define PHY_REG_ALLOC_H
36
37#include "llvm/CodeGen/MachineInstr.h"
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000038#include "llvm/CodeGen/RegClass.h"
39#include "llvm/CodeGen/LiveRangeInfo.h"
40#include "llvm/Analysis/LiveVar/MethodLiveVarInfo.h"
41
42
43class AddedInstrns
44{
45 public:
46 vector<const MachineInstr *> InstrnsBefore;
47 vector<const MachineInstr *> InstrnsAfter;
48
49 AddedInstrns() : InstrnsBefore(), InstrnsAfter() { }
50};
51
52typedef hash_map<const MachineInstr *, AddedInstrns *> AddedInstrMapType;
53
54
55
56class PhyRegAlloc
57{
58
59 vector<RegClass *> RegClassList ; // vector of register classes
60 const Method *const Meth; // name of the method we work on
61 const TargetMachine &TM; // target machine
62 MethodLiveVarInfo *const LVI; // LV information for this method
63 // (already computed for BBs)
64 LiveRangeInfo LRI; // LR info (will be computed)
65 const MachineRegInfo &MRI; // Machine Register information
66 const unsigned NumOfRegClasses; // recorded here for efficiency
67
68 vector<const Instruction *> CallInstrList; // a list of all call instrs
Ruchira Sasanka80acc6c2001-09-18 22:57:47 +000069 vector<const Instruction *> RetInstrList; // a list of all return instrs
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000070
71 AddedInstrMapType AddedInstrMap; // to store instrns added in this phase
72
73
Ruchira Sasanka1bf6d642001-09-15 00:33:26 +000074
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000075 //------- private methods ---------------------------------------------------
76
77 void addInterference(const Value *const Def, const LiveVarSet *const LVSet,
78 const bool isCallInst);
79
80 void addInterferencesForArgs();
81 void createIGNodeListsAndIGs();
82 void buildInterferenceGraphs();
83
84 inline void constructLiveRanges()
85 { LRI.constructLiveRanges(); }
86
87 void colorIncomingArgs();
88 void updateMachineCode();
Ruchira Sasanka6053b932001-09-15 19:08:41 +000089 void printLabel(const Value *const Val);
90 void printMachineCode();
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000091
92 public:
93 PhyRegAlloc(const Method *const M, const TargetMachine& TM,
94 MethodLiveVarInfo *const Lvi);
95
96 void allocateRegisters(); // main method called for allocatin
97
98};
99
100
101
102
103
104
105
106
107#endif
108