Hi, all When I compile the C code containing the next statement to LLVM, *struct A const o = func(...);* I got the next corresponding LLVM bytecode *call void @func(%struct.A* noalias sret %o, ...)* Could you tell me why function "func" with a return value is changed to be one with a void return value and another more parameter %o. Does "noalias sret" play a special role? What is the exact meaning of "noalias sret"? Thank you all in advance. -------------------------------------------- Qiuping Yi Institute Of Software Chinese Academy of Sciences -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150716/a1db0dac/attachment.html>
> Could you tell me why function "func" with a return value > is changed to be one with a void return value and another > more parameter %o. Does "noalias sret" play a special role?Have you found the reference page for LLVM IR yet? It describes sret: http://llvm.org/docs/LangRef.html> What is the exact meaning of "noalias sret"?The "sret" (struct-return) is the important one. When a struct gets too big (as decided by the ABI writers) to be returned directly, what often happens is that the caller has to allocate storage for the object and pass this pointer to the function being called. Because this demotion is often handled differently from a normal argument (AArch64 requires register "X8" to be used; as I recall x86 requires the pointer to be re-returned) we need a special argument attribute to mark this so that the correct code can be generated. "noalias" is just an optimisation hint: because of how this argument came to exist (allocated by the caller directly before the call), no other pointer accessible to the function can alias it. This allows some useful transformations in the mid-end. Cheers. Tim.
Got it, thank you for your perfect answer. -------------------------------------------- Qiuping Yi Institute Of Software Chinese Academy of Sciences On Thu, Jul 16, 2015 at 12:08 PM, Tim Northover <t.p.northover at gmail.com> wrote:> > Could you tell me why function "func" with a return value > > is changed to be one with a void return value and another > > more parameter %o. Does "noalias sret" play a special role? > > Have you found the reference page for LLVM IR yet? It describes sret: > http://llvm.org/docs/LangRef.html > > > What is the exact meaning of "noalias sret"? > > The "sret" (struct-return) is the important one. When a struct gets > too big (as decided by the ABI writers) to be returned directly, what > often happens is that the caller has to allocate storage for the > object and pass this pointer to the function being called. > > Because this demotion is often handled differently from a normal > argument (AArch64 requires register "X8" to be used; as I recall x86 > requires the pointer to be re-returned) we need a special argument > attribute to mark this so that the correct code can be generated. > > "noalias" is just an optimisation hint: because of how this argument > came to exist (allocated by the caller directly before the call), no > other pointer accessible to the function can alias it. This allows > some useful transformations in the mid-end. > > Cheers. > > Tim. >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150716/f743f035/attachment.html>