[m-rev.] for review: .opt files for intermodule analysis

Peter Wang novalazy at gmail.com
Fri Feb 15 12:00:48 AEDT 2008


Branches: main

Support `.opt' files with `--intermodule-analysis'.  Unlike with
`--intermodule-optimisation', in this case `.opt' files only contain the
initial information produced by `intermod.m' and not later analyses which
should instead use the analysis framework.  This makes intermodule inlining,
etc. work with `--intermodule-analysis'.  Also, the CTGC analyses will require
the definitions of abstract types from imported modules.

compiler/mercury_compile.m:
	Read and make `.opt' files with `--intermodule-analysis'.

	Don't run exception analysis, etc. when producing `.opt' files for
	`--intermodule-analysis'.

	Eliminate unnecessary clauses from `.opt' files to speed up
	compilation with `--intermodule-analysis', as we do for
	`--intermodule-optimisation'.

compiler/make.dependencies.m:
compiler/make.program_target.m:
	Account for `.opt' files being made with `--intermodule-analysis'
	in `mmc --make'.

	Make `.analysis' files dependent on `.opt' files.

compiler/globals.m:
	Add a predicate to return whether either intermodule optimisation
	system is enabled.

compiler/post_typecheck.m:
	Avoid spurious warning about duplicate mode declarations when using
	`--intermodule-analysis' as they may be read from `.opt' files (same
	as for `--intermodule-optimisation').

compiler/exception_analysis.m:
compiler/structure_sharing.analysis.m:
compiler/tabling_analysis.m:
compiler/trailing_analysis.m:
compiler/unused_args.m:
	Don't write the analysis results into `.opt' files.

compiler/term_constr_main.m:
compiler/termination.m:
	Add todos for when these analyses are updated to support
	`--intermodule-analysis'.

compiler/trans_opt.m:
	Fix a comment.


Index: compiler/exception_analysis.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/exception_analysis.m,v
retrieving revision 1.43
diff -u -r1.43 exception_analysis.m
--- compiler/exception_analysis.m	11 Feb 2008 21:25:52 -0000	1.43
+++ compiler/exception_analysis.m	15 Feb 2008 00:58:36 -0000
@@ -160,13 +160,19 @@
     module_info_dependency_info(!.ModuleInfo, DepInfo),
     hlds_dependency_info_get_dependency_ordering(DepInfo, SCCs),
     list.foldl2(check_scc_for_exceptions, SCCs, !ModuleInfo, !IO),
+    % Only write exception analysis pragmas to `.opt' files for
+    % `--intermodule-optimization', not `--intermodule-analysis'.
     globals.io_lookup_bool_option(make_optimization_interface, MakeOptInt,
         !IO),
+    globals.io_lookup_bool_option(intermodule_analysis, IntermodAnalysis,
+        !IO),
     (
         MakeOptInt = yes,
+        IntermodAnalysis = no
+    ->
         make_optimization_interface(!.ModuleInfo, !IO)
     ;
-        MakeOptInt = no
+        true
     ).
 
 %----------------------------------------------------------------------------%
Index: compiler/globals.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/globals.m,v
retrieving revision 1.87
diff -u -r1.87 globals.m
--- compiler/globals.m	23 Jan 2008 13:12:15 -0000	1.87
+++ compiler/globals.m	15 Feb 2008 00:58:36 -0000
@@ -262,6 +262,8 @@
 
 :- pred io_get_extra_error_info(bool::out, io::di, io::uo) is det.
 
+:- pred io_get_any_intermod(bool::out, io::di, io::uo) is det.
+
     % This is semipure because it is called in a context in which the I/O
     % state is not available.  Note that the corresponding set predicate
     % below does take the I/O state.
@@ -690,6 +692,12 @@
 io_get_extra_error_info(ExtraErrorInfo, !IO) :-
     get_extra_error_info(ExtraErrorInfo, !IO).
 
+io_get_any_intermod(AnyIntermod, !IO) :-
+    io_get_globals(Globals, !IO),
+    lookup_bool_option(Globals, intermodule_optimization, IntermodOpt),
+    lookup_bool_option(Globals, intermodule_analysis, IntermodAnalysis),
+    AnyIntermod = bool.or(IntermodOpt, IntermodAnalysis).
+
 semipure_get_solver_auto_init_supported(AutoInitSupported) :-
     semipure get_solver_auto_init_supported(AutoInitSupported).
 
