LLVM API Documentation

X86ISelLowering.h

Go to the documentation of this file.
00001 //===-- X86ISelLowering.h - X86 DAG Lowering Interface ----------*- C++ -*-===//
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 the interfaces that X86 uses to lower LLVM code into a
00011 // selection DAG.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef X86ISELLOWERING_H
00016 #define X86ISELLOWERING_H
00017 
00018 #include "X86Subtarget.h"
00019 #include "X86RegisterInfo.h"
00020 #include "X86MachineFunctionInfo.h"
00021 #include "llvm/Target/TargetLowering.h"
00022 #include "llvm/CodeGen/FastISel.h"
00023 #include "llvm/CodeGen/SelectionDAG.h"
00024 #include "llvm/CodeGen/CallingConvLower.h"
00025 
00026 namespace llvm {
00027   namespace X86ISD {
00028     // X86 Specific DAG Nodes
00029     enum NodeType {
00030       // Start the numbering where the builtin ops leave off.
00031       FIRST_NUMBER = ISD::BUILTIN_OP_END,
00032 
00033       /// BSF - Bit scan forward.
00034       /// BSR - Bit scan reverse.
00035       BSF,
00036       BSR,
00037 
00038       /// SHLD, SHRD - Double shift instructions. These correspond to
00039       /// X86::SHLDxx and X86::SHRDxx instructions.
00040       SHLD,
00041       SHRD,
00042 
00043       /// FAND - Bitwise logical AND of floating point values. This corresponds
00044       /// to X86::ANDPS or X86::ANDPD.
00045       FAND,
00046 
00047       /// FOR - Bitwise logical OR of floating point values. This corresponds
00048       /// to X86::ORPS or X86::ORPD.
00049       FOR,
00050 
00051       /// FXOR - Bitwise logical XOR of floating point values. This corresponds
00052       /// to X86::XORPS or X86::XORPD.
00053       FXOR,
00054 
00055       /// FSRL - Bitwise logical right shift of floating point values. These
00056       /// corresponds to X86::PSRLDQ.
00057       FSRL,
00058 
00059       /// FILD, FILD_FLAG - This instruction implements SINT_TO_FP with the
00060       /// integer source in memory and FP reg result.  This corresponds to the
00061       /// X86::FILD*m instructions. It has three inputs (token chain, address,
00062       /// and source type) and two outputs (FP value and token chain). FILD_FLAG
00063       /// also produces a flag).
00064       FILD,
00065       FILD_FLAG,
00066 
00067       /// FP_TO_INT*_IN_MEM - This instruction implements FP_TO_SINT with the
00068       /// integer destination in memory and a FP reg source.  This corresponds
00069       /// to the X86::FIST*m instructions and the rounding mode change stuff. It
00070       /// has two inputs (token chain and address) and two outputs (int value
00071       /// and token chain).
00072       FP_TO_INT16_IN_MEM,
00073       FP_TO_INT32_IN_MEM,
00074       FP_TO_INT64_IN_MEM,
00075 
00076       /// FLD - This instruction implements an extending load to FP stack slots.
00077       /// This corresponds to the X86::FLD32m / X86::FLD64m. It takes a chain
00078       /// operand, ptr to load from, and a ValueType node indicating the type
00079       /// to load to.
00080       FLD,
00081 
00082       /// FST - This instruction implements a truncating store to FP stack
00083       /// slots. This corresponds to the X86::FST32m / X86::FST64m. It takes a
00084       /// chain operand, value to store, address, and a ValueType to store it
00085       /// as.
00086       FST,
00087 
00088       /// CALL - These operations represent an abstract X86 call
00089       /// instruction, which includes a bunch of information.  In particular the
00090       /// operands of these node are:
00091       ///
00092       ///     #0 - The incoming token chain
00093       ///     #1 - The callee
00094       ///     #2 - The number of arg bytes the caller pushes on the stack.
00095       ///     #3 - The number of arg bytes the callee pops off the stack.
00096       ///     #4 - The value to pass in AL/AX/EAX (optional)
00097       ///     #5 - The value to pass in DL/DX/EDX (optional)
00098       ///
00099       /// The result values of these nodes are:
00100       ///
00101       ///     #0 - The outgoing token chain
00102       ///     #1 - The first register result value (optional)
00103       ///     #2 - The second register result value (optional)
00104       ///
00105       CALL,
00106 
00107       /// RDTSC_DAG - This operation implements the lowering for 
00108       /// readcyclecounter
00109       RDTSC_DAG,
00110 
00111       /// X86 compare and logical compare instructions.
00112       CMP, COMI, UCOMI,
00113 
00114       /// X86 bit-test instructions.
00115       BT,
00116 
00117       /// X86 SetCC. Operand 0 is condition code, and operand 1 is the flag
00118       /// operand produced by a CMP instruction.
00119       SETCC,
00120 
00121       /// X86 conditional moves. Operand 0 and operand 1 are the two values
00122       /// to select from. Operand 2 is the condition code, and operand 3 is the
00123       /// flag operand produced by a CMP or TEST instruction. It also writes a
00124       /// flag result.
00125       CMOV,
00126 
00127       /// X86 conditional branches. Operand 0 is the chain operand, operand 1
00128       /// is the block to branch if condition is true, operand 2 is the
00129       /// condition code, and operand 3 is the flag operand produced by a CMP
00130       /// or TEST instruction.
00131       BRCOND,
00132 
00133       /// Return with a flag operand. Operand 0 is the chain operand, operand
00134       /// 1 is the number of bytes of stack to pop.
00135       RET_FLAG,
00136 
00137       /// REP_STOS - Repeat fill, corresponds to X86::REP_STOSx.
00138       REP_STOS,
00139 
00140       /// REP_MOVS - Repeat move, corresponds to X86::REP_MOVSx.
00141       REP_MOVS,
00142 
00143       /// GlobalBaseReg - On Darwin, this node represents the result of the popl
00144       /// at function entry, used for PIC code.
00145       GlobalBaseReg,
00146 
00147       /// Wrapper - A wrapper node for TargetConstantPool,
00148       /// TargetExternalSymbol, and TargetGlobalAddress.
00149       Wrapper,
00150 
00151       /// WrapperRIP - Special wrapper used under X86-64 PIC mode for RIP
00152       /// relative displacements.
00153       WrapperRIP,
00154 
00155       /// PEXTRB - Extract an 8-bit value from a vector and zero extend it to
00156       /// i32, corresponds to X86::PEXTRB.
00157       PEXTRB,
00158 
00159       /// PEXTRW - Extract a 16-bit value from a vector and zero extend it to
00160       /// i32, corresponds to X86::PEXTRW.
00161       PEXTRW,
00162 
00163       /// INSERTPS - Insert any element of a 4 x float vector into any element
00164       /// of a destination 4 x floatvector.
00165       INSERTPS,
00166 
00167       /// PINSRB - Insert the lower 8-bits of a 32-bit value to a vector,
00168       /// corresponds to X86::PINSRB.
00169       PINSRB,
00170 
00171       /// PINSRW - Insert the lower 16-bits of a 32-bit value to a vector,
00172       /// corresponds to X86::PINSRW.
00173       PINSRW,
00174 
00175       /// PSHUFB - Shuffle 16 8-bit values within a vector.
00176       PSHUFB,
00177 
00178       /// FMAX, FMIN - Floating point max and min.
00179       ///
00180       FMAX, FMIN,
00181 
00182       /// FRSQRT, FRCP - Floating point reciprocal-sqrt and reciprocal
00183       /// approximation.  Note that these typically require refinement
00184       /// in order to obtain suitable precision.
00185       FRSQRT, FRCP,
00186 
00187       // TLSADDR - Thread Local Storage.
00188       TLSADDR,
00189 
00190       // SegmentBaseAddress - The address segment:0
00191       SegmentBaseAddress,
00192 
00193       // EH_RETURN - Exception Handling helpers.
00194       EH_RETURN,
00195       
00196       /// TC_RETURN - Tail call return.
00197       ///   operand #0 chain
00198       ///   operand #1 callee (register or absolute)
00199       ///   operand #2 stack adjustment
00200       ///   operand #3 optional in flag
00201       TC_RETURN,
00202 
00203       // LCMPXCHG_DAG, LCMPXCHG8_DAG - Compare and swap.
00204       LCMPXCHG_DAG,
00205       LCMPXCHG8_DAG,
00206 
00207       // ATOMADD64_DAG, ATOMSUB64_DAG, ATOMOR64_DAG, ATOMAND64_DAG, 
00208       // ATOMXOR64_DAG, ATOMNAND64_DAG, ATOMSWAP64_DAG - 
00209       // Atomic 64-bit binary operations.
00210       ATOMADD64_DAG,
00211       ATOMSUB64_DAG,
00212       ATOMOR64_DAG,
00213       ATOMXOR64_DAG,
00214       ATOMAND64_DAG,
00215       ATOMNAND64_DAG,
00216       ATOMSWAP64_DAG,
00217 
00218       // FNSTCW16m - Store FP control world into i16 memory.
00219       FNSTCW16m,
00220 
00221       // VZEXT_MOVL - Vector move low and zero extend.
00222       VZEXT_MOVL,
00223 
00224       // VZEXT_LOAD - Load, scalar_to_vector, and zero extend.
00225       VZEXT_LOAD,
00226 
00227       // VSHL, VSRL - Vector logical left / right shift.
00228       VSHL, VSRL,
00229 
00230       // CMPPD, CMPPS - Vector double/float comparison.
00231       // CMPPD, CMPPS - Vector double/float comparison.
00232       CMPPD, CMPPS,
00233       
00234       // PCMP* - Vector integer comparisons.
00235       PCMPEQB, PCMPEQW, PCMPEQD, PCMPEQQ,
00236       PCMPGTB, PCMPGTW, PCMPGTD, PCMPGTQ,
00237 
00238       // ADD, SUB, SMUL, UMUL, etc. - Arithmetic operations with FLAGS results.
00239       ADD, SUB, SMUL, UMUL,
00240       INC, DEC,
00241 
00242       // MUL_IMM - X86 specific multiply by immediate.
00243       MUL_IMM,
00244       
00245       // PTEST - Vector bitwise comparisons
00246       PTEST,
00247 
00248       // VASTART_SAVE_XMM_REGS - Save xmm argument registers to the stack,
00249       // according to %al. An operator is needed so that this can be expanded
00250       // with control flow.
00251       VASTART_SAVE_XMM_REGS
00252     };
00253   }
00254 
00255   /// Define some predicates that are used for node matching.
00256   namespace X86 {
00257     /// isPSHUFDMask - Return true if the specified VECTOR_SHUFFLE operand
00258     /// specifies a shuffle of elements that is suitable for input to PSHUFD.
00259     bool isPSHUFDMask(ShuffleVectorSDNode *N);
00260 
00261     /// isPSHUFHWMask - Return true if the specified VECTOR_SHUFFLE operand
00262     /// specifies a shuffle of elements that is suitable for input to PSHUFD.
00263     bool isPSHUFHWMask(ShuffleVectorSDNode *N);
00264 
00265     /// isPSHUFLWMask - Return true if the specified VECTOR_SHUFFLE operand
00266     /// specifies a shuffle of elements that is suitable for input to PSHUFD.
00267     bool isPSHUFLWMask(ShuffleVectorSDNode *N);
00268 
00269     /// isSHUFPMask - Return true if the specified VECTOR_SHUFFLE operand
00270     /// specifies a shuffle of elements that is suitable for input to SHUFP*.
00271     bool isSHUFPMask(ShuffleVectorSDNode *N);
00272 
00273     /// isMOVHLPSMask - Return true if the specified VECTOR_SHUFFLE operand
00274     /// specifies a shuffle of elements that is suitable for input to MOVHLPS.
00275     bool isMOVHLPSMask(ShuffleVectorSDNode *N);
00276 
00277     /// isMOVHLPS_v_undef_Mask - Special case of isMOVHLPSMask for canonical form
00278     /// of vector_shuffle v, v, <2, 3, 2, 3>, i.e. vector_shuffle v, undef,
00279     /// <2, 3, 2, 3>
00280     bool isMOVHLPS_v_undef_Mask(ShuffleVectorSDNode *N);
00281 
00282     /// isMOVLPMask - Return true if the specified VECTOR_SHUFFLE operand
00283     /// specifies a shuffle of elements that is suitable for MOVLP{S|D}.
00284     bool isMOVLPMask(ShuffleVectorSDNode *N);
00285 
00286     /// isMOVHPMask - Return true if the specified VECTOR_SHUFFLE operand
00287     /// specifies a shuffle of elements that is suitable for MOVHP{S|D}.
00288     /// as well as MOVLHPS.
00289     bool isMOVHPMask(ShuffleVectorSDNode *N);
00290 
00291     /// isUNPCKLMask - Return true if the specified VECTOR_SHUFFLE operand
00292     /// specifies a shuffle of elements that is suitable for input to UNPCKL.
00293     bool isUNPCKLMask(ShuffleVectorSDNode *N, bool V2IsSplat = false);
00294 
00295     /// isUNPCKHMask - Return true if the specified VECTOR_SHUFFLE operand
00296     /// specifies a shuffle of elements that is suitable for input to UNPCKH.
00297     bool isUNPCKHMask(ShuffleVectorSDNode *N, bool V2IsSplat = false);
00298 
00299     /// isUNPCKL_v_undef_Mask - Special case of isUNPCKLMask for canonical form
00300     /// of vector_shuffle v, v, <0, 4, 1, 5>, i.e. vector_shuffle v, undef,
00301     /// <0, 0, 1, 1>
00302     bool isUNPCKL_v_undef_Mask(ShuffleVectorSDNode *N);
00303 
00304     /// isUNPCKH_v_undef_Mask - Special case of isUNPCKHMask for canonical form
00305     /// of vector_shuffle v, v, <2, 6, 3, 7>, i.e. vector_shuffle v, undef,
00306     /// <2, 2, 3, 3>
00307     bool isUNPCKH_v_undef_Mask(ShuffleVectorSDNode *N);
00308 
00309     /// isMOVLMask - Return true if the specified VECTOR_SHUFFLE operand
00310     /// specifies a shuffle of elements that is suitable for input to MOVSS,
00311     /// MOVSD, and MOVD, i.e. setting the lowest element.
00312     bool isMOVLMask(ShuffleVectorSDNode *N);
00313 
00314     /// isMOVSHDUPMask - Return true if the specified VECTOR_SHUFFLE operand
00315     /// specifies a shuffle of elements that is suitable for input to MOVSHDUP.
00316     bool isMOVSHDUPMask(ShuffleVectorSDNode *N);
00317 
00318     /// isMOVSLDUPMask - Return true if the specified VECTOR_SHUFFLE operand
00319     /// specifies a shuffle of elements that is suitable for input to MOVSLDUP.
00320     bool isMOVSLDUPMask(ShuffleVectorSDNode *N);
00321 
00322     /// isMOVDDUPMask - Return true if the specified VECTOR_SHUFFLE operand
00323     /// specifies a shuffle of elements that is suitable for input to MOVDDUP.
00324     bool isMOVDDUPMask(ShuffleVectorSDNode *N);
00325 
00326     /// getShuffleSHUFImmediate - Return the appropriate immediate to shuffle
00327     /// the specified isShuffleMask VECTOR_SHUFFLE mask with PSHUF* and SHUFP*
00328     /// instructions.
00329     unsigned getShuffleSHUFImmediate(SDNode *N);
00330 
00331     /// getShufflePSHUFHWImmediate - Return the appropriate immediate to shuffle
00332     /// the specified isShuffleMask VECTOR_SHUFFLE mask with PSHUFHW
00333     /// instructions.
00334     unsigned getShufflePSHUFHWImmediate(SDNode *N);
00335 
00336     /// getShufflePSHUFKWImmediate - Return the appropriate immediate to shuffle
00337     /// the specified isShuffleMask VECTOR_SHUFFLE mask with PSHUFLW
00338     /// instructions.
00339     unsigned getShufflePSHUFLWImmediate(SDNode *N);
00340 
00341     /// isZeroNode - Returns true if Elt is a constant zero or a floating point
00342     /// constant +0.0.
00343     bool isZeroNode(SDValue Elt);
00344 
00345     /// isOffsetSuitableForCodeModel - Returns true of the given offset can be
00346     /// fit into displacement field of the instruction.
00347     bool isOffsetSuitableForCodeModel(int64_t Offset, CodeModel::Model M,
00348                                       bool hasSymbolicDisplacement = true);
00349   }
00350 
00351   //===--------------------------------------------------------------------===//
00352   //  X86TargetLowering - X86 Implementation of the TargetLowering interface
00353   class X86TargetLowering : public TargetLowering {
00354     int VarArgsFrameIndex;            // FrameIndex for start of varargs area.
00355     int RegSaveFrameIndex;            // X86-64 vararg func register save area.
00356     unsigned VarArgsGPOffset;         // X86-64 vararg func int reg offset.
00357     unsigned VarArgsFPOffset;         // X86-64 vararg func fp reg offset.
00358     int BytesToPopOnReturn;           // Number of arg bytes ret should pop.
00359     int BytesCallerReserves;          // Number of arg bytes caller makes.
00360 
00361   public:
00362     explicit X86TargetLowering(X86TargetMachine &TM);
00363 
00364     /// getPICJumpTableRelocaBase - Returns relocation base for the given PIC
00365     /// jumptable.
00366     SDValue getPICJumpTableRelocBase(SDValue Table,
00367                                        SelectionDAG &DAG) const;
00368 
00369     // Return the number of bytes that a function should pop when it returns (in
00370     // addition to the space used by the return address).
00371     //
00372     unsigned getBytesToPopOnReturn() const { return BytesToPopOnReturn; }
00373 
00374     // Return the number of bytes that the caller reserves for arguments passed
00375     // to this function.
00376     unsigned getBytesCallerReserves() const { return BytesCallerReserves; }
00377  
00378     /// getStackPtrReg - Return the stack pointer register we are using: either
00379     /// ESP or RSP.
00380     unsigned getStackPtrReg() const { return X86StackPtr; }
00381 
00382     /// getByValTypeAlignment - Return the desired alignment for ByVal aggregate
00383     /// function arguments in the caller parameter area. For X86, aggregates
00384     /// that contains are placed at 16-byte boundaries while the rest are at
00385     /// 4-byte boundaries.
00386     virtual unsigned getByValTypeAlignment(const Type *Ty) const;
00387 
00388     /// getOptimalMemOpType - Returns the target specific optimal type for load
00389     /// and store operations as a result of memset, memcpy, and memmove
00390     /// lowering. It returns EVT::iAny if SelectionDAG should be responsible for
00391     /// determining it.
00392     virtual EVT getOptimalMemOpType(uint64_t Size, unsigned Align,
00393                                     bool isSrcConst, bool isSrcStr,
00394                                     SelectionDAG &DAG) const;
00395 
00396     /// allowsUnalignedMemoryAccesses - Returns true if the target allows
00397     /// unaligned memory accesses. of the specified type.
00398     virtual bool allowsUnalignedMemoryAccesses(EVT VT) const {
00399       return true;
00400     }
00401 
00402     /// LowerOperation - Provide custom lowering hooks for some operations.
00403     ///
00404     virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG);
00405 
00406     /// ReplaceNodeResults - Replace the results of node with an illegal result
00407     /// type with new values built out of custom code.
00408     ///
00409     virtual void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results,
00410                                     SelectionDAG &DAG);
00411 
00412     
00413     virtual SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const;
00414 
00415     virtual MachineBasicBlock *EmitInstrWithCustomInserter(MachineInstr *MI,
00416                                                   MachineBasicBlock *MBB) const;
00417 
00418  
00419     /// getTargetNodeName - This method returns the name of a target specific
00420     /// DAG node.
00421     virtual const char *getTargetNodeName(unsigned Opcode) const;
00422 
00423     /// getSetCCResultType - Return the ISD::SETCC ValueType
00424     virtual MVT::SimpleValueType getSetCCResultType(EVT VT) const;
00425 
00426     /// computeMaskedBitsForTargetNode - Determine which of the bits specified 
00427     /// in Mask are known to be either zero or one and return them in the 
00428     /// KnownZero/KnownOne bitsets.
00429     virtual void computeMaskedBitsForTargetNode(const SDValue Op,
00430                                                 const APInt &Mask,
00431                                                 APInt &KnownZero, 
00432                                                 APInt &KnownOne,
00433                                                 const SelectionDAG &DAG,
00434                                                 unsigned Depth = 0) const;
00435 
00436     virtual bool
00437     isGAPlusOffset(SDNode *N, GlobalValue* &GA, int64_t &Offset) const;
00438     
00439     SDValue getReturnAddressFrameIndex(SelectionDAG &DAG);
00440 
00441     virtual bool ExpandInlineAsm(CallInst *CI) const;
00442     
00443     ConstraintType getConstraintType(const std::string &Constraint) const;
00444      
00445     std::vector<unsigned> 
00446       getRegClassForInlineAsmConstraint(const std::string &Constraint,
00447                                         EVT VT) const;
00448 
00449     virtual const char *LowerXConstraint(EVT ConstraintVT) const;
00450 
00451     /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops
00452     /// vector.  If it is invalid, don't add anything to Ops. If hasMemory is
00453     /// true it means one of the asm constraint of the inline asm instruction
00454     /// being processed is 'm'.
00455     virtual void LowerAsmOperandForConstraint(SDValue Op,
00456                                               char ConstraintLetter,
00457                                               bool hasMemory,
00458                                               std::vector<SDValue> &Ops,
00459                                               SelectionDAG &DAG) const;
00460     
00461     /// getRegForInlineAsmConstraint - Given a physical register constraint
00462     /// (e.g. {edx}), return the register number and the register class for the
00463     /// register.  This should only be used for C_Register constraints.  On
00464     /// error, this returns a register number of 0.
00465     std::pair<unsigned, const TargetRegisterClass*> 
00466       getRegForInlineAsmConstraint(const std::string &Constraint,
00467                                    EVT VT) const;
00468     
00469     /// isLegalAddressingMode - Return true if the addressing mode represented
00470     /// by AM is legal for this target, for a load/store of the specified type.
00471     virtual bool isLegalAddressingMode(const AddrMode &AM, const Type *Ty)const;
00472 
00473     /// isTruncateFree - Return true if it's free to truncate a value of
00474     /// type Ty1 to type Ty2. e.g. On x86 it's free to truncate a i32 value in
00475     /// register EAX to i16 by referencing its sub-register AX.
00476     virtual bool isTruncateFree(const Type *Ty1, const Type *Ty2) const;
00477     virtual bool isTruncateFree(EVT VT1, EVT VT2) const;
00478 
00479     /// isZExtFree - Return true if any actual instruction that defines a
00480     /// value of type Ty1 implicit zero-extends the value to Ty2 in the result
00481     /// register. This does not necessarily include registers defined in
00482     /// unknown ways, such as incoming arguments, or copies from unknown
00483     /// virtual registers. Also, if isTruncateFree(Ty2, Ty1) is true, this
00484     /// does not necessarily apply to truncate instructions. e.g. on x86-64,
00485     /// all instructions that define 32-bit values implicit zero-extend the
00486     /// result out to 64 bits.
00487     virtual bool isZExtFree(const Type *Ty1, const Type *Ty2) const;
00488     virtual bool isZExtFree(EVT VT1, EVT VT2) const;
00489 
00490     /// isNarrowingProfitable - Return true if it's profitable to narrow
00491     /// operations of type VT1 to VT2. e.g. on x86, it's profitable to narrow
00492     /// from i32 to i8 but not from i32 to i16.
00493     virtual bool isNarrowingProfitable(EVT VT1, EVT VT2) const;
00494 
00495     /// isShuffleMaskLegal - Targets can use this to indicate that they only
00496     /// support *some* VECTOR_SHUFFLE operations, those with specific masks.
00497     /// By default, if a target supports the VECTOR_SHUFFLE node, all mask
00498     /// values are assumed to be legal.
00499     virtual bool isShuffleMaskLegal(const SmallVectorImpl<int> &Mask,
00500                                     EVT VT) const;
00501 
00502     /// isVectorClearMaskLegal - Similar to isShuffleMaskLegal. This is
00503     /// used by Targets can use this to indicate if there is a suitable
00504     /// VECTOR_SHUFFLE that can be used to replace a VAND with a constant
00505     /// pool entry.
00506     virtual bool isVectorClearMaskLegal(const SmallVectorImpl<int> &Mask,
00507                                         EVT VT) const;
00508 
00509     /// ShouldShrinkFPConstant - If true, then instruction selection should
00510     /// seek to shrink the FP constant of the specified type to a smaller type
00511     /// in order to save space and / or reduce runtime.
00512     virtual bool ShouldShrinkFPConstant(EVT VT) const {
00513       // Don't shrink FP constpool if SSE2 is available since cvtss2sd is more
00514       // expensive than a straight movsd. On the other hand, it's important to
00515       // shrink long double fp constant since fldt is very slow.
00516       return !X86ScalarSSEf64 || VT == MVT::f80;
00517     }
00518     
00519     /// IsEligibleForTailCallOptimization - Check whether the call is eligible
00520     /// for tail call optimization. Targets which want to do tail call
00521     /// optimization should implement this function.
00522     virtual bool
00523     IsEligibleForTailCallOptimization(SDValue Callee,
00524                                       unsigned CalleeCC,
00525                                       bool isVarArg,
00526                                       const SmallVectorImpl<ISD::InputArg> &Ins,
00527                                       SelectionDAG& DAG) const;
00528 
00529     virtual const X86Subtarget* getSubtarget() {
00530       return Subtarget;
00531     }
00532 
00533     /// isScalarFPTypeInSSEReg - Return true if the specified scalar FP type is
00534     /// computed in an SSE register, not on the X87 floating point stack.
00535     bool isScalarFPTypeInSSEReg(EVT VT) const {
00536       return (VT == MVT::f64 && X86ScalarSSEf64) || // f64 is when SSE2
00537       (VT == MVT::f32 && X86ScalarSSEf32);   // f32 is when SSE1
00538     }
00539 
00540     /// getWidenVectorType: given a vector type, returns the type to widen
00541     /// to (e.g., v7i8 to v8i8). If the vector type is legal, it returns itself.
00542     /// If there is no vector type that we want to widen to, returns EVT::Other
00543     /// When and were to widen is target dependent based on the cost of
00544     /// scalarizing vs using the wider vector type.
00545     virtual EVT getWidenVectorType(EVT VT) const;
00546 
00547     /// createFastISel - This method returns a target specific FastISel object,
00548     /// or null if the target does not support "fast" ISel.
00549     virtual FastISel *
00550     createFastISel(MachineFunction &mf,
00551                    MachineModuleInfo *mmi, DwarfWriter *dw,
00552                    DenseMap<const Value *, unsigned> &,
00553                    DenseMap<const BasicBlock *, MachineBasicBlock *> &,
00554                    DenseMap<const AllocaInst *, int> &
00555 #ifndef NDEBUG
00556                    , SmallSet<Instruction*, 8> &
00557 #endif
00558                    );
00559 
00560     /// getFunctionAlignment - Return the Log2 alignment of this function.
00561     virtual unsigned getFunctionAlignment(const Function *F) const;
00562 
00563   private:
00564     /// Subtarget - Keep a pointer to the X86Subtarget around so that we can
00565     /// make the right decision when generating code for different targets.
00566     const X86Subtarget *Subtarget;
00567     const X86RegisterInfo *RegInfo;
00568     const TargetData *TD;
00569 
00570     /// X86StackPtr - X86 physical register used as stack ptr.
00571     unsigned X86StackPtr;
00572    
00573     /// X86ScalarSSEf32, X86ScalarSSEf64 - Select between SSE or x87 
00574     /// floating point ops.
00575     /// When SSE is available, use it for f32 operations.
00576     /// When SSE2 is available, use it for f64 operations.
00577     bool X86ScalarSSEf32;
00578     bool X86ScalarSSEf64;
00579 
00580     SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
00581                             unsigned CallConv, bool isVarArg,
00582                             const SmallVectorImpl<ISD::InputArg> &Ins,
00583                             DebugLoc dl, SelectionDAG &DAG,
00584                             SmallVectorImpl<SDValue> &InVals);
00585     SDValue LowerMemArgument(SDValue Chain,
00586                              unsigned CallConv,
00587                              const SmallVectorImpl<ISD::InputArg> &ArgInfo,
00588                              DebugLoc dl, SelectionDAG &DAG,
00589                              const CCValAssign &VA,  MachineFrameInfo *MFI,
00590                               unsigned i);
00591     SDValue LowerMemOpCallTo(SDValue Chain, SDValue StackPtr, SDValue Arg,
00592                              DebugLoc dl, SelectionDAG &DAG,
00593                              const CCValAssign &VA,
00594                              ISD::ArgFlagsTy Flags);
00595 
00596     // Call lowering helpers.
00597     bool IsCalleePop(bool isVarArg, unsigned CallConv);
00598     SDValue EmitTailCallLoadRetAddr(SelectionDAG &DAG, SDValue &OutRetAddr,
00599                                 SDValue Chain, bool IsTailCall, bool Is64Bit,
00600                                 int FPDiff, DebugLoc dl);
00601 
00602     CCAssignFn *CCAssignFnForNode(unsigned CallConv) const;
00603     NameDecorationStyle NameDecorationForCallConv(unsigned CallConv);
00604     unsigned GetAlignedArgumentStackSize(unsigned StackSize, SelectionDAG &DAG);
00605 
00606     std::pair<SDValue,SDValue> FP_TO_INTHelper(SDValue Op, SelectionDAG &DAG,
00607                                                bool isSigned);
00608     
00609     SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG);
00610     SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG);
00611     SDValue LowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG);
00612     SDValue LowerEXTRACT_VECTOR_ELT_SSE4(SDValue Op, SelectionDAG &DAG);
00613     SDValue LowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG);
00614     SDValue LowerINSERT_VECTOR_ELT_SSE4(SDValue Op, SelectionDAG &DAG);
00615     SDValue LowerSCALAR_TO_VECTOR(SDValue Op, SelectionDAG &DAG);
00616     SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG);
00617     SDValue LowerGlobalAddress(const GlobalValue *GV, DebugLoc dl,
00618                                int64_t Offset, SelectionDAG &DAG) const;
00619     SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG);
00620     SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG);
00621     SDValue LowerExternalSymbol(SDValue Op, SelectionDAG &DAG);
00622     SDValue LowerShift(SDValue Op, SelectionDAG &DAG);
00623     SDValue BuildFILD(SDValue Op, EVT SrcVT, SDValue Chain, SDValue StackSlot,
00624                       SelectionDAG &DAG);
00625     SDValue LowerSINT_TO_FP(SDValue Op, SelectionDAG &DAG);
00626     SDValue LowerUINT_TO_FP(SDValue Op, SelectionDAG &DAG);
00627     SDValue LowerUINT_TO_FP_i64(SDValue Op, SelectionDAG &DAG);
00628     SDValue LowerUINT_TO_FP_i32(SDValue Op, SelectionDAG &DAG);
00629     SDValue LowerFP_TO_SINT(SDValue Op, SelectionDAG &DAG);
00630     SDValue LowerFP_TO_UINT(SDValue Op, SelectionDAG &DAG);
00631     SDValue LowerFABS(SDValue Op, SelectionDAG &DAG);
00632     SDValue LowerFNEG(SDValue Op, SelectionDAG &DAG);
00633     SDValue LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG);
00634     SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG);
00635     SDValue LowerVSETCC(SDValue Op, SelectionDAG &DAG);
00636     SDValue LowerSELECT(SDValue Op, SelectionDAG &DAG);
00637     SDValue LowerBRCOND(SDValue Op, SelectionDAG &DAG);
00638     SDValue LowerMEMSET(SDValue Op, SelectionDAG &DAG);
00639     SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG);
00640     SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG);
00641     SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG);
00642     SDValue LowerVAARG(SDValue Op, SelectionDAG &DAG);
00643     SDValue LowerVACOPY(SDValue Op, SelectionDAG &DAG);
00644     SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG);
00645     SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG);
00646     SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG);
00647     SDValue LowerFRAME_TO_ARGS_OFFSET(SDValue Op, SelectionDAG &DAG);
00648     SDValue LowerEH_RETURN(SDValue Op, SelectionDAG &DAG);
00649     SDValue LowerTRAMPOLINE(SDValue Op, SelectionDAG &DAG);
00650     SDValue LowerFLT_ROUNDS_(SDValue Op, SelectionDAG &DAG);
00651     SDValue LowerCTLZ(SDValue Op, SelectionDAG &DAG);
00652     SDValue LowerCTTZ(SDValue Op, SelectionDAG &DAG);
00653     SDValue LowerMUL_V2I64(SDValue Op, SelectionDAG &DAG);
00654     SDValue LowerXALUO(SDValue Op, SelectionDAG &DAG);
00655 
00656     SDValue LowerCMP_SWAP(SDValue Op, SelectionDAG &DAG);
00657     SDValue LowerLOAD_SUB(SDValue Op, SelectionDAG &DAG);
00658     SDValue LowerREADCYCLECOUNTER(SDValue Op, SelectionDAG &DAG);
00659 
00660     virtual SDValue
00661       LowerFormalArguments(SDValue Chain,
00662                            unsigned CallConv, bool isVarArg,
00663                            const SmallVectorImpl<ISD::InputArg> &Ins,
00664                            DebugLoc dl, SelectionDAG &DAG,
00665                            SmallVectorImpl<SDValue> &InVals);
00666     virtual SDValue
00667       LowerCall(SDValue Chain, SDValue Callee,
00668                 unsigned CallConv, bool isVarArg, bool isTailCall,
00669                 const SmallVectorImpl<ISD::OutputArg> &Outs,
00670                 const SmallVectorImpl<ISD::InputArg> &Ins,
00671                 DebugLoc dl, SelectionDAG &DAG,
00672                 SmallVectorImpl<SDValue> &InVals);
00673 
00674     virtual SDValue
00675       LowerReturn(SDValue Chain,
00676                   unsigned CallConv, bool isVarArg,
00677                   const SmallVectorImpl<ISD::OutputArg> &Outs,
00678                   DebugLoc dl, SelectionDAG &DAG);
00679 
00680     void ReplaceATOMIC_BINARY_64(SDNode *N, SmallVectorImpl<SDValue> &Results,
00681                                  SelectionDAG &DAG, unsigned NewOp);
00682 
00683     SDValue EmitTargetCodeForMemset(SelectionDAG &DAG, DebugLoc dl,
00684                                     SDValue Chain,
00685                                     SDValue Dst, SDValue Src,
00686                                     SDValue Size, unsigned Align,
00687                                     const Value *DstSV, uint64_t DstSVOff);
00688     SDValue EmitTargetCodeForMemcpy(SelectionDAG &DAG, DebugLoc dl,
00689                                     SDValue Chain,
00690                                     SDValue Dst, SDValue Src,
00691                                     SDValue Size, unsigned Align,
00692                                     bool AlwaysInline,
00693                                     const Value *DstSV, uint64_t DstSVOff,
00694                                     const Value *SrcSV, uint64_t SrcSVOff);
00695     
00696     /// Utility function to emit string processing sse4.2 instructions
00697     /// that return in xmm0.
00698     // This takes the instruction to expand, the associated machine basic
00699     // block, the number of args, and whether or not the second arg is
00700     // in memory or not.
00701     MachineBasicBlock *EmitPCMP(MachineInstr *BInstr, MachineBasicBlock *BB,
00702         unsigned argNum, bool inMem) const;
00703 
00704     /// Utility function to emit atomic bitwise operations (and, or, xor).
00705     // It takes the bitwise instruction to expand, the associated machine basic
00706     // block, and the associated X86 opcodes for reg/reg and reg/imm.
00707     MachineBasicBlock *EmitAtomicBitwiseWithCustomInserter(
00708                                                     MachineInstr *BInstr,
00709                                                     MachineBasicBlock *BB,
00710                                                     unsigned regOpc,
00711                                                     unsigned immOpc,
00712                                                     unsigned loadOpc,
00713                                                     unsigned cxchgOpc,
00714                                                     unsigned copyOpc,
00715                                                     unsigned notOpc,
00716                                                     unsigned EAXreg,
00717                                                     TargetRegisterClass *RC,
00718                                                     bool invSrc = false) const;
00719 
00720     MachineBasicBlock *EmitAtomicBit6432WithCustomInserter(
00721                                                     MachineInstr *BInstr,
00722                                                     MachineBasicBlock *BB,
00723                                                     unsigned regOpcL,
00724                                                     unsigned regOpcH,
00725                                                     unsigned immOpcL,
00726                                                     unsigned immOpcH,
00727                                                     bool invSrc = false) const;
00728     
00729     /// Utility function to emit atomic min and max.  It takes the min/max
00730     /// instruction to expand, the associated basic block, and the associated
00731     /// cmov opcode for moving the min or max value.
00732     MachineBasicBlock *EmitAtomicMinMaxWithCustomInserter(MachineInstr *BInstr,
00733                                                           MachineBasicBlock *BB,
00734                                                         unsigned cmovOpc) const;
00735 
00736     /// Utility function to emit the xmm reg save portion of va_start.
00737     MachineBasicBlock *EmitVAStartSaveXMMRegsWithCustomInserter(
00738                                                    MachineInstr *BInstr,
00739                                                    MachineBasicBlock *BB) const;
00740 
00741     /// Emit nodes that will be selected as "test Op0,Op0", or something
00742     /// equivalent, for use with the given x86 condition code.
00743     SDValue EmitTest(SDValue Op0, unsigned X86CC, SelectionDAG &DAG);
00744 
00745     /// Emit nodes that will be selected as "cmp Op0,Op1", or something
00746     /// equivalent, for use with the given x86 condition code.
00747     SDValue EmitCmp(SDValue Op0, SDValue Op1, unsigned X86CC,
00748                     SelectionDAG &DAG);
00749   };
00750 
00751   namespace X86 {
00752     FastISel *createFastISel(MachineFunction &mf,
00753                            MachineModuleInfo *mmi, DwarfWriter *dw,
00754                            DenseMap<const Value *, unsigned> &,
00755                            DenseMap<const BasicBlock *, MachineBasicBlock *> &,
00756                            DenseMap<const AllocaInst *, int> &
00757 #ifndef NDEBUG
00758                            , SmallSet<Instruction*, 8> &
00759 #endif
00760                            );
00761   }
00762 }
00763 
00764 #endif    // X86ISELLOWERING_H