[m-dev.] diff: merge trunk_snapshot_19990615175135 into alias branch [2/2]

Peter Ross petdr at cs.mu.OZ.AU
Wed Jun 16 12:01:07 AEST 1999


Index: compiler/goal_util.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/goal_util.m,v
retrieving revision 1.38.2.10
diff -u -b -r1.38.2.10 goal_util.m
--- goal_util.m	1999/05/05 01:23:20	1.38.2.10
+++ goal_util.m	1999/06/15 12:34:51
@@ -1,5 +1,5 @@
 %-----------------------------------------------------------------------------%
-% Copyright (C) 1995-1998 The University of Melbourne.
+% Copyright (C) 1995-1999 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.
 %-----------------------------------------------------------------------------%
@@ -142,11 +142,36 @@
 :- mode goal_util__if_then_else_to_disjunction(in, in, in, in, out) is det.
 
 %-----------------------------------------------------------------------------%
+
+	% goal_util__can_reorder_goals(ModuleInfo, FullyStrict, Goal1, Goal2).
+	%
+	% Goals can be reordered if
+	% - the goals are independent
+	% - the goals are not impure
+	% - any possible change in termination behaviour is allowed
+	% 	according to the semantics options.
+	%
+:- pred goal_util__can_reorder_goals(module_info::in, bool::in, 
+		inst_table::in, instmap::in, hlds_goal::in,
+		instmap::in, hlds_goal::in) is semidet.
+
+	% goal_util__reordering_maintains_termination(ModuleInfo,
+	%		 FullyStrict, Goal1, Goal2)
+	%
+	% Succeeds if any possible change in termination behaviour from
+	% reordering the goals is allowed according to the semantics options.
+	% The information computed by termination analysis is used when
+	% making this decision.
+	%
+:- pred goal_util__reordering_maintains_termination(module_info::in, bool::in, 
+		hlds_goal::in, hlds_goal::in) is semidet.
+
+%-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
 :- implementation.
 
-:- import_module hlds_data, mode_util, code_aux, prog_data.
+:- import_module hlds_data, mode_util, code_aux, prog_data, purity.
 :- import_module code_aux, det_analysis, inst_match, type_util, (inst).
 :- import_module int, std_util, string, assoc_list, require, varset.
 
@@ -865,6 +890,94 @@
 
 	goal_info_init(CombinedNonLocals, CombinedDelta, 
 		CombinedDetism, CombinedInfo).
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
+
+goal_util__can_reorder_goals(ModuleInfo, FullyStrict, InstTable,
+		InstmapBeforeEarlierGoal, EarlierGoal,
+		InstmapBeforeLaterGoal, LaterGoal) :-
+
+	EarlierGoal = _ - EarlierGoalInfo,
+	LaterGoal = _ - LaterGoalInfo,
+
+		% Impure goals cannot be reordered.
+	\+ goal_info_is_impure(EarlierGoalInfo),
+	\+ goal_info_is_impure(LaterGoalInfo),
+
+	goal_util__reordering_maintains_termination(ModuleInfo, FullyStrict, 
+		EarlierGoal, LaterGoal),
+
+	%
+	% Don't reorder the goals if the later goal depends
+	% on the outputs of the current goal.
+	%
+	\+ goal_depends_on_earlier_goal(LaterGoal, EarlierGoal,
+			InstmapBeforeEarlierGoal, InstTable, ModuleInfo),
+
+	%
+	% Don't reorder the goals if the later goal changes the 
+	% instantiatedness of any of the non-locals of the earlier
+	% goal. This is necessary if the later goal clobbers any 
+	% of the non-locals of the earlier goal, and avoids rerunning
+	% full mode analysis in other cases.
+	%
+	\+ goal_depends_on_earlier_goal(EarlierGoal, LaterGoal, 
+			InstmapBeforeLaterGoal, InstTable, ModuleInfo).
+
+
+goal_util__reordering_maintains_termination(ModuleInfo, FullyStrict, 
+		EarlierGoal, LaterGoal) :-
+	EarlierGoal = _ - EarlierGoalInfo,
+	LaterGoal = _ - LaterGoalInfo,
+
+	goal_info_get_determinism(EarlierGoalInfo, EarlierDetism),
+	determinism_components(EarlierDetism, EarlierCanFail, _),
+	goal_info_get_determinism(LaterGoalInfo, LaterDetism),
+	determinism_components(LaterDetism, LaterCanFail, _),
+
+		% If --fully-strict was specified, don't convert 
+		% (can_loop, can_fail) into (can_fail, can_loop). 
+	( 
+		FullyStrict = yes, 
+		\+ code_aux__goal_cannot_loop(ModuleInfo, EarlierGoal)
+	->
+		LaterCanFail = cannot_fail
+	;
+		true
+	),
+		% Don't convert (can_fail, can_loop) into 
+		% (can_loop, can_fail), since this could worsen 
+		% the termination properties of the program.
+	( EarlierCanFail = can_fail ->
+		code_aux__goal_cannot_loop(ModuleInfo, LaterGoal)
+	;
+		true
+	).
+
+	%
+	% If the earlier goal changes the instantiatedness of a variable
+	% that is used in the later goal, then the later goal depends on
+	% the earlier goal.
+	%
+	% This code does work on the alias branch.
+	%
+:- pred goal_depends_on_earlier_goal(hlds_goal::in, hlds_goal::in,
+		instmap::in, inst_table::in, module_info::in) is semidet.
+
+goal_depends_on_earlier_goal(_ - LaterGoalInfo, _ - EarlierGoalInfo,
+		InstMapBeforeEarlierGoal, InstTable, ModuleInfo) :-
+	goal_info_get_instmap_delta(EarlierGoalInfo, EarlierInstMapDelta),
+	instmap__apply_instmap_delta(InstMapBeforeEarlierGoal,
+			EarlierInstMapDelta, InstMapAfterEarlierGoal),
+
+	instmap_changed_vars(InstMapBeforeEarlierGoal, InstMapAfterEarlierGoal,
+			InstTable, ModuleInfo, EarlierChangedVars),
+
+	goal_info_get_nonlocals(LaterGoalInfo, LaterGoalNonLocals),
+	set__intersect(EarlierChangedVars, LaterGoalNonLocals, Intersection),
+	not set__empty(Intersection).
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
Index: compiler/hlds_out.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/hlds_out.m,v
retrieving revision 1.172.2.24
diff -u -b -r1.172.2.24 hlds_out.m
--- hlds_out.m	1999/06/03 01:38:35	1.172.2.24
+++ hlds_out.m	1999/06/15 07:53:19
@@ -766,7 +766,7 @@
 			AppendVarnums),
 		io__write_string(" = "),
 		mercury_output_term(term__variable(RetVal), VarSet,
-			AppendVarnums)
+			AppendVarnums, next_to_graphic_token)
 	;
 		{ PredOrFunc = predicate },
 		hlds_out__write_qualified_functor(ModuleName,
@@ -1253,7 +1253,7 @@
 	;
 		{ PredName = unqualified(Name) },
 		hlds_out__write_functor(term__atom(Name), ArgVars, VarSet,
-			AppendVarnums)
+			AppendVarnums, next_to_graphic_token)
 	),
 	io__write_string(Follow),
 	( { string__contains_char(Verbose, 'l') } ->
@@ -1541,7 +1541,7 @@
 		AppendVarnums),
 	( { MaybeType = yes(Type), TypeQual = yes(TVarSet, _) } ->
 		io__write_string(" TYPE_QUAL_OP "),
-		mercury_output_term(Type, TVarSet, no)
+		mercury_output_term(Type, TVarSet, no, next_to_graphic_token)
 	;
 		[]
 	).
