[LLVMdev] Structs passed by value

Martinez, Javier E javier.e.martinez at intel.com
Wed Jun 13 09:55:02 PDT 2012


Hello,

I'm trying to change the default behavior for how structures are passed to functions to use pass-by-value. Currently LLVM's default behavior is to pass structures by reference. I'm not disputing the benefits of this but I really want to change the default behavior for experimentation purposes.

To this end I've changed the code in DefaultABIInfo::classifyArgumentType() to use the different types. What I've found is that none of the options yield the expected results for the input code (see below). Except for the indirect case, the function signature is changed to take each structure element. How can I modify LLVM to pass structures by value?

Thanks,
Javier

[Original Code]
struct myType {
  long val;
};
int convert(struct myType in)
{
  return (int)in.val;
}

[Expected Result]
define i32 @convert(%myType %in) nounwind readonly alwaysinline{
entry:
  %in.addr = alloca %myType, align 8
  store %myType %in, %myType* %in.addr, align 8
  %0 = getelementptr inbounds %myType* %in.addr, i32 0, i32 0
  %1 = load i64* %0, align 8
  %conv = trunc i64 %1 to i32
  ret i32 %conv
}

[ABIArgInfo::getIndirect(0) - Default]
%struct.myType = type { i64 }

define i32 @convert(%struct.myType* nocapture byval %in) nounwind readonly {
entry:
  %val = getelementptr inbounds %struct.myType* %in, i64 0, i32 0
  %0 = load i64* %val, align 8, !tbaa !0
  %conv = trunc i64 %0 to i32
  ret i32 %conv
}

[ABIArgInfo::getExtend(), ABIArgInfo::getDirect(), ABIArgInfo::getExpand()]
define i32 @convert(i64 %in.coerce0) nounwind readnone {
entry:
  %conv = trunc i64 %in.coerce0 to i32
  ret i32 %conv
}

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120613/70b200dc/attachment.html>


More information about the llvm-dev mailing list