LLVM API Documentation
00001 //===- X86ISelDAGToDAG.cpp - A DAG pattern matching inst selector for X86 -===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines a DAG pattern matching instruction selector for X86, 00011 // converting from a legalized dag to a X86 dag. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #define DEBUG_TYPE "x86-isel" 00016 #include "X86.h" 00017 #include "X86InstrBuilder.h" 00018 #include "X86ISelLowering.h" 00019 #include "X86MachineFunctionInfo.h" 00020 #include "X86RegisterInfo.h" 00021 #include "X86Subtarget.h" 00022 #include "X86TargetMachine.h" 00023 #include "llvm/GlobalValue.h" 00024 #include "llvm/Instructions.h" 00025 #include "llvm/Intrinsics.h" 00026 #include "llvm/Support/CFG.h" 00027 #include "llvm/Type.h" 00028 #include "llvm/CodeGen/MachineConstantPool.h" 00029 #include "llvm/CodeGen/MachineFunction.h" 00030 #include "llvm/CodeGen/MachineFrameInfo.h" 00031 #include "llvm/CodeGen/MachineInstrBuilder.h" 00032 #include "llvm/CodeGen/MachineRegisterInfo.h" 00033 #include "llvm/CodeGen/SelectionDAGISel.h" 00034 #include "llvm/Target/TargetMachine.h" 00035 #include "llvm/Target/TargetOptions.h" 00036 #include "llvm/Support/Compiler.h" 00037 #include "llvm/Support/Debug.h" 00038 #include "llvm/Support/ErrorHandling.h" 00039 #include "llvm/Support/MathExtras.h" 00040 #include "llvm/Support/Streams.h" 00041 #include "llvm/Support/raw_ostream.h" 00042 #include "llvm/ADT/SmallPtrSet.h" 00043 #include "llvm/ADT/Statistic.h" 00044 using namespace llvm; 00045 00046 #include "llvm/Support/CommandLine.h" 00047 static cl::opt<bool> AvoidDupAddrCompute("x86-avoid-dup-address", cl::Hidden); 00048 00049 STATISTIC(NumLoadMoved, "Number of loads moved below TokenFactor"); 00050 00051 //===----------------------------------------------------------------------===// 00052 // Pattern Matcher Implementation 00053 //===----------------------------------------------------------------------===// 00054 00055 namespace { 00056 /// X86ISelAddressMode - This corresponds to X86AddressMode, but uses 00057 /// SDValue's instead of register numbers for the leaves of the matched 00058 /// tree. 00059 struct X86ISelAddressMode { 00060 enum { 00061 RegBase, 00062 FrameIndexBase 00063 } BaseType; 00064 00065 struct { // This is really a union, discriminated by BaseType! 00066 SDValue Reg; 00067 int FrameIndex; 00068 } Base; 00069 00070 unsigned Scale; 00071 SDValue IndexReg; 00072 int32_t Disp; 00073 SDValue Segment; 00074 GlobalValue *GV; 00075 Constant *CP; 00076 const char *ES; 00077 int JT; 00078 unsigned Align; // CP alignment. 00079 unsigned char SymbolFlags; // X86II::MO_* 00080 00081 X86ISelAddressMode() 00082 : BaseType(RegBase), Scale(1), IndexReg(), Disp(0), 00083 Segment(), GV(0), CP(0), ES(0), JT(-1), Align(0), SymbolFlags(0) { 00084 } 00085 00086 bool hasSymbolicDisplacement() const { 00087 return GV != 0 || CP != 0 || ES != 0 || JT != -1; 00088 } 00089 00090 bool hasBaseOrIndexReg() const { 00091 return IndexReg.getNode() != 0 || Base.Reg.getNode() != 0; 00092 } 00093 00094 /// isRIPRelative - Return true if this addressing mode is already RIP 00095 /// relative. 00096 bool isRIPRelative() const { 00097 if (BaseType != RegBase) return false; 00098 if (RegisterSDNode *RegNode = 00099 dyn_cast_or_null<RegisterSDNode>(Base.Reg.getNode())) 00100 return RegNode->getReg() == X86::RIP; 00101 return false; 00102 } 00103 00104 void setBaseReg(SDValue Reg) { 00105 BaseType = RegBase; 00106 Base.Reg = Reg; 00107 } 00108 00109 void dump() { 00110 cerr << "X86ISelAddressMode " << this << '\n'; 00111 cerr << "Base.Reg "; 00112 if (Base.Reg.getNode() != 0) 00113 Base.Reg.getNode()->dump(); 00114 else 00115 cerr << "nul"; 00116 cerr << " Base.FrameIndex " << Base.FrameIndex << '\n'; 00117 cerr << " Scale" << Scale << '\n'; 00118 cerr << "IndexReg "; 00119 if (IndexReg.getNode() != 0) 00120 IndexReg.getNode()->dump(); 00121 else 00122 cerr << "nul"; 00123 cerr << " Disp " << Disp << '\n'; 00124 cerr << "GV "; 00125 if (GV) 00126 GV->dump(); 00127 else 00128 cerr << "nul"; 00129 cerr << " CP "; 00130 if (CP) 00131 CP->dump(); 00132 else 00133 cerr << "nul"; 00134 cerr << '\n'; 00135 cerr << "ES "; 00136 if (ES) 00137 cerr << ES; 00138 else 00139 cerr << "nul"; 00140 cerr << " JT" << JT << " Align" << Align << '\n'; 00141 } 00142 }; 00143 } 00144 00145 namespace { 00146 //===--------------------------------------------------------------------===// 00147 /// ISel - X86 specific code to select X86 machine instructions for 00148 /// SelectionDAG operations. 00149 /// 00150 class VISIBILITY_HIDDEN X86DAGToDAGISel : public SelectionDAGISel { 00151 /// X86Lowering - This object fully describes how to lower LLVM code to an 00152 /// X86-specific SelectionDAG. 00153 X86TargetLowering &X86Lowering; 00154 00155 /// Subtarget - Keep a pointer to the X86Subtarget around so that we can 00156 /// make the right decision when generating code for different targets. 00157 const X86Subtarget *Subtarget; 00158 00159 /// OptForSize - If true, selector should try to optimize for code size 00160 /// instead of performance. 00161 bool OptForSize; 00162 00163 public: 00164 explicit X86DAGToDAGISel(X86TargetMachine &tm, CodeGenOpt::Level OptLevel) 00165 : SelectionDAGISel(tm, OptLevel), 00166 X86Lowering(*tm.getTargetLowering()), 00167 Subtarget(&tm.getSubtarget<X86Subtarget>()), 00168 OptForSize(false) {} 00169 00170 virtual const char *getPassName() const { 00171 return "X86 DAG->DAG Instruction Selection"; 00172 } 00173 00174 /// InstructionSelect - This callback is invoked by 00175 /// SelectionDAGISel when it has created a SelectionDAG for us to codegen. 00176 virtual void InstructionSelect(); 00177 00178 virtual void EmitFunctionEntryCode(Function &Fn, MachineFunction &MF); 00179 00180 virtual 00181 bool IsLegalAndProfitableToFold(SDNode *N, SDNode *U, SDNode *Root) const; 00182 00183 // Include the pieces autogenerated from the target description. 00184 #include "X86GenDAGISel.inc" 00185 00186 private: 00187 SDNode *Select(SDValue N); 00188 SDNode *SelectAtomic64(SDNode *Node, unsigned Opc); 00189 SDNode *SelectAtomicLoadAdd(SDNode *Node, EVT NVT); 00190 00191 bool MatchSegmentBaseAddress(SDValue N, X86ISelAddressMode &AM); 00192 bool MatchLoad(SDValue N, X86ISelAddressMode &AM); 00193 bool MatchWrapper(SDValue N, X86ISelAddressMode &AM); 00194 bool MatchAddress(SDValue N, X86ISelAddressMode &AM); 00195 bool MatchAddressRecursively(SDValue N, X86ISelAddressMode &AM, 00196 unsigned Depth); 00197 bool MatchAddressBase(SDValue N, X86ISelAddressMode &AM); 00198 bool SelectAddr(SDValue Op, SDValue N, SDValue &Base, 00199 SDValue &Scale, SDValue &Index, SDValue &Disp, 00200 SDValue &Segment); 00201 bool SelectLEAAddr(SDValue Op, SDValue N, SDValue &Base, 00202 SDValue &Scale, SDValue &Index, SDValue &Disp); 00203 bool SelectTLSADDRAddr(SDValue Op, SDValue N, SDValue &Base, 00204 SDValue &Scale, SDValue &Index, SDValue &Disp); 00205 bool SelectScalarSSELoad(SDValue Op, SDValue Pred, 00206 SDValue N, SDValue &Base, SDValue &Scale, 00207 SDValue &Index, SDValue &Disp, 00208 SDValue &Segment, 00209 SDValue &InChain, SDValue &OutChain); 00210 bool TryFoldLoad(SDValue P, SDValue N, 00211 SDValue &Base, SDValue &Scale, 00212 SDValue &Index, SDValue &Disp, 00213 SDValue &Segment); 00214 void PreprocessForRMW(); 00215 void PreprocessForFPConvert(); 00216 00217 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for 00218 /// inline asm expressions. 00219 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op, 00220 char ConstraintCode, 00221 std::vector<SDValue> &OutOps); 00222 00223 void EmitSpecialCodeForMain(MachineBasicBlock *BB, MachineFrameInfo *MFI); 00224 00225 inline void getAddressOperands(X86ISelAddressMode &AM, SDValue &Base, 00226 SDValue &Scale, SDValue &Index, 00227 SDValue &Disp, SDValue &Segment) { 00228 Base = (AM.BaseType == X86ISelAddressMode::FrameIndexBase) ? 00229 CurDAG->getTargetFrameIndex(AM.Base.FrameIndex, TLI.getPointerTy()) : 00230 AM.Base.Reg; 00231 Scale = getI8Imm(AM.Scale); 00232 Index = AM.IndexReg; 00233 // These are 32-bit even in 64-bit mode since RIP relative offset 00234 // is 32-bit. 00235 if (AM.GV) 00236 Disp = CurDAG->getTargetGlobalAddress(AM.GV, MVT::i32, AM.Disp, 00237 AM.SymbolFlags); 00238 else if (AM.CP) 00239 Disp = CurDAG->getTargetConstantPool(AM.CP, MVT::i32, 00240 AM.Align, AM.Disp, AM.SymbolFlags); 00241 else if (AM.ES) 00242 Disp = CurDAG->getTargetExternalSymbol(AM.ES, MVT::i32, AM.SymbolFlags); 00243 else if (AM.JT != -1) 00244 Disp = CurDAG->getTargetJumpTable(AM.JT, MVT::i32, AM.SymbolFlags); 00245 else 00246 Disp = CurDAG->getTargetConstant(AM.Disp, MVT::i32); 00247 00248 if (AM.Segment.getNode()) 00249 Segment = AM.Segment; 00250 else 00251 Segment = CurDAG->getRegister(0, MVT::i32); 00252 } 00253 00254 /// getI8Imm - Return a target constant with the specified value, of type 00255 /// i8. 00256 inline SDValue getI8Imm(unsigned Imm) { 00257 return CurDAG->getTargetConstant(Imm, MVT::i8); 00258 } 00259 00260 /// getI16Imm - Return a target constant with the specified value, of type 00261 /// i16. 00262 inline SDValue getI16Imm(unsigned Imm) { 00263 return CurDAG->getTargetConstant(Imm, MVT::i16); 00264 } 00265 00266 /// getI32Imm - Return a target constant with the specified value, of type 00267 /// i32. 00268 inline SDValue getI32Imm(unsigned Imm) { 00269 return CurDAG->getTargetConstant(Imm, MVT::i32); 00270 } 00271 00272 /// getGlobalBaseReg - Return an SDNode that returns the value of 00273 /// the global base register. Output instructions required to 00274 /// initialize the global base register, if necessary. 00275 /// 00276 SDNode *getGlobalBaseReg(); 00277 00278 /// getTargetMachine - Return a reference to the TargetMachine, casted 00279 /// to the target-specific type. 00280 const X86TargetMachine &getTargetMachine() { 00281 return static_cast<const X86TargetMachine &>(TM); 00282 } 00283 00284 /// getInstrInfo - Return a reference to the TargetInstrInfo, casted 00285 /// to the target-specific type. 00286 const X86InstrInfo *getInstrInfo() { 00287 return getTargetMachine().getInstrInfo(); 00288 } 00289 00290 #ifndef NDEBUG 00291 unsigned Indent; 00292 #endif 00293 }; 00294 } 00295 00296 00297 bool X86DAGToDAGISel::IsLegalAndProfitableToFold(SDNode *N, SDNode *U, 00298 SDNode *Root) const { 00299 if (OptLevel == CodeGenOpt::None) return false; 00300 00301 if (U == Root) 00302 switch (U->getOpcode()) { 00303 default: break; 00304 case ISD::ADD: 00305 case ISD::ADDC: 00306 case ISD::ADDE: 00307 case ISD::AND: 00308 case ISD::OR: 00309 case ISD::XOR: { 00310 SDValue Op1 = U->getOperand(1); 00311 00312 // If the other operand is a 8-bit immediate we should fold the immediate 00313 // instead. This reduces code size. 00314 // e.g. 00315 // movl 4(%esp), %eax 00316 // addl $4, %eax 00317 // vs. 00318 // movl $4, %eax 00319 // addl 4(%esp), %eax 00320 // The former is 2 bytes shorter. In case where the increment is 1, then 00321 // the saving can be 4 bytes (by using incl %eax). 00322 if (ConstantSDNode *Imm = dyn_cast<ConstantSDNode>(Op1)) 00323 if (Imm->getAPIntValue().isSignedIntN(8)) 00324 return false; 00325 00326 // If the other operand is a TLS address, we should fold it instead. 00327 // This produces 00328 // movl %gs:0, %eax 00329 // leal i@NTPOFF(%eax), %eax 00330 // instead of 00331 // movl $i@NTPOFF, %eax 00332 // addl %gs:0, %eax 00333 // if the block also has an access to a second TLS address this will save 00334 // a load. 00335 // FIXME: This is probably also true for non TLS addresses. 00336 if (Op1.getOpcode() == X86ISD::Wrapper) { 00337 SDValue Val = Op1.getOperand(0); 00338 if (Val.getOpcode() == ISD::TargetGlobalTLSAddress) 00339 return false; 00340 } 00341 } 00342 } 00343 00344 // Proceed to 'generic' cycle finder code 00345 return SelectionDAGISel::IsLegalAndProfitableToFold(N, U, Root); 00346 } 00347 00348 /// MoveBelowTokenFactor - Replace TokenFactor operand with load's chain operand 00349 /// and move load below the TokenFactor. Replace store's chain operand with 00350 /// load's chain result. 00351 static void MoveBelowTokenFactor(SelectionDAG *CurDAG, SDValue Load, 00352 SDValue Store, SDValue TF) { 00353 SmallVector<SDValue, 4> Ops; 00354 for (unsigned i = 0, e = TF.getNode()->getNumOperands(); i != e; ++i) 00355 if (Load.getNode() == TF.getOperand(i).getNode()) 00356 Ops.push_back(Load.getOperand(0)); 00357 else 00358 Ops.push_back(TF.getOperand(i)); 00359 SDValue NewTF = CurDAG->UpdateNodeOperands(TF, &Ops[0], Ops.size()); 00360 SDValue NewLoad = CurDAG->UpdateNodeOperands(Load, NewTF, 00361 Load.getOperand(1), 00362 Load.getOperand(2)); 00363 CurDAG->UpdateNodeOperands(Store, NewLoad.getValue(1), Store.getOperand(1), 00364 Store.getOperand(2), Store.getOperand(3)); 00365 } 00366 00367 /// isRMWLoad - Return true if N is a load that's part of RMW sub-DAG. 00368 /// 00369 static bool isRMWLoad(SDValue N, SDValue Chain, SDValue Address, 00370 SDValue &Load) { 00371 if (N.getOpcode() == ISD::BIT_CONVERT) 00372 N = N.getOperand(0); 00373 00374 LoadSDNode *LD = dyn_cast<LoadSDNode>(N); 00375 if (!LD || LD->isVolatile()) 00376 return false; 00377 if (LD->getAddressingMode() != ISD::UNINDEXED) 00378 return false; 00379 00380 ISD::LoadExtType ExtType = LD->getExtensionType(); 00381 if (ExtType != ISD::NON_EXTLOAD && ExtType != ISD::EXTLOAD) 00382 return false; 00383 00384 if (N.hasOneUse() && 00385 N.getOperand(1) == Address && 00386 N.getNode()->isOperandOf(Chain.getNode())) { 00387 Load = N; 00388 return true; 00389 } 00390 return false; 00391 } 00392 00393 /// MoveBelowCallSeqStart - Replace CALLSEQ_START operand with load's chain 00394 /// operand and move load below the call's chain operand. 00395 static void MoveBelowCallSeqStart(SelectionDAG *CurDAG, SDValue Load, 00396 SDValue Call, SDValue CallSeqStart) { 00397 SmallVector<SDValue, 8> Ops; 00398 SDValue Chain = CallSeqStart.getOperand(0); 00399 if (Chain.getNode() == Load.getNode()) 00400 Ops.push_back(Load.getOperand(0)); 00401 else { 00402 assert(Chain.getOpcode() == ISD::TokenFactor && 00403 "Unexpected CallSeqStart chain operand"); 00404 for (unsigned i = 0, e = Chain.getNumOperands(); i != e; ++i) 00405 if (Chain.getOperand(i).getNode() == Load.getNode()) 00406 Ops.push_back(Load.getOperand(0)); 00407 else 00408 Ops.push_back(Chain.getOperand(i)); 00409 SDValue NewChain = 00410 CurDAG->getNode(ISD::TokenFactor, Load.getDebugLoc(), 00411 MVT::Other, &Ops[0], Ops.size()); 00412 Ops.clear(); 00413 Ops.push_back(NewChain); 00414 } 00415 for (unsigned i = 1, e = CallSeqStart.getNumOperands(); i != e; ++i) 00416 Ops.push_back(CallSeqStart.getOperand(i)); 00417 CurDAG->UpdateNodeOperands(CallSeqStart, &Ops[0], Ops.size()); 00418 CurDAG->UpdateNodeOperands(Load, Call.getOperand(0), 00419 Load.getOperand(1), Load.getOperand(2)); 00420 Ops.clear(); 00421 Ops.push_back(SDValue(Load.getNode(), 1)); 00422 for (unsigned i = 1, e = Call.getNode()->getNumOperands(); i != e; ++i) 00423 Ops.push_back(Call.getOperand(i)); 00424 CurDAG->UpdateNodeOperands(Call, &Ops[0], Ops.size()); 00425 } 00426 00427 /// isCalleeLoad - Return true if call address is a load and it can be 00428 /// moved below CALLSEQ_START and the chains leading up to the call. 00429 /// Return the CALLSEQ_START by reference as a second output. 00430 static bool isCalleeLoad(SDValue Callee, SDValue &Chain) { 00431 if (Callee.getNode() == Chain.getNode() || !Callee.hasOneUse()) 00432 return false; 00433 LoadSDNode *LD = dyn_cast<LoadSDNode>(Callee.getNode()); 00434 if (!LD || 00435 LD->isVolatile() || 00436 LD->getAddressingMode() != ISD::UNINDEXED || 00437 LD->getExtensionType() != ISD::NON_EXTLOAD) 00438 return false; 00439 00440 // Now let's find the callseq_start. 00441 while (Chain.getOpcode() != ISD::CALLSEQ_START) { 00442 if (!Chain.hasOneUse()) 00443 return false; 00444 Chain = Chain.getOperand(0); 00445 } 00446 00447 if (Chain.getOperand(0).getNode() == Callee.getNode()) 00448 return true; 00449 if (Chain.getOperand(0).getOpcode() == ISD::TokenFactor && 00450 Callee.getValue(1).isOperandOf(Chain.getOperand(0).getNode()) && 00451 Callee.getValue(1).hasOneUse()) 00452 return true; 00453 return false; 00454 } 00455 00456 00457 /// PreprocessForRMW - Preprocess the DAG to make instruction selection better. 00458 /// This is only run if not in -O0 mode. 00459 /// This allows the instruction selector to pick more read-modify-write 00460 /// instructions. This is a common case: 00461 /// 00462 /// [Load chain] 00463 /// ^ 00464 /// | 00465 /// [Load] 00466 /// ^ ^ 00467 /// | | 00468 /// / \- 00469 /// / | 00470 /// [TokenFactor] [Op] 00471 /// ^ ^ 00472 /// | | 00473 /// \ / 00474 /// \ / 00475 /// [Store] 00476 /// 00477 /// The fact the store's chain operand != load's chain will prevent the 00478 /// (store (op (load))) instruction from being selected. We can transform it to: 00479 /// 00480 /// [Load chain] 00481 /// ^ 00482 /// | 00483 /// [TokenFactor] 00484 /// ^ 00485 /// | 00486 /// [Load] 00487 /// ^ ^ 00488 /// | | 00489 /// | \- 00490 /// | | 00491 /// | [Op] 00492 /// | ^ 00493 /// | | 00494 /// \ / 00495 /// \ / 00496 /// [Store] 00497 void X86DAGToDAGISel::PreprocessForRMW() { 00498 for (SelectionDAG::allnodes_iterator I = CurDAG->allnodes_begin(), 00499 E = CurDAG->allnodes_end(); I != E; ++I) { 00500 if (I->getOpcode() == X86ISD::CALL) { 00501 /// Also try moving call address load from outside callseq_start to just 00502 /// before the call to allow it to be folded. 00503 /// 00504 /// [Load chain] 00505 /// ^ 00506 /// | 00507 /// [Load] 00508 /// ^ ^ 00509 /// | | 00510 /// / \-- 00511 /// / | 00512 ///[CALLSEQ_START] | 00513 /// ^ | 00514 /// | | 00515 /// [LOAD/C2Reg] | 00516 /// | | 00517 /// \ / 00518 /// \ / 00519 /// [CALL] 00520 SDValue Chain = I->getOperand(0); 00521 SDValue Load = I->getOperand(1); 00522 if (!isCalleeLoad(Load, Chain)) 00523 continue; 00524 MoveBelowCallSeqStart(CurDAG, Load, SDValue(I, 0), Chain); 00525 ++NumLoadMoved; 00526 continue; 00527 } 00528 00529 if (!ISD::isNON_TRUNCStore(I)) 00530 continue; 00531 SDValue Chain = I->getOperand(0); 00532 00533 if (Chain.getNode()->getOpcode() != ISD::TokenFactor) 00534 continue; 00535 00536 SDValue N1 = I->getOperand(1); 00537 SDValue N2 = I->getOperand(2); 00538 if ((N1.getValueType().isFloatingPoint() && 00539 !N1.getValueType().isVector()) || 00540 !N1.hasOneUse()) 00541 continue; 00542 00543 bool RModW = false; 00544 SDValue Load; 00545 unsigned Opcode = N1.getNode()->getOpcode(); 00546 switch (Opcode) { 00547 case ISD::ADD: 00548 case ISD::MUL: 00549 case ISD::AND: 00550 case ISD::OR: 00551 case ISD::XOR: 00552 case ISD::ADDC: 00553 case ISD::ADDE: 00554 case ISD::VECTOR_SHUFFLE: { 00555 SDValue N10 = N1.getOperand(0); 00556 SDValue N11 = N1.getOperand(1); 00557 RModW = isRMWLoad(N10, Chain, N2, Load); 00558 if (!RModW) 00559 RModW = isRMWLoad(N11, Chain, N2, Load); 00560 break; 00561 } 00562 case ISD::SUB: 00563 case ISD::SHL: 00564 case ISD::SRA: 00565 case ISD::SRL: 00566 case ISD::ROTL: 00567 case ISD::ROTR: 00568 case ISD::SUBC: 00569 case ISD::SUBE: 00570 case X86ISD::SHLD: 00571 case X86ISD::SHRD: { 00572 SDValue N10 = N1.getOperand(0); 00573 RModW = isRMWLoad(N10, Chain, N2, Load); 00574 break; 00575 } 00576 } 00577 00578 if (RModW) { 00579 MoveBelowTokenFactor(CurDAG, Load, SDValue(I, 0), Chain); 00580 ++NumLoadMoved; 00581 } 00582 } 00583 } 00584 00585 00586 /// PreprocessForFPConvert - Walk over the dag lowering fpround and fpextend 00587 /// nodes that target the FP stack to be store and load to the stack. This is a 00588 /// gross hack. We would like to simply mark these as being illegal, but when 00589 /// we do that, legalize produces these when it expands calls, then expands 00590 /// these in the same legalize pass. We would like dag combine to be able to 00591 /// hack on these between the call expansion and the node legalization. As such 00592 /// this pass basically does "really late" legalization of these inline with the 00593 /// X86 isel pass. 00594 void X86DAGToDAGISel::PreprocessForFPConvert() { 00595 for (SelectionDAG::allnodes_iterator I = CurDAG->allnodes_begin(), 00596 E = CurDAG->allnodes_end(); I != E; ) { 00597 SDNode *N = I++; // Preincrement iterator to avoid invalidation issues. 00598 if (N->getOpcode() != ISD::FP_ROUND && N->getOpcode() != ISD::FP_EXTEND) 00599 continue; 00600 00601 // If the source and destination are SSE registers, then this is a legal 00602 // conversion that should not be lowered. 00603 EVT SrcVT = N->getOperand(0).getValueType(); 00604 EVT DstVT = N->getValueType(0); 00605 bool SrcIsSSE = X86Lowering.isScalarFPTypeInSSEReg(SrcVT); 00606 bool DstIsSSE = X86Lowering.isScalarFPTypeInSSEReg(DstVT); 00607 if (SrcIsSSE && DstIsSSE) 00608 continue; 00609 00610 if (!SrcIsSSE && !DstIsSSE) { 00611 // If this is an FPStack extension, it is a noop. 00612 if (N->getOpcode() == ISD::FP_EXTEND) 00613 continue; 00614 // If this is a value-preserving FPStack truncation, it is a noop. 00615 if (N->getConstantOperandVal(1)) 00616 continue; 00617 } 00618 00619 // Here we could have an FP stack truncation or an FPStack <-> SSE convert. 00620 // FPStack has extload and truncstore. SSE can fold direct loads into other 00621 // operations. Based on this, decide what we want to do. 00622 EVT MemVT; 00623 if (N->getOpcode() == ISD::FP_ROUND) 00624 MemVT = DstVT; // FP_ROUND must use DstVT, we can't do a 'trunc load'. 00625 else 00626 MemVT = SrcIsSSE ? SrcVT : DstVT; 00627 00628 SDValue MemTmp = CurDAG->CreateStackTemporary(MemVT); 00629 DebugLoc dl = N->getDebugLoc(); 00630 00631 // FIXME: optimize the case where the src/dest is a load or store? 00632 SDValue Store = CurDAG->getTruncStore(CurDAG->getEntryNode(), dl, 00633 N->getOperand(0), 00634 MemTmp, NULL, 0, MemVT); 00635 SDValue Result = CurDAG->getExtLoad(ISD::EXTLOAD, dl, DstVT, Store, MemTmp, 00636 NULL, 0, MemVT); 00637 00638 // We're about to replace all uses of the FP_ROUND/FP_EXTEND with the 00639 // extload we created. This will cause general havok on the dag because 00640 // anything below the conversion could be folded into other existing nodes. 00641 // To avoid invalidating 'I', back it up to the convert node. 00642 --I; 00643 CurDAG->ReplaceAllUsesOfValueWith(SDValue(N, 0), Result); 00644 00645 // Now that we did that, the node is dead. Increment the iterator to the 00646 // next node to process, then delete N. 00647 ++I; 00648 CurDAG->DeleteNode(N); 00649 } 00650 } 00651 00652 /// InstructionSelectBasicBlock - This callback is invoked by SelectionDAGISel 00653 /// when it has created a SelectionDAG for us to codegen. 00654 void X86DAGToDAGISel::InstructionSelect() { 00655 const Function *F = MF->getFunction(); 00656 OptForSize = F->hasFnAttr(Attribute::OptimizeForSize); 00657 00658 DEBUG(BB->dump()); 00659 if (OptLevel != CodeGenOpt::None) 00660 PreprocessForRMW(); 00661 00662 // FIXME: This should only happen when not compiled with -O0. 00663 PreprocessForFPConvert(); 00664 00665 // Codegen the basic block. 00666 #ifndef NDEBUG 00667 DEBUG(errs() << "===== Instruction selection begins:\n"); 00668 Indent = 0; 00669 #endif 00670 SelectRoot(*CurDAG); 00671 #ifndef NDEBUG 00672 DEBUG(errs() << "===== Instruction selection ends:\n"); 00673 #endif 00674 00675 CurDAG->RemoveDeadNodes(); 00676 } 00677 00678 /// EmitSpecialCodeForMain - Emit any code that needs to be executed only in 00679 /// the main function. 00680 void X86DAGToDAGISel::EmitSpecialCodeForMain(MachineBasicBlock *BB, 00681 MachineFrameInfo *MFI) { 00682 const TargetInstrInfo *TII = TM.getInstrInfo(); 00683 if (Subtarget->isTargetCygMing()) 00684 BuildMI(BB, DebugLoc::getUnknownLoc(), 00685 TII->get(X86::CALLpcrel32)).addExternalSymbol("__main"); 00686 } 00687 00688 void X86DAGToDAGISel::EmitFunctionEntryCode(Function &Fn, MachineFunction &MF) { 00689 // If this is main, emit special code for main. 00690 MachineBasicBlock *BB = MF.begin(); 00691 if (Fn.hasExternalLinkage() && Fn.getName() == "main") 00692 EmitSpecialCodeForMain(BB, MF.getFrameInfo()); 00693 } 00694 00695 00696 bool X86DAGToDAGISel::MatchSegmentBaseAddress(SDValue N, 00697 X86ISelAddressMode &AM) { 00698 assert(N.getOpcode() == X86ISD::SegmentBaseAddress); 00699 SDValue Segment = N.getOperand(0); 00700 00701 if (AM.Segment.getNode() == 0) { 00702 AM.Segment = Segment; 00703 return false; 00704 } 00705 00706 return true; 00707 } 00708 00709 bool X86DAGToDAGISel::MatchLoad(SDValue N, X86ISelAddressMode &AM) { 00710 // This optimization is valid because the GNU TLS model defines that 00711 // gs:0 (or fs:0 on X86-64) contains its own address. 00712 // For more information see http://people.redhat.com/drepper/tls.pdf 00713 00714 SDValue Address = N.getOperand(1); 00715 if (Address.getOpcode() == X86ISD::SegmentBaseAddress && 00716 !MatchSegmentBaseAddress (Address, AM)) 00717 return false; 00718 00719 return true; 00720 } 00721 00722 /// MatchWrapper - Try to match X86ISD::Wrapper and X86ISD::WrapperRIP nodes 00723 /// into an addressing mode. These wrap things that will resolve down into a 00724 /// symbol reference. If no match is possible, this returns true, otherwise it 00725 /// returns false. 00726 bool X86DAGToDAGISel::MatchWrapper(SDValue N, X86ISelAddressMode &AM) { 00727 // If the addressing mode already has a symbol as the displacement, we can 00728 // never match another symbol. 00729 if (AM.hasSymbolicDisplacement()) 00730 return true; 00731 00732 SDValue N0 = N.getOperand(0); 00733 CodeModel::Model M = TM.getCodeModel(); 00734 00735 // Handle X86-64 rip-relative addresses. We check this before checking direct 00736 // folding because RIP is preferable to non-RIP accesses. 00737 if (Subtarget->is64Bit() && 00738 // Under X86-64 non-small code model, GV (and friends) are 64-bits, so 00739 // they cannot be folded into immediate fields. 00740 // FIXME: This can be improved for kernel and other models? 00741 (M == CodeModel::Small || M == CodeModel::Kernel) && 00742 // Base and index reg must be 0 in order to use %rip as base and lowering 00743 // must allow RIP. 00744 !AM.hasBaseOrIndexReg() && N.getOpcode() == X86ISD::WrapperRIP) { 00745 if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(N0)) { 00746 int64_t Offset = AM.Disp + G->getOffset(); 00747 if (!X86::isOffsetSuitableForCodeModel(Offset, M)) return true; 00748 AM.GV = G->getGlobal(); 00749 AM.Disp = Offset; 00750 AM.SymbolFlags = G->getTargetFlags(); 00751 } else if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(N0)) { 00752 int64_t Offset = AM.Disp + CP->getOffset(); 00753 if (!X86::isOffsetSuitableForCodeModel(Offset, M)) return true; 00754 AM.CP = CP->getConstVal(); 00755 AM.Align = CP->getAlignment(); 00756 AM.Disp = Offset; 00757 AM.SymbolFlags = CP->getTargetFlags(); 00758 } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(N0)) { 00759 AM.ES = S->getSymbol(); 00760 AM.SymbolFlags = S->getTargetFlags(); 00761 } else { 00762 JumpTableSDNode *J = cast<JumpTableSDNode>(N0); 00763 AM.JT = J->getIndex(); 00764 AM.SymbolFlags = J->getTargetFlags(); 00765 } 00766 00767 if (N.getOpcode() == X86ISD::WrapperRIP) 00768 AM.setBaseReg(CurDAG->getRegister(X86::RIP, MVT::i64)); 00769 return false; 00770 } 00771 00772 // Handle the case when globals fit in our immediate field: This is true for 00773 // X86-32 always and X86-64 when in -static -mcmodel=small mode. In 64-bit 00774 // mode, this results in a non-RIP-relative computation. 00775 if (!Subtarget->is64Bit() || 00776 ((M == CodeModel::Small || M == CodeModel::Kernel) && 00777 TM.getRelocationModel() == Reloc::Static)) { 00778 if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(N0)) { 00779 AM.GV = G->getGlobal(); 00780 AM.Disp += G->getOffset(); 00781 AM.SymbolFlags = G->getTargetFlags(); 00782 } else if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(N0)) { 00783 AM.CP = CP->getConstVal(); 00784 AM.Align = CP->getAlignment(); 00785 AM.Disp += CP->getOffset(); 00786 AM.SymbolFlags = CP->getTargetFlags(); 00787 } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(N0)) { 00788 AM.ES = S->getSymbol(); 00789 AM.SymbolFlags = S->getTargetFlags(); 00790 } else { 00791 JumpTableSDNode *J = cast<JumpTableSDNode>(N0); 00792 AM.JT = J->getIndex(); 00793 AM.SymbolFlags = J->getTargetFlags(); 00794 } 00795 return false; 00796 } 00797 00798 return true; 00799 } 00800 00801 /// MatchAddress - Add the specified node to the specified addressing mode, 00802 /// returning true if it cannot be done. This just pattern matches for the 00803 /// addressing mode. 00804 bool X86DAGToDAGISel::MatchAddress(SDValue N, X86ISelAddressMode &AM) { 00805 if (MatchAddressRecursively(N, AM, 0)) 00806 return true; 00807 00808 // Post-processing: Convert lea(,%reg,2) to lea(%reg,%reg), which has 00809 // a smaller encoding and avoids a scaled-index. 00810 if (AM.Scale == 2 && 00811 AM.BaseType == X86ISelAddressMode::RegBase && 00812 AM.Base.Reg.getNode() == 0) { 00813 AM.Base.Reg = AM.IndexReg; 00814 AM.Scale = 1; 00815 } 00816 00817 // Post-processing: Convert foo to foo(%rip), even in non-PIC mode, 00818 // because it has a smaller encoding. 00819 // TODO: Which other code models can use this? 00820 if (TM.getCodeModel() == CodeModel::Small && 00821 Subtarget->is64Bit() && 00822 AM.Scale == 1 && 00823 AM.BaseType == X86ISelAddressMode::RegBase && 00824 AM.Base.Reg.getNode() == 0 && 00825 AM.IndexReg.getNode() == 0 && 00826 AM.SymbolFlags == 0 && 00827 AM.hasSymbolicDisplacement()) 00828 AM.Base.Reg = CurDAG->getRegister(X86::RIP, MVT::i64); 00829 00830 return false; 00831 } 00832 00833 bool X86DAGToDAGISel::MatchAddressRecursively(SDValue N, X86ISelAddressMode &AM, 00834 unsigned Depth) { 00835 bool is64Bit = Subtarget->is64Bit(); 00836 DebugLoc dl = N.getDebugLoc(); 00837 DEBUG({ 00838 errs() << "MatchAddress: "; 00839 AM.dump(); 00840 }); 00841 // Limit recursion. 00842 if (Depth > 5) 00843 return MatchAddressBase(N, AM); 00844 00845 CodeModel::Model M = TM.getCodeModel(); 00846 00847 // If this is already a %rip relative address, we can only merge immediates 00848 // into it. Instead of handling this in every case, we handle it here. 00849 // RIP relative addressing: %rip + 32-bit displacement! 00850 if (AM.isRIPRelative()) { 00851 // FIXME: JumpTable and ExternalSymbol address currently don't like 00852 // displacements. It isn't very important, but this should be fixed for 00853 // consistency. 00854 if (!AM.ES && AM.JT != -1) return true; 00855 00856 if (ConstantSDNode *Cst = dyn_cast<ConstantSDNode>(N)) { 00857 int64_t Val = AM.Disp + Cst->getSExtValue(); 00858 if (X86::isOffsetSuitableForCodeModel(Val, M, 00859 AM.hasSymbolicDisplacement())) { 00860 AM.Disp = Val; 00861 return false; 00862 } 00863 } 00864 return true; 00865 } 00866 00867 switch (N.getOpcode()) { 00868 default: break; 00869 case ISD::Constant: { 00870 uint64_t Val = cast<ConstantSDNode>(N)->getSExtValue(); 00871 if (!is64Bit || 00872 X86::isOffsetSuitableForCodeModel(AM.Disp + Val, M, 00873 AM.hasSymbolicDisplacement())) { 00874 AM.Disp += Val; 00875 return false; 00876 } 00877 break; 00878 } 00879 00880 case X86ISD::SegmentBaseAddress: 00881 if (!MatchSegmentBaseAddress(N, AM)) 00882 return false; 00883 break; 00884 00885 case X86ISD::Wrapper: 00886 case X86ISD::WrapperRIP: 00887 if (!MatchWrapper(N, AM)) 00888 return false; 00889 break; 00890 00891 case ISD::LOAD: 00892 if (!MatchLoad(N, AM)) 00893 return false; 00894 break; 00895 00896 case ISD::FrameIndex: 00897 if (AM.BaseType == X86ISelAddressMode::RegBase 00898 && AM.Base.Reg.getNode() == 0) { 00899 AM.BaseType = X86ISelAddressMode::FrameIndexBase; 00900 AM.Base.FrameIndex = cast<FrameIndexSDNode>(N)->getIndex(); 00901 return false; 00902 } 00903 break; 00904 00905 case ISD::SHL: 00906 if (AM.IndexReg.getNode() != 0 || AM.Scale != 1) 00907 break; 00908 00909 if (ConstantSDNode 00910 *CN = dyn_cast<ConstantSDNode>(N.getNode()->getOperand(1))) { 00911 unsigned Val = CN->getZExtValue(); 00912 // Note that we handle x<<1 as (,x,2) rather than (x,x) here so 00913 // that the base operand remains free for further matching. If 00914 // the base doesn't end up getting used, a post-processing step 00915 // in MatchAddress turns (,x,2) into (x,x), which is cheaper. 00916 if (Val == 1 || Val == 2 || Val == 3) { 00917 AM.Scale = 1 << Val; 00918 SDValue ShVal = N.getNode()->getOperand(0); 00919 00920 // Okay, we know that we have a scale by now. However, if the scaled 00921 // value is an add of something and a constant, we can fold the 00922 // constant into the disp field here. 00923 if (ShVal.getNode()->getOpcode() == ISD::ADD && ShVal.hasOneUse() && 00924 isa<ConstantSDNode>(ShVal.getNode()->getOperand(1))) { 00925 AM.IndexReg = ShVal.getNode()->getOperand(0); 00926 ConstantSDNode *AddVal = 00927 cast<ConstantSDNode>(ShVal.getNode()->getOperand(1)); 00928 uint64_t Disp = AM.Disp + (AddVal->getSExtValue() << Val); 00929 if (!is64Bit || 00930 X86::isOffsetSuitableForCodeModel(Disp, M, 00931 AM.hasSymbolicDisplacement())) 00932 AM.Disp = Disp; 00933 else 00934 AM.IndexReg = ShVal; 00935 } else { 00936 AM.IndexReg = ShVal; 00937 } 00938 return false; 00939 } 00940 break; 00941 } 00942 00943 case ISD::SMUL_LOHI: 00944 case ISD::UMUL_LOHI: 00945 // A mul_lohi where we need the low part can be folded as a plain multiply. 00946 if (N.getResNo() != 0) break; 00947 // FALL THROUGH 00948 case ISD::MUL: 00949 case X86ISD::MUL_IMM: 00950 // X*[3,5,9] -> X+X*[2,4,8] 00951 if (AM.BaseType == X86ISelAddressMode::RegBase && 00952 AM.Base.Reg.getNode() == 0 && 00953 AM.IndexReg.getNode() == 0) { 00954 if (ConstantSDNode 00955 *CN = dyn_cast<ConstantSDNode>(N.getNode()->getOperand(1))) 00956 if (CN->getZExtValue() == 3 || CN->getZExtValue() == 5 || 00957 CN->getZExtValue() == 9) { 00958 AM.Scale = unsigned(CN->getZExtValue())-1; 00959 00960 SDValue MulVal = N.getNode()->getOperand(0); 00961 SDValue Reg; 00962 00963 // Okay, we know that we have a scale by now. However, if the scaled 00964 // value is an add of something and a constant, we can fold the 00965 // constant into the disp field here. 00966 if (MulVal.getNode()->getOpcode() == ISD::ADD && MulVal.hasOneUse() && 00967 isa<ConstantSDNode>(MulVal.getNode()->getOperand(1))) { 00968 Reg = MulVal.getNode()->getOperand(0); 00969 ConstantSDNode *AddVal = 00970 cast<ConstantSDNode>(MulVal.getNode()->getOperand(1)); 00971 uint64_t Disp = AM.Disp + AddVal->getSExtValue() * 00972 CN->getZExtValue(); 00973 if (!is64Bit || 00974 X86::isOffsetSuitableForCodeModel(Disp, M, 00975 AM.hasSymbolicDisplacement())) 00976 AM.Disp = Disp; 00977 else 00978 Reg = N.getNode()->getOperand(0); 00979 } else { 00980 Reg = N.getNode()->getOperand(0); 00981 } 00982 00983 AM.IndexReg = AM.Base.Reg = Reg; 00984 return false; 00985 } 00986 } 00987 break; 00988 00989 case ISD::SUB: { 00990 // Given A-B, if A can be completely folded into the address and 00991 // the index field with the index field unused, use -B as the index. 00992 // This is a win if a has multiple parts that can be folded into 00993 // the address. Also, this saves a mov if the base register has 00994 // other uses, since it avoids a two-address sub instruction, however 00995 // it costs an additional mov if the index register has other uses. 00996 00997 // Test if the LHS of the sub can be folded. 00998 X86ISelAddressMode Backup = AM; 00999 if (MatchAddressRecursively(N.getNode()->getOperand(0), AM, Depth+1)) { 01000 AM = Backup; 01001 break; 01002 } 01003 // Test if the index field is free for use. 01004 if (AM.IndexReg.getNode() || AM.isRIPRelative()) { 01005 AM = Backup; 01006 break; 01007 } 01008 int Cost = 0; 01009 SDValue RHS = N.getNode()->getOperand(1); 01010 // If the RHS involves a register with multiple uses, this 01011 // transformation incurs an extra mov, due to the neg instruction 01012 // clobbering its operand. 01013 if (!RHS.getNode()->hasOneUse() || 01014 RHS.getNode()->getOpcode() == ISD::CopyFromReg || 01015 RHS.getNode()->getOpcode() == ISD::TRUNCATE || 01016 RHS.getNode()->getOpcode() == ISD::ANY_EXTEND || 01017 (RHS.getNode()->getOpcode() == ISD::ZERO_EXTEND && 01018 RHS.getNode()->getOperand(0).getValueType() == MVT::i32)) 01019 ++Cost; 01020 // If the base is a register with multiple uses, this 01021 // transformation may save a mov. 01022 if ((AM.BaseType == X86ISelAddressMode::RegBase && 01023 AM.Base.Reg.getNode() && 01024 !AM.Base.Reg.getNode()->hasOneUse()) || 01025 AM.BaseType == X86ISelAddressMode::FrameIndexBase) 01026 --Cost; 01027 // If the folded LHS was interesting, this transformation saves 01028 // address arithmetic. 01029 if ((AM.hasSymbolicDisplacement() && !Backup.hasSymbolicDisplacement()) + 01030 ((AM.Disp != 0) && (Backup.Disp == 0)) + 01031 (AM.Segment.getNode() && !Backup.Segment.getNode()) >= 2) 01032 --Cost; 01033 // If it doesn't look like it may be an overall win, don't do it. 01034 if (Cost >= 0) { 01035 AM = Backup; 01036 break; 01037 } 01038 01039 // Ok, the transformation is legal and appears profitable. Go for it. 01040 SDValue Zero = CurDAG->getConstant(0, N.getValueType()); 01041 SDValue Neg = CurDAG->getNode(ISD::SUB, dl, N.getValueType(), Zero, RHS); 01042 AM.IndexReg = Neg; 01043 AM.Scale = 1; 01044 01045 // Insert the new nodes into the topological ordering. 01046 if (Zero.getNode()->getNodeId() == -1 || 01047 Zero.getNode()->getNodeId() > N.getNode()->getNodeId()) { 01048 CurDAG->RepositionNode(N.getNode(), Zero.getNode()); 01049 Zero.getNode()->setNodeId(N.getNode()->getNodeId()); 01050 } 01051 if (Neg.getNode()->getNodeId() == -1 || 01052 Neg.getNode()->getNodeId() > N.getNode()->getNodeId()) { 01053 CurDAG->RepositionNode(N.getNode(), Neg.getNode()); 01054 Neg.getNode()->setNodeId(N.getNode()->getNodeId()); 01055 } 01056 return false; 01057 } 01058 01059 case ISD::ADD: { 01060 X86ISelAddressMode Backup = AM; 01061 if (!MatchAddressRecursively(N.getNode()->getOperand(0), AM, Depth+1) && 01062 !MatchAddressRecursively(N.getNode()->getOperand(1), AM, Depth+1)) 01063 return false; 01064 AM = Backup; 01065 if (!MatchAddressRecursively(N.getNode()->getOperand(1), AM, Depth+1) && 01066 !MatchAddressRecursively(N.getNode()->getOperand(0), AM, Depth+1)) 01067 return false; 01068 AM = Backup; 01069 01070 // If we couldn't fold both operands into the address at the same time, 01071 // see if we can just put each operand into a register and fold at least 01072 // the add. 01073 if (AM.BaseType == X86ISelAddressMode::RegBase && 01074 !AM.Base.Reg.getNode() && 01075 !AM.IndexReg.getNode()) { 01076 AM.Base.Reg = N.getNode()->getOperand(0); 01077 AM.IndexReg = N.getNode()->getOperand(1); 01078 AM.Scale = 1; 01079 return false; 01080 } 01081 break; 01082 } 01083 01084 case ISD::OR: 01085 // Handle "X | C" as "X + C" iff X is known to have C bits clear. 01086 if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N.getOperand(1))) { 01087 X86ISelAddressMode Backup = AM; 01088 uint64_t Offset = CN->getSExtValue(); 01089 // Start with the LHS as an addr mode. 01090 if (!MatchAddressRecursively(N.getOperand(0), AM, Depth+1) && 01091 // Address could not have picked a GV address for the displacement. 01092 AM.GV == NULL && 01093 // On x86-64, the resultant disp must fit in 32-bits. 01094 (!is64Bit || 01095 X86::isOffsetSuitableForCodeModel(AM.Disp + Offset, M, 01096 AM.hasSymbolicDisplacement())) && 01097 // Check to see if the LHS & C is zero. 01098 CurDAG->MaskedValueIsZero(N.getOperand(0), CN->getAPIntValue())) { 01099 AM.Disp += Offset; 01100 return false; 01101 } 01102 AM = Backup; 01103 } 01104 break; 01105 01106 case ISD::AND: { 01107 // Perform some heroic transforms on an and of a constant-count shift 01108 // with a constant to enable use of the scaled offset field. 01109 01110 SDValue Shift = N.getOperand(0); 01111 if (Shift.getNumOperands() != 2) break; 01112 01113 // Scale must not be used already. 01114 if (AM.IndexReg.getNode() != 0 || AM.Scale != 1) break; 01115 01116 SDValue X = Shift.getOperand(0); 01117 ConstantSDNode *C2 = dyn_cast<ConstantSDNode>(N.getOperand(1)); 01118 ConstantSDNode *C1 = dyn_cast<ConstantSDNode>(Shift.getOperand(1)); 01119 if (!C1 || !C2) break; 01120 01121 // Handle "(X >> (8-C1)) & C2" as "(X >> 8) & 0xff)" if safe. This 01122 // allows us to convert the shift and and into an h-register extract and 01123 // a scaled index. 01124 if (Shift.getOpcode() == ISD::SRL && Shift.hasOneUse()) { 01125 unsigned ScaleLog = 8 - C1->getZExtValue(); 01126 if (ScaleLog > 0 && ScaleLog < 4 && 01127 C2->getZExtValue() == (UINT64_C(0xff) << ScaleLog)) { 01128 SDValue Eight = CurDAG->getConstant(8, MVT::i8); 01129 SDValue Mask = CurDAG->getConstant(0xff, N.getValueType()); 01130 SDValue Srl = CurDAG->getNode(ISD::SRL, dl, N.getValueType(), 01131 X, Eight); 01132 SDValue And = CurDAG->getNode(ISD::AND, dl, N.getValueType(), 01133 Srl, Mask); 01134 SDValue ShlCount = CurDAG->getConstant(ScaleLog, MVT::i8); 01135 SDValue Shl = CurDAG->getNode(ISD::SHL, dl, N.getValueType(), 01136 And, ShlCount); 01137 01138 // Insert the new nodes into the topological ordering. 01139 if (Eight.getNode()->getNodeId() == -1 || 01140 Eight.getNode()->getNodeId() > X.getNode()->getNodeId()) { 01141 CurDAG->RepositionNode(X.getNode(), Eight.getNode()); 01142 Eight.getNode()->setNodeId(X.getNode()->getNodeId()); 01143 } 01144 if (Mask.getNode()->getNodeId() == -1 || 01145 Mask.getNode()->getNodeId() > X.getNode()->getNodeId()) { 01146 CurDAG->RepositionNode(X.getNode(), Mask.getNode()); 01147 Mask.getNode()->setNodeId(X.getNode()->getNodeId()); 01148 } 01149 if (Srl.getNode()->getNodeId() == -1 || 01150 Srl.getNode()->getNodeId() > Shift.getNode()->getNodeId()) { 01151 CurDAG->RepositionNode(Shift.getNode(), Srl.getNode()); 01152 Srl.getNode()->setNodeId(Shift.getNode()->getNodeId()); 01153 } 01154 if (And.getNode()->getNodeId() == -1 || 01155 And.getNode()->getNodeId() > N.getNode()->getNodeId()) { 01156 CurDAG->RepositionNode(N.getNode(), And.getNode()); 01157 And.getNode()->setNodeId(N.getNode()->getNodeId()); 01158 } 01159 if (ShlCount.getNode()->getNodeId() == -1 || 01160 ShlCount.getNode()->getNodeId() > X.getNode()->getNodeId()) { 01161 CurDAG->RepositionNode(X.getNode(), ShlCount.getNode()); 01162 ShlCount.getNode()->setNodeId(N.getNode()->getNodeId()); 01163 } 01164 if (Shl.getNode()->getNodeId() == -1 || 01165 Shl.getNode()->getNodeId() > N.getNode()->getNodeId()) { 01166 CurDAG->RepositionNode(N.getNode(), Shl.getNode()); 01167 Shl.getNode()->setNodeId(N.getNode()->getNodeId()); 01168 } 01169 CurDAG->ReplaceAllUsesWith(N, Shl); 01170 AM.IndexReg = And; 01171 AM.Scale = (1 << ScaleLog); 01172 return false; 01173 } 01174 } 01175 01176 // Handle "(X << C1) & C2" as "(X & (C2>>C1)) << C1" if safe and if this 01177 // allows us to fold the shift into this addressing mode. 01178 if (Shift.getOpcode() != ISD::SHL) break; 01179 01180 // Not likely to be profitable if either the AND or SHIFT node has more 01181 // than one use (unless all uses are for address computation). Besides, 01182 // isel mechanism requires their node ids to be reused. 01183 if (!N.hasOneUse() || !Shift.hasOneUse()) 01184 break; 01185 01186 // Verify that the shift amount is something we can fold. 01187 unsigned ShiftCst = C1->getZExtValue(); 01188 if (ShiftCst != 1 && ShiftCst != 2 && ShiftCst != 3) 01189 break; 01190 01191 // Get the new AND mask, this folds to a constant. 01192 SDValue NewANDMask = CurDAG->getNode(ISD::SRL, dl, N.getValueType(), 01193 SDValue(C2, 0), SDValue(C1, 0)); 01194 SDValue NewAND = CurDAG->getNode(ISD::AND, dl, N.getValueType(), X, 01195 NewANDMask); 01196 SDValue NewSHIFT = CurDAG->getNode(ISD::SHL, dl, N.getValueType(), 01197 NewAND, SDValue(C1, 0)); 01198 01199 // Insert the new nodes into the topological ordering. 01200 if (C1->getNodeId() > X.getNode()->getNodeId()) { 01201 CurDAG->RepositionNode(X.getNode(), C1); 01202 C1->setNodeId(X.getNode()->getNodeId()); 01203 } 01204 if (NewANDMask.getNode()->getNodeId() == -1 || 01205 NewANDMask.getNode()->getNodeId() > X.getNode()->getNodeId()) { 01206 CurDAG->RepositionNode(X.getNode(), NewANDMask.getNode()); 01207 NewANDMask.getNode()->setNodeId(X.getNode()->getNodeId()); 01208 } 01209 if (NewAND.getNode()->getNodeId() == -1 || 01210 NewAND.getNode()->getNodeId() > Shift.getNode()->getNodeId()) { 01211 CurDAG->RepositionNode(Shift.getNode(), NewAND.getNode()); 01212 NewAND.getNode()->setNodeId(Shift.getNode()->getNodeId()); 01213 } 01214 if (NewSHIFT.getNode()->getNodeId() == -1 || 01215 NewSHIFT.getNode()->getNodeId() > N.getNode()->getNodeId()) { 01216 CurDAG->RepositionNode(N.getNode(), NewSHIFT.getNode()); 01217 NewSHIFT.getNode()->setNodeId(N.getNode()->getNodeId()); 01218 } 01219 01220 CurDAG->ReplaceAllUsesWith(N, NewSHIFT); 01221 01222 AM.Scale = 1 << ShiftCst; 01223 AM.IndexReg = NewAND; 01224 return false; 01225 } 01226 } 01227 01228 return MatchAddressBase(N, AM); 01229 } 01230 01231 /// MatchAddressBase - Helper for MatchAddress. Add the specified node to the 01232 /// specified addressing mode without any further recursion. 01233 bool X86DAGToDAGISel::MatchAddressBase(SDValue N, X86ISelAddressMode &AM) { 01234 // Is the base register already occupied? 01235 if (AM.BaseType != X86ISelAddressMode::RegBase || AM.Base.Reg.getNode()) { 01236 // If so, check to see if the scale index register is set. 01237 if (AM.IndexReg.getNode() == 0) { 01238 AM.IndexReg = N; 01239 AM.Scale = 1; 01240 return false; 01241 } 01242 01243 // Otherwise, we cannot select it. 01244 return true; 01245 } 01246 01247 // Default, generate it as a register. 01248 AM.BaseType = X86ISelAddressMode::RegBase; 01249 AM.Base.Reg = N; 01250 return false; 01251 } 01252 01253 /// SelectAddr - returns true if it is able pattern match an addressing mode. 01254 /// It returns the operands which make up the maximal addressing mode it can 01255 /// match by reference. 01256 bool X86DAGToDAGISel::SelectAddr(SDValue Op, SDValue N, SDValue &Base, 01257 SDValue &Scale, SDValue &Index, 01258 SDValue &Disp, SDValue &Segment) { 01259 X86ISelAddressMode AM; 01260 bool Done = false; 01261 if (AvoidDupAddrCompute && !N.hasOneUse()) { 01262 unsigned Opcode = N.getOpcode(); 01263 if (Opcode != ISD::Constant && Opcode != ISD::FrameIndex && 01264 Opcode != X86ISD::Wrapper && Opcode != X86ISD::WrapperRIP) { 01265 // If we are able to fold N into addressing mode, then we'll allow it even 01266 // if N has multiple uses. In general, addressing computation is used as 01267 // addresses by all of its uses. But watch out for CopyToReg uses, that 01268 // means the address computation is liveout. It will be computed by a LEA 01269 // so we want to avoid computing the address twice. 01270 for (SDNode::use_iterator UI = N.getNode()->use_begin(), 01271 UE = N.getNode()->use_end(); UI != UE; ++UI) { 01272 if (UI->getOpcode() == ISD::CopyToReg) { 01273 MatchAddressBase(N, AM); 01274 Done = true; 01275 break; 01276 } 01277 } 01278 } 01279 } 01280 01281 if (!Done && MatchAddress(N, AM)) 01282 return false; 01283 01284 EVT VT = N.getValueType(); 01285 if (AM.BaseType == X86ISelAddressMode::RegBase) { 01286 if (!AM.Base.Reg.getNode()) 01287 AM.Base.Reg = CurDAG->getRegister(0, VT); 01288 } 01289 01290 if (!AM.IndexReg.getNode()) 01291 AM.IndexReg = CurDAG->getRegister(0, VT); 01292 01293 getAddressOperands(AM, Base, Scale, Index, Disp, Segment); 01294 return true; 01295 } 01296 01297 /// SelectScalarSSELoad - Match a scalar SSE load. In particular, we want to 01298 /// match a load whose top elements are either undef or zeros. The load flavor 01299 /// is derived from the type of N, which is either v4f32 or v2f64. 01300 bool X86DAGToDAGISel::SelectScalarSSELoad(SDValue Op, SDValue Pred, 01301 SDValue N, SDValue &Base, 01302 SDValue &Scale, SDValue &Index, 01303 SDValue &Disp, SDValue &Segment, 01304 SDValue &InChain, 01305 SDValue &OutChain) { 01306 if (N.getOpcode() == ISD::SCALAR_TO_VECTOR) { 01307 InChain = N.getOperand(0).getValue(1); 01308 if (ISD::isNON_EXTLoad(InChain.getNode()) && 01309 InChain.getValue(0).hasOneUse() && 01310 N.hasOneUse() && 01311 IsLegalAndProfitableToFold(N.getNode(), Pred.getNode(), Op.getNode())) { 01312 LoadSDNode *LD = cast<LoadSDNode>(InChain); 01313 if (!SelectAddr(Op, LD->getBasePtr(), Base, Scale, Index, Disp, Segment)) 01314 return false; 01315 OutChain = LD->getChain(); 01316 return true; 01317 } 01318 } 01319 01320 // Also handle the case where we explicitly require zeros in the top 01321 // elements. This is a vector shuffle from the zero vector. 01322 if (N.getOpcode() == X86ISD::VZEXT_MOVL && N.getNode()->hasOneUse() && 01323 // Check to see if the top elements are all zeros (or bitcast of zeros). 01324 N.getOperand(0).getOpcode() == ISD::SCALAR_TO_VECTOR && 01325 N.getOperand(0).getNode()->hasOneUse() && 01326 ISD::isNON_EXTLoad(N.getOperand(0).getOperand(0).getNode()) && 01327 N.getOperand(0).getOperand(0).hasOneUse()) { 01328 // Okay, this is a zero extending load. Fold it. 01329 LoadSDNode *LD = cast<LoadSDNode>(N.getOperand(0).getOperand(0)); 01330 if (!SelectAddr(Op, LD->getBasePtr(), Base, Scale, Index, Disp, Segment)) 01331 return false; 01332 OutChain = LD->getChain(); 01333 InChain = SDValue(LD, 1); 01334 return true; 01335 } 01336 return false; 01337 } 01338 01339 01340 /// SelectLEAAddr - it calls SelectAddr and determines if the maximal addressing 01341 /// mode it matches can be cost effectively emitted as an LEA instruction. 01342 bool X86DAGToDAGISel::SelectLEAAddr(SDValue Op, SDValue N, 01343 SDValue &Base, SDValue &Scale, 01344 SDValue &Index, SDValue &Disp) { 01345 X86ISelAddressMode AM; 01346 01347 // Set AM.Segment to prevent MatchAddress from using one. LEA doesn't support 01348 // segments. 01349 SDValue Copy = AM.Segment; 01350 SDValue T = CurDAG->getRegister(0, MVT::i32); 01351 AM.Segment = T; 01352 if (MatchAddress(N, AM)) 01353 return false; 01354 assert (T == AM.Segment); 01355 AM.Segment = Copy; 01356 01357 EVT VT = N.getValueType(); 01358 unsigned Complexity = 0; 01359 if (AM.BaseType == X86ISelAddressMode::RegBase) 01360 if (AM.Base.Reg.getNode()) 01361 Complexity = 1; 01362 else 01363 AM.Base.Reg = CurDAG->getRegister(0, VT); 01364 else if (AM.BaseType == X86ISelAddressMode::FrameIndexBase) 01365 Complexity = 4; 01366 01367 if (AM.IndexReg.getNode()) 01368 Complexity++; 01369 else 01370 AM.IndexReg = CurDAG->getRegister(0, VT); 01371 01372 // Don't match just leal(,%reg,2). It's cheaper to do addl %reg, %reg, or with 01373 // a simple shift. 01374 if (AM.Scale > 1) 01375 Complexity++; 01376 01377 // FIXME: We are artificially lowering the criteria to turn ADD %reg, $GA 01378 // to a LEA. This is determined with some expermentation but is by no means 01379 // optimal (especially for code size consideration). LEA is nice because of 01380 // its three-address nature. Tweak the cost function again when we can run 01381 // convertToThreeAddress() at register allocation time. 01382 if (AM.hasSymbolicDisplacement()) { 01383 // For X86-64, we should always use lea to materialize RIP relative 01384 // addresses. 01385 if (Subtarget->is64Bit()) 01386 Complexity = 4; 01387 else 01388 Complexity += 2; 01389 } 01390 01391 if (AM.Disp && (AM.Base.Reg.getNode() || AM.IndexReg.getNode())) 01392 Complexity++; 01393 01394 // If it isn't worth using an LEA, reject it. 01395 if (Complexity <= 2) 01396 return false; 01397 01398 SDValue Segment; 01399 getAddressOperands(AM, Base, Scale, Index, Disp, Segment); 01400 return true; 01401 } 01402 01403 /// SelectTLSADDRAddr - This is only run on TargetGlobalTLSAddress nodes. 01404 bool X86DAGToDAGISel::SelectTLSADDRAddr(SDValue Op, SDValue N, SDValue &Base, 01405 SDValue &Scale, SDValue &Index, 01406 SDValue &Disp) { 01407 assert(Op.getOpcode() == X86ISD::TLSADDR); 01408 assert(N.getOpcode() == ISD::TargetGlobalTLSAddress); 01409 const GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(N); 01410 01411 X86ISelAddressMode AM; 01412 AM.GV = GA->getGlobal(); 01413 AM.Disp += GA->getOffset(); 01414 AM.Base.Reg = CurDAG->getRegister(0, N.getValueType()); 01415 AM.SymbolFlags = GA->getTargetFlags(); 01416 01417 if (N.getValueType() == MVT::i32) { 01418 AM.Scale = 1; 01419 AM.IndexReg = CurDAG->getRegister(X86::EBX, MVT::i32); 01420 } else { 01421 AM.IndexReg = CurDAG->getRegister(0, MVT::i64); 01422 } 01423 01424 SDValue Segment; 01425 getAddressOperands(AM, Base, Scale, Index, Disp, Segment); 01426 return true; 01427 } 01428 01429 01430 bool X86DAGToDAGISel::TryFoldLoad(SDValue P, SDValue N, 01431 SDValue &Base, SDValue &Scale, 01432 SDValue &Index, SDValue &Disp, 01433 SDValue &Segment) { 01434 if (ISD::isNON_EXTLoad(N.getNode()) && 01435 N.hasOneUse() && 01436 IsLegalAndProfitableToFold(N.getNode(), P.getNode(), P.getNode())) 01437 return SelectAddr(P, N.getOperand(1), Base, Scale, Index, Disp, Segment); 01438 return false; 01439 } 01440 01441 /// getGlobalBaseReg - Return an SDNode that returns the value of 01442 /// the global base register. Output instructions required to 01443 /// initialize the global base register, if necessary. 01444 /// 01445 SDNode *X86DAGToDAGISel::getGlobalBaseReg() { 01446 unsigned GlobalBaseReg = getInstrInfo()->getGlobalBaseReg(MF); 01447 return CurDAG->getRegister(GlobalBaseReg, TLI.getPointerTy()).getNode(); 01448 } 01449 01450 static SDNode *FindCallStartFromCall(SDNode *Node) { 01451 if (Node->getOpcode() == ISD::CALLSEQ_START) return Node; 01452 assert(Node->getOperand(0).getValueType() == MVT::Other && 01453 "Node doesn't have a token chain argument!"); 01454 return FindCallStartFromCall(Node->getOperand(0).getNode()); 01455 } 01456 01457 SDNode *X86DAGToDAGISel::SelectAtomic64(SDNode *Node, unsigned Opc) { 01458 SDValue Chain = Node->getOperand(0); 01459 SDValue In1 = Node->getOperand(1); 01460 SDValue In2L = Node->getOperand(2); 01461 SDValue In2H = Node->getOperand(3); 01462 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Tmp4; 01463 if (!SelectAddr(In1, In1, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4)) 01464 return NULL; 01465 SDValue LSI = Node->getOperand(4); // MemOperand 01466 const SDValue Ops[] = { Tmp0, Tmp1, Tmp2, Tmp3, Tmp4, In2L, In2H, LSI, Chain}; 01467 return CurDAG->getTargetNode(Opc, Node->getDebugLoc(), 01468 MVT::i32, MVT::i32, MVT::Other, Ops, 01469 array_lengthof(Ops)); 01470 } 01471 01472 SDNode *X86DAGToDAGISel::SelectAtomicLoadAdd(SDNode *Node, EVT NVT) { 01473 if (Node->hasAnyUseOfValue(0)) 01474 return 0; 01475 01476 // Optimize common patterns for __sync_add_and_fetch and 01477 // __sync_sub_and_fetch where the result is not used. This allows us 01478 // to use "lock" version of add, sub, inc, dec instructions. 01479 // FIXME: Do not use special instructions but instead add the "lock" 01480 // prefix to the target node somehow. The extra information will then be 01481 // transferred to machine instruction and it denotes the prefix. 01482 SDValue Chain = Node->getOperand(0); 01483 SDValue Ptr = Node->getOperand(1); 01484 SDValue Val = Node->getOperand(2); 01485 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Tmp4; 01486 if (!SelectAddr(Ptr, Ptr, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4)) 01487 return 0; 01488 01489 bool isInc = false, isDec = false, isSub = false, isCN = false; 01490 ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Val); 01491 if (CN) { 01492 isCN = true; 01493 int64_t CNVal = CN->getSExtValue(); 01494 if (CNVal == 1) 01495 isInc = true; 01496 else if (CNVal == -1) 01497 isDec = true; 01498 else if (CNVal >= 0) 01499 Val = CurDAG->getTargetConstant(CNVal, NVT); 01500 else { 01501 isSub = true; 01502 Val = CurDAG->getTargetConstant(-CNVal, NVT); 01503 } 01504 } else if (Val.hasOneUse() && 01505 Val.getOpcode() == ISD::SUB && 01506 X86::isZeroNode(Val.getOperand(0))) { 01507 isSub = true; 01508 Val = Val.getOperand(1); 01509 } 01510 01511 unsigned Opc = 0; 01512 switch (NVT.getSimpleVT().SimpleTy) { 01513 default: return 0; 01514 case MVT::i8: 01515 if (isInc) 01516 Opc = X86::LOCK_INC8m; 01517 else if (isDec) 01518 Opc = X86::LOCK_DEC8m; 01519 else if (isSub) { 01520 if (isCN) 01521 Opc = X86::LOCK_SUB8mi; 01522 else 01523 Opc = X86::LOCK_SUB8mr; 01524 } else { 01525 if (isCN) 01526 Opc = X86::LOCK_ADD8mi; 01527 else 01528 Opc = X86::LOCK_ADD8mr; 01529 } 01530 break; 01531 case MVT::i16: 01532 if (isInc) 01533 Opc = X86::LOCK_INC16m; 01534 else if (isDec) 01535 Opc = X86::LOCK_DEC16m; 01536 else if (isSub) { 01537 if (isCN) { 01538 if (Predicate_i16immSExt8(Val.getNode())) 01539 Opc = X86::LOCK_SUB16mi8; 01540 else 01541 Opc = X86::LOCK_SUB16mi; 01542 } else 01543 Opc = X86::LOCK_SUB16mr; 01544 } else { 01545 if (isCN) { 01546 if (Predicate_i16immSExt8(Val.getNode())) 01547 Opc = X86::LOCK_ADD16mi8; 01548 else 01549 Opc = X86::LOCK_ADD16mi; 01550 } else 01551 Opc = X86::LOCK_ADD16mr; 01552 } 01553 break; 01554 case MVT::i32: 01555 if (isInc) 01556 Opc = X86::LOCK_INC32m; 01557 else if (isDec) 01558 Opc = X86::LOCK_DEC32m; 01559 else if (isSub) { 01560 if (isCN) { 01561 if (Predicate_i32immSExt8(Val.getNode())) 01562 Opc = X86::LOCK_SUB32mi8; 01563 else 01564 Opc = X86::LOCK_SUB32mi; 01565 } else 01566 Opc = X86::LOCK_SUB32mr; 01567 } else { 01568 if (isCN) { 01569 if (Predicate_i32immSExt8(Val.getNode())) 01570 Opc = X86::LOCK_ADD32mi8; 01571 else 01572 Opc = X86::LOCK_ADD32mi; 01573 } else 01574 Opc = X86::LOCK_ADD32mr; 01575 } 01576 break; 01577 case MVT::i64: 01578 if (isInc) 01579 Opc = X86::LOCK_INC64m; 01580 else if (isDec) 01581 Opc = X86::LOCK_DEC64m; 01582 else if (isSub) { 01583 Opc = X86::LOCK_SUB64mr; 01584 if (isCN) { 01585 if (Predicate_i64immSExt8(Val.getNode())) 01586 Opc = X86::LOCK_SUB64mi8; 01587 else if (Predicate_i64immSExt32(Val.getNode())) 01588 Opc = X86::LOCK_SUB64mi32; 01589 } 01590 } else { 01591 Opc = X86::LOCK_ADD64mr; 01592 if (isCN) { 01593 if (Predicate_i64immSExt8(Val.getNode())) 01594 Opc = X86::LOCK_ADD64mi8; 01595 else if (Predicate_i64immSExt32(Val.getNode())) 01596 Opc = X86::LOCK_ADD64mi32; 01597 } 01598 } 01599 break; 01600 } 01601 01602 DebugLoc dl = Node->getDebugLoc(); 01603 SDValue Undef = SDValue(CurDAG->getTargetNode(TargetInstrInfo::IMPLICIT_DEF, 01604 dl, NVT), 0); 01605 SDValue MemOp = CurDAG->getMemOperand(cast<MemSDNode>(Node)->getMemOperand()); 01606 if (isInc || isDec) { 01607 SDValue Ops[] = { Tmp0, Tmp1, Tmp2, Tmp3, Tmp4, MemOp, Chain }; 01608 SDValue Ret = SDValue(CurDAG->getTargetNode(Opc, dl, MVT::Other, Ops, 7), 0); 01609 SDValue RetVals[] = { Undef, Ret }; 01610 return CurDAG->getMergeValues(RetVals, 2, dl).getNode(); 01611 } else { 01612 SDValue Ops[] = { Tmp0, Tmp1, Tmp2, Tmp3, Tmp4, Val, MemOp, Chain }; 01613 SDValue Ret = SDValue(CurDAG->getTargetNode(Opc, dl, MVT::Other, Ops, 8), 0); 01614 SDValue RetVals[] = { Undef, Ret }; 01615 return CurDAG->getMergeValues(RetVals, 2, dl).getNode(); 01616 } 01617 } 01618 01619 SDNode *X86DAGToDAGISel::Select(SDValue N) { 01620 SDNode *Node = N.getNode(); 01621 EVT NVT = Node->getValueType(0); 01622 unsigned Opc, MOpc; 01623 unsigned Opcode = Node->getOpcode(); 01624 DebugLoc dl = Node->getDebugLoc(); 01625 01626 #ifndef NDEBUG 01627 DEBUG({ 01628 errs() << std::string(Indent, ' ') << "Selecting: "; 01629 Node->dump(CurDAG); 01630 errs() << '\n'; 01631 }); 01632 Indent += 2; 01633 #endif 01634 01635 if (Node->isMachineOpcode()) { 01636 #ifndef NDEBUG 01637 DEBUG({ 01638 errs() << std::string(Indent-2, ' ') << "== "; 01639 Node->dump(CurDAG); 01640 errs() << '\n'; 01641 }); 01642 Indent -= 2; 01643 #endif 01644 return NULL; // Already selected. 01645 } 01646 01647 switch (Opcode) { 01648 default: break; 01649 case X86ISD::GlobalBaseReg: 01650 return getGlobalBaseReg(); 01651 01652 case X86ISD::ATOMOR64_DAG: 01653 return SelectAtomic64(Node, X86::ATOMOR6432); 01654 case X86ISD::ATOMXOR64_DAG: 01655 return SelectAtomic64(Node, X86::ATOMXOR6432); 01656 case X86ISD::ATOMADD64_DAG: 01657 return SelectAtomic64(Node, X86::ATOMADD6432); 01658 case X86ISD::ATOMSUB64_DAG: 01659 return SelectAtomic64(Node, X86::ATOMSUB6432); 01660 case X86ISD::ATOMNAND64_DAG: 01661 return SelectAtomic64(Node, X86::ATOMNAND6432); 01662 case X86ISD::ATOMAND64_DAG: 01663 return SelectAtomic64(Node, X86::ATOMAND6432); 01664 case X86ISD::ATOMSWAP64_DAG: 01665 return SelectAtomic64(Node, X86::ATOMSWAP6432); 01666 01667 case ISD::ATOMIC_LOAD_ADD: { 01668 SDNode *RetVal = SelectAtomicLoadAdd(Node, NVT); 01669 if (RetVal) 01670 return RetVal; 01671 break; 01672 } 01673 01674 case ISD::SMUL_LOHI: 01675 case ISD::UMUL_LOHI: { 01676 SDValue N0 = Node->getOperand(0); 01677 SDValue N1 = Node->getOperand(1); 01678 01679 bool isSigned = Opcode == ISD::SMUL_LOHI; 01680 if (!isSigned) { 01681 switch (NVT.getSimpleVT().SimpleTy) { 01682 default: llvm_unreachable("Unsupported VT!"); 01683 case MVT::i8: Opc = X86::MUL8r; MOpc = X86::MUL8m; break; 01684 case MVT::i16: Opc = X86::MUL16r; MOpc = X86::MUL16m; break; 01685 case MVT::i32: Opc = X86::MUL32r; MOpc = X86::MUL32m; break; 01686 case MVT::i64: Opc = X86::MUL64r; MOpc = X86::MUL64m; break; 01687 } 01688 } else { 01689 switch (NVT.getSimpleVT().SimpleTy) { 01690 default: llvm_unreachable("Unsupported VT!"); 01691 case MVT::i8: Opc = X86::IMUL8r; MOpc = X86::IMUL8m; break; 01692 case MVT::i16: Opc = X86::IMUL16r; MOpc = X86::IMUL16m; break; 01693 case MVT::i32: Opc = X86::IMUL32r; MOpc = X86::IMUL32m; break; 01694 case MVT::i64: Opc = X86::IMUL64r; MOpc = X86::IMUL64m; break; 01695 } 01696 } 01697 01698 unsigned LoReg, HiReg; 01699 switch (NVT.getSimpleVT().SimpleTy) { 01700 default: llvm_unreachable("Unsupported VT!"); 01701 case MVT::i8: LoReg = X86::AL; HiReg = X86::AH; break; 01702 case MVT::i16: LoReg = X86::AX; HiReg = X86::DX; break; 01703 case MVT::i32: LoReg = X86::EAX; HiReg = X86::EDX; break; 01704 case MVT::i64: LoReg = X86::RAX; HiReg = X86::RDX; break; 01705 } 01706 01707 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Tmp4; 01708 bool foldedLoad = TryFoldLoad(N, N1, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4); 01709 // Multiply is commmutative. 01710 if (!foldedLoad) { 01711 foldedLoad = TryFoldLoad(N, N0, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4); 01712 if (foldedLoad) 01713 std::swap(N0, N1); 01714 } 01715 01716 SDValue InFlag = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, LoReg, 01717 N0, SDValue()).getValue(1); 01718 01719 if (foldedLoad) { 01720 SDValue Ops[] = { Tmp0, Tmp1, Tmp2, Tmp3, Tmp4, N1.getOperand(0), 01721 InFlag }; 01722 SDNode *CNode = 01723 CurDAG->getTargetNode(MOpc, dl, MVT::Other, MVT::Flag, Ops, 01724 array_lengthof(Ops)); 01725 InFlag = SDValue(CNode, 1); 01726 // Update the chain. 01727 ReplaceUses(N1.getValue(1), SDValue(CNode, 0)); 01728 } else { 01729 InFlag = 01730 SDValue(CurDAG->getTargetNode(Opc, dl, MVT::Flag, N1, InFlag), 0); 01731 } 01732 01733 // Copy the low half of the result, if it is needed. 01734 if (!N.getValue(0).use_empty()) { 01735 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl, 01736 LoReg, NVT, InFlag); 01737 InFlag = Result.getValue(2); 01738 ReplaceUses(N.getValue(0), Result); 01739 #ifndef NDEBUG 01740 DEBUG({ 01741 errs() << std::string(Indent-2, ' ') << "=> "; 01742 Result.getNode()->dump(CurDAG); 01743 errs() << '\n'; 01744 }); 01745 #endif 01746 } 01747 // Copy the high half of the result, if it is needed. 01748 if (!N.getValue(1).use_empty()) { 01749 SDValue Result; 01750 if (HiReg == X86::AH && Subtarget->is64Bit()) { 01751 // Prevent use of AH in a REX instruction by referencing AX instead. 01752 // Shift it down 8 bits. 01753 Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl, 01754 X86::AX, MVT::i16, InFlag); 01755 InFlag = Result.getValue(2); 01756 Result = SDValue(CurDAG->getTargetNode(X86::SHR16ri, dl, MVT::i16, 01757 Result, 01758 CurDAG->getTargetConstant(8, MVT::i8)), 0); 01759 // Then truncate it down to i8. 01760 Result = CurDAG->getTargetExtractSubreg(X86::SUBREG_8BIT, dl, 01761 MVT::i8, Result); 01762 } else { 01763 Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl, 01764 HiReg, NVT, InFlag); 01765 InFlag = Result.getValue(2); 01766 } 01767 ReplaceUses(N.getValue(1), Result); 01768 #ifndef NDEBUG 01769 DEBUG({ 01770 errs() << std::string(Indent-2, ' ') << "=> "; 01771 Result.getNode()->dump(CurDAG); 01772 errs() << '\n'; 01773 }); 01774 #endif 01775 } 01776 01777 #ifndef NDEBUG 01778 Indent -= 2; 01779 #endif 01780 01781 return NULL; 01782 } 01783 01784 case ISD::SDIVREM: 01785 case ISD::UDIVREM: { 01786 SDValue N0 = Node->getOperand(0); 01787 SDValue N1 = Node->getOperand(1); 01788 01789 bool isSigned = Opcode == ISD::SDIVREM; 01790 if (!isSigned) { 01791 switch (NVT.getSimpleVT().SimpleTy) { 01792 default: llvm_unreachable("Unsupported VT!"); 01793 case MVT::i8: Opc = X86::DIV8r; MOpc = X86::DIV8m; break; 01794 case MVT::i16: Opc = X86::DIV16r; MOpc = X86::DIV16m; break; 01795 case MVT::i32: Opc = X86::DIV32r; MOpc = X86::DIV32m; break; 01796 case MVT::i64: Opc = X86::DIV64r; MOpc = X86::DIV64m; break; 01797 } 01798 } else { 01799 switch (NVT.getSimpleVT().SimpleTy) { 01800 default: llvm_unreachable("Unsupported VT!"); 01801 case MVT::i8: Opc = X86::IDIV8r; MOpc = X86::IDIV8m; break; 01802 case MVT::i16: Opc = X86::IDIV16r; MOpc = X86::IDIV16m; break; 01803 case MVT::i32: Opc = X86::IDIV32r; MOpc = X86::IDIV32m; break; 01804 case MVT::i64: Opc = X86::IDIV64r; MOpc = X86::IDIV64m; break; 01805 } 01806 } 01807 01808 unsigned LoReg, HiReg; 01809 unsigned ClrOpcode, SExtOpcode; 01810 switch (NVT.getSimpleVT().SimpleTy) { 01811 default: llvm_unreachable("Unsupported VT!"); 01812 case MVT::i8: 01813 LoReg = X86::AL; HiReg = X86::AH; 01814 ClrOpcode = 0; 01815 SExtOpcode = X86::CBW; 01816 break; 01817 case MVT::i16: 01818 LoReg = X86::AX; HiReg = X86::DX; 01819 ClrOpcode = X86::MOV16r0; 01820 SExtOpcode = X86::CWD; 01821 break; 01822 case MVT::i32: 01823 LoReg = X86::EAX; HiReg = X86::EDX; 01824 ClrOpcode = X86::MOV32r0; 01825 SExtOpcode = X86::CDQ; 01826 break; 01827 case MVT::i64: 01828 LoReg = X86::RAX; HiReg = X86::RDX; 01829 ClrOpcode = ~0U; // NOT USED. 01830 SExtOpcode = X86::CQO; 01831 break; 01832 } 01833 01834 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Tmp4; 01835 bool foldedLoad = TryFoldLoad(N, N1, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4); 01836 bool signBitIsZero = CurDAG->SignBitIsZero(N0); 01837 01838 SDValue InFlag; 01839 if (NVT == MVT::i8 && (!isSigned || signBitIsZero)) { 01840 // Special case for div8, just use a move with zero extension to AX to 01841 // clear the upper 8 bits (AH). 01842 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Tmp4, Move, Chain; 01843 if (TryFoldLoad(N, N0, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4)) { 01844 SDValue Ops[] = { Tmp0, Tmp1, Tmp2, Tmp3, Tmp4, N0.getOperand(0) }; 01845 Move = 01846 SDValue(CurDAG->getTargetNode(X86::MOVZX16rm8, dl, MVT::i16, 01847 MVT::Other, Ops, 01848 array_lengthof(Ops)), 0); 01849 Chain = Move.getValue(1); 01850 ReplaceUses(N0.getValue(1), Chain); 01851 } else { 01852 Move = 01853 SDValue(CurDAG->getTargetNode(X86::MOVZX16rr8, dl, MVT::i16, N0),0); 01854 Chain = CurDAG->getEntryNode(); 01855 } 01856 Chain = CurDAG->getCopyToReg(Chain, dl, X86::AX, Move, SDValue()); 01857 InFlag = Chain.getValue(1); 01858 } else { 01859 InFlag = 01860 CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, 01861 LoReg, N0, SDValue()).getValue(1); 01862 if (isSigned && !signBitIsZero) { 01863 // Sign extend the low part into the high part. 01864 InFlag = 01865 SDValue(CurDAG->getTargetNode(SExtOpcode, dl, MVT::Flag, InFlag),0); 01866 } else { 01867 // Zero out the high part, effectively zero extending the input. 01868 SDValue ClrNode; 01869 01870 if (NVT.getSimpleVT() == MVT::i64) { 01871 ClrNode = SDValue(CurDAG->getTargetNode(X86::MOV32r0, dl, MVT::i32), 01872 0); 01873 // We just did a 32-bit clear, insert it into a 64-bit register to 01874 // clear the whole 64-bit reg. 01875 SDValue Undef = 01876 SDValue(CurDAG->getTargetNode(TargetInstrInfo::IMPLICIT_DEF, 01877 dl, MVT::i64), 0); 01878 SDValue SubRegNo = 01879 CurDAG->getTargetConstant(X86::SUBREG_32BIT, MVT::i32); 01880 ClrNode = 01881 SDValue(CurDAG->getTargetNode(TargetInstrInfo::INSERT_SUBREG, dl, 01882 MVT::i64, Undef, ClrNode, SubRegNo), 01883 0); 01884 } else { 01885 ClrNode = SDValue(CurDAG->getTargetNode(ClrOpcode, dl, NVT), 0); 01886 } 01887 01888 InFlag = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, HiReg, 01889 ClrNode, InFlag).getValue(1); 01890 } 01891 } 01892 01893 if (foldedLoad) { 01894 SDValue Ops[] = { Tmp0, Tmp1, Tmp2, Tmp3, Tmp4, N1.getOperand(0), 01895 InFlag }; 01896 SDNode *CNode = 01897 CurDAG->getTargetNode(MOpc, dl, MVT::Other, MVT::Flag, Ops, 01898 array_lengthof(Ops)); 01899 InFlag = SDValue(CNode, 1); 01900 // Update the chain. 01901 ReplaceUses(N1.getValue(1), SDValue(CNode, 0)); 01902 } else { 01903 InFlag = 01904 SDValue(CurDAG->getTargetNode(Opc, dl, MVT::Flag, N1, InFlag), 0); 01905 } 01906 01907 // Copy the division (low) result, if it is needed. 01908 if (!N.getValue(0).use_empty()) { 01909 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl, 01910 LoReg, NVT, InFlag); 01911 InFlag = Result.getValue(2); 01912 ReplaceUses(N.getValue(0), Result); 01913 #ifndef NDEBUG 01914 DEBUG({ 01915 errs() << std::string(Indent-2, ' ') << "=> "; 01916 Result.getNode()->dump(CurDAG); 01917 errs() << '\n'; 01918 }); 01919 #endif 01920 } 01921 // Copy the remainder (high) result, if it is needed. 01922 if (!N.getValue(1).use_empty()) { 01923 SDValue Result; 01924 if (HiReg == X86::AH && Subtarget->is64Bit()) { 01925 // Prevent use of AH in a REX instruction by referencing AX instead. 01926 // Shift it down 8 bits. 01927 Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl, 01928 X86::AX, MVT::i16, InFlag); 01929 InFlag = Result.getValue(2); 01930 Result = SDValue(CurDAG->getTargetNode(X86::SHR16ri, dl, MVT::i16, 01931 Result, 01932 CurDAG->getTargetConstant(8, MVT::i8)), 01933 0); 01934 // Then truncate it down to i8. 01935 Result = CurDAG->getTargetExtractSubreg(X86::SUBREG_8BIT, dl, 01936 MVT::i8, Result); 01937 } else { 01938 Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl, 01939 HiReg, NVT, InFlag); 01940 InFlag = Result.getValue(2); 01941 } 01942 ReplaceUses(N.getValue(1), Result); 01943 #ifndef NDEBUG 01944 DEBUG({ 01945 errs() << std::string(Indent-2, ' ') << "=> "; 01946 Result.getNode()->dump(CurDAG); 01947 errs() << '\n'; 01948 }); 01949 #endif 01950 } 01951 01952 #ifndef NDEBUG 01953 Indent -= 2; 01954 #endif 01955 01956 return NULL; 01957 } 01958 01959 case X86ISD::CMP: { 01960 SDValue N0 = Node->getOperand(0); 01961 SDValue N1 = Node->getOperand(1); 01962 01963 // Look for (X86cmp (and $op, $imm), 0) and see if we can convert it to 01964 // use a smaller encoding. 01965 if (N0.getNode()->getOpcode() == ISD::AND && N0.getNode()->hasOneUse() && 01966 N0.getValueType() != MVT::i8 && 01967 X86::isZeroNode(N1)) { 01968 ConstantSDNode *C = dyn_cast<ConstantSDNode>(N0.getNode()->getOperand(1)); 01969 if (!C) break; 01970 01971 // For example, convert "testl %eax, $8" to "testb %al, $8" 01972 if ((C->getZExtValue() & ~UINT64_C(0xff)) == 0) { 01973 SDValue Imm = CurDAG->getTargetConstant(C->getZExtValue(), MVT::i8); 01974 SDValue Reg = N0.getNode()->getOperand(0); 01975 01976 // On x86-32, only the ABCD registers have 8-bit subregisters. 01977 if (!Subtarget->is64Bit()) { 01978 TargetRegisterClass *TRC = 0; 01979 switch (N0.getValueType().getSimpleVT().SimpleTy) { 01980 case MVT::i32: TRC = &X86::GR32_ABCDRegClass; break; 01981 case MVT::i16: TRC = &X86::GR16_ABCDRegClass; break; 01982 default: llvm_unreachable("Unsupported TEST operand type!"); 01983 } 01984 SDValue RC = CurDAG->getTargetConstant(TRC->getID(), MVT::i32); 01985 Reg = SDValue(CurDAG->getTargetNode(X86::COPY_TO_REGCLASS, dl, 01986 Reg.getValueType(), Reg, RC), 0); 01987 } 01988 01989 // Extract the l-register. 01990 SDValue Subreg = CurDAG->getTargetExtractSubreg(X86::SUBREG_8BIT, dl, 01991 MVT::i8, Reg); 01992 01993 // Emit a testb. 01994 return CurDAG->getTargetNode(X86::TEST8ri, dl, MVT::i32, Subreg, Imm); 01995 } 01996 01997 // For example, "testl %eax, $2048" to "testb %ah, $8". 01998 if ((C->getZExtValue() & ~UINT64_C(0xff00)) == 0) { 01999 // Shift the immediate right by 8 bits. 02000 SDValue ShiftedImm = CurDAG->getTargetConstant(C->getZExtValue() >> 8, 02001 MVT::i8); 02002 SDValue Reg = N0.getNode()->getOperand(0); 02003 02004 // Put the value in an ABCD register. 02005 TargetRegisterClass *TRC = 0; 02006 switch (N0.getValueType().getSimpleVT().SimpleTy) { 02007 case MVT::i64: TRC = &X86::GR64_ABCDRegClass; break; 02008 case MVT::i32: TRC = &X86::GR32_ABCDRegClass; break; 02009 case MVT::i16: TRC = &X86::GR16_ABCDRegClass; break; 02010 default: llvm_unreachable("Unsupported TEST operand type!"); 02011 } 02012 SDValue RC = CurDAG->getTargetConstant(TRC->getID(), MVT::i32); 02013 Reg = SDValue(CurDAG->getTargetNode(X86::COPY_TO_REGCLASS, dl, 02014 Reg.getValueType(), Reg, RC), 0); 02015 02016 // Extract the h-register. 02017 SDValue Subreg = CurDAG->getTargetExtractSubreg(X86::SUBREG_8BIT_HI, dl, 02018 MVT::i8, Reg); 02019 02020 // Emit a testb. No special NOREX tricks are needed since there's 02021 // only one GPR operand! 02022 return CurDAG->getTargetNode(X86::TEST8ri, dl, MVT::i32, 02023 Subreg, ShiftedImm); 02024 } 02025 02026 // For example, "testl %eax, $32776" to "testw %ax, $32776". 02027 if ((C->getZExtValue() & ~UINT64_C(0xffff)) == 0 && 02028 N0.getValueType() != MVT::i16) { 02029 SDValue Imm = CurDAG->getTargetConstant(C->getZExtValue(), MVT::i16); 02030 SDValue Reg = N0.getNode()->getOperand(0); 02031 02032 // Extract the 16-bit subregister. 02033 SDValue Subreg = CurDAG->getTargetExtractSubreg(X86::SUBREG_16BIT, dl, 02034 MVT::i16, Reg); 02035 02036 // Emit a testw. 02037 return CurDAG->getTargetNode(X86::TEST16ri, dl, MVT::i32, Subreg, Imm); 02038 } 02039 02040 // For example, "testq %rax, $268468232" to "testl %eax, $268468232". 02041 if ((C->getZExtValue() & ~UINT64_C(0xffffffff)) == 0 && 02042 N0.getValueType() == MVT::i64) { 02043 SDValue Imm = CurDAG->getTargetConstant(C->getZExtValue(), MVT::i32); 02044 SDValue Reg = N0.getNode()->getOperand(0); 02045 02046 // Extract the 32-bit subregister. 02047 SDValue Subreg = CurDAG->getTargetExtractSubreg(X86::SUBREG_32BIT, dl, 02048 MVT::i32, Reg); 02049 02050 // Emit a testl. 02051 return CurDAG->getTargetNode(X86::TEST32ri, dl, MVT::i32, Subreg, Imm); 02052 } 02053 } 02054 break; 02055 } 02056 02057 case ISD::DECLARE: { 02058 // Handle DECLARE nodes here because the second operand may have been 02059 // wrapped in X86ISD::Wrapper. 02060 SDValue Chain = Node->getOperand(0); 02061 SDValue N1 = Node->getOperand(1); 02062 SDValue N2 = Node->getOperand(2); 02063 FrameIndexSDNode *FINode = dyn_cast<FrameIndexSDNode>(N1); 02064 02065 // FIXME: We need to handle this for VLAs. 02066 if (!FINode) { 02067 ReplaceUses(N.getValue(0), Chain); 02068 return NULL; 02069 } 02070 02071 if (N2.getOpcode() == ISD::ADD && 02072 N2.getOperand(0).getOpcode() == X86ISD::GlobalBaseReg) 02073 N2 = N2.getOperand(1); 02074 02075 // If N2 is not Wrapper(decriptor) then the llvm.declare is mangled 02076 // somehow, just ignore it. 02077 if (N2.getOpcode() != X86ISD::Wrapper && 02078 N2.getOpcode() != X86ISD::WrapperRIP) { 02079 ReplaceUses(N.getValue(0), Chain); 02080 return NULL; 02081 } 02082 GlobalAddressSDNode *GVNode = 02083 dyn_cast<GlobalAddressSDNode>(N2.getOperand(0)); 02084 if (GVNode == 0) { 02085 ReplaceUses(N.getValue(0), Chain); 02086 return NULL; 02087 } 02088 SDValue Tmp1 = CurDAG->getTargetFrameIndex(FINode->getIndex(), 02089 TLI.getPointerTy()); 02090 SDValue Tmp2 = CurDAG->getTargetGlobalAddress(GVNode->getGlobal(), 02091 TLI.getPointerTy()); 02092 SDValue Ops[] = { Tmp1, Tmp2, Chain }; 02093 return CurDAG->getTargetNode(TargetInstrInfo::DECLARE, dl, 02094 MVT::Other, Ops, 02095 array_lengthof(Ops)); 02096 } 02097 } 02098 02099 SDNode *ResNode = SelectCode(N); 02100 02101 #ifndef NDEBUG 02102 DEBUG({ 02103 errs() << std::string(Indent-2, ' ') << "=> "; 02104 if (ResNode == NULL || ResNode == N.getNode()) 02105 N.getNode()->dump(CurDAG); 02106 else 02107 ResNode->dump(CurDAG); 02108 errs() << '\n'; 02109 }); 02110 Indent -= 2; 02111 #endif 02112 02113 return ResNode; 02114 } 02115 02116 bool X86DAGToDAGISel:: 02117 SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode, 02118 std::vector<SDValue> &OutOps) { 02119 SDValue Op0, Op1, Op2, Op3, Op4; 02120 switch (ConstraintCode) { 02121 case 'o': // offsetable ?? 02122 case 'v': // not offsetable ?? 02123 default: return true; 02124 case 'm': // memory 02125 if (!SelectAddr(Op, Op, Op0, Op1, Op2, Op3, Op4)) 02126 return true; 02127 break; 02128 } 02129 02130 OutOps.push_back(Op0); 02131 OutOps.push_back(Op1); 02132 OutOps.push_back(Op2); 02133 OutOps.push_back(Op3); 02134 OutOps.push_back(Op4); 02135 return false; 02136 } 02137 02138 /// createX86ISelDag - This pass converts a legalized DAG into a 02139 /// X86-specific DAG, ready for instruction scheduling. 02140 /// 02141 FunctionPass *llvm::createX86ISelDag(X86TargetMachine &TM, 02142 llvm::CodeGenOpt::Level OptLevel) { 02143 return new X86DAGToDAGISel(TM, OptLevel); 02144 }