[cfe-dev] Passing structs byval

Matthijs Kooijman matthijs at stdin.nl
Mon Apr 28 02:11:22 PDT 2008


Hi,

I'm looking at the argpromotion optimizer pass in LLVM, but it doesn't seem to
reliably work right now in combination with clang (didn't try with llvm-gcc).

When passing a struct to a function, clang currently generates a call to
memcpy and passes the pointer to the (temp copy of the) struct to the
function. ArgPromotion can succesfully promote this struct argument (i.e.,
replace it by multiple scalar arguments) but only if the called function does
not modify the struct.

Now, on to my actual question. Why does clang do this memcpy trick in the
frontend? Wouldn't it be more flexible to simply pass the struct pointer byval
to the function and let the codegenerator or a later optimization step add the
memcpy (if still needed)? Is this a deliberate choice (perhaps because the
codegen doesn't support byval properly yet?), or is it simply generic
handling of structs that causes this (from looking at the code, it looks like
this).

Any suggestions on how and where to implement this byval passing of structs?
I'm still digging around in the source code, following call paths to see what
actually happens right now :-)

Gr.

Matthijs
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20080428/acd7db3b/attachment.sig>


More information about the cfe-dev mailing list