LLVM 24.0.0git
SIInsertAsyncBarrierArriveWorkaround.cpp
Go to the documentation of this file.
1//===- SIInsertAsyncBarrierArriveWorkaround.cpp ---------------------------===//
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//
9/// \file
10/// Add a counted replay pseudo after affected async barrier arrivals. MC
11/// emission saves EXEC, clears it for the dummy load, and restores it.
12/// Run after scheduling to keep the pseudo after its arrival, and before
13/// wait-count analysis so it accounts for the added async load.
14//
15//===----------------------------------------------------------------------===//
16
17#include "AMDGPU.h"
18#include "GCNSubtarget.h"
25
26using namespace llvm;
27
28#define DEBUG_TYPE "si-insert-async-barrier-arrive-workaround"
29
31 const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>();
32 if (!ST.needsAsyncBarrierArriveReplayWorkaround())
33 return false;
34
35 // Collect arrivals before inserting new definitions of ASYNCcnt.
36 SmallVector<MachineInstr *, 4> AsyncBarrierArrivals;
38 for (MachineInstr &MI : MRI.def_instructions(AMDGPU::ASYNCcnt)) {
39 if (MI.getOpcode() == AMDGPU::DS_ATOMIC_ASYNC_BARRIER_ARRIVE_B64)
40 AsyncBarrierArrivals.push_back(&MI);
41 }
42 if (AsyncBarrierArrivals.empty())
43 return false;
44
46 const Register SavedExec = MFI->getSGPRForEXECCopy();
47 if (!SavedExec) {
49 "missing EXEC copy SGPR for async barrier workaround");
50 }
51
52 const SIInstrInfo &TII = *ST.getInstrInfo();
53 for (MachineInstr *MI : AsyncBarrierArrivals) {
54 MachineBasicBlock &MBB = *MI->getParent();
55 const DebugLoc &DL = MI->getDebugLoc();
56 auto InsertPt = std::next(MI->getIterator());
57 // Leave explicit S_WAIT_ASYNCCNT thresholds unchanged.
58 BuildMI(MBB, InsertPt, DL,
59 TII.get(AMDGPU::GLOBAL_LOAD_ASYNC_TO_LDS_B8_replay))
60 .addReg(AMDGPU::VGPR0, RegState::Undef)
61 .addReg(AMDGPU::VGPR0_VGPR1, RegState::Undef)
62 .addImm(0)
63 .addImm(0)
65 }
66 return true;
67}
68
69namespace {
70class SIInsertAsyncBarrierArriveWorkaroundLegacy : public MachineFunctionPass {
71public:
72 static char ID;
73
74 SIInsertAsyncBarrierArriveWorkaroundLegacy() : MachineFunctionPass(ID) {}
75
76 bool runOnMachineFunction(MachineFunction &MF) override {
78 }
79
80 void getAnalysisUsage(AnalysisUsage &AU) const override {
81 AU.setPreservesCFG();
83 }
84};
85} // namespace
86
87INITIALIZE_PASS(SIInsertAsyncBarrierArriveWorkaroundLegacy, DEBUG_TYPE,
88 "SI insert async barrier arrival workaround", false, false)
89
90char SIInsertAsyncBarrierArriveWorkaroundLegacy::ID = 0;
91
93 return new SIInsertAsyncBarrierArriveWorkaroundLegacy();
94}
95
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
AMD GCN specific subclass of TargetSubtarget.
#define DEBUG_TYPE
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
MachineRegisterInfo & MRI
static bool insertAsyncBarrierArriveWorkaround(MachineFunction &MF)
This file defines the SmallVector class.
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition Pass.cpp:280
Represents analyses that only rely on functions' control flow.
Definition Analysis.h:73
A debug info location.
Definition DebugLoc.h:126
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:312
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.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
Representation of each machine instruction.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
Definition Analysis.h:152
Wrapper class representing virtual and physical registers.
Definition Register.h:20
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
This class keeps track of the SPI_SP_INPUT_ADDR config register, which tells the hardware which inter...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This is an optimization pass for GlobalISel generic memory operations.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
@ Undef
Value of the register doesn't matter.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
FunctionPass * createSIInsertAsyncBarrierArriveWorkaroundPass()
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
Definition Error.cpp:177