Skip to content

[SPIRV] Add pass SPIRVEmitIntrinsics to new pass manager - #188285

Merged
mgcarrasco merged 13 commits into
llvm:mainfrom
ambergorzynski:spirv-emit-intrinsics-npm
Mar 25, 2026
Merged

mgcarrasco merged 13 commits into
llvm:mainfrom
ambergorzynski:spirv-emit-intrinsics-npm

Conversation

@ambergorzynski

@ambergorzynski ambergorzynski commented Mar 24, 2026 •

Copy link
Copy Markdown
Contributor

Registered SPIRVEmitIntrinsics with the new pass manager as emit-intrinsics. The motivation for this is to allow it to be run from opt as a standalone pass for testing purposes. A simple pipeline test is also included to check that the registration works.

For discussion - I used the name emit-intrinsics for consistency with the legacy pass manager and the existing pass name. Alternatively, we could update the registered name to spirv-emit-intrinsics everywhere for consistency with the other SPIRV passes that are registered with the new pass manager, which are prefixed with spirv.

@github-actions

github-actions Bot commented Mar 24, 2026 •

Copy link
Copy Markdown

✅ With the latest revision this PR passed the C/C++ code formatter.

@ambergorzynski ambergorzynski changed the title [WIP][SPIRV] Add pass SPIRVEmitIntrinsics to new pass manager [SPIRV] Add pass SPIRVEmitIntrinsics to new pass manager Mar 25, 2026
@ambergorzynski
ambergorzynski marked this pull request as ready for review March 25, 2026 09:45
@mgcarrasco
mgcarrasco requested review from MrSidims and s-perron March 25, 2026 09:45
@llvmbot

llvmbot commented Mar 25, 2026

Copy link
Copy Markdown
Member

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

Author: ambergorzynski

Changes

Registered SPIRVEmitIntrinsics with the new pass manager as emit-intrinsics. The motivation for this is to allow it to be run from opt as a standalone pass for testing purposes. A simple pipeline test is also included to check that the registration works.

For discussion - I used the name emit-intrinsics for consistency with the legacy pass manager and the existing pass name. Alternatively, we could update the registered name to spirv-emit-intrinsics everywhere for consistency with the other SPIRV passes that are registered with the new pass manager, which are prefixed with spirv.


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

5 Files Affected:

  • (modified) llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp (+9)
  • (added) llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.h (+28)
  • (modified) llvm/lib/Target/SPIRV/SPIRVPassRegistry.def (+1)
  • (modified) llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp (+1)
  • (added) llvm/test/CodeGen/SPIRV/passes/SPIRVEmitIntrinsics.ll (+20)
diff --git a/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp b/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
index 131b56e92b8be..0b10bef059fb6 100644
--- a/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
@@ -11,6 +11,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "SPIRVEmitIntrinsics.h"
 #include "SPIRV.h"
 #include "SPIRVBuiltins.h"
 #include "SPIRVSubtarget.h"
@@ -3443,6 +3444,14 @@ bool SPIRVEmitIntrinsics::runOnModule(Module &M) {
   return Changed;
 }
 
+PreservedAnalyses
+llvm::SPIRVEmitIntrinsicsPass::run(Module &M, ModuleAnalysisManager &AM) {
+  SPIRVEmitIntrinsics Legacy(TM);
+  if (Legacy.runOnModule(M))
+    return PreservedAnalyses::none();
+  return PreservedAnalyses::all();
+}
+
 ModulePass *llvm::createSPIRVEmitIntrinsicsPass(SPIRVTargetMachine *TM) {
   return new SPIRVEmitIntrinsics(TM);
 }
