<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Il 22/08/2011 12:26, Duncan Sands ha scritto:
    <blockquote cite="mid:4E522ED2.6010106@free.fr" type="cite">
      <pre wrap="">Hi Carlo,

</pre>
      <blockquote type="cite">
        <pre wrap="">Nella citazione lunedì 22 agosto 2011 11:53:29, Duncan Sands ha scritto:
</pre>
        <blockquote type="cite">
          <pre wrap="">Hi Carlo, rather than declaring individual stack variables
int x;
int y;
int z;
and so on, which requires you to pass each one, or a pointer to each one,
to your function, declare one stack variable of struct type that holds
them all:
struct StackObjects {
int x;
int y;
int z;
...
};
...
struct StackObjects stack;
then pass the address of stack to your function, enabling it to access all
of the objects on the callers stack. This way you only need to copy a single
pointer. This is what GCC's nested function implementation does for example to
enable child functions to access variables on the parent's stack.
</pre>
        </blockquote>
        <pre wrap="">
Hi Duncan,
this is what I'm already doing (see
<a class="moz-txt-link-freetext" href="http://stackoverflow.com/questions/7144733/argument-forwarding-in-llvm">http://stackoverflow.com/questions/7144733/argument-forwarding-in-llvm</a>, the code
I posted is in pseudo-C but I'm actually working on LLVM-IR in my pass) but this in
curs the boxing-unboxing penalty and I was wondering if there is a way to avoid it.
</pre>
      </blockquote>
      <pre wrap="">
I didn't read your question carefully enough: I thought you were talking about
accessing stack variables declared by the parent (in which case there is no cost
to using the above technique), but in fact you were talking about accessing the
parent's arguments.  Probably the best you can do is store a pointer to each
argument in a stack struct object (like above), then pass a pointer to that
object.  The setup cost is then one pointer store per argument, plus one pointer
copy (passing the stack object to the callee).  The cost of accessing is one
pointer dereference per argument.  I'm pretty sure this is what GCC does when
a nested function wants to access one of its parent's arguments.

</pre>
    </blockquote>
    I see. Just wondering: what if I were to construct F as a function
    with a number of parameters high enough to be able to accept any
    combination of parameters of the other functions? Something like:<br>
    <br>
    void A(int, float, float)<br>
    void B(float, struct S)<br>
    <br>
    --> void fastcc F(int, float, float, struct S)<br>
    <br>
    and then calling F with undefs for the unused parameters:<br>
    <br>
    void A(int a, float b, float c) {<br>
      F(a, b, c, undef);<br>
    }<br>
    <br>
    void B(float a, struct S b) {<br>
      F(undef, a, undef, b);<br>
    }<br>
    <br>
    are the backends able to efficiently handle functions with many
    arguments (the majority of which would be undefs)? could this work?<br>
  </body>
</html>