42#define DEBUG_TYPE "si-insert-hard-clauses"
60 HARDCLAUSE_MIMG_STORE,
61 HARDCLAUSE_MIMG_ATOMIC,
62 HARDCLAUSE_MIMG_SAMPLE,
65 HARDCLAUSE_VMEM_STORE,
66 HARDCLAUSE_VMEM_ATOMIC,
69 HARDCLAUSE_FLAT_STORE,
70 HARDCLAUSE_FLAT_ATOMIC,
82 LAST_REAL_HARDCLAUSE_TYPE = HARDCLAUSE_VALU,
94class SIInsertHardClauses {
100 if (
MI.getOpcode() == AMDGPU::GLOBAL_LOAD_ASYNC_TO_LDS_B8_replay)
101 return HARDCLAUSE_ILLEGAL;
102 if (
MI.mayLoad() || (
MI.mayStore() && ST->shouldClusterStores())) {
103 if (ST->hasMixedLoadStoreClauses()) {
106 if (ST->hasNSAClauseBug()) {
108 if (Info && Info->MIMGEncoding == AMDGPU::MIMGEncGfx10NSA)
109 return HARDCLAUSE_ILLEGAL;
111 return HARDCLAUSE_VMEM;
114 return HARDCLAUSE_FLAT;
121 return HARDCLAUSE_BVH;
123 return HARDCLAUSE_MIMG_SAMPLE;
124 return MI.mayLoad() ?
MI.mayStore() ? HARDCLAUSE_MIMG_ATOMIC
125 : HARDCLAUSE_MIMG_LOAD
126 : HARDCLAUSE_MIMG_STORE;
130 return MI.mayLoad() ?
MI.mayStore() ? HARDCLAUSE_VMEM_ATOMIC
131 : HARDCLAUSE_VMEM_LOAD
132 : HARDCLAUSE_VMEM_STORE;
135 return MI.mayLoad() ?
MI.mayStore() ? HARDCLAUSE_FLAT_ATOMIC
136 : HARDCLAUSE_FLAT_LOAD
137 : HARDCLAUSE_FLAT_STORE;
142 return HARDCLAUSE_SMEM;
149 if (
MI.getOpcode() == AMDGPU::S_NOP)
150 return HARDCLAUSE_INTERNAL;
151 if (
MI.isMetaInstruction())
152 return HARDCLAUSE_IGNORE;
153 return HARDCLAUSE_ILLEGAL;
159 HardClauseType
Type = HARDCLAUSE_ILLEGAL;
170 unsigned TrailingInternalLength = 0;
175 bool emitClause(
const ClauseInfo &CI,
const SIInstrInfo *SII) {
176 if (CI.First == CI.Last)
178 assert(CI.Length <= ST->maxHardClauseLength() &&
179 "Hard clause is too long!");
181 auto &
MBB = *CI.First->getParent();
186 std::next(CI.Last->getIterator()));
194 ST->hasGFX1250Insts());
195 int CPol1 = 0, CPol2 = 0;
204 return CPol1 != CPol2;
209 if (!ST->hasHardClauses())
212 unsigned MaxClauseLength =
213 ST->getCLOpts().hard_clause_length_limit.value_or(
215 "amdgpu-hard-clause-length-limit", 255));
216 MaxClauseLength = std::min(MaxClauseLength, ST->maxHardClauseLength());
217 if (MaxClauseLength <= 1)
223 for (
auto &
MBB : MF) {
225 unsigned ExistingClauseRemaining = 0;
226 for (
auto &
MI :
MBB) {
228 if (ExistingClauseRemaining) {
229 if (!
MI.isMetaInstruction())
230 ExistingClauseRemaining--;
231 Type = HARDCLAUSE_ILLEGAL;
232 }
else if (
MI.getOpcode() == AMDGPU::S_CLAUSE) {
235 ExistingClauseRemaining = (
MI.getOperand(0).
getImm() & 63) + 1;
236 Type = HARDCLAUSE_ILLEGAL;
238 Type = getHardClauseType(
MI);
245 if (
Type <= LAST_REAL_HARDCLAUSE_TYPE) {
250 Type = HARDCLAUSE_ILLEGAL;
254 if (CI.Length == MaxClauseLength ||
255 (CI.Length &&
Type != HARDCLAUSE_INTERNAL &&
256 Type != HARDCLAUSE_IGNORE &&
262 (CI.Length && ST->hasGFX1250_STRICT() &&
263 isIncompatibleScope(
MI, *CI.Last, SII))) {
265 Changed |= emitClause(CI, SII);
271 if (
Type != HARDCLAUSE_IGNORE) {
272 if (
Type == HARDCLAUSE_INTERNAL) {
273 ++CI.TrailingInternalLength;
276 CI.Length += CI.TrailingInternalLength;
277 CI.TrailingInternalLength = 0;
279 CI.BaseOps = std::move(BaseOps);
282 }
else if (
Type <= LAST_REAL_HARDCLAUSE_TYPE) {
284 CI = ClauseInfo{
Type, &
MI, &
MI, 1, 0, std::move(BaseOps)};
290 Changed |= emitClause(CI, SII);
306 return SIInsertHardClauses().run(MF);
320 if (!SIInsertHardClauses().
run(MF))
328char SIInsertHardClausesLegacy::ID = 0;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
AMD GCN specific subclass of TargetSubtarget.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file defines the SmallVector class.
Represent the analysis usage information of a pass.
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Represents analyses that only rely on functions' control flow.
uint64_t getFnAttributeAsParsedInteger(StringRef Kind, uint64_t Default=0) const
For a string attribute Kind, parse attribute as an integer.
static LocationSize precise(uint64_t Value)
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.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Function & getFunction()
Return the LLVM function that this machine code represents.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
static bool isVMEM(const MachineInstr &MI)
static bool isSMRD(const MachineInstr &MI)
bool getMemOperandsWithOffsetWidth(const MachineInstr &LdSt, SmallVectorImpl< const MachineOperand * > &BaseOps, int64_t &Offset, bool &OffsetIsScalable, LocationSize &Width) const final
static bool isSegmentSpecificFLAT(const MachineInstr &MI)
static bool isMIMG(const MachineInstr &MI)
bool memOpsHaveSameBase(ArrayRef< const MachineOperand * > BaseOps1, ArrayRef< const MachineOperand * > BaseOps2) const
Return true if the memory operations described by BaseOps1 and BaseOps2 (as returned by getMemOperand...
static bool isFLAT(const MachineInstr &MI)
LLVM_READONLY MachineOperand * getNamedOperand(MachineInstr &MI, AMDGPU::OpName OperandName) const
Returns the operand named Op.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM_READONLY const MIMGInfo * getMIMGInfo(unsigned Opc)
LLVM_READONLY const MIMGBaseOpcodeInfo * getMIMGBaseOpcodeInfo(unsigned BaseOpcode)
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI void finalizeBundle(MachineBasicBlock &MBB, MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI)
finalizeBundle - Finalize a machine instruction bundle which includes a sequence of instructions star...
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
DWARFExpression::Operation Op
char & SIInsertHardClausesID