[LLVMdev] A new mechanism to compiler kernel modules using llvm: Defer type evaluation in clang?

Joshua Cranmer pidgeot18 at gmail.com
Mon Apr 29 07:38:17 PDT 2013


On 4/29/2013 9:13 AM, Jovi Zhang wrote:
> We arrived the key part:  offsetof and sizeof are resolved to a
 > constant by Clang before they are lowered to LLVM IR, so that's the
 > main reason why there have a high-level IR file except LLVM IR file,
 > that high-level IR file contain unresolved structure field reference
 > info and unresolved sizeof, that high-level IR file "link" with
 > kernel header ABI file which contain structure offset and sizeof
 > info, then generate to LLVM IR file, this is the design picture.
 >
 > I don't want to change LLVM IR format, I'm just thinking on hack
 > Clang to output that high-level IR file without resolved
 > offset/sizeof info, how about this sounds?

I think that is much less feasible then it sounds. Since offsetof/sizeof 
are both compiled to a constant, they are both compile-time constants. 
In particular, you can do things in C like:

#if sizeof(T) == 10
...
#endif

This means that the only truly portable way to late-resolve 
offsetof/sizeof is to save the source code of the program and compile it 
as late as possible. I'm skeptical that you could convince all the 
stakeholders you would need to support this approach, especially since 
you are probably neither willing to implement any optimizations on your 
"high-level IR" nor able to make it close enough to LLVM IR to reuse 
LLVM's optimization passes--as a result, you would pretty much be 
distributing the source code to your driver module, just without the 
comments and less resilient to kernel changes than the original source.

-- 
Joshua Cranmer
News submodule owner
DXR coauthor

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130429/d008124d/attachment.html>


More information about the llvm-dev mailing list