[m-dev.] for review: added new option `--mark-tailcalls'

Julien Fischer juliensf at students.cs.mu.oz.au
Mon Feb 5 00:55:57 AEDT 2001


I've addressed the issues raised in the review.  The log message and diff
are now as follows:

Julien
---------------------------------------------------------------------------

Estimated hours taken: 1.

Added an option `--optimize-tailcalls' which makes optimization of
tailcalls in the MLDS backend optional.  This is turned off in
optimization levels -1 and 0 and when the Java grade is being used; for
other optimization levels it is on.

compiler/handle_options.m:
compiler/mercury_compile.m:
compiler/options.m:
doc/user_guide.texi:
	Added new option `--optimize-tailcalls'.

Index: compiler/handle_options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/handle_options.m,v
retrieving revision 1.100
diff -u -r1.100 handle_options.m
--- compiler/handle_options.m	2001/01/29 01:54:13	1.100
+++ compiler/handle_options.m	2001/02/04 13:45:09
@@ -297,15 +297,17 @@
 	),
 	% Generating Java implies high-level code, turning off nested functions,
 	% using copy-out for both det and nondet output arguments,
-	% using no tags and no static ground terms.
+	% using no tags, not optimizing tailcalls and no static ground terms.
 	% XXX no static ground terms should be eliminated in a later
 	%     version.
+	% XXX The Java backend should eventually support optimizing tailcalls.
 	( { Target = java } ->
 		globals__io_set_option(highlevel_code, bool(yes)),
 		globals__io_set_option(gcc_nested_functions, bool(no)),
 		globals__io_set_option(nondet_copy_out, bool(yes)),
 		globals__io_set_option(det_copy_out, bool(yes)),
 		globals__io_set_option(num_tag_bits, int(0)),
+		globals__io_set_option(optimize_tailcalls, bool(no)),
 		globals__io_set_option(static_ground_terms, bool(no))
 	;
 		[]
@@ -334,6 +336,9 @@
 
 	% --no-gcc-nested-functions implies --no-gcc-local-labels
 	option_neg_implies(gcc_nested_functions, gcc_local_labels, bool(no)),
+
+	% --no-mlds_optimize implies --no-optimize-tailcalls
+	option_neg_implies(optimize, optimize_tailcalls, bool(no)),
 
 	option_implies(verbose_check_termination, check_termination,bool(yes)),
 	option_implies(check_termination, termination, bool(yes)),
Index: compiler/mercury_compile.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.190
diff -u -r1.190 mercury_compile.m
--- compiler/mercury_compile.m	2001/01/29 01:54:09	1.190
+++ compiler/mercury_compile.m	2001/02/04 13:45:09
@@ -2530,11 +2530,15 @@
 	maybe_report_stats(Stats),
 	mercury_compile__maybe_dump_mlds(MLDS10, "10", "rtti"),
 
-	% XXX this pass should be conditional on a compilation option
-
-	maybe_write_string(Verbose, "% Detecting tail calls...\n"),
-	ml_mark_tailcalls(MLDS10, MLDS20),
-	maybe_write_string(Verbose, "% done.\n"),
+	globals__io_lookup_bool_option(optimize_tailcalls, OptimizeTailCalls),
+	( { OptimizeTailCalls = yes } ->
+		maybe_write_string(Verbose, 
+			"% Detecting tail calls...\n"),
+		ml_mark_tailcalls(MLDS10, MLDS20),
+		maybe_write_string(Verbose, "% done.\n")
+	;
+		{ MLDS10 = MLDS20 }
+	),
 	maybe_report_stats(Stats),
 	mercury_compile__maybe_dump_mlds(MLDS20, "20", "tailcalls"),
 
Index: compiler/options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/options.m,v
retrieving revision 1.307
diff -u -r1.307 options.m
--- compiler/options.m	2001/02/03 23:17:34	1.307
+++ compiler/options.m	2001/02/04 13:45:10
@@ -368,6 +368,8 @@
 		;	simple_neg
 		;	follow_vars
 		;	allow_hijacks
+	%	- MLDS
+		;	optimize_tailcalls
 	%	- LLDS
 		;	common_data
 		;	optimize	% also used for MLDS->MLDS optimizations
@@ -758,7 +760,8 @@
 	simple_neg		-	bool(no),
 	follow_vars		-	bool(no),
 	allow_hijacks		-	bool(yes),
-
+% MLDS
+	optimize_tailcalls	- 	bool(no),
 % LLDS
 	common_data		-	bool(no),
 	optimize		-	bool(no),
@@ -1184,6 +1187,8 @@
 % you can't use both at the same time it doesn't really matter.
 long_option("mlds-optimize",		optimize).
 long_option("mlds-optimise",		optimize).
+long_option("optimize-tailcalls",	optimize_tailcalls).
+long_option("optimise-tailcalls",	optimize_tailcalls).
 
 % LLDS optimizations
 long_option("common-data",		common_data).
@@ -1454,7 +1459,8 @@
 	optimize_delay_slot	-	bool(DelaySlot),
 	follow_vars		-	bool(yes),
 	middle_rec		-	bool(yes),
-	emit_c_loops		-	bool(yes)
+	emit_c_loops		-	bool(yes),
+	optimize_tailcalls	-	bool(yes)
 	% dups?
 ]) :-
 	getopt__lookup_bool_option(OptionTable, have_delay_slot, DelaySlot).
@@ -2530,7 +2536,9 @@
 	io__write_string("\n    MLDS -> MLDS optimizations:\n"),
 	write_tabbed_lines([
 		"--no-mlds-optimize",
-		"\tDisable the MLDS->MLDS optimization passes."
+		"\tDisable the MLDS->MLDS optimization passes.",
+		"--optimize-tailcalls",
+		"\tOptimize tailcalls by turning self-tailcalls into loops."
 	]).
 
 
Index: doc/user_guide.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/user_guide.texi,v
retrieving revision 1.235
diff -u -r1.235 user_guide.texi
--- doc/user_guide.texi	2001/01/30 03:08:46	1.235
+++ doc/user_guide.texi	2001/02/04 13:45:10
@@ -4097,6 +4097,10 @@
 @item --no-mlds-optimize
 Disable the MLDS -> MLDS optimization passes.
 
+ at sp 1
+ at item --optimize-tailcalls
+Optimize tailcalls by turning self-tailcalls into loops.
+
 @end table
 
 @node Medium-level (HLDS -> LLDS) optimization options



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