for review: factorring out the number of type parameters
Zoltan Somogyi
zs at cs.mu.OZ.AU
Mon May 18 17:46:53 AEST 1998
Estimated hours taken: 2
compiler/stack_layout.m:
Move the number of type parameters from the label layout structures
to the start of the vector of type parameter locations. Since the
vectors are very often common, this saves one word on a large fraction
of all label layout tables.
Fix some documentation rot.
runtime/mercury_stack_layout.h:
Make the corresponding change in the C description of the layout
structure.
runtime/mercury_trace_internal.c:
Make the corresponding change in the C code that accesses the layout
structure.
Fix an earlier oversight: don't try to materialize type parameters
that aren't live.
With --trace all, this change reduces the size of the data segment in the
executable by a bit over 200 kb, which is about 3.5%.
Zoltan.
cvs diff: Diffing .
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing bytecode
cvs diff: Diffing bytecode/test
cvs diff: Diffing compiler
Index: compiler/stack_layout.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/stack_layout.m,v
retrieving revision 1.12
diff -u -u -r1.12 stack_layout.m
--- stack_layout.m 1998/05/16 07:30:47 1.12
+++ stack_layout.m 1998/05/18 07:36:20
@@ -18,7 +18,7 @@
% Modifications by zs.
%
% NOTE: If you make changes in this file, you may also need to modify
-% runtime/mercury_stack_layout.h
+% runtime/mercury_stack_layout.h.
%
%---------------------------------------------------------------------------%
%
@@ -88,8 +88,10 @@
% live data pairs (Word *) - pointer to vector of pairs
% containing MR_Live_Lval and MR_Live_Type
% live data names (Word *) - pointer to vector of String
-% # of type parameters (Integer)
% type parameters (Word *) - pointer to vector of MR_Live_Lval
+% in which the first word is an Integer
+% giving the number of entries in the vector;
+% a NULL pointer means no type parameters
%
% The internal label number field holds either the real label number
% (which is always strictly positive), 0 indicating the entry label,
@@ -107,14 +109,17 @@
% of the variable (it is either a pointer to a string, or a NULL pointer,
% which means that the variable has no name).
%
-% The number of type parameters is never stored as it is not needed --
-% the type parameter vector will simply be indexed by the type variable's
-% variable number stored within pseudo-typeinfos inside the elements
-% of the live data pairs vectors. Since we allocate type variable numbers
-% sequentially, the type parameter vector will usually be dense. However,
-% after all variables whose types include e.g. type variable 2 have gone
-% out of scope, variables whose types include type variable 3 may still
-% be around.
+% If the number of type parameters is not zero, we store the number,
+% so that the code that needs the type parameters can materialize
+% all the type parameters from their location descriptions in one go.
+% This is an optimization, since the type parameter vector could simply
+% be indexed on demand by the type variable's variable number stored within
+% pseudo-typeinfos inside the elements of the live data pairs vectors.
+%
+% Since we allocate type variable numbers sequentially, the type parameter
+% vector will usually be dense. However, after all variables whose types
+% include e.g. type variable 2 have gone out of scope, variables whose
+% types include type variable 3 may still be around.
%
% We need detailed information about the variables that are live at an
% internal label in two kinds of circumstances. Stack layout information
@@ -136,9 +141,9 @@
% to the live data names vector will be NULL unless the first condition
% holds for the label (i.e. the label is used in execution tracing).
%
-% XXX: Presently, type parameter vectors are not created, and
-% inst information is ignored. We also do not yet enable procid stack
-% layouts for profiling, since profiling does not yet use stack layouts.
+% XXX: Presently, inst information is ignored. We also do not yet enable
+% procid stack layouts for profiling, since profiling does not yet use
+% stack layouts.
%
%---------------------------------------------------------------------------%
@@ -423,17 +428,20 @@
NamesRval),
{ set__to_sorted_list(TVarLocnSet, TVarLocns) },
- stack_layout__construct_type_param_locn_vector(TVarLocns, 1,
- TypeParamLocs),
- stack_layout__get_next_cell_number(CNum1),
- { TypeParamRval = create(0, TypeParamLocs, no, CNum1,
- "stack_layout_type_param_locn_vector") },
- { list__length(TypeParamLocs, TypeParamsLength) },
- { TypeParamLengthRval = const(int_const(TypeParamsLength)) },
-
+ ( { TVarLocns = [] } ->
+ { TypeParamRval = const(int_const(0)) }
+ ;
+ stack_layout__construct_type_param_locn_vector(
+ TVarLocns, 1, TypeParamLocs),
+ { list__length(TypeParamLocs, TypeParamsLength) },
+ { LengthRval = const(int_const(TypeParamsLength)) },
+ { Vector = [yes(LengthRval) | TypeParamLocs] },
+ stack_layout__get_next_cell_number(CNum1),
+ { TypeParamRval = create(0, Vector, no, CNum1,
+ "stack_layout_type_param_locn_vector") }
+ ),
{ RvalList = [yes(VarLengthRval), yes(LiveValRval),
- yes(NamesRval), yes(TypeParamLengthRval),
- yes(TypeParamRval)] }
+ yes(NamesRval), yes(TypeParamRval)] }
;
{ RvalList = [yes(VarLengthRval)] }
).
cvs diff: Diffing compiler/notes
cvs diff: Diffing doc
cvs diff: Diffing extras
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/Togl-1.2
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/references
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing library
cvs diff: Diffing lp_solve
cvs diff: Diffing lp_solve/lp_examples
cvs diff: Diffing profiler
cvs diff: Diffing runtime
Index: runtime/mercury_stack_layout.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_stack_layout.h,v
retrieving revision 1.5
diff -u -u -r1.5 mercury_stack_layout.h
--- mercury_stack_layout.h 1998/05/16 07:28:19 1.5
+++ mercury_stack_layout.h 1998/05/18 06:53:53
@@ -257,8 +257,22 @@
typedef struct MR_Stack_Layout_Vars_Struct {
MR_Stack_Layout_Var *MR_slvs_pairs;
String *MR_slvs_names;
- Integer MR_slvs_tvar_count;
MR_Live_Lval *MR_slvs_tvars;
+ /*
+ ** If MR_slvs_tvars == NULL, there are no
+ ** type parameters. If it is != NULL, then
+ ** (Integer) MR_slvs_tvars[0] is the index
+ ** of the highest numbered type parameter,
+ ** and MR_slvs_tvars[i] for values of i
+ ** between 1 and (Integer) MR_slvs_tvars[0]
+ ** (both inclusive) describe the location
+ ** of the typeinfo structure for the type
+ ** variable of the corresponding number.
+ ** If one of these type variables is not
+ ** referred to by the variables described in
+ ** MR_slvs_pairs, the corresponding entry
+ ** will be zero.
+ */
} MR_Stack_Layout_Vars;
#define MR_name_if_present(vars, i) \
Index: runtime/mercury_trace_internal.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_trace_internal.c,v
retrieving revision 1.1
diff -u -u -r1.1 mercury_trace_internal.c
--- mercury_trace_internal.c 1998/05/16 07:28:27 1.1
+++ mercury_trace_internal.c 1998/05/18 07:50:00
@@ -236,6 +236,7 @@
{
Word *type_params;
bool succeeded;
+ int count;
int i;
if (var_count == 0) {
@@ -243,15 +244,25 @@
return;
}
- type_params = checked_malloc((vars->MR_slvs_tvar_count + 1)
- * sizeof(Word));
- /* type_params should look like a typeinfo; type_params[0] is empty */
- for (i = 0; i < vars->MR_slvs_tvar_count; i++) {
- type_params[i+1] = MR_trace_lookup_live_lval(
- vars->MR_slvs_tvars[i], &succeeded);
- if (!succeeded) {
- fatal_error("missing type param in MR_trace_browse");
+ if (vars->MR_slvs_tvars != NULL) {
+ count = (int) (Integer) vars->MR_slvs_tvars[0];
+ type_params = checked_malloc((count + 1) * sizeof(Word));
+
+ /*
+ ** type_params should look like a typeinfo;
+ ** type_params[0] is empty and will not be referred to
+ */
+ for (i = 1; i <= count; i++) {
+ if (vars->MR_slvs_tvars[i] != 0) {
+ type_params[i] = MR_trace_lookup_live_lval(
+ vars->MR_slvs_tvars[i], &succeeded);
+ if (!succeeded) {
+ fatal_error("missing type param in MR_trace_browse");
+ }
+ }
}
+ } else {
+ type_params = NULL;
}
for (i = 0; i < var_count; i++) {
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/diff
cvs diff: Diffing scripts
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
cvs diff: Diffing tests/general
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/term
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trial
cvs diff: Diffing util
More information about the developers
mailing list