LLVM  14.0.0git
AMDGPURegisterBankInfo.h
Go to the documentation of this file.
1 //===- AMDGPURegisterBankInfo -----------------------------------*- 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 /// \file
9 /// This file declares the targeting of the RegisterBankInfo class for AMDGPU.
10 /// \todo This should be generated by TableGen.
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUREGISTERBANKINFO_H
14 #define LLVM_LIB_TARGET_AMDGPU_AMDGPUREGISTERBANKINFO_H
15 
16 #include "llvm/ADT/SmallSet.h"
18 #include "llvm/CodeGen/Register.h"
20 
21 #define GET_REGBANK_DECLARATIONS
22 #include "AMDGPUGenRegisterBank.inc"
23 
24 namespace llvm {
25 
26 class LLT;
27 class GCNSubtarget;
28 class MachineIRBuilder;
29 class SIInstrInfo;
30 class SIRegisterInfo;
31 class TargetRegisterInfo;
32 
33 /// This class provides the information for the target register banks.
35 
36 protected:
37 
38 #define GET_TARGET_REGBANK_CLASS
39 #include "AMDGPUGenRegisterBank.inc"
40 };
41 
43 public:
46  const SIInstrInfo *TII;
47 
48  bool buildVCopy(MachineIRBuilder &B, Register DstReg, Register SrcReg) const;
49 
51  SmallSet<Register, 4> &SGPROperandRegs,
54  ArrayRef<unsigned> OpIndices) const;
55 
59  SmallSet<Register, 4> &SGPROperandRegs,
60  MachineRegisterInfo &MRI) const;
61 
65  ArrayRef<unsigned> OpIndices) const;
68  ArrayRef<unsigned> OpIndices) const;
69 
71  unsigned OpIdx) const;
73  const OperandsMapper &OpdMapper,
74  MachineRegisterInfo &MRI) const;
76  const OperandsMapper &OpdMapper,
77  MachineRegisterInfo &MRI) const;
78  bool
80  const OperandsMapper &OpdMapper,
81  MachineRegisterInfo &MRI, int RSrcIdx) const;
82  bool applyMappingSBufferLoad(const OperandsMapper &OpdMapper) const;
83 
84  bool applyMappingBFE(const OperandsMapper &OpdMapper, bool Signed) const;
85 
87  Register Reg) const;
88 
89  std::pair<Register, unsigned>
91 
93  MachineInstr &MI) const;
94 
95  /// See RegisterBankInfo::applyMapping.
96  void applyMappingImpl(const OperandsMapper &OpdMapper) const override;
97 
99  Register Ptr) const;
100 
102  getInstrMappingForLoad(const MachineInstr &MI) const;
103 
105  unsigned Default = AMDGPU::VGPRRegBankID) const;
106 
107  // Return a value mapping for an operand that is required to be an SGPR.
109  const MachineRegisterInfo &MRI,
110  const TargetRegisterInfo &TRI) const;
111 
112  // Return a value mapping for an operand that is required to be a VGPR.
114  const MachineRegisterInfo &MRI,
115  const TargetRegisterInfo &TRI) const;
116 
117  // Return a value mapping for an operand that is required to be a AGPR.
119  const MachineRegisterInfo &MRI,
120  const TargetRegisterInfo &TRI) const;
121 
122  /// Split 64-bit value \p Reg into two 32-bit halves and populate them into \p
123  /// Regs. This appropriately sets the regbank of the new registers.
126  LLT HalfTy,
127  Register Reg) const;
128 
129  template <unsigned NumOps>
130  struct OpRegBankEntry {
131  int8_t RegBanks[NumOps];
132  int16_t Cost;
133  };
134 
135  template <unsigned NumOps>
138  const std::array<unsigned, NumOps> RegSrcOpIdx,
139  ArrayRef<OpRegBankEntry<NumOps>> Table) const;
140 
143  const MachineInstr &MI, const MachineRegisterInfo &MRI) const;
144 
147  const MachineInstr &MI, const MachineRegisterInfo &MRI) const;
148 
149  unsigned getMappingType(const MachineRegisterInfo &MRI,
150  const MachineInstr &MI) const;
151 
152  bool isSALUMapping(const MachineInstr &MI) const;
153 
157  const MachineInstr &MI) const;
158 
160  const MachineInstr &MI,
161  int RsrcIdx) const;
162 
163 public:
165 
166  unsigned copyCost(const RegisterBank &A, const RegisterBank &B,
167  unsigned Size) const override;
168 
169  unsigned getBreakDownCost(const ValueMapping &ValMapping,
170  const RegisterBank *CurBank = nullptr) const override;
171 
173  LLT) const override;
174 
176  getInstrAlternativeMappings(const MachineInstr &MI) const override;
177 
178  const InstructionMapping &
179  getInstrMapping(const MachineInstr &MI) const override;
180 
181 private:
182 
183  bool foldExtractEltToCmpSelect(MachineInstr &MI,
185  const OperandsMapper &OpdMapper) const;
186  bool foldInsertEltToCmpSelect(MachineInstr &MI,
188  const OperandsMapper &OpdMapper) const;
189 };
190 } // End llvm namespace.
191 #endif
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::AMDGPURegisterBankInfo::getSGPROpMapping
const ValueMapping * getSGPROpMapping(Register Reg, const MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI) const
Definition: AMDGPURegisterBankInfo.cpp:3406
Signed
@ Signed
Definition: NVPTXISelLowering.cpp:4636
llvm::AMDGPURegisterBankInfo
Definition: AMDGPURegisterBankInfo.h:42
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:105
llvm::AMDGPURegisterBankInfo::getDefaultMappingAllVGPR
const InstructionMapping & getDefaultMappingAllVGPR(const MachineInstr &MI) const
Definition: AMDGPURegisterBankInfo.cpp:3273
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
Reg
unsigned Reg
Definition: MachineSink.cpp:1566
llvm::MachineRegisterInfo
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Definition: MachineRegisterInfo.h:52
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
RegisterBankInfo.h
llvm::AMDGPURegisterBankInfo::applyMappingImpl
void applyMappingImpl(const OperandsMapper &OpdMapper) const override
See RegisterBankInfo::applyMapping.
Definition: AMDGPURegisterBankInfo.cpp:2136
llvm::AMDGPURegisterBankInfo::AMDGPURegisterBankInfo
AMDGPURegisterBankInfo(const GCNSubtarget &STI)
Definition: AMDGPURegisterBankInfo.cpp:195
MachineBasicBlock.h
llvm::TargetRegisterInfo
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Definition: TargetRegisterInfo.h:233
llvm::AMDGPURegisterBankInfo::getInstrMapping
const InstructionMapping & getInstrMapping(const MachineInstr &MI) const override
This function must return a legal mapping, because AMDGPURegisterBankInfo::getInstrAlternativeMapping...
Definition: AMDGPURegisterBankInfo.cpp:3442
llvm::SmallSet
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition: SmallSet.h:134
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::AMDGPURegisterBankInfo::getVGPROpMapping
const ValueMapping * getVGPROpMapping(Register Reg, const MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI) const
Definition: AMDGPURegisterBankInfo.cpp:3417
llvm::GCNSubtarget
Definition: GCNSubtarget.h:31
llvm::AMDGPURegisterBankInfo::TII
const SIInstrInfo * TII
Definition: AMDGPURegisterBankInfo.h:46
llvm::AMDGPURegisterBankInfo::applyMappingSBufferLoad
bool applyMappingSBufferLoad(const OperandsMapper &OpdMapper) const
Definition: AMDGPURegisterBankInfo.cpp:1416
llvm::AMDGPURegisterBankInfo::TRI
const SIRegisterInfo * TRI
Definition: AMDGPURegisterBankInfo.h:45
llvm::AMDGPURegisterBankInfo::getInstrAlternativeMappingsIntrinsic
RegisterBankInfo::InstructionMappings getInstrAlternativeMappingsIntrinsic(const MachineInstr &MI, const MachineRegisterInfo &MRI) const
Definition: AMDGPURegisterBankInfo.cpp:335
llvm::AMDGPURegisterBankInfo::OpRegBankEntry::Cost
int16_t Cost
Definition: AMDGPURegisterBankInfo.h:132
llvm::AMDGPURegisterBankInfo::copyCost
unsigned copyCost(const RegisterBank &A, const RegisterBank &B, unsigned Size) const override
Get the cost of a copy from B to A, or put differently, get the cost of A = COPY B.
Definition: AMDGPURegisterBankInfo.cpp:219
llvm::AMDGPURegisterBankInfo::OpRegBankEntry::RegBanks
int8_t RegBanks[NumOps]
Definition: AMDGPURegisterBankInfo.h:131
llvm::RegisterBank
This class implements the register bank concept.
Definition: RegisterBank.h:28
llvm::AMDGPURegisterBankInfo::applyMappingLoad
bool applyMappingLoad(MachineInstr &MI, const OperandsMapper &OpdMapper, MachineRegisterInfo &MRI) const
Definition: AMDGPURegisterBankInfo.cpp:1140
llvm::AMDGPURegisterBankInfo::getAGPROpMapping
const ValueMapping * getAGPROpMapping(Register Reg, const MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI) const
Definition: AMDGPURegisterBankInfo.cpp:3425
llvm::AMDGPURegisterBankInfo::addMappingFromTable
InstructionMappings addMappingFromTable(const MachineInstr &MI, const MachineRegisterInfo &MRI, const std::array< unsigned, NumOps > RegSrcOpIdx, ArrayRef< OpRegBankEntry< NumOps >> Table) const
llvm::TargetRegisterClass
Definition: TargetRegisterInfo.h:46
llvm::AMDGPURegisterBankInfo::getValueMappingForPtr
const ValueMapping * getValueMappingForPtr(const MachineRegisterInfo &MRI, Register Ptr) const
Return the mapping for a pointer argument.
Definition: AMDGPURegisterBankInfo.cpp:3336
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::AMDGPURegisterBankInfo::OpRegBankEntry
Definition: AMDGPURegisterBankInfo.h:130
llvm::AMDGPURegisterBankInfo::constrainOpWithReadfirstlane
void constrainOpWithReadfirstlane(MachineInstr &MI, MachineRegisterInfo &MRI, unsigned OpIdx) const
Definition: AMDGPURegisterBankInfo.cpp:1082
llvm::AMDGPURegisterBankInfo::collectWaterfallOperands
bool collectWaterfallOperands(SmallSet< Register, 4 > &SGPROperandRegs, MachineInstr &MI, MachineRegisterInfo &MRI, ArrayRef< unsigned > OpIndices) const
Definition: AMDGPURegisterBankInfo.cpp:1044
llvm::SIRegisterInfo
Definition: SIRegisterInfo.h:30
llvm::AMDGPURegisterBankInfo::getInstrAlternativeMappingsIntrinsicWSideEffects
RegisterBankInfo::InstructionMappings getInstrAlternativeMappingsIntrinsicWSideEffects(const MachineInstr &MI, const MachineRegisterInfo &MRI) const
Definition: AMDGPURegisterBankInfo.cpp:375
llvm::RegisterBankInfo::OperandsMapper
Helper class used to get/create the virtual registers that will be used to replace the MachineOperand...
Definition: RegisterBankInfo.h:280
llvm::AMDGPURegisterBankInfo::splitBufferOffsets
std::pair< Register, unsigned > splitBufferOffsets(MachineIRBuilder &B, Register Offset) const
Definition: AMDGPURegisterBankInfo.cpp:1735
llvm::RegisterBankInfo
Holds all the information related to register banks.
Definition: RegisterBankInfo.h:39
llvm::AMDGPURegisterBankInfo::getRegBankFromRegClass
const RegisterBank & getRegBankFromRegClass(const TargetRegisterClass &RC, LLT) const override
Get a register bank that covers RC.
Definition: AMDGPURegisterBankInfo.cpp:276
llvm::MachineIRBuilder
Helper class to build MachineInstr.
Definition: MachineIRBuilder.h:212
llvm::AMDGPURegisterBankInfo::Subtarget
const GCNSubtarget & Subtarget
Definition: AMDGPURegisterBankInfo.h:44
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:64
llvm::AMDGPURegisterBankInfo::getBreakDownCost
unsigned getBreakDownCost(const ValueMapping &ValMapping, const RegisterBank *CurBank=nullptr) const override
Get the cost of using ValMapping to decompose a register.
Definition: AMDGPURegisterBankInfo.cpp:250
llvm::RegisterBankInfo::InstructionMapping
Helper class that represents how the value of an instruction may be mapped and what is the related co...
Definition: RegisterBankInfo.h:189
llvm::AMDGPURegisterBankInfo::selectStoreIntrinsic
MachineInstr * selectStoreIntrinsic(MachineIRBuilder &B, MachineInstr &MI) const
Definition: AMDGPURegisterBankInfo.cpp:1793
llvm::AMDGPURegisterBankInfo::getMappingType
unsigned getMappingType(const MachineRegisterInfo &MRI, const MachineInstr &MI) const
Definition: AMDGPURegisterBankInfo.cpp:3197
llvm::AMDGPURegisterBankInfo::split64BitValueForMapping
void split64BitValueForMapping(MachineIRBuilder &B, SmallVector< Register, 2 > &Regs, LLT HalfTy, Register Reg) const
Split 64-bit value Reg into two 32-bit halves and populate them into Regs.
Definition: AMDGPURegisterBankInfo.cpp:645
llvm::AMDGPURegisterBankInfo::getDefaultMappingSOP
const InstructionMapping & getDefaultMappingSOP(const MachineInstr &MI) const
Definition: AMDGPURegisterBankInfo.cpp:3231
llvm::AMDGPURegisterBankInfo::applyMappingImage
bool applyMappingImage(MachineInstr &MI, const OperandsMapper &OpdMapper, MachineRegisterInfo &MRI, int RSrcIdx) const
Definition: AMDGPURegisterBankInfo.cpp:1292
llvm::RegisterBankInfo::ValueMapping
Helper struct that represents how a value is mapped through different register banks.
Definition: RegisterBankInfo.h:145
llvm::ArrayRef< unsigned >
llvm::AMDGPURegisterBankInfo::applyMappingDynStackAlloc
bool applyMappingDynStackAlloc(MachineInstr &MI, const OperandsMapper &OpdMapper, MachineRegisterInfo &MRI) const
Definition: AMDGPURegisterBankInfo.cpp:1245
llvm::AMDGPURegisterBankInfo::buildVCopy
bool buildVCopy(MachineIRBuilder &B, Register DstReg, Register SrcReg) const
Definition: AMDGPURegisterBankInfo.cpp:1869
llvm::AMDGPUGenRegisterBankInfo
This class provides the information for the target register banks.
Definition: AMDGPURegisterBankInfo.h:34
MRI
unsigned const MachineRegisterInfo * MRI
Definition: AArch64AdvSIMDScalarPass.cpp:105
llvm::AMDGPURegisterBankInfo::handleD16VData
Register handleD16VData(MachineIRBuilder &B, MachineRegisterInfo &MRI, Register Reg) const
Handle register layout difference for f16 images for some subtargets.
Definition: AMDGPURegisterBankInfo.cpp:1696
llvm::Register
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
llvm::AMDGPURegisterBankInfo::executeInWaterfallLoop
bool executeInWaterfallLoop(MachineIRBuilder &B, iterator_range< MachineBasicBlock::iterator > Range, SmallSet< Register, 4 > &SGPROperandRegs, MachineRegisterInfo &MRI) const
Legalize instruction MI where operands in OpIndices must be SGPRs.
Definition: AMDGPURegisterBankInfo.cpp:705
llvm::AMDGPURegisterBankInfo::applyMappingBFE
bool applyMappingBFE(const OperandsMapper &OpdMapper, bool Signed) const
Definition: AMDGPURegisterBankInfo.cpp:1535
llvm::AMDGPURegisterBankInfo::getInstrMappingForLoad
const RegisterBankInfo::InstructionMapping & getInstrMappingForLoad(const MachineInstr &MI) const
Definition: AMDGPURegisterBankInfo.cpp:3351
llvm::AMDGPURegisterBankInfo::getDefaultMappingVOP
const InstructionMapping & getDefaultMappingVOP(const MachineInstr &MI) const
Definition: AMDGPURegisterBankInfo.cpp:3249
llvm::AMDGPURegisterBankInfo::getInstrAlternativeMappings
InstructionMappings getInstrAlternativeMappings(const MachineInstr &MI) const override
Get the alternative mappings for MI.
Definition: AMDGPURegisterBankInfo.cpp:459
llvm::SIInstrInfo
Definition: SIInstrInfo.h:38
llvm::iterator_range
A range adaptor for a pair of iterators.
Definition: iterator_range.h:30
llvm::AMDGPURegisterBankInfo::isSALUMapping
bool isSALUMapping(const MachineInstr &MI) const
Definition: AMDGPURegisterBankInfo.cpp:3215
llvm::AMDGPURegisterBankInfo::getImageMapping
const InstructionMapping & getImageMapping(const MachineRegisterInfo &MRI, const MachineInstr &MI, int RsrcIdx) const
Definition: AMDGPURegisterBankInfo.cpp:3292
Register.h
llvm::AMDGPURegisterBankInfo::getRegBankID
unsigned getRegBankID(Register Reg, const MachineRegisterInfo &MRI, unsigned Default=AMDGPU::VGPRRegBankID) const
Definition: AMDGPURegisterBankInfo.cpp:3398
SmallSet.h
llvm::LLT
Definition: LowLevelTypeImpl.h:40