From patchwork Tue Dec 19 14:30:30 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: 82488 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AE1E13881875 for ; Tue, 19 Dec 2023 14:30:50 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id C60B4386D625 for ; Tue, 19 Dec 2023 14:30:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C60B4386D625 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C60B4386D625 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702996234; cv=none; b=Xps/SPFwPjQt+0F2hkMyEg1gQYyA7N+jUxGmU0Lcb0Gwz0XRT3RQkEiLNoryzSxcKMafN4HxI00nq9mL6STSW2tS+KcItsV1o9NaTjvv6qpThQtyzexBj2NyJYXidp21Yi2YreBBDjBuoRK9sxm8pgP2zVegNp6mExzxtA6+hqo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702996234; c=relaxed/simple; bh=5RaqjU2QPGXOgzaQol2t8GGgIKQV1ZCQTV0PU5SzUtU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=VMhMcyFpms9SGHCj/MaEPbr2VwshigR0CdD3cPkC/VlnbzsFHcoP77M2zythUYn6VKAt/XBljfvCkfCzdQqgZ3TqV0NrakTa06CpGmX/DA1BANE3aRUYWbSTGegQa3dkT8M9XhKD8w8w6QNpN6p7NdBmDgX8+nfGoXLCx/QPkQU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-33660cf2296so3611440f8f.3 for ; Tue, 19 Dec 2023 06:30:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1702996231; x=1703601031; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=C22juWb7JQN+Cxo7ugpwQs+Tr9U9nqyLzLvUuaPWBYw=; b=UPyO1plLZIqtwBH2IJ2K3x5loqN3++rsIqr4yMCty1m732DfuwybD1kskSl30h884D CmpG8AeZqoQ9XX675BBxe6xCYZlpe8kq0QBD4bCRxmu7IOjfkZwIBQDHxGNVX/GZ9/6S ZP8sy14GaY+ydRok1sswDLV24C8W1S9yXj8bNUG+Nn3ZFH6Bls+8UOH65W/3RMDig9xE lL+cCZoELYHf/KvaYoJlGs83ctcvcCdmvdCpAdBjHD1F+S8UpVYuI/XcFxWR4JuPqiQn LMdVjOtagp+zqGBhZ0hS26FGJMIhgVG9EMrZhGH0X7EgwqGDdguo+ckczp35/2MLvOSx KEtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702996231; x=1703601031; 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=C22juWb7JQN+Cxo7ugpwQs+Tr9U9nqyLzLvUuaPWBYw=; b=aeyAinVxjljJaxZ31PKYtmpowBXj5RdmiBBESVos3Hbq+gVM1Eo9VEaRKgHvX/Y6Sk QY4P8VnErv+AkOqWcdDpE6ESTYnvfYt8jGoEmDAVS2RcAqwmTDp0YfabANzo8sizEzxL XEIfQ8AIKYi5d1l9LYUmg70HqihsJhmjaHM6AVvNMtngV9sIE6/k9qo2PI0o5RQlv42w UCbmFfwKIHSFJjvH8wNRevgp8mequmdAkXZ2nH2VSbQUnACwzZG+SzgRMHPfzGciOKHA 7A5t8kwEWOzCu9/8SL5Gu1/m1i/xGdJmvuwsKMc4alYnEE4sED1qkW0iwrr1PKu9dv95 puaA== X-Gm-Message-State: AOJu0YyNPJkd6Ka3f87s0HochReJY/wSwXUG/J+AB88z/yNU9DN7xfY9 /+VGRf74GuPaj3T7zkq6uYZAWc7qdrr+8ZZZRPo= X-Google-Smtp-Source: AGHT+IEPd5UziH0oy8/FhlR+v5oX9xtCfHD60tttGxnk4mB/ABwACjnP9/IPM9PmUH38/GWaPGD4PA== X-Received: by 2002:a5d:52cd:0:b0:333:26aa:d598 with SMTP id r13-20020a5d52cd000000b0033326aad598mr9837939wrv.39.1702996231535; Tue, 19 Dec 2023 06:30:31 -0800 (PST) Received: from poulhies-Precision-5550.lan ([2001:861:3382:1a90:fe1e:443:c34f:edaa]) by smtp.gmail.com with ESMTPSA id c11-20020adfef4b000000b003366f4406f6sm2677608wrp.97.2023.12.19.06.30.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 06:30:31 -0800 (PST) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Ronan Desplanques Subject: [COMMITTED] ada: Restore object constraint optimization Date: Tue, 19 Dec 2023 15:30:30 +0100 Message-ID: <20231219143030.454782-1-poulhies@adacore.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org From: Ronan Desplanques This patch relaxes the requirement that discriminants values should be known at compile time for a particular optimization to be applied. That optimization is the one that treats an unconstrained object as constrained when the object is of a limited type, in order to reduce the size of the object. What makes it possible to relax this requirement is that the set of cases where the optimization is applied was narrowed in a previous patch. gcc/ada/ * sem_util.adb (Build_Default_Subtype_OK): Relax known-at-compile-time requirement. * sem_util.ads (Build_Default_Subtype_OK): Bring documentation comment up-to-date. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_util.adb | 57 -------------------------------------------- gcc/ada/sem_util.ads | 11 ++++----- 2 files changed, 5 insertions(+), 63 deletions(-) diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index 909f93da040..2a31a11f9a2 100644 --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -1813,51 +1813,6 @@ package body Sem_Util is ------------------------------ function Build_Default_Subtype_OK (T : Entity_Id) return Boolean is - - function Default_Discriminant_Values_Known_At_Compile_Time - (T : Entity_Id) return Boolean; - -- For an unconstrained type T, return False if the given type has a - -- discriminant with default value not known at compile time. Return - -- True otherwise. - - --------------------------------------------------------- - -- Default_Discriminant_Values_Known_At_Compile_Time -- - --------------------------------------------------------- - - function Default_Discriminant_Values_Known_At_Compile_Time - (T : Entity_Id) return Boolean - is - Discr : Entity_Id; - DDV : Node_Id; - - begin - - -- If the type has no discriminant, we know them all at compile time - - if not Has_Discriminants (T) then - return True; - end if; - - -- The type has discriminants, check that none of them has a default - -- value not known at compile time. - - Discr := First_Discriminant (T); - - while Present (Discr) loop - DDV := Discriminant_Default_Value (Discr); - - if Present (DDV) and then not Compile_Time_Known_Value (DDV) then - return False; - end if; - - Next_Discriminant (Discr); - end loop; - - return True; - end Default_Discriminant_Values_Known_At_Compile_Time; - - -- Start of processing for Build_Default_Subtype_OK - begin if Is_Constrained (T) then @@ -1867,18 +1822,6 @@ package body Sem_Util is return False; end if; - if not Default_Discriminant_Values_Known_At_Compile_Time (T) then - - -- This is a special case of definite subtypes. To allocate a - -- specific size to the subtype, we need to know the value at compile - -- time. This might not be the case if the default value is the - -- result of a function. In that case, the object might be definite - -- and limited but the needed size might not be statically known or - -- too tricky to obtain. In that case, we will not build the subtype. - - return False; - end if; - return Is_Definite_Subtype (T) and then Is_Inherently_Limited_Type (T); end Build_Default_Subtype_OK; diff --git a/gcc/ada/sem_util.ads b/gcc/ada/sem_util.ads index 081217a455a..2dc75a1387f 100644 --- a/gcc/ada/sem_util.ads +++ b/gcc/ada/sem_util.ads @@ -282,14 +282,13 @@ package Sem_Util is -- subtype. Otherwise, simply return T. function Build_Default_Subtype_OK (T : Entity_Id) return Boolean; - -- When analyzing components or object declarations, it is possible, in - -- some cases, to build subtypes for discriminated types. This is - -- worthwhile to avoid the backend allocating the maximum possible size for - -- objects of the type. + -- When analyzing object declarations, it is possible, in some cases, to + -- build subtypes for discriminated types. This is worthwhile to avoid the + -- backend allocating the maximum possible size for objects of the type. -- In particular, when T is limited, the discriminants and therefore the -- size of an object of type T cannot change. Furthermore, if T is definite - -- with statically initialized defaulted discriminants, we are able and - -- want to build a constrained subtype of the right size. + -- with initialized defaulted discriminants, we are able and want to build + -- a constrained subtype of the right size. function Build_Discriminal_Subtype_Of_Component (T : Entity_Id) return Node_Id;