Files
mercury/compiler/mmc_analysis.m
Simon Taylor 69be9ed096 A first implementation of the inter-module analysis framwork.
Estimated hours taken: 80
Branches: main

A first implementation of the inter-module analysis framwork.
Currently only unused argument analysis is supported.

The current inter-module analysis scheme using `.trans_opt' files
has some major limitations. The compilation dependencies introduced
by `.trans_opt' files are too complicated for Mmake without major
limitations on which modules can use the contents of which `.trans_opt'
files. Also, the `.trans_opt' file system only computes greatest fixpoints,
which is often too weak to find opportunities for optimization.
A better solution is to provide a library which manually handles
the dependencies introduced by inter-module analysis, and can deal with
the complications introduced by cyclic module dependencies.

TODO:
- support other analyses, e.g. termination, type specialization
- dependency tracking and invalidation after source modifications
- garbage collection of unused versions
- least fixpoint analyses

analysis/Mmakefile:
analysis/mer_analysis.m:
analysis/analysis.m:
analysis/analysis.file.m:
	The analysis library.

analysis/README:
	Description and design documentation.

Mmake.workspace:
Mmakefile:
compiler/Mmakefile:
tools/bootcheck:
	Link the analysis library into mercury_compile.

compiler/hlds_module.m:
	Store analysis information in the module_info.

compiler/options.m:
doc/user_guide.texi:
	Add an option `--intermodule-analysis'.

compiler/mercury_compile.m:
	Call the analysis library to write the gathered
	information at the end of a compilation.

compiler/unused_args.m:
	Call the analysis library to retrieve information
	about imported procedures. This replaces code which
	used the `.opt' files.

	Change the names created for unused arguments procedures
	to include the arguments removed, rather than a sequence
	number. I think Zoltan is working on a change to name
	mangling, so I haven't updated the demangler.

compiler/prog_util.m:
	Generate the new predicate names for unused_args.m.

library/std_util.m:
	Add a polymorphic version of unit, which is useful
	for binding type variables.

compiler/modules.m:
scripts/Mmake.vars.in:
	Clean up files created by the analysis framework
	in `mmake realclean'.

util/mdemangle.c:
profiler/demangle.m:
	Document the change in the name mangling of procedures with
	unused arguments.

configure.in:
	Check for state variables and fixes for some typeclass bugs.

tests/warnings/Mmakefile:
tests/warnings/unused_args_analysis.{m,exp}:
	Test case.
2003-01-02 07:35:00 +00:00

65 lines
2.0 KiB
Mathematica

%-----------------------------------------------------------------------------%
% Copyright (C) 2003 University of Melbourne.
% This file may only be copied under the terms of the GNU General
% Public License - see the file COPYING in the Mercury distribution.
%-----------------------------------------------------------------------------%
% File: mmc_analysis.m
% Main author: stayl
%
% Specify Mercury compiler analyses to be used with the
% inter-module analysis framework.
%-----------------------------------------------------------------------------%
:- module transform_hlds__mmc_analysis.
:- interface.
:- import_module parse_tree__prog_data.
:- import_module hlds__hlds_pred.
:- import_module analysis.
:- type mmc ---> mmc.
:- instance compiler(mmc).
:- func module_name_to_module_id(module_name) = module_id.
:- func module_id_to_module_name(module_id) = module_name.
:- func pred_or_func_name_arity_to_func_id(pred_or_func,
string, arity, proc_id) = func_id.
:- implementation.
:- import_module parse_tree__prog_out, parse_tree__prog_util.
:- import_module parse_tree__modules.
:- import_module hlds__hlds_out.
:- import_module transform_hlds__unused_args.
:- import_module bool, std_util, string.
:- instance compiler(mmc) where [
compiler_name(mmc) = "mmc",
analyses(mmc, "unused_args") =
'new analysis_type'(
unit1 `with_type` unit(unused_args_func_info),
unit1 `with_type` unit(any_call),
unit1 `with_type` unit(unused_args_answer)),
module_id_to_file_name(mmc, ModuleId, Ext, FileName) -->
module_name_to_file_name(module_id_to_module_name(ModuleId),
Ext, yes, FileName)
].
module_name_to_module_id(ModuleName) = ModuleId :-
sym_name_to_string(ModuleName, ModuleId).
module_id_to_module_name(ModuleId) = ModuleName :-
string_to_sym_name(ModuleId, ".", ModuleName).
pred_or_func_name_arity_to_func_id(PredOrFunc, Name, Arity, ProcId) = FuncId :-
hlds_out__simple_call_id_to_string(
PredOrFunc - unqualified(Name)/Arity, FuncId0),
proc_id_to_int(ProcId, ProcInt),
FuncId = FuncId0 ++ "-" ++ int_to_string(ProcInt).