[llvm] [NFC] Cleanup pass initialization for SPIRV passes (PR #134189)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 2 18:35:40 PDT 2025
https://github.com/jurahul created https://github.com/llvm/llvm-project/pull/134189
- Do not call pass initialization functions from pass contructors.
- Instead, call them from SPIRV target initialization.
>From de69d2a81c2b5c9686cabb35f4afac2a7e95d6b6 Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Wed, 2 Apr 2025 18:21:26 -0700
Subject: [PATCH] [NFC] Cleanup pass initialization for SPIRV passes
- Do not call pass initialization functions from pass contructors.
- Instead, call them from SPIRV target initialization.
---
.../Analysis/SPIRVConvergenceRegionAnalysis.cpp | 5 +----
llvm/lib/Target/SPIRV/SPIRV.h | 5 +++++
llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp | 15 ++++-----------
llvm/lib/Target/SPIRV/SPIRVEmitNonSemanticDI.cpp | 13 ++-----------
.../lib/Target/SPIRV/SPIRVLegalizePointerCast.cpp | 10 +++-------
.../Target/SPIRV/SPIRVMergeRegionExitTargets.cpp | 9 +++------
llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp | 4 ----
llvm/lib/Target/SPIRV/SPIRVPostLegalizer.cpp | 4 +---
llvm/lib/Target/SPIRV/SPIRVPreLegalizer.cpp | 4 +---
.../Target/SPIRV/SPIRVPreLegalizerCombiner.cpp | 2 --
llvm/lib/Target/SPIRV/SPIRVPrepareFunctions.cpp | 11 +++--------
llvm/lib/Target/SPIRV/SPIRVRegularizer.cpp | 8 +-------
.../SPIRV/SPIRVStripConvergentIntrinsics.cpp | 11 +++--------
llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp | 9 +++++++++
14 files changed, 36 insertions(+), 74 deletions(-)
diff --git a/llvm/lib/Target/SPIRV/Analysis/SPIRVConvergenceRegionAnalysis.cpp b/llvm/lib/Target/SPIRV/Analysis/SPIRVConvergenceRegionAnalysis.cpp
index 48b327deaba84..88d5d0d503aa3 100644
--- a/llvm/lib/Target/SPIRV/Analysis/SPIRVConvergenceRegionAnalysis.cpp
+++ b/llvm/lib/Target/SPIRV/Analysis/SPIRVConvergenceRegionAnalysis.cpp
@@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//
#include "SPIRVConvergenceRegionAnalysis.h"
+#include "SPIRV.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/IntrinsicInst.h"
@@ -26,10 +27,6 @@
using namespace llvm;
using namespace SPIRV;
-namespace llvm {
-void initializeSPIRVConvergenceRegionAnalysisWrapperPassPass(PassRegistry &);
-} // namespace llvm
-
INITIALIZE_PASS_BEGIN(SPIRVConvergenceRegionAnalysisWrapperPass,
"convergence-region",
"SPIRV convergence regions analysis", true, true)
diff --git a/llvm/lib/Target/SPIRV/SPIRV.h b/llvm/lib/Target/SPIRV/SPIRV.h
index d765dfe370be2..51728d1aa678d 100644
--- a/llvm/lib/Target/SPIRV/SPIRV.h
+++ b/llvm/lib/Target/SPIRV/SPIRV.h
@@ -43,6 +43,11 @@ void initializeSPIRVPostLegalizerPass(PassRegistry &);
void initializeSPIRVStructurizerPass(PassRegistry &);
void initializeSPIRVEmitIntrinsicsPass(PassRegistry &);
void initializeSPIRVEmitNonSemanticDIPass(PassRegistry &);
+void initializeSPIRVLegalizePointerCastPass(PassRegistry &);
+void initializeSPIRVRegularizerPass(PassRegistry &);
+void initializeSPIRVMergeRegionExitTargetsPass(PassRegistry &);
+void initializeSPIRVPrepareFunctionsPass(PassRegistry &);
+void initializeSPIRVStripConvergentIntrinsicsPass(PassRegistry &);
} // namespace llvm
#endif // LLVM_LIB_TARGET_SPIRV_SPIRV_H
diff --git a/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp b/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
index 0a6a54b4a2f67..05861832b1415 100644
--- a/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
@@ -47,13 +47,10 @@
using namespace llvm;
-namespace llvm {
-namespace SPIRV {
+namespace llvm::SPIRV {
#define GET_BuiltinGroup_DECL
#include "SPIRVGenTables.inc"
-} // namespace SPIRV
-void initializeSPIRVEmitIntrinsicsPass(PassRegistry &);
-} // namespace llvm
+} // namespace llvm::SPIRV
namespace {
@@ -200,12 +197,8 @@ class SPIRVEmitIntrinsics
public:
static char ID;
- SPIRVEmitIntrinsics() : ModulePass(ID) {
- initializeSPIRVEmitIntrinsicsPass(*PassRegistry::getPassRegistry());
- }
- SPIRVEmitIntrinsics(SPIRVTargetMachine *_TM) : ModulePass(ID), TM(_TM) {
- initializeSPIRVEmitIntrinsicsPass(*PassRegistry::getPassRegistry());
- }
+ SPIRVEmitIntrinsics(SPIRVTargetMachine *TM = nullptr)
+ : ModulePass(ID), TM(TM) {}
Instruction *visitInstruction(Instruction &I) { return &I; }
Instruction *visitSwitchInst(SwitchInst &I);
Instruction *visitGetElementPtrInst(GetElementPtrInst &I);
diff --git a/llvm/lib/Target/SPIRV/SPIRVEmitNonSemanticDI.cpp b/llvm/lib/Target/SPIRV/SPIRVEmitNonSemanticDI.cpp
index 7858f44a054d7..725fcdb46f56d 100644
--- a/llvm/lib/Target/SPIRV/SPIRVEmitNonSemanticDI.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVEmitNonSemanticDI.cpp
@@ -33,8 +33,8 @@ namespace {
struct SPIRVEmitNonSemanticDI : public MachineFunctionPass {
static char ID;
SPIRVTargetMachine *TM;
- SPIRVEmitNonSemanticDI(SPIRVTargetMachine *TM);
- SPIRVEmitNonSemanticDI();
+ SPIRVEmitNonSemanticDI(SPIRVTargetMachine *TM = nullptr)
+ : MachineFunctionPass(ID), TM(TM) {}
bool runOnMachineFunction(MachineFunction &MF) override;
@@ -54,15 +54,6 @@ llvm::createSPIRVEmitNonSemanticDIPass(SPIRVTargetMachine *TM) {
return new SPIRVEmitNonSemanticDI(TM);
}
-SPIRVEmitNonSemanticDI::SPIRVEmitNonSemanticDI(SPIRVTargetMachine *TM)
- : MachineFunctionPass(ID), TM(TM) {
- initializeSPIRVEmitNonSemanticDIPass(*PassRegistry::getPassRegistry());
-}
-
-SPIRVEmitNonSemanticDI::SPIRVEmitNonSemanticDI() : MachineFunctionPass(ID) {
- initializeSPIRVEmitNonSemanticDIPass(*PassRegistry::getPassRegistry());
-}
-
enum BaseTypeAttributeEncoding {
Unspecified = 0,
Address = 1,
diff --git a/llvm/lib/Target/SPIRV/SPIRVLegalizePointerCast.cpp b/llvm/lib/Target/SPIRV/SPIRVLegalizePointerCast.cpp
index 2ccff9dd321ec..560869f9fe62a 100644
--- a/llvm/lib/Target/SPIRV/SPIRVLegalizePointerCast.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVLegalizePointerCast.cpp
@@ -56,10 +56,7 @@
using namespace llvm;
-namespace llvm {
-void initializeSPIRVLegalizePointerCastPass(PassRegistry &);
-}
-
+namespace {
class SPIRVLegalizePointerCast : public FunctionPass {
// Builds the `spv_assign_type` assigning |Ty| to |Value| at the current
@@ -182,9 +179,7 @@ class SPIRVLegalizePointerCast : public FunctionPass {
}
public:
- SPIRVLegalizePointerCast(SPIRVTargetMachine *TM) : FunctionPass(ID), TM(TM) {
- initializeSPIRVLegalizePointerCastPass(*PassRegistry::getPassRegistry());
- };
+ SPIRVLegalizePointerCast(SPIRVTargetMachine *TM) : FunctionPass(ID), TM(TM) {}
virtual bool runOnFunction(Function &F) override {
const SPIRVSubtarget &ST = TM->getSubtarget<SPIRVSubtarget>(F);
@@ -217,6 +212,7 @@ class SPIRVLegalizePointerCast : public FunctionPass {
public:
static char ID;
};
+} // namespace
char SPIRVLegalizePointerCast::ID = 0;
INITIALIZE_PASS(SPIRVLegalizePointerCast, "spirv-legalize-bitcast",
diff --git a/llvm/lib/Target/SPIRV/SPIRVMergeRegionExitTargets.cpp b/llvm/lib/Target/SPIRV/SPIRVMergeRegionExitTargets.cpp
index 267ab7b6376bd..67e73f1bd2198 100644
--- a/llvm/lib/Target/SPIRV/SPIRVMergeRegionExitTargets.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVMergeRegionExitTargets.cpp
@@ -34,16 +34,13 @@
using namespace llvm;
-namespace llvm {
-void initializeSPIRVMergeRegionExitTargetsPass(PassRegistry &);
+namespace {
class SPIRVMergeRegionExitTargets : public FunctionPass {
public:
static char ID;
- SPIRVMergeRegionExitTargets() : FunctionPass(ID) {
- initializeSPIRVMergeRegionExitTargetsPass(*PassRegistry::getPassRegistry());
- };
+ SPIRVMergeRegionExitTargets() : FunctionPass(ID) {}
// Gather all the successors of |BB|.
// This function asserts if the terminator neither a branch, switch or return.
@@ -273,7 +270,7 @@ class SPIRVMergeRegionExitTargets : public FunctionPass {
FunctionPass::getAnalysisUsage(AU);
}
};
-} // namespace llvm
+} // namespace
char SPIRVMergeRegionExitTargets::ID = 0;
diff --git a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
index acc8c014cb26b..fc85e2aa5f0fe 100644
--- a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
@@ -49,10 +49,6 @@ struct AvoidCapabilitiesSet {
char llvm::SPIRVModuleAnalysis::ID = 0;
-namespace llvm {
-void initializeSPIRVModuleAnalysisPass(PassRegistry &);
-} // namespace llvm
-
INITIALIZE_PASS(SPIRVModuleAnalysis, DEBUG_TYPE, "SPIRV module analysis", true,
true)
diff --git a/llvm/lib/Target/SPIRV/SPIRVPostLegalizer.cpp b/llvm/lib/Target/SPIRV/SPIRVPostLegalizer.cpp
index de9be33d68c34..c9b78c521f504 100644
--- a/llvm/lib/Target/SPIRV/SPIRVPostLegalizer.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVPostLegalizer.cpp
@@ -34,9 +34,7 @@ namespace {
class SPIRVPostLegalizer : public MachineFunctionPass {
public:
static char ID;
- SPIRVPostLegalizer() : MachineFunctionPass(ID) {
- initializeSPIRVPostLegalizerPass(*PassRegistry::getPassRegistry());
- }
+ SPIRVPostLegalizer() : MachineFunctionPass(ID) {}
bool runOnMachineFunction(MachineFunction &MF) override;
};
} // namespace
diff --git a/llvm/lib/Target/SPIRV/SPIRVPreLegalizer.cpp b/llvm/lib/Target/SPIRV/SPIRVPreLegalizer.cpp
index 3a68def3df058..e4cc03eff1035 100644
--- a/llvm/lib/Target/SPIRV/SPIRVPreLegalizer.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVPreLegalizer.cpp
@@ -32,9 +32,7 @@ namespace {
class SPIRVPreLegalizer : public MachineFunctionPass {
public:
static char ID;
- SPIRVPreLegalizer() : MachineFunctionPass(ID) {
- initializeSPIRVPreLegalizerPass(*PassRegistry::getPassRegistry());
- }
+ SPIRVPreLegalizer() : MachineFunctionPass(ID) {}
bool runOnMachineFunction(MachineFunction &MF) override;
void getAnalysisUsage(AnalysisUsage &AU) const override;
};
diff --git a/llvm/lib/Target/SPIRV/SPIRVPreLegalizerCombiner.cpp b/llvm/lib/Target/SPIRV/SPIRVPreLegalizerCombiner.cpp
index ec688762ca0a5..d2de71ce10c10 100644
--- a/llvm/lib/Target/SPIRV/SPIRVPreLegalizerCombiner.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVPreLegalizerCombiner.cpp
@@ -197,8 +197,6 @@ void SPIRVPreLegalizerCombiner::getAnalysisUsage(AnalysisUsage &AU) const {
SPIRVPreLegalizerCombiner::SPIRVPreLegalizerCombiner()
: MachineFunctionPass(ID) {
- initializeSPIRVPreLegalizerCombinerPass(*PassRegistry::getPassRegistry());
-
if (!RuleConfig.parseCommandLineOption())
report_fatal_error("Invalid rule identifier");
}
diff --git a/llvm/lib/Target/SPIRV/SPIRVPrepareFunctions.cpp b/llvm/lib/Target/SPIRV/SPIRVPrepareFunctions.cpp
index 028699e56a946..628688d83a314 100644
--- a/llvm/lib/Target/SPIRV/SPIRVPrepareFunctions.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVPrepareFunctions.cpp
@@ -35,10 +35,6 @@
using namespace llvm;
-namespace llvm {
-void initializeSPIRVPrepareFunctionsPass(PassRegistry &);
-}
-
namespace {
class SPIRVPrepareFunctions : public ModulePass {
@@ -48,9 +44,8 @@ class SPIRVPrepareFunctions : public ModulePass {
public:
static char ID;
- SPIRVPrepareFunctions(const SPIRVTargetMachine &TM) : ModulePass(ID), TM(TM) {
- initializeSPIRVPrepareFunctionsPass(*PassRegistry::getPassRegistry());
- }
+ SPIRVPrepareFunctions(const SPIRVTargetMachine &TM)
+ : ModulePass(ID), TM(TM) {}
bool runOnModule(Module &M) override;
@@ -68,7 +63,7 @@ char SPIRVPrepareFunctions::ID = 0;
INITIALIZE_PASS(SPIRVPrepareFunctions, "prepare-functions",
"SPIRV prepare functions", false, false)
-std::string lowerLLVMIntrinsicName(IntrinsicInst *II) {
+static std::string lowerLLVMIntrinsicName(IntrinsicInst *II) {
Function *IntrinsicFunc = II->getCalledFunction();
assert(IntrinsicFunc && "Missing function");
std::string FuncName = IntrinsicFunc->getName().str();
diff --git a/llvm/lib/Target/SPIRV/SPIRVRegularizer.cpp b/llvm/lib/Target/SPIRV/SPIRVRegularizer.cpp
index a956fad5487c1..0e01430d3b863 100644
--- a/llvm/lib/Target/SPIRV/SPIRVRegularizer.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVRegularizer.cpp
@@ -25,19 +25,13 @@
using namespace llvm;
-namespace llvm {
-void initializeSPIRVRegularizerPass(PassRegistry &);
-}
-
namespace {
struct SPIRVRegularizer : public FunctionPass, InstVisitor<SPIRVRegularizer> {
DenseMap<Function *, Function *> Old2NewFuncs;
public:
static char ID;
- SPIRVRegularizer() : FunctionPass(ID) {
- initializeSPIRVRegularizerPass(*PassRegistry::getPassRegistry());
- }
+ SPIRVRegularizer() : FunctionPass(ID) {}
bool runOnFunction(Function &F) override;
StringRef getPassName() const override { return "SPIR-V Regularizer"; }
diff --git a/llvm/lib/Target/SPIRV/SPIRVStripConvergentIntrinsics.cpp b/llvm/lib/Target/SPIRV/SPIRVStripConvergentIntrinsics.cpp
index c87048b93f80f..78bb6973f3896 100644
--- a/llvm/lib/Target/SPIRV/SPIRVStripConvergentIntrinsics.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVStripConvergentIntrinsics.cpp
@@ -25,18 +25,12 @@
using namespace llvm;
-namespace llvm {
-void initializeSPIRVStripConvergentIntrinsicsPass(PassRegistry &);
-}
-
+namespace {
class SPIRVStripConvergentIntrinsics : public FunctionPass {
public:
static char ID;
- SPIRVStripConvergentIntrinsics() : FunctionPass(ID) {
- initializeSPIRVStripConvergentIntrinsicsPass(
- *PassRegistry::getPassRegistry());
- };
+ SPIRVStripConvergentIntrinsics() : FunctionPass(ID) {}
virtual bool runOnFunction(Function &F) override {
DenseSet<Instruction *> ToRemove;
@@ -85,6 +79,7 @@ class SPIRVStripConvergentIntrinsics : public FunctionPass {
return ToRemove.size() != 0;
}
};
+} // namespace
char SPIRVStripConvergentIntrinsics::ID = 0;
INITIALIZE_PASS(SPIRVStripConvergentIntrinsics, "strip-convergent-intrinsics",
diff --git a/llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp b/llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp
index 0aa214dd354ee..4399f080f1f81 100644
--- a/llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp
@@ -49,6 +49,15 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeSPIRVTarget() {
initializeSPIRVConvergenceRegionAnalysisWrapperPassPass(PR);
initializeSPIRVStructurizerPass(PR);
initializeSPIRVPreLegalizerCombinerPass(PR);
+ initializeSPIRVLegalizePointerCastPass(PR);
+ initializeSPIRVRegularizerPass(PR);
+ initializeSPIRVPreLegalizerPass(PR);
+ initializeSPIRVPostLegalizerPass(PR);
+ initializeSPIRVMergeRegionExitTargetsPass(PR);
+ initializeSPIRVEmitIntrinsicsPass(PR);
+ initializeSPIRVEmitNonSemanticDIPass(PR);
+ initializeSPIRVPrepareFunctionsPass(PR);
+ initializeSPIRVStripConvergentIntrinsicsPass(PR);
}
static std::string computeDataLayout(const Triple &TT) {
More information about the llvm-commits
mailing list