Skip to content

Conversation

karolherbst
Copy link

Otherwise multiple translation units in the same process could run into ID reuse collisions cause invalid SPIR-Vs to be generated due to having multiple definition for the same SPIR-V SSA value.

Closes: #160613

Otherwise multiple translation units in the same process could run into ID
reuse collisions cause invalid SPIR-Vs to be generated due to having
multiple definition for the same SPIR-V SSA value.

Closes: llvm#160613
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Sep 26, 2025

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

Author: Karol Herbst (karolherbst)

Changes

Otherwise multiple translation units in the same process could run into ID reuse collisions cause invalid SPIR-Vs to be generated due to having multiple definition for the same SPIR-V SSA value.

Closes: #160613


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

3 Files Affected:

  • (modified) llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp (+1-1)
  • (modified) llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp (-2)
  • (modified) llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.h (+1-1)
diff --git a/llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp b/llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp
index c2a6e51913a0a..c0fb217e8006f 100644
--- a/llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp
@@ -611,7 +611,7 @@ void SPIRVAsmPrinter::outputModuleSections() {
   // Get the global subtarget to output module-level info.
   ST = static_cast<const SPIRVTargetMachine &>(TM).getSubtargetImpl();
   TII = ST->getInstrInfo();
-  MAI = &SPIRVModuleAnalysis::MAI;
+  MAI = &getAnalysis<SPIRVModuleAnalysis>().MAI;
   assert(ST && TII && MAI && M && "Module analysis is required");
   // Output instructions according to the Logical Layout of a Module:
   // 1,2. All OpCapability instructions, then optional OpExtension instructions.
diff --git a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
index a95f393b75605..9aa815b13e76e 100644
--- a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
@@ -2126,8 +2126,6 @@ static void patchPhis(const Module &M, SPIRVGlobalRegistry *GR,
   }
 }
 
-struct SPIRV::ModuleAnalysisInfo SPIRVModuleAnalysis::MAI;
-
 void SPIRVModuleAnalysis::getAnalysisUsage(AnalysisUsage &AU) const {
   AU.addRequired<TargetPassConfig>();
   AU.addRequired<MachineModuleInfoWrapperPass>();
diff --git a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.h b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.h
index 41c792a98534f..4e9ca064b8d37 100644
--- a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.h
+++ b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.h
@@ -222,7 +222,7 @@ struct SPIRVModuleAnalysis : public ModulePass {
 
   bool runOnModule(Module &M) override;
   void getAnalysisUsage(AnalysisUsage &AU) const override;
-  static struct SPIRV::ModuleAnalysisInfo MAI;
+  struct SPIRV::ModuleAnalysisInfo MAI;
 
 private:
   void setBaseInfo(const Module &M);

@karolherbst
Copy link
Author

Not knowing LLVM well enough to deal with the test regressions. Something about the Analysis not available. Anyway, this PR demonstrates what's broken, so if anybody has a better idea to fix it, please let me know.

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.

[SPIR-V] SPIR-V back-end is generating duplicate IDs

2 participants