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