[cfe-dev] Passing StructType arguments directly

David Meyer pdox at google.com
Mon Sep 19 13:13:38 PDT 2011


John,

> I'm not asking you to undergo code review, which would happen in any
> case.  I'm asking you to verify that your technical direction is acceptable
> downstream before muddying up clang with code that's only useful if it is.

I most certainly will get the blessings of llvmdev and Chris before
embarking on any major technical changes.

But LLVM already has struct types which can be passed directly. It
makes perfect sense for Clang to be able to emit this, and the patch
is trivial. How many other people have asked for or may want this
feature?

Also, this change is immediately useful to us without any changes in
technical direction. See my comments below.

>
>> In either case, PNaCl will definitely be using direct struct passing,
>> whether or not we can make the result match the platform ABI, so
>> there's no controversy over the code written so far.
>
> But if you don't care about matching the platform ABI, there's no reason
> you can't use byval and/or indirection.

We *do* care about matching the platform ABI, and we also care about
performance (register-passing for small structs). Using byval in the
usual sense would commit us to passing structs on the stack.

Using the non-byval struct argument form is crucial for two reasons:

1) The front-ends don't already expect this form to work in a certain
way, which gives us the ability to fix how it is handled in the
backends. With the information already stored in bitcode, we can lower
"simple" structures correctly in the LLVM target backends, even for
the X86-64 ABI. For our needs, even partial compliance is a lot better
than no compliance at all. Other users of this form may also
appreciate having the expansion better match the target ABI.

Right now, struct arguments are flattened element by element, which
creates a non-standard calling convention. My understanding is that
the original intent was to do the correct ABI lowering here, but those
plans were scaled back because of the missing ABI information.

2) Using this form doesn't require us to create a copy to obtain a
pointer (in SelectionDAGBuilder). It requires the front-ends to do
this in the bitcode, but opt can optimize this out.

- pdox




More information about the cfe-dev mailing list