| 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" |
| 22 |
|
| 23 |
int plugin_is_GPL_compatible; |
| 24 |
|
| 25 |
namespace { |
| 26 |
|
| 27 |
const pass_data pass_data_one_pass = |
| 28 |
{ |
| 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 */ |
| 38 |
}; |
| 39 |
|
| 40 |
class one_pass : public gimple_opt_pass |
| 41 |
{ |
| 42 |
public: |
| 43 |
one_pass(gcc::context *ctxt) |
| 44 |
: gimple_opt_pass(pass_data_one_pass, ctxt), |
| 45 |
counter(0) |
| 46 |
{} |
| 47 |
|
| 48 |
/* opt_pass methods: */ |
| 49 |
virtual bool gate (function *); |
| 50 |
virtual unsigned int execute (function *); |
| 51 |
|
| 52 |
private: |
| 53 |
int counter; |
| 54 |
}; // class one_pass |
| 55 |
|
| 56 |
} // anon namespace |
| 57 |
|
| 58 |
bool one_pass::gate (function *) |
| 59 |
{ |
| 60 |
return true; |
| 61 |
} |
| 62 |
|
| 63 |
unsigned int |
| 64 |
one_pass::execute (function *) |
| 65 |
{ |
| 66 |
if (counter > 0) { |
| 67 |
printf ("Executed more than once \n"); |
| 68 |
} |
| 69 |
counter++; |
| 70 |
return 0; |
| 71 |
} |
| 72 |
|
| 73 |
gimple_opt_pass * |
| 74 |
make_one_pass (gcc::context *ctxt) |
| 75 |
{ |
| 76 |
return new one_pass (ctxt); |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
int plugin_init (struct plugin_name_args *plugin_info, |
| 81 |
struct plugin_gcc_version *version) |
| 82 |
{ |
| 83 |
struct register_pass_info p; |
| 84 |
|
| 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; |
| 89 |
|
| 90 |
register_callback ("one_pass", PLUGIN_PASS_MANAGER_SETUP, NULL, &p); |
| 91 |
|
| 92 |
return 0; |
| 93 |
} |