LLVM API Documentation

SPUISelLowering.h

Go to the documentation of this file.
00001 //===-- SPUISelLowering.h - Cell SPU 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 Cell SPU uses to lower LLVM code into
00011 // a selection DAG.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef SPU_ISELLOWERING_H
00016 #define SPU_ISELLOWERING_H
00017 
00018 #include "llvm/Target/TargetLowering.h"
00019 #include "llvm/CodeGen/SelectionDAG.h"
00020 #include "SPU.h"
00021 
00022 namespace llvm {
00023   namespace SPUISD {
00024     enum NodeType {
00025       // Start the numbering where the builting ops and target ops leave off.
00026       FIRST_NUMBER = ISD::BUILTIN_OP_END,
00027 
00028       // Pseudo instructions:
00029       RET_FLAG,                 ///< Return with flag, matched by bi instruction
00030 
00031       Hi,                       ///< High address component (upper 16)
00032       Lo,                       ///< Low address component (lower 16)
00033       PCRelAddr,                ///< Program counter relative address
00034       AFormAddr,                ///< A-form address (local store)
00035       IndirectAddr,             ///< D-Form "imm($r)" and X-form "$r($r)"
00036 
00037       LDRESULT,                 ///< Load result (value, chain)
00038       CALL,                     ///< CALL instruction
00039       SHUFB,                    ///< Vector shuffle (permute)
00040       SHUFFLE_MASK,             ///< Shuffle mask
00041       CNTB,                     ///< Count leading ones in bytes
00042       PREFSLOT2VEC,             ///< Promote scalar->vector
00043       VEC2PREFSLOT,             ///< Extract element 0
00044       SHLQUAD_L_BITS,           ///< Rotate quad left, by bits
00045       SHLQUAD_L_BYTES,          ///< Rotate quad left, by bytes
00046       VEC_SHL,                  ///< Vector shift left
00047       VEC_SRL,                  ///< Vector shift right (logical)
00048       VEC_SRA,                  ///< Vector shift right (arithmetic)
00049       VEC_ROTL,                 ///< Vector rotate left
00050       VEC_ROTR,                 ///< Vector rotate right
00051       ROTBYTES_LEFT,            ///< Rotate bytes (loads -> ROTQBYI)
00052       ROTBYTES_LEFT_BITS,       ///< Rotate bytes left by bit shift count
00053       SELECT_MASK,              ///< Select Mask (FSM, FSMB, FSMH, FSMBI)
00054       SELB,                     ///< Select bits -> (b & mask) | (a & ~mask)
00055       // Markers: These aren't used to generate target-dependent nodes, but
00056       // are used during instruction selection.
00057       ADD64_MARKER,             ///< i64 addition marker
00058       SUB64_MARKER,             ///< i64 subtraction marker
00059       MUL64_MARKER,             ///< i64 multiply marker
00060       LAST_SPUISD               ///< Last user-defined instruction
00061     };
00062   }
00063 
00064   //! Utility functions specific to CellSPU:
00065   namespace SPU {
00066     SDValue get_vec_u18imm(SDNode *N, SelectionDAG &DAG,
00067                              MVT ValueType);
00068     SDValue get_vec_i16imm(SDNode *N, SelectionDAG &DAG,
00069                              MVT ValueType);
00070     SDValue get_vec_i10imm(SDNode *N, SelectionDAG &DAG,
00071                              MVT ValueType);
00072     SDValue get_vec_i8imm(SDNode *N, SelectionDAG &DAG,
00073                             MVT ValueType);
00074     SDValue get_ILHUvec_imm(SDNode *N, SelectionDAG &DAG,
00075                               MVT ValueType);
00076     SDValue get_v4i32_imm(SDNode *N, SelectionDAG &DAG);
00077     SDValue get_v2i64_imm(SDNode *N, SelectionDAG &DAG);
00078 
00079     SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG,
00080                               const SPUTargetMachine &TM);
00081     SDValue LowerSplat_v2i64(MVT OpVT, SelectionDAG &DAG, uint64_t splat);
00082 
00083     SDValue getBorrowGenerateShufMask(SelectionDAG &DAG);
00084     SDValue getCarryGenerateShufMask(SelectionDAG &DAG);
00085   }
00086 
00087   class SPUTargetMachine;            // forward dec'l.
00088 
00089   class SPUTargetLowering :
00090     public TargetLowering
00091   {
00092     int VarArgsFrameIndex;            // FrameIndex for start of varargs area.
00093     int ReturnAddrIndex;              // FrameIndex for return slot.
00094     SPUTargetMachine &SPUTM;
00095 
00096   public:
00097     //! The venerable constructor
00098     /*!
00099      This is where the CellSPU backend sets operation handling (i.e., legal,
00100      custom, expand or promote.)
00101      */
00102     SPUTargetLowering(SPUTargetMachine &TM);
00103 
00104     //! Get the target machine
00105     SPUTargetMachine &getSPUTargetMachine() {
00106       return SPUTM;
00107     }
00108 
00109     /// getTargetNodeName() - This method returns the name of a target specific
00110     /// DAG node.
00111     virtual const char *getTargetNodeName(unsigned Opcode) const;
00112 
00113     /// getSetCCResultType - Return the ValueType for ISD::SETCC
00114     virtual MVT getSetCCResultType(MVT VT) const;
00115 
00116     //! Custom lowering hooks
00117     virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG);
00118 
00119     //! Custom lowering hook for nodes with illegal result types.
00120     virtual void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results,
00121                                     SelectionDAG &DAG);
00122 
00123     virtual SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const;
00124 
00125     virtual void computeMaskedBitsForTargetNode(const SDValue Op,
00126                                                 const APInt &Mask,
00127                                                 APInt &KnownZero,
00128                                                 APInt &KnownOne,
00129                                                 const SelectionDAG &DAG,
00130                                                 unsigned Depth = 0) const;
00131 
00132     virtual unsigned ComputeNumSignBitsForTargetNode(SDValue Op,
00133                                                    unsigned Depth = 0) const;
00134 
00135     ConstraintType getConstraintType(const std::string &ConstraintLetter) const;
00136 
00137     std::pair<unsigned, const TargetRegisterClass*>
00138       getRegForInlineAsmConstraint(const std::string &Constraint,
00139                                    MVT VT) const;
00140 
00141     void LowerAsmOperandForConstraint(SDValue Op, char ConstraintLetter,
00142                                       bool hasMemory,
00143                                       std::vector<SDValue> &Ops,
00144                                       SelectionDAG &DAG) const;
00145 
00146     /// isLegalAddressImmediate - Return true if the integer value can be used
00147     /// as the offset of the target addressing mode.
00148     virtual bool isLegalAddressImmediate(int64_t V, const Type *Ty) const;
00149     virtual bool isLegalAddressImmediate(GlobalValue *) const;
00150 
00151     virtual bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const;
00152   };
00153 }
00154 
00155 #endif