1 | //===-- NVPTXISelDAGToDAG.h - A dag to dag inst selector for NVPTX --------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | // |
9 | // This file defines an instruction selector for the NVPTX target. |
10 | // |
11 | //===----------------------------------------------------------------------===// |
12 | |
13 | #ifndef LLVM_LIB_TARGET_NVPTX_NVPTXISELDAGTODAG_H |
14 | #define LLVM_LIB_TARGET_NVPTX_NVPTXISELDAGTODAG_H |
15 | |
16 | #include "MCTargetDesc/NVPTXBaseInfo.h" |
17 | #include "NVPTX.h" |
18 | #include "NVPTXISelLowering.h" |
19 | #include "NVPTXRegisterInfo.h" |
20 | #include "NVPTXTargetMachine.h" |
21 | #include "llvm/CodeGen/SelectionDAGISel.h" |
22 | #include "llvm/IR/InlineAsm.h" |
23 | #include "llvm/IR/Intrinsics.h" |
24 | #include "llvm/Support/Compiler.h" |
25 | |
26 | namespace llvm { |
27 | |
28 | class LLVM_LIBRARY_VISIBILITY NVPTXDAGToDAGISel : public SelectionDAGISel { |
29 | const NVPTXTargetMachine &TM; |
30 | |
31 | // If true, generate mul.wide from sext and mul |
32 | bool doMulWide; |
33 | |
34 | int getDivF32Level() const; |
35 | bool usePrecSqrtF32() const; |
36 | bool useF32FTZ() const; |
37 | bool allowFMA() const; |
38 | bool allowUnsafeFPMath() const; |
39 | bool doRsqrtOpt() const; |
40 | |
41 | public: |
42 | NVPTXDAGToDAGISel() = delete; |
43 | |
44 | explicit NVPTXDAGToDAGISel(NVPTXTargetMachine &tm, CodeGenOptLevel OptLevel); |
45 | |
46 | bool runOnMachineFunction(MachineFunction &MF) override; |
47 | const NVPTXSubtarget *Subtarget = nullptr; |
48 | |
49 | bool SelectInlineAsmMemoryOperand(const SDValue &Op, |
50 | InlineAsm::ConstraintCode ConstraintID, |
51 | std::vector<SDValue> &OutOps) override; |
52 | |
53 | private: |
54 | // Include the pieces autogenerated from the target description. |
55 | #include "NVPTXGenDAGISel.inc" |
56 | |
57 | void Select(SDNode *N) override; |
58 | bool tryIntrinsicNoChain(SDNode *N); |
59 | bool tryIntrinsicChain(SDNode *N); |
60 | void SelectTexSurfHandle(SDNode *N); |
61 | bool tryLoad(SDNode *N); |
62 | bool tryLoadVector(SDNode *N); |
63 | bool tryLDGLDU(SDNode *N); |
64 | bool tryStore(SDNode *N); |
65 | bool tryStoreVector(SDNode *N); |
66 | bool tryLoadParam(SDNode *N); |
67 | bool tryStoreRetval(SDNode *N); |
68 | bool tryStoreParam(SDNode *N); |
69 | void SelectAddrSpaceCast(SDNode *N); |
70 | bool tryTextureIntrinsic(SDNode *N); |
71 | bool trySurfaceIntrinsic(SDNode *N); |
72 | bool tryBFE(SDNode *N); |
73 | bool tryConstantFP(SDNode *N); |
74 | bool SelectSETP_F16X2(SDNode *N); |
75 | bool SelectSETP_BF16X2(SDNode *N); |
76 | bool (SDNode *N); |
77 | void SelectV2I64toI128(SDNode *N); |
78 | void SelectI128toV2I64(SDNode *N); |
79 | inline SDValue getI32Imm(unsigned Imm, const SDLoc &DL) { |
80 | return CurDAG->getTargetConstant(Val: Imm, DL, VT: MVT::i32); |
81 | } |
82 | |
83 | // Match direct address complex pattern. |
84 | bool SelectDirectAddr(SDValue N, SDValue &Address); |
85 | |
86 | bool SelectADDRri_imp(SDNode *OpNode, SDValue Addr, SDValue &Base, |
87 | SDValue &Offset, MVT mvt); |
88 | bool SelectADDRri(SDNode *OpNode, SDValue Addr, SDValue &Base, |
89 | SDValue &Offset); |
90 | bool SelectADDRri64(SDNode *OpNode, SDValue Addr, SDValue &Base, |
91 | SDValue &Offset); |
92 | bool SelectADDRsi_imp(SDNode *OpNode, SDValue Addr, SDValue &Base, |
93 | SDValue &Offset, MVT mvt); |
94 | bool SelectADDRsi(SDNode *OpNode, SDValue Addr, SDValue &Base, |
95 | SDValue &Offset); |
96 | bool SelectADDRsi64(SDNode *OpNode, SDValue Addr, SDValue &Base, |
97 | SDValue &Offset); |
98 | |
99 | bool ChkMemSDNodeAddressSpace(SDNode *N, unsigned int spN) const; |
100 | |
101 | static unsigned GetConvertOpcode(MVT DestTy, MVT SrcTy, LoadSDNode *N); |
102 | }; |
103 | |
104 | class NVPTXDAGToDAGISelLegacy : public SelectionDAGISelLegacy { |
105 | public: |
106 | static char ID; |
107 | explicit NVPTXDAGToDAGISelLegacy(NVPTXTargetMachine &tm, |
108 | CodeGenOptLevel OptLevel); |
109 | }; |
110 | } // end namespace llvm |
111 | |
112 | #endif |
113 | |