From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1643) id 5D416385AE47; Mon, 29 Aug 2022 15:33:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5D416385AE47 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661787194; bh=fG1BWyllH2nFgmld6RfAboPgtx6CwqDcSPhPZpUxTv4=; h=From:To:Subject:Date:From; b=g0g3rxdPyoRMbLrSR0cJ5T8ADX/Lj5zwSMA4SL92lmH27CYLjJOawzorWEqsCaLXH CkhR5o/AFiq7V9ZhwxpbZuHAlipp2TGciK0NYl8WZ1ZUxJc8zRqfjKB6zrdntjSBYW xOnq8EvjE4db5vZyla/DK5RYpJHwhJpX+Ejbkyo4= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Thomas Schwinge To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] Port over context structures X-Act-Checkin: gcc X-Git-Author: Philip Herron X-Git-Refname: refs/heads/devel/rust/master X-Git-Oldrev: bb4dd8fbc857a78bb4bfb69f1bdfdcbd9b1b6cdb X-Git-Newrev: 44b80bf0240aefb56d9abcce59c15a24a22048f4 Message-Id: <20220829153314.5D416385AE47@sourceware.org> Date: Mon, 29 Aug 2022 15:33:14 +0000 (GMT) List-Id: https://gcc.gnu.org/g:44b80bf0240aefb56d9abcce59c15a24a22048f4 commit 44b80bf0240aefb56d9abcce59c15a24a22048f4 Author: Philip Herron Date: Wed Jul 20 13:30:56 2022 +0100 Port over context structures Diff: --- gcc/rust/backend/rust-constexpr.cc | 120 +++++++++++++++++++++++++++++++++---- 1 file changed, 107 insertions(+), 13 deletions(-) diff --git a/gcc/rust/backend/rust-constexpr.cc b/gcc/rust/backend/rust-constexpr.cc index 189badabf94..c1d5cad1448 100644 --- a/gcc/rust/backend/rust-constexpr.cc +++ b/gcc/rust/backend/rust-constexpr.cc @@ -50,31 +50,108 @@ array_index_cmp (tree key, tree index); struct constexpr_global_ctx { + /* Values for any temporaries or local variables within the + constant-expression. */ + hash_map values; + /* Number of cxx_eval_constant_expression calls (except skipped ones, + on simple constants or location wrappers) encountered during current + cxx_eval_outermost_constant_expr call. */ HOST_WIDE_INT constexpr_ops_count; - - /* Cleanups that need to be evaluated at the end of CLEANUP_POINT_EXPR. */ - vec *cleanups; /* Heap VAR_DECLs created during the evaluation of the outermost constant expression. */ auto_vec heap_vars; - constexpr_global_ctx () : constexpr_ops_count (0) {} + /* Cleanups that need to be evaluated at the end of CLEANUP_POINT_EXPR. */ + vec *cleanups; + /* Number of heap VAR_DECL deallocations. */ + unsigned heap_dealloc_count; + /* Constructor. */ + constexpr_global_ctx () + : constexpr_ops_count (0), cleanups (NULL), heap_dealloc_count (0) + {} +}; + +/* In constexpr.cc */ +/* Representation of entries in the constexpr function definition table. */ + +struct GTY ((for_user)) constexpr_fundef +{ + tree decl; + tree body; + tree parms; + tree result; +}; + +/* Objects of this type represent calls to constexpr functions + along with the bindings of parameters to their arguments, for + the purpose of compile time evaluation. */ + +struct GTY ((for_user)) constexpr_call +{ + /* Description of the constexpr function definition. */ + constexpr_fundef *fundef; + /* Parameter bindings environment. A TREE_VEC of arguments. */ + tree bindings; + /* Result of the call. + NULL means the call is being evaluated. + error_mark_node means that the evaluation was erroneous; + otherwise, the actuall value of the call. */ + tree result; + /* The hash of this call; we remember it here to avoid having to + recalculate it when expanding the hash table. */ + hashval_t hash; + /* Whether __builtin_is_constant_evaluated() should evaluate to true. */ + bool manifestly_const_eval; +}; + +struct constexpr_call_hasher : ggc_ptr_hash +{ + static hashval_t hash (constexpr_call *); + static bool equal (constexpr_call *, constexpr_call *); +}; + +enum constexpr_switch_state +{ + /* Used when processing a switch for the first time by cxx_eval_switch_expr + and default: label for that switch has not been seen yet. */ + css_default_not_seen, + /* Used when processing a switch for the first time by cxx_eval_switch_expr + and default: label for that switch has been seen already. */ + css_default_seen, + /* Used when processing a switch for the second time by + cxx_eval_switch_expr, where default: label should match. */ + css_default_processing }; struct constexpr_ctx { /* The part of the context that needs to be unique to the whole - cxx_eval_outermost_constant_expr invocation. */ + cxx_eval_outermost_constant_expr invocation. */ constexpr_global_ctx *global; - - /* Whether we should error on a non-constant expression or fail quietly. - This flag needs to be here, but some of the others could move to global - if they get larger than a word. */ - bool quiet; - /* The object we're building the CONSTRUCTOR for. */ - tree object; + /* The innermost call we're evaluating. */ + constexpr_call *call; + /* SAVE_EXPRs and TARGET_EXPR_SLOT vars of TARGET_EXPRs that we've seen + within the current LOOP_EXPR. NULL if we aren't inside a loop. */ + vec *save_exprs; /* The CONSTRUCTOR we're currently building up for an aggregate initializer. */ tree ctor; + /* The object we're building the CONSTRUCTOR for. */ + tree object; + /* If inside SWITCH_EXPR. */ + constexpr_switch_state *css_state; + /* The aggregate initialization context inside which this one is nested. This + is used by lookup_placeholder to resolve PLACEHOLDER_EXPRs. */ + const constexpr_ctx *parent; + + /* Whether we should error on a non-constant expression or fail quietly. + This flag needs to be here, but some of the others could move to global + if they get larger than a word. */ + bool quiet; + /* Whether we are strictly conforming to constant expression rules or + trying harder to get a constant value. */ + bool strict; + /* Whether __builtin_is_constant_evaluated () should be true. */ + bool manifestly_const_eval; }; static tree @@ -105,17 +182,34 @@ eval_binary_expression (const constexpr_ctx *ctx, tree r, bool, bool *, bool *); static tree get_function_named_in_call (tree t); +// this is ported from cxx_eval_outermost_constant_expr tree fold_expr (tree expr) { + bool allow_non_constant = false; + bool strict = true; + bool manifestly_const_eval = false; + constexpr_global_ctx global_ctx; - constexpr_ctx ctx = {&global_ctx, false}; + constexpr_ctx ctx + = {&global_ctx, NULL, + NULL, NULL, + NULL, NULL, + NULL, allow_non_constant, + strict, manifestly_const_eval || !allow_non_constant}; + + auto_vec cleanups; + global_ctx.cleanups = &cleanups; + bool non_constant_p = false; bool overflow_p = false; tree folded = constexpr_expression (&ctx, expr, false, &non_constant_p, &overflow_p); rust_assert (folded != NULL_TREE); + + // more logic here to possibly port + return folded; }