From patchwork Tue May 30 07:21:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 1787301 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=SvVi7aI3; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QVkSb6YqKz20Py for ; Tue, 30 May 2023 17:25:19 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8CC833883004 for ; Tue, 30 May 2023 07:25:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8CC833883004 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685431517; bh=PDMdN8KXy8ioJH02iZdjrhkJ+bmCKA+tOznpiCOVcko=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=SvVi7aI38fnezE5NzB8084ZTdx9ywWvS/Qz6UChi9KHleOJdK3+VDIRZvywu12rG0 TQMn89lhlhtDisph3SMWbXzosblWjmzgUe6CHs0l7kKH6vWVHoU5Ew4GJWMIEPq9e0 7OWVUgMLmvpOPSv5NlTfc4uGKrB05oz/KrNjrBpY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by sourceware.org (Postfix) with ESMTPS id 241A438532E7 for ; Tue, 30 May 2023 07:21:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 241A438532E7 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-30af20f5f67so896360f8f.1 for ; Tue, 30 May 2023 00:21:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685431273; x=1688023273; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=PDMdN8KXy8ioJH02iZdjrhkJ+bmCKA+tOznpiCOVcko=; b=gjFDrzgURFzWjCWIvb6yCbFkC3CGKaU4fj6OMbG3MBFsPYyPckUBsdYxFLOVO4rYdP 4toUXVK2NovvNFienp6aE6qLuf+vStzEpIWR/pujaPn0D+wsskMIs/uq75L0TN5ZwNzC 5lCu5G7e02c99kmRwRJR4pBa96ioz8TVeVED0qss4Etoh3p9ONo1amv2l03Q9/TJn7pr AosOr83n4j9ztOkcBEa4QBe393MolHWjGX/Gym2yrq/iKNQ99b13hCQMSeX8N23mH16e lDS+mkyTalONoVX4C8wxhCAosBIo67V9dw/vXX+3MA6BEA/87Bd2s3vKi4eCysQ8zwNf Loww== X-Gm-Message-State: AC+VfDywjah4Kw2QvfRS5WV44GcigLtj9GJ6b+tQKs300WIs8A6Efd04 VxlUU4TiFCyGoB4B8vcSirFYcHMkQVmqBrfyj1rlIA== X-Google-Smtp-Source: ACHHUZ4amdrTJOq9g7AoqsMYy1hjWivmc8i+qxhrTI31vEPDnMxxT9Ec/y0HGEwp2y+bCcmipztGqA== X-Received: by 2002:adf:e650:0:b0:309:4da8:7713 with SMTP id b16-20020adfe650000000b003094da87713mr769866wrn.64.1685431272897; Tue, 30 May 2023 00:21:12 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3382:1a90:7733:a608:a415:6b2a]) by smtp.gmail.com with ESMTPSA id w12-20020a5d544c000000b002fed865c55esm2221299wrv.56.2023.05.30.00.21.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 00:21:12 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Simplify the implementation of storage models Date: Tue, 30 May 2023 09:21:11 +0200 Message-Id: <20230530072111.2500487-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Marc_Poulhi=C3=A8s_via_Gcc-patches?= From: =?utf-8?q?Marc_Poulhi=C3=A8s?= Reply-To: =?utf-8?q?Marc_Poulhi=C3=A8s?= Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" From: Eric Botcazou As the additional temporaries required by the semantics of nonnative storage models are now created by the front-end, in particular for actual parameters and assignment statements, the corresponding code in gigi can be removed. gcc/ada/ * gcc-interface/trans.cc (Call_to_gnu): Remove code implementing the by-copy semantics for actuals with nonnative storage models. (gnat_to_gnu) : Remove code instantiating a temporary for assignments between nonnative storage models. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/gcc-interface/trans.cc | 130 +++++++-------------------------- 1 file changed, 27 insertions(+), 103 deletions(-) diff --git a/gcc/ada/gcc-interface/trans.cc b/gcc/ada/gcc-interface/trans.cc index f4a5db002f4..92c8dc33af8 100644 --- a/gcc/ada/gcc-interface/trans.cc +++ b/gcc/ada/gcc-interface/trans.cc @@ -4560,14 +4560,13 @@ elaborate_profile (Entity_Id first_formal, Entity_Id result_type) N_Assignment_Statement and the result is to be placed into that object. ATOMIC_ACCESS is the type of atomic access to be used for the assignment to GNU_TARGET. If, in addition, ATOMIC_SYNC is true, then the assignment - to GNU_TARGET requires atomic synchronization. GNAT_STORAGE_MODEL is the - storage model object to be used for the assignment to GNU_TARGET or Empty - if there is none. */ + to GNU_TARGET requires atomic synchronization. GNAT_SMO is the storage + model object to be used for the assignment to GNU_TARGET or Empty if there + is none. */ static tree Call_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, tree gnu_target, - atomic_acces_t atomic_access, bool atomic_sync, - Entity_Id gnat_storage_model) + atomic_acces_t atomic_access, bool atomic_sync, Entity_Id gnat_smo) { const bool function_call = (Nkind (gnat_node) == N_Function_Call); const bool returning_value = (function_call && !gnu_target); @@ -4599,7 +4598,6 @@ Call_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, tree gnu_target, Node_Id gnat_actual; atomic_acces_t aa_type; bool aa_sync; - Entity_Id gnat_smo; /* The only way we can make a call via an access type is if GNAT_NAME is an explicit dereference. In that case, get the list of formal args from the @@ -4751,8 +4749,8 @@ Call_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, tree gnu_target, != TYPE_SIZE (TREE_TYPE (gnu_target)) && type_is_padding_self_referential (gnu_result_type)) || (gnu_target - && Present (gnat_storage_model) - && Present (Storage_Model_Copy_To (gnat_storage_model))))) + && Present (gnat_smo) + && Present (Storage_Model_Copy_To (gnat_smo))))) { gnu_retval = create_temporary ("R", gnu_result_type); DECL_RETURN_VALUE_P (gnu_retval) = 1; @@ -4823,19 +4821,12 @@ Call_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, tree gnu_target, = build_compound_expr (TREE_TYPE (gnu_name), init, gnu_name); } - get_storage_model_access (gnat_actual, &gnat_smo); - - /* If we are passing a non-addressable actual parameter by reference, - pass the address of a copy. Likewise if it needs to be accessed with - a storage model. In the In Out or Out case, set up to copy back out - after the call. */ + /* If we are passing a non-addressable parameter by reference, pass the + address of a copy. In the In Out or Out case, set up to copy back + out after the call. */ if (is_by_ref_formal_parm && (gnu_name_type = gnat_to_gnu_type (Etype (gnat_name))) - && (!addressable_p (gnu_name, gnu_name_type) - || (Present (gnat_smo) - && (Present (Storage_Model_Copy_From (gnat_smo)) - || (!in_param - && Present (Storage_Model_Copy_To (gnat_smo))))))) + && !addressable_p (gnu_name, gnu_name_type)) { tree gnu_orig = gnu_name, gnu_temp, gnu_stmt; @@ -4906,40 +4897,21 @@ Call_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, tree gnu_target, } /* Create an explicit temporary holding the copy. */ - tree gnu_temp_type; - if (Nkind (gnat_actual) == N_Explicit_Dereference - && Present (Actual_Designated_Subtype (gnat_actual))) - gnu_temp_type - = gnat_to_gnu_type (Actual_Designated_Subtype (gnat_actual)); - else - gnu_temp_type = TREE_TYPE (gnu_name); /* Do not initialize it for the _Init parameter of an initialization procedure since no data is meant to be passed in. */ if (Ekind (gnat_formal) == E_Out_Parameter && Is_Entity_Name (gnat_subprog) && Is_Init_Proc (Entity (gnat_subprog))) - gnu_name = gnu_temp = create_temporary ("A", gnu_temp_type); + gnu_name = gnu_temp = create_temporary ("A", TREE_TYPE (gnu_name)); /* Initialize it on the fly like for an implicit temporary in the other cases, as we don't necessarily have a statement list. */ else { - if (Present (gnat_smo) - && Present (Storage_Model_Copy_From (gnat_smo))) - { - gnu_temp = create_temporary ("A", gnu_temp_type); - gnu_stmt - = build_storage_model_load (gnat_smo, gnu_temp, - gnu_name, - TYPE_SIZE_UNIT (gnu_temp_type)); - set_expr_location_from_node (gnu_stmt, gnat_actual); - } - else - gnu_temp = create_init_temporary ("A", gnu_name, &gnu_stmt, - gnat_actual); - - gnu_name = build_compound_expr (gnu_temp_type, gnu_stmt, + gnu_temp = create_init_temporary ("A", gnu_name, &gnu_stmt, + gnat_actual); + gnu_name = build_compound_expr (TREE_TYPE (gnu_name), gnu_stmt, gnu_temp); } @@ -4955,16 +4927,8 @@ Call_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, tree gnu_target, (TREE_OPERAND (TREE_OPERAND (gnu_orig, 1), 1))) gnu_orig = TREE_OPERAND (gnu_orig, 2); - if (Present (gnat_smo) - && Present (Storage_Model_Copy_To (gnat_smo))) - gnu_stmt - = build_storage_model_store (gnat_smo, gnu_orig, - gnu_temp, - TYPE_SIZE_UNIT (gnu_temp_type)); - else - gnu_stmt - = build_binary_op (MODIFY_EXPR, NULL_TREE, gnu_orig, - gnu_temp); + gnu_stmt + = build_binary_op (MODIFY_EXPR, NULL_TREE, gnu_orig, gnu_temp); set_expr_location_from_node (gnu_stmt, gnat_node); append_to_statement_list (gnu_stmt, &gnu_after_list); @@ -4975,19 +4939,12 @@ Call_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, tree gnu_target, tree gnu_actual = gnu_name; /* If atomic access is required for an In or In Out actual parameter, - build the atomic load. Or else, if storage model access is required, - build the special load. */ + build the atomic load. */ if (is_true_formal_parm && !is_by_ref_formal_parm - && Ekind (gnat_formal) != E_Out_Parameter) - { - if (simple_atomic_access_required_p (gnat_actual, &aa_sync)) - gnu_actual = build_atomic_load (gnu_actual, aa_sync); - - else if (Present (gnat_smo) - && Present (Storage_Model_Copy_From (gnat_smo))) - gnu_actual = build_storage_model_load (gnat_smo, gnu_actual); - } + && Ekind (gnat_formal) != E_Out_Parameter + && simple_atomic_access_required_p (gnat_actual, &aa_sync)) + gnu_actual = build_atomic_load (gnu_actual, aa_sync); /* If this was a procedure call, we may not have removed any padding. So do it here for the part we will use as an input, if any. */ @@ -5351,7 +5308,6 @@ Call_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, tree gnu_target, } get_atomic_access (gnat_actual, &aa_type, &aa_sync); - get_storage_model_access (gnat_actual, &gnat_smo); /* If an outer atomic access is required for an actual parameter, build the load-modify-store sequence. */ @@ -5365,13 +5321,6 @@ Call_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, tree gnu_target, gnu_result = build_atomic_store (gnu_actual, gnu_result, aa_sync); - /* Or else, if a storage model access is required, build the special - store. */ - else if (Present (gnat_smo) - && Present (Storage_Model_Copy_To (gnat_smo))) - gnu_result - = build_storage_model_store (gnat_smo, gnu_actual, gnu_result); - /* Otherwise build a regular assignment. */ else gnu_result = build_binary_op (MODIFY_EXPR, NULL_TREE, @@ -5446,11 +5395,10 @@ Call_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, tree gnu_target, = build_load_modify_store (gnu_target, gnu_call, gnat_node); else if (atomic_access == SIMPLE_ATOMIC) gnu_call = build_atomic_store (gnu_target, gnu_call, atomic_sync); - else if (Present (gnat_storage_model) - && Present (Storage_Model_Copy_To (gnat_storage_model))) + else if (Present (gnat_smo) + && Present (Storage_Model_Copy_To (gnat_smo))) gnu_call - = build_storage_model_store (gnat_storage_model, gnu_target, - gnu_call); + = build_storage_model_store (gnat_smo, gnu_target, gnu_call); else gnu_call = build_binary_op (op_code, NULL_TREE, gnu_target, gnu_call); @@ -7482,36 +7430,12 @@ gnat_to_gnu (Node_Id gnat_node) /* We obviously cannot use memset in this case. */ gcc_assert (!use_memset_p); + /* We cannot directly move between nonnative storage models. */ tree t = remove_conversions (gnu_rhs, false); + gcc_assert (TREE_CODE (t) != LOAD_EXPR); - /* If a storage model load is present on the RHS then instantiate - the temporary associated with it now, lest it be of variable - size and thus could not be instantiated by gimplification. */ - if (TREE_CODE (t) == LOAD_EXPR) - { - t = TREE_OPERAND (t, 1); - gcc_assert (TREE_CODE (t) == CALL_EXPR); - - tree elem - = build_nonstandard_integer_type (BITS_PER_UNIT, 1); - tree size = fold_convert (sizetype, CALL_EXPR_ARG (t, 3)); - tree index = build_index_type (size); - tree temp - = create_temporary ("L", build_array_type (elem, index)); - tree arg = CALL_EXPR_ARG (t, 1); - CALL_EXPR_ARG (t, 1) - = build_unary_op (ADDR_EXPR, TREE_TYPE (arg), temp); - - start_stmt_group (); - add_stmt (t); - t = build_storage_model_store (gnat_smo, gnu_lhs, temp); - add_stmt (t); - gnu_result = end_stmt_group (); - } - - else - gnu_result - = build_storage_model_store (gnat_smo, gnu_lhs, gnu_rhs); + gnu_result + = build_storage_model_store (gnat_smo, gnu_lhs, gnu_rhs); } /* Or else, use memset when the conditions are met. This has already