20#include "llvm/IR/IntrinsicsAMDGPU.h"
30 if (ScaleDef && ScaleDef->
getOpcode() == AMDGPU::G_AMDGPU_COPY_VCC_SCC)
33 if (!Scale || !Scale->Value.isZero())
41std::pair<Register, unsigned>
46 if (
Def->getOpcode() == TargetOpcode::G_CONSTANT) {
52 Offset =
Op.getCImm()->getZExtValue();
58 if (
Def->getOpcode() == TargetOpcode::G_ADD) {
62 assert(
MRI.getType(Reg).getScalarSizeInBits() == 32);
63 return std::pair(Reg, 0);
67 return std::pair(
Def->getOperand(1).getReg(),
Offset);
71 return std::pair(
Def->getOperand(1).getReg(),
Offset);
82 if (
Def->getOpcode() == TargetOpcode::G_PTRTOINT) {
90 assert(
MRI.getType(Reg).getScalarSizeInBits() == 32);
91 return std::pair(Reg, 0);
94 if (
Base->getOpcode() == TargetOpcode::G_INTTOPTR)
95 return std::pair(
Base->getOperand(1).getReg(),
Offset);
98 return std::pair(
Base->getOperand(0).getReg(),
Offset);
102 return std::pair(Reg, 0);
106 : MRI(MF.getRegInfo()) {
107 initLaneMaskIntrinsics(MF);
111 return S32S64LaneMask.contains(Reg);
114void IntrinsicLaneMaskAnalyzer::initLaneMaskIntrinsics(
MachineFunction &MF) {
115 for (
auto &
MBB : MF) {
116 for (
auto &
MI :
MBB) {
118 if (GI && GI->
is(Intrinsic::amdgcn_if_break)) {
119 S32S64LaneMask.insert(
MI.getOperand(3).getReg());
120 S32S64LaneMask.insert(
MI.getOperand(0).getReg());
123 if (
MI.getOpcode() == AMDGPU::SI_IF ||
124 MI.getOpcode() == AMDGPU::SI_ELSE) {
125 S32S64LaneMask.insert(
MI.getOperand(0).getReg());
144template <
typename ReadLaneFnTy>
146 const RegisterBankInfo &, ReadLaneFnTy);
148template <
typename ReadLaneFnTy>
152 ReadLaneFnTy BuildRL) {
154 auto Unmerge =
B.buildUnmerge({VgprRB, UnmergeTy}, VgprSrc);
155 for (
unsigned i = 0; i < Unmerge->getNumOperands() - 1; ++i) {
160template <
typename ReadLaneFnTy>
163 ReadLaneFnTy BuildRL) {
164 LLT Ty =
B.getMRI()->getType(VgprSrc);
166 if (Ty.getSizeInBits() == 32) {
167 Register SgprDst =
B.getMRI()->createVirtualRegister({SgprRB, Ty});
168 return BuildRL(
B, SgprDst, VgprSrc).getReg(0);
175 return B.buildMergeLikeInstr({SgprRB, Ty}, SgprDstParts).
getReg(0);
178template <
typename ReadLaneFnTy>
181 ReadLaneFnTy BuildReadLane) {
182 LLT Ty =
B.getMRI()->getType(VgprSrc);
183 if (Ty.getSizeInBits() == 32) {
184 BuildReadLane(
B, SgprDst, VgprSrc);
192 B.buildMergeLikeInstr(SgprDst, SgprDstParts).getReg(0);
198 B, SgprDst, VgprSrc, RBI,
200 return B.buildInstr(AMDGPU::G_AMDGPU_READANYLANE, {SgprDst}, {VgprSrc});
207 B, SgprDst, VgprSrc, RBI,
209 return B.buildIntrinsic(Intrinsic::amdgcn_readfirstlane, SgprDst)
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.
Implement a low-level type suitable for MachineInstr level instruction selection.
Implement a low-level type suitable for MachineInstr level instruction selection.
Contains matchers for matching SSA Machine Instructions.
This file declares the MachineIRBuilder class.
Promote Memory to Register
static MCRegister getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
MachineRegisterInfo & MRI
bool isS32S64LaneMask(Register Reg) const
IntrinsicLaneMaskAnalyzer(MachineFunction &MF)
Class for arbitrary precision integers.
bool maskedValueIsZero(Register Val, const APInt &Mask)
Represents a call to an intrinsic.
bool is(Intrinsic::ID ID) const
constexpr TypeSize getSizeInBits() const
Returns the total size of the type. Must only be called on sized 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.
static LLT integer(unsigned SizeInBits)
LLT getElementType() const
Returns the vector's element type. Only valid for vector types.
Helper class to build MachineInstr.
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineOperand & getOperand(unsigned i) const
MachineOperand class - Representation of each machine instruction operand.
Register getReg() const
getReg - Returns the register number.
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.
bool isUnscaledIEEEDivFmas(const MachineInstr &MI, const MachineRegisterInfo &MRI)
Return whether div.fmas can use ordinary FMA without changing denormals.
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)
MIFlagsRef m_MIFlags(uint32_t &Flags)
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.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI const llvm::fltSemantics & getFltSemanticForLLT(LLT Ty)
Get the appropriate floating point arithmetic semantic based on the bit size of the given scalar LLT.
LLVM_ABI MachineInstr * getDefIgnoringCopies(Register Reg, const MachineRegisterInfo &MRI)
Find the def instruction for Reg, folding away any trivial copies.
DWARFExpression::Operation Op
LLVM_ABI std::optional< ValueAndVReg > getIConstantVRegValWithLookThrough(Register VReg, const MachineRegisterInfo &MRI, bool LookThroughInstrs=true)
If VReg is defined by a statically evaluable chain of instructions rooted on a G_CONSTANT returns its...
@ IEEE
IEEE-754 denormal numbers preserved.