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