[m-rev.] diff: Move dependency_graph module

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


Move dependency_graph module

Move the dependency_graph module from transform_hlds to the hlds parent
module.  Rename the dependency_graph.m file to hlds_dependency_graph.m

This change will allow us to move generic dependency_graph code to
dependency_graph.m.

compiler/dependency_graph.m -> hlds_dependency_graph.m:
compiler/hlds.m:
compiler/transform_hlds.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/inlining.m:
compiler/lco.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_main.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                 |   4 +-
 compiler/deforest.m                       |   4 +-
 compiler/dep_par_conj.m                   |   4 +-
 compiler/dependency_graph.m               | 722 ------------------------------
 compiler/exception_analysis.m             |   3 +-
 compiler/granularity.m                    |   3 +-
 compiler/hlds.m                           |   2 +
 compiler/hlds_dependency_graph.m          | 722 ++++++++++++++++++++++++++++++
 compiler/inlining.m                       |   3 +-
 compiler/lco.m                            |   4 +-
 compiler/mercury_compile_llds_back_end.m  |   6 +-
 compiler/mercury_compile_main.m           |   8 +-
 compiler/mode_constraints.m               |   7 +-
 compiler/par_loop_control.m               |   4 +-
 compiler/rbmm.interproc_region_lifetime.m |   3 +-
 compiler/rbmm.points_to_analysis.m        |   3 +-
 compiler/stratify.m                       |   4 +-
 compiler/structure_reuse.indirect.m       |   3 +-
 compiler/structure_sharing.analysis.m     |   3 +-
 compiler/tabling_analysis.m               |   3 +-
 compiler/term_constr_build.m              |   5 +-
 compiler/term_constr_main.m               |   3 +-
 compiler/termination.m                    |   3 +-
 compiler/trailing_analysis.m              |   3 +-
 compiler/transform_hlds.m                 |   3 +-
 compiler/tupling.m                        |   3 +-
 27 files changed, 776 insertions(+), 762 deletions(-)
 delete mode 100644 compiler/dependency_graph.m
 create mode 100644 compiler/hlds_dependency_graph.m

diff --git a/compiler/closure_analysis.m b/compiler/closure_analysis.m
index ea7762b..363a42c 100644
--- a/compiler/closure_analysis.m
+++ b/compiler/closure_analysis.m
@@ -2,6 +2,7 @@
 % vim: ft=mercury ts=4 sw=4 et
 %-----------------------------------------------------------------------------%
 % Copyright (C) 2005-2012 The University of Melbourne.
+% 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.
 %-----------------------------------------------------------------------------%
@@ -37,6 +38,7 @@
 
 :- import_module check_hlds.
 :- import_module check_hlds.mode_util.
+:- import_module hlds.hlds_dependency_graph.
 :- import_module hlds.hlds_goal.
 :- import_module hlds.hlds_pred.
 :- import_module hlds.passes_aux.
@@ -49,7 +51,6 @@
 :- import_module parse_tree.prog_out.
 :- import_module parse_tree.prog_type.
 :- import_module parse_tree.set_of_var.
-:- import_module transform_hlds.dependency_graph.
 
 :- import_module assoc_list.
 :- import_module bool.
diff --git a/compiler/deep_profiling.m b/compiler/deep_profiling.m
index b21c666..e3c167e 100644
--- a/compiler/deep_profiling.m
+++ b/compiler/deep_profiling.m
@@ -2,7 +2,7 @@
 % vim: ft=mercury ts=4 sw=4 et
 %-----------------------------------------------------------------------------%
 % Copyright (C) 2001-2012 The University of Melbourne.
-% Copyright (C) 2015 The Mercury team.
+% Copyright (C) 2015, 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.
 %-----------------------------------------------------------------------------%
@@ -59,6 +59,7 @@
 :- import_module hlds.code_model.
 :- import_module hlds.goal_path.
 :- import_module hlds.goal_util.
+:- import_module hlds.hlds_dependency_graph.
 :- import_module hlds.hlds_out.
 :- import_module hlds.hlds_out.hlds_out_util.
 :- import_module hlds.hlds_rtti.
@@ -81,7 +82,6 @@
 :- import_module parse_tree.set_of_var.
 :- import_module transform_hlds.
 :- import_module transform_hlds.dead_proc_elim.
-:- import_module transform_hlds.dependency_graph.
 
 :- import_module assoc_list.
 :- import_module bool.
diff --git a/compiler/deforest.m b/compiler/deforest.m
index 6cc4410..48277e0 100644
--- a/compiler/deforest.m
+++ b/compiler/deforest.m
@@ -2,7 +2,7 @@
 % vim: ft=mercury ts=4 sw=4 et
 %-----------------------------------------------------------------------------%
 % Copyright (C) 1999-2012 University of Melbourne.
-% Copyright (C) 2015 The Mercury team.
+% Copyright (C) 2015, 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.
 %-----------------------------------------------------------------------------%
@@ -56,6 +56,7 @@
 :- import_module check_hlds.simplify.simplify_tasks.
 :- import_module hlds.goal_form.
 :- import_module hlds.goal_util.
+:- import_module hlds.hlds_dependency_graph.
 :- import_module hlds.hlds_goal.
 :- import_module hlds.hlds_pred.
 :- import_module hlds.instmap.
@@ -73,7 +74,6 @@
 :- import_module parse_tree.prog_detism.
 :- import_module parse_tree.prog_type_subst.
 :- import_module parse_tree.set_of_var.
-:- import_module transform_hlds.dependency_graph.
 :- import_module transform_hlds.inlining.
 :- import_module transform_hlds.pd_cost.
 :- import_module transform_hlds.pd_debug.
diff --git a/compiler/dep_par_conj.m b/compiler/dep_par_conj.m
index 5535f71..3ddec79 100644
--- a/compiler/dep_par_conj.m
+++ b/compiler/dep_par_conj.m
@@ -2,7 +2,7 @@
 % vim: ft=mercury ts=4 sw=4 et
 %---------------------------------------------------------------------------%
 % Copyright (C) 2006-2012 The University of Melbourne.
-% Copyright (C) 2015 The Mercury team.
+% Copyright (C) 2015, 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.
 %---------------------------------------------------------------------------%
@@ -134,6 +134,7 @@
 :- import_module check_hlds.mode_util.
 :- import_module check_hlds.purity.
 :- 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_goal.
@@ -159,7 +160,6 @@
 :- import_module parse_tree.prog_mode.
 :- import_module parse_tree.prog_util.
 :- import_module parse_tree.set_of_var.
-:- import_module transform_hlds.dependency_graph.
 
 :- import_module assoc_list.
 :- import_module bool.
