for review: use available opt files

Simon Taylor stayl at cs.mu.OZ.AU
Thu Jun 25 15:01:45 AEST 1998


Hi,

Zoltan, is this what you wanted?

Simon.


Estimated hours taken: 2.5

Add options --use-opt-files and --use-trans-opt-files, which cause
the compiler to use any `.opt' or `.trans_opt' files which are available
when the dependencies are made, but not make any more `.opt' files.
This is useful for using just the `.opt' files for the library
without building them for the compiler.

compiler/modules.m
	When searching for available `.opt' files, don't look for 
	`.m' files which could be used to build the `.opt' files
	is --use-opt-files or --use-trans-opt-files is set.

compiler/handle_options.m
compiler/options.m
doc/user_guide.texi
	Handle and document the new options.


Index: compiler/handle_options.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/handle_options.m,v
retrieving revision 1.56
diff -u -t -u -r1.56 handle_options.m
--- handle_options.m	1998/06/18 06:06:11	1.56
+++ handle_options.m	1998/06/24 23:28:31
@@ -252,6 +252,13 @@
                 bool(yes)),
         option_implies(transitive_optimization, intermodule_optimization,
                 bool(yes)),
+        option_implies(use_trans_opt_files, use_opt_files, bool(yes)),
+
+        % If we are doing full inter-module or transitive optimization,
+        % we need to build all `.opt' or `.trans_opt' files.
+        option_implies(intermodule_optimization, use_opt_files, bool(no)),
+        option_implies(transitive_optimization, use_trans_opt_files, bool(no)),
+
         option_implies(very_verbose, verbose, bool(yes)),
 
         % --split-c-files implies --procs-per-c-function 1
@@ -390,6 +397,11 @@
         ;
                 []
         ),
+
+        % --use-opt-files implies --no-warn-missing-opt-files since
+        % we are expecting some to be missing.
+        option_implies(use_opt_files, warn_missing_opt_files, bool(no)),
+
         % --optimize-frames requires --optimize-labels and --optimize-jumps
         option_implies(optimize_frames, optimize_labels, bool(yes)),
         option_implies(optimize_frames, optimize_jumps, bool(yes)).
Index: compiler/mercury_compile.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/mercury_compile.m,v
retrieving revision 1.100
diff -u -t -u -r1.100 mercury_compile.m
--- mercury_compile.m	1998/06/18 06:06:37	1.100
+++ mercury_compile.m	1998/06/25 01:17:12
@@ -467,13 +467,14 @@
 
 mercury_compile__maybe_grab_optfiles(Imports0, Verbose, MaybeTransOptDeps, 
                 Imports, Error) -->
-        globals__io_lookup_bool_option(intermodule_optimization, UseOptInt),
+        globals__io_lookup_bool_option(intermodule_optimization, IntermodOpt),
+        globals__io_lookup_bool_option(use_opt_files, UseOptInt),
         globals__io_lookup_bool_option(make_optimization_interface,
                                                 MakeOptInt),
         globals__io_lookup_bool_option(transitive_optimization, TransOpt),
         globals__io_lookup_bool_option(make_transitive_opt_interface,
                 MakeTransOptInt),
