2001-09-18 22:52:44 +00:00
|
|
|
#include "llvm/Target/Sparc.h"
|
2001-09-15 00:30:44 +00:00
|
|
|
#include "SparcInternals.h"
|
2001-09-18 22:52:44 +00:00
|
|
|
#include "llvm/Method.h"
|
|
|
|
#include "llvm/iTerminators.h"
|
2001-09-30 23:16:47 +00:00
|
|
|
#include "llvm/iOther.h"
|
2001-09-18 22:52:44 +00:00
|
|
|
#include "llvm/CodeGen/InstrScheduling.h"
|
|
|
|
#include "llvm/CodeGen/InstrSelection.h"
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2001-09-18 22:52:44 +00:00
|
|
|
#include "llvm/Analysis/LiveVar/MethodLiveVarInfo.h"
|
|
|
|
#include "llvm/CodeGen/PhyRegAlloc.h"
|
2001-09-14 03:47:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-09-18 22:52:44 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// UltraSparcRegInfo
|
|
|
|
//---------------------------------------------------------------------------
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
//---------------------------------------------------------------------------
|
2001-10-15 16:25:28 +00:00
|
|
|
// Suggests a register for the ret address in the RET machine instruction
|
2001-09-30 23:16:47 +00:00
|
|
|
//---------------------------------------------------------------------------
|
2001-10-15 16:25:28 +00:00
|
|
|
void UltraSparcRegInfo::suggestReg4RetAddr(const MachineInstr * RetMI,
|
|
|
|
LiveRangeInfo& LRI) const {
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
assert( (RetMI->getNumOperands() == 2) && "RETURN must have 2 operands");
|
|
|
|
MachineOperand & MO = ( MachineOperand &) RetMI->getOperand(0);
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
MO.setRegForValue( getUnifiedRegNum( IntRegClassID, SparcIntRegOrder::i7) );
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
// TODO (Optimize):
|
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
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
/*
|
|
|
|
const Value *RetAddrVal = MO.getVRegValue();
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
assert( RetAddrVal && "LR for ret address must be created at start");
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
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
|
|
|
//---------------------------------------------------------------------------
|
2001-10-15 16:25:28 +00:00
|
|
|
// Suggests a register for the ret address in the JMPL/CALL machine instr
|
2001-09-18 22:52:44 +00:00
|
|
|
//---------------------------------------------------------------------------
|
2001-10-15 16:25:28 +00:00
|
|
|
void UltraSparcRegInfo::suggestReg4CallAddr(const MachineInstr * CallMI) const
|
|
|
|
{
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
assert( (CallMI->getNumOperands() == 3) && "JMPL must have 3 operands");
|
|
|
|
|
|
|
|
// directly set color since the LR of ret address (if there were one)
|
|
|
|
// will not extend after the call instr
|
|
|
|
|
|
|
|
MachineOperand & MO = ( MachineOperand &) CallMI->getOperand(2);
|
|
|
|
MO.setRegForValue( getUnifiedRegNum( IntRegClassID,SparcIntRegOrder::o7) );
|
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.
|
|
|
|
// If the arg is passed on stack due to the lack of regs, NOTHING will be
|
|
|
|
// done - it will be colored (or spilled) as a normal value.
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void UltraSparcRegInfo::suggestRegs4MethodArgs(const Method *const Meth,
|
|
|
|
LiveRangeInfo& LRI) const
|
2001-09-18 22:52:44 +00:00
|
|
|
{
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2001-09-18 22:52:44 +00:00
|
|
|
// get the argument list
|
|
|
|
const Method::ArgumentListType& ArgList = Meth->getArgumentList();
|
|
|
|
// get an iterator to arg list
|
|
|
|
Method::ArgumentListType::const_iterator ArgIt = ArgList.begin();
|
|
|
|
|
|
|
|
// for each argument
|
2001-09-30 23:16:47 +00:00
|
|
|
for( unsigned argNo=0; ArgIt != ArgList.end() ; ++ArgIt, ++argNo) {
|
2001-09-18 22:52:44 +00:00
|
|
|
|
|
|
|
// get the LR of arg
|
|
|
|
LiveRange *const LR = LRI.getLiveRangeForValue((const Value *) *ArgIt);
|
2001-09-30 23:16:47 +00:00
|
|
|
assert( LR && "No live range found for method arg");
|
|
|
|
|
|
|
|
unsigned RegType = getRegType( LR );
|
|
|
|
|
2001-09-18 22:52:44 +00:00
|
|
|
|
|
|
|
// if the arg is in int class - allocate a reg for an int arg
|
2001-09-30 23:16:47 +00:00
|
|
|
if( RegType == IntRegType ) {
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
if( argNo < NumOfIntArgRegs) {
|
|
|
|
LR->setSuggestedColor( SparcIntRegOrder::i0 + argNo );
|
2001-09-18 22:52:44 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
2001-09-30 23:16:47 +00:00
|
|
|
// Do NOTHING as this will be colored as a normal value.
|
2001-10-15 18:15:27 +00:00
|
|
|
if (DEBUG_RA) cerr << " Int Regr not suggested for method arg\n";
|
2001-09-18 22:52:44 +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
|
|
|
else if( RegType==FPSingleRegType && (argNo*2+1) < NumOfFloatArgRegs)
|
|
|
|
LR->setSuggestedColor( SparcFloatRegOrder::f0 + (argNo * 2 + 1) );
|
|
|
|
|
|
|
|
|
|
|
|
else if( RegType == FPDoubleRegType && (argNo*2) < NumOfFloatArgRegs)
|
|
|
|
LR->setSuggestedColor( SparcFloatRegOrder::f0 + (argNo * 2) );
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
void UltraSparcRegInfo::colorMethodArgs(const Method *const Meth,
|
|
|
|
LiveRangeInfo& LRI,
|
|
|
|
AddedInstrns *const FirstAI) const {
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
// get the argument list
|
|
|
|
const Method::ArgumentListType& ArgList = Meth->getArgumentList();
|
|
|
|
// get an iterator to arg list
|
|
|
|
Method::ArgumentListType::const_iterator ArgIt = ArgList.begin();
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
MachineInstr *AdMI;
|
2001-09-18 22:52:44 +00:00
|
|
|
|
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
// for each argument
|
|
|
|
for( unsigned argNo=0; ArgIt != ArgList.end() ; ++ArgIt, ++argNo) {
|
|
|
|
|
|
|
|
// get the LR of arg
|
|
|
|
LiveRange *const LR = LRI.getLiveRangeForValue((const Value *) *ArgIt);
|
|
|
|
assert( LR && "No live range found for method arg");
|
|
|
|
|
|
|
|
|
|
|
|
// if the LR received the suggested color, NOTHING to be done
|
|
|
|
if( LR->hasSuggestedColor() && LR->hasColor() )
|
|
|
|
if( LR->getSuggestedColor() == LR->getColor() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// We are here because the LR did not have a suggested
|
|
|
|
// color or did not receive the suggested color. Now handle
|
|
|
|
// individual cases.
|
|
|
|
|
|
|
|
|
|
|
|
unsigned RegType = getRegType( LR );
|
|
|
|
unsigned RegClassID = (LR->getRegClass())->getID();
|
|
|
|
|
|
|
|
|
|
|
|
// find whether this argument is coming in a register (if not, on stack)
|
|
|
|
|
|
|
|
bool isArgInReg = false;
|
|
|
|
unsigned UniArgReg = InvalidRegNum;
|
|
|
|
|
|
|
|
if( (RegType== IntRegType && argNo < NumOfIntArgRegs)) {
|
|
|
|
isArgInReg = true;
|
|
|
|
UniArgReg = getUnifiedRegNum( RegClassID, SparcIntRegOrder::o0 + argNo );
|
|
|
|
}
|
|
|
|
else if(RegType == FPSingleRegType && argNo < NumOfFloatArgRegs) {
|
|
|
|
isArgInReg = true;
|
|
|
|
UniArgReg = getUnifiedRegNum( RegClassID,
|
|
|
|
SparcFloatRegOrder::f0 + argNo*2 + 1 ) ;
|
|
|
|
}
|
|
|
|
else if(RegType == FPDoubleRegType && argNo < NumOfFloatArgRegs) {
|
|
|
|
isArgInReg = true;
|
|
|
|
UniArgReg = getUnifiedRegNum(RegClassID, SparcFloatRegOrder::f0+argNo*2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if( LR->hasColor() ) {
|
|
|
|
|
|
|
|
// We are here because the LR did not have a suggested
|
|
|
|
// color or did not receive the suggested color but LR got a register.
|
|
|
|
// Now we have to copy %ix reg (or stack pos of arg)
|
|
|
|
// to the register it was colored with.
|
|
|
|
|
|
|
|
unsigned UniLRReg = getUnifiedRegNum( RegClassID, LR->getColor() );
|
|
|
|
|
|
|
|
// if the arg is coming in a register and goes into a register
|
|
|
|
if( isArgInReg )
|
|
|
|
AdMI = cpReg2RegMI(UniArgReg, UniLRReg, RegType );
|
2001-09-18 22:52:44 +00:00
|
|
|
|
|
|
|
else
|
2001-09-30 23:16:47 +00:00
|
|
|
assert(0 && "TODO: Color an Incoming arg on stack");
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
// Now add the instruction
|
|
|
|
FirstAI->InstrnsBefore.push_back( AdMI );
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else { // LR is not colored (i.e., spilled)
|
|
|
|
|
|
|
|
assert(0 && "TODO: Color a spilled arg ");
|
|
|
|
|
|
|
|
}
|
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.
|
|
|
|
//---------------------------------------------------------------------------
|
2001-10-15 16:25:28 +00:00
|
|
|
void UltraSparcRegInfo::suggestRegs4CallArgs(const MachineInstr *const CallMI,
|
2001-09-30 23:16:47 +00:00
|
|
|
LiveRangeInfo& LRI,
|
|
|
|
vector<RegClass *> RCList) const {
|
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
assert ( (UltraSparcInfo->getInstrInfo()).isCall(CallMI->getOpCode()) );
|
|
|
|
|
|
|
|
suggestReg4CallAddr(CallMI);
|
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
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
unsigned NumOfImpRefs = CallMI->getNumImplicitRefs();
|
|
|
|
unsigned NumOfCallArgs = NumOfImpRefs; // assume all implicits are args
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
if( NumOfImpRefs > 0 ) {
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
// The last implicit operand is the return value of a call
|
|
|
|
if( CallMI->implicitRefIsDefined(NumOfImpRefs-1) ) {
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
const Value *RetVal = CallMI->getImplicitRef(NumOfImpRefs-1);
|
|
|
|
|
|
|
|
assert( (! LRI.getLiveRangeForValue( RetVal ) ) &&
|
|
|
|
"LR for ret Value of call already definded!");
|
2001-09-30 23:16:47 +00:00
|
|
|
|
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
// create a new LR for the return value
|
|
|
|
|
|
|
|
LiveRange * RetValLR = new LiveRange();
|
|
|
|
RetValLR->add( RetVal );
|
|
|
|
unsigned RegClassID = getRegClassIDOfValue( RetVal );
|
|
|
|
RetValLR->setRegClass( RCList[RegClassID] );
|
|
|
|
LRI.addLRToMap( RetVal, RetValLR);
|
|
|
|
|
|
|
|
// now suggest a register depending on the register class of ret arg
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
// the last imp ref is the def, so one less arg
|
|
|
|
NumOfCallArgs--;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
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-15 16:25:28 +00:00
|
|
|
// go thru call args - implicit operands of the call MI
|
|
|
|
for(unsigned argNo=0, i=0; i < NumOfCallArgs; ++i, ++argNo ) {
|
|
|
|
|
|
|
|
const Value *CallArg = CallMI->getImplicitRef(i);
|
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);
|
2001-09-30 23:16:47 +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
|
|
|
|
if( !LR ) {
|
2001-09-30 23:16:47 +00:00
|
|
|
if( DEBUG_RA) {
|
2001-10-15 18:15:27 +00:00
|
|
|
cerr << " ERROR: In call instr, no LR for arg: " ;
|
|
|
|
printValue(CallArg); cerr << endl;
|
2001-09-18 22:52:44 +00:00
|
|
|
}
|
2001-10-15 16:25:28 +00:00
|
|
|
assert(0 && "NO LR for call arg");
|
|
|
|
// continue;
|
2001-09-14 03:47:57 +00:00
|
|
|
}
|
2001-09-30 23:16:47 +00:00
|
|
|
|
|
|
|
unsigned RegType = getRegType( LR );
|
|
|
|
|
|
|
|
// if the arg is in int class - allocate a reg for an int arg
|
|
|
|
if( RegType == IntRegType ) {
|
|
|
|
|
|
|
|
if( argNo < NumOfIntArgRegs)
|
|
|
|
LR->setSuggestedColor( SparcIntRegOrder::o0 + argNo );
|
|
|
|
|
|
|
|
else if (DEBUG_RA)
|
|
|
|
// Do NOTHING as this will be colored as a normal value.
|
2001-10-15 18:15:27 +00:00
|
|
|
cerr << " Regr not suggested for int call arg" << endl;
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2001-09-14 03:47:57 +00:00
|
|
|
}
|
2001-09-30 23:16:47 +00:00
|
|
|
else if( RegType == FPSingleRegType && (argNo*2 +1)< NumOfFloatArgRegs)
|
|
|
|
LR->setSuggestedColor( SparcFloatRegOrder::f0 + (argNo * 2 + 1) );
|
|
|
|
|
|
|
|
|
|
|
|
else if( RegType == FPDoubleRegType && (argNo*2) < NumOfFloatArgRegs)
|
|
|
|
LR->setSuggestedColor( SparcFloatRegOrder::f0 + (argNo * 2) );
|
|
|
|
|
2001-09-18 22:52:44 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
void UltraSparcRegInfo::colorCallArgs(const MachineInstr *const CallMI,
|
2001-09-30 23:16:47 +00:00
|
|
|
LiveRangeInfo& LRI,
|
|
|
|
AddedInstrns *const CallAI) const {
|
2001-09-18 22:52:44 +00:00
|
|
|
|
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
assert ( (UltraSparcInfo->getInstrInfo()).isCall(CallMI->getOpCode()) );
|
|
|
|
|
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
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
unsigned NumOfImpRefs = CallMI->getNumImplicitRefs();
|
|
|
|
unsigned NumOfCallArgs = NumOfImpRefs; // assume all implicits are args
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
if( NumOfImpRefs > 0 ) {
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
// The last implicit operand is the return value of a call
|
|
|
|
if( CallMI->implicitRefIsDefined(NumOfImpRefs-1) ) {
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
// one less call arg since last implicit ref is the return value
|
|
|
|
NumOfCallArgs--;
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
// find the return value and its LR
|
|
|
|
const Value *RetVal = CallMI->getImplicitRef(NumOfImpRefs-1);
|
|
|
|
LiveRange * RetValLR = LRI.getLiveRangeForValue( RetVal );
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
if( !RetValLR ) {
|
2001-10-15 18:15:27 +00:00
|
|
|
cerr << "\nNo LR for:";
|
2001-10-15 16:25:28 +00:00
|
|
|
printValue( RetVal );
|
2001-10-15 18:15:27 +00:00
|
|
|
cerr << endl;
|
2001-10-15 16:25:28 +00:00
|
|
|
assert( RetValLR && "ERR:No LR for non-void return value");
|
|
|
|
//return;
|
|
|
|
}
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
bool recvSugColor = false;
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
if( RetValLR->hasSuggestedColor() && RetValLR->hasColor() )
|
|
|
|
if( RetValLR->getSuggestedColor() == RetValLR->getColor())
|
|
|
|
recvSugColor = true;
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
// if we didn't receive the suggested color for some reason,
|
|
|
|
// put copy instruction
|
|
|
|
|
|
|
|
if( !recvSugColor ) {
|
|
|
|
|
|
|
|
if( RetValLR->hasColor() ) {
|
|
|
|
|
|
|
|
unsigned RegType = getRegType( RetValLR );
|
|
|
|
unsigned RegClassID = (RetValLR->getRegClass())->getID();
|
|
|
|
|
|
|
|
unsigned
|
|
|
|
UniRetLRReg=getUnifiedRegNum(RegClassID,RetValLR->getColor());
|
|
|
|
unsigned UniRetReg = InvalidRegNum;
|
|
|
|
|
|
|
|
// find where we receive the return value depending on
|
|
|
|
// register class
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
if(RegClassID == IntRegClassID)
|
|
|
|
UniRetReg = getUnifiedRegNum( RegClassID, SparcIntRegOrder::o0);
|
|
|
|
else if(RegClassID == FloatRegClassID)
|
|
|
|
UniRetReg = getUnifiedRegNum( RegClassID, SparcFloatRegOrder::f0);
|
2001-09-30 23:16:47 +00:00
|
|
|
|
|
|
|
|
2001-10-16 01:23:19 +00:00
|
|
|
AdMI = cpReg2RegMI(UniRetReg, UniRetLRReg, RegType );
|
2001-10-15 16:25:28 +00:00
|
|
|
CallAI->InstrnsAfter.push_back( AdMI );
|
2001-09-18 22:52:44 +00:00
|
|
|
|
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
} // if LR has color
|
|
|
|
else {
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
assert(0 && "LR of return value is splilled");
|
|
|
|
}
|
2001-09-18 22:52:44 +00:00
|
|
|
|
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
} // the LR didn't receive the suggested color
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
} // if there a return value
|
|
|
|
|
|
|
|
} // if there is an implicit arg for a return value
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2001-09-18 22:52:44 +00:00
|
|
|
|
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
// Now color all args of the call instruction
|
2001-09-18 22:52:44 +00:00
|
|
|
|
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
for(unsigned argNo=0, i=0; i < NumOfCallArgs; ++i, ++argNo ) {
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
const Value *CallArg = CallMI->getImplicitRef(i);
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
// get the LR of call operand (parameter)
|
|
|
|
LiveRange *const LR = LRI.getLiveRangeForValue(CallArg);
|
|
|
|
|
|
|
|
unsigned RegType = getRegType( CallArg );
|
|
|
|
unsigned RegClassID = getRegClassIDOfValue( CallArg);
|
2001-09-30 23:16:47 +00:00
|
|
|
|
|
|
|
// find whether this argument is coming in a register (if not, on stack)
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
bool isArgInReg = false;
|
|
|
|
unsigned UniArgReg = InvalidRegNum;
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
if( (RegType== IntRegType && argNo < NumOfIntArgRegs)) {
|
|
|
|
isArgInReg = true;
|
|
|
|
UniArgReg = getUnifiedRegNum(RegClassID, SparcIntRegOrder::o0 + argNo );
|
|
|
|
}
|
|
|
|
else if(RegType == FPSingleRegType && argNo < NumOfFloatArgRegs) {
|
|
|
|
isArgInReg = true;
|
|
|
|
UniArgReg = getUnifiedRegNum(RegClassID,
|
|
|
|
SparcFloatRegOrder::f0 + (argNo*2 + 1) );
|
|
|
|
}
|
|
|
|
else if(RegType == FPDoubleRegType && argNo < NumOfFloatArgRegs) {
|
|
|
|
isArgInReg = true;
|
|
|
|
UniArgReg = getUnifiedRegNum(RegClassID, SparcFloatRegOrder::f0+argNo*2);
|
|
|
|
}
|
2001-09-14 03:47:57 +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
|
|
|
|
if( !LR ) {
|
2001-09-30 23:16:47 +00:00
|
|
|
if( DEBUG_RA) {
|
2001-10-15 18:15:27 +00:00
|
|
|
cerr << " ERROR: In call instr, no LR for arg: " ;
|
|
|
|
printValue(CallArg); cerr << endl;
|
2001-09-30 23:16:47 +00:00
|
|
|
}
|
2001-10-15 16:25:28 +00:00
|
|
|
assert(0 && "NO LR for call arg");
|
|
|
|
// continue;
|
2001-09-30 23:16:47 +00:00
|
|
|
}
|
2001-10-15 16:25:28 +00:00
|
|
|
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
// if the LR received the suggested color, NOTHING to do
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
if( LR->hasSuggestedColor() && LR->hasColor() )
|
|
|
|
if( LR->getSuggestedColor() == LR->getColor() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
if( LR->hasColor() ) {
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
// We are here because though the LR is allocated a register, it
|
|
|
|
// was not allocated the suggested register. So, we have to copy %ix reg
|
|
|
|
// (or stack pos of arg) to the register it was colored with
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2001-09-19 22:40:51 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
unsigned UniLRReg = getUnifiedRegNum( RegClassID, LR->getColor() );
|
2001-09-19 22:40:51 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
if( isArgInReg )
|
|
|
|
AdMI = cpReg2RegMI(UniLRReg, UniArgReg, RegType );
|
2001-09-19 22:40:51 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
else
|
|
|
|
assert(0 && "TODO: Push an outgoing arg on stack");
|
|
|
|
|
|
|
|
// Now add the instruction
|
|
|
|
CallAI->InstrnsBefore.push_back( AdMI );
|
2001-09-19 22:40:51 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else { // LR is not colored (i.e., spilled)
|
2001-09-19 22:40:51 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
assert(0 && "TODO: Copy a spilled call arg to an output reg ");
|
2001-09-19 22:40:51 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
}
|
2001-09-19 22:40:51 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
} // for each parameter in call instruction
|
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 for an LLVM return instruction to identify which
|
|
|
|
// values will be returned from this method and to suggest colors.
|
|
|
|
//---------------------------------------------------------------------------
|
2001-10-15 16:25:28 +00:00
|
|
|
void UltraSparcRegInfo::suggestReg4RetValue(const MachineInstr *const RetMI,
|
2001-09-30 23:16:47 +00:00
|
|
|
LiveRangeInfo& LRI) const {
|
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
assert( (UltraSparcInfo->getInstrInfo()).isReturn( RetMI->getOpCode() ) );
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2001-10-15 16:25:28 +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
|
|
|
|
|
|
|
MachineInstr *AdMI;
|
|
|
|
LiveRange *const LR = LRI.getLiveRangeForValue( RetVal );
|
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
if( !LR ) {
|
2001-10-15 18:15:27 +00:00
|
|
|
cerr << "\nNo LR for:";
|
2001-10-15 16:25:28 +00:00
|
|
|
printValue( RetVal );
|
2001-10-15 18:15:27 +00:00
|
|
|
cerr << endl;
|
2001-10-15 16:25:28 +00:00
|
|
|
assert( LR && "No LR for return value of non-void method");
|
|
|
|
//return;
|
|
|
|
}
|
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
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
if( RegClassID == IntRegClassID )
|
|
|
|
LR->setSuggestedColor(SparcIntRegOrder::i0);
|
|
|
|
|
|
|
|
else if ( RegClassID == FloatRegClassID )
|
|
|
|
LR->setSuggestedColor(SparcFloatRegOrder::f0);
|
2001-09-30 23:16:47 +00:00
|
|
|
|
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-09-30 23:16:47 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
2001-10-15 16:25:28 +00:00
|
|
|
void UltraSparcRegInfo::colorRetValue(const MachineInstr *const RetMI,
|
2001-09-30 23:16:47 +00:00
|
|
|
LiveRangeInfo& LRI,
|
|
|
|
AddedInstrns *const RetAI) const {
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2001-10-15 16:25:28 +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
|
|
|
|
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
|
|
|
|
|
|
|
MachineInstr *AdMI;
|
|
|
|
LiveRange *const LR = LRI.getLiveRangeForValue( RetVal );
|
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
if( ! LR ) {
|
2001-10-15 18:15:27 +00:00
|
|
|
cerr << "\nNo LR for:";
|
2001-10-15 16:25:28 +00:00
|
|
|
printValue( RetVal );
|
2001-10-15 18:15:27 +00:00
|
|
|
cerr << endl;
|
2001-10-15 16:25:28 +00:00
|
|
|
// assert( LR && "No LR for return value of non-void method");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
unsigned RegClassID = getRegClassIDOfValue(RetVal);
|
|
|
|
unsigned RegType = getRegType( RetVal );
|
|
|
|
unsigned UniRetReg = InvalidRegNum;
|
|
|
|
|
|
|
|
if(RegClassID == IntRegClassID)
|
|
|
|
UniRetReg = getUnifiedRegNum( RegClassID, SparcIntRegOrder::i0 );
|
|
|
|
else if(RegClassID == FloatRegClassID)
|
|
|
|
UniRetReg = getUnifiedRegNum( RegClassID, SparcFloatRegOrder::f0);
|
|
|
|
|
|
|
|
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
// if the LR received the suggested color, NOTHING to do
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
if( LR->hasSuggestedColor() && LR->hasColor() )
|
|
|
|
if( LR->getSuggestedColor() == LR->getColor() )
|
|
|
|
return;
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
if( LR->hasColor() ) {
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2001-10-15 16:25:28 +00:00
|
|
|
// We are here because the LR was allocted a regiter, but NOT
|
|
|
|
// the correct register.
|
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-15 16:25:28 +00:00
|
|
|
if(RegClassID == IntRegClassID)
|
|
|
|
UniRetReg = getUnifiedRegNum( RegClassID, SparcIntRegOrder::i0);
|
|
|
|
else if(RegClassID == FloatRegClassID)
|
|
|
|
UniRetReg = getUnifiedRegNum( RegClassID, SparcFloatRegOrder::f0);
|
|
|
|
|
|
|
|
AdMI = cpReg2RegMI( UniLRReg, UniRetReg, RegType);
|
2001-09-30 23:16:47 +00:00
|
|
|
|
|
|
|
}
|
2001-10-15 16:25:28 +00:00
|
|
|
else
|
|
|
|
assert(0 && "TODO: Copy the return value from stack\n");
|
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
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
MachineInstr * UltraSparcRegInfo::cpReg2RegMI(const unsigned SrcReg,
|
|
|
|
const unsigned DestReg,
|
|
|
|
const int RegType) 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;
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
switch( RegType ) {
|
|
|
|
|
|
|
|
case IntRegType:
|
2001-09-18 22:52:44 +00:00
|
|
|
MI = new MachineInstr(ADD, 3);
|
2001-09-30 23:16:47 +00:00
|
|
|
MI->SetMachineOperand(0, SrcReg, false);
|
2001-09-18 22:52:44 +00:00
|
|
|
MI->SetMachineOperand(1, SparcIntRegOrder::g0, false);
|
2001-09-30 23:16:47 +00:00
|
|
|
MI->SetMachineOperand(2, DestReg, true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FPSingleRegType:
|
|
|
|
MI = new MachineInstr(FMOVS, 2);
|
|
|
|
MI->SetMachineOperand(0, SrcReg, false);
|
|
|
|
MI->SetMachineOperand(1, DestReg, true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FPDoubleRegType:
|
|
|
|
MI = new MachineInstr(FMOVD, 2);
|
|
|
|
MI->SetMachineOperand(0, SrcReg, false);
|
|
|
|
MI->SetMachineOperand(1, DestReg, true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert(0 && "Unknow RegType");
|
2001-09-18 22:52:44 +00:00
|
|
|
}
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
return MI;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-16 01:23:19 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// Copy from a register to memory. Register number must be the unified
|
|
|
|
// register number
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
MachineInstr * UltraSparcRegInfo::cpReg2MemMI(const unsigned SrcReg,
|
|
|
|
const unsigned DestPtrReg,
|
|
|
|
const int Offset,
|
|
|
|
const int RegType) const {
|
|
|
|
|
|
|
|
|
|
|
|
MachineInstr * MI = NULL;
|
|
|
|
|
|
|
|
switch( RegType ) {
|
|
|
|
|
|
|
|
case IntRegType:
|
|
|
|
MI = new MachineInstr(STX, 3);
|
|
|
|
MI->SetMachineOperand(0, DestPtrReg, false);
|
|
|
|
MI->SetMachineOperand(1, SrcReg, false);
|
|
|
|
MI->SetMachineOperand(2, MachineOperand:: MO_SignExtendedImmed,
|
|
|
|
(int64_t) Offset, false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FPSingleRegType:
|
|
|
|
MI = new MachineInstr(ST, 3);
|
|
|
|
MI->SetMachineOperand(0, DestPtrReg, false);
|
|
|
|
MI->SetMachineOperand(1, SrcReg, false);
|
|
|
|
MI->SetMachineOperand(2, MachineOperand:: MO_SignExtendedImmed,
|
|
|
|
(int64_t) Offset, false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FPDoubleRegType:
|
|
|
|
MI = new MachineInstr(STD, 3);
|
|
|
|
MI->SetMachineOperand(0, DestPtrReg, false);
|
|
|
|
MI->SetMachineOperand(1, SrcReg, false);
|
|
|
|
MI->SetMachineOperand(2, MachineOperand:: MO_SignExtendedImmed,
|
|
|
|
(int64_t) Offset, false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert(0 && "Unknow RegType");
|
|
|
|
}
|
|
|
|
|
|
|
|
return MI;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// Copy from memory to a reg. Register number must be the unified
|
|
|
|
// register number
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
MachineInstr * UltraSparcRegInfo::cpMem2RegMI(const unsigned SrcPtrReg,
|
|
|
|
const int Offset,
|
|
|
|
const unsigned DestReg,
|
|
|
|
const int RegType) const {
|
|
|
|
|
|
|
|
MachineInstr * MI = NULL;
|
|
|
|
|
|
|
|
switch( RegType ) {
|
|
|
|
|
|
|
|
case IntRegType:
|
|
|
|
MI = new MachineInstr(LDX, 3);
|
|
|
|
MI->SetMachineOperand(0, SrcPtrReg, false);
|
|
|
|
MI->SetMachineOperand(1, MachineOperand:: MO_SignExtendedImmed,
|
|
|
|
(int64_t) Offset, false);
|
|
|
|
MI->SetMachineOperand(2, DestReg, false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FPSingleRegType:
|
|
|
|
MI = new MachineInstr(LD, 3);
|
|
|
|
MI->SetMachineOperand(0, SrcPtrReg, false);
|
|
|
|
MI->SetMachineOperand(1, MachineOperand:: MO_SignExtendedImmed,
|
|
|
|
(int64_t) Offset, false);
|
|
|
|
MI->SetMachineOperand(2, DestReg, false);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FPDoubleRegType:
|
|
|
|
MI = new MachineInstr(LDD, 3);
|
|
|
|
MI->SetMachineOperand(0, SrcPtrReg, false);
|
|
|
|
MI->SetMachineOperand(1, MachineOperand:: MO_SignExtendedImmed,
|
|
|
|
(int64_t) Offset, false);
|
|
|
|
MI->SetMachineOperand(2, DestReg, false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert(0 && "Unknow RegType");
|
|
|
|
}
|
|
|
|
|
|
|
|
return MI;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// Only constant/label values are accepted.
|
|
|
|
// ***This code is temporary ***
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
MachineInstr * UltraSparcRegInfo::cpValue2RegMI(Value * Val,
|
|
|
|
const unsigned DestReg,
|
|
|
|
const int RegType) const {
|
|
|
|
|
2001-10-16 01:23:19 +00:00
|
|
|
assert( ((int)DestReg != InvalidRegNum) && "Invalid Register");
|
2001-09-30 23:16:47 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
unsigned MReg;
|
|
|
|
int64_t Imm;
|
|
|
|
|
|
|
|
MachineOperand::MachineOperandType MOTypeInt =
|
|
|
|
ChooseRegOrImmed(Val, ADD, *UltraSparcInfo, true, MReg, Imm);
|
|
|
|
*/
|
|
|
|
|
|
|
|
MachineOperand::MachineOperandType MOType;
|
|
|
|
|
|
|
|
switch( Val->getValueType() ) {
|
|
|
|
|
|
|
|
case Value::ConstantVal:
|
2001-10-03 14:53:21 +00:00
|
|
|
case Value::GlobalVariableVal:
|
2001-09-30 23:16:47 +00:00
|
|
|
MOType = MachineOperand:: MO_UnextendedImmed; // TODO**** correct???
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Value::BasicBlockVal:
|
|
|
|
case Value::MethodVal:
|
|
|
|
MOType = MachineOperand::MO_PCRelativeDisp;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2001-10-15 18:15:27 +00:00
|
|
|
cerr << "Value Type: " << Val->getValueType() << endl;
|
2001-09-30 23:16:47 +00:00
|
|
|
assert(0 && "Unknown val type - Only constants/globals/labels are valid");
|
2001-09-18 22:52:44 +00:00
|
|
|
}
|
2001-09-14 20:31:39 +00:00
|
|
|
|
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
|
|
|
|
MachineInstr * MI = NULL;
|
|
|
|
|
|
|
|
switch( RegType ) {
|
|
|
|
|
|
|
|
case IntRegType:
|
|
|
|
MI = new MachineInstr(ADD);
|
|
|
|
MI->SetMachineOperand(0, MOType, Val, false);
|
|
|
|
MI->SetMachineOperand(1, SparcIntRegOrder::g0, false);
|
|
|
|
MI->SetMachineOperand(2, DestReg, true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FPSingleRegType:
|
|
|
|
assert(0 && "FP const move not yet implemented");
|
|
|
|
MI = new MachineInstr(FMOVS);
|
|
|
|
MI->SetMachineOperand(0, MachineOperand::MO_SignExtendedImmed, Val, false);
|
|
|
|
MI->SetMachineOperand(1, DestReg, true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FPDoubleRegType:
|
|
|
|
assert(0 && "FP const move not yet implemented");
|
|
|
|
MI = new MachineInstr(FMOVD);
|
|
|
|
MI->SetMachineOperand(0, MachineOperand::MO_SignExtendedImmed, Val, false);
|
|
|
|
MI->SetMachineOperand(1, DestReg, true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert(0 && "Unknow RegType");
|
|
|
|
}
|
|
|
|
|
|
|
|
return MI;
|
2001-09-18 22:52:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-30 23:16:47 +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
|
|
|
|
2001-09-18 22:52:44 +00:00
|
|
|
void UltraSparcRegInfo::printReg(const LiveRange *const LR) {
|
2001-09-14 20:31:39 +00:00
|
|
|
|
2001-09-18 22:52:44 +00:00
|
|
|
unsigned RegClassID = (LR->getRegClass())->getID();
|
2001-09-14 20:31:39 +00:00
|
|
|
|
2001-10-15 18:15:27 +00:00
|
|
|
cerr << " *Node " << (LR->getUserIGNode())->getIndex();
|
2001-09-18 22:52:44 +00:00
|
|
|
|
|
|
|
if( ! LR->hasColor() ) {
|
2001-10-15 18:15:27 +00:00
|
|
|
cerr << " - could not find a color" << endl;
|
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
|
|
|
|
2001-09-18 22:52:44 +00:00
|
|
|
if( RegClassID == IntRegClassID ) {
|
2001-09-14 20:31:39 +00:00
|
|
|
|
2001-10-15 18:15:27 +00:00
|
|
|
cerr<< " [" << SparcIntRegOrder::getRegName(LR->getColor()) ;
|
|
|
|
cerr << "]" << endl;
|
2001-09-18 22:52:44 +00:00
|
|
|
}
|
|
|
|
else if ( RegClassID == FloatRegClassID) {
|
2001-10-15 18:15:27 +00:00
|
|
|
cerr << "[" << SparcFloatRegOrder::getRegName(LR->getColor());
|
2001-09-18 22:52:44 +00:00
|
|
|
if( LR->getTypeID() == Type::DoubleTyID )
|
2001-10-15 18:15:27 +00:00
|
|
|
cerr << "+" << SparcFloatRegOrder::getRegName(LR->getColor()+1);
|
|
|
|
cerr << "]" << endl;
|
2001-09-18 22:52:44 +00:00
|
|
|
}
|
|
|
|
}
|