1*6b90bd4bSEmese Revfy /* 2*6b90bd4bSEmese Revfy * Generator for SIMPLE_IPA pass related boilerplate code/data 3*6b90bd4bSEmese Revfy * 4*6b90bd4bSEmese Revfy * Supports gcc 4.5-6 5*6b90bd4bSEmese Revfy * 6*6b90bd4bSEmese Revfy * Usage: 7*6b90bd4bSEmese Revfy * 8*6b90bd4bSEmese Revfy * 1. before inclusion define PASS_NAME 9*6b90bd4bSEmese Revfy * 2. before inclusion define NO_* for unimplemented callbacks 10*6b90bd4bSEmese Revfy * NO_GATE 11*6b90bd4bSEmese Revfy * NO_EXECUTE 12*6b90bd4bSEmese Revfy * 3. before inclusion define PROPERTIES_* and TODO_FLAGS_* to override 13*6b90bd4bSEmese Revfy * the default 0 values 14*6b90bd4bSEmese Revfy * 4. for convenience, all the above will be undefined after inclusion! 15*6b90bd4bSEmese Revfy * 5. the only exported name is make_PASS_NAME_pass() to register with gcc 16*6b90bd4bSEmese Revfy */ 17*6b90bd4bSEmese Revfy 18*6b90bd4bSEmese Revfy #ifndef PASS_NAME 19*6b90bd4bSEmese Revfy #error at least PASS_NAME must be defined 20*6b90bd4bSEmese Revfy #else 21*6b90bd4bSEmese Revfy #define __GCC_PLUGIN_STRINGIFY(n) #n 22*6b90bd4bSEmese Revfy #define _GCC_PLUGIN_STRINGIFY(n) __GCC_PLUGIN_STRINGIFY(n) 23*6b90bd4bSEmese Revfy #define _GCC_PLUGIN_CONCAT2(x, y) x ## y 24*6b90bd4bSEmese Revfy #define _GCC_PLUGIN_CONCAT3(x, y, z) x ## y ## z 25*6b90bd4bSEmese Revfy 26*6b90bd4bSEmese Revfy #define __PASS_NAME_PASS_DATA(n) _GCC_PLUGIN_CONCAT2(n, _pass_data) 27*6b90bd4bSEmese Revfy #define _PASS_NAME_PASS_DATA __PASS_NAME_PASS_DATA(PASS_NAME) 28*6b90bd4bSEmese Revfy 29*6b90bd4bSEmese Revfy #define __PASS_NAME_PASS(n) _GCC_PLUGIN_CONCAT2(n, _pass) 30*6b90bd4bSEmese Revfy #define _PASS_NAME_PASS __PASS_NAME_PASS(PASS_NAME) 31*6b90bd4bSEmese Revfy 32*6b90bd4bSEmese Revfy #define _PASS_NAME_NAME _GCC_PLUGIN_STRINGIFY(PASS_NAME) 33*6b90bd4bSEmese Revfy 34*6b90bd4bSEmese Revfy #define __MAKE_PASS_NAME_PASS(n) _GCC_PLUGIN_CONCAT3(make_, n, _pass) 35*6b90bd4bSEmese Revfy #define _MAKE_PASS_NAME_PASS __MAKE_PASS_NAME_PASS(PASS_NAME) 36*6b90bd4bSEmese Revfy 37*6b90bd4bSEmese Revfy #ifdef NO_GATE 38*6b90bd4bSEmese Revfy #define _GATE NULL 39*6b90bd4bSEmese Revfy #define _HAS_GATE false 40*6b90bd4bSEmese Revfy #else 41*6b90bd4bSEmese Revfy #define __GATE(n) _GCC_PLUGIN_CONCAT2(n, _gate) 42*6b90bd4bSEmese Revfy #define _GATE __GATE(PASS_NAME) 43*6b90bd4bSEmese Revfy #define _HAS_GATE true 44*6b90bd4bSEmese Revfy #endif 45*6b90bd4bSEmese Revfy 46*6b90bd4bSEmese Revfy #ifdef NO_EXECUTE 47*6b90bd4bSEmese Revfy #define _EXECUTE NULL 48*6b90bd4bSEmese Revfy #define _HAS_EXECUTE false 49*6b90bd4bSEmese Revfy #else 50*6b90bd4bSEmese Revfy #define __EXECUTE(n) _GCC_PLUGIN_CONCAT2(n, _execute) 51*6b90bd4bSEmese Revfy #define _EXECUTE __EXECUTE(PASS_NAME) 52*6b90bd4bSEmese Revfy #define _HAS_EXECUTE true 53*6b90bd4bSEmese Revfy #endif 54*6b90bd4bSEmese Revfy 55*6b90bd4bSEmese Revfy #ifndef PROPERTIES_REQUIRED 56*6b90bd4bSEmese Revfy #define PROPERTIES_REQUIRED 0 57*6b90bd4bSEmese Revfy #endif 58*6b90bd4bSEmese Revfy 59*6b90bd4bSEmese Revfy #ifndef PROPERTIES_PROVIDED 60*6b90bd4bSEmese Revfy #define PROPERTIES_PROVIDED 0 61*6b90bd4bSEmese Revfy #endif 62*6b90bd4bSEmese Revfy 63*6b90bd4bSEmese Revfy #ifndef PROPERTIES_DESTROYED 64*6b90bd4bSEmese Revfy #define PROPERTIES_DESTROYED 0 65*6b90bd4bSEmese Revfy #endif 66*6b90bd4bSEmese Revfy 67*6b90bd4bSEmese Revfy #ifndef TODO_FLAGS_START 68*6b90bd4bSEmese Revfy #define TODO_FLAGS_START 0 69*6b90bd4bSEmese Revfy #endif 70*6b90bd4bSEmese Revfy 71*6b90bd4bSEmese Revfy #ifndef TODO_FLAGS_FINISH 72*6b90bd4bSEmese Revfy #define TODO_FLAGS_FINISH 0 73*6b90bd4bSEmese Revfy #endif 74*6b90bd4bSEmese Revfy 75*6b90bd4bSEmese Revfy #if BUILDING_GCC_VERSION >= 4009 76*6b90bd4bSEmese Revfy namespace { 77*6b90bd4bSEmese Revfy static const pass_data _PASS_NAME_PASS_DATA = { 78*6b90bd4bSEmese Revfy #else 79*6b90bd4bSEmese Revfy static struct simple_ipa_opt_pass _PASS_NAME_PASS = { 80*6b90bd4bSEmese Revfy .pass = { 81*6b90bd4bSEmese Revfy #endif 82*6b90bd4bSEmese Revfy .type = SIMPLE_IPA_PASS, 83*6b90bd4bSEmese Revfy .name = _PASS_NAME_NAME, 84*6b90bd4bSEmese Revfy #if BUILDING_GCC_VERSION >= 4008 85*6b90bd4bSEmese Revfy .optinfo_flags = OPTGROUP_NONE, 86*6b90bd4bSEmese Revfy #endif 87*6b90bd4bSEmese Revfy #if BUILDING_GCC_VERSION >= 5000 88*6b90bd4bSEmese Revfy #elif BUILDING_GCC_VERSION == 4009 89*6b90bd4bSEmese Revfy .has_gate = _HAS_GATE, 90*6b90bd4bSEmese Revfy .has_execute = _HAS_EXECUTE, 91*6b90bd4bSEmese Revfy #else 92*6b90bd4bSEmese Revfy .gate = _GATE, 93*6b90bd4bSEmese Revfy .execute = _EXECUTE, 94*6b90bd4bSEmese Revfy .sub = NULL, 95*6b90bd4bSEmese Revfy .next = NULL, 96*6b90bd4bSEmese Revfy .static_pass_number = 0, 97*6b90bd4bSEmese Revfy #endif 98*6b90bd4bSEmese Revfy .tv_id = TV_NONE, 99*6b90bd4bSEmese Revfy .properties_required = PROPERTIES_REQUIRED, 100*6b90bd4bSEmese Revfy .properties_provided = PROPERTIES_PROVIDED, 101*6b90bd4bSEmese Revfy .properties_destroyed = PROPERTIES_DESTROYED, 102*6b90bd4bSEmese Revfy .todo_flags_start = TODO_FLAGS_START, 103*6b90bd4bSEmese Revfy .todo_flags_finish = TODO_FLAGS_FINISH, 104*6b90bd4bSEmese Revfy #if BUILDING_GCC_VERSION < 4009 105*6b90bd4bSEmese Revfy } 106*6b90bd4bSEmese Revfy #endif 107*6b90bd4bSEmese Revfy }; 108*6b90bd4bSEmese Revfy 109*6b90bd4bSEmese Revfy #if BUILDING_GCC_VERSION >= 4009 110*6b90bd4bSEmese Revfy class _PASS_NAME_PASS : public simple_ipa_opt_pass { 111*6b90bd4bSEmese Revfy public: 112*6b90bd4bSEmese Revfy _PASS_NAME_PASS() : simple_ipa_opt_pass(_PASS_NAME_PASS_DATA, g) {} 113*6b90bd4bSEmese Revfy 114*6b90bd4bSEmese Revfy #ifndef NO_GATE 115*6b90bd4bSEmese Revfy #if BUILDING_GCC_VERSION >= 5000 116*6b90bd4bSEmese Revfy virtual bool gate(function *) { return _GATE(); } 117*6b90bd4bSEmese Revfy #else 118*6b90bd4bSEmese Revfy virtual bool gate(void) { return _GATE(); } 119*6b90bd4bSEmese Revfy #endif 120*6b90bd4bSEmese Revfy #endif 121*6b90bd4bSEmese Revfy 122*6b90bd4bSEmese Revfy virtual opt_pass *clone() { return new _PASS_NAME_PASS(); } 123*6b90bd4bSEmese Revfy 124*6b90bd4bSEmese Revfy #ifndef NO_EXECUTE 125*6b90bd4bSEmese Revfy #if BUILDING_GCC_VERSION >= 5000 126*6b90bd4bSEmese Revfy virtual unsigned int execute(function *) { return _EXECUTE(); } 127*6b90bd4bSEmese Revfy #else 128*6b90bd4bSEmese Revfy virtual unsigned int execute(void) { return _EXECUTE(); } 129*6b90bd4bSEmese Revfy #endif 130*6b90bd4bSEmese Revfy #endif 131*6b90bd4bSEmese Revfy }; 132*6b90bd4bSEmese Revfy } 133*6b90bd4bSEmese Revfy 134*6b90bd4bSEmese Revfy opt_pass *_MAKE_PASS_NAME_PASS(void) 135*6b90bd4bSEmese Revfy { 136*6b90bd4bSEmese Revfy return new _PASS_NAME_PASS(); 137*6b90bd4bSEmese Revfy } 138*6b90bd4bSEmese Revfy #else 139*6b90bd4bSEmese Revfy struct opt_pass *_MAKE_PASS_NAME_PASS(void) 140*6b90bd4bSEmese Revfy { 141*6b90bd4bSEmese Revfy return &_PASS_NAME_PASS.pass; 142*6b90bd4bSEmese Revfy } 143*6b90bd4bSEmese Revfy #endif 144*6b90bd4bSEmese Revfy 145*6b90bd4bSEmese Revfy /* clean up user provided defines */ 146*6b90bd4bSEmese Revfy #undef PASS_NAME 147*6b90bd4bSEmese Revfy #undef NO_GATE 148*6b90bd4bSEmese Revfy #undef NO_EXECUTE 149*6b90bd4bSEmese Revfy 150*6b90bd4bSEmese Revfy #undef PROPERTIES_DESTROYED 151*6b90bd4bSEmese Revfy #undef PROPERTIES_PROVIDED 152*6b90bd4bSEmese Revfy #undef PROPERTIES_REQUIRED 153*6b90bd4bSEmese Revfy #undef TODO_FLAGS_FINISH 154*6b90bd4bSEmese Revfy #undef TODO_FLAGS_START 155*6b90bd4bSEmese Revfy 156*6b90bd4bSEmese Revfy /* clean up generated defines */ 157*6b90bd4bSEmese Revfy #undef _EXECUTE 158*6b90bd4bSEmese Revfy #undef __EXECUTE 159*6b90bd4bSEmese Revfy #undef _GATE 160*6b90bd4bSEmese Revfy #undef __GATE 161*6b90bd4bSEmese Revfy #undef _GCC_PLUGIN_CONCAT2 162*6b90bd4bSEmese Revfy #undef _GCC_PLUGIN_CONCAT3 163*6b90bd4bSEmese Revfy #undef _GCC_PLUGIN_STRINGIFY 164*6b90bd4bSEmese Revfy #undef __GCC_PLUGIN_STRINGIFY 165*6b90bd4bSEmese Revfy #undef _HAS_EXECUTE 166*6b90bd4bSEmese Revfy #undef _HAS_GATE 167*6b90bd4bSEmese Revfy #undef _MAKE_PASS_NAME_PASS 168*6b90bd4bSEmese Revfy #undef __MAKE_PASS_NAME_PASS 169*6b90bd4bSEmese Revfy #undef _PASS_NAME_NAME 170*6b90bd4bSEmese Revfy #undef _PASS_NAME_PASS 171*6b90bd4bSEmese Revfy #undef __PASS_NAME_PASS 172*6b90bd4bSEmese Revfy #undef _PASS_NAME_PASS_DATA 173*6b90bd4bSEmese Revfy #undef __PASS_NAME_PASS_DATA 174*6b90bd4bSEmese Revfy 175*6b90bd4bSEmese Revfy #endif /* PASS_NAME */ 176