Skip to content

Commit cc8ceab

Browse files
committed
[AMDGPU][AMDGPUDemoteSCCBranchToExecz] create new pass (boilerplate only)
1 parent 8b20f1b commit cc8ceab

File tree

7 files changed

+97
-1
lines changed

7 files changed

+97
-1
lines changed

llvm/lib/Target/AMDGPU/AMDGPU.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,9 @@ extern char &AMDGPUCodeGenPrepareID;
373373
void initializeAMDGPURemoveIncompatibleFunctionsPass(PassRegistry &);
374374
extern char &AMDGPURemoveIncompatibleFunctionsID;
375375

376+
void initializeAMDGPUDemoteSCCBranchToExeczLegacyPass(PassRegistry &);
377+
extern char &AMDGPUDemoteSCCBranchToExeczLegacyID;
378+
376379
void initializeAMDGPULateCodeGenPrepareLegacyPass(PassRegistry &);
377380
extern char &AMDGPULateCodeGenPrepareLegacyID;
378381

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

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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "AMDGPU.h"
1919
#include "AMDGPUAliasAnalysis.h"
2020
#include "AMDGPUCtorDtorLowering.h"
21+
#include "AMDGPUDemoteSCCBranchToExecz.h"
2122
#include "AMDGPUExportClustering.h"
2223
#include "AMDGPUIGroupLP.h"
2324
#include "AMDGPUISelDAGToDAG.h"
@@ -498,6 +499,7 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAMDGPUTarget() {
498499
initializeAMDGPURewriteUndefForPHILegacyPass(*PR);
499500
initializeAMDGPUUnifyMetadataPass(*PR);
500501
initializeSIAnnotateControlFlowLegacyPass(*PR);
502+
initializeAMDGPUDemoteSCCBranchToExeczLegacyPass(*PR);
501503
initializeAMDGPUInsertDelayAluPass(*PR);
502504
initializeSIInsertHardClausesPass(*PR);
503505
initializeSIInsertWaitcntsPass(*PR);
@@ -1336,7 +1338,7 @@ void GCNPassConfig::addMachineSSAOptimization() {
13361338
bool GCNPassConfig::addILPOpts() {
13371339
if (EnableEarlyIfConversion)
13381340
addPass(&EarlyIfConverterID);
1339-
1341+
addPass(&AMDGPUDemoteSCCBranchToExeczLegacyID);
13401342
TargetPassConfig::addILPOpts();
13411343
return false;
13421344
}

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
@@ -315,6 +315,7 @@
315315
; GCN-O1-NEXT: Merge disjoint stack slots
316316
; GCN-O1-NEXT: Local Stack Slot Allocation
317317
; GCN-O1-NEXT: Remove dead machine instructions
318+
; GCN-O1-NEXT: AMDGPU s_cbranch_scc to s_cbranch_execz conversion
318319
; GCN-O1-NEXT: MachineDominator Tree Construction
319320
; GCN-O1-NEXT: Machine Natural Loop Construction
320321
; GCN-O1-NEXT: Machine Block Frequency Analysis
@@ -617,6 +618,7 @@
617618
; GCN-O1-OPTS-NEXT: Merge disjoint stack slots
618619
; GCN-O1-OPTS-NEXT: Local Stack Slot Allocation
619620
; GCN-O1-OPTS-NEXT: Remove dead machine instructions
621+
; GCN-O1-OPTS-NEXT: AMDGPU s_cbranch_scc to s_cbranch_execz conversion
620622
; GCN-O1-OPTS-NEXT: MachineDominator Tree Construction
621623
; GCN-O1-OPTS-NEXT: Machine Natural Loop Construction
622624
; GCN-O1-OPTS-NEXT: Machine Block Frequency Analysis
@@ -932,6 +934,7 @@
932934
; GCN-O2-NEXT: Merge disjoint stack slots
933935
; GCN-O2-NEXT: Local Stack Slot Allocation
934936
; GCN-O2-NEXT: Remove dead machine instructions
937+
; GCN-O2-NEXT: AMDGPU s_cbranch_scc to s_cbranch_execz conversion
935938
; GCN-O2-NEXT: MachineDominator Tree Construction
936939
; GCN-O2-NEXT: Machine Natural Loop Construction
937940
; GCN-O2-NEXT: Machine Block Frequency Analysis
@@ -1260,6 +1263,7 @@
12601263
; GCN-O3-NEXT: Merge disjoint stack slots
12611264
; GCN-O3-NEXT: Local Stack Slot Allocation
12621265
; GCN-O3-NEXT: Remove dead machine instructions
1266+
; GCN-O3-NEXT: AMDGPU s_cbranch_scc to s_cbranch_execz conversion
12631267
; GCN-O3-NEXT: MachineDominator Tree Construction
12641268
; GCN-O3-NEXT: Machine Natural Loop Construction
12651269
; GCN-O3-NEXT: Machine Block Frequency Analysis

0 commit comments

Comments
 (0)