[LLVMdev] RFC: Tail call optimization X86

Arnold Schwaighofer arnold.schwaighofer at gmail.com
Thu Sep 6 07:20:23 PDT 2007


Hi Evan,

first off thanks to you and Chris for taking time.
On 6 Sep 2007, at 00:57, Evan Cheng wrote:

> We'd like to see tail call optimization to be similar to the target
> independent lowering of ISD::CALL nodes. These are auto-generated
> from ???CallingConv.td files. Some target specific details such as
> function address register (ECX in your example) should be coded in
> these files. Ditto for stack offsets, etc. These should be part of the
> fastcc calling convention. The tail call lowering will use these
> information and target hooks to perform tail call optimization on
> fastcc calls that are really tail calls.
>
> I think it's reasonable to start by doing a (clean) target specific
> implementation for X86. Just understand we'd like to move to a target
> independent mechanism so the earlier implementation may not survive.
>
Good that roughly sounds like what i did.
(except probably for the clean bit :)


> As for what you described here. I am having a hard time following
> it. :-) Please send patch.
>

Okay here is a patch containing the tail call optimization code
for X86. It mostly does what i have described in preceeding
emails:

There is new code for lowering fastcc calls:
LowerX86_32FastCCCallTo
LowerX86_32FastCCArguments

There is some code checking whether a TAIL CALL really is
eligible for tail call optimization.

I modified:
LowerRET
to create a TC_RETURN node. (used for adjusting stackpointer and
jumping to function in epilogue, similar to EH_RETURN)

There is a  new calling convention:
CC_X86_32_TailCall
which is ~ CC_X86_32_C minus ECX.

There are some modifications in
X86InstrInfo.td

There are new X86 DAG nodes:
TRUETAILCALL
TC_RETURN


There is some voodoo in X86RegisterInfo.cpp to deal with the
RETADDR problem described in X86ISelLowering.cpp comments.
(callee has more args than caller -> there needs to be space
between RETADDR stack slot and ebp/spilled registers for safely
moving the RETADDR to)

any comments, critique, suggestions welcome.
regards arnold

-------------- next part --------------
A non-text attachment was scrubbed...
Name: tailcall10.patch
Type: application/octet-stream
Size: 43991 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20070906/270e6d7a/attachment.obj>


More information about the llvm-dev mailing list