CellSPU:
[oota-llvm.git] / lib / Target / CellSPU / SPUISelLowering.h
1 //===-- SPUISelLowering.h - Cell SPU DAG Lowering Interface -----*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the interfaces that Cell SPU uses to lower LLVM code into
11 // a selection DAG.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef SPU_ISELLOWERING_H
16 #define SPU_ISELLOWERING_H
17
18 #include "llvm/Target/TargetLowering.h"
19 #include "llvm/CodeGen/SelectionDAG.h"
20 #include "SPU.h"
21
22 namespace llvm {
23   namespace SPUISD {
24     enum NodeType {
25       // Start the numbering where the builting ops and target ops leave off.
26       FIRST_NUMBER = ISD::BUILTIN_OP_END,
27       
28       // Pseudo instructions:
29       RET_FLAG,                 ///< Return with flag, matched by bi instruction
30       
31       Hi,                       ///< High address component (upper 16)
32       Lo,                       ///< Low address component (lower 16)
33       PCRelAddr,                ///< Program counter relative address
34       AFormAddr,                ///< A-form address (local store)
35       IndirectAddr,             ///< D-Form "imm($r)" and X-form "$r($r)"
36
37       LDRESULT,                 ///< Load result (value, chain)
38       CALL,                     ///< CALL instruction
39       SHUFB,                    ///< Vector shuffle (permute)
40       SHUFFLE_MASK,             ///< Shuffle mask
41       CNTB,                     ///< Count leading ones in bytes
42       PROMOTE_SCALAR,           ///< Promote scalar->vector
43       VEC2PREFSLOT,             ///< Extract element 0
44       MPY,                      ///< 16-bit Multiply (low parts of a 32-bit)
45       MPYU,                     ///< Multiply Unsigned
46       MPYH,                     ///< Multiply High
47       MPYHH,                    ///< Multiply High-High
48       SHLQUAD_L_BITS,           ///< Rotate quad left, by bits
49       SHLQUAD_L_BYTES,          ///< Rotate quad left, by bytes
50       VEC_SHL,                  ///< Vector shift left
51       VEC_SRL,                  ///< Vector shift right (logical)
52       VEC_SRA,                  ///< Vector shift right (arithmetic)
53       VEC_ROTL,                 ///< Vector rotate left
54       VEC_ROTR,                 ///< Vector rotate right
55       ROTQUAD_RZ_BYTES,         ///< Rotate quad right, by bytes, zero fill
56       ROTQUAD_RZ_BITS,          ///< Rotate quad right, by bits, zero fill
57       ROTBYTES_LEFT,            ///< Rotate bytes (loads -> ROTQBYI)
58       ROTBYTES_LEFT_BITS,       ///< Rotate bytes left by bit shift count
59       SELECT_MASK,              ///< Select Mask (FSM, FSMB, FSMH, FSMBI)
60       SELB,                     ///< Select bits -> (b & mask) | (a & ~mask)
61       ADD_EXTENDED,             ///< Add extended, with carry
62       CARRY_GENERATE,           ///< Carry generate for ADD_EXTENDED
63       SUB_EXTENDED,             ///< Subtract extended, with borrow
64       BORROW_GENERATE,          ///< Borrow generate for SUB_EXTENDED
65       FPInterp,                 ///< Floating point interpolate
66       FPRecipEst,               ///< Floating point reciprocal estimate
67       SEXT32TO64,               ///< Sign-extended 32-bit const -> 64-bits
68       LAST_SPUISD               ///< Last user-defined instruction
69     };
70   }
71
72   /// Predicates that are used for node matching:
73   namespace SPU {
74     SDValue get_vec_u18imm(SDNode *N, SelectionDAG &DAG,
75                              MVT ValueType);
76     SDValue get_vec_i16imm(SDNode *N, SelectionDAG &DAG,
77                              MVT ValueType);
78     SDValue get_vec_i10imm(SDNode *N, SelectionDAG &DAG,
79                              MVT ValueType);
80     SDValue get_vec_i8imm(SDNode *N, SelectionDAG &DAG,
81                             MVT ValueType);
82     SDValue get_ILHUvec_imm(SDNode *N, SelectionDAG &DAG,
83                               MVT ValueType);
84     SDValue get_v4i32_imm(SDNode *N, SelectionDAG &DAG);
85     SDValue get_v2i64_imm(SDNode *N, SelectionDAG &DAG);
86   }
87
88   class SPUTargetMachine;            // forward dec'l.
89   
90   class SPUTargetLowering :
91     public TargetLowering
92   {
93     int VarArgsFrameIndex;            // FrameIndex for start of varargs area.
94     int ReturnAddrIndex;              // FrameIndex for return slot.
95     SPUTargetMachine &SPUTM;
96
97   public:
98     SPUTargetLowering(SPUTargetMachine &TM);
99     
100     /// getTargetNodeName() - This method returns the name of a target specific
101     /// DAG node.
102     virtual const char *getTargetNodeName(unsigned Opcode) const;
103
104     /// getSetCCResultType - Return the ValueType for ISD::SETCC
105     virtual MVT getSetCCResultType(const SDValue &) const;
106     
107     //! Custom lowering hooks
108     virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG);
109
110     //! Custom lowering hook for nodes with illegal result types.
111     virtual void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results,
112                                     SelectionDAG &DAG);
113
114     virtual SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const;
115
116     virtual void computeMaskedBitsForTargetNode(const SDValue Op,
117                                                 const APInt &Mask,
118                                                 APInt &KnownZero, 
119                                                 APInt &KnownOne,
120                                                 const SelectionDAG &DAG,
121                                                 unsigned Depth = 0) const;
122
123     ConstraintType getConstraintType(const std::string &ConstraintLetter) const;
124
125     std::pair<unsigned, const TargetRegisterClass*> 
126       getRegForInlineAsmConstraint(const std::string &Constraint,
127                                    MVT VT) const;
128
129     void LowerAsmOperandForConstraint(SDValue Op, char ConstraintLetter,
130                                       bool hasMemory, 
131                                       std::vector<SDValue> &Ops,
132                                       SelectionDAG &DAG) const;
133
134     /// isLegalAddressImmediate - Return true if the integer value can be used
135     /// as the offset of the target addressing mode.
136     virtual bool isLegalAddressImmediate(int64_t V, const Type *Ty) const;
137     virtual bool isLegalAddressImmediate(GlobalValue *) const;
138
139     virtual bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const;
140   };
141 }
142
143 #endif