29 #define DEBUG_TYPE "amdgpu-isel"
36 TRI(*STI.getRegisterInfo()), RBI(RBI), AMDGPUASI(STI.
getAMDGPUAS()) {}
40 unsigned SubIdx)
const {
49 unsigned ComposedSubIdx = TRI.composeSubRegIndices(MO.
getSubReg(), SubIdx);
52 .addReg(Reg, 0, ComposedSubIdx);
74 bool AMDGPUInstructionSelector::selectG_ADD(
MachineInstr &
I)
const {
90 BuildMI(*BB, &I, DL, TII.get(AMDGPU::S_ADD_U32), DstLo)
97 BuildMI(*BB, &I, DL, TII.get(AMDGPU::S_ADDC_U32), DstHi)
117 bool AMDGPUInstructionSelector::selectG_GEP(
MachineInstr &I)
const {
118 return selectG_ADD(I);
121 bool AMDGPUInstructionSelector::selectG_STORE(
MachineInstr &I)
const {
142 bool AMDGPUInstructionSelector::selectG_CONSTANT(
MachineInstr &I)
const {
147 unsigned Size = RBI.getSizeInBits(DstReg, MRI, TRI);
150 I.
setDesc(TII.get(AMDGPU::S_MOV_B32));
161 BuildMI(*BB, &I, DL, TII.get(AMDGPU::S_MOV_B32), LoReg)
164 BuildMI(*BB, &I, DL, TII.get(AMDGPU::S_MOV_B32), HiReg)
167 BuildMI(*BB, &I, DL, TII.get(AMDGPU::REG_SEQUENCE), DstReg)
179 return MI.
getOpcode() == TargetOpcode::G_CONSTANT;
189 if (PtrMI->
getOpcode() != TargetOpcode::G_GEP)
192 GEPInfo GEPInfo(*PtrMI);
194 for (
unsigned i = 1, e = 3; i < e; ++i) {
207 GEPInfo.SgprParts.push_back(GEPOp.
getReg());
209 GEPInfo.VgprParts.push_back(GEPOp.
getReg());
213 getAddrModeInfo(*PtrMI, MRI, AddrInfo);
227 if (!Ptr || isa<UndefValue>(Ptr) || isa<Argument>(Ptr) ||
228 isa<Constant>(Ptr) || isa<GlobalValue>(Ptr))
240 switch (BaseOpcode) {
241 case AMDGPU::S_LOAD_DWORD_IMM:
244 return AMDGPU::S_LOAD_DWORDX2_IMM;
246 return AMDGPU::S_LOAD_DWORDX4_IMM;
248 return AMDGPU::S_LOAD_DWORDX8_IMM;
250 return AMDGPU::S_LOAD_DWORDX16_IMM;
253 case AMDGPU::S_LOAD_DWORD_IMM_ci:
256 return AMDGPU::S_LOAD_DWORDX2_IMM_ci;
258 return AMDGPU::S_LOAD_DWORDX4_IMM_ci;
260 return AMDGPU::S_LOAD_DWORDX8_IMM_ci;
262 return AMDGPU::S_LOAD_DWORDX16_IMM_ci;
265 case AMDGPU::S_LOAD_DWORD_SGPR:
268 return AMDGPU::S_LOAD_DWORDX2_SGPR;
270 return AMDGPU::S_LOAD_DWORDX4_SGPR;
272 return AMDGPU::S_LOAD_DWORDX8_SGPR;
274 return AMDGPU::S_LOAD_DWORDX16_SGPR;
282 for (
const GEPInfo &GEPInfo : AddrInfo) {
283 if (!GEPInfo.VgprParts.empty())
289 bool AMDGPUInstructionSelector::selectSMRD(
MachineInstr &I,
301 if (hasVgprParts(AddrInfo))
311 unsigned LoadSize = RBI.getSizeInBits(DstReg, MRI, TRI);
313 if (!AddrInfo.
empty() && AddrInfo[0].SgprParts.
size() == 1) {
315 const GEPInfo &GEPInfo = AddrInfo[0];
317 unsigned PtrReg = GEPInfo.SgprParts[0];
331 Opcode =
getSmrdOpcode(AMDGPU::S_LOAD_DWORD_IMM_ci, LoadSize);
341 unsigned OffsetReg = MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass);
342 BuildMI(*BB, &I, DL, TII.get(AMDGPU::S_MOV_B32), OffsetReg)
343 .addImm(GEPInfo.Imm);
363 bool AMDGPUInstructionSelector::selectG_LOAD(
MachineInstr &I)
const {
370 unsigned LoadSize = RBI.getSizeInBits(DstReg, MRI, TRI);
375 getAddrModeInfo(I, MRI, AddrInfo);
377 if (selectSMRD(I, AddrInfo)) {
386 Opcode = AMDGPU::FLAT_LOAD_DWORD;
389 Opcode = AMDGPU::FLAT_LOAD_DWORDX2;
413 case TargetOpcode::G_ADD:
414 return selectG_ADD(I);
415 case TargetOpcode::G_CONSTANT:
416 return selectG_CONSTANT(I);
417 case TargetOpcode::G_GEP:
418 return selectG_GEP(I);
419 case TargetOpcode::G_LOAD:
420 return selectG_LOAD(I);
421 case TargetOpcode::G_STORE:
422 return selectG_STORE(I);
constexpr bool isUInt< 32 >(uint64_t x)
void push_back(const T &Elt)
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
static bool isConstant(const MachineInstr &MI)
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
This file declares the targeting of the RegisterBankInfo class for AMDGPU.
AMDGPU specific subclass of TargetSubtarget.
uint64_t getZExtValue() const
Get zero extended value.
iterator_range< mop_iterator > explicit_operands()
unsigned createVirtualRegister(const TargetRegisterClass *RegClass)
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
static bool isInstrUniform(const MachineInstr &MI)
AMDGPUAS getAMDGPUAS(const Module &M)
bool constrainSelectedInstRegOperands(MachineInstr &I, const TargetInstrInfo &TII, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI) const
Mutate the newly-selected instruction I to constrain its (possibly generic) virtual register operands...
bool select(MachineInstr &I) const override
Select the (possibly generic) instruction I to only use target-specific opcodes.
static unsigned getSmrdOpcode(unsigned BaseOpcode, unsigned LoadSize)
A description of a memory reference used in the backend.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
This file declares the targeting of the InstructionSelector class for AMDGPU.
const HexagonInstrInfo * TII
const APInt & getValue() const
Return the constant as an APInt value reference.
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 isImm() const
isImm - Tests if this is a MO_Immediate operand.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
bool isReg() const
isReg - Tests if this is a MO_Register operand.
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
Reg
All possible values of the reg field in the ModR/M byte.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
TargetRegisterInfo interface that is implemented by all hw codegen targets.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Generation getGeneration() const
AMDGPUInstructionSelector(const SISubtarget &STI, const AMDGPURegisterBankInfo &RBI)
size_t size() const
size - Get the array size.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineBasicBlock * getParent() const
bool isEarlyClobber() const
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)
unsigned const MachineRegisterInfo * MRI
APInt trunc(unsigned width) const
Truncate to new width.
const MachineOperand & getOperand(unsigned i) const
unsigned getID() const
Get the identifier of this register bank.
APInt ashr(unsigned ShiftAmt) const
Arithmetic right-shift function.
bool hasOneMemOperand() const
Return true if this instruction has exactly one MachineMemOperand.
bool empty() const
empty - Check if the array is empty.
bool isLegalSMRDImmOffset(const MCSubtargetInfo &ST, int64_t ByteOffset)
unsigned getSubReg() const
void setDesc(const MCInstrDesc &tid)
Replace the instruction descriptor (thus opcode) of the current instruction with a new one...
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...
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
This class implements the register bank concept.
const ConstantInt * getCImm() const
Class for arbitrary precision integers.
const Value * getValue() const
Return the base address of the memory access.
static bool isPreISelGenericOpcode(unsigned Opcode)
Check whether the given Opcode is a generic opcode that is not supposed to appear after ISel...
MachineInstr * getUniqueVRegDef(unsigned Reg) const
getUniqueVRegDef - Return the unique machine instr that defines the specified virtual register or nul...
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
llvm_unreachable("Unknown RegBank!")
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.
Provides the logic to select generic machine instructions.
Representation of each machine instruction.
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
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)
static const unsigned CONSTANT_ADDRESS
Address space for constant memory (VTX2)
unsigned getReg() const
getReg - Returns the register number.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
bool isInternalRead() const
mmo_iterator memoperands_begin() const
Access to memory operands of the instruction.