[cfe-dev] Generating strict LLVM IR out of C/C++ headers
John McCall
rjmccall at apple.com
Mon Jun 11 01:36:14 PDT 2012
On Jun 9, 2012, at 2:43 PM, Dmitry N. Mikushin wrote:
> Dear colleagues,
>
> Consider there is a need to mix sources and headers that are in two different high-level languages. It should be possible, if both languages are lowered down to LLVM IR and merged. But the problem is that clang is unable to generate strict IR code for headers. For example the code
>
> extern __attribute__((device)) int var;
>
> __attribute__((always_inline)) void kernel()
> {
> var = 2;
> }
>
> with
>
> clang -cc1 test.cu -emit-llvm -triple ptx64-unknown-unknown -fcuda-is-device test.cu -o -
>
> reasonably produces empty module: the only function is inline and not used.
>
> So the question: is there an easy way to generate IR with clang strictly for entire header file, with all inlined functions and unused types?
> Probably one way would be to write a plugin to add a fictive call of every function and declare fictive variable of every type, but this is stupid. Any better solution?
IIRC, LLVM's IR printer never prints types that aren't actually used. Types aren't really contained in a module like that.
__attribute__(("used")) should force the emission of a function even if it isn't called. I don't believe we have a "emit every function definition you see" mode.
John.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120611/2ab30393/attachment.html>
More information about the cfe-dev
mailing list