aboutsummaryrefslogtreecommitdiff
path: root/gcc/gimple.h
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2016-05-20 14:20:03 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2016-05-20 14:20:03 +0000
commit9a385c2d3d74ffed78f2ed9ad47b844d2f294105 (patch)
treed8d972fbd4d22fa989496efe8ce39275409a0d3d /gcc/gimple.h
parentb40d90e6c569c434002f968a197d58eed0d2aaa3 (diff)
downloadgcc-9a385c2d3d74ffed78f2ed9ad47b844d2f294105.zip
gcc-9a385c2d3d74ffed78f2ed9ad47b844d2f294105.tar.gz
gcc-9a385c2d3d74ffed78f2ed9ad47b844d2f294105.tar.bz2
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. From-SVN: r236514
Diffstat (limited to 'gcc/gimple.h')
-rw-r--r--gcc/gimple.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/gcc/gimple.h b/gcc/gimple.h
index 6d15dab..063e29d 100644
--- a/gcc/gimple.h
+++ b/gcc/gimple.h
@@ -145,6 +145,7 @@ enum gf_mask {
GF_CALL_INTERNAL = 1 << 6,
GF_CALL_CTRL_ALTERING = 1 << 7,
GF_CALL_WITH_BOUNDS = 1 << 8,
+ GF_CALL_MUST_TAIL_CALL = 1 << 9,
GF_OMP_PARALLEL_COMBINED = 1 << 0,
GF_OMP_PARALLEL_GRID_PHONY = 1 << 1,
GF_OMP_TASK_TASKLOOP = 1 << 0,
@@ -3209,6 +3210,25 @@ gimple_call_tail_p (gcall *s)
return (s->subcode & GF_CALL_TAILCALL) != 0;
}
+/* Mark (or clear) call statement S as requiring tail call optimization. */
+
+static inline void
+gimple_call_set_must_tail (gcall *s, bool must_tail_p)
+{
+ if (must_tail_p)
+ s->subcode |= GF_CALL_MUST_TAIL_CALL;
+ else
+ s->subcode &= ~GF_CALL_MUST_TAIL_CALL;
+}
+
+/* Return true if call statement has been marked as requiring
+ tail call optimization. */
+
+static inline bool
+gimple_call_must_tail_p (const gcall *s)
+{
+ return (s->subcode & GF_CALL_MUST_TAIL_CALL) != 0;
+}
/* If RETURN_SLOT_OPT_P is true mark GIMPLE_CALL S as valid for return
slot optimization. This transformation uses the target of the call