blob: 9ef20da92e9d70bd95c8d5021fa8602a3076b3b6 [file] [log] [blame]
Chris Lattner5930d3d2005-11-16 22:59:19 +00001//===- X86ISelDAGToDAG.cpp - A DAG pattern matching inst selector for X86 -===//
Chris Lattner655e7df2005-11-16 01:54:32 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by the Evan Cheng and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines a DAG pattern matching instruction selector for X86,
11// converting from a legalized dag to a X86 dag.
12//
13//===----------------------------------------------------------------------===//
14
Evan Chengd49cc362006-02-10 22:24:32 +000015#define DEBUG_TYPE "isel"
Chris Lattner655e7df2005-11-16 01:54:32 +000016#include "X86.h"
Evan Chengbc7a0f442006-01-11 06:09:51 +000017#include "X86InstrBuilder.h"
Chris Lattner7c551262006-01-11 01:15:34 +000018#include "X86RegisterInfo.h"
Chris Lattner655e7df2005-11-16 01:54:32 +000019#include "X86Subtarget.h"
20#include "X86ISelLowering.h"
Chris Lattner3f0f71b2005-11-19 02:11:08 +000021#include "llvm/GlobalValue.h"
Chris Lattner7c551262006-01-11 01:15:34 +000022#include "llvm/Instructions.h"
23#include "llvm/Support/CFG.h"
Chris Lattner3f0f71b2005-11-19 02:11:08 +000024#include "llvm/CodeGen/MachineConstantPool.h"
Chris Lattner655e7df2005-11-16 01:54:32 +000025#include "llvm/CodeGen/MachineFunction.h"
Evan Cheng73a1ad92006-01-10 20:26:56 +000026#include "llvm/CodeGen/MachineFrameInfo.h"
Chris Lattner7c551262006-01-11 01:15:34 +000027#include "llvm/CodeGen/MachineInstrBuilder.h"
28#include "llvm/CodeGen/SSARegMap.h"
Chris Lattner655e7df2005-11-16 01:54:32 +000029#include "llvm/CodeGen/SelectionDAGISel.h"
30#include "llvm/Target/TargetMachine.h"
31#include "llvm/Support/Debug.h"
32#include "llvm/ADT/Statistic.h"
Chris Lattnerde02d772006-01-22 23:41:00 +000033#include <iostream>
Evan Cheng54cb1832006-02-05 06:46:41 +000034#include <set>
Chris Lattner655e7df2005-11-16 01:54:32 +000035using namespace llvm;
36
37//===----------------------------------------------------------------------===//
38// Pattern Matcher Implementation
39//===----------------------------------------------------------------------===//
40
41namespace {
Chris Lattner3f0f71b2005-11-19 02:11:08 +000042 /// X86ISelAddressMode - This corresponds to X86AddressMode, but uses
43 /// SDOperand's instead of register numbers for the leaves of the matched
44 /// tree.
45 struct X86ISelAddressMode {
46 enum {
47 RegBase,
48 FrameIndexBase,
49 } BaseType;
50
51 struct { // This is really a union, discriminated by BaseType!
52 SDOperand Reg;
53 int FrameIndex;
54 } Base;
55
56 unsigned Scale;
57 SDOperand IndexReg;
58 unsigned Disp;
59 GlobalValue *GV;
Evan Cheng77d86ff2006-02-25 10:09:08 +000060 Constant *CP;
61 unsigned Align; // CP alignment.
Chris Lattner3f0f71b2005-11-19 02:11:08 +000062
63 X86ISelAddressMode()
Evan Cheng77d86ff2006-02-25 10:09:08 +000064 : BaseType(RegBase), Scale(1), IndexReg(), Disp(0), GV(0),
65 CP(0), Align(0) {
Chris Lattner3f0f71b2005-11-19 02:11:08 +000066 }
67 };
68}
69
70namespace {
Chris Lattner655e7df2005-11-16 01:54:32 +000071 Statistic<>
72 NumFPKill("x86-codegen", "Number of FP_REG_KILL instructions added");
73
74 //===--------------------------------------------------------------------===//
75 /// ISel - X86 specific code to select X86 machine instructions for
76 /// SelectionDAG operations.
77 ///
78 class X86DAGToDAGISel : public SelectionDAGISel {
79 /// ContainsFPCode - Every instruction we select that uses or defines a FP
80 /// register should set this to true.
81 bool ContainsFPCode;
82
83 /// X86Lowering - This object fully describes how to lower LLVM code to an
84 /// X86-specific SelectionDAG.
85 X86TargetLowering X86Lowering;
86
87 /// Subtarget - Keep a pointer to the X86Subtarget around so that we can
88 /// make the right decision when generating code for different targets.
89 const X86Subtarget *Subtarget;
Evan Cheng5588de92006-02-18 00:15:05 +000090
91 unsigned GlobalBaseReg;
Chris Lattner655e7df2005-11-16 01:54:32 +000092 public:
93 X86DAGToDAGISel(TargetMachine &TM)
94 : SelectionDAGISel(X86Lowering), X86Lowering(TM) {
95 Subtarget = &TM.getSubtarget<X86Subtarget>();
96 }
97
Evan Cheng5588de92006-02-18 00:15:05 +000098 virtual bool runOnFunction(Function &Fn) {
99 // Make sure we re-emit a set of the global base reg if necessary
100 GlobalBaseReg = 0;
101 return SelectionDAGISel::runOnFunction(Fn);
102 }
103
Chris Lattner655e7df2005-11-16 01:54:32 +0000104 virtual const char *getPassName() const {
105 return "X86 DAG->DAG Instruction Selection";
106 }
107
108 /// InstructionSelectBasicBlock - This callback is invoked by
109 /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
110 virtual void InstructionSelectBasicBlock(SelectionDAG &DAG);
111
Evan Chengbc7a0f442006-01-11 06:09:51 +0000112 virtual void EmitFunctionEntryCode(Function &Fn, MachineFunction &MF);
113
Chris Lattner655e7df2005-11-16 01:54:32 +0000114// Include the pieces autogenerated from the target description.
115#include "X86GenDAGISel.inc"
116
117 private:
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000118 void Select(SDOperand &Result, SDOperand N);
Chris Lattner655e7df2005-11-16 01:54:32 +0000119
Evan Chenga86ba852006-02-11 02:05:36 +0000120 bool MatchAddress(SDOperand N, X86ISelAddressMode &AM, bool isRoot = true);
Evan Chengc9fab312005-12-08 02:01:35 +0000121 bool SelectAddr(SDOperand N, SDOperand &Base, SDOperand &Scale,
122 SDOperand &Index, SDOperand &Disp);
123 bool SelectLEAAddr(SDOperand N, SDOperand &Base, SDOperand &Scale,
124 SDOperand &Index, SDOperand &Disp);
Evan Chengd5f2ba02006-02-06 06:02:33 +0000125 bool TryFoldLoad(SDOperand P, SDOperand N,
126 SDOperand &Base, SDOperand &Scale,
Evan Cheng10d27902006-01-06 20:36:21 +0000127 SDOperand &Index, SDOperand &Disp);
Chris Lattner3f0f71b2005-11-19 02:11:08 +0000128
Evan Cheng67ed58e2005-12-12 21:49:40 +0000129 inline void getAddressOperands(X86ISelAddressMode &AM, SDOperand &Base,
130 SDOperand &Scale, SDOperand &Index,
131 SDOperand &Disp) {
132 Base = (AM.BaseType == X86ISelAddressMode::FrameIndexBase) ?
133 CurDAG->getTargetFrameIndex(AM.Base.FrameIndex, MVT::i32) : AM.Base.Reg;
Evan Cheng1d712482005-12-17 09:13:43 +0000134 Scale = getI8Imm(AM.Scale);
Evan Cheng67ed58e2005-12-12 21:49:40 +0000135 Index = AM.IndexReg;
136 Disp = AM.GV ? CurDAG->getTargetGlobalAddress(AM.GV, MVT::i32, AM.Disp)
Evan Cheng77d86ff2006-02-25 10:09:08 +0000137 : (AM.CP ?
138 CurDAG->getTargetConstantPool(AM.CP, MVT::i32, AM.Align, AM.Disp)
139 : getI32Imm(AM.Disp));
Evan Cheng67ed58e2005-12-12 21:49:40 +0000140 }
141
Chris Lattner3f0f71b2005-11-19 02:11:08 +0000142 /// getI8Imm - Return a target constant with the specified value, of type
143 /// i8.
144 inline SDOperand getI8Imm(unsigned Imm) {
145 return CurDAG->getTargetConstant(Imm, MVT::i8);
146 }
147
Chris Lattner655e7df2005-11-16 01:54:32 +0000148 /// getI16Imm - Return a target constant with the specified value, of type
149 /// i16.
150 inline SDOperand getI16Imm(unsigned Imm) {
151 return CurDAG->getTargetConstant(Imm, MVT::i16);
152 }
153
154 /// getI32Imm - Return a target constant with the specified value, of type
155 /// i32.
156 inline SDOperand getI32Imm(unsigned Imm) {
157 return CurDAG->getTargetConstant(Imm, MVT::i32);
158 }
Evan Chengd49cc362006-02-10 22:24:32 +0000159
Evan Cheng5588de92006-02-18 00:15:05 +0000160 /// getGlobalBaseReg - insert code into the entry mbb to materialize the PIC
161 /// base register. Return the virtual register that holds this value.
162 SDOperand getGlobalBaseReg();
163
Evan Cheng2b6f78b2006-02-10 22:46:26 +0000164#ifndef NDEBUG
165 unsigned Indent;
166#endif
Chris Lattner655e7df2005-11-16 01:54:32 +0000167 };
168}
169
170/// InstructionSelectBasicBlock - This callback is invoked by SelectionDAGISel
171/// when it has created a SelectionDAG for us to codegen.
172void X86DAGToDAGISel::InstructionSelectBasicBlock(SelectionDAG &DAG) {
173 DEBUG(BB->dump());
Chris Lattner7c551262006-01-11 01:15:34 +0000174 MachineFunction::iterator FirstMBB = BB;
Chris Lattner655e7df2005-11-16 01:54:32 +0000175
176 // Codegen the basic block.
Evan Chengd49cc362006-02-10 22:24:32 +0000177#ifndef NDEBUG
178 DEBUG(std::cerr << "===== Instruction selection begins:\n");
Evan Cheng2b6f78b2006-02-10 22:46:26 +0000179 Indent = 0;
Evan Chengd49cc362006-02-10 22:24:32 +0000180#endif
Evan Cheng54cb1832006-02-05 06:46:41 +0000181 DAG.setRoot(SelectRoot(DAG.getRoot()));
Evan Chengd49cc362006-02-10 22:24:32 +0000182#ifndef NDEBUG
183 DEBUG(std::cerr << "===== Instruction selection ends:\n");
184#endif
Evan Cheng1d9b6712005-12-19 22:36:02 +0000185 CodeGenMap.clear();
Chris Lattner655e7df2005-11-16 01:54:32 +0000186 DAG.RemoveDeadNodes();
187
188 // Emit machine code to BB.
189 ScheduleAndEmitDAG(DAG);
Chris Lattner7c551262006-01-11 01:15:34 +0000190
191 // If we are emitting FP stack code, scan the basic block to determine if this
192 // block defines any FP values. If so, put an FP_REG_KILL instruction before
193 // the terminator of the block.
Evan Chengcde9e302006-01-27 08:10:46 +0000194 if (!Subtarget->hasSSE2()) {
Chris Lattner7c551262006-01-11 01:15:34 +0000195 // Note that FP stack instructions *are* used in SSE code when returning
196 // values, but these are not live out of the basic block, so we don't need
197 // an FP_REG_KILL in this case either.
198 bool ContainsFPCode = false;
199
200 // Scan all of the machine instructions in these MBBs, checking for FP
201 // stores.
202 MachineFunction::iterator MBBI = FirstMBB;
203 do {
204 for (MachineBasicBlock::iterator I = MBBI->begin(), E = MBBI->end();
205 !ContainsFPCode && I != E; ++I) {
206 for (unsigned op = 0, e = I->getNumOperands(); op != e; ++op) {
207 if (I->getOperand(op).isRegister() && I->getOperand(op).isDef() &&
208 MRegisterInfo::isVirtualRegister(I->getOperand(op).getReg()) &&
209 RegMap->getRegClass(I->getOperand(0).getReg()) ==
210 X86::RFPRegisterClass) {
211 ContainsFPCode = true;
212 break;
213 }
214 }
215 }
216 } while (!ContainsFPCode && &*(MBBI++) != BB);
217
218 // Check PHI nodes in successor blocks. These PHI's will be lowered to have
219 // a copy of the input value in this block.
220 if (!ContainsFPCode) {
221 // Final check, check LLVM BB's that are successors to the LLVM BB
222 // corresponding to BB for FP PHI nodes.
223 const BasicBlock *LLVMBB = BB->getBasicBlock();
224 const PHINode *PN;
225 for (succ_const_iterator SI = succ_begin(LLVMBB), E = succ_end(LLVMBB);
226 !ContainsFPCode && SI != E; ++SI) {
227 for (BasicBlock::const_iterator II = SI->begin();
228 (PN = dyn_cast<PHINode>(II)); ++II) {
229 if (PN->getType()->isFloatingPoint()) {
230 ContainsFPCode = true;
231 break;
232 }
233 }
234 }
235 }
236
237 // Finally, if we found any FP code, emit the FP_REG_KILL instruction.
238 if (ContainsFPCode) {
239 BuildMI(*BB, BB->getFirstTerminator(), X86::FP_REG_KILL, 0);
240 ++NumFPKill;
241 }
242 }
Chris Lattner655e7df2005-11-16 01:54:32 +0000243}
244
Evan Chengbc7a0f442006-01-11 06:09:51 +0000245/// EmitSpecialCodeForMain - Emit any code that needs to be executed only in
246/// the main function.
247static void EmitSpecialCodeForMain(MachineBasicBlock *BB,
248 MachineFrameInfo *MFI) {
249 // Switch the FPU to 64-bit precision mode for better compatibility and speed.
250 int CWFrameIdx = MFI->CreateStackObject(2, 2);
251 addFrameReference(BuildMI(BB, X86::FNSTCW16m, 4), CWFrameIdx);
252
253 // Set the high part to be 64-bit precision.
254 addFrameReference(BuildMI(BB, X86::MOV8mi, 5),
255 CWFrameIdx, 1).addImm(2);
256
257 // Reload the modified control word now.
258 addFrameReference(BuildMI(BB, X86::FLDCW16m, 4), CWFrameIdx);
259}
260
261void X86DAGToDAGISel::EmitFunctionEntryCode(Function &Fn, MachineFunction &MF) {
262 // If this is main, emit special code for main.
263 MachineBasicBlock *BB = MF.begin();
264 if (Fn.hasExternalLinkage() && Fn.getName() == "main")
265 EmitSpecialCodeForMain(BB, MF.getFrameInfo());
266}
267
Chris Lattner3f0f71b2005-11-19 02:11:08 +0000268/// MatchAddress - Add the specified node to the specified addressing mode,
269/// returning true if it cannot be done. This just pattern matches for the
270/// addressing mode
Evan Chenga86ba852006-02-11 02:05:36 +0000271bool X86DAGToDAGISel::MatchAddress(SDOperand N, X86ISelAddressMode &AM,
272 bool isRoot) {
Evan Cheng77d86ff2006-02-25 10:09:08 +0000273 bool Available = false;
274 // If N has already been selected, reuse the result unless in some very
275 // specific cases.
Evan Chenga86ba852006-02-11 02:05:36 +0000276 std::map<SDOperand, SDOperand>::iterator CGMI= CodeGenMap.find(N.getValue(0));
277 if (CGMI != CodeGenMap.end()) {
Evan Cheng77d86ff2006-02-25 10:09:08 +0000278 Available = true;
Evan Chenga86ba852006-02-11 02:05:36 +0000279 }
280
Chris Lattner3f0f71b2005-11-19 02:11:08 +0000281 switch (N.getOpcode()) {
282 default: break;
Evan Cheng77d86ff2006-02-25 10:09:08 +0000283 case ISD::Constant:
284 AM.Disp += cast<ConstantSDNode>(N)->getValue();
285 return false;
286
287 case X86ISD::Wrapper:
288 // If both base and index components have been picked, we can't fit
289 // the result available in the register in the addressing mode. Duplicate
290 // GlobalAddress or ConstantPool as displacement.
291 if (!Available || (AM.Base.Reg.Val && AM.IndexReg.Val)) {
292 if (ConstantPoolSDNode *CP =
293 dyn_cast<ConstantPoolSDNode>(N.getOperand(0))) {
294 if (AM.CP == 0) {
295 AM.CP = CP->get();
296 AM.Align = CP->getAlignment();
297 AM.Disp += CP->getOffset();
298 return false;
299 }
300 } else if (GlobalAddressSDNode *G =
301 dyn_cast<GlobalAddressSDNode>(N.getOperand(0))) {
302 if (AM.GV == 0) {
303 AM.GV = G->getGlobal();
304 AM.Disp += G->getOffset();
305 return false;
306 }
307 }
308 }
309 break;
310
Chris Lattner3f0f71b2005-11-19 02:11:08 +0000311 case ISD::FrameIndex:
312 if (AM.BaseType == X86ISelAddressMode::RegBase && AM.Base.Reg.Val == 0) {
313 AM.BaseType = X86ISelAddressMode::FrameIndexBase;
314 AM.Base.FrameIndex = cast<FrameIndexSDNode>(N)->getIndex();
315 return false;
316 }
317 break;
Evan Chengc9fab312005-12-08 02:01:35 +0000318
Chris Lattner3f0f71b2005-11-19 02:11:08 +0000319 case ISD::SHL:
Evan Cheng77d86ff2006-02-25 10:09:08 +0000320 if (!Available && AM.IndexReg.Val == 0 && AM.Scale == 1)
Chris Lattner3f0f71b2005-11-19 02:11:08 +0000321 if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N.Val->getOperand(1))) {
322 unsigned Val = CN->getValue();
323 if (Val == 1 || Val == 2 || Val == 3) {
324 AM.Scale = 1 << Val;
325 SDOperand ShVal = N.Val->getOperand(0);
326
327 // Okay, we know that we have a scale by now. However, if the scaled
328 // value is an add of something and a constant, we can fold the
329 // constant into the disp field here.
330 if (ShVal.Val->getOpcode() == ISD::ADD && ShVal.hasOneUse() &&
331 isa<ConstantSDNode>(ShVal.Val->getOperand(1))) {
332 AM.IndexReg = ShVal.Val->getOperand(0);
333 ConstantSDNode *AddVal =
334 cast<ConstantSDNode>(ShVal.Val->getOperand(1));
335 AM.Disp += AddVal->getValue() << Val;
336 } else {
337 AM.IndexReg = ShVal;
338 }
339 return false;
340 }
341 }
342 break;
Evan Chengc9fab312005-12-08 02:01:35 +0000343
Chris Lattner3f0f71b2005-11-19 02:11:08 +0000344 case ISD::MUL:
345 // X*[3,5,9] -> X+X*[2,4,8]
Evan Cheng77d86ff2006-02-25 10:09:08 +0000346 if (!Available &&
347 AM.BaseType == X86ISelAddressMode::RegBase &&
348 AM.Base.Reg.Val == 0 &&
349 AM.IndexReg.Val == 0)
Chris Lattner3f0f71b2005-11-19 02:11:08 +0000350 if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N.Val->getOperand(1)))
351 if (CN->getValue() == 3 || CN->getValue() == 5 || CN->getValue() == 9) {
352 AM.Scale = unsigned(CN->getValue())-1;
353
354 SDOperand MulVal = N.Val->getOperand(0);
355 SDOperand Reg;
356
357 // Okay, we know that we have a scale by now. However, if the scaled
358 // value is an add of something and a constant, we can fold the
359 // constant into the disp field here.
360 if (MulVal.Val->getOpcode() == ISD::ADD && MulVal.hasOneUse() &&
361 isa<ConstantSDNode>(MulVal.Val->getOperand(1))) {
362 Reg = MulVal.Val->getOperand(0);
363 ConstantSDNode *AddVal =
364 cast<ConstantSDNode>(MulVal.Val->getOperand(1));
365 AM.Disp += AddVal->getValue() * CN->getValue();
366 } else {
367 Reg = N.Val->getOperand(0);
368 }
369
370 AM.IndexReg = AM.Base.Reg = Reg;
371 return false;
372 }
373 break;
374
375 case ISD::ADD: {
Evan Cheng77d86ff2006-02-25 10:09:08 +0000376 if (!Available) {
Evan Chenga86ba852006-02-11 02:05:36 +0000377 X86ISelAddressMode Backup = AM;
378 if (!MatchAddress(N.Val->getOperand(0), AM, false) &&
379 !MatchAddress(N.Val->getOperand(1), AM, false))
380 return false;
381 AM = Backup;
382 if (!MatchAddress(N.Val->getOperand(1), AM, false) &&
383 !MatchAddress(N.Val->getOperand(0), AM, false))
384 return false;
385 AM = Backup;
386 }
Chris Lattner3f0f71b2005-11-19 02:11:08 +0000387 break;
388 }
389 }
390
391 // Is the base register already occupied?
392 if (AM.BaseType != X86ISelAddressMode::RegBase || AM.Base.Reg.Val) {
393 // If so, check to see if the scale index register is set.
394 if (AM.IndexReg.Val == 0) {
395 AM.IndexReg = N;
396 AM.Scale = 1;
397 return false;
398 }
399
400 // Otherwise, we cannot select it.
401 return true;
402 }
403
404 // Default, generate it as a register.
405 AM.BaseType = X86ISelAddressMode::RegBase;
406 AM.Base.Reg = N;
407 return false;
408}
409
Evan Chengc9fab312005-12-08 02:01:35 +0000410/// SelectAddr - returns true if it is able pattern match an addressing mode.
411/// It returns the operands which make up the maximal addressing mode it can
412/// match by reference.
413bool X86DAGToDAGISel::SelectAddr(SDOperand N, SDOperand &Base, SDOperand &Scale,
414 SDOperand &Index, SDOperand &Disp) {
415 X86ISelAddressMode AM;
Evan Chengbc7a0f442006-01-11 06:09:51 +0000416 if (MatchAddress(N, AM))
417 return false;
Evan Chengc9fab312005-12-08 02:01:35 +0000418
Evan Chengbc7a0f442006-01-11 06:09:51 +0000419 if (AM.BaseType == X86ISelAddressMode::RegBase) {
Evan Chengd19d51f2006-02-05 05:25:07 +0000420 if (!AM.Base.Reg.Val)
Evan Chengbc7a0f442006-01-11 06:09:51 +0000421 AM.Base.Reg = CurDAG->getRegister(0, MVT::i32);
Evan Chengc9fab312005-12-08 02:01:35 +0000422 }
Evan Chengbc7a0f442006-01-11 06:09:51 +0000423
Evan Chengd19d51f2006-02-05 05:25:07 +0000424 if (!AM.IndexReg.Val)
Evan Chengbc7a0f442006-01-11 06:09:51 +0000425 AM.IndexReg = CurDAG->getRegister(0, MVT::i32);
426
427 getAddressOperands(AM, Base, Scale, Index, Disp);
Evan Cheng77d86ff2006-02-25 10:09:08 +0000428
Evan Chengbc7a0f442006-01-11 06:09:51 +0000429 return true;
Evan Chengc9fab312005-12-08 02:01:35 +0000430}
431
Evan Cheng77d86ff2006-02-25 10:09:08 +0000432/// SelectLEAAddr - it calls SelectAddr and determines if the maximal addressing
433/// mode it matches can be cost effectively emitted as an LEA instruction.
434/// For X86, it always is unless it's just a (Reg + const).
435bool X86DAGToDAGISel::SelectLEAAddr(SDOperand N, SDOperand &Base,
436 SDOperand &Scale,
437 SDOperand &Index, SDOperand &Disp) {
438 X86ISelAddressMode AM;
439 if (MatchAddress(N, AM))
440 return false;
441
442 unsigned Complexity = 0;
443 if (AM.BaseType == X86ISelAddressMode::RegBase)
444 if (AM.Base.Reg.Val)
445 Complexity = 1;
446 else
447 AM.Base.Reg = CurDAG->getRegister(0, MVT::i32);
448 else if (AM.BaseType == X86ISelAddressMode::FrameIndexBase)
449 Complexity = 4;
450
451 if (AM.IndexReg.Val)
452 Complexity++;
453 else
454 AM.IndexReg = CurDAG->getRegister(0, MVT::i32);
455
456 if (AM.Scale > 1)
457 Complexity += 2;
458
459 // FIXME: We are artificially lowering the criteria to turn ADD %reg, $GA
460 // to a LEA. This is determined with some expermentation but is by no means
461 // optimal (especially for code size consideration). LEA is nice because of
462 // its three-address nature. Tweak the cost function again when we can run
463 // convertToThreeAddress() at register allocation time.
464 if (AM.GV || AM.CP)
465 Complexity += 2;
466
467 if (AM.Disp && (AM.Base.Reg.Val || AM.IndexReg.Val))
468 Complexity++;
469
470 if (Complexity > 2) {
471 getAddressOperands(AM, Base, Scale, Index, Disp);
472 return true;
473 }
474
475 return false;
476}
477
Evan Chengd5f2ba02006-02-06 06:02:33 +0000478bool X86DAGToDAGISel::TryFoldLoad(SDOperand P, SDOperand N,
479 SDOperand &Base, SDOperand &Scale,
480 SDOperand &Index, SDOperand &Disp) {
481 if (N.getOpcode() == ISD::LOAD &&
482 N.hasOneUse() &&
483 !CodeGenMap.count(N.getValue(0)) &&
484 (P.getNumOperands() == 1 || !isNonImmUse(P.Val, N.Val)))
Evan Cheng10d27902006-01-06 20:36:21 +0000485 return SelectAddr(N.getOperand(1), Base, Scale, Index, Disp);
486 return false;
487}
488
489static bool isRegister0(SDOperand Op) {
Evan Chengc9fab312005-12-08 02:01:35 +0000490 if (RegisterSDNode *R = dyn_cast<RegisterSDNode>(Op))
491 return (R->getReg() == 0);
492 return false;
493}
494
Evan Cheng5588de92006-02-18 00:15:05 +0000495/// getGlobalBaseReg - Output the instructions required to put the
496/// base address to use for accessing globals into a register.
497///
498SDOperand X86DAGToDAGISel::getGlobalBaseReg() {
499 if (!GlobalBaseReg) {
500 // Insert the set of GlobalBaseReg into the first MBB of the function
501 MachineBasicBlock &FirstMBB = BB->getParent()->front();
502 MachineBasicBlock::iterator MBBI = FirstMBB.begin();
503 SSARegMap *RegMap = BB->getParent()->getSSARegMap();
504 // FIXME: when we get to LP64, we will need to create the appropriate
505 // type of register here.
506 GlobalBaseReg = RegMap->createVirtualRegister(X86::R32RegisterClass);
507 BuildMI(FirstMBB, MBBI, X86::MovePCtoStack, 0);
508 BuildMI(FirstMBB, MBBI, X86::POP32r, 1, GlobalBaseReg);
509 }
510 return CurDAG->getRegister(GlobalBaseReg, MVT::i32);
511}
512
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000513void X86DAGToDAGISel::Select(SDOperand &Result, SDOperand N) {
Evan Cheng00fcb002005-12-15 01:02:48 +0000514 SDNode *Node = N.Val;
515 MVT::ValueType NVT = Node->getValueType(0);
Evan Cheng10d27902006-01-06 20:36:21 +0000516 unsigned Opc, MOpc;
517 unsigned Opcode = Node->getOpcode();
Chris Lattner655e7df2005-11-16 01:54:32 +0000518
Evan Chengd49cc362006-02-10 22:24:32 +0000519#ifndef NDEBUG
Evan Cheng2b6f78b2006-02-10 22:46:26 +0000520 DEBUG(std::cerr << std::string(Indent, ' '));
Evan Chengd49cc362006-02-10 22:24:32 +0000521 DEBUG(std::cerr << "Selecting: ");
522 DEBUG(Node->dump(CurDAG));
523 DEBUG(std::cerr << "\n");
Evan Cheng2b6f78b2006-02-10 22:46:26 +0000524 Indent += 2;
Evan Chengd49cc362006-02-10 22:24:32 +0000525#endif
526
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000527 if (Opcode >= ISD::BUILTIN_OP_END && Opcode < X86ISD::FIRST_NUMBER) {
528 Result = N;
Evan Chengd49cc362006-02-10 22:24:32 +0000529#ifndef NDEBUG
Evan Chenga86ba852006-02-11 02:05:36 +0000530 DEBUG(std::cerr << std::string(Indent-2, ' '));
Evan Chengd49cc362006-02-10 22:24:32 +0000531 DEBUG(std::cerr << "== ");
532 DEBUG(Node->dump(CurDAG));
533 DEBUG(std::cerr << "\n");
Evan Cheng2b6f78b2006-02-10 22:46:26 +0000534 Indent -= 2;
Evan Chengd49cc362006-02-10 22:24:32 +0000535#endif
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000536 return; // Already selected.
537 }
Evan Cheng2ae799a2006-01-11 22:15:18 +0000538
539 std::map<SDOperand, SDOperand>::iterator CGMI = CodeGenMap.find(N);
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000540 if (CGMI != CodeGenMap.end()) {
541 Result = CGMI->second;
Evan Chengd49cc362006-02-10 22:24:32 +0000542#ifndef NDEBUG
Evan Chenga86ba852006-02-11 02:05:36 +0000543 DEBUG(std::cerr << std::string(Indent-2, ' '));
Evan Chengd49cc362006-02-10 22:24:32 +0000544 DEBUG(std::cerr << "== ");
545 DEBUG(Result.Val->dump(CurDAG));
546 DEBUG(std::cerr << "\n");
Evan Cheng2b6f78b2006-02-10 22:46:26 +0000547 Indent -= 2;
Evan Chengd49cc362006-02-10 22:24:32 +0000548#endif
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000549 return;
550 }
Chris Lattner655e7df2005-11-16 01:54:32 +0000551
Evan Cheng10d27902006-01-06 20:36:21 +0000552 switch (Opcode) {
Chris Lattner655e7df2005-11-16 01:54:32 +0000553 default: break;
Evan Chenge0ed6ec2006-02-23 20:41:18 +0000554 case X86ISD::GlobalBaseReg:
555 Result = getGlobalBaseReg();
556 return;
557
Evan Cheng77d86ff2006-02-25 10:09:08 +0000558 case ISD::ADD: {
559 // Turn ADD X, c to MOV32ri X+c. This cannot be done with tblgen'd
560 // code and is matched first so to prevent it from being turned into
561 // LEA32r X+c.
562 SDOperand N0 = N.getOperand(0);
563 SDOperand N1 = N.getOperand(1);
564 if (N.Val->getValueType(0) == MVT::i32 &&
565 N0.getOpcode() == X86ISD::Wrapper &&
566 N1.getOpcode() == ISD::Constant) {
567 unsigned Offset = (unsigned)cast<ConstantSDNode>(N1)->getValue();
568 SDOperand C(0, 0);
569 // TODO: handle ExternalSymbolSDNode.
570 if (GlobalAddressSDNode *G =
571 dyn_cast<GlobalAddressSDNode>(N0.getOperand(0))) {
572 C = CurDAG->getTargetGlobalAddress(G->getGlobal(), MVT::i32,
573 G->getOffset() + Offset);
574 } else if (ConstantPoolSDNode *CP =
575 dyn_cast<ConstantPoolSDNode>(N0.getOperand(0))) {
576 C = CurDAG->getTargetConstantPool(CP->get(), MVT::i32,
577 CP->getAlignment(),
578 CP->getOffset()+Offset);
579 }
580
581 if (C.Val) {
582 if (N.Val->hasOneUse()) {
583 Result = CurDAG->SelectNodeTo(N.Val, X86::MOV32ri, MVT::i32, C);
584 } else {
585 SDNode *ResNode = CurDAG->getTargetNode(X86::MOV32ri, MVT::i32, C);
586 Result = CodeGenMap[N] = SDOperand(ResNode, 0);
587 }
588 return;
589 }
590 }
591
592 // Other cases are handled by auto-generated code.
593 break;
Evan Cheng1f342c22006-02-23 02:43:52 +0000594 }
Evan Chenge0ed6ec2006-02-23 20:41:18 +0000595
Evan Cheng10d27902006-01-06 20:36:21 +0000596 case ISD::MULHU:
597 case ISD::MULHS: {
598 if (Opcode == ISD::MULHU)
599 switch (NVT) {
600 default: assert(0 && "Unsupported VT!");
601 case MVT::i8: Opc = X86::MUL8r; MOpc = X86::MUL8m; break;
602 case MVT::i16: Opc = X86::MUL16r; MOpc = X86::MUL16m; break;
603 case MVT::i32: Opc = X86::MUL32r; MOpc = X86::MUL32m; break;
604 }
605 else
606 switch (NVT) {
607 default: assert(0 && "Unsupported VT!");
608 case MVT::i8: Opc = X86::IMUL8r; MOpc = X86::IMUL8m; break;
609 case MVT::i16: Opc = X86::IMUL16r; MOpc = X86::IMUL16m; break;
610 case MVT::i32: Opc = X86::IMUL32r; MOpc = X86::IMUL32m; break;
611 }
612
613 unsigned LoReg, HiReg;
614 switch (NVT) {
615 default: assert(0 && "Unsupported VT!");
616 case MVT::i8: LoReg = X86::AL; HiReg = X86::AH; break;
617 case MVT::i16: LoReg = X86::AX; HiReg = X86::DX; break;
618 case MVT::i32: LoReg = X86::EAX; HiReg = X86::EDX; break;
619 }
620
621 SDOperand N0 = Node->getOperand(0);
622 SDOperand N1 = Node->getOperand(1);
623
624 bool foldedLoad = false;
625 SDOperand Tmp0, Tmp1, Tmp2, Tmp3;
Evan Chengd5f2ba02006-02-06 06:02:33 +0000626 foldedLoad = TryFoldLoad(N, N1, Tmp0, Tmp1, Tmp2, Tmp3);
Evan Cheng92e27972006-01-06 23:19:29 +0000627 // MULHU and MULHS are commmutative
628 if (!foldedLoad) {
Evan Chengd5f2ba02006-02-06 06:02:33 +0000629 foldedLoad = TryFoldLoad(N, N0, Tmp0, Tmp1, Tmp2, Tmp3);
Evan Cheng92e27972006-01-06 23:19:29 +0000630 if (foldedLoad) {
631 N0 = Node->getOperand(1);
632 N1 = Node->getOperand(0);
633 }
634 }
635
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000636 SDOperand Chain;
637 if (foldedLoad)
638 Select(Chain, N1.getOperand(0));
639 else
640 Chain = CurDAG->getEntryNode();
Evan Cheng10d27902006-01-06 20:36:21 +0000641
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000642 SDOperand InFlag(0, 0);
643 Select(N0, N0);
Evan Cheng10d27902006-01-06 20:36:21 +0000644 Chain = CurDAG->getCopyToReg(Chain, CurDAG->getRegister(LoReg, NVT),
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000645 N0, InFlag);
Evan Cheng10d27902006-01-06 20:36:21 +0000646 InFlag = Chain.getValue(1);
647
648 if (foldedLoad) {
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000649 Select(Tmp0, Tmp0);
650 Select(Tmp1, Tmp1);
651 Select(Tmp2, Tmp2);
652 Select(Tmp3, Tmp3);
Evan Chengd1b82d82006-02-09 07:17:49 +0000653 SDNode *CNode =
654 CurDAG->getTargetNode(MOpc, MVT::Other, MVT::Flag, Tmp0, Tmp1,
655 Tmp2, Tmp3, Chain, InFlag);
656 Chain = SDOperand(CNode, 0);
657 InFlag = SDOperand(CNode, 1);
Evan Cheng10d27902006-01-06 20:36:21 +0000658 } else {
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000659 Select(N1, N1);
Evan Chengd1b82d82006-02-09 07:17:49 +0000660 InFlag =
661 SDOperand(CurDAG->getTargetNode(Opc, MVT::Flag, N1, InFlag), 0);
Evan Cheng10d27902006-01-06 20:36:21 +0000662 }
663
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000664 Result = CurDAG->getCopyFromReg(Chain, HiReg, NVT, InFlag);
Evan Cheng10d27902006-01-06 20:36:21 +0000665 CodeGenMap[N.getValue(0)] = Result;
Evan Chengd5f2ba02006-02-06 06:02:33 +0000666 if (foldedLoad) {
Evan Cheng92e27972006-01-06 23:19:29 +0000667 CodeGenMap[N1.getValue(1)] = Result.getValue(1);
Evan Cheng101e4b92006-02-09 22:12:53 +0000668 AddHandleReplacement(N1.Val, 1, Result.Val, 1);
Evan Chengd5f2ba02006-02-06 06:02:33 +0000669 }
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000670
Evan Chengd49cc362006-02-10 22:24:32 +0000671#ifndef NDEBUG
Evan Chenga86ba852006-02-11 02:05:36 +0000672 DEBUG(std::cerr << std::string(Indent-2, ' '));
Evan Chengd49cc362006-02-10 22:24:32 +0000673 DEBUG(std::cerr << "== ");
674 DEBUG(Result.Val->dump(CurDAG));
675 DEBUG(std::cerr << "\n");
Evan Cheng2b6f78b2006-02-10 22:46:26 +0000676 Indent -= 2;
Evan Chengd49cc362006-02-10 22:24:32 +0000677#endif
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000678 return;
Evan Cheng92e27972006-01-06 23:19:29 +0000679 }
Evan Cheng5588de92006-02-18 00:15:05 +0000680
Evan Cheng92e27972006-01-06 23:19:29 +0000681 case ISD::SDIV:
682 case ISD::UDIV:
683 case ISD::SREM:
684 case ISD::UREM: {
685 bool isSigned = Opcode == ISD::SDIV || Opcode == ISD::SREM;
686 bool isDiv = Opcode == ISD::SDIV || Opcode == ISD::UDIV;
687 if (!isSigned)
688 switch (NVT) {
689 default: assert(0 && "Unsupported VT!");
690 case MVT::i8: Opc = X86::DIV8r; MOpc = X86::DIV8m; break;
691 case MVT::i16: Opc = X86::DIV16r; MOpc = X86::DIV16m; break;
692 case MVT::i32: Opc = X86::DIV32r; MOpc = X86::DIV32m; break;
693 }
694 else
695 switch (NVT) {
696 default: assert(0 && "Unsupported VT!");
697 case MVT::i8: Opc = X86::IDIV8r; MOpc = X86::IDIV8m; break;
698 case MVT::i16: Opc = X86::IDIV16r; MOpc = X86::IDIV16m; break;
699 case MVT::i32: Opc = X86::IDIV32r; MOpc = X86::IDIV32m; break;
700 }
701
702 unsigned LoReg, HiReg;
703 unsigned ClrOpcode, SExtOpcode;
704 switch (NVT) {
705 default: assert(0 && "Unsupported VT!");
706 case MVT::i8:
707 LoReg = X86::AL; HiReg = X86::AH;
708 ClrOpcode = X86::MOV8ri;
709 SExtOpcode = X86::CBW;
710 break;
711 case MVT::i16:
712 LoReg = X86::AX; HiReg = X86::DX;
713 ClrOpcode = X86::MOV16ri;
714 SExtOpcode = X86::CWD;
715 break;
716 case MVT::i32:
717 LoReg = X86::EAX; HiReg = X86::EDX;
718 ClrOpcode = X86::MOV32ri;
719 SExtOpcode = X86::CDQ;
720 break;
721 }
722
723 SDOperand N0 = Node->getOperand(0);
724 SDOperand N1 = Node->getOperand(1);
725
726 bool foldedLoad = false;
727 SDOperand Tmp0, Tmp1, Tmp2, Tmp3;
Evan Chengd5f2ba02006-02-06 06:02:33 +0000728 foldedLoad = TryFoldLoad(N, N1, Tmp0, Tmp1, Tmp2, Tmp3);
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000729 SDOperand Chain;
730 if (foldedLoad)
731 Select(Chain, N1.getOperand(0));
732 else
733 Chain = CurDAG->getEntryNode();
Evan Cheng92e27972006-01-06 23:19:29 +0000734
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000735 SDOperand InFlag(0, 0);
736 Select(N0, N0);
Evan Cheng92e27972006-01-06 23:19:29 +0000737 Chain = CurDAG->getCopyToReg(Chain, CurDAG->getRegister(LoReg, NVT),
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000738 N0, InFlag);
Evan Cheng92e27972006-01-06 23:19:29 +0000739 InFlag = Chain.getValue(1);
740
741 if (isSigned) {
742 // Sign extend the low part into the high part.
Evan Chengd1b82d82006-02-09 07:17:49 +0000743 InFlag =
744 SDOperand(CurDAG->getTargetNode(SExtOpcode, MVT::Flag, InFlag), 0);
Evan Cheng92e27972006-01-06 23:19:29 +0000745 } else {
746 // Zero out the high part, effectively zero extending the input.
747 SDOperand ClrNode =
Evan Chengd1b82d82006-02-09 07:17:49 +0000748 SDOperand(CurDAG->getTargetNode(ClrOpcode, NVT,
749 CurDAG->getTargetConstant(0, NVT)), 0);
Evan Cheng92e27972006-01-06 23:19:29 +0000750 Chain = CurDAG->getCopyToReg(Chain, CurDAG->getRegister(HiReg, NVT),
751 ClrNode, InFlag);
752 InFlag = Chain.getValue(1);
753 }
754
755 if (foldedLoad) {
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000756 Select(Tmp0, Tmp0);
757 Select(Tmp1, Tmp1);
758 Select(Tmp2, Tmp2);
759 Select(Tmp3, Tmp3);
Evan Chengd1b82d82006-02-09 07:17:49 +0000760 SDNode *CNode =
761 CurDAG->getTargetNode(MOpc, MVT::Other, MVT::Flag, Tmp0, Tmp1,
762 Tmp2, Tmp3, Chain, InFlag);
763 Chain = SDOperand(CNode, 0);
764 InFlag = SDOperand(CNode, 1);
Evan Cheng92e27972006-01-06 23:19:29 +0000765 } else {
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000766 Select(N1, N1);
Evan Chengd1b82d82006-02-09 07:17:49 +0000767 InFlag =
768 SDOperand(CurDAG->getTargetNode(Opc, MVT::Flag, N1, InFlag), 0);
Evan Cheng92e27972006-01-06 23:19:29 +0000769 }
770
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000771 Result = CurDAG->getCopyFromReg(Chain, isDiv ? LoReg : HiReg,
772 NVT, InFlag);
Evan Cheng92e27972006-01-06 23:19:29 +0000773 CodeGenMap[N.getValue(0)] = Result;
Evan Chengd5f2ba02006-02-06 06:02:33 +0000774 if (foldedLoad) {
Evan Cheng92e27972006-01-06 23:19:29 +0000775 CodeGenMap[N1.getValue(1)] = Result.getValue(1);
Evan Cheng101e4b92006-02-09 22:12:53 +0000776 AddHandleReplacement(N1.Val, 1, Result.Val, 1);
Evan Chengd5f2ba02006-02-06 06:02:33 +0000777 }
Evan Chengd49cc362006-02-10 22:24:32 +0000778
779#ifndef NDEBUG
Evan Chenga86ba852006-02-11 02:05:36 +0000780 DEBUG(std::cerr << std::string(Indent-2, ' '));
Evan Chengd49cc362006-02-10 22:24:32 +0000781 DEBUG(std::cerr << "== ");
782 DEBUG(Result.Val->dump(CurDAG));
783 DEBUG(std::cerr << "\n");
Evan Cheng2b6f78b2006-02-10 22:46:26 +0000784 Indent -= 2;
Evan Chengd49cc362006-02-10 22:24:32 +0000785#endif
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000786 return;
Evan Cheng10d27902006-01-06 20:36:21 +0000787 }
Evan Cheng4eb7af92005-11-30 02:51:20 +0000788
Evan Chengbc7708c2005-12-17 02:02:50 +0000789 case ISD::TRUNCATE: {
790 unsigned Reg;
791 MVT::ValueType VT;
792 switch (Node->getOperand(0).getValueType()) {
793 default: assert(0 && "Unknown truncate!");
794 case MVT::i16: Reg = X86::AX; Opc = X86::MOV16rr; VT = MVT::i16; break;
795 case MVT::i32: Reg = X86::EAX; Opc = X86::MOV32rr; VT = MVT::i32; break;
796 }
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000797 SDOperand Tmp0, Tmp1;
798 Select(Tmp0, Node->getOperand(0));
Evan Chengd1b82d82006-02-09 07:17:49 +0000799 Select(Tmp1, SDOperand(CurDAG->getTargetNode(Opc, VT, Tmp0), 0));
Evan Chengbc7708c2005-12-17 02:02:50 +0000800 SDOperand InFlag = SDOperand(0,0);
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000801 Result = CurDAG->getCopyToReg(CurDAG->getEntryNode(), Reg, Tmp1, InFlag);
Evan Chengbc7708c2005-12-17 02:02:50 +0000802 SDOperand Chain = Result.getValue(0);
803 InFlag = Result.getValue(1);
804
805 switch (NVT) {
806 default: assert(0 && "Unknown truncate!");
807 case MVT::i8: Reg = X86::AL; Opc = X86::MOV8rr; VT = MVT::i8; break;
808 case MVT::i16: Reg = X86::AX; Opc = X86::MOV16rr; VT = MVT::i16; break;
809 }
810
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000811 Result = CurDAG->getCopyFromReg(Chain, Reg, VT, InFlag);
Evan Cheng10d27902006-01-06 20:36:21 +0000812 if (N.Val->hasOneUse())
Evan Chengd1b82d82006-02-09 07:17:49 +0000813 Result = CurDAG->SelectNodeTo(N.Val, Opc, VT, Result);
Evan Cheng10d27902006-01-06 20:36:21 +0000814 else
Evan Chengd1b82d82006-02-09 07:17:49 +0000815 Result = CodeGenMap[N] =
816 SDOperand(CurDAG->getTargetNode(Opc, VT, Result), 0);
Evan Chengd49cc362006-02-10 22:24:32 +0000817
818#ifndef NDEBUG
Evan Chenga86ba852006-02-11 02:05:36 +0000819 DEBUG(std::cerr << std::string(Indent-2, ' '));
Evan Chengd49cc362006-02-10 22:24:32 +0000820 DEBUG(std::cerr << "== ");
821 DEBUG(Result.Val->dump(CurDAG));
822 DEBUG(std::cerr << "\n");
Evan Cheng2b6f78b2006-02-10 22:46:26 +0000823 Indent -= 2;
Evan Chengd49cc362006-02-10 22:24:32 +0000824#endif
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000825 return;
Evan Chengbc7708c2005-12-17 02:02:50 +0000826 }
Chris Lattner655e7df2005-11-16 01:54:32 +0000827 }
828
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000829 SelectCode(Result, N);
Evan Chengd49cc362006-02-10 22:24:32 +0000830#ifndef NDEBUG
Evan Chenga86ba852006-02-11 02:05:36 +0000831 DEBUG(std::cerr << std::string(Indent-2, ' '));
Evan Chengd49cc362006-02-10 22:24:32 +0000832 DEBUG(std::cerr << "=> ");
833 DEBUG(Result.Val->dump(CurDAG));
834 DEBUG(std::cerr << "\n");
Evan Cheng2b6f78b2006-02-10 22:46:26 +0000835 Indent -= 2;
Evan Chengd49cc362006-02-10 22:24:32 +0000836#endif
Chris Lattner655e7df2005-11-16 01:54:32 +0000837}
838
839/// createX86ISelDag - This pass converts a legalized DAG into a
840/// X86-specific DAG, ready for instruction scheduling.
841///
842FunctionPass *llvm::createX86ISelDag(TargetMachine &TM) {
843 return new X86DAGToDAGISel(TM);
844}