blob: a749380b864bae141598a520449160381f469000 [file] [log] [blame]
Chris Lattner76ac0682005-11-15 00:40:23 +00001//===-- X86ISelLowering.h - X86 DAG Lowering Interface ----------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Chris Lattner and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the interfaces that X86 uses to lower LLVM code into a
11// selection DAG.
12//
13//===----------------------------------------------------------------------===//
14
15#include "X86.h"
16#include "X86ISelLowering.h"
17#include "X86TargetMachine.h"
18#include "llvm/CallingConv.h"
19#include "llvm/Function.h"
Chris Lattner76ac0682005-11-15 00:40:23 +000020#include "llvm/CodeGen/MachineFrameInfo.h"
Evan Cheng339edad2006-01-11 00:33:36 +000021#include "llvm/CodeGen/MachineFunction.h"
22#include "llvm/CodeGen/MachineInstrBuilder.h"
Chris Lattner76ac0682005-11-15 00:40:23 +000023#include "llvm/CodeGen/SelectionDAG.h"
24#include "llvm/CodeGen/SSARegMap.h"
25#include "llvm/Target/TargetOptions.h"
26using namespace llvm;
27
28// FIXME: temporary.
29#include "llvm/Support/CommandLine.h"
30static cl::opt<bool> EnableFastCC("enable-x86-fastcc", cl::Hidden,
31 cl::desc("Enable fastcc on X86"));
32
33X86TargetLowering::X86TargetLowering(TargetMachine &TM)
34 : TargetLowering(TM) {
Chris Lattner76ac0682005-11-15 00:40:23 +000035 // Set up the TargetLowering object.
36
37 // X86 is weird, it always uses i8 for shift amounts and setcc results.
38 setShiftAmountType(MVT::i8);
39 setSetCCResultType(MVT::i8);
40 setSetCCResultContents(ZeroOrOneSetCCResult);
41 setShiftAmountFlavor(Mask); // shl X, 32 == shl X, 0
Chris Lattner1a8d9182006-01-13 18:00:54 +000042 setStackPointerRegisterToSaveRestore(X86::ESP);
Chris Lattner76ac0682005-11-15 00:40:23 +000043
44 // Set up the register classes.
Chris Lattner76ac0682005-11-15 00:40:23 +000045 addRegisterClass(MVT::i8, X86::R8RegisterClass);
46 addRegisterClass(MVT::i16, X86::R16RegisterClass);
47 addRegisterClass(MVT::i32, X86::R32RegisterClass);
48
49 // Promote all UINT_TO_FP to larger SINT_TO_FP's, as X86 doesn't have this
50 // operation.
51 setOperationAction(ISD::UINT_TO_FP , MVT::i1 , Promote);
52 setOperationAction(ISD::UINT_TO_FP , MVT::i8 , Promote);
53 setOperationAction(ISD::UINT_TO_FP , MVT::i16 , Promote);
54 setOperationAction(ISD::UINT_TO_FP , MVT::i32 , Promote);
55
56 // Promote i1/i8 SINT_TO_FP to larger SINT_TO_FP's, as X86 doesn't have
57 // this operation.
58 setOperationAction(ISD::SINT_TO_FP , MVT::i1 , Promote);
59 setOperationAction(ISD::SINT_TO_FP , MVT::i8 , Promote);
60
61 if (!X86ScalarSSE) {
62 // We can handle SINT_TO_FP and FP_TO_SINT from/TO i64 even though i64
63 // isn't legal.
64 setOperationAction(ISD::SINT_TO_FP , MVT::i64 , Custom);
65 setOperationAction(ISD::FP_TO_SINT , MVT::i64 , Custom);
66 setOperationAction(ISD::FP_TO_SINT , MVT::i32 , Custom);
67 setOperationAction(ISD::FP_TO_SINT , MVT::i16 , Custom);
68 }
69
70 // Handle FP_TO_UINT by promoting the destination to a larger signed
71 // conversion.
72 setOperationAction(ISD::FP_TO_UINT , MVT::i1 , Promote);
73 setOperationAction(ISD::FP_TO_UINT , MVT::i8 , Promote);
74 setOperationAction(ISD::FP_TO_UINT , MVT::i16 , Promote);
75
76 if (!X86ScalarSSE)
77 setOperationAction(ISD::FP_TO_UINT , MVT::i32 , Promote);
78
79 // Promote i1/i8 FP_TO_SINT to larger FP_TO_SINTS's, as X86 doesn't have
80 // this operation.
81 setOperationAction(ISD::FP_TO_SINT , MVT::i1 , Promote);
82 setOperationAction(ISD::FP_TO_SINT , MVT::i8 , Promote);
83 setOperationAction(ISD::FP_TO_SINT , MVT::i16 , Promote);
84
Chris Lattner30107e62005-12-23 05:15:23 +000085 setOperationAction(ISD::BIT_CONVERT, MVT::f32, Expand);
86 setOperationAction(ISD::BIT_CONVERT, MVT::i32, Expand);
87
Evan Cheng6fc31042005-12-19 23:12:38 +000088 if (X86DAGIsel) {
89 setOperationAction(ISD::BRCOND , MVT::Other, Custom);
90 }
Chris Lattner76ac0682005-11-15 00:40:23 +000091 setOperationAction(ISD::BRCONDTWOWAY , MVT::Other, Expand);
92 setOperationAction(ISD::BRTWOWAY_CC , MVT::Other, Expand);
93 setOperationAction(ISD::MEMMOVE , MVT::Other, Expand);
94 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16 , Expand);
Chris Lattner32257332005-12-07 17:59:14 +000095 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i8 , Expand);
Chris Lattner76ac0682005-11-15 00:40:23 +000096 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1 , Expand);
97 setOperationAction(ISD::FP_ROUND_INREG , MVT::f32 , Expand);
98 setOperationAction(ISD::SEXTLOAD , MVT::i1 , Expand);
99 setOperationAction(ISD::FREM , MVT::f64 , Expand);
100 setOperationAction(ISD::CTPOP , MVT::i8 , Expand);
101 setOperationAction(ISD::CTTZ , MVT::i8 , Expand);
102 setOperationAction(ISD::CTLZ , MVT::i8 , Expand);
103 setOperationAction(ISD::CTPOP , MVT::i16 , Expand);
104 setOperationAction(ISD::CTTZ , MVT::i16 , Expand);
105 setOperationAction(ISD::CTLZ , MVT::i16 , Expand);
106 setOperationAction(ISD::CTPOP , MVT::i32 , Expand);
107 setOperationAction(ISD::CTTZ , MVT::i32 , Expand);
108 setOperationAction(ISD::CTLZ , MVT::i32 , Expand);
Andrew Lenharth0bf68ae2005-11-20 21:41:10 +0000109 setOperationAction(ISD::READCYCLECOUNTER , MVT::i64 , Custom);
Chris Lattner76ac0682005-11-15 00:40:23 +0000110
Evan Cheng6d2ab042006-01-11 23:20:05 +0000111 if (!X86DAGIsel) {
Nate Begeman2fba8a32006-01-14 03:14:10 +0000112 setOperationAction(ISD::BSWAP , MVT::i32 , Expand);
Evan Cheng6d2ab042006-01-11 23:20:05 +0000113 setOperationAction(ISD::ROTL , MVT::i8 , Expand);
114 setOperationAction(ISD::ROTR , MVT::i8 , Expand);
115 setOperationAction(ISD::ROTL , MVT::i16 , Expand);
116 setOperationAction(ISD::ROTR , MVT::i16 , Expand);
117 setOperationAction(ISD::ROTL , MVT::i32 , Expand);
118 setOperationAction(ISD::ROTR , MVT::i32 , Expand);
119 }
Nate Begeman2fba8a32006-01-14 03:14:10 +0000120 setOperationAction(ISD::BSWAP , MVT::i16 , Expand);
Nate Begeman1b8121b2006-01-11 21:21:00 +0000121
Chris Lattner76ac0682005-11-15 00:40:23 +0000122 setOperationAction(ISD::READIO , MVT::i1 , Expand);
123 setOperationAction(ISD::READIO , MVT::i8 , Expand);
124 setOperationAction(ISD::READIO , MVT::i16 , Expand);
125 setOperationAction(ISD::READIO , MVT::i32 , Expand);
126 setOperationAction(ISD::WRITEIO , MVT::i1 , Expand);
127 setOperationAction(ISD::WRITEIO , MVT::i8 , Expand);
128 setOperationAction(ISD::WRITEIO , MVT::i16 , Expand);
129 setOperationAction(ISD::WRITEIO , MVT::i32 , Expand);
130
131 // These should be promoted to a larger select which is supported.
132 setOperationAction(ISD::SELECT , MVT::i1 , Promote);
133 setOperationAction(ISD::SELECT , MVT::i8 , Promote);
Evan Cheng225a4d02005-12-17 01:21:05 +0000134 if (X86DAGIsel) {
Evan Cheng172fce72006-01-06 00:43:03 +0000135 // X86 wants to expand cmov itself.
Evan Cheng225a4d02005-12-17 01:21:05 +0000136 setOperationAction(ISD::SELECT , MVT::i16 , Custom);
137 setOperationAction(ISD::SELECT , MVT::i32 , Custom);
Evan Cheng172fce72006-01-06 00:43:03 +0000138 setOperationAction(ISD::SELECT , MVT::f32 , Custom);
139 setOperationAction(ISD::SELECT , MVT::f64 , Custom);
Evan Chengc1583db2005-12-21 20:21:51 +0000140 setOperationAction(ISD::SETCC , MVT::i8 , Custom);
141 setOperationAction(ISD::SETCC , MVT::i16 , Custom);
142 setOperationAction(ISD::SETCC , MVT::i32 , Custom);
Evan Cheng172fce72006-01-06 00:43:03 +0000143 setOperationAction(ISD::SETCC , MVT::f32 , Custom);
144 setOperationAction(ISD::SETCC , MVT::f64 , Custom);
145 // X86 ret instruction may pop stack.
146 setOperationAction(ISD::RET , MVT::Other, Custom);
147 // Darwin ABI issue.
Evan Cheng9cdc16c2005-12-21 23:05:39 +0000148 setOperationAction(ISD::GlobalAddress , MVT::i32 , Custom);
Evan Cheng9c249c32006-01-09 18:33:28 +0000149 // 64-bit addm sub, shl, sra, srl (iff 32-bit x86)
150 setOperationAction(ISD::ADD_PARTS , MVT::i32 , Custom);
151 setOperationAction(ISD::SUB_PARTS , MVT::i32 , Custom);
152 setOperationAction(ISD::SHL_PARTS , MVT::i32 , Custom);
153 setOperationAction(ISD::SRA_PARTS , MVT::i32 , Custom);
154 setOperationAction(ISD::SRL_PARTS , MVT::i32 , Custom);
Evan Chengae986f12006-01-11 22:15:48 +0000155 // X86 wants to expand memset / memcpy itself.
156 setOperationAction(ISD::MEMSET , MVT::Other, Custom);
157 setOperationAction(ISD::MEMCPY , MVT::Other, Custom);
Evan Cheng225a4d02005-12-17 01:21:05 +0000158 }
Chris Lattner76ac0682005-11-15 00:40:23 +0000159
Chris Lattner9c415362005-11-29 06:16:21 +0000160 // We don't have line number support yet.
161 setOperationAction(ISD::LOCATION, MVT::Other, Expand);
Jim Laskeydeeafa02006-01-05 01:47:43 +0000162 setOperationAction(ISD::DEBUG_LOC, MVT::Other, Expand);
163 setOperationAction(ISD::DEBUG_LABEL, MVT::Other, Expand);
Chris Lattner9c415362005-11-29 06:16:21 +0000164
Chris Lattner8e2f52e2006-01-13 02:42:53 +0000165 // Not implemented yet.
166 setOperationAction(ISD::STACKSAVE, MVT::Other, Expand);
167 setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand);
168
Chris Lattner76ac0682005-11-15 00:40:23 +0000169 if (X86ScalarSSE) {
170 // Set up the FP register classes.
Evan Cheng84dc9b52006-01-12 08:27:59 +0000171 addRegisterClass(MVT::f32, X86::FR32RegisterClass);
172 addRegisterClass(MVT::f64, X86::FR64RegisterClass);
Chris Lattner76ac0682005-11-15 00:40:23 +0000173
174 // SSE has no load+extend ops
175 setOperationAction(ISD::EXTLOAD, MVT::f32, Expand);
176 setOperationAction(ISD::ZEXTLOAD, MVT::f32, Expand);
177
178 // SSE has no i16 to fp conversion, only i32
179 setOperationAction(ISD::SINT_TO_FP, MVT::i16, Promote);
180 setOperationAction(ISD::FP_TO_SINT, MVT::i16, Promote);
181
182 // Expand FP_TO_UINT into a select.
183 // FIXME: We would like to use a Custom expander here eventually to do
184 // the optimal thing for SSE vs. the default expansion in the legalizer.
185 setOperationAction(ISD::FP_TO_UINT , MVT::i32 , Expand);
186
187 // We don't support sin/cos/sqrt/fmod
188 setOperationAction(ISD::FSIN , MVT::f64, Expand);
189 setOperationAction(ISD::FCOS , MVT::f64, Expand);
190 setOperationAction(ISD::FABS , MVT::f64, Expand);
191 setOperationAction(ISD::FNEG , MVT::f64, Expand);
192 setOperationAction(ISD::FREM , MVT::f64, Expand);
193 setOperationAction(ISD::FSIN , MVT::f32, Expand);
194 setOperationAction(ISD::FCOS , MVT::f32, Expand);
195 setOperationAction(ISD::FABS , MVT::f32, Expand);
196 setOperationAction(ISD::FNEG , MVT::f32, Expand);
197 setOperationAction(ISD::FREM , MVT::f32, Expand);
198
199 addLegalFPImmediate(+0.0); // xorps / xorpd
200 } else {
201 // Set up the FP register classes.
202 addRegisterClass(MVT::f64, X86::RFPRegisterClass);
203
Evan Cheng6305e502006-01-12 22:54:21 +0000204 if (X86DAGIsel) {
205 setOperationAction(ISD::SINT_TO_FP, MVT::i16, Custom);
206 setOperationAction(ISD::SINT_TO_FP, MVT::i32, Custom);
207 }
208
Chris Lattner76ac0682005-11-15 00:40:23 +0000209 if (!UnsafeFPMath) {
210 setOperationAction(ISD::FSIN , MVT::f64 , Expand);
211 setOperationAction(ISD::FCOS , MVT::f64 , Expand);
212 }
213
214 addLegalFPImmediate(+0.0); // FLD0
215 addLegalFPImmediate(+1.0); // FLD1
216 addLegalFPImmediate(-0.0); // FLD0/FCHS
217 addLegalFPImmediate(-1.0); // FLD1/FCHS
218 }
219 computeRegisterProperties();
220
221 maxStoresPerMemSet = 8; // For %llvm.memset -> sequence of stores
222 maxStoresPerMemCpy = 8; // For %llvm.memcpy -> sequence of stores
223 maxStoresPerMemMove = 8; // For %llvm.memmove -> sequence of stores
224 allowUnalignedMemoryAccesses = true; // x86 supports it!
225}
226
227std::vector<SDOperand>
228X86TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
229 if (F.getCallingConv() == CallingConv::Fast && EnableFastCC)
230 return LowerFastCCArguments(F, DAG);
231 return LowerCCCArguments(F, DAG);
232}
233
234std::pair<SDOperand, SDOperand>
235X86TargetLowering::LowerCallTo(SDOperand Chain, const Type *RetTy,
236 bool isVarArg, unsigned CallingConv,
237 bool isTailCall,
238 SDOperand Callee, ArgListTy &Args,
239 SelectionDAG &DAG) {
240 assert((!isVarArg || CallingConv == CallingConv::C) &&
241 "Only C takes varargs!");
Evan Cheng172fce72006-01-06 00:43:03 +0000242
243 // If the callee is a GlobalAddress node (quite common, every direct call is)
244 // turn it into a TargetGlobalAddress node so that legalize doesn't hack it.
245 if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee))
246 Callee = DAG.getTargetGlobalAddress(G->getGlobal(), getPointerTy());
Evan Chengbc7a0f442006-01-11 06:09:51 +0000247 else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee))
248 Callee = DAG.getTargetExternalSymbol(S->getSymbol(), getPointerTy());
Evan Cheng172fce72006-01-06 00:43:03 +0000249
Chris Lattner76ac0682005-11-15 00:40:23 +0000250 if (CallingConv == CallingConv::Fast && EnableFastCC)
251 return LowerFastCCCallTo(Chain, RetTy, isTailCall, Callee, Args, DAG);
252 return LowerCCCCallTo(Chain, RetTy, isVarArg, isTailCall, Callee, Args, DAG);
253}
254
Evan Chenga74ce622005-12-21 02:39:21 +0000255SDOperand X86TargetLowering::LowerReturnTo(SDOperand Chain, SDOperand Op,
256 SelectionDAG &DAG) {
257 if (!X86DAGIsel)
258 return DAG.getNode(ISD::RET, MVT::Other, Chain, Op);
259
260 SDOperand Copy;
261 MVT::ValueType OpVT = Op.getValueType();
262 switch (OpVT) {
263 default: assert(0 && "Unknown type to return!");
264 case MVT::i32:
265 Copy = DAG.getCopyToReg(Chain, X86::EAX, Op, SDOperand());
266 break;
267 case MVT::i64: {
268 SDOperand Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, Op,
269 DAG.getConstant(1, MVT::i32));
270 SDOperand Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, Op,
271 DAG.getConstant(0, MVT::i32));
Evan Cheng172fce72006-01-06 00:43:03 +0000272 Copy = DAG.getCopyToReg(Chain, X86::EDX, Hi, SDOperand());
273 Copy = DAG.getCopyToReg(Copy, X86::EAX, Lo, Copy.getValue(1));
Evan Chenga74ce622005-12-21 02:39:21 +0000274 break;
275 }
276 case MVT::f32:
Evan Chenga74ce622005-12-21 02:39:21 +0000277 case MVT::f64:
278 if (!X86ScalarSSE) {
Evan Cheng9c249c32006-01-09 18:33:28 +0000279 if (OpVT == MVT::f32)
280 Op = DAG.getNode(ISD::FP_EXTEND, MVT::f64, Op);
Evan Chenga74ce622005-12-21 02:39:21 +0000281 std::vector<MVT::ValueType> Tys;
282 Tys.push_back(MVT::Other);
283 Tys.push_back(MVT::Flag);
284 std::vector<SDOperand> Ops;
285 Ops.push_back(Chain);
286 Ops.push_back(Op);
287 Copy = DAG.getNode(X86ISD::FP_SET_RESULT, Tys, Ops);
288 } else {
289 // Spill the value to memory and reload it into top of stack.
290 unsigned Size = MVT::getSizeInBits(OpVT)/8;
291 MachineFunction &MF = DAG.getMachineFunction();
292 int SSFI = MF.getFrameInfo()->CreateStackObject(Size, Size);
293 SDOperand StackSlot = DAG.getFrameIndex(SSFI, getPointerTy());
294 Chain = DAG.getNode(ISD::STORE, MVT::Other, Chain, Op,
295 StackSlot, DAG.getSrcValue(NULL));
296 std::vector<MVT::ValueType> Tys;
297 Tys.push_back(MVT::f64);
298 Tys.push_back(MVT::Other);
299 std::vector<SDOperand> Ops;
300 Ops.push_back(Chain);
301 Ops.push_back(StackSlot);
302 Ops.push_back(DAG.getValueType(OpVT));
303 Copy = DAG.getNode(X86ISD::FLD, Tys, Ops);
304 Tys.clear();
305 Tys.push_back(MVT::Other);
306 Tys.push_back(MVT::Flag);
307 Ops.clear();
308 Ops.push_back(Copy.getValue(1));
309 Ops.push_back(Copy);
310 Copy = DAG.getNode(X86ISD::FP_SET_RESULT, Tys, Ops);
311 }
312 break;
313 }
Evan Chengc1583db2005-12-21 20:21:51 +0000314
315 return DAG.getNode(X86ISD::RET_FLAG, MVT::Other,
316 Copy, DAG.getConstant(getBytesToPopOnReturn(), MVT::i16),
317 Copy.getValue(1));
Evan Chenga74ce622005-12-21 02:39:21 +0000318}
319
Chris Lattner76ac0682005-11-15 00:40:23 +0000320//===----------------------------------------------------------------------===//
321// C Calling Convention implementation
322//===----------------------------------------------------------------------===//
323
324std::vector<SDOperand>
325X86TargetLowering::LowerCCCArguments(Function &F, SelectionDAG &DAG) {
326 std::vector<SDOperand> ArgValues;
327
328 MachineFunction &MF = DAG.getMachineFunction();
329 MachineFrameInfo *MFI = MF.getFrameInfo();
330
331 // Add DAG nodes to load the arguments... On entry to a function on the X86,
332 // the stack frame looks like this:
333 //
334 // [ESP] -- return address
335 // [ESP + 4] -- first argument (leftmost lexically)
336 // [ESP + 8] -- second argument, if first argument is four bytes in size
337 // ...
338 //
339 unsigned ArgOffset = 0; // Frame mechanisms handle retaddr slot
340 for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I) {
341 MVT::ValueType ObjectVT = getValueType(I->getType());
342 unsigned ArgIncrement = 4;
343 unsigned ObjSize;
344 switch (ObjectVT) {
345 default: assert(0 && "Unhandled argument type!");
346 case MVT::i1:
347 case MVT::i8: ObjSize = 1; break;
348 case MVT::i16: ObjSize = 2; break;
349 case MVT::i32: ObjSize = 4; break;
350 case MVT::i64: ObjSize = ArgIncrement = 8; break;
351 case MVT::f32: ObjSize = 4; break;
352 case MVT::f64: ObjSize = ArgIncrement = 8; break;
353 }
354 // Create the frame index object for this incoming parameter...
355 int FI = MFI->CreateFixedObject(ObjSize, ArgOffset);
356
357 // Create the SelectionDAG nodes corresponding to a load from this parameter
358 SDOperand FIN = DAG.getFrameIndex(FI, MVT::i32);
359
360 // Don't codegen dead arguments. FIXME: remove this check when we can nuke
361 // dead loads.
362 SDOperand ArgValue;
363 if (!I->use_empty())
364 ArgValue = DAG.getLoad(ObjectVT, DAG.getEntryNode(), FIN,
365 DAG.getSrcValue(NULL));
366 else {
367 if (MVT::isInteger(ObjectVT))
368 ArgValue = DAG.getConstant(0, ObjectVT);
369 else
370 ArgValue = DAG.getConstantFP(0, ObjectVT);
371 }
372 ArgValues.push_back(ArgValue);
373
374 ArgOffset += ArgIncrement; // Move on to the next argument...
375 }
376
377 // If the function takes variable number of arguments, make a frame index for
378 // the start of the first vararg value... for expansion of llvm.va_start.
379 if (F.isVarArg())
380 VarArgsFrameIndex = MFI->CreateFixedObject(1, ArgOffset);
381 ReturnAddrIndex = 0; // No return address slot generated yet.
382 BytesToPopOnReturn = 0; // Callee pops nothing.
383 BytesCallerReserves = ArgOffset;
384
385 // Finally, inform the code generator which regs we return values in.
386 switch (getValueType(F.getReturnType())) {
387 default: assert(0 && "Unknown type!");
388 case MVT::isVoid: break;
389 case MVT::i1:
390 case MVT::i8:
391 case MVT::i16:
392 case MVT::i32:
393 MF.addLiveOut(X86::EAX);
394 break;
395 case MVT::i64:
396 MF.addLiveOut(X86::EAX);
397 MF.addLiveOut(X86::EDX);
398 break;
399 case MVT::f32:
400 case MVT::f64:
401 MF.addLiveOut(X86::ST0);
402 break;
403 }
404 return ArgValues;
405}
406
407std::pair<SDOperand, SDOperand>
408X86TargetLowering::LowerCCCCallTo(SDOperand Chain, const Type *RetTy,
409 bool isVarArg, bool isTailCall,
410 SDOperand Callee, ArgListTy &Args,
411 SelectionDAG &DAG) {
412 // Count how many bytes are to be pushed on the stack.
413 unsigned NumBytes = 0;
414
415 if (Args.empty()) {
416 // Save zero bytes.
417 Chain = DAG.getNode(ISD::CALLSEQ_START, MVT::Other, Chain,
418 DAG.getConstant(0, getPointerTy()));
419 } else {
420 for (unsigned i = 0, e = Args.size(); i != e; ++i)
421 switch (getValueType(Args[i].second)) {
422 default: assert(0 && "Unknown value type!");
423 case MVT::i1:
424 case MVT::i8:
425 case MVT::i16:
426 case MVT::i32:
427 case MVT::f32:
428 NumBytes += 4;
429 break;
430 case MVT::i64:
431 case MVT::f64:
432 NumBytes += 8;
433 break;
434 }
435
436 Chain = DAG.getNode(ISD::CALLSEQ_START, MVT::Other, Chain,
437 DAG.getConstant(NumBytes, getPointerTy()));
438
439 // Arguments go on the stack in reverse order, as specified by the ABI.
440 unsigned ArgOffset = 0;
Evan Chengbc7a0f442006-01-11 06:09:51 +0000441 SDOperand StackPtr = DAG.getRegister(X86::ESP, MVT::i32);
Chris Lattner76ac0682005-11-15 00:40:23 +0000442 std::vector<SDOperand> Stores;
443
444 for (unsigned i = 0, e = Args.size(); i != e; ++i) {
445 SDOperand PtrOff = DAG.getConstant(ArgOffset, getPointerTy());
446 PtrOff = DAG.getNode(ISD::ADD, MVT::i32, StackPtr, PtrOff);
447
448 switch (getValueType(Args[i].second)) {
449 default: assert(0 && "Unexpected ValueType for argument!");
450 case MVT::i1:
451 case MVT::i8:
452 case MVT::i16:
453 // Promote the integer to 32 bits. If the input type is signed use a
454 // sign extend, otherwise use a zero extend.
455 if (Args[i].second->isSigned())
456 Args[i].first =DAG.getNode(ISD::SIGN_EXTEND, MVT::i32, Args[i].first);
457 else
458 Args[i].first =DAG.getNode(ISD::ZERO_EXTEND, MVT::i32, Args[i].first);
459
460 // FALL THROUGH
461 case MVT::i32:
462 case MVT::f32:
463 Stores.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
464 Args[i].first, PtrOff,
465 DAG.getSrcValue(NULL)));
466 ArgOffset += 4;
467 break;
468 case MVT::i64:
469 case MVT::f64:
470 Stores.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
471 Args[i].first, PtrOff,
472 DAG.getSrcValue(NULL)));
473 ArgOffset += 8;
474 break;
475 }
476 }
477 Chain = DAG.getNode(ISD::TokenFactor, MVT::Other, Stores);
478 }
479
480 std::vector<MVT::ValueType> RetVals;
481 MVT::ValueType RetTyVT = getValueType(RetTy);
482 RetVals.push_back(MVT::Other);
483
484 // The result values produced have to be legal. Promote the result.
485 switch (RetTyVT) {
486 case MVT::isVoid: break;
487 default:
488 RetVals.push_back(RetTyVT);
489 break;
490 case MVT::i1:
491 case MVT::i8:
492 case MVT::i16:
493 RetVals.push_back(MVT::i32);
494 break;
495 case MVT::f32:
496 if (X86ScalarSSE)
497 RetVals.push_back(MVT::f32);
498 else
499 RetVals.push_back(MVT::f64);
500 break;
501 case MVT::i64:
502 RetVals.push_back(MVT::i32);
503 RetVals.push_back(MVT::i32);
504 break;
505 }
Chris Lattner76ac0682005-11-15 00:40:23 +0000506
Evan Cheng45e190982006-01-05 00:27:02 +0000507 if (X86DAGIsel) {
508 std::vector<MVT::ValueType> NodeTys;
509 NodeTys.push_back(MVT::Other); // Returns a chain
510 NodeTys.push_back(MVT::Flag); // Returns a flag for retval copy to use.
Evan Cheng45e190982006-01-05 00:27:02 +0000511 std::vector<SDOperand> Ops;
512 Ops.push_back(Chain);
513 Ops.push_back(Callee);
514
Evan Cheng172fce72006-01-06 00:43:03 +0000515 // FIXME: Do not generate X86ISD::TAILCALL for now.
516 Chain = DAG.getNode(X86ISD::CALL, NodeTys, Ops);
Evan Cheng45e190982006-01-05 00:27:02 +0000517 SDOperand InFlag = Chain.getValue(1);
518
519 SDOperand RetVal;
520 if (RetTyVT != MVT::isVoid) {
521 switch (RetTyVT) {
522 default: assert(0 && "Unknown value type to return!");
523 case MVT::i1:
524 case MVT::i8:
525 RetVal = DAG.getCopyFromReg(Chain, X86::AL, MVT::i8, InFlag);
526 Chain = RetVal.getValue(1);
527 break;
528 case MVT::i16:
529 RetVal = DAG.getCopyFromReg(Chain, X86::AX, MVT::i16, InFlag);
530 Chain = RetVal.getValue(1);
531 break;
532 case MVT::i32:
533 RetVal = DAG.getCopyFromReg(Chain, X86::EAX, MVT::i32, InFlag);
534 Chain = RetVal.getValue(1);
535 break;
536 case MVT::i64: {
537 SDOperand Lo = DAG.getCopyFromReg(Chain, X86::EAX, MVT::i32, InFlag);
538 SDOperand Hi = DAG.getCopyFromReg(Lo.getValue(1), X86::EDX, MVT::i32,
539 Lo.getValue(2));
540 RetVal = DAG.getNode(ISD::BUILD_PAIR, MVT::i64, Lo, Hi);
541 Chain = Hi.getValue(1);
542 break;
543 }
544 case MVT::f32:
545 case MVT::f64: {
546 std::vector<MVT::ValueType> Tys;
547 Tys.push_back(MVT::f64);
548 Tys.push_back(MVT::Other);
549 std::vector<SDOperand> Ops;
550 Ops.push_back(Chain);
551 Ops.push_back(InFlag);
552 RetVal = DAG.getNode(X86ISD::FP_GET_RESULT, Tys, Ops);
553 Chain = RetVal.getValue(1);
554 if (X86ScalarSSE) {
555 unsigned Size = MVT::getSizeInBits(MVT::f64)/8;
556 MachineFunction &MF = DAG.getMachineFunction();
557 int SSFI = MF.getFrameInfo()->CreateStackObject(Size, Size);
558 SDOperand StackSlot = DAG.getFrameIndex(SSFI, getPointerTy());
559 Tys.clear();
560 Tys.push_back(MVT::Other);
561 Ops.clear();
562 Ops.push_back(Chain);
563 Ops.push_back(RetVal);
564 Ops.push_back(StackSlot);
565 Ops.push_back(DAG.getValueType(RetTyVT));
566 Chain = DAG.getNode(X86ISD::FST, Tys, Ops);
567 RetVal = DAG.getLoad(RetTyVT, Chain, StackSlot,
568 DAG.getSrcValue(NULL));
569 Chain = RetVal.getValue(1);
570 } else if (RetTyVT == MVT::f32)
571 RetVal = DAG.getNode(ISD::FP_ROUND, MVT::f32, RetVal);
572 break;
573 }
574 }
575 }
576
577 Chain = DAG.getNode(ISD::CALLSEQ_END, MVT::Other, Chain,
578 DAG.getConstant(NumBytes, getPointerTy()),
579 DAG.getConstant(0, getPointerTy()));
580 return std::make_pair(RetVal, Chain);
581 } else {
582 std::vector<SDOperand> Ops;
583 Ops.push_back(Chain);
584 Ops.push_back(Callee);
585 Ops.push_back(DAG.getConstant(NumBytes, getPointerTy()));
586 Ops.push_back(DAG.getConstant(0, getPointerTy()));
587
588 SDOperand TheCall = DAG.getNode(isTailCall ? X86ISD::TAILCALL : X86ISD::CALL,
589 RetVals, Ops);
590
591 SDOperand ResultVal;
592 switch (RetTyVT) {
593 case MVT::isVoid: break;
594 default:
595 ResultVal = TheCall.getValue(1);
596 break;
597 case MVT::i1:
598 case MVT::i8:
599 case MVT::i16:
600 ResultVal = DAG.getNode(ISD::TRUNCATE, RetTyVT, TheCall.getValue(1));
601 break;
602 case MVT::f32:
603 // FIXME: we would really like to remember that this FP_ROUND operation is
604 // okay to eliminate if we allow excess FP precision.
605 ResultVal = DAG.getNode(ISD::FP_ROUND, MVT::f32, TheCall.getValue(1));
606 break;
607 case MVT::i64:
608 ResultVal = DAG.getNode(ISD::BUILD_PAIR, MVT::i64, TheCall.getValue(1),
609 TheCall.getValue(2));
610 break;
611 }
612
613 Chain = DAG.getNode(ISD::CALLSEQ_END, MVT::Other, TheCall);
614 return std::make_pair(ResultVal, Chain);
Chris Lattner76ac0682005-11-15 00:40:23 +0000615 }
Chris Lattner76ac0682005-11-15 00:40:23 +0000616}
617
618SDOperand
619X86TargetLowering::LowerVAStart(SDOperand Chain, SDOperand VAListP,
620 Value *VAListV, SelectionDAG &DAG) {
621 // vastart just stores the address of the VarArgsFrameIndex slot.
622 SDOperand FR = DAG.getFrameIndex(VarArgsFrameIndex, MVT::i32);
623 return DAG.getNode(ISD::STORE, MVT::Other, Chain, FR, VAListP,
624 DAG.getSrcValue(VAListV));
625}
626
627
628std::pair<SDOperand,SDOperand>
629X86TargetLowering::LowerVAArg(SDOperand Chain, SDOperand VAListP,
630 Value *VAListV, const Type *ArgTy,
631 SelectionDAG &DAG) {
632 MVT::ValueType ArgVT = getValueType(ArgTy);
633 SDOperand Val = DAG.getLoad(MVT::i32, Chain,
634 VAListP, DAG.getSrcValue(VAListV));
635 SDOperand Result = DAG.getLoad(ArgVT, Chain, Val,
636 DAG.getSrcValue(NULL));
637 unsigned Amt;
638 if (ArgVT == MVT::i32)
639 Amt = 4;
640 else {
641 assert((ArgVT == MVT::i64 || ArgVT == MVT::f64) &&
642 "Other types should have been promoted for varargs!");
643 Amt = 8;
644 }
645 Val = DAG.getNode(ISD::ADD, Val.getValueType(), Val,
646 DAG.getConstant(Amt, Val.getValueType()));
647 Chain = DAG.getNode(ISD::STORE, MVT::Other, Chain,
648 Val, VAListP, DAG.getSrcValue(VAListV));
649 return std::make_pair(Result, Chain);
650}
651
652//===----------------------------------------------------------------------===//
653// Fast Calling Convention implementation
654//===----------------------------------------------------------------------===//
655//
656// The X86 'fast' calling convention passes up to two integer arguments in
657// registers (an appropriate portion of EAX/EDX), passes arguments in C order,
658// and requires that the callee pop its arguments off the stack (allowing proper
659// tail calls), and has the same return value conventions as C calling convs.
660//
661// This calling convention always arranges for the callee pop value to be 8n+4
662// bytes, which is needed for tail recursion elimination and stack alignment
663// reasons.
664//
665// Note that this can be enhanced in the future to pass fp vals in registers
666// (when we have a global fp allocator) and do other tricks.
667//
668
669/// AddLiveIn - This helper function adds the specified physical register to the
670/// MachineFunction as a live in value. It also creates a corresponding virtual
671/// register for it.
672static unsigned AddLiveIn(MachineFunction &MF, unsigned PReg,
673 TargetRegisterClass *RC) {
674 assert(RC->contains(PReg) && "Not the correct regclass!");
675 unsigned VReg = MF.getSSARegMap()->createVirtualRegister(RC);
676 MF.addLiveIn(PReg, VReg);
677 return VReg;
678}
679
680
681std::vector<SDOperand>
682X86TargetLowering::LowerFastCCArguments(Function &F, SelectionDAG &DAG) {
683 std::vector<SDOperand> ArgValues;
684
685 MachineFunction &MF = DAG.getMachineFunction();
686 MachineFrameInfo *MFI = MF.getFrameInfo();
687
688 // Add DAG nodes to load the arguments... On entry to a function the stack
689 // frame looks like this:
690 //
691 // [ESP] -- return address
692 // [ESP + 4] -- first nonreg argument (leftmost lexically)
693 // [ESP + 8] -- second nonreg argument, if first argument is 4 bytes in size
694 // ...
695 unsigned ArgOffset = 0; // Frame mechanisms handle retaddr slot
696
697 // Keep track of the number of integer regs passed so far. This can be either
698 // 0 (neither EAX or EDX used), 1 (EAX is used) or 2 (EAX and EDX are both
699 // used).
700 unsigned NumIntRegs = 0;
701
702 for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I) {
703 MVT::ValueType ObjectVT = getValueType(I->getType());
704 unsigned ArgIncrement = 4;
705 unsigned ObjSize = 0;
706 SDOperand ArgValue;
707
708 switch (ObjectVT) {
709 default: assert(0 && "Unhandled argument type!");
710 case MVT::i1:
711 case MVT::i8:
712 if (NumIntRegs < 2) {
713 if (!I->use_empty()) {
714 unsigned VReg = AddLiveIn(MF, NumIntRegs ? X86::DL : X86::AL,
715 X86::R8RegisterClass);
716 ArgValue = DAG.getCopyFromReg(DAG.getRoot(), VReg, MVT::i8);
717 DAG.setRoot(ArgValue.getValue(1));
Chris Lattner82584892005-12-27 03:02:18 +0000718 if (ObjectVT == MVT::i1)
719 // FIXME: Should insert a assertzext here.
720 ArgValue = DAG.getNode(ISD::TRUNCATE, MVT::i1, ArgValue);
Chris Lattner76ac0682005-11-15 00:40:23 +0000721 }
722 ++NumIntRegs;
723 break;
724 }
725
726 ObjSize = 1;
727 break;
728 case MVT::i16:
729 if (NumIntRegs < 2) {
730 if (!I->use_empty()) {
731 unsigned VReg = AddLiveIn(MF, NumIntRegs ? X86::DX : X86::AX,
732 X86::R16RegisterClass);
733 ArgValue = DAG.getCopyFromReg(DAG.getRoot(), VReg, MVT::i16);
734 DAG.setRoot(ArgValue.getValue(1));
735 }
736 ++NumIntRegs;
737 break;
738 }
739 ObjSize = 2;
740 break;
741 case MVT::i32:
742 if (NumIntRegs < 2) {
743 if (!I->use_empty()) {
744 unsigned VReg = AddLiveIn(MF,NumIntRegs ? X86::EDX : X86::EAX,
745 X86::R32RegisterClass);
746 ArgValue = DAG.getCopyFromReg(DAG.getRoot(), VReg, MVT::i32);
747 DAG.setRoot(ArgValue.getValue(1));
748 }
749 ++NumIntRegs;
750 break;
751 }
752 ObjSize = 4;
753 break;
754 case MVT::i64:
755 if (NumIntRegs == 0) {
756 if (!I->use_empty()) {
757 unsigned BotReg = AddLiveIn(MF, X86::EAX, X86::R32RegisterClass);
758 unsigned TopReg = AddLiveIn(MF, X86::EDX, X86::R32RegisterClass);
759
760 SDOperand Low = DAG.getCopyFromReg(DAG.getRoot(), BotReg, MVT::i32);
761 SDOperand Hi = DAG.getCopyFromReg(Low.getValue(1), TopReg, MVT::i32);
762 DAG.setRoot(Hi.getValue(1));
763
764 ArgValue = DAG.getNode(ISD::BUILD_PAIR, MVT::i64, Low, Hi);
765 }
766 NumIntRegs = 2;
767 break;
768 } else if (NumIntRegs == 1) {
769 if (!I->use_empty()) {
770 unsigned BotReg = AddLiveIn(MF, X86::EDX, X86::R32RegisterClass);
771 SDOperand Low = DAG.getCopyFromReg(DAG.getRoot(), BotReg, MVT::i32);
772 DAG.setRoot(Low.getValue(1));
773
774 // Load the high part from memory.
775 // Create the frame index object for this incoming parameter...
776 int FI = MFI->CreateFixedObject(4, ArgOffset);
777 SDOperand FIN = DAG.getFrameIndex(FI, MVT::i32);
778 SDOperand Hi = DAG.getLoad(MVT::i32, DAG.getEntryNode(), FIN,
779 DAG.getSrcValue(NULL));
780 ArgValue = DAG.getNode(ISD::BUILD_PAIR, MVT::i64, Low, Hi);
781 }
782 ArgOffset += 4;
783 NumIntRegs = 2;
784 break;
785 }
786 ObjSize = ArgIncrement = 8;
787 break;
788 case MVT::f32: ObjSize = 4; break;
789 case MVT::f64: ObjSize = ArgIncrement = 8; break;
790 }
791
792 // Don't codegen dead arguments. FIXME: remove this check when we can nuke
793 // dead loads.
794 if (ObjSize && !I->use_empty()) {
795 // Create the frame index object for this incoming parameter...
796 int FI = MFI->CreateFixedObject(ObjSize, ArgOffset);
797
798 // Create the SelectionDAG nodes corresponding to a load from this
799 // parameter.
800 SDOperand FIN = DAG.getFrameIndex(FI, MVT::i32);
801
802 ArgValue = DAG.getLoad(ObjectVT, DAG.getEntryNode(), FIN,
803 DAG.getSrcValue(NULL));
804 } else if (ArgValue.Val == 0) {
805 if (MVT::isInteger(ObjectVT))
806 ArgValue = DAG.getConstant(0, ObjectVT);
807 else
808 ArgValue = DAG.getConstantFP(0, ObjectVT);
809 }
810 ArgValues.push_back(ArgValue);
811
812 if (ObjSize)
813 ArgOffset += ArgIncrement; // Move on to the next argument.
814 }
815
816 // Make sure the instruction takes 8n+4 bytes to make sure the start of the
817 // arguments and the arguments after the retaddr has been pushed are aligned.
818 if ((ArgOffset & 7) == 0)
819 ArgOffset += 4;
820
821 VarArgsFrameIndex = 0xAAAAAAA; // fastcc functions can't have varargs.
822 ReturnAddrIndex = 0; // No return address slot generated yet.
823 BytesToPopOnReturn = ArgOffset; // Callee pops all stack arguments.
824 BytesCallerReserves = 0;
825
826 // Finally, inform the code generator which regs we return values in.
827 switch (getValueType(F.getReturnType())) {
828 default: assert(0 && "Unknown type!");
829 case MVT::isVoid: break;
830 case MVT::i1:
831 case MVT::i8:
832 case MVT::i16:
833 case MVT::i32:
834 MF.addLiveOut(X86::EAX);
835 break;
836 case MVT::i64:
837 MF.addLiveOut(X86::EAX);
838 MF.addLiveOut(X86::EDX);
839 break;
840 case MVT::f32:
841 case MVT::f64:
842 MF.addLiveOut(X86::ST0);
843 break;
844 }
845 return ArgValues;
846}
847
848std::pair<SDOperand, SDOperand>
849X86TargetLowering::LowerFastCCCallTo(SDOperand Chain, const Type *RetTy,
850 bool isTailCall, SDOperand Callee,
851 ArgListTy &Args, SelectionDAG &DAG) {
852 // Count how many bytes are to be pushed on the stack.
853 unsigned NumBytes = 0;
854
855 // Keep track of the number of integer regs passed so far. This can be either
856 // 0 (neither EAX or EDX used), 1 (EAX is used) or 2 (EAX and EDX are both
857 // used).
858 unsigned NumIntRegs = 0;
859
860 for (unsigned i = 0, e = Args.size(); i != e; ++i)
861 switch (getValueType(Args[i].second)) {
862 default: assert(0 && "Unknown value type!");
863 case MVT::i1:
864 case MVT::i8:
865 case MVT::i16:
866 case MVT::i32:
867 if (NumIntRegs < 2) {
868 ++NumIntRegs;
869 break;
870 }
871 // fall through
872 case MVT::f32:
873 NumBytes += 4;
874 break;
875 case MVT::i64:
876 if (NumIntRegs == 0) {
877 NumIntRegs = 2;
878 break;
879 } else if (NumIntRegs == 1) {
880 NumIntRegs = 2;
881 NumBytes += 4;
882 break;
883 }
884
885 // fall through
886 case MVT::f64:
887 NumBytes += 8;
888 break;
889 }
890
891 // Make sure the instruction takes 8n+4 bytes to make sure the start of the
892 // arguments and the arguments after the retaddr has been pushed are aligned.
893 if ((NumBytes & 7) == 0)
894 NumBytes += 4;
895
896 Chain = DAG.getNode(ISD::CALLSEQ_START, MVT::Other, Chain,
897 DAG.getConstant(NumBytes, getPointerTy()));
898
899 // Arguments go on the stack in reverse order, as specified by the ABI.
900 unsigned ArgOffset = 0;
901 SDOperand StackPtr = DAG.getCopyFromReg(DAG.getEntryNode(),
902 X86::ESP, MVT::i32);
903 NumIntRegs = 0;
904 std::vector<SDOperand> Stores;
905 std::vector<SDOperand> RegValuesToPass;
906 for (unsigned i = 0, e = Args.size(); i != e; ++i) {
907 switch (getValueType(Args[i].second)) {
908 default: assert(0 && "Unexpected ValueType for argument!");
909 case MVT::i1:
Chris Lattner82584892005-12-27 03:02:18 +0000910 Args[i].first = DAG.getNode(ISD::ANY_EXTEND, MVT::i8, Args[i].first);
911 // Fall through.
Chris Lattner76ac0682005-11-15 00:40:23 +0000912 case MVT::i8:
913 case MVT::i16:
914 case MVT::i32:
915 if (NumIntRegs < 2) {
916 RegValuesToPass.push_back(Args[i].first);
917 ++NumIntRegs;
918 break;
919 }
920 // Fall through
921 case MVT::f32: {
922 SDOperand PtrOff = DAG.getConstant(ArgOffset, getPointerTy());
923 PtrOff = DAG.getNode(ISD::ADD, MVT::i32, StackPtr, PtrOff);
924 Stores.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
925 Args[i].first, PtrOff,
926 DAG.getSrcValue(NULL)));
927 ArgOffset += 4;
928 break;
929 }
930 case MVT::i64:
931 if (NumIntRegs < 2) { // Can pass part of it in regs?
932 SDOperand Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32,
933 Args[i].first, DAG.getConstant(1, MVT::i32));
934 SDOperand Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32,
935 Args[i].first, DAG.getConstant(0, MVT::i32));
936 RegValuesToPass.push_back(Lo);
937 ++NumIntRegs;
938 if (NumIntRegs < 2) { // Pass both parts in regs?
939 RegValuesToPass.push_back(Hi);
940 ++NumIntRegs;
941 } else {
942 // Pass the high part in memory.
943 SDOperand PtrOff = DAG.getConstant(ArgOffset, getPointerTy());
944 PtrOff = DAG.getNode(ISD::ADD, MVT::i32, StackPtr, PtrOff);
945 Stores.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
946 Hi, PtrOff, DAG.getSrcValue(NULL)));
947 ArgOffset += 4;
948 }
949 break;
950 }
951 // Fall through
952 case MVT::f64:
953 SDOperand PtrOff = DAG.getConstant(ArgOffset, getPointerTy());
954 PtrOff = DAG.getNode(ISD::ADD, MVT::i32, StackPtr, PtrOff);
955 Stores.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
956 Args[i].first, PtrOff,
957 DAG.getSrcValue(NULL)));
958 ArgOffset += 8;
959 break;
960 }
961 }
962 if (!Stores.empty())
963 Chain = DAG.getNode(ISD::TokenFactor, MVT::Other, Stores);
964
965 // Make sure the instruction takes 8n+4 bytes to make sure the start of the
966 // arguments and the arguments after the retaddr has been pushed are aligned.
967 if ((ArgOffset & 7) == 0)
968 ArgOffset += 4;
969
970 std::vector<MVT::ValueType> RetVals;
971 MVT::ValueType RetTyVT = getValueType(RetTy);
972
973 RetVals.push_back(MVT::Other);
974
975 // The result values produced have to be legal. Promote the result.
976 switch (RetTyVT) {
977 case MVT::isVoid: break;
978 default:
979 RetVals.push_back(RetTyVT);
980 break;
981 case MVT::i1:
982 case MVT::i8:
983 case MVT::i16:
984 RetVals.push_back(MVT::i32);
985 break;
986 case MVT::f32:
987 if (X86ScalarSSE)
988 RetVals.push_back(MVT::f32);
989 else
990 RetVals.push_back(MVT::f64);
991 break;
992 case MVT::i64:
993 RetVals.push_back(MVT::i32);
994 RetVals.push_back(MVT::i32);
995 break;
996 }
997
Evan Cheng172fce72006-01-06 00:43:03 +0000998 if (X86DAGIsel) {
999 // Build a sequence of copy-to-reg nodes chained together with token chain
1000 // and flag operands which copy the outgoing args into registers.
1001 SDOperand InFlag;
1002 for (unsigned i = 0, e = RegValuesToPass.size(); i != e; ++i) {
1003 unsigned CCReg;
1004 SDOperand RegToPass = RegValuesToPass[i];
1005 switch (RegToPass.getValueType()) {
1006 default: assert(0 && "Bad thing to pass in regs");
1007 case MVT::i8:
1008 CCReg = (i == 0) ? X86::AL : X86::DL;
1009 break;
1010 case MVT::i16:
1011 CCReg = (i == 0) ? X86::AX : X86::DX;
1012 break;
1013 case MVT::i32:
1014 CCReg = (i == 0) ? X86::EAX : X86::EDX;
1015 break;
1016 }
Chris Lattner76ac0682005-11-15 00:40:23 +00001017
Evan Cheng172fce72006-01-06 00:43:03 +00001018 Chain = DAG.getCopyToReg(Chain, CCReg, RegToPass, InFlag);
1019 InFlag = Chain.getValue(1);
1020 }
Chris Lattner76ac0682005-11-15 00:40:23 +00001021
Evan Cheng172fce72006-01-06 00:43:03 +00001022 std::vector<MVT::ValueType> NodeTys;
1023 NodeTys.push_back(MVT::Other); // Returns a chain
1024 NodeTys.push_back(MVT::Flag); // Returns a flag for retval copy to use.
Evan Cheng172fce72006-01-06 00:43:03 +00001025 std::vector<SDOperand> Ops;
1026 Ops.push_back(Chain);
1027 Ops.push_back(Callee);
1028 if (InFlag.Val)
1029 Ops.push_back(InFlag);
1030
1031 // FIXME: Do not generate X86ISD::TAILCALL for now.
1032 Chain = DAG.getNode(X86ISD::CALL, NodeTys, Ops);
1033 InFlag = Chain.getValue(1);
1034
1035 SDOperand RetVal;
1036 if (RetTyVT != MVT::isVoid) {
1037 switch (RetTyVT) {
1038 default: assert(0 && "Unknown value type to return!");
1039 case MVT::i1:
1040 case MVT::i8:
1041 RetVal = DAG.getCopyFromReg(Chain, X86::AL, MVT::i8, InFlag);
1042 Chain = RetVal.getValue(1);
1043 break;
1044 case MVT::i16:
1045 RetVal = DAG.getCopyFromReg(Chain, X86::AX, MVT::i16, InFlag);
1046 Chain = RetVal.getValue(1);
1047 break;
1048 case MVT::i32:
1049 RetVal = DAG.getCopyFromReg(Chain, X86::EAX, MVT::i32, InFlag);
1050 Chain = RetVal.getValue(1);
1051 break;
1052 case MVT::i64: {
1053 SDOperand Lo = DAG.getCopyFromReg(Chain, X86::EAX, MVT::i32, InFlag);
1054 SDOperand Hi = DAG.getCopyFromReg(Lo.getValue(1), X86::EDX, MVT::i32,
1055 Lo.getValue(2));
1056 RetVal = DAG.getNode(ISD::BUILD_PAIR, MVT::i64, Lo, Hi);
1057 Chain = Hi.getValue(1);
1058 break;
1059 }
1060 case MVT::f32:
1061 case MVT::f64: {
1062 std::vector<MVT::ValueType> Tys;
1063 Tys.push_back(MVT::f64);
1064 Tys.push_back(MVT::Other);
1065 std::vector<SDOperand> Ops;
1066 Ops.push_back(Chain);
1067 Ops.push_back(InFlag);
1068 RetVal = DAG.getNode(X86ISD::FP_GET_RESULT, Tys, Ops);
1069 Chain = RetVal.getValue(1);
1070 if (X86ScalarSSE) {
1071 unsigned Size = MVT::getSizeInBits(MVT::f64)/8;
1072 MachineFunction &MF = DAG.getMachineFunction();
1073 int SSFI = MF.getFrameInfo()->CreateStackObject(Size, Size);
1074 SDOperand StackSlot = DAG.getFrameIndex(SSFI, getPointerTy());
1075 Tys.clear();
1076 Tys.push_back(MVT::Other);
1077 Ops.clear();
1078 Ops.push_back(Chain);
1079 Ops.push_back(RetVal);
1080 Ops.push_back(StackSlot);
1081 Ops.push_back(DAG.getValueType(RetTyVT));
1082 Chain = DAG.getNode(X86ISD::FST, Tys, Ops);
1083 RetVal = DAG.getLoad(RetTyVT, Chain, StackSlot,
1084 DAG.getSrcValue(NULL));
1085 Chain = RetVal.getValue(1);
1086 } else if (RetTyVT == MVT::f32)
1087 RetVal = DAG.getNode(ISD::FP_ROUND, MVT::f32, RetVal);
1088 break;
1089 }
1090 }
1091 }
1092
1093 Chain = DAG.getNode(ISD::CALLSEQ_END, MVT::Other, Chain,
1094 DAG.getConstant(ArgOffset, getPointerTy()),
1095 DAG.getConstant(ArgOffset, getPointerTy()));
1096 return std::make_pair(RetVal, Chain);
1097 } else {
1098 std::vector<SDOperand> Ops;
1099 Ops.push_back(Chain);
1100 Ops.push_back(Callee);
1101 Ops.push_back(DAG.getConstant(ArgOffset, getPointerTy()));
1102 // Callee pops all arg values on the stack.
1103 Ops.push_back(DAG.getConstant(ArgOffset, getPointerTy()));
1104
1105 // Pass register arguments as needed.
1106 Ops.insert(Ops.end(), RegValuesToPass.begin(), RegValuesToPass.end());
1107
1108 SDOperand TheCall = DAG.getNode(isTailCall ? X86ISD::TAILCALL : X86ISD::CALL,
1109 RetVals, Ops);
1110 Chain = DAG.getNode(ISD::CALLSEQ_END, MVT::Other, TheCall);
1111
1112 SDOperand ResultVal;
1113 switch (RetTyVT) {
1114 case MVT::isVoid: break;
1115 default:
1116 ResultVal = TheCall.getValue(1);
1117 break;
1118 case MVT::i1:
1119 case MVT::i8:
1120 case MVT::i16:
1121 ResultVal = DAG.getNode(ISD::TRUNCATE, RetTyVT, TheCall.getValue(1));
1122 break;
1123 case MVT::f32:
1124 // FIXME: we would really like to remember that this FP_ROUND operation is
1125 // okay to eliminate if we allow excess FP precision.
1126 ResultVal = DAG.getNode(ISD::FP_ROUND, MVT::f32, TheCall.getValue(1));
1127 break;
1128 case MVT::i64:
1129 ResultVal = DAG.getNode(ISD::BUILD_PAIR, MVT::i64, TheCall.getValue(1),
1130 TheCall.getValue(2));
1131 break;
1132 }
1133
1134 return std::make_pair(ResultVal, Chain);
Chris Lattner76ac0682005-11-15 00:40:23 +00001135 }
Chris Lattner76ac0682005-11-15 00:40:23 +00001136}
1137
1138SDOperand X86TargetLowering::getReturnAddressFrameIndex(SelectionDAG &DAG) {
1139 if (ReturnAddrIndex == 0) {
1140 // Set up a frame object for the return address.
1141 MachineFunction &MF = DAG.getMachineFunction();
1142 ReturnAddrIndex = MF.getFrameInfo()->CreateFixedObject(4, -4);
1143 }
1144
1145 return DAG.getFrameIndex(ReturnAddrIndex, MVT::i32);
1146}
1147
1148
1149
1150std::pair<SDOperand, SDOperand> X86TargetLowering::
1151LowerFrameReturnAddress(bool isFrameAddress, SDOperand Chain, unsigned Depth,
1152 SelectionDAG &DAG) {
1153 SDOperand Result;
1154 if (Depth) // Depths > 0 not supported yet!
1155 Result = DAG.getConstant(0, getPointerTy());
1156 else {
1157 SDOperand RetAddrFI = getReturnAddressFrameIndex(DAG);
1158 if (!isFrameAddress)
1159 // Just load the return address
1160 Result = DAG.getLoad(MVT::i32, DAG.getEntryNode(), RetAddrFI,
1161 DAG.getSrcValue(NULL));
1162 else
1163 Result = DAG.getNode(ISD::SUB, MVT::i32, RetAddrFI,
1164 DAG.getConstant(4, MVT::i32));
1165 }
1166 return std::make_pair(Result, Chain);
1167}
1168
Evan Cheng339edad2006-01-11 00:33:36 +00001169/// getCondBrOpcodeForX86CC - Returns the X86 conditional branch opcode
1170/// which corresponds to the condition code.
1171static unsigned getCondBrOpcodeForX86CC(unsigned X86CC) {
1172 switch (X86CC) {
1173 default: assert(0 && "Unknown X86 conditional code!");
1174 case X86ISD::COND_A: return X86::JA;
1175 case X86ISD::COND_AE: return X86::JAE;
1176 case X86ISD::COND_B: return X86::JB;
1177 case X86ISD::COND_BE: return X86::JBE;
1178 case X86ISD::COND_E: return X86::JE;
1179 case X86ISD::COND_G: return X86::JG;
1180 case X86ISD::COND_GE: return X86::JGE;
1181 case X86ISD::COND_L: return X86::JL;
1182 case X86ISD::COND_LE: return X86::JLE;
1183 case X86ISD::COND_NE: return X86::JNE;
1184 case X86ISD::COND_NO: return X86::JNO;
1185 case X86ISD::COND_NP: return X86::JNP;
1186 case X86ISD::COND_NS: return X86::JNS;
1187 case X86ISD::COND_O: return X86::JO;
1188 case X86ISD::COND_P: return X86::JP;
1189 case X86ISD::COND_S: return X86::JS;
1190 }
1191}
Chris Lattner76ac0682005-11-15 00:40:23 +00001192
Evan Cheng339edad2006-01-11 00:33:36 +00001193/// getX86CC - do a one to one translation of a ISD::CondCode to the X86
1194/// specific condition code. It returns a X86ISD::COND_INVALID if it cannot
Evan Cheng172fce72006-01-06 00:43:03 +00001195/// do a direct translation.
Evan Cheng339edad2006-01-11 00:33:36 +00001196static unsigned getX86CC(SDOperand CC, bool isFP) {
Evan Cheng172fce72006-01-06 00:43:03 +00001197 ISD::CondCode SetCCOpcode = cast<CondCodeSDNode>(CC)->get();
1198 unsigned X86CC = X86ISD::COND_INVALID;
1199 if (!isFP) {
1200 switch (SetCCOpcode) {
1201 default: break;
1202 case ISD::SETEQ: X86CC = X86ISD::COND_E; break;
1203 case ISD::SETGT: X86CC = X86ISD::COND_G; break;
1204 case ISD::SETGE: X86CC = X86ISD::COND_GE; break;
1205 case ISD::SETLT: X86CC = X86ISD::COND_L; break;
1206 case ISD::SETLE: X86CC = X86ISD::COND_LE; break;
1207 case ISD::SETNE: X86CC = X86ISD::COND_NE; break;
1208 case ISD::SETULT: X86CC = X86ISD::COND_B; break;
1209 case ISD::SETUGT: X86CC = X86ISD::COND_A; break;
1210 case ISD::SETULE: X86CC = X86ISD::COND_BE; break;
1211 case ISD::SETUGE: X86CC = X86ISD::COND_AE; break;
1212 }
1213 } else {
1214 // On a floating point condition, the flags are set as follows:
1215 // ZF PF CF op
1216 // 0 | 0 | 0 | X > Y
1217 // 0 | 0 | 1 | X < Y
1218 // 1 | 0 | 0 | X == Y
1219 // 1 | 1 | 1 | unordered
1220 switch (SetCCOpcode) {
1221 default: break;
1222 case ISD::SETUEQ:
1223 case ISD::SETEQ: X86CC = X86ISD::COND_E; break;
1224 case ISD::SETOGT:
1225 case ISD::SETGT: X86CC = X86ISD::COND_A; break;
1226 case ISD::SETOGE:
1227 case ISD::SETGE: X86CC = X86ISD::COND_AE; break;
1228 case ISD::SETULT:
1229 case ISD::SETLT: X86CC = X86ISD::COND_B; break;
1230 case ISD::SETULE:
1231 case ISD::SETLE: X86CC = X86ISD::COND_BE; break;
1232 case ISD::SETONE:
1233 case ISD::SETNE: X86CC = X86ISD::COND_NE; break;
1234 case ISD::SETUO: X86CC = X86ISD::COND_P; break;
1235 case ISD::SETO: X86CC = X86ISD::COND_NP; break;
1236 }
1237 }
1238 return X86CC;
1239}
1240
Evan Cheng339edad2006-01-11 00:33:36 +00001241/// hasFPCMov - is there a floating point cmov for the specific X86 condition
1242/// code. Current x86 isa includes the following FP cmov instructions:
Evan Cheng73a1ad92006-01-10 20:26:56 +00001243/// fcmovb, fcomvbe, fcomve, fcmovu, fcmovae, fcmova, fcmovne, fcmovnu.
Evan Cheng339edad2006-01-11 00:33:36 +00001244static bool hasFPCMov(unsigned X86CC) {
Evan Cheng73a1ad92006-01-10 20:26:56 +00001245 switch (X86CC) {
1246 default:
1247 return false;
1248 case X86ISD::COND_B:
1249 case X86ISD::COND_BE:
1250 case X86ISD::COND_E:
1251 case X86ISD::COND_P:
1252 case X86ISD::COND_A:
1253 case X86ISD::COND_AE:
1254 case X86ISD::COND_NE:
1255 case X86ISD::COND_NP:
1256 return true;
1257 }
1258}
1259
Evan Cheng339edad2006-01-11 00:33:36 +00001260MachineBasicBlock *
1261X86TargetLowering::InsertAtEndOfBasicBlock(MachineInstr *MI,
1262 MachineBasicBlock *BB) {
1263 assert((MI->getOpcode() == X86::CMOV_FR32 ||
1264 MI->getOpcode() == X86::CMOV_FR64) &&
1265 "Unexpected instr type to insert");
1266
1267 // To "insert" a SELECT_CC instruction, we actually have to insert the diamond
1268 // control-flow pattern. The incoming instruction knows the destination vreg
1269 // to set, the condition code register to branch on, the true/false values to
1270 // select between, and a branch opcode to use.
1271 const BasicBlock *LLVM_BB = BB->getBasicBlock();
1272 ilist<MachineBasicBlock>::iterator It = BB;
1273 ++It;
1274
1275 // thisMBB:
1276 // ...
1277 // TrueVal = ...
1278 // cmpTY ccX, r1, r2
1279 // bCC copy1MBB
1280 // fallthrough --> copy0MBB
1281 MachineBasicBlock *thisMBB = BB;
1282 MachineBasicBlock *copy0MBB = new MachineBasicBlock(LLVM_BB);
1283 MachineBasicBlock *sinkMBB = new MachineBasicBlock(LLVM_BB);
1284 unsigned Opc = getCondBrOpcodeForX86CC(MI->getOperand(3).getImmedValue());
1285 BuildMI(BB, Opc, 1).addMBB(sinkMBB);
1286 MachineFunction *F = BB->getParent();
1287 F->getBasicBlockList().insert(It, copy0MBB);
1288 F->getBasicBlockList().insert(It, sinkMBB);
1289 // Update machine-CFG edges
1290 BB->addSuccessor(copy0MBB);
1291 BB->addSuccessor(sinkMBB);
1292
1293 // copy0MBB:
1294 // %FalseValue = ...
1295 // # fallthrough to sinkMBB
1296 BB = copy0MBB;
1297
1298 // Update machine-CFG edges
1299 BB->addSuccessor(sinkMBB);
1300
1301 // sinkMBB:
1302 // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ]
1303 // ...
1304 BB = sinkMBB;
1305 BuildMI(BB, X86::PHI, 4, MI->getOperand(0).getReg())
1306 .addReg(MI->getOperand(1).getReg()).addMBB(copy0MBB)
1307 .addReg(MI->getOperand(2).getReg()).addMBB(thisMBB);
1308
1309 delete MI; // The pseudo instruction is gone now.
1310 return BB;
1311}
1312
1313
1314//===----------------------------------------------------------------------===//
1315// X86 Custom Lowering Hooks
1316//===----------------------------------------------------------------------===//
1317
Chris Lattner76ac0682005-11-15 00:40:23 +00001318/// LowerOperation - Provide custom lowering hooks for some operations.
1319///
1320SDOperand X86TargetLowering::LowerOperation(SDOperand Op, SelectionDAG &DAG) {
1321 switch (Op.getOpcode()) {
1322 default: assert(0 && "Should not custom lower this!");
Evan Cheng9c249c32006-01-09 18:33:28 +00001323 case ISD::ADD_PARTS:
1324 case ISD::SUB_PARTS: {
1325 assert(Op.getNumOperands() == 4 && Op.getValueType() == MVT::i32 &&
1326 "Not an i64 add/sub!");
1327 bool isAdd = Op.getOpcode() == ISD::ADD_PARTS;
1328 std::vector<MVT::ValueType> Tys;
1329 Tys.push_back(MVT::i32);
1330 Tys.push_back(MVT::Flag);
1331 std::vector<SDOperand> Ops;
1332 Ops.push_back(Op.getOperand(0));
1333 Ops.push_back(Op.getOperand(2));
1334 SDOperand Lo = DAG.getNode(isAdd ? X86ISD::ADD_FLAG : X86ISD::SUB_FLAG,
1335 Tys, Ops);
1336 SDOperand Hi = DAG.getNode(isAdd ? X86ISD::ADC : X86ISD::SBB, MVT::i32,
1337 Op.getOperand(1), Op.getOperand(3),
1338 Lo.getValue(1));
1339 Tys.clear();
1340 Tys.push_back(MVT::i32);
1341 Tys.push_back(MVT::i32);
1342 Ops.clear();
1343 Ops.push_back(Lo);
1344 Ops.push_back(Hi);
1345 return DAG.getNode(ISD::MERGE_VALUES, Tys, Ops);
1346 }
1347 case ISD::SHL_PARTS:
1348 case ISD::SRA_PARTS:
1349 case ISD::SRL_PARTS: {
1350 assert(Op.getNumOperands() == 3 && Op.getValueType() == MVT::i32 &&
1351 "Not an i64 shift!");
1352 bool isSRA = Op.getOpcode() == ISD::SRA_PARTS;
1353 SDOperand ShOpLo = Op.getOperand(0);
1354 SDOperand ShOpHi = Op.getOperand(1);
1355 SDOperand ShAmt = Op.getOperand(2);
1356 SDOperand Tmp1 = isSRA ? DAG.getNode(ISD::SRA, MVT::i32, ShOpHi,
Evan Cheng12181af2006-01-09 22:29:54 +00001357 DAG.getConstant(31, MVT::i32))
Evan Cheng9c249c32006-01-09 18:33:28 +00001358 : DAG.getConstant(0, MVT::i32);
1359
1360 SDOperand Tmp2, Tmp3;
1361 if (Op.getOpcode() == ISD::SHL_PARTS) {
1362 Tmp2 = DAG.getNode(X86ISD::SHLD, MVT::i32, ShOpHi, ShOpLo, ShAmt);
1363 Tmp3 = DAG.getNode(ISD::SHL, MVT::i32, ShOpLo, ShAmt);
1364 } else {
1365 Tmp2 = DAG.getNode(X86ISD::SHRD, MVT::i32, ShOpLo, ShOpHi, ShAmt);
1366 Tmp3 = DAG.getNode(isSRA ? ISD::SRA : ISD::SHL, MVT::i32, ShOpHi, ShAmt);
1367 }
1368
1369 SDOperand InFlag = DAG.getNode(X86ISD::TEST, MVT::Flag,
1370 ShAmt, DAG.getConstant(32, MVT::i8));
1371
1372 SDOperand Hi, Lo;
Evan Cheng77fa9192006-01-09 20:49:21 +00001373 SDOperand CC = DAG.getConstant(X86ISD::COND_NE, MVT::i8);
Evan Cheng9c249c32006-01-09 18:33:28 +00001374
1375 std::vector<MVT::ValueType> Tys;
1376 Tys.push_back(MVT::i32);
1377 Tys.push_back(MVT::Flag);
1378 std::vector<SDOperand> Ops;
1379 if (Op.getOpcode() == ISD::SHL_PARTS) {
1380 Ops.push_back(Tmp2);
1381 Ops.push_back(Tmp3);
1382 Ops.push_back(CC);
1383 Ops.push_back(InFlag);
1384 Hi = DAG.getNode(X86ISD::CMOV, Tys, Ops);
1385 InFlag = Hi.getValue(1);
1386
1387 Ops.clear();
1388 Ops.push_back(Tmp3);
1389 Ops.push_back(Tmp1);
1390 Ops.push_back(CC);
1391 Ops.push_back(InFlag);
1392 Lo = DAG.getNode(X86ISD::CMOV, Tys, Ops);
1393 } else {
1394 Ops.push_back(Tmp2);
1395 Ops.push_back(Tmp3);
1396 Ops.push_back(CC);
Evan Cheng12181af2006-01-09 22:29:54 +00001397 Ops.push_back(InFlag);
Evan Cheng9c249c32006-01-09 18:33:28 +00001398 Lo = DAG.getNode(X86ISD::CMOV, Tys, Ops);
1399 InFlag = Lo.getValue(1);
1400
1401 Ops.clear();
1402 Ops.push_back(Tmp3);
1403 Ops.push_back(Tmp1);
1404 Ops.push_back(CC);
1405 Ops.push_back(InFlag);
1406 Hi = DAG.getNode(X86ISD::CMOV, Tys, Ops);
1407 }
1408
1409 Tys.clear();
1410 Tys.push_back(MVT::i32);
1411 Tys.push_back(MVT::i32);
1412 Ops.clear();
1413 Ops.push_back(Lo);
1414 Ops.push_back(Hi);
1415 return DAG.getNode(ISD::MERGE_VALUES, Tys, Ops);
1416 }
Chris Lattner76ac0682005-11-15 00:40:23 +00001417 case ISD::SINT_TO_FP: {
1418 assert(Op.getValueType() == MVT::f64 &&
Evan Cheng6305e502006-01-12 22:54:21 +00001419 Op.getOperand(0).getValueType() <= MVT::i64 &&
1420 Op.getOperand(0).getValueType() >= MVT::i16 &&
Chris Lattner76ac0682005-11-15 00:40:23 +00001421 "Unknown SINT_TO_FP to lower!");
Evan Cheng6305e502006-01-12 22:54:21 +00001422
1423 SDOperand Result;
1424 MVT::ValueType SrcVT = Op.getOperand(0).getValueType();
1425 unsigned Size = MVT::getSizeInBits(SrcVT)/8;
Chris Lattner76ac0682005-11-15 00:40:23 +00001426 MachineFunction &MF = DAG.getMachineFunction();
Evan Cheng6305e502006-01-12 22:54:21 +00001427 int SSFI = MF.getFrameInfo()->CreateStackObject(Size, Size);
Chris Lattner76ac0682005-11-15 00:40:23 +00001428 SDOperand StackSlot = DAG.getFrameIndex(SSFI, getPointerTy());
Evan Cheng6305e502006-01-12 22:54:21 +00001429 SDOperand Chain = DAG.getNode(ISD::STORE, MVT::Other,
1430 DAG.getEntryNode(), Op.getOperand(0),
1431 StackSlot, DAG.getSrcValue(NULL));
1432
1433 // Build the FILD
1434 std::vector<MVT::ValueType> Tys;
1435 Tys.push_back(MVT::f64);
1436 Tys.push_back(MVT::Flag);
Chris Lattner76ac0682005-11-15 00:40:23 +00001437 std::vector<SDOperand> Ops;
Evan Cheng6305e502006-01-12 22:54:21 +00001438 Ops.push_back(Chain);
Chris Lattner76ac0682005-11-15 00:40:23 +00001439 Ops.push_back(StackSlot);
Evan Cheng6305e502006-01-12 22:54:21 +00001440 Ops.push_back(DAG.getValueType(SrcVT));
1441 Result = DAG.getNode(X86ISD::FILD, Tys, Ops);
1442 return Result;
Chris Lattner76ac0682005-11-15 00:40:23 +00001443 }
1444 case ISD::FP_TO_SINT: {
1445 assert(Op.getValueType() <= MVT::i64 && Op.getValueType() >= MVT::i16 &&
1446 Op.getOperand(0).getValueType() == MVT::f64 &&
1447 "Unknown FP_TO_SINT to lower!");
1448 // We lower FP->sint64 into FISTP64, followed by a load, all to a temporary
1449 // stack slot.
1450 MachineFunction &MF = DAG.getMachineFunction();
1451 unsigned MemSize = MVT::getSizeInBits(Op.getValueType())/8;
1452 int SSFI = MF.getFrameInfo()->CreateStackObject(MemSize, MemSize);
1453 SDOperand StackSlot = DAG.getFrameIndex(SSFI, getPointerTy());
1454
1455 unsigned Opc;
1456 switch (Op.getValueType()) {
1457 default: assert(0 && "Invalid FP_TO_SINT to lower!");
1458 case MVT::i16: Opc = X86ISD::FP_TO_INT16_IN_MEM; break;
1459 case MVT::i32: Opc = X86ISD::FP_TO_INT32_IN_MEM; break;
1460 case MVT::i64: Opc = X86ISD::FP_TO_INT64_IN_MEM; break;
1461 }
1462
1463 // Build the FP_TO_INT*_IN_MEM
1464 std::vector<SDOperand> Ops;
1465 Ops.push_back(DAG.getEntryNode());
1466 Ops.push_back(Op.getOperand(0));
1467 Ops.push_back(StackSlot);
1468 SDOperand FIST = DAG.getNode(Opc, MVT::Other, Ops);
1469
1470 // Load the result.
1471 return DAG.getLoad(Op.getValueType(), FIST, StackSlot,
1472 DAG.getSrcValue(NULL));
1473 }
Andrew Lenharth0bf68ae2005-11-20 21:41:10 +00001474 case ISD::READCYCLECOUNTER: {
Chris Lattner6df9e112005-11-20 22:01:40 +00001475 std::vector<MVT::ValueType> Tys;
1476 Tys.push_back(MVT::Other);
1477 Tys.push_back(MVT::Flag);
1478 std::vector<SDOperand> Ops;
1479 Ops.push_back(Op.getOperand(0));
1480 SDOperand rd = DAG.getNode(X86ISD::RDTSC_DAG, Tys, Ops);
Chris Lattner6c1ca882005-11-20 22:57:19 +00001481 Ops.clear();
1482 Ops.push_back(DAG.getCopyFromReg(rd, X86::EAX, MVT::i32, rd.getValue(1)));
1483 Ops.push_back(DAG.getCopyFromReg(Ops[0].getValue(1), X86::EDX,
1484 MVT::i32, Ops[0].getValue(2)));
1485 Ops.push_back(Ops[1].getValue(1));
1486 Tys[0] = Tys[1] = MVT::i32;
1487 Tys.push_back(MVT::Other);
1488 return DAG.getNode(ISD::MERGE_VALUES, Tys, Ops);
Andrew Lenharth0bf68ae2005-11-20 21:41:10 +00001489 }
Evan Chengc1583db2005-12-21 20:21:51 +00001490 case ISD::SETCC: {
1491 assert(Op.getValueType() == MVT::i8 && "SetCC type must be 8-bit integer");
1492 SDOperand CC = Op.getOperand(2);
1493 SDOperand Cond = DAG.getNode(X86ISD::CMP, MVT::Flag,
1494 Op.getOperand(0), Op.getOperand(1));
Evan Cheng172fce72006-01-06 00:43:03 +00001495 ISD::CondCode SetCCOpcode = cast<CondCodeSDNode>(CC)->get();
1496 bool isFP = MVT::isFloatingPoint(Op.getOperand(1).getValueType());
Evan Cheng339edad2006-01-11 00:33:36 +00001497 unsigned X86CC = getX86CC(CC, isFP);
Evan Cheng172fce72006-01-06 00:43:03 +00001498 if (X86CC != X86ISD::COND_INVALID) {
1499 return DAG.getNode(X86ISD::SETCC, MVT::i8,
1500 DAG.getConstant(X86CC, MVT::i8), Cond);
1501 } else {
1502 assert(isFP && "Illegal integer SetCC!");
1503
1504 std::vector<MVT::ValueType> Tys;
1505 std::vector<SDOperand> Ops;
1506 switch (SetCCOpcode) {
1507 default: assert(false && "Illegal floating point SetCC!");
1508 case ISD::SETOEQ: { // !PF & ZF
1509 Tys.push_back(MVT::i8);
1510 Tys.push_back(MVT::Flag);
1511 Ops.push_back(DAG.getConstant(X86ISD::COND_NP, MVT::i8));
1512 Ops.push_back(Cond);
1513 SDOperand Tmp1 = DAG.getNode(X86ISD::SETCC, Tys, Ops);
1514 SDOperand Tmp2 = DAG.getNode(X86ISD::SETCC, MVT::i8,
1515 DAG.getConstant(X86ISD::COND_E, MVT::i8),
1516 Tmp1.getValue(1));
1517 return DAG.getNode(ISD::AND, MVT::i8, Tmp1, Tmp2);
1518 }
1519 case ISD::SETOLT: { // !PF & CF
1520 Tys.push_back(MVT::i8);
1521 Tys.push_back(MVT::Flag);
1522 Ops.push_back(DAG.getConstant(X86ISD::COND_NP, MVT::i8));
1523 Ops.push_back(Cond);
1524 SDOperand Tmp1 = DAG.getNode(X86ISD::SETCC, Tys, Ops);
1525 SDOperand Tmp2 = DAG.getNode(X86ISD::SETCC, MVT::i8,
1526 DAG.getConstant(X86ISD::COND_B, MVT::i8),
1527 Tmp1.getValue(1));
1528 return DAG.getNode(ISD::AND, MVT::i8, Tmp1, Tmp2);
1529 }
1530 case ISD::SETOLE: { // !PF & (CF || ZF)
1531 Tys.push_back(MVT::i8);
1532 Tys.push_back(MVT::Flag);
1533 Ops.push_back(DAG.getConstant(X86ISD::COND_NP, MVT::i8));
1534 Ops.push_back(Cond);
1535 SDOperand Tmp1 = DAG.getNode(X86ISD::SETCC, Tys, Ops);
1536 SDOperand Tmp2 = DAG.getNode(X86ISD::SETCC, MVT::i8,
1537 DAG.getConstant(X86ISD::COND_BE, MVT::i8),
1538 Tmp1.getValue(1));
1539 return DAG.getNode(ISD::AND, MVT::i8, Tmp1, Tmp2);
1540 }
1541 case ISD::SETUGT: { // PF | (!ZF & !CF)
1542 Tys.push_back(MVT::i8);
1543 Tys.push_back(MVT::Flag);
1544 Ops.push_back(DAG.getConstant(X86ISD::COND_P, MVT::i8));
1545 Ops.push_back(Cond);
1546 SDOperand Tmp1 = DAG.getNode(X86ISD::SETCC, Tys, Ops);
1547 SDOperand Tmp2 = DAG.getNode(X86ISD::SETCC, MVT::i8,
1548 DAG.getConstant(X86ISD::COND_A, MVT::i8),
1549 Tmp1.getValue(1));
1550 return DAG.getNode(ISD::OR, MVT::i8, Tmp1, Tmp2);
1551 }
1552 case ISD::SETUGE: { // PF | !CF
1553 Tys.push_back(MVT::i8);
1554 Tys.push_back(MVT::Flag);
1555 Ops.push_back(DAG.getConstant(X86ISD::COND_P, MVT::i8));
1556 Ops.push_back(Cond);
1557 SDOperand Tmp1 = DAG.getNode(X86ISD::SETCC, Tys, Ops);
1558 SDOperand Tmp2 = DAG.getNode(X86ISD::SETCC, MVT::i8,
1559 DAG.getConstant(X86ISD::COND_AE, MVT::i8),
1560 Tmp1.getValue(1));
1561 return DAG.getNode(ISD::OR, MVT::i8, Tmp1, Tmp2);
1562 }
1563 case ISD::SETUNE: { // PF | !ZF
1564 Tys.push_back(MVT::i8);
1565 Tys.push_back(MVT::Flag);
1566 Ops.push_back(DAG.getConstant(X86ISD::COND_P, MVT::i8));
1567 Ops.push_back(Cond);
1568 SDOperand Tmp1 = DAG.getNode(X86ISD::SETCC, Tys, Ops);
1569 SDOperand Tmp2 = DAG.getNode(X86ISD::SETCC, MVT::i8,
1570 DAG.getConstant(X86ISD::COND_NE, MVT::i8),
1571 Tmp1.getValue(1));
1572 return DAG.getNode(ISD::OR, MVT::i8, Tmp1, Tmp2);
1573 }
1574 }
1575 }
Evan Chengc1583db2005-12-21 20:21:51 +00001576 }
Evan Cheng225a4d02005-12-17 01:21:05 +00001577 case ISD::SELECT: {
Evan Cheng73a1ad92006-01-10 20:26:56 +00001578 MVT::ValueType VT = Op.getValueType();
1579 bool isFP = MVT::isFloatingPoint(VT);
1580 bool isFPStack = isFP && (X86Vector < SSE2);
1581 bool isFPSSE = isFP && (X86Vector >= SSE2);
Evan Chengfb22e862006-01-13 01:03:02 +00001582 bool addTest = false;
Evan Cheng73a1ad92006-01-10 20:26:56 +00001583 SDOperand Op0 = Op.getOperand(0);
1584 SDOperand Cond, CC;
1585 if (Op0.getOpcode() == X86ISD::SETCC) {
Evan Chengfb22e862006-01-13 01:03:02 +00001586 // If condition flag is set by a X86ISD::CMP, then make a copy of it
1587 // (since flag operand cannot be shared). If the X86ISD::SETCC does not
1588 // have another use it will be eliminated.
1589 // If the X86ISD::SETCC has more than one use, then it's probably better
1590 // to use a test instead of duplicating the X86ISD::CMP (for register
1591 // pressure reason).
Evan Chengd7faa4b2006-01-13 01:17:24 +00001592 if (Op0.hasOneUse() && Op0.getOperand(1).getOpcode() == X86ISD::CMP) {
Evan Chengfb22e862006-01-13 01:03:02 +00001593 CC = Op0.getOperand(0);
1594 Cond = Op0.getOperand(1);
1595 addTest =
Evan Chengd7faa4b2006-01-13 01:17:24 +00001596 isFPStack && !hasFPCMov(cast<ConstantSDNode>(CC)->getSignExtended());
Evan Chengfb22e862006-01-13 01:03:02 +00001597 } else
1598 addTest = true;
Evan Cheng73a1ad92006-01-10 20:26:56 +00001599 } else if (Op0.getOpcode() == ISD::SETCC) {
1600 CC = Op0.getOperand(2);
1601 bool isFP = MVT::isFloatingPoint(Op0.getOperand(1).getValueType());
Evan Cheng339edad2006-01-11 00:33:36 +00001602 unsigned X86CC = getX86CC(CC, isFP);
Evan Cheng172fce72006-01-06 00:43:03 +00001603 CC = DAG.getConstant(X86CC, MVT::i8);
Evan Cheng225a4d02005-12-17 01:21:05 +00001604 Cond = DAG.getNode(X86ISD::CMP, MVT::Flag,
Evan Cheng73a1ad92006-01-10 20:26:56 +00001605 Op0.getOperand(0), Op0.getOperand(1));
Evan Chengfb22e862006-01-13 01:03:02 +00001606 addTest = true;
1607 } else
1608 addTest = true;
Evan Cheng73a1ad92006-01-10 20:26:56 +00001609
Evan Cheng731423f2006-01-13 01:06:49 +00001610 if (addTest) {
Evan Chengdba84bb2006-01-13 19:51:46 +00001611 CC = DAG.getConstant(X86ISD::COND_NE, MVT::i8);
Evan Cheng73a1ad92006-01-10 20:26:56 +00001612 Cond = DAG.getNode(X86ISD::TEST, MVT::Flag, Op0, Op0);
Evan Cheng225a4d02005-12-17 01:21:05 +00001613 }
Evan Cheng9c249c32006-01-09 18:33:28 +00001614
1615 std::vector<MVT::ValueType> Tys;
1616 Tys.push_back(Op.getValueType());
1617 Tys.push_back(MVT::Flag);
1618 std::vector<SDOperand> Ops;
Evan Chengdba84bb2006-01-13 19:51:46 +00001619 // X86ISD::CMOV means set the result (which is operand 1) to the RHS if
1620 // condition is true.
Evan Cheng9c249c32006-01-09 18:33:28 +00001621 Ops.push_back(Op.getOperand(2));
Evan Chengdba84bb2006-01-13 19:51:46 +00001622 Ops.push_back(Op.getOperand(1));
Evan Cheng9c249c32006-01-09 18:33:28 +00001623 Ops.push_back(CC);
1624 Ops.push_back(Cond);
1625 return DAG.getNode(X86ISD::CMOV, Tys, Ops);
Evan Cheng225a4d02005-12-17 01:21:05 +00001626 }
Evan Cheng6fc31042005-12-19 23:12:38 +00001627 case ISD::BRCOND: {
Evan Chengfb22e862006-01-13 01:03:02 +00001628 bool addTest = false;
Evan Cheng6fc31042005-12-19 23:12:38 +00001629 SDOperand Cond = Op.getOperand(1);
1630 SDOperand Dest = Op.getOperand(2);
1631 SDOperand CC;
Evan Chengc1583db2005-12-21 20:21:51 +00001632 if (Cond.getOpcode() == X86ISD::SETCC) {
Evan Chengfb22e862006-01-13 01:03:02 +00001633 // If condition flag is set by a X86ISD::CMP, then make a copy of it
1634 // (since flag operand cannot be shared). If the X86ISD::SETCC does not
1635 // have another use it will be eliminated.
1636 // If the X86ISD::SETCC has more than one use, then it's probably better
1637 // to use a test instead of duplicating the X86ISD::CMP (for register
1638 // pressure reason).
1639 if (Cond.hasOneUse() && Cond.getOperand(1).getOpcode() == X86ISD::CMP) {
1640 CC = Cond.getOperand(0);
1641 Cond = DAG.getNode(X86ISD::CMP, MVT::Flag,
1642 Cond.getOperand(1).getOperand(0),
1643 Cond.getOperand(1).getOperand(1));
1644 } else
1645 addTest = true;
Evan Chengc1583db2005-12-21 20:21:51 +00001646 } else if (Cond.getOpcode() == ISD::SETCC) {
Evan Cheng6fc31042005-12-19 23:12:38 +00001647 CC = Cond.getOperand(2);
Evan Cheng172fce72006-01-06 00:43:03 +00001648 bool isFP = MVT::isFloatingPoint(Cond.getOperand(1).getValueType());
Evan Cheng339edad2006-01-11 00:33:36 +00001649 unsigned X86CC = getX86CC(CC, isFP);
Evan Cheng172fce72006-01-06 00:43:03 +00001650 CC = DAG.getConstant(X86CC, MVT::i8);
Evan Cheng6fc31042005-12-19 23:12:38 +00001651 Cond = DAG.getNode(X86ISD::CMP, MVT::Flag,
1652 Cond.getOperand(0), Cond.getOperand(1));
Evan Chengfb22e862006-01-13 01:03:02 +00001653 } else
1654 addTest = true;
1655
1656 if (addTest) {
Evan Cheng172fce72006-01-06 00:43:03 +00001657 CC = DAG.getConstant(X86ISD::COND_NE, MVT::i8);
Evan Cheng6fc31042005-12-19 23:12:38 +00001658 Cond = DAG.getNode(X86ISD::TEST, MVT::Flag, Cond, Cond);
1659 }
1660 return DAG.getNode(X86ISD::BRCOND, Op.getValueType(),
1661 Op.getOperand(0), Op.getOperand(2), CC, Cond);
1662 }
Evan Cheng172fce72006-01-06 00:43:03 +00001663 case ISD::RET: {
1664 // Can only be return void.
Evan Cheng9c249c32006-01-09 18:33:28 +00001665 return DAG.getNode(X86ISD::RET_FLAG, MVT::Other, Op.getOperand(0),
Evan Cheng172fce72006-01-06 00:43:03 +00001666 DAG.getConstant(getBytesToPopOnReturn(), MVT::i16));
1667 }
Evan Chengae986f12006-01-11 22:15:48 +00001668 case ISD::MEMSET: {
1669 SDOperand InFlag;
1670 SDOperand Chain = Op.getOperand(0);
1671 unsigned Align =
1672 (unsigned)cast<ConstantSDNode>(Op.getOperand(4))->getValue();
1673 if (Align == 0) Align = 1;
1674
1675 MVT::ValueType AVT;
1676 SDOperand Count;
1677 if (ConstantSDNode *ValC = dyn_cast<ConstantSDNode>(Op.getOperand(2))) {
1678 unsigned ValReg;
1679 unsigned Val = ValC->getValue() & 255;
1680
1681 // If the value is a constant, then we can potentially use larger sets.
1682 switch (Align & 3) {
1683 case 2: // WORD aligned
1684 AVT = MVT::i16;
1685 if (ConstantSDNode *I = dyn_cast<ConstantSDNode>(Op.getOperand(3)))
1686 Count = DAG.getConstant(I->getValue() / 2, MVT::i32);
1687 else
1688 Count = DAG.getNode(ISD::SRL, MVT::i32, Op.getOperand(3),
1689 DAG.getConstant(1, MVT::i8));
1690 Val = (Val << 8) | Val;
1691 ValReg = X86::AX;
1692 break;
1693 case 0: // DWORD aligned
1694 AVT = MVT::i32;
1695 if (ConstantSDNode *I = dyn_cast<ConstantSDNode>(Op.getOperand(3)))
1696 Count = DAG.getConstant(I->getValue() / 4, MVT::i32);
1697 else
1698 Count = DAG.getNode(ISD::SRL, MVT::i32, Op.getOperand(3),
1699 DAG.getConstant(2, MVT::i8));
1700 Val = (Val << 8) | Val;
1701 Val = (Val << 16) | Val;
1702 ValReg = X86::EAX;
1703 break;
1704 default: // Byte aligned
1705 AVT = MVT::i8;
1706 Count = Op.getOperand(3);
1707 ValReg = X86::AL;
1708 break;
1709 }
1710
1711 Chain = DAG.getCopyToReg(Chain, ValReg, DAG.getConstant(Val, AVT),
1712 InFlag);
1713 InFlag = Chain.getValue(1);
1714 } else {
1715 AVT = MVT::i8;
1716 Count = Op.getOperand(3);
1717 Chain = DAG.getCopyToReg(Chain, X86::AL, Op.getOperand(2), InFlag);
1718 InFlag = Chain.getValue(1);
1719 }
1720
1721 Chain = DAG.getCopyToReg(Chain, X86::ECX, Count, InFlag);
1722 InFlag = Chain.getValue(1);
1723 Chain = DAG.getCopyToReg(Chain, X86::EDI, Op.getOperand(1), InFlag);
1724 InFlag = Chain.getValue(1);
1725
1726 return DAG.getNode(X86ISD::REP_STOS, MVT::Other, Chain,
1727 DAG.getValueType(AVT), InFlag);
1728 }
1729 case ISD::MEMCPY: {
1730 SDOperand Chain = Op.getOperand(0);
1731 unsigned Align =
1732 (unsigned)cast<ConstantSDNode>(Op.getOperand(4))->getValue();
1733 if (Align == 0) Align = 1;
1734
1735 MVT::ValueType AVT;
1736 SDOperand Count;
1737 switch (Align & 3) {
1738 case 2: // WORD aligned
1739 AVT = MVT::i16;
1740 if (ConstantSDNode *I = dyn_cast<ConstantSDNode>(Op.getOperand(3)))
1741 Count = DAG.getConstant(I->getValue() / 2, MVT::i32);
1742 else
1743 Count = DAG.getNode(ISD::SRL, MVT::i32, Op.getOperand(3),
1744 DAG.getConstant(1, MVT::i8));
1745 break;
1746 case 0: // DWORD aligned
1747 AVT = MVT::i32;
1748 if (ConstantSDNode *I = dyn_cast<ConstantSDNode>(Op.getOperand(3)))
1749 Count = DAG.getConstant(I->getValue() / 4, MVT::i32);
1750 else
1751 Count = DAG.getNode(ISD::SRL, MVT::i32, Op.getOperand(3),
1752 DAG.getConstant(2, MVT::i8));
1753 break;
1754 default: // Byte aligned
1755 AVT = MVT::i8;
1756 Count = Op.getOperand(3);
1757 break;
1758 }
1759
1760 SDOperand InFlag;
1761 Chain = DAG.getCopyToReg(Chain, X86::ECX, Count, InFlag);
1762 InFlag = Chain.getValue(1);
1763 Chain = DAG.getCopyToReg(Chain, X86::EDI, Op.getOperand(1), InFlag);
1764 InFlag = Chain.getValue(1);
1765 Chain = DAG.getCopyToReg(Chain, X86::ESI, Op.getOperand(2), InFlag);
1766 InFlag = Chain.getValue(1);
1767
1768 return DAG.getNode(X86ISD::REP_MOVS, MVT::Other, Chain,
1769 DAG.getValueType(AVT), InFlag);
1770 }
Evan Cheng5c59d492005-12-23 07:31:11 +00001771 case ISD::GlobalAddress: {
Evan Chengb94db9e2006-01-12 07:56:47 +00001772 SDOperand Result;
Evan Chenga74ce622005-12-21 02:39:21 +00001773 GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
1774 // For Darwin, external and weak symbols are indirect, so we want to load
1775 // the value at address GV, not the value of GV itself. This means that
1776 // the GlobalAddress must be in the base or index register of the address,
1777 // not the GV offset field.
1778 if (getTargetMachine().
1779 getSubtarget<X86Subtarget>().getIndirectExternAndWeakGlobals() &&
1780 (GV->hasWeakLinkage() || GV->isExternal()))
Evan Chengb94db9e2006-01-12 07:56:47 +00001781 Result = DAG.getLoad(MVT::i32, DAG.getEntryNode(),
1782 DAG.getTargetGlobalAddress(GV, getPointerTy()),
1783 DAG.getSrcValue(NULL));
1784 return Result;
Chris Lattner76ac0682005-11-15 00:40:23 +00001785 }
Evan Cheng5c59d492005-12-23 07:31:11 +00001786 }
Chris Lattner76ac0682005-11-15 00:40:23 +00001787}
Evan Cheng6af02632005-12-20 06:22:03 +00001788
1789const char *X86TargetLowering::getTargetNodeName(unsigned Opcode) const {
1790 switch (Opcode) {
1791 default: return NULL;
Evan Cheng9c249c32006-01-09 18:33:28 +00001792 case X86ISD::ADD_FLAG: return "X86ISD::ADD_FLAG";
1793 case X86ISD::SUB_FLAG: return "X86ISD::SUB_FLAG";
1794 case X86ISD::ADC: return "X86ISD::ADC";
1795 case X86ISD::SBB: return "X86ISD::SBB";
1796 case X86ISD::SHLD: return "X86ISD::SHLD";
1797 case X86ISD::SHRD: return "X86ISD::SHRD";
Evan Cheng6305e502006-01-12 22:54:21 +00001798 case X86ISD::FILD: return "X86ISD::FILD";
Evan Cheng6af02632005-12-20 06:22:03 +00001799 case X86ISD::FP_TO_INT16_IN_MEM: return "X86ISD::FP_TO_INT16_IN_MEM";
1800 case X86ISD::FP_TO_INT32_IN_MEM: return "X86ISD::FP_TO_INT32_IN_MEM";
1801 case X86ISD::FP_TO_INT64_IN_MEM: return "X86ISD::FP_TO_INT64_IN_MEM";
Evan Chenga74ce622005-12-21 02:39:21 +00001802 case X86ISD::FLD: return "X86ISD::FLD";
Evan Cheng45e190982006-01-05 00:27:02 +00001803 case X86ISD::FST: return "X86ISD::FST";
1804 case X86ISD::FP_GET_RESULT: return "X86ISD::FP_GET_RESULT";
Evan Chenga74ce622005-12-21 02:39:21 +00001805 case X86ISD::FP_SET_RESULT: return "X86ISD::FP_SET_RESULT";
Evan Cheng6af02632005-12-20 06:22:03 +00001806 case X86ISD::CALL: return "X86ISD::CALL";
1807 case X86ISD::TAILCALL: return "X86ISD::TAILCALL";
1808 case X86ISD::RDTSC_DAG: return "X86ISD::RDTSC_DAG";
1809 case X86ISD::CMP: return "X86ISD::CMP";
1810 case X86ISD::TEST: return "X86ISD::TEST";
Evan Chengc1583db2005-12-21 20:21:51 +00001811 case X86ISD::SETCC: return "X86ISD::SETCC";
Evan Cheng6af02632005-12-20 06:22:03 +00001812 case X86ISD::CMOV: return "X86ISD::CMOV";
1813 case X86ISD::BRCOND: return "X86ISD::BRCOND";
Evan Chenga74ce622005-12-21 02:39:21 +00001814 case X86ISD::RET_FLAG: return "X86ISD::RET_FLAG";
Evan Chengae986f12006-01-11 22:15:48 +00001815 case X86ISD::REP_STOS: return "X86ISD::RET_STOS";
1816 case X86ISD::REP_MOVS: return "X86ISD::RET_MOVS";
Evan Cheng6af02632005-12-20 06:22:03 +00001817 }
1818}
Evan Cheng9cdc16c2005-12-21 23:05:39 +00001819
1820bool X86TargetLowering::isMaskedValueZeroForTargetNode(const SDOperand &Op,
1821 uint64_t Mask) const {
1822
1823 unsigned Opc = Op.getOpcode();
1824
1825 switch (Opc) {
1826 default:
1827 assert(Opc >= ISD::BUILTIN_OP_END && "Expected a target specific node");
1828 break;
1829 case X86ISD::SETCC: return (Mask & 1) == 0;
1830 }
1831
1832 return false;
1833}