@@ -1586,7 +1586,8 @@
 	),
 	( { MaybeType = yes(Type), TypeQual = yes(TVarSet, _) } ->
 		io__write_string(" TYPE_QUAL_OP "),
-		mercury_output_term(Type, TVarSet, AppendVarnums)
+		mercury_output_term(Type, TVarSet, AppendVarnums,
+			next_to_graphic_token)
 	;
 		[]
 	),
@@ -1644,7 +1645,8 @@
 		;
 			{ SymName = unqualified(Name) },
 			hlds_out__write_functor(term__atom(Name),
-				ArgVars, VarSet, AppendVarnums)
+				ArgVars, VarSet, AppendVarnums,
+				next_to_graphic_token)
 		)
 	;
 		{ ConsId = int_const(Int) },
Index: compiler/instmap.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/instmap.m,v
retrieving revision 1.15.2.21
diff -u -b -r1.15.2.21 instmap.m
--- instmap.m	1999/05/05 01:23:35	1.15.2.21
+++ instmap.m	1999/06/15 11:24:28
@@ -104,6 +104,16 @@
 :- pred instmap__vars_list(instmap, list(prog_var)).
 :- mode instmap__vars_list(in, out) is det.
 
+	%
+	% instmap_changed_vars(IMA, IMB, IT, MI, CV)
+	%
+	% Given an earlier instmap, IMA, and a later instmap, IMB,
+	% determine what variables, CV, have had their instantiatedness
+	% information changed.
+	%
+:- pred instmap_changed_vars(instmap::in, instmap::in, inst_table::in,
+		module_info::in, set(prog_var)::out) is det.
+
 %-----------------------------------------------------------------------------%
 
 	% Given an instmap and a variable, determine the inst of
@@ -374,6 +384,35 @@
 instmap__vars_list(unreachable, []).
 instmap__vars_list(reachable(InstMapping, _), VarsList) :-
 	map__keys(InstMapping, VarsList).
+
+%-----------------------------------------------------------------------------%
+
+instmap_changed_vars(InstMapA, InstMapB, InstTable, ModuleInfo, ChangedVars) :-
+	instmap__vars_list(InstMapB, VarsB),
+	changed_vars_2(VarsB, InstMapA, InstMapB,
+			InstTable, ModuleInfo, ChangedVars).
+
+:- pred changed_vars_2(prog_vars::in, instmap::in, instmap::in,
+		inst_table::in, module_info::in, set(prog_var)::out) is det.
+
+changed_vars_2([], _InstMapA, _InstMapB, _InstTbl, _ModuleInfo, ChangedVars) :-
+	set__init(ChangedVars).
+changed_vars_2([VarB|VarBs], InstMapA, InstMapB,
+		InstTable, ModuleInfo, ChangedVars) :-
+	changed_vars_2(VarBs, InstMapA, InstMapB, InstTable,
+			ModuleInfo, ChangedVars0),
+
+	instmap__lookup_var(InstMapA, VarB, InitialInst),
+	instmap__lookup_var(InstMapB, VarB, FinalInst),
+
+	(
+		inst_matches_final(InitialInst, InstMapA,
+				FinalInst, InstMapB, InstTable, ModuleInfo)
+	->
+		ChangedVars = ChangedVars0
+	;
+		set__insert(ChangedVars0, VarB, ChangedVars)
+	).
 
 %-----------------------------------------------------------------------------%
 
Index: compiler/mercury_compile.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/mercury_compile.m,v
retrieving revision 1.53.2.18
diff -u -b -r1.53.2.18 mercury_compile.m
--- mercury_compile.m	1999/06/03 01:38:54	1.53.2.18
+++ mercury_compile.m	1999/06/15 07:53:20
@@ -37,7 +37,7 @@
 :- import_module bytecode_gen, bytecode.
 :- import_module (lambda), polymorphism, termination, higher_order, inlining.
 :- import_module deforest, dnf, unused_args, magic, dead_proc_elim.
-:- import_module lco, saved_vars, liveness.
+:- import_module accumulator, lco, saved_vars, liveness.
 :- import_module follow_code, live_vars, arg_info, store_alloc, goal_path.
 :- import_module code_gen, optimize, export, base_type_info, base_type_layout.
 :- import_module rl_gen, rl_opt, rl_out.
@@ -1004,7 +1004,11 @@
 	mercury_compile__maybe_unused_args(HLDS36, Verbose, Stats, HLDS38), !,
 	mercury_compile__maybe_dump_hlds(HLDS38, "38", "unused_args"), !,
 
