Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1 | //===- X86ISelDAGToDAG.cpp - A DAG pattern matching inst selector for X86 -===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 081ce94 | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 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 | |
| 15 | #define DEBUG_TYPE "x86-isel" |
| 16 | #include "X86.h" |
| 17 | #include "X86InstrBuilder.h" |
| 18 | #include "X86ISelLowering.h" |
Evan Cheng | 0729ccf | 2008-01-05 00:41:47 +0000 | [diff] [blame] | 19 | #include "X86MachineFunctionInfo.h" |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 20 | #include "X86RegisterInfo.h" |
| 21 | #include "X86Subtarget.h" |
| 22 | #include "X86TargetMachine.h" |
| 23 | #include "llvm/GlobalValue.h" |
| 24 | #include "llvm/Instructions.h" |
| 25 | #include "llvm/Intrinsics.h" |
| 26 | #include "llvm/Support/CFG.h" |
| 27 | #include "llvm/Type.h" |
| 28 | #include "llvm/CodeGen/MachineConstantPool.h" |
| 29 | #include "llvm/CodeGen/MachineFunction.h" |
| 30 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 31 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Chris Lattner | 1b98919 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 32 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 33 | #include "llvm/CodeGen/SelectionDAGISel.h" |
| 34 | #include "llvm/Target/TargetMachine.h" |
| 35 | #include "llvm/Support/Compiler.h" |
| 36 | #include "llvm/Support/Debug.h" |
| 37 | #include "llvm/Support/MathExtras.h" |
Dale Johannesen | c501c08 | 2008-08-11 23:46:25 +0000 | [diff] [blame] | 38 | #include "llvm/Support/Streams.h" |
Evan Cheng | 656269e | 2008-04-25 08:22:20 +0000 | [diff] [blame] | 39 | #include "llvm/ADT/SmallPtrSet.h" |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 40 | #include "llvm/ADT/Statistic.h" |
| 41 | #include <queue> |
| 42 | #include <set> |
| 43 | using namespace llvm; |
| 44 | |
| 45 | STATISTIC(NumFPKill , "Number of FP_REG_KILL instructions added"); |
| 46 | STATISTIC(NumLoadMoved, "Number of loads moved below TokenFactor"); |
| 47 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 48 | //===----------------------------------------------------------------------===// |
| 49 | // Pattern Matcher Implementation |
| 50 | //===----------------------------------------------------------------------===// |
| 51 | |
| 52 | namespace { |
| 53 | /// X86ISelAddressMode - This corresponds to X86AddressMode, but uses |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 54 | /// SDValue's instead of register numbers for the leaves of the matched |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 55 | /// tree. |
| 56 | struct X86ISelAddressMode { |
| 57 | enum { |
| 58 | RegBase, |
| 59 | FrameIndexBase |
| 60 | } BaseType; |
| 61 | |
| 62 | struct { // This is really a union, discriminated by BaseType! |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 63 | SDValue Reg; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 64 | int FrameIndex; |
| 65 | } Base; |
| 66 | |
Evan Cheng | 3b5a127 | 2008-02-07 08:53:49 +0000 | [diff] [blame] | 67 | bool isRIPRel; // RIP as base? |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 68 | unsigned Scale; |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 69 | SDValue IndexReg; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 70 | unsigned Disp; |
| 71 | GlobalValue *GV; |
| 72 | Constant *CP; |
| 73 | const char *ES; |
| 74 | int JT; |
| 75 | unsigned Align; // CP alignment. |
| 76 | |
| 77 | X86ISelAddressMode() |
| 78 | : BaseType(RegBase), isRIPRel(false), Scale(1), IndexReg(), Disp(0), |
| 79 | GV(0), CP(0), ES(0), JT(-1), Align(0) { |
| 80 | } |
Dale Johannesen | c501c08 | 2008-08-11 23:46:25 +0000 | [diff] [blame] | 81 | void dump() { |
| 82 | cerr << "X86ISelAddressMode " << this << "\n"; |
Gabor Greif | e9f7f58 | 2008-08-31 15:37:04 +0000 | [diff] [blame] | 83 | cerr << "Base.Reg "; |
| 84 | if (Base.Reg.getNode() != 0) Base.Reg.getNode()->dump(); |
| 85 | else cerr << "nul"; |
Dale Johannesen | c501c08 | 2008-08-11 23:46:25 +0000 | [diff] [blame] | 86 | cerr << " Base.FrameIndex " << Base.FrameIndex << "\n"; |
| 87 | cerr << "isRIPRel " << isRIPRel << " Scale" << Scale << "\n"; |
Gabor Greif | e9f7f58 | 2008-08-31 15:37:04 +0000 | [diff] [blame] | 88 | cerr << "IndexReg "; |
| 89 | if (IndexReg.getNode() != 0) IndexReg.getNode()->dump(); |
| 90 | else cerr << "nul"; |
Dale Johannesen | c501c08 | 2008-08-11 23:46:25 +0000 | [diff] [blame] | 91 | cerr << " Disp " << Disp << "\n"; |
| 92 | cerr << "GV "; if (GV) GV->dump(); |
| 93 | else cerr << "nul"; |
| 94 | cerr << " CP "; if (CP) CP->dump(); |
| 95 | else cerr << "nul"; |
| 96 | cerr << "\n"; |
| 97 | cerr << "ES "; if (ES) cerr << ES; else cerr << "nul"; |
| 98 | cerr << " JT" << JT << " Align" << Align << "\n"; |
| 99 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 100 | }; |
| 101 | } |
| 102 | |
| 103 | namespace { |
| 104 | //===--------------------------------------------------------------------===// |
| 105 | /// ISel - X86 specific code to select X86 machine instructions for |
| 106 | /// SelectionDAG operations. |
| 107 | /// |
| 108 | class VISIBILITY_HIDDEN X86DAGToDAGISel : public SelectionDAGISel { |
| 109 | /// ContainsFPCode - Every instruction we select that uses or defines a FP |
| 110 | /// register should set this to true. |
| 111 | bool ContainsFPCode; |
| 112 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 113 | /// TM - Keep a reference to X86TargetMachine. |
| 114 | /// |
| 115 | X86TargetMachine &TM; |
| 116 | |
| 117 | /// X86Lowering - This object fully describes how to lower LLVM code to an |
| 118 | /// X86-specific SelectionDAG. |
| 119 | X86TargetLowering X86Lowering; |
| 120 | |
| 121 | /// Subtarget - Keep a pointer to the X86Subtarget around so that we can |
| 122 | /// make the right decision when generating code for different targets. |
| 123 | const X86Subtarget *Subtarget; |
| 124 | |
| 125 | /// GlobalBaseReg - keeps track of the virtual register mapped onto global |
| 126 | /// base register. |
| 127 | unsigned GlobalBaseReg; |
| 128 | |
Evan Cheng | 34fd4f3 | 2008-06-30 20:45:06 +0000 | [diff] [blame] | 129 | /// CurBB - Current BB being isel'd. |
| 130 | /// |
| 131 | MachineBasicBlock *CurBB; |
| 132 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 133 | public: |
| 134 | X86DAGToDAGISel(X86TargetMachine &tm, bool fast) |
Evan Cheng | 9b77cae | 2008-07-01 18:05:03 +0000 | [diff] [blame] | 135 | : SelectionDAGISel(X86Lowering, fast), |
| 136 | ContainsFPCode(false), TM(tm), |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 137 | X86Lowering(*TM.getTargetLowering()), |
| 138 | Subtarget(&TM.getSubtarget<X86Subtarget>()) {} |
| 139 | |
| 140 | virtual bool runOnFunction(Function &Fn) { |
| 141 | // Make sure we re-emit a set of the global base reg if necessary |
| 142 | GlobalBaseReg = 0; |
| 143 | return SelectionDAGISel::runOnFunction(Fn); |
| 144 | } |
| 145 | |
| 146 | virtual const char *getPassName() const { |
| 147 | return "X86 DAG->DAG Instruction Selection"; |
| 148 | } |
| 149 | |
Evan Cheng | 34fd4f3 | 2008-06-30 20:45:06 +0000 | [diff] [blame] | 150 | /// InstructionSelect - This callback is invoked by |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 151 | /// SelectionDAGISel when it has created a SelectionDAG for us to codegen. |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 152 | virtual void InstructionSelect(); |
Evan Cheng | 34fd4f3 | 2008-06-30 20:45:06 +0000 | [diff] [blame] | 153 | |
| 154 | /// InstructionSelectPostProcessing - Post processing of selected and |
| 155 | /// scheduled basic blocks. |
Dan Gohman | b552df7 | 2008-07-21 20:00:07 +0000 | [diff] [blame] | 156 | virtual void InstructionSelectPostProcessing(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 157 | |
Anton Korobeynikov | 34ef31e | 2007-09-25 21:52:30 +0000 | [diff] [blame] | 158 | virtual void EmitFunctionEntryCode(Function &Fn, MachineFunction &MF); |
| 159 | |
Dan Gohman | d609827 | 2007-07-24 23:00:27 +0000 | [diff] [blame] | 160 | virtual bool CanBeFoldedBy(SDNode *N, SDNode *U, SDNode *Root) const; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 161 | |
| 162 | // Include the pieces autogenerated from the target description. |
| 163 | #include "X86GenDAGISel.inc" |
| 164 | |
| 165 | private: |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 166 | SDNode *Select(SDValue N); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 167 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 168 | bool MatchAddress(SDValue N, X86ISelAddressMode &AM, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 169 | bool isRoot = true, unsigned Depth = 0); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 170 | bool MatchAddressBase(SDValue N, X86ISelAddressMode &AM, |
Dan Gohman | a60c1b3 | 2007-08-13 20:03:06 +0000 | [diff] [blame] | 171 | bool isRoot, unsigned Depth); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 172 | bool SelectAddr(SDValue Op, SDValue N, SDValue &Base, |
| 173 | SDValue &Scale, SDValue &Index, SDValue &Disp); |
| 174 | bool SelectLEAAddr(SDValue Op, SDValue N, SDValue &Base, |
| 175 | SDValue &Scale, SDValue &Index, SDValue &Disp); |
| 176 | bool SelectScalarSSELoad(SDValue Op, SDValue Pred, |
| 177 | SDValue N, SDValue &Base, SDValue &Scale, |
| 178 | SDValue &Index, SDValue &Disp, |
| 179 | SDValue &InChain, SDValue &OutChain); |
| 180 | bool TryFoldLoad(SDValue P, SDValue N, |
| 181 | SDValue &Base, SDValue &Scale, |
| 182 | SDValue &Index, SDValue &Disp); |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 183 | void PreprocessForRMW(); |
| 184 | void PreprocessForFPConvert(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 185 | |
| 186 | /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for |
| 187 | /// inline asm expressions. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 188 | virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 189 | char ConstraintCode, |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 190 | std::vector<SDValue> &OutOps); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 191 | |
Anton Korobeynikov | 34ef31e | 2007-09-25 21:52:30 +0000 | [diff] [blame] | 192 | void EmitSpecialCodeForMain(MachineBasicBlock *BB, MachineFrameInfo *MFI); |
| 193 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 194 | inline void getAddressOperands(X86ISelAddressMode &AM, SDValue &Base, |
| 195 | SDValue &Scale, SDValue &Index, |
| 196 | SDValue &Disp) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 197 | Base = (AM.BaseType == X86ISelAddressMode::FrameIndexBase) ? |
| 198 | CurDAG->getTargetFrameIndex(AM.Base.FrameIndex, TLI.getPointerTy()) : |
| 199 | AM.Base.Reg; |
| 200 | Scale = getI8Imm(AM.Scale); |
| 201 | Index = AM.IndexReg; |
| 202 | // These are 32-bit even in 64-bit mode since RIP relative offset |
| 203 | // is 32-bit. |
| 204 | if (AM.GV) |
| 205 | Disp = CurDAG->getTargetGlobalAddress(AM.GV, MVT::i32, AM.Disp); |
| 206 | else if (AM.CP) |
Gabor Greif | e9f7f58 | 2008-08-31 15:37:04 +0000 | [diff] [blame] | 207 | Disp = CurDAG->getTargetConstantPool(AM.CP, MVT::i32, |
| 208 | AM.Align, AM.Disp); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 209 | else if (AM.ES) |
Bill Wendling | fef0605 | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 210 | Disp = CurDAG->getTargetExternalSymbol(AM.ES, MVT::i32); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 211 | else if (AM.JT != -1) |
| 212 | Disp = CurDAG->getTargetJumpTable(AM.JT, MVT::i32); |
| 213 | else |
| 214 | Disp = getI32Imm(AM.Disp); |
| 215 | } |
| 216 | |
| 217 | /// getI8Imm - Return a target constant with the specified value, of type |
| 218 | /// i8. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 219 | inline SDValue getI8Imm(unsigned Imm) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 220 | return CurDAG->getTargetConstant(Imm, MVT::i8); |
| 221 | } |
| 222 | |
| 223 | /// getI16Imm - Return a target constant with the specified value, of type |
| 224 | /// i16. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 225 | inline SDValue getI16Imm(unsigned Imm) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 226 | return CurDAG->getTargetConstant(Imm, MVT::i16); |
| 227 | } |
| 228 | |
| 229 | /// getI32Imm - Return a target constant with the specified value, of type |
| 230 | /// i32. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 231 | inline SDValue getI32Imm(unsigned Imm) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 232 | return CurDAG->getTargetConstant(Imm, MVT::i32); |
| 233 | } |
| 234 | |
| 235 | /// getGlobalBaseReg - insert code into the entry mbb to materialize the PIC |
| 236 | /// base register. Return the virtual register that holds this value. |
| 237 | SDNode *getGlobalBaseReg(); |
| 238 | |
Dan Gohman | dd612bb | 2008-08-20 21:27:32 +0000 | [diff] [blame] | 239 | /// getTruncateTo8Bit - return an SDNode that implements a subreg based |
| 240 | /// truncate of the specified operand to i8. This can be done with tablegen, |
| 241 | /// except that this code uses MVT::Flag in a tricky way that happens to |
| 242 | /// improve scheduling in some cases. |
| 243 | SDNode *getTruncateTo8Bit(SDValue N0); |
Christopher Lamb | 0a7c866 | 2007-08-10 21:48:46 +0000 | [diff] [blame] | 244 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 245 | #ifndef NDEBUG |
| 246 | unsigned Indent; |
| 247 | #endif |
| 248 | }; |
| 249 | } |
| 250 | |
Gabor Greif | e9f7f58 | 2008-08-31 15:37:04 +0000 | [diff] [blame] | 251 | /// findFlagUse - Return use of MVT::Flag value produced by the specified |
| 252 | /// SDNode. |
Evan Cheng | 656269e | 2008-04-25 08:22:20 +0000 | [diff] [blame] | 253 | /// |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 254 | static SDNode *findFlagUse(SDNode *N) { |
| 255 | unsigned FlagResNo = N->getNumValues()-1; |
| 256 | for (SDNode::use_iterator I = N->use_begin(), E = N->use_end(); I != E; ++I) { |
Dan Gohman | 0c97f1d | 2008-07-27 20:43:25 +0000 | [diff] [blame] | 257 | SDNode *User = *I; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 258 | for (unsigned i = 0, e = User->getNumOperands(); i != e; ++i) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 259 | SDValue Op = User->getOperand(i); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 260 | if (Op.getNode() == N && Op.getResNo() == FlagResNo) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 261 | return User; |
| 262 | } |
| 263 | } |
| 264 | return NULL; |
| 265 | } |
| 266 | |
Evan Cheng | 656269e | 2008-04-25 08:22:20 +0000 | [diff] [blame] | 267 | /// findNonImmUse - Return true by reference in "found" if "Use" is an |
| 268 | /// non-immediate use of "Def". This function recursively traversing |
| 269 | /// up the operand chain ignoring certain nodes. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 270 | static void findNonImmUse(SDNode *Use, SDNode* Def, SDNode *ImmedUse, |
Dan Gohman | 602d44a | 2008-09-17 01:39:10 +0000 | [diff] [blame^] | 271 | SDNode *Root, bool &found, |
Evan Cheng | 656269e | 2008-04-25 08:22:20 +0000 | [diff] [blame] | 272 | SmallPtrSet<SDNode*, 16> &Visited) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 273 | if (found || |
| 274 | Use->getNodeId() > Def->getNodeId() || |
Evan Cheng | 656269e | 2008-04-25 08:22:20 +0000 | [diff] [blame] | 275 | !Visited.insert(Use)) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 276 | return; |
Evan Cheng | 656269e | 2008-04-25 08:22:20 +0000 | [diff] [blame] | 277 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 278 | for (unsigned i = 0, e = Use->getNumOperands(); !found && i != e; ++i) { |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 279 | SDNode *N = Use->getOperand(i).getNode(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 280 | if (N == Def) { |
Dan Gohman | 602d44a | 2008-09-17 01:39:10 +0000 | [diff] [blame^] | 281 | if (Use == ImmedUse || Use == Root) |
Evan Cheng | 9ea310c | 2008-04-25 08:55:28 +0000 | [diff] [blame] | 282 | continue; // We are not looking for immediate use. |
Dan Gohman | 602d44a | 2008-09-17 01:39:10 +0000 | [diff] [blame^] | 283 | assert(N != Root); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 284 | found = true; |
| 285 | break; |
| 286 | } |
Evan Cheng | 656269e | 2008-04-25 08:22:20 +0000 | [diff] [blame] | 287 | |
| 288 | // Traverse up the operand chain. |
Dan Gohman | 602d44a | 2008-09-17 01:39:10 +0000 | [diff] [blame^] | 289 | findNonImmUse(N, Def, ImmedUse, Root, found, Visited); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 290 | } |
| 291 | } |
| 292 | |
| 293 | /// isNonImmUse - Start searching from Root up the DAG to check is Def can |
| 294 | /// be reached. Return true if that's the case. However, ignore direct uses |
| 295 | /// by ImmedUse (which would be U in the example illustrated in |
| 296 | /// CanBeFoldedBy) and by Root (which can happen in the store case). |
| 297 | /// FIXME: to be really generic, we should allow direct use by any node |
| 298 | /// that is being folded. But realisticly since we only fold loads which |
| 299 | /// have one non-chain use, we only need to watch out for load/op/store |
| 300 | /// and load/op/cmp case where the root (store / cmp) may reach the load via |
| 301 | /// its chain operand. |
Dan Gohman | 602d44a | 2008-09-17 01:39:10 +0000 | [diff] [blame^] | 302 | static inline bool isNonImmUse(SDNode *Root, SDNode *Def, SDNode *ImmedUse) { |
Evan Cheng | 656269e | 2008-04-25 08:22:20 +0000 | [diff] [blame] | 303 | SmallPtrSet<SDNode*, 16> Visited; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 304 | bool found = false; |
Dan Gohman | 602d44a | 2008-09-17 01:39:10 +0000 | [diff] [blame^] | 305 | findNonImmUse(Root, Def, ImmedUse, Root, found, Visited); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 306 | return found; |
| 307 | } |
| 308 | |
| 309 | |
Dan Gohman | d609827 | 2007-07-24 23:00:27 +0000 | [diff] [blame] | 310 | bool X86DAGToDAGISel::CanBeFoldedBy(SDNode *N, SDNode *U, SDNode *Root) const { |
Dan Gohman | a29efcf | 2008-08-13 19:55:00 +0000 | [diff] [blame] | 311 | if (Fast) return false; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 312 | |
Dan Gohman | 602d44a | 2008-09-17 01:39:10 +0000 | [diff] [blame^] | 313 | // If Root use can somehow reach N through a path that that doesn't contain |
| 314 | // U then folding N would create a cycle. e.g. In the following |
| 315 | // diagram, Root can reach N through X. If N is folded into into Root, then |
| 316 | // X is both a predecessor and a successor of U. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 317 | // |
Dan Gohman | 602d44a | 2008-09-17 01:39:10 +0000 | [diff] [blame^] | 318 | // [N*] // |
| 319 | // ^ ^ // |
| 320 | // / \ // |
| 321 | // [U*] [X]? // |
| 322 | // ^ ^ // |
| 323 | // \ / // |
| 324 | // \ / // |
| 325 | // [Root*] // |
| 326 | // |
| 327 | // * indicates nodes to be folded together. |
| 328 | // |
| 329 | // If Root produces a flag, then it gets (even more) interesting. Since it |
| 330 | // will be "glued" together with its flag use in the scheduler, we need to |
| 331 | // check if it might reach N. |
| 332 | // |
| 333 | // [N*] // |
| 334 | // ^ ^ // |
| 335 | // / \ // |
| 336 | // [U*] [X]? // |
| 337 | // ^ ^ // |
| 338 | // \ \ // |
| 339 | // \ | // |
| 340 | // [Root*] | // |
| 341 | // ^ | // |
| 342 | // f | // |
| 343 | // | / // |
| 344 | // [Y] / // |
| 345 | // ^ / // |
| 346 | // f / // |
| 347 | // | / // |
| 348 | // [FU] // |
| 349 | // |
| 350 | // If FU (flag use) indirectly reaches N (the load), and Root folds N |
| 351 | // (call it Fold), then X is a predecessor of FU and a successor of |
| 352 | // Fold. But since Fold and FU are flagged together, this will create |
| 353 | // a cycle in the scheduling graph. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 354 | |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 355 | MVT VT = Root->getValueType(Root->getNumValues()-1); |
Dan Gohman | 602d44a | 2008-09-17 01:39:10 +0000 | [diff] [blame^] | 356 | while (VT == MVT::Flag) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 357 | SDNode *FU = findFlagUse(Root); |
| 358 | if (FU == NULL) |
| 359 | break; |
Dan Gohman | 602d44a | 2008-09-17 01:39:10 +0000 | [diff] [blame^] | 360 | Root = FU; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 361 | VT = Root->getValueType(Root->getNumValues()-1); |
| 362 | } |
| 363 | |
Dan Gohman | 602d44a | 2008-09-17 01:39:10 +0000 | [diff] [blame^] | 364 | return !isNonImmUse(Root, N, U); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | /// MoveBelowTokenFactor - Replace TokenFactor operand with load's chain operand |
| 368 | /// and move load below the TokenFactor. Replace store's chain operand with |
| 369 | /// load's chain result. |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 370 | static void MoveBelowTokenFactor(SelectionDAG *CurDAG, SDValue Load, |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 371 | SDValue Store, SDValue TF) { |
Evan Cheng | 98cfaf8 | 2008-08-25 21:27:18 +0000 | [diff] [blame] | 372 | SmallVector<SDValue, 4> Ops; |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 373 | for (unsigned i = 0, e = TF.getNode()->getNumOperands(); i != e; ++i) |
| 374 | if (Load.getNode() == TF.getOperand(i).getNode()) |
Evan Cheng | 98cfaf8 | 2008-08-25 21:27:18 +0000 | [diff] [blame] | 375 | Ops.push_back(Load.getOperand(0)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 376 | else |
Evan Cheng | 98cfaf8 | 2008-08-25 21:27:18 +0000 | [diff] [blame] | 377 | Ops.push_back(TF.getOperand(i)); |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 378 | CurDAG->UpdateNodeOperands(TF, &Ops[0], Ops.size()); |
| 379 | CurDAG->UpdateNodeOperands(Load, TF, Load.getOperand(1), Load.getOperand(2)); |
| 380 | CurDAG->UpdateNodeOperands(Store, Load.getValue(1), Store.getOperand(1), |
| 381 | Store.getOperand(2), Store.getOperand(3)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 382 | } |
| 383 | |
Evan Cheng | 2b2a701 | 2008-05-23 21:23:16 +0000 | [diff] [blame] | 384 | /// isRMWLoad - Return true if N is a load that's part of RMW sub-DAG. |
| 385 | /// |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 386 | static bool isRMWLoad(SDValue N, SDValue Chain, SDValue Address, |
| 387 | SDValue &Load) { |
Evan Cheng | 2b2a701 | 2008-05-23 21:23:16 +0000 | [diff] [blame] | 388 | if (N.getOpcode() == ISD::BIT_CONVERT) |
| 389 | N = N.getOperand(0); |
| 390 | |
| 391 | LoadSDNode *LD = dyn_cast<LoadSDNode>(N); |
| 392 | if (!LD || LD->isVolatile()) |
| 393 | return false; |
| 394 | if (LD->getAddressingMode() != ISD::UNINDEXED) |
| 395 | return false; |
| 396 | |
| 397 | ISD::LoadExtType ExtType = LD->getExtensionType(); |
| 398 | if (ExtType != ISD::NON_EXTLOAD && ExtType != ISD::EXTLOAD) |
| 399 | return false; |
| 400 | |
| 401 | if (N.hasOneUse() && |
| 402 | N.getOperand(1) == Address && |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 403 | N.getNode()->isOperandOf(Chain.getNode())) { |
Evan Cheng | 2b2a701 | 2008-05-23 21:23:16 +0000 | [diff] [blame] | 404 | Load = N; |
| 405 | return true; |
| 406 | } |
| 407 | return false; |
| 408 | } |
| 409 | |
Evan Cheng | 98cfaf8 | 2008-08-25 21:27:18 +0000 | [diff] [blame] | 410 | /// MoveBelowCallSeqStart - Replace CALLSEQ_START operand with load's chain |
| 411 | /// operand and move load below the call's chain operand. |
| 412 | static void MoveBelowCallSeqStart(SelectionDAG *CurDAG, SDValue Load, |
| 413 | SDValue Call, SDValue Chain) { |
| 414 | SmallVector<SDValue, 8> Ops; |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 415 | for (unsigned i = 0, e = Chain.getNode()->getNumOperands(); i != e; ++i) |
| 416 | if (Load.getNode() == Chain.getOperand(i).getNode()) |
Evan Cheng | 98cfaf8 | 2008-08-25 21:27:18 +0000 | [diff] [blame] | 417 | Ops.push_back(Load.getOperand(0)); |
| 418 | else |
| 419 | Ops.push_back(Chain.getOperand(i)); |
| 420 | CurDAG->UpdateNodeOperands(Chain, &Ops[0], Ops.size()); |
| 421 | CurDAG->UpdateNodeOperands(Load, Call.getOperand(0), |
| 422 | Load.getOperand(1), Load.getOperand(2)); |
| 423 | Ops.clear(); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 424 | Ops.push_back(SDValue(Load.getNode(), 1)); |
| 425 | for (unsigned i = 1, e = Call.getNode()->getNumOperands(); i != e; ++i) |
Evan Cheng | 98cfaf8 | 2008-08-25 21:27:18 +0000 | [diff] [blame] | 426 | Ops.push_back(Call.getOperand(i)); |
| 427 | CurDAG->UpdateNodeOperands(Call, &Ops[0], Ops.size()); |
| 428 | } |
| 429 | |
| 430 | /// isCalleeLoad - Return true if call address is a load and it can be |
| 431 | /// moved below CALLSEQ_START and the chains leading up to the call. |
| 432 | /// Return the CALLSEQ_START by reference as a second output. |
| 433 | static bool isCalleeLoad(SDValue Callee, SDValue &Chain) { |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 434 | if (Callee.getNode() == Chain.getNode() || !Callee.hasOneUse()) |
Evan Cheng | 98cfaf8 | 2008-08-25 21:27:18 +0000 | [diff] [blame] | 435 | return false; |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 436 | LoadSDNode *LD = dyn_cast<LoadSDNode>(Callee.getNode()); |
Evan Cheng | 98cfaf8 | 2008-08-25 21:27:18 +0000 | [diff] [blame] | 437 | if (!LD || |
| 438 | LD->isVolatile() || |
| 439 | LD->getAddressingMode() != ISD::UNINDEXED || |
| 440 | LD->getExtensionType() != ISD::NON_EXTLOAD) |
| 441 | return false; |
| 442 | |
| 443 | // Now let's find the callseq_start. |
| 444 | while (Chain.getOpcode() != ISD::CALLSEQ_START) { |
| 445 | if (!Chain.hasOneUse()) |
| 446 | return false; |
| 447 | Chain = Chain.getOperand(0); |
| 448 | } |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 449 | return Chain.getOperand(0).getNode() == Callee.getNode(); |
Evan Cheng | 98cfaf8 | 2008-08-25 21:27:18 +0000 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | |
Chris Lattner | dec9cb5 | 2008-01-24 08:07:48 +0000 | [diff] [blame] | 453 | /// PreprocessForRMW - Preprocess the DAG to make instruction selection better. |
| 454 | /// This is only run if not in -fast mode (aka -O0). |
| 455 | /// This allows the instruction selector to pick more read-modify-write |
| 456 | /// instructions. This is a common case: |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 457 | /// |
| 458 | /// [Load chain] |
| 459 | /// ^ |
| 460 | /// | |
| 461 | /// [Load] |
| 462 | /// ^ ^ |
| 463 | /// | | |
| 464 | /// / \- |
| 465 | /// / | |
| 466 | /// [TokenFactor] [Op] |
| 467 | /// ^ ^ |
| 468 | /// | | |
| 469 | /// \ / |
| 470 | /// \ / |
| 471 | /// [Store] |
| 472 | /// |
| 473 | /// The fact the store's chain operand != load's chain will prevent the |
| 474 | /// (store (op (load))) instruction from being selected. We can transform it to: |
| 475 | /// |
| 476 | /// [Load chain] |
| 477 | /// ^ |
| 478 | /// | |
| 479 | /// [TokenFactor] |
| 480 | /// ^ |
| 481 | /// | |
| 482 | /// [Load] |
| 483 | /// ^ ^ |
| 484 | /// | | |
| 485 | /// | \- |
| 486 | /// | | |
| 487 | /// | [Op] |
| 488 | /// | ^ |
| 489 | /// | | |
| 490 | /// \ / |
| 491 | /// \ / |
| 492 | /// [Store] |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 493 | void X86DAGToDAGISel::PreprocessForRMW() { |
| 494 | for (SelectionDAG::allnodes_iterator I = CurDAG->allnodes_begin(), |
| 495 | E = CurDAG->allnodes_end(); I != E; ++I) { |
Evan Cheng | 98cfaf8 | 2008-08-25 21:27:18 +0000 | [diff] [blame] | 496 | if (I->getOpcode() == X86ISD::CALL) { |
| 497 | /// Also try moving call address load from outside callseq_start to just |
| 498 | /// before the call to allow it to be folded. |
| 499 | /// |
| 500 | /// [Load chain] |
| 501 | /// ^ |
| 502 | /// | |
| 503 | /// [Load] |
| 504 | /// ^ ^ |
| 505 | /// | | |
| 506 | /// / \-- |
| 507 | /// / | |
| 508 | ///[CALLSEQ_START] | |
| 509 | /// ^ | |
| 510 | /// | | |
| 511 | /// [LOAD/C2Reg] | |
| 512 | /// | | |
| 513 | /// \ / |
| 514 | /// \ / |
| 515 | /// [CALL] |
| 516 | SDValue Chain = I->getOperand(0); |
| 517 | SDValue Load = I->getOperand(1); |
| 518 | if (!isCalleeLoad(Load, Chain)) |
| 519 | continue; |
| 520 | MoveBelowCallSeqStart(CurDAG, Load, SDValue(I, 0), Chain); |
| 521 | ++NumLoadMoved; |
| 522 | continue; |
| 523 | } |
| 524 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 525 | if (!ISD::isNON_TRUNCStore(I)) |
| 526 | continue; |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 527 | SDValue Chain = I->getOperand(0); |
Evan Cheng | 98cfaf8 | 2008-08-25 21:27:18 +0000 | [diff] [blame] | 528 | |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 529 | if (Chain.getNode()->getOpcode() != ISD::TokenFactor) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 530 | continue; |
| 531 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 532 | SDValue N1 = I->getOperand(1); |
| 533 | SDValue N2 = I->getOperand(2); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 534 | if ((N1.getValueType().isFloatingPoint() && |
| 535 | !N1.getValueType().isVector()) || |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 536 | !N1.hasOneUse()) |
| 537 | continue; |
| 538 | |
| 539 | bool RModW = false; |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 540 | SDValue Load; |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 541 | unsigned Opcode = N1.getNode()->getOpcode(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 542 | switch (Opcode) { |
Evan Cheng | 98cfaf8 | 2008-08-25 21:27:18 +0000 | [diff] [blame] | 543 | case ISD::ADD: |
| 544 | case ISD::MUL: |
| 545 | case ISD::AND: |
| 546 | case ISD::OR: |
| 547 | case ISD::XOR: |
| 548 | case ISD::ADDC: |
| 549 | case ISD::ADDE: |
| 550 | case ISD::VECTOR_SHUFFLE: { |
| 551 | SDValue N10 = N1.getOperand(0); |
| 552 | SDValue N11 = N1.getOperand(1); |
| 553 | RModW = isRMWLoad(N10, Chain, N2, Load); |
| 554 | if (!RModW) |
| 555 | RModW = isRMWLoad(N11, Chain, N2, Load); |
| 556 | break; |
| 557 | } |
| 558 | case ISD::SUB: |
| 559 | case ISD::SHL: |
| 560 | case ISD::SRA: |
| 561 | case ISD::SRL: |
| 562 | case ISD::ROTL: |
| 563 | case ISD::ROTR: |
| 564 | case ISD::SUBC: |
| 565 | case ISD::SUBE: |
| 566 | case X86ISD::SHLD: |
| 567 | case X86ISD::SHRD: { |
| 568 | SDValue N10 = N1.getOperand(0); |
| 569 | RModW = isRMWLoad(N10, Chain, N2, Load); |
| 570 | break; |
| 571 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | if (RModW) { |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 575 | MoveBelowTokenFactor(CurDAG, Load, SDValue(I, 0), Chain); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 576 | ++NumLoadMoved; |
| 577 | } |
| 578 | } |
| 579 | } |
| 580 | |
Chris Lattner | dec9cb5 | 2008-01-24 08:07:48 +0000 | [diff] [blame] | 581 | |
| 582 | /// PreprocessForFPConvert - Walk over the dag lowering fpround and fpextend |
| 583 | /// nodes that target the FP stack to be store and load to the stack. This is a |
| 584 | /// gross hack. We would like to simply mark these as being illegal, but when |
| 585 | /// we do that, legalize produces these when it expands calls, then expands |
| 586 | /// these in the same legalize pass. We would like dag combine to be able to |
| 587 | /// hack on these between the call expansion and the node legalization. As such |
| 588 | /// this pass basically does "really late" legalization of these inline with the |
| 589 | /// X86 isel pass. |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 590 | void X86DAGToDAGISel::PreprocessForFPConvert() { |
| 591 | for (SelectionDAG::allnodes_iterator I = CurDAG->allnodes_begin(), |
| 592 | E = CurDAG->allnodes_end(); I != E; ) { |
Chris Lattner | dec9cb5 | 2008-01-24 08:07:48 +0000 | [diff] [blame] | 593 | SDNode *N = I++; // Preincrement iterator to avoid invalidation issues. |
| 594 | if (N->getOpcode() != ISD::FP_ROUND && N->getOpcode() != ISD::FP_EXTEND) |
| 595 | continue; |
| 596 | |
| 597 | // If the source and destination are SSE registers, then this is a legal |
| 598 | // conversion that should not be lowered. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 599 | MVT SrcVT = N->getOperand(0).getValueType(); |
| 600 | MVT DstVT = N->getValueType(0); |
Chris Lattner | dec9cb5 | 2008-01-24 08:07:48 +0000 | [diff] [blame] | 601 | bool SrcIsSSE = X86Lowering.isScalarFPTypeInSSEReg(SrcVT); |
| 602 | bool DstIsSSE = X86Lowering.isScalarFPTypeInSSEReg(DstVT); |
| 603 | if (SrcIsSSE && DstIsSSE) |
| 604 | continue; |
| 605 | |
Chris Lattner | 5d294e5 | 2008-03-09 07:05:32 +0000 | [diff] [blame] | 606 | if (!SrcIsSSE && !DstIsSSE) { |
| 607 | // If this is an FPStack extension, it is a noop. |
| 608 | if (N->getOpcode() == ISD::FP_EXTEND) |
| 609 | continue; |
| 610 | // If this is a value-preserving FPStack truncation, it is a noop. |
| 611 | if (N->getConstantOperandVal(1)) |
| 612 | continue; |
| 613 | } |
| 614 | |
Chris Lattner | dec9cb5 | 2008-01-24 08:07:48 +0000 | [diff] [blame] | 615 | // Here we could have an FP stack truncation or an FPStack <-> SSE convert. |
| 616 | // FPStack has extload and truncstore. SSE can fold direct loads into other |
| 617 | // operations. Based on this, decide what we want to do. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 618 | MVT MemVT; |
Chris Lattner | dec9cb5 | 2008-01-24 08:07:48 +0000 | [diff] [blame] | 619 | if (N->getOpcode() == ISD::FP_ROUND) |
| 620 | MemVT = DstVT; // FP_ROUND must use DstVT, we can't do a 'trunc load'. |
| 621 | else |
| 622 | MemVT = SrcIsSSE ? SrcVT : DstVT; |
| 623 | |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 624 | SDValue MemTmp = CurDAG->CreateStackTemporary(MemVT); |
Chris Lattner | dec9cb5 | 2008-01-24 08:07:48 +0000 | [diff] [blame] | 625 | |
| 626 | // FIXME: optimize the case where the src/dest is a load or store? |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 627 | SDValue Store = CurDAG->getTruncStore(CurDAG->getEntryNode(), |
| 628 | N->getOperand(0), |
| 629 | MemTmp, NULL, 0, MemVT); |
| 630 | SDValue Result = CurDAG->getExtLoad(ISD::EXTLOAD, DstVT, Store, MemTmp, |
| 631 | NULL, 0, MemVT); |
Chris Lattner | dec9cb5 | 2008-01-24 08:07:48 +0000 | [diff] [blame] | 632 | |
| 633 | // We're about to replace all uses of the FP_ROUND/FP_EXTEND with the |
| 634 | // extload we created. This will cause general havok on the dag because |
| 635 | // anything below the conversion could be folded into other existing nodes. |
| 636 | // To avoid invalidating 'I', back it up to the convert node. |
| 637 | --I; |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 638 | CurDAG->ReplaceAllUsesOfValueWith(SDValue(N, 0), Result); |
Chris Lattner | dec9cb5 | 2008-01-24 08:07:48 +0000 | [diff] [blame] | 639 | |
| 640 | // Now that we did that, the node is dead. Increment the iterator to the |
| 641 | // next node to process, then delete N. |
| 642 | ++I; |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 643 | CurDAG->DeleteNode(N); |
Chris Lattner | dec9cb5 | 2008-01-24 08:07:48 +0000 | [diff] [blame] | 644 | } |
| 645 | } |
| 646 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 647 | /// InstructionSelectBasicBlock - This callback is invoked by SelectionDAGISel |
| 648 | /// when it has created a SelectionDAG for us to codegen. |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 649 | void X86DAGToDAGISel::InstructionSelect() { |
Evan Cheng | 34fd4f3 | 2008-06-30 20:45:06 +0000 | [diff] [blame] | 650 | CurBB = BB; // BB can change as result of isel. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 651 | |
Evan Cheng | 34fd4f3 | 2008-06-30 20:45:06 +0000 | [diff] [blame] | 652 | DEBUG(BB->dump()); |
Dan Gohman | a29efcf | 2008-08-13 19:55:00 +0000 | [diff] [blame] | 653 | if (!Fast) |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 654 | PreprocessForRMW(); |
Chris Lattner | dec9cb5 | 2008-01-24 08:07:48 +0000 | [diff] [blame] | 655 | |
| 656 | // FIXME: This should only happen when not -fast. |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 657 | PreprocessForFPConvert(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 658 | |
| 659 | // Codegen the basic block. |
| 660 | #ifndef NDEBUG |
| 661 | DOUT << "===== Instruction selection begins:\n"; |
| 662 | Indent = 0; |
| 663 | #endif |
Dan Gohman | bd3f882 | 2008-08-21 16:36:34 +0000 | [diff] [blame] | 664 | SelectRoot(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 665 | #ifndef NDEBUG |
| 666 | DOUT << "===== Instruction selection ends:\n"; |
| 667 | #endif |
| 668 | |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 669 | CurDAG->RemoveDeadNodes(); |
Evan Cheng | 34fd4f3 | 2008-06-30 20:45:06 +0000 | [diff] [blame] | 670 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 671 | |
Dan Gohman | b552df7 | 2008-07-21 20:00:07 +0000 | [diff] [blame] | 672 | void X86DAGToDAGISel::InstructionSelectPostProcessing() { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 673 | // If we are emitting FP stack code, scan the basic block to determine if this |
| 674 | // block defines any FP values. If so, put an FP_REG_KILL instruction before |
| 675 | // the terminator of the block. |
Dale Johannesen | c428e0f | 2007-08-07 20:29:26 +0000 | [diff] [blame] | 676 | |
Dale Johannesen | 684887e | 2007-09-24 22:52:39 +0000 | [diff] [blame] | 677 | // Note that FP stack instructions are used in all modes for long double, |
| 678 | // so we always need to do this check. |
| 679 | // Also note that it's possible for an FP stack register to be live across |
| 680 | // an instruction that produces multiple basic blocks (SSE CMOV) so we |
| 681 | // must check all the generated basic blocks. |
Dale Johannesen | c428e0f | 2007-08-07 20:29:26 +0000 | [diff] [blame] | 682 | |
| 683 | // Scan all of the machine instructions in these MBBs, checking for FP |
| 684 | // stores. (RFP32 and RFP64 will not exist in SSE mode, but RFP80 might.) |
Evan Cheng | 34fd4f3 | 2008-06-30 20:45:06 +0000 | [diff] [blame] | 685 | MachineFunction::iterator MBBI = CurBB; |
Chris Lattner | 04d64b2 | 2008-03-10 23:34:12 +0000 | [diff] [blame] | 686 | MachineFunction::iterator EndMBB = BB; ++EndMBB; |
| 687 | for (; MBBI != EndMBB; ++MBBI) { |
| 688 | MachineBasicBlock *MBB = MBBI; |
| 689 | |
| 690 | // If this block returns, ignore it. We don't want to insert an FP_REG_KILL |
| 691 | // before the return. |
| 692 | if (!MBB->empty()) { |
| 693 | MachineBasicBlock::iterator EndI = MBB->end(); |
| 694 | --EndI; |
| 695 | if (EndI->getDesc().isReturn()) |
| 696 | continue; |
| 697 | } |
| 698 | |
Dale Johannesen | 684887e | 2007-09-24 22:52:39 +0000 | [diff] [blame] | 699 | bool ContainsFPCode = false; |
Chris Lattner | 04d64b2 | 2008-03-10 23:34:12 +0000 | [diff] [blame] | 700 | for (MachineBasicBlock::iterator I = MBB->begin(), E = MBB->end(); |
Dale Johannesen | c428e0f | 2007-08-07 20:29:26 +0000 | [diff] [blame] | 701 | !ContainsFPCode && I != E; ++I) { |
| 702 | if (I->getNumOperands() != 0 && I->getOperand(0).isRegister()) { |
| 703 | const TargetRegisterClass *clas; |
| 704 | for (unsigned op = 0, e = I->getNumOperands(); op != e; ++op) { |
| 705 | if (I->getOperand(op).isRegister() && I->getOperand(op).isDef() && |
Chris Lattner | 04d64b2 | 2008-03-10 23:34:12 +0000 | [diff] [blame] | 706 | TargetRegisterInfo::isVirtualRegister(I->getOperand(op).getReg()) && |
Chris Lattner | 1b98919 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 707 | ((clas = RegInfo->getRegClass(I->getOperand(0).getReg())) == |
Dale Johannesen | c428e0f | 2007-08-07 20:29:26 +0000 | [diff] [blame] | 708 | X86::RFP32RegisterClass || |
| 709 | clas == X86::RFP64RegisterClass || |
| 710 | clas == X86::RFP80RegisterClass)) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 711 | ContainsFPCode = true; |
| 712 | break; |
| 713 | } |
| 714 | } |
| 715 | } |
| 716 | } |
Dale Johannesen | 684887e | 2007-09-24 22:52:39 +0000 | [diff] [blame] | 717 | // Check PHI nodes in successor blocks. These PHI's will be lowered to have |
| 718 | // a copy of the input value in this block. In SSE mode, we only care about |
| 719 | // 80-bit values. |
| 720 | if (!ContainsFPCode) { |
| 721 | // Final check, check LLVM BB's that are successors to the LLVM BB |
| 722 | // corresponding to BB for FP PHI nodes. |
| 723 | const BasicBlock *LLVMBB = BB->getBasicBlock(); |
| 724 | const PHINode *PN; |
| 725 | for (succ_const_iterator SI = succ_begin(LLVMBB), E = succ_end(LLVMBB); |
| 726 | !ContainsFPCode && SI != E; ++SI) { |
| 727 | for (BasicBlock::const_iterator II = SI->begin(); |
| 728 | (PN = dyn_cast<PHINode>(II)); ++II) { |
| 729 | if (PN->getType()==Type::X86_FP80Ty || |
| 730 | (!Subtarget->hasSSE1() && PN->getType()->isFloatingPoint()) || |
| 731 | (!Subtarget->hasSSE2() && PN->getType()==Type::DoubleTy)) { |
| 732 | ContainsFPCode = true; |
| 733 | break; |
| 734 | } |
Dale Johannesen | c428e0f | 2007-08-07 20:29:26 +0000 | [diff] [blame] | 735 | } |
| 736 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 737 | } |
Dale Johannesen | 684887e | 2007-09-24 22:52:39 +0000 | [diff] [blame] | 738 | // Finally, if we found any FP code, emit the FP_REG_KILL instruction. |
| 739 | if (ContainsFPCode) { |
Chris Lattner | 04d64b2 | 2008-03-10 23:34:12 +0000 | [diff] [blame] | 740 | BuildMI(*MBB, MBBI->getFirstTerminator(), |
Dale Johannesen | 684887e | 2007-09-24 22:52:39 +0000 | [diff] [blame] | 741 | TM.getInstrInfo()->get(X86::FP_REG_KILL)); |
| 742 | ++NumFPKill; |
| 743 | } |
Chris Lattner | 04d64b2 | 2008-03-10 23:34:12 +0000 | [diff] [blame] | 744 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 745 | } |
| 746 | |
Anton Korobeynikov | 34ef31e | 2007-09-25 21:52:30 +0000 | [diff] [blame] | 747 | /// EmitSpecialCodeForMain - Emit any code that needs to be executed only in |
| 748 | /// the main function. |
| 749 | void X86DAGToDAGISel::EmitSpecialCodeForMain(MachineBasicBlock *BB, |
| 750 | MachineFrameInfo *MFI) { |
| 751 | const TargetInstrInfo *TII = TM.getInstrInfo(); |
| 752 | if (Subtarget->isTargetCygMing()) |
| 753 | BuildMI(BB, TII->get(X86::CALLpcrel32)).addExternalSymbol("__main"); |
| 754 | } |
| 755 | |
| 756 | void X86DAGToDAGISel::EmitFunctionEntryCode(Function &Fn, MachineFunction &MF) { |
| 757 | // If this is main, emit special code for main. |
| 758 | MachineBasicBlock *BB = MF.begin(); |
| 759 | if (Fn.hasExternalLinkage() && Fn.getName() == "main") |
| 760 | EmitSpecialCodeForMain(BB, MF.getFrameInfo()); |
| 761 | } |
| 762 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 763 | /// MatchAddress - Add the specified node to the specified addressing mode, |
| 764 | /// returning true if it cannot be done. This just pattern matches for the |
Chris Lattner | 7f06edd | 2007-12-08 07:22:58 +0000 | [diff] [blame] | 765 | /// addressing mode. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 766 | bool X86DAGToDAGISel::MatchAddress(SDValue N, X86ISelAddressMode &AM, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 767 | bool isRoot, unsigned Depth) { |
Dale Johannesen | c501c08 | 2008-08-11 23:46:25 +0000 | [diff] [blame] | 768 | DOUT << "MatchAddress: "; DEBUG(AM.dump()); |
Dan Gohman | a60c1b3 | 2007-08-13 20:03:06 +0000 | [diff] [blame] | 769 | // Limit recursion. |
| 770 | if (Depth > 5) |
| 771 | return MatchAddressBase(N, AM, isRoot, Depth); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 772 | |
| 773 | // RIP relative addressing: %rip + 32-bit displacement! |
| 774 | if (AM.isRIPRel) { |
| 775 | if (!AM.ES && AM.JT != -1 && N.getOpcode() == ISD::Constant) { |
| 776 | int64_t Val = cast<ConstantSDNode>(N)->getSignExtended(); |
| 777 | if (isInt32(AM.Disp + Val)) { |
| 778 | AM.Disp += Val; |
| 779 | return false; |
| 780 | } |
| 781 | } |
| 782 | return true; |
| 783 | } |
| 784 | |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 785 | int id = N.getNode()->getNodeId(); |
Evan Cheng | f2abee7 | 2007-12-13 00:43:27 +0000 | [diff] [blame] | 786 | bool AlreadySelected = isSelected(id); // Already selected, not yet replaced. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 787 | |
| 788 | switch (N.getOpcode()) { |
| 789 | default: break; |
| 790 | case ISD::Constant: { |
| 791 | int64_t Val = cast<ConstantSDNode>(N)->getSignExtended(); |
| 792 | if (isInt32(AM.Disp + Val)) { |
| 793 | AM.Disp += Val; |
| 794 | return false; |
| 795 | } |
| 796 | break; |
| 797 | } |
| 798 | |
| 799 | case X86ISD::Wrapper: { |
Dale Johannesen | c501c08 | 2008-08-11 23:46:25 +0000 | [diff] [blame] | 800 | DOUT << "Wrapper: 64bit " << Subtarget->is64Bit(); |
| 801 | DOUT << " AM "; DEBUG(AM.dump()); DOUT << "\n"; |
| 802 | DOUT << "AlreadySelected " << AlreadySelected << "\n"; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 803 | bool is64Bit = Subtarget->is64Bit(); |
| 804 | // Under X86-64 non-small code model, GV (and friends) are 64-bits. |
Evan Cheng | 3b5a127 | 2008-02-07 08:53:49 +0000 | [diff] [blame] | 805 | // Also, base and index reg must be 0 in order to use rip as base. |
| 806 | if (is64Bit && (TM.getCodeModel() != CodeModel::Small || |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 807 | AM.Base.Reg.getNode() || AM.IndexReg.getNode())) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 808 | break; |
| 809 | if (AM.GV != 0 || AM.CP != 0 || AM.ES != 0 || AM.JT != -1) |
| 810 | break; |
| 811 | // If value is available in a register both base and index components have |
| 812 | // been picked, we can't fit the result available in the register in the |
| 813 | // addressing mode. Duplicate GlobalAddress or ConstantPool as displacement. |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 814 | if (!AlreadySelected || (AM.Base.Reg.getNode() && AM.IndexReg.getNode())) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 815 | SDValue N0 = N.getOperand(0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 816 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(N0)) { |
| 817 | GlobalValue *GV = G->getGlobal(); |
Evan Cheng | 3b5a127 | 2008-02-07 08:53:49 +0000 | [diff] [blame] | 818 | AM.GV = GV; |
| 819 | AM.Disp += G->getOffset(); |
Evan Cheng | a54e14f | 2008-02-12 19:20:46 +0000 | [diff] [blame] | 820 | AM.isRIPRel = TM.getRelocationModel() != Reloc::Static && |
| 821 | Subtarget->isPICStyleRIPRel(); |
Evan Cheng | 3b5a127 | 2008-02-07 08:53:49 +0000 | [diff] [blame] | 822 | return false; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 823 | } else if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(N0)) { |
Evan Cheng | 3b5a127 | 2008-02-07 08:53:49 +0000 | [diff] [blame] | 824 | AM.CP = CP->getConstVal(); |
| 825 | AM.Align = CP->getAlignment(); |
| 826 | AM.Disp += CP->getOffset(); |
Evan Cheng | a54e14f | 2008-02-12 19:20:46 +0000 | [diff] [blame] | 827 | AM.isRIPRel = TM.getRelocationModel() != Reloc::Static && |
| 828 | Subtarget->isPICStyleRIPRel(); |
Evan Cheng | 3b5a127 | 2008-02-07 08:53:49 +0000 | [diff] [blame] | 829 | return false; |
Bill Wendling | fef0605 | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 830 | } else if (ExternalSymbolSDNode *S =dyn_cast<ExternalSymbolSDNode>(N0)) { |
Evan Cheng | 3b5a127 | 2008-02-07 08:53:49 +0000 | [diff] [blame] | 831 | AM.ES = S->getSymbol(); |
Evan Cheng | a54e14f | 2008-02-12 19:20:46 +0000 | [diff] [blame] | 832 | AM.isRIPRel = TM.getRelocationModel() != Reloc::Static && |
| 833 | Subtarget->isPICStyleRIPRel(); |
Evan Cheng | 3b5a127 | 2008-02-07 08:53:49 +0000 | [diff] [blame] | 834 | return false; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 835 | } else if (JumpTableSDNode *J = dyn_cast<JumpTableSDNode>(N0)) { |
Evan Cheng | 3b5a127 | 2008-02-07 08:53:49 +0000 | [diff] [blame] | 836 | AM.JT = J->getIndex(); |
Evan Cheng | a54e14f | 2008-02-12 19:20:46 +0000 | [diff] [blame] | 837 | AM.isRIPRel = TM.getRelocationModel() != Reloc::Static && |
| 838 | Subtarget->isPICStyleRIPRel(); |
Evan Cheng | 3b5a127 | 2008-02-07 08:53:49 +0000 | [diff] [blame] | 839 | return false; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 840 | } |
| 841 | } |
| 842 | break; |
| 843 | } |
| 844 | |
| 845 | case ISD::FrameIndex: |
Gabor Greif | e9f7f58 | 2008-08-31 15:37:04 +0000 | [diff] [blame] | 846 | if (AM.BaseType == X86ISelAddressMode::RegBase |
| 847 | && AM.Base.Reg.getNode() == 0) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 848 | AM.BaseType = X86ISelAddressMode::FrameIndexBase; |
| 849 | AM.Base.FrameIndex = cast<FrameIndexSDNode>(N)->getIndex(); |
| 850 | return false; |
| 851 | } |
| 852 | break; |
| 853 | |
| 854 | case ISD::SHL: |
Gabor Greif | e9f7f58 | 2008-08-31 15:37:04 +0000 | [diff] [blame] | 855 | if (AlreadySelected || AM.IndexReg.getNode() != 0 |
| 856 | || AM.Scale != 1 || AM.isRIPRel) |
Chris Lattner | 7f06edd | 2007-12-08 07:22:58 +0000 | [diff] [blame] | 857 | break; |
| 858 | |
Gabor Greif | e9f7f58 | 2008-08-31 15:37:04 +0000 | [diff] [blame] | 859 | if (ConstantSDNode |
| 860 | *CN = dyn_cast<ConstantSDNode>(N.getNode()->getOperand(1))) { |
Dan Gohman | faeb4a3 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 861 | unsigned Val = CN->getZExtValue(); |
Chris Lattner | 7f06edd | 2007-12-08 07:22:58 +0000 | [diff] [blame] | 862 | if (Val == 1 || Val == 2 || Val == 3) { |
| 863 | AM.Scale = 1 << Val; |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 864 | SDValue ShVal = N.getNode()->getOperand(0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 865 | |
Chris Lattner | 7f06edd | 2007-12-08 07:22:58 +0000 | [diff] [blame] | 866 | // Okay, we know that we have a scale by now. However, if the scaled |
| 867 | // value is an add of something and a constant, we can fold the |
| 868 | // constant into the disp field here. |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 869 | if (ShVal.getNode()->getOpcode() == ISD::ADD && ShVal.hasOneUse() && |
| 870 | isa<ConstantSDNode>(ShVal.getNode()->getOperand(1))) { |
| 871 | AM.IndexReg = ShVal.getNode()->getOperand(0); |
Chris Lattner | 7f06edd | 2007-12-08 07:22:58 +0000 | [diff] [blame] | 872 | ConstantSDNode *AddVal = |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 873 | cast<ConstantSDNode>(ShVal.getNode()->getOperand(1)); |
Dan Gohman | faeb4a3 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 874 | uint64_t Disp = AM.Disp + (AddVal->getZExtValue() << Val); |
Chris Lattner | 7f06edd | 2007-12-08 07:22:58 +0000 | [diff] [blame] | 875 | if (isInt32(Disp)) |
| 876 | AM.Disp = Disp; |
| 877 | else |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 878 | AM.IndexReg = ShVal; |
Chris Lattner | 7f06edd | 2007-12-08 07:22:58 +0000 | [diff] [blame] | 879 | } else { |
| 880 | AM.IndexReg = ShVal; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 881 | } |
Chris Lattner | 7f06edd | 2007-12-08 07:22:58 +0000 | [diff] [blame] | 882 | return false; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 883 | } |
| 884 | break; |
Chris Lattner | 7f06edd | 2007-12-08 07:22:58 +0000 | [diff] [blame] | 885 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 886 | |
Dan Gohman | 35b9922 | 2007-10-22 20:22:24 +0000 | [diff] [blame] | 887 | case ISD::SMUL_LOHI: |
| 888 | case ISD::UMUL_LOHI: |
| 889 | // A mul_lohi where we need the low part can be folded as a plain multiply. |
Gabor Greif | 46bf547 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 890 | if (N.getResNo() != 0) break; |
Dan Gohman | 35b9922 | 2007-10-22 20:22:24 +0000 | [diff] [blame] | 891 | // FALL THROUGH |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 892 | case ISD::MUL: |
| 893 | // X*[3,5,9] -> X+X*[2,4,8] |
Evan Cheng | f2abee7 | 2007-12-13 00:43:27 +0000 | [diff] [blame] | 894 | if (!AlreadySelected && |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 895 | AM.BaseType == X86ISelAddressMode::RegBase && |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 896 | AM.Base.Reg.getNode() == 0 && |
| 897 | AM.IndexReg.getNode() == 0 && |
Evan Cheng | 3b5a127 | 2008-02-07 08:53:49 +0000 | [diff] [blame] | 898 | !AM.isRIPRel) { |
Gabor Greif | e9f7f58 | 2008-08-31 15:37:04 +0000 | [diff] [blame] | 899 | if (ConstantSDNode |
| 900 | *CN = dyn_cast<ConstantSDNode>(N.getNode()->getOperand(1))) |
Dan Gohman | faeb4a3 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 901 | if (CN->getZExtValue() == 3 || CN->getZExtValue() == 5 || |
| 902 | CN->getZExtValue() == 9) { |
| 903 | AM.Scale = unsigned(CN->getZExtValue())-1; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 904 | |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 905 | SDValue MulVal = N.getNode()->getOperand(0); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 906 | SDValue Reg; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 907 | |
| 908 | // Okay, we know that we have a scale by now. However, if the scaled |
| 909 | // value is an add of something and a constant, we can fold the |
| 910 | // constant into the disp field here. |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 911 | if (MulVal.getNode()->getOpcode() == ISD::ADD && MulVal.hasOneUse() && |
| 912 | isa<ConstantSDNode>(MulVal.getNode()->getOperand(1))) { |
| 913 | Reg = MulVal.getNode()->getOperand(0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 914 | ConstantSDNode *AddVal = |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 915 | cast<ConstantSDNode>(MulVal.getNode()->getOperand(1)); |
Dan Gohman | faeb4a3 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 916 | uint64_t Disp = AM.Disp + AddVal->getZExtValue() * |
| 917 | CN->getZExtValue(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 918 | if (isInt32(Disp)) |
| 919 | AM.Disp = Disp; |
| 920 | else |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 921 | Reg = N.getNode()->getOperand(0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 922 | } else { |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 923 | Reg = N.getNode()->getOperand(0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | AM.IndexReg = AM.Base.Reg = Reg; |
| 927 | return false; |
| 928 | } |
| 929 | } |
| 930 | break; |
| 931 | |
| 932 | case ISD::ADD: |
Evan Cheng | f2abee7 | 2007-12-13 00:43:27 +0000 | [diff] [blame] | 933 | if (!AlreadySelected) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 934 | X86ISelAddressMode Backup = AM; |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 935 | if (!MatchAddress(N.getNode()->getOperand(0), AM, false, Depth+1) && |
| 936 | !MatchAddress(N.getNode()->getOperand(1), AM, false, Depth+1)) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 937 | return false; |
| 938 | AM = Backup; |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 939 | if (!MatchAddress(N.getNode()->getOperand(1), AM, false, Depth+1) && |
| 940 | !MatchAddress(N.getNode()->getOperand(0), AM, false, Depth+1)) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 941 | return false; |
| 942 | AM = Backup; |
| 943 | } |
| 944 | break; |
| 945 | |
| 946 | case ISD::OR: |
| 947 | // Handle "X | C" as "X + C" iff X is known to have C bits clear. |
Evan Cheng | f2abee7 | 2007-12-13 00:43:27 +0000 | [diff] [blame] | 948 | if (AlreadySelected) break; |
Chris Lattner | 7f06edd | 2007-12-08 07:22:58 +0000 | [diff] [blame] | 949 | |
| 950 | if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N.getOperand(1))) { |
| 951 | X86ISelAddressMode Backup = AM; |
| 952 | // Start with the LHS as an addr mode. |
| 953 | if (!MatchAddress(N.getOperand(0), AM, false) && |
| 954 | // Address could not have picked a GV address for the displacement. |
| 955 | AM.GV == NULL && |
| 956 | // On x86-64, the resultant disp must fit in 32-bits. |
| 957 | isInt32(AM.Disp + CN->getSignExtended()) && |
| 958 | // Check to see if the LHS & C is zero. |
Dan Gohman | 07961cd | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 959 | CurDAG->MaskedValueIsZero(N.getOperand(0), CN->getAPIntValue())) { |
Dan Gohman | faeb4a3 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 960 | AM.Disp += CN->getZExtValue(); |
Chris Lattner | 7f06edd | 2007-12-08 07:22:58 +0000 | [diff] [blame] | 961 | return false; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 962 | } |
Chris Lattner | 7f06edd | 2007-12-08 07:22:58 +0000 | [diff] [blame] | 963 | AM = Backup; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 964 | } |
| 965 | break; |
Evan Cheng | f2abee7 | 2007-12-13 00:43:27 +0000 | [diff] [blame] | 966 | |
| 967 | case ISD::AND: { |
| 968 | // Handle "(x << C1) & C2" as "(X & (C2>>C1)) << C1" if safe and if this |
| 969 | // allows us to fold the shift into this addressing mode. |
| 970 | if (AlreadySelected) break; |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 971 | SDValue Shift = N.getOperand(0); |
Evan Cheng | f2abee7 | 2007-12-13 00:43:27 +0000 | [diff] [blame] | 972 | if (Shift.getOpcode() != ISD::SHL) break; |
| 973 | |
| 974 | // Scale must not be used already. |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 975 | if (AM.IndexReg.getNode() != 0 || AM.Scale != 1) break; |
Evan Cheng | 3b5a127 | 2008-02-07 08:53:49 +0000 | [diff] [blame] | 976 | |
| 977 | // Not when RIP is used as the base. |
| 978 | if (AM.isRIPRel) break; |
Evan Cheng | f2abee7 | 2007-12-13 00:43:27 +0000 | [diff] [blame] | 979 | |
| 980 | ConstantSDNode *C2 = dyn_cast<ConstantSDNode>(N.getOperand(1)); |
| 981 | ConstantSDNode *C1 = dyn_cast<ConstantSDNode>(Shift.getOperand(1)); |
| 982 | if (!C1 || !C2) break; |
| 983 | |
| 984 | // Not likely to be profitable if either the AND or SHIFT node has more |
| 985 | // than one use (unless all uses are for address computation). Besides, |
| 986 | // isel mechanism requires their node ids to be reused. |
| 987 | if (!N.hasOneUse() || !Shift.hasOneUse()) |
| 988 | break; |
| 989 | |
| 990 | // Verify that the shift amount is something we can fold. |
Dan Gohman | faeb4a3 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 991 | unsigned ShiftCst = C1->getZExtValue(); |
Evan Cheng | f2abee7 | 2007-12-13 00:43:27 +0000 | [diff] [blame] | 992 | if (ShiftCst != 1 && ShiftCst != 2 && ShiftCst != 3) |
| 993 | break; |
| 994 | |
| 995 | // Get the new AND mask, this folds to a constant. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 996 | SDValue NewANDMask = CurDAG->getNode(ISD::SRL, N.getValueType(), |
| 997 | SDValue(C2, 0), SDValue(C1, 0)); |
| 998 | SDValue NewAND = CurDAG->getNode(ISD::AND, N.getValueType(), |
Evan Cheng | f2abee7 | 2007-12-13 00:43:27 +0000 | [diff] [blame] | 999 | Shift.getOperand(0), NewANDMask); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1000 | NewANDMask.getNode()->setNodeId(Shift.getNode()->getNodeId()); |
| 1001 | NewAND.getNode()->setNodeId(N.getNode()->getNodeId()); |
Evan Cheng | f2abee7 | 2007-12-13 00:43:27 +0000 | [diff] [blame] | 1002 | |
| 1003 | AM.Scale = 1 << ShiftCst; |
| 1004 | AM.IndexReg = NewAND; |
| 1005 | return false; |
| 1006 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1007 | } |
| 1008 | |
Dan Gohman | a60c1b3 | 2007-08-13 20:03:06 +0000 | [diff] [blame] | 1009 | return MatchAddressBase(N, AM, isRoot, Depth); |
| 1010 | } |
| 1011 | |
| 1012 | /// MatchAddressBase - Helper for MatchAddress. Add the specified node to the |
| 1013 | /// specified addressing mode without any further recursion. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1014 | bool X86DAGToDAGISel::MatchAddressBase(SDValue N, X86ISelAddressMode &AM, |
Dan Gohman | a60c1b3 | 2007-08-13 20:03:06 +0000 | [diff] [blame] | 1015 | bool isRoot, unsigned Depth) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1016 | // Is the base register already occupied? |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1017 | if (AM.BaseType != X86ISelAddressMode::RegBase || AM.Base.Reg.getNode()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1018 | // If so, check to see if the scale index register is set. |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1019 | if (AM.IndexReg.getNode() == 0 && !AM.isRIPRel) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1020 | AM.IndexReg = N; |
| 1021 | AM.Scale = 1; |
| 1022 | return false; |
| 1023 | } |
| 1024 | |
| 1025 | // Otherwise, we cannot select it. |
| 1026 | return true; |
| 1027 | } |
| 1028 | |
| 1029 | // Default, generate it as a register. |
| 1030 | AM.BaseType = X86ISelAddressMode::RegBase; |
| 1031 | AM.Base.Reg = N; |
| 1032 | return false; |
| 1033 | } |
| 1034 | |
| 1035 | /// SelectAddr - returns true if it is able pattern match an addressing mode. |
| 1036 | /// It returns the operands which make up the maximal addressing mode it can |
| 1037 | /// match by reference. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1038 | bool X86DAGToDAGISel::SelectAddr(SDValue Op, SDValue N, SDValue &Base, |
| 1039 | SDValue &Scale, SDValue &Index, |
| 1040 | SDValue &Disp) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1041 | X86ISelAddressMode AM; |
| 1042 | if (MatchAddress(N, AM)) |
| 1043 | return false; |
| 1044 | |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1045 | MVT VT = N.getValueType(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1046 | if (AM.BaseType == X86ISelAddressMode::RegBase) { |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1047 | if (!AM.Base.Reg.getNode()) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1048 | AM.Base.Reg = CurDAG->getRegister(0, VT); |
| 1049 | } |
| 1050 | |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1051 | if (!AM.IndexReg.getNode()) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1052 | AM.IndexReg = CurDAG->getRegister(0, VT); |
| 1053 | |
| 1054 | getAddressOperands(AM, Base, Scale, Index, Disp); |
| 1055 | return true; |
| 1056 | } |
| 1057 | |
| 1058 | /// isZeroNode - Returns true if Elt is a constant zero or a floating point |
| 1059 | /// constant +0.0. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1060 | static inline bool isZeroNode(SDValue Elt) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1061 | return ((isa<ConstantSDNode>(Elt) && |
Dan Gohman | faeb4a3 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1062 | cast<ConstantSDNode>(Elt)->getZExtValue() == 0) || |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1063 | (isa<ConstantFPSDNode>(Elt) && |
Dale Johannesen | df8a831 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 1064 | cast<ConstantFPSDNode>(Elt)->getValueAPF().isPosZero())); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1065 | } |
| 1066 | |
| 1067 | |
| 1068 | /// SelectScalarSSELoad - Match a scalar SSE load. In particular, we want to |
| 1069 | /// match a load whose top elements are either undef or zeros. The load flavor |
| 1070 | /// is derived from the type of N, which is either v4f32 or v2f64. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1071 | bool X86DAGToDAGISel::SelectScalarSSELoad(SDValue Op, SDValue Pred, |
| 1072 | SDValue N, SDValue &Base, |
| 1073 | SDValue &Scale, SDValue &Index, |
| 1074 | SDValue &Disp, SDValue &InChain, |
| 1075 | SDValue &OutChain) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1076 | if (N.getOpcode() == ISD::SCALAR_TO_VECTOR) { |
| 1077 | InChain = N.getOperand(0).getValue(1); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1078 | if (ISD::isNON_EXTLoad(InChain.getNode()) && |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1079 | InChain.getValue(0).hasOneUse() && |
| 1080 | N.hasOneUse() && |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1081 | CanBeFoldedBy(N.getNode(), Pred.getNode(), Op.getNode())) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1082 | LoadSDNode *LD = cast<LoadSDNode>(InChain); |
| 1083 | if (!SelectAddr(Op, LD->getBasePtr(), Base, Scale, Index, Disp)) |
| 1084 | return false; |
| 1085 | OutChain = LD->getChain(); |
| 1086 | return true; |
| 1087 | } |
| 1088 | } |
| 1089 | |
| 1090 | // Also handle the case where we explicitly require zeros in the top |
| 1091 | // elements. This is a vector shuffle from the zero vector. |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1092 | if (N.getOpcode() == X86ISD::VZEXT_MOVL && N.getNode()->hasOneUse() && |
Chris Lattner | e6aa386 | 2007-11-25 00:24:49 +0000 | [diff] [blame] | 1093 | // Check to see if the top elements are all zeros (or bitcast of zeros). |
Evan Cheng | 40ee6e5 | 2008-05-08 00:57:18 +0000 | [diff] [blame] | 1094 | N.getOperand(0).getOpcode() == ISD::SCALAR_TO_VECTOR && |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1095 | N.getOperand(0).getNode()->hasOneUse() && |
| 1096 | ISD::isNON_EXTLoad(N.getOperand(0).getOperand(0).getNode()) && |
Evan Cheng | 40ee6e5 | 2008-05-08 00:57:18 +0000 | [diff] [blame] | 1097 | N.getOperand(0).getOperand(0).hasOneUse()) { |
| 1098 | // Okay, this is a zero extending load. Fold it. |
| 1099 | LoadSDNode *LD = cast<LoadSDNode>(N.getOperand(0).getOperand(0)); |
| 1100 | if (!SelectAddr(Op, LD->getBasePtr(), Base, Scale, Index, Disp)) |
| 1101 | return false; |
| 1102 | OutChain = LD->getChain(); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1103 | InChain = SDValue(LD, 1); |
Evan Cheng | 40ee6e5 | 2008-05-08 00:57:18 +0000 | [diff] [blame] | 1104 | return true; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1105 | } |
| 1106 | return false; |
| 1107 | } |
| 1108 | |
| 1109 | |
| 1110 | /// SelectLEAAddr - it calls SelectAddr and determines if the maximal addressing |
| 1111 | /// mode it matches can be cost effectively emitted as an LEA instruction. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1112 | bool X86DAGToDAGISel::SelectLEAAddr(SDValue Op, SDValue N, |
| 1113 | SDValue &Base, SDValue &Scale, |
| 1114 | SDValue &Index, SDValue &Disp) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1115 | X86ISelAddressMode AM; |
| 1116 | if (MatchAddress(N, AM)) |
| 1117 | return false; |
| 1118 | |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1119 | MVT VT = N.getValueType(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1120 | unsigned Complexity = 0; |
| 1121 | if (AM.BaseType == X86ISelAddressMode::RegBase) |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1122 | if (AM.Base.Reg.getNode()) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1123 | Complexity = 1; |
| 1124 | else |
| 1125 | AM.Base.Reg = CurDAG->getRegister(0, VT); |
| 1126 | else if (AM.BaseType == X86ISelAddressMode::FrameIndexBase) |
| 1127 | Complexity = 4; |
| 1128 | |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1129 | if (AM.IndexReg.getNode()) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1130 | Complexity++; |
| 1131 | else |
| 1132 | AM.IndexReg = CurDAG->getRegister(0, VT); |
| 1133 | |
| 1134 | // Don't match just leal(,%reg,2). It's cheaper to do addl %reg, %reg, or with |
| 1135 | // a simple shift. |
| 1136 | if (AM.Scale > 1) |
| 1137 | Complexity++; |
| 1138 | |
| 1139 | // FIXME: We are artificially lowering the criteria to turn ADD %reg, $GA |
| 1140 | // to a LEA. This is determined with some expermentation but is by no means |
| 1141 | // optimal (especially for code size consideration). LEA is nice because of |
| 1142 | // its three-address nature. Tweak the cost function again when we can run |
| 1143 | // convertToThreeAddress() at register allocation time. |
| 1144 | if (AM.GV || AM.CP || AM.ES || AM.JT != -1) { |
| 1145 | // For X86-64, we should always use lea to materialize RIP relative |
| 1146 | // addresses. |
| 1147 | if (Subtarget->is64Bit()) |
| 1148 | Complexity = 4; |
| 1149 | else |
| 1150 | Complexity += 2; |
| 1151 | } |
| 1152 | |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1153 | if (AM.Disp && (AM.Base.Reg.getNode() || AM.IndexReg.getNode())) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1154 | Complexity++; |
| 1155 | |
| 1156 | if (Complexity > 2) { |
| 1157 | getAddressOperands(AM, Base, Scale, Index, Disp); |
| 1158 | return true; |
| 1159 | } |
| 1160 | return false; |
| 1161 | } |
| 1162 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1163 | bool X86DAGToDAGISel::TryFoldLoad(SDValue P, SDValue N, |
| 1164 | SDValue &Base, SDValue &Scale, |
| 1165 | SDValue &Index, SDValue &Disp) { |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1166 | if (ISD::isNON_EXTLoad(N.getNode()) && |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1167 | N.hasOneUse() && |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1168 | CanBeFoldedBy(N.getNode(), P.getNode(), P.getNode())) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1169 | return SelectAddr(P, N.getOperand(1), Base, Scale, Index, Disp); |
| 1170 | return false; |
| 1171 | } |
| 1172 | |
| 1173 | /// getGlobalBaseReg - Output the instructions required to put the |
| 1174 | /// base address to use for accessing globals into a register. |
| 1175 | /// |
| 1176 | SDNode *X86DAGToDAGISel::getGlobalBaseReg() { |
| 1177 | assert(!Subtarget->is64Bit() && "X86-64 PIC uses RIP relative addressing"); |
| 1178 | if (!GlobalBaseReg) { |
| 1179 | // Insert the set of GlobalBaseReg into the first MBB of the function |
Evan Cheng | 0729ccf | 2008-01-05 00:41:47 +0000 | [diff] [blame] | 1180 | MachineFunction *MF = BB->getParent(); |
| 1181 | MachineBasicBlock &FirstMBB = MF->front(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1182 | MachineBasicBlock::iterator MBBI = FirstMBB.begin(); |
Evan Cheng | 0729ccf | 2008-01-05 00:41:47 +0000 | [diff] [blame] | 1183 | MachineRegisterInfo &RegInfo = MF->getRegInfo(); |
Chris Lattner | 1b98919 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 1184 | unsigned PC = RegInfo.createVirtualRegister(X86::GR32RegisterClass); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1185 | |
| 1186 | const TargetInstrInfo *TII = TM.getInstrInfo(); |
Evan Cheng | 34f9371 | 2007-12-22 02:26:46 +0000 | [diff] [blame] | 1187 | // Operand of MovePCtoStack is completely ignored by asm printer. It's |
| 1188 | // only used in JIT code emission as displacement to pc. |
Evan Cheng | 0729ccf | 2008-01-05 00:41:47 +0000 | [diff] [blame] | 1189 | BuildMI(FirstMBB, MBBI, TII->get(X86::MOVPC32r), PC).addImm(0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1190 | |
| 1191 | // If we're using vanilla 'GOT' PIC style, we should use relative addressing |
| 1192 | // not to pc, but to _GLOBAL_ADDRESS_TABLE_ external |
| 1193 | if (TM.getRelocationModel() == Reloc::PIC_ && |
| 1194 | Subtarget->isPICStyleGOT()) { |
Chris Lattner | 1b98919 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 1195 | GlobalBaseReg = RegInfo.createVirtualRegister(X86::GR32RegisterClass); |
Evan Cheng | 0729ccf | 2008-01-05 00:41:47 +0000 | [diff] [blame] | 1196 | BuildMI(FirstMBB, MBBI, TII->get(X86::ADD32ri), GlobalBaseReg) |
| 1197 | .addReg(PC).addExternalSymbol("_GLOBAL_OFFSET_TABLE_"); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1198 | } else { |
| 1199 | GlobalBaseReg = PC; |
| 1200 | } |
| 1201 | |
| 1202 | } |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1203 | return CurDAG->getRegister(GlobalBaseReg, TLI.getPointerTy()).getNode(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1204 | } |
| 1205 | |
| 1206 | static SDNode *FindCallStartFromCall(SDNode *Node) { |
| 1207 | if (Node->getOpcode() == ISD::CALLSEQ_START) return Node; |
| 1208 | assert(Node->getOperand(0).getValueType() == MVT::Other && |
| 1209 | "Node doesn't have a token chain argument!"); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1210 | return FindCallStartFromCall(Node->getOperand(0).getNode()); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1211 | } |
| 1212 | |
Dan Gohman | dd612bb | 2008-08-20 21:27:32 +0000 | [diff] [blame] | 1213 | /// getTruncateTo8Bit - return an SDNode that implements a subreg based |
| 1214 | /// truncate of the specified operand to i8. This can be done with tablegen, |
| 1215 | /// except that this code uses MVT::Flag in a tricky way that happens to |
| 1216 | /// improve scheduling in some cases. |
| 1217 | SDNode *X86DAGToDAGISel::getTruncateTo8Bit(SDValue N0) { |
| 1218 | assert(!Subtarget->is64Bit() && |
| 1219 | "getTruncateTo8Bit is only needed on x86-32!"); |
| 1220 | SDValue SRIdx = CurDAG->getTargetConstant(1, MVT::i32); // SubRegSet 1 |
| 1221 | |
| 1222 | // Ensure that the source register has an 8-bit subreg on 32-bit targets |
| 1223 | unsigned Opc; |
| 1224 | MVT N0VT = N0.getValueType(); |
| 1225 | switch (N0VT.getSimpleVT()) { |
| 1226 | default: assert(0 && "Unknown truncate!"); |
| 1227 | case MVT::i16: |
| 1228 | Opc = X86::MOV16to16_; |
| 1229 | break; |
| 1230 | case MVT::i32: |
| 1231 | Opc = X86::MOV32to32_; |
| 1232 | break; |
| 1233 | } |
| 1234 | |
| 1235 | // The use of MVT::Flag here is not strictly accurate, but it helps |
| 1236 | // scheduling in some cases. |
| 1237 | N0 = SDValue(CurDAG->getTargetNode(Opc, N0VT, MVT::Flag, N0), 0); |
| 1238 | return CurDAG->getTargetNode(X86::EXTRACT_SUBREG, |
| 1239 | MVT::i8, N0, SRIdx, N0.getValue(1)); |
Christopher Lamb | 0a7c866 | 2007-08-10 21:48:46 +0000 | [diff] [blame] | 1240 | } |
| 1241 | |
| 1242 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1243 | SDNode *X86DAGToDAGISel::Select(SDValue N) { |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1244 | SDNode *Node = N.getNode(); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1245 | MVT NVT = Node->getValueType(0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1246 | unsigned Opc, MOpc; |
| 1247 | unsigned Opcode = Node->getOpcode(); |
| 1248 | |
| 1249 | #ifndef NDEBUG |
| 1250 | DOUT << std::string(Indent, ' ') << "Selecting: "; |
| 1251 | DEBUG(Node->dump(CurDAG)); |
| 1252 | DOUT << "\n"; |
| 1253 | Indent += 2; |
| 1254 | #endif |
| 1255 | |
Dan Gohman | bd68c79 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 1256 | if (Node->isMachineOpcode()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1257 | #ifndef NDEBUG |
| 1258 | DOUT << std::string(Indent-2, ' ') << "== "; |
| 1259 | DEBUG(Node->dump(CurDAG)); |
| 1260 | DOUT << "\n"; |
| 1261 | Indent -= 2; |
| 1262 | #endif |
| 1263 | return NULL; // Already selected. |
| 1264 | } |
| 1265 | |
| 1266 | switch (Opcode) { |
| 1267 | default: break; |
| 1268 | case X86ISD::GlobalBaseReg: |
| 1269 | return getGlobalBaseReg(); |
| 1270 | |
| 1271 | case ISD::ADD: { |
| 1272 | // Turn ADD X, c to MOV32ri X+c. This cannot be done with tblgen'd |
| 1273 | // code and is matched first so to prevent it from being turned into |
| 1274 | // LEA32r X+c. |
Evan Cheng | 17e39d6 | 2008-01-08 02:06:11 +0000 | [diff] [blame] | 1275 | // In 64-bit small code size mode, use LEA to take advantage of |
| 1276 | // RIP-relative addressing. |
| 1277 | if (TM.getCodeModel() != CodeModel::Small) |
| 1278 | break; |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1279 | MVT PtrVT = TLI.getPointerTy(); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1280 | SDValue N0 = N.getOperand(0); |
| 1281 | SDValue N1 = N.getOperand(1); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1282 | if (N.getNode()->getValueType(0) == PtrVT && |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1283 | N0.getOpcode() == X86ISD::Wrapper && |
| 1284 | N1.getOpcode() == ISD::Constant) { |
Dan Gohman | faeb4a3 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1285 | unsigned Offset = (unsigned)cast<ConstantSDNode>(N1)->getZExtValue(); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1286 | SDValue C(0, 0); |
Bill Wendling | fef0605 | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1287 | // TODO: handle ExternalSymbolSDNode. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1288 | if (GlobalAddressSDNode *G = |
| 1289 | dyn_cast<GlobalAddressSDNode>(N0.getOperand(0))) { |
| 1290 | C = CurDAG->getTargetGlobalAddress(G->getGlobal(), PtrVT, |
| 1291 | G->getOffset() + Offset); |
| 1292 | } else if (ConstantPoolSDNode *CP = |
| 1293 | dyn_cast<ConstantPoolSDNode>(N0.getOperand(0))) { |
| 1294 | C = CurDAG->getTargetConstantPool(CP->getConstVal(), PtrVT, |
| 1295 | CP->getAlignment(), |
| 1296 | CP->getOffset()+Offset); |
| 1297 | } |
| 1298 | |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1299 | if (C.getNode()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1300 | if (Subtarget->is64Bit()) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1301 | SDValue Ops[] = { CurDAG->getRegister(0, PtrVT), getI8Imm(1), |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1302 | CurDAG->getRegister(0, PtrVT), C }; |
Gabor Greif | e9f7f58 | 2008-08-31 15:37:04 +0000 | [diff] [blame] | 1303 | return CurDAG->SelectNodeTo(N.getNode(), X86::LEA64r, |
| 1304 | MVT::i64, Ops, 4); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1305 | } else |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1306 | return CurDAG->SelectNodeTo(N.getNode(), X86::MOV32ri, PtrVT, C); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1307 | } |
| 1308 | } |
| 1309 | |
| 1310 | // Other cases are handled by auto-generated code. |
| 1311 | break; |
| 1312 | } |
| 1313 | |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1314 | case ISD::SMUL_LOHI: |
| 1315 | case ISD::UMUL_LOHI: { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1316 | SDValue N0 = Node->getOperand(0); |
| 1317 | SDValue N1 = Node->getOperand(1); |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1318 | |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1319 | bool isSigned = Opcode == ISD::SMUL_LOHI; |
| 1320 | if (!isSigned) |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1321 | switch (NVT.getSimpleVT()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1322 | default: assert(0 && "Unsupported VT!"); |
| 1323 | case MVT::i8: Opc = X86::MUL8r; MOpc = X86::MUL8m; break; |
| 1324 | case MVT::i16: Opc = X86::MUL16r; MOpc = X86::MUL16m; break; |
| 1325 | case MVT::i32: Opc = X86::MUL32r; MOpc = X86::MUL32m; break; |
| 1326 | case MVT::i64: Opc = X86::MUL64r; MOpc = X86::MUL64m; break; |
| 1327 | } |
| 1328 | else |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1329 | switch (NVT.getSimpleVT()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1330 | default: assert(0 && "Unsupported VT!"); |
| 1331 | case MVT::i8: Opc = X86::IMUL8r; MOpc = X86::IMUL8m; break; |
| 1332 | case MVT::i16: Opc = X86::IMUL16r; MOpc = X86::IMUL16m; break; |
| 1333 | case MVT::i32: Opc = X86::IMUL32r; MOpc = X86::IMUL32m; break; |
| 1334 | case MVT::i64: Opc = X86::IMUL64r; MOpc = X86::IMUL64m; break; |
| 1335 | } |
| 1336 | |
| 1337 | unsigned LoReg, HiReg; |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1338 | switch (NVT.getSimpleVT()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1339 | default: assert(0 && "Unsupported VT!"); |
| 1340 | case MVT::i8: LoReg = X86::AL; HiReg = X86::AH; break; |
| 1341 | case MVT::i16: LoReg = X86::AX; HiReg = X86::DX; break; |
| 1342 | case MVT::i32: LoReg = X86::EAX; HiReg = X86::EDX; break; |
| 1343 | case MVT::i64: LoReg = X86::RAX; HiReg = X86::RDX; break; |
| 1344 | } |
| 1345 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1346 | SDValue Tmp0, Tmp1, Tmp2, Tmp3; |
Evan Cheng | 508fe8b | 2007-08-02 05:48:35 +0000 | [diff] [blame] | 1347 | bool foldedLoad = TryFoldLoad(N, N1, Tmp0, Tmp1, Tmp2, Tmp3); |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1348 | // multiplty is commmutative |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1349 | if (!foldedLoad) { |
| 1350 | foldedLoad = TryFoldLoad(N, N0, Tmp0, Tmp1, Tmp2, Tmp3); |
Evan Cheng | 508fe8b | 2007-08-02 05:48:35 +0000 | [diff] [blame] | 1351 | if (foldedLoad) |
| 1352 | std::swap(N0, N1); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1353 | } |
| 1354 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1355 | AddToISelQueue(N0); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1356 | SDValue InFlag = CurDAG->getCopyToReg(CurDAG->getEntryNode(), LoReg, |
| 1357 | N0, SDValue()).getValue(1); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1358 | |
| 1359 | if (foldedLoad) { |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1360 | AddToISelQueue(N1.getOperand(0)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1361 | AddToISelQueue(Tmp0); |
| 1362 | AddToISelQueue(Tmp1); |
| 1363 | AddToISelQueue(Tmp2); |
| 1364 | AddToISelQueue(Tmp3); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1365 | SDValue Ops[] = { Tmp0, Tmp1, Tmp2, Tmp3, N1.getOperand(0), InFlag }; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1366 | SDNode *CNode = |
| 1367 | CurDAG->getTargetNode(MOpc, MVT::Other, MVT::Flag, Ops, 6); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1368 | InFlag = SDValue(CNode, 1); |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1369 | // Update the chain. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1370 | ReplaceUses(N1.getValue(1), SDValue(CNode, 0)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1371 | } else { |
| 1372 | AddToISelQueue(N1); |
| 1373 | InFlag = |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1374 | SDValue(CurDAG->getTargetNode(Opc, MVT::Flag, N1, InFlag), 0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1375 | } |
| 1376 | |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1377 | // Copy the low half of the result, if it is needed. |
| 1378 | if (!N.getValue(0).use_empty()) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1379 | SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1380 | LoReg, NVT, InFlag); |
| 1381 | InFlag = Result.getValue(2); |
| 1382 | ReplaceUses(N.getValue(0), Result); |
| 1383 | #ifndef NDEBUG |
| 1384 | DOUT << std::string(Indent-2, ' ') << "=> "; |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1385 | DEBUG(Result.getNode()->dump(CurDAG)); |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1386 | DOUT << "\n"; |
| 1387 | #endif |
Evan Cheng | 6f0f0dd | 2007-08-09 21:59:35 +0000 | [diff] [blame] | 1388 | } |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1389 | // Copy the high half of the result, if it is needed. |
| 1390 | if (!N.getValue(1).use_empty()) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1391 | SDValue Result; |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1392 | if (HiReg == X86::AH && Subtarget->is64Bit()) { |
| 1393 | // Prevent use of AH in a REX instruction by referencing AX instead. |
| 1394 | // Shift it down 8 bits. |
| 1395 | Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), |
| 1396 | X86::AX, MVT::i16, InFlag); |
| 1397 | InFlag = Result.getValue(2); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1398 | Result = SDValue(CurDAG->getTargetNode(X86::SHR16ri, MVT::i16, Result, |
Gabor Greif | e9f7f58 | 2008-08-31 15:37:04 +0000 | [diff] [blame] | 1399 | CurDAG->getTargetConstant(8, MVT::i8)), 0); |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1400 | // Then truncate it down to i8. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1401 | SDValue SRIdx = CurDAG->getTargetConstant(1, MVT::i32); // SubRegSet 1 |
| 1402 | Result = SDValue(CurDAG->getTargetNode(X86::EXTRACT_SUBREG, |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1403 | MVT::i8, Result, SRIdx), 0); |
| 1404 | } else { |
| 1405 | Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), |
| 1406 | HiReg, NVT, InFlag); |
| 1407 | InFlag = Result.getValue(2); |
| 1408 | } |
| 1409 | ReplaceUses(N.getValue(1), Result); |
| 1410 | #ifndef NDEBUG |
| 1411 | DOUT << std::string(Indent-2, ' ') << "=> "; |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1412 | DEBUG(Result.getNode()->dump(CurDAG)); |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1413 | DOUT << "\n"; |
| 1414 | #endif |
| 1415 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1416 | |
| 1417 | #ifndef NDEBUG |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1418 | Indent -= 2; |
| 1419 | #endif |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1420 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1421 | return NULL; |
| 1422 | } |
| 1423 | |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1424 | case ISD::SDIVREM: |
| 1425 | case ISD::UDIVREM: { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1426 | SDValue N0 = Node->getOperand(0); |
| 1427 | SDValue N1 = Node->getOperand(1); |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1428 | |
| 1429 | bool isSigned = Opcode == ISD::SDIVREM; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1430 | if (!isSigned) |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1431 | switch (NVT.getSimpleVT()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1432 | default: assert(0 && "Unsupported VT!"); |
| 1433 | case MVT::i8: Opc = X86::DIV8r; MOpc = X86::DIV8m; break; |
| 1434 | case MVT::i16: Opc = X86::DIV16r; MOpc = X86::DIV16m; break; |
| 1435 | case MVT::i32: Opc = X86::DIV32r; MOpc = X86::DIV32m; break; |
| 1436 | case MVT::i64: Opc = X86::DIV64r; MOpc = X86::DIV64m; break; |
| 1437 | } |
| 1438 | else |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1439 | switch (NVT.getSimpleVT()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1440 | default: assert(0 && "Unsupported VT!"); |
| 1441 | case MVT::i8: Opc = X86::IDIV8r; MOpc = X86::IDIV8m; break; |
| 1442 | case MVT::i16: Opc = X86::IDIV16r; MOpc = X86::IDIV16m; break; |
| 1443 | case MVT::i32: Opc = X86::IDIV32r; MOpc = X86::IDIV32m; break; |
| 1444 | case MVT::i64: Opc = X86::IDIV64r; MOpc = X86::IDIV64m; break; |
| 1445 | } |
| 1446 | |
| 1447 | unsigned LoReg, HiReg; |
| 1448 | unsigned ClrOpcode, SExtOpcode; |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1449 | switch (NVT.getSimpleVT()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1450 | default: assert(0 && "Unsupported VT!"); |
| 1451 | case MVT::i8: |
| 1452 | LoReg = X86::AL; HiReg = X86::AH; |
| 1453 | ClrOpcode = 0; |
| 1454 | SExtOpcode = X86::CBW; |
| 1455 | break; |
| 1456 | case MVT::i16: |
| 1457 | LoReg = X86::AX; HiReg = X86::DX; |
| 1458 | ClrOpcode = X86::MOV16r0; |
| 1459 | SExtOpcode = X86::CWD; |
| 1460 | break; |
| 1461 | case MVT::i32: |
| 1462 | LoReg = X86::EAX; HiReg = X86::EDX; |
| 1463 | ClrOpcode = X86::MOV32r0; |
| 1464 | SExtOpcode = X86::CDQ; |
| 1465 | break; |
| 1466 | case MVT::i64: |
| 1467 | LoReg = X86::RAX; HiReg = X86::RDX; |
| 1468 | ClrOpcode = X86::MOV64r0; |
| 1469 | SExtOpcode = X86::CQO; |
| 1470 | break; |
| 1471 | } |
| 1472 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1473 | SDValue Tmp0, Tmp1, Tmp2, Tmp3; |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1474 | bool foldedLoad = TryFoldLoad(N, N1, Tmp0, Tmp1, Tmp2, Tmp3); |
| 1475 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1476 | SDValue InFlag; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1477 | if (NVT == MVT::i8 && !isSigned) { |
| 1478 | // Special case for div8, just use a move with zero extension to AX to |
| 1479 | // clear the upper 8 bits (AH). |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1480 | SDValue Tmp0, Tmp1, Tmp2, Tmp3, Move, Chain; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1481 | if (TryFoldLoad(N, N0, Tmp0, Tmp1, Tmp2, Tmp3)) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1482 | SDValue Ops[] = { Tmp0, Tmp1, Tmp2, Tmp3, N0.getOperand(0) }; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1483 | AddToISelQueue(N0.getOperand(0)); |
| 1484 | AddToISelQueue(Tmp0); |
| 1485 | AddToISelQueue(Tmp1); |
| 1486 | AddToISelQueue(Tmp2); |
| 1487 | AddToISelQueue(Tmp3); |
| 1488 | Move = |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1489 | SDValue(CurDAG->getTargetNode(X86::MOVZX16rm8, MVT::i16, MVT::Other, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1490 | Ops, 5), 0); |
| 1491 | Chain = Move.getValue(1); |
| 1492 | ReplaceUses(N0.getValue(1), Chain); |
| 1493 | } else { |
| 1494 | AddToISelQueue(N0); |
| 1495 | Move = |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1496 | SDValue(CurDAG->getTargetNode(X86::MOVZX16rr8, MVT::i16, N0), 0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1497 | Chain = CurDAG->getEntryNode(); |
| 1498 | } |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1499 | Chain = CurDAG->getCopyToReg(Chain, X86::AX, Move, SDValue()); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1500 | InFlag = Chain.getValue(1); |
| 1501 | } else { |
| 1502 | AddToISelQueue(N0); |
| 1503 | InFlag = |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1504 | CurDAG->getCopyToReg(CurDAG->getEntryNode(), |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1505 | LoReg, N0, SDValue()).getValue(1); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1506 | if (isSigned) { |
| 1507 | // Sign extend the low part into the high part. |
| 1508 | InFlag = |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1509 | SDValue(CurDAG->getTargetNode(SExtOpcode, MVT::Flag, InFlag), 0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1510 | } else { |
| 1511 | // Zero out the high part, effectively zero extending the input. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1512 | SDValue ClrNode = SDValue(CurDAG->getTargetNode(ClrOpcode, NVT), 0); |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1513 | InFlag = CurDAG->getCopyToReg(CurDAG->getEntryNode(), HiReg, |
| 1514 | ClrNode, InFlag).getValue(1); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1515 | } |
| 1516 | } |
| 1517 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1518 | if (foldedLoad) { |
| 1519 | AddToISelQueue(N1.getOperand(0)); |
| 1520 | AddToISelQueue(Tmp0); |
| 1521 | AddToISelQueue(Tmp1); |
| 1522 | AddToISelQueue(Tmp2); |
| 1523 | AddToISelQueue(Tmp3); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1524 | SDValue Ops[] = { Tmp0, Tmp1, Tmp2, Tmp3, N1.getOperand(0), InFlag }; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1525 | SDNode *CNode = |
| 1526 | CurDAG->getTargetNode(MOpc, MVT::Other, MVT::Flag, Ops, 6); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1527 | InFlag = SDValue(CNode, 1); |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1528 | // Update the chain. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1529 | ReplaceUses(N1.getValue(1), SDValue(CNode, 0)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1530 | } else { |
| 1531 | AddToISelQueue(N1); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1532 | InFlag = |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1533 | SDValue(CurDAG->getTargetNode(Opc, MVT::Flag, N1, InFlag), 0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1534 | } |
| 1535 | |
Dan Gohman | 242a5ba | 2007-09-25 18:23:27 +0000 | [diff] [blame] | 1536 | // Copy the division (low) result, if it is needed. |
| 1537 | if (!N.getValue(0).use_empty()) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1538 | SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1539 | LoReg, NVT, InFlag); |
Dan Gohman | 242a5ba | 2007-09-25 18:23:27 +0000 | [diff] [blame] | 1540 | InFlag = Result.getValue(2); |
| 1541 | ReplaceUses(N.getValue(0), Result); |
| 1542 | #ifndef NDEBUG |
| 1543 | DOUT << std::string(Indent-2, ' ') << "=> "; |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1544 | DEBUG(Result.getNode()->dump(CurDAG)); |
Dan Gohman | 242a5ba | 2007-09-25 18:23:27 +0000 | [diff] [blame] | 1545 | DOUT << "\n"; |
| 1546 | #endif |
Evan Cheng | 6f0f0dd | 2007-08-09 21:59:35 +0000 | [diff] [blame] | 1547 | } |
Dan Gohman | 242a5ba | 2007-09-25 18:23:27 +0000 | [diff] [blame] | 1548 | // Copy the remainder (high) result, if it is needed. |
| 1549 | if (!N.getValue(1).use_empty()) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1550 | SDValue Result; |
Dan Gohman | 242a5ba | 2007-09-25 18:23:27 +0000 | [diff] [blame] | 1551 | if (HiReg == X86::AH && Subtarget->is64Bit()) { |
| 1552 | // Prevent use of AH in a REX instruction by referencing AX instead. |
| 1553 | // Shift it down 8 bits. |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1554 | Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), |
| 1555 | X86::AX, MVT::i16, InFlag); |
Dan Gohman | 242a5ba | 2007-09-25 18:23:27 +0000 | [diff] [blame] | 1556 | InFlag = Result.getValue(2); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1557 | Result = SDValue(CurDAG->getTargetNode(X86::SHR16ri, MVT::i16, Result, |
Gabor Greif | e9f7f58 | 2008-08-31 15:37:04 +0000 | [diff] [blame] | 1558 | CurDAG->getTargetConstant(8, MVT::i8)), 0); |
Dan Gohman | 242a5ba | 2007-09-25 18:23:27 +0000 | [diff] [blame] | 1559 | // Then truncate it down to i8. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1560 | SDValue SRIdx = CurDAG->getTargetConstant(1, MVT::i32); // SubRegSet 1 |
| 1561 | Result = SDValue(CurDAG->getTargetNode(X86::EXTRACT_SUBREG, |
Dan Gohman | 242a5ba | 2007-09-25 18:23:27 +0000 | [diff] [blame] | 1562 | MVT::i8, Result, SRIdx), 0); |
| 1563 | } else { |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1564 | Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), |
| 1565 | HiReg, NVT, InFlag); |
Dan Gohman | 242a5ba | 2007-09-25 18:23:27 +0000 | [diff] [blame] | 1566 | InFlag = Result.getValue(2); |
| 1567 | } |
| 1568 | ReplaceUses(N.getValue(1), Result); |
| 1569 | #ifndef NDEBUG |
| 1570 | DOUT << std::string(Indent-2, ' ') << "=> "; |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1571 | DEBUG(Result.getNode()->dump(CurDAG)); |
Dan Gohman | 242a5ba | 2007-09-25 18:23:27 +0000 | [diff] [blame] | 1572 | DOUT << "\n"; |
| 1573 | #endif |
| 1574 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1575 | |
| 1576 | #ifndef NDEBUG |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1577 | Indent -= 2; |
| 1578 | #endif |
| 1579 | |
| 1580 | return NULL; |
| 1581 | } |
Christopher Lamb | 422213d | 2007-08-10 22:22:41 +0000 | [diff] [blame] | 1582 | |
Christopher Lamb | 0a7c866 | 2007-08-10 21:48:46 +0000 | [diff] [blame] | 1583 | case ISD::SIGN_EXTEND_INREG: { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1584 | MVT SVT = cast<VTSDNode>(Node->getOperand(1))->getVT(); |
Dan Gohman | dd612bb | 2008-08-20 21:27:32 +0000 | [diff] [blame] | 1585 | if (SVT == MVT::i8 && !Subtarget->is64Bit()) { |
| 1586 | SDValue N0 = Node->getOperand(0); |
| 1587 | AddToISelQueue(N0); |
Christopher Lamb | 0a7c866 | 2007-08-10 21:48:46 +0000 | [diff] [blame] | 1588 | |
Dan Gohman | dd612bb | 2008-08-20 21:27:32 +0000 | [diff] [blame] | 1589 | SDValue TruncOp = SDValue(getTruncateTo8Bit(N0), 0); |
| 1590 | unsigned Opc = 0; |
| 1591 | switch (NVT.getSimpleVT()) { |
| 1592 | default: assert(0 && "Unknown sign_extend_inreg!"); |
| 1593 | case MVT::i16: |
| 1594 | Opc = X86::MOVSX16rr8; |
| 1595 | break; |
| 1596 | case MVT::i32: |
| 1597 | Opc = X86::MOVSX32rr8; |
| 1598 | break; |
| 1599 | } |
| 1600 | |
| 1601 | SDNode *ResNode = CurDAG->getTargetNode(Opc, NVT, TruncOp); |
Christopher Lamb | 0a7c866 | 2007-08-10 21:48:46 +0000 | [diff] [blame] | 1602 | |
| 1603 | #ifndef NDEBUG |
Dan Gohman | dd612bb | 2008-08-20 21:27:32 +0000 | [diff] [blame] | 1604 | DOUT << std::string(Indent-2, ' ') << "=> "; |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1605 | DEBUG(TruncOp.getNode()->dump(CurDAG)); |
Dan Gohman | dd612bb | 2008-08-20 21:27:32 +0000 | [diff] [blame] | 1606 | DOUT << "\n"; |
| 1607 | DOUT << std::string(Indent-2, ' ') << "=> "; |
| 1608 | DEBUG(ResNode->dump(CurDAG)); |
| 1609 | DOUT << "\n"; |
| 1610 | Indent -= 2; |
Christopher Lamb | 0a7c866 | 2007-08-10 21:48:46 +0000 | [diff] [blame] | 1611 | #endif |
Dan Gohman | dd612bb | 2008-08-20 21:27:32 +0000 | [diff] [blame] | 1612 | return ResNode; |
| 1613 | } |
Christopher Lamb | 0a7c866 | 2007-08-10 21:48:46 +0000 | [diff] [blame] | 1614 | break; |
| 1615 | } |
| 1616 | |
| 1617 | case ISD::TRUNCATE: { |
Dan Gohman | dd612bb | 2008-08-20 21:27:32 +0000 | [diff] [blame] | 1618 | if (NVT == MVT::i8 && !Subtarget->is64Bit()) { |
| 1619 | SDValue Input = Node->getOperand(0); |
| 1620 | AddToISelQueue(Node->getOperand(0)); |
| 1621 | SDNode *ResNode = getTruncateTo8Bit(Input); |
Christopher Lamb | 0a7c866 | 2007-08-10 21:48:46 +0000 | [diff] [blame] | 1622 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1623 | #ifndef NDEBUG |
| 1624 | DOUT << std::string(Indent-2, ' ') << "=> "; |
| 1625 | DEBUG(ResNode->dump(CurDAG)); |
| 1626 | DOUT << "\n"; |
| 1627 | Indent -= 2; |
| 1628 | #endif |
Dan Gohman | dd612bb | 2008-08-20 21:27:32 +0000 | [diff] [blame] | 1629 | return ResNode; |
| 1630 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1631 | break; |
| 1632 | } |
Evan Cheng | d4cebcd | 2008-06-17 02:01:22 +0000 | [diff] [blame] | 1633 | |
| 1634 | case ISD::DECLARE: { |
| 1635 | // Handle DECLARE nodes here because the second operand may have been |
| 1636 | // wrapped in X86ISD::Wrapper. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1637 | SDValue Chain = Node->getOperand(0); |
| 1638 | SDValue N1 = Node->getOperand(1); |
| 1639 | SDValue N2 = Node->getOperand(2); |
Evan Cheng | 651e144 | 2008-06-18 02:48:27 +0000 | [diff] [blame] | 1640 | if (!isa<FrameIndexSDNode>(N1)) |
| 1641 | break; |
| 1642 | int FI = cast<FrameIndexSDNode>(N1)->getIndex(); |
| 1643 | if (N2.getOpcode() == ISD::ADD && |
| 1644 | N2.getOperand(0).getOpcode() == X86ISD::GlobalBaseReg) |
| 1645 | N2 = N2.getOperand(1); |
| 1646 | if (N2.getOpcode() == X86ISD::Wrapper && |
Evan Cheng | d4cebcd | 2008-06-17 02:01:22 +0000 | [diff] [blame] | 1647 | isa<GlobalAddressSDNode>(N2.getOperand(0))) { |
Evan Cheng | d4cebcd | 2008-06-17 02:01:22 +0000 | [diff] [blame] | 1648 | GlobalValue *GV = |
| 1649 | cast<GlobalAddressSDNode>(N2.getOperand(0))->getGlobal(); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1650 | SDValue Tmp1 = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy()); |
| 1651 | SDValue Tmp2 = CurDAG->getTargetGlobalAddress(GV, TLI.getPointerTy()); |
Evan Cheng | d4cebcd | 2008-06-17 02:01:22 +0000 | [diff] [blame] | 1652 | AddToISelQueue(Chain); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1653 | SDValue Ops[] = { Tmp1, Tmp2, Chain }; |
Evan Cheng | d4cebcd | 2008-06-17 02:01:22 +0000 | [diff] [blame] | 1654 | return CurDAG->getTargetNode(TargetInstrInfo::DECLARE, |
| 1655 | MVT::Other, Ops, 3); |
| 1656 | } |
| 1657 | break; |
| 1658 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1659 | } |
| 1660 | |
| 1661 | SDNode *ResNode = SelectCode(N); |
| 1662 | |
| 1663 | #ifndef NDEBUG |
| 1664 | DOUT << std::string(Indent-2, ' ') << "=> "; |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1665 | if (ResNode == NULL || ResNode == N.getNode()) |
| 1666 | DEBUG(N.getNode()->dump(CurDAG)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1667 | else |
| 1668 | DEBUG(ResNode->dump(CurDAG)); |
| 1669 | DOUT << "\n"; |
| 1670 | Indent -= 2; |
| 1671 | #endif |
| 1672 | |
| 1673 | return ResNode; |
| 1674 | } |
| 1675 | |
| 1676 | bool X86DAGToDAGISel:: |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1677 | SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode, |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 1678 | std::vector<SDValue> &OutOps) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1679 | SDValue Op0, Op1, Op2, Op3; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1680 | switch (ConstraintCode) { |
| 1681 | case 'o': // offsetable ?? |
| 1682 | case 'v': // not offsetable ?? |
| 1683 | default: return true; |
| 1684 | case 'm': // memory |
| 1685 | if (!SelectAddr(Op, Op, Op0, Op1, Op2, Op3)) |
| 1686 | return true; |
| 1687 | break; |
| 1688 | } |
| 1689 | |
| 1690 | OutOps.push_back(Op0); |
| 1691 | OutOps.push_back(Op1); |
| 1692 | OutOps.push_back(Op2); |
| 1693 | OutOps.push_back(Op3); |
| 1694 | AddToISelQueue(Op0); |
| 1695 | AddToISelQueue(Op1); |
| 1696 | AddToISelQueue(Op2); |
| 1697 | AddToISelQueue(Op3); |
| 1698 | return false; |
| 1699 | } |
| 1700 | |
| 1701 | /// createX86ISelDag - This pass converts a legalized DAG into a |
| 1702 | /// X86-specific DAG, ready for instruction scheduling. |
| 1703 | /// |
| 1704 | FunctionPass *llvm::createX86ISelDag(X86TargetMachine &TM, bool Fast) { |
| 1705 | return new X86DAGToDAGISel(TM, Fast); |
| 1706 | } |