blob: 1ff4415dac1cdf5968850b7aca9c0a945291e59b [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,
Evan Chengc9fab312005-12-08 02:01:35 +000049 ConstantPoolBase
Chris Lattner3f0f71b2005-11-19 02:11:08 +000050 } BaseType;
51
52 struct { // This is really a union, discriminated by BaseType!
53 SDOperand Reg;
54 int FrameIndex;
55 } Base;
56
57 unsigned Scale;
58 SDOperand IndexReg;
59 unsigned Disp;
60 GlobalValue *GV;
61
62 X86ISelAddressMode()
Evan Cheng4eb7af92005-11-30 02:51:20 +000063 : BaseType(RegBase), Scale(1), IndexReg(), Disp(0), GV(0) {
Chris Lattner3f0f71b2005-11-19 02:11:08 +000064 }
65 };
66}
67
68namespace {
Chris Lattner655e7df2005-11-16 01:54:32 +000069 Statistic<>
70 NumFPKill("x86-codegen", "Number of FP_REG_KILL instructions added");
71
72 //===--------------------------------------------------------------------===//
73 /// ISel - X86 specific code to select X86 machine instructions for
74 /// SelectionDAG operations.
75 ///
76 class X86DAGToDAGISel : public SelectionDAGISel {
77 /// ContainsFPCode - Every instruction we select that uses or defines a FP
78 /// register should set this to true.
79 bool ContainsFPCode;
80
81 /// X86Lowering - This object fully describes how to lower LLVM code to an
82 /// X86-specific SelectionDAG.
83 X86TargetLowering X86Lowering;
84
85 /// Subtarget - Keep a pointer to the X86Subtarget around so that we can
86 /// make the right decision when generating code for different targets.
87 const X86Subtarget *Subtarget;
Evan Cheng5588de92006-02-18 00:15:05 +000088
89 unsigned GlobalBaseReg;
Chris Lattner655e7df2005-11-16 01:54:32 +000090 public:
91 X86DAGToDAGISel(TargetMachine &TM)
92 : SelectionDAGISel(X86Lowering), X86Lowering(TM) {
93 Subtarget = &TM.getSubtarget<X86Subtarget>();
94 }
95
Evan Cheng5588de92006-02-18 00:15:05 +000096 virtual bool runOnFunction(Function &Fn) {
97 // Make sure we re-emit a set of the global base reg if necessary
98 GlobalBaseReg = 0;
99 return SelectionDAGISel::runOnFunction(Fn);
100 }
101
Chris Lattner655e7df2005-11-16 01:54:32 +0000102 virtual const char *getPassName() const {
103 return "X86 DAG->DAG Instruction Selection";
104 }
105
106 /// InstructionSelectBasicBlock - This callback is invoked by
107 /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
108 virtual void InstructionSelectBasicBlock(SelectionDAG &DAG);
109
Evan Chengbc7a0f442006-01-11 06:09:51 +0000110 virtual void EmitFunctionEntryCode(Function &Fn, MachineFunction &MF);
111
Chris Lattner655e7df2005-11-16 01:54:32 +0000112// Include the pieces autogenerated from the target description.
113#include "X86GenDAGISel.inc"
114
115 private:
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000116 void Select(SDOperand &Result, SDOperand N);
Chris Lattner655e7df2005-11-16 01:54:32 +0000117
Evan Chenga86ba852006-02-11 02:05:36 +0000118 bool MatchAddress(SDOperand N, X86ISelAddressMode &AM, bool isRoot = true);
Evan Chengc9fab312005-12-08 02:01:35 +0000119 bool SelectAddr(SDOperand N, SDOperand &Base, SDOperand &Scale,
120 SDOperand &Index, SDOperand &Disp);
121 bool SelectLEAAddr(SDOperand N, SDOperand &Base, SDOperand &Scale,
122 SDOperand &Index, SDOperand &Disp);
Evan Chengd5f2ba02006-02-06 06:02:33 +0000123 bool TryFoldLoad(SDOperand P, SDOperand N,
124 SDOperand &Base, SDOperand &Scale,
Evan Cheng10d27902006-01-06 20:36:21 +0000125 SDOperand &Index, SDOperand &Disp);
Chris Lattner3f0f71b2005-11-19 02:11:08 +0000126
Evan Cheng67ed58e2005-12-12 21:49:40 +0000127 inline void getAddressOperands(X86ISelAddressMode &AM, SDOperand &Base,
128 SDOperand &Scale, SDOperand &Index,
129 SDOperand &Disp) {
130 Base = (AM.BaseType == X86ISelAddressMode::FrameIndexBase) ?
131 CurDAG->getTargetFrameIndex(AM.Base.FrameIndex, MVT::i32) : AM.Base.Reg;
Evan Cheng1d712482005-12-17 09:13:43 +0000132 Scale = getI8Imm(AM.Scale);
Evan Cheng67ed58e2005-12-12 21:49:40 +0000133 Index = AM.IndexReg;
134 Disp = AM.GV ? CurDAG->getTargetGlobalAddress(AM.GV, MVT::i32, AM.Disp)
135 : getI32Imm(AM.Disp);
136 }
137
Chris Lattner3f0f71b2005-11-19 02:11:08 +0000138 /// getI8Imm - Return a target constant with the specified value, of type
139 /// i8.
140 inline SDOperand getI8Imm(unsigned Imm) {
141 return CurDAG->getTargetConstant(Imm, MVT::i8);
142 }
143
Chris Lattner655e7df2005-11-16 01:54:32 +0000144 /// getI16Imm - Return a target constant with the specified value, of type
145 /// i16.
146 inline SDOperand getI16Imm(unsigned Imm) {
147 return CurDAG->getTargetConstant(Imm, MVT::i16);
148 }
149
150 /// getI32Imm - Return a target constant with the specified value, of type
151 /// i32.
152 inline SDOperand getI32Imm(unsigned Imm) {
153 return CurDAG->getTargetConstant(Imm, MVT::i32);
154 }
Evan Chengd49cc362006-02-10 22:24:32 +0000155
Evan Cheng5588de92006-02-18 00:15:05 +0000156 /// getGlobalBaseReg - insert code into the entry mbb to materialize the PIC
157 /// base register. Return the virtual register that holds this value.
158 SDOperand getGlobalBaseReg();
159
Evan Cheng2b6f78b2006-02-10 22:46:26 +0000160#ifndef NDEBUG
161 unsigned Indent;
162#endif
Chris Lattner655e7df2005-11-16 01:54:32 +0000163 };
164}
165
166/// InstructionSelectBasicBlock - This callback is invoked by SelectionDAGISel
167/// when it has created a SelectionDAG for us to codegen.
168void X86DAGToDAGISel::InstructionSelectBasicBlock(SelectionDAG &DAG) {
169 DEBUG(BB->dump());
Chris Lattner7c551262006-01-11 01:15:34 +0000170 MachineFunction::iterator FirstMBB = BB;
Chris Lattner655e7df2005-11-16 01:54:32 +0000171
172 // Codegen the basic block.
Evan Chengd49cc362006-02-10 22:24:32 +0000173#ifndef NDEBUG
174 DEBUG(std::cerr << "===== Instruction selection begins:\n");
Evan Cheng2b6f78b2006-02-10 22:46:26 +0000175 Indent = 0;
Evan Chengd49cc362006-02-10 22:24:32 +0000176#endif
Evan Cheng54cb1832006-02-05 06:46:41 +0000177 DAG.setRoot(SelectRoot(DAG.getRoot()));
Evan Chengd49cc362006-02-10 22:24:32 +0000178#ifndef NDEBUG
179 DEBUG(std::cerr << "===== Instruction selection ends:\n");
180#endif
Evan Cheng1d9b6712005-12-19 22:36:02 +0000181 CodeGenMap.clear();
Chris Lattner655e7df2005-11-16 01:54:32 +0000182 DAG.RemoveDeadNodes();
183
184 // Emit machine code to BB.
185 ScheduleAndEmitDAG(DAG);
Chris Lattner7c551262006-01-11 01:15:34 +0000186
187 // If we are emitting FP stack code, scan the basic block to determine if this
188 // block defines any FP values. If so, put an FP_REG_KILL instruction before
189 // the terminator of the block.
Evan Chengcde9e302006-01-27 08:10:46 +0000190 if (!Subtarget->hasSSE2()) {
Chris Lattner7c551262006-01-11 01:15:34 +0000191 // Note that FP stack instructions *are* used in SSE code when returning
192 // values, but these are not live out of the basic block, so we don't need
193 // an FP_REG_KILL in this case either.
194 bool ContainsFPCode = false;
195
196 // Scan all of the machine instructions in these MBBs, checking for FP
197 // stores.
198 MachineFunction::iterator MBBI = FirstMBB;
199 do {
200 for (MachineBasicBlock::iterator I = MBBI->begin(), E = MBBI->end();
201 !ContainsFPCode && I != E; ++I) {
202 for (unsigned op = 0, e = I->getNumOperands(); op != e; ++op) {
203 if (I->getOperand(op).isRegister() && I->getOperand(op).isDef() &&
204 MRegisterInfo::isVirtualRegister(I->getOperand(op).getReg()) &&
205 RegMap->getRegClass(I->getOperand(0).getReg()) ==
206 X86::RFPRegisterClass) {
207 ContainsFPCode = true;
208 break;
209 }
210 }
211 }
212 } while (!ContainsFPCode && &*(MBBI++) != BB);
213
214 // Check PHI nodes in successor blocks. These PHI's will be lowered to have
215 // a copy of the input value in this block.
216 if (!ContainsFPCode) {
217 // Final check, check LLVM BB's that are successors to the LLVM BB
218 // corresponding to BB for FP PHI nodes.
219 const BasicBlock *LLVMBB = BB->getBasicBlock();
220 const PHINode *PN;
221 for (succ_const_iterator SI = succ_begin(LLVMBB), E = succ_end(LLVMBB);
222 !ContainsFPCode && SI != E; ++SI) {
223 for (BasicBlock::const_iterator II = SI->begin();
224 (PN = dyn_cast<PHINode>(II)); ++II) {
225 if (PN->getType()->isFloatingPoint()) {
226 ContainsFPCode = true;
227 break;
228 }
229 }
230 }
231 }
232
233 // Finally, if we found any FP code, emit the FP_REG_KILL instruction.
234 if (ContainsFPCode) {
235 BuildMI(*BB, BB->getFirstTerminator(), X86::FP_REG_KILL, 0);
236 ++NumFPKill;
237 }
238 }
Chris Lattner655e7df2005-11-16 01:54:32 +0000239}
240
Evan Chengbc7a0f442006-01-11 06:09:51 +0000241/// EmitSpecialCodeForMain - Emit any code that needs to be executed only in
242/// the main function.
243static void EmitSpecialCodeForMain(MachineBasicBlock *BB,
244 MachineFrameInfo *MFI) {
245 // Switch the FPU to 64-bit precision mode for better compatibility and speed.
246 int CWFrameIdx = MFI->CreateStackObject(2, 2);
247 addFrameReference(BuildMI(BB, X86::FNSTCW16m, 4), CWFrameIdx);
248
249 // Set the high part to be 64-bit precision.
250 addFrameReference(BuildMI(BB, X86::MOV8mi, 5),
251 CWFrameIdx, 1).addImm(2);
252
253 // Reload the modified control word now.
254 addFrameReference(BuildMI(BB, X86::FLDCW16m, 4), CWFrameIdx);
255}
256
257void X86DAGToDAGISel::EmitFunctionEntryCode(Function &Fn, MachineFunction &MF) {
258 // If this is main, emit special code for main.
259 MachineBasicBlock *BB = MF.begin();
260 if (Fn.hasExternalLinkage() && Fn.getName() == "main")
261 EmitSpecialCodeForMain(BB, MF.getFrameInfo());
262}
263
Chris Lattner3f0f71b2005-11-19 02:11:08 +0000264/// MatchAddress - Add the specified node to the specified addressing mode,
265/// returning true if it cannot be done. This just pattern matches for the
266/// addressing mode
Evan Chenga86ba852006-02-11 02:05:36 +0000267bool X86DAGToDAGISel::MatchAddress(SDOperand N, X86ISelAddressMode &AM,
268 bool isRoot) {
269 bool StopHere = false;
270 // If N has already been selected, we may or may not want to fold its
271 // operands into the addressing mode. It will result in code duplication!
272 // FIXME: Right now we do. That is, as long as the selected target node
273 // does not produce a chain. This may require a more sophisticated heuristics.
274 std::map<SDOperand, SDOperand>::iterator CGMI= CodeGenMap.find(N.getValue(0));
275 if (CGMI != CodeGenMap.end()) {
276 if (isRoot)
277 // Stop here if it is a root. It's probably not profitable to go deeper.
278 StopHere = true;
279 else {
280 for (unsigned i = 0, e = CGMI->second.Val->getNumValues(); i != e; ++i) {
281 if (CGMI->second.Val->getValueType(i) == MVT::Other)
282 StopHere = true;
283 }
284 }
285 }
286
Chris Lattner3f0f71b2005-11-19 02:11:08 +0000287 switch (N.getOpcode()) {
288 default: break;
289 case ISD::FrameIndex:
290 if (AM.BaseType == X86ISelAddressMode::RegBase && AM.Base.Reg.Val == 0) {
291 AM.BaseType = X86ISelAddressMode::FrameIndexBase;
292 AM.Base.FrameIndex = cast<FrameIndexSDNode>(N)->getIndex();
293 return false;
294 }
295 break;
Evan Chengc9fab312005-12-08 02:01:35 +0000296
297 case ISD::ConstantPool:
Evan Cheng5588de92006-02-18 00:15:05 +0000298 case ISD::TargetConstantPool:
Evan Chengc9fab312005-12-08 02:01:35 +0000299 if (AM.BaseType == X86ISelAddressMode::RegBase && AM.Base.Reg.Val == 0) {
300 if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(N)) {
301 AM.BaseType = X86ISelAddressMode::ConstantPoolBase;
Evan Cheng72d5c252006-01-31 22:28:30 +0000302 AM.Base.Reg = CurDAG->getTargetConstantPool(CP->get(), MVT::i32,
303 CP->getAlignment());
Evan Chengc9fab312005-12-08 02:01:35 +0000304 return false;
305 }
306 }
307 break;
308
Chris Lattner3f0f71b2005-11-19 02:11:08 +0000309 case ISD::GlobalAddress:
Evan Cheng9cdc16c2005-12-21 23:05:39 +0000310 case ISD::TargetGlobalAddress:
Chris Lattner3f0f71b2005-11-19 02:11:08 +0000311 if (AM.GV == 0) {
Evan Chenga74ce622005-12-21 02:39:21 +0000312 AM.GV = cast<GlobalAddressSDNode>(N)->getGlobal();
Evan Cheng1d712482005-12-17 09:13:43 +0000313 return false;
Chris Lattner3f0f71b2005-11-19 02:11:08 +0000314 }
315 break;
Evan Chengc9fab312005-12-08 02:01:35 +0000316
Evan Cheng1f342c22006-02-23 02:43:52 +0000317 case X86ISD::TGAWrapper:
318 if (AM.GV == 0) {
319 AM.GV = cast<GlobalAddressSDNode>(N.getOperand(0))->getGlobal();
320 return false;
321 }
322 break;
323
Chris Lattner3f0f71b2005-11-19 02:11:08 +0000324 case ISD::Constant:
325 AM.Disp += cast<ConstantSDNode>(N)->getValue();
326 return false;
Evan Chengc9fab312005-12-08 02:01:35 +0000327
Chris Lattner3f0f71b2005-11-19 02:11:08 +0000328 case ISD::SHL:
Evan Chenga86ba852006-02-11 02:05:36 +0000329 if (!StopHere && AM.IndexReg.Val == 0 && AM.Scale == 1)
Chris Lattner3f0f71b2005-11-19 02:11:08 +0000330 if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N.Val->getOperand(1))) {
331 unsigned Val = CN->getValue();
332 if (Val == 1 || Val == 2 || Val == 3) {
333 AM.Scale = 1 << Val;
334 SDOperand ShVal = N.Val->getOperand(0);
335
336 // Okay, we know that we have a scale by now. However, if the scaled
337 // value is an add of something and a constant, we can fold the
338 // constant into the disp field here.
339 if (ShVal.Val->getOpcode() == ISD::ADD && ShVal.hasOneUse() &&
340 isa<ConstantSDNode>(ShVal.Val->getOperand(1))) {
341 AM.IndexReg = ShVal.Val->getOperand(0);
342 ConstantSDNode *AddVal =
343 cast<ConstantSDNode>(ShVal.Val->getOperand(1));
344 AM.Disp += AddVal->getValue() << Val;
345 } else {
346 AM.IndexReg = ShVal;
347 }
348 return false;
349 }
350 }
351 break;
Evan Chengc9fab312005-12-08 02:01:35 +0000352
Chris Lattner3f0f71b2005-11-19 02:11:08 +0000353 case ISD::MUL:
354 // X*[3,5,9] -> X+X*[2,4,8]
Evan Chenga86ba852006-02-11 02:05:36 +0000355 if (!StopHere && AM.IndexReg.Val == 0 && AM.BaseType == X86ISelAddressMode::RegBase &&
Chris Lattner3f0f71b2005-11-19 02:11:08 +0000356 AM.Base.Reg.Val == 0)
357 if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N.Val->getOperand(1)))
358 if (CN->getValue() == 3 || CN->getValue() == 5 || CN->getValue() == 9) {
359 AM.Scale = unsigned(CN->getValue())-1;
360
361 SDOperand MulVal = N.Val->getOperand(0);
362 SDOperand Reg;
363
364 // Okay, we know that we have a scale by now. However, if the scaled
365 // value is an add of something and a constant, we can fold the
366 // constant into the disp field here.
367 if (MulVal.Val->getOpcode() == ISD::ADD && MulVal.hasOneUse() &&
368 isa<ConstantSDNode>(MulVal.Val->getOperand(1))) {
369 Reg = MulVal.Val->getOperand(0);
370 ConstantSDNode *AddVal =
371 cast<ConstantSDNode>(MulVal.Val->getOperand(1));
372 AM.Disp += AddVal->getValue() * CN->getValue();
373 } else {
374 Reg = N.Val->getOperand(0);
375 }
376
377 AM.IndexReg = AM.Base.Reg = Reg;
378 return false;
379 }
380 break;
381
382 case ISD::ADD: {
Evan Chenga86ba852006-02-11 02:05:36 +0000383 if (!StopHere) {
384 X86ISelAddressMode Backup = AM;
385 if (!MatchAddress(N.Val->getOperand(0), AM, false) &&
386 !MatchAddress(N.Val->getOperand(1), AM, false))
387 return false;
388 AM = Backup;
389 if (!MatchAddress(N.Val->getOperand(1), AM, false) &&
390 !MatchAddress(N.Val->getOperand(0), AM, false))
391 return false;
392 AM = Backup;
393 }
Chris Lattner3f0f71b2005-11-19 02:11:08 +0000394 break;
395 }
396 }
397
398 // Is the base register already occupied?
399 if (AM.BaseType != X86ISelAddressMode::RegBase || AM.Base.Reg.Val) {
Evan Cheng5588de92006-02-18 00:15:05 +0000400 // TargetConstantPool cannot be anything but the base.
401 if (N.getOpcode() == ISD::TargetConstantPool)
402 return true;
403
Chris Lattner3f0f71b2005-11-19 02:11:08 +0000404 // If so, check to see if the scale index register is set.
405 if (AM.IndexReg.Val == 0) {
406 AM.IndexReg = N;
407 AM.Scale = 1;
408 return false;
409 }
410
411 // Otherwise, we cannot select it.
412 return true;
413 }
414
415 // Default, generate it as a register.
416 AM.BaseType = X86ISelAddressMode::RegBase;
417 AM.Base.Reg = N;
418 return false;
419}
420
Evan Chengc9fab312005-12-08 02:01:35 +0000421/// SelectAddr - returns true if it is able pattern match an addressing mode.
422/// It returns the operands which make up the maximal addressing mode it can
423/// match by reference.
424bool X86DAGToDAGISel::SelectAddr(SDOperand N, SDOperand &Base, SDOperand &Scale,
425 SDOperand &Index, SDOperand &Disp) {
426 X86ISelAddressMode AM;
Evan Chengbc7a0f442006-01-11 06:09:51 +0000427 if (MatchAddress(N, AM))
428 return false;
Evan Chengc9fab312005-12-08 02:01:35 +0000429
Evan Chengbc7a0f442006-01-11 06:09:51 +0000430 if (AM.BaseType == X86ISelAddressMode::RegBase) {
Evan Chengd19d51f2006-02-05 05:25:07 +0000431 if (!AM.Base.Reg.Val)
Evan Chengbc7a0f442006-01-11 06:09:51 +0000432 AM.Base.Reg = CurDAG->getRegister(0, MVT::i32);
Evan Chengc9fab312005-12-08 02:01:35 +0000433 }
Evan Chengbc7a0f442006-01-11 06:09:51 +0000434
Evan Chengd19d51f2006-02-05 05:25:07 +0000435 if (!AM.IndexReg.Val)
Evan Chengbc7a0f442006-01-11 06:09:51 +0000436 AM.IndexReg = CurDAG->getRegister(0, MVT::i32);
437
438 getAddressOperands(AM, Base, Scale, Index, Disp);
439 return true;
Evan Chengc9fab312005-12-08 02:01:35 +0000440}
441
Evan Chengd5f2ba02006-02-06 06:02:33 +0000442bool X86DAGToDAGISel::TryFoldLoad(SDOperand P, SDOperand N,
443 SDOperand &Base, SDOperand &Scale,
444 SDOperand &Index, SDOperand &Disp) {
445 if (N.getOpcode() == ISD::LOAD &&
446 N.hasOneUse() &&
447 !CodeGenMap.count(N.getValue(0)) &&
448 (P.getNumOperands() == 1 || !isNonImmUse(P.Val, N.Val)))
Evan Cheng10d27902006-01-06 20:36:21 +0000449 return SelectAddr(N.getOperand(1), Base, Scale, Index, Disp);
450 return false;
451}
452
453static bool isRegister0(SDOperand Op) {
Evan Chengc9fab312005-12-08 02:01:35 +0000454 if (RegisterSDNode *R = dyn_cast<RegisterSDNode>(Op))
455 return (R->getReg() == 0);
456 return false;
457}
458
459/// SelectLEAAddr - it calls SelectAddr and determines if the maximal addressing
460/// mode it matches can be cost effectively emitted as an LEA instruction.
461/// For X86, it always is unless it's just a (Reg + const).
Chris Lattner29852a582006-01-11 00:46:55 +0000462bool X86DAGToDAGISel::SelectLEAAddr(SDOperand N, SDOperand &Base,
463 SDOperand &Scale,
Evan Chengc9fab312005-12-08 02:01:35 +0000464 SDOperand &Index, SDOperand &Disp) {
Evan Cheng67ed58e2005-12-12 21:49:40 +0000465 X86ISelAddressMode AM;
466 if (!MatchAddress(N, AM)) {
Evan Cheng67ed58e2005-12-12 21:49:40 +0000467 bool SelectIndex = false;
468 bool Check = false;
469 if (AM.BaseType == X86ISelAddressMode::RegBase) {
Evan Cheng7eabbfd2006-02-23 00:13:58 +0000470 if (AM.Base.Reg.Val)
471 Check = true;
472 else
Evan Cheng67ed58e2005-12-12 21:49:40 +0000473 AM.Base.Reg = CurDAG->getRegister(0, MVT::i32);
Evan Chengc9fab312005-12-08 02:01:35 +0000474 }
Evan Cheng67ed58e2005-12-12 21:49:40 +0000475
Evan Cheng7eabbfd2006-02-23 00:13:58 +0000476 if (AM.IndexReg.Val)
Evan Cheng67ed58e2005-12-12 21:49:40 +0000477 SelectIndex = true;
Evan Cheng7eabbfd2006-02-23 00:13:58 +0000478 else
Evan Cheng67ed58e2005-12-12 21:49:40 +0000479 AM.IndexReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng67ed58e2005-12-12 21:49:40 +0000480
481 if (Check) {
482 unsigned Complexity = 0;
483 if (AM.Scale > 1)
484 Complexity++;
485 if (SelectIndex)
486 Complexity++;
487 if (AM.GV)
488 Complexity++;
489 else if (AM.Disp > 1)
490 Complexity++;
Evan Cheng7eabbfd2006-02-23 00:13:58 +0000491 // Suppose base == %eax and it has multiple uses, then instead of
492 // movl %eax, %ecx
493 // addl $8, %ecx
494 // use
495 // leal 8(%eax), %ecx.
Evan Cheng1f342c22006-02-23 02:43:52 +0000496 // FIXME: If the other uses ended up being scheduled ahead of the leal
497 // then it would have been better to use the addl. The proper way to
498 // handle this is with using X86InstrInfo::convertToThreeAddress hook.
499 // From an email:
500 // BTW, this problem is the one that inspired the
501 // "X86InstrInfo::convertToThreeAddress" hook (which would handle this
502 // the "right" way). Unfortunately the X86 implementation of this is
503 // disabled, because we don't currently have enough information handy to
504 // know that the flags from the add is dead when the hook is called (from
505 // the register allocator).
Evan Cheng7eabbfd2006-02-23 00:13:58 +0000506 if (AM.Base.Reg.Val->use_size() > 1)
507 Complexity++;
Evan Cheng67ed58e2005-12-12 21:49:40 +0000508 if (Complexity <= 1)
509 return false;
510 }
511
Evan Cheng67ed58e2005-12-12 21:49:40 +0000512 getAddressOperands(AM, Base, Scale, Index, Disp);
Evan Chengc9fab312005-12-08 02:01:35 +0000513 return true;
Evan Chengc9fab312005-12-08 02:01:35 +0000514 }
Evan Cheng67ed58e2005-12-12 21:49:40 +0000515 return false;
Evan Chengc9fab312005-12-08 02:01:35 +0000516}
517
Evan Cheng5588de92006-02-18 00:15:05 +0000518/// getGlobalBaseReg - Output the instructions required to put the
519/// base address to use for accessing globals into a register.
520///
521SDOperand X86DAGToDAGISel::getGlobalBaseReg() {
522 if (!GlobalBaseReg) {
523 // Insert the set of GlobalBaseReg into the first MBB of the function
524 MachineBasicBlock &FirstMBB = BB->getParent()->front();
525 MachineBasicBlock::iterator MBBI = FirstMBB.begin();
526 SSARegMap *RegMap = BB->getParent()->getSSARegMap();
527 // FIXME: when we get to LP64, we will need to create the appropriate
528 // type of register here.
529 GlobalBaseReg = RegMap->createVirtualRegister(X86::R32RegisterClass);
530 BuildMI(FirstMBB, MBBI, X86::MovePCtoStack, 0);
531 BuildMI(FirstMBB, MBBI, X86::POP32r, 1, GlobalBaseReg);
532 }
533 return CurDAG->getRegister(GlobalBaseReg, MVT::i32);
534}
535
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000536void X86DAGToDAGISel::Select(SDOperand &Result, SDOperand N) {
Evan Cheng00fcb002005-12-15 01:02:48 +0000537 SDNode *Node = N.Val;
538 MVT::ValueType NVT = Node->getValueType(0);
Evan Cheng10d27902006-01-06 20:36:21 +0000539 unsigned Opc, MOpc;
540 unsigned Opcode = Node->getOpcode();
Chris Lattner655e7df2005-11-16 01:54:32 +0000541
Evan Chengd49cc362006-02-10 22:24:32 +0000542#ifndef NDEBUG
Evan Cheng2b6f78b2006-02-10 22:46:26 +0000543 DEBUG(std::cerr << std::string(Indent, ' '));
Evan Chengd49cc362006-02-10 22:24:32 +0000544 DEBUG(std::cerr << "Selecting: ");
545 DEBUG(Node->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
549
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000550 if (Opcode >= ISD::BUILTIN_OP_END && Opcode < X86ISD::FIRST_NUMBER) {
551 Result = N;
Evan Chengd49cc362006-02-10 22:24:32 +0000552#ifndef NDEBUG
Evan Chenga86ba852006-02-11 02:05:36 +0000553 DEBUG(std::cerr << std::string(Indent-2, ' '));
Evan Chengd49cc362006-02-10 22:24:32 +0000554 DEBUG(std::cerr << "== ");
555 DEBUG(Node->dump(CurDAG));
556 DEBUG(std::cerr << "\n");
Evan Cheng2b6f78b2006-02-10 22:46:26 +0000557 Indent -= 2;
Evan Chengd49cc362006-02-10 22:24:32 +0000558#endif
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000559 return; // Already selected.
560 }
Evan Cheng2ae799a2006-01-11 22:15:18 +0000561
562 std::map<SDOperand, SDOperand>::iterator CGMI = CodeGenMap.find(N);
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000563 if (CGMI != CodeGenMap.end()) {
564 Result = CGMI->second;
Evan Chengd49cc362006-02-10 22:24:32 +0000565#ifndef NDEBUG
Evan Chenga86ba852006-02-11 02:05:36 +0000566 DEBUG(std::cerr << std::string(Indent-2, ' '));
Evan Chengd49cc362006-02-10 22:24:32 +0000567 DEBUG(std::cerr << "== ");
568 DEBUG(Result.Val->dump(CurDAG));
569 DEBUG(std::cerr << "\n");
Evan Cheng2b6f78b2006-02-10 22:46:26 +0000570 Indent -= 2;
Evan Chengd49cc362006-02-10 22:24:32 +0000571#endif
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000572 return;
573 }
Chris Lattner655e7df2005-11-16 01:54:32 +0000574
Evan Cheng10d27902006-01-06 20:36:21 +0000575 switch (Opcode) {
Chris Lattner655e7df2005-11-16 01:54:32 +0000576 default: break;
Evan Cheng1f342c22006-02-23 02:43:52 +0000577 case X86ISD::TGAWrapper: {
578 GlobalValue *GV = cast<GlobalAddressSDNode>(N.getOperand(0))->getGlobal();
579 SDOperand TGA = CurDAG->getTargetGlobalAddress(GV, MVT::i32);
580 Result = CodeGenMap[N] =
581 SDOperand(CurDAG->getTargetNode(X86::MOV32ri, MVT::i32, TGA), 0);
582 return;
583 }
Evan Cheng10d27902006-01-06 20:36:21 +0000584 case ISD::MULHU:
585 case ISD::MULHS: {
586 if (Opcode == ISD::MULHU)
587 switch (NVT) {
588 default: assert(0 && "Unsupported VT!");
589 case MVT::i8: Opc = X86::MUL8r; MOpc = X86::MUL8m; break;
590 case MVT::i16: Opc = X86::MUL16r; MOpc = X86::MUL16m; break;
591 case MVT::i32: Opc = X86::MUL32r; MOpc = X86::MUL32m; break;
592 }
593 else
594 switch (NVT) {
595 default: assert(0 && "Unsupported VT!");
596 case MVT::i8: Opc = X86::IMUL8r; MOpc = X86::IMUL8m; break;
597 case MVT::i16: Opc = X86::IMUL16r; MOpc = X86::IMUL16m; break;
598 case MVT::i32: Opc = X86::IMUL32r; MOpc = X86::IMUL32m; break;
599 }
600
601 unsigned LoReg, HiReg;
602 switch (NVT) {
603 default: assert(0 && "Unsupported VT!");
604 case MVT::i8: LoReg = X86::AL; HiReg = X86::AH; break;
605 case MVT::i16: LoReg = X86::AX; HiReg = X86::DX; break;
606 case MVT::i32: LoReg = X86::EAX; HiReg = X86::EDX; break;
607 }
608
609 SDOperand N0 = Node->getOperand(0);
610 SDOperand N1 = Node->getOperand(1);
611
612 bool foldedLoad = false;
613 SDOperand Tmp0, Tmp1, Tmp2, Tmp3;
Evan Chengd5f2ba02006-02-06 06:02:33 +0000614 foldedLoad = TryFoldLoad(N, N1, Tmp0, Tmp1, Tmp2, Tmp3);
Evan Cheng92e27972006-01-06 23:19:29 +0000615 // MULHU and MULHS are commmutative
616 if (!foldedLoad) {
Evan Chengd5f2ba02006-02-06 06:02:33 +0000617 foldedLoad = TryFoldLoad(N, N0, Tmp0, Tmp1, Tmp2, Tmp3);
Evan Cheng92e27972006-01-06 23:19:29 +0000618 if (foldedLoad) {
619 N0 = Node->getOperand(1);
620 N1 = Node->getOperand(0);
621 }
622 }
623
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000624 SDOperand Chain;
625 if (foldedLoad)
626 Select(Chain, N1.getOperand(0));
627 else
628 Chain = CurDAG->getEntryNode();
Evan Cheng10d27902006-01-06 20:36:21 +0000629
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000630 SDOperand InFlag(0, 0);
631 Select(N0, N0);
Evan Cheng10d27902006-01-06 20:36:21 +0000632 Chain = CurDAG->getCopyToReg(Chain, CurDAG->getRegister(LoReg, NVT),
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000633 N0, InFlag);
Evan Cheng10d27902006-01-06 20:36:21 +0000634 InFlag = Chain.getValue(1);
635
636 if (foldedLoad) {
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000637 Select(Tmp0, Tmp0);
638 Select(Tmp1, Tmp1);
639 Select(Tmp2, Tmp2);
640 Select(Tmp3, Tmp3);
Evan Chengd1b82d82006-02-09 07:17:49 +0000641 SDNode *CNode =
642 CurDAG->getTargetNode(MOpc, MVT::Other, MVT::Flag, Tmp0, Tmp1,
643 Tmp2, Tmp3, Chain, InFlag);
644 Chain = SDOperand(CNode, 0);
645 InFlag = SDOperand(CNode, 1);
Evan Cheng10d27902006-01-06 20:36:21 +0000646 } else {
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000647 Select(N1, N1);
Evan Chengd1b82d82006-02-09 07:17:49 +0000648 InFlag =
649 SDOperand(CurDAG->getTargetNode(Opc, MVT::Flag, N1, InFlag), 0);
Evan Cheng10d27902006-01-06 20:36:21 +0000650 }
651
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000652 Result = CurDAG->getCopyFromReg(Chain, HiReg, NVT, InFlag);
Evan Cheng10d27902006-01-06 20:36:21 +0000653 CodeGenMap[N.getValue(0)] = Result;
Evan Chengd5f2ba02006-02-06 06:02:33 +0000654 if (foldedLoad) {
Evan Cheng92e27972006-01-06 23:19:29 +0000655 CodeGenMap[N1.getValue(1)] = Result.getValue(1);
Evan Cheng101e4b92006-02-09 22:12:53 +0000656 AddHandleReplacement(N1.Val, 1, Result.Val, 1);
Evan Chengd5f2ba02006-02-06 06:02:33 +0000657 }
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000658
Evan Chengd49cc362006-02-10 22:24:32 +0000659#ifndef NDEBUG
Evan Chenga86ba852006-02-11 02:05:36 +0000660 DEBUG(std::cerr << std::string(Indent-2, ' '));
Evan Chengd49cc362006-02-10 22:24:32 +0000661 DEBUG(std::cerr << "== ");
662 DEBUG(Result.Val->dump(CurDAG));
663 DEBUG(std::cerr << "\n");
Evan Cheng2b6f78b2006-02-10 22:46:26 +0000664 Indent -= 2;
Evan Chengd49cc362006-02-10 22:24:32 +0000665#endif
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000666 return;
Evan Cheng92e27972006-01-06 23:19:29 +0000667 }
Evan Cheng5588de92006-02-18 00:15:05 +0000668
669 case X86ISD::GlobalBaseReg:
670 Result = getGlobalBaseReg();
671 return;
Evan Cheng92e27972006-01-06 23:19:29 +0000672
673 case ISD::SDIV:
674 case ISD::UDIV:
675 case ISD::SREM:
676 case ISD::UREM: {
677 bool isSigned = Opcode == ISD::SDIV || Opcode == ISD::SREM;
678 bool isDiv = Opcode == ISD::SDIV || Opcode == ISD::UDIV;
679 if (!isSigned)
680 switch (NVT) {
681 default: assert(0 && "Unsupported VT!");
682 case MVT::i8: Opc = X86::DIV8r; MOpc = X86::DIV8m; break;
683 case MVT::i16: Opc = X86::DIV16r; MOpc = X86::DIV16m; break;
684 case MVT::i32: Opc = X86::DIV32r; MOpc = X86::DIV32m; break;
685 }
686 else
687 switch (NVT) {
688 default: assert(0 && "Unsupported VT!");
689 case MVT::i8: Opc = X86::IDIV8r; MOpc = X86::IDIV8m; break;
690 case MVT::i16: Opc = X86::IDIV16r; MOpc = X86::IDIV16m; break;
691 case MVT::i32: Opc = X86::IDIV32r; MOpc = X86::IDIV32m; break;
692 }
693
694 unsigned LoReg, HiReg;
695 unsigned ClrOpcode, SExtOpcode;
696 switch (NVT) {
697 default: assert(0 && "Unsupported VT!");
698 case MVT::i8:
699 LoReg = X86::AL; HiReg = X86::AH;
700 ClrOpcode = X86::MOV8ri;
701 SExtOpcode = X86::CBW;
702 break;
703 case MVT::i16:
704 LoReg = X86::AX; HiReg = X86::DX;
705 ClrOpcode = X86::MOV16ri;
706 SExtOpcode = X86::CWD;
707 break;
708 case MVT::i32:
709 LoReg = X86::EAX; HiReg = X86::EDX;
710 ClrOpcode = X86::MOV32ri;
711 SExtOpcode = X86::CDQ;
712 break;
713 }
714
715 SDOperand N0 = Node->getOperand(0);
716 SDOperand N1 = Node->getOperand(1);
717
718 bool foldedLoad = false;
719 SDOperand Tmp0, Tmp1, Tmp2, Tmp3;
Evan Chengd5f2ba02006-02-06 06:02:33 +0000720 foldedLoad = TryFoldLoad(N, N1, Tmp0, Tmp1, Tmp2, Tmp3);
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000721 SDOperand Chain;
722 if (foldedLoad)
723 Select(Chain, N1.getOperand(0));
724 else
725 Chain = CurDAG->getEntryNode();
Evan Cheng92e27972006-01-06 23:19:29 +0000726
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000727 SDOperand InFlag(0, 0);
728 Select(N0, N0);
Evan Cheng92e27972006-01-06 23:19:29 +0000729 Chain = CurDAG->getCopyToReg(Chain, CurDAG->getRegister(LoReg, NVT),
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000730 N0, InFlag);
Evan Cheng92e27972006-01-06 23:19:29 +0000731 InFlag = Chain.getValue(1);
732
733 if (isSigned) {
734 // Sign extend the low part into the high part.
Evan Chengd1b82d82006-02-09 07:17:49 +0000735 InFlag =
736 SDOperand(CurDAG->getTargetNode(SExtOpcode, MVT::Flag, InFlag), 0);
Evan Cheng92e27972006-01-06 23:19:29 +0000737 } else {
738 // Zero out the high part, effectively zero extending the input.
739 SDOperand ClrNode =
Evan Chengd1b82d82006-02-09 07:17:49 +0000740 SDOperand(CurDAG->getTargetNode(ClrOpcode, NVT,
741 CurDAG->getTargetConstant(0, NVT)), 0);
Evan Cheng92e27972006-01-06 23:19:29 +0000742 Chain = CurDAG->getCopyToReg(Chain, CurDAG->getRegister(HiReg, NVT),
743 ClrNode, InFlag);
744 InFlag = Chain.getValue(1);
745 }
746
747 if (foldedLoad) {
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000748 Select(Tmp0, Tmp0);
749 Select(Tmp1, Tmp1);
750 Select(Tmp2, Tmp2);
751 Select(Tmp3, Tmp3);
Evan Chengd1b82d82006-02-09 07:17:49 +0000752 SDNode *CNode =
753 CurDAG->getTargetNode(MOpc, MVT::Other, MVT::Flag, Tmp0, Tmp1,
754 Tmp2, Tmp3, Chain, InFlag);
755 Chain = SDOperand(CNode, 0);
756 InFlag = SDOperand(CNode, 1);
Evan Cheng92e27972006-01-06 23:19:29 +0000757 } else {
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000758 Select(N1, N1);
Evan Chengd1b82d82006-02-09 07:17:49 +0000759 InFlag =
760 SDOperand(CurDAG->getTargetNode(Opc, MVT::Flag, N1, InFlag), 0);
Evan Cheng92e27972006-01-06 23:19:29 +0000761 }
762
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000763 Result = CurDAG->getCopyFromReg(Chain, isDiv ? LoReg : HiReg,
764 NVT, InFlag);
Evan Cheng92e27972006-01-06 23:19:29 +0000765 CodeGenMap[N.getValue(0)] = Result;
Evan Chengd5f2ba02006-02-06 06:02:33 +0000766 if (foldedLoad) {
Evan Cheng92e27972006-01-06 23:19:29 +0000767 CodeGenMap[N1.getValue(1)] = Result.getValue(1);
Evan Cheng101e4b92006-02-09 22:12:53 +0000768 AddHandleReplacement(N1.Val, 1, Result.Val, 1);
Evan Chengd5f2ba02006-02-06 06:02:33 +0000769 }
Evan Chengd49cc362006-02-10 22:24:32 +0000770
771#ifndef NDEBUG
Evan Chenga86ba852006-02-11 02:05:36 +0000772 DEBUG(std::cerr << std::string(Indent-2, ' '));
Evan Chengd49cc362006-02-10 22:24:32 +0000773 DEBUG(std::cerr << "== ");
774 DEBUG(Result.Val->dump(CurDAG));
775 DEBUG(std::cerr << "\n");
Evan Cheng2b6f78b2006-02-10 22:46:26 +0000776 Indent -= 2;
Evan Chengd49cc362006-02-10 22:24:32 +0000777#endif
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000778 return;
Evan Cheng10d27902006-01-06 20:36:21 +0000779 }
Evan Cheng4eb7af92005-11-30 02:51:20 +0000780
Evan Chengbc7708c2005-12-17 02:02:50 +0000781 case ISD::TRUNCATE: {
782 unsigned Reg;
783 MVT::ValueType VT;
784 switch (Node->getOperand(0).getValueType()) {
785 default: assert(0 && "Unknown truncate!");
786 case MVT::i16: Reg = X86::AX; Opc = X86::MOV16rr; VT = MVT::i16; break;
787 case MVT::i32: Reg = X86::EAX; Opc = X86::MOV32rr; VT = MVT::i32; break;
788 }
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000789 SDOperand Tmp0, Tmp1;
790 Select(Tmp0, Node->getOperand(0));
Evan Chengd1b82d82006-02-09 07:17:49 +0000791 Select(Tmp1, SDOperand(CurDAG->getTargetNode(Opc, VT, Tmp0), 0));
Evan Chengbc7708c2005-12-17 02:02:50 +0000792 SDOperand InFlag = SDOperand(0,0);
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000793 Result = CurDAG->getCopyToReg(CurDAG->getEntryNode(), Reg, Tmp1, InFlag);
Evan Chengbc7708c2005-12-17 02:02:50 +0000794 SDOperand Chain = Result.getValue(0);
795 InFlag = Result.getValue(1);
796
797 switch (NVT) {
798 default: assert(0 && "Unknown truncate!");
799 case MVT::i8: Reg = X86::AL; Opc = X86::MOV8rr; VT = MVT::i8; break;
800 case MVT::i16: Reg = X86::AX; Opc = X86::MOV16rr; VT = MVT::i16; break;
801 }
802
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000803 Result = CurDAG->getCopyFromReg(Chain, Reg, VT, InFlag);
Evan Cheng10d27902006-01-06 20:36:21 +0000804 if (N.Val->hasOneUse())
Evan Chengd1b82d82006-02-09 07:17:49 +0000805 Result = CurDAG->SelectNodeTo(N.Val, Opc, VT, Result);
Evan Cheng10d27902006-01-06 20:36:21 +0000806 else
Evan Chengd1b82d82006-02-09 07:17:49 +0000807 Result = CodeGenMap[N] =
808 SDOperand(CurDAG->getTargetNode(Opc, VT, Result), 0);
Evan Chengd49cc362006-02-10 22:24:32 +0000809
810#ifndef NDEBUG
Evan Chenga86ba852006-02-11 02:05:36 +0000811 DEBUG(std::cerr << std::string(Indent-2, ' '));
Evan Chengd49cc362006-02-10 22:24:32 +0000812 DEBUG(std::cerr << "== ");
813 DEBUG(Result.Val->dump(CurDAG));
814 DEBUG(std::cerr << "\n");
Evan Cheng2b6f78b2006-02-10 22:46:26 +0000815 Indent -= 2;
Evan Chengd49cc362006-02-10 22:24:32 +0000816#endif
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000817 return;
Evan Chengbc7708c2005-12-17 02:02:50 +0000818 }
Chris Lattner655e7df2005-11-16 01:54:32 +0000819 }
820
Evan Cheng6dc90ca2006-02-09 00:37:58 +0000821 SelectCode(Result, N);
Evan Chengd49cc362006-02-10 22:24:32 +0000822#ifndef NDEBUG
Evan Chenga86ba852006-02-11 02:05:36 +0000823 DEBUG(std::cerr << std::string(Indent-2, ' '));
Evan Chengd49cc362006-02-10 22:24:32 +0000824 DEBUG(std::cerr << "=> ");
825 DEBUG(Result.Val->dump(CurDAG));
826 DEBUG(std::cerr << "\n");
Evan Cheng2b6f78b2006-02-10 22:46:26 +0000827 Indent -= 2;
Evan Chengd49cc362006-02-10 22:24:32 +0000828#endif
Chris Lattner655e7df2005-11-16 01:54:32 +0000829}
830
831/// createX86ISelDag - This pass converts a legalized DAG into a
832/// X86-specific DAG, ready for instruction scheduling.
833///
834FunctionPass *llvm::createX86ISelDag(TargetMachine &TM) {
835 return new X86DAGToDAGISel(TM);
836}