25#define DEBUG_TYPE "si-late-branch-lowering"
29class SILateBranchLowering {
44 : ST(ST),
TII(ST.getInstrInfo()), MDT(MDT), MLI(MLI),
57 auto *MDT = &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
58 auto *MLIWP = getAnalysisIfAvailable<MachineLoopInfoWrapperPass>();
60 return SILateBranchLowering(ST, MDT, MLI).run(MF);
64 return "SI Final Branch Preparation";
77char SILateBranchLoweringLegacy::ID = 0;
80 "SI insert s_cbranch_execz instructions",
false,
false)
96 bool HasExports = HasColorExports || HasDepthExports;
101 if (IsPS && (HasExports || MustExport)) {
105 ST.hasNullExportTarget()
131 DTUpdates.
push_back({DomTreeT::Insert, SplitBB, Succ});
158 AMDGPU::getNamedOperandIdx(
MI.getOpcode(), AMDGPU::OpName::exec);
159 assert(ExecIdx != -1 &&
"Missing EXEC operand");
172 *
TII->getNamedOperand(
MI, AMDGPU::OpName::numvgprs));
176 .
addDef(
TII->getNamedOperand(
MI, AMDGPU::OpName::src0)->getReg());
178 *
TII->getNamedOperand(
MI, AMDGPU::OpName::src0));
180 *
TII->getNamedOperand(
MI, AMDGPU::OpName::fbcallee));
186 *
TII->getNamedOperand(
MI, AMDGPU::OpName::exec));
188 *
TII->getNamedOperand(
MI, AMDGPU::OpName::fbexec));
193 *
TII->getNamedOperand(
MI, AMDGPU::OpName::exec));
196 for (
int OpIdx =
MI.getNumExplicitOperands() - 1; OpIdx >= ExecIdx; --OpIdx)
197 MI.removeOperand(OpIdx);
199 MI.setDesc(
TII->get(AMDGPU::SI_TCRETURN_CHAIN));
202void SILateBranchLowering::earlyTerm(MachineInstr &
MI,
203 MachineBasicBlock *EarlyExitBlock) {
213 if (FirstNonDebug !=
MBB.
end() && !FirstNonDebug->isTerminator()) {
231 if (!SILateBranchLowering(ST, MDT, MLI).
run(MF))
243 bool MadeChange =
false;
247 switch (
MI.getOpcode()) {
248 case AMDGPU::S_BRANCH:
251 if (
MBB.isLayoutSuccessor(
MI.getOperand(0).getMBB())) {
253 MI.eraseFromParent();
258 case AMDGPU::SI_CS_CHAIN_TC_W32:
259 case AMDGPU::SI_CS_CHAIN_TC_W64:
260 expandChainCall(
MI, ST,
false);
263 case AMDGPU::SI_CS_CHAIN_TC_W32_DVGPR:
264 case AMDGPU::SI_CS_CHAIN_TC_W64_DVGPR:
265 expandChainCall(
MI, ST,
true);
269 case AMDGPU::SI_EARLY_TERMINATE_SCC0:
273 case AMDGPU::SI_RETURN_TO_EPILOG:
284 if (!EarlyTermInstrs.
empty()) {
285 MachineBasicBlock *EarlyExitBlock = MF.CreateMachineBasicBlock();
288 MF.
insert(MF.end(), EarlyExitBlock);
294 for (MachineInstr *Instr : EarlyTermInstrs) {
296 if (MF.getFunction().getCallingConv() != CallingConv::AMDGPU_GS)
297 earlyTerm(*Instr, EarlyExitBlock);
298 Instr->eraseFromParent();
301 EarlyTermInstrs.clear();
306 if (!EpilogInstrs.
empty()) {
307 MachineBasicBlock *EmptyMBBAtEnd =
nullptr;
308 assert(!MF.getInfo<SIMachineFunctionInfo>()->returnsVoid());
312 if (EpilogInstrs.
size() > 1) {
313 EmptyMBBAtEnd = MF.CreateMachineBasicBlock();
314 MF.
insert(MF.end(), EmptyMBBAtEnd);
317 for (
auto *
MI : EpilogInstrs) {
324 if (!EmptyMBBAtEnd) {
325 EmptyMBBAtEnd = MF.CreateMachineBasicBlock();
326 MF.
insert(MF.end(), EmptyMBBAtEnd);
337 EpilogInstrs.clear();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
AMD GCN specific subclass of TargetSubtarget.
const HexagonInstrInfo * TII
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
static void generateEndPgm(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, DebugLoc DL, const SIInstrInfo *TII, MachineFunction &MF)
static void splitBlock(MachineBasicBlock &MBB, MachineInstr &MI, MachineDominatorTree *MDT, MachineLoopInfo *MLI)
static void copyOpWithoutRegFlags(MachineInstrBuilder &MIB, MachineOperand &Op)
const unsigned CSelectOpc
static const LaneMaskConstants & get(const GCNSubtarget &ST)
PassT::Result * getCachedResult(IRUnitT &IR) const
Get the cached result of an analysis pass for a given IR unit.
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()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
void applyUpdates(ArrayRef< UpdateType > Updates)
Inform the dominator tree about a sequence of CFG edge insertions and deletions and perform a batch u...
void insertEdge(NodeT *From, NodeT *To)
Inform the dominator tree about a CFG edge insertion and update the tree.
void addBasicBlockToLoop(BlockT *NewBB, LoopInfoBase< BlockT, LoopT > &LI)
This method is used by other analyses to update loop information.
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
Represents a single loop in the control flow graph.
LLVM_ABI instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
LLVM_ABI void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
iterator_range< succ_iterator > successors()
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
MachineInstrBundleIterator< MachineInstr > iterator
Analysis pass which computes a MachineDominatorTree.
Analysis pass which computes a MachineDominatorTree.
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
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.
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.
const MachineInstrBuilder & add(const MachineOperand &MO) const
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
const MachineInstrBuilder & addDef(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a virtual register definition operand.
Representation of each machine instruction.
LLVM_ABI MachineInstrBundleIterator< MachineInstr > eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
Analysis pass that exposes the MachineLoopInfo for a machine function.
MachineOperand class - Representation of each machine instruction operand.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Target - Wrapper for Target specific information.
bool getHasColorExport(const Function &F)
bool getHasDepthExport(const Function &F)
bool isGFX10Plus(const MCSubtargetInfo &STI)
@ AMDGPU_PS
Used for Mesa/AMDPAL pixel shaders.
NodeAddr< InstrNode * > Instr
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.
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.
IterT skipDebugInstructionsForward(IterT It, IterT End, bool SkipPseudoOp=true)
Increment It until it points to a non-debug instruction or to End and return the resulting iterator.
char & SILateBranchLoweringPassID
DominatorTreeBase< T, false > DomTreeBase
DWARFExpression::Operation Op
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Next