blob: 1e7f064e8f6e6d4154548b61790ce9279ead855e [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Emese Revfy6b90bd42016-05-24 00:09:38 +02002/*
3 * Generator for IPA pass related boilerplate code/data
4 *
5 * Supports gcc 4.5-6
6 *
7 * Usage:
8 *
9 * 1. before inclusion define PASS_NAME
10 * 2. before inclusion define NO_* for unimplemented callbacks
11 * NO_GENERATE_SUMMARY
12 * NO_READ_SUMMARY
13 * NO_WRITE_SUMMARY
14 * NO_READ_OPTIMIZATION_SUMMARY
15 * NO_WRITE_OPTIMIZATION_SUMMARY
16 * NO_STMT_FIXUP
17 * NO_FUNCTION_TRANSFORM
18 * NO_VARIABLE_TRANSFORM
19 * NO_GATE
20 * NO_EXECUTE
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
25 */
26
27#ifndef PASS_NAME
28#error at least PASS_NAME must be defined
29#else
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
34
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)
37
38#define __PASS_NAME_PASS(n) _GCC_PLUGIN_CONCAT2(n, _pass)
39#define _PASS_NAME_PASS __PASS_NAME_PASS(PASS_NAME)
40
41#define _PASS_NAME_NAME _GCC_PLUGIN_STRINGIFY(PASS_NAME)
42
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)
45
46#ifdef NO_GENERATE_SUMMARY
47#define _GENERATE_SUMMARY NULL
48#else
49#define __GENERATE_SUMMARY(n) _GCC_PLUGIN_CONCAT2(n, _generate_summary)
50#define _GENERATE_SUMMARY __GENERATE_SUMMARY(PASS_NAME)
51#endif
52
53#ifdef NO_READ_SUMMARY
54#define _READ_SUMMARY NULL
55#else
56#define __READ_SUMMARY(n) _GCC_PLUGIN_CONCAT2(n, _read_summary)
57#define _READ_SUMMARY __READ_SUMMARY(PASS_NAME)
58#endif
59
60#ifdef NO_WRITE_SUMMARY
61#define _WRITE_SUMMARY NULL
62#else
63#define __WRITE_SUMMARY(n) _GCC_PLUGIN_CONCAT2(n, _write_summary)
64#define _WRITE_SUMMARY __WRITE_SUMMARY(PASS_NAME)
65#endif
66
67#ifdef NO_READ_OPTIMIZATION_SUMMARY
68#define _READ_OPTIMIZATION_SUMMARY NULL
69#else
70#define __READ_OPTIMIZATION_SUMMARY(n) _GCC_PLUGIN_CONCAT2(n, _read_optimization_summary)
71#define _READ_OPTIMIZATION_SUMMARY __READ_OPTIMIZATION_SUMMARY(PASS_NAME)
72#endif
73
74#ifdef NO_WRITE_OPTIMIZATION_SUMMARY
75#define _WRITE_OPTIMIZATION_SUMMARY NULL
76#else
77#define __WRITE_OPTIMIZATION_SUMMARY(n) _GCC_PLUGIN_CONCAT2(n, _write_optimization_summary)
78#define _WRITE_OPTIMIZATION_SUMMARY __WRITE_OPTIMIZATION_SUMMARY(PASS_NAME)
79#endif
80
81#ifdef NO_STMT_FIXUP
82#define _STMT_FIXUP NULL
83#else
84#define __STMT_FIXUP(n) _GCC_PLUGIN_CONCAT2(n, _stmt_fixup)
85#define _STMT_FIXUP __STMT_FIXUP(PASS_NAME)
86#endif
87
88#ifdef NO_FUNCTION_TRANSFORM
89#define _FUNCTION_TRANSFORM NULL
90#else
91#define __FUNCTION_TRANSFORM(n) _GCC_PLUGIN_CONCAT2(n, _function_transform)
92#define _FUNCTION_TRANSFORM __FUNCTION_TRANSFORM(PASS_NAME)
93#endif
94
95#ifdef NO_VARIABLE_TRANSFORM
96#define _VARIABLE_TRANSFORM NULL
97#else
98#define __VARIABLE_TRANSFORM(n) _GCC_PLUGIN_CONCAT2(n, _variable_transform)
99#define _VARIABLE_TRANSFORM __VARIABLE_TRANSFORM(PASS_NAME)
100#endif
101
102#ifdef NO_GATE
103#define _GATE NULL
104#define _HAS_GATE false
105#else
106#define __GATE(n) _GCC_PLUGIN_CONCAT2(n, _gate)
107#define _GATE __GATE(PASS_NAME)
108#define _HAS_GATE true
109#endif
110
111#ifdef NO_EXECUTE
112#define _EXECUTE NULL
113#define _HAS_EXECUTE false
114#else
115#define __EXECUTE(n) _GCC_PLUGIN_CONCAT2(n, _execute)
116#define _EXECUTE __EXECUTE(PASS_NAME)
117#define _HAS_EXECUTE true
118#endif
119
120#ifndef PROPERTIES_REQUIRED
121#define PROPERTIES_REQUIRED 0
122#endif
123
124#ifndef PROPERTIES_PROVIDED
125#define PROPERTIES_PROVIDED 0
126#endif
127
128#ifndef PROPERTIES_DESTROYED
129#define PROPERTIES_DESTROYED 0
130#endif
131
132#ifndef TODO_FLAGS_START
133#define TODO_FLAGS_START 0
134#endif
135
136#ifndef TODO_FLAGS_FINISH
137#define TODO_FLAGS_FINISH 0
138#endif
139
140#ifndef FUNCTION_TRANSFORM_TODO_FLAGS_START
141#define FUNCTION_TRANSFORM_TODO_FLAGS_START 0
142#endif
143
Emese Revfy6b90bd42016-05-24 00:09:38 +0200144namespace {
145static const pass_data _PASS_NAME_PASS_DATA = {
Emese Revfy6b90bd42016-05-24 00:09:38 +0200146 .type = IPA_PASS,
147 .name = _PASS_NAME_NAME,
Emese Revfy6b90bd42016-05-24 00:09:38 +0200148 .optinfo_flags = OPTGROUP_NONE,
Emese Revfy6b90bd42016-05-24 00:09:38 +0200149 .tv_id = TV_NONE,
150 .properties_required = PROPERTIES_REQUIRED,
151 .properties_provided = PROPERTIES_PROVIDED,
152 .properties_destroyed = PROPERTIES_DESTROYED,
153 .todo_flags_start = TODO_FLAGS_START,
154 .todo_flags_finish = TODO_FLAGS_FINISH,
Emese Revfy6b90bd42016-05-24 00:09:38 +0200155};
156
Emese Revfy6b90bd42016-05-24 00:09:38 +0200157class _PASS_NAME_PASS : public ipa_opt_pass_d {
158public:
159 _PASS_NAME_PASS() : ipa_opt_pass_d(_PASS_NAME_PASS_DATA,
160 g,
161 _GENERATE_SUMMARY,
162 _WRITE_SUMMARY,
163 _READ_SUMMARY,
164 _WRITE_OPTIMIZATION_SUMMARY,
165 _READ_OPTIMIZATION_SUMMARY,
166 _STMT_FIXUP,
167 FUNCTION_TRANSFORM_TODO_FLAGS_START,
168 _FUNCTION_TRANSFORM,
169 _VARIABLE_TRANSFORM) {}
170
171#ifndef NO_GATE
Emese Revfy6b90bd42016-05-24 00:09:38 +0200172 virtual bool gate(function *) { return _GATE(); }
Emese Revfy6b90bd42016-05-24 00:09:38 +0200173
174 virtual opt_pass *clone() { return new _PASS_NAME_PASS(); }
175
176#ifndef NO_EXECUTE
Emese Revfy6b90bd42016-05-24 00:09:38 +0200177 virtual unsigned int execute(function *) { return _EXECUTE(); }
Emese Revfy6b90bd42016-05-24 00:09:38 +0200178#endif
179};
180}
181
182opt_pass *_MAKE_PASS_NAME_PASS(void)
183{
184 return new _PASS_NAME_PASS();
185}
186#else
187struct opt_pass *_MAKE_PASS_NAME_PASS(void)
188{
189 return &_PASS_NAME_PASS.pass;
190}
191#endif
192
193/* clean up user provided defines */
194#undef PASS_NAME
195#undef NO_GENERATE_SUMMARY
196#undef NO_WRITE_SUMMARY
197#undef NO_READ_SUMMARY
198#undef NO_WRITE_OPTIMIZATION_SUMMARY
199#undef NO_READ_OPTIMIZATION_SUMMARY
200#undef NO_STMT_FIXUP
201#undef NO_FUNCTION_TRANSFORM
202#undef NO_VARIABLE_TRANSFORM
203#undef NO_GATE
204#undef NO_EXECUTE
205
206#undef FUNCTION_TRANSFORM_TODO_FLAGS_START
207#undef PROPERTIES_DESTROYED
208#undef PROPERTIES_PROVIDED
209#undef PROPERTIES_REQUIRED
210#undef TODO_FLAGS_FINISH
211#undef TODO_FLAGS_START
212
213/* clean up generated defines */
214#undef _EXECUTE
215#undef __EXECUTE
216#undef _FUNCTION_TRANSFORM
217#undef __FUNCTION_TRANSFORM
218#undef _GATE
219#undef __GATE
220#undef _GCC_PLUGIN_CONCAT2
221#undef _GCC_PLUGIN_CONCAT3
222#undef _GCC_PLUGIN_STRINGIFY
223#undef __GCC_PLUGIN_STRINGIFY
224#undef _GENERATE_SUMMARY
225#undef __GENERATE_SUMMARY
226#undef _HAS_EXECUTE
227#undef _HAS_GATE
228#undef _MAKE_PASS_NAME_PASS
229#undef __MAKE_PASS_NAME_PASS
230#undef _PASS_NAME_NAME
231#undef _PASS_NAME_PASS
232#undef __PASS_NAME_PASS
233#undef _PASS_NAME_PASS_DATA
234#undef __PASS_NAME_PASS_DATA
235#undef _READ_OPTIMIZATION_SUMMARY
236#undef __READ_OPTIMIZATION_SUMMARY
237#undef _READ_SUMMARY
238#undef __READ_SUMMARY
239#undef _STMT_FIXUP
240#undef __STMT_FIXUP
241#undef _VARIABLE_TRANSFORM
242#undef __VARIABLE_TRANSFORM
243#undef _WRITE_OPTIMIZATION_SUMMARY
244#undef __WRITE_OPTIMIZATION_SUMMARY
245#undef _WRITE_SUMMARY
246#undef __WRITE_SUMMARY
247
248#endif /* PASS_NAME */