[m-rev.] for review: run dependent parallel conjunction as necessary
Peter Wang
wangp at students.cs.mu.oz.au
Fri Aug 11 12:29:52 AEST 2006
Estimated hours taken: 3
Branches: main
This patch reduces the amount of time spent running the dependent parallel
conjunction transformation by only running it on predicates which contain
(or could contain) parallel conjunctions.
compiler/hlds_out.m:
compiler/hlds_pred.m:
compiler/intermod.m:
compiler/size_prof.m:
compiler/table_gen.m:
Add the marker `may_have_parallel_conj'.
compiler/simplify.m:
When we come across a parallel conjunction during the simplification
of a procedure, add the marker `may_have_parallel_conj' for the
pred_info of that procedure.
compiler/dep_par_conj.m:
Check that a predicate has the `may_have_parallel_conj' marker before
running the dependent parallel conjunction transformation on the
procedures of that predicate.
compiler/deforest.m:
compiler/inlining.m:
compiler/lambda.m:
Preserve the `may_have_parallel_conj' marker in derived procedures.
Index: compiler/deforest.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/deforest.m,v
retrieving revision 1.68
diff -u -r1.68 deforest.m
--- compiler/deforest.m 31 Jul 2006 08:31:34 -0000 1.68
+++ compiler/deforest.m 9 Aug 2006 05:09:08 -0000
@@ -1819,8 +1819,18 @@
proc_info_get_rtti_varmaps(ProcInfo0, RttiVarMaps0),
inlining.do_inline_call(UnivQVars, Args, CalledPredInfo,
CalledProcInfo, VarSet0, VarSet, VarTypes0, VarTypes,
- TypeVarSet0, TypeVarSet, RttiVarMaps0, RttiVarMaps, Goal1),
- pred_info_set_typevarset(TypeVarSet, PredInfo0, PredInfo),
+ TypeVarSet0, TypeVarSet, RttiVarMaps0, RttiVarMaps,
+ MayHaveParallelConj, Goal1),
+ pred_info_set_typevarset(TypeVarSet, PredInfo0, PredInfo1),
+ (
+ MayHaveParallelConj = yes,
+ pred_info_get_markers(PredInfo1, Markers1),
+ add_marker(may_have_parallel_conj, Markers1, Markers),
+ pred_info_set_markers(Markers, PredInfo1, PredInfo)
+ ;
+ MayHaveParallelConj = no,
+ PredInfo = PredInfo1
+ ),
proc_info_set_varset(VarSet, ProcInfo0, ProcInfo1),
proc_info_set_vartypes(VarTypes, ProcInfo1, ProcInfo2),
proc_info_set_rtti_varmaps(RttiVarMaps, ProcInfo2, ProcInfo),
Index: compiler/dep_par_conj.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/dep_par_conj.m,v
retrieving revision 1.6
diff -u -r1.6 dep_par_conj.m
--- compiler/dep_par_conj.m 9 Aug 2006 03:17:14 -0000 1.6
+++ compiler/dep_par_conj.m 9 Aug 2006 06:34:34 -0000
@@ -56,7 +56,6 @@
% into sequential conjunctions.
%
% TODO:
-% - only run this pass if parallel conjunctions are present in a module
% - reconsider when this pass is run; in particular par_builtin primitives
% ought to be inlined
%
@@ -215,9 +214,14 @@
process_pred_for_dep_par_conj(PredId, !ModuleInfo, !ParProcs, !IO) :-
module_info_pred_info(!.ModuleInfo, PredId, PredInfo),
- ProcIds = pred_info_non_imported_procids(PredInfo),
- list.foldl3(process_proc_for_dep_par_conj(PredId), ProcIds,
- !ModuleInfo, !ParProcs, !IO).
+ pred_info_get_markers(PredInfo, Markers),
+ (if check_marker(Markers, may_have_parallel_conj) then
+ ProcIds = pred_info_non_imported_procids(PredInfo),
+ list.foldl3(process_proc_for_dep_par_conj(PredId), ProcIds,
+ !ModuleInfo, !ParProcs, !IO)
+ else
+ true
+ ).
:- pred process_proc_for_dep_par_conj(pred_id::in, proc_id::in,
module_info::in, module_info::out, par_procs::in, par_procs::out,
@@ -258,7 +262,9 @@
!:VarSet, !:VarTypes, _IgnoreVars)
),
- % XXX we really only need to run this part if something changed
+ % We really only need to run this part if something changed, but we
+ % only run this predicate on procedures which are likely to have
+ % parallel conjunctions.
proc_info_set_varset(!.VarSet, !ProcInfo),
proc_info_set_vartypes(!.VarTypes, !ProcInfo),
proc_info_set_goal(!.Body, !ProcInfo),
Index: compiler/hlds_out.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_out.m,v
retrieving revision 1.396
diff -u -r1.396 hlds_out.m
--- compiler/hlds_out.m 31 Jul 2006 08:31:40 -0000 1.396
+++ compiler/hlds_out.m 9 Aug 2006 05:08:33 -0000
@@ -1017,6 +1017,7 @@
marker_name(does_not_terminate, "does_not_terminate").
marker_name(calls_are_fully_qualified, "calls_are_fully_qualified").
marker_name(mode_check_clauses, "mode_check_clauses").
+marker_name(may_have_parallel_conj, "may_have_parallel_conj").
write_marker(Marker, !IO) :-
marker_name(Marker, Name),
Index: compiler/hlds_pred.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_pred.m,v
retrieving revision 1.204
diff -u -r1.204 hlds_pred.m
--- compiler/hlds_pred.m 9 Aug 2006 03:17:14 -0000 1.204
+++ compiler/hlds_pred.m 9 Aug 2006 05:07:03 -0000
@@ -385,7 +385,7 @@
% All calls in this predicate are fully qualified.
% This occurs for predicates read from `.opt' files
% and compiler-generated predicates.
- ; mode_check_clauses.
+ ; mode_check_clauses
% Each clause of the predicate should be modechecked
% separately. Used for predicates defined by lots of
% clauses (usually facts) for which the compiler's
@@ -393,6 +393,11 @@
% inst_match.bound_inst_list_contains_instname and
% instmap.merge) would be unacceptable.
+ ; may_have_parallel_conj.
+ % The predicate may contain parallel conjunctions.
+ % It should be run through the dependent parallel
+ % conjunction transformation.
+
% An abstract set of attributes.
:- type pred_attributes.
Index: compiler/inlining.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/inlining.m,v
retrieving revision 1.143
diff -u -r1.143 inlining.m
--- compiler/inlining.m 31 Jul 2006 08:31:42 -0000 1.143
+++ compiler/inlining.m 9 Aug 2006 05:09:18 -0000
@@ -114,7 +114,7 @@
:- pred do_inline_call(list(tvar)::in, list(prog_var)::in,
pred_info::in, proc_info::in, prog_varset::in, prog_varset::out,
vartypes::in, vartypes::out, tvarset::in, tvarset::out,
- rtti_varmaps::in, rtti_varmaps::out, hlds_goal::out) is det.
+ rtti_varmaps::in, rtti_varmaps::out, bool::out, hlds_goal::out) is det.
% get_type_substitution(CalleeArgTypes, CallerArgTypes,
% HeadTypeParams, CalleeExistQTVars, TypeSubn):
@@ -458,7 +458,7 @@
pred_info_get_univ_quant_tvars(!.PredInfo, UnivQTVars),
pred_info_get_typevarset(!.PredInfo, TypeVarSet0),
- pred_info_get_markers(!.PredInfo, Markers),
+ pred_info_get_markers(!.PredInfo, Markers0),
proc_info_get_goal(!.ProcInfo, Goal0),
proc_info_get_varset(!.ProcInfo, VarSet0),
@@ -471,16 +471,17 @@
PurityChanged0 = no,
InlineInfo0 = inline_info(VarThresh, HighLevelCode, AnyTracing,
- InlinedProcs, !.ModuleInfo, UnivQTVars, Markers,
+ InlinedProcs, !.ModuleInfo, UnivQTVars, Markers0,
VarSet0, VarTypes0, TypeVarSet0, RttiVarMaps0,
DidInlining0, Requantify0, DetChanged0, PurityChanged0),
inlining_in_goal(Goal0, Goal, InlineInfo0, InlineInfo),
- InlineInfo = inline_info(_, _, _, _, _, _, _, VarSet, VarTypes,
+ InlineInfo = inline_info(_, _, _, _, _, _, Markers, VarSet, VarTypes,
TypeVarSet, RttiVarMaps, DidInlining, Requantify,
DetChanged, PurityChanged),
+ pred_info_set_markers(Markers, !PredInfo),
pred_info_set_typevarset(TypeVarSet, !PredInfo),
proc_info_set_varset(VarSet, !ProcInfo),
@@ -597,7 +598,7 @@
inlining_in_call(PredId, ProcId, ArgVars, Builtin,
Context, Sym, Goal, GoalInfo0, GoalInfo, !Info) :-
!.Info = inline_info(VarThresh, HighLevelCode, AnyTracing,
- InlinedProcs, ModuleInfo, HeadTypeParams, Markers,
+ InlinedProcs, ModuleInfo, HeadTypeParams, Markers0,
VarSet0, VarTypes0, TypeVarSet0, RttiVarMaps0,
_DidInlining0, Requantify0, DetChanged0, PurityChanged0),
@@ -605,7 +606,7 @@
% Should we inline this call?
(
should_inline_proc(PredId, ProcId, Builtin, HighLevelCode,
- AnyTracing, InlinedProcs, Markers, ModuleInfo, UserReq),
+ AnyTracing, InlinedProcs, Markers0, ModuleInfo, UserReq),
(
UserReq = yes
;
@@ -624,7 +625,7 @@
->
do_inline_call(HeadTypeParams, ArgVars, PredInfo, ProcInfo,
VarSet0, VarSet, VarTypes0, VarTypes, TypeVarSet0, TypeVarSet,
- RttiVarMaps0, RttiVarMaps, Goal - GoalInfo),
+ RttiVarMaps0, RttiVarMaps, MayHaveParallelConj, Goal - GoalInfo),
% If some of the output variables are not used in the calling
% procedure, requantify the procedure.
@@ -655,6 +656,15 @@
;
DetChanged = yes
),
+
+ (
+ MayHaveParallelConj = yes,
+ add_marker(may_have_parallel_conj, Markers0, Markers)
+ ;
+ MayHaveParallelConj = no,
+ Markers = Markers0
+ ),
+
!:Info = inline_info(VarThresh, HighLevelCode, AnyTracing,
InlinedProcs, ModuleInfo, HeadTypeParams, Markers,
VarSet, VarTypes, TypeVarSet, RttiVarMaps,
@@ -668,7 +678,7 @@
do_inline_call(HeadTypeParams, ArgVars, PredInfo, ProcInfo,
VarSet0, VarSet, VarTypes0, VarTypes, TypeVarSet0, TypeVarSet,
- RttiVarMaps0, RttiVarMaps, Goal) :-
+ RttiVarMaps0, RttiVarMaps, MayHaveParallelConj, Goal) :-
proc_info_get_goal(ProcInfo, CalledGoal),
@@ -744,7 +754,11 @@
% have been produced by extracting type_infos or typeclass_infos
% from typeclass_infos in the caller, so they won't necessarily
% be the same.
- rtti_varmaps_overlay(CalleeRttiVarMaps1, RttiVarMaps0, RttiVarMaps).
+ rtti_varmaps_overlay(CalleeRttiVarMaps1, RttiVarMaps0, RttiVarMaps),
+
+ pred_info_get_markers(PredInfo, CalleeMarkers),
+ MayHaveParallelConj = pred_to_bool(check_marker(CalleeMarkers,
+ may_have_parallel_conj)).
get_type_substitution(HeadTypes, ArgTypes,
HeadTypeParams, CalleeExistQVars, TypeSubn) :-
Index: compiler/intermod.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/intermod.m,v
retrieving revision 1.202
diff -u -r1.202 intermod.m
--- compiler/intermod.m 31 Jul 2006 08:31:43 -0000 1.202
+++ compiler/intermod.m 9 Aug 2006 05:08:54 -0000
@@ -1801,6 +1801,7 @@
should_output_marker(check_termination, no).
should_output_marker(calls_are_fully_qualified, no).
should_output_marker(mode_check_clauses, yes).
+should_output_marker(may_have_parallel_conj, no).
:- pred get_pragma_foreign_code_vars(list(foreign_arg)::in, list(mer_mode)::in,
prog_varset::in, prog_varset::out, list(pragma_var)::out) is det.
Index: compiler/lambda.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/lambda.m,v
retrieving revision 1.118
diff -u -r1.118 lambda.m
--- compiler/lambda.m 4 Aug 2006 10:51:18 -0000 1.118
+++ compiler/lambda.m 9 Aug 2006 05:02:41 -0000
@@ -472,7 +472,12 @@
list.append(ArgModes1, Modes, AllArgModes),
map.apply_to_list(AllArgVars, VarTypes, ArgTypes),
- purity_to_markers(Purity, LambdaMarkers),
+ purity_to_markers(Purity, LambdaMarkers0),
+ (if check_marker(Markers, may_have_parallel_conj) then
+ add_marker(may_have_parallel_conj, LambdaMarkers0, LambdaMarkers)
+ else
+ LambdaMarkers = LambdaMarkers0
+ ),
% Now construct the proc_info and pred_info for the new single-mode
% predicate, using the information computed above.
Index: compiler/simplify.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/simplify.m,v
retrieving revision 1.184
diff -u -r1.184 simplify.m
--- compiler/simplify.m 9 Aug 2006 03:17:15 -0000 1.184
+++ compiler/simplify.m 9 Aug 2006 05:03:19 -0000
@@ -57,7 +57,7 @@
:- pred simplify_proc_return_msgs(simplifications::in, pred_id::in,
proc_id::in, module_info::in, module_info::out,
- proc_info::in, proc_info::out, set(context_det_msg)::out,
+ proc_info::in, proc_info::out, set(context_det_msg)::out, bool::out,
io::di, io::uo) is det.
:- pred simplify_process_goal(hlds_goal::in, hlds_goal::out,
@@ -326,7 +326,7 @@
pred_info_get_procedures(!.PredInfo, Procs0),
map.lookup(Procs0, ProcId, Proc0),
simplify_proc_return_msgs(Simplifications, PredId, ProcId,
- !ModuleInfo, Proc0, Proc, ProcMsgSet, !IO),
+ !ModuleInfo, Proc0, Proc, ProcMsgSet, MayHaveParallelConj, !IO),
map.det_update(Procs0, ProcId, Proc, Procs),
pred_info_set_procedures(Procs, !PredInfo),
set.to_sorted_list(ProcMsgSet, ProcMsgs),
@@ -344,20 +344,32 @@
!.MaybeMsgs = no,
!:MaybeMsgs = yes(ProcAnyModeMsgSet - ProcAllModeMsgSet)
),
+ % This is ugly, but we want to avoid running the dependent parallel
+ % conjunction pass on predicates not containing parallel conjunctions
+ % (nearly all of them). Since simplification is always done, we use it
+ % to mark predicates containing parallel conjunctions.
+ (
+ MayHaveParallelConj = yes,
+ pred_info_get_markers(!.PredInfo, Markers0),
+ add_marker(may_have_parallel_conj, Markers0, Markers),
+ pred_info_set_markers(Markers, !PredInfo)
+ ;
+ MayHaveParallelConj = no
+ ),
simplify_procs(Simplifications, PredId, ProcIds, !ModuleInfo, !PredInfo,
!MaybeMsgs, !IO).
simplify_proc(Simplifications, PredId, ProcId, !ModuleInfo, !Proc, !IO) :-
write_pred_progress_message("% Simplifying ", PredId, !.ModuleInfo, !IO),
simplify_proc_return_msgs(Simplifications, PredId, ProcId, !ModuleInfo,
- !Proc, _, !IO).
+ !Proc, _, _, !IO).
:- func turn_off_common_struct_threshold = int.
turn_off_common_struct_threshold = 1000.
simplify_proc_return_msgs(Simplifications0, PredId, ProcId, !ModuleInfo,
- !ProcInfo, DetMsgs, !IO) :-
+ !ProcInfo, DetMsgs, MayHaveParallelConj, !IO) :-
module_info_get_globals(!.ModuleInfo, Globals),
proc_info_get_vartypes(!.ProcInfo, VarTypes0),
NumVars = map.count(VarTypes0),
@@ -431,7 +443,8 @@
;
IsDefinedHere = yes,
DetMsgs = DetMsgs1
- ).
+ ),
+ MayHaveParallelConj = Info ^ may_have_parallel_conj.
simplify_process_goal(Goal0, Goal, !Info, !IO) :-
simplify_info_get_simplifications(!.Info, Simplifications0),
@@ -778,7 +791,8 @@
Goals0 = [_, _ | _],
GoalInfo = GoalInfo0,
simplify_par_conj(Goals0, Goals, !.Info, !Info, !IO),
- Goal = conj(parallel_conj, Goals)
+ Goal = conj(parallel_conj, Goals),
+ !:Info = !.Info ^ may_have_parallel_conj := yes
)
).
@@ -2604,9 +2618,11 @@
format_calls :: bool,
% Do we have any calls to
% string.format and io.format?
- inside_dupl_for_switch :: bool
+ inside_dupl_for_switch :: bool,
% Are we currently inside a goal
% that was duplicated for a switch?
+ may_have_parallel_conj :: bool
+ % Have we seen a parallel conjunction?
).
simplify_info_init(DetInfo, Simplifications, InstMap, ProcInfo, Info) :-
@@ -2616,7 +2632,7 @@
set.init(Msgs),
Info = simplify_info(DetInfo, Msgs, Simplifications,
common_info_init, InstMap, VarSet, InstVarSet,
- no, no, no, 0, 0, RttiVarMaps, no, no).
+ no, no, no, 0, 0, RttiVarMaps, no, no, no).
% Reinitialise the simplify_info before reprocessing a goal.
%
@@ -2630,7 +2646,8 @@
!:Info = !.Info ^ requantify := no,
!:Info = !.Info ^ recompute_atomic := no,
!:Info = !.Info ^ rerun_det := no,
- !:Info = !.Info ^ lambdas := 0.
+ !:Info = !.Info ^ lambdas := 0,
+ !:Info = !.Info ^ may_have_parallel_conj := no.
% exported for common.m
:- interface.
Index: compiler/size_prof.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/size_prof.m,v
retrieving revision 1.43
diff -u -r1.43 size_prof.m
--- compiler/size_prof.m 4 Aug 2006 10:51:20 -0000 1.43
+++ compiler/size_prof.m 9 Aug 2006 05:09:26 -0000
@@ -239,7 +239,7 @@
process_proc(Transform, PredId, ProcId, !ProcInfo, !ModuleInfo, !IO) :-
Simplifications = list_to_simplifications([]),
simplify_proc_return_msgs(Simplifications, PredId, ProcId,
- !ModuleInfo, !ProcInfo, _Msgs, !IO),
+ !ModuleInfo, !ProcInfo, _Msgs, _MayHaveParallelConj, !IO),
proc_info_get_goal(!.ProcInfo, Goal0),
proc_info_get_varset(!.ProcInfo, VarSet0),
Index: compiler/table_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/table_gen.m,v
retrieving revision 1.114
diff -u -r1.114 table_gen.m
--- compiler/table_gen.m 1 Aug 2006 07:37:49 -0000 1.114
+++ compiler/table_gen.m 9 Aug 2006 05:08:42 -0000
@@ -1930,6 +1930,7 @@
keep_marker(check_termination) = no.
keep_marker(calls_are_fully_qualified) = yes.
keep_marker(mode_check_clauses) = yes.
+keep_marker(may_have_parallel_conj) = yes.
%-----------------------------------------------------------------------------%
--------------------------------------------------------------------------
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