[LLVMdev] making a copy of a byval aggregate on the callee's frame

Tim Northover t.p.northover at gmail.com
Thu Jul 4 12:24:38 PDT 2013

Hi Robert,

> I tried adding to the XCoreCallingConv.td:
>     CCIfByVal<CCPassByVal<0,4>>        // pushes pointer to the stack

This looks sensible to me. After that it comes down to cooperation
between XCoreISelLowering's LowerFormalArguments and LowerCall
functions. LowerFormalArguments is at the beginning of a function and
is responsible for taking arguments out of registers and putting them
into sensible places for the rest of the function to use. LowerCall is
responsible for putting call arguments where callees will expect them
and making the call.

On most targets, for byval, LowerCall would store the argument by
value on the stack (likely with a memcpy equivalent from the actual
pointer that's being passed); and LowerFormalArguments would create a
fixed FrameIndex pointing there and record that as the address for use
by everything else.

You'll want to do basically the reverse: LowerCall will just put the
pointer it's given on the stack; LowerFormalArguments will do the
memcpy like operation into a local variable created for the purpose
(also a FrameIndex, but of a different kind), then it'll record that
frame-index as the address for everything else to use.

Hope this helps; come back if there's still stuff you don't understand.



More information about the llvm-dev mailing list