162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Generator for IPA pass related boilerplate code/data 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Supports gcc 4.5-6 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci * Usage: 862306a36Sopenharmony_ci * 962306a36Sopenharmony_ci * 1. before inclusion define PASS_NAME 1062306a36Sopenharmony_ci * 2. before inclusion define NO_* for unimplemented callbacks 1162306a36Sopenharmony_ci * NO_GENERATE_SUMMARY 1262306a36Sopenharmony_ci * NO_READ_SUMMARY 1362306a36Sopenharmony_ci * NO_WRITE_SUMMARY 1462306a36Sopenharmony_ci * NO_READ_OPTIMIZATION_SUMMARY 1562306a36Sopenharmony_ci * NO_WRITE_OPTIMIZATION_SUMMARY 1662306a36Sopenharmony_ci * NO_STMT_FIXUP 1762306a36Sopenharmony_ci * NO_FUNCTION_TRANSFORM 1862306a36Sopenharmony_ci * NO_VARIABLE_TRANSFORM 1962306a36Sopenharmony_ci * NO_GATE 2062306a36Sopenharmony_ci * NO_EXECUTE 2162306a36Sopenharmony_ci * 3. before inclusion define PROPERTIES_* and *TODO_FLAGS_* to override 2262306a36Sopenharmony_ci * the default 0 values 2362306a36Sopenharmony_ci * 4. for convenience, all the above will be undefined after inclusion! 2462306a36Sopenharmony_ci * 5. the only exported name is make_PASS_NAME_pass() to register with gcc 2562306a36Sopenharmony_ci */ 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci#ifndef PASS_NAME 2862306a36Sopenharmony_ci#error at least PASS_NAME must be defined 2962306a36Sopenharmony_ci#else 3062306a36Sopenharmony_ci#define __GCC_PLUGIN_STRINGIFY(n) #n 3162306a36Sopenharmony_ci#define _GCC_PLUGIN_STRINGIFY(n) __GCC_PLUGIN_STRINGIFY(n) 3262306a36Sopenharmony_ci#define _GCC_PLUGIN_CONCAT2(x, y) x ## y 3362306a36Sopenharmony_ci#define _GCC_PLUGIN_CONCAT3(x, y, z) x ## y ## z 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci#define __PASS_NAME_PASS_DATA(n) _GCC_PLUGIN_CONCAT2(n, _pass_data) 3662306a36Sopenharmony_ci#define _PASS_NAME_PASS_DATA __PASS_NAME_PASS_DATA(PASS_NAME) 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci#define __PASS_NAME_PASS(n) _GCC_PLUGIN_CONCAT2(n, _pass) 3962306a36Sopenharmony_ci#define _PASS_NAME_PASS __PASS_NAME_PASS(PASS_NAME) 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci#define _PASS_NAME_NAME _GCC_PLUGIN_STRINGIFY(PASS_NAME) 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci#define __MAKE_PASS_NAME_PASS(n) _GCC_PLUGIN_CONCAT3(make_, n, _pass) 4462306a36Sopenharmony_ci#define _MAKE_PASS_NAME_PASS __MAKE_PASS_NAME_PASS(PASS_NAME) 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ci#ifdef NO_GENERATE_SUMMARY 4762306a36Sopenharmony_ci#define _GENERATE_SUMMARY NULL 4862306a36Sopenharmony_ci#else 4962306a36Sopenharmony_ci#define __GENERATE_SUMMARY(n) _GCC_PLUGIN_CONCAT2(n, _generate_summary) 5062306a36Sopenharmony_ci#define _GENERATE_SUMMARY __GENERATE_SUMMARY(PASS_NAME) 5162306a36Sopenharmony_ci#endif 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci#ifdef NO_READ_SUMMARY 5462306a36Sopenharmony_ci#define _READ_SUMMARY NULL 5562306a36Sopenharmony_ci#else 5662306a36Sopenharmony_ci#define __READ_SUMMARY(n) _GCC_PLUGIN_CONCAT2(n, _read_summary) 5762306a36Sopenharmony_ci#define _READ_SUMMARY __READ_SUMMARY(PASS_NAME) 5862306a36Sopenharmony_ci#endif 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci#ifdef NO_WRITE_SUMMARY 6162306a36Sopenharmony_ci#define _WRITE_SUMMARY NULL 6262306a36Sopenharmony_ci#else 6362306a36Sopenharmony_ci#define __WRITE_SUMMARY(n) _GCC_PLUGIN_CONCAT2(n, _write_summary) 6462306a36Sopenharmony_ci#define _WRITE_SUMMARY __WRITE_SUMMARY(PASS_NAME) 6562306a36Sopenharmony_ci#endif 6662306a36Sopenharmony_ci 6762306a36Sopenharmony_ci#ifdef NO_READ_OPTIMIZATION_SUMMARY 6862306a36Sopenharmony_ci#define _READ_OPTIMIZATION_SUMMARY NULL 6962306a36Sopenharmony_ci#else 7062306a36Sopenharmony_ci#define __READ_OPTIMIZATION_SUMMARY(n) _GCC_PLUGIN_CONCAT2(n, _read_optimization_summary) 7162306a36Sopenharmony_ci#define _READ_OPTIMIZATION_SUMMARY __READ_OPTIMIZATION_SUMMARY(PASS_NAME) 7262306a36Sopenharmony_ci#endif 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_ci#ifdef NO_WRITE_OPTIMIZATION_SUMMARY 7562306a36Sopenharmony_ci#define _WRITE_OPTIMIZATION_SUMMARY NULL 7662306a36Sopenharmony_ci#else 7762306a36Sopenharmony_ci#define __WRITE_OPTIMIZATION_SUMMARY(n) _GCC_PLUGIN_CONCAT2(n, _write_optimization_summary) 7862306a36Sopenharmony_ci#define _WRITE_OPTIMIZATION_SUMMARY __WRITE_OPTIMIZATION_SUMMARY(PASS_NAME) 7962306a36Sopenharmony_ci#endif 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ci#ifdef NO_STMT_FIXUP 8262306a36Sopenharmony_ci#define _STMT_FIXUP NULL 8362306a36Sopenharmony_ci#else 8462306a36Sopenharmony_ci#define __STMT_FIXUP(n) _GCC_PLUGIN_CONCAT2(n, _stmt_fixup) 8562306a36Sopenharmony_ci#define _STMT_FIXUP __STMT_FIXUP(PASS_NAME) 8662306a36Sopenharmony_ci#endif 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_ci#ifdef NO_FUNCTION_TRANSFORM 8962306a36Sopenharmony_ci#define _FUNCTION_TRANSFORM NULL 9062306a36Sopenharmony_ci#else 9162306a36Sopenharmony_ci#define __FUNCTION_TRANSFORM(n) _GCC_PLUGIN_CONCAT2(n, _function_transform) 9262306a36Sopenharmony_ci#define _FUNCTION_TRANSFORM __FUNCTION_TRANSFORM(PASS_NAME) 9362306a36Sopenharmony_ci#endif 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_ci#ifdef NO_VARIABLE_TRANSFORM 9662306a36Sopenharmony_ci#define _VARIABLE_TRANSFORM NULL 9762306a36Sopenharmony_ci#else 9862306a36Sopenharmony_ci#define __VARIABLE_TRANSFORM(n) _GCC_PLUGIN_CONCAT2(n, _variable_transform) 9962306a36Sopenharmony_ci#define _VARIABLE_TRANSFORM __VARIABLE_TRANSFORM(PASS_NAME) 10062306a36Sopenharmony_ci#endif 10162306a36Sopenharmony_ci 10262306a36Sopenharmony_ci#ifdef NO_GATE 10362306a36Sopenharmony_ci#define _GATE NULL 10462306a36Sopenharmony_ci#define _HAS_GATE false 10562306a36Sopenharmony_ci#else 10662306a36Sopenharmony_ci#define __GATE(n) _GCC_PLUGIN_CONCAT2(n, _gate) 10762306a36Sopenharmony_ci#define _GATE __GATE(PASS_NAME) 10862306a36Sopenharmony_ci#define _HAS_GATE true 10962306a36Sopenharmony_ci#endif 11062306a36Sopenharmony_ci 11162306a36Sopenharmony_ci#ifdef NO_EXECUTE 11262306a36Sopenharmony_ci#define _EXECUTE NULL 11362306a36Sopenharmony_ci#define _HAS_EXECUTE false 11462306a36Sopenharmony_ci#else 11562306a36Sopenharmony_ci#define __EXECUTE(n) _GCC_PLUGIN_CONCAT2(n, _execute) 11662306a36Sopenharmony_ci#define _EXECUTE __EXECUTE(PASS_NAME) 11762306a36Sopenharmony_ci#define _HAS_EXECUTE true 11862306a36Sopenharmony_ci#endif 11962306a36Sopenharmony_ci 12062306a36Sopenharmony_ci#ifndef PROPERTIES_REQUIRED 12162306a36Sopenharmony_ci#define PROPERTIES_REQUIRED 0 12262306a36Sopenharmony_ci#endif 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ci#ifndef PROPERTIES_PROVIDED 12562306a36Sopenharmony_ci#define PROPERTIES_PROVIDED 0 12662306a36Sopenharmony_ci#endif 12762306a36Sopenharmony_ci 12862306a36Sopenharmony_ci#ifndef PROPERTIES_DESTROYED 12962306a36Sopenharmony_ci#define PROPERTIES_DESTROYED 0 13062306a36Sopenharmony_ci#endif 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_ci#ifndef TODO_FLAGS_START 13362306a36Sopenharmony_ci#define TODO_FLAGS_START 0 13462306a36Sopenharmony_ci#endif 13562306a36Sopenharmony_ci 13662306a36Sopenharmony_ci#ifndef TODO_FLAGS_FINISH 13762306a36Sopenharmony_ci#define TODO_FLAGS_FINISH 0 13862306a36Sopenharmony_ci#endif 13962306a36Sopenharmony_ci 14062306a36Sopenharmony_ci#ifndef FUNCTION_TRANSFORM_TODO_FLAGS_START 14162306a36Sopenharmony_ci#define FUNCTION_TRANSFORM_TODO_FLAGS_START 0 14262306a36Sopenharmony_ci#endif 14362306a36Sopenharmony_ci 14462306a36Sopenharmony_cinamespace { 14562306a36Sopenharmony_cistatic const pass_data _PASS_NAME_PASS_DATA = { 14662306a36Sopenharmony_ci .type = IPA_PASS, 14762306a36Sopenharmony_ci .name = _PASS_NAME_NAME, 14862306a36Sopenharmony_ci .optinfo_flags = OPTGROUP_NONE, 14962306a36Sopenharmony_ci .tv_id = TV_NONE, 15062306a36Sopenharmony_ci .properties_required = PROPERTIES_REQUIRED, 15162306a36Sopenharmony_ci .properties_provided = PROPERTIES_PROVIDED, 15262306a36Sopenharmony_ci .properties_destroyed = PROPERTIES_DESTROYED, 15362306a36Sopenharmony_ci .todo_flags_start = TODO_FLAGS_START, 15462306a36Sopenharmony_ci .todo_flags_finish = TODO_FLAGS_FINISH, 15562306a36Sopenharmony_ci}; 15662306a36Sopenharmony_ci 15762306a36Sopenharmony_ciclass _PASS_NAME_PASS : public ipa_opt_pass_d { 15862306a36Sopenharmony_cipublic: 15962306a36Sopenharmony_ci _PASS_NAME_PASS() : ipa_opt_pass_d(_PASS_NAME_PASS_DATA, 16062306a36Sopenharmony_ci g, 16162306a36Sopenharmony_ci _GENERATE_SUMMARY, 16262306a36Sopenharmony_ci _WRITE_SUMMARY, 16362306a36Sopenharmony_ci _READ_SUMMARY, 16462306a36Sopenharmony_ci _WRITE_OPTIMIZATION_SUMMARY, 16562306a36Sopenharmony_ci _READ_OPTIMIZATION_SUMMARY, 16662306a36Sopenharmony_ci _STMT_FIXUP, 16762306a36Sopenharmony_ci FUNCTION_TRANSFORM_TODO_FLAGS_START, 16862306a36Sopenharmony_ci _FUNCTION_TRANSFORM, 16962306a36Sopenharmony_ci _VARIABLE_TRANSFORM) {} 17062306a36Sopenharmony_ci 17162306a36Sopenharmony_ci#ifndef NO_GATE 17262306a36Sopenharmony_ci virtual bool gate(function *) { return _GATE(); } 17362306a36Sopenharmony_ci 17462306a36Sopenharmony_ci virtual opt_pass *clone() { return new _PASS_NAME_PASS(); } 17562306a36Sopenharmony_ci 17662306a36Sopenharmony_ci#ifndef NO_EXECUTE 17762306a36Sopenharmony_ci virtual unsigned int execute(function *) { return _EXECUTE(); } 17862306a36Sopenharmony_ci#endif 17962306a36Sopenharmony_ci}; 18062306a36Sopenharmony_ci} 18162306a36Sopenharmony_ci 18262306a36Sopenharmony_ciopt_pass *_MAKE_PASS_NAME_PASS(void) 18362306a36Sopenharmony_ci{ 18462306a36Sopenharmony_ci return new _PASS_NAME_PASS(); 18562306a36Sopenharmony_ci} 18662306a36Sopenharmony_ci#else 18762306a36Sopenharmony_cistruct opt_pass *_MAKE_PASS_NAME_PASS(void) 18862306a36Sopenharmony_ci{ 18962306a36Sopenharmony_ci return &_PASS_NAME_PASS.pass; 19062306a36Sopenharmony_ci} 19162306a36Sopenharmony_ci#endif 19262306a36Sopenharmony_ci 19362306a36Sopenharmony_ci/* clean up user provided defines */ 19462306a36Sopenharmony_ci#undef PASS_NAME 19562306a36Sopenharmony_ci#undef NO_GENERATE_SUMMARY 19662306a36Sopenharmony_ci#undef NO_WRITE_SUMMARY 19762306a36Sopenharmony_ci#undef NO_READ_SUMMARY 19862306a36Sopenharmony_ci#undef NO_WRITE_OPTIMIZATION_SUMMARY 19962306a36Sopenharmony_ci#undef NO_READ_OPTIMIZATION_SUMMARY 20062306a36Sopenharmony_ci#undef NO_STMT_FIXUP 20162306a36Sopenharmony_ci#undef NO_FUNCTION_TRANSFORM 20262306a36Sopenharmony_ci#undef NO_VARIABLE_TRANSFORM 20362306a36Sopenharmony_ci#undef NO_GATE 20462306a36Sopenharmony_ci#undef NO_EXECUTE 20562306a36Sopenharmony_ci 20662306a36Sopenharmony_ci#undef FUNCTION_TRANSFORM_TODO_FLAGS_START 20762306a36Sopenharmony_ci#undef PROPERTIES_DESTROYED 20862306a36Sopenharmony_ci#undef PROPERTIES_PROVIDED 20962306a36Sopenharmony_ci#undef PROPERTIES_REQUIRED 21062306a36Sopenharmony_ci#undef TODO_FLAGS_FINISH 21162306a36Sopenharmony_ci#undef TODO_FLAGS_START 21262306a36Sopenharmony_ci 21362306a36Sopenharmony_ci/* clean up generated defines */ 21462306a36Sopenharmony_ci#undef _EXECUTE 21562306a36Sopenharmony_ci#undef __EXECUTE 21662306a36Sopenharmony_ci#undef _FUNCTION_TRANSFORM 21762306a36Sopenharmony_ci#undef __FUNCTION_TRANSFORM 21862306a36Sopenharmony_ci#undef _GATE 21962306a36Sopenharmony_ci#undef __GATE 22062306a36Sopenharmony_ci#undef _GCC_PLUGIN_CONCAT2 22162306a36Sopenharmony_ci#undef _GCC_PLUGIN_CONCAT3 22262306a36Sopenharmony_ci#undef _GCC_PLUGIN_STRINGIFY 22362306a36Sopenharmony_ci#undef __GCC_PLUGIN_STRINGIFY 22462306a36Sopenharmony_ci#undef _GENERATE_SUMMARY 22562306a36Sopenharmony_ci#undef __GENERATE_SUMMARY 22662306a36Sopenharmony_ci#undef _HAS_EXECUTE 22762306a36Sopenharmony_ci#undef _HAS_GATE 22862306a36Sopenharmony_ci#undef _MAKE_PASS_NAME_PASS 22962306a36Sopenharmony_ci#undef __MAKE_PASS_NAME_PASS 23062306a36Sopenharmony_ci#undef _PASS_NAME_NAME 23162306a36Sopenharmony_ci#undef _PASS_NAME_PASS 23262306a36Sopenharmony_ci#undef __PASS_NAME_PASS 23362306a36Sopenharmony_ci#undef _PASS_NAME_PASS_DATA 23462306a36Sopenharmony_ci#undef __PASS_NAME_PASS_DATA 23562306a36Sopenharmony_ci#undef _READ_OPTIMIZATION_SUMMARY 23662306a36Sopenharmony_ci#undef __READ_OPTIMIZATION_SUMMARY 23762306a36Sopenharmony_ci#undef _READ_SUMMARY 23862306a36Sopenharmony_ci#undef __READ_SUMMARY 23962306a36Sopenharmony_ci#undef _STMT_FIXUP 24062306a36Sopenharmony_ci#undef __STMT_FIXUP 24162306a36Sopenharmony_ci#undef _VARIABLE_TRANSFORM 24262306a36Sopenharmony_ci#undef __VARIABLE_TRANSFORM 24362306a36Sopenharmony_ci#undef _WRITE_OPTIMIZATION_SUMMARY 24462306a36Sopenharmony_ci#undef __WRITE_OPTIMIZATION_SUMMARY 24562306a36Sopenharmony_ci#undef _WRITE_SUMMARY 24662306a36Sopenharmony_ci#undef __WRITE_SUMMARY 24762306a36Sopenharmony_ci 24862306a36Sopenharmony_ci#endif /* PASS_NAME */ 249