[m-rev.] [reuse] diff: make the strategy settable by options

Peter Ross peter.ross at miscrit.be
Tue Mar 13 23:11:46 AEDT 2001


Hi,


===================================================================


Estimated hours taken: 2
Branches: reuse

Use options to choose which strategy structure reuse chooses.

compiler/options.m:
    Add the structure_reuse_constraint, structure_reuse_constraint_arg,
    and structure_reuse_selection options.

compiler/sr_choice.m:
compiler/sr_direct.m:
    Parse these options.


Index: options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/options.m,v
retrieving revision 1.288.2.8
diff -u -r1.288.2.8 options.m
--- options.m	2001/03/05 12:06:03	1.288.2.8
+++ options.m	2001/03/13 12:04:21
@@ -357,6 +357,9 @@
 		;	termination_norm
 		;	termination_error_limit
 		;	termination_path_limit
+		;	structure_reuse_constraint
+		;	structure_reuse_constraint_arg
+		;	structure_reuse_selection
 	%	- HLDS->LLDS
 		;	smart_indexing
 		;	  dense_switch_req_density
@@ -703,7 +706,11 @@
 	termination_norm	-	string("total"),
 	termination_error_limit	-	int(3),
 	termination_path_limit	-	int(256),
-	split_c_files		-	bool(no)
+	split_c_files		-	bool(no),
+
+	structure_reuse_constraint -	string("within_n_cells"),
+	structure_reuse_constraint_arg - int(0),
+	structure_reuse_selection -	string("lifo")
 ]).
 option_defaults_2(optimization_option, [
 		% Optimization options
@@ -1165,6 +1172,12 @@
 long_option("check-termination",	check_termination).
 long_option("check-term",		check_termination).
 long_option("chk-term",			check_termination).
+long_option("sr-constraint",		structure_reuse_constraint).
+long_option("structure-reuse-constraint",structure_reuse_constraint).
+long_option("sr-constraint-arg",	structure_reuse_constraint_arg).
+long_option("structure-reuse-constraint-arg",structure_reuse_constraint_arg).
+long_option("sr-selection",		structure_reuse_selection).
+long_option("structure-reuse-selection",structure_reuse_selection).
 long_option("verbose-check-termination",verbose_check_termination).
 long_option("verb-check-term",		verbose_check_termination).
 long_option("verb-chk-term",		verbose_check_termination).
@@ -1887,6 +1900,15 @@
 		"--infer-structure-reuse",
 		"\tAnnotate the program point with information about which",
 		"\tdatastructures can be reused and where they can be reused.",
+
+		"--structure-reuse-constraint",
+		"\tConstraint on the set of cells that we consider available",
+		"\tfor reuse.  Currently within_n_cells_difference(N) or",
+		"\tsame_cons_id.",
+
+		"--structure-reuse-selection",
+		"\tStrategy to decide which of the possible cells available",
+		"\tfor reuse is reused.  Currently lifo or random.",
 
 		"--no-infer-det, --no-infer-determinism",
 		"\tIf there is no determinism declaration for a procedure,",
Index: sr_choice.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/sr_choice.m,v
retrieving revision 1.1.2.14
diff -u -r1.1.2.14 sr_choice.m
--- sr_choice.m	2001/03/12 20:24:44	1.1.2.14
+++ sr_choice.m	2001/03/13 12:04:25
@@ -17,8 +17,8 @@
 :- module sr_choice.
 :- interface.
 
-:- import_module hlds_goal, sr_data.
-:- import_module list, std_util.
+:- import_module hlds_goal, hlds_module, sr_data.
+:- import_module io, list, std_util.
 
 :- type strategy
 	--->	strategy(
@@ -43,14 +43,18 @@
 
 :- pred sr_choice__process_goal(strategy::in, hlds_goal::in, hlds_goal::out,
 		maybe(list(reuse_condition))::out) is det.
+:- pred get_strategy(strategy::out, module_info::in, module_info::out,
+		io__state::di, io__state::uo) is det.
 
+
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
 :- implementation.
 
 :- import_module hlds_data, prog_data.
-:- import_module assoc_list, bool, int, multi_map, require, set.
+:- import_module assoc_list, bool, globals, int. 
+:- import_module multi_map, options, require, set.
 
 process_goal(Strategy, Goal0, Goal, MaybeReuseConditions) :-
 	Strategy = strategy(Constraint, SelectionRule),
@@ -550,5 +554,36 @@
 select_reuses_unification(_Selection, Unif, GoalInfo, GoalInfo) -->
 	{ Unif = complicated_unify(_, _, _) }.
 
-%-----------------------------------------------------------------------------%
-%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------% %-----------------------------------------------------------------------------%
+
+get_strategy(Strategy, ModuleInfo0, ModuleInfo) -->
+	io_lookup_string_option(structure_reuse_constraint, ConstraintStr),
+	( { ConstraintStr = "same_cons_id" } ->
+		{ Constraint = same_cons_id },
+		{ ModuleInfo1 = ModuleInfo0 }
+	; { ConstraintStr = "within_n_cells_difference" } ->
+		io_lookup_int_option(structure_reuse_constraint_arg, NCells),
+		{ Constraint = within_n_cells_difference(NCells) },
+		{ ModuleInfo1 = ModuleInfo0 }
+	;
+		{ Constraint = same_cons_id },
+		io__write_string("error: Invalid argument to --structure-reuse-constraint.\n"),
+		io__set_exit_status(1),
+		{ module_info_incr_errors(ModuleInfo0, ModuleInfo1) }
+	),
+	io_lookup_string_option(structure_reuse_selection, SelectionStr),
+	( { SelectionStr = "lifo" } ->
+		{ Selection = lifo },
+		{ ModuleInfo = ModuleInfo1 }
+	; { SelectionStr = "random" } ->
+		{ Selection = random },
+		{ ModuleInfo = ModuleInfo1 }
+	; 
+		{ Selection = lifo },
+		io__write_string("error: Invalid argument to --structure-reuse-selection.\n"),
+		io__set_exit_status(1),
+		{ module_info_incr_errors(ModuleInfo1, ModuleInfo) }
+	),
+	{ Strategy = strategy(Constraint, Selection) }.
+
+%-----------------------------------------------------------------------------% %-----------------------------------------------------------------------------%
Index: sr_direct.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/sr_direct.m,v
retrieving revision 1.1.2.10
diff -u -r1.1.2.10 sr_direct.m
--- sr_direct.m	2000/10/15 17:27:59	1.1.2.10
+++ sr_direct.m	2001/03/13 12:04:25
@@ -63,7 +63,8 @@
 		% Select which cells will be reused and which can be
 		% compile time garbage collected.
 	maybe_write_string(VeryVerbose, "%\tchoice analysis..."),
-	{ sr_choice__process_goal(strategy(same_cons_id, random),
+	sr_choice__get_strategy(Strategy, ModuleInfo0, ModuleInfo),
+	{ sr_choice__process_goal(Strategy,
 			Goal1, Goal, MaybeReuseConditions) },
 	(
 		{ VeryVerbose = yes } 
@@ -88,6 +89,5 @@
 		
 	{ proc_info_set_reuse_information( ProcInfo2, MaybeReuseConditions, 
 			ProcInfo3 ) },
-	{ proc_info_set_goal( ProcInfo3, Goal, ProcInfo ) },
-	{ ModuleInfo = ModuleInfo0 }.
+	{ proc_info_set_goal( ProcInfo3, Goal, ProcInfo ) }.
 

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