35 #define DEBUG_TYPE "amdgpu-isel" 39 #define GET_GLOBALISEL_IMPL 40 #define AMDGPUSubtarget GCNSubtarget 41 #include "AMDGPUGenGlobalISel.inc" 42 #undef GET_GLOBALISEL_IMPL 43 #undef AMDGPUSubtarget 49 TRI(*STI.getRegisterInfo()), RBI(RBI), TM(TM),
53 #include
"AMDGPUGenGlobalISel.inc" 56 #include
"AMDGPUGenGlobalISel.inc" 64 bool AMDGPUInstructionSelector::selectCOPY(
MachineInstr &
I)
const {
68 I.
setDesc(TII.get(TargetOpcode::COPY));
84 unsigned SubIdx)
const {
93 unsigned ComposedSubIdx = TRI.composeSubRegIndices(MO.
getSubReg(), SubIdx);
96 .addReg(Reg, 0, ComposedSubIdx);
122 bool AMDGPUInstructionSelector::selectG_ADD(
MachineInstr &I)
const {
138 BuildMI(*BB, &I, DL, TII.get(AMDGPU::S_ADD_U32), DstLo)
145 BuildMI(*BB, &I, DL, TII.get(AMDGPU::S_ADDC_U32), DstHi)
165 bool AMDGPUInstructionSelector::selectG_GEP(
MachineInstr &I)
const {
166 return selectG_ADD(I);
169 bool AMDGPUInstructionSelector::selectG_IMPLICIT_DEF(
MachineInstr &I)
const {
178 I.
setDesc(TII.get(TargetOpcode::IMPLICIT_DEF));
182 bool AMDGPUInstructionSelector::selectG_INTRINSIC(
MachineInstr &I,
186 switch (IntrinsicID) {
191 case Intrinsic::amdgcn_cvt_pkrtz:
192 return selectImpl(I, CoverageInfo);
194 case Intrinsic::amdgcn_kernarg_segment_ptr: {
202 std::tie(InputPtrReg, RC)
219 unsigned Reg0,
unsigned Reg1,
unsigned Reg2,
unsigned Reg3,
220 unsigned VM,
bool Compr,
unsigned Enabled,
bool Done) {
223 unsigned Opcode = Done ? AMDGPU::EXP_DONE :
AMDGPU::EXP;
224 return BuildMI(BB, Insert, DL, TII.
get(Opcode))
235 bool AMDGPUInstructionSelector::selectG_INTRINSIC_W_SIDE_EFFECTS(
243 switch (IntrinsicID) {
244 case Intrinsic::amdgcn_exp: {
259 case Intrinsic::amdgcn_exp_compr: {
269 BuildMI(*BB, &I, DL, TII.get(AMDGPU::IMPLICIT_DEF),
Undef);
271 true, Enabled, Done);
280 bool AMDGPUInstructionSelector::selectG_STORE(
MachineInstr &I)
const {
293 Opcode = AMDGPU::FLAT_STORE_DWORD;
296 Opcode = AMDGPU::FLAT_STORE_DWORDX2;
299 Opcode = AMDGPU::FLAT_STORE_DWORDX3;
302 Opcode = AMDGPU::FLAT_STORE_DWORDX4;
322 bool AMDGPUInstructionSelector::selectG_CONSTANT(
MachineInstr &I)
const {
332 }
else if (ImmOp.
isCImm()) {
341 IsSgpr = RB->
getID() == AMDGPU::SGPRRegBankID;
346 Size = TRI.getRegSizeInBits(*RC);
349 if (Size != 32 && Size != 64)
352 unsigned Opcode = IsSgpr ? AMDGPU::S_MOV_B32 : AMDGPU::V_MOV_B32_e32;
361 &AMDGPU::VGPR_32RegClass;
366 BuildMI(*BB, &I, DL, TII.get(Opcode), LoReg)
369 BuildMI(*BB, &I, DL, TII.get(Opcode), HiReg)
373 BuildMI(*BB, &I, DL, TII.get(AMDGPU::REG_SEQUENCE), DstReg)
390 return MI.
getOpcode() == TargetOpcode::G_CONSTANT;
400 if (PtrMI->
getOpcode() != TargetOpcode::G_GEP)
403 GEPInfo GEPInfo(*PtrMI);
405 for (
unsigned i = 1, e = 3; i < e; ++i) {
417 if (OpBank->
getID() == AMDGPU::SGPRRegBankID)
418 GEPInfo.SgprParts.push_back(GEPOp.
getReg());
420 GEPInfo.VgprParts.push_back(GEPOp.
getReg());
424 getAddrModeInfo(*PtrMI, MRI, AddrInfo);
438 if (!Ptr || isa<UndefValue>(Ptr) || isa<Argument>(Ptr) ||
439 isa<Constant>(Ptr) || isa<GlobalValue>(Ptr))
454 switch (BaseOpcode) {
455 case AMDGPU::S_LOAD_DWORD_IMM:
458 return AMDGPU::S_LOAD_DWORDX2_IMM;
460 return AMDGPU::S_LOAD_DWORDX4_IMM;
462 return AMDGPU::S_LOAD_DWORDX8_IMM;
464 return AMDGPU::S_LOAD_DWORDX16_IMM;
467 case AMDGPU::S_LOAD_DWORD_IMM_ci:
470 return AMDGPU::S_LOAD_DWORDX2_IMM_ci;
472 return AMDGPU::S_LOAD_DWORDX4_IMM_ci;
474 return AMDGPU::S_LOAD_DWORDX8_IMM_ci;
476 return AMDGPU::S_LOAD_DWORDX16_IMM_ci;
479 case AMDGPU::S_LOAD_DWORD_SGPR:
482 return AMDGPU::S_LOAD_DWORDX2_SGPR;
484 return AMDGPU::S_LOAD_DWORDX4_SGPR;
486 return AMDGPU::S_LOAD_DWORDX8_SGPR;
488 return AMDGPU::S_LOAD_DWORDX16_SGPR;
496 for (
const GEPInfo &GEPInfo : AddrInfo) {
497 if (!GEPInfo.VgprParts.empty())
503 bool AMDGPUInstructionSelector::selectSMRD(
MachineInstr &I,
516 if (hasVgprParts(AddrInfo))
526 unsigned LoadSize = RBI.getSizeInBits(DstReg, MRI, TRI);
528 if (!AddrInfo.
empty() && AddrInfo[0].SgprParts.
size() == 1) {
530 const GEPInfo &GEPInfo = AddrInfo[0];
532 unsigned PtrReg = GEPInfo.SgprParts[0];
546 Opcode =
getSmrdOpcode(AMDGPU::S_LOAD_DWORD_IMM_ci, LoadSize);
556 unsigned OffsetReg = MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
557 BuildMI(*BB, &I, DL, TII.get(AMDGPU::S_MOV_B32), OffsetReg)
558 .addImm(GEPInfo.Imm);
578 bool AMDGPUInstructionSelector::selectG_LOAD(
MachineInstr &I)
const {
585 unsigned LoadSize = RBI.getSizeInBits(DstReg, MRI, TRI);
590 getAddrModeInfo(I, MRI, AddrInfo);
592 if (selectSMRD(I, AddrInfo)) {
601 Opcode = AMDGPU::FLAT_LOAD_DWORD;
604 Opcode = AMDGPU::FLAT_LOAD_DWORDX2;
625 return selectCOPY(I);
631 return selectImpl(I, CoverageInfo);
632 case TargetOpcode::G_ADD:
633 return selectG_ADD(I);
634 case TargetOpcode::G_BITCAST:
635 return selectCOPY(I);
636 case TargetOpcode::G_CONSTANT:
637 case TargetOpcode::G_FCONSTANT:
638 return selectG_CONSTANT(I);
639 case TargetOpcode::G_GEP:
640 return selectG_GEP(I);
641 case TargetOpcode::G_IMPLICIT_DEF:
642 return selectG_IMPLICIT_DEF(I);
643 case TargetOpcode::G_INTRINSIC:
644 return selectG_INTRINSIC(I, CoverageInfo);
645 case TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS:
646 return selectG_INTRINSIC_W_SIDE_EFFECTS(I, CoverageInfo);
647 case TargetOpcode::G_LOAD:
648 return selectG_LOAD(I);
649 case TargetOpcode::G_STORE:
650 return selectG_STORE(I);
656 AMDGPUInstructionSelector::selectVCSRC(
MachineOperand &Root)
const {
667 AMDGPUInstructionSelector::selectVSRC0(
MachineOperand &Root)
const {
674 AMDGPUInstructionSelector::selectVOP3Mods0(
MachineOperand &Root)
const {
683 AMDGPUInstructionSelector::selectVOP3OMods(
MachineOperand &Root)
const {
692 AMDGPUInstructionSelector::selectVOP3Mods(
MachineOperand &Root)
const {
static MachineInstr * buildEXP(const TargetInstrInfo &TII, MachineInstr *Insert, unsigned Tgt, unsigned Reg0, unsigned Reg1, unsigned Reg2, unsigned Reg3, unsigned VM, bool Compr, unsigned Enabled, bool Done)
constexpr bool isUInt< 32 >(uint64_t x)
void push_back(const T &Elt)
static bool isConstant(const MachineInstr &MI)
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
uint64_t getZExtValue() const
Get zero extended value.
This file declares the targeting of the RegisterBankInfo class for AMDGPU.
unsigned getAddrSpace() const
AMDGPU specific subclass of TargetSubtarget.
static const char * getName()
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Compute iterated dominance frontiers using a linear time algorithm.
iterator_range< mop_iterator > explicit_operands()
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
unsigned getReg() const
getReg - Returns the register number.
static bool isInstrUniform(const MachineInstr &MI)
unsigned getSubReg() const
AMDGPUAS getAMDGPUAS(const Module &M)
LLT getType(unsigned Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register...
const TargetRegisterClass * getConstrainedRegClassForOperand(const MachineOperand &MO, const MachineRegisterInfo &MRI) const override
APInt trunc(unsigned width) const
Truncate to new width.
unsigned const TargetRegisterInfo * TRI
iterator_range< mop_iterator > operands()
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
bool isInternalRead() const
static unsigned getSmrdOpcode(unsigned BaseOpcode, unsigned LoadSize)
static MachineOperand CreateReg(unsigned Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isEarlyClobber=false, unsigned SubReg=0, bool isDebug=false, bool isInternalRead=false, bool isRenamable=false)
static unsigned getAddrSpace(StringRef R)
AMDGPUInstructionSelector(const GCNSubtarget &STI, const AMDGPURegisterBankInfo &RBI, const AMDGPUTargetMachine &TM)
bool isEarlyClobber() const
bool select(MachineInstr &I, CodeGenCoverage &CoverageInfo) const override
Select the (possibly generic) instruction I to only use target-specific opcodes.
Address space for constant memory (VTX2)
A description of a memory reference used in the backend.
This file declares the targeting of the InstructionSelector class for AMDGPU.
const HexagonInstrInfo * TII
const ConstantFP * getFPImm() const
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
bool isSGPRClass(const TargetRegisterClass *RC) const
#define GET_GLOBALISEL_PREDICATES_INIT
static int64_t getConstant(const MachineInstr *MI)
TargetRegisterInfo interface that is implemented by all hw codegen targets.
MachineInstr * getVRegDef(unsigned Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
bool isFPImm() const
isFPImm - Tests if this is a MO_FPImmediate operand.
void ChangeToImmediate(int64_t ImmVal)
ChangeToImmediate - Replace this operand with a new immediate operand of the specified value...
TargetInstrInfo - Interface to description of machine instruction set.
const Value * getValue() const
Return the base address of the memory access.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
int64_t getSMRDEncodedOffset(const MCSubtargetInfo &ST, int64_t ByteOffset)
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
unsigned const MachineRegisterInfo * MRI
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
size_t size() const
size - Get the array size.
bool isCImm() const
isCImm - Test if this is a MO_CImmediate operand.
bool hasOneMemOperand() const
Return true if this instruction has exactly one MachineMemOperand.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
Generation getGeneration() const
const RegisterBank * getRegBankOrNull(unsigned Reg) const
Return the register bank of Reg, or null if Reg has not been assigned a register bank or has been ass...
The AMDGPU TargetMachine interface definition for hw codgen targets.
bool isLegalSMRDImmOffset(const MCSubtargetInfo &ST, int64_t ByteOffset)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVM_READONLY APFloat maxnum(const APFloat &A, const APFloat &B)
Implements IEEE maxNum semantics.
const APFloat & getValueAPF() const
APInt ashr(unsigned ShiftAmt) const
Arithmetic right-shift function.
Address space for 32-bit constant memory.
void setDesc(const MCInstrDesc &tid)
Replace the instruction descriptor (thus opcode) of the current instruction with a new one...
mmo_iterator memoperands_begin() const
Access to memory operands of the instruction.
RegisterBank & getRegBank(unsigned ID)
Get the register bank identified by ID.
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Intrinsic::ID getIntrinsicID() const
unsigned getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
bool constrainSelectedInstRegOperands(MachineInstr &I, const TargetInstrInfo &TII, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI)
Mutate the newly-selected instruction I to constrain its (possibly generic) virtual register operands...
This class implements the register bank concept.
MachineInstr * getUniqueVRegDef(unsigned Reg) const
getUniqueVRegDef - Return the unique machine instr that defines the specified virtual register or nul...
const TargetRegisterClass * getRegClassForReg(const MachineRegisterInfo &MRI, unsigned Reg) const
Class for arbitrary precision integers.
void addImplicitDefUseOperands(MachineFunction &MF)
Add all implicit def and use operands to this instruction.
#define GET_GLOBALISEL_TEMPORARIES_INIT
const MachineBasicBlock * getParent() const
Contains the definition of a TargetInstrInfo class that is common to all AMD GPUs.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
std::pair< const ArgDescriptor *, const TargetRegisterClass * > getPreloadedValue(AMDGPUFunctionArgInfo::PreloadedValue Value) const
Provides the logic to select generic machine instructions.
Provides AMDGPU specific target descriptions.
Representation of each machine instruction.
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
This class keeps track of the SPI_SP_INPUT_ADDR config register, which tells the hardware which inter...
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
static MachineOperand CreateImm(int64_t Val)
static const TargetRegisterClass * constrainGenericRegister(unsigned Reg, const TargetRegisterClass &RC, MachineRegisterInfo &MRI)
Constrain the (possibly generic) virtual register Reg to RC.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isPreISelGenericOpcode(unsigned Opcode)
Check whether the given Opcode is a generic opcode that is not supposed to appear after ISel...
LLVM Value Representation.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
APInt bitcastToAPInt() const
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
unsigned getLiveInVirtReg(unsigned PReg) const
getLiveInVirtReg - If PReg is a live-in physical register, return the corresponding live-in physical ...
const MachineOperand & getOperand(unsigned i) const
const ConstantInt * getCImm() const
LLVM_READONLY APFloat minnum(const APFloat &A, const APFloat &B)
Implements IEEE minNum semantics.
unsigned createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
bool empty() const
empty - Check if the array is empty.
unsigned getID() const
Get the identifier of this register bank.