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