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