[m-dev.] for review: counters for label and cell number allocation

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Aug 9 16:42:19 AEST 2000


On 09-Aug-2000, Zoltan Somogyi <zs at cs.mu.OZ.AU> wrote:
> Consistently use counters to allocate label numbers and cell numbers
> throughout the compiler.

That part of the log message is not quite correct -- this change
does not modify the MLDS back-end, which still uses ints to allocate
label numbers.

> diff -u -r1.77 code_gen.m
> --- compiler/code_gen.m	2000/04/26 05:40:04	1.77
> +++ compiler/code_gen.m	2000/08/07 15:00:05
> @@ -268,19 +270,23 @@
>  	),
>  
>  		% Construct a c_procedure structure with all the information.
> -	Proc = c_procedure(Name, Arity, proc(PredId, ProcId),
> -		Instructions, ContainsReconstruction).
> +	code_info__get_label_counter(LabelCounter, CodeInfo, _),
> +		% For historical reasons, the code generator allocates labels
> +		% by remembering the last allocated label number, while the
> +		% various optimizations remember the next label number to be
> +		% allocated. The addition in the last argument performs the
> +		% conversion.
> +	Proc = c_procedure(Name, Arity, proc(PredId, ProcId), Instructions,
> +		ProcLabel, LabelCounter, ContainsReconstruction).

That comment looks like it is now obsolete?

> --- compiler/vn_debug.m	1998/03/03 17:36:33	1.30
> +++ compiler/vn_debug.m	1999/12/03 13:12:15
> @@ -400,7 +400,7 @@
>  
>  vn_debug__cost_header_msg(Header) -->
>  	vn_debug__cost_msg_flag(Flag),
> -	opt_debug__msg(Flag, Header).
> +	opt_debug__msg(Flag, -1, Header).

> --- compiler/opt_debug.m        2000/05/10 18:06:57     1.104
> +++ compiler/opt_debug.m        2000/08/07 09:11:44
> @@ -19,8 +19,8 @@
> 
>  :- import_module io, bool, list, assoc_list, std_util.
> 
>  -:- pred opt_debug__msg(bool, string, io__state, io__state).
>  -:- mode opt_debug__msg(in, in, di, uo) is det.
>  +:- pred opt_debug__msg(bool, int, string, io__state, io__state).
>  +:- mode opt_debug__msg(in, in, in, di, uo) is det.

`opt_debug__msg' is an exported procedure, so it should have some
documentation, and the documentation should say what the meaning of
the `int' parameter is, in particular the meaning of the mysterious
value `-1'.

Apart from that, this change looks fine.
But I do have one final suggestion:

> compiler/code_gen.m:
> 
>  :- pred generate_proc_code(pred_info::in, proc_info::in,
>         proc_id::in, pred_id::in, module_info::in, globals::in,
> -       global_data::in, global_data::out, int::in, int::out,
> +       global_data::in, global_data::out, counter::in, counter::out,
>         c_procedure::out) is det.

That's an improvement.  Still, `counter' is not that informative.
It would be even better to define type aliases, e.g.

	:- type label_counter == counter.
	:- type cell_counter == counter.

and to then use those rather than plain `counter' where appropriate.

However, I suspect that implementing that suggestion would be a
non-trivial amount of work.  I'm happy for you to commit this change
as is, since it is definitely an improvement on the status quo.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list