blob: b9332890d6c11f7a9685e6736d8d6a05a2019df7 [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 }
Nate Begemand88fc032006-01-14 03:14:10 +000084 setOperationAction(ISD::BSWAP , MVT::i64, Expand);
Nate Begeman35ef9132006-01-11 21:21:00 +000085 setOperationAction(ISD::ROTL , MVT::i64, Expand);
86 setOperationAction(ISD::ROTR , MVT::i64, Expand);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000087
Andrew Lenharth53d89702005-12-25 01:34:27 +000088 setOperationAction(ISD::SREM , MVT::i64, Custom);
89 setOperationAction(ISD::UREM , MVT::i64, Custom);
90 setOperationAction(ISD::SDIV , MVT::i64, Custom);
91 setOperationAction(ISD::UDIV , MVT::i64, Custom);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +000092
93 setOperationAction(ISD::MEMMOVE , MVT::Other, Expand);
94 setOperationAction(ISD::MEMSET , MVT::Other, Expand);
95 setOperationAction(ISD::MEMCPY , MVT::Other, Expand);
96
97 // We don't support sin/cos/sqrt
98 setOperationAction(ISD::FSIN , MVT::f64, Expand);
99 setOperationAction(ISD::FCOS , MVT::f64, Expand);
100 setOperationAction(ISD::FSQRT, MVT::f64, Expand);
101 setOperationAction(ISD::FSIN , MVT::f32, Expand);
102 setOperationAction(ISD::FCOS , MVT::f32, Expand);
103 setOperationAction(ISD::FSQRT, MVT::f32, Expand);
104
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 Lenharthaa38ce42005-09-02 18:46:02 +0000115
Andrew Lenharth53d89702005-12-25 01:34:27 +0000116 // We want to legalize GlobalAddress and ConstantPool and
117 // ExternalSymbols nodes into the appropriate instructions to
118 // materialize the address.
119 setOperationAction(ISD::GlobalAddress, MVT::i64, Custom);
120 setOperationAction(ISD::ConstantPool, MVT::i64, Custom);
121 setOperationAction(ISD::ExternalSymbol, MVT::i64, Custom);
Andrew Lenharth4e629512005-12-24 05:36:33 +0000122
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000123 addLegalFPImmediate(+0.0); //F31
124 addLegalFPImmediate(-0.0); //-F31
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000125
126 computeRegisterProperties();
127
128 useITOF = TM.getSubtarget<AlphaSubtarget>().hasF2I();
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000129}
130
131
132//http://www.cs.arizona.edu/computer.help/policy/DIGITAL_unix/AA-PY8AC-TET1_html/callCH3.html#BLOCK21
133
134//For now, just use variable size stack frame format
135
136//In a standard call, the first six items are passed in registers $16
137//- $21 and/or registers $f16 - $f21. (See Section 4.1.2 for details
138//of argument-to-register correspondence.) The remaining items are
139//collected in a memory argument list that is a naturally aligned
140//array of quadwords. In a standard call, this list, if present, must
141//be passed at 0(SP).
142//7 ... n 0(SP) ... (n-7)*8(SP)
143
144// //#define FP $15
145// //#define RA $26
146// //#define PV $27
147// //#define GP $29
148// //#define SP $30
149
150std::vector<SDOperand>
151AlphaTargetLowering::LowerArguments(Function &F, SelectionDAG &DAG)
152{
153 MachineFunction &MF = DAG.getMachineFunction();
154 MachineFrameInfo *MFI = MF.getFrameInfo();
155 MachineBasicBlock& BB = MF.front();
156 std::vector<SDOperand> ArgValues;
157
Andrew Lenharthf71df332005-09-04 06:12:19 +0000158 unsigned args_int[] = {
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000159 Alpha::R16, Alpha::R17, Alpha::R18, Alpha::R19, Alpha::R20, Alpha::R21};
Andrew Lenharthf71df332005-09-04 06:12:19 +0000160 unsigned args_float[] = {
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000161 Alpha::F16, Alpha::F17, Alpha::F18, Alpha::F19, Alpha::F20, Alpha::F21};
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000162
163 int count = 0;
164
165 GP = AddLiveIn(MF, Alpha::R29, getRegClassFor(MVT::i64));
166 RA = AddLiveIn(MF, Alpha::R26, getRegClassFor(MVT::i64));
167
168 for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I)
169 {
170 SDOperand argt;
171 if (count < 6) {
172 unsigned Vreg;
173 MVT::ValueType VT = getValueType(I->getType());
174 switch (VT) {
175 default:
176 std::cerr << "Unknown Type " << VT << "\n";
177 abort();
178 case MVT::f64:
179 case MVT::f32:
Andrew Lenharthf71df332005-09-04 06:12:19 +0000180 args_float[count] = AddLiveIn(MF, args_float[count], getRegClassFor(VT));
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000181 argt = DAG.getCopyFromReg(DAG.getRoot(), args_float[count], VT);
182 DAG.setRoot(argt.getValue(1));
183 break;
184 case MVT::i1:
185 case MVT::i8:
186 case MVT::i16:
187 case MVT::i32:
188 case MVT::i64:
Andrew Lenharthf71df332005-09-04 06:12:19 +0000189 args_int[count] = AddLiveIn(MF, args_int[count], getRegClassFor(MVT::i64));
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000190 argt = DAG.getCopyFromReg(DAG.getRoot(), args_int[count], MVT::i64);
191 DAG.setRoot(argt.getValue(1));
192 if (VT != MVT::i64) {
193 unsigned AssertOp =
194 I->getType()->isSigned() ? ISD::AssertSext : ISD::AssertZext;
195 argt = DAG.getNode(AssertOp, MVT::i64, argt,
196 DAG.getValueType(VT));
197 argt = DAG.getNode(ISD::TRUNCATE, VT, argt);
198 }
199 break;
200 }
201 } else { //more args
202 // Create the frame index object for this incoming parameter...
203 int FI = MFI->CreateFixedObject(8, 8 * (count - 6));
204
205 // Create the SelectionDAG nodes corresponding to a load
206 //from this parameter
207 SDOperand FIN = DAG.getFrameIndex(FI, MVT::i64);
208 argt = DAG.getLoad(getValueType(I->getType()),
209 DAG.getEntryNode(), FIN, DAG.getSrcValue(NULL));
210 }
211 ++count;
212 ArgValues.push_back(argt);
213 }
214
215 // If the functions takes variable number of arguments, copy all regs to stack
216 if (F.isVarArg()) {
217 VarArgsOffset = count * 8;
218 std::vector<SDOperand> LS;
219 for (int i = 0; i < 6; ++i) {
Chris Lattnerf2cded72005-09-13 19:03:13 +0000220 if (MRegisterInfo::isPhysicalRegister(args_int[i]))
Andrew Lenharthf71df332005-09-04 06:12:19 +0000221 args_int[i] = AddLiveIn(MF, args_int[i], getRegClassFor(MVT::i64));
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000222 SDOperand argt = DAG.getCopyFromReg(DAG.getRoot(), args_int[i], MVT::i64);
223 int FI = MFI->CreateFixedObject(8, -8 * (6 - i));
224 if (i == 0) VarArgsBase = FI;
225 SDOperand SDFI = DAG.getFrameIndex(FI, MVT::i64);
226 LS.push_back(DAG.getNode(ISD::STORE, MVT::Other, DAG.getRoot(), argt,
227 SDFI, DAG.getSrcValue(NULL)));
228
Chris Lattnerf2cded72005-09-13 19:03:13 +0000229 if (MRegisterInfo::isPhysicalRegister(args_float[i]))
Andrew Lenharthf71df332005-09-04 06:12:19 +0000230 args_float[i] = AddLiveIn(MF, args_float[i], getRegClassFor(MVT::f64));
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000231 argt = DAG.getCopyFromReg(DAG.getRoot(), args_float[i], MVT::f64);
232 FI = MFI->CreateFixedObject(8, - 8 * (12 - i));
233 SDFI = DAG.getFrameIndex(FI, MVT::i64);
234 LS.push_back(DAG.getNode(ISD::STORE, MVT::Other, DAG.getRoot(), argt,
235 SDFI, DAG.getSrcValue(NULL)));
236 }
237
238 //Set up a token factor with all the stack traffic
239 DAG.setRoot(DAG.getNode(ISD::TokenFactor, MVT::Other, LS));
240 }
241
242 // Finally, inform the code generator which regs we return values in.
243 switch (getValueType(F.getReturnType())) {
244 default: assert(0 && "Unknown type!");
245 case MVT::isVoid: break;
246 case MVT::i1:
247 case MVT::i8:
248 case MVT::i16:
249 case MVT::i32:
250 case MVT::i64:
251 MF.addLiveOut(Alpha::R0);
252 break;
253 case MVT::f32:
254 case MVT::f64:
255 MF.addLiveOut(Alpha::F0);
256 break;
257 }
258
259 //return the arguments
260 return ArgValues;
261}
262
263std::pair<SDOperand, SDOperand>
264AlphaTargetLowering::LowerCallTo(SDOperand Chain,
265 const Type *RetTy, bool isVarArg,
266 unsigned CallingConv, bool isTailCall,
267 SDOperand Callee, ArgListTy &Args,
268 SelectionDAG &DAG) {
269 int NumBytes = 0;
270 if (Args.size() > 6)
271 NumBytes = (Args.size() - 6) * 8;
272
273 Chain = DAG.getNode(ISD::CALLSEQ_START, MVT::Other, Chain,
274 DAG.getConstant(NumBytes, getPointerTy()));
275 std::vector<SDOperand> args_to_use;
276 for (unsigned i = 0, e = Args.size(); i != e; ++i)
277 {
278 switch (getValueType(Args[i].second)) {
279 default: assert(0 && "Unexpected ValueType for argument!");
280 case MVT::i1:
281 case MVT::i8:
282 case MVT::i16:
283 case MVT::i32:
284 // Promote the integer to 64 bits. If the input type is signed use a
285 // sign extend, otherwise use a zero extend.
286 if (Args[i].second->isSigned())
287 Args[i].first = DAG.getNode(ISD::SIGN_EXTEND, MVT::i64, Args[i].first);
288 else
289 Args[i].first = DAG.getNode(ISD::ZERO_EXTEND, MVT::i64, Args[i].first);
290 break;
291 case MVT::i64:
292 case MVT::f64:
293 case MVT::f32:
294 break;
295 }
296 args_to_use.push_back(Args[i].first);
297 }
298
299 std::vector<MVT::ValueType> RetVals;
300 MVT::ValueType RetTyVT = getValueType(RetTy);
Andrew Lenharth46a776e2005-09-06 17:00:23 +0000301 MVT::ValueType ActualRetTyVT = RetTyVT;
302 if (RetTyVT >= MVT::i1 && RetTyVT <= MVT::i32)
303 ActualRetTyVT = MVT::i64;
304
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000305 if (RetTyVT != MVT::isVoid)
Andrew Lenharth46a776e2005-09-06 17:00:23 +0000306 RetVals.push_back(ActualRetTyVT);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000307 RetVals.push_back(MVT::Other);
308
309 SDOperand TheCall = SDOperand(DAG.getCall(RetVals,
310 Chain, Callee, args_to_use), 0);
311 Chain = TheCall.getValue(RetTyVT != MVT::isVoid);
312 Chain = DAG.getNode(ISD::CALLSEQ_END, MVT::Other, Chain,
313 DAG.getConstant(NumBytes, getPointerTy()));
Andrew Lenharth46a776e2005-09-06 17:00:23 +0000314 SDOperand RetVal = TheCall;
315
316 if (RetTyVT != ActualRetTyVT) {
317 RetVal = DAG.getNode(RetTy->isSigned() ? ISD::AssertSext : ISD::AssertZext,
318 MVT::i64, RetVal, DAG.getValueType(RetTyVT));
319 RetVal = DAG.getNode(ISD::TRUNCATE, RetTyVT, RetVal);
320 }
321
322 return std::make_pair(RetVal, Chain);
Andrew Lenharthaa38ce42005-09-02 18:46:02 +0000323}
324
325SDOperand AlphaTargetLowering::LowerVAStart(SDOperand Chain, SDOperand VAListP,
326 Value *VAListV, SelectionDAG &DAG) {
327 // vastart stores the address of the VarArgsBase and VarArgsOffset
328 SDOperand FR = DAG.getFrameIndex(VarArgsBase, MVT::i64);
329 SDOperand S1 = DAG.getNode(ISD::STORE, MVT::Other, Chain, FR, VAListP,
330 DAG.getSrcValue(VAListV));
331 SDOperand SA2 = DAG.getNode(ISD::ADD, MVT::i64, VAListP,
332 DAG.getConstant(8, MVT::i64));
333 return DAG.getNode(ISD::TRUNCSTORE, MVT::Other, S1,
334 DAG.getConstant(VarArgsOffset, MVT::i64), SA2,
335 DAG.getSrcValue(VAListV, 8), DAG.getValueType(MVT::i32));
336}
337
338std::pair<SDOperand,SDOperand> AlphaTargetLowering::
339LowerVAArg(SDOperand Chain, SDOperand VAListP, Value *VAListV,
340 const Type *ArgTy, SelectionDAG &DAG) {
341 SDOperand Base = DAG.getLoad(MVT::i64, Chain, VAListP,
342 DAG.getSrcValue(VAListV));
343 SDOperand Tmp = DAG.getNode(ISD::ADD, MVT::i64, VAListP,
344 DAG.getConstant(8, MVT::i64));
345 SDOperand Offset = DAG.getExtLoad(ISD::SEXTLOAD, MVT::i64, Base.getValue(1),
346 Tmp, DAG.getSrcValue(VAListV, 8), MVT::i32);
347 SDOperand DataPtr = DAG.getNode(ISD::ADD, MVT::i64, Base, Offset);
348 if (ArgTy->isFloatingPoint())
349 {
350 //if fp && Offset < 6*8, then subtract 6*8 from DataPtr
351 SDOperand FPDataPtr = DAG.getNode(ISD::SUB, MVT::i64, DataPtr,
352 DAG.getConstant(8*6, MVT::i64));
353 SDOperand CC = DAG.getSetCC(MVT::i64, Offset,
354 DAG.getConstant(8*6, MVT::i64), ISD::SETLT);
355 DataPtr = DAG.getNode(ISD::SELECT, MVT::i64, CC, FPDataPtr, DataPtr);
356 }
357
358 SDOperand Result;
359 if (ArgTy == Type::IntTy)
360 Result = DAG.getExtLoad(ISD::SEXTLOAD, MVT::i64, Offset.getValue(1),
361 DataPtr, DAG.getSrcValue(NULL), MVT::i32);
362 else if (ArgTy == Type::UIntTy)
363 Result = DAG.getExtLoad(ISD::ZEXTLOAD, MVT::i64, Offset.getValue(1),
364 DataPtr, DAG.getSrcValue(NULL), MVT::i32);
365 else
366 Result = DAG.getLoad(getValueType(ArgTy), Offset.getValue(1), DataPtr,
367 DAG.getSrcValue(NULL));
368
369 SDOperand NewOffset = DAG.getNode(ISD::ADD, MVT::i64, Offset,
370 DAG.getConstant(8, MVT::i64));
371 SDOperand Update = DAG.getNode(ISD::TRUNCSTORE, MVT::Other,
372 Result.getValue(1), NewOffset,
373 Tmp, DAG.getSrcValue(VAListV, 8),
374 DAG.getValueType(MVT::i32));
375 Result = DAG.getNode(ISD::TRUNCATE, getValueType(ArgTy), Result);
376
377 return std::make_pair(Result, Update);
378}
379
380
381SDOperand AlphaTargetLowering::
382LowerVACopy(SDOperand Chain, SDOperand SrcP, Value *SrcV, SDOperand DestP,
383 Value *DestV, SelectionDAG &DAG) {
384 SDOperand Val = DAG.getLoad(getPointerTy(), Chain, SrcP,
385 DAG.getSrcValue(SrcV));
386 SDOperand Result = DAG.getNode(ISD::STORE, MVT::Other, Val.getValue(1),
387 Val, DestP, DAG.getSrcValue(DestV));
388 SDOperand NP = DAG.getNode(ISD::ADD, MVT::i64, SrcP,
389 DAG.getConstant(8, MVT::i64));
390 Val = DAG.getExtLoad(ISD::SEXTLOAD, MVT::i64, Result, NP,
391 DAG.getSrcValue(SrcV, 8), MVT::i32);
392 SDOperand NPD = DAG.getNode(ISD::ADD, MVT::i64, DestP,
393 DAG.getConstant(8, MVT::i64));
394 return DAG.getNode(ISD::TRUNCSTORE, MVT::Other, Val.getValue(1),
395 Val, NPD, DAG.getSrcValue(DestV, 8),
396 DAG.getValueType(MVT::i32));
397}
398
399void AlphaTargetLowering::restoreGP(MachineBasicBlock* BB)
400{
401 BuildMI(BB, Alpha::BIS, 2, Alpha::R29).addReg(GP).addReg(GP);
402}
403void AlphaTargetLowering::restoreRA(MachineBasicBlock* BB)
404{
405 BuildMI(BB, Alpha::BIS, 2, Alpha::R26).addReg(RA).addReg(RA);
406}
407
408
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000409/// LowerOperation - Provide custom lowering hooks for some operations.
410///
411SDOperand AlphaTargetLowering::LowerOperation(SDOperand Op, SelectionDAG &DAG) {
412 switch (Op.getOpcode()) {
413 default: assert(0 && "Wasn't expecting to be able to lower this!");
414 case ISD::SINT_TO_FP: {
415 assert(MVT::i64 == Op.getOperand(0).getValueType() &&
416 "Unhandled SINT_TO_FP type in custom expander!");
417 SDOperand LD;
418 bool isDouble = MVT::f64 == Op.getValueType();
419 if (useITOF) {
420 LD = DAG.getNode(AlphaISD::ITOFT_, MVT::f64, Op.getOperand(0));
421 } else {
422 int FrameIdx =
423 DAG.getMachineFunction().getFrameInfo()->CreateStackObject(8, 8);
424 SDOperand FI = DAG.getFrameIndex(FrameIdx, MVT::i64);
425 SDOperand ST = DAG.getNode(ISD::STORE, MVT::Other, DAG.getEntryNode(),
426 Op.getOperand(0), FI, DAG.getSrcValue(0));
427 LD = DAG.getLoad(MVT::f64, ST, FI, DAG.getSrcValue(0));
428 }
429 SDOperand FP = DAG.getNode(isDouble?AlphaISD::CVTQT_:AlphaISD::CVTQS_,
430 isDouble?MVT::f64:MVT::f32, LD);
431 return FP;
432 }
Andrew Lenharthcd804962005-11-30 16:10:29 +0000433 case ISD::FP_TO_SINT: {
434 bool isDouble = MVT::f64 == Op.getOperand(0).getValueType();
435 SDOperand src = Op.getOperand(0);
436
437 if (!isDouble) //Promote
438 src = DAG.getNode(ISD::FP_EXTEND, MVT::f64, src);
439
440 src = DAG.getNode(AlphaISD::CVTTQ_, MVT::f64, src);
441
442 if (useITOF) {
443 return DAG.getNode(AlphaISD::FTOIT_, MVT::i64, src);
444 } else {
445 int FrameIdx =
446 DAG.getMachineFunction().getFrameInfo()->CreateStackObject(8, 8);
447 SDOperand FI = DAG.getFrameIndex(FrameIdx, MVT::i64);
448 SDOperand ST = DAG.getNode(ISD::STORE, MVT::Other, DAG.getEntryNode(),
449 src, FI, DAG.getSrcValue(0));
450 return DAG.getLoad(MVT::i64, ST, FI, DAG.getSrcValue(0));
451 }
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000452 }
Andrew Lenharth4e629512005-12-24 05:36:33 +0000453 case ISD::ConstantPool: {
454 Constant *C = cast<ConstantPoolSDNode>(Op)->get();
455 SDOperand CPI = DAG.getTargetConstantPool(C, MVT::i64);
456
457 SDOperand Hi = DAG.getNode(AlphaISD::GPRelHi, MVT::i64, CPI,
458 DAG.getNode(AlphaISD::GlobalBaseReg, MVT::i64));
459 SDOperand Lo = DAG.getNode(AlphaISD::GPRelLo, MVT::i64, CPI, Hi);
460 return Lo;
461 }
462 case ISD::GlobalAddress: {
463 GlobalAddressSDNode *GSDN = cast<GlobalAddressSDNode>(Op);
464 GlobalValue *GV = GSDN->getGlobal();
465 SDOperand GA = DAG.getTargetGlobalAddress(GV, MVT::i64, GSDN->getOffset());
466
467 if (!GV->hasWeakLinkage() && !GV->isExternal()) {
468 SDOperand Hi = DAG.getNode(AlphaISD::GPRelHi, MVT::i64, GA,
469 DAG.getNode(AlphaISD::GlobalBaseReg, MVT::i64));
470 SDOperand Lo = DAG.getNode(AlphaISD::GPRelLo, MVT::i64, GA, Hi);
471 return Lo;
472 } else
Andrew Lenharthc687b482005-12-24 08:29:32 +0000473 return DAG.getNode(AlphaISD::RelLit, MVT::i64, GA, DAG.getNode(AlphaISD::GlobalBaseReg, MVT::i64));
Andrew Lenharth4e629512005-12-24 05:36:33 +0000474 }
Andrew Lenharth53d89702005-12-25 01:34:27 +0000475 case ISD::ExternalSymbol: {
476 return DAG.getNode(AlphaISD::RelLit, MVT::i64,
477 DAG.getTargetExternalSymbol(cast<ExternalSymbolSDNode>(Op)->getSymbol(), MVT::i64),
478 DAG.getNode(AlphaISD::GlobalBaseReg, MVT::i64));
479 }
480
481 case ISD::SDIV:
482 case ISD::UDIV:
483 case ISD::UREM:
484 case ISD::SREM:
485 if (MVT::isInteger(Op.getValueType())) {
486 const char* opstr = 0;
487 switch(Op.getOpcode()) {
488 case ISD::UREM: opstr = "__remqu"; break;
489 case ISD::SREM: opstr = "__remq"; break;
490 case ISD::UDIV: opstr = "__divqu"; break;
491 case ISD::SDIV: opstr = "__divq"; break;
492 }
493 SDOperand Tmp1 = Op.getOperand(0),
494 Tmp2 = Op.getOperand(1),
495 Addr = DAG.getExternalSymbol(opstr, MVT::i64);
496 return DAG.getNode(AlphaISD::DivCall, MVT::i64, Addr, Tmp1, Tmp2);
497 }
498 break;
Andrew Lenharthcd804962005-11-30 16:10:29 +0000499
500 }
501
Andrew Lenharth7f0db912005-11-30 07:19:56 +0000502 return SDOperand();
503}