public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Marc Poulhiès" <poulhies@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Eric Botcazou <ebotcazou@adacore.com>
Subject: [COMMITTED 19/35] ada: Minor performance improvement for dynamically-allocated controlled objects
Date: Thu, 16 May 2024 11:25:48 +0200	[thread overview]
Message-ID: <20240516092606.41242-19-poulhies@adacore.com> (raw)
In-Reply-To: <20240516092606.41242-1-poulhies@adacore.com>

From: Eric Botcazou <ebotcazou@adacore.com>

The values returned by Header_Alignment and Header_Size are known at compile
time and powers of two on almost all platforms, so inlining them by means of
an expression function improves the object code generated for alignment and
size calculations involving them.

gcc/ada/

	* libgnat/s-finpri.ads: Add use type clause for Storage_Offset.
	(Header_Alignment): Turn into an expression function.
	(Header_Size): Likewise.
	* libgnat/s-finpri.adb: Remove use type clause for Storage_Offset.
	(Header_Alignment): Delete.
	(Header_Size): Likewise.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/libgnat/s-finpri.adb | 20 --------------------
 gcc/ada/libgnat/s-finpri.ads |  8 ++++++--
 2 files changed, 6 insertions(+), 22 deletions(-)

diff --git a/gcc/ada/libgnat/s-finpri.adb b/gcc/ada/libgnat/s-finpri.adb
index 5bd8eeaea22..bd70e582de3 100644
--- a/gcc/ada/libgnat/s-finpri.adb
+++ b/gcc/ada/libgnat/s-finpri.adb
@@ -37,8 +37,6 @@ with System.Soft_Links;        use System.Soft_Links;
 
 package body System.Finalization_Primitives is
 
-   use type System.Storage_Elements.Storage_Offset;
-
    function To_Collection_Node_Ptr is
      new Ada.Unchecked_Conversion (Address, Collection_Node_Ptr);
 
@@ -389,24 +387,6 @@ package body System.Finalization_Primitives is
       end if;
    end Finalize_Object;
 
-   ----------------------
-   -- Header_Alignment --
-   ----------------------
-
-   function Header_Alignment return System.Storage_Elements.Storage_Count is
-   begin
-      return Collection_Node'Alignment;
-   end Header_Alignment;
-
-   -----------------
-   -- Header_Size --
-   -----------------
-
-   function Header_Size return System.Storage_Elements.Storage_Count is
-   begin
-      return Collection_Node'Object_Size / Storage_Unit;
-   end Header_Size;
-
    ----------------
    -- Initialize --
    ----------------
diff --git a/gcc/ada/libgnat/s-finpri.ads b/gcc/ada/libgnat/s-finpri.ads
index 468aa584958..b0b662ca39c 100644
--- a/gcc/ada/libgnat/s-finpri.ads
+++ b/gcc/ada/libgnat/s-finpri.ads
@@ -39,6 +39,8 @@ with System.Storage_Elements;
 
 package System.Finalization_Primitives with Preelaborate is
 
+   use type System.Storage_Elements.Storage_Offset;
+
    type Finalize_Address_Ptr is access procedure (Obj : System.Address);
    --  Values of this type denote finalization procedures associated with
    --  objects that have controlled parts. For convenience, such objects
@@ -168,10 +170,12 @@ package System.Finalization_Primitives with Preelaborate is
    --  Calls to the procedure with an object that has already been detached
    --  have no effects.
 
