llvm / llvm/llvm-project

[SPIRV] llvm.used and related variables not properly handled

Open
#179,973 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

backend:SPIR-V
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Previously, there was no special handling for variables like llvm.used in the SPIR-V backend, so the backend would just try to emit them as normal variables.

This caused many problems, one common example is the constant initializer for the variables would contain IR that illegal and cannot be legalized (ex. addrspacecast from UniformConstant to Generic), so the backend would blow up saying these instructions are illegal.

So, changes were made to skip emission of these variables and any types defined by them, see the PRs at the bottom of this bug report.

However, if we take a step back, it's not totally clear what these variables should do in SPIR-V.

For example, the llvm.used definition is If a symbol appears in the @llvm.used list, then the compiler, assembler, and linker are required to treat the symbol as if there is a reference to the symbol that it cannot see (which is why they have to be named)., but it's unclear what compiler, assembler and linker mean in this context (reference)

In addition, out-of-tree tools are required to use SPIR-V with Clang, such as spirv-as and spirv-link, and these tools seem to optimize out unreferenced variables today.

We need to:

  1. Define what llvm.used and related variables should do in SPIR-V
  2. Determine what impact the results of 1) have on the SPIR-V backend as well as out-of-tree tools such as those in SPIRV-Tools
  3. Possibly define a new SPIR-V extension
  4. Implement any changes to the relevant software projects

See the below PRs for context:

https://github.com/llvm/llvm-project/pull/162678
https://github.com/llvm/llvm-project/pull/179498

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the linked LLVM pull requests and the definitions of llvm.used and related variables in the issue. Then determine the intended SPIR-V behavior and its impact on the SPIR-V backend, spirv-as, and spirv-link; done requires agreed semantics and any resulting implementation changes.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.