blob: b1031b46be6bff92085f43a36da762f75e1dd613 [file] [log] [blame]
Chris Lattnerd23405e2008-03-17 03:21:36 +00001//===-- SparcISelLowering.cpp - Sparc DAG Lowering Implementation ---------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the interfaces that Sparc uses to lower LLVM code into a
11// selection DAG.
12//
13//===----------------------------------------------------------------------===//
14
15#include "SparcISelLowering.h"
16#include "SparcTargetMachine.h"
Chris Lattnerd23405e2008-03-17 03:21:36 +000017#include "llvm/Function.h"
Chris Lattner5a65b922008-03-17 05:41:48 +000018#include "llvm/CodeGen/CallingConvLower.h"
Chris Lattnerd23405e2008-03-17 03:21:36 +000019#include "llvm/CodeGen/MachineFrameInfo.h"
20#include "llvm/CodeGen/MachineFunction.h"
21#include "llvm/CodeGen/MachineInstrBuilder.h"
22#include "llvm/CodeGen/MachineRegisterInfo.h"
23#include "llvm/CodeGen/SelectionDAG.h"
Anton Korobeynikov0eefda12008-10-10 20:28:10 +000024#include "llvm/ADT/VectorExtras.h"
Chris Lattnerd23405e2008-03-17 03:21:36 +000025using namespace llvm;
26
Chris Lattner5a65b922008-03-17 05:41:48 +000027
28//===----------------------------------------------------------------------===//
29// Calling Convention Implementation
30//===----------------------------------------------------------------------===//
31
32#include "SparcGenCallingConv.inc"
33
Dan Gohman475871a2008-07-27 21:46:04 +000034static SDValue LowerRET(SDValue Op, SelectionDAG &DAG) {
Chris Lattner5a65b922008-03-17 05:41:48 +000035 // CCValAssign - represent the assignment of the return value to locations.
36 SmallVector<CCValAssign, 16> RVLocs;
Chris Lattner98949a62008-03-17 06:01:07 +000037 unsigned CC = DAG.getMachineFunction().getFunction()->getCallingConv();
Chris Lattner5a65b922008-03-17 05:41:48 +000038 bool isVarArg = DAG.getMachineFunction().getFunction()->isVarArg();
Anton Korobeynikov53835702008-10-10 20:27:31 +000039
Chris Lattner5a65b922008-03-17 05:41:48 +000040 // CCState - Info about the registers and stack slot.
41 CCState CCInfo(CC, isVarArg, DAG.getTarget(), RVLocs);
Anton Korobeynikov53835702008-10-10 20:27:31 +000042
Chris Lattner5a65b922008-03-17 05:41:48 +000043 // Analize return values of ISD::RET
Gabor Greifba36cb52008-08-28 21:40:38 +000044 CCInfo.AnalyzeReturn(Op.getNode(), RetCC_Sparc32);
Anton Korobeynikov53835702008-10-10 20:27:31 +000045
Chris Lattner5a65b922008-03-17 05:41:48 +000046 // If this is the first return lowered for this function, add the regs to the
47 // liveout set for the function.
48 if (DAG.getMachineFunction().getRegInfo().liveout_empty()) {
49 for (unsigned i = 0; i != RVLocs.size(); ++i)
50 if (RVLocs[i].isRegLoc())
51 DAG.getMachineFunction().getRegInfo().addLiveOut(RVLocs[i].getLocReg());
52 }
Anton Korobeynikov53835702008-10-10 20:27:31 +000053
Dan Gohman475871a2008-07-27 21:46:04 +000054 SDValue Chain = Op.getOperand(0);
55 SDValue Flag;
Chris Lattner5a65b922008-03-17 05:41:48 +000056
57 // Copy the result values into the output registers.
58 for (unsigned i = 0; i != RVLocs.size(); ++i) {
59 CCValAssign &VA = RVLocs[i];
60 assert(VA.isRegLoc() && "Can only return in registers!");
Anton Korobeynikov53835702008-10-10 20:27:31 +000061
Chris Lattner5a65b922008-03-17 05:41:48 +000062 // ISD::RET => ret chain, (regnum1,val1), ...
63 // So i*2+1 index only the regnums.
64 Chain = DAG.getCopyToReg(Chain, VA.getLocReg(), Op.getOperand(i*2+1), Flag);
Anton Korobeynikov53835702008-10-10 20:27:31 +000065
Chris Lattner5a65b922008-03-17 05:41:48 +000066 // Guarantee that all emitted copies are stuck together with flags.
67 Flag = Chain.getValue(1);
68 }
Anton Korobeynikov53835702008-10-10 20:27:31 +000069
Gabor Greifba36cb52008-08-28 21:40:38 +000070 if (Flag.getNode())
Chris Lattner5a65b922008-03-17 05:41:48 +000071 return DAG.getNode(SPISD::RET_FLAG, MVT::Other, Chain, Flag);
72 return DAG.getNode(SPISD::RET_FLAG, MVT::Other, Chain);
73}
74
75/// LowerArguments - V8 uses a very simple ABI, where all values are passed in
76/// either one or two GPRs, including FP values. TODO: we should pass FP values
77/// in FP registers for fastcc functions.
Dan Gohmana44b6742008-06-30 20:31:15 +000078void
79SparcTargetLowering::LowerArguments(Function &F, SelectionDAG &DAG,
Dan Gohman475871a2008-07-27 21:46:04 +000080 SmallVectorImpl<SDValue> &ArgValues) {
Chris Lattner5a65b922008-03-17 05:41:48 +000081 MachineFunction &MF = DAG.getMachineFunction();
82 MachineRegisterInfo &RegInfo = MF.getRegInfo();
Anton Korobeynikov53835702008-10-10 20:27:31 +000083
Chris Lattner5a65b922008-03-17 05:41:48 +000084 static const unsigned ArgRegs[] = {
85 SP::I0, SP::I1, SP::I2, SP::I3, SP::I4, SP::I5
86 };
Anton Korobeynikov53835702008-10-10 20:27:31 +000087
Chris Lattner5a65b922008-03-17 05:41:48 +000088 const unsigned *CurArgReg = ArgRegs, *ArgRegEnd = ArgRegs+6;
89 unsigned ArgOffset = 68;
Anton Korobeynikov53835702008-10-10 20:27:31 +000090
Dan Gohman475871a2008-07-27 21:46:04 +000091 SDValue Root = DAG.getRoot();
92 std::vector<SDValue> OutChains;
Chris Lattner5a65b922008-03-17 05:41:48 +000093
94 for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I) {
Duncan Sands83ec4b62008-06-06 12:08:01 +000095 MVT ObjectVT = getValueType(I->getType());
Anton Korobeynikov53835702008-10-10 20:27:31 +000096
Duncan Sands83ec4b62008-06-06 12:08:01 +000097 switch (ObjectVT.getSimpleVT()) {
Chris Lattner5a65b922008-03-17 05:41:48 +000098 default: assert(0 && "Unhandled argument type!");
99 case MVT::i1:
100 case MVT::i8:
101 case MVT::i16:
102 case MVT::i32:
103 if (I->use_empty()) { // Argument is dead.
104 if (CurArgReg < ArgRegEnd) ++CurArgReg;
105 ArgValues.push_back(DAG.getNode(ISD::UNDEF, ObjectVT));
106 } else if (CurArgReg < ArgRegEnd) { // Lives in an incoming GPR
107 unsigned VReg = RegInfo.createVirtualRegister(&SP::IntRegsRegClass);
108 MF.getRegInfo().addLiveIn(*CurArgReg++, VReg);
Dan Gohman475871a2008-07-27 21:46:04 +0000109 SDValue Arg = DAG.getCopyFromReg(Root, VReg, MVT::i32);
Chris Lattner5a65b922008-03-17 05:41:48 +0000110 if (ObjectVT != MVT::i32) {
111 unsigned AssertOp = ISD::AssertSext;
Anton Korobeynikov53835702008-10-10 20:27:31 +0000112 Arg = DAG.getNode(AssertOp, MVT::i32, Arg,
Chris Lattner5a65b922008-03-17 05:41:48 +0000113 DAG.getValueType(ObjectVT));
114 Arg = DAG.getNode(ISD::TRUNCATE, ObjectVT, Arg);
115 }
116 ArgValues.push_back(Arg);
117 } else {
118 int FrameIdx = MF.getFrameInfo()->CreateFixedObject(4, ArgOffset);
Dan Gohman475871a2008-07-27 21:46:04 +0000119 SDValue FIPtr = DAG.getFrameIndex(FrameIdx, MVT::i32);
120 SDValue Load;
Chris Lattner5a65b922008-03-17 05:41:48 +0000121 if (ObjectVT == MVT::i32) {
122 Load = DAG.getLoad(MVT::i32, Root, FIPtr, NULL, 0);
123 } else {
124 ISD::LoadExtType LoadOp = ISD::SEXTLOAD;
125
126 // Sparc is big endian, so add an offset based on the ObjectVT.
Duncan Sands83ec4b62008-06-06 12:08:01 +0000127 unsigned Offset = 4-std::max(1U, ObjectVT.getSizeInBits()/8);
Chris Lattner5a65b922008-03-17 05:41:48 +0000128 FIPtr = DAG.getNode(ISD::ADD, MVT::i32, FIPtr,
129 DAG.getConstant(Offset, MVT::i32));
130 Load = DAG.getExtLoad(LoadOp, MVT::i32, Root, FIPtr,
131 NULL, 0, ObjectVT);
132 Load = DAG.getNode(ISD::TRUNCATE, ObjectVT, Load);
133 }
134 ArgValues.push_back(Load);
135 }
Anton Korobeynikov53835702008-10-10 20:27:31 +0000136
Chris Lattner5a65b922008-03-17 05:41:48 +0000137 ArgOffset += 4;
138 break;
139 case MVT::f32:
140 if (I->use_empty()) { // Argument is dead.
141 if (CurArgReg < ArgRegEnd) ++CurArgReg;
142 ArgValues.push_back(DAG.getNode(ISD::UNDEF, ObjectVT));
143 } else if (CurArgReg < ArgRegEnd) { // Lives in an incoming GPR
144 // FP value is passed in an integer register.
145 unsigned VReg = RegInfo.createVirtualRegister(&SP::IntRegsRegClass);
146 MF.getRegInfo().addLiveIn(*CurArgReg++, VReg);
Dan Gohman475871a2008-07-27 21:46:04 +0000147 SDValue Arg = DAG.getCopyFromReg(Root, VReg, MVT::i32);
Chris Lattner5a65b922008-03-17 05:41:48 +0000148
149 Arg = DAG.getNode(ISD::BIT_CONVERT, MVT::f32, Arg);
150 ArgValues.push_back(Arg);
151 } else {
152 int FrameIdx = MF.getFrameInfo()->CreateFixedObject(4, ArgOffset);
Dan Gohman475871a2008-07-27 21:46:04 +0000153 SDValue FIPtr = DAG.getFrameIndex(FrameIdx, MVT::i32);
154 SDValue Load = DAG.getLoad(MVT::f32, Root, FIPtr, NULL, 0);
Chris Lattner5a65b922008-03-17 05:41:48 +0000155 ArgValues.push_back(Load);
156 }
157 ArgOffset += 4;
158 break;
159
160 case MVT::i64:
161 case MVT::f64:
162 if (I->use_empty()) { // Argument is dead.
163 if (CurArgReg < ArgRegEnd) ++CurArgReg;
164 if (CurArgReg < ArgRegEnd) ++CurArgReg;
165 ArgValues.push_back(DAG.getNode(ISD::UNDEF, ObjectVT));
Chris Lattner5a65b922008-03-17 05:41:48 +0000166 } else {
Dan Gohman475871a2008-07-27 21:46:04 +0000167 SDValue HiVal;
Chris Lattner5a65b922008-03-17 05:41:48 +0000168 if (CurArgReg < ArgRegEnd) { // Lives in an incoming GPR
169 unsigned VRegHi = RegInfo.createVirtualRegister(&SP::IntRegsRegClass);
170 MF.getRegInfo().addLiveIn(*CurArgReg++, VRegHi);
171 HiVal = DAG.getCopyFromReg(Root, VRegHi, MVT::i32);
172 } else {
173 int FrameIdx = MF.getFrameInfo()->CreateFixedObject(4, ArgOffset);
Dan Gohman475871a2008-07-27 21:46:04 +0000174 SDValue FIPtr = DAG.getFrameIndex(FrameIdx, MVT::i32);
Chris Lattner5a65b922008-03-17 05:41:48 +0000175 HiVal = DAG.getLoad(MVT::i32, Root, FIPtr, NULL, 0);
176 }
Anton Korobeynikov53835702008-10-10 20:27:31 +0000177
Dan Gohman475871a2008-07-27 21:46:04 +0000178 SDValue LoVal;
Chris Lattner5a65b922008-03-17 05:41:48 +0000179 if (CurArgReg < ArgRegEnd) { // Lives in an incoming GPR
180 unsigned VRegLo = RegInfo.createVirtualRegister(&SP::IntRegsRegClass);
181 MF.getRegInfo().addLiveIn(*CurArgReg++, VRegLo);
182 LoVal = DAG.getCopyFromReg(Root, VRegLo, MVT::i32);
183 } else {
184 int FrameIdx = MF.getFrameInfo()->CreateFixedObject(4, ArgOffset+4);
Dan Gohman475871a2008-07-27 21:46:04 +0000185 SDValue FIPtr = DAG.getFrameIndex(FrameIdx, MVT::i32);
Chris Lattner5a65b922008-03-17 05:41:48 +0000186 LoVal = DAG.getLoad(MVT::i32, Root, FIPtr, NULL, 0);
187 }
Anton Korobeynikov53835702008-10-10 20:27:31 +0000188
Chris Lattner5a65b922008-03-17 05:41:48 +0000189 // Compose the two halves together into an i64 unit.
Anton Korobeynikov53835702008-10-10 20:27:31 +0000190 SDValue WholeValue =
Chris Lattner5a65b922008-03-17 05:41:48 +0000191 DAG.getNode(ISD::BUILD_PAIR, MVT::i64, LoVal, HiVal);
Anton Korobeynikov53835702008-10-10 20:27:31 +0000192
Chris Lattner5a65b922008-03-17 05:41:48 +0000193 // If we want a double, do a bit convert.
194 if (ObjectVT == MVT::f64)
195 WholeValue = DAG.getNode(ISD::BIT_CONVERT, MVT::f64, WholeValue);
Anton Korobeynikov53835702008-10-10 20:27:31 +0000196
Chris Lattner5a65b922008-03-17 05:41:48 +0000197 ArgValues.push_back(WholeValue);
198 }
199 ArgOffset += 8;
200 break;
201 }
202 }
Anton Korobeynikov53835702008-10-10 20:27:31 +0000203
Chris Lattner5a65b922008-03-17 05:41:48 +0000204 // Store remaining ArgRegs to the stack if this is a varargs function.
205 if (F.isVarArg()) {
206 // Remember the vararg offset for the va_start implementation.
207 VarArgsFrameOffset = ArgOffset;
Anton Korobeynikov53835702008-10-10 20:27:31 +0000208
Chris Lattner5a65b922008-03-17 05:41:48 +0000209 for (; CurArgReg != ArgRegEnd; ++CurArgReg) {
210 unsigned VReg = RegInfo.createVirtualRegister(&SP::IntRegsRegClass);
211 MF.getRegInfo().addLiveIn(*CurArgReg, VReg);
Dan Gohman475871a2008-07-27 21:46:04 +0000212 SDValue Arg = DAG.getCopyFromReg(DAG.getRoot(), VReg, MVT::i32);
Chris Lattner5a65b922008-03-17 05:41:48 +0000213
214 int FrameIdx = MF.getFrameInfo()->CreateFixedObject(4, ArgOffset);
Dan Gohman475871a2008-07-27 21:46:04 +0000215 SDValue FIPtr = DAG.getFrameIndex(FrameIdx, MVT::i32);
Chris Lattner5a65b922008-03-17 05:41:48 +0000216
217 OutChains.push_back(DAG.getStore(DAG.getRoot(), Arg, FIPtr, NULL, 0));
218 ArgOffset += 4;
219 }
220 }
Anton Korobeynikov53835702008-10-10 20:27:31 +0000221
Chris Lattner5a65b922008-03-17 05:41:48 +0000222 if (!OutChains.empty())
223 DAG.setRoot(DAG.getNode(ISD::TokenFactor, MVT::Other,
224 &OutChains[0], OutChains.size()));
Chris Lattner5a65b922008-03-17 05:41:48 +0000225}
226
Dan Gohman475871a2008-07-27 21:46:04 +0000227static SDValue LowerCALL(SDValue Op, SelectionDAG &DAG) {
Dan Gohman095cc292008-09-13 01:54:27 +0000228 CallSDNode *TheCall = cast<CallSDNode>(Op.getNode());
229 unsigned CallingConv = TheCall->getCallingConv();
230 SDValue Chain = TheCall->getChain();
231 SDValue Callee = TheCall->getCallee();
232 bool isVarArg = TheCall->isVarArg();
Chris Lattner98949a62008-03-17 06:01:07 +0000233
Chris Lattner315123f2008-03-17 06:58:37 +0000234#if 0
235 // Analyze operands of the call, assigning locations to each operand.
236 SmallVector<CCValAssign, 16> ArgLocs;
237 CCState CCInfo(CallingConv, isVarArg, DAG.getTarget(), ArgLocs);
Gabor Greifba36cb52008-08-28 21:40:38 +0000238 CCInfo.AnalyzeCallOperands(Op.getNode(), CC_Sparc32);
Anton Korobeynikov53835702008-10-10 20:27:31 +0000239
Chris Lattner315123f2008-03-17 06:58:37 +0000240 // Get the size of the outgoing arguments stack space requirement.
241 unsigned ArgsSize = CCInfo.getNextStackOffset();
242 // FIXME: We can't use this until f64 is known to take two GPRs.
243#else
244 (void)CC_Sparc32;
Anton Korobeynikov53835702008-10-10 20:27:31 +0000245
Chris Lattner5a65b922008-03-17 05:41:48 +0000246 // Count the size of the outgoing arguments.
247 unsigned ArgsSize = 0;
Dan Gohman095cc292008-09-13 01:54:27 +0000248 for (unsigned i = 0, e = TheCall->getNumArgs(); i != e; ++i) {
249 switch (TheCall->getArg(i).getValueType().getSimpleVT()) {
Chris Lattner315123f2008-03-17 06:58:37 +0000250 default: assert(0 && "Unknown value type!");
251 case MVT::i1:
252 case MVT::i8:
253 case MVT::i16:
254 case MVT::i32:
255 case MVT::f32:
256 ArgsSize += 4;
257 break;
258 case MVT::i64:
259 case MVT::f64:
260 ArgsSize += 8;
261 break;
Chris Lattner5a65b922008-03-17 05:41:48 +0000262 }
263 }
264 if (ArgsSize > 4*6)
265 ArgsSize -= 4*6; // Space for first 6 arguments is prereserved.
266 else
267 ArgsSize = 0;
Anton Korobeynikov53835702008-10-10 20:27:31 +0000268#endif
269
Chris Lattner5a65b922008-03-17 05:41:48 +0000270 // Keep stack frames 8-byte aligned.
271 ArgsSize = (ArgsSize+7) & ~7;
272
Chris Lattnere563bbc2008-10-11 22:08:30 +0000273 Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(ArgsSize, true));
Anton Korobeynikov53835702008-10-10 20:27:31 +0000274
Dan Gohman475871a2008-07-27 21:46:04 +0000275 SmallVector<std::pair<unsigned, SDValue>, 8> RegsToPass;
276 SmallVector<SDValue, 8> MemOpChains;
Anton Korobeynikov53835702008-10-10 20:27:31 +0000277
Chris Lattner315123f2008-03-17 06:58:37 +0000278#if 0
279 // Walk the register/memloc assignments, inserting copies/loads.
280 for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
281 CCValAssign &VA = ArgLocs[i];
Anton Korobeynikov53835702008-10-10 20:27:31 +0000282
Chris Lattner315123f2008-03-17 06:58:37 +0000283 // Arguments start after the 5 first operands of ISD::CALL
Dan Gohman095cc292008-09-13 01:54:27 +0000284 SDValue Arg = TheCall->getArg(i);
Chris Lattner315123f2008-03-17 06:58:37 +0000285
286 // Promote the value if needed.
287 switch (VA.getLocInfo()) {
288 default: assert(0 && "Unknown loc info!");
289 case CCValAssign::Full: break;
290 case CCValAssign::SExt:
291 Arg = DAG.getNode(ISD::SIGN_EXTEND, VA.getLocVT(), Arg);
292 break;
293 case CCValAssign::ZExt:
294 Arg = DAG.getNode(ISD::ZERO_EXTEND, VA.getLocVT(), Arg);
295 break;
296 case CCValAssign::AExt:
297 Arg = DAG.getNode(ISD::ANY_EXTEND, VA.getLocVT(), Arg);
298 break;
299 }
Anton Korobeynikov53835702008-10-10 20:27:31 +0000300
301 // Arguments that can be passed on register must be kept at
Chris Lattner315123f2008-03-17 06:58:37 +0000302 // RegsToPass vector
303 if (VA.isRegLoc()) {
304 RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg));
305 continue;
306 }
Anton Korobeynikov53835702008-10-10 20:27:31 +0000307
Chris Lattner315123f2008-03-17 06:58:37 +0000308 assert(VA.isMemLoc());
Anton Korobeynikov53835702008-10-10 20:27:31 +0000309
Chris Lattner315123f2008-03-17 06:58:37 +0000310 // Create a store off the stack pointer for this argument.
Dan Gohman475871a2008-07-27 21:46:04 +0000311 SDValue StackPtr = DAG.getRegister(SP::O6, MVT::i32);
Chris Lattner315123f2008-03-17 06:58:37 +0000312 // FIXME: VERIFY THAT 68 IS RIGHT.
Dan Gohman475871a2008-07-27 21:46:04 +0000313 SDValue PtrOff = DAG.getIntPtrConstant(VA.getLocMemOffset()+68);
Chris Lattner315123f2008-03-17 06:58:37 +0000314 PtrOff = DAG.getNode(ISD::ADD, MVT::i32, StackPtr, PtrOff);
315 MemOpChains.push_back(DAG.getStore(Chain, Arg, PtrOff, NULL, 0));
316 }
Anton Korobeynikov53835702008-10-10 20:27:31 +0000317
318#else
Chris Lattner315123f2008-03-17 06:58:37 +0000319 static const unsigned ArgRegs[] = {
320 SP::I0, SP::I1, SP::I2, SP::I3, SP::I4, SP::I5
321 };
Chris Lattner5a65b922008-03-17 05:41:48 +0000322 unsigned ArgOffset = 68;
Chris Lattner315123f2008-03-17 06:58:37 +0000323
Dan Gohman095cc292008-09-13 01:54:27 +0000324 for (unsigned i = 0, e = TheCall->getNumArgs(); i != e; ++i) {
325 SDValue Val = TheCall->getArg(i);
Duncan Sands83ec4b62008-06-06 12:08:01 +0000326 MVT ObjectVT = Val.getValueType();
Dan Gohman475871a2008-07-27 21:46:04 +0000327 SDValue ValToStore(0, 0);
Chris Lattner5a65b922008-03-17 05:41:48 +0000328 unsigned ObjSize;
Duncan Sands83ec4b62008-06-06 12:08:01 +0000329 switch (ObjectVT.getSimpleVT()) {
Chris Lattner5a65b922008-03-17 05:41:48 +0000330 default: assert(0 && "Unhandled argument type!");
Chris Lattner5a65b922008-03-17 05:41:48 +0000331 case MVT::i32:
332 ObjSize = 4;
333
Chris Lattner315123f2008-03-17 06:58:37 +0000334 if (RegsToPass.size() >= 6) {
Chris Lattner5a65b922008-03-17 05:41:48 +0000335 ValToStore = Val;
336 } else {
Chris Lattner315123f2008-03-17 06:58:37 +0000337 RegsToPass.push_back(std::make_pair(ArgRegs[RegsToPass.size()], Val));
Chris Lattner5a65b922008-03-17 05:41:48 +0000338 }
339 break;
340 case MVT::f32:
341 ObjSize = 4;
Chris Lattner315123f2008-03-17 06:58:37 +0000342 if (RegsToPass.size() >= 6) {
Chris Lattner5a65b922008-03-17 05:41:48 +0000343 ValToStore = Val;
344 } else {
345 // Convert this to a FP value in an int reg.
346 Val = DAG.getNode(ISD::BIT_CONVERT, MVT::i32, Val);
Chris Lattner315123f2008-03-17 06:58:37 +0000347 RegsToPass.push_back(std::make_pair(ArgRegs[RegsToPass.size()], Val));
Chris Lattner5a65b922008-03-17 05:41:48 +0000348 }
349 break;
Duncan Sands8c0f2442008-12-12 08:05:40 +0000350 case MVT::f64: {
Chris Lattner5a65b922008-03-17 05:41:48 +0000351 ObjSize = 8;
Duncan Sands8c0f2442008-12-12 08:05:40 +0000352 if (RegsToPass.size() >= 6) {
353 ValToStore = Val; // Whole thing is passed in memory.
354 break;
355 }
356
357 // Break into top and bottom parts by storing to the stack and loading
358 // out the parts as integers. Top part goes in a reg.
359 SDValue StackPtr = DAG.CreateStackTemporary(MVT::f64, MVT::i32);
360 SDValue Store = DAG.getStore(DAG.getEntryNode(), Val, StackPtr, NULL, 0);
361 // Sparc is big-endian, so the high part comes first.
362 SDValue Hi = DAG.getLoad(MVT::i32, Store, StackPtr, NULL, 0, 0);
363 // Increment the pointer to the other half.
364 StackPtr = DAG.getNode(ISD::ADD, StackPtr.getValueType(), StackPtr,
365 DAG.getIntPtrConstant(4));
366 // Load the low part.
367 SDValue Lo = DAG.getLoad(MVT::i32, Store, StackPtr, NULL, 0, 0);
368
369 RegsToPass.push_back(std::make_pair(ArgRegs[RegsToPass.size()], Hi));
370
371 if (RegsToPass.size() >= 6) {
372 ValToStore = Lo;
373 ArgOffset += 4;
374 ObjSize = 4;
375 } else {
376 RegsToPass.push_back(std::make_pair(ArgRegs[RegsToPass.size()], Lo));
377 }
378 break;
379 }
380 case MVT::i64: {
Chris Lattner5a65b922008-03-17 05:41:48 +0000381 ObjSize = 8;
Chris Lattner315123f2008-03-17 06:58:37 +0000382 if (RegsToPass.size() >= 6) {
Chris Lattner5a65b922008-03-17 05:41:48 +0000383 ValToStore = Val; // Whole thing is passed in memory.
384 break;
385 }
Anton Korobeynikov53835702008-10-10 20:27:31 +0000386
Chris Lattner5a65b922008-03-17 05:41:48 +0000387 // Split the value into top and bottom part. Top part goes in a reg.
Anton Korobeynikov53835702008-10-10 20:27:31 +0000388 SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, Val,
Chris Lattner5a65b922008-03-17 05:41:48 +0000389 DAG.getConstant(1, MVT::i32));
Dan Gohman475871a2008-07-27 21:46:04 +0000390 SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, Val,
Chris Lattner5a65b922008-03-17 05:41:48 +0000391 DAG.getConstant(0, MVT::i32));
Chris Lattner315123f2008-03-17 06:58:37 +0000392 RegsToPass.push_back(std::make_pair(ArgRegs[RegsToPass.size()], Hi));
Anton Korobeynikov53835702008-10-10 20:27:31 +0000393
Chris Lattner315123f2008-03-17 06:58:37 +0000394 if (RegsToPass.size() >= 6) {
Chris Lattner5a65b922008-03-17 05:41:48 +0000395 ValToStore = Lo;
396 ArgOffset += 4;
397 ObjSize = 4;
398 } else {
Chris Lattner315123f2008-03-17 06:58:37 +0000399 RegsToPass.push_back(std::make_pair(ArgRegs[RegsToPass.size()], Lo));
Chris Lattner5a65b922008-03-17 05:41:48 +0000400 }
401 break;
402 }
Duncan Sands8c0f2442008-12-12 08:05:40 +0000403 }
Anton Korobeynikov53835702008-10-10 20:27:31 +0000404
Gabor Greifba36cb52008-08-28 21:40:38 +0000405 if (ValToStore.getNode()) {
Dan Gohman475871a2008-07-27 21:46:04 +0000406 SDValue StackPtr = DAG.getRegister(SP::O6, MVT::i32);
407 SDValue PtrOff = DAG.getConstant(ArgOffset, MVT::i32);
Chris Lattner5a65b922008-03-17 05:41:48 +0000408 PtrOff = DAG.getNode(ISD::ADD, MVT::i32, StackPtr, PtrOff);
Chris Lattner315123f2008-03-17 06:58:37 +0000409 MemOpChains.push_back(DAG.getStore(Chain, ValToStore, PtrOff, NULL, 0));
Chris Lattner5a65b922008-03-17 05:41:48 +0000410 }
411 ArgOffset += ObjSize;
412 }
Chris Lattner315123f2008-03-17 06:58:37 +0000413#endif
Anton Korobeynikov53835702008-10-10 20:27:31 +0000414
Chris Lattner5a65b922008-03-17 05:41:48 +0000415 // Emit all stores, make sure the occur before any copies into physregs.
Chris Lattner315123f2008-03-17 06:58:37 +0000416 if (!MemOpChains.empty())
417 Chain = DAG.getNode(ISD::TokenFactor, MVT::Other,
418 &MemOpChains[0], MemOpChains.size());
Anton Korobeynikov53835702008-10-10 20:27:31 +0000419
420 // Build a sequence of copy-to-reg nodes chained together with token
Chris Lattner315123f2008-03-17 06:58:37 +0000421 // chain and flag operands which copy the outgoing args into registers.
422 // The InFlag in necessary since all emited instructions must be
423 // stuck together.
Dan Gohman475871a2008-07-27 21:46:04 +0000424 SDValue InFlag;
Chris Lattner315123f2008-03-17 06:58:37 +0000425 for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) {
426 unsigned Reg = RegsToPass[i].first;
427 // Remap I0->I7 -> O0->O7.
428 if (Reg >= SP::I0 && Reg <= SP::I7)
429 Reg = Reg-SP::I0+SP::O0;
430
431 Chain = DAG.getCopyToReg(Chain, Reg, RegsToPass[i].second, InFlag);
Chris Lattner5a65b922008-03-17 05:41:48 +0000432 InFlag = Chain.getValue(1);
433 }
434
435 // If the callee is a GlobalAddress node (quite common, every direct call is)
436 // turn it into a TargetGlobalAddress node so that legalize doesn't hack it.
Bill Wendling056292f2008-09-16 21:48:12 +0000437 // Likewise ExternalSymbol -> TargetExternalSymbol.
Chris Lattner5a65b922008-03-17 05:41:48 +0000438 if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee))
439 Callee = DAG.getTargetGlobalAddress(G->getGlobal(), MVT::i32);
Bill Wendling056292f2008-09-16 21:48:12 +0000440 else if (ExternalSymbolSDNode *E = dyn_cast<ExternalSymbolSDNode>(Callee))
441 Callee = DAG.getTargetExternalSymbol(E->getSymbol(), MVT::i32);
Chris Lattner5a65b922008-03-17 05:41:48 +0000442
Duncan Sands83ec4b62008-06-06 12:08:01 +0000443 std::vector<MVT> NodeTys;
Chris Lattner5a65b922008-03-17 05:41:48 +0000444 NodeTys.push_back(MVT::Other); // Returns a chain
445 NodeTys.push_back(MVT::Flag); // Returns a flag for retval copy to use.
Dan Gohman475871a2008-07-27 21:46:04 +0000446 SDValue Ops[] = { Chain, Callee, InFlag };
Gabor Greifba36cb52008-08-28 21:40:38 +0000447 Chain = DAG.getNode(SPISD::CALL, NodeTys, Ops, InFlag.getNode() ? 3 : 2);
Chris Lattner5a65b922008-03-17 05:41:48 +0000448 InFlag = Chain.getValue(1);
Anton Korobeynikov53835702008-10-10 20:27:31 +0000449
Chris Lattnere563bbc2008-10-11 22:08:30 +0000450 Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(ArgsSize, true),
451 DAG.getIntPtrConstant(0, true), InFlag);
Chris Lattner98949a62008-03-17 06:01:07 +0000452 InFlag = Chain.getValue(1);
Anton Korobeynikov53835702008-10-10 20:27:31 +0000453
Chris Lattner98949a62008-03-17 06:01:07 +0000454 // Assign locations to each value returned by this call.
455 SmallVector<CCValAssign, 16> RVLocs;
Chris Lattner315123f2008-03-17 06:58:37 +0000456 CCState RVInfo(CallingConv, isVarArg, DAG.getTarget(), RVLocs);
Anton Korobeynikov53835702008-10-10 20:27:31 +0000457
Dan Gohman095cc292008-09-13 01:54:27 +0000458 RVInfo.AnalyzeCallResult(TheCall, RetCC_Sparc32);
Dan Gohman475871a2008-07-27 21:46:04 +0000459 SmallVector<SDValue, 8> ResultVals;
Anton Korobeynikov53835702008-10-10 20:27:31 +0000460
Chris Lattner98949a62008-03-17 06:01:07 +0000461 // Copy all of the result registers out of their specified physreg.
462 for (unsigned i = 0; i != RVLocs.size(); ++i) {
463 unsigned Reg = RVLocs[i].getLocReg();
Anton Korobeynikov53835702008-10-10 20:27:31 +0000464
Chris Lattner98949a62008-03-17 06:01:07 +0000465 // Remap I0->I7 -> O0->O7.
466 if (Reg >= SP::I0 && Reg <= SP::I7)
467 Reg = Reg-SP::I0+SP::O0;
Anton Korobeynikov53835702008-10-10 20:27:31 +0000468
Chris Lattner98949a62008-03-17 06:01:07 +0000469 Chain = DAG.getCopyFromReg(Chain, Reg,
470 RVLocs[i].getValVT(), InFlag).getValue(1);
471 InFlag = Chain.getValue(2);
472 ResultVals.push_back(Chain.getValue(0));
Chris Lattner5a65b922008-03-17 05:41:48 +0000473 }
Anton Korobeynikov53835702008-10-10 20:27:31 +0000474
Chris Lattner98949a62008-03-17 06:01:07 +0000475 ResultVals.push_back(Chain);
Duncan Sands4bdcb612008-07-02 17:40:58 +0000476
Chris Lattner98949a62008-03-17 06:01:07 +0000477 // Merge everything together with a MERGE_VALUES node.
Duncan Sandsaaffa052008-12-01 11:41:29 +0000478 return DAG.getNode(ISD::MERGE_VALUES, TheCall->getVTList(), &ResultVals[0],
479 ResultVals.size());
Chris Lattner5a65b922008-03-17 05:41:48 +0000480}
481
482
483
Chris Lattnerd23405e2008-03-17 03:21:36 +0000484//===----------------------------------------------------------------------===//
485// TargetLowering Implementation
486//===----------------------------------------------------------------------===//
487
488/// IntCondCCodeToICC - Convert a DAG integer condition code to a SPARC ICC
489/// condition.
490static SPCC::CondCodes IntCondCCodeToICC(ISD::CondCode CC) {
491 switch (CC) {
492 default: assert(0 && "Unknown integer condition code!");
493 case ISD::SETEQ: return SPCC::ICC_E;
494 case ISD::SETNE: return SPCC::ICC_NE;
495 case ISD::SETLT: return SPCC::ICC_L;
496 case ISD::SETGT: return SPCC::ICC_G;
497 case ISD::SETLE: return SPCC::ICC_LE;
498 case ISD::SETGE: return SPCC::ICC_GE;
499 case ISD::SETULT: return SPCC::ICC_CS;
500 case ISD::SETULE: return SPCC::ICC_LEU;
501 case ISD::SETUGT: return SPCC::ICC_GU;
502 case ISD::SETUGE: return SPCC::ICC_CC;
503 }
504}
505
506/// FPCondCCodeToFCC - Convert a DAG floatingp oint condition code to a SPARC
507/// FCC condition.
508static SPCC::CondCodes FPCondCCodeToFCC(ISD::CondCode CC) {
509 switch (CC) {
510 default: assert(0 && "Unknown fp condition code!");
511 case ISD::SETEQ:
512 case ISD::SETOEQ: return SPCC::FCC_E;
513 case ISD::SETNE:
514 case ISD::SETUNE: return SPCC::FCC_NE;
515 case ISD::SETLT:
516 case ISD::SETOLT: return SPCC::FCC_L;
517 case ISD::SETGT:
518 case ISD::SETOGT: return SPCC::FCC_G;
519 case ISD::SETLE:
520 case ISD::SETOLE: return SPCC::FCC_LE;
521 case ISD::SETGE:
522 case ISD::SETOGE: return SPCC::FCC_GE;
523 case ISD::SETULT: return SPCC::FCC_UL;
524 case ISD::SETULE: return SPCC::FCC_ULE;
525 case ISD::SETUGT: return SPCC::FCC_UG;
526 case ISD::SETUGE: return SPCC::FCC_UGE;
527 case ISD::SETUO: return SPCC::FCC_U;
528 case ISD::SETO: return SPCC::FCC_O;
529 case ISD::SETONE: return SPCC::FCC_LG;
530 case ISD::SETUEQ: return SPCC::FCC_UE;
531 }
532}
533
534
535SparcTargetLowering::SparcTargetLowering(TargetMachine &TM)
536 : TargetLowering(TM) {
Anton Korobeynikov53835702008-10-10 20:27:31 +0000537
Chris Lattnerd23405e2008-03-17 03:21:36 +0000538 // Set up the register classes.
539 addRegisterClass(MVT::i32, SP::IntRegsRegisterClass);
540 addRegisterClass(MVT::f32, SP::FPRegsRegisterClass);
541 addRegisterClass(MVT::f64, SP::DFPRegsRegisterClass);
542
543 // Turn FP extload into load/fextend
Evan Cheng03294662008-10-14 21:26:46 +0000544 setLoadExtAction(ISD::EXTLOAD, MVT::f32, Expand);
Chris Lattnerd23405e2008-03-17 03:21:36 +0000545 // Sparc doesn't have i1 sign extending load
Evan Cheng03294662008-10-14 21:26:46 +0000546 setLoadExtAction(ISD::SEXTLOAD, MVT::i1, Promote);
Chris Lattnerd23405e2008-03-17 03:21:36 +0000547 // Turn FP truncstore into trunc + store.
548 setTruncStoreAction(MVT::f64, MVT::f32, Expand);
549
550 // Custom legalize GlobalAddress nodes into LO/HI parts.
551 setOperationAction(ISD::GlobalAddress, MVT::i32, Custom);
552 setOperationAction(ISD::GlobalTLSAddress, MVT::i32, Custom);
553 setOperationAction(ISD::ConstantPool , MVT::i32, Custom);
Anton Korobeynikov53835702008-10-10 20:27:31 +0000554
Chris Lattnerd23405e2008-03-17 03:21:36 +0000555 // Sparc doesn't have sext_inreg, replace them with shl/sra
556 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16, Expand);
557 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i8 , Expand);
558 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1 , Expand);
559
560 // Sparc has no REM or DIVREM operations.
561 setOperationAction(ISD::UREM, MVT::i32, Expand);
562 setOperationAction(ISD::SREM, MVT::i32, Expand);
563 setOperationAction(ISD::SDIVREM, MVT::i32, Expand);
564 setOperationAction(ISD::UDIVREM, MVT::i32, Expand);
565
566 // Custom expand fp<->sint
567 setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom);
568 setOperationAction(ISD::SINT_TO_FP, MVT::i32, Custom);
569
570 // Expand fp<->uint
571 setOperationAction(ISD::FP_TO_UINT, MVT::i32, Expand);
572 setOperationAction(ISD::UINT_TO_FP, MVT::i32, Expand);
Anton Korobeynikov53835702008-10-10 20:27:31 +0000573
Chris Lattnerd23405e2008-03-17 03:21:36 +0000574 setOperationAction(ISD::BIT_CONVERT, MVT::f32, Expand);
575 setOperationAction(ISD::BIT_CONVERT, MVT::i32, Expand);
Anton Korobeynikov53835702008-10-10 20:27:31 +0000576
Chris Lattnerd23405e2008-03-17 03:21:36 +0000577 // Sparc has no select or setcc: expand to SELECT_CC.
578 setOperationAction(ISD::SELECT, MVT::i32, Expand);
579 setOperationAction(ISD::SELECT, MVT::f32, Expand);
580 setOperationAction(ISD::SELECT, MVT::f64, Expand);
581 setOperationAction(ISD::SETCC, MVT::i32, Expand);
582 setOperationAction(ISD::SETCC, MVT::f32, Expand);
583 setOperationAction(ISD::SETCC, MVT::f64, Expand);
Anton Korobeynikov53835702008-10-10 20:27:31 +0000584
Chris Lattnerd23405e2008-03-17 03:21:36 +0000585 // Sparc doesn't have BRCOND either, it has BR_CC.
586 setOperationAction(ISD::BRCOND, MVT::Other, Expand);
587 setOperationAction(ISD::BRIND, MVT::Other, Expand);
588 setOperationAction(ISD::BR_JT, MVT::Other, Expand);
589 setOperationAction(ISD::BR_CC, MVT::i32, Custom);
590 setOperationAction(ISD::BR_CC, MVT::f32, Custom);
591 setOperationAction(ISD::BR_CC, MVT::f64, Custom);
Anton Korobeynikov53835702008-10-10 20:27:31 +0000592
Chris Lattnerd23405e2008-03-17 03:21:36 +0000593 setOperationAction(ISD::SELECT_CC, MVT::i32, Custom);
594 setOperationAction(ISD::SELECT_CC, MVT::f32, Custom);
595 setOperationAction(ISD::SELECT_CC, MVT::f64, Custom);
Anton Korobeynikov53835702008-10-10 20:27:31 +0000596
Chris Lattnerd23405e2008-03-17 03:21:36 +0000597 // SPARC has no intrinsics for these particular operations.
Chris Lattnerd23405e2008-03-17 03:21:36 +0000598 setOperationAction(ISD::MEMBARRIER, MVT::Other, Expand);
599
600 setOperationAction(ISD::FSIN , MVT::f64, Expand);
601 setOperationAction(ISD::FCOS , MVT::f64, Expand);
602 setOperationAction(ISD::FREM , MVT::f64, Expand);
603 setOperationAction(ISD::FSIN , MVT::f32, Expand);
604 setOperationAction(ISD::FCOS , MVT::f32, Expand);
605 setOperationAction(ISD::FREM , MVT::f32, Expand);
606 setOperationAction(ISD::CTPOP, MVT::i32, Expand);
607 setOperationAction(ISD::CTTZ , MVT::i32, Expand);
608 setOperationAction(ISD::CTLZ , MVT::i32, Expand);
609 setOperationAction(ISD::ROTL , MVT::i32, Expand);
610 setOperationAction(ISD::ROTR , MVT::i32, Expand);
611 setOperationAction(ISD::BSWAP, MVT::i32, Expand);
612 setOperationAction(ISD::FCOPYSIGN, MVT::f64, Expand);
613 setOperationAction(ISD::FCOPYSIGN, MVT::f32, Expand);
614 setOperationAction(ISD::FPOW , MVT::f64, Expand);
615 setOperationAction(ISD::FPOW , MVT::f32, Expand);
616
617 setOperationAction(ISD::SHL_PARTS, MVT::i32, Expand);
618 setOperationAction(ISD::SRA_PARTS, MVT::i32, Expand);
619 setOperationAction(ISD::SRL_PARTS, MVT::i32, Expand);
620
621 // FIXME: Sparc provides these multiplies, but we don't have them yet.
622 setOperationAction(ISD::UMUL_LOHI, MVT::i32, Expand);
Anton Korobeynikov4b58b6a2008-10-10 20:29:31 +0000623 setOperationAction(ISD::SMUL_LOHI, MVT::i32, Expand);
Anton Korobeynikov53835702008-10-10 20:27:31 +0000624
Chris Lattnerd23405e2008-03-17 03:21:36 +0000625 // We don't have line number support yet.
Dan Gohman7f460202008-06-30 20:59:49 +0000626 setOperationAction(ISD::DBG_STOPPOINT, MVT::Other, Expand);
Chris Lattnerd23405e2008-03-17 03:21:36 +0000627 setOperationAction(ISD::DEBUG_LOC, MVT::Other, Expand);
Dan Gohman44066042008-07-01 00:05:16 +0000628 setOperationAction(ISD::DBG_LABEL, MVT::Other, Expand);
629 setOperationAction(ISD::EH_LABEL, MVT::Other, Expand);
Chris Lattnerd23405e2008-03-17 03:21:36 +0000630
631 // RET must be custom lowered, to meet ABI requirements
632 setOperationAction(ISD::RET , MVT::Other, Custom);
633
634 // VASTART needs to be custom lowered to use the VarArgsFrameIndex.
635 setOperationAction(ISD::VASTART , MVT::Other, Custom);
636 // VAARG needs to be lowered to not do unaligned accesses for doubles.
637 setOperationAction(ISD::VAARG , MVT::Other, Custom);
Anton Korobeynikov53835702008-10-10 20:27:31 +0000638
Chris Lattnerd23405e2008-03-17 03:21:36 +0000639 // Use the default implementation.
640 setOperationAction(ISD::VACOPY , MVT::Other, Expand);
641 setOperationAction(ISD::VAEND , MVT::Other, Expand);
Anton Korobeynikov53835702008-10-10 20:27:31 +0000642 setOperationAction(ISD::STACKSAVE , MVT::Other, Expand);
Chris Lattnerd23405e2008-03-17 03:21:36 +0000643 setOperationAction(ISD::STACKRESTORE , MVT::Other, Expand);
644 setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32 , Custom);
645
646 // No debug info support yet.
Dan Gohman7f460202008-06-30 20:59:49 +0000647 setOperationAction(ISD::DBG_STOPPOINT, MVT::Other, Expand);
Dan Gohman44066042008-07-01 00:05:16 +0000648 setOperationAction(ISD::DBG_LABEL, MVT::Other, Expand);
649 setOperationAction(ISD::EH_LABEL, MVT::Other, Expand);
Chris Lattnerd23405e2008-03-17 03:21:36 +0000650 setOperationAction(ISD::DECLARE, MVT::Other, Expand);
Anton Korobeynikov53835702008-10-10 20:27:31 +0000651
Chris Lattnerd23405e2008-03-17 03:21:36 +0000652 setStackPointerRegisterToSaveRestore(SP::O6);
653
654 if (TM.getSubtarget<SparcSubtarget>().isV9())
655 setOperationAction(ISD::CTPOP, MVT::i32, Legal);
Anton Korobeynikov53835702008-10-10 20:27:31 +0000656
Chris Lattnerd23405e2008-03-17 03:21:36 +0000657 computeRegisterProperties();
658}
659
660const char *SparcTargetLowering::getTargetNodeName(unsigned Opcode) const {
661 switch (Opcode) {
662 default: return 0;
663 case SPISD::CMPICC: return "SPISD::CMPICC";
664 case SPISD::CMPFCC: return "SPISD::CMPFCC";
665 case SPISD::BRICC: return "SPISD::BRICC";
666 case SPISD::BRFCC: return "SPISD::BRFCC";
667 case SPISD::SELECT_ICC: return "SPISD::SELECT_ICC";
668 case SPISD::SELECT_FCC: return "SPISD::SELECT_FCC";
669 case SPISD::Hi: return "SPISD::Hi";
670 case SPISD::Lo: return "SPISD::Lo";
671 case SPISD::FTOI: return "SPISD::FTOI";
672 case SPISD::ITOF: return "SPISD::ITOF";
673 case SPISD::CALL: return "SPISD::CALL";
674 case SPISD::RET_FLAG: return "SPISD::RET_FLAG";
675 }
676}
677
678/// isMaskedValueZeroForTargetNode - Return true if 'Op & Mask' is known to
679/// be zero. Op is expected to be a target specific node. Used by DAG
680/// combiner.
Dan Gohman475871a2008-07-27 21:46:04 +0000681void SparcTargetLowering::computeMaskedBitsForTargetNode(const SDValue Op,
Chris Lattnerd23405e2008-03-17 03:21:36 +0000682 const APInt &Mask,
Anton Korobeynikov53835702008-10-10 20:27:31 +0000683 APInt &KnownZero,
Chris Lattnerd23405e2008-03-17 03:21:36 +0000684 APInt &KnownOne,
685 const SelectionDAG &DAG,
686 unsigned Depth) const {
687 APInt KnownZero2, KnownOne2;
688 KnownZero = KnownOne = APInt(Mask.getBitWidth(), 0); // Don't know anything.
Anton Korobeynikov53835702008-10-10 20:27:31 +0000689
Chris Lattnerd23405e2008-03-17 03:21:36 +0000690 switch (Op.getOpcode()) {
691 default: break;
692 case SPISD::SELECT_ICC:
693 case SPISD::SELECT_FCC:
694 DAG.ComputeMaskedBits(Op.getOperand(1), Mask, KnownZero, KnownOne,
695 Depth+1);
696 DAG.ComputeMaskedBits(Op.getOperand(0), Mask, KnownZero2, KnownOne2,
697 Depth+1);
Anton Korobeynikov53835702008-10-10 20:27:31 +0000698 assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?");
699 assert((KnownZero2 & KnownOne2) == 0 && "Bits known to be one AND zero?");
700
Chris Lattnerd23405e2008-03-17 03:21:36 +0000701 // Only known if known in both the LHS and RHS.
702 KnownOne &= KnownOne2;
703 KnownZero &= KnownZero2;
704 break;
705 }
706}
707
Chris Lattnerd23405e2008-03-17 03:21:36 +0000708// Look at LHS/RHS/CC and see if they are a lowered setcc instruction. If so
709// set LHS/RHS and SPCC to the LHS/RHS of the setcc and SPCC to the condition.
Dan Gohman475871a2008-07-27 21:46:04 +0000710static void LookThroughSetCC(SDValue &LHS, SDValue &RHS,
Chris Lattnerd23405e2008-03-17 03:21:36 +0000711 ISD::CondCode CC, unsigned &SPCC) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000712 if (isa<ConstantSDNode>(RHS) &&
713 cast<ConstantSDNode>(RHS)->getZExtValue() == 0 &&
Anton Korobeynikov53835702008-10-10 20:27:31 +0000714 CC == ISD::SETNE &&
Chris Lattnerd23405e2008-03-17 03:21:36 +0000715 ((LHS.getOpcode() == SPISD::SELECT_ICC &&
716 LHS.getOperand(3).getOpcode() == SPISD::CMPICC) ||
717 (LHS.getOpcode() == SPISD::SELECT_FCC &&
718 LHS.getOperand(3).getOpcode() == SPISD::CMPFCC)) &&
719 isa<ConstantSDNode>(LHS.getOperand(0)) &&
720 isa<ConstantSDNode>(LHS.getOperand(1)) &&
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000721 cast<ConstantSDNode>(LHS.getOperand(0))->getZExtValue() == 1 &&
722 cast<ConstantSDNode>(LHS.getOperand(1))->getZExtValue() == 0) {
Dan Gohman475871a2008-07-27 21:46:04 +0000723 SDValue CMPCC = LHS.getOperand(3);
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000724 SPCC = cast<ConstantSDNode>(LHS.getOperand(2))->getZExtValue();
Chris Lattnerd23405e2008-03-17 03:21:36 +0000725 LHS = CMPCC.getOperand(0);
726 RHS = CMPCC.getOperand(1);
727 }
728}
729
Dan Gohman475871a2008-07-27 21:46:04 +0000730static SDValue LowerGLOBALADDRESS(SDValue Op, SelectionDAG &DAG) {
Chris Lattnerd23405e2008-03-17 03:21:36 +0000731 GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
Dan Gohman475871a2008-07-27 21:46:04 +0000732 SDValue GA = DAG.getTargetGlobalAddress(GV, MVT::i32);
733 SDValue Hi = DAG.getNode(SPISD::Hi, MVT::i32, GA);
734 SDValue Lo = DAG.getNode(SPISD::Lo, MVT::i32, GA);
Chris Lattnerd23405e2008-03-17 03:21:36 +0000735 return DAG.getNode(ISD::ADD, MVT::i32, Lo, Hi);
736}
737
Dan Gohman475871a2008-07-27 21:46:04 +0000738static SDValue LowerCONSTANTPOOL(SDValue Op, SelectionDAG &DAG) {
Chris Lattnerd23405e2008-03-17 03:21:36 +0000739 ConstantPoolSDNode *N = cast<ConstantPoolSDNode>(Op);
740 Constant *C = N->getConstVal();
Dan Gohman475871a2008-07-27 21:46:04 +0000741 SDValue CP = DAG.getTargetConstantPool(C, MVT::i32, N->getAlignment());
742 SDValue Hi = DAG.getNode(SPISD::Hi, MVT::i32, CP);
743 SDValue Lo = DAG.getNode(SPISD::Lo, MVT::i32, CP);
Chris Lattnerd23405e2008-03-17 03:21:36 +0000744 return DAG.getNode(ISD::ADD, MVT::i32, Lo, Hi);
745}
746
Dan Gohman475871a2008-07-27 21:46:04 +0000747static SDValue LowerFP_TO_SINT(SDValue Op, SelectionDAG &DAG) {
Chris Lattnerd23405e2008-03-17 03:21:36 +0000748 // Convert the fp value to integer in an FP register.
749 assert(Op.getValueType() == MVT::i32);
750 Op = DAG.getNode(SPISD::FTOI, MVT::f32, Op.getOperand(0));
751 return DAG.getNode(ISD::BIT_CONVERT, MVT::i32, Op);
752}
753
Dan Gohman475871a2008-07-27 21:46:04 +0000754static SDValue LowerSINT_TO_FP(SDValue Op, SelectionDAG &DAG) {
Chris Lattnerd23405e2008-03-17 03:21:36 +0000755 assert(Op.getOperand(0).getValueType() == MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +0000756 SDValue Tmp = DAG.getNode(ISD::BIT_CONVERT, MVT::f32, Op.getOperand(0));
Chris Lattnerd23405e2008-03-17 03:21:36 +0000757 // Convert the int value to FP in an FP register.
758 return DAG.getNode(SPISD::ITOF, Op.getValueType(), Tmp);
759}
760
Dan Gohman475871a2008-07-27 21:46:04 +0000761static SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG) {
762 SDValue Chain = Op.getOperand(0);
Chris Lattnerd23405e2008-03-17 03:21:36 +0000763 ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get();
Dan Gohman475871a2008-07-27 21:46:04 +0000764 SDValue LHS = Op.getOperand(2);
765 SDValue RHS = Op.getOperand(3);
766 SDValue Dest = Op.getOperand(4);
Chris Lattnerd23405e2008-03-17 03:21:36 +0000767 unsigned Opc, SPCC = ~0U;
Anton Korobeynikov53835702008-10-10 20:27:31 +0000768
Chris Lattnerd23405e2008-03-17 03:21:36 +0000769 // If this is a br_cc of a "setcc", and if the setcc got lowered into
770 // an CMP[IF]CC/SELECT_[IF]CC pair, find the original compared values.
771 LookThroughSetCC(LHS, RHS, CC, SPCC);
Anton Korobeynikov53835702008-10-10 20:27:31 +0000772
Chris Lattnerd23405e2008-03-17 03:21:36 +0000773 // Get the condition flag.
Dan Gohman475871a2008-07-27 21:46:04 +0000774 SDValue CompareFlag;
Chris Lattnerd23405e2008-03-17 03:21:36 +0000775 if (LHS.getValueType() == MVT::i32) {
Duncan Sands83ec4b62008-06-06 12:08:01 +0000776 std::vector<MVT> VTs;
Chris Lattnerd23405e2008-03-17 03:21:36 +0000777 VTs.push_back(MVT::i32);
778 VTs.push_back(MVT::Flag);
Dan Gohman475871a2008-07-27 21:46:04 +0000779 SDValue Ops[2] = { LHS, RHS };
Chris Lattnerd23405e2008-03-17 03:21:36 +0000780 CompareFlag = DAG.getNode(SPISD::CMPICC, VTs, Ops, 2).getValue(1);
781 if (SPCC == ~0U) SPCC = IntCondCCodeToICC(CC);
782 Opc = SPISD::BRICC;
783 } else {
784 CompareFlag = DAG.getNode(SPISD::CMPFCC, MVT::Flag, LHS, RHS);
785 if (SPCC == ~0U) SPCC = FPCondCCodeToFCC(CC);
786 Opc = SPISD::BRFCC;
787 }
788 return DAG.getNode(Opc, MVT::Other, Chain, Dest,
789 DAG.getConstant(SPCC, MVT::i32), CompareFlag);
790}
791
Dan Gohman475871a2008-07-27 21:46:04 +0000792static SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) {
793 SDValue LHS = Op.getOperand(0);
794 SDValue RHS = Op.getOperand(1);
Chris Lattnerd23405e2008-03-17 03:21:36 +0000795 ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get();
Dan Gohman475871a2008-07-27 21:46:04 +0000796 SDValue TrueVal = Op.getOperand(2);
797 SDValue FalseVal = Op.getOperand(3);
Chris Lattnerd23405e2008-03-17 03:21:36 +0000798 unsigned Opc, SPCC = ~0U;
Anton Korobeynikov53835702008-10-10 20:27:31 +0000799
Chris Lattnerd23405e2008-03-17 03:21:36 +0000800 // If this is a select_cc of a "setcc", and if the setcc got lowered into
801 // an CMP[IF]CC/SELECT_[IF]CC pair, find the original compared values.
802 LookThroughSetCC(LHS, RHS, CC, SPCC);
Anton Korobeynikov53835702008-10-10 20:27:31 +0000803
Dan Gohman475871a2008-07-27 21:46:04 +0000804 SDValue CompareFlag;
Chris Lattnerd23405e2008-03-17 03:21:36 +0000805 if (LHS.getValueType() == MVT::i32) {
Duncan Sands83ec4b62008-06-06 12:08:01 +0000806 std::vector<MVT> VTs;
Chris Lattnerd23405e2008-03-17 03:21:36 +0000807 VTs.push_back(LHS.getValueType()); // subcc returns a value
808 VTs.push_back(MVT::Flag);
Dan Gohman475871a2008-07-27 21:46:04 +0000809 SDValue Ops[2] = { LHS, RHS };
Chris Lattnerd23405e2008-03-17 03:21:36 +0000810 CompareFlag = DAG.getNode(SPISD::CMPICC, VTs, Ops, 2).getValue(1);
811 Opc = SPISD::SELECT_ICC;
812 if (SPCC == ~0U) SPCC = IntCondCCodeToICC(CC);
813 } else {
814 CompareFlag = DAG.getNode(SPISD::CMPFCC, MVT::Flag, LHS, RHS);
815 Opc = SPISD::SELECT_FCC;
816 if (SPCC == ~0U) SPCC = FPCondCCodeToFCC(CC);
817 }
Anton Korobeynikov53835702008-10-10 20:27:31 +0000818 return DAG.getNode(Opc, TrueVal.getValueType(), TrueVal, FalseVal,
Chris Lattnerd23405e2008-03-17 03:21:36 +0000819 DAG.getConstant(SPCC, MVT::i32), CompareFlag);
820}
821
Dan Gohman475871a2008-07-27 21:46:04 +0000822static SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG,
Chris Lattnerd23405e2008-03-17 03:21:36 +0000823 SparcTargetLowering &TLI) {
824 // vastart just stores the address of the VarArgsFrameIndex slot into the
825 // memory location argument.
Dan Gohman475871a2008-07-27 21:46:04 +0000826 SDValue Offset = DAG.getNode(ISD::ADD, MVT::i32,
Chris Lattnerd23405e2008-03-17 03:21:36 +0000827 DAG.getRegister(SP::I6, MVT::i32),
828 DAG.getConstant(TLI.getVarArgsFrameOffset(),
829 MVT::i32));
830 const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue();
831 return DAG.getStore(Op.getOperand(0), Offset, Op.getOperand(1), SV, 0);
832}
833
Dan Gohman475871a2008-07-27 21:46:04 +0000834static SDValue LowerVAARG(SDValue Op, SelectionDAG &DAG) {
Gabor Greifba36cb52008-08-28 21:40:38 +0000835 SDNode *Node = Op.getNode();
Duncan Sands83ec4b62008-06-06 12:08:01 +0000836 MVT VT = Node->getValueType(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000837 SDValue InChain = Node->getOperand(0);
838 SDValue VAListPtr = Node->getOperand(1);
Chris Lattnerd23405e2008-03-17 03:21:36 +0000839 const Value *SV = cast<SrcValueSDNode>(Node->getOperand(2))->getValue();
Dan Gohman475871a2008-07-27 21:46:04 +0000840 SDValue VAList = DAG.getLoad(MVT::i32, InChain, VAListPtr, SV, 0);
Chris Lattnerd23405e2008-03-17 03:21:36 +0000841 // Increment the pointer, VAList, to the next vaarg
Anton Korobeynikov53835702008-10-10 20:27:31 +0000842 SDValue NextPtr = DAG.getNode(ISD::ADD, MVT::i32, VAList,
Duncan Sands83ec4b62008-06-06 12:08:01 +0000843 DAG.getConstant(VT.getSizeInBits()/8,
Chris Lattnerd23405e2008-03-17 03:21:36 +0000844 MVT::i32));
845 // Store the incremented VAList to the legalized pointer
846 InChain = DAG.getStore(VAList.getValue(1), NextPtr,
847 VAListPtr, SV, 0);
848 // Load the actual argument out of the pointer VAList, unless this is an
849 // f64 load.
850 if (VT != MVT::f64)
851 return DAG.getLoad(VT, InChain, VAList, NULL, 0);
Anton Korobeynikov53835702008-10-10 20:27:31 +0000852
Chris Lattnerd23405e2008-03-17 03:21:36 +0000853 // Otherwise, load it as i64, then do a bitconvert.
Dan Gohman475871a2008-07-27 21:46:04 +0000854 SDValue V = DAG.getLoad(MVT::i64, InChain, VAList, NULL, 0);
Anton Korobeynikov53835702008-10-10 20:27:31 +0000855
Chris Lattnerd23405e2008-03-17 03:21:36 +0000856 // Bit-Convert the value to f64.
Dan Gohman475871a2008-07-27 21:46:04 +0000857 SDValue Ops[2] = {
Chris Lattnerd23405e2008-03-17 03:21:36 +0000858 DAG.getNode(ISD::BIT_CONVERT, MVT::f64, V),
859 V.getValue(1)
860 };
Duncan Sands4bdcb612008-07-02 17:40:58 +0000861 return DAG.getMergeValues(Ops, 2);
Chris Lattnerd23405e2008-03-17 03:21:36 +0000862}
863
Dan Gohman475871a2008-07-27 21:46:04 +0000864static SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) {
865 SDValue Chain = Op.getOperand(0); // Legalize the chain.
866 SDValue Size = Op.getOperand(1); // Legalize the size.
Anton Korobeynikov53835702008-10-10 20:27:31 +0000867
Chris Lattnerd23405e2008-03-17 03:21:36 +0000868 unsigned SPReg = SP::O6;
Dan Gohman475871a2008-07-27 21:46:04 +0000869 SDValue SP = DAG.getCopyFromReg(Chain, SPReg, MVT::i32);
870 SDValue NewSP = DAG.getNode(ISD::SUB, MVT::i32, SP, Size); // Value
Chris Lattnerd23405e2008-03-17 03:21:36 +0000871 Chain = DAG.getCopyToReg(SP.getValue(1), SPReg, NewSP); // Output chain
Anton Korobeynikov53835702008-10-10 20:27:31 +0000872
Chris Lattnerd23405e2008-03-17 03:21:36 +0000873 // The resultant pointer is actually 16 words from the bottom of the stack,
874 // to provide a register spill area.
Dan Gohman475871a2008-07-27 21:46:04 +0000875 SDValue NewVal = DAG.getNode(ISD::ADD, MVT::i32, NewSP,
Chris Lattnerd23405e2008-03-17 03:21:36 +0000876 DAG.getConstant(96, MVT::i32));
Dan Gohman475871a2008-07-27 21:46:04 +0000877 SDValue Ops[2] = { NewVal, Chain };
Duncan Sands4bdcb612008-07-02 17:40:58 +0000878 return DAG.getMergeValues(Ops, 2);
Chris Lattnerd23405e2008-03-17 03:21:36 +0000879}
880
Chris Lattnerd23405e2008-03-17 03:21:36 +0000881
Dan Gohman475871a2008-07-27 21:46:04 +0000882SDValue SparcTargetLowering::
883LowerOperation(SDValue Op, SelectionDAG &DAG) {
Chris Lattnerd23405e2008-03-17 03:21:36 +0000884 switch (Op.getOpcode()) {
885 default: assert(0 && "Should not custom lower this!");
886 // Frame & Return address. Currently unimplemented
Dan Gohman475871a2008-07-27 21:46:04 +0000887 case ISD::RETURNADDR: return SDValue();
888 case ISD::FRAMEADDR: return SDValue();
Chris Lattnerd23405e2008-03-17 03:21:36 +0000889 case ISD::GlobalTLSAddress:
890 assert(0 && "TLS not implemented for Sparc.");
891 case ISD::GlobalAddress: return LowerGLOBALADDRESS(Op, DAG);
892 case ISD::ConstantPool: return LowerCONSTANTPOOL(Op, DAG);
893 case ISD::FP_TO_SINT: return LowerFP_TO_SINT(Op, DAG);
894 case ISD::SINT_TO_FP: return LowerSINT_TO_FP(Op, DAG);
895 case ISD::BR_CC: return LowerBR_CC(Op, DAG);
896 case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG);
897 case ISD::VASTART: return LowerVASTART(Op, DAG, *this);
898 case ISD::VAARG: return LowerVAARG(Op, DAG);
899 case ISD::DYNAMIC_STACKALLOC: return LowerDYNAMIC_STACKALLOC(Op, DAG);
Chris Lattner98949a62008-03-17 06:01:07 +0000900 case ISD::CALL: return LowerCALL(Op, DAG);
Chris Lattnerd23405e2008-03-17 03:21:36 +0000901 case ISD::RET: return LowerRET(Op, DAG);
902 }
903}
904
905MachineBasicBlock *
906SparcTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
907 MachineBasicBlock *BB) {
908 const TargetInstrInfo &TII = *getTargetMachine().getInstrInfo();
909 unsigned BROpcode;
910 unsigned CC;
911 // Figure out the conditional branch opcode to use for this select_cc.
912 switch (MI->getOpcode()) {
913 default: assert(0 && "Unknown SELECT_CC!");
914 case SP::SELECT_CC_Int_ICC:
915 case SP::SELECT_CC_FP_ICC:
916 case SP::SELECT_CC_DFP_ICC:
917 BROpcode = SP::BCOND;
918 break;
919 case SP::SELECT_CC_Int_FCC:
920 case SP::SELECT_CC_FP_FCC:
921 case SP::SELECT_CC_DFP_FCC:
922 BROpcode = SP::FBCOND;
923 break;
924 }
925
926 CC = (SPCC::CondCodes)MI->getOperand(3).getImm();
Anton Korobeynikov53835702008-10-10 20:27:31 +0000927
Chris Lattnerd23405e2008-03-17 03:21:36 +0000928 // To "insert" a SELECT_CC instruction, we actually have to insert the diamond
929 // control-flow pattern. The incoming instruction knows the destination vreg
930 // to set, the condition code register to branch on, the true/false values to
931 // select between, and a branch opcode to use.
932 const BasicBlock *LLVM_BB = BB->getBasicBlock();
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000933 MachineFunction::iterator It = BB;
Chris Lattnerd23405e2008-03-17 03:21:36 +0000934 ++It;
Anton Korobeynikov53835702008-10-10 20:27:31 +0000935
Chris Lattnerd23405e2008-03-17 03:21:36 +0000936 // thisMBB:
937 // ...
938 // TrueVal = ...
939 // [f]bCC copy1MBB
940 // fallthrough --> copy0MBB
941 MachineBasicBlock *thisMBB = BB;
Chris Lattnerd23405e2008-03-17 03:21:36 +0000942 MachineFunction *F = BB->getParent();
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000943 MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB);
944 MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB);
945 BuildMI(BB, TII.get(BROpcode)).addMBB(sinkMBB).addImm(CC);
946 F->insert(It, copy0MBB);
947 F->insert(It, sinkMBB);
Dan Gohman0011dc42008-06-21 20:21:19 +0000948 // Update machine-CFG edges by transferring all successors of the current
Chris Lattnerd23405e2008-03-17 03:21:36 +0000949 // block to the new block which will contain the Phi node for the select.
Dan Gohman0011dc42008-06-21 20:21:19 +0000950 sinkMBB->transferSuccessors(BB);
951 // Next, add the true and fallthrough blocks as its successors.
Chris Lattnerd23405e2008-03-17 03:21:36 +0000952 BB->addSuccessor(copy0MBB);
953 BB->addSuccessor(sinkMBB);
Anton Korobeynikov53835702008-10-10 20:27:31 +0000954
Chris Lattnerd23405e2008-03-17 03:21:36 +0000955 // copy0MBB:
956 // %FalseValue = ...
957 // # fallthrough to sinkMBB
958 BB = copy0MBB;
Anton Korobeynikov53835702008-10-10 20:27:31 +0000959
Chris Lattnerd23405e2008-03-17 03:21:36 +0000960 // Update machine-CFG edges
961 BB->addSuccessor(sinkMBB);
Anton Korobeynikov53835702008-10-10 20:27:31 +0000962
Chris Lattnerd23405e2008-03-17 03:21:36 +0000963 // sinkMBB:
964 // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ]
965 // ...
966 BB = sinkMBB;
967 BuildMI(BB, TII.get(SP::PHI), MI->getOperand(0).getReg())
968 .addReg(MI->getOperand(2).getReg()).addMBB(copy0MBB)
969 .addReg(MI->getOperand(1).getReg()).addMBB(thisMBB);
Anton Korobeynikov53835702008-10-10 20:27:31 +0000970
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000971 F->DeleteMachineInstr(MI); // The pseudo instruction is gone now.
Chris Lattnerd23405e2008-03-17 03:21:36 +0000972 return BB;
973}
Anton Korobeynikov0eefda12008-10-10 20:28:10 +0000974
975//===----------------------------------------------------------------------===//
976// Sparc Inline Assembly Support
977//===----------------------------------------------------------------------===//
978
979/// getConstraintType - Given a constraint letter, return the type of
980/// constraint it is for this target.
981SparcTargetLowering::ConstraintType
982SparcTargetLowering::getConstraintType(const std::string &Constraint) const {
983 if (Constraint.size() == 1) {
984 switch (Constraint[0]) {
985 default: break;
986 case 'r': return C_RegisterClass;
987 }
988 }
989
990 return TargetLowering::getConstraintType(Constraint);
991}
992
993std::pair<unsigned, const TargetRegisterClass*>
994SparcTargetLowering::getRegForInlineAsmConstraint(const std::string &Constraint,
995 MVT VT) const {
996 if (Constraint.size() == 1) {
997 switch (Constraint[0]) {
998 case 'r':
999 return std::make_pair(0U, SP::IntRegsRegisterClass);
1000 }
1001 }
1002
1003 return TargetLowering::getRegForInlineAsmConstraint(Constraint, VT);
1004}
1005
1006std::vector<unsigned> SparcTargetLowering::
1007getRegClassForInlineAsmConstraint(const std::string &Constraint,
1008 MVT VT) const {
1009 if (Constraint.size() != 1)
1010 return std::vector<unsigned>();
1011
1012 switch (Constraint[0]) {
1013 default: break;
1014 case 'r':
1015 return make_vector<unsigned>(SP::L0, SP::L1, SP::L2, SP::L3,
1016 SP::L4, SP::L5, SP::L6, SP::L7,
1017 SP::I0, SP::I1, SP::I2, SP::I3,
1018 SP::I4, SP::I5,
1019 SP::O0, SP::O1, SP::O2, SP::O3,
1020 SP::O4, SP::O5, SP::O7, 0);
1021 }
1022
1023 return std::vector<unsigned>();
1024}
Dan Gohman6520e202008-10-18 02:06:02 +00001025
1026bool
1027SparcTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const {
1028 // The Sparc target isn't yet aware of offsets.
1029 return false;
1030}