[llvm] [AsmPrinter] Do not emit label instructions after the function body if the target is SPIR-V (PR #107013)
Vyacheslav Levytskyy via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 2 11:33:54 PDT 2024
https://github.com/VyacheslavLevytskyy created https://github.com/llvm/llvm-project/pull/107013
AsmPrinter always creates a symbol for the end of function if valid debug info is present. However, this breaks SPIR-V target's output, because SPIR-V specification allows label instructions only inside a block, not after the function body (see https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpLabel). This PR proposes to disable emission of label instructions after the function body if the target is SPIR-V.
This PR is a fix of the https://github.com/llvm/llvm-project/issues/102732 issue.
>From 95eb6f4859decb56c79f25f5c77ea71a1c9f7547 Mon Sep 17 00:00:00 2001
From: "Levytskyy, Vyacheslav" <vyacheslav.levytskyy at intel.com>
Date: Mon, 2 Sep 2024 11:21:19 -0700
Subject: [PATCH] do not emit label instructions after the function body if the
target is SPIR-V
---
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 4 +++-
llvm/test/CodeGen/SPIRV/debug-info/basic-global-di.ll | 2 ++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 19d23c8ba96783..439aefccb59b26 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -1960,7 +1960,9 @@ void AsmPrinter::emitFunctionBody() {
// are automatically sized.
bool EmitFunctionSize = MAI->hasDotTypeDotSizeDirective() && !TT.isWasm();
- if (EmitFunctionSize || needFuncLabels(*MF, *this)) {
+ // SPIR-V supports label instructions only inside a block, not after the
+ // function body.
+ if (!TT.isSPIRV() && (EmitFunctionSize || needFuncLabels(*MF, *this))) {
// Create a symbol for the end of function.
CurrentFnEnd = createTempSymbol("func_end");
OutStreamer->emitLabel(CurrentFnEnd);
diff --git a/llvm/test/CodeGen/SPIRV/debug-info/basic-global-di.ll b/llvm/test/CodeGen/SPIRV/debug-info/basic-global-di.ll
index 139a8e11182bcc..a63f01b8c64a24 100644
--- a/llvm/test/CodeGen/SPIRV/debug-info/basic-global-di.ll
+++ b/llvm/test/CodeGen/SPIRV/debug-info/basic-global-di.ll
@@ -29,11 +29,13 @@ define spir_func void @foo() {
entry:
ret void
}
+; CHECK-SPIRV-NOT: Lfunc_end0:
define spir_func void @bar() {
entry:
ret void
}
+; CHECK-SPIRV-NOT: Lfunc_end1:
!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!2, !3, !4, !5}
More information about the llvm-commits
mailing list