diff options
author | Bob Duff <duff@adacore.com> | 2021-08-09 19:06:18 -0400 |
---|---|---|
committer | Pierre-Marie de Rodat <derodat@adacore.com> | 2021-10-01 06:13:36 +0000 |
commit | a6fe12b0a9a375e655945ff385810661d8bb494c (patch) | |
tree | 56f4b101a3296d6c88ae641309ba536ebbd728be /gcc/ada/atree.adb | |
parent | e0ab2003576fd34f37afbf5cd39d714b261f3f05 (diff) | |
download | gcc-a6fe12b0a9a375e655945ff385810661d8bb494c.zip gcc-a6fe12b0a9a375e655945ff385810661d8bb494c.tar.gz gcc-a6fe12b0a9a375e655945ff385810661d8bb494c.tar.bz2 |
[Ada] Info. gathering in preparation for more efficiency improvements
gcc/ada/
* atree.adb: Gather and print statistics about frequency of
getter and setter calls.
* atree.ads (Print_Statistics): New procedure for printing
statistics.
* debug.adb: Document -gnatd.A switch.
* gen_il-gen.adb: Generate code for statistics gathering.
Choose the offset of Homonym early. Misc cleanup. Put more
comments in the generated code.
* gen_il-internals.ads (Unknown_Offset): New value to indicate
that the offset has not yet been chosen.
* gnat1drv.adb: Call Print_Statistics.
* libgnat/s-imglli.ads: Minor comment fix.
* output.ads (Write_Int_64): New procedure to write a 64-bit
value. Needed for new statistics, and could come in handy
elsewhere.
* output.adb (Write_Int_64): Likewise.
* sinfo.ads: Remove obsolete comment. The xtreeprs program no
longer exists.
* types.ads: New 64-bit types needed for new statistics.
Diffstat (limited to 'gcc/ada/atree.adb')
-rw-r--r-- | gcc/ada/atree.adb | 73 |
1 files changed, 70 insertions, 3 deletions
diff --git a/gcc/ada/atree.adb b/gcc/ada/atree.adb index e7fa8e0..5af4b13 100644 --- a/gcc/ada/atree.adb +++ b/gcc/ada/atree.adb @@ -211,6 +211,10 @@ package body Atree is (Old_N : Entity_Id; New_Kind : Entity_Kind); -- Above are the same as the ones for nodes, but for entities + procedure Update_Kind_Statistics (Field : Node_Or_Entity_Field); + -- Increment Set_Count (Field). This is in a procedure so we can put it in + -- pragma Debug for efficiency. + procedure Init_Nkind (N : Node_Id; Val : Node_Kind); -- Initialize the Nkind field, which must not have been set already. This -- cannot be used to modify an already-initialized Nkind field. See also @@ -905,7 +909,7 @@ package body Atree is Old_Kind : constant Node_Kind := Nkind (Old_N); -- If this fails, it means you need to call Reinit_Field_To_Zero before - -- calling Set_Nkind. + -- calling Mutate_Nkind. begin for J in Node_Field_Table (Old_Kind)'Range loop @@ -970,11 +974,17 @@ package body Atree is Nkind_Offset : constant Field_Offset := Field_Descriptors (F_Nkind).Offset; + procedure Update_Kind_Statistics (Field : Node_Or_Entity_Field) is + begin + Set_Count (Field) := Set_Count (Field) + 1; + end Update_Kind_Statistics; + procedure Set_Node_Kind_Type is new Set_8_Bit_Field (Node_Kind) with Inline; procedure Init_Nkind (N : Node_Id; Val : Node_Kind) is pragma Assert (Field_Is_Initial_Zero (N, F_Nkind)); begin + pragma Debug (Update_Kind_Statistics (F_Nkind)); Set_Node_Kind_Type (N, Nkind_Offset, Val); end Init_Nkind; @@ -1017,6 +1027,7 @@ package body Atree is Zero_Dynamic_Slots (Off_F (N) + Old_Size, Slots.Last); end if; + pragma Debug (Update_Kind_Statistics (F_Nkind)); Set_Node_Kind_Type (N, Nkind_Offset, Val); pragma Debug (Validate_Node_Write (N)); @@ -1049,6 +1060,7 @@ package body Atree is -- For now, we are allocating all entities with the same size, so we -- don't need to reallocate slots here. + pragma Debug (Update_Kind_Statistics (F_Ekind)); Set_Entity_Kind_Type (N, Ekind_Offset, Val); pragma Debug (Validate_Node_Write (N)); @@ -1535,8 +1547,7 @@ package body Atree is for J in Fields'Range loop declare use Seinfo; - Desc : Field_Descriptor renames - Field_Descriptors (Fields (J)); + Desc : Field_Descriptor renames Field_Descriptors (Fields (J)); begin if Desc.Kind in Node_Id_Field | List_Id_Field then Fix_Parent (Get_Node_Field_Union (Fix_Node, Desc.Offset)); @@ -2477,4 +2488,60 @@ package body Atree is Zero_Header_Slots (N); end Zero_Slots; + ---------------------- + -- Print_Statistics -- + ---------------------- + + procedure Print_Statistics is + Total, G_Total, S_Total : Call_Count := 0; + begin + Write_Line ("Frequency of field getter and setter calls:"); + + for Field in Node_Or_Entity_Field loop + G_Total := G_Total + Get_Count (Field); + S_Total := S_Total + Set_Count (Field); + Total := G_Total + S_Total; + end loop; + + Write_Int_64 (Total); + Write_Str (" (100%) = "); + Write_Int_64 (G_Total); + Write_Str (" + "); + Write_Int_64 (S_Total); + Write_Line (" total getter and setter calls"); + + for Field in Node_Or_Entity_Field loop + declare + G : constant Call_Count := Get_Count (Field); + S : constant Call_Count := Set_Count (Field); + GS : constant Call_Count := G + S; + + Percent : constant Int := + Int ((Long_Float (GS) / Long_Float (Total)) * 100.0); + + use Seinfo; + Desc : Field_Descriptor renames Field_Descriptors (Field); + Slot : constant Field_Offset := + (Field_Size (Desc.Kind) * Desc.Offset) / Slot_Size; + + begin + Write_Int_64 (GS); + Write_Str (" ("); + Write_Int (Percent); + Write_Str ("%)"); + Write_Str (" = "); + Write_Int_64 (G); + Write_Str (" + "); + Write_Int_64 (S); + Write_Str (" "); + Write_Str (Node_Or_Entity_Field'Image (Field)); + Write_Str (" in slot "); + Write_Int (Int (Slot)); + Write_Str (" size "); + Write_Int (Int (Field_Size (Desc.Kind))); + Write_Eol; + end; + end loop; + end Print_Statistics; + end Atree; |