From patchwork Tue Dec 3 10:06:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 1203589 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-515039-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="lO+q9qvS"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47RyLm43sKz9s4Y for ; Tue, 3 Dec 2019 21:06:38 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=N2jBJ7roolZoYuaF NMF4Y1RddPUZb8ulyORBjrWZ7wpmpDx/2P+UtbuJ4SdaxtGyf98grbCO7wuWY1w4 Fn0ENQNe2dZ21YFBAsVE+ZXnPhmrOw/mb1CdRVNl2OJNiJSvKPRwo4PrWE4tz4Tz XEalLCcDeJSSm+LXckhf+ZkOWaE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=7kQNyuE29C9TsPrrpP5T3l J6xz8=; b=lO+q9qvSdCL6hGTT4TQEVu2OE3tezQQ0A8hPUlX59xkP/xpWt2fhjJ WXLUmAYVhg2DqhSfHghi9HlE5Gdbh6fL+8gIi+2dMNIbRACRQglwIqMdjOb55NVO aSUvegY49tKnHcwLsxZZRZcHpJ5LsE2tshGT9dlVm/w13pZy9mev4= Received: (qmail 34568 invoked by alias); 3 Dec 2019 10:06:30 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 34307 invoked by uid 89); 3 Dec 2019 10:06:30 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: smtp.eu.adacore.com Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 03 Dec 2019 10:06:28 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 8447A8137E for ; Tue, 3 Dec 2019 11:06:25 +0100 (CET) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id XyNUKoQ1VYj7 for ; Tue, 3 Dec 2019 11:06:25 +0100 (CET) Received: from polaris.localnet (unknown [IPv6:2a01:e0a:41b:9230:1a03:73ff:fe45:373a]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id 5E6188137C for ; Tue, 3 Dec 2019 11:06:25 +0100 (CET) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [Ada] Adjust Copy-In/Copy-Out mechanism on 64-bit targets Date: Tue, 03 Dec 2019 11:06:23 +0100 Message-ID: <3128935.At6jULYyoa@polaris> MIME-Version: 1.0 This adjusts the return part of the mechanism used to pass In Out or Out parameters on 64-bit targets to avoid generating problematic paradoxical subregs with floating-point mode. Tested on x86_64-suse-linux, applied on the mainline. 2019-12-03 Eric Botcazou * gcc-interface/decl.c (gnat_to_gnu_subprog_type): With the Copy-In/ Copy-Out mechanism, do not promote the mode of the return type to an integral mode if it contains a field on a non-integral type and even demote it for 64-bit targets. Index: gcc-interface/decl.c =================================================================== --- gcc-interface/decl.c (revision 277906) +++ gcc-interface/decl.c (working copy) @@ -5620,6 +5620,32 @@ gnat_to_gnu_profile_type (Entity_Id gnat return gnu_type; } +/* Return true if TYPE contains only integral data, recursively if need be. */ + +static bool +type_contains_only_integral_data (tree type) +{ + switch (TREE_CODE (type)) + { + case RECORD_TYPE: + case UNION_TYPE: + case QUAL_UNION_TYPE: + for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) + if (!type_contains_only_integral_data (TREE_TYPE (field))) + return false; + return true; + + case ARRAY_TYPE: + case COMPLEX_TYPE: + return type_contains_only_integral_data (TREE_TYPE (type)); + + default: + return INTEGRAL_TYPE_P (type); + } + + gcc_unreachable (); +} + /* Return a GCC tree for a subprogram type corresponding to GNAT_SUBPROG. DEFINITION is true if this is for a subprogram being defined. DEBUG_INFO_P is true if we need to write debug information for other types that we may @@ -5649,8 +5675,8 @@ gnat_to_gnu_subprog_type (Entity_Id gnat the TYPE_CI_CO_LIST field of the FUNCTION_TYPE node we create. */ tree gnu_cico_list = NULL_TREE; tree gnu_cico_return_type = NULL_TREE; - /* Fields in return type of procedure with copy-in copy-out parameters. */ - tree gnu_field_list = NULL_TREE; + tree gnu_cico_field_list = NULL_TREE; + bool gnu_cico_only_integral_type = true; /* The semantics of "pure" in Ada essentially matches that of "const" or "pure" in GCC. In particular, both properties are orthogonal to the "nothrow" property if the EH circuitry is explicit in the @@ -5976,9 +6002,11 @@ gnat_to_gnu_subprog_type (Entity_Id gnat NULL_TREE, 0, 0); Sloc_to_locus (Sloc (gnat_subprog), &DECL_SOURCE_LOCATION (gnu_field)); - gnu_field_list = gnu_field; + gnu_cico_field_list = gnu_field; gnu_cico_list = tree_cons (gnu_field, void_type_node, NULL_TREE); + if (!type_contains_only_integral_data (gnu_return_type)) + gnu_cico_only_integral_type = false; } TYPE_NAME (gnu_cico_return_type) = get_identifier ("RETURN"); @@ -5995,9 +6023,11 @@ gnat_to_gnu_subprog_type (Entity_Id gnat 0, 0); Sloc_to_locus (Sloc (gnat_param), &DECL_SOURCE_LOCATION (gnu_field)); - DECL_CHAIN (gnu_field) = gnu_field_list; - gnu_field_list = gnu_field; + DECL_CHAIN (gnu_field) = gnu_cico_field_list; + gnu_cico_field_list = gnu_field; gnu_cico_list = tree_cons (gnu_field, gnu_param, gnu_cico_list); + if (!type_contains_only_integral_data (gnu_param_type)) + gnu_cico_only_integral_type = false; } } @@ -6014,12 +6044,14 @@ gnat_to_gnu_subprog_type (Entity_Id gnat since structures are incomplete for the back-end. */ else if (Convention (gnat_subprog) != Convention_Stubbed) { - finish_record_type (gnu_cico_return_type, nreverse (gnu_field_list), + finish_record_type (gnu_cico_return_type, + nreverse (gnu_cico_field_list), 0, false); - /* Try to promote the mode of the return type if it is passed - in registers, again to speed up accesses. */ + /* Try to promote the mode if the return type is fully returned + in integer registers, again to speed up accesses. */ if (TYPE_MODE (gnu_cico_return_type) == BLKmode + && gnu_cico_only_integral_type && !targetm.calls.return_in_memory (gnu_cico_return_type, NULL_TREE)) { @@ -6042,6 +6074,17 @@ gnat_to_gnu_subprog_type (Entity_Id gnat } } + /* But demote the mode if the return type is partly returned in FP + registers to avoid creating problematic paradoxical subregs. + Note that we need to cater to historical 32-bit architectures + that incorrectly use the mode to select the return mechanism. */ + else if (INTEGRAL_MODE_P (TYPE_MODE (gnu_cico_return_type)) + && !gnu_cico_only_integral_type + && BITS_PER_WORD >= 64 + && !targetm.calls.return_in_memory (gnu_cico_return_type, + NULL_TREE)) + SET_TYPE_MODE (gnu_cico_return_type, BLKmode); + if (debug_info_p) rest_of_record_type_compilation (gnu_cico_return_type); }