1 /* brig-lang.c -- brig (HSAIL) input gcc interface.
2 Copyright (C) 2016-2020 Free Software Foundation, Inc.
3 Contributed by Pekka Jaaskelainen <pekka.jaaskelainen@parmance.com>
4 for General Processor Tech.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
25 #include "coretypes.h"
28 #include "tree-iterator.h"
29 #include "print-tree.h"
30 #include "stringpool.h"
31 #include "basic-block.h"
32 #include "gimple-expr.h"
35 #include "stor-layout.h"
41 #include "diagnostic.h"
42 #include "langhooks.h"
43 #include "langhooks-def.h"
46 #include "brigfrontend/brig-to-generic.h"
48 #include "fold-const.h"
49 #include "common/common-target.h"
52 #include "brig-builtins.h"
54 static tree
handle_leaf_attribute (tree
*, tree
, tree
, int, bool *);
55 static tree
handle_const_attribute (tree
*, tree
, tree
, int, bool *);
56 static tree
handle_pure_attribute (tree
*, tree
, tree
, int, bool *);
57 static tree
handle_nothrow_attribute (tree
*, tree
, tree
, int, bool *);
58 static tree
handle_returns_twice_attribute (tree
*, tree
, tree
, int, bool *);
60 /* This file is based on Go frontend's go-lang.c and gogo-tree.cc. */
64 int gccbrig_verbose
= 0;
66 /* Language-dependent contents of a type. */
68 struct GTY (()) lang_type
73 /* Language-dependent contents of a decl. */
75 struct GTY ((variable_size
)) lang_decl
80 /* Language-dependent contents of an identifier. This must include a
83 struct GTY (()) lang_identifier
85 struct tree_identifier common
;
88 /* The resulting tree type. */
90 union GTY ((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
91 chain_next ("CODE_CONTAINS_STRUCT (TREE_CODE (&%h.generic), "
92 "TS_COMMON) ? ((union lang_tree_node *) TREE_CHAIN "
93 "(&%h.generic)) : NULL"))) lang_tree_node
95 union tree_node
GTY ((tag ("0"), desc ("tree_node_structure (&%h)"))) generic
;
96 struct lang_identifier
GTY ((tag ("1"))) identifier
;
99 /* We don't use language_function. */
101 struct GTY (()) language_function
107 /* The option mask. */
110 brig_langhook_option_lang_mask (void)
115 /* Initialize the options structure. */
118 brig_langhook_init_options_struct (struct gcc_options
*opts
)
120 /* Signed overflow is precisely defined. */
121 opts
->x_flag_wrapv
= 1;
123 /* If we set this to one, the whole program optimizations internalize
124 all global variables, making them invisible to the dyn loader (and
125 thus the HSA runtime implementation). */
126 opts
->x_flag_whole_program
= 1;
128 /* The builtin math functions should not set errno. */
129 opts
->x_flag_errno_math
= 0;
130 opts
->frontend_set_flag_errno_math
= false;
132 opts
->x_flag_exceptions
= 0;
133 opts
->x_flag_non_call_exceptions
= 0;
135 opts
->x_flag_finite_math_only
= 0;
136 opts
->x_flag_signed_zeros
= 1;
138 opts
->x_optimize
= 3;
143 /* Handle Brig specific options. Return 0 if we didn't do anything. */
146 brig_langhook_handle_option
147 (size_t scode
, const char *arg ATTRIBUTE_UNUSED
,
148 HOST_WIDE_INT value ATTRIBUTE_UNUSED
, int kind ATTRIBUTE_UNUSED
,
149 location_t loc ATTRIBUTE_UNUSED
,
150 const struct cl_option_handlers
*handlers ATTRIBUTE_UNUSED
)
152 enum opt_code code
= (enum opt_code
) scode
;
164 /* Run after parsing options. */
167 brig_langhook_post_options (const char **pfilename ATTRIBUTE_UNUSED
)
169 if (flag_excess_precision
== EXCESS_PRECISION_DEFAULT
)
170 flag_excess_precision
= EXCESS_PRECISION_STANDARD
;
172 /* gccbrig casts pointers around like crazy, TBAA might produce broken
173 code if not disabling it by default. Some PRM conformance tests such
174 as prm/core/memory/ordinary/ld/ld_u16 fail currently with strict
175 aliasing (to fix). It can be enabled from the command line for cases
176 that are known not to break the C style aliasing requirements. */
177 if (!global_options_set
.x_flag_strict_aliasing
)
178 flag_strict_aliasing
= 0;
180 flag_strict_aliasing
= global_options
.x_flag_strict_aliasing
;
182 /* Returning false means that the backend should be used. */
187 get_file_size (FILE *file
)
190 fseek (file
, 0, SEEK_END
);
191 size
= (size_t) ftell (file
);
192 fseek (file
, 0, SEEK_SET
);
197 brig_langhook_parse_file (void)
199 brig_to_generic brig_to_gen
;
201 std::vector
<char*> brig_blobs
;
203 for (unsigned int i
= 0; i
< num_in_fnames
; ++i
)
207 f
= fopen (in_fnames
[i
], "r");
208 size_t fsize
= get_file_size (f
);
209 char *brig_blob
= new char[fsize
];
210 if (fread (brig_blob
, 1, fsize
, f
) != fsize
)
212 error ("could not read the BRIG file");
217 brig_to_gen
.analyze (brig_blob
);
218 brig_blobs
.push_back (brig_blob
);
221 for (size_t i
= 0; i
< brig_blobs
.size(); ++i
)
223 char *brig_blob
= brig_blobs
.at(i
);
224 brig_to_gen
.parse (brig_blob
);
227 brig_to_gen
.write_globals ();
229 for (size_t i
= 0; i
< brig_blobs
.size (); ++i
)
230 delete brig_blobs
[i
];
234 brig_langhook_type_for_size (unsigned int bits
,
237 /* Copied from go-lang.c */
241 if (bits
== INT_TYPE_SIZE
)
242 type
= unsigned_type_node
;
243 else if (bits
== CHAR_TYPE_SIZE
)
244 type
= unsigned_char_type_node
;
245 else if (bits
== SHORT_TYPE_SIZE
)
246 type
= short_unsigned_type_node
;
247 else if (bits
== LONG_TYPE_SIZE
)
248 type
= long_unsigned_type_node
;
249 else if (bits
== LONG_LONG_TYPE_SIZE
)
250 type
= long_long_unsigned_type_node
;
252 type
= make_unsigned_type(bits
);
256 if (bits
== INT_TYPE_SIZE
)
257 type
= integer_type_node
;
258 else if (bits
== CHAR_TYPE_SIZE
)
259 type
= signed_char_type_node
;
260 else if (bits
== SHORT_TYPE_SIZE
)
261 type
= short_integer_type_node
;
262 else if (bits
== LONG_TYPE_SIZE
)
263 type
= long_integer_type_node
;
264 else if (bits
== LONG_LONG_TYPE_SIZE
)
265 type
= long_long_integer_type_node
;
267 type
= make_signed_type(bits
);
273 brig_langhook_type_for_mode (machine_mode mode
, int unsignedp
)
275 if (mode
== TYPE_MODE (void_type_node
))
276 return void_type_node
;
278 if (VECTOR_MODE_P (mode
))
282 inner
= brig_langhook_type_for_mode (GET_MODE_INNER (mode
), unsignedp
);
283 if (inner
!= NULL_TREE
)
284 return build_vector_type_for_mode (inner
, mode
);
289 scalar_int_mode imode
;
290 scalar_float_mode fmode
;
291 if (is_float_mode (mode
, &fmode
))
293 switch (GET_MODE_BITSIZE (fmode
))
296 return float_type_node
;
298 return double_type_node
;
300 /* We have to check for long double in order to support
301 i386 excess precision. */
302 if (fmode
== TYPE_MODE (long_double_type_node
))
303 return long_double_type_node
;
309 else if (is_int_mode (mode
, &imode
))
310 return brig_langhook_type_for_size (GET_MODE_BITSIZE (imode
), unsignedp
);
313 /* E.g., build_common_builtin_nodes () asks for modes/builtins
314 we do not generate or need. Just ignore them silently for now.
322 brig_langhook_builtin_function (tree decl
)
327 static GTY(()) tree registered_builtin_types
;
330 brig_langhook_register_builtin_type (tree type
, const char *name
)
334 if (!TYPE_NAME (type
))
336 decl
= build_decl (UNKNOWN_LOCATION
, TYPE_DECL
,
337 get_identifier (name
), type
);
338 DECL_ARTIFICIAL (decl
) = 1;
339 TYPE_NAME (type
) = decl
;
342 registered_builtin_types
= tree_cons (0, type
, registered_builtin_types
);
346 /* Return true if we are in the global binding level. */
349 brig_langhook_global_bindings_p (void)
351 return current_function_decl
== NULL_TREE
;
354 /* Push a declaration into the current binding level. From Go: We can't
355 usefully implement this since we don't want to convert from tree
356 back to one of our internal data structures. I think the only way
357 this is used is to record a decl which is to be returned by
358 getdecls, and we could implement it for that purpose if
362 brig_langhook_pushdecl (tree decl ATTRIBUTE_UNUSED
)
367 /* This hook is used to get the current list of declarations as trees.
368 From Go: We don't support that; instead we use the write_globals hook.
369 This can't simply crash because it is called by -gstabs. */
372 brig_langhook_getdecls (void)
378 brig_langhook_gimplify_expr (tree
*expr_p
, gimple_seq
*pre_p ATTRIBUTE_UNUSED
,
379 gimple_seq
*post_p ATTRIBUTE_UNUSED
)
382 /* Strip off the static chain info that appears to function
383 calls for some strange reason even though we don't add
384 nested functions. Maybe something wrong with the function
385 declaration contexts? */
386 if (TREE_CODE (*expr_p
) == CALL_EXPR
387 && CALL_EXPR_STATIC_CHAIN (*expr_p
) != NULL_TREE
)
388 CALL_EXPR_STATIC_CHAIN (*expr_p
) = NULL_TREE
;
393 brig_langhook_eh_personality (void)
398 /* Functions called directly by the generic backend.
399 Adapted from go-lang.c. */
402 convert (tree type
, tree expr
)
404 if (type
== error_mark_node
|| expr
== error_mark_node
405 || TREE_TYPE (expr
) == error_mark_node
)
406 return error_mark_node
;
408 if (type
== TREE_TYPE (expr
))
411 if (TYPE_MAIN_VARIANT (type
) == TYPE_MAIN_VARIANT (TREE_TYPE (expr
)))
412 return fold_convert (type
, expr
);
414 switch (TREE_CODE (type
))
418 return fold_convert (type
, expr
);
420 return fold (convert_to_integer (type
, expr
));
422 return fold (convert_to_real (type
, expr
));
424 return fold (convert_to_vector (type
, expr
));
426 return build1 (VIEW_CONVERT_EXPR
, type
, convert (size_type_node
, expr
));
434 static GTY (()) tree brig_gc_root
;
436 /* Preserve trees that we create from the garbage collector. */
439 brig_preserve_from_gc (tree t
)
441 brig_gc_root
= tree_cons (NULL_TREE
, t
, brig_gc_root
);
444 /* Convert an identifier for use in an error message. */
447 brig_localize_identifier (const char *ident
)
449 return identifier_to_locale (ident
);
452 /* Define supported attributes and their handlers. Code copied from
455 /* Table of machine-independent attributes supported in GIMPLE. */
456 const struct attribute_spec brig_attribute_table
[] =
458 /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
459 affects_type_identity, handler, exclude } */
460 { "leaf", 0, 0, true, false, false, false,
461 handle_leaf_attribute
, NULL
},
462 { "const", 0, 0, true, false, false, false,
463 handle_const_attribute
, NULL
},
464 { "pure", 0, 0, true, false, false, false,
465 handle_pure_attribute
, NULL
},
466 { "nothrow", 0, 0, true, false, false, false,
467 handle_nothrow_attribute
, NULL
},
468 { "returns_twice", 0, 0, true, false, false, false,
469 handle_returns_twice_attribute
, NULL
},
470 { NULL
, 0, 0, false, false, false, false, NULL
, NULL
}
473 /* Attribute handlers. */
474 /* Handle a "leaf" attribute; arguments as in
475 struct attribute_spec.handler. */
478 handle_leaf_attribute (tree
*node
, tree name
,
479 tree
ARG_UNUSED (args
),
480 int ARG_UNUSED (flags
), bool *no_add_attrs
)
482 if (TREE_CODE (*node
) != FUNCTION_DECL
)
484 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
485 *no_add_attrs
= true;
487 if (!TREE_PUBLIC (*node
))
489 warning (OPT_Wattributes
,
490 "%qE attribute has no effect on unit local functions", name
);
491 *no_add_attrs
= true;
497 /* Handle a "const" attribute; arguments as in
498 struct attribute_spec.handler. */
501 handle_const_attribute (tree
*node
, tree
ARG_UNUSED (name
),
502 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
503 bool * ARG_UNUSED (no_add_attrs
))
505 tree type
= TREE_TYPE (*node
);
507 /* See FIXME comment on noreturn in c_common_attribute_table. */
508 if (TREE_CODE (*node
) == FUNCTION_DECL
)
509 TREE_READONLY (*node
) = 1;
510 else if (TREE_CODE (type
) == POINTER_TYPE
511 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
514 (build_type_variant (TREE_TYPE (type
), 1,
515 TREE_THIS_VOLATILE (TREE_TYPE (type
))));
522 /* Handle a "pure" attribute; arguments as in
523 struct attribute_spec.handler. */
526 handle_pure_attribute (tree
*node
, tree
ARG_UNUSED (name
),
527 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
528 bool * ARG_UNUSED (no_add_attrs
))
530 if (TREE_CODE (*node
) == FUNCTION_DECL
)
531 DECL_PURE_P (*node
) = 1;
538 /* Handle a "nothrow" attribute; arguments as in
539 struct attribute_spec.handler. */
542 handle_nothrow_attribute (tree
*node
, tree
ARG_UNUSED (name
),
543 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
544 bool * ARG_UNUSED (no_add_attrs
))
546 if (TREE_CODE (*node
) == FUNCTION_DECL
)
547 TREE_NOTHROW (*node
) = 1;
554 /* Handle a "returns_twice" attribute. */
557 handle_returns_twice_attribute (tree
*node
, tree
ARG_UNUSED (name
),
558 tree
ARG_UNUSED (args
),
559 int ARG_UNUSED (flags
),
560 bool * ARG_UNUSED (no_add_attrs
))
562 gcc_assert (TREE_CODE (*node
) == FUNCTION_DECL
);
564 DECL_IS_RETURNS_TWICE (*node
) = 1;
570 /* Built-in initialization code cribbed from lto-lang.c which cribbed it
574 static GTY(()) tree built_in_attributes
[(int) ATTR_LAST
];
577 static GTY(()) tree builtin_types
[(int) BT_LAST
+ 1];
579 static GTY(()) tree string_type_node
;
580 static GTY(()) tree const_string_type_node
;
581 static GTY(()) tree wint_type_node
;
582 static GTY(()) tree intmax_type_node
;
583 static GTY(()) tree uintmax_type_node
;
584 static GTY(()) tree signed_size_type_node
;
586 /* Flags needed to process builtins.def. */
593 def_fn_type (builtin_type def
, builtin_type ret
, bool var
, int n
, ...)
596 tree
*args
= XALLOCAVEC (tree
, n
);
602 for (i
= 0; i
< n
; ++i
)
604 builtin_type a
= (builtin_type
) va_arg (list
, int);
605 t
= builtin_types
[a
];
606 if (t
== error_mark_node
)
612 t
= builtin_types
[ret
];
615 if (t
== error_mark_node
)
618 t
= build_varargs_function_type_array (t
, n
, args
);
620 t
= build_function_type_array (t
, n
, args
);
622 builtin_types
[def
] = t
;
625 /* Used to help initialize the builtin-types.def table. When a type of
626 the correct size doesn't exist, use error_mark_node instead of NULL.
627 The later results in segfaults even when a decl using the type doesn't
631 builtin_type_for_size (int size
, bool unsignedp
)
633 tree type
= brig_langhook_type_for_size (size
, unsignedp
);
634 return type
? type
: error_mark_node
;
637 /* Support for DEF_BUILTIN. */
640 def_builtin_1 (enum built_in_function fncode
, const char *name
,
641 enum built_in_class fnclass ATTRIBUTE_UNUSED
,
642 tree fntype
, tree libtype ATTRIBUTE_UNUSED
,
643 bool both_p ATTRIBUTE_UNUSED
, bool fallback_p
,
644 bool nonansi_p ATTRIBUTE_UNUSED
, tree fnattrs
,
650 if (fntype
== error_mark_node
)
653 libname
= name
+ strlen ("__builtin_");
654 decl
= add_builtin_function (name
, fntype
, fncode
, fnclass
,
655 (fallback_p
? libname
: NULL
),
658 set_builtin_decl (fncode
, decl
, implicit_p
);
662 /* Initialize the attribute table for all the supported builtins. */
665 brig_init_attributes (void)
667 /* Fill in the built_in_attributes array. */
668 #define DEF_ATTR_NULL_TREE(ENUM) \
669 built_in_attributes[(int) ENUM] = NULL_TREE;
670 #define DEF_ATTR_INT(ENUM, VALUE) \
671 built_in_attributes[(int) ENUM] = build_int_cst (NULL_TREE, VALUE);
672 #define DEF_ATTR_STRING(ENUM, VALUE) \
673 built_in_attributes[(int) ENUM] = build_string (strlen (VALUE), VALUE);
674 #define DEF_ATTR_IDENT(ENUM, STRING) \
675 built_in_attributes[(int) ENUM] = get_identifier (STRING);
676 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \
677 built_in_attributes[(int) ENUM] \
678 = tree_cons (built_in_attributes[(int) PURPOSE], \
679 built_in_attributes[(int) VALUE], \
680 built_in_attributes[(int) CHAIN]);
681 #include "builtin-attrs.def"
682 #undef DEF_ATTR_NULL_TREE
684 #undef DEF_ATTR_STRING
685 #undef DEF_ATTR_IDENT
686 #undef DEF_ATTR_TREE_LIST
689 /* Create builtin types and functions. VA_LIST_REF_TYPE_NODE and
690 VA_LIST_ARG_TYPE_NODE are used in builtin-types.def. */
693 brig_define_builtins (tree va_list_ref_type_node ATTRIBUTE_UNUSED
,
694 tree va_list_arg_type_node ATTRIBUTE_UNUSED
)
696 #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
697 builtin_types[ENUM] = VALUE;
698 #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
699 def_fn_type (ENUM, RETURN, 0, 0);
700 #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
701 def_fn_type (ENUM, RETURN, 0, 1, ARG1);
702 #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
703 def_fn_type (ENUM, RETURN, 0, 2, ARG1, ARG2);
704 #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
705 def_fn_type (ENUM, RETURN, 0, 3, ARG1, ARG2, ARG3);
706 #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
707 def_fn_type (ENUM, RETURN, 0, 4, ARG1, ARG2, ARG3, ARG4);
708 #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
709 def_fn_type (ENUM, RETURN, 0, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
710 #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
712 def_fn_type (ENUM, RETURN, 0, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
713 #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
715 def_fn_type (ENUM, RETURN, 0, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
716 #define DEF_FUNCTION_TYPE_8(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
718 def_fn_type (ENUM, RETURN, 0, 8, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
720 #define DEF_FUNCTION_TYPE_9(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
721 ARG6, ARG7, ARG8, ARG9) \
722 def_fn_type (ENUM, RETURN, 0, 9, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
724 #define DEF_FUNCTION_TYPE_10(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
725 ARG6, ARG7, ARG8, ARG9, ARG10) \
726 def_fn_type (ENUM, RETURN, 0, 10, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
727 ARG7, ARG8, ARG9, ARG10);
728 #define DEF_FUNCTION_TYPE_11(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
729 ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) \
730 def_fn_type (ENUM, RETURN, 0, 11, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
731 ARG7, ARG8, ARG9, ARG10, ARG11);
732 #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
733 def_fn_type (ENUM, RETURN, 1, 0);
734 #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
735 def_fn_type (ENUM, RETURN, 1, 1, ARG1);
736 #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
737 def_fn_type (ENUM, RETURN, 1, 2, ARG1, ARG2);
738 #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
739 def_fn_type (ENUM, RETURN, 1, 3, ARG1, ARG2, ARG3);
740 #define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
741 def_fn_type (ENUM, RETURN, 1, 4, ARG1, ARG2, ARG3, ARG4);
742 #define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
743 def_fn_type (ENUM, RETURN, 1, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
744 #define DEF_FUNCTION_TYPE_VAR_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
746 def_fn_type (ENUM, RETURN, 1, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
747 #define DEF_FUNCTION_TYPE_VAR_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
749 def_fn_type (ENUM, RETURN, 1, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
750 #define DEF_POINTER_TYPE(ENUM, TYPE) \
751 builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]);
753 #include "builtin-types.def"
755 #undef DEF_PRIMITIVE_TYPE
756 #undef DEF_FUNCTION_TYPE_0
757 #undef DEF_FUNCTION_TYPE_1
758 #undef DEF_FUNCTION_TYPE_2
759 #undef DEF_FUNCTION_TYPE_3
760 #undef DEF_FUNCTION_TYPE_4
761 #undef DEF_FUNCTION_TYPE_5
762 #undef DEF_FUNCTION_TYPE_6
763 #undef DEF_FUNCTION_TYPE_7
764 #undef DEF_FUNCTION_TYPE_8
765 #undef DEF_FUNCTION_TYPE_9
766 #undef DEF_FUNCTION_TYPE_10
767 #undef DEF_FUNCTION_TYPE_11
768 #undef DEF_FUNCTION_TYPE_VAR_0
769 #undef DEF_FUNCTION_TYPE_VAR_1
770 #undef DEF_FUNCTION_TYPE_VAR_2
771 #undef DEF_FUNCTION_TYPE_VAR_3
772 #undef DEF_FUNCTION_TYPE_VAR_4
773 #undef DEF_FUNCTION_TYPE_VAR_5
774 #undef DEF_FUNCTION_TYPE_VAR_6
775 #undef DEF_FUNCTION_TYPE_VAR_7
776 #undef DEF_POINTER_TYPE
777 builtin_types
[(int) BT_LAST
] = NULL_TREE
;
779 brig_init_attributes ();
781 #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P,\
782 NONANSI_P, ATTRS, IMPLICIT, COND) \
784 def_builtin_1 (ENUM, NAME, CLASS, builtin_types[(int) TYPE], \
785 builtin_types[(int) LIBTYPE], BOTH_P, FALLBACK_P, \
786 NONANSI_P, built_in_attributes[(int) ATTRS], IMPLICIT);
788 #undef DEF_HSAIL_BUILTIN
789 #define DEF_HSAIL_BUILTIN(ENUM, HSAIL_OPCODE, HSAIL_TYPE, NAME, TYPE, ATTRS) \
790 DEF_BUILTIN (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE, TYPE, \
791 false, true, true, ATTRS, false, true)
793 /* HSAIL atomic builtins do not have separate identifying opcodes. */
795 #undef DEF_HSAIL_ATOMIC_BUILTIN
796 #define DEF_HSAIL_ATOMIC_BUILTIN(ENUM, ATOMIC_OPCODE, HSAIL_TYPE, NAME, \
798 DEF_BUILTIN (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE, TYPE, \
799 false, true, true, ATTRS, false, true)
801 /* HSAIL saturating arithmetics builtins. */
803 #undef DEF_HSAIL_SAT_BUILTIN
804 #define DEF_HSAIL_SAT_BUILTIN(ENUM, BRIG_OPCODE, HSAIL_TYPE, NAME, \
806 DEF_BUILTIN (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE, TYPE, \
807 false, true, true, ATTRS, false, true)
809 /* HSAIL builtins used internally by the frontend. */
811 #undef DEF_HSAIL_INTR_BUILTIN
812 #define DEF_HSAIL_INTR_BUILTIN(ENUM, NAME, TYPE, ATTRS) \
813 DEF_BUILTIN (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE, TYPE, \
814 false, true, true, ATTRS, false, true)
816 /* HSAIL saturated conversions. */
818 #undef DEF_HSAIL_CVT_ZEROI_SAT_BUILTIN
819 #define DEF_HSAIL_CVT_ZEROI_SAT_BUILTIN(ENUM, HSAIL_DEST_TYPE, HSAIL_SRC_TYPE, \
821 DEF_BUILTIN (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE, TYPE, \
822 false, true, true, ATTRS, false, true)
824 #include "builtins.def"
827 /* Build nodes that would have be created by the C front-end; necessary
828 for including builtin-types.def and ultimately builtins.def. Borrowed
832 brig_build_c_type_nodes (void)
834 gcc_assert (void_type_node
);
836 void_list_node
= build_tree_list (NULL_TREE
, void_type_node
);
837 string_type_node
= build_pointer_type (char_type_node
);
838 const_string_type_node
839 = build_pointer_type (build_qualified_type (char_type_node
,
842 if (strcmp (SIZE_TYPE
, "unsigned int") == 0)
844 intmax_type_node
= integer_type_node
;
845 uintmax_type_node
= unsigned_type_node
;
846 signed_size_type_node
= integer_type_node
;
848 else if (strcmp (SIZE_TYPE
, "long unsigned int") == 0)
850 intmax_type_node
= long_integer_type_node
;
851 uintmax_type_node
= long_unsigned_type_node
;
852 signed_size_type_node
= long_integer_type_node
;
854 else if (strcmp (SIZE_TYPE
, "long long unsigned int") == 0)
856 intmax_type_node
= long_long_integer_type_node
;
857 uintmax_type_node
= long_long_unsigned_type_node
;
858 signed_size_type_node
= long_long_integer_type_node
;
864 signed_size_type_node
= NULL_TREE
;
865 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
866 if (int_n_enabled_p
[i
])
868 char name
[50], altname
[50];
869 sprintf (name
, "__int%d unsigned", int_n_data
[i
].bitsize
);
870 sprintf (altname
, "__int%d__ unsigned", int_n_data
[i
].bitsize
);
872 if (strcmp (name
, SIZE_TYPE
) == 0
873 || strcmp (altname
, SIZE_TYPE
) == 0)
875 intmax_type_node
= int_n_trees
[i
].signed_type
;
876 uintmax_type_node
= int_n_trees
[i
].unsigned_type
;
877 signed_size_type_node
= int_n_trees
[i
].signed_type
;
880 if (signed_size_type_node
== NULL_TREE
)
884 wint_type_node
= unsigned_type_node
;
885 pid_type_node
= integer_type_node
;
890 brig_langhook_init (void)
892 build_common_tree_nodes (false);
894 /* Builtin initialization related code borrowed from lto-lang.c. */
895 void_list_node
= build_tree_list (NULL_TREE
, void_type_node
);
897 brig_build_c_type_nodes ();
899 if (TREE_CODE (va_list_type_node
) == ARRAY_TYPE
)
901 tree x
= build_pointer_type (TREE_TYPE (va_list_type_node
));
902 brig_define_builtins (x
, x
);
906 brig_define_builtins (build_reference_type (va_list_type_node
),
910 targetm
.init_builtins ();
911 build_common_builtin_nodes ();
916 #undef LANG_HOOKS_NAME
917 #undef LANG_HOOKS_INIT
918 #undef LANG_HOOKS_OPTION_LANG_MASK
919 #undef LANG_HOOKS_INIT_OPTIONS_STRUCT
920 #undef LANG_HOOKS_HANDLE_OPTION
921 #undef LANG_HOOKS_POST_OPTIONS
922 #undef LANG_HOOKS_PARSE_FILE
923 #undef LANG_HOOKS_TYPE_FOR_MODE
924 #undef LANG_HOOKS_TYPE_FOR_SIZE
925 #undef LANG_HOOKS_REGISTER_BUILTIN_TYPE
926 #undef LANG_HOOKS_BUILTIN_FUNCTION
927 #undef LANG_HOOKS_GLOBAL_BINDINGS_P
928 #undef LANG_HOOKS_PUSHDECL
929 #undef LANG_HOOKS_GETDECLS
930 #undef LANG_HOOKS_WRITE_GLOBALS
931 #undef LANG_HOOKS_GIMPLIFY_EXPR
932 #undef LANG_HOOKS_EH_PERSONALITY
934 #define LANG_HOOKS_NAME "GNU Brig"
935 #define LANG_HOOKS_INIT brig_langhook_init
936 #define LANG_HOOKS_OPTION_LANG_MASK brig_langhook_option_lang_mask
937 #define LANG_HOOKS_INIT_OPTIONS_STRUCT brig_langhook_init_options_struct
938 #define LANG_HOOKS_HANDLE_OPTION brig_langhook_handle_option
939 #define LANG_HOOKS_POST_OPTIONS brig_langhook_post_options
940 #define LANG_HOOKS_PARSE_FILE brig_langhook_parse_file
941 #define LANG_HOOKS_TYPE_FOR_MODE brig_langhook_type_for_mode
942 #define LANG_HOOKS_TYPE_FOR_SIZE brig_langhook_type_for_size
943 #define LANG_HOOKS_REGISTER_BUILTIN_TYPE brig_langhook_register_builtin_type
944 #define LANG_HOOKS_BUILTIN_FUNCTION brig_langhook_builtin_function
945 #define LANG_HOOKS_GLOBAL_BINDINGS_P brig_langhook_global_bindings_p
946 #define LANG_HOOKS_PUSHDECL brig_langhook_pushdecl
947 #define LANG_HOOKS_GETDECLS brig_langhook_getdecls
948 #define LANG_HOOKS_GIMPLIFY_EXPR brig_langhook_gimplify_expr
949 #define LANG_HOOKS_EH_PERSONALITY brig_langhook_eh_personality
951 /* Attribute hooks. */
952 #undef LANG_HOOKS_COMMON_ATTRIBUTE_TABLE
953 #define LANG_HOOKS_COMMON_ATTRIBUTE_TABLE brig_attribute_table
955 struct lang_hooks lang_hooks
= LANG_HOOKS_INITIALIZER
;
957 #include "gt-brig-brig-lang.h"
958 #include "gtype-brig.h"