diff --git a/compiler/dependency_graph.m b/compiler/dependency_graph.m
deleted file mode 100644
index 32c5dbe..0000000
--- a/compiler/dependency_graph.m
+++ /dev/null
@@ -1,722 +0,0 @@
-%-----------------------------------------------------------------------------%
-% vim: ft=mercury ts=4 sw=4 et
-%-----------------------------------------------------------------------------%
-% Copyright (C) 1995-2012 The University of Melbourne.
-% 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.
-% 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).
-%
-% 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 transform_hlds.dependency_graph.
-:- interface.
-
-:- import_module hlds.
-:- import_module hlds.hlds_module.
-:- import_module hlds.hlds_pred.
-
-:- import_module io.
-:- import_module list.
-
-%-----------------------------------------------------------------------------%
-
-    % Ensure that the module_info contains a version of the dependency_info
-    % which only contains arcs between procedures for which there are clauses
-    % defined (everything that is not imported, plus opt_imported). There is
-    % no guarantee that the dependency_info is current.
-    %
-:- pred module_info_ensure_dependency_info(module_info::in, module_info::out)
-    is det.
-
-    % Ensure that the module_info contains a version of the dependency_info
-    % which only contains arcs between procedures for which there are clauses
-    % defined (everything that is not imported, plus opt_imported). The
-    % 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.
-
-:- type include_imported
-    --->    include_imported
-    ;       do_not_include_imported.
-
-    % Build the dependency graph of procedures.
-    %
-:- pred build_pred_dependency_graph(module_info::in, list(pred_id)::in,
-    include_imported::in, dependency_info(pred_id)::out) is det.
-
-    % Build the dependency graph of predicates.
-    %
-:- pred build_proc_dependency_graph(module_info::in, list(pred_id)::in,
-    include_imported::in, dependency_info(pred_proc_id)::out) is det.
-
-    % 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
-    % each line is
-    %
-    %   CallerModeDecl \t CalleeModeDecl
-    %
-:- pred write_dependency_graph(module_info::in, module_info::out,
-    io::di, io::uo) is det.
-
-    % Output a form of the static call graph to a file for use by the profiler.
-    % There is no heading, and the format of each line is
-    %
-    %   CallerLabel \t CalleeLabel
-    %
-:- pred write_prof_dependency_graph(module_info::in, module_info::out,
-    io::di, io::uo) is det.
-
-    % Given the list of predicates in a strongly connected component
-    % of the dependency graph, a list of the higher SCCs in the module
-    % 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.
-
-    % write_graph(Graph, WriteNode, WriteEdge):
-    %
-    % Write out the dependency graph using WriteNode to decide what to output
-    % for a node in the dependency graph and WriteEdge for an edge.
-    %
-:- pred write_graph(dependency_info::in,
-    pred(pred_proc_id, io, io)::pred(in, di, uo) is det,
-    pred(pred_proc_id, pred_proc_id, io, io)::pred(in, in, di, uo) is det,
-    io::di, io::uo) is det.
-
-    % write_graph_nodes(Nodes, Graph, WriteNode, WriteEdge)
-    %
-    % Write out each of the Nodes in the Graph using WriteNode and
-    % any edges originating in Nodes, using WriteEdge.
-    %
-:- pred write_graph_nodes(list(pred_proc_id)::in, dependency_graph::in,
-    pred(pred_proc_id, io, io)::pred(in, di, uo) is det,
-    pred(pred_proc_id, pred_proc_id, io, io)::pred(in, in, di, uo) is det,
-    io::di, io::uo) is det.
-
-%-----------------------------------------------------------------------------%
-%-----------------------------------------------------------------------------%
-
-:- implementation.
-
-:- import_module backend_libs.
-:- import_module backend_libs.name_mangle.
-:- import_module backend_libs.proc_label.
-:- import_module hlds.hlds_clauses.
-:- import_module hlds.hlds_goal.
-:- import_module hlds.status.
-:- import_module mdbcomp.
-:- import_module mdbcomp.sym_name.
-:- import_module parse_tree.
-:- import_module parse_tree.parse_tree_out_info.
-:- import_module parse_tree.parse_tree_out_pred_decl.
-:- import_module parse_tree.prog_data.
-
-:- import_module bool.
-:- import_module digraph.
-:- import_module int.
-:- import_module map.
-:- import_module maybe.
-:- import_module multi_map.
-:- import_module set.
-:- import_module std_util.
-:- import_module term.
-:- import_module varset.
-
-%-----------------------------------------------------------------------------%
-
-module_info_ensure_dependency_info(!ModuleInfo) :-
-    module_info_get_maybe_dependency_info(!.ModuleInfo, MaybeDepInfo),
-    (
-        MaybeDepInfo = yes(_)
-    ;
-        MaybeDepInfo = no,
-        module_info_get_valid_pred_ids(!.ModuleInfo, PredIds),
-        build_dependency_graph(!.ModuleInfo, PredIds, do_not_include_imported,
-            DepInfo),
-        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),
-    module_info_set_dependency_info(DepInfo, !ModuleInfo).
-
-build_proc_dependency_graph(ModuleInfo, PredIds, Imported, DepInfo) :-
-    build_dependency_graph(ModuleInfo, PredIds, Imported, DepInfo).
-
-build_pred_dependency_graph(ModuleInfo, PredIds, Imported, DepInfo) :-
-    build_dependency_graph(ModuleInfo, PredIds, Imported, DepInfo).
-
-    % 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).
-
-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).
-
-%-----------------------------------------------------------------------------%
-%-----------------------------------------------------------------------------%
-
-:- typeclass dependency_node(T) where [
-    pred add_dependency_nodes(list(pred_id)::in, module_info::in,
-        include_imported::in,
-        dependency_graph(T)::in, dependency_graph(T)::out) is det,
-
-    pred add_dependency_arcs(list(pred_id)::in, module_info::in,
-        include_imported::in,
-        dependency_graph(T)::in, dependency_graph(T)::out) is det,
-
-    func dependency_node(pred_proc_id) = T
-].
-
-:- instance dependency_node(pred_proc_id) where [
-    pred(add_dependency_nodes/5) is add_pred_proc_nodes,
-    pred(add_dependency_arcs/5) is add_pred_proc_arcs,
-    func(dependency_node/1) is id
-].
-
-:- instance dependency_node(pred_id) where [
-    pred(add_dependency_nodes/5) is add_pred_nodes,
-    pred(add_dependency_arcs/5) is add_pred_arcs,
-    func(dependency_node/1) is pred_proc_id_get_pred_id
-].
-
-%-----------------------------------------------------------------------------%
-%-----------------------------------------------------------------------------%
-
-:- pred add_pred_proc_nodes(list(pred_id)::in, module_info::in,
-    include_imported::in, dependency_graph::in, dependency_graph::out) is det.
-
-add_pred_proc_nodes([], _ModuleInfo, _, !DepGraph).
-add_pred_proc_nodes([PredId | PredIds], ModuleInfo, Imported, !DepGraph) :-
-    module_info_get_preds(ModuleInfo, PredTable),
-    map.lookup(PredTable, PredId, PredInfo),
-    (
-        % Don't bother adding nodes (or arcs) for procedures which are imported
-        % (i.e. which we don't have any `clauses' for).
-        Imported = do_not_include_imported,
-        ProcIds = pred_info_non_imported_procids(PredInfo)
-    ;
-        Imported = include_imported,
-        ProcIds = pred_info_procids(PredInfo)
-    ),
-    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.
-
-add_proc_nodes([], _PredId, _ModuleInfo, !DepGraph).
-add_proc_nodes([ProcId | ProcIds], PredId, ModuleInfo, !DepGraph) :-
-    digraph.add_vertex(proc(PredId, ProcId), _, !DepGraph),
-    add_proc_nodes(ProcIds, PredId, ModuleInfo, !DepGraph).
-
-%-----------------------------------------------------------------------------%
-
-:- pred add_pred_nodes(list(pred_id)::in, module_info::in,
-    include_imported::in,
-    dependency_graph(pred_id)::in, dependency_graph(pred_id)::out) is det.
-
-add_pred_nodes([], _ModuleInfo, _, DepGraph, DepGraph).
-add_pred_nodes([PredId | PredIds], ModuleInfo, IncludeImported, !DepGraph) :-
-    module_info_get_preds(ModuleInfo, PredTable),
-    map.lookup(PredTable, PredId, PredInfo),
-    % Don't bother adding nodes (or arcs) for predicates
-    % which are imported (i.e. which we don't have any `clauses' for).
-    ( if
-        IncludeImported = do_not_include_imported,
-        pred_info_is_imported(PredInfo)
-    then
-        true
-    else
-        digraph.add_vertex(PredId, _, !DepGraph)
-    ),
-    add_pred_nodes(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.
-
-add_pred_proc_arcs([], _ModuleInfo, _, !DepGraph).
-add_pred_proc_arcs([PredId | PredIds], ModuleInfo, Imported, !DepGraph) :-
-    module_info_get_preds(ModuleInfo, PredTable),
-    map.lookup(PredTable, PredId, PredInfo),
-    (
-        % Don't bother adding nodes (or arcs) for procedures which are imported
-        % (i.e. which we don't have any `clauses' for).
-        Imported = do_not_include_imported,
-        ProcIds = pred_info_non_imported_procids(PredInfo)
-    ;
-        Imported = include_imported,
-        ProcIds = pred_info_procids(PredInfo)
-    ),
-    add_proc_arcs(ProcIds, PredId, 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.
-
-add_proc_arcs([], _PredId, _ModuleInfo, _, !DepGraph).
-add_proc_arcs([ProcId | ProcIds], PredId, ModuleInfo, IncludeImported,
-        !DepGraph) :-
-    module_info_get_preds(ModuleInfo, PredTable0),
-    map.lookup(PredTable0, PredId, PredInfo0),
-    pred_info_get_proc_table(PredInfo0, ProcTable0),
-    map.lookup(ProcTable0, ProcId, ProcInfo0),
-    (
-        IncludeImported = do_not_include_imported,
-        proc_info_get_goal(ProcInfo0, Goal),
-
-        digraph.lookup_key(!.DepGraph, proc(PredId, ProcId), Caller),
-        add_dependency_arcs_in_goal(Caller, Goal, !DepGraph)
-    ;
-        IncludeImported = include_imported,
-        pred_info_get_status(PredInfo0, PredStatus),
-        Imported = pred_status_is_imported(PredStatus),
-        (
-            Imported = yes
-        ;
-            Imported = no,
-            proc_info_get_goal(ProcInfo0, Goal),
-            digraph.lookup_key(!.DepGraph, proc(PredId, ProcId), Caller),
-            add_dependency_arcs_in_goal(Caller, Goal, !DepGraph)
-        )
-    ),
-    add_proc_arcs(ProcIds, PredId, ModuleInfo, IncludeImported, !DepGraph).
-
-%-----------------------------------------------------------------------------%
-
-:- pred add_pred_arcs(list(pred_id)::in, module_info::in, include_imported::in,
-    dependency_graph(pred_id)::in, dependency_graph(pred_id)::out) is det.
-
-add_pred_arcs([], _ModuleInfo, _, !DepGraph).
-add_pred_arcs([PredId | PredIds], ModuleInfo, IncludeImported, !DepGraph) :-
-    module_info_get_preds(ModuleInfo, PredTable),
-    map.lookup(PredTable, PredId, PredInfo),
-    ( if
-        IncludeImported = do_not_include_imported,
-        pred_info_is_imported(PredInfo)
-    then
-        true
-    else
-        pred_info_get_clauses_info(PredInfo, ClausesInfo),
-        clauses_info_get_clauses_rep(ClausesInfo, ClausesRep, _ItemNumbers),
-        get_clause_list_maybe_repeated(ClausesRep, Clauses),
-        Goals = list.map(clause_body, Clauses),
-        digraph.lookup_key(!.DepGraph, PredId, Caller),
-        add_dependency_arcs_in_goals(Caller, Goals, !DepGraph)
-    ),
-    add_pred_arcs(PredIds, ModuleInfo, IncludeImported, !DepGraph).
-
-%-----------------------------------------------------------------------------%
-%-----------------------------------------------------------------------------%
-
-:- func pred_proc_id_get_pred_id(pred_proc_id) = pred_id.
-
-pred_proc_id_get_pred_id(proc(PredId, _)) = PredId.
-
-%-----------------------------------------------------------------------------%
-%-----------------------------------------------------------------------------%
-
-:- pred add_dependency_arcs_in_goal(digraph_key(T)::in, hlds_goal::in,
-    dependency_graph(T)::in, dependency_graph(T)::out) is det
-    <= dependency_node(T).
-
-add_dependency_arcs_in_goal(Caller, Goal, !DepGraph) :-
-    Goal = hlds_goal(GoalExpr, _),
-    (
-        ( GoalExpr = conj(_, Goals)
-        ; GoalExpr = disj(Goals)
-        ),
-        add_dependency_arcs_in_goals(Caller, Goals, !DepGraph)
-    ;
-        GoalExpr = switch(_Var, _Det, Cases),
-        add_dependency_arcs_in_cases(Caller, Cases, !DepGraph)
-    ;
-        GoalExpr = if_then_else(_Vars, Cond, Then, Else),
-        add_dependency_arcs_in_goal(Caller, Cond, !DepGraph),
-        add_dependency_arcs_in_goal(Caller, Then, !DepGraph),
-        add_dependency_arcs_in_goal(Caller, Else, !DepGraph)
-    ;
-        GoalExpr = negation(SubGoal),
-        add_dependency_arcs_in_goal(Caller, SubGoal, !DepGraph)
-    ;
-        GoalExpr = scope(Reason, SubGoal),
-        ( if
-            Reason = from_ground_term(_, FGT),
-            ( FGT = from_ground_term_construct
-            ; FGT = from_ground_term_deconstruct
-            )
-        then
-            % The scope references no predicates or procedures.
-            true
-        else
-            add_dependency_arcs_in_goal(Caller, SubGoal, !DepGraph)
-        )
-    ;
-        GoalExpr = generic_call(_, _, _, _, _)
-    ;
-        GoalExpr = plain_call(PredId, ProcId, _, Builtin, _, _),
-        (
-            Builtin = inline_builtin
-        ;
-            ( Builtin = out_of_line_builtin
-            ; Builtin = not_builtin
-            ),
-            ( if
-                % If the node isn't in the graph, then we didn't insert it
-                % because is was imported, and we don't consider it.
-                digraph.search_key(!.DepGraph,
-                    dependency_node(proc(PredId, ProcId)), Callee)
-            then
-                digraph.add_edge(Caller, Callee, !DepGraph)
-            else
-                true
-            )
-        )
-    ;
-        GoalExpr = unify(_,_,_,Unify,_),
-        (
-            Unify = assign(_, _)
-        ;
-            Unify = simple_test(_, _)
-        ;
-            Unify = construct(_, ConsId, _, _, _, _, _),
-            add_dependency_arcs_in_cons(Caller, ConsId, !DepGraph)
-        ;
-            Unify = deconstruct(_, ConsId, _, _, _, _),
-            add_dependency_arcs_in_cons(Caller, ConsId, !DepGraph)
-        ;
-            Unify = complicated_unify(_, _, _)
-        )
-    ;
-        GoalExpr = call_foreign_proc(_, _, _, _, _, _, _)
-    ;
-        GoalExpr = shorthand(ShortHand),
-        (
-            ShortHand = atomic_goal(_GoalType, _Outer, _Inner, _Vars,
-                MainGoal, OrElseGoals, _OrElseInners),
-            add_dependency_arcs_in_goal(Caller, MainGoal, !DepGraph),
-            add_dependency_arcs_in_goals(Caller, OrElseGoals, !DepGraph)
-        ;
-            ShortHand = try_goal(_, _, SubGoal),
-            add_dependency_arcs_in_goal(Caller, SubGoal, !DepGraph)
-        ;
-            ShortHand = bi_implication(LHS, RHS),
-            add_dependency_arcs_in_goal(Caller, LHS, !DepGraph),
-            add_dependency_arcs_in_goal(Caller, RHS, !DepGraph)
-        )
-    ).
-
-%-----------------------------------------------------------------------------%
-
-:- pred add_dependency_arcs_in_goals(digraph_key(T)::in, list(hlds_goal)::in,
-    dependency_graph(T)::in, dependency_graph(T)::out) is det
-    <= dependency_node(T).
-
-add_dependency_arcs_in_goals(_Caller, [], !DepGraph).
-add_dependency_arcs_in_goals(Caller, [Goal | Goals], !DepGraph) :-
-    add_dependency_arcs_in_goal(Caller, Goal, !DepGraph),
-    add_dependency_arcs_in_goals(Caller, Goals, !DepGraph).
-
-%-----------------------------------------------------------------------------%
-
-:- pred add_dependency_arcs_in_cases(digraph_key(T)::in, list(case)::in,
-    dependency_graph(T)::in, dependency_graph(T)::out) is det
-    <= dependency_node(T).
-
-add_dependency_arcs_in_cases(_Caller, [], !DepGraph).
-add_dependency_arcs_in_cases(Caller, [Case | Cases], !DepGraph) :-
-    Case = case(MainConsId, OtherConsIds, Goal),
-    add_dependency_arcs_in_cons(Caller, MainConsId, !DepGraph),
-    list.foldl(add_dependency_arcs_in_cons(Caller), OtherConsIds, !DepGraph),
-    add_dependency_arcs_in_goal(Caller, Goal, !DepGraph),
-    add_dependency_arcs_in_cases(Caller, Cases, !DepGraph).
-
-%-----------------------------------------------------------------------------%
-
-:- pred add_dependency_arcs_in_cons(digraph_key(T)::in, cons_id::in,
-    dependency_graph(T)::in, dependency_graph(T)::out) is det
-    <= dependency_node(T).
-
-add_dependency_arcs_in_cons(Caller, ConsId, !DepGraph) :-
-    (
-        ConsId = closure_cons(ShroudedPredProcId, _),
-        PredProcId = unshroud_pred_proc_id(ShroudedPredProcId),
-        ( if
-            % If the node isn't in the graph, then we didn't insert it
-            % because it was imported, and we don't consider it.
-            digraph.search_key(!.DepGraph, dependency_node(PredProcId), Callee)
-        then
-            digraph.add_edge(Caller, Callee, !DepGraph)
-        else
-            true
-        )
-    ;
-        ( ConsId = cons(_, _, _)
-        ; ConsId = tuple_cons(_)
-        ; ConsId = int_const(_)
-        ; ConsId = uint_const(_)
-        ; ConsId = float_const(_)
-        ; ConsId = char_const(_)
-        ; ConsId = string_const(_)
-        ; ConsId = impl_defined_const(_)
-        ; ConsId = type_ctor_info_const(_, _, _)
-        ; ConsId = base_typeclass_info_const(_, _, _, _)
-        ; ConsId = type_info_cell_constructor(_)
-        ; ConsId = typeclass_info_cell_constructor
-        ; ConsId = type_info_const(_)
-        ; ConsId = typeclass_info_const(_)
-        ; ConsId = ground_term_const(_, _)
-        ; ConsId = tabling_info_const(_)
-        ; ConsId = table_io_entry_desc(_)
-        ; ConsId = deep_profiling_proc_layout(_)
-        )
-    ).
-
-%-----------------------------------------------------------------------------%
-
-:- pred write_dependency_ordering(module_info::in, int::in,
-    list(list(pred_proc_id))::in, io::di, io::uo) is det.
-:- pragma consider_used(write_dependency_ordering/5).
-
-write_dependency_ordering(_ModuleInfo, _CurSCCNum, [], !IO) :-
-    io.write_string("\n", !IO).
-write_dependency_ordering(ModuleInfo, CurSCCNum, [SCC | SCCs], !IO) :-
-    io.write_string("% SCC ", !IO),
-    io.write_int(CurSCCNum, !IO),
-    io.write_string("\n", !IO),
-    write_scc(ModuleInfo, SCC, !IO),
-    write_dependency_ordering(ModuleInfo, CurSCCNum + 1, SCCs, !IO).
-
-:- pred write_scc(module_info::in, list(pred_proc_id)::in, io::di, io::uo)
-    is det.
-
-write_scc(_ModuleInfo, [], !IO).
-write_scc(ModuleInfo, [PredProcId | PredProcIds], !IO) :-
-    PredProcId = proc(PredId, ProcId),
-    module_info_pred_proc_info(ModuleInfo, PredId, ProcId, PredInfo, ProcInfo),
-    Name = pred_info_name(PredInfo),
-    proc_info_get_declared_determinism(ProcInfo, Det),
-    proc_info_get_argmodes(ProcInfo, Modes),
-    varset.init(ModeVarSet),
-
-    io.write_string("% ", !IO),
-    mercury_output_pred_mode_subdecl(output_mercury,ModeVarSet,
-        unqualified(Name), Modes, Det, !IO),
-    io.write_string("\n", !IO),
-    write_scc(ModuleInfo, PredProcIds, !IO).
-
-%-----------------------------------------------------------------------------%
-
-write_prof_dependency_graph(!ModuleInfo, !IO) :-
-    module_info_ensure_dependency_info(!ModuleInfo),
-    module_info_dependency_info(!.ModuleInfo, DepInfo),
-    write_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),
-    write_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.
-
-write_empty_node(_, !IO).
-
-:- pred write_prof_dep_graph_link(module_info::in,
-    pred_proc_id::in, pred_proc_id::in, io::di, io::uo) is det.
-
-write_prof_dep_graph_link(ModuleInfo, Parent, Child, !IO) :-
-    Parent = proc(PPredId, PProcId),    % Caller
-    Child = proc(CPredId, CProcId),     % Callee
-    output_label_dependency(ModuleInfo, PPredId, PProcId, !IO),
-    io.write_string("\t", !IO),
-    output_label_dependency(ModuleInfo, CPredId, CProcId, !IO),
-    io.write_string("\n", !IO).
-
-:- pred write_dep_graph_link(module_info::in,
-    pred_proc_id::in, pred_proc_id::in, io::di, io::uo) is det.
-
-write_dep_graph_link(ModuleInfo, Parent, Child, !IO) :-
-    Parent = proc(PPredId, PProcId),    % Caller
-    Child = proc(CPredId, CProcId),     % Callee
-    module_info_pred_proc_info(ModuleInfo, PPredId, PProcId,
-        PPredInfo, PProcInfo),
-    module_info_pred_proc_info(ModuleInfo, CPredId, CProcId,
-        CPredInfo, CProcInfo),
-    PName = pred_info_name(PPredInfo),
-    proc_info_get_declared_determinism(PProcInfo, PDet),
-    proc_info_get_argmodes(PProcInfo, PModes),
-    CName = pred_info_name(CPredInfo),
-    proc_info_get_declared_determinism(CProcInfo, CDet),
-    proc_info_get_argmodes(CProcInfo, CModes),
-    varset.init(ModeVarSet),
-    mercury_output_pred_mode_subdecl(output_mercury, ModeVarSet,
-        unqualified(PName), PModes, PDet, !IO),
-    io.write_string(" -> ", !IO),
-    mercury_output_pred_mode_subdecl(output_mercury, ModeVarSet,
-        unqualified(CName), CModes, CDet, !IO),
-    io.write_string("\n", !IO).
-
-%-----------------------------------------------------------------------------%
-
-write_graph(DepInfo, WriteNode, WriteLink, !IO) :-
-    hlds_dependency_info_get_dependency_graph(DepInfo, DepGraph),
-    digraph.vertices(DepGraph, DomSet),
-    set.to_sorted_list(DomSet, DomList),
-    write_graph_nodes(DomList, DepGraph, WriteNode, WriteLink, !IO).
-
-write_graph_nodes([], _Graph, _WriteNode, _WriteLink, !IO).
-write_graph_nodes([Node | Nodes], Graph, WriteNode, WriteLink, !IO) :-
-    WriteNode(Node, !IO),
-    digraph.lookup_key(Graph, Node, NodeKey),
-    digraph.lookup_from(Graph, NodeKey, ChildrenSet),
-    set.to_sorted_list(ChildrenSet, Children),
-    write_graph_children(Children, Node, Graph, WriteLink, !IO),
-    write_graph_nodes(Nodes, Graph, WriteNode, WriteLink, !IO).
-
-:- pred write_graph_children(list(dependency_graph_key)::in, pred_proc_id::in,
-    dependency_graph::in,
-    pred(pred_proc_id, pred_proc_id, io, io)::pred(in, in, di, uo) is det,
-    io::di, io::uo) is det.
-
-write_graph_children([], _Parent, _Graph, _WriteLink, !IO).
-write_graph_children([ChildKey | Children], Parent, Graph, WriteLink, !IO) :-
-    digraph.lookup_vertex(Graph, ChildKey, Child),
-    WriteLink(Parent, Child, !IO),
-    write_graph_children(Children, Parent, Graph, WriteLink, !IO).
-
-%-----------------------------------------------------------------------------%
-
-    % Print out the label corresponding to the given pred_id and proc_id.
-    %
-:- pred output_label_dependency(module_info::in, pred_id::in, proc_id::in,
-    io::di, io::uo) is det.
-
-output_label_dependency(ModuleInfo, PredId, ProcId, !IO) :-
-    ProcLabel = make_proc_label(ModuleInfo, PredId, ProcId),
-    output_proc_label(ProcLabel, !IO).
-
-%-----------------------------------------------------------------------------%
-
-get_scc_entry_points(SCC, HigherSCCs, ModuleInfo, EntryPoints) :-
-    list.filter(is_entry_point(HigherSCCs, ModuleInfo), SCC, EntryPoints).
-
-:- pred is_entry_point(list(list(pred_proc_id))::in, module_info::in,
-    pred_proc_id::in) is semidet.
-
-is_entry_point(HigherSCCs, ModuleInfo, PredProcId) :-
-    (
-        % Is the predicate exported?
-        PredProcId = proc(PredId, _ProcId),
-        module_info_pred_info(ModuleInfo, PredId, PredInfo),
-        pred_info_is_exported(PredInfo)
-    ;
-        % Is the predicate called from a higher SCC?
-        module_info_dependency_info(ModuleInfo, DepInfo),
-        hlds_dependency_info_get_dependency_graph(DepInfo, DepGraph),
-
-        digraph.lookup_key(DepGraph, PredProcId, PredProcIdKey),
-        digraph.lookup_to(DepGraph, PredProcIdKey, CallingKeys),
-        set.member(CallingKey, CallingKeys),
-        digraph.lookup_vertex(DepGraph, CallingKey, CallingPred),
-        list.member(HigherSCC, HigherSCCs),
-        list.member(CallingPred, HigherSCC)
-    ).
-
-%-----------------------------------------------------------------------------%
-
-:- type scc_id == int.
-
-    % An SCC cannot be merged into its parents if one of its procedures
-    % is called as an aggregate query.
-    %
-    % XXX This predicate is not called from anywhere. Maybe it should be;
-    % maybe not.
-    %
-:- pred handle_higher_order_args(list(prog_var)::in, bool::in, scc_id::in,
-    multi_map(prog_var, pred_proc_id)::in, map(pred_proc_id, scc_id)::in,
-    digraph(scc_id)::in, digraph(scc_id)::out,
-    set(scc_id)::in, set(scc_id)::out) is det.
-:- pragma consider_used(handle_higher_order_args/9).
-
-handle_higher_order_args([], _, _, _, _, !SCCRel, !NoMerge).
-handle_higher_order_args([Arg | Args], IsAgg, SCCid, Map, PredSCC,
-        !SCCGraph, !NoMerge) :-
-    ( if multi_map.search(Map, Arg, PredProcIds) then
-        list.foldl2(handle_higher_order_arg(PredSCC, IsAgg, SCCid),
-            PredProcIds, !SCCGraph, !NoMerge)
-    else
-        true
-    ),
-    handle_higher_order_args(Args, IsAgg, SCCid, Map, PredSCC,
-        !SCCGraph, !NoMerge).
-
-:- pred handle_higher_order_arg(map(pred_proc_id, scc_id)::in, bool::in,
-    scc_id::in, pred_proc_id::in,
-    digraph(scc_id)::in, digraph(scc_id)::out,
-    set(scc_id)::in, set(scc_id)::out) is det.
-
-handle_higher_order_arg(PredSCC, IsAgg, SCCid, PredProcId,
-        !SCCGraph, !NoMerge) :-
-    ( if map.search(PredSCC, PredProcId, CalledSCCid) then
-        % Make sure anything called through an aggregate
-        % is not merged into the current sub-module.
-        (
-            IsAgg = yes,
-            set.insert(CalledSCCid, !NoMerge)
-        ;
-            IsAgg = no
-        ),
-        ( if CalledSCCid = SCCid then
-            true
-        else
-            digraph.add_vertices_and_edge(SCCid, CalledSCCid, !SCCGraph)
-        )
-    else
-        true
-    ).
-
-%-----------------------------------------------------------------------------%
-:- end_module transform_hlds.dependency_graph.
-%-----------------------------------------------------------------------------%
diff --git a/compiler/exception_analysis.m b/compiler/exception_analysis.m
index c333a4e..a15244d 100644
--- a/compiler/exception_analysis.m
+++ b/compiler/exception_analysis.m
@@ -2,6 +2,7 @@
 % vim: ft=mercury ts=4 sw=4 et
 %-----------------------------------------------------------------------------%
 % Copyright (C) 2004-2012 The University of Melbourne.
+% 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.
 %-----------------------------------------------------------------------------%
@@ -123,6 +124,7 @@
 
 :- import_module check_hlds.
 :- import_module check_hlds.type_util.
+:- import_module hlds.hlds_dependency_graph.
 :- import_module hlds.hlds_goal.
 :- import_module hlds.vartypes.
 :- import_module libs.
@@ -137,7 +139,6 @@
 :- import_module parse_tree.prog_data_foreign.
 :- import_module parse_tree.prog_type.
 :- import_module transform_hlds.intermod.
-:- import_module transform_hlds.dependency_graph.
 :- import_module transform_hlds.mmc_analysis.
 
 :- import_module bool.
diff --git a/compiler/granularity.m b/compiler/granularity.m
index dbb7ccf..dda17ba 100644
--- a/compiler/granularity.m
+++ b/compiler/granularity.m
@@ -2,6 +2,7 @@
 % vim: ft=mercury ts=4 sw=4 et
 %-----------------------------------------------------------------------------%
 % Copyright (C) 2006-2012 The University of Melbourne.
+% 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.
 %-----------------------------------------------------------------------------%
@@ -32,6 +33,7 @@
 :- implementation.
 
 :- import_module hlds.goal_util.
+:- import_module hlds.hlds_dependency_graph.
 :- import_module hlds.hlds_pred.
 :- import_module hlds.hlds_goal.
 :- import_module hlds.instmap.
@@ -39,7 +41,6 @@
 :- import_module hlds.quantification.
 :- import_module libs.
 :- import_module libs.globals.
-:- import_module transform_hlds.dependency_graph.
 :- import_module mdbcomp.
 :- import_module mdbcomp.builtin_modules.
 :- import_module mdbcomp.prim_data.
diff --git a/compiler/hlds.m b/compiler/hlds.m
index 5687909..92229e0 100644
--- a/compiler/hlds.m
+++ b/compiler/hlds.m
@@ -2,6 +2,7 @@
 % vim: ft=mercury ts=4 sw=4 et
 %-----------------------------------------------------------------------------%
 % Copyright (C) 2002-2010, 2012 The University of Melbourne.
+% 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.
 %-----------------------------------------------------------------------------%
@@ -50,6 +51,7 @@
 % Miscellaneous utilities.
 :- include_module arg_info.
 :- include_module code_model.
+:- include_module hlds_dependency_graph.
 :- include_module from_ground_term_util.
 :- include_module goal_form.
 :- include_module goal_path.
diff --git a/compiler/hlds_dependency_graph.m b/compiler/hlds_dependency_graph.m
new file mode 100644
index 0000000..bee1585
--- /dev/null
+++ b/compiler/hlds_dependency_graph.m
@@ -0,0 +1,722 @@
+%-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et
+%-----------------------------------------------------------------------------%
+% Copyright (C) 1995-2012 The University of Melbourne.
+% 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: 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).
+%
+% 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 hlds.hlds_dependency_graph.
+:- interface.
+
+:- import_module hlds.hlds_module.
+:- import_module hlds.hlds_pred.
+
+:- import_module io.
+:- import_module list.
+
+%-----------------------------------------------------------------------------%
+
+    % Ensure that the module_info contains a version of the dependency_info
+    % which only contains arcs between procedures for which there are clauses
+    % defined (everything that is not imported, plus opt_imported). There is
+    % no guarantee that the dependency_info is current.
+    %
+:- pred module_info_ensure_dependency_info(module_info::in, module_info::out)
+    is det.
+
+    % Ensure that the module_info contains a version of the dependency_info
+    % which only contains arcs between procedures for which there are clauses
+    % defined (everything that is not imported, plus opt_imported). The
+    % 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.
+
+:- type include_imported
+    --->    include_imported
+    ;       do_not_include_imported.
+
+    % Build the dependency graph of procedures.
+    %
+:- pred build_pred_dependency_graph(module_info::in, list(pred_id)::in,
+    include_imported::in, dependency_info(pred_id)::out) is det.
+
+    % Build the dependency graph of predicates.
+    %
+:- pred build_proc_dependency_graph(module_info::in, list(pred_id)::in,
+    include_imported::in, dependency_info(pred_proc_id)::out) is det.
+
+    % 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
+    % each line is
+    %
+    %   CallerModeDecl \t CalleeModeDecl
+    %
+:- pred write_dependency_graph(module_info::in, module_info::out,
+    io::di, io::uo) is det.
+
+    % Output a form of the static call graph to a file for use by the profiler.
+    % There is no heading, and the format of each line is
+    %
+    %   CallerLabel \t CalleeLabel
+    %
+:- pred write_prof_dependency_graph(module_info::in, module_info::out,
+    io::di, io::uo) is det.
+
+    % Given the list of predicates in a strongly connected component
+    % of the dependency graph, a list of the higher SCCs in the module
+    % 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.
+
+    % write_graph(Graph, WriteNode, WriteEdge):
+    %
+    % Write out the dependency graph using WriteNode to decide what to output
+    % for a node in the dependency graph and WriteEdge for an edge.
+    %
+:- pred write_graph(dependency_info::in,
+    pred(pred_proc_id, io, io)::pred(in, di, uo) is det,
+    pred(pred_proc_id, pred_proc_id, io, io)::pred(in, in, di, uo) is det,
+    io::di, io::uo) is det.
+
+    % write_graph_nodes(Nodes, Graph, WriteNode, WriteEdge)
+    %
+    % Write out each of the Nodes in the Graph using WriteNode and
+    % any edges originating in Nodes, using WriteEdge.
+    %
+:- pred write_graph_nodes(list(pred_proc_id)::in, dependency_graph::in,
+    pred(pred_proc_id, io, io)::pred(in, di, uo) is det,
+    pred(pred_proc_id, pred_proc_id, io, io)::pred(in, in, di, uo) is det,
+    io::di, io::uo) is det.
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
+:- implementation.
+
+:- import_module backend_libs.
+:- import_module backend_libs.name_mangle.
+:- import_module backend_libs.proc_label.
+:- import_module hlds.hlds_clauses.
+:- import_module hlds.hlds_goal.
+:- import_module hlds.status.
+:- import_module mdbcomp.
+:- import_module mdbcomp.sym_name.
+:- import_module parse_tree.
+:- import_module parse_tree.parse_tree_out_info.
+:- import_module parse_tree.parse_tree_out_pred_decl.
+:- import_module parse_tree.prog_data.
+
+:- import_module bool.
+:- import_module digraph.
+:- import_module int.
+:- import_module map.
+:- import_module maybe.
+:- import_module multi_map.
+:- import_module set.
+:- import_module std_util.
+:- import_module term.
+:- import_module varset.
+
+%-----------------------------------------------------------------------------%
+
+module_info_ensure_dependency_info(!ModuleInfo) :-
+    module_info_get_maybe_dependency_info(!.ModuleInfo, MaybeDepInfo),
+    (
+        MaybeDepInfo = yes(_)
+    ;
+        MaybeDepInfo = no,
+        module_info_get_valid_pred_ids(!.ModuleInfo, PredIds),
+        build_dependency_graph(!.ModuleInfo, PredIds, do_not_include_imported,
+            DepInfo),
+        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),
+    module_info_set_dependency_info(DepInfo, !ModuleInfo).
+
+build_proc_dependency_graph(ModuleInfo, PredIds, Imported, DepInfo) :-
+    build_dependency_graph(ModuleInfo, PredIds, Imported, DepInfo).
+
+build_pred_dependency_graph(ModuleInfo, PredIds, Imported, DepInfo) :-
+    build_dependency_graph(ModuleInfo, PredIds, Imported, DepInfo).
+
+    % 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).
+
+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).
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
+:- typeclass dependency_node(T) where [
+    pred add_dependency_nodes(list(pred_id)::in, module_info::in,
+        include_imported::in,
+        dependency_graph(T)::in, dependency_graph(T)::out) is det,
+
+    pred add_dependency_arcs(list(pred_id)::in, module_info::in,
+        include_imported::in,
+        dependency_graph(T)::in, dependency_graph(T)::out) is det,
+
+    func dependency_node(pred_proc_id) = T
+].
+
+:- instance dependency_node(pred_proc_id) where [
+    pred(add_dependency_nodes/5) is add_pred_proc_nodes,
+    pred(add_dependency_arcs/5) is add_pred_proc_arcs,
+    func(dependency_node/1) is id
+].
+
+:- instance dependency_node(pred_id) where [
+    pred(add_dependency_nodes/5) is add_pred_nodes,
+    pred(add_dependency_arcs/5) is add_pred_arcs,
+    func(dependency_node/1) is pred_proc_id_get_pred_id
+].
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
+:- pred add_pred_proc_nodes(list(pred_id)::in, module_info::in,
+    include_imported::in, dependency_graph::in, dependency_graph::out) is det.
+
+add_pred_proc_nodes([], _ModuleInfo, _, !DepGraph).
+add_pred_proc_nodes([PredId | PredIds], ModuleInfo, Imported, !DepGraph) :-
+    module_info_get_preds(ModuleInfo, PredTable),
+    map.lookup(PredTable, PredId, PredInfo),
+    (
+        % Don't bother adding nodes (or arcs) for procedures which are imported
+        % (i.e. which we don't have any `clauses' for).
+        Imported = do_not_include_imported,
+        ProcIds = pred_info_non_imported_procids(PredInfo)
+    ;
+        Imported = include_imported,
+        ProcIds = pred_info_procids(PredInfo)
+    ),
+    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.
+
+add_proc_nodes([], _PredId, _ModuleInfo, !DepGraph).
+add_proc_nodes([ProcId | ProcIds], PredId, ModuleInfo, !DepGraph) :-
+    digraph.add_vertex(proc(PredId, ProcId), _, !DepGraph),
+    add_proc_nodes(ProcIds, PredId, ModuleInfo, !DepGraph).
+
+%-----------------------------------------------------------------------------%
+
+:- pred add_pred_nodes(list(pred_id)::in, module_info::in,
+    include_imported::in,
+    dependency_graph(pred_id)::in, dependency_graph(pred_id)::out) is det.
+
+add_pred_nodes([], _ModuleInfo, _, DepGraph, DepGraph).
+add_pred_nodes([PredId | PredIds], ModuleInfo, IncludeImported, !DepGraph) :-
+    module_info_get_preds(ModuleInfo, PredTable),
+    map.lookup(PredTable, PredId, PredInfo),
+    % Don't bother adding nodes (or arcs) for predicates
+    % which are imported (i.e. which we don't have any `clauses' for).
+    ( if
+        IncludeImported = do_not_include_imported,
+        pred_info_is_imported(PredInfo)
+    then
+        true
+    else
+        digraph.add_vertex(PredId, _, !DepGraph)
+    ),
+    add_pred_nodes(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.
+
+add_pred_proc_arcs([], _ModuleInfo, _, !DepGraph).
+add_pred_proc_arcs([PredId | PredIds], ModuleInfo, Imported, !DepGraph) :-
+    module_info_get_preds(ModuleInfo, PredTable),
+    map.lookup(PredTable, PredId, PredInfo),
+    (
+        % Don't bother adding nodes (or arcs) for procedures which are imported
+        % (i.e. which we don't have any `clauses' for).
+        Imported = do_not_include_imported,
+        ProcIds = pred_info_non_imported_procids(PredInfo)
+    ;
+        Imported = include_imported,
+        ProcIds = pred_info_procids(PredInfo)
+    ),
+    add_proc_arcs(ProcIds, PredId, 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.
+
+add_proc_arcs([], _PredId, _ModuleInfo, _, !DepGraph).
+add_proc_arcs([ProcId | ProcIds], PredId, ModuleInfo, IncludeImported,
+        !DepGraph) :-
+    module_info_get_preds(ModuleInfo, PredTable0),
+    map.lookup(PredTable0, PredId, PredInfo0),
+    pred_info_get_proc_table(PredInfo0, ProcTable0),
+    map.lookup(ProcTable0, ProcId, ProcInfo0),
+    (
+        IncludeImported = do_not_include_imported,
+        proc_info_get_goal(ProcInfo0, Goal),
+
+        digraph.lookup_key(!.DepGraph, proc(PredId, ProcId), Caller),
+        add_dependency_arcs_in_goal(Caller, Goal, !DepGraph)
+    ;
+        IncludeImported = include_imported,
+        pred_info_get_status(PredInfo0, PredStatus),
+        Imported = pred_status_is_imported(PredStatus),
+        (
+            Imported = yes
+        ;
+            Imported = no,
+            proc_info_get_goal(ProcInfo0, Goal),
+            digraph.lookup_key(!.DepGraph, proc(PredId, ProcId), Caller),
+            add_dependency_arcs_in_goal(Caller, Goal, !DepGraph)
+        )
+    ),
+    add_proc_arcs(ProcIds, PredId, ModuleInfo, IncludeImported, !DepGraph).
+
+%-----------------------------------------------------------------------------%
+
+:- pred add_pred_arcs(list(pred_id)::in, module_info::in, include_imported::in,
+    dependency_graph(pred_id)::in, dependency_graph(pred_id)::out) is det.
+
+add_pred_arcs([], _ModuleInfo, _, !DepGraph).
+add_pred_arcs([PredId | PredIds], ModuleInfo, IncludeImported, !DepGraph) :-
+    module_info_get_preds(ModuleInfo, PredTable),
+    map.lookup(PredTable, PredId, PredInfo),
+    ( if
+        IncludeImported = do_not_include_imported,
+        pred_info_is_imported(PredInfo)
+    then
+        true
+    else
+        pred_info_get_clauses_info(PredInfo, ClausesInfo),
+        clauses_info_get_clauses_rep(ClausesInfo, ClausesRep, _ItemNumbers),
+        get_clause_list_maybe_repeated(ClausesRep, Clauses),
+        Goals = list.map(clause_body, Clauses),
+        digraph.lookup_key(!.DepGraph, PredId, Caller),
+        add_dependency_arcs_in_goals(Caller, Goals, !DepGraph)
+    ),
+    add_pred_arcs(PredIds, ModuleInfo, IncludeImported, !DepGraph).
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
+:- func pred_proc_id_get_pred_id(pred_proc_id) = pred_id.
+
+pred_proc_id_get_pred_id(proc(PredId, _)) = PredId.
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
+:- pred add_dependency_arcs_in_goal(digraph_key(T)::in, hlds_goal::in,
+    dependency_graph(T)::in, dependency_graph(T)::out) is det
+    <= dependency_node(T).
+
+add_dependency_arcs_in_goal(Caller, Goal, !DepGraph) :-
+    Goal = hlds_goal(GoalExpr, _),
+    (
+        ( GoalExpr = conj(_, Goals)
+        ; GoalExpr = disj(Goals)
+        ),
+        add_dependency_arcs_in_goals(Caller, Goals, !DepGraph)
+    ;
+        GoalExpr = switch(_Var, _Det, Cases),
+        add_dependency_arcs_in_cases(Caller, Cases, !DepGraph)
+    ;
+        GoalExpr = if_then_else(_Vars, Cond, Then, Else),
+        add_dependency_arcs_in_goal(Caller, Cond, !DepGraph),
+        add_dependency_arcs_in_goal(Caller, Then, !DepGraph),
+        add_dependency_arcs_in_goal(Caller, Else, !DepGraph)
+    ;
+        GoalExpr = negation(SubGoal),
+        add_dependency_arcs_in_goal(Caller, SubGoal, !DepGraph)
+    ;
+        GoalExpr = scope(Reason, SubGoal),
+        ( if
+            Reason = from_ground_term(_, FGT),
+            ( FGT = from_ground_term_construct
+            ; FGT = from_ground_term_deconstruct
+            )
+        then
+            % The scope references no predicates or procedures.
+            true
+        else
+            add_dependency_arcs_in_goal(Caller, SubGoal, !DepGraph)
+        )
+    ;
+        GoalExpr = generic_call(_, _, _, _, _)
+    ;
+        GoalExpr = plain_call(PredId, ProcId, _, Builtin, _, _),
+        (
+            Builtin = inline_builtin
+        ;
+            ( Builtin = out_of_line_builtin
+            ; Builtin = not_builtin
+            ),
+            ( if
+                % If the node isn't in the graph, then we didn't insert it
+                % because is was imported, and we don't consider it.
+                digraph.search_key(!.DepGraph,
+                    dependency_node(proc(PredId, ProcId)), Callee)
+            then
+                digraph.add_edge(Caller, Callee, !DepGraph)
+            else
+                true
+            )
+        )
+    ;
+        GoalExpr = unify(_,_,_,Unify,_),
+        (
+            Unify = assign(_, _)
+        ;
+            Unify = simple_test(_, _)
+        ;
+            Unify = construct(_, ConsId, _, _, _, _, _),
+            add_dependency_arcs_in_cons(Caller, ConsId, !DepGraph)
+        ;
+            Unify = deconstruct(_, ConsId, _, _, _, _),
+            add_dependency_arcs_in_cons(Caller, ConsId, !DepGraph)
+        ;
+            Unify = complicated_unify(_, _, _)
+        )
+    ;
+        GoalExpr = call_foreign_proc(_, _, _, _, _, _, _)
+    ;
+        GoalExpr = shorthand(ShortHand),
+        (
+            ShortHand = atomic_goal(_GoalType, _Outer, _Inner, _Vars,
+                MainGoal, OrElseGoals, _OrElseInners),
+            add_dependency_arcs_in_goal(Caller, MainGoal, !DepGraph),
+            add_dependency_arcs_in_goals(Caller, OrElseGoals, !DepGraph)
+        ;
+            ShortHand = try_goal(_, _, SubGoal),
+            add_dependency_arcs_in_goal(Caller, SubGoal, !DepGraph)
+        ;
+            ShortHand = bi_implication(LHS, RHS),
+            add_dependency_arcs_in_goal(Caller, LHS, !DepGraph),
+            add_dependency_arcs_in_goal(Caller, RHS, !DepGraph)
+        )
+    ).
+
+%-----------------------------------------------------------------------------%
+
+:- pred add_dependency_arcs_in_goals(digraph_key(T)::in, list(hlds_goal)::in,
+    dependency_graph(T)::in, dependency_graph(T)::out) is det
+    <= dependency_node(T).
+
+add_dependency_arcs_in_goals(_Caller, [], !DepGraph).
+add_dependency_arcs_in_goals(Caller, [Goal | Goals], !DepGraph) :-
+    add_dependency_arcs_in_goal(Caller, Goal, !DepGraph),
+    add_dependency_arcs_in_goals(Caller, Goals, !DepGraph).
+
+%-----------------------------------------------------------------------------%
+
+:- pred add_dependency_arcs_in_cases(digraph_key(T)::in, list(case)::in,
+    dependency_graph(T)::in, dependency_graph(T)::out) is det
+    <= dependency_node(T).
+
+add_dependency_arcs_in_cases(_Caller, [], !DepGraph).
+add_dependency_arcs_in_cases(Caller, [Case | Cases], !DepGraph) :-
+    Case = case(MainConsId, OtherConsIds, Goal),
+    add_dependency_arcs_in_cons(Caller, MainConsId, !DepGraph),
+    list.foldl(add_dependency_arcs_in_cons(Caller), OtherConsIds, !DepGraph),
+    add_dependency_arcs_in_goal(Caller, Goal, !DepGraph),
+    add_dependency_arcs_in_cases(Caller, Cases, !DepGraph).
+
+%-----------------------------------------------------------------------------%
+
+:- pred add_dependency_arcs_in_cons(digraph_key(T)::in, cons_id::in,
+    dependency_graph(T)::in, dependency_graph(T)::out) is det
+    <= dependency_node(T).
+
+add_dependency_arcs_in_cons(Caller, ConsId, !DepGraph) :-
+    (
+        ConsId = closure_cons(ShroudedPredProcId, _),
+        PredProcId = unshroud_pred_proc_id(ShroudedPredProcId),
+        ( if
+            % If the node isn't in the graph, then we didn't insert it
+            % because it was imported, and we don't consider it.
+            digraph.search_key(!.DepGraph, dependency_node(PredProcId), Callee)
+        then
+            digraph.add_edge(Caller, Callee, !DepGraph)
+        else
+            true
+        )
+    ;
+        ( ConsId = cons(_, _, _)
+        ; ConsId = tuple_cons(_)
+        ; ConsId = int_const(_)
+        ; ConsId = uint_const(_)
+        ; ConsId = float_const(_)
+        ; ConsId = char_const(_)
+        ; ConsId = string_const(_)
+        ; ConsId = impl_defined_const(_)
+        ; ConsId = type_ctor_info_const(_, _, _)
+        ; ConsId = base_typeclass_info_const(_, _, _, _)
+        ; ConsId = type_info_cell_constructor(_)
+        ; ConsId = typeclass_info_cell_constructor
+        ; ConsId = type_info_const(_)
+        ; ConsId = typeclass_info_const(_)
+        ; ConsId = ground_term_const(_, _)
+        ; ConsId = tabling_info_const(_)
+        ; ConsId = table_io_entry_desc(_)
+        ; ConsId = deep_profiling_proc_layout(_)
+        )
+    ).
+
+%-----------------------------------------------------------------------------%
+
+:- pred write_dependency_ordering(module_info::in, int::in,
+    list(list(pred_proc_id))::in, io::di, io::uo) is det.
+:- pragma consider_used(write_dependency_ordering/5).
+
+write_dependency_ordering(_ModuleInfo, _CurSCCNum, [], !IO) :-
+    io.write_string("\n", !IO).
+write_dependency_ordering(ModuleInfo, CurSCCNum, [SCC | SCCs], !IO) :-
+    io.write_string("% SCC ", !IO),
+    io.write_int(CurSCCNum, !IO),
+    io.write_string("\n", !IO),
+    write_scc(ModuleInfo, SCC, !IO),
+    write_dependency_ordering(ModuleInfo, CurSCCNum + 1, SCCs, !IO).
+
+:- pred write_scc(module_info::in, list(pred_proc_id)::in, io::di, io::uo)
+    is det.
+
+write_scc(_ModuleInfo, [], !IO).
+write_scc(ModuleInfo, [PredProcId | PredProcIds], !IO) :-
+    PredProcId = proc(PredId, ProcId),
+    module_info_pred_proc_info(ModuleInfo, PredId, ProcId, PredInfo, ProcInfo),
+    Name = pred_info_name(PredInfo),
+    proc_info_get_declared_determinism(ProcInfo, Det),
+    proc_info_get_argmodes(ProcInfo, Modes),
+    varset.init(ModeVarSet),
+
+    io.write_string("% ", !IO),
+    mercury_output_pred_mode_subdecl(output_mercury,ModeVarSet,
+        unqualified(Name), Modes, Det, !IO),
+    io.write_string("\n", !IO),
+    write_scc(ModuleInfo, PredProcIds, !IO).
+
+%-----------------------------------------------------------------------------%
+
+write_prof_dependency_graph(!ModuleInfo, !IO) :-
+    module_info_ensure_dependency_info(!ModuleInfo),
+    module_info_dependency_info(!.ModuleInfo, DepInfo),
+    write_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),
+    write_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.
+
+write_empty_node(_, !IO).
+
+:- pred write_prof_dep_graph_link(module_info::in,
+    pred_proc_id::in, pred_proc_id::in, io::di, io::uo) is det.
+
+write_prof_dep_graph_link(ModuleInfo, Parent, Child, !IO) :-
+    Parent = proc(PPredId, PProcId),    % Caller
+    Child = proc(CPredId, CProcId),     % Callee
+    output_label_dependency(ModuleInfo, PPredId, PProcId, !IO),
+    io.write_string("\t", !IO),
+    output_label_dependency(ModuleInfo, CPredId, CProcId, !IO),
+    io.write_string("\n", !IO).
+
+:- pred write_dep_graph_link(module_info::in,
+    pred_proc_id::in, pred_proc_id::in, io::di, io::uo) is det.
+
+write_dep_graph_link(ModuleInfo, Parent, Child, !IO) :-
+    Parent = proc(PPredId, PProcId),    % Caller
+    Child = proc(CPredId, CProcId),     % Callee
+    module_info_pred_proc_info(ModuleInfo, PPredId, PProcId,
+        PPredInfo, PProcInfo),
+    module_info_pred_proc_info(ModuleInfo, CPredId, CProcId,
+        CPredInfo, CProcInfo),
+    PName = pred_info_name(PPredInfo),
+    proc_info_get_declared_determinism(PProcInfo, PDet),
+    proc_info_get_argmodes(PProcInfo, PModes),
+    CName = pred_info_name(CPredInfo),
+    proc_info_get_declared_determinism(CProcInfo, CDet),
+    proc_info_get_argmodes(CProcInfo, CModes),
+    varset.init(ModeVarSet),
+    mercury_output_pred_mode_subdecl(output_mercury, ModeVarSet,
+        unqualified(PName), PModes, PDet, !IO),
+    io.write_string(" -> ", !IO),
+    mercury_output_pred_mode_subdecl(output_mercury, ModeVarSet,
+        unqualified(CName), CModes, CDet, !IO),
+    io.write_string("\n", !IO).
+
+%-----------------------------------------------------------------------------%
+
+write_graph(DepInfo, WriteNode, WriteLink, !IO) :-
+    hlds_dependency_info_get_dependency_graph(DepInfo, DepGraph),
+    digraph.vertices(DepGraph, DomSet),
+    set.to_sorted_list(DomSet, DomList),
+    write_graph_nodes(DomList, DepGraph, WriteNode, WriteLink, !IO).
+
+write_graph_nodes([], _Graph, _WriteNode, _WriteLink, !IO).
+write_graph_nodes([Node | Nodes], Graph, WriteNode, WriteLink, !IO) :-
+    WriteNode(Node, !IO),
+    digraph.lookup_key(Graph, Node, NodeKey),
+    digraph.lookup_from(Graph, NodeKey, ChildrenSet),
+    set.to_sorted_list(ChildrenSet, Children),
+    write_graph_children(Children, Node, Graph, WriteLink, !IO),
+    write_graph_nodes(Nodes, Graph, WriteNode, WriteLink, !IO).
+
+:- pred write_graph_children(list(dependency_graph_key)::in, pred_proc_id::in,
+    dependency_graph::in,
+    pred(pred_proc_id, pred_proc_id, io, io)::pred(in, in, di, uo) is det,
+    io::di, io::uo) is det.
+
+write_graph_children([], _Parent, _Graph, _WriteLink, !IO).
+write_graph_children([ChildKey | Children], Parent, Graph, WriteLink, !IO) :-
+    digraph.lookup_vertex(Graph, ChildKey, Child),
+    WriteLink(Parent, Child, !IO),
+    write_graph_children(Children, Parent, Graph, WriteLink, !IO).
+
+%-----------------------------------------------------------------------------%
+
+    % Print out the label corresponding to the given pred_id and proc_id.
+    %
+:- pred output_label_dependency(module_info::in, pred_id::in, proc_id::in,
+    io::di, io::uo) is det.
+
+output_label_dependency(ModuleInfo, PredId, ProcId, !IO) :-
+    ProcLabel = make_proc_label(ModuleInfo, PredId, ProcId),
+    output_proc_label(ProcLabel, !IO).
+
+%-----------------------------------------------------------------------------%
+
+get_scc_entry_points(SCC, HigherSCCs, ModuleInfo, EntryPoints) :-
+    list.filter(is_entry_point(HigherSCCs, ModuleInfo), SCC, EntryPoints).
+
+:- pred is_entry_point(list(list(pred_proc_id))::in, module_info::in,
+    pred_proc_id::in) is semidet.
+
+is_entry_point(HigherSCCs, ModuleInfo, PredProcId) :-
+    (
+        % Is the predicate exported?
+        PredProcId = proc(PredId, _ProcId),
+        module_info_pred_info(ModuleInfo, PredId, PredInfo),
+        pred_info_is_exported(PredInfo)
+    ;
+        % Is the predicate called from a higher SCC?
+        module_info_dependency_info(ModuleInfo, DepInfo),
+        hlds_dependency_info_get_dependency_graph(DepInfo, DepGraph),
+
+        digraph.lookup_key(DepGraph, PredProcId, PredProcIdKey),
+        digraph.lookup_to(DepGraph, PredProcIdKey, CallingKeys),
+        set.member(CallingKey, CallingKeys),
+        digraph.lookup_vertex(DepGraph, CallingKey, CallingPred),
+        list.member(HigherSCC, HigherSCCs),
+        list.member(CallingPred, HigherSCC)
+    ).
+
+%-----------------------------------------------------------------------------%
+
+:- type scc_id == int.
+
+    % An SCC cannot be merged into its parents if one of its procedures
+    % is called as an aggregate query.
+    %
+    % XXX This predicate is not called from anywhere. Maybe it should be;
+    % maybe not.
+    %
+:- pred handle_higher_order_args(list(prog_var)::in, bool::in, scc_id::in,
+    multi_map(prog_var, pred_proc_id)::in, map(pred_proc_id, scc_id)::in,
+    digraph(scc_id)::in, digraph(scc_id)::out,
+    set(scc_id)::in, set(scc_id)::out) is det.
+:- pragma consider_used(handle_higher_order_args/9).
+
+handle_higher_order_args([], _, _, _, _, !SCCRel, !NoMerge).
+handle_higher_order_args([Arg | Args], IsAgg, SCCid, Map, PredSCC,
+        !SCCGraph, !NoMerge) :-
+    ( if multi_map.search(Map, Arg, PredProcIds) then
+        list.foldl2(handle_higher_order_arg(PredSCC, IsAgg, SCCid),
+            PredProcIds, !SCCGraph, !NoMerge)
+    else
+        true
+    ),
+    handle_higher_order_args(Args, IsAgg, SCCid, Map, PredSCC,
+        !SCCGraph, !NoMerge).
+
+:- pred handle_higher_order_arg(map(pred_proc_id, scc_id)::in, bool::in,
+    scc_id::in, pred_proc_id::in,
+    digraph(scc_id)::in, digraph(scc_id)::out,
+    set(scc_id)::in, set(scc_id)::out) is det.
+
+handle_higher_order_arg(PredSCC, IsAgg, SCCid, PredProcId,
+        !SCCGraph, !NoMerge) :-
+    ( if map.search(PredSCC, PredProcId, CalledSCCid) then
+        % Make sure anything called through an aggregate
+        % is not merged into the current sub-module.
+        (
+            IsAgg = yes,
+            set.insert(CalledSCCid, !NoMerge)
+        ;
+            IsAgg = no
+        ),
+        ( if CalledSCCid = SCCid then
+            true
+        else
+            digraph.add_vertices_and_edge(SCCid, CalledSCCid, !SCCGraph)
+        )
+    else
+        true
+    ).
+
+%-----------------------------------------------------------------------------%
+:- end_module hlds.hlds_dependency_graph.
+%-----------------------------------------------------------------------------%
diff --git a/compiler/inlining.m b/compiler/inlining.m
index e16af77..1337155 100644
--- a/compiler/inlining.m
+++ b/compiler/inlining.m
@@ -2,6 +2,7 @@
 % vim: ft=mercury ts=4 sw=4 et
 %-----------------------------------------------------------------------------%
 % Copyright (C) 1994-2012 The University of Melbourne.
+% 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.
 %-----------------------------------------------------------------------------%
@@ -155,6 +156,7 @@
 :- import_module check_hlds.mode_util.
 :- import_module check_hlds.purity.
 :- import_module hlds.goal_util.
+:- import_module hlds.hlds_dependency_graph.
 :- import_module hlds.passes_aux.
 :- import_module hlds.quantification.
 :- import_module libs.
@@ -169,7 +171,6 @@
 :- import_module parse_tree.set_of_var.
 :- import_module transform_hlds.complexity.
 :- import_module transform_hlds.dead_proc_elim.
-:- import_module transform_hlds.dependency_graph.
 
 :- import_module int.
 :- import_module maybe.
diff --git a/compiler/lco.m b/compiler/lco.m
index 9b6cb4e..a7a5bf0 100644
--- a/compiler/lco.m
+++ b/compiler/lco.m
@@ -2,7 +2,7 @@
 % vim: ft=mercury ts=4 sw=4 et
 %-----------------------------------------------------------------------------%
 % Copyright (C) 1996-2012 The University of Melbourne.
-% Copyright (C) 2015 The Mercury team.
+% Copyright (C) 2015, 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.
 %-----------------------------------------------------------------------------%
@@ -176,6 +176,7 @@
 :- import_module hlds.arg_info.
 :- import_module hlds.goal_util.
 :- import_module hlds.hlds_code_util.
+:- import_module hlds.hlds_dependency_graph.
 :- import_module hlds.hlds_data.
 :- import_module hlds.hlds_goal.
 :- import_module hlds.hlds_out.
@@ -200,7 +201,6 @@
 :- import_module parse_tree.prog_type.
 :- import_module parse_tree.prog_util.
 :- import_module parse_tree.set_of_var.
-:- import_module transform_hlds.dependency_graph.
 
 :- import_module assoc_list.
 :- import_module bag.
diff --git a/compiler/mercury_compile_llds_back_end.m b/compiler/mercury_compile_llds_back_end.m
index 0bfa4e0..f4db365 100644
--- a/compiler/mercury_compile_llds_back_end.m
+++ b/compiler/mercury_compile_llds_back_end.m
@@ -2,6 +2,7 @@
 % vim: ft=mercury ts=4 sw=4 et
 %---------------------------------------------------------------------------%
 % Copyright (C) 2009-2012 The University of Melbourne.
+% 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.
 %---------------------------------------------------------------------------%
@@ -60,6 +61,7 @@
 :- import_module check_hlds.simplify.simplify_proc.
 :- import_module check_hlds.simplify.simplify_tasks.
 :- import_module hlds.arg_info.
+:- import_module hlds.hlds_dependency_graph.
 :- import_module hlds.hlds_out.
 :- import_module hlds.hlds_out.hlds_out_util.
 :- import_module hlds.hlds_pred.
@@ -90,8 +92,6 @@
 :- import_module parse_tree.prog_data_foreign.
 :- import_module parse_tree.prog_foreign.
 :- import_module top_level.mercury_compile_front_end.
-:- import_module transform_hlds.
-:- import_module transform_hlds.dependency_graph.
 
 :- import_module assoc_list.
 :- import_module cord.
@@ -209,7 +209,7 @@ llds_backend_pass_by_preds(!HLDS, LLDS, !GlobalData, !Specs) :-
         MaybeDupProcMap = no
     ;
         ProcDups = yes,
-        dependency_graph.build_pred_dependency_graph(!.HLDS, PredIds,
+        build_pred_dependency_graph(!.HLDS, PredIds,
             do_not_include_imported, DepInfo),
         hlds_dependency_info_get_dependency_ordering(DepInfo, PredSCCs),
         list.condense(PredSCCs, OrderedPredIds),
diff --git a/compiler/mercury_compile_main.m b/compiler/mercury_compile_main.m
index 20f923e..d8c2068 100644
--- a/compiler/mercury_compile_main.m
+++ b/compiler/mercury_compile_main.m
@@ -2,6 +2,7 @@
 % vim: ts=4 sw=4 et ft=mercury
 %---------------------------------------------------------------------------%
 % Copyright (C) 1994-2012 The University of Melbourne.
+% 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.
 %---------------------------------------------------------------------------%
@@ -49,6 +50,7 @@
 :- import_module check_hlds.xml_documentation.
 :- import_module hlds.
 :- import_module hlds.hlds_defns.
+:- import_module hlds.hlds_dependency_graph.
 :- import_module hlds.hlds_module.
 :- import_module hlds.make_hlds.
 :- import_module hlds.passes_aux.
@@ -97,8 +99,6 @@
 :- import_module top_level.mercury_compile_llds_back_end.
 :- import_module top_level.mercury_compile_middle_passes.
 :- import_module top_level.mercury_compile_mlds_back_end.
-:- import_module transform_hlds.
-:- import_module transform_hlds.dependency_graph.
 
 :- import_module bool.
 :- import_module char.
@@ -2061,7 +2061,7 @@ maybe_write_dependency_graph(Verbose, Stats, !HLDS, !IO) :-
         (
             Res = ok(FileStream),
             io.set_output_stream(FileStream, OutputStream, !IO),
-            dependency_graph.write_dependency_graph(!HLDS, !IO),
+            write_dependency_graph(!HLDS, !IO),
             io.set_output_stream(OutputStream, _, !IO),
             io.close_output(FileStream, !IO),
             maybe_write_string(Verbose, " done.\n", !IO)
@@ -2292,7 +2292,7 @@ maybe_output_prof_call_graph(Verbose, Stats, !HLDS, !IO) :-
         (
             Res = ok(FileStream),
             io.set_output_stream(FileStream, OutputStream, !IO),
-            dependency_graph.write_prof_dependency_graph(!HLDS, !IO),
+            write_prof_dependency_graph(!HLDS, !IO),
             io.set_output_stream(OutputStream, _, !IO),
             io.close_output(FileStream, !IO)
         ;
diff --git a/compiler/mode_constraints.m b/compiler/mode_constraints.m
index ea809d4..af21a3b 100644
--- a/compiler/mode_constraints.m
+++ b/compiler/mode_constraints.m
@@ -2,6 +2,7 @@
 % vim: ft=mercury ts=4 sw=4 et
 %-----------------------------------------------------------------------------%
 % Copyright (C) 2001-2012 The University of Melbourne.
+% 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.
 %-----------------------------------------------------------------------------%
@@ -44,14 +45,13 @@
 
 :- implementation.
 
-:- import_module transform_hlds.    % for pd_cost, etc.
-
 :- import_module check_hlds.build_mode_constraints.
 :- import_module check_hlds.ordering_mode_constraints.
 
 :- 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.
@@ -77,7 +77,6 @@
 :- import_module parse_tree.prog_data.
 :- import_module parse_tree.prog_mode.
 :- import_module parse_tree.set_of_var.
-:- import_module transform_hlds.dependency_graph.
 
 :- import_module assoc_list.
 :- import_module bool.
@@ -1870,7 +1869,7 @@ keep_var(_ForwardGoalPathMap, NonLocals, GoalVars, _GoalId, AtomicGoals,
 
 get_predicate_sccs(ModuleInfo, SCCs) :-
     module_info_get_valid_pred_ids(ModuleInfo, PredIds),
-    dependency_graph.build_pred_dependency_graph(ModuleInfo, PredIds,
+    build_pred_dependency_graph(ModuleInfo, PredIds,
         do_not_include_imported, DepInfo),
     hlds_dependency_info_get_dependency_ordering(DepInfo, SCCs0),
 
diff --git a/compiler/par_loop_control.m b/compiler/par_loop_control.m
index 151b876..f70a2a0 100644
--- a/compiler/par_loop_control.m
+++ b/compiler/par_loop_control.m
@@ -2,7 +2,7 @@
 % vim: ft=mercury ts=4 sw=4 et
 %-----------------------------------------------------------------------------%
 % Copyright (C) 2011-2012 The University of Melbourne.
-% Copyright (C) 2015 The Mercury team.
+% Copyright (C) 2015, 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.
 %-----------------------------------------------------------------------------%
@@ -100,6 +100,7 @@
 
 :- import_module hlds.goal_path.
 :- import_module hlds.goal_util.
+:- import_module hlds.hlds_dependency_graph.
 :- import_module hlds.hlds_goal.
 :- import_module hlds.hlds_pred.
 :- import_module hlds.hlds_rtti.
@@ -119,7 +120,6 @@
 :- import_module parse_tree.prog_data.
 :- import_module parse_tree.prog_util.
 :- import_module parse_tree.set_of_var.
-:- import_module transform_hlds.dependency_graph.
 
 :- import_module bool.
 :- import_module digraph.
diff --git a/compiler/rbmm.interproc_region_lifetime.m b/compiler/rbmm.interproc_region_lifetime.m
index 06bf75b..951e2de 100644
--- a/compiler/rbmm.interproc_region_lifetime.m
+++ b/compiler/rbmm.interproc_region_lifetime.m
@@ -2,6 +2,7 @@
 % vim: ft=mercury ts=4 sw=4 et
 %-----------------------------------------------------------------------------%
 % Copyright (C) 2005-2007, 2009-2011 The University of Melbourne.
+% 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.
 %-----------------------------------------------------------------------------%
@@ -60,9 +61,9 @@
 
 :- import_module check_hlds.
 :- import_module check_hlds.type_util.
+:- import_module hlds.hlds_dependency_graph.
 :- import_module hlds.hlds_goal.
 :- import_module hlds.hlds_pred.
-:- import_module transform_hlds.dependency_graph.
 :- import_module transform_hlds.rbmm.points_to_graph.
 :- import_module transform_hlds.smm_common.
 
diff --git a/compiler/rbmm.points_to_analysis.m b/compiler/rbmm.points_to_analysis.m
index f40b955..6d0d558 100644
--- a/compiler/rbmm.points_to_analysis.m
+++ b/compiler/rbmm.points_to_analysis.m
@@ -2,6 +2,7 @@
 % vim: ft=mercury ts=4 sw=4 et
 %-----------------------------------------------------------------------------%
 % Copyright (C) 2005-2012 The University of Melbourne.
+% 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.
 %-----------------------------------------------------------------------------%
@@ -48,12 +49,12 @@
 :- implementation.
 
 :- import_module hlds.goal_path.
+:- import_module hlds.hlds_dependency_graph.
 :- import_module hlds.hlds_goal.
 :- import_module hlds.hlds_pred.
 :- import_module parse_tree.
 :- import_module parse_tree.prog_data.
 :- import_module parse_tree.prog_data_pragma.
-:- import_module transform_hlds.dependency_graph.
 :- import_module transform_hlds.rbmm.points_to_graph.
 :- import_module transform_hlds.smm_common.
 :- import_module transform_hlds.ctgc.
diff --git a/compiler/stratify.m b/compiler/stratify.m
index 7d465c2..87d1d28 100644
--- a/compiler/stratify.m
+++ b/compiler/stratify.m
@@ -2,6 +2,7 @@
 % vim: ft=mercury ts=4 sw=4 et
 %-----------------------------------------------------------------------------%
 % Copyright (C) 1996-2012 The University of Melbourne.
+% 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.
 %-----------------------------------------------------------------------------%
@@ -52,6 +53,7 @@
 :- implementation.
 
 :- import_module check_hlds.mode_util.
+:- import_module hlds.hlds_dependency_graph.
 :- import_module hlds.hlds_error_util.
 :- import_module hlds.hlds_goal.
 :- import_module hlds.hlds_pred.
@@ -62,8 +64,6 @@
 :- import_module mdbcomp.sym_name.
 :- import_module parse_tree.prog_data.
 :- import_module parse_tree.prog_type.
-:- import_module transform_hlds.
-:- import_module transform_hlds.dependency_graph.
 
 :- import_module assoc_list.
 :- import_module bool.
diff --git a/compiler/structure_reuse.indirect.m b/compiler/structure_reuse.indirect.m
index d588fff..63ccc8b 100644
--- a/compiler/structure_reuse.indirect.m
+++ b/compiler/structure_reuse.indirect.m
@@ -2,6 +2,7 @@
 % vim: ft=mercury ff=unix ts=4 sw=4 et
 %-----------------------------------------------------------------------------%
 % Copyright (C) 2006-2012 The University of Melbourne.
+% 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.
 %-----------------------------------------------------------------------------%
@@ -74,6 +75,7 @@
 :- import_module analysis.
 :- import_module check_hlds.
 :- import_module check_hlds.type_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.
@@ -92,7 +94,6 @@
 :- import_module transform_hlds.ctgc.fixpoint_table.
 :- import_module transform_hlds.ctgc.livedata.
 :- import_module transform_hlds.ctgc.util.
-:- import_module transform_hlds.dependency_graph.
 
 :- import_module bimap.
 :- import_module bool.
diff --git a/compiler/structure_sharing.analysis.m b/compiler/structure_sharing.analysis.m
index 9ad0848..358aba0 100644
--- a/compiler/structure_sharing.analysis.m
+++ b/compiler/structure_sharing.analysis.m
@@ -2,6 +2,7 @@
 % vim: ft=mercury ts=4 sw=4 et
 %-----------------------------------------------------------------------------%
 % Copyright (C) 2005-2012 The University of Melbourne.
+% 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.
 %-----------------------------------------------------------------------------%
@@ -64,6 +65,7 @@
 :- import_module check_hlds.simplify.simplify_proc.
 :- import_module check_hlds.simplify.simplify_tasks.
 :- import_module hlds.arg_info.
+:- import_module hlds.hlds_dependency_graph.
 :- import_module hlds.hlds_goal.
 :- import_module hlds.hlds_out.
 :- import_module hlds.hlds_out.hlds_out_util.
@@ -90,7 +92,6 @@
 :- import_module transform_hlds.ctgc.selector.
 :- import_module transform_hlds.ctgc.structure_sharing.domain.
 :- import_module transform_hlds.ctgc.util.
-:- import_module transform_hlds.dependency_graph.
 :- import_module transform_hlds.intermod.
 :- import_module transform_hlds.mmc_analysis.
 
diff --git a/compiler/tabling_analysis.m b/compiler/tabling_analysis.m
index f894701..00f9670 100644
--- a/compiler/tabling_analysis.m
+++ b/compiler/tabling_analysis.m
@@ -2,6 +2,7 @@
 % vim: ft=mercury ts=4 sw=4 et
 %-----------------------------------------------------------------------------%
 % Copyright (C) 2006-2012 The University of Melbourne.
+% 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.
 %-----------------------------------------------------------------------------%
@@ -78,6 +79,7 @@
 
 :- implementation.
 
+:- import_module hlds.hlds_dependency_graph.
 :- import_module hlds.hlds_error_util.
 :- import_module hlds.hlds_goal.
 :- import_module hlds.hlds_pred.
@@ -95,7 +97,6 @@
 :- import_module parse_tree.prog_data.
 :- import_module parse_tree.prog_data_foreign.
 :- import_module parse_tree.prog_data_pragma.
-:- import_module transform_hlds.dependency_graph.
 :- import_module transform_hlds.intermod.
 :- import_module transform_hlds.mmc_analysis.
 
diff --git a/compiler/term_constr_build.m b/compiler/term_constr_build.m
index bb36258..e113efd 100644
--- a/compiler/term_constr_build.m
+++ b/compiler/term_constr_build.m
@@ -2,6 +2,7 @@
 % vim: ft=mercury ts=4 sw=4 et
 %-----------------------------------------------------------------------------%
 % Copyright (C) 2003, 2005-2012 The University of Melbourne.
+% 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.
 %-----------------------------------------------------------------------------%
@@ -64,6 +65,7 @@
 :- 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.
@@ -79,7 +81,6 @@
 :- import_module parse_tree.prog_data_pragma.
 :- import_module parse_tree.prog_type.
 :- import_module parse_tree.set_of_var.
-:- import_module transform_hlds.dependency_graph.
 :- import_module transform_hlds.term_constr_data.
 :- import_module transform_hlds.term_constr_main_types.
 :- import_module transform_hlds.term_constr_util.
@@ -135,7 +136,7 @@ term_build_options_init(Norm, Failure, ArgSizeOnly) =
 %-----------------------------------------------------------------------------%
 
 term_constr_build_abstract_scc(DepOrder, SCC, Options, Errors, !ModuleInfo) :-
-    dependency_graph.get_scc_entry_points(SCC, DepOrder, !.ModuleInfo,
+    get_scc_entry_points(SCC, DepOrder, !.ModuleInfo,
         EntryProcs),
     list.foldl2(
         term_constr_build_abstract_proc(EntryProcs, Options, SCC,
diff --git a/compiler/term_constr_main.m b/compiler/term_constr_main.m
index 9927de0..079b9d6 100644
--- a/compiler/term_constr_main.m
+++ b/compiler/term_constr_main.m
@@ -2,6 +2,7 @@
 % vim: ft=mercury ts=4 sw=4 et
 %-----------------------------------------------------------------------------%
 % Copyright (C) 1997,2002-2011 The University of Melbourne.
+% 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.
 %----------------------------------------------------------------------------%
@@ -89,12 +90,12 @@
 
 :- implementation.
 
+:- import_module hlds.hlds_dependency_graph.
 :- import_module hlds.hlds_pred.
 :- import_module libs.
 :- import_module libs.globals.
 :- import_module libs.options.
 :- import_module parse_tree.prog_data_pragma.
-:- import_module transform_hlds.dependency_graph.
 :- import_module transform_hlds.term_constr_build.
 :- import_module transform_hlds.term_constr_data.
 :- import_module transform_hlds.term_constr_errors.
diff --git a/compiler/termination.m b/compiler/termination.m
index 41d2774..6c6cded 100644
--- a/compiler/termination.m
+++ b/compiler/termination.m
@@ -2,6 +2,7 @@
 % vim: ft=mercury ts=4 sw=4 et
 %-----------------------------------------------------------------------------%
 % Copyright (C) 1997-2001, 2003-2011 The University of Melbourne.
+% 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.
 %----------------------------------------------------------------------------%
@@ -51,6 +52,7 @@
 
 :- implementation.
 
+:- import_module hlds.hlds_dependency_graph.
 :- import_module hlds.hlds_error_util.
 :- import_module hlds.hlds_goal.
 :- import_module hlds.hlds_pred.
@@ -65,7 +67,6 @@
 :- import_module parse_tree.prog_data.
 :- import_module parse_tree.prog_data_foreign.
 :- import_module parse_tree.prog_data_pragma.
-:- import_module transform_hlds.dependency_graph.
 :- import_module transform_hlds.post_term_analysis.
 :- import_module transform_hlds.term_errors.
 :- import_module transform_hlds.term_norm.
diff --git a/compiler/trailing_analysis.m b/compiler/trailing_analysis.m
index 83a0925..5a1f84a 100644
--- a/compiler/trailing_analysis.m
+++ b/compiler/trailing_analysis.m
@@ -2,6 +2,7 @@
 % vim: ft=mercury ts=4 sw=4 et
 %-----------------------------------------------------------------------------%
 % Copyright (C) 2005-2012 The University of Melbourne.
+% 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.
 %-----------------------------------------------------------------------------%
@@ -79,6 +80,7 @@
 :- import_module check_hlds.
 :- import_module check_hlds.type_util.
 :- import_module hlds.code_model.
+:- import_module hlds.hlds_dependency_graph.
 :- import_module hlds.hlds_error_util.
 :- import_module hlds.hlds_goal.
 :- import_module hlds.hlds_pred.
@@ -96,7 +98,6 @@
 :- import_module parse_tree.prog_data.
 :- import_module parse_tree.prog_data_foreign.
 :- import_module parse_tree.prog_type.
-:- import_module transform_hlds.dependency_graph.
 :- import_module transform_hlds.intermod.
 :- import_module transform_hlds.mmc_analysis.
 
diff --git a/compiler/transform_hlds.m b/compiler/transform_hlds.m
index d9ad266..b6535aa 100644
--- a/compiler/transform_hlds.m
+++ b/compiler/transform_hlds.m
@@ -2,6 +2,7 @@
 % vim: ft=mercury ts=4 sw=4 et
 %-----------------------------------------------------------------------------%
 % Copyright (C) 2002-2008, 2012 The University of Melbourne.
+% 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.
 %-----------------------------------------------------------------------------%
@@ -17,8 +18,6 @@
 
 :- include_module intermod.
 
-:- include_module dependency_graph.
-
 :- include_module equiv_type_hlds.
 
 :- include_module table_gen.
diff --git a/compiler/tupling.m b/compiler/tupling.m
index 38f82c5..4e3e1ea 100644
--- a/compiler/tupling.m
+++ b/compiler/tupling.m
@@ -2,6 +2,7 @@
 % vim: ft=mercury ts=4 sw=4 et
 %-----------------------------------------------------------------------------%
 % Copyright (C) 2005-2012 The University of Melbourne.
+% 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.
 %-----------------------------------------------------------------------------%
@@ -104,6 +105,7 @@
 :- import_module check_hlds.type_util.
 :- import_module hlds.arg_info.
 :- import_module hlds.goal_path.
+:- import_module hlds.hlds_dependency_graph.
 :- import_module hlds.hlds_goal.
 :- import_module hlds.hlds_llds.
 :- import_module hlds.hlds_out.
@@ -132,7 +134,6 @@
 :- import_module parse_tree.prog_type.
 :- import_module parse_tree.prog_util.
 :- import_module parse_tree.set_of_var.
-:- import_module transform_hlds.dependency_graph.
 
 :- import_module array.
 :- import_module assoc_list.
-- 
2.7.4



More information about the reviews mailing list