Commit 9098d477 by Hristian Kirtchev Committed by Pierre-Marie de Rodat

[Ada] Elaboration order v4.0 and cycle detection

This patch introduces a new cycle detection algorithm which is based on
Tarjan's "Enumeration of the Elementary Circuits of a Directed Graph"
algorithm, with several ideas borrowed from Jonson's "Finding all the
Elementary Circuits of a Directed Graph" algorithm.

No need for a test because the new algorithm improves the performance of
cycle detection only.

2019-07-10  Hristian Kirtchev  <kirtchev@adacore.com>

gcc/ada/

	* bindo.adb: Update the section on switches.
	* bindo-graphs.adb
	(Add_Cycle, Add_Vertex_And_Complement): Remove.
	(Create): The graph no longer needs a set of recorded cycles
	because the cycles are not rediscovered in permuted forms.
	(Cycle_End_Vertices): New routine.
	(Destroy): The graph no longer needs a set of recorded cycles
	because the cycles are not rediscovered in permuted forms.
	(Destroy_Library_Graph_Vertex): Move to the library level.
	(Find_All_Cycles_Through_Vertex, Find_All_Cycles_With_Edge):
	Remove.
	(Find_Cycles_From_Successor, Find_Cycles_From_Vertex,
	Find_Cycles_In_Component, Has_Elaborate_All_Edge): New routines.
	(Insert_And_Sort): Remove.
	(Is_Elaborate_Body_Edge): Use predicate
	Is_Vertex_With_Elaborate_Body.
	(Is_Recorded_Cycle): Remove.
	(Is_Vertex_With_Elaborate_Body): New routine.
	(Normalize_And_Add_Cycle): Remove.
	(Precedence): Rename to xxx_Precedence, where xxx relates to the
	input.  These versions better reflect the desired input
	precedence.
	(Record_Cycle): New routine.
	(Remove_Vertex_And_Complement, Set_Is_Recorded_Cycle): Remove.
	(Trace_xxx): Update all versions to use debug switch -d_t.
	(Trace_Component): New routine.
	(Trace_Eol): Removed.
	(Trace_Vertex): Do not output the component as this information
	is already available when the component is traced.
	(Unvisit, Visit): New routine.
	* bindo-graphs.ads: Add new instance LGV_Lists.  Remove instance
	RC_Sets.  Update the structure of type Library_Graph_Attributes
	to remove the set of recorded cycles.
	(Destroy_Library_Graph_Vertex): Move to the library level.
	* bindo-writers.adb (Write_Component_Vertices): Output
	information about the number of vertices.
	* debug.adb: Document the use of binder switch -d_t.  Update the
	use of binder switch -d_T.

