Skip to content

[SPIRV][OPT] Adding flag to run spirv structurizer #119301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 11, 2024

Conversation

joaosaffran
Copy link
Contributor

This PR adds a new flag into OPT to run SPIRV structurizer, this is being added improving testing of such pass.

This change is required to implement a test request that come #116331.

@llvmbot
Copy link
Member

llvmbot commented Dec 10, 2024

@llvm/pr-subscribers-backend-spir-v

Author: None (joaosaffran)

Changes

This PR adds a new flag into OPT to run SPIRV structurizer, this is being added improving testing of such pass.

This change is required to implement a test request that come #116331.


Full diff: https://github.com/llvm/llvm-project/pull/119301.diff

4 Files Affected:

  • (modified) llvm/lib/Target/SPIRV/SPIRV.h (+1)
  • (modified) llvm/lib/Target/SPIRV/SPIRVStructurizer.cpp (+1-1)
  • (modified) llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp (+1)
  • (modified) llvm/tools/opt/optdriver.cpp (+1-1)
diff --git a/llvm/lib/Target/SPIRV/SPIRV.h b/llvm/lib/Target/SPIRV/SPIRV.h
index 384133e7b4bd18..81b57202644256 100644
--- a/llvm/lib/Target/SPIRV/SPIRV.h
+++ b/llvm/lib/Target/SPIRV/SPIRV.h
@@ -37,6 +37,7 @@ void initializeSPIRVModuleAnalysisPass(PassRegistry &);
 void initializeSPIRVConvergenceRegionAnalysisWrapperPassPass(PassRegistry &);
 void initializeSPIRVPreLegalizerPass(PassRegistry &);
 void initializeSPIRVPostLegalizerPass(PassRegistry &);
+void initializeSPIRVStructurizerPass(PassRegistry &);
 void initializeSPIRVEmitIntrinsicsPass(PassRegistry &);
 void initializeSPIRVEmitNonSemanticDIPass(PassRegistry &);
 } // namespace llvm
diff --git a/llvm/lib/Target/SPIRV/SPIRVStructurizer.cpp b/llvm/lib/Target/SPIRV/SPIRVStructurizer.cpp
index 13e05b67927518..641e6caa23f95a 100644
--- a/llvm/lib/Target/SPIRV/SPIRVStructurizer.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVStructurizer.cpp
@@ -1218,7 +1218,7 @@ INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
 INITIALIZE_PASS_DEPENDENCY(SPIRVConvergenceRegionAnalysisWrapperPass)
 
-INITIALIZE_PASS_END(SPIRVStructurizer, "structurize", "structurize SPIRV",
+INITIALIZE_PASS_END(SPIRVStructurizer, "structurizer", "structurize SPIRV",
                     false, false)
 
 FunctionPass *llvm::createSPIRVStructurizerPass() {
diff --git a/llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp b/llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp
index d9d0d00cc71e41..744d4834b825c4 100644
--- a/llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp
@@ -45,6 +45,7 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeSPIRVTarget() {
   initializeGlobalISel(PR);
   initializeSPIRVModuleAnalysisPass(PR);
   initializeSPIRVConvergenceRegionAnalysisWrapperPassPass(PR);
+  initializeSPIRVStructurizerPass(PR);
 }
 
 static std::string computeDataLayout(const Triple &TT) {
diff --git a/llvm/tools/opt/optdriver.cpp b/llvm/tools/opt/optdriver.cpp
index 8ef249e1708b95..d60000e8889a05 100644
--- a/llvm/tools/opt/optdriver.cpp
+++ b/llvm/tools/opt/optdriver.cpp
@@ -376,7 +376,7 @@ static bool shouldPinPassToLegacyPM(StringRef Pass) {
       "expand-large-fp-convert",
       "callbrprepare",
       "scalarizer",
-  };
+      "structurizer"};
   for (const auto &P : PassNamePrefix)
     if (Pass.starts_with(P))
       return true;

@@ -1218,7 +1218,7 @@ INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
INITIALIZE_PASS_DEPENDENCY(SPIRVConvergenceRegionAnalysisWrapperPass)

INITIALIZE_PASS_END(SPIRVStructurizer, "structurize", "structurize SPIRV",
INITIALIZE_PASS_END(SPIRVStructurizer, "structurizer", "structurize SPIRV",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably prefix the pass with spirv- and connect it the way the DXIL-specific passes are. That reduces the surface area of exposing target-specific passes in code that isn't target-specific.

Copy link
Contributor

@Keenuts Keenuts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for the idea, modulus the pass name fix
Thanks!

Copy link
Collaborator

@llvm-beanz llvm-beanz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you for adding this, we can extend this to other SPIRV passes in the future to enable better testing of the individual passes.

@joaosaffran joaosaffran merged commit 10b1caf into llvm:main Dec 11, 2024
9 checks passed
@joaosaffran joaosaffran deleted the opt/add-structurizer branch February 26, 2025 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants