]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gcc.dg/plugin/one_time_plugin.c
pass cfun to pass::execute
[thirdparty/gcc.git] / gcc / testsuite / gcc.dg / plugin / one_time_plugin.c
1 /* Plugin that prints message if it inserted (and invoked) more than once. */
2 #include "config.h"
3 #include "gcc-plugin.h"
4 #include "system.h"
5 #include "coretypes.h"
6 #include "tree.h"
7 #include "tm.h"
8 #include "toplev.h"
9 #include "pointer-set.h"
10 #include "hash-table.h"
11 #include "vec.h"
12 #include "ggc.h"
13 #include "basic-block.h"
14 #include "tree-ssa-alias.h"
15 #include "internal-fn.h"
16 #include "gimple-fold.h"
17 #include "tree-eh.h"
18 #include "gimple-expr.h"
19 #include "is-a.h"
20 #include "gimple.h"
21 #include "tree-pass.h"
22 #include "intl.h"
23 #include "context.h"
24
25 int plugin_is_GPL_compatible;
26
27 namespace {
28
29 const pass_data pass_data_one_pass =
30 {
31 GIMPLE_PASS, /* type */
32 "cfg", /* name */
33 OPTGROUP_NONE, /* optinfo_flags */
34 true, /* has_execute */
35 TV_NONE, /* tv_id */
36 PROP_gimple_any, /* properties_required */
37 0, /* properties_provided */
38 0, /* properties_destroyed */
39 0, /* todo_flags_start */
40 0, /* todo_flags_finish */
41 };
42
43 class one_pass : public gimple_opt_pass
44 {
45 public:
46 one_pass(gcc::context *ctxt)
47 : gimple_opt_pass(pass_data_one_pass, ctxt),
48 counter(0)
49 {}
50
51 /* opt_pass methods: */
52 virtual bool gate (function *);
53 virtual unsigned int execute (function *);
54
55 private:
56 int counter;
57 }; // class one_pass
58
59 } // anon namespace
60
61 bool one_pass::gate (function *)
62 {
63 return true;
64 }
65
66 unsigned int
67 one_pass::execute (function *)
68 {
69 if (counter > 0) {
70 printf ("Executed more than once \n");
71 }
72 counter++;
73 return 0;
74 }
75
76 gimple_opt_pass *
77 make_one_pass (gcc::context *ctxt)
78 {
79 return new one_pass (ctxt);
80 }
81
82
83 int plugin_init (struct plugin_name_args *plugin_info,
84 struct plugin_gcc_version *version)
85 {
86 struct register_pass_info p;
87
88 p.pass = make_one_pass (g);
89 p.reference_pass_name = "cfg";
90 p.ref_pass_instance_number = 1;
91 p.pos_op = PASS_POS_INSERT_AFTER;
92
93 register_callback ("one_pass", PLUGIN_PASS_MANAGER_SETUP, NULL, &p);
94
95 return 0;
96 }