1 /* brig-lang.c -- brig (HSAIL) input gcc interface.
2 Copyright (C) 2016-2018 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_cmdline
== EXCESS_PRECISION_DEFAULT
)
170 flag_excess_precision_cmdline
= 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. */
592 def_fn_type (builtin_type def
, builtin_type ret
, bool var
, int n
, ...)
595 tree
*args
= XALLOCAVEC (tree
, n
);
601 for (i
= 0; i
< n
; ++i
)
603 builtin_type a
= (builtin_type
) va_arg (list
, int);
604 t
= builtin_types
[a
];
605 if (t
== error_mark_node
)
611 t
= builtin_types
[ret
];
614 if (t
== error_mark_node
)
617 t
= build_varargs_function_type_array (t
, n
, args
);
619 t
= build_function_type_array (t
, n
, args
);
621 builtin_types
[def
] = t
;
624 /* Used to help initialize the builtin-types.def table. When a type of
625 the correct size doesn't exist, use error_mark_node instead of NULL.
626 The later results in segfaults even when a decl using the type doesn't
630 builtin_type_for_size (int size
, bool unsignedp
)
632 tree type
= brig_langhook_type_for_size (size
, unsignedp
);
633 return type
? type
: error_mark_node
;
636 /* Support for DEF_BUILTIN. */
639 def_builtin_1 (enum built_in_function fncode
, const char *name
,
640 enum built_in_class fnclass ATTRIBUTE_UNUSED
,
641 tree fntype
, tree libtype ATTRIBUTE_UNUSED
,
642 bool both_p ATTRIBUTE_UNUSED
, bool fallback_p
,
643 bool nonansi_p ATTRIBUTE_UNUSED
, tree fnattrs
,
649 if (fntype
== error_mark_node
)
652 libname
= name
+ strlen ("__builtin_");
653 decl
= add_builtin_function (name
, fntype
, fncode
, fnclass
,
654 (fallback_p
? libname
: NULL
),
657 set_builtin_decl (fncode
, decl
, implicit_p
);
661 /* Initialize the attribute table for all the supported builtins. */
664 brig_init_attributes (void)
666 /* Fill in the built_in_attributes array. */
667 #define DEF_ATTR_NULL_TREE(ENUM) \
668 built_in_attributes[(int) ENUM] = NULL_TREE;
669 #define DEF_ATTR_INT(ENUM, VALUE) \
670 built_in_attributes[(int) ENUM] = build_int_cst (NULL_TREE, VALUE);
671 #define DEF_ATTR_STRING(ENUM, VALUE) \
672 built_in_attributes[(int) ENUM] = build_string (strlen (VALUE), VALUE);
673 #define DEF_ATTR_IDENT(ENUM, STRING) \
674 built_in_attributes[(int) ENUM] = get_identifier (STRING);
675 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \
676 built_in_attributes[(int) ENUM] \
677 = tree_cons (built_in_attributes[(int) PURPOSE], \
678 built_in_attributes[(int) VALUE], \
679 built_in_attributes[(int) CHAIN]);
680 #include "builtin-attrs.def"
681 #undef DEF_ATTR_NULL_TREE
683 #undef DEF_ATTR_STRING
684 #undef DEF_ATTR_IDENT
685 #undef DEF_ATTR_TREE_LIST
688 /* Create builtin types and functions. VA_LIST_REF_TYPE_NODE and
689 VA_LIST_ARG_TYPE_NODE are used in builtin-types.def. */
692 brig_define_builtins (tree va_list_ref_type_node ATTRIBUTE_UNUSED
,
693 tree va_list_arg_type_node ATTRIBUTE_UNUSED
)
695 #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
696 builtin_types[ENUM] = VALUE;
697 #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
698 def_fn_type (ENUM, RETURN, 0, 0);
699 #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
700 def_fn_type (ENUM, RETURN, 0, 1, ARG1);
701 #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
702 def_fn_type (ENUM, RETURN, 0, 2, ARG1, ARG2);
703 #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
704 def_fn_type (ENUM, RETURN, 0, 3, ARG1, ARG2, ARG3);
705 #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
706 def_fn_type (ENUM, RETURN, 0, 4, ARG1, ARG2, ARG3, ARG4);
707 #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
708 def_fn_type (ENUM, RETURN, 0, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
709 #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
711 def_fn_type (ENUM, RETURN, 0, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
712 #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
714 def_fn_type (ENUM, RETURN, 0, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
715 #define DEF_FUNCTION_TYPE_8(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
717 def_fn_type (ENUM, RETURN, 0, 8, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
719 #define DEF_FUNCTION_TYPE_9(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
720 ARG6, ARG7, ARG8, ARG9) \
721 def_fn_type (ENUM, RETURN, 0, 9, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
723 #define DEF_FUNCTION_TYPE_10(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
724 ARG6, ARG7, ARG8, ARG9, ARG10) \
725 def_fn_type (ENUM, RETURN, 0, 10, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
726 ARG7, ARG8, ARG9, ARG10);
727 #define DEF_FUNCTION_TYPE_11(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
728 ARG6, ARG7, ARG8, ARG9, ARG10, ARG11) \
729 def_fn_type (ENUM, RETURN, 0, 11, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, \
730 ARG7, ARG8, ARG9, ARG10, ARG11);
731 #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
732 def_fn_type (ENUM, RETURN, 1, 0);
733 #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
734 def_fn_type (ENUM, RETURN, 1, 1, ARG1);
735 #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
736 def_fn_type (ENUM, RETURN, 1, 2, ARG1, ARG2);
737 #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
738 def_fn_type (ENUM, RETURN, 1, 3, ARG1, ARG2, ARG3);
739 #define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
740 def_fn_type (ENUM, RETURN, 1, 4, ARG1, ARG2, ARG3, ARG4);
741 #define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \
742 def_fn_type (ENUM, RETURN, 1, 5, ARG1, ARG2, ARG3, ARG4, ARG5);
743 #define DEF_FUNCTION_TYPE_VAR_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
745 def_fn_type (ENUM, RETURN, 1, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6);
746 #define DEF_FUNCTION_TYPE_VAR_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \
748 def_fn_type (ENUM, RETURN, 1, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7);
749 #define DEF_POINTER_TYPE(ENUM, TYPE) \
750 builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]);
752 #include "builtin-types.def"
754 #undef DEF_PRIMITIVE_TYPE
755 #undef DEF_FUNCTION_TYPE_0
756 #undef DEF_FUNCTION_TYPE_1
757 #undef DEF_FUNCTION_TYPE_2
758 #undef DEF_FUNCTION_TYPE_3
759 #undef DEF_FUNCTION_TYPE_4
760 #undef DEF_FUNCTION_TYPE_5
761 #undef DEF_FUNCTION_TYPE_6
762 #undef DEF_FUNCTION_TYPE_7
763 #undef DEF_FUNCTION_TYPE_8
764 #undef DEF_FUNCTION_TYPE_9
765 #undef DEF_FUNCTION_TYPE_10
766 #undef DEF_FUNCTION_TYPE_11
767 #undef DEF_FUNCTION_TYPE_VAR_0
768 #undef DEF_FUNCTION_TYPE_VAR_1
769 #undef DEF_FUNCTION_TYPE_VAR_2
770 #undef DEF_FUNCTION_TYPE_VAR_3
771 #undef DEF_FUNCTION_TYPE_VAR_4
772 #undef DEF_FUNCTION_TYPE_VAR_5
773 #undef DEF_FUNCTION_TYPE_VAR_6
774 #undef DEF_FUNCTION_TYPE_VAR_7
775 #undef DEF_POINTER_TYPE
776 builtin_types
[(int) BT_LAST
] = NULL_TREE
;
778 brig_init_attributes ();
780 #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P,\
781 NONANSI_P, ATTRS, IMPLICIT, COND) \
783 def_builtin_1 (ENUM, NAME, CLASS, builtin_types[(int) TYPE], \
784 builtin_types[(int) LIBTYPE], BOTH_P, FALLBACK_P, \
785 NONANSI_P, built_in_attributes[(int) ATTRS], IMPLICIT);
787 #undef DEF_HSAIL_BUILTIN
788 #define DEF_HSAIL_BUILTIN(ENUM, HSAIL_OPCODE, HSAIL_TYPE, NAME, TYPE, ATTRS) \
789 DEF_BUILTIN (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE, TYPE, \
790 false, true, true, ATTRS, false, true)
792 /* HSAIL atomic builtins do not have separate identifying opcodes. */
794 #undef DEF_HSAIL_ATOMIC_BUILTIN
795 #define DEF_HSAIL_ATOMIC_BUILTIN(ENUM, ATOMIC_OPCODE, HSAIL_TYPE, NAME, \
797 DEF_BUILTIN (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE, TYPE, \
798 false, true, true, ATTRS, false, true)
800 /* HSAIL saturating arithmetics builtins. */
802 #undef DEF_HSAIL_SAT_BUILTIN
803 #define DEF_HSAIL_SAT_BUILTIN(ENUM, BRIG_OPCODE, HSAIL_TYPE, NAME, \
805 DEF_BUILTIN (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE, TYPE, \
806 false, true, true, ATTRS, false, true)
808 /* HSAIL builtins used internally by the frontend. */
810 #undef DEF_HSAIL_INTR_BUILTIN
811 #define DEF_HSAIL_INTR_BUILTIN(ENUM, NAME, TYPE, ATTRS) \
812 DEF_BUILTIN (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE, TYPE, \
813 false, true, true, ATTRS, false, true)
815 /* HSAIL saturated conversions. */
817 #undef DEF_HSAIL_CVT_ZEROI_SAT_BUILTIN
818 #define DEF_HSAIL_CVT_ZEROI_SAT_BUILTIN(ENUM, HSAIL_DEST_TYPE, HSAIL_SRC_TYPE, \
820 DEF_BUILTIN (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE, TYPE, \
821 false, true, true, ATTRS, false, true)
823 #include "builtins.def"
826 /* Build nodes that would have be created by the C front-end; necessary
827 for including builtin-types.def and ultimately builtins.def. Borrowed
831 brig_build_c_type_nodes (void)
833 gcc_assert (void_type_node
);
835 void_list_node
= build_tree_list (NULL_TREE
, void_type_node
);
836 string_type_node
= build_pointer_type (char_type_node
);
837 const_string_type_node
838 = build_pointer_type (build_qualified_type (char_type_node
,
841 if (strcmp (SIZE_TYPE
, "unsigned int") == 0)
843 intmax_type_node
= integer_type_node
;
844 uintmax_type_node
= unsigned_type_node
;
845 signed_size_type_node
= integer_type_node
;
847 else if (strcmp (SIZE_TYPE
, "long unsigned int") == 0)
849 intmax_type_node
= long_integer_type_node
;
850 uintmax_type_node
= long_unsigned_type_node
;
851 signed_size_type_node
= long_integer_type_node
;
853 else if (strcmp (SIZE_TYPE
, "long long unsigned int") == 0)
855 intmax_type_node
= long_long_integer_type_node
;
856 uintmax_type_node
= long_long_unsigned_type_node
;
857 signed_size_type_node
= long_long_integer_type_node
;
863 signed_size_type_node
= NULL_TREE
;
864 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
865 if (int_n_enabled_p
[i
])
868 sprintf (name
, "__int%d unsigned", int_n_data
[i
].bitsize
);
870 if (strcmp (name
, SIZE_TYPE
) == 0)
872 intmax_type_node
= int_n_trees
[i
].signed_type
;
873 uintmax_type_node
= int_n_trees
[i
].unsigned_type
;
874 signed_size_type_node
= int_n_trees
[i
].signed_type
;
877 if (signed_size_type_node
== NULL_TREE
)
881 wint_type_node
= unsigned_type_node
;
882 pid_type_node
= integer_type_node
;
887 brig_langhook_init (void)
889 build_common_tree_nodes (false);
891 /* Builtin initialization related code borrowed from lto-lang.c. */
892 void_list_node
= build_tree_list (NULL_TREE
, void_type_node
);
894 brig_build_c_type_nodes ();
896 if (TREE_CODE (va_list_type_node
) == ARRAY_TYPE
)
898 tree x
= build_pointer_type (TREE_TYPE (va_list_type_node
));
899 brig_define_builtins (x
, x
);
903 brig_define_builtins (build_reference_type (va_list_type_node
),
907 targetm
.init_builtins ();
908 build_common_builtin_nodes ();
913 #undef LANG_HOOKS_NAME
914 #undef LANG_HOOKS_INIT
915 #undef LANG_HOOKS_OPTION_LANG_MASK
916 #undef LANG_HOOKS_INIT_OPTIONS_STRUCT
917 #undef LANG_HOOKS_HANDLE_OPTION
918 #undef LANG_HOOKS_POST_OPTIONS
919 #undef LANG_HOOKS_PARSE_FILE
920 #undef LANG_HOOKS_TYPE_FOR_MODE
921 #undef LANG_HOOKS_TYPE_FOR_SIZE
922 #undef LANG_HOOKS_REGISTER_BUILTIN_TYPE
923 #undef LANG_HOOKS_BUILTIN_FUNCTION
924 #undef LANG_HOOKS_GLOBAL_BINDINGS_P
925 #undef LANG_HOOKS_PUSHDECL
926 #undef LANG_HOOKS_GETDECLS
927 #undef LANG_HOOKS_WRITE_GLOBALS
928 #undef LANG_HOOKS_GIMPLIFY_EXPR
929 #undef LANG_HOOKS_EH_PERSONALITY
931 #define LANG_HOOKS_NAME "GNU Brig"
932 #define LANG_HOOKS_INIT brig_langhook_init
933 #define LANG_HOOKS_OPTION_LANG_MASK brig_langhook_option_lang_mask
934 #define LANG_HOOKS_INIT_OPTIONS_STRUCT brig_langhook_init_options_struct
935 #define LANG_HOOKS_HANDLE_OPTION brig_langhook_handle_option
936 #define LANG_HOOKS_POST_OPTIONS brig_langhook_post_options
937 #define LANG_HOOKS_PARSE_FILE brig_langhook_parse_file
938 #define LANG_HOOKS_TYPE_FOR_MODE brig_langhook_type_for_mode
939 #define LANG_HOOKS_TYPE_FOR_SIZE brig_langhook_type_for_size
940 #define LANG_HOOKS_REGISTER_BUILTIN_TYPE brig_langhook_register_builtin_type
941 #define LANG_HOOKS_BUILTIN_FUNCTION brig_langhook_builtin_function
942 #define LANG_HOOKS_GLOBAL_BINDINGS_P brig_langhook_global_bindings_p
943 #define LANG_HOOKS_PUSHDECL brig_langhook_pushdecl
944 #define LANG_HOOKS_GETDECLS brig_langhook_getdecls
945 #define LANG_HOOKS_GIMPLIFY_EXPR brig_langhook_gimplify_expr
946 #define LANG_HOOKS_EH_PERSONALITY brig_langhook_eh_personality
948 /* Attribute hooks. */
949 #undef LANG_HOOKS_COMMON_ATTRIBUTE_TABLE
950 #define LANG_HOOKS_COMMON_ATTRIBUTE_TABLE brig_attribute_table
952 struct lang_hooks lang_hooks
= LANG_HOOKS_INITIALIZER
;
954 #include "gt-brig-brig-lang.h"
955 #include "gtype-brig.h"