Index: compiler/make.dependencies.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/make.dependencies.m,v
retrieving revision 1.44
diff -u -r1.44 make.dependencies.m
--- compiler/make.dependencies.m	23 Nov 2007 07:35:10 -0000	1.44
+++ compiler/make.dependencies.m	15 Feb 2008 00:58:36 -0000
@@ -245,10 +245,9 @@
     ]).
 target_dependencies(_, module_target_analysis_registry) =
     combine_deps_list([
-        module_target_source `of` self,
-        module_target_private_interface `of` parents,
-        module_target_long_interface `of` non_intermod_direct_imports,
-        module_target_short_interface `of` non_intermod_indirect_imports
+        module_target_intermodule_interface `of` direct_imports,
+        module_target_intermodule_interface `of` indirect_imports,
+        module_target_intermodule_interface `of` intermod_imports
     ]).
 target_dependencies(_, module_target_foreign_il_asm(_)) =
     combine_deps_list([
@@ -315,11 +314,12 @@
     (find_module_deps(dependency_file)::out(find_module_deps)) is det.
 
 compiled_code_dependencies(Globals) = Deps :-
-    globals.lookup_bool_option(Globals, intermodule_optimization, Intermod),
+    globals.lookup_bool_option(Globals, intermodule_optimization, IntermodOpt),
     globals.lookup_bool_option(Globals, intermodule_analysis,
         IntermodAnalysis),
+    AnyIntermod = bool.or(IntermodOpt, IntermodAnalysis),
     (
-        Intermod = yes,
+        AnyIntermod = yes,
         Deps0 = combine_deps_list([
             module_target_intermodule_interface `of` self,
             module_target_intermodule_interface `of` intermod_imports,
@@ -328,7 +328,7 @@
             base_compiled_code_dependencies
         ])
     ;
-        Intermod = no,
+        AnyIntermod = no,
         Deps0 = base_compiled_code_dependencies
     ),
     (
@@ -598,9 +598,9 @@
     make_info::in, make_info::out, io::di, io::uo) is det.
 
 intermod_imports(ModuleName, Success, Modules, !Info, !IO) :-
-    globals.io_lookup_bool_option(intermodule_optimization, Intermod, !IO),
+    globals.io_get_any_intermod(AnyIntermod, !IO),
     (
-        Intermod = yes,
+        AnyIntermod = yes,
         globals.io_lookup_bool_option(read_opt_files_transitively,
             Transitive, !IO),
         (
@@ -613,7 +613,7 @@
                 Modules, !Info, !IO)
         )
     ;
-        Intermod = no,
+        AnyIntermod = no,
         Success = yes,
         Modules = set.init
     ).
@@ -668,7 +668,7 @@
         MaybeImports = yes(Imports),
         ForeignModules = set.list_to_set(
             get_foreign_imported_modules_lang(Languages,
-            Imports ^ foreign_import_modules)),
+                Imports ^ foreign_import_modules)),
         Success = yes
     ;
         MaybeImports = no,
Index: compiler/make.program_target.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/make.program_target.m,v
retrieving revision 1.80
diff -u -r1.80 make.program_target.m
--- compiler/make.program_target.m	23 Nov 2007 07:35:10 -0000	1.80
+++ compiler/make.program_target.m	15 Feb 2008 00:58:36 -0000
@@ -699,13 +699,13 @@
         module_target_unqualified_short_interface),
     LongInts = make_dependency_list(AllModules,
         module_target_long_interface),
-    globals.io_lookup_bool_option(intermodule_optimization, Intermod, !IO),
+    globals.io_get_any_intermod(AnyIntermod, !IO),
     (
-        Intermod = yes,
+        AnyIntermod = yes,
         OptFiles = make_dependency_list(AllModules,
             module_target_intermodule_interface)
     ;
-        Intermod = no,
+        AnyIntermod = no,
         OptFiles = []
     ),
     globals.io_lookup_bool_option(keep_going, KeepGoing, !IO),
@@ -1018,9 +1018,9 @@
     get_module_dependencies(ModuleName, MaybeImports, !Info, !IO),
     (
         MaybeImports = yes(Imports),
-        globals.io_lookup_bool_option(intermodule_optimization, Intermod, !IO),
+        globals.io_get_any_intermod(AnyIntermod, !IO),
         (
-            Intermod = yes,
+            AnyIntermod = yes,
             % `.int0' files are imported by `.opt' files.
             (
                 Imports ^ children = [_ | _],
@@ -1030,7 +1030,7 @@
                 Exts = ["opt"]
             )
         ;
-            Intermod = no,
+            AnyIntermod = no,
             Exts = []
         ),
 
@@ -1287,16 +1287,15 @@
         ),
 
         GradeIntDir = LibDir/"ints"/GradeDir,
