[m-rev.] [reuse] diff: increase aliasing precision
Nancy Mazur
Nancy.Mazur at cs.kuleuven.ac.be
Mon Apr 30 21:36:54 AEST 2001
Hi,
===================================================================
Estimated hours taken: 1
Branches: reuse
Increase the aliasing precision by avoiding the alias-analysis for procedures
which would yield bottom by simply looking at the modes and types of the
headvariables. In those cases, the aliasing is simply set to `bottom'.
pa_alias_as.m:
Add a new predicate is_bottom_alias/4 which checks whether it is
safe to simply say that the aliases for a procedure with given
headvars, modes and types are bottom.
pa_run.m:
If we can safely predict that the aliases created by a procedure
will be bottom, don't analyse the full procedure.
Index: pa_alias_as.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/pa_alias_as.m,v
retrieving revision 1.1.2.25
diff -u -r1.1.2.25 pa_alias_as.m
--- pa_alias_as.m 2001/04/25 07:42:20 1.1.2.25
+++ pa_alias_as.m 2001/04/30 11:31:42
@@ -199,6 +199,13 @@
:- pred apply_widening(module_info::in, proc_info::in, alias_as::in,
alias_as::out) is det.
+ % is_bottom_alias(ModuleInfo, HeadVars, Modes, Types) will check
+ % whether the procedure with the given headvariables, modes and
+ % types has a bottom-alias just by looking at the modes and types.
+ % It fails if the alias can not be shown to be bottom in this way.
+:- pred is_bottom_alias(module_info::in, list(prog_var)::in,
+ list(mode)::in, list(type)::in) is semidet.
+
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
:- implementation.
@@ -570,38 +577,41 @@
GoalInfo, UserDefinedAlias)
)
;
- % else --> apply heuristics
- to_trios(Vars, MaybeModes, Types, Trios),
- % remove all unique objects
- remove_all_unique_vars(HLDS, Trios, NonUniqueVars),
- % keep only the output vars
- collect_all_output_vars(HLDS, NonUniqueVars, OutputVars),
(
- OutputVars = []
+ maybe_modes_to_modes(MaybeModes, Modes),
+ is_bottom_alias(HLDS, Vars, Modes, Types)
->
Alias = bottom
- ;
- list__map(
- pred(Trio::in, Type::out) is det:-
- (
- Trio = trio(_, _, Type)
- ),
- OutputVars,
- OutputTypes),
- (
- types_are_primitive(HLDS, OutputTypes)
- ->
- Alias = bottom
- ;
- goal_info_get_context(GoalInfo, Context),
- format_context(Context, ContextStr),
- string__append_list(["pragma_foreign_code:",
- " (",ContextStr, ")"], Msg),
- pa_alias_as__top(Msg, Alias)
- )
+ ;
+ goal_info_get_context(GoalInfo, Context),
+ format_context(Context, ContextStr),
+ string__append_list(["pragma_foreign_code:",
+ " (",ContextStr, ")"], Msg),
+ pa_alias_as__top(Msg, Alias)
)
).
+
+is_bottom_alias(HLDS, Vars, Modes, Types):-
+ % else --> apply heuristics
+ to_trios(Vars, Modes, Types, Trios),
+ % remove all unique objects
+ remove_all_unique_vars(HLDS, Trios, NonUniqueVars),
+ % keep only the output vars
+ collect_all_output_vars(HLDS, NonUniqueVars, OutputVars),
+ (
+ OutputVars = []
+ ;
+ list__map(
+ pred(Trio::in, Type::out) is det:-
+ (
+ Trio = trio(_, _, Type)
+ ),
+ OutputVars,
+ OutputTypes),
+ types_are_primitive(HLDS, OutputTypes)
+ ).
+
:- pred report_pragma_type_error(proc_info::in, hlds_goal_info::in,
aliasing::in) is erroneous.
report_pragma_type_error(ProcInfo, GoalInfo, Aliasing):-
@@ -642,35 +652,37 @@
:- import_module std_util, inst_match.
+:- pred maybe_modes_to_modes(list(maybe(pair(string, mode))), list(mode)).
+:- mode maybe_modes_to_modes(in, out) is semidet.
+
+maybe_modes_to_modes([], []).
+maybe_modes_to_modes([MaybeMode | MaybeRest], [Mode | Rest]):-
+ MaybeMode = yes(_String - Mode),
+ maybe_modes_to_modes(MaybeRest, Rest).
+
:- type trio ---> trio(prog_var, mode, type).
-:- pred to_trios(list(prog_var), list(maybe(pair(string, mode))),
+:- pred to_trios(list(prog_var), list(mode),
list(type), list(trio)).
:- mode to_trios(in, in, in, out) is det.
-to_trios(Vars, MaybeModes, Types, Trios):-
+to_trios(Vars, Modes, Types, Trios):-
(
Vars = [ V1 | VR ]
->
(
- MaybeModes = [ M1 | MR ],
+ Modes = [ Mode | MR ],
Types = [ T1 | TR ]
->
- (
- M1 = yes(_String - Mode)
- ->
- Trio1 = trio(V1, Mode, T1),
- to_trios(VR, MR, TR, TrioR),
- Trios = [ Trio1 | TrioR ]
- ;
- to_trios(VR, MR, TR, Trios)
- )
+ Trio1 = trio(V1, Mode, T1),
+ to_trios(VR, MR, TR, TrioR),
+ Trios = [ Trio1 | TrioR ]
;
require__error("(pa_run) to_trios: lists of different length.")
)
;
(
- MaybeModes = [], Types = []
+ Modes = [], Types = []
->
Trios = []
;
Index: pa_run.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/pa_run.m,v
retrieving revision 1.1.2.23
diff -u -r1.1.2.23 pa_run.m
--- pa_run.m 2001/04/20 15:23:08 1.1.2.23
+++ pa_run.m 2001/04/30 11:31:42
@@ -202,10 +202,28 @@
instmap__init_reachable(InitIM),
instmap__apply_instmap_delta(InitIM, InstMapDelta, InstMap),
- pa_alias_as__init(Alias0),
-
- analyse_goal(ProcInfo, HLDS, Goal,
- FPtable0, FPtable1, Alias0, Alias1),
+ pa_alias_as__init(Alias0)
+
+ },
+
+ (
+ { predict_bottom_aliases(HLDS, ProcInfo) }
+ ->
+ (
+ { Verbose = yes }
+ ->
+ io__write_string("% bottom predicted")
+ ;
+ []
+ ),
+ { Alias1 = Alias0 }, % = bottom
+ { FPtable1 = FPtable0 }
+ ;
+ { analyse_goal(ProcInfo, HLDS, Goal,
+ FPtable0, FPtable1, Alias0, Alias1) }
+ ),
+
+ {
FullSize = pa_alias_as__size(Alias1),
pa_alias_as__project(HeadVars, Alias1, Alias2),
@@ -275,6 +293,15 @@
;
[]
).
+
+:- pred predict_bottom_aliases(module_info::in, proc_info::in) is semidet.
+
+predict_bottom_aliases(ModuleInfo, ProcInfo):-
+ proc_info_headvars(ProcInfo, HeadVars),
+ proc_info_argmodes(ProcInfo, Modes),
+ proc_info_vartypes(ProcInfo, VarTypes),
+ list__map( map__lookup(VarTypes), HeadVars, Types),
+ pa_alias_as__is_bottom_alias(ModuleInfo, HeadVars, Modes, Types).
:- pred dummy_test(pred_proc_id::in) is semidet.
dummy_test(proc(PredId, _)):- pred_id_to_int(PredId, 16).
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list