diff --git a/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.h b/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.h
new file mode 100644
index 0000000000000..9d587f57f118f
--- /dev/null
+++ b/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.h
@@ -0,0 +1,28 @@
+//===- SPIRVEmitIntrinsics.h - Emit SPIRV intrinsics *- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIB_TARGET_SPIRV_SPIRVEMITINTRINSICS_H_
+#define LLVM_LIB_TARGET_SPIRV_SPIRVEMITINTRINSICS_H_
+
+#include "llvm/IR/PassManager.h"
+
+namespace llvm {
+
+class SPIRVTargetMachine;
+
+class SPIRVEmitIntrinsicsPass : public PassInfoMixin<SPIRVEmitIntrinsicsPass> {
+  SPIRVTargetMachine *TM;
+
+public:
+  SPIRVEmitIntrinsicsPass(SPIRVTargetMachine *TM) : TM(TM) {}
+  PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
+};
+
+} // namespace llvm
+
+#endif // LLVM_LIB_TARGET_SPIRV_SPIRVEMITINTRINSICS_H_
diff --git a/llvm/lib/Target/SPIRV/SPIRVPassRegistry.def b/llvm/lib/Target/SPIRV/SPIRVPassRegistry.def
index 1e24f636b1d17..1f81e359b6d30 100644
--- a/llvm/lib/Target/SPIRV/SPIRVPassRegistry.def
+++ b/llvm/lib/Target/SPIRV/SPIRVPassRegistry.def
@@ -19,6 +19,7 @@
 MODULE_PASS("spirv-cbuffer-access", SPIRVCBufferAccess())
 MODULE_PASS("spirv-legalize-zero-size-arrays", SPIRVLegalizeZeroSizeArrays(*static_cast<const SPIRVTargetMachine *>(this)))
 MODULE_PASS("spirv-pushconstant-access", SPIRVPushConstantAccess(*static_cast<const SPIRVTargetMachine *>(this)))
+MODULE_PASS("emit-intrinsics", SPIRVEmitIntrinsicsPass(this))
 #undef MODULE_PASS
 
 #ifndef FUNCTION_PASS
diff --git a/llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp b/llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp
index 1759b34af3e90..5f8886333e710 100644
--- a/llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp
@@ -13,6 +13,7 @@
 #include "SPIRVTargetMachine.h"
 #include "SPIRV.h"
 #include "SPIRVCBufferAccess.h"
+#include "SPIRVEmitIntrinsics.h"
 #include "SPIRVGlobalRegistry.h"
 #include "SPIRVLegalizeZeroSizeArrays.h"
 #include "SPIRVLegalizerInfo.h"
diff --git a/llvm/test/CodeGen/SPIRV/passes/SPIRVEmitIntrinsics.ll b/llvm/test/CodeGen/SPIRV/passes/SPIRVEmitIntrinsics.ll
new file mode 100644
index 0000000000000..0d35672ef900c
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/passes/SPIRVEmitIntrinsics.ll
@@ -0,0 +1,20 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; Test NPM registration of emit-intrinsics for SPIR-V (SPIRVPassRegistry.def).
+;
+; RUN: opt -S -passes=emit-intrinsics %s -mtriple=spirv64-unknown-unknown -o - | FileCheck %s
+
+define spir_kernel void @k() {
+; CHECK-LABEL: define spir_kernel void @k() {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[A:%.*]] = call ptr @llvm.spv.alloca.p0(i32 4)
+; CHECK-NEXT:    call void @llvm.spv.assign.name.p0(ptr [[A]], metadata [[META0:![0-9]+]])
+; CHECK-NEXT:    call void @llvm.spv.assign.ptr.type.p0(ptr [[A]], metadata i32 poison, i32 0)
+; CHECK-NEXT:    ret void
+;
+entry:
+  %a = alloca i32, align 4
+  ret void
+}
+;.
+; CHECK: [[META0]] = !{!"a"}
+;.

@MrSidims MrSidims left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@aobolensk aobolensk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@mgcarrasco
mgcarrasco merged commit 741eb80 into llvm:main Mar 25, 2026
9 checks passed
@ambergorzynski
ambergorzynski deleted the spirv-emit-intrinsics-npm branch March 25, 2026 16:41
Aadarsh-Keshri pushed a commit to Aadarsh-Keshri/llvm-project that referenced this pull request Mar 28, 2026
Registered SPIRVEmitIntrinsics with the new pass manager as
`spirv-emit-intrinsics`. The motivation for this is to allow it to be run from
`opt` as a standalone pass for testing purposes. A simple pipeline test
is also included to check that the registration works.
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