blob: f402053e73a1f74acfe258d5adb3550a29e1c748 [file] [log] [blame]
Chris Lattner7a125372005-11-16 22:59:19 +00001//===- X86ISelDAGToDAG.cpp - A DAG pattern matching inst selector for X86 -===//
Chris Lattnerc961eea2005-11-16 01:54:32 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnerc961eea2005-11-16 01:54:32 +00007//
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 Cheng2ef88a02006-08-07 22:28:20 +000015#define DEBUG_TYPE "x86-isel"
Chris Lattnerc961eea2005-11-16 01:54:32 +000016#include "X86.h"
Evan Cheng8700e142006-01-11 06:09:51 +000017#include "X86InstrBuilder.h"
Evan Chengc4c62572006-03-13 23:20:37 +000018#include "X86ISelLowering.h"
Evan Cheng0475ab52008-01-05 00:41:47 +000019#include "X86MachineFunctionInfo.h"
Chris Lattner92cb0af2006-01-11 01:15:34 +000020#include "X86RegisterInfo.h"
Chris Lattnerc961eea2005-11-16 01:54:32 +000021#include "X86Subtarget.h"
Evan Chengc4c62572006-03-13 23:20:37 +000022#include "X86TargetMachine.h"
Chris Lattnerf9ce9fb2005-11-19 02:11:08 +000023#include "llvm/GlobalValue.h"
Chris Lattner92cb0af2006-01-11 01:15:34 +000024#include "llvm/Instructions.h"
Chris Lattner420736d2006-03-25 06:47:10 +000025#include "llvm/Intrinsics.h"
Chris Lattner92cb0af2006-01-11 01:15:34 +000026#include "llvm/Support/CFG.h"
Reid Spencer7aa8a452007-01-12 23:22:14 +000027#include "llvm/Type.h"
Chris Lattnerf9ce9fb2005-11-19 02:11:08 +000028#include "llvm/CodeGen/MachineConstantPool.h"
Chris Lattnerc961eea2005-11-16 01:54:32 +000029#include "llvm/CodeGen/MachineFunction.h"
Evan Chengaaca22c2006-01-10 20:26:56 +000030#include "llvm/CodeGen/MachineFrameInfo.h"
Chris Lattner92cb0af2006-01-11 01:15:34 +000031#include "llvm/CodeGen/MachineInstrBuilder.h"
Chris Lattner84bc5422007-12-31 04:13:23 +000032#include "llvm/CodeGen/MachineRegisterInfo.h"
Chris Lattnerc961eea2005-11-16 01:54:32 +000033#include "llvm/CodeGen/SelectionDAGISel.h"
34#include "llvm/Target/TargetMachine.h"
Evan Chengb7a75a52008-09-26 23:41:32 +000035#include "llvm/Target/TargetOptions.h"
Chris Lattnera4f0b3a2006-08-27 12:54:02 +000036#include "llvm/Support/Compiler.h"
Evan Cheng25ab6902006-09-08 06:48:29 +000037#include "llvm/Support/Debug.h"
38#include "llvm/Support/MathExtras.h"
Dale Johannesen50dd1d02008-08-11 23:46:25 +000039#include "llvm/Support/Streams.h"
Evan Chengcdda25d2008-04-25 08:22:20 +000040#include "llvm/ADT/SmallPtrSet.h"
Chris Lattnerc961eea2005-11-16 01:54:32 +000041#include "llvm/ADT/Statistic.h"
42using namespace llvm;
43
Evan Cheng4d952322009-03-31 01:13:53 +000044#include "llvm/Support/CommandLine.h"
45static cl::opt<bool> AvoidDupAddrCompute("x86-avoid-dup-address", cl::Hidden);
46
Chris Lattner95b2c7d2006-12-19 22:59:26 +000047STATISTIC(NumLoadMoved, "Number of loads moved below TokenFactor");
48
Chris Lattnerc961eea2005-11-16 01:54:32 +000049//===----------------------------------------------------------------------===//
50// Pattern Matcher Implementation
51//===----------------------------------------------------------------------===//
52
53namespace {
Chris Lattnerf9ce9fb2005-11-19 02:11:08 +000054 /// X86ISelAddressMode - This corresponds to X86AddressMode, but uses
Dan Gohman475871a2008-07-27 21:46:04 +000055 /// SDValue's instead of register numbers for the leaves of the matched
Chris Lattnerf9ce9fb2005-11-19 02:11:08 +000056 /// tree.
57 struct X86ISelAddressMode {
58 enum {
59 RegBase,
Chris Lattnerd74ea2b2006-05-24 17:04:05 +000060 FrameIndexBase
Chris Lattnerf9ce9fb2005-11-19 02:11:08 +000061 } BaseType;
62
63 struct { // This is really a union, discriminated by BaseType!
Dan Gohman475871a2008-07-27 21:46:04 +000064 SDValue Reg;
Chris Lattnerf9ce9fb2005-11-19 02:11:08 +000065 int FrameIndex;
66 } Base;
67
Evan Chengbe3bf422008-02-07 08:53:49 +000068 bool isRIPRel; // RIP as base?
Chris Lattnerf9ce9fb2005-11-19 02:11:08 +000069 unsigned Scale;
Dan Gohman475871a2008-07-27 21:46:04 +000070 SDValue IndexReg;
Dan Gohman27cae7b2008-11-11 15:52:29 +000071 int32_t Disp;
Chris Lattnerf9ce9fb2005-11-19 02:11:08 +000072 GlobalValue *GV;
Evan Cheng51a9ed92006-02-25 10:09:08 +000073 Constant *CP;
Evan Cheng25ab6902006-09-08 06:48:29 +000074 const char *ES;
75 int JT;
Evan Cheng51a9ed92006-02-25 10:09:08 +000076 unsigned Align; // CP alignment.
Chris Lattnerf9ce9fb2005-11-19 02:11:08 +000077
78 X86ISelAddressMode()
Evan Cheng25ab6902006-09-08 06:48:29 +000079 : BaseType(RegBase), isRIPRel(false), Scale(1), IndexReg(), Disp(0),
Bill Wendling044b5342009-04-07 22:35:25 +000080 GV(0), CP(0), ES(0), JT(-1), Align(0) {
Chris Lattnerf9ce9fb2005-11-19 02:11:08 +000081 }
Dan Gohman2d0a1cc2009-02-07 00:43:41 +000082
83 bool hasSymbolicDisplacement() const {
84 return GV != 0 || CP != 0 || ES != 0 || JT != -1;
85 }
86
Dale Johannesen50dd1d02008-08-11 23:46:25 +000087 void dump() {
88 cerr << "X86ISelAddressMode " << this << "\n";
Gabor Greif93c53e52008-08-31 15:37:04 +000089 cerr << "Base.Reg ";
90 if (Base.Reg.getNode() != 0) Base.Reg.getNode()->dump();
91 else cerr << "nul";
Dale Johannesen50dd1d02008-08-11 23:46:25 +000092 cerr << " Base.FrameIndex " << Base.FrameIndex << "\n";
93 cerr << "isRIPRel " << isRIPRel << " Scale" << Scale << "\n";
Gabor Greif93c53e52008-08-31 15:37:04 +000094 cerr << "IndexReg ";
95 if (IndexReg.getNode() != 0) IndexReg.getNode()->dump();
96 else cerr << "nul";
Dale Johannesen50dd1d02008-08-11 23:46:25 +000097 cerr << " Disp " << Disp << "\n";
98 cerr << "GV "; if (GV) GV->dump();
99 else cerr << "nul";
100 cerr << " CP "; if (CP) CP->dump();
101 else cerr << "nul";
102 cerr << "\n";
103 cerr << "ES "; if (ES) cerr << ES; else cerr << "nul";
104 cerr << " JT" << JT << " Align" << Align << "\n";
105 }
Chris Lattnerf9ce9fb2005-11-19 02:11:08 +0000106 };
107}
108
109namespace {
Chris Lattnerc961eea2005-11-16 01:54:32 +0000110 //===--------------------------------------------------------------------===//
111 /// ISel - X86 specific code to select X86 machine instructions for
112 /// SelectionDAG operations.
113 ///
Chris Lattner2c79de82006-06-28 23:27:49 +0000114 class VISIBILITY_HIDDEN X86DAGToDAGISel : public SelectionDAGISel {
Evan Cheng25ab6902006-09-08 06:48:29 +0000115 /// TM - Keep a reference to X86TargetMachine.
116 ///
117 X86TargetMachine &TM;
118
Chris Lattnerc961eea2005-11-16 01:54:32 +0000119 /// X86Lowering - This object fully describes how to lower LLVM code to an
120 /// X86-specific SelectionDAG.
Dan Gohmanda8ac5f2008-10-03 16:55:19 +0000121 X86TargetLowering &X86Lowering;
Chris Lattnerc961eea2005-11-16 01:54:32 +0000122
123 /// Subtarget - Keep a pointer to the X86Subtarget around so that we can
124 /// make the right decision when generating code for different targets.
125 const X86Subtarget *Subtarget;
Evan Cheng7ccced62006-02-18 00:15:05 +0000126
Evan Chengdb8d56b2008-06-30 20:45:06 +0000127 /// CurBB - Current BB being isel'd.
128 ///
129 MachineBasicBlock *CurBB;
130
Evan Chengb7a75a52008-09-26 23:41:32 +0000131 /// OptForSize - If true, selector should try to optimize for code size
132 /// instead of performance.
133 bool OptForSize;
134
Chris Lattnerc961eea2005-11-16 01:54:32 +0000135 public:
Evan Cheng25ab6902006-09-08 06:48:29 +0000136 X86DAGToDAGISel(X86TargetMachine &tm, bool fast)
Dan Gohman79ce2762009-01-15 19:20:50 +0000137 : SelectionDAGISel(tm, fast),
Dan Gohman38217fe2008-10-03 16:17:33 +0000138 TM(tm), X86Lowering(*TM.getTargetLowering()),
Evan Chengb7a75a52008-09-26 23:41:32 +0000139 Subtarget(&TM.getSubtarget<X86Subtarget>()),
Devang Patel4ae641f2008-10-01 23:18:38 +0000140 OptForSize(false) {}
Chris Lattnerc961eea2005-11-16 01:54:32 +0000141
142 virtual const char *getPassName() const {
143 return "X86 DAG->DAG Instruction Selection";
144 }
145
Evan Chengdb8d56b2008-06-30 20:45:06 +0000146 /// InstructionSelect - This callback is invoked by
Chris Lattnerc961eea2005-11-16 01:54:32 +0000147 /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
Dan Gohmanf350b272008-08-23 02:25:05 +0000148 virtual void InstructionSelect();
Evan Chengdb8d56b2008-06-30 20:45:06 +0000149
Anton Korobeynikov2fe12592007-09-25 21:52:30 +0000150 virtual void EmitFunctionEntryCode(Function &Fn, MachineFunction &MF);
151
Evan Cheng884c70c2008-11-27 00:49:46 +0000152 virtual
153 bool IsLegalAndProfitableToFold(SDNode *N, SDNode *U, SDNode *Root) const;
Evan Chenga8df1b42006-07-27 16:44:36 +0000154
Chris Lattnerc961eea2005-11-16 01:54:32 +0000155// Include the pieces autogenerated from the target description.
156#include "X86GenDAGISel.inc"
157
158 private:
Dan Gohman475871a2008-07-27 21:46:04 +0000159 SDNode *Select(SDValue N);
Dale Johannesen48c1bc22008-10-02 18:53:47 +0000160 SDNode *SelectAtomic64(SDNode *Node, unsigned Opc);
Chris Lattnerc961eea2005-11-16 01:54:32 +0000161
Dan Gohman475871a2008-07-27 21:46:04 +0000162 bool MatchAddress(SDValue N, X86ISelAddressMode &AM,
Rafael Espindola523249f2009-03-31 16:16:57 +0000163 unsigned Depth = 0);
164 bool MatchAddressBase(SDValue N, X86ISelAddressMode &AM);
Dan Gohman475871a2008-07-27 21:46:04 +0000165 bool SelectAddr(SDValue Op, SDValue N, SDValue &Base,
Bill Wendling044b5342009-04-07 22:35:25 +0000166 SDValue &Scale, SDValue &Index, SDValue &Disp);
Dan Gohman475871a2008-07-27 21:46:04 +0000167 bool SelectLEAAddr(SDValue Op, SDValue N, SDValue &Base,
168 SDValue &Scale, SDValue &Index, SDValue &Disp);
169 bool SelectScalarSSELoad(SDValue Op, SDValue Pred,
170 SDValue N, SDValue &Base, SDValue &Scale,
171 SDValue &Index, SDValue &Disp,
172 SDValue &InChain, SDValue &OutChain);
173 bool TryFoldLoad(SDValue P, SDValue N,
174 SDValue &Base, SDValue &Scale,
Bill Wendling044b5342009-04-07 22:35:25 +0000175 SDValue &Index, SDValue &Disp);
Dan Gohmanf350b272008-08-23 02:25:05 +0000176 void PreprocessForRMW();
177 void PreprocessForFPConvert();
Evan Cheng2ef88a02006-08-07 22:28:20 +0000178
Chris Lattnerc0bad572006-06-08 18:03:49 +0000179 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
180 /// inline asm expressions.
Dan Gohman475871a2008-07-27 21:46:04 +0000181 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
Chris Lattnerc0bad572006-06-08 18:03:49 +0000182 char ConstraintCode,
Dan Gohmanf350b272008-08-23 02:25:05 +0000183 std::vector<SDValue> &OutOps);
Chris Lattnerc0bad572006-06-08 18:03:49 +0000184
Anton Korobeynikov2fe12592007-09-25 21:52:30 +0000185 void EmitSpecialCodeForMain(MachineBasicBlock *BB, MachineFrameInfo *MFI);
186
Dan Gohman475871a2008-07-27 21:46:04 +0000187 inline void getAddressOperands(X86ISelAddressMode &AM, SDValue &Base,
188 SDValue &Scale, SDValue &Index,
Bill Wendling044b5342009-04-07 22:35:25 +0000189 SDValue &Disp) {
Evan Chenge5280532005-12-12 21:49:40 +0000190 Base = (AM.BaseType == X86ISelAddressMode::FrameIndexBase) ?
Evan Cheng25ab6902006-09-08 06:48:29 +0000191 CurDAG->getTargetFrameIndex(AM.Base.FrameIndex, TLI.getPointerTy()) :
192 AM.Base.Reg;
Evan Chengbdce7b42005-12-17 09:13:43 +0000193 Scale = getI8Imm(AM.Scale);
Evan Chenge5280532005-12-12 21:49:40 +0000194 Index = AM.IndexReg;
Evan Cheng25ab6902006-09-08 06:48:29 +0000195 // These are 32-bit even in 64-bit mode since RIP relative offset
196 // is 32-bit.
197 if (AM.GV)
198 Disp = CurDAG->getTargetGlobalAddress(AM.GV, MVT::i32, AM.Disp);
199 else if (AM.CP)
Gabor Greif93c53e52008-08-31 15:37:04 +0000200 Disp = CurDAG->getTargetConstantPool(AM.CP, MVT::i32,
201 AM.Align, AM.Disp);
Evan Cheng25ab6902006-09-08 06:48:29 +0000202 else if (AM.ES)
Bill Wendling056292f2008-09-16 21:48:12 +0000203 Disp = CurDAG->getTargetExternalSymbol(AM.ES, MVT::i32);
Evan Cheng25ab6902006-09-08 06:48:29 +0000204 else if (AM.JT != -1)
205 Disp = CurDAG->getTargetJumpTable(AM.JT, MVT::i32);
206 else
Dan Gohman27cae7b2008-11-11 15:52:29 +0000207 Disp = CurDAG->getTargetConstant(AM.Disp, MVT::i32);
Evan Chenge5280532005-12-12 21:49:40 +0000208 }
209
Chris Lattnerf9ce9fb2005-11-19 02:11:08 +0000210 /// getI8Imm - Return a target constant with the specified value, of type
211 /// i8.
Dan Gohman475871a2008-07-27 21:46:04 +0000212 inline SDValue getI8Imm(unsigned Imm) {
Chris Lattnerf9ce9fb2005-11-19 02:11:08 +0000213 return CurDAG->getTargetConstant(Imm, MVT::i8);
214 }
215
Chris Lattnerc961eea2005-11-16 01:54:32 +0000216 /// getI16Imm - Return a target constant with the specified value, of type
217 /// i16.
Dan Gohman475871a2008-07-27 21:46:04 +0000218 inline SDValue getI16Imm(unsigned Imm) {
Chris Lattnerc961eea2005-11-16 01:54:32 +0000219 return CurDAG->getTargetConstant(Imm, MVT::i16);
220 }
221
222 /// getI32Imm - Return a target constant with the specified value, of type
223 /// i32.
Dan Gohman475871a2008-07-27 21:46:04 +0000224 inline SDValue getI32Imm(unsigned Imm) {
Chris Lattnerc961eea2005-11-16 01:54:32 +0000225 return CurDAG->getTargetConstant(Imm, MVT::i32);
226 }
Evan Chengf597dc72006-02-10 22:24:32 +0000227
Dan Gohman8b746962008-09-23 18:22:58 +0000228 /// getGlobalBaseReg - Return an SDNode that returns the value of
229 /// the global base register. Output instructions required to
230 /// initialize the global base register, if necessary.
231 ///
Evan Cheng9ade2182006-08-26 05:34:46 +0000232 SDNode *getGlobalBaseReg();
Evan Cheng7ccced62006-02-18 00:15:05 +0000233
Dan Gohman0bfa1bf2008-08-20 21:27:32 +0000234 /// getTruncateTo8Bit - return an SDNode that implements a subreg based
235 /// truncate of the specified operand to i8. This can be done with tablegen,
236 /// except that this code uses MVT::Flag in a tricky way that happens to
237 /// improve scheduling in some cases.
238 SDNode *getTruncateTo8Bit(SDValue N0);
Christopher Lambc59e5212007-08-10 21:48:46 +0000239
Evan Cheng23addc02006-02-10 22:46:26 +0000240#ifndef NDEBUG
241 unsigned Indent;
242#endif
Chris Lattnerc961eea2005-11-16 01:54:32 +0000243 };
244}
245
Gabor Greif93c53e52008-08-31 15:37:04 +0000246/// findFlagUse - Return use of MVT::Flag value produced by the specified
247/// SDNode.
Evan Chengcdda25d2008-04-25 08:22:20 +0000248///
Evan Chenga275ecb2006-10-10 01:46:56 +0000249static SDNode *findFlagUse(SDNode *N) {
250 unsigned FlagResNo = N->getNumValues()-1;
251 for (SDNode::use_iterator I = N->use_begin(), E = N->use_end(); I != E; ++I) {
Dan Gohmane8ecf482009-01-27 02:37:43 +0000252 SDUse &Use = I.getUse();
253 if (Use.getResNo() == FlagResNo)
254 return Use.getUser();
Evan Chenga275ecb2006-10-10 01:46:56 +0000255 }
256 return NULL;
257}
258
Dan Gohmanc03e9a12009-01-27 19:04:30 +0000259/// findNonImmUse - Return true if "Use" is a non-immediate use of "Def".
260/// This function recursively traverses up the operand chain, ignoring
261/// certain nodes.
262static bool findNonImmUse(SDNode *Use, SDNode* Def, SDNode *ImmedUse,
263 SDNode *Root,
Evan Chengcdda25d2008-04-25 08:22:20 +0000264 SmallPtrSet<SDNode*, 16> &Visited) {
Dan Gohmanc03e9a12009-01-27 19:04:30 +0000265 if (Use->getNodeId() < Def->getNodeId() ||
Evan Chengcdda25d2008-04-25 08:22:20 +0000266 !Visited.insert(Use))
Dan Gohmanc03e9a12009-01-27 19:04:30 +0000267 return false;
268
269 for (unsigned i = 0, e = Use->getNumOperands(); i != e; ++i) {
Gabor Greifba36cb52008-08-28 21:40:38 +0000270 SDNode *N = Use->getOperand(i).getNode();
Evan Cheng27e1fe92006-10-14 08:33:25 +0000271 if (N == Def) {
Dan Gohman682d5a82008-09-17 01:39:10 +0000272 if (Use == ImmedUse || Use == Root)
Evan Cheng419ace92008-04-25 08:55:28 +0000273 continue; // We are not looking for immediate use.
Dan Gohman682d5a82008-09-17 01:39:10 +0000274 assert(N != Root);
Dan Gohmanc03e9a12009-01-27 19:04:30 +0000275 return true;
Evan Chengf4b4c412006-08-08 00:31:00 +0000276 }
Evan Chengcdda25d2008-04-25 08:22:20 +0000277
278 // Traverse up the operand chain.
Dan Gohmanc03e9a12009-01-27 19:04:30 +0000279 if (findNonImmUse(N, Def, ImmedUse, Root, Visited))
280 return true;
Evan Chengf4b4c412006-08-08 00:31:00 +0000281 }
Dan Gohmanc03e9a12009-01-27 19:04:30 +0000282 return false;
Evan Chengf4b4c412006-08-08 00:31:00 +0000283}
284
Evan Cheng27e1fe92006-10-14 08:33:25 +0000285/// isNonImmUse - Start searching from Root up the DAG to check is Def can
286/// be reached. Return true if that's the case. However, ignore direct uses
287/// by ImmedUse (which would be U in the example illustrated in
Evan Cheng884c70c2008-11-27 00:49:46 +0000288/// IsLegalAndProfitableToFold) and by Root (which can happen in the store
289/// case).
Evan Cheng27e1fe92006-10-14 08:33:25 +0000290/// FIXME: to be really generic, we should allow direct use by any node
291/// that is being folded. But realisticly since we only fold loads which
292/// have one non-chain use, we only need to watch out for load/op/store
293/// and load/op/cmp case where the root (store / cmp) may reach the load via
294/// its chain operand.
Dan Gohman682d5a82008-09-17 01:39:10 +0000295static inline bool isNonImmUse(SDNode *Root, SDNode *Def, SDNode *ImmedUse) {
Evan Chengcdda25d2008-04-25 08:22:20 +0000296 SmallPtrSet<SDNode*, 16> Visited;
Dan Gohmanc03e9a12009-01-27 19:04:30 +0000297 return findNonImmUse(Root, Def, ImmedUse, Root, Visited);
Evan Chengf4b4c412006-08-08 00:31:00 +0000298}
299
300
Evan Cheng884c70c2008-11-27 00:49:46 +0000301bool X86DAGToDAGISel::IsLegalAndProfitableToFold(SDNode *N, SDNode *U,
302 SDNode *Root) const {
Dan Gohmanea9587b2008-08-13 19:55:00 +0000303 if (Fast) return false;
Evan Cheng27e1fe92006-10-14 08:33:25 +0000304
Evan Cheng884c70c2008-11-27 00:49:46 +0000305 if (U == Root)
306 switch (U->getOpcode()) {
307 default: break;
308 case ISD::ADD:
309 case ISD::ADDC:
310 case ISD::ADDE:
311 case ISD::AND:
312 case ISD::OR:
313 case ISD::XOR: {
314 // If the other operand is a 8-bit immediate we should fold the immediate
315 // instead. This reduces code size.
316 // e.g.
317 // movl 4(%esp), %eax
318 // addl $4, %eax
319 // vs.
320 // movl $4, %eax
321 // addl 4(%esp), %eax
322 // The former is 2 bytes shorter. In case where the increment is 1, then
323 // the saving can be 4 bytes (by using incl %eax).
Dan Gohman9a49d312009-03-14 02:07:16 +0000324 if (ConstantSDNode *Imm = dyn_cast<ConstantSDNode>(U->getOperand(1)))
325 if (Imm->getAPIntValue().isSignedIntN(8))
326 return false;
Evan Cheng884c70c2008-11-27 00:49:46 +0000327 }
328 }
329
Dan Gohman682d5a82008-09-17 01:39:10 +0000330 // If Root use can somehow reach N through a path that that doesn't contain
331 // U then folding N would create a cycle. e.g. In the following
332 // diagram, Root can reach N through X. If N is folded into into Root, then
333 // X is both a predecessor and a successor of U.
Evan Chenga8df1b42006-07-27 16:44:36 +0000334 //
Dan Gohman682d5a82008-09-17 01:39:10 +0000335 // [N*] //
336 // ^ ^ //
337 // / \ //
338 // [U*] [X]? //
339 // ^ ^ //
340 // \ / //
341 // \ / //
342 // [Root*] //
343 //
344 // * indicates nodes to be folded together.
345 //
346 // If Root produces a flag, then it gets (even more) interesting. Since it
347 // will be "glued" together with its flag use in the scheduler, we need to
348 // check if it might reach N.
349 //
350 // [N*] //
351 // ^ ^ //
352 // / \ //
353 // [U*] [X]? //
354 // ^ ^ //
355 // \ \ //
356 // \ | //
357 // [Root*] | //
358 // ^ | //
359 // f | //
360 // | / //
361 // [Y] / //
362 // ^ / //
363 // f / //
364 // | / //
365 // [FU] //
366 //
367 // If FU (flag use) indirectly reaches N (the load), and Root folds N
368 // (call it Fold), then X is a predecessor of FU and a successor of
369 // Fold. But since Fold and FU are flagged together, this will create
370 // a cycle in the scheduling graph.
Evan Cheng27e1fe92006-10-14 08:33:25 +0000371
Duncan Sands83ec4b62008-06-06 12:08:01 +0000372 MVT VT = Root->getValueType(Root->getNumValues()-1);
Dan Gohman682d5a82008-09-17 01:39:10 +0000373 while (VT == MVT::Flag) {
Evan Cheng27e1fe92006-10-14 08:33:25 +0000374 SDNode *FU = findFlagUse(Root);
375 if (FU == NULL)
376 break;
Dan Gohman682d5a82008-09-17 01:39:10 +0000377 Root = FU;
Evan Cheng27e1fe92006-10-14 08:33:25 +0000378 VT = Root->getValueType(Root->getNumValues()-1);
Evan Chenga275ecb2006-10-10 01:46:56 +0000379 }
Evan Cheng27e1fe92006-10-14 08:33:25 +0000380
Dan Gohman682d5a82008-09-17 01:39:10 +0000381 return !isNonImmUse(Root, N, U);
Evan Chenga8df1b42006-07-27 16:44:36 +0000382}
383
Evan Cheng70e674e2006-08-28 20:10:17 +0000384/// MoveBelowTokenFactor - Replace TokenFactor operand with load's chain operand
385/// and move load below the TokenFactor. Replace store's chain operand with
386/// load's chain result.
Dan Gohmanf350b272008-08-23 02:25:05 +0000387static void MoveBelowTokenFactor(SelectionDAG *CurDAG, SDValue Load,
Dan Gohman475871a2008-07-27 21:46:04 +0000388 SDValue Store, SDValue TF) {
Evan Chengab6c3bb2008-08-25 21:27:18 +0000389 SmallVector<SDValue, 4> Ops;
Gabor Greifba36cb52008-08-28 21:40:38 +0000390 for (unsigned i = 0, e = TF.getNode()->getNumOperands(); i != e; ++i)
391 if (Load.getNode() == TF.getOperand(i).getNode())
Evan Chengab6c3bb2008-08-25 21:27:18 +0000392 Ops.push_back(Load.getOperand(0));
Evan Cheng70e674e2006-08-28 20:10:17 +0000393 else
Evan Chengab6c3bb2008-08-25 21:27:18 +0000394 Ops.push_back(TF.getOperand(i));
Dan Gohmanf350b272008-08-23 02:25:05 +0000395 CurDAG->UpdateNodeOperands(TF, &Ops[0], Ops.size());
396 CurDAG->UpdateNodeOperands(Load, TF, Load.getOperand(1), Load.getOperand(2));
397 CurDAG->UpdateNodeOperands(Store, Load.getValue(1), Store.getOperand(1),
398 Store.getOperand(2), Store.getOperand(3));
Evan Cheng70e674e2006-08-28 20:10:17 +0000399}
400
Evan Chengcd0baf22008-05-23 21:23:16 +0000401/// isRMWLoad - Return true if N is a load that's part of RMW sub-DAG.
402///
Dan Gohman475871a2008-07-27 21:46:04 +0000403static bool isRMWLoad(SDValue N, SDValue Chain, SDValue Address,
404 SDValue &Load) {
Evan Chengcd0baf22008-05-23 21:23:16 +0000405 if (N.getOpcode() == ISD::BIT_CONVERT)
406 N = N.getOperand(0);
407
408 LoadSDNode *LD = dyn_cast<LoadSDNode>(N);
409 if (!LD || LD->isVolatile())
410 return false;
411 if (LD->getAddressingMode() != ISD::UNINDEXED)
412 return false;
413
414 ISD::LoadExtType ExtType = LD->getExtensionType();
415 if (ExtType != ISD::NON_EXTLOAD && ExtType != ISD::EXTLOAD)
416 return false;
417
418 if (N.hasOneUse() &&
419 N.getOperand(1) == Address &&
Gabor Greifba36cb52008-08-28 21:40:38 +0000420 N.getNode()->isOperandOf(Chain.getNode())) {
Evan Chengcd0baf22008-05-23 21:23:16 +0000421 Load = N;
422 return true;
423 }
424 return false;
425}
426
Evan Chengab6c3bb2008-08-25 21:27:18 +0000427/// MoveBelowCallSeqStart - Replace CALLSEQ_START operand with load's chain
428/// operand and move load below the call's chain operand.
429static void MoveBelowCallSeqStart(SelectionDAG *CurDAG, SDValue Load,
Evan Cheng5b2e5892009-01-26 18:43:34 +0000430 SDValue Call, SDValue CallSeqStart) {
Evan Chengab6c3bb2008-08-25 21:27:18 +0000431 SmallVector<SDValue, 8> Ops;
Evan Cheng5b2e5892009-01-26 18:43:34 +0000432 SDValue Chain = CallSeqStart.getOperand(0);
433 if (Chain.getNode() == Load.getNode())
434 Ops.push_back(Load.getOperand(0));
435 else {
436 assert(Chain.getOpcode() == ISD::TokenFactor &&
437 "Unexpected CallSeqStart chain operand");
438 for (unsigned i = 0, e = Chain.getNumOperands(); i != e; ++i)
439 if (Chain.getOperand(i).getNode() == Load.getNode())
440 Ops.push_back(Load.getOperand(0));
441 else
442 Ops.push_back(Chain.getOperand(i));
443 SDValue NewChain =
Dale Johannesened2eee62009-02-06 01:31:28 +0000444 CurDAG->getNode(ISD::TokenFactor, Load.getDebugLoc(),
445 MVT::Other, &Ops[0], Ops.size());
Evan Cheng5b2e5892009-01-26 18:43:34 +0000446 Ops.clear();
447 Ops.push_back(NewChain);
448 }
449 for (unsigned i = 1, e = CallSeqStart.getNumOperands(); i != e; ++i)
450 Ops.push_back(CallSeqStart.getOperand(i));
451 CurDAG->UpdateNodeOperands(CallSeqStart, &Ops[0], Ops.size());
Evan Chengab6c3bb2008-08-25 21:27:18 +0000452 CurDAG->UpdateNodeOperands(Load, Call.getOperand(0),
453 Load.getOperand(1), Load.getOperand(2));
454 Ops.clear();
Gabor Greifba36cb52008-08-28 21:40:38 +0000455 Ops.push_back(SDValue(Load.getNode(), 1));
456 for (unsigned i = 1, e = Call.getNode()->getNumOperands(); i != e; ++i)
Evan Chengab6c3bb2008-08-25 21:27:18 +0000457 Ops.push_back(Call.getOperand(i));
458 CurDAG->UpdateNodeOperands(Call, &Ops[0], Ops.size());
459}
460
461/// isCalleeLoad - Return true if call address is a load and it can be
462/// moved below CALLSEQ_START and the chains leading up to the call.
463/// Return the CALLSEQ_START by reference as a second output.
464static bool isCalleeLoad(SDValue Callee, SDValue &Chain) {
Gabor Greifba36cb52008-08-28 21:40:38 +0000465 if (Callee.getNode() == Chain.getNode() || !Callee.hasOneUse())
Evan Chengab6c3bb2008-08-25 21:27:18 +0000466 return false;
Gabor Greifba36cb52008-08-28 21:40:38 +0000467 LoadSDNode *LD = dyn_cast<LoadSDNode>(Callee.getNode());
Evan Chengab6c3bb2008-08-25 21:27:18 +0000468 if (!LD ||
469 LD->isVolatile() ||
470 LD->getAddressingMode() != ISD::UNINDEXED ||
471 LD->getExtensionType() != ISD::NON_EXTLOAD)
472 return false;
473
474 // Now let's find the callseq_start.
475 while (Chain.getOpcode() != ISD::CALLSEQ_START) {
476 if (!Chain.hasOneUse())
477 return false;
478 Chain = Chain.getOperand(0);
479 }
Evan Cheng5b2e5892009-01-26 18:43:34 +0000480
481 if (Chain.getOperand(0).getNode() == Callee.getNode())
482 return true;
483 if (Chain.getOperand(0).getOpcode() == ISD::TokenFactor &&
484 Callee.getValue(1).isOperandOf(Chain.getOperand(0).getNode()))
485 return true;
486 return false;
Evan Chengab6c3bb2008-08-25 21:27:18 +0000487}
488
489
Chris Lattnerd43d00c2008-01-24 08:07:48 +0000490/// PreprocessForRMW - Preprocess the DAG to make instruction selection better.
491/// This is only run if not in -fast mode (aka -O0).
492/// This allows the instruction selector to pick more read-modify-write
493/// instructions. This is a common case:
Evan Cheng70e674e2006-08-28 20:10:17 +0000494///
495/// [Load chain]
496/// ^
497/// |
498/// [Load]
499/// ^ ^
500/// | |
501/// / \-
502/// / |
503/// [TokenFactor] [Op]
504/// ^ ^
505/// | |
506/// \ /
507/// \ /
508/// [Store]
509///
510/// The fact the store's chain operand != load's chain will prevent the
511/// (store (op (load))) instruction from being selected. We can transform it to:
512///
513/// [Load chain]
514/// ^
515/// |
516/// [TokenFactor]
517/// ^
518/// |
519/// [Load]
520/// ^ ^
521/// | |
522/// | \-
523/// | |
524/// | [Op]
525/// | ^
526/// | |
527/// \ /
528/// \ /
529/// [Store]
Dan Gohmanf350b272008-08-23 02:25:05 +0000530void X86DAGToDAGISel::PreprocessForRMW() {
531 for (SelectionDAG::allnodes_iterator I = CurDAG->allnodes_begin(),
532 E = CurDAG->allnodes_end(); I != E; ++I) {
Evan Chengab6c3bb2008-08-25 21:27:18 +0000533 if (I->getOpcode() == X86ISD::CALL) {
534 /// Also try moving call address load from outside callseq_start to just
535 /// before the call to allow it to be folded.
536 ///
537 /// [Load chain]
538 /// ^
539 /// |
540 /// [Load]
541 /// ^ ^
542 /// | |
543 /// / \--
544 /// / |
545 ///[CALLSEQ_START] |
546 /// ^ |
547 /// | |
548 /// [LOAD/C2Reg] |
549 /// | |
550 /// \ /
551 /// \ /
552 /// [CALL]
553 SDValue Chain = I->getOperand(0);
554 SDValue Load = I->getOperand(1);
555 if (!isCalleeLoad(Load, Chain))
556 continue;
557 MoveBelowCallSeqStart(CurDAG, Load, SDValue(I, 0), Chain);
558 ++NumLoadMoved;
559 continue;
560 }
561
Evan Cheng8b2794a2006-10-13 21:14:26 +0000562 if (!ISD::isNON_TRUNCStore(I))
Evan Cheng70e674e2006-08-28 20:10:17 +0000563 continue;
Dan Gohman475871a2008-07-27 21:46:04 +0000564 SDValue Chain = I->getOperand(0);
Evan Chengab6c3bb2008-08-25 21:27:18 +0000565
Gabor Greifba36cb52008-08-28 21:40:38 +0000566 if (Chain.getNode()->getOpcode() != ISD::TokenFactor)
Evan Cheng70e674e2006-08-28 20:10:17 +0000567 continue;
568
Dan Gohman475871a2008-07-27 21:46:04 +0000569 SDValue N1 = I->getOperand(1);
570 SDValue N2 = I->getOperand(2);
Duncan Sands83ec4b62008-06-06 12:08:01 +0000571 if ((N1.getValueType().isFloatingPoint() &&
572 !N1.getValueType().isVector()) ||
Evan Cheng780413d2006-08-29 18:37:37 +0000573 !N1.hasOneUse())
Evan Cheng70e674e2006-08-28 20:10:17 +0000574 continue;
575
576 bool RModW = false;
Dan Gohman475871a2008-07-27 21:46:04 +0000577 SDValue Load;
Gabor Greifba36cb52008-08-28 21:40:38 +0000578 unsigned Opcode = N1.getNode()->getOpcode();
Evan Cheng70e674e2006-08-28 20:10:17 +0000579 switch (Opcode) {
Evan Chengab6c3bb2008-08-25 21:27:18 +0000580 case ISD::ADD:
581 case ISD::MUL:
582 case ISD::AND:
583 case ISD::OR:
584 case ISD::XOR:
585 case ISD::ADDC:
586 case ISD::ADDE:
587 case ISD::VECTOR_SHUFFLE: {
588 SDValue N10 = N1.getOperand(0);
589 SDValue N11 = N1.getOperand(1);
590 RModW = isRMWLoad(N10, Chain, N2, Load);
591 if (!RModW)
592 RModW = isRMWLoad(N11, Chain, N2, Load);
593 break;
594 }
595 case ISD::SUB:
596 case ISD::SHL:
597 case ISD::SRA:
598 case ISD::SRL:
599 case ISD::ROTL:
600 case ISD::ROTR:
601 case ISD::SUBC:
602 case ISD::SUBE:
603 case X86ISD::SHLD:
604 case X86ISD::SHRD: {
605 SDValue N10 = N1.getOperand(0);
606 RModW = isRMWLoad(N10, Chain, N2, Load);
607 break;
608 }
Evan Cheng70e674e2006-08-28 20:10:17 +0000609 }
610
Evan Cheng82a35b32006-08-29 06:44:17 +0000611 if (RModW) {
Dan Gohmanf350b272008-08-23 02:25:05 +0000612 MoveBelowTokenFactor(CurDAG, Load, SDValue(I, 0), Chain);
Evan Cheng82a35b32006-08-29 06:44:17 +0000613 ++NumLoadMoved;
614 }
Evan Cheng70e674e2006-08-28 20:10:17 +0000615 }
616}
617
Chris Lattnerd43d00c2008-01-24 08:07:48 +0000618
619/// PreprocessForFPConvert - Walk over the dag lowering fpround and fpextend
620/// nodes that target the FP stack to be store and load to the stack. This is a
621/// gross hack. We would like to simply mark these as being illegal, but when
622/// we do that, legalize produces these when it expands calls, then expands
623/// these in the same legalize pass. We would like dag combine to be able to
624/// hack on these between the call expansion and the node legalization. As such
625/// this pass basically does "really late" legalization of these inline with the
626/// X86 isel pass.
Dan Gohmanf350b272008-08-23 02:25:05 +0000627void X86DAGToDAGISel::PreprocessForFPConvert() {
628 for (SelectionDAG::allnodes_iterator I = CurDAG->allnodes_begin(),
629 E = CurDAG->allnodes_end(); I != E; ) {
Chris Lattnerd43d00c2008-01-24 08:07:48 +0000630 SDNode *N = I++; // Preincrement iterator to avoid invalidation issues.
631 if (N->getOpcode() != ISD::FP_ROUND && N->getOpcode() != ISD::FP_EXTEND)
632 continue;
633
634 // If the source and destination are SSE registers, then this is a legal
635 // conversion that should not be lowered.
Duncan Sands83ec4b62008-06-06 12:08:01 +0000636 MVT SrcVT = N->getOperand(0).getValueType();
637 MVT DstVT = N->getValueType(0);
Chris Lattnerd43d00c2008-01-24 08:07:48 +0000638 bool SrcIsSSE = X86Lowering.isScalarFPTypeInSSEReg(SrcVT);
639 bool DstIsSSE = X86Lowering.isScalarFPTypeInSSEReg(DstVT);
640 if (SrcIsSSE && DstIsSSE)
641 continue;
642
Chris Lattner6fa2f9c2008-03-09 07:05:32 +0000643 if (!SrcIsSSE && !DstIsSSE) {
644 // If this is an FPStack extension, it is a noop.
645 if (N->getOpcode() == ISD::FP_EXTEND)
646 continue;
647 // If this is a value-preserving FPStack truncation, it is a noop.
648 if (N->getConstantOperandVal(1))
649 continue;
650 }
651
Chris Lattnerd43d00c2008-01-24 08:07:48 +0000652 // Here we could have an FP stack truncation or an FPStack <-> SSE convert.
653 // FPStack has extload and truncstore. SSE can fold direct loads into other
654 // operations. Based on this, decide what we want to do.
Duncan Sands83ec4b62008-06-06 12:08:01 +0000655 MVT MemVT;
Chris Lattnerd43d00c2008-01-24 08:07:48 +0000656 if (N->getOpcode() == ISD::FP_ROUND)
657 MemVT = DstVT; // FP_ROUND must use DstVT, we can't do a 'trunc load'.
658 else
659 MemVT = SrcIsSSE ? SrcVT : DstVT;
660
Dan Gohmanf350b272008-08-23 02:25:05 +0000661 SDValue MemTmp = CurDAG->CreateStackTemporary(MemVT);
Dale Johannesend8392542009-02-03 21:48:12 +0000662 DebugLoc dl = N->getDebugLoc();
Chris Lattnerd43d00c2008-01-24 08:07:48 +0000663
664 // FIXME: optimize the case where the src/dest is a load or store?
Dale Johannesend8392542009-02-03 21:48:12 +0000665 SDValue Store = CurDAG->getTruncStore(CurDAG->getEntryNode(), dl,
Dan Gohmanf350b272008-08-23 02:25:05 +0000666 N->getOperand(0),
667 MemTmp, NULL, 0, MemVT);
Dale Johannesend8392542009-02-03 21:48:12 +0000668 SDValue Result = CurDAG->getExtLoad(ISD::EXTLOAD, dl, DstVT, Store, MemTmp,
Dan Gohmanf350b272008-08-23 02:25:05 +0000669 NULL, 0, MemVT);
Chris Lattnerd43d00c2008-01-24 08:07:48 +0000670
671 // We're about to replace all uses of the FP_ROUND/FP_EXTEND with the
672 // extload we created. This will cause general havok on the dag because
673 // anything below the conversion could be folded into other existing nodes.
674 // To avoid invalidating 'I', back it up to the convert node.
675 --I;
Dan Gohmanf350b272008-08-23 02:25:05 +0000676 CurDAG->ReplaceAllUsesOfValueWith(SDValue(N, 0), Result);
Chris Lattnerd43d00c2008-01-24 08:07:48 +0000677
678 // Now that we did that, the node is dead. Increment the iterator to the
679 // next node to process, then delete N.
680 ++I;
Dan Gohmanf350b272008-08-23 02:25:05 +0000681 CurDAG->DeleteNode(N);
Chris Lattnerd43d00c2008-01-24 08:07:48 +0000682 }
683}
684
Chris Lattnerc961eea2005-11-16 01:54:32 +0000685/// InstructionSelectBasicBlock - This callback is invoked by SelectionDAGISel
686/// when it has created a SelectionDAG for us to codegen.
Dan Gohmanf350b272008-08-23 02:25:05 +0000687void X86DAGToDAGISel::InstructionSelect() {
Evan Chengdb8d56b2008-06-30 20:45:06 +0000688 CurBB = BB; // BB can change as result of isel.
Devang Patele76225a2008-10-06 18:03:39 +0000689 const Function *F = CurDAG->getMachineFunction().getFunction();
690 OptForSize = F->hasFnAttr(Attribute::OptimizeForSize);
Chris Lattnerc961eea2005-11-16 01:54:32 +0000691
Evan Chengdb8d56b2008-06-30 20:45:06 +0000692 DEBUG(BB->dump());
Dan Gohmanea9587b2008-08-13 19:55:00 +0000693 if (!Fast)
Dan Gohmanf350b272008-08-23 02:25:05 +0000694 PreprocessForRMW();
Chris Lattnerd43d00c2008-01-24 08:07:48 +0000695
696 // FIXME: This should only happen when not -fast.
Dan Gohmanf350b272008-08-23 02:25:05 +0000697 PreprocessForFPConvert();
Evan Cheng70e674e2006-08-28 20:10:17 +0000698
Chris Lattnerc961eea2005-11-16 01:54:32 +0000699 // Codegen the basic block.
Evan Chengf597dc72006-02-10 22:24:32 +0000700#ifndef NDEBUG
Bill Wendling6345d752006-11-17 07:52:03 +0000701 DOUT << "===== Instruction selection begins:\n";
Evan Cheng23addc02006-02-10 22:46:26 +0000702 Indent = 0;
Evan Chengf597dc72006-02-10 22:24:32 +0000703#endif
David Greene8ad4c002008-10-27 21:56:29 +0000704 SelectRoot(*CurDAG);
Evan Chengf597dc72006-02-10 22:24:32 +0000705#ifndef NDEBUG
Bill Wendling6345d752006-11-17 07:52:03 +0000706 DOUT << "===== Instruction selection ends:\n";
Evan Chengf597dc72006-02-10 22:24:32 +0000707#endif
Evan Cheng63ce5682006-07-28 00:10:59 +0000708
Dan Gohmanf350b272008-08-23 02:25:05 +0000709 CurDAG->RemoveDeadNodes();
Evan Chengdb8d56b2008-06-30 20:45:06 +0000710}
Chris Lattnerc961eea2005-11-16 01:54:32 +0000711
Anton Korobeynikov2fe12592007-09-25 21:52:30 +0000712/// EmitSpecialCodeForMain - Emit any code that needs to be executed only in
713/// the main function.
714void X86DAGToDAGISel::EmitSpecialCodeForMain(MachineBasicBlock *BB,
715 MachineFrameInfo *MFI) {
716 const TargetInstrInfo *TII = TM.getInstrInfo();
717 if (Subtarget->isTargetCygMing())
Dale Johannesen8d13f8f2009-02-13 02:33:27 +0000718 BuildMI(BB, DebugLoc::getUnknownLoc(),
719 TII->get(X86::CALLpcrel32)).addExternalSymbol("__main");
Anton Korobeynikov2fe12592007-09-25 21:52:30 +0000720}
721
722void X86DAGToDAGISel::EmitFunctionEntryCode(Function &Fn, MachineFunction &MF) {
723 // If this is main, emit special code for main.
724 MachineBasicBlock *BB = MF.begin();
725 if (Fn.hasExternalLinkage() && Fn.getName() == "main")
726 EmitSpecialCodeForMain(BB, MF.getFrameInfo());
727}
728
Chris Lattnerf9ce9fb2005-11-19 02:11:08 +0000729/// MatchAddress - Add the specified node to the specified addressing mode,
730/// returning true if it cannot be done. This just pattern matches for the
Chris Lattner5aaddaa2007-12-08 07:22:58 +0000731/// addressing mode.
Dan Gohman475871a2008-07-27 21:46:04 +0000732bool X86DAGToDAGISel::MatchAddress(SDValue N, X86ISelAddressMode &AM,
Rafael Espindola523249f2009-03-31 16:16:57 +0000733 unsigned Depth) {
Dan Gohman6520e202008-10-18 02:06:02 +0000734 bool is64Bit = Subtarget->is64Bit();
Dale Johannesen6f38cb62009-02-07 19:59:05 +0000735 DebugLoc dl = N.getDebugLoc();
Evan Chengda43bcf2008-09-24 00:05:32 +0000736 DOUT << "MatchAddress: "; DEBUG(AM.dump());
Dan Gohmanbadb2d22007-08-13 20:03:06 +0000737 // Limit recursion.
738 if (Depth > 5)
Rafael Espindola523249f2009-03-31 16:16:57 +0000739 return MatchAddressBase(N, AM);
Anton Korobeynikov33bf8c42007-03-28 18:36:33 +0000740
Evan Cheng25ab6902006-09-08 06:48:29 +0000741 // RIP relative addressing: %rip + 32-bit displacement!
742 if (AM.isRIPRel) {
743 if (!AM.ES && AM.JT != -1 && N.getOpcode() == ISD::Constant) {
Dan Gohman27cae7b2008-11-11 15:52:29 +0000744 uint64_t Val = cast<ConstantSDNode>(N)->getSExtValue();
Dan Gohman6520e202008-10-18 02:06:02 +0000745 if (!is64Bit || isInt32(AM.Disp + Val)) {
Evan Cheng25ab6902006-09-08 06:48:29 +0000746 AM.Disp += Val;
747 return false;
748 }
749 }
750 return true;
751 }
752
Chris Lattnerf9ce9fb2005-11-19 02:11:08 +0000753 switch (N.getOpcode()) {
754 default: break;
Evan Cheng25ab6902006-09-08 06:48:29 +0000755 case ISD::Constant: {
Dan Gohman27cae7b2008-11-11 15:52:29 +0000756 uint64_t Val = cast<ConstantSDNode>(N)->getSExtValue();
Dan Gohman6520e202008-10-18 02:06:02 +0000757 if (!is64Bit || isInt32(AM.Disp + Val)) {
Evan Cheng25ab6902006-09-08 06:48:29 +0000758 AM.Disp += Val;
759 return false;
760 }
761 break;
762 }
Evan Cheng51a9ed92006-02-25 10:09:08 +0000763
Evan Cheng19f2ffc2006-12-05 04:01:03 +0000764 case X86ISD::Wrapper: {
Dan Gohman6520e202008-10-18 02:06:02 +0000765 DOUT << "Wrapper: 64bit " << is64Bit;
766 DOUT << " AM "; DEBUG(AM.dump()); DOUT << "\n";
Evan Cheng0085a282006-11-30 21:55:46 +0000767 // Under X86-64 non-small code model, GV (and friends) are 64-bits.
Evan Chengbe3bf422008-02-07 08:53:49 +0000768 // Also, base and index reg must be 0 in order to use rip as base.
769 if (is64Bit && (TM.getCodeModel() != CodeModel::Small ||
Gabor Greifba36cb52008-08-28 21:40:38 +0000770 AM.Base.Reg.getNode() || AM.IndexReg.getNode()))
Evan Cheng0085a282006-11-30 21:55:46 +0000771 break;
Dan Gohman2d0a1cc2009-02-07 00:43:41 +0000772 if (AM.hasSymbolicDisplacement())
Evan Cheng28b514392006-12-05 19:50:18 +0000773 break;
Evan Cheng25ab6902006-09-08 06:48:29 +0000774 // If value is available in a register both base and index components have
775 // been picked, we can't fit the result available in the register in the
776 // addressing mode. Duplicate GlobalAddress or ConstantPool as displacement.
Dan Gohman8be6bbe2008-11-05 04:14:16 +0000777 {
Dan Gohman475871a2008-07-27 21:46:04 +0000778 SDValue N0 = N.getOperand(0);
Evan Cheng28b514392006-12-05 19:50:18 +0000779 if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(N0)) {
Dan Gohman27cae7b2008-11-11 15:52:29 +0000780 uint64_t Offset = G->getOffset();
781 if (!is64Bit || isInt32(AM.Disp + Offset)) {
Dan Gohman6520e202008-10-18 02:06:02 +0000782 GlobalValue *GV = G->getGlobal();
783 AM.GV = GV;
Dan Gohman27cae7b2008-11-11 15:52:29 +0000784 AM.Disp += Offset;
Dan Gohman6520e202008-10-18 02:06:02 +0000785 AM.isRIPRel = TM.symbolicAddressesAreRIPRel();
786 return false;
787 }
Evan Cheng28b514392006-12-05 19:50:18 +0000788 } else if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(N0)) {
Dan Gohman27cae7b2008-11-11 15:52:29 +0000789 uint64_t Offset = CP->getOffset();
790 if (!is64Bit || isInt32(AM.Disp + Offset)) {
Dan Gohman6520e202008-10-18 02:06:02 +0000791 AM.CP = CP->getConstVal();
792 AM.Align = CP->getAlignment();
Dan Gohman27cae7b2008-11-11 15:52:29 +0000793 AM.Disp += Offset;
Dan Gohman6520e202008-10-18 02:06:02 +0000794 AM.isRIPRel = TM.symbolicAddressesAreRIPRel();
795 return false;
796 }
Bill Wendling056292f2008-09-16 21:48:12 +0000797 } else if (ExternalSymbolSDNode *S =dyn_cast<ExternalSymbolSDNode>(N0)) {
Evan Chengbe3bf422008-02-07 08:53:49 +0000798 AM.ES = S->getSymbol();
Dan Gohman97135e12008-09-26 19:15:30 +0000799 AM.isRIPRel = TM.symbolicAddressesAreRIPRel();
Evan Chengbe3bf422008-02-07 08:53:49 +0000800 return false;
Evan Cheng28b514392006-12-05 19:50:18 +0000801 } else if (JumpTableSDNode *J = dyn_cast<JumpTableSDNode>(N0)) {
Evan Chengbe3bf422008-02-07 08:53:49 +0000802 AM.JT = J->getIndex();
Dan Gohman97135e12008-09-26 19:15:30 +0000803 AM.isRIPRel = TM.symbolicAddressesAreRIPRel();
Evan Chengbe3bf422008-02-07 08:53:49 +0000804 return false;
Evan Cheng51a9ed92006-02-25 10:09:08 +0000805 }
806 }
807 break;
Evan Cheng0085a282006-11-30 21:55:46 +0000808 }
Evan Cheng51a9ed92006-02-25 10:09:08 +0000809
Chris Lattnerf9ce9fb2005-11-19 02:11:08 +0000810 case ISD::FrameIndex:
Gabor Greif93c53e52008-08-31 15:37:04 +0000811 if (AM.BaseType == X86ISelAddressMode::RegBase
812 && AM.Base.Reg.getNode() == 0) {
Chris Lattnerf9ce9fb2005-11-19 02:11:08 +0000813 AM.BaseType = X86ISelAddressMode::FrameIndexBase;
814 AM.Base.FrameIndex = cast<FrameIndexSDNode>(N)->getIndex();
815 return false;
816 }
817 break;
Evan Chengec693f72005-12-08 02:01:35 +0000818
Chris Lattnerf9ce9fb2005-11-19 02:11:08 +0000819 case ISD::SHL:
Dan Gohman8be6bbe2008-11-05 04:14:16 +0000820 if (AM.IndexReg.getNode() != 0 || AM.Scale != 1 || AM.isRIPRel)
Chris Lattner5aaddaa2007-12-08 07:22:58 +0000821 break;
822
Gabor Greif93c53e52008-08-31 15:37:04 +0000823 if (ConstantSDNode
824 *CN = dyn_cast<ConstantSDNode>(N.getNode()->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000825 unsigned Val = CN->getZExtValue();
Chris Lattner5aaddaa2007-12-08 07:22:58 +0000826 if (Val == 1 || Val == 2 || Val == 3) {
827 AM.Scale = 1 << Val;
Gabor Greifba36cb52008-08-28 21:40:38 +0000828 SDValue ShVal = N.getNode()->getOperand(0);
Chris Lattnerf9ce9fb2005-11-19 02:11:08 +0000829
Chris Lattner5aaddaa2007-12-08 07:22:58 +0000830 // Okay, we know that we have a scale by now. However, if the scaled
831 // value is an add of something and a constant, we can fold the
832 // constant into the disp field here.
Gabor Greifba36cb52008-08-28 21:40:38 +0000833 if (ShVal.getNode()->getOpcode() == ISD::ADD && ShVal.hasOneUse() &&
834 isa<ConstantSDNode>(ShVal.getNode()->getOperand(1))) {
835 AM.IndexReg = ShVal.getNode()->getOperand(0);
Chris Lattner5aaddaa2007-12-08 07:22:58 +0000836 ConstantSDNode *AddVal =
Gabor Greifba36cb52008-08-28 21:40:38 +0000837 cast<ConstantSDNode>(ShVal.getNode()->getOperand(1));
Evan Cheng8e278262009-01-17 07:09:27 +0000838 uint64_t Disp = AM.Disp + (AddVal->getSExtValue() << Val);
Dan Gohman6520e202008-10-18 02:06:02 +0000839 if (!is64Bit || isInt32(Disp))
Chris Lattner5aaddaa2007-12-08 07:22:58 +0000840 AM.Disp = Disp;
841 else
Chris Lattnerf9ce9fb2005-11-19 02:11:08 +0000842 AM.IndexReg = ShVal;
Chris Lattner5aaddaa2007-12-08 07:22:58 +0000843 } else {
844 AM.IndexReg = ShVal;
Chris Lattnerf9ce9fb2005-11-19 02:11:08 +0000845 }
Chris Lattner5aaddaa2007-12-08 07:22:58 +0000846 return false;
Chris Lattnerf9ce9fb2005-11-19 02:11:08 +0000847 }
848 break;
Chris Lattner5aaddaa2007-12-08 07:22:58 +0000849 }
Evan Chengec693f72005-12-08 02:01:35 +0000850
Dan Gohman83688052007-10-22 20:22:24 +0000851 case ISD::SMUL_LOHI:
852 case ISD::UMUL_LOHI:
853 // A mul_lohi where we need the low part can be folded as a plain multiply.
Gabor Greif99a6cb92008-08-26 22:36:50 +0000854 if (N.getResNo() != 0) break;
Dan Gohman83688052007-10-22 20:22:24 +0000855 // FALL THROUGH
Chris Lattnerf9ce9fb2005-11-19 02:11:08 +0000856 case ISD::MUL:
Evan Cheng73f24c92009-03-30 21:36:47 +0000857 case X86ISD::MUL_IMM:
Chris Lattnerf9ce9fb2005-11-19 02:11:08 +0000858 // X*[3,5,9] -> X+X*[2,4,8]
Dan Gohman8be6bbe2008-11-05 04:14:16 +0000859 if (AM.BaseType == X86ISelAddressMode::RegBase &&
Gabor Greifba36cb52008-08-28 21:40:38 +0000860 AM.Base.Reg.getNode() == 0 &&
861 AM.IndexReg.getNode() == 0 &&
Evan Chengbe3bf422008-02-07 08:53:49 +0000862 !AM.isRIPRel) {
Gabor Greif93c53e52008-08-31 15:37:04 +0000863 if (ConstantSDNode
864 *CN = dyn_cast<ConstantSDNode>(N.getNode()->getOperand(1)))
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000865 if (CN->getZExtValue() == 3 || CN->getZExtValue() == 5 ||
866 CN->getZExtValue() == 9) {
867 AM.Scale = unsigned(CN->getZExtValue())-1;
Chris Lattnerf9ce9fb2005-11-19 02:11:08 +0000868
Gabor Greifba36cb52008-08-28 21:40:38 +0000869 SDValue MulVal = N.getNode()->getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000870 SDValue Reg;
Chris Lattnerf9ce9fb2005-11-19 02:11:08 +0000871
872 // Okay, we know that we have a scale by now. However, if the scaled
873 // value is an add of something and a constant, we can fold the
874 // constant into the disp field here.
Gabor Greifba36cb52008-08-28 21:40:38 +0000875 if (MulVal.getNode()->getOpcode() == ISD::ADD && MulVal.hasOneUse() &&
876 isa<ConstantSDNode>(MulVal.getNode()->getOperand(1))) {
877 Reg = MulVal.getNode()->getOperand(0);
Chris Lattnerf9ce9fb2005-11-19 02:11:08 +0000878 ConstantSDNode *AddVal =
Gabor Greifba36cb52008-08-28 21:40:38 +0000879 cast<ConstantSDNode>(MulVal.getNode()->getOperand(1));
Evan Cheng8e278262009-01-17 07:09:27 +0000880 uint64_t Disp = AM.Disp + AddVal->getSExtValue() *
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000881 CN->getZExtValue();
Dan Gohman6520e202008-10-18 02:06:02 +0000882 if (!is64Bit || isInt32(Disp))
Evan Cheng25ab6902006-09-08 06:48:29 +0000883 AM.Disp = Disp;
884 else
Gabor Greifba36cb52008-08-28 21:40:38 +0000885 Reg = N.getNode()->getOperand(0);
Chris Lattnerf9ce9fb2005-11-19 02:11:08 +0000886 } else {
Gabor Greifba36cb52008-08-28 21:40:38 +0000887 Reg = N.getNode()->getOperand(0);
Chris Lattnerf9ce9fb2005-11-19 02:11:08 +0000888 }
889
890 AM.IndexReg = AM.Base.Reg = Reg;
891 return false;
892 }
Chris Lattner62412262007-02-04 20:18:17 +0000893 }
Chris Lattnerf9ce9fb2005-11-19 02:11:08 +0000894 break;
895
Evan Cheng8e278262009-01-17 07:09:27 +0000896 case ISD::ADD: {
897 X86ISelAddressMode Backup = AM;
Rafael Espindola523249f2009-03-31 16:16:57 +0000898 if (!MatchAddress(N.getNode()->getOperand(0), AM, Depth+1) &&
899 !MatchAddress(N.getNode()->getOperand(1), AM, Depth+1))
Evan Cheng8e278262009-01-17 07:09:27 +0000900 return false;
901 AM = Backup;
Rafael Espindola523249f2009-03-31 16:16:57 +0000902 if (!MatchAddress(N.getNode()->getOperand(1), AM, Depth+1) &&
903 !MatchAddress(N.getNode()->getOperand(0), AM, Depth+1))
Evan Cheng8e278262009-01-17 07:09:27 +0000904 return false;
905 AM = Backup;
Dan Gohman77502c92009-03-13 02:25:09 +0000906
907 // If we couldn't fold both operands into the address at the same time,
908 // see if we can just put each operand into a register and fold at least
909 // the add.
910 if (AM.BaseType == X86ISelAddressMode::RegBase &&
911 !AM.Base.Reg.getNode() &&
912 !AM.IndexReg.getNode() &&
913 !AM.isRIPRel) {
914 AM.Base.Reg = N.getNode()->getOperand(0);
915 AM.IndexReg = N.getNode()->getOperand(1);
916 AM.Scale = 1;
917 return false;
918 }
Chris Lattnerf9ce9fb2005-11-19 02:11:08 +0000919 break;
Evan Cheng8e278262009-01-17 07:09:27 +0000920 }
Evan Chenge6ad27e2006-05-30 06:59:36 +0000921
Chris Lattner62412262007-02-04 20:18:17 +0000922 case ISD::OR:
923 // Handle "X | C" as "X + C" iff X is known to have C bits clear.
Chris Lattner5aaddaa2007-12-08 07:22:58 +0000924 if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
925 X86ISelAddressMode Backup = AM;
Dan Gohman27cae7b2008-11-11 15:52:29 +0000926 uint64_t Offset = CN->getSExtValue();
Chris Lattner5aaddaa2007-12-08 07:22:58 +0000927 // Start with the LHS as an addr mode.
Rafael Espindola523249f2009-03-31 16:16:57 +0000928 if (!MatchAddress(N.getOperand(0), AM, Depth+1) &&
Chris Lattner5aaddaa2007-12-08 07:22:58 +0000929 // Address could not have picked a GV address for the displacement.
930 AM.GV == NULL &&
931 // On x86-64, the resultant disp must fit in 32-bits.
Dan Gohman27cae7b2008-11-11 15:52:29 +0000932 (!is64Bit || isInt32(AM.Disp + Offset)) &&
Chris Lattner5aaddaa2007-12-08 07:22:58 +0000933 // Check to see if the LHS & C is zero.
Dan Gohman2e68b6f2008-02-25 21:11:39 +0000934 CurDAG->MaskedValueIsZero(N.getOperand(0), CN->getAPIntValue())) {
Dan Gohman27cae7b2008-11-11 15:52:29 +0000935 AM.Disp += Offset;
Chris Lattner5aaddaa2007-12-08 07:22:58 +0000936 return false;
Evan Chenge6ad27e2006-05-30 06:59:36 +0000937 }
Chris Lattner5aaddaa2007-12-08 07:22:58 +0000938 AM = Backup;
Evan Chenge6ad27e2006-05-30 06:59:36 +0000939 }
940 break;
Evan Cheng1314b002007-12-13 00:43:27 +0000941
942 case ISD::AND: {
943 // Handle "(x << C1) & C2" as "(X & (C2>>C1)) << C1" if safe and if this
944 // allows us to fold the shift into this addressing mode.
Dan Gohman475871a2008-07-27 21:46:04 +0000945 SDValue Shift = N.getOperand(0);
Evan Cheng1314b002007-12-13 00:43:27 +0000946 if (Shift.getOpcode() != ISD::SHL) break;
Dan Gohman8be6bbe2008-11-05 04:14:16 +0000947
Evan Cheng1314b002007-12-13 00:43:27 +0000948 // Scale must not be used already.
Gabor Greifba36cb52008-08-28 21:40:38 +0000949 if (AM.IndexReg.getNode() != 0 || AM.Scale != 1) break;
Evan Chengbe3bf422008-02-07 08:53:49 +0000950
951 // Not when RIP is used as the base.
952 if (AM.isRIPRel) break;
Evan Cheng1314b002007-12-13 00:43:27 +0000953
954 ConstantSDNode *C2 = dyn_cast<ConstantSDNode>(N.getOperand(1));
955 ConstantSDNode *C1 = dyn_cast<ConstantSDNode>(Shift.getOperand(1));
956 if (!C1 || !C2) break;
957
958 // Not likely to be profitable if either the AND or SHIFT node has more
959 // than one use (unless all uses are for address computation). Besides,
960 // isel mechanism requires their node ids to be reused.
961 if (!N.hasOneUse() || !Shift.hasOneUse())
962 break;
963
964 // Verify that the shift amount is something we can fold.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000965 unsigned ShiftCst = C1->getZExtValue();
Evan Cheng1314b002007-12-13 00:43:27 +0000966 if (ShiftCst != 1 && ShiftCst != 2 && ShiftCst != 3)
967 break;
968
969 // Get the new AND mask, this folds to a constant.
Dan Gohman8be6bbe2008-11-05 04:14:16 +0000970 SDValue X = Shift.getOperand(0);
Dale Johannesend8392542009-02-03 21:48:12 +0000971 SDValue NewANDMask = CurDAG->getNode(ISD::SRL, dl, N.getValueType(),
Evan Cheng552e3be2008-10-14 17:15:39 +0000972 SDValue(C2, 0), SDValue(C1, 0));
Dale Johannesend8392542009-02-03 21:48:12 +0000973 SDValue NewAND = CurDAG->getNode(ISD::AND, dl, N.getValueType(), X,
974 NewANDMask);
975 SDValue NewSHIFT = CurDAG->getNode(ISD::SHL, dl, N.getValueType(),
Dan Gohman7b8e9642008-10-13 20:52:04 +0000976 NewAND, SDValue(C1, 0));
Dan Gohman8be6bbe2008-11-05 04:14:16 +0000977
978 // Insert the new nodes into the topological ordering.
979 if (C1->getNodeId() > X.getNode()->getNodeId()) {
980 CurDAG->RepositionNode(X.getNode(), C1);
981 C1->setNodeId(X.getNode()->getNodeId());
982 }
983 if (NewANDMask.getNode()->getNodeId() == -1 ||
984 NewANDMask.getNode()->getNodeId() > X.getNode()->getNodeId()) {
985 CurDAG->RepositionNode(X.getNode(), NewANDMask.getNode());
986 NewANDMask.getNode()->setNodeId(X.getNode()->getNodeId());
987 }
988 if (NewAND.getNode()->getNodeId() == -1 ||
989 NewAND.getNode()->getNodeId() > Shift.getNode()->getNodeId()) {
990 CurDAG->RepositionNode(Shift.getNode(), NewAND.getNode());
991 NewAND.getNode()->setNodeId(Shift.getNode()->getNodeId());
992 }
993 if (NewSHIFT.getNode()->getNodeId() == -1 ||
994 NewSHIFT.getNode()->getNodeId() > N.getNode()->getNodeId()) {
995 CurDAG->RepositionNode(N.getNode(), NewSHIFT.getNode());
996 NewSHIFT.getNode()->setNodeId(N.getNode()->getNodeId());
997 }
998
Dan Gohman7b8e9642008-10-13 20:52:04 +0000999 CurDAG->ReplaceAllUsesWith(N, NewSHIFT);
Evan Cheng1314b002007-12-13 00:43:27 +00001000
1001 AM.Scale = 1 << ShiftCst;
1002 AM.IndexReg = NewAND;
1003 return false;
1004 }
Evan Chenge6ad27e2006-05-30 06:59:36 +00001005 }
Chris Lattnerf9ce9fb2005-11-19 02:11:08 +00001006
Rafael Espindola523249f2009-03-31 16:16:57 +00001007 return MatchAddressBase(N, AM);
Dan Gohmanbadb2d22007-08-13 20:03:06 +00001008}
1009
1010/// MatchAddressBase - Helper for MatchAddress. Add the specified node to the
1011/// specified addressing mode without any further recursion.
Rafael Espindola523249f2009-03-31 16:16:57 +00001012bool X86DAGToDAGISel::MatchAddressBase(SDValue N, X86ISelAddressMode &AM) {
Chris Lattnerf9ce9fb2005-11-19 02:11:08 +00001013 // Is the base register already occupied?
Gabor Greifba36cb52008-08-28 21:40:38 +00001014 if (AM.BaseType != X86ISelAddressMode::RegBase || AM.Base.Reg.getNode()) {
Chris Lattnerf9ce9fb2005-11-19 02:11:08 +00001015 // If so, check to see if the scale index register is set.
Gabor Greifba36cb52008-08-28 21:40:38 +00001016 if (AM.IndexReg.getNode() == 0 && !AM.isRIPRel) {
Chris Lattnerf9ce9fb2005-11-19 02:11:08 +00001017 AM.IndexReg = N;
1018 AM.Scale = 1;
1019 return false;
1020 }
1021
1022 // Otherwise, we cannot select it.
1023 return true;
1024 }
1025
1026 // Default, generate it as a register.
1027 AM.BaseType = X86ISelAddressMode::RegBase;
1028 AM.Base.Reg = N;
1029 return false;
1030}
1031
Evan Chengec693f72005-12-08 02:01:35 +00001032/// SelectAddr - returns true if it is able pattern match an addressing mode.
1033/// It returns the operands which make up the maximal addressing mode it can
1034/// match by reference.
Dan Gohman475871a2008-07-27 21:46:04 +00001035bool X86DAGToDAGISel::SelectAddr(SDValue Op, SDValue N, SDValue &Base,
1036 SDValue &Scale, SDValue &Index,
Bill Wendling044b5342009-04-07 22:35:25 +00001037 SDValue &Disp) {
Evan Chengec693f72005-12-08 02:01:35 +00001038 X86ISelAddressMode AM;
Evan Cheng4d952322009-03-31 01:13:53 +00001039 bool Done = false;
1040 if (AvoidDupAddrCompute && !N.hasOneUse()) {
1041 unsigned Opcode = N.getOpcode();
1042 if (Opcode != ISD::Constant && Opcode != ISD::FrameIndex &&
1043 Opcode != X86ISD::Wrapper) {
1044 // If we are able to fold N into addressing mode, then we'll allow it even
1045 // if N has multiple uses. In general, addressing computation is used as
1046 // addresses by all of its uses. But watch out for CopyToReg uses, that
1047 // means the address computation is liveout. It will be computed by a LEA
1048 // so we want to avoid computing the address twice.
1049 for (SDNode::use_iterator UI = N.getNode()->use_begin(),
1050 UE = N.getNode()->use_end(); UI != UE; ++UI) {
1051 if (UI->getOpcode() == ISD::CopyToReg) {
Rafael Espindola523249f2009-03-31 16:16:57 +00001052 MatchAddressBase(N, AM);
Evan Cheng4d952322009-03-31 01:13:53 +00001053 Done = true;
1054 break;
1055 }
1056 }
1057 }
1058 }
1059
1060 if (!Done && MatchAddress(N, AM))
Evan Cheng8700e142006-01-11 06:09:51 +00001061 return false;
Evan Chengec693f72005-12-08 02:01:35 +00001062
Duncan Sands83ec4b62008-06-06 12:08:01 +00001063 MVT VT = N.getValueType();
Evan Cheng8700e142006-01-11 06:09:51 +00001064 if (AM.BaseType == X86ISelAddressMode::RegBase) {
Gabor Greifba36cb52008-08-28 21:40:38 +00001065 if (!AM.Base.Reg.getNode())
Evan Cheng25ab6902006-09-08 06:48:29 +00001066 AM.Base.Reg = CurDAG->getRegister(0, VT);
Evan Chengec693f72005-12-08 02:01:35 +00001067 }
Evan Cheng8700e142006-01-11 06:09:51 +00001068
Gabor Greifba36cb52008-08-28 21:40:38 +00001069 if (!AM.IndexReg.getNode())
Evan Cheng25ab6902006-09-08 06:48:29 +00001070 AM.IndexReg = CurDAG->getRegister(0, VT);
Evan Cheng8700e142006-01-11 06:09:51 +00001071
Bill Wendling044b5342009-04-07 22:35:25 +00001072 getAddressOperands(AM, Base, Scale, Index, Disp);
Evan Cheng8700e142006-01-11 06:09:51 +00001073 return true;
Evan Chengec693f72005-12-08 02:01:35 +00001074}
1075
Chris Lattner3a7cd952006-10-07 21:55:32 +00001076/// SelectScalarSSELoad - Match a scalar SSE load. In particular, we want to
1077/// match a load whose top elements are either undef or zeros. The load flavor
1078/// is derived from the type of N, which is either v4f32 or v2f64.
Dan Gohman475871a2008-07-27 21:46:04 +00001079bool X86DAGToDAGISel::SelectScalarSSELoad(SDValue Op, SDValue Pred,
1080 SDValue N, SDValue &Base,
1081 SDValue &Scale, SDValue &Index,
Bill Wendling044b5342009-04-07 22:35:25 +00001082 SDValue &Disp, SDValue &InChain,
Dan Gohman475871a2008-07-27 21:46:04 +00001083 SDValue &OutChain) {
Chris Lattner3a7cd952006-10-07 21:55:32 +00001084 if (N.getOpcode() == ISD::SCALAR_TO_VECTOR) {
Chris Lattner4fe4f252006-10-11 22:09:58 +00001085 InChain = N.getOperand(0).getValue(1);
Gabor Greifba36cb52008-08-28 21:40:38 +00001086 if (ISD::isNON_EXTLoad(InChain.getNode()) &&
Evan Cheng07e4b002006-10-16 06:34:55 +00001087 InChain.getValue(0).hasOneUse() &&
Evan Chengd6373bc2006-11-10 21:23:04 +00001088 N.hasOneUse() &&
Evan Cheng884c70c2008-11-27 00:49:46 +00001089 IsLegalAndProfitableToFold(N.getNode(), Pred.getNode(), Op.getNode())) {
Evan Cheng82a91642006-10-11 21:06:01 +00001090 LoadSDNode *LD = cast<LoadSDNode>(InChain);
Bill Wendling044b5342009-04-07 22:35:25 +00001091 if (!SelectAddr(Op, LD->getBasePtr(), Base, Scale, Index, Disp))
Chris Lattner3a7cd952006-10-07 21:55:32 +00001092 return false;
Evan Cheng82a91642006-10-11 21:06:01 +00001093 OutChain = LD->getChain();
Chris Lattner3a7cd952006-10-07 21:55:32 +00001094 return true;
1095 }
1096 }
Chris Lattner4fe4f252006-10-11 22:09:58 +00001097
1098 // Also handle the case where we explicitly require zeros in the top
Chris Lattner3a7cd952006-10-07 21:55:32 +00001099 // elements. This is a vector shuffle from the zero vector.
Gabor Greifba36cb52008-08-28 21:40:38 +00001100 if (N.getOpcode() == X86ISD::VZEXT_MOVL && N.getNode()->hasOneUse() &&
Chris Lattner8a594482007-11-25 00:24:49 +00001101 // Check to see if the top elements are all zeros (or bitcast of zeros).
Evan Cheng7e2ff772008-05-08 00:57:18 +00001102 N.getOperand(0).getOpcode() == ISD::SCALAR_TO_VECTOR &&
Gabor Greifba36cb52008-08-28 21:40:38 +00001103 N.getOperand(0).getNode()->hasOneUse() &&
1104 ISD::isNON_EXTLoad(N.getOperand(0).getOperand(0).getNode()) &&
Evan Cheng7e2ff772008-05-08 00:57:18 +00001105 N.getOperand(0).getOperand(0).hasOneUse()) {
1106 // Okay, this is a zero extending load. Fold it.
1107 LoadSDNode *LD = cast<LoadSDNode>(N.getOperand(0).getOperand(0));
Bill Wendling044b5342009-04-07 22:35:25 +00001108 if (!SelectAddr(Op, LD->getBasePtr(), Base, Scale, Index, Disp))
Evan Cheng7e2ff772008-05-08 00:57:18 +00001109 return false;
1110 OutChain = LD->getChain();
Dan Gohman475871a2008-07-27 21:46:04 +00001111 InChain = SDValue(LD, 1);
Evan Cheng7e2ff772008-05-08 00:57:18 +00001112 return true;
Chris Lattner4fe4f252006-10-11 22:09:58 +00001113 }
Chris Lattner3a7cd952006-10-07 21:55:32 +00001114 return false;
1115}
1116
1117
Evan Cheng51a9ed92006-02-25 10:09:08 +00001118/// SelectLEAAddr - it calls SelectAddr and determines if the maximal addressing
1119/// mode it matches can be cost effectively emitted as an LEA instruction.
Dan Gohman475871a2008-07-27 21:46:04 +00001120bool X86DAGToDAGISel::SelectLEAAddr(SDValue Op, SDValue N,
1121 SDValue &Base, SDValue &Scale,
1122 SDValue &Index, SDValue &Disp) {
Evan Cheng51a9ed92006-02-25 10:09:08 +00001123 X86ISelAddressMode AM;
1124 if (MatchAddress(N, AM))
1125 return false;
1126
Duncan Sands83ec4b62008-06-06 12:08:01 +00001127 MVT VT = N.getValueType();
Evan Cheng51a9ed92006-02-25 10:09:08 +00001128 unsigned Complexity = 0;
1129 if (AM.BaseType == X86ISelAddressMode::RegBase)
Gabor Greifba36cb52008-08-28 21:40:38 +00001130 if (AM.Base.Reg.getNode())
Evan Cheng51a9ed92006-02-25 10:09:08 +00001131 Complexity = 1;
1132 else
Evan Cheng25ab6902006-09-08 06:48:29 +00001133 AM.Base.Reg = CurDAG->getRegister(0, VT);
Evan Cheng51a9ed92006-02-25 10:09:08 +00001134 else if (AM.BaseType == X86ISelAddressMode::FrameIndexBase)
1135 Complexity = 4;
1136
Gabor Greifba36cb52008-08-28 21:40:38 +00001137 if (AM.IndexReg.getNode())
Evan Cheng51a9ed92006-02-25 10:09:08 +00001138 Complexity++;
1139 else
Evan Cheng25ab6902006-09-08 06:48:29 +00001140 AM.IndexReg = CurDAG->getRegister(0, VT);
Evan Cheng51a9ed92006-02-25 10:09:08 +00001141
Chris Lattnera16b7cb2007-03-20 06:08:29 +00001142 // Don't match just leal(,%reg,2). It's cheaper to do addl %reg, %reg, or with
1143 // a simple shift.
1144 if (AM.Scale > 1)
Evan Cheng8c03fe42006-02-28 21:13:57 +00001145 Complexity++;
Evan Cheng51a9ed92006-02-25 10:09:08 +00001146
1147 // FIXME: We are artificially lowering the criteria to turn ADD %reg, $GA
1148 // to a LEA. This is determined with some expermentation but is by no means
1149 // optimal (especially for code size consideration). LEA is nice because of
1150 // its three-address nature. Tweak the cost function again when we can run
1151 // convertToThreeAddress() at register allocation time.
Dan Gohman2d0a1cc2009-02-07 00:43:41 +00001152 if (AM.hasSymbolicDisplacement()) {
Evan Cheng25ab6902006-09-08 06:48:29 +00001153 // For X86-64, we should always use lea to materialize RIP relative
1154 // addresses.
Evan Cheng953fa042006-12-05 22:03:40 +00001155 if (Subtarget->is64Bit())
Evan Cheng25ab6902006-09-08 06:48:29 +00001156 Complexity = 4;
1157 else
1158 Complexity += 2;
1159 }
Evan Cheng51a9ed92006-02-25 10:09:08 +00001160
Gabor Greifba36cb52008-08-28 21:40:38 +00001161 if (AM.Disp && (AM.Base.Reg.getNode() || AM.IndexReg.getNode()))
Evan Cheng51a9ed92006-02-25 10:09:08 +00001162 Complexity++;
1163
1164 if (Complexity > 2) {
Bill Wendling044b5342009-04-07 22:35:25 +00001165 getAddressOperands(AM, Base, Scale, Index, Disp);
Evan Cheng51a9ed92006-02-25 10:09:08 +00001166 return true;
1167 }
Evan Cheng51a9ed92006-02-25 10:09:08 +00001168 return false;
1169}
1170
Dan Gohman475871a2008-07-27 21:46:04 +00001171bool X86DAGToDAGISel::TryFoldLoad(SDValue P, SDValue N,
1172 SDValue &Base, SDValue &Scale,
Bill Wendling044b5342009-04-07 22:35:25 +00001173 SDValue &Index, SDValue &Disp) {
Gabor Greifba36cb52008-08-28 21:40:38 +00001174 if (ISD::isNON_EXTLoad(N.getNode()) &&
Evan Cheng5e351682006-02-06 06:02:33 +00001175 N.hasOneUse() &&
Evan Cheng884c70c2008-11-27 00:49:46 +00001176 IsLegalAndProfitableToFold(N.getNode(), P.getNode(), P.getNode()))
Bill Wendling044b5342009-04-07 22:35:25 +00001177 return SelectAddr(P, N.getOperand(1), Base, Scale, Index, Disp);
Evan Cheng0114e942006-01-06 20:36:21 +00001178 return false;
1179}
1180
Dan Gohman8b746962008-09-23 18:22:58 +00001181/// getGlobalBaseReg - Return an SDNode that returns the value of
1182/// the global base register. Output instructions required to
1183/// initialize the global base register, if necessary.
Evan Cheng7ccced62006-02-18 00:15:05 +00001184///
Evan Cheng9ade2182006-08-26 05:34:46 +00001185SDNode *X86DAGToDAGISel::getGlobalBaseReg() {
Dan Gohman57c3dac2008-09-30 00:58:23 +00001186 MachineFunction *MF = CurBB->getParent();
1187 unsigned GlobalBaseReg = TM.getInstrInfo()->getGlobalBaseReg(MF);
Gabor Greifba36cb52008-08-28 21:40:38 +00001188 return CurDAG->getRegister(GlobalBaseReg, TLI.getPointerTy()).getNode();
Evan Cheng7ccced62006-02-18 00:15:05 +00001189}
1190
Evan Chengb245d922006-05-20 01:36:52 +00001191static SDNode *FindCallStartFromCall(SDNode *Node) {
1192 if (Node->getOpcode() == ISD::CALLSEQ_START) return Node;
1193 assert(Node->getOperand(0).getValueType() == MVT::Other &&
1194 "Node doesn't have a token chain argument!");
Gabor Greifba36cb52008-08-28 21:40:38 +00001195 return FindCallStartFromCall(Node->getOperand(0).getNode());
Evan Chengb245d922006-05-20 01:36:52 +00001196}
1197
Dan Gohman0bfa1bf2008-08-20 21:27:32 +00001198/// getTruncateTo8Bit - return an SDNode that implements a subreg based
1199/// truncate of the specified operand to i8. This can be done with tablegen,
1200/// except that this code uses MVT::Flag in a tricky way that happens to
1201/// improve scheduling in some cases.
1202SDNode *X86DAGToDAGISel::getTruncateTo8Bit(SDValue N0) {
1203 assert(!Subtarget->is64Bit() &&
1204 "getTruncateTo8Bit is only needed on x86-32!");
1205 SDValue SRIdx = CurDAG->getTargetConstant(1, MVT::i32); // SubRegSet 1
Dale Johannesen6f38cb62009-02-07 19:59:05 +00001206 DebugLoc dl = N0.getDebugLoc();
Dan Gohman0bfa1bf2008-08-20 21:27:32 +00001207
1208 // Ensure that the source register has an 8-bit subreg on 32-bit targets
1209 unsigned Opc;
1210 MVT N0VT = N0.getValueType();
1211 switch (N0VT.getSimpleVT()) {
1212 default: assert(0 && "Unknown truncate!");
1213 case MVT::i16:
1214 Opc = X86::MOV16to16_;
1215 break;
1216 case MVT::i32:
1217 Opc = X86::MOV32to32_;
1218 break;
1219 }
1220
1221 // The use of MVT::Flag here is not strictly accurate, but it helps
1222 // scheduling in some cases.
Dale Johannesend8392542009-02-03 21:48:12 +00001223 N0 = SDValue(CurDAG->getTargetNode(Opc, dl, N0VT, MVT::Flag, N0), 0);
1224 return CurDAG->getTargetNode(X86::EXTRACT_SUBREG, dl,
Dan Gohman0bfa1bf2008-08-20 21:27:32 +00001225 MVT::i8, N0, SRIdx, N0.getValue(1));
Christopher Lambc59e5212007-08-10 21:48:46 +00001226}
1227
Dale Johannesen48c1bc22008-10-02 18:53:47 +00001228SDNode *X86DAGToDAGISel::SelectAtomic64(SDNode *Node, unsigned Opc) {
1229 SDValue Chain = Node->getOperand(0);
1230 SDValue In1 = Node->getOperand(1);
1231 SDValue In2L = Node->getOperand(2);
1232 SDValue In2H = Node->getOperand(3);
Bill Wendling044b5342009-04-07 22:35:25 +00001233 SDValue Tmp0, Tmp1, Tmp2, Tmp3;
1234 if (!SelectAddr(In1, In1, Tmp0, Tmp1, Tmp2, Tmp3))
Dale Johannesen48c1bc22008-10-02 18:53:47 +00001235 return NULL;
Dale Johannesen1b54c7f2008-10-03 19:41:08 +00001236 SDValue LSI = Node->getOperand(4); // MemOperand
Bill Wendling044b5342009-04-07 22:35:25 +00001237 const SDValue Ops[] = { Tmp0, Tmp1, Tmp2, Tmp3, In2L, In2H, LSI, Chain };
Rafael Espindolae4d5d342009-03-27 15:45:05 +00001238 return CurDAG->getTargetNode(Opc, Node->getDebugLoc(),
1239 MVT::i32, MVT::i32, MVT::Other, Ops,
Rafael Espindolaa0a4f072009-03-28 19:02:18 +00001240 array_lengthof(Ops));
Dale Johannesen48c1bc22008-10-02 18:53:47 +00001241}
Christopher Lambc59e5212007-08-10 21:48:46 +00001242
Dan Gohman475871a2008-07-27 21:46:04 +00001243SDNode *X86DAGToDAGISel::Select(SDValue N) {
Gabor Greifba36cb52008-08-28 21:40:38 +00001244 SDNode *Node = N.getNode();
Duncan Sands83ec4b62008-06-06 12:08:01 +00001245 MVT NVT = Node->getValueType(0);
Evan Cheng0114e942006-01-06 20:36:21 +00001246 unsigned Opc, MOpc;
1247 unsigned Opcode = Node->getOpcode();
Dale Johannesend8392542009-02-03 21:48:12 +00001248 DebugLoc dl = Node->getDebugLoc();
1249
Evan Chengf597dc72006-02-10 22:24:32 +00001250#ifndef NDEBUG
Bill Wendling6345d752006-11-17 07:52:03 +00001251 DOUT << std::string(Indent, ' ') << "Selecting: ";
Evan Chengf597dc72006-02-10 22:24:32 +00001252 DEBUG(Node->dump(CurDAG));
Bill Wendling6345d752006-11-17 07:52:03 +00001253 DOUT << "\n";
Evan Cheng23addc02006-02-10 22:46:26 +00001254 Indent += 2;
Evan Chengf597dc72006-02-10 22:24:32 +00001255#endif
1256
Dan Gohmane8be6c62008-07-17 19:10:17 +00001257 if (Node->isMachineOpcode()) {
Evan Chengf597dc72006-02-10 22:24:32 +00001258#ifndef NDEBUG
Bill Wendling6345d752006-11-17 07:52:03 +00001259 DOUT << std::string(Indent-2, ' ') << "== ";
Evan Chengf597dc72006-02-10 22:24:32 +00001260 DEBUG(Node->dump(CurDAG));
Bill Wendling6345d752006-11-17 07:52:03 +00001261 DOUT << "\n";
Evan Cheng23addc02006-02-10 22:46:26 +00001262 Indent -= 2;
Evan Chengf597dc72006-02-10 22:24:32 +00001263#endif
Evan Cheng64a752f2006-08-11 09:08:15 +00001264 return NULL; // Already selected.
Evan Cheng34167212006-02-09 00:37:58 +00001265 }
Evan Cheng38262ca2006-01-11 22:15:18 +00001266
Evan Cheng0114e942006-01-06 20:36:21 +00001267 switch (Opcode) {
Chris Lattnerc961eea2005-11-16 01:54:32 +00001268 default: break;
Evan Cheng020d2e82006-02-23 20:41:18 +00001269 case X86ISD::GlobalBaseReg:
Evan Cheng9ade2182006-08-26 05:34:46 +00001270 return getGlobalBaseReg();
Evan Cheng020d2e82006-02-23 20:41:18 +00001271
Dale Johannesen48c1bc22008-10-02 18:53:47 +00001272 case X86ISD::ATOMOR64_DAG:
1273 return SelectAtomic64(Node, X86::ATOMOR6432);
1274 case X86ISD::ATOMXOR64_DAG:
1275 return SelectAtomic64(Node, X86::ATOMXOR6432);
1276 case X86ISD::ATOMADD64_DAG:
1277 return SelectAtomic64(Node, X86::ATOMADD6432);
1278 case X86ISD::ATOMSUB64_DAG:
1279 return SelectAtomic64(Node, X86::ATOMSUB6432);
1280 case X86ISD::ATOMNAND64_DAG:
1281 return SelectAtomic64(Node, X86::ATOMNAND6432);
1282 case X86ISD::ATOMAND64_DAG:
1283 return SelectAtomic64(Node, X86::ATOMAND6432);
Dale Johannesen880ae362008-10-03 22:25:52 +00001284 case X86ISD::ATOMSWAP64_DAG:
1285 return SelectAtomic64(Node, X86::ATOMSWAP6432);
Dale Johannesen48c1bc22008-10-02 18:53:47 +00001286
Dan Gohman525178c2007-10-08 18:33:35 +00001287 case ISD::SMUL_LOHI:
1288 case ISD::UMUL_LOHI: {
Dan Gohman475871a2008-07-27 21:46:04 +00001289 SDValue N0 = Node->getOperand(0);
1290 SDValue N1 = Node->getOperand(1);
Dan Gohman525178c2007-10-08 18:33:35 +00001291
Dan Gohman525178c2007-10-08 18:33:35 +00001292 bool isSigned = Opcode == ISD::SMUL_LOHI;
1293 if (!isSigned)
Duncan Sands83ec4b62008-06-06 12:08:01 +00001294 switch (NVT.getSimpleVT()) {
Evan Cheng0114e942006-01-06 20:36:21 +00001295 default: assert(0 && "Unsupported VT!");
1296 case MVT::i8: Opc = X86::MUL8r; MOpc = X86::MUL8m; break;
1297 case MVT::i16: Opc = X86::MUL16r; MOpc = X86::MUL16m; break;
1298 case MVT::i32: Opc = X86::MUL32r; MOpc = X86::MUL32m; break;
Evan Cheng25ab6902006-09-08 06:48:29 +00001299 case MVT::i64: Opc = X86::MUL64r; MOpc = X86::MUL64m; break;
Evan Cheng0114e942006-01-06 20:36:21 +00001300 }
1301 else
Duncan Sands83ec4b62008-06-06 12:08:01 +00001302 switch (NVT.getSimpleVT()) {
Evan Cheng0114e942006-01-06 20:36:21 +00001303 default: assert(0 && "Unsupported VT!");
1304 case MVT::i8: Opc = X86::IMUL8r; MOpc = X86::IMUL8m; break;
1305 case MVT::i16: Opc = X86::IMUL16r; MOpc = X86::IMUL16m; break;
1306 case MVT::i32: Opc = X86::IMUL32r; MOpc = X86::IMUL32m; break;
Evan Cheng25ab6902006-09-08 06:48:29 +00001307 case MVT::i64: Opc = X86::IMUL64r; MOpc = X86::IMUL64m; break;
Evan Cheng0114e942006-01-06 20:36:21 +00001308 }
1309
1310 unsigned LoReg, HiReg;
Duncan Sands83ec4b62008-06-06 12:08:01 +00001311 switch (NVT.getSimpleVT()) {
Evan Cheng0114e942006-01-06 20:36:21 +00001312 default: assert(0 && "Unsupported VT!");
1313 case MVT::i8: LoReg = X86::AL; HiReg = X86::AH; break;
1314 case MVT::i16: LoReg = X86::AX; HiReg = X86::DX; break;
1315 case MVT::i32: LoReg = X86::EAX; HiReg = X86::EDX; break;
Evan Cheng25ab6902006-09-08 06:48:29 +00001316 case MVT::i64: LoReg = X86::RAX; HiReg = X86::RDX; break;
Evan Cheng0114e942006-01-06 20:36:21 +00001317 }
1318
Bill Wendling044b5342009-04-07 22:35:25 +00001319 SDValue Tmp0, Tmp1, Tmp2, Tmp3;
1320 bool foldedLoad = TryFoldLoad(N, N1, Tmp0, Tmp1, Tmp2, Tmp3);
Dan Gohman525178c2007-10-08 18:33:35 +00001321 // multiplty is commmutative
Evan Cheng948f3432006-01-06 23:19:29 +00001322 if (!foldedLoad) {
Bill Wendling044b5342009-04-07 22:35:25 +00001323 foldedLoad = TryFoldLoad(N, N0, Tmp0, Tmp1, Tmp2, Tmp3);
Evan Cheng7afa1662007-08-02 05:48:35 +00001324 if (foldedLoad)
1325 std::swap(N0, N1);
Evan Cheng948f3432006-01-06 23:19:29 +00001326 }
1327
Dale Johannesendd64c412009-02-04 00:33:20 +00001328 SDValue InFlag = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, LoReg,
Dan Gohman475871a2008-07-27 21:46:04 +00001329 N0, SDValue()).getValue(1);
Evan Cheng0114e942006-01-06 20:36:21 +00001330
1331 if (foldedLoad) {
Bill Wendling044b5342009-04-07 22:35:25 +00001332 SDValue Ops[] = { Tmp0, Tmp1, Tmp2, Tmp3, N1.getOperand(0), InFlag };
Evan Cheng7e9b26f2006-02-09 07:17:49 +00001333 SDNode *CNode =
Rafael Espindolae4d5d342009-03-27 15:45:05 +00001334 CurDAG->getTargetNode(MOpc, dl, MVT::Other, MVT::Flag, Ops,
Rafael Espindolaa0a4f072009-03-28 19:02:18 +00001335 array_lengthof(Ops));
Dan Gohman475871a2008-07-27 21:46:04 +00001336 InFlag = SDValue(CNode, 1);
Dan Gohman525178c2007-10-08 18:33:35 +00001337 // Update the chain.
Dan Gohman475871a2008-07-27 21:46:04 +00001338 ReplaceUses(N1.getValue(1), SDValue(CNode, 0));
Evan Cheng0114e942006-01-06 20:36:21 +00001339 } else {
Evan Cheng7e9b26f2006-02-09 07:17:49 +00001340 InFlag =
Dale Johannesend8392542009-02-03 21:48:12 +00001341 SDValue(CurDAG->getTargetNode(Opc, dl, MVT::Flag, N1, InFlag), 0);
Evan Cheng0114e942006-01-06 20:36:21 +00001342 }
1343
Dan Gohman525178c2007-10-08 18:33:35 +00001344 // Copy the low half of the result, if it is needed.
1345 if (!N.getValue(0).use_empty()) {
Dale Johannesendd64c412009-02-04 00:33:20 +00001346 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
Dan Gohman525178c2007-10-08 18:33:35 +00001347 LoReg, NVT, InFlag);
1348 InFlag = Result.getValue(2);
1349 ReplaceUses(N.getValue(0), Result);
1350#ifndef NDEBUG
1351 DOUT << std::string(Indent-2, ' ') << "=> ";
Gabor Greifba36cb52008-08-28 21:40:38 +00001352 DEBUG(Result.getNode()->dump(CurDAG));
Dan Gohman525178c2007-10-08 18:33:35 +00001353 DOUT << "\n";
1354#endif
Evan Chengf7ef26e2007-08-09 21:59:35 +00001355 }
Dan Gohman525178c2007-10-08 18:33:35 +00001356 // Copy the high half of the result, if it is needed.
1357 if (!N.getValue(1).use_empty()) {
Dan Gohman475871a2008-07-27 21:46:04 +00001358 SDValue Result;
Dan Gohman525178c2007-10-08 18:33:35 +00001359 if (HiReg == X86::AH && Subtarget->is64Bit()) {
1360 // Prevent use of AH in a REX instruction by referencing AX instead.
1361 // Shift it down 8 bits.
Dale Johannesendd64c412009-02-04 00:33:20 +00001362 Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
Dan Gohman525178c2007-10-08 18:33:35 +00001363 X86::AX, MVT::i16, InFlag);
1364 InFlag = Result.getValue(2);
Dale Johannesend8392542009-02-03 21:48:12 +00001365 Result = SDValue(CurDAG->getTargetNode(X86::SHR16ri, dl, MVT::i16,
1366 Result,
Gabor Greif93c53e52008-08-31 15:37:04 +00001367 CurDAG->getTargetConstant(8, MVT::i8)), 0);
Dan Gohman525178c2007-10-08 18:33:35 +00001368 // Then truncate it down to i8.
Dan Gohman475871a2008-07-27 21:46:04 +00001369 SDValue SRIdx = CurDAG->getTargetConstant(1, MVT::i32); // SubRegSet 1
Dale Johannesend8392542009-02-03 21:48:12 +00001370 Result = SDValue(CurDAG->getTargetNode(X86::EXTRACT_SUBREG, dl,
Dan Gohman525178c2007-10-08 18:33:35 +00001371 MVT::i8, Result, SRIdx), 0);
1372 } else {
Dale Johannesendd64c412009-02-04 00:33:20 +00001373 Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
Dan Gohman525178c2007-10-08 18:33:35 +00001374 HiReg, NVT, InFlag);
1375 InFlag = Result.getValue(2);
1376 }
1377 ReplaceUses(N.getValue(1), Result);
1378#ifndef NDEBUG
1379 DOUT << std::string(Indent-2, ' ') << "=> ";
Gabor Greifba36cb52008-08-28 21:40:38 +00001380 DEBUG(Result.getNode()->dump(CurDAG));
Dan Gohman525178c2007-10-08 18:33:35 +00001381 DOUT << "\n";
1382#endif
1383 }
Evan Cheng34167212006-02-09 00:37:58 +00001384
Evan Chengf597dc72006-02-10 22:24:32 +00001385#ifndef NDEBUG
Evan Cheng23addc02006-02-10 22:46:26 +00001386 Indent -= 2;
Evan Chengf597dc72006-02-10 22:24:32 +00001387#endif
Dan Gohman525178c2007-10-08 18:33:35 +00001388
Evan Cheng64a752f2006-08-11 09:08:15 +00001389 return NULL;
Evan Cheng948f3432006-01-06 23:19:29 +00001390 }
Evan Cheng7ccced62006-02-18 00:15:05 +00001391
Dan Gohman525178c2007-10-08 18:33:35 +00001392 case ISD::SDIVREM:
1393 case ISD::UDIVREM: {
Dan Gohman475871a2008-07-27 21:46:04 +00001394 SDValue N0 = Node->getOperand(0);
1395 SDValue N1 = Node->getOperand(1);
Dan Gohman525178c2007-10-08 18:33:35 +00001396
1397 bool isSigned = Opcode == ISD::SDIVREM;
Evan Cheng948f3432006-01-06 23:19:29 +00001398 if (!isSigned)
Duncan Sands83ec4b62008-06-06 12:08:01 +00001399 switch (NVT.getSimpleVT()) {
Evan Cheng948f3432006-01-06 23:19:29 +00001400 default: assert(0 && "Unsupported VT!");
1401 case MVT::i8: Opc = X86::DIV8r; MOpc = X86::DIV8m; break;
1402 case MVT::i16: Opc = X86::DIV16r; MOpc = X86::DIV16m; break;
1403 case MVT::i32: Opc = X86::DIV32r; MOpc = X86::DIV32m; break;
Evan Cheng25ab6902006-09-08 06:48:29 +00001404 case MVT::i64: Opc = X86::DIV64r; MOpc = X86::DIV64m; break;
Evan Cheng948f3432006-01-06 23:19:29 +00001405 }
1406 else
Duncan Sands83ec4b62008-06-06 12:08:01 +00001407 switch (NVT.getSimpleVT()) {
Evan Cheng948f3432006-01-06 23:19:29 +00001408 default: assert(0 && "Unsupported VT!");
1409 case MVT::i8: Opc = X86::IDIV8r; MOpc = X86::IDIV8m; break;
1410 case MVT::i16: Opc = X86::IDIV16r; MOpc = X86::IDIV16m; break;
1411 case MVT::i32: Opc = X86::IDIV32r; MOpc = X86::IDIV32m; break;
Evan Cheng25ab6902006-09-08 06:48:29 +00001412 case MVT::i64: Opc = X86::IDIV64r; MOpc = X86::IDIV64m; break;
Evan Cheng948f3432006-01-06 23:19:29 +00001413 }
1414
1415 unsigned LoReg, HiReg;
1416 unsigned ClrOpcode, SExtOpcode;
Duncan Sands83ec4b62008-06-06 12:08:01 +00001417 switch (NVT.getSimpleVT()) {
Evan Cheng948f3432006-01-06 23:19:29 +00001418 default: assert(0 && "Unsupported VT!");
1419 case MVT::i8:
1420 LoReg = X86::AL; HiReg = X86::AH;
Evan Chengb1409ce2006-11-17 22:10:14 +00001421 ClrOpcode = 0;
Evan Cheng948f3432006-01-06 23:19:29 +00001422 SExtOpcode = X86::CBW;
1423 break;
1424 case MVT::i16:
1425 LoReg = X86::AX; HiReg = X86::DX;
Evan Chengaede9b92006-06-02 21:20:34 +00001426 ClrOpcode = X86::MOV16r0;
Evan Cheng948f3432006-01-06 23:19:29 +00001427 SExtOpcode = X86::CWD;
1428 break;
1429 case MVT::i32:
1430 LoReg = X86::EAX; HiReg = X86::EDX;
Evan Chengaede9b92006-06-02 21:20:34 +00001431 ClrOpcode = X86::MOV32r0;
Evan Cheng948f3432006-01-06 23:19:29 +00001432 SExtOpcode = X86::CDQ;
1433 break;
Evan Cheng25ab6902006-09-08 06:48:29 +00001434 case MVT::i64:
1435 LoReg = X86::RAX; HiReg = X86::RDX;
1436 ClrOpcode = X86::MOV64r0;
1437 SExtOpcode = X86::CQO;
1438 break;
Evan Cheng948f3432006-01-06 23:19:29 +00001439 }
1440
Bill Wendling044b5342009-04-07 22:35:25 +00001441 SDValue Tmp0, Tmp1, Tmp2, Tmp3;
1442 bool foldedLoad = TryFoldLoad(N, N1, Tmp0, Tmp1, Tmp2, Tmp3);
Dan Gohman1ef4d8f2009-01-21 14:50:16 +00001443 bool signBitIsZero = CurDAG->SignBitIsZero(N0);
Dan Gohman525178c2007-10-08 18:33:35 +00001444
Dan Gohman475871a2008-07-27 21:46:04 +00001445 SDValue InFlag;
Dan Gohman1ef4d8f2009-01-21 14:50:16 +00001446 if (NVT == MVT::i8 && (!isSigned || signBitIsZero)) {
Evan Chengb1409ce2006-11-17 22:10:14 +00001447 // Special case for div8, just use a move with zero extension to AX to
1448 // clear the upper 8 bits (AH).
Bill Wendling044b5342009-04-07 22:35:25 +00001449 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Move, Chain;
1450 if (TryFoldLoad(N, N0, Tmp0, Tmp1, Tmp2, Tmp3)) {
1451 SDValue Ops[] = { Tmp0, Tmp1, Tmp2, Tmp3, N0.getOperand(0) };
Evan Chengb1409ce2006-11-17 22:10:14 +00001452 Move =
Dale Johannesend8392542009-02-03 21:48:12 +00001453 SDValue(CurDAG->getTargetNode(X86::MOVZX16rm8, dl, MVT::i16,
Rafael Espindolae4d5d342009-03-27 15:45:05 +00001454 MVT::Other, Ops,
Rafael Espindolaa0a4f072009-03-28 19:02:18 +00001455 array_lengthof(Ops)), 0);
Evan Chengb1409ce2006-11-17 22:10:14 +00001456 Chain = Move.getValue(1);
1457 ReplaceUses(N0.getValue(1), Chain);
1458 } else {
Evan Chengb1409ce2006-11-17 22:10:14 +00001459 Move =
Dale Johannesend8392542009-02-03 21:48:12 +00001460 SDValue(CurDAG->getTargetNode(X86::MOVZX16rr8, dl, MVT::i16, N0),0);
Evan Chengb1409ce2006-11-17 22:10:14 +00001461 Chain = CurDAG->getEntryNode();
1462 }
Dale Johannesendd64c412009-02-04 00:33:20 +00001463 Chain = CurDAG->getCopyToReg(Chain, dl, X86::AX, Move, SDValue());
Evan Cheng948f3432006-01-06 23:19:29 +00001464 InFlag = Chain.getValue(1);
Evan Chengb1409ce2006-11-17 22:10:14 +00001465 } else {
Evan Chengb1409ce2006-11-17 22:10:14 +00001466 InFlag =
Dale Johannesendd64c412009-02-04 00:33:20 +00001467 CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl,
Dan Gohman475871a2008-07-27 21:46:04 +00001468 LoReg, N0, SDValue()).getValue(1);
Dan Gohman1ef4d8f2009-01-21 14:50:16 +00001469 if (isSigned && !signBitIsZero) {
Evan Chengb1409ce2006-11-17 22:10:14 +00001470 // Sign extend the low part into the high part.
1471 InFlag =
Dale Johannesend8392542009-02-03 21:48:12 +00001472 SDValue(CurDAG->getTargetNode(SExtOpcode, dl, MVT::Flag, InFlag),0);
Evan Chengb1409ce2006-11-17 22:10:14 +00001473 } else {
1474 // Zero out the high part, effectively zero extending the input.
Dale Johannesend8392542009-02-03 21:48:12 +00001475 SDValue ClrNode = SDValue(CurDAG->getTargetNode(ClrOpcode, dl, NVT),
1476 0);
Dale Johannesendd64c412009-02-04 00:33:20 +00001477 InFlag = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, HiReg,
Dan Gohman525178c2007-10-08 18:33:35 +00001478 ClrNode, InFlag).getValue(1);
Evan Chengb1409ce2006-11-17 22:10:14 +00001479 }
Evan Cheng948f3432006-01-06 23:19:29 +00001480 }
1481
1482 if (foldedLoad) {
Bill Wendling044b5342009-04-07 22:35:25 +00001483 SDValue Ops[] = { Tmp0, Tmp1, Tmp2, Tmp3, N1.getOperand(0), InFlag };
Evan Cheng7e9b26f2006-02-09 07:17:49 +00001484 SDNode *CNode =
Rafael Espindolae4d5d342009-03-27 15:45:05 +00001485 CurDAG->getTargetNode(MOpc, dl, MVT::Other, MVT::Flag, Ops,
Rafael Espindolaa0a4f072009-03-28 19:02:18 +00001486 array_lengthof(Ops));
Dan Gohman475871a2008-07-27 21:46:04 +00001487 InFlag = SDValue(CNode, 1);
Dan Gohman525178c2007-10-08 18:33:35 +00001488 // Update the chain.
Dan Gohman475871a2008-07-27 21:46:04 +00001489 ReplaceUses(N1.getValue(1), SDValue(CNode, 0));
Evan Cheng948f3432006-01-06 23:19:29 +00001490 } else {
Evan Cheng7e9b26f2006-02-09 07:17:49 +00001491 InFlag =
Dale Johannesend8392542009-02-03 21:48:12 +00001492 SDValue(CurDAG->getTargetNode(Opc, dl, MVT::Flag, N1, InFlag), 0);
Evan Cheng948f3432006-01-06 23:19:29 +00001493 }
1494
Dan Gohmana37c9f72007-09-25 18:23:27 +00001495 // Copy the division (low) result, if it is needed.
1496 if (!N.getValue(0).use_empty()) {
Dale Johannesendd64c412009-02-04 00:33:20 +00001497 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
Dan Gohman525178c2007-10-08 18:33:35 +00001498 LoReg, NVT, InFlag);
Dan Gohmana37c9f72007-09-25 18:23:27 +00001499 InFlag = Result.getValue(2);
1500 ReplaceUses(N.getValue(0), Result);
1501#ifndef NDEBUG
1502 DOUT << std::string(Indent-2, ' ') << "=> ";
Gabor Greifba36cb52008-08-28 21:40:38 +00001503 DEBUG(Result.getNode()->dump(CurDAG));
Dan Gohmana37c9f72007-09-25 18:23:27 +00001504 DOUT << "\n";
1505#endif
Evan Chengf7ef26e2007-08-09 21:59:35 +00001506 }
Dan Gohmana37c9f72007-09-25 18:23:27 +00001507 // Copy the remainder (high) result, if it is needed.
1508 if (!N.getValue(1).use_empty()) {
Dan Gohman475871a2008-07-27 21:46:04 +00001509 SDValue Result;
Dan Gohmana37c9f72007-09-25 18:23:27 +00001510 if (HiReg == X86::AH && Subtarget->is64Bit()) {
1511 // Prevent use of AH in a REX instruction by referencing AX instead.
1512 // Shift it down 8 bits.
Dale Johannesendd64c412009-02-04 00:33:20 +00001513 Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
Dan Gohman525178c2007-10-08 18:33:35 +00001514 X86::AX, MVT::i16, InFlag);
Dan Gohmana37c9f72007-09-25 18:23:27 +00001515 InFlag = Result.getValue(2);
Dale Johannesend8392542009-02-03 21:48:12 +00001516 Result = SDValue(CurDAG->getTargetNode(X86::SHR16ri, dl, MVT::i16,
1517 Result,
1518 CurDAG->getTargetConstant(8, MVT::i8)),
1519 0);
Dan Gohmana37c9f72007-09-25 18:23:27 +00001520 // Then truncate it down to i8.
Dan Gohman475871a2008-07-27 21:46:04 +00001521 SDValue SRIdx = CurDAG->getTargetConstant(1, MVT::i32); // SubRegSet 1
Dale Johannesend8392542009-02-03 21:48:12 +00001522 Result = SDValue(CurDAG->getTargetNode(X86::EXTRACT_SUBREG, dl,
Dan Gohmana37c9f72007-09-25 18:23:27 +00001523 MVT::i8, Result, SRIdx), 0);
1524 } else {
Dale Johannesendd64c412009-02-04 00:33:20 +00001525 Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
Dan Gohman525178c2007-10-08 18:33:35 +00001526 HiReg, NVT, InFlag);
Dan Gohmana37c9f72007-09-25 18:23:27 +00001527 InFlag = Result.getValue(2);
1528 }
1529 ReplaceUses(N.getValue(1), Result);
1530#ifndef NDEBUG
1531 DOUT << std::string(Indent-2, ' ') << "=> ";
Gabor Greifba36cb52008-08-28 21:40:38 +00001532 DEBUG(Result.getNode()->dump(CurDAG));
Dan Gohmana37c9f72007-09-25 18:23:27 +00001533 DOUT << "\n";
1534#endif
1535 }
Evan Chengf597dc72006-02-10 22:24:32 +00001536
1537#ifndef NDEBUG
Evan Cheng23addc02006-02-10 22:46:26 +00001538 Indent -= 2;
Evan Chengf597dc72006-02-10 22:24:32 +00001539#endif
Evan Cheng64a752f2006-08-11 09:08:15 +00001540
1541 return NULL;
Evan Cheng0114e942006-01-06 20:36:21 +00001542 }
Christopher Lamba1eb1552007-08-10 22:22:41 +00001543
Christopher Lambc59e5212007-08-10 21:48:46 +00001544 case ISD::SIGN_EXTEND_INREG: {
Duncan Sands83ec4b62008-06-06 12:08:01 +00001545 MVT SVT = cast<VTSDNode>(Node->getOperand(1))->getVT();
Dan Gohman0bfa1bf2008-08-20 21:27:32 +00001546 if (SVT == MVT::i8 && !Subtarget->is64Bit()) {
1547 SDValue N0 = Node->getOperand(0);
Christopher Lambc59e5212007-08-10 21:48:46 +00001548
Dan Gohman0bfa1bf2008-08-20 21:27:32 +00001549 SDValue TruncOp = SDValue(getTruncateTo8Bit(N0), 0);
1550 unsigned Opc = 0;
1551 switch (NVT.getSimpleVT()) {
1552 default: assert(0 && "Unknown sign_extend_inreg!");
1553 case MVT::i16:
1554 Opc = X86::MOVSX16rr8;
1555 break;
1556 case MVT::i32:
1557 Opc = X86::MOVSX32rr8;
1558 break;
1559 }
1560
Dale Johannesend8392542009-02-03 21:48:12 +00001561 SDNode *ResNode = CurDAG->getTargetNode(Opc, dl, NVT, TruncOp);
Christopher Lambc59e5212007-08-10 21:48:46 +00001562
1563#ifndef NDEBUG
Dan Gohman0bfa1bf2008-08-20 21:27:32 +00001564 DOUT << std::string(Indent-2, ' ') << "=> ";
Gabor Greifba36cb52008-08-28 21:40:38 +00001565 DEBUG(TruncOp.getNode()->dump(CurDAG));
Dan Gohman0bfa1bf2008-08-20 21:27:32 +00001566 DOUT << "\n";
1567 DOUT << std::string(Indent-2, ' ') << "=> ";
1568 DEBUG(ResNode->dump(CurDAG));
1569 DOUT << "\n";
1570 Indent -= 2;
Christopher Lambc59e5212007-08-10 21:48:46 +00001571#endif
Dan Gohman0bfa1bf2008-08-20 21:27:32 +00001572 return ResNode;
1573 }
Christopher Lambc59e5212007-08-10 21:48:46 +00001574 break;
1575 }
1576
1577 case ISD::TRUNCATE: {
Dan Gohman0bfa1bf2008-08-20 21:27:32 +00001578 if (NVT == MVT::i8 && !Subtarget->is64Bit()) {
1579 SDValue Input = Node->getOperand(0);
Dan Gohman0bfa1bf2008-08-20 21:27:32 +00001580 SDNode *ResNode = getTruncateTo8Bit(Input);
Christopher Lambc59e5212007-08-10 21:48:46 +00001581
Evan Cheng403be7e2006-05-08 08:01:26 +00001582#ifndef NDEBUG
Bill Wendling6345d752006-11-17 07:52:03 +00001583 DOUT << std::string(Indent-2, ' ') << "=> ";
Evan Cheng9ade2182006-08-26 05:34:46 +00001584 DEBUG(ResNode->dump(CurDAG));
Bill Wendling6345d752006-11-17 07:52:03 +00001585 DOUT << "\n";
Evan Cheng403be7e2006-05-08 08:01:26 +00001586 Indent -= 2;
1587#endif
Dan Gohman0bfa1bf2008-08-20 21:27:32 +00001588 return ResNode;
1589 }
Evan Cheng6b2e2542006-05-20 07:44:28 +00001590 break;
Evan Cheng403be7e2006-05-08 08:01:26 +00001591 }
Evan Cheng851bc042008-06-17 02:01:22 +00001592
1593 case ISD::DECLARE: {
1594 // Handle DECLARE nodes here because the second operand may have been
1595 // wrapped in X86ISD::Wrapper.
Dan Gohman475871a2008-07-27 21:46:04 +00001596 SDValue Chain = Node->getOperand(0);
1597 SDValue N1 = Node->getOperand(1);
1598 SDValue N2 = Node->getOperand(2);
Evan Cheng6bb14ca2008-12-10 21:49:05 +00001599 FrameIndexSDNode *FINode = dyn_cast<FrameIndexSDNode>(N1);
Chris Lattner1823c922009-02-12 17:33:11 +00001600
1601 // FIXME: We need to handle this for VLAs.
1602 if (!FINode) {
1603 ReplaceUses(N.getValue(0), Chain);
1604 return NULL;
1605 }
1606
Evan Chengfab83872008-06-18 02:48:27 +00001607 if (N2.getOpcode() == ISD::ADD &&
1608 N2.getOperand(0).getOpcode() == X86ISD::GlobalBaseReg)
1609 N2 = N2.getOperand(1);
Chris Lattner1823c922009-02-12 17:33:11 +00001610
1611 // If N2 is not Wrapper(decriptor) then the llvm.declare is mangled
1612 // somehow, just ignore it.
1613 if (N2.getOpcode() != X86ISD::Wrapper) {
1614 ReplaceUses(N.getValue(0), Chain);
1615 return NULL;
1616 }
Evan Chengf2accb52009-01-10 03:33:22 +00001617 GlobalAddressSDNode *GVNode =
1618 dyn_cast<GlobalAddressSDNode>(N2.getOperand(0));
Chris Lattner1823c922009-02-12 17:33:11 +00001619 if (GVNode == 0) {
1620 ReplaceUses(N.getValue(0), Chain);
1621 return NULL;
1622 }
Evan Cheng6bb14ca2008-12-10 21:49:05 +00001623 SDValue Tmp1 = CurDAG->getTargetFrameIndex(FINode->getIndex(),
1624 TLI.getPointerTy());
1625 SDValue Tmp2 = CurDAG->getTargetGlobalAddress(GVNode->getGlobal(),
1626 TLI.getPointerTy());
1627 SDValue Ops[] = { Tmp1, Tmp2, Chain };
Dale Johannesend8392542009-02-03 21:48:12 +00001628 return CurDAG->getTargetNode(TargetInstrInfo::DECLARE, dl,
Rafael Espindolae4d5d342009-03-27 15:45:05 +00001629 MVT::Other, Ops,
Rafael Espindolaa0a4f072009-03-28 19:02:18 +00001630 array_lengthof(Ops));
Evan Cheng851bc042008-06-17 02:01:22 +00001631 }
Chris Lattnerc961eea2005-11-16 01:54:32 +00001632 }
1633
Evan Cheng9ade2182006-08-26 05:34:46 +00001634 SDNode *ResNode = SelectCode(N);
Evan Cheng64a752f2006-08-11 09:08:15 +00001635
Evan Chengf597dc72006-02-10 22:24:32 +00001636#ifndef NDEBUG
Bill Wendling6345d752006-11-17 07:52:03 +00001637 DOUT << std::string(Indent-2, ' ') << "=> ";
Gabor Greifba36cb52008-08-28 21:40:38 +00001638 if (ResNode == NULL || ResNode == N.getNode())
1639 DEBUG(N.getNode()->dump(CurDAG));
Evan Cheng9ade2182006-08-26 05:34:46 +00001640 else
1641 DEBUG(ResNode->dump(CurDAG));
Bill Wendling6345d752006-11-17 07:52:03 +00001642 DOUT << "\n";
Evan Cheng23addc02006-02-10 22:46:26 +00001643 Indent -= 2;
Evan Chengf597dc72006-02-10 22:24:32 +00001644#endif
Evan Cheng64a752f2006-08-11 09:08:15 +00001645
1646 return ResNode;
Chris Lattnerc961eea2005-11-16 01:54:32 +00001647}
1648
Chris Lattnerc0bad572006-06-08 18:03:49 +00001649bool X86DAGToDAGISel::
Dan Gohman475871a2008-07-27 21:46:04 +00001650SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
Dan Gohmanf350b272008-08-23 02:25:05 +00001651 std::vector<SDValue> &OutOps) {
Bill Wendling044b5342009-04-07 22:35:25 +00001652 SDValue Op0, Op1, Op2, Op3;
Chris Lattnerc0bad572006-06-08 18:03:49 +00001653 switch (ConstraintCode) {
1654 case 'o': // offsetable ??
1655 case 'v': // not offsetable ??
1656 default: return true;
1657 case 'm': // memory
Bill Wendling044b5342009-04-07 22:35:25 +00001658 if (!SelectAddr(Op, Op, Op0, Op1, Op2, Op3))
Chris Lattnerc0bad572006-06-08 18:03:49 +00001659 return true;
1660 break;
1661 }
1662
Evan Cheng04699902006-08-26 01:05:16 +00001663 OutOps.push_back(Op0);
1664 OutOps.push_back(Op1);
1665 OutOps.push_back(Op2);
1666 OutOps.push_back(Op3);
Chris Lattnerc0bad572006-06-08 18:03:49 +00001667 return false;
1668}
1669
Chris Lattnerc961eea2005-11-16 01:54:32 +00001670/// createX86ISelDag - This pass converts a legalized DAG into a
1671/// X86-specific DAG, ready for instruction scheduling.
1672///
Evan Chenge50794a2006-08-29 18:28:33 +00001673FunctionPass *llvm::createX86ISelDag(X86TargetMachine &TM, bool Fast) {
1674 return new X86DAGToDAGISel(TM, Fast);
Chris Lattnerc961eea2005-11-16 01:54:32 +00001675}