blob: 776780ff531cd99f5a9c69b759dea78f7dcbbabd [file] [log] [blame]
Chris Lattnerdbdbf0c2005-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 Lattnerdbdbf0c2005-11-15 00:40:23 +000020#include "llvm/CodeGen/MachineFrameInfo.h"
Evan Cheng4a460802006-01-11 00:33:36 +000021#include "llvm/CodeGen/MachineFunction.h"
22#include "llvm/CodeGen/MachineInstrBuilder.h"
Chris Lattnerdbdbf0c2005-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 Lattnerdbdbf0c2005-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 Lattner9edba762006-01-13 18:00:54 +000042 setStackPointerRegisterToSaveRestore(X86::ESP);
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +000043
44 // Set up the register classes.
Chris Lattnerdbdbf0c2005-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 Lattner21f66852005-12-23 05:15:23 +000085 setOperationAction(ISD::BIT_CONVERT, MVT::f32, Expand);
86 setOperationAction(ISD::BIT_CONVERT, MVT::i32, Expand);
87
Evan Cheng898101c2005-12-19 23:12:38 +000088 if (X86DAGIsel) {
89 setOperationAction(ISD::BRCOND , MVT::Other, Custom);
90 }
Chris Lattnerdbdbf0c2005-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 Lattnere80242a2005-12-07 17:59:14 +000095 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i8 , Expand);
Chris Lattnerdbdbf0c2005-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 Lenharthb873ff32005-11-20 21:41:10 +0000109 setOperationAction(ISD::READCYCLECOUNTER , MVT::i64 , Custom);
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000110
Evan Chengeb422a72006-01-11 23:20:05 +0000111 if (!X86DAGIsel) {
112 setOperationAction(ISD::ROTL , MVT::i8 , Expand);
113 setOperationAction(ISD::ROTR , MVT::i8 , Expand);
114 setOperationAction(ISD::ROTL , MVT::i16 , Expand);
115 setOperationAction(ISD::ROTR , MVT::i16 , Expand);
116 setOperationAction(ISD::ROTL , MVT::i32 , Expand);
117 setOperationAction(ISD::ROTR , MVT::i32 , Expand);
118 }
Nate Begeman35ef9132006-01-11 21:21:00 +0000119
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000120 setOperationAction(ISD::READIO , MVT::i1 , Expand);
121 setOperationAction(ISD::READIO , MVT::i8 , Expand);
122 setOperationAction(ISD::READIO , MVT::i16 , Expand);
123 setOperationAction(ISD::READIO , MVT::i32 , Expand);
124 setOperationAction(ISD::WRITEIO , MVT::i1 , Expand);
125 setOperationAction(ISD::WRITEIO , MVT::i8 , Expand);
126 setOperationAction(ISD::WRITEIO , MVT::i16 , Expand);
127 setOperationAction(ISD::WRITEIO , MVT::i32 , Expand);
128
129 // These should be promoted to a larger select which is supported.
130 setOperationAction(ISD::SELECT , MVT::i1 , Promote);
131 setOperationAction(ISD::SELECT , MVT::i8 , Promote);
Evan Cheng7df96d62005-12-17 01:21:05 +0000132 if (X86DAGIsel) {
Evan Chengd9558e02006-01-06 00:43:03 +0000133 // X86 wants to expand cmov itself.
Evan Cheng7df96d62005-12-17 01:21:05 +0000134 setOperationAction(ISD::SELECT , MVT::i16 , Custom);
135 setOperationAction(ISD::SELECT , MVT::i32 , Custom);
Evan Chengd9558e02006-01-06 00:43:03 +0000136 setOperationAction(ISD::SELECT , MVT::f32 , Custom);
137 setOperationAction(ISD::SELECT , MVT::f64 , Custom);
Evan Chengd5781fc2005-12-21 20:21:51 +0000138 setOperationAction(ISD::SETCC , MVT::i8 , Custom);
139 setOperationAction(ISD::SETCC , MVT::i16 , Custom);
140 setOperationAction(ISD::SETCC , MVT::i32 , Custom);
Evan Chengd9558e02006-01-06 00:43:03 +0000141 setOperationAction(ISD::SETCC , MVT::f32 , Custom);
142 setOperationAction(ISD::SETCC , MVT::f64 , Custom);
143 // X86 ret instruction may pop stack.
144 setOperationAction(ISD::RET , MVT::Other, Custom);
145 // Darwin ABI issue.
Evan Cheng3a03ebb2005-12-21 23:05:39 +0000146 setOperationAction(ISD::GlobalAddress , MVT::i32 , Custom);
Evan Chenge3413162006-01-09 18:33:28 +0000147 // 64-bit addm sub, shl, sra, srl (iff 32-bit x86)
148 setOperationAction(ISD::ADD_PARTS , MVT::i32 , Custom);
149 setOperationAction(ISD::SUB_PARTS , MVT::i32 , Custom);
150 setOperationAction(ISD::SHL_PARTS , MVT::i32 , Custom);
151 setOperationAction(ISD::SRA_PARTS , MVT::i32 , Custom);
152 setOperationAction(ISD::SRL_PARTS , MVT::i32 , Custom);
Evan Cheng67f92a72006-01-11 22:15:48 +0000153 // X86 wants to expand memset / memcpy itself.
154 setOperationAction(ISD::MEMSET , MVT::Other, Custom);
155 setOperationAction(ISD::MEMCPY , MVT::Other, Custom);
Evan Cheng7df96d62005-12-17 01:21:05 +0000156 }
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000157
Chris Lattnerf73bae12005-11-29 06:16:21 +0000158 // We don't have line number support yet.
159 setOperationAction(ISD::LOCATION, MVT::Other, Expand);
Jim Laskeye0bce712006-01-05 01:47:43 +0000160 setOperationAction(ISD::DEBUG_LOC, MVT::Other, Expand);
161 setOperationAction(ISD::DEBUG_LABEL, MVT::Other, Expand);
Chris Lattnerf73bae12005-11-29 06:16:21 +0000162
Chris Lattnerb99329e2006-01-13 02:42:53 +0000163 // Not implemented yet.
164 setOperationAction(ISD::STACKSAVE, MVT::Other, Expand);
165 setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand);
166
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000167 if (X86ScalarSSE) {
168 // Set up the FP register classes.
Evan Cheng5ee4ccc2006-01-12 08:27:59 +0000169 addRegisterClass(MVT::f32, X86::FR32RegisterClass);
170 addRegisterClass(MVT::f64, X86::FR64RegisterClass);
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000171
172 // SSE has no load+extend ops
173 setOperationAction(ISD::EXTLOAD, MVT::f32, Expand);
174 setOperationAction(ISD::ZEXTLOAD, MVT::f32, Expand);
175
176 // SSE has no i16 to fp conversion, only i32
177 setOperationAction(ISD::SINT_TO_FP, MVT::i16, Promote);
178 setOperationAction(ISD::FP_TO_SINT, MVT::i16, Promote);
179
180 // Expand FP_TO_UINT into a select.
181 // FIXME: We would like to use a Custom expander here eventually to do
182 // the optimal thing for SSE vs. the default expansion in the legalizer.
183 setOperationAction(ISD::FP_TO_UINT , MVT::i32 , Expand);
184
185 // We don't support sin/cos/sqrt/fmod
186 setOperationAction(ISD::FSIN , MVT::f64, Expand);
187 setOperationAction(ISD::FCOS , MVT::f64, Expand);
188 setOperationAction(ISD::FABS , MVT::f64, Expand);
189 setOperationAction(ISD::FNEG , MVT::f64, Expand);
190 setOperationAction(ISD::FREM , MVT::f64, Expand);
191 setOperationAction(ISD::FSIN , MVT::f32, Expand);
192 setOperationAction(ISD::FCOS , MVT::f32, Expand);
193 setOperationAction(ISD::FABS , MVT::f32, Expand);
194 setOperationAction(ISD::FNEG , MVT::f32, Expand);
195 setOperationAction(ISD::FREM , MVT::f32, Expand);
196
197 addLegalFPImmediate(+0.0); // xorps / xorpd
198 } else {
199 // Set up the FP register classes.
200 addRegisterClass(MVT::f64, X86::RFPRegisterClass);
201
Evan Chenga3195e82006-01-12 22:54:21 +0000202 if (X86DAGIsel) {
203 setOperationAction(ISD::SINT_TO_FP, MVT::i16, Custom);
204 setOperationAction(ISD::SINT_TO_FP, MVT::i32, Custom);
205 }
206
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000207 if (!UnsafeFPMath) {
208 setOperationAction(ISD::FSIN , MVT::f64 , Expand);
209 setOperationAction(ISD::FCOS , MVT::f64 , Expand);
210 }
211
212 addLegalFPImmediate(+0.0); // FLD0
213 addLegalFPImmediate(+1.0); // FLD1
214 addLegalFPImmediate(-0.0); // FLD0/FCHS
215 addLegalFPImmediate(-1.0); // FLD1/FCHS
216 }
217 computeRegisterProperties();
218
219 maxStoresPerMemSet = 8; // For %llvm.memset -> sequence of stores
220 maxStoresPerMemCpy = 8; // For %llvm.memcpy -> sequence of stores
221 maxStoresPerMemMove = 8; // For %llvm.memmove -> sequence of stores
222 allowUnalignedMemoryAccesses = true; // x86 supports it!
223}
224
225std::vector<SDOperand>
226X86TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
227 if (F.getCallingConv() == CallingConv::Fast && EnableFastCC)
228 return LowerFastCCArguments(F, DAG);
229 return LowerCCCArguments(F, DAG);
230}
231
232std::pair<SDOperand, SDOperand>
233X86TargetLowering::LowerCallTo(SDOperand Chain, const Type *RetTy,
234 bool isVarArg, unsigned CallingConv,
235 bool isTailCall,
236 SDOperand Callee, ArgListTy &Args,
237 SelectionDAG &DAG) {
238 assert((!isVarArg || CallingConv == CallingConv::C) &&
239 "Only C takes varargs!");
Evan Chengd9558e02006-01-06 00:43:03 +0000240
241 // If the callee is a GlobalAddress node (quite common, every direct call is)
242 // turn it into a TargetGlobalAddress node so that legalize doesn't hack it.
243 if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee))
244 Callee = DAG.getTargetGlobalAddress(G->getGlobal(), getPointerTy());
Evan Cheng8700e142006-01-11 06:09:51 +0000245 else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee))
246 Callee = DAG.getTargetExternalSymbol(S->getSymbol(), getPointerTy());
Evan Chengd9558e02006-01-06 00:43:03 +0000247
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000248 if (CallingConv == CallingConv::Fast && EnableFastCC)
249 return LowerFastCCCallTo(Chain, RetTy, isTailCall, Callee, Args, DAG);
250 return LowerCCCCallTo(Chain, RetTy, isVarArg, isTailCall, Callee, Args, DAG);
251}
252
Evan Chengb077b842005-12-21 02:39:21 +0000253SDOperand X86TargetLowering::LowerReturnTo(SDOperand Chain, SDOperand Op,
254 SelectionDAG &DAG) {
255 if (!X86DAGIsel)
256 return DAG.getNode(ISD::RET, MVT::Other, Chain, Op);
257
258 SDOperand Copy;
259 MVT::ValueType OpVT = Op.getValueType();
260 switch (OpVT) {
261 default: assert(0 && "Unknown type to return!");
262 case MVT::i32:
263 Copy = DAG.getCopyToReg(Chain, X86::EAX, Op, SDOperand());
264 break;
265 case MVT::i64: {
266 SDOperand Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, Op,
267 DAG.getConstant(1, MVT::i32));
268 SDOperand Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, Op,
269 DAG.getConstant(0, MVT::i32));
Evan Chengd9558e02006-01-06 00:43:03 +0000270 Copy = DAG.getCopyToReg(Chain, X86::EDX, Hi, SDOperand());
271 Copy = DAG.getCopyToReg(Copy, X86::EAX, Lo, Copy.getValue(1));
Evan Chengb077b842005-12-21 02:39:21 +0000272 break;
273 }
274 case MVT::f32:
Evan Chengb077b842005-12-21 02:39:21 +0000275 case MVT::f64:
276 if (!X86ScalarSSE) {
Evan Chenge3413162006-01-09 18:33:28 +0000277 if (OpVT == MVT::f32)
278 Op = DAG.getNode(ISD::FP_EXTEND, MVT::f64, Op);
Evan Chengb077b842005-12-21 02:39:21 +0000279 std::vector<MVT::ValueType> Tys;
280 Tys.push_back(MVT::Other);
281 Tys.push_back(MVT::Flag);
282 std::vector<SDOperand> Ops;
283 Ops.push_back(Chain);
284 Ops.push_back(Op);
285 Copy = DAG.getNode(X86ISD::FP_SET_RESULT, Tys, Ops);
286 } else {
287 // Spill the value to memory and reload it into top of stack.
288 unsigned Size = MVT::getSizeInBits(OpVT)/8;
289 MachineFunction &MF = DAG.getMachineFunction();
290 int SSFI = MF.getFrameInfo()->CreateStackObject(Size, Size);
291 SDOperand StackSlot = DAG.getFrameIndex(SSFI, getPointerTy());
292 Chain = DAG.getNode(ISD::STORE, MVT::Other, Chain, Op,
293 StackSlot, DAG.getSrcValue(NULL));
294 std::vector<MVT::ValueType> Tys;
295 Tys.push_back(MVT::f64);
296 Tys.push_back(MVT::Other);
297 std::vector<SDOperand> Ops;
298 Ops.push_back(Chain);
299 Ops.push_back(StackSlot);
300 Ops.push_back(DAG.getValueType(OpVT));
301 Copy = DAG.getNode(X86ISD::FLD, Tys, Ops);
302 Tys.clear();
303 Tys.push_back(MVT::Other);
304 Tys.push_back(MVT::Flag);
305 Ops.clear();
306 Ops.push_back(Copy.getValue(1));
307 Ops.push_back(Copy);
308 Copy = DAG.getNode(X86ISD::FP_SET_RESULT, Tys, Ops);
309 }
310 break;
311 }
Evan Chengd5781fc2005-12-21 20:21:51 +0000312
313 return DAG.getNode(X86ISD::RET_FLAG, MVT::Other,
314 Copy, DAG.getConstant(getBytesToPopOnReturn(), MVT::i16),
315 Copy.getValue(1));
Evan Chengb077b842005-12-21 02:39:21 +0000316}
317
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000318//===----------------------------------------------------------------------===//
319// C Calling Convention implementation
320//===----------------------------------------------------------------------===//
321
322std::vector<SDOperand>
323X86TargetLowering::LowerCCCArguments(Function &F, SelectionDAG &DAG) {
324 std::vector<SDOperand> ArgValues;
325
326 MachineFunction &MF = DAG.getMachineFunction();
327 MachineFrameInfo *MFI = MF.getFrameInfo();
328
329 // Add DAG nodes to load the arguments... On entry to a function on the X86,
330 // the stack frame looks like this:
331 //
332 // [ESP] -- return address
333 // [ESP + 4] -- first argument (leftmost lexically)
334 // [ESP + 8] -- second argument, if first argument is four bytes in size
335 // ...
336 //
337 unsigned ArgOffset = 0; // Frame mechanisms handle retaddr slot
338 for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I) {
339 MVT::ValueType ObjectVT = getValueType(I->getType());
340 unsigned ArgIncrement = 4;
341 unsigned ObjSize;
342 switch (ObjectVT) {
343 default: assert(0 && "Unhandled argument type!");
344 case MVT::i1:
345 case MVT::i8: ObjSize = 1; break;
346 case MVT::i16: ObjSize = 2; break;
347 case MVT::i32: ObjSize = 4; break;
348 case MVT::i64: ObjSize = ArgIncrement = 8; break;
349 case MVT::f32: ObjSize = 4; break;
350 case MVT::f64: ObjSize = ArgIncrement = 8; break;
351 }
352 // Create the frame index object for this incoming parameter...
353 int FI = MFI->CreateFixedObject(ObjSize, ArgOffset);
354
355 // Create the SelectionDAG nodes corresponding to a load from this parameter
356 SDOperand FIN = DAG.getFrameIndex(FI, MVT::i32);
357
358 // Don't codegen dead arguments. FIXME: remove this check when we can nuke
359 // dead loads.
360 SDOperand ArgValue;
361 if (!I->use_empty())
362 ArgValue = DAG.getLoad(ObjectVT, DAG.getEntryNode(), FIN,
363 DAG.getSrcValue(NULL));
364 else {
365 if (MVT::isInteger(ObjectVT))
366 ArgValue = DAG.getConstant(0, ObjectVT);
367 else
368 ArgValue = DAG.getConstantFP(0, ObjectVT);
369 }
370 ArgValues.push_back(ArgValue);
371
372 ArgOffset += ArgIncrement; // Move on to the next argument...
373 }
374
375 // If the function takes variable number of arguments, make a frame index for
376 // the start of the first vararg value... for expansion of llvm.va_start.
377 if (F.isVarArg())
378 VarArgsFrameIndex = MFI->CreateFixedObject(1, ArgOffset);
379 ReturnAddrIndex = 0; // No return address slot generated yet.
380 BytesToPopOnReturn = 0; // Callee pops nothing.
381 BytesCallerReserves = ArgOffset;
382
383 // Finally, inform the code generator which regs we return values in.
384 switch (getValueType(F.getReturnType())) {
385 default: assert(0 && "Unknown type!");
386 case MVT::isVoid: break;
387 case MVT::i1:
388 case MVT::i8:
389 case MVT::i16:
390 case MVT::i32:
391 MF.addLiveOut(X86::EAX);
392 break;
393 case MVT::i64:
394 MF.addLiveOut(X86::EAX);
395 MF.addLiveOut(X86::EDX);
396 break;
397 case MVT::f32:
398 case MVT::f64:
399 MF.addLiveOut(X86::ST0);
400 break;
401 }
402 return ArgValues;
403}
404
405std::pair<SDOperand, SDOperand>
406X86TargetLowering::LowerCCCCallTo(SDOperand Chain, const Type *RetTy,
407 bool isVarArg, bool isTailCall,
408 SDOperand Callee, ArgListTy &Args,
409 SelectionDAG &DAG) {
410 // Count how many bytes are to be pushed on the stack.
411 unsigned NumBytes = 0;
412
413 if (Args.empty()) {
414 // Save zero bytes.
415 Chain = DAG.getNode(ISD::CALLSEQ_START, MVT::Other, Chain,
416 DAG.getConstant(0, getPointerTy()));
417 } else {
418 for (unsigned i = 0, e = Args.size(); i != e; ++i)
419 switch (getValueType(Args[i].second)) {
420 default: assert(0 && "Unknown value type!");
421 case MVT::i1:
422 case MVT::i8:
423 case MVT::i16:
424 case MVT::i32:
425 case MVT::f32:
426 NumBytes += 4;
427 break;
428 case MVT::i64:
429 case MVT::f64:
430 NumBytes += 8;
431 break;
432 }
433
434 Chain = DAG.getNode(ISD::CALLSEQ_START, MVT::Other, Chain,
435 DAG.getConstant(NumBytes, getPointerTy()));
436
437 // Arguments go on the stack in reverse order, as specified by the ABI.
438 unsigned ArgOffset = 0;
Evan Cheng8700e142006-01-11 06:09:51 +0000439 SDOperand StackPtr = DAG.getRegister(X86::ESP, MVT::i32);
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000440 std::vector<SDOperand> Stores;
441
442 for (unsigned i = 0, e = Args.size(); i != e; ++i) {
443 SDOperand PtrOff = DAG.getConstant(ArgOffset, getPointerTy());
444 PtrOff = DAG.getNode(ISD::ADD, MVT::i32, StackPtr, PtrOff);
445
446 switch (getValueType(Args[i].second)) {
447 default: assert(0 && "Unexpected ValueType for argument!");
448 case MVT::i1:
449 case MVT::i8:
450 case MVT::i16:
451 // Promote the integer to 32 bits. If the input type is signed use a
452 // sign extend, otherwise use a zero extend.
453 if (Args[i].second->isSigned())
454 Args[i].first =DAG.getNode(ISD::SIGN_EXTEND, MVT::i32, Args[i].first);
455 else
456 Args[i].first =DAG.getNode(ISD::ZERO_EXTEND, MVT::i32, Args[i].first);
457
458 // FALL THROUGH
459 case MVT::i32:
460 case MVT::f32:
461 Stores.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
462 Args[i].first, PtrOff,
463 DAG.getSrcValue(NULL)));
464 ArgOffset += 4;
465 break;
466 case MVT::i64:
467 case MVT::f64:
468 Stores.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
469 Args[i].first, PtrOff,
470 DAG.getSrcValue(NULL)));
471 ArgOffset += 8;
472 break;
473 }
474 }
475 Chain = DAG.getNode(ISD::TokenFactor, MVT::Other, Stores);
476 }
477
478 std::vector<MVT::ValueType> RetVals;
479 MVT::ValueType RetTyVT = getValueType(RetTy);
480 RetVals.push_back(MVT::Other);
481
482 // The result values produced have to be legal. Promote the result.
483 switch (RetTyVT) {
484 case MVT::isVoid: break;
485 default:
486 RetVals.push_back(RetTyVT);
487 break;
488 case MVT::i1:
489 case MVT::i8:
490 case MVT::i16:
491 RetVals.push_back(MVT::i32);
492 break;
493 case MVT::f32:
494 if (X86ScalarSSE)
495 RetVals.push_back(MVT::f32);
496 else
497 RetVals.push_back(MVT::f64);
498 break;
499 case MVT::i64:
500 RetVals.push_back(MVT::i32);
501 RetVals.push_back(MVT::i32);
502 break;
503 }
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000504
Evan Chengd90eb7f2006-01-05 00:27:02 +0000505 if (X86DAGIsel) {
506 std::vector<MVT::ValueType> NodeTys;
507 NodeTys.push_back(MVT::Other); // Returns a chain
508 NodeTys.push_back(MVT::Flag); // Returns a flag for retval copy to use.
Evan Chengd90eb7f2006-01-05 00:27:02 +0000509 std::vector<SDOperand> Ops;
510 Ops.push_back(Chain);
511 Ops.push_back(Callee);
512
Evan Chengd9558e02006-01-06 00:43:03 +0000513 // FIXME: Do not generate X86ISD::TAILCALL for now.
514 Chain = DAG.getNode(X86ISD::CALL, NodeTys, Ops);
Evan Chengd90eb7f2006-01-05 00:27:02 +0000515 SDOperand InFlag = Chain.getValue(1);
516
517 SDOperand RetVal;
518 if (RetTyVT != MVT::isVoid) {
519 switch (RetTyVT) {
520 default: assert(0 && "Unknown value type to return!");
521 case MVT::i1:
522 case MVT::i8:
523 RetVal = DAG.getCopyFromReg(Chain, X86::AL, MVT::i8, InFlag);
524 Chain = RetVal.getValue(1);
525 break;
526 case MVT::i16:
527 RetVal = DAG.getCopyFromReg(Chain, X86::AX, MVT::i16, InFlag);
528 Chain = RetVal.getValue(1);
529 break;
530 case MVT::i32:
531 RetVal = DAG.getCopyFromReg(Chain, X86::EAX, MVT::i32, InFlag);
532 Chain = RetVal.getValue(1);
533 break;
534 case MVT::i64: {
535 SDOperand Lo = DAG.getCopyFromReg(Chain, X86::EAX, MVT::i32, InFlag);
536 SDOperand Hi = DAG.getCopyFromReg(Lo.getValue(1), X86::EDX, MVT::i32,
537 Lo.getValue(2));
538 RetVal = DAG.getNode(ISD::BUILD_PAIR, MVT::i64, Lo, Hi);
539 Chain = Hi.getValue(1);
540 break;
541 }
542 case MVT::f32:
543 case MVT::f64: {
544 std::vector<MVT::ValueType> Tys;
545 Tys.push_back(MVT::f64);
546 Tys.push_back(MVT::Other);
547 std::vector<SDOperand> Ops;
548 Ops.push_back(Chain);
549 Ops.push_back(InFlag);
550 RetVal = DAG.getNode(X86ISD::FP_GET_RESULT, Tys, Ops);
551 Chain = RetVal.getValue(1);
552 if (X86ScalarSSE) {
553 unsigned Size = MVT::getSizeInBits(MVT::f64)/8;
554 MachineFunction &MF = DAG.getMachineFunction();
555 int SSFI = MF.getFrameInfo()->CreateStackObject(Size, Size);
556 SDOperand StackSlot = DAG.getFrameIndex(SSFI, getPointerTy());
557 Tys.clear();
558 Tys.push_back(MVT::Other);
559 Ops.clear();
560 Ops.push_back(Chain);
561 Ops.push_back(RetVal);
562 Ops.push_back(StackSlot);
563 Ops.push_back(DAG.getValueType(RetTyVT));
564 Chain = DAG.getNode(X86ISD::FST, Tys, Ops);
565 RetVal = DAG.getLoad(RetTyVT, Chain, StackSlot,
566 DAG.getSrcValue(NULL));
567 Chain = RetVal.getValue(1);
568 } else if (RetTyVT == MVT::f32)
569 RetVal = DAG.getNode(ISD::FP_ROUND, MVT::f32, RetVal);
570 break;
571 }
572 }
573 }
574
575 Chain = DAG.getNode(ISD::CALLSEQ_END, MVT::Other, Chain,
576 DAG.getConstant(NumBytes, getPointerTy()),
577 DAG.getConstant(0, getPointerTy()));
578 return std::make_pair(RetVal, Chain);
579 } else {
580 std::vector<SDOperand> Ops;
581 Ops.push_back(Chain);
582 Ops.push_back(Callee);
583 Ops.push_back(DAG.getConstant(NumBytes, getPointerTy()));
584 Ops.push_back(DAG.getConstant(0, getPointerTy()));
585
586 SDOperand TheCall = DAG.getNode(isTailCall ? X86ISD::TAILCALL : X86ISD::CALL,
587 RetVals, Ops);
588
589 SDOperand ResultVal;
590 switch (RetTyVT) {
591 case MVT::isVoid: break;
592 default:
593 ResultVal = TheCall.getValue(1);
594 break;
595 case MVT::i1:
596 case MVT::i8:
597 case MVT::i16:
598 ResultVal = DAG.getNode(ISD::TRUNCATE, RetTyVT, TheCall.getValue(1));
599 break;
600 case MVT::f32:
601 // FIXME: we would really like to remember that this FP_ROUND operation is
602 // okay to eliminate if we allow excess FP precision.
603 ResultVal = DAG.getNode(ISD::FP_ROUND, MVT::f32, TheCall.getValue(1));
604 break;
605 case MVT::i64:
606 ResultVal = DAG.getNode(ISD::BUILD_PAIR, MVT::i64, TheCall.getValue(1),
607 TheCall.getValue(2));
608 break;
609 }
610
611 Chain = DAG.getNode(ISD::CALLSEQ_END, MVT::Other, TheCall);
612 return std::make_pair(ResultVal, Chain);
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000613 }
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000614}
615
616SDOperand
617X86TargetLowering::LowerVAStart(SDOperand Chain, SDOperand VAListP,
618 Value *VAListV, SelectionDAG &DAG) {
619 // vastart just stores the address of the VarArgsFrameIndex slot.
620 SDOperand FR = DAG.getFrameIndex(VarArgsFrameIndex, MVT::i32);
621 return DAG.getNode(ISD::STORE, MVT::Other, Chain, FR, VAListP,
622 DAG.getSrcValue(VAListV));
623}
624
625
626std::pair<SDOperand,SDOperand>
627X86TargetLowering::LowerVAArg(SDOperand Chain, SDOperand VAListP,
628 Value *VAListV, const Type *ArgTy,
629 SelectionDAG &DAG) {
630 MVT::ValueType ArgVT = getValueType(ArgTy);
631 SDOperand Val = DAG.getLoad(MVT::i32, Chain,
632 VAListP, DAG.getSrcValue(VAListV));
633 SDOperand Result = DAG.getLoad(ArgVT, Chain, Val,
634 DAG.getSrcValue(NULL));
635 unsigned Amt;
636 if (ArgVT == MVT::i32)
637 Amt = 4;
638 else {
639 assert((ArgVT == MVT::i64 || ArgVT == MVT::f64) &&
640 "Other types should have been promoted for varargs!");
641 Amt = 8;
642 }
643 Val = DAG.getNode(ISD::ADD, Val.getValueType(), Val,
644 DAG.getConstant(Amt, Val.getValueType()));
645 Chain = DAG.getNode(ISD::STORE, MVT::Other, Chain,
646 Val, VAListP, DAG.getSrcValue(VAListV));
647 return std::make_pair(Result, Chain);
648}
649
650//===----------------------------------------------------------------------===//
651// Fast Calling Convention implementation
652//===----------------------------------------------------------------------===//
653//
654// The X86 'fast' calling convention passes up to two integer arguments in
655// registers (an appropriate portion of EAX/EDX), passes arguments in C order,
656// and requires that the callee pop its arguments off the stack (allowing proper
657// tail calls), and has the same return value conventions as C calling convs.
658//
659// This calling convention always arranges for the callee pop value to be 8n+4
660// bytes, which is needed for tail recursion elimination and stack alignment
661// reasons.
662//
663// Note that this can be enhanced in the future to pass fp vals in registers
664// (when we have a global fp allocator) and do other tricks.
665//
666
667/// AddLiveIn - This helper function adds the specified physical register to the
668/// MachineFunction as a live in value. It also creates a corresponding virtual
669/// register for it.
670static unsigned AddLiveIn(MachineFunction &MF, unsigned PReg,
671 TargetRegisterClass *RC) {
672 assert(RC->contains(PReg) && "Not the correct regclass!");
673 unsigned VReg = MF.getSSARegMap()->createVirtualRegister(RC);
674 MF.addLiveIn(PReg, VReg);
675 return VReg;
676}
677
678
679std::vector<SDOperand>
680X86TargetLowering::LowerFastCCArguments(Function &F, SelectionDAG &DAG) {
681 std::vector<SDOperand> ArgValues;
682
683 MachineFunction &MF = DAG.getMachineFunction();
684 MachineFrameInfo *MFI = MF.getFrameInfo();
685
686 // Add DAG nodes to load the arguments... On entry to a function the stack
687 // frame looks like this:
688 //
689 // [ESP] -- return address
690 // [ESP + 4] -- first nonreg argument (leftmost lexically)
691 // [ESP + 8] -- second nonreg argument, if first argument is 4 bytes in size
692 // ...
693 unsigned ArgOffset = 0; // Frame mechanisms handle retaddr slot
694
695 // Keep track of the number of integer regs passed so far. This can be either
696 // 0 (neither EAX or EDX used), 1 (EAX is used) or 2 (EAX and EDX are both
697 // used).
698 unsigned NumIntRegs = 0;
699
700 for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I) {
701 MVT::ValueType ObjectVT = getValueType(I->getType());
702 unsigned ArgIncrement = 4;
703 unsigned ObjSize = 0;
704 SDOperand ArgValue;
705
706 switch (ObjectVT) {
707 default: assert(0 && "Unhandled argument type!");
708 case MVT::i1:
709 case MVT::i8:
710 if (NumIntRegs < 2) {
711 if (!I->use_empty()) {
712 unsigned VReg = AddLiveIn(MF, NumIntRegs ? X86::DL : X86::AL,
713 X86::R8RegisterClass);
714 ArgValue = DAG.getCopyFromReg(DAG.getRoot(), VReg, MVT::i8);
715 DAG.setRoot(ArgValue.getValue(1));
Chris Lattnerf31d1932005-12-27 03:02:18 +0000716 if (ObjectVT == MVT::i1)
717 // FIXME: Should insert a assertzext here.
718 ArgValue = DAG.getNode(ISD::TRUNCATE, MVT::i1, ArgValue);
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000719 }
720 ++NumIntRegs;
721 break;
722 }
723
724 ObjSize = 1;
725 break;
726 case MVT::i16:
727 if (NumIntRegs < 2) {
728 if (!I->use_empty()) {
729 unsigned VReg = AddLiveIn(MF, NumIntRegs ? X86::DX : X86::AX,
730 X86::R16RegisterClass);
731 ArgValue = DAG.getCopyFromReg(DAG.getRoot(), VReg, MVT::i16);
732 DAG.setRoot(ArgValue.getValue(1));
733 }
734 ++NumIntRegs;
735 break;
736 }
737 ObjSize = 2;
738 break;
739 case MVT::i32:
740 if (NumIntRegs < 2) {
741 if (!I->use_empty()) {
742 unsigned VReg = AddLiveIn(MF,NumIntRegs ? X86::EDX : X86::EAX,
743 X86::R32RegisterClass);
744 ArgValue = DAG.getCopyFromReg(DAG.getRoot(), VReg, MVT::i32);
745 DAG.setRoot(ArgValue.getValue(1));
746 }
747 ++NumIntRegs;
748 break;
749 }
750 ObjSize = 4;
751 break;
752 case MVT::i64:
753 if (NumIntRegs == 0) {
754 if (!I->use_empty()) {
755 unsigned BotReg = AddLiveIn(MF, X86::EAX, X86::R32RegisterClass);
756 unsigned TopReg = AddLiveIn(MF, X86::EDX, X86::R32RegisterClass);
757
758 SDOperand Low = DAG.getCopyFromReg(DAG.getRoot(), BotReg, MVT::i32);
759 SDOperand Hi = DAG.getCopyFromReg(Low.getValue(1), TopReg, MVT::i32);
760 DAG.setRoot(Hi.getValue(1));
761
762 ArgValue = DAG.getNode(ISD::BUILD_PAIR, MVT::i64, Low, Hi);
763 }
764 NumIntRegs = 2;
765 break;
766 } else if (NumIntRegs == 1) {
767 if (!I->use_empty()) {
768 unsigned BotReg = AddLiveIn(MF, X86::EDX, X86::R32RegisterClass);
769 SDOperand Low = DAG.getCopyFromReg(DAG.getRoot(), BotReg, MVT::i32);
770 DAG.setRoot(Low.getValue(1));
771
772 // Load the high part from memory.
773 // Create the frame index object for this incoming parameter...
774 int FI = MFI->CreateFixedObject(4, ArgOffset);
775 SDOperand FIN = DAG.getFrameIndex(FI, MVT::i32);
776 SDOperand Hi = DAG.getLoad(MVT::i32, DAG.getEntryNode(), FIN,
777 DAG.getSrcValue(NULL));
778 ArgValue = DAG.getNode(ISD::BUILD_PAIR, MVT::i64, Low, Hi);
779 }
780 ArgOffset += 4;
781 NumIntRegs = 2;
782 break;
783 }
784 ObjSize = ArgIncrement = 8;
785 break;
786 case MVT::f32: ObjSize = 4; break;
787 case MVT::f64: ObjSize = ArgIncrement = 8; break;
788 }
789
790 // Don't codegen dead arguments. FIXME: remove this check when we can nuke
791 // dead loads.
792 if (ObjSize && !I->use_empty()) {
793 // Create the frame index object for this incoming parameter...
794 int FI = MFI->CreateFixedObject(ObjSize, ArgOffset);
795
796 // Create the SelectionDAG nodes corresponding to a load from this
797 // parameter.
798 SDOperand FIN = DAG.getFrameIndex(FI, MVT::i32);
799
800 ArgValue = DAG.getLoad(ObjectVT, DAG.getEntryNode(), FIN,
801 DAG.getSrcValue(NULL));
802 } else if (ArgValue.Val == 0) {
803 if (MVT::isInteger(ObjectVT))
804 ArgValue = DAG.getConstant(0, ObjectVT);
805 else
806 ArgValue = DAG.getConstantFP(0, ObjectVT);
807 }
808 ArgValues.push_back(ArgValue);
809
810 if (ObjSize)
811 ArgOffset += ArgIncrement; // Move on to the next argument.
812 }
813
814 // Make sure the instruction takes 8n+4 bytes to make sure the start of the
815 // arguments and the arguments after the retaddr has been pushed are aligned.
816 if ((ArgOffset & 7) == 0)
817 ArgOffset += 4;
818
819 VarArgsFrameIndex = 0xAAAAAAA; // fastcc functions can't have varargs.
820 ReturnAddrIndex = 0; // No return address slot generated yet.
821 BytesToPopOnReturn = ArgOffset; // Callee pops all stack arguments.
822 BytesCallerReserves = 0;
823
824 // Finally, inform the code generator which regs we return values in.
825 switch (getValueType(F.getReturnType())) {
826 default: assert(0 && "Unknown type!");
827 case MVT::isVoid: break;
828 case MVT::i1:
829 case MVT::i8:
830 case MVT::i16:
831 case MVT::i32:
832 MF.addLiveOut(X86::EAX);
833 break;
834 case MVT::i64:
835 MF.addLiveOut(X86::EAX);
836 MF.addLiveOut(X86::EDX);
837 break;
838 case MVT::f32:
839 case MVT::f64:
840 MF.addLiveOut(X86::ST0);
841 break;
842 }
843 return ArgValues;
844}
845
846std::pair<SDOperand, SDOperand>
847X86TargetLowering::LowerFastCCCallTo(SDOperand Chain, const Type *RetTy,
848 bool isTailCall, SDOperand Callee,
849 ArgListTy &Args, SelectionDAG &DAG) {
850 // Count how many bytes are to be pushed on the stack.
851 unsigned NumBytes = 0;
852
853 // Keep track of the number of integer regs passed so far. This can be either
854 // 0 (neither EAX or EDX used), 1 (EAX is used) or 2 (EAX and EDX are both
855 // used).
856 unsigned NumIntRegs = 0;
857
858 for (unsigned i = 0, e = Args.size(); i != e; ++i)
859 switch (getValueType(Args[i].second)) {
860 default: assert(0 && "Unknown value type!");
861 case MVT::i1:
862 case MVT::i8:
863 case MVT::i16:
864 case MVT::i32:
865 if (NumIntRegs < 2) {
866 ++NumIntRegs;
867 break;
868 }
869 // fall through
870 case MVT::f32:
871 NumBytes += 4;
872 break;
873 case MVT::i64:
874 if (NumIntRegs == 0) {
875 NumIntRegs = 2;
876 break;
877 } else if (NumIntRegs == 1) {
878 NumIntRegs = 2;
879 NumBytes += 4;
880 break;
881 }
882
883 // fall through
884 case MVT::f64:
885 NumBytes += 8;
886 break;
887 }
888
889 // Make sure the instruction takes 8n+4 bytes to make sure the start of the
890 // arguments and the arguments after the retaddr has been pushed are aligned.
891 if ((NumBytes & 7) == 0)
892 NumBytes += 4;
893
894 Chain = DAG.getNode(ISD::CALLSEQ_START, MVT::Other, Chain,
895 DAG.getConstant(NumBytes, getPointerTy()));
896
897 // Arguments go on the stack in reverse order, as specified by the ABI.
898 unsigned ArgOffset = 0;
899 SDOperand StackPtr = DAG.getCopyFromReg(DAG.getEntryNode(),
900 X86::ESP, MVT::i32);
901 NumIntRegs = 0;
902 std::vector<SDOperand> Stores;
903 std::vector<SDOperand> RegValuesToPass;
904 for (unsigned i = 0, e = Args.size(); i != e; ++i) {
905 switch (getValueType(Args[i].second)) {
906 default: assert(0 && "Unexpected ValueType for argument!");
907 case MVT::i1:
Chris Lattnerf31d1932005-12-27 03:02:18 +0000908 Args[i].first = DAG.getNode(ISD::ANY_EXTEND, MVT::i8, Args[i].first);
909 // Fall through.
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000910 case MVT::i8:
911 case MVT::i16:
912 case MVT::i32:
913 if (NumIntRegs < 2) {
914 RegValuesToPass.push_back(Args[i].first);
915 ++NumIntRegs;
916 break;
917 }
918 // Fall through
919 case MVT::f32: {
920 SDOperand PtrOff = DAG.getConstant(ArgOffset, getPointerTy());
921 PtrOff = DAG.getNode(ISD::ADD, MVT::i32, StackPtr, PtrOff);
922 Stores.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
923 Args[i].first, PtrOff,
924 DAG.getSrcValue(NULL)));
925 ArgOffset += 4;
926 break;
927 }
928 case MVT::i64:
929 if (NumIntRegs < 2) { // Can pass part of it in regs?
930 SDOperand Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32,
931 Args[i].first, DAG.getConstant(1, MVT::i32));
932 SDOperand Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32,
933 Args[i].first, DAG.getConstant(0, MVT::i32));
934 RegValuesToPass.push_back(Lo);
935 ++NumIntRegs;
936 if (NumIntRegs < 2) { // Pass both parts in regs?
937 RegValuesToPass.push_back(Hi);
938 ++NumIntRegs;
939 } else {
940 // Pass the high part in memory.
941 SDOperand PtrOff = DAG.getConstant(ArgOffset, getPointerTy());
942 PtrOff = DAG.getNode(ISD::ADD, MVT::i32, StackPtr, PtrOff);
943 Stores.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
944 Hi, PtrOff, DAG.getSrcValue(NULL)));
945 ArgOffset += 4;
946 }
947 break;
948 }
949 // Fall through
950 case MVT::f64:
951 SDOperand PtrOff = DAG.getConstant(ArgOffset, getPointerTy());
952 PtrOff = DAG.getNode(ISD::ADD, MVT::i32, StackPtr, PtrOff);
953 Stores.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
954 Args[i].first, PtrOff,
955 DAG.getSrcValue(NULL)));
956 ArgOffset += 8;
957 break;
958 }
959 }
960 if (!Stores.empty())
961 Chain = DAG.getNode(ISD::TokenFactor, MVT::Other, Stores);
962
963 // Make sure the instruction takes 8n+4 bytes to make sure the start of the
964 // arguments and the arguments after the retaddr has been pushed are aligned.
965 if ((ArgOffset & 7) == 0)
966 ArgOffset += 4;
967
968 std::vector<MVT::ValueType> RetVals;
969 MVT::ValueType RetTyVT = getValueType(RetTy);
970
971 RetVals.push_back(MVT::Other);
972
973 // The result values produced have to be legal. Promote the result.
974 switch (RetTyVT) {
975 case MVT::isVoid: break;
976 default:
977 RetVals.push_back(RetTyVT);
978 break;
979 case MVT::i1:
980 case MVT::i8:
981 case MVT::i16:
982 RetVals.push_back(MVT::i32);
983 break;
984 case MVT::f32:
985 if (X86ScalarSSE)
986 RetVals.push_back(MVT::f32);
987 else
988 RetVals.push_back(MVT::f64);
989 break;
990 case MVT::i64:
991 RetVals.push_back(MVT::i32);
992 RetVals.push_back(MVT::i32);
993 break;
994 }
995
Evan Chengd9558e02006-01-06 00:43:03 +0000996 if (X86DAGIsel) {
997 // Build a sequence of copy-to-reg nodes chained together with token chain
998 // and flag operands which copy the outgoing args into registers.
999 SDOperand InFlag;
1000 for (unsigned i = 0, e = RegValuesToPass.size(); i != e; ++i) {
1001 unsigned CCReg;
1002 SDOperand RegToPass = RegValuesToPass[i];
1003 switch (RegToPass.getValueType()) {
1004 default: assert(0 && "Bad thing to pass in regs");
1005 case MVT::i8:
1006 CCReg = (i == 0) ? X86::AL : X86::DL;
1007 break;
1008 case MVT::i16:
1009 CCReg = (i == 0) ? X86::AX : X86::DX;
1010 break;
1011 case MVT::i32:
1012 CCReg = (i == 0) ? X86::EAX : X86::EDX;
1013 break;
1014 }
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +00001015
Evan Chengd9558e02006-01-06 00:43:03 +00001016 Chain = DAG.getCopyToReg(Chain, CCReg, RegToPass, InFlag);
1017 InFlag = Chain.getValue(1);
1018 }
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +00001019
Evan Chengd9558e02006-01-06 00:43:03 +00001020 std::vector<MVT::ValueType> NodeTys;
1021 NodeTys.push_back(MVT::Other); // Returns a chain
1022 NodeTys.push_back(MVT::Flag); // Returns a flag for retval copy to use.
Evan Chengd9558e02006-01-06 00:43:03 +00001023 std::vector<SDOperand> Ops;
1024 Ops.push_back(Chain);
1025 Ops.push_back(Callee);
1026 if (InFlag.Val)
1027 Ops.push_back(InFlag);
1028
1029 // FIXME: Do not generate X86ISD::TAILCALL for now.
1030 Chain = DAG.getNode(X86ISD::CALL, NodeTys, Ops);
1031 InFlag = Chain.getValue(1);
1032
1033 SDOperand RetVal;
1034 if (RetTyVT != MVT::isVoid) {
1035 switch (RetTyVT) {
1036 default: assert(0 && "Unknown value type to return!");
1037 case MVT::i1:
1038 case MVT::i8:
1039 RetVal = DAG.getCopyFromReg(Chain, X86::AL, MVT::i8, InFlag);
1040 Chain = RetVal.getValue(1);
1041 break;
1042 case MVT::i16:
1043 RetVal = DAG.getCopyFromReg(Chain, X86::AX, MVT::i16, InFlag);
1044 Chain = RetVal.getValue(1);
1045 break;
1046 case MVT::i32:
1047 RetVal = DAG.getCopyFromReg(Chain, X86::EAX, MVT::i32, InFlag);
1048 Chain = RetVal.getValue(1);
1049 break;
1050 case MVT::i64: {
1051 SDOperand Lo = DAG.getCopyFromReg(Chain, X86::EAX, MVT::i32, InFlag);
1052 SDOperand Hi = DAG.getCopyFromReg(Lo.getValue(1), X86::EDX, MVT::i32,
1053 Lo.getValue(2));
1054 RetVal = DAG.getNode(ISD::BUILD_PAIR, MVT::i64, Lo, Hi);
1055 Chain = Hi.getValue(1);
1056 break;
1057 }
1058 case MVT::f32:
1059 case MVT::f64: {
1060 std::vector<MVT::ValueType> Tys;
1061 Tys.push_back(MVT::f64);
1062 Tys.push_back(MVT::Other);
1063 std::vector<SDOperand> Ops;
1064 Ops.push_back(Chain);
1065 Ops.push_back(InFlag);
1066 RetVal = DAG.getNode(X86ISD::FP_GET_RESULT, Tys, Ops);
1067 Chain = RetVal.getValue(1);
1068 if (X86ScalarSSE) {
1069 unsigned Size = MVT::getSizeInBits(MVT::f64)/8;
1070 MachineFunction &MF = DAG.getMachineFunction();
1071 int SSFI = MF.getFrameInfo()->CreateStackObject(Size, Size);
1072 SDOperand StackSlot = DAG.getFrameIndex(SSFI, getPointerTy());
1073 Tys.clear();
1074 Tys.push_back(MVT::Other);
1075 Ops.clear();
1076 Ops.push_back(Chain);
1077 Ops.push_back(RetVal);
1078 Ops.push_back(StackSlot);
1079 Ops.push_back(DAG.getValueType(RetTyVT));
1080 Chain = DAG.getNode(X86ISD::FST, Tys, Ops);
1081 RetVal = DAG.getLoad(RetTyVT, Chain, StackSlot,
1082 DAG.getSrcValue(NULL));
1083 Chain = RetVal.getValue(1);
1084 } else if (RetTyVT == MVT::f32)
1085 RetVal = DAG.getNode(ISD::FP_ROUND, MVT::f32, RetVal);
1086 break;
1087 }
1088 }
1089 }
1090
1091 Chain = DAG.getNode(ISD::CALLSEQ_END, MVT::Other, Chain,
1092 DAG.getConstant(ArgOffset, getPointerTy()),
1093 DAG.getConstant(ArgOffset, getPointerTy()));
1094 return std::make_pair(RetVal, Chain);
1095 } else {
1096 std::vector<SDOperand> Ops;
1097 Ops.push_back(Chain);
1098 Ops.push_back(Callee);
1099 Ops.push_back(DAG.getConstant(ArgOffset, getPointerTy()));
1100 // Callee pops all arg values on the stack.
1101 Ops.push_back(DAG.getConstant(ArgOffset, getPointerTy()));
1102
1103 // Pass register arguments as needed.
1104 Ops.insert(Ops.end(), RegValuesToPass.begin(), RegValuesToPass.end());
1105
1106 SDOperand TheCall = DAG.getNode(isTailCall ? X86ISD::TAILCALL : X86ISD::CALL,
1107 RetVals, Ops);
1108 Chain = DAG.getNode(ISD::CALLSEQ_END, MVT::Other, TheCall);
1109
1110 SDOperand ResultVal;
1111 switch (RetTyVT) {
1112 case MVT::isVoid: break;
1113 default:
1114 ResultVal = TheCall.getValue(1);
1115 break;
1116 case MVT::i1:
1117 case MVT::i8:
1118 case MVT::i16:
1119 ResultVal = DAG.getNode(ISD::TRUNCATE, RetTyVT, TheCall.getValue(1));
1120 break;
1121 case MVT::f32:
1122 // FIXME: we would really like to remember that this FP_ROUND operation is
1123 // okay to eliminate if we allow excess FP precision.
1124 ResultVal = DAG.getNode(ISD::FP_ROUND, MVT::f32, TheCall.getValue(1));
1125 break;
1126 case MVT::i64:
1127 ResultVal = DAG.getNode(ISD::BUILD_PAIR, MVT::i64, TheCall.getValue(1),
1128 TheCall.getValue(2));
1129 break;
1130 }
1131
1132 return std::make_pair(ResultVal, Chain);
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +00001133 }
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +00001134}
1135
1136SDOperand X86TargetLowering::getReturnAddressFrameIndex(SelectionDAG &DAG) {
1137 if (ReturnAddrIndex == 0) {
1138 // Set up a frame object for the return address.
1139 MachineFunction &MF = DAG.getMachineFunction();
1140 ReturnAddrIndex = MF.getFrameInfo()->CreateFixedObject(4, -4);
1141 }
1142
1143 return DAG.getFrameIndex(ReturnAddrIndex, MVT::i32);
1144}
1145
1146
1147
1148std::pair<SDOperand, SDOperand> X86TargetLowering::
1149LowerFrameReturnAddress(bool isFrameAddress, SDOperand Chain, unsigned Depth,
1150 SelectionDAG &DAG) {
1151 SDOperand Result;
1152 if (Depth) // Depths > 0 not supported yet!
1153 Result = DAG.getConstant(0, getPointerTy());
1154 else {
1155 SDOperand RetAddrFI = getReturnAddressFrameIndex(DAG);
1156 if (!isFrameAddress)
1157 // Just load the return address
1158 Result = DAG.getLoad(MVT::i32, DAG.getEntryNode(), RetAddrFI,
1159 DAG.getSrcValue(NULL));
1160 else
1161 Result = DAG.getNode(ISD::SUB, MVT::i32, RetAddrFI,
1162 DAG.getConstant(4, MVT::i32));
1163 }
1164 return std::make_pair(Result, Chain);
1165}
1166
Evan Cheng4a460802006-01-11 00:33:36 +00001167/// getCondBrOpcodeForX86CC - Returns the X86 conditional branch opcode
1168/// which corresponds to the condition code.
1169static unsigned getCondBrOpcodeForX86CC(unsigned X86CC) {
1170 switch (X86CC) {
1171 default: assert(0 && "Unknown X86 conditional code!");
1172 case X86ISD::COND_A: return X86::JA;
1173 case X86ISD::COND_AE: return X86::JAE;
1174 case X86ISD::COND_B: return X86::JB;
1175 case X86ISD::COND_BE: return X86::JBE;
1176 case X86ISD::COND_E: return X86::JE;
1177 case X86ISD::COND_G: return X86::JG;
1178 case X86ISD::COND_GE: return X86::JGE;
1179 case X86ISD::COND_L: return X86::JL;
1180 case X86ISD::COND_LE: return X86::JLE;
1181 case X86ISD::COND_NE: return X86::JNE;
1182 case X86ISD::COND_NO: return X86::JNO;
1183 case X86ISD::COND_NP: return X86::JNP;
1184 case X86ISD::COND_NS: return X86::JNS;
1185 case X86ISD::COND_O: return X86::JO;
1186 case X86ISD::COND_P: return X86::JP;
1187 case X86ISD::COND_S: return X86::JS;
1188 }
1189}
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +00001190
Evan Cheng4a460802006-01-11 00:33:36 +00001191/// getX86CC - do a one to one translation of a ISD::CondCode to the X86
1192/// specific condition code. It returns a X86ISD::COND_INVALID if it cannot
Evan Chengd9558e02006-01-06 00:43:03 +00001193/// do a direct translation.
Evan Cheng4a460802006-01-11 00:33:36 +00001194static unsigned getX86CC(SDOperand CC, bool isFP) {
Evan Chengd9558e02006-01-06 00:43:03 +00001195 ISD::CondCode SetCCOpcode = cast<CondCodeSDNode>(CC)->get();
1196 unsigned X86CC = X86ISD::COND_INVALID;
1197 if (!isFP) {
1198 switch (SetCCOpcode) {
1199 default: break;
1200 case ISD::SETEQ: X86CC = X86ISD::COND_E; break;
1201 case ISD::SETGT: X86CC = X86ISD::COND_G; break;
1202 case ISD::SETGE: X86CC = X86ISD::COND_GE; break;
1203 case ISD::SETLT: X86CC = X86ISD::COND_L; break;
1204 case ISD::SETLE: X86CC = X86ISD::COND_LE; break;
1205 case ISD::SETNE: X86CC = X86ISD::COND_NE; break;
1206 case ISD::SETULT: X86CC = X86ISD::COND_B; break;
1207 case ISD::SETUGT: X86CC = X86ISD::COND_A; break;
1208 case ISD::SETULE: X86CC = X86ISD::COND_BE; break;
1209 case ISD::SETUGE: X86CC = X86ISD::COND_AE; break;
1210 }
1211 } else {
1212 // On a floating point condition, the flags are set as follows:
1213 // ZF PF CF op
1214 // 0 | 0 | 0 | X > Y
1215 // 0 | 0 | 1 | X < Y
1216 // 1 | 0 | 0 | X == Y
1217 // 1 | 1 | 1 | unordered
1218 switch (SetCCOpcode) {
1219 default: break;
1220 case ISD::SETUEQ:
1221 case ISD::SETEQ: X86CC = X86ISD::COND_E; break;
1222 case ISD::SETOGT:
1223 case ISD::SETGT: X86CC = X86ISD::COND_A; break;
1224 case ISD::SETOGE:
1225 case ISD::SETGE: X86CC = X86ISD::COND_AE; break;
1226 case ISD::SETULT:
1227 case ISD::SETLT: X86CC = X86ISD::COND_B; break;
1228 case ISD::SETULE:
1229 case ISD::SETLE: X86CC = X86ISD::COND_BE; break;
1230 case ISD::SETONE:
1231 case ISD::SETNE: X86CC = X86ISD::COND_NE; break;
1232 case ISD::SETUO: X86CC = X86ISD::COND_P; break;
1233 case ISD::SETO: X86CC = X86ISD::COND_NP; break;
1234 }
1235 }
1236 return X86CC;
1237}
1238
Evan Cheng4a460802006-01-11 00:33:36 +00001239/// hasFPCMov - is there a floating point cmov for the specific X86 condition
1240/// code. Current x86 isa includes the following FP cmov instructions:
Evan Chengaaca22c2006-01-10 20:26:56 +00001241/// fcmovb, fcomvbe, fcomve, fcmovu, fcmovae, fcmova, fcmovne, fcmovnu.
Evan Cheng4a460802006-01-11 00:33:36 +00001242static bool hasFPCMov(unsigned X86CC) {
Evan Chengaaca22c2006-01-10 20:26:56 +00001243 switch (X86CC) {
1244 default:
1245 return false;
1246 case X86ISD::COND_B:
1247 case X86ISD::COND_BE:
1248 case X86ISD::COND_E:
1249 case X86ISD::COND_P:
1250 case X86ISD::COND_A:
1251 case X86ISD::COND_AE:
1252 case X86ISD::COND_NE:
1253 case X86ISD::COND_NP:
1254 return true;
1255 }
1256}
1257
Evan Cheng4a460802006-01-11 00:33:36 +00001258MachineBasicBlock *
1259X86TargetLowering::InsertAtEndOfBasicBlock(MachineInstr *MI,
1260 MachineBasicBlock *BB) {
1261 assert((MI->getOpcode() == X86::CMOV_FR32 ||
1262 MI->getOpcode() == X86::CMOV_FR64) &&
1263 "Unexpected instr type to insert");
1264
1265 // To "insert" a SELECT_CC instruction, we actually have to insert the diamond
1266 // control-flow pattern. The incoming instruction knows the destination vreg
1267 // to set, the condition code register to branch on, the true/false values to
1268 // select between, and a branch opcode to use.
1269 const BasicBlock *LLVM_BB = BB->getBasicBlock();
1270 ilist<MachineBasicBlock>::iterator It = BB;
1271 ++It;
1272
1273 // thisMBB:
1274 // ...
1275 // TrueVal = ...
1276 // cmpTY ccX, r1, r2
1277 // bCC copy1MBB
1278 // fallthrough --> copy0MBB
1279 MachineBasicBlock *thisMBB = BB;
1280 MachineBasicBlock *copy0MBB = new MachineBasicBlock(LLVM_BB);
1281 MachineBasicBlock *sinkMBB = new MachineBasicBlock(LLVM_BB);
1282 unsigned Opc = getCondBrOpcodeForX86CC(MI->getOperand(3).getImmedValue());
1283 BuildMI(BB, Opc, 1).addMBB(sinkMBB);
1284 MachineFunction *F = BB->getParent();
1285 F->getBasicBlockList().insert(It, copy0MBB);
1286 F->getBasicBlockList().insert(It, sinkMBB);
1287 // Update machine-CFG edges
1288 BB->addSuccessor(copy0MBB);
1289 BB->addSuccessor(sinkMBB);
1290
1291 // copy0MBB:
1292 // %FalseValue = ...
1293 // # fallthrough to sinkMBB
1294 BB = copy0MBB;
1295
1296 // Update machine-CFG edges
1297 BB->addSuccessor(sinkMBB);
1298
1299 // sinkMBB:
1300 // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ]
1301 // ...
1302 BB = sinkMBB;
1303 BuildMI(BB, X86::PHI, 4, MI->getOperand(0).getReg())
1304 .addReg(MI->getOperand(1).getReg()).addMBB(copy0MBB)
1305 .addReg(MI->getOperand(2).getReg()).addMBB(thisMBB);
1306
1307 delete MI; // The pseudo instruction is gone now.
1308 return BB;
1309}
1310
1311
1312//===----------------------------------------------------------------------===//
1313// X86 Custom Lowering Hooks
1314//===----------------------------------------------------------------------===//
1315
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +00001316/// LowerOperation - Provide custom lowering hooks for some operations.
1317///
1318SDOperand X86TargetLowering::LowerOperation(SDOperand Op, SelectionDAG &DAG) {
1319 switch (Op.getOpcode()) {
1320 default: assert(0 && "Should not custom lower this!");
Evan Chenge3413162006-01-09 18:33:28 +00001321 case ISD::ADD_PARTS:
1322 case ISD::SUB_PARTS: {
1323 assert(Op.getNumOperands() == 4 && Op.getValueType() == MVT::i32 &&
1324 "Not an i64 add/sub!");
1325 bool isAdd = Op.getOpcode() == ISD::ADD_PARTS;
1326 std::vector<MVT::ValueType> Tys;
1327 Tys.push_back(MVT::i32);
1328 Tys.push_back(MVT::Flag);
1329 std::vector<SDOperand> Ops;
1330 Ops.push_back(Op.getOperand(0));
1331 Ops.push_back(Op.getOperand(2));
1332 SDOperand Lo = DAG.getNode(isAdd ? X86ISD::ADD_FLAG : X86ISD::SUB_FLAG,
1333 Tys, Ops);
1334 SDOperand Hi = DAG.getNode(isAdd ? X86ISD::ADC : X86ISD::SBB, MVT::i32,
1335 Op.getOperand(1), Op.getOperand(3),
1336 Lo.getValue(1));
1337 Tys.clear();
1338 Tys.push_back(MVT::i32);
1339 Tys.push_back(MVT::i32);
1340 Ops.clear();
1341 Ops.push_back(Lo);
1342 Ops.push_back(Hi);
1343 return DAG.getNode(ISD::MERGE_VALUES, Tys, Ops);
1344 }
1345 case ISD::SHL_PARTS:
1346 case ISD::SRA_PARTS:
1347 case ISD::SRL_PARTS: {
1348 assert(Op.getNumOperands() == 3 && Op.getValueType() == MVT::i32 &&
1349 "Not an i64 shift!");
1350 bool isSRA = Op.getOpcode() == ISD::SRA_PARTS;
1351 SDOperand ShOpLo = Op.getOperand(0);
1352 SDOperand ShOpHi = Op.getOperand(1);
1353 SDOperand ShAmt = Op.getOperand(2);
1354 SDOperand Tmp1 = isSRA ? DAG.getNode(ISD::SRA, MVT::i32, ShOpHi,
Evan Cheng910cd3c2006-01-09 22:29:54 +00001355 DAG.getConstant(31, MVT::i32))
Evan Chenge3413162006-01-09 18:33:28 +00001356 : DAG.getConstant(0, MVT::i32);
1357
1358 SDOperand Tmp2, Tmp3;
1359 if (Op.getOpcode() == ISD::SHL_PARTS) {
1360 Tmp2 = DAG.getNode(X86ISD::SHLD, MVT::i32, ShOpHi, ShOpLo, ShAmt);
1361 Tmp3 = DAG.getNode(ISD::SHL, MVT::i32, ShOpLo, ShAmt);
1362 } else {
1363 Tmp2 = DAG.getNode(X86ISD::SHRD, MVT::i32, ShOpLo, ShOpHi, ShAmt);
1364 Tmp3 = DAG.getNode(isSRA ? ISD::SRA : ISD::SHL, MVT::i32, ShOpHi, ShAmt);
1365 }
1366
1367 SDOperand InFlag = DAG.getNode(X86ISD::TEST, MVT::Flag,
1368 ShAmt, DAG.getConstant(32, MVT::i8));
1369
1370 SDOperand Hi, Lo;
Evan Cheng82a24b92006-01-09 20:49:21 +00001371 SDOperand CC = DAG.getConstant(X86ISD::COND_NE, MVT::i8);
Evan Chenge3413162006-01-09 18:33:28 +00001372
1373 std::vector<MVT::ValueType> Tys;
1374 Tys.push_back(MVT::i32);
1375 Tys.push_back(MVT::Flag);
1376 std::vector<SDOperand> Ops;
1377 if (Op.getOpcode() == ISD::SHL_PARTS) {
1378 Ops.push_back(Tmp2);
1379 Ops.push_back(Tmp3);
1380 Ops.push_back(CC);
1381 Ops.push_back(InFlag);
1382 Hi = DAG.getNode(X86ISD::CMOV, Tys, Ops);
1383 InFlag = Hi.getValue(1);
1384
1385 Ops.clear();
1386 Ops.push_back(Tmp3);
1387 Ops.push_back(Tmp1);
1388 Ops.push_back(CC);
1389 Ops.push_back(InFlag);
1390 Lo = DAG.getNode(X86ISD::CMOV, Tys, Ops);
1391 } else {
1392 Ops.push_back(Tmp2);
1393 Ops.push_back(Tmp3);
1394 Ops.push_back(CC);
Evan Cheng910cd3c2006-01-09 22:29:54 +00001395 Ops.push_back(InFlag);
Evan Chenge3413162006-01-09 18:33:28 +00001396 Lo = DAG.getNode(X86ISD::CMOV, Tys, Ops);
1397 InFlag = Lo.getValue(1);
1398
1399 Ops.clear();
1400 Ops.push_back(Tmp3);
1401 Ops.push_back(Tmp1);
1402 Ops.push_back(CC);
1403 Ops.push_back(InFlag);
1404 Hi = DAG.getNode(X86ISD::CMOV, Tys, Ops);
1405 }
1406
1407 Tys.clear();
1408 Tys.push_back(MVT::i32);
1409 Tys.push_back(MVT::i32);
1410 Ops.clear();
1411 Ops.push_back(Lo);
1412 Ops.push_back(Hi);
1413 return DAG.getNode(ISD::MERGE_VALUES, Tys, Ops);
1414 }
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +00001415 case ISD::SINT_TO_FP: {
1416 assert(Op.getValueType() == MVT::f64 &&
Evan Chenga3195e82006-01-12 22:54:21 +00001417 Op.getOperand(0).getValueType() <= MVT::i64 &&
1418 Op.getOperand(0).getValueType() >= MVT::i16 &&
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +00001419 "Unknown SINT_TO_FP to lower!");
Evan Chenga3195e82006-01-12 22:54:21 +00001420
1421 SDOperand Result;
1422 MVT::ValueType SrcVT = Op.getOperand(0).getValueType();
1423 unsigned Size = MVT::getSizeInBits(SrcVT)/8;
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +00001424 MachineFunction &MF = DAG.getMachineFunction();
Evan Chenga3195e82006-01-12 22:54:21 +00001425 int SSFI = MF.getFrameInfo()->CreateStackObject(Size, Size);
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +00001426 SDOperand StackSlot = DAG.getFrameIndex(SSFI, getPointerTy());
Evan Chenga3195e82006-01-12 22:54:21 +00001427 SDOperand Chain = DAG.getNode(ISD::STORE, MVT::Other,
1428 DAG.getEntryNode(), Op.getOperand(0),
1429 StackSlot, DAG.getSrcValue(NULL));
1430
1431 // Build the FILD
1432 std::vector<MVT::ValueType> Tys;
1433 Tys.push_back(MVT::f64);
1434 Tys.push_back(MVT::Flag);
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +00001435 std::vector<SDOperand> Ops;
Evan Chenga3195e82006-01-12 22:54:21 +00001436 Ops.push_back(Chain);
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +00001437 Ops.push_back(StackSlot);
Evan Chenga3195e82006-01-12 22:54:21 +00001438 Ops.push_back(DAG.getValueType(SrcVT));
1439 Result = DAG.getNode(X86ISD::FILD, Tys, Ops);
1440 return Result;
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +00001441 }
1442 case ISD::FP_TO_SINT: {
1443 assert(Op.getValueType() <= MVT::i64 && Op.getValueType() >= MVT::i16 &&
1444 Op.getOperand(0).getValueType() == MVT::f64 &&
1445 "Unknown FP_TO_SINT to lower!");
1446 // We lower FP->sint64 into FISTP64, followed by a load, all to a temporary
1447 // stack slot.
1448 MachineFunction &MF = DAG.getMachineFunction();
1449 unsigned MemSize = MVT::getSizeInBits(Op.getValueType())/8;
1450 int SSFI = MF.getFrameInfo()->CreateStackObject(MemSize, MemSize);
1451 SDOperand StackSlot = DAG.getFrameIndex(SSFI, getPointerTy());
1452
1453 unsigned Opc;
1454 switch (Op.getValueType()) {
1455 default: assert(0 && "Invalid FP_TO_SINT to lower!");
1456 case MVT::i16: Opc = X86ISD::FP_TO_INT16_IN_MEM; break;
1457 case MVT::i32: Opc = X86ISD::FP_TO_INT32_IN_MEM; break;
1458 case MVT::i64: Opc = X86ISD::FP_TO_INT64_IN_MEM; break;
1459 }
1460
1461 // Build the FP_TO_INT*_IN_MEM
1462 std::vector<SDOperand> Ops;
1463 Ops.push_back(DAG.getEntryNode());
1464 Ops.push_back(Op.getOperand(0));
1465 Ops.push_back(StackSlot);
1466 SDOperand FIST = DAG.getNode(Opc, MVT::Other, Ops);
1467
1468 // Load the result.
1469 return DAG.getLoad(Op.getValueType(), FIST, StackSlot,
1470 DAG.getSrcValue(NULL));
1471 }
Andrew Lenharthb873ff32005-11-20 21:41:10 +00001472 case ISD::READCYCLECOUNTER: {
Chris Lattner81363c32005-11-20 22:01:40 +00001473 std::vector<MVT::ValueType> Tys;
1474 Tys.push_back(MVT::Other);
1475 Tys.push_back(MVT::Flag);
1476 std::vector<SDOperand> Ops;
1477 Ops.push_back(Op.getOperand(0));
1478 SDOperand rd = DAG.getNode(X86ISD::RDTSC_DAG, Tys, Ops);
Chris Lattner81f803d2005-11-20 22:57:19 +00001479 Ops.clear();
1480 Ops.push_back(DAG.getCopyFromReg(rd, X86::EAX, MVT::i32, rd.getValue(1)));
1481 Ops.push_back(DAG.getCopyFromReg(Ops[0].getValue(1), X86::EDX,
1482 MVT::i32, Ops[0].getValue(2)));
1483 Ops.push_back(Ops[1].getValue(1));
1484 Tys[0] = Tys[1] = MVT::i32;
1485 Tys.push_back(MVT::Other);
1486 return DAG.getNode(ISD::MERGE_VALUES, Tys, Ops);
Andrew Lenharthb873ff32005-11-20 21:41:10 +00001487 }
Evan Chengd5781fc2005-12-21 20:21:51 +00001488 case ISD::SETCC: {
1489 assert(Op.getValueType() == MVT::i8 && "SetCC type must be 8-bit integer");
1490 SDOperand CC = Op.getOperand(2);
1491 SDOperand Cond = DAG.getNode(X86ISD::CMP, MVT::Flag,
1492 Op.getOperand(0), Op.getOperand(1));
Evan Chengd9558e02006-01-06 00:43:03 +00001493 ISD::CondCode SetCCOpcode = cast<CondCodeSDNode>(CC)->get();
1494 bool isFP = MVT::isFloatingPoint(Op.getOperand(1).getValueType());
Evan Cheng4a460802006-01-11 00:33:36 +00001495 unsigned X86CC = getX86CC(CC, isFP);
Evan Chengd9558e02006-01-06 00:43:03 +00001496 if (X86CC != X86ISD::COND_INVALID) {
1497 return DAG.getNode(X86ISD::SETCC, MVT::i8,
1498 DAG.getConstant(X86CC, MVT::i8), Cond);
1499 } else {
1500 assert(isFP && "Illegal integer SetCC!");
1501
1502 std::vector<MVT::ValueType> Tys;
1503 std::vector<SDOperand> Ops;
1504 switch (SetCCOpcode) {
1505 default: assert(false && "Illegal floating point SetCC!");
1506 case ISD::SETOEQ: { // !PF & ZF
1507 Tys.push_back(MVT::i8);
1508 Tys.push_back(MVT::Flag);
1509 Ops.push_back(DAG.getConstant(X86ISD::COND_NP, MVT::i8));
1510 Ops.push_back(Cond);
1511 SDOperand Tmp1 = DAG.getNode(X86ISD::SETCC, Tys, Ops);
1512 SDOperand Tmp2 = DAG.getNode(X86ISD::SETCC, MVT::i8,
1513 DAG.getConstant(X86ISD::COND_E, MVT::i8),
1514 Tmp1.getValue(1));
1515 return DAG.getNode(ISD::AND, MVT::i8, Tmp1, Tmp2);
1516 }
1517 case ISD::SETOLT: { // !PF & CF
1518 Tys.push_back(MVT::i8);
1519 Tys.push_back(MVT::Flag);
1520 Ops.push_back(DAG.getConstant(X86ISD::COND_NP, MVT::i8));
1521 Ops.push_back(Cond);
1522 SDOperand Tmp1 = DAG.getNode(X86ISD::SETCC, Tys, Ops);
1523 SDOperand Tmp2 = DAG.getNode(X86ISD::SETCC, MVT::i8,
1524 DAG.getConstant(X86ISD::COND_B, MVT::i8),
1525 Tmp1.getValue(1));
1526 return DAG.getNode(ISD::AND, MVT::i8, Tmp1, Tmp2);
1527 }
1528 case ISD::SETOLE: { // !PF & (CF || ZF)
1529 Tys.push_back(MVT::i8);
1530 Tys.push_back(MVT::Flag);
1531 Ops.push_back(DAG.getConstant(X86ISD::COND_NP, MVT::i8));
1532 Ops.push_back(Cond);
1533 SDOperand Tmp1 = DAG.getNode(X86ISD::SETCC, Tys, Ops);
1534 SDOperand Tmp2 = DAG.getNode(X86ISD::SETCC, MVT::i8,
1535 DAG.getConstant(X86ISD::COND_BE, MVT::i8),
1536 Tmp1.getValue(1));
1537 return DAG.getNode(ISD::AND, MVT::i8, Tmp1, Tmp2);
1538 }
1539 case ISD::SETUGT: { // PF | (!ZF & !CF)
1540 Tys.push_back(MVT::i8);
1541 Tys.push_back(MVT::Flag);
1542 Ops.push_back(DAG.getConstant(X86ISD::COND_P, MVT::i8));
1543 Ops.push_back(Cond);
1544 SDOperand Tmp1 = DAG.getNode(X86ISD::SETCC, Tys, Ops);
1545 SDOperand Tmp2 = DAG.getNode(X86ISD::SETCC, MVT::i8,
1546 DAG.getConstant(X86ISD::COND_A, MVT::i8),
1547 Tmp1.getValue(1));
1548 return DAG.getNode(ISD::OR, MVT::i8, Tmp1, Tmp2);
1549 }
1550 case ISD::SETUGE: { // PF | !CF
1551 Tys.push_back(MVT::i8);
1552 Tys.push_back(MVT::Flag);
1553 Ops.push_back(DAG.getConstant(X86ISD::COND_P, MVT::i8));
1554 Ops.push_back(Cond);
1555 SDOperand Tmp1 = DAG.getNode(X86ISD::SETCC, Tys, Ops);
1556 SDOperand Tmp2 = DAG.getNode(X86ISD::SETCC, MVT::i8,
1557 DAG.getConstant(X86ISD::COND_AE, MVT::i8),
1558 Tmp1.getValue(1));
1559 return DAG.getNode(ISD::OR, MVT::i8, Tmp1, Tmp2);
1560 }
1561 case ISD::SETUNE: { // PF | !ZF
1562 Tys.push_back(MVT::i8);
1563 Tys.push_back(MVT::Flag);
1564 Ops.push_back(DAG.getConstant(X86ISD::COND_P, MVT::i8));
1565 Ops.push_back(Cond);
1566 SDOperand Tmp1 = DAG.getNode(X86ISD::SETCC, Tys, Ops);
1567 SDOperand Tmp2 = DAG.getNode(X86ISD::SETCC, MVT::i8,
1568 DAG.getConstant(X86ISD::COND_NE, MVT::i8),
1569 Tmp1.getValue(1));
1570 return DAG.getNode(ISD::OR, MVT::i8, Tmp1, Tmp2);
1571 }
1572 }
1573 }
Evan Chengd5781fc2005-12-21 20:21:51 +00001574 }
Evan Cheng7df96d62005-12-17 01:21:05 +00001575 case ISD::SELECT: {
Evan Chengaaca22c2006-01-10 20:26:56 +00001576 MVT::ValueType VT = Op.getValueType();
1577 bool isFP = MVT::isFloatingPoint(VT);
1578 bool isFPStack = isFP && (X86Vector < SSE2);
1579 bool isFPSSE = isFP && (X86Vector >= SSE2);
Evan Cheng1bcee362006-01-13 01:03:02 +00001580 bool addTest = false;
Evan Chengaaca22c2006-01-10 20:26:56 +00001581 SDOperand Op0 = Op.getOperand(0);
1582 SDOperand Cond, CC;
1583 if (Op0.getOpcode() == X86ISD::SETCC) {
Evan Cheng1bcee362006-01-13 01:03:02 +00001584 // If condition flag is set by a X86ISD::CMP, then make a copy of it
1585 // (since flag operand cannot be shared). If the X86ISD::SETCC does not
1586 // have another use it will be eliminated.
1587 // If the X86ISD::SETCC has more than one use, then it's probably better
1588 // to use a test instead of duplicating the X86ISD::CMP (for register
1589 // pressure reason).
Evan Cheng80ebe382006-01-13 01:17:24 +00001590 if (Op0.hasOneUse() && Op0.getOperand(1).getOpcode() == X86ISD::CMP) {
Evan Cheng1bcee362006-01-13 01:03:02 +00001591 CC = Op0.getOperand(0);
1592 Cond = Op0.getOperand(1);
1593 addTest =
Evan Cheng80ebe382006-01-13 01:17:24 +00001594 isFPStack && !hasFPCMov(cast<ConstantSDNode>(CC)->getSignExtended());
Evan Cheng1bcee362006-01-13 01:03:02 +00001595 } else
1596 addTest = true;
Evan Chengaaca22c2006-01-10 20:26:56 +00001597 } else if (Op0.getOpcode() == ISD::SETCC) {
1598 CC = Op0.getOperand(2);
1599 bool isFP = MVT::isFloatingPoint(Op0.getOperand(1).getValueType());
Evan Cheng4a460802006-01-11 00:33:36 +00001600 unsigned X86CC = getX86CC(CC, isFP);
Evan Chengd9558e02006-01-06 00:43:03 +00001601 CC = DAG.getConstant(X86CC, MVT::i8);
Evan Cheng7df96d62005-12-17 01:21:05 +00001602 Cond = DAG.getNode(X86ISD::CMP, MVT::Flag,
Evan Chengaaca22c2006-01-10 20:26:56 +00001603 Op0.getOperand(0), Op0.getOperand(1));
Evan Cheng1bcee362006-01-13 01:03:02 +00001604 addTest = true;
1605 } else
1606 addTest = true;
Evan Chengaaca22c2006-01-10 20:26:56 +00001607
Evan Cheng189d01e2006-01-13 01:06:49 +00001608 if (addTest) {
Evan Chengd9558e02006-01-06 00:43:03 +00001609 CC = DAG.getConstant(X86ISD::COND_E, MVT::i8);
Evan Chengaaca22c2006-01-10 20:26:56 +00001610 Cond = DAG.getNode(X86ISD::TEST, MVT::Flag, Op0, Op0);
Evan Cheng7df96d62005-12-17 01:21:05 +00001611 }
Evan Chenge3413162006-01-09 18:33:28 +00001612
1613 std::vector<MVT::ValueType> Tys;
1614 Tys.push_back(Op.getValueType());
1615 Tys.push_back(MVT::Flag);
1616 std::vector<SDOperand> Ops;
1617 Ops.push_back(Op.getOperand(1));
1618 Ops.push_back(Op.getOperand(2));
1619 Ops.push_back(CC);
1620 Ops.push_back(Cond);
1621 return DAG.getNode(X86ISD::CMOV, Tys, Ops);
Evan Cheng7df96d62005-12-17 01:21:05 +00001622 }
Evan Cheng898101c2005-12-19 23:12:38 +00001623 case ISD::BRCOND: {
Evan Cheng1bcee362006-01-13 01:03:02 +00001624 bool addTest = false;
Evan Cheng898101c2005-12-19 23:12:38 +00001625 SDOperand Cond = Op.getOperand(1);
1626 SDOperand Dest = Op.getOperand(2);
1627 SDOperand CC;
Evan Chengd5781fc2005-12-21 20:21:51 +00001628 if (Cond.getOpcode() == X86ISD::SETCC) {
Evan Cheng1bcee362006-01-13 01:03:02 +00001629 // If condition flag is set by a X86ISD::CMP, then make a copy of it
1630 // (since flag operand cannot be shared). If the X86ISD::SETCC does not
1631 // have another use it will be eliminated.
1632 // If the X86ISD::SETCC has more than one use, then it's probably better
1633 // to use a test instead of duplicating the X86ISD::CMP (for register
1634 // pressure reason).
1635 if (Cond.hasOneUse() && Cond.getOperand(1).getOpcode() == X86ISD::CMP) {
1636 CC = Cond.getOperand(0);
1637 Cond = DAG.getNode(X86ISD::CMP, MVT::Flag,
1638 Cond.getOperand(1).getOperand(0),
1639 Cond.getOperand(1).getOperand(1));
1640 } else
1641 addTest = true;
Evan Chengd5781fc2005-12-21 20:21:51 +00001642 } else if (Cond.getOpcode() == ISD::SETCC) {
Evan Cheng898101c2005-12-19 23:12:38 +00001643 CC = Cond.getOperand(2);
Evan Chengd9558e02006-01-06 00:43:03 +00001644 bool isFP = MVT::isFloatingPoint(Cond.getOperand(1).getValueType());
Evan Cheng4a460802006-01-11 00:33:36 +00001645 unsigned X86CC = getX86CC(CC, isFP);
Evan Chengd9558e02006-01-06 00:43:03 +00001646 CC = DAG.getConstant(X86CC, MVT::i8);
Evan Cheng898101c2005-12-19 23:12:38 +00001647 Cond = DAG.getNode(X86ISD::CMP, MVT::Flag,
1648 Cond.getOperand(0), Cond.getOperand(1));
Evan Cheng1bcee362006-01-13 01:03:02 +00001649 } else
1650 addTest = true;
1651
1652 if (addTest) {
Evan Chengd9558e02006-01-06 00:43:03 +00001653 CC = DAG.getConstant(X86ISD::COND_NE, MVT::i8);
Evan Cheng898101c2005-12-19 23:12:38 +00001654 Cond = DAG.getNode(X86ISD::TEST, MVT::Flag, Cond, Cond);
1655 }
1656 return DAG.getNode(X86ISD::BRCOND, Op.getValueType(),
1657 Op.getOperand(0), Op.getOperand(2), CC, Cond);
1658 }
Evan Chengd9558e02006-01-06 00:43:03 +00001659 case ISD::RET: {
1660 // Can only be return void.
Evan Chenge3413162006-01-09 18:33:28 +00001661 return DAG.getNode(X86ISD::RET_FLAG, MVT::Other, Op.getOperand(0),
Evan Chengd9558e02006-01-06 00:43:03 +00001662 DAG.getConstant(getBytesToPopOnReturn(), MVT::i16));
1663 }
Evan Cheng67f92a72006-01-11 22:15:48 +00001664 case ISD::MEMSET: {
1665 SDOperand InFlag;
1666 SDOperand Chain = Op.getOperand(0);
1667 unsigned Align =
1668 (unsigned)cast<ConstantSDNode>(Op.getOperand(4))->getValue();
1669 if (Align == 0) Align = 1;
1670
1671 MVT::ValueType AVT;
1672 SDOperand Count;
1673 if (ConstantSDNode *ValC = dyn_cast<ConstantSDNode>(Op.getOperand(2))) {
1674 unsigned ValReg;
1675 unsigned Val = ValC->getValue() & 255;
1676
1677 // If the value is a constant, then we can potentially use larger sets.
1678 switch (Align & 3) {
1679 case 2: // WORD aligned
1680 AVT = MVT::i16;
1681 if (ConstantSDNode *I = dyn_cast<ConstantSDNode>(Op.getOperand(3)))
1682 Count = DAG.getConstant(I->getValue() / 2, MVT::i32);
1683 else
1684 Count = DAG.getNode(ISD::SRL, MVT::i32, Op.getOperand(3),
1685 DAG.getConstant(1, MVT::i8));
1686 Val = (Val << 8) | Val;
1687 ValReg = X86::AX;
1688 break;
1689 case 0: // DWORD aligned
1690 AVT = MVT::i32;
1691 if (ConstantSDNode *I = dyn_cast<ConstantSDNode>(Op.getOperand(3)))
1692 Count = DAG.getConstant(I->getValue() / 4, MVT::i32);
1693 else
1694 Count = DAG.getNode(ISD::SRL, MVT::i32, Op.getOperand(3),
1695 DAG.getConstant(2, MVT::i8));
1696 Val = (Val << 8) | Val;
1697 Val = (Val << 16) | Val;
1698 ValReg = X86::EAX;
1699 break;
1700 default: // Byte aligned
1701 AVT = MVT::i8;
1702 Count = Op.getOperand(3);
1703 ValReg = X86::AL;
1704 break;
1705 }
1706
1707 Chain = DAG.getCopyToReg(Chain, ValReg, DAG.getConstant(Val, AVT),
1708 InFlag);
1709 InFlag = Chain.getValue(1);
1710 } else {
1711 AVT = MVT::i8;
1712 Count = Op.getOperand(3);
1713 Chain = DAG.getCopyToReg(Chain, X86::AL, Op.getOperand(2), InFlag);
1714 InFlag = Chain.getValue(1);
1715 }
1716
1717 Chain = DAG.getCopyToReg(Chain, X86::ECX, Count, InFlag);
1718 InFlag = Chain.getValue(1);
1719 Chain = DAG.getCopyToReg(Chain, X86::EDI, Op.getOperand(1), InFlag);
1720 InFlag = Chain.getValue(1);
1721
1722 return DAG.getNode(X86ISD::REP_STOS, MVT::Other, Chain,
1723 DAG.getValueType(AVT), InFlag);
1724 }
1725 case ISD::MEMCPY: {
1726 SDOperand Chain = Op.getOperand(0);
1727 unsigned Align =
1728 (unsigned)cast<ConstantSDNode>(Op.getOperand(4))->getValue();
1729 if (Align == 0) Align = 1;
1730
1731 MVT::ValueType AVT;
1732 SDOperand Count;
1733 switch (Align & 3) {
1734 case 2: // WORD aligned
1735 AVT = MVT::i16;
1736 if (ConstantSDNode *I = dyn_cast<ConstantSDNode>(Op.getOperand(3)))
1737 Count = DAG.getConstant(I->getValue() / 2, MVT::i32);
1738 else
1739 Count = DAG.getNode(ISD::SRL, MVT::i32, Op.getOperand(3),
1740 DAG.getConstant(1, MVT::i8));
1741 break;
1742 case 0: // DWORD aligned
1743 AVT = MVT::i32;
1744 if (ConstantSDNode *I = dyn_cast<ConstantSDNode>(Op.getOperand(3)))
1745 Count = DAG.getConstant(I->getValue() / 4, MVT::i32);
1746 else
1747 Count = DAG.getNode(ISD::SRL, MVT::i32, Op.getOperand(3),
1748 DAG.getConstant(2, MVT::i8));
1749 break;
1750 default: // Byte aligned
1751 AVT = MVT::i8;
1752 Count = Op.getOperand(3);
1753 break;
1754 }
1755
1756 SDOperand InFlag;
1757 Chain = DAG.getCopyToReg(Chain, X86::ECX, Count, InFlag);
1758 InFlag = Chain.getValue(1);
1759 Chain = DAG.getCopyToReg(Chain, X86::EDI, Op.getOperand(1), InFlag);
1760 InFlag = Chain.getValue(1);
1761 Chain = DAG.getCopyToReg(Chain, X86::ESI, Op.getOperand(2), InFlag);
1762 InFlag = Chain.getValue(1);
1763
1764 return DAG.getNode(X86ISD::REP_MOVS, MVT::Other, Chain,
1765 DAG.getValueType(AVT), InFlag);
1766 }
Evan Cheng38bcbaf2005-12-23 07:31:11 +00001767 case ISD::GlobalAddress: {
Evan Cheng002fe9b2006-01-12 07:56:47 +00001768 SDOperand Result;
Evan Chengb077b842005-12-21 02:39:21 +00001769 GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
1770 // For Darwin, external and weak symbols are indirect, so we want to load
1771 // the value at address GV, not the value of GV itself. This means that
1772 // the GlobalAddress must be in the base or index register of the address,
1773 // not the GV offset field.
1774 if (getTargetMachine().
1775 getSubtarget<X86Subtarget>().getIndirectExternAndWeakGlobals() &&
1776 (GV->hasWeakLinkage() || GV->isExternal()))
Evan Cheng002fe9b2006-01-12 07:56:47 +00001777 Result = DAG.getLoad(MVT::i32, DAG.getEntryNode(),
1778 DAG.getTargetGlobalAddress(GV, getPointerTy()),
1779 DAG.getSrcValue(NULL));
1780 return Result;
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +00001781 }
Evan Cheng38bcbaf2005-12-23 07:31:11 +00001782 }
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +00001783}
Evan Cheng72261582005-12-20 06:22:03 +00001784
1785const char *X86TargetLowering::getTargetNodeName(unsigned Opcode) const {
1786 switch (Opcode) {
1787 default: return NULL;
Evan Chenge3413162006-01-09 18:33:28 +00001788 case X86ISD::ADD_FLAG: return "X86ISD::ADD_FLAG";
1789 case X86ISD::SUB_FLAG: return "X86ISD::SUB_FLAG";
1790 case X86ISD::ADC: return "X86ISD::ADC";
1791 case X86ISD::SBB: return "X86ISD::SBB";
1792 case X86ISD::SHLD: return "X86ISD::SHLD";
1793 case X86ISD::SHRD: return "X86ISD::SHRD";
Evan Chenga3195e82006-01-12 22:54:21 +00001794 case X86ISD::FILD: return "X86ISD::FILD";
Evan Cheng72261582005-12-20 06:22:03 +00001795 case X86ISD::FP_TO_INT16_IN_MEM: return "X86ISD::FP_TO_INT16_IN_MEM";
1796 case X86ISD::FP_TO_INT32_IN_MEM: return "X86ISD::FP_TO_INT32_IN_MEM";
1797 case X86ISD::FP_TO_INT64_IN_MEM: return "X86ISD::FP_TO_INT64_IN_MEM";
Evan Chengb077b842005-12-21 02:39:21 +00001798 case X86ISD::FLD: return "X86ISD::FLD";
Evan Chengd90eb7f2006-01-05 00:27:02 +00001799 case X86ISD::FST: return "X86ISD::FST";
1800 case X86ISD::FP_GET_RESULT: return "X86ISD::FP_GET_RESULT";
Evan Chengb077b842005-12-21 02:39:21 +00001801 case X86ISD::FP_SET_RESULT: return "X86ISD::FP_SET_RESULT";
Evan Cheng72261582005-12-20 06:22:03 +00001802 case X86ISD::CALL: return "X86ISD::CALL";
1803 case X86ISD::TAILCALL: return "X86ISD::TAILCALL";
1804 case X86ISD::RDTSC_DAG: return "X86ISD::RDTSC_DAG";
1805 case X86ISD::CMP: return "X86ISD::CMP";
1806 case X86ISD::TEST: return "X86ISD::TEST";
Evan Chengd5781fc2005-12-21 20:21:51 +00001807 case X86ISD::SETCC: return "X86ISD::SETCC";
Evan Cheng72261582005-12-20 06:22:03 +00001808 case X86ISD::CMOV: return "X86ISD::CMOV";
1809 case X86ISD::BRCOND: return "X86ISD::BRCOND";
Evan Chengb077b842005-12-21 02:39:21 +00001810 case X86ISD::RET_FLAG: return "X86ISD::RET_FLAG";
Evan Cheng67f92a72006-01-11 22:15:48 +00001811 case X86ISD::REP_STOS: return "X86ISD::RET_STOS";
1812 case X86ISD::REP_MOVS: return "X86ISD::RET_MOVS";
Evan Cheng72261582005-12-20 06:22:03 +00001813 }
1814}
Evan Cheng3a03ebb2005-12-21 23:05:39 +00001815
1816bool X86TargetLowering::isMaskedValueZeroForTargetNode(const SDOperand &Op,
1817 uint64_t Mask) const {
1818
1819 unsigned Opc = Op.getOpcode();
1820
1821 switch (Opc) {
1822 default:
1823 assert(Opc >= ISD::BUILTIN_OP_END && "Expected a target specific node");
1824 break;
1825 case X86ISD::SETCC: return (Mask & 1) == 0;
1826 }
1827
1828 return false;
1829}