public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* CALL_EXPR_MUST_TAIL_CALL and LLVM's musttail
@ 2021-12-07 22:38 Bradley Lucier
  2021-12-08 23:17 ` Jeff Law
  0 siblings, 1 reply; 22+ messages in thread
From: Bradley Lucier @ 2021-12-07 22:38 UTC (permalink / raw)
  To: gcc-help; +Cc: lucier, Marc Feeley

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

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2021-12-15 18:29 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-07 22:38 CALL_EXPR_MUST_TAIL_CALL and LLVM's musttail Bradley Lucier
2021-12-08 23:17 ` Jeff Law
2021-12-09  0:07   ` Segher Boessenkool
2021-12-09  3:31     ` Bradley Lucier
2021-12-09 10:56       ` Florian Weimer
2021-12-09 23:15       ` Segher Boessenkool
2021-12-09 10:57     ` Florian Weimer
2021-12-09 13:30       ` Marc Feeley
2021-12-09 14:04         ` Florian Weimer
2021-12-09 14:17           ` Marc Feeley
2021-12-10  4:31             ` Florian Weimer
2021-12-11  2:44               ` Segher Boessenkool
2021-12-09 23:36         ` Segher Boessenkool
2021-12-10  1:06           ` Marc Feeley
2021-12-10 22:40             ` Jeff Law
2021-12-12 17:32               ` Segher Boessenkool
2021-12-12 18:08                 ` Jonathan Wakely
2021-12-12 21:41                   ` Segher Boessenkool
2021-12-11 23:02             ` Segher Boessenkool
2021-12-13 17:48             ` Avi Kivity
2021-12-15 18:29               ` Bradley Lucier
2021-12-09 22:00       ` Segher Boessenkool

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).