CALL_EXPR_MUST_TAIL_CALL and LLVM's musttail

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I use GCC mainly to compile Scheme code that has been translated to large, heavily macrofied C routines by the Gambit Scheme compiler:

https://github.com/gambit/gambit

Scheme semantics require that all procedure calls in "tail call position" are, in fact, tail called.

For calls between Scheme procedures defined in the same file, Gambit's compiler generates a C goto; intermodule calls use a trampoline.

Recently, the Gambit-generated C code was modified to take advantage of LLVM's musttail attribute, when available.

So I've been investigating whether gcc's -foptimize-sibling-calls option (for which I've found very little documentation) might produce similar results.

This commit to GCC's source tree defines must_tail_call_plugin.c, which seems (a) to be used only in some tests, and (b) to have had no patches since first committed:

https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=9a385c2d3d74ffed78f2ed9ad47b844d2f294105

I found this similar, more recent plugin:

https://github.com/pietro/gcc-musttail-plugin/

This seems to set up maybe_complain_about_tail_call in calls.c to fail when a call is not compiled to a tail call.

So, my understanding of what I need to do is:

1. Built and dynamically link a plugin to set CALL_EXPR_MUST_TAIL_CALL on all calls.

2.  Use -foptimize-sibling-calls.

3. gcc fails with an appropriate message on the first call it can't "tail call" in each file, or it succeeds.

So some questions:

1.  Is this how you recommend I proceed?

2.  Which plugin do you recommend?

3. I think it would be better to have a flag named something like -Wcant-tail-call that would generate a warning in maybe_complain_about_tail_call, so that (a) one could catch all such cases at once and (b) one can throw an error if needed by specifying -Werror, and (c) I wouldn't need to fiddle with a plugin.

Do you agree with this idea? I added a few flags to gcc about 20 years ago, I guess I could look at it again to see how to do such a thing now.

Brad Lucier



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux