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