2002-02-03 07:52:04 +00:00
|
|
|
//===-- SparcRegInfo.cpp - Sparc Target Register Information --------------===//
|
|
|
|
//
|
|
|
|
// This file contains implementation of Sparc specific helper methods
|
|
|
|
// used for register allocation.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2001-09-15 00:30:44 +00:00
|
|
|
#include "SparcInternals.h"
|
2002-02-04 05:59:25 +00:00
|
|
|
#include "SparcRegClassInfo.h"
|
|
|
|
#include "llvm/Target/Sparc.h"
|
2002-02-03 07:52:04 +00:00
|
|
|
#include "llvm/CodeGen/MachineCodeForMethod.h"
|
2001-09-18 22:52:44 +00:00
|
|
|
#include "llvm/CodeGen/PhyRegAlloc.h"
|
2002-05-19 15:25:51 +00:00
|
|
|
#include "llvm/CodeGen/InstrSelection.h"
|
2002-02-04 05:59:25 +00:00
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
2002-05-19 15:25:51 +00:00
|
|
|
#include "llvm/CodeGen/MachineInstrAnnot.h"
|
2002-04-29 17:42:12 +00:00
|
|
|
#include "llvm/CodeGen/RegAllocCommon.h"
|
2002-04-27 07:27:19 +00:00
|
|
|
#include "llvm/Analysis/LiveVar/FunctionLiveVarInfo.h"
|
2002-02-04 05:59:25 +00:00
|
|
|
#include "llvm/iTerminators.h"
|
|
|
|
#include "llvm/iOther.h"
|
2002-04-09 19:08:28 +00:00
|
|
|
#include "llvm/Function.h"
|
2002-01-07 19:20:28 +00:00
|
|
|
#include "llvm/DerivedTypes.h"
|
2002-01-20 22:54:45 +00:00
|
|
|
#include <iostream>
|
2002-04-25 04:42:21 +00:00
|
|
|
#include <values.h>
|
2002-01-20 22:54:45 +00:00
|
|
|
using std::cerr;
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2002-02-04 05:59:25 +00:00
|
|
|
UltraSparcRegInfo::UltraSparcRegInfo(const UltraSparc &tgt)
|
|
|
|
: MachineRegInfo(tgt), UltraSparcInfo(&tgt), NumOfIntArgRegs(6),
|
|
|
|
NumOfFloatArgRegs(32), InvalidRegNum(1000) {
|
|
|
|
|
|
|
|
MachineRegClassArr.push_back(new SparcIntRegClass(IntRegClassID));
|
|
|
|
MachineRegClassArr.push_back(new SparcFloatRegClass(FloatRegClassID));
|
|
|
|
MachineRegClassArr.push_back(new SparcIntCCRegClass(IntCCRegClassID));
|
|
|
|
MachineRegClassArr.push_back(new SparcFloatCCRegClass(FloatCCRegClassID));
|
|
|
|
|
|
|
|
assert(SparcFloatRegOrder::StartOfNonVolatileRegs == 32 &&
|
|
|
|
"32 Float regs are used for float arg passing");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-18 03:12:16 +00:00
|
|
|
// getZeroRegNum - returns the register that contains always zero.
|
|
|
|
// this is the unified register number
|
2002-02-04 05:59:25 +00:00
|
|
|
//
|
2002-03-18 03:12:16 +00:00
|
|
|
int UltraSparcRegInfo::getZeroRegNum() const {
|
|
|
|
return this->getUnifiedRegNum(UltraSparcRegInfo::IntRegClassID,
|
|
|
|
SparcIntRegOrder::g0);
|
|
|
|
}
|
2002-02-04 05:59:25 +00:00
|
|
|
|
|
|
|
// getCallAddressReg - returns the reg used for pushing the address when a
|
|
|
|
// method is called. This can be used for other purposes between calls
|
|
|
|
//
|
|
|
|
unsigned UltraSparcRegInfo::getCallAddressReg() const {
|
2002-03-18 03:12:16 +00:00
|
|
|
return this->getUnifiedRegNum(UltraSparcRegInfo::IntRegClassID,
|
|
|
|
SparcIntRegOrder::o7);
|
2002-02-04 05:59:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the register containing the return address.
|
|
|
|
// It should be made sure that this register contains the return
|
|
|
|
// value when a return instruction is reached.
|
|
|
|
//
|
|
|
|
unsigned UltraSparcRegInfo::getReturnAddressReg() const {
|
2002-03-18 03:12:16 +00:00
|
|
|
return this->getUnifiedRegNum(UltraSparcRegInfo::IntRegClassID,
|
|
|
|
SparcIntRegOrder::i7);
|
2002-02-04 05:59:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// given the unified register number, this gives the name
|
|
|
|
// for generating assembly code or debugging.
|
|
|
|
//
|
|
|
|
const std::string UltraSparcRegInfo::getUnifiedRegName(int reg) const {
|
|
|
|
if( reg < 32 )
|
|
|
|
return SparcIntRegOrder::getRegName(reg);
|
|
|
|
else if ( reg < (64 + 32) )
|
|
|
|
return SparcFloatRegOrder::getRegName( reg - 32);
|
|
|
|
else if( reg < (64+32+4) )
|
|
|
|
return SparcFloatCCRegOrder::getRegName( reg -32 - 64);
|
|
|
|
else if( reg < (64+32+4+2) ) // two names: %xcc and %ccr
|
|
|
|
return SparcIntCCRegOrder::getRegName( reg -32 - 64 - 4);
|
|
|
|
else if (reg== InvalidRegNum) //****** TODO: Remove */
|
|
|
|
return "<*NoReg*>";
|
|
|
|
else
|
|
|
|
assert(0 && "Invalid register number");
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2002-03-18 03:12:16 +00:00
|
|
|
// Get unified reg number for frame pointer
|
2002-02-04 05:59:25 +00:00
|
|
|
unsigned UltraSparcRegInfo::getFramePointer() const {
|
2002-03-18 03:12:16 +00:00
|
|
|
return this->getUnifiedRegNum(UltraSparcRegInfo::IntRegClassID,
|
|
|
|
SparcIntRegOrder::i6);
|
2002-02-04 05:59:25 +00:00
|
|
|
}
|
|
|
|
|
2002-03-18 03:12:16 +00:00
|
|
|
// Get unified reg number for stack pointer
|
2002-02-04 05:59:25 +00:00
|
|
|
unsigned UltraSparcRegInfo::getStackPointer() const {
|
2002-03-18 03:12:16 +00:00
|
|
|
return this->getUnifiedRegNum(UltraSparcRegInfo::IntRegClassID,
|
|
|
|
SparcIntRegOrder::o6);
|
2002-02-04 05:59:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-04-25 04:42:21 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// Finds whether a call is an indirect call
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
isVarArgsFunction(const Type *funcType) {
|
|
|
|
return cast<FunctionType>(cast<PointerType>(funcType)
|
|
|
|
->getElementType())->isVarArg();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
isVarArgsCall(const MachineInstr *CallMI) {
|
|
|
|
Value* callee = CallMI->getOperand(0).getVRegValue();
|
|
|
|
// const Type* funcType = isa<Function>(callee)? callee->getType()
|
|
|
|
// : cast<PointerType>(callee->getType())->getElementType();
|
|
|
|
const Type* funcType = callee->getType();
|
|
|
|
return isVarArgsFunction(funcType);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Get the register number for the specified integer arg#,
|
|
|
|
// assuming there are argNum total args, intArgNum int args,
|
|
|
|
// and fpArgNum FP args preceding (and not including) this one.
|
|
|
|
// Use INT regs for FP args if this is a varargs call.
|
|
|
|
//
|
|
|
|
// Return value:
|
|
|
|
// InvalidRegNum, if there is no int register available for the arg.
|
|
|
|
// regNum, otherwise (this is NOT the unified reg. num).
|
|
|
|
//
|
|
|
|
inline int
|
|
|
|
UltraSparcRegInfo::regNumForIntArg(bool inCallee, bool isVarArgsCall,
|
|
|
|
unsigned argNo,
|
|
|
|
unsigned intArgNo, unsigned fpArgNo,
|
|
|
|
unsigned& regClassId) const
|
|
|
|
{
|
2002-05-19 15:25:51 +00:00
|
|
|
regClassId = IntRegClassID;
|
2002-04-25 04:42:21 +00:00
|
|
|
if (argNo >= NumOfIntArgRegs)
|
|
|
|
return InvalidRegNum;
|
2002-05-19 15:25:51 +00:00
|
|
|
else
|
|
|
|
return argNo + (inCallee? SparcIntRegOrder::i0 : SparcIntRegOrder::o0);
|
2002-04-25 04:42:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get the register number for the specified FP arg#,
|
|
|
|
// assuming there are argNum total args, intArgNum int args,
|
|
|
|
// and fpArgNum FP args preceding (and not including) this one.
|
|
|
|
// Use INT regs for FP args if this is a varargs call.
|
|
|
|
//
|
|
|
|
// Return value:
|
|
|
|
// InvalidRegNum, if there is no int register available for the arg.
|
|
|
|
// regNum, otherwise (this is NOT the unified reg. num).
|
|
|
|
//
|
|
|
|
inline int
|
|
|
|
UltraSparcRegInfo::regNumForFPArg(unsigned regType,
|
|
|
|
bool inCallee, bool isVarArgsCall,
|
|
|
|
unsigned argNo,
|
|
|
|
unsigned intArgNo, unsigned fpArgNo,
|
|
|
|
unsigned& regClassId) const
|
|
|
|
{
|
2002-05-19 15:25:51 +00:00
|
|
|
if (isVarArgsCall)
|
|
|
|
return regNumForIntArg(inCallee, isVarArgsCall, argNo, intArgNo, fpArgNo,
|
|
|
|
regClassId);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
regClassId = FloatRegClassID;
|
|
|
|
if (regType == FPSingleRegType)
|
|
|
|
return (argNo*2+1 >= NumOfFloatArgRegs)?
|
|
|
|
InvalidRegNum : SparcFloatRegOrder::f0 + (argNo * 2 + 1);
|
|
|
|
else if (regType == FPDoubleRegType)
|
|
|
|
return (argNo*2 >= NumOfFloatArgRegs)?
|
|
|
|
InvalidRegNum : SparcFloatRegOrder::f0 + (argNo * 2);
|
|
|
|
else
|
|
|
|
assert(0 && "Illegal FP register type");
|
|
|
|
}
|
2002-03-31 19:04:50 +00:00
|
|
|
}
|
|
|
|
|
2002-01-07 19:20:28 +00:00
|
|
|
|
2001-10-21 16:43:41 +00:00
|
|
|
//---------------------------------------------------------------------------
|
2002-01-07 19:20:28 +00:00
|
|
|
// Finds the return address of a call sparc specific call instruction
|
2001-10-21 16:43:41 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
// The following 4 methods are used to find the RegType (see enum above)
|
|
|
|
// of a LiveRange, a Value, and for a given register unified reg number.
|
2002-02-04 05:59:25 +00:00
|
|
|
//
|
2002-05-19 15:25:51 +00:00
|
|
|
int UltraSparcRegInfo::getRegType(unsigned regClassID,
|
|
|
|
const Type* type) const {
|
|
|
|
switch (regClassID) {
|
2002-02-04 05:59:25 +00:00
|
|
|
case IntRegClassID: return IntRegType;
|
2002-02-05 03:52:29 +00:00
|
|
|
case FloatRegClassID: {
|
2002-05-19 15:25:51 +00:00
|
|
|
if (type == Type::FloatTy)
|
2002-02-04 05:59:25 +00:00
|
|
|
return FPSingleRegType;
|
2002-05-19 15:25:51 +00:00
|
|
|
else if (type == Type::DoubleTy)
|
2002-02-04 05:59:25 +00:00
|
|
|
return FPDoubleRegType;
|
|
|
|
assert(0 && "Unknown type in FloatRegClass");
|
2002-02-05 03:52:29 +00:00
|
|
|
}
|
2002-05-19 15:25:51 +00:00
|
|
|
case IntCCRegClassID: return IntCCRegType;
|
2002-02-04 05:59:25 +00:00
|
|
|
case FloatCCRegClassID: return FloatCCRegType;
|
2002-05-19 15:25:51 +00:00
|
|
|
default: assert( 0 && "Unknown reg class ID"); return 0;
|
2001-10-21 16:43:41 +00:00
|
|
|
}
|
2002-02-04 05:59:25 +00:00
|
|
|
}
|
2001-10-21 16:43:41 +00:00
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
int UltraSparcRegInfo::getRegType(const LiveRange *LR) const {
|
|
|
|
return getRegType(LR->getRegClass()->getID(), LR->getType());
|
|
|
|
}
|
|
|
|
|
2002-02-04 05:59:25 +00:00
|
|
|
int UltraSparcRegInfo::getRegType(const Value *Val) const {
|
2002-05-19 15:25:51 +00:00
|
|
|
return getRegType(getRegClassIDOfValue(Val), Val->getType());
|
2002-02-04 05:59:25 +00:00
|
|
|
}
|
2001-10-21 16:43:41 +00:00
|
|
|
|
2002-02-04 05:59:25 +00:00
|
|
|
int UltraSparcRegInfo::getRegType(int reg) const {
|
|
|
|
if (reg < 32)
|
|
|
|
return IntRegType;
|
|
|
|
else if (reg < (32 + 32))
|
|
|
|
return FPSingleRegType;
|
|
|
|
else if (reg < (64 + 32))
|
|
|
|
return FPDoubleRegType;
|
|
|
|
else if (reg < (64+32+4))
|
|
|
|
return FloatCCRegType;
|
|
|
|
else if (reg < (64+32+4+2))
|
|
|
|
return IntCCRegType;
|
|
|
|
else
|
|
|
|
assert(0 && "Invalid register number in getRegType");
|
2002-02-24 23:02:40 +00:00
|
|
|
return 0;
|
2001-10-21 16:43:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-01-07 19:20:28 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// Suggests a register for the ret address in the RET machine instruction.
|
|
|
|
// We always suggest %i7 by convention.
|
|
|
|
//---------------------------------------------------------------------------
|
2002-02-04 05:59:25 +00:00
|
|
|
void UltraSparcRegInfo::suggestReg4RetAddr(const MachineInstr *RetMI,
|
2001-10-15 16:25:28 +00:00
|
|
|
LiveRangeInfo& LRI) const {
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2001-10-22 13:41:12 +00:00
|
|
|
assert( (RetMI->getNumOperands() >= 2)
|
|
|
|
&& "JMPL/RETURN must have 3 and 2 operands respectively");
|
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
MachineOperand & MO = ( MachineOperand &) RetMI->getOperand(0);
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2002-01-07 19:20:28 +00:00
|
|
|
// return address is always mapped to i7
|
|
|
|
//
|
2001-10-15 16:25:28 +00:00
|
|
|
MO.setRegForValue( getUnifiedRegNum( IntRegClassID, SparcIntRegOrder::i7) );
|
2001-10-22 13:41:12 +00:00
|
|
|
|
2002-01-07 19:20:28 +00:00
|
|
|
// Possible Optimization:
|
2001-10-16 01:23:19 +00:00
|
|
|
// Instead of setting the color, we can suggest one. In that case,
|
2001-10-15 16:25:28 +00:00
|
|
|
// we have to test later whether it received the suggested color.
|
|
|
|
// In that case, a LR has to be created at the start of method.
|
|
|
|
// It has to be done as follows (remove the setRegVal above):
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2002-01-07 19:20:28 +00:00
|
|
|
// const Value *RetAddrVal = MO.getVRegValue();
|
|
|
|
// assert( RetAddrVal && "LR for ret address must be created at start");
|
|
|
|
// LiveRange * RetAddrLR = LRI.getLiveRangeForValue( RetAddrVal);
|
|
|
|
// RetAddrLR->setSuggestedColor(getUnifiedRegNum( IntRegClassID,
|
|
|
|
// SparcIntRegOrdr::i7) );
|
2001-09-30 23:16:47 +00:00
|
|
|
}
|
2001-09-14 03:47:57 +00:00
|
|
|
|
|
|
|
|
2001-09-18 22:52:44 +00:00
|
|
|
//---------------------------------------------------------------------------
|
2002-01-07 19:20:28 +00:00
|
|
|
// Suggests a register for the ret address in the JMPL/CALL machine instr.
|
|
|
|
// Sparc ABI dictates that %o7 be used for this purpose.
|
2001-09-18 22:52:44 +00:00
|
|
|
//---------------------------------------------------------------------------
|
2001-10-21 16:43:41 +00:00
|
|
|
void UltraSparcRegInfo::suggestReg4CallAddr(const MachineInstr * CallMI,
|
|
|
|
LiveRangeInfo& LRI,
|
2002-01-20 22:54:45 +00:00
|
|
|
std::vector<RegClass *> RCList) const {
|
2002-05-19 15:25:51 +00:00
|
|
|
CallArgsDescriptor* argDesc = CallArgsDescriptor::get(CallMI);
|
|
|
|
const Value *RetAddrVal = argDesc->getReturnAddrReg();
|
|
|
|
assert(RetAddrVal && "Return address value is required");
|
2001-10-21 16:43:41 +00:00
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
// create a new LR for the return address and color it
|
2001-10-21 16:43:41 +00:00
|
|
|
LiveRange * RetAddrLR = new LiveRange();
|
2002-02-04 16:37:09 +00:00
|
|
|
RetAddrLR->insert( RetAddrVal );
|
2001-10-21 16:43:41 +00:00
|
|
|
unsigned RegClassID = getRegClassIDOfValue( RetAddrVal );
|
|
|
|
RetAddrLR->setRegClass( RCList[RegClassID] );
|
|
|
|
RetAddrLR->setColor(getUnifiedRegNum(IntRegClassID,SparcIntRegOrder::o7));
|
|
|
|
LRI.addLRToMap( RetAddrVal, RetAddrLR);
|
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
}
|
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
|
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// This method will suggest colors to incoming args to a method.
|
2002-01-07 19:20:28 +00:00
|
|
|
// According to the Sparc ABI, the first 6 incoming args are in
|
|
|
|
// %i0 - %i5 (if they are integer) OR in %f0 - %f31 (if they are float).
|
2001-09-30 23:16:47 +00:00
|
|
|
// If the arg is passed on stack due to the lack of regs, NOTHING will be
|
2002-01-07 19:20:28 +00:00
|
|
|
// done - it will be colored (or spilled) as a normal live range.
|
2001-09-30 23:16:47 +00:00
|
|
|
//---------------------------------------------------------------------------
|
2002-04-08 22:03:57 +00:00
|
|
|
void UltraSparcRegInfo::suggestRegs4MethodArgs(const Function *Meth,
|
2001-09-30 23:16:47 +00:00
|
|
|
LiveRangeInfo& LRI) const
|
2001-09-18 22:52:44 +00:00
|
|
|
{
|
2002-04-25 04:42:21 +00:00
|
|
|
// check if this is a varArgs function. needed for choosing regs.
|
|
|
|
bool isVarArgs = isVarArgsFunction(Meth->getType());
|
|
|
|
|
|
|
|
// get the argument list
|
2002-04-08 22:03:57 +00:00
|
|
|
const Function::ArgumentListType& ArgList = Meth->getArgumentList();
|
2002-04-25 04:42:21 +00:00
|
|
|
|
|
|
|
// for each argument. count INT and FP arguments separately.
|
|
|
|
for( unsigned argNo=0, intArgNo=0, fpArgNo=0;
|
|
|
|
argNo != ArgList.size(); ++argNo)
|
|
|
|
{
|
|
|
|
// get the LR of arg
|
|
|
|
LiveRange *LR = LRI.getLiveRangeForValue((const Value *)ArgList[argNo]);
|
|
|
|
assert( LR && "No live range found for method arg");
|
|
|
|
|
|
|
|
unsigned regType = getRegType( LR );
|
|
|
|
unsigned regClassIDOfArgReg = MAXINT; // reg class of chosen reg (unused)
|
|
|
|
|
|
|
|
int regNum = (regType == IntRegType)
|
2002-05-19 15:25:51 +00:00
|
|
|
? regNumForIntArg(/*inCallee*/ true, isVarArgs,
|
|
|
|
argNo, intArgNo++, fpArgNo, regClassIDOfArgReg)
|
|
|
|
: regNumForFPArg(regType, /*inCallee*/ true, isVarArgs,
|
|
|
|
argNo, intArgNo, fpArgNo++, regClassIDOfArgReg);
|
2002-04-25 04:42:21 +00:00
|
|
|
|
|
|
|
if(regNum != InvalidRegNum)
|
|
|
|
LR->setSuggestedColor(regNum);
|
2001-09-14 03:47:57 +00:00
|
|
|
}
|
2001-09-30 23:16:47 +00:00
|
|
|
}
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2002-01-07 19:20:28 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
//---------------------------------------------------------------------------
|
2002-01-07 19:20:28 +00:00
|
|
|
// This method is called after graph coloring to move incoming args to
|
|
|
|
// the correct hardware registers if they did not receive the correct
|
|
|
|
// (suggested) color through graph coloring.
|
2001-09-30 23:16:47 +00:00
|
|
|
//---------------------------------------------------------------------------
|
2002-04-08 22:03:57 +00:00
|
|
|
void UltraSparcRegInfo::colorMethodArgs(const Function *Meth,
|
2002-02-04 05:59:25 +00:00
|
|
|
LiveRangeInfo &LRI,
|
|
|
|
AddedInstrns *FirstAI) const {
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2002-04-25 04:42:21 +00:00
|
|
|
// check if this is a varArgs function. needed for choosing regs.
|
|
|
|
bool isVarArgs = isVarArgsFunction(Meth->getType());
|
2001-09-30 23:16:47 +00:00
|
|
|
// get the argument list
|
2002-04-08 22:03:57 +00:00
|
|
|
const Function::ArgumentListType& ArgList = Meth->getArgumentList();
|
2001-09-30 23:16:47 +00:00
|
|
|
// get an iterator to arg list
|
|
|
|
MachineInstr *AdMI;
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
// for each argument
|
2002-04-25 04:42:21 +00:00
|
|
|
for( unsigned argNo=0, intArgNo=0, fpArgNo=0;
|
|
|
|
argNo != ArgList.size(); ++argNo) {
|
2001-09-30 23:16:47 +00:00
|
|
|
// get the LR of arg
|
2002-04-09 19:46:27 +00:00
|
|
|
LiveRange *LR = LRI.getLiveRangeForValue((Value*)ArgList[argNo]);
|
2001-09-30 23:16:47 +00:00
|
|
|
assert( LR && "No live range found for method arg");
|
|
|
|
|
2002-04-25 04:42:21 +00:00
|
|
|
unsigned regType = getRegType( LR );
|
2001-09-30 23:16:47 +00:00
|
|
|
unsigned RegClassID = (LR->getRegClass())->getID();
|
2002-04-25 04:42:21 +00:00
|
|
|
|
2002-01-07 19:20:28 +00:00
|
|
|
// Find whether this argument is coming in a register (if not, on stack)
|
2002-04-25 04:42:21 +00:00
|
|
|
// Also find the correct register the argument must use (UniArgReg)
|
2002-01-07 19:20:28 +00:00
|
|
|
//
|
2001-09-30 23:16:47 +00:00
|
|
|
bool isArgInReg = false;
|
2002-01-07 19:20:28 +00:00
|
|
|
unsigned UniArgReg = InvalidRegNum; // reg that LR MUST be colored with
|
2002-04-25 04:42:21 +00:00
|
|
|
unsigned regClassIDOfArgReg = MAXINT; // reg class of chosen reg
|
|
|
|
|
|
|
|
int regNum = (regType == IntRegType)
|
2002-05-19 15:25:51 +00:00
|
|
|
? regNumForIntArg(/*inCallee*/ true, isVarArgs,
|
|
|
|
argNo, intArgNo++, fpArgNo, regClassIDOfArgReg)
|
|
|
|
: regNumForFPArg(regType, /*inCallee*/ true, isVarArgs,
|
|
|
|
argNo, intArgNo, fpArgNo++, regClassIDOfArgReg);
|
2002-04-25 04:42:21 +00:00
|
|
|
|
|
|
|
if(regNum != InvalidRegNum) {
|
2001-09-30 23:16:47 +00:00
|
|
|
isArgInReg = true;
|
2002-04-25 04:42:21 +00:00
|
|
|
UniArgReg = getUnifiedRegNum( regClassIDOfArgReg, regNum);
|
2001-09-30 23:16:47 +00:00
|
|
|
}
|
|
|
|
|
2002-01-07 19:20:28 +00:00
|
|
|
if( LR->hasColor() ) { // if this arg received a register
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2001-10-24 15:56:58 +00:00
|
|
|
unsigned UniLRReg = getUnifiedRegNum( RegClassID, LR->getColor() );
|
|
|
|
|
|
|
|
// if LR received the correct color, nothing to do
|
2002-01-07 19:20:28 +00:00
|
|
|
//
|
2001-10-24 15:56:58 +00:00
|
|
|
if( UniLRReg == UniArgReg )
|
|
|
|
continue;
|
|
|
|
|
2002-01-07 19:20:28 +00:00
|
|
|
// We are here because the LR did not receive the suggested
|
|
|
|
// but LR received another register.
|
|
|
|
// Now we have to copy the %i reg (or stack pos of arg)
|
|
|
|
// to the register the LR was colored with.
|
2001-10-24 15:56:58 +00:00
|
|
|
|
2002-01-07 19:20:28 +00:00
|
|
|
// if the arg is coming in UniArgReg register, it MUST go into
|
2001-10-24 15:56:58 +00:00
|
|
|
// the UniLRReg register
|
2002-01-07 19:20:28 +00:00
|
|
|
//
|
2002-04-25 04:42:21 +00:00
|
|
|
if( isArgInReg ) {
|
|
|
|
if( regClassIDOfArgReg != RegClassID ) {
|
2002-05-19 15:25:51 +00:00
|
|
|
assert(0 && "This could should work but it is not tested yet");
|
2002-04-25 04:42:21 +00:00
|
|
|
|
|
|
|
// It is a variable argument call: the float reg must go in a %o reg.
|
|
|
|
// We have to move an int reg to a float reg via memory.
|
|
|
|
//
|
|
|
|
assert(isVarArgs &&
|
|
|
|
RegClassID == FloatRegClassID &&
|
|
|
|
regClassIDOfArgReg == IntRegClassID &&
|
|
|
|
"This should only be an Int register for an FP argument");
|
|
|
|
|
|
|
|
int TmpOff = MachineCodeForMethod::get(Meth).pushTempValue(target,
|
|
|
|
getSpilledRegSize(regType));
|
2002-05-19 15:25:51 +00:00
|
|
|
cpReg2MemMI(UniArgReg, getFramePointer(), TmpOff, IntRegType,
|
|
|
|
FirstAI->InstrnsBefore);
|
2002-04-25 04:42:21 +00:00
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
cpMem2RegMI(getFramePointer(), TmpOff, UniLRReg, regType,
|
|
|
|
FirstAI->InstrnsBefore);
|
2002-04-25 04:42:21 +00:00
|
|
|
}
|
|
|
|
else {
|
2002-05-19 15:25:51 +00:00
|
|
|
cpReg2RegMI(UniArgReg, UniLRReg, regType, FirstAI->InstrnsBefore);
|
2002-04-25 04:42:21 +00:00
|
|
|
}
|
|
|
|
}
|
2001-10-28 18:15:12 +00:00
|
|
|
else {
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2001-10-28 18:15:12 +00:00
|
|
|
// Now the arg is coming on stack. Since the LR recieved a register,
|
|
|
|
// we just have to load the arg on stack into that register
|
2002-01-07 19:20:28 +00:00
|
|
|
//
|
2001-11-08 04:56:41 +00:00
|
|
|
const MachineFrameInfo& frameInfo = target.getFrameInfo();
|
|
|
|
int offsetFromFP =
|
2002-04-25 04:42:21 +00:00
|
|
|
frameInfo.getIncomingArgOffset(MachineCodeForMethod::get(Meth),
|
|
|
|
argNo);
|
2001-11-08 04:56:41 +00:00
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
cpMem2RegMI(getFramePointer(), offsetFromFP, UniLRReg, regType,
|
|
|
|
FirstAI->InstrnsBefore);
|
2001-10-28 18:15:12 +00:00
|
|
|
}
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2001-10-28 18:15:12 +00:00
|
|
|
} // if LR received a color
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
// Now, the LR did not receive a color. But it has a stack offset for
|
|
|
|
// spilling.
|
|
|
|
// So, if the arg is coming in UniArgReg register, we can just move
|
|
|
|
// that on to the stack pos of LR
|
|
|
|
|
|
|
|
if( isArgInReg ) {
|
2002-04-25 04:42:21 +00:00
|
|
|
|
|
|
|
if( regClassIDOfArgReg != RegClassID ) {
|
|
|
|
assert(0 &&
|
|
|
|
"FP arguments to a varargs function should be explicitly "
|
|
|
|
"copied to/from int registers by instruction selection!");
|
|
|
|
|
|
|
|
// It must be a float arg for a variable argument call, which
|
|
|
|
// must come in a %o reg. Move the int reg to the stack.
|
|
|
|
//
|
|
|
|
assert(isVarArgs && regClassIDOfArgReg == IntRegClassID &&
|
|
|
|
"This should only be an Int register for an FP argument");
|
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
cpReg2MemMI(UniArgReg, getFramePointer(), LR->getSpillOffFromFP(),
|
|
|
|
IntRegType, FirstAI->InstrnsBefore);
|
2002-04-25 04:42:21 +00:00
|
|
|
}
|
|
|
|
else {
|
2002-05-19 15:25:51 +00:00
|
|
|
cpReg2MemMI(UniArgReg, getFramePointer(), LR->getSpillOffFromFP(),
|
|
|
|
regType, FirstAI->InstrnsBefore);
|
2002-04-25 04:42:21 +00:00
|
|
|
}
|
2001-10-28 18:15:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
// Now the arg is coming on stack. Since the LR did NOT
|
|
|
|
// recieved a register as well, it is allocated a stack position. We
|
2002-04-25 04:42:21 +00:00
|
|
|
// can simply change the stack position of the LR. We can do this,
|
2001-10-28 18:15:12 +00:00
|
|
|
// since this method is called before any other method that makes
|
|
|
|
// uses of the stack pos of the LR (e.g., updateMachineInstr)
|
|
|
|
|
2001-11-08 04:56:41 +00:00
|
|
|
const MachineFrameInfo& frameInfo = target.getFrameInfo();
|
|
|
|
int offsetFromFP =
|
2002-04-25 04:42:21 +00:00
|
|
|
frameInfo.getIncomingArgOffset(MachineCodeForMethod::get(Meth),
|
|
|
|
argNo);
|
2001-11-08 04:56:41 +00:00
|
|
|
|
|
|
|
LR->modifySpillOffFromFP( offsetFromFP );
|
2001-10-28 18:15:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
} // for each incoming argument
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
}
|
2001-09-14 03:47:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// This method is called before graph coloring to suggest colors to the
|
|
|
|
// outgoing call args and the return value of the call.
|
|
|
|
//---------------------------------------------------------------------------
|
2002-02-04 05:59:25 +00:00
|
|
|
void UltraSparcRegInfo::suggestRegs4CallArgs(const MachineInstr *CallMI,
|
2001-09-30 23:16:47 +00:00
|
|
|
LiveRangeInfo& LRI,
|
2002-01-20 22:54:45 +00:00
|
|
|
std::vector<RegClass *> RCList) const {
|
2001-10-15 16:25:28 +00:00
|
|
|
assert ( (UltraSparcInfo->getInstrInfo()).isCall(CallMI->getOpCode()) );
|
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
CallArgsDescriptor* argDesc = CallArgsDescriptor::get(CallMI);
|
2002-04-25 04:42:21 +00:00
|
|
|
|
2001-10-21 16:43:41 +00:00
|
|
|
suggestReg4CallAddr(CallMI, LRI, RCList);
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
// First color the return value of the call instruction. The return value
|
2001-09-18 22:52:44 +00:00
|
|
|
// will be in %o0 if the value is an integer type, or in %f0 if the
|
|
|
|
// value is a float type.
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
// the return value cannot have a LR in machine instruction since it is
|
|
|
|
// only defined by the call instruction
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
// if type is not void, create a new live range and set its
|
|
|
|
// register class and add to LRI
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
const Value *RetVal = argDesc->getReturnValue();
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2002-02-04 05:59:25 +00:00
|
|
|
if (RetVal) {
|
|
|
|
assert ((!LRI.getLiveRangeForValue(RetVal)) &&
|
2001-10-21 16:43:41 +00:00
|
|
|
"LR for ret Value of call already definded!");
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2002-02-04 05:59:25 +00:00
|
|
|
// create a new LR for the return value
|
|
|
|
LiveRange *RetValLR = new LiveRange();
|
2002-02-04 16:37:09 +00:00
|
|
|
RetValLR->insert(RetVal);
|
2002-02-04 05:59:25 +00:00
|
|
|
unsigned RegClassID = getRegClassIDOfValue(RetVal);
|
|
|
|
RetValLR->setRegClass(RCList[RegClassID]);
|
|
|
|
LRI.addLRToMap(RetVal, RetValLR);
|
2001-10-21 16:43:41 +00:00
|
|
|
|
|
|
|
// now suggest a register depending on the register class of ret arg
|
2001-10-15 16:25:28 +00:00
|
|
|
|
2001-10-21 16:43:41 +00:00
|
|
|
if( RegClassID == IntRegClassID )
|
|
|
|
RetValLR->setSuggestedColor(SparcIntRegOrder::o0);
|
|
|
|
else if (RegClassID == FloatRegClassID )
|
|
|
|
RetValLR->setSuggestedColor(SparcFloatRegOrder::f0 );
|
|
|
|
else assert( 0 && "Unknown reg class for return value of call\n");
|
2001-10-15 16:25:28 +00:00
|
|
|
}
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2001-10-21 16:43:41 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
// Now suggest colors for arguments (operands) of the call instruction.
|
|
|
|
// Colors are suggested only if the arg number is smaller than the
|
|
|
|
// the number of registers allocated for argument passing.
|
2001-10-21 16:43:41 +00:00
|
|
|
// Now, go thru call args - implicit operands of the call MI
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
unsigned NumOfCallArgs = argDesc->getNumArgs();
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2002-04-25 04:42:21 +00:00
|
|
|
for(unsigned argNo=0, i=0, intArgNo=0, fpArgNo=0;
|
|
|
|
i < NumOfCallArgs; ++i, ++argNo) {
|
2001-10-15 16:25:28 +00:00
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
const Value *CallArg = argDesc->getArgInfo(i).getArgVal();
|
2001-09-30 23:16:47 +00:00
|
|
|
|
|
|
|
// get the LR of call operand (parameter)
|
2001-10-15 16:25:28 +00:00
|
|
|
LiveRange *const LR = LRI.getLiveRangeForValue(CallArg);
|
2002-05-19 15:25:51 +00:00
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
// not possible to have a null LR since all args (even consts)
|
|
|
|
// must be defined before
|
2002-02-05 01:43:49 +00:00
|
|
|
if (!LR) {
|
|
|
|
cerr << " ERROR: In call instr, no LR for arg: " << RAV(CallArg) << "\n";
|
2001-10-15 16:25:28 +00:00
|
|
|
assert(0 && "NO LR for call arg");
|
2001-09-14 03:47:57 +00:00
|
|
|
}
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2002-04-25 04:42:21 +00:00
|
|
|
unsigned regType = getRegType( LR );
|
|
|
|
unsigned regClassIDOfArgReg = MAXINT; // reg class of chosen reg (unused)
|
2002-05-19 15:25:51 +00:00
|
|
|
|
2002-04-25 04:42:21 +00:00
|
|
|
// Choose a register for this arg depending on whether it is
|
2002-05-19 15:25:51 +00:00
|
|
|
// an INT or FP value. Here we ignore whether or not it is a
|
|
|
|
// varargs calls, because FP arguments will be explicitly copied
|
|
|
|
// to an integer Value and handled under (argCopy != NULL) below.
|
2002-04-25 04:42:21 +00:00
|
|
|
int regNum = (regType == IntRegType)
|
2002-05-19 15:25:51 +00:00
|
|
|
? regNumForIntArg(/*inCallee*/ false, /*isVarArgs*/ false,
|
|
|
|
argNo, intArgNo++, fpArgNo, regClassIDOfArgReg)
|
|
|
|
: regNumForFPArg(regType, /*inCallee*/ false, /*isVarArgs*/ false,
|
|
|
|
argNo, intArgNo, fpArgNo++, regClassIDOfArgReg);
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2002-04-25 04:42:21 +00:00
|
|
|
// If a register could be allocated, use it.
|
|
|
|
// If not, do NOTHING as this will be colored as a normal value.
|
|
|
|
if(regNum != InvalidRegNum)
|
|
|
|
LR->setSuggestedColor(regNum);
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
// Repeat for the second copy of the argument, which would be
|
|
|
|
// an FP argument being passed to a function with no prototype
|
|
|
|
const Value *argCopy = argDesc->getArgInfo(i).getArgCopy();
|
|
|
|
if (argCopy != NULL)
|
|
|
|
{
|
|
|
|
assert(regType != IntRegType && argCopy->getType()->isIntegral()
|
|
|
|
&& "Must be passing copy of FP argument in int register");
|
|
|
|
int copyRegNum = regNumForIntArg(/*inCallee*/false, /*isVarArgs*/false,
|
|
|
|
argNo, intArgNo, fpArgNo-1,
|
|
|
|
regClassIDOfArgReg);
|
|
|
|
assert(copyRegNum != InvalidRegNum);
|
|
|
|
LiveRange *const copyLR = LRI.getLiveRangeForValue(argCopy);
|
|
|
|
copyLR->setSuggestedColor(copyRegNum);
|
|
|
|
}
|
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
} // for all call arguments
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
}
|
2001-09-18 22:52:44 +00:00
|
|
|
|
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// Helper method for UltraSparcRegInfo::colorCallArgs().
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void
|
|
|
|
UltraSparcRegInfo::InitializeOutgoingArg(const MachineInstr* CallMI,
|
|
|
|
AddedInstrns *CallAI,
|
|
|
|
PhyRegAlloc &PRA, LiveRange* LR,
|
|
|
|
unsigned regType, unsigned RegClassID,
|
|
|
|
int UniArgRegOrNone, unsigned int argNo,
|
|
|
|
std::vector<MachineInstr *>& AddedInstrnsBefore)
|
|
|
|
const
|
|
|
|
{
|
|
|
|
MachineInstr *AdMI;
|
|
|
|
bool isArgInReg = false;
|
|
|
|
unsigned UniArgReg = MAXINT; // unused unless initialized below
|
|
|
|
if (UniArgRegOrNone != InvalidRegNum)
|
|
|
|
{
|
|
|
|
isArgInReg = true;
|
|
|
|
UniArgReg = (unsigned) UniArgRegOrNone;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LR->hasColor()) {
|
|
|
|
unsigned UniLRReg = getUnifiedRegNum(RegClassID, LR->getColor());
|
|
|
|
|
|
|
|
// if LR received the correct color, nothing to do
|
|
|
|
if( isArgInReg && UniArgReg == UniLRReg )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// The LR is allocated to a register UniLRReg and must be copied
|
|
|
|
// to UniArgReg or to the stack slot.
|
|
|
|
//
|
|
|
|
if( isArgInReg ) {
|
|
|
|
// Copy UniLRReg to UniArgReg
|
|
|
|
cpReg2RegMI(UniLRReg, UniArgReg, regType, AddedInstrnsBefore);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Copy UniLRReg to the stack to pass the arg on stack.
|
|
|
|
const MachineFrameInfo& frameInfo = target.getFrameInfo();
|
|
|
|
int argOffset = frameInfo.getOutgoingArgOffset(PRA.mcInfo, argNo);
|
|
|
|
cpReg2MemMI(UniLRReg, getStackPointer(), argOffset, regType,
|
|
|
|
CallAI->InstrnsBefore);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else { // LR is not colored (i.e., spilled)
|
|
|
|
|
|
|
|
if( isArgInReg ) {
|
|
|
|
// Insert a load instruction to load the LR to UniArgReg
|
|
|
|
cpMem2RegMI(getFramePointer(), LR->getSpillOffFromFP(),
|
|
|
|
UniArgReg, regType, AddedInstrnsBefore);
|
|
|
|
// Now add the instruction
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
// Now, we have to pass the arg on stack. Since LR also did NOT
|
|
|
|
// receive a register we have to move an argument in memory to
|
|
|
|
// outgoing parameter on stack.
|
|
|
|
// Use TReg to load and store the value.
|
|
|
|
// Use TmpOff to save TReg, since that may have a live value.
|
|
|
|
//
|
|
|
|
int TReg = PRA.getUniRegNotUsedByThisInst( LR->getRegClass(), CallMI );
|
|
|
|
int TmpOff = PRA.mcInfo.pushTempValue(target,
|
|
|
|
getSpilledRegSize(getRegType(LR)));
|
|
|
|
const MachineFrameInfo& frameInfo = target.getFrameInfo();
|
|
|
|
int argOffset = frameInfo.getOutgoingArgOffset(PRA.mcInfo, argNo);
|
|
|
|
|
|
|
|
MachineInstr *Ad1, *Ad2, *Ad3, *Ad4;
|
|
|
|
|
|
|
|
// Sequence:
|
|
|
|
// (1) Save TReg on stack
|
|
|
|
// (2) Load LR value into TReg from stack pos of LR
|
|
|
|
// (3) Store Treg on outgoing Arg pos on stack
|
|
|
|
// (4) Load the old value of TReg from stack to TReg (restore it)
|
|
|
|
//
|
|
|
|
// OPTIMIZE THIS:
|
|
|
|
// When reverse pointers in MahineInstr are introduced:
|
|
|
|
// Call PRA.getUnusedRegAtMI(....) to get an unused reg. Step 1 is
|
|
|
|
// needed only if this fails. Currently, we cannot call the
|
|
|
|
// above method since we cannot find LVSetBefore without the BB
|
|
|
|
//
|
|
|
|
// NOTE: We directly add to CallAI->InstrnsBefore instead of adding to
|
|
|
|
// AddedInstrnsBefore since these instructions must not be reordered.
|
|
|
|
cpReg2MemMI(TReg, getFramePointer(), TmpOff, regType,
|
|
|
|
CallAI->InstrnsBefore);
|
|
|
|
cpMem2RegMI(getFramePointer(), LR->getSpillOffFromFP(), TReg, regType,
|
|
|
|
CallAI->InstrnsBefore);
|
|
|
|
cpReg2MemMI(TReg, getStackPointer(), argOffset, regType,
|
|
|
|
CallAI->InstrnsBefore);
|
|
|
|
cpMem2RegMI(getFramePointer(), TmpOff, TReg, regType,
|
|
|
|
CallAI->InstrnsBefore);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// After graph coloring, we have call this method to see whehter the return
|
|
|
|
// value and the call args received the correct colors. If not, we have
|
|
|
|
// to instert copy instructions.
|
|
|
|
//---------------------------------------------------------------------------
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2002-02-04 05:59:25 +00:00
|
|
|
void UltraSparcRegInfo::colorCallArgs(const MachineInstr *CallMI,
|
|
|
|
LiveRangeInfo &LRI,
|
|
|
|
AddedInstrns *CallAI,
|
2002-01-07 19:20:28 +00:00
|
|
|
PhyRegAlloc &PRA,
|
|
|
|
const BasicBlock *BB) const {
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
assert ( (UltraSparcInfo->getInstrInfo()).isCall(CallMI->getOpCode()) );
|
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
CallArgsDescriptor* argDesc = CallArgsDescriptor::get(CallMI);
|
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
// First color the return value of the call.
|
|
|
|
// If there is a LR for the return value, it means this
|
|
|
|
// method returns a value
|
|
|
|
|
|
|
|
MachineInstr *AdMI;
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
const Value *RetVal = argDesc->getReturnValue();
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2002-02-05 01:43:49 +00:00
|
|
|
if (RetVal) {
|
|
|
|
LiveRange *RetValLR = LRI.getLiveRangeForValue( RetVal );
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2002-02-05 01:43:49 +00:00
|
|
|
if (!RetValLR) {
|
|
|
|
cerr << "\nNo LR for:" << RAV(RetVal) << "\n";
|
2002-05-19 15:25:51 +00:00
|
|
|
assert(RetValLR && "ERR:No LR for non-void return value");
|
2001-10-21 16:43:41 +00:00
|
|
|
}
|
2001-10-24 15:56:58 +00:00
|
|
|
|
|
|
|
unsigned RegClassID = (RetValLR->getRegClass())->getID();
|
|
|
|
bool recvCorrectColor = false;
|
|
|
|
|
|
|
|
unsigned CorrectCol; // correct color for ret value
|
|
|
|
if(RegClassID == IntRegClassID)
|
|
|
|
CorrectCol = SparcIntRegOrder::o0;
|
|
|
|
else if(RegClassID == FloatRegClassID)
|
|
|
|
CorrectCol = SparcFloatRegOrder::f0;
|
2001-11-07 14:01:59 +00:00
|
|
|
else {
|
2001-10-24 15:56:58 +00:00
|
|
|
assert( 0 && "Unknown RegClass");
|
2001-11-07 14:01:59 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-10-24 15:56:58 +00:00
|
|
|
|
|
|
|
// if the LR received the correct color, NOTHING to do
|
|
|
|
|
|
|
|
if( RetValLR->hasColor() )
|
|
|
|
if( RetValLR->getColor() == CorrectCol )
|
|
|
|
recvCorrectColor = true;
|
|
|
|
|
|
|
|
|
|
|
|
// if we didn't receive the correct color for some reason,
|
2001-10-21 16:43:41 +00:00
|
|
|
// put copy instruction
|
|
|
|
|
2001-10-24 15:56:58 +00:00
|
|
|
if( !recvCorrectColor ) {
|
2001-10-28 18:15:12 +00:00
|
|
|
|
2002-04-25 04:42:21 +00:00
|
|
|
unsigned regType = getRegType( RetValLR );
|
2001-10-28 18:15:12 +00:00
|
|
|
|
|
|
|
// the reg that LR must be colored with
|
|
|
|
unsigned UniRetReg = getUnifiedRegNum( RegClassID, CorrectCol);
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2001-10-21 16:43:41 +00:00
|
|
|
if( RetValLR->hasColor() ) {
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2001-10-21 16:43:41 +00:00
|
|
|
unsigned
|
|
|
|
UniRetLRReg=getUnifiedRegNum(RegClassID,RetValLR->getColor());
|
|
|
|
|
2001-10-24 15:56:58 +00:00
|
|
|
// the return value is coming in UniRetReg but has to go into
|
|
|
|
// the UniRetLRReg
|
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
cpReg2RegMI(UniRetReg, UniRetLRReg, regType, CallAI->InstrnsAfter);
|
2001-10-28 18:15:12 +00:00
|
|
|
|
2001-10-21 16:43:41 +00:00
|
|
|
} // if LR has color
|
|
|
|
else {
|
2001-10-28 18:15:12 +00:00
|
|
|
|
|
|
|
// if the LR did NOT receive a color, we have to move the return
|
|
|
|
// value coming in UniRetReg to the stack pos of spilled LR
|
2001-10-21 16:43:41 +00:00
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
cpReg2MemMI(UniRetReg, getFramePointer(),RetValLR->getSpillOffFromFP(),
|
|
|
|
regType, CallAI->InstrnsAfter);
|
2001-10-21 16:43:41 +00:00
|
|
|
}
|
2001-10-28 18:15:12 +00:00
|
|
|
|
2001-10-21 16:43:41 +00:00
|
|
|
} // the LR didn't receive the suggested color
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2001-10-21 16:43:41 +00:00
|
|
|
} // if there a return value
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2002-01-07 19:20:28 +00:00
|
|
|
//-------------------------------------------
|
2001-10-15 16:25:28 +00:00
|
|
|
// Now color all args of the call instruction
|
2002-01-07 19:20:28 +00:00
|
|
|
//-------------------------------------------
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2002-01-20 22:54:45 +00:00
|
|
|
std::vector<MachineInstr *> AddedInstrnsBefore;
|
2002-05-19 15:25:51 +00:00
|
|
|
|
|
|
|
unsigned NumOfCallArgs = argDesc->getNumArgs();
|
|
|
|
|
2002-04-25 04:42:21 +00:00
|
|
|
for(unsigned argNo=0, i=0, intArgNo=0, fpArgNo=0;
|
|
|
|
i < NumOfCallArgs; ++i, ++argNo) {
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
const Value *CallArg = argDesc->getArgInfo(i).getArgVal();
|
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
// get the LR of call operand (parameter)
|
|
|
|
LiveRange *const LR = LRI.getLiveRangeForValue(CallArg);
|
|
|
|
|
2002-04-25 04:42:21 +00:00
|
|
|
unsigned RegClassID = getRegClassIDOfValue( CallArg);
|
2002-05-19 15:25:51 +00:00
|
|
|
unsigned regType = getRegType( RegClassID, CallArg->getType() );
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
// Find whether this argument is coming in a register (if not, on stack)
|
2002-04-25 04:42:21 +00:00
|
|
|
// Also find the correct register the argument must use (UniArgReg)
|
|
|
|
//
|
2001-09-30 23:16:47 +00:00
|
|
|
bool isArgInReg = false;
|
2002-05-19 15:25:51 +00:00
|
|
|
unsigned UniArgReg = InvalidRegNum; // reg that LR MUST be colored with
|
2002-04-25 04:42:21 +00:00
|
|
|
unsigned regClassIDOfArgReg = MAXINT; // reg class of chosen reg
|
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
// Find the register that must be used for this arg, depending on
|
|
|
|
// whether it is an INT or FP value. Here we ignore whether or not it
|
|
|
|
// is a varargs calls, because FP arguments will be explicitly copied
|
|
|
|
// to an integer Value and handled under (argCopy != NULL) below.
|
2002-04-25 04:42:21 +00:00
|
|
|
int regNum = (regType == IntRegType)
|
2002-05-19 15:25:51 +00:00
|
|
|
? regNumForIntArg(/*inCallee*/ false, /*isVarArgs*/ false,
|
|
|
|
argNo, intArgNo++, fpArgNo, regClassIDOfArgReg)
|
|
|
|
: regNumForFPArg(regType, /*inCallee*/ false, /*isVarArgs*/ false,
|
|
|
|
argNo, intArgNo, fpArgNo++, regClassIDOfArgReg);
|
2002-04-25 04:42:21 +00:00
|
|
|
|
|
|
|
if(regNum != InvalidRegNum) {
|
2001-09-30 23:16:47 +00:00
|
|
|
isArgInReg = true;
|
2002-04-25 04:42:21 +00:00
|
|
|
UniArgReg = getUnifiedRegNum( regClassIDOfArgReg, regNum);
|
2002-05-19 15:25:51 +00:00
|
|
|
assert(regClassIDOfArgReg == RegClassID &&
|
|
|
|
"Moving values between reg classes must happen during selection");
|
2002-01-07 19:20:28 +00:00
|
|
|
}
|
2002-04-25 04:42:21 +00:00
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
// not possible to have a null LR since all args (even consts)
|
|
|
|
// must be defined before
|
2002-02-05 01:43:49 +00:00
|
|
|
if (!LR) {
|
2002-04-25 04:42:21 +00:00
|
|
|
cerr << " ERROR: In call instr, no LR for arg: " << RAV(CallArg) <<"\n";
|
2002-05-19 15:25:51 +00:00
|
|
|
assert(LR && "NO LR for call arg");
|
2001-09-30 23:16:47 +00:00
|
|
|
}
|
2002-05-19 15:25:51 +00:00
|
|
|
|
|
|
|
InitializeOutgoingArg(CallMI, CallAI, PRA, LR, regType, RegClassID,
|
|
|
|
UniArgReg, argNo, AddedInstrnsBefore);
|
|
|
|
|
|
|
|
// Repeat for the second copy of the argument, which would be
|
|
|
|
// an FP argument being passed to a function with no prototype.
|
|
|
|
const Value *argCopy = argDesc->getArgInfo(i).getArgCopy();
|
|
|
|
if (argCopy != NULL)
|
|
|
|
{
|
|
|
|
assert(regType != IntRegType && argCopy->getType()->isIntegral()
|
|
|
|
&& "Must be passing copy of FP argument in int register");
|
2001-11-08 04:56:41 +00:00
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
unsigned copyRegClassID = getRegClassIDOfValue(argCopy);
|
|
|
|
unsigned copyRegType = getRegType(copyRegClassID, argCopy->getType());
|
2001-11-08 04:56:41 +00:00
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
int copyRegNum = regNumForIntArg(/*inCallee*/false, /*isVarArgs*/false,
|
|
|
|
argNo, intArgNo, fpArgNo-1,
|
|
|
|
regClassIDOfArgReg);
|
|
|
|
assert(copyRegNum != InvalidRegNum);
|
|
|
|
assert(regClassIDOfArgReg == copyRegClassID &&
|
|
|
|
"Moving values between reg classes must happen during selection");
|
2001-11-08 04:56:41 +00:00
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
InitializeOutgoingArg(CallMI, CallAI, PRA,
|
|
|
|
LRI.getLiveRangeForValue(argCopy), copyRegType,
|
|
|
|
copyRegClassID, copyRegNum, argNo,
|
|
|
|
AddedInstrnsBefore);
|
2001-10-28 18:15:12 +00:00
|
|
|
}
|
2001-09-30 23:16:47 +00:00
|
|
|
} // for each parameter in call instruction
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
// If we added any instruction before the call instruction, verify
|
2001-11-09 23:49:14 +00:00
|
|
|
// that they are in the proper order and if not, reorder them
|
2002-05-19 15:25:51 +00:00
|
|
|
//
|
2002-02-04 05:59:25 +00:00
|
|
|
if (!AddedInstrnsBefore.empty()) {
|
2001-11-09 23:49:14 +00:00
|
|
|
|
2002-02-04 05:59:25 +00:00
|
|
|
if (DEBUG_RA) {
|
2001-11-09 23:49:14 +00:00
|
|
|
cerr << "\nCalling reorder with instrns: \n";
|
|
|
|
for(unsigned i=0; i < AddedInstrnsBefore.size(); i++)
|
|
|
|
cerr << *(AddedInstrnsBefore[i]);
|
|
|
|
}
|
|
|
|
|
2002-01-20 22:54:45 +00:00
|
|
|
std::vector<MachineInstr *> TmpVec;
|
2001-11-10 21:20:43 +00:00
|
|
|
OrderAddedInstrns(AddedInstrnsBefore, TmpVec, PRA);
|
2001-11-09 23:49:14 +00:00
|
|
|
|
2002-02-04 05:59:25 +00:00
|
|
|
if (DEBUG_RA) {
|
2001-11-09 23:49:14 +00:00
|
|
|
cerr << "\nAfter reordering instrns: \n";
|
2002-02-04 05:59:25 +00:00
|
|
|
for(unsigned i = 0; i < TmpVec.size(); i++)
|
|
|
|
cerr << *TmpVec[i];
|
2001-11-09 23:49:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// copy the results back from TmpVec to InstrnsBefore
|
|
|
|
for(unsigned i=0; i < TmpVec.size(); i++)
|
|
|
|
CallAI->InstrnsBefore.push_back( TmpVec[i] );
|
|
|
|
}
|
2002-05-19 15:25:51 +00:00
|
|
|
|
2002-01-07 19:20:28 +00:00
|
|
|
// now insert caller saving code for this call instruction
|
|
|
|
//
|
|
|
|
insertCallerSavingCode(CallMI, BB, PRA);
|
2001-09-30 23:16:47 +00:00
|
|
|
}
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// This method is called for an LLVM return instruction to identify which
|
|
|
|
// values will be returned from this method and to suggest colors.
|
|
|
|
//---------------------------------------------------------------------------
|
2002-02-04 05:59:25 +00:00
|
|
|
void UltraSparcRegInfo::suggestReg4RetValue(const MachineInstr *RetMI,
|
|
|
|
LiveRangeInfo &LRI) const {
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
assert( (UltraSparcInfo->getInstrInfo()).isReturn( RetMI->getOpCode() ) );
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2001-10-23 21:40:39 +00:00
|
|
|
suggestReg4RetAddr(RetMI, LRI);
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
// if there is an implicit ref, that has to be the ret value
|
|
|
|
if( RetMI->getNumImplicitRefs() > 0 ) {
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
// The first implicit operand is the return value of a return instr
|
|
|
|
const Value *RetVal = RetMI->getImplicitRef(0);
|
2001-09-30 23:16:47 +00:00
|
|
|
|
|
|
|
LiveRange *const LR = LRI.getLiveRangeForValue( RetVal );
|
|
|
|
|
2002-02-05 01:43:49 +00:00
|
|
|
if (!LR) {
|
|
|
|
cerr << "\nNo LR for:" << RAV(RetVal) << "\n";
|
|
|
|
assert(0 && "No LR for return value of non-void method");
|
|
|
|
}
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
unsigned RegClassID = (LR->getRegClass())->getID();
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2002-02-04 05:59:25 +00:00
|
|
|
if (RegClassID == IntRegClassID)
|
2001-10-15 16:25:28 +00:00
|
|
|
LR->setSuggestedColor(SparcIntRegOrder::i0);
|
2002-02-04 05:59:25 +00:00
|
|
|
else if (RegClassID == FloatRegClassID)
|
2001-10-15 16:25:28 +00:00
|
|
|
LR->setSuggestedColor(SparcFloatRegOrder::f0);
|
2001-09-14 03:47:57 +00:00
|
|
|
}
|
2001-09-18 22:52:44 +00:00
|
|
|
}
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2001-10-28 18:15:12 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2001-10-28 18:15:12 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// Colors the return value of a method to %i0 or %f0, if possible. If it is
|
|
|
|
// not possilbe to directly color the LR, insert a copy instruction to move
|
|
|
|
// the LR to %i0 or %f0. When the LR is spilled, instead of the copy, we
|
|
|
|
// have to put a load instruction.
|
2001-09-30 23:16:47 +00:00
|
|
|
//---------------------------------------------------------------------------
|
2002-02-04 05:59:25 +00:00
|
|
|
void UltraSparcRegInfo::colorRetValue(const MachineInstr *RetMI,
|
|
|
|
LiveRangeInfo &LRI,
|
|
|
|
AddedInstrns *RetAI) const {
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2002-02-04 05:59:25 +00:00
|
|
|
assert((UltraSparcInfo->getInstrInfo()).isReturn( RetMI->getOpCode()));
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
// if there is an implicit ref, that has to be the ret value
|
2002-02-04 05:59:25 +00:00
|
|
|
if(RetMI->getNumImplicitRefs() > 0) {
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
// The first implicit operand is the return value of a return instr
|
|
|
|
const Value *RetVal = RetMI->getImplicitRef(0);
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2002-02-04 05:59:25 +00:00
|
|
|
LiveRange *LR = LRI.getLiveRangeForValue(RetVal);
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2002-02-05 01:43:49 +00:00
|
|
|
if (!LR) {
|
|
|
|
cerr << "\nNo LR for:" << RAV(RetVal) << "\n";
|
|
|
|
// assert( LR && "No LR for return value of non-void method");
|
|
|
|
return;
|
2001-10-28 18:15:12 +00:00
|
|
|
}
|
2001-10-15 16:25:28 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
unsigned RegClassID = getRegClassIDOfValue(RetVal);
|
2002-04-25 04:42:21 +00:00
|
|
|
unsigned regType = getRegType( RetVal );
|
2001-10-23 21:40:39 +00:00
|
|
|
|
|
|
|
unsigned CorrectCol;
|
2001-09-30 23:16:47 +00:00
|
|
|
if(RegClassID == IntRegClassID)
|
2001-10-23 21:40:39 +00:00
|
|
|
CorrectCol = SparcIntRegOrder::i0;
|
2001-09-30 23:16:47 +00:00
|
|
|
else if(RegClassID == FloatRegClassID)
|
2001-10-23 21:40:39 +00:00
|
|
|
CorrectCol = SparcFloatRegOrder::f0;
|
2001-11-07 14:01:59 +00:00
|
|
|
else {
|
2002-02-04 05:59:25 +00:00
|
|
|
assert (0 && "Unknown RegClass");
|
2001-11-07 14:01:59 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2001-10-24 15:56:58 +00:00
|
|
|
// if the LR received the correct color, NOTHING to do
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2002-02-04 05:59:25 +00:00
|
|
|
if (LR->hasColor() && LR->getColor() == CorrectCol)
|
|
|
|
return;
|
2001-10-23 21:40:39 +00:00
|
|
|
|
2002-02-04 05:59:25 +00:00
|
|
|
unsigned UniRetReg = getUnifiedRegNum(RegClassID, CorrectCol);
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2002-02-04 05:59:25 +00:00
|
|
|
if (LR->hasColor()) {
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2001-10-23 21:40:39 +00:00
|
|
|
// We are here because the LR was allocted a regiter
|
|
|
|
// It may be the suggested register or not
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
// copy the LR of retun value to i0 or f0
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
unsigned UniLRReg =getUnifiedRegNum( RegClassID, LR->getColor());
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2001-10-24 15:56:58 +00:00
|
|
|
// the LR received UniLRReg but must be colored with UniRetReg
|
|
|
|
// to pass as the return value
|
2002-05-19 15:25:51 +00:00
|
|
|
cpReg2RegMI(UniLRReg, UniRetReg, regType, RetAI->InstrnsBefore);
|
2001-09-30 23:16:47 +00:00
|
|
|
}
|
2001-10-28 18:15:12 +00:00
|
|
|
else { // if the LR is spilled
|
2002-05-19 15:25:51 +00:00
|
|
|
cpMem2RegMI(getFramePointer(), LR->getSpillOffFromFP(),
|
|
|
|
UniRetReg, regType, RetAI->InstrnsBefore);
|
2002-01-20 22:54:45 +00:00
|
|
|
cerr << "\nCopied the return value from stack\n";
|
2001-10-28 18:15:12 +00:00
|
|
|
}
|
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
} // if there is a return value
|
2001-09-14 03:47:57 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// Copy from a register to register. Register number must be the unified
|
|
|
|
// register number
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
void
|
|
|
|
UltraSparcRegInfo::cpReg2RegMI(unsigned SrcReg,
|
|
|
|
unsigned DestReg,
|
|
|
|
int RegType,
|
|
|
|
vector<MachineInstr*>& mvec) const {
|
2001-10-16 01:23:19 +00:00
|
|
|
assert( ((int)SrcReg != InvalidRegNum) && ((int)DestReg != InvalidRegNum) &&
|
2001-09-30 23:16:47 +00:00
|
|
|
"Invalid Register");
|
|
|
|
|
|
|
|
MachineInstr * MI = NULL;
|
2002-05-19 15:25:51 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
switch( RegType ) {
|
|
|
|
|
2001-10-18 22:38:52 +00:00
|
|
|
case IntCCRegType:
|
|
|
|
case FloatCCRegType:
|
2002-05-19 15:25:51 +00:00
|
|
|
assert(0 && "This code was bogus and needs to be fixed!");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IntRegType:
|
2001-09-18 22:52:44 +00:00
|
|
|
MI = new MachineInstr(ADD, 3);
|
2002-03-18 03:12:16 +00:00
|
|
|
MI->SetMachineOperandReg(0, SrcReg, false);
|
|
|
|
MI->SetMachineOperandReg(1, this->getZeroRegNum(), false);
|
|
|
|
MI->SetMachineOperandReg(2, DestReg, true);
|
2001-09-30 23:16:47 +00:00
|
|
|
break;
|
2002-05-19 15:25:51 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
case FPSingleRegType:
|
|
|
|
MI = new MachineInstr(FMOVS, 2);
|
2002-03-18 03:12:16 +00:00
|
|
|
MI->SetMachineOperandReg(0, SrcReg, false);
|
|
|
|
MI->SetMachineOperandReg(1, DestReg, true);
|
2001-09-30 23:16:47 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FPDoubleRegType:
|
|
|
|
MI = new MachineInstr(FMOVD, 2);
|
2002-03-18 03:12:16 +00:00
|
|
|
MI->SetMachineOperandReg(0, SrcReg, false);
|
|
|
|
MI->SetMachineOperandReg(1, DestReg, true);
|
2001-09-30 23:16:47 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2002-05-19 15:25:51 +00:00
|
|
|
assert(0 && "Unknown RegType");
|
2001-09-18 22:52:44 +00:00
|
|
|
}
|
2002-05-19 15:25:51 +00:00
|
|
|
|
|
|
|
if (MI)
|
|
|
|
mvec.push_back(MI);
|
2001-09-30 23:16:47 +00:00
|
|
|
}
|
|
|
|
|
2001-10-16 01:23:19 +00:00
|
|
|
//---------------------------------------------------------------------------
|
2001-10-24 22:05:34 +00:00
|
|
|
// Copy from a register to memory (i.e., Store). Register number must
|
|
|
|
// be the unified register number
|
2001-10-16 01:23:19 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
void
|
|
|
|
UltraSparcRegInfo::cpReg2MemMI(unsigned SrcReg,
|
|
|
|
unsigned DestPtrReg,
|
|
|
|
int Offset, int RegType,
|
|
|
|
vector<MachineInstr*>& mvec) const {
|
2001-10-16 01:23:19 +00:00
|
|
|
MachineInstr * MI = NULL;
|
|
|
|
switch( RegType ) {
|
|
|
|
case IntRegType:
|
2001-10-18 22:38:52 +00:00
|
|
|
case FloatCCRegType:
|
2001-10-16 01:23:19 +00:00
|
|
|
MI = new MachineInstr(STX, 3);
|
2002-03-18 03:12:16 +00:00
|
|
|
MI->SetMachineOperandReg(0, SrcReg, false);
|
|
|
|
MI->SetMachineOperandReg(1, DestPtrReg, false);
|
|
|
|
MI->SetMachineOperandConst(2, MachineOperand:: MO_SignExtendedImmed,
|
|
|
|
(int64_t) Offset);
|
2001-10-16 01:23:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FPSingleRegType:
|
|
|
|
MI = new MachineInstr(ST, 3);
|
2002-03-18 03:12:16 +00:00
|
|
|
MI->SetMachineOperandReg(0, SrcReg, false);
|
|
|
|
MI->SetMachineOperandReg(1, DestPtrReg, false);
|
|
|
|
MI->SetMachineOperandConst(2, MachineOperand:: MO_SignExtendedImmed,
|
|
|
|
(int64_t) Offset);
|
2001-10-16 01:23:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FPDoubleRegType:
|
|
|
|
MI = new MachineInstr(STD, 3);
|
2002-03-18 03:12:16 +00:00
|
|
|
MI->SetMachineOperandReg(0, SrcReg, false);
|
|
|
|
MI->SetMachineOperandReg(1, DestPtrReg, false);
|
|
|
|
MI->SetMachineOperandConst(2, MachineOperand:: MO_SignExtendedImmed,
|
|
|
|
(int64_t) Offset);
|
2001-10-16 01:23:19 +00:00
|
|
|
break;
|
|
|
|
|
2001-11-03 19:59:59 +00:00
|
|
|
case IntCCRegType:
|
|
|
|
assert( 0 && "Cannot directly store %ccr to memory");
|
|
|
|
|
2001-10-16 01:23:19 +00:00
|
|
|
default:
|
2002-05-19 15:25:51 +00:00
|
|
|
assert(0 && "Unknown RegType in cpReg2MemMI");
|
2001-10-16 01:23:19 +00:00
|
|
|
}
|
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
if (MI)
|
|
|
|
mvec.push_back(MI);
|
2001-10-16 01:23:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
2001-10-24 22:05:34 +00:00
|
|
|
// Copy from memory to a reg (i.e., Load) Register number must be the unified
|
2001-10-16 01:23:19 +00:00
|
|
|
// register number
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
void
|
|
|
|
UltraSparcRegInfo::cpMem2RegMI(unsigned SrcPtrReg,
|
|
|
|
int Offset,
|
|
|
|
unsigned DestReg,
|
|
|
|
int RegType,
|
|
|
|
vector<MachineInstr*>& mvec) const {
|
2001-10-16 01:23:19 +00:00
|
|
|
MachineInstr * MI = NULL;
|
2002-02-04 05:59:25 +00:00
|
|
|
switch (RegType) {
|
2001-10-16 01:23:19 +00:00
|
|
|
case IntRegType:
|
2001-10-18 22:38:52 +00:00
|
|
|
case FloatCCRegType:
|
2001-10-16 01:23:19 +00:00
|
|
|
MI = new MachineInstr(LDX, 3);
|
2002-03-18 03:12:16 +00:00
|
|
|
MI->SetMachineOperandReg(0, SrcPtrReg, false);
|
|
|
|
MI->SetMachineOperandConst(1, MachineOperand:: MO_SignExtendedImmed,
|
|
|
|
(int64_t) Offset);
|
|
|
|
MI->SetMachineOperandReg(2, DestReg, true);
|
2001-10-16 01:23:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FPSingleRegType:
|
|
|
|
MI = new MachineInstr(LD, 3);
|
2002-03-18 03:12:16 +00:00
|
|
|
MI->SetMachineOperandReg(0, SrcPtrReg, false);
|
|
|
|
MI->SetMachineOperandConst(1, MachineOperand:: MO_SignExtendedImmed,
|
|
|
|
(int64_t) Offset);
|
|
|
|
MI->SetMachineOperandReg(2, DestReg, true);
|
2001-10-16 01:23:19 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FPDoubleRegType:
|
|
|
|
MI = new MachineInstr(LDD, 3);
|
2002-03-18 03:12:16 +00:00
|
|
|
MI->SetMachineOperandReg(0, SrcPtrReg, false);
|
|
|
|
MI->SetMachineOperandConst(1, MachineOperand:: MO_SignExtendedImmed,
|
|
|
|
(int64_t) Offset);
|
|
|
|
MI->SetMachineOperandReg(2, DestReg, true);
|
2001-10-16 01:23:19 +00:00
|
|
|
break;
|
|
|
|
|
2001-11-03 19:59:59 +00:00
|
|
|
case IntCCRegType:
|
|
|
|
assert( 0 && "Cannot directly load into %ccr from memory");
|
|
|
|
|
2001-10-16 01:23:19 +00:00
|
|
|
default:
|
2001-11-10 21:20:43 +00:00
|
|
|
assert(0 && "Unknown RegType in cpMem2RegMI");
|
2001-10-16 01:23:19 +00:00
|
|
|
}
|
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
if (MI)
|
|
|
|
mvec.push_back(MI);
|
2001-10-16 01:23:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-12 14:45:33 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// Generate a copy instruction to copy a value to another. Temporarily
|
|
|
|
// used by PhiElimination code.
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
void
|
|
|
|
UltraSparcRegInfo::cpValue2Value(Value *Src,
|
|
|
|
Value *Dest,
|
|
|
|
vector<MachineInstr*>& mvec) const {
|
2001-11-12 14:45:33 +00:00
|
|
|
int RegType = getRegType( Src );
|
|
|
|
|
|
|
|
assert( (RegType==getRegType(Src)) && "Src & Dest are diff types");
|
2001-10-16 01:23:19 +00:00
|
|
|
|
2001-11-03 17:13:27 +00:00
|
|
|
MachineInstr * MI = NULL;
|
|
|
|
|
2001-11-12 14:45:33 +00:00
|
|
|
switch( RegType ) {
|
|
|
|
case IntRegType:
|
|
|
|
MI = new MachineInstr(ADD, 3);
|
2002-03-18 03:12:16 +00:00
|
|
|
MI->SetMachineOperandVal(0, MachineOperand:: MO_VirtualRegister, Src, false);
|
|
|
|
MI->SetMachineOperandReg(1, this->getZeroRegNum(), false);
|
|
|
|
MI->SetMachineOperandVal(2, MachineOperand:: MO_VirtualRegister, Dest, true);
|
2001-11-12 14:45:33 +00:00
|
|
|
break;
|
2001-11-03 17:13:27 +00:00
|
|
|
|
2001-11-12 14:45:33 +00:00
|
|
|
case FPSingleRegType:
|
|
|
|
MI = new MachineInstr(FMOVS, 2);
|
2002-03-18 03:12:16 +00:00
|
|
|
MI->SetMachineOperandVal(0, MachineOperand:: MO_VirtualRegister, Src, false);
|
|
|
|
MI->SetMachineOperandVal(1, MachineOperand:: MO_VirtualRegister, Dest, true);
|
2001-11-12 14:45:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case FPDoubleRegType:
|
|
|
|
MI = new MachineInstr(FMOVD, 2);
|
2002-03-18 03:12:16 +00:00
|
|
|
MI->SetMachineOperandVal(0, MachineOperand:: MO_VirtualRegister, Src, false);
|
|
|
|
MI->SetMachineOperandVal(1, MachineOperand:: MO_VirtualRegister, Dest, true);
|
2001-11-12 14:45:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert(0 && "Unknow RegType in CpValu2Value");
|
|
|
|
}
|
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
if (MI)
|
|
|
|
mvec.push_back(MI);
|
2001-11-03 17:13:27 +00:00
|
|
|
}
|
2001-10-16 01:23:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2001-11-12 14:45:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2001-10-28 18:15:12 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// This method inserts caller saving/restoring instructons before/after
|
2002-01-07 21:03:42 +00:00
|
|
|
// a call machine instruction. The caller saving/restoring instructions are
|
|
|
|
// inserted like:
|
|
|
|
//
|
|
|
|
// ** caller saving instructions
|
|
|
|
// other instructions inserted for the call by ColorCallArg
|
|
|
|
// CALL instruction
|
|
|
|
// other instructions inserted for the call ColorCallArg
|
|
|
|
// ** caller restoring instructions
|
|
|
|
//
|
2001-10-28 18:15:12 +00:00
|
|
|
//----------------------------------------------------------------------------
|
2001-10-16 01:23:19 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
void UltraSparcRegInfo::insertCallerSavingCode(const MachineInstr *CallMI,
|
2001-10-28 18:15:12 +00:00
|
|
|
const BasicBlock *BB,
|
|
|
|
PhyRegAlloc &PRA) const {
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
assert ( (UltraSparcInfo->getInstrInfo()).isCall(CallMI->getOpCode()) );
|
|
|
|
|
2002-01-07 21:03:42 +00:00
|
|
|
// has set to record which registers were saved/restored
|
|
|
|
//
|
2002-01-20 22:54:45 +00:00
|
|
|
std::hash_set<unsigned> PushedRegSet;
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
CallArgsDescriptor* argDesc = CallArgsDescriptor::get(CallMI);
|
|
|
|
|
2001-10-28 18:15:12 +00:00
|
|
|
// Now find the LR of the return value of the call
|
|
|
|
// The last *implicit operand* is the return value of a call
|
|
|
|
// Insert it to to he PushedRegSet since we must not save that register
|
|
|
|
// and restore it after the call.
|
|
|
|
// We do this because, we look at the LV set *after* the instruction
|
|
|
|
// to determine, which LRs must be saved across calls. The return value
|
|
|
|
// of the call is live in this set - but we must not save/restore it.
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
const Value *RetVal = argDesc->getReturnValue();
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2002-02-04 05:59:25 +00:00
|
|
|
if (RetVal) {
|
2001-10-28 18:15:12 +00:00
|
|
|
LiveRange *RetValLR = PRA.LRI.getLiveRangeForValue( RetVal );
|
2002-02-04 05:59:25 +00:00
|
|
|
assert(RetValLR && "No LR for RetValue of call");
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2002-02-04 05:59:25 +00:00
|
|
|
if (RetValLR->hasColor())
|
2001-11-10 21:20:43 +00:00
|
|
|
PushedRegSet.insert(
|
|
|
|
getUnifiedRegNum((RetValLR->getRegClass())->getID(),
|
2001-10-28 18:15:12 +00:00
|
|
|
RetValLR->getColor() ) );
|
|
|
|
}
|
2001-09-30 23:16:47 +00:00
|
|
|
|
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
const ValueSet &LVSetAft = PRA.LVI->getLiveVarSetAfterMInst(CallMI, BB);
|
2002-02-05 04:20:12 +00:00
|
|
|
ValueSet::const_iterator LIt = LVSetAft.begin();
|
2001-09-14 20:31:39 +00:00
|
|
|
|
2001-10-28 18:15:12 +00:00
|
|
|
// for each live var in live variable set after machine inst
|
2002-02-05 04:20:12 +00:00
|
|
|
for( ; LIt != LVSetAft.end(); ++LIt) {
|
2001-09-14 20:31:39 +00:00
|
|
|
|
2001-10-28 18:15:12 +00:00
|
|
|
// get the live range corresponding to live var
|
|
|
|
LiveRange *const LR = PRA.LRI.getLiveRangeForValue(*LIt );
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2001-10-28 18:15:12 +00:00
|
|
|
// LR can be null if it is a const since a const
|
|
|
|
// doesn't have a dominating def - see Assumptions above
|
|
|
|
if( LR ) {
|
|
|
|
|
|
|
|
if( LR->hasColor() ) {
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2001-10-28 18:15:12 +00:00
|
|
|
unsigned RCID = (LR->getRegClass())->getID();
|
|
|
|
unsigned Color = LR->getColor();
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2001-10-28 18:15:12 +00:00
|
|
|
if ( isRegVolatile(RCID, Color) ) {
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2001-10-28 18:15:12 +00:00
|
|
|
// if the value is in both LV sets (i.e., live before and after
|
|
|
|
// the call machine instruction)
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2001-10-28 18:15:12 +00:00
|
|
|
unsigned Reg = getUnifiedRegNum(RCID, Color);
|
|
|
|
|
|
|
|
if( PushedRegSet.find(Reg) == PushedRegSet.end() ) {
|
|
|
|
|
|
|
|
// if we haven't already pushed that register
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2001-10-28 18:15:12 +00:00
|
|
|
unsigned RegType = getRegType( LR );
|
|
|
|
|
|
|
|
// Now get two instructions - to push on stack and pop from stack
|
|
|
|
// and add them to InstrnsBefore and InstrnsAfter of the
|
|
|
|
// call instruction
|
|
|
|
|
2002-01-07 19:20:28 +00:00
|
|
|
|
|
|
|
int StackOff = PRA.mcInfo.pushTempValue(target,
|
|
|
|
getSpilledRegSize(RegType));
|
|
|
|
|
2001-11-08 04:56:41 +00:00
|
|
|
|
2002-03-18 03:12:16 +00:00
|
|
|
MachineInstr *AdIBefCC=NULL, *AdIAftCC=NULL, *AdICpCC;
|
|
|
|
MachineInstr *AdIBef=NULL, *AdIAft=NULL;
|
2001-11-03 19:59:59 +00:00
|
|
|
|
|
|
|
//---- Insert code for pushing the reg on stack ----------
|
2001-10-28 18:15:12 +00:00
|
|
|
|
2001-11-03 19:59:59 +00:00
|
|
|
if( RegType == IntCCRegType ) {
|
|
|
|
|
|
|
|
// Handle IntCCRegType specially since we cannot directly
|
|
|
|
// push %ccr on to the stack
|
|
|
|
|
2002-02-05 04:20:12 +00:00
|
|
|
const ValueSet &LVSetBef =
|
2002-05-19 15:25:51 +00:00
|
|
|
PRA.LVI->getLiveVarSetBeforeMInst(CallMI, BB);
|
2001-11-03 19:59:59 +00:00
|
|
|
|
|
|
|
// get a free INTEGER register
|
|
|
|
int FreeIntReg =
|
2002-03-18 03:12:16 +00:00
|
|
|
PRA.getUsableUniRegAtMI(PRA.getRegClassByID(IntRegClassID) /*LR->getRegClass()*/,
|
2002-05-19 15:25:51 +00:00
|
|
|
IntRegType, CallMI, &LVSetBef, AdIBefCC, AdIAftCC);
|
2002-03-18 03:12:16 +00:00
|
|
|
|
2001-11-03 19:59:59 +00:00
|
|
|
// insert the instructions in reverse order since we are
|
|
|
|
// adding them to the front of InstrnsBefore
|
2002-05-19 15:25:51 +00:00
|
|
|
AddedInstrns& addedI = PRA.AddedInstrMap[CallMI];
|
2001-11-03 19:59:59 +00:00
|
|
|
if(AdIAftCC)
|
2002-05-19 15:25:51 +00:00
|
|
|
addedI.InstrnsBefore.insert(addedI.InstrnsBefore.begin(),
|
|
|
|
AdIAftCC);
|
|
|
|
|
2001-11-03 19:59:59 +00:00
|
|
|
AdICpCC = cpCCR2IntMI(FreeIntReg);
|
2002-05-19 15:25:51 +00:00
|
|
|
addedI.InstrnsBefore.insert(addedI.InstrnsBefore.begin(),
|
|
|
|
AdICpCC);
|
|
|
|
|
2001-11-03 19:59:59 +00:00
|
|
|
if(AdIBefCC)
|
2002-05-19 15:25:51 +00:00
|
|
|
addedI.InstrnsBefore.insert(addedI.InstrnsBefore.begin(),
|
|
|
|
AdIBefCC);
|
|
|
|
|
2001-11-10 00:26:55 +00:00
|
|
|
if(DEBUG_RA) {
|
|
|
|
cerr << "\n!! Inserted caller saving (push) inst for %ccr:";
|
|
|
|
if(AdIBefCC) cerr << "\t" << *(AdIBefCC);
|
|
|
|
cerr << "\t" << *AdICpCC;
|
|
|
|
if(AdIAftCC) cerr << "\t" << *(AdIAftCC);
|
|
|
|
}
|
2001-11-03 19:59:59 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
// for any other register type, just add the push inst
|
2002-05-19 15:25:51 +00:00
|
|
|
cpReg2MemMI(Reg, getFramePointer(), StackOff, RegType,
|
|
|
|
PRA.AddedInstrMap[CallMI].InstrnsBefore);
|
2001-10-28 18:15:12 +00:00
|
|
|
}
|
2001-11-03 19:59:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
//---- Insert code for popping the reg from the stack ----------
|
|
|
|
|
2002-02-05 04:20:12 +00:00
|
|
|
if (RegType == IntCCRegType) {
|
2001-11-03 19:59:59 +00:00
|
|
|
|
|
|
|
// Handle IntCCRegType specially since we cannot directly
|
|
|
|
// pop %ccr on from the stack
|
|
|
|
|
|
|
|
// get a free INT register
|
|
|
|
int FreeIntReg =
|
2002-03-18 03:12:16 +00:00
|
|
|
PRA.getUsableUniRegAtMI(PRA.getRegClassByID(IntRegClassID) /* LR->getRegClass()*/,
|
2002-05-19 15:25:51 +00:00
|
|
|
IntRegType, CallMI, &LVSetAft, AdIBefCC, AdIAftCC);
|
2001-11-03 19:59:59 +00:00
|
|
|
|
|
|
|
if(AdIBefCC)
|
2002-05-19 15:25:51 +00:00
|
|
|
PRA.AddedInstrMap[CallMI].InstrnsAfter.push_back(AdIBefCC);
|
2001-11-03 19:59:59 +00:00
|
|
|
|
|
|
|
AdICpCC = cpInt2CCRMI(FreeIntReg);
|
2002-05-19 15:25:51 +00:00
|
|
|
PRA.AddedInstrMap[CallMI].InstrnsAfter.push_back(AdICpCC);
|
2001-10-28 18:15:12 +00:00
|
|
|
|
2001-11-03 19:59:59 +00:00
|
|
|
if(AdIAftCC)
|
2002-05-19 15:25:51 +00:00
|
|
|
PRA.AddedInstrMap[CallMI].InstrnsAfter.push_back(AdIAftCC);
|
2001-11-03 19:59:59 +00:00
|
|
|
|
2001-11-10 00:26:55 +00:00
|
|
|
if(DEBUG_RA) {
|
|
|
|
|
|
|
|
cerr << "\n!! Inserted caller saving (pop) inst for %ccr:";
|
|
|
|
if(AdIBefCC) cerr << "\t" << *(AdIBefCC);
|
|
|
|
cerr << "\t" << *AdICpCC;
|
|
|
|
if(AdIAftCC) cerr << "\t" << *(AdIAftCC);
|
|
|
|
}
|
2001-11-03 19:59:59 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
// for any other register type, just add the pop inst
|
2002-05-19 15:25:51 +00:00
|
|
|
cpMem2RegMI(getFramePointer(), StackOff, Reg, RegType,
|
|
|
|
PRA.AddedInstrMap[CallMI].InstrnsAfter);
|
2001-11-03 19:59:59 +00:00
|
|
|
}
|
2001-10-28 18:15:12 +00:00
|
|
|
|
2002-02-05 04:20:12 +00:00
|
|
|
PushedRegSet.insert(Reg);
|
2001-10-28 18:15:12 +00:00
|
|
|
|
2001-11-10 00:26:55 +00:00
|
|
|
if(DEBUG_RA) {
|
2002-05-19 15:25:51 +00:00
|
|
|
cerr << "\nFor call inst:" << *CallMI;
|
2001-11-10 00:26:55 +00:00
|
|
|
cerr << " -inserted caller saving instrs:\n\t ";
|
2002-03-18 03:12:16 +00:00
|
|
|
if( RegType == IntCCRegType ) {
|
|
|
|
if(AdIBefCC) cerr << *AdIBefCC << "\t";
|
|
|
|
if(AdIAftCC) cerr << *AdIAftCC;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(AdIBef) cerr << *AdIBef << "\t";
|
|
|
|
if(AdIAft) cerr << *AdIAft;
|
|
|
|
}
|
2001-10-28 18:15:12 +00:00
|
|
|
}
|
|
|
|
} // if not already pushed
|
|
|
|
|
|
|
|
} // if LR has a volatile color
|
|
|
|
|
|
|
|
} // if LR has color
|
|
|
|
|
|
|
|
} // if there is a LR for Var
|
|
|
|
|
|
|
|
} // for each value in the LV set after instruction
|
|
|
|
|
2001-09-18 22:52:44 +00:00
|
|
|
}
|
|
|
|
|
2001-11-03 19:59:59 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// Copies %ccr into an integer register. IntReg is the UNIFIED register
|
|
|
|
// number.
|
|
|
|
//---------------------------------------------------------------------------
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2002-02-04 05:59:25 +00:00
|
|
|
MachineInstr * UltraSparcRegInfo::cpCCR2IntMI(unsigned IntReg) const {
|
|
|
|
MachineInstr * MI = new MachineInstr(RDCCR, 2);
|
2002-03-18 03:12:16 +00:00
|
|
|
MI->SetMachineOperandReg(0, this->getUnifiedRegNum(UltraSparcRegInfo::IntCCRegClassID,
|
|
|
|
SparcIntCCRegOrder::ccr),
|
|
|
|
false, true);
|
|
|
|
MI->SetMachineOperandReg(1, IntReg, true);
|
2001-11-03 19:59:59 +00:00
|
|
|
return MI;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// Copies an integer register into %ccr. IntReg is the UNIFIED register
|
|
|
|
// number.
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2002-02-04 05:59:25 +00:00
|
|
|
MachineInstr *UltraSparcRegInfo::cpInt2CCRMI(unsigned IntReg) const {
|
|
|
|
MachineInstr *MI = new MachineInstr(WRCCR, 3);
|
2002-03-18 03:12:16 +00:00
|
|
|
MI->SetMachineOperandReg(0, IntReg, false);
|
|
|
|
MI->SetMachineOperandReg(1, this->getZeroRegNum(), false);
|
|
|
|
MI->SetMachineOperandReg(2, this->getUnifiedRegNum(UltraSparcRegInfo::IntCCRegClassID, SparcIntCCRegOrder::ccr),
|
|
|
|
true, true);
|
2001-11-03 19:59:59 +00:00
|
|
|
return MI;
|
|
|
|
}
|
2001-09-30 23:16:47 +00:00
|
|
|
|
|
|
|
|
2001-10-28 18:15:12 +00:00
|
|
|
|
|
|
|
|
2001-09-18 22:52:44 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// Print the register assigned to a LR
|
|
|
|
//---------------------------------------------------------------------------
|
2001-09-14 20:31:39 +00:00
|
|
|
|
2002-02-04 05:59:25 +00:00
|
|
|
void UltraSparcRegInfo::printReg(const LiveRange *LR) {
|
2001-09-18 22:52:44 +00:00
|
|
|
unsigned RegClassID = (LR->getRegClass())->getID();
|
2001-10-15 18:15:27 +00:00
|
|
|
cerr << " *Node " << (LR->getUserIGNode())->getIndex();
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2002-02-04 05:59:25 +00:00
|
|
|
if (!LR->hasColor()) {
|
2002-01-20 22:54:45 +00:00
|
|
|
cerr << " - could not find a color\n";
|
2001-09-18 22:52:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if a color is found
|
2001-09-14 20:31:39 +00:00
|
|
|
|
2001-10-15 18:15:27 +00:00
|
|
|
cerr << " colored with color "<< LR->getColor();
|
2001-09-14 20:31:39 +00:00
|
|
|
|
2002-02-04 05:59:25 +00:00
|
|
|
if (RegClassID == IntRegClassID) {
|
2002-01-20 22:54:45 +00:00
|
|
|
cerr<< " [" << SparcIntRegOrder::getRegName(LR->getColor()) << "]\n";
|
2001-09-14 20:31:39 +00:00
|
|
|
|
2002-02-04 05:59:25 +00:00
|
|
|
} else if (RegClassID == FloatRegClassID) {
|
2001-10-15 18:15:27 +00:00
|
|
|
cerr << "[" << SparcFloatRegOrder::getRegName(LR->getColor());
|
2002-02-05 03:52:29 +00:00
|
|
|
if( LR->getType() == Type::DoubleTy)
|
2001-10-15 18:15:27 +00:00
|
|
|
cerr << "+" << SparcFloatRegOrder::getRegName(LR->getColor()+1);
|
2002-01-20 22:54:45 +00:00
|
|
|
cerr << "]\n";
|
2001-09-18 22:52:44 +00:00
|
|
|
}
|
|
|
|
}
|
2001-11-09 23:49:14 +00:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// This method examines instructions inserted by RegAlloc code before a
|
|
|
|
// machine instruction to detect invalid orders that destroy values before
|
|
|
|
// they are used. If it detects such conditions, it reorders the instructions.
|
|
|
|
//
|
|
|
|
// The unordered instructions come in the UnordVec. These instructions are
|
2001-11-10 21:20:43 +00:00
|
|
|
// instructions inserted by RegAlloc. All such instruction MUST have
|
|
|
|
// their USES BEFORE THE DEFS after reordering.
|
2002-05-19 15:25:51 +00:00
|
|
|
//
|
2001-11-09 23:49:14 +00:00
|
|
|
// The UnordVec & OrdVec must be DISTINCT. The OrdVec must be empty when
|
|
|
|
// this method is called.
|
2002-05-19 15:25:51 +00:00
|
|
|
//
|
2001-11-09 23:49:14 +00:00
|
|
|
// This method uses two vectors for efficiency in accessing
|
2002-05-19 15:25:51 +00:00
|
|
|
//
|
2001-11-10 21:20:43 +00:00
|
|
|
// Since instructions are inserted in RegAlloc, this assumes that the
|
|
|
|
// first operand is the source reg and the last operand is the dest reg.
|
2002-05-19 15:25:51 +00:00
|
|
|
//
|
2001-11-10 21:20:43 +00:00
|
|
|
// All the uses are before THE def to a register
|
2001-11-09 23:49:14 +00:00
|
|
|
//---------------------------------------------------------------------------
|
2002-05-19 15:25:51 +00:00
|
|
|
|
|
|
|
void UltraSparcRegInfo::OrderAddedInstrns(std::vector<MachineInstr*> &UnordVec,
|
|
|
|
std::vector<MachineInstr*> &OrdVec,
|
2002-01-20 22:54:45 +00:00
|
|
|
PhyRegAlloc &PRA) const{
|
2001-11-09 23:49:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Problem: We can have instructions inserted by RegAlloc like
|
|
|
|
1. add %ox %g0 %oy
|
|
|
|
2. add %oy %g0 %oz, where z!=x or z==x
|
|
|
|
|
|
|
|
This is wrong since %oy used by 2 is overwritten by 1
|
2001-11-10 21:20:43 +00:00
|
|
|
|
|
|
|
Solution:
|
|
|
|
We re-order the instructions so that the uses are before the defs
|
2001-11-09 23:49:14 +00:00
|
|
|
|
2001-11-10 21:20:43 +00:00
|
|
|
Algorithm:
|
|
|
|
|
|
|
|
do
|
|
|
|
for each instruction 'DefInst' in the UnOrdVec
|
|
|
|
for each instruction 'UseInst' that follows the DefInst
|
|
|
|
if the reg defined by DefInst is used by UseInst
|
|
|
|
mark DefInst as not movable in this iteration
|
|
|
|
If DefInst is not marked as not-movable, move DefInst to OrdVec
|
|
|
|
while all instructions in DefInst are moved to OrdVec
|
|
|
|
|
|
|
|
For moving, we call the move2OrdVec(). It checks whether there is a def
|
|
|
|
in it for the uses in the instruction to be added to OrdVec. If there
|
|
|
|
are no preceding defs, it just appends the instruction. If there is a
|
|
|
|
preceding def, it puts two instructions to save the reg on stack before
|
|
|
|
the load and puts a restore at use.
|
2001-11-09 23:49:14 +00:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
2001-11-10 21:20:43 +00:00
|
|
|
bool CouldMoveAll;
|
|
|
|
bool DebugPrint = false;
|
2001-11-09 23:49:14 +00:00
|
|
|
|
2001-11-10 21:20:43 +00:00
|
|
|
do {
|
|
|
|
CouldMoveAll = true;
|
2002-01-20 22:54:45 +00:00
|
|
|
std::vector<MachineInstr *>::iterator DefIt = UnordVec.begin();
|
2001-11-09 23:49:14 +00:00
|
|
|
|
2001-11-10 21:20:43 +00:00
|
|
|
for( ; DefIt != UnordVec.end(); ++DefIt ) {
|
2001-11-09 23:49:14 +00:00
|
|
|
|
2001-11-10 21:20:43 +00:00
|
|
|
// for each instruction in the UnordVec do ...
|
2001-11-09 23:49:14 +00:00
|
|
|
|
2001-11-10 21:20:43 +00:00
|
|
|
MachineInstr *DefInst = *DefIt;
|
2001-11-09 23:49:14 +00:00
|
|
|
|
2001-11-10 21:20:43 +00:00
|
|
|
if( DefInst == NULL) continue;
|
2001-11-09 23:49:14 +00:00
|
|
|
|
2001-11-10 21:20:43 +00:00
|
|
|
//cerr << "\nInst in UnordVec = " << *DefInst;
|
|
|
|
|
|
|
|
// last operand is the def (unless for a store which has no def reg)
|
|
|
|
MachineOperand& DefOp = DefInst->getOperand(DefInst->getNumOperands()-1);
|
|
|
|
|
2001-11-09 23:49:14 +00:00
|
|
|
if( DefOp.opIsDef() &&
|
|
|
|
DefOp.getOperandType() == MachineOperand::MO_MachineRegister) {
|
2001-11-10 21:20:43 +00:00
|
|
|
|
2001-11-09 23:49:14 +00:00
|
|
|
// If the operand in DefInst is a def ...
|
2001-11-10 21:20:43 +00:00
|
|
|
|
2001-11-09 23:49:14 +00:00
|
|
|
bool DefEqUse = false;
|
2001-11-10 21:20:43 +00:00
|
|
|
|
2002-01-20 22:54:45 +00:00
|
|
|
std::vector<MachineInstr *>::iterator UseIt = DefIt;
|
2001-11-09 23:49:14 +00:00
|
|
|
UseIt++;
|
2001-11-10 21:20:43 +00:00
|
|
|
|
2001-11-09 23:49:14 +00:00
|
|
|
for( ; UseIt != UnordVec.end(); ++UseIt ) {
|
|
|
|
|
|
|
|
MachineInstr *UseInst = *UseIt;
|
2001-11-10 21:20:43 +00:00
|
|
|
if( UseInst == NULL) continue;
|
|
|
|
|
|
|
|
// for each inst (UseInst) that is below the DefInst do ...
|
|
|
|
MachineOperand& UseOp = UseInst->getOperand(0);
|
|
|
|
|
|
|
|
if( ! UseOp.opIsDef() &&
|
|
|
|
UseOp.getOperandType() == MachineOperand::MO_MachineRegister) {
|
|
|
|
|
|
|
|
// if use is a register ...
|
|
|
|
|
|
|
|
if( DefOp.getMachineRegNum() == UseOp.getMachineRegNum() ) {
|
|
|
|
|
|
|
|
// if Def and this use are the same, it means that this use
|
|
|
|
// is destroyed by a def before it is used
|
|
|
|
|
|
|
|
// cerr << "\nCouldn't move " << *DefInst;
|
2001-11-09 23:49:14 +00:00
|
|
|
|
2001-11-10 21:20:43 +00:00
|
|
|
DefEqUse = true;
|
|
|
|
CouldMoveAll = false;
|
|
|
|
DebugPrint = true;
|
|
|
|
break;
|
|
|
|
} // if two registers are equal
|
|
|
|
|
|
|
|
} // if use is a register
|
|
|
|
|
|
|
|
}// for all use instructions
|
|
|
|
|
|
|
|
if( ! DefEqUse ) {
|
|
|
|
|
|
|
|
// after examining all the instructions that follow the DefInst
|
|
|
|
// if there are no dependencies, we can move it to the OrdVec
|
2001-11-09 23:49:14 +00:00
|
|
|
|
2001-11-10 21:20:43 +00:00
|
|
|
// cerr << "Moved to Ord: " << *DefInst;
|
2001-11-09 23:49:14 +00:00
|
|
|
|
2001-11-10 21:20:43 +00:00
|
|
|
moveInst2OrdVec(OrdVec, DefInst, PRA);
|
2001-11-09 23:49:14 +00:00
|
|
|
|
2001-11-10 21:20:43 +00:00
|
|
|
//OrdVec.push_back(DefInst);
|
2001-11-09 23:49:14 +00:00
|
|
|
|
2001-11-10 21:20:43 +00:00
|
|
|
// mark the pos of DefInst with NULL to indicate that it is
|
|
|
|
// empty
|
2001-11-09 23:49:14 +00:00
|
|
|
*DefIt = NULL;
|
|
|
|
}
|
2001-11-10 21:20:43 +00:00
|
|
|
|
2001-11-09 23:49:14 +00:00
|
|
|
} // if Def is a machine register
|
2001-11-10 21:20:43 +00:00
|
|
|
|
|
|
|
} // for all instructions in the UnordVec
|
|
|
|
|
2001-11-09 23:49:14 +00:00
|
|
|
|
2002-02-04 05:59:25 +00:00
|
|
|
} while(!CouldMoveAll);
|
2001-11-09 23:49:14 +00:00
|
|
|
|
2002-02-04 05:59:25 +00:00
|
|
|
if (DebugPrint) {
|
2001-11-10 21:20:43 +00:00
|
|
|
cerr << "\nAdded instructions were reordered to:\n";
|
|
|
|
for(unsigned int i=0; i < OrdVec.size(); i++)
|
|
|
|
cerr << *(OrdVec[i]);
|
2001-11-09 23:49:14 +00:00
|
|
|
}
|
2001-11-10 21:20:43 +00:00
|
|
|
}
|
2001-11-09 23:49:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-01-20 22:54:45 +00:00
|
|
|
void UltraSparcRegInfo::moveInst2OrdVec(std::vector<MachineInstr *> &OrdVec,
|
2001-11-10 21:20:43 +00:00
|
|
|
MachineInstr *UnordInst,
|
2002-02-04 05:59:25 +00:00
|
|
|
PhyRegAlloc &PRA) const {
|
2001-11-10 21:20:43 +00:00
|
|
|
MachineOperand& UseOp = UnordInst->getOperand(0);
|
2001-11-09 23:49:14 +00:00
|
|
|
|
2001-11-10 21:20:43 +00:00
|
|
|
if( ! UseOp.opIsDef() &&
|
|
|
|
UseOp.getOperandType() == MachineOperand::MO_MachineRegister) {
|
2001-11-09 23:49:14 +00:00
|
|
|
|
2001-11-10 21:20:43 +00:00
|
|
|
// for the use of UnordInst, see whether there is a defining instr
|
|
|
|
// before in the OrdVec
|
|
|
|
bool DefEqUse = false;
|
2001-11-09 23:49:14 +00:00
|
|
|
|
2002-01-20 22:54:45 +00:00
|
|
|
std::vector<MachineInstr *>::iterator OrdIt = OrdVec.begin();
|
2001-11-10 21:20:43 +00:00
|
|
|
|
|
|
|
for( ; OrdIt != OrdVec.end(); ++OrdIt ) {
|
2001-11-09 23:49:14 +00:00
|
|
|
|
2001-11-10 21:20:43 +00:00
|
|
|
MachineInstr *OrdInst = *OrdIt ;
|
2001-11-09 23:49:14 +00:00
|
|
|
|
2001-11-10 21:20:43 +00:00
|
|
|
MachineOperand& DefOp =
|
|
|
|
OrdInst->getOperand(OrdInst->getNumOperands()-1);
|
2001-11-09 23:49:14 +00:00
|
|
|
|
2001-11-10 21:20:43 +00:00
|
|
|
if( DefOp.opIsDef() &&
|
|
|
|
DefOp.getOperandType() == MachineOperand::MO_MachineRegister) {
|
2001-11-09 23:49:14 +00:00
|
|
|
|
2001-11-10 21:20:43 +00:00
|
|
|
//cerr << "\nDefining Ord Inst: " << *OrdInst;
|
|
|
|
|
|
|
|
if( DefOp.getMachineRegNum() == UseOp.getMachineRegNum() ) {
|
|
|
|
|
|
|
|
// we are here because there is a preceding def in the OrdVec
|
|
|
|
// for the use in this intr we are going to insert. This
|
|
|
|
// happened because the original code was like:
|
|
|
|
// 1. add %ox %g0 %oy
|
|
|
|
// 2. add %oy %g0 %ox
|
|
|
|
// In Round1, we added 2 to OrdVec but 1 remained in UnordVec
|
|
|
|
// Now we are processing %ox of 1.
|
|
|
|
// We have to
|
|
|
|
|
|
|
|
const int UReg = DefOp.getMachineRegNum();
|
|
|
|
const int RegType = getRegType(UReg);
|
|
|
|
MachineInstr *AdIBef, *AdIAft;
|
|
|
|
|
2002-01-07 19:20:28 +00:00
|
|
|
const int StackOff = PRA.mcInfo.pushTempValue(target,
|
|
|
|
getSpilledRegSize(RegType));
|
2001-11-10 21:20:43 +00:00
|
|
|
|
|
|
|
// Save the UReg (%ox) on stack before it's destroyed
|
2002-05-19 15:25:51 +00:00
|
|
|
vector<MachineInstr*> mvec;
|
|
|
|
cpReg2MemMI(UReg, getFramePointer(), StackOff, RegType, mvec);
|
|
|
|
for (vector<MachineInstr*>::iterator MI=mvec.begin(); MI != mvec.end(); ++MI) {
|
|
|
|
OrdIt = OrdVec.insert(OrdIt, *MI);
|
|
|
|
++OrdIt; // OrdIt must still point to current instr we processed
|
|
|
|
}
|
2001-11-10 21:20:43 +00:00
|
|
|
|
|
|
|
// Load directly into DReg (%oy)
|
|
|
|
MachineOperand& DOp=
|
|
|
|
(UnordInst->getOperand(UnordInst->getNumOperands()-1));
|
|
|
|
assert(DOp.opIsDef() && "Last operand is not the def");
|
|
|
|
const int DReg = DOp.getMachineRegNum();
|
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
cpMem2RegMI(getFramePointer(), StackOff, DReg, RegType, OrdVec);
|
2001-11-10 21:20:43 +00:00
|
|
|
|
|
|
|
cerr << "\nFixed CIRCULAR references by reordering";
|
2001-11-09 23:49:14 +00:00
|
|
|
|
2001-11-10 21:20:43 +00:00
|
|
|
if( DEBUG_RA ) {
|
|
|
|
cerr << "\nBefore CIRCULAR Reordering:\n";
|
|
|
|
cerr << *UnordInst;
|
|
|
|
cerr << *OrdInst;
|
|
|
|
|
|
|
|
cerr << "\nAfter CIRCULAR Reordering - All Inst so far:\n";
|
|
|
|
for(unsigned i=0; i < OrdVec.size(); i++)
|
|
|
|
cerr << *(OrdVec[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do not copy the UseInst to OrdVec
|
|
|
|
DefEqUse = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}// if two registers are equal
|
2001-11-09 23:49:14 +00:00
|
|
|
|
2001-11-10 21:20:43 +00:00
|
|
|
} // if Def is a register
|
2001-11-09 23:49:14 +00:00
|
|
|
|
2001-11-10 21:20:43 +00:00
|
|
|
} // for each instr in OrdVec
|
2001-11-09 23:49:14 +00:00
|
|
|
|
2002-02-04 05:59:25 +00:00
|
|
|
if(!DefEqUse) {
|
2001-11-09 23:49:14 +00:00
|
|
|
|
2001-11-10 21:20:43 +00:00
|
|
|
// We didn't find a def in the OrdVec, so just append this inst
|
|
|
|
OrdVec.push_back( UnordInst );
|
|
|
|
//cerr << "Reordered Inst (Moved Dn): " << *UnordInst;
|
|
|
|
}
|
2001-11-09 23:49:14 +00:00
|
|
|
|
2001-11-10 21:20:43 +00:00
|
|
|
}// if the operand in UnordInst is a use
|
|
|
|
}
|