Files
mercury/compiler/smm_common.m
Paul Bone d43239d6a7 Move some of the goal path code from compiler/goal_path.m to the mdbcomp
library where it can be used by the deep profiler.

Also move the goal path code from program_representation.m to the new module,
goal_path.m in mdbcomp/

mdbcomp/goal_path.m:
    New module containing goal path code.

mdbcomp/program_representation.m:
    Original location of goal path code.

compiler/goal_path.m:
    Move some of this goal_path code into mdbcomp/goal_path.m

mdbcomp/feedback.automatic_parallelisation.m:
mdbcomp/rtti_access.m:
mdbcomp/slice_and_dice.m:
mdbcomp/trace_counts.m:
browser/debugger_interface.m:
browser/declarative_execution.m:
browser/declarative_tree.m:
compiler/build_mode_constraints.m:
compiler/call_gen.m:
compiler/code_info.m:
compiler/continuation_info.m:
compiler/coverage_profiling.m:
compiler/deep_profiling.m:
compiler/format_call.m:
compiler/goal_path.m:
compiler/goal_util.m:
compiler/hlds_data.m:
compiler/hlds_goal.m:
compiler/hlds_out_goal.m:
compiler/hlds_out_pred.m:
compiler/hlds_pred.m:
compiler/interval.m:
compiler/introduce_parallelism.m:
compiler/layout_out.m:
compiler/llds.m:
compiler/mode_constraint_robdd.m:
compiler/mode_constraints.m:
compiler/mode_ordering.m:
compiler/ordering_mode_constraints.m:
compiler/polymorphism.m:
compiler/post_typecheck.m:
compiler/prog_rep.m:
compiler/prop_mode_constraints.m:
compiler/push_goals_together.m:
compiler/rbmm.condition_renaming.m:
compiler/smm_common.m:
compiler/stack_layout.m:
compiler/stack_opt.m:
compiler/trace_gen.m:
compiler/tupling.m:
compiler/type_constraints.m:
compiler/typecheck.m:
compiler/unify_gen.m:
compiler/unneeded_code.m:
deep_profiler/Mmakefile:
deep_profiler/analysis_utils.m:
deep_profiler/coverage.m:
deep_profiler/create_report.m:
deep_profiler/display_report.m:
deep_profiler/dump.m:
deep_profiler/mdprof_fb.automatic_parallelism.m:
deep_profiler/message.m:
deep_profiler/old_query.m:
deep_profiler/profile.m:
deep_profiler/program_representation_utils.m:
deep_profiler/read_profile.m:
deep_profiler/recursion_patterns.m:
deep_profiler/report.m:
deep_profiler/var_use_analysis.m:
slice/Mmakefile:
slice/mcov.m:
    Conform to the move of the goal path code.
2011-01-13 00:36:56 +00:00

152 lines
5.1 KiB
Mathematica

%-----------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et
%-----------------------------------------------------------------------------%
% Copyright (C) 2005-2008, 2010-2011 The 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 smm_common.m.
% Main author: Quan Phan.
%
% This module contains defines types and procedures that are common to
% various static memory management analyses, e.g. CTGC, RBMM.
%
%-----------------------------------------------------------------------------%
:- module transform_hlds.smm_common.
:- interface.
:- import_module hlds.
:- import_module hlds.hlds_goal.
:- import_module hlds.hlds_pred.
:- import_module hlds.hlds_module.
:- import_module mdbcomp.
:- import_module mdbcomp.goal_path.
:- import_module parse_tree.
:- import_module parse_tree.prog_data.
:- import_module io.
:- import_module list.
:- import_module term.
%-----------------------------------------------------------------------------%
% Succeeds if the selector selects the type node of the input type.
%
:- pred check_type_of_node(module_info::in, mer_type::in, selector::in)
is semidet.
% Succeeds if some (or all) of the procedures in the list are special.
%
:- pred some_are_special_preds(list(pred_proc_id)::in, module_info::in)
is semidet.
%-----------------------------------------------------------------------------%
%
% Definition of a program point.
%
% A program point identifies a place at which a data structure possibly
% becomes garbage.
%
:- type program_point
---> pp(
pp_context :: term.context,
pp_id :: reverse_goal_path
).
% Compute the program point from the given goal_info.
%
:- func program_point_init(hlds_goal_info) = program_point.
% Dump the information contained in a program point.
%
:- pred dump_program_point(program_point::in, io::di, io::uo) is det.
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
:- implementation.
:- import_module check_hlds.
:- import_module check_hlds.type_util.
:- import_module parse_tree.prog_out.
:- import_module bool.
:- import_module map.
%-----------------------------------------------------------------------------%
% Check if the selector is valid w.r.t the type.
%
check_type_of_node(ModuleInfo, StartType, Selector) :-
(
Selector = [Sel | Sels],
(
Sel = termsel(Cons_id, Choice),
select_subtype(ModuleInfo, StartType, Cons_id, Choice, SubType)
;
Sel = typesel(SubType)
),
check_type_of_node(ModuleInfo, SubType, Sels)
;
Selector = []
).
% Select the subtype of a type Type, selecting ConsId's position Position.
% Position counts starting from 1 (instead of 0).
% The predicate aborts if the subtype cannot be determined.
%
:- pred select_subtype(module_info::in, mer_type::in, cons_id::in, int::in,
mer_type::out) is semidet.
select_subtype(ModuleInfo, Type, ConsId, Choice, SubType) :-
get_cons_id_non_existential_arg_types(ModuleInfo, Type, ConsId, ArgTypes),
list.index1(ArgTypes, Choice, SubType).
% Special predicates are either compiler-generated ones, such as
% __Unify__ and others or ones that are not defined in the module.
%
some_are_special_preds(PPIds, ModuleInfo) :-
module_info_get_special_pred_map(ModuleInfo, SpecialPredMap),
map.values(SpecialPredMap, SpecialPredIds),
(
list.filter(
pred(PPId::in) is semidet :- (
PPId = proc(PredId, _),
list.member(PredId, SpecialPredIds)
),
PPIds, SpecialPPIds),
SpecialPPIds = [_ | _]
;
list.filter(proc_not_defined_in_module(ModuleInfo), PPIds,
FilteredPPIds),
FilteredPPIds = [_ | _]
).
:- pred proc_not_defined_in_module(module_info::in, pred_proc_id::in)
is semidet.
proc_not_defined_in_module(ModuleInfo, proc(PredId, _)):-
module_info_pred_info(ModuleInfo, PredId, PredInfo),
pred_info_get_import_status(PredInfo, Status),
status_defined_in_this_module(Status) = no.
% Note: for a meaningful use of this predicate the goal needs to be
% filled with goal id information, i.e. call to fill_goal_id_slots(...).
%
program_point_init(GoalInfo) = ProgPoint :-
Context = goal_info_get_context(GoalInfo),
RevGoalPath = goal_info_get_reverse_goal_path(GoalInfo),
ProgPoint = pp(Context, RevGoalPath).
dump_program_point(pp(Context, RevGoalPath), !IO):-
prog_out.write_context(Context, !IO),
io.write_string("--", !IO),
io.write_string(rev_goal_path_to_string(RevGoalPath), !IO).
%-----------------------------------------------------------------------------%
:- end_module smm_common.
%-----------------------------------------------------------------------------%