<div dir="ltr"><div>I needed this functionality to solve <a href="http://llvm.org/PR20653">http://llvm.org/PR20653</a>, but it obviously has far more general applications.</div><div><br></div><div>You can do it like this:</div>
<div><br></div><div>define i32 @my_forwarding_thunk(i32 %arg1, i8* %arg2, ...) {</div><div>  ... ; define new_arg1 and new_arg2</div><div>  %r = musttail call i32 (i32, i8*, ...)* @the_true_target(i32 %new_arg1, i8* %new_arg2, ...)</div>
<div>  ret i32 %r<br>}</div><div><div>declare i32 @the_true_target(i32, i8*, ...)</div></div><div><br></div><div>The varargs convention (usually) matches the standard function call convention, and everything will line up if you do an indirect call like this:</div>
<div><br></div><div>declare i32 @the_true_target(%struct.Foo* %this, i64, i8)</div><div>define i32 @my_forwarding_thunk(%struct.Foo* %this, ...) {</div><div>  %fptr = ... ; Compute fptr by bitcasting @the_true_target to the varargs type</div>
<div>  %r = musttail call i32 (%struct.Foo*, ...)* %fptr(%struct.Foo* %this, ...)</div><div>  ret i32 %r<br>}</div><div><br></div><div>Currently this functionality is only implemented for x86 in the absence of inreg and for x86_64 in the general case, but I'd like to see it implemented for the CPU backends. I'm happy to do some of them, but I don't have the time to do all of them.</div>
<div><br></div><div>Alternatively, it would be great if we could handle forwarding of unused register parameters in variadic functions in a general way. Perhaps CCState should surface this information.</div><div><br></div>
<div>Thoughts? This seemed like a reasonable way to represent such thunks, but I'd like to know if there are objections.</div><div></div></div>