[m-dev.] for review: dependency restructuring change #3

Fergus Henderson fjh at cs.mu.OZ.AU
Sat Jul 10 18:15:15 AEST 1999


Estimated hours taken: 4

Some more changes to minimize the complexity of the intermodule dependencies. 
In particular, ensure that hlds_module.m does not need to import llds.m.

compiler/hlds_module.m:
compiler/llds.m:
	Move the definition of the c_interface_info type (and the types
	used for all its fields) from llds.m into hlds_module.m, since
	this type contains high-level information about the user-level
	C interface stuff that is not directly related to the LLDS and
	is needed by other back-ends.

compiler/hlds_module.m:
compiler/llds.m:
compiler/mercury_compile.m:
compiler/code_gen.m:
compiler/stack_layout.m:
compiler/table_gen.m:
	Move the `global_data' type from hlds_module.m into llds.m,
	since this type contains low-level stuff that is dependent on
	the LLDS.  Delete the `global_data' field of the module_info,
	instead passing it around as a separate argument where needed.
	Move the code for inserting llds__tabling_pointer_vars into the
	global_data from table_gen.m to code_gen.m, since this is
	dependent on the LLDS and table_gen.m should be a pure
	HLDS->HLDS transformation, so that it can work with other
	back-ends.

compiler/continuation_info.m:
	Update some comments which this change makes obsolete.

compiler/optimize.m:
	Delete the import of module hlds_module, since it is no longer
	needed.

Workspace: /home/mercury0/fjh/mercury-other
Index: compiler/code_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/code_gen.m,v
retrieving revision 1.64
diff -u -r1.64 code_gen.m
--- code_gen.m	1999/04/30 08:23:42	1.64
+++ code_gen.m	1999/07/09 08:22:37
@@ -37,7 +37,8 @@
 		% Translate a HLDS module to LLDS.
 
 :- pred generate_code(module_info::in, module_info::out,
-	list(c_procedure)::out, io__state::di, io__state::uo) is det.
+	global_data::in, global_data::out, list(c_procedure)::out,
+	io__state::di, io__state::uo) is det.
 
 		% Translate a HLDS procedure to LLDS, threading through
 		% the data structure that records information about layout
@@ -70,22 +71,25 @@
 
 %---------------------------------------------------------------------------%
 
-generate_code(ModuleInfo0, ModuleInfo, Procedures) -->
+generate_code(ModuleInfo0, ModuleInfo, GlobalData0, GlobalData, Procedures) -->
 		% get a list of all the predicate ids
 		% for which we are going to generate code.
 	{ module_info_predids(ModuleInfo0, PredIds) },
 		% now generate the code for each predicate
-	generate_pred_list_code(ModuleInfo0, ModuleInfo, PredIds, Procedures).
+	generate_pred_list_code(ModuleInfo0, ModuleInfo,
+		GlobalData0, GlobalData, PredIds, Procedures).
 
 	% Translate a list of HLDS predicates to LLDS.
 
 :- pred generate_pred_list_code(module_info::in, module_info::out,
+	global_data::in, global_data::out,
 	list(pred_id)::in, list(c_procedure)::out,
 	io__state::di, io__state::uo) is det.
 
-generate_pred_list_code(ModuleInfo, ModuleInfo, [], []) --> [].
-generate_pred_list_code(ModuleInfo0, ModuleInfo, [PredId | PredIds],
-				Predicates) -->
+generate_pred_list_code(ModuleInfo, ModuleInfo, GlobalData, GlobalData,
+		[], []) --> [].
+generate_pred_list_code(ModuleInfo0, ModuleInfo, GlobalData0, GlobalData,
+		[PredId | PredIds], Predicates) -->
 	{ module_info_preds(ModuleInfo0, PredInfos) },
 		% get the pred_info structure for this predicate
 	{ map__lookup(PredInfos, PredId, PredInfo) },
@@ -98,22 +102,27 @@
 		}
 	->
 		{ Predicates0 = [] },
-		{ ModuleInfo1 = ModuleInfo0 } 
+		{ ModuleInfo1 = ModuleInfo0 },
+		{ GlobalData1 = GlobalData0 }
 	;
-		generate_pred_code(ModuleInfo0, ModuleInfo1, PredId,
-					PredInfo, ProcIds, Predicates0) 
+		generate_pred_code(ModuleInfo0, ModuleInfo1,
+				GlobalData0, GlobalData1,
+				PredId, PredInfo, ProcIds, Predicates0) 
 	),
 	{ list__append(Predicates0, Predicates1, Predicates) },
 		% and generate the code for the rest of the predicates
-	generate_pred_list_code(ModuleInfo1, ModuleInfo, PredIds, Predicates1).
+	generate_pred_list_code(ModuleInfo1, ModuleInfo,
+		GlobalData1, GlobalData, PredIds, Predicates1).
 
 	% Translate a HLDS predicate to LLDS.
 
 :- pred generate_pred_code(module_info::in, module_info::out,
+	global_data::in, global_data::out,
 	pred_id::in, pred_info::in, list(proc_id)::in, list(c_procedure)::out,
 	io__state::di, io__state::uo) is det.
 
-generate_pred_code(ModuleInfo0, ModuleInfo, PredId, PredInfo, ProcIds, Code) -->
+generate_pred_code(ModuleInfo0, ModuleInfo, GlobalData0, GlobalData,
+		PredId, PredInfo, ProcIds, Code) -->
 	globals__io_lookup_bool_option(very_verbose, VeryVerbose),
 	( { VeryVerbose = yes } ->
 		io__write_string("% Generating code for "),
@@ -124,15 +133,12 @@
 	;
 		[]
 	),
-	{ module_info_get_global_data(ModuleInfo0, GlobalData0) },
 	{ module_info_get_cell_count(ModuleInfo0, CellCount0) },
 	globals__io_get_globals(Globals),
 	{ generate_proc_list_code(ProcIds, PredId, PredInfo, ModuleInfo0,
 		Globals, GlobalData0, GlobalData, CellCount0, CellCount,
 		[], Code) },