-	mercury_compile__maybe_lco(HLDS38, Verbose, Stats, HLDS40), !,
+	mercury_compile__maybe_introduce_accumulators(HLDS38,
+			Verbose, Stats, HLDS39), !,
+	mercury_compile__maybe_dump_hlds(HLDS39, "39", "accum"), !,
+
+	mercury_compile__maybe_lco(HLDS39, Verbose, Stats, HLDS40), !,
 	mercury_compile__maybe_dump_hlds(HLDS40, "40", "lco"), !,
 
 	% DNF transformations should be after inlining.
@@ -1781,6 +1785,28 @@
 	;
 		{ HLDS0 = HLDS }
 	).
+
+
+:- pred mercury_compile__maybe_introduce_accumulators(module_info, bool, bool,
+	module_info, io__state, io__state).
+:- mode mercury_compile__maybe_introduce_accumulators(in, in, in, out, di, uo)
+	is det.
+
+mercury_compile__maybe_introduce_accumulators(HLDS0, Verbose, Stats, HLDS) -->
+	globals__io_lookup_bool_option(introduce_accumulators, Optimize),
+	( { Optimize = yes } ->
+		maybe_write_string(Verbose,
+				"% Attempting to introduce accumulators...\n"),
+		maybe_flush_output(Verbose),
+		process_all_nonimported_procs(
+			update_module_io(accumulator__process_proc),
+			HLDS0, HLDS),
+		maybe_write_string(Verbose, "% done.\n"),
+		maybe_report_stats(Stats)
+	;
+		{ HLDS0 = HLDS }
+	).
+
 
 :- pred mercury_compile__maybe_lco(module_info, bool, bool,
 	module_info, io__state, io__state).
Index: compiler/mercury_to_mercury.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/mercury_to_mercury.m,v
retrieving revision 1.115.2.24
diff -u -b -r1.115.2.24 mercury_to_mercury.m
--- mercury_to_mercury.m	1999/05/05 01:24:00	1.115.2.24
+++ mercury_to_mercury.m	1999/06/15 07:53:20
@@ -1310,7 +1310,7 @@
 mercury_output_type_defn_2(abstract_type(Name, Args), VarSet, Context) -->
 	io__write_string(":- type "),
 	{ construct_qualified_term(Name, Args, Context, TypeTerm) },
-	mercury_output_term(TypeTerm, VarSet, no),
+	mercury_output_term(TypeTerm, VarSet, no, next_to_graphic_token),
 	io__write_string(".\n").
 
 mercury_output_type_defn_2(eqv_type(Name, Args, Body), VarSet, Context) -->
@@ -1318,7 +1318,7 @@
 	{ construct_qualified_term(Name, Args, Context, TypeTerm) },
 	mercury_output_term(TypeTerm, VarSet, no),
 	io__write_string(" == "),
-	mercury_output_term(Body, VarSet, no),
+	mercury_output_term(Body, VarSet, no, next_to_graphic_token),
 	io__write_string(".\n").
 
 mercury_output_type_defn_2(du_type(Name, Args, Ctors, MaybeEqualityPred),
@@ -1594,7 +1594,7 @@
 		mercury_output_bracketed_sym_name(FuncName)
 	),
 	io__write_string(" = "),
-	mercury_output_term(RetType, VarSet, no),
+	mercury_output_term(RetType, VarSet, no, next_to_graphic_token),
 	mercury_output_class_context(ClassContext, ExistQVars, VarSet),
 	mercury_output_det_annotation(MaybeDet),
 	io__write_string(Separator).
@@ -1878,12 +1878,12 @@
 		[]
 	),
 	io__write_string(" = "),
-	mercury_output_term(Result, VarSet, no),
 	(
 		{ Body = true - _Context0 }
 	->
-		[]
+		mercury_output_term(Result, VarSet, no, next_to_graphic_token)
 	;
+		mercury_output_term(Result, VarSet, no),
 		io__write_string(" :-\n\t"),
 		mercury_output_goal(Body, VarSet, 1)
 	),
@@ -2011,7 +2011,7 @@
 mercury_output_goal_2(unify(A, B), VarSet, _Indent) -->
 	mercury_output_term(A, VarSet, no),
 	io__write_string(" = "),
-	mercury_output_term(B, VarSet, no).
+	mercury_output_term(B, VarSet, no, next_to_graphic_token).
 
 
 :- pred mercury_output_call(sym_name, list(prog_term), prog_varset, int,
@@ -2031,7 +2031,7 @@
 		{ Name = unqualified(PredName) },
 		{ term__context_init(Context0) },
 		mercury_output_term(term__functor(term__atom(PredName),
-			Term, Context0), VarSet, no)
+			Term, Context0), VarSet, no, next_to_graphic_token)
 	).
 
 :- pred mercury_output_disj(goal, prog_varset, int, io__state, io__state).
Index: compiler/options.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/options.m,v
retrieving revision 1.203.2.21
diff -u -b -r1.203.2.21 options.m
--- options.m	1999/06/03 01:39:05	1.203.2.21
+++ options.m	1999/06/15 07:53:21
@@ -257,6 +257,7 @@
 		;	type_specialization
 		;	user_guided_type_specialization
 		;	higher_order_size_limit
+		;	introduce_accumulators
 		;	optimize_constructor_last_call
 		;	optimize_duplicate_calls
 		;	constant_propagation
@@ -605,6 +606,7 @@
 	type_specialization	-	bool(no),
 	user_guided_type_specialization	-	bool(no),
 	higher_order_size_limit	-	int(20),
+	introduce_accumulators -	bool(no),
 	optimize_constructor_last_call -	bool(no),
 	optimize_dead_procs	-	bool(no),
 	deforestation		-	bool(no),
@@ -942,6 +944,7 @@
 long_option("user-guided-type-specialisation",
 					user_guided_type_specialization).
 long_option("higher-order-size-limit",	higher_order_size_limit).
+long_option("introduce-accumulators",	introduce_accumulators).
 long_option("optimise-constructor-last-call",	optimize_constructor_last_call).
 long_option("optimize-constructor-last-call",	optimize_constructor_last_call).
 long_option("optimize-dead-procs",	optimize_dead_procs).
