1 /* Title: PhyRegAlloc.h
2 Author: Ruchira Sasanka
4 Purpose: This is the main entry point for register allocation.
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.
14 * Machine dependent work: All parts of the register coloring algorithm
15 except coloring of an individual node are machine independent.
17 Register allocation must be done as:
19 static const MachineRegInfo MRI = MachineRegInfo(); // machine reg info
21 MethodLiveVarInfo LVI(*MethodI ); // compute LV info
24 PhyRegAlloc PRA(*MethodI, &MRI, &LVI); // allocate regs
25 PRA.allocateRegisters();
28 All values in a live range will be of the same physical reg class.
34 #ifndef PHY_REG_ALLOC_H
35 #define PHY_REG_ALLOC_H
37 #include "llvm/CodeGen/MachineInstr.h"
38 #include "llvm/CodeGen/Sparc.h"
40 #include "llvm/CodeGen/RegClass.h"
41 #include "llvm/CodeGen/LiveRangeInfo.h"
42 #include "llvm/Analysis/LiveVar/MethodLiveVarInfo.h"
48 vector<const MachineInstr *> InstrnsBefore;
49 vector<const MachineInstr *> InstrnsAfter;
51 AddedInstrns() : InstrnsBefore(), InstrnsAfter() { }
54 typedef hash_map<const MachineInstr *, AddedInstrns *> AddedInstrMapType;
61 vector<RegClass *> RegClassList ; // vector of register classes
62 const Method *const Meth; // name of the method we work on
63 const TargetMachine &TM; // target machine
64 MethodLiveVarInfo *const LVI; // LV information for this method
65 // (already computed for BBs)
66 LiveRangeInfo LRI; // LR info (will be computed)
67 const MachineRegInfo &MRI; // Machine Register information
68 const unsigned NumOfRegClasses; // recorded here for efficiency
70 vector<const Instruction *> CallInstrList; // a list of all call instrs
72 AddedInstrMapType AddedInstrMap; // to store instrns added in this phase
75 //------- private methods ---------------------------------------------------
77 void addInterference(const Value *const Def, const LiveVarSet *const LVSet,
78 const bool isCallInst);
80 void addInterferencesForArgs();
81 void createIGNodeListsAndIGs();
82 void buildInterferenceGraphs();
84 inline void constructLiveRanges()
85 { LRI.constructLiveRanges(); }
87 void colorIncomingArgs();
88 void updateMachineCode();
91 PhyRegAlloc(const Method *const M, const TargetMachine& TM,
92 MethodLiveVarInfo *const Lvi);
94 void allocateRegisters(); // main method called for allocatin