[m-rev.] for review: LLDS code gen change for AGC
Fergus Henderson
fjh at cs.mu.OZ.AU
Fri Nov 7 05:28:42 AEDT 2003
For review by Zoltan.
Estimated hours taken: 3
Branches: main
Another step towards supporting accurate GC for the LLDS back-end:
modify the LLDS code generator to allocate the proper forwarding pointer
slots for type_infos and typeclass_infos.
compiler/unify_gen.m:
compiler/code_info.m:
compiler/var_locn.m:
When allocating type_infos or typeclass_infos on the heap,
if accurate garbage collection is enabled then ensure that we
reserve a word before the start of the object. This word is
used by the collector to store a forwarding pointer.
For ordinary objects, we store the forwarding pointer in the
old copy of the object, but we can't clobber the old copies of
type_infos and typeclass_infos, since they might be used _during_
garbage collection.
Workspace: /home/jupiter/fjh/ws-jupiter/mercury
Index: compiler/code_info.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/code_info.m,v
retrieving revision 1.281
diff -u -d -r1.281 code_info.m
--- compiler/code_info.m 5 Nov 2003 03:17:35 -0000 1.281
+++ compiler/code_info.m 6 Nov 2003 17:46:55 -0000
@@ -3020,7 +3020,9 @@
:- pred code_info__assign_expr_to_var(prog_var::in, rval::in, code_tree::out,
code_info::in, code_info::out) is det.
-:- pred code_info__assign_cell_to_var(prog_var::in, tag::in,
+ % code_info__assign_cell_to_var(Var, ReserveWordAtStart, Ptag, Vector,
+ % Size, TypeMsg, Code, !CI)
+:- pred code_info__assign_cell_to_var(prog_var::in, bool::in, tag::in,
list(maybe(rval))::in, maybe(term_size_value)::in, string::in,
code_tree::out, code_info::in, code_info::out) is det.
@@ -3157,11 +3159,13 @@
),
code_info__set_var_locn_info(VarLocnInfo, !CI).
-code_info__assign_cell_to_var(Var, Ptag, Vector, Size, TypeMsg, Code, !CI) :-
+code_info__assign_cell_to_var(Var, ReserveWordAtStart, Ptag, Vector, Size,
+ TypeMsg, Code, !CI) :-
code_info__get_var_locn_info(!.CI, VarLocnInfo0),
code_info__get_static_cell_info(!.CI, StaticCellInfo0),
- var_locn__assign_cell_to_var(Var, Ptag, Vector, Size, TypeMsg, Code,
- StaticCellInfo0, StaticCellInfo, VarLocnInfo0, VarLocnInfo),
+ var_locn__assign_cell_to_var(Var, ReserveWordAtStart, Ptag, Vector,
+ Size, TypeMsg, Code, StaticCellInfo0, StaticCellInfo,
+ VarLocnInfo0, VarLocnInfo),
code_info__set_static_cell_info(StaticCellInfo, !CI),
code_info__set_var_locn_info(VarLocnInfo, !CI).
Index: compiler/unify_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/unify_gen.m,v
retrieving revision 1.135
diff -u -d -r1.135 unify_gen.m
--- compiler/unify_gen.m 31 Oct 2003 03:27:30 -0000 1.135
+++ compiler/unify_gen.m 6 Nov 2003 18:24:57 -0000
@@ -375,10 +375,7 @@
unify_gen__var_types(!.CI, Args, ArgTypes),
unify_gen__generate_cons_args(Args, ArgTypes, Modes, ModuleInfo,
Rvals),
- VarType = code_info__variable_type(!.CI, Var),
- unify_gen__var_type_msg(VarType, VarTypeMsg),
- code_info__assign_cell_to_var(Var, Ptag, Rvals, Size, VarTypeMsg, Code,
- !CI).
+ unify_gen__construct_cell(Var, Ptag, Rvals, Size, Code, !CI).
unify_gen__generate_construction_2(shared_remote_tag(Ptag, Sectag),
Var, Args, Modes, Size, _, Code, !CI) :-
code_info__get_module_info(!.CI, ModuleInfo),
@@ -387,10 +384,7 @@
Rvals0),
% the first field holds the secondary tag
Rvals = [yes(const(int_const(Sectag))) | Rvals0],
- VarType = code_info__variable_type(!.CI, Var),
- unify_gen__var_type_msg(VarType, VarTypeMsg),
- code_info__assign_cell_to_var(Var, Ptag, Rvals, Size, VarTypeMsg, Code,
- !CI).
+ unify_gen__construct_cell(Var, Ptag, Rvals, Size, Code, !CI).
unify_gen__generate_construction_2(shared_local_tag(Bits1, Num1),
Var, _Args, _Modes, _, _, empty, !CI) :-
code_info__assign_const_to_var(Var,
@@ -672,8 +666,8 @@
yes(const(int_const(NumArgs)))
| PredArgs
],
- code_info__assign_cell_to_var(Var, 0, Vector, no, "closure",
- Code, !CI)
+ code_info__assign_cell_to_var(Var, no, 0, Vector, no,
+ "closure", Code, !CI)
).
:- pred unify_gen__generate_extra_closure_args(list(prog_var)::in, lval::in,
@@ -746,6 +740,34 @@
),
unify_gen__generate_cons_args_2(Vars, Types, UniModes, ModuleInfo,
RVals).
+
+:- pred unify_gen__construct_cell(prog_var::in, tag::in, list(maybe(rval))::in,
+ maybe(term_size_value)::in, code_tree::out,
+ code_info::in, code_info::out) is det.
+
+unify_gen__construct_cell(Var, Ptag, Rvals, Size, Code, !CI) :-
+ VarType = code_info__variable_type(!.CI, Var),
+ unify_gen__var_type_msg(VarType, VarTypeMsg),
+ % If we're doing accurate GC, then
+ % for types which hold RTTI that will be traversed
+ % by the collector at GC-time, we need to allocate
+ % an extra word at the start, to hold the forwarding
+ % pointer. Normally we would just overwrite the
+ % first word of the object in the "from" space,
+ % but this can't be done for objects which will be
+ % referenced during the garbage collection process.
+ (
+ code_info__get_globals(!.CI, Globals),
+ globals__get_gc_method(Globals, GCMethod),
+ GCMethod = accurate,
+ is_introduced_type_info_type(VarType)
+ ->
+ ReserveWordAtStart = yes
+ ;
+ ReserveWordAtStart = no
+ ),
+ code_info__assign_cell_to_var(Var, ReserveWordAtStart, Ptag, Rvals,
+ Size, VarTypeMsg, Code, !CI).
%---------------------------------------------------------------------------%
Index: compiler/var_locn.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/var_locn.m,v
retrieving revision 1.12
diff -u -d -r1.12 var_locn.m
--- compiler/var_locn.m 27 Oct 2003 05:42:37 -0000 1.12
+++ compiler/var_locn.m 6 Nov 2003 18:25:37 -0000
@@ -151,14 +151,18 @@
:- pred var_locn__assign_expr_to_var(prog_var::in, rval::in, code_tree::out,
var_locn_info::in, var_locn_info::out) is det.
-% var_locn__assign_cell_to_var(Var, Ptag, Vector, TypeMsg, Code,
-% StaticCellInfo0, StaticCellInfo,
+% var_locn__assign_cell_to_var(Var, ReserveWordAtStart, Ptag, Vector,
+% TypeMsg, Code, StaticCellInfo0, StaticCellInfo,
% VarLocnInfo0, VarLocnInfo)
% Generates code to assign to Var a pointer, tagged by Ptag, to
% the cell whose contents are given by the other arguments,
% and updates the state of VarLocnInfo0 accordingly.
+% If ReserveWordAtStart is yes, and the cell is allocated on
+% the heap (rather than statically), then reserve an extra
+% word immediately before the allocated object, for the
+% garbage collector to use to hold a forwarding pointer.
-:- pred var_locn__assign_cell_to_var(prog_var::in, tag::in,
+:- pred var_locn__assign_cell_to_var(prog_var::in, bool::in, tag::in,
list(maybe(rval))::in, maybe(term_size_value)::in, string::in,
code_tree::out, static_cell_info::in, static_cell_info::out,
var_locn_info::in, var_locn_info::out) is det.
@@ -330,6 +334,7 @@
:- import_module libs__tree.
:- import_module ll_backend__code_util.
:- import_module ll_backend__exprn_aux.
+:- import_module hlds__error_util.
:- import_module int, string, bag, require, getopt, varset, term.
@@ -787,8 +792,8 @@
%----------------------------------------------------------------------------%
-var_locn__assign_cell_to_var(Var, Ptag, MaybeRvals0, SizeInfo, TypeMsg, Code,
- !StaticCellInfo, !VLI) :-
+var_locn__assign_cell_to_var(Var, ReserveWordAtStart, Ptag, MaybeRvals0,
+ SizeInfo, TypeMsg, Code, !StaticCellInfo, !VLI) :-
(
SizeInfo = yes(SizeSource),
(
@@ -817,23 +822,35 @@
var_locn__assign_const_to_var(Var, CellPtrRval, !VLI),
Code = empty
;
- var_locn__assign_dynamic_cell_to_var(Var, Ptag, MaybeRvals,
- MaybeOffset, TypeMsg, Code, !VLI)
+ var_locn__assign_dynamic_cell_to_var(Var, ReserveWordAtStart,
+ Ptag, MaybeRvals, MaybeOffset, TypeMsg, Code, !VLI)
).
-:- pred var_locn__assign_dynamic_cell_to_var(prog_var::in, tag::in,
+:- pred var_locn__assign_dynamic_cell_to_var(prog_var::in, bool::in, tag::in,
list(maybe(rval))::in, maybe(int)::in, string::in, code_tree::out,
var_locn_info::in, var_locn_info::out) is det.
-var_locn__assign_dynamic_cell_to_var(Var, Ptag, Vector, MaybeOffset,
- TypeMsg, Code, !VLI) :-
+var_locn__assign_dynamic_cell_to_var(Var, ReserveWordAtStart, Ptag, Vector,
+ MaybeOffset, TypeMsg, Code, !VLI) :-
var_locn__check_var_is_unknown(!.VLI, Var),
var_locn__select_preferred_reg_or_stack_check(!.VLI, Var, Lval),
var_locn__get_var_name(!.VLI, Var, VarName),
list__length(Vector, Size),
+ ( ReserveWordAtStart = yes ->
+ ( MaybeOffset = yes(_) ->
+ % Accurate GC and term profiling both want to own
+ % the word before this object
+ sorry(this_file,
+ "accurate GC combined with term size profiling")
+ ;
+ TotalOffset = yes(1)
+ )
+ ;
+ TotalOffset = MaybeOffset
+ ),
CellCode = node([
- incr_hp(Lval, yes(Ptag), MaybeOffset, const(int_const(Size)),
+ incr_hp(Lval, yes(Ptag), TotalOffset, const(int_const(Size)),
TypeMsg)
- string__append("Allocating heap for ", VarName)
]),
@@ -2302,5 +2319,12 @@
var_locn__set_acquired(A, VI, VI ^ acquired := A).
var_locn__set_locked(L, VI, VI ^ locked := L).
var_locn__set_exceptions(E, VI, VI ^ exceptions := E).
+
+%----------------------------------------------------------------------------%
+
+:- func this_file = string.
+this_file = "var_locn.m".
+
+:- end_module ll_backend__var_locn.
%----------------------------------------------------------------------------%
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list