diff options
author | Philip Herron <philip.herron@embecosm.com> | 2022-07-21 12:07:51 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2022-08-25 12:40:25 +0100 |
commit | 4fe7b96c2726322191c0eadd2c1c712afb3d0299 (patch) | |
tree | 117f357a9849069359e7bf8d0ffe4ce56bdd3d57 /gcc/rust/backend/rust-tree.cc | |
parent | 8a9b94d8c3ac6c691fa49585756c0df234602d8b (diff) | |
download | gcc-4fe7b96c2726322191c0eadd2c1c712afb3d0299.zip gcc-4fe7b96c2726322191c0eadd2c1c712afb3d0299.tar.gz gcc-4fe7b96c2726322191c0eadd2c1c712afb3d0299.tar.bz2 |
Const functions need to be marked as DECL_DECLARED_CONSTEXPR_P
This signifys in the GCC generic that this is a constant function and
should be foldable in the constexpr evaluation. This also ports over the
correct eval_store_expression which updates the context tables.
CPP consteval seems pretty powerful but overall the algorithm is fairly
simple at least for simple types. When we encounter a CALL_EXPR we must
"bind" the arguments. So when we encourter a PARAM_DECL the associated
argument for this parameter is bound to this parameter in a map of
map<tree, tree> using their pointer as the key to value. So when folding
a function body every usage of the parameter decl is then updated in the
context with the apropriate value fomr the context. When we hit
assignment operations a similar context store occurs for VAR_DECLS.
While walking the tree We finally hit the RESULT_DECL with the folded
result. The complex pieces remaining are aggregate, record and union types
so that we have zero allocation required to find the result. We also need
to support walking conditionals and loop expressions which require porting
a few more functions and using the jump_target tree.
Diffstat (limited to 'gcc/rust/backend/rust-tree.cc')
-rw-r--r-- | gcc/rust/backend/rust-tree.cc | 54 |
1 files changed, 36 insertions, 18 deletions
diff --git a/gcc/rust/backend/rust-tree.cc b/gcc/rust/backend/rust-tree.cc index 028d88f..98c112a 100644 --- a/gcc/rust/backend/rust-tree.cc +++ b/gcc/rust/backend/rust-tree.cc @@ -2228,8 +2228,8 @@ set_array_type_canon (tree t, tree elt_type, tree index_type, bool dep) || (index_type && TYPE_CANONICAL (index_type) != index_type)) TYPE_CANONICAL (t) = build_cplus_array_type (TYPE_CANONICAL (elt_type), - index_type - ? TYPE_CANONICAL (index_type) : index_type, + index_type ? TYPE_CANONICAL (index_type) + : index_type, dep); else TYPE_CANONICAL (t) = t; @@ -2289,12 +2289,10 @@ bool is_byte_access_type (tree type) { type = TYPE_MAIN_VARIANT (type); - if (type == char_type_node - || type == unsigned_char_type_node) + if (type == char_type_node || type == unsigned_char_type_node) return true; - return (TREE_CODE (type) == ENUMERAL_TYPE - && TYPE_CONTEXT (type) == std_node + return (TREE_CODE (type) == ENUMERAL_TYPE && TYPE_CONTEXT (type) == std_node && !strcmp ("byte", TYPE_NAME_STRING (type))); } @@ -2318,8 +2316,8 @@ build_cplus_array_type (tree elt_type, tree index_type, int dependent) if (elt_type != TYPE_MAIN_VARIANT (elt_type)) /* Start with an array of the TYPE_MAIN_VARIANT. */ - t = build_cplus_array_type (TYPE_MAIN_VARIANT (elt_type), - index_type, dependent); + t = build_cplus_array_type (TYPE_MAIN_VARIANT (elt_type), index_type, + dependent); else if (dependent) { /* Since type_hash_canon calls layout_type, we need to use our own @@ -2329,14 +2327,14 @@ build_cplus_array_type (tree elt_type, tree index_type, int dependent) if (cplus_array_htab == NULL) cplus_array_htab = hash_table<cplus_array_hasher>::create_ggc (61); - + hash = TYPE_UID (elt_type); if (index_type) hash ^= TYPE_UID (index_type); cai.type = elt_type; cai.domain = index_type; - tree *e = cplus_array_htab->find_slot_with_hash (&cai, hash, INSERT); + tree *e = cplus_array_htab->find_slot_with_hash (&cai, hash, INSERT); if (*e) /* We have found the type: we're done. */ return (tree) *e; @@ -2370,8 +2368,7 @@ build_cplus_array_type (tree elt_type, tree index_type, int dependent) { tree m = t; for (t = m; t; t = TYPE_NEXT_VARIANT (t)) - if (TREE_TYPE (t) == elt_type - && TYPE_NAME (t) == NULL_TREE + if (TREE_TYPE (t) == elt_type && TYPE_NAME (t) == NULL_TREE && TYPE_ATTRIBUTES (t) == NULL_TREE) break; if (!t) @@ -2404,13 +2401,13 @@ build_cplus_array_type (tree elt_type, tree index_type, int dependent) /* Push these needs up to the ARRAY_TYPE so that initialization takes place more easily. */ - bool needs_ctor = (TYPE_NEEDS_CONSTRUCTING (t) - = TYPE_NEEDS_CONSTRUCTING (elt_type)); + bool needs_ctor + = (TYPE_NEEDS_CONSTRUCTING (t) = TYPE_NEEDS_CONSTRUCTING (elt_type)); bool needs_dtor = (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (elt_type)); - if (!dependent && t == TYPE_MAIN_VARIANT (t) - && !COMPLETE_TYPE_P (t) && COMPLETE_TYPE_P (elt_type)) + if (!dependent && t == TYPE_MAIN_VARIANT (t) && !COMPLETE_TYPE_P (t) + && COMPLETE_TYPE_P (elt_type)) { /* The element type has been completed since the last time we saw this array type; update the layout and 'tor flags for any variants @@ -2539,8 +2536,8 @@ rs_build_qualified_type_real (tree type, int type_quals, /* A restrict-qualified type must be a pointer (or reference) to object or incomplete type. */ - if ((type_quals & TYPE_QUAL_RESTRICT) - && TREE_CODE (type) != TYPENAME_TYPE && !INDIRECT_TYPE_P (type)) + if ((type_quals & TYPE_QUAL_RESTRICT) && TREE_CODE (type) != TYPENAME_TYPE + && !INDIRECT_TYPE_P (type)) { bad_quals |= TYPE_QUAL_RESTRICT; type_quals &= ~TYPE_QUAL_RESTRICT; @@ -4015,4 +4012,25 @@ require_deduced_type (tree decl, tsubst_flags_t complain) { return true; } + +/* Return the location of a tree passed to %+ formats. */ + +location_t +location_of (tree t) +{ + if (TYPE_P (t)) + { + t = TYPE_MAIN_DECL (t); + if (t == NULL_TREE) + return input_location; + } + else if (TREE_CODE (t) == OVERLOAD) + t = OVL_FIRST (t); + + if (DECL_P (t)) + return DECL_SOURCE_LOCATION (t); + + return EXPR_LOCATION (t); +} + } // namespace Rust |