[PATCH] D88775: [AMDGPU] SIInsertSkips: Refactor early exit block creation
Carl Ritson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 2 22:48:19 PDT 2020
critson created this revision.
critson added reviewers: nhaehnle, arsenm.
Herald added subscribers: llvm-commits, kerbowa, hiraditya, t-tye, tpr, dstuttard, yaxunl, jvesely, kzhuravl.
Herald added a project: LLVM.
critson requested review of this revision.
Herald added a subscriber: wdng.
Refactor exit block creation to a single call ensureEarlyExitBlock.
Add support for generating an early exit block which clears the
exec mask, but only add this instruction when required.
These changes are to facilitate adding more forms of early
termination for PS shaders in the near future.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D88775
Files:
llvm/lib/Target/AMDGPU/SIInsertSkips.cpp
Index: llvm/lib/Target/AMDGPU/SIInsertSkips.cpp
===================================================================
--- llvm/lib/Target/AMDGPU/SIInsertSkips.cpp
+++ llvm/lib/Target/AMDGPU/SIInsertSkips.cpp
@@ -58,12 +58,13 @@
MachineDominatorTree *MDT = nullptr;
MachineBasicBlock *EarlyExitBlock = nullptr;
+ bool EarlyExitClearsExec = false;
bool shouldSkip(const MachineBasicBlock &From,
const MachineBasicBlock &To) const;
bool dominatesAllReachable(MachineBasicBlock &MBB);
- void createEarlyExitBlock(MachineBasicBlock &MBB);
+ void ensureEarlyExitBlock(MachineBasicBlock &MBB, bool ClearExec);
void skipIfDead(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
DebugLoc DL);
@@ -180,15 +181,26 @@
BuildMI(MBB, I, DL, TII->get(AMDGPU::S_ENDPGM)).addImm(0);
}
-void SIInsertSkips::createEarlyExitBlock(MachineBasicBlock &MBB) {
+void SIInsertSkips::ensureEarlyExitBlock(MachineBasicBlock &MBB,
+ bool ClearExec) {
MachineFunction *MF = MBB.getParent();
DebugLoc DL;
- assert(!EarlyExitBlock);
- EarlyExitBlock = MF->CreateMachineBasicBlock();
- MF->insert(MF->end(), EarlyExitBlock);
+ if (!EarlyExitBlock) {
+ EarlyExitBlock = MF->CreateMachineBasicBlock();
+ MF->insert(MF->end(), EarlyExitBlock);
+ generatePsEndPgm(*EarlyExitBlock, EarlyExitBlock->end(), DL, TII);
+ }
- generatePsEndPgm(*EarlyExitBlock, EarlyExitBlock->end(), DL, TII);
+ if (ClearExec && !EarlyExitClearsExec) {
+ const GCNSubtarget &ST = MF->getSubtarget<GCNSubtarget>();
+ unsigned Mov = ST.isWave32() ? AMDGPU::S_MOV_B32 : AMDGPU::S_MOV_B64;
+ Register Exec = ST.isWave32() ? AMDGPU::EXEC_LO : AMDGPU::EXEC;
+ auto ExitI = EarlyExitBlock->getFirstNonPHI();
+ assert(ExitI->getOpcode() == AMDGPU::EXP_DONE);
+ BuildMI(*EarlyExitBlock, ExitI, DL, TII->get(Mov), Exec).addImm(0);
+ EarlyExitClearsExec = true;
+ }
}
static void splitBlock(MachineBasicBlock &MBB, MachineInstr &MI,
@@ -233,11 +245,9 @@
if (NoSuccessor) {
generatePsEndPgm(MBB, I, DL, TII);
} else {
- if (!EarlyExitBlock) {
- createEarlyExitBlock(MBB);
- // Update next block pointer to reflect any new blocks
- NextBBI = std::next(MBB.getIterator());
- }
+ ensureEarlyExitBlock(MBB, false);
+ // Update next block pointer to reflect any new blocks
+ NextBBI = std::next(MBB.getIterator());
MachineInstr *BranchMI =
BuildMI(MBB, I, DL, TII->get(AMDGPU::S_CBRANCH_EXECZ))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88775.295961.patch
Type: text/x-patch
Size: 2538 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201003/2311ddaa/attachment.bin>
More information about the llvm-commits
mailing list