blob: 9ce9a3ebe09d4c3c2905a215cc23bf46fee9316f [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"
23#include "llvm/Support/CommandLine.h"
24#include <iostream>
25
26using namespace llvm;
27
28namespace llvm {
29 extern cl::opt<bool> EnableAlphaIDIV;
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000030 extern cl::opt<bool> EnableAlphaCount;
31 extern cl::opt<bool> EnableAlphaLSMark;
32}
33
34/// AddLiveIn - This helper function adds the specified physical register to the
35/// MachineFunction as a live in value. It also creates a corresponding virtual
36/// register for it.
37static unsigned AddLiveIn(MachineFunction &MF, unsigned PReg,
38 TargetRegisterClass *RC) {
39 assert(RC->contains(PReg) && "Not the correct regclass!");
40 unsigned VReg = MF.getSSARegMap()->createVirtualRegister(RC);
41 MF.addLiveIn(PReg, VReg);
42 return VReg;
43}
44
45AlphaTargetLowering::AlphaTargetLowering(TargetMachine &TM) : TargetLowering(TM) {
46 // Set up the TargetLowering object.
47 //I am having problems with shr n ubyte 1
48 setShiftAmountType(MVT::i64);
49 setSetCCResultType(MVT::i64);
50 setSetCCResultContents(ZeroOrOneSetCCResult);
51
52 addRegisterClass(MVT::i64, Alpha::GPRCRegisterClass);
Andrew Lenharth5cefc5e2005-11-09 19:17:08 +000053 addRegisterClass(MVT::f64, Alpha::F8RCRegisterClass);
54 addRegisterClass(MVT::f32, Alpha::F4RCRegisterClass);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000055
56 setOperationAction(ISD::BRCONDTWOWAY, MVT::Other, Expand);
57 setOperationAction(ISD::BRTWOWAY_CC, MVT::Other, Expand);
58
59 setOperationAction(ISD::EXTLOAD, MVT::i1, Promote);
60 setOperationAction(ISD::EXTLOAD, MVT::f32, Expand);
61
62 setOperationAction(ISD::ZEXTLOAD, MVT::i1, Promote);
63 setOperationAction(ISD::ZEXTLOAD, MVT::i32, Expand);
64
65 setOperationAction(ISD::SEXTLOAD, MVT::i1, Promote);
66 setOperationAction(ISD::SEXTLOAD, MVT::i8, Expand);
67 setOperationAction(ISD::SEXTLOAD, MVT::i16, Expand);
68
Andrew Lenharthf3fb71b2005-10-06 16:54:29 +000069 setOperationAction(ISD::TRUNCSTORE, MVT::i1, Promote);
70
Chris Lattner3e2bafd2005-09-28 22:29:17 +000071 setOperationAction(ISD::FREM, MVT::f32, Expand);
72 setOperationAction(ISD::FREM, MVT::f64, Expand);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000073
74 setOperationAction(ISD::UINT_TO_FP, MVT::i64, Expand);
Andrew Lenharth7f0db912005-11-30 07:19:56 +000075 setOperationAction(ISD::SINT_TO_FP, MVT::i64, Custom);
Andrew Lenharthcd804962005-11-30 16:10:29 +000076 setOperationAction(ISD::FP_TO_UINT, MVT::i64, Expand);
77 setOperationAction(ISD::FP_TO_SINT, MVT::i64, Custom);
78
Andrew Lenharth120ab482005-09-29 22:54:56 +000079 if (!TM.getSubtarget<AlphaSubtarget>().hasCT()) {
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000080 setOperationAction(ISD::CTPOP , MVT::i64 , Expand);
81 setOperationAction(ISD::CTTZ , MVT::i64 , Expand);
82 setOperationAction(ISD::CTLZ , MVT::i64 , Expand);
83 }
84
Andrew Lenharth53d89702005-12-25 01:34:27 +000085 setOperationAction(ISD::SREM , MVT::i64, Custom);
86 setOperationAction(ISD::UREM , MVT::i64, Custom);
87 setOperationAction(ISD::SDIV , MVT::i64, Custom);
88 setOperationAction(ISD::UDIV , MVT::i64, Custom);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000089
90 setOperationAction(ISD::MEMMOVE , MVT::Other, Expand);
91 setOperationAction(ISD::MEMSET , MVT::Other, Expand);
92 setOperationAction(ISD::MEMCPY , MVT::Other, Expand);
93
94 // We don't support sin/cos/sqrt
95 setOperationAction(ISD::FSIN , MVT::f64, Expand);
96 setOperationAction(ISD::FCOS , MVT::f64, Expand);
97 setOperationAction(ISD::FSQRT, MVT::f64, Expand);
98 setOperationAction(ISD::FSIN , MVT::f32, Expand);
99 setOperationAction(ISD::FCOS , MVT::f32, Expand);
100 setOperationAction(ISD::FSQRT, MVT::f32, Expand);
101
Andrew Lenharthb2156f92005-11-30 17:11:20 +0000102 setOperationAction(ISD::SETCC, MVT::f32, Promote);
Chris Lattnerf73bae12005-11-29 06:16:21 +0000103
104 // We don't have line number support yet.
105 setOperationAction(ISD::LOCATION, MVT::Other, Expand);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000106
Andrew Lenharth53d89702005-12-25 01:34:27 +0000107 // We want to legalize GlobalAddress and ConstantPool and
108 // ExternalSymbols nodes into the appropriate instructions to
109 // materialize the address.
110 setOperationAction(ISD::GlobalAddress, MVT::i64, Custom);
111 setOperationAction(ISD::ConstantPool, MVT::i64, Custom);
112 setOperationAction(ISD::ExternalSymbol, MVT::i64, Custom);
Andrew Lenharth4e629512005-12-24 05:36:33 +0000113
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000114 addLegalFPImmediate(+0.0); //F31
115 addLegalFPImmediate(-0.0); //-F31
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000116
117 computeRegisterProperties();
118
119 useITOF = TM.getSubtarget<AlphaSubtarget>().hasF2I();
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000120}
121
122
123//http://www.cs.arizona.edu/computer.help/policy/DIGITAL_unix/AA-PY8AC-TET1_html/callCH3.html#BLOCK21
124
125//For now, just use variable size stack frame format
126
127//In a standard call, the first six items are passed in registers $16
128//- $21 and/or registers $f16 - $f21. (See Section 4.1.2 for details
129//of argument-to-register correspondence.) The remaining items are
130//collected in a memory argument list that is a naturally aligned
131//array of quadwords. In a standard call, this list, if present, must
132//be passed at 0(SP).
133//7 ... n 0(SP) ... (n-7)*8(SP)
134
135// //#define FP $15
136// //#define RA $26
137// //#define PV $27
138// //#define GP $29
139// //#define SP $30
140
141std::vector<SDOperand>
142AlphaTargetLowering::LowerArguments(Function &F, SelectionDAG &DAG)
143{
144 MachineFunction &MF = DAG.getMachineFunction();
145 MachineFrameInfo *MFI = MF.getFrameInfo();
146 MachineBasicBlock& BB = MF.front();
147 std::vector<SDOperand> ArgValues;
148
Andrew Lenharthf71df332005-09-04 06:12:19 +0000149 unsigned args_int[] = {
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000150 Alpha::R16, Alpha::R17, Alpha::R18, Alpha::R19, Alpha::R20, Alpha::R21};
Andrew Lenharthf71df332005-09-04 06:12:19 +0000151 unsigned args_float[] = {
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000152 Alpha::F16, Alpha::F17, Alpha::F18, Alpha::F19, Alpha::F20, Alpha::F21};
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000153
154 int count = 0;
155
156 GP = AddLiveIn(MF, Alpha::R29, getRegClassFor(MVT::i64));
157 RA = AddLiveIn(MF, Alpha::R26, getRegClassFor(MVT::i64));
158
159 for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I)
160 {
161 SDOperand argt;
162 if (count < 6) {
163 unsigned Vreg;
164 MVT::ValueType VT = getValueType(I->getType());
165 switch (VT) {
166 default:
167 std::cerr << "Unknown Type " << VT << "\n";
168 abort();
169 case MVT::f64:
170 case MVT::f32:
Andrew Lenharthf71df332005-09-04 06:12:19 +0000171 args_float[count] = AddLiveIn(MF, args_float[count], getRegClassFor(VT));
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000172 argt = DAG.getCopyFromReg(DAG.getRoot(), args_float[count], VT);
173 DAG.setRoot(argt.getValue(1));
174 break;
175 case MVT::i1:
176 case MVT::i8:
177 case MVT::i16:
178 case MVT::i32:
179 case MVT::i64:
Andrew Lenharthf71df332005-09-04 06:12:19 +0000180 args_int[count] = AddLiveIn(MF, args_int[count], getRegClassFor(MVT::i64));
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000181 argt = DAG.getCopyFromReg(DAG.getRoot(), args_int[count], MVT::i64);
182 DAG.setRoot(argt.getValue(1));
183 if (VT != MVT::i64) {
184 unsigned AssertOp =
185 I->getType()->isSigned() ? ISD::AssertSext : ISD::AssertZext;
186 argt = DAG.getNode(AssertOp, MVT::i64, argt,
187 DAG.getValueType(VT));
188 argt = DAG.getNode(ISD::TRUNCATE, VT, argt);
189 }
190 break;
191 }
192 } else { //more args
193 // Create the frame index object for this incoming parameter...
194 int FI = MFI->CreateFixedObject(8, 8 * (count - 6));
195
196 // Create the SelectionDAG nodes corresponding to a load
197 //from this parameter
198 SDOperand FIN = DAG.getFrameIndex(FI, MVT::i64);
199 argt = DAG.getLoad(getValueType(I->getType()),
200 DAG.getEntryNode(), FIN, DAG.getSrcValue(NULL));
201 }
202 ++count;
203 ArgValues.push_back(argt);
204 }
205
206 // If the functions takes variable number of arguments, copy all regs to stack
207 if (F.isVarArg()) {
208 VarArgsOffset = count * 8;
209 std::vector<SDOperand> LS;
210 for (int i = 0; i < 6; ++i) {
Chris Lattnerf2cded72005-09-13 19:03:13 +0000211 if (MRegisterInfo::isPhysicalRegister(args_int[i]))
Andrew Lenharthf71df332005-09-04 06:12:19 +0000212 args_int[i] = AddLiveIn(MF, args_int[i], getRegClassFor(MVT::i64));
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000213 SDOperand argt = DAG.getCopyFromReg(DAG.getRoot(), args_int[i], MVT::i64);
214 int FI = MFI->CreateFixedObject(8, -8 * (6 - i));
215 if (i == 0) VarArgsBase = FI;
216 SDOperand SDFI = DAG.getFrameIndex(FI, MVT::i64);
217 LS.push_back(DAG.getNode(ISD::STORE, MVT::Other, DAG.getRoot(), argt,
218 SDFI, DAG.getSrcValue(NULL)));
219
Chris Lattnerf2cded72005-09-13 19:03:13 +0000220 if (MRegisterInfo::isPhysicalRegister(args_float[i]))
Andrew Lenharthf71df332005-09-04 06:12:19 +0000221 args_float[i] = AddLiveIn(MF, args_float[i], getRegClassFor(MVT::f64));
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000222 argt = DAG.getCopyFromReg(DAG.getRoot(), args_float[i], MVT::f64);
223 FI = MFI->CreateFixedObject(8, - 8 * (12 - i));
224 SDFI = DAG.getFrameIndex(FI, MVT::i64);
225 LS.push_back(DAG.getNode(ISD::STORE, MVT::Other, DAG.getRoot(), argt,
226 SDFI, DAG.getSrcValue(NULL)));
227 }
228
229 //Set up a token factor with all the stack traffic
230 DAG.setRoot(DAG.getNode(ISD::TokenFactor, MVT::Other, LS));
231 }
232
233 // Finally, inform the code generator which regs we return values in.
234 switch (getValueType(F.getReturnType())) {
235 default: assert(0 && "Unknown type!");
236 case MVT::isVoid: break;
237 case MVT::i1:
238 case MVT::i8:
239 case MVT::i16:
240 case MVT::i32:
241 case MVT::i64:
242 MF.addLiveOut(Alpha::R0);
243 break;
244 case MVT::f32:
245 case MVT::f64:
246 MF.addLiveOut(Alpha::F0);
247 break;
248 }
249
250 //return the arguments
251 return ArgValues;
252}
253
254std::pair<SDOperand, SDOperand>
255AlphaTargetLowering::LowerCallTo(SDOperand Chain,
256 const Type *RetTy, bool isVarArg,
257 unsigned CallingConv, bool isTailCall,
258 SDOperand Callee, ArgListTy &Args,
259 SelectionDAG &DAG) {
260 int NumBytes = 0;
261 if (Args.size() > 6)
262 NumBytes = (Args.size() - 6) * 8;
263
264 Chain = DAG.getNode(ISD::CALLSEQ_START, MVT::Other, Chain,
265 DAG.getConstant(NumBytes, getPointerTy()));
266 std::vector<SDOperand> args_to_use;
267 for (unsigned i = 0, e = Args.size(); i != e; ++i)
268 {
269 switch (getValueType(Args[i].second)) {
270 default: assert(0 && "Unexpected ValueType for argument!");
271 case MVT::i1:
272 case MVT::i8:
273 case MVT::i16:
274 case MVT::i32:
275 // Promote the integer to 64 bits. If the input type is signed use a
276 // sign extend, otherwise use a zero extend.
277 if (Args[i].second->isSigned())
278 Args[i].first = DAG.getNode(ISD::SIGN_EXTEND, MVT::i64, Args[i].first);
279 else
280 Args[i].first = DAG.getNode(ISD::ZERO_EXTEND, MVT::i64, Args[i].first);
281 break;
282 case MVT::i64:
283 case MVT::f64:
284 case MVT::f32:
285 break;
286 }
287 args_to_use.push_back(Args[i].first);
288 }
289
290 std::vector<MVT::ValueType> RetVals;
291 MVT::ValueType RetTyVT = getValueType(RetTy);
Andrew Lenharth46a776e2005-09-06 17:00:23 +0000292 MVT::ValueType ActualRetTyVT = RetTyVT;
293 if (RetTyVT >= MVT::i1 && RetTyVT <= MVT::i32)
294 ActualRetTyVT = MVT::i64;
295
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000296 if (RetTyVT != MVT::isVoid)
Andrew Lenharth46a776e2005-09-06 17:00:23 +0000297 RetVals.push_back(ActualRetTyVT);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000298 RetVals.push_back(MVT::Other);
299
300 SDOperand TheCall = SDOperand(DAG.getCall(RetVals,
301 Chain, Callee, args_to_use), 0);
302 Chain = TheCall.getValue(RetTyVT != MVT::isVoid);
303 Chain = DAG.getNode(ISD::CALLSEQ_END, MVT::Other, Chain,
304 DAG.getConstant(NumBytes, getPointerTy()));
Andrew Lenharth46a776e2005-09-06 17:00:23 +0000305 SDOperand RetVal = TheCall;
306
307 if (RetTyVT != ActualRetTyVT) {
308 RetVal = DAG.getNode(RetTy->isSigned() ? ISD::AssertSext : ISD::AssertZext,
309 MVT::i64, RetVal, DAG.getValueType(RetTyVT));
310 RetVal = DAG.getNode(ISD::TRUNCATE, RetTyVT, RetVal);
311 }
312
313 return std::make_pair(RetVal, Chain);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000314}
315
316SDOperand AlphaTargetLowering::LowerVAStart(SDOperand Chain, SDOperand VAListP,
317 Value *VAListV, SelectionDAG &DAG) {
318 // vastart stores the address of the VarArgsBase and VarArgsOffset
319 SDOperand FR = DAG.getFrameIndex(VarArgsBase, MVT::i64);
320 SDOperand S1 = DAG.getNode(ISD::STORE, MVT::Other, Chain, FR, VAListP,
321 DAG.getSrcValue(VAListV));
322 SDOperand SA2 = DAG.getNode(ISD::ADD, MVT::i64, VAListP,
323 DAG.getConstant(8, MVT::i64));
324 return DAG.getNode(ISD::TRUNCSTORE, MVT::Other, S1,
325 DAG.getConstant(VarArgsOffset, MVT::i64), SA2,
326 DAG.getSrcValue(VAListV, 8), DAG.getValueType(MVT::i32));
327}
328
329std::pair<SDOperand,SDOperand> AlphaTargetLowering::
330LowerVAArg(SDOperand Chain, SDOperand VAListP, Value *VAListV,
331 const Type *ArgTy, SelectionDAG &DAG) {
332 SDOperand Base = DAG.getLoad(MVT::i64, Chain, VAListP,
333 DAG.getSrcValue(VAListV));
334 SDOperand Tmp = DAG.getNode(ISD::ADD, MVT::i64, VAListP,
335 DAG.getConstant(8, MVT::i64));
336 SDOperand Offset = DAG.getExtLoad(ISD::SEXTLOAD, MVT::i64, Base.getValue(1),
337 Tmp, DAG.getSrcValue(VAListV, 8), MVT::i32);
338 SDOperand DataPtr = DAG.getNode(ISD::ADD, MVT::i64, Base, Offset);
339 if (ArgTy->isFloatingPoint())
340 {
341 //if fp && Offset < 6*8, then subtract 6*8 from DataPtr
342 SDOperand FPDataPtr = DAG.getNode(ISD::SUB, MVT::i64, DataPtr,
343 DAG.getConstant(8*6, MVT::i64));
344 SDOperand CC = DAG.getSetCC(MVT::i64, Offset,
345 DAG.getConstant(8*6, MVT::i64), ISD::SETLT);
346 DataPtr = DAG.getNode(ISD::SELECT, MVT::i64, CC, FPDataPtr, DataPtr);
347 }
348
349 SDOperand Result;
350 if (ArgTy == Type::IntTy)
351 Result = DAG.getExtLoad(ISD::SEXTLOAD, MVT::i64, Offset.getValue(1),
352 DataPtr, DAG.getSrcValue(NULL), MVT::i32);
353 else if (ArgTy == Type::UIntTy)
354 Result = DAG.getExtLoad(ISD::ZEXTLOAD, MVT::i64, Offset.getValue(1),
355 DataPtr, DAG.getSrcValue(NULL), MVT::i32);
356 else
357 Result = DAG.getLoad(getValueType(ArgTy), Offset.getValue(1), DataPtr,
358 DAG.getSrcValue(NULL));
359
360 SDOperand NewOffset = DAG.getNode(ISD::ADD, MVT::i64, Offset,
361 DAG.getConstant(8, MVT::i64));
362 SDOperand Update = DAG.getNode(ISD::TRUNCSTORE, MVT::Other,
363 Result.getValue(1), NewOffset,
364 Tmp, DAG.getSrcValue(VAListV, 8),
365 DAG.getValueType(MVT::i32));
366 Result = DAG.getNode(ISD::TRUNCATE, getValueType(ArgTy), Result);
367
368 return std::make_pair(Result, Update);
369}
370
371
372SDOperand AlphaTargetLowering::
373LowerVACopy(SDOperand Chain, SDOperand SrcP, Value *SrcV, SDOperand DestP,
374 Value *DestV, SelectionDAG &DAG) {
375 SDOperand Val = DAG.getLoad(getPointerTy(), Chain, SrcP,
376 DAG.getSrcValue(SrcV));
377 SDOperand Result = DAG.getNode(ISD::STORE, MVT::Other, Val.getValue(1),
378 Val, DestP, DAG.getSrcValue(DestV));
379 SDOperand NP = DAG.getNode(ISD::ADD, MVT::i64, SrcP,
380 DAG.getConstant(8, MVT::i64));
381 Val = DAG.getExtLoad(ISD::SEXTLOAD, MVT::i64, Result, NP,
382 DAG.getSrcValue(SrcV, 8), MVT::i32);
383 SDOperand NPD = DAG.getNode(ISD::ADD, MVT::i64, DestP,
384 DAG.getConstant(8, MVT::i64));
385 return DAG.getNode(ISD::TRUNCSTORE, MVT::Other, Val.getValue(1),
386 Val, NPD, DAG.getSrcValue(DestV, 8),
387 DAG.getValueType(MVT::i32));
388}
389
390void AlphaTargetLowering::restoreGP(MachineBasicBlock* BB)
391{
392 BuildMI(BB, Alpha::BIS, 2, Alpha::R29).addReg(GP).addReg(GP);
393}
394void AlphaTargetLowering::restoreRA(MachineBasicBlock* BB)
395{
396 BuildMI(BB, Alpha::BIS, 2, Alpha::R26).addReg(RA).addReg(RA);
397}
398
399
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000400/// LowerOperation - Provide custom lowering hooks for some operations.
401///
402SDOperand AlphaTargetLowering::LowerOperation(SDOperand Op, SelectionDAG &DAG) {
403 switch (Op.getOpcode()) {
404 default: assert(0 && "Wasn't expecting to be able to lower this!");
405 case ISD::SINT_TO_FP: {
406 assert(MVT::i64 == Op.getOperand(0).getValueType() &&
407 "Unhandled SINT_TO_FP type in custom expander!");
408 SDOperand LD;
409 bool isDouble = MVT::f64 == Op.getValueType();
410 if (useITOF) {
411 LD = DAG.getNode(AlphaISD::ITOFT_, MVT::f64, Op.getOperand(0));
412 } else {
413 int FrameIdx =
414 DAG.getMachineFunction().getFrameInfo()->CreateStackObject(8, 8);
415 SDOperand FI = DAG.getFrameIndex(FrameIdx, MVT::i64);
416 SDOperand ST = DAG.getNode(ISD::STORE, MVT::Other, DAG.getEntryNode(),
417 Op.getOperand(0), FI, DAG.getSrcValue(0));
418 LD = DAG.getLoad(MVT::f64, ST, FI, DAG.getSrcValue(0));
419 }
420 SDOperand FP = DAG.getNode(isDouble?AlphaISD::CVTQT_:AlphaISD::CVTQS_,
421 isDouble?MVT::f64:MVT::f32, LD);
422 return FP;
423 }
Andrew Lenharthcd804962005-11-30 16:10:29 +0000424 case ISD::FP_TO_SINT: {
425 bool isDouble = MVT::f64 == Op.getOperand(0).getValueType();
426 SDOperand src = Op.getOperand(0);
427
428 if (!isDouble) //Promote
429 src = DAG.getNode(ISD::FP_EXTEND, MVT::f64, src);
430
431 src = DAG.getNode(AlphaISD::CVTTQ_, MVT::f64, src);
432
433 if (useITOF) {
434 return DAG.getNode(AlphaISD::FTOIT_, MVT::i64, src);
435 } else {
436 int FrameIdx =
437 DAG.getMachineFunction().getFrameInfo()->CreateStackObject(8, 8);
438 SDOperand FI = DAG.getFrameIndex(FrameIdx, MVT::i64);
439 SDOperand ST = DAG.getNode(ISD::STORE, MVT::Other, DAG.getEntryNode(),
440 src, FI, DAG.getSrcValue(0));
441 return DAG.getLoad(MVT::i64, ST, FI, DAG.getSrcValue(0));
442 }
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000443 }
Andrew Lenharth4e629512005-12-24 05:36:33 +0000444 case ISD::ConstantPool: {
445 Constant *C = cast<ConstantPoolSDNode>(Op)->get();
446 SDOperand CPI = DAG.getTargetConstantPool(C, MVT::i64);
447
448 SDOperand Hi = DAG.getNode(AlphaISD::GPRelHi, MVT::i64, CPI,
449 DAG.getNode(AlphaISD::GlobalBaseReg, MVT::i64));
450 SDOperand Lo = DAG.getNode(AlphaISD::GPRelLo, MVT::i64, CPI, Hi);
451 return Lo;
452 }
453 case ISD::GlobalAddress: {
454 GlobalAddressSDNode *GSDN = cast<GlobalAddressSDNode>(Op);
455 GlobalValue *GV = GSDN->getGlobal();
456 SDOperand GA = DAG.getTargetGlobalAddress(GV, MVT::i64, GSDN->getOffset());
457
458 if (!GV->hasWeakLinkage() && !GV->isExternal()) {
459 SDOperand Hi = DAG.getNode(AlphaISD::GPRelHi, MVT::i64, GA,
460 DAG.getNode(AlphaISD::GlobalBaseReg, MVT::i64));
461 SDOperand Lo = DAG.getNode(AlphaISD::GPRelLo, MVT::i64, GA, Hi);
462 return Lo;
463 } else
Andrew Lenharthc687b482005-12-24 08:29:32 +0000464 return DAG.getNode(AlphaISD::RelLit, MVT::i64, GA, DAG.getNode(AlphaISD::GlobalBaseReg, MVT::i64));
Andrew Lenharth4e629512005-12-24 05:36:33 +0000465 }
Andrew Lenharth53d89702005-12-25 01:34:27 +0000466 case ISD::ExternalSymbol: {
467 return DAG.getNode(AlphaISD::RelLit, MVT::i64,
468 DAG.getTargetExternalSymbol(cast<ExternalSymbolSDNode>(Op)->getSymbol(), MVT::i64),
469 DAG.getNode(AlphaISD::GlobalBaseReg, MVT::i64));
470 }
471
472 case ISD::SDIV:
473 case ISD::UDIV:
474 case ISD::UREM:
475 case ISD::SREM:
476 if (MVT::isInteger(Op.getValueType())) {
477 const char* opstr = 0;
478 switch(Op.getOpcode()) {
479 case ISD::UREM: opstr = "__remqu"; break;
480 case ISD::SREM: opstr = "__remq"; break;
481 case ISD::UDIV: opstr = "__divqu"; break;
482 case ISD::SDIV: opstr = "__divq"; break;
483 }
484 SDOperand Tmp1 = Op.getOperand(0),
485 Tmp2 = Op.getOperand(1),
486 Addr = DAG.getExternalSymbol(opstr, MVT::i64);
487 return DAG.getNode(AlphaISD::DivCall, MVT::i64, Addr, Tmp1, Tmp2);
488 }
489 break;
Andrew Lenharthcd804962005-11-30 16:10:29 +0000490
491 }
492
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000493 return SDOperand();
494}