R600: Add support for global vector stores with elements less than 32-bits
[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 LowerEXTRACT_SUBVECTOR(SDValue Op, SelectionDAG &DAG) const;
32   SDValue LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG) const;
33   SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
34   SDValue LowerUDIVREM(SDValue Op, SelectionDAG &DAG) const;
35
36 protected:
37
38   /// \brief Helper function that adds Reg to the LiveIn list of the DAG's
39   /// MachineFunction.
40   ///
41   /// \returns a RegisterSDNode representing Reg.
42   virtual SDValue CreateLiveInRegister(SelectionDAG &DAG,
43                                        const TargetRegisterClass *RC,
44                                        unsigned Reg, EVT VT) const;
45   SDValue LowerGlobalAddress(AMDGPUMachineFunction *MFI, SDValue Op,
46                              SelectionDAG &DAG) const;
47
48   bool isHWTrueValue(SDValue Op) const;
49   bool isHWFalseValue(SDValue Op) const;
50
51   void AnalyzeFormalArguments(CCState &State,
52                               const SmallVectorImpl<ISD::InputArg> &Ins) const;
53
54   /// \brief Lower vector stores by merging the vector elements into an integer
55   /// of the same bitwidth.
56   SDValue LowerVectorStore(const SDValue &Op, SelectionDAG &DAG) const;
57
58 public:
59   AMDGPUTargetLowering(TargetMachine &TM);
60
61   virtual bool isFAbsFree(EVT VT) const;
62   virtual bool isFNegFree(EVT VT) const;
63   virtual MVT getVectorIdxTy() const;
64   virtual SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv,
65                               bool isVarArg,
66                               const SmallVectorImpl<ISD::OutputArg> &Outs,
67                               const SmallVectorImpl<SDValue> &OutVals,
68                               SDLoc DL, SelectionDAG &DAG) const;
69   virtual SDValue LowerCall(CallLoweringInfo &CLI,
70                             SmallVectorImpl<SDValue> &InVals) const {
71     CLI.Callee.dump();
72     llvm_unreachable("Undefined function");
73   }
74
75   virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const;
76   SDValue LowerIntrinsicIABS(SDValue Op, SelectionDAG &DAG) const;
77   SDValue LowerIntrinsicLRP(SDValue Op, SelectionDAG &DAG) const;
78   SDValue LowerMinMax(SDValue Op, SelectionDAG &DAG) const;
79   virtual const char* getTargetNodeName(unsigned Opcode) const;
80
81   virtual SDNode *PostISelFolding(MachineSDNode *N, SelectionDAG &DAG) const {
82     return N;
83   }
84
85 // Functions defined in AMDILISelLowering.cpp
86 public:
87
88   /// \brief Determine which of the bits specified in \p Mask are known to be
89   /// either zero or one and return them in the \p KnownZero and \p KnownOne
90   /// bitsets.
91   virtual void computeMaskedBitsForTargetNode(const SDValue Op,
92                                               APInt &KnownZero,
93                                               APInt &KnownOne,
94                                               const SelectionDAG &DAG,
95                                               unsigned Depth = 0) const;
96
97   virtual bool getTgtMemIntrinsic(IntrinsicInfo &Info,
98                                   const CallInst &I, unsigned Intrinsic) const;
99
100   /// We want to mark f32/f64 floating point values as legal.
101   bool isFPImmLegal(const APFloat &Imm, EVT VT) const;
102
103   /// We don't want to shrink f64/f32 constants.
104   bool ShouldShrinkFPConstant(EVT VT) const;
105
106 private:
107   void InitAMDILLowering();
108   SDValue LowerSREM(SDValue Op, SelectionDAG &DAG) const;
109   SDValue LowerSREM8(SDValue Op, SelectionDAG &DAG) const;
110   SDValue LowerSREM16(SDValue Op, SelectionDAG &DAG) const;
111   SDValue LowerSREM32(SDValue Op, SelectionDAG &DAG) const;
112   SDValue LowerSREM64(SDValue Op, SelectionDAG &DAG) const;
113   SDValue LowerSDIV(SDValue Op, SelectionDAG &DAG) const;
114   SDValue LowerSDIV24(SDValue Op, SelectionDAG &DAG) const;
115   SDValue LowerSDIV32(SDValue Op, SelectionDAG &DAG) const;
116   SDValue LowerSDIV64(SDValue Op, SelectionDAG &DAG) const;
117   SDValue LowerSIGN_EXTEND_INREG(SDValue Op, SelectionDAG &DAG) const;
118   EVT genIntType(uint32_t size = 32, uint32_t numEle = 1) const;
119   SDValue LowerBRCOND(SDValue Op, SelectionDAG &DAG) const;
120   SDValue LowerFP_ROUND(SDValue Op, SelectionDAG &DAG) const;
121 };
122
123 namespace AMDGPUISD {
124
125 enum {
126   // AMDIL ISD Opcodes
127   FIRST_NUMBER = ISD::BUILTIN_OP_END,
128   CALL,        // Function call based on a single integer
129   UMUL,        // 32bit unsigned multiplication
130   DIV_INF,      // Divide with infinity returned on zero divisor
131   RET_FLAG,
132   BRANCH_COND,
133   // End AMDIL ISD Opcodes
134   DWORDADDR,
135   FRACT,
136   COS_HW,
137   SIN_HW,
138   FMAX,
139   SMAX,
140   UMAX,
141   FMIN,
142   SMIN,
143   UMIN,
144   URECIP,
145   DOT4,
146   TEXTURE_FETCH,
147   EXPORT,
148   CONST_ADDRESS,
149   REGISTER_LOAD,
150   REGISTER_STORE,
151   LOAD_INPUT,
152   SAMPLE,
153   SAMPLEB,
154   SAMPLED,
155   SAMPLEL,
156   FIRST_MEM_OPCODE_NUMBER = ISD::FIRST_TARGET_MEMORY_OPCODE,
157   STORE_MSKOR,
158   LOAD_CONSTANT,
159   LAST_AMDGPU_ISD_NUMBER
160 };
161
162
163 } // End namespace AMDGPUISD
164
165 } // End namespace llvm
166
167 #endif // AMDGPUISELLOWERING_H