blob: b0d5be3e78e0208fdf8d3bd09073691a3e5e1f16 [file] [log] [blame]
Andrew Lenharthaa38ce42005-09-02 18:46:02 +00001//===-- AlphaISelLowering.cpp - Alpha DAG Lowering Implementation ---------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Andrew Lenharth and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the AlphaISelLowering class.
11//
12//===----------------------------------------------------------------------===//
13
14#include "AlphaISelLowering.h"
15#include "AlphaTargetMachine.h"
16#include "llvm/CodeGen/MachineFrameInfo.h"
17#include "llvm/CodeGen/MachineFunction.h"
18#include "llvm/CodeGen/MachineInstrBuilder.h"
19#include "llvm/CodeGen/SelectionDAG.h"
20#include "llvm/CodeGen/SSARegMap.h"
21#include "llvm/Constants.h"
22#include "llvm/Function.h"
Andrew Lenharth167bc6e2006-01-23 20:59:50 +000023#include "llvm/Module.h"
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000024#include "llvm/Support/CommandLine.h"
25#include <iostream>
26
27using namespace llvm;
28
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000029/// AddLiveIn - This helper function adds the specified physical register to the
30/// MachineFunction as a live in value. It also creates a corresponding virtual
31/// register for it.
32static unsigned AddLiveIn(MachineFunction &MF, unsigned PReg,
33 TargetRegisterClass *RC) {
34 assert(RC->contains(PReg) && "Not the correct regclass!");
35 unsigned VReg = MF.getSSARegMap()->createVirtualRegister(RC);
36 MF.addLiveIn(PReg, VReg);
37 return VReg;
38}
39
40AlphaTargetLowering::AlphaTargetLowering(TargetMachine &TM) : TargetLowering(TM) {
41 // Set up the TargetLowering object.
42 //I am having problems with shr n ubyte 1
43 setShiftAmountType(MVT::i64);
44 setSetCCResultType(MVT::i64);
45 setSetCCResultContents(ZeroOrOneSetCCResult);
46
47 addRegisterClass(MVT::i64, Alpha::GPRCRegisterClass);
Andrew Lenharth5cefc5e2005-11-09 19:17:08 +000048 addRegisterClass(MVT::f64, Alpha::F8RCRegisterClass);
49 addRegisterClass(MVT::f32, Alpha::F4RCRegisterClass);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000050
Nate Begeman750ac1b2006-02-01 07:19:44 +000051 setOperationAction(ISD::BR_CC, MVT::Other, Expand);
52 setOperationAction(ISD::SELECT_CC, MVT::Other, Expand);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000053
54 setOperationAction(ISD::EXTLOAD, MVT::i1, Promote);
55 setOperationAction(ISD::EXTLOAD, MVT::f32, Expand);
56
57 setOperationAction(ISD::ZEXTLOAD, MVT::i1, Promote);
58 setOperationAction(ISD::ZEXTLOAD, MVT::i32, Expand);
59
60 setOperationAction(ISD::SEXTLOAD, MVT::i1, Promote);
61 setOperationAction(ISD::SEXTLOAD, MVT::i8, Expand);
62 setOperationAction(ISD::SEXTLOAD, MVT::i16, Expand);
63
Andrew Lenharthf3fb71b2005-10-06 16:54:29 +000064 setOperationAction(ISD::TRUNCSTORE, MVT::i1, Promote);
65
Chris Lattner3e2bafd2005-09-28 22:29:17 +000066 setOperationAction(ISD::FREM, MVT::f32, Expand);
67 setOperationAction(ISD::FREM, MVT::f64, Expand);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000068
69 setOperationAction(ISD::UINT_TO_FP, MVT::i64, Expand);
Andrew Lenharth7f0db912005-11-30 07:19:56 +000070 setOperationAction(ISD::SINT_TO_FP, MVT::i64, Custom);
Andrew Lenharthcd804962005-11-30 16:10:29 +000071 setOperationAction(ISD::FP_TO_UINT, MVT::i64, Expand);
72 setOperationAction(ISD::FP_TO_SINT, MVT::i64, Custom);
73
Andrew Lenharth120ab482005-09-29 22:54:56 +000074 if (!TM.getSubtarget<AlphaSubtarget>().hasCT()) {
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000075 setOperationAction(ISD::CTPOP , MVT::i64 , Expand);
76 setOperationAction(ISD::CTTZ , MVT::i64 , Expand);
77 setOperationAction(ISD::CTLZ , MVT::i64 , Expand);
78 }
Nate Begemand88fc032006-01-14 03:14:10 +000079 setOperationAction(ISD::BSWAP , MVT::i64, Expand);
Nate Begeman35ef9132006-01-11 21:21:00 +000080 setOperationAction(ISD::ROTL , MVT::i64, Expand);
81 setOperationAction(ISD::ROTR , MVT::i64, Expand);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000082
Andrew Lenharth53d89702005-12-25 01:34:27 +000083 setOperationAction(ISD::SREM , MVT::i64, Custom);
84 setOperationAction(ISD::UREM , MVT::i64, Custom);
85 setOperationAction(ISD::SDIV , MVT::i64, Custom);
86 setOperationAction(ISD::UDIV , MVT::i64, Custom);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000087
88 setOperationAction(ISD::MEMMOVE , MVT::Other, Expand);
89 setOperationAction(ISD::MEMSET , MVT::Other, Expand);
90 setOperationAction(ISD::MEMCPY , MVT::Other, Expand);
91
92 // We don't support sin/cos/sqrt
93 setOperationAction(ISD::FSIN , MVT::f64, Expand);
94 setOperationAction(ISD::FCOS , MVT::f64, Expand);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000095 setOperationAction(ISD::FSIN , MVT::f32, Expand);
96 setOperationAction(ISD::FCOS , MVT::f32, Expand);
Andrew Lenharth39424472006-01-19 21:10:38 +000097
98 setOperationAction(ISD::FSQRT, MVT::f64, Expand);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000099 setOperationAction(ISD::FSQRT, MVT::f32, Expand);
Chris Lattner9601a862006-03-05 05:08:37 +0000100
101 // FIXME: Alpha supports fcopysign natively!?
102 setOperationAction(ISD::FCOPYSIGN, MVT::f64, Expand);
103 setOperationAction(ISD::FCOPYSIGN, MVT::f32, Expand);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000104
Andrew Lenharthb2156f92005-11-30 17:11:20 +0000105 setOperationAction(ISD::SETCC, MVT::f32, Promote);
Chris Lattnerf73bae12005-11-29 06:16:21 +0000106
107 // We don't have line number support yet.
108 setOperationAction(ISD::LOCATION, MVT::Other, Expand);
Jim Laskeye0bce712006-01-05 01:47:43 +0000109 setOperationAction(ISD::DEBUG_LOC, MVT::Other, Expand);
110 setOperationAction(ISD::DEBUG_LABEL, MVT::Other, Expand);
Chris Lattnerb99329e2006-01-13 02:42:53 +0000111
112 // Not implemented yet.
113 setOperationAction(ISD::STACKSAVE, MVT::Other, Expand);
114 setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand);
Andrew Lenharth739027e2006-01-16 21:22:38 +0000115 setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i64, Expand);
116
Andrew Lenharth53d89702005-12-25 01:34:27 +0000117 // We want to legalize GlobalAddress and ConstantPool and
118 // ExternalSymbols nodes into the appropriate instructions to
119 // materialize the address.
120 setOperationAction(ISD::GlobalAddress, MVT::i64, Custom);
121 setOperationAction(ISD::ConstantPool, MVT::i64, Custom);
122 setOperationAction(ISD::ExternalSymbol, MVT::i64, Custom);
Andrew Lenharth4e629512005-12-24 05:36:33 +0000123
Andrew Lenharth0e538792006-01-25 21:54:38 +0000124 setOperationAction(ISD::VASTART, MVT::Other, Custom);
Andrew Lenharth677c4f22006-01-25 23:33:32 +0000125 setOperationAction(ISD::VAEND, MVT::Other, Expand);
Andrew Lenharth0e538792006-01-25 21:54:38 +0000126 setOperationAction(ISD::VACOPY, MVT::Other, Custom);
Andrew Lenharth5f8f0e22006-01-25 22:28:07 +0000127 setOperationAction(ISD::VAARG, MVT::Other, Custom);
Nate Begeman0aed7842006-01-28 03:14:31 +0000128 setOperationAction(ISD::VAARG, MVT::i32, Custom);
Andrew Lenharth0e538792006-01-25 21:54:38 +0000129
Andrew Lenharth739027e2006-01-16 21:22:38 +0000130 setStackPointerRegisterToSaveRestore(Alpha::R30);
131
Chris Lattner08a90222006-01-29 06:25:22 +0000132 setOperationAction(ISD::ConstantFP, MVT::f64, Expand);
133 setOperationAction(ISD::ConstantFP, MVT::f32, Expand);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000134 addLegalFPImmediate(+0.0); //F31
135 addLegalFPImmediate(-0.0); //-F31
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000136
137 computeRegisterProperties();
138
139 useITOF = TM.getSubtarget<AlphaSubtarget>().hasF2I();
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000140}
141
Andrew Lenharth84a06052006-01-16 19:53:25 +0000142const char *AlphaTargetLowering::getTargetNodeName(unsigned Opcode) const {
143 switch (Opcode) {
144 default: return 0;
145 case AlphaISD::ITOFT_: return "Alpha::ITOFT_";
146 case AlphaISD::FTOIT_: return "Alpha::FTOIT_";
147 case AlphaISD::CVTQT_: return "Alpha::CVTQT_";
148 case AlphaISD::CVTQS_: return "Alpha::CVTQS_";
149 case AlphaISD::CVTTQ_: return "Alpha::CVTTQ_";
150 case AlphaISD::GPRelHi: return "Alpha::GPRelHi";
151 case AlphaISD::GPRelLo: return "Alpha::GPRelLo";
152 case AlphaISD::RelLit: return "Alpha::RelLit";
153 case AlphaISD::GlobalBaseReg: return "Alpha::GlobalBaseReg";
Chris Lattner2d90bd52006-01-27 23:39:00 +0000154 case AlphaISD::CALL: return "Alpha::CALL";
Andrew Lenharth84a06052006-01-16 19:53:25 +0000155 case AlphaISD::DivCall: return "Alpha::DivCall";
156 }
157}
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000158
159//http://www.cs.arizona.edu/computer.help/policy/DIGITAL_unix/AA-PY8AC-TET1_html/callCH3.html#BLOCK21
160
161//For now, just use variable size stack frame format
162
163//In a standard call, the first six items are passed in registers $16
164//- $21 and/or registers $f16 - $f21. (See Section 4.1.2 for details
165//of argument-to-register correspondence.) The remaining items are
166//collected in a memory argument list that is a naturally aligned
167//array of quadwords. In a standard call, this list, if present, must
168//be passed at 0(SP).
169//7 ... n 0(SP) ... (n-7)*8(SP)
170
171// //#define FP $15
172// //#define RA $26
173// //#define PV $27
174// //#define GP $29
175// //#define SP $30
176
177std::vector<SDOperand>
178AlphaTargetLowering::LowerArguments(Function &F, SelectionDAG &DAG)
179{
180 MachineFunction &MF = DAG.getMachineFunction();
181 MachineFrameInfo *MFI = MF.getFrameInfo();
182 MachineBasicBlock& BB = MF.front();
183 std::vector<SDOperand> ArgValues;
184
Andrew Lenharthf71df332005-09-04 06:12:19 +0000185 unsigned args_int[] = {
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000186 Alpha::R16, Alpha::R17, Alpha::R18, Alpha::R19, Alpha::R20, Alpha::R21};
Andrew Lenharthf71df332005-09-04 06:12:19 +0000187 unsigned args_float[] = {
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000188 Alpha::F16, Alpha::F17, Alpha::F18, Alpha::F19, Alpha::F20, Alpha::F21};
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000189
190 int count = 0;
191
192 GP = AddLiveIn(MF, Alpha::R29, getRegClassFor(MVT::i64));
193 RA = AddLiveIn(MF, Alpha::R26, getRegClassFor(MVT::i64));
194
195 for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I)
196 {
197 SDOperand argt;
198 if (count < 6) {
199 unsigned Vreg;
200 MVT::ValueType VT = getValueType(I->getType());
201 switch (VT) {
202 default:
203 std::cerr << "Unknown Type " << VT << "\n";
204 abort();
205 case MVT::f64:
206 case MVT::f32:
Andrew Lenharthf71df332005-09-04 06:12:19 +0000207 args_float[count] = AddLiveIn(MF, args_float[count], getRegClassFor(VT));
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000208 argt = DAG.getCopyFromReg(DAG.getRoot(), args_float[count], VT);
209 DAG.setRoot(argt.getValue(1));
210 break;
211 case MVT::i1:
212 case MVT::i8:
213 case MVT::i16:
214 case MVT::i32:
215 case MVT::i64:
Andrew Lenharthf71df332005-09-04 06:12:19 +0000216 args_int[count] = AddLiveIn(MF, args_int[count], getRegClassFor(MVT::i64));
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000217 argt = DAG.getCopyFromReg(DAG.getRoot(), args_int[count], MVT::i64);
218 DAG.setRoot(argt.getValue(1));
219 if (VT != MVT::i64) {
220 unsigned AssertOp =
221 I->getType()->isSigned() ? ISD::AssertSext : ISD::AssertZext;
222 argt = DAG.getNode(AssertOp, MVT::i64, argt,
223 DAG.getValueType(VT));
224 argt = DAG.getNode(ISD::TRUNCATE, VT, argt);
225 }
226 break;
227 }
228 } else { //more args
229 // Create the frame index object for this incoming parameter...
230 int FI = MFI->CreateFixedObject(8, 8 * (count - 6));
231
232 // Create the SelectionDAG nodes corresponding to a load
233 //from this parameter
234 SDOperand FIN = DAG.getFrameIndex(FI, MVT::i64);
235 argt = DAG.getLoad(getValueType(I->getType()),
236 DAG.getEntryNode(), FIN, DAG.getSrcValue(NULL));
237 }
238 ++count;
239 ArgValues.push_back(argt);
240 }
241
242 // If the functions takes variable number of arguments, copy all regs to stack
243 if (F.isVarArg()) {
244 VarArgsOffset = count * 8;
245 std::vector<SDOperand> LS;
246 for (int i = 0; i < 6; ++i) {
Chris Lattnerf2cded72005-09-13 19:03:13 +0000247 if (MRegisterInfo::isPhysicalRegister(args_int[i]))
Andrew Lenharthf71df332005-09-04 06:12:19 +0000248 args_int[i] = AddLiveIn(MF, args_int[i], getRegClassFor(MVT::i64));
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000249 SDOperand argt = DAG.getCopyFromReg(DAG.getRoot(), args_int[i], MVT::i64);
250 int FI = MFI->CreateFixedObject(8, -8 * (6 - i));
251 if (i == 0) VarArgsBase = FI;
252 SDOperand SDFI = DAG.getFrameIndex(FI, MVT::i64);
253 LS.push_back(DAG.getNode(ISD::STORE, MVT::Other, DAG.getRoot(), argt,
254 SDFI, DAG.getSrcValue(NULL)));
255
Chris Lattnerf2cded72005-09-13 19:03:13 +0000256 if (MRegisterInfo::isPhysicalRegister(args_float[i]))
Andrew Lenharthf71df332005-09-04 06:12:19 +0000257 args_float[i] = AddLiveIn(MF, args_float[i], getRegClassFor(MVT::f64));
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000258 argt = DAG.getCopyFromReg(DAG.getRoot(), args_float[i], MVT::f64);
259 FI = MFI->CreateFixedObject(8, - 8 * (12 - i));
260 SDFI = DAG.getFrameIndex(FI, MVT::i64);
261 LS.push_back(DAG.getNode(ISD::STORE, MVT::Other, DAG.getRoot(), argt,
262 SDFI, DAG.getSrcValue(NULL)));
263 }
264
265 //Set up a token factor with all the stack traffic
266 DAG.setRoot(DAG.getNode(ISD::TokenFactor, MVT::Other, LS));
267 }
268
269 // Finally, inform the code generator which regs we return values in.
270 switch (getValueType(F.getReturnType())) {
271 default: assert(0 && "Unknown type!");
272 case MVT::isVoid: break;
273 case MVT::i1:
274 case MVT::i8:
275 case MVT::i16:
276 case MVT::i32:
277 case MVT::i64:
278 MF.addLiveOut(Alpha::R0);
279 break;
280 case MVT::f32:
281 case MVT::f64:
282 MF.addLiveOut(Alpha::F0);
283 break;
284 }
285
286 //return the arguments
287 return ArgValues;
288}
289
290std::pair<SDOperand, SDOperand>
291AlphaTargetLowering::LowerCallTo(SDOperand Chain,
292 const Type *RetTy, bool isVarArg,
293 unsigned CallingConv, bool isTailCall,
294 SDOperand Callee, ArgListTy &Args,
295 SelectionDAG &DAG) {
296 int NumBytes = 0;
297 if (Args.size() > 6)
298 NumBytes = (Args.size() - 6) * 8;
299
Chris Lattner94dd2922006-02-13 09:00:43 +0000300 Chain = DAG.getCALLSEQ_START(Chain,
301 DAG.getConstant(NumBytes, getPointerTy()));
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000302 std::vector<SDOperand> args_to_use;
303 for (unsigned i = 0, e = Args.size(); i != e; ++i)
304 {
305 switch (getValueType(Args[i].second)) {
306 default: assert(0 && "Unexpected ValueType for argument!");
307 case MVT::i1:
308 case MVT::i8:
309 case MVT::i16:
310 case MVT::i32:
311 // Promote the integer to 64 bits. If the input type is signed use a
312 // sign extend, otherwise use a zero extend.
313 if (Args[i].second->isSigned())
314 Args[i].first = DAG.getNode(ISD::SIGN_EXTEND, MVT::i64, Args[i].first);
315 else
316 Args[i].first = DAG.getNode(ISD::ZERO_EXTEND, MVT::i64, Args[i].first);
317 break;
318 case MVT::i64:
319 case MVT::f64:
320 case MVT::f32:
321 break;
322 }
323 args_to_use.push_back(Args[i].first);
324 }
325
326 std::vector<MVT::ValueType> RetVals;
327 MVT::ValueType RetTyVT = getValueType(RetTy);
Andrew Lenharth46a776e2005-09-06 17:00:23 +0000328 MVT::ValueType ActualRetTyVT = RetTyVT;
329 if (RetTyVT >= MVT::i1 && RetTyVT <= MVT::i32)
330 ActualRetTyVT = MVT::i64;
331
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000332 if (RetTyVT != MVT::isVoid)
Andrew Lenharth46a776e2005-09-06 17:00:23 +0000333 RetVals.push_back(ActualRetTyVT);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000334 RetVals.push_back(MVT::Other);
335
Chris Lattner2d90bd52006-01-27 23:39:00 +0000336 std::vector<SDOperand> Ops;
337 Ops.push_back(Chain);
338 Ops.push_back(Callee);
339 Ops.insert(Ops.end(), args_to_use.begin(), args_to_use.end());
340 SDOperand TheCall = DAG.getNode(AlphaISD::CALL, RetVals, Ops);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000341 Chain = TheCall.getValue(RetTyVT != MVT::isVoid);
342 Chain = DAG.getNode(ISD::CALLSEQ_END, MVT::Other, Chain,
343 DAG.getConstant(NumBytes, getPointerTy()));
Andrew Lenharth46a776e2005-09-06 17:00:23 +0000344 SDOperand RetVal = TheCall;
345
346 if (RetTyVT != ActualRetTyVT) {
347 RetVal = DAG.getNode(RetTy->isSigned() ? ISD::AssertSext : ISD::AssertZext,
348 MVT::i64, RetVal, DAG.getValueType(RetTyVT));
349 RetVal = DAG.getNode(ISD::TRUNCATE, RetTyVT, RetVal);
350 }
351
352 return std::make_pair(RetVal, Chain);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000353}
354
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000355void AlphaTargetLowering::restoreGP(MachineBasicBlock* BB)
356{
357 BuildMI(BB, Alpha::BIS, 2, Alpha::R29).addReg(GP).addReg(GP);
358}
359void AlphaTargetLowering::restoreRA(MachineBasicBlock* BB)
360{
361 BuildMI(BB, Alpha::BIS, 2, Alpha::R26).addReg(RA).addReg(RA);
362}
363
Andrew Lenharth167bc6e2006-01-23 20:59:50 +0000364static int getUID()
365{
366 static int id = 0;
367 return ++id;
368}
369
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000370/// LowerOperation - Provide custom lowering hooks for some operations.
371///
372SDOperand AlphaTargetLowering::LowerOperation(SDOperand Op, SelectionDAG &DAG) {
373 switch (Op.getOpcode()) {
374 default: assert(0 && "Wasn't expecting to be able to lower this!");
375 case ISD::SINT_TO_FP: {
376 assert(MVT::i64 == Op.getOperand(0).getValueType() &&
377 "Unhandled SINT_TO_FP type in custom expander!");
378 SDOperand LD;
379 bool isDouble = MVT::f64 == Op.getValueType();
380 if (useITOF) {
381 LD = DAG.getNode(AlphaISD::ITOFT_, MVT::f64, Op.getOperand(0));
382 } else {
383 int FrameIdx =
384 DAG.getMachineFunction().getFrameInfo()->CreateStackObject(8, 8);
385 SDOperand FI = DAG.getFrameIndex(FrameIdx, MVT::i64);
386 SDOperand ST = DAG.getNode(ISD::STORE, MVT::Other, DAG.getEntryNode(),
387 Op.getOperand(0), FI, DAG.getSrcValue(0));
388 LD = DAG.getLoad(MVT::f64, ST, FI, DAG.getSrcValue(0));
389 }
390 SDOperand FP = DAG.getNode(isDouble?AlphaISD::CVTQT_:AlphaISD::CVTQS_,
391 isDouble?MVT::f64:MVT::f32, LD);
392 return FP;
393 }
Andrew Lenharthcd804962005-11-30 16:10:29 +0000394 case ISD::FP_TO_SINT: {
395 bool isDouble = MVT::f64 == Op.getOperand(0).getValueType();
396 SDOperand src = Op.getOperand(0);
397
398 if (!isDouble) //Promote
399 src = DAG.getNode(ISD::FP_EXTEND, MVT::f64, src);
400
401 src = DAG.getNode(AlphaISD::CVTTQ_, MVT::f64, src);
402
403 if (useITOF) {
404 return DAG.getNode(AlphaISD::FTOIT_, MVT::i64, src);
405 } else {
406 int FrameIdx =
407 DAG.getMachineFunction().getFrameInfo()->CreateStackObject(8, 8);
408 SDOperand FI = DAG.getFrameIndex(FrameIdx, MVT::i64);
409 SDOperand ST = DAG.getNode(ISD::STORE, MVT::Other, DAG.getEntryNode(),
410 src, FI, DAG.getSrcValue(0));
411 return DAG.getLoad(MVT::i64, ST, FI, DAG.getSrcValue(0));
412 }
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000413 }
Andrew Lenharth4e629512005-12-24 05:36:33 +0000414 case ISD::ConstantPool: {
Evan Chengb8973bd2006-01-31 22:23:14 +0000415 ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op);
416 Constant *C = CP->get();
417 SDOperand CPI = DAG.getTargetConstantPool(C, MVT::i64, CP->getAlignment());
Andrew Lenharth4e629512005-12-24 05:36:33 +0000418
419 SDOperand Hi = DAG.getNode(AlphaISD::GPRelHi, MVT::i64, CPI,
420 DAG.getNode(AlphaISD::GlobalBaseReg, MVT::i64));
421 SDOperand Lo = DAG.getNode(AlphaISD::GPRelLo, MVT::i64, CPI, Hi);
422 return Lo;
423 }
424 case ISD::GlobalAddress: {
425 GlobalAddressSDNode *GSDN = cast<GlobalAddressSDNode>(Op);
426 GlobalValue *GV = GSDN->getGlobal();
427 SDOperand GA = DAG.getTargetGlobalAddress(GV, MVT::i64, GSDN->getOffset());
428
429 if (!GV->hasWeakLinkage() && !GV->isExternal()) {
430 SDOperand Hi = DAG.getNode(AlphaISD::GPRelHi, MVT::i64, GA,
431 DAG.getNode(AlphaISD::GlobalBaseReg, MVT::i64));
432 SDOperand Lo = DAG.getNode(AlphaISD::GPRelLo, MVT::i64, GA, Hi);
433 return Lo;
434 } else
Andrew Lenharthc687b482005-12-24 08:29:32 +0000435 return DAG.getNode(AlphaISD::RelLit, MVT::i64, GA, DAG.getNode(AlphaISD::GlobalBaseReg, MVT::i64));
Andrew Lenharth4e629512005-12-24 05:36:33 +0000436 }
Andrew Lenharth53d89702005-12-25 01:34:27 +0000437 case ISD::ExternalSymbol: {
438 return DAG.getNode(AlphaISD::RelLit, MVT::i64,
439 DAG.getTargetExternalSymbol(cast<ExternalSymbolSDNode>(Op)->getSymbol(), MVT::i64),
440 DAG.getNode(AlphaISD::GlobalBaseReg, MVT::i64));
441 }
442
443 case ISD::SDIV:
444 case ISD::UDIV:
445 case ISD::UREM:
446 case ISD::SREM:
447 if (MVT::isInteger(Op.getValueType())) {
448 const char* opstr = 0;
449 switch(Op.getOpcode()) {
450 case ISD::UREM: opstr = "__remqu"; break;
451 case ISD::SREM: opstr = "__remq"; break;
452 case ISD::UDIV: opstr = "__divqu"; break;
453 case ISD::SDIV: opstr = "__divq"; break;
454 }
455 SDOperand Tmp1 = Op.getOperand(0),
456 Tmp2 = Op.getOperand(1),
457 Addr = DAG.getExternalSymbol(opstr, MVT::i64);
458 return DAG.getNode(AlphaISD::DivCall, MVT::i64, Addr, Tmp1, Tmp2);
459 }
460 break;
Andrew Lenharthcd804962005-11-30 16:10:29 +0000461
Nate Begemanacc398c2006-01-25 18:21:52 +0000462 case ISD::VAARG: {
463 SDOperand Chain = Op.getOperand(0);
464 SDOperand VAListP = Op.getOperand(1);
465 SDOperand VAListS = Op.getOperand(2);
466
467 SDOperand Base = DAG.getLoad(MVT::i64, Chain, VAListP, VAListS);
468 SDOperand Tmp = DAG.getNode(ISD::ADD, MVT::i64, VAListP,
469 DAG.getConstant(8, MVT::i64));
470 SDOperand Offset = DAG.getExtLoad(ISD::SEXTLOAD, MVT::i64, Base.getValue(1),
471 Tmp, DAG.getSrcValue(0), MVT::i32);
472 SDOperand DataPtr = DAG.getNode(ISD::ADD, MVT::i64, Base, Offset);
473 if (MVT::isFloatingPoint(Op.getValueType()))
474 {
475 //if fp && Offset < 6*8, then subtract 6*8 from DataPtr
476 SDOperand FPDataPtr = DAG.getNode(ISD::SUB, MVT::i64, DataPtr,
477 DAG.getConstant(8*6, MVT::i64));
478 SDOperand CC = DAG.getSetCC(MVT::i64, Offset,
479 DAG.getConstant(8*6, MVT::i64), ISD::SETLT);
480 DataPtr = DAG.getNode(ISD::SELECT, MVT::i64, CC, FPDataPtr, DataPtr);
481 }
Andrew Lenharth66e49582006-01-23 21:51:33 +0000482
Nate Begemanacc398c2006-01-25 18:21:52 +0000483 SDOperand NewOffset = DAG.getNode(ISD::ADD, MVT::i64, Offset,
484 DAG.getConstant(8, MVT::i64));
485 SDOperand Update = DAG.getNode(ISD::TRUNCSTORE, MVT::Other,
486 Offset.getValue(1), NewOffset,
487 Tmp, DAG.getSrcValue(0),
488 DAG.getValueType(MVT::i32));
489
490 SDOperand Result;
491 if (Op.getValueType() == MVT::i32)
492 Result = DAG.getExtLoad(ISD::SEXTLOAD, MVT::i64, Update, DataPtr,
493 DAG.getSrcValue(0), MVT::i32);
494 else
495 Result = DAG.getLoad(Op.getValueType(), Update, DataPtr,
496 DAG.getSrcValue(0));
497 return Result;
498 }
499 case ISD::VACOPY: {
500 SDOperand Chain = Op.getOperand(0);
501 SDOperand DestP = Op.getOperand(1);
502 SDOperand SrcP = Op.getOperand(2);
503 SDOperand DestS = Op.getOperand(3);
504 SDOperand SrcS = Op.getOperand(4);
505
506 SDOperand Val = DAG.getLoad(getPointerTy(), Chain, SrcP, SrcS);
507 SDOperand Result = DAG.getNode(ISD::STORE, MVT::Other, Val.getValue(1), Val,
508 DestP, DestS);
509 SDOperand NP = DAG.getNode(ISD::ADD, MVT::i64, SrcP,
510 DAG.getConstant(8, MVT::i64));
511 Val = DAG.getExtLoad(ISD::SEXTLOAD, MVT::i64, Result, NP,
512 DAG.getSrcValue(0), MVT::i32);
513 SDOperand NPD = DAG.getNode(ISD::ADD, MVT::i64, DestP,
514 DAG.getConstant(8, MVT::i64));
515 return DAG.getNode(ISD::TRUNCSTORE, MVT::Other, Val.getValue(1),
516 Val, NPD, DAG.getSrcValue(0),DAG.getValueType(MVT::i32));
517 }
518 case ISD::VASTART: {
519 SDOperand Chain = Op.getOperand(0);
520 SDOperand VAListP = Op.getOperand(1);
521 SDOperand VAListS = Op.getOperand(2);
522
523 // vastart stores the address of the VarArgsBase and VarArgsOffset
524 SDOperand FR = DAG.getFrameIndex(VarArgsBase, MVT::i64);
525 SDOperand S1 = DAG.getNode(ISD::STORE, MVT::Other, Chain, FR, VAListP,
526 VAListS);
527 SDOperand SA2 = DAG.getNode(ISD::ADD, MVT::i64, VAListP,
528 DAG.getConstant(8, MVT::i64));
529 return DAG.getNode(ISD::TRUNCSTORE, MVT::Other, S1,
530 DAG.getConstant(VarArgsOffset, MVT::i64), SA2,
531 DAG.getSrcValue(0), DAG.getValueType(MVT::i32));
532 }
Andrew Lenharthcd804962005-11-30 16:10:29 +0000533 }
534
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000535 return SDOperand();
536}
Nate Begeman0aed7842006-01-28 03:14:31 +0000537
538SDOperand AlphaTargetLowering::CustomPromoteOperation(SDOperand Op,
539 SelectionDAG &DAG) {
540 assert(Op.getValueType() == MVT::i32 &&
541 Op.getOpcode() == ISD::VAARG &&
542 "Unknown node to custom promote!");
543
544 // The code in LowerOperation already handles i32 vaarg
545 return LowerOperation(Op, DAG);
546}