Debian Codegraph @

gcc/testsuite/gcc.dg/plugin/dump_plugin.cc

raw
1 /* Plugin for testing dumpfile.c. */
2
3 #define INCLUDE_MEMORY
4 #include "gcc-plugin.h"
5 #include "config.h"
6 #include "system.h"
7 #include "coretypes.h"
8 #include "tree.h"
9 #include "tree-pass.h"
10 #include "intl.h"
11 #include "plugin-version.h"
12 #include "diagnostic.h"
13 #include "context.h"
14 #include "optinfo.h"
15 #include "gimple.h"
16 #include "gimple-iterator.h"
17 #include "cgraph.h"
18
19 int plugin_is_GPL_compatible;
20
21 const pass_data pass_data_test_dumping =
22 {
23 GIMPLE_PASS, /* type */
24 "test_dumping", /* name */
25 OPTGROUP_LOOP, /* optinfo_flags */
26 TV_NONE, /* tv_id */
27 PROP_ssa, /* properties_required */
28 0, /* properties_provided */
29 0, /* properties_destroyed */
30 0, /* todo_flags_start */
31 0, /* todo_flags_finish */
32 };
33
34 class pass_test_dumping : public gimple_opt_pass
35 {
36 public:
37 pass_test_dumping (gcc::context *ctxt)
38 : gimple_opt_pass (pass_data_test_dumping, ctxt)
39 {}
40
41 /* opt_pass methods: */
42 bool gate (function *) { return true; }
43 virtual unsigned int execute (function *);
44
45 }; // class pass_test_dumping
46
47 unsigned int
48 pass_test_dumping::execute (function *fun)
49 {
50 basic_block bb;
51
52 if (!dump_enabled_p ())
53 return 0;
54
55 FOR_ALL_BB_FN (bb, fun)
56 for (gimple_stmt_iterator gsi = gsi_start_bb (bb);
57 !gsi_end_p (gsi); gsi_next (&gsi))
58 {
59 gimple *stmt = gsi_stmt (gsi);
60 gcall *call = dyn_cast <gcall *> (stmt);
61 if (!call)
62 continue;
63 tree callee_decl = gimple_call_fndecl (call);
64 if (!callee_decl)
65 continue;
66 tree callee_name = DECL_NAME (callee_decl);
67 if (!callee_name)
68 continue;
69 const char *callee = IDENTIFIER_POINTER (callee_name);
70
71 /* Various dumping tests, done at callsites,
72 controlled by the callee name. */
73 if (strcmp (callee, "test_string_literal") == 0)
74 dump_printf_loc (MSG_NOTE, stmt, "test of dump for %qs\n",
75 callee);
76 else if (strcmp (callee, "test_tree") == 0)
77 dump_printf_loc (MSG_NOTE, stmt, "test of tree: %T\n",
78 integer_zero_node);
79 else if (strcmp (callee, "test_gimple") == 0)
80 dump_printf_loc (MSG_NOTE, stmt, "test of gimple: %G", stmt);
81 else if (strcmp (callee, "test_cgraph_node") == 0)
82 {
83 dump_printf_loc (MSG_NOTE, stmt, "test of callgraph node: ");
84 dump_symtab_node (MSG_NOTE, cgraph_node::get (callee_decl));
85 dump_printf (MSG_NOTE, "\n");
86 }
87 else if (strcmp (callee, "test_wide_int") == 0)
88 {
89 HOST_WIDE_INT val = 0;
90 dump_printf_loc (MSG_NOTE, stmt,
91 "test of wide int: " HOST_WIDE_INT_PRINT_DEC "\n",
92 val);
93 }
94 else if (strcmp (callee, "test_poly_int") == 0)
95 {
96 dump_printf_loc (MSG_NOTE, stmt, "test of poly int: ");
97 dump_dec (MSG_NOTE, poly_int64 (42));
98 dump_printf (MSG_NOTE, "\n");
99 }
100 else if (strcmp (callee, "test_scopes") == 0)
101 {
102 AUTO_DUMP_SCOPE ("outer scope", stmt);
103 {
104 dump_printf_loc (MSG_NOTE, stmt, "at outer scope\n");
105 AUTO_DUMP_SCOPE ("middle scope", stmt);
106 {
107 dump_printf_loc (MSG_NOTE, stmt, "at middle scope\n");
108 AUTO_DUMP_SCOPE ("innermost scope", stmt);
109 dump_printf_loc (MSG_NOTE, stmt, "at innermost scope\n");
110 }
111 }
112 }
113 }
114
115 return 0;
116 }
117
118 static gimple_opt_pass *
119 make_pass_test_dumping (gcc::context *ctxt)
120 {
121 return new pass_test_dumping (ctxt);
122 }
123
124 int
125 plugin_init (struct plugin_name_args *plugin_info,
126 struct plugin_gcc_version *version)
127 {
128 struct register_pass_info pass_info;
129 const char *plugin_name = plugin_info->base_name;
130 int argc = plugin_info->argc;
131 struct plugin_argument *argv = plugin_info->argv;
132
133 if (!plugin_default_version_check (version, &gcc_version))
134 return 1;
135
136 pass_info.pass = make_pass_test_dumping (g);
137 pass_info.reference_pass_name = "ssa";
138 pass_info.ref_pass_instance_number = 1;
139 pass_info.pos_op = PASS_POS_INSERT_AFTER;
140 register_callback (plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL,
141 &pass_info);
142
143 return 0;
144 }