[LLVMdev] Question about 'byval'

Bob Wilson bob.wilson at apple.com
Fri Sep 10 21:24:52 PDT 2010


On Sep 10, 2010, at 4:24 PM, Yuan Lin wrote:

> Hello, I am seeking a clarification of the semantics of ‘byval’ parameter attribute in llvm IR.
>  
> Let’s assume the ABI says the caller should create the ‘hidden copy’ of the pointee. My question is which part of the compiler chain should generate the alloca and copy code. My understanding is that it is the target code generator, not the provider of the llvm IR.
>  
> But given the following simple test case,
>  
> typedef struct {
>     int a;
>     int b[1000];
> } A;
>  
> void bar(A s) {
>     s.a = 1;
> }
>  
> void foo(void) {
>     A s;
>     s.a = 100;
>     bar(s);
> }
>  
> I see ‘clang’ generates an extra copy in foo() and the parameter for bar() also has the ‘byval’ attribute.
>  
> Running the generated bc file through various backends , I see different behaviors,
> - x86 and ppc32 create yet another copy on the caller site, while
> - arm, sparc, and mips do not.
>  
> What am I missing? Thanks.

The ARM backend does not support "byval", at least not very well.  It wouldn't surprise me if the same is true for Mips and Sparc.  The X86 and PPC behavior is what you want to look at.

>  
> -- Yuan
>  
>  
>  
> This email message is for the sole use of the intended recipient(s) and may contain confidential information.  Any unauthorized review, use, disclosure or distribution is prohibited.  If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
> 
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev





More information about the llvm-dev mailing list