18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Generator for IPA 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_GENERATE_SUMMARY 128c2ecf20Sopenharmony_ci * NO_READ_SUMMARY 138c2ecf20Sopenharmony_ci * NO_WRITE_SUMMARY 148c2ecf20Sopenharmony_ci * NO_READ_OPTIMIZATION_SUMMARY 158c2ecf20Sopenharmony_ci * NO_WRITE_OPTIMIZATION_SUMMARY 168c2ecf20Sopenharmony_ci * NO_STMT_FIXUP 178c2ecf20Sopenharmony_ci * NO_FUNCTION_TRANSFORM 188c2ecf20Sopenharmony_ci * NO_VARIABLE_TRANSFORM 198c2ecf20Sopenharmony_ci * NO_GATE 208c2ecf20Sopenharmony_ci * NO_EXECUTE 218c2ecf20Sopenharmony_ci * 3. before inclusion define PROPERTIES_* and *TODO_FLAGS_* to override 228c2ecf20Sopenharmony_ci * the default 0 values 238c2ecf20Sopenharmony_ci * 4. for convenience, all the above will be undefined after inclusion! 248c2ecf20Sopenharmony_ci * 5. the only exported name is make_PASS_NAME_pass() to register with gcc 258c2ecf20Sopenharmony_ci */ 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci#ifndef PASS_NAME 288c2ecf20Sopenharmony_ci#error at least PASS_NAME must be defined 298c2ecf20Sopenharmony_ci#else 308c2ecf20Sopenharmony_ci#define __GCC_PLUGIN_STRINGIFY(n) #n 318c2ecf20Sopenharmony_ci#define _GCC_PLUGIN_STRINGIFY(n) __GCC_PLUGIN_STRINGIFY(n) 328c2ecf20Sopenharmony_ci#define _GCC_PLUGIN_CONCAT2(x, y) x ## y 338c2ecf20Sopenharmony_ci#define _GCC_PLUGIN_CONCAT3(x, y, z) x ## y ## z 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci#define __PASS_NAME_PASS_DATA(n) _GCC_PLUGIN_CONCAT2(n, _pass_data) 368c2ecf20Sopenharmony_ci#define _PASS_NAME_PASS_DATA __PASS_NAME_PASS_DATA(PASS_NAME) 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci#define __PASS_NAME_PASS(n) _GCC_PLUGIN_CONCAT2(n, _pass) 398c2ecf20Sopenharmony_ci#define _PASS_NAME_PASS __PASS_NAME_PASS(PASS_NAME) 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci#define _PASS_NAME_NAME _GCC_PLUGIN_STRINGIFY(PASS_NAME) 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci#define __MAKE_PASS_NAME_PASS(n) _GCC_PLUGIN_CONCAT3(make_, n, _pass) 448c2ecf20Sopenharmony_ci#define _MAKE_PASS_NAME_PASS __MAKE_PASS_NAME_PASS(PASS_NAME) 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci#ifdef NO_GENERATE_SUMMARY 478c2ecf20Sopenharmony_ci#define _GENERATE_SUMMARY NULL 488c2ecf20Sopenharmony_ci#else 498c2ecf20Sopenharmony_ci#define __GENERATE_SUMMARY(n) _GCC_PLUGIN_CONCAT2(n, _generate_summary) 508c2ecf20Sopenharmony_ci#define _GENERATE_SUMMARY __GENERATE_SUMMARY(PASS_NAME) 518c2ecf20Sopenharmony_ci#endif 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci#ifdef NO_READ_SUMMARY 548c2ecf20Sopenharmony_ci#define _READ_SUMMARY NULL 558c2ecf20Sopenharmony_ci#else 568c2ecf20Sopenharmony_ci#define __READ_SUMMARY(n) _GCC_PLUGIN_CONCAT2(n, _read_summary) 578c2ecf20Sopenharmony_ci#define _READ_SUMMARY __READ_SUMMARY(PASS_NAME) 588c2ecf20Sopenharmony_ci#endif 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci#ifdef NO_WRITE_SUMMARY 618c2ecf20Sopenharmony_ci#define _WRITE_SUMMARY NULL 628c2ecf20Sopenharmony_ci#else 638c2ecf20Sopenharmony_ci#define __WRITE_SUMMARY(n) _GCC_PLUGIN_CONCAT2(n, _write_summary) 648c2ecf20Sopenharmony_ci#define _WRITE_SUMMARY __WRITE_SUMMARY(PASS_NAME) 658c2ecf20Sopenharmony_ci#endif 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci#ifdef NO_READ_OPTIMIZATION_SUMMARY 688c2ecf20Sopenharmony_ci#define _READ_OPTIMIZATION_SUMMARY NULL 698c2ecf20Sopenharmony_ci#else 708c2ecf20Sopenharmony_ci#define __READ_OPTIMIZATION_SUMMARY(n) _GCC_PLUGIN_CONCAT2(n, _read_optimization_summary) 718c2ecf20Sopenharmony_ci#define _READ_OPTIMIZATION_SUMMARY __READ_OPTIMIZATION_SUMMARY(PASS_NAME) 728c2ecf20Sopenharmony_ci#endif 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci#ifdef NO_WRITE_OPTIMIZATION_SUMMARY 758c2ecf20Sopenharmony_ci#define _WRITE_OPTIMIZATION_SUMMARY NULL 768c2ecf20Sopenharmony_ci#else 778c2ecf20Sopenharmony_ci#define __WRITE_OPTIMIZATION_SUMMARY(n) _GCC_PLUGIN_CONCAT2(n, _write_optimization_summary) 788c2ecf20Sopenharmony_ci#define _WRITE_OPTIMIZATION_SUMMARY __WRITE_OPTIMIZATION_SUMMARY(PASS_NAME) 798c2ecf20Sopenharmony_ci#endif 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci#ifdef NO_STMT_FIXUP 828c2ecf20Sopenharmony_ci#define _STMT_FIXUP NULL 838c2ecf20Sopenharmony_ci#else 848c2ecf20Sopenharmony_ci#define __STMT_FIXUP(n) _GCC_PLUGIN_CONCAT2(n, _stmt_fixup) 858c2ecf20Sopenharmony_ci#define _STMT_FIXUP __STMT_FIXUP(PASS_NAME) 868c2ecf20Sopenharmony_ci#endif 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci#ifdef NO_FUNCTION_TRANSFORM 898c2ecf20Sopenharmony_ci#define _FUNCTION_TRANSFORM NULL 908c2ecf20Sopenharmony_ci#else 918c2ecf20Sopenharmony_ci#define __FUNCTION_TRANSFORM(n) _GCC_PLUGIN_CONCAT2(n, _function_transform) 928c2ecf20Sopenharmony_ci#define _FUNCTION_TRANSFORM __FUNCTION_TRANSFORM(PASS_NAME) 938c2ecf20Sopenharmony_ci#endif 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci#ifdef NO_VARIABLE_TRANSFORM 968c2ecf20Sopenharmony_ci#define _VARIABLE_TRANSFORM NULL 978c2ecf20Sopenharmony_ci#else 988c2ecf20Sopenharmony_ci#define __VARIABLE_TRANSFORM(n) _GCC_PLUGIN_CONCAT2(n, _variable_transform) 998c2ecf20Sopenharmony_ci#define _VARIABLE_TRANSFORM __VARIABLE_TRANSFORM(PASS_NAME) 1008c2ecf20Sopenharmony_ci#endif 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci#ifdef NO_GATE 1038c2ecf20Sopenharmony_ci#define _GATE NULL 1048c2ecf20Sopenharmony_ci#define _HAS_GATE false 1058c2ecf20Sopenharmony_ci#else 1068c2ecf20Sopenharmony_ci#define __GATE(n) _GCC_PLUGIN_CONCAT2(n, _gate) 1078c2ecf20Sopenharmony_ci#define _GATE __GATE(PASS_NAME) 1088c2ecf20Sopenharmony_ci#define _HAS_GATE true 1098c2ecf20Sopenharmony_ci#endif 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci#ifdef NO_EXECUTE 1128c2ecf20Sopenharmony_ci#define _EXECUTE NULL 1138c2ecf20Sopenharmony_ci#define _HAS_EXECUTE false 1148c2ecf20Sopenharmony_ci#else 1158c2ecf20Sopenharmony_ci#define __EXECUTE(n) _GCC_PLUGIN_CONCAT2(n, _execute) 1168c2ecf20Sopenharmony_ci#define _EXECUTE __EXECUTE(PASS_NAME) 1178c2ecf20Sopenharmony_ci#define _HAS_EXECUTE true 1188c2ecf20Sopenharmony_ci#endif 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci#ifndef PROPERTIES_REQUIRED 1218c2ecf20Sopenharmony_ci#define PROPERTIES_REQUIRED 0 1228c2ecf20Sopenharmony_ci#endif 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci#ifndef PROPERTIES_PROVIDED 1258c2ecf20Sopenharmony_ci#define PROPERTIES_PROVIDED 0 1268c2ecf20Sopenharmony_ci#endif 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci#ifndef PROPERTIES_DESTROYED 1298c2ecf20Sopenharmony_ci#define PROPERTIES_DESTROYED 0 1308c2ecf20Sopenharmony_ci#endif 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci#ifndef TODO_FLAGS_START 1338c2ecf20Sopenharmony_ci#define TODO_FLAGS_START 0 1348c2ecf20Sopenharmony_ci#endif 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci#ifndef TODO_FLAGS_FINISH 1378c2ecf20Sopenharmony_ci#define TODO_FLAGS_FINISH 0 1388c2ecf20Sopenharmony_ci#endif 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci#ifndef FUNCTION_TRANSFORM_TODO_FLAGS_START 1418c2ecf20Sopenharmony_ci#define FUNCTION_TRANSFORM_TODO_FLAGS_START 0 1428c2ecf20Sopenharmony_ci#endif 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci#if BUILDING_GCC_VERSION >= 4009 1458c2ecf20Sopenharmony_cinamespace { 1468c2ecf20Sopenharmony_cistatic const pass_data _PASS_NAME_PASS_DATA = { 1478c2ecf20Sopenharmony_ci#else 1488c2ecf20Sopenharmony_cistatic struct ipa_opt_pass_d _PASS_NAME_PASS = { 1498c2ecf20Sopenharmony_ci .pass = { 1508c2ecf20Sopenharmony_ci#endif 1518c2ecf20Sopenharmony_ci .type = IPA_PASS, 1528c2ecf20Sopenharmony_ci .name = _PASS_NAME_NAME, 1538c2ecf20Sopenharmony_ci#if BUILDING_GCC_VERSION >= 4008 1548c2ecf20Sopenharmony_ci .optinfo_flags = OPTGROUP_NONE, 1558c2ecf20Sopenharmony_ci#endif 1568c2ecf20Sopenharmony_ci#if BUILDING_GCC_VERSION >= 5000 1578c2ecf20Sopenharmony_ci#elif BUILDING_GCC_VERSION == 4009 1588c2ecf20Sopenharmony_ci .has_gate = _HAS_GATE, 1598c2ecf20Sopenharmony_ci .has_execute = _HAS_EXECUTE, 1608c2ecf20Sopenharmony_ci#else 1618c2ecf20Sopenharmony_ci .gate = _GATE, 1628c2ecf20Sopenharmony_ci .execute = _EXECUTE, 1638c2ecf20Sopenharmony_ci .sub = NULL, 1648c2ecf20Sopenharmony_ci .next = NULL, 1658c2ecf20Sopenharmony_ci .static_pass_number = 0, 1668c2ecf20Sopenharmony_ci#endif 1678c2ecf20Sopenharmony_ci .tv_id = TV_NONE, 1688c2ecf20Sopenharmony_ci .properties_required = PROPERTIES_REQUIRED, 1698c2ecf20Sopenharmony_ci .properties_provided = PROPERTIES_PROVIDED, 1708c2ecf20Sopenharmony_ci .properties_destroyed = PROPERTIES_DESTROYED, 1718c2ecf20Sopenharmony_ci .todo_flags_start = TODO_FLAGS_START, 1728c2ecf20Sopenharmony_ci .todo_flags_finish = TODO_FLAGS_FINISH, 1738c2ecf20Sopenharmony_ci#if BUILDING_GCC_VERSION < 4009 1748c2ecf20Sopenharmony_ci }, 1758c2ecf20Sopenharmony_ci .generate_summary = _GENERATE_SUMMARY, 1768c2ecf20Sopenharmony_ci .write_summary = _WRITE_SUMMARY, 1778c2ecf20Sopenharmony_ci .read_summary = _READ_SUMMARY, 1788c2ecf20Sopenharmony_ci#if BUILDING_GCC_VERSION >= 4006 1798c2ecf20Sopenharmony_ci .write_optimization_summary = _WRITE_OPTIMIZATION_SUMMARY, 1808c2ecf20Sopenharmony_ci .read_optimization_summary = _READ_OPTIMIZATION_SUMMARY, 1818c2ecf20Sopenharmony_ci#endif 1828c2ecf20Sopenharmony_ci .stmt_fixup = _STMT_FIXUP, 1838c2ecf20Sopenharmony_ci .function_transform_todo_flags_start = FUNCTION_TRANSFORM_TODO_FLAGS_START, 1848c2ecf20Sopenharmony_ci .function_transform = _FUNCTION_TRANSFORM, 1858c2ecf20Sopenharmony_ci .variable_transform = _VARIABLE_TRANSFORM, 1868c2ecf20Sopenharmony_ci#endif 1878c2ecf20Sopenharmony_ci}; 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci#if BUILDING_GCC_VERSION >= 4009 1908c2ecf20Sopenharmony_ciclass _PASS_NAME_PASS : public ipa_opt_pass_d { 1918c2ecf20Sopenharmony_cipublic: 1928c2ecf20Sopenharmony_ci _PASS_NAME_PASS() : ipa_opt_pass_d(_PASS_NAME_PASS_DATA, 1938c2ecf20Sopenharmony_ci g, 1948c2ecf20Sopenharmony_ci _GENERATE_SUMMARY, 1958c2ecf20Sopenharmony_ci _WRITE_SUMMARY, 1968c2ecf20Sopenharmony_ci _READ_SUMMARY, 1978c2ecf20Sopenharmony_ci _WRITE_OPTIMIZATION_SUMMARY, 1988c2ecf20Sopenharmony_ci _READ_OPTIMIZATION_SUMMARY, 1998c2ecf20Sopenharmony_ci _STMT_FIXUP, 2008c2ecf20Sopenharmony_ci FUNCTION_TRANSFORM_TODO_FLAGS_START, 2018c2ecf20Sopenharmony_ci _FUNCTION_TRANSFORM, 2028c2ecf20Sopenharmony_ci _VARIABLE_TRANSFORM) {} 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_ci#ifndef NO_GATE 2058c2ecf20Sopenharmony_ci#if BUILDING_GCC_VERSION >= 5000 2068c2ecf20Sopenharmony_ci virtual bool gate(function *) { return _GATE(); } 2078c2ecf20Sopenharmony_ci#else 2088c2ecf20Sopenharmony_ci virtual bool gate(void) { return _GATE(); } 2098c2ecf20Sopenharmony_ci#endif 2108c2ecf20Sopenharmony_ci#endif 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ci virtual opt_pass *clone() { return new _PASS_NAME_PASS(); } 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_ci#ifndef NO_EXECUTE 2158c2ecf20Sopenharmony_ci#if BUILDING_GCC_VERSION >= 5000 2168c2ecf20Sopenharmony_ci virtual unsigned int execute(function *) { return _EXECUTE(); } 2178c2ecf20Sopenharmony_ci#else 2188c2ecf20Sopenharmony_ci virtual unsigned int execute(void) { return _EXECUTE(); } 2198c2ecf20Sopenharmony_ci#endif 2208c2ecf20Sopenharmony_ci#endif 2218c2ecf20Sopenharmony_ci}; 2228c2ecf20Sopenharmony_ci} 2238c2ecf20Sopenharmony_ci 2248c2ecf20Sopenharmony_ciopt_pass *_MAKE_PASS_NAME_PASS(void) 2258c2ecf20Sopenharmony_ci{ 2268c2ecf20Sopenharmony_ci return new _PASS_NAME_PASS(); 2278c2ecf20Sopenharmony_ci} 2288c2ecf20Sopenharmony_ci#else 2298c2ecf20Sopenharmony_cistruct opt_pass *_MAKE_PASS_NAME_PASS(void) 2308c2ecf20Sopenharmony_ci{ 2318c2ecf20Sopenharmony_ci return &_PASS_NAME_PASS.pass; 2328c2ecf20Sopenharmony_ci} 2338c2ecf20Sopenharmony_ci#endif 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_ci/* clean up user provided defines */ 2368c2ecf20Sopenharmony_ci#undef PASS_NAME 2378c2ecf20Sopenharmony_ci#undef NO_GENERATE_SUMMARY 2388c2ecf20Sopenharmony_ci#undef NO_WRITE_SUMMARY 2398c2ecf20Sopenharmony_ci#undef NO_READ_SUMMARY 2408c2ecf20Sopenharmony_ci#undef NO_WRITE_OPTIMIZATION_SUMMARY 2418c2ecf20Sopenharmony_ci#undef NO_READ_OPTIMIZATION_SUMMARY 2428c2ecf20Sopenharmony_ci#undef NO_STMT_FIXUP 2438c2ecf20Sopenharmony_ci#undef NO_FUNCTION_TRANSFORM 2448c2ecf20Sopenharmony_ci#undef NO_VARIABLE_TRANSFORM 2458c2ecf20Sopenharmony_ci#undef NO_GATE 2468c2ecf20Sopenharmony_ci#undef NO_EXECUTE 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_ci#undef FUNCTION_TRANSFORM_TODO_FLAGS_START 2498c2ecf20Sopenharmony_ci#undef PROPERTIES_DESTROYED 2508c2ecf20Sopenharmony_ci#undef PROPERTIES_PROVIDED 2518c2ecf20Sopenharmony_ci#undef PROPERTIES_REQUIRED 2528c2ecf20Sopenharmony_ci#undef TODO_FLAGS_FINISH 2538c2ecf20Sopenharmony_ci#undef TODO_FLAGS_START 2548c2ecf20Sopenharmony_ci 2558c2ecf20Sopenharmony_ci/* clean up generated defines */ 2568c2ecf20Sopenharmony_ci#undef _EXECUTE 2578c2ecf20Sopenharmony_ci#undef __EXECUTE 2588c2ecf20Sopenharmony_ci#undef _FUNCTION_TRANSFORM 2598c2ecf20Sopenharmony_ci#undef __FUNCTION_TRANSFORM 2608c2ecf20Sopenharmony_ci#undef _GATE 2618c2ecf20Sopenharmony_ci#undef __GATE 2628c2ecf20Sopenharmony_ci#undef _GCC_PLUGIN_CONCAT2 2638c2ecf20Sopenharmony_ci#undef _GCC_PLUGIN_CONCAT3 2648c2ecf20Sopenharmony_ci#undef _GCC_PLUGIN_STRINGIFY 2658c2ecf20Sopenharmony_ci#undef __GCC_PLUGIN_STRINGIFY 2668c2ecf20Sopenharmony_ci#undef _GENERATE_SUMMARY 2678c2ecf20Sopenharmony_ci#undef __GENERATE_SUMMARY 2688c2ecf20Sopenharmony_ci#undef _HAS_EXECUTE 2698c2ecf20Sopenharmony_ci#undef _HAS_GATE 2708c2ecf20Sopenharmony_ci#undef _MAKE_PASS_NAME_PASS 2718c2ecf20Sopenharmony_ci#undef __MAKE_PASS_NAME_PASS 2728c2ecf20Sopenharmony_ci#undef _PASS_NAME_NAME 2738c2ecf20Sopenharmony_ci#undef _PASS_NAME_PASS 2748c2ecf20Sopenharmony_ci#undef __PASS_NAME_PASS 2758c2ecf20Sopenharmony_ci#undef _PASS_NAME_PASS_DATA 2768c2ecf20Sopenharmony_ci#undef __PASS_NAME_PASS_DATA 2778c2ecf20Sopenharmony_ci#undef _READ_OPTIMIZATION_SUMMARY 2788c2ecf20Sopenharmony_ci#undef __READ_OPTIMIZATION_SUMMARY 2798c2ecf20Sopenharmony_ci#undef _READ_SUMMARY 2808c2ecf20Sopenharmony_ci#undef __READ_SUMMARY 2818c2ecf20Sopenharmony_ci#undef _STMT_FIXUP 2828c2ecf20Sopenharmony_ci#undef __STMT_FIXUP 2838c2ecf20Sopenharmony_ci#undef _VARIABLE_TRANSFORM 2848c2ecf20Sopenharmony_ci#undef __VARIABLE_TRANSFORM 2858c2ecf20Sopenharmony_ci#undef _WRITE_OPTIMIZATION_SUMMARY 2868c2ecf20Sopenharmony_ci#undef __WRITE_OPTIMIZATION_SUMMARY 2878c2ecf20Sopenharmony_ci#undef _WRITE_SUMMARY 2888c2ecf20Sopenharmony_ci#undef __WRITE_SUMMARY 2898c2ecf20Sopenharmony_ci 2908c2ecf20Sopenharmony_ci#endif /* PASS_NAME */ 291