This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: SPIR-V and GCC
- From: BogDan <bog_dan_ro at yahoo dot com>
- To: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Cc: David Malcolm <dmalcolm at redhat dot com>
- Date: Fri, 6 Mar 2015 15:23:21 +0000 (UTC)
- Subject: Re: SPIR-V and GCC
- Authentication-results: sourceware.org; auth=none
- References: <1425487411 dot 8624 dot 152 dot camel at surprise>
- Reply-to: BogDan <bog_dan_ro at yahoo dot com>
[...]
> This http://www.g-truc.net/post-0714.html great article explans better
> what SPIR-V is.
Another use-case that occurred to me when I was looking at the link you
posted above: using gcc for optimizing SPIR-V and compiling it e.g. to
CPU code.
As of gcc 5, libgccjit can be hooked up to a pre-existing language
frontend, with the gcc backend emitting machine code for the CPU,
assuming that the frontend is license-compatible with libgccjit's
GPLv3-or-later. See this example, which uses libgccjit to build a
compiler for brainf**k:
https://gcc.gnu.org/onlinedocs/jit/intro/tutorial05.html
So if there's a SPIR-V loader library that's license-compatible, you
could write code to inject SPIR-V into libgccjit, and call
gcc_jit_context_compile_to_file on it to optimize it and turn it into
machine code.
That use-case is probably doable today using gcc 5 (and could be written
in C, C++, Python, or D, with the bindings we already have).
Potentially such a library could also generate other kinds of code,
including e.g. optimized SPIR-V... but that requires both (i) a gcc
backend for the desired target code and (ii) libgccjit to support
cross-compilation (which as I mentioned would probably be a gcc 6
thing).
[...]
Yep, that's another use-case, which might be used by free drives (Intel, AMD, Lima, etc.).
[...]
I'm probably not the best person to help, as I've not written a gcc
backend (the jit counts as a frontend, albeit a very unusual one). FWIW
there seems to be a good tutorial on writing backends here:
http://www.cse.iitb.ac.in/grc/intdocs/gcc-writing-md.html
[...]
Thanks a lot for the link, it helped me a lot (I found this [0] one quite good).
I checked them a little bit and I'm afraid it might be a a few problems to create a SPIR-V backend:
1. SPIR-V a binary Intermediate Language format but it's still not machine code. It seems gcc backends produces a text machine code, so I think will not be possible to produce SPIR-V a binary format directly from GCC backend.
2. Because SPIR-V is not a machine format, it doesn't have any registers. Instead it's using IDs for everything [1]. I didn't find a way to create IDs instead of registers in GCC.
3. SPIR-V supports some "non-standard" types[2], will it be a problems to support these types in GCC frontend/backend?
Cheers,
BogDan.
[0] https://gcc.gnu.org/onlinedocs/gccint/Back-End.html#Back-End
[1] https://www.khronos.org/registry/spir-v/specs/1.0/SPIRV.html#_instructions
[2] https://www.khronos.org/registry/spir-v/specs/1.0/SPIRV.html#_types