[m-rev.] Re: [m-dev.] deforestation missed opportunities
Simon Taylor
stayl at cs.mu.OZ.AU
Mon Apr 9 17:31:05 AEST 2001
On Mon, Apr 09, 2001 at 12:13:45AM +1000, Fergus Henderson wrote:
> In the following example, I think deforestation ought to be able to
> optimize the call to max_list([A,B,C]. It does unfold the call to max_list/1.
> But it doesn't go the next step and unfold the call to max_list_aux/2.
>
> :- module max.
> :- interface.
> :- import_module int, list.
>
> :- func max_triple(int, int, int) = int.
>
> :- func max_list(list(int)) = int.
>
> :- implementation.
> :- import_module require.
>
> max_triple(A,B,C) = max_list([A,B,C]).
>
> max_list([]) = _ :- error("max of empty list").
> max_list([X|Xs]) = max_list_aux(X, Xs).
>
> :- func max_list_aux(int, list(int)) = int.
> max_list_aux(X, []) = X.
> max_list_aux(X, [Y|Ys]) = max_list_aux(int__max(X, Y), Ys).
Estimated hours taken: 0.5
Branches: main
Fix a problem reported by Fergus where deforestation was missing
opportunities for optimization.
compiler/deforest.m:
Run simplification on each goal before processing it
to take advantage of any extra information provided by
inlined sub-goals.
Index: deforest.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/deforest.m,v
retrieving revision 1.21
diff -u -u -r1.21 deforest.m
--- deforest.m 2001/04/07 14:04:33 1.21
+++ deforest.m 2001/04/09 02:00:24
@@ -110,9 +110,17 @@
PredInfo0, ProcInfo0) },
pd_info_init_unfold_info(proc(PredId, ProcId), PredInfo0, ProcInfo0),
{ proc_info_goal(ProcInfo0, Goal0) },
- deforest__goal(Goal0, Goal1),
+
+ % Inlining may have created some opportunities for simplification.
+ pd_info_get_io_state(IOState0),
+ { globals__io_get_globals(Globals, IOState0, IOState) },
+ pd_info_set_io_state(IOState),
+ { simplify__find_simplifications(no, Globals, Simplifications) },
+ pd_util__simplify_goal(Simplifications, Goal0, Goal1),
+
+ deforest__goal(Goal1, Goal2),
pd_info_get_proc_info(ProcInfo1),
- { proc_info_set_goal(ProcInfo1, Goal1, ProcInfo2) },
+ { proc_info_set_goal(ProcInfo1, Goal2, ProcInfo2) },
pd_info_get_changed(Changed),
( { Changed = yes } ->
@@ -139,9 +147,6 @@
% then we re-run determinism analysis. As with
% inlining.m, this avoids problems with inlining
% erroneous procedures.
- pd_info_get_io_state(IO10),
- { globals__io_get_globals(Globals, IO10, IO11) },
- pd_info_set_io_state(IO11),
{ det_infer_proc(PredId, ProcId, ModuleInfo4,
ModuleInfo5, Globals, _, _, _) }
;
--------------------------------------------------------------------------
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