@@ -1996,6 +1999,9 @@
 		"\t`--optimize-higher-order' and `--type-specialization'.",
 		"\tGoal size is measured as the number of calls, unifications",
 		"\tand branched goals.",
+		"--introduce-accumulators",
+		"\tAttempt to introduce accumulating variables into",
+		"\tprocedures, so as to make them tail recursive.",
 		"--optimize-constructor-last-call",
 		"\tEnable the optimization of ""last"" calls that are followed by",
 		"\tconstructor application.",
Index: compiler/passes_aux.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/passes_aux.m,v
retrieving revision 1.22.4.10
diff -u -b -r1.22.4.10 passes_aux.m
--- passes_aux.m	1999/05/05 01:24:23	1.22.4.10
+++ passes_aux.m	1999/06/15 07:53:22
@@ -37,7 +37,7 @@
 				pred_id, proc_id, proc_info, proc_info,
 				module_info, module_info,
 				io__state, io__state))
-		% It would be better to use an existentiallly-quantified type
+		% It would be better to use an existentially-quantified type
 		% rather than `univ' here, but the current version of Mercury 
 		% doesn't support existentially-quantified types.
 		;	update_module_cookie(pred(
Index: compiler/quantification.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/quantification.m,v
retrieving revision 1.53.2.7
diff -u -b -r1.53.2.7 quantification.m
--- quantification.m	1999/05/05 01:24:46	1.53.2.7
+++ quantification.m	1999/06/15 12:27:36
@@ -68,8 +68,11 @@
 %-----------------------------------------------------------------------------%
 
 :- implementation.
+
+:- import_module instmap, goal_util.
+
 :- import_module term, varset.
-:- import_module std_util, bool, goal_util, require.
+:- import_module std_util, bool, require.
 
 	% The `outside vars', `lambda outside vars', and `quant vars'
 	% fields are inputs; the `nonlocals' field is output; and
@@ -169,6 +172,18 @@
 		{ GoalInfo1 = GoalInfo0 }
 	),
 	{ goal_info_set_nonlocals(GoalInfo1, NonLocalVars, GoalInfo) }.
+	/* XXX instmap_delta_restrict no longer exists
+	{ goal_info_set_nonlocals(GoalInfo1, NonLocalVars, GoalInfo2) },
+	%
+	% If the non-locals set has shrunk (e.g. because some optimization
+	% optimizes away the other occurrences of a variable, causing it
+	% to become local when previously it was non-local),
+	% then we may need to likewise shrink the instmap delta.
+	%
+	{ goal_info_get_instmap_delta(GoalInfo2, InstMapDelta0) },
+	{ instmap_delta_restrict(InstMapDelta0, NonLocalVars, InstMapDelta) },
+	{ goal_info_set_instmap_delta(GoalInfo2, InstMapDelta, GoalInfo) }.
+	*/
 
 :- pred implicitly_quantify_goal_2(hlds_goal_expr, prog_context,
 				hlds_goal_expr, quant_info, quant_info).
Index: compiler/rl_code.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/rl_code.m,v
retrieving revision 1.2.2.2
diff -u -b -r1.2.2.2 rl_code.m
--- rl_code.m	1999/06/03 01:39:10	1.2.2.2
+++ rl_code.m	1999/06/15 07:53:22
@@ -5,7 +5,7 @@
 %-----------------------------------------------------------------------------%
 % Do not edit - this file was automatically generated by
 % $ADITI_ROOT/src/rosi/create_rl_code_m.
-% Created Tue May 11 12:46:29 1999
+% Created Wed Jun  2 16:41:37 1999
 
 %-----------------------------------------------------------------------------%
 :- module rl_code.
@@ -335,6 +335,7 @@
 	;	rl_PROC_conditional_goto_label(int32)
 	;	rl_PROC_notempty
 	;	rl_PROC_empty
+	;	rl_PROC_one_reference(int32)
 	;	rl_PROC_and
 	;	rl_PROC_or
 	;	rl_PROC_not
@@ -1414,241 +1415,245 @@
 bytecode_to_intlist(rl_PROC_empty,	 Splits) :-
 	int16_to_bytecode(272, I272Codes),
 	list__condense([I272Codes], Splits).
-bytecode_to_intlist(rl_PROC_and,	 Splits) :-
+bytecode_to_intlist(rl_PROC_one_reference(X0int32),	 Splits) :-
 	int16_to_bytecode(273, I273Codes),
-	list__condense([I273Codes], Splits).
-bytecode_to_intlist(rl_PROC_or,	 Splits) :-
+	int32_to_bytecode(X0int32, X0int32Codes),
+	list__condense([I273Codes,X0int32Codes], Splits).
+bytecode_to_intlist(rl_PROC_and,	 Splits) :-
 	int16_to_bytecode(274, I274Codes),
 	list__condense([I274Codes], Splits).
-bytecode_to_intlist(rl_PROC_not,	 Splits) :-
+bytecode_to_intlist(rl_PROC_or,	 Splits) :-
 	int16_to_bytecode(275, I275Codes),
 	list__condense([I275Codes], Splits).
-bytecode_to_intlist(rl_PROC_stream,	 Splits) :-
+bytecode_to_intlist(rl_PROC_not,	 Splits) :-
 	int16_to_bytecode(276, I276Codes),
 	list__condense([I276Codes], Splits).
-bytecode_to_intlist(rl_PROC_stream_end,	 Splits) :-
+bytecode_to_intlist(rl_PROC_stream,	 Splits) :-
 	int16_to_bytecode(277, I277Codes),
 	list__condense([I277Codes], Splits).
-bytecode_to_intlist(rl_PROC_stream_list_cons,	 Splits) :-
+bytecode_to_intlist(rl_PROC_stream_end,	 Splits) :-
 	int16_to_bytecode(278, I278Codes),
 	list__condense([I278Codes], Splits).
