[m-rev.] for review: Reorganise dependency graph code

Paul Bone paul at bone.id.au
Wed Feb 15 22:15:03 AEDT 2017


For review by Zoltan.

Hi Zoltan, This is some of the work I had done to move generic parts of
hlds_dependency_graph.m into dependency_graph.m.  Even if we don't create
a dependency graph module form the MLDS I think this is still an improvement.

Thanks.

---

Reorganise dependency graph code

This change moves code that could be generic/common out of
hlds_dependency_graph.m into dependency_graph.m.  It also moves some code
from hlds_module.m into hlds_dependency_graph.m where it makes more sense.

compiler/dependency_graph.m:
    New module.

    Make the accessors predicates functions and give them more sensible
    names.

    Create a new accessors to get a version or the dependency ordering,
    condensed into a single list.

compiler/hlds_dependency_graph.m:
    Build the dependency_info structure in a more straightforward way.  It
    can easily be created with a single call rather than three.  The
    dependency ordering information is now calculated by dependency_graph.m.

    Make build_dependency_graph, build_proc_dependency_graph and
    build_pred_dependency_graph functions rather than predicates.

compiler/hlds_module.m:
    As above.

compiler/closure_analysis.m:
compiler/deep_profiling.m:
compiler/deforest.m:
compiler/dep_par_conj.m:
compiler/exception_analysis.m:
compiler/granularity.m:
compiler/hlds_dependency_graph.m:
compiler/inlining.m:
compiler/lco.m:
compiler/libs.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mode_constraints.m:
compiler/par_loop_control.m:
compiler/rbmm.interproc_region_lifetime.m:
compiler/rbmm.points_to_analysis.m:
compiler/stratify.m:
compiler/structure_reuse.indirect.m:
compiler/structure_sharing.analysis.m:
compiler/tabling_analysis.m:
compiler/term_constr_build.m:
compiler/term_constr_main.m:
compiler/termination.m:
compiler/trailing_analysis.m:
compiler/tupling.m:
    Conform to changes.
---
 compiler/closure_analysis.m               |   3 +-
 compiler/deep_profiling.m                 |   3 +-
 compiler/deforest.m                       |   4 +-
 compiler/dep_par_conj.m                   |   3 +-
 compiler/dependency_graph.m               | 101 ++++++++++++++++++++++++++++
 compiler/exception_analysis.m             |   3 +-
 compiler/granularity.m                    |   3 +-
 compiler/hlds_dependency_graph.m          | 105 +++++++++++++++---------------
 compiler/hlds_module.m                    |  67 ++-----------------
 compiler/inlining.m                       |   4 +-
 compiler/lco.m                            |   3 +-
 compiler/libs.m                           |   1 +
 compiler/mercury_compile_llds_back_end.m  |   9 +--
 compiler/mode_constraints.m               |   9 +--
 compiler/par_loop_control.m               |  14 ++--
 compiler/rbmm.interproc_region_lifetime.m |   7 +-
 compiler/rbmm.points_to_analysis.m        |   6 +-
 compiler/stratify.m                       |  12 ++--
 compiler/structure_reuse.indirect.m       |   5 +-
 compiler/structure_sharing.analysis.m     |   3 +-
 compiler/tabling_analysis.m               |   3 +-
 compiler/term_constr_build.m              |   4 +-
 compiler/term_constr_main.m               |   7 +-
 compiler/termination.m                    |   3 +-
 compiler/trailing_analysis.m              |   3 +-
 compiler/tupling.m                        |  15 +++--
 26 files changed, 235 insertions(+), 165 deletions(-)
 create mode 100644 compiler/dependency_graph.m

diff --git a/compiler/closure_analysis.m b/compiler/closure_analysis.m
index 363a42c..aa94d42 100644
--- a/compiler/closure_analysis.m
+++ b/compiler/closure_analysis.m
@@ -44,6 +44,7 @@
 :- import_module hlds.passes_aux.
 :- import_module hlds.vartypes.
 :- import_module libs.
+:- import_module libs.dependency_graph.
 :- import_module libs.globals.
 :- import_module libs.options.
 :- import_module parse_tree.
@@ -74,7 +75,7 @@ closure_analyse_module(!ModuleInfo, !IO) :-
     globals.lookup_bool_option(Globals, debug_closure, Debug),
     module_info_ensure_dependency_info(!ModuleInfo),
     module_info_dependency_info(!.ModuleInfo, DepInfo),
-    hlds_dependency_info_get_dependency_ordering(DepInfo, SCCs),
+    SCCs = dependency_info_get_ordering(DepInfo),
     list.foldl2(closure_analyse_scc(Debug), SCCs, !ModuleInfo, !IO).
 
 %----------------------------------------------------------------------------%
diff --git a/compiler/deep_profiling.m b/compiler/deep_profiling.m
index e3c167e..e47d335 100644
--- a/compiler/deep_profiling.m
+++ b/compiler/deep_profiling.m
@@ -67,6 +67,7 @@
 :- import_module hlds.make_goal.
 :- import_module hlds.pred_table.
 :- import_module libs.
+:- import_module libs.dependency_graph.
 :- import_module libs.file_util.
 :- import_module libs.globals.
 :- import_module libs.options.
@@ -129,7 +130,7 @@ apply_deep_profiling_transform(!ModuleInfo) :-
 apply_deep_prof_tail_rec_transform(!ModuleInfo) :-
     module_info_ensure_dependency_info(!ModuleInfo),
     module_info_dependency_info(!.ModuleInfo, DepInfo),
