xref: /linux/scripts/gcc-plugins/gcc-generate-rtl-pass.h (revision 03ab8e6297acd1bc0eedaa050e2a1635c576fd11)
1*b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
26b90bd4bSEmese Revfy /*
36b90bd4bSEmese Revfy  * Generator for RTL 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_GATE
126b90bd4bSEmese Revfy  *    NO_EXECUTE
136b90bd4bSEmese Revfy  * 3. before inclusion define PROPERTIES_* and TODO_FLAGS_* to override
146b90bd4bSEmese Revfy  *    the default 0 values
156b90bd4bSEmese Revfy  * 4. for convenience, all the above will be undefined after inclusion!
166b90bd4bSEmese Revfy  * 5. the only exported name is make_PASS_NAME_pass() to register with gcc
176b90bd4bSEmese Revfy  */
186b90bd4bSEmese Revfy 
196b90bd4bSEmese Revfy #ifndef PASS_NAME
206b90bd4bSEmese Revfy #error at least PASS_NAME must be defined
216b90bd4bSEmese Revfy #else
226b90bd4bSEmese Revfy #define __GCC_PLUGIN_STRINGIFY(n)	#n
236b90bd4bSEmese Revfy #define _GCC_PLUGIN_STRINGIFY(n)	__GCC_PLUGIN_STRINGIFY(n)
246b90bd4bSEmese Revfy #define _GCC_PLUGIN_CONCAT2(x, y)	x ## y
256b90bd4bSEmese Revfy #define _GCC_PLUGIN_CONCAT3(x, y, z)	x ## y ## z
266b90bd4bSEmese Revfy 
276b90bd4bSEmese Revfy #define __PASS_NAME_PASS_DATA(n)	_GCC_PLUGIN_CONCAT2(n, _pass_data)
286b90bd4bSEmese Revfy #define _PASS_NAME_PASS_DATA		__PASS_NAME_PASS_DATA(PASS_NAME)
296b90bd4bSEmese Revfy 
306b90bd4bSEmese Revfy #define __PASS_NAME_PASS(n)		_GCC_PLUGIN_CONCAT2(n, _pass)
316b90bd4bSEmese Revfy #define _PASS_NAME_PASS			__PASS_NAME_PASS(PASS_NAME)
326b90bd4bSEmese Revfy 
336b90bd4bSEmese Revfy #define _PASS_NAME_NAME			_GCC_PLUGIN_STRINGIFY(PASS_NAME)
346b90bd4bSEmese Revfy 
356b90bd4bSEmese Revfy #define __MAKE_PASS_NAME_PASS(n)	_GCC_PLUGIN_CONCAT3(make_, n, _pass)
366b90bd4bSEmese Revfy #define _MAKE_PASS_NAME_PASS		__MAKE_PASS_NAME_PASS(PASS_NAME)
376b90bd4bSEmese Revfy 
386b90bd4bSEmese Revfy #ifdef NO_GATE
396b90bd4bSEmese Revfy #define _GATE NULL
406b90bd4bSEmese Revfy #define _HAS_GATE false
416b90bd4bSEmese Revfy #else
426b90bd4bSEmese Revfy #define __GATE(n)			_GCC_PLUGIN_CONCAT2(n, _gate)
436b90bd4bSEmese Revfy #define _GATE				__GATE(PASS_NAME)
446b90bd4bSEmese Revfy #define _HAS_GATE true
456b90bd4bSEmese Revfy #endif
466b90bd4bSEmese Revfy 
476b90bd4bSEmese Revfy #ifdef NO_EXECUTE
486b90bd4bSEmese Revfy #define _EXECUTE NULL
496b90bd4bSEmese Revfy #define _HAS_EXECUTE false
506b90bd4bSEmese Revfy #else
516b90bd4bSEmese Revfy #define __EXECUTE(n)			_GCC_PLUGIN_CONCAT2(n, _execute)
526b90bd4bSEmese Revfy #define _EXECUTE			__EXECUTE(PASS_NAME)
536b90bd4bSEmese Revfy #define _HAS_EXECUTE true
546b90bd4bSEmese Revfy #endif
556b90bd4bSEmese Revfy 
566b90bd4bSEmese Revfy #ifndef PROPERTIES_REQUIRED
576b90bd4bSEmese Revfy #define PROPERTIES_REQUIRED 0
586b90bd4bSEmese Revfy #endif
596b90bd4bSEmese Revfy 
606b90bd4bSEmese Revfy #ifndef PROPERTIES_PROVIDED
616b90bd4bSEmese Revfy #define PROPERTIES_PROVIDED 0
626b90bd4bSEmese Revfy #endif
636b90bd4bSEmese Revfy 
646b90bd4bSEmese Revfy #ifndef PROPERTIES_DESTROYED
656b90bd4bSEmese Revfy #define PROPERTIES_DESTROYED 0
666b90bd4bSEmese Revfy #endif
676b90bd4bSEmese Revfy 
686b90bd4bSEmese Revfy #ifndef TODO_FLAGS_START
696b90bd4bSEmese Revfy #define TODO_FLAGS_START 0
706b90bd4bSEmese Revfy #endif
716b90bd4bSEmese Revfy 
726b90bd4bSEmese Revfy #ifndef TODO_FLAGS_FINISH
736b90bd4bSEmese Revfy #define TODO_FLAGS_FINISH 0
746b90bd4bSEmese Revfy #endif
756b90bd4bSEmese Revfy 
766b90bd4bSEmese Revfy namespace {
776b90bd4bSEmese Revfy static const pass_data _PASS_NAME_PASS_DATA = {
786b90bd4bSEmese Revfy 		.type			= RTL_PASS,
796b90bd4bSEmese Revfy 		.name			= _PASS_NAME_NAME,
806b90bd4bSEmese Revfy 		.optinfo_flags		= OPTGROUP_NONE,
816b90bd4bSEmese Revfy 		.tv_id			= TV_NONE,
826b90bd4bSEmese Revfy 		.properties_required	= PROPERTIES_REQUIRED,
836b90bd4bSEmese Revfy 		.properties_provided	= PROPERTIES_PROVIDED,
846b90bd4bSEmese Revfy 		.properties_destroyed	= PROPERTIES_DESTROYED,
856b90bd4bSEmese Revfy 		.todo_flags_start	= TODO_FLAGS_START,
866b90bd4bSEmese Revfy 		.todo_flags_finish	= TODO_FLAGS_FINISH,
876b90bd4bSEmese Revfy };
886b90bd4bSEmese Revfy 
896b90bd4bSEmese Revfy class _PASS_NAME_PASS : public rtl_opt_pass {
906b90bd4bSEmese Revfy public:
_PASS_NAME_PASS()916b90bd4bSEmese Revfy 	_PASS_NAME_PASS() : rtl_opt_pass(_PASS_NAME_PASS_DATA, g) {}
926b90bd4bSEmese Revfy 
936b90bd4bSEmese Revfy #ifndef NO_GATE
gate(function *)946b90bd4bSEmese Revfy 	virtual bool gate(function *) { return _GATE(); }
956b90bd4bSEmese Revfy #endif
966b90bd4bSEmese Revfy 
clone()976b90bd4bSEmese Revfy 	virtual opt_pass *clone() { return new _PASS_NAME_PASS(); }
986b90bd4bSEmese Revfy 
996b90bd4bSEmese Revfy #ifndef NO_EXECUTE
execute(function *)1006b90bd4bSEmese Revfy 	virtual unsigned int execute(function *) { return _EXECUTE(); }
1016b90bd4bSEmese Revfy #endif
1026b90bd4bSEmese Revfy };
1036b90bd4bSEmese Revfy }
1046b90bd4bSEmese Revfy 
_MAKE_PASS_NAME_PASS(void)1056b90bd4bSEmese Revfy opt_pass *_MAKE_PASS_NAME_PASS(void)
1066b90bd4bSEmese Revfy {
1076b90bd4bSEmese Revfy 	return new _PASS_NAME_PASS();
1086b90bd4bSEmese Revfy }
1096b90bd4bSEmese Revfy 
1106b90bd4bSEmese Revfy /* clean up user provided defines */
1116b90bd4bSEmese Revfy #undef PASS_NAME
1126b90bd4bSEmese Revfy #undef NO_GATE
1136b90bd4bSEmese Revfy #undef NO_EXECUTE
1146b90bd4bSEmese Revfy 
1156b90bd4bSEmese Revfy #undef PROPERTIES_DESTROYED
1166b90bd4bSEmese Revfy #undef PROPERTIES_PROVIDED
1176b90bd4bSEmese Revfy #undef PROPERTIES_REQUIRED
1186b90bd4bSEmese Revfy #undef TODO_FLAGS_FINISH
1196b90bd4bSEmese Revfy #undef TODO_FLAGS_START
1206b90bd4bSEmese Revfy 
1216b90bd4bSEmese Revfy /* clean up generated defines */
1226b90bd4bSEmese Revfy #undef _EXECUTE
1236b90bd4bSEmese Revfy #undef __EXECUTE
1246b90bd4bSEmese Revfy #undef _GATE
1256b90bd4bSEmese Revfy #undef __GATE
1266b90bd4bSEmese Revfy #undef _GCC_PLUGIN_CONCAT2
1276b90bd4bSEmese Revfy #undef _GCC_PLUGIN_CONCAT3
1286b90bd4bSEmese Revfy #undef _GCC_PLUGIN_STRINGIFY
1296b90bd4bSEmese Revfy #undef __GCC_PLUGIN_STRINGIFY
1306b90bd4bSEmese Revfy #undef _HAS_EXECUTE
1316b90bd4bSEmese Revfy #undef _HAS_GATE
1326b90bd4bSEmese Revfy #undef _MAKE_PASS_NAME_PASS
1336b90bd4bSEmese Revfy #undef __MAKE_PASS_NAME_PASS
1346b90bd4bSEmese Revfy #undef _PASS_NAME_NAME
1356b90bd4bSEmese Revfy #undef _PASS_NAME_PASS
1366b90bd4bSEmese Revfy #undef __PASS_NAME_PASS
1376b90bd4bSEmese Revfy #undef _PASS_NAME_PASS_DATA
1386b90bd4bSEmese Revfy #undef __PASS_NAME_PASS_DATA
1396b90bd4bSEmese Revfy 
1406b90bd4bSEmese Revfy #endif /* PASS_NAME */
141