From-SVN: r273330
parent 74b96685
2019-07-10 Hristian Kirtchev <kirtchev@adacore.com>
* bindo.adb: Update the section on switches.
* bindo-graphs.adb
(Add_Cycle, Add_Vertex_And_Complement): Remove.
(Create): The graph no longer needs a set of recorded cycles
because the cycles are not rediscovered in permuted forms.
(Cycle_End_Vertices): New routine.
(Destroy): The graph no longer needs a set of recorded cycles
because the cycles are not rediscovered in permuted forms.
(Destroy_Library_Graph_Vertex): Move to the library level.
(Find_All_Cycles_Through_Vertex, Find_All_Cycles_With_Edge):
Remove.
(Find_Cycles_From_Successor, Find_Cycles_From_Vertex,
Find_Cycles_In_Component, Has_Elaborate_All_Edge): New routines.
(Insert_And_Sort): Remove.
(Is_Elaborate_Body_Edge): Use predicate
Is_Vertex_With_Elaborate_Body.
(Is_Recorded_Cycle): Remove.
(Is_Vertex_With_Elaborate_Body): New routine.
(Normalize_And_Add_Cycle): Remove.
(Precedence): Rename to xxx_Precedence, where xxx relates to the
input. These versions better reflect the desired input
precedence.
(Record_Cycle): New routine.
(Remove_Vertex_And_Complement, Set_Is_Recorded_Cycle): Remove.
(Trace_xxx): Update all versions to use debug switch -d_t.
(Trace_Component): New routine.
(Trace_Eol): Removed.
(Trace_Vertex): Do not output the component as this information
is already available when the component is traced.
(Unvisit, Visit): New routine.
* bindo-graphs.ads: Add new instance LGV_Lists. Remove instance
RC_Sets. Update the structure of type Library_Graph_Attributes
to remove the set of recorded cycles.
(Destroy_Library_Graph_Vertex): Move to the library level.
* bindo-writers.adb (Write_Component_Vertices): Output
information about the number of vertices.
* debug.adb: Document the use of binder switch -d_t. Update the
use of binder switch -d_T.
2019-07-10 Yannick Moy <moy@adacore.com>
* sem_spark.adb (Get_Root_Object): Replace precondition by error
......
......@@ -174,6 +174,11 @@ package Bindo.Graphs is
First_Library_Graph_Vertex : constant Library_Graph_Vertex_Id :=
No_Library_Graph_Vertex + 1;
procedure Destroy_Library_Graph_Vertex
(Vertex : in out Library_Graph_Vertex_Id);
pragma Inline (Destroy_Library_Graph_Vertex);
-- Destroy library graph vertex Vertex
function Hash_Library_Graph_Vertex
(Vertex : Library_Graph_Vertex_Id) return Bucket_Range_Type;
pragma Inline (Hash_Library_Graph_Vertex);
......@@ -183,6 +188,11 @@ package Bindo.Graphs is
pragma Inline (Present);
-- Determine whether library graph vertex Vertex exists
package LGV_Lists is new Doubly_Linked_Lists
(Element_Type => Library_Graph_Vertex_Id,
"=" => "=",
Destroy_Element => Destroy_Library_Graph_Vertex);
package LGV_Sets is new Membership_Sets
(Element_Type => Library_Graph_Vertex_Id,
"=" => "=",
......@@ -1406,11 +1416,6 @@ package Bindo.Graphs is
-- Vertices --
--------------
procedure Destroy_Library_Graph_Vertex
(Vertex : in out Library_Graph_Vertex_Id);
pragma Inline (Destroy_Library_Graph_Vertex);
-- Destroy library graph vertex Vertex
-- The following type represents the attributes of a library graph
-- vertex.
......@@ -1593,15 +1598,6 @@ package Bindo.Graphs is
Destroy_Value => Destroy_Library_Graph_Cycle_Attributes,
Hash => Hash_Library_Graph_Cycle);
---------------------
-- Recorded cycles --
---------------------
package RC_Sets is new Membership_Sets
(Element_Type => Library_Graph_Cycle_Attributes,
"=" => Same_Library_Graph_Cycle_Attributes,
Hash => Hash_Library_Graph_Cycle_Attributes);
--------------------
-- Recorded edges --
--------------------
......@@ -1693,10 +1689,6 @@ package Bindo.Graphs is
-- The underlying graph describing the relations between edges and
-- vertices.
Recorded_Cycles : RC_Sets.Membership_Set := RC_Sets.Nil;
-- The set of recorded cycles, used to prevent duplicate cycles in
-- the graph.
Recorded_Edges : RE_Sets.Membership_Set := RE_Sets.Nil;
-- The set of recorded edges, used to prevent duplicate edges in the
-- graph.
......
......@@ -1102,6 +1102,8 @@ package body Bindo.Writers is
Write_Eol;
Write_Component_Vertices (G, Comp);
Write_Eol;
end Write_Component;
------------------------------
......@@ -1112,25 +1114,34 @@ package body Bindo.Writers is
(G : Library_Graph;
Comp : Component_Id)
is
pragma Assert (Present (G));
pragma Assert (Present (Comp));
Num_Of_Vertices : constant Natural :=
Number_Of_Component_Vertices (G, Comp);
Iter : Component_Vertex_Iterator;
Vertex : Library_Graph_Vertex_Id;
begin
pragma Assert (Present (G));
pragma Assert (Present (Comp));
Write_Str (" Vertices: ");
Write_Int (Int (Num_Of_Vertices));
Write_Eol;
Iter := Iterate_Component_Vertices (G, Comp);
while Has_Next (Iter) loop
Next (Iter, Vertex);
if Num_Of_Vertices > 0 then
Iter := Iterate_Component_Vertices (G, Comp);
while Has_Next (Iter) loop
Next (Iter, Vertex);
Write_Str (" library graph vertex (LGV_Id_");
Write_Int (Int (Vertex));
Write_Str (") name = ");
Write_Name (Name (G, Vertex));
Write_Str (" library graph vertex (LGV_Id_");
Write_Int (Int (Vertex));
Write_Str (") name = ");
Write_Name (Name (G, Vertex));
Write_Eol;
end loop;
else
Write_Eol;
end loop;
Write_Eol;
end if;
end Write_Component_Vertices;
----------------------
......
......@@ -322,6 +322,11 @@ package body Bindo is
-- In addition, GNATbind does not create an edge to the body of the
-- pragma argument.
--
-- -d_t Output cycle detection trace information
--
-- GNATbind outputs trace information on cycle detection activities
-- to standard output.
--
-- -d_A Output ALI invocation tables
--
-- GNATbind outputs the contents of ALI table Invocation_Constructs
......@@ -352,8 +357,8 @@ package body Bindo is
--
-- -d_T Output elaboration-order trace information
--
-- GNATbind outputs trace information on elaboration-order and cycle-
-- detection activities to standard output.
-- GNATbind outputs trace information on elaboration-order detection
-- activities to standard output.
--
-- -d_V Validate bindo cycles, graphs, and order
--
......@@ -395,7 +400,7 @@ package body Bindo is
-- number of files in the bind, Bindo may emit anywhere between several MBs
-- to several hundred MBs of data to standard output. The switches are:
--
-- -d_A -d_C -d_I -d_L -d_P -d_T -d_V
-- -d_A -d_C -d_I -d_L -d_P -d_t -d_T -d_V
--
-- Bindo offers several debugging routines that can be invoked from gdb.
-- Those are defined in the body of Bindo.Writers, in sections denoted by
......
......@@ -368,7 +368,7 @@ package body Debug is
-- d_q
-- d_r
-- d_s
-- d_t
-- d_t Output cycle detection trace information
-- d_u
-- d_v
-- d_w
......@@ -380,6 +380,7 @@ package body Debug is
-- d_B
-- d_C Diagnose all cycles
-- d_D
-- d_E
-- d_F
-- d_G
-- d_H
......@@ -394,7 +395,7 @@ package body Debug is
-- d_Q
-- d_R
-- d_S
-- d_T Output elaboration order and cycle detection trace information
-- d_T Output elaboration order trace information
-- d_U
-- d_V Validate bindo cycles, graphs, and order
-- d_W
......@@ -1149,6 +1150,9 @@ package body Debug is
-- elaboration order and no longer creates an implicit dependency on
-- the body of the argument.
-- d_t GNATBIND output trace information of cycle detection activities to
-- standard output.
-- d_A GNATBIND output the contents of all ALI invocation-related tables
-- in textual format to standard output.
......@@ -1163,8 +1167,8 @@ package body Debug is
-- d_P GNATBIND outputs the cycle paths to standard output
-- d_T GNATBIND outputs trace information of elaboration order and cycle
-- detection activities to standard output.
-- d_T GNATBIND outputs trace information of elaboration order detection
-- activities to standard output.
-- d_V GNATBIND validates the invocation graph, library graph along with
-- its cycles, and the elaboration order.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment