Implement CALL_EXPR_MUST_TAIL_CALL
commitb4a61e7769e57109038e2c75f85383d67810bbfc
authordmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 20 May 2016 14:20:03 +0000 (20 14:20 +0000)
committerdmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 20 May 2016 14:20:03 +0000 (20 14:20 +0000)
treed8d972fbd4d22fa989496efe8ce39275409a0d3d
parent80e11038c724952803a1802b43380957e00ea112
Implement CALL_EXPR_MUST_TAIL_CALL

This patch implements support for marking CALL_EXPRs
as being mandatory for tail-call-optimization. expand_call
tries harder to perform the optimization on such CALL_EXPRs,
and issues an error if it fails.

Currently this flag isn't accessible from any frontend,
so the patch uses a plugin for testing the functionality.

gcc/ChangeLog:
* calls.c (maybe_complain_about_tail_call): New function.
(initialize_argument_information): Call
maybe_complain_about_tail_call when clearing *may_tailcall.
(can_implement_as_sibling_call_p): Call
maybe_complain_about_tail_call when returning false.
(expand_call): Read CALL_EXPR_MUST_TAIL_CALL and, if set,
ensure try_tail_call is set.  Call maybe_complain_about_tail_call
if tail-call optimization fails.
* cfgexpand.c (expand_call_stmt): Initialize
CALL_EXPR_MUST_TAIL_CALL from gimple_call_must_tail_p.
* gimple-pretty-print.c (dump_gimple_call): Dump
gimple_call_must_tail_p.
* gimple.c (gimple_build_call_from_tree): Call
gimple_call_set_must_tail with the value of
CALL_EXPR_MUST_TAIL_CALL.
* gimple.h (enum gf_mask): Add GF_CALL_MUST_TAIL_CALL.
(gimple_call_set_must_tail): New function.
(gimple_call_must_tail_p): New function.
* print-tree.c (print_node): Update printing of TREE_STATIC
to reflect its use for CALL_EXPR_MUST_TAIL_CALL.
* tree-core.h (struct tree_base): Add MUST_TAIL_CALL to the
trailing comment listing applicable flags.
* tree.h (CALL_EXPR_MUST_TAIL_CALL): New macro.

gcc/testsuite/ChangeLog:
* gcc.dg/plugin/must-tail-call-1.c: New test case.
* gcc.dg/plugin/must-tail-call-2.c: New test case.
* gcc.dg/plugin/must_tail_call_plugin.c: New file.
* gcc.dg/plugin/plugin.exp (plugin_test_list): Add the above.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@236514 138bc75d-0d04-0410-961f-82ee72b054a4
14 files changed:
gcc/ChangeLog
gcc/calls.c
gcc/cfgexpand.c
gcc/gimple-pretty-print.c
gcc/gimple.c
gcc/gimple.h
gcc/print-tree.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/plugin/must-tail-call-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/plugin/must-tail-call-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/plugin/must_tail_call_plugin.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/plugin/plugin.exp
gcc/tree-core.h
gcc/tree.h