-        ( { UseOptInt = yes, MakeOptInt = no } ->
+        ( { (UseOptInt = yes ; IntermodOpt = yes), MakeOptInt = no } ->
                 maybe_write_string(Verbose, "% Reading .opt files...\n"),
                 maybe_flush_output(Verbose),
                 intermod__grab_optfiles(Imports0, Imports1, Error1),
@@ -694,6 +695,7 @@
 mercury_compile__maybe_write_optfile(MakeOptInt, HLDS0, HLDS) -->
         globals__io_lookup_bool_option(intermodule_optimization, Intermod),
         globals__io_lookup_bool_option(intermod_unused_args, IntermodArgs),
+        globals__io_lookup_bool_option(use_opt_files, UseOptFiles),
         globals__io_lookup_bool_option(verbose, Verbose),
         globals__io_lookup_bool_option(statistics, Stats),
         globals__io_lookup_bool_option(termination, Termination),
@@ -735,7 +737,7 @@
                 module_name_to_file_name(ModuleName, ".opt", yes, OptName),
                 update_interface(OptName),
                 touch_interface_datestamp(ModuleName, ".optdate")
-        ; { Intermod = yes } ->
+        ; { Intermod = yes; UseOptFiles = yes } ->
                 intermod__adjust_pred_import_status(HLDS0, HLDS)
         ;
                 { HLDS = HLDS0 }
Index: compiler/modules.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/modules.m,v
retrieving revision 1.77
diff -u -t -u -r1.77 modules.m
--- modules.m	1998/05/30 13:34:02	1.77
+++ modules.m	1998/06/25 01:18:25
@@ -1357,9 +1357,12 @@
                         []
                 ),
 
+                globals__io_lookup_bool_option(use_opt_files, UseOptFiles),
                 globals__io_lookup_bool_option(intermodule_optimization,
                         Intermod),
-                ( { Intermod = yes } ->
+                globals__io_lookup_accumulating_option(intermod_directories,
+                        IntermodDirs),
+                ( { Intermod = yes; UseOptFiles = yes } ->
                         io__write_strings(DepStream, [
                                 "\n\n", 
                                 CFileName, " ",
@@ -1368,6 +1371,7 @@
                                 PicObjFileName, " ",
                                 ObjFileName, " :"
                         ]),
+
                         % The .c file only depends on the .opt files from 
                         % the current directory, so that inter-module
                         % optimization works when the .opt files for the 
@@ -1377,14 +1381,17 @@
                         % is to make sure the module gets type-checked without
                         % having the definitions of abstract types from other
                         % modules.
-                        globals__io_lookup_accumulating_option(
-                                intermod_directories, IntermodDirs),
                         globals__io_lookup_bool_option(transitive_optimization,
                                 TransOpt),
-                        ( { TransOpt = yes } ->
-                                get_both_opt_deps(LongDeps, IntermodDirs, 
+                        globals__io_lookup_bool_option(use_trans_opt_files,
+                                UseTransOpt),
+
+                        ( { TransOpt = yes ; UseTransOpt = yes } ->
+                                { bool__not(UseTransOpt, BuildOptFiles) },
+                                get_both_opt_deps(BuildOptFiles,
+                                        [ModuleName | LongDeps], IntermodDirs,
                                         OptDeps, TransOptDeps),
-                                write_dependencies_list([ModuleName | OptDeps],
+                                write_dependencies_list(OptDeps,
                                         ".opt", DepStream),
                                 io__write_strings(DepStream, [
                                         "\n\n", 
@@ -1396,9 +1403,11 @@
                                 write_dependencies_list(TransOptDeps,
                                         ".trans_opt", DepStream)
                         ;
-                                get_opt_deps(LongDeps, IntermodDirs, ".opt", 
-                                        OptDeps),
-                                write_dependencies_list([ModuleName | OptDeps],
+                                { bool__not(UseOptFiles, BuildOptFiles) },
+                                get_opt_deps(BuildOptFiles,
+                                        [ModuleName | LongDeps],
+                                        IntermodDirs, ".opt", OptDeps),
+                                write_dependencies_list(OptDeps,
                                         ".opt", DepStream)
                         )
                 ;
@@ -1605,60 +1614,100 @@
         % If it exists, add it to both output lists. Otherwise, if a .opt
         % file exists, add it to the OptDeps list, and if a .trans_opt
         % file exists, add it to the TransOptDeps list.
-:- pred get_both_opt_deps(list(module_name)::in, list(string)::in, 
+        % If --use-opt-files is set, don't look for `.m' files, since
+        % we are not building `.opt' files, only using those which
+        % are available.
+:- pred get_both_opt_deps(bool::in, list(module_name)::in, list(string)::in, 
         list(module_name)::out, list(module_name)::out, 
         io__state::di, io__state::uo) is det.
-get_both_opt_deps([], _, [], []) --> [].
-get_both_opt_deps([Dep | Deps], IntermodDirs, OptDeps, TransOptDeps) -->
-        module_name_to_file_name(Dep, ".m", no, DepName), 
-        search_for_file(IntermodDirs, DepName, Result1),
-        get_both_opt_deps(Deps, IntermodDirs, OptDeps0, TransOptDeps0),
-        ( { Result1 = yes } ->
-                { OptDeps = [Dep | OptDeps0] },
-                { TransOptDeps = [Dep | TransOptDeps0] },
-                io__seen
+get_both_opt_deps(_, [], _, [], []) --> [].
+get_both_opt_deps(BuildOptFiles, [Dep | Deps], IntermodDirs,
+                OptDeps, TransOptDeps) -->
+        get_both_opt_deps(BuildOptFiles, Deps, IntermodDirs,
+                OptDeps0, TransOptDeps0),
+        ( { BuildOptFiles = yes } ->
+                module_name_to_file_name(Dep, ".m", no, DepName), 
+                search_for_file(IntermodDirs, DepName, Result1),
+                ( { Result1 = yes } ->
+                        { OptDeps1 = [Dep | OptDeps0] },
+                        { TransOptDeps1 = [Dep | TransOptDeps0] },
+                        io__seen,
+                        { Found = yes }
+                ;
+                        { OptDeps1 = OptDeps0 },
+                        { TransOptDeps1 = TransOptDeps0 },
+                        { Found = no }
+                )
         ;
+                { OptDeps1 = OptDeps0 },
+                { TransOptDeps1 = TransOptDeps0 },
+                { Found = no }
+        ),
+        { is_bool(Found) },
+        ( { Found = no } ->
                 module_name_to_file_name(Dep, ".opt", no, OptName), 
                 search_for_file(IntermodDirs, OptName, Result2),
                 ( { Result2 = yes } ->
-                        { OptDeps = [Dep | OptDeps0] },
+                        { OptDeps = [Dep | OptDeps1] },
                         io__seen
                 ;
-                        { OptDeps = OptDeps0 }
+                        { OptDeps = OptDeps1 }
                 ),
                 module_name_to_file_name(Dep, ".trans_opt", no, TransOptName), 
                 search_for_file(IntermodDirs, TransOptName, Result3),
                 ( { Result3 = yes } ->
-                        { TransOptDeps = [Dep | TransOptDeps0] },
+                        { TransOptDeps = [Dep | TransOptDeps1] },
                         io__seen
                 ;
-                        { TransOptDeps = TransOptDeps0 }
+                        { TransOptDeps = TransOptDeps1 }
                 )
+        ;
+                { TransOptDeps = TransOptDeps1 },
+                { OptDeps = OptDeps1 }
         ).
 
         % For each dependency, search intermod_directories for a .Suffix
         % file or a .m file, filtering out those for which the search fails.
-:- pred get_opt_deps(list(module_name)::in, list(string)::in, string::in,
-        list(module_name)::out, io__state::di, io__state::uo) is det.
-get_opt_deps([], _, _, []) --> [].
-get_opt_deps([Dep | Deps], IntermodDirs, Suffix, OptDeps) -->
-        module_name_to_file_name(Dep, ".m", no, DepName),
-        search_for_file(IntermodDirs, DepName, Result1),
-        get_opt_deps(Deps, IntermodDirs, Suffix, OptDeps0),
-        ( { Result1 = yes } ->
-                { OptDeps = [Dep | OptDeps0] },
-                io__seen
+        % If --use-opt-files is set, only look for `.opt' files,
+        % not `.m' files.
+:- pred get_opt_deps(bool::in, list(module_name)::in, list(string)::in,
+        string::in, list(module_name)::out,
+        io__state::di, io__state::uo) is det.
+get_opt_deps(_, [], _, _, []) --> [].
+get_opt_deps(BuildOptFiles, [Dep | Deps], IntermodDirs, Suffix, OptDeps) -->
+        get_opt_deps(BuildOptFiles, Deps, IntermodDirs, Suffix, OptDeps0),
+        ( { BuildOptFiles = yes } ->
+                module_name_to_file_name(Dep, ".m", no, DepName),
+                search_for_file(IntermodDirs, DepName, Result1),
+                ( { Result1 = yes } ->
+                        { OptDeps1 = [Dep | OptDeps0] },
+                        { Found = yes },
+                        io__seen
+                ;
+                        { Found = no },
+                        { OptDeps1 = OptDeps0 }
+                )
         ;
+                { Found = no },
+                { OptDeps1 = OptDeps0 }
+        ),
+        { is_bool(Found) },
+        ( { Found = no } ->
                 module_name_to_file_name(Dep, Suffix, no, OptName),
                 search_for_file(IntermodDirs, OptName, Result2),
                 ( { Result2 = yes } ->
-                        { OptDeps = [Dep | OptDeps0] },
+                        { OptDeps = [Dep | OptDeps1] },
                         io__seen
                 ;
-                        { OptDeps = OptDeps0 }
+                        { OptDeps = OptDeps1 }
                 )
+        ;
+                { OptDeps = OptDeps1 }
         ).
 
+:- pred is_bool(bool::in) is det.
+is_bool(_).
+
 %-----------------------------------------------------------------------------%
 
 generate_module_dependencies(ModuleName) -->
@@ -1720,8 +1769,8 @@
                 { list__condense(ImplDepsOrdering, TransOptDepsOrdering0) },
                 globals__io_lookup_accumulating_option(intermod_directories, 
                         IntermodDirs),
-                get_opt_deps(TransOptDepsOrdering0, IntermodDirs, ".trans_opt",
-                        TransOptDepsOrdering),
+                get_opt_deps(yes, TransOptDepsOrdering0, IntermodDirs,
+                        ".trans_opt", TransOptDepsOrdering),
 
                 %
                 % compute the indirect dependencies: they are equal to the
Index: compiler/options.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/options.m,v
retrieving revision 1.233
diff -u -t -u -r1.233 options.m
--- options.m	1998/06/22 01:06:28	1.233
+++ options.m	1998/06/24 23:25:49
@@ -198,6 +198,8 @@
                 ;       opt_level
                 ;       opt_space       % default is to optimize time
                 ;       intermodule_optimization
+                ;       use_opt_files
+                ;       use_trans_opt_files
                 ;       transitive_optimization
                 ;       split_c_files
         %       - HLDS
@@ -485,6 +487,8 @@
         opt_level               -       int_special,
         opt_space               -       special,
         intermodule_optimization -      bool(no),
+        use_opt_files           -       bool(no),
+        use_trans_opt_files     -       bool(no),
         transitive_optimization -       bool(no),
         check_termination       -       bool(no),
         verbose_check_termination -     bool(no),
@@ -792,6 +796,8 @@
 long_option("optimise-space",           opt_space).
 long_option("intermodule-optimization", intermodule_optimization).
 long_option("intermodule-optimisation", intermodule_optimization).
+long_option("use-opt-files",            use_opt_files).
+long_option("use-trans-opt-files",      use_trans_opt_files).
 long_option("transitive-intermodule-optimization", 
                                         transitive_optimization).
 long_option("transitive-intermodule-optimisation", 
@@ -1705,6 +1711,14 @@
         io__write_string("\t--transitive-intermodule-optimization\n"),
         io__write_string("\t\tImport the transitive intermodule optimization data.\n"),
         io__write_string("\t\tThis data is imported from `<module>.trans_opt' files.\n"),
+        io__write_string("\t--use-opt-files\n"),
+        io__write_string("\t\tPerform inter-module optimization using any\n"),
+        io__write_string("\t\t`.opt' files which are already built, but do not\n"),
+        io__write_string("\t\tbuild any others.\n"),
+        io__write_string("\t--use-trans-opt-files\n"),
+        io__write_string("\t\tPerform inter-module optimization using any\n"),
+        io__write_string("\t\t`.trans_opt' files which are already built, but do\n"),
+        io__write_string("\t\tnot build any others.\n"),
         io__write_string("\t--split-c-files\n"),
         io__write_string("\t\tGenerate each C function in its own C file,\n"),
         io__write_string("\t\tso that the linker will optimize away unused code.\n"),
Index: doc/user_guide.texi
===================================================================
RCS file: /home/staff/zs/imp/mercury/doc/user_guide.texi,v
retrieving revision 1.126
diff -u -t -u -r1.126 user_guide.texi
--- user_guide.texi	1998/06/04 01:03:12	1.126
+++ user_guide.texi	1998/06/25 04:13:18
@@ -2319,6 +2319,14 @@
 files may depend on other @samp{.trans_opt} files, whereas each
 @samp{.opt} file may only depend on the corresponding @samp{.m} file. 
 
+ at item --use-opt-files
+Perform inter-module optimization using any @samp{.opt} files which are 
+already built, but do not build any others.
+
+ at item --use-transopt-files
+Perform inter-module optimization using any @samp{.trans_opt} files which are 
+already built, but do not build any others.
+
 @sp 1
 @item --split-c-files
 Generate each C function in its own C file,



More information about the developers mailing list