diff options
author | Bob Duff <duff@adacore.com> | 2020-07-14 17:10:19 -0400 |
---|---|---|
committer | Pierre-Marie de Rodat <derodat@adacore.com> | 2020-10-20 03:21:35 -0400 |
commit | 83dcc2bd35e5dc981a13959b9bb6750736cd6544 (patch) | |
tree | b2ecadbe1434218ceaec2b21a0539708482a3755 /gcc/ada/atree.ads | |
parent | 1b93e420fc10f0eaeb2b09d9b86c8defb5b459a4 (diff) | |
download | gcc-83dcc2bd35e5dc981a13959b9bb6750736cd6544.tar.gz |
[Ada] Flexible AST node structure
gcc/ada/
* atree.ads: Make Default_Node a constant. Remove the
modification of Comes_From_Source, and use a separate flag for
that. Change Sloc to 0; it always overwritten, and never left
as the No_Location value.
(Print_Statistics): Move to spec so we can call it from
gnat1drv.
(Num_Nodes): Rename to clarify that this is approximate.
Correct comment: nodes and entities are never deleted, the count
is never decremented, and this is not used by Xref.
(Initialize): Correct comment: Error_List is not created here.
Other minor naming and comment changes.
* atree.adb (Extend_Node, New_Copy, New_Entity, New_Node):
Streamline these. Simplify and improve efficiency. Move code
from Allocate_Initialize_Node to these, where it can be executed
unconditionally. Take advantage of automatic zeroing of the
Nodes table.
(Allocate_Initialize_Node): Remove this. It was an efficiency
bottleneck, and somewhat complicated, because it was called from
4 places, and had all sorts of conditionals to check where it
was called from. Better to move most of that code to the call
sites, where it can be executed (or not) unconditionally.
(Allocate_New_Node): New procedure to partly replace
Allocate_Initialize_Node (called from just 2 of those 4 places).
(Comes_From_Source_Default): New flag written/read by
Set_Comes_From_Source_Default/Get_Comes_From_Source_Default.
This allows us to make Default_Node into a constant with
all-zeros value.
(Set_Paren_Count_Of_Copy): New procedure to avoid duplicated
code.
(Report): New procedure to encapsulate the call to the reporting
procedure.
(Atree_Private_Part): We now need a body for this package, to
contain package body Nodes.
(Approx_Num_Nodes_And_Entities): Was Num_Nodes. For efficiency,
compute the answer from Nodes.Last. That way we don't need to
increment a counter on every node creation. Other minor naming
and comment changes.
* gnat1drv.adb: Call Atree.Print_Statistics if -gnatd.A switch
was given. Add comment documenting the new order dependency (we
must process the command line before calling Atree.Initialize).
* debug.adb: Document -gnatd.A.
* einfo.adb, sinfo.adb: Remove useless Style_Checks pragmas.
* nlists.ads (Allocate_List_Tables): Inline makes node creation
a little faster.
* nlists.adb (Initialize): Remove local constant E, which didn't
seem to add clarity.
* treepr.adb (Print_Init): Use renamed
Approx_Num_Nodes_And_Entities function.
* types.ads: Change the Low and High bounds as described above.
* types.h: Change Low and High bounds to match types.ads.
* sem_ch8.adb, namet.adb, namet.ads: Move the computation of
Last_Name_Id from sem_ch8 to namet, and correct it to not assume
Name_Ids are positive.
* ali.adb, ali-util.adb, bindo-writers.adb, exp_dist.adb,
fmap.adb, fname-uf.adb, osint.adb: Fix various hash functions to
avoid assuming the various ranges are positive. Note that "mod"
returns a nonnegative result when the second operand is
positive. "rem" can return negative values in that case (in
particular, if the first operand is negative, which it now is).
* switch-c.adb: Allow switch -gnaten to control the value of
Nodes_Size_In_Meg.
* doc/gnat_ugn/building_executable_programs_with_gnat.rst:
Remove traling whitespaces.
* opt.ads (Nodes_Size_In_Meg): New Variable.
Diffstat (limited to 'gcc/ada/atree.ads')
-rw-r--r-- | gcc/ada/atree.ads | 53 |
1 files changed, 27 insertions, 26 deletions
diff --git a/gcc/ada/atree.ads b/gcc/ada/atree.ads index e958a9b7af5..278753519af 100644 --- a/gcc/ada/atree.ads +++ b/gcc/ada/atree.ads @@ -70,7 +70,7 @@ package Atree is -- Currently entities are composed of 7 sequentially allocated 32-byte -- nodes, considered as a single record. The following definition gives - -- the number of extension nodes. + -- the number of extension nodes. ????We plan to change this. Num_Extension_Nodes : Node_Id := 6; -- This value is increased by one if debug flag -gnatd.N is set. This is @@ -81,6 +81,10 @@ package Atree is -- 2.01 for the nodes/entities ratio and a 2% increase in compilation time -- on average for the GCC-based compiler at -O0 on a 32-bit x86 host. + procedure Print_Statistics; + pragma Export (Ada, Print_Statistics); + -- Print various statistics on the tables maintained by the package + ---------------------------------------- -- Definitions of Fields in Tree Node -- ---------------------------------------- @@ -231,12 +235,9 @@ package Atree is function Flags_Address return System.Address; -- Return address of Flags table (used in Back_End for Gigi call) - function Num_Nodes return Nat; - -- Total number of nodes allocated, where an entity counts as a single - -- node. This count is incremented every time a node or entity is - -- allocated, and decremented every time a node or entity is deleted. - -- This value is used by Xref and by Treepr to allocate hash tables of - -- suitable size for hashing Node_Id values. + function Approx_Num_Nodes_And_Entities return Nat; + -- This is an approximation to the number of nodes and entities allocated, + -- used to determine sizes of hash tables. ----------------------- -- Use of Empty Node -- @@ -404,9 +405,8 @@ package Atree is -- place, and then for subsequent modifications as required. procedure Initialize; - -- Called at the start of compilation to initialize the allocation of - -- the node and list tables and make the standard entries for Empty, - -- Error and Error_List. + -- Called at the start of compilation to initialize the allocation of the + -- node and list tables and make the entries for Empty and Error. procedure Lock; -- Called before the back end is invoked to lock the nodes table @@ -551,7 +551,7 @@ package Atree is -- semantic chains: Homonym and Next_Entity: the corresponding links must -- be adjusted by the caller, according to context. - function Extend_Node (Node : Node_Id) return Entity_Id; + function Extend_Node (Source : Node_Id) return Entity_Id; -- This function returns a copy of its input node with an extension added. -- The fields of the extension are set to Empty. Due to the way extensions -- are handled (as four consecutive array elements), it may be necessary @@ -3843,7 +3843,8 @@ package Atree is -- Field6-11 Holds Field36-Field41 end case; - end record; + end record; -- Node_Record + pragma Suppress_Initialization (Node_Record); -- see package Nodes below pragma Pack (Node_Record); for Node_Record'Size use 8 * 32; @@ -3855,7 +3856,7 @@ package Atree is -- Default value used to initialize default nodes. Note that some of the -- fields get overwritten, and in particular, Nkind always gets reset. - Default_Node : Node_Record := ( + Default_Node : constant Node_Record := ( Is_Extension => False, Pflag1 => False, Pflag2 => False, @@ -3864,7 +3865,6 @@ package Atree is Rewrite_Ins => False, Analyzed => False, Comes_From_Source => False, - -- modified by Set_Comes_From_Source_Default Error_Posted => False, Flag4 => False, @@ -3886,7 +3886,7 @@ package Atree is Nkind => N_Unused_At_Start, - Sloc => No_Location, + Sloc => 0, Link => Empty_List_Or_Node, Field1 => Empty_List_Or_Node, Field2 => Empty_List_Or_Node, @@ -3938,17 +3938,18 @@ package Atree is Field11 => Empty_List_Or_Node, Field12 => Empty_List_Or_Node); - -- The following defines the extendable array used for the nodes table - -- Nodes with extensions use six consecutive entries in the array - - package Nodes is new Table.Table ( - Table_Component_Type => Node_Record, - Table_Index_Type => Node_Id'Base, - Table_Low_Bound => First_Node_Id, - Table_Initial => Alloc.Nodes_Initial, - Table_Increment => Alloc.Nodes_Increment, - Release_Threshold => Alloc.Nodes_Release_Threshold, - Table_Name => "Nodes"); + -- The following defines the extendable array used for the nodes table. + -- Nodes with extensions use multiple consecutive entries in the array + -- (see Num_Extension_Nodes). + + package Nodes is new Table.Table + (Table_Component_Type => Node_Record, + Table_Index_Type => Node_Id'Base, + Table_Low_Bound => First_Node_Id, + Table_Initial => Alloc.Nodes_Initial, + Table_Increment => Alloc.Nodes_Increment, + Release_Threshold => Alloc.Nodes_Release_Threshold, + Table_Name => "Nodes"); -- The following is a parallel table to Nodes, which provides 8 more -- bits of space that logically belong to the corresponding node. This |