[m-rev.] for review: untupling transformation

Julien Fischer juliensf at cs.mu.OZ.AU
Tue Feb 1 16:33:35 AEDT 2005


On Tue, 1 Feb 2005, Peter Wang wrote:

> > > +:- pred expandable_arg_mode((mode)::in) is semidet.
> > > +
> > > +expandable_arg_mode(in_mode).
> > > +expandable_arg_mode(out_mode).
> > > +
> >
> > Does this compiler bootstrap when this transformation is turned on?
>
> Yes, and it runs slower too :-)
>

That was to be expected; the important thing is that it worked.

> A relative diff follows.  In addition to the changes relating to
> your comments, I also made it:
>
> - perform the transformation for procedures which are exported (this was not
> possible in my first attempt at it, but now there is no reason not to);
>

You should add a comment to the top the module that it should be possible
for this transformation to work across module boundaries by exporting the
goal templates in the `.opt' files.

> - not go into an infinite loop trying to expand recursive types, such as
> 	:- type t ---> t(t).
> or
> 	:- type u ---> u(v).
> 	:- type v ---> v(u).
>
>


>
> diff -u -r ws3.old/compiler/options.m ws3/compiler/options.m
> --- ws3.old/compiler/options.m	2005-02-01 14:42:45.000000000 +1100
> +++ ws3/compiler/options.m	2005-02-01 14:21:22.000000000 +1100
> @@ -3704,6 +3704,11 @@
>  		"\tEnable exception analysis.  Identify those",
>  		"\tprocedures that will not throw an exception.",
>  		"\tSome optimizations can make use of this information."
> +		% ,
> +		% "--untuple",
> +		% "\tExpand out procedure arguments when the argument type",
> +		% "\tis a tuple or a type with exactly one functor.",
> +		% "\tNote this is almost always a pessimization."
>  	]).
s/Note/Note: /

>
>  :- pred options_help_hlds_llds_optimization(io::di, io::uo) is det.
> diff -u -r ws3.old/compiler/untupling.m ws3/compiler/untupling.m
> --- ws3.old/compiler/untupling.m	2005-02-01 14:42:45.000000000 +1100
> +++ ws3/compiler/untupling.m	2005-02-01 15:28:07.000000000 +1100
> @@ -8,14 +8,13 @@
>  %
>  % Author: wangp.
>  %
> -% This module takes an HLDS structure as its input and transforms the
> -% locally-defined procedures as follows: if the formal parameter of a
> -% procedure has a type consisting of a single function symbol then that
> -% parameter is expanded into multiple parameters (one for each field of the
> -% functor).  Tuple types are also expanded.  The argument lists are expanded
> -% as deeply (flatly) as possible.
> +% This module takes the HLDS and transforms the locally-defined procedures as
> +% follows: if the formal parameter of a procedure has a type consisting of a
> +% single function symbol then that parameter is expanded into multiple
> +% parameters (one for each field of the functor).  Tuple types are also
> +% expanded.  The argument lists are expanded as deeply (flatly) as possible.
>  %
> -% e.g. for the following module,
> +% e.g. for the following predicate,

That should be "for the following predicate and types"

>  %
>  %	:- type t ---> t(u).
>  %	:- type u ---> u(v, w).
> @@ -34,7 +33,51 @@
>  % made to update all the calls in the module which refer to the old procedures
>  % to call the transformed procedures.  This is done by adding deconstruction
>  % and construction unifications as needed, which can later be simplified by a
> -% simplification pass.
> +% simplification pass (not called from this module).
> +%
> +% e.g. a call to the predicate above,
> +%
> +%	:- pred g(T::in) is det.
> +%	g(_) :-
> +%		A = 1,
> +%		B = "foo",
> +%		C = w(A, B),
> +%		D = v1,
> +%		E = u(D, C),
> +%		F = t(E),
> +%		f(F).
> +%
> +% is changed to this:
> +%
> +%	g(_) :-
> +%		A = 1,
> +%		B = "foo",
> +%		C = w(A, B),
> +%		D = v1,
> +%		E = u(D, C),
> +%		F = t(E),
> +%		F = t(G),	% added deconstructions
> +%		G = u(H, I),
> +%		I = w(J, K),
> +%		f_untupled(H, J, K).
> +%
> +% which, after simplication, should become:
> +%
> +%	g(_) :-
> +%		A = 1,
> +%		B = "foo",
> +%		D = v1,
> +%		f_untupled(D, A, B).
> +%
> +% Limitations:
> +%
> +% - When a formal parameter is expanded, both the parameter's type and mode
> +% have to be expanded.  Currently only arguments with in and out modes can
> +% be expanded at present, as I don't know how to do it for the general case.
> +% It should be enough for the majority of code.
> +%

Currently ... at present ... seems a little redundant.

> +% - Some predicates may or may not be expandable but won't be right
now,
> +% because I don't understand the features they use (see expand_args_in_pred).
>  %

I suggest either module qualifying that reference or adding the word
`below' after it (So the reader knows that it is from this module).

...

>  %-----------------------------------------------------------------------------%
> diff -u -r ws3.old/doc/user_guide.texi ws3/doc/user_guide.texi
> --- ws3.old/doc/user_guide.texi	2005-02-01 14:40:29.000000000 +1100
> +++ ws3/doc/user_guide.texi	2005-02-01 14:43:11.000000000 +1100
> @@ -6764,6 +6764,13 @@
>  exception.  This information can be used by some
>  optimization passes.
>
> + at c @sp 1
> + at c @item --untuple
> + at c @findex --untuple
> + at c Expand out procedure arguments when the argument type
> + at c is a tuple or a type with exactly one functor.
> + at c Note this is almost always a pessimization.
> +
s/Note/Note: /

Julien.
--------------------------------------------------------------------------
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