2004-04-25 07:04:49 +00:00
|
|
|
//===-- SparcV9RegInfo.cpp - SparcV9 Target Register Information ----------===//
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-02-03 07:52:04 +00:00
|
|
|
//
|
2004-04-25 07:04:49 +00:00
|
|
|
// This file contains implementations of SparcV9 specific helper methods
|
2002-02-03 07:52:04 +00:00
|
|
|
// used for register allocation.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2002-10-28 00:28:31 +00:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2003-01-15 17:47:49 +00:00
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
2004-08-16 21:55:02 +00:00
|
|
|
#include "MachineFunctionInfo.h"
|
|
|
|
#include "MachineCodeForInstruction.h"
|
2004-02-29 19:12:51 +00:00
|
|
|
#include "MachineInstrAnnot.h"
|
2004-01-09 16:17:09 +00:00
|
|
|
#include "RegAlloc/LiveRangeInfo.h"
|
|
|
|
#include "RegAlloc/LiveRange.h"
|
2003-12-17 22:04:00 +00:00
|
|
|
#include "llvm/DerivedTypes.h"
|
|
|
|
#include "llvm/Function.h"
|
2004-07-29 17:11:37 +00:00
|
|
|
#include "llvm/Instructions.h"
|
2004-02-25 18:44:15 +00:00
|
|
|
#include "SparcV9Internals.h"
|
|
|
|
#include "SparcV9RegClassInfo.h"
|
|
|
|
#include "SparcV9RegInfo.h"
|
2004-08-12 18:29:05 +00:00
|
|
|
#include "SparcV9FrameInfo.h"
|
2004-02-25 18:44:15 +00:00
|
|
|
#include "SparcV9TargetMachine.h"
|
2004-08-04 07:29:53 +00:00
|
|
|
#include "SparcV9TmpInstr.h"
|
2004-07-04 12:19:56 +00:00
|
|
|
#include <iostream>
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
namespace llvm {
|
|
|
|
|
2003-01-14 23:05:08 +00:00
|
|
|
enum {
|
|
|
|
BadRegClass = ~0
|
|
|
|
};
|
|
|
|
|
2004-02-25 18:44:15 +00:00
|
|
|
SparcV9RegInfo::SparcV9RegInfo(const SparcV9TargetMachine &tgt)
|
2004-06-03 02:45:09 +00:00
|
|
|
: target (tgt), NumOfIntArgRegs (6), NumOfFloatArgRegs (32)
|
2003-05-31 07:32:01 +00:00
|
|
|
{
|
2004-02-25 18:44:15 +00:00
|
|
|
MachineRegClassArr.push_back(new SparcV9IntRegClass(IntRegClassID));
|
|
|
|
MachineRegClassArr.push_back(new SparcV9FloatRegClass(FloatRegClassID));
|
|
|
|
MachineRegClassArr.push_back(new SparcV9IntCCRegClass(IntCCRegClassID));
|
|
|
|
MachineRegClassArr.push_back(new SparcV9FloatCCRegClass(FloatCCRegClassID));
|
|
|
|
MachineRegClassArr.push_back(new SparcV9SpecialRegClass(SpecialRegClassID));
|
2005-04-21 23:30:14 +00:00
|
|
|
|
|
|
|
assert(SparcV9FloatRegClass::StartOfNonVolatileRegs == 32 &&
|
2002-02-04 05:59:25 +00:00
|
|
|
"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
|
|
|
//
|
2004-02-25 18:44:15 +00:00
|
|
|
unsigned SparcV9RegInfo::getZeroRegNum() const {
|
|
|
|
return getUnifiedRegNum(SparcV9RegInfo::IntRegClassID,
|
|
|
|
SparcV9IntRegClass::g0);
|
2002-03-18 03:12:16 +00:00
|
|
|
}
|
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
|
|
|
|
//
|
2004-02-25 18:44:15 +00:00
|
|
|
unsigned SparcV9RegInfo::getCallAddressReg() const {
|
|
|
|
return getUnifiedRegNum(SparcV9RegInfo::IntRegClassID,
|
|
|
|
SparcV9IntRegClass::o7);
|
2002-02-04 05:59:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the register containing the return address.
|
2005-04-21 23:30:14 +00:00
|
|
|
// It should be made sure that this register contains the return
|
2002-02-04 05:59:25 +00:00
|
|
|
// value when a return instruction is reached.
|
|
|
|
//
|
2004-02-25 18:44:15 +00:00
|
|
|
unsigned SparcV9RegInfo::getReturnAddressReg() const {
|
|
|
|
return getUnifiedRegNum(SparcV9RegInfo::IntRegClassID,
|
|
|
|
SparcV9IntRegClass::i7);
|
2002-08-12 21:25:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Register get name implementations...
|
|
|
|
|
2004-02-25 18:44:15 +00:00
|
|
|
// Int register names in same order as enum in class SparcV9IntRegClass
|
2002-08-12 21:25:05 +00:00
|
|
|
static const char * const IntRegNames[] = {
|
|
|
|
"o0", "o1", "o2", "o3", "o4", "o5", "o7",
|
|
|
|
"l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7",
|
2005-04-21 23:30:14 +00:00
|
|
|
"i0", "i1", "i2", "i3", "i4", "i5",
|
2002-08-12 21:25:05 +00:00
|
|
|
"i6", "i7",
|
2005-04-21 23:30:14 +00:00
|
|
|
"g0", "g1", "g2", "g3", "g4", "g5", "g6", "g7",
|
2002-08-12 21:25:05 +00:00
|
|
|
"o6"
|
2005-04-21 23:30:14 +00:00
|
|
|
};
|
2002-08-12 21:25:05 +00:00
|
|
|
|
2004-02-25 18:44:15 +00:00
|
|
|
const char * const SparcV9IntRegClass::getRegName(unsigned reg) const {
|
2002-08-12 21:25:05 +00:00
|
|
|
assert(reg < NumOfAllRegs);
|
|
|
|
return IntRegNames[reg];
|
|
|
|
}
|
|
|
|
|
2005-04-21 23:30:14 +00:00
|
|
|
static const char * const FloatRegNames[] = {
|
|
|
|
"f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9",
|
2002-08-12 21:25:05 +00:00
|
|
|
"f10", "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18", "f19",
|
|
|
|
"f20", "f21", "f22", "f23", "f24", "f25", "f26", "f27", "f28", "f29",
|
|
|
|
"f30", "f31", "f32", "f33", "f34", "f35", "f36", "f37", "f38", "f39",
|
|
|
|
"f40", "f41", "f42", "f43", "f44", "f45", "f46", "f47", "f48", "f49",
|
|
|
|
"f50", "f51", "f52", "f53", "f54", "f55", "f56", "f57", "f58", "f59",
|
|
|
|
"f60", "f61", "f62", "f63"
|
|
|
|
};
|
|
|
|
|
2004-02-25 18:44:15 +00:00
|
|
|
const char * const SparcV9FloatRegClass::getRegName(unsigned reg) const {
|
2002-08-12 21:25:05 +00:00
|
|
|
assert (reg < NumOfAllRegs);
|
|
|
|
return FloatRegNames[reg];
|
|
|
|
}
|
|
|
|
|
2005-04-21 23:30:14 +00:00
|
|
|
static const char * const IntCCRegNames[] = {
|
2003-07-06 20:13:59 +00:00
|
|
|
"xcc", "icc", "ccr"
|
2002-08-12 21:25:05 +00:00
|
|
|
};
|
|
|
|
|
2004-02-25 18:44:15 +00:00
|
|
|
const char * const SparcV9IntCCRegClass::getRegName(unsigned reg) const {
|
2003-07-06 20:13:59 +00:00
|
|
|
assert(reg < 3);
|
2002-08-12 21:25:05 +00:00
|
|
|
return IntCCRegNames[reg];
|
|
|
|
}
|
|
|
|
|
2005-04-21 23:30:14 +00:00
|
|
|
static const char * const FloatCCRegNames[] = {
|
2002-08-12 21:25:05 +00:00
|
|
|
"fcc0", "fcc1", "fcc2", "fcc3"
|
|
|
|
};
|
|
|
|
|
2004-02-25 18:44:15 +00:00
|
|
|
const char * const SparcV9FloatCCRegClass::getRegName(unsigned reg) const {
|
2004-04-19 18:53:43 +00:00
|
|
|
assert (reg < 4);
|
2002-08-12 21:25:05 +00:00
|
|
|
return FloatCCRegNames[reg];
|
2002-02-04 05:59:25 +00:00
|
|
|
}
|
|
|
|
|
2005-04-21 23:30:14 +00:00
|
|
|
static const char * const SpecialRegNames[] = {
|
2003-05-27 00:02:22 +00:00
|
|
|
"fsr"
|
|
|
|
};
|
|
|
|
|
2004-02-25 18:44:15 +00:00
|
|
|
const char * const SparcV9SpecialRegClass::getRegName(unsigned reg) const {
|
2003-05-27 00:02:22 +00:00
|
|
|
assert (reg < 1);
|
|
|
|
return SpecialRegNames[reg];
|
2002-02-04 05:59:25 +00:00
|
|
|
}
|
|
|
|
|
2002-03-18 03:12:16 +00:00
|
|
|
// Get unified reg number for frame pointer
|
2004-02-25 18:44:15 +00:00
|
|
|
unsigned SparcV9RegInfo::getFramePointer() const {
|
|
|
|
return getUnifiedRegNum(SparcV9RegInfo::IntRegClassID,
|
|
|
|
SparcV9IntRegClass::i6);
|
2002-02-04 05:59:25 +00:00
|
|
|
}
|
|
|
|
|
2002-03-18 03:12:16 +00:00
|
|
|
// Get unified reg number for stack pointer
|
2004-02-25 18:44:15 +00:00
|
|
|
unsigned SparcV9RegInfo::getStackPointer() const {
|
|
|
|
return getUnifiedRegNum(SparcV9RegInfo::IntRegClassID,
|
|
|
|
SparcV9IntRegClass::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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-31 07:32:01 +00:00
|
|
|
// Get the register number for the specified argument #argNo,
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
2002-04-25 04:42:21 +00:00
|
|
|
// Return value:
|
2005-04-21 23:30:14 +00:00
|
|
|
// getInvalidRegNum(), if there is no int register available for the arg.
|
2003-05-31 07:32:01 +00:00
|
|
|
// regNum, otherwise (this is NOT the unified reg. num).
|
|
|
|
// regClassId is set to the register class ID.
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
2003-05-31 07:32:01 +00:00
|
|
|
int
|
2004-02-25 18:44:15 +00:00
|
|
|
SparcV9RegInfo::regNumForIntArg(bool inCallee, bool isVarArgsCall,
|
2003-05-31 07:32:01 +00:00
|
|
|
unsigned argNo, unsigned& regClassId) const
|
2002-04-25 04:42:21 +00:00
|
|
|
{
|
2002-05-19 15:25:51 +00:00
|
|
|
regClassId = IntRegClassID;
|
2002-04-25 04:42:21 +00:00
|
|
|
if (argNo >= NumOfIntArgRegs)
|
2003-05-31 07:32:01 +00:00
|
|
|
return getInvalidRegNum();
|
2002-05-19 15:25:51 +00:00
|
|
|
else
|
2004-02-25 18:44:15 +00:00
|
|
|
return argNo + (inCallee? SparcV9IntRegClass::i0 : SparcV9IntRegClass::o0);
|
2002-04-25 04:42:21 +00:00
|
|
|
}
|
|
|
|
|
2003-05-31 07:32:01 +00:00
|
|
|
// Get the register number for the specified FP argument #argNo,
|
2002-04-25 04:42:21 +00:00
|
|
|
// Use INT regs for FP args if this is a varargs call.
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
2002-04-25 04:42:21 +00:00
|
|
|
// Return value:
|
2005-04-21 23:30:14 +00:00
|
|
|
// getInvalidRegNum(), if there is no int register available for the arg.
|
2003-05-31 07:32:01 +00:00
|
|
|
// regNum, otherwise (this is NOT the unified reg. num).
|
|
|
|
// regClassId is set to the register class ID.
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
2003-05-31 07:32:01 +00:00
|
|
|
int
|
2004-02-25 18:44:15 +00:00
|
|
|
SparcV9RegInfo::regNumForFPArg(unsigned regType,
|
2002-04-25 04:42:21 +00:00
|
|
|
bool inCallee, bool isVarArgsCall,
|
2003-05-31 07:32:01 +00:00
|
|
|
unsigned argNo, unsigned& regClassId) const
|
2002-04-25 04:42:21 +00:00
|
|
|
{
|
2002-05-19 15:25:51 +00:00
|
|
|
if (isVarArgsCall)
|
2003-05-31 07:32:01 +00:00
|
|
|
return regNumForIntArg(inCallee, isVarArgsCall, argNo, regClassId);
|
2002-05-19 15:25:51 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
regClassId = FloatRegClassID;
|
|
|
|
if (regType == FPSingleRegType)
|
|
|
|
return (argNo*2+1 >= NumOfFloatArgRegs)?
|
2004-02-25 18:44:15 +00:00
|
|
|
getInvalidRegNum() : SparcV9FloatRegClass::f0 + (argNo * 2 + 1);
|
2002-05-19 15:25:51 +00:00
|
|
|
else if (regType == FPDoubleRegType)
|
|
|
|
return (argNo*2 >= NumOfFloatArgRegs)?
|
2004-02-25 18:44:15 +00:00
|
|
|
getInvalidRegNum() : SparcV9FloatRegClass::f0 + (argNo * 2);
|
2002-05-19 15:25:51 +00:00
|
|
|
else
|
|
|
|
assert(0 && "Illegal FP register type");
|
2005-07-27 05:53:44 +00:00
|
|
|
return 0;
|
2002-05-19 15:25:51 +00:00
|
|
|
}
|
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
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2004-02-25 18:44:15 +00:00
|
|
|
// The following 4 methods are used to find the RegType (SparcV9Internals.h)
|
2005-06-12 23:52:58 +00:00
|
|
|
// of a V9LiveRange, a Value, and for a given register unified reg number.
|
2002-02-04 05:59:25 +00:00
|
|
|
//
|
2004-02-25 18:44:15 +00:00
|
|
|
int SparcV9RegInfo::getRegTypeForClassAndType(unsigned regClassID,
|
2003-05-27 00:02:22 +00:00
|
|
|
const Type* type) const
|
|
|
|
{
|
2002-05-19 15:25:51 +00:00
|
|
|
switch (regClassID) {
|
2005-04-21 23:30:14 +00:00
|
|
|
case IntRegClassID: return IntRegType;
|
2003-05-27 00:02:22 +00:00
|
|
|
case FloatRegClassID:
|
|
|
|
if (type == Type::FloatTy) return FPSingleRegType;
|
|
|
|
else if (type == Type::DoubleTy) return FPDoubleRegType;
|
|
|
|
assert(0 && "Unknown type in FloatRegClass"); return 0;
|
2005-04-21 23:30:14 +00:00
|
|
|
case IntCCRegClassID: return IntCCRegType;
|
|
|
|
case FloatCCRegClassID: return FloatCCRegType;
|
|
|
|
case SpecialRegClassID: return SpecialRegType;
|
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
|
|
|
|
2004-02-25 18:44:15 +00:00
|
|
|
int SparcV9RegInfo::getRegTypeForDataType(const Type* type) const
|
2003-05-27 00:02:22 +00:00
|
|
|
{
|
|
|
|
return getRegTypeForClassAndType(getRegClassIDOfType(type), type);
|
2002-02-04 05:59:25 +00:00
|
|
|
}
|
2001-10-21 16:43:41 +00:00
|
|
|
|
2005-06-12 23:52:58 +00:00
|
|
|
int SparcV9RegInfo::getRegTypeForLR(const V9LiveRange *LR) const
|
2003-05-27 00:02:22 +00:00
|
|
|
{
|
|
|
|
return getRegTypeForClassAndType(LR->getRegClassID(), LR->getType());
|
|
|
|
}
|
2003-01-15 21:14:32 +00:00
|
|
|
|
2004-02-25 18:44:15 +00:00
|
|
|
int SparcV9RegInfo::getRegType(int unifiedRegNum) const
|
2003-05-27 00:02:22 +00:00
|
|
|
{
|
2005-04-21 23:30:14 +00:00
|
|
|
if (unifiedRegNum < 32)
|
2002-02-04 05:59:25 +00:00
|
|
|
return IntRegType;
|
2002-07-08 23:23:12 +00:00
|
|
|
else if (unifiedRegNum < (32 + 32))
|
2002-02-04 05:59:25 +00:00
|
|
|
return FPSingleRegType;
|
2002-07-08 23:23:12 +00:00
|
|
|
else if (unifiedRegNum < (64 + 32))
|
2002-02-04 05:59:25 +00:00
|
|
|
return FPDoubleRegType;
|
2004-04-21 17:53:58 +00:00
|
|
|
else if (unifiedRegNum < (64+32+3))
|
|
|
|
return IntCCRegType;
|
2005-04-21 23:30:14 +00:00
|
|
|
else if (unifiedRegNum < (64+32+3+4))
|
|
|
|
return FloatCCRegType;
|
|
|
|
else if (unifiedRegNum < (64+32+3+4+1))
|
|
|
|
return SpecialRegType;
|
|
|
|
else
|
2002-07-08 23:23:12 +00:00
|
|
|
assert(0 && "Invalid unified register number in getRegType");
|
2002-02-24 23:02:40 +00:00
|
|
|
return 0;
|
2001-10-21 16:43:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-08 23:23:12 +00:00
|
|
|
// To find the register class used for a specified Type
|
|
|
|
//
|
2004-02-25 18:44:15 +00:00
|
|
|
unsigned SparcV9RegInfo::getRegClassIDOfType(const Type *type,
|
2002-07-25 06:08:32 +00:00
|
|
|
bool isCCReg) const {
|
2004-06-17 18:19:28 +00:00
|
|
|
Type::TypeID ty = type->getTypeID();
|
2002-07-08 23:23:12 +00:00
|
|
|
unsigned res;
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2002-07-08 23:23:12 +00:00
|
|
|
// FIXME: Comparing types like this isn't very safe...
|
|
|
|
if ((ty && ty <= Type::LongTyID) || (ty == Type::LabelTyID) ||
|
|
|
|
(ty == Type::FunctionTyID) || (ty == Type::PointerTyID) )
|
|
|
|
res = IntRegClassID; // sparc int reg (ty=0: void)
|
|
|
|
else if (ty <= Type::DoubleTyID)
|
|
|
|
res = FloatRegClassID; // sparc float reg class
|
2005-04-21 23:30:14 +00:00
|
|
|
else {
|
2002-07-08 23:23:12 +00:00
|
|
|
//std::cerr << "TypeID: " << ty << "\n";
|
|
|
|
assert(0 && "Cannot resolve register class for type");
|
|
|
|
return 0;
|
|
|
|
}
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2003-01-15 21:14:32 +00:00
|
|
|
if (isCCReg)
|
2005-04-21 23:30:14 +00:00
|
|
|
return res + 2; // corresponding condition code register
|
|
|
|
else
|
2002-07-08 23:23:12 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2004-02-25 18:44:15 +00:00
|
|
|
unsigned SparcV9RegInfo::getRegClassIDOfRegType(int regType) const {
|
2002-07-08 23:23:12 +00:00
|
|
|
switch(regType) {
|
|
|
|
case IntRegType: return IntRegClassID;
|
|
|
|
case FPSingleRegType:
|
|
|
|
case FPDoubleRegType: return FloatRegClassID;
|
|
|
|
case IntCCRegType: return IntCCRegClassID;
|
|
|
|
case FloatCCRegType: return FloatCCRegClassID;
|
2004-04-21 17:53:58 +00:00
|
|
|
case SpecialRegType: return SpecialRegClassID;
|
2002-07-08 23:23:12 +00:00
|
|
|
default:
|
|
|
|
assert(0 && "Invalid register type in getRegClassIDOfRegType");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
//---------------------------------------------------------------------------
|
2005-04-21 23:30:14 +00:00
|
|
|
void SparcV9RegInfo::suggestReg4RetAddr(MachineInstr *RetMI,
|
2005-07-27 05:53:44 +00:00
|
|
|
LiveRangeInfo& LRI) const {
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2004-06-02 05:55:25 +00:00
|
|
|
assert(target.getInstrInfo()->isReturn(RetMI->getOpcode()));
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2002-07-08 23:23:12 +00:00
|
|
|
// return address is always mapped to i7 so set it immediately
|
|
|
|
RetMI->SetRegForOperand(0, getUnifiedRegNum(IntRegClassID,
|
2004-02-25 18:44:15 +00:00
|
|
|
SparcV9IntRegClass::i7));
|
2005-04-21 23:30:14 +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-07-08 23:23:12 +00:00
|
|
|
// MachineOperand & MO = RetMI->getOperand(0);
|
2002-01-07 19:20:28 +00:00
|
|
|
// const Value *RetAddrVal = MO.getVRegValue();
|
|
|
|
// assert( RetAddrVal && "LR for ret address must be created at start");
|
2005-06-12 23:52:58 +00:00
|
|
|
// V9LiveRange * RetAddrLR = LRI.getLiveRangeForValue( RetAddrVal);
|
2005-04-21 23:30:14 +00:00
|
|
|
// RetAddrLR->setSuggestedColor(getUnifiedRegNum( IntRegClassID,
|
2004-02-25 18:44:15 +00:00
|
|
|
// SparcV9IntRegOrdr::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.
|
2004-02-25 18:44:15 +00:00
|
|
|
// SparcV9 ABI dictates that %o7 be used for this purpose.
|
2001-09-18 22:52:44 +00:00
|
|
|
//---------------------------------------------------------------------------
|
2002-09-28 16:59:05 +00:00
|
|
|
void
|
2004-02-25 18:44:15 +00:00
|
|
|
SparcV9RegInfo::suggestReg4CallAddr(MachineInstr * CallMI,
|
2002-09-28 16:59:05 +00:00
|
|
|
LiveRangeInfo& LRI) const
|
|
|
|
{
|
2005-04-21 23:30:14 +00:00
|
|
|
CallArgsDescriptor* argDesc = CallArgsDescriptor::get(CallMI);
|
2002-05-19 15:25:51 +00:00
|
|
|
const Value *RetAddrVal = argDesc->getReturnAddrReg();
|
2002-09-28 16:59:05 +00:00
|
|
|
assert(RetAddrVal && "INTERNAL ERROR: Return address value is required");
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2002-09-28 16:59:05 +00:00
|
|
|
// A LR must already exist for the return address.
|
2005-06-12 23:52:58 +00:00
|
|
|
V9LiveRange *RetAddrLR = LRI.getLiveRangeForValue(RetAddrVal);
|
2002-09-28 16:59:05 +00:00
|
|
|
assert(RetAddrLR && "INTERNAL ERROR: No LR for return address of call!");
|
|
|
|
|
2003-01-15 21:14:32 +00:00
|
|
|
unsigned RegClassID = RetAddrLR->getRegClassID();
|
2004-02-25 18:44:15 +00:00
|
|
|
RetAddrLR->setColor(getUnifiedRegNum(IntRegClassID, SparcV9IntRegClass::o7));
|
2002-09-28 16:59:05 +00:00
|
|
|
}
|
2001-10-15 16:25:28 +00:00
|
|
|
|
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
2005-04-21 23:30:14 +00:00
|
|
|
// This method will suggest colors to incoming args to a method.
|
|
|
|
// According to the SparcV9 ABI, the first 6 incoming args are in
|
2002-01-07 19:20:28 +00:00
|
|
|
// %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
|
|
|
//---------------------------------------------------------------------------
|
2005-04-21 23:30:14 +00:00
|
|
|
void SparcV9RegInfo::suggestRegs4MethodArgs(const Function *Meth,
|
2005-07-27 05:53:44 +00:00
|
|
|
LiveRangeInfo& LRI) const
|
2001-09-18 22:52:44 +00:00
|
|
|
{
|
2003-07-25 21:12:15 +00:00
|
|
|
// Check if this is a varArgs function. needed for choosing regs.
|
2002-04-25 04:42:21 +00:00
|
|
|
bool isVarArgs = isVarArgsFunction(Meth->getType());
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2003-07-25 21:12:15 +00:00
|
|
|
// Count the arguments, *ignoring* whether they are int or FP args.
|
|
|
|
// Use this common arg numbering to pick the right int or fp register.
|
|
|
|
unsigned argNo=0;
|
2005-03-15 04:54:21 +00:00
|
|
|
for(Function::const_arg_iterator I = Meth->arg_begin(), E = Meth->arg_end();
|
2002-06-25 16:13:21 +00:00
|
|
|
I != E; ++I, ++argNo) {
|
2005-06-12 23:52:58 +00:00
|
|
|
V9LiveRange *LR = LRI.getLiveRangeForValue(I);
|
2002-06-25 16:13:21 +00:00
|
|
|
assert(LR && "No live range found for method arg");
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2003-07-25 21:12:15 +00:00
|
|
|
unsigned regType = getRegTypeForLR(LR);
|
|
|
|
unsigned regClassIDOfArgReg = BadRegClass; // for chosen reg (unused)
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2002-06-25 16:13:21 +00:00
|
|
|
int regNum = (regType == IntRegType)
|
2003-07-25 21:12:15 +00:00
|
|
|
? regNumForIntArg(/*inCallee*/ true, isVarArgs, argNo, regClassIDOfArgReg)
|
|
|
|
: regNumForFPArg(regType, /*inCallee*/ true, isVarArgs, argNo,
|
2005-04-21 23:30:14 +00:00
|
|
|
regClassIDOfArgReg);
|
|
|
|
|
2003-07-25 21:12:15 +00:00
|
|
|
if (regNum != getInvalidRegNum())
|
2002-06-25 16:13:21 +00:00
|
|
|
LR->setSuggestedColor(regNum);
|
|
|
|
}
|
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
|
|
|
//---------------------------------------------------------------------------
|
2005-04-21 23:30:14 +00:00
|
|
|
void SparcV9RegInfo::colorMethodArgs(const Function *Meth,
|
2003-07-29 19:53:21 +00:00
|
|
|
LiveRangeInfo &LRI,
|
|
|
|
std::vector<MachineInstr*>& InstrnsBefore,
|
|
|
|
std::vector<MachineInstr*>& InstrnsAfter) 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
|
|
|
MachineInstr *AdMI;
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
// for each argument
|
2002-06-25 16:13:21 +00:00
|
|
|
// for each argument. count INT and FP arguments separately.
|
|
|
|
unsigned argNo=0, intArgNo=0, fpArgNo=0;
|
2005-03-15 04:54:21 +00:00
|
|
|
for(Function::const_arg_iterator I = Meth->arg_begin(), E = Meth->arg_end();
|
2002-06-25 16:13:21 +00:00
|
|
|
I != E; ++I, ++argNo) {
|
2001-09-30 23:16:47 +00:00
|
|
|
// get the LR of arg
|
2005-06-12 23:52:58 +00:00
|
|
|
V9LiveRange *LR = LRI.getLiveRangeForValue(I);
|
2001-09-30 23:16:47 +00:00
|
|
|
assert( LR && "No live range found for method arg");
|
|
|
|
|
2003-07-25 21:12:15 +00:00
|
|
|
unsigned regType = getRegTypeForLR(LR);
|
2003-01-15 21:14:32 +00:00
|
|
|
unsigned RegClassID = LR->getRegClassID();
|
2005-04-21 23:30:14 +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;
|
2003-05-31 07:32:01 +00:00
|
|
|
unsigned UniArgReg = getInvalidRegNum(); // reg that LR MUST be colored with
|
2003-01-14 23:05:08 +00:00
|
|
|
unsigned regClassIDOfArgReg = BadRegClass; // reg class of chosen reg
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2002-04-25 04:42:21 +00:00
|
|
|
int regNum = (regType == IntRegType)
|
2002-05-19 15:25:51 +00:00
|
|
|
? regNumForIntArg(/*inCallee*/ true, isVarArgs,
|
2003-05-31 07:32:01 +00:00
|
|
|
argNo, regClassIDOfArgReg)
|
2002-05-19 15:25:51 +00:00
|
|
|
: regNumForFPArg(regType, /*inCallee*/ true, isVarArgs,
|
2003-05-31 07:32:01 +00:00
|
|
|
argNo, regClassIDOfArgReg);
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2003-05-31 07:32:01 +00:00
|
|
|
if(regNum != getInvalidRegNum()) {
|
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
|
|
|
}
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2003-07-10 19:42:11 +00:00
|
|
|
if( ! LR->isMarkedForSpill() ) { // 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 )
|
2005-07-27 05:53:44 +00:00
|
|
|
continue;
|
2001-10-24 15:56:58 +00:00
|
|
|
|
2005-04-21 23:30:14 +00:00
|
|
|
// We are here because the LR did not receive the suggested
|
2002-01-07 19:20:28 +00:00
|
|
|
// but LR received another register.
|
2005-04-21 23:30:14 +00:00
|
|
|
// Now we have to copy the %i reg (or stack pos of arg)
|
2002-01-07 19:20:28 +00:00
|
|
|
// to the register the LR was colored with.
|
2005-04-21 23:30:14 +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 ) {
|
2005-07-27 05:53:44 +00:00
|
|
|
if( regClassIDOfArgReg != RegClassID ) {
|
|
|
|
// NOTE: This code has not been well-tested.
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2005-07-27 05:53:44 +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.
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
2002-04-25 04:42:21 +00:00
|
|
|
assert(isVarArgs &&
|
2005-04-21 23:30:14 +00:00
|
|
|
RegClassID == FloatRegClassID &&
|
2002-04-25 04:42:21 +00:00
|
|
|
regClassIDOfArgReg == IntRegClassID &&
|
|
|
|
"This should only be an Int register for an FP argument");
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2005-07-27 05:53:44 +00:00
|
|
|
int TmpOff = MachineFunction::get(Meth).getInfo<SparcV9FunctionInfo>()->pushTempValue(
|
2002-04-25 04:42:21 +00:00
|
|
|
getSpilledRegSize(regType));
|
2005-07-27 05:53:44 +00:00
|
|
|
cpReg2MemMI(InstrnsBefore,
|
2002-07-08 23:23:12 +00:00
|
|
|
UniArgReg, getFramePointer(), TmpOff, IntRegType);
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2005-07-27 05:53:44 +00:00
|
|
|
cpMem2RegMI(InstrnsBefore,
|
2002-07-08 23:23:12 +00:00
|
|
|
getFramePointer(), TmpOff, UniLRReg, regType);
|
2005-07-27 05:53:44 +00:00
|
|
|
}
|
2005-07-27 06:12:32 +00:00
|
|
|
else {
|
2005-07-27 05:53:44 +00:00
|
|
|
cpReg2RegMI(InstrnsBefore, UniArgReg, UniLRReg, regType);
|
|
|
|
}
|
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
|
|
|
|
2005-07-27 05:53:44 +00:00
|
|
|
// Now the arg is coming on stack. Since the LR received a register,
|
|
|
|
// we just have to load the arg on stack into that register
|
|
|
|
//
|
2004-06-02 05:55:25 +00:00
|
|
|
const TargetFrameInfo& frameInfo = *target.getFrameInfo();
|
2005-07-27 05:53:44 +00:00
|
|
|
int offsetFromFP =
|
2002-10-28 00:28:31 +00:00
|
|
|
frameInfo.getIncomingArgOffset(MachineFunction::get(Meth),
|
2002-04-25 04:42:21 +00:00
|
|
|
argNo);
|
2003-05-31 07:32:01 +00:00
|
|
|
|
|
|
|
// float arguments on stack are right justified so adjust the offset!
|
|
|
|
// int arguments are also right justified but they are always loaded as
|
|
|
|
// a full double-word so the offset does not need to be adjusted.
|
|
|
|
if (regType == FPSingleRegType) {
|
|
|
|
unsigned argSize = target.getTargetData().getTypeSize(LR->getType());
|
2004-08-12 18:29:05 +00:00
|
|
|
unsigned slotSize = SparcV9FrameInfo::SizeOfEachArgOnStack;
|
2003-05-31 07:32:01 +00:00
|
|
|
assert(argSize <= slotSize && "Insufficient slot size!");
|
|
|
|
offsetFromFP += slotSize - argSize;
|
|
|
|
}
|
|
|
|
|
2005-07-27 05:53:44 +00:00
|
|
|
cpMem2RegMI(InstrnsBefore,
|
2002-07-08 23:23:12 +00:00
|
|
|
getFramePointer(), offsetFromFP, UniLRReg, regType);
|
2001-10-28 18:15:12 +00:00
|
|
|
}
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2001-10-28 18:15:12 +00:00
|
|
|
} // if LR received a color
|
|
|
|
|
2005-04-21 23:30:14 +00:00
|
|
|
else {
|
2001-10-28 18:15:12 +00:00
|
|
|
|
|
|
|
// 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 ) {
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2005-07-27 05:53:44 +00:00
|
|
|
if( regClassIDOfArgReg != RegClassID ) {
|
2002-04-25 04:42:21 +00:00
|
|
|
assert(0 &&
|
|
|
|
"FP arguments to a varargs function should be explicitly "
|
|
|
|
"copied to/from int registers by instruction selection!");
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2005-07-27 05:53:44 +00:00
|
|
|
// It must be a float arg for a variable argument call, which
|
2002-04-25 04:42:21 +00:00
|
|
|
// must come in a %o reg. Move the int reg to the stack.
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
2002-04-25 04:42:21 +00:00
|
|
|
assert(isVarArgs && regClassIDOfArgReg == IntRegClassID &&
|
|
|
|
"This should only be an Int register for an FP argument");
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2003-07-29 19:53:21 +00:00
|
|
|
cpReg2MemMI(InstrnsBefore, UniArgReg,
|
2002-07-08 23:23:12 +00:00
|
|
|
getFramePointer(), LR->getSpillOffFromFP(), IntRegType);
|
2002-04-25 04:42:21 +00:00
|
|
|
}
|
|
|
|
else {
|
2003-07-29 19:53:21 +00:00
|
|
|
cpReg2MemMI(InstrnsBefore, UniArgReg,
|
2002-07-08 23:23:12 +00:00
|
|
|
getFramePointer(), LR->getSpillOffFromFP(), regType);
|
2002-04-25 04:42:21 +00:00
|
|
|
}
|
2001-10-28 18:15:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
2005-07-27 05:53:44 +00:00
|
|
|
// Now the arg is coming on stack. Since the LR did NOT
|
|
|
|
// received a register as well, it is allocated a stack position. We
|
|
|
|
// can simply change the stack position of the LR. We can do this,
|
|
|
|
// since this method is called before any other method that makes
|
|
|
|
// uses of the stack pos of the LR (e.g., updateMachineInstr)
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
2004-06-02 05:55:25 +00:00
|
|
|
const TargetFrameInfo& frameInfo = *target.getFrameInfo();
|
2005-07-27 05:53:44 +00:00
|
|
|
int offsetFromFP =
|
2002-10-28 00:28:31 +00:00
|
|
|
frameInfo.getIncomingArgOffset(MachineFunction::get(Meth),
|
2002-04-25 04:42:21 +00:00
|
|
|
argNo);
|
2003-05-31 07:32:01 +00:00
|
|
|
|
|
|
|
// FP arguments on stack are right justified so adjust offset!
|
|
|
|
// int arguments are also right justified but they are always loaded as
|
|
|
|
// a full double-word so the offset does not need to be adjusted.
|
|
|
|
if (regType == FPSingleRegType) {
|
|
|
|
unsigned argSize = target.getTargetData().getTypeSize(LR->getType());
|
2004-08-12 18:29:05 +00:00
|
|
|
unsigned slotSize = SparcV9FrameInfo::SizeOfEachArgOnStack;
|
2003-05-31 07:32:01 +00:00
|
|
|
assert(argSize <= slotSize && "Insufficient slot size!");
|
|
|
|
offsetFromFP += slotSize - argSize;
|
|
|
|
}
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2005-07-27 05:53:44 +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.
|
|
|
|
//---------------------------------------------------------------------------
|
2005-04-21 23:30:14 +00:00
|
|
|
void SparcV9RegInfo::suggestRegs4CallArgs(MachineInstr *CallMI,
|
2005-07-27 05:53:44 +00:00
|
|
|
LiveRangeInfo& LRI) const {
|
2004-06-02 05:55:25 +00:00
|
|
|
assert ( (target.getInstrInfo())->isCall(CallMI->getOpcode()) );
|
2001-10-15 16:25:28 +00:00
|
|
|
|
2005-04-21 23:30:14 +00:00
|
|
|
CallArgsDescriptor* argDesc = CallArgsDescriptor::get(CallMI);
|
|
|
|
|
2002-09-28 16:59:05 +00:00
|
|
|
suggestReg4CallAddr(CallMI, LRI);
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2002-09-28 16:59:05 +00:00
|
|
|
// First color the return value of the call instruction, if any.
|
|
|
|
// The return value will be in %o0 if the value is an integer type,
|
|
|
|
// or in %f0 if the value is a float type.
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
2002-09-28 16:59:05 +00:00
|
|
|
if (const Value *RetVal = argDesc->getReturnValue()) {
|
2005-06-12 23:52:58 +00:00
|
|
|
V9LiveRange *RetValLR = LRI.getLiveRangeForValue(RetVal);
|
2002-09-28 16:59:05 +00:00
|
|
|
assert(RetValLR && "No LR for return Value of call!");
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2003-01-15 21:14:32 +00:00
|
|
|
unsigned RegClassID = RetValLR->getRegClassID();
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2001-10-21 16:43:41 +00:00
|
|
|
// now suggest a register depending on the register class of ret arg
|
2005-04-21 23:30:14 +00:00
|
|
|
if( RegClassID == IntRegClassID )
|
2004-02-25 18:44:15 +00:00
|
|
|
RetValLR->setSuggestedColor(SparcV9IntRegClass::o0);
|
2005-04-21 23:30:14 +00:00
|
|
|
else if (RegClassID == FloatRegClassID )
|
2004-02-25 18:44:15 +00:00
|
|
|
RetValLR->setSuggestedColor(SparcV9FloatRegClass::f0 );
|
2001-10-21 16:43:41 +00:00
|
|
|
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
|
|
|
|
|
|
|
// 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();
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2002-04-25 04:42:21 +00:00
|
|
|
for(unsigned argNo=0, i=0, intArgNo=0, fpArgNo=0;
|
2005-04-21 23:30:14 +00:00
|
|
|
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();
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
// get the LR of call operand (parameter)
|
2005-06-12 23:52:58 +00:00
|
|
|
V9LiveRange *const LR = LRI.getLiveRangeForValue(CallArg);
|
2003-05-31 07:32:01 +00:00
|
|
|
if (!LR)
|
|
|
|
continue; // no live ranges for constants and labels
|
2002-09-28 16:59:05 +00:00
|
|
|
|
2003-07-25 21:12:15 +00:00
|
|
|
unsigned regType = getRegTypeForLR(LR);
|
2003-05-31 07:32:01 +00:00
|
|
|
unsigned regClassIDOfArgReg = BadRegClass; // chosen reg class (unused)
|
2002-09-28 16:59:05 +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,
|
2003-05-31 07:32:01 +00:00
|
|
|
argNo, regClassIDOfArgReg)
|
2002-05-19 15:25:51 +00:00
|
|
|
: regNumForFPArg(regType, /*inCallee*/ false, /*isVarArgs*/ false,
|
2005-04-21 23:30:14 +00:00
|
|
|
argNo, regClassIDOfArgReg);
|
|
|
|
|
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.
|
2003-05-31 07:32:01 +00:00
|
|
|
if(regNum != getInvalidRegNum())
|
2002-04-25 04:42:21 +00:00
|
|
|
LR->setSuggestedColor(regNum);
|
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
|
|
|
//---------------------------------------------------------------------------
|
2003-06-01 02:48:23 +00:00
|
|
|
// this method is called for an LLVM return instruction to identify which
|
2001-09-30 23:16:47 +00:00
|
|
|
// values will be returned from this method and to suggest colors.
|
|
|
|
//---------------------------------------------------------------------------
|
2005-04-21 23:30:14 +00:00
|
|
|
void SparcV9RegInfo::suggestReg4RetValue(MachineInstr *RetMI,
|
2003-07-29 19:53:21 +00:00
|
|
|
LiveRangeInfo& LRI) const {
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2004-06-02 05:55:25 +00:00
|
|
|
assert( target.getInstrInfo()->isReturn( RetMI->getOpcode() ) );
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2002-07-08 23:23:12 +00:00
|
|
|
suggestReg4RetAddr(RetMI, LRI);
|
2001-09-30 23:16:47 +00:00
|
|
|
|
2003-05-31 07:32:01 +00:00
|
|
|
// To find the return value (if any), we can get the LLVM return instr.
|
|
|
|
// from the return address register, which is the first operand
|
|
|
|
Value* tmpI = RetMI->getOperand(0).getVRegValue();
|
|
|
|
ReturnInst* retI=cast<ReturnInst>(cast<TmpInstruction>(tmpI)->getOperand(0));
|
|
|
|
if (const Value *RetVal = retI->getReturnValue())
|
2005-06-12 23:52:58 +00:00
|
|
|
if (V9LiveRange *const LR = LRI.getLiveRangeForValue(RetVal))
|
2003-05-31 07:32:01 +00:00
|
|
|
LR->setSuggestedColor(LR->getRegClassID() == IntRegClassID
|
2004-02-25 18:44:15 +00:00
|
|
|
? (unsigned) SparcV9IntRegClass::i0
|
|
|
|
: (unsigned) SparcV9FloatRegClass::f0);
|
2001-09-18 22:52:44 +00:00
|
|
|
}
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2002-07-08 23:23:12 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// Check if a specified register type needs a scratch register to be
|
|
|
|
// copied to/from memory. If it does, the reg. type that must be used
|
|
|
|
// for scratch registers is returned in scratchRegType.
|
|
|
|
//
|
|
|
|
// Only the int CC register needs such a scratch register.
|
|
|
|
// The FP CC registers can (and must) be copied directly to/from memory.
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
bool
|
2004-02-25 18:44:15 +00:00
|
|
|
SparcV9RegInfo::regTypeNeedsScratchReg(int RegType,
|
2002-07-08 23:23:12 +00:00
|
|
|
int& scratchRegType) const
|
|
|
|
{
|
|
|
|
if (RegType == IntCCRegType)
|
|
|
|
{
|
|
|
|
scratchRegType = IntRegType;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
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
|
2002-07-08 23:23:12 +00:00
|
|
|
// register number.
|
2001-09-30 23:16:47 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
void
|
2004-02-25 18:44:15 +00:00
|
|
|
SparcV9RegInfo::cpReg2RegMI(std::vector<MachineInstr*>& mvec,
|
2002-07-08 23:23:12 +00:00
|
|
|
unsigned SrcReg,
|
2002-05-19 15:25:51 +00:00
|
|
|
unsigned DestReg,
|
2002-07-08 23:23:12 +00:00
|
|
|
int RegType) const {
|
2005-04-21 23:30:14 +00:00
|
|
|
assert( ((int)SrcReg != getInvalidRegNum()) &&
|
2003-06-06 09:52:23 +00:00
|
|
|
((int)DestReg != getInvalidRegNum()) &&
|
2005-07-27 05:53:44 +00:00
|
|
|
"Invalid Register");
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
MachineInstr * MI = NULL;
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
switch( RegType ) {
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2001-10-18 22:38:52 +00:00
|
|
|
case IntCCRegType:
|
2003-05-20 20:32:24 +00:00
|
|
|
if (getRegType(DestReg) == IntRegType) {
|
|
|
|
// copy intCC reg to int reg
|
2003-07-10 19:42:11 +00:00
|
|
|
MI = (BuildMI(V9::RDCCR, 2)
|
2004-02-25 18:44:15 +00:00
|
|
|
.addMReg(getUnifiedRegNum(SparcV9RegInfo::IntCCRegClassID,
|
|
|
|
SparcV9IntCCRegClass::ccr))
|
2004-02-22 19:23:26 +00:00
|
|
|
.addMReg(DestReg,MachineOperand::Def));
|
2003-05-20 20:32:24 +00:00
|
|
|
} else {
|
|
|
|
// copy int reg to intCC reg
|
|
|
|
assert(getRegType(SrcReg) == IntRegType
|
|
|
|
&& "Can only copy CC reg to/from integer reg");
|
2003-07-10 19:42:11 +00:00
|
|
|
MI = (BuildMI(V9::WRCCRr, 3)
|
|
|
|
.addMReg(SrcReg)
|
2004-02-25 18:44:15 +00:00
|
|
|
.addMReg(SparcV9IntRegClass::g0)
|
|
|
|
.addMReg(getUnifiedRegNum(SparcV9RegInfo::IntCCRegClassID,
|
|
|
|
SparcV9IntCCRegClass::ccr),
|
2004-02-22 19:23:26 +00:00
|
|
|
MachineOperand::Def));
|
2003-05-20 20:32:24 +00:00
|
|
|
}
|
2002-07-08 23:23:12 +00:00
|
|
|
break;
|
2005-04-21 23:30:14 +00:00
|
|
|
|
|
|
|
case FloatCCRegType:
|
2002-07-08 23:23:12 +00:00
|
|
|
assert(0 && "Cannot copy FPCC register to any other register");
|
2002-05-19 15:25:51 +00:00
|
|
|
break;
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
case IntRegType:
|
2003-05-27 22:40:34 +00:00
|
|
|
MI = BuildMI(V9::ADDr, 3).addMReg(SrcReg).addMReg(getZeroRegNum())
|
2004-02-22 19:23:26 +00:00
|
|
|
.addMReg(DestReg, MachineOperand::Def);
|
2001-09-30 23:16:47 +00:00
|
|
|
break;
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2001-09-30 23:16:47 +00:00
|
|
|
case FPSingleRegType:
|
2004-02-22 19:23:26 +00:00
|
|
|
MI = BuildMI(V9::FMOVS, 2).addMReg(SrcReg)
|
|
|
|
.addMReg(DestReg, MachineOperand::Def);
|
2001-09-30 23:16:47 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FPDoubleRegType:
|
2004-02-22 19:23:26 +00:00
|
|
|
MI = BuildMI(V9::FMOVD, 2).addMReg(SrcReg)
|
|
|
|
.addMReg(DestReg, MachineOperand::Def);
|
2001-09-30 23:16:47 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2002-05-19 15:25:51 +00:00
|
|
|
assert(0 && "Unknown RegType");
|
2002-07-08 23:23:12 +00:00
|
|
|
break;
|
2001-09-18 22:52:44 +00:00
|
|
|
}
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2002-05-19 15:25:51 +00:00
|
|
|
if (MI)
|
|
|
|
mvec.push_back(MI);
|
2001-09-30 23:16:47 +00:00
|
|
|
}
|
|
|
|
|
2004-08-18 17:44:14 +00:00
|
|
|
/// cpReg2MemMI - Generate SparcV9 MachineInstrs to store a register
|
|
|
|
/// (SrcReg) to memory, at [PtrReg + Offset]. Register numbers must be the
|
|
|
|
/// unified register numbers. RegType must be the SparcV9 register type
|
|
|
|
/// of SrcReg. When SrcReg is %ccr, scratchReg must be the
|
|
|
|
/// number of a free integer register. The newly-generated MachineInstrs
|
|
|
|
/// are appended to mvec.
|
|
|
|
///
|
|
|
|
void SparcV9RegInfo::cpReg2MemMI(std::vector<MachineInstr*>& mvec,
|
|
|
|
unsigned SrcReg, unsigned PtrReg, int Offset,
|
|
|
|
int RegType, int scratchReg) const {
|
|
|
|
unsigned OffReg = SparcV9::g4; // Use register g4 for holding large offsets
|
|
|
|
bool useImmediateOffset = true;
|
|
|
|
|
|
|
|
// If the Offset will not fit in the signed-immediate field, we put it in
|
|
|
|
// register g4. This takes advantage of the fact that all the opcodes
|
|
|
|
// used below have the same size immed. field.
|
|
|
|
if (RegType != IntCCRegType
|
|
|
|
&& !target.getInstrInfo()->constantFitsInImmedField(V9::LDXi, Offset)) {
|
|
|
|
// Put the offset into a register. We could do this in fewer steps,
|
|
|
|
// in some cases (see CreateSETSWConst()) but we're being lazy.
|
|
|
|
MachineInstr *MI = BuildMI(V9::SETHI, 2).addZImm(Offset).addMReg(OffReg,
|
|
|
|
MachineOperand::Def);
|
|
|
|
MI->getOperand(0).markHi32();
|
|
|
|
mvec.push_back(MI);
|
|
|
|
MI = BuildMI(V9::ORi,3).addMReg(OffReg).addZImm(Offset).addMReg(OffReg,
|
|
|
|
MachineOperand::Def);
|
|
|
|
MI->getOperand(1).markLo32();
|
|
|
|
mvec.push_back(MI);
|
|
|
|
MI = BuildMI(V9::SRAi5,3).addMReg(OffReg).addZImm(0).addMReg(OffReg,
|
|
|
|
MachineOperand::Def);
|
|
|
|
mvec.push_back(MI);
|
|
|
|
useImmediateOffset = false;
|
|
|
|
}
|
2003-07-29 19:53:21 +00:00
|
|
|
|
2004-08-18 17:44:14 +00:00
|
|
|
MachineInstr *MI = 0;
|
2003-01-15 17:47:49 +00:00
|
|
|
switch (RegType) {
|
2001-10-16 01:23:19 +00:00
|
|
|
case IntRegType:
|
2004-08-18 17:44:14 +00:00
|
|
|
if (useImmediateOffset)
|
2003-07-29 19:53:21 +00:00
|
|
|
MI = BuildMI(V9::STXi,3).addMReg(SrcReg).addMReg(PtrReg).addSImm(Offset);
|
|
|
|
else
|
|
|
|
MI = BuildMI(V9::STXr,3).addMReg(SrcReg).addMReg(PtrReg).addMReg(OffReg);
|
2001-10-16 01:23:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FPSingleRegType:
|
2004-08-18 17:44:14 +00:00
|
|
|
if (useImmediateOffset)
|
2003-07-29 19:53:21 +00:00
|
|
|
MI = BuildMI(V9::STFi, 3).addMReg(SrcReg).addMReg(PtrReg).addSImm(Offset);
|
|
|
|
else
|
|
|
|
MI = BuildMI(V9::STFr, 3).addMReg(SrcReg).addMReg(PtrReg).addMReg(OffReg);
|
2001-10-16 01:23:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FPDoubleRegType:
|
2004-08-18 17:44:14 +00:00
|
|
|
if (useImmediateOffset)
|
2003-07-29 19:53:21 +00:00
|
|
|
MI = BuildMI(V9::STDFi,3).addMReg(SrcReg).addMReg(PtrReg).addSImm(Offset);
|
|
|
|
else
|
|
|
|
MI = BuildMI(V9::STDFr,3).addMReg(SrcReg).addMReg(PtrReg).addSImm(OffReg);
|
2001-10-16 01:23:19 +00:00
|
|
|
break;
|
|
|
|
|
2001-11-03 19:59:59 +00:00
|
|
|
case IntCCRegType:
|
2004-08-18 17:44:14 +00:00
|
|
|
assert(scratchReg >= 0 && getRegType(scratchReg) == IntRegType
|
|
|
|
&& "Need a scratch reg of integer type to load or store %ccr");
|
|
|
|
MI = BuildMI(V9::RDCCR, 2).addMReg(SparcV9::ccr)
|
|
|
|
.addMReg(scratchReg, MachineOperand::Def);
|
2002-07-08 23:23:12 +00:00
|
|
|
mvec.push_back(MI);
|
2003-07-29 19:53:21 +00:00
|
|
|
cpReg2MemMI(mvec, scratchReg, PtrReg, Offset, IntRegType);
|
2003-01-15 17:47:49 +00:00
|
|
|
return;
|
2003-07-29 19:53:21 +00:00
|
|
|
|
2004-04-19 19:12:12 +00:00
|
|
|
case SpecialRegType: // used only for %fsr itself.
|
2003-05-27 00:02:22 +00:00
|
|
|
case FloatCCRegType: {
|
2004-08-18 17:44:14 +00:00
|
|
|
if (useImmediateOffset)
|
|
|
|
MI = BuildMI(V9::STXFSRi,3).addMReg(SparcV9::fsr).addMReg(PtrReg)
|
|
|
|
.addSImm(Offset);
|
2003-07-29 19:53:21 +00:00
|
|
|
else
|
2004-08-18 17:44:14 +00:00
|
|
|
MI = BuildMI(V9::STXFSRr,3).addMReg(SparcV9::fsr).addMReg(PtrReg)
|
|
|
|
.addMReg(OffReg);
|
2002-07-08 23:23:12 +00:00
|
|
|
break;
|
2003-05-27 00:02:22 +00:00
|
|
|
}
|
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
|
|
|
}
|
2003-01-15 17:47:49 +00:00
|
|
|
mvec.push_back(MI);
|
2001-10-16 01:23:19 +00:00
|
|
|
}
|
|
|
|
|
2004-08-18 17:44:14 +00:00
|
|
|
/// cpMem2RegMI - Generate SparcV9 MachineInstrs to load a register
|
|
|
|
/// (DestReg) from memory, at [PtrReg + Offset]. Register numbers must be the
|
|
|
|
/// unified register numbers. RegType must be the SparcV9 register type
|
|
|
|
/// of DestReg. When DestReg is %ccr, scratchReg must be the
|
|
|
|
/// number of a free integer register. The newly-generated MachineInstrs
|
|
|
|
/// are appended to mvec.
|
|
|
|
///
|
|
|
|
void SparcV9RegInfo::cpMem2RegMI(std::vector<MachineInstr*>& mvec,
|
|
|
|
unsigned PtrReg, int Offset, unsigned DestReg,
|
|
|
|
int RegType, int scratchReg) const {
|
|
|
|
unsigned OffReg = SparcV9::g4; // Use register g4 for holding large offsets
|
|
|
|
bool useImmediateOffset = true;
|
|
|
|
|
|
|
|
// If the Offset will not fit in the signed-immediate field, we put it in
|
|
|
|
// register g4. This takes advantage of the fact that all the opcodes
|
|
|
|
// used below have the same size immed. field.
|
|
|
|
if (RegType != IntCCRegType
|
|
|
|
&& !target.getInstrInfo()->constantFitsInImmedField(V9::LDXi, Offset)) {
|
|
|
|
MachineInstr *MI = BuildMI(V9::SETHI, 2).addZImm(Offset).addMReg(OffReg,
|
|
|
|
MachineOperand::Def);
|
|
|
|
MI->getOperand(0).markHi32();
|
|
|
|
mvec.push_back(MI);
|
|
|
|
MI = BuildMI(V9::ORi,3).addMReg(OffReg).addZImm(Offset).addMReg(OffReg,
|
|
|
|
MachineOperand::Def);
|
|
|
|
MI->getOperand(1).markLo32();
|
|
|
|
mvec.push_back(MI);
|
|
|
|
MI = BuildMI(V9::SRAi5,3).addMReg(OffReg).addZImm(0).addMReg(OffReg,
|
|
|
|
MachineOperand::Def);
|
|
|
|
mvec.push_back(MI);
|
|
|
|
useImmediateOffset = false;
|
|
|
|
}
|
2001-10-16 01:23:19 +00:00
|
|
|
|
2004-08-18 17:44:14 +00:00
|
|
|
MachineInstr *MI = 0;
|
2002-02-04 05:59:25 +00:00
|
|
|
switch (RegType) {
|
2001-10-16 01:23:19 +00:00
|
|
|
case IntRegType:
|
2004-08-18 17:44:14 +00:00
|
|
|
if (useImmediateOffset)
|
2004-02-22 19:23:26 +00:00
|
|
|
MI = BuildMI(V9::LDXi, 3).addMReg(PtrReg).addSImm(Offset)
|
|
|
|
.addMReg(DestReg, MachineOperand::Def);
|
2003-07-29 19:53:21 +00:00
|
|
|
else
|
2004-02-22 19:23:26 +00:00
|
|
|
MI = BuildMI(V9::LDXr, 3).addMReg(PtrReg).addMReg(OffReg)
|
|
|
|
.addMReg(DestReg, MachineOperand::Def);
|
2001-10-16 01:23:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FPSingleRegType:
|
2004-08-18 17:44:14 +00:00
|
|
|
if (useImmediateOffset)
|
2004-02-22 19:23:26 +00:00
|
|
|
MI = BuildMI(V9::LDFi, 3).addMReg(PtrReg).addSImm(Offset)
|
|
|
|
.addMReg(DestReg, MachineOperand::Def);
|
2003-07-29 19:53:21 +00:00
|
|
|
else
|
2004-02-22 19:23:26 +00:00
|
|
|
MI = BuildMI(V9::LDFr, 3).addMReg(PtrReg).addMReg(OffReg)
|
|
|
|
.addMReg(DestReg, MachineOperand::Def);
|
2001-10-16 01:23:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FPDoubleRegType:
|
2004-08-18 17:44:14 +00:00
|
|
|
if (useImmediateOffset)
|
2004-02-22 19:23:26 +00:00
|
|
|
MI= BuildMI(V9::LDDFi, 3).addMReg(PtrReg).addSImm(Offset)
|
|
|
|
.addMReg(DestReg, MachineOperand::Def);
|
2003-07-29 19:53:21 +00:00
|
|
|
else
|
2004-02-22 19:23:26 +00:00
|
|
|
MI= BuildMI(V9::LDDFr, 3).addMReg(PtrReg).addMReg(OffReg)
|
|
|
|
.addMReg(DestReg, MachineOperand::Def);
|
2001-10-16 01:23:19 +00:00
|
|
|
break;
|
|
|
|
|
2001-11-03 19:59:59 +00:00
|
|
|
case IntCCRegType:
|
2004-08-18 17:44:14 +00:00
|
|
|
assert(scratchReg >= 0 && getRegType(scratchReg) == IntRegType
|
|
|
|
&& "Need a scratch reg of integer type to load or store %ccr");
|
2003-07-29 19:53:21 +00:00
|
|
|
cpMem2RegMI(mvec, PtrReg, Offset, scratchReg, IntRegType);
|
2004-08-18 17:44:14 +00:00
|
|
|
MI = BuildMI(V9::WRCCRr, 3).addMReg(scratchReg).addMReg(SparcV9::g0)
|
|
|
|
.addMReg(SparcV9::ccr, MachineOperand::Def);
|
2002-07-08 23:23:12 +00:00
|
|
|
break;
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2004-04-19 19:12:12 +00:00
|
|
|
case SpecialRegType: // used only for %fsr itself
|
2003-05-27 00:02:22 +00:00
|
|
|
case FloatCCRegType: {
|
2004-08-18 17:44:14 +00:00
|
|
|
if (useImmediateOffset)
|
2003-07-29 19:53:21 +00:00
|
|
|
MI = BuildMI(V9::LDXFSRi, 3).addMReg(PtrReg).addSImm(Offset)
|
2004-08-18 17:44:14 +00:00
|
|
|
.addMReg(SparcV9::fsr, MachineOperand::Def);
|
2003-07-29 19:53:21 +00:00
|
|
|
else
|
|
|
|
MI = BuildMI(V9::LDXFSRr, 3).addMReg(PtrReg).addMReg(OffReg)
|
2004-08-18 17:44:14 +00:00
|
|
|
.addMReg(SparcV9::fsr, MachineOperand::Def);
|
2002-07-08 23:23:12 +00:00
|
|
|
break;
|
2003-05-27 00:02:22 +00:00
|
|
|
}
|
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
|
|
|
}
|
2003-01-15 17:47:49 +00:00
|
|
|
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
|
2004-02-25 18:44:15 +00:00
|
|
|
SparcV9RegInfo::cpValue2Value(Value *Src, Value *Dest,
|
2004-06-04 20:51:40 +00:00
|
|
|
std::vector<MachineInstr*>& mvec) const {
|
2003-07-25 21:12:15 +00:00
|
|
|
int RegType = getRegTypeForDataType(Src->getType());
|
2001-11-03 17:13:27 +00:00
|
|
|
MachineInstr * MI = NULL;
|
|
|
|
|
2004-06-04 20:51:40 +00:00
|
|
|
switch (RegType) {
|
2001-11-12 14:45:33 +00:00
|
|
|
case IntRegType:
|
2003-05-27 22:40:34 +00:00
|
|
|
MI = BuildMI(V9::ADDr, 3).addReg(Src).addMReg(getZeroRegNum())
|
2003-05-20 20:32:24 +00:00
|
|
|
.addRegDef(Dest);
|
2001-11-12 14:45:33 +00:00
|
|
|
break;
|
|
|
|
case FPSingleRegType:
|
2003-05-20 20:32:24 +00:00
|
|
|
MI = BuildMI(V9::FMOVS, 2).addReg(Src).addRegDef(Dest);
|
2001-11-12 14:45:33 +00:00
|
|
|
break;
|
|
|
|
case FPDoubleRegType:
|
2003-05-20 20:32:24 +00:00
|
|
|
MI = BuildMI(V9::FMOVD, 2).addReg(Src).addRegDef(Dest);
|
2001-11-12 14:45:33 +00:00
|
|
|
break;
|
|
|
|
default:
|
2004-06-04 20:51:40 +00:00
|
|
|
assert(0 && "Unknown RegType in cpValue2Value");
|
2001-11-12 14:45:33 +00:00
|
|
|
}
|
|
|
|
|
2002-10-28 20:10:56 +00:00
|
|
|
mvec.push_back(MI);
|
2001-11-03 17:13:27 +00:00
|
|
|
}
|
2001-10-16 01:23:19 +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
|
|
|
|
2005-06-12 23:52:58 +00:00
|
|
|
void SparcV9RegInfo::printReg(const V9LiveRange *LR) const {
|
2003-01-15 21:14:32 +00:00
|
|
|
unsigned RegClassID = LR->getRegClassID();
|
2003-09-01 19:58:02 +00:00
|
|
|
std::cerr << " Node ";
|
2001-09-18 22:52:44 +00:00
|
|
|
|
2002-02-04 05:59:25 +00:00
|
|
|
if (!LR->hasColor()) {
|
2003-05-21 17:59:06 +00:00
|
|
|
std::cerr << " - could not find a color\n";
|
2001-09-18 22:52:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2001-09-18 22:52:44 +00:00
|
|
|
// if a color is found
|
2001-09-14 20:31:39 +00:00
|
|
|
|
2003-05-21 17:59:06 +00:00
|
|
|
std::cerr << " colored with color "<< LR->getColor();
|
2001-09-14 20:31:39 +00:00
|
|
|
|
2003-05-27 00:02:22 +00:00
|
|
|
unsigned uRegName = getUnifiedRegNum(RegClassID, LR->getColor());
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2003-05-27 00:02:22 +00:00
|
|
|
std::cerr << "[";
|
|
|
|
std::cerr<< getUnifiedRegName(uRegName);
|
|
|
|
if (RegClassID == FloatRegClassID && LR->getType() == Type::DoubleTy)
|
|
|
|
std::cerr << "+" << getUnifiedRegName(uRegName+1);
|
|
|
|
std::cerr << "]\n";
|
2001-09-18 22:52:44 +00:00
|
|
|
}
|
2003-11-11 22:41:34 +00:00
|
|
|
|
|
|
|
} // End llvm namespace
|