libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / plugin / one_time_plugin.c
blob84f2d31f0f219667583f10cfde61454c3f0c5497
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 "tree-eh.h"
16 #include "gimple-expr.h"
17 #include "is-a.h"
18 #include "gimple.h"
19 #include "tree-pass.h"
20 #include "intl.h"
21 #include "context.h"
23 int plugin_is_GPL_compatible;
25 namespace {
27 const pass_data pass_data_one_pass =
29 GIMPLE_PASS, /* type */
30 "cfg", /* name */
31 OPTGROUP_NONE, /* optinfo_flags */
32 TV_NONE, /* tv_id */
33 PROP_gimple_any, /* properties_required */
34 0, /* properties_provided */
35 0, /* properties_destroyed */
36 0, /* todo_flags_start */
37 0, /* todo_flags_finish */
40 class one_pass : public gimple_opt_pass
42 public:
43 one_pass(gcc::context *ctxt)
44 : gimple_opt_pass(pass_data_one_pass, ctxt),
45 counter(0)
48 /* opt_pass methods: */
49 virtual bool gate (function *);
50 virtual unsigned int execute (function *);
52 private:
53 int counter;
54 }; // class one_pass
56 } // anon namespace
58 bool one_pass::gate (function *)
60 return true;
63 unsigned int
64 one_pass::execute (function *)
66 if (counter > 0) {
67 printf ("Executed more than once \n");
69 counter++;
70 return 0;
73 gimple_opt_pass *
74 make_one_pass (gcc::context *ctxt)
76 return new one_pass (ctxt);
80 int plugin_init (struct plugin_name_args *plugin_info,
81 struct plugin_gcc_version *version)
83 struct register_pass_info p;
85 p.pass = make_one_pass (g);
86 p.reference_pass_name = "cfg";
87 p.ref_pass_instance_number = 1;
88 p.pos_op = PASS_POS_INSERT_AFTER;
90 register_callback ("one_pass", PLUGIN_PASS_MANAGER_SETUP, NULL, &p);
92 return 0;