1 /* This plugin tests the GGC related plugin events. */
2 /* { dg-options "-O" } */
3
4 #include "config.h"
5 #include "system.h"
6 #include "coretypes.h"
7 #include "tm.h"
8 #include "tree.h"
9 #include "toplev.h"
10 #include "basic-block.h"
11 #include "pointer-set.h"
12 #include "hash-table.h"
13 #include "vec.h"
14 #include "ggc.h"
15 #include "basic-block.h"
16 #include "tree-ssa-alias.h"
17 #include "internal-fn.h"
18 #include "gimple-fold.h"
19 #include "tree-eh.h"
20 #include "gimple-expr.h"
21 #include "is-a.h"
22 #include "gimple.h"
23 #include "tree.h"
24 #include "tree-pass.h"
25 #include "intl.h"
26 #include "gcc-plugin.h"
27 #include "plugin-version.h"
28 #include "diagnostic.h"
29
30 int plugin_is_GPL_compatible;
31
32 /* our callback is the same for all PLUGIN_GGC_START,
33 PLUGIN_GGC_MARKING, PLUGIN_GGC_END events; it just increments the
34 user_data which is an int */
35 static void increment_callback (void *gcc_data, void *user_data);
36
37 /* our counters are user_data */
38 static int our_ggc_start_counter;
39 static int our_ggc_end_counter;
40 static int our_ggc_marking_counter;
41
42 /* our empty GGC extra root table */
43 static const struct ggc_root_tab our_xtratab[] = {
44 LAST_GGC_ROOT_TAB
45 };
46
47
48 /* The initialization routine exposed to and called by GCC. The spec of this
49 function is defined in gcc/gcc-plugin.h.
50
51 Note that this function needs to be named exactly "plugin_init". */
52 int
plugin_init(struct plugin_name_args * plugin_info,struct plugin_gcc_version * version)53 plugin_init (struct plugin_name_args *plugin_info,
54 struct plugin_gcc_version *version)
55 {
56 const char *plugin_name = plugin_info->base_name;
57 int argc = plugin_info->argc;
58 int i = 0;
59 struct plugin_argument *argv = plugin_info->argv;
60 if (!plugin_default_version_check (version, &gcc_version))
61 return 1;
62 /* Process the plugin arguments. This plugin takes the following arguments:
63 count-ggc-start count-ggc-end count-ggc-mark */
64 for (i = 0; i < argc; ++i)
65 {
66 if (!strcmp (argv[i].key, "count-ggc-start"))
67 {
68 if (argv[i].value)
69 warning (0, G_ ("option '-fplugin-arg-%s-count-ggc-start=%s'"
70 " ignored (superfluous '=%s')"),
71 plugin_name, argv[i].value, argv[i].value);
72 else
73 register_callback ("ggcplug",
74 PLUGIN_GGC_START,
75 increment_callback,
76 (void *) &our_ggc_start_counter);
77 }
78 else if (!strcmp (argv[i].key, "count-ggc-end"))
79 {
80 if (argv[i].value)
81 warning (0, G_ ("option '-fplugin-arg-%s-count-ggc-end=%s'"
82 " ignored (superfluous '=%s')"),
83 plugin_name, argv[i].value, argv[i].value);
84 else
85 register_callback ("ggcplug",
86 PLUGIN_GGC_END,
87 increment_callback,
88 (void *) &our_ggc_end_counter);
89 }
90 else if (!strcmp (argv[i].key, "count-ggc-mark"))
91 {
92 if (argv[i].value)
93 warning (0, G_ ("option '-fplugin-arg-%s-count-ggc-mark=%s'"
94 " ignored (superfluous '=%s')"),
95 plugin_name, argv[i].value, argv[i].value);
96 else
97 register_callback ("ggcplug",
98 PLUGIN_GGC_MARKING,
99 increment_callback,
100 (void *) &our_ggc_marking_counter);
101 }
102 else if (!strcmp (argv[i].key, "test-extra-root"))
103 {
104 if (argv[i].value)
105 warning (0, G_ ("option '-fplugin-arg-%s-test-extra-root=%s'"
106 " ignored (superfluous '=%s')"),
107 plugin_name, argv[i].value, argv[i].value);
108 else
109 register_callback ("ggcplug",
110 PLUGIN_REGISTER_GGC_ROOTS,
111 NULL,
112 (void *) our_xtratab);
113 }
114 }
115 /* plugin initialization succeeded */
116 return 0;
117 }
118
119 static void
increment_callback(void * gcc_data,void * user_data)120 increment_callback (void *gcc_data, void *user_data)
121 {
122 int *usercountptr = (int *) user_data;
123 gcc_assert (!gcc_data);
124 gcc_assert (user_data);
125 (*usercountptr)++;
126 }
127