LLVM 22.0.0git
AMDGPURegBankLegalizeHelper.h
Go to the documentation of this file.
1//===- AMDGPURegBankLegalizeHelper ------------------------------*- C++ -*-===//
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#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUREGBANKLEGALIZEHELPER_H
10#define LLVM_LIB_TARGET_AMDGPU_AMDGPUREGBANKLEGALIZEHELPER_H
11
13#include "llvm/ADT/SmallSet.h"
16
17namespace llvm {
18
20
21namespace AMDGPU {
22
23// Receives list of RegBankLLTMappingApplyID and applies register banks on all
24// operands. It is user's responsibility to provide RegBankLLTMappingApplyIDs
25// for all register operands, there is no need to specify NonReg for trailing
26// imm operands. This finishes selection of register banks if there is no need
27// to replace instruction. In other case InstApplyMethod will create new
28// instruction(s).
30 const GCNSubtarget &ST;
33 const MachineUniformityInfo &MUI;
34 const RegisterBankInfo &RBI;
35 const RegBankLegalizeRules &RBLRules;
36 const bool IsWave32;
37 const RegisterBank *SgprRB;
38 const RegisterBank *VgprRB;
39 const RegisterBank *VccRB;
40
41 static constexpr LLT S1 = LLT::scalar(1);
42 static constexpr LLT S16 = LLT::scalar(16);
43 static constexpr LLT S32 = LLT::scalar(32);
44 static constexpr LLT S64 = LLT::scalar(64);
45 static constexpr LLT S96 = LLT::scalar(96);
46 static constexpr LLT S128 = LLT::scalar(128);
47 static constexpr LLT S256 = LLT::scalar(256);
48
49 static constexpr LLT V2S16 = LLT::fixed_vector(2, 16);
50 static constexpr LLT V4S16 = LLT::fixed_vector(4, 16);
51 static constexpr LLT V6S16 = LLT::fixed_vector(6, 16);
52 static constexpr LLT V8S16 = LLT::fixed_vector(8, 16);
53 static constexpr LLT V16S16 = LLT::fixed_vector(16, 16);
54 static constexpr LLT V32S16 = LLT::fixed_vector(32, 16);
55
56 static constexpr LLT V2S32 = LLT::fixed_vector(2, 32);
57 static constexpr LLT V3S32 = LLT::fixed_vector(3, 32);
58 static constexpr LLT V4S32 = LLT::fixed_vector(4, 32);
59 static constexpr LLT V6S32 = LLT::fixed_vector(6, 32);
60 static constexpr LLT V7S32 = LLT::fixed_vector(7, 32);
61 static constexpr LLT V8S32 = LLT::fixed_vector(8, 32);
62 static constexpr LLT V16S32 = LLT::fixed_vector(16, 32);
63
64 static constexpr LLT V2S64 = LLT::fixed_vector(2, 64);
65 static constexpr LLT V3S64 = LLT::fixed_vector(3, 64);
66 static constexpr LLT V4S64 = LLT::fixed_vector(4, 64);
67 static constexpr LLT V8S64 = LLT::fixed_vector(8, 64);
68 static constexpr LLT V16S64 = LLT::fixed_vector(16, 64);
69
70 static constexpr LLT P1 = LLT::pointer(1, 64);
71 static constexpr LLT P4 = LLT::pointer(4, 64);
72 static constexpr LLT P6 = LLT::pointer(6, 32);
73
74 MachineRegisterInfo::VRegAttrs SgprRB_S32 = {SgprRB, S32};
75 MachineRegisterInfo::VRegAttrs VgprRB_S32 = {VgprRB, S32};
76 MachineRegisterInfo::VRegAttrs VccRB_S1 = {VccRB, S1};
77
78public:
80 const RegisterBankInfo &RBI,
81 const RegBankLegalizeRules &RBLRules);
82
84
85 // Manual apply helpers.
88
89private:
90 bool executeInWaterfallLoop(MachineIRBuilder &B,
92 SmallSet<Register, 4> &SgprOperandRegs);
93
94 LLT getTyFromID(RegBankLLTMappingApplyID ID);
95 LLT getBTyFromID(RegBankLLTMappingApplyID ID, LLT Ty);
96
97 const RegisterBank *getRegBankFromID(RegBankLLTMappingApplyID ID);
98
99 void
100 applyMappingDst(MachineInstr &MI, unsigned &OpIdx,
102
103 void
104 applyMappingSrc(MachineInstr &MI, unsigned &OpIdx,
106 SmallSet<Register, 4> &SgprWaterfallOperandRegs);
107
108 void splitLoad(MachineInstr &MI, ArrayRef<LLT> LLTBreakdown,
109 LLT MergeTy = LLT());
110 void widenLoad(MachineInstr &MI, LLT WideTy, LLT MergeTy = LLT());
111 void widenMMOToS32(GAnyLoad &MI) const;
112
113 void lower(MachineInstr &MI, const RegBankLLTMapping &Mapping,
114 SmallSet<Register, 4> &SgprWaterfallOperandRegs);
115
116 void lowerVccExtToSel(MachineInstr &MI);
117 std::pair<Register, Register> unpackZExt(Register Reg);
118 std::pair<Register, Register> unpackSExt(Register Reg);
119 std::pair<Register, Register> unpackAExt(Register Reg);
120 void lowerUnpackBitShift(MachineInstr &MI);
121 void lowerV_BFE(MachineInstr &MI);
122 void lowerS_BFE(MachineInstr &MI);
123 void lowerSplitTo32(MachineInstr &MI);
124 void lowerSplitTo32Select(MachineInstr &MI);
125 void lowerSplitTo32SExtInReg(MachineInstr &MI);
126};
127
128} // end namespace AMDGPU
129} // end namespace llvm
130
131#endif
Declares convenience wrapper classes for interpreting MachineInstr instances as specific generic oper...
IRTranslator LLVM IR MI
Register Reg
MachineInstr unsigned OpIdx
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
This file defines the SmallSet class.
RegBankLegalizeHelper(MachineIRBuilder &B, const MachineUniformityInfo &MUI, const RegisterBankInfo &RBI, const RegBankLegalizeRules &RBLRules)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
Represents any generic load, including sign/zero extending variants.
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
static constexpr LLT pointer(unsigned AddressSpace, unsigned SizeInBits)
Get a low-level pointer in the given address space.
static constexpr LLT fixed_vector(unsigned NumElements, unsigned ScalarSizeInBits)
Get a low-level fixed-width vector of some number of elements and element width.
Helper class to build MachineInstr.
Representation of each machine instruction.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Holds all the information related to register banks.
This class implements the register bank concept.
Wrapper class representing virtual and physical registers.
Definition Register.h:19
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition SmallSet.h:133
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
A range adaptor for a pair of iterators.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
This is an optimization pass for GlobalISel generic memory operations.
GenericUniformityInfo< MachineSSAContext > MachineUniformityInfo
All attributes(register class or bank and low-level type) a virtual register can have.