[m-dev.] [reuse] diff: stricter decision for candidates for reuse
Nancy Mazur
Nancy.Mazur at cs.kuleuven.ac.be
Sat Sep 23 02:20:03 AEDT 2000
Hi,
just this small diff...
===================================================================
Estimated hours taken: 0.10
Make the selection of candidates for reuse strict: don't indicate
different constructions to reuse the same dead cell (which is absurd
of course). The reason why it was differently before was to
simply report indication on where one could reuse what. But now
we have to really decide. (Later on, that decision could be made
a bit smarter, now it's just based on a LIFO strategy... )
sr_reuse.m:
Only reuse a dead cell if it is not already reused by a
previous construction.
( including preparatory code for allowing other cons-id's
than the cons being constructed to be reused for that
construction)
Index: sr_reuse.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/sr_reuse.m,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 sr_reuse.m
--- sr_reuse.m 2000/09/19 10:02:13 1.1.2.1
+++ sr_reuse.m 2000/09/22 15:12:43
@@ -842,19 +842,52 @@
direct_reuses_try_to_reuse( CONS_ID, DRsIN, Var, DRsOUT ) :-
DRsIN = direct_reuses( Gin, L),
- map__search( Gin, CONS_ID, LIST_REUSES_in),
+ map__keys( Gin, ALL_CONSES),
+ select_most_matching_cons( ALL_CONSES, CONS_ID, SELECTED_CONS_ID),
+ map__lookup( Gin, SELECTED_CONS_ID, LIST_REUSES_in),
direct_reuse_list_try_to_reuse( LIST_REUSES_in, Var, LIST_REUSES_out),
- map__det_update( Gin, CONS_ID, LIST_REUSES_out, Gout),
+ map__det_update( Gin, SELECTED_CONS_ID, LIST_REUSES_out, Gout),
DRsOUT = direct_reuses( Gout, L).
+:- pred select_most_matching_cons( list(cons_id), cons_id, cons_id).
+:- mode select_most_matching_cons( in, in, out ) is semidet.
+
+select_most_matching_cons( LIST, C, MATCH ) :-
+ (
+ list__member( C, LIST )
+ ->
+ MATCH = C
+ ;
+ % cons_id_arity(C, ARITY),
+ % select_same_arity_cons( LIST, ARITY, MATCH)
+ fail
+ ).
+
+ % picks out the first cons_id occuring in the given list that
+ % has the same arity as the given cons_id.
+:- pred select_same_arity_cons( list(cons_id), int, cons_id).
+:- mode select_same_arity_cons( in, in, out) is semidet.
+
+select_same_arity_cons( LIST, ARITY, MATCH ):-
+ LIST = [ CONS | REST ],
+ (
+ cons_id_arity( CONS, ARITY )
+ ->
+ MATCH = CONS
+ ;
+ select_same_arity_cons( REST, ARITY, MATCH )
+ ).
+
+
:- pred direct_reuse_list_try_to_reuse( list(direct_reuse), prog_var,
list(direct_reuse) ).
-:- mode direct_reuse_list_try_to_reuse( in, out, out) is det.
+:- mode direct_reuse_list_try_to_reuse( in, out, out) is semidet.
direct_reuse_list_try_to_reuse( Lin, Var, Lout) :-
(
Lin = [ Fin | R ]
->
+ direct_reuse_get_candidates(Fin, 0),
direct_reuse_get_var(Fin, Var),
direct_reuse_update_candidates( Fin, 1, Fout ),
direct_reuse_list_order( [Fout | R ], Lout)
--------------------------------------------------------------------------
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