2001-09-18 12:38:31 +00:00
|
|
|
//===-- llvm/Target/RegInfo.h - Target Register Information ------*- C++ -*-==//
|
|
|
|
//
|
|
|
|
// This file is used to describe the register system of a target to the
|
|
|
|
// register allocator.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_TARGET_MACHINEREGINFO_H
|
|
|
|
#define LLVM_TARGET_MACHINEREGINFO_H
|
|
|
|
|
2001-11-27 00:03:19 +00:00
|
|
|
#include "Support/NonCopyable.h"
|
2002-01-20 22:54:45 +00:00
|
|
|
#include <ext/hash_map>
|
2001-09-18 12:38:31 +00:00
|
|
|
#include <string>
|
|
|
|
|
2001-11-08 05:22:43 +00:00
|
|
|
class TargetMachine;
|
2001-09-18 12:38:31 +00:00
|
|
|
class IGNode;
|
2002-03-18 03:18:28 +00:00
|
|
|
class Type;
|
2001-09-18 12:38:31 +00:00
|
|
|
class Value;
|
|
|
|
class LiveRangeInfo;
|
2002-03-23 22:51:58 +00:00
|
|
|
class Function;
|
2001-09-18 12:38:31 +00:00
|
|
|
class Instruction;
|
|
|
|
class LiveRange;
|
|
|
|
class AddedInstrns;
|
|
|
|
class MachineInstr;
|
2001-09-30 23:19:09 +00:00
|
|
|
class RegClass;
|
|
|
|
class CallInst;
|
|
|
|
class ReturnInst;
|
2001-10-28 18:14:15 +00:00
|
|
|
class PhyRegAlloc;
|
|
|
|
class BasicBlock;
|
2001-09-18 12:38:31 +00:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// class MachineRegClassInfo
|
|
|
|
//
|
|
|
|
// Purpose:
|
|
|
|
// Interface to description of machine register class (e.g., int reg class
|
|
|
|
// float reg class etc)
|
|
|
|
//
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
class MachineRegClassInfo {
|
|
|
|
protected:
|
|
|
|
const unsigned RegClassID; // integer ID of a reg class
|
|
|
|
const unsigned NumOfAvailRegs; // # of avail for coloring -without SP etc.
|
|
|
|
const unsigned NumOfAllRegs; // # of all registers -including SP,g0 etc.
|
|
|
|
|
|
|
|
public:
|
|
|
|
inline unsigned getRegClassID() const { return RegClassID; }
|
|
|
|
inline unsigned getNumOfAvailRegs() const { return NumOfAvailRegs; }
|
|
|
|
inline unsigned getNumOfAllRegs() const { return NumOfAllRegs; }
|
|
|
|
|
|
|
|
// This method should find a color which is not used by neighbors
|
|
|
|
// (i.e., a false position in IsColorUsedArr) and
|
2002-02-04 05:55:10 +00:00
|
|
|
virtual void colorIGNode(IGNode *Node, bool IsColorUsedArr[]) const = 0;
|
|
|
|
virtual bool isRegVolatile(int Reg) const = 0;
|
2001-09-18 12:38:31 +00:00
|
|
|
|
2002-02-04 05:55:10 +00:00
|
|
|
MachineRegClassInfo(unsigned ID, unsigned NVR, unsigned NAR)
|
|
|
|
: RegClassID(ID), NumOfAvailRegs(NVR), NumOfAllRegs(NAR) {}
|
2001-09-18 12:38:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// class MachineRegInfo
|
|
|
|
//
|
|
|
|
// Purpose:
|
|
|
|
// Interface to register info of target machine
|
|
|
|
//
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class MachineRegInfo : public NonCopyableV {
|
|
|
|
protected:
|
2002-02-04 05:55:10 +00:00
|
|
|
// A vector of all machine register classes
|
|
|
|
//
|
|
|
|
std::vector<const MachineRegClassInfo *> MachineRegClassArr;
|
2001-09-18 22:57:47 +00:00
|
|
|
|
2001-09-18 12:38:31 +00:00
|
|
|
public:
|
2002-02-04 05:55:10 +00:00
|
|
|
const TargetMachine ⌖
|
2001-09-18 12:38:31 +00:00
|
|
|
|
2002-01-07 19:57:37 +00:00
|
|
|
MachineRegInfo(const TargetMachine& tgt) : target(tgt) { }
|
2002-04-09 15:04:37 +00:00
|
|
|
~MachineRegInfo() {
|
|
|
|
for (unsigned i = 0, e = MachineRegClassArr.size(); i != e; ++i)
|
|
|
|
delete MachineRegClassArr[i];
|
|
|
|
}
|
2001-09-18 22:57:47 +00:00
|
|
|
|
2001-09-18 12:38:31 +00:00
|
|
|
// According the definition of a MachineOperand class, a Value in a
|
|
|
|
// machine instruction can go into either a normal register or a
|
|
|
|
// condition code register. If isCCReg is true below, the ID of the condition
|
|
|
|
// code regiter class will be returned. Otherwise, the normal register
|
|
|
|
// class (eg. int, float) must be returned.
|
2002-03-18 03:18:28 +00:00
|
|
|
virtual unsigned getRegClassIDOfType (const Type *type,
|
|
|
|
bool isCCReg = false) const =0;
|
2002-02-04 05:55:10 +00:00
|
|
|
virtual unsigned getRegClassIDOfValue (const Value *Val,
|
2001-09-18 12:38:31 +00:00
|
|
|
bool isCCReg = false) const =0;
|
2002-03-18 03:18:28 +00:00
|
|
|
|
2001-09-18 12:38:31 +00:00
|
|
|
|
|
|
|
inline unsigned int getNumOfRegClasses() const {
|
|
|
|
return MachineRegClassArr.size();
|
|
|
|
}
|
|
|
|
|
2002-02-04 05:55:10 +00:00
|
|
|
const MachineRegClassInfo *getMachineRegClass(unsigned i) const {
|
2001-09-18 12:38:31 +00:00
|
|
|
return MachineRegClassArr[i];
|
|
|
|
}
|
|
|
|
|
2001-09-18 22:57:47 +00:00
|
|
|
// returns the register that is hardwired to zero if any (-1 if none)
|
2002-01-07 19:57:37 +00:00
|
|
|
//
|
2002-02-04 05:55:10 +00:00
|
|
|
virtual int getZeroRegNum() const = 0;
|
2001-09-18 12:38:31 +00:00
|
|
|
|
|
|
|
|
2002-01-07 19:57:37 +00:00
|
|
|
// The following methods are used to color special live ranges (e.g.
|
|
|
|
// method args and return values etc.) with specific hardware registers
|
|
|
|
// as required. See SparcRegInfo.cpp for the implementation for Sparc.
|
|
|
|
//
|
2002-03-23 22:51:58 +00:00
|
|
|
virtual void suggestRegs4MethodArgs(const Function *Func,
|
2002-02-04 05:55:10 +00:00
|
|
|
LiveRangeInfo &LRI) const = 0;
|
2001-09-18 12:38:31 +00:00
|
|
|
|
2002-02-04 05:55:10 +00:00
|
|
|
virtual void suggestRegs4CallArgs(const MachineInstr *CallI,
|
|
|
|
LiveRangeInfo &LRI, std::vector<RegClass *> RCL) const = 0;
|
2001-09-18 12:38:31 +00:00
|
|
|
|
2002-02-04 05:55:10 +00:00
|
|
|
virtual void suggestReg4RetValue(const MachineInstr *RetI,
|
|
|
|
LiveRangeInfo &LRI) const = 0;
|
2001-09-18 22:57:47 +00:00
|
|
|
|
2002-03-23 22:51:58 +00:00
|
|
|
virtual void colorMethodArgs(const Function *Func, LiveRangeInfo &LRI,
|
2002-02-04 05:55:10 +00:00
|
|
|
AddedInstrns *FirstAI) const = 0;
|
2001-09-30 23:19:09 +00:00
|
|
|
|
2002-02-04 05:55:10 +00:00
|
|
|
virtual void colorCallArgs(const MachineInstr *CalI,
|
|
|
|
LiveRangeInfo& LRI, AddedInstrns *CallAI,
|
2002-01-07 19:17:41 +00:00
|
|
|
PhyRegAlloc &PRA, const BasicBlock *BB) const = 0;
|
2001-09-30 23:19:09 +00:00
|
|
|
|
2002-02-04 05:55:10 +00:00
|
|
|
virtual void colorRetValue(const MachineInstr *RetI, LiveRangeInfo &LRI,
|
|
|
|
AddedInstrns *RetAI) const = 0;
|
2001-09-30 23:19:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2002-01-07 19:57:37 +00:00
|
|
|
// The following methods are used to generate "copy" machine instructions
|
|
|
|
// for an architecture. Currently they are used in MachineRegClass
|
|
|
|
// interface. However, they can be moved to MachineInstrInfo interface if
|
|
|
|
// necessary.
|
|
|
|
//
|
2002-02-04 05:55:10 +00:00
|
|
|
virtual MachineInstr *cpReg2RegMI(unsigned SrcReg, unsigned DestReg,
|
|
|
|
int RegType) const = 0;
|
2001-10-16 01:23:19 +00:00
|
|
|
|
2002-02-04 05:55:10 +00:00
|
|
|
virtual MachineInstr *cpReg2MemMI(unsigned SrcReg, unsigned DestPtrReg,
|
|
|
|
int Offset, int RegType) const = 0;
|
2001-10-16 01:23:19 +00:00
|
|
|
|
2002-02-04 05:55:10 +00:00
|
|
|
virtual MachineInstr *cpMem2RegMI(unsigned SrcPtrReg, int Offset,
|
|
|
|
unsigned DestReg, int RegType) const = 0;
|
2001-10-16 01:23:19 +00:00
|
|
|
|
2002-02-04 05:55:10 +00:00
|
|
|
virtual MachineInstr *cpValue2Value(Value *Src, Value *Dest) const = 0;
|
2001-11-03 17:14:13 +00:00
|
|
|
|
2002-02-04 05:55:10 +00:00
|
|
|
virtual bool isRegVolatile(int RegClassID, int Reg) const = 0;
|
2001-10-16 01:23:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2001-09-30 23:19:09 +00:00
|
|
|
|
2002-01-07 19:57:37 +00:00
|
|
|
// Returns the reg used for pushing the address when a method is called.
|
2001-09-18 22:57:47 +00:00
|
|
|
// This can be used for other purposes between calls
|
2002-01-07 19:57:37 +00:00
|
|
|
//
|
2001-09-18 22:57:47 +00:00
|
|
|
virtual unsigned getCallAddressReg() const = 0;
|
|
|
|
|
2002-01-07 19:57:37 +00:00
|
|
|
// Returns the register containing the return address.
|
|
|
|
//It should be made sure that this
|
2001-09-18 22:57:47 +00:00
|
|
|
// register contains the return value when a return instruction is reached.
|
2002-01-07 19:57:37 +00:00
|
|
|
//
|
2001-09-18 22:57:47 +00:00
|
|
|
virtual unsigned getReturnAddressReg() const = 0;
|
|
|
|
|
2002-01-07 19:57:37 +00:00
|
|
|
|
|
|
|
// Each register class has a seperate space for register IDs. To convert
|
|
|
|
// a regId in a register class to a common Id, we use the folloing method(s)
|
|
|
|
//
|
2001-09-18 12:38:31 +00:00
|
|
|
virtual int getUnifiedRegNum(int RegClassID, int reg) const = 0;
|
|
|
|
|
2002-01-20 22:54:45 +00:00
|
|
|
virtual const std::string getUnifiedRegName(int UnifiedRegNum) const = 0;
|
2001-09-18 12:38:31 +00:00
|
|
|
|
2002-01-07 19:57:37 +00:00
|
|
|
|
|
|
|
// Gives the type of a register based on the type of the LR
|
|
|
|
//
|
2002-02-04 05:55:10 +00:00
|
|
|
virtual int getRegType(const LiveRange *LR) const = 0;
|
2001-10-16 01:23:19 +00:00
|
|
|
|
2002-03-31 18:58:49 +00:00
|
|
|
// To obtain the return value and the indirect call address (if any)
|
|
|
|
// contained in a CALL machine instruction
|
2002-01-07 19:57:37 +00:00
|
|
|
//
|
2002-02-04 05:55:10 +00:00
|
|
|
virtual const Value *getCallInstRetVal(const MachineInstr *CallMI) const = 0;
|
2002-03-31 18:58:49 +00:00
|
|
|
virtual const Value *getCallInstIndirectAddrVal(const MachineInstr *CallMI) const = 0;
|
2001-10-16 01:23:19 +00:00
|
|
|
|
2002-01-07 19:57:37 +00:00
|
|
|
// The following methods are used to get the frame/stack pointers
|
|
|
|
//
|
2002-02-04 05:55:10 +00:00
|
|
|
virtual unsigned getFramePointer() const = 0;
|
|
|
|
virtual unsigned getStackPointer() const = 0;
|
2001-10-16 01:23:19 +00:00
|
|
|
|
2002-01-07 19:57:37 +00:00
|
|
|
// A register can be initialized to an invalid number. That number can
|
|
|
|
// be obtained using this method.
|
|
|
|
//
|
2002-02-04 05:55:10 +00:00
|
|
|
virtual int getInvalidRegNum() const = 0;
|
2001-10-16 01:23:19 +00:00
|
|
|
|
|
|
|
|
2002-01-07 19:57:37 +00:00
|
|
|
// Method for inserting caller saving code. The caller must save all the
|
|
|
|
// volatile registers across a call based on the calling conventions of
|
|
|
|
// an architecture. This must insert code for saving and restoring
|
|
|
|
// such registers on
|
|
|
|
//
|
2001-10-28 18:14:15 +00:00
|
|
|
virtual void insertCallerSavingCode(const MachineInstr *MInst,
|
|
|
|
const BasicBlock *BB,
|
2002-02-04 05:55:10 +00:00
|
|
|
PhyRegAlloc &PRA) const = 0;
|
2001-10-28 18:14:15 +00:00
|
|
|
|
2002-01-07 19:57:37 +00:00
|
|
|
// This method gives the the number of bytes of stack spaceallocated
|
|
|
|
// to a register when it is spilled to the stack.
|
|
|
|
//
|
2002-02-04 05:55:10 +00:00
|
|
|
virtual int getSpilledRegSize(int RegType) const = 0;
|
2001-09-18 12:38:31 +00:00
|
|
|
};
|
|
|
|
|
2001-09-18 22:57:47 +00:00
|
|
|
#endif
|