From: Pierre-Marie de Rodat <derodat@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Eric Botcazou <ebotcazou@adacore.com>
Subject: [Ada] Adjust expansion of perfect hash function for Value
Date: Wed, 5 May 2021 04:20:04 -0400 [thread overview]
Message-ID: <20210505082004.GA31203@adacore.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 375 bytes --]
This moves the declaration of the 4 tables to inside the function itself
for reasons explained in the code.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* exp_imgv.ads (Build_Enumeration_Image_Tables): Adjust comment.
* exp_imgv.adb (Build_Enumeration_Image_Tables): Add the
declaration nodes of the 4 tables to the declaration list of the
function body.
[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 4541 bytes --]
diff --git a/gcc/ada/exp_imgv.adb b/gcc/ada/exp_imgv.adb
--- a/gcc/ada/exp_imgv.adb
+++ b/gcc/ada/exp_imgv.adb
@@ -304,6 +304,11 @@ package body Exp_Imgv is
-- named P, T1, T2 and G are needed. The hash function is of the form
-- function Hash (S : String) return Natural is
+ -- xxxP : constant array (0 .. X) of Natural = [...];
+ -- xxxT1 : constant array (0 .. Y) of Index_Type = [...];
+ -- xxxT2 : constant array (0 .. Y) of Index_Type = [...];
+ -- xxxG : constant array (0 .. Z) of Index_Type = [...];
+
-- F : constant Natural := S'First - 1;
-- L : constant Natural := S'Length;
-- A, B : Natural := 0;
@@ -320,7 +325,13 @@ package body Exp_Imgv is
-- return (Natural (G (A)) + Natural (G (B))) mod M;
-- end Hash;
- -- where N is the length of G and M the number of literals.
+ -- where N is the length of G and M the number of literals. Note that
+ -- we declare the tables inside the function for two reasons: first,
+ -- their analysis creates array subtypes and thus their concatenation
+ -- operators which are homonyms of the concatenation operator and may
+ -- change the homonym number of user operators declared in the scope;
+ -- second, the code generator can fold the values in the tables when
+ -- they are small and avoid emitting them in the final object code.
if H_OK then
declare
@@ -336,6 +347,8 @@ package body Exp_Imgv is
Loop_Stmts : List_Id;
begin
+ Body_Decls := New_List;
+
-- Generate position table
SPHG.Define (SPHG.Character_Position, Siz, L1, L2);
@@ -350,7 +363,7 @@ package body Exp_Imgv is
Chars => New_External_Name (Chars (E), 'P'));
Append_Table_To
- (Act, EPos, Nat (L1 - 1), Standard_Natural, Pos);
+ (Body_Decls, EPos, Nat (L1 - 1), Standard_Natural, Pos);
-- Generate function table 1
@@ -367,7 +380,7 @@ package body Exp_Imgv is
Ityp :=
Small_Integer_Type_For (UI_From_Int (Int (Siz)), Uns => True);
- Append_Table_To (Act, ET1, Nat (L1 - 1), Ityp, T1);
+ Append_Table_To (Body_Decls, ET1, Nat (L1 - 1), Ityp, T1);
-- Generate function table 2
@@ -384,7 +397,7 @@ package body Exp_Imgv is
Ityp :=
Small_Integer_Type_For (UI_From_Int (Int (Siz)), Uns => True);
- Append_Table_To (Act, ET2, Nat (L1 - 1), Ityp, T2);
+ Append_Table_To (Body_Decls, ET2, Nat (L1 - 1), Ityp, T2);
-- Generate graph table
@@ -401,13 +414,11 @@ package body Exp_Imgv is
Ityp :=
Small_Integer_Type_For (UI_From_Int (Int (Siz)), Uns => True);
- Append_Table_To (Act, EG, Nat (L1 - 1), Ityp, G);
-
- -- Generate body of hash function
+ Append_Table_To (Body_Decls, EG, Nat (L1 - 1), Ityp, G);
F := Make_Temporary (Loc, 'F');
- Body_Decls := New_List (
+ Append_To (Body_Decls,
Make_Object_Declaration (Loc,
Defining_Identifier => F,
Object_Definition =>
diff --git a/gcc/ada/exp_imgv.ads b/gcc/ada/exp_imgv.ads
--- a/gcc/ada/exp_imgv.ads
+++ b/gcc/ada/exp_imgv.ads
@@ -70,14 +70,8 @@ package Exp_Imgv is
--
-- If the number of enumeration literals is large enough, a (perfect) hash
-- function mapping the literals to their position number is also built and
- -- requires in turn to build four additional tables:
- --
- -- xxxP : constant array (0 .. X - 1) of Natural = (p1, p2, ..., pX);
- -- xxxT1 : constant array (0 .. Y - 1) of Index_Type = (q1, ..., qY);
- -- xxxT2 : constant array (0 .. Y - 1) of Index_Type = (r1, ..., rY);
- -- xxxG : constant array (0 .. Z - 1) of Index_Type = (s1, ..., sZ);
- --
- -- See the System.Perfect_Hash_Generators unit for a complete description.
+ -- requires additional tables. See the System.Perfect_Hash_Generators unit
+ -- for a complete description of this processing.
procedure Expand_Image_Attribute (N : Node_Id);
-- This procedure is called from Exp_Attr to expand an occurrence of the
reply other threads:[~2021-05-05 8:20 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20210505082004.GA31203@adacore.com \
--to=derodat@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).