-    hlds_dependency_info_get_dependency_ordering(DepInfo, SCCs),
+    SCCs = dependency_info_get_ordering(DepInfo),
     list.foldl(apply_deep_prof_tail_rec_transform_to_scc, SCCs, !ModuleInfo).
 
 :- pred apply_deep_prof_tail_rec_transform_to_scc(list(pred_proc_id)::in,
diff --git a/compiler/deforest.m b/compiler/deforest.m
index 48277e0..acc3341 100644
--- a/compiler/deforest.m
+++ b/compiler/deforest.m
@@ -64,6 +64,7 @@
 :- import_module hlds.quantification.
 :- import_module hlds.vartypes.
 :- import_module libs.
+:- import_module libs.dependency_graph.
 :- import_module libs.globals.
 :- import_module libs.options.
 :- import_module mdbcomp.
@@ -121,8 +122,7 @@ deforestation(!ModuleInfo) :-
     % also to avoid redoing optimizations.
     module_info_ensure_dependency_info(!ModuleInfo),
     module_info_dependency_info(!.ModuleInfo, DepInfo),
-    hlds_dependency_info_get_dependency_ordering(DepInfo, DepOrdering),
-    list.condense(DepOrdering, DepList),
+    DepList = dependency_info_get_condensed_ordering(DepInfo),
 
     pd_info_init(!.ModuleInfo, ProcArgInfo, PDInfo0),
     list.foldl(deforest_proc, DepList, PDInfo0, PDInfo),
diff --git a/compiler/dep_par_conj.m b/compiler/dep_par_conj.m
index 3ddec79..9d127a1 100644
--- a/compiler/dep_par_conj.m
+++ b/compiler/dep_par_conj.m
@@ -146,6 +146,7 @@
 :- import_module hlds.status.
 :- import_module hlds.vartypes.
 :- import_module libs.
+:- import_module libs.dependency_graph.
 :- import_module libs.globals.
 :- import_module libs.options.
 :- import_module mdbcomp.
@@ -1341,7 +1342,7 @@ insert_signal_in_cases(ModuleInfo, FutureMap, ProducedVar,
 reorder_indep_par_conj(PredProcId, VarTypes, InstMapBefore, Conjuncts0,
         GoalInfo, Goal, !ModuleInfo) :-
     module_info_dependency_info(!.ModuleInfo, DependencyInfo),
-    hlds_dependency_info_get_dependency_ordering(DependencyInfo, Ordering),
+    Ordering = dependency_info_get_ordering(DependencyInfo),
     search_scc(Ordering, PredProcId, SCC),
     CallsToSameSCC = goal_list_calls_proc_in_list(Conjuncts0, SCC),
     (
diff --git a/compiler/dependency_graph.m b/compiler/dependency_graph.m
new file mode 100644
index 0000000..4a93321
--- /dev/null
+++ b/compiler/dependency_graph.m
@@ -0,0 +1,101 @@
+%-----------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et
+%-----------------------------------------------------------------------%
+% Copyright (C) 2017 The Mercury Team.
+% This file may only be copied under the terms of the GNU General
+% Public License - see the file COPYING in the Mercury distribution.
+%-----------------------------------------------------------------------%
+%
+% File: dependency_graph.m.
+%
+% These are generic types and predicates for managing a dependency graph.
+% hlds.dependency_graph.m and mlds.dependency_graph.m make use of them.
+%
+% A dependency_graph records which procedures depend on which other
+% procedures. It is defined as a digraph (see hlds_module.m) R where
+% edge x -> y means that the definition of x depends on the definition of y.
+% Imported procedures are not normally included in a dependency_graph
+% (although opt_imported procedures are included).
+%
+% The other important structure is the dependency_ordering which is
+% a list of the cliques (strongly-connected components) of this graph,
+% in topological order. This is very handy for doing fixpoint iterations.
+%
+%-----------------------------------------------------------------------%
+
+:- module libs.dependency_graph.
+:- interface.
+
+:- import_module digraph.
+:- import_module list.
+
+%-----------------------------------------------------------------------%
+
+    % A dependency ordering gives the list of SCCs of the module. The list
+    % is in ascending order: the lowest SCC is first, the highest SCC is last.
+:- type dependency_ordering(T)  == list(list(T)).
+
+:- type dependency_graph(T)     == digraph(T).
+
+:- type dependency_graph_key(T) == digraph_key(T).
+
+:- type dependency_info(T).
+
+%-----------------------------------------------------------------------%
+
+:- func make_dependency_info(digraph(T)) = dependency_info(T).
+
+%-----------------------------------------------------------------------%
+
+:- func dependency_info_get_graph(dependency_info(T)) = dependency_graph(T).
+
+:- func dependency_info_get_ordering(dependency_info(T)) =
+    dependency_ordering(T).
+
+    % Same as the above, except all the nodes are condensed into a single
+    % list.  This is useful when processing them in order is important, but
+    % processing whole SCCs or knowing the SCC boundaries is not.
+    %
+:- func dependency_info_get_condensed_ordering(dependency_info(T)) = list(T).
+
+%-----------------------------------------------------------------------%
+%-----------------------------------------------------------------------%
+
+:- implementation.
+
+:- import_module set.
+
+%-----------------------------------------------------------------------%
+
+:- type dependency_info(T)
+    --->    dependency_info(
+                dep_graph       :: dependency_graph(T),
+                dep_ord         :: dependency_ordering(T)
+            ).
+
+make_dependency_info(Graph) = dependency_info(Graph, Ordering) :-
+    digraph.atsort(Graph, Ordering0),
+    sets_to_lists(Ordering0, [], Ordering).
+
+:- pred sets_to_lists(list(set(T))::in, list(list(T))::in,
+    list(list(T))::out) is det.
+
+sets_to_lists([], Xs, Xs).
+sets_to_lists([X | Xs], Ys, Zs) :-
+    set.to_sorted_list(X, Y),
+    sets_to_lists(Xs, [Y | Ys], Zs).
+
+%-----------------------------------------------------------------------%
+
+dependency_info_get_graph(DepInfo) = DepInfo ^ dep_graph.
+
+    % TODO: These could be improved to reduce the amount of intermedediate
+    % structures created.
+    %
+dependency_info_get_ordering(DepInfo) = DepInfo ^ dep_ord.
+
+dependency_info_get_condensed_ordering(DepInfo) =
+    list.condense(dependency_info_get_ordering(DepInfo)).
+
+%-----------------------------------------------------------------------%
+%-----------------------------------------------------------------------%
diff --git a/compiler/exception_analysis.m b/compiler/exception_analysis.m
index a15244d..08cb981 100644
--- a/compiler/exception_analysis.m
+++ b/compiler/exception_analysis.m
@@ -128,6 +128,7 @@
 :- import_module hlds.hlds_goal.
 :- import_module hlds.vartypes.
 :- import_module libs.
+:- import_module libs.dependency_graph.
 :- import_module libs.globals.
 :- import_module libs.op_mode.
 :- import_module libs.options.
@@ -157,7 +158,7 @@
 analyse_exceptions_in_module(!ModuleInfo) :-
     module_info_ensure_dependency_info(!ModuleInfo),
     module_info_dependency_info(!.ModuleInfo, DepInfo),
-    hlds_dependency_info_get_dependency_ordering(DepInfo, SCCs),
+    SCCs = dependency_info_get_ordering(DepInfo),
     list.foldl(check_scc_for_exceptions, SCCs, !ModuleInfo),
 
     module_info_get_proc_analysis_kinds(!.ModuleInfo, ProcAnalysisKinds0),
diff --git a/compiler/granularity.m b/compiler/granularity.m
index dda17ba..554b420 100644
--- a/compiler/granularity.m
+++ b/compiler/granularity.m
@@ -40,6 +40,7 @@
 :- import_module hlds.pred_table.
 :- import_module hlds.quantification.
 :- import_module libs.
+:- import_module libs.dependency_graph.
 :- import_module libs.globals.
 :- import_module mdbcomp.
 :- import_module mdbcomp.builtin_modules.
@@ -59,7 +60,7 @@
 
 control_granularity(!ModuleInfo) :-
     module_info_rebuild_dependency_info(!ModuleInfo, DepInfo),
-    hlds_dependency_info_get_dependency_ordering(DepInfo, SCCs),
+    SCCs = dependency_info_get_ordering(DepInfo),
     list.foldl(runtime_granularity_test_in_scc, SCCs, !ModuleInfo).
 
 :- pred runtime_granularity_test_in_scc(list(pred_proc_id)::in,
diff --git a/compiler/hlds_dependency_graph.m b/compiler/hlds_dependency_graph.m
index db32f74..e21d29c 100644
--- a/compiler/hlds_dependency_graph.m
+++ b/compiler/hlds_dependency_graph.m
@@ -10,14 +10,12 @@
 % File: hlds_dependency_graph.m.
 % Main authors: bromage, conway, stayl.
 %
-% The dependency_graph records which procedures depend on which other
-% procedures. It is defined as a digraph (see hlds_module.m) R where
-% edge x -> y means that the definition of x depends on the definition of y.
-% Note that imported procedures are not included in the dependency_graph
-% (although opt_imported procedures are included).
+% This dependency graph is based on the one in dependency_graph.m, it is
+% specialised for the HLDS.  Note that imported procedures are not included
+% in the dependency_graph (although opt_imported procedures are included).
 %
 % The other important structure is the dependency_ordering which is
-% a list of the cliques (strongly-connected components) of this graph,
+% a list of the SCCs (strongly-connected components) of this graph,
 % in topological order. This is very handy for doing fixpoint iterations.
 %
 %-----------------------------------------------------------------------------%
@@ -27,10 +25,20 @@
 
 :- import_module hlds.hlds_module.
 :- import_module hlds.hlds_pred.
+:- import_module libs.
+:- import_module libs.dependency_graph.
 
 :- import_module io.
 :- import_module list.
 
+%---------------------------------------------------------------------------%
+
+:- type hlds_dependency_info        == dependency_info(pred_proc_id).
+
+:- type hlds_dependency_ordering    == dependency_ordering(pred_proc_id).
+:- type hlds_dependency_graph       == dependency_graph(pred_proc_id).
+:- type hlds_dependency_graph_key   == dependency_graph_key(pred_proc_id).
+
 %-----------------------------------------------------------------------------%
 
     % Ensure that the module_info contains a version of the dependency_info
@@ -47,21 +55,21 @@
     % dependency_info will be up-to-date.
     %
 :- pred module_info_rebuild_dependency_info(module_info::in, module_info::out,
-    dependency_info(pred_proc_id)::out) is det.
+    hlds_dependency_info::out) is det.
 
 :- type include_imported
     --->    include_imported
     ;       do_not_include_imported.
 
-    % Build the dependency graph of procedures.
+    % Build the dependency graph of predicates.
     %
-:- pred build_pred_dependency_graph(module_info::in, list(pred_id)::in,
-    include_imported::in, dependency_info(pred_id)::out) is det.
+:- func build_pred_dependency_graph(module_info, list(pred_id),
+    include_imported) = dependency_info(pred_id).
 
-    % Build the dependency graph of predicates.
+    % Build the dependency graph of procedures.
     %
-:- pred build_proc_dependency_graph(module_info::in, list(pred_id)::in,
-    include_imported::in, dependency_info(pred_proc_id)::out) is det.
+:- func build_proc_dependency_graph(module_info, list(pred_id),
+    include_imported) = dependency_info(pred_proc_id).
 
     % Output a form of the static call graph to a file, in a format suitable
     % for use in .dependency_info files. After the heading, the format of
@@ -85,8 +93,9 @@
     % and a module_info, find out which members of the SCC can be
     % called from outside the SCC.
     %
-:- pred get_scc_entry_points(list(pred_proc_id)::in, dependency_ordering::in,
-    module_info::in, list(pred_proc_id)::out) is det.
+:- pred get_scc_entry_points(list(pred_proc_id)::in,
+    hlds_dependency_ordering::in, module_info::in,
+    list(pred_proc_id)::out) is det.
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
@@ -126,47 +135,34 @@ module_info_ensure_dependency_info(!ModuleInfo) :-
     ;
         MaybeDepInfo = no,
         module_info_get_valid_pred_ids(!.ModuleInfo, PredIds),
-        build_dependency_graph(!.ModuleInfo, PredIds, do_not_include_imported,
-            DepInfo),
+        DepInfo = build_dependency_graph(!.ModuleInfo, PredIds,
+            do_not_include_imported),
         module_info_set_dependency_info(DepInfo, !ModuleInfo)
     ).
 
 module_info_rebuild_dependency_info(!ModuleInfo, DepInfo) :-
     module_info_get_valid_pred_ids(!.ModuleInfo, PredIds),
-    build_dependency_graph(!.ModuleInfo, PredIds, do_not_include_imported,
-        DepInfo),
+    DepInfo = build_dependency_graph(!.ModuleInfo, PredIds,
+        do_not_include_imported),
     module_info_set_dependency_info(DepInfo, !ModuleInfo).
 
-build_proc_dependency_graph(ModuleInfo, PredIds, Imported, DepInfo) :-
-    build_dependency_graph(ModuleInfo, PredIds, Imported, DepInfo).
+build_proc_dependency_graph(ModuleInfo, PredIds, Imported) =
+    build_dependency_graph(ModuleInfo, PredIds, Imported).
 
-build_pred_dependency_graph(ModuleInfo, PredIds, Imported, DepInfo) :-
-    build_dependency_graph(ModuleInfo, PredIds, Imported, DepInfo).
+build_pred_dependency_graph(ModuleInfo, PredIds, Imported) =
+    build_dependency_graph(ModuleInfo, PredIds, Imported).
 
     % Traverse the module structure, calling `add_dependency_arcs'
     % for each procedure body.
     %
-:- pred build_dependency_graph(module_info::in, list(pred_id)::in,
-    include_imported::in, dependency_info(T)::out) is det
-    <= dependency_node(T).
+:- func build_dependency_graph(module_info, list(pred_id),
+    include_imported) = dependency_info(T) <= dependency_node(T).
 
-build_dependency_graph(ModuleInfo, PredIds, Imported, !:DepInfo) :-
+build_dependency_graph(ModuleInfo, PredIds, Imported) = DepInfo :-
     digraph.init(DepGraph0),
     add_dependency_nodes(PredIds, ModuleInfo, Imported, DepGraph0, DepGraph1),
     add_dependency_arcs(PredIds, ModuleInfo, Imported, DepGraph1, DepGraph),
-    hlds_dependency_info_init(!:DepInfo),
-    hlds_dependency_info_set_dependency_graph(DepGraph, !DepInfo),
-    digraph.atsort(DepGraph, DepOrd0),
-    sets_to_lists(DepOrd0, [], DepOrd),
-    hlds_dependency_info_set_dependency_ordering(DepOrd, !DepInfo).
-
-:- pred sets_to_lists(list(set(T))::in, list(list(T))::in,
-    list(list(T))::out) is det.
-
-sets_to_lists([], Xs, Xs).
-sets_to_lists([X | Xs], Ys, Zs) :-
-    set.to_sorted_list(X, Y),
-    sets_to_lists(Xs, [Y | Ys], Zs).
+    DepInfo = make_dependency_info(DepGraph).
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
@@ -199,7 +195,9 @@ sets_to_lists([X | Xs], Ys, Zs) :-
 %-----------------------------------------------------------------------------%
 
 :- pred add_pred_proc_nodes(list(pred_id)::in, module_info::in,
-    include_imported::in, dependency_graph::in, dependency_graph::out) is det.
+    include_imported::in,
+    dependency_graph(pred_proc_id)::in, dependency_graph(pred_proc_id)::out)
+    is det.
 
 add_pred_proc_nodes([], _ModuleInfo, _, !DepGraph).
 add_pred_proc_nodes([PredId | PredIds], ModuleInfo, Imported, !DepGraph) :-
@@ -217,8 +215,9 @@ add_pred_proc_nodes([PredId | PredIds], ModuleInfo, Imported, !DepGraph) :-
     add_proc_nodes(ProcIds, PredId, ModuleInfo, !DepGraph),
     add_pred_proc_nodes(PredIds, ModuleInfo, Imported, !DepGraph).
 
-:- pred add_proc_nodes(list(proc_id)::in, pred_id::in,
-    module_info::in, dependency_graph::in, dependency_graph::out) is det.
+:- pred add_proc_nodes(list(proc_id)::in, pred_id::in, module_info::in,
+    dependency_graph(pred_proc_id)::in, dependency_graph(pred_proc_id)::out)
+    is det.
 
 add_proc_nodes([], _PredId, _ModuleInfo, !DepGraph).
 add_proc_nodes([ProcId | ProcIds], PredId, ModuleInfo, !DepGraph) :-
@@ -251,7 +250,9 @@ add_pred_nodes([PredId | PredIds], ModuleInfo, IncludeImported, !DepGraph) :-
 %-----------------------------------------------------------------------------%
 
 :- pred add_pred_proc_arcs(list(pred_id)::in, module_info::in,
-    include_imported::in, dependency_graph::in, dependency_graph::out) is det.
+    include_imported::in,
+    dependency_graph(pred_proc_id)::in, dependency_graph(pred_proc_id)::out)
+    is det.
 
 add_pred_proc_arcs([], _ModuleInfo, _, !DepGraph).
 add_pred_proc_arcs([PredId | PredIds], ModuleInfo, Imported, !DepGraph) :-
@@ -270,7 +271,9 @@ add_pred_proc_arcs([PredId | PredIds], ModuleInfo, Imported, !DepGraph) :-
     add_pred_proc_arcs(PredIds, ModuleInfo, Imported, !DepGraph).
 
 :- pred add_proc_arcs(list(proc_id)::in, pred_id::in, module_info::in,
-    include_imported::in, dependency_graph::in, dependency_graph::out) is det.
+    include_imported::in,
+    dependency_graph(pred_proc_id)::in, dependency_graph(pred_proc_id)::out)
+    is det.
 
 add_proc_arcs([], _PredId, _ModuleInfo, _, !DepGraph).
 add_proc_arcs([ProcId | ProcIds], PredId, ModuleInfo, IncludeImported,
@@ -528,18 +531,16 @@ write_scc(ModuleInfo, [PredProcId | PredProcIds], !IO) :-
 write_prof_dependency_graph(!ModuleInfo, !IO) :-
     module_info_ensure_dependency_info(!ModuleInfo),
     module_info_dependency_info(!.ModuleInfo, DepInfo),
-    hlds_dependency_info_get_dependency_graph(DepInfo, DepGraph),
-    digraph.traverse(DepGraph, write_empty_node,
-        write_prof_dep_graph_link(!.ModuleInfo), !IO).
+    digraph.traverse(dependency_info_get_graph(DepInfo),
+        write_empty_node, write_prof_dep_graph_link(!.ModuleInfo), !IO).
 
 write_dependency_graph(!ModuleInfo, !IO) :-
     module_info_ensure_dependency_info(!ModuleInfo),
     module_info_dependency_info(!.ModuleInfo, DepInfo),
     io.write_string("% Dependency graph\n", !IO),
     io.write_string("\n\n% Dependency ordering\n", !IO),
-    hlds_dependency_info_get_dependency_graph(DepInfo, DepGraph),
-    digraph.traverse(DepGraph, write_empty_node,
-        write_dep_graph_link(!.ModuleInfo), !IO).
+    digraph.traverse(dependency_info_get_graph(DepInfo),
+        write_empty_node, write_dep_graph_link(!.ModuleInfo), !IO).
 
 :- pred write_empty_node(pred_proc_id::in, io::di, io::uo) is det.
 
@@ -608,7 +609,7 @@ is_entry_point(HigherSCCs, ModuleInfo, PredProcId) :-
     ;
         % Is the predicate called from a higher SCC?
         module_info_dependency_info(ModuleInfo, DepInfo),
-        hlds_dependency_info_get_dependency_graph(DepInfo, DepGraph),
+        DepGraph = dependency_info_get_graph(DepInfo),
 
         digraph.lookup_key(DepGraph, PredProcId, PredProcIdKey),
         digraph.lookup_to(DepGraph, PredProcIdKey, CallingKeys),
diff --git a/compiler/hlds_module.m b/compiler/hlds_module.m
index 982e502..63f3cb0 100644
--- a/compiler/hlds_module.m
+++ b/compiler/hlds_module.m
@@ -15,7 +15,6 @@
 % The main data structures defined here are the types
 %
 %   module_info
-%   dependency_info
 %
 % There is a separate interface section for each of these.
 %
@@ -29,6 +28,7 @@
 :- import_module check_hlds.unify_proc.
 :- import_module hlds.const_struct.
 :- import_module hlds.hlds_data.
+:- import_module hlds.hlds_dependency_graph.
 :- import_module hlds.hlds_pred.
 :- import_module hlds.pred_table.
 :- import_module hlds.special_pred.
@@ -49,7 +49,6 @@
 :- import_module recompilation.
 
 :- import_module cord.
-:- import_module digraph.
 :- import_module list.
 :- import_module map.
 :- import_module maybe.
@@ -299,7 +298,7 @@
 :- pred module_get_fact_table_file_names(module_info::in,
     list(string)::out) is det.
 :- pred module_info_get_maybe_dependency_info(module_info::in,
-    maybe(dependency_info)::out) is det.
+    maybe(hlds_dependency_info)::out) is det.
 :- pred module_info_get_num_errors(module_info::in, int::out) is det.
 :- pred module_info_get_type_ctor_gen_infos(module_info::in,
     list(type_ctor_gen_info)::out) is det.
@@ -510,9 +509,9 @@
     % on the returned dependency_info.
     %
 :- pred module_info_dependency_info(module_info::in,
-    dependency_info::out) is det.
+    hlds_dependency_info::out) is det.
 
-:- pred module_info_set_dependency_info(dependency_info::in,
+:- pred module_info_set_dependency_info(hlds_dependency_info::in,
     module_info::in, module_info::out) is det.
 
 :- pred module_info_clobber_dependency_info(
@@ -704,7 +703,7 @@
 
                 % Please see module_info_ensure_dependency_info for the
                 % meaning of this dependency_info, and the constraints on it.
-                mri_maybe_dependency_info       :: maybe(dependency_info),
+                mri_maybe_dependency_info       :: maybe(hlds_dependency_info),
 
                 mri_num_errors                  :: int,
 
@@ -1022,7 +1021,7 @@ module_info_optimize(!ModuleInfo) :-
     module_info::in, module_info::out) is det.
 :- pred module_info_set_atomics_per_context(map(prog_context, counter)::in,
     module_info::in, module_info::out) is det.
-:- pred module_info_set_maybe_dependency_info(maybe(dependency_info)::in,
+:- pred module_info_set_maybe_dependency_info(maybe(hlds_dependency_info)::in,
     module_info::in, module_info::out) is det.
 :- pred module_info_set_user_init_pred_c_names(
     assoc_list(sym_name_and_arity, string)::in,
@@ -1661,59 +1660,5 @@ get_unique_pred_proc_id_for_symname_and_arity(MI,
     ).
 
 %---------------------------------------------------------------------------%
-%---------------------------------------------------------------------------%
-
-:- interface.
-
-    % A dependency ordering gives the list of SCCs of the module. The list
-    % is in ascending order: the lowest SCC is first, the highest SCC is last.
-:- type dependency_ordering(T)  == list(list(T)).
-:- type dependency_ordering     == dependency_ordering(pred_proc_id).
-
-:- type dependency_graph(T)     == digraph(T).
-:- type dependency_graph        == dependency_graph(pred_proc_id).
-:- type dependency_graph_key    == digraph_key(pred_proc_id).
-:- type dependency_info(T).
-:- type dependency_info         == dependency_info(pred_proc_id).
-
-:- pred hlds_dependency_info_init(dependency_info(T)::out) is det.
-
-:- pred hlds_dependency_info_get_dependency_graph(dependency_info(T)::in,
-    dependency_graph(T)::out) is det.
-
-:- pred hlds_dependency_info_get_dependency_ordering(dependency_info(T)::in,
-    dependency_ordering(T)::out) is det.
-
-:- pred hlds_dependency_info_set_dependency_graph(dependency_graph(T)::in,
-    dependency_info(T)::in, dependency_info(T)::out) is det.
-
-:- pred hlds_dependency_info_set_dependency_ordering(
-    dependency_ordering(T)::in,
-    dependency_info(T)::in, dependency_info(T)::out) is det.
-
-%---------------------------------------------------------------------------%
-
-:- implementation.
-
-:- type dependency_info(T)
-    --->    dependency_info(
-                dep_graph       :: dependency_graph(T),
-                dep_ord         :: dependency_ordering(T)
-            ).
-
-hlds_dependency_info_init(DepInfo) :-
-    digraph.init(DepGraph),
-    DepOrd = [],
-    DepInfo = dependency_info(DepGraph, DepOrd).
-
-hlds_dependency_info_get_dependency_graph(DepInfo, DepInfo ^ dep_graph).
-hlds_dependency_info_get_dependency_ordering(DepInfo, DepInfo ^ dep_ord).
-
-hlds_dependency_info_set_dependency_graph(DepGraph, !DepInfo) :-
-    !DepInfo ^ dep_graph := DepGraph.
-hlds_dependency_info_set_dependency_ordering(DepOrd, !DepInfo) :-
-    !DepInfo ^ dep_ord := DepOrd.
-
-%---------------------------------------------------------------------------%
 :- end_module hlds.hlds_module.
 %---------------------------------------------------------------------------%
diff --git a/compiler/inlining.m b/compiler/inlining.m
index 1337155..b0b5202 100644
--- a/compiler/inlining.m
+++ b/compiler/inlining.m
@@ -160,6 +160,7 @@
 :- import_module hlds.passes_aux.
 :- import_module hlds.quantification.
 :- import_module libs.
+:- import_module libs.dependency_graph.
 :- import_module libs.globals.
 :- import_module libs.options.
 :- import_module libs.trace_params.
@@ -249,8 +250,7 @@ inlining(!ModuleInfo) :-
 
     module_info_ensure_dependency_info(!ModuleInfo),
     module_info_dependency_info(!.ModuleInfo, DepInfo),
-    hlds_dependency_info_get_dependency_ordering(DepInfo, SCCs),
-    list.condense(SCCs, PredProcs),
+    PredProcs = dependency_info_get_condensed_ordering(DepInfo),
     set.init(InlinedProcs0),
     do_inlining(PredProcs, NeededMap, Params, InlinedProcs0, !ModuleInfo),
 
diff --git a/compiler/lco.m b/compiler/lco.m
index a7a5bf0..9560e3a 100644
--- a/compiler/lco.m
+++ b/compiler/lco.m
@@ -188,6 +188,7 @@
 :- import_module hlds.status.
 :- import_module hlds.vartypes.
 :- import_module libs.
+:- import_module libs.dependency_graph.
 :- import_module libs.globals.
 :- import_module libs.options.
 :- import_module mdbcomp.
@@ -297,7 +298,7 @@
 
 lco_modulo_constructors(!ModuleInfo) :-
     module_info_rebuild_dependency_info(!ModuleInfo, DepInfo),
-    hlds_dependency_info_get_dependency_ordering(DepInfo, SCCs),
+    SCCs = dependency_info_get_ordering(DepInfo),
     list.foldl2(lco_scc, SCCs, map.init, _, !ModuleInfo).
 
 :- pred lco_scc(list(pred_proc_id)::in, variant_map::in, variant_map::out,
diff --git a/compiler/libs.m b/compiler/libs.m
index f6bced1..c7d56ca 100644
--- a/compiler/libs.m
+++ b/compiler/libs.m
@@ -26,6 +26,7 @@
 % Generic algorithms and data structures that are not quite useful enough
 % or otherwise aren't in the standard library.
 % :- include_module atsort.       % currently unused
+:- include_module dependency_graph.
 :- include_module file_util.
 :- include_module graph_colour.
 :- include_module int_emu.
diff --git a/compiler/mercury_compile_llds_back_end.m b/compiler/mercury_compile_llds_back_end.m
index f4db365..7f06bd5 100644
--- a/compiler/mercury_compile_llds_back_end.m
+++ b/compiler/mercury_compile_llds_back_end.m
@@ -66,6 +66,7 @@
 :- import_module hlds.hlds_out.hlds_out_util.
 :- import_module hlds.hlds_pred.
 :- import_module hlds.mark_tail_calls.
+:- import_module libs.dependency_graph.
 :- import_module libs.file_util.
 :- import_module libs.globals.
 :- import_module libs.options.
@@ -209,10 +210,10 @@ llds_backend_pass_by_preds(!HLDS, LLDS, !GlobalData, !Specs) :-
         MaybeDupProcMap = no
     ;
         ProcDups = yes,
-        build_pred_dependency_graph(!.HLDS, PredIds,
-            do_not_include_imported, DepInfo),
-        hlds_dependency_info_get_dependency_ordering(DepInfo, PredSCCs),
-        list.condense(PredSCCs, OrderedPredIds),
+        DepInfo = build_pred_dependency_graph(!.HLDS, PredIds,
+            do_not_include_imported),
+        OrderedPredIds =
+            dependency_info_get_condensed_ordering(DepInfo),
         MaybeDupProcMap = yes(map.init)
     ),
     generate_const_structs(!.HLDS, ConstStructMap, !GlobalData),
diff --git a/compiler/mode_constraints.m b/compiler/mode_constraints.m
index af21a3b..526b44f 100644
--- a/compiler/mode_constraints.m
+++ b/compiler/mode_constraints.m
@@ -51,10 +51,10 @@
 :- import_module check_hlds.mode_constraint_robdd.
 :- import_module check_hlds.mode_ordering.
 :- import_module check_hlds.mode_util.
-:- import_module hlds.hlds_dependency_graph.
 :- import_module hlds.goal_form.
 :- import_module hlds.goal_path.
 :- import_module hlds.hhf.
+:- import_module hlds.hlds_dependency_graph.
 :- import_module hlds.hlds_clauses.
 :- import_module hlds.hlds_goal.
 :- import_module hlds.hlds_pred.
@@ -64,6 +64,7 @@
 :- import_module hlds.quantification.
 :- import_module hlds.vartypes.
 :- import_module libs.
+:- import_module libs.dependency_graph.
 :- import_module libs.globals.
 :- import_module libs.options.
 :- import_module mdbcomp.
@@ -1869,9 +1870,9 @@ keep_var(_ForwardGoalPathMap, NonLocals, GoalVars, _GoalId, AtomicGoals,
 
 get_predicate_sccs(ModuleInfo, SCCs) :-
     module_info_get_valid_pred_ids(ModuleInfo, PredIds),
-    build_pred_dependency_graph(ModuleInfo, PredIds,
-        do_not_include_imported, DepInfo),
-    hlds_dependency_info_get_dependency_ordering(DepInfo, SCCs0),
+    DepInfo = build_pred_dependency_graph(ModuleInfo, PredIds,
+        do_not_include_imported),
+    SCCs0 = dependency_info_get_ordering(DepInfo),
 
     % Remove predicates that have mode declarations and place them in
     % their own ``SCC'' at the end of the list.
diff --git a/compiler/par_loop_control.m b/compiler/par_loop_control.m
index f70a2a0..424af71 100644
--- a/compiler/par_loop_control.m
+++ b/compiler/par_loop_control.m
@@ -110,6 +110,7 @@
 :- import_module hlds.status.
 :- import_module hlds.vartypes.
 :- import_module libs.
+:- import_module libs.dependency_graph.
 :- import_module libs.globals.
 :- import_module libs.options.
 :- import_module mdbcomp.
@@ -140,8 +141,9 @@ maybe_par_loop_control_module(!ModuleInfo) :-
         update_module(maybe_par_loop_control_proc(DepInfo)),
         !ModuleInfo).
 
-:- pred maybe_par_loop_control_proc(dependency_info::in, pred_proc_id::in,
-    proc_info::in, proc_info::out, module_info::in, module_info::out) is det.
+:- pred maybe_par_loop_control_proc(hlds_dependency_info::in,
+    pred_proc_id::in, proc_info::in, proc_info::out,
+    module_info::in, module_info::out) is det.
 
 maybe_par_loop_control_proc(DepInfo, PredProcId, !ProcInfo, !ModuleInfo) :-
     ( if loop_control_is_applicable(DepInfo, PredProcId, !.ProcInfo) then
@@ -179,8 +181,8 @@ maybe_par_loop_control_proc(DepInfo, PredProcId, !ProcInfo, !ModuleInfo) :-
     % conjunction with exactly two conjuncts whose right conjunct contains a
     % recursive call.
     %
-:- pred loop_control_is_applicable(dependency_info::in, pred_proc_id::in,
-    proc_info::in) is semidet.
+:- pred loop_control_is_applicable(hlds_dependency_info::in,
+    pred_proc_id::in, proc_info::in) is semidet.
 
 loop_control_is_applicable(DepInfo, PredProcId, ProcInfo) :-
     proc_info_get_has_parallel_conj(ProcInfo, HasParallelConj),
@@ -194,11 +196,11 @@ loop_control_is_applicable(DepInfo, PredProcId, ProcInfo) :-
     ),
     proc_is_self_recursive(DepInfo, PredProcId).
 
-:- pred proc_is_self_recursive(dependency_info::in, pred_proc_id::in)
+:- pred proc_is_self_recursive(hlds_dependency_info::in, pred_proc_id::in)
     is semidet.
 
 proc_is_self_recursive(DepInfo, PredProcId) :-
-    hlds_dependency_info_get_dependency_graph(DepInfo, DepGraph),
+    DepGraph = dependency_info_get_graph(DepInfo),
 
     % There must be a directly recursive call.
     digraph.lookup_key(DepGraph, PredProcId, SelfKey),
diff --git a/compiler/rbmm.interproc_region_lifetime.m b/compiler/rbmm.interproc_region_lifetime.m
index 951e2de..aa480b2 100644
--- a/compiler/rbmm.interproc_region_lifetime.m
+++ b/compiler/rbmm.interproc_region_lifetime.m
@@ -64,6 +64,8 @@
 :- import_module hlds.hlds_dependency_graph.
 :- import_module hlds.hlds_goal.
 :- import_module hlds.hlds_pred.
+:- import_module libs.
+:- import_module libs.dependency_graph.
 :- import_module transform_hlds.rbmm.points_to_graph.
 :- import_module transform_hlds.smm_common.
 
@@ -147,8 +149,7 @@ apply_live_region_rule(Rule, ModuleInfo, RptaInfoTable, ExecPathTable,
     module_info_get_maybe_dependency_info(ModuleInfo1, MaybeDepInfo),
     (
         MaybeDepInfo = yes(DepInfo),
-        hlds.hlds_module.hlds_dependency_info_get_dependency_ordering(
-            DepInfo, DepOrdering),
+        DepOrdering = dependency_info_get_ordering(DepInfo),
         run_with_dependencies(Rule, DepOrdering, ModuleInfo1,
             RptaInfoTable, ExecPathTable, LRBeforeTable, LRAfterTable,
             !ProcRegionSetTable)
@@ -158,7 +159,7 @@ apply_live_region_rule(Rule, ModuleInfo, RptaInfoTable, ExecPathTable,
     ).
 
 :- pred run_with_dependencies(rule_pred::in(rule_pred),
-    dependency_ordering::in, module_info::in, rpta_info_table::in,
+    hlds_dependency_ordering::in, module_info::in, rpta_info_table::in,
     execution_path_table::in, proc_pp_region_set_table::in,
     proc_pp_region_set_table::in, proc_region_set_table::in,
     proc_region_set_table::out) is det.
diff --git a/compiler/rbmm.points_to_analysis.m b/compiler/rbmm.points_to_analysis.m
index 6d0d558..383d4bf 100644
--- a/compiler/rbmm.points_to_analysis.m
+++ b/compiler/rbmm.points_to_analysis.m
@@ -52,6 +52,8 @@
 :- import_module hlds.hlds_dependency_graph.
 :- import_module hlds.hlds_goal.
 :- import_module hlds.hlds_pred.
+:- import_module libs.
+:- import_module libs.dependency_graph.
 :- import_module parse_tree.
 :- import_module parse_tree.prog_data.
 :- import_module parse_tree.prog_data_pragma.
@@ -268,14 +270,14 @@ inter_proc_rpta(ModuleInfo0, !InfoTable) :-
     module_info_get_maybe_dependency_info(ModuleInfo, MaybeDepInfo),
     (
         MaybeDepInfo = yes(DepInfo),
-        hlds_dependency_info_get_dependency_ordering(DepInfo, DepOrdering),
+        DepOrdering = dependency_info_get_ordering(DepInfo),
         run_with_dependencies(DepOrdering, ModuleInfo, !InfoTable)
     ;
         MaybeDepInfo = no,
         unexpected($module, $pred, "no dependency information")
     ).
 
-:- pred run_with_dependencies(dependency_ordering::in, module_info::in,
+:- pred run_with_dependencies(hlds_dependency_ordering::in, module_info::in,
     rpta_info_table::in, rpta_info_table::out) is det.
 
 run_with_dependencies(Deps, ModuleInfo, !InfoTable) :-
diff --git a/compiler/stratify.m b/compiler/stratify.m
index 87d1d28..832d864 100644
--- a/compiler/stratify.m
+++ b/compiler/stratify.m
@@ -58,6 +58,7 @@
 :- import_module hlds.hlds_goal.
 :- import_module hlds.hlds_pred.
 :- import_module libs.
+:- import_module libs.dependency_graph.
 :- import_module libs.globals.
 :- import_module libs.options.
 :- import_module mdbcomp.
@@ -78,7 +79,7 @@ check_module_for_stratification(!ModuleInfo, Specs) :-
     module_info_ensure_dependency_info(!ModuleInfo),
     module_info_dependency_info(!.ModuleInfo, DepInfo),
 
-    hlds_dependency_info_get_dependency_graph(DepInfo, DepGraph0),
+    DepGraph0 = dependency_info_get_graph(DepInfo),
     digraph.atsort(DepGraph0, FOSCCs1),
     dep_sets_to_lists_and_sets(FOSCCs1, [], FOSCCs),
     module_info_get_globals(!.ModuleInfo, Globals),
@@ -491,7 +492,7 @@ higher_order_check_cases([Case | Goals], Negated, WholeScc, ThisPredProcId,
     % It also returns a map of all the higher order info it collects.
     %
 :- pred gen_conservative_graph(module_info::in,
-    dependency_graph::in, dependency_graph::out, ho_map::out) is det.
+    hlds_dependency_graph::in, hlds_dependency_graph::out, ho_map::out) is det.
 :- pragma consider_used(gen_conservative_graph/4).
 
 gen_conservative_graph(ModuleInfo, !DepGraph, HOInfo) :-
@@ -626,7 +627,8 @@ merge_calls([C | Cs], P, CallsHO, DoingFirstOrder, !HOInfo, !Changed) :-
     % the given call graph with new arcs for every possible higher order call.
     %
 :- pred add_new_arcs(assoc_list(pred_proc_id, strat_ho_info)::in,
-    set(pred_proc_id)::in, dependency_graph::in, dependency_graph::out) is det.
+    set(pred_proc_id)::in,
+    hlds_dependency_graph::in, hlds_dependency_graph::out) is det.
 
 add_new_arcs([], _, !DepGraph).
 add_new_arcs([Caller - CallerInfo | Cs], CallsHO, !DepGraph) :-
@@ -641,8 +643,8 @@ add_new_arcs([Caller - CallerInfo | Cs], CallsHO, !DepGraph) :-
     ),
     add_new_arcs(Cs, CallsHO, !DepGraph).
 
-:- pred add_new_arcs2(list(pred_proc_id)::in, dependency_graph_key::in,
-    dependency_graph::in, dependency_graph::out) is det.
+:- pred add_new_arcs2(list(pred_proc_id)::in, hlds_dependency_graph_key::in,
+    hlds_dependency_graph::in, hlds_dependency_graph::out) is det.
 
 add_new_arcs2([], _, !DepGraph).
 add_new_arcs2([Callee | Cs], CallerKey, !DepGraph) :-
diff --git a/compiler/structure_reuse.indirect.m b/compiler/structure_reuse.indirect.m
index 63ccc8b..bda721b 100644
--- a/compiler/structure_reuse.indirect.m
+++ b/compiler/structure_reuse.indirect.m
@@ -82,6 +82,7 @@
 :- import_module hlds.status.
 :- import_module hlds.vartypes.
 :- import_module libs.
+:- import_module libs.dependency_graph.
 :- import_module libs.globals.
 :- import_module libs.options.
 :- import_module parse_tree.
@@ -122,7 +123,7 @@ indirect_reuse_pass(SharingTable, !ModuleInfo, !ReuseTable, DepProcs,
     module_info_get_maybe_dependency_info(!.ModuleInfo, MaybeDepInfo),
     (
         MaybeDepInfo = yes(DepInfo),
-        hlds_dependency_info_get_dependency_ordering(DepInfo, SCCs),
+        SCCs = dependency_info_get_ordering(DepInfo),
         list.foldl5(indirect_reuse_analyse_scc(SharingTable), SCCs,
             !ModuleInfo, !ReuseTable, set.init, DepProcs, set.init, Requests,
             set.init, IntermodRequests)
@@ -162,7 +163,7 @@ update_reuse_in_table(FixpointTable, PPId, !ReuseTable) :-
 indirect_reuse_rerun(SharingTable, !ModuleInfo, !ReuseTable,
         DepProcs, Requests, !IntermodRequests) :-
     module_info_rebuild_dependency_info(!ModuleInfo, DepInfo),
-    hlds_dependency_info_get_dependency_ordering(DepInfo, SCCs),
+    SCCs = dependency_info_get_ordering(DepInfo),
     list.foldl5(indirect_reuse_rerun_analyse_scc(SharingTable),
         SCCs, !ModuleInfo, !ReuseTable, set.init, DepProcs, set.init, Requests,
         !IntermodRequests).
diff --git a/compiler/structure_sharing.analysis.m b/compiler/structure_sharing.analysis.m
index 358aba0..6d97cd7 100644
--- a/compiler/structure_sharing.analysis.m
+++ b/compiler/structure_sharing.analysis.m
@@ -74,6 +74,7 @@
 :- import_module hlds.status.
 :- import_module hlds.vartypes.
 :- import_module libs.
+:- import_module libs.dependency_graph.
 :- import_module libs.file_util.
 :- import_module libs.globals.
 :- import_module libs.op_mode.
@@ -370,7 +371,7 @@ sharing_analysis(!ModuleInfo, !.SharingTable, !IO) :-
     module_info_get_maybe_dependency_info(!.ModuleInfo, MaybeDepInfo),
     (
         MaybeDepInfo = yes(DepInfo),
-        hlds_dependency_info_get_dependency_ordering(DepInfo, SCCs),
+        SCCs = dependency_info_get_ordering(DepInfo),
         list.foldl3(analyse_scc(!.ModuleInfo), SCCs,
             !SharingTable, [], DepProcs, !IO)
     ;
diff --git a/compiler/tabling_analysis.m b/compiler/tabling_analysis.m
index 00f9670..2af1856 100644
--- a/compiler/tabling_analysis.m
+++ b/compiler/tabling_analysis.m
@@ -85,6 +85,7 @@
 :- import_module hlds.hlds_pred.
 :- import_module hlds.vartypes.
 :- import_module libs.
+:- import_module libs.dependency_graph.
 :- import_module libs.globals.
 :- import_module libs.op_mode.
 :- import_module libs.options.
@@ -136,7 +137,7 @@ analyse_mm_tabling_in_module(!ModuleInfo) :-
         ),
         module_info_ensure_dependency_info(!ModuleInfo),
         module_info_dependency_info(!.ModuleInfo, DepInfo),
-        hlds_dependency_info_get_dependency_ordering(DepInfo, SCCs),
+        SCCs = dependency_info_get_ordering(DepInfo),
         globals.lookup_bool_option(Globals, debug_mm_tabling_analysis, Debug),
         list.foldl(analyse_mm_tabling_in_scc(Debug, Pass1Only), SCCs,
             !ModuleInfo),
diff --git a/compiler/term_constr_build.m b/compiler/term_constr_build.m
index e113efd..b254bd6 100644
--- a/compiler/term_constr_build.m
+++ b/compiler/term_constr_build.m
@@ -24,6 +24,7 @@
 :- interface.
 
 :- import_module hlds.
+:- import_module hlds.hlds_dependency_graph.
 :- import_module hlds.hlds_module.
 :- import_module hlds.hlds_pred.
 :- import_module transform_hlds.term_constr_errors.
@@ -52,7 +53,7 @@
 
     % Builds the abstract representation of an SCC.
     %
-:- pred term_constr_build_abstract_scc(dependency_ordering::in,
+:- pred term_constr_build_abstract_scc(hlds_dependency_ordering::in,
     list(pred_proc_id)::in, term_build_options::in, list(term2_error)::out,
     module_info::in, module_info::out) is det.
 
@@ -65,7 +66,6 @@
 :- import_module check_hlds.mode_util.
 :- import_module check_hlds.type_util.
 :- import_module hlds.goal_util.
-:- import_module hlds.hlds_dependency_graph.
 :- import_module hlds.hlds_goal.
 :- import_module hlds.hlds_out.
 :- import_module hlds.hlds_out.hlds_out_util.
diff --git a/compiler/term_constr_main.m b/compiler/term_constr_main.m
index 079b9d6..0cbd332 100644
--- a/compiler/term_constr_main.m
+++ b/compiler/term_constr_main.m
@@ -93,6 +93,7 @@
 :- import_module hlds.hlds_dependency_graph.
 :- import_module hlds.hlds_pred.
 :- import_module libs.
+:- import_module libs.dependency_graph.
 :- import_module libs.globals.
 :- import_module libs.options.
 :- import_module parse_tree.prog_data_pragma.
@@ -151,7 +152,7 @@ term2_analyse_module(!ModuleInfo, Specs) :-
     % Analyse the module per SCC in bottom-up fashion.
     module_info_ensure_dependency_info(!ModuleInfo),
     module_info_dependency_info(!.ModuleInfo, DepInfo),
-    hlds_dependency_info_get_dependency_ordering(DepInfo, SCCs),
+    SCCs = dependency_info_get_ordering(DepInfo),
     list.foldl2(
         term2_analyse_scc(SCCs, BuildOptions, FixpointOptions, Pass2Options),
         SCCs, !ModuleInfo, [], Specs),
@@ -201,8 +202,8 @@ term2_analyse_module(!ModuleInfo, Specs) :-
     % If no argument size constraint is supplied then non-zero arguments
     % are assumed to have unbounded size.
     %
-:- pred term2_analyse_scc(dependency_ordering::in, term_build_options::in,
-    fixpoint_options::in, pass2_options::in,
+:- pred term2_analyse_scc(hlds_dependency_ordering::in,
+    term_build_options::in, fixpoint_options::in, pass2_options::in,
     list(pred_proc_id)::in, module_info::in, module_info::out,
     list(error_spec)::in, list(error_spec)::out) is det.
 
diff --git a/compiler/termination.m b/compiler/termination.m
index 6c6cded..ccf5bc5 100644
--- a/compiler/termination.m
+++ b/compiler/termination.m
@@ -58,6 +58,7 @@
 :- import_module hlds.hlds_pred.
 :- import_module hlds.status.
 :- import_module libs.
+:- import_module libs.dependency_graph.
 :- import_module libs.globals.
 :- import_module libs.op_mode.
 :- import_module libs.options.
@@ -101,7 +102,7 @@ analyse_termination_in_module(!ModuleInfo, !:Specs) :-
     % Process all the SCCs of the call graph in a bottom-up order.
     module_info_ensure_dependency_info(!ModuleInfo),
     module_info_dependency_info(!.ModuleInfo, DepInfo),
-    hlds_dependency_info_get_dependency_ordering(DepInfo, SCCs),
+    SCCs = dependency_info_get_ordering(DepInfo),
 
     % Set the termination status of foreign_procs based on the foreign code
     % attributes.
diff --git a/compiler/trailing_analysis.m b/compiler/trailing_analysis.m
index 5a1f84a..768d54d 100644
--- a/compiler/trailing_analysis.m
+++ b/compiler/trailing_analysis.m
@@ -86,6 +86,7 @@
 :- import_module hlds.hlds_pred.
 :- import_module hlds.vartypes.
 :- import_module libs.
+:- import_module libs.dependency_graph.
 :- import_module libs.globals.
 :- import_module libs.op_mode.
 :- import_module libs.options.
@@ -146,7 +147,7 @@ analyse_trail_usage(!ModuleInfo) :-
         ),
         module_info_ensure_dependency_info(!ModuleInfo),
         module_info_dependency_info(!.ModuleInfo, DepInfo),
-        hlds_dependency_info_get_dependency_ordering(DepInfo, SCCs),
+        SCCs = dependency_info_get_ordering(DepInfo),
         globals.lookup_bool_option(Globals, debug_trail_usage, Debug),
         list.foldl(trail_analyse_scc(Debug, Pass1Only), SCCs, !ModuleInfo),
 
diff --git a/compiler/tupling.m b/compiler/tupling.m
index 4e3e1ea..baa22a6 100644
--- a/compiler/tupling.m
+++ b/compiler/tupling.m
@@ -117,6 +117,7 @@
 :- import_module hlds.vartypes.
 :- import_module libs.
 :- import_module libs.compiler_util.
+:- import_module libs.dependency_graph.
 :- import_module libs.globals.
 :- import_module libs.options.
 :- import_module ll_backend.
@@ -221,8 +222,8 @@ tuple_arguments_with_trace_counts(!ModuleInfo, TraceCounts0) :-
 
     module_info_ensure_dependency_info(!ModuleInfo),
     module_info_dependency_info(!.ModuleInfo, DepInfo),
-    hlds_dependency_info_get_dependency_graph(DepInfo, DepGraph),
-    hlds_dependency_info_get_dependency_ordering(DepInfo, SCCs),
+    DepGraph = dependency_info_get_graph(DepInfo),
+    SCCs = dependency_info_get_ordering(DepInfo),
 
     % Add transformed versions of procedures that we think would be
     % beneficial.
@@ -243,7 +244,7 @@ tuple_arguments_with_trace_counts(!ModuleInfo, TraceCounts0) :-
     % unused but might be useful for debugging.
     %
 :- pred maybe_tuple_scc_individual_procs(trace_counts::in, tuning_params::in,
-    dependency_graph::in, list(pred_proc_id)::in,
+    hlds_dependency_graph::in, list(pred_proc_id)::in,
     module_info::in, module_info::out, counter::in, counter::out,
     transform_map::in, transform_map::out) is det.
 :- pragma consider_used(maybe_tuple_scc_individual_procs/10).
@@ -258,7 +259,7 @@ maybe_tuple_scc_individual_procs(TraceCounts, TuningParams, DepGraph,
         Procs, !ModuleInfo, !Counter, !TransformMap).
 
 :- pred maybe_tuple_scc(trace_counts::in, tuning_params::in,
-    dependency_graph::in, list(pred_proc_id)::in,
+    hlds_dependency_graph::in, list(pred_proc_id)::in,
     module_info::in, module_info::out, counter::in, counter::out,
     transform_map::in, transform_map::out) is det.
 
@@ -315,8 +316,8 @@ maybe_tuple_scc(TraceCounts, TuningParams, DepGraph, SCC,
         )
     ).
 
-:- pred scc_has_local_callers(list(pred_proc_id)::in, dependency_graph::in)
-    is semidet.
+:- pred scc_has_local_callers(list(pred_proc_id)::in,
+    hlds_dependency_graph::in) is semidet.
 
 scc_has_local_callers(CalleeProcs, DepGraph) :-
     some [CalleeProc] (
@@ -324,7 +325,7 @@ scc_has_local_callers(CalleeProcs, DepGraph) :-
         proc_has_local_callers(CalleeProc, DepGraph)
     ).
 
-:- pred proc_has_local_callers(pred_proc_id::in, dependency_graph::in)
+:- pred proc_has_local_callers(pred_proc_id::in, hlds_dependency_graph::in)
     is semidet.
 
 proc_has_local_callers(CalleeProc, DepGraph) :-
-- 
2.7.4



More information about the reviews mailing list