-	{ module_info_set_cell_count(ModuleInfo0, CellCount, ModuleInfo1) },
-	{ module_info_set_global_data(ModuleInfo1, GlobalData, 
-		ModuleInfo) }.
+	{ module_info_set_cell_count(ModuleInfo0, CellCount, ModuleInfo) }.
 
 	% Translate all the procedures of a HLDS predicate to LLDS.
 
@@ -243,12 +249,34 @@
 	),
 	code_info__get_non_common_static_data(NonCommonStatics, CodeInfo, _),
 	global_data_add_new_non_common_static_datas(GlobalData1,
-		NonCommonStatics, GlobalData),
+		NonCommonStatics, GlobalData2),
+	maybe_add_tabling_pointer_var(ModuleInfo, PredId, ProcId, ProcInfo,
+		GlobalData2, GlobalData),
 
-	predicate_name(ModuleInfo, PredId, Name),
-	predicate_arity(ModuleInfo, PredId, Arity),
+	pred_info_name(PredInfo, Name),
+	pred_info_arity(PredInfo, Arity),
 		% Construct a c_procedure structure with all the information.
 	Proc = c_procedure(Name, Arity, proc(PredId, ProcId), Instructions).
+
+:- pred maybe_add_tabling_pointer_var(module_info, pred_id, proc_id, proc_info,
+		global_data, global_data).
+:- mode maybe_add_tabling_pointer_var(in, in, in, in, in, out) is det.
+
+maybe_add_tabling_pointer_var(ModuleInfo, PredId, ProcId, ProcInfo,
+		GlobalData0, GlobalData) :-
+	proc_info_eval_method(ProcInfo, EvalMethod),
+	(
+		EvalMethod \= eval_normal
+	->
+		code_util__make_proc_label(ModuleInfo, PredId, ProcId,
+			ProcLabel),
+		module_info_name(ModuleInfo, ModuleName),
+		Var = tabling_pointer_var(ModuleName, ProcLabel),
+		global_data_add_new_proc_var(GlobalData0,
+			proc(PredId, ProcId), Var, GlobalData)
+	;
+		GlobalData = GlobalData0
+	).
 
 %---------------------------------------------------------------------------%
 %---------------------------------------------------------------------------%
Index: compiler/continuation_info.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/continuation_info.m,v
retrieving revision 1.22
diff -u -r1.22 continuation_info.m
--- continuation_info.m	1999/07/08 05:08:50	1.22
+++ continuation_info.m	1999/07/09 07:35:12
@@ -31,14 +31,13 @@
 %	  all the static information about the procedure (some of which
 %	  is available only after code generation), together with the
 %	  info about internal labels accumulated in the code generator state,
-%	  in the global_data structure (which is part of HLDS).
+%	  in the global_data structure.
 %
 % 	4 If agc_stack_layouts is set, we make a pass over the
 % 	  optimized code recorded in the final LLDS instructions.
 %	  In this pass, we collect information from call instructions
 %	  about the internal labels to which calls can return.
-%	  This info will also go straight into the global_data
-%	  in the HLDS.
+%	  This info will also go straight into the global_data.
 %
 % This module defines the data structures used by all passes. It also
 % implements the whole of pass 4, and various fractions of the other passes.
Index: compiler/hlds_module.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_module.m,v
retrieving revision 1.45
diff -u -r1.45 hlds_module.m
--- hlds_module.m	1999/07/09 01:15:26	1.45
+++ hlds_module.m	1999/07/10 07:24:34
@@ -12,7 +12,6 @@
 %	module_info
 %	dependency_info
 %	predicate_table
-%	global_data
 %
 % There is a separate interface section for each of these.
 
@@ -23,7 +22,7 @@
 :- interface.
 
 :- import_module hlds_pred, hlds_data, prog_data, unify_proc, special_pred.
-:- import_module globals, llds, continuation_info.
+:- import_module globals, llds.
 :- import_module relation, map, std_util, list, set, multi_map.
 
 :- implementation.
@@ -148,12 +147,13 @@
 	module_info).
 :- mode module_info_set_special_pred_map(in, in, out) is det.
 
-:- pred module_info_get_global_data(module_info, global_data).
-:- mode module_info_get_global_data(in, out) is det.
+% This junk field is unused... feel free to replace it.
 
-:- pred module_info_set_global_data(module_info, global_data, 
-	module_info).
-:- mode module_info_set_global_data(in, in, out) is det.
+:- pred module_info_get_junk(module_info, unit).
+:- mode module_info_get_junk(in, out) is det.
+
+:- pred module_info_set_junk(module_info, unit, module_info).
+:- mode module_info_set_junk(in, in, out) is det.
 
 :- pred module_info_types(module_info, type_table).
 :- mode module_info_types(in, out) is det.
@@ -554,7 +554,7 @@
 			predicate_table,
 			proc_requests,
 			special_pred_map,
-			global_data,
+			unit,		% junk (unused)
 			type_table,
 			inst_table,
 			mode_table,
@@ -614,7 +614,7 @@
 	map__init(Types),
 	inst_table_init(Insts),
 	mode_table_init(Modes),
-	global_data_init(GlobalData),
+	Junk = unit,
 	map__init(Ctors),
 	set__init(StratPreds),
 	map__init(UnusedArgInfo),
@@ -637,7 +637,7 @@
 		[], [], StratPreds, UnusedArgInfo, 0, ModuleNames,
 		no_aditi_compilation, TypeSpecInfo),
 	ModuleInfo = module(ModuleSubInfo, PredicateTable, Requests,
-		UnifyPredMap, GlobalData, Types, Insts, Modes, Ctors,
+		UnifyPredMap, Junk, Types, Insts, Modes, Ctors,
 		ClassTable, SuperClassTable, InstanceTable, AssertionTable, 0).
 
 %-----------------------------------------------------------------------------%
@@ -801,7 +801,7 @@
 % B			predicate_table,
 % C			proc_requests,
 % D			special_pred_map,
