1 /* This plugin tests the GGC related plugin events. */
2 /* { dg-options "-O" } */
9 #include "basic-block.h"
12 #include "tree-pass.h"
14 #include "gcc-plugin.h"
16 int plugin_is_GPL_compatible;
18 /* our callback is the same for all PLUGIN_GGC_START,
19 PLUGIN_GGC_MARKING, PLUGIN_GGC_END events; it just increments the
20 user_data which is an int */
21 static void increment_callback (void *gcc_data, void *user_data);
23 /* our counters are user_data */
24 static int our_ggc_start_counter;
25 static int our_ggc_end_counter;
26 static int our_ggc_marking_counter;
28 /* our empty GGC extra root table */
29 static const struct ggc_root_tab our_xtratab[] = {
34 /* The initialization routine exposed to and called by GCC. The spec of this
35 function is defined in gcc/gcc-plugin.h.
37 Note that this function needs to be named exactly "plugin_init". */
39 plugin_init (struct plugin_name_args *plugin_info,
40 struct plugin_gcc_version *version)
42 const char *plugin_name = plugin_info->base_name;
43 int argc = plugin_info->argc;
45 struct plugin_argument *argv = plugin_info->argv;
46 if (!plugin_default_version_check (version, version))
48 /* Process the plugin arguments. This plugin takes the following arguments:
49 count-ggc-start count-ggc-end count-ggc-mark */
50 for (i = 0; i < argc; ++i)
52 if (!strcmp (argv[i].key, "count-ggc-start"))
55 warning (0, G_ ("option '-fplugin-arg-%s-count-ggc-start=%s'"
56 " ignored (superfluous '=%s')"),
57 plugin_name, argv[i].value, argv[i].value);
59 register_callback ("ggcplug",
62 (void *) &our_ggc_start_counter);
64 else if (!strcmp (argv[i].key, "count-ggc-end"))
67 warning (0, G_ ("option '-fplugin-arg-%s-count-ggc-end=%s'"
68 " ignored (superfluous '=%s')"),
69 plugin_name, argv[i].value, argv[i].value);
71 register_callback ("ggcplug",
74 (void *) &our_ggc_end_counter);
76 else if (!strcmp (argv[i].key, "count-ggc-mark"))
79 warning (0, G_ ("option '-fplugin-arg-%s-count-ggc-mark=%s'"
80 " ignored (superfluous '=%s')"),
81 plugin_name, argv[i].value, argv[i].value);
83 register_callback ("ggcplug",
86 (void *) &our_ggc_marking_counter);
88 else if (!strcmp (argv[i].key, "test-extra-root"))
91 warning (0, G_ ("option '-fplugin-arg-%s-test-extra-root=%s'"
92 " ignored (superfluous '=%s')"),
93 plugin_name, argv[i].value, argv[i].value);
95 register_callback ("ggcplug",
96 PLUGIN_REGISTER_GGC_ROOTS,
98 (void *) our_xtratab);
101 /* plugin initialization succeeded */
106 increment_callback (void *gcc_data, void *user_data)
108 int *usercountptr = (int *) user_data;
109 gcc_assert (!gcc_data);
110 gcc_assert (user_data);