-bytecode_to_intlist(rl_PROC_stream_list_nil,	 Splits) :-
+bytecode_to_intlist(rl_PROC_stream_list_cons,	 Splits) :-
 	int16_to_bytecode(279, I279Codes),
 	list__condense([I279Codes], Splits).
-bytecode_to_intlist(rl_PROC_var(X0int32,X1int32),	 Splits) :-
+bytecode_to_intlist(rl_PROC_stream_list_nil,	 Splits) :-
 	int16_to_bytecode(280, I280Codes),
+	list__condense([I280Codes], Splits).
+bytecode_to_intlist(rl_PROC_var(X0int32,X1int32),	 Splits) :-
+	int16_to_bytecode(281, I281Codes),
 	int32_to_bytecode(X0int32, X0int32Codes),
 	int32_to_bytecode(X1int32, X1int32Codes),
-	list__condense([I280Codes,X0int32Codes,X1int32Codes], Splits).
+	list__condense([I281Codes,X0int32Codes,X1int32Codes], Splits).
 bytecode_to_intlist(rl_PROC_indexed_var(X0int32,X1int32,X2aString),	 Splits) :-
-	int16_to_bytecode(281, I281Codes),
+	int16_to_bytecode(282, I282Codes),
 	int32_to_bytecode(X0int32, X0int32Codes),
 	int32_to_bytecode(X1int32, X1int32Codes),
 	int32_to_bytecode(X2aString, X2aStringCodes),
-	list__condense([I281Codes,X0int32Codes,X1int32Codes,X2aStringCodes], Splits).
+	list__condense([I282Codes,X0int32Codes,X1int32Codes,X2aStringCodes], Splits).
 bytecode_to_intlist(rl_PROC_var_list_cons(X0int32,X1int32),	 Splits) :-
-	int16_to_bytecode(282, I282Codes),
+	int16_to_bytecode(283, I283Codes),
 	int32_to_bytecode(X0int32, X0int32Codes),
 	int32_to_bytecode(X1int32, X1int32Codes),
-	list__condense([I282Codes,X0int32Codes,X1int32Codes], Splits).
+	list__condense([I283Codes,X0int32Codes,X1int32Codes], Splits).
 bytecode_to_intlist(rl_PROC_var_list_nil,	 Splits) :-
-	int16_to_bytecode(283, I283Codes),
-	list__condense([I283Codes], Splits).
-bytecode_to_intlist(rl_PROC_expr(X0int32),	 Splits) :-
 	int16_to_bytecode(284, I284Codes),
-	int32_to_bytecode(X0int32, X0int32Codes),
-	list__condense([I284Codes,X0int32Codes], Splits).
-bytecode_to_intlist(rl_PROC_expr_frag(X0int32),	 Splits) :-
+	list__condense([I284Codes], Splits).
+bytecode_to_intlist(rl_PROC_expr(X0int32),	 Splits) :-
 	int16_to_bytecode(285, I285Codes),
 	int32_to_bytecode(X0int32, X0int32Codes),
 	list__condense([I285Codes,X0int32Codes], Splits).
-bytecode_to_intlist(rl_PROC_expr_end,	 Splits) :-
+bytecode_to_intlist(rl_PROC_expr_frag(X0int32),	 Splits) :-
 	int16_to_bytecode(286, I286Codes),
-	list__condense([I286Codes], Splits).
-bytecode_to_intlist(rl_PROC_expr_list_cons(X0int32),	 Splits) :-
+	int32_to_bytecode(X0int32, X0int32Codes),
+	list__condense([I286Codes,X0int32Codes], Splits).
+bytecode_to_intlist(rl_PROC_expr_end,	 Splits) :-
 	int16_to_bytecode(287, I287Codes),
+	list__condense([I287Codes], Splits).
+bytecode_to_intlist(rl_PROC_expr_list_cons(X0int32),	 Splits) :-
+	int16_to_bytecode(288, I288Codes),
 	int32_to_bytecode(X0int32, X0int32Codes),
-	list__condense([I287Codes,X0int32Codes], Splits).
+	list__condense([I288Codes,X0int32Codes], Splits).
 bytecode_to_intlist(rl_PROC_expr_list_nil,	 Splits) :-
-	int16_to_bytecode(288, I288Codes),
-	list__condense([I288Codes], Splits).
-bytecode_to_intlist(rl_PROC_bool_op_list_cons,	 Splits) :-
 	int16_to_bytecode(289, I289Codes),
 	list__condense([I289Codes], Splits).
-bytecode_to_intlist(rl_PROC_bool_op_list_nil,	 Splits) :-
+bytecode_to_intlist(rl_PROC_bool_op_list_cons,	 Splits) :-
 	int16_to_bytecode(290, I290Codes),
 	list__condense([I290Codes], Splits).
-bytecode_to_intlist(rl_PROC_int_list_cons(X0int32),	 Splits) :-
+bytecode_to_intlist(rl_PROC_bool_op_list_nil,	 Splits) :-
 	int16_to_bytecode(291, I291Codes),
+	list__condense([I291Codes], Splits).
+bytecode_to_intlist(rl_PROC_int_list_cons(X0int32),	 Splits) :-
+	int16_to_bytecode(292, I292Codes),
 	int32_to_bytecode(X0int32, X0int32Codes),
-	list__condense([I291Codes,X0int32Codes], Splits).
+	list__condense([I292Codes,X0int32Codes], Splits).
 bytecode_to_intlist(rl_PROC_int_list_nil,	 Splits) :-
-	int16_to_bytecode(292, I292Codes),
-	list__condense([I292Codes], Splits).
-bytecode_to_intlist(rl_PROC_ret,	 Splits) :-
 	int16_to_bytecode(293, I293Codes),
 	list__condense([I293Codes], Splits).
-bytecode_to_intlist(rl_PROC_join,	 Splits) :-
+bytecode_to_intlist(rl_PROC_ret,	 Splits) :-
 	int16_to_bytecode(294, I294Codes),
 	list__condense([I294Codes], Splits).
-bytecode_to_intlist(rl_PROC_join_nl,	 Splits) :-
+bytecode_to_intlist(rl_PROC_join,	 Splits) :-
 	int16_to_bytecode(295, I295Codes),
 	list__condense([I295Codes], Splits).
