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"
15 #include "plugin-version.h"
17 int plugin_is_GPL_compatible;
19 /* our callback is the same for all PLUGIN_GGC_START,
20 PLUGIN_GGC_MARKING, PLUGIN_GGC_END events; it just increments the
21 user_data which is an int */
22 static void increment_callback (void *gcc_data, void *user_data);
24 /* our counters are user_data */
25 static int our_ggc_start_counter;
26 static int our_ggc_end_counter;
27 static int our_ggc_marking_counter;
29 /* our empty GGC extra root table */
30 static const struct ggc_root_tab our_xtratab[] = {
35 /* The initialization routine exposed to and called by GCC. The spec of this
36 function is defined in gcc/gcc-plugin.h.
38 Note that this function needs to be named exactly "plugin_init". */
40 plugin_init (struct plugin_name_args *plugin_info,
41 struct plugin_gcc_version *version)
43 const char *plugin_name = plugin_info->base_name;
44 int argc = plugin_info->argc;
46 struct plugin_argument *argv = plugin_info->argv;
47 if (!plugin_default_version_check (version, &gcc_version))
49 /* Process the plugin arguments. This plugin takes the following arguments:
50 count-ggc-start count-ggc-end count-ggc-mark */
51 for (i = 0; i < argc; ++i)
53 if (!strcmp (argv[i].key, "count-ggc-start"))
56 warning (0, G_ ("option '-fplugin-arg-%s-count-ggc-start=%s'"
57 " ignored (superfluous '=%s')"),
58 plugin_name, argv[i].value, argv[i].value);
60 register_callback ("ggcplug",
63 (void *) &our_ggc_start_counter);
65 else if (!strcmp (argv[i].key, "count-ggc-end"))
68 warning (0, G_ ("option '-fplugin-arg-%s-count-ggc-end=%s'"
69 " ignored (superfluous '=%s')"),
70 plugin_name, argv[i].value, argv[i].value);
72 register_callback ("ggcplug",
75 (void *) &our_ggc_end_counter);
77 else if (!strcmp (argv[i].key, "count-ggc-mark"))
80 warning (0, G_ ("option '-fplugin-arg-%s-count-ggc-mark=%s'"
81 " ignored (superfluous '=%s')"),
82 plugin_name, argv[i].value, argv[i].value);
84 register_callback ("ggcplug",
87 (void *) &our_ggc_marking_counter);
89 else if (!strcmp (argv[i].key, "test-extra-root"))
92 warning (0, G_ ("option '-fplugin-arg-%s-test-extra-root=%s'"
93 " ignored (superfluous '=%s')"),
94 plugin_name, argv[i].value, argv[i].value);
96 register_callback ("ggcplug",
97 PLUGIN_REGISTER_GGC_ROOTS,
99 (void *) our_xtratab);
102 /* plugin initialization succeeded */
107 increment_callback (void *gcc_data, void *user_data)
109 int *usercountptr = (int *) user_data;
110 gcc_assert (!gcc_data);
111 gcc_assert (user_data);