-   function Header_Alignment return System.Storage_Elements.Storage_Count;
+   function Header_Alignment return System.Storage_Elements.Storage_Count is
+     (Collection_Node'Alignment);
    --  Return the alignment of type Collection_Node as Storage_Count
 
-   function Header_Size return System.Storage_Elements.Storage_Count;
+   function Header_Size return System.Storage_Elements.Storage_Count is
+     (Collection_Node'Object_Size / Storage_Unit);
    --  Return the object size of type Collection_Node as Storage_Count
 
 private
-- 
2.43.2


  parent reply	other threads:[~2024-05-16  9:26 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-16  9:25 [COMMITTED 01/35] ada: Fix docs and comments about pragmas for Boolean-valued aspects Marc Poulhiès
2024-05-16  9:25 ` [COMMITTED 02/35] ada: Fix casing in error messages Marc Poulhiès
2024-05-16  9:25 ` [COMMITTED 03/35] ada: Fix ordering of code for pragma Preelaborable_Initialization Marc Poulhiès
2024-05-16  9:25 ` [COMMITTED 04/35] ada: Fix alphabetic ordering of aspect identifiers Marc Poulhiès
2024-05-16  9:25 ` [COMMITTED 05/35] ada: Cleanup reporting locations for Ada 2022 and GNAT extension aspects Marc Poulhiès
2024-05-16  9:25 ` [COMMITTED 06/35] ada: Reuse existing expression when rewriting aspects to pragmas Marc Poulhiès
2024-05-16  9:25 ` [COMMITTED 07/35] ada: Remove Aspect_Specifications field from N_Procedure_Specification Marc Poulhiès
2024-05-16  9:25 ` [COMMITTED 08/35] ada: Fix bug in maintaining dimension info Marc Poulhiès
2024-05-16  9:25 ` [COMMITTED 09/35] ada: Formal_Derived_Type'Size is not static Marc Poulhiès
2024-05-16  9:25 ` [COMMITTED 10/35] ada: Implement per-finalization-collection spinlocks Marc Poulhiès
2024-05-16  9:25 ` [COMMITTED 11/35] ada: Follow up fixes for Put_Image/streaming regressions Marc Poulhiès
2024-05-16  9:25 ` [COMMITTED 12/35] ada: Fix crash with -gnatdJ and -gnatw_q Marc Poulhiès
2024-05-16  9:25 ` [COMMITTED 13/35] ada: Fix casing of CUDA in error messages Marc Poulhiès
2024-05-16  9:25 ` [COMMITTED 14/35] ada: Fix bogus error on function returning noncontrolling result in private part Marc Poulhiès
2024-05-16  9:25 ` [COMMITTED 15/35] ada: Fix resolving tagged operations in array aggregates Marc Poulhiès
2024-05-16  9:25 ` [COMMITTED 16/35] ada: Fix latent alignment issue for dynamically-allocated controlled objects Marc Poulhiès
2024-05-16  9:25 ` [COMMITTED 17/35] ada: Fix typo in CUDA error message Marc Poulhiès
2024-05-16  9:25 ` [COMMITTED 18/35] ada: Fixup one more pattern of broken scope information Marc Poulhiès
2024-05-16  9:25 ` Marc Poulhiès [this message]
2024-05-16  9:25 ` [COMMITTED 20/35] ada: Fix comments about Get_Ranged_Checks Marc Poulhiès
2024-05-16  9:25 ` [COMMITTED 21/35] ada: Fix detection of if_expressions that are known on entry Marc Poulhiès
2024-05-16  9:25 ` [COMMITTED 22/35] ada: No need to follow New_Occurrence_Of with Set_Etype Marc Poulhiès
2024-05-16  9:25 ` [COMMITTED 23/35] ada: Improve recovery from illegal occurrence of 'Old in if_expression Marc Poulhiès
2024-05-16  9:25 ` [COMMITTED 24/35] ada: Propagate Program_Error from failed finalization of collection Marc Poulhiès
2024-05-16  9:25 ` [COMMITTED 25/35] ada: Fix reason code for length check Marc Poulhiès
2024-05-16  9:25 ` [COMMITTED 26/35] ada: Ignore ghost nodes in call graph information for dispatching calls Marc Poulhiès
2024-05-16  9:25 ` [COMMITTED 27/35] ada: Avoid checking parameters of protected procedures Marc Poulhiès
2024-05-16  9:25 ` [COMMITTED 28/35] ada: Fix standalone Windows builds of adaint.c Marc Poulhiès
2024-05-16  9:25 ` [COMMITTED 29/35] ada: Fix missing length checks with case expressions Marc Poulhiès
2024-05-16  9:25 ` [COMMITTED 30/35] ada: Fix reference to RM clause in comment Marc Poulhiès
2024-05-16  9:26 ` [COMMITTED 31/35] ada: Implement new experimental attribute 'Super Marc Poulhiès
2024-05-16  9:26 ` [COMMITTED 32/35] ada: Exception on Indefinite_Vector aggregate with loop_parameter_specification Marc Poulhiès
2024-05-16  9:26 ` [COMMITTED 33/35] ada: Redundant validity checks Marc Poulhiès
2024-05-16  9:26 ` [COMMITTED 34/35] ada: Reset scope of top level object declaration during unnesting Marc Poulhiès
2024-05-16  9:26 ` [COMMITTED 35/35] ada: Remove obsolete reference in comment Marc Poulhiès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240516092606.41242-19-poulhies@adacore.com \
    --to=poulhies@adacore.com \
    --cc=ebotcazou@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).