18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Generator for GIMPLE pass related boilerplate code/data
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Supports gcc 4.5-6
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Usage:
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * 1. before inclusion define PASS_NAME
108c2ecf20Sopenharmony_ci * 2. before inclusion define NO_* for unimplemented callbacks
118c2ecf20Sopenharmony_ci *    NO_GATE
128c2ecf20Sopenharmony_ci *    NO_EXECUTE
138c2ecf20Sopenharmony_ci * 3. before inclusion define PROPERTIES_* and TODO_FLAGS_* to override
148c2ecf20Sopenharmony_ci *    the default 0 values
158c2ecf20Sopenharmony_ci * 4. for convenience, all the above will be undefined after inclusion!
168c2ecf20Sopenharmony_ci * 5. the only exported name is make_PASS_NAME_pass() to register with gcc
178c2ecf20Sopenharmony_ci */
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#ifndef PASS_NAME
208c2ecf20Sopenharmony_ci#error at least PASS_NAME must be defined
218c2ecf20Sopenharmony_ci#else
228c2ecf20Sopenharmony_ci#define __GCC_PLUGIN_STRINGIFY(n)	#n
238c2ecf20Sopenharmony_ci#define _GCC_PLUGIN_STRINGIFY(n)	__GCC_PLUGIN_STRINGIFY(n)
248c2ecf20Sopenharmony_ci#define _GCC_PLUGIN_CONCAT2(x, y)	x ## y
258c2ecf20Sopenharmony_ci#define _GCC_PLUGIN_CONCAT3(x, y, z)	x ## y ## z
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci#define __PASS_NAME_PASS_DATA(n)	_GCC_PLUGIN_CONCAT2(n, _pass_data)
288c2ecf20Sopenharmony_ci#define _PASS_NAME_PASS_DATA		__PASS_NAME_PASS_DATA(PASS_NAME)
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci#define __PASS_NAME_PASS(n)		_GCC_PLUGIN_CONCAT2(n, _pass)
318c2ecf20Sopenharmony_ci#define _PASS_NAME_PASS			__PASS_NAME_PASS(PASS_NAME)
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci#define _PASS_NAME_NAME			_GCC_PLUGIN_STRINGIFY(PASS_NAME)
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#define __MAKE_PASS_NAME_PASS(n)	_GCC_PLUGIN_CONCAT3(make_, n, _pass)
368c2ecf20Sopenharmony_ci#define _MAKE_PASS_NAME_PASS		__MAKE_PASS_NAME_PASS(PASS_NAME)
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#ifdef NO_GATE
398c2ecf20Sopenharmony_ci#define _GATE NULL
408c2ecf20Sopenharmony_ci#define _HAS_GATE false
418c2ecf20Sopenharmony_ci#else
428c2ecf20Sopenharmony_ci#define __GATE(n)			_GCC_PLUGIN_CONCAT2(n, _gate)
438c2ecf20Sopenharmony_ci#define _GATE				__GATE(PASS_NAME)
448c2ecf20Sopenharmony_ci#define _HAS_GATE true
458c2ecf20Sopenharmony_ci#endif
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci#ifdef NO_EXECUTE
488c2ecf20Sopenharmony_ci#define _EXECUTE NULL
498c2ecf20Sopenharmony_ci#define _HAS_EXECUTE false
508c2ecf20Sopenharmony_ci#else
518c2ecf20Sopenharmony_ci#define __EXECUTE(n)			_GCC_PLUGIN_CONCAT2(n, _execute)
528c2ecf20Sopenharmony_ci#define _EXECUTE			__EXECUTE(PASS_NAME)
538c2ecf20Sopenharmony_ci#define _HAS_EXECUTE true
548c2ecf20Sopenharmony_ci#endif
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci#ifndef PROPERTIES_REQUIRED
578c2ecf20Sopenharmony_ci#define PROPERTIES_REQUIRED 0
588c2ecf20Sopenharmony_ci#endif
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci#ifndef PROPERTIES_PROVIDED
618c2ecf20Sopenharmony_ci#define PROPERTIES_PROVIDED 0
628c2ecf20Sopenharmony_ci#endif
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci#ifndef PROPERTIES_DESTROYED
658c2ecf20Sopenharmony_ci#define PROPERTIES_DESTROYED 0
668c2ecf20Sopenharmony_ci#endif
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci#ifndef TODO_FLAGS_START
698c2ecf20Sopenharmony_ci#define TODO_FLAGS_START 0
708c2ecf20Sopenharmony_ci#endif
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci#ifndef TODO_FLAGS_FINISH
738c2ecf20Sopenharmony_ci#define TODO_FLAGS_FINISH 0
748c2ecf20Sopenharmony_ci#endif
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci#if BUILDING_GCC_VERSION >= 4009
778c2ecf20Sopenharmony_cinamespace {
788c2ecf20Sopenharmony_cistatic const pass_data _PASS_NAME_PASS_DATA = {
798c2ecf20Sopenharmony_ci#else
808c2ecf20Sopenharmony_cistatic struct gimple_opt_pass _PASS_NAME_PASS = {
818c2ecf20Sopenharmony_ci	.pass = {
828c2ecf20Sopenharmony_ci#endif
838c2ecf20Sopenharmony_ci		.type			= GIMPLE_PASS,
848c2ecf20Sopenharmony_ci		.name			= _PASS_NAME_NAME,
858c2ecf20Sopenharmony_ci#if BUILDING_GCC_VERSION >= 4008
868c2ecf20Sopenharmony_ci		.optinfo_flags		= OPTGROUP_NONE,
878c2ecf20Sopenharmony_ci#endif
888c2ecf20Sopenharmony_ci#if BUILDING_GCC_VERSION >= 5000
898c2ecf20Sopenharmony_ci#elif BUILDING_GCC_VERSION == 4009
908c2ecf20Sopenharmony_ci		.has_gate		= _HAS_GATE,
918c2ecf20Sopenharmony_ci		.has_execute		= _HAS_EXECUTE,
928c2ecf20Sopenharmony_ci#else
938c2ecf20Sopenharmony_ci		.gate			= _GATE,
948c2ecf20Sopenharmony_ci		.execute		= _EXECUTE,
958c2ecf20Sopenharmony_ci		.sub			= NULL,
968c2ecf20Sopenharmony_ci		.next			= NULL,
978c2ecf20Sopenharmony_ci		.static_pass_number	= 0,
988c2ecf20Sopenharmony_ci#endif
998c2ecf20Sopenharmony_ci		.tv_id			= TV_NONE,
1008c2ecf20Sopenharmony_ci		.properties_required	= PROPERTIES_REQUIRED,
1018c2ecf20Sopenharmony_ci		.properties_provided	= PROPERTIES_PROVIDED,
1028c2ecf20Sopenharmony_ci		.properties_destroyed	= PROPERTIES_DESTROYED,
1038c2ecf20Sopenharmony_ci		.todo_flags_start	= TODO_FLAGS_START,
1048c2ecf20Sopenharmony_ci		.todo_flags_finish	= TODO_FLAGS_FINISH,
1058c2ecf20Sopenharmony_ci#if BUILDING_GCC_VERSION < 4009
1068c2ecf20Sopenharmony_ci	}
1078c2ecf20Sopenharmony_ci#endif
1088c2ecf20Sopenharmony_ci};
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci#if BUILDING_GCC_VERSION >= 4009
1118c2ecf20Sopenharmony_ciclass _PASS_NAME_PASS : public gimple_opt_pass {
1128c2ecf20Sopenharmony_cipublic:
1138c2ecf20Sopenharmony_ci	_PASS_NAME_PASS() : gimple_opt_pass(_PASS_NAME_PASS_DATA, g) {}
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci#ifndef NO_GATE
1168c2ecf20Sopenharmony_ci#if BUILDING_GCC_VERSION >= 5000
1178c2ecf20Sopenharmony_ci	virtual bool gate(function *) { return _GATE(); }
1188c2ecf20Sopenharmony_ci#else
1198c2ecf20Sopenharmony_ci	virtual bool gate(void) { return _GATE(); }
1208c2ecf20Sopenharmony_ci#endif
1218c2ecf20Sopenharmony_ci#endif
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci	virtual opt_pass * clone () { return new _PASS_NAME_PASS(); }
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci#ifndef NO_EXECUTE
1268c2ecf20Sopenharmony_ci#if BUILDING_GCC_VERSION >= 5000
1278c2ecf20Sopenharmony_ci	virtual unsigned int execute(function *) { return _EXECUTE(); }
1288c2ecf20Sopenharmony_ci#else
1298c2ecf20Sopenharmony_ci	virtual unsigned int execute(void) { return _EXECUTE(); }
1308c2ecf20Sopenharmony_ci#endif
1318c2ecf20Sopenharmony_ci#endif
1328c2ecf20Sopenharmony_ci};
1338c2ecf20Sopenharmony_ci}
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ciopt_pass *_MAKE_PASS_NAME_PASS(void)
1368c2ecf20Sopenharmony_ci{
1378c2ecf20Sopenharmony_ci	return new _PASS_NAME_PASS();
1388c2ecf20Sopenharmony_ci}
1398c2ecf20Sopenharmony_ci#else
1408c2ecf20Sopenharmony_cistruct opt_pass *_MAKE_PASS_NAME_PASS(void)
1418c2ecf20Sopenharmony_ci{
1428c2ecf20Sopenharmony_ci	return &_PASS_NAME_PASS.pass;
1438c2ecf20Sopenharmony_ci}
1448c2ecf20Sopenharmony_ci#endif
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci/* clean up user provided defines */
1478c2ecf20Sopenharmony_ci#undef PASS_NAME
1488c2ecf20Sopenharmony_ci#undef NO_GATE
1498c2ecf20Sopenharmony_ci#undef NO_EXECUTE
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci#undef PROPERTIES_DESTROYED
1528c2ecf20Sopenharmony_ci#undef PROPERTIES_PROVIDED
1538c2ecf20Sopenharmony_ci#undef PROPERTIES_REQUIRED
1548c2ecf20Sopenharmony_ci#undef TODO_FLAGS_FINISH
1558c2ecf20Sopenharmony_ci#undef TODO_FLAGS_START
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci/* clean up generated defines */
1588c2ecf20Sopenharmony_ci#undef _EXECUTE
1598c2ecf20Sopenharmony_ci#undef __EXECUTE
1608c2ecf20Sopenharmony_ci#undef _GATE
1618c2ecf20Sopenharmony_ci#undef __GATE
1628c2ecf20Sopenharmony_ci#undef _GCC_PLUGIN_CONCAT2
1638c2ecf20Sopenharmony_ci#undef _GCC_PLUGIN_CONCAT3
1648c2ecf20Sopenharmony_ci#undef _GCC_PLUGIN_STRINGIFY
1658c2ecf20Sopenharmony_ci#undef __GCC_PLUGIN_STRINGIFY
1668c2ecf20Sopenharmony_ci#undef _HAS_EXECUTE
1678c2ecf20Sopenharmony_ci#undef _HAS_GATE
1688c2ecf20Sopenharmony_ci#undef _MAKE_PASS_NAME_PASS
1698c2ecf20Sopenharmony_ci#undef __MAKE_PASS_NAME_PASS
1708c2ecf20Sopenharmony_ci#undef _PASS_NAME_NAME
1718c2ecf20Sopenharmony_ci#undef _PASS_NAME_PASS
1728c2ecf20Sopenharmony_ci#undef __PASS_NAME_PASS
1738c2ecf20Sopenharmony_ci#undef _PASS_NAME_PASS_DATA
1748c2ecf20Sopenharmony_ci#undef __PASS_NAME_PASS_DATA
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ci#endif /* PASS_NAME */
177