blob: d63157fb444b32b63f0096bb3c218370da32825f [file] [log] [blame]
Duraid Madinaf221c262005-10-28 17:46:35 +00001//===-- IA64ISelLowering.cpp - IA64 DAG Lowering Implementation -----------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Duraid Madina 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 IA64ISelLowering class.
11//
12//===----------------------------------------------------------------------===//
13
14#include "IA64ISelLowering.h"
15#include "IA64MachineFunctionInfo.h"
16#include "IA64TargetMachine.h"
17#include "llvm/CodeGen/MachineFrameInfo.h"
18#include "llvm/CodeGen/MachineFunction.h"
19#include "llvm/CodeGen/MachineInstrBuilder.h"
20#include "llvm/CodeGen/SelectionDAG.h"
21#include "llvm/CodeGen/SSARegMap.h"
22#include "llvm/Constants.h"
23#include "llvm/Function.h"
24using namespace llvm;
25
26IA64TargetLowering::IA64TargetLowering(TargetMachine &TM)
27 : TargetLowering(TM) {
28
29 // register class for general registers
30 addRegisterClass(MVT::i64, IA64::GRRegisterClass);
31
32 // register class for FP registers
33 addRegisterClass(MVT::f64, IA64::FPRegisterClass);
34
35 // register class for predicate registers
36 addRegisterClass(MVT::i1, IA64::PRRegisterClass);
37
38 setOperationAction(ISD::BRCONDTWOWAY , MVT::Other, Expand);
39 setOperationAction(ISD::BRTWOWAY_CC , MVT::Other, Expand);
40 setOperationAction(ISD::FP_ROUND_INREG , MVT::f32 , Expand);
41
42 setSetCCResultType(MVT::i1);
43 setShiftAmountType(MVT::i64);
44
45 setOperationAction(ISD::EXTLOAD , MVT::i1 , Promote);
46
47 setOperationAction(ISD::ZEXTLOAD , MVT::i1 , Expand);
48
49 setOperationAction(ISD::SEXTLOAD , MVT::i1 , Expand);
50 setOperationAction(ISD::SEXTLOAD , MVT::i8 , Expand);
51 setOperationAction(ISD::SEXTLOAD , MVT::i16 , Expand);
52 setOperationAction(ISD::SEXTLOAD , MVT::i32 , Expand);
53
54 setOperationAction(ISD::FREM , MVT::f32 , Expand);
55 setOperationAction(ISD::FREM , MVT::f64 , Expand);
56
57 setOperationAction(ISD::UREM , MVT::f32 , Expand);
58 setOperationAction(ISD::UREM , MVT::f64 , Expand);
59
60 setOperationAction(ISD::MEMMOVE , MVT::Other, Expand);
61 setOperationAction(ISD::MEMSET , MVT::Other, Expand);
62 setOperationAction(ISD::MEMCPY , MVT::Other, Expand);
63
64 setOperationAction(ISD::SINT_TO_FP , MVT::i1 , Promote);
65 setOperationAction(ISD::UINT_TO_FP , MVT::i1 , Promote);
66
67 // We don't support sin/cos/sqrt
68 setOperationAction(ISD::FSIN , MVT::f64, Expand);
69 setOperationAction(ISD::FCOS , MVT::f64, Expand);
70 setOperationAction(ISD::FSQRT, MVT::f64, Expand);
71 setOperationAction(ISD::FSIN , MVT::f32, Expand);
72 setOperationAction(ISD::FCOS , MVT::f32, Expand);
73 setOperationAction(ISD::FSQRT, MVT::f32, Expand);
74
Chris Lattner9c415362005-11-29 06:16:21 +000075 // We don't have line number support yet.
76 setOperationAction(ISD::LOCATION, MVT::Other, Expand);
Jim Laskey9e296be2005-12-21 20:51:37 +000077 setOperationAction(ISD::DEBUG_LOC, MVT::Other, Expand);
Chris Lattner9c415362005-11-29 06:16:21 +000078
Duraid Madinaf221c262005-10-28 17:46:35 +000079 //IA64 has these, but they are not implemented
80 setOperationAction(ISD::CTTZ , MVT::i64 , Expand);
81 setOperationAction(ISD::CTLZ , MVT::i64 , Expand);
82
83 computeRegisterProperties();
84
85 addLegalFPImmediate(+0.0);
86 addLegalFPImmediate(+1.0);
Duraid Madinaf221c262005-10-28 17:46:35 +000087}
88
89/// isFloatingPointZero - Return true if this is 0.0 or -0.0.
90static bool isFloatingPointZero(SDOperand Op) {
91 if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(Op))
92 return CFP->isExactlyValue(-0.0) || CFP->isExactlyValue(0.0);
93 else if (Op.getOpcode() == ISD::EXTLOAD || Op.getOpcode() == ISD::LOAD) {
94 // Maybe this has already been legalized into the constant pool?
95 if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Op.getOperand(1)))
96 if (ConstantFP *CFP = dyn_cast<ConstantFP>(CP->get()))
97 return CFP->isExactlyValue(-0.0) || CFP->isExactlyValue(0.0);
98 }
99 return false;
100}
101
102std::vector<SDOperand>
103IA64TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
104 std::vector<SDOperand> ArgValues;
105 //
106 // add beautiful description of IA64 stack frame format
107 // here (from intel 24535803.pdf most likely)
108 //
109 MachineFunction &MF = DAG.getMachineFunction();
110 MachineFrameInfo *MFI = MF.getFrameInfo();
111
112 GP = MF.getSSARegMap()->createVirtualRegister(getRegClassFor(MVT::i64));
113 SP = MF.getSSARegMap()->createVirtualRegister(getRegClassFor(MVT::i64));
114 RP = MF.getSSARegMap()->createVirtualRegister(getRegClassFor(MVT::i64));
115
116 MachineBasicBlock& BB = MF.front();
117
118 unsigned args_int[] = {IA64::r32, IA64::r33, IA64::r34, IA64::r35,
119 IA64::r36, IA64::r37, IA64::r38, IA64::r39};
120
121 unsigned args_FP[] = {IA64::F8, IA64::F9, IA64::F10, IA64::F11,
122 IA64::F12,IA64::F13,IA64::F14, IA64::F15};
123
124 unsigned argVreg[8];
125 unsigned argPreg[8];
126 unsigned argOpc[8];
127
128 unsigned used_FPArgs = 0; // how many FP args have been used so far?
129
130 unsigned ArgOffset = 0;
131 int count = 0;
132
133 for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I)
134 {
135 SDOperand newroot, argt;
136 if(count < 8) { // need to fix this logic? maybe.
137
138 switch (getValueType(I->getType())) {
139 default:
140 assert(0 && "ERROR in LowerArgs: can't lower this type of arg.\n");
141 case MVT::f32:
142 // fixme? (well, will need to for weird FP structy stuff,
143 // see intel ABI docs)
144 case MVT::f64:
145//XXX BuildMI(&BB, IA64::IDEF, 0, args_FP[used_FPArgs]);
146 MF.addLiveIn(args_FP[used_FPArgs]); // mark this reg as liveIn
147 // floating point args go into f8..f15 as-needed, the increment
148 argVreg[count] = // is below..:
149 MF.getSSARegMap()->createVirtualRegister(getRegClassFor(MVT::f64));
150 // FP args go into f8..f15 as needed: (hence the ++)
151 argPreg[count] = args_FP[used_FPArgs++];
152 argOpc[count] = IA64::FMOV;
153 argt = newroot = DAG.getCopyFromReg(DAG.getRoot(), argVreg[count],
154 MVT::f64);
155 if (I->getType() == Type::FloatTy)
156 argt = DAG.getNode(ISD::FP_ROUND, MVT::f32, argt);
157 break;
158 case MVT::i1: // NOTE: as far as C abi stuff goes,
159 // bools are just boring old ints
160 case MVT::i8:
161 case MVT::i16:
162 case MVT::i32:
163 case MVT::i64:
164//XXX BuildMI(&BB, IA64::IDEF, 0, args_int[count]);
165 MF.addLiveIn(args_int[count]); // mark this register as liveIn
166 argVreg[count] =
167 MF.getSSARegMap()->createVirtualRegister(getRegClassFor(MVT::i64));
168 argPreg[count] = args_int[count];
169 argOpc[count] = IA64::MOV;
170 argt = newroot =
171 DAG.getCopyFromReg(DAG.getRoot(), argVreg[count], MVT::i64);
172 if ( getValueType(I->getType()) != MVT::i64)
173 argt = DAG.getNode(ISD::TRUNCATE, getValueType(I->getType()),
174 newroot);
175 break;
176 }
177 } else { // more than 8 args go into the frame
178 // Create the frame index object for this incoming parameter...
179 ArgOffset = 16 + 8 * (count - 8);
180 int FI = MFI->CreateFixedObject(8, ArgOffset);
181
182 // Create the SelectionDAG nodes corresponding to a load
183 //from this parameter
184 SDOperand FIN = DAG.getFrameIndex(FI, MVT::i64);
185 argt = newroot = DAG.getLoad(getValueType(I->getType()),
186 DAG.getEntryNode(), FIN, DAG.getSrcValue(NULL));
187 }
188 ++count;
189 DAG.setRoot(newroot.getValue(1));
190 ArgValues.push_back(argt);
191 }
192
193
194 // Create a vreg to hold the output of (what will become)
195 // the "alloc" instruction
196 VirtGPR = MF.getSSARegMap()->createVirtualRegister(getRegClassFor(MVT::i64));
197 BuildMI(&BB, IA64::PSEUDO_ALLOC, 0, VirtGPR);
198 // we create a PSEUDO_ALLOC (pseudo)instruction for now
Duraid Madinad3260122005-11-04 10:01:10 +0000199/*
Duraid Madinaf221c262005-10-28 17:46:35 +0000200 BuildMI(&BB, IA64::IDEF, 0, IA64::r1);
201
202 // hmm:
203 BuildMI(&BB, IA64::IDEF, 0, IA64::r12);
204 BuildMI(&BB, IA64::IDEF, 0, IA64::rp);
205 // ..hmm.
Duraid Madinad3260122005-11-04 10:01:10 +0000206
Duraid Madinaf221c262005-10-28 17:46:35 +0000207 BuildMI(&BB, IA64::MOV, 1, GP).addReg(IA64::r1);
208
209 // hmm:
210 BuildMI(&BB, IA64::MOV, 1, SP).addReg(IA64::r12);
211 BuildMI(&BB, IA64::MOV, 1, RP).addReg(IA64::rp);
212 // ..hmm.
Duraid Madinad3260122005-11-04 10:01:10 +0000213*/
Duraid Madinaf221c262005-10-28 17:46:35 +0000214
215 unsigned tempOffset=0;
216
217 // if this is a varargs function, we simply lower llvm.va_start by
218 // pointing to the first entry
219 if(F.isVarArg()) {
220 tempOffset=0;
221 VarArgsFrameIndex = MFI->CreateFixedObject(8, tempOffset);
222 }
223
224 // here we actually do the moving of args, and store them to the stack
225 // too if this is a varargs function:
226 for (int i = 0; i < count && i < 8; ++i) {
227 BuildMI(&BB, argOpc[i], 1, argVreg[i]).addReg(argPreg[i]);
228 if(F.isVarArg()) {
229 // if this is a varargs function, we copy the input registers to the stack
230 int FI = MFI->CreateFixedObject(8, tempOffset);
231 tempOffset+=8; //XXX: is it safe to use r22 like this?
232 BuildMI(&BB, IA64::MOV, 1, IA64::r22).addFrameIndex(FI);
233 // FIXME: we should use st8.spill here, one day
234 BuildMI(&BB, IA64::ST8, 1, IA64::r22).addReg(argPreg[i]);
235 }
236 }
237
238 // Finally, inform the code generator which regs we return values in.
239 // (see the ISD::RET: case in the instruction selector)
240 switch (getValueType(F.getReturnType())) {
241 default: assert(0 && "i have no idea where to return this type!");
242 case MVT::isVoid: break;
243 case MVT::i1:
244 case MVT::i8:
245 case MVT::i16:
246 case MVT::i32:
247 case MVT::i64:
248 MF.addLiveOut(IA64::r8);
249 break;
250 case MVT::f32:
251 case MVT::f64:
252 MF.addLiveOut(IA64::F8);
253 break;
254 }
255
256 return ArgValues;
257}
258
259std::pair<SDOperand, SDOperand>
260IA64TargetLowering::LowerCallTo(SDOperand Chain,
261 const Type *RetTy, bool isVarArg,
262 unsigned CallingConv, bool isTailCall,
263 SDOperand Callee, ArgListTy &Args,
264 SelectionDAG &DAG) {
265
266 MachineFunction &MF = DAG.getMachineFunction();
267
268 unsigned NumBytes = 16;
269 unsigned outRegsUsed = 0;
270
271 if (Args.size() > 8) {
272 NumBytes += (Args.size() - 8) * 8;
273 outRegsUsed = 8;
274 } else {
275 outRegsUsed = Args.size();
276 }
277
278 // FIXME? this WILL fail if we ever try to pass around an arg that
279 // consumes more than a single output slot (a 'real' double, int128
280 // some sort of aggregate etc.), as we'll underestimate how many 'outX'
281 // registers we use. Hopefully, the assembler will notice.
282 MF.getInfo<IA64FunctionInfo>()->outRegsUsed=
283 std::max(outRegsUsed, MF.getInfo<IA64FunctionInfo>()->outRegsUsed);
284
Duraid Madina5ccf76f2005-12-22 04:07:40 +0000285 // keep stack frame 16-byte aligned
286 //assert(NumBytes==((NumBytes+15) & ~15) && "stack frame not 16-byte aligned!");
287 NumBytes = (NumBytes+15) & ~15;
288
Duraid Madinaf221c262005-10-28 17:46:35 +0000289 Chain = DAG.getNode(ISD::CALLSEQ_START, MVT::Other, Chain,
290 DAG.getConstant(NumBytes, getPointerTy()));
291
Duraid Madina5ccf76f2005-12-22 04:07:40 +0000292 SDOperand StackPtr, NullSV;
293 std::vector<SDOperand> Stores;
Duraid Madina644e7db2005-12-22 13:29:14 +0000294 std::vector<SDOperand> Converts;
Duraid Madina5ccf76f2005-12-22 04:07:40 +0000295 std::vector<SDOperand> RegValuesToPass;
296 unsigned ArgOffset = 16;
297
Duraid Madinaf221c262005-10-28 17:46:35 +0000298 for (unsigned i = 0, e = Args.size(); i != e; ++i)
299 {
Duraid Madina5ccf76f2005-12-22 04:07:40 +0000300 SDOperand Val = Args[i].first;
301 MVT::ValueType ObjectVT = Val.getValueType();
Duraid Madina644e7db2005-12-22 13:29:14 +0000302 SDOperand ValToStore, ValToConvert;
Duraid Madina5ccf76f2005-12-22 04:07:40 +0000303 unsigned ObjSize=8;
304 switch (ObjectVT) {
Duraid Madinaf221c262005-10-28 17:46:35 +0000305 default: assert(0 && "unexpected argument type!");
306 case MVT::i1:
307 case MVT::i8:
308 case MVT::i16:
309 case MVT::i32:
310 //promote to 64-bits, sign/zero extending based on type
311 //of the argument
312 if(Args[i].second->isSigned())
Duraid Madina5ccf76f2005-12-22 04:07:40 +0000313 Val = DAG.getNode(ISD::SIGN_EXTEND, MVT::i64, Val);
Duraid Madinaf221c262005-10-28 17:46:35 +0000314 else
Duraid Madina5ccf76f2005-12-22 04:07:40 +0000315 Val = DAG.getNode(ISD::ZERO_EXTEND, MVT::i64, Val);
316 // XXX: fall through
317 case MVT::i64:
318 //ObjSize = 8;
319 if(RegValuesToPass.size() >= 8) {
320 ValToStore = Val;
321 } else {
322 RegValuesToPass.push_back(Val);
323 }
Duraid Madinaf221c262005-10-28 17:46:35 +0000324 break;
325 case MVT::f32:
326 //promote to 64-bits
Duraid Madina5ccf76f2005-12-22 04:07:40 +0000327 Val = DAG.getNode(ISD::FP_EXTEND, MVT::f64, Val);
328 // XXX: fall through
Duraid Madinaf221c262005-10-28 17:46:35 +0000329 case MVT::f64:
Duraid Madina5ccf76f2005-12-22 04:07:40 +0000330 if(RegValuesToPass.size() >= 8) {
331 ValToStore = Val;
332 } else {
333 RegValuesToPass.push_back(Val);
Duraid Madina644e7db2005-12-22 13:29:14 +0000334 if(1 /* TODO: if(calling external or varadic function)*/ ) {
335 ValToConvert = Val; // additionally pass this FP value as an int
336 }
Duraid Madina5ccf76f2005-12-22 04:07:40 +0000337 }
Duraid Madinaf221c262005-10-28 17:46:35 +0000338 break;
339 }
Duraid Madina5ccf76f2005-12-22 04:07:40 +0000340
341 if(ValToStore.Val) {
342 if(!StackPtr.Val) {
343 StackPtr = DAG.getRegister(IA64::r12, MVT::i64);
344 NullSV = DAG.getSrcValue(NULL);
345 }
346 SDOperand PtrOff = DAG.getConstant(ArgOffset, getPointerTy());
347 PtrOff = DAG.getNode(ISD::ADD, MVT::i64, StackPtr, PtrOff);
348 Stores.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
349 ValToStore, PtrOff, NullSV));
Duraid Madina69ac08c2005-12-27 10:17:03 +0000350 ArgOffset += ObjSize;
Duraid Madina5ccf76f2005-12-22 04:07:40 +0000351 }
Duraid Madina644e7db2005-12-22 13:29:14 +0000352
353 if(ValToConvert.Val) {
354 Converts.push_back(DAG.getNode(IA64ISD::GETFD, MVT::i64, ValToConvert));
355 }
Duraid Madinaf221c262005-10-28 17:46:35 +0000356 }
357
Duraid Madina5ccf76f2005-12-22 04:07:40 +0000358 // Emit all stores, make sure they occur before any copies into physregs.
359 if (!Stores.empty())
360 Chain = DAG.getNode(ISD::TokenFactor, MVT::Other, Stores);
Duraid Madinaf221c262005-10-28 17:46:35 +0000361
Duraid Madina5ccf76f2005-12-22 04:07:40 +0000362 static const unsigned IntArgRegs[] = {
363 IA64::out0, IA64::out1, IA64::out2, IA64::out3,
364 IA64::out4, IA64::out5, IA64::out6, IA64::out7
365 };
366
367 static const unsigned FPArgRegs[] = {
368 IA64::F8, IA64::F9, IA64::F10, IA64::F11,
369 IA64::F12, IA64::F13, IA64::F14, IA64::F15
370 };
371
372 SDOperand InFlag;
373
374 // save the current GP, SP and RP : FIXME: do we need to do all 3 always?
375 SDOperand GPBeforeCall = DAG.getCopyFromReg(Chain, IA64::r1, MVT::i64, InFlag);
376 Chain = GPBeforeCall;
377 InFlag = Chain.getValue(1);
378 SDOperand SPBeforeCall = DAG.getCopyFromReg(Chain, IA64::r12, MVT::i64, InFlag);
379 Chain = SPBeforeCall;
380 InFlag = Chain.getValue(1);
381 SDOperand RPBeforeCall = DAG.getCopyFromReg(Chain, IA64::rp, MVT::i64, InFlag);
382 Chain = RPBeforeCall;
383 InFlag = Chain.getValue(1);
384
385 // Build a sequence of copy-to-reg nodes chained together with token chain
386 // and flag operands which copy the outgoing integer args into regs out[0-7]
387 // mapped 1:1 and the FP args into regs F8-F15 "lazily"
388 // TODO: for performance, we should only copy FP args into int regs when we
389 // know this is required (i.e. for varardic or external (unknown) functions)
Duraid Madina644e7db2005-12-22 13:29:14 +0000390
391 // first to the FP->(integer representation) conversions, these are
392 // free-floating
393 unsigned seenConverts = 0;
394 for (unsigned i = 0, e = RegValuesToPass.size(); i != e; ++i) {
395 if(MVT::isFloatingPoint(RegValuesToPass[i].getValueType())) {
396 Chain = DAG.getCopyToReg(Chain, IntArgRegs[i], Converts[seenConverts++]);
397 }
398 }
399
Duraid Madina69ac08c2005-12-27 10:17:03 +0000400 // next copy args into the usual places, these are flagged
Duraid Madina5ccf76f2005-12-22 04:07:40 +0000401 unsigned usedFPArgs = 0;
402 for (unsigned i = 0, e = RegValuesToPass.size(); i != e; ++i) {
403 Chain = DAG.getCopyToReg(Chain,
404 MVT::isInteger(RegValuesToPass[i].getValueType()) ?
405 IntArgRegs[i] : FPArgRegs[usedFPArgs++],
406 RegValuesToPass[i], InFlag);
407 InFlag = Chain.getValue(1);
Duraid Madina5ccf76f2005-12-22 04:07:40 +0000408 }
409
Duraid Madina5ccf76f2005-12-22 04:07:40 +0000410 // If the callee is a GlobalAddress node (quite common, every direct call is)
411 // turn it into a TargetGlobalAddress node so that legalize doesn't hack it.
Duraid Madina644e7db2005-12-22 13:29:14 +0000412/*
413 if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) {
Duraid Madina5ccf76f2005-12-22 04:07:40 +0000414 Callee = DAG.getTargetGlobalAddress(G->getGlobal(), MVT::i64);
Duraid Madina644e7db2005-12-22 13:29:14 +0000415 }
416*/
Duraid Madina5ccf76f2005-12-22 04:07:40 +0000417
418 std::vector<MVT::ValueType> NodeTys;
Duraid Madina644e7db2005-12-22 13:29:14 +0000419 std::vector<SDOperand> CallOperands;
Duraid Madina5ccf76f2005-12-22 04:07:40 +0000420 NodeTys.push_back(MVT::Other); // Returns a chain
421 NodeTys.push_back(MVT::Flag); // Returns a flag for retval copy to use.
Duraid Madina644e7db2005-12-22 13:29:14 +0000422 CallOperands.push_back(Chain);
423 CallOperands.push_back(Callee);
424
425 // emit the call itself
Duraid Madina5ccf76f2005-12-22 04:07:40 +0000426 if (InFlag.Val)
Duraid Madina644e7db2005-12-22 13:29:14 +0000427 CallOperands.push_back(InFlag);
428
429/* out with the old...
Duraid Madina5ccf76f2005-12-22 04:07:40 +0000430 Chain = SDOperand(DAG.getCall(NodeTys, Chain, Callee, InFlag), 0);
431 else
432 Chain = SDOperand(DAG.getCall(NodeTys, Chain, Callee), 0);
Duraid Madina644e7db2005-12-22 13:29:14 +0000433*/
434 // to make way for a hack:
435 Chain = DAG.getNode(IA64ISD::BRCALL, NodeTys, CallOperands);
Duraid Madina5ccf76f2005-12-22 04:07:40 +0000436 InFlag = Chain.getValue(1);
437
438 // restore the GP, SP and RP after the call
439 Chain = DAG.getCopyToReg(Chain, IA64::r1, GPBeforeCall, InFlag);
440 InFlag = Chain.getValue(1);
441 Chain = DAG.getCopyToReg(Chain, IA64::r12, SPBeforeCall, InFlag);
442 InFlag = Chain.getValue(1);
443 Chain = DAG.getCopyToReg(Chain, IA64::rp, RPBeforeCall, InFlag);
444 InFlag = Chain.getValue(1);
Duraid Madina644e7db2005-12-22 13:29:14 +0000445
446 std::vector<MVT::ValueType> RetVals;
447 RetVals.push_back(MVT::Other);
448 RetVals.push_back(MVT::Flag);
449
Duraid Madina5ccf76f2005-12-22 04:07:40 +0000450 MVT::ValueType RetTyVT = getValueType(RetTy);
451 SDOperand RetVal;
452 if (RetTyVT != MVT::isVoid) {
453 switch (RetTyVT) {
454 default: assert(0 && "Unknown value type to return!");
455 case MVT::i1:/* { // bools are just like other integers (returned in r8)
456 SDOperand boolInR8 = DAG.getCopyFromReg(Chain, IA64::r8, MVT::i64, InFlag);
457 RetVal = DAG.getTargetNode(IA64::CMPNE, MVT::i1, // FIXME: is this flagged correctly?
458 DAG.getRegister(IA64::r0, MVT::i64), boolInR8, Chain, InFlag);
459 Chain = RetVal.getValue(1);
460 // Add a note to keep track of whether it is sign or zero extended - TODO: bools
461 RetVal = DAG.getNode(RetTy->isSigned() ? ISD::AssertSext :ISD::AssertZext,
462 MVT::i64, RetVal, DAG.getValueType(RetTyVT));
463 RetVal = DAG.getNode(ISD::TRUNCATE, RetTyVT, RetVal);
464 break;
465 }*/
466 case MVT::i8:
467 case MVT::i16:
468 case MVT::i32:
469 RetVal = DAG.getCopyFromReg(Chain, IA64::r8, MVT::i64, InFlag);
470 Chain = RetVal.getValue(1);
471
472 // Add a note to keep track of whether it is sign or zero extended - TODO: bools
473 RetVal = DAG.getNode(RetTy->isSigned() ? ISD::AssertSext :ISD::AssertZext,
474 MVT::i64, RetVal, DAG.getValueType(RetTyVT));
475 RetVal = DAG.getNode(ISD::TRUNCATE, RetTyVT, RetVal);
Duraid Madinad0c146d2005-12-22 06:39:57 +0000476 break;
Duraid Madina5ccf76f2005-12-22 04:07:40 +0000477 case MVT::i64:
478 RetVal = DAG.getCopyFromReg(Chain, IA64::r8, MVT::i64, InFlag);
479 Chain = RetVal.getValue(1);
480 break;
481 case MVT::f64:
482 RetVal = DAG.getCopyFromReg(Chain, IA64::F8, MVT::f64, InFlag);
483 Chain = RetVal.getValue(1);
484 break;
485 }
486 }
487
Duraid Madinaf221c262005-10-28 17:46:35 +0000488 Chain = DAG.getNode(ISD::CALLSEQ_END, MVT::Other, Chain,
489 DAG.getConstant(NumBytes, getPointerTy()));
Duraid Madina5ccf76f2005-12-22 04:07:40 +0000490
491 return std::make_pair(RetVal, Chain);
Duraid Madinaf221c262005-10-28 17:46:35 +0000492}
493
494SDOperand
495IA64TargetLowering::LowerVAStart(SDOperand Chain, SDOperand VAListP,
496 Value *VAListV, SelectionDAG &DAG) {
497 // vastart just stores the address of the VarArgsFrameIndex slot.
498 SDOperand FR = DAG.getFrameIndex(VarArgsFrameIndex, MVT::i64);
499 return DAG.getNode(ISD::STORE, MVT::Other, Chain, FR,
500 VAListP, DAG.getSrcValue(VAListV));
501}
502
503std::pair<SDOperand,SDOperand> IA64TargetLowering::
504LowerVAArg(SDOperand Chain, SDOperand VAListP, Value *VAListV,
505 const Type *ArgTy, SelectionDAG &DAG) {
506
507 MVT::ValueType ArgVT = getValueType(ArgTy);
508 SDOperand Val = DAG.getLoad(MVT::i64, Chain,
509 VAListP, DAG.getSrcValue(VAListV));
510 SDOperand Result = DAG.getLoad(ArgVT, DAG.getEntryNode(), Val,
511 DAG.getSrcValue(NULL));
512 unsigned Amt;
513 if (ArgVT == MVT::i32 || ArgVT == MVT::f32)
514 Amt = 8;
515 else {
516 assert((ArgVT == MVT::i64 || ArgVT == MVT::f64) &&
517 "Other types should have been promoted for varargs!");
518 Amt = 8;
519 }
520 Val = DAG.getNode(ISD::ADD, Val.getValueType(), Val,
521 DAG.getConstant(Amt, Val.getValueType()));
522 Chain = DAG.getNode(ISD::STORE, MVT::Other, Chain,
523 Val, VAListP, DAG.getSrcValue(VAListV));
524 return std::make_pair(Result, Chain);
525}
526
527
528
529std::pair<SDOperand, SDOperand> IA64TargetLowering::
530LowerFrameReturnAddress(bool isFrameAddress, SDOperand Chain, unsigned Depth,
531 SelectionDAG &DAG) {
532 assert(0 && "LowerFrameReturnAddress unimplemented");
533 abort();
534}
535