honggui / SPIRV-LLVM

LLVM framework with SPIR-V support. It's intended to contain LLVM <-> SPIR-V converter and serve as a foundation for LLVM-based front-end compilers targeting SPIR-V.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

LLVM/SPIR-V Bi-Directional Translator

Build Status

The khronos/spirv-3.6.1 branch of this repository contains source code for the LLVM/SPIR-V Bi-Directional Translator, a library for translating between LLVM and SPIR-V.

The LLVM/SPIR-V Bi-Directional Translator is open source software. You may freely distribute it under the terms of the license agreement found in LICENSE.txt.

Currently it accepts LLVM bitcodes compatible with SPIR 1.2/2.0 standards, and SPIR-V friendly format.

It also works together with Khronos OpenCL C compiler for SPIR-V to compile OpenCL C source code to SPIR-V.

Directory Structure

The files/directories are related to the translator:

Build Instructions

Follow the build instructions of Khronos OpenCL C compiler for SPIR-V.

Alternatively,

  1. Clone the khronos/spirv-3.6.1 branch.
  2. Follow LLVM build instructions.

Test instructions

All tests related to the translator are placed in test/SPIRV.

Execute the following command to run translator tests:

llvm-lit test/SPIRV

Run Instructions for llvm-spirv

llvm-spirv only accepts SPIR 1.2/2.0 or LLVM bitcode following a SPIR-V friendly format.

The Khronos OpenCL C compiler can be used to compile OpenCL 1.2/2.0 C source code to SPIR 1.2/2.0 or SPIR-V. It has three branches: spir_12, spir_20_provisional, and spirv-1.0, corresponding to SPIR 1.2, SPIR 2.0, and SPIR-V, respectively. The spirv-1.0 branch emits SPIR-V directly. It is recommended to use the spirv-1.0 branch since SPIR 1.2/2.0 have limitations for representing sampler types and access qualifier of image and pipe types, which may result in incorrect SPIR-V in certain cases.

To translate between SPIR 1.2/2.0 and SPIR-V:

  1. Follow the instructions provided by the Khronos OpenCL C compiler website to use clang to compile OpenCL C source code to SPIR 1.2/2.0 binary.

  2. Execute the following command to translate input.bc to input.spv

    llvm-spirv input.bc
    
  3. Execute the following command to translate input.spv to input.bc

    llvm-spirv -r input.spv
    
  4. Other options accepted by llvm-spirv

    • -o file_name - to specify output name
    • -spirv-debug - output debugging information
    • -spirv-text - read/write SPIR-V in an internal textual format for debugging purpose. The textual format is not defined by SPIR-V spec.

About

LLVM framework with SPIR-V support. It's intended to contain LLVM <-> SPIR-V converter and serve as a foundation for LLVM-based front-end compilers targeting SPIR-V.

License:Other


Languages

Language:C++ 51.6%Language:LLVM 35.9%Language:Assembly 9.1%Language:C 1.5%Language:Python 0.5%Language:OCaml 0.4%Language:Makefile 0.3%Language:CMake 0.3%Language:Go 0.2%Language:Shell 0.1%Language:M4 0.1%Language:Perl 0.0%Language:Vim Script 0.0%Language:Emacs Lisp 0.0%Language:NASL 0.0%Language:Batchfile 0.0%Language:Objective-C 0.0%Language:Monkey C 0.0%