Skip to content

Commit c43d1d6

Browse files
committed
[AMDGPU][AMDGPUDemoteSCCBranchToExecz] create new pass (boilerplate only)
1 parent 4610dfa commit c43d1d6

File tree

6 files changed

+72
-1
lines changed

6 files changed

+72
-1
lines changed

llvm/lib/Target/AMDGPU/AMDGPU.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,17 @@ extern char &AMDGPUCodeGenPrepareID;
369369
void initializeAMDGPURemoveIncompatibleFunctionsPass(PassRegistry &);
370370
extern char &AMDGPURemoveIncompatibleFunctionsID;
371371

372+
void initializeAMDGPUDemoteSCCBranchToExeczLegacyPass(PassRegistry &);
373+
extern char &AMDGPUDemoteSCCBranchToExeczLegacyID;
374+
375+
class AMDGPUDemoteSCCBranchToExeczPass
376+
: public PassInfoMixin<AMDGPUDemoteSCCBranchToExeczPass> {
377+
public:
378+
AMDGPUDemoteSCCBranchToExeczPass() = default;
379+
PreservedAnalyses run(MachineFunction &MF,
380+
MachineFunctionAnalysisManager &MFAM);
381+
};
382+
372383
void initializeAMDGPULateCodeGenPrepareLegacyPass(PassRegistry &);
373384
extern char &AMDGPULateCodeGenPrepareLegacyID;
374385

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include <llvm/CodeGen/MachineFunctionPass.h>
2+
3+
#include "AMDGPU.h"
4+
5+
using namespace llvm;
6+
7+
namespace {
8+
#define DEBUG_TYPE "amdgpu-demote-scc-to-execz"
9+
const char PassName[] = "AMDGPU if conversion";
10+
11+
class AMDGPUDemoteSCCBranchToExecz {
12+
public:
13+
AMDGPUDemoteSCCBranchToExecz() = default;
14+
15+
bool run() { return false; }
16+
};
17+
18+
class AMDGPUDemoteSCCBranchToExeczLegacy : public MachineFunctionPass {
19+
public:
20+
static char ID;
21+
22+
AMDGPUDemoteSCCBranchToExeczLegacy() : MachineFunctionPass(ID) {}
23+
24+
bool runOnMachineFunction(MachineFunction &MF) override {
25+
AMDGPUDemoteSCCBranchToExecz IfCvt{};
26+
return IfCvt.run();
27+
}
28+
29+
void getAnalysisUsage(AnalysisUsage &AU) const override {
30+
MachineFunctionPass::getAnalysisUsage(AU);
31+
}
32+
33+
StringRef getPassName() const override { return PassName; }
34+
};
35+
36+
char AMDGPUDemoteSCCBranchToExeczLegacy::ID = 0;
37+
38+
} // namespace
39+
40+
PreservedAnalyses llvm::AMDGPUDemoteSCCBranchToExeczPass::run(
41+
MachineFunction &MF, MachineFunctionAnalysisManager &MFAM) {
42+
AMDGPUDemoteSCCBranchToExecz IfCvt{};
43+
if (!IfCvt.run())
44+
return PreservedAnalyses::all();
45+
return PreservedAnalyses::none();
46+
}
47+
48+
char &llvm::AMDGPUDemoteSCCBranchToExeczLegacyID =
49+
AMDGPUDemoteSCCBranchToExeczLegacy::ID;
50+
INITIALIZE_PASS_BEGIN(AMDGPUDemoteSCCBranchToExeczLegacy, DEBUG_TYPE, PassName,
51+
false, false)
52+
INITIALIZE_PASS_END(AMDGPUDemoteSCCBranchToExeczLegacy, DEBUG_TYPE, PassName,
53+
false, false)

llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ FUNCTION_PASS_WITH_PARAMS(
9595
#define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS)
9696
#endif
9797
MACHINE_FUNCTION_PASS("amdgpu-isel", AMDGPUISelDAGToDAGPass(*this))
98+
MACHINE_FUNCTION_PASS("amdgpu-demote-scc-to-execz", AMDGPUDemoteSCCBranchToExeczPass())
9899
MACHINE_FUNCTION_PASS("si-fix-sgpr-copies", SIFixSGPRCopiesPass())
99100
MACHINE_FUNCTION_PASS("si-i1-copies", SILowerI1CopiesPass())
100101
MACHINE_FUNCTION_PASS("si-fold-operands", SIFoldOperandsPass());

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAMDGPUTarget() {
444444
initializeAMDGPURewriteUndefForPHILegacyPass(*PR);
445445
initializeAMDGPUUnifyMetadataPass(*PR);
446446
initializeSIAnnotateControlFlowLegacyPass(*PR);
447+
initializeAMDGPUDemoteSCCBranchToExeczLegacyPass(*PR);
447448
initializeAMDGPUInsertDelayAluPass(*PR);
448449
initializeSIInsertHardClausesPass(*PR);
449450
initializeSIInsertWaitcntsPass(*PR);
@@ -1283,7 +1284,7 @@ void GCNPassConfig::addMachineSSAOptimization() {
12831284
bool GCNPassConfig::addILPOpts() {
12841285
if (EnableEarlyIfConversion)
12851286
addPass(&EarlyIfConverterID);
1286-
1287+
addPass(&AMDGPUDemoteSCCBranchToExeczLegacyID);
12871288
TargetPassConfig::addILPOpts();
12881289
return false;
12891290
}

llvm/lib/Target/AMDGPU/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ add_llvm_target(AMDGPUCodeGen
5959
AMDGPUGlobalISelDivergenceLowering.cpp
6060
AMDGPUGlobalISelUtils.cpp
6161
AMDGPUHSAMetadataStreamer.cpp
62+
AMDGPUDemoteSCCBranchToExecz.cpp
6263
AMDGPUInsertDelayAlu.cpp
6364
AMDGPUInstCombineIntrinsic.cpp
6465
AMDGPUInstrInfo.cpp

llvm/test/CodeGen/AMDGPU/llc-pipeline.ll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@
316316
; GCN-O1-NEXT: Merge disjoint stack slots
317317
; GCN-O1-NEXT: Local Stack Slot Allocation
318318
; GCN-O1-NEXT: Remove dead machine instructions
319+
; GCN-O1-NEXT: AMDGPU s_cbranch_scc to s_cbranch_execz conversion
319320
; GCN-O1-NEXT: MachineDominator Tree Construction
320321
; GCN-O1-NEXT: Machine Natural Loop Construction
321322
; GCN-O1-NEXT: Machine Block Frequency Analysis
@@ -614,6 +615,7 @@
614615
; GCN-O1-OPTS-NEXT: Merge disjoint stack slots
615616
; GCN-O1-OPTS-NEXT: Local Stack Slot Allocation
616617
; GCN-O1-OPTS-NEXT: Remove dead machine instructions
618+
; GCN-O1-OPTS-NEXT: AMDGPU s_cbranch_scc to s_cbranch_execz conversion
617619
; GCN-O1-OPTS-NEXT: MachineDominator Tree Construction
618620
; GCN-O1-OPTS-NEXT: Machine Natural Loop Construction
619621
; GCN-O1-OPTS-NEXT: Machine Block Frequency Analysis
@@ -925,6 +927,7 @@
925927
; GCN-O2-NEXT: Merge disjoint stack slots
926928
; GCN-O2-NEXT: Local Stack Slot Allocation
927929
; GCN-O2-NEXT: Remove dead machine instructions
930+
; GCN-O2-NEXT: AMDGPU s_cbranch_scc to s_cbranch_execz conversion
928931
; GCN-O2-NEXT: MachineDominator Tree Construction
929932
; GCN-O2-NEXT: Machine Natural Loop Construction
930933
; GCN-O2-NEXT: Machine Block Frequency Analysis
@@ -1249,6 +1252,7 @@
12491252
; GCN-O3-NEXT: Merge disjoint stack slots
12501253
; GCN-O3-NEXT: Local Stack Slot Allocation
12511254
; GCN-O3-NEXT: Remove dead machine instructions
1255+
; GCN-O3-NEXT: AMDGPU s_cbranch_scc to s_cbranch_execz conversion
12521256
; GCN-O3-NEXT: MachineDominator Tree Construction
12531257
; GCN-O3-NEXT: Machine Natural Loop Construction
12541258
; GCN-O3-NEXT: Machine Block Frequency Analysis

0 commit comments

Comments
 (0)