jit-builtins.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /* jit-builtins.h -- Handling of builtin functions during JIT-compilation.
  2. Copyright (C) 2014-2015 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free
  6. Software Foundation; either version 3, or (at your option) any later
  7. version.
  8. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GCC; see the file COPYING3. If not see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef JIT_BUILTINS_H
  16. #define JIT_BUILTINS_H
  17. #include "jit-common.h"
  18. namespace gcc {
  19. namespace jit {
  20. /* Create an enum of the builtin types. */
  21. enum jit_builtin_type
  22. {
  23. #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
  24. #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
  25. #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
  26. #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
  27. #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
  28. #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
  29. #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME,
  30. #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
  31. ARG6) NAME,
  32. #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
  33. ARG6, ARG7) NAME,
  34. #define DEF_FUNCTION_TYPE_8(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
  35. ARG6, ARG7, ARG8) NAME,
  36. #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
  37. #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
  38. #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
  39. #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
  40. #define DEF_FUNCTION_TYPE_VAR_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
  41. #define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
  42. NAME,
  43. #define DEF_FUNCTION_TYPE_VAR_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
  44. ARG6, ARG7) NAME,
  45. #define DEF_FUNCTION_TYPE_VAR_11(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
  46. ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) NAME,
  47. #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
  48. #include "builtin-types.def"
  49. #undef DEF_PRIMITIVE_TYPE
  50. #undef DEF_FUNCTION_TYPE_0
  51. #undef DEF_FUNCTION_TYPE_1
  52. #undef DEF_FUNCTION_TYPE_2
  53. #undef DEF_FUNCTION_TYPE_3
  54. #undef DEF_FUNCTION_TYPE_4
  55. #undef DEF_FUNCTION_TYPE_5
  56. #undef DEF_FUNCTION_TYPE_6
  57. #undef DEF_FUNCTION_TYPE_7
  58. #undef DEF_FUNCTION_TYPE_8
  59. #undef DEF_FUNCTION_TYPE_VAR_0
  60. #undef DEF_FUNCTION_TYPE_VAR_1
  61. #undef DEF_FUNCTION_TYPE_VAR_2
  62. #undef DEF_FUNCTION_TYPE_VAR_3
  63. #undef DEF_FUNCTION_TYPE_VAR_4
  64. #undef DEF_FUNCTION_TYPE_VAR_5
  65. #undef DEF_FUNCTION_TYPE_VAR_7
  66. #undef DEF_FUNCTION_TYPE_VAR_11
  67. #undef DEF_POINTER_TYPE
  68. BT_LAST
  69. }; /* enum jit_builtin_type */
  70. /* Create an enum of the attributes that can be present on builtins. */
  71. enum built_in_attribute
  72. {
  73. #define DEF_ATTR_NULL_TREE(ENUM) ENUM,
  74. #define DEF_ATTR_INT(ENUM, VALUE) ENUM,
  75. #define DEF_ATTR_STRING(ENUM, VALUE) ENUM,
  76. #define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
  77. #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
  78. #include "builtin-attrs.def"
  79. #undef DEF_ATTR_NULL_TREE
  80. #undef DEF_ATTR_INT
  81. #undef DEF_ATTR_STRING
  82. #undef DEF_ATTR_IDENT
  83. #undef DEF_ATTR_TREE_LIST
  84. ATTR_LAST
  85. };
  86. /***********************************************************************/
  87. class builtins_manager
  88. {
  89. public:
  90. builtins_manager (recording::context *ctxt);
  91. recording::function *
  92. get_builtin_function (const char *name);
  93. static enum built_in_class
  94. get_class (enum built_in_function builtin_id);
  95. static bool
  96. implicit_p (enum built_in_function builtin_id);
  97. tree
  98. get_attrs_tree (enum built_in_function builtin_id);
  99. tree
  100. get_attrs_tree (enum built_in_attribute attr);
  101. void
  102. finish_playback (void);
  103. private:
  104. recording::function *
  105. get_builtin_function_by_id (enum built_in_function builtin_id);
  106. recording::function *
  107. make_builtin_function (enum built_in_function builtin_id);
  108. recording::type *
  109. get_type (enum jit_builtin_type type_id);
  110. recording::type *
  111. make_type (enum jit_builtin_type type_id);
  112. recording::type*
  113. make_primitive_type (enum jit_builtin_type type_id);
  114. recording::function_type*
  115. make_fn_type (enum jit_builtin_type type_id,
  116. enum jit_builtin_type return_type_id,
  117. bool is_variadic,
  118. int num_args, ...);
  119. recording::type*
  120. make_ptr_type (enum jit_builtin_type type_id,
  121. enum jit_builtin_type other_type_id);
  122. tree
  123. make_attrs_tree (enum built_in_attribute attr);
  124. private:
  125. /* Recording fields. */
  126. recording::context *m_ctxt;
  127. recording::type *m_types[BT_LAST];
  128. recording::function *m_builtin_functions[END_BUILTINS];
  129. /* Playback fields. */
  130. /* m_attributes is not GTY-marked, but is only ever used from within
  131. the region of playback::context::replay () in which a GC can't
  132. happen. */
  133. tree m_attributes[ATTR_LAST];
  134. };
  135. } // namespace jit
  136. } // namespace gcc
  137. #endif /* JIT_BUILTINS_H */