2002-01-20 23:54:45 +01:00
|
|
|
/* Title: PhyRegAlloc.h -*- C++ -*-
|
2001-09-08 16:22:50 +02:00
|
|
|
Author: Ruchira Sasanka
|
|
|
|
Date: Aug 20, 01
|
|
|
|
Purpose: This is the main entry point for register allocation.
|
|
|
|
|
|
|
|
Notes:
|
2002-01-07 20:16:26 +01:00
|
|
|
=====
|
2001-09-08 16:22:50 +02:00
|
|
|
|
|
|
|
* RegisterClasses: Each RegClass accepts a
|
|
|
|
MachineRegClass which contains machine specific info about that register
|
|
|
|
class. The code in the RegClass is machine independent and they use
|
|
|
|
access functions in the MachineRegClass object passed into it to get
|
|
|
|
machine specific info.
|
|
|
|
|
|
|
|
* Machine dependent work: All parts of the register coloring algorithm
|
|
|
|
except coloring of an individual node are machine independent.
|
|
|
|
|
2002-01-07 20:16:26 +01:00
|
|
|
Register allocation must be done as:
|
2001-09-08 16:22:50 +02:00
|
|
|
|
2002-01-07 20:16:26 +01:00
|
|
|
MethodLiveVarInfo LVI(*MethodI ); // compute LV info
|
|
|
|
LVI.analyze();
|
2001-09-08 16:22:50 +02:00
|
|
|
|
2002-01-07 20:16:26 +01:00
|
|
|
TargetMachine &target = ....
|
|
|
|
|
|
|
|
|
|
|
|
PhyRegAlloc PRA(*MethodI, target, &LVI); // allocate regs
|
|
|
|
PRA.allocateRegisters();
|
2001-09-08 16:22:50 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PHY_REG_ALLOC_H
|
|
|
|
#define PHY_REG_ALLOC_H
|
|
|
|
|
|
|
|
#include "llvm/CodeGen/RegClass.h"
|
|
|
|
#include "llvm/CodeGen/LiveRangeInfo.h"
|
2001-10-15 18:22:44 +02:00
|
|
|
#include <deque>
|
2002-02-03 08:13:04 +01:00
|
|
|
class MachineCodeForMethod;
|
2002-02-04 06:52:08 +01:00
|
|
|
class MachineRegInfo;
|
|
|
|
class MethodLiveVarInfo;
|
|
|
|
class MachineInstr;
|
2002-02-04 18:38:48 +01:00
|
|
|
namespace cfg { class LoopDepthCalculator; }
|
2001-10-28 19:15:12 +01:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// Class AddedInstrns:
|
|
|
|
// When register allocator inserts new instructions in to the existing
|
|
|
|
// instruction stream, it does NOT directly modify the instruction stream.
|
|
|
|
// Rather, it creates an object of AddedInstrns and stick it in the
|
|
|
|
// AddedInstrMap for an existing instruction. This class contains two vectors
|
|
|
|
// to store such instructions added before and after an existing instruction.
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2001-09-08 16:22:50 +02:00
|
|
|
class AddedInstrns
|
|
|
|
{
|
|
|
|
public:
|
2002-01-20 23:54:45 +01:00
|
|
|
std::deque<MachineInstr*> InstrnsBefore;// Added insts BEFORE an existing inst
|
|
|
|
std::deque<MachineInstr*> InstrnsAfter; // Added insts AFTER an existing inst
|
2001-09-08 16:22:50 +02:00
|
|
|
};
|
|
|
|
|
2002-01-20 23:54:45 +01:00
|
|
|
typedef std::hash_map<const MachineInstr *, AddedInstrns *> AddedInstrMapType;
|
2001-09-08 16:22:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2001-10-28 19:15:12 +01:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// class PhyRegAlloc:
|
|
|
|
// Main class the register allocator. Call allocateRegisters() to allocate
|
|
|
|
// registers for a Method.
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
2002-02-04 18:38:48 +01:00
|
|
|
class PhyRegAlloc: public NonCopyable {
|
2001-09-08 16:22:50 +02:00
|
|
|
|
2002-01-20 23:54:45 +01:00
|
|
|
std::vector<RegClass *> RegClassList; // vector of register classes
|
2001-09-08 16:22:50 +02:00
|
|
|
const TargetMachine &TM; // target machine
|
2001-11-08 05:48:50 +01:00
|
|
|
const Method* Meth; // name of the method we work on
|
2002-02-03 08:13:04 +01:00
|
|
|
MachineCodeForMethod &mcInfo; // descriptor for method's native code
|
2001-09-08 16:22:50 +02:00
|
|
|
MethodLiveVarInfo *const LVI; // LV information for this method
|
|
|
|
// (already computed for BBs)
|
|
|
|
LiveRangeInfo LRI; // LR info (will be computed)
|
|
|
|
const MachineRegInfo &MRI; // Machine Register information
|
|
|
|
const unsigned NumOfRegClasses; // recorded here for efficiency
|
|
|
|
|
2001-11-03 18:14:44 +01:00
|
|
|
|
2001-09-08 16:22:50 +02:00
|
|
|
AddedInstrMapType AddedInstrMap; // to store instrns added in this phase
|
2002-02-04 18:38:48 +01:00
|
|
|
cfg::LoopDepthCalculator *LoopDepthCalc; // to calculate loop depths
|
2002-01-07 20:16:26 +01:00
|
|
|
ReservedColorListType ResColList; // A set of reserved regs if desired.
|
|
|
|
// currently not used
|
2001-09-08 16:22:50 +02:00
|
|
|
|
2002-02-04 18:38:48 +01:00
|
|
|
public:
|
|
|
|
PhyRegAlloc(Method *M, const TargetMachine& TM, MethodLiveVarInfo *Lvi,
|
|
|
|
cfg::LoopDepthCalculator *LoopDepthCalc);
|
|
|
|
~PhyRegAlloc();
|
|
|
|
|
|
|
|
// main method called for allocating registers
|
|
|
|
//
|
|
|
|
void allocateRegisters();
|
|
|
|
private:
|
|
|
|
|
2001-11-03 18:14:44 +01:00
|
|
|
|
2002-01-07 20:16:26 +01:00
|
|
|
|
|
|
|
//------- ------------------ private methods---------------------------------
|
2001-09-08 16:22:50 +02:00
|
|
|
|
|
|
|
void addInterference(const Value *const Def, const LiveVarSet *const LVSet,
|
|
|
|
const bool isCallInst);
|
|
|
|
|
|
|
|
void addInterferencesForArgs();
|
|
|
|
void createIGNodeListsAndIGs();
|
|
|
|
void buildInterferenceGraphs();
|
2001-10-16 03:23:19 +02:00
|
|
|
|
2001-10-19 19:21:59 +02:00
|
|
|
void setCallInterferences(const MachineInstr *MInst,
|
|
|
|
const LiveVarSet *const LVSetAft );
|
2001-09-08 16:22:50 +02:00
|
|
|
|
2001-10-23 23:38:42 +02:00
|
|
|
void move2DelayedInstr(const MachineInstr *OrigMI,
|
|
|
|
const MachineInstr *DelayedMI );
|
|
|
|
|
2001-10-19 23:42:06 +02:00
|
|
|
void markUnusableSugColors();
|
2001-10-28 19:15:12 +01:00
|
|
|
void allocateStackSpace4SpilledLRs();
|
|
|
|
|
2001-11-08 21:55:05 +01:00
|
|
|
void insertCode4SpilledLR (const LiveRange *LR,
|
|
|
|
MachineInstr *MInst,
|
|
|
|
const BasicBlock *BB,
|
|
|
|
const unsigned OpNum);
|
2001-10-19 23:42:06 +02:00
|
|
|
|
2002-01-20 23:54:45 +01:00
|
|
|
inline void constructLiveRanges() { LRI.constructLiveRanges(); }
|
2001-09-08 16:22:50 +02:00
|
|
|
|
|
|
|
void colorIncomingArgs();
|
2001-10-01 01:19:57 +02:00
|
|
|
void colorCallRetArgs();
|
2001-09-08 16:22:50 +02:00
|
|
|
void updateMachineCode();
|
2001-10-01 01:19:57 +02:00
|
|
|
|
2001-09-15 21:08:41 +02:00
|
|
|
void printLabel(const Value *const Val);
|
|
|
|
void printMachineCode();
|
2001-10-28 19:15:12 +01:00
|
|
|
|
|
|
|
friend class UltraSparcRegInfo;
|
2001-11-03 21:41:22 +01:00
|
|
|
|
|
|
|
|
2001-11-15 21:22:37 +01:00
|
|
|
int getUsableUniRegAtMI(RegClass *RC, const int RegType,
|
|
|
|
const MachineInstr *MInst,
|
|
|
|
const LiveVarSet *LVSetBef, MachineInstr *MIBef,
|
|
|
|
MachineInstr *MIAft );
|
2001-11-03 21:41:22 +01:00
|
|
|
|
2001-11-15 21:22:37 +01:00
|
|
|
int getUnusedUniRegAtMI(RegClass *RC, const MachineInstr *MInst,
|
2001-11-03 21:41:22 +01:00
|
|
|
const LiveVarSet *LVSetBef);
|
|
|
|
|
2001-11-15 21:22:37 +01:00
|
|
|
void setRelRegsUsedByThisInst(RegClass *RC, const MachineInstr *MInst );
|
|
|
|
int getUniRegNotUsedByThisInst(RegClass *RC, const MachineInstr *MInst);
|
2001-10-28 19:15:12 +01:00
|
|
|
|
2001-11-14 16:37:13 +01:00
|
|
|
void addInterf4PseudoInstr(const MachineInstr *MInst);
|
2001-09-08 16:22:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|