30 #define DEBUG_TYPE "si-form-memory-clauses" 36 cl::desc(
"Maximum length of a memory clause, instructions"));
54 return "SI Form memory clauses";
64 template <
typename Callable>
65 void forAllLanes(
unsigned Reg,
LaneBitmask LaneMask, Callable Func)
const;
67 bool canBundle(
const MachineInstr &
MI, RegUse &Defs, RegUse &Uses)
const;
69 void collectRegUses(
const MachineInstr &
MI, RegUse &Defs, RegUse &Uses)
const;
70 bool processRegUses(
const MachineInstr &
MI, RegUse &Defs, RegUse &Uses,
78 unsigned LastRecordedOccupancy;
86 "SI Form memory clauses",
false,
false)
92 char SIFormMemoryClauses::ID = 0;
97 return new SIFormMemoryClauses();
126 if (!MO.isReg() || MO.isDef())
128 if (MO.getReg() == ResReg)
153 template <
typename Callable>
154 void SIFormMemoryClauses::forAllLanes(
unsigned Reg,
LaneBitmask LaneMask,
155 Callable Func)
const {
157 LaneMask ==
MRI->getMaxLaneMaskForVReg(Reg)) {
163 unsigned E =
TRI->getNumSubRegIndices();
165 for (
unsigned Idx = 1; Idx <
E; ++Idx) {
167 if (
TRI->getSubClassWithSubReg(RC, Idx) != RC)
171 if (SubRegMask == LaneMask) {
176 if ((SubRegMask & ~LaneMask).any() || (SubRegMask & LaneMask).none())
182 llvm::sort(CoveringSubregs, [
this](
unsigned A,
unsigned B) {
192 for (
unsigned Idx : CoveringSubregs) {
194 if ((SubRegMask & ~LaneMask).any() || (SubRegMask & LaneMask).none())
198 LaneMask &= ~SubRegMask;
209 RegUse &Defs, RegUse &Uses)
const {
226 RegUse &Map = MO.isDef() ? Uses : Defs;
227 auto Conflict = Map.find(Reg);
228 if (Conflict == Map.end())
235 if ((Conflict->second.second & Mask).any())
245 bool SIFormMemoryClauses::checkPressure(
const MachineInstr &MI,
254 if (Occupancy >= MFI->getMinAllowedOccupancy() &&
257 LastRecordedOccupancy = Occupancy;
264 void SIFormMemoryClauses::collectRegUses(
const MachineInstr &MI,
265 RegUse &Defs, RegUse &Uses)
const {
274 ?
TRI->getSubRegIndexLaneMask(MO.getSubReg())
276 RegUse &Map = MO.isDef() ? Defs : Uses;
278 auto Loc = Map.find(Reg);
280 if (Loc == Map.end()) {
281 Map[
Reg] = std::make_pair(State, Mask);
283 Loc->second.first |= State;
284 Loc->second.second |=
Mask;
292 bool SIFormMemoryClauses::processRegUses(
const MachineInstr &MI,
293 RegUse &Defs, RegUse &Uses,
295 if (!canBundle(MI, Defs, Uses))
298 if (!checkPressure(MI, RPT))
301 collectRegUses(MI, Defs, Uses);
310 if (!
ST->isXNACKEnabled())
314 TRI =
ST->getRegisterInfo();
319 bool Changed =
false;
321 MaxVGPRs =
TRI->getAllocatableSet(MF, &AMDGPU::VGPR_32RegClass).count();
322 MaxSGPRs =
TRI->getAllocatableSet(MF, &AMDGPU::SGPR_32RegClass).count();
328 for (
auto I = MBB.instr_begin(),
E = MBB.instr_end();
I !=
E;
I = Next) {
341 if (!processRegUses(MI, Defs, Uses, RPT))
345 for ( ; Next !=
E && Length < FuncMaxClause; ++Next) {
352 if (!processRegUses(*Next, Defs, Uses, RPT))
361 MFI->limitOccupancy(LastRecordedOccupancy);
364 Ind->insertMachineInstrInMaps(*
B);
366 for (
auto BI =
I; BI != Next; ++BI) {
368 Ind->removeSingleMachineInstrFromMaps(*BI);
372 MO.setIsInternalRead(
true);
375 for (
auto &&R : Defs) {
376 forAllLanes(R.first, R.second.second, [&R, &
B](
unsigned SubReg) {
377 unsigned S = R.second.first | RegState::EarlyClobber;
379 S &= ~(RegState::Undef | RegState::Dead);
380 B.addDef(R.first, S, SubReg);
384 for (
auto &&R : Uses) {
385 forAllLanes(R.first, R.second.second, [&R, &
B](
unsigned SubReg) {
386 B.addUse(R.first, R.second.first & ~RegState::Kill, SubReg);
390 for (
auto &&R : Defs) {
391 unsigned Reg = R.first;
395 LIS->removeInterval(Reg);
396 LIS->createAndComputeVirtRegInterval(Reg);
399 for (
auto &&R : Uses) {
400 unsigned Reg = R.first;
403 LIS->removeInterval(Reg);
404 LIS->createAndComputeVirtRegInterval(Reg);
char & SIFormMemoryClausesID
unsigned getNumLanes() const
void bundleWithPred()
Bundle this instruction with its predecessor.
Interface definition for SIRegisterInfo.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
AMDGPU specific subclass of TargetSubtarget.
This class represents lattice values for constants.
iterator_range< mop_iterator > uses()
Returns a range that includes all operands that are register uses.
FunctionPass * createSIFormMemoryClausesPass()
void initializeSIFormMemoryClausesPass(PassRegistry &)
decltype(MaxPressure) moveMaxPressure()
void push_back(const T &Elt)
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
bool reset(const MachineInstr &MI, const LiveRegSet *LiveRegs=nullptr)
unsigned getHighestLane() const
unsigned const TargetRegisterInfo * TRI
LLVM_READONLY int getAtomicNoRetOp(uint16_t Opcode)
iterator_range< mop_iterator > operands()
static bool isSMRD(const MachineInstr &MI)
bool isEarlyClobber() const
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
LLVM_READONLY int getAtomicRetOp(uint16_t Opcode)
static bool isFLAT(const MachineInstr &MI)
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
static constexpr LaneBitmask getAll()
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
unsigned getOccupancy(const GCNSubtarget &ST) const
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
bool mayStore(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly modify memory.
initializer< Ty > init(const Ty &Val)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
unsigned const MachineRegisterInfo * MRI
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
bool isBundled() const
Return true if this instruction part of a bundle.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
unsigned getSGPRNum() const
Represent the analysis usage information of a pass.
iterator_range< mop_iterator > defs()
Returns a range over all explicit operands that are register definitions.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
FunctionPass class - This class is used to implement most global optimizations.
constexpr bool all() const
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void sort(IteratorTy Start, IteratorTy End)
Iterator for intrusive lists based on ilist_node.
bool isDebugValue() const
MachineOperand class - Representation of each machine instruction operand.
unsigned getVGPRNum() const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
const Function & getFunction() const
Return the LLVM function that this machine code represents.
void setPreservesAll()
Set by analyses that do not transform their input at all.
bool isRenamable() const
isRenamable - Returns true if this register may be renamed, i.e.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Provides AMDGPU specific target descriptions.
Representation of each machine instruction.
This class keeps track of the SPI_SP_INPUT_ADDR config register, which tells the hardware which inter...
Interface definition for SIInstrInfo.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
int getIntegerAttribute(const Function &F, StringRef Name, int Default)
static bool isVMEM(const MachineInstr &MI)
bool mayLoad(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly read memory.
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
StringRef - Represent a constant reference to a string, i.e.
Register getReg() const
getReg - Returns the register number.
Wrapper class representing virtual and physical registers.