1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Generator for IPA pass related boilerplate code/data
9 * 1. before inclusion define PASS_NAME
10 * 2. before inclusion define NO_* for unimplemented callbacks
14 * NO_READ_OPTIMIZATION_SUMMARY
15 * NO_WRITE_OPTIMIZATION_SUMMARY
17 * NO_FUNCTION_TRANSFORM
18 * NO_VARIABLE_TRANSFORM
21 * 3. before inclusion define PROPERTIES_* and *TODO_FLAGS_* to override
22 * the default 0 values
23 * 4. for convenience, all the above will be undefined after inclusion!
24 * 5. the only exported name is make_PASS_NAME_pass() to register with gcc
28 #error at least PASS_NAME must be defined
30 #define __GCC_PLUGIN_STRINGIFY(n) #n
31 #define _GCC_PLUGIN_STRINGIFY(n) __GCC_PLUGIN_STRINGIFY(n)
32 #define _GCC_PLUGIN_CONCAT2(x, y) x ## y
33 #define _GCC_PLUGIN_CONCAT3(x, y, z) x ## y ## z
35 #define __PASS_NAME_PASS_DATA(n) _GCC_PLUGIN_CONCAT2(n, _pass_data)
36 #define _PASS_NAME_PASS_DATA __PASS_NAME_PASS_DATA(PASS_NAME)
38 #define __PASS_NAME_PASS(n) _GCC_PLUGIN_CONCAT2(n, _pass)
39 #define _PASS_NAME_PASS __PASS_NAME_PASS(PASS_NAME)
41 #define _PASS_NAME_NAME _GCC_PLUGIN_STRINGIFY(PASS_NAME)
43 #define __MAKE_PASS_NAME_PASS(n) _GCC_PLUGIN_CONCAT3(make_, n, _pass)
44 #define _MAKE_PASS_NAME_PASS __MAKE_PASS_NAME_PASS(PASS_NAME)
46 #ifdef NO_GENERATE_SUMMARY
47 #define _GENERATE_SUMMARY NULL
49 #define __GENERATE_SUMMARY(n) _GCC_PLUGIN_CONCAT2(n, _generate_summary)
50 #define _GENERATE_SUMMARY __GENERATE_SUMMARY(PASS_NAME)
53 #ifdef NO_READ_SUMMARY
54 #define _READ_SUMMARY NULL
56 #define __READ_SUMMARY(n) _GCC_PLUGIN_CONCAT2(n, _read_summary)
57 #define _READ_SUMMARY __READ_SUMMARY(PASS_NAME)
60 #ifdef NO_WRITE_SUMMARY
61 #define _WRITE_SUMMARY NULL
63 #define __WRITE_SUMMARY(n) _GCC_PLUGIN_CONCAT2(n, _write_summary)
64 #define _WRITE_SUMMARY __WRITE_SUMMARY(PASS_NAME)
67 #ifdef NO_READ_OPTIMIZATION_SUMMARY
68 #define _READ_OPTIMIZATION_SUMMARY NULL
70 #define __READ_OPTIMIZATION_SUMMARY(n) _GCC_PLUGIN_CONCAT2(n, _read_optimization_summary)
71 #define _READ_OPTIMIZATION_SUMMARY __READ_OPTIMIZATION_SUMMARY(PASS_NAME)
74 #ifdef NO_WRITE_OPTIMIZATION_SUMMARY
75 #define _WRITE_OPTIMIZATION_SUMMARY NULL
77 #define __WRITE_OPTIMIZATION_SUMMARY(n) _GCC_PLUGIN_CONCAT2(n, _write_optimization_summary)
78 #define _WRITE_OPTIMIZATION_SUMMARY __WRITE_OPTIMIZATION_SUMMARY(PASS_NAME)
82 #define _STMT_FIXUP NULL
84 #define __STMT_FIXUP(n) _GCC_PLUGIN_CONCAT2(n, _stmt_fixup)
85 #define _STMT_FIXUP __STMT_FIXUP(PASS_NAME)
88 #ifdef NO_FUNCTION_TRANSFORM
89 #define _FUNCTION_TRANSFORM NULL
91 #define __FUNCTION_TRANSFORM(n) _GCC_PLUGIN_CONCAT2(n, _function_transform)
92 #define _FUNCTION_TRANSFORM __FUNCTION_TRANSFORM(PASS_NAME)
95 #ifdef NO_VARIABLE_TRANSFORM
96 #define _VARIABLE_TRANSFORM NULL
98 #define __VARIABLE_TRANSFORM(n) _GCC_PLUGIN_CONCAT2(n, _variable_transform)
99 #define _VARIABLE_TRANSFORM __VARIABLE_TRANSFORM(PASS_NAME)
104 #define _HAS_GATE false
106 #define __GATE(n) _GCC_PLUGIN_CONCAT2(n, _gate)
107 #define _GATE __GATE(PASS_NAME)
108 #define _HAS_GATE true
112 #define _EXECUTE NULL
113 #define _HAS_EXECUTE false
115 #define __EXECUTE(n) _GCC_PLUGIN_CONCAT2(n, _execute)
116 #define _EXECUTE __EXECUTE(PASS_NAME)
117 #define _HAS_EXECUTE true
120 #ifndef PROPERTIES_REQUIRED
121 #define PROPERTIES_REQUIRED 0
124 #ifndef PROPERTIES_PROVIDED
125 #define PROPERTIES_PROVIDED 0
128 #ifndef PROPERTIES_DESTROYED
129 #define PROPERTIES_DESTROYED 0
132 #ifndef TODO_FLAGS_START
133 #define TODO_FLAGS_START 0
136 #ifndef TODO_FLAGS_FINISH
137 #define TODO_FLAGS_FINISH 0
140 #ifndef FUNCTION_TRANSFORM_TODO_FLAGS_START
141 #define FUNCTION_TRANSFORM_TODO_FLAGS_START 0
144 #if BUILDING_GCC_VERSION >= 4009
146 static const pass_data _PASS_NAME_PASS_DATA
= {
148 static struct ipa_opt_pass_d _PASS_NAME_PASS
= {
152 .name
= _PASS_NAME_NAME
,
153 #if BUILDING_GCC_VERSION >= 4008
154 .optinfo_flags
= OPTGROUP_NONE
,
156 #if BUILDING_GCC_VERSION >= 5000
157 #elif BUILDING_GCC_VERSION == 4009
158 .has_gate
= _HAS_GATE
,
159 .has_execute
= _HAS_EXECUTE
,
165 .static_pass_number
= 0,
168 .properties_required
= PROPERTIES_REQUIRED
,
169 .properties_provided
= PROPERTIES_PROVIDED
,
170 .properties_destroyed
= PROPERTIES_DESTROYED
,
171 .todo_flags_start
= TODO_FLAGS_START
,
172 .todo_flags_finish
= TODO_FLAGS_FINISH
,
173 #if BUILDING_GCC_VERSION < 4009
175 .generate_summary
= _GENERATE_SUMMARY
,
176 .write_summary
= _WRITE_SUMMARY
,
177 .read_summary
= _READ_SUMMARY
,
178 #if BUILDING_GCC_VERSION >= 4006
179 .write_optimization_summary
= _WRITE_OPTIMIZATION_SUMMARY
,
180 .read_optimization_summary
= _READ_OPTIMIZATION_SUMMARY
,
182 .stmt_fixup
= _STMT_FIXUP
,
183 .function_transform_todo_flags_start
= FUNCTION_TRANSFORM_TODO_FLAGS_START
,
184 .function_transform
= _FUNCTION_TRANSFORM
,
185 .variable_transform
= _VARIABLE_TRANSFORM
,
189 #if BUILDING_GCC_VERSION >= 4009
190 class _PASS_NAME_PASS
: public ipa_opt_pass_d
{
192 _PASS_NAME_PASS() : ipa_opt_pass_d(_PASS_NAME_PASS_DATA
,
197 _WRITE_OPTIMIZATION_SUMMARY
,
198 _READ_OPTIMIZATION_SUMMARY
,
200 FUNCTION_TRANSFORM_TODO_FLAGS_START
,
202 _VARIABLE_TRANSFORM
) {}
205 #if BUILDING_GCC_VERSION >= 5000
206 virtual bool gate(function
*) { return _GATE(); }
208 virtual bool gate(void) { return _GATE(); }
212 virtual opt_pass
*clone() { return new _PASS_NAME_PASS(); }
215 #if BUILDING_GCC_VERSION >= 5000
216 virtual unsigned int execute(function
*) { return _EXECUTE(); }
218 virtual unsigned int execute(void) { return _EXECUTE(); }
224 opt_pass
*_MAKE_PASS_NAME_PASS(void)
226 return new _PASS_NAME_PASS();
229 struct opt_pass
*_MAKE_PASS_NAME_PASS(void)
231 return &_PASS_NAME_PASS
.pass
;
235 /* clean up user provided defines */
237 #undef NO_GENERATE_SUMMARY
238 #undef NO_WRITE_SUMMARY
239 #undef NO_READ_SUMMARY
240 #undef NO_WRITE_OPTIMIZATION_SUMMARY
241 #undef NO_READ_OPTIMIZATION_SUMMARY
243 #undef NO_FUNCTION_TRANSFORM
244 #undef NO_VARIABLE_TRANSFORM
248 #undef FUNCTION_TRANSFORM_TODO_FLAGS_START
249 #undef PROPERTIES_DESTROYED
250 #undef PROPERTIES_PROVIDED
251 #undef PROPERTIES_REQUIRED
252 #undef TODO_FLAGS_FINISH
253 #undef TODO_FLAGS_START
255 /* clean up generated defines */
258 #undef _FUNCTION_TRANSFORM
259 #undef __FUNCTION_TRANSFORM
262 #undef _GCC_PLUGIN_CONCAT2
263 #undef _GCC_PLUGIN_CONCAT3
264 #undef _GCC_PLUGIN_STRINGIFY
265 #undef __GCC_PLUGIN_STRINGIFY
266 #undef _GENERATE_SUMMARY
267 #undef __GENERATE_SUMMARY
270 #undef _MAKE_PASS_NAME_PASS
271 #undef __MAKE_PASS_NAME_PASS
272 #undef _PASS_NAME_NAME
273 #undef _PASS_NAME_PASS
274 #undef __PASS_NAME_PASS
275 #undef _PASS_NAME_PASS_DATA
276 #undef __PASS_NAME_PASS_DATA
277 #undef _READ_OPTIMIZATION_SUMMARY
278 #undef __READ_OPTIMIZATION_SUMMARY
280 #undef __READ_SUMMARY
283 #undef _VARIABLE_TRANSFORM
284 #undef __VARIABLE_TRANSFORM
285 #undef _WRITE_OPTIMIZATION_SUMMARY
286 #undef __WRITE_OPTIMIZATION_SUMMARY
287 #undef _WRITE_SUMMARY
288 #undef __WRITE_SUMMARY
290 #endif /* PASS_NAME */