1 //===- AMDGPUInstructionSelector --------------------------------*- C++ -*-==//
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
7 //===----------------------------------------------------------------------===//
9 /// This file declares the targeting of the InstructionSelector class for
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUINSTRUCTIONSELECTOR_H
14 #define LLVM_LIB_TARGET_AMDGPU_AMDGPUINSTRUCTIONSELECTOR_H
17 #include "AMDGPUArgumentUsageInfo.h"
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/CodeGen/Register.h"
21 #include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
22 #include "llvm/IR/InstrTypes.h"
25 #define GET_GLOBALISEL_PREDICATE_BITSET
26 #define AMDGPUSubtarget GCNSubtarget
27 #include "AMDGPUGenGlobalISel.inc"
28 #undef GET_GLOBALISEL_PREDICATE_BITSET
29 #undef AMDGPUSubtarget
34 class AMDGPUInstrInfo
;
35 class AMDGPURegisterBankInfo
;
38 class MachineIRBuilder
;
40 class MachineRegisterInfo
;
42 class SIMachineFunctionInfo
;
45 class AMDGPUInstructionSelector
: public InstructionSelector
{
47 AMDGPUInstructionSelector(const GCNSubtarget
&STI
,
48 const AMDGPURegisterBankInfo
&RBI
,
49 const AMDGPUTargetMachine
&TM
);
51 bool select(MachineInstr
&I
) override
;
52 static const char *getName();
56 const MachineInstr
&GEP
;
57 SmallVector
<unsigned, 2> SgprParts
;
58 SmallVector
<unsigned, 2> VgprParts
;
60 GEPInfo(const MachineInstr
&GEP
) : GEP(GEP
), Imm(0) { }
63 bool isInstrUniform(const MachineInstr
&MI
) const;
64 bool isVCC(Register Reg
, const MachineRegisterInfo
&MRI
) const;
66 /// tblgen-erated 'select' implementation.
67 bool selectImpl(MachineInstr
&I
, CodeGenCoverage
&CoverageInfo
) const;
69 MachineOperand
getSubOperand64(MachineOperand
&MO
,
70 const TargetRegisterClass
&SubRC
,
71 unsigned SubIdx
) const;
72 bool selectCOPY(MachineInstr
&I
) const;
73 bool selectPHI(MachineInstr
&I
) const;
74 bool selectG_TRUNC(MachineInstr
&I
) const;
75 bool selectG_SZA_EXT(MachineInstr
&I
) const;
76 bool selectG_CONSTANT(MachineInstr
&I
) const;
77 bool selectG_AND_OR_XOR(MachineInstr
&I
) const;
78 bool selectG_ADD_SUB(MachineInstr
&I
) const;
79 bool selectG_EXTRACT(MachineInstr
&I
) const;
80 bool selectG_MERGE_VALUES(MachineInstr
&I
) const;
81 bool selectG_UNMERGE_VALUES(MachineInstr
&I
) const;
82 bool selectG_GEP(MachineInstr
&I
) const;
83 bool selectG_IMPLICIT_DEF(MachineInstr
&I
) const;
84 bool selectG_INSERT(MachineInstr
&I
) const;
85 bool selectG_INTRINSIC(MachineInstr
&I
) const;
87 std::tuple
<Register
, unsigned, unsigned>
88 splitBufferOffsets(MachineIRBuilder
&B
, Register OrigOffset
) const;
90 bool selectStoreIntrinsic(MachineInstr
&MI
, bool IsFormat
) const;
92 bool selectG_INTRINSIC_W_SIDE_EFFECTS(MachineInstr
&I
) const;
93 int getS_CMPOpcode(CmpInst::Predicate P
, unsigned Size
) const;
94 bool selectG_ICMP(MachineInstr
&I
) const;
95 bool hasVgprParts(ArrayRef
<GEPInfo
> AddrInfo
) const;
96 void getAddrModeInfo(const MachineInstr
&Load
, const MachineRegisterInfo
&MRI
,
97 SmallVectorImpl
<GEPInfo
> &AddrInfo
) const;
98 bool selectSMRD(MachineInstr
&I
, ArrayRef
<GEPInfo
> AddrInfo
) const;
100 void initM0(MachineInstr
&I
) const;
101 bool selectG_LOAD_ATOMICRMW(MachineInstr
&I
) const;
102 bool selectG_STORE(MachineInstr
&I
) const;
103 bool selectG_SELECT(MachineInstr
&I
) const;
104 bool selectG_BRCOND(MachineInstr
&I
) const;
105 bool selectG_FRAME_INDEX(MachineInstr
&I
) const;
106 bool selectG_PTR_MASK(MachineInstr
&I
) const;
108 std::pair
<Register
, unsigned>
109 selectVOP3ModsImpl(Register Src
, const MachineRegisterInfo
&MRI
) const;
111 InstructionSelector::ComplexRendererFns
112 selectVCSRC(MachineOperand
&Root
) const;
114 InstructionSelector::ComplexRendererFns
115 selectVSRC0(MachineOperand
&Root
) const;
117 InstructionSelector::ComplexRendererFns
118 selectVOP3Mods0(MachineOperand
&Root
) const;
119 InstructionSelector::ComplexRendererFns
120 selectVOP3Mods0Clamp0OMod(MachineOperand
&Root
) const;
121 InstructionSelector::ComplexRendererFns
122 selectVOP3OMods(MachineOperand
&Root
) const;
123 InstructionSelector::ComplexRendererFns
124 selectVOP3Mods(MachineOperand
&Root
) const;
126 InstructionSelector::ComplexRendererFns
127 selectVOP3OpSelMods0(MachineOperand
&Root
) const;
128 InstructionSelector::ComplexRendererFns
129 selectVOP3OpSelMods(MachineOperand
&Root
) const;
131 InstructionSelector::ComplexRendererFns
132 selectSmrdImm(MachineOperand
&Root
) const;
133 InstructionSelector::ComplexRendererFns
134 selectSmrdImm32(MachineOperand
&Root
) const;
135 InstructionSelector::ComplexRendererFns
136 selectSmrdSgpr(MachineOperand
&Root
) const;
138 template <bool Signed
>
139 InstructionSelector::ComplexRendererFns
140 selectFlatOffsetImpl(MachineOperand
&Root
) const;
141 InstructionSelector::ComplexRendererFns
142 selectFlatOffset(MachineOperand
&Root
) const;
144 InstructionSelector::ComplexRendererFns
145 selectFlatOffsetSigned(MachineOperand
&Root
) const;
147 InstructionSelector::ComplexRendererFns
148 selectMUBUFScratchOffen(MachineOperand
&Root
) const;
149 InstructionSelector::ComplexRendererFns
150 selectMUBUFScratchOffset(MachineOperand
&Root
) const;
152 bool isDSOffsetLegal(const MachineRegisterInfo
&MRI
,
153 const MachineOperand
&Base
,
154 int64_t Offset
, unsigned OffsetBits
) const;
156 InstructionSelector::ComplexRendererFns
157 selectDS1Addr1Offset(MachineOperand
&Root
) const;
159 const SIInstrInfo
&TII
;
160 const SIRegisterInfo
&TRI
;
161 const AMDGPURegisterBankInfo
&RBI
;
162 const AMDGPUTargetMachine
&TM
;
163 const GCNSubtarget
&STI
;
164 bool EnableLateStructurizeCFG
;
165 #define GET_GLOBALISEL_PREDICATES_DECL
166 #define AMDGPUSubtarget GCNSubtarget
167 #include "AMDGPUGenGlobalISel.inc"
168 #undef GET_GLOBALISEL_PREDICATES_DECL
169 #undef AMDGPUSubtarget
171 #define GET_GLOBALISEL_TEMPORARIES_DECL
172 #include "AMDGPUGenGlobalISel.inc"
173 #undef GET_GLOBALISEL_TEMPORARIES_DECL
176 } // End llvm namespace.