<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Jan 20, 2015 at 9:52 AM, Rodney M. Bates <span dir="ltr"><<a href="mailto:rodney_bates@lcwb.coop" target="_blank">rodney_bates@lcwb.coop</a>></span> wrote:<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
1)  Larger structs are returned differently, via memcpy.  Do<br>
    these methods of returning struct values show through in<br>
    the ultimately generated machine code?  It seems hard to<br>
    imagine that, of the many different target code generators<br>
    in llvm, there would not be at least some with standardized<br>
    ABIs that differ in such respects.  Does llvm make target-<br>
    dependent transformations for different targets to match<br>
    their ABIs?  Or do I have to do that at the level of generating<br>
    llvm IR?<br></blockquote><div><br></div><div>LLVM handles the low-level ABI details like what registers to use for arguments, but frontends unfortunately need to handle lots of ABI issues around struct passing. LLVM isn't really responsible for transforming IR to make it match any particular ABI.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
2)  To correctly return the value using a bitcast, as in the example, the<br>
    front end has to independently and correctly duplicate the layout that<br>
    llvm will produce.  This seems both very fragile and difficult to<br>
    diagnose when it fails.  My front end already does record layout, but<br>
    I had previously decided, after a discussion on this list, that it was<br>
    better to let llvm do it.  Any advice on the best way here?<br></blockquote><div><br></div><div>Personally, I wouldn't recommend letting LLVM do struct layout. I would recommend creating high-level LLVM struct types, but the frontend should use packed struct types to precisely control the layout. In that way, the frontend can still make assumptions about the exact layout in memory. Make sense?</div><div><br></div><div>In this particular case, probably all you need to know is the size of the struct, and notice that it is small. I would try to find the Sys V ABI docs to get the threshold or check the Clang source code.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
3)  I am also a little worried about the implications of returning an<br>
    i16, with alignment of 1.  Won't this create trouble somewhere, or<br>
    at least lose some benefit of returning as a scalar?</blockquote><div><br></div><div>First, the optimizer will typically remove the alloca and the load. Second, the low alignment on the alloca and load looks like a bug in Clang.</div></div></div></div>