1 /* jit-builtins.c -- Handling of builtin functions during JIT-compilation.
2 Copyright (C) 2014-2020 Free Software Foundation, Inc.
4 This file is part of GCC.
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
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
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/>. */
22 #include "coretypes.h"
24 #include "jit-playback.h"
25 #include "stringpool.h"
27 #include "jit-builtins.h"
33 const char *const prefix
= "__builtin_";
34 const size_t prefix_len
= strlen (prefix
);
36 /* Create "builtin_data", a const table of the data within builtins.def. */
40 enum built_in_class fnclass
;
41 enum jit_builtin_type type
;
44 enum built_in_attribute attr
;
47 const char *get_asm_name () const
49 if (both_p
&& fallback_p
)
50 return name
+ prefix_len
;
56 #define DEF_BUILTIN(X, NAME, CLASS, TYPE, LT, BOTH_P, FALLBACK_P, \
57 NONANSI_P, ATTRS, IMPLICIT, COND) \
58 {NAME, CLASS, TYPE, BOTH_P, FALLBACK_P, ATTRS, IMPLICIT},
59 static const struct builtin_data builtin_data
[] =
61 #include "builtins.def"
64 /* Helper function for find_builtin_by_name. */
67 matches_builtin (const char *in_name
,
68 const struct builtin_data
& bd
)
72 /* Ignore entries with a NULL name. */
77 fprintf (stderr
, "seen builtin: %s\n", bd
.name
);
79 if (strcmp (bd
.name
, in_name
) == 0)
84 /* Then the macros in builtins.def gave a "__builtin_"
85 prefix to bd.name, but we should also recognize the form
86 without the prefix. */
87 gcc_assert (strncmp (bd
.name
, prefix
, prefix_len
) == 0);
89 fprintf (stderr
, "testing without prefix as: %s\n",
90 bd
.name
+ prefix_len
);
91 if (strcmp (bd
.name
+ prefix_len
, in_name
) == 0)
98 /* Locate the built-in function that matches name IN_NAME,
99 writing the result to OUT_ID and returning true if found,
100 or returning false if not found. */
103 find_builtin_by_name (const char *in_name
,
104 enum built_in_function
*out_id
)
106 /* Locate builtin. This currently works by performing repeated
107 strcmp against every possible candidate, which is likely to
110 We start at index 1 to skip the initial entry (BUILT_IN_NONE), which
112 for (unsigned int i
= 1;
113 i
< sizeof (builtin_data
) / sizeof (builtin_data
[0]);
116 const struct builtin_data
& bd
= builtin_data
[i
];
117 if (matches_builtin (in_name
, bd
))
120 *out_id
= static_cast<enum built_in_function
> (i
);
129 // class builtins_manager
131 /* Constructor for gcc::jit::builtins_manager. */
133 builtins_manager::builtins_manager (recording::context
*ctxt
)
136 memset (m_types
, 0, sizeof (m_types
));
137 memset (m_builtin_functions
, 0, sizeof (m_builtin_functions
));
138 memset (m_attributes
, 0, sizeof (m_attributes
));
141 /* Locate a builtin function by name.
142 Create a recording::function of the appropriate type, reusing them
143 if they've already been seen. */
145 recording::function
*
146 builtins_manager::get_builtin_function (const char *name
)
148 enum built_in_function builtin_id
;
149 if (!find_builtin_by_name (name
, &builtin_id
))
151 m_ctxt
->add_error (NULL
, "builtin \"%s\" not found", name
);
155 return get_builtin_function_by_id (builtin_id
);
158 /* Locate a builtin function by id.
159 Create a recording::function of the appropriate type, reusing them
160 if they've already been seen. */
162 recording::function
*
163 builtins_manager::get_builtin_function_by_id (enum built_in_function builtin_id
)
165 gcc_assert (builtin_id
>= 0);
166 gcc_assert (builtin_id
< END_BUILTINS
);
168 /* Lazily build the functions, caching them so that repeated calls for
169 the same id on a context give back the same object. */
170 if (!m_builtin_functions
[builtin_id
])
172 recording::function
*fn
= make_builtin_function (builtin_id
);
175 m_builtin_functions
[builtin_id
] = fn
;
180 return m_builtin_functions
[builtin_id
];
183 /* Create the recording::function for a given builtin function, by ID. */
185 recording::function
*
186 builtins_manager::make_builtin_function (enum built_in_function builtin_id
)
188 const struct builtin_data
& bd
= builtin_data
[builtin_id
];
189 enum jit_builtin_type type_id
= bd
.type
;
190 recording::type
*t
= get_type (type_id
);
193 recording::function_type
*func_type
= t
->as_a_function_type ();
197 vec
<recording::type
*> param_types
= func_type
->get_param_types ();
198 recording::param
**params
= new recording::param
*[param_types
.length ()];
201 recording::type
*param_type
;
202 FOR_EACH_VEC_ELT (param_types
, i
, param_type
)
205 snprintf (buf
, 16, "arg%d", i
);
206 params
[i
] = m_ctxt
->new_param (NULL
,
210 const char *asm_name
= bd
.get_asm_name ();
211 recording::function
*result
=
212 new recording::function (m_ctxt
,
214 GCC_JIT_FUNCTION_IMPORTED
, // FIXME
215 func_type
->get_return_type (),
216 m_ctxt
->new_string (asm_name
),
217 param_types
.length (),
219 func_type
->is_variadic (),
223 /* PR/64020 - If the client code is using builtin cos or sin,
224 tree-ssa-math-opt.c's execute_cse_sincos_1 may attempt
225 to optimize them to use __builtin_cexpi; for this,
226 BUILT_IN_CEXPI needs to exist.
228 Hence query the cache for BUILT_IN_CEXPI to ensure it gets
230 if (builtin_id
== BUILT_IN_COS
|| builtin_id
== BUILT_IN_SIN
)
231 (void)get_builtin_function_by_id (BUILT_IN_CEXPI
);
233 /* builtins.c:expand_builtin_cexpi can optimize the various
234 CEXP builtins to SINCOS builtins, and hence we may require
235 SINCOS builtins latter.
237 Ensure the appropriate SINCOS builtin exists. */
238 if (builtin_id
== BUILT_IN_CEXPIF
)
239 (void)get_builtin_function_by_id (BUILT_IN_SINCOSF
);
240 else if (builtin_id
== BUILT_IN_CEXPI
)
241 (void)get_builtin_function_by_id (BUILT_IN_SINCOS
);
242 else if (builtin_id
== BUILT_IN_CEXPIL
)
243 (void)get_builtin_function_by_id (BUILT_IN_SINCOSL
);
248 /* Build an array of type names for use by get_string_for_type_id. */
250 static const char * const type_names
[] = {
251 #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) #ENUM,
252 #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) #ENUM,
253 #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) #ENUM,
254 #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) #ENUM,
255 #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) #ENUM,
256 #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) #ENUM,
257 #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) #ENUM,
258 #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
261 #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
264 #define DEF_FUNCTION_TYPE_8(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
267 #define DEF_FUNCTION_TYPE_9(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
268 ARG6, ARG7, ARG8, ARG9) \
270 #define DEF_FUNCTION_TYPE_10(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
271 ARG6, ARG7, ARG8, ARG9, ARG10) \
273 #define DEF_FUNCTION_TYPE_11(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
274 ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) \
276 #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) #ENUM,
277 #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) #ENUM,
278 #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) #ENUM,
279 #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) #ENUM,
280 #define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) #ENUM,
281 #define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
283 #define DEF_FUNCTION_TYPE_VAR_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
286 #define DEF_FUNCTION_TYPE_VAR_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
289 #define DEF_POINTER_TYPE(ENUM, TYPE) #ENUM,
291 #include "builtin-types.def"
293 #undef DEF_PRIMITIVE_TYPE
294 #undef DEF_FUNCTION_TYPE_0
295 #undef DEF_FUNCTION_TYPE_1
296 #undef DEF_FUNCTION_TYPE_2
297 #undef DEF_FUNCTION_TYPE_3
298 #undef DEF_FUNCTION_TYPE_4
299 #undef DEF_FUNCTION_TYPE_5
300 #undef DEF_FUNCTION_TYPE_6
301 #undef DEF_FUNCTION_TYPE_7
302 #undef DEF_FUNCTION_TYPE_8
303 #undef DEF_FUNCTION_TYPE_9
304 #undef DEF_FUNCTION_TYPE_10
305 #undef DEF_FUNCTION_TYPE_11
306 #undef DEF_FUNCTION_TYPE_VAR_0
307 #undef DEF_FUNCTION_TYPE_VAR_1
308 #undef DEF_FUNCTION_TYPE_VAR_2
309 #undef DEF_FUNCTION_TYPE_VAR_3
310 #undef DEF_FUNCTION_TYPE_VAR_4
311 #undef DEF_FUNCTION_TYPE_VAR_5
312 #undef DEF_FUNCTION_TYPE_VAR_6
313 #undef DEF_FUNCTION_TYPE_VAR_7
314 #undef DEF_POINTER_TYPE
317 /* Get a string for TYPE_ID suitable for use in logs and error messages
321 get_string_for_type_id (enum jit_builtin_type type_id
)
323 gcc_assert (type_id
< sizeof (type_names
)/sizeof(type_names
[0]));
324 return type_names
[type_id
];
327 /* Get the recording::type for a given type of builtin function,
328 by ID, creating it if it doesn't already exist. */
331 builtins_manager::get_type (enum jit_builtin_type type_id
)
333 if (!m_types
[type_id
])
334 m_types
[type_id
] = make_type (type_id
);
335 return m_types
[type_id
];
338 /* Create the recording::type for a given type of builtin function. */
341 builtins_manager::make_type (enum jit_builtin_type type_id
)
343 /* Use builtin-types.def to construct a switch statement, with each
344 case deferring to one of the methods below:
345 - DEF_PRIMITIVE_TYPE is handled as a call to make_primitive_type.
346 - the various DEF_FUNCTION_TYPE_n are handled by variadic calls
348 - similarly for DEF_FUNCTION_TYPE_VAR_n, but setting the
349 "is_variadic" argument.
350 - DEF_POINTER_TYPE is handled by make_ptr_type.
351 That should handle everything, but just in case we also suppy a
352 gcc_unreachable default clause. */
355 #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
356 case ENUM: return make_primitive_type (ENUM);
357 #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
358 case ENUM: return make_fn_type (ENUM, RETURN, 0, 0);
359 #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
360 case ENUM: return make_fn_type (ENUM, RETURN, 0, 1, ARG1);
361 #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
362 case ENUM: return make_fn_type (ENUM, RETURN, 0, 2, ARG1, ARG2);
363 #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
364 case ENUM: return make_fn_type (ENUM, RETURN, 0, 3, ARG1, ARG2, ARG3);
365 #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
366 case ENUM: return make_fn_type (ENUM, RETURN, 0, 4, ARG1, ARG2, ARG3, \
368 #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
369 case ENUM: return make_fn_type (ENUM, RETURN, 0, 5, ARG1, ARG2, ARG3, \
371 #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
373 case ENUM: return make_fn_type (ENUM, RETURN, 0, 6, ARG1, ARG2, ARG3, \
375 #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
377 case ENUM: return make_fn_type (ENUM, RETURN, 0, 7, ARG1, ARG2, ARG3, \
378 ARG4, ARG5, ARG6, ARG7);
379 #define DEF_FUNCTION_TYPE_8(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
381 case ENUM: return make_fn_type (ENUM, RETURN, 0, 8, ARG1, ARG2, ARG3, \
382 ARG4, ARG5, ARG6, ARG7, ARG8);
383 #define DEF_FUNCTION_TYPE_9(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
384 ARG6, ARG7, ARG8, ARG9) \
385 case ENUM: return make_fn_type (ENUM, RETURN, 0, 9, ARG1, ARG2, ARG3, \
386 ARG4, ARG5, ARG6, ARG7, ARG8, ARG9);
387 #define DEF_FUNCTION_TYPE_10(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
388 ARG6, ARG7, ARG8, ARG9, ARG10) \
389 case ENUM: return make_fn_type (ENUM, RETURN, 0, 10, ARG1, ARG2, ARG3, \
390 ARG4, ARG5, ARG6, ARG7, ARG8, ARG9, \
392 #define DEF_FUNCTION_TYPE_11(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
393 ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) \
394 case ENUM: return make_fn_type (ENUM, RETURN, 0, 11, ARG1, ARG2, ARG3, \
395 ARG4, ARG5, ARG6, ARG7, ARG8, ARG9, \
397 #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
398 case ENUM: return make_fn_type (ENUM, RETURN, 1, 0);
399 #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
400 case ENUM: return make_fn_type (ENUM, RETURN, 1, 1, ARG1);
401 #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
402 case ENUM: return make_fn_type (ENUM, RETURN, 1, 2, ARG1, ARG2);
403 #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
404 case ENUM: return make_fn_type (ENUM, RETURN, 1, 3, ARG1, ARG2, ARG3);
405 #define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
406 case ENUM: return make_fn_type (ENUM, RETURN, 1, 4, ARG1, ARG2, ARG3, \
408 #define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
409 case ENUM: return make_fn_type (ENUM, RETURN, 1, 5, ARG1, ARG2, ARG3, \
411 #define DEF_FUNCTION_TYPE_VAR_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
413 case ENUM: return make_fn_type (ENUM, RETURN, 1, 6, ARG1, ARG2, ARG3, \
415 #define DEF_FUNCTION_TYPE_VAR_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
417 case ENUM: return make_fn_type (ENUM, RETURN, 1, 7, ARG1, ARG2, ARG3, \
418 ARG4, ARG5, ARG6, ARG7);
419 #define DEF_POINTER_TYPE(ENUM, TYPE) \
420 case ENUM: return make_ptr_type (ENUM, TYPE);
422 #include "builtin-types.def"
424 #undef DEF_PRIMITIVE_TYPE
425 #undef DEF_FUNCTION_TYPE_0
426 #undef DEF_FUNCTION_TYPE_1
427 #undef DEF_FUNCTION_TYPE_2
428 #undef DEF_FUNCTION_TYPE_3
429 #undef DEF_FUNCTION_TYPE_4
430 #undef DEF_FUNCTION_TYPE_5
431 #undef DEF_FUNCTION_TYPE_6
432 #undef DEF_FUNCTION_TYPE_7
433 #undef DEF_FUNCTION_TYPE_8
434 #undef DEF_FUNCTION_TYPE_9
435 #undef DEF_FUNCTION_TYPE_10
436 #undef DEF_FUNCTION_TYPE_11
437 #undef DEF_FUNCTION_TYPE_VAR_0
438 #undef DEF_FUNCTION_TYPE_VAR_1
439 #undef DEF_FUNCTION_TYPE_VAR_2
440 #undef DEF_FUNCTION_TYPE_VAR_3
441 #undef DEF_FUNCTION_TYPE_VAR_4
442 #undef DEF_FUNCTION_TYPE_VAR_5
443 #undef DEF_FUNCTION_TYPE_VAR_6
444 #undef DEF_FUNCTION_TYPE_VAR_7
445 #undef DEF_POINTER_TYPE
452 /* Create the recording::type for a given primitive type within the
455 Only some types are currently supported. */
458 builtins_manager::make_primitive_type (enum jit_builtin_type type_id
)
463 // only some of these types are implemented so far:
464 m_ctxt
->add_error (NULL
,
465 "unimplemented primitive type for builtin (type: %s)",
466 get_string_for_type_id (type_id
));
469 case BT_VOID
: return m_ctxt
->get_type (GCC_JIT_TYPE_VOID
);
470 case BT_BOOL
: return m_ctxt
->get_type (GCC_JIT_TYPE_BOOL
);
471 case BT_INT
: return m_ctxt
->get_type (GCC_JIT_TYPE_INT
);
472 case BT_UINT
: return m_ctxt
->get_type (GCC_JIT_TYPE_UNSIGNED_INT
);
473 case BT_LONG
: return m_ctxt
->get_type (GCC_JIT_TYPE_LONG
);
474 case BT_ULONG
: return m_ctxt
->get_type (GCC_JIT_TYPE_UNSIGNED_LONG
);
475 case BT_LONGLONG
: return m_ctxt
->get_type (GCC_JIT_TYPE_LONG_LONG
);
477 return m_ctxt
->get_type (GCC_JIT_TYPE_UNSIGNED_LONG_LONG
);
480 case BT_INT8
: return m_ctxt
->get_int_type (1, true);
481 case BT_INT16
: return m_ctxt
->get_int_type (2, true);
482 case BT_UINT8
: return m_ctxt
->get_int_type (1, false);
483 case BT_UINT16
: return m_ctxt
->get_int_type (2, false);
484 case BT_UINT32
: return m_ctxt
->get_int_type (4, false);
485 case BT_UINT64
: return m_ctxt
->get_int_type (8, false);
487 // case BT_UNWINDWORD:
488 case BT_FLOAT
: return m_ctxt
->get_type (GCC_JIT_TYPE_FLOAT
);
489 case BT_DOUBLE
: return m_ctxt
->get_type (GCC_JIT_TYPE_DOUBLE
);
490 case BT_LONGDOUBLE
: return m_ctxt
->get_type (GCC_JIT_TYPE_LONG_DOUBLE
);
497 // case BT_FLOAT128X:
498 case BT_COMPLEX_FLOAT
:
499 return m_ctxt
->get_type (GCC_JIT_TYPE_COMPLEX_FLOAT
);
500 case BT_COMPLEX_DOUBLE
:
501 return m_ctxt
->get_type (GCC_JIT_TYPE_COMPLEX_DOUBLE
);
502 case BT_COMPLEX_LONGDOUBLE
:
503 return m_ctxt
->get_type (GCC_JIT_TYPE_COMPLEX_LONG_DOUBLE
);
504 case BT_PTR
: return m_ctxt
->get_type (GCC_JIT_TYPE_VOID_PTR
);
505 case BT_FILEPTR
: return m_ctxt
->get_type (GCC_JIT_TYPE_FILE_PTR
);
506 // case BT_CONST_TM_PTR:
507 // case BT_FENV_T_PTR:
508 // case BT_CONST_FENV_T_PTR:
509 // case BT_FEXCEPT_T_PTR:
510 // case BT_CONST_FEXCEPT_T_PTR:
512 return m_ctxt
->get_type (GCC_JIT_TYPE_VOID
)->get_const ()->get_pointer ();
513 case BT_VOLATILE_PTR
:
514 return (m_ctxt
->get_type (GCC_JIT_TYPE_VOID
)->get_volatile ()
516 case BT_CONST_VOLATILE_PTR
:
517 return (m_ctxt
->get_type (GCC_JIT_TYPE_VOID
)->get_const ()
518 ->get_volatile ()->get_pointer ());
521 return m_ctxt
->get_type (GCC_JIT_TYPE_INT
)->get_pointer ();
523 return m_ctxt
->get_type (GCC_JIT_TYPE_FLOAT
)->get_pointer ();
525 return m_ctxt
->get_type (GCC_JIT_TYPE_DOUBLE
)->get_pointer ();
526 case BT_CONST_DOUBLE_PTR
:
527 return (m_ctxt
->get_type (GCC_JIT_TYPE_DOUBLE
)->get_const ()
529 // case BT_LONGDOUBLE_PTR:
532 return m_ctxt
->get_type (GCC_JIT_TYPE_SIZE_T
);
534 return m_ctxt
->get_type (GCC_JIT_TYPE_SIZE_T
)->get_const ();
538 case BT_CONST_STRING
: return m_ctxt
->get_type (GCC_JIT_TYPE_CONST_CHAR_PTR
);
541 // case BT_DFLOAT128:
542 // case BT_VALIST_REF:
543 // case BT_VALIST_ARG:
549 // case BT_PTR_CONST_STRING:
553 /* Create the recording::function_type for a given function type
556 recording::function_type
*
557 builtins_manager::make_fn_type (enum jit_builtin_type
,
558 enum jit_builtin_type return_type_id
,
564 recording::type
**param_types
= new recording::type
*[num_args
];
565 recording::type
*return_type
= NULL
;
566 recording::function_type
*result
= NULL
;
568 va_start (list
, num_args
);
569 for (i
= 0; i
< num_args
; ++i
)
571 enum jit_builtin_type arg_type_id
=
572 (enum jit_builtin_type
) va_arg (list
, int);
573 param_types
[i
] = get_type (arg_type_id
);
579 return_type
= get_type (return_type_id
);
583 result
= m_ctxt
->new_function_type (return_type
,
589 delete[] param_types
;
593 /* Handler for DEF_POINTER_TYPE within builtins_manager::make_type. */
596 builtins_manager::make_ptr_type (enum jit_builtin_type
,
597 enum jit_builtin_type other_type_id
)
599 recording::type
*base_type
= get_type (other_type_id
);
600 return base_type
->get_pointer ();
603 /* Playback support. */
605 /* A builtins_manager is associated with a recording::context
606 and might be reused for multiple compiles on various
607 playback::contexts, perhaps with different options.
609 Purge any playback state. Currently this is just the table of
613 builtins_manager::finish_playback (void)
615 memset (m_attributes
, 0, sizeof (m_attributes
));
618 /* Get the enum built_in_class for BUILTIN_ID. */
621 builtins_manager::get_class (enum built_in_function builtin_id
)
623 return builtin_data
[builtin_id
].fnclass
;
626 /* Is BUILTIN_ID implicit? */
629 builtins_manager::implicit_p (enum built_in_function builtin_id
)
631 return builtin_data
[builtin_id
].implicit_p
;
634 /* Get any attributes (in tree form) for the function declaration
637 These are created on-demand, and cached within the m_attributes
638 array, until finish_playback. */
641 builtins_manager::get_attrs_tree (enum built_in_function builtin_id
)
643 enum built_in_attribute attr
= builtin_data
[builtin_id
].attr
;
644 return get_attrs_tree (attr
);
647 /* As above, but for an enum built_in_attribute. */
650 builtins_manager::get_attrs_tree (enum built_in_attribute attr
)
652 gcc_assert (attr
< ATTR_LAST
);
653 if (!m_attributes
[attr
])
654 m_attributes
[attr
] = make_attrs_tree (attr
);
655 return m_attributes
[attr
];
658 /* Handle a cache-miss within the m_attributes array by
659 generating the attributes for enum built_in_attribute
663 builtins_manager::make_attrs_tree (enum built_in_attribute attr
)
667 /* Generate cases from builtin-attrs.def. */
668 #define DEF_ATTR_NULL_TREE(ENUM) \
669 case ENUM: return NULL_TREE;
670 #define DEF_ATTR_INT(ENUM, VALUE) \
671 case ENUM: return build_int_cst (integer_type_node, VALUE);
672 #define DEF_ATTR_STRING(ENUM, VALUE) \
673 case ENUM: return build_string (strlen (VALUE), VALUE);
674 #define DEF_ATTR_IDENT(ENUM, STRING) \
675 case ENUM: return get_identifier (STRING);
676 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \
677 case ENUM: return tree_cons (get_attrs_tree (PURPOSE), \
678 get_attrs_tree (VALUE), \
679 get_attrs_tree (CHAIN));
680 #include "builtin-attrs.def"
681 #undef DEF_ATTR_NULL_TREE
683 #undef DEF_ATTR_IDENT
684 #undef DEF_ATTR_TREE_LIST
687 /* We somehow got a value not covered by the autogenerated