mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-13 21:04:00 +00:00
Estimated hours taken: 400
Deforestation.
This increases the code size of the compiler by ~80k when compiling
with --intermodule-optimization --deforestation.
The improvement from deforestation is not measurable for mmc -C make_hlds.m.
Compile time for make_hlds.m increased from 50.7 seconds to 52.2 seconds
when running deforestation.
compiler/simplify.m
compiler/common.m
Provide a nicer interface for simplifying a goal,
not an entire procedure.
Rework the interface to avoid manipulating lots of booleans.
Return an estimate of the improvement in cost from simplification.
Remove failing cases and disjuncts.
Add an option to optimize common structures even across calls.
Remove code to merge branched goals, since that is now
done by deforestation.
Fix a bug: the code to collect instmap_deltas for cases was not
including the switched-on variable in the instmap_delta,
which caused an abort in merge_instmap_delta if the switched
on variable was further instantiated in the switch.
This came up while compiling the compiler with --deforestation.
compiler/det_report.
Output duplicate call warnings even if --warn-simple-code is not set.
XXX fix the same problem with `:- pragma obsolete'.
compiler/code_aux.m
Update code_aux__cannot_loop to use termination information.
compiler/hlds_pred.m
compiler/dnf.m
Pass the type_info_varmap and typeclass_info_varmap
into hlds_pred__define_new_pred.
Restrict the variables of the new procedure onto the variables
of the goal.
Make sure all relevant type_infos are passed into the new
procedure if --typeinfo-liveness is set.
compiler/modes.m
compiler/unique_modes.m
compiler/mode_info.m
compiler/modecheck_unify.m
Put `how_to_check_goal' into the mode_info, rather
than passing it around.
Add a field to the `check_unique_modes' case which
controls whether unique modes is allowed to choose
a different procedure. For deforestation, this is
not allowed, since it could result in choosing a less
efficient procedure after generalisation.
compiler/options.m
New options:
--deforestation
--deforestation-depth-limit
Safety net for termination of the algorithm.
--deforestation-cost-factor
Fudge factor for working out whether deforestation
was worthwhile.
--deforestation-vars-threshold
Like --inline-vars-threshold.
Enable deforestation at -O3.
Removed an unnecessary mode for option_defaults_2, since it
resulted in a warning about disjuncts which cannot succeed.
compiler/handle_options.m
--no-reorder-conj implies --no-deforestation.
compiler/inlining.m
Separate code to rename goals into inlining__do_inline_call.
compiler/hlds_goal.m
Added predicates goal_list_nonlocals, goal_list_instmap_delta
and goal_list_determinism to approximate information about
conjunctions.
compiler/hlds_module.m
Added module_info_set_pred_proc_info to put an updated
pred_info and proc_info back into the module_info.
compiler/hlds_out.m
Exported hlds_out__write_instmap for debugging of deforestation.
Bracket module names on constructors where necessary.
compiler/mercury_compile.m
Call deforestation.
Use the new interface to simplify.m.
compiler/intermod.m
Put recursive predicates with a top-level branched goal
into `.opt' files.
goal_util.m
Added goal_calls_pred_id to work out if a predicate is
recursive before mode analysis.
Export goal_util__goals_goal_vars for use by deforestation.
Give a better message for a missing variable in a substitution.
compiler/instmap.m
Give a better message for inst_merge failing.
compiler/notes/compiler_design.m
Document the new modules.
library/varset.m
Add varset__select to project a varset's names and values
onto a set of variables.
doc/user_guide.texi
Document deforestation.
Remove a reference to a non-existent option, --no-specialize.
util/mdemangle.c
profiler/demangle.m
tests/misc_tests/mdemangle_test.{exp,inp}
Handle the `DeforestationIn__' predicate names introduced by
deforestation, similar to the `IntroducedFrom__' for lambda goals.
New files:
deforest.m Deforestation.
pd_cost.m Cost estimation.
pd_debug.m Debugging output.
pd_info.m State type and version control.
pd_term.m Termination checking.
pd_util.m Utility predicates
224 lines
7.3 KiB
Mathematica
224 lines
7.3 KiB
Mathematica
%-----------------------------------------------------------------------------%
|
|
% Copyright (C) 1998 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: pd_debug.m
|
|
% Main author: stayl.
|
|
%
|
|
% Debugging routines for partial deduction.
|
|
%-----------------------------------------------------------------------------%
|
|
:- module pd_debug.
|
|
|
|
:- interface.
|
|
|
|
:- import_module pd_info, hlds_goal, hlds_pred.
|
|
:- import_module list, string.
|
|
|
|
:- pred pd_debug__do_io(pred(io__state, io__state)::pred(di, uo) is det,
|
|
pd_info::pd_info_di, pd_info::pd_info_uo) is det.
|
|
|
|
:- pred pd_debug__output_goal(string::in, hlds_goal::in,
|
|
pd_info::pd_info_di, pd_info::pd_info_uo) is det.
|
|
|
|
:- pred pd_debug__search_version_result(maybe_version::in,
|
|
pd_info::pd_info_di, pd_info::pd_info_uo) is det.
|
|
|
|
:- pred pd_debug__register_version(pred_proc_id::in, version_info::in,
|
|
pd_info::pd_info_di, pd_info::pd_info_uo) is det.
|
|
|
|
:- pred pd_debug__write_instmap(pd_info::pd_info_di,
|
|
pd_info::pd_info_uo) is det.
|
|
|
|
:- pred pd_debug__message(string::in, list(string__poly_type)::in,
|
|
pd_info::pd_info_di, pd_info::pd_info_uo) is det.
|
|
|
|
:- pred pd_debug__message(term__context::in, string::in,
|
|
list(string__poly_type)::in,
|
|
pd_info::pd_info_di, pd_info::pd_info_uo) is det.
|
|
|
|
:- pred pd_debug__write(T::in, pd_info::pd_info_di,
|
|
pd_info::pd_info_uo) is det.
|
|
|
|
:- pred pd_debug__write_pred_proc_id_list(list(pred_proc_id)::in,
|
|
pd_info::pd_info_di, pd_info::pd_info_uo) is det.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
:- implementation.
|
|
|
|
:- import_module globals, hlds_module, hlds_out, instmap, options.
|
|
:- import_module instmap, prog_out, goal_util.
|
|
:- import_module bool, io, set, std_util.
|
|
|
|
pd_debug__do_io(Pred) -->
|
|
pd_debug__do_output(DoOutput),
|
|
( { DoOutput = yes } ->
|
|
pd_info_get_io_state(IO0),
|
|
{ call(Pred, IO0, IO1) },
|
|
{ io__flush_output(IO1, IO) },
|
|
pd_info_set_io_state(IO)
|
|
;
|
|
[]
|
|
).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
pd_debug__search_version_result(MaybeVersion) -->
|
|
pd_info_get_module_info(ModuleInfo),
|
|
pd_debug__do_io(pd_debug__search_version_result_2(ModuleInfo,
|
|
MaybeVersion)).
|
|
|
|
:- pred pd_debug__search_version_result_2(module_info::in, maybe_version::in,
|
|
io__state::di, io__state::uo) is det.
|
|
|
|
pd_debug__search_version_result_2(ModuleInfo, MaybeVersion) -->
|
|
(
|
|
{ MaybeVersion = no_version },
|
|
io__write_string("Specialised version not found.\n")
|
|
;
|
|
{ MaybeVersion = version(exact, _, _, _, _) },
|
|
io__write_string("Exact match found.\n")
|
|
;
|
|
{ MaybeVersion = version(more_general,
|
|
PredProcId, Version, _, _) },
|
|
io__write_string("More general version.\n"),
|
|
pd_debug__output_version(ModuleInfo, PredProcId, Version, no)
|
|
).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
pd_debug__register_version(PredProcId, Version) -->
|
|
pd_info_get_module_info(ModuleInfo),
|
|
{ Register = lambda([IO0::di, IO::uo] is det, (
|
|
io__write_string("Registering version:\n", IO0, IO1),
|
|
pd_debug__output_version(ModuleInfo, PredProcId, Version,
|
|
no, IO1, IO)
|
|
)) },
|
|
pd_debug__do_io(Register).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- pred pd_debug__output_version(module_info::in, pred_proc_id::in,
|
|
version_info::in, bool::in, io__state::di, io__state::uo) is det.
|
|
|
|
pd_debug__output_version(ModuleInfo, PredProcId,
|
|
Version, WriteUnfoldedGoal) -->
|
|
{ Version = version_info(Goal - GoalInfo, _, _, _, InstMap,
|
|
InitialCost, CostDelta, Parents, _) },
|
|
{ predicate_name(ModuleInfo, PredId, PredName) },
|
|
io__write_string(PredName),
|
|
io__write_string(": (PredProcId :"),
|
|
{ PredProcId = proc(PredId, ProcId) },
|
|
{ pred_id_to_int(PredId, PredInt) },
|
|
{ proc_id_to_int(ProcId, ProcInt) },
|
|
io__write_int(PredInt),
|
|
io__write_string("-"),
|
|
io__write_int(ProcInt),
|
|
io__write_string(")"),
|
|
io__nl,
|
|
io__write_string(" initial cost: "),
|
|
io__write_int(InitialCost),
|
|
io__nl,
|
|
io__write_string(" cost delta: "),
|
|
io__write_int(CostDelta),
|
|
io__nl,
|
|
{ goal_info_get_nonlocals(GoalInfo, NonLocals) },
|
|
{ module_info_pred_proc_info(ModuleInfo,
|
|
PredId, ProcId, _, ProcInfo) },
|
|
{ proc_info_varset(ProcInfo, VarSet) },
|
|
{ instmap__restrict(InstMap, NonLocals, InstMap1) },
|
|
hlds_out__write_instmap(InstMap1, VarSet, yes, 1),
|
|
io__nl,
|
|
hlds_out__write_goal(Goal - GoalInfo, ModuleInfo, VarSet, no, 1, ""),
|
|
io__nl,
|
|
io__write_string("Parents: "),
|
|
{ set__to_sorted_list(Parents, ParentsList) },
|
|
io__write_list(ParentsList, ", ",
|
|
pd_debug__write_pred_proc_id(ModuleInfo)),
|
|
io__nl,
|
|
( { WriteUnfoldedGoal = yes } ->
|
|
{ proc_info_goal(ProcInfo, ProcGoal) },
|
|
io__write_string("Unfolded goal\n"),
|
|
hlds_out__write_goal(ProcGoal,
|
|
ModuleInfo, VarSet, no, 1, ""),
|
|
io__nl
|
|
;
|
|
[]
|
|
).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
pd_debug__write_instmap -->
|
|
pd_info_get_instmap(InstMap),
|
|
pd_info_get_proc_info(ProcInfo),
|
|
{ proc_info_varset(ProcInfo, VarSet) },
|
|
pd_debug__do_io(hlds_out__write_instmap(InstMap, VarSet, yes, 1)).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
pd_debug__write_pred_proc_id_list(PredProcIds) -->
|
|
pd_info_get_module_info(ModuleInfo),
|
|
pd_debug__do_io(
|
|
io__write_list(PredProcIds, ", ",
|
|
pd_debug__write_pred_proc_id(ModuleInfo))
|
|
).
|
|
|
|
:- pred pd_debug__write_pred_proc_id(module_info::in, pred_proc_id::in,
|
|
io__state::di, io__state::uo) is det.
|
|
|
|
pd_debug__write_pred_proc_id(ModuleInfo, proc(PredId, ProcId)) -->
|
|
hlds_out__write_pred_proc_id(ModuleInfo, PredId, ProcId).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
pd_debug__output_goal(Msg, Goal - GoalInfo) -->
|
|
pd_debug__do_output(DoOutput),
|
|
( { DoOutput = yes } ->
|
|
pd_info_get_proc_info(ProcInfo),
|
|
{ proc_info_varset(ProcInfo, VarSet) },
|
|
pd_info_get_instmap(InstMap),
|
|
pd_info_get_io_state(IO0),
|
|
pd_info_get_module_info(ModuleInfo),
|
|
{
|
|
io__write_string(Msg, IO0, IO1),
|
|
goal_util__goal_vars(Goal - GoalInfo, Vars),
|
|
instmap__restrict(InstMap, Vars, InstMap1),
|
|
hlds_out__write_instmap(InstMap1, VarSet, yes, 1, IO1, IO2),
|
|
io__nl(IO2, IO3),
|
|
hlds_out__write_goal(Goal - GoalInfo, ModuleInfo,
|
|
VarSet, yes, 1, "", IO3, IO4),
|
|
io__nl(IO4, IO5),
|
|
io__flush_output(IO5, IO)
|
|
},
|
|
pd_info_set_io_state(IO)
|
|
;
|
|
[]
|
|
).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- pred pd_debug__do_output(bool::out, pd_info::pd_info_di,
|
|
pd_info::pd_info_uo) is det.
|
|
|
|
pd_debug__do_output(DoDebug) -->
|
|
pd_info_get_io_state(IO0),
|
|
{ globals__io_lookup_bool_option(debug_pd, DoDebug, IO0, IO1) },
|
|
pd_info_set_io_state(IO1).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
pd_debug__message(Context, Fmt, Args) -->
|
|
pd_debug__do_io(prog_out__write_context(Context)),
|
|
pd_debug__do_io(io__format(Fmt, Args)).
|
|
|
|
pd_debug__message(Fmt, Args) -->
|
|
pd_debug__do_io(io__format(Fmt, Args)).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
pd_debug__write(Thing) -->
|
|
pd_debug__do_io(io__write(Thing)).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|