ada: Inline composite node kind AST queries
authorPiotr Trojanek <trojanek@adacore.com>
Mon, 17 Oct 2022 14:28:20 +0000 (16:28 +0200)
committerMarc Poulhiès <poulhies@adacore.com>
Mon, 7 Nov 2022 08:36:34 +0000 (09:36 +0100)
Queries that ultimately examine the same field of an AST
node (e.g. Nkind) are visibly more efficient when inlined.

In particular, routines Is_Body_Or_Package_Declaration and Is_Body can
apparently be inlined into a single Nkind membership test.

This patch fixes some of the performance lost with the recent changes,
which increased the number of calls to Is_Body_Or_Package_Declaration
(as it is typically used to prevent AST search from climbing too far).
However, it should be generally beneficial to inline routines like this.

gcc/ada/

* sem_aux.ads (Is_Body): Annotate with Inline.
* sem_util.ads (Is_Body_Or_Package_Declaration): Likewise.

gcc/ada/sem_aux.ads
gcc/ada/sem_util.ads

index 66cbcfb..004aadb 100644 (file)
@@ -279,7 +279,7 @@ package Sem_Aux is
    --  or subtype. This is true if Suppress_Initialization is set either for
    --  the subtype itself, or for the corresponding base type.
 
-   function Is_Body (N : Node_Id) return Boolean;
+   function Is_Body (N : Node_Id) return Boolean with Inline;
    --  Determine whether an arbitrary node denotes a body
 
    function Is_By_Copy_Type (Ent : Entity_Id) return Boolean;
index 5c08cb8..2126bed 100644 (file)
@@ -1881,7 +1881,8 @@ package Sem_Util is
    function Is_Attribute_Update (N : Node_Id) return Boolean;
    --  Determine whether node N denotes attribute 'Update
 
-   function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean;
+   function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean
+     with Inline;
    --  Determine whether node N denotes a body or a package declaration
 
    function Is_Bounded_String (T : Entity_Id) return Boolean;