Files
mercury/compiler/commit_gen.m
Zoltan Somogyi 0fcd954631 Implement the runtime system for region-based memory management.
Estimated hours taken: 50 by quan, 8 by zs
Branches: main

Implement the runtime system for region-based memory management. This includes
the implementation of regions, region instructions and support for
backtracking.

Support for backtracking deals with preventing the destruction of backward
live regions and provides instant reclaiming of space in regions when
backtracking reaches a resume point. This support now exploits the data
in rbmm_goal_info structures. The mechanisms are documented in the
papers/rbmm module of the Mercury repository.

compiler/code_info.m:
	Change the option to control the addition of region operations from
	use_region to region_analysis so that no region operations are
	introduced when compiling a compiler in .rbmm grade. This is temporary,
	as is the re-adding of --region-analysis option.

	Make use of rbmm_goal_info when generating backtrack-supporting code
	for commit operations.

compiler/commit_gen.m:
	Make use of rbmm_goal_info when generating backtrack-supporting code.

compiler/disj_gen.m:
	Make use of rbmm_goal_info when generating semidet disjunction.
	Correct one error so that use_region_disj_later is not generated in
	the code for the first disjunct.

compiler/ite_gen.m:
	Make use of rbmm_goal_info.

compiler/options.m:
	Modify the size of disj_protect(ion) to 1 instead of 2.

library/region_builtin.m:
	Change the region builtins to call to the correct region operations
	in the region runtime system.

	Add a predicate to print out profiling information for region-based
	memory management.

runtime/mercury_region.h
runtime/mercury_region.c
	New files containing the implementation of the region runtime system.

	This runtime system supports its own profiling and debugging messages,
	which can be turned on and off via the MR_RBMM_PROFILING and
	MR_RBMM_DEBUG flags.

	Note that these files are still in a state of flux.

runtime/mercury_types.h:
	Add typedefs needed by declarations in mercury_region.h.

runtime/mercury_conf_paramh:
	Document MR_RBMM_PROFILING and MR_RBMM_DEBUG.

runtime/mercury_imp.h:
	#include mercury_region.h in rbmm grades.

runtime/Mmakefile:
	Link the region runtime system into the runtime system of Mercury.

tests/tabling/Mmakefile:
	Avoid accidental matches on the "mm" in "rbmm".
2007-10-09 07:59:55 +00:00

122 lines
4.4 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et
%---------------------------------------------------------------------------%
% Copyright (C) 1997-1998, 2003-2007 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.prog_data.
:- import_module set.
%---------------------------------------------------------------------------%
:- pred generate_scope(scope_reason::in, code_model::in, hlds_goal_info::in,
set(prog_var)::in, hlds_goal::in, code_tree::out,
code_info::in, code_info::out) is det.
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
:- implementation.
:- import_module libs.compiler_util.
:- import_module libs.tree.
:- import_module ll_backend.code_gen.
:- import_module list.
:- import_module maybe.
:- import_module pair.
:- import_module string.
%---------------------------------------------------------------------------%
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(this_file, "generate_scope: trace_goal")
;
generate_commit(OuterCodeModel, OuterGoalInfo,
ForwardLiveVarsBeforeGoal, Goal, Code, !CI)
).
:- pred generate_commit(code_model::in, hlds_goal_info::in, set(prog_var)::in,
hlds_goal::in, code_tree::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(this_file,
"generate_commit: 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 = tree_list([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 = tree_list([PreCommit, GoalCode, Commit])
)
;
OuterCodeModel = model_non,
code_gen.generate_goal(InnerCodeModel, Goal, Code, !CI)
).
%---------------------------------------------------------------------------%
:- func this_file = string.
this_file = "commit_gen.m".
%---------------------------------------------------------------------------%
:- end_module commit_gen.
%---------------------------------------------------------------------------%