R600/SI: Add support for i8 and i16 private loads/stores
[oota-llvm.git] / lib / Target / R600 / AMDGPUISelLowering.h
1 //===-- AMDGPUISelLowering.h - AMDGPU 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 /// \file
11 /// \brief Interface definition of the TargetLowering class that is common
12 /// to all AMD GPUs.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef AMDGPUISELLOWERING_H
17 #define AMDGPUISELLOWERING_H
18
19 #include "llvm/Target/TargetLowering.h"
20
21 namespace llvm {
22
23 class AMDGPUMachineFunction;
24 class MachineRegisterInfo;
25
26 class AMDGPUTargetLowering : public TargetLowering {
27 private:
28   void ExtractVectorElements(SDValue Op, SelectionDAG &DAG,
29                              SmallVectorImpl<SDValue> &Args,
30                              unsigned Start, unsigned Count) const;
31   SDValue LowerFrameIndex(SDValue Op, SelectionDAG &DAG) const;
32   SDValue LowerEXTRACT_SUBVECTOR(SDValue Op, SelectionDAG &DAG) const;
33   SDValue LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG) const;
34   SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
35   /// \brief Lower vector stores by merging the vector elements into an integer
36   /// of the same bitwidth.
37   SDValue MergeVectorStore(const SDValue &Op, SelectionDAG &DAG) const;
38   /// \brief Split a vector store into multiple scalar stores.
39   /// \returns The resulting chain. 
40   SDValue LowerUDIVREM(SDValue Op, SelectionDAG &DAG) const;
41   SDValue LowerUINT_TO_FP(SDValue Op, SelectionDAG &DAG) const;
42
43 protected:
44
45   /// \brief Helper function that adds Reg to the LiveIn list of the DAG's
46   /// MachineFunction.
47   ///
48   /// \returns a RegisterSDNode representing Reg.
49   virtual SDValue CreateLiveInRegister(SelectionDAG &DAG,
50                                        const TargetRegisterClass *RC,
51                                        unsigned Reg, EVT VT) const;
52   SDValue LowerGlobalAddress(AMDGPUMachineFunction *MFI, SDValue Op,
53                              SelectionDAG &DAG) const;
54   /// \brief Split a vector load into multiple scalar loads.
55   SDValue SplitVectorLoad(const SDValue &Op, SelectionDAG &DAG) const;
56   SDValue SplitVectorStore(SDValue Op, SelectionDAG &DAG) const;
57   SDValue LowerLOAD(SDValue Op, SelectionDAG &DAG) const;
58   SDValue LowerSTORE(SDValue Op, SelectionDAG &DAG) const;
59   bool isHWTrueValue(SDValue Op) const;
60   bool isHWFalseValue(SDValue Op) const;
61
62   /// The SelectionDAGBuilder will automatically promote function arguments
63   /// with illegal types.  However, this does not work for the AMDGPU targets
64   /// since the function arguments are stored in memory as these illegal types.
65   /// In order to handle this properly we need to get the origianl types sizes
66   /// from the LLVM IR Function and fixup the ISD:InputArg values before
67   /// passing them to AnalyzeFormalArguments()
68   void getOriginalFunctionArgs(SelectionDAG &DAG,
69                                const Function *F,
70                                const SmallVectorImpl<ISD::InputArg> &Ins,
71                                SmallVectorImpl<ISD::InputArg> &OrigIns) const;
72   void AnalyzeFormalArguments(CCState &State,
73                               const SmallVectorImpl<ISD::InputArg> &Ins) const;
74
75 public:
76   AMDGPUTargetLowering(TargetMachine &TM);
77
78   virtual bool isFAbsFree(EVT VT) const;
79   virtual bool isFNegFree(EVT VT) const;
80   virtual MVT getVectorIdxTy() const;
81   virtual bool isLoadBitCastBeneficial(EVT, EVT) const LLVM_OVERRIDE;
82   virtual SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv,
83                               bool isVarArg,
84                               const SmallVectorImpl<ISD::OutputArg> &Outs,
85                               const SmallVectorImpl<SDValue> &OutVals,
86                               SDLoc DL, SelectionDAG &DAG) const;
87   virtual SDValue LowerCall(CallLoweringInfo &CLI,
88                             SmallVectorImpl<SDValue> &InVals) const {
89     CLI.Callee.dump();
90     llvm_unreachable("Undefined function");
91   }
92
93   virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const;
94   SDValue LowerIntrinsicIABS(SDValue Op, SelectionDAG &DAG) const;
95   SDValue LowerIntrinsicLRP(SDValue Op, SelectionDAG &DAG) const;
96   SDValue LowerMinMax(SDValue Op, SelectionDAG &DAG) const;
97   virtual const char* getTargetNodeName(unsigned Opcode) const;
98
99   virtual SDNode *PostISelFolding(MachineSDNode *N, SelectionDAG &DAG) const {
100     return N;
101   }
102
103 // Functions defined in AMDILISelLowering.cpp
104 public:
105
106   /// \brief Determine which of the bits specified in \p Mask are known to be
107   /// either zero or one and return them in the \p KnownZero and \p KnownOne
108   /// bitsets.
109   virtual void computeMaskedBitsForTargetNode(const SDValue Op,
110                                               APInt &KnownZero,
111                                               APInt &KnownOne,
112                                               const SelectionDAG &DAG,
113                                               unsigned Depth = 0) const;
114
115   virtual bool getTgtMemIntrinsic(IntrinsicInfo &Info,
116                                   const CallInst &I, unsigned Intrinsic) const;
117
118   /// We want to mark f32/f64 floating point values as legal.
119   bool isFPImmLegal(const APFloat &Imm, EVT VT) const;
120
121   /// We don't want to shrink f64/f32 constants.
122   bool ShouldShrinkFPConstant(EVT VT) const;
123
124 private:
125   void InitAMDILLowering();
126   SDValue LowerSREM(SDValue Op, SelectionDAG &DAG) const;
127   SDValue LowerSREM8(SDValue Op, SelectionDAG &DAG) const;
128   SDValue LowerSREM16(SDValue Op, SelectionDAG &DAG) const;
129   SDValue LowerSREM32(SDValue Op, SelectionDAG &DAG) const;
130   SDValue LowerSREM64(SDValue Op, SelectionDAG &DAG) const;
131   SDValue LowerSDIV(SDValue Op, SelectionDAG &DAG) const;
132   SDValue LowerSDIV24(SDValue Op, SelectionDAG &DAG) const;
133   SDValue LowerSDIV32(SDValue Op, SelectionDAG &DAG) const;
134   SDValue LowerSDIV64(SDValue Op, SelectionDAG &DAG) const;
135   SDValue LowerSIGN_EXTEND_INREG(SDValue Op, SelectionDAG &DAG) const;
136   EVT genIntType(uint32_t size = 32, uint32_t numEle = 1) const;
137   SDValue LowerBRCOND(SDValue Op, SelectionDAG &DAG) const;
138   SDValue LowerFP_ROUND(SDValue Op, SelectionDAG &DAG) const;
139 };
140
141 namespace AMDGPUISD {
142
143 enum {
144   // AMDIL ISD Opcodes
145   FIRST_NUMBER = ISD::BUILTIN_OP_END,
146   CALL,        // Function call based on a single integer
147   UMUL,        // 32bit unsigned multiplication
148   DIV_INF,      // Divide with infinity returned on zero divisor
149   RET_FLAG,
150   BRANCH_COND,
151   // End AMDIL ISD Opcodes
152   DWORDADDR,
153   FRACT,
154   COS_HW,
155   SIN_HW,
156   FMAX,
157   SMAX,
158   UMAX,
159   FMIN,
160   SMIN,
161   UMIN,
162   URECIP,
163   DOT4,
164   TEXTURE_FETCH,
165   EXPORT,
166   CONST_ADDRESS,
167   REGISTER_LOAD,
168   REGISTER_STORE,
169   LOAD_INPUT,
170   SAMPLE,
171   SAMPLEB,
172   SAMPLED,
173   SAMPLEL,
174   FIRST_MEM_OPCODE_NUMBER = ISD::FIRST_TARGET_MEMORY_OPCODE,
175   STORE_MSKOR,
176   LOAD_CONSTANT,
177   TBUFFER_STORE_FORMAT,
178   LAST_AMDGPU_ISD_NUMBER
179 };
180
181
182 } // End namespace AMDGPUISD
183
184 } // End namespace llvm
185
186 #endif // AMDGPUISELLOWERING_H