111
|
1 /* { dg-options "-O" } */
|
|
2
|
|
3 /* Mark all CALL_EXPRs not within "main" as requiring tail-call. */
|
|
4
|
|
5 #include "gcc-plugin.h"
|
|
6 #include "config.h"
|
|
7 #include "system.h"
|
|
8 #include "coretypes.h"
|
|
9 #include "tm.h"
|
|
10 #include "tree.h"
|
|
11 #include "stringpool.h"
|
|
12 #include "toplev.h"
|
|
13 #include "basic-block.h"
|
|
14 #include "hash-table.h"
|
|
15 #include "vec.h"
|
|
16 #include "ggc.h"
|
|
17 #include "basic-block.h"
|
|
18 #include "tree-ssa-alias.h"
|
|
19 #include "internal-fn.h"
|
|
20 #include "gimple-fold.h"
|
|
21 #include "tree-eh.h"
|
|
22 #include "gimple-expr.h"
|
|
23 #include "is-a.h"
|
|
24 #include "tree.h"
|
|
25 #include "tree-pass.h"
|
|
26 #include "intl.h"
|
|
27 #include "plugin-version.h"
|
|
28
|
|
29 int plugin_is_GPL_compatible;
|
|
30
|
|
31 tree
|
|
32 cb_walk_tree_fn (tree * tp, int * walk_subtrees,
|
|
33 void * data ATTRIBUTE_UNUSED)
|
|
34 {
|
|
35 if (TREE_CODE (*tp) != CALL_EXPR)
|
|
36 return NULL_TREE;
|
|
37
|
|
38 tree call_expr = *tp;
|
|
39
|
|
40 /* Forcibly mark the CALL_EXPR as requiring tail-call optimization. */
|
|
41 CALL_EXPR_MUST_TAIL_CALL (call_expr) = 1;
|
|
42
|
|
43 return NULL_TREE;
|
|
44 }
|
|
45
|
|
46 static void
|
|
47 callback (void *gcc_data, void *user_data)
|
|
48 {
|
|
49 tree fndecl = (tree)gcc_data;
|
|
50 gcc_assert (TREE_CODE (fndecl) == FUNCTION_DECL);
|
|
51
|
|
52 /* Don't mark calls inside "main". */
|
|
53 tree decl_name = DECL_NAME (fndecl);
|
|
54 if (decl_name)
|
|
55 if (0 == strcmp (IDENTIFIER_POINTER (decl_name), "main"))
|
|
56 return;
|
|
57
|
|
58 walk_tree (&DECL_SAVED_TREE (fndecl), cb_walk_tree_fn, NULL, NULL);
|
|
59 }
|
|
60
|
|
61 int
|
|
62 plugin_init (struct plugin_name_args *plugin_info,
|
|
63 struct plugin_gcc_version *version)
|
|
64 {
|
|
65 const char *plugin_name = plugin_info->base_name;
|
|
66
|
|
67 if (!plugin_default_version_check (version, &gcc_version))
|
|
68 return 1;
|
|
69
|
|
70 register_callback (plugin_name,
|
|
71 PLUGIN_PRE_GENERICIZE,
|
|
72 callback,
|
|
73 NULL);
|
|
74
|
|
75 return 0;
|
|
76 }
|