-        globals.io_lookup_bool_option(intermodule_optimization, Intermod, !IO),
+        globals.io_get_any_intermod(AnyIntermod, !IO),
         (
-            Intermod = yes,
+            AnyIntermod = yes,
             install_subdir_file(LinkSucceeded, GradeIntDir, ModuleName, "opt",
                 OptSucceeded, !IO)
         ;
-            Intermod = no,
+            AnyIntermod = no,
             OptSucceeded = yes
         ),
-
         globals.io_lookup_bool_option(intermodule_analysis, IntermodAnalysis,
             !IO),
         (
Index: compiler/mercury_compile.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.460
diff -u -r1.460 mercury_compile.m
--- compiler/mercury_compile.m	29 Jan 2008 03:17:38 -0000	1.460
+++ compiler/mercury_compile.m	15 Feb 2008 00:58:37 -0000
@@ -1941,9 +1941,12 @@
     globals.lookup_bool_option(Globals, transitive_optimization, TransOpt),
     globals.lookup_bool_option(Globals, make_transitive_opt_interface,
         MakeTransOptInt),
+    globals.lookup_bool_option(Globals, intermodule_analysis,
+        IntermodAnalysis),
     (
         ( UseOptInt = yes
         ; IntermodOpt = yes
+        ; IntermodAnalysis = yes
         ),
         MakeOptInt = no
     ->
@@ -2099,12 +2102,15 @@
     globals.io_get_globals(Globals, !IO),
     globals.lookup_bool_option(Globals, verbose, Verbose),
     globals.lookup_bool_option(Globals, statistics, Stats),
-    globals.lookup_bool_option(Globals, intermodule_optimization, Intermod),
+    globals.lookup_bool_option(Globals, intermodule_optimization, IntermodOpt),
+    globals.lookup_bool_option(Globals, intermodule_analysis,
+        IntermodAnalysis),
     globals.lookup_bool_option(Globals, use_opt_files, UseOptFiles),
     globals.lookup_bool_option(Globals, make_optimization_interface,
         MakeOptInt),
     (
-        ( Intermod = yes
+        ( IntermodOpt = yes
+        ; IntermodAnalysis = yes
         ; UseOptFiles = yes
         ),
         MakeOptInt = no
@@ -2231,7 +2237,9 @@
 
 maybe_write_optfile(MakeOptInt, !HLDS, !DumpInfo, !IO) :-
     globals.io_get_globals(Globals, !IO),
-    globals.lookup_bool_option(Globals, intermodule_optimization, Intermod),
+    globals.lookup_bool_option(Globals, intermodule_optimization, IntermodOpt),
+    globals.lookup_bool_option(Globals, intermodule_analysis,
+        IntermodAnalysis),
     globals.lookup_bool_option(Globals, intermod_unused_args, IntermodArgs),
     globals.lookup_accumulating_option(Globals, intermod_directories,
         IntermodDirs),
@@ -2256,11 +2264,15 @@
         MakeOptInt = yes,
         write_opt_file(!HLDS, !IO),
 
+        % The following passes are only run with `--intermodule-optimisation'
+        % to append their results to the `.opt.tmp' file.  For
+        % `--intermodule-analysis', analyses results should be recorded
+        % using the intermodule analysis framework instead.
+        %
         % If intermod_unused_args is being performed, run polymorphism,
-        % mode analysis and determinism analysis, then run unused_args
-        % to append the unused argument information to the `.opt.tmp'
-        % file written above.
+        % mode analysis and determinism analysis before unused_args.
         (
+            IntermodAnalysis = no,
             ( IntermodArgs = yes
             ; Termination = yes
             ; Termination2 = yes
@@ -2350,7 +2362,9 @@
         MakeOptInt = no,
         % If there is a `.opt' file for this module the import
         % status of items in the `.opt' file needs to be updated.
-        ( Intermod = yes ->
+        ( IntermodOpt = yes ->
+            UpdateStatus = yes
+        ; IntermodAnalysis = yes ->
             UpdateStatus = yes
         ; UseOptFiles = yes ->
             module_info_get_name(!.HLDS, ModuleName),
Index: compiler/post_typecheck.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/post_typecheck.m,v
retrieving revision 1.123
diff -u -r1.123 post_typecheck.m
--- compiler/post_typecheck.m	22 Jan 2008 15:06:14 -0000	1.123
+++ compiler/post_typecheck.m	15 Feb 2008 00:58:37 -0000
@@ -881,17 +881,20 @@
         pred_info_get_import_status(!.PredInfo, Status),
         module_info_get_globals(ModuleInfo, Globals),
         globals.lookup_bool_option(Globals, intermodule_optimization,
-            Intermod),
+            IntermodOpt),
+        globals.lookup_bool_option(Globals, intermodule_analysis,
+            IntermodAnalysis),
         globals.lookup_bool_option(Globals, make_optimization_interface,
             MakeOptInt),
         (
-            % With `--intermodule-optimization' we can read the declarations
+            % With intermodule optimization we can read the declarations
             % for a predicate from the `.int' and `.int0' files, so ignore
-            % the error in that case.
+            % the error in those cases.
             (
                 status_defined_in_this_module(Status) = yes
             ;
-                Intermod = no
+                IntermodOpt = no,
+                IntermodAnalysis = no
             ;
                 MakeOptInt = yes
             )
Index: compiler/structure_sharing.analysis.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/structure_sharing.analysis.m,v
retrieving revision 1.27
diff -u -r1.27 structure_sharing.analysis.m
--- compiler/structure_sharing.analysis.m	31 Jan 2008 02:16:00 -0000	1.27
+++ compiler/structure_sharing.analysis.m	15 Feb 2008 00:58:37 -0000
@@ -92,15 +92,20 @@
     %
     sharing_analysis(!ModuleInfo, LoadedSharingTable, !IO),
     %
-    % Maybe write structure sharing pragmas to .opt files.
+    % Only write structure sharing pragmas to `.opt' files for
+    % `--intermodule-optimization' not `--intermodule-analysis'.
     %
     globals.io_lookup_bool_option(make_optimization_interface,
         MakeOptInt, !IO),
+    globals.io_lookup_bool_option(intermodule_analysis,
+        IntermodAnalysis, !IO),
     (
         MakeOptInt = yes,
+        IntermodAnalysis = no
+    ->
         make_opt_int(!.ModuleInfo, !IO)
     ;
-        MakeOptInt = no
+        true
     ).
 
 %-----------------------------------------------------------------------------%
Index: compiler/tabling_analysis.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/tabling_analysis.m,v
retrieving revision 1.12
diff -u -r1.12 tabling_analysis.m
--- compiler/tabling_analysis.m	21 Jan 2008 00:32:54 -0000	1.12
+++ compiler/tabling_analysis.m	15 Feb 2008 00:58:37 -0000
@@ -125,6 +125,8 @@
             MakeOptInt, !IO),
         globals.io_lookup_bool_option(make_transitive_opt_interface,
             MakeTransOptInt, !IO),
+        globals.io_lookup_bool_option(intermodule_analysis,
+            IntermodAnalysis, !IO),
         globals.io_lookup_bool_option(make_analysis_registry,
             MakeAnalysisReg, !IO),
         Pass1Only = MakeOptInt `bool.or` MakeTransOptInt
@@ -135,11 +137,15 @@
         globals.io_lookup_bool_option(debug_mm_tabling_analysis, Debug, !IO),
         list.foldl2(analyse_mm_tabling_in_scc(Debug, Pass1Only), SCCs,
             !ModuleInfo, !IO),
+        % Only write tabling pragmas to `.opt' files for
+        % `--intermodule-optimisation' not `--intermodule-analysis'.
         (
             MakeOptInt = yes,
+            IntermodAnalysis = no
+        ->
             make_opt_int(!.ModuleInfo, !IO)
         ;
-            MakeOptInt = no
+            true
         )
     ;
         UseMinimalModel = no
Index: compiler/term_constr_main.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/term_constr_main.m,v
retrieving revision 1.16
diff -u -r1.16 term_constr_main.m
--- compiler/term_constr_main.m	21 Jan 2008 00:32:54 -0000	1.16
+++ compiler/term_constr_main.m	15 Feb 2008 00:58:38 -0000
@@ -462,6 +462,7 @@
     is det.
 
 maybe_make_optimization_interface(ModuleInfo, !IO) :-
+    % XXX update this once this analysis supports `--intermodule-analysis'
     globals.io_lookup_bool_option(make_optimization_interface, MakeOptInt,
         !IO),
     (
Index: compiler/termination.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/termination.m,v
retrieving revision 1.79
diff -u -r1.79 termination.m
--- compiler/termination.m	29 Jan 2008 04:59:44 -0000	1.79
+++ compiler/termination.m	15 Feb 2008 00:58:38 -0000
@@ -116,6 +116,7 @@
 
     list.foldl2(analyse_termination_in_scc(PassInfo), SCCs, !ModuleInfo, !IO),
 
+    % XXX update this once this analysis supports `--intermodule-analysis'
     globals.io_lookup_bool_option(make_optimization_interface, MakeOptInt,
         !IO),
     (
Index: compiler/trailing_analysis.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/trailing_analysis.m,v
retrieving revision 1.31
diff -u -r1.31 trailing_analysis.m
--- compiler/trailing_analysis.m	11 Feb 2008 21:26:10 -0000	1.31
+++ compiler/trailing_analysis.m	15 Feb 2008 00:58:38 -0000
@@ -135,6 +135,8 @@
             MakeOptInt, !IO),
         globals.io_lookup_bool_option(make_transitive_opt_interface,
             MakeTransOptInt, !IO),
+        globals.io_lookup_bool_option(intermodule_analysis,
+            IntermodAnalysis, !IO),
         globals.io_lookup_bool_option(make_analysis_registry,
             MakeAnalysisReg, !IO),
         Pass1Only = MakeOptInt `bool.or` MakeTransOptInt
@@ -144,11 +146,15 @@
         hlds_dependency_info_get_dependency_ordering(DepInfo, SCCs),
         globals.io_lookup_bool_option(debug_trail_usage, Debug, !IO),
         list.foldl2(process_scc(Debug, Pass1Only), SCCs, !ModuleInfo, !IO),
+        % Only write trailing analysis pragmas to `.opt' files for
+        % `--intermodule-optimization', not `--intermodule-analysis'.
         (
             MakeOptInt = yes,
+            IntermodAnalysis = no
+        ->
             make_opt_int(!.ModuleInfo, !IO)
         ;
-            MakeOptInt = no
+            true
         )
     ;
         UseTrail = no
Index: compiler/trans_opt.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/trans_opt.m,v
retrieving revision 1.46
diff -u -r1.46 trans_opt.m
--- compiler/trans_opt.m	10 Jan 2008 04:29:54 -0000	1.46
+++ compiler/trans_opt.m	15 Feb 2008 00:58:38 -0000
@@ -69,7 +69,7 @@
     %
 :- pred write_trans_opt_file(module_info::in, io::di, io::uo) is det.
 
-    % grab_optfiles(ModuleList, !ModuleImports, Error, !IO):
+    % grab_trans_optfiles(ModuleList, !ModuleImports, Error, !IO):
     %
     % Add the items from each of the modules in ModuleList.trans_opt to
     % the items in ModuleImports.
Index: compiler/unused_args.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/unused_args.m,v
retrieving revision 1.149
diff -u -r1.149 unused_args.m
--- compiler/unused_args.m	29 Jan 2008 04:59:45 -0000	1.149
+++ compiler/unused_args.m	15 Feb 2008 00:58:38 -0000
@@ -233,8 +233,14 @@
 
     map.keys(UnusedArgInfo, PredProcsToFix),
     globals.lookup_bool_option(Globals, make_optimization_interface, MakeOpt),
+    globals.lookup_bool_option(Globals, intermodule_analysis,
+        IntermodAnalysis),
+    % Only write unused argument analysis pragmas to `.opt' files for
+    % `--intermodule-optimization', not `--intermodule-analysis'.
     (
         MakeOpt = yes,
+        IntermodAnalysis = no
+    ->
         module_info_get_name(!.ModuleInfo, ModuleName),
         module_name_to_file_name(ModuleName, ".opt.tmp", no, OptFileName, !IO),
         io.open_append(OptFileName, OptFileRes, !IO),
@@ -250,7 +256,6 @@
             MaybeOptFile = no
         )
     ;
-        MakeOpt = no,
         MaybeOptFile = no
     ),
     globals.lookup_bool_option(Globals, warn_unused_args, DoWarn),

--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list