[m-rev.] for review: structure sharing analysis using analysis framework

Julien Fischer juliensf at csse.unimelb.edu.au
Thu Mar 27 12:39:05 AEDT 2008


On Tue, 25 Mar 2008, Peter Wang wrote:

> Branches: main
>
> Make the structure sharing analysis capable of using the intermodule analysis
> framework.
>
> This requires changes to the analysis framework.  Structure sharing answer
> patterns need information from the module_info and proc_info in order to be
> compared.  In Simon Taylor's original analysis framework implementation, this
> would have been provided for by a `FuncInfo' parameter in the `partial_order'
> typeclass.  I removed it two years ago as it was causing difficulties which
> couldn't be solved cleanly while the analysis framework was not specific to
> the Mercury compiler.  Also, there were no analyses at the time which needed
> FuncInfos.  Now that we do require it, and the analysis framework has been
> made Mercury specific, we can restore the `FuncInfo' parameter.
>
> Also make some more simplifications to the analysis framework.
>
> compiler/analysis.m:
> compiler/analysis.file.m:
> 	Remove the `module_id' type and replace occurrences by `module_name'.
>
> 	Remove "extra info" facilities. They were intended for storing
> 	information needed by intermodule inlining and higher order
> 	specialisation but now that information is in `.opt' files, even
> 	when using `--intermodule-analysis'.
>
> 	Change `func_id' from a string to a structured type so we can extract
> 	its components easily.
>
> 	Add a message argument to the `invalid_analysis_file' functor so when
> 	we throw an exception due to being unable to parse a `.analysis'
> 	we get a meaningful message.
>
> 	Change the `.analysis' file format to account for the changes to
> 	`module_id' and `func_id'.  Bump the file version number.
>
> 	Add a `FuncInfo' parameter to the `partial_order' typeclass, as
> 	explained above.
>
> 	Add a `no_func_info' dummy type.
>
> 	Add a `get_func_info' method to the `analysis' framework.  When
> 	updating the analysis files after analysing a module, we need to be
> 	able to materialise FuncInfos for each procedure in order to compare
> 	its call or answer patterns.  This is what couldn't be added cleanly
> 	while the analysis framework was not specific to the Mercury compiler.
>
> compiler/structure_sharing.analysis.m:
> 	Make the structure sharing analysis capable of using the analysis
> 	framework, i.e. use imported answers from the analysis registry,
> 	record new answers, dependencies and requests, and keeping track of
> 	the optimality of results during analysis.
>
> compiler/structure_sharing.domain.m:
> 	Add `sharing_as_and_status' to pair `sharing_as' with an
> 	`analysis_status'.
>
> 	Make `sharing_as_table' record the `analysis_status' alongside a
> 	sharing domain.  Update access predicates.
>
> 	Move `sharing_as' into the interface section as it is needed by
> 	structure_sharing.m to convert between `sharing_as' and
> 	`structure_sharing_answer' values for the analysis framework.
>
> 	When we can't look up the sharing result for an `:- external'
> 	predicate, that should not be a sign that the analysis is non-optimal
> 	since we can't get a better result by reanalysis.
>
> 	Make special predicates be approximated by `bottom' sharing as we know
> 	they don't introduce sharing.
>
> 	Avoid an assertion failure in removing subsumed sharing pairs from a
> 	sharing set.
>
> compiler/ctgc.util.m:
> 	Make `pred_requires_no_analysis' not succeed on special predicates
> 	(unify, compare, index, init) which causes the analysis to assume all
> 	possible sharing between its arguments, whereas we know that those
> 	predicates don't introduce any sharing.
>
> 	Also make `pred_requires_no_analysis' not succeed on `:- external'
> 	predicates.
>
> compiler/ctgc.selector.m:
> 	Make type_on_path_2 fail instead of aborting if asked to select a
> 	subtype which turns out to be existentially typed.
>
> compiler/structure_reuse.direct.m:
> 	Don't run direct structure reuse on compiler generated special
> 	predicates.  We need to handle them specifically now due to the change
> 	to `pred_requires_no_analysis'.
>
> compiler/structure_reuse.indirect.m:
> 	Don't run indirect structure reuse on compiler generated special
> 	predicates, as for the direct reuse pass.
>
> 	Conform to change to `top_feedback'.
>
> 	Change a semidet function to a predicate.
>
> compiler/hlds_pred.m:
> compiler/hlds_out.m:
> 	Change `structure_sharing_info' to associate an analysis status with
> 	the structure sharing domain of a procedure (if any).  Add a type
> 	`structure_sharing_domain_and_status' for this.
>
> compiler/prog_data.m:
> 	Make `top_feedback' a structured type instead of a string.  Divide the
> 	reasons that we might approximate structure sharing by `top' into
> 	different classes.
>
> compiler/exception_analysis.m:
> compiler/tabling_analysis.m:
> compiler/trailing_analysis.m:
> 	Conform to analysis framework changes.
>
> compiler/unused_args.m:
> 	Conform to analysis framework changes.
>
> 	Move the predicate arity from the call pattern into a FuncInfo,
> 	where it belongs.
>
> 	Bump the analysis version number.
>
> compiler/prog_ctgc.m:
> compiler/structure_reuse.direct.detect_garbage.m:
> 	Conform to change to `top_feedback'.
>
> compiler/make.dependencies.m:
> compiler/make.module_target.m:
> compiler/make.program_target.m:
> compiler/make.util.m:
> 	Conform to removal of `module_id' type.
>
> compiler/mercury_compile.m:
> 	Call mm_tabling_analysis, structure sharing and structure reuse passes
> 	when making `.analysis' files.

Not calling the tabling analysis was deliberate; I never tested it with
--intermodule-analysis.

> 	Conform to removal of `module_id' type.
>
> compiler/mmc_analysis.m:
> 	Add structure sharing to the list of analyses.
>
> 	Add `func_id_to_ppid'.
>
> 	Conform to analysis framework changes.
>
> compiler/ctgc.fixpoint_table.m:
> 	Replace a semidet function by a predicate.
>

...

> +%-----------------------------------------------------------------------------%
> +
> +:- pred should_write_sharing_info(module_info::in, pred_id::in, pred_info::in,
> +    bool::out) is det.
> +
> +should_write_sharing_info(ModuleInfo, PredId, PredInfo, ShouldWrite) :-
> +    pred_info_get_import_status(PredInfo, ImportStatus),
> +    module_info_get_type_spec_info(ModuleInfo, TypeSpecInfo),
> +    TypeSpecInfo = type_spec_info(_, TypeSpecForcePreds, _, _),
> +    (
> +        (
> +            ImportStatus = status_exported
> +        ;
> +            ImportStatus = status_opt_exported
> +            % XXX status_exported_to_submodules?

I think yes there as not all impl. preds may be marked as opt_exported.

> +        ),
> +        \+ is_unify_or_compare_pred(PredInfo),
> +
> +        % XXX These should be allowed, but the predicate declaration for the
> +        % specialized predicate is not produced before the structure_sharing
> +        % pragmas are read in, resulting in an undefined predicate error.
> +        \+ set.member(PredId, TypeSpecForcePreds)
> +    ->
> +        ShouldWrite = yes
> +    ;
> +        ShouldWrite = no
> +    ).
> +
> +%-----------------------------------------------------------------------------%

That looks fine otherwise.

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