[m-dev.] for review: make tailcall loops an MLDS transformation

Tyson Dowd trd at cs.mu.OZ.AU
Thu Aug 24 14:27:15 AEST 2000


On 22-Aug-2000, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> On 22-Aug-2000, Tyson Dowd <trd at cs.mu.OZ.AU> wrote:
> > Do the transformation of self-tailcalls into loops as an MLDS->MLDS
> > transformation (instead of during mlds_to_c.m).  Both the IL and C
> > backends for MLDS use this transformation.
> 
> This is a good idea...
> 
> > Also, we transform into label/goto instead of for/continue.  This is
> > because IL doesn't have a for/continue construct.  It may be worth
> > revisiting this decision in future and performing benchmarks.
> 
> I think this one is not such a good idea, since Java, which is definitely
> an important target language, supports for/continue but not label/goto.
> 
> > +++ compiler/mercury_compile.m	2000/08/21 01:50:42
> > @@ -2376,7 +2377,13 @@
> >  	maybe_report_stats(Stats),
> >  	mercury_compile__maybe_dump_mlds(MLDS30, "30", "nested_funcs"),
> >  
> > -	{ MLDS = MLDS30 },
> > +	maybe_write_string(Verbose, "% Optimizing MLDS...\n"),
> > +	ml_optimize__optimize(MLDS30, MLDS40),
> > +	maybe_write_string(Verbose, "% done.\n"),
> > +	maybe_report_stats(Stats),
> > +	mercury_compile__maybe_dump_mlds(MLDS40, "40", "optimize"),
> 
> That pass should be disable-able.
> 
> > +	% The label name we use for the top of the loop introduced by
> > +	% tailcall optimization.
> > +:- func tailcall_loop_label_name = string.
> > +tailcall_loop_label_name = "looptop".
> 
> I suggest s/looptop/loop_top/
> 
> [... to be continued ...]

I'm pretty keen to commit this so if you have any critical comments to
make, please say so ASAP.  

Here's an incremental diff that addresses those comments and Zoltan's
comments.


(PS: interdiff rocks my world)

diff -u compiler/mercury_compile.m compiler/mercury_compile.m
--- compiler/mercury_compile.m
+++ compiler/mercury_compile.m
@@ -2369,17 +2369,22 @@
 	( { NestedFuncs = no } ->
 		maybe_write_string(Verbose,
 			"% Flattening nested functions...\n"),
-		ml_elim_nested(MLDS20, MLDS30)
+		ml_elim_nested(MLDS20, MLDS30),
+		maybe_write_string(Verbose, "% done.\n")
 	;
 		{ MLDS30 = MLDS20 }
 	),
-	maybe_write_string(Verbose, "% done.\n"),
 	maybe_report_stats(Stats),
 	mercury_compile__maybe_dump_mlds(MLDS30, "30", "nested_funcs"),
 
-	maybe_write_string(Verbose, "% Optimizing MLDS...\n"),
-	ml_optimize__optimize(MLDS30, MLDS40),
-	maybe_write_string(Verbose, "% done.\n"),
+	globals__io_lookup_bool_option(optimize, Optimize),
+	( { Optimize = yes } ->
+		maybe_write_string(Verbose, "% Optimizing MLDS...\n"),
+		ml_optimize__optimize(MLDS30, MLDS40),
+		maybe_write_string(Verbose, "% done.\n")
+	;
+		{ MLDS40 = MLDS30 }
+	),
 	maybe_report_stats(Stats),
 	mercury_compile__maybe_dump_mlds(MLDS40, "40", "optimize"),
 
diff -u ml_optimize.m ml_optimize.m
--- ml_optimize.m
+++ ml_optimize.m
@@ -16,9 +16,12 @@
 % loop transformation (in the case of self-tailcalls) and marking
 % tailcalls at the same time.
 %
-% It would probably be a good idea to make this transformation optional.
-% Previously it depended on emit_c_loops, but this is a bit misleading
-% given the documentation of emit_c_loops.
+% Ultimately this module should just consist of a skeleton to traverse
+% the MLDS, and should call various optimization modules along the way.
+%
+% It would probably be a good idea to make each transformation optional.
+% Previously the tailcall transformation depended on emit_c_loops, but
+% this is a bit misleading given the documentation of emit_c_loops.
 
 %-----------------------------------------------------------------------------%
 
@@ -50,7 +53,7 @@
 	% The label name we use for the top of the loop introduced by
 	% tailcall optimization.
 :- func tailcall_loop_label_name = string.
-tailcall_loop_label_name = "looptop".
+tailcall_loop_label_name = "loop_top".
 
 optimize(MLDS0, MLDS) -->
 	globals__io_get_globals(Globals),


-- 
       Tyson Dowd           # 
                            #  Surreal humour isn't everyone's cup of fur.
     trd at cs.mu.oz.au        # 
http://www.cs.mu.oz.au/~trd #
--------------------------------------------------------------------------
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