-
Notifications
You must be signed in to change notification settings - Fork 49
Home
Hugh Perkins edited this page Jun 26, 2017
·
20 revisions
'SPIR' is the original 'thing', that was based directly on LLVM bytecode. 'SPIR-V' is the later 'thing', that is orthogonal to llvm bytecode, but based loosely on llvm 3.2.
In order of earlier to later:
- SPIR 1.2
- SPIR 2.0
- SPIRV 1.1
- SPIRV 1.2
-
SPIR:
- contains the
clang
compiler, that can take eg OpenCL source-code, and output SPIR-V binary form - be careful to choose teh appropriate branch: by default it chagnes to
spir_12
, which is not SPIR-V, and is pretty old - the branch for the latest vailable verison of SPIR-V is spirv-1.1
- contains the
-
SPIRV-LLVM:
- fork of llvm
- contain LLVM <-> SPIR-V converter
- serves as a foundation for LLVM-based front-end compilers targeting SPIR-V
-
SPIRV-Tools
- contains assembler and disassembler, to convert between SPIR-V binary and textual form
- SPIR-V validator
- binary parser, usable from C/C++ code, to read SPIR-V binary files
-
SPIRV-Headers
- header files for various languages.
- JSON files describing the grammar for the SPIR-V core instruction set
- The XML registry file
-
SPIRV-Cross
- library for performing reflection on SPIR-V and disassembling SPIR-V back to high level languages
- download and build SPIR and LLVM-SPIRV, following this guide
- build SPIRV-Tools, following SPIRV-Tools build guide
- you can use the
llvm::ReadSPIRV
function, in the SPIRV-LLVM repo, in the llvm/Support/SPIRV.h header:
#include "llvm/Support/SPIRV.h"
...
llvm::LLVMContext Context;
std::ifstream IFS("somefile.spv", std::ios::binary);
llvm::Module *M;
std::string Err;
if (!llvm::ReadSPIRV(Context, IFS, M, Err)) {
llvm::errs() << "Fails to load SPIRV as LLVM Module: " << Err << '\n';
return;
}
- there is also a binary parser, available in the
SPIRV-Tools
repo- note that you probably need the opcode headers, from SPIRV-Headers
- very simple example, to get you started
- better (c++) example
I'm not sure the difference between these, but I assume that:
- the SPIRV-LLVM
ReadSPIRV
function allows one to bring the full power ofllvm
to bear on parsing and walking the tree - the
SPIRV-Tools
method possibly is lighter-weight, does not need one to link with llvm?