LLVM API Documentation

PPCISelLowering.h
Go to the documentation of this file.
00001 //===-- PPCISelLowering.h - PPC32 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 PPC uses to lower LLVM code into a
00011 // selection DAG.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_LIB_TARGET_POWERPC_PPCISELLOWERING_H
00016 #define LLVM_LIB_TARGET_POWERPC_PPCISELLOWERING_H
00017 
00018 #include "PPC.h"
00019 #include "PPCInstrInfo.h"
00020 #include "PPCRegisterInfo.h"
00021 #include "llvm/CodeGen/CallingConvLower.h"
00022 #include "llvm/CodeGen/SelectionDAG.h"
00023 #include "llvm/Target/TargetLowering.h"
00024 
00025 namespace llvm {
00026   namespace PPCISD {
00027     enum NodeType {
00028       // Start the numbering where the builtin ops and target ops leave off.
00029       FIRST_NUMBER = ISD::BUILTIN_OP_END,
00030 
00031       /// FSEL - Traditional three-operand fsel node.
00032       ///
00033       FSEL,
00034 
00035       /// FCFID - The FCFID instruction, taking an f64 operand and producing
00036       /// and f64 value containing the FP representation of the integer that
00037       /// was temporarily in the f64 operand.
00038       FCFID,
00039 
00040       /// Newer FCFID[US] integer-to-floating-point conversion instructions for
00041       /// unsigned integers and single-precision outputs.
00042       FCFIDU, FCFIDS, FCFIDUS,
00043 
00044       /// FCTI[D,W]Z - The FCTIDZ and FCTIWZ instructions, taking an f32 or f64
00045       /// operand, producing an f64 value containing the integer representation
00046       /// of that FP value.
00047       FCTIDZ, FCTIWZ,
00048 
00049       /// Newer FCTI[D,W]UZ floating-point-to-integer conversion instructions for
00050       /// unsigned integers.
00051       FCTIDUZ, FCTIWUZ,
00052 
00053       /// Reciprocal estimate instructions (unary FP ops).
00054       FRE, FRSQRTE,
00055 
00056       // VMADDFP, VNMSUBFP - The VMADDFP and VNMSUBFP instructions, taking
00057       // three v4f32 operands and producing a v4f32 result.
00058       VMADDFP, VNMSUBFP,
00059 
00060       /// VPERM - The PPC VPERM Instruction.
00061       ///
00062       VPERM,
00063 
00064       /// Hi/Lo - These represent the high and low 16-bit parts of a global
00065       /// address respectively.  These nodes have two operands, the first of
00066       /// which must be a TargetGlobalAddress, and the second of which must be a
00067       /// Constant.  Selected naively, these turn into 'lis G+C' and 'li G+C',
00068       /// though these are usually folded into other nodes.
00069       Hi, Lo,
00070 
00071       TOC_ENTRY,
00072 
00073       /// The following two target-specific nodes are used for calls through
00074       /// function pointers in the 64-bit SVR4 ABI.
00075 
00076       /// Like a regular LOAD but additionally taking/producing a flag.
00077       LOAD,
00078 
00079       /// Like LOAD (taking/producing a flag), but using r2 as hard-coded
00080       /// destination.
00081       LOAD_TOC,
00082 
00083       /// OPRC, CHAIN = DYNALLOC(CHAIN, NEGSIZE, FRAME_INDEX)
00084       /// This instruction is lowered in PPCRegisterInfo::eliminateFrameIndex to
00085       /// compute an allocation on the stack.
00086       DYNALLOC,
00087 
00088       /// GlobalBaseReg - On Darwin, this node represents the result of the mflr
00089       /// at function entry, used for PIC code.
00090       GlobalBaseReg,
00091 
00092       /// These nodes represent the 32-bit PPC shifts that operate on 6-bit
00093       /// shift amounts.  These nodes are generated by the multi-precision shift
00094       /// code.
00095       SRL, SRA, SHL,
00096 
00097       /// CALL - A direct function call.
00098       /// CALL_NOP is a call with the special NOP which follows 64-bit
00099       /// SVR4 calls.
00100       CALL, CALL_NOP,
00101 
00102       /// CHAIN,FLAG = MTCTR(VAL, CHAIN[, INFLAG]) - Directly corresponds to a
00103       /// MTCTR instruction.
00104       MTCTR,
00105 
00106       /// CHAIN,FLAG = BCTRL(CHAIN, INFLAG) - Directly corresponds to a
00107       /// BCTRL instruction.
00108       BCTRL,
00109 
00110       /// Return with a flag operand, matched by 'blr'
00111       RET_FLAG,
00112 
00113       /// R32 = MFOCRF(CRREG, INFLAG) - Represents the MFOCRF instruction.
00114       /// This copies the bits corresponding to the specified CRREG into the
00115       /// resultant GPR.  Bits corresponding to other CR regs are undefined.
00116       MFOCRF,
00117 
00118       // FIXME: Remove these once the ANDI glue bug is fixed:
00119       /// i1 = ANDIo_1_[EQ|GT]_BIT(i32 or i64 x) - Represents the result of the
00120       /// eq or gt bit of CR0 after executing andi. x, 1. This is used to
00121       /// implement truncation of i32 or i64 to i1.
00122       ANDIo_1_EQ_BIT, ANDIo_1_GT_BIT,
00123 
00124       // EH_SJLJ_SETJMP - SjLj exception handling setjmp.
00125       EH_SJLJ_SETJMP,
00126 
00127       // EH_SJLJ_LONGJMP - SjLj exception handling longjmp.
00128       EH_SJLJ_LONGJMP,
00129 
00130       /// RESVEC = VCMP(LHS, RHS, OPC) - Represents one of the altivec VCMP*
00131       /// instructions.  For lack of better number, we use the opcode number
00132       /// encoding for the OPC field to identify the compare.  For example, 838
00133       /// is VCMPGTSH.
00134       VCMP,
00135 
00136       /// RESVEC, OUTFLAG = VCMPo(LHS, RHS, OPC) - Represents one of the
00137       /// altivec VCMP*o instructions.  For lack of better number, we use the
00138       /// opcode number encoding for the OPC field to identify the compare.  For
00139       /// example, 838 is VCMPGTSH.
00140       VCMPo,
00141 
00142       /// CHAIN = COND_BRANCH CHAIN, CRRC, OPC, DESTBB [, INFLAG] - This
00143       /// corresponds to the COND_BRANCH pseudo instruction.  CRRC is the
00144       /// condition register to branch on, OPC is the branch opcode to use (e.g.
00145       /// PPC::BLE), DESTBB is the destination block to branch to, and INFLAG is
00146       /// an optional input flag argument.
00147       COND_BRANCH,
00148 
00149       /// CHAIN = BDNZ CHAIN, DESTBB - These are used to create counter-based
00150       /// loops.
00151       BDNZ, BDZ,
00152 
00153       /// F8RC = FADDRTZ F8RC, F8RC - This is an FADD done with rounding
00154       /// towards zero.  Used only as part of the long double-to-int
00155       /// conversion sequence.
00156       FADDRTZ,
00157 
00158       /// F8RC = MFFS - This moves the FPSCR (not modeled) into the register.
00159       MFFS,
00160 
00161       /// LARX = This corresponds to PPC l{w|d}arx instrcution: load and
00162       /// reserve indexed. This is used to implement atomic operations.
00163       LARX,
00164 
00165       /// STCX = This corresponds to PPC stcx. instrcution: store conditional
00166       /// indexed. This is used to implement atomic operations.
00167       STCX,
00168 
00169       /// TC_RETURN - A tail call return.
00170       ///   operand #0 chain
00171       ///   operand #1 callee (register or absolute)
00172       ///   operand #2 stack adjustment
00173       ///   operand #3 optional in flag
00174       TC_RETURN,
00175 
00176       /// ch, gl = CR6[UN]SET ch, inglue - Toggle CR bit 6 for SVR4 vararg calls
00177       CR6SET,
00178       CR6UNSET,
00179 
00180       /// GPRC = address of _GLOBAL_OFFSET_TABLE_. Used by initial-exec TLS
00181       /// on PPC32.
00182       PPC32_GOT,
00183 
00184       /// GPRC = address of _GLOBAL_OFFSET_TABLE_. Used by general dynamic and
00185       /// local dynamic TLS  on PPC32.
00186       PPC32_PICGOT,
00187 
00188       /// G8RC = ADDIS_GOT_TPREL_HA %X2, Symbol - Used by the initial-exec
00189       /// TLS model, produces an ADDIS8 instruction that adds the GOT
00190       /// base to sym\@got\@tprel\@ha.
00191       ADDIS_GOT_TPREL_HA,
00192 
00193       /// G8RC = LD_GOT_TPREL_L Symbol, G8RReg - Used by the initial-exec
00194       /// TLS model, produces a LD instruction with base register G8RReg
00195       /// and offset sym\@got\@tprel\@l.  This completes the addition that
00196       /// finds the offset of "sym" relative to the thread pointer.
00197       LD_GOT_TPREL_L,
00198 
00199       /// G8RC = ADD_TLS G8RReg, Symbol - Used by the initial-exec TLS
00200       /// model, produces an ADD instruction that adds the contents of
00201       /// G8RReg to the thread pointer.  Symbol contains a relocation
00202       /// sym\@tls which is to be replaced by the thread pointer and
00203       /// identifies to the linker that the instruction is part of a
00204       /// TLS sequence.
00205       ADD_TLS,
00206 
00207       /// G8RC = ADDIS_TLSGD_HA %X2, Symbol - For the general-dynamic TLS
00208       /// model, produces an ADDIS8 instruction that adds the GOT base
00209       /// register to sym\@got\@tlsgd\@ha.
00210       ADDIS_TLSGD_HA,
00211 
00212       /// G8RC = ADDI_TLSGD_L G8RReg, Symbol - For the general-dynamic TLS
00213       /// model, produces an ADDI8 instruction that adds G8RReg to
00214       /// sym\@got\@tlsgd\@l.
00215       ADDI_TLSGD_L,
00216 
00217       /// G8RC = GET_TLS_ADDR %X3, Symbol - For the general-dynamic TLS
00218       /// model, produces a call to __tls_get_addr(sym\@tlsgd).
00219       GET_TLS_ADDR,
00220 
00221       /// G8RC = ADDIS_TLSLD_HA %X2, Symbol - For the local-dynamic TLS
00222       /// model, produces an ADDIS8 instruction that adds the GOT base
00223       /// register to sym\@got\@tlsld\@ha.
00224       ADDIS_TLSLD_HA,
00225 
00226       /// G8RC = ADDI_TLSLD_L G8RReg, Symbol - For the local-dynamic TLS
00227       /// model, produces an ADDI8 instruction that adds G8RReg to
00228       /// sym\@got\@tlsld\@l.
00229       ADDI_TLSLD_L,
00230 
00231       /// G8RC = GET_TLSLD_ADDR %X3, Symbol - For the local-dynamic TLS
00232       /// model, produces a call to __tls_get_addr(sym\@tlsld).
00233       GET_TLSLD_ADDR,
00234 
00235       /// G8RC = ADDIS_DTPREL_HA %X3, Symbol, Chain - For the
00236       /// local-dynamic TLS model, produces an ADDIS8 instruction
00237       /// that adds X3 to sym\@dtprel\@ha. The Chain operand is needed
00238       /// to tie this in place following a copy to %X3 from the result
00239       /// of a GET_TLSLD_ADDR.
00240       ADDIS_DTPREL_HA,
00241 
00242       /// G8RC = ADDI_DTPREL_L G8RReg, Symbol - For the local-dynamic TLS
00243       /// model, produces an ADDI8 instruction that adds G8RReg to
00244       /// sym\@got\@dtprel\@l.
00245       ADDI_DTPREL_L,
00246 
00247       /// VRRC = VADD_SPLAT Elt, EltSize - Temporary node to be expanded
00248       /// during instruction selection to optimize a BUILD_VECTOR into
00249       /// operations on splats.  This is necessary to avoid losing these
00250       /// optimizations due to constant folding.
00251       VADD_SPLAT,
00252 
00253       /// CHAIN = SC CHAIN, Imm128 - System call.  The 7-bit unsigned
00254       /// operand identifies the operating system entry point.
00255       SC,
00256 
00257       /// CHAIN = STBRX CHAIN, GPRC, Ptr, Type - This is a
00258       /// byte-swapping store instruction.  It byte-swaps the low "Type" bits of
00259       /// the GPRC input, then stores it through Ptr.  Type can be either i16 or
00260       /// i32.
00261       STBRX = ISD::FIRST_TARGET_MEMORY_OPCODE,
00262 
00263       /// GPRC, CHAIN = LBRX CHAIN, Ptr, Type - This is a
00264       /// byte-swapping load instruction.  It loads "Type" bits, byte swaps it,
00265       /// then puts it in the bottom bits of the GPRC.  TYPE can be either i16
00266       /// or i32.
00267       LBRX,
00268 
00269       /// STFIWX - The STFIWX instruction.  The first operand is an input token
00270       /// chain, then an f64 value to store, then an address to store it to.
00271       STFIWX,
00272 
00273       /// GPRC, CHAIN = LFIWAX CHAIN, Ptr - This is a floating-point
00274       /// load which sign-extends from a 32-bit integer value into the
00275       /// destination 64-bit register.
00276       LFIWAX,
00277 
00278       /// GPRC, CHAIN = LFIWZX CHAIN, Ptr - This is a floating-point
00279       /// load which zero-extends from a 32-bit integer value into the
00280       /// destination 64-bit register.
00281       LFIWZX,
00282 
00283       /// G8RC = ADDIS_TOC_HA %X2, Symbol - For medium and large code model,
00284       /// produces an ADDIS8 instruction that adds the TOC base register to
00285       /// sym\@toc\@ha.
00286       ADDIS_TOC_HA,
00287 
00288       /// G8RC = LD_TOC_L Symbol, G8RReg - For medium and large code model,
00289       /// produces a LD instruction with base register G8RReg and offset
00290       /// sym\@toc\@l. Preceded by an ADDIS_TOC_HA to form a full 32-bit offset.
00291       LD_TOC_L,
00292 
00293       /// G8RC = ADDI_TOC_L G8RReg, Symbol - For medium code model, produces
00294       /// an ADDI8 instruction that adds G8RReg to sym\@toc\@l.
00295       /// Preceded by an ADDIS_TOC_HA to form a full 32-bit offset.
00296       ADDI_TOC_L
00297     };
00298   }
00299 
00300   /// Define some predicates that are used for node matching.
00301   namespace PPC {
00302     /// isVPKUHUMShuffleMask - Return true if this is the shuffle mask for a
00303     /// VPKUHUM instruction.
00304     bool isVPKUHUMShuffleMask(ShuffleVectorSDNode *N, unsigned ShuffleKind,
00305                               SelectionDAG &DAG);
00306 
00307     /// isVPKUWUMShuffleMask - Return true if this is the shuffle mask for a
00308     /// VPKUWUM instruction.
00309     bool isVPKUWUMShuffleMask(ShuffleVectorSDNode *N, unsigned ShuffleKind,
00310                               SelectionDAG &DAG);
00311 
00312     /// isVMRGLShuffleMask - Return true if this is a shuffle mask suitable for
00313     /// a VRGL* instruction with the specified unit size (1,2 or 4 bytes).
00314     bool isVMRGLShuffleMask(ShuffleVectorSDNode *N, unsigned UnitSize,
00315                             unsigned ShuffleKind, SelectionDAG &DAG);
00316 
00317     /// isVMRGHShuffleMask - Return true if this is a shuffle mask suitable for
00318     /// a VRGH* instruction with the specified unit size (1,2 or 4 bytes).
00319     bool isVMRGHShuffleMask(ShuffleVectorSDNode *N, unsigned UnitSize,
00320                             unsigned ShuffleKind, SelectionDAG &DAG);
00321 
00322     /// isVSLDOIShuffleMask - If this is a vsldoi shuffle mask, return the
00323     /// shift amount, otherwise return -1.
00324     int isVSLDOIShuffleMask(SDNode *N, unsigned ShuffleKind,
00325                             SelectionDAG &DAG);
00326 
00327     /// isSplatShuffleMask - Return true if the specified VECTOR_SHUFFLE operand
00328     /// specifies a splat of a single element that is suitable for input to
00329     /// VSPLTB/VSPLTH/VSPLTW.
00330     bool isSplatShuffleMask(ShuffleVectorSDNode *N, unsigned EltSize);
00331 
00332     /// isAllNegativeZeroVector - Returns true if all elements of build_vector
00333     /// are -0.0.
00334     bool isAllNegativeZeroVector(SDNode *N);
00335 
00336     /// getVSPLTImmediate - Return the appropriate VSPLT* immediate to splat the
00337     /// specified isSplatShuffleMask VECTOR_SHUFFLE mask.
00338     unsigned getVSPLTImmediate(SDNode *N, unsigned EltSize, SelectionDAG &DAG);
00339 
00340     /// get_VSPLTI_elt - If this is a build_vector of constants which can be
00341     /// formed by using a vspltis[bhw] instruction of the specified element
00342     /// size, return the constant being splatted.  The ByteSize field indicates
00343     /// the number of bytes of each element [124] -> [bhw].
00344     SDValue get_VSPLTI_elt(SDNode *N, unsigned ByteSize, SelectionDAG &DAG);
00345   }
00346 
00347   class PPCSubtarget;
00348   class PPCTargetLowering : public TargetLowering {
00349     const PPCSubtarget &Subtarget;
00350 
00351   public:
00352     explicit PPCTargetLowering(PPCTargetMachine &TM);
00353 
00354     /// getTargetNodeName() - This method returns the name of a target specific
00355     /// DAG node.
00356     const char *getTargetNodeName(unsigned Opcode) const override;
00357 
00358     MVT getScalarShiftAmountTy(EVT LHSTy) const override { return MVT::i32; }
00359 
00360     /// getSetCCResultType - Return the ISD::SETCC ValueType
00361     EVT getSetCCResultType(LLVMContext &Context, EVT VT) const override;
00362 
00363     /// getPreIndexedAddressParts - returns true by value, base pointer and
00364     /// offset pointer and addressing mode by reference if the node's address
00365     /// can be legally represented as pre-indexed load / store address.
00366     bool getPreIndexedAddressParts(SDNode *N, SDValue &Base,
00367                                    SDValue &Offset,
00368                                    ISD::MemIndexedMode &AM,
00369                                    SelectionDAG &DAG) const override;
00370 
00371     /// SelectAddressRegReg - Given the specified addressed, check to see if it
00372     /// can be represented as an indexed [r+r] operation.  Returns false if it
00373     /// can be more efficiently represented with [r+imm].
00374     bool SelectAddressRegReg(SDValue N, SDValue &Base, SDValue &Index,
00375                              SelectionDAG &DAG) const;
00376 
00377     /// SelectAddressRegImm - Returns true if the address N can be represented
00378     /// by a base register plus a signed 16-bit displacement [r+imm], and if it
00379     /// is not better represented as reg+reg.  If Aligned is true, only accept
00380     /// displacements suitable for STD and friends, i.e. multiples of 4.
00381     bool SelectAddressRegImm(SDValue N, SDValue &Disp, SDValue &Base,
00382                              SelectionDAG &DAG, bool Aligned) const;
00383 
00384     /// SelectAddressRegRegOnly - Given the specified addressed, force it to be
00385     /// represented as an indexed [r+r] operation.
00386     bool SelectAddressRegRegOnly(SDValue N, SDValue &Base, SDValue &Index,
00387                                  SelectionDAG &DAG) const;
00388 
00389     Sched::Preference getSchedulingPreference(SDNode *N) const override;
00390 
00391     /// LowerOperation - Provide custom lowering hooks for some operations.
00392     ///
00393     SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
00394 
00395     /// ReplaceNodeResults - Replace the results of node with an illegal result
00396     /// type with new values built out of custom code.
00397     ///
00398     void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results,
00399                             SelectionDAG &DAG) const override;
00400 
00401     SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override;
00402 
00403     unsigned getRegisterByName(const char* RegName, EVT VT) const override;
00404 
00405     void computeKnownBitsForTargetNode(const SDValue Op,
00406                                        APInt &KnownZero,
00407                                        APInt &KnownOne,
00408                                        const SelectionDAG &DAG,
00409                                        unsigned Depth = 0) const override;
00410 
00411     MachineBasicBlock *
00412       EmitInstrWithCustomInserter(MachineInstr *MI,
00413                                   MachineBasicBlock *MBB) const override;
00414     MachineBasicBlock *EmitAtomicBinary(MachineInstr *MI,
00415                                         MachineBasicBlock *MBB, bool is64Bit,
00416                                         unsigned BinOpcode) const;
00417     MachineBasicBlock *EmitPartwordAtomicBinary(MachineInstr *MI,
00418                                                 MachineBasicBlock *MBB,
00419                                             bool is8bit, unsigned Opcode) const;
00420 
00421     MachineBasicBlock *emitEHSjLjSetJmp(MachineInstr *MI,
00422                                         MachineBasicBlock *MBB) const;
00423 
00424     MachineBasicBlock *emitEHSjLjLongJmp(MachineInstr *MI,
00425                                          MachineBasicBlock *MBB) const;
00426 
00427     ConstraintType
00428     getConstraintType(const std::string &Constraint) const override;
00429 
00430     /// Examine constraint string and operand type and determine a weight value.
00431     /// The operand object must already have been set up with the operand type.
00432     ConstraintWeight getSingleConstraintMatchWeight(
00433       AsmOperandInfo &info, const char *constraint) const override;
00434 
00435     std::pair<unsigned, const TargetRegisterClass*>
00436       getRegForInlineAsmConstraint(const std::string &Constraint,
00437                                    MVT VT) const override;
00438 
00439     /// getByValTypeAlignment - Return the desired alignment for ByVal aggregate
00440     /// function arguments in the caller parameter area.  This is the actual
00441     /// alignment, not its logarithm.
00442     unsigned getByValTypeAlignment(Type *Ty) const override;
00443 
00444     /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops
00445     /// vector.  If it is invalid, don't add anything to Ops.
00446     void LowerAsmOperandForConstraint(SDValue Op,
00447                                       std::string &Constraint,
00448                                       std::vector<SDValue> &Ops,
00449                                       SelectionDAG &DAG) const override;
00450 
00451     /// isLegalAddressingMode - Return true if the addressing mode represented
00452     /// by AM is legal for this target, for a load/store of the specified type.
00453     bool isLegalAddressingMode(const AddrMode &AM, Type *Ty) const override;
00454 
00455     /// isLegalICmpImmediate - Return true if the specified immediate is legal
00456     /// icmp immediate, that is the target has icmp instructions which can
00457     /// compare a register against the immediate without having to materialize
00458     /// the immediate into a register.
00459     bool isLegalICmpImmediate(int64_t Imm) const override;
00460 
00461     /// isLegalAddImmediate - Return true if the specified immediate is legal
00462     /// add immediate, that is the target has add instructions which can
00463     /// add a register and the immediate without having to materialize
00464     /// the immediate into a register.
00465     bool isLegalAddImmediate(int64_t Imm) const override;
00466 
00467     /// isTruncateFree - Return true if it's free to truncate a value of
00468     /// type Ty1 to type Ty2. e.g. On PPC it's free to truncate a i64 value in
00469     /// register X1 to i32 by referencing its sub-register R1.
00470     bool isTruncateFree(Type *Ty1, Type *Ty2) const override;
00471     bool isTruncateFree(EVT VT1, EVT VT2) const override;
00472 
00473     /// \brief Returns true if it is beneficial to convert a load of a constant
00474     /// to just the constant itself.
00475     bool shouldConvertConstantLoadToIntImm(const APInt &Imm,
00476                                            Type *Ty) const override;
00477 
00478     bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;
00479 
00480     bool getTgtMemIntrinsic(IntrinsicInfo &Info,
00481                             const CallInst &I,
00482                             unsigned Intrinsic) const override;
00483 
00484     /// getOptimalMemOpType - Returns the target specific optimal type for load
00485     /// and store operations as a result of memset, memcpy, and memmove
00486     /// lowering. If DstAlign is zero that means it's safe to destination
00487     /// alignment can satisfy any constraint. Similarly if SrcAlign is zero it
00488     /// means there isn't a need to check it against alignment requirement,
00489     /// probably because the source does not need to be loaded. If 'IsMemset' is
00490     /// true, that means it's expanding a memset. If 'ZeroMemset' is true, that
00491     /// means it's a memset of zero. 'MemcpyStrSrc' indicates whether the memcpy
00492     /// source is constant so it does not need to be loaded.
00493     /// It returns EVT::Other if the type should be determined using generic
00494     /// target-independent logic.
00495     EVT
00496     getOptimalMemOpType(uint64_t Size, unsigned DstAlign, unsigned SrcAlign,
00497                         bool IsMemset, bool ZeroMemset, bool MemcpyStrSrc,
00498                         MachineFunction &MF) const override;
00499 
00500     /// Is unaligned memory access allowed for the given type, and is it fast
00501     /// relative to software emulation.
00502     bool allowsMisalignedMemoryAccesses(EVT VT,
00503                                         unsigned AddrSpace,
00504                                         unsigned Align = 1,
00505                                         bool *Fast = nullptr) const override;
00506 
00507     /// isFMAFasterThanFMulAndFAdd - Return true if an FMA operation is faster
00508     /// than a pair of fmul and fadd instructions. fmuladd intrinsics will be
00509     /// expanded to FMAs when this method returns true, otherwise fmuladd is
00510     /// expanded to fmul + fadd.
00511     bool isFMAFasterThanFMulAndFAdd(EVT VT) const override;
00512 
00513     // Should we expand the build vector with shuffles?
00514     bool
00515     shouldExpandBuildVectorWithShuffles(EVT VT,
00516                                         unsigned DefinedValues) const override;
00517 
00518     /// createFastISel - This method returns a target-specific FastISel object,
00519     /// or null if the target does not support "fast" instruction selection.
00520     FastISel *createFastISel(FunctionLoweringInfo &FuncInfo,
00521                              const TargetLibraryInfo *LibInfo) const override;
00522 
00523     /// \brief Returns true if an argument of type Ty needs to be passed in a
00524     /// contiguous block of registers in calling convention CallConv.
00525     bool functionArgumentNeedsConsecutiveRegisters(
00526       Type *Ty, CallingConv::ID CallConv, bool isVarArg) const override {
00527       // We support any array type as "consecutive" block in the parameter
00528       // save area.  The element type defines the alignment requirement and
00529       // whether the argument should go in GPRs, FPRs, or VRs if available.
00530       //
00531       // Note that clang uses this capability both to implement the ELFv2
00532       // homogeneous float/vector aggregate ABI, and to avoid having to use
00533       // "byval" when passing aggregates that might fully fit in registers.
00534       return Ty->isArrayTy();
00535     }
00536 
00537   private:
00538     SDValue getFramePointerFrameIndex(SelectionDAG & DAG) const;
00539     SDValue getReturnAddrFrameIndex(SelectionDAG & DAG) const;
00540 
00541     bool
00542     IsEligibleForTailCallOptimization(SDValue Callee,
00543                                       CallingConv::ID CalleeCC,
00544                                       bool isVarArg,
00545                                       const SmallVectorImpl<ISD::InputArg> &Ins,
00546                                       SelectionDAG& DAG) const;
00547 
00548     SDValue EmitTailCallLoadFPAndRetAddr(SelectionDAG & DAG,
00549                                          int SPDiff,
00550                                          SDValue Chain,
00551                                          SDValue &LROpOut,
00552                                          SDValue &FPOpOut,
00553                                          bool isDarwinABI,
00554                                          SDLoc dl) const;
00555 
00556     SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
00557     SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
00558     SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
00559     SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
00560     SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;
00561     SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
00562     SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
00563     SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const;
00564     SDValue LowerINIT_TRAMPOLINE(SDValue Op, SelectionDAG &DAG) const;
00565     SDValue LowerADJUST_TRAMPOLINE(SDValue Op, SelectionDAG &DAG) const;
00566     SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG,
00567                          const PPCSubtarget &Subtarget) const;
00568     SDValue LowerVAARG(SDValue Op, SelectionDAG &DAG,
00569                        const PPCSubtarget &Subtarget) const;
00570     SDValue LowerVACOPY(SDValue Op, SelectionDAG &DAG,
00571                         const PPCSubtarget &Subtarget) const;
00572     SDValue LowerSTACKRESTORE(SDValue Op, SelectionDAG &DAG,
00573                                 const PPCSubtarget &Subtarget) const;
00574     SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG,
00575                                       const PPCSubtarget &Subtarget) const;
00576     SDValue LowerLOAD(SDValue Op, SelectionDAG &DAG) const;
00577     SDValue LowerSTORE(SDValue Op, SelectionDAG &DAG) const;
00578     SDValue LowerTRUNCATE(SDValue Op, SelectionDAG &DAG) const;
00579     SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const;
00580     SDValue LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG, SDLoc dl) const;
00581     SDValue LowerINT_TO_FP(SDValue Op, SelectionDAG &DAG) const;
00582     SDValue LowerFLT_ROUNDS_(SDValue Op, SelectionDAG &DAG) const;
00583     SDValue LowerSHL_PARTS(SDValue Op, SelectionDAG &DAG) const;
00584     SDValue LowerSRL_PARTS(SDValue Op, SelectionDAG &DAG) const;
00585     SDValue LowerSRA_PARTS(SDValue Op, SelectionDAG &DAG) const;
00586     SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const;
00587     SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) const;
00588     SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
00589     SDValue LowerSCALAR_TO_VECTOR(SDValue Op, SelectionDAG &DAG) const;
00590     SDValue LowerSIGN_EXTEND_INREG(SDValue Op, SelectionDAG &DAG) const;
00591     SDValue LowerMUL(SDValue Op, SelectionDAG &DAG) const;
00592 
00593     SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
00594                             CallingConv::ID CallConv, bool isVarArg,
00595                             const SmallVectorImpl<ISD::InputArg> &Ins,
00596                             SDLoc dl, SelectionDAG &DAG,
00597                             SmallVectorImpl<SDValue> &InVals) const;
00598     SDValue FinishCall(CallingConv::ID CallConv, SDLoc dl, bool isTailCall,
00599                        bool isVarArg,
00600                        SelectionDAG &DAG,
00601                        SmallVector<std::pair<unsigned, SDValue>, 8>
00602                          &RegsToPass,
00603                        SDValue InFlag, SDValue Chain,
00604                        SDValue &Callee,
00605                        int SPDiff, unsigned NumBytes,
00606                        const SmallVectorImpl<ISD::InputArg> &Ins,
00607                        SmallVectorImpl<SDValue> &InVals) const;
00608 
00609     SDValue
00610       LowerFormalArguments(SDValue Chain,
00611                            CallingConv::ID CallConv, bool isVarArg,
00612                            const SmallVectorImpl<ISD::InputArg> &Ins,
00613                            SDLoc dl, SelectionDAG &DAG,
00614                            SmallVectorImpl<SDValue> &InVals) const override;
00615 
00616     SDValue
00617       LowerCall(TargetLowering::CallLoweringInfo &CLI,
00618                 SmallVectorImpl<SDValue> &InVals) const override;
00619 
00620     bool
00621       CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,
00622                    bool isVarArg,
00623                    const SmallVectorImpl<ISD::OutputArg> &Outs,
00624                    LLVMContext &Context) const override;
00625 
00626     SDValue
00627       LowerReturn(SDValue Chain,
00628                   CallingConv::ID CallConv, bool isVarArg,
00629                   const SmallVectorImpl<ISD::OutputArg> &Outs,
00630                   const SmallVectorImpl<SDValue> &OutVals,
00631                   SDLoc dl, SelectionDAG &DAG) const override;
00632 
00633     SDValue
00634       extendArgForPPC64(ISD::ArgFlagsTy Flags, EVT ObjectVT, SelectionDAG &DAG,
00635                         SDValue ArgVal, SDLoc dl) const;
00636 
00637     SDValue
00638       LowerFormalArguments_Darwin(SDValue Chain,
00639                                   CallingConv::ID CallConv, bool isVarArg,
00640                                   const SmallVectorImpl<ISD::InputArg> &Ins,
00641                                   SDLoc dl, SelectionDAG &DAG,
00642                                   SmallVectorImpl<SDValue> &InVals) const;
00643     SDValue
00644       LowerFormalArguments_64SVR4(SDValue Chain,
00645                                   CallingConv::ID CallConv, bool isVarArg,
00646                                   const SmallVectorImpl<ISD::InputArg> &Ins,
00647                                   SDLoc dl, SelectionDAG &DAG,
00648                                   SmallVectorImpl<SDValue> &InVals) const;
00649     SDValue
00650       LowerFormalArguments_32SVR4(SDValue Chain,
00651                                   CallingConv::ID CallConv, bool isVarArg,
00652                                   const SmallVectorImpl<ISD::InputArg> &Ins,
00653                                   SDLoc dl, SelectionDAG &DAG,
00654                                   SmallVectorImpl<SDValue> &InVals) const;
00655 
00656     SDValue
00657       createMemcpyOutsideCallSeq(SDValue Arg, SDValue PtrOff,
00658                                  SDValue CallSeqStart, ISD::ArgFlagsTy Flags,
00659                                  SelectionDAG &DAG, SDLoc dl) const;
00660 
00661     SDValue
00662       LowerCall_Darwin(SDValue Chain, SDValue Callee,
00663                        CallingConv::ID CallConv,
00664                        bool isVarArg, bool isTailCall,
00665                        const SmallVectorImpl<ISD::OutputArg> &Outs,
00666                        const SmallVectorImpl<SDValue> &OutVals,
00667                        const SmallVectorImpl<ISD::InputArg> &Ins,
00668                        SDLoc dl, SelectionDAG &DAG,
00669                        SmallVectorImpl<SDValue> &InVals) const;
00670     SDValue
00671       LowerCall_64SVR4(SDValue Chain, SDValue Callee,
00672                        CallingConv::ID CallConv,
00673                        bool isVarArg, bool isTailCall,
00674                        const SmallVectorImpl<ISD::OutputArg> &Outs,
00675                        const SmallVectorImpl<SDValue> &OutVals,
00676                        const SmallVectorImpl<ISD::InputArg> &Ins,
00677                        SDLoc dl, SelectionDAG &DAG,
00678                        SmallVectorImpl<SDValue> &InVals) const;
00679     SDValue
00680     LowerCall_32SVR4(SDValue Chain, SDValue Callee, CallingConv::ID CallConv,
00681                      bool isVarArg, bool isTailCall,
00682                      const SmallVectorImpl<ISD::OutputArg> &Outs,
00683                      const SmallVectorImpl<SDValue> &OutVals,
00684                      const SmallVectorImpl<ISD::InputArg> &Ins,
00685                      SDLoc dl, SelectionDAG &DAG,
00686                      SmallVectorImpl<SDValue> &InVals) const;
00687 
00688     SDValue lowerEH_SJLJ_SETJMP(SDValue Op, SelectionDAG &DAG) const;
00689     SDValue lowerEH_SJLJ_LONGJMP(SDValue Op, SelectionDAG &DAG) const;
00690 
00691     SDValue DAGCombineExtBoolTrunc(SDNode *N, DAGCombinerInfo &DCI) const;
00692     SDValue DAGCombineTruncBoolExt(SDNode *N, DAGCombinerInfo &DCI) const;
00693     SDValue DAGCombineFastRecip(SDValue Op, DAGCombinerInfo &DCI) const;
00694     SDValue DAGCombineFastRecipFSQRT(SDValue Op, DAGCombinerInfo &DCI) const;
00695 
00696     CCAssignFn *useFastISelCCs(unsigned Flag) const;
00697   };
00698 
00699   namespace PPC {
00700     FastISel *createFastISel(FunctionLoweringInfo &FuncInfo,
00701                              const TargetLibraryInfo *LibInfo);
00702   }
00703 
00704   bool CC_PPC32_SVR4_Custom_Dummy(unsigned &ValNo, MVT &ValVT, MVT &LocVT,
00705                                   CCValAssign::LocInfo &LocInfo,
00706                                   ISD::ArgFlagsTy &ArgFlags,
00707                                   CCState &State);
00708 
00709   bool CC_PPC32_SVR4_Custom_AlignArgRegs(unsigned &ValNo, MVT &ValVT,
00710                                          MVT &LocVT,
00711                                          CCValAssign::LocInfo &LocInfo,
00712                                          ISD::ArgFlagsTy &ArgFlags,
00713                                          CCState &State);
00714 
00715   bool CC_PPC32_SVR4_Custom_AlignFPArgRegs(unsigned &ValNo, MVT &ValVT,
00716                                            MVT &LocVT,
00717                                            CCValAssign::LocInfo &LocInfo,
00718                                            ISD::ArgFlagsTy &ArgFlags,
00719                                            CCState &State);
00720 }
00721 
00722 #endif   // LLVM_TARGET_POWERPC_PPC32ISELLOWERING_H