-bytecode_to_intlist(rl_PROC_join_sm,	 Splits) :-
+bytecode_to_intlist(rl_PROC_join_nl,	 Splits) :-
 	int16_to_bytecode(296, I296Codes),
 	list__condense([I296Codes], Splits).
-bytecode_to_intlist(rl_PROC_join_hj,	 Splits) :-
+bytecode_to_intlist(rl_PROC_join_sm,	 Splits) :-
 	int16_to_bytecode(297, I297Codes),
 	list__condense([I297Codes], Splits).
-bytecode_to_intlist(rl_PROC_join_index_simple,	 Splits) :-
+bytecode_to_intlist(rl_PROC_join_hj,	 Splits) :-
 	int16_to_bytecode(298, I298Codes),
 	list__condense([I298Codes], Splits).
-bytecode_to_intlist(rl_PROC_join_index_complex,	 Splits) :-
+bytecode_to_intlist(rl_PROC_join_index_simple,	 Splits) :-
 	int16_to_bytecode(299, I299Codes),
 	list__condense([I299Codes], Splits).
-bytecode_to_intlist(rl_PROC_join_cross,	 Splits) :-
+bytecode_to_intlist(rl_PROC_join_index_complex,	 Splits) :-
 	int16_to_bytecode(300, I300Codes),
 	list__condense([I300Codes], Splits).
-bytecode_to_intlist(rl_PROC_semijoin_nl,	 Splits) :-
+bytecode_to_intlist(rl_PROC_join_cross,	 Splits) :-
 	int16_to_bytecode(301, I301Codes),
 	list__condense([I301Codes], Splits).
-bytecode_to_intlist(rl_PROC_semijoin_sm,	 Splits) :-
+bytecode_to_intlist(rl_PROC_semijoin_nl,	 Splits) :-
 	int16_to_bytecode(302, I302Codes),
 	list__condense([I302Codes], Splits).
-bytecode_to_intlist(rl_PROC_semijoin_index,	 Splits) :-
+bytecode_to_intlist(rl_PROC_semijoin_sm,	 Splits) :-
 	int16_to_bytecode(303, I303Codes),
 	list__condense([I303Codes], Splits).
-bytecode_to_intlist(rl_PROC_subtract,	 Splits) :-
+bytecode_to_intlist(rl_PROC_semijoin_index,	 Splits) :-
 	int16_to_bytecode(304, I304Codes),
 	list__condense([I304Codes], Splits).
-bytecode_to_intlist(rl_PROC_subtract_nl,	 Splits) :-
+bytecode_to_intlist(rl_PROC_subtract,	 Splits) :-
 	int16_to_bytecode(305, I305Codes),
 	list__condense([I305Codes], Splits).
-bytecode_to_intlist(rl_PROC_subtract_sm,	 Splits) :-
+bytecode_to_intlist(rl_PROC_subtract_nl,	 Splits) :-
 	int16_to_bytecode(306, I306Codes),
 	list__condense([I306Codes], Splits).
-bytecode_to_intlist(rl_PROC_subtract_hj,	 Splits) :-
+bytecode_to_intlist(rl_PROC_subtract_sm,	 Splits) :-
 	int16_to_bytecode(307, I307Codes),
 	list__condense([I307Codes], Splits).
-bytecode_to_intlist(rl_PROC_subtract_index,	 Splits) :-
+bytecode_to_intlist(rl_PROC_subtract_hj,	 Splits) :-
 	int16_to_bytecode(308, I308Codes),
 	list__condense([I308Codes], Splits).
-bytecode_to_intlist(rl_PROC_subtract_cross,	 Splits) :-
+bytecode_to_intlist(rl_PROC_subtract_index,	 Splits) :-
 	int16_to_bytecode(309, I309Codes),
 	list__condense([I309Codes], Splits).
-bytecode_to_intlist(rl_PROC_difference,	 Splits) :-
+bytecode_to_intlist(rl_PROC_subtract_cross,	 Splits) :-
 	int16_to_bytecode(310, I310Codes),
 	list__condense([I310Codes], Splits).
-bytecode_to_intlist(rl_PROC_select,	 Splits) :-
+bytecode_to_intlist(rl_PROC_difference,	 Splits) :-
 	int16_to_bytecode(311, I311Codes),
 	list__condense([I311Codes], Splits).
-bytecode_to_intlist(rl_PROC_select_filter,	 Splits) :-
+bytecode_to_intlist(rl_PROC_select,	 Splits) :-
 	int16_to_bytecode(312, I312Codes),
 	list__condense([I312Codes], Splits).
-bytecode_to_intlist(rl_PROC_select_index,	 Splits) :-
+bytecode_to_intlist(rl_PROC_select_filter,	 Splits) :-
 	int16_to_bytecode(313, I313Codes),
 	list__condense([I313Codes], Splits).
-bytecode_to_intlist(rl_PROC_btree_scan,	 Splits) :-
+bytecode_to_intlist(rl_PROC_select_index,	 Splits) :-
 	int16_to_bytecode(314, I314Codes),
 	list__condense([I314Codes], Splits).
-bytecode_to_intlist(rl_PROC_project_tee,	 Splits) :-
+bytecode_to_intlist(rl_PROC_btree_scan,	 Splits) :-
 	int16_to_bytecode(315, I315Codes),
 	list__condense([I315Codes], Splits).
-bytecode_to_intlist(rl_PROC_sort(X0int32),	 Splits) :-
+bytecode_to_intlist(rl_PROC_project_tee,	 Splits) :-
 	int16_to_bytecode(316, I316Codes),
+	list__condense([I316Codes], Splits).
+bytecode_to_intlist(rl_PROC_sort(X0int32),	 Splits) :-
+	int16_to_bytecode(317, I317Codes),
 	int32_to_bytecode(X0int32, X0int32Codes),
-	list__condense([I316Codes,X0int32Codes], Splits).
+	list__condense([I317Codes,X0int32Codes], Splits).
 bytecode_to_intlist(rl_PROC_union,	 Splits) :-
