[m-rev.] diff: more .c file size reductions
Zoltan Somogyi
zs at cs.mu.OZ.AU
Fri May 21 08:04:02 AEST 2004
Generate smaller C source files. In common cell types, never emit fields that
are one-element arrays; emit a scalar field instead. This saves a surprisingly
large number of {} characters in debug grades, saving around 1.5% in .c file
size.
compiler/llds.m:
Change the definition of the common_cell_arg_group type to make this
possible.
compiler/llds_out.m:
Output cells based on the now riches type.
compiler/global_data.m:
Generate scalar fields instead of one-element array fields.
Zoltan.
cvs diff: Diffing .
Index: global_data.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/global_data.m,v
retrieving revision 1.4
diff -u -b -r1.4 global_data.m
--- global_data.m 19 May 2004 03:59:09 -0000 1.4
+++ global_data.m 19 May 2004 04:33:38 -0000
@@ -316,10 +316,8 @@
TypeAndArgGroups) :-
(
LaterArgsTypes = [],
- list__length(RevArgsSoFar, NumArgsSoFar),
- TypeGroup = CurType - NumArgsSoFar,
- TypeAndArgGroup = common_cell_arg_group(CurType,
- NumArgsSoFar, list__reverse(RevArgsSoFar)),
+ make_arg_groups(CurType, RevArgsSoFar,
+ TypeGroup, TypeAndArgGroup),
TypeGroups = [TypeGroup],
TypeAndArgGroups = [TypeAndArgGroup]
;
@@ -329,19 +327,31 @@
[NextArg | RevArgsSoFar], MoreArgsTypes,
TypeGroups, TypeAndArgGroups)
;
- list__length(RevArgsSoFar, NumArgsSoFar),
threshold_group_types(NextType, [NextArg],
MoreArgsTypes,
TypeGroupsTail, TypeAndArgGroupsTail),
- TypeGroup = CurType - NumArgsSoFar,
- TypeAndArgGroup = common_cell_arg_group(CurType,
- NumArgsSoFar, list__reverse(RevArgsSoFar)),
+ make_arg_groups(CurType, RevArgsSoFar,
+ TypeGroup, TypeAndArgGroup),
TypeGroups = [TypeGroup | TypeGroupsTail],
TypeAndArgGroups = [TypeAndArgGroup |
TypeAndArgGroupsTail]
)
).
+:- pred make_arg_groups(llds_type::in, list(rval)::in,
+ pair(llds_type, int)::out, common_cell_arg_group::out) is det.
+
+make_arg_groups(Type, RevArgs, TypeGroup, TypeAndArgGroup) :-
+ ( RevArgs = [Arg] ->
+ TypeGroup = Type - 1,
+ TypeAndArgGroup = common_cell_ungrouped_arg(Type, Arg)
+ ;
+ list__length(RevArgs, NumArgs),
+ list__reverse(RevArgs, Args),
+ TypeGroup = Type - NumArgs,
+ TypeAndArgGroup = common_cell_grouped_args(Type, NumArgs, Args)
+ ).
+
search_static_cell_offset(Info, DataAddr, Offset, Rval) :-
DataAddr = data_addr(Info ^ module_name, DataName),
DataName = common(CellNum, _),
@@ -361,11 +371,21 @@
offset_into_group([], _, _) :-
error("offset_into_group: offset out of bounds").
offset_into_group([Group | Groups], Offset, Rval) :-
- Group = common_cell_arg_group(_, NumRvalsInGroup, Rvals),
+ (
+ Group = common_cell_grouped_args(_, NumRvalsInGroup, Rvals),
( Offset < NumRvalsInGroup ->
list__index0_det(Rvals, Offset, Rval)
;
- offset_into_group(Groups, Offset - NumRvalsInGroup, Rval)
+ offset_into_group(Groups, Offset - NumRvalsInGroup,
+ Rval)
+ )
+ ;
+ Group = common_cell_ungrouped_arg(_, GroupRval),
+ ( Offset = 0 ->
+ Rval = GroupRval
+ ;
+ offset_into_group(Groups, Offset - 1, Rval)
+ )
).
get_static_cells(Info) =
Index: llds.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/llds.m,v
retrieving revision 1.302
diff -u -b -r1.302 llds.m
--- llds.m 12 May 2004 14:24:20 -0000 1.302
+++ llds.m 17 May 2004 08:43:15 -0000
@@ -73,15 +73,24 @@
).
:- type common_cell_arg_group
- ---> common_cell_arg_group(
+ ---> common_cell_grouped_args(
llds_type, % The shared type of the
% fields in the group.
int, % The number of fields in the
% group. This will contain the
% length of the list in the
% third argument, but computed
- % only once.
+ % only once. It ought to be
+ % more than one; if a field
+ % cannot be grouped with
+ % neighbouring values of the
+ % same type, it should be
+ % stored as an ungrouped arg.
list(rval) % The field values themselves.
+ )
+ ; common_cell_ungrouped_arg(
+ llds_type, % The type of the field.
+ rval % The field value.
).
:- type common_cell_type_and_value
Index: llds_out.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/llds_out.m,v
retrieving revision 1.231
diff -u -b -r1.231 llds_out.m
--- llds_out.m 19 May 2004 03:59:21 -0000 1.231
+++ llds_out.m 19 May 2004 04:33:39 -0000
@@ -2679,7 +2679,8 @@
:- func common_group_get_rvals(common_cell_arg_group) = list(rval).
-common_group_get_rvals(common_cell_arg_group(_, _, Rvals)) = Rvals.
+common_group_get_rvals(common_cell_grouped_args(_, _, Rvals)) = Rvals.
+common_group_get_rvals(common_cell_ungrouped_arg(_, Rval)) = [Rval].
%-----------------------------------------------------------------------------%
@@ -2821,13 +2822,21 @@
output_cons_arg_group_types([], _, _, !IO).
output_cons_arg_group_types([Group | Groups], Indent, ArgNum, !IO) :-
io__write_string(Indent, !IO),
- Group = common_cell_arg_group(Type, ArraySize, _),
+ (
+ Group = common_cell_grouped_args(Type, ArraySize, _),
output_llds_type(Type, !IO),
io__write_string(" f", !IO),
io__write_int(ArgNum, !IO),
io__write_string("[", !IO),
io__write_int(ArraySize, !IO),
- io__write_string("];\n", !IO),
+ io__write_string("];\n", !IO)
+ ;
+ Group = common_cell_ungrouped_arg(Type, _),
+ output_llds_type(Type, !IO),
+ io__write_string(" f", !IO),
+ io__write_int(ArgNum, !IO),
+ io__write_string(";\n", !IO)
+ ),
output_cons_arg_group_types(Groups, Indent, ArgNum + 1, !IO).
% Given an rval, figure out the type it would have as
@@ -2905,7 +2914,8 @@
output_cons_arg_groups([], !IO).
output_cons_arg_groups([Group | Groups], !IO) :-
- Group = common_cell_arg_group(Type, _, Rvals),
+ (
+ Group = common_cell_grouped_args(Type, _, Rvals),
io__write_string("{\n", !IO),
(
direct_field_int_constant(Type) = yes,
@@ -2915,11 +2925,23 @@
;
output_cons_arg_group_elements(Type, Rvals, !IO)
),
+ io__write_string("}", !IO)
+ ;
+ Group = common_cell_ungrouped_arg(Type, Rval),
+ (
+ direct_field_int_constant(Type) = yes,
+ project_int_constant(Rval, Int)
+ ->
+ io__write_int(Int, !IO)
+ ;
+ output_rval_as_type(Rval, Type, !IO)
+ )
+ ),
( Groups \= [] ->
- io__write_string("},\n", !IO),
+ io__write_string(",\n", !IO),
output_cons_arg_groups(Groups, !IO)
;
- io__write_string("}\n", !IO)
+ io__write_string("\n", !IO)
).
:- pred output_cons_arg_group_elements(llds_type::in, list(rval)::in,
cvs diff: Diffing notes
--------------------------------------------------------------------------
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