Capturing x86 %rax in prologue to use in body

As part of our OpenVMS-specific changes, we're adding an arg-count to
all of our calls.

We've done this as part of callLowering to put the # of slots used into
%ah and leaving %al to hold the standard info about vector registers.
That part is working.

However, we're struggling somewhat on the code in the prologue to
capture the %ah value to then be obtained by our "arg_count" compiler
builtin. We found where the 1st parameter is put into a virtual
register in the event that it has to be passed back in %rax for
functions returning large structures. We certainly could do the same
with %ah, but what IR would we generate to fetch that value in the body
of a routine?

We haven't created our own private OpenVMS calling convention but just
riding along on the standard convention. Another thought would be to
create a new CC but that seems overkill just for this.

Anybody have suggestions on where we should be poking with our
screwdriver? Do we have to write a new intrinsic to obtain that saved
value?

Thanks for any advice

John

Hi John,

However, we're struggling somewhat on the code in the prologue to
capture the %ah value to then be obtained by our "arg_count" compiler
builtin. We found where the 1st parameter is put into a virtual
register in the event that it has to be passed back in %rax for
functions returning large structures. We certainly could do the same
with %ah, but what IR would we generate to fetch that value in the body
of a routine?

It would almost certainly be an @llvm.whatever intrinsic call at the
IR level with custom SDAG lowering that uses getCopyFromReg to copy
the value back out of the stashed VReg you found before.

We haven't created our own private OpenVMS calling convention but just
riding along on the standard convention. Another thought would be to
create a new CC but that seems overkill just for this.

That sounds pretty sensible. Unless you need to support multiple
calling conventions simultaneously the default "C" makes sense at the
IR level. You may or may not want a special OpenVMS CallingConv in the
.td files.

Cheers.

Tim.

Thanks. We did exactly that (add a new intrinsic call & put a piece of
VMS-specific metadata on the routine to tell it to capture the %ah into
a virtual register) and it all works as expected.