'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?
Solution 1:[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.
Solution 2:[2]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | BZKN |
| Solution 2 | Andrea |
