<div dir="ltr">I agree it would be really nice to build a library for ABI lowering, but any solution that isn't clang or isn't ultimately picked up by clang will necessarily be incomplete. Perhaps that is OK for your frontend's uses, but I think it's the main reason that we haven't done something like this in LLVM already.<div><br></div><div>Any solution that doesn't involve actual Clang ASTs is unlikely to be able to represent all C-with-extensions types (unions, bitfields, alignment attributes, transparent_union attribute). I took a look at Type.hpp in your project, and it seems to be missing some of these things. Keeping such a library up to date with new extensions is going to be a maintenance burden.</div><div><br></div><div>That said, I wish you luck, and I hope the project eases some of the difficulties for new frontends. It is very possible that the corner cases that keep me up at night are not the problems that users actually face. :)</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jun 28, 2015 at 3:22 PM, Stephen Cross <span dir="ltr"><<a href="mailto:scross@scross.co.uk" target="_blank">scross@scross.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi everyone,<br>
<br>
(Also CC'ed cfe-dev since this seems relevant to Clang, particularly<br>
the questions at the end.)<br>
<br>
I've been working on a library to generate LLVM IR that complies with<br>
platform ABIs (the current focus is on C but I'm also interested in<br>
ABIs for other languages).<br>
<br>
You can find it here: <a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_scross99_llvm-2Dabi&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6GUNn7_wosSM&m=8Uj9zNmgatq7-h8sZTCvI400afg93OJyccrOj3g8x0o&s=fwhypz_BxOEGl4iIoNEsw-GKRvyo4OyIWQ7QBlg5Q-g&e=" rel="noreferrer" target="_blank">https://github.com/scross99/llvm-abi</a><br>
<br>
To explain further (for those who are unfamiliar), LLVM frontends have<br>
to modify function argument types, attributes etc. in order to ensure<br>
the backend generates code that satisfies the ABI; this is needed<br>
because LLVM's type system can't encode all the necessary information.<br>
This is a complex task and involves substantial amounts of<br>
target-dependent logic. Clang performs this encoding and indeed much<br>
of the current functionality is derived from Clang's source.<br>
<br>
This project originated as a necessary piece of functionality for the<br>
Loci compiler frontend [1] and is now an external dependency; my aim<br>
is to make this usable for other LLVM frontends that also need to<br>
generate ABI-compliant IR (I assume this is a fairly large subset of<br>
the frontends).<br>
<br>
I'd be very interested in any suggestions/queries/comments.<br>
<br>
I made a few interesting discoveries while working on this:<br>
<br>
* Clang generates 8 byte alignment for 16+ byte arrays on x86-64, even<br>
though the AMD64 ABI seems to require that arrays of 16+ bytes are<br>
aligned to 16 bytes. Is this a bug or am I missing something obvious?<br>
<br>
* Clang determines the features for a CPU (e.g. whether we have AVX<br>
support on x86-64 CPUs), even though this functionality is already<br>
available in LLVM (but appears to be very difficult to query). Would<br>
it be possible to expose the information from LLVM and hence eliminate<br>
the duplication in Clang?<br>
<br>
* Clang determines a 'generic CPU' if the user doesn't specify a CPU.<br>
My understanding is that we don't usually generate code for the native<br>
CPU because it may have features unavailable on other similar CPUs.<br>
LLVM can provide full details of the native CPU but can't determine a<br>
generic CPU; could this functionality be added to LLVM?<br>
<br>
(Separately I've also been considering a proposal to add ABI<br>
information directly inside LLVM IR in a language-independent way and<br>
I'll discuss this in a later email.)<br>
<br>
Thanks,<br>
Stephen<br>
<br>
[1] <a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_scross99_locic&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6GUNn7_wosSM&m=8Uj9zNmgatq7-h8sZTCvI400afg93OJyccrOj3g8x0o&s=6x_kStye9CHHYxbcFBI6xolEA4LkLfqwSfgn7un8CPk&e=" rel="noreferrer" target="_blank">https://github.com/scross99/locic</a><br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br></div>