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 #if BUILDING_GCC_VERSION >= 4009 1456b90bd4bSEmese Revfy namespace { 1466b90bd4bSEmese Revfy static const pass_data _PASS_NAME_PASS_DATA = { 1476b90bd4bSEmese Revfy #else 1486b90bd4bSEmese Revfy static struct ipa_opt_pass_d _PASS_NAME_PASS = { 1496b90bd4bSEmese Revfy .pass = { 1506b90bd4bSEmese Revfy #endif 1516b90bd4bSEmese Revfy .type = IPA_PASS, 1526b90bd4bSEmese Revfy .name = _PASS_NAME_NAME, 1536b90bd4bSEmese Revfy #if BUILDING_GCC_VERSION >= 4008 1546b90bd4bSEmese Revfy .optinfo_flags = OPTGROUP_NONE, 1556b90bd4bSEmese Revfy #endif 1566b90bd4bSEmese Revfy #if BUILDING_GCC_VERSION >= 5000 1576b90bd4bSEmese Revfy #elif BUILDING_GCC_VERSION == 4009 1586b90bd4bSEmese Revfy .has_gate = _HAS_GATE, 1596b90bd4bSEmese Revfy .has_execute = _HAS_EXECUTE, 1606b90bd4bSEmese Revfy #else 1616b90bd4bSEmese Revfy .gate = _GATE, 1626b90bd4bSEmese Revfy .execute = _EXECUTE, 1636b90bd4bSEmese Revfy .sub = NULL, 1646b90bd4bSEmese Revfy .next = NULL, 1656b90bd4bSEmese Revfy .static_pass_number = 0, 1666b90bd4bSEmese Revfy #endif 1676b90bd4bSEmese Revfy .tv_id = TV_NONE, 1686b90bd4bSEmese Revfy .properties_required = PROPERTIES_REQUIRED, 1696b90bd4bSEmese Revfy .properties_provided = PROPERTIES_PROVIDED, 1706b90bd4bSEmese Revfy .properties_destroyed = PROPERTIES_DESTROYED, 1716b90bd4bSEmese Revfy .todo_flags_start = TODO_FLAGS_START, 1726b90bd4bSEmese Revfy .todo_flags_finish = TODO_FLAGS_FINISH, 1736b90bd4bSEmese Revfy #if BUILDING_GCC_VERSION < 4009 1746b90bd4bSEmese Revfy }, 1756b90bd4bSEmese Revfy .generate_summary = _GENERATE_SUMMARY, 1766b90bd4bSEmese Revfy .write_summary = _WRITE_SUMMARY, 1776b90bd4bSEmese Revfy .read_summary = _READ_SUMMARY, 1786b90bd4bSEmese Revfy #if BUILDING_GCC_VERSION >= 4006 1796b90bd4bSEmese Revfy .write_optimization_summary = _WRITE_OPTIMIZATION_SUMMARY, 1806b90bd4bSEmese Revfy .read_optimization_summary = _READ_OPTIMIZATION_SUMMARY, 1816b90bd4bSEmese Revfy #endif 1826b90bd4bSEmese Revfy .stmt_fixup = _STMT_FIXUP, 1836b90bd4bSEmese Revfy .function_transform_todo_flags_start = FUNCTION_TRANSFORM_TODO_FLAGS_START, 1846b90bd4bSEmese Revfy .function_transform = _FUNCTION_TRANSFORM, 1856b90bd4bSEmese Revfy .variable_transform = _VARIABLE_TRANSFORM, 1866b90bd4bSEmese Revfy #endif 1876b90bd4bSEmese Revfy }; 1886b90bd4bSEmese Revfy 1896b90bd4bSEmese Revfy #if BUILDING_GCC_VERSION >= 4009 1906b90bd4bSEmese Revfy class _PASS_NAME_PASS : public ipa_opt_pass_d { 1916b90bd4bSEmese Revfy public: 1926b90bd4bSEmese Revfy _PASS_NAME_PASS() : ipa_opt_pass_d(_PASS_NAME_PASS_DATA, 1936b90bd4bSEmese Revfy g, 1946b90bd4bSEmese Revfy _GENERATE_SUMMARY, 1956b90bd4bSEmese Revfy _WRITE_SUMMARY, 1966b90bd4bSEmese Revfy _READ_SUMMARY, 1976b90bd4bSEmese Revfy _WRITE_OPTIMIZATION_SUMMARY, 1986b90bd4bSEmese Revfy _READ_OPTIMIZATION_SUMMARY, 1996b90bd4bSEmese Revfy _STMT_FIXUP, 2006b90bd4bSEmese Revfy FUNCTION_TRANSFORM_TODO_FLAGS_START, 2016b90bd4bSEmese Revfy _FUNCTION_TRANSFORM, 2026b90bd4bSEmese Revfy _VARIABLE_TRANSFORM) {} 2036b90bd4bSEmese Revfy 2046b90bd4bSEmese Revfy #ifndef NO_GATE 2056b90bd4bSEmese Revfy #if BUILDING_GCC_VERSION >= 5000 2066b90bd4bSEmese Revfy virtual bool gate(function *) { return _GATE(); } 2076b90bd4bSEmese Revfy #else 2086b90bd4bSEmese Revfy virtual bool gate(void) { return _GATE(); } 2096b90bd4bSEmese Revfy #endif 2106b90bd4bSEmese Revfy #endif 2116b90bd4bSEmese Revfy 2126b90bd4bSEmese Revfy virtual opt_pass *clone() { return new _PASS_NAME_PASS(); } 2136b90bd4bSEmese Revfy 2146b90bd4bSEmese Revfy #ifndef NO_EXECUTE 2156b90bd4bSEmese Revfy #if BUILDING_GCC_VERSION >= 5000 2166b90bd4bSEmese Revfy virtual unsigned int execute(function *) { return _EXECUTE(); } 2176b90bd4bSEmese Revfy #else 2186b90bd4bSEmese Revfy virtual unsigned int execute(void) { return _EXECUTE(); } 2196b90bd4bSEmese Revfy #endif 2206b90bd4bSEmese Revfy #endif 2216b90bd4bSEmese Revfy }; 2226b90bd4bSEmese Revfy } 2236b90bd4bSEmese Revfy 2246b90bd4bSEmese Revfy opt_pass *_MAKE_PASS_NAME_PASS(void) 2256b90bd4bSEmese Revfy { 2266b90bd4bSEmese Revfy return new _PASS_NAME_PASS(); 2276b90bd4bSEmese Revfy } 2286b90bd4bSEmese Revfy #else 2296b90bd4bSEmese Revfy struct opt_pass *_MAKE_PASS_NAME_PASS(void) 2306b90bd4bSEmese Revfy { 2316b90bd4bSEmese Revfy return &_PASS_NAME_PASS.pass; 2326b90bd4bSEmese Revfy } 2336b90bd4bSEmese Revfy #endif 2346b90bd4bSEmese Revfy 2356b90bd4bSEmese Revfy /* clean up user provided defines */ 2366b90bd4bSEmese Revfy #undef PASS_NAME 2376b90bd4bSEmese Revfy #undef NO_GENERATE_SUMMARY 2386b90bd4bSEmese Revfy #undef NO_WRITE_SUMMARY 2396b90bd4bSEmese Revfy #undef NO_READ_SUMMARY 2406b90bd4bSEmese Revfy #undef NO_WRITE_OPTIMIZATION_SUMMARY 2416b90bd4bSEmese Revfy #undef NO_READ_OPTIMIZATION_SUMMARY 2426b90bd4bSEmese Revfy #undef NO_STMT_FIXUP 2436b90bd4bSEmese Revfy #undef NO_FUNCTION_TRANSFORM 2446b90bd4bSEmese Revfy #undef NO_VARIABLE_TRANSFORM 2456b90bd4bSEmese Revfy #undef NO_GATE 2466b90bd4bSEmese Revfy #undef NO_EXECUTE 2476b90bd4bSEmese Revfy 2486b90bd4bSEmese Revfy #undef FUNCTION_TRANSFORM_TODO_FLAGS_START 2496b90bd4bSEmese Revfy #undef PROPERTIES_DESTROYED 2506b90bd4bSEmese Revfy #undef PROPERTIES_PROVIDED 2516b90bd4bSEmese Revfy #undef PROPERTIES_REQUIRED 2526b90bd4bSEmese Revfy #undef TODO_FLAGS_FINISH 2536b90bd4bSEmese Revfy #undef TODO_FLAGS_START 2546b90bd4bSEmese Revfy 2556b90bd4bSEmese Revfy /* clean up generated defines */ 2566b90bd4bSEmese Revfy #undef _EXECUTE 2576b90bd4bSEmese Revfy #undef __EXECUTE 2586b90bd4bSEmese Revfy #undef _FUNCTION_TRANSFORM 2596b90bd4bSEmese Revfy #undef __FUNCTION_TRANSFORM 2606b90bd4bSEmese Revfy #undef _GATE 2616b90bd4bSEmese Revfy #undef __GATE 2626b90bd4bSEmese Revfy #undef _GCC_PLUGIN_CONCAT2 2636b90bd4bSEmese Revfy #undef _GCC_PLUGIN_CONCAT3 2646b90bd4bSEmese Revfy #undef _GCC_PLUGIN_STRINGIFY 2656b90bd4bSEmese Revfy #undef __GCC_PLUGIN_STRINGIFY 2666b90bd4bSEmese Revfy #undef _GENERATE_SUMMARY 2676b90bd4bSEmese Revfy #undef __GENERATE_SUMMARY 2686b90bd4bSEmese Revfy #undef _HAS_EXECUTE 2696b90bd4bSEmese Revfy #undef _HAS_GATE 2706b90bd4bSEmese Revfy #undef _MAKE_PASS_NAME_PASS 2716b90bd4bSEmese Revfy #undef __MAKE_PASS_NAME_PASS 2726b90bd4bSEmese Revfy #undef _PASS_NAME_NAME 2736b90bd4bSEmese Revfy #undef _PASS_NAME_PASS 2746b90bd4bSEmese Revfy #undef __PASS_NAME_PASS 2756b90bd4bSEmese Revfy #undef _PASS_NAME_PASS_DATA 2766b90bd4bSEmese Revfy #undef __PASS_NAME_PASS_DATA 2776b90bd4bSEmese Revfy #undef _READ_OPTIMIZATION_SUMMARY 2786b90bd4bSEmese Revfy #undef __READ_OPTIMIZATION_SUMMARY 2796b90bd4bSEmese Revfy #undef _READ_SUMMARY 2806b90bd4bSEmese Revfy #undef __READ_SUMMARY 2816b90bd4bSEmese Revfy #undef _STMT_FIXUP 2826b90bd4bSEmese Revfy #undef __STMT_FIXUP 2836b90bd4bSEmese Revfy #undef _VARIABLE_TRANSFORM 2846b90bd4bSEmese Revfy #undef __VARIABLE_TRANSFORM 2856b90bd4bSEmese Revfy #undef _WRITE_OPTIMIZATION_SUMMARY 2866b90bd4bSEmese Revfy #undef __WRITE_OPTIMIZATION_SUMMARY 2876b90bd4bSEmese Revfy #undef _WRITE_SUMMARY 2886b90bd4bSEmese Revfy #undef __WRITE_SUMMARY 2896b90bd4bSEmese Revfy 2906b90bd4bSEmese Revfy #endif /* PASS_NAME */ 291