eawang
eawang

Reputation: 21

what is the most fundamental difference between SPIR-V and LLVM-IR?

Spir-v and LLVM IR have the same granularity and can be converted to each other. May I ask why SPir-V is still so popular with LLVM IR? The fundamental difference between the two?

Upvotes: 2

Views: 1220

Answers (2)

mystery
mystery

Reputation: 19513

Unlike SPIR-V, LLVM IR is:

  • Unstable, changing every LLVM release
  • Neither forwards nor backwards-compatible in textual form
  • Only backwards-compatible in binary form — newer LLVM versions can't produce binary IR that older versions can consume
  • Complex and irregular structure
  • Difficult to read or write without creating a dependency on LLVM, which is a massive project
  • Not standardised
  • Highly specific to LLVM's needs as a compiler, not being suited to other compilers or purposes other than an internal representation
  • Limited extensibility (intrinsics and custom metadata exist, but they don't look or behave like the built-in instructions)
  • Not portable (IR encodes platform-specific characteristics)
  • Does not directly support many features needed by GPUs: textures, images, buffers, attributes, control over warp divergence, subgroup operations, variable precision…

Many projects have tried to use LLVM bitcode as a “universal bytecode” and many have regretted it. SPIR-V itself was created to replace SPIR which was based on LLVM IR.

The most important difference though is that Vulkan and OpenGL can directly consume SPIR-V, and SPIR-V is usable for shaders, not just compute kernels.

Upvotes: 3

BZKN
BZKN

Reputation: 1709

LLVM-IR is a very coherent single IR threading through the majority layers of the compiler stack and the LLVM-IR focuses very much as a means for compiler transformations. SPIR-V is actually a mix of multiple things. For instance, the SPIR-V memory model was built on the foundation of the C++ memory model, but ended up diverging in a number of places. Hence, an obvious addition to the answer by Yugr is, beside instruction set, a fundamental difference is a memory model.

Upvotes: 1

Related Questions