[llvm] [SPIRV] Add pass SPIRVEmitIntrinsics to new pass manager (PR #188285)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 25 02:46:48 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-spir-v
Author: ambergorzynski
<details>
<summary>Changes</summary>
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
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"}
+;.
``````````
</details>
https://github.com/llvm/llvm-project/pull/188285
More information about the llvm-commits
mailing list