[LLVMdev] Union support in LLVM

James Lyon jameslyon0 at gmail.com
Sun Dec 12 04:15:43 PST 2010


Hi,

I'm working on developing a programming language using LLVM as a
backend, and it'd be very handy for me if LLVM had union support. I've
been looking into getting the previous union implementation working
properly for the last week or so, but I'm entirely new to the LLVM
codebase so I thought I'd ask whether I'm barking up the wrong tree
before doing a full-blown implementation. At the moment it seems like
the best approach to get unions working is to treat them as a byte array
and then have the insertvalue/extractvalue instructions automatically
perform conversions to and from other types by bitcasting to/from an
equivalent size i8 vector where the bytes can be got at individually.

This approach seems to have a few problems. It gets vector instructions
involved without any really good reason (I'm looking at the assembler
output). It also seems to violate the ABI - my test function is trying
to return the result in memory where I think it should be using
registers (I'm JITing a function and calling it using GCC compiled
code). The x86-86 ABI isn't very clear to me though.

Anyway, please let me know if anyone sees major problems with this
approach, or has any thoughts on the ABI issues.

Regards,

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


More information about the llvm-dev mailing list