[m-rev.] for review: switch arms for more than one cons_id

Ian MacLarty maclarty at csse.unimelb.edu.au
Tue Dec 18 17:38:00 AEDT 2007


On Fri, Dec 14, 2007 at 06:59:29PM +1100, Zoltan Somogyi wrote:
> For review by anyone. I have tested this in several grades, but not yet at
> several optimization levels (except for the test that lead to the filing
> of Mantis bug 32). I intend to do those tests over the weekend.
> 
> Zoltan.
> 
...
> compiler/tag_switch.m:
> 	Reorganize the way these modules work. We can't generate the code of
> 	each arm in place anymore, since it is now possible for more than one
> 	cons_id to call for the execution of the same code. Instead, in
> 	string_switch.m, we generate the codes of all the arms all at once,
> 	and construct the hash index afterwards. (This approach simplifies
> 	the code significantly.)
> 	
> 	In tag switches (unlike string switches), we can get locality benefits
> 	if the code testing for a cons_id is close to the code for that
> 	cons_id, so we still try to put them next to each other when such
> 	a locality benefit is available.
> 
> 	In both modules, the new approach uses a utility predicate in
> 	switch_case.m to actually generate the code of each switch arm,
> 	eliminating several copies the same code in the old versions of these

missing "of"

...
> compiler/switch_gen.m:
> 	Delete the code for tagging cons_ids, since that functionality is now
> 	in switch_util.m.
> 
> 	The old version of this module could call the code generator to produce
> 	(i.e. materialize) the switched-on variable repeatedly. We now produce
> 	the variable once, and do the switch on the resulting rval.
> 
> compiler/unify_gen.m:
> 	Use the information about cheaper tag tests in the type constructor's
> 	entry in the HLDS type table, instead of trying to recompute it
> 	every time.
> 
> 	Provide the predicates switch_gen.m now needs to perform tag tests
> 	on rvals, as opposed to variables, and against possible more than one

"possibly"

...
> Index: compiler/Mercury.options
> ===================================================================
> RCS file: /home/mercury/mercury1/repository/mercury/compiler/Mercury.options,v
> retrieving revision 1.32
> diff -u -b -r1.32 Mercury.options
> --- compiler/Mercury.options	14 Aug 2007 01:52:27 -0000	1.32
> +++ compiler/Mercury.options	14 Dec 2007 07:44:38 -0000
> @@ -51,6 +51,9 @@
>  
>  # Bug workarounds
>  
> +# This works around bug 32 in Mantis.
> +MCFLAGS-check_hlds.check_typeclass = --no-loop-invariants
> +
>  # This is the same bug as tests/valid/ho_and_type_spec_bug2.
>  MCFLAGS-mode_robdd.tfeirn = -O3
>  MCFLAGS-mode_robdd.implications = -O0

This file isn't mentioned in the log message.

...
> Index: compiler/code_info.m
> ===================================================================
> RCS file: /home/mercury/mercury1/repository/mercury/compiler/code_info.m,v
> retrieving revision 1.354
> diff -u -b -r1.354 code_info.m
> --- compiler/code_info.m	26 Nov 2007 05:13:18 -0000	1.354
> +++ compiler/code_info.m	13 Dec 2007 00:34:36 -0000
> @@ -745,11 +745,17 @@
>      %
>  :- func lookup_type_defn(code_info, mer_type) = hlds_type_defn.
>  
> +:- func lookup_cheaper_tag_test(code_info, mer_type) = maybe_cheaper_tag_test.
> +
>  :- func filter_region_vars(code_info, set(prog_var)) = set(prog_var).
>  
> -    % Given a constructor id, and a variable (so that we can work out the
> -    % type of the constructor), determine correct tag (representation)
> -    % of that constructor.
> +    % XXX check if used

Is this XXX meant to be here?  If so, it's not clear to me what should
be checked.

> +    % Given a constructor id, and the type to which it belongs, determine
> +    % the tag representing that constructor.
> +    %
> +:- func cons_id_to_tag_for_type(code_info, mer_type, cons_id) = cons_tag.
> +
> +    % As cons_id_to_tag_for_type, but get the type from the variable.

I haven't looked at the rest of the diff.

Ian.
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list