diff options
author | visit0r <visit0r@138bc75d-0d04-0410-961f-82ee72b054a4> | 2017-09-28 15:29:07 +0000 |
---|---|---|
committer | visit0r <visit0r@138bc75d-0d04-0410-961f-82ee72b054a4> | 2017-09-28 15:29:07 +0000 |
commit | d2a5e3d37abeac438673d66a55159a39ce77381c (patch) | |
tree | 5b5a01851c89b143aa7ec7663621fc61d906b795 /gcc/brig | |
parent | e4e13a22cacd93a02c46321f2880268d8f5de314 (diff) | |
download | gcc-d2a5e3d37abeac438673d66a55159a39ce77381c.tar.gz |
[BRIGFE] Changed pure attributes to const for the brig-builtins
that are actually const.
Also:
* Fixed brig-lang.c such that the builtin attributes actually
have effect...
* Made -O3 the default optimization level for BRIG.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@253254 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/brig')
-rw-r--r-- | gcc/brig/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/brig/brig-lang.c | 130 |
2 files changed, 135 insertions, 0 deletions
diff --git a/gcc/brig/ChangeLog b/gcc/brig/ChangeLog index 0225929c2ef..fb2b09d70e4 100644 --- a/gcc/brig/ChangeLog +++ b/gcc/brig/ChangeLog @@ -1,3 +1,8 @@ +2017-09-28 Henry Linjamäki <henry.linjamaki@parmance.com> + + * brig-lang.c: Added function attributes and their handlers. + Make BRIGFE 3-level optimize by default. + 2017-09-27 Pekka Jääskeläinen <pekka.jaaskelainen@parmance.com> * brig-lang.c: Improved support for function and module scope diff --git a/gcc/brig/brig-lang.c b/gcc/brig/brig-lang.c index a587c8b6091..970214b3a3f 100644 --- a/gcc/brig/brig-lang.c +++ b/gcc/brig/brig-lang.c @@ -51,6 +51,12 @@ along with GCC; see the file COPYING3. If not see #include "brig-c.h" #include "brig-builtins.h" +static tree handle_leaf_attribute (tree *, tree, tree, int, bool *); +static tree handle_const_attribute (tree *, tree, tree, int, bool *); +static tree handle_pure_attribute (tree *, tree, tree, int, bool *); +static tree handle_nothrow_attribute (tree *, tree, tree, int, bool *); +static tree handle_returns_twice_attribute (tree *, tree, tree, int, bool *); + /* This file is based on Go frontent'd go-lang.c and gogo-tree.cc. */ /* If -v set. */ @@ -128,6 +134,8 @@ brig_langhook_init_options_struct (struct gcc_options *opts) opts->x_flag_finite_math_only = 0; opts->x_flag_signed_zeros = 1; + + opts->x_optimize = 3; } /* Handle Brig specific options. Return 0 if we didn't do anything. */ @@ -432,6 +440,124 @@ brig_localize_identifier (const char *ident) return identifier_to_locale (ident); } +/* Define supported attributes and their handlers. Code copied from + lto-lang.c */ + +/* Table of machine-independent attributes supported in GIMPLE. */ +const struct attribute_spec brig_attribute_table[] = +{ + /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler, + do_diagnostic } */ + { "leaf", 0, 0, true, false, false, + handle_leaf_attribute, false }, + { "const", 0, 0, true, false, false, + handle_const_attribute, false }, + { "pure", 0, 0, true, false, false, + handle_pure_attribute, false }, + { "nothrow", 0, 0, true, false, false, + handle_nothrow_attribute, false }, + { "returns_twice", 0, 0, true, false, false, + handle_returns_twice_attribute, false }, + { NULL, 0, 0, false, false, false, NULL, false } +}; + +/* Attribute handlers. */ +/* Handle a "leaf" attribute; arguments as in + struct attribute_spec.handler. */ + +static tree +handle_leaf_attribute (tree *node, tree name, + tree ARG_UNUSED (args), + int ARG_UNUSED (flags), bool *no_add_attrs) +{ + if (TREE_CODE (*node) != FUNCTION_DECL) + { + warning (OPT_Wattributes, "%qE attribute ignored", name); + *no_add_attrs = true; + } + if (!TREE_PUBLIC (*node)) + { + warning (OPT_Wattributes, + "%qE attribute has no effect on unit local functions", name); + *no_add_attrs = true; + } + + return NULL_TREE; +} + +/* Handle a "const" attribute; arguments as in + struct attribute_spec.handler. */ + +static tree +handle_const_attribute (tree *node, tree ARG_UNUSED (name), + tree ARG_UNUSED (args), int ARG_UNUSED (flags), + bool * ARG_UNUSED (no_add_attrs)) +{ + tree type = TREE_TYPE (*node); + + /* See FIXME comment on noreturn in c_common_attribute_table. */ + if (TREE_CODE (*node) == FUNCTION_DECL) + TREE_READONLY (*node) = 1; + else if (TREE_CODE (type) == POINTER_TYPE + && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE) + TREE_TYPE (*node) + = build_pointer_type + (build_type_variant (TREE_TYPE (type), 1, + TREE_THIS_VOLATILE (TREE_TYPE (type)))); + else + gcc_unreachable (); + + return NULL_TREE; +} + +/* Handle a "pure" attribute; arguments as in + struct attribute_spec.handler. */ + +static tree +handle_pure_attribute (tree *node, tree ARG_UNUSED (name), + tree ARG_UNUSED (args), int ARG_UNUSED (flags), + bool * ARG_UNUSED (no_add_attrs)) +{ + if (TREE_CODE (*node) == FUNCTION_DECL) + DECL_PURE_P (*node) = 1; + else + gcc_unreachable (); + + return NULL_TREE; +} + +/* Handle a "nothrow" attribute; arguments as in + struct attribute_spec.handler. */ + +static tree +handle_nothrow_attribute (tree *node, tree ARG_UNUSED (name), + tree ARG_UNUSED (args), int ARG_UNUSED (flags), + bool * ARG_UNUSED (no_add_attrs)) +{ + if (TREE_CODE (*node) == FUNCTION_DECL) + TREE_NOTHROW (*node) = 1; + else + gcc_unreachable (); + + return NULL_TREE; +} + +/* Handle a "returns_twice" attribute. */ + +static tree +handle_returns_twice_attribute (tree *node, tree ARG_UNUSED (name), + tree ARG_UNUSED (args), + int ARG_UNUSED (flags), + bool * ARG_UNUSED (no_add_attrs)) +{ + gcc_assert (TREE_CODE (*node) == FUNCTION_DECL); + + DECL_IS_RETURNS_TWICE (*node) = 1; + + return NULL_TREE; +} + + /* Built-in initialization code cribbed from lto-lang.c which cribbed it from c-common.c. */ @@ -814,6 +940,10 @@ brig_langhook_init (void) #define LANG_HOOKS_GIMPLIFY_EXPR brig_langhook_gimplify_expr #define LANG_HOOKS_EH_PERSONALITY brig_langhook_eh_personality +/* Attribute hooks. */ +#undef LANG_HOOKS_COMMON_ATTRIBUTE_TABLE +#define LANG_HOOKS_COMMON_ATTRIBUTE_TABLE brig_attribute_table + struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER; #include "gt-brig-brig-lang.h" |