2

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?

eawang
  • 21
  • 1
  • You mean, besides the fact that SPIR-V is directly consumed by two APIs for doing graphics and compute operations (Vulkan and OpenCL), while LLVM is not? – Nicol Bolas Feb 24 '22 at 14:34

2 Answers2

3

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.

Andrea
  • 19,134
  • 4
  • 43
  • 65
1

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.

BZKN
  • 1,499
  • 2
  • 10
  • 25