[llvm] [AsmPrinter] Do not emit label instructions after the function body if the target is SPIR-V (PR #107013)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 2 12:28:00 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-spir-v
Author: Vyacheslav Levytskyy (VyacheslavLevytskyy)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/107013.diff
2 Files Affected:
- (modified) llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (+3-1)
- (modified) llvm/test/CodeGen/SPIRV/debug-info/basic-global-di.ll (+2)
``````````diff
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}
``````````
</details>
https://github.com/llvm/llvm-project/pull/107013
More information about the llvm-commits
mailing list