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