[Mesa-dev] [PATCH] radeon/llvm: Use LLVM C API for compiling LLVM IR to ISA.

Mathias Fröhlich Mathias.Froehlich at gmx.net
Sat Apr 27 01:33:29 PDT 2013


Hi,

On Thursday, April 25, 2013 10:29:27 Jose Fonseca wrote:
> - There are a bunch of options that need to be set via globals, (see
> lp_set_target_options), so app/drivers could tamper with each other
> options.
>
> - llvm::cl::ParseCommandLineOptions will complain if called multiple times
> -- I think we no longer need to call it these days though
>
> In short, LLVM was not designed for multiple users in the same process.
Yep.

Also llvm is still emerging too fast to assume a specific version to be 
available. At least with r600 we do currently need a somewhat recent version 
and kind of have this assumption.
But due to the api not kept strictly backwards compatible and all the pitfalls 
that happen while emerging fast its very likely that a potential application 
that also tries to make use of the driver modules just brings its own probably 
incompatible llvm version in some way. So shielding this in any way makes 
sense ...


For the Mesa wrappers:
I have attached a shell script again as a rapid proof that is able to build a 
linker script that builds up a wrapper shared library that contains a private 
llvm copy. That's again non optimal - it contains just all static libs that I 
have in my current test environment... It's just to sketch how this could 
work.

The MesaLLVM-with-prefix.link script can by used with the command

g++ -shared -o libMesaLLVM.so MesaLLVM-with-prefix.link

to produce a libMesaLLVM.so that contains all C symbols starting with LLVM 
from libLLVMCore.a. All of them get prefixed with Mesa and are the only 
exported symbols then.
That's close to Joses suggestion but with less work to be done in sources.

The MesaLLVM-with-version.link script can by used with the command

g++ -shared -o libMesaLLVM.so MesaLLVM-with-version.link

to produce a libMesaLLVM.so shared library that uses symbol versioning to 
distinguish between the llvm versions. I got this idea yesterday and this 
might simplify the problem a lot.
By this variant we do not even need to prefix all the callers by Mesa. What 
this does is to explicitly assign a symbol version to all these calls. At 
static link symbol resolve time with this libMesaLLVM.so, this symbol version  
(the 'A MesaLLVM_1.0' entry) is then pulled out of this shared object and all 
users, in libllvmradeon.so for example, are linked against 
LLVMCreateContext at MesaLLVM_1,0 instead of just LLVMCreateContext. So we should 
get a private copy of llvm in libMesaLLVM.so with just the same call names 
than usual source code wise.
That's to be tested and verified, but if this works like I think it should, 
this is the easiest way to get our own LLVM version on linux at least.

And sorry for just doing these crude proof of concept stuff ...

Greetings

Mathias
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mklinkerscript.sh
Type: application/x-shellscript
Size: 925 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20130427/0445aa17/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: MesaLLVM-with-prefix.link
Type: text/x-csrc
Size: 32971 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20130427/0445aa17/attachment-0002.c>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: MesaLLVM-with-version.link
Type: text/x-csrc
Size: 11273 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20130427/0445aa17/attachment-0003.c>


More information about the mesa-dev mailing list