19#include "llvm/IR/IntrinsicsAMDGPU.h"
22using namespace AMDGPU;
23using namespace MIPatternMatch;
25std::pair<Register, unsigned>
30 if (Def->getOpcode() == TargetOpcode::G_CONSTANT) {
36 Offset =
Op.getCImm()->getZExtValue();
42 if (Def->getOpcode() == TargetOpcode::G_ADD) {
46 assert(
MRI.getType(Reg).getScalarSizeInBits() == 32);
47 return std::pair(Reg, 0);
51 return std::pair(Def->getOperand(1).getReg(),
Offset);
55 return std::pair(Def->getOperand(1).getReg(),
Offset);
65 if (Def->getOpcode() == TargetOpcode::G_PTRTOINT) {
70 if (
Base->getOpcode() == TargetOpcode::G_INTTOPTR)
71 return std::pair(
Base->getOperand(1).getReg(),
Offset);
74 return std::pair(
Base->getOperand(0).getReg(),
Offset);
78 return std::pair(Reg, 0);
82 :
MRI(MF.getRegInfo()) {
83 initLaneMaskIntrinsics(MF);
87 return S32S64LaneMask.contains(Reg);
90void IntrinsicLaneMaskAnalyzer::initLaneMaskIntrinsics(
MachineFunction &MF) {
91 for (
auto &
MBB : MF) {
92 for (
auto &
MI :
MBB) {
94 if (GI && GI->
is(Intrinsic::amdgcn_if_break)) {
95 S32S64LaneMask.insert(
MI.getOperand(3).getReg());
96 S32S64LaneMask.insert(
MI.getOperand(0).getReg());
99 if (
MI.getOpcode() == AMDGPU::SI_IF ||
100 MI.getOpcode() == AMDGPU::SI_ELSE) {
101 S32S64LaneMask.insert(
MI.getOperand(0).getReg());
120template <
typename ReadLaneFnTy>
124template <
typename ReadLaneFnTy>
128 ReadLaneFnTy BuildRL) {
130 auto Unmerge =
B.buildUnmerge({VgprRB, UnmergeTy}, VgprSrc);
131 for (
unsigned i = 0; i < Unmerge->getNumOperands() - 1; ++i) {
136template <
typename ReadLaneFnTy>
139 ReadLaneFnTy BuildRL) {
140 LLT Ty =
B.getMRI()->getType(VgprSrc);
143 Register SgprDst =
B.getMRI()->createVirtualRegister({SgprRB, Ty});
144 return BuildRL(
B, SgprDst, VgprSrc).getReg(0);
151 return B.buildMergeLikeInstr({SgprRB, Ty}, SgprDstParts).
getReg(0);
154template <
typename ReadLaneFnTy>
157 ReadLaneFnTy BuildReadLane) {
158 LLT Ty =
B.getMRI()->getType(VgprSrc);
160 BuildReadLane(
B, SgprDst, VgprSrc);
168 B.buildMergeLikeInstr(SgprDst, SgprDstParts).getReg(0);
174 B, SgprDst, VgprSrc, RBI,
176 return B.buildInstr(AMDGPU::G_AMDGPU_READANYLANE, {SgprDst}, {VgprSrc});
183 B, SgprDst, VgprSrc, RBI,
185 return B.buildIntrinsic(Intrinsic::amdgcn_readfirstlane, SgprDst)
unsigned const MachineRegisterInfo * MRI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static LLT getReadAnyLaneSplitTy(LLT Ty)
static Register buildReadLane(MachineIRBuilder &, Register, const RegisterBankInfo &, ReadLaneFnTy)
static void unmergeReadAnyLane(MachineIRBuilder &B, SmallVectorImpl< Register > &SgprDstParts, LLT UnmergeTy, Register VgprSrc, const RegisterBankInfo &RBI, ReadLaneFnTy BuildRL)
Provides AMDGPU specific target descriptions.
This file declares the targeting of the RegisterBankInfo class for AMDGPU.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file defines the DenseSet and SmallDenseSet classes.
Provides analysis for querying information about KnownBits during GISel passes.
Declares convenience wrapper classes for interpreting MachineInstr instances as specific generic oper...
Implement a low-level type suitable for MachineInstr level instruction selection.
Contains matchers for matching SSA Machine Instructions.
This file declares the MachineIRBuilder class.
static unsigned getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
bool isS32S64LaneMask(Register Reg) const
IntrinsicLaneMaskAnalyzer(MachineFunction &MF)
Class for arbitrary precision integers.
This class represents an Operation in the Expression.
bool maskedValueIsZero(Register Val, const APInt &Mask)
Represents a call to an intrinsic.
bool is(Intrinsic::ID ID) const
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
constexpr bool isVector() const
constexpr TypeSize getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
constexpr LLT getElementType() const
Returns the vector's element type. Only valid for vector types.
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.
MachineOperand class - Representation of each machine instruction operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Holds all the information related to register banks.
const RegisterBank & getRegBank(unsigned ID)
Get the register bank identified by ID.
This class implements the register bank concept.
Wrapper class representing virtual and physical registers.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
std::pair< Register, unsigned > getBaseWithConstantOffset(MachineRegisterInfo &MRI, Register Reg, GISelValueTracking *ValueTracking=nullptr, bool CheckNUW=false)
Returns base register and constant offset.
void buildReadAnyLane(MachineIRBuilder &B, Register SgprDst, Register VgprSrc, const RegisterBankInfo &RBI)
void buildReadFirstLane(MachineIRBuilder &B, Register SgprDst, Register VgprSrc, const RegisterBankInfo &RBI)
operand_type_match m_Reg()
UnaryOp_match< SrcTy, TargetOpcode::COPY > m_Copy(SrcTy &&Src)
ConstantMatch< APInt > m_ICst(APInt &Cst)
BinaryOp_match< LHS, RHS, TargetOpcode::G_OR, true > m_GOr(const LHS &L, const RHS &R)
bool mi_match(Reg R, const MachineRegisterInfo &MRI, Pattern &&P)
BinaryOp_match< LHS, RHS, TargetOpcode::G_PTR_ADD, false > m_GPtrAdd(const LHS &L, const RHS &R)
bind_ty< MachineInstr * > m_MInstr(MachineInstr *&MI)
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI MachineInstr * getDefIgnoringCopies(Register Reg, const MachineRegisterInfo &MRI)
Find the def instruction for Reg, folding away any trivial copies.