blob: 866d12fa594d956a40e3755e4212efddb4014d4f [file] [log] [blame]
Dan Gohman1adf1b02008-08-19 21:45:35 +00001//===-- X86FastISel.cpp - X86 FastISel implementation ---------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the X86-specific support for the FastISel class. Much
11// of the target-specific code is generated by tablegen in the file
12// X86GenFastISel.inc, which is #included here.
13//
14//===----------------------------------------------------------------------===//
15
16#include "X86.h"
Evan Cheng8b19e562008-09-03 06:44:39 +000017#include "X86InstrBuilder.h"
Dan Gohman1adf1b02008-08-19 21:45:35 +000018#include "X86ISelLowering.h"
Evan Cheng88e30412008-09-03 01:04:47 +000019#include "X86RegisterInfo.h"
20#include "X86Subtarget.h"
Dan Gohman22bb3112008-08-22 00:20:26 +000021#include "X86TargetMachine.h"
Evan Chengf3d4efe2008-09-07 09:09:33 +000022#include "llvm/CallingConv.h"
Dan Gohman6e3f05f2008-09-04 23:26:51 +000023#include "llvm/DerivedTypes.h"
Evan Chengf3d4efe2008-09-07 09:09:33 +000024#include "llvm/Instructions.h"
Evan Chengc3f44b02008-09-03 00:03:49 +000025#include "llvm/CodeGen/FastISel.h"
Owen Anderson95267a12008-09-05 00:06:23 +000026#include "llvm/CodeGen/MachineConstantPool.h"
Evan Chengf3d4efe2008-09-07 09:09:33 +000027#include "llvm/CodeGen/MachineFrameInfo.h"
Owen Anderson667d8f72008-08-29 17:45:56 +000028#include "llvm/CodeGen/MachineRegisterInfo.h"
Evan Chengf3d4efe2008-09-07 09:09:33 +000029#include "llvm/Support/CallSite.h"
Dan Gohman35893082008-09-18 23:23:44 +000030#include "llvm/Support/GetElementPtrTypeIterator.h"
Evan Chengc3f44b02008-09-03 00:03:49 +000031
32using namespace llvm;
33
34class X86FastISel : public FastISel {
35 /// Subtarget - Keep a pointer to the X86Subtarget around so that we can
36 /// make the right decision when generating code for different targets.
37 const X86Subtarget *Subtarget;
Evan Chengf3d4efe2008-09-07 09:09:33 +000038
39 /// StackPtr - Register used as the stack pointer.
40 ///
41 unsigned StackPtr;
42
Dan Gohman2cc3aa42008-09-25 15:24:26 +000043 /// GlobalBaseReg - keeps track of the virtual register mapped onto global
44 /// base register.
45 unsigned GlobalBaseReg;
46
Evan Chengf3d4efe2008-09-07 09:09:33 +000047 /// X86ScalarSSEf32, X86ScalarSSEf64 - Select between SSE or x87
48 /// floating point ops.
49 /// When SSE is available, use it for f32 operations.
50 /// When SSE2 is available, use it for f64 operations.
51 bool X86ScalarSSEf64;
52 bool X86ScalarSSEf32;
53
Evan Cheng8b19e562008-09-03 06:44:39 +000054public:
Dan Gohman3df24e62008-09-03 23:12:08 +000055 explicit X86FastISel(MachineFunction &mf,
Dan Gohmand57dd5f2008-09-23 21:53:34 +000056 MachineModuleInfo *mmi,
Dan Gohman3df24e62008-09-03 23:12:08 +000057 DenseMap<const Value *, unsigned> &vm,
Dan Gohman0586d912008-09-10 20:11:02 +000058 DenseMap<const BasicBlock *, MachineBasicBlock *> &bm,
59 DenseMap<const AllocaInst *, int> &am)
Dan Gohmand57dd5f2008-09-23 21:53:34 +000060 : FastISel(mf, mmi, vm, bm, am) {
Evan Cheng88e30412008-09-03 01:04:47 +000061 Subtarget = &TM.getSubtarget<X86Subtarget>();
Evan Chengf3d4efe2008-09-07 09:09:33 +000062 StackPtr = Subtarget->is64Bit() ? X86::RSP : X86::ESP;
Dan Gohman2cc3aa42008-09-25 15:24:26 +000063 GlobalBaseReg = 0;
Evan Chengf3d4efe2008-09-07 09:09:33 +000064 X86ScalarSSEf64 = Subtarget->hasSSE2();
65 X86ScalarSSEf32 = Subtarget->hasSSE1();
Evan Cheng88e30412008-09-03 01:04:47 +000066 }
Evan Chengc3f44b02008-09-03 00:03:49 +000067
Dan Gohman3df24e62008-09-03 23:12:08 +000068 virtual bool TargetSelectInstruction(Instruction *I);
Evan Chengc3f44b02008-09-03 00:03:49 +000069
Dan Gohman1adf1b02008-08-19 21:45:35 +000070#include "X86GenFastISel.inc"
Evan Cheng8b19e562008-09-03 06:44:39 +000071
72private:
Dan Gohman0586d912008-09-10 20:11:02 +000073 bool X86FastEmitLoad(MVT VT, const X86AddressMode &AM, unsigned &RR);
Evan Cheng0de588f2008-09-05 21:00:03 +000074
Evan Chengf3d4efe2008-09-07 09:09:33 +000075 bool X86FastEmitStore(MVT VT, unsigned Val,
Dan Gohman0586d912008-09-10 20:11:02 +000076 const X86AddressMode &AM);
Evan Cheng24e3a902008-09-08 06:35:17 +000077
78 bool X86FastEmitExtend(ISD::NodeType Opc, MVT DstVT, unsigned Src, MVT SrcVT,
79 unsigned &ResultReg);
Evan Cheng0de588f2008-09-05 21:00:03 +000080
Dan Gohman2ff7fd12008-09-19 22:16:54 +000081 bool X86SelectAddress(Value *V, X86AddressMode &AM, bool isCall);
Dan Gohman0586d912008-09-10 20:11:02 +000082
Dan Gohman3df24e62008-09-03 23:12:08 +000083 bool X86SelectLoad(Instruction *I);
Owen Andersona3971df2008-09-04 07:08:58 +000084
85 bool X86SelectStore(Instruction *I);
Dan Gohman6e3f05f2008-09-04 23:26:51 +000086
87 bool X86SelectCmp(Instruction *I);
Dan Gohmand89ae992008-09-05 01:06:14 +000088
89 bool X86SelectZExt(Instruction *I);
90
91 bool X86SelectBranch(Instruction *I);
Dan Gohmanc39f4db2008-09-05 18:30:08 +000092
93 bool X86SelectShift(Instruction *I);
94
95 bool X86SelectSelect(Instruction *I);
Evan Cheng0de588f2008-09-05 21:00:03 +000096
Evan Cheng10a8d9c2008-09-07 08:47:42 +000097 bool X86SelectTrunc(Instruction *I);
98
Dan Gohman78efce62008-09-10 21:02:08 +000099 bool X86SelectFPExt(Instruction *I);
100 bool X86SelectFPTrunc(Instruction *I);
101
Evan Chengf3d4efe2008-09-07 09:09:33 +0000102 bool X86SelectCall(Instruction *I);
103
104 CCAssignFn *CCAssignFnForCall(unsigned CC, bool isTailCall = false);
105
Dan Gohman2cc3aa42008-09-25 15:24:26 +0000106 unsigned getGlobalBaseReg();
107
108 const X86InstrInfo *getInstrInfo() const {
Dan Gohman97135e12008-09-26 19:15:30 +0000109 return getTargetMachine()->getInstrInfo();
110 }
111 const X86TargetMachine *getTargetMachine() const {
112 return static_cast<const X86TargetMachine *>(&TM);
Dan Gohman2cc3aa42008-09-25 15:24:26 +0000113 }
114
Dan Gohman0586d912008-09-10 20:11:02 +0000115 unsigned TargetMaterializeConstant(Constant *C);
116
117 unsigned TargetMaterializeAlloca(AllocaInst *C);
Evan Chengf3d4efe2008-09-07 09:09:33 +0000118
119 /// isScalarFPTypeInSSEReg - Return true if the specified scalar FP type is
120 /// computed in an SSE register, not on the X87 floating point stack.
121 bool isScalarFPTypeInSSEReg(MVT VT) const {
122 return (VT == MVT::f64 && X86ScalarSSEf64) || // f64 is when SSE2
123 (VT == MVT::f32 && X86ScalarSSEf32); // f32 is when SSE1
124 }
125
Dan Gohman9b66d732008-09-30 00:48:39 +0000126 bool isTypeLegal(const Type *Ty, const TargetLowering &TLI, MVT &VT,
127 bool AllowI1 = false);
Evan Chengc3f44b02008-09-03 00:03:49 +0000128};
Dan Gohman99b21822008-08-28 23:21:34 +0000129
Dan Gohman9b66d732008-09-30 00:48:39 +0000130bool X86FastISel::isTypeLegal(const Type *Ty, const TargetLowering &TLI,
131 MVT &VT, bool AllowI1) {
Evan Chengf3d4efe2008-09-07 09:09:33 +0000132 VT = MVT::getMVT(Ty, /*HandleUnknown=*/true);
133 if (VT == MVT::Other || !VT.isSimple())
134 // Unhandled type. Halt "fast" selection and bail.
135 return false;
136 if (VT == MVT::iPTR)
137 // Use pointer type.
138 VT = TLI.getPointerTy();
Dan Gohman9b66d732008-09-30 00:48:39 +0000139 // For now, require SSE/SSE2 for performing floating-point operations,
140 // since x87 requires additional work.
141 if (VT == MVT::f64 && !X86ScalarSSEf64)
142 return false;
143 if (VT == MVT::f32 && !X86ScalarSSEf32)
144 return false;
145 // Similarly, no f80 support yet.
146 if (VT == MVT::f80)
147 return false;
Evan Chengf3d4efe2008-09-07 09:09:33 +0000148 // We only handle legal types. For example, on x86-32 the instruction
149 // selector contains all of the 64-bit instructions from x86-64,
150 // under the assumption that i64 won't be used if the target doesn't
151 // support it.
Evan Chengdebdea02008-09-08 17:15:42 +0000152 return (AllowI1 && VT == MVT::i1) || TLI.isTypeLegal(VT);
Evan Chengf3d4efe2008-09-07 09:09:33 +0000153}
154
Dan Gohman2cc3aa42008-09-25 15:24:26 +0000155/// getGlobalBaseReg - Return the the global base register. Output
156/// instructions required to initialize the global base register, if necessary.
157///
158unsigned X86FastISel::getGlobalBaseReg() {
159 assert(!Subtarget->is64Bit() && "X86-64 PIC uses RIP relative addressing");
160 if (!GlobalBaseReg)
161 GlobalBaseReg = getInstrInfo()->initializeGlobalBaseReg(MBB->getParent());
162 return GlobalBaseReg;
163}
164
Evan Chengf3d4efe2008-09-07 09:09:33 +0000165#include "X86GenCallingConv.inc"
166
167/// CCAssignFnForCall - Selects the correct CCAssignFn for a given calling
168/// convention.
169CCAssignFn *X86FastISel::CCAssignFnForCall(unsigned CC, bool isTaillCall) {
170 if (Subtarget->is64Bit()) {
171 if (Subtarget->isTargetWin64())
172 return CC_X86_Win64_C;
173 else if (CC == CallingConv::Fast && isTaillCall)
174 return CC_X86_64_TailCall;
175 else
176 return CC_X86_64_C;
177 }
178
179 if (CC == CallingConv::X86_FastCall)
180 return CC_X86_32_FastCall;
Evan Chengf3d4efe2008-09-07 09:09:33 +0000181 else if (CC == CallingConv::Fast)
182 return CC_X86_32_FastCC;
183 else
184 return CC_X86_32_C;
185}
186
Evan Cheng0de588f2008-09-05 21:00:03 +0000187/// X86FastEmitLoad - Emit a machine instruction to load a value of type VT.
Evan Chengf3d4efe2008-09-07 09:09:33 +0000188/// The address is either pre-computed, i.e. Ptr, or a GlobalAddress, i.e. GV.
Evan Cheng0de588f2008-09-05 21:00:03 +0000189/// Return true and the result register by reference if it is possible.
Dan Gohman0586d912008-09-10 20:11:02 +0000190bool X86FastISel::X86FastEmitLoad(MVT VT, const X86AddressMode &AM,
Evan Cheng0de588f2008-09-05 21:00:03 +0000191 unsigned &ResultReg) {
192 // Get opcode and regclass of the output for the given load instruction.
193 unsigned Opc = 0;
194 const TargetRegisterClass *RC = NULL;
195 switch (VT.getSimpleVT()) {
196 default: return false;
197 case MVT::i8:
198 Opc = X86::MOV8rm;
199 RC = X86::GR8RegisterClass;
200 break;
201 case MVT::i16:
202 Opc = X86::MOV16rm;
203 RC = X86::GR16RegisterClass;
204 break;
205 case MVT::i32:
206 Opc = X86::MOV32rm;
207 RC = X86::GR32RegisterClass;
208 break;
209 case MVT::i64:
210 // Must be in x86-64 mode.
211 Opc = X86::MOV64rm;
212 RC = X86::GR64RegisterClass;
213 break;
214 case MVT::f32:
215 if (Subtarget->hasSSE1()) {
216 Opc = X86::MOVSSrm;
217 RC = X86::FR32RegisterClass;
218 } else {
219 Opc = X86::LD_Fp32m;
220 RC = X86::RFP32RegisterClass;
221 }
222 break;
223 case MVT::f64:
224 if (Subtarget->hasSSE2()) {
225 Opc = X86::MOVSDrm;
226 RC = X86::FR64RegisterClass;
227 } else {
228 Opc = X86::LD_Fp64m;
229 RC = X86::RFP64RegisterClass;
230 }
231 break;
232 case MVT::f80:
Dan Gohman5af29c22008-09-26 01:39:32 +0000233 // No f80 support yet.
234 return false;
Evan Cheng0de588f2008-09-05 21:00:03 +0000235 }
236
237 ResultReg = createResultReg(RC);
Evan Cheng0de588f2008-09-05 21:00:03 +0000238 addFullAddress(BuildMI(MBB, TII.get(Opc), ResultReg), AM);
239 return true;
240}
241
Evan Chengf3d4efe2008-09-07 09:09:33 +0000242/// X86FastEmitStore - Emit a machine instruction to store a value Val of
243/// type VT. The address is either pre-computed, consisted of a base ptr, Ptr
244/// and a displacement offset, or a GlobalAddress,
Evan Cheng0de588f2008-09-05 21:00:03 +0000245/// i.e. V. Return true if it is possible.
246bool
Evan Chengf3d4efe2008-09-07 09:09:33 +0000247X86FastISel::X86FastEmitStore(MVT VT, unsigned Val,
Dan Gohman0586d912008-09-10 20:11:02 +0000248 const X86AddressMode &AM) {
Dan Gohman863890e2008-09-08 16:31:35 +0000249 // Get opcode and regclass of the output for the given store instruction.
Evan Cheng0de588f2008-09-05 21:00:03 +0000250 unsigned Opc = 0;
251 const TargetRegisterClass *RC = NULL;
252 switch (VT.getSimpleVT()) {
253 default: return false;
254 case MVT::i8:
255 Opc = X86::MOV8mr;
256 RC = X86::GR8RegisterClass;
257 break;
258 case MVT::i16:
259 Opc = X86::MOV16mr;
260 RC = X86::GR16RegisterClass;
261 break;
262 case MVT::i32:
263 Opc = X86::MOV32mr;
264 RC = X86::GR32RegisterClass;
265 break;
266 case MVT::i64:
267 // Must be in x86-64 mode.
268 Opc = X86::MOV64mr;
269 RC = X86::GR64RegisterClass;
270 break;
271 case MVT::f32:
272 if (Subtarget->hasSSE1()) {
273 Opc = X86::MOVSSmr;
274 RC = X86::FR32RegisterClass;
275 } else {
276 Opc = X86::ST_Fp32m;
277 RC = X86::RFP32RegisterClass;
278 }
279 break;
280 case MVT::f64:
281 if (Subtarget->hasSSE2()) {
282 Opc = X86::MOVSDmr;
283 RC = X86::FR64RegisterClass;
284 } else {
285 Opc = X86::ST_Fp64m;
286 RC = X86::RFP64RegisterClass;
287 }
288 break;
289 case MVT::f80:
Dan Gohman5af29c22008-09-26 01:39:32 +0000290 // No f80 support yet.
291 return false;
Evan Cheng0de588f2008-09-05 21:00:03 +0000292 }
293
Evan Chengf3d4efe2008-09-07 09:09:33 +0000294 addFullAddress(BuildMI(MBB, TII.get(Opc)), AM).addReg(Val);
Evan Cheng0de588f2008-09-05 21:00:03 +0000295 return true;
296}
297
Evan Cheng24e3a902008-09-08 06:35:17 +0000298/// X86FastEmitExtend - Emit a machine instruction to extend a value Src of
299/// type SrcVT to type DstVT using the specified extension opcode Opc (e.g.
300/// ISD::SIGN_EXTEND).
301bool X86FastISel::X86FastEmitExtend(ISD::NodeType Opc, MVT DstVT,
302 unsigned Src, MVT SrcVT,
303 unsigned &ResultReg) {
Owen Andersonac34a002008-09-11 19:44:55 +0000304 unsigned RR = FastEmit_r(SrcVT.getSimpleVT(), DstVT.getSimpleVT(), Opc, Src);
305
306 if (RR != 0) {
307 ResultReg = RR;
308 return true;
309 } else
310 return false;
Evan Cheng24e3a902008-09-08 06:35:17 +0000311}
312
Dan Gohman0586d912008-09-10 20:11:02 +0000313/// X86SelectAddress - Attempt to fill in an address from the given value.
314///
Dan Gohman2ff7fd12008-09-19 22:16:54 +0000315bool X86FastISel::X86SelectAddress(Value *V, X86AddressMode &AM, bool isCall) {
Dan Gohman35893082008-09-18 23:23:44 +0000316 User *U;
317 unsigned Opcode = Instruction::UserOp1;
318 if (Instruction *I = dyn_cast<Instruction>(V)) {
319 Opcode = I->getOpcode();
320 U = I;
321 } else if (ConstantExpr *C = dyn_cast<ConstantExpr>(V)) {
322 Opcode = C->getOpcode();
323 U = C;
324 }
Dan Gohman0586d912008-09-10 20:11:02 +0000325
Dan Gohman35893082008-09-18 23:23:44 +0000326 switch (Opcode) {
327 default: break;
328 case Instruction::BitCast:
329 // Look past bitcasts.
Dan Gohman2ff7fd12008-09-19 22:16:54 +0000330 return X86SelectAddress(U->getOperand(0), AM, isCall);
Dan Gohman35893082008-09-18 23:23:44 +0000331
332 case Instruction::IntToPtr:
333 // Look past no-op inttoptrs.
334 if (TLI.getValueType(U->getOperand(0)->getType()) == TLI.getPointerTy())
Dan Gohman2ff7fd12008-09-19 22:16:54 +0000335 return X86SelectAddress(U->getOperand(0), AM, isCall);
Dan Gohman35893082008-09-18 23:23:44 +0000336
337 case Instruction::PtrToInt:
338 // Look past no-op ptrtoints.
339 if (TLI.getValueType(U->getType()) == TLI.getPointerTy())
Dan Gohman2ff7fd12008-09-19 22:16:54 +0000340 return X86SelectAddress(U->getOperand(0), AM, isCall);
Dan Gohman35893082008-09-18 23:23:44 +0000341
342 case Instruction::Alloca: {
Dan Gohman2ff7fd12008-09-19 22:16:54 +0000343 if (isCall) break;
Dan Gohman35893082008-09-18 23:23:44 +0000344 // Do static allocas.
345 const AllocaInst *A = cast<AllocaInst>(V);
Dan Gohman0586d912008-09-10 20:11:02 +0000346 DenseMap<const AllocaInst*, int>::iterator SI = StaticAllocaMap.find(A);
Dan Gohman97135e12008-09-26 19:15:30 +0000347 if (SI != StaticAllocaMap.end()) {
348 AM.BaseType = X86AddressMode::FrameIndexBase;
349 AM.Base.FrameIndex = SI->second;
350 return true;
351 }
352 break;
Dan Gohman35893082008-09-18 23:23:44 +0000353 }
354
355 case Instruction::Add: {
Dan Gohman2ff7fd12008-09-19 22:16:54 +0000356 if (isCall) break;
Dan Gohman35893082008-09-18 23:23:44 +0000357 // Adds of constants are common and easy enough.
358 if (ConstantInt *CI = dyn_cast<ConstantInt>(U->getOperand(1))) {
Dan Gohman09aae462008-09-26 20:04:15 +0000359 uint64_t Disp = (int32_t)AM.Disp + (uint64_t)CI->getSExtValue();
360 // They have to fit in the 32-bit signed displacement field though.
361 if (isInt32(Disp)) {
362 AM.Disp = (uint32_t)Disp;
363 return X86SelectAddress(U->getOperand(0), AM, isCall);
364 }
Dan Gohman0586d912008-09-10 20:11:02 +0000365 }
Dan Gohman35893082008-09-18 23:23:44 +0000366 break;
367 }
368
369 case Instruction::GetElementPtr: {
Dan Gohman2ff7fd12008-09-19 22:16:54 +0000370 if (isCall) break;
Dan Gohman35893082008-09-18 23:23:44 +0000371 // Pattern-match simple GEPs.
Dan Gohman09aae462008-09-26 20:04:15 +0000372 uint64_t Disp = (int32_t)AM.Disp;
Dan Gohman35893082008-09-18 23:23:44 +0000373 unsigned IndexReg = AM.IndexReg;
374 unsigned Scale = AM.Scale;
375 gep_type_iterator GTI = gep_type_begin(U);
376 // Look at all but the last index. Constants can be folded,
377 // and one dynamic index can be handled, if the scale is supported.
378 for (User::op_iterator i = U->op_begin() + 1, e = U->op_end();
379 i != e; ++i, ++GTI) {
380 Value *Op = *i;
381 if (const StructType *STy = dyn_cast<StructType>(*GTI)) {
382 const StructLayout *SL = TD.getStructLayout(STy);
383 unsigned Idx = cast<ConstantInt>(Op)->getZExtValue();
384 Disp += SL->getElementOffset(Idx);
385 } else {
386 uint64_t S = TD.getABITypeSize(GTI.getIndexedType());
387 if (ConstantInt *CI = dyn_cast<ConstantInt>(Op)) {
388 // Constant-offset addressing.
Dan Gohman09aae462008-09-26 20:04:15 +0000389 Disp += CI->getSExtValue() * S;
Dan Gohman35893082008-09-18 23:23:44 +0000390 } else if (IndexReg == 0 &&
Dan Gohman97135e12008-09-26 19:15:30 +0000391 (!AM.GV ||
392 !getTargetMachine()->symbolicAddressesAreRIPRel()) &&
Dan Gohman35893082008-09-18 23:23:44 +0000393 (S == 1 || S == 2 || S == 4 || S == 8)) {
394 // Scaled-index addressing.
395 Scale = S;
396 IndexReg = getRegForValue(Op);
397 if (IndexReg == 0)
398 return false;
399 } else
400 // Unsupported.
401 goto unsupported_gep;
402 }
403 }
Dan Gohman09aae462008-09-26 20:04:15 +0000404 // Check for displacement overflow.
405 if (!isInt32(Disp))
406 break;
Dan Gohman35893082008-09-18 23:23:44 +0000407 // Ok, the GEP indices were covered by constant-offset and scaled-index
408 // addressing. Update the address state and move on to examining the base.
409 AM.IndexReg = IndexReg;
410 AM.Scale = Scale;
Dan Gohman09aae462008-09-26 20:04:15 +0000411 AM.Disp = (uint32_t)Disp;
Dan Gohman2ff7fd12008-09-19 22:16:54 +0000412 return X86SelectAddress(U->getOperand(0), AM, isCall);
Dan Gohman35893082008-09-18 23:23:44 +0000413 unsupported_gep:
414 // Ok, the GEP indices weren't all covered.
415 break;
416 }
417 }
418
419 // Handle constant address.
Dan Gohman2ff7fd12008-09-19 22:16:54 +0000420 if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
Dan Gohman2cc3aa42008-09-25 15:24:26 +0000421 // Can't handle alternate code models yet.
422 if (TM.getCodeModel() != CodeModel::Default &&
423 TM.getCodeModel() != CodeModel::Small)
424 return false;
425
Dan Gohman97135e12008-09-26 19:15:30 +0000426 // RIP-relative addresses can't have additional register operands.
427 if (getTargetMachine()->symbolicAddressesAreRIPRel() &&
428 (AM.Base.Reg != 0 || AM.IndexReg != 0))
429 return false;
430
Dan Gohman2cc3aa42008-09-25 15:24:26 +0000431 // Set up the basic address.
432 AM.GV = GV;
433 if (!isCall &&
434 TM.getRelocationModel() == Reloc::PIC_ &&
435 !Subtarget->is64Bit())
436 AM.Base.Reg = getGlobalBaseReg();
437
438 // Emit an extra load if the ABI requires it.
Dan Gohman2ff7fd12008-09-19 22:16:54 +0000439 if (Subtarget->GVRequiresExtraLoad(GV, TM, isCall)) {
440 // Check to see if we've already materialized this
441 // value in a register in this block.
Dan Gohman7e8ef602008-09-19 23:42:04 +0000442 if (unsigned Reg = LocalValueMap[V]) {
443 AM.Base.Reg = Reg;
Dan Gohman2cc3aa42008-09-25 15:24:26 +0000444 AM.GV = 0;
Dan Gohman7e8ef602008-09-19 23:42:04 +0000445 return true;
446 }
Dan Gohman2ff7fd12008-09-19 22:16:54 +0000447 // Issue load from stub if necessary.
448 unsigned Opc = 0;
449 const TargetRegisterClass *RC = NULL;
450 if (TLI.getPointerTy() == MVT::i32) {
451 Opc = X86::MOV32rm;
452 RC = X86::GR32RegisterClass;
453 } else {
454 Opc = X86::MOV64rm;
455 RC = X86::GR64RegisterClass;
456 }
Dan Gohman789ce772008-09-25 23:34:02 +0000457
458 X86AddressMode StubAM;
459 StubAM.Base.Reg = AM.Base.Reg;
460 StubAM.GV = AM.GV;
Dan Gohman2cc3aa42008-09-25 15:24:26 +0000461 unsigned ResultReg = createResultReg(RC);
Dan Gohman789ce772008-09-25 23:34:02 +0000462 addFullAddress(BuildMI(MBB, TII.get(Opc), ResultReg), StubAM);
463
464 // Now construct the final address. Note that the Disp, Scale,
465 // and Index values may already be set here.
Dan Gohman2cc3aa42008-09-25 15:24:26 +0000466 AM.Base.Reg = ResultReg;
467 AM.GV = 0;
Dan Gohman789ce772008-09-25 23:34:02 +0000468
Dan Gohman2ff7fd12008-09-19 22:16:54 +0000469 // Prevent loading GV stub multiple times in same MBB.
470 LocalValueMap[V] = AM.Base.Reg;
Dan Gohman2ff7fd12008-09-19 22:16:54 +0000471 }
472 return true;
Dan Gohman0586d912008-09-10 20:11:02 +0000473 }
474
Dan Gohman97135e12008-09-26 19:15:30 +0000475 // If all else fails, try to materialize the value in a register.
Dan Gohman7962e852008-09-29 21:13:15 +0000476 if (!AM.GV || !getTargetMachine()->symbolicAddressesAreRIPRel()) {
Dan Gohman97135e12008-09-26 19:15:30 +0000477 if (AM.Base.Reg == 0) {
478 AM.Base.Reg = getRegForValue(V);
479 return AM.Base.Reg != 0;
480 }
481 if (AM.IndexReg == 0) {
482 assert(AM.Scale == 1 && "Scale with no index!");
483 AM.IndexReg = getRegForValue(V);
484 return AM.IndexReg != 0;
485 }
486 }
487
488 return false;
Dan Gohman0586d912008-09-10 20:11:02 +0000489}
490
Owen Andersona3971df2008-09-04 07:08:58 +0000491/// X86SelectStore - Select and emit code to implement store instructions.
492bool X86FastISel::X86SelectStore(Instruction* I) {
Evan Cheng24e3a902008-09-08 06:35:17 +0000493 MVT VT;
494 if (!isTypeLegal(I->getOperand(0)->getType(), TLI, VT))
Owen Andersona3971df2008-09-04 07:08:58 +0000495 return false;
Evan Chengf3d4efe2008-09-07 09:09:33 +0000496 unsigned Val = getRegForValue(I->getOperand(0));
497 if (Val == 0)
Owen Andersona3971df2008-09-04 07:08:58 +0000498 // Unhandled operand. Halt "fast" selection and bail.
499 return false;
500
Dan Gohman0586d912008-09-10 20:11:02 +0000501 X86AddressMode AM;
Dan Gohman2ff7fd12008-09-19 22:16:54 +0000502 if (!X86SelectAddress(I->getOperand(1), AM, false))
Dan Gohman0586d912008-09-10 20:11:02 +0000503 return false;
Owen Andersona3971df2008-09-04 07:08:58 +0000504
Dan Gohman0586d912008-09-10 20:11:02 +0000505 return X86FastEmitStore(VT, Val, AM);
Owen Andersona3971df2008-09-04 07:08:58 +0000506}
507
Evan Cheng8b19e562008-09-03 06:44:39 +0000508/// X86SelectLoad - Select and emit code to implement load instructions.
509///
Dan Gohman3df24e62008-09-03 23:12:08 +0000510bool X86FastISel::X86SelectLoad(Instruction *I) {
Evan Chengf3d4efe2008-09-07 09:09:33 +0000511 MVT VT;
512 if (!isTypeLegal(I->getType(), TLI, VT))
Evan Cheng8b19e562008-09-03 06:44:39 +0000513 return false;
514
Dan Gohman0586d912008-09-10 20:11:02 +0000515 X86AddressMode AM;
Dan Gohman2ff7fd12008-09-19 22:16:54 +0000516 if (!X86SelectAddress(I->getOperand(0), AM, false))
Dan Gohman0586d912008-09-10 20:11:02 +0000517 return false;
Evan Cheng8b19e562008-09-03 06:44:39 +0000518
Evan Cheng0de588f2008-09-05 21:00:03 +0000519 unsigned ResultReg = 0;
Dan Gohman0586d912008-09-10 20:11:02 +0000520 if (X86FastEmitLoad(VT, AM, ResultReg)) {
Evan Cheng0de588f2008-09-05 21:00:03 +0000521 UpdateValueMap(I, ResultReg);
522 return true;
Evan Cheng8b19e562008-09-03 06:44:39 +0000523 }
Evan Cheng0de588f2008-09-05 21:00:03 +0000524 return false;
Evan Cheng8b19e562008-09-03 06:44:39 +0000525}
526
Dan Gohman6e3f05f2008-09-04 23:26:51 +0000527bool X86FastISel::X86SelectCmp(Instruction *I) {
528 CmpInst *CI = cast<CmpInst>(I);
529
Dan Gohman9b66d732008-09-30 00:48:39 +0000530 MVT VT;
531 if (!isTypeLegal(I->getOperand(0)->getType(), TLI, VT))
Dan Gohman4f22bb02008-09-05 01:33:56 +0000532 return false;
533
Dan Gohman6e3f05f2008-09-04 23:26:51 +0000534 unsigned Op0Reg = getRegForValue(CI->getOperand(0));
Dan Gohmanf52550b2008-09-05 01:15:35 +0000535 if (Op0Reg == 0) return false;
Dan Gohman6e3f05f2008-09-04 23:26:51 +0000536 unsigned Op1Reg = getRegForValue(CI->getOperand(1));
Dan Gohmanf52550b2008-09-05 01:15:35 +0000537 if (Op1Reg == 0) return false;
538
Dan Gohman6e3f05f2008-09-04 23:26:51 +0000539 unsigned Opc;
Dan Gohmanf52550b2008-09-05 01:15:35 +0000540 switch (VT.getSimpleVT()) {
Dan Gohman6e3f05f2008-09-04 23:26:51 +0000541 case MVT::i8: Opc = X86::CMP8rr; break;
542 case MVT::i16: Opc = X86::CMP16rr; break;
543 case MVT::i32: Opc = X86::CMP32rr; break;
544 case MVT::i64: Opc = X86::CMP64rr; break;
545 case MVT::f32: Opc = X86::UCOMISSrr; break;
546 case MVT::f64: Opc = X86::UCOMISDrr; break;
547 default: return false;
548 }
549
550 unsigned ResultReg = createResultReg(&X86::GR8RegClass);
551 switch (CI->getPredicate()) {
552 case CmpInst::FCMP_OEQ: {
553 unsigned EReg = createResultReg(&X86::GR8RegClass);
554 unsigned NPReg = createResultReg(&X86::GR8RegClass);
555 BuildMI(MBB, TII.get(Opc)).addReg(Op0Reg).addReg(Op1Reg);
556 BuildMI(MBB, TII.get(X86::SETEr), EReg);
557 BuildMI(MBB, TII.get(X86::SETNPr), NPReg);
558 BuildMI(MBB, TII.get(X86::AND8rr), ResultReg).addReg(NPReg).addReg(EReg);
559 break;
560 }
561 case CmpInst::FCMP_UNE: {
562 unsigned NEReg = createResultReg(&X86::GR8RegClass);
563 unsigned PReg = createResultReg(&X86::GR8RegClass);
564 BuildMI(MBB, TII.get(Opc)).addReg(Op0Reg).addReg(Op1Reg);
565 BuildMI(MBB, TII.get(X86::SETNEr), NEReg);
566 BuildMI(MBB, TII.get(X86::SETPr), PReg);
567 BuildMI(MBB, TII.get(X86::OR8rr), ResultReg).addReg(PReg).addReg(NEReg);
568 break;
569 }
570 case CmpInst::FCMP_OGT:
571 BuildMI(MBB, TII.get(Opc)).addReg(Op0Reg).addReg(Op1Reg);
572 BuildMI(MBB, TII.get(X86::SETAr), ResultReg);
573 break;
574 case CmpInst::FCMP_OGE:
575 BuildMI(MBB, TII.get(Opc)).addReg(Op0Reg).addReg(Op1Reg);
576 BuildMI(MBB, TII.get(X86::SETAEr), ResultReg);
577 break;
578 case CmpInst::FCMP_OLT:
579 BuildMI(MBB, TII.get(Opc)).addReg(Op1Reg).addReg(Op0Reg);
580 BuildMI(MBB, TII.get(X86::SETAr), ResultReg);
581 break;
582 case CmpInst::FCMP_OLE:
583 BuildMI(MBB, TII.get(Opc)).addReg(Op1Reg).addReg(Op0Reg);
584 BuildMI(MBB, TII.get(X86::SETAEr), ResultReg);
585 break;
586 case CmpInst::FCMP_ONE:
587 BuildMI(MBB, TII.get(Opc)).addReg(Op0Reg).addReg(Op1Reg);
588 BuildMI(MBB, TII.get(X86::SETNEr), ResultReg);
589 break;
590 case CmpInst::FCMP_ORD:
591 BuildMI(MBB, TII.get(Opc)).addReg(Op0Reg).addReg(Op1Reg);
592 BuildMI(MBB, TII.get(X86::SETNPr), ResultReg);
593 break;
594 case CmpInst::FCMP_UNO:
595 BuildMI(MBB, TII.get(Opc)).addReg(Op0Reg).addReg(Op1Reg);
596 BuildMI(MBB, TII.get(X86::SETPr), ResultReg);
597 break;
598 case CmpInst::FCMP_UEQ:
599 BuildMI(MBB, TII.get(Opc)).addReg(Op0Reg).addReg(Op1Reg);
600 BuildMI(MBB, TII.get(X86::SETEr), ResultReg);
601 break;
602 case CmpInst::FCMP_UGT:
603 BuildMI(MBB, TII.get(Opc)).addReg(Op1Reg).addReg(Op0Reg);
604 BuildMI(MBB, TII.get(X86::SETBr), ResultReg);
605 break;
606 case CmpInst::FCMP_UGE:
607 BuildMI(MBB, TII.get(Opc)).addReg(Op1Reg).addReg(Op0Reg);
608 BuildMI(MBB, TII.get(X86::SETBEr), ResultReg);
609 break;
610 case CmpInst::FCMP_ULT:
611 BuildMI(MBB, TII.get(Opc)).addReg(Op0Reg).addReg(Op1Reg);
612 BuildMI(MBB, TII.get(X86::SETBr), ResultReg);
613 break;
614 case CmpInst::FCMP_ULE:
615 BuildMI(MBB, TII.get(Opc)).addReg(Op0Reg).addReg(Op1Reg);
616 BuildMI(MBB, TII.get(X86::SETBEr), ResultReg);
617 break;
618 case CmpInst::ICMP_EQ:
619 BuildMI(MBB, TII.get(Opc)).addReg(Op0Reg).addReg(Op1Reg);
620 BuildMI(MBB, TII.get(X86::SETEr), ResultReg);
621 break;
622 case CmpInst::ICMP_NE:
623 BuildMI(MBB, TII.get(Opc)).addReg(Op0Reg).addReg(Op1Reg);
624 BuildMI(MBB, TII.get(X86::SETNEr), ResultReg);
625 break;
626 case CmpInst::ICMP_UGT:
627 BuildMI(MBB, TII.get(Opc)).addReg(Op0Reg).addReg(Op1Reg);
628 BuildMI(MBB, TII.get(X86::SETAr), ResultReg);
629 break;
630 case CmpInst::ICMP_UGE:
631 BuildMI(MBB, TII.get(Opc)).addReg(Op0Reg).addReg(Op1Reg);
632 BuildMI(MBB, TII.get(X86::SETAEr), ResultReg);
633 break;
634 case CmpInst::ICMP_ULT:
635 BuildMI(MBB, TII.get(Opc)).addReg(Op0Reg).addReg(Op1Reg);
636 BuildMI(MBB, TII.get(X86::SETBr), ResultReg);
637 break;
638 case CmpInst::ICMP_ULE:
639 BuildMI(MBB, TII.get(Opc)).addReg(Op0Reg).addReg(Op1Reg);
640 BuildMI(MBB, TII.get(X86::SETBEr), ResultReg);
641 break;
642 case CmpInst::ICMP_SGT:
643 BuildMI(MBB, TII.get(Opc)).addReg(Op0Reg).addReg(Op1Reg);
644 BuildMI(MBB, TII.get(X86::SETGr), ResultReg);
645 break;
646 case CmpInst::ICMP_SGE:
647 BuildMI(MBB, TII.get(Opc)).addReg(Op0Reg).addReg(Op1Reg);
648 BuildMI(MBB, TII.get(X86::SETGEr), ResultReg);
649 break;
650 case CmpInst::ICMP_SLT:
651 BuildMI(MBB, TII.get(Opc)).addReg(Op0Reg).addReg(Op1Reg);
652 BuildMI(MBB, TII.get(X86::SETLr), ResultReg);
653 break;
654 case CmpInst::ICMP_SLE:
655 BuildMI(MBB, TII.get(Opc)).addReg(Op0Reg).addReg(Op1Reg);
656 BuildMI(MBB, TII.get(X86::SETLEr), ResultReg);
657 break;
658 default:
659 return false;
660 }
661
662 UpdateValueMap(I, ResultReg);
663 return true;
664}
Evan Cheng8b19e562008-09-03 06:44:39 +0000665
Dan Gohmand89ae992008-09-05 01:06:14 +0000666bool X86FastISel::X86SelectZExt(Instruction *I) {
667 // Special-case hack: The only i1 values we know how to produce currently
668 // set the upper bits of an i8 value to zero.
669 if (I->getType() == Type::Int8Ty &&
670 I->getOperand(0)->getType() == Type::Int1Ty) {
671 unsigned ResultReg = getRegForValue(I->getOperand(0));
Dan Gohmanf52550b2008-09-05 01:15:35 +0000672 if (ResultReg == 0) return false;
Dan Gohmand89ae992008-09-05 01:06:14 +0000673 UpdateValueMap(I, ResultReg);
674 return true;
675 }
676
677 return false;
678}
679
680bool X86FastISel::X86SelectBranch(Instruction *I) {
681 BranchInst *BI = cast<BranchInst>(I);
682 // Unconditional branches are selected by tablegen-generated code.
683 unsigned OpReg = getRegForValue(BI->getCondition());
Dan Gohmanf52550b2008-09-05 01:15:35 +0000684 if (OpReg == 0) return false;
Dan Gohmand89ae992008-09-05 01:06:14 +0000685 MachineBasicBlock *TrueMBB = MBBMap[BI->getSuccessor(0)];
686 MachineBasicBlock *FalseMBB = MBBMap[BI->getSuccessor(1)];
687
688 BuildMI(MBB, TII.get(X86::TEST8rr)).addReg(OpReg).addReg(OpReg);
689 BuildMI(MBB, TII.get(X86::JNE)).addMBB(TrueMBB);
690 BuildMI(MBB, TII.get(X86::JMP)).addMBB(FalseMBB);
691
692 MBB->addSuccessor(TrueMBB);
693 MBB->addSuccessor(FalseMBB);
694
695 return true;
696}
697
Dan Gohmanc39f4db2008-09-05 18:30:08 +0000698bool X86FastISel::X86SelectShift(Instruction *I) {
Chris Lattner743922e2008-09-21 21:44:29 +0000699 unsigned CReg = 0, OpReg = 0, OpImm = 0;
Dan Gohmanc39f4db2008-09-05 18:30:08 +0000700 const TargetRegisterClass *RC = NULL;
701 if (I->getType() == Type::Int8Ty) {
702 CReg = X86::CL;
703 RC = &X86::GR8RegClass;
704 switch (I->getOpcode()) {
Chris Lattner743922e2008-09-21 21:44:29 +0000705 case Instruction::LShr: OpReg = X86::SHR8rCL; OpImm = X86::SHR8ri; break;
706 case Instruction::AShr: OpReg = X86::SAR8rCL; OpImm = X86::SAR8ri; break;
707 case Instruction::Shl: OpReg = X86::SHL8rCL; OpImm = X86::SHL8ri; break;
Dan Gohmanc39f4db2008-09-05 18:30:08 +0000708 default: return false;
709 }
710 } else if (I->getType() == Type::Int16Ty) {
711 CReg = X86::CX;
712 RC = &X86::GR16RegClass;
713 switch (I->getOpcode()) {
Chris Lattner743922e2008-09-21 21:44:29 +0000714 case Instruction::LShr: OpReg = X86::SHR16rCL; OpImm = X86::SHR16ri; break;
715 case Instruction::AShr: OpReg = X86::SAR16rCL; OpImm = X86::SAR16ri; break;
716 case Instruction::Shl: OpReg = X86::SHL16rCL; OpImm = X86::SHL16ri; break;
Dan Gohmanc39f4db2008-09-05 18:30:08 +0000717 default: return false;
718 }
719 } else if (I->getType() == Type::Int32Ty) {
720 CReg = X86::ECX;
721 RC = &X86::GR32RegClass;
722 switch (I->getOpcode()) {
Chris Lattner743922e2008-09-21 21:44:29 +0000723 case Instruction::LShr: OpReg = X86::SHR32rCL; OpImm = X86::SHR32ri; break;
724 case Instruction::AShr: OpReg = X86::SAR32rCL; OpImm = X86::SAR32ri; break;
725 case Instruction::Shl: OpReg = X86::SHL32rCL; OpImm = X86::SHL32ri; break;
Dan Gohmanc39f4db2008-09-05 18:30:08 +0000726 default: return false;
727 }
728 } else if (I->getType() == Type::Int64Ty) {
729 CReg = X86::RCX;
730 RC = &X86::GR64RegClass;
731 switch (I->getOpcode()) {
Chris Lattner743922e2008-09-21 21:44:29 +0000732 case Instruction::LShr: OpReg = X86::SHR64rCL; OpImm = X86::SHR64ri; break;
733 case Instruction::AShr: OpReg = X86::SAR64rCL; OpImm = X86::SAR64ri; break;
734 case Instruction::Shl: OpReg = X86::SHL64rCL; OpImm = X86::SHL64ri; break;
Dan Gohmanc39f4db2008-09-05 18:30:08 +0000735 default: return false;
736 }
737 } else {
738 return false;
739 }
740
Dan Gohmanf58cb6d2008-09-05 21:27:34 +0000741 MVT VT = MVT::getMVT(I->getType(), /*HandleUnknown=*/true);
Dan Gohman9b66d732008-09-30 00:48:39 +0000742 if (VT == MVT::Other || !isTypeLegal(I->getType(), TLI, VT))
Dan Gohmanf58cb6d2008-09-05 21:27:34 +0000743 return false;
744
Dan Gohmanc39f4db2008-09-05 18:30:08 +0000745 unsigned Op0Reg = getRegForValue(I->getOperand(0));
746 if (Op0Reg == 0) return false;
Chris Lattner743922e2008-09-21 21:44:29 +0000747
748 // Fold immediate in shl(x,3).
749 if (ConstantInt *CI = dyn_cast<ConstantInt>(I->getOperand(1))) {
750 unsigned ResultReg = createResultReg(RC);
751 BuildMI(MBB, TII.get(OpImm),
752 ResultReg).addReg(Op0Reg).addImm(CI->getZExtValue());
753 UpdateValueMap(I, ResultReg);
754 return true;
755 }
756
Dan Gohmanc39f4db2008-09-05 18:30:08 +0000757 unsigned Op1Reg = getRegForValue(I->getOperand(1));
758 if (Op1Reg == 0) return false;
759 TII.copyRegToReg(*MBB, MBB->end(), CReg, Op1Reg, RC, RC);
760 unsigned ResultReg = createResultReg(RC);
Chris Lattner743922e2008-09-21 21:44:29 +0000761 BuildMI(MBB, TII.get(OpReg), ResultReg).addReg(Op0Reg);
Dan Gohmanc39f4db2008-09-05 18:30:08 +0000762 UpdateValueMap(I, ResultReg);
763 return true;
764}
765
766bool X86FastISel::X86SelectSelect(Instruction *I) {
Dan Gohmanf58cb6d2008-09-05 21:27:34 +0000767 const Type *Ty = I->getType();
Dan Gohmanc39f4db2008-09-05 18:30:08 +0000768 if (isa<PointerType>(Ty))
Dan Gohman1fbc3cd2008-09-18 18:26:43 +0000769 Ty = TD.getIntPtrType();
Dan Gohmanc39f4db2008-09-05 18:30:08 +0000770
771 unsigned Opc = 0;
772 const TargetRegisterClass *RC = NULL;
773 if (Ty == Type::Int16Ty) {
Dan Gohman31d26912008-09-05 21:13:04 +0000774 Opc = X86::CMOVE16rr;
Dan Gohmanc39f4db2008-09-05 18:30:08 +0000775 RC = &X86::GR16RegClass;
776 } else if (Ty == Type::Int32Ty) {
Dan Gohman31d26912008-09-05 21:13:04 +0000777 Opc = X86::CMOVE32rr;
Dan Gohmanc39f4db2008-09-05 18:30:08 +0000778 RC = &X86::GR32RegClass;
779 } else if (Ty == Type::Int64Ty) {
Dan Gohman31d26912008-09-05 21:13:04 +0000780 Opc = X86::CMOVE64rr;
Dan Gohmanc39f4db2008-09-05 18:30:08 +0000781 RC = &X86::GR64RegClass;
782 } else {
783 return false;
784 }
785
Dan Gohmanf58cb6d2008-09-05 21:27:34 +0000786 MVT VT = MVT::getMVT(Ty, /*HandleUnknown=*/true);
Dan Gohman9b66d732008-09-30 00:48:39 +0000787 if (VT == MVT::Other || !isTypeLegal(Ty, TLI, VT))
Dan Gohmanf58cb6d2008-09-05 21:27:34 +0000788 return false;
789
Dan Gohmanc39f4db2008-09-05 18:30:08 +0000790 unsigned Op0Reg = getRegForValue(I->getOperand(0));
791 if (Op0Reg == 0) return false;
792 unsigned Op1Reg = getRegForValue(I->getOperand(1));
793 if (Op1Reg == 0) return false;
794 unsigned Op2Reg = getRegForValue(I->getOperand(2));
795 if (Op2Reg == 0) return false;
796
797 BuildMI(MBB, TII.get(X86::TEST8rr)).addReg(Op0Reg).addReg(Op0Reg);
798 unsigned ResultReg = createResultReg(RC);
799 BuildMI(MBB, TII.get(Opc), ResultReg).addReg(Op1Reg).addReg(Op2Reg);
800 UpdateValueMap(I, ResultReg);
801 return true;
802}
803
Dan Gohman78efce62008-09-10 21:02:08 +0000804bool X86FastISel::X86SelectFPExt(Instruction *I) {
805 if (Subtarget->hasSSE2()) {
806 if (I->getType() == Type::DoubleTy) {
807 Value *V = I->getOperand(0);
808 if (V->getType() == Type::FloatTy) {
809 unsigned OpReg = getRegForValue(V);
810 if (OpReg == 0) return false;
811 unsigned ResultReg = createResultReg(X86::FR64RegisterClass);
812 BuildMI(MBB, TII.get(X86::CVTSS2SDrr), ResultReg).addReg(OpReg);
813 UpdateValueMap(I, ResultReg);
814 return true;
815 }
816 }
817 }
818
819 return false;
820}
821
822bool X86FastISel::X86SelectFPTrunc(Instruction *I) {
823 if (Subtarget->hasSSE2()) {
824 if (I->getType() == Type::FloatTy) {
825 Value *V = I->getOperand(0);
826 if (V->getType() == Type::DoubleTy) {
827 unsigned OpReg = getRegForValue(V);
828 if (OpReg == 0) return false;
829 unsigned ResultReg = createResultReg(X86::FR32RegisterClass);
830 BuildMI(MBB, TII.get(X86::CVTSD2SSrr), ResultReg).addReg(OpReg);
831 UpdateValueMap(I, ResultReg);
832 return true;
833 }
834 }
835 }
836
837 return false;
838}
839
Evan Cheng10a8d9c2008-09-07 08:47:42 +0000840bool X86FastISel::X86SelectTrunc(Instruction *I) {
841 if (Subtarget->is64Bit())
842 // All other cases should be handled by the tblgen generated code.
843 return false;
844 MVT SrcVT = TLI.getValueType(I->getOperand(0)->getType());
845 MVT DstVT = TLI.getValueType(I->getType());
846 if (DstVT != MVT::i8)
847 // All other cases should be handled by the tblgen generated code.
848 return false;
849 if (SrcVT != MVT::i16 && SrcVT != MVT::i32)
850 // All other cases should be handled by the tblgen generated code.
851 return false;
852
853 unsigned InputReg = getRegForValue(I->getOperand(0));
854 if (!InputReg)
855 // Unhandled operand. Halt "fast" selection and bail.
856 return false;
857
858 // First issue a copy to GR16_ or GR32_.
859 unsigned CopyOpc = (SrcVT == MVT::i16) ? X86::MOV16to16_ : X86::MOV32to32_;
860 const TargetRegisterClass *CopyRC = (SrcVT == MVT::i16)
861 ? X86::GR16_RegisterClass : X86::GR32_RegisterClass;
862 unsigned CopyReg = createResultReg(CopyRC);
863 BuildMI(MBB, TII.get(CopyOpc), CopyReg).addReg(InputReg);
864
865 // Then issue an extract_subreg.
866 unsigned ResultReg = FastEmitInst_extractsubreg(CopyReg,1); // x86_subreg_8bit
867 if (!ResultReg)
868 return false;
869
870 UpdateValueMap(I, ResultReg);
871 return true;
872}
873
Evan Chengf3d4efe2008-09-07 09:09:33 +0000874bool X86FastISel::X86SelectCall(Instruction *I) {
875 CallInst *CI = cast<CallInst>(I);
876 Value *Callee = I->getOperand(0);
877
878 // Can't handle inline asm yet.
879 if (isa<InlineAsm>(Callee))
880 return false;
881
882 // FIXME: Handle some intrinsics.
883 if (Function *F = CI->getCalledFunction()) {
884 if (F->isDeclaration() &&F->getIntrinsicID())
885 return false;
886 }
887
Evan Chengf3d4efe2008-09-07 09:09:33 +0000888 // Handle only C and fastcc calling conventions for now.
889 CallSite CS(CI);
890 unsigned CC = CS.getCallingConv();
891 if (CC != CallingConv::C &&
892 CC != CallingConv::Fast &&
893 CC != CallingConv::X86_FastCall)
894 return false;
895
896 // Let SDISel handle vararg functions.
897 const PointerType *PT = cast<PointerType>(CS.getCalledValue()->getType());
898 const FunctionType *FTy = cast<FunctionType>(PT->getElementType());
899 if (FTy->isVarArg())
900 return false;
901
902 // Handle *simple* calls for now.
903 const Type *RetTy = CS.getType();
904 MVT RetVT;
Dan Gohmanb5b6ec62008-09-17 21:18:49 +0000905 if (RetTy == Type::VoidTy)
906 RetVT = MVT::isVoid;
907 else if (!isTypeLegal(RetTy, TLI, RetVT, true))
Evan Chengf3d4efe2008-09-07 09:09:33 +0000908 return false;
909
Dan Gohmanb5b6ec62008-09-17 21:18:49 +0000910 // Materialize callee address in a register. FIXME: GV address can be
911 // handled with a CALLpcrel32 instead.
Dan Gohman2ff7fd12008-09-19 22:16:54 +0000912 X86AddressMode CalleeAM;
913 if (!X86SelectAddress(Callee, CalleeAM, true))
914 return false;
Dan Gohmanb5b6ec62008-09-17 21:18:49 +0000915 unsigned CalleeOp = 0;
Dan Gohman2ff7fd12008-09-19 22:16:54 +0000916 GlobalValue *GV = 0;
917 if (CalleeAM.Base.Reg != 0) {
918 assert(CalleeAM.GV == 0);
919 CalleeOp = CalleeAM.Base.Reg;
920 } else if (CalleeAM.GV != 0) {
921 assert(CalleeAM.GV != 0);
922 GV = CalleeAM.GV;
923 } else
924 return false;
Dan Gohmanb5b6ec62008-09-17 21:18:49 +0000925
Evan Chengdebdea02008-09-08 17:15:42 +0000926 // Allow calls which produce i1 results.
927 bool AndToI1 = false;
928 if (RetVT == MVT::i1) {
929 RetVT = MVT::i8;
930 AndToI1 = true;
931 }
932
Evan Chengf3d4efe2008-09-07 09:09:33 +0000933 // Deal with call operands first.
934 SmallVector<unsigned, 4> Args;
935 SmallVector<MVT, 4> ArgVTs;
936 SmallVector<ISD::ArgFlagsTy, 4> ArgFlags;
937 Args.reserve(CS.arg_size());
938 ArgVTs.reserve(CS.arg_size());
939 ArgFlags.reserve(CS.arg_size());
940 for (CallSite::arg_iterator i = CS.arg_begin(), e = CS.arg_end();
941 i != e; ++i) {
942 unsigned Arg = getRegForValue(*i);
943 if (Arg == 0)
944 return false;
945 ISD::ArgFlagsTy Flags;
946 unsigned AttrInd = i - CS.arg_begin() + 1;
Devang Patel05988662008-09-25 21:00:45 +0000947 if (CS.paramHasAttr(AttrInd, Attribute::SExt))
Evan Chengf3d4efe2008-09-07 09:09:33 +0000948 Flags.setSExt();
Devang Patel05988662008-09-25 21:00:45 +0000949 if (CS.paramHasAttr(AttrInd, Attribute::ZExt))
Evan Chengf3d4efe2008-09-07 09:09:33 +0000950 Flags.setZExt();
951
952 // FIXME: Only handle *easy* calls for now.
Devang Patel05988662008-09-25 21:00:45 +0000953 if (CS.paramHasAttr(AttrInd, Attribute::InReg) ||
954 CS.paramHasAttr(AttrInd, Attribute::StructRet) ||
955 CS.paramHasAttr(AttrInd, Attribute::Nest) ||
956 CS.paramHasAttr(AttrInd, Attribute::ByVal))
Evan Chengf3d4efe2008-09-07 09:09:33 +0000957 return false;
958
959 const Type *ArgTy = (*i)->getType();
960 MVT ArgVT;
961 if (!isTypeLegal(ArgTy, TLI, ArgVT))
962 return false;
963 unsigned OriginalAlignment = TD.getABITypeAlignment(ArgTy);
964 Flags.setOrigAlign(OriginalAlignment);
965
966 Args.push_back(Arg);
967 ArgVTs.push_back(ArgVT);
968 ArgFlags.push_back(Flags);
969 }
970
971 // Analyze operands of the call, assigning locations to each operand.
972 SmallVector<CCValAssign, 16> ArgLocs;
973 CCState CCInfo(CC, false, TM, ArgLocs);
974 CCInfo.AnalyzeCallOperands(ArgVTs, ArgFlags, CCAssignFnForCall(CC));
975
976 // Get a count of how many bytes are to be pushed on the stack.
977 unsigned NumBytes = CCInfo.getNextStackOffset();
978
979 // Issue CALLSEQ_START
980 BuildMI(MBB, TII.get(X86::ADJCALLSTACKDOWN)).addImm(NumBytes);
981
982 // Process argumenet: walk the register/memloc assignments, inserting
983 // copies / loads.
984 SmallVector<unsigned, 4> RegArgs;
985 for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
986 CCValAssign &VA = ArgLocs[i];
987 unsigned Arg = Args[VA.getValNo()];
988 MVT ArgVT = ArgVTs[VA.getValNo()];
989
990 // Promote the value if needed.
991 switch (VA.getLocInfo()) {
992 default: assert(0 && "Unknown loc info!");
993 case CCValAssign::Full: break;
Evan Cheng24e3a902008-09-08 06:35:17 +0000994 case CCValAssign::SExt: {
995 bool Emitted = X86FastEmitExtend(ISD::SIGN_EXTEND, VA.getLocVT(),
996 Arg, ArgVT, Arg);
997 assert(Emitted && "Failed to emit a sext!");
998 ArgVT = VA.getLocVT();
Evan Chengf3d4efe2008-09-07 09:09:33 +0000999 break;
Evan Cheng24e3a902008-09-08 06:35:17 +00001000 }
1001 case CCValAssign::ZExt: {
1002 bool Emitted = X86FastEmitExtend(ISD::ZERO_EXTEND, VA.getLocVT(),
1003 Arg, ArgVT, Arg);
1004 assert(Emitted && "Failed to emit a zext!");
1005 ArgVT = VA.getLocVT();
Evan Chengf3d4efe2008-09-07 09:09:33 +00001006 break;
Evan Cheng24e3a902008-09-08 06:35:17 +00001007 }
1008 case CCValAssign::AExt: {
1009 bool Emitted = X86FastEmitExtend(ISD::ANY_EXTEND, VA.getLocVT(),
1010 Arg, ArgVT, Arg);
Owen Andersonb6369132008-09-11 02:41:37 +00001011 if (!Emitted)
1012 Emitted = X86FastEmitExtend(ISD::ZERO_EXTEND, VA.getLocVT(),
1013 Arg, ArgVT, Arg);
1014 if (!Emitted)
1015 Emitted = X86FastEmitExtend(ISD::SIGN_EXTEND, VA.getLocVT(),
1016 Arg, ArgVT, Arg);
1017
Evan Cheng24e3a902008-09-08 06:35:17 +00001018 assert(Emitted && "Failed to emit a aext!");
1019 ArgVT = VA.getLocVT();
Evan Chengf3d4efe2008-09-07 09:09:33 +00001020 break;
1021 }
Evan Cheng24e3a902008-09-08 06:35:17 +00001022 }
Evan Chengf3d4efe2008-09-07 09:09:33 +00001023
1024 if (VA.isRegLoc()) {
1025 TargetRegisterClass* RC = TLI.getRegClassFor(ArgVT);
1026 bool Emitted = TII.copyRegToReg(*MBB, MBB->end(), VA.getLocReg(),
1027 Arg, RC, RC);
1028 assert(Emitted && "Failed to emit a copy instruction!");
1029 RegArgs.push_back(VA.getLocReg());
1030 } else {
1031 unsigned LocMemOffset = VA.getLocMemOffset();
Dan Gohman0586d912008-09-10 20:11:02 +00001032 X86AddressMode AM;
1033 AM.Base.Reg = StackPtr;
1034 AM.Disp = LocMemOffset;
1035 X86FastEmitStore(ArgVT, Arg, AM);
Evan Chengf3d4efe2008-09-07 09:09:33 +00001036 }
1037 }
1038
Dan Gohman2cc3aa42008-09-25 15:24:26 +00001039 // ELF / PIC requires GOT in the EBX register before function calls via PLT
1040 // GOT pointer.
1041 if (!Subtarget->is64Bit() &&
1042 TM.getRelocationModel() == Reloc::PIC_ &&
1043 Subtarget->isPICStyleGOT()) {
1044 TargetRegisterClass *RC = X86::GR32RegisterClass;
1045 unsigned Base = getGlobalBaseReg();
1046 bool Emitted = TII.copyRegToReg(*MBB, MBB->end(), X86::EBX, Base, RC, RC);
1047 assert(Emitted && "Failed to emit a copy instruction!");
1048 }
1049
Evan Chengf3d4efe2008-09-07 09:09:33 +00001050 // Issue the call.
1051 unsigned CallOpc = CalleeOp
1052 ? (Subtarget->is64Bit() ? X86::CALL64r : X86::CALL32r)
1053 : (Subtarget->is64Bit() ? X86::CALL64pcrel32 : X86::CALLpcrel32);
1054 MachineInstrBuilder MIB = CalleeOp
1055 ? BuildMI(MBB, TII.get(CallOpc)).addReg(CalleeOp)
Dan Gohman2ff7fd12008-09-19 22:16:54 +00001056 : BuildMI(MBB, TII.get(CallOpc)).addGlobalAddress(GV);
Dan Gohman2cc3aa42008-09-25 15:24:26 +00001057
1058 // Add an implicit use GOT pointer in EBX.
1059 if (!Subtarget->is64Bit() &&
1060 TM.getRelocationModel() == Reloc::PIC_ &&
1061 Subtarget->isPICStyleGOT())
1062 MIB.addReg(X86::EBX);
1063
Evan Chengf3d4efe2008-09-07 09:09:33 +00001064 // Add implicit physical register uses to the call.
1065 while (!RegArgs.empty()) {
1066 MIB.addReg(RegArgs.back());
1067 RegArgs.pop_back();
1068 }
1069
1070 // Issue CALLSEQ_END
1071 BuildMI(MBB, TII.get(X86::ADJCALLSTACKUP)).addImm(NumBytes).addImm(0);
1072
1073 // Now handle call return value (if any).
Evan Chengf3d4efe2008-09-07 09:09:33 +00001074 if (RetVT.getSimpleVT() != MVT::isVoid) {
1075 SmallVector<CCValAssign, 16> RVLocs;
1076 CCState CCInfo(CC, false, TM, RVLocs);
1077 CCInfo.AnalyzeCallResult(RetVT, RetCC_X86);
1078
1079 // Copy all of the result registers out of their specified physreg.
1080 assert(RVLocs.size() == 1 && "Can't handle multi-value calls!");
1081 MVT CopyVT = RVLocs[0].getValVT();
1082 TargetRegisterClass* DstRC = TLI.getRegClassFor(CopyVT);
1083 TargetRegisterClass *SrcRC = DstRC;
1084
1085 // If this is a call to a function that returns an fp value on the x87 fp
1086 // stack, but where we prefer to use the value in xmm registers, copy it
1087 // out as F80 and use a truncate to move it from fp stack reg to xmm reg.
1088 if ((RVLocs[0].getLocReg() == X86::ST0 ||
1089 RVLocs[0].getLocReg() == X86::ST1) &&
1090 isScalarFPTypeInSSEReg(RVLocs[0].getValVT())) {
1091 CopyVT = MVT::f80;
1092 SrcRC = X86::RSTRegisterClass;
1093 DstRC = X86::RFP80RegisterClass;
1094 }
1095
1096 unsigned ResultReg = createResultReg(DstRC);
1097 bool Emitted = TII.copyRegToReg(*MBB, MBB->end(), ResultReg,
1098 RVLocs[0].getLocReg(), DstRC, SrcRC);
1099 assert(Emitted && "Failed to emit a copy instruction!");
1100 if (CopyVT != RVLocs[0].getValVT()) {
1101 // Round the F80 the right size, which also moves to the appropriate xmm
1102 // register. This is accomplished by storing the F80 value in memory and
1103 // then loading it back. Ewww...
1104 MVT ResVT = RVLocs[0].getValVT();
1105 unsigned Opc = ResVT == MVT::f32 ? X86::ST_Fp80m32 : X86::ST_Fp80m64;
1106 unsigned MemSize = ResVT.getSizeInBits()/8;
Dan Gohman0586d912008-09-10 20:11:02 +00001107 int FI = MFI.CreateStackObject(MemSize, MemSize);
Evan Chengf3d4efe2008-09-07 09:09:33 +00001108 addFrameReference(BuildMI(MBB, TII.get(Opc)), FI).addReg(ResultReg);
1109 DstRC = ResVT == MVT::f32
1110 ? X86::FR32RegisterClass : X86::FR64RegisterClass;
1111 Opc = ResVT == MVT::f32 ? X86::MOVSSrm : X86::MOVSDrm;
1112 ResultReg = createResultReg(DstRC);
1113 addFrameReference(BuildMI(MBB, TII.get(Opc), ResultReg), FI);
1114 }
1115
Evan Chengdebdea02008-09-08 17:15:42 +00001116 if (AndToI1) {
1117 // Mask out all but lowest bit for some call which produces an i1.
1118 unsigned AndResult = createResultReg(X86::GR8RegisterClass);
1119 BuildMI(MBB, TII.get(X86::AND8ri), AndResult).addReg(ResultReg).addImm(1);
1120 ResultReg = AndResult;
1121 }
1122
Evan Chengf3d4efe2008-09-07 09:09:33 +00001123 UpdateValueMap(I, ResultReg);
1124 }
1125
1126 return true;
1127}
1128
1129
Dan Gohman99b21822008-08-28 23:21:34 +00001130bool
Dan Gohman3df24e62008-09-03 23:12:08 +00001131X86FastISel::TargetSelectInstruction(Instruction *I) {
Dan Gohman99b21822008-08-28 23:21:34 +00001132 switch (I->getOpcode()) {
1133 default: break;
Evan Cheng8b19e562008-09-03 06:44:39 +00001134 case Instruction::Load:
Dan Gohman3df24e62008-09-03 23:12:08 +00001135 return X86SelectLoad(I);
Owen Anderson79924eb2008-09-04 16:48:33 +00001136 case Instruction::Store:
1137 return X86SelectStore(I);
Dan Gohman6e3f05f2008-09-04 23:26:51 +00001138 case Instruction::ICmp:
1139 case Instruction::FCmp:
1140 return X86SelectCmp(I);
Dan Gohmand89ae992008-09-05 01:06:14 +00001141 case Instruction::ZExt:
1142 return X86SelectZExt(I);
1143 case Instruction::Br:
1144 return X86SelectBranch(I);
Evan Chengf3d4efe2008-09-07 09:09:33 +00001145 case Instruction::Call:
1146 return X86SelectCall(I);
Dan Gohmanc39f4db2008-09-05 18:30:08 +00001147 case Instruction::LShr:
1148 case Instruction::AShr:
1149 case Instruction::Shl:
1150 return X86SelectShift(I);
1151 case Instruction::Select:
1152 return X86SelectSelect(I);
Evan Cheng10a8d9c2008-09-07 08:47:42 +00001153 case Instruction::Trunc:
1154 return X86SelectTrunc(I);
Dan Gohman78efce62008-09-10 21:02:08 +00001155 case Instruction::FPExt:
1156 return X86SelectFPExt(I);
1157 case Instruction::FPTrunc:
1158 return X86SelectFPTrunc(I);
Dan Gohman99b21822008-08-28 23:21:34 +00001159 }
1160
1161 return false;
1162}
1163
Dan Gohman0586d912008-09-10 20:11:02 +00001164unsigned X86FastISel::TargetMaterializeConstant(Constant *C) {
Evan Cheng59fbc802008-09-09 01:26:59 +00001165 MVT VT;
1166 if (!isTypeLegal(C->getType(), TLI, VT))
Owen Anderson95267a12008-09-05 00:06:23 +00001167 return false;
1168
1169 // Get opcode and regclass of the output for the given load instruction.
1170 unsigned Opc = 0;
1171 const TargetRegisterClass *RC = NULL;
1172 switch (VT.getSimpleVT()) {
1173 default: return false;
1174 case MVT::i8:
1175 Opc = X86::MOV8rm;
1176 RC = X86::GR8RegisterClass;
1177 break;
1178 case MVT::i16:
1179 Opc = X86::MOV16rm;
1180 RC = X86::GR16RegisterClass;
1181 break;
1182 case MVT::i32:
1183 Opc = X86::MOV32rm;
1184 RC = X86::GR32RegisterClass;
1185 break;
1186 case MVT::i64:
1187 // Must be in x86-64 mode.
1188 Opc = X86::MOV64rm;
1189 RC = X86::GR64RegisterClass;
1190 break;
1191 case MVT::f32:
1192 if (Subtarget->hasSSE1()) {
1193 Opc = X86::MOVSSrm;
1194 RC = X86::FR32RegisterClass;
1195 } else {
1196 Opc = X86::LD_Fp32m;
1197 RC = X86::RFP32RegisterClass;
1198 }
1199 break;
1200 case MVT::f64:
1201 if (Subtarget->hasSSE2()) {
1202 Opc = X86::MOVSDrm;
1203 RC = X86::FR64RegisterClass;
1204 } else {
1205 Opc = X86::LD_Fp64m;
1206 RC = X86::RFP64RegisterClass;
1207 }
1208 break;
1209 case MVT::f80:
Dan Gohman5af29c22008-09-26 01:39:32 +00001210 // No f80 support yet.
1211 return false;
Owen Anderson95267a12008-09-05 00:06:23 +00001212 }
1213
Dan Gohman2ff7fd12008-09-19 22:16:54 +00001214 // Materialize addresses with LEA instructions.
Owen Anderson95267a12008-09-05 00:06:23 +00001215 if (isa<GlobalValue>(C)) {
Dan Gohman2ff7fd12008-09-19 22:16:54 +00001216 X86AddressMode AM;
1217 if (X86SelectAddress(C, AM, false)) {
1218 if (TLI.getPointerTy() == MVT::i32)
1219 Opc = X86::LEA32r;
1220 else
1221 Opc = X86::LEA64r;
1222 unsigned ResultReg = createResultReg(RC);
1223 addFullAddress(BuildMI(MBB, TII.get(Opc), ResultReg), AM);
Owen Anderson95267a12008-09-05 00:06:23 +00001224 return ResultReg;
Dan Gohman2ff7fd12008-09-19 22:16:54 +00001225 }
Evan Cheng0de588f2008-09-05 21:00:03 +00001226 return 0;
Owen Anderson95267a12008-09-05 00:06:23 +00001227 }
1228
Owen Anderson3b217c62008-09-06 01:11:01 +00001229 // MachineConstantPool wants an explicit alignment.
Dan Gohman1fbc3cd2008-09-18 18:26:43 +00001230 unsigned Align = TD.getPreferredTypeAlignmentShift(C->getType());
Owen Anderson3b217c62008-09-06 01:11:01 +00001231 if (Align == 0) {
1232 // Alignment of vector types. FIXME!
Dan Gohman1fbc3cd2008-09-18 18:26:43 +00001233 Align = TD.getABITypeSize(C->getType());
Owen Anderson3b217c62008-09-06 01:11:01 +00001234 Align = Log2_64(Align);
1235 }
Owen Anderson95267a12008-09-05 00:06:23 +00001236
Dan Gohman0586d912008-09-10 20:11:02 +00001237 unsigned MCPOffset = MCP.getConstantPoolIndex(C, Align);
Dan Gohman2ff7fd12008-09-19 22:16:54 +00001238 unsigned ResultReg = createResultReg(RC);
Owen Anderson95267a12008-09-05 00:06:23 +00001239 addConstantPoolReference(BuildMI(MBB, TII.get(Opc), ResultReg), MCPOffset);
Owen Anderson95267a12008-09-05 00:06:23 +00001240 return ResultReg;
1241}
1242
Dan Gohman0586d912008-09-10 20:11:02 +00001243unsigned X86FastISel::TargetMaterializeAlloca(AllocaInst *C) {
1244 X86AddressMode AM;
Dan Gohman2ff7fd12008-09-19 22:16:54 +00001245 if (!X86SelectAddress(C, AM, false))
Dan Gohman0586d912008-09-10 20:11:02 +00001246 return 0;
1247 unsigned Opc = Subtarget->is64Bit() ? X86::LEA64r : X86::LEA32r;
1248 TargetRegisterClass* RC = TLI.getRegClassFor(TLI.getPointerTy());
1249 unsigned ResultReg = createResultReg(RC);
1250 addFullAddress(BuildMI(MBB, TII.get(Opc), ResultReg), AM);
1251 return ResultReg;
1252}
1253
Evan Chengc3f44b02008-09-03 00:03:49 +00001254namespace llvm {
Dan Gohman3df24e62008-09-03 23:12:08 +00001255 llvm::FastISel *X86::createFastISel(MachineFunction &mf,
Dan Gohmand57dd5f2008-09-23 21:53:34 +00001256 MachineModuleInfo *mmi,
Dan Gohman3df24e62008-09-03 23:12:08 +00001257 DenseMap<const Value *, unsigned> &vm,
Dan Gohman0586d912008-09-10 20:11:02 +00001258 DenseMap<const BasicBlock *, MachineBasicBlock *> &bm,
1259 DenseMap<const AllocaInst *, int> &am) {
Dan Gohmand57dd5f2008-09-23 21:53:34 +00001260 return new X86FastISel(mf, mmi, vm, bm, am);
Evan Chengc3f44b02008-09-03 00:03:49 +00001261 }
Dan Gohman99b21822008-08-28 23:21:34 +00001262}