[m-dev.] [reuse] for review: reuse cells with different tags

Peter Ross peter.ross at miscrit.be
Tue Mar 13 20:54:46 AEDT 2001


On Tue, Mar 13, 2001 at 05:42:08AM +1100, Fergus Henderson wrote:
> That looks good, Pete.
> I do have a couple of suggestions:
> 
> On 12-Mar-2001, Peter Ross <peter.ross at miscrit.be> wrote:
> > +++ compiler/hlds_goal.m	2001/03/12 17:11:10
> > @@ -524,7 +524,7 @@
> >  :- type cell_to_reuse
> >  	---> cell_to_reuse(
> >  		prog_var,
> > -		cons_id,
> > +		list(cons_id),
> >  		list(bool)      % A `no' entry means that the corresponding
> >  				% argument already has the correct value
> >  				% and does not need to be filled in.
> 
> You should document the meaning of the list(cons_id) field.
> 
> > Index: compiler/ml_unify_gen.m
> > ===================================================================
> > RCS file: /home/mercury1/repository/mercury/compiler/ml_unify_gen.m,v
> > retrieving revision 1.16.2.10
> > diff -u -r1.16.2.10 ml_unify_gen.m
> > --- compiler/ml_unify_gen.m	2001/03/09 14:11:46	1.16.2.10
> > +++ compiler/ml_unify_gen.m	2001/03/12 17:11:13
> > @@ -1061,12 +1067,16 @@
> >  
> >  		ml_gen_var(Var, Var1Lval),
> >  		ml_gen_var(ReuseVar, Var2Lval),
> > -		{ ReusePrimaryTag = PrimaryTag ->
> > +
> > +		{ list__filter((pred(ReuseTag::in) is semidet :-
> > +				ReuseTag \= PrimaryTag
> > +			), ReusePrimaryTags, DifferentTags) },
> > +		{ DifferentTags = [] ->
> >  			Var2Rval = lval(Var2Lval)
> >  		;
> >  			Var2Rval = mkword(PrimaryTag,
> > -					binop(body, lval(Var2Lval),
> > -					ml_gen_mktag(ReusePrimaryTag)))
> > +					unop(std_unop(strip_tag),
> > +					lval(Var2Lval)))
> >  		},
> 
> `strip_tag' is slightly more expensive that `body', so you should try to
> use `body' when possible, i.e. when the old tag is known.  In particular,
> in the else case here you should call list__remove_duplicates on
> ReusePrimaryTags, and then see if the result is a singleton list;
> if so, the contents of that list is the old tag value and you
> should use `body' to remove it.
> 

I have already placed the change in to use body rather then strip_tag
when possible.


===================================================================


Estimated hours taken: 0.25
Branches: reuse

Apply some suggested fixes from fjh.

compiler/hlds_goal.m:
    Document the list(cons_id) field in cell_to_reuse.
    
compiler/ml_unify_gen.m:
    Remove all duplicate tags.  This increases the chance that we have
    a singleton list and can use the quicker body operation instead of
    strip_tag to replace the tag.


Index: hlds_goal.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_goal.m,v
retrieving revision 1.76.2.10
diff -u -r1.76.2.10 hlds_goal.m
--- hlds_goal.m	2001/03/12 20:24:31	1.76.2.10
+++ hlds_goal.m	2001/03/13 09:41:04
@@ -524,7 +524,8 @@
 :- type cell_to_reuse
 	---> cell_to_reuse(
 		prog_var,
-		list(cons_id),
+		list(cons_id),	% The cell to be reused may be tagged
+				% with one of these cons_ids.
 		list(bool)      % A `no' entry means that the corresponding
 				% argument already has the correct value
 				% and does not need to be filled in.
Index: ml_unify_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_unify_gen.m,v
retrieving revision 1.16.2.11
diff -u -r1.16.2.11 ml_unify_gen.m
--- ml_unify_gen.m	2001/03/12 20:24:41	1.16.2.11
+++ ml_unify_gen.m	2001/03/13 09:41:05
@@ -1058,7 +1058,8 @@
 				{ ml_tag_offset_and_argnum(ReuseConsIdTag,
 						ReusePrimTag,
 						_ReuseOffSet, _ReuseArgNum) }
-			), ReuseConsIds, ReusePrimaryTags),
+			), ReuseConsIds, ReusePrimaryTags0),
+		{ list__remove_dups(ReusePrimaryTags0, ReusePrimaryTags) },
 
 		ml_cons_id_to_tag(ConsId, Type, ConsIdTag),
 		ml_field_names_and_types(Type, ConsId, ArgTypes, Fields),

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