mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-18 07:15:19 +00:00
Estimated hours taken: 16 Branches: main Change the mechanism we use to transmit a representation of procedure bodies from the compiler to the declarative debugger from Mercury terms to a bytecode. This achieves two objectives. First, the code for Mercury terms worked only as long as the compiler used the same data representation as the program being compiled; it generated incorrect term representations when e.g. the compiler generating code in reserve tag grades. Second, the new representation is significantly smaller. The total size of the .c files in the compiler directory in grade asm_fast.gc.decldebug.tr is now only 213 Mb compared with 313 Mb previously (a reduction of almost one third). The executable file size of a compiler compiled in asm_fast.gc.decldebug.tr is now only 59 Mb, compare with 64 Mb previously (a reduction of almost 8%, and there is room for further reductions). The overhead of the decldebug grade when compared with a plain debug grade now only about 25%, compared to about 36% before. The downside is that the procedure body representation must now be constructed by the declarative debugger from the bytecode instead of being available directly. We minimize this effect by using a cache to ensure that each procedure's body representation is constructed at most once. browser/declarative_execution.m: Do not include the procedure representation in call nodes. This should make the annotated trace somewhat smaller and quicker to construct. Since this code will be executed many more times than the number of procedures whose bodies are needed by subterm dependency tracking, the overall effect of this change on speed should be positive. Instead, add code to construct procedure body representations on demand from bytecode, which is reachable indirectly through the call's node label label structure. browser/declarative_tree.m: Conform to the new structure of call nodes. compiler/prog_rep.m: Replace the code that generated the term representation of procedure bodies with code that generates a bytecode representation of procedure bodies. compiler/static_term.m: Delete this file, since it is no longer needed. compiler/notes/compiler_design.html: Document the deletion of static_term.m. mdbcomp/program_representation.m: Add the definitions related to the structure of the bytecode that are shared by the compiler and the declarative debugger. This includes the representations of determinisms. compiler/code_model.m: To prevent requiring double maintenance, use the facilities now in mdbcomp/program_representation.m to encode determinisms. runtime/mercury_stack_layout.h: compiler/layout.m: compiler/layout_out.m: compiler/opt_debug.m: compiler/stack_layout.m: Replace the proc layout field holding the procedure representation term with the field holding the procedure representation bytecode. runtime/mercury_grade.h: Record the breaking of backward compatibility in debug grades. compiler/options.m: Add an option for use by compiler implementors while implementing changes like this. runtime/mercury_trace_base.[ch]: Add the hash table that caches the results of bytecode translations. trace/mercury_trace_declarative.c: Do not include procedure representations when constructing call nodes, since it is no longer necessary. trace/mercury_trace_internal.c: Update the code that deals with procedure bodies to use the bytecode representation.
87 lines
3.6 KiB
Mathematica
87 lines
3.6 KiB
Mathematica
%-----------------------------------------------------------------------------%
|
|
% Copyright (C) 2000, 2003-2005 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.
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- module hlds__code_model.
|
|
|
|
% This module defines the `code_model' data type, and associated procedures.
|
|
% The `code_model' type is a simplified version of the `determinism' type
|
|
% that is defined in prog_data.m. It ignores most of the distinctions in
|
|
% the determinism type and keeps only the distinctions that are important
|
|
% for code generation.
|
|
|
|
% We define this in a different module than the `determinism' type because
|
|
% it is only used by some of the different back-ends, not all of them.
|
|
% It is used by the MLDS, LLDS, and bytecode back-ends, but not by the
|
|
% Aditi-RL back-end.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- interface.
|
|
|
|
:- import_module hlds__hlds_goal.
|
|
:- import_module hlds__hlds_pred.
|
|
:- import_module parse_tree__prog_data.
|
|
|
|
:- type code_model
|
|
---> model_det % functional & total
|
|
; model_semi % just functional
|
|
; model_non. % not functional
|
|
|
|
:- pred determinism_to_code_model(determinism, code_model).
|
|
:- mode determinism_to_code_model(in, out) is det.
|
|
:- mode determinism_to_code_model(out, in) is multi.
|
|
|
|
:- pred proc_info_interface_code_model(proc_info::in, code_model::out) is det.
|
|
|
|
:- pred goal_info_get_code_model(hlds_goal_info::in, code_model::out) is det.
|
|
|
|
% Construct a representation of the interface determinism of a
|
|
% procedure. The code we have chosen is not sequential; instead
|
|
% it encodes the various properties of each determinism.
|
|
% This must match the encoding of MR_Determinism in
|
|
% mercury_stack_layout.h.
|
|
%
|
|
% The 8 bit is set iff the context is first_solution.
|
|
% The 4 bit is set iff the min number of solutions is more than zero.
|
|
% The 2 bit is set iff the max number of solutions is more than zero.
|
|
% The 1 bit is set iff the max number of solutions is more than one.
|
|
:- func represent_determinism(determinism) = int.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module mdbcomp.program_representation.
|
|
:- import_module int.
|
|
|
|
determinism_to_code_model(det, model_det).
|
|
determinism_to_code_model(semidet, model_semi).
|
|
determinism_to_code_model(nondet, model_non).
|
|
determinism_to_code_model(multidet, model_non).
|
|
determinism_to_code_model(cc_nondet, model_semi).
|
|
determinism_to_code_model(cc_multidet, model_det).
|
|
determinism_to_code_model(erroneous, model_det).
|
|
determinism_to_code_model(failure, model_semi).
|
|
|
|
proc_info_interface_code_model(ProcInfo, CodeModel) :-
|
|
proc_info_interface_determinism(ProcInfo, Determinism),
|
|
determinism_to_code_model(Determinism, CodeModel).
|
|
|
|
goal_info_get_code_model(GoalInfo, CodeModel) :-
|
|
goal_info_get_determinism(GoalInfo, Determinism),
|
|
determinism_to_code_model(Determinism, CodeModel).
|
|
|
|
represent_determinism(det) = detism_rep(det_rep).
|
|
represent_determinism(semidet) = detism_rep(semidet_rep).
|
|
represent_determinism(nondet) = detism_rep(nondet_rep).
|
|
represent_determinism(multidet) = detism_rep(multidet_rep).
|
|
represent_determinism(erroneous) = detism_rep(erroneous_rep).
|
|
represent_determinism(failure) = detism_rep(failure_rep).
|
|
represent_determinism(cc_nondet) = detism_rep(cc_nondet_rep).
|
|
represent_determinism(cc_multidet) = detism_rep(cc_multidet_rep).
|
|
|
|
%-----------------------------------------------------------------------------%
|