AIR is the LLVM IR dialect used by Metal. AIR shader binaries are guaranteed to run unmodified on a future operating system release.
However, Apple explicitly chose to not document AIR, making the Metal Shading Language the only officially supported input language.
The compiler
metal, the compiler, supports two input languages under the hood. But only one of which is exposed through public API, the Metal Shading Language.
That second input language is OpenCL, usable through --driver-mode=openclc -x cl
. That’s what Apple’s OpenCL implementation on M1 uses under the hood. It’s an internal implementation detail not exposed to developers.
The Metal tool set as shipped as part of Xcode does not ship with opencl-c.h however, and the resulting binaries do not seem to be loadable through clCreateProgramWithBinary.
Offline compilation
In the Metal API, offline compilation is a first-class citizen. Apple does ship metal-as as an AIR assembler, a disassembler for AIR (metal-objdump) and a linker (metallib).
At runtime, Metal doesn’t take LLVM bitcode files directly (.air, equivalent to .bc), but does take linked programs (.metallib).
Online compilation
Online compilation is also available. However, options are quite limited there, without possibility to pass compiler arguments or even custom include paths.
For the OpenCL implementation, argument filtering is also done, to block non-allowlisted arguments from being passed through to the compiler.
AIR versions
This section is a work in progress.
AIR is versioned, with the version number shared with the Metal Shading Language version
Multiple different GPUCompiler libraries ship with macOS. Version 3802, 3902, 31001