Skip to content

Commit 4f8e766

Browse files
[AsmPrinter] Do not emit label instructions after the function body if the target is SPIR-V (#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 #102732 issue.
1 parent 5dc15dd commit 4f8e766

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1971,7 +1971,10 @@ void AsmPrinter::emitFunctionBody() {
19711971
// are automatically sized.
19721972
bool EmitFunctionSize = MAI->hasDotTypeDotSizeDirective() && !TT.isWasm();
19731973

1974-
if (EmitFunctionSize || needFuncLabels(*MF, *this)) {
1974+
// SPIR-V supports label instructions only inside a block, not after the
1975+
// function body.
1976+
if (TT.getObjectFormat() != Triple::SPIRV &&
1977+
(EmitFunctionSize || needFuncLabels(*MF, *this))) {
19751978
// Create a symbol for the end of function.
19761979
CurrentFnEnd = createTempSymbol("func_end");
19771980
OutStreamer->emitLabel(CurrentFnEnd);

llvm/test/CodeGen/SPIRV/debug-info/debug-compilation-unit.ll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ define spir_func void @foo() {
2929
entry:
3030
ret void
3131
}
32+
; CHECK-SPIRV-NOT: Lfunc_end0:
3233

3334
define spir_func void @bar() {
3435
entry:
3536
ret void
3637
}
38+
; CHECK-SPIRV-NOT: Lfunc_end1:
3739

3840
!llvm.dbg.cu = !{!0}
3941
!llvm.module.flags = !{!2, !3, !4, !5}

0 commit comments

Comments
 (0)