blob: e2f22ae0a3e5488d92755d773a503e556aa57c27 [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"
Evan Cheng911c68d2006-01-16 21:21:29 +000016#include "X86InstrBuilder.h"
Chris Lattner76ac0682005-11-15 00:40:23 +000017#include "X86ISelLowering.h"
18#include "X86TargetMachine.h"
19#include "llvm/CallingConv.h"
Evan Cheng72d5c252006-01-31 22:28:30 +000020#include "llvm/Constants.h"
Chris Lattner76ac0682005-11-15 00:40:23 +000021#include "llvm/Function.h"
Chris Lattner76ac0682005-11-15 00:40:23 +000022#include "llvm/CodeGen/MachineFrameInfo.h"
Evan Cheng339edad2006-01-11 00:33:36 +000023#include "llvm/CodeGen/MachineFunction.h"
24#include "llvm/CodeGen/MachineInstrBuilder.h"
Chris Lattner76ac0682005-11-15 00:40:23 +000025#include "llvm/CodeGen/SelectionDAG.h"
26#include "llvm/CodeGen/SSARegMap.h"
Evan Cheng2dd217b2006-01-31 03:14:29 +000027#include "llvm/Support/MathExtras.h"
Chris Lattner76ac0682005-11-15 00:40:23 +000028#include "llvm/Target/TargetOptions.h"
Chris Lattnerc642aa52006-01-31 19:43:35 +000029#include "llvm/ADT/VectorExtras.h"
Chris Lattner76ac0682005-11-15 00:40:23 +000030using namespace llvm;
31
32// FIXME: temporary.
33#include "llvm/Support/CommandLine.h"
34static cl::opt<bool> EnableFastCC("enable-x86-fastcc", cl::Hidden,
35 cl::desc("Enable fastcc on X86"));
36
37X86TargetLowering::X86TargetLowering(TargetMachine &TM)
38 : TargetLowering(TM) {
Evan Chengcde9e302006-01-27 08:10:46 +000039 Subtarget = &TM.getSubtarget<X86Subtarget>();
40 X86ScalarSSE = Subtarget->hasSSE2();
41
Chris Lattner76ac0682005-11-15 00:40:23 +000042 // Set up the TargetLowering object.
43
44 // X86 is weird, it always uses i8 for shift amounts and setcc results.
45 setShiftAmountType(MVT::i8);
46 setSetCCResultType(MVT::i8);
47 setSetCCResultContents(ZeroOrOneSetCCResult);
Evan Cheng83eeefb2006-01-25 09:15:17 +000048 setSchedulingPreference(SchedulingForRegPressure);
Chris Lattner76ac0682005-11-15 00:40:23 +000049 setShiftAmountFlavor(Mask); // shl X, 32 == shl X, 0
Chris Lattner1a8d9182006-01-13 18:00:54 +000050 setStackPointerRegisterToSaveRestore(X86::ESP);
Chris Lattner61c9a8e2006-01-29 06:26:08 +000051
Chris Lattner76ac0682005-11-15 00:40:23 +000052 // Set up the register classes.
Chris Lattner76ac0682005-11-15 00:40:23 +000053 addRegisterClass(MVT::i8, X86::R8RegisterClass);
54 addRegisterClass(MVT::i16, X86::R16RegisterClass);
55 addRegisterClass(MVT::i32, X86::R32RegisterClass);
56
57 // Promote all UINT_TO_FP to larger SINT_TO_FP's, as X86 doesn't have this
58 // operation.
59 setOperationAction(ISD::UINT_TO_FP , MVT::i1 , Promote);
60 setOperationAction(ISD::UINT_TO_FP , MVT::i8 , Promote);
61 setOperationAction(ISD::UINT_TO_FP , MVT::i16 , Promote);
Evan Cheng0d5b69f2006-01-17 02:32:49 +000062
63 if (X86ScalarSSE)
64 // No SSE i64 SINT_TO_FP, so expand i32 UINT_TO_FP instead.
65 setOperationAction(ISD::UINT_TO_FP , MVT::i32 , Expand);
66 else
67 setOperationAction(ISD::UINT_TO_FP , MVT::i32 , Promote);
Chris Lattner76ac0682005-11-15 00:40:23 +000068
69 // Promote i1/i8 SINT_TO_FP to larger SINT_TO_FP's, as X86 doesn't have
70 // this operation.
71 setOperationAction(ISD::SINT_TO_FP , MVT::i1 , Promote);
72 setOperationAction(ISD::SINT_TO_FP , MVT::i8 , Promote);
Nate Begeman7e5496d2006-02-17 00:03:04 +000073 // SSE has no i16 to fp conversion, only i32
Evan Cheng08390f62006-01-30 22:13:22 +000074 if (X86ScalarSSE)
Evan Cheng08390f62006-01-30 22:13:22 +000075 setOperationAction(ISD::SINT_TO_FP , MVT::i16 , Promote);
Evan Cheng593bea72006-02-17 07:01:52 +000076 else {
77 setOperationAction(ISD::SINT_TO_FP , MVT::i16 , Custom);
78 setOperationAction(ISD::SINT_TO_FP , MVT::i32 , Custom);
79 }
Chris Lattner76ac0682005-11-15 00:40:23 +000080
Evan Cheng5b97fcf2006-01-30 08:02:57 +000081 // We can handle SINT_TO_FP and FP_TO_SINT from/to i64 even though i64
82 // isn't legal.
83 setOperationAction(ISD::SINT_TO_FP , MVT::i64 , Custom);
84 setOperationAction(ISD::FP_TO_SINT , MVT::i64 , Custom);
85
Evan Cheng08390f62006-01-30 22:13:22 +000086 // Promote i1/i8 FP_TO_SINT to larger FP_TO_SINTS's, as X86 doesn't have
87 // this operation.
88 setOperationAction(ISD::FP_TO_SINT , MVT::i1 , Promote);
89 setOperationAction(ISD::FP_TO_SINT , MVT::i8 , Promote);
90
91 if (X86ScalarSSE) {
92 setOperationAction(ISD::FP_TO_SINT , MVT::i16 , Promote);
93 } else {
Chris Lattner76ac0682005-11-15 00:40:23 +000094 setOperationAction(ISD::FP_TO_SINT , MVT::i16 , Custom);
Evan Cheng08390f62006-01-30 22:13:22 +000095 setOperationAction(ISD::FP_TO_SINT , MVT::i32 , Custom);
Chris Lattner76ac0682005-11-15 00:40:23 +000096 }
97
98 // Handle FP_TO_UINT by promoting the destination to a larger signed
99 // conversion.
100 setOperationAction(ISD::FP_TO_UINT , MVT::i1 , Promote);
101 setOperationAction(ISD::FP_TO_UINT , MVT::i8 , Promote);
102 setOperationAction(ISD::FP_TO_UINT , MVT::i16 , Promote);
103
Evan Chengd13778e2006-02-18 07:26:17 +0000104 if (X86ScalarSSE && !Subtarget->hasSSE3())
Evan Cheng08390f62006-01-30 22:13:22 +0000105 // Expand FP_TO_UINT into a select.
106 // FIXME: We would like to use a Custom expander here eventually to do
107 // the optimal thing for SSE vs. the default expansion in the legalizer.
108 setOperationAction(ISD::FP_TO_UINT , MVT::i32 , Expand);
109 else
Evan Chengd13778e2006-02-18 07:26:17 +0000110 // With SSE3 we can use fisttpll to convert to a signed i64.
Chris Lattner76ac0682005-11-15 00:40:23 +0000111 setOperationAction(ISD::FP_TO_UINT , MVT::i32 , Promote);
112
Evan Cheng08390f62006-01-30 22:13:22 +0000113 setOperationAction(ISD::BIT_CONVERT , MVT::f32 , Expand);
114 setOperationAction(ISD::BIT_CONVERT , MVT::i32 , Expand);
Chris Lattner30107e62005-12-23 05:15:23 +0000115
Evan Cheng593bea72006-02-17 07:01:52 +0000116 setOperationAction(ISD::BRCOND , MVT::Other, Custom);
Chris Lattner76ac0682005-11-15 00:40:23 +0000117 setOperationAction(ISD::BRCONDTWOWAY , MVT::Other, Expand);
118 setOperationAction(ISD::BRTWOWAY_CC , MVT::Other, Expand);
Nate Begeman7e7f4392006-02-01 07:19:44 +0000119 setOperationAction(ISD::BR_CC , MVT::Other, Expand);
120 setOperationAction(ISD::SELECT_CC , MVT::Other, Expand);
Chris Lattner76ac0682005-11-15 00:40:23 +0000121 setOperationAction(ISD::MEMMOVE , MVT::Other, Expand);
122 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16 , Expand);
Chris Lattner32257332005-12-07 17:59:14 +0000123 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i8 , Expand);
Chris Lattner76ac0682005-11-15 00:40:23 +0000124 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1 , Expand);
125 setOperationAction(ISD::FP_ROUND_INREG , MVT::f32 , Expand);
126 setOperationAction(ISD::SEXTLOAD , MVT::i1 , Expand);
127 setOperationAction(ISD::FREM , MVT::f64 , Expand);
128 setOperationAction(ISD::CTPOP , MVT::i8 , Expand);
129 setOperationAction(ISD::CTTZ , MVT::i8 , Expand);
130 setOperationAction(ISD::CTLZ , MVT::i8 , Expand);
131 setOperationAction(ISD::CTPOP , MVT::i16 , Expand);
132 setOperationAction(ISD::CTTZ , MVT::i16 , Expand);
133 setOperationAction(ISD::CTLZ , MVT::i16 , Expand);
134 setOperationAction(ISD::CTPOP , MVT::i32 , Expand);
135 setOperationAction(ISD::CTTZ , MVT::i32 , Expand);
136 setOperationAction(ISD::CTLZ , MVT::i32 , Expand);
Andrew Lenharth0bf68ae2005-11-20 21:41:10 +0000137 setOperationAction(ISD::READCYCLECOUNTER , MVT::i64 , Custom);
Nate Begeman2fba8a32006-01-14 03:14:10 +0000138 setOperationAction(ISD::BSWAP , MVT::i16 , Expand);
Nate Begeman1b8121b2006-01-11 21:21:00 +0000139
Chris Lattner76ac0682005-11-15 00:40:23 +0000140 setOperationAction(ISD::READIO , MVT::i1 , Expand);
141 setOperationAction(ISD::READIO , MVT::i8 , Expand);
142 setOperationAction(ISD::READIO , MVT::i16 , Expand);
143 setOperationAction(ISD::READIO , MVT::i32 , Expand);
144 setOperationAction(ISD::WRITEIO , MVT::i1 , Expand);
145 setOperationAction(ISD::WRITEIO , MVT::i8 , Expand);
146 setOperationAction(ISD::WRITEIO , MVT::i16 , Expand);
147 setOperationAction(ISD::WRITEIO , MVT::i32 , Expand);
148
149 // These should be promoted to a larger select which is supported.
150 setOperationAction(ISD::SELECT , MVT::i1 , Promote);
151 setOperationAction(ISD::SELECT , MVT::i8 , Promote);
Nate Begeman7e5496d2006-02-17 00:03:04 +0000152
153 // X86 wants to expand cmov itself.
Evan Cheng593bea72006-02-17 07:01:52 +0000154 setOperationAction(ISD::SELECT , MVT::i16 , Custom);
155 setOperationAction(ISD::SELECT , MVT::i32 , Custom);
156 setOperationAction(ISD::SELECT , MVT::f32 , Custom);
157 setOperationAction(ISD::SELECT , MVT::f64 , Custom);
158 setOperationAction(ISD::SETCC , MVT::i8 , Custom);
159 setOperationAction(ISD::SETCC , MVT::i16 , Custom);
160 setOperationAction(ISD::SETCC , MVT::i32 , Custom);
161 setOperationAction(ISD::SETCC , MVT::f32 , Custom);
162 setOperationAction(ISD::SETCC , MVT::f64 , Custom);
Nate Begeman7e5496d2006-02-17 00:03:04 +0000163 // X86 ret instruction may pop stack.
Evan Cheng593bea72006-02-17 07:01:52 +0000164 setOperationAction(ISD::RET , MVT::Other, Custom);
Nate Begeman7e5496d2006-02-17 00:03:04 +0000165 // Darwin ABI issue.
Evan Cheng5588de92006-02-18 00:15:05 +0000166 setOperationAction(ISD::ConstantPool , MVT::i32 , Custom);
Evan Cheng593bea72006-02-17 07:01:52 +0000167 setOperationAction(ISD::GlobalAddress , MVT::i32 , Custom);
Evan Chenge0ed6ec2006-02-23 20:41:18 +0000168 setOperationAction(ISD::ExternalSymbol , MVT::i32 , Custom);
Nate Begeman7e5496d2006-02-17 00:03:04 +0000169 // 64-bit addm sub, shl, sra, srl (iff 32-bit x86)
Evan Cheng593bea72006-02-17 07:01:52 +0000170 setOperationAction(ISD::SHL_PARTS , MVT::i32 , Custom);
171 setOperationAction(ISD::SRA_PARTS , MVT::i32 , Custom);
172 setOperationAction(ISD::SRL_PARTS , MVT::i32 , Custom);
Nate Begeman7e5496d2006-02-17 00:03:04 +0000173 // X86 wants to expand memset / memcpy itself.
Evan Cheng593bea72006-02-17 07:01:52 +0000174 setOperationAction(ISD::MEMSET , MVT::Other, Custom);
175 setOperationAction(ISD::MEMCPY , MVT::Other, Custom);
Chris Lattner76ac0682005-11-15 00:40:23 +0000176
Chris Lattner9c415362005-11-29 06:16:21 +0000177 // We don't have line number support yet.
178 setOperationAction(ISD::LOCATION, MVT::Other, Expand);
Jim Laskeydeeafa02006-01-05 01:47:43 +0000179 setOperationAction(ISD::DEBUG_LOC, MVT::Other, Expand);
180 setOperationAction(ISD::DEBUG_LABEL, MVT::Other, Expand);
Chris Lattner9c415362005-11-29 06:16:21 +0000181
Nate Begemane74795c2006-01-25 18:21:52 +0000182 // VASTART needs to be custom lowered to use the VarArgsFrameIndex
183 setOperationAction(ISD::VASTART , MVT::Other, Custom);
184
185 // Use the default implementation.
186 setOperationAction(ISD::VAARG , MVT::Other, Expand);
187 setOperationAction(ISD::VACOPY , MVT::Other, Expand);
188 setOperationAction(ISD::VAEND , MVT::Other, Expand);
Chris Lattner78c358d2006-01-15 09:00:21 +0000189 setOperationAction(ISD::STACKSAVE, MVT::Other, Expand);
190 setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand);
191 setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32 , Expand);
Chris Lattner8e2f52e2006-01-13 02:42:53 +0000192
Chris Lattner76ac0682005-11-15 00:40:23 +0000193 if (X86ScalarSSE) {
194 // Set up the FP register classes.
Evan Cheng84dc9b52006-01-12 08:27:59 +0000195 addRegisterClass(MVT::f32, X86::FR32RegisterClass);
196 addRegisterClass(MVT::f64, X86::FR64RegisterClass);
Chris Lattner76ac0682005-11-15 00:40:23 +0000197
198 // SSE has no load+extend ops
199 setOperationAction(ISD::EXTLOAD, MVT::f32, Expand);
200 setOperationAction(ISD::ZEXTLOAD, MVT::f32, Expand);
201
Evan Cheng72d5c252006-01-31 22:28:30 +0000202 // Use ANDPD to simulate FABS.
203 setOperationAction(ISD::FABS , MVT::f64, Custom);
204 setOperationAction(ISD::FABS , MVT::f32, Custom);
205
206 // Use XORP to simulate FNEG.
207 setOperationAction(ISD::FNEG , MVT::f64, Custom);
208 setOperationAction(ISD::FNEG , MVT::f32, Custom);
209
Evan Chengd8fba3a2006-02-02 00:28:23 +0000210 // We don't support sin/cos/fmod
Chris Lattner76ac0682005-11-15 00:40:23 +0000211 setOperationAction(ISD::FSIN , MVT::f64, Expand);
212 setOperationAction(ISD::FCOS , MVT::f64, Expand);
Chris Lattner76ac0682005-11-15 00:40:23 +0000213 setOperationAction(ISD::FREM , MVT::f64, Expand);
214 setOperationAction(ISD::FSIN , MVT::f32, Expand);
215 setOperationAction(ISD::FCOS , MVT::f32, Expand);
Chris Lattner76ac0682005-11-15 00:40:23 +0000216 setOperationAction(ISD::FREM , MVT::f32, Expand);
217
Chris Lattner61c9a8e2006-01-29 06:26:08 +0000218 // Expand FP immediates into loads from the stack, except for the special
219 // cases we handle.
220 setOperationAction(ISD::ConstantFP, MVT::f64, Expand);
221 setOperationAction(ISD::ConstantFP, MVT::f32, Expand);
Chris Lattner76ac0682005-11-15 00:40:23 +0000222 addLegalFPImmediate(+0.0); // xorps / xorpd
223 } else {
224 // Set up the FP register classes.
225 addRegisterClass(MVT::f64, X86::RFPRegisterClass);
Chris Lattner132177e2006-01-29 06:44:22 +0000226
227 setOperationAction(ISD::UNDEF, MVT::f64, Expand);
228
Chris Lattner76ac0682005-11-15 00:40:23 +0000229 if (!UnsafeFPMath) {
230 setOperationAction(ISD::FSIN , MVT::f64 , Expand);
231 setOperationAction(ISD::FCOS , MVT::f64 , Expand);
232 }
233
Chris Lattner61c9a8e2006-01-29 06:26:08 +0000234 setOperationAction(ISD::ConstantFP, MVT::f64, Expand);
Chris Lattner76ac0682005-11-15 00:40:23 +0000235 addLegalFPImmediate(+0.0); // FLD0
236 addLegalFPImmediate(+1.0); // FLD1
237 addLegalFPImmediate(-0.0); // FLD0/FCHS
238 addLegalFPImmediate(-1.0); // FLD1/FCHS
239 }
Evan Cheng9e252e32006-02-22 02:26:30 +0000240
241 if (TM.getSubtarget<X86Subtarget>().hasMMX()) {
242 addRegisterClass(MVT::v8i8, X86::VR64RegisterClass);
243 addRegisterClass(MVT::v4i16, X86::VR64RegisterClass);
244 addRegisterClass(MVT::v2i32, X86::VR64RegisterClass);
245
246 // FIXME: We don't support any ConstantVec's yet. We should custom expand
247 // the ones we do!
248 setOperationAction(ISD::ConstantVec, MVT::v8i8, Expand);
249 setOperationAction(ISD::ConstantVec, MVT::v4i16, Expand);
250 setOperationAction(ISD::ConstantVec, MVT::v2i32, Expand);
251 }
252
253 if (TM.getSubtarget<X86Subtarget>().hasSSE1()) {
254 addRegisterClass(MVT::v4f32, X86::VR128RegisterClass);
255
256 // FIXME: We don't support any ConstantVec's yet. We should custom expand
257 // the ones we do!
258 setOperationAction(ISD::ConstantVec, MVT::v4f32, Expand);
259 }
260
261 if (TM.getSubtarget<X86Subtarget>().hasSSE2()) {
262 addRegisterClass(MVT::v2f64, X86::VR128RegisterClass);
263 addRegisterClass(MVT::v16i8, X86::VR128RegisterClass);
264 addRegisterClass(MVT::v8i16, X86::VR128RegisterClass);
265 addRegisterClass(MVT::v4i32, X86::VR128RegisterClass);
266 addRegisterClass(MVT::v2i64, X86::VR128RegisterClass);
267
268
269 // FIXME: We don't support any ConstantVec's yet. We should custom expand
270 // the ones we do!
271 setOperationAction(ISD::ConstantVec, MVT::v2f64, Expand);
272 setOperationAction(ISD::ConstantVec, MVT::v16i8, Expand);
273 setOperationAction(ISD::ConstantVec, MVT::v8i16, Expand);
274 setOperationAction(ISD::ConstantVec, MVT::v4i32, Expand);
275 setOperationAction(ISD::ConstantVec, MVT::v2i64, Expand);
276 }
277
Chris Lattner76ac0682005-11-15 00:40:23 +0000278 computeRegisterProperties();
279
Evan Cheng6a374562006-02-14 08:25:08 +0000280 // FIXME: These should be based on subtarget info. Plus, the values should
281 // be smaller when we are in optimizing for size mode.
Evan Cheng4b40a422006-02-14 08:38:30 +0000282 maxStoresPerMemset = 16; // For %llvm.memset -> sequence of stores
283 maxStoresPerMemcpy = 16; // For %llvm.memcpy -> sequence of stores
284 maxStoresPerMemmove = 16; // For %llvm.memmove -> sequence of stores
Chris Lattner76ac0682005-11-15 00:40:23 +0000285 allowUnalignedMemoryAccesses = true; // x86 supports it!
286}
287
288std::vector<SDOperand>
289X86TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
290 if (F.getCallingConv() == CallingConv::Fast && EnableFastCC)
291 return LowerFastCCArguments(F, DAG);
292 return LowerCCCArguments(F, DAG);
293}
294
295std::pair<SDOperand, SDOperand>
296X86TargetLowering::LowerCallTo(SDOperand Chain, const Type *RetTy,
297 bool isVarArg, unsigned CallingConv,
298 bool isTailCall,
299 SDOperand Callee, ArgListTy &Args,
300 SelectionDAG &DAG) {
301 assert((!isVarArg || CallingConv == CallingConv::C) &&
302 "Only C takes varargs!");
Evan Cheng172fce72006-01-06 00:43:03 +0000303
304 // If the callee is a GlobalAddress node (quite common, every direct call is)
305 // turn it into a TargetGlobalAddress node so that legalize doesn't hack it.
306 if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee))
307 Callee = DAG.getTargetGlobalAddress(G->getGlobal(), getPointerTy());
Evan Chengbc7a0f442006-01-11 06:09:51 +0000308 else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee))
309 Callee = DAG.getTargetExternalSymbol(S->getSymbol(), getPointerTy());
Evan Cheng172fce72006-01-06 00:43:03 +0000310
Chris Lattner76ac0682005-11-15 00:40:23 +0000311 if (CallingConv == CallingConv::Fast && EnableFastCC)
312 return LowerFastCCCallTo(Chain, RetTy, isTailCall, Callee, Args, DAG);
313 return LowerCCCCallTo(Chain, RetTy, isVarArg, isTailCall, Callee, Args, DAG);
314}
315
316//===----------------------------------------------------------------------===//
317// C Calling Convention implementation
318//===----------------------------------------------------------------------===//
319
320std::vector<SDOperand>
321X86TargetLowering::LowerCCCArguments(Function &F, SelectionDAG &DAG) {
322 std::vector<SDOperand> ArgValues;
323
324 MachineFunction &MF = DAG.getMachineFunction();
325 MachineFrameInfo *MFI = MF.getFrameInfo();
326
327 // Add DAG nodes to load the arguments... On entry to a function on the X86,
328 // the stack frame looks like this:
329 //
330 // [ESP] -- return address
331 // [ESP + 4] -- first argument (leftmost lexically)
332 // [ESP + 8] -- second argument, if first argument is four bytes in size
333 // ...
334 //
335 unsigned ArgOffset = 0; // Frame mechanisms handle retaddr slot
336 for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I) {
337 MVT::ValueType ObjectVT = getValueType(I->getType());
338 unsigned ArgIncrement = 4;
339 unsigned ObjSize;
340 switch (ObjectVT) {
341 default: assert(0 && "Unhandled argument type!");
342 case MVT::i1:
343 case MVT::i8: ObjSize = 1; break;
344 case MVT::i16: ObjSize = 2; break;
345 case MVT::i32: ObjSize = 4; break;
346 case MVT::i64: ObjSize = ArgIncrement = 8; break;
347 case MVT::f32: ObjSize = 4; break;
348 case MVT::f64: ObjSize = ArgIncrement = 8; break;
349 }
350 // Create the frame index object for this incoming parameter...
351 int FI = MFI->CreateFixedObject(ObjSize, ArgOffset);
352
353 // Create the SelectionDAG nodes corresponding to a load from this parameter
354 SDOperand FIN = DAG.getFrameIndex(FI, MVT::i32);
355
356 // Don't codegen dead arguments. FIXME: remove this check when we can nuke
357 // dead loads.
358 SDOperand ArgValue;
359 if (!I->use_empty())
360 ArgValue = DAG.getLoad(ObjectVT, DAG.getEntryNode(), FIN,
361 DAG.getSrcValue(NULL));
362 else {
363 if (MVT::isInteger(ObjectVT))
364 ArgValue = DAG.getConstant(0, ObjectVT);
365 else
366 ArgValue = DAG.getConstantFP(0, ObjectVT);
367 }
368 ArgValues.push_back(ArgValue);
369
370 ArgOffset += ArgIncrement; // Move on to the next argument...
371 }
372
373 // If the function takes variable number of arguments, make a frame index for
374 // the start of the first vararg value... for expansion of llvm.va_start.
375 if (F.isVarArg())
376 VarArgsFrameIndex = MFI->CreateFixedObject(1, ArgOffset);
377 ReturnAddrIndex = 0; // No return address slot generated yet.
378 BytesToPopOnReturn = 0; // Callee pops nothing.
379 BytesCallerReserves = ArgOffset;
380
381 // Finally, inform the code generator which regs we return values in.
382 switch (getValueType(F.getReturnType())) {
383 default: assert(0 && "Unknown type!");
384 case MVT::isVoid: break;
385 case MVT::i1:
386 case MVT::i8:
387 case MVT::i16:
388 case MVT::i32:
389 MF.addLiveOut(X86::EAX);
390 break;
391 case MVT::i64:
392 MF.addLiveOut(X86::EAX);
393 MF.addLiveOut(X86::EDX);
394 break;
395 case MVT::f32:
396 case MVT::f64:
397 MF.addLiveOut(X86::ST0);
398 break;
399 }
400 return ArgValues;
401}
402
403std::pair<SDOperand, SDOperand>
404X86TargetLowering::LowerCCCCallTo(SDOperand Chain, const Type *RetTy,
405 bool isVarArg, bool isTailCall,
406 SDOperand Callee, ArgListTy &Args,
407 SelectionDAG &DAG) {
408 // Count how many bytes are to be pushed on the stack.
409 unsigned NumBytes = 0;
410
411 if (Args.empty()) {
412 // Save zero bytes.
Chris Lattner62c34842006-02-13 09:00:43 +0000413 Chain = DAG.getCALLSEQ_START(Chain, DAG.getConstant(0, getPointerTy()));
Chris Lattner76ac0682005-11-15 00:40:23 +0000414 } else {
415 for (unsigned i = 0, e = Args.size(); i != e; ++i)
416 switch (getValueType(Args[i].second)) {
417 default: assert(0 && "Unknown value type!");
418 case MVT::i1:
419 case MVT::i8:
420 case MVT::i16:
421 case MVT::i32:
422 case MVT::f32:
423 NumBytes += 4;
424 break;
425 case MVT::i64:
426 case MVT::f64:
427 NumBytes += 8;
428 break;
429 }
430
Chris Lattner62c34842006-02-13 09:00:43 +0000431 Chain = DAG.getCALLSEQ_START(Chain,
432 DAG.getConstant(NumBytes, getPointerTy()));
Chris Lattner76ac0682005-11-15 00:40:23 +0000433
434 // Arguments go on the stack in reverse order, as specified by the ABI.
435 unsigned ArgOffset = 0;
Evan Chengbc7a0f442006-01-11 06:09:51 +0000436 SDOperand StackPtr = DAG.getRegister(X86::ESP, MVT::i32);
Chris Lattner76ac0682005-11-15 00:40:23 +0000437 std::vector<SDOperand> Stores;
438
439 for (unsigned i = 0, e = Args.size(); i != e; ++i) {
440 SDOperand PtrOff = DAG.getConstant(ArgOffset, getPointerTy());
441 PtrOff = DAG.getNode(ISD::ADD, MVT::i32, StackPtr, PtrOff);
442
443 switch (getValueType(Args[i].second)) {
444 default: assert(0 && "Unexpected ValueType for argument!");
445 case MVT::i1:
446 case MVT::i8:
447 case MVT::i16:
448 // Promote the integer to 32 bits. If the input type is signed use a
449 // sign extend, otherwise use a zero extend.
450 if (Args[i].second->isSigned())
451 Args[i].first =DAG.getNode(ISD::SIGN_EXTEND, MVT::i32, Args[i].first);
452 else
453 Args[i].first =DAG.getNode(ISD::ZERO_EXTEND, MVT::i32, Args[i].first);
454
455 // FALL THROUGH
456 case MVT::i32:
457 case MVT::f32:
458 Stores.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
459 Args[i].first, PtrOff,
460 DAG.getSrcValue(NULL)));
461 ArgOffset += 4;
462 break;
463 case MVT::i64:
464 case MVT::f64:
465 Stores.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
466 Args[i].first, PtrOff,
467 DAG.getSrcValue(NULL)));
468 ArgOffset += 8;
469 break;
470 }
471 }
472 Chain = DAG.getNode(ISD::TokenFactor, MVT::Other, Stores);
473 }
474
475 std::vector<MVT::ValueType> RetVals;
476 MVT::ValueType RetTyVT = getValueType(RetTy);
477 RetVals.push_back(MVT::Other);
478
479 // The result values produced have to be legal. Promote the result.
480 switch (RetTyVT) {
481 case MVT::isVoid: break;
482 default:
483 RetVals.push_back(RetTyVT);
484 break;
485 case MVT::i1:
486 case MVT::i8:
487 case MVT::i16:
488 RetVals.push_back(MVT::i32);
489 break;
490 case MVT::f32:
491 if (X86ScalarSSE)
492 RetVals.push_back(MVT::f32);
493 else
494 RetVals.push_back(MVT::f64);
495 break;
496 case MVT::i64:
497 RetVals.push_back(MVT::i32);
498 RetVals.push_back(MVT::i32);
499 break;
500 }
Chris Lattner76ac0682005-11-15 00:40:23 +0000501
Nate Begeman7e5496d2006-02-17 00:03:04 +0000502 std::vector<MVT::ValueType> NodeTys;
503 NodeTys.push_back(MVT::Other); // Returns a chain
504 NodeTys.push_back(MVT::Flag); // Returns a flag for retval copy to use.
505 std::vector<SDOperand> Ops;
506 Ops.push_back(Chain);
507 Ops.push_back(Callee);
Evan Cheng45e190982006-01-05 00:27:02 +0000508
Nate Begeman7e5496d2006-02-17 00:03:04 +0000509 // FIXME: Do not generate X86ISD::TAILCALL for now.
510 Chain = DAG.getNode(X86ISD::CALL, NodeTys, Ops);
511 SDOperand InFlag = Chain.getValue(1);
Evan Cheng45e190982006-01-05 00:27:02 +0000512
Nate Begeman7e5496d2006-02-17 00:03:04 +0000513 NodeTys.clear();
514 NodeTys.push_back(MVT::Other); // Returns a chain
515 NodeTys.push_back(MVT::Flag); // Returns a flag for retval copy to use.
516 Ops.clear();
517 Ops.push_back(Chain);
518 Ops.push_back(DAG.getConstant(NumBytes, getPointerTy()));
519 Ops.push_back(DAG.getConstant(0, getPointerTy()));
520 Ops.push_back(InFlag);
521 Chain = DAG.getNode(ISD::CALLSEQ_END, NodeTys, Ops);
522 InFlag = Chain.getValue(1);
523
524 SDOperand RetVal;
525 if (RetTyVT != MVT::isVoid) {
Evan Cheng45e190982006-01-05 00:27:02 +0000526 switch (RetTyVT) {
Nate Begeman7e5496d2006-02-17 00:03:04 +0000527 default: assert(0 && "Unknown value type to return!");
Evan Cheng45e190982006-01-05 00:27:02 +0000528 case MVT::i1:
529 case MVT::i8:
Nate Begeman7e5496d2006-02-17 00:03:04 +0000530 RetVal = DAG.getCopyFromReg(Chain, X86::AL, MVT::i8, InFlag);
531 Chain = RetVal.getValue(1);
532 if (RetTyVT == MVT::i1)
533 RetVal = DAG.getNode(ISD::TRUNCATE, MVT::i1, RetVal);
534 break;
Evan Cheng45e190982006-01-05 00:27:02 +0000535 case MVT::i16:
Nate Begeman7e5496d2006-02-17 00:03:04 +0000536 RetVal = DAG.getCopyFromReg(Chain, X86::AX, MVT::i16, InFlag);
537 Chain = RetVal.getValue(1);
Evan Cheng45e190982006-01-05 00:27:02 +0000538 break;
Nate Begeman7e5496d2006-02-17 00:03:04 +0000539 case MVT::i32:
540 RetVal = DAG.getCopyFromReg(Chain, X86::EAX, MVT::i32, InFlag);
541 Chain = RetVal.getValue(1);
Evan Cheng45e190982006-01-05 00:27:02 +0000542 break;
Nate Begeman7e5496d2006-02-17 00:03:04 +0000543 case MVT::i64: {
544 SDOperand Lo = DAG.getCopyFromReg(Chain, X86::EAX, MVT::i32, InFlag);
545 SDOperand Hi = DAG.getCopyFromReg(Lo.getValue(1), X86::EDX, MVT::i32,
546 Lo.getValue(2));
547 RetVal = DAG.getNode(ISD::BUILD_PAIR, MVT::i64, Lo, Hi);
548 Chain = Hi.getValue(1);
Evan Cheng45e190982006-01-05 00:27:02 +0000549 break;
550 }
Nate Begeman7e5496d2006-02-17 00:03:04 +0000551 case MVT::f32:
552 case MVT::f64: {
553 std::vector<MVT::ValueType> Tys;
554 Tys.push_back(MVT::f64);
555 Tys.push_back(MVT::Other);
556 Tys.push_back(MVT::Flag);
557 std::vector<SDOperand> Ops;
558 Ops.push_back(Chain);
559 Ops.push_back(InFlag);
560 RetVal = DAG.getNode(X86ISD::FP_GET_RESULT, Tys, Ops);
561 Chain = RetVal.getValue(1);
562 InFlag = RetVal.getValue(2);
563 if (X86ScalarSSE) {
564 // FIXME: Currently the FST is flagged to the FP_GET_RESULT. This
565 // shouldn't be necessary except that RFP cannot be live across
566 // multiple blocks. When stackifier is fixed, they can be uncoupled.
567 MachineFunction &MF = DAG.getMachineFunction();
568 int SSFI = MF.getFrameInfo()->CreateStackObject(8, 8);
569 SDOperand StackSlot = DAG.getFrameIndex(SSFI, getPointerTy());
570 Tys.clear();
571 Tys.push_back(MVT::Other);
572 Ops.clear();
573 Ops.push_back(Chain);
574 Ops.push_back(RetVal);
575 Ops.push_back(StackSlot);
576 Ops.push_back(DAG.getValueType(RetTyVT));
577 Ops.push_back(InFlag);
578 Chain = DAG.getNode(X86ISD::FST, Tys, Ops);
579 RetVal = DAG.getLoad(RetTyVT, Chain, StackSlot,
580 DAG.getSrcValue(NULL));
581 Chain = RetVal.getValue(1);
582 }
Evan Cheng45e190982006-01-05 00:27:02 +0000583
Nate Begeman7e5496d2006-02-17 00:03:04 +0000584 if (RetTyVT == MVT::f32 && !X86ScalarSSE)
585 // FIXME: we would really like to remember that this FP_ROUND
586 // operation is okay to eliminate if we allow excess FP precision.
587 RetVal = DAG.getNode(ISD::FP_ROUND, MVT::f32, RetVal);
588 break;
589 }
590 }
Chris Lattner76ac0682005-11-15 00:40:23 +0000591 }
Nate Begeman7e5496d2006-02-17 00:03:04 +0000592
593 return std::make_pair(RetVal, Chain);
Chris Lattner76ac0682005-11-15 00:40:23 +0000594}
595
Chris Lattner76ac0682005-11-15 00:40:23 +0000596//===----------------------------------------------------------------------===//
597// Fast Calling Convention implementation
598//===----------------------------------------------------------------------===//
599//
600// The X86 'fast' calling convention passes up to two integer arguments in
601// registers (an appropriate portion of EAX/EDX), passes arguments in C order,
602// and requires that the callee pop its arguments off the stack (allowing proper
603// tail calls), and has the same return value conventions as C calling convs.
604//
605// This calling convention always arranges for the callee pop value to be 8n+4
606// bytes, which is needed for tail recursion elimination and stack alignment
607// reasons.
608//
609// Note that this can be enhanced in the future to pass fp vals in registers
610// (when we have a global fp allocator) and do other tricks.
611//
612
613/// AddLiveIn - This helper function adds the specified physical register to the
614/// MachineFunction as a live in value. It also creates a corresponding virtual
615/// register for it.
616static unsigned AddLiveIn(MachineFunction &MF, unsigned PReg,
617 TargetRegisterClass *RC) {
618 assert(RC->contains(PReg) && "Not the correct regclass!");
619 unsigned VReg = MF.getSSARegMap()->createVirtualRegister(RC);
620 MF.addLiveIn(PReg, VReg);
621 return VReg;
622}
623
624
625std::vector<SDOperand>
626X86TargetLowering::LowerFastCCArguments(Function &F, SelectionDAG &DAG) {
627 std::vector<SDOperand> ArgValues;
628
629 MachineFunction &MF = DAG.getMachineFunction();
630 MachineFrameInfo *MFI = MF.getFrameInfo();
631
632 // Add DAG nodes to load the arguments... On entry to a function the stack
633 // frame looks like this:
634 //
635 // [ESP] -- return address
636 // [ESP + 4] -- first nonreg argument (leftmost lexically)
637 // [ESP + 8] -- second nonreg argument, if first argument is 4 bytes in size
638 // ...
639 unsigned ArgOffset = 0; // Frame mechanisms handle retaddr slot
640
641 // Keep track of the number of integer regs passed so far. This can be either
642 // 0 (neither EAX or EDX used), 1 (EAX is used) or 2 (EAX and EDX are both
643 // used).
644 unsigned NumIntRegs = 0;
645
646 for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I) {
647 MVT::ValueType ObjectVT = getValueType(I->getType());
648 unsigned ArgIncrement = 4;
649 unsigned ObjSize = 0;
650 SDOperand ArgValue;
651
652 switch (ObjectVT) {
653 default: assert(0 && "Unhandled argument type!");
654 case MVT::i1:
655 case MVT::i8:
656 if (NumIntRegs < 2) {
657 if (!I->use_empty()) {
658 unsigned VReg = AddLiveIn(MF, NumIntRegs ? X86::DL : X86::AL,
659 X86::R8RegisterClass);
660 ArgValue = DAG.getCopyFromReg(DAG.getRoot(), VReg, MVT::i8);
661 DAG.setRoot(ArgValue.getValue(1));
Chris Lattner82584892005-12-27 03:02:18 +0000662 if (ObjectVT == MVT::i1)
663 // FIXME: Should insert a assertzext here.
664 ArgValue = DAG.getNode(ISD::TRUNCATE, MVT::i1, ArgValue);
Chris Lattner76ac0682005-11-15 00:40:23 +0000665 }
666 ++NumIntRegs;
667 break;
668 }
669
670 ObjSize = 1;
671 break;
672 case MVT::i16:
673 if (NumIntRegs < 2) {
674 if (!I->use_empty()) {
675 unsigned VReg = AddLiveIn(MF, NumIntRegs ? X86::DX : X86::AX,
676 X86::R16RegisterClass);
677 ArgValue = DAG.getCopyFromReg(DAG.getRoot(), VReg, MVT::i16);
678 DAG.setRoot(ArgValue.getValue(1));
679 }
680 ++NumIntRegs;
681 break;
682 }
683 ObjSize = 2;
684 break;
685 case MVT::i32:
686 if (NumIntRegs < 2) {
687 if (!I->use_empty()) {
688 unsigned VReg = AddLiveIn(MF,NumIntRegs ? X86::EDX : X86::EAX,
689 X86::R32RegisterClass);
690 ArgValue = DAG.getCopyFromReg(DAG.getRoot(), VReg, MVT::i32);
691 DAG.setRoot(ArgValue.getValue(1));
692 }
693 ++NumIntRegs;
694 break;
695 }
696 ObjSize = 4;
697 break;
698 case MVT::i64:
699 if (NumIntRegs == 0) {
700 if (!I->use_empty()) {
701 unsigned BotReg = AddLiveIn(MF, X86::EAX, X86::R32RegisterClass);
702 unsigned TopReg = AddLiveIn(MF, X86::EDX, X86::R32RegisterClass);
703
704 SDOperand Low = DAG.getCopyFromReg(DAG.getRoot(), BotReg, MVT::i32);
705 SDOperand Hi = DAG.getCopyFromReg(Low.getValue(1), TopReg, MVT::i32);
706 DAG.setRoot(Hi.getValue(1));
707
708 ArgValue = DAG.getNode(ISD::BUILD_PAIR, MVT::i64, Low, Hi);
709 }
710 NumIntRegs = 2;
711 break;
712 } else if (NumIntRegs == 1) {
713 if (!I->use_empty()) {
714 unsigned BotReg = AddLiveIn(MF, X86::EDX, X86::R32RegisterClass);
715 SDOperand Low = DAG.getCopyFromReg(DAG.getRoot(), BotReg, MVT::i32);
716 DAG.setRoot(Low.getValue(1));
717
718 // Load the high part from memory.
719 // Create the frame index object for this incoming parameter...
720 int FI = MFI->CreateFixedObject(4, ArgOffset);
721 SDOperand FIN = DAG.getFrameIndex(FI, MVT::i32);
722 SDOperand Hi = DAG.getLoad(MVT::i32, DAG.getEntryNode(), FIN,
723 DAG.getSrcValue(NULL));
724 ArgValue = DAG.getNode(ISD::BUILD_PAIR, MVT::i64, Low, Hi);
725 }
726 ArgOffset += 4;
727 NumIntRegs = 2;
728 break;
729 }
730 ObjSize = ArgIncrement = 8;
731 break;
732 case MVT::f32: ObjSize = 4; break;
733 case MVT::f64: ObjSize = ArgIncrement = 8; break;
734 }
735
736 // Don't codegen dead arguments. FIXME: remove this check when we can nuke
737 // dead loads.
738 if (ObjSize && !I->use_empty()) {
739 // Create the frame index object for this incoming parameter...
740 int FI = MFI->CreateFixedObject(ObjSize, ArgOffset);
741
742 // Create the SelectionDAG nodes corresponding to a load from this
743 // parameter.
744 SDOperand FIN = DAG.getFrameIndex(FI, MVT::i32);
745
746 ArgValue = DAG.getLoad(ObjectVT, DAG.getEntryNode(), FIN,
747 DAG.getSrcValue(NULL));
748 } else if (ArgValue.Val == 0) {
749 if (MVT::isInteger(ObjectVT))
750 ArgValue = DAG.getConstant(0, ObjectVT);
751 else
752 ArgValue = DAG.getConstantFP(0, ObjectVT);
753 }
754 ArgValues.push_back(ArgValue);
755
756 if (ObjSize)
757 ArgOffset += ArgIncrement; // Move on to the next argument.
758 }
759
760 // Make sure the instruction takes 8n+4 bytes to make sure the start of the
761 // arguments and the arguments after the retaddr has been pushed are aligned.
762 if ((ArgOffset & 7) == 0)
763 ArgOffset += 4;
764
765 VarArgsFrameIndex = 0xAAAAAAA; // fastcc functions can't have varargs.
766 ReturnAddrIndex = 0; // No return address slot generated yet.
767 BytesToPopOnReturn = ArgOffset; // Callee pops all stack arguments.
768 BytesCallerReserves = 0;
769
770 // Finally, inform the code generator which regs we return values in.
771 switch (getValueType(F.getReturnType())) {
772 default: assert(0 && "Unknown type!");
773 case MVT::isVoid: break;
774 case MVT::i1:
775 case MVT::i8:
776 case MVT::i16:
777 case MVT::i32:
778 MF.addLiveOut(X86::EAX);
779 break;
780 case MVT::i64:
781 MF.addLiveOut(X86::EAX);
782 MF.addLiveOut(X86::EDX);
783 break;
784 case MVT::f32:
785 case MVT::f64:
786 MF.addLiveOut(X86::ST0);
787 break;
788 }
789 return ArgValues;
790}
791
792std::pair<SDOperand, SDOperand>
793X86TargetLowering::LowerFastCCCallTo(SDOperand Chain, const Type *RetTy,
794 bool isTailCall, SDOperand Callee,
795 ArgListTy &Args, SelectionDAG &DAG) {
796 // Count how many bytes are to be pushed on the stack.
797 unsigned NumBytes = 0;
798
799 // Keep track of the number of integer regs passed so far. This can be either
800 // 0 (neither EAX or EDX used), 1 (EAX is used) or 2 (EAX and EDX are both
801 // used).
802 unsigned NumIntRegs = 0;
803
804 for (unsigned i = 0, e = Args.size(); i != e; ++i)
805 switch (getValueType(Args[i].second)) {
806 default: assert(0 && "Unknown value type!");
807 case MVT::i1:
808 case MVT::i8:
809 case MVT::i16:
810 case MVT::i32:
811 if (NumIntRegs < 2) {
812 ++NumIntRegs;
813 break;
814 }
815 // fall through
816 case MVT::f32:
817 NumBytes += 4;
818 break;
819 case MVT::i64:
820 if (NumIntRegs == 0) {
821 NumIntRegs = 2;
822 break;
823 } else if (NumIntRegs == 1) {
824 NumIntRegs = 2;
825 NumBytes += 4;
826 break;
827 }
828
829 // fall through
830 case MVT::f64:
831 NumBytes += 8;
832 break;
833 }
834
835 // Make sure the instruction takes 8n+4 bytes to make sure the start of the
836 // arguments and the arguments after the retaddr has been pushed are aligned.
837 if ((NumBytes & 7) == 0)
838 NumBytes += 4;
839
Chris Lattner62c34842006-02-13 09:00:43 +0000840 Chain = DAG.getCALLSEQ_START(Chain,DAG.getConstant(NumBytes, getPointerTy()));
Chris Lattner76ac0682005-11-15 00:40:23 +0000841
842 // Arguments go on the stack in reverse order, as specified by the ABI.
843 unsigned ArgOffset = 0;
Chris Lattner27d30a52006-01-24 06:14:44 +0000844 SDOperand StackPtr = DAG.getRegister(X86::ESP, MVT::i32);
Chris Lattner76ac0682005-11-15 00:40:23 +0000845 NumIntRegs = 0;
846 std::vector<SDOperand> Stores;
847 std::vector<SDOperand> RegValuesToPass;
848 for (unsigned i = 0, e = Args.size(); i != e; ++i) {
849 switch (getValueType(Args[i].second)) {
850 default: assert(0 && "Unexpected ValueType for argument!");
851 case MVT::i1:
Chris Lattner82584892005-12-27 03:02:18 +0000852 Args[i].first = DAG.getNode(ISD::ANY_EXTEND, MVT::i8, Args[i].first);
853 // Fall through.
Chris Lattner76ac0682005-11-15 00:40:23 +0000854 case MVT::i8:
855 case MVT::i16:
856 case MVT::i32:
857 if (NumIntRegs < 2) {
858 RegValuesToPass.push_back(Args[i].first);
859 ++NumIntRegs;
860 break;
861 }
862 // Fall through
863 case MVT::f32: {
864 SDOperand PtrOff = DAG.getConstant(ArgOffset, getPointerTy());
865 PtrOff = DAG.getNode(ISD::ADD, MVT::i32, StackPtr, PtrOff);
866 Stores.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
867 Args[i].first, PtrOff,
868 DAG.getSrcValue(NULL)));
869 ArgOffset += 4;
870 break;
871 }
872 case MVT::i64:
873 if (NumIntRegs < 2) { // Can pass part of it in regs?
874 SDOperand Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32,
875 Args[i].first, DAG.getConstant(1, MVT::i32));
876 SDOperand Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32,
877 Args[i].first, DAG.getConstant(0, MVT::i32));
878 RegValuesToPass.push_back(Lo);
879 ++NumIntRegs;
880 if (NumIntRegs < 2) { // Pass both parts in regs?
881 RegValuesToPass.push_back(Hi);
882 ++NumIntRegs;
883 } else {
884 // Pass the high part in memory.
885 SDOperand PtrOff = DAG.getConstant(ArgOffset, getPointerTy());
886 PtrOff = DAG.getNode(ISD::ADD, MVT::i32, StackPtr, PtrOff);
887 Stores.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
888 Hi, PtrOff, DAG.getSrcValue(NULL)));
889 ArgOffset += 4;
890 }
891 break;
892 }
893 // Fall through
894 case MVT::f64:
895 SDOperand PtrOff = DAG.getConstant(ArgOffset, getPointerTy());
896 PtrOff = DAG.getNode(ISD::ADD, MVT::i32, StackPtr, PtrOff);
897 Stores.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
898 Args[i].first, PtrOff,
899 DAG.getSrcValue(NULL)));
900 ArgOffset += 8;
901 break;
902 }
903 }
904 if (!Stores.empty())
905 Chain = DAG.getNode(ISD::TokenFactor, MVT::Other, Stores);
906
907 // Make sure the instruction takes 8n+4 bytes to make sure the start of the
908 // arguments and the arguments after the retaddr has been pushed are aligned.
909 if ((ArgOffset & 7) == 0)
910 ArgOffset += 4;
911
912 std::vector<MVT::ValueType> RetVals;
913 MVT::ValueType RetTyVT = getValueType(RetTy);
914
915 RetVals.push_back(MVT::Other);
916
917 // The result values produced have to be legal. Promote the result.
918 switch (RetTyVT) {
919 case MVT::isVoid: break;
920 default:
921 RetVals.push_back(RetTyVT);
922 break;
923 case MVT::i1:
924 case MVT::i8:
925 case MVT::i16:
926 RetVals.push_back(MVT::i32);
927 break;
928 case MVT::f32:
929 if (X86ScalarSSE)
930 RetVals.push_back(MVT::f32);
931 else
932 RetVals.push_back(MVT::f64);
933 break;
934 case MVT::i64:
935 RetVals.push_back(MVT::i32);
936 RetVals.push_back(MVT::i32);
937 break;
938 }
939
Nate Begeman7e5496d2006-02-17 00:03:04 +0000940 // Build a sequence of copy-to-reg nodes chained together with token chain
941 // and flag operands which copy the outgoing args into registers.
942 SDOperand InFlag;
943 for (unsigned i = 0, e = RegValuesToPass.size(); i != e; ++i) {
944 unsigned CCReg;
945 SDOperand RegToPass = RegValuesToPass[i];
946 switch (RegToPass.getValueType()) {
947 default: assert(0 && "Bad thing to pass in regs");
948 case MVT::i8:
949 CCReg = (i == 0) ? X86::AL : X86::DL;
Evan Cheng172fce72006-01-06 00:43:03 +0000950 break;
Nate Begeman7e5496d2006-02-17 00:03:04 +0000951 case MVT::i16:
952 CCReg = (i == 0) ? X86::AX : X86::DX;
953 break;
954 case MVT::i32:
955 CCReg = (i == 0) ? X86::EAX : X86::EDX;
956 break;
957 }
958
959 Chain = DAG.getCopyToReg(Chain, CCReg, RegToPass, InFlag);
960 InFlag = Chain.getValue(1);
961 }
962
963 std::vector<MVT::ValueType> NodeTys;
964 NodeTys.push_back(MVT::Other); // Returns a chain
965 NodeTys.push_back(MVT::Flag); // Returns a flag for retval copy to use.
966 std::vector<SDOperand> Ops;
967 Ops.push_back(Chain);
968 Ops.push_back(Callee);
969 if (InFlag.Val)
970 Ops.push_back(InFlag);
971
972 // FIXME: Do not generate X86ISD::TAILCALL for now.
973 Chain = DAG.getNode(X86ISD::CALL, NodeTys, Ops);
974 InFlag = Chain.getValue(1);
975
976 NodeTys.clear();
977 NodeTys.push_back(MVT::Other); // Returns a chain
978 NodeTys.push_back(MVT::Flag); // Returns a flag for retval copy to use.
979 Ops.clear();
980 Ops.push_back(Chain);
981 Ops.push_back(DAG.getConstant(ArgOffset, getPointerTy()));
982 Ops.push_back(DAG.getConstant(ArgOffset, getPointerTy()));
983 Ops.push_back(InFlag);
984 Chain = DAG.getNode(ISD::CALLSEQ_END, NodeTys, Ops);
985 InFlag = Chain.getValue(1);
986
987 SDOperand RetVal;
988 if (RetTyVT != MVT::isVoid) {
989 switch (RetTyVT) {
990 default: assert(0 && "Unknown value type to return!");
Evan Cheng172fce72006-01-06 00:43:03 +0000991 case MVT::i1:
992 case MVT::i8:
Nate Begeman7e5496d2006-02-17 00:03:04 +0000993 RetVal = DAG.getCopyFromReg(Chain, X86::AL, MVT::i8, InFlag);
994 Chain = RetVal.getValue(1);
995 if (RetTyVT == MVT::i1)
996 RetVal = DAG.getNode(ISD::TRUNCATE, MVT::i1, RetVal);
997 break;
Evan Cheng172fce72006-01-06 00:43:03 +0000998 case MVT::i16:
Nate Begeman7e5496d2006-02-17 00:03:04 +0000999 RetVal = DAG.getCopyFromReg(Chain, X86::AX, MVT::i16, InFlag);
1000 Chain = RetVal.getValue(1);
Evan Cheng172fce72006-01-06 00:43:03 +00001001 break;
Nate Begeman7e5496d2006-02-17 00:03:04 +00001002 case MVT::i32:
1003 RetVal = DAG.getCopyFromReg(Chain, X86::EAX, MVT::i32, InFlag);
1004 Chain = RetVal.getValue(1);
Evan Cheng172fce72006-01-06 00:43:03 +00001005 break;
Nate Begeman7e5496d2006-02-17 00:03:04 +00001006 case MVT::i64: {
1007 SDOperand Lo = DAG.getCopyFromReg(Chain, X86::EAX, MVT::i32, InFlag);
1008 SDOperand Hi = DAG.getCopyFromReg(Lo.getValue(1), X86::EDX, MVT::i32,
1009 Lo.getValue(2));
1010 RetVal = DAG.getNode(ISD::BUILD_PAIR, MVT::i64, Lo, Hi);
1011 Chain = Hi.getValue(1);
Evan Cheng172fce72006-01-06 00:43:03 +00001012 break;
1013 }
Nate Begeman7e5496d2006-02-17 00:03:04 +00001014 case MVT::f32:
1015 case MVT::f64: {
1016 std::vector<MVT::ValueType> Tys;
1017 Tys.push_back(MVT::f64);
1018 Tys.push_back(MVT::Other);
1019 Tys.push_back(MVT::Flag);
1020 std::vector<SDOperand> Ops;
1021 Ops.push_back(Chain);
1022 Ops.push_back(InFlag);
1023 RetVal = DAG.getNode(X86ISD::FP_GET_RESULT, Tys, Ops);
1024 Chain = RetVal.getValue(1);
1025 InFlag = RetVal.getValue(2);
1026 if (X86ScalarSSE) {
1027 // FIXME: Currently the FST is flagged to the FP_GET_RESULT. This
1028 // shouldn't be necessary except that RFP cannot be live across
1029 // multiple blocks. When stackifier is fixed, they can be uncoupled.
1030 MachineFunction &MF = DAG.getMachineFunction();
1031 int SSFI = MF.getFrameInfo()->CreateStackObject(8, 8);
1032 SDOperand StackSlot = DAG.getFrameIndex(SSFI, getPointerTy());
1033 Tys.clear();
1034 Tys.push_back(MVT::Other);
1035 Ops.clear();
1036 Ops.push_back(Chain);
1037 Ops.push_back(RetVal);
1038 Ops.push_back(StackSlot);
1039 Ops.push_back(DAG.getValueType(RetTyVT));
1040 Ops.push_back(InFlag);
1041 Chain = DAG.getNode(X86ISD::FST, Tys, Ops);
1042 RetVal = DAG.getLoad(RetTyVT, Chain, StackSlot,
1043 DAG.getSrcValue(NULL));
1044 Chain = RetVal.getValue(1);
1045 }
Evan Cheng172fce72006-01-06 00:43:03 +00001046
Nate Begeman7e5496d2006-02-17 00:03:04 +00001047 if (RetTyVT == MVT::f32 && !X86ScalarSSE)
1048 // FIXME: we would really like to remember that this FP_ROUND
1049 // operation is okay to eliminate if we allow excess FP precision.
1050 RetVal = DAG.getNode(ISD::FP_ROUND, MVT::f32, RetVal);
1051 break;
1052 }
1053 }
Chris Lattner76ac0682005-11-15 00:40:23 +00001054 }
Nate Begeman7e5496d2006-02-17 00:03:04 +00001055
1056 return std::make_pair(RetVal, Chain);
Chris Lattner76ac0682005-11-15 00:40:23 +00001057}
1058
1059SDOperand X86TargetLowering::getReturnAddressFrameIndex(SelectionDAG &DAG) {
1060 if (ReturnAddrIndex == 0) {
1061 // Set up a frame object for the return address.
1062 MachineFunction &MF = DAG.getMachineFunction();
1063 ReturnAddrIndex = MF.getFrameInfo()->CreateFixedObject(4, -4);
1064 }
1065
1066 return DAG.getFrameIndex(ReturnAddrIndex, MVT::i32);
1067}
1068
1069
1070
1071std::pair<SDOperand, SDOperand> X86TargetLowering::
1072LowerFrameReturnAddress(bool isFrameAddress, SDOperand Chain, unsigned Depth,
1073 SelectionDAG &DAG) {
1074 SDOperand Result;
1075 if (Depth) // Depths > 0 not supported yet!
1076 Result = DAG.getConstant(0, getPointerTy());
1077 else {
1078 SDOperand RetAddrFI = getReturnAddressFrameIndex(DAG);
1079 if (!isFrameAddress)
1080 // Just load the return address
1081 Result = DAG.getLoad(MVT::i32, DAG.getEntryNode(), RetAddrFI,
1082 DAG.getSrcValue(NULL));
1083 else
1084 Result = DAG.getNode(ISD::SUB, MVT::i32, RetAddrFI,
1085 DAG.getConstant(4, MVT::i32));
1086 }
1087 return std::make_pair(Result, Chain);
1088}
1089
Evan Cheng339edad2006-01-11 00:33:36 +00001090/// getCondBrOpcodeForX86CC - Returns the X86 conditional branch opcode
1091/// which corresponds to the condition code.
1092static unsigned getCondBrOpcodeForX86CC(unsigned X86CC) {
1093 switch (X86CC) {
1094 default: assert(0 && "Unknown X86 conditional code!");
1095 case X86ISD::COND_A: return X86::JA;
1096 case X86ISD::COND_AE: return X86::JAE;
1097 case X86ISD::COND_B: return X86::JB;
1098 case X86ISD::COND_BE: return X86::JBE;
1099 case X86ISD::COND_E: return X86::JE;
1100 case X86ISD::COND_G: return X86::JG;
1101 case X86ISD::COND_GE: return X86::JGE;
1102 case X86ISD::COND_L: return X86::JL;
1103 case X86ISD::COND_LE: return X86::JLE;
1104 case X86ISD::COND_NE: return X86::JNE;
1105 case X86ISD::COND_NO: return X86::JNO;
1106 case X86ISD::COND_NP: return X86::JNP;
1107 case X86ISD::COND_NS: return X86::JNS;
1108 case X86ISD::COND_O: return X86::JO;
1109 case X86ISD::COND_P: return X86::JP;
1110 case X86ISD::COND_S: return X86::JS;
1111 }
1112}
Chris Lattner76ac0682005-11-15 00:40:23 +00001113
Evan Cheng45df7f82006-01-30 23:41:35 +00001114/// translateX86CC - do a one to one translation of a ISD::CondCode to the X86
1115/// specific condition code. It returns a false if it cannot do a direct
1116/// translation. X86CC is the translated CondCode. Flip is set to true if the
1117/// the order of comparison operands should be flipped.
Chris Lattnerc642aa52006-01-31 19:43:35 +00001118static bool translateX86CC(SDOperand CC, bool isFP, unsigned &X86CC,
1119 bool &Flip) {
Evan Cheng172fce72006-01-06 00:43:03 +00001120 ISD::CondCode SetCCOpcode = cast<CondCodeSDNode>(CC)->get();
Evan Cheng45df7f82006-01-30 23:41:35 +00001121 Flip = false;
1122 X86CC = X86ISD::COND_INVALID;
Evan Cheng172fce72006-01-06 00:43:03 +00001123 if (!isFP) {
1124 switch (SetCCOpcode) {
1125 default: break;
1126 case ISD::SETEQ: X86CC = X86ISD::COND_E; break;
1127 case ISD::SETGT: X86CC = X86ISD::COND_G; break;
1128 case ISD::SETGE: X86CC = X86ISD::COND_GE; break;
1129 case ISD::SETLT: X86CC = X86ISD::COND_L; break;
1130 case ISD::SETLE: X86CC = X86ISD::COND_LE; break;
1131 case ISD::SETNE: X86CC = X86ISD::COND_NE; break;
1132 case ISD::SETULT: X86CC = X86ISD::COND_B; break;
1133 case ISD::SETUGT: X86CC = X86ISD::COND_A; break;
1134 case ISD::SETULE: X86CC = X86ISD::COND_BE; break;
1135 case ISD::SETUGE: X86CC = X86ISD::COND_AE; break;
1136 }
1137 } else {
1138 // On a floating point condition, the flags are set as follows:
1139 // ZF PF CF op
1140 // 0 | 0 | 0 | X > Y
1141 // 0 | 0 | 1 | X < Y
1142 // 1 | 0 | 0 | X == Y
1143 // 1 | 1 | 1 | unordered
1144 switch (SetCCOpcode) {
1145 default: break;
1146 case ISD::SETUEQ:
1147 case ISD::SETEQ: X86CC = X86ISD::COND_E; break;
Evan Cheng45df7f82006-01-30 23:41:35 +00001148 case ISD::SETOLE: Flip = true; // Fallthrough
Evan Cheng172fce72006-01-06 00:43:03 +00001149 case ISD::SETOGT:
1150 case ISD::SETGT: X86CC = X86ISD::COND_A; break;
Evan Cheng45df7f82006-01-30 23:41:35 +00001151 case ISD::SETOLT: Flip = true; // Fallthrough
Evan Cheng172fce72006-01-06 00:43:03 +00001152 case ISD::SETOGE:
1153 case ISD::SETGE: X86CC = X86ISD::COND_AE; break;
Evan Cheng45df7f82006-01-30 23:41:35 +00001154 case ISD::SETUGE: Flip = true; // Fallthrough
Evan Cheng172fce72006-01-06 00:43:03 +00001155 case ISD::SETULT:
1156 case ISD::SETLT: X86CC = X86ISD::COND_B; break;
Evan Cheng45df7f82006-01-30 23:41:35 +00001157 case ISD::SETUGT: Flip = true; // Fallthrough
Evan Cheng172fce72006-01-06 00:43:03 +00001158 case ISD::SETULE:
1159 case ISD::SETLE: X86CC = X86ISD::COND_BE; break;
1160 case ISD::SETONE:
1161 case ISD::SETNE: X86CC = X86ISD::COND_NE; break;
1162 case ISD::SETUO: X86CC = X86ISD::COND_P; break;
1163 case ISD::SETO: X86CC = X86ISD::COND_NP; break;
1164 }
1165 }
Evan Cheng45df7f82006-01-30 23:41:35 +00001166
1167 return X86CC != X86ISD::COND_INVALID;
Evan Cheng172fce72006-01-06 00:43:03 +00001168}
1169
Evan Cheng339edad2006-01-11 00:33:36 +00001170/// hasFPCMov - is there a floating point cmov for the specific X86 condition
1171/// code. Current x86 isa includes the following FP cmov instructions:
Evan Cheng73a1ad92006-01-10 20:26:56 +00001172/// fcmovb, fcomvbe, fcomve, fcmovu, fcmovae, fcmova, fcmovne, fcmovnu.
Evan Cheng339edad2006-01-11 00:33:36 +00001173static bool hasFPCMov(unsigned X86CC) {
Evan Cheng73a1ad92006-01-10 20:26:56 +00001174 switch (X86CC) {
1175 default:
1176 return false;
1177 case X86ISD::COND_B:
1178 case X86ISD::COND_BE:
1179 case X86ISD::COND_E:
1180 case X86ISD::COND_P:
1181 case X86ISD::COND_A:
1182 case X86ISD::COND_AE:
1183 case X86ISD::COND_NE:
1184 case X86ISD::COND_NP:
1185 return true;
1186 }
1187}
1188
Evan Cheng339edad2006-01-11 00:33:36 +00001189MachineBasicBlock *
1190X86TargetLowering::InsertAtEndOfBasicBlock(MachineInstr *MI,
1191 MachineBasicBlock *BB) {
Evan Cheng911c68d2006-01-16 21:21:29 +00001192 switch (MI->getOpcode()) {
1193 default: assert(false && "Unexpected instr type to insert");
1194 case X86::CMOV_FR32:
1195 case X86::CMOV_FR64: {
Chris Lattnerc642aa52006-01-31 19:43:35 +00001196 // To "insert" a SELECT_CC instruction, we actually have to insert the
1197 // diamond control-flow pattern. The incoming instruction knows the
1198 // destination vreg to set, the condition code register to branch on, the
1199 // true/false values to select between, and a branch opcode to use.
Evan Cheng911c68d2006-01-16 21:21:29 +00001200 const BasicBlock *LLVM_BB = BB->getBasicBlock();
1201 ilist<MachineBasicBlock>::iterator It = BB;
1202 ++It;
1203
1204 // thisMBB:
1205 // ...
1206 // TrueVal = ...
1207 // cmpTY ccX, r1, r2
1208 // bCC copy1MBB
1209 // fallthrough --> copy0MBB
1210 MachineBasicBlock *thisMBB = BB;
1211 MachineBasicBlock *copy0MBB = new MachineBasicBlock(LLVM_BB);
1212 MachineBasicBlock *sinkMBB = new MachineBasicBlock(LLVM_BB);
1213 unsigned Opc = getCondBrOpcodeForX86CC(MI->getOperand(3).getImmedValue());
1214 BuildMI(BB, Opc, 1).addMBB(sinkMBB);
1215 MachineFunction *F = BB->getParent();
1216 F->getBasicBlockList().insert(It, copy0MBB);
1217 F->getBasicBlockList().insert(It, sinkMBB);
1218 // Update machine-CFG edges
1219 BB->addSuccessor(copy0MBB);
1220 BB->addSuccessor(sinkMBB);
1221
1222 // copy0MBB:
1223 // %FalseValue = ...
1224 // # fallthrough to sinkMBB
1225 BB = copy0MBB;
1226
1227 // Update machine-CFG edges
1228 BB->addSuccessor(sinkMBB);
1229
1230 // sinkMBB:
1231 // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ]
1232 // ...
1233 BB = sinkMBB;
1234 BuildMI(BB, X86::PHI, 4, MI->getOperand(0).getReg())
1235 .addReg(MI->getOperand(1).getReg()).addMBB(copy0MBB)
1236 .addReg(MI->getOperand(2).getReg()).addMBB(thisMBB);
Evan Cheng339edad2006-01-11 00:33:36 +00001237
Evan Cheng911c68d2006-01-16 21:21:29 +00001238 delete MI; // The pseudo instruction is gone now.
1239 return BB;
1240 }
Evan Cheng339edad2006-01-11 00:33:36 +00001241
Evan Cheng911c68d2006-01-16 21:21:29 +00001242 case X86::FP_TO_INT16_IN_MEM:
1243 case X86::FP_TO_INT32_IN_MEM:
1244 case X86::FP_TO_INT64_IN_MEM: {
1245 // Change the floating point control register to use "round towards zero"
1246 // mode when truncating to an integer value.
1247 MachineFunction *F = BB->getParent();
1248 int CWFrameIdx = F->getFrameInfo()->CreateStackObject(2, 2);
1249 addFrameReference(BuildMI(BB, X86::FNSTCW16m, 4), CWFrameIdx);
1250
1251 // Load the old value of the high byte of the control word...
1252 unsigned OldCW =
1253 F->getSSARegMap()->createVirtualRegister(X86::R16RegisterClass);
1254 addFrameReference(BuildMI(BB, X86::MOV16rm, 4, OldCW), CWFrameIdx);
1255
1256 // Set the high part to be round to zero...
1257 addFrameReference(BuildMI(BB, X86::MOV16mi, 5), CWFrameIdx).addImm(0xC7F);
1258
1259 // Reload the modified control word now...
1260 addFrameReference(BuildMI(BB, X86::FLDCW16m, 4), CWFrameIdx);
1261
1262 // Restore the memory image of control word to original value
1263 addFrameReference(BuildMI(BB, X86::MOV16mr, 5), CWFrameIdx).addReg(OldCW);
1264
1265 // Get the X86 opcode to use.
1266 unsigned Opc;
1267 switch (MI->getOpcode()) {
Chris Lattnerccd2a202006-01-28 10:34:47 +00001268 default: assert(0 && "illegal opcode!");
Evan Cheng911c68d2006-01-16 21:21:29 +00001269 case X86::FP_TO_INT16_IN_MEM: Opc = X86::FpIST16m; break;
1270 case X86::FP_TO_INT32_IN_MEM: Opc = X86::FpIST32m; break;
1271 case X86::FP_TO_INT64_IN_MEM: Opc = X86::FpIST64m; break;
1272 }
1273
1274 X86AddressMode AM;
1275 MachineOperand &Op = MI->getOperand(0);
1276 if (Op.isRegister()) {
1277 AM.BaseType = X86AddressMode::RegBase;
1278 AM.Base.Reg = Op.getReg();
1279 } else {
1280 AM.BaseType = X86AddressMode::FrameIndexBase;
1281 AM.Base.FrameIndex = Op.getFrameIndex();
1282 }
1283 Op = MI->getOperand(1);
1284 if (Op.isImmediate())
1285 AM.Scale = Op.getImmedValue();
1286 Op = MI->getOperand(2);
1287 if (Op.isImmediate())
1288 AM.IndexReg = Op.getImmedValue();
1289 Op = MI->getOperand(3);
1290 if (Op.isGlobalAddress()) {
1291 AM.GV = Op.getGlobal();
1292 } else {
1293 AM.Disp = Op.getImmedValue();
1294 }
1295 addFullAddress(BuildMI(BB, Opc, 5), AM).addReg(MI->getOperand(4).getReg());
1296
1297 // Reload the original control word now.
1298 addFrameReference(BuildMI(BB, X86::FLDCW16m, 4), CWFrameIdx);
1299
1300 delete MI; // The pseudo instruction is gone now.
1301 return BB;
1302 }
1303 }
Evan Cheng339edad2006-01-11 00:33:36 +00001304}
1305
1306
1307//===----------------------------------------------------------------------===//
1308// X86 Custom Lowering Hooks
1309//===----------------------------------------------------------------------===//
1310
Chris Lattner76ac0682005-11-15 00:40:23 +00001311/// LowerOperation - Provide custom lowering hooks for some operations.
1312///
1313SDOperand X86TargetLowering::LowerOperation(SDOperand Op, SelectionDAG &DAG) {
1314 switch (Op.getOpcode()) {
1315 default: assert(0 && "Should not custom lower this!");
Evan Cheng9c249c32006-01-09 18:33:28 +00001316 case ISD::SHL_PARTS:
1317 case ISD::SRA_PARTS:
1318 case ISD::SRL_PARTS: {
1319 assert(Op.getNumOperands() == 3 && Op.getValueType() == MVT::i32 &&
1320 "Not an i64 shift!");
1321 bool isSRA = Op.getOpcode() == ISD::SRA_PARTS;
1322 SDOperand ShOpLo = Op.getOperand(0);
1323 SDOperand ShOpHi = Op.getOperand(1);
1324 SDOperand ShAmt = Op.getOperand(2);
1325 SDOperand Tmp1 = isSRA ? DAG.getNode(ISD::SRA, MVT::i32, ShOpHi,
Evan Cheng621674a2006-01-18 09:26:46 +00001326 DAG.getConstant(31, MVT::i8))
Evan Cheng9c249c32006-01-09 18:33:28 +00001327 : DAG.getConstant(0, MVT::i32);
1328
1329 SDOperand Tmp2, Tmp3;
1330 if (Op.getOpcode() == ISD::SHL_PARTS) {
1331 Tmp2 = DAG.getNode(X86ISD::SHLD, MVT::i32, ShOpHi, ShOpLo, ShAmt);
1332 Tmp3 = DAG.getNode(ISD::SHL, MVT::i32, ShOpLo, ShAmt);
1333 } else {
1334 Tmp2 = DAG.getNode(X86ISD::SHRD, MVT::i32, ShOpLo, ShOpHi, ShAmt);
Evan Cheng267ba592006-01-19 01:46:14 +00001335 Tmp3 = DAG.getNode(isSRA ? ISD::SRA : ISD::SRL, MVT::i32, ShOpHi, ShAmt);
Evan Cheng9c249c32006-01-09 18:33:28 +00001336 }
1337
1338 SDOperand InFlag = DAG.getNode(X86ISD::TEST, MVT::Flag,
1339 ShAmt, DAG.getConstant(32, MVT::i8));
1340
1341 SDOperand Hi, Lo;
Evan Cheng77fa9192006-01-09 20:49:21 +00001342 SDOperand CC = DAG.getConstant(X86ISD::COND_NE, MVT::i8);
Evan Cheng9c249c32006-01-09 18:33:28 +00001343
1344 std::vector<MVT::ValueType> Tys;
1345 Tys.push_back(MVT::i32);
1346 Tys.push_back(MVT::Flag);
1347 std::vector<SDOperand> Ops;
1348 if (Op.getOpcode() == ISD::SHL_PARTS) {
1349 Ops.push_back(Tmp2);
1350 Ops.push_back(Tmp3);
1351 Ops.push_back(CC);
1352 Ops.push_back(InFlag);
1353 Hi = DAG.getNode(X86ISD::CMOV, Tys, Ops);
1354 InFlag = Hi.getValue(1);
1355
1356 Ops.clear();
1357 Ops.push_back(Tmp3);
1358 Ops.push_back(Tmp1);
1359 Ops.push_back(CC);
1360 Ops.push_back(InFlag);
1361 Lo = DAG.getNode(X86ISD::CMOV, Tys, Ops);
1362 } else {
1363 Ops.push_back(Tmp2);
1364 Ops.push_back(Tmp3);
1365 Ops.push_back(CC);
Evan Cheng12181af2006-01-09 22:29:54 +00001366 Ops.push_back(InFlag);
Evan Cheng9c249c32006-01-09 18:33:28 +00001367 Lo = DAG.getNode(X86ISD::CMOV, Tys, Ops);
1368 InFlag = Lo.getValue(1);
1369
1370 Ops.clear();
1371 Ops.push_back(Tmp3);
1372 Ops.push_back(Tmp1);
1373 Ops.push_back(CC);
1374 Ops.push_back(InFlag);
1375 Hi = DAG.getNode(X86ISD::CMOV, Tys, Ops);
1376 }
1377
1378 Tys.clear();
1379 Tys.push_back(MVT::i32);
1380 Tys.push_back(MVT::i32);
1381 Ops.clear();
1382 Ops.push_back(Lo);
1383 Ops.push_back(Hi);
1384 return DAG.getNode(ISD::MERGE_VALUES, Tys, Ops);
1385 }
Chris Lattner76ac0682005-11-15 00:40:23 +00001386 case ISD::SINT_TO_FP: {
Evan Cheng08390f62006-01-30 22:13:22 +00001387 assert(Op.getOperand(0).getValueType() <= MVT::i64 &&
Evan Cheng6305e502006-01-12 22:54:21 +00001388 Op.getOperand(0).getValueType() >= MVT::i16 &&
Chris Lattner76ac0682005-11-15 00:40:23 +00001389 "Unknown SINT_TO_FP to lower!");
Evan Cheng6305e502006-01-12 22:54:21 +00001390
1391 SDOperand Result;
1392 MVT::ValueType SrcVT = Op.getOperand(0).getValueType();
1393 unsigned Size = MVT::getSizeInBits(SrcVT)/8;
Chris Lattner76ac0682005-11-15 00:40:23 +00001394 MachineFunction &MF = DAG.getMachineFunction();
Evan Cheng6305e502006-01-12 22:54:21 +00001395 int SSFI = MF.getFrameInfo()->CreateStackObject(Size, Size);
Chris Lattner76ac0682005-11-15 00:40:23 +00001396 SDOperand StackSlot = DAG.getFrameIndex(SSFI, getPointerTy());
Evan Cheng6305e502006-01-12 22:54:21 +00001397 SDOperand Chain = DAG.getNode(ISD::STORE, MVT::Other,
1398 DAG.getEntryNode(), Op.getOperand(0),
1399 StackSlot, DAG.getSrcValue(NULL));
1400
1401 // Build the FILD
1402 std::vector<MVT::ValueType> Tys;
1403 Tys.push_back(MVT::f64);
Evan Cheng5b97fcf2006-01-30 08:02:57 +00001404 Tys.push_back(MVT::Other);
Evan Cheng11613a52006-02-04 02:20:30 +00001405 if (X86ScalarSSE) Tys.push_back(MVT::Flag);
Chris Lattner76ac0682005-11-15 00:40:23 +00001406 std::vector<SDOperand> Ops;
Evan Cheng6305e502006-01-12 22:54:21 +00001407 Ops.push_back(Chain);
Chris Lattner76ac0682005-11-15 00:40:23 +00001408 Ops.push_back(StackSlot);
Evan Cheng6305e502006-01-12 22:54:21 +00001409 Ops.push_back(DAG.getValueType(SrcVT));
Evan Cheng11613a52006-02-04 02:20:30 +00001410 Result = DAG.getNode(X86ScalarSSE ? X86ISD::FILD_FLAG :X86ISD::FILD,
1411 Tys, Ops);
Evan Cheng5b97fcf2006-01-30 08:02:57 +00001412
1413 if (X86ScalarSSE) {
Evan Cheng5b97fcf2006-01-30 08:02:57 +00001414 Chain = Result.getValue(1);
1415 SDOperand InFlag = Result.getValue(2);
1416
Evan Cheng11613a52006-02-04 02:20:30 +00001417 // FIXME: Currently the FST is flagged to the FILD_FLAG. This
Evan Cheng5b97fcf2006-01-30 08:02:57 +00001418 // shouldn't be necessary except that RFP cannot be live across
1419 // multiple blocks. When stackifier is fixed, they can be uncoupled.
1420 MachineFunction &MF = DAG.getMachineFunction();
1421 int SSFI = MF.getFrameInfo()->CreateStackObject(8, 8);
1422 SDOperand StackSlot = DAG.getFrameIndex(SSFI, getPointerTy());
1423 std::vector<MVT::ValueType> Tys;
1424 Tys.push_back(MVT::Other);
1425 std::vector<SDOperand> Ops;
1426 Ops.push_back(Chain);
1427 Ops.push_back(Result);
1428 Ops.push_back(StackSlot);
Evan Cheng08390f62006-01-30 22:13:22 +00001429 Ops.push_back(DAG.getValueType(Op.getValueType()));
Evan Cheng5b97fcf2006-01-30 08:02:57 +00001430 Ops.push_back(InFlag);
1431 Chain = DAG.getNode(X86ISD::FST, Tys, Ops);
1432 Result = DAG.getLoad(Op.getValueType(), Chain, StackSlot,
1433 DAG.getSrcValue(NULL));
1434 }
1435
Evan Cheng6305e502006-01-12 22:54:21 +00001436 return Result;
Chris Lattner76ac0682005-11-15 00:40:23 +00001437 }
1438 case ISD::FP_TO_SINT: {
1439 assert(Op.getValueType() <= MVT::i64 && Op.getValueType() >= MVT::i16 &&
Chris Lattner76ac0682005-11-15 00:40:23 +00001440 "Unknown FP_TO_SINT to lower!");
1441 // We lower FP->sint64 into FISTP64, followed by a load, all to a temporary
1442 // stack slot.
1443 MachineFunction &MF = DAG.getMachineFunction();
1444 unsigned MemSize = MVT::getSizeInBits(Op.getValueType())/8;
1445 int SSFI = MF.getFrameInfo()->CreateStackObject(MemSize, MemSize);
1446 SDOperand StackSlot = DAG.getFrameIndex(SSFI, getPointerTy());
1447
1448 unsigned Opc;
1449 switch (Op.getValueType()) {
1450 default: assert(0 && "Invalid FP_TO_SINT to lower!");
1451 case MVT::i16: Opc = X86ISD::FP_TO_INT16_IN_MEM; break;
1452 case MVT::i32: Opc = X86ISD::FP_TO_INT32_IN_MEM; break;
1453 case MVT::i64: Opc = X86ISD::FP_TO_INT64_IN_MEM; break;
1454 }
1455
Evan Cheng5b97fcf2006-01-30 08:02:57 +00001456 SDOperand Chain = DAG.getEntryNode();
1457 SDOperand Value = Op.getOperand(0);
1458 if (X86ScalarSSE) {
1459 assert(Op.getValueType() == MVT::i64 && "Invalid FP_TO_SINT to lower!");
1460 Chain = DAG.getNode(ISD::STORE, MVT::Other, Chain, Value, StackSlot,
1461 DAG.getSrcValue(0));
1462 std::vector<MVT::ValueType> Tys;
1463 Tys.push_back(MVT::f64);
1464 Tys.push_back(MVT::Other);
1465 std::vector<SDOperand> Ops;
1466 Ops.push_back(Chain);
1467 Ops.push_back(StackSlot);
Evan Cheng08390f62006-01-30 22:13:22 +00001468 Ops.push_back(DAG.getValueType(Op.getOperand(0).getValueType()));
Evan Cheng5b97fcf2006-01-30 08:02:57 +00001469 Value = DAG.getNode(X86ISD::FLD, Tys, Ops);
1470 Chain = Value.getValue(1);
1471 SSFI = MF.getFrameInfo()->CreateStackObject(MemSize, MemSize);
1472 StackSlot = DAG.getFrameIndex(SSFI, getPointerTy());
1473 }
1474
Chris Lattner76ac0682005-11-15 00:40:23 +00001475 // Build the FP_TO_INT*_IN_MEM
1476 std::vector<SDOperand> Ops;
Evan Cheng5b97fcf2006-01-30 08:02:57 +00001477 Ops.push_back(Chain);
1478 Ops.push_back(Value);
Chris Lattner76ac0682005-11-15 00:40:23 +00001479 Ops.push_back(StackSlot);
1480 SDOperand FIST = DAG.getNode(Opc, MVT::Other, Ops);
1481
1482 // Load the result.
1483 return DAG.getLoad(Op.getValueType(), FIST, StackSlot,
1484 DAG.getSrcValue(NULL));
1485 }
Andrew Lenharth0bf68ae2005-11-20 21:41:10 +00001486 case ISD::READCYCLECOUNTER: {
Chris Lattner6df9e112005-11-20 22:01:40 +00001487 std::vector<MVT::ValueType> Tys;
1488 Tys.push_back(MVT::Other);
1489 Tys.push_back(MVT::Flag);
1490 std::vector<SDOperand> Ops;
1491 Ops.push_back(Op.getOperand(0));
1492 SDOperand rd = DAG.getNode(X86ISD::RDTSC_DAG, Tys, Ops);
Chris Lattner6c1ca882005-11-20 22:57:19 +00001493 Ops.clear();
1494 Ops.push_back(DAG.getCopyFromReg(rd, X86::EAX, MVT::i32, rd.getValue(1)));
1495 Ops.push_back(DAG.getCopyFromReg(Ops[0].getValue(1), X86::EDX,
1496 MVT::i32, Ops[0].getValue(2)));
1497 Ops.push_back(Ops[1].getValue(1));
1498 Tys[0] = Tys[1] = MVT::i32;
1499 Tys.push_back(MVT::Other);
1500 return DAG.getNode(ISD::MERGE_VALUES, Tys, Ops);
Andrew Lenharth0bf68ae2005-11-20 21:41:10 +00001501 }
Evan Cheng2dd217b2006-01-31 03:14:29 +00001502 case ISD::FABS: {
1503 MVT::ValueType VT = Op.getValueType();
Evan Cheng72d5c252006-01-31 22:28:30 +00001504 const Type *OpNTy = MVT::getTypeForValueType(VT);
1505 std::vector<Constant*> CV;
1506 if (VT == MVT::f64) {
1507 CV.push_back(ConstantFP::get(OpNTy, BitsToDouble(~(1ULL << 63))));
1508 CV.push_back(ConstantFP::get(OpNTy, 0.0));
1509 } else {
1510 CV.push_back(ConstantFP::get(OpNTy, BitsToFloat(~(1U << 31))));
1511 CV.push_back(ConstantFP::get(OpNTy, 0.0));
1512 CV.push_back(ConstantFP::get(OpNTy, 0.0));
1513 CV.push_back(ConstantFP::get(OpNTy, 0.0));
1514 }
1515 Constant *CS = ConstantStruct::get(CV);
1516 SDOperand CPIdx = DAG.getConstantPool(CS, getPointerTy(), 4);
1517 SDOperand Mask
1518 = DAG.getNode(X86ISD::LOAD_PACK,
1519 VT, DAG.getEntryNode(), CPIdx, DAG.getSrcValue(NULL));
Evan Cheng2dd217b2006-01-31 03:14:29 +00001520 return DAG.getNode(X86ISD::FAND, VT, Op.getOperand(0), Mask);
1521 }
Evan Cheng72d5c252006-01-31 22:28:30 +00001522 case ISD::FNEG: {
1523 MVT::ValueType VT = Op.getValueType();
1524 const Type *OpNTy = MVT::getTypeForValueType(VT);
1525 std::vector<Constant*> CV;
1526 if (VT == MVT::f64) {
1527 CV.push_back(ConstantFP::get(OpNTy, BitsToDouble(1ULL << 63)));
1528 CV.push_back(ConstantFP::get(OpNTy, 0.0));
1529 } else {
1530 CV.push_back(ConstantFP::get(OpNTy, BitsToFloat(1U << 31)));
1531 CV.push_back(ConstantFP::get(OpNTy, 0.0));
1532 CV.push_back(ConstantFP::get(OpNTy, 0.0));
1533 CV.push_back(ConstantFP::get(OpNTy, 0.0));
1534 }
1535 Constant *CS = ConstantStruct::get(CV);
1536 SDOperand CPIdx = DAG.getConstantPool(CS, getPointerTy(), 4);
1537 SDOperand Mask
1538 = DAG.getNode(X86ISD::LOAD_PACK,
1539 VT, DAG.getEntryNode(), CPIdx, DAG.getSrcValue(NULL));
1540 return DAG.getNode(X86ISD::FXOR, VT, Op.getOperand(0), Mask);
1541 }
Evan Chengc1583db2005-12-21 20:21:51 +00001542 case ISD::SETCC: {
1543 assert(Op.getValueType() == MVT::i8 && "SetCC type must be 8-bit integer");
Evan Cheng45df7f82006-01-30 23:41:35 +00001544 SDOperand Cond;
1545 SDOperand CC = Op.getOperand(2);
Evan Cheng172fce72006-01-06 00:43:03 +00001546 ISD::CondCode SetCCOpcode = cast<CondCodeSDNode>(CC)->get();
1547 bool isFP = MVT::isFloatingPoint(Op.getOperand(1).getValueType());
Evan Cheng45df7f82006-01-30 23:41:35 +00001548 bool Flip;
1549 unsigned X86CC;
1550 if (translateX86CC(CC, isFP, X86CC, Flip)) {
1551 if (Flip)
1552 Cond = DAG.getNode(X86ISD::CMP, MVT::Flag,
1553 Op.getOperand(1), Op.getOperand(0));
1554 else
1555 Cond = DAG.getNode(X86ISD::CMP, MVT::Flag,
1556 Op.getOperand(0), Op.getOperand(1));
Evan Cheng172fce72006-01-06 00:43:03 +00001557 return DAG.getNode(X86ISD::SETCC, MVT::i8,
1558 DAG.getConstant(X86CC, MVT::i8), Cond);
1559 } else {
1560 assert(isFP && "Illegal integer SetCC!");
1561
Evan Cheng45df7f82006-01-30 23:41:35 +00001562 Cond = DAG.getNode(X86ISD::CMP, MVT::Flag,
1563 Op.getOperand(0), Op.getOperand(1));
Evan Cheng172fce72006-01-06 00:43:03 +00001564 std::vector<MVT::ValueType> Tys;
1565 std::vector<SDOperand> Ops;
1566 switch (SetCCOpcode) {
1567 default: assert(false && "Illegal floating point SetCC!");
1568 case ISD::SETOEQ: { // !PF & ZF
1569 Tys.push_back(MVT::i8);
1570 Tys.push_back(MVT::Flag);
1571 Ops.push_back(DAG.getConstant(X86ISD::COND_NP, MVT::i8));
1572 Ops.push_back(Cond);
1573 SDOperand Tmp1 = DAG.getNode(X86ISD::SETCC, Tys, Ops);
1574 SDOperand Tmp2 = DAG.getNode(X86ISD::SETCC, MVT::i8,
1575 DAG.getConstant(X86ISD::COND_E, MVT::i8),
1576 Tmp1.getValue(1));
1577 return DAG.getNode(ISD::AND, MVT::i8, Tmp1, Tmp2);
1578 }
Evan Cheng172fce72006-01-06 00:43:03 +00001579 case ISD::SETUNE: { // PF | !ZF
1580 Tys.push_back(MVT::i8);
1581 Tys.push_back(MVT::Flag);
1582 Ops.push_back(DAG.getConstant(X86ISD::COND_P, MVT::i8));
1583 Ops.push_back(Cond);
1584 SDOperand Tmp1 = DAG.getNode(X86ISD::SETCC, Tys, Ops);
1585 SDOperand Tmp2 = DAG.getNode(X86ISD::SETCC, MVT::i8,
1586 DAG.getConstant(X86ISD::COND_NE, MVT::i8),
1587 Tmp1.getValue(1));
1588 return DAG.getNode(ISD::OR, MVT::i8, Tmp1, Tmp2);
1589 }
1590 }
1591 }
Evan Chengc1583db2005-12-21 20:21:51 +00001592 }
Evan Cheng225a4d02005-12-17 01:21:05 +00001593 case ISD::SELECT: {
Evan Cheng73a1ad92006-01-10 20:26:56 +00001594 MVT::ValueType VT = Op.getValueType();
1595 bool isFP = MVT::isFloatingPoint(VT);
Evan Chengcde9e302006-01-27 08:10:46 +00001596 bool isFPStack = isFP && !X86ScalarSSE;
1597 bool isFPSSE = isFP && X86ScalarSSE;
Evan Chengfb22e862006-01-13 01:03:02 +00001598 bool addTest = false;
Evan Cheng73a1ad92006-01-10 20:26:56 +00001599 SDOperand Op0 = Op.getOperand(0);
1600 SDOperand Cond, CC;
Evan Cheng45df7f82006-01-30 23:41:35 +00001601 if (Op0.getOpcode() == ISD::SETCC)
1602 Op0 = LowerOperation(Op0, DAG);
1603
Evan Cheng73a1ad92006-01-10 20:26:56 +00001604 if (Op0.getOpcode() == X86ISD::SETCC) {
Evan Chengfb22e862006-01-13 01:03:02 +00001605 // If condition flag is set by a X86ISD::CMP, then make a copy of it
1606 // (since flag operand cannot be shared). If the X86ISD::SETCC does not
1607 // have another use it will be eliminated.
1608 // If the X86ISD::SETCC has more than one use, then it's probably better
1609 // to use a test instead of duplicating the X86ISD::CMP (for register
1610 // pressure reason).
Evan Cheng944d1e92006-01-26 02:13:10 +00001611 if (Op0.getOperand(1).getOpcode() == X86ISD::CMP) {
1612 if (!Op0.hasOneUse()) {
1613 std::vector<MVT::ValueType> Tys;
1614 for (unsigned i = 0; i < Op0.Val->getNumValues(); ++i)
1615 Tys.push_back(Op0.Val->getValueType(i));
1616 std::vector<SDOperand> Ops;
1617 for (unsigned i = 0; i < Op0.getNumOperands(); ++i)
1618 Ops.push_back(Op0.getOperand(i));
1619 Op0 = DAG.getNode(X86ISD::SETCC, Tys, Ops);
1620 }
1621
Evan Chengfb22e862006-01-13 01:03:02 +00001622 CC = Op0.getOperand(0);
1623 Cond = Op0.getOperand(1);
Evan Chengaff08002006-01-25 09:05:09 +00001624 // Make a copy as flag result cannot be used by more than one.
1625 Cond = DAG.getNode(X86ISD::CMP, MVT::Flag,
1626 Cond.getOperand(0), Cond.getOperand(1));
Evan Chengfb22e862006-01-13 01:03:02 +00001627 addTest =
Evan Chengd7faa4b2006-01-13 01:17:24 +00001628 isFPStack && !hasFPCMov(cast<ConstantSDNode>(CC)->getSignExtended());
Evan Chengfb22e862006-01-13 01:03:02 +00001629 } else
1630 addTest = true;
Evan Chengfb22e862006-01-13 01:03:02 +00001631 } else
1632 addTest = true;
Evan Cheng73a1ad92006-01-10 20:26:56 +00001633
Evan Cheng731423f2006-01-13 01:06:49 +00001634 if (addTest) {
Evan Chengdba84bb2006-01-13 19:51:46 +00001635 CC = DAG.getConstant(X86ISD::COND_NE, MVT::i8);
Evan Cheng73a1ad92006-01-10 20:26:56 +00001636 Cond = DAG.getNode(X86ISD::TEST, MVT::Flag, Op0, Op0);
Evan Cheng225a4d02005-12-17 01:21:05 +00001637 }
Evan Cheng9c249c32006-01-09 18:33:28 +00001638
1639 std::vector<MVT::ValueType> Tys;
1640 Tys.push_back(Op.getValueType());
1641 Tys.push_back(MVT::Flag);
1642 std::vector<SDOperand> Ops;
Evan Chengdba84bb2006-01-13 19:51:46 +00001643 // X86ISD::CMOV means set the result (which is operand 1) to the RHS if
1644 // condition is true.
Evan Cheng9c249c32006-01-09 18:33:28 +00001645 Ops.push_back(Op.getOperand(2));
Evan Chengdba84bb2006-01-13 19:51:46 +00001646 Ops.push_back(Op.getOperand(1));
Evan Cheng9c249c32006-01-09 18:33:28 +00001647 Ops.push_back(CC);
1648 Ops.push_back(Cond);
1649 return DAG.getNode(X86ISD::CMOV, Tys, Ops);
Evan Cheng225a4d02005-12-17 01:21:05 +00001650 }
Evan Cheng6fc31042005-12-19 23:12:38 +00001651 case ISD::BRCOND: {
Evan Chengfb22e862006-01-13 01:03:02 +00001652 bool addTest = false;
Evan Cheng6fc31042005-12-19 23:12:38 +00001653 SDOperand Cond = Op.getOperand(1);
1654 SDOperand Dest = Op.getOperand(2);
1655 SDOperand CC;
Evan Cheng45df7f82006-01-30 23:41:35 +00001656 if (Cond.getOpcode() == ISD::SETCC)
1657 Cond = LowerOperation(Cond, DAG);
1658
Evan Chengc1583db2005-12-21 20:21:51 +00001659 if (Cond.getOpcode() == X86ISD::SETCC) {
Evan Chengfb22e862006-01-13 01:03:02 +00001660 // If condition flag is set by a X86ISD::CMP, then make a copy of it
1661 // (since flag operand cannot be shared). If the X86ISD::SETCC does not
1662 // have another use it will be eliminated.
1663 // If the X86ISD::SETCC has more than one use, then it's probably better
1664 // to use a test instead of duplicating the X86ISD::CMP (for register
1665 // pressure reason).
Evan Cheng944d1e92006-01-26 02:13:10 +00001666 if (Cond.getOperand(1).getOpcode() == X86ISD::CMP) {
1667 if (!Cond.hasOneUse()) {
1668 std::vector<MVT::ValueType> Tys;
1669 for (unsigned i = 0; i < Cond.Val->getNumValues(); ++i)
1670 Tys.push_back(Cond.Val->getValueType(i));
1671 std::vector<SDOperand> Ops;
1672 for (unsigned i = 0; i < Cond.getNumOperands(); ++i)
1673 Ops.push_back(Cond.getOperand(i));
1674 Cond = DAG.getNode(X86ISD::SETCC, Tys, Ops);
1675 }
1676
Evan Chengfb22e862006-01-13 01:03:02 +00001677 CC = Cond.getOperand(0);
Evan Chengaff08002006-01-25 09:05:09 +00001678 Cond = Cond.getOperand(1);
1679 // Make a copy as flag result cannot be used by more than one.
Evan Chengfb22e862006-01-13 01:03:02 +00001680 Cond = DAG.getNode(X86ISD::CMP, MVT::Flag,
Evan Chengaff08002006-01-25 09:05:09 +00001681 Cond.getOperand(0), Cond.getOperand(1));
Evan Chengfb22e862006-01-13 01:03:02 +00001682 } else
1683 addTest = true;
Evan Chengfb22e862006-01-13 01:03:02 +00001684 } else
1685 addTest = true;
1686
1687 if (addTest) {
Evan Cheng172fce72006-01-06 00:43:03 +00001688 CC = DAG.getConstant(X86ISD::COND_NE, MVT::i8);
Evan Cheng6fc31042005-12-19 23:12:38 +00001689 Cond = DAG.getNode(X86ISD::TEST, MVT::Flag, Cond, Cond);
1690 }
1691 return DAG.getNode(X86ISD::BRCOND, Op.getValueType(),
1692 Op.getOperand(0), Op.getOperand(2), CC, Cond);
1693 }
Evan Chengae986f12006-01-11 22:15:48 +00001694 case ISD::MEMSET: {
1695 SDOperand InFlag;
1696 SDOperand Chain = Op.getOperand(0);
1697 unsigned Align =
1698 (unsigned)cast<ConstantSDNode>(Op.getOperand(4))->getValue();
1699 if (Align == 0) Align = 1;
1700
Evan Cheng03c1e6f2006-02-16 00:21:07 +00001701 ConstantSDNode *I = dyn_cast<ConstantSDNode>(Op.getOperand(3));
1702 // If not DWORD aligned, call memset if size is less than the threshold.
1703 // It knows how to align to the right boundary first.
1704 if ((Align & 3) != 0 &&
1705 !(I && I->getValue() >= Subtarget->getMinRepStrSizeThreshold())) {
1706 MVT::ValueType IntPtr = getPointerTy();
1707 const Type *IntPtrTy = getTargetData().getIntPtrType();
1708 std::vector<std::pair<SDOperand, const Type*> > Args;
1709 Args.push_back(std::make_pair(Op.getOperand(1), IntPtrTy));
1710 // Extend the ubyte argument to be an int value for the call.
1711 SDOperand Val = DAG.getNode(ISD::ZERO_EXTEND, MVT::i32, Op.getOperand(2));
1712 Args.push_back(std::make_pair(Val, IntPtrTy));
1713 Args.push_back(std::make_pair(Op.getOperand(3), IntPtrTy));
1714 std::pair<SDOperand,SDOperand> CallResult =
1715 LowerCallTo(Chain, Type::VoidTy, false, CallingConv::C, false,
1716 DAG.getExternalSymbol("memset", IntPtr), Args, DAG);
1717 return CallResult.second;
1718 }
1719
Evan Chengae986f12006-01-11 22:15:48 +00001720 MVT::ValueType AVT;
1721 SDOperand Count;
1722 if (ConstantSDNode *ValC = dyn_cast<ConstantSDNode>(Op.getOperand(2))) {
1723 unsigned ValReg;
1724 unsigned Val = ValC->getValue() & 255;
1725
1726 // If the value is a constant, then we can potentially use larger sets.
1727 switch (Align & 3) {
1728 case 2: // WORD aligned
1729 AVT = MVT::i16;
Evan Cheng03c1e6f2006-02-16 00:21:07 +00001730 if (I)
Evan Chengae986f12006-01-11 22:15:48 +00001731 Count = DAG.getConstant(I->getValue() / 2, MVT::i32);
1732 else
1733 Count = DAG.getNode(ISD::SRL, MVT::i32, Op.getOperand(3),
1734 DAG.getConstant(1, MVT::i8));
1735 Val = (Val << 8) | Val;
1736 ValReg = X86::AX;
1737 break;
1738 case 0: // DWORD aligned
1739 AVT = MVT::i32;
Evan Cheng03c1e6f2006-02-16 00:21:07 +00001740 if (I)
Evan Chengae986f12006-01-11 22:15:48 +00001741 Count = DAG.getConstant(I->getValue() / 4, MVT::i32);
1742 else
1743 Count = DAG.getNode(ISD::SRL, MVT::i32, Op.getOperand(3),
1744 DAG.getConstant(2, MVT::i8));
1745 Val = (Val << 8) | Val;
1746 Val = (Val << 16) | Val;
1747 ValReg = X86::EAX;
1748 break;
1749 default: // Byte aligned
1750 AVT = MVT::i8;
1751 Count = Op.getOperand(3);
1752 ValReg = X86::AL;
1753 break;
1754 }
1755
1756 Chain = DAG.getCopyToReg(Chain, ValReg, DAG.getConstant(Val, AVT),
1757 InFlag);
1758 InFlag = Chain.getValue(1);
1759 } else {
Evan Cheng03c1e6f2006-02-16 00:21:07 +00001760 AVT = MVT::i8;
Evan Chengae986f12006-01-11 22:15:48 +00001761 Count = Op.getOperand(3);
1762 Chain = DAG.getCopyToReg(Chain, X86::AL, Op.getOperand(2), InFlag);
1763 InFlag = Chain.getValue(1);
1764 }
1765
1766 Chain = DAG.getCopyToReg(Chain, X86::ECX, Count, InFlag);
1767 InFlag = Chain.getValue(1);
1768 Chain = DAG.getCopyToReg(Chain, X86::EDI, Op.getOperand(1), InFlag);
1769 InFlag = Chain.getValue(1);
1770
1771 return DAG.getNode(X86ISD::REP_STOS, MVT::Other, Chain,
1772 DAG.getValueType(AVT), InFlag);
1773 }
1774 case ISD::MEMCPY: {
1775 SDOperand Chain = Op.getOperand(0);
1776 unsigned Align =
1777 (unsigned)cast<ConstantSDNode>(Op.getOperand(4))->getValue();
1778 if (Align == 0) Align = 1;
1779
Evan Cheng03c1e6f2006-02-16 00:21:07 +00001780 ConstantSDNode *I = dyn_cast<ConstantSDNode>(Op.getOperand(3));
1781 // If not DWORD aligned, call memcpy if size is less than the threshold.
1782 // It knows how to align to the right boundary first.
1783 if ((Align & 3) != 0 &&
1784 !(I && I->getValue() >= Subtarget->getMinRepStrSizeThreshold())) {
1785 MVT::ValueType IntPtr = getPointerTy();
1786 const Type *IntPtrTy = getTargetData().getIntPtrType();
1787 std::vector<std::pair<SDOperand, const Type*> > Args;
1788 Args.push_back(std::make_pair(Op.getOperand(1), IntPtrTy));
1789 Args.push_back(std::make_pair(Op.getOperand(2), IntPtrTy));
1790 Args.push_back(std::make_pair(Op.getOperand(3), IntPtrTy));
1791 std::pair<SDOperand,SDOperand> CallResult =
1792 LowerCallTo(Chain, Type::VoidTy, false, CallingConv::C, false,
1793 DAG.getExternalSymbol("memcpy", IntPtr), Args, DAG);
1794 return CallResult.second;
1795 }
1796
Evan Chengae986f12006-01-11 22:15:48 +00001797 MVT::ValueType AVT;
1798 SDOperand Count;
1799 switch (Align & 3) {
1800 case 2: // WORD aligned
1801 AVT = MVT::i16;
Evan Cheng03c1e6f2006-02-16 00:21:07 +00001802 if (I)
Evan Chengae986f12006-01-11 22:15:48 +00001803 Count = DAG.getConstant(I->getValue() / 2, MVT::i32);
1804 else
Evan Cheng03c1e6f2006-02-16 00:21:07 +00001805 Count = DAG.getConstant(I->getValue() / 2, MVT::i32);
Evan Chengae986f12006-01-11 22:15:48 +00001806 break;
1807 case 0: // DWORD aligned
1808 AVT = MVT::i32;
Evan Cheng03c1e6f2006-02-16 00:21:07 +00001809 if (I)
Evan Chengae986f12006-01-11 22:15:48 +00001810 Count = DAG.getConstant(I->getValue() / 4, MVT::i32);
1811 else
1812 Count = DAG.getNode(ISD::SRL, MVT::i32, Op.getOperand(3),
1813 DAG.getConstant(2, MVT::i8));
1814 break;
1815 default: // Byte aligned
1816 AVT = MVT::i8;
1817 Count = Op.getOperand(3);
1818 break;
1819 }
1820
1821 SDOperand InFlag;
1822 Chain = DAG.getCopyToReg(Chain, X86::ECX, Count, InFlag);
1823 InFlag = Chain.getValue(1);
1824 Chain = DAG.getCopyToReg(Chain, X86::EDI, Op.getOperand(1), InFlag);
1825 InFlag = Chain.getValue(1);
1826 Chain = DAG.getCopyToReg(Chain, X86::ESI, Op.getOperand(2), InFlag);
1827 InFlag = Chain.getValue(1);
1828
1829 return DAG.getNode(X86ISD::REP_MOVS, MVT::Other, Chain,
1830 DAG.getValueType(AVT), InFlag);
1831 }
Evan Cheng5588de92006-02-18 00:15:05 +00001832 case ISD::ConstantPool: {
1833 ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op);
Evan Chenge0ed6ec2006-02-23 20:41:18 +00001834 SDOperand Result = DAG.getNode(X86ISD::Wrapper, getPointerTy(),
1835 DAG.getTargetConstantPool(CP->get(), getPointerTy(),
1836 CP->getAlignment()));
Evan Cheng1f342c22006-02-23 02:43:52 +00001837 if (getTargetMachine().getSubtarget<X86Subtarget>().isTargetDarwin()) {
Evan Cheng5588de92006-02-18 00:15:05 +00001838 // With PIC, the address is actually $g + Offset.
Evan Cheng73136df2006-02-22 20:19:42 +00001839 if (getTargetMachine().getRelocationModel() == Reloc::PIC)
Evan Cheng5588de92006-02-18 00:15:05 +00001840 Result = DAG.getNode(ISD::ADD, getPointerTy(),
1841 DAG.getNode(X86ISD::GlobalBaseReg, getPointerTy()), Result);
1842 }
1843
1844 return Result;
1845 }
Evan Cheng5c59d492005-12-23 07:31:11 +00001846 case ISD::GlobalAddress: {
Evan Chenge0ed6ec2006-02-23 20:41:18 +00001847 GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
1848 SDOperand Result = DAG.getNode(X86ISD::Wrapper, getPointerTy(),
1849 DAG.getTargetGlobalAddress(GV, getPointerTy()));
Evan Chenga74ce622005-12-21 02:39:21 +00001850 if (getTargetMachine().
Evan Cheng5588de92006-02-18 00:15:05 +00001851 getSubtarget<X86Subtarget>().isTargetDarwin()) {
Evan Cheng5588de92006-02-18 00:15:05 +00001852 // With PIC, the address is actually $g + Offset.
Evan Cheng73136df2006-02-22 20:19:42 +00001853 if (getTargetMachine().getRelocationModel() == Reloc::PIC)
Evan Cheng1f342c22006-02-23 02:43:52 +00001854 Result = DAG.getNode(ISD::ADD, getPointerTy(),
1855 DAG.getNode(X86ISD::GlobalBaseReg, getPointerTy()), Result);
Evan Cheng5588de92006-02-18 00:15:05 +00001856
1857 // For Darwin, external and weak symbols are indirect, so we want to load
1858 // the value at address GV, not the value of GV itself. This means that
1859 // the GlobalAddress must be in the base or index register of the address,
1860 // not the GV offset field.
Evan Cheng73136df2006-02-22 20:19:42 +00001861 if (getTargetMachine().getRelocationModel() != Reloc::Static &&
1862 (GV->hasWeakLinkage() || GV->hasLinkOnceLinkage() ||
1863 (GV->isExternal() && !GV->hasNotBeenReadFromBytecode())))
Evan Cheng5a766802006-02-07 08:38:37 +00001864 Result = DAG.getLoad(MVT::i32, DAG.getEntryNode(),
Evan Cheng1f342c22006-02-23 02:43:52 +00001865 Result, DAG.getSrcValue(NULL));
Evan Cheng5a766802006-02-07 08:38:37 +00001866 }
Evan Cheng5588de92006-02-18 00:15:05 +00001867
Evan Chengb94db9e2006-01-12 07:56:47 +00001868 return Result;
Chris Lattner76ac0682005-11-15 00:40:23 +00001869 }
Evan Chenge0ed6ec2006-02-23 20:41:18 +00001870 case ISD::ExternalSymbol: {
1871 const char *Sym = cast<ExternalSymbolSDNode>(Op)->getSymbol();
1872 SDOperand Result = DAG.getNode(X86ISD::Wrapper, getPointerTy(),
1873 DAG.getTargetExternalSymbol(Sym, getPointerTy()));
1874 if (getTargetMachine().
1875 getSubtarget<X86Subtarget>().isTargetDarwin()) {
1876 // With PIC, the address is actually $g + Offset.
1877 if (getTargetMachine().getRelocationModel() == Reloc::PIC)
1878 Result = DAG.getNode(ISD::ADD, getPointerTy(),
1879 DAG.getNode(X86ISD::GlobalBaseReg, getPointerTy()), Result);
1880 }
1881
1882 return Result;
1883 }
Nate Begemane74795c2006-01-25 18:21:52 +00001884 case ISD::VASTART: {
1885 // vastart just stores the address of the VarArgsFrameIndex slot into the
1886 // memory location argument.
1887 // FIXME: Replace MVT::i32 with PointerTy
1888 SDOperand FR = DAG.getFrameIndex(VarArgsFrameIndex, MVT::i32);
1889 return DAG.getNode(ISD::STORE, MVT::Other, Op.getOperand(0), FR,
1890 Op.getOperand(1), Op.getOperand(2));
1891 }
Nate Begeman8c47c3a2006-01-27 21:09:22 +00001892 case ISD::RET: {
1893 SDOperand Copy;
1894
1895 switch(Op.getNumOperands()) {
1896 default:
1897 assert(0 && "Do not know how to return this many arguments!");
1898 abort();
1899 case 1:
1900 return DAG.getNode(X86ISD::RET_FLAG, MVT::Other, Op.getOperand(0),
1901 DAG.getConstant(getBytesToPopOnReturn(), MVT::i16));
1902 case 2: {
1903 MVT::ValueType ArgVT = Op.getOperand(1).getValueType();
1904 if (MVT::isInteger(ArgVT))
1905 Copy = DAG.getCopyToReg(Op.getOperand(0), X86::EAX, Op.getOperand(1),
1906 SDOperand());
1907 else if (!X86ScalarSSE) {
1908 std::vector<MVT::ValueType> Tys;
1909 Tys.push_back(MVT::Other);
1910 Tys.push_back(MVT::Flag);
1911 std::vector<SDOperand> Ops;
1912 Ops.push_back(Op.getOperand(0));
1913 Ops.push_back(Op.getOperand(1));
1914 Copy = DAG.getNode(X86ISD::FP_SET_RESULT, Tys, Ops);
1915 } else {
Evan Chenge1ce4d72006-02-01 00:20:21 +00001916 SDOperand MemLoc;
1917 SDOperand Chain = Op.getOperand(0);
Evan Cheng5659ca82006-01-31 23:19:54 +00001918 SDOperand Value = Op.getOperand(1);
1919
Evan Chenga24617f2006-02-01 01:19:32 +00001920 if (Value.getOpcode() == ISD::LOAD &&
1921 (Chain == Value.getValue(1) || Chain == Value.getOperand(0))) {
Evan Cheng5659ca82006-01-31 23:19:54 +00001922 Chain = Value.getOperand(0);
1923 MemLoc = Value.getOperand(1);
1924 } else {
1925 // Spill the value to memory and reload it into top of stack.
1926 unsigned Size = MVT::getSizeInBits(ArgVT)/8;
1927 MachineFunction &MF = DAG.getMachineFunction();
1928 int SSFI = MF.getFrameInfo()->CreateStackObject(Size, Size);
1929 MemLoc = DAG.getFrameIndex(SSFI, getPointerTy());
1930 Chain = DAG.getNode(ISD::STORE, MVT::Other, Op.getOperand(0),
1931 Value, MemLoc, DAG.getSrcValue(0));
1932 }
Nate Begeman8c47c3a2006-01-27 21:09:22 +00001933 std::vector<MVT::ValueType> Tys;
1934 Tys.push_back(MVT::f64);
1935 Tys.push_back(MVT::Other);
1936 std::vector<SDOperand> Ops;
1937 Ops.push_back(Chain);
Evan Cheng5659ca82006-01-31 23:19:54 +00001938 Ops.push_back(MemLoc);
Nate Begeman8c47c3a2006-01-27 21:09:22 +00001939 Ops.push_back(DAG.getValueType(ArgVT));
1940 Copy = DAG.getNode(X86ISD::FLD, Tys, Ops);
1941 Tys.clear();
1942 Tys.push_back(MVT::Other);
1943 Tys.push_back(MVT::Flag);
1944 Ops.clear();
1945 Ops.push_back(Copy.getValue(1));
1946 Ops.push_back(Copy);
1947 Copy = DAG.getNode(X86ISD::FP_SET_RESULT, Tys, Ops);
1948 }
1949 break;
1950 }
1951 case 3:
1952 Copy = DAG.getCopyToReg(Op.getOperand(0), X86::EDX, Op.getOperand(2),
1953 SDOperand());
1954 Copy = DAG.getCopyToReg(Copy, X86::EAX,Op.getOperand(1),Copy.getValue(1));
1955 break;
1956 }
1957 return DAG.getNode(X86ISD::RET_FLAG, MVT::Other,
1958 Copy, DAG.getConstant(getBytesToPopOnReturn(), MVT::i16),
1959 Copy.getValue(1));
1960 }
Evan Cheng5c59d492005-12-23 07:31:11 +00001961 }
Chris Lattner76ac0682005-11-15 00:40:23 +00001962}
Evan Cheng6af02632005-12-20 06:22:03 +00001963
1964const char *X86TargetLowering::getTargetNodeName(unsigned Opcode) const {
1965 switch (Opcode) {
1966 default: return NULL;
Evan Cheng9c249c32006-01-09 18:33:28 +00001967 case X86ISD::SHLD: return "X86ISD::SHLD";
1968 case X86ISD::SHRD: return "X86ISD::SHRD";
Evan Cheng2dd217b2006-01-31 03:14:29 +00001969 case X86ISD::FAND: return "X86ISD::FAND";
Evan Cheng72d5c252006-01-31 22:28:30 +00001970 case X86ISD::FXOR: return "X86ISD::FXOR";
Evan Cheng6305e502006-01-12 22:54:21 +00001971 case X86ISD::FILD: return "X86ISD::FILD";
Evan Cheng11613a52006-02-04 02:20:30 +00001972 case X86ISD::FILD_FLAG: return "X86ISD::FILD_FLAG";
Evan Cheng6af02632005-12-20 06:22:03 +00001973 case X86ISD::FP_TO_INT16_IN_MEM: return "X86ISD::FP_TO_INT16_IN_MEM";
1974 case X86ISD::FP_TO_INT32_IN_MEM: return "X86ISD::FP_TO_INT32_IN_MEM";
1975 case X86ISD::FP_TO_INT64_IN_MEM: return "X86ISD::FP_TO_INT64_IN_MEM";
Evan Chenga74ce622005-12-21 02:39:21 +00001976 case X86ISD::FLD: return "X86ISD::FLD";
Evan Cheng45e190982006-01-05 00:27:02 +00001977 case X86ISD::FST: return "X86ISD::FST";
1978 case X86ISD::FP_GET_RESULT: return "X86ISD::FP_GET_RESULT";
Evan Chenga74ce622005-12-21 02:39:21 +00001979 case X86ISD::FP_SET_RESULT: return "X86ISD::FP_SET_RESULT";
Evan Cheng6af02632005-12-20 06:22:03 +00001980 case X86ISD::CALL: return "X86ISD::CALL";
1981 case X86ISD::TAILCALL: return "X86ISD::TAILCALL";
1982 case X86ISD::RDTSC_DAG: return "X86ISD::RDTSC_DAG";
1983 case X86ISD::CMP: return "X86ISD::CMP";
1984 case X86ISD::TEST: return "X86ISD::TEST";
Evan Chengc1583db2005-12-21 20:21:51 +00001985 case X86ISD::SETCC: return "X86ISD::SETCC";
Evan Cheng6af02632005-12-20 06:22:03 +00001986 case X86ISD::CMOV: return "X86ISD::CMOV";
1987 case X86ISD::BRCOND: return "X86ISD::BRCOND";
Evan Chenga74ce622005-12-21 02:39:21 +00001988 case X86ISD::RET_FLAG: return "X86ISD::RET_FLAG";
Evan Chengae986f12006-01-11 22:15:48 +00001989 case X86ISD::REP_STOS: return "X86ISD::RET_STOS";
1990 case X86ISD::REP_MOVS: return "X86ISD::RET_MOVS";
Evan Cheng72d5c252006-01-31 22:28:30 +00001991 case X86ISD::LOAD_PACK: return "X86ISD::LOAD_PACK";
Evan Cheng5588de92006-02-18 00:15:05 +00001992 case X86ISD::GlobalBaseReg: return "X86ISD::GlobalBaseReg";
Evan Chenge0ed6ec2006-02-23 20:41:18 +00001993 case X86ISD::Wrapper: return "X86ISD::Wrapper";
Evan Cheng6af02632005-12-20 06:22:03 +00001994 }
1995}
Evan Cheng9cdc16c2005-12-21 23:05:39 +00001996
Nate Begeman8a77efe2006-02-16 21:11:51 +00001997void X86TargetLowering::computeMaskedBitsForTargetNode(const SDOperand Op,
1998 uint64_t Mask,
1999 uint64_t &KnownZero,
2000 uint64_t &KnownOne,
2001 unsigned Depth) const {
Evan Cheng9cdc16c2005-12-21 23:05:39 +00002002
2003 unsigned Opc = Op.getOpcode();
Nate Begeman8a77efe2006-02-16 21:11:51 +00002004 KnownZero = KnownOne = 0; // Don't know anything.
Evan Cheng9cdc16c2005-12-21 23:05:39 +00002005
2006 switch (Opc) {
2007 default:
2008 assert(Opc >= ISD::BUILTIN_OP_END && "Expected a target specific node");
2009 break;
Nate Begeman8a77efe2006-02-16 21:11:51 +00002010 case X86ISD::SETCC:
2011 KnownZero |= (MVT::getIntVTBitMask(Op.getValueType()) ^ 1ULL);
2012 break;
Evan Cheng9cdc16c2005-12-21 23:05:39 +00002013 }
Evan Cheng9cdc16c2005-12-21 23:05:39 +00002014}
Chris Lattnerc642aa52006-01-31 19:43:35 +00002015
2016std::vector<unsigned> X86TargetLowering::
Chris Lattner7ad77df2006-02-22 00:56:39 +00002017getRegClassForInlineAsmConstraint(const std::string &Constraint,
2018 MVT::ValueType VT) const {
Chris Lattnerc642aa52006-01-31 19:43:35 +00002019 if (Constraint.size() == 1) {
2020 // FIXME: not handling fp-stack yet!
2021 // FIXME: not handling MMX registers yet ('y' constraint).
2022 switch (Constraint[0]) { // GCC X86 Constraint Letters
2023 default: break; // Unknown constriant letter
2024 case 'r': // GENERAL_REGS
2025 case 'R': // LEGACY_REGS
2026 return make_vector<unsigned>(X86::EAX, X86::EBX, X86::ECX, X86::EDX,
2027 X86::ESI, X86::EDI, X86::EBP, X86::ESP, 0);
2028 case 'l': // INDEX_REGS
2029 return make_vector<unsigned>(X86::EAX, X86::EBX, X86::ECX, X86::EDX,
2030 X86::ESI, X86::EDI, X86::EBP, 0);
2031 case 'q': // Q_REGS (GENERAL_REGS in 64-bit mode)
2032 case 'Q': // Q_REGS
2033 return make_vector<unsigned>(X86::EAX, X86::EBX, X86::ECX, X86::EDX, 0);
2034 case 'x': // SSE_REGS if SSE1 allowed
2035 if (Subtarget->hasSSE1())
2036 return make_vector<unsigned>(X86::XMM0, X86::XMM1, X86::XMM2, X86::XMM3,
2037 X86::XMM4, X86::XMM5, X86::XMM6, X86::XMM7,
2038 0);
2039 return std::vector<unsigned>();
2040 case 'Y': // SSE_REGS if SSE2 allowed
2041 if (Subtarget->hasSSE2())
2042 return make_vector<unsigned>(X86::XMM0, X86::XMM1, X86::XMM2, X86::XMM3,
2043 X86::XMM4, X86::XMM5, X86::XMM6, X86::XMM7,
2044 0);
2045 return std::vector<unsigned>();
2046 }
2047 }
2048
Chris Lattner7ad77df2006-02-22 00:56:39 +00002049 return std::vector<unsigned>();
Chris Lattnerc642aa52006-01-31 19:43:35 +00002050}