23#define DEBUG_TYPE "si-post-ra-bundler"
37 return "SI post-RA bundler";
46class SIPostRABundler {
73char SIPostRABundlerLegacy::
ID = 0;
78 return new SIPostRABundlerLegacy();
81bool SIPostRABundler::isDependentLoad(
const MachineInstr &
MI)
const {
90 if (
TRI->regsOverlap(
Reg, Def))
97void SIPostRABundler::collectUsedRegUnits(
const MachineInstr &
MI,
98 BitVector &UsedRegUnits)
const {
99 if (
MI.isDebugInstr())
102 for (
const MachineOperand &
Op :
MI.operands()) {
103 if (!
Op.isReg() || !
Op.readsReg())
108 "subregister indexes should not be present after RA");
110 for (MCRegUnit Unit :
TRI->regunits(
Reg))
111 UsedRegUnits.
set(
static_cast<unsigned>(Unit));
115bool SIPostRABundler::isBundleCandidate(
const MachineInstr &
MI)
const {
116 const uint64_t IMemFlags =
MI.getDesc().TSFlags & MemFlags;
117 return IMemFlags != 0 &&
MI.mayLoadOrStore() && !
MI.isBundled();
120bool SIPostRABundler::canBundle(
const MachineInstr &
MI,
121 const MachineInstr &NextMI)
const {
122 const uint64_t IMemFlags =
MI.getDesc().TSFlags & MemFlags;
124 return (IMemFlags != 0 &&
MI.mayLoadOrStore() && !NextMI.
isBundled() &&
127 !isDependentLoad(NextMI));
130bool SIPostRABundlerLegacy::runOnMachineFunction(MachineFunction &MF) {
133 return SIPostRABundler().run(MF);
138 SIPostRABundler().run(MF);
151 unsigned Opc = MI.getOpcode();
152 return Opc == AMDGPU::SCHED_GROUP_BARRIER || Opc == AMDGPU::IGLP_OPT;
163 for (
auto I =
B;
I != E;
I =
Next) {
165 if (!isBundleCandidate(*
I))
170 if (
I->getNumExplicitDefs() != 0)
171 Defs.
insert(
I->defs().begin()->getReg());
175 unsigned ClauseLength = 1;
180 if (canBundle(*BundleEnd, *
I)) {
182 if (
I->getNumExplicitDefs() != 0)
183 Defs.
insert(
I->defs().begin()->getReg());
185 }
else if (!
I->isMetaInstruction() ||
186 I->getOpcode() == AMDGPU::SCHED_BARRIER) {
198 Next = std::next(BundleEnd);
199 if (ClauseLength > 1) {
208 for (
const MachineInstr &BundleMI :
make_range(BundleStart,
Next))
209 collectUsedRegUnits(BundleMI, BundleUsedRegUnits);
211 BundleUsedRegUnits.flip();
215 collectUsedRegUnits(
Kill, KillUsedRegUnits);
217 KillUsedRegUnits &= BundleUsedRegUnits;
223 if (KillUsedRegUnits.none()) {
225 Kill.eraseFromParent();
229 KillUsedRegUnits.reset();
232 BundleUsedRegUnits.reset();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
AMD GCN specific subclass of TargetSubtarget.
Register const TargetRegisterInfo * TRI
Promote Memory to Register
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file defines the SmallSet class.
Represent the analysis usage information of a pass.
void setPreservesAll()
Set by analyses that do not transform their input at all.
FunctionPass class - This class is used to implement most global optimizations.
Instructions::iterator instr_iterator
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.
Representation of each machine instruction.
bool mayLoad(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly read memory.
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
bool mayStore(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly modify memory.
bool isBundled() const
Return true if this instruction part of a bundle.
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.
Wrapper class representing virtual and physical registers.
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
StringRef - Represent a constant reference to a string, i.e.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
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...
@ Kill
The last use of a register.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
FunctionPass * createSIPostRABundlerPass()
char & SIPostRABundlerLegacyID
FunctionAddr VTableAddr Next
DWARFExpression::Operation Op