xref: /openbmc/linux/scripts/gcc-plugins/gcc-generate-ipa-pass.h (revision 03ab8e6297acd1bc0eedaa050e2a1635c576fd11)
1*b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
26b90bd4bSEmese Revfy /*
36b90bd4bSEmese Revfy  * Generator for IPA pass related boilerplate code/data
46b90bd4bSEmese Revfy  *
56b90bd4bSEmese Revfy  * Supports gcc 4.5-6
66b90bd4bSEmese Revfy  *
76b90bd4bSEmese Revfy  * Usage:
86b90bd4bSEmese Revfy  *
96b90bd4bSEmese Revfy  * 1. before inclusion define PASS_NAME
106b90bd4bSEmese Revfy  * 2. before inclusion define NO_* for unimplemented callbacks
116b90bd4bSEmese Revfy  *    NO_GENERATE_SUMMARY
126b90bd4bSEmese Revfy  *    NO_READ_SUMMARY
136b90bd4bSEmese Revfy  *    NO_WRITE_SUMMARY
146b90bd4bSEmese Revfy  *    NO_READ_OPTIMIZATION_SUMMARY
156b90bd4bSEmese Revfy  *    NO_WRITE_OPTIMIZATION_SUMMARY
166b90bd4bSEmese Revfy  *    NO_STMT_FIXUP
176b90bd4bSEmese Revfy  *    NO_FUNCTION_TRANSFORM
186b90bd4bSEmese Revfy  *    NO_VARIABLE_TRANSFORM
196b90bd4bSEmese Revfy  *    NO_GATE
206b90bd4bSEmese Revfy  *    NO_EXECUTE
216b90bd4bSEmese Revfy  * 3. before inclusion define PROPERTIES_* and *TODO_FLAGS_* to override
226b90bd4bSEmese Revfy  *    the default 0 values
236b90bd4bSEmese Revfy  * 4. for convenience, all the above will be undefined after inclusion!
246b90bd4bSEmese Revfy  * 5. the only exported name is make_PASS_NAME_pass() to register with gcc
256b90bd4bSEmese Revfy  */
266b90bd4bSEmese Revfy 
276b90bd4bSEmese Revfy #ifndef PASS_NAME
286b90bd4bSEmese Revfy #error at least PASS_NAME must be defined
296b90bd4bSEmese Revfy #else
306b90bd4bSEmese Revfy #define __GCC_PLUGIN_STRINGIFY(n)	#n
316b90bd4bSEmese Revfy #define _GCC_PLUGIN_STRINGIFY(n)	__GCC_PLUGIN_STRINGIFY(n)
326b90bd4bSEmese Revfy #define _GCC_PLUGIN_CONCAT2(x, y)	x ## y
336b90bd4bSEmese Revfy #define _GCC_PLUGIN_CONCAT3(x, y, z)	x ## y ## z
346b90bd4bSEmese Revfy 
356b90bd4bSEmese Revfy #define __PASS_NAME_PASS_DATA(n)	_GCC_PLUGIN_CONCAT2(n, _pass_data)
366b90bd4bSEmese Revfy #define _PASS_NAME_PASS_DATA		__PASS_NAME_PASS_DATA(PASS_NAME)
376b90bd4bSEmese Revfy 
386b90bd4bSEmese Revfy #define __PASS_NAME_PASS(n)		_GCC_PLUGIN_CONCAT2(n, _pass)
396b90bd4bSEmese Revfy #define _PASS_NAME_PASS			__PASS_NAME_PASS(PASS_NAME)
406b90bd4bSEmese Revfy 
416b90bd4bSEmese Revfy #define _PASS_NAME_NAME			_GCC_PLUGIN_STRINGIFY(PASS_NAME)
426b90bd4bSEmese Revfy 
436b90bd4bSEmese Revfy #define __MAKE_PASS_NAME_PASS(n)	_GCC_PLUGIN_CONCAT3(make_, n, _pass)
446b90bd4bSEmese Revfy #define _MAKE_PASS_NAME_PASS		__MAKE_PASS_NAME_PASS(PASS_NAME)
456b90bd4bSEmese Revfy 
466b90bd4bSEmese Revfy #ifdef NO_GENERATE_SUMMARY
476b90bd4bSEmese Revfy #define _GENERATE_SUMMARY NULL
486b90bd4bSEmese Revfy #else
496b90bd4bSEmese Revfy #define __GENERATE_SUMMARY(n)		_GCC_PLUGIN_CONCAT2(n, _generate_summary)
506b90bd4bSEmese Revfy #define _GENERATE_SUMMARY		__GENERATE_SUMMARY(PASS_NAME)
516b90bd4bSEmese Revfy #endif
526b90bd4bSEmese Revfy 
536b90bd4bSEmese Revfy #ifdef NO_READ_SUMMARY
546b90bd4bSEmese Revfy #define _READ_SUMMARY NULL
556b90bd4bSEmese Revfy #else
566b90bd4bSEmese Revfy #define __READ_SUMMARY(n)		_GCC_PLUGIN_CONCAT2(n, _read_summary)
576b90bd4bSEmese Revfy #define _READ_SUMMARY			__READ_SUMMARY(PASS_NAME)
586b90bd4bSEmese Revfy #endif
596b90bd4bSEmese Revfy 
606b90bd4bSEmese Revfy #ifdef NO_WRITE_SUMMARY
616b90bd4bSEmese Revfy #define _WRITE_SUMMARY NULL
626b90bd4bSEmese Revfy #else
636b90bd4bSEmese Revfy #define __WRITE_SUMMARY(n)		_GCC_PLUGIN_CONCAT2(n, _write_summary)
646b90bd4bSEmese Revfy #define _WRITE_SUMMARY			__WRITE_SUMMARY(PASS_NAME)
656b90bd4bSEmese Revfy #endif
666b90bd4bSEmese Revfy 
676b90bd4bSEmese Revfy #ifdef NO_READ_OPTIMIZATION_SUMMARY
686b90bd4bSEmese Revfy #define _READ_OPTIMIZATION_SUMMARY NULL
696b90bd4bSEmese Revfy #else
706b90bd4bSEmese Revfy #define __READ_OPTIMIZATION_SUMMARY(n)	_GCC_PLUGIN_CONCAT2(n, _read_optimization_summary)
716b90bd4bSEmese Revfy #define _READ_OPTIMIZATION_SUMMARY	__READ_OPTIMIZATION_SUMMARY(PASS_NAME)
726b90bd4bSEmese Revfy #endif
736b90bd4bSEmese Revfy 
746b90bd4bSEmese Revfy #ifdef NO_WRITE_OPTIMIZATION_SUMMARY
756b90bd4bSEmese Revfy #define _WRITE_OPTIMIZATION_SUMMARY NULL
766b90bd4bSEmese Revfy #else
776b90bd4bSEmese Revfy #define __WRITE_OPTIMIZATION_SUMMARY(n)	_GCC_PLUGIN_CONCAT2(n, _write_optimization_summary)
786b90bd4bSEmese Revfy #define _WRITE_OPTIMIZATION_SUMMARY	__WRITE_OPTIMIZATION_SUMMARY(PASS_NAME)
796b90bd4bSEmese Revfy #endif
806b90bd4bSEmese Revfy 
816b90bd4bSEmese Revfy #ifdef NO_STMT_FIXUP
826b90bd4bSEmese Revfy #define _STMT_FIXUP NULL
836b90bd4bSEmese Revfy #else
846b90bd4bSEmese Revfy #define __STMT_FIXUP(n)			_GCC_PLUGIN_CONCAT2(n, _stmt_fixup)
856b90bd4bSEmese Revfy #define _STMT_FIXUP			__STMT_FIXUP(PASS_NAME)
866b90bd4bSEmese Revfy #endif
876b90bd4bSEmese Revfy 
886b90bd4bSEmese Revfy #ifdef NO_FUNCTION_TRANSFORM
896b90bd4bSEmese Revfy #define _FUNCTION_TRANSFORM NULL
906b90bd4bSEmese Revfy #else
916b90bd4bSEmese Revfy #define __FUNCTION_TRANSFORM(n)		_GCC_PLUGIN_CONCAT2(n, _function_transform)
926b90bd4bSEmese Revfy #define _FUNCTION_TRANSFORM		__FUNCTION_TRANSFORM(PASS_NAME)
936b90bd4bSEmese Revfy #endif
946b90bd4bSEmese Revfy 
956b90bd4bSEmese Revfy #ifdef NO_VARIABLE_TRANSFORM
966b90bd4bSEmese Revfy #define _VARIABLE_TRANSFORM NULL
976b90bd4bSEmese Revfy #else
986b90bd4bSEmese Revfy #define __VARIABLE_TRANSFORM(n)		_GCC_PLUGIN_CONCAT2(n, _variable_transform)
996b90bd4bSEmese Revfy #define _VARIABLE_TRANSFORM		__VARIABLE_TRANSFORM(PASS_NAME)
1006b90bd4bSEmese Revfy #endif
1016b90bd4bSEmese Revfy 
1026b90bd4bSEmese Revfy #ifdef NO_GATE
1036b90bd4bSEmese Revfy #define _GATE NULL
1046b90bd4bSEmese Revfy #define _HAS_GATE false
1056b90bd4bSEmese Revfy #else
1066b90bd4bSEmese Revfy #define __GATE(n)			_GCC_PLUGIN_CONCAT2(n, _gate)
1076b90bd4bSEmese Revfy #define _GATE				__GATE(PASS_NAME)
1086b90bd4bSEmese Revfy #define _HAS_GATE true
1096b90bd4bSEmese Revfy #endif
1106b90bd4bSEmese Revfy 
1116b90bd4bSEmese Revfy #ifdef NO_EXECUTE
1126b90bd4bSEmese Revfy #define _EXECUTE NULL
1136b90bd4bSEmese Revfy #define _HAS_EXECUTE false
1146b90bd4bSEmese Revfy #else
1156b90bd4bSEmese Revfy #define __EXECUTE(n)			_GCC_PLUGIN_CONCAT2(n, _execute)
1166b90bd4bSEmese Revfy #define _EXECUTE			__EXECUTE(PASS_NAME)
1176b90bd4bSEmese Revfy #define _HAS_EXECUTE true
1186b90bd4bSEmese Revfy #endif
1196b90bd4bSEmese Revfy 
1206b90bd4bSEmese Revfy #ifndef PROPERTIES_REQUIRED
1216b90bd4bSEmese Revfy #define PROPERTIES_REQUIRED 0
1226b90bd4bSEmese Revfy #endif
1236b90bd4bSEmese Revfy 
1246b90bd4bSEmese Revfy #ifndef PROPERTIES_PROVIDED
1256b90bd4bSEmese Revfy #define PROPERTIES_PROVIDED 0
1266b90bd4bSEmese Revfy #endif
1276b90bd4bSEmese Revfy 
1286b90bd4bSEmese Revfy #ifndef PROPERTIES_DESTROYED
1296b90bd4bSEmese Revfy #define PROPERTIES_DESTROYED 0
1306b90bd4bSEmese Revfy #endif
1316b90bd4bSEmese Revfy 
1326b90bd4bSEmese Revfy #ifndef TODO_FLAGS_START
1336b90bd4bSEmese Revfy #define TODO_FLAGS_START 0
1346b90bd4bSEmese Revfy #endif
1356b90bd4bSEmese Revfy 
1366b90bd4bSEmese Revfy #ifndef TODO_FLAGS_FINISH
1376b90bd4bSEmese Revfy #define TODO_FLAGS_FINISH 0
1386b90bd4bSEmese Revfy #endif
1396b90bd4bSEmese Revfy 
1406b90bd4bSEmese Revfy #ifndef FUNCTION_TRANSFORM_TODO_FLAGS_START
1416b90bd4bSEmese Revfy #define FUNCTION_TRANSFORM_TODO_FLAGS_START 0
1426b90bd4bSEmese Revfy #endif
1436b90bd4bSEmese Revfy 
1446b90bd4bSEmese Revfy namespace {
1456b90bd4bSEmese Revfy static const pass_data _PASS_NAME_PASS_DATA = {
1466b90bd4bSEmese Revfy 		.type			= IPA_PASS,
1476b90bd4bSEmese Revfy 		.name			= _PASS_NAME_NAME,
1486b90bd4bSEmese Revfy 		.optinfo_flags		= OPTGROUP_NONE,
1496b90bd4bSEmese Revfy 		.tv_id			= TV_NONE,
1506b90bd4bSEmese Revfy 		.properties_required	= PROPERTIES_REQUIRED,
1516b90bd4bSEmese Revfy 		.properties_provided	= PROPERTIES_PROVIDED,
1526b90bd4bSEmese Revfy 		.properties_destroyed	= PROPERTIES_DESTROYED,
1536b90bd4bSEmese Revfy 		.todo_flags_start	= TODO_FLAGS_START,
1546b90bd4bSEmese Revfy 		.todo_flags_finish	= TODO_FLAGS_FINISH,
1556b90bd4bSEmese Revfy };
1566b90bd4bSEmese Revfy 
1576b90bd4bSEmese Revfy class _PASS_NAME_PASS : public ipa_opt_pass_d {
1586b90bd4bSEmese Revfy public:
_PASS_NAME_PASS()1596b90bd4bSEmese Revfy 	_PASS_NAME_PASS() : ipa_opt_pass_d(_PASS_NAME_PASS_DATA,
1606b90bd4bSEmese Revfy 			 g,
1616b90bd4bSEmese Revfy 			 _GENERATE_SUMMARY,
1626b90bd4bSEmese Revfy 			 _WRITE_SUMMARY,
1636b90bd4bSEmese Revfy 			 _READ_SUMMARY,
1646b90bd4bSEmese Revfy 			 _WRITE_OPTIMIZATION_SUMMARY,
1656b90bd4bSEmese Revfy 			 _READ_OPTIMIZATION_SUMMARY,
1666b90bd4bSEmese Revfy 			 _STMT_FIXUP,
1676b90bd4bSEmese Revfy 			 FUNCTION_TRANSFORM_TODO_FLAGS_START,
1686b90bd4bSEmese Revfy 			 _FUNCTION_TRANSFORM,
1696b90bd4bSEmese Revfy 			 _VARIABLE_TRANSFORM) {}
1706b90bd4bSEmese Revfy 
1716b90bd4bSEmese Revfy #ifndef NO_GATE
gate(function *)1726b90bd4bSEmese Revfy 	virtual bool gate(function *) { return _GATE(); }
1736b90bd4bSEmese Revfy 
clone()1746b90bd4bSEmese Revfy 	virtual opt_pass *clone() { return new _PASS_NAME_PASS(); }
1756b90bd4bSEmese Revfy 
1766b90bd4bSEmese Revfy #ifndef NO_EXECUTE
execute(function *)1776b90bd4bSEmese Revfy 	virtual unsigned int execute(function *) { return _EXECUTE(); }
1786b90bd4bSEmese Revfy #endif
1796b90bd4bSEmese Revfy };
1806b90bd4bSEmese Revfy }
1816b90bd4bSEmese Revfy 
_MAKE_PASS_NAME_PASS(void)1826b90bd4bSEmese Revfy opt_pass *_MAKE_PASS_NAME_PASS(void)
1836b90bd4bSEmese Revfy {
1846b90bd4bSEmese Revfy 	return new _PASS_NAME_PASS();
1856b90bd4bSEmese Revfy }
1866b90bd4bSEmese Revfy #else
1876b90bd4bSEmese Revfy struct opt_pass *_MAKE_PASS_NAME_PASS(void)
1886b90bd4bSEmese Revfy {
1896b90bd4bSEmese Revfy 	return &_PASS_NAME_PASS.pass;
1906b90bd4bSEmese Revfy }
1916b90bd4bSEmese Revfy #endif
1926b90bd4bSEmese Revfy 
1936b90bd4bSEmese Revfy /* clean up user provided defines */
1946b90bd4bSEmese Revfy #undef PASS_NAME
1956b90bd4bSEmese Revfy #undef NO_GENERATE_SUMMARY
1966b90bd4bSEmese Revfy #undef NO_WRITE_SUMMARY
1976b90bd4bSEmese Revfy #undef NO_READ_SUMMARY
1986b90bd4bSEmese Revfy #undef NO_WRITE_OPTIMIZATION_SUMMARY
1996b90bd4bSEmese Revfy #undef NO_READ_OPTIMIZATION_SUMMARY
2006b90bd4bSEmese Revfy #undef NO_STMT_FIXUP
2016b90bd4bSEmese Revfy #undef NO_FUNCTION_TRANSFORM
2026b90bd4bSEmese Revfy #undef NO_VARIABLE_TRANSFORM
2036b90bd4bSEmese Revfy #undef NO_GATE
2046b90bd4bSEmese Revfy #undef NO_EXECUTE
2056b90bd4bSEmese Revfy 
2066b90bd4bSEmese Revfy #undef FUNCTION_TRANSFORM_TODO_FLAGS_START
2076b90bd4bSEmese Revfy #undef PROPERTIES_DESTROYED
2086b90bd4bSEmese Revfy #undef PROPERTIES_PROVIDED
2096b90bd4bSEmese Revfy #undef PROPERTIES_REQUIRED
2106b90bd4bSEmese Revfy #undef TODO_FLAGS_FINISH
2116b90bd4bSEmese Revfy #undef TODO_FLAGS_START
2126b90bd4bSEmese Revfy 
2136b90bd4bSEmese Revfy /* clean up generated defines */
2146b90bd4bSEmese Revfy #undef _EXECUTE
2156b90bd4bSEmese Revfy #undef __EXECUTE
2166b90bd4bSEmese Revfy #undef _FUNCTION_TRANSFORM
2176b90bd4bSEmese Revfy #undef __FUNCTION_TRANSFORM
2186b90bd4bSEmese Revfy #undef _GATE
2196b90bd4bSEmese Revfy #undef __GATE
2206b90bd4bSEmese Revfy #undef _GCC_PLUGIN_CONCAT2
2216b90bd4bSEmese Revfy #undef _GCC_PLUGIN_CONCAT3
2226b90bd4bSEmese Revfy #undef _GCC_PLUGIN_STRINGIFY
2236b90bd4bSEmese Revfy #undef __GCC_PLUGIN_STRINGIFY
2246b90bd4bSEmese Revfy #undef _GENERATE_SUMMARY
2256b90bd4bSEmese Revfy #undef __GENERATE_SUMMARY
2266b90bd4bSEmese Revfy #undef _HAS_EXECUTE
2276b90bd4bSEmese Revfy #undef _HAS_GATE
2286b90bd4bSEmese Revfy #undef _MAKE_PASS_NAME_PASS
2296b90bd4bSEmese Revfy #undef __MAKE_PASS_NAME_PASS
2306b90bd4bSEmese Revfy #undef _PASS_NAME_NAME
2316b90bd4bSEmese Revfy #undef _PASS_NAME_PASS
2326b90bd4bSEmese Revfy #undef __PASS_NAME_PASS
2336b90bd4bSEmese Revfy #undef _PASS_NAME_PASS_DATA
2346b90bd4bSEmese Revfy #undef __PASS_NAME_PASS_DATA
2356b90bd4bSEmese Revfy #undef _READ_OPTIMIZATION_SUMMARY
2366b90bd4bSEmese Revfy #undef __READ_OPTIMIZATION_SUMMARY
2376b90bd4bSEmese Revfy #undef _READ_SUMMARY
2386b90bd4bSEmese Revfy #undef __READ_SUMMARY
2396b90bd4bSEmese Revfy #undef _STMT_FIXUP
2406b90bd4bSEmese Revfy #undef __STMT_FIXUP
2416b90bd4bSEmese Revfy #undef _VARIABLE_TRANSFORM
2426b90bd4bSEmese Revfy #undef __VARIABLE_TRANSFORM
2436b90bd4bSEmese Revfy #undef _WRITE_OPTIMIZATION_SUMMARY
2446b90bd4bSEmese Revfy #undef __WRITE_OPTIMIZATION_SUMMARY
2456b90bd4bSEmese Revfy #undef _WRITE_SUMMARY
2466b90bd4bSEmese Revfy #undef __WRITE_SUMMARY
2476b90bd4bSEmese Revfy 
2486b90bd4bSEmese Revfy #endif /* PASS_NAME */
249