mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-17 14:57:03 +00:00
Estimated hours taken: 24 Branches: main Predicates with many variables, such as some of those in zm_enums.m, tickle pretty bad behavior in the liveness and stack_alloc passes. This is because those passes manipulate sets of variables, which in such cases are large sets of variables, and the quadratic behavior of repeated operations on sets represents as sorted lists hurts us. This diff changes the representation of the sets of variables involved in those two passes, which are the prebirth, postbirth, predeath and postdeath sets in goal_infos, to be values of an abstract type (set_of_progvar). By default, these are implemented using tree_bitsets, which have much better worst case behaviour that set_ordlists. When compiling zm_enums with debugging enabled, this diff speeds up the liveness pass by about half and the stack alloc pass by about a third, with the overall speedup being about 6% (due to some other expensive passes). On tools/speedtest -l, the result is a 3.4% slowdown. Since the slowdown worsens slightly if I make the abstract representation of sets of prog_vars be the existing representation (an ordinary set), I think this slowdown is due to the conversions that are now required in some places between the abstract representation and an explicit set(prog_var) representation. As such, as other uses of set(progvar) get converted to set_of_progvar, this slowdown should disappear. compiler/set_of_var.m: The new module that contains the set_of_progvar abstract data type. This module also contains a copy of the code of the graph_colour module. Since the set_of_progvar type is private, this is necessary if we want all the set operations done by graph colouring (which does the bulk of the work of the stack alloc pass) to use the preferred set representation. compiler/graph_colour.m: Note that this module is no longer used. compiler/stack_alloc.m: compiler/liveness.m: Switch over to using the new module. compiler/parse_tree.m: Include set_of_var among the modules of this package. (It is in this package because the prog_var type is defined in this package.) compiler/test_bitset.m: A module that allows new set implementations to be tested. It is an extended and specialized version of the bitset_tester module from tests/hard_coded. compiler/hlds_llds.m: Use the set_of_progvar type for the prebirth, postbirth, predeath and postdeath sets in goal_infos, and for other liveness-related sets of variables. compiler/code_info.m: Some of the fields of the code_info structure represent sets of variables, and some of the predicates defined by this module have arguments that are sets of variables. If these sets represent entities that are computed from prebirth, postbirth, predeath and postdeath sets or from other goal_info fields that have been changed to the set_of_progvar representation, change them to use the set_of_progvar representation as well, or, in a few cases, to plain sorted lists. Conform to the above change. compiler/proc_type.m: Add a utility predicate to operate of set_of_progvar. Replace a lambda expression with a named predicate. compiler/quantification.m: Until now, quantification.m used its own private abstract type (defined as tree_bitset) to represent sets. Make it use set_of_progvar instead, since it has the same purpose. This eliminates a potential maintenance problem. compiler/call_gen.m: compiler/code_gen.m: compiler/commit_gen.m: compiler/delay_construct.m: compiler/disj_gen.m: compiler/hlds_out_goal.m: compiler/hlds_rtti.m: compiler/interval.m: compiler/ite_gen.m: compiler/live_vars.m: compiler/lookup_switch.m: compiler/lookup_util.m: compiler/matching.m: compiler/pd_util.m: compiler/polymorphism.m: compiler/pragma_c_gen.m: compiler/proc_gen.m: compiler/simplify.m: compiler/stack_opt.m: compiler/store_alloc.m: compiler/string_switch.m: compiler/structure_reuse.lbu.m: compiler/structure_reuse.lfu.m: compiler/structure_sharing.domain.m: compiler/switch_util.m: compiler/trace_gen.m: compiler/tupling.m: compiler/unify_gen.m: compiler/unused_args.m: Conform to the above change. library/map.m: Add a utility predicate, map.select_sorted_list, which functions the same way as map.select, but takes a sorted list as argument instead of a set. library/set_ordlist.m: Bring the interface of this module closer to set.m and tree_bitset.m to make them more easily interchangeable. This required adding the predicates is_non_empty and is_singleton, as well as adding predicate forms of union_list and intersect_list. I also added missing type_spec pragmas for some predicates frequently used by the compiler. library/tree_bitset.m: Bring the interface of this module closer to set.m and set_ordlist.m to make them more easily interchangeable. This required adding the predicates is_non_empty and is_singleton, and both function and predicate forms of union_list and intersect_list. Fix an old bug in the difference operation. Given SetA - SetB, if SetA was the empty set, then this operation would correctly return the empty set if SetB was small (represented by a leaf list), but would incorrectly return SetB if it was large (represented by an interior node list).
112 lines
4.2 KiB
Mathematica
112 lines
4.2 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=4 sw=4 et
|
|
%---------------------------------------------------------------------------%
|
|
% Copyright (C) 1997-1998, 2003-2007, 2009-2011 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: commit_gen.m.
|
|
% Main authors: conway, fjh, zs.
|
|
%
|
|
% The predicates of this module generate code for performing commits.
|
|
%
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- module ll_backend.commit_gen.
|
|
:- interface.
|
|
|
|
:- import_module hlds.code_model.
|
|
:- import_module hlds.hlds_goal.
|
|
:- import_module ll_backend.code_info.
|
|
:- import_module ll_backend.llds.
|
|
:- import_module parse_tree.set_of_var.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- pred generate_scope(scope_reason::in, code_model::in, hlds_goal_info::in,
|
|
set_of_progvar::in, hlds_goal::in, llds_code::out,
|
|
code_info::in, code_info::out) is det.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module ll_backend.code_gen.
|
|
% :- import_module parse_tree.prog_data.
|
|
% :- import_module set.
|
|
|
|
:- import_module cord.
|
|
:- import_module maybe.
|
|
:- import_module require.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
generate_scope(Reason, OuterCodeModel, OuterGoalInfo,
|
|
ForwardLiveVarsBeforeGoal, Goal, Code, !CI) :-
|
|
(
|
|
Reason = trace_goal(_, MaybeTraceRuntimeCond, _, _, _),
|
|
MaybeTraceRuntimeCond = yes(_)
|
|
->
|
|
% These goals should have been transformed into other forms of goals
|
|
% by simplify.m at the end of semantic analysis.
|
|
unexpected($module, $pred, "trace_goal")
|
|
;
|
|
generate_commit(OuterCodeModel, OuterGoalInfo,
|
|
ForwardLiveVarsBeforeGoal, Goal, Code, !CI)
|
|
).
|
|
|
|
:- pred generate_commit(code_model::in, hlds_goal_info::in, set_of_progvar::in,
|
|
hlds_goal::in, llds_code::out, code_info::in, code_info::out) is det.
|
|
|
|
generate_commit(OuterCodeModel, OuterGoalInfo, ForwardLiveVarsBeforeGoal,
|
|
Goal, Code, !CI) :-
|
|
AddTrailOps = should_add_trail_ops(!.CI, OuterGoalInfo),
|
|
AddRegionOps = should_add_region_ops(!.CI, OuterGoalInfo),
|
|
|
|
Goal = hlds_goal(_, InnerGoalInfo),
|
|
InnerCodeModel = goal_info_get_code_model(InnerGoalInfo),
|
|
(
|
|
OuterCodeModel = model_det,
|
|
(
|
|
InnerCodeModel = model_det,
|
|
code_gen.generate_goal(InnerCodeModel, Goal, Code, !CI)
|
|
;
|
|
InnerCodeModel = model_semi,
|
|
unexpected($module, $pred, "semidet model in det context")
|
|
;
|
|
InnerCodeModel = model_non,
|
|
prepare_for_det_commit(AddTrailOps, AddRegionOps,
|
|
ForwardLiveVarsBeforeGoal, InnerGoalInfo, CommitInfo,
|
|
PreCommit, !CI),
|
|
code_gen.generate_goal(InnerCodeModel, Goal, GoalCode, !CI),
|
|
generate_det_commit(CommitInfo, Commit, !CI),
|
|
Code = PreCommit ++ GoalCode ++ Commit
|
|
)
|
|
;
|
|
OuterCodeModel = model_semi,
|
|
(
|
|
InnerCodeModel = model_det,
|
|
code_gen.generate_goal(InnerCodeModel, Goal, Code, !CI)
|
|
;
|
|
InnerCodeModel = model_semi,
|
|
code_gen.generate_goal(InnerCodeModel, Goal, Code, !CI)
|
|
;
|
|
InnerCodeModel = model_non,
|
|
prepare_for_semi_commit(AddTrailOps, AddRegionOps,
|
|
ForwardLiveVarsBeforeGoal, InnerGoalInfo, CommitInfo,
|
|
PreCommit, !CI),
|
|
code_gen.generate_goal(InnerCodeModel, Goal, GoalCode, !CI),
|
|
generate_semi_commit(CommitInfo, Commit, !CI),
|
|
Code = PreCommit ++ GoalCode ++ Commit
|
|
)
|
|
;
|
|
OuterCodeModel = model_non,
|
|
code_gen.generate_goal(InnerCodeModel, Goal, Code, !CI)
|
|
).
|
|
|
|
%---------------------------------------------------------------------------%
|
|
:- end_module ll_backend.commit_gen.
|
|
%---------------------------------------------------------------------------%
|