[cfe-dev] Direct Argument Passing in Clang

Morgan, Zachary z-morgan at ti.com
Thu Aug 28 15:01:29 PDT 2014


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:

    foo(struct s)

I instead find

    foo(member1, member2, ...)

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:

typedef struct S
{
    char a;
    char b;
    char c;
} S;

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.

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.

Thanks,
Zachary Morgan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140828/5772d430/attachment.html>


More information about the cfe-dev mailing list