blob: 1c537030fc19b6db026552f4abd2697d2e951ece [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"
Chris Lattner38590312004-02-29 19:12:51 +000020#include "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
Chris Lattner56e91662002-08-12 21:25:05 +0000109static const char * const IntCCRegNames[] = {
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000110 "xcc", "icc", "ccr"
Chris Lattner56e91662002-08-12 21:25:05 +0000111};
112
Brian Gaeke94e95d22004-02-25 18:44:15 +0000113const char * const SparcV9IntCCRegClass::getRegName(unsigned reg) const {
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000114 assert(reg < 3);
Chris Lattner56e91662002-08-12 21:25:05 +0000115 return IntCCRegNames[reg];
116}
117
118static const char * const FloatCCRegNames[] = {
119 "fcc0", "fcc1", "fcc2", "fcc3"
120};
121
Brian Gaeke94e95d22004-02-25 18:44:15 +0000122const char * const SparcV9FloatCCRegClass::getRegName(unsigned reg) const {
Brian Gaeke2fd25362004-04-19 18:53:43 +0000123 assert (reg < 4);
Chris Lattner56e91662002-08-12 21:25:05 +0000124 return FloatCCRegNames[reg];
Chris Lattner5216cc52002-02-04 05:59:25 +0000125}
126
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000127static const char * const SpecialRegNames[] = {
128 "fsr"
129};
130
Brian Gaeke94e95d22004-02-25 18:44:15 +0000131const char * const SparcV9SpecialRegClass::getRegName(unsigned reg) const {
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000132 assert (reg < 1);
133 return SpecialRegNames[reg];
Chris Lattner5216cc52002-02-04 05:59:25 +0000134}
135
Vikram S. Advedb1435f2002-03-18 03:12:16 +0000136// Get unified reg number for frame pointer
Brian Gaeke94e95d22004-02-25 18:44:15 +0000137unsigned SparcV9RegInfo::getFramePointer() const {
138 return getUnifiedRegNum(SparcV9RegInfo::IntRegClassID,
139 SparcV9IntRegClass::i6);
Chris Lattner5216cc52002-02-04 05:59:25 +0000140}
141
Vikram S. Advedb1435f2002-03-18 03:12:16 +0000142// Get unified reg number for stack pointer
Brian Gaeke94e95d22004-02-25 18:44:15 +0000143unsigned SparcV9RegInfo::getStackPointer() const {
144 return getUnifiedRegNum(SparcV9RegInfo::IntRegClassID,
145 SparcV9IntRegClass::o6);
Chris Lattner5216cc52002-02-04 05:59:25 +0000146}
147
148
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000149//---------------------------------------------------------------------------
150// Finds whether a call is an indirect call
151//---------------------------------------------------------------------------
152
153inline bool
154isVarArgsFunction(const Type *funcType) {
155 return cast<FunctionType>(cast<PointerType>(funcType)
156 ->getElementType())->isVarArg();
157}
158
159inline bool
160isVarArgsCall(const MachineInstr *CallMI) {
161 Value* callee = CallMI->getOperand(0).getVRegValue();
162 // const Type* funcType = isa<Function>(callee)? callee->getType()
163 // : cast<PointerType>(callee->getType())->getElementType();
164 const Type* funcType = callee->getType();
165 return isVarArgsFunction(funcType);
166}
167
168
Vikram S. Advea83804a2003-05-31 07:32:01 +0000169// Get the register number for the specified argument #argNo,
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000170//
171// Return value:
Vikram S. Advea83804a2003-05-31 07:32:01 +0000172// getInvalidRegNum(), if there is no int register available for the arg.
173// regNum, otherwise (this is NOT the unified reg. num).
174// regClassId is set to the register class ID.
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000175//
Vikram S. Advea83804a2003-05-31 07:32:01 +0000176int
Brian Gaeke94e95d22004-02-25 18:44:15 +0000177SparcV9RegInfo::regNumForIntArg(bool inCallee, bool isVarArgsCall,
Vikram S. Advea83804a2003-05-31 07:32:01 +0000178 unsigned argNo, unsigned& regClassId) const
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000179{
Vikram S. Advee9327f02002-05-19 15:25:51 +0000180 regClassId = IntRegClassID;
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000181 if (argNo >= NumOfIntArgRegs)
Vikram S. Advea83804a2003-05-31 07:32:01 +0000182 return getInvalidRegNum();
Vikram S. Advee9327f02002-05-19 15:25:51 +0000183 else
Brian Gaeke94e95d22004-02-25 18:44:15 +0000184 return argNo + (inCallee? SparcV9IntRegClass::i0 : SparcV9IntRegClass::o0);
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000185}
186
Vikram S. Advea83804a2003-05-31 07:32:01 +0000187// Get the register number for the specified FP argument #argNo,
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000188// Use INT regs for FP args if this is a varargs call.
189//
190// Return value:
Vikram S. Advea83804a2003-05-31 07:32:01 +0000191// getInvalidRegNum(), if there is no int register available for the arg.
192// regNum, otherwise (this is NOT the unified reg. num).
193// regClassId is set to the register class ID.
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000194//
Vikram S. Advea83804a2003-05-31 07:32:01 +0000195int
Brian Gaeke94e95d22004-02-25 18:44:15 +0000196SparcV9RegInfo::regNumForFPArg(unsigned regType,
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000197 bool inCallee, bool isVarArgsCall,
Vikram S. Advea83804a2003-05-31 07:32:01 +0000198 unsigned argNo, unsigned& regClassId) const
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000199{
Vikram S. Advee9327f02002-05-19 15:25:51 +0000200 if (isVarArgsCall)
Vikram S. Advea83804a2003-05-31 07:32:01 +0000201 return regNumForIntArg(inCallee, isVarArgsCall, argNo, regClassId);
Vikram S. Advee9327f02002-05-19 15:25:51 +0000202 else
203 {
204 regClassId = FloatRegClassID;
205 if (regType == FPSingleRegType)
206 return (argNo*2+1 >= NumOfFloatArgRegs)?
Brian Gaeke94e95d22004-02-25 18:44:15 +0000207 getInvalidRegNum() : SparcV9FloatRegClass::f0 + (argNo * 2 + 1);
Vikram S. Advee9327f02002-05-19 15:25:51 +0000208 else if (regType == FPDoubleRegType)
209 return (argNo*2 >= NumOfFloatArgRegs)?
Brian Gaeke94e95d22004-02-25 18:44:15 +0000210 getInvalidRegNum() : SparcV9FloatRegClass::f0 + (argNo * 2);
Vikram S. Advee9327f02002-05-19 15:25:51 +0000211 else
212 assert(0 && "Illegal FP register type");
Chris Lattner3091e112002-07-25 06:08:32 +0000213 return 0;
Vikram S. Advee9327f02002-05-19 15:25:51 +0000214 }
Vikram S. Adve02662bd2002-03-31 19:04:50 +0000215}
216
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000217
218//---------------------------------------------------------------------------
219// Finds the return address of a call sparc specific call instruction
220//---------------------------------------------------------------------------
Ruchira Sasanka24729a32001-10-21 16:43:41 +0000221
Brian Gaeke94e95d22004-02-25 18:44:15 +0000222// The following 4 methods are used to find the RegType (SparcV9Internals.h)
Vikram S. Advee9327f02002-05-19 15:25:51 +0000223// of a LiveRange, a Value, and for a given register unified reg number.
Chris Lattner5216cc52002-02-04 05:59:25 +0000224//
Brian Gaeke94e95d22004-02-25 18:44:15 +0000225int SparcV9RegInfo::getRegTypeForClassAndType(unsigned regClassID,
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000226 const Type* type) const
227{
Vikram S. Advee9327f02002-05-19 15:25:51 +0000228 switch (regClassID) {
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000229 case IntRegClassID: return IntRegType;
230 case FloatRegClassID:
231 if (type == Type::FloatTy) return FPSingleRegType;
232 else if (type == Type::DoubleTy) return FPDoubleRegType;
233 assert(0 && "Unknown type in FloatRegClass"); return 0;
234 case IntCCRegClassID: return IntCCRegType;
235 case FloatCCRegClassID: return FloatCCRegType;
236 case SpecialRegClassID: return SpecialRegType;
Vikram S. Advee9327f02002-05-19 15:25:51 +0000237 default: assert( 0 && "Unknown reg class ID"); return 0;
Chris Lattner5216cc52002-02-04 05:59:25 +0000238 }
239}
240
Brian Gaeke94e95d22004-02-25 18:44:15 +0000241int SparcV9RegInfo::getRegTypeForDataType(const Type* type) const
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000242{
243 return getRegTypeForClassAndType(getRegClassIDOfType(type), type);
Vikram S. Advee9327f02002-05-19 15:25:51 +0000244}
245
Brian Gaeke94e95d22004-02-25 18:44:15 +0000246int SparcV9RegInfo::getRegTypeForLR(const LiveRange *LR) const
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000247{
248 return getRegTypeForClassAndType(LR->getRegClassID(), LR->getType());
249}
Chris Lattner5216cc52002-02-04 05:59:25 +0000250
Brian Gaeke94e95d22004-02-25 18:44:15 +0000251int SparcV9RegInfo::getRegType(int unifiedRegNum) const
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000252{
Vikram S. Adveaee67012002-07-08 23:23:12 +0000253 if (unifiedRegNum < 32)
Chris Lattner5216cc52002-02-04 05:59:25 +0000254 return IntRegType;
Vikram S. Adveaee67012002-07-08 23:23:12 +0000255 else if (unifiedRegNum < (32 + 32))
Chris Lattner5216cc52002-02-04 05:59:25 +0000256 return FPSingleRegType;
Vikram S. Adveaee67012002-07-08 23:23:12 +0000257 else if (unifiedRegNum < (64 + 32))
Chris Lattner5216cc52002-02-04 05:59:25 +0000258 return FPDoubleRegType;
Vikram S. Adveaee67012002-07-08 23:23:12 +0000259 else if (unifiedRegNum < (64+32+4))
Chris Lattner5216cc52002-02-04 05:59:25 +0000260 return FloatCCRegType;
Vikram S. Adveaee67012002-07-08 23:23:12 +0000261 else if (unifiedRegNum < (64+32+4+2))
Chris Lattner5216cc52002-02-04 05:59:25 +0000262 return IntCCRegType;
Brian Gaekea2f66db2004-04-20 20:12:57 +0000263 else if (unifiedRegNum < (64+32+4+2+1))
264 return SpecialRegType;
Chris Lattner5216cc52002-02-04 05:59:25 +0000265 else
Vikram S. Adveaee67012002-07-08 23:23:12 +0000266 assert(0 && "Invalid unified register number in getRegType");
Chris Lattner5536c9c2002-02-24 23:02:40 +0000267 return 0;
Chris Lattner5216cc52002-02-04 05:59:25 +0000268}
269
270
Vikram S. Adveaee67012002-07-08 23:23:12 +0000271// To find the register class used for a specified Type
272//
Brian Gaeke94e95d22004-02-25 18:44:15 +0000273unsigned SparcV9RegInfo::getRegClassIDOfType(const Type *type,
Chris Lattner3091e112002-07-25 06:08:32 +0000274 bool isCCReg) const {
Vikram S. Adveaee67012002-07-08 23:23:12 +0000275 Type::PrimitiveID ty = type->getPrimitiveID();
276 unsigned res;
277
278 // FIXME: Comparing types like this isn't very safe...
279 if ((ty && ty <= Type::LongTyID) || (ty == Type::LabelTyID) ||
280 (ty == Type::FunctionTyID) || (ty == Type::PointerTyID) )
281 res = IntRegClassID; // sparc int reg (ty=0: void)
282 else if (ty <= Type::DoubleTyID)
283 res = FloatRegClassID; // sparc float reg class
284 else {
285 //std::cerr << "TypeID: " << ty << "\n";
286 assert(0 && "Cannot resolve register class for type");
287 return 0;
288 }
289
Chris Lattnerf9fd5912003-01-15 21:14:32 +0000290 if (isCCReg)
291 return res + 2; // corresponding condition code register
Vikram S. Adveaee67012002-07-08 23:23:12 +0000292 else
293 return res;
294}
295
Brian Gaeke94e95d22004-02-25 18:44:15 +0000296unsigned SparcV9RegInfo::getRegClassIDOfRegType(int regType) const {
Vikram S. Adveaee67012002-07-08 23:23:12 +0000297 switch(regType) {
298 case IntRegType: return IntRegClassID;
299 case FPSingleRegType:
300 case FPDoubleRegType: return FloatRegClassID;
301 case IntCCRegType: return IntCCRegClassID;
302 case FloatCCRegType: return FloatCCRegClassID;
303 default:
304 assert(0 && "Invalid register type in getRegClassIDOfRegType");
305 return 0;
306 }
307}
308
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000309//---------------------------------------------------------------------------
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000310// Suggests a register for the ret address in the RET machine instruction.
311// We always suggest %i7 by convention.
312//---------------------------------------------------------------------------
Brian Gaeke94e95d22004-02-25 18:44:15 +0000313void SparcV9RegInfo::suggestReg4RetAddr(MachineInstr *RetMI,
Ruchira Sasanka086bf0f2001-10-15 16:25:28 +0000314 LiveRangeInfo& LRI) const {
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000315
Brian Gaekeb22186a2004-02-11 20:47:34 +0000316 assert(target.getInstrInfo().isReturn(RetMI->getOpcode()));
Vikram S. Adve84982772001-10-22 13:41:12 +0000317
Vikram S. Adveaee67012002-07-08 23:23:12 +0000318 // return address is always mapped to i7 so set it immediately
319 RetMI->SetRegForOperand(0, getUnifiedRegNum(IntRegClassID,
Brian Gaeke94e95d22004-02-25 18:44:15 +0000320 SparcV9IntRegClass::i7));
Vikram S. Adve84982772001-10-22 13:41:12 +0000321
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000322 // Possible Optimization:
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000323 // Instead of setting the color, we can suggest one. In that case,
Ruchira Sasanka086bf0f2001-10-15 16:25:28 +0000324 // we have to test later whether it received the suggested color.
325 // In that case, a LR has to be created at the start of method.
326 // It has to be done as follows (remove the setRegVal above):
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000327
Vikram S. Adveaee67012002-07-08 23:23:12 +0000328 // MachineOperand & MO = RetMI->getOperand(0);
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000329 // const Value *RetAddrVal = MO.getVRegValue();
330 // assert( RetAddrVal && "LR for ret address must be created at start");
331 // LiveRange * RetAddrLR = LRI.getLiveRangeForValue( RetAddrVal);
332 // RetAddrLR->setSuggestedColor(getUnifiedRegNum( IntRegClassID,
Brian Gaeke94e95d22004-02-25 18:44:15 +0000333 // SparcV9IntRegOrdr::i7) );
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000334}
335
336
337//---------------------------------------------------------------------------
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000338// Suggests a register for the ret address in the JMPL/CALL machine instr.
Brian Gaeke94e95d22004-02-25 18:44:15 +0000339// SparcV9 ABI dictates that %o7 be used for this purpose.
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000340//---------------------------------------------------------------------------
Vikram S. Adve6d1036d2002-09-28 16:59:05 +0000341void
Brian Gaeke94e95d22004-02-25 18:44:15 +0000342SparcV9RegInfo::suggestReg4CallAddr(MachineInstr * CallMI,
Vikram S. Adve6d1036d2002-09-28 16:59:05 +0000343 LiveRangeInfo& LRI) const
344{
Vikram S. Advee9327f02002-05-19 15:25:51 +0000345 CallArgsDescriptor* argDesc = CallArgsDescriptor::get(CallMI);
346 const Value *RetAddrVal = argDesc->getReturnAddrReg();
Vikram S. Adve6d1036d2002-09-28 16:59:05 +0000347 assert(RetAddrVal && "INTERNAL ERROR: Return address value is required");
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000348
Vikram S. Adve6d1036d2002-09-28 16:59:05 +0000349 // A LR must already exist for the return address.
350 LiveRange *RetAddrLR = LRI.getLiveRangeForValue(RetAddrVal);
351 assert(RetAddrLR && "INTERNAL ERROR: No LR for return address of call!");
352
Chris Lattnerf9fd5912003-01-15 21:14:32 +0000353 unsigned RegClassID = RetAddrLR->getRegClassID();
Brian Gaeke94e95d22004-02-25 18:44:15 +0000354 RetAddrLR->setColor(getUnifiedRegNum(IntRegClassID, SparcV9IntRegClass::o7));
Vikram S. Adve6d1036d2002-09-28 16:59:05 +0000355}
Ruchira Sasanka086bf0f2001-10-15 16:25:28 +0000356
357
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000358
359//---------------------------------------------------------------------------
360// This method will suggest colors to incoming args to a method.
Brian Gaeke94e95d22004-02-25 18:44:15 +0000361// According to the SparcV9 ABI, the first 6 incoming args are in
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000362// %i0 - %i5 (if they are integer) OR in %f0 - %f31 (if they are float).
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000363// If the arg is passed on stack due to the lack of regs, NOTHING will be
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000364// done - it will be colored (or spilled) as a normal live range.
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000365//---------------------------------------------------------------------------
Brian Gaeke94e95d22004-02-25 18:44:15 +0000366void SparcV9RegInfo::suggestRegs4MethodArgs(const Function *Meth,
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000367 LiveRangeInfo& LRI) const
Chris Lattnerb0ddffa2001-09-14 03:47:57 +0000368{
Vikram S. Adve536b1922003-07-25 21:12:15 +0000369 // Check if this is a varArgs function. needed for choosing regs.
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000370 bool isVarArgs = isVarArgsFunction(Meth->getType());
371
Vikram S. Adve536b1922003-07-25 21:12:15 +0000372 // Count the arguments, *ignoring* whether they are int or FP args.
373 // Use this common arg numbering to pick the right int or fp register.
374 unsigned argNo=0;
Chris Lattner7076ff22002-06-25 16:13:21 +0000375 for(Function::const_aiterator I = Meth->abegin(), E = Meth->aend();
376 I != E; ++I, ++argNo) {
Chris Lattner7076ff22002-06-25 16:13:21 +0000377 LiveRange *LR = LRI.getLiveRangeForValue(I);
378 assert(LR && "No live range found for method arg");
379
Vikram S. Adve536b1922003-07-25 21:12:15 +0000380 unsigned regType = getRegTypeForLR(LR);
381 unsigned regClassIDOfArgReg = BadRegClass; // for chosen reg (unused)
Chris Lattner7076ff22002-06-25 16:13:21 +0000382
383 int regNum = (regType == IntRegType)
Vikram S. Adve536b1922003-07-25 21:12:15 +0000384 ? regNumForIntArg(/*inCallee*/ true, isVarArgs, argNo, regClassIDOfArgReg)
385 : regNumForFPArg(regType, /*inCallee*/ true, isVarArgs, argNo,
386 regClassIDOfArgReg);
Chris Lattner7076ff22002-06-25 16:13:21 +0000387
Vikram S. Adve536b1922003-07-25 21:12:15 +0000388 if (regNum != getInvalidRegNum())
Chris Lattner7076ff22002-06-25 16:13:21 +0000389 LR->setSuggestedColor(regNum);
390 }
Chris Lattnerb0ddffa2001-09-14 03:47:57 +0000391}
392
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000393
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000394//---------------------------------------------------------------------------
395// This method is called after graph coloring to move incoming args to
396// the correct hardware registers if they did not receive the correct
397// (suggested) color through graph coloring.
398//---------------------------------------------------------------------------
Brian Gaeke94e95d22004-02-25 18:44:15 +0000399void SparcV9RegInfo::colorMethodArgs(const Function *Meth,
Vikram S. Adve23535842003-07-29 19:53:21 +0000400 LiveRangeInfo &LRI,
401 std::vector<MachineInstr*>& InstrnsBefore,
402 std::vector<MachineInstr*>& InstrnsAfter) const {
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000403
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000404 // check if this is a varArgs function. needed for choosing regs.
405 bool isVarArgs = isVarArgsFunction(Meth->getType());
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000406 MachineInstr *AdMI;
407
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000408 // for each argument
Chris Lattner7076ff22002-06-25 16:13:21 +0000409 // for each argument. count INT and FP arguments separately.
410 unsigned argNo=0, intArgNo=0, fpArgNo=0;
411 for(Function::const_aiterator I = Meth->abegin(), E = Meth->aend();
412 I != E; ++I, ++argNo) {
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000413 // get the LR of arg
Chris Lattner7076ff22002-06-25 16:13:21 +0000414 LiveRange *LR = LRI.getLiveRangeForValue(I);
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000415 assert( LR && "No live range found for method arg");
416
Vikram S. Adve536b1922003-07-25 21:12:15 +0000417 unsigned regType = getRegTypeForLR(LR);
Chris Lattnerf9fd5912003-01-15 21:14:32 +0000418 unsigned RegClassID = LR->getRegClassID();
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000419
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000420 // Find whether this argument is coming in a register (if not, on stack)
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000421 // Also find the correct register the argument must use (UniArgReg)
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000422 //
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000423 bool isArgInReg = false;
Vikram S. Advea83804a2003-05-31 07:32:01 +0000424 unsigned UniArgReg = getInvalidRegNum(); // reg that LR MUST be colored with
Chris Lattner24c1d5e2003-01-14 23:05:08 +0000425 unsigned regClassIDOfArgReg = BadRegClass; // reg class of chosen reg
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000426
427 int regNum = (regType == IntRegType)
Vikram S. Advee9327f02002-05-19 15:25:51 +0000428 ? regNumForIntArg(/*inCallee*/ true, isVarArgs,
Vikram S. Advea83804a2003-05-31 07:32:01 +0000429 argNo, regClassIDOfArgReg)
Vikram S. Advee9327f02002-05-19 15:25:51 +0000430 : regNumForFPArg(regType, /*inCallee*/ true, isVarArgs,
Vikram S. Advea83804a2003-05-31 07:32:01 +0000431 argNo, regClassIDOfArgReg);
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000432
Vikram S. Advea83804a2003-05-31 07:32:01 +0000433 if(regNum != getInvalidRegNum()) {
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000434 isArgInReg = true;
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000435 UniArgReg = getUnifiedRegNum( regClassIDOfArgReg, regNum);
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000436 }
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000437
Vikram S. Adve65280672003-07-10 19:42:11 +0000438 if( ! LR->isMarkedForSpill() ) { // if this arg received a register
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000439
Ruchira Sasanka36bcd792001-10-24 15:56:58 +0000440 unsigned UniLRReg = getUnifiedRegNum( RegClassID, LR->getColor() );
441
442 // if LR received the correct color, nothing to do
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000443 //
Ruchira Sasanka36bcd792001-10-24 15:56:58 +0000444 if( UniLRReg == UniArgReg )
445 continue;
446
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000447 // We are here because the LR did not receive the suggested
448 // but LR received another register.
449 // Now we have to copy the %i reg (or stack pos of arg)
450 // to the register the LR was colored with.
Ruchira Sasanka36bcd792001-10-24 15:56:58 +0000451
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000452 // if the arg is coming in UniArgReg register, it MUST go into
Ruchira Sasanka36bcd792001-10-24 15:56:58 +0000453 // the UniLRReg register
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000454 //
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000455 if( isArgInReg ) {
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000456 if( regClassIDOfArgReg != RegClassID ) {
Vikram S. Advee9327f02002-05-19 15:25:51 +0000457 assert(0 && "This could should work but it is not tested yet");
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000458
459 // It is a variable argument call: the float reg must go in a %o reg.
460 // We have to move an int reg to a float reg via memory.
461 //
462 assert(isVarArgs &&
463 RegClassID == FloatRegClassID &&
464 regClassIDOfArgReg == IntRegClassID &&
465 "This should only be an Int register for an FP argument");
466
Chris Lattnerd47aac92002-12-28 20:21:29 +0000467 int TmpOff = MachineFunction::get(Meth).getInfo()->pushTempValue(
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000468 getSpilledRegSize(regType));
Vikram S. Adve23535842003-07-29 19:53:21 +0000469 cpReg2MemMI(InstrnsBefore,
Vikram S. Adveaee67012002-07-08 23:23:12 +0000470 UniArgReg, getFramePointer(), TmpOff, IntRegType);
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000471
Vikram S. Adve23535842003-07-29 19:53:21 +0000472 cpMem2RegMI(InstrnsBefore,
Vikram S. Adveaee67012002-07-08 23:23:12 +0000473 getFramePointer(), TmpOff, UniLRReg, regType);
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000474 }
475 else {
Vikram S. Adve23535842003-07-29 19:53:21 +0000476 cpReg2RegMI(InstrnsBefore, UniArgReg, UniLRReg, regType);
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000477 }
478 }
Ruchira Sasanka9c38dbc2001-10-28 18:15:12 +0000479 else {
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000480
Misha Brukman8b2bd4e2003-10-10 17:57:28 +0000481 // Now the arg is coming on stack. Since the LR received a register,
Ruchira Sasanka9c38dbc2001-10-28 18:15:12 +0000482 // we just have to load the arg on stack into that register
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000483 //
Chris Lattnerd47aac92002-12-28 20:21:29 +0000484 const TargetFrameInfo& frameInfo = target.getFrameInfo();
Vikram S. Adve7a1524f2001-11-08 04:56:41 +0000485 int offsetFromFP =
Misha Brukman7ae7f842002-10-28 00:28:31 +0000486 frameInfo.getIncomingArgOffset(MachineFunction::get(Meth),
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000487 argNo);
Vikram S. Advea83804a2003-05-31 07:32:01 +0000488
489 // float arguments on stack are right justified so adjust the offset!
490 // int arguments are also right justified but they are always loaded as
491 // a full double-word so the offset does not need to be adjusted.
492 if (regType == FPSingleRegType) {
493 unsigned argSize = target.getTargetData().getTypeSize(LR->getType());
494 unsigned slotSize = frameInfo.getSizeOfEachArgOnStack();
495 assert(argSize <= slotSize && "Insufficient slot size!");
496 offsetFromFP += slotSize - argSize;
497 }
498
Vikram S. Adve23535842003-07-29 19:53:21 +0000499 cpMem2RegMI(InstrnsBefore,
Vikram S. Adveaee67012002-07-08 23:23:12 +0000500 getFramePointer(), offsetFromFP, UniLRReg, regType);
Ruchira Sasanka9c38dbc2001-10-28 18:15:12 +0000501 }
Ruchira Sasanka9c38dbc2001-10-28 18:15:12 +0000502
503 } // if LR received a color
504
505 else {
506
507 // Now, the LR did not receive a color. But it has a stack offset for
508 // spilling.
Ruchira Sasanka9c38dbc2001-10-28 18:15:12 +0000509 // So, if the arg is coming in UniArgReg register, we can just move
510 // that on to the stack pos of LR
511
Ruchira Sasanka9c38dbc2001-10-28 18:15:12 +0000512 if( isArgInReg ) {
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000513
514 if( regClassIDOfArgReg != RegClassID ) {
515 assert(0 &&
516 "FP arguments to a varargs function should be explicitly "
517 "copied to/from int registers by instruction selection!");
518
519 // It must be a float arg for a variable argument call, which
520 // must come in a %o reg. Move the int reg to the stack.
521 //
522 assert(isVarArgs && regClassIDOfArgReg == IntRegClassID &&
523 "This should only be an Int register for an FP argument");
524
Vikram S. Adve23535842003-07-29 19:53:21 +0000525 cpReg2MemMI(InstrnsBefore, UniArgReg,
Vikram S. Adveaee67012002-07-08 23:23:12 +0000526 getFramePointer(), LR->getSpillOffFromFP(), IntRegType);
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000527 }
528 else {
Vikram S. Adve23535842003-07-29 19:53:21 +0000529 cpReg2MemMI(InstrnsBefore, UniArgReg,
Vikram S. Adveaee67012002-07-08 23:23:12 +0000530 getFramePointer(), LR->getSpillOffFromFP(), regType);
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000531 }
Ruchira Sasanka9c38dbc2001-10-28 18:15:12 +0000532 }
533
534 else {
535
536 // Now the arg is coming on stack. Since the LR did NOT
Misha Brukman8b2bd4e2003-10-10 17:57:28 +0000537 // received a register as well, it is allocated a stack position. We
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000538 // can simply change the stack position of the LR. We can do this,
Ruchira Sasanka9c38dbc2001-10-28 18:15:12 +0000539 // since this method is called before any other method that makes
540 // uses of the stack pos of the LR (e.g., updateMachineInstr)
Vikram S. Advea83804a2003-05-31 07:32:01 +0000541 //
Chris Lattnerd47aac92002-12-28 20:21:29 +0000542 const TargetFrameInfo& frameInfo = target.getFrameInfo();
Vikram S. Adve7a1524f2001-11-08 04:56:41 +0000543 int offsetFromFP =
Misha Brukman7ae7f842002-10-28 00:28:31 +0000544 frameInfo.getIncomingArgOffset(MachineFunction::get(Meth),
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000545 argNo);
Vikram S. Advea83804a2003-05-31 07:32:01 +0000546
547 // FP arguments on stack are right justified so adjust offset!
548 // int arguments are also right justified but they are always loaded as
549 // a full double-word so the offset does not need to be adjusted.
550 if (regType == FPSingleRegType) {
551 unsigned argSize = target.getTargetData().getTypeSize(LR->getType());
552 unsigned slotSize = frameInfo.getSizeOfEachArgOnStack();
553 assert(argSize <= slotSize && "Insufficient slot size!");
554 offsetFromFP += slotSize - argSize;
555 }
Vikram S. Adve7a1524f2001-11-08 04:56:41 +0000556
557 LR->modifySpillOffFromFP( offsetFromFP );
Ruchira Sasanka9c38dbc2001-10-28 18:15:12 +0000558 }
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000559
560 }
561
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000562 } // for each incoming argument
563
564}
565
Chris Lattnerb0ddffa2001-09-14 03:47:57 +0000566
567
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000568//---------------------------------------------------------------------------
569// This method is called before graph coloring to suggest colors to the
570// outgoing call args and the return value of the call.
571//---------------------------------------------------------------------------
Brian Gaeke94e95d22004-02-25 18:44:15 +0000572void SparcV9RegInfo::suggestRegs4CallArgs(MachineInstr *CallMI,
Vikram S. Adve6d1036d2002-09-28 16:59:05 +0000573 LiveRangeInfo& LRI) const {
Brian Gaekeb22186a2004-02-11 20:47:34 +0000574 assert ( (target.getInstrInfo()).isCall(CallMI->getOpcode()) );
Chris Lattnerb0ddffa2001-09-14 03:47:57 +0000575
Vikram S. Advee9327f02002-05-19 15:25:51 +0000576 CallArgsDescriptor* argDesc = CallArgsDescriptor::get(CallMI);
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000577
Vikram S. Adve6d1036d2002-09-28 16:59:05 +0000578 suggestReg4CallAddr(CallMI, LRI);
Ruchira Sasanka086bf0f2001-10-15 16:25:28 +0000579
Vikram S. Adve6d1036d2002-09-28 16:59:05 +0000580 // First color the return value of the call instruction, if any.
581 // The return value will be in %o0 if the value is an integer type,
582 // or in %f0 if the value is a float type.
583 //
584 if (const Value *RetVal = argDesc->getReturnValue()) {
585 LiveRange *RetValLR = LRI.getLiveRangeForValue(RetVal);
586 assert(RetValLR && "No LR for return Value of call!");
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000587
Chris Lattnerf9fd5912003-01-15 21:14:32 +0000588 unsigned RegClassID = RetValLR->getRegClassID();
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000589
Ruchira Sasanka24729a32001-10-21 16:43:41 +0000590 // now suggest a register depending on the register class of ret arg
Ruchira Sasanka24729a32001-10-21 16:43:41 +0000591 if( RegClassID == IntRegClassID )
Brian Gaeke94e95d22004-02-25 18:44:15 +0000592 RetValLR->setSuggestedColor(SparcV9IntRegClass::o0);
Ruchira Sasanka24729a32001-10-21 16:43:41 +0000593 else if (RegClassID == FloatRegClassID )
Brian Gaeke94e95d22004-02-25 18:44:15 +0000594 RetValLR->setSuggestedColor(SparcV9FloatRegClass::f0 );
Ruchira Sasanka24729a32001-10-21 16:43:41 +0000595 else assert( 0 && "Unknown reg class for return value of call\n");
Chris Lattnerb0ddffa2001-09-14 03:47:57 +0000596 }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000597
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000598 // Now suggest colors for arguments (operands) of the call instruction.
599 // Colors are suggested only if the arg number is smaller than the
600 // the number of registers allocated for argument passing.
Ruchira Sasanka24729a32001-10-21 16:43:41 +0000601 // Now, go thru call args - implicit operands of the call MI
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000602
Vikram S. Advee9327f02002-05-19 15:25:51 +0000603 unsigned NumOfCallArgs = argDesc->getNumArgs();
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000604
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000605 for(unsigned argNo=0, i=0, intArgNo=0, fpArgNo=0;
606 i < NumOfCallArgs; ++i, ++argNo) {
Ruchira Sasanka086bf0f2001-10-15 16:25:28 +0000607
Vikram S. Advee9327f02002-05-19 15:25:51 +0000608 const Value *CallArg = argDesc->getArgInfo(i).getArgVal();
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000609
610 // get the LR of call operand (parameter)
Ruchira Sasanka086bf0f2001-10-15 16:25:28 +0000611 LiveRange *const LR = LRI.getLiveRangeForValue(CallArg);
Vikram S. Advea83804a2003-05-31 07:32:01 +0000612 if (!LR)
613 continue; // no live ranges for constants and labels
Vikram S. Adve6d1036d2002-09-28 16:59:05 +0000614
Vikram S. Adve536b1922003-07-25 21:12:15 +0000615 unsigned regType = getRegTypeForLR(LR);
Vikram S. Advea83804a2003-05-31 07:32:01 +0000616 unsigned regClassIDOfArgReg = BadRegClass; // chosen reg class (unused)
Vikram S. Adve6d1036d2002-09-28 16:59:05 +0000617
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000618 // Choose a register for this arg depending on whether it is
Vikram S. Advee9327f02002-05-19 15:25:51 +0000619 // an INT or FP value. Here we ignore whether or not it is a
620 // varargs calls, because FP arguments will be explicitly copied
621 // to an integer Value and handled under (argCopy != NULL) below.
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000622 int regNum = (regType == IntRegType)
Vikram S. Advee9327f02002-05-19 15:25:51 +0000623 ? regNumForIntArg(/*inCallee*/ false, /*isVarArgs*/ false,
Vikram S. Advea83804a2003-05-31 07:32:01 +0000624 argNo, regClassIDOfArgReg)
Vikram S. Advee9327f02002-05-19 15:25:51 +0000625 : regNumForFPArg(regType, /*inCallee*/ false, /*isVarArgs*/ false,
Vikram S. Advea83804a2003-05-31 07:32:01 +0000626 argNo, regClassIDOfArgReg);
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000627
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000628 // If a register could be allocated, use it.
629 // If not, do NOTHING as this will be colored as a normal value.
Vikram S. Advea83804a2003-05-31 07:32:01 +0000630 if(regNum != getInvalidRegNum())
Vikram S. Advea6d94c92002-04-25 04:42:21 +0000631 LR->setSuggestedColor(regNum);
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000632 } // for all call arguments
Chris Lattnerb0ddffa2001-09-14 03:47:57 +0000633}
634
635
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000636//---------------------------------------------------------------------------
Anand Shuklae6c3ee62003-06-01 02:48:23 +0000637// this method is called for an LLVM return instruction to identify which
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000638// values will be returned from this method and to suggest colors.
639//---------------------------------------------------------------------------
Brian Gaeke94e95d22004-02-25 18:44:15 +0000640void SparcV9RegInfo::suggestReg4RetValue(MachineInstr *RetMI,
Vikram S. Adve23535842003-07-29 19:53:21 +0000641 LiveRangeInfo& LRI) const {
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000642
Brian Gaekeb22186a2004-02-11 20:47:34 +0000643 assert( (target.getInstrInfo()).isReturn( RetMI->getOpcode() ) );
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000644
Vikram S. Adveaee67012002-07-08 23:23:12 +0000645 suggestReg4RetAddr(RetMI, LRI);
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000646
Vikram S. Advea83804a2003-05-31 07:32:01 +0000647 // To find the return value (if any), we can get the LLVM return instr.
648 // from the return address register, which is the first operand
649 Value* tmpI = RetMI->getOperand(0).getVRegValue();
650 ReturnInst* retI=cast<ReturnInst>(cast<TmpInstruction>(tmpI)->getOperand(0));
651 if (const Value *RetVal = retI->getReturnValue())
652 if (LiveRange *const LR = LRI.getLiveRangeForValue(RetVal))
653 LR->setSuggestedColor(LR->getRegClassID() == IntRegClassID
Brian Gaeke94e95d22004-02-25 18:44:15 +0000654 ? (unsigned) SparcV9IntRegClass::i0
655 : (unsigned) SparcV9FloatRegClass::f0);
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000656}
657
Vikram S. Adveaee67012002-07-08 23:23:12 +0000658//---------------------------------------------------------------------------
659// Check if a specified register type needs a scratch register to be
660// copied to/from memory. If it does, the reg. type that must be used
661// for scratch registers is returned in scratchRegType.
662//
663// Only the int CC register needs such a scratch register.
664// The FP CC registers can (and must) be copied directly to/from memory.
665//---------------------------------------------------------------------------
666
667bool
Brian Gaeke94e95d22004-02-25 18:44:15 +0000668SparcV9RegInfo::regTypeNeedsScratchReg(int RegType,
Vikram S. Adveaee67012002-07-08 23:23:12 +0000669 int& scratchRegType) const
670{
671 if (RegType == IntCCRegType)
672 {
673 scratchRegType = IntRegType;
674 return true;
675 }
676 return false;
677}
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000678
679//---------------------------------------------------------------------------
680// Copy from a register to register. Register number must be the unified
Vikram S. Adveaee67012002-07-08 23:23:12 +0000681// register number.
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000682//---------------------------------------------------------------------------
683
Vikram S. Advee9327f02002-05-19 15:25:51 +0000684void
Brian Gaeke94e95d22004-02-25 18:44:15 +0000685SparcV9RegInfo::cpReg2RegMI(std::vector<MachineInstr*>& mvec,
Vikram S. Adveaee67012002-07-08 23:23:12 +0000686 unsigned SrcReg,
Vikram S. Advee9327f02002-05-19 15:25:51 +0000687 unsigned DestReg,
Vikram S. Adveaee67012002-07-08 23:23:12 +0000688 int RegType) const {
Misha Brukman2969ec52003-06-06 09:52:23 +0000689 assert( ((int)SrcReg != getInvalidRegNum()) &&
690 ((int)DestReg != getInvalidRegNum()) &&
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000691 "Invalid Register");
692
693 MachineInstr * MI = NULL;
Vikram S. Advee9327f02002-05-19 15:25:51 +0000694
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000695 switch( RegType ) {
696
Ruchira Sasanka5f629312001-10-18 22:38:52 +0000697 case IntCCRegType:
Misha Brukman56f4fa12003-05-20 20:32:24 +0000698 if (getRegType(DestReg) == IntRegType) {
699 // copy intCC reg to int reg
Vikram S. Adve65280672003-07-10 19:42:11 +0000700 MI = (BuildMI(V9::RDCCR, 2)
Brian Gaeke94e95d22004-02-25 18:44:15 +0000701 .addMReg(getUnifiedRegNum(SparcV9RegInfo::IntCCRegClassID,
702 SparcV9IntCCRegClass::ccr))
Alkis Evlogimenos8358cc52004-02-22 19:23:26 +0000703 .addMReg(DestReg,MachineOperand::Def));
Misha Brukman56f4fa12003-05-20 20:32:24 +0000704 } else {
705 // copy int reg to intCC reg
Misha Brukman56f4fa12003-05-20 20:32:24 +0000706 assert(getRegType(SrcReg) == IntRegType
707 && "Can only copy CC reg to/from integer reg");
Vikram S. Adve65280672003-07-10 19:42:11 +0000708 MI = (BuildMI(V9::WRCCRr, 3)
709 .addMReg(SrcReg)
Brian Gaeke94e95d22004-02-25 18:44:15 +0000710 .addMReg(SparcV9IntRegClass::g0)
711 .addMReg(getUnifiedRegNum(SparcV9RegInfo::IntCCRegClassID,
712 SparcV9IntCCRegClass::ccr),
Alkis Evlogimenos8358cc52004-02-22 19:23:26 +0000713 MachineOperand::Def));
Misha Brukman56f4fa12003-05-20 20:32:24 +0000714 }
Vikram S. Adveaee67012002-07-08 23:23:12 +0000715 break;
716
Ruchira Sasanka5f629312001-10-18 22:38:52 +0000717 case FloatCCRegType:
Vikram S. Adveaee67012002-07-08 23:23:12 +0000718 assert(0 && "Cannot copy FPCC register to any other register");
Vikram S. Advee9327f02002-05-19 15:25:51 +0000719 break;
720
721 case IntRegType:
Misha Brukmanaf96d392003-05-27 22:40:34 +0000722 MI = BuildMI(V9::ADDr, 3).addMReg(SrcReg).addMReg(getZeroRegNum())
Alkis Evlogimenos8358cc52004-02-22 19:23:26 +0000723 .addMReg(DestReg, MachineOperand::Def);
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000724 break;
Vikram S. Advee9327f02002-05-19 15:25:51 +0000725
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000726 case FPSingleRegType:
Alkis Evlogimenos8358cc52004-02-22 19:23:26 +0000727 MI = BuildMI(V9::FMOVS, 2).addMReg(SrcReg)
728 .addMReg(DestReg, MachineOperand::Def);
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000729 break;
730
731 case FPDoubleRegType:
Alkis Evlogimenos8358cc52004-02-22 19:23:26 +0000732 MI = BuildMI(V9::FMOVD, 2).addMReg(SrcReg)
733 .addMReg(DestReg, MachineOperand::Def);
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000734 break;
735
736 default:
Vikram S. Advee9327f02002-05-19 15:25:51 +0000737 assert(0 && "Unknown RegType");
Vikram S. Adveaee67012002-07-08 23:23:12 +0000738 break;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000739 }
Vikram S. Advee9327f02002-05-19 15:25:51 +0000740
741 if (MI)
742 mvec.push_back(MI);
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000743}
Chris Lattnerb0ddffa2001-09-14 03:47:57 +0000744
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000745//---------------------------------------------------------------------------
Ruchira Sasanka0863c162001-10-24 22:05:34 +0000746// Copy from a register to memory (i.e., Store). Register number must
747// be the unified register number
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000748//---------------------------------------------------------------------------
749
750
Vikram S. Advee9327f02002-05-19 15:25:51 +0000751void
Brian Gaeke94e95d22004-02-25 18:44:15 +0000752SparcV9RegInfo::cpReg2MemMI(std::vector<MachineInstr*>& mvec,
Vikram S. Adveaee67012002-07-08 23:23:12 +0000753 unsigned SrcReg,
Vikram S. Adve23535842003-07-29 19:53:21 +0000754 unsigned PtrReg,
Vikram S. Advee9327f02002-05-19 15:25:51 +0000755 int Offset, int RegType,
Chris Lattner3091e112002-07-25 06:08:32 +0000756 int scratchReg) const {
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000757 MachineInstr * MI = NULL;
Vikram S. Adve23535842003-07-29 19:53:21 +0000758 int OffReg = -1;
759
760 // If the Offset will not fit in the signed-immediate field, find an
761 // unused register to hold the offset value. This takes advantage of
762 // the fact that all the opcodes used below have the same size immed. field.
763 // Use the register allocator, PRA, to find an unused reg. at this MI.
764 //
765 if (RegType != IntCCRegType) // does not use offset below
766 if (! target.getInstrInfo().constantFitsInImmedField(V9::LDXi, Offset)) {
767#ifdef CAN_FIND_FREE_REGISTER_TRANSPARENTLY
768 RegClass* RC = PRA.getRegClassByID(this->getRegClassIDOfRegType(RegType));
769 OffReg = PRA.getUnusedUniRegAtMI(RC, RegType, MInst, LVSetBef);
770#else
Brian Gaekef8cb2412003-11-08 18:12:24 +0000771 // Default to using register g4 for holding large offsets
Brian Gaeke94e95d22004-02-25 18:44:15 +0000772 OffReg = getUnifiedRegNum(SparcV9RegInfo::IntRegClassID,
773 SparcV9IntRegClass::g4);
Vikram S. Adve23535842003-07-29 19:53:21 +0000774#endif
775 assert(OffReg >= 0 && "FIXME: cpReg2MemMI cannot find an unused reg.");
776 mvec.push_back(BuildMI(V9::SETSW, 2).addZImm(Offset).addReg(OffReg));
777 }
778
Chris Lattner1ebaa902003-01-15 17:47:49 +0000779 switch (RegType) {
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000780 case IntRegType:
Vikram S. Adve23535842003-07-29 19:53:21 +0000781 if (target.getInstrInfo().constantFitsInImmedField(V9::STXi, Offset))
782 MI = BuildMI(V9::STXi,3).addMReg(SrcReg).addMReg(PtrReg).addSImm(Offset);
783 else
784 MI = BuildMI(V9::STXr,3).addMReg(SrcReg).addMReg(PtrReg).addMReg(OffReg);
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000785 break;
786
787 case FPSingleRegType:
Vikram S. Adve23535842003-07-29 19:53:21 +0000788 if (target.getInstrInfo().constantFitsInImmedField(V9::STFi, Offset))
789 MI = BuildMI(V9::STFi, 3).addMReg(SrcReg).addMReg(PtrReg).addSImm(Offset);
790 else
791 MI = BuildMI(V9::STFr, 3).addMReg(SrcReg).addMReg(PtrReg).addMReg(OffReg);
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000792 break;
793
794 case FPDoubleRegType:
Vikram S. Adve23535842003-07-29 19:53:21 +0000795 if (target.getInstrInfo().constantFitsInImmedField(V9::STDFi, Offset))
796 MI = BuildMI(V9::STDFi,3).addMReg(SrcReg).addMReg(PtrReg).addSImm(Offset);
797 else
798 MI = BuildMI(V9::STDFr,3).addMReg(SrcReg).addMReg(PtrReg).addSImm(OffReg);
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000799 break;
800
Ruchira Sasanka9d8950d2001-11-03 19:59:59 +0000801 case IntCCRegType:
Vikram S. Adveaee67012002-07-08 23:23:12 +0000802 assert(scratchReg >= 0 && "Need scratch reg to store %ccr to memory");
Chris Lattner56e91662002-08-12 21:25:05 +0000803 assert(getRegType(scratchReg) ==IntRegType && "Invalid scratch reg");
Vikram S. Adve65280672003-07-10 19:42:11 +0000804 MI = (BuildMI(V9::RDCCR, 2)
Brian Gaeke94e95d22004-02-25 18:44:15 +0000805 .addMReg(getUnifiedRegNum(SparcV9RegInfo::IntCCRegClassID,
806 SparcV9IntCCRegClass::ccr))
Alkis Evlogimenos8358cc52004-02-22 19:23:26 +0000807 .addMReg(scratchReg, MachineOperand::Def));
Vikram S. Adveaee67012002-07-08 23:23:12 +0000808 mvec.push_back(MI);
809
Vikram S. Adve23535842003-07-29 19:53:21 +0000810 cpReg2MemMI(mvec, scratchReg, PtrReg, Offset, IntRegType);
Chris Lattner1ebaa902003-01-15 17:47:49 +0000811 return;
Vikram S. Adve23535842003-07-29 19:53:21 +0000812
Brian Gaeke6c272a92004-04-19 19:12:12 +0000813 case SpecialRegType: // used only for %fsr itself.
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000814 case FloatCCRegType: {
Brian Gaeke94e95d22004-02-25 18:44:15 +0000815 unsigned fsrReg = getUnifiedRegNum(SparcV9RegInfo::SpecialRegClassID,
816 SparcV9SpecialRegClass::fsr);
Vikram S. Adve23535842003-07-29 19:53:21 +0000817 if (target.getInstrInfo().constantFitsInImmedField(V9::STXFSRi, Offset))
818 MI=BuildMI(V9::STXFSRi,3).addMReg(fsrReg).addMReg(PtrReg).addSImm(Offset);
819 else
820 MI=BuildMI(V9::STXFSRr,3).addMReg(fsrReg).addMReg(PtrReg).addMReg(OffReg);
Vikram S. Adveaee67012002-07-08 23:23:12 +0000821 break;
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000822 }
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000823 default:
Vikram S. Advee9327f02002-05-19 15:25:51 +0000824 assert(0 && "Unknown RegType in cpReg2MemMI");
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000825 }
Chris Lattner1ebaa902003-01-15 17:47:49 +0000826 mvec.push_back(MI);
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000827}
828
829
830//---------------------------------------------------------------------------
Ruchira Sasanka0863c162001-10-24 22:05:34 +0000831// Copy from memory to a reg (i.e., Load) Register number must be the unified
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000832// register number
833//---------------------------------------------------------------------------
834
835
Vikram S. Advee9327f02002-05-19 15:25:51 +0000836void
Brian Gaeke94e95d22004-02-25 18:44:15 +0000837SparcV9RegInfo::cpMem2RegMI(std::vector<MachineInstr*>& mvec,
Vikram S. Adve23535842003-07-29 19:53:21 +0000838 unsigned PtrReg,
Vikram S. Advee9327f02002-05-19 15:25:51 +0000839 int Offset,
840 unsigned DestReg,
841 int RegType,
Chris Lattner3091e112002-07-25 06:08:32 +0000842 int scratchReg) const {
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000843 MachineInstr * MI = NULL;
Vikram S. Adve23535842003-07-29 19:53:21 +0000844 int OffReg = -1;
845
846 // If the Offset will not fit in the signed-immediate field, find an
847 // unused register to hold the offset value. This takes advantage of
848 // the fact that all the opcodes used below have the same size immed. field.
849 // Use the register allocator, PRA, to find an unused reg. at this MI.
850 //
851 if (RegType != IntCCRegType) // does not use offset below
852 if (! target.getInstrInfo().constantFitsInImmedField(V9::LDXi, Offset)) {
853#ifdef CAN_FIND_FREE_REGISTER_TRANSPARENTLY
854 RegClass* RC = PRA.getRegClassByID(this->getRegClassIDOfRegType(RegType));
855 OffReg = PRA.getUnusedUniRegAtMI(RC, RegType, MInst, LVSetBef);
856#else
Brian Gaekef8cb2412003-11-08 18:12:24 +0000857 // Default to using register g4 for holding large offsets
Brian Gaeke94e95d22004-02-25 18:44:15 +0000858 OffReg = getUnifiedRegNum(SparcV9RegInfo::IntRegClassID,
859 SparcV9IntRegClass::g4);
Vikram S. Adve23535842003-07-29 19:53:21 +0000860#endif
861 assert(OffReg >= 0 && "FIXME: cpReg2MemMI cannot find an unused reg.");
862 mvec.push_back(BuildMI(V9::SETSW, 2).addZImm(Offset).addReg(OffReg));
863 }
864
Chris Lattner5216cc52002-02-04 05:59:25 +0000865 switch (RegType) {
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000866 case IntRegType:
Vikram S. Adve23535842003-07-29 19:53:21 +0000867 if (target.getInstrInfo().constantFitsInImmedField(V9::LDXi, Offset))
Alkis Evlogimenos8358cc52004-02-22 19:23:26 +0000868 MI = BuildMI(V9::LDXi, 3).addMReg(PtrReg).addSImm(Offset)
869 .addMReg(DestReg, MachineOperand::Def);
Vikram S. Adve23535842003-07-29 19:53:21 +0000870 else
Alkis Evlogimenos8358cc52004-02-22 19:23:26 +0000871 MI = BuildMI(V9::LDXr, 3).addMReg(PtrReg).addMReg(OffReg)
872 .addMReg(DestReg, MachineOperand::Def);
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000873 break;
874
875 case FPSingleRegType:
Vikram S. Adve23535842003-07-29 19:53:21 +0000876 if (target.getInstrInfo().constantFitsInImmedField(V9::LDFi, Offset))
Alkis Evlogimenos8358cc52004-02-22 19:23:26 +0000877 MI = BuildMI(V9::LDFi, 3).addMReg(PtrReg).addSImm(Offset)
878 .addMReg(DestReg, MachineOperand::Def);
Vikram S. Adve23535842003-07-29 19:53:21 +0000879 else
Alkis Evlogimenos8358cc52004-02-22 19:23:26 +0000880 MI = BuildMI(V9::LDFr, 3).addMReg(PtrReg).addMReg(OffReg)
881 .addMReg(DestReg, MachineOperand::Def);
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000882 break;
883
884 case FPDoubleRegType:
Vikram S. Adve23535842003-07-29 19:53:21 +0000885 if (target.getInstrInfo().constantFitsInImmedField(V9::LDDFi, Offset))
Alkis Evlogimenos8358cc52004-02-22 19:23:26 +0000886 MI= BuildMI(V9::LDDFi, 3).addMReg(PtrReg).addSImm(Offset)
887 .addMReg(DestReg, MachineOperand::Def);
Vikram S. Adve23535842003-07-29 19:53:21 +0000888 else
Alkis Evlogimenos8358cc52004-02-22 19:23:26 +0000889 MI= BuildMI(V9::LDDFr, 3).addMReg(PtrReg).addMReg(OffReg)
890 .addMReg(DestReg, MachineOperand::Def);
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000891 break;
892
Ruchira Sasanka9d8950d2001-11-03 19:59:59 +0000893 case IntCCRegType:
Vikram S. Adveaee67012002-07-08 23:23:12 +0000894 assert(scratchReg >= 0 && "Need scratch reg to load %ccr from memory");
Chris Lattner56e91662002-08-12 21:25:05 +0000895 assert(getRegType(scratchReg) ==IntRegType && "Invalid scratch reg");
Vikram S. Adve23535842003-07-29 19:53:21 +0000896 cpMem2RegMI(mvec, PtrReg, Offset, scratchReg, IntRegType);
Vikram S. Adve65280672003-07-10 19:42:11 +0000897 MI = (BuildMI(V9::WRCCRr, 3)
898 .addMReg(scratchReg)
Brian Gaeke94e95d22004-02-25 18:44:15 +0000899 .addMReg(SparcV9IntRegClass::g0)
900 .addMReg(getUnifiedRegNum(SparcV9RegInfo::IntCCRegClassID,
901 SparcV9IntCCRegClass::ccr), MachineOperand::Def));
Vikram S. Adveaee67012002-07-08 23:23:12 +0000902 break;
903
Brian Gaeke6c272a92004-04-19 19:12:12 +0000904 case SpecialRegType: // used only for %fsr itself
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000905 case FloatCCRegType: {
Brian Gaeke94e95d22004-02-25 18:44:15 +0000906 unsigned fsrRegNum = getUnifiedRegNum(SparcV9RegInfo::SpecialRegClassID,
907 SparcV9SpecialRegClass::fsr);
Vikram S. Adve23535842003-07-29 19:53:21 +0000908 if (target.getInstrInfo().constantFitsInImmedField(V9::LDXFSRi, Offset))
909 MI = BuildMI(V9::LDXFSRi, 3).addMReg(PtrReg).addSImm(Offset)
Alkis Evlogimenos8358cc52004-02-22 19:23:26 +0000910 .addMReg(fsrRegNum, MachineOperand::UseAndDef);
Vikram S. Adve23535842003-07-29 19:53:21 +0000911 else
912 MI = BuildMI(V9::LDXFSRr, 3).addMReg(PtrReg).addMReg(OffReg)
Alkis Evlogimenos8358cc52004-02-22 19:23:26 +0000913 .addMReg(fsrRegNum, MachineOperand::UseAndDef);
Vikram S. Adveaee67012002-07-08 23:23:12 +0000914 break;
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000915 }
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000916 default:
Ruchira Sasanka0c085982001-11-10 21:20:43 +0000917 assert(0 && "Unknown RegType in cpMem2RegMI");
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000918 }
Chris Lattner1ebaa902003-01-15 17:47:49 +0000919 mvec.push_back(MI);
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000920}
921
922
Ruchira Sasankafcdc2ff2001-11-12 14:45:33 +0000923//---------------------------------------------------------------------------
924// Generate a copy instruction to copy a value to another. Temporarily
925// used by PhiElimination code.
926//---------------------------------------------------------------------------
927
928
Vikram S. Advee9327f02002-05-19 15:25:51 +0000929void
Brian Gaeke94e95d22004-02-25 18:44:15 +0000930SparcV9RegInfo::cpValue2Value(Value *Src, Value *Dest,
Misha Brukman352f7ac2003-05-21 17:59:06 +0000931 std::vector<MachineInstr*>& mvec) const {
Vikram S. Adve536b1922003-07-25 21:12:15 +0000932 int RegType = getRegTypeForDataType(Src->getType());
Ruchira Sasankab7a39722001-11-03 17:13:27 +0000933 MachineInstr * MI = NULL;
934
Ruchira Sasankafcdc2ff2001-11-12 14:45:33 +0000935 switch( RegType ) {
Ruchira Sasankafcdc2ff2001-11-12 14:45:33 +0000936 case IntRegType:
Misha Brukmanaf96d392003-05-27 22:40:34 +0000937 MI = BuildMI(V9::ADDr, 3).addReg(Src).addMReg(getZeroRegNum())
Misha Brukman56f4fa12003-05-20 20:32:24 +0000938 .addRegDef(Dest);
Ruchira Sasankafcdc2ff2001-11-12 14:45:33 +0000939 break;
Ruchira Sasankafcdc2ff2001-11-12 14:45:33 +0000940 case FPSingleRegType:
Misha Brukman56f4fa12003-05-20 20:32:24 +0000941 MI = BuildMI(V9::FMOVS, 2).addReg(Src).addRegDef(Dest);
Ruchira Sasankafcdc2ff2001-11-12 14:45:33 +0000942 break;
Ruchira Sasankafcdc2ff2001-11-12 14:45:33 +0000943 case FPDoubleRegType:
Misha Brukman56f4fa12003-05-20 20:32:24 +0000944 MI = BuildMI(V9::FMOVD, 2).addReg(Src).addRegDef(Dest);
Ruchira Sasankafcdc2ff2001-11-12 14:45:33 +0000945 break;
Ruchira Sasankafcdc2ff2001-11-12 14:45:33 +0000946 default:
947 assert(0 && "Unknow RegType in CpValu2Value");
948 }
Ruchira Sasankab7a39722001-11-03 17:13:27 +0000949
Chris Lattner9bebf832002-10-28 20:10:56 +0000950 mvec.push_back(MI);
Ruchira Sasankab7a39722001-11-03 17:13:27 +0000951}
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000952
953
954
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000955//---------------------------------------------------------------------------
956// Print the register assigned to a LR
957//---------------------------------------------------------------------------
958
Brian Gaeke94e95d22004-02-25 18:44:15 +0000959void SparcV9RegInfo::printReg(const LiveRange *LR) const {
Chris Lattnerf9fd5912003-01-15 21:14:32 +0000960 unsigned RegClassID = LR->getRegClassID();
Chris Lattner69382172003-09-01 19:58:02 +0000961 std::cerr << " Node ";
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000962
Chris Lattner5216cc52002-02-04 05:59:25 +0000963 if (!LR->hasColor()) {
Misha Brukman352f7ac2003-05-21 17:59:06 +0000964 std::cerr << " - could not find a color\n";
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000965 return;
966 }
967
968 // if a color is found
969
Misha Brukman352f7ac2003-05-21 17:59:06 +0000970 std::cerr << " colored with color "<< LR->getColor();
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000971
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000972 unsigned uRegName = getUnifiedRegNum(RegClassID, LR->getColor());
973
974 std::cerr << "[";
975 std::cerr<< getUnifiedRegName(uRegName);
976 if (RegClassID == FloatRegClassID && LR->getType() == Type::DoubleTy)
977 std::cerr << "+" << getUnifiedRegName(uRegName+1);
978 std::cerr << "]\n";
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000979}
Brian Gaeke960707c2003-11-11 22:41:34 +0000980
981} // End llvm namespace