29#define DEBUG_TYPE "amdgpu-reg-bank-select"
45 return "AMDGPU Register Bank Select";
65 "AMDGPU Register Bank Select",
false,
false)
72char AMDGPURegBankSelectLegacy::ID = 0;
77 return new AMDGPURegBankSelectLegacy();
95 : B(B), MRI(*B.getMRI()), ILMA(ILMA), MUI(MUI), TRI(TRI),
96 SgprRB(&RBI.getRegBank(
AMDGPU::SGPRRegBankID)),
97 VgprRB(&RBI.getRegBank(
AMDGPU::VGPRRegBankID)),
98 VccRB(&RBI.getRegBank(
AMDGPU::VCCRegBankID)) {}
108 if (!
MI->isCopy() ||
MI->getNumImplicitOperands() != 1)
111 return MI->implicit_operands().begin()->getReg() == TRI.getExec();
116 (MUI.isUniformAtDef(Reg) || ILMA.isS32S64LaneMask(Reg)))
138 LLT Ty = MRI.getType(Reg);
139 Register NewReg = MRI.createVirtualRegister({RB, Ty});
142 auto &
MBB = *
MI.getParent();
143 B.setInsertPt(
MBB,
MBB.SkipPHIsAndLabels(std::next(
MI.getIterator())));
144 B.buildCopy(Reg, NewReg);
157 if (
UseMI.isPreISelOpcode()) {
159 if (
Op.isReg() &&
Op.getReg() == Reg)
174 LLT Ty = MRI.getType(Reg);
175 Register NewReg = MRI.createVirtualRegister({RB, Ty});
179 auto DefMI = MRI.getVRegDef(Reg)->getIterator();
186 B.buildCopy(NewReg, Reg);
196 if (!
Reg.isVirtual())
216 B.setCSEInfo(&CSEInfo);
217 B.setChangeObserver(Observer);
226 *ST.getRegBankInfo());
241 MRI.
setRegBank(DefReg, *RBSHelper.getRegBankToAssign(DefReg));
245 if (!
MI.isPreISelOpcode())
263 const RegisterBank *RB = RBSHelper.getRegBankToAssign(DefReg);
265 RBSHelper.reAssignRegBankOnDef(
MI, DefOP, RB);
286 RBSHelper.constrainRegBankUse(
MI, UseOP, RB);
294bool AMDGPURegBankSelectLegacy::runOnMachineFunction(
MachineFunction &MF) {
298 GISelCSEAnalysisWrapper &
Wrapper =
299 getAnalysis<GISelCSEAnalysisWrapperPass>().getCSEWrapper();
300 return &
Wrapper.get(getAnalysis<TargetPassConfig>().getCSEConfig());
303 return &getAnalysis<MachineUniformityAnalysisPass>()
304 .getUniformityInfo();
MachineInstrBuilder & UseMI
MachineInstrBuilder MachineInstrBuilder & DefMI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
amdgpu aa AMDGPU Address space based Alias Analysis Wrapper
static bool runRegBankSelect(MachineFunction &MF, function_ref< GISelCSEInfo *()> GetCSEInfo, function_ref< const MachineUniformityInfo *()> GetMUI)
static Register getVReg(MachineOperand &Op)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Provides analysis for continuously CSEing during GISel passes.
This file implements a version of MachineIRBuilder which CSEs insts within a MachineBasicBlock.
AMD GCN specific subclass of TargetSubtarget.
static Register UseReg(const MachineOperand &MO)
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Target-Independent Code Generator Pass Configuration Options pass.
const RegisterBank * getRegBankToAssign(Register Reg)
void reAssignRegBankOnDef(MachineInstr &MI, MachineOperand &DefOP, const RegisterBank *RB)
RegBankSelectHelper(MachineIRBuilder &B, AMDGPU::IntrinsicLaneMaskAnalyzer &ILMA, const MachineUniformityInfo &MUI, const SIRegisterInfo &TRI, const RegisterBankInfo &RBI)
bool isTemporalDivergenceCopy(Register Reg)
void constrainRegBankUse(MachineInstr &MI, MachineOperand &UseOP, const RegisterBank *RB)
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
Defines a builder that does CSE of MachineInstructions using GISelCSEInfo.
FunctionPass class - This class is used to implement most global optimizations.
The actual analysis pass wrapper.
Simple wrapper observer that takes several observers, and calls each one for each event.
void addObserver(GISelChangeObserver *O)
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
An RAII based helper class to modify MachineFunctionProperties when running pass.
LLVM_ABI iterator SkipPHIsAndLabels(iterator I)
Return the first instruction in MBB after I that is not a PHI or a label.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Properties which a MachineFunction may have at a given point in time.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
const MachineFunctionProperties & getProperties() const
Get the function properties.
Helper class to build MachineInstr.
Representation of each machine instruction.
bool isPreISelOpcode(QueryType Type=IgnoreBundle) const
Return true if this is an instruction that should go through the usual legalization steps.
MachineOperand class - Representation of each machine instruction operand.
LLVM_ABI void setReg(Register Reg)
Change the register this operand corresponds to.
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
LLVM_ABI LLVM_READONLY MachineInstr * getVRegDef(Register Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
const RegisterBank * getRegBankOrNull(Register Reg) const
Return the register bank of Reg, or null if Reg has not been assigned a register bank or has been ass...
LLVM_ABI void setRegBank(Register Reg, const RegisterBank &RegBank)
Set the register bank to RegBank for Reg.
const TargetRegisterClass * getRegClassOrNull(Register Reg) const
Return the register class of Reg, or null if Reg has not been assigned a register class yet.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
A simple RAII based Delegate installer.
A simple RAII based Observer installer.
Holds all the information related to register banks.
This class implements the register bank concept.
Wrapper class representing virtual and physical registers.
constexpr bool isValid() const
Represent a constant reference to a string, i.e.
Target-Independent Code Generator Pass Configuration Options.
An efficient, type-erasing, non-owning reference to a callable.
This is an optimization pass for GlobalISel generic memory operations.
GenericUniformityInfo< MachineSSAContext > MachineUniformityInfo
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
DWARFExpression::Operation Op
FunctionPass * createAMDGPURegBankSelectLegacyPass()
char & AMDGPURegBankSelectLegacyID