Skip to content

[SPIR-V] Unexpected label emitted in SPIRVAsmPrinter when debug info is present #102732

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
seven-mile opened this issue Aug 10, 2024 · 2 comments
Closed

Comments

@seven-mile
Copy link
Contributor

seven-mile commented Aug 10, 2024

I used -g to emit debug info in Clang and get a LLVM IR module. When I tried to invoke llc and use SPIR-V backend to emit the final SPIR-V, an unexpected label is emitted after OpFunctionEnd:

... omitted
        OpBranchConditional %56 %61 %59
        %59 = OpLabel
        OpReturn
        OpFunctionEnd
Lfunc_end0:
                                        ; -- End function

, which prevented the SPIR-V to be consumed by spirv-as. After disabling -g, the label is gone. I believe it's caused by these lines in the base class AsmPrinter:

if (EmitFunctionSize || needFuncLabels(*MF, *this)) {
// Create a symbol for the end of function.
CurrentFnEnd = createTempSymbol("func_end");
OutStreamer->emitLabel(CurrentFnEnd);
}

We need some overrides to disable this behaviour for SPIR-V.

@VyacheslavLevytskyy
Copy link
Contributor

@seven-mile Thank you for the report! I don't see any good workarounds using existing hooks/overrides. needFuncLabels() is always true if we have debug info, and a flag for the debug info is private (

bool DbgInfoAvailable = false;
).

A path that I see is that we fix it as a part of AsmPrinter.cpp itself by checking !TT.isSPIRV() before emitting a label after the function body and referring to the SPIR-V specification that supports label instructions only inside a block, not after the function body.

VyacheslavLevytskyy added a commit that referenced this issue Sep 24, 2024
…f 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.
@seven-mile
Copy link
Contributor Author

Resolved by #107013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants