Repository navigation
[SPIRV] Add pass SPIRVEmitIntrinsics to new pass manager - #188285
Merged
Merged
Conversation
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
ambergorzynski
marked this pull request as ready for review
March 25, 2026 09:45
Member
|
@llvm/pr-subscribers-backend-spir-v Author: ambergorzynski ChangesRegistered SPIRVEmitIntrinsics with the new pass manager as For discussion - I used the name 5 Files Affected:
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
approved these changes
Mar 25, 2026
aobolensk
reviewed
Mar 25, 2026
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Registered SPIRVEmitIntrinsics with the new pass manager as
emit-intrinsics. The motivation for this is to allow it to be run fromoptas 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-intrinsicsfor consistency with the legacy pass manager and the existing pass name. Alternatively, we could update the registered name tospirv-emit-intrinsicseverywhere for consistency with the other SPIRV passes that are registered with the new pass manager, which are prefixed withspirv.