gcc-generate-ipa-pass.h 7.3 KB

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