-	int16_to_bytecode(317, I317Codes),
-	list__condense([I317Codes], Splits).
-bytecode_to_intlist(rl_PROC_union_sm,	 Splits) :-
 	int16_to_bytecode(318, I318Codes),
 	list__condense([I318Codes], Splits).
-bytecode_to_intlist(rl_PROC_uniondiff,	 Splits) :-
+bytecode_to_intlist(rl_PROC_union_sm,	 Splits) :-
 	int16_to_bytecode(319, I319Codes),
 	list__condense([I319Codes], Splits).
-bytecode_to_intlist(rl_PROC_uniondiff_sm,	 Splits) :-
+bytecode_to_intlist(rl_PROC_uniondiff,	 Splits) :-
 	int16_to_bytecode(320, I320Codes),
 	list__condense([I320Codes], Splits).
-bytecode_to_intlist(rl_PROC_uniondiff_btree,	 Splits) :-
+bytecode_to_intlist(rl_PROC_uniondiff_sm,	 Splits) :-
 	int16_to_bytecode(321, I321Codes),
 	list__condense([I321Codes], Splits).
-bytecode_to_intlist(rl_PROC_aggregate,	 Splits) :-
+bytecode_to_intlist(rl_PROC_uniondiff_btree,	 Splits) :-
 	int16_to_bytecode(322, I322Codes),
 	list__condense([I322Codes], Splits).
-bytecode_to_intlist(rl_PROC_aggregate_sm,	 Splits) :-
+bytecode_to_intlist(rl_PROC_aggregate,	 Splits) :-
 	int16_to_bytecode(323, I323Codes),
 	list__condense([I323Codes], Splits).
-bytecode_to_intlist(rl_PROC_insert_tuple_stream,	 Splits) :-
+bytecode_to_intlist(rl_PROC_aggregate_sm,	 Splits) :-
 	int16_to_bytecode(324, I324Codes),
 	list__condense([I324Codes], Splits).
-bytecode_to_intlist(rl_PROC_empty_stream(X0aString),	 Splits) :-
+bytecode_to_intlist(rl_PROC_insert_tuple_stream,	 Splits) :-
 	int16_to_bytecode(325, I325Codes),
+	list__condense([I325Codes], Splits).
+bytecode_to_intlist(rl_PROC_empty_stream(X0aString),	 Splits) :-
+	int16_to_bytecode(326, I326Codes),
 	int32_to_bytecode(X0aString, X0aStringCodes),
-	list__condense([I325Codes,X0aStringCodes], Splits).
+	list__condense([I326Codes,X0aStringCodes], Splits).
 bytecode_to_intlist(rl_PROC_hypothetical,	 Splits) :-
-	int16_to_bytecode(326, I326Codes),
-	list__condense([I326Codes], Splits).
-bytecode_to_intlist(rl_PROC_topdown,	 Splits) :-
 	int16_to_bytecode(327, I327Codes),
 	list__condense([I327Codes], Splits).
-bytecode_to_intlist(rl_PROC_last_bytecode,	 Splits) :-
+bytecode_to_intlist(rl_PROC_topdown,	 Splits) :-
 	int16_to_bytecode(328, I328Codes),
 	list__condense([I328Codes], Splits).
-bytecode_to_intlist(rl_HEAD_proc(X0aString,X1aString,X2aString,X3int32),	 Splits) :-
+bytecode_to_intlist(rl_PROC_last_bytecode,	 Splits) :-
 	int16_to_bytecode(329, I329Codes),
+	list__condense([I329Codes], Splits).
+bytecode_to_intlist(rl_HEAD_proc(X0aString,X1aString,X2aString,X3int32),	 Splits) :-
+	int16_to_bytecode(330, I330Codes),
 	int32_to_bytecode(X0aString, X0aStringCodes),
 	int32_to_bytecode(X1aString, X1aStringCodes),
 	int32_to_bytecode(X2aString, X2aStringCodes),
 	int32_to_bytecode(X3int32, X3int32Codes),
-	list__condense([I329Codes,X0aStringCodes,X1aStringCodes,X2aStringCodes,X3int32Codes], Splits).
+	list__condense([I330Codes,X0aStringCodes,X1aStringCodes,X2aStringCodes,X3int32Codes], Splits).
 bytecode_to_intlist(rl_HEAD_proc_end,	 Splits) :-
-	int16_to_bytecode(330, I330Codes),
-	list__condense([I330Codes], Splits).
-bytecode_to_intlist(rl_HEAD_const_int(X0int32,X1aInt),	 Splits) :-
 	int16_to_bytecode(331, I331Codes),
+	list__condense([I331Codes], Splits).
+bytecode_to_intlist(rl_HEAD_const_int(X0int32,X1aInt),	 Splits) :-
+	int16_to_bytecode(332, I332Codes),
 	int32_to_bytecode(X0int32, X0int32Codes),
 	aInt_to_bytecode(X1aInt, X1aIntCodes),
-	list__condense([I331Codes,X0int32Codes,X1aIntCodes], Splits).
+	list__condense([I332Codes,X0int32Codes,X1aIntCodes], Splits).
 bytecode_to_intlist(rl_HEAD_const_flt(X0int32,X1aDouble),	 Splits) :-
-	int16_to_bytecode(332, I332Codes),
+	int16_to_bytecode(333, I333Codes),
 	int32_to_bytecode(X0int32, X0int32Codes),
 	aDouble_to_bytecode(X1aDouble, X1aDoubleCodes),
-	list__condense([I332Codes,X0int32Codes,X1aDoubleCodes], Splits).
+	list__condense([I333Codes,X0int32Codes,X1aDoubleCodes], Splits).
 bytecode_to_intlist(rl_HEAD_const_str(X0int32,X1aString),	 Splits) :-
-	int16_to_bytecode(333, I333Codes),
+	int16_to_bytecode(334, I334Codes),
 	int32_to_bytecode(X0int32, X0int32Codes),
 	aString_to_bytecode(X1aString, X1aStringCodes),
