[LLVMdev] Structs as first class values.

Matthijs Kooijman matthijs at stdin.nl
Mon Jul 21 06:37:45 PDT 2008


Hi Rich,


> I was thinking about my problem and thought that there might be a good 
> interim solution. I would like not to clutter my front end with stuff 
> that will go away. How about a pass that runs before code generation 
> that changes functions returning structs to void functions with the 
> return pointer first parameter?
On this topic, you should look at the StructRetPromotion pass
(lib/Transforms/IPO/StructRetPromotion.cpp). This pass does exactly the
opposite of what you propose: It transforms return pointers in the first
parameter to first class returns.

This pass only operates on internal functions, though, so it does not have to
deal with ABI issues. If you want to support the C ABI (which requires a
pointer in the first argument to return any struct AFAIK), you might be better
off generating such code in your frontend. Any internal function can then be
simplified by the sretpromotion pass (perhaps it could be modified to take an
option for the maximum number of elements to put in the real return struct?)

Not sure how to go about this exactly, but perhaps this helps a bit.

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/llvm-dev/attachments/20080721/249574f5/attachment.sig>


More information about the llvm-dev mailing list