blob: cb6d536479335f8f6193c9ebb18460e9fd6899a3 [file] [log] [blame]
Tom Stellard75aadc22012-12-11 21:25:42 +00001//===-- SIISelLowering.h - SI DAG 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 SI DAG Lowering interface definition
12//
13//===----------------------------------------------------------------------===//
14
Matt Arsenault6b6a2c32016-03-11 08:00:27 +000015#ifndef LLVM_LIB_TARGET_AMDGPU_SIISELLOWERING_H
16#define LLVM_LIB_TARGET_AMDGPU_SIISELLOWERING_H
Tom Stellard75aadc22012-12-11 21:25:42 +000017
18#include "AMDGPUISelLowering.h"
19#include "SIInstrInfo.h"
20
21namespace llvm {
22
Matt Arsenault6b6a2c32016-03-11 08:00:27 +000023class SITargetLowering final : public AMDGPUTargetLowering {
Jan Veselyfea814d2016-06-21 20:46:20 +000024 SDValue LowerParameterPtr(SelectionDAG &DAG, const SDLoc &SL, SDValue Chain,
25 unsigned Offset) const;
26 SDValue LowerParameter(SelectionDAG &DAG, EVT VT, EVT MemVT, const SDLoc &SL,
Matt Arsenaulte1f030c2014-04-11 20:59:54 +000027 SDValue Chain, unsigned Offset, bool Signed) const;
Tom Stellardbf3e6e52016-06-14 20:29:59 +000028 SDValue LowerGlobalAddress(AMDGPUMachineFunction *MFI, SDValue Op,
29 SelectionDAG &DAG) const override;
Matt Arsenaultff6da2f2015-11-30 21:15:45 +000030 SDValue lowerImplicitZextParam(SelectionDAG &DAG, SDValue Op,
31 MVT VT, unsigned Offset) const;
32
Matt Arsenaulta5789bb2014-07-26 06:23:37 +000033 SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
Matt Arsenaulta9dbdca2016-04-12 14:05:04 +000034 SDValue LowerINTRINSIC_W_CHAIN(SDValue Op, SelectionDAG &DAG) const;
Matt Arsenaulta5789bb2014-07-26 06:23:37 +000035 SDValue LowerINTRINSIC_VOID(SDValue Op, SelectionDAG &DAG) const;
Tom Stellard81d871d2013-11-13 23:36:50 +000036 SDValue LowerLOAD(SDValue Op, SelectionDAG &DAG) const;
Tom Stellard0ec134f2014-02-04 17:18:40 +000037 SDValue LowerSELECT(SDValue Op, SelectionDAG &DAG) const;
Matt Arsenaulta1fe17c2016-07-19 23:16:53 +000038 SDValue lowerFastUnsafeFDIV(SDValue Op, SelectionDAG &DAG) const;
39 SDValue lowerFDIV_FAST(SDValue Op, SelectionDAG &DAG) const;
Matt Arsenaulte9fa3b82014-07-15 20:18:31 +000040 SDValue LowerFDIV32(SDValue Op, SelectionDAG &DAG) const;
41 SDValue LowerFDIV64(SDValue Op, SelectionDAG &DAG) const;
42 SDValue LowerFDIV(SDValue Op, SelectionDAG &DAG) const;
Matt Arsenaultf7c95e32014-10-03 23:54:41 +000043 SDValue LowerINT_TO_FP(SDValue Op, SelectionDAG &DAG, bool Signed) const;
Tom Stellard81d871d2013-11-13 23:36:50 +000044 SDValue LowerSTORE(SDValue Op, SelectionDAG &DAG) const;
Matt Arsenaultad14ce82014-07-19 18:44:39 +000045 SDValue LowerTrig(SDValue Op, SelectionDAG &DAG) const;
Tom Stellard354a43c2016-04-01 18:27:37 +000046 SDValue LowerATOMIC_CMP_SWAP(SDValue Op, SelectionDAG &DAG) const;
Tom Stellardf8794352012-12-19 22:10:31 +000047 SDValue LowerBRCOND(SDValue Op, SelectionDAG &DAG) const;
Tom Stellard75aadc22012-12-11 21:25:42 +000048
Konstantin Zhuravlyovf86e4b72016-11-13 07:01:11 +000049 /// \brief Converts \p Op, which must be of floating point type, to the
50 /// floating point type \p VT, by either extending or truncating it.
51 SDValue getFPExtOrFPTrunc(SelectionDAG &DAG,
52 SDValue Op,
53 const SDLoc &DL,
54 EVT VT) const;
55
Konstantin Zhuravlyovd709efb2016-11-17 04:28:37 +000056 /// \brief Custom lowering for ISD::FP_ROUND for MVT::f16.
57 SDValue lowerFP_ROUND(SDValue Op, SelectionDAG &DAG) const;
58
Matt Arsenault99c14522016-04-25 19:27:24 +000059 SDValue getSegmentAperture(unsigned AS, SelectionDAG &DAG) const;
60 SDValue lowerADDRSPACECAST(SDValue Op, SelectionDAG &DAG) const;
Matt Arsenault0bb294b2016-06-17 22:27:03 +000061 SDValue lowerTRAP(SDValue Op, SelectionDAG &DAG) const;
Matt Arsenault99c14522016-04-25 19:27:24 +000062
Christian Konig8e06e2a2013-04-10 08:39:08 +000063 void adjustWritemask(MachineSDNode *&N, SelectionDAG &DAG) const;
64
Matt Arsenaulte6986632015-01-14 01:35:22 +000065 SDValue performUCharToFloatCombine(SDNode *N,
66 DAGCombinerInfo &DCI) const;
Matt Arsenaultb2baffa2014-08-15 17:49:05 +000067 SDValue performSHLPtrCombine(SDNode *N,
68 unsigned AS,
69 DAGCombinerInfo &DCI) const;
Matt Arsenaultfa5f7672016-09-14 15:19:03 +000070
71 SDValue splitBinaryBitConstantOp(DAGCombinerInfo &DCI, const SDLoc &SL,
72 unsigned Opc, SDValue LHS,
73 const ConstantSDNode *CRHS) const;
74
Matt Arsenaultd0101a22015-01-06 23:00:46 +000075 SDValue performAndCombine(SDNode *N, DAGCombinerInfo &DCI) const;
Matt Arsenaultf2290332015-01-06 23:00:39 +000076 SDValue performOrCombine(SDNode *N, DAGCombinerInfo &DCI) const;
Matt Arsenaultfa5f7672016-09-14 15:19:03 +000077 SDValue performXorCombine(SDNode *N, DAGCombinerInfo &DCI) const;
Matt Arsenaultf2290332015-01-06 23:00:39 +000078 SDValue performClassCombine(SDNode *N, DAGCombinerInfo &DCI) const;
Matt Arsenault9cd90712016-04-14 01:42:16 +000079 SDValue performFCanonicalizeCombine(SDNode *N, DAGCombinerInfo &DCI) const;
Matt Arsenault364a6742014-06-11 17:50:44 +000080
Matt Arsenaultf639c322016-01-28 20:53:42 +000081 SDValue performMinMaxCombine(SDNode *N, DAGCombinerInfo &DCI) const;
82
Matt Arsenault6f6233d2015-01-06 23:00:41 +000083 SDValue performSetCCCombine(SDNode *N, DAGCombinerInfo &DCI) const;
Matt Arsenaultcc3c2b32014-11-14 20:08:52 +000084
Tom Stellard70580f82015-07-20 14:28:41 +000085 bool isLegalFlatAddressingMode(const AddrMode &AM) const;
Matt Arsenault711b3902015-08-07 20:18:34 +000086 bool isLegalMUBUFAddressingMode(const AddrMode &AM) const;
Tom Stellardbc4497b2016-02-12 23:45:29 +000087
88 bool isCFIntrinsic(const SDNode *Intr) const;
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +000089
90 void createDebuggerPrologueStackObjects(MachineFunction &MF) const;
Konstantin Zhuravlyov08326b62016-10-20 18:12:38 +000091
92 /// \returns True if fixup needs to be emitted for given global value \p GV,
93 /// false otherwise.
94 bool shouldEmitFixup(const GlobalValue *GV) const;
95
96 /// \returns True if GOT relocation needs to be emitted for given global value
97 /// \p GV, false otherwise.
98 bool shouldEmitGOTReloc(const GlobalValue *GV) const;
99
100 /// \returns True if PC-relative relocation needs to be emitted for given
101 /// global value \p GV, false otherwise.
102 bool shouldEmitPCReloc(const GlobalValue *GV) const;
103
Tom Stellard75aadc22012-12-11 21:25:42 +0000104public:
Matt Arsenault43e92fe2016-06-24 06:30:11 +0000105 SITargetLowering(const TargetMachine &tm, const SISubtarget &STI);
106
107 const SISubtarget *getSubtarget() const;
Matt Arsenault5015a892014-08-15 17:17:07 +0000108
Matt Arsenaulta9dbdca2016-04-12 14:05:04 +0000109 bool getTgtMemIntrinsic(IntrinsicInfo &, const CallInst &,
110 unsigned IntrinsicID) const override;
111
Matt Arsenaulte306a322014-10-21 16:25:08 +0000112 bool isShuffleMaskLegal(const SmallVectorImpl<int> &/*Mask*/,
113 EVT /*VT*/) const override;
114
Mehdi Amini0cdec1e2015-07-09 02:09:40 +0000115 bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty,
116 unsigned AS) const override;
Matt Arsenault5015a892014-08-15 17:17:07 +0000117
Matt Arsenault6f2a5262014-07-27 17:46:40 +0000118 bool allowsMisalignedMemoryAccesses(EVT VT, unsigned AS,
119 unsigned Align,
120 bool *IsFast) const override;
Chandler Carruth9d010ff2014-07-03 00:23:43 +0000121
Matt Arsenault46645fa2014-07-28 17:49:26 +0000122 EVT getOptimalMemOpType(uint64_t Size, unsigned DstAlign,
123 unsigned SrcAlign, bool IsMemset,
124 bool ZeroMemset,
125 bool MemcpyStrSrc,
126 MachineFunction &MF) const override;
127
Tom Stellarda6f24c62015-12-15 20:55:55 +0000128 bool isMemOpUniform(const SDNode *N) const;
Alexander Timofeev18009562016-12-08 17:28:47 +0000129 bool isMemOpHasNoClobberedMemOperand(const SDNode *N) const;
Matt Arsenaultf9bfeaf2015-12-01 23:04:00 +0000130 bool isNoopAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const override;
Matt Arsenaultd4da0ed2016-12-02 18:12:53 +0000131 bool isCheapAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const override;
Matt Arsenaultf9bfeaf2015-12-01 23:04:00 +0000132
Chandler Carruth9d010ff2014-07-03 00:23:43 +0000133 TargetLoweringBase::LegalizeTypeAction
134 getPreferredVectorAction(EVT VT) const override;
Christian Konig2c8f6d52013-03-07 09:03:52 +0000135
Craig Topper5656db42014-04-29 07:57:24 +0000136 bool shouldConvertConstantLoadToIntImm(const APInt &Imm,
137 Type *Ty) const override;
Matt Arsenaultd7bdcc42014-03-31 19:54:27 +0000138
Tom Stellard2e045bb2016-01-20 00:13:22 +0000139 bool isTypeDesirableForOp(unsigned Op, EVT VT) const override;
140
Tom Stellardb164a982016-06-25 01:59:16 +0000141 bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;
142
Christian Konig2c8f6d52013-03-07 09:03:52 +0000143 SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv,
144 bool isVarArg,
145 const SmallVectorImpl<ISD::InputArg> &Ins,
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000146 const SDLoc &DL, SelectionDAG &DAG,
Craig Topper5656db42014-04-29 07:57:24 +0000147 SmallVectorImpl<SDValue> &InVals) const override;
Christian Konig2c8f6d52013-03-07 09:03:52 +0000148
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000149 SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
Marek Olsak8a0f3352016-01-13 17:23:04 +0000150 const SmallVectorImpl<ISD::OutputArg> &Outs,
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000151 const SmallVectorImpl<SDValue> &OutVals, const SDLoc &DL,
152 SelectionDAG &DAG) const override;
Marek Olsak8a0f3352016-01-13 17:23:04 +0000153
Matt Arsenault9a10cea2016-01-26 04:29:24 +0000154 unsigned getRegisterByName(const char* RegName, EVT VT,
155 SelectionDAG &DAG) const override;
156
Matt Arsenault786724a2016-07-12 21:41:32 +0000157 MachineBasicBlock *splitKillBlock(MachineInstr &MI,
158 MachineBasicBlock *BB) const;
159
Duncan P. N. Exon Smithe4f5e4f2016-06-30 22:52:52 +0000160 MachineBasicBlock *
161 EmitInstrWithCustomInserter(MachineInstr &MI,
162 MachineBasicBlock *BB) const override;
Matt Arsenault423bf3f2015-01-29 19:34:32 +0000163 bool enableAggressiveFMAFusion(EVT VT) const override;
Mehdi Amini44ede332015-07-09 02:09:04 +0000164 EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,
165 EVT VT) const override;
Mehdi Aminieaabc512015-07-09 15:12:23 +0000166 MVT getScalarShiftAmountTy(const DataLayout &, EVT) const override;
Craig Topper5656db42014-04-29 07:57:24 +0000167 bool isFMAFasterThanFMulAndFAdd(EVT VT) const override;
168 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
169 SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override;
170 SDNode *PostISelFolding(MachineSDNode *N, SelectionDAG &DAG) const override;
Duncan P. N. Exon Smithe4f5e4f2016-06-30 22:52:52 +0000171 void AdjustInstrPostInstrSelection(MachineInstr &MI,
Craig Topper5656db42014-04-29 07:57:24 +0000172 SDNode *Node) const override;
Christian Konigf82901a2013-02-26 17:52:23 +0000173
Tom Stellard94593ee2013-06-03 17:40:18 +0000174 SDValue CreateLiveInRegister(SelectionDAG &DAG, const TargetRegisterClass *RC,
Craig Topper5656db42014-04-29 07:57:24 +0000175 unsigned Reg, EVT VT) const override;
Tom Stellard3457a842014-10-09 19:06:00 +0000176 void legalizeTargetIndependentNode(SDNode *Node, SelectionDAG &DAG) const;
Matt Arsenault485defe2014-11-05 19:01:17 +0000177
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000178 MachineSDNode *wrapAddr64Rsrc(SelectionDAG &DAG, const SDLoc &DL,
179 SDValue Ptr) const;
180 MachineSDNode *buildRSRC(SelectionDAG &DAG, const SDLoc &DL, SDValue Ptr,
181 uint32_t RsrcDword1, uint64_t RsrcDword2And3) const;
Benjamin Kramer9bfb6272015-07-05 19:29:18 +0000182 std::pair<unsigned, const TargetRegisterClass *>
183 getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
184 StringRef Constraint, MVT VT) const override;
Tom Stellardb3c3bda2015-12-10 02:12:53 +0000185 ConstraintType getConstraintType(StringRef Constraint) const override;
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000186 SDValue copyToM0(SelectionDAG &DAG, SDValue Chain, const SDLoc &DL,
187 SDValue V) const;
Tom Stellard75aadc22012-12-11 21:25:42 +0000188};
189
190} // End namespace llvm
191
Benjamin Kramera7c40ef2014-08-13 16:26:38 +0000192#endif