<div dir="ltr">The comment in CGCall was accurate when it was written. All backends used to handle first-class LLVM aggregates (FCA) by passing the constituent elements separately. That was never written down as a rule, so the situation has evolved.<div>
<br></div><div>I believe ARM now does something different for homogenous floating point aggregates (HFAs). It's still the case that if you pass an LLVM FCA, LLVM is allowed to take it apart and put it back together again, without preserving any padding bytes.</div>
<div><br></div><div>Depending on what you want, there are three things you can do:</div><div><br></div><div>1. Use ABIArgInfo::getDirect() and set CanBeFlattened to false. This is probably the easiest, but most LLVM optimizations don't handle FCAs very well. ARM does this for HFAs.</div>
<div><br></div><div>2. Use getIndirect(/*ByVal=*/true) to pass the argument on the stack in memory with exactly the specified layout. There will be a bytewise copy. Do this if you want the argument in memory (never in registers) and you care about the struct layout.</div>
<div><br></div><div>3. Implement custom expansion logic from the struct type to constituent member types. This is pretty much your only option if you want to pass unions in registers. This is what x86_64 SysV does for example. In the worst case, you can basically take a struct and split it up into pointer-sized ints, pass those, and reconstitute the struct on the other side.</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Aug 28, 2014 at 3:01 PM, Morgan, Zachary <span dir="ltr"><<a href="mailto:z-morgan@ti.com" target="_blank">z-morgan@ti.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div lang="EN-US" link="blue" vlink="purple">
<div>
<p class="MsoNormal">I am in the process of adding a new ABI Info to lib/CodeGen/TargetInfo.cpp.  When classifying arguments passing conventions, for small structs, we want to pass directly.  That is, in classifyArgumentType(), we return ABIArgInfo::getDirect()
 in these cases.  However, I noticed that the structure is then passed by its members individually.  So where I would expect a call of the form:<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">    foo(struct s)<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I instead find<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">    foo(member1, member2, …)<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">This change in calling convention occurs in lib/CodeGen/CGCall.cpp – in each case near a comment stating that “If the coerce-to type is a first class aggregate, we flatten it” and further asserting that either way is semantically identical. 
 I would presume this can only be true only if padding of structures is equivalent to padding and promotions of values on the stack.  The test case I am looking at contains the use of the following as a parameter:<u></u><u></u></p>

<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">typedef struct S<u></u><u></u></p>
<p class="MsoNormal">{<u></u><u></u></p>
<p class="MsoNormal">    char a;<u></u><u></u></p>
<p class="MsoNormal">    char b;<u></u><u></u></p>
<p class="MsoNormal">    char c;<u></u><u></u></p>
<p class="MsoNormal">} S;<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">As a whole, the struct will fit within at least 32 bits on the stack.  When the members are separated, due to promotions, the struct will take up 3 * sizeof(int) on the stack.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I’m fairly certain that what I want to do is pass the arguments directly as stated above, but I wanted to check and see if there is a more preferred way for handling this.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Thanks,<u></u><u></u></p>
<p class="MsoNormal">Zachary Morgan<u></u><u></u></p>
</div>
</div>

<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" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div>