gcc-generate-gimple-pass.h 4.1 KB

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