gcc-generate-rtl-pass.h 4.0 KB

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