1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Generator for RTL 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_GATE
12  *    NO_EXECUTE
13  * 3. before inclusion define PROPERTIES_* and TODO_FLAGS_* to override
14  *    the default 0 values
15  * 4. for convenience, all the above will be undefined after inclusion!
16  * 5. the only exported name is make_PASS_NAME_pass() to register with gcc
17  */
18 
19 #ifndef PASS_NAME
20 #error at least PASS_NAME must be defined
21 #else
22 #define __GCC_PLUGIN_STRINGIFY(n)	#n
23 #define _GCC_PLUGIN_STRINGIFY(n)	__GCC_PLUGIN_STRINGIFY(n)
24 #define _GCC_PLUGIN_CONCAT2(x, y)	x ## y
25 #define _GCC_PLUGIN_CONCAT3(x, y, z)	x ## y ## z
26 
27 #define __PASS_NAME_PASS_DATA(n)	_GCC_PLUGIN_CONCAT2(n, _pass_data)
28 #define _PASS_NAME_PASS_DATA		__PASS_NAME_PASS_DATA(PASS_NAME)
29 
30 #define __PASS_NAME_PASS(n)		_GCC_PLUGIN_CONCAT2(n, _pass)
31 #define _PASS_NAME_PASS			__PASS_NAME_PASS(PASS_NAME)
32 
33 #define _PASS_NAME_NAME			_GCC_PLUGIN_STRINGIFY(PASS_NAME)
34 
35 #define __MAKE_PASS_NAME_PASS(n)	_GCC_PLUGIN_CONCAT3(make_, n, _pass)
36 #define _MAKE_PASS_NAME_PASS		__MAKE_PASS_NAME_PASS(PASS_NAME)
37 
38 #ifdef NO_GATE
39 #define _GATE NULL
40 #define _HAS_GATE false
41 #else
42 #define __GATE(n)			_GCC_PLUGIN_CONCAT2(n, _gate)
43 #define _GATE				__GATE(PASS_NAME)
44 #define _HAS_GATE true
45 #endif
46 
47 #ifdef NO_EXECUTE
48 #define _EXECUTE NULL
49 #define _HAS_EXECUTE false
50 #else
51 #define __EXECUTE(n)			_GCC_PLUGIN_CONCAT2(n, _execute)
52 #define _EXECUTE			__EXECUTE(PASS_NAME)
53 #define _HAS_EXECUTE true
54 #endif
55 
56 #ifndef PROPERTIES_REQUIRED
57 #define PROPERTIES_REQUIRED 0
58 #endif
59 
60 #ifndef PROPERTIES_PROVIDED
61 #define PROPERTIES_PROVIDED 0
62 #endif
63 
64 #ifndef PROPERTIES_DESTROYED
65 #define PROPERTIES_DESTROYED 0
66 #endif
67 
68 #ifndef TODO_FLAGS_START
69 #define TODO_FLAGS_START 0
70 #endif
71 
72 #ifndef TODO_FLAGS_FINISH
73 #define TODO_FLAGS_FINISH 0
74 #endif
75 
76 #if BUILDING_GCC_VERSION >= 4009
77 namespace {
78 static const pass_data _PASS_NAME_PASS_DATA = {
79 #else
80 static struct rtl_opt_pass _PASS_NAME_PASS = {
81 	.pass = {
82 #endif
83 		.type			= RTL_PASS,
84 		.name			= _PASS_NAME_NAME,
85 #if BUILDING_GCC_VERSION >= 4008
86 		.optinfo_flags		= OPTGROUP_NONE,
87 #endif
88 #if BUILDING_GCC_VERSION >= 5000
89 #elif BUILDING_GCC_VERSION == 4009
90 		.has_gate		= _HAS_GATE,
91 		.has_execute		= _HAS_EXECUTE,
92 #else
93 		.gate			= _GATE,
94 		.execute		= _EXECUTE,
95 		.sub			= NULL,
96 		.next			= NULL,
97 		.static_pass_number	= 0,
98 #endif
99 		.tv_id			= TV_NONE,
100 		.properties_required	= PROPERTIES_REQUIRED,
101 		.properties_provided	= PROPERTIES_PROVIDED,
102 		.properties_destroyed	= PROPERTIES_DESTROYED,
103 		.todo_flags_start	= TODO_FLAGS_START,
104 		.todo_flags_finish	= TODO_FLAGS_FINISH,
105 #if BUILDING_GCC_VERSION < 4009
106 	}
107 #endif
108 };
109 
110 #if BUILDING_GCC_VERSION >= 4009
111 class _PASS_NAME_PASS : public rtl_opt_pass {
112 public:
113 	_PASS_NAME_PASS() : rtl_opt_pass(_PASS_NAME_PASS_DATA, g) {}
114 
115 #ifndef NO_GATE
116 #if BUILDING_GCC_VERSION >= 5000
117 	virtual bool gate(function *) { return _GATE(); }
118 #else
119 	virtual bool gate(void) { return _GATE(); }
120 #endif
121 #endif
122 
123 	virtual opt_pass *clone() { return new _PASS_NAME_PASS(); }
124 
125 #ifndef NO_EXECUTE
126 #if BUILDING_GCC_VERSION >= 5000
127 	virtual unsigned int execute(function *) { return _EXECUTE(); }
128 #else
129 	virtual unsigned int execute(void) { return _EXECUTE(); }
130 #endif
131 #endif
132 };
133 }
134 
135 opt_pass *_MAKE_PASS_NAME_PASS(void)
136 {
137 	return new _PASS_NAME_PASS();
138 }
139 #else
140 struct opt_pass *_MAKE_PASS_NAME_PASS(void)
141 {
142 	return &_PASS_NAME_PASS.pass;
143 }
144 #endif
145 
146 /* clean up user provided defines */
147 #undef PASS_NAME
148 #undef NO_GATE
149 #undef NO_EXECUTE
150 
151 #undef PROPERTIES_DESTROYED
152 #undef PROPERTIES_PROVIDED
153 #undef PROPERTIES_REQUIRED
154 #undef TODO_FLAGS_FINISH
155 #undef TODO_FLAGS_START
156 
157 /* clean up generated defines */
158 #undef _EXECUTE
159 #undef __EXECUTE
160 #undef _GATE
161 #undef __GATE
162 #undef _GCC_PLUGIN_CONCAT2
163 #undef _GCC_PLUGIN_CONCAT3
164 #undef _GCC_PLUGIN_STRINGIFY
165 #undef __GCC_PLUGIN_STRINGIFY
166 #undef _HAS_EXECUTE
167 #undef _HAS_GATE
168 #undef _MAKE_PASS_NAME_PASS
169 #undef __MAKE_PASS_NAME_PASS
170 #undef _PASS_NAME_NAME
171 #undef _PASS_NAME_PASS
172 #undef __PASS_NAME_PASS
173 #undef _PASS_NAME_PASS_DATA
174 #undef __PASS_NAME_PASS_DATA
175 
176 #endif /* PASS_NAME */
177