-	list__condense([I333Codes,X0int32Codes,X1aStringCodes], Splits).
+	list__condense([I334Codes,X0int32Codes,X1aStringCodes], Splits).
 bytecode_to_intlist(rl_HEAD_var_int(X0int32),	 Splits) :-
-	int16_to_bytecode(334, I334Codes),
-	int32_to_bytecode(X0int32, X0int32Codes),
-	list__condense([I334Codes,X0int32Codes], Splits).
-bytecode_to_intlist(rl_HEAD_var_flt(X0int32),	 Splits) :-
 	int16_to_bytecode(335, I335Codes),
 	int32_to_bytecode(X0int32, X0int32Codes),
 	list__condense([I335Codes,X0int32Codes], Splits).
-bytecode_to_intlist(rl_HEAD_var_str(X0int32),	 Splits) :-
+bytecode_to_intlist(rl_HEAD_var_flt(X0int32),	 Splits) :-
 	int16_to_bytecode(336, I336Codes),
 	int32_to_bytecode(X0int32, X0int32Codes),
 	list__condense([I336Codes,X0int32Codes], Splits).
-bytecode_to_intlist(rl_HEAD_var_term(X0int32),	 Splits) :-
+bytecode_to_intlist(rl_HEAD_var_str(X0int32),	 Splits) :-
 	int16_to_bytecode(337, I337Codes),
 	int32_to_bytecode(X0int32, X0int32Codes),
 	list__condense([I337Codes,X0int32Codes], Splits).
-bytecode_to_intlist(rl_HEAD_var_stream(X0int32),	 Splits) :-
+bytecode_to_intlist(rl_HEAD_var_term(X0int32),	 Splits) :-
 	int16_to_bytecode(338, I338Codes),
 	int32_to_bytecode(X0int32, X0int32Codes),
 	list__condense([I338Codes,X0int32Codes], Splits).
-bytecode_to_intlist(rl_HEAD_define_rule(X0int32,X1aString,X2aString),	 Splits) :-
+bytecode_to_intlist(rl_HEAD_var_stream(X0int32),	 Splits) :-
 	int16_to_bytecode(339, I339Codes),
 	int32_to_bytecode(X0int32, X0int32Codes),
+	list__condense([I339Codes,X0int32Codes], Splits).
+bytecode_to_intlist(rl_HEAD_define_rule(X0int32,X1aString,X2aString),	 Splits) :-
+	int16_to_bytecode(340, I340Codes),
+	int32_to_bytecode(X0int32, X0int32Codes),
 	int32_to_bytecode(X1aString, X1aStringCodes),
 	int32_to_bytecode(X2aString, X2aStringCodes),
-	list__condense([I339Codes,X0int32Codes,X1aStringCodes,X2aStringCodes], Splits).
+	list__condense([I340Codes,X0int32Codes,X1aStringCodes,X2aStringCodes], Splits).
 bytecode_to_intlist(rl_HEAD_last_bytecode,	 Splits) :-
-	int16_to_bytecode(340, I340Codes),
-	list__condense([I340Codes], Splits).
+	int16_to_bytecode(341, I341Codes),
+	list__condense([I341Codes], Splits).
 
 int32_to_bytecode(X, List) :-
 	int32_to_byte_list(X, List).
@@ -1671,4 +1676,4 @@
 	int_to_byte_list(X, List).
 
 
-rl_code__version(1, 20).
+rl_code__version(1, 21).
Index: compiler/rl_opt.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/rl_opt.m,v
retrieving revision 1.1.2.2
diff -u -b -r1.1.2.2 rl_opt.m
--- rl_opt.m	1999/06/03 01:39:11	1.1.2.2
+++ rl_opt.m	1999/06/15 07:53:23
@@ -83,7 +83,20 @@
 		maybe_write_string(VeryVerbose, "..."),
 		maybe_flush_output(VeryVerbose),
 
-		{ Flags0 = [merge_output_projections] },
+		% The `merge_output_projections' flag enables
+		% the merging of multiple projections of a single
+		% relation into a single instruction, reducing the
+		% number of passes over the input relation.
+		% It is disabled because for small relations
+		% it significantly worsens performance.
+		% The problem is that it is much faster to make
+		% multiple passes over the input relation than
+		% to materialise all the outputs of the projections.
+		% If this pass were run again after stream detection,
+		% the merging could be done if all outputs are materialised
+		% anyway.
+		%{ Flags0 = [merge_output_projections] },
+		{ Flags0 = [] },
 		{ OptIndex = yes ->
 			Flags = [add_uniondiff | Flags0]
 		;
Index: compiler/notes/compiler_design.html
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/notes/compiler_design.html,v
retrieving revision 1.6.2.8
diff -u -b -r1.6.2.8 compiler_design.html
--- compiler_design.html	1999/05/05 01:26:42	1.6.2.8
+++ compiler_design.html	1999/06/15 07:56:18
@@ -460,6 +460,14 @@
   specialized versions without them (unused_args.m); type_infos are
   often unused.
 
+<li> attempt to introduce accumulators (accumulator.m).  This optimizes
+  procedures whose tail consists of independent associative computations
+  or independant chains of commutative computations into a tail
+  recursive form by the introduction of accumulators.  If lco is turned
+  on it can also transform some procedures so that only construction
+  unifications are after the recursive call.  This pass must come before
+  lco.
+
 <li> elimination of dead procedures (dead_proc_elim.m). Inlining, higher-order
   specialization and the elimination of unused args can make procedures dead
   even the user doesn't, and automatically constructed unification and
@@ -919,6 +927,6 @@
 <hr>
 <!-------------------------->
 
-Last update was $Date: 1999/05/05 01:26:42 $ by $Author: stayl $@cs.mu.oz.au. <br>
+Last update was $Date: 1999/06/15 07:10:00 $ by $Author: petdr $@cs.mu.oz.au. <br>
 </body>
 </html>

----
 +----------------------------------------------------------------------+
 | Peter Ross      M Sci/Eng Melbourne Uni                              |
 | petdr at cs.mu.oz.au  WWW: www.cs.mu.oz.au/~petdr/ ph: +61 3 9344 9158  |
 +----------------------------------------------------------------------+
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list