[m-dev.] for review: MLDS->C back-end: efficiency improvements

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Jan 18 00:34:54 AEDT 2001


On 17-Jan-2001, Peter Ross <peter.ross at miscrit.be> wrote:
> On Wed, Jan 17, 2001 at 11:35:22PM +1100, Fergus Henderson wrote:
> > compiler/mlds_to_c.m:
...
> > 	Put the default case first, so that if it is empty (as it will
> > 	be if the default is unreachable and MR_assert() is not enabled),
> > 	it gets merged with.
> > 
> 
> with what?

Sorry.  "... merged with the first (non-default) case."

> > 	Replace an obsolete comment about a problem with setjmp() and
> > 	volatile with a comment explaining how that problem was fixed.
> > 
> > 	Generate calls to MR_builtin_setjmp() and MR_builtin_longjmp()
> > 	rather than to setjmp() and longjmp().
> > 
> I would prefer MR_setjmp() and MR_longjmp() because that is the more
> general case.

Nice idea, but unfortunately those names are already taken!
See MR_setjmp() and MR_longjmp() in runtime/mercury_engine.h.

> > +%
> > +% Note that if we're using GCC's __builtin_longjmp(),
> > +% then it is important that the call to __builtin_longjmp() be
> > +% put in its own function, to ensure that it is not in the same
> > +% function as the __builtin_setjmp().
> > +% The code generation schema below does that automatically.
> > +% We will need to be careful with MLDS optimizations to
> > +% ensure that we preserve that invariant, though.
> > +% (Alternatively, we could just call a function that
> > +% calls __builtin_longjmp() rather than calling it directly.
> > +% But that would be a little less efficient.)
> >  %
> 
> I can see this being a gotcha that is going to get us at some stage.  I
> would prefer to see some sort of check added to avoid this problem.
> Maybe we should add a pass which traverses the MLDS just before output
> and checks for any problems.

Perhaps.  But that would slow down the compiler if enabled by
default, and would not be much use if it was not enabled by default.

I'll document this clearly in mlds.m.  See below.

> s/as taking as/as taking for/
> 
> reads slightly better to me.

Done.

----------

compiler/mlds.m:
	Add some comments about __builtin_setjmp() and __builtin_longjmp().

Index: mlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds.m,v
retrieving revision 1.44
diff -u -d -u -r1.44 mlds.m
--- mlds.m	2000/12/11 04:52:45	1.44
+++ mlds.m	2001/01/17 13:15:47
@@ -779,6 +779,16 @@
 		% do_commit(Ref) instructions should only be used
 		% in goals called from the GoalToTry goal in the
 		% try_commit instruction with the same Ref.
+		%
+		% The C and GCC back-ends require each try_commit
+		% to be put in its own nested function, to avoid
+		% problems with setjmp() and local vars not declared
+		% volatile.  They also require each do_commit
+		% to be put in its own function -- this is needed when
+		% using __builtin_setjmp()/__builtin_longjmp() to
+		% ensure that the call to __builtin_longjmp() is
+		% not in the same function as the call to
+		% __builtin_setjmp().
 		%	
 	;	try_commit(mlds__lval, mlds__statement, mlds__statement)
 	;	do_commit(mlds__rval)
-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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