8d2e99454555c1d1c5c7de0bada3ed4965c330e3
[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       PREFSLOT2VEC,             ///< 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       GATHER_BITS,              ///< Gather bits from bytes/words/halfwords
62       ADD_EXTENDED,             ///< Add extended, with carry
63       CARRY_GENERATE,           ///< Carry generate for ADD_EXTENDED
64       SUB_EXTENDED,             ///< Subtract extended, with borrow
65       BORROW_GENERATE,          ///< Borrow generate for SUB_EXTENDED
66       FPInterp,                 ///< Floating point interpolate
67       FPRecipEst,               ///< Floating point reciprocal estimate
68       SEXT32TO64,               ///< Sign-extended 32-bit const -> 64-bits
69       LAST_SPUISD               ///< Last user-defined instruction
70     };
71   }
72
73   /// Predicates that are used for node matching:
74   namespace SPU {
75     SDValue get_vec_u18imm(SDNode *N, SelectionDAG &DAG,
76                              MVT ValueType);
77     SDValue get_vec_i16imm(SDNode *N, SelectionDAG &DAG,
78                              MVT ValueType);
79     SDValue get_vec_i10imm(SDNode *N, SelectionDAG &DAG,
80                              MVT ValueType);
81     SDValue get_vec_i8imm(SDNode *N, SelectionDAG &DAG,
82                             MVT ValueType);
83     SDValue get_ILHUvec_imm(SDNode *N, SelectionDAG &DAG,
84                               MVT ValueType);
85     SDValue get_v4i32_imm(SDNode *N, SelectionDAG &DAG);
86     SDValue get_v2i64_imm(SDNode *N, SelectionDAG &DAG);
87   }
88
89   class SPUTargetMachine;            // forward dec'l.
90   
91   class SPUTargetLowering :
92     public TargetLowering
93   {
94     int VarArgsFrameIndex;            // FrameIndex for start of varargs area.
95     int ReturnAddrIndex;              // FrameIndex for return slot.
96     SPUTargetMachine &SPUTM;
97
98   public:
99     SPUTargetLowering(SPUTargetMachine &TM);
100     
101     /// getTargetNodeName() - This method returns the name of a target specific
102     /// DAG node.
103     virtual const char *getTargetNodeName(unsigned Opcode) const;
104
105     /// getSetCCResultType - Return the ValueType for ISD::SETCC
106     virtual MVT getSetCCResultType(const SDValue &) const;
107     
108     //! Custom lowering hooks
109     virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG);
110
111     //! Custom lowering hook for nodes with illegal result types.
112     virtual void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results,
113                                     SelectionDAG &DAG);
114
115     virtual SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const;
116
117     virtual void computeMaskedBitsForTargetNode(const SDValue Op,
118                                                 const APInt &Mask,
119                                                 APInt &KnownZero, 
120                                                 APInt &KnownOne,
121                                                 const SelectionDAG &DAG,
122                                                 unsigned Depth = 0) const;
123
124     virtual unsigned ComputeNumSignBitsForTargetNode(SDValue Op,
125                                                    unsigned Depth = 0) const;
126
127     ConstraintType getConstraintType(const std::string &ConstraintLetter) const;
128
129     std::pair<unsigned, const TargetRegisterClass*> 
130       getRegForInlineAsmConstraint(const std::string &Constraint,
131                                    MVT VT) const;
132
133     void LowerAsmOperandForConstraint(SDValue Op, char ConstraintLetter,
134                                       bool hasMemory, 
135                                       std::vector<SDValue> &Ops,
136                                       SelectionDAG &DAG) const;
137
138     /// isLegalAddressImmediate - Return true if the integer value can be used
139     /// as the offset of the target addressing mode.
140     virtual bool isLegalAddressImmediate(int64_t V, const Type *Ty) const;
141     virtual bool isLegalAddressImmediate(GlobalValue *) const;
142
143     virtual bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const;
144   };
145 }
146
147 #endif