blob: 42f68dba6fecf9cb1eca0ed2632451b8a66fe6c3 [file] [log] [blame]
Brian Gaeke94e95d22004-02-25 18:44:15 +00001//===-- SparcV9RegInfo.cpp - SparcV9 Target Register Information --------------===//
John Criswell482202a2003-10-20 19:43:21 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
Chris Lattner029af0b2002-02-03 07:52:04 +00009//
Brian Gaeke94e95d22004-02-25 18:44:15 +000010// This file contains implementation of SparcV9 specific helper methods
Chris Lattner029af0b2002-02-03 07:52:04 +000011// used for register allocation.
12//
13//===----------------------------------------------------------------------===//
14
Misha Brukman7ae7f842002-10-28 00:28:31 +000015#include "llvm/CodeGen/MachineFunction.h"
Chris Lattnerd47aac92002-12-28 20:21:29 +000016#include "llvm/CodeGen/MachineFunctionInfo.h"
Vikram S. Advee9327f02002-05-19 15:25:51 +000017#include "llvm/CodeGen/InstrSelection.h"
Chris Lattner1ebaa902003-01-15 17:47:49 +000018#include "llvm/CodeGen/MachineInstrBuilder.h"
Anand Shuklae6c3ee62003-06-01 02:48:23 +000019#include "llvm/CodeGen/MachineCodeForInstruction.h"
Vikram S. Advee9327f02002-05-19 15:25:51 +000020#include "llvm/CodeGen/MachineInstrAnnot.h"
Chris Lattnerbb6fa4b2004-01-09 16:17:09 +000021#include "RegAlloc/LiveRangeInfo.h"
22#include "RegAlloc/LiveRange.h"
Misha Brukmanb01a80a2003-12-17 22:04:00 +000023#include "llvm/DerivedTypes.h"
24#include "llvm/Function.h"
Chris Lattner5216cc52002-02-04 05:59:25 +000025#include "llvm/iTerminators.h"
26#include "llvm/iOther.h"
Brian Gaeke94e95d22004-02-25 18:44:15 +000027#include "SparcV9Internals.h"
28#include "SparcV9RegClassInfo.h"
29#include "SparcV9RegInfo.h"
30#include "SparcV9TargetMachine.h"
Chris Lattnerb0ddffa2001-09-14 03:47:57 +000031
Brian Gaeke960707c2003-11-11 22:41:34 +000032namespace llvm {
33
Chris Lattner24c1d5e2003-01-14 23:05:08 +000034enum {
35 BadRegClass = ~0
36};
37
Brian Gaeke94e95d22004-02-25 18:44:15 +000038SparcV9RegInfo::SparcV9RegInfo(const SparcV9TargetMachine &tgt)
Vikram S. Advea83804a2003-05-31 07:32:01 +000039 : TargetRegInfo(tgt), NumOfIntArgRegs(6), NumOfFloatArgRegs(32)
40{
Brian Gaeke94e95d22004-02-25 18:44:15 +000041 MachineRegClassArr.push_back(new SparcV9IntRegClass(IntRegClassID));
42 MachineRegClassArr.push_back(new SparcV9FloatRegClass(FloatRegClassID));
43 MachineRegClassArr.push_back(new SparcV9IntCCRegClass(IntCCRegClassID));
44 MachineRegClassArr.push_back(new SparcV9FloatCCRegClass(FloatCCRegClassID));
45 MachineRegClassArr.push_back(new SparcV9SpecialRegClass(SpecialRegClassID));
Vikram S. Adveaee67012002-07-08 23:23:12 +000046
Brian Gaeke94e95d22004-02-25 18:44:15 +000047 assert(SparcV9FloatRegClass::StartOfNonVolatileRegs == 32 &&
Chris Lattner5216cc52002-02-04 05:59:25 +000048 "32 Float regs are used for float arg passing");
49}
50
51
Vikram S. Advedb1435f2002-03-18 03:12:16 +000052// getZeroRegNum - returns the register that contains always zero.
53// this is the unified register number
Chris Lattner5216cc52002-02-04 05:59:25 +000054//
Brian Gaeke94e95d22004-02-25 18:44:15 +000055unsigned SparcV9RegInfo::getZeroRegNum() const {
56 return getUnifiedRegNum(SparcV9RegInfo::IntRegClassID,
57 SparcV9IntRegClass::g0);
Vikram S. Advedb1435f2002-03-18 03:12:16 +000058}
Chris Lattner5216cc52002-02-04 05:59:25 +000059
60// getCallAddressReg - returns the reg used for pushing the address when a
61// method is called. This can be used for other purposes between calls
62//
Brian Gaeke94e95d22004-02-25 18:44:15 +000063unsigned SparcV9RegInfo::getCallAddressReg() const {
64 return getUnifiedRegNum(SparcV9RegInfo::IntRegClassID,
65 SparcV9IntRegClass::o7);
Chris Lattner5216cc52002-02-04 05:59:25 +000066}
67
68// Returns the register containing the return address.
69// It should be made sure that this register contains the return
70// value when a return instruction is reached.
71//
Brian Gaeke94e95d22004-02-25 18:44:15 +000072unsigned SparcV9RegInfo::getReturnAddressReg() const {
73 return getUnifiedRegNum(SparcV9RegInfo::IntRegClassID,
74 SparcV9IntRegClass::i7);
Chris Lattner56e91662002-08-12 21:25:05 +000075}
76
77// Register get name implementations...
78
Brian Gaeke94e95d22004-02-25 18:44:15 +000079// Int register names in same order as enum in class SparcV9IntRegClass
Chris Lattner56e91662002-08-12 21:25:05 +000080static const char * const IntRegNames[] = {
81 "o0", "o1", "o2", "o3", "o4", "o5", "o7",
82 "l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7",
83 "i0", "i1", "i2", "i3", "i4", "i5",
84 "i6", "i7",
85 "g0", "g1", "g2", "g3", "g4", "g5", "g6", "g7",
86 "o6"
87};
88
Brian Gaeke94e95d22004-02-25 18:44:15 +000089const char * const SparcV9IntRegClass::getRegName(unsigned reg) const {
Chris Lattner56e91662002-08-12 21:25:05 +000090 assert(reg < NumOfAllRegs);
91 return IntRegNames[reg];
92}
93
94static const char * const FloatRegNames[] = {
95 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9",
96 "f10", "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18", "f19",
97 "f20", "f21", "f22", "f23", "f24", "f25", "f26", "f27", "f28", "f29",
98 "f30", "f31", "f32", "f33", "f34", "f35", "f36", "f37", "f38", "f39",
99 "f40", "f41", "f42", "f43", "f44", "f45", "f46", "f47", "f48", "f49",
100 "f50", "f51", "f52", "f53", "f54", "f55", "f56", "f57", "f58", "f59",
101 "f60", "f61", "f62", "f63"
102};
103
Brian Gaeke94e95d22004-02-25 18:44:15 +0000104const char * const SparcV9FloatRegClass::getRegName(unsigned reg) const {
Chris Lattner56e91662002-08-12 21:25:05 +0000105 assert (reg < NumOfAllRegs);
106 return FloatRegNames[reg];
107}
108
109
110static const char * const IntCCRegNames[] = {
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000111 "xcc", "icc", "ccr"
Chris Lattner56e91662002-08-12 21:25:05 +0000112};
113
Brian Gaeke94e95d22004-02-25 18:44:15 +0000114const char * const SparcV9IntCCRegClass::getRegName(unsigned reg) const {
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000115 assert(reg < 3);
Chris Lattner56e91662002-08-12 21:25:05 +0000116 return IntCCRegNames[reg];
117}
118
119static const char * const FloatCCRegNames[] = {
120 "fcc0", "fcc1", "fcc2", "fcc3"
121};
122
Brian Gaeke94e95d22004-02-25 18:44:15 +0000123const char * const SparcV9FloatCCRegClass::getRegName(unsigned reg) const {
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000124 assert (reg < 5);
Chris Lattner56e91662002-08-12 21:25:05 +0000125 return FloatCCRegNames[reg];
Chris Lattner5216cc52002-02-04 05:59:25 +0000126}
127
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000128static const char * const SpecialRegNames[] = {
129 "fsr"
130};
131
Brian Gaeke94e95d22004-02-25 18:44:15 +0000132const char * const SparcV9SpecialRegClass::getRegName(unsigned reg) const {
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000133 assert (reg < 1);
134 return SpecialRegNames[reg];
Chris Lattner5216cc52002-02-04 05:59:25 +0000135}
136
Vikram S. Advedb1435f2002-03-18 03:12:16 +0000137// Get unified reg number for frame pointer
Brian Gaeke94e95d22004-02-25 18:44:15 +0000138unsigned SparcV9RegInfo::getFramePointer() const {
139 return getUnifiedRegNum(SparcV9RegInfo::IntRegClassID,
140 SparcV9IntRegClass::i6);
Chris Lattner5216cc52002-02-04 05:59:25 +0000141}
142
Vikram S. Advedb1435f2002-03-18 03:12:16 +0000143// Get unified reg number for stack pointer
Brian Gaeke94e95d22004-02-25 18:44:15 +0000144unsigned SparcV9RegInfo::getStackPointer() const {
145 return getUnifiedRegNum(SparcV9RegInfo::IntRegClassID,
146 SparcV9IntRegClass::o6);
Chris Lattner5216cc52002-02-04 05:59:25 +0000147}
148
149
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000150//---------------------------------------------------------------------------
151// Finds whether a call is an indirect call
152//---------------------------------------------------------------------------
153
154inline bool
155isVarArgsFunction(const Type *funcType) {
156 return cast<FunctionType>(cast<PointerType>(funcType)
157 ->getElementType())->isVarArg();
158}
159
160inline bool
161isVarArgsCall(const MachineInstr *CallMI) {
162 Value* callee = CallMI->getOperand(0).getVRegValue();
163 // const Type* funcType = isa<Function>(callee)? callee->getType()
164 // : cast<PointerType>(callee->getType())->getElementType();
165 const Type* funcType = callee->getType();
166 return isVarArgsFunction(funcType);
167}
168
169
Vikram S. Advea83804a2003-05-31 07:32:01 +0000170// Get the register number for the specified argument #argNo,
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000171//
172// Return value:
Vikram S. Advea83804a2003-05-31 07:32:01 +0000173// getInvalidRegNum(), if there is no int register available for the arg.
174// regNum, otherwise (this is NOT the unified reg. num).
175// regClassId is set to the register class ID.
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000176//
Vikram S. Advea83804a2003-05-31 07:32:01 +0000177int
Brian Gaeke94e95d22004-02-25 18:44:15 +0000178SparcV9RegInfo::regNumForIntArg(bool inCallee, bool isVarArgsCall,
Vikram S. Advea83804a2003-05-31 07:32:01 +0000179 unsigned argNo, unsigned& regClassId) const
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000180{
Vikram S. Advee9327f02002-05-19 15:25:51 +0000181 regClassId = IntRegClassID;
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000182 if (argNo >= NumOfIntArgRegs)
Vikram S. Advea83804a2003-05-31 07:32:01 +0000183 return getInvalidRegNum();
Vikram S. Advee9327f02002-05-19 15:25:51 +0000184 else
Brian Gaeke94e95d22004-02-25 18:44:15 +0000185 return argNo + (inCallee? SparcV9IntRegClass::i0 : SparcV9IntRegClass::o0);
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000186}
187
Vikram S. Advea83804a2003-05-31 07:32:01 +0000188// Get the register number for the specified FP argument #argNo,
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000189// Use INT regs for FP args if this is a varargs call.
190//
191// Return value:
Vikram S. Advea83804a2003-05-31 07:32:01 +0000192// getInvalidRegNum(), if there is no int register available for the arg.
193// regNum, otherwise (this is NOT the unified reg. num).
194// regClassId is set to the register class ID.
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000195//
Vikram S. Advea83804a2003-05-31 07:32:01 +0000196int
Brian Gaeke94e95d22004-02-25 18:44:15 +0000197SparcV9RegInfo::regNumForFPArg(unsigned regType,
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000198 bool inCallee, bool isVarArgsCall,
Vikram S. Advea83804a2003-05-31 07:32:01 +0000199 unsigned argNo, unsigned& regClassId) const
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000200{
Vikram S. Advee9327f02002-05-19 15:25:51 +0000201 if (isVarArgsCall)
Vikram S. Advea83804a2003-05-31 07:32:01 +0000202 return regNumForIntArg(inCallee, isVarArgsCall, argNo, regClassId);
Vikram S. Advee9327f02002-05-19 15:25:51 +0000203 else
204 {
205 regClassId = FloatRegClassID;
206 if (regType == FPSingleRegType)
207 return (argNo*2+1 >= NumOfFloatArgRegs)?
Brian Gaeke94e95d22004-02-25 18:44:15 +0000208 getInvalidRegNum() : SparcV9FloatRegClass::f0 + (argNo * 2 + 1);
Vikram S. Advee9327f02002-05-19 15:25:51 +0000209 else if (regType == FPDoubleRegType)
210 return (argNo*2 >= NumOfFloatArgRegs)?
Brian Gaeke94e95d22004-02-25 18:44:15 +0000211 getInvalidRegNum() : SparcV9FloatRegClass::f0 + (argNo * 2);
Vikram S. Advee9327f02002-05-19 15:25:51 +0000212 else
213 assert(0 && "Illegal FP register type");
Chris Lattner3091e112002-07-25 06:08:32 +0000214 return 0;
Vikram S. Advee9327f02002-05-19 15:25:51 +0000215 }
Vikram S. Adve02662bd2002-03-31 19:04:50 +0000216}
217
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000218
219//---------------------------------------------------------------------------
220// Finds the return address of a call sparc specific call instruction
221//---------------------------------------------------------------------------
Ruchira Sasanka24729a32001-10-21 16:43:41 +0000222
Brian Gaeke94e95d22004-02-25 18:44:15 +0000223// The following 4 methods are used to find the RegType (SparcV9Internals.h)
Vikram S. Advee9327f02002-05-19 15:25:51 +0000224// of a LiveRange, a Value, and for a given register unified reg number.
Chris Lattner5216cc52002-02-04 05:59:25 +0000225//
Brian Gaeke94e95d22004-02-25 18:44:15 +0000226int SparcV9RegInfo::getRegTypeForClassAndType(unsigned regClassID,
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000227 const Type* type) const
228{
Vikram S. Advee9327f02002-05-19 15:25:51 +0000229 switch (regClassID) {
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000230 case IntRegClassID: return IntRegType;
231 case FloatRegClassID:
232 if (type == Type::FloatTy) return FPSingleRegType;
233 else if (type == Type::DoubleTy) return FPDoubleRegType;
234 assert(0 && "Unknown type in FloatRegClass"); return 0;
235 case IntCCRegClassID: return IntCCRegType;
236 case FloatCCRegClassID: return FloatCCRegType;
237 case SpecialRegClassID: return SpecialRegType;
Vikram S. Advee9327f02002-05-19 15:25:51 +0000238 default: assert( 0 && "Unknown reg class ID"); return 0;
Chris Lattner5216cc52002-02-04 05:59:25 +0000239 }
240}
241
Brian Gaeke94e95d22004-02-25 18:44:15 +0000242int SparcV9RegInfo::getRegTypeForDataType(const Type* type) const
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000243{
244 return getRegTypeForClassAndType(getRegClassIDOfType(type), type);
Vikram S. Advee9327f02002-05-19 15:25:51 +0000245}
246
Brian Gaeke94e95d22004-02-25 18:44:15 +0000247int SparcV9RegInfo::getRegTypeForLR(const LiveRange *LR) const
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000248{
249 return getRegTypeForClassAndType(LR->getRegClassID(), LR->getType());
250}
Chris Lattner5216cc52002-02-04 05:59:25 +0000251
Brian Gaeke94e95d22004-02-25 18:44:15 +0000252int SparcV9RegInfo::getRegType(int unifiedRegNum) const
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000253{
Vikram S. Adveaee67012002-07-08 23:23:12 +0000254 if (unifiedRegNum < 32)
Chris Lattner5216cc52002-02-04 05:59:25 +0000255 return IntRegType;
Vikram S. Adveaee67012002-07-08 23:23:12 +0000256 else if (unifiedRegNum < (32 + 32))
Chris Lattner5216cc52002-02-04 05:59:25 +0000257 return FPSingleRegType;
Vikram S. Adveaee67012002-07-08 23:23:12 +0000258 else if (unifiedRegNum < (64 + 32))
Chris Lattner5216cc52002-02-04 05:59:25 +0000259 return FPDoubleRegType;
Vikram S. Adveaee67012002-07-08 23:23:12 +0000260 else if (unifiedRegNum < (64+32+4))
Chris Lattner5216cc52002-02-04 05:59:25 +0000261 return FloatCCRegType;
Vikram S. Adveaee67012002-07-08 23:23:12 +0000262 else if (unifiedRegNum < (64+32+4+2))
Chris Lattner5216cc52002-02-04 05:59:25 +0000263 return IntCCRegType;
264 else
Vikram S. Adveaee67012002-07-08 23:23:12 +0000265 assert(0 && "Invalid unified register number in getRegType");
Chris Lattner5536c9c2002-02-24 23:02:40 +0000266 return 0;
Chris Lattner5216cc52002-02-04 05:59:25 +0000267}
268
269
Vikram S. Adveaee67012002-07-08 23:23:12 +0000270// To find the register class used for a specified Type
271//
Brian Gaeke94e95d22004-02-25 18:44:15 +0000272unsigned SparcV9RegInfo::getRegClassIDOfType(const Type *type,
Chris Lattner3091e112002-07-25 06:08:32 +0000273 bool isCCReg) const {
Vikram S. Adveaee67012002-07-08 23:23:12 +0000274 Type::PrimitiveID ty = type->getPrimitiveID();
275 unsigned res;
276
277 // FIXME: Comparing types like this isn't very safe...
278 if ((ty && ty <= Type::LongTyID) || (ty == Type::LabelTyID) ||
279 (ty == Type::FunctionTyID) || (ty == Type::PointerTyID) )
280 res = IntRegClassID; // sparc int reg (ty=0: void)
281 else if (ty <= Type::DoubleTyID)
282 res = FloatRegClassID; // sparc float reg class
283 else {
284 //std::cerr << "TypeID: " << ty << "\n";
285 assert(0 && "Cannot resolve register class for type");
286 return 0;
287 }
288
Chris Lattnerf9fd5912003-01-15 21:14:32 +0000289 if (isCCReg)
290 return res + 2; // corresponding condition code register
Vikram S. Adveaee67012002-07-08 23:23:12 +0000291 else
292 return res;
293}
294
Brian Gaeke94e95d22004-02-25 18:44:15 +0000295unsigned SparcV9RegInfo::getRegClassIDOfRegType(int regType) const {
Vikram S. Adveaee67012002-07-08 23:23:12 +0000296 switch(regType) {
297 case IntRegType: return IntRegClassID;
298 case FPSingleRegType:
299 case FPDoubleRegType: return FloatRegClassID;
300 case IntCCRegType: return IntCCRegClassID;
301 case FloatCCRegType: return FloatCCRegClassID;
302 default:
303 assert(0 && "Invalid register type in getRegClassIDOfRegType");
304 return 0;
305 }
306}
307
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000308//---------------------------------------------------------------------------
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000309// Suggests a register for the ret address in the RET machine instruction.
310// We always suggest %i7 by convention.
311//---------------------------------------------------------------------------
Brian Gaeke94e95d22004-02-25 18:44:15 +0000312void SparcV9RegInfo::suggestReg4RetAddr(MachineInstr *RetMI,
Ruchira Sasanka086bf0f2001-10-15 16:25:28 +0000313 LiveRangeInfo& LRI) const {
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000314
Brian Gaekeb22186a2004-02-11 20:47:34 +0000315 assert(target.getInstrInfo().isReturn(RetMI->getOpcode()));
Vikram S. Adve84982772001-10-22 13:41:12 +0000316
Vikram S. Adveaee67012002-07-08 23:23:12 +0000317 // return address is always mapped to i7 so set it immediately
318 RetMI->SetRegForOperand(0, getUnifiedRegNum(IntRegClassID,
Brian Gaeke94e95d22004-02-25 18:44:15 +0000319 SparcV9IntRegClass::i7));
Vikram S. Adve84982772001-10-22 13:41:12 +0000320
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000321 // Possible Optimization:
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000322 // Instead of setting the color, we can suggest one. In that case,
Ruchira Sasanka086bf0f2001-10-15 16:25:28 +0000323 // we have to test later whether it received the suggested color.
324 // In that case, a LR has to be created at the start of method.
325 // It has to be done as follows (remove the setRegVal above):
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000326
Vikram S. Adveaee67012002-07-08 23:23:12 +0000327 // MachineOperand & MO = RetMI->getOperand(0);
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000328 // const Value *RetAddrVal = MO.getVRegValue();
329 // assert( RetAddrVal && "LR for ret address must be created at start");
330 // LiveRange * RetAddrLR = LRI.getLiveRangeForValue( RetAddrVal);
331 // RetAddrLR->setSuggestedColor(getUnifiedRegNum( IntRegClassID,
Brian Gaeke94e95d22004-02-25 18:44:15 +0000332 // SparcV9IntRegOrdr::i7) );
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000333}
334
335
336//---------------------------------------------------------------------------
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000337// Suggests a register for the ret address in the JMPL/CALL machine instr.
Brian Gaeke94e95d22004-02-25 18:44:15 +0000338// SparcV9 ABI dictates that %o7 be used for this purpose.
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000339//---------------------------------------------------------------------------
Vikram S. Adve6d1036d2002-09-28 16:59:05 +0000340void
Brian Gaeke94e95d22004-02-25 18:44:15 +0000341SparcV9RegInfo::suggestReg4CallAddr(MachineInstr * CallMI,
Vikram S. Adve6d1036d2002-09-28 16:59:05 +0000342 LiveRangeInfo& LRI) const
343{
Vikram S. Advee9327f02002-05-19 15:25:51 +0000344 CallArgsDescriptor* argDesc = CallArgsDescriptor::get(CallMI);
345 const Value *RetAddrVal = argDesc->getReturnAddrReg();
Vikram S. Adve6d1036d2002-09-28 16:59:05 +0000346 assert(RetAddrVal && "INTERNAL ERROR: Return address value is required");
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000347
Vikram S. Adve6d1036d2002-09-28 16:59:05 +0000348 // A LR must already exist for the return address.
349 LiveRange *RetAddrLR = LRI.getLiveRangeForValue(RetAddrVal);
350 assert(RetAddrLR && "INTERNAL ERROR: No LR for return address of call!");
351
Chris Lattnerf9fd5912003-01-15 21:14:32 +0000352 unsigned RegClassID = RetAddrLR->getRegClassID();
Brian Gaeke94e95d22004-02-25 18:44:15 +0000353 RetAddrLR->setColor(getUnifiedRegNum(IntRegClassID, SparcV9IntRegClass::o7));
Vikram S. Adve6d1036d2002-09-28 16:59:05 +0000354}
Ruchira Sasanka086bf0f2001-10-15 16:25:28 +0000355
356
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000357
358//---------------------------------------------------------------------------
359// This method will suggest colors to incoming args to a method.
Brian Gaeke94e95d22004-02-25 18:44:15 +0000360// According to the SparcV9 ABI, the first 6 incoming args are in
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000361// %i0 - %i5 (if they are integer) OR in %f0 - %f31 (if they are float).
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000362// If the arg is passed on stack due to the lack of regs, NOTHING will be
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000363// done - it will be colored (or spilled) as a normal live range.
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000364//---------------------------------------------------------------------------
Brian Gaeke94e95d22004-02-25 18:44:15 +0000365void SparcV9RegInfo::suggestRegs4MethodArgs(const Function *Meth,
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000366 LiveRangeInfo& LRI) const
Chris Lattnerb0ddffa2001-09-14 03:47:57 +0000367{
Vikram S. Adve536b1922003-07-25 21:12:15 +0000368 // Check if this is a varArgs function. needed for choosing regs.
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000369 bool isVarArgs = isVarArgsFunction(Meth->getType());
370
Vikram S. Adve536b1922003-07-25 21:12:15 +0000371 // Count the arguments, *ignoring* whether they are int or FP args.
372 // Use this common arg numbering to pick the right int or fp register.
373 unsigned argNo=0;
Chris Lattner7076ff22002-06-25 16:13:21 +0000374 for(Function::const_aiterator I = Meth->abegin(), E = Meth->aend();
375 I != E; ++I, ++argNo) {
Chris Lattner7076ff22002-06-25 16:13:21 +0000376 LiveRange *LR = LRI.getLiveRangeForValue(I);
377 assert(LR && "No live range found for method arg");
378
Vikram S. Adve536b1922003-07-25 21:12:15 +0000379 unsigned regType = getRegTypeForLR(LR);
380 unsigned regClassIDOfArgReg = BadRegClass; // for chosen reg (unused)
Chris Lattner7076ff22002-06-25 16:13:21 +0000381
382 int regNum = (regType == IntRegType)
Vikram S. Adve536b1922003-07-25 21:12:15 +0000383 ? regNumForIntArg(/*inCallee*/ true, isVarArgs, argNo, regClassIDOfArgReg)
384 : regNumForFPArg(regType, /*inCallee*/ true, isVarArgs, argNo,
385 regClassIDOfArgReg);
Chris Lattner7076ff22002-06-25 16:13:21 +0000386
Vikram S. Adve536b1922003-07-25 21:12:15 +0000387 if (regNum != getInvalidRegNum())
Chris Lattner7076ff22002-06-25 16:13:21 +0000388 LR->setSuggestedColor(regNum);
389 }
Chris Lattnerb0ddffa2001-09-14 03:47:57 +0000390}
391
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000392
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000393//---------------------------------------------------------------------------
394// This method is called after graph coloring to move incoming args to
395// the correct hardware registers if they did not receive the correct
396// (suggested) color through graph coloring.
397//---------------------------------------------------------------------------
Brian Gaeke94e95d22004-02-25 18:44:15 +0000398void SparcV9RegInfo::colorMethodArgs(const Function *Meth,
Vikram S. Adve23535842003-07-29 19:53:21 +0000399 LiveRangeInfo &LRI,
400 std::vector<MachineInstr*>& InstrnsBefore,
401 std::vector<MachineInstr*>& InstrnsAfter) const {
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000402
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000403 // check if this is a varArgs function. needed for choosing regs.
404 bool isVarArgs = isVarArgsFunction(Meth->getType());
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000405 MachineInstr *AdMI;
406
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000407 // for each argument
Chris Lattner7076ff22002-06-25 16:13:21 +0000408 // for each argument. count INT and FP arguments separately.
409 unsigned argNo=0, intArgNo=0, fpArgNo=0;
410 for(Function::const_aiterator I = Meth->abegin(), E = Meth->aend();
411 I != E; ++I, ++argNo) {
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000412 // get the LR of arg
Chris Lattner7076ff22002-06-25 16:13:21 +0000413 LiveRange *LR = LRI.getLiveRangeForValue(I);
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000414 assert( LR && "No live range found for method arg");
415
Vikram S. Adve536b1922003-07-25 21:12:15 +0000416 unsigned regType = getRegTypeForLR(LR);
Chris Lattnerf9fd5912003-01-15 21:14:32 +0000417 unsigned RegClassID = LR->getRegClassID();
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000418
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000419 // Find whether this argument is coming in a register (if not, on stack)
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000420 // Also find the correct register the argument must use (UniArgReg)
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000421 //
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000422 bool isArgInReg = false;
Vikram S. Advea83804a2003-05-31 07:32:01 +0000423 unsigned UniArgReg = getInvalidRegNum(); // reg that LR MUST be colored with
Chris Lattner24c1d5e2003-01-14 23:05:08 +0000424 unsigned regClassIDOfArgReg = BadRegClass; // reg class of chosen reg
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000425
426 int regNum = (regType == IntRegType)
Vikram S. Advee9327f02002-05-19 15:25:51 +0000427 ? regNumForIntArg(/*inCallee*/ true, isVarArgs,
Vikram S. Advea83804a2003-05-31 07:32:01 +0000428 argNo, regClassIDOfArgReg)
Vikram S. Advee9327f02002-05-19 15:25:51 +0000429 : regNumForFPArg(regType, /*inCallee*/ true, isVarArgs,
Vikram S. Advea83804a2003-05-31 07:32:01 +0000430 argNo, regClassIDOfArgReg);
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000431
Vikram S. Advea83804a2003-05-31 07:32:01 +0000432 if(regNum != getInvalidRegNum()) {
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000433 isArgInReg = true;
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000434 UniArgReg = getUnifiedRegNum( regClassIDOfArgReg, regNum);
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000435 }
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000436
Vikram S. Adve65280672003-07-10 19:42:11 +0000437 if( ! LR->isMarkedForSpill() ) { // if this arg received a register
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000438
Ruchira Sasanka36bcd792001-10-24 15:56:58 +0000439 unsigned UniLRReg = getUnifiedRegNum( RegClassID, LR->getColor() );
440
441 // if LR received the correct color, nothing to do
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000442 //
Ruchira Sasanka36bcd792001-10-24 15:56:58 +0000443 if( UniLRReg == UniArgReg )
444 continue;
445
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000446 // We are here because the LR did not receive the suggested
447 // but LR received another register.
448 // Now we have to copy the %i reg (or stack pos of arg)
449 // to the register the LR was colored with.
Ruchira Sasanka36bcd792001-10-24 15:56:58 +0000450
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000451 // if the arg is coming in UniArgReg register, it MUST go into
Ruchira Sasanka36bcd792001-10-24 15:56:58 +0000452 // the UniLRReg register
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000453 //
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000454 if( isArgInReg ) {
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000455 if( regClassIDOfArgReg != RegClassID ) {
Vikram S. Advee9327f02002-05-19 15:25:51 +0000456 assert(0 && "This could should work but it is not tested yet");
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000457
458 // It is a variable argument call: the float reg must go in a %o reg.
459 // We have to move an int reg to a float reg via memory.
460 //
461 assert(isVarArgs &&
462 RegClassID == FloatRegClassID &&
463 regClassIDOfArgReg == IntRegClassID &&
464 "This should only be an Int register for an FP argument");
465
Chris Lattnerd47aac92002-12-28 20:21:29 +0000466 int TmpOff = MachineFunction::get(Meth).getInfo()->pushTempValue(
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000467 getSpilledRegSize(regType));
Vikram S. Adve23535842003-07-29 19:53:21 +0000468 cpReg2MemMI(InstrnsBefore,
Vikram S. Adveaee67012002-07-08 23:23:12 +0000469 UniArgReg, getFramePointer(), TmpOff, IntRegType);
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000470
Vikram S. Adve23535842003-07-29 19:53:21 +0000471 cpMem2RegMI(InstrnsBefore,
Vikram S. Adveaee67012002-07-08 23:23:12 +0000472 getFramePointer(), TmpOff, UniLRReg, regType);
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000473 }
474 else {
Vikram S. Adve23535842003-07-29 19:53:21 +0000475 cpReg2RegMI(InstrnsBefore, UniArgReg, UniLRReg, regType);
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000476 }
477 }
Ruchira Sasanka9c38dbc2001-10-28 18:15:12 +0000478 else {
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000479
Misha Brukman8b2bd4e2003-10-10 17:57:28 +0000480 // Now the arg is coming on stack. Since the LR received a register,
Ruchira Sasanka9c38dbc2001-10-28 18:15:12 +0000481 // we just have to load the arg on stack into that register
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000482 //
Chris Lattnerd47aac92002-12-28 20:21:29 +0000483 const TargetFrameInfo& frameInfo = target.getFrameInfo();
Vikram S. Adve7a1524f2001-11-08 04:56:41 +0000484 int offsetFromFP =
Misha Brukman7ae7f842002-10-28 00:28:31 +0000485 frameInfo.getIncomingArgOffset(MachineFunction::get(Meth),
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000486 argNo);
Vikram S. Advea83804a2003-05-31 07:32:01 +0000487
488 // float arguments on stack are right justified so adjust the offset!
489 // int arguments are also right justified but they are always loaded as
490 // a full double-word so the offset does not need to be adjusted.
491 if (regType == FPSingleRegType) {
492 unsigned argSize = target.getTargetData().getTypeSize(LR->getType());
493 unsigned slotSize = frameInfo.getSizeOfEachArgOnStack();
494 assert(argSize <= slotSize && "Insufficient slot size!");
495 offsetFromFP += slotSize - argSize;
496 }
497
Vikram S. Adve23535842003-07-29 19:53:21 +0000498 cpMem2RegMI(InstrnsBefore,
Vikram S. Adveaee67012002-07-08 23:23:12 +0000499 getFramePointer(), offsetFromFP, UniLRReg, regType);
Ruchira Sasanka9c38dbc2001-10-28 18:15:12 +0000500 }
Ruchira Sasanka9c38dbc2001-10-28 18:15:12 +0000501
502 } // if LR received a color
503
504 else {
505
506 // Now, the LR did not receive a color. But it has a stack offset for
507 // spilling.
Ruchira Sasanka9c38dbc2001-10-28 18:15:12 +0000508 // So, if the arg is coming in UniArgReg register, we can just move
509 // that on to the stack pos of LR
510
Ruchira Sasanka9c38dbc2001-10-28 18:15:12 +0000511 if( isArgInReg ) {
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000512
513 if( regClassIDOfArgReg != RegClassID ) {
514 assert(0 &&
515 "FP arguments to a varargs function should be explicitly "
516 "copied to/from int registers by instruction selection!");
517
518 // It must be a float arg for a variable argument call, which
519 // must come in a %o reg. Move the int reg to the stack.
520 //
521 assert(isVarArgs && regClassIDOfArgReg == IntRegClassID &&
522 "This should only be an Int register for an FP argument");
523
Vikram S. Adve23535842003-07-29 19:53:21 +0000524 cpReg2MemMI(InstrnsBefore, UniArgReg,
Vikram S. Adveaee67012002-07-08 23:23:12 +0000525 getFramePointer(), LR->getSpillOffFromFP(), IntRegType);
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000526 }
527 else {
Vikram S. Adve23535842003-07-29 19:53:21 +0000528 cpReg2MemMI(InstrnsBefore, UniArgReg,
Vikram S. Adveaee67012002-07-08 23:23:12 +0000529 getFramePointer(), LR->getSpillOffFromFP(), regType);
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000530 }
Ruchira Sasanka9c38dbc2001-10-28 18:15:12 +0000531 }
532
533 else {
534
535 // Now the arg is coming on stack. Since the LR did NOT
Misha Brukman8b2bd4e2003-10-10 17:57:28 +0000536 // received a register as well, it is allocated a stack position. We
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000537 // can simply change the stack position of the LR. We can do this,
Ruchira Sasanka9c38dbc2001-10-28 18:15:12 +0000538 // since this method is called before any other method that makes
539 // uses of the stack pos of the LR (e.g., updateMachineInstr)
Vikram S. Advea83804a2003-05-31 07:32:01 +0000540 //
Chris Lattnerd47aac92002-12-28 20:21:29 +0000541 const TargetFrameInfo& frameInfo = target.getFrameInfo();
Vikram S. Adve7a1524f2001-11-08 04:56:41 +0000542 int offsetFromFP =
Misha Brukman7ae7f842002-10-28 00:28:31 +0000543 frameInfo.getIncomingArgOffset(MachineFunction::get(Meth),
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000544 argNo);
Vikram S. Advea83804a2003-05-31 07:32:01 +0000545
546 // FP arguments on stack are right justified so adjust offset!
547 // int arguments are also right justified but they are always loaded as
548 // a full double-word so the offset does not need to be adjusted.
549 if (regType == FPSingleRegType) {
550 unsigned argSize = target.getTargetData().getTypeSize(LR->getType());
551 unsigned slotSize = frameInfo.getSizeOfEachArgOnStack();
552 assert(argSize <= slotSize && "Insufficient slot size!");
553 offsetFromFP += slotSize - argSize;
554 }
Vikram S. Adve7a1524f2001-11-08 04:56:41 +0000555
556 LR->modifySpillOffFromFP( offsetFromFP );
Ruchira Sasanka9c38dbc2001-10-28 18:15:12 +0000557 }
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000558
559 }
560
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000561 } // for each incoming argument
562
563}
564
Chris Lattnerb0ddffa2001-09-14 03:47:57 +0000565
566
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000567//---------------------------------------------------------------------------
568// This method is called before graph coloring to suggest colors to the
569// outgoing call args and the return value of the call.
570//---------------------------------------------------------------------------
Brian Gaeke94e95d22004-02-25 18:44:15 +0000571void SparcV9RegInfo::suggestRegs4CallArgs(MachineInstr *CallMI,
Vikram S. Adve6d1036d2002-09-28 16:59:05 +0000572 LiveRangeInfo& LRI) const {
Brian Gaekeb22186a2004-02-11 20:47:34 +0000573 assert ( (target.getInstrInfo()).isCall(CallMI->getOpcode()) );
Chris Lattnerb0ddffa2001-09-14 03:47:57 +0000574
Vikram S. Advee9327f02002-05-19 15:25:51 +0000575 CallArgsDescriptor* argDesc = CallArgsDescriptor::get(CallMI);
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000576
Vikram S. Adve6d1036d2002-09-28 16:59:05 +0000577 suggestReg4CallAddr(CallMI, LRI);
Ruchira Sasanka086bf0f2001-10-15 16:25:28 +0000578
Vikram S. Adve6d1036d2002-09-28 16:59:05 +0000579 // First color the return value of the call instruction, if any.
580 // The return value will be in %o0 if the value is an integer type,
581 // or in %f0 if the value is a float type.
582 //
583 if (const Value *RetVal = argDesc->getReturnValue()) {
584 LiveRange *RetValLR = LRI.getLiveRangeForValue(RetVal);
585 assert(RetValLR && "No LR for return Value of call!");
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000586
Chris Lattnerf9fd5912003-01-15 21:14:32 +0000587 unsigned RegClassID = RetValLR->getRegClassID();
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000588
Ruchira Sasanka24729a32001-10-21 16:43:41 +0000589 // now suggest a register depending on the register class of ret arg
Ruchira Sasanka24729a32001-10-21 16:43:41 +0000590 if( RegClassID == IntRegClassID )
Brian Gaeke94e95d22004-02-25 18:44:15 +0000591 RetValLR->setSuggestedColor(SparcV9IntRegClass::o0);
Ruchira Sasanka24729a32001-10-21 16:43:41 +0000592 else if (RegClassID == FloatRegClassID )
Brian Gaeke94e95d22004-02-25 18:44:15 +0000593 RetValLR->setSuggestedColor(SparcV9FloatRegClass::f0 );
Ruchira Sasanka24729a32001-10-21 16:43:41 +0000594 else assert( 0 && "Unknown reg class for return value of call\n");
Chris Lattnerb0ddffa2001-09-14 03:47:57 +0000595 }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000596
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000597 // Now suggest colors for arguments (operands) of the call instruction.
598 // Colors are suggested only if the arg number is smaller than the
599 // the number of registers allocated for argument passing.
Ruchira Sasanka24729a32001-10-21 16:43:41 +0000600 // Now, go thru call args - implicit operands of the call MI
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000601
Vikram S. Advee9327f02002-05-19 15:25:51 +0000602 unsigned NumOfCallArgs = argDesc->getNumArgs();
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000603
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000604 for(unsigned argNo=0, i=0, intArgNo=0, fpArgNo=0;
605 i < NumOfCallArgs; ++i, ++argNo) {
Ruchira Sasanka086bf0f2001-10-15 16:25:28 +0000606
Vikram S. Advee9327f02002-05-19 15:25:51 +0000607 const Value *CallArg = argDesc->getArgInfo(i).getArgVal();
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000608
609 // get the LR of call operand (parameter)
Ruchira Sasanka086bf0f2001-10-15 16:25:28 +0000610 LiveRange *const LR = LRI.getLiveRangeForValue(CallArg);
Vikram S. Advea83804a2003-05-31 07:32:01 +0000611 if (!LR)
612 continue; // no live ranges for constants and labels
Vikram S. Adve6d1036d2002-09-28 16:59:05 +0000613
Vikram S. Adve536b1922003-07-25 21:12:15 +0000614 unsigned regType = getRegTypeForLR(LR);
Vikram S. Advea83804a2003-05-31 07:32:01 +0000615 unsigned regClassIDOfArgReg = BadRegClass; // chosen reg class (unused)
Vikram S. Adve6d1036d2002-09-28 16:59:05 +0000616
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000617 // Choose a register for this arg depending on whether it is
Vikram S. Advee9327f02002-05-19 15:25:51 +0000618 // an INT or FP value. Here we ignore whether or not it is a
619 // varargs calls, because FP arguments will be explicitly copied
620 // to an integer Value and handled under (argCopy != NULL) below.
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000621 int regNum = (regType == IntRegType)
Vikram S. Advee9327f02002-05-19 15:25:51 +0000622 ? regNumForIntArg(/*inCallee*/ false, /*isVarArgs*/ false,
Vikram S. Advea83804a2003-05-31 07:32:01 +0000623 argNo, regClassIDOfArgReg)
Vikram S. Advee9327f02002-05-19 15:25:51 +0000624 : regNumForFPArg(regType, /*inCallee*/ false, /*isVarArgs*/ false,
Vikram S. Advea83804a2003-05-31 07:32:01 +0000625 argNo, regClassIDOfArgReg);
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000626
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000627 // If a register could be allocated, use it.
628 // If not, do NOTHING as this will be colored as a normal value.
Vikram S. Advea83804a2003-05-31 07:32:01 +0000629 if(regNum != getInvalidRegNum())
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000630 LR->setSuggestedColor(regNum);
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000631 } // for all call arguments
Chris Lattnerb0ddffa2001-09-14 03:47:57 +0000632}
633
634
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000635//---------------------------------------------------------------------------
Anand Shuklae6c3ee62003-06-01 02:48:23 +0000636// this method is called for an LLVM return instruction to identify which
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000637// values will be returned from this method and to suggest colors.
638//---------------------------------------------------------------------------
Brian Gaeke94e95d22004-02-25 18:44:15 +0000639void SparcV9RegInfo::suggestReg4RetValue(MachineInstr *RetMI,
Vikram S. Adve23535842003-07-29 19:53:21 +0000640 LiveRangeInfo& LRI) const {
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000641
Brian Gaekeb22186a2004-02-11 20:47:34 +0000642 assert( (target.getInstrInfo()).isReturn( RetMI->getOpcode() ) );
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000643
Vikram S. Adveaee67012002-07-08 23:23:12 +0000644 suggestReg4RetAddr(RetMI, LRI);
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000645
Vikram S. Advea83804a2003-05-31 07:32:01 +0000646 // To find the return value (if any), we can get the LLVM return instr.
647 // from the return address register, which is the first operand
648 Value* tmpI = RetMI->getOperand(0).getVRegValue();
649 ReturnInst* retI=cast<ReturnInst>(cast<TmpInstruction>(tmpI)->getOperand(0));
650 if (const Value *RetVal = retI->getReturnValue())
651 if (LiveRange *const LR = LRI.getLiveRangeForValue(RetVal))
652 LR->setSuggestedColor(LR->getRegClassID() == IntRegClassID
Brian Gaeke94e95d22004-02-25 18:44:15 +0000653 ? (unsigned) SparcV9IntRegClass::i0
654 : (unsigned) SparcV9FloatRegClass::f0);
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000655}
656
Vikram S. Adveaee67012002-07-08 23:23:12 +0000657//---------------------------------------------------------------------------
658// Check if a specified register type needs a scratch register to be
659// copied to/from memory. If it does, the reg. type that must be used
660// for scratch registers is returned in scratchRegType.
661//
662// Only the int CC register needs such a scratch register.
663// The FP CC registers can (and must) be copied directly to/from memory.
664//---------------------------------------------------------------------------
665
666bool
Brian Gaeke94e95d22004-02-25 18:44:15 +0000667SparcV9RegInfo::regTypeNeedsScratchReg(int RegType,
Vikram S. Adveaee67012002-07-08 23:23:12 +0000668 int& scratchRegType) const
669{
670 if (RegType == IntCCRegType)
671 {
672 scratchRegType = IntRegType;
673 return true;
674 }
675 return false;
676}
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000677
678//---------------------------------------------------------------------------
679// Copy from a register to register. Register number must be the unified
Vikram S. Adveaee67012002-07-08 23:23:12 +0000680// register number.
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000681//---------------------------------------------------------------------------
682
Vikram S. Advee9327f02002-05-19 15:25:51 +0000683void
Brian Gaeke94e95d22004-02-25 18:44:15 +0000684SparcV9RegInfo::cpReg2RegMI(std::vector<MachineInstr*>& mvec,
Vikram S. Adveaee67012002-07-08 23:23:12 +0000685 unsigned SrcReg,
Vikram S. Advee9327f02002-05-19 15:25:51 +0000686 unsigned DestReg,
Vikram S. Adveaee67012002-07-08 23:23:12 +0000687 int RegType) const {
Misha Brukman2969ec52003-06-06 09:52:23 +0000688 assert( ((int)SrcReg != getInvalidRegNum()) &&
689 ((int)DestReg != getInvalidRegNum()) &&
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000690 "Invalid Register");
691
692 MachineInstr * MI = NULL;
Vikram S. Advee9327f02002-05-19 15:25:51 +0000693
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000694 switch( RegType ) {
695
Ruchira Sasanka5f629312001-10-18 22:38:52 +0000696 case IntCCRegType:
Misha Brukman56f4fa12003-05-20 20:32:24 +0000697 if (getRegType(DestReg) == IntRegType) {
698 // copy intCC reg to int reg
Vikram S. Adve65280672003-07-10 19:42:11 +0000699 MI = (BuildMI(V9::RDCCR, 2)
Brian Gaeke94e95d22004-02-25 18:44:15 +0000700 .addMReg(getUnifiedRegNum(SparcV9RegInfo::IntCCRegClassID,
701 SparcV9IntCCRegClass::ccr))
Alkis Evlogimenos8358cc52004-02-22 19:23:26 +0000702 .addMReg(DestReg,MachineOperand::Def));
Misha Brukman56f4fa12003-05-20 20:32:24 +0000703 } else {
704 // copy int reg to intCC reg
Misha Brukman56f4fa12003-05-20 20:32:24 +0000705 assert(getRegType(SrcReg) == IntRegType
706 && "Can only copy CC reg to/from integer reg");
Vikram S. Adve65280672003-07-10 19:42:11 +0000707 MI = (BuildMI(V9::WRCCRr, 3)
708 .addMReg(SrcReg)
Brian Gaeke94e95d22004-02-25 18:44:15 +0000709 .addMReg(SparcV9IntRegClass::g0)
710 .addMReg(getUnifiedRegNum(SparcV9RegInfo::IntCCRegClassID,
711 SparcV9IntCCRegClass::ccr),
Alkis Evlogimenos8358cc52004-02-22 19:23:26 +0000712 MachineOperand::Def));
Misha Brukman56f4fa12003-05-20 20:32:24 +0000713 }
Vikram S. Adveaee67012002-07-08 23:23:12 +0000714 break;
715
Ruchira Sasanka5f629312001-10-18 22:38:52 +0000716 case FloatCCRegType:
Vikram S. Adveaee67012002-07-08 23:23:12 +0000717 assert(0 && "Cannot copy FPCC register to any other register");
Vikram S. Advee9327f02002-05-19 15:25:51 +0000718 break;
719
720 case IntRegType:
Misha Brukmanaf96d392003-05-27 22:40:34 +0000721 MI = BuildMI(V9::ADDr, 3).addMReg(SrcReg).addMReg(getZeroRegNum())
Alkis Evlogimenos8358cc52004-02-22 19:23:26 +0000722 .addMReg(DestReg, MachineOperand::Def);
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000723 break;
Vikram S. Advee9327f02002-05-19 15:25:51 +0000724
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000725 case FPSingleRegType:
Alkis Evlogimenos8358cc52004-02-22 19:23:26 +0000726 MI = BuildMI(V9::FMOVS, 2).addMReg(SrcReg)
727 .addMReg(DestReg, MachineOperand::Def);
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000728 break;
729
730 case FPDoubleRegType:
Alkis Evlogimenos8358cc52004-02-22 19:23:26 +0000731 MI = BuildMI(V9::FMOVD, 2).addMReg(SrcReg)
732 .addMReg(DestReg, MachineOperand::Def);
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000733 break;
734
735 default:
Vikram S. Advee9327f02002-05-19 15:25:51 +0000736 assert(0 && "Unknown RegType");
Vikram S. Adveaee67012002-07-08 23:23:12 +0000737 break;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000738 }
Vikram S. Advee9327f02002-05-19 15:25:51 +0000739
740 if (MI)
741 mvec.push_back(MI);
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000742}
Chris Lattnerb0ddffa2001-09-14 03:47:57 +0000743
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000744//---------------------------------------------------------------------------
Ruchira Sasanka0863c162001-10-24 22:05:34 +0000745// Copy from a register to memory (i.e., Store). Register number must
746// be the unified register number
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000747//---------------------------------------------------------------------------
748
749
Vikram S. Advee9327f02002-05-19 15:25:51 +0000750void
Brian Gaeke94e95d22004-02-25 18:44:15 +0000751SparcV9RegInfo::cpReg2MemMI(std::vector<MachineInstr*>& mvec,
Vikram S. Adveaee67012002-07-08 23:23:12 +0000752 unsigned SrcReg,
Vikram S. Adve23535842003-07-29 19:53:21 +0000753 unsigned PtrReg,
Vikram S. Advee9327f02002-05-19 15:25:51 +0000754 int Offset, int RegType,
Chris Lattner3091e112002-07-25 06:08:32 +0000755 int scratchReg) const {
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000756 MachineInstr * MI = NULL;
Vikram S. Adve23535842003-07-29 19:53:21 +0000757 int OffReg = -1;
758
759 // If the Offset will not fit in the signed-immediate field, find an
760 // unused register to hold the offset value. This takes advantage of
761 // the fact that all the opcodes used below have the same size immed. field.
762 // Use the register allocator, PRA, to find an unused reg. at this MI.
763 //
764 if (RegType != IntCCRegType) // does not use offset below
765 if (! target.getInstrInfo().constantFitsInImmedField(V9::LDXi, Offset)) {
766#ifdef CAN_FIND_FREE_REGISTER_TRANSPARENTLY
767 RegClass* RC = PRA.getRegClassByID(this->getRegClassIDOfRegType(RegType));
768 OffReg = PRA.getUnusedUniRegAtMI(RC, RegType, MInst, LVSetBef);
769#else
Brian Gaekef8cb2412003-11-08 18:12:24 +0000770 // Default to using register g4 for holding large offsets
Brian Gaeke94e95d22004-02-25 18:44:15 +0000771 OffReg = getUnifiedRegNum(SparcV9RegInfo::IntRegClassID,
772 SparcV9IntRegClass::g4);
Vikram S. Adve23535842003-07-29 19:53:21 +0000773#endif
774 assert(OffReg >= 0 && "FIXME: cpReg2MemMI cannot find an unused reg.");
775 mvec.push_back(BuildMI(V9::SETSW, 2).addZImm(Offset).addReg(OffReg));
776 }
777
Chris Lattner1ebaa902003-01-15 17:47:49 +0000778 switch (RegType) {
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000779 case IntRegType:
Vikram S. Adve23535842003-07-29 19:53:21 +0000780 if (target.getInstrInfo().constantFitsInImmedField(V9::STXi, Offset))
781 MI = BuildMI(V9::STXi,3).addMReg(SrcReg).addMReg(PtrReg).addSImm(Offset);
782 else
783 MI = BuildMI(V9::STXr,3).addMReg(SrcReg).addMReg(PtrReg).addMReg(OffReg);
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000784 break;
785
786 case FPSingleRegType:
Vikram S. Adve23535842003-07-29 19:53:21 +0000787 if (target.getInstrInfo().constantFitsInImmedField(V9::STFi, Offset))
788 MI = BuildMI(V9::STFi, 3).addMReg(SrcReg).addMReg(PtrReg).addSImm(Offset);
789 else
790 MI = BuildMI(V9::STFr, 3).addMReg(SrcReg).addMReg(PtrReg).addMReg(OffReg);
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000791 break;
792
793 case FPDoubleRegType:
Vikram S. Adve23535842003-07-29 19:53:21 +0000794 if (target.getInstrInfo().constantFitsInImmedField(V9::STDFi, Offset))
795 MI = BuildMI(V9::STDFi,3).addMReg(SrcReg).addMReg(PtrReg).addSImm(Offset);
796 else
797 MI = BuildMI(V9::STDFr,3).addMReg(SrcReg).addMReg(PtrReg).addSImm(OffReg);
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000798 break;
799
Ruchira Sasanka9d8950d2001-11-03 19:59:59 +0000800 case IntCCRegType:
Vikram S. Adveaee67012002-07-08 23:23:12 +0000801 assert(scratchReg >= 0 && "Need scratch reg to store %ccr to memory");
Chris Lattner56e91662002-08-12 21:25:05 +0000802 assert(getRegType(scratchReg) ==IntRegType && "Invalid scratch reg");
Vikram S. Adve65280672003-07-10 19:42:11 +0000803 MI = (BuildMI(V9::RDCCR, 2)
Brian Gaeke94e95d22004-02-25 18:44:15 +0000804 .addMReg(getUnifiedRegNum(SparcV9RegInfo::IntCCRegClassID,
805 SparcV9IntCCRegClass::ccr))
Alkis Evlogimenos8358cc52004-02-22 19:23:26 +0000806 .addMReg(scratchReg, MachineOperand::Def));
Vikram S. Adveaee67012002-07-08 23:23:12 +0000807 mvec.push_back(MI);
808
Vikram S. Adve23535842003-07-29 19:53:21 +0000809 cpReg2MemMI(mvec, scratchReg, PtrReg, Offset, IntRegType);
Chris Lattner1ebaa902003-01-15 17:47:49 +0000810 return;
Vikram S. Adve23535842003-07-29 19:53:21 +0000811
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000812 case FloatCCRegType: {
Brian Gaeke94e95d22004-02-25 18:44:15 +0000813 unsigned fsrReg = getUnifiedRegNum(SparcV9RegInfo::SpecialRegClassID,
814 SparcV9SpecialRegClass::fsr);
Vikram S. Adve23535842003-07-29 19:53:21 +0000815 if (target.getInstrInfo().constantFitsInImmedField(V9::STXFSRi, Offset))
816 MI=BuildMI(V9::STXFSRi,3).addMReg(fsrReg).addMReg(PtrReg).addSImm(Offset);
817 else
818 MI=BuildMI(V9::STXFSRr,3).addMReg(fsrReg).addMReg(PtrReg).addMReg(OffReg);
Vikram S. Adveaee67012002-07-08 23:23:12 +0000819 break;
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000820 }
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000821 default:
Vikram S. Advee9327f02002-05-19 15:25:51 +0000822 assert(0 && "Unknown RegType in cpReg2MemMI");
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000823 }
Chris Lattner1ebaa902003-01-15 17:47:49 +0000824 mvec.push_back(MI);
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000825}
826
827
828//---------------------------------------------------------------------------
Ruchira Sasanka0863c162001-10-24 22:05:34 +0000829// Copy from memory to a reg (i.e., Load) Register number must be the unified
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000830// register number
831//---------------------------------------------------------------------------
832
833
Vikram S. Advee9327f02002-05-19 15:25:51 +0000834void
Brian Gaeke94e95d22004-02-25 18:44:15 +0000835SparcV9RegInfo::cpMem2RegMI(std::vector<MachineInstr*>& mvec,
Vikram S. Adve23535842003-07-29 19:53:21 +0000836 unsigned PtrReg,
Vikram S. Advee9327f02002-05-19 15:25:51 +0000837 int Offset,
838 unsigned DestReg,
839 int RegType,
Chris Lattner3091e112002-07-25 06:08:32 +0000840 int scratchReg) const {
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000841 MachineInstr * MI = NULL;
Vikram S. Adve23535842003-07-29 19:53:21 +0000842 int OffReg = -1;
843
844 // If the Offset will not fit in the signed-immediate field, find an
845 // unused register to hold the offset value. This takes advantage of
846 // the fact that all the opcodes used below have the same size immed. field.
847 // Use the register allocator, PRA, to find an unused reg. at this MI.
848 //
849 if (RegType != IntCCRegType) // does not use offset below
850 if (! target.getInstrInfo().constantFitsInImmedField(V9::LDXi, Offset)) {
851#ifdef CAN_FIND_FREE_REGISTER_TRANSPARENTLY
852 RegClass* RC = PRA.getRegClassByID(this->getRegClassIDOfRegType(RegType));
853 OffReg = PRA.getUnusedUniRegAtMI(RC, RegType, MInst, LVSetBef);
854#else
Brian Gaekef8cb2412003-11-08 18:12:24 +0000855 // Default to using register g4 for holding large offsets
Brian Gaeke94e95d22004-02-25 18:44:15 +0000856 OffReg = getUnifiedRegNum(SparcV9RegInfo::IntRegClassID,
857 SparcV9IntRegClass::g4);
Vikram S. Adve23535842003-07-29 19:53:21 +0000858#endif
859 assert(OffReg >= 0 && "FIXME: cpReg2MemMI cannot find an unused reg.");
860 mvec.push_back(BuildMI(V9::SETSW, 2).addZImm(Offset).addReg(OffReg));
861 }
862
Chris Lattner5216cc52002-02-04 05:59:25 +0000863 switch (RegType) {
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000864 case IntRegType:
Vikram S. Adve23535842003-07-29 19:53:21 +0000865 if (target.getInstrInfo().constantFitsInImmedField(V9::LDXi, Offset))
Alkis Evlogimenos8358cc52004-02-22 19:23:26 +0000866 MI = BuildMI(V9::LDXi, 3).addMReg(PtrReg).addSImm(Offset)
867 .addMReg(DestReg, MachineOperand::Def);
Vikram S. Adve23535842003-07-29 19:53:21 +0000868 else
Alkis Evlogimenos8358cc52004-02-22 19:23:26 +0000869 MI = BuildMI(V9::LDXr, 3).addMReg(PtrReg).addMReg(OffReg)
870 .addMReg(DestReg, MachineOperand::Def);
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000871 break;
872
873 case FPSingleRegType:
Vikram S. Adve23535842003-07-29 19:53:21 +0000874 if (target.getInstrInfo().constantFitsInImmedField(V9::LDFi, Offset))
Alkis Evlogimenos8358cc52004-02-22 19:23:26 +0000875 MI = BuildMI(V9::LDFi, 3).addMReg(PtrReg).addSImm(Offset)
876 .addMReg(DestReg, MachineOperand::Def);
Vikram S. Adve23535842003-07-29 19:53:21 +0000877 else
Alkis Evlogimenos8358cc52004-02-22 19:23:26 +0000878 MI = BuildMI(V9::LDFr, 3).addMReg(PtrReg).addMReg(OffReg)
879 .addMReg(DestReg, MachineOperand::Def);
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000880 break;
881
882 case FPDoubleRegType:
Vikram S. Adve23535842003-07-29 19:53:21 +0000883 if (target.getInstrInfo().constantFitsInImmedField(V9::LDDFi, Offset))
Alkis Evlogimenos8358cc52004-02-22 19:23:26 +0000884 MI= BuildMI(V9::LDDFi, 3).addMReg(PtrReg).addSImm(Offset)
885 .addMReg(DestReg, MachineOperand::Def);
Vikram S. Adve23535842003-07-29 19:53:21 +0000886 else
Alkis Evlogimenos8358cc52004-02-22 19:23:26 +0000887 MI= BuildMI(V9::LDDFr, 3).addMReg(PtrReg).addMReg(OffReg)
888 .addMReg(DestReg, MachineOperand::Def);
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000889 break;
890
Ruchira Sasanka9d8950d2001-11-03 19:59:59 +0000891 case IntCCRegType:
Vikram S. Adveaee67012002-07-08 23:23:12 +0000892 assert(scratchReg >= 0 && "Need scratch reg to load %ccr from memory");
Chris Lattner56e91662002-08-12 21:25:05 +0000893 assert(getRegType(scratchReg) ==IntRegType && "Invalid scratch reg");
Vikram S. Adve23535842003-07-29 19:53:21 +0000894 cpMem2RegMI(mvec, PtrReg, Offset, scratchReg, IntRegType);
Vikram S. Adve65280672003-07-10 19:42:11 +0000895 MI = (BuildMI(V9::WRCCRr, 3)
896 .addMReg(scratchReg)
Brian Gaeke94e95d22004-02-25 18:44:15 +0000897 .addMReg(SparcV9IntRegClass::g0)
898 .addMReg(getUnifiedRegNum(SparcV9RegInfo::IntCCRegClassID,
899 SparcV9IntCCRegClass::ccr), MachineOperand::Def));
Vikram S. Adveaee67012002-07-08 23:23:12 +0000900 break;
901
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000902 case FloatCCRegType: {
Brian Gaeke94e95d22004-02-25 18:44:15 +0000903 unsigned fsrRegNum = getUnifiedRegNum(SparcV9RegInfo::SpecialRegClassID,
904 SparcV9SpecialRegClass::fsr);
Vikram S. Adve23535842003-07-29 19:53:21 +0000905 if (target.getInstrInfo().constantFitsInImmedField(V9::LDXFSRi, Offset))
906 MI = BuildMI(V9::LDXFSRi, 3).addMReg(PtrReg).addSImm(Offset)
Alkis Evlogimenos8358cc52004-02-22 19:23:26 +0000907 .addMReg(fsrRegNum, MachineOperand::UseAndDef);
Vikram S. Adve23535842003-07-29 19:53:21 +0000908 else
909 MI = BuildMI(V9::LDXFSRr, 3).addMReg(PtrReg).addMReg(OffReg)
Alkis Evlogimenos8358cc52004-02-22 19:23:26 +0000910 .addMReg(fsrRegNum, MachineOperand::UseAndDef);
Vikram S. Adveaee67012002-07-08 23:23:12 +0000911 break;
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000912 }
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000913 default:
Ruchira Sasanka0c085982001-11-10 21:20:43 +0000914 assert(0 && "Unknown RegType in cpMem2RegMI");
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000915 }
Chris Lattner1ebaa902003-01-15 17:47:49 +0000916 mvec.push_back(MI);
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000917}
918
919
Ruchira Sasankafcdc2ff2001-11-12 14:45:33 +0000920//---------------------------------------------------------------------------
921// Generate a copy instruction to copy a value to another. Temporarily
922// used by PhiElimination code.
923//---------------------------------------------------------------------------
924
925
Vikram S. Advee9327f02002-05-19 15:25:51 +0000926void
Brian Gaeke94e95d22004-02-25 18:44:15 +0000927SparcV9RegInfo::cpValue2Value(Value *Src, Value *Dest,
Misha Brukman352f7ac2003-05-21 17:59:06 +0000928 std::vector<MachineInstr*>& mvec) const {
Vikram S. Adve536b1922003-07-25 21:12:15 +0000929 int RegType = getRegTypeForDataType(Src->getType());
Ruchira Sasankab7a39722001-11-03 17:13:27 +0000930 MachineInstr * MI = NULL;
931
Ruchira Sasankafcdc2ff2001-11-12 14:45:33 +0000932 switch( RegType ) {
Ruchira Sasankafcdc2ff2001-11-12 14:45:33 +0000933 case IntRegType:
Misha Brukmanaf96d392003-05-27 22:40:34 +0000934 MI = BuildMI(V9::ADDr, 3).addReg(Src).addMReg(getZeroRegNum())
Misha Brukman56f4fa12003-05-20 20:32:24 +0000935 .addRegDef(Dest);
Ruchira Sasankafcdc2ff2001-11-12 14:45:33 +0000936 break;
Ruchira Sasankafcdc2ff2001-11-12 14:45:33 +0000937 case FPSingleRegType:
Misha Brukman56f4fa12003-05-20 20:32:24 +0000938 MI = BuildMI(V9::FMOVS, 2).addReg(Src).addRegDef(Dest);
Ruchira Sasankafcdc2ff2001-11-12 14:45:33 +0000939 break;
Ruchira Sasankafcdc2ff2001-11-12 14:45:33 +0000940 case FPDoubleRegType:
Misha Brukman56f4fa12003-05-20 20:32:24 +0000941 MI = BuildMI(V9::FMOVD, 2).addReg(Src).addRegDef(Dest);
Ruchira Sasankafcdc2ff2001-11-12 14:45:33 +0000942 break;
Ruchira Sasankafcdc2ff2001-11-12 14:45:33 +0000943 default:
944 assert(0 && "Unknow RegType in CpValu2Value");
945 }
Ruchira Sasankab7a39722001-11-03 17:13:27 +0000946
Chris Lattner9bebf832002-10-28 20:10:56 +0000947 mvec.push_back(MI);
Ruchira Sasankab7a39722001-11-03 17:13:27 +0000948}
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000949
950
951
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000952//---------------------------------------------------------------------------
953// Print the register assigned to a LR
954//---------------------------------------------------------------------------
955
Brian Gaeke94e95d22004-02-25 18:44:15 +0000956void SparcV9RegInfo::printReg(const LiveRange *LR) const {
Chris Lattnerf9fd5912003-01-15 21:14:32 +0000957 unsigned RegClassID = LR->getRegClassID();
Chris Lattner69382172003-09-01 19:58:02 +0000958 std::cerr << " Node ";
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000959
Chris Lattner5216cc52002-02-04 05:59:25 +0000960 if (!LR->hasColor()) {
Misha Brukman352f7ac2003-05-21 17:59:06 +0000961 std::cerr << " - could not find a color\n";
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000962 return;
963 }
964
965 // if a color is found
966
Misha Brukman352f7ac2003-05-21 17:59:06 +0000967 std::cerr << " colored with color "<< LR->getColor();
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000968
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000969 unsigned uRegName = getUnifiedRegNum(RegClassID, LR->getColor());
970
971 std::cerr << "[";
972 std::cerr<< getUnifiedRegName(uRegName);
973 if (RegClassID == FloatRegClassID && LR->getType() == Type::DoubleTy)
974 std::cerr << "+" << getUnifiedRegName(uRegName+1);
975 std::cerr << "]\n";
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000976}
Brian Gaeke960707c2003-11-11 22:41:34 +0000977
978} // End llvm namespace