LLVM Image Activator
Nathan Whitehorn
nwhitehorn at freebsd.org
Mon Jan 7 16:46:00 UTC 2013
On 01/07/13 08:25, David Naylor wrote:
> Hi,
>
> Just my 2c
>
> On Sunday, 6 January 2013 20:02:21 Nathan Whitehorn wrote:
>> Having LLVM/clang in the base system lets us do some interesting things
>> that we couldn't do with GCC. One is that LLVM ships with a JIT for LLVM
>> IR as well as components of a toolchain for it (this is what Google's
>> pNACL uses) and that you can end up producing binary files that are in
>> IR instead of native code. The IR isn't really cross-platform, but does
>> let you do CPU-specific optimizations when executed by the JIT, etc.
>>
>> The attached patch causes the LLVM JIT (lli) to be built by default
>> (adding ~20 seconds to buildworld on my five-year-old laptop) and adds a
>> kernel image activator that invokes it when passed LLVM bitcode files.
>> It's not completely finished (see the XXX comment in the middle), but it
>> does work, as follows:
>>
>> $ clang -emit-llvm -c -o hw.ll hw.c
>> $ file hw.ll
>> hw.ll: LLVM bitcode
>> $ lli hw.ll
>> Hello world!
>> $ chmod a+x hw.ll
>> $ ./hw.ll
>> Hello world!
>> $
>>
>> Is there any interest in having features like this? It seems like this
>> could provides some interesting possibilities for us and nice
>> integration from having imported clang into base.
>
> Would it be possible to have this as a module (and thus in ports)? Or,
> perhaps, change the sources such these things could be loaded as a module...
We do support that, but I'm not really sure what would be gained. We
have LLVM in base; it seems a shame not to use it.
> Also, with modification to LLVM, wouldn't the existing '#!' mechanism work
> (aka '#!/usr/bin/lli') at the beginning of the file?
In principle, yes, but we'd have to coordinate that with a lot of
players since a number of tools operate on LLVM bitcode. The other
obstacle is that LLVM bitcode is a giant binary blob, not text, so the
standard #! seems a little out of place.
> On an aside. Could you imagine shipping a 'x86' llvm-byte code and get the
> jit (with caching), thus your computer will get full support (speed) from the
> binaries and the binaries will work on all 'x86' related architectures. (My
> thinking is for things like i386 vs pentium4).
>
Yes, this is exactly the kind of thing I had in mind.
-Nathan
More information about the freebsd-toolchain
mailing list