[m-rev.] diff/for review: make closure analysis work with intermodule optimization

Julien Fischer juliensf at cs.mu.OZ.AU
Wed Aug 3 18:37:27 AEST 2005


Estimated hours taken: 1
Branches: main

Transform lambda expressions into separate predicates when
building the (transitive-)intermodule interfaces.  Closure
analysis will not work unless this has been done.

Add a test case for the termination analysis of generic calls.

compiler/mercury_compile.m:
	When building the (transitive-)intermodule optimization
	interface for a module, make sure that we transform
	lambda expressions if we are also going to run
	closure analysis.

tests/term/Mercury.options:
tests/term/Mmakefile:
tests/term/generic_call.m:
tests/term/generic_call.trans_opt_exp:
	A test case for the termination analysis of generic calls.

Julien.

Workspace:/home/earth/juliensf/ws-closure-analysis2
Index: compiler/mercury_compile.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.337
diff -u -r1.337 mercury_compile.m
--- compiler/mercury_compile.m	26 Jul 2005 01:56:24 -0000	1.337
+++ compiler/mercury_compile.m	3 Aug 2005 08:23:04 -0000
@@ -2070,6 +2070,8 @@
     globals__lookup_bool_option(Globals, termination2, Termination2),
     globals__lookup_bool_option(Globals, analyse_exceptions,
         ExceptionAnalysis),
+    globals__lookup_bool_option(Globals, analyse_closures,
+        ClosureAnalysis),
     (
         MakeOptInt = yes,
         intermod__write_optfile(!HLDS, !IO),
@@ -2088,8 +2090,17 @@
             mercury_compile__frontend_pass_by_phases(!HLDS, FoundModeError,
                 !IO),
             ( FoundModeError = no ->
-                mercury_compile.maybe_closure_analysis(Verbose, Stats,
-                    !HLDS, !IO),
+                (
+                    % Closure analysis assumes that lambda expressions have
+                    % been converted into separate predicates.
+                    ClosureAnalysis = yes,
+                    mercury_compile.process_lambdas(Verbose, Stats,
+                        !HLDS, !IO),
+                    mercury_compile.maybe_closure_analysis(Verbose, Stats,
+                        !HLDS, !IO)
+                ;
+                    ClosureAnalysis = no
+                ),
                 (
                     ExceptionAnalysis = yes,
                     mercury_compile__maybe_exception_analysis(Verbose, Stats,
@@ -2161,6 +2172,18 @@
 mercury_compile__output_trans_opt_file(!.HLDS, !IO) :-
     globals__io_lookup_bool_option(verbose, Verbose, !IO),
     globals__io_lookup_bool_option(statistics, Stats, !IO),
+    globals__io_lookup_bool_option(analyse_closures, ClosureAnalysis, !IO),
+    %
+    % Closure analysis assumes that lambda expressions have
+    % been converted into separate predicates.
+    %
+    (
+        ClosureAnalysis = yes,
+        mercury_compile__process_lambdas(Verbose, Stats, !HLDS, !IO)
+    ;
+        ClosureAnalysis = no
+    ),
+    mercury_compile__maybe_dump_hlds(!.HLDS, 110, "lambda", !IO),
     mercury_compile__maybe_closure_analysis(Verbose, Stats, !HLDS, !IO),
     mercury_compile__maybe_dump_hlds(!.HLDS, 117, "closure_analysis", !IO),
     mercury_compile__maybe_exception_analysis(Verbose, Stats, !HLDS, !IO),
Index: tests/term/Mercury.options
===================================================================
RCS file: /home/mercury1/repository/tests/term/Mercury.options,v
retrieving revision 1.6
diff -u -r1.6 Mercury.options
--- tests/term/Mercury.options	10 Dec 2004 07:03:44 -0000	1.6
+++ tests/term/Mercury.options	29 Jun 2005 04:34:03 -0000
@@ -13,6 +13,7 @@
 MCFLAGS-existential_error2=--term-norm=num-data-elems
 MCFLAGS-existential_error3=--term-norm=num-data-elems
 MCFLAGS-fold=--term-norm=simple
+MCFLAGS-generic_call=--analyse-closures
 MCFLAGS-inf_const_bug=--term-norm=total
 MCFLAGS-my_list=--term-norm=simple
 MCFLAGS-lte=--term-norm=simple
Index: tests/term/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/term/Mmakefile,v
retrieving revision 1.28
diff -u -r1.28 Mmakefile
--- tests/term/Mmakefile	3 Aug 2005 02:30:39 -0000	1.28
+++ tests/term/Mmakefile	3 Aug 2005 03:00:47 -0000
@@ -25,6 +25,7 @@
 	existential_error3 \
 	fold \
 	foreign_valid \
+	generic_call \
 	inf_const_bug \
 	my_list \
 	lte \
Index: tests/term/generic_call.m
===================================================================
RCS file: tests/term/generic_call.m
diff -N tests/term/generic_call.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/term/generic_call.m	3 Aug 2005 08:30:16 -0000
@@ -0,0 +1,34 @@
+:- module generic_call.
+
+:- interface.
+
+:- type what ---> double ; triple.
+
+:- pred alpha(what::in, int::in, int::out) is det.
+
+:- implementation.
+
+:- import_module int.
+
+alpha(What, In0, Out) :-
+	force_deps(In0, In),
+	(
+		What = double,
+		Op   = double_int
+	;
+		What = triple,
+		Op   = triple_int
+	),
+	Op(In, Out).
+
+:- pred double_int(int::in, int::out) is det.
+
+double_int(X, X + X).
+
+:- pred triple_int(int::in, int::out) is det.
+
+triple_int(X, X + X + X).
+
+:- pred force_deps(int::in, int::out) is det.
+
+force_deps(!N) :- double_int(!N), triple_int(!N).
Index: tests/term/generic_call.trans_opt_exp
===================================================================
RCS file: tests/term/generic_call.trans_opt_exp
diff -N tests/term/generic_call.trans_opt_exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/term/generic_call.trans_opt_exp	3 Aug 2005 08:32:07 -0000
@@ -0,0 +1,9 @@
+:- module generic_call.
+:- pragma termination_info(generic_call.alpha((builtin.in), (builtin.in), (builtin.out)), infinite, cannot_loop).
+:- pragma termination_info(generic_call.double_int((builtin.in), (builtin.out)), finite(0, [no, no]), cannot_loop).
+:- pragma termination_info(generic_call.triple_int((builtin.in), (builtin.out)), finite(0, [no, no]), cannot_loop).
+:- pragma termination_info(generic_call.force_deps((builtin.in), (builtin.out)), finite(0, [no, no]), cannot_loop).
+:- pragma termination2_info(generic_call.alpha((builtin.in), (builtin.in), (builtin.out)), constraints([]), not_set, can_loop).
+:- pragma termination2_info(generic_call.double_int((builtin.in), (builtin.out)), constraints([]), not_set, cannot_loop).
+:- pragma termination2_info(generic_call.triple_int((builtin.in), (builtin.out)), constraints([]), not_set, cannot_loop).
+:- pragma termination2_info(generic_call.force_deps((builtin.in), (builtin.out)), constraints([]), not_set, cannot_loop).

--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list