-% E			global_data,
+% E			unit,		% junk (unused)
 % F			type_table,
 % G			inst_table,
 % H			mode_table,
@@ -832,7 +832,7 @@
 module_info_get_special_pred_map(MI0, D) :-
 	MI0 = module(_, _, _, D, _, _, _, _, _, _, _, _, _, _).
 
-module_info_get_global_data(MI0, E) :-
+module_info_get_junk(MI0, E) :-
 	MI0 = module(_, _, _, _, E, _, _, _, _, _, _, _, _, _).
 
 module_info_types(MI0, F) :-
@@ -882,7 +882,7 @@
 	MI0 = module(A, B, C, _, E, F, G, H, I, J, K, L, M, N),
 	MI  = module(A, B, C, D, E, F, G, H, I, J, K, L, M, N).
 
-module_info_set_global_data(MI0, E, MI) :-
+module_info_set_junk(MI0, E, MI) :-
 	MI0 = module(A, B, C, D, _, F, G, H, I, J, K, L, M, N),
 	MI  = module(A, B, C, D, E, F, G, H, I, J, K, L, M, N).
 
@@ -1207,8 +1207,6 @@
 	predicate_table_optimize(Preds0, Preds),
 	module_info_set_predicate_table(ModuleInfo0, Preds, ModuleInfo3),
 
-	% XXX Might want to optimize global_data here.
-
 	module_info_types(ModuleInfo3, Types0),
 	map__optimize(Types0, Types),
 	module_info_set_types(ModuleInfo3, Types, ModuleInfo4),
@@ -2136,150 +2134,5 @@
 	module_info_preds(ModuleInfo, Preds),
 	map__lookup(Preds, PredId, PredInfo),
 	pred_info_arity(PredInfo, Arity).
-
-%-----------------------------------------------------------------------------%
-%-----------------------------------------------------------------------------%
-
-:- interface.
-
-:- type global_data.
-
-:- pred global_data_init(global_data::out) is det.
-
-:- pred global_data_add_new_proc_var(global_data::in,
-	pred_proc_id::in, comp_gen_c_var::in, global_data::out) is det.
-
-:- pred global_data_add_new_proc_layout(global_data::in,
-	pred_proc_id::in, proc_layout_info::in, global_data::out) is det.
-
-:- pred global_data_update_proc_layout(global_data::in,
-	pred_proc_id::in, proc_layout_info::in, global_data::out) is det.
-
-:- pred global_data_add_new_non_common_static_datas(global_data::in,
-	list(comp_gen_c_data)::in, global_data::out) is det.
-
-:- pred global_data_maybe_get_proc_layout(global_data::in, pred_proc_id::in,
-	proc_layout_info::out) is semidet.
-
-:- pred global_data_get_proc_layout(global_data::in, pred_proc_id::in,
-	proc_layout_info::out) is det.
-
-:- pred global_data_get_all_proc_vars(global_data::in,
-	list(comp_gen_c_var)::out) is det.
-
-:- pred global_data_get_all_proc_layouts(global_data::in,
-	list(proc_layout_info)::out) is det.
-
-:- pred global_data_get_all_non_common_static_data(global_data::in,
-	list(comp_gen_c_data)::out) is det.
-
-%-----------------------------------------------------------------------------%
-
-:- implementation.
-
-:- type proc_var_map	==	map(pred_proc_id, comp_gen_c_var).
-:- type proc_layout_map	==	map(pred_proc_id, proc_layout_info).
-
-:- type global_data
-	--->	global_data(
-			proc_var_map,		% Information about the global
-						% variables defined by each
-						% procedure.
-			proc_layout_map,	% Information about the
-						% layout structures defined
-						% by each procedure.
-			list(comp_gen_c_data)	% The list of global data
-						% structures that do not need
-						% to be checked by llds_common,
-						% because their construction
-						% ensures no overlaps.
-		).
-
-global_data_init(global_data(EmptyDataMap, EmptyLayoutMap, [])) :-
-	map__init(EmptyDataMap),
-	map__init(EmptyLayoutMap).
-
-global_data_add_new_proc_var(GlobalData0, PredProcId, ProcVar,
-		GlobalData) :-
-	global_data_get_proc_var_map(GlobalData0, ProcVarMap0),
-	map__det_insert(ProcVarMap0, PredProcId, ProcVar, ProcVarMap),
-	global_data_set_proc_var_map(GlobalData0, ProcVarMap,
-		GlobalData).
-
-global_data_add_new_proc_layout(GlobalData0, PredProcId, ProcLayout,
-		GlobalData) :-
-	global_data_get_proc_layout_map(GlobalData0, ProcLayoutMap0),
-	map__det_insert(ProcLayoutMap0, PredProcId, ProcLayout, ProcLayoutMap),
-	global_data_set_proc_layout_map(GlobalData0, ProcLayoutMap,
-		GlobalData).
-
-global_data_update_proc_layout(GlobalData0, PredProcId, ProcLayout,
-		GlobalData) :-
-	global_data_get_proc_layout_map(GlobalData0, ProcLayoutMap0),
-	map__det_update(ProcLayoutMap0, PredProcId, ProcLayout, ProcLayoutMap),
-	global_data_set_proc_layout_map(GlobalData0, ProcLayoutMap,
-		GlobalData).
-
-global_data_add_new_non_common_static_datas(GlobalData0, NewNonCommonStatics,
-		GlobalData) :-
-	global_data_get_non_common_static_data(GlobalData0, NonCommonStatics0),
-	list__append(NewNonCommonStatics, NonCommonStatics0, NonCommonStatics),
-	global_data_set_non_common_static_data(GlobalData0, NonCommonStatics,
-		GlobalData).
-
-global_data_maybe_get_proc_layout(GlobalData0, PredProcId, ProcLayout) :-
-	global_data_get_proc_layout_map(GlobalData0, ProcLayoutMap),
-	map__search(ProcLayoutMap, PredProcId, ProcLayout).
-
-global_data_get_proc_layout(GlobalData0, PredProcId, ProcLayout) :-
-	global_data_get_proc_layout_map(GlobalData0, ProcLayoutMap),
-	map__lookup(ProcLayoutMap, PredProcId, ProcLayout).
-
-global_data_get_all_proc_vars(GlobalData, ProcVars) :-
-	global_data_get_proc_var_map(GlobalData, ProcVarMap),
-	map__values(ProcVarMap, ProcVars).
-
-global_data_get_all_proc_layouts(GlobalData, ProcLayouts) :-
-	global_data_get_proc_layout_map(GlobalData, ProcLayoutMap),
-	map__values(ProcLayoutMap, ProcLayouts).
-
-global_data_get_all_non_common_static_data(GlobalData, NonCommonStatics) :-
-	global_data_get_non_common_static_data(GlobalData, NonCommonStatics).
-
-%-----------------------------------------------------------------------------%
-
-:- pred global_data_get_proc_var_map(global_data::in, proc_var_map::out)
-	is det.
-:- pred global_data_get_proc_layout_map(global_data::in, proc_layout_map::out)
-	is det.
-:- pred global_data_get_non_common_static_data(global_data::in,
-	list(comp_gen_c_data)::out) is det.
-:- pred global_data_set_proc_var_map(global_data::in, proc_var_map::in,
-	global_data::out) is det.
-:- pred global_data_set_proc_layout_map(global_data::in, proc_layout_map::in,
-	global_data::out) is det.
-:- pred global_data_set_non_common_static_data(global_data::in,
-	list(comp_gen_c_data)::in, global_data::out) is det.
-
-global_data_get_proc_var_map(GD, A) :-
-	GD = global_data(A, _, _).
-
-global_data_get_proc_layout_map(GD, B) :-
-	GD = global_data(_, B, _).
-
-global_data_get_non_common_static_data(GD, C) :-
-	GD = global_data(_, _, C).
-
-global_data_set_proc_var_map(GD0, A, GD) :-
-	GD0 = global_data(_, B, C),
-	GD  = global_data(A, B, C).
-
-global_data_set_proc_layout_map(GD0, B, GD) :-
-	GD0 = global_data(A, _, C),
-	GD  = global_data(A, B, C).
-
-global_data_set_non_common_static_data(GD0, C, GD) :-
-	GD0 = global_data(A, B, _),
-	GD  = global_data(A, B, C).
 
 %-----------------------------------------------------------------------------%
Index: compiler/llds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/llds.m,v
retrieving revision 1.242
diff -u -r1.242 llds.m
--- llds.m	1999/07/10 07:19:51	1.242
+++ llds.m	1999/07/10 07:20:26
@@ -28,6 +28,8 @@
 	;	model_semi		% just functional
 	;	model_non.		% not functional
 
+%-----------------------------------------------------------------------------%
+
 % c_interface_info holds information used when generating
 % code that uses the C interface.
 :- type c_interface_info
@@ -61,6 +63,43 @@
 	% by export.m.
 :- type c_export	==	string.
 
+%-----------------------------------------------------------------------------%
+
+:- import_module continuation_info.
+
+:- type global_data.
+
+:- pred global_data_init(global_data::out) is det.
+
+:- pred global_data_add_new_proc_var(global_data::in,
+	pred_proc_id::in, comp_gen_c_var::in, global_data::out) is det.
+
+:- pred global_data_add_new_proc_layout(global_data::in,
+	pred_proc_id::in, proc_layout_info::in, global_data::out) is det.
+
+:- pred global_data_update_proc_layout(global_data::in,
+	pred_proc_id::in, proc_layout_info::in, global_data::out) is det.
+
+:- pred global_data_add_new_non_common_static_datas(global_data::in,
+	list(comp_gen_c_data)::in, global_data::out) is det.
+
+:- pred global_data_maybe_get_proc_layout(global_data::in, pred_proc_id::in,
+	proc_layout_info::out) is semidet.
+
+:- pred global_data_get_proc_layout(global_data::in, pred_proc_id::in,
+	proc_layout_info::out) is det.
+
+:- pred global_data_get_all_proc_vars(global_data::in,
+	list(comp_gen_c_var)::out) is det.
+
+:- pred global_data_get_all_proc_layouts(global_data::in,
+	list(proc_layout_info)::out) is det.
+
+:- pred global_data_get_all_non_common_static_data(global_data::in,
+	list(comp_gen_c_data)::out) is det.
+
+%-----------------------------------------------------------------------------%
+
 %
 % The type `c_file' is the actual LLDS.
 %
@@ -1058,3 +1097,114 @@
 llds__type_is_word_size_as_arg(data_ptr,     yes).
 llds__type_is_word_size_as_arg(code_ptr,     yes).
 llds__type_is_word_size_as_arg(word,         yes).
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
+:- type proc_var_map	==	map(pred_proc_id, comp_gen_c_var).
+:- type proc_layout_map	==	map(pred_proc_id, proc_layout_info).
+
+:- type global_data
+	--->	global_data(
+			proc_var_map,		% Information about the global
+						% variables defined by each
+						% procedure.
+			proc_layout_map,	% Information about the
+						% layout structures defined
+						% by each procedure.
+			list(comp_gen_c_data)	% The list of global data
+						% structures that do not need
+						% to be checked by llds_common,
+						% because their construction
+						% ensures no overlaps.
+		).
+
+global_data_init(global_data(EmptyDataMap, EmptyLayoutMap, [])) :-
+	map__init(EmptyDataMap),
+	map__init(EmptyLayoutMap).
+
+global_data_add_new_proc_var(GlobalData0, PredProcId, ProcVar,
+		GlobalData) :-
+	global_data_get_proc_var_map(GlobalData0, ProcVarMap0),
+	map__det_insert(ProcVarMap0, PredProcId, ProcVar, ProcVarMap),
+	global_data_set_proc_var_map(GlobalData0, ProcVarMap,
+		GlobalData).
+
+global_data_add_new_proc_layout(GlobalData0, PredProcId, ProcLayout,
+		GlobalData) :-
+	global_data_get_proc_layout_map(GlobalData0, ProcLayoutMap0),
+	map__det_insert(ProcLayoutMap0, PredProcId, ProcLayout, ProcLayoutMap),
+	global_data_set_proc_layout_map(GlobalData0, ProcLayoutMap,
+		GlobalData).
+
+global_data_update_proc_layout(GlobalData0, PredProcId, ProcLayout,
+		GlobalData) :-
+	global_data_get_proc_layout_map(GlobalData0, ProcLayoutMap0),
+	map__det_update(ProcLayoutMap0, PredProcId, ProcLayout, ProcLayoutMap),
+	global_data_set_proc_layout_map(GlobalData0, ProcLayoutMap,
+		GlobalData).
+
+global_data_add_new_non_common_static_datas(GlobalData0, NewNonCommonStatics,
+		GlobalData) :-
+	global_data_get_non_common_static_data(GlobalData0, NonCommonStatics0),
+	list__append(NewNonCommonStatics, NonCommonStatics0, NonCommonStatics),
+	global_data_set_non_common_static_data(GlobalData0, NonCommonStatics,
+		GlobalData).
+
+global_data_maybe_get_proc_layout(GlobalData0, PredProcId, ProcLayout) :-
+	global_data_get_proc_layout_map(GlobalData0, ProcLayoutMap),
+	map__search(ProcLayoutMap, PredProcId, ProcLayout).
+
+global_data_get_proc_layout(GlobalData0, PredProcId, ProcLayout) :-
+	global_data_get_proc_layout_map(GlobalData0, ProcLayoutMap),
+	map__lookup(ProcLayoutMap, PredProcId, ProcLayout).
+
+global_data_get_all_proc_vars(GlobalData, ProcVars) :-
+	global_data_get_proc_var_map(GlobalData, ProcVarMap),
+	map__values(ProcVarMap, ProcVars).
+
+global_data_get_all_proc_layouts(GlobalData, ProcLayouts) :-
+	global_data_get_proc_layout_map(GlobalData, ProcLayoutMap),
+	map__values(ProcLayoutMap, ProcLayouts).
+
+global_data_get_all_non_common_static_data(GlobalData, NonCommonStatics) :-
+	global_data_get_non_common_static_data(GlobalData, NonCommonStatics).
+
+%-----------------------------------------------------------------------------%
+
+:- pred global_data_get_proc_var_map(global_data::in, proc_var_map::out)
+	is det.
+:- pred global_data_get_proc_layout_map(global_data::in, proc_layout_map::out)
+	is det.
+:- pred global_data_get_non_common_static_data(global_data::in,
+	list(comp_gen_c_data)::out) is det.
+:- pred global_data_set_proc_var_map(global_data::in, proc_var_map::in,
+	global_data::out) is det.
+:- pred global_data_set_proc_layout_map(global_data::in, proc_layout_map::in,
+	global_data::out) is det.
+:- pred global_data_set_non_common_static_data(global_data::in,
+	list(comp_gen_c_data)::in, global_data::out) is det.
+
+global_data_get_proc_var_map(GD, A) :-
+	GD = global_data(A, _, _).
+
+global_data_get_proc_layout_map(GD, B) :-
+	GD = global_data(_, B, _).
+
+global_data_get_non_common_static_data(GD, C) :-
+	GD = global_data(_, _, C).
+
+global_data_set_proc_var_map(GD0, A, GD) :-
+	GD0 = global_data(_, B, C),
+	GD  = global_data(A, B, C).
+
+global_data_set_proc_layout_map(GD0, B, GD) :-
+	GD0 = global_data(A, _, C),
+	GD  = global_data(A, B, C).
+
+global_data_set_non_common_static_data(GD0, C, GD) :-
+	GD0 = global_data(A, B, _),
+	GD  = global_data(A, B, C).
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
Index: compiler/mercury_compile.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.132
diff -u -r1.132 mercury_compile.m
--- mercury_compile.m	1999/07/10 07:59:04	1.132
+++ mercury_compile.m	1999/07/10 07:53:21
@@ -433,9 +433,10 @@
 			    []
 			)
 		    ;
-			mercury_compile__backend_pass(HLDS50, HLDS70, LLDS), !,
-			mercury_compile__output_pass(HLDS70, LLDS, MaybeRLFile,
-				ModuleName, _CompileErrors)
+			mercury_compile__backend_pass(HLDS50, HLDS70,
+				GlobalData, LLDS), !,
+			mercury_compile__output_pass(HLDS70, GlobalData, LLDS,
+				MaybeRLFile, ModuleName, _CompileErrors)
 		    )
 		;
 		    []
@@ -1053,28 +1054,31 @@
 
 %-----------------------------------------------------------------------------%
 
-:- pred mercury_compile__backend_pass(module_info, module_info,
+:- pred mercury_compile__backend_pass(module_info, module_info, global_data,
 	list(c_procedure), io__state, io__state).
-% :- mode mercury_compile__backend_pass(di, uo, out, di, uo) is det.
-:- mode mercury_compile__backend_pass(in, out, out, di, uo) is det.
+% :- mode mercury_compile__backend_pass(di, uo, out, out, di, uo) is det.
+:- mode mercury_compile__backend_pass(in, out, out, out, di, uo) is det.
 
-mercury_compile__backend_pass(HLDS0, HLDS, LLDS) -->
+mercury_compile__backend_pass(HLDS0, HLDS, GlobalData, LLDS) -->
 	globals__io_lookup_bool_option(trad_passes, TradPasses),
 	(
 		{ TradPasses = no },
-		mercury_compile__backend_pass_by_phases(HLDS0, HLDS, LLDS)
+		mercury_compile__backend_pass_by_phases(HLDS0, HLDS,
+			GlobalData, LLDS)
 	;
 		{ TradPasses = yes },
-		mercury_compile__backend_pass_by_preds(HLDS0, HLDS, LLDS)
+		mercury_compile__backend_pass_by_preds(HLDS0, HLDS,
+			GlobalData, LLDS)
 	).
 
 %-----------------------------------------------------------------------------%
 
 :- pred mercury_compile__backend_pass_by_phases(module_info, module_info,
-	list(c_procedure), io__state, io__state).
-:- mode mercury_compile__backend_pass_by_phases(in, out, out, di, uo) is det.
+	global_data, list(c_procedure), io__state, io__state).
+:- mode mercury_compile__backend_pass_by_phases(in, out, out, out, di, uo)
+	is det.
 
-mercury_compile__backend_pass_by_phases(HLDS50, HLDS99, LLDS) -->
+mercury_compile__backend_pass_by_phases(HLDS50, HLDS99, GlobalData, LLDS) -->
 	globals__io_lookup_bool_option(verbose, Verbose),
 	globals__io_lookup_bool_option(statistics, Stats),
 
@@ -1105,41 +1109,45 @@
 	{ HLDS90 = HLDS72 },
 	mercury_compile__maybe_dump_hlds(HLDS90, "90", "precodegen"), !,
 
-	mercury_compile__generate_code(HLDS90, Verbose, Stats, HLDS95, LLDS1),
-	!,
-	mercury_compile__maybe_dump_hlds(HLDS95, "95", "codegen"), !,
+	{ global_data_init(GlobalData0) },
 
-	mercury_compile__maybe_generate_stack_layouts(HLDS95, LLDS1, Verbose, 
-		Stats, HLDS97), !,
-	mercury_compile__maybe_dump_hlds(HLDS97, "97", "stack_layout"), !,
+	mercury_compile__generate_code(HLDS90, GlobalData0, Verbose, Stats,
+		HLDS99, GlobalData1, LLDS1),
+	!,
+	mercury_compile__maybe_dump_hlds(HLDS99, "99", "codegen"), !,
 
-	{ HLDS99 = HLDS97 },
-	mercury_compile__maybe_dump_hlds(HLDS99, "99", "final"), !,
+	mercury_compile__maybe_generate_stack_layouts(HLDS99, GlobalData1,
+		LLDS1, Verbose, Stats, GlobalData), !,
+	% mercury_compile__maybe_dump_global_data(GlobalData),
 
-	{ module_info_get_global_data(HLDS99, GlobalData) },
 	mercury_compile__maybe_do_optimize(LLDS1, GlobalData, Verbose, Stats,
 		LLDS).
 
 :- pred mercury_compile__backend_pass_by_preds(module_info, module_info,
-	list(c_procedure), io__state, io__state).
-% :- mode mercury_compile__backend_pass_by_preds(di, uo, out, di, uo) is det.
-:- mode mercury_compile__backend_pass_by_preds(in, out, out, di, uo) is det.
+	global_data, list(c_procedure), io__state, io__state).
+% :- mode mercury_compile__backend_pass_by_preds(di, uo, out, out, di, uo)
+%	is det.
+:- mode mercury_compile__backend_pass_by_preds(in, out, out, out, di, uo)
+	is det.
 
-mercury_compile__backend_pass_by_preds(HLDS0, HLDS, LLDS) -->
+mercury_compile__backend_pass_by_preds(HLDS0, HLDS, GlobalData, LLDS) -->
 	{ module_info_predids(HLDS0, PredIds) },
-	mercury_compile__backend_pass_by_preds_2(PredIds, HLDS0, HLDS, LLDS).
+	{ global_data_init(GlobalData0) },
+	mercury_compile__backend_pass_by_preds_2(PredIds, HLDS0, HLDS,
+		GlobalData0, GlobalData, LLDS).
 
 :- pred mercury_compile__backend_pass_by_preds_2(list(pred_id),
-	module_info, module_info, list(c_procedure), io__state, io__state).
-% :- mode mercury_compile__backend_pass_by_preds_2(in, di, uo, out, di, uo)
-% 	is det.
-:- mode mercury_compile__backend_pass_by_preds_2(in, in, out, out, di, uo)
-	is det.
+	module_info, module_info, global_data, global_data, list(c_procedure),
+	io__state, io__state).
+% :- mode mercury_compile__backend_pass_by_preds_2(in, di, uo, in, out, out,
+%	di, uo) is det.
+:- mode mercury_compile__backend_pass_by_preds_2(in, in, out, in, out, out,
+	di, uo) is det.
 
-mercury_compile__backend_pass_by_preds_2([], ModuleInfo, ModuleInfo, [])
-	--> [].
+mercury_compile__backend_pass_by_preds_2([], ModuleInfo, ModuleInfo,
+		GlobalData, GlobalData, []) --> [].
 mercury_compile__backend_pass_by_preds_2([PredId | PredIds], ModuleInfo0,
-		ModuleInfo, Code) -->
+		ModuleInfo, GlobalData0, GlobalData, Code) -->
 	{ module_info_preds(ModuleInfo0, PredTable) },
 	{ map__lookup(PredTable, PredId, PredInfo) },
 	{ pred_info_non_imported_procids(PredInfo, ProcIds) },
@@ -1149,6 +1157,7 @@
 		}
 	->
 		{ ModuleInfo1 = ModuleInfo0 },
+		{ GlobalData1 = GlobalData0 },
 		{ Code1 = [] }
 	;
 		globals__io_lookup_bool_option(verbose, Verbose),
@@ -1160,41 +1169,44 @@
 			[]
 		),
 		mercury_compile__backend_pass_by_preds_3(ProcIds, PredId,
-			PredInfo, ModuleInfo0, ModuleInfo1, Code1), !
+			PredInfo, ModuleInfo0, ModuleInfo1,
+			GlobalData0, GlobalData1, Code1), !
 	),
 	mercury_compile__backend_pass_by_preds_2(PredIds,
-		ModuleInfo1, ModuleInfo, Code2),
+		ModuleInfo1, ModuleInfo, GlobalData1, GlobalData, Code2),
 	{ list__append(Code1, Code2, Code) }.
 
 :- pred mercury_compile__backend_pass_by_preds_3(list(proc_id), pred_id,
-	pred_info, module_info, module_info, list(c_procedure),
-	io__state, io__state).
-% :- mode mercury_compile__backend_pass_by_preds_3(in, in, in, di, uo, out,
-% 	di, uo) is det.
-:- mode mercury_compile__backend_pass_by_preds_3(in, in, in, in, out, out,
-	di, uo) is det.
+	pred_info, module_info, module_info, global_data, global_data,
+	list(c_procedure), io__state, io__state).
+% :- mode mercury_compile__backend_pass_by_preds_3(in, in, in, di, uo, in, out,
+%	out, di, uo) is det.
+:- mode mercury_compile__backend_pass_by_preds_3(in, in, in, in, out, in, out,
+	out, di, uo) is det.
 
-mercury_compile__backend_pass_by_preds_3([], _, _, ModuleInfo, ModuleInfo, [])
-		--> [].
+mercury_compile__backend_pass_by_preds_3([], _, _, ModuleInfo, ModuleInfo,
+		GlobalData, GlobalData, []) --> [].
 mercury_compile__backend_pass_by_preds_3([ProcId | ProcIds], PredId, PredInfo,
-		ModuleInfo0, ModuleInfo, [Proc | Procs]) -->
+		ModuleInfo0, ModuleInfo, GlobalData0, GlobalData,
+		[Proc | Procs]) -->
 	{ pred_info_procedures(PredInfo, ProcTable) },
 	{ map__lookup(ProcTable, ProcId, ProcInfo) },
 	mercury_compile__backend_pass_by_preds_4(PredInfo, ProcInfo,
-		ProcId, PredId, ModuleInfo0, ModuleInfo1, Proc),
+		ProcId, PredId, ModuleInfo0, ModuleInfo1,
+		GlobalData0, GlobalData1, Proc),
 	mercury_compile__backend_pass_by_preds_3(ProcIds, PredId, PredInfo,
-		ModuleInfo1, ModuleInfo, Procs).
+		ModuleInfo1, ModuleInfo, GlobalData1, GlobalData, Procs).
 
 :- pred mercury_compile__backend_pass_by_preds_4(pred_info, proc_info,
-	proc_id, pred_id, module_info, module_info, c_procedure,
-	io__state, io__state).
+	proc_id, pred_id, module_info, module_info, global_data, global_data,
+	c_procedure, io__state, io__state).
 % :- mode mercury_compile__backend_pass_by_preds_4(in, in, in, in, di, uo,
-% 	out, di, uo) is det.
+% 	in, out, out, di, uo) is det.
 :- mode mercury_compile__backend_pass_by_preds_4(in, in, in, in, in, out,
-	out, di, uo) is det.
+	in, out, out, di, uo) is det.
 
 mercury_compile__backend_pass_by_preds_4(PredInfo, ProcInfo0, ProcId, PredId,
-		ModuleInfo0, ModuleInfo, Proc) -->
+		ModuleInfo0, ModuleInfo, GlobalData0, GlobalData, Proc) -->
 	globals__io_get_globals(Globals),
 	{ globals__lookup_bool_option(Globals, follow_code, FollowCode) },
 	{ globals__lookup_bool_option(Globals, prev_code, PrevCode) },
@@ -1240,7 +1252,6 @@
 	write_proc_progress_message(
 		"% Generating low-level (LLDS) code for ",
 				PredId, ProcId, ModuleInfo3),
-	{ module_info_get_global_data(ModuleInfo3, GlobalData0) },
 	{ module_info_get_cell_count(ModuleInfo3, CellCount0) },
 	{ generate_proc_code(PredInfo, ProcInfo, ProcId, PredId, ModuleInfo3,
 		Globals, GlobalData0, GlobalData1, CellCount0, CellCount,
@@ -1256,9 +1267,8 @@
 		"% Generating call continuation information for ",
 			PredId, ProcId, ModuleInfo3),
 	{ continuation_info__maybe_process_proc_llds(Instructions, PredProcId,
-		ModuleInfo3, GlobalData1, GlobalData2) },
-	{ module_info_set_global_data(ModuleInfo3, GlobalData2, ModuleInfo4) },
-	{ module_info_set_cell_count(ModuleInfo4, CellCount, ModuleInfo) }.
+		ModuleInfo3, GlobalData1, GlobalData) },
+	{ module_info_set_cell_count(ModuleInfo3, CellCount, ModuleInfo) }.
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
@@ -1956,14 +1966,16 @@
 		{ HLDS = HLDS0 }
 	).
 
-:- pred mercury_compile__generate_code(module_info, bool, bool, module_info,
-	list(c_procedure), io__state, io__state).
-:- mode mercury_compile__generate_code(in, in, in, out, out, di, uo) is det.
+:- pred mercury_compile__generate_code(module_info, global_data, bool, bool,
+	module_info, global_data, list(c_procedure), io__state, io__state).
+:- mode mercury_compile__generate_code(in, in, in, in, out, out, out, di, uo)
+	is det.
 
-mercury_compile__generate_code(HLDS0, Verbose, Stats, HLDS, LLDS) -->
+mercury_compile__generate_code(HLDS0, GlobalData0, Verbose, Stats,
+		HLDS, GlobalData, LLDS) -->
 	maybe_write_string(Verbose, "% Generating code...\n"),
 	maybe_flush_output(Verbose),
-	generate_code(HLDS0, HLDS, LLDS),
+	generate_code(HLDS0, HLDS, GlobalData0, GlobalData, LLDS),
 	maybe_write_string(Verbose, "% done.\n"),
 	maybe_report_stats(Stats).
 
@@ -1984,20 +1996,18 @@
 		{ LLDS = LLDS0 }
 	).
 
-:- pred mercury_compile__maybe_generate_stack_layouts(module_info, 
-	list(c_procedure), bool, bool, module_info, io__state, io__state).
-:- mode mercury_compile__maybe_generate_stack_layouts(in, in, in, in, out, 
+:- pred mercury_compile__maybe_generate_stack_layouts(module_info, global_data,
+	list(c_procedure), bool, bool, global_data, io__state, io__state).
+:- mode mercury_compile__maybe_generate_stack_layouts(in, in, in, in, in, out, 
 	di, uo) is det.
 
-mercury_compile__maybe_generate_stack_layouts(ModuleInfo0, LLDS0, Verbose, 
-		Stats, ModuleInfo) -->
+mercury_compile__maybe_generate_stack_layouts(ModuleInfo0, GlobalData0, LLDS0,
+		Verbose, Stats, GlobalData) -->
 	maybe_write_string(Verbose,
 		"% Generating call continuation information..."),
 	maybe_flush_output(Verbose),
-	{ module_info_get_global_data(ModuleInfo0, GlobalData0) },
 	{ continuation_info__maybe_process_llds(LLDS0, ModuleInfo0,
 		GlobalData0, GlobalData) },
-	{ module_info_set_global_data(ModuleInfo0, GlobalData, ModuleInfo) },
 	maybe_write_string(Verbose, " done.\n"),
 	maybe_report_stats(Stats).
 
@@ -2009,7 +2019,7 @@
 % used for the C interface.  This stuff mostly just gets
 % passed directly to the LLDS unchanged, but we do do
 % a bit of code generation -- for example, we call
-% export__get_pragma_exported_procs here, which does the
+% export__get_c_export_{decls,defns} here, which do the
 % generation of C code for `pragma export' declarations.
 %
 
@@ -2030,20 +2040,20 @@
 
 % The LLDS output pass
 
-:- pred mercury_compile__output_pass(module_info, list(c_procedure),
-	maybe(rl_file), module_name, bool, io__state, io__state).
-:- mode mercury_compile__output_pass(in, in, in, in, out, di, uo) is det.
+:- pred mercury_compile__output_pass(module_info, global_data,
+	list(c_procedure), maybe(rl_file), module_name, bool,
+	io__state, io__state).
+:- mode mercury_compile__output_pass(in, in, in, in, in, out, di, uo) is det.
 
-mercury_compile__output_pass(HLDS0, Procs0, MaybeRLFile,
+mercury_compile__output_pass(HLDS0, GlobalData, Procs0, MaybeRLFile,
 		ModuleName, CompileErrors) -->
 	globals__io_lookup_bool_option(verbose, Verbose),
 	globals__io_lookup_bool_option(statistics, Stats),
 	{ base_type_info__generate_llds(HLDS0, TypeCtorInfos) },
 	{ base_type_layout__generate_llds(HLDS0, HLDS1, TypeCtorLayouts) },
-	{ stack_layout__generate_llds(HLDS1, HLDS,
+	{ stack_layout__generate_llds(HLDS1, HLDS, GlobalData,
 		PossiblyDynamicLayouts, StaticLayouts, LayoutLabels) },
 	{ get_c_interface_info(HLDS, C_InterfaceInfo) },
-	{ module_info_get_global_data(HLDS, GlobalData) },
 	{ global_data_get_all_proc_vars(GlobalData, GlobalVars) },
 	{ global_data_get_all_non_common_static_data(GlobalData,
 		NonCommonStaticData) },
Index: compiler/optimize.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/optimize.m,v
retrieving revision 1.16
diff -u -r1.16 optimize.m
--- optimize.m	1999/03/12 05:53:28	1.16
+++ optimize.m	1999/07/09 08:27:06
@@ -14,7 +14,7 @@
 
 :- interface.
 
-:- import_module llds, hlds_module.
+:- import_module llds.
 :- import_module io, list.
 
 :- pred optimize_main(list(c_procedure)::in, global_data::in,
Index: compiler/stack_layout.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/stack_layout.m,v
retrieving revision 1.31
diff -u -r1.31 stack_layout.m
--- stack_layout.m	1999/05/28 05:26:35	1.31
+++ stack_layout.m	1999/07/09 08:26:51
@@ -230,6 +230,7 @@
 :- import_module std_util, list, set_bbbtree.
 
 :- pred stack_layout__generate_llds(module_info::in, module_info::out,
+	global_data::in,
 	list(comp_gen_c_data)::out, list(comp_gen_c_data)::out,
 	set_bbbtree(label)::out) is det.
 
@@ -250,9 +251,8 @@
 	% Process all the continuation information stored in the HLDS,
 	% converting it into LLDS data structures.
 
-stack_layout__generate_llds(ModuleInfo0, ModuleInfo,
+stack_layout__generate_llds(ModuleInfo0, ModuleInfo, GlobalData,
 		PossiblyDynamicLayouts, StaticLayouts, LayoutLabels) :-
-	module_info_get_global_data(ModuleInfo0, GlobalData),
 	global_data_get_all_proc_layouts(GlobalData, ProcLayoutList),
 
 	module_info_name(ModuleInfo0, ModuleName),
Index: compiler/table_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/table_gen.m,v
retrieving revision 1.8
diff -u -r1.8 table_gen.m
--- table_gen.m	1999/06/30 17:12:41	1.8
+++ table_gen.m	1999/07/09 08:27:59
@@ -224,19 +224,12 @@
 		EvalMethod \= eval_normal
 	->
 		table_gen__process_proc(EvalMethod, PredId, ProcId, ProcInfo,
-			PredInfo, Module0, Module1),
-		module_info_get_global_data(Module1, GlobalData0),
-		code_util__make_proc_label(Module1, PredId, ProcId, ProcLabel),
-		module_info_name(Module0, ModuleName),
-		Var = tabling_pointer_var(ModuleName, ProcLabel),
-		global_data_add_new_proc_var(GlobalData0,
-			proc(PredId, ProcId), Var, GlobalData),
-		module_info_set_global_data(Module1, GlobalData, Module2)
+			PredInfo, Module0, Module1)
 	;
-		Module2 = Module0
+		Module1 = Module0
 	),
 
-	table_gen__process_procs(PredId, ProcIds, Module2, Module).
+	table_gen__process_procs(PredId, ProcIds, Module1, Module).
 
 %-----------------------------------------------------------------------------%
 
-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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