gcc-generate-ipa-pass.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Generator for IPA 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_GENERATE_SUMMARY
  12. * NO_READ_SUMMARY
  13. * NO_WRITE_SUMMARY
  14. * NO_READ_OPTIMIZATION_SUMMARY
  15. * NO_WRITE_OPTIMIZATION_SUMMARY
  16. * NO_STMT_FIXUP
  17. * NO_FUNCTION_TRANSFORM
  18. * NO_VARIABLE_TRANSFORM
  19. * NO_GATE
  20. * NO_EXECUTE
  21. * 3. before inclusion define PROPERTIES_* and *TODO_FLAGS_* to override
  22. * the default 0 values
  23. * 4. for convenience, all the above will be undefined after inclusion!
  24. * 5. the only exported name is make_PASS_NAME_pass() to register with gcc
  25. */
  26. #ifndef PASS_NAME
  27. #error at least PASS_NAME must be defined
  28. #else
  29. #define __GCC_PLUGIN_STRINGIFY(n) #n
  30. #define _GCC_PLUGIN_STRINGIFY(n) __GCC_PLUGIN_STRINGIFY(n)
  31. #define _GCC_PLUGIN_CONCAT2(x, y) x ## y
  32. #define _GCC_PLUGIN_CONCAT3(x, y, z) x ## y ## z
  33. #define __PASS_NAME_PASS_DATA(n) _GCC_PLUGIN_CONCAT2(n, _pass_data)
  34. #define _PASS_NAME_PASS_DATA __PASS_NAME_PASS_DATA(PASS_NAME)
  35. #define __PASS_NAME_PASS(n) _GCC_PLUGIN_CONCAT2(n, _pass)
  36. #define _PASS_NAME_PASS __PASS_NAME_PASS(PASS_NAME)
  37. #define _PASS_NAME_NAME _GCC_PLUGIN_STRINGIFY(PASS_NAME)
  38. #define __MAKE_PASS_NAME_PASS(n) _GCC_PLUGIN_CONCAT3(make_, n, _pass)
  39. #define _MAKE_PASS_NAME_PASS __MAKE_PASS_NAME_PASS(PASS_NAME)
  40. #ifdef NO_GENERATE_SUMMARY
  41. #define _GENERATE_SUMMARY NULL
  42. #else
  43. #define __GENERATE_SUMMARY(n) _GCC_PLUGIN_CONCAT2(n, _generate_summary)
  44. #define _GENERATE_SUMMARY __GENERATE_SUMMARY(PASS_NAME)
  45. #endif
  46. #ifdef NO_READ_SUMMARY
  47. #define _READ_SUMMARY NULL
  48. #else
  49. #define __READ_SUMMARY(n) _GCC_PLUGIN_CONCAT2(n, _read_summary)
  50. #define _READ_SUMMARY __READ_SUMMARY(PASS_NAME)
  51. #endif
  52. #ifdef NO_WRITE_SUMMARY
  53. #define _WRITE_SUMMARY NULL
  54. #else
  55. #define __WRITE_SUMMARY(n) _GCC_PLUGIN_CONCAT2(n, _write_summary)
  56. #define _WRITE_SUMMARY __WRITE_SUMMARY(PASS_NAME)
  57. #endif
  58. #ifdef NO_READ_OPTIMIZATION_SUMMARY
  59. #define _READ_OPTIMIZATION_SUMMARY NULL
  60. #else
  61. #define __READ_OPTIMIZATION_SUMMARY(n) _GCC_PLUGIN_CONCAT2(n, _read_optimization_summary)
  62. #define _READ_OPTIMIZATION_SUMMARY __READ_OPTIMIZATION_SUMMARY(PASS_NAME)
  63. #endif
  64. #ifdef NO_WRITE_OPTIMIZATION_SUMMARY
  65. #define _WRITE_OPTIMIZATION_SUMMARY NULL
  66. #else
  67. #define __WRITE_OPTIMIZATION_SUMMARY(n) _GCC_PLUGIN_CONCAT2(n, _write_optimization_summary)
  68. #define _WRITE_OPTIMIZATION_SUMMARY __WRITE_OPTIMIZATION_SUMMARY(PASS_NAME)
  69. #endif
  70. #ifdef NO_STMT_FIXUP
  71. #define _STMT_FIXUP NULL
  72. #else
  73. #define __STMT_FIXUP(n) _GCC_PLUGIN_CONCAT2(n, _stmt_fixup)
  74. #define _STMT_FIXUP __STMT_FIXUP(PASS_NAME)
  75. #endif
  76. #ifdef NO_FUNCTION_TRANSFORM
  77. #define _FUNCTION_TRANSFORM NULL
  78. #else
  79. #define __FUNCTION_TRANSFORM(n) _GCC_PLUGIN_CONCAT2(n, _function_transform)
  80. #define _FUNCTION_TRANSFORM __FUNCTION_TRANSFORM(PASS_NAME)
  81. #endif
  82. #ifdef NO_VARIABLE_TRANSFORM
  83. #define _VARIABLE_TRANSFORM NULL
  84. #else
  85. #define __VARIABLE_TRANSFORM(n) _GCC_PLUGIN_CONCAT2(n, _variable_transform)
  86. #define _VARIABLE_TRANSFORM __VARIABLE_TRANSFORM(PASS_NAME)
  87. #endif
  88. #ifdef NO_GATE
  89. #define _GATE NULL
  90. #define _HAS_GATE false
  91. #else
  92. #define __GATE(n) _GCC_PLUGIN_CONCAT2(n, _gate)
  93. #define _GATE __GATE(PASS_NAME)
  94. #define _HAS_GATE true
  95. #endif
  96. #ifdef NO_EXECUTE
  97. #define _EXECUTE NULL
  98. #define _HAS_EXECUTE false
  99. #else
  100. #define __EXECUTE(n) _GCC_PLUGIN_CONCAT2(n, _execute)
  101. #define _EXECUTE __EXECUTE(PASS_NAME)
  102. #define _HAS_EXECUTE true
  103. #endif
  104. #ifndef PROPERTIES_REQUIRED
  105. #define PROPERTIES_REQUIRED 0
  106. #endif
  107. #ifndef PROPERTIES_PROVIDED
  108. #define PROPERTIES_PROVIDED 0
  109. #endif
  110. #ifndef PROPERTIES_DESTROYED
  111. #define PROPERTIES_DESTROYED 0
  112. #endif
  113. #ifndef TODO_FLAGS_START
  114. #define TODO_FLAGS_START 0
  115. #endif
  116. #ifndef TODO_FLAGS_FINISH
  117. #define TODO_FLAGS_FINISH 0
  118. #endif
  119. #ifndef FUNCTION_TRANSFORM_TODO_FLAGS_START
  120. #define FUNCTION_TRANSFORM_TODO_FLAGS_START 0
  121. #endif
  122. #if BUILDING_GCC_VERSION >= 4009
  123. namespace {
  124. static const pass_data _PASS_NAME_PASS_DATA = {
  125. #else
  126. static struct ipa_opt_pass_d _PASS_NAME_PASS = {
  127. .pass = {
  128. #endif
  129. .type = IPA_PASS,
  130. .name = _PASS_NAME_NAME,
  131. #if BUILDING_GCC_VERSION >= 4008
  132. .optinfo_flags = OPTGROUP_NONE,
  133. #endif
  134. #if BUILDING_GCC_VERSION >= 5000
  135. #elif BUILDING_GCC_VERSION == 4009
  136. .has_gate = _HAS_GATE,
  137. .has_execute = _HAS_EXECUTE,
  138. #else
  139. .gate = _GATE,
  140. .execute = _EXECUTE,
  141. .sub = NULL,
  142. .next = NULL,
  143. .static_pass_number = 0,
  144. #endif
  145. .tv_id = TV_NONE,
  146. .properties_required = PROPERTIES_REQUIRED,
  147. .properties_provided = PROPERTIES_PROVIDED,
  148. .properties_destroyed = PROPERTIES_DESTROYED,
  149. .todo_flags_start = TODO_FLAGS_START,
  150. .todo_flags_finish = TODO_FLAGS_FINISH,
  151. #if BUILDING_GCC_VERSION < 4009
  152. },
  153. .generate_summary = _GENERATE_SUMMARY,
  154. .write_summary = _WRITE_SUMMARY,
  155. .read_summary = _READ_SUMMARY,
  156. #if BUILDING_GCC_VERSION >= 4006
  157. .write_optimization_summary = _WRITE_OPTIMIZATION_SUMMARY,
  158. .read_optimization_summary = _READ_OPTIMIZATION_SUMMARY,
  159. #endif
  160. .stmt_fixup = _STMT_FIXUP,
  161. .function_transform_todo_flags_start = FUNCTION_TRANSFORM_TODO_FLAGS_START,
  162. .function_transform = _FUNCTION_TRANSFORM,
  163. .variable_transform = _VARIABLE_TRANSFORM,
  164. #endif
  165. };
  166. #if BUILDING_GCC_VERSION >= 4009
  167. class _PASS_NAME_PASS : public ipa_opt_pass_d {
  168. public:
  169. _PASS_NAME_PASS() : ipa_opt_pass_d(_PASS_NAME_PASS_DATA,
  170. g,
  171. _GENERATE_SUMMARY,
  172. _WRITE_SUMMARY,
  173. _READ_SUMMARY,
  174. _WRITE_OPTIMIZATION_SUMMARY,
  175. _READ_OPTIMIZATION_SUMMARY,
  176. _STMT_FIXUP,
  177. FUNCTION_TRANSFORM_TODO_FLAGS_START,
  178. _FUNCTION_TRANSFORM,
  179. _VARIABLE_TRANSFORM) {}
  180. #ifndef NO_GATE
  181. #if BUILDING_GCC_VERSION >= 5000
  182. virtual bool gate(function *) { return _GATE(); }
  183. #else
  184. virtual bool gate(void) { return _GATE(); }
  185. #endif
  186. #endif
  187. virtual opt_pass *clone() { return new _PASS_NAME_PASS(); }
  188. #ifndef NO_EXECUTE
  189. #if BUILDING_GCC_VERSION >= 5000
  190. virtual unsigned int execute(function *) { return _EXECUTE(); }
  191. #else
  192. virtual unsigned int execute(void) { return _EXECUTE(); }
  193. #endif
  194. #endif
  195. };
  196. }
  197. opt_pass *_MAKE_PASS_NAME_PASS(void)
  198. {
  199. return new _PASS_NAME_PASS();
  200. }
  201. #else
  202. struct opt_pass *_MAKE_PASS_NAME_PASS(void)
  203. {
  204. return &_PASS_NAME_PASS.pass;
  205. }
  206. #endif
  207. /* clean up user provided defines */
  208. #undef PASS_NAME
  209. #undef NO_GENERATE_SUMMARY
  210. #undef NO_WRITE_SUMMARY
  211. #undef NO_READ_SUMMARY
  212. #undef NO_WRITE_OPTIMIZATION_SUMMARY
  213. #undef NO_READ_OPTIMIZATION_SUMMARY
  214. #undef NO_STMT_FIXUP
  215. #undef NO_FUNCTION_TRANSFORM
  216. #undef NO_VARIABLE_TRANSFORM
  217. #undef NO_GATE
  218. #undef NO_EXECUTE
  219. #undef FUNCTION_TRANSFORM_TODO_FLAGS_START
  220. #undef PROPERTIES_DESTROYED
  221. #undef PROPERTIES_PROVIDED
  222. #undef PROPERTIES_REQUIRED
  223. #undef TODO_FLAGS_FINISH
  224. #undef TODO_FLAGS_START
  225. /* clean up generated defines */
  226. #undef _EXECUTE
  227. #undef __EXECUTE
  228. #undef _FUNCTION_TRANSFORM
  229. #undef __FUNCTION_TRANSFORM
  230. #undef _GATE
  231. #undef __GATE
  232. #undef _GCC_PLUGIN_CONCAT2
  233. #undef _GCC_PLUGIN_CONCAT3
  234. #undef _GCC_PLUGIN_STRINGIFY
  235. #undef __GCC_PLUGIN_STRINGIFY
  236. #undef _GENERATE_SUMMARY
  237. #undef __GENERATE_SUMMARY
  238. #undef _HAS_EXECUTE
  239. #undef _HAS_GATE
  240. #undef _MAKE_PASS_NAME_PASS
  241. #undef __MAKE_PASS_NAME_PASS
  242. #undef _PASS_NAME_NAME
  243. #undef _PASS_NAME_PASS
  244. #undef __PASS_NAME_PASS
  245. #undef _PASS_NAME_PASS_DATA
  246. #undef __PASS_NAME_PASS_DATA
  247. #undef _READ_OPTIMIZATION_SUMMARY
  248. #undef __READ_OPTIMIZATION_SUMMARY
  249. #undef _READ_SUMMARY
  250. #undef __READ_SUMMARY
  251. #undef _STMT_FIXUP
  252. #undef __STMT_FIXUP
  253. #undef _VARIABLE_TRANSFORM
  254. #undef __VARIABLE_TRANSFORM
  255. #undef _WRITE_OPTIMIZATION_SUMMARY
  256. #undef __WRITE_OPTIMIZATION_SUMMARY
  257. #undef _WRITE_SUMMARY
  258. #undef __WRITE_SUMMARY
  259. #endif /* PASS_NAME */