[m-rev.] for review: gather execution counts

Zoltan Somogyi zs at cs.mu.OZ.AU
Wed Aug 11 14:07:19 AEST 2004


For review by Ian.

Zoltan.

Add a mechanism for collecting information about how many times each event
is executed. Later changes will exploit this information, for coverage testing
and for better search strategies in the declarative debugger.

runtime/mercury_stack_layout.h:
	Extend the module layout structure to contain a pointer to an array
	of counters, with one counter for each label layout structure
	corresponding an event.

	Extend label layout structures to contain the label's index into
	this array. The new field fits into a hole in the existing structure
	required by alignment considerations, so the size of label layout
	structures is unaffected.

	The memory cost of the new facility is thus only one word per event.

	Extend the macros for defining label layout structures to take an extra
	argument for the new field.

runtime/mercury_grade.m:
	Update the binary compatibility version number for debug grades,
	since runtimes before this change and the compiler-generated C files
	in debug grades from after this change are not compatible, and neither
	are runtimes after this change and the compiler-generated C files
	in debug grades from before this change.

runtime/mercury_trace_base.[ch]:
	Add a third alternative function to call from MR_trace; besides
	MR_trace_real (in the trace directory) and MR_trace_fake (in this
	module), add MR_trace_count, which returns after incrementing the
	counter of the event's label layout structure.

	Instead of a single variable, MR_trace_enabled, controlling whether
	MR_trace is enabled or not and debugging is enabled or not, use two
	separate variables: MR_trace_func_enabled controlling whether MR_trace
	is enabled or not, and MR_debug_enabled controlling whether debugging
	is enabled or not. MR_trace_func_enabled is always set to the
	disjunction of MR_debug_enabled and a new variable
	MR_trace_count_enabled, the variable controlling whether the facility
	for counting label executions is enabled.

	Add a function for writing out the gathered execution counts.

runtime/mercury_trace_base.[ch]:
trace/mercury_trace_tables.[ch]:
	Move the table of module_infos from mercury_trace_tables to
	mercury_trace_base, since the code to write out execution counts
	needs it.

runtime/mercury_wrapper.c:
	When MERCURY_OPTIONS contains --trace-count and debugging is not,
	enable the mechanism for counting the execution of events, and
	write out the results.

library/exception.m:
library/io.m:
library/table_builtin.m:
runtime/mercury_tabling_preds.h:
trace/mercury_trace_declarative.c:
trace/mercury_trace_external.c:
trace/mercury_trace_vars.c:
	Conform to the changes involving the replacement of MR_trace_enabled.

tools/bootcheck:
	Add an new option, --trace-count, for enabling the new mechanism.

compiler/layout.m:
	Change the compiler's data structures for label layouts and module
	layouts to conform to the changes in mercury_stack_layout.h.

compiler/layout_out.m:
	Update the code for writing out label layouts and module
	layouts.

compiler/stack_layout.m:
	Allocate slots in the execution count array to the label layout
	structures of all events.

	Delete the unnecessary last arguments of `get' field access predicates.

compiler/llds_out.m:
compiler/opt_debug.m:
	Conform to the changes in layout.m.

cvs diff: Diffing .
cvs diff: Diffing analysis
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/doc
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing boehm_gc/tests
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
Index: compiler/layout.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/layout.m,v
retrieving revision 1.14
diff -u -r1.14 layout.m
--- compiler/layout.m	23 May 2004 23:14:28 -0000	1.14
+++ compiler/layout.m	9 Aug 2004 09:45:32 -0000
@@ -50,6 +50,7 @@
 			proc_layout_name	:: layout_name,
 			maybe_port		:: maybe(trace_port),
 			maybe_is_hidden		:: maybe(bool),
+			label_num_in_module	:: int,
 			maybe_goal_path		:: maybe(int), % offset
 			maybe_var_info		:: maybe(label_var_info)
 		)
@@ -65,7 +66,8 @@
 			proc_layout_names	:: list(layout_name),
 			file_layouts		:: list(file_layout_data),
 			trace_level		:: trace_level,
-			suppressed_events	:: int
+			suppressed_events	:: int,
+			num_label_exec_count	:: int
 		)
 	;	closure_proc_id_data(		% defines MR_Closure_Id
 			caller_proc_label	:: proc_label,
@@ -200,6 +202,7 @@
 	;	module_layout_string_table(module_name)
 	;	module_layout_file_vector(module_name)
 	;	module_layout_proc_vector(module_name)
+	;	module_layout_label_exec_count(module_name, int)
 	;	module_layout(module_name)
 	;	proc_static(rtti_proc_label)
 	;	proc_static_call_sites(rtti_proc_label).
Index: compiler/layout_out.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/layout_out.m,v
retrieving revision 1.36
diff -u -r1.36 layout_out.m
--- compiler/layout_out.m	20 Jul 2004 04:41:00 -0000	1.36
+++ compiler/layout_out.m	9 Aug 2004 12:20:20 -0000
@@ -99,11 +99,11 @@
 :- import_module int, char, string, require, std_util, list.
 
 output_layout_data_defn(label_layout_data(ProcLabel, LabelNum, ProcLayoutAddr,
-		MaybePort, MaybeIsHidden, MaybeGoalPath, MaybeVarInfo),
-		!DeclSet, !IO) :-
+		MaybePort, MaybeIsHidden, LabelNumber, MaybeGoalPath,
+		MaybeVarInfo), !DeclSet, !IO) :-
 	output_label_layout_data_defn(ProcLabel, LabelNum, ProcLayoutAddr,
-		MaybePort, MaybeIsHidden, MaybeGoalPath, MaybeVarInfo,
-		!DeclSet, !IO).
+		MaybePort, MaybeIsHidden, LabelNumber, MaybeGoalPath,
+		MaybeVarInfo, !DeclSet, !IO).
 output_layout_data_defn(proc_layout_data(ProcLabel, Traversal, MaybeRest),
 		!DeclSet, !IO) :-
 	output_proc_layout_data_defn(ProcLabel, Traversal, MaybeRest,
@@ -115,10 +115,10 @@
 		ModuleName, FileName, LineNumber, GoalPath, !DeclSet, !IO).
 output_layout_data_defn(module_layout_data(ModuleName, StringTableSize,
 		StringTable, ProcLayoutNames, FileLayouts, TraceLevel,
-		SuppressedEvents), !DeclSet, !IO) :-
+		SuppressedEvents, NumLabels), !DeclSet, !IO) :-
 	output_module_layout_data_defn(ModuleName, StringTableSize,
 		StringTable, ProcLayoutNames, FileLayouts, TraceLevel,
-		SuppressedEvents, !DeclSet, !IO).
+		SuppressedEvents, NumLabels, !DeclSet, !IO).
 output_layout_data_defn(table_io_decl_data(RttiProcLabel, Kind, NumPTIs,
 		PTIVectorRval, TypeParamsRval), !DeclSet, !IO) :-
 	output_table_io_decl(RttiProcLabel, Kind, NumPTIs,
@@ -148,10 +148,10 @@
 
 :- pred extract_layout_name(layout_data::in, layout_name::out) is det.
 
-extract_layout_name(label_layout_data(ProcLabel, LabelNum, _, _, _, _, yes(_)),
-		LayoutName) :-
+extract_layout_name(label_layout_data(ProcLabel, LabelNum, _, _, _, _, _,
+		yes(_)), LayoutName) :-
 	LayoutName = label_layout(ProcLabel, LabelNum, label_has_var_info).
-extract_layout_name(label_layout_data(ProcLabel, LabelNum, _, _, _, _, no),
+extract_layout_name(label_layout_data(ProcLabel, LabelNum, _, _, _, _, _, no),
 		LayoutName) :-
 	LayoutName = label_layout(ProcLabel, LabelNum, label_has_no_var_info).
 extract_layout_name(proc_layout_data(RttiProcLabel, _, MaybeRest),
@@ -162,7 +162,8 @@
 extract_layout_name(closure_proc_id_data(CallerProcLabel, SeqNo,
 		ClosureProcLabel, _, _, _, _),
 		closure_proc_id(CallerProcLabel, SeqNo, ClosureProcLabel)).
-extract_layout_name(module_layout_data(ModuleName, _,_,_,_,_,_), LayoutName) :-
+extract_layout_name(module_layout_data(ModuleName, _, _, _, _, _, _, _),
+		LayoutName) :-
 	LayoutName = module_layout(ModuleName).
 extract_layout_name(table_io_decl_data(RttiProcLabel, _, _, _, _),
 		LayoutName) :-
@@ -264,6 +265,11 @@
 	io__write_string("_module_procs__"),
 	{ ModuleNameStr = sym_name_mangle(ModuleName) },
 	io__write_string(ModuleNameStr).
+output_layout_name(module_layout_label_exec_count(ModuleName, _)) -->
+	io__write_string(mercury_data_prefix),
+	io__write_string("_module_label_exec_counts__"),
+	{ ModuleNameStr = sym_name_mangle(ModuleName) },
+	io__write_string(ModuleNameStr).
 output_layout_name(module_layout(ModuleName)) -->
 	io__write_string(mercury_data_prefix),
 	io__write_string("_module_layout__"),
@@ -382,6 +388,14 @@
 	io__write_string("static const MR_Module_File_Layout *"),
 	output_layout_name(module_layout_file_vector(ModuleName)),
 	io__write_string("[]").
+output_layout_name_storage_type_name(module_layout_label_exec_count(
+		ModuleName, NumElements), _BeingDefined) -->
+	io__write_string("static MR_Unsigned "),
+	output_layout_name(
+		module_layout_label_exec_count(ModuleName, NumElements)),
+	io__write_string("["),
+	io__write_int(NumElements),
+	io__write_string("]").
 output_layout_name_storage_type_name(module_layout_proc_vector(ModuleName),
 		_BeingDefined) -->
 	io__write_string("static const MR_Proc_Layout *"),
@@ -431,6 +445,7 @@
 layout_name_would_include_code_addr(module_layout_string_table(_)) = no.
 layout_name_would_include_code_addr(module_layout_file_vector(_)) = no.
 layout_name_would_include_code_addr(module_layout_proc_vector(_)) = no.
+layout_name_would_include_code_addr(module_layout_label_exec_count(_, _)) = no.
 layout_name_would_include_code_addr(module_layout(_)) = no.
 layout_name_would_include_code_addr(proc_static(_)) = no.
 layout_name_would_include_code_addr(proc_static_call_sites(_)) = no.
@@ -472,12 +487,13 @@
 output_rval_or_num_or_none(none, !IO).
 
 :- pred output_label_layout_data_defn(proc_label::in, int::in, layout_name::in,
-	maybe(trace_port)::in, maybe(bool)::in, maybe(int)::in,
+	maybe(trace_port)::in, maybe(bool)::in, int::in, maybe(int)::in,
 	maybe(label_var_info)::in, decl_set::in, decl_set::out,
 	io::di, io::uo) is det.
 
 output_label_layout_data_defn(ProcLabel, LabelNum, ProcLayoutAddr, MaybePort,
-		MaybeIsHidden, MaybeGoalPath, MaybeVarInfo, !DeclSet, !IO) :-
+		MaybeIsHidden, LabelNumberInModule, MaybeGoalPath,
+		MaybeVarInfo, !DeclSet, !IO) :-
 	output_layout_decl(ProcLayoutAddr, !DeclSet, !IO),
 	(
 		MaybeIsHidden = yes(yes),
@@ -564,6 +580,8 @@
 		io__write_string("NONE", !IO)
 	),
 	io__write_string(", ", !IO),
+	io__write_int(LabelNumberInModule, !IO),
+	io__write_string(", ", !IO),
 	(
 		MaybeGoalPath = yes(GoalPath),
 		io__write_int(GoalPath, !IO)
@@ -1046,12 +1064,12 @@
 
 :- pred output_module_layout_data_defn(module_name::in, int::in,
 	string_with_0s::in, list(layout_name)::in, list(file_layout_data)::in,
-	trace_level::in, int::in, decl_set::in, decl_set::out,
+	trace_level::in, int::in, int::in, decl_set::in, decl_set::out,
 	io::di, io::uo) is det.
 
 output_module_layout_data_defn(ModuleName, StringTableSize, StringTable,
 		ProcLayoutNames, FileLayouts, TraceLevel, SuppressedEvents,
-		!DeclSet, !IO) :-
+		NumLabels, !DeclSet, !IO) :-
 	output_module_string_table(ModuleName, StringTableSize, StringTable,
 		!DeclSet, !IO),
 	output_module_layout_proc_vector_defn(ModuleName, ProcLayoutNames,
@@ -1061,6 +1079,13 @@
 	output_file_layout_vector_data_defn(ModuleName, FileLayoutNames,
 		FileVectorName, !DeclSet, !IO),
 
+	io__write_string("\n", !IO),
+	LabelExecCountName = module_layout_label_exec_count(ModuleName,
+		NumLabels),
+	output_layout_name_storage_type_name(LabelExecCountName, yes, !IO),
+	io__write_string(";\n", !IO),
+	decl_set_insert(data_addr(layout_addr(LabelExecCountName)), !DeclSet),
+
 	ModuleLayoutName = module_layout(ModuleName),
 	io__write_string("\n", !IO),
 	output_layout_name_storage_type_name(ModuleLayoutName, yes, !IO),
@@ -1086,6 +1111,10 @@
 	io__write_string(trace_level_rep(TraceLevel), !IO),
 	io__write_string(",\n", !IO),
 	io__write_int(SuppressedEvents, !IO),
+	io__write_string(",\n", !IO),
+	io__write_int(NumLabels, !IO),
+	io__write_string(",\n", !IO),
+	output_layout_name(LabelExecCountName, !IO),
 	io__write_string("\n};\n", !IO),
 	decl_set_insert(data_addr(layout_addr(ModuleLayoutName)), !DeclSet).
 
Index: compiler/llds_out.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/llds_out.m,v
retrieving revision 1.236
diff -u -r1.236 llds_out.m
--- compiler/llds_out.m	7 Jul 2004 07:11:03 -0000	1.236
+++ compiler/llds_out.m	9 Aug 2004 09:28:12 -0000
@@ -463,7 +463,7 @@
 		!OtherLayouts) :-
 	( Layout = proc_layout_data(_, _, _) ->
 		!:ProcLayouts = [Layout | !.ProcLayouts]
-	; Layout = label_layout_data(_, _, _, _, _, _, _) ->
+	; Layout = label_layout_data(_, _, _, _, _, _, _, _) ->
 		!:LabelLayouts = [Layout | !.LabelLayouts]
 	;
 		!:OtherLayouts = [Layout | !.OtherLayouts]
@@ -687,7 +687,7 @@
 output_debugger_init_list_decls([Data | Datas], !DeclSet, !IO) :-
 	(
 		Data = layout_data(LayoutData),
-		LayoutData = module_layout_data(ModuleName, _,_,_,_,_,_)
+		LayoutData = module_layout_data(ModuleName, _,_,_,_,_,_,_)
 	->
 		output_data_addr_decls(layout_addr(module_layout(ModuleName)),
 			!DeclSet, !IO)
@@ -707,7 +707,7 @@
 output_debugger_init_list([Data | Datas], !IO) :-
 	(
 		Data = layout_data(LayoutData),
-		LayoutData = module_layout_data(ModuleName, _,_,_,_,_,_)
+		LayoutData = module_layout_data(ModuleName, _,_,_,_,_,_,_)
 	->
 		io__write_string(
 			"\tif (MR_register_module_layout != NULL) {\n",
Index: compiler/opt_debug.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/opt_debug.m,v
retrieving revision 1.143
diff -u -r1.143 opt_debug.m
--- compiler/opt_debug.m	30 Jun 2004 02:48:05 -0000	1.143
+++ compiler/opt_debug.m	9 Aug 2004 10:20:48 -0000
@@ -531,6 +531,11 @@
 	ModuleNameStr = sym_name_mangle(ModuleName),
 	string__append_list(["module_layout_proc_vector(", ModuleNameStr, ")"],
 		Str).
+dump_layout_name(module_layout_label_exec_count(ModuleName, NumLabels), Str) :-
+	ModuleNameStr = sym_name_mangle(ModuleName),
+	NumLabelsStr = int_to_string(NumLabels),
+	string__append_list(["module_layout_label_exec_count(",
+		ModuleNameStr, ", ", NumLabelsStr, ")"], Str).
 dump_layout_name(module_layout(ModuleName), Str) :-
 	ModuleNameStr = sym_name_mangle(ModuleName),
 	string__append_list(["module_layout(", ModuleNameStr, ")"], Str).
Index: compiler/stack_layout.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/stack_layout.m,v
retrieving revision 1.93
diff -u -r1.93 stack_layout.m
--- compiler/stack_layout.m	21 Jul 2004 16:04:45 -0000	1.93
+++ compiler/stack_layout.m	10 Aug 2004 10:50:22 -0000
@@ -96,15 +96,18 @@
 	map__init(LabelTables0),
 	StringTable0 = string_table(StringMap0, [], 0),
 	global_data_get_static_cell_info(!.GlobalData, StaticCellInfo0),
+	counter__init(1, LabelCounter0),
 	LayoutInfo0 = stack_layout_info(ModuleInfo0,
-		AgcLayout, TraceLayout, ProcIdLayout,
-		StaticCodeAddr, [], [], [], LayoutLabels0, [],
+		AgcLayout, TraceLayout, ProcIdLayout, StaticCodeAddr,
+		LabelCounter0, [], [], [], LayoutLabels0, [],
 		StringTable0, LabelTables0, StaticCellInfo0),
 	stack_layout__lookup_string_in_table("", _, LayoutInfo0, LayoutInfo1),
 	stack_layout__lookup_string_in_table("<too many variables>", _,
 		LayoutInfo1, LayoutInfo2),
 	list__foldl(stack_layout__construct_layouts, ProcLayoutList,
 		LayoutInfo2, LayoutInfo),
+	LabelsCounter = LayoutInfo ^ label_counter,
+	counter__allocate(NumLabels, LabelsCounter, _),
 	TableIoDecls = LayoutInfo ^ table_infos,
 	ProcLayouts = LayoutInfo ^ proc_layouts,
 	InternalLayouts = LayoutInfo ^ internal_layouts,
@@ -138,7 +141,8 @@
 		SuppressedEvents = encode_suppressed_events(TraceSuppress),
 		ModuleLayout = layout_data(module_layout_data(ModuleName,
 			StringOffset, ConcatStrings, ProcLayoutNames,
-			SourceFileLayouts, TraceLevel, SuppressedEvents)),
+			SourceFileLayouts, TraceLevel, SuppressedEvents,
+			NumLabels)),
 		Layouts = [ModuleLayout | Layouts0]
 	;
 		TraceLayout = no,
@@ -296,7 +300,7 @@
 		VarNumMap),
 
 	ProcLabel = get_proc_label(EntryLabel),
-	stack_layout__get_procid_stack_layout(ProcIdLayout0, !Info),
+	stack_layout__get_procid_stack_layout(!.Info, ProcIdLayout0),
 	bool__or(ProcIdLayout0, ForceProcIdLayout, ProcIdLayout),
 	(
 		( ProcIdLayout = yes
@@ -323,7 +327,7 @@
 		InternalLayouts = []
 	),
 
-	stack_layout__get_label_tables(LabelTables0, !Info),
+	stack_layout__get_label_tables(!.Info, LabelTables0),
 	list__foldl(stack_layout__update_label_table, InternalLayouts,
 		LabelTables0, LabelTables),
 	stack_layout__set_label_tables(LabelTables, !Info),
@@ -471,7 +475,7 @@
 			% similar constraints.
 		MaybeSuccipInt = no
 	),
-	stack_layout__get_static_code_addresses(StaticCodeAddr, !Info),
+	stack_layout__get_static_code_addresses(!.Info, StaticCodeAddr),
 	(
 		StaticCodeAddr = yes,
 		MaybeEntryLabel = yes(EntryLabel)
@@ -502,7 +506,7 @@
 		More = no_proc_id
 	;
 		Kind = proc_layout_proc_id(_),
-		stack_layout__get_trace_stack_layout(TraceStackLayout, !Info),
+		stack_layout__get_trace_stack_layout(!.Info, TraceStackLayout),
 		(
 			TraceStackLayout = yes,
 			IsBeingTraced = yes,
@@ -528,7 +532,7 @@
 		MaybeTableInfo = no
 	;
 		MaybeTableInfo = yes(TableInfo),
-		stack_layout__get_static_cell_info(StaticCellInfo0, !Info),
+		stack_layout__get_static_cell_info(!.Info, StaticCellInfo0),
 		stack_layout__make_table_data(RttiProcLabel, Kind,
 			TableInfo, TableData,
 			StaticCellInfo0, StaticCellInfo),
@@ -834,7 +838,7 @@
 		Return = yes(_),
 		error("label has both trace and return layout info")
 	),
-	stack_layout__get_agc_stack_layout(AgcStackLayout, !Info),
+	stack_layout__get_agc_stack_layout(!.Info, AgcStackLayout),
 	(
 		Return = no,
 		set__init(ReturnLiveVarSet),
@@ -886,8 +890,24 @@
 		LabelVars = label_has_var_info
 	),
 
+	(
+		Trace = yes(_),
+		stack_layout__allocate_label_number(LabelNumber0, !Info),
+		% MR_ml_label_exec_count[0] is never written out;
+		% it is reserved for cases like this, for labels without
+		% events, and for handwritten labels.
+		( LabelNumber0 < (1 << 16) ->
+			LabelNumber = LabelNumber0
+		;
+			LabelNumber = 0
+		)
+	;
+		Trace = no,
+		LabelNumber = 0
+	),
 	LayoutData = label_layout_data(ProcLabel, LabelNum, ProcLayoutName,
-		MaybePort, MaybeIsHidden, MaybeGoalPath, MaybeVarInfo),
+		MaybePort, MaybeIsHidden, LabelNumber, MaybeGoalPath,
+		MaybeVarInfo),
 	CData = layout_data(LayoutData),
 	LayoutName = label_layout(ProcLabel, LabelNum, LabelVars),
 	Label = internal(LabelNum, ProcLabel),
@@ -1099,13 +1119,13 @@
 	list__append(IntLocnsTypes, ByteLocnsTypes, AllLocnsTypes),
 	list__append(AllTypeRvalsTypes, AllLocnsTypes,
 		TypeLocnVectorRvalsTypes),
-	stack_layout__get_static_cell_info(StaticCellInfo0, !Info),
+	stack_layout__get_static_cell_info(!.Info, StaticCellInfo0),
 	add_static_cell(TypeLocnVectorRvalsTypes, TypeLocnVectorAddr,
 		StaticCellInfo0, StaticCellInfo1),
 	TypeLocnVector = const(data_addr_const(TypeLocnVectorAddr, no)),
 	stack_layout__set_static_cell_info(StaticCellInfo1, !Info),
 
-	stack_layout__get_trace_stack_layout(TraceStackLayout, !Info),
+	stack_layout__get_trace_stack_layout(!.Info, TraceStackLayout),
 	(
 		TraceStackLayout = yes,
 		list__foldl(AddRevNums, AllArrayInfo,
@@ -1113,7 +1133,7 @@
 		list__reverse(RevVarNumRvals, VarNumRvals),
 		list__map(associate_type(uint_least16), VarNumRvals,
 			VarNumRvalsTypes),
-		stack_layout__get_static_cell_info(StaticCellInfo2, !Info),
+		stack_layout__get_static_cell_info(!.Info, StaticCellInfo2),
 		add_static_cell(VarNumRvalsTypes, NumVectorAddr,
 			StaticCellInfo2, StaticCellInfo),
 		stack_layout__set_static_cell_info(StaticCellInfo, !Info),
@@ -1355,7 +1375,7 @@
 		% variable number directly from the procedure's tvar set.
 	ExistQTvars = [],
 	NumUnivQTvars = -1,
-	stack_layout__get_static_cell_info(StaticCellInfo0, !Info),
+	stack_layout__get_static_cell_info(!.Info, StaticCellInfo0),
 	ll_pseudo_type_info__construct_typed_llds_pseudo_type_info(Type,
 		NumUnivQTvars, ExistQTvars, StaticCellInfo0, StaticCellInfo,
 		Rval, LldsType),
@@ -1634,6 +1654,7 @@
 		trace_stack_layout	:: bool, % generate tracing info?
 		procid_stack_layout	:: bool, % generate proc id info?
 		static_code_addresses	:: bool, % have static code addresses?
+		label_counter		:: counter,
 		table_infos		:: list(comp_gen_c_data),
 		proc_layouts		:: list(comp_gen_c_data),
 		internal_layouts	:: list(comp_gen_c_data),
@@ -1652,77 +1673,73 @@
 		static_cell_info	:: static_cell_info
 	).
 
-:- pred stack_layout__get_module_info(module_info::out,
-	stack_layout_info::in, stack_layout_info::out) is det.
-
-:- pred stack_layout__get_agc_stack_layout(bool::out,
-	stack_layout_info::in, stack_layout_info::out) is det.
-
-:- pred stack_layout__get_trace_stack_layout(bool::out,
-	stack_layout_info::in, stack_layout_info::out) is det.
-
-:- pred stack_layout__get_procid_stack_layout(bool::out,
-	stack_layout_info::in, stack_layout_info::out) is det.
-
-:- pred stack_layout__get_static_code_addresses(bool::out,
-	stack_layout_info::in, stack_layout_info::out) is det.
-
-:- pred stack_layout__get_table_infos(list(comp_gen_c_data)::out,
-	stack_layout_info::in, stack_layout_info::out) is det.
-
-:- pred stack_layout__get_proc_layout_data(list(comp_gen_c_data)::out,
-	stack_layout_info::in, stack_layout_info::out) is det.
-
-:- pred stack_layout__get_internal_layout_data(list(comp_gen_c_data)::out,
-	stack_layout_info::in, stack_layout_info::out) is det.
-
-:- pred stack_layout__get_label_set(map(label, data_addr)::out,
-	stack_layout_info::in, stack_layout_info::out) is det.
-
-:- pred stack_layout__get_string_table(string_table::out,
-	stack_layout_info::in, stack_layout_info::out) is det.
-
-:- pred stack_layout__get_label_tables(map(string, label_table)::out,
-	stack_layout_info::in, stack_layout_info::out) is det.
-
-:- pred stack_layout__get_static_cell_info(static_cell_info::out,
-	stack_layout_info::in, stack_layout_info::out) is det.
-
-stack_layout__get_module_info(LI ^ module_info, LI, LI).
-stack_layout__get_agc_stack_layout(LI ^ agc_stack_layout, LI, LI).
-stack_layout__get_trace_stack_layout(LI ^ trace_stack_layout, LI, LI).
-stack_layout__get_procid_stack_layout(LI ^ procid_stack_layout, LI, LI).
-stack_layout__get_static_code_addresses(LI ^ static_code_addresses, LI, LI).
-stack_layout__get_table_infos(LI ^ table_infos, LI, LI).
-stack_layout__get_proc_layout_data(LI ^ proc_layouts, LI, LI).
-stack_layout__get_internal_layout_data(LI ^ internal_layouts, LI, LI).
-stack_layout__get_label_set(LI ^ label_set, LI, LI).
-stack_layout__get_string_table(LI ^ string_table, LI, LI).
-stack_layout__get_label_tables(LI ^ label_tables, LI, LI).
-stack_layout__get_static_cell_info(LI ^ static_cell_info, LI, LI).
+:- pred stack_layout__get_module_info(stack_layout_info::in,
+	module_info::out) is det.
+:- pred stack_layout__get_agc_stack_layout(stack_layout_info::in,
+	bool::out) is det.
+:- pred stack_layout__get_trace_stack_layout(stack_layout_info::in,
+	bool::out) is det.
+:- pred stack_layout__get_procid_stack_layout(stack_layout_info::in,
+	bool::out) is det.
+:- pred stack_layout__get_static_code_addresses(stack_layout_info::in,
+	bool::out) is det.
+:- pred stack_layout__get_table_infos(stack_layout_info::in,
+	list(comp_gen_c_data)::out) is det.
+:- pred stack_layout__get_proc_layout_data(stack_layout_info::in,
+	list(comp_gen_c_data)::out) is det.
+:- pred stack_layout__get_internal_layout_data(stack_layout_info::in,
+	list(comp_gen_c_data)::out) is det.
+:- pred stack_layout__get_label_set(stack_layout_info::in,
+	map(label, data_addr)::out) is det.
+:- pred stack_layout__get_string_table(stack_layout_info::in,
+	string_table::out) is det.
+:- pred stack_layout__get_label_tables(stack_layout_info::in,
+	map(string, label_table)::out) is det.
+:- pred stack_layout__get_static_cell_info(stack_layout_info::in,
+	static_cell_info::out) is det.
+
+stack_layout__get_module_info(LI, LI ^ module_info).
+stack_layout__get_agc_stack_layout(LI, LI ^ agc_stack_layout).
+stack_layout__get_trace_stack_layout(LI, LI ^ trace_stack_layout).
+stack_layout__get_procid_stack_layout(LI, LI ^ procid_stack_layout).
+stack_layout__get_static_code_addresses(LI, LI ^ static_code_addresses).
+stack_layout__get_table_infos(LI, LI ^ table_infos).
+stack_layout__get_proc_layout_data(LI, LI ^ proc_layouts).
+stack_layout__get_internal_layout_data(LI, LI ^ internal_layouts).
+stack_layout__get_label_set(LI, LI ^ label_set).
+stack_layout__get_string_table(LI, LI ^ string_table).
+stack_layout__get_label_tables(LI, LI ^ label_tables).
+stack_layout__get_static_cell_info(LI, LI ^ static_cell_info).
+
+:- pred stack_layout__allocate_label_number(int::out,
+	stack_layout_info::in, stack_layout_info::out) is det.
+
+stack_layout__allocate_label_number(LabelNum, !LI) :-
+	Counter0 = !.LI ^ label_counter,
+	counter__allocate(LabelNum, Counter0, Counter),
+	!:LI = !.LI ^ label_counter := Counter.
 
 :- pred stack_layout__add_table_data(layout_data::in,
 	stack_layout_info::in, stack_layout_info::out) is det.
 
-stack_layout__add_table_data(TableIoDeclData, LI0, LI) :-
-	TableIoDecls0 = LI0 ^ table_infos,
+stack_layout__add_table_data(TableIoDeclData, !LI) :-
+	TableIoDecls0 = !.LI ^ table_infos,
 	TableIoDecls = [layout_data(TableIoDeclData) | TableIoDecls0],
-	LI = LI0 ^ table_infos := TableIoDecls.
+	!:LI = !.LI ^ table_infos := TableIoDecls.
 
 :- pred stack_layout__add_proc_layout_data(comp_gen_c_data::in,
 	layout_name::in, label::in,
 	stack_layout_info::in, stack_layout_info::out) is det.
 
-stack_layout__add_proc_layout_data(ProcLayout, ProcLayoutName, Label,
-		LI0, LI) :-
-	ProcLayouts0 = LI0 ^ proc_layouts,
+stack_layout__add_proc_layout_data(ProcLayout, ProcLayoutName, Label, !LI) :-
+	ProcLayouts0 = !.LI ^ proc_layouts,
 	ProcLayouts = [ProcLayout | ProcLayouts0],
-	LabelSet0 = LI0 ^ label_set,
+	LabelSet0 = !.LI ^ label_set,
 	map__det_insert(LabelSet0, Label, layout_addr(ProcLayoutName),
 		LabelSet),
-	ProcLayoutNames0 = LI0 ^ proc_layout_name_list,
+	ProcLayoutNames0 = !.LI ^ proc_layout_name_list,
 	ProcLayoutNames = [ProcLayoutName | ProcLayoutNames0],
-	LI = (((LI0 ^ proc_layouts := ProcLayouts)
+	!:LI = (((!.LI ^ proc_layouts := ProcLayouts)
 		^ label_set := LabelSet)
 		^ proc_layout_name_list := ProcLayoutNames).
 
@@ -1731,12 +1748,12 @@
 	stack_layout_info::out) is det.
 
 stack_layout__add_internal_layout_data(InternalLayout, Label, LayoutName,
-		LI0, LI) :-
-	InternalLayouts0 = LI0 ^ internal_layouts,
+		!LI) :-
+	InternalLayouts0 = !.LI ^ internal_layouts,
 	InternalLayouts = [InternalLayout | InternalLayouts0],
-	LabelSet0 = LI0 ^ label_set,
+	LabelSet0 = !.LI ^ label_set,
 	map__det_insert(LabelSet0, Label, layout_addr(LayoutName), LabelSet),
-	LI = ((LI0 ^ internal_layouts := InternalLayouts)
+	!:LI = ((!.LI ^ internal_layouts := InternalLayouts)
 		^ label_set := LabelSet).
 
 :- pred stack_layout__set_string_table(string_table::in,
@@ -1748,10 +1765,9 @@
 :- pred stack_layout__set_static_cell_info(static_cell_info::in,
 	stack_layout_info::in, stack_layout_info::out) is det.
 
-stack_layout__set_string_table(ST, LI0, LI0 ^ string_table := ST).
-stack_layout__set_label_tables(LT, LI0, LI0 ^ label_tables := LT).
-stack_layout__set_static_cell_info(SCI, LI0,
-	LI0 ^ static_cell_info := SCI).
+stack_layout__set_string_table(ST, LI, LI ^ string_table := ST).
+stack_layout__set_label_tables(LT, LI, LI ^ label_tables := LT).
+stack_layout__set_static_cell_info(SCI, LI, LI ^ static_cell_info := SCI).
 
 %---------------------------------------------------------------------------%
 
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
cvs diff: Diffing deep_profiler
cvs diff: Diffing deep_profiler/notes
cvs diff: Diffing doc
cvs diff: Diffing extras
cvs diff: Diffing extras/aditi
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/concurrency
cvs diff: Diffing extras/curs
cvs diff: Diffing extras/curs/samples
cvs diff: Diffing extras/curses
cvs diff: Diffing extras/curses/sample
cvs diff: Diffing extras/dynamic_linking
cvs diff: Diffing extras/error
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/mercury_glut
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/gears
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/lazy_evaluation
cvs diff: Diffing extras/lex
cvs diff: Diffing extras/lex/samples
cvs diff: Diffing extras/lex/tests
cvs diff: Diffing extras/logged_output
cvs diff: Diffing extras/moose
cvs diff: Diffing extras/moose/samples
cvs diff: Diffing extras/moose/tests
cvs diff: Diffing extras/morphine
cvs diff: Diffing extras/morphine/non-regression-tests
cvs diff: Diffing extras/morphine/scripts
cvs diff: Diffing extras/morphine/source
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/posix
cvs diff: Diffing extras/quickcheck
cvs diff: Diffing extras/quickcheck/tutes
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/stream
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing extras/xml
cvs diff: Diffing extras/xml/samples
cvs diff: Diffing java
cvs diff: Diffing java/runtime
cvs diff: Diffing library
Index: library/exception.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/exception.m,v
retrieving revision 1.94
diff -u -r1.94 exception.m
--- library/exception.m	3 Aug 2004 05:31:38 -0000	1.94
+++ library/exception.m	9 Aug 2004 13:41:57 -0000
@@ -1450,7 +1450,7 @@
 ** with an exception handler.  As we go, invoke either or both
 ** of two actions.
 **
-** (1) If MR_trace_enabled is set, then invoke
+** (1) If MR_debug_enabled is set, then invoke
 **     `MR_trace(..., MR_PORT_EXCEPTION, ...)' for each stack frame,
 **     to signal to the debugger that that procedure has exited via
 **     an exception.  This allows to user to use the `retry' command
@@ -1632,7 +1632,7 @@
 
   #endif
 
-  		if (MR_trace_enabled) {
+  		if (MR_debug_enabled) {
 			/*
 			** invoke MR_trace() to trace the exception
 			*/
@@ -2100,7 +2100,7 @@
 #ifdef	MR_DEEP_PROFILING
 	walk_stack = MR_TRUE;
 #else
-	walk_stack = MR_trace_enabled;
+	walk_stack = MR_debug_enabled;
 #endif
 
 	if (walk_stack) {
Index: library/io.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/io.m,v
retrieving revision 1.325
diff -u -r1.325 io.m
--- library/io.m	2 Aug 2004 08:30:16 -0000	1.325
+++ library/io.m	9 Aug 2004 13:45:45 -0000
@@ -4266,7 +4266,7 @@
 	[may_call_mercury, promise_pure, tabled_for_io, thread_safe,
 		terminates],
 "
-	MayDelete = !MR_trace_ever_enabled;
+	MayDelete = !MR_debug_ever_enabled;
 	IO = IO0;
 ").
 
Index: library/table_builtin.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/table_builtin.m,v
retrieving revision 1.41
diff -u -r1.41 table_builtin.m
--- library/table_builtin.m	3 Aug 2004 05:32:04 -0000	1.41
+++ library/table_builtin.m	9 Aug 2004 13:42:09 -0000
@@ -642,8 +642,8 @@
 
 	% Calls to these predicates bracket the code of foreign_procs with
 	% the tabled_for_io_unitize annotation. The left bracket procedure
-	% returns the current value of MR_trace_enabled, and then turns off
-	% both MR_trace_enabled and MR_io_tabling_enabled. (We don't need to
+	% returns the current value of MR_debug_enabled, and then turns off
+	% both MR_debug_enabled and MR_io_tabling_enabled. (We don't need to
 	% save MR_io_tabling_enabled because we only get to this code if it
 	% contains true.) The right bracket code takes the value returned by
 	% the left bracket as input and restores both globals to the values
cvs diff: Diffing profiler
cvs diff: Diffing robdd
cvs diff: Diffing runtime
Index: runtime/mercury_grade.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_grade.h,v
retrieving revision 1.55
diff -u -r1.55 mercury_grade.h
--- runtime/mercury_grade.h	20 Jul 2004 04:41:22 -0000	1.55
+++ runtime/mercury_grade.h	9 Aug 2004 09:05:59 -0000
@@ -60,7 +60,7 @@
 */
 
 #define MR_GRADE_PART_0	v13_
-#define MR_GRADE_EXEC_TRACE_VERSION_NO	1
+#define MR_GRADE_EXEC_TRACE_VERSION_NO	2
 #define MR_GRADE_DEEP_PROF_VERSION_NO	1
 
 #ifdef MR_HIGHLEVEL_CODE
Index: runtime/mercury_stack_layout.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_stack_layout.h,v
retrieving revision 1.84
diff -u -r1.84 mercury_stack_layout.h
--- runtime/mercury_stack_layout.h	20 Jul 2004 04:41:23 -0000	1.84
+++ runtime/mercury_stack_layout.h	10 Aug 2004 11:10:39 -0000
@@ -316,6 +316,15 @@
 ** structure for type variable i+1, since array offsets start at zero
 ** but type variable numbers start at one.
 **
+** The MR_sll_label_num_in_module is used for counting the number of times
+** the event of this label is executed. It gives the label's index in the
+** array pointed to by the module layout's MR_ml_label_exec_count field;
+** whenever the event of this label is executed, the element in that array
+** indicated by this index will be incremented (when MR_trace_count_enabled
+** is set). The array element at index zero is ignored. A label layout will
+** have zero in its MR_sll_label_num_in_module field if the label doesn't
+** corresponding to an event.
+**
 ** XXX: Presently, inst information is ignored; we assume that all live values
 ** are ground.
 */
@@ -329,6 +338,7 @@
 	const MR_Proc_Layout		*MR_sll_entry;
 	MR_int_least8_t			MR_sll_port;
 	MR_int_least8_t			MR_sll_hidden;
+	MR_uint_least16_t		MR_sll_label_num_in_module;
 	MR_uint_least32_t		MR_sll_goal_path;
 	MR_Integer			MR_sll_var_count; /* >= 0 */
 	const void			*MR_sll_locns_types;
@@ -340,6 +350,7 @@
 	const MR_Proc_Layout		*MR_sll_entry;
 	MR_int_least8_t			MR_sll_port;
 	MR_int_least8_t			MR_sll_hidden;
+	MR_uint_least16_t		MR_sll_label_num_in_module;
 	MR_uint_least32_t		MR_sll_goal_path;
 	MR_Integer			MR_sll_var_count; /* < 0 */
 } MR_Label_Layout_No_Var_Info;
@@ -403,6 +414,7 @@
 		-1,							\
 		MR_FALSE,						\
 		0,							\
+		0,							\
 		-1		/* No info about live values */		\
 	}
 
@@ -412,59 +424,59 @@
 ** the others are the fields of MR_Label_Layouts.
 */
 
-#define	MR_DEF_LL_GEN(e, ln, port, h, path, vc, lt, vn, tv)		\
+#define	MR_DEF_LL_GEN(e, ln, port, h, num, path, vc, lt, vn, tv)	\
 	static const MR_Label_Layout 					\
 		MR_LABEL_LAYOUT_NAME(MR_label_name(MR_add_prefix(e), ln)) \
 	= {								\
 		MR_PROC_LAYOUT(MR_add_prefix(e)),			\
 		MR_PASTE2(MR_PORT_, port),				\
-		(h), (path), (vc),					\
+		(h), (num), (path), (vc),				\
 		((const void *) lt),					\
 		((const MR_uint_least16_t *) vn),			\
 		((const MR_Type_Param_Locns *) tv)			\
 	}
 
-#define	MR_DEF_LLNVI_GEN(e, ln, port, h, path)				\
+#define	MR_DEF_LLNVI_GEN(e, ln, port, h, num, path)			\
 	static const MR_Label_Layout_No_Var_Info			\
 		MR_LABEL_LAYOUT_NAME(MR_label_name(MR_add_prefix(e), ln)) \
 	= {								\
 		MR_PROC_LAYOUT(MR_add_prefix(e)),			\
 		MR_PASTE2(MR_PORT_, port),				\
-		(h), (path), -1						\
+		(h), (path), (num), -1					\
 	}
 
-#define	MR_DEF_LL(e, ln, port, path, vc, lt, vn, tv)			\
-	MR_DEF_LL_GEN(e, ln, port, MR_FALSE, path, vc, lt, vn, tv)
+#define	MR_DEF_LL(e, ln, port, num, path, vc, lt, vn, tv)		\
+	MR_DEF_LL_GEN(e, ln, port, MR_FALSE, num, path, vc, lt, vn, tv)
 
-#define	MR_DEF_LLT(e, ln, port, path, vc, lt, vn, tv)			\
-	MR_DEF_LL_GEN(e, ln, port, MR_TRUE, path, vc, lt, vn, tv)
+#define	MR_DEF_LLT(e, ln, port, num, path, vc, lt, vn, tv)		\
+	MR_DEF_LL_GEN(e, ln, port, MR_TRUE, num, path, vc, lt, vn, tv)
 
-#define	MR_DEF_LLCCC(e, ln, port, path, vc, lt, vn, tv)		\
-	MR_DEF_LL_GEN(e, ln, port, MR_FALSE, path, vc,			\
+#define	MR_DEF_LLCCC(e, ln, port, num, path, vc, lt, vn, tv)		\
+	MR_DEF_LL_GEN(e, ln, port, MR_FALSE, num, path, vc,		\
 		&MR_PASTE2(mercury_common_, lt),			\
 		&MR_PASTE2(mercury_common_, vn),			\
 		&MR_PASTE2(mercury_common_, tv))
 
-#define	MR_DEF_LLCC0(e, ln, port, path, vc, lt, vn)			\
-	MR_DEF_LL_GEN(e, ln, port, MR_FALSE, path, vc,			\
+#define	MR_DEF_LLCC0(e, ln, port, num, path, vc, lt, vn)		\
+	MR_DEF_LL_GEN(e, ln, port, MR_FALSE, num, path, vc,		\
 		&MR_PASTE2(mercury_common_, lt),			\
 		&MR_PASTE2(mercury_common_, vn), 0)			\
 
-#define	MR_DEF_LLTCCC(e, ln, port, path, vc, lt, vn, tv)		\
-	MR_DEF_LL_GEN(e, ln, port, MR_TRUE, path, vc,			\
+#define	MR_DEF_LLTCCC(e, ln, port, num, path, vc, lt, vn, tv)		\
+	MR_DEF_LL_GEN(e, ln, port, MR_TRUE, num, path, vc,		\
 		&MR_PASTE2(mercury_common_, lt),			\
 		&MR_PASTE2(mercury_common_, vn),			\
 		&MR_PASTE2(mercury_common_, tv))
 
-#define	MR_DEF_LLTCC0(e, ln, port, path, vc, lt, vn)			\
-	MR_DEF_LL_GEN(e, ln, port, MR_TRUE, path, vc,			\
+#define	MR_DEF_LLTCC0(e, ln, port, num, path, vc, lt, vn)		\
+	MR_DEF_LL_GEN(e, ln, port, MR_TRUE, num, path, vc,		\
 		&MR_PASTE2(mercury_common_, lt),			\
 		&MR_PASTE2(mercury_common_, vn), 0)
 
-#define	MR_DEF_LLNVI(e, ln, port, path)					\
+#define	MR_DEF_LLNVI(e, ln, port, num, path)				\
 	MR_DEF_LLNVI_GEN(e, ln, port, MR_FALSE, path)
 
-#define	MR_DEF_LLNVIT(e, ln, port, path)				\
+#define	MR_DEF_LLNVIT(e, ln, port, num, path)				\
 	MR_DEF_LLNVI_GEN(e, ln, port, MR_TRUE, path)
 
 #define MR_DECL_LL(e, ln)						\
@@ -775,6 +787,7 @@
 	MR_int_least8_t		MR_exec_maybe_maxfr;
 	MR_EvalMethodInt	MR_exec_eval_method_CAST_ME;
 	MR_int_least8_t		MR_exec_maybe_call_table;
+	const MR_Label_Layout	**MR_exec_label_layout;
 } MR_Exec_Trace;
 
 #define MR_compute_max_mr_num(max_mr_num, layout)			\
@@ -1113,8 +1126,21 @@
 **
 ** The MR_ml_suppressed_events events field encodes the set of event types
 ** (ports) that were suppressed when generating code for this module. The bit
-** given by the expression (1 << MR_PORT_XXX) will be set in this integer
-** iff trace port MR_PORT_XXX is suppressed.
+** given by the expression (1 << MR_PORT_<PORTTYPE>) will be set in this
+** integer iff trace port MR_PORT_<PORTTYPE> is suppressed.
+**
+** The MR_ml_label_exec_count field points to an array of integers, with each
+** integer holding the number of times execution has reached a given label.
+** Each label's layout structure records the index of that label in this array.
+** To most direct way to go the other way, to find out which label owns a
+** particular slot in this array, is to search the label arrays in the file
+** layout structures, and test their MR_sll_label_num_in_module fields.
+** (If we needed faster access, we could add another array with elements
+** corresponding to MR_ml_label_exec_count's pointing to the labels' layout
+** structures.)
+**
+** The MR_ml_num_label_exec_counts field contains the number of elements
+** in the MR_ml_label_exec_count array.
 */
 
 typedef enum {
@@ -1142,6 +1168,8 @@
 	const MR_Module_File_Layout	**MR_ml_module_file_layout;
 	MR_Trace_Level			MR_ml_trace_level;
 	MR_int_least32_t		MR_ml_suppressed_events;
+	MR_int_least32_t		MR_ml_num_label_exec_counts;
+	MR_Unsigned			*MR_ml_label_exec_count;
 };
 
 /*-------------------------------------------------------------------------*/
Index: runtime/mercury_tabling_preds.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_tabling_preds.h,v
retrieving revision 1.3
diff -u -r1.3 mercury_tabling_preds.h
--- runtime/mercury_tabling_preds.h	20 Jul 2004 04:41:25 -0000	1.3
+++ runtime/mercury_tabling_preds.h	9 Aug 2004 13:43:54 -0000
@@ -587,8 +587,9 @@
 
 #define MR_table_io_left_bracket_unitized_goal(TraceEnabled)            \
     do {                                                                \
-        TraceEnabled = MR_trace_enabled;                                \
-        MR_trace_enabled = MR_FALSE;                                    \
+        TraceEnabled = MR_debug_enabled;                                \
+        MR_debug_enabled = MR_FALSE;                                    \
+        MR_update_trace_func_enabled();                                 \
         MR_io_tabling_enabled = MR_FALSE;                               \
     } while(0)
 
@@ -597,7 +598,8 @@
 #define MR_table_io_right_bracket_unitized_goal(TraceEnabled)           \
     do {                                                                \
         MR_io_tabling_enabled = MR_TRUE;                                \
-        MR_trace_enabled = TraceEnabled;                                \
+        MR_debug_enabled = TraceEnabled;                                \
+        MR_update_trace_func_enabled();                                 \
     } while(0)
 
 /***********************************************************************/
Index: runtime/mercury_trace_base.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_trace_base.c,v
retrieving revision 1.57
diff -u -r1.57 mercury_trace_base.c
--- runtime/mercury_trace_base.c	19 May 2004 03:59:52 -0000	1.57
+++ runtime/mercury_trace_base.c	10 Aug 2004 11:10:57 -0000
@@ -27,6 +27,7 @@
 #include "mercury_runtime_util.h"	/* for strerror() on some systems */
 #include "mercury_signal.h"		/* for MR_setup_signal() */
 #include "mercury_builtin_types.h"	/* for type_ctor_infos */
+#include "mercury_array_macros.h"	/* for type_ctor_infos */
 #include <signal.h>			/* for SIGINT */
 #include <stdio.h>
 #include <errno.h>
@@ -41,8 +42,11 @@
 
 void		(*MR_trace_shutdown)(void) = NULL;
 
-MR_bool		MR_trace_enabled = MR_FALSE;
-MR_bool		MR_trace_ever_enabled = MR_FALSE;
+MR_bool		MR_debug_ever_enabled = MR_FALSE;
+MR_bool		MR_debug_enabled = MR_FALSE;
+MR_bool		MR_trace_count_enabled = MR_FALSE;
+MR_bool		MR_trace_func_enabled = MR_FALSE;
+MR_Code		*(*MR_selected_trace_func_ptr)(const MR_Label_Layout *);
 MR_Unsigned	MR_trace_call_seqno = 0;
 MR_Unsigned	MR_trace_call_depth = 0;
 MR_Unsigned	MR_trace_event_number = 0;
@@ -116,11 +120,11 @@
 MR_Code *
 MR_trace(const MR_Label_Layout *layout)
 {
-	if (! MR_trace_enabled) {
+	if (! MR_trace_func_enabled) {
 		return NULL;
 	}
 
-	return (*MR_trace_func_ptr)(layout);
+	return (*MR_selected_trace_func_ptr)(layout);
 }
 
 void
@@ -146,6 +150,122 @@
 	return NULL;
 }
 
+MR_Code *
+MR_trace_count(const MR_Label_Layout *label_layout)
+{
+	const MR_Module_Layout	*module_layout;
+	const MR_Proc_Layout	*proc_layout;
+	MR_uint_least16_t	label_number;
+
+	proc_layout = label_layout->MR_sll_entry;
+	if (! MR_PROC_LAYOUT_HAS_EXEC_TRACE(proc_layout)) {
+		MR_fatal_error("MR_trace_count: no exec trace");
+	}
+
+	module_layout = proc_layout->MR_sle_module_layout;
+	label_number = label_layout->MR_sll_label_num_in_module;
+	if (label_number >= module_layout->MR_ml_num_label_exec_counts) {
+		MR_fatal_error("MR_trace_count: invalid label number");
+	}
+	++module_layout->MR_ml_label_exec_count[label_number];
+	return NULL;
+}
+
+#define	INIT_MODULE_TABLE_SIZE	10
+
+const MR_Module_Layout	**MR_module_infos;
+int			MR_module_info_next = 0;
+int			MR_module_info_max  = 0;
+
+void
+MR_insert_module_info_into_module_table(const MR_Module_Layout *module)
+{
+	int		slot;
+
+	MR_GC_ensure_room_for_next(MR_module_info, const MR_Module_Layout *,
+		INIT_MODULE_TABLE_SIZE);
+	MR_prepare_insert_into_sorted(MR_module_infos, MR_module_info_next,
+		slot,
+		strcmp(MR_module_infos[slot]->MR_ml_name, module->MR_ml_name));
+
+	MR_module_infos[slot] = module;
+}
+
+static void
+MR_write_count_proc_id(FILE *fp, const MR_User_Proc_Id *id)
+{
+	fprintf(fp, "proc %c %s %s %d %d\n",
+		( id->MR_user_pred_or_func == MR_PREDICATE ? 'p' : 'f'),
+		id->MR_user_decl_module,
+		id->MR_user_name,
+		id->MR_user_arity,
+		id->MR_user_mode);
+}
+
+void
+MR_trace_write_label_exec_counts(FILE *fp)
+{
+	const MR_Module_Layout		*module;
+	const MR_Module_File_Layout	*file;
+	const MR_Label_Layout		*label;
+	const MR_Proc_Layout		*prev_proc;
+	const MR_Proc_Layout		*proc;
+	const MR_User_Proc_Id		*id;
+	MR_Trace_Port			port;
+	int				num_modules;
+	int				num_files;
+	int				num_labels;
+	int				module_num;
+	int				file_num;
+	int				label_num;
+	int				label_index;
+	MR_Unsigned			exec_count;
+
+	prev_proc = NULL;
+	num_modules = MR_module_info_next;
+	for (module_num = 0; module_num < num_modules; module_num++) {
+		module = MR_module_infos[module_num];
+		num_files = module->MR_ml_filename_count;
+
+		for (file_num = 0; file_num < num_files; file_num++) {
+			file = module->MR_ml_module_file_layout[file_num];
+			num_labels = file->MR_mfl_label_count;
+			for (label_num = 0; label_num < num_labels;
+				label_num++)
+			{
+				label = file->MR_mfl_label_layout[label_num];
+				proc = label->MR_sll_entry;
+				label_index =
+					label->MR_sll_label_num_in_module;
+				exec_count = module->MR_ml_label_exec_count[
+					label_index];
+				if (! MR_PROC_LAYOUT_IS_UCI(proc) &&
+					exec_count > 0 && label_index > 0)
+				{
+					id = &proc->MR_sle_user;
+					if (proc != prev_proc) {
+						MR_write_count_proc_id(fp, id);
+					}
+
+					port = label->MR_sll_port;
+					if (port <= MR_PORT_FAIL) {
+						fprintf(fp, "%s %u\n",
+							MR_port_names[port],
+							exec_count);
+					} else {
+						fprintf(fp, "<%s> %u\n",
+							MR_label_goal_path(
+								label),
+							exec_count);
+					}
+
+					prev_proc = proc;
+				}
+			}
+		}
+	}
+}
+
 #ifdef	MR_TABLE_DEBUG
 MR_bool	MR_saved_tabledebug;
 #endif
@@ -202,7 +322,8 @@
 	MR_trace_call_seqno = 0;
 	MR_trace_call_depth = 0;
 	MR_trace_from_full = MR_TRUE;
-	MR_trace_enabled = enabled;
+	MR_debug_enabled = enabled;
+	MR_update_trace_func_enabled();
 
 #ifdef	MR_TABLE_DEBUG
 	/*
@@ -232,7 +353,8 @@
 void
 MR_trace_end(void)
 {
-	MR_trace_enabled = MR_FALSE;
+	MR_debug_enabled = MR_FALSE;
+	MR_update_trace_func_enabled();
 }
 
 #define MR_STANDARD_HASH_TABLE_SIZE 1024
@@ -471,9 +593,10 @@
 {
 	int	i;
 
-	saved_state->MR_sds_trace_enabled = MR_trace_enabled;
+	saved_state->MR_sds_debug_enabled = MR_debug_enabled;
 	saved_state->MR_sds_io_tabling_enabled = MR_io_tabling_enabled;
-	MR_trace_enabled = MR_FALSE;
+	MR_debug_enabled = MR_FALSE;
+	MR_update_trace_func_enabled();
 	MR_io_tabling_enabled = MR_FALSE;
 
 	for (i = 0; i < MR_MAXFLAG ; i++) {
@@ -492,7 +615,8 @@
 {
 	int	i;
 
-	MR_trace_enabled = saved_state->MR_sds_trace_enabled;
+	MR_debug_enabled = saved_state->MR_sds_debug_enabled;
+	MR_update_trace_func_enabled();
 	MR_io_tabling_enabled = saved_state->MR_sds_io_tabling_enabled;
 
 	for (i = 0; i < MR_MAXFLAG ; i++) {
Index: runtime/mercury_trace_base.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_trace_base.h,v
retrieving revision 1.40
diff -u -r1.40 mercury_trace_base.h
--- runtime/mercury_trace_base.h	1 Apr 2004 04:51:06 -0000	1.40
+++ runtime/mercury_trace_base.h	10 Aug 2004 11:04:40 -0000
@@ -76,7 +76,8 @@
 ** If the event is supposed to be traced, it performs an indirect call
 ** through MR_trace_func_ptr, which will point either to MR_trace_real,
 ** which is defined in the trace library, or to MR_trace_fake, defined here,
-** which just prints an error message and aborts.
+** which just prints an error message and aborts, or to MR_trace_count, also
+** defined here, which counts the execution of the event.
 **
 ** The return value, if not NULL, says where execution should continue
 ** after the event. (NULL means it should continue as usual.)
@@ -84,6 +85,29 @@
 
 extern	MR_Code	*MR_trace(const MR_Label_Layout *);
 extern	MR_Code	*MR_trace_fake(const MR_Label_Layout *);
+extern	MR_Code	*MR_trace_count(const MR_Label_Layout *);
+
+/*
+** These three variables implement a table of module layout structures,
+** sorted on module name, maintained by the macros in mercury_array_macros.h.
+**
+** Insertions are handled by MR_insert_module_info_into_module_table.
+*/
+
+extern	const MR_Module_Layout	**MR_module_infos;
+extern	int			MR_module_info_next;
+extern	int			MR_module_info_max;
+
+extern	void	MR_insert_module_info_into_module_table(
+			const MR_Module_Layout *module_layout);
+
+/*
+** For every label reachable from the module table, write the id of the label
+** and the number of times it has been executed to the specified file, with the
+** exception of labels that haven't been executed.
+*/
+
+extern	void	MR_trace_write_label_exec_counts(FILE *fp);
 
 /*
 ** MR_trace_init() is called from mercury_runtime_init()
@@ -124,14 +148,12 @@
 */
 
 /*
-** Compiler generated tracing code will check whether MR_trace_enabled is true,
-** before calling MR_trace.
-**
-** MR_trace_enabled should keep the same value throughout the execution of
-** the entire program after being set in mercury_wrapper.c, with two
-** exceptions. First, the Mercury routines called as part of the functionality
+** MR_debug_enabled says whether debugging of the program is enabled.
+** It should keep the same value throughout the execution of the entire
+** program after being set in mercury_wrapper.c, with two exceptions.
+** First, the Mercury routines called as part of the functionality
 ** of the tracer itself (e.g. the term browser) should always be executed
-** with MR_trace_enabled set to MR_FALSE. Second, when a procedure has
+** with MR_debug_enabled set to MR_FALSE. Second, when a procedure has
 ** the tabled_for_io_unitize annotation, which means that it can both do I/O
 ** and call Mercury code, then we turn the procedure and its descendants
 ** into a single unit by turning off tracing within the descendants.
@@ -139,16 +161,56 @@
 ** arise if we got retries from within the descendants.
 */
 
-extern	MR_bool		MR_trace_enabled;
+extern	MR_bool		MR_debug_enabled;
 
 /*
-** MR_trace_ever_enabled will keep the same value throughout the execution of
+** MR_debug_ever_enabled will keep the same value throughout the execution of
 ** the entire program after being set in mercury_wrapper.c to the same value
-** as MR_trace_enabled. Unlike MR_trace_enabled, it is never reset, so one can
+** as MR_debug_enabled. Unlike MR_debug_enabled, it is never reset, so one can
 ** use its value to test whether tracing was ever enabled.
 */
 
-extern	MR_bool		MR_trace_ever_enabled;
+extern	MR_bool		MR_debug_ever_enabled;
+
+/*
+** MR_trace_count_enabled will keep the same value throughout the execution of
+** the entire program after being set in mercury_wrapper.c to the same value
+** as MR_debug_enabled. Unlike MR_debug_enabled, it is never reset, so one can
+** use its value to test whether tracing was ever enabled.
+*/
+
+extern	MR_bool		MR_trace_count_enabled;
+
+/*
+** MR_trace checks whether MR_trace_func_enabled is true, and return
+** immediately if it is not.
+**
+** MR_trace_func_enabled should be updated whenever either of the variables
+** it depends on is updated. The reason why we require this is that
+** MR_trace_func_enabled is read many times, but MR_debug_enabled and
+** MR_trace_count_enabled are updated only infrequently.
+**
+** Usually, MR_trace_func_enabled should be updated with the macro below.
+** However, MR_debug_enabled and MR_trace_count_enabled can never be set
+** simultaneously, and in places where performance is important, the update
+** of MR_trace_func_enabled can exploit this.
+*/
+
+extern	MR_bool		MR_trace_func_enabled;
+
+#define	MR_update_trace_func_enabled()				\
+	do {							\
+		MR_trace_func_enabled = 			\
+			MR_debug_enabled || MR_trace_count_enabled; \
+	} while (0)
+
+/*
+** MR_selected_trace_func_ptr contains the address of the function to call
+** in MR_trace if MR_trace_func_enabled is true.
+*/
+
+extern	MR_Code *(*MR_selected_trace_func_ptr)(const MR_Label_Layout *);
+
 
 /*
 ** MR_trace_call_seqno counts distinct calls. The prologue of every
@@ -352,7 +414,7 @@
 */
 
 typedef struct {
-	MR_bool		MR_sds_trace_enabled;
+	MR_bool		MR_sds_debug_enabled;
 	MR_bool		MR_sds_io_tabling_enabled;
 	MR_bool		MR_sds_debugflags[MR_MAXFLAG];
 	MR_bool		MR_sds_include_counter_vars;
Index: runtime/mercury_wrapper.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_wrapper.c,v
retrieving revision 1.135
diff -u -r1.135 mercury_wrapper.c
--- runtime/mercury_wrapper.c	20 Jul 2004 04:41:25 -0000	1.135
+++ runtime/mercury_wrapper.c	10 Aug 2004 10:37:51 -0000
@@ -412,7 +412,8 @@
 void
 mercury_runtime_init(int argc, char **argv)
 {
-	MR_bool	saved_trace_enabled;
+	MR_bool	saved_debug_enabled;
+	MR_bool	saved_trace_count_enabled;
 
 #if MR_NUM_REAL_REGS > 0
 	MR_Word c_regs[MR_NUM_REAL_REGS];
@@ -487,8 +488,11 @@
 	** tracing until the end of this function.
 	*/
 
-	saved_trace_enabled = MR_trace_enabled;
-	MR_trace_enabled = MR_FALSE;
+	saved_debug_enabled = MR_debug_enabled;
+	saved_trace_count_enabled = MR_trace_count_enabled;
+	MR_debug_enabled = MR_FALSE;
+	MR_trace_count_enabled = MR_FALSE;
+	MR_update_trace_func_enabled();
 
 #ifdef MR_NEED_INITIALIZATION_AT_START
 	MR_do_init_modules();
@@ -580,7 +584,20 @@
 	** Now the real tracing starts; undo any updates to the trace state
 	** made by the trace code in the library initializer.
 	*/
-	MR_trace_start(saved_trace_enabled);
+	MR_debug_enabled = saved_debug_enabled;
+	MR_trace_count_enabled = saved_trace_count_enabled;
+	MR_update_trace_func_enabled();
+	MR_trace_start(MR_debug_enabled);
+
+	if (MR_debug_enabled) {
+		MR_selected_trace_func_ptr = MR_trace_func_ptr;
+		/* MR_debug_enabled overrides MR_trace_count_enabled */
+		MR_trace_count_enabled = MR_FALSE;
+	} else if (MR_trace_count_enabled) {
+		MR_register_module_layout =
+			MR_insert_module_info_into_module_table;
+		MR_selected_trace_func_ptr = MR_trace_count;
+	}
 
 	/*
 	** Restore the callee-save registers before returning,
@@ -928,7 +945,8 @@
 	MR_NUM_OUTPUT_ARGS,
 	MR_DEBUG_THREADS_OPT,
 	MR_DEEP_PROF_DEBUG_FILE_OPT,
-	MR_TABLING_STATISTICS_OPT
+	MR_TABLING_STATISTICS_OPT,
+	MR_TRACE_COUNT_OPT
 };
 
 struct MR_option MR_long_opts[] = {
@@ -957,7 +975,8 @@
 	{ "num-output-args", 		1, 0, MR_NUM_OUTPUT_ARGS },
 	{ "debug-threads",		0, 0, MR_DEBUG_THREADS_OPT },
 	{ "deep-debug-file",		0, 0, MR_DEEP_PROF_DEBUG_FILE_OPT },
-	{ "tabling-statistics",		0, 0, MR_TABLING_STATISTICS_OPT }
+	{ "tabling-statistics",		0, 0, MR_TABLING_STATISTICS_OPT },
+	{ "trace-count",		0, 0, MR_TRACE_COUNT_OPT }
 };
 
 static void
@@ -1147,6 +1166,10 @@
 			MR_print_table_statistics = MR_TRUE;
 			break;
 
+		case MR_TRACE_COUNT_OPT:
+			MR_trace_count_enabled = MR_TRUE;
+			break;
+
 		case 'a':
 			benchmark_all_solns = MR_TRUE;
 			break;
@@ -1283,8 +1306,8 @@
 			break;
 
 		case 'D':
-			MR_trace_enabled = MR_TRUE;
-			MR_trace_ever_enabled = MR_TRUE;
+			MR_debug_enabled = MR_TRUE;
+			MR_debug_ever_enabled = MR_TRUE;
 
 			if (MR_streq(MR_optarg, "i"))
 				MR_trace_handler = MR_TRACE_INTERNAL;
@@ -1292,7 +1315,6 @@
 			else if (MR_streq(MR_optarg, "e"))
 				MR_trace_handler = MR_TRACE_EXTERNAL;
 #endif
-
 			else
 				usage();
 
@@ -1875,6 +1897,8 @@
 
 /*---------------------------------------------------------------------------*/
 
+#define	MERCURY_TRACE_COUNTS_FILE_NAME	".mercury_trace_counts"
+
 int
 mercury_runtime_terminate(void)
 {
@@ -1900,6 +1924,21 @@
 	MR_restore_registers(); 
 
 	MR_trace_final();
+
+	if (MR_trace_count_enabled) {
+		FILE	*fp;
+
+		fp = fopen(MERCURY_TRACE_COUNTS_FILE_NAME, "w");
+		if (fp != NULL) {
+			MR_do_init_modules_debugger();
+			MR_trace_write_label_exec_counts(fp);
+			(void) fclose(fp);
+		} else {
+			fprintf(stderr, "%s: %s\n",
+				MERCURY_TRACE_COUNTS_FILE_NAME,
+				strerror(errno));
+		}
+	}
 
 #if defined(MR_MPROF_PROFILE_TIME) || defined(MR_MPROF_PROFILE_CALLS) \
 		|| defined(MR_MPROF_PROFILE_MEMORY)
cvs diff: Diffing runtime/GETOPT
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing samples/solutions
cvs diff: Diffing samples/tests
cvs diff: Diffing samples/tests/c_interface
cvs diff: Diffing samples/tests/c_interface/c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/tests/c_interface/mercury_calls_c
cvs diff: Diffing samples/tests/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/tests/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/tests/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/tests/diff
cvs diff: Diffing samples/tests/muz
cvs diff: Diffing samples/tests/rot13
cvs diff: Diffing samples/tests/solutions
cvs diff: Diffing samples/tests/toplevel
cvs diff: Diffing scripts
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
cvs diff: Diffing tests/debugger/declarative
cvs diff: Diffing tests/dppd
cvs diff: Diffing tests/general
cvs diff: Diffing tests/general/accumulator
cvs diff: Diffing tests/general/string_format
cvs diff: Diffing tests/general/structure_reuse
cvs diff: Diffing tests/grade_subdirs
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/exceptions
cvs diff: Diffing tests/hard_coded/purity
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/invalid/purity
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/mmc_make
cvs diff: Diffing tests/mmc_make/lib
cvs diff: Diffing tests/recompilation
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
Index: tools/bootcheck
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/tools/bootcheck,v
retrieving revision 1.161
diff -u -r1.161 bootcheck
--- tools/bootcheck	20 Jul 2004 04:41:46 -0000	1.161
+++ tools/bootcheck	9 Aug 2004 14:50:38 -0000
@@ -116,6 +116,9 @@
 		be put into TYPE_STATS_FILE_NAME.tests.$$. Both filenames will
 		be reported in the output of bootcheck, to allow the statistics
 		files to be matched with the bootcheck that created them.
+	--trace-count
+		Collect counts of the number of times each label is executed
+		in modules compiled with debugging.
 	-W, --windows
 		Translate paths into the Microsoft Windows format and use the
 		extension \`.lib' for libraries. This option also implies
@@ -177,6 +180,7 @@
 compile_times=false
 write_out_profile_data=true
 type_stats=""
+trace_count=false
 disable_debug_libs=false
 delete_deep_data=true
 
@@ -320,6 +324,9 @@
 	--type-stats)
 		type_stats="$2"; shift ;;
 
+	--trace-count)
+		trace_count=true ;;
+
 	-W|--windows)
 		windows=true; use_cp=true; A=lib ;;
 
@@ -499,6 +506,14 @@
 		# of *huge* amounts of stuff on stderr.
 		MERCURY_OPTIONS="$MERCURY_OPTIONS -s"
 		export MERCURY_OPTIONS
+	fi
+
+	if $trace_count
+	then
+		MERCURY_OPTIONS="$MERCURY_OPTIONS --trace-count"
+		export MERCURY_OPTIONS
+	else
+		true
 	fi
 
 	MERCURY_COMPILER=$root/compiler/mercury_compile
cvs diff: Diffing trace
Index: trace/mercury_trace_declarative.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/trace/mercury_trace_declarative.c,v
retrieving revision 1.69
diff -u -r1.69 mercury_trace_declarative.c
--- trace/mercury_trace_declarative.c	7 Jul 2004 07:11:22 -0000	1.69
+++ trace/mercury_trace_declarative.c	9 Aug 2004 13:40:19 -0000
@@ -316,7 +316,8 @@
 	event_details.MR_call_depth = MR_trace_call_depth;
 	event_details.MR_event_number = MR_trace_event_number;
 
-	MR_trace_enabled = MR_FALSE;
+	MR_debug_enabled = MR_FALSE;
+	MR_update_trace_func_enabled();
 	MR_decl_checkpoint_event(event_info);
 	trace = MR_trace_current_node;
 	switch (event_info->MR_trace_port) {
@@ -384,7 +385,8 @@
 				event_info, &event_details);
 	}
 
-	MR_trace_enabled = MR_TRUE;
+	MR_debug_enabled = MR_TRUE;
+	MR_update_trace_func_enabled();
 	return NULL;
 }
 
@@ -1139,7 +1141,8 @@
 		fflush(MR_mdb_out);
 		fprintf(MR_mdb_err, "mdb: diagnosis aborted:\n%s\n", message);
 		MR_trace_decl_mode = MR_TRACE_INTERACTIVE;
-		MR_trace_enabled = MR_TRUE;
+		MR_debug_enabled = MR_TRUE;
+		MR_update_trace_func_enabled();
 		return MR_trace_event_internal(cmd, MR_TRUE, event_info);
 	}
 
@@ -1201,7 +1204,8 @@
 	cmd->MR_trace_print_level = MR_PRINT_LEVEL_NONE;
 	cmd->MR_trace_must_check = MR_FALSE;
 
-	MR_trace_enabled = MR_TRUE;
+	MR_debug_enabled = MR_TRUE;
+	MR_update_trace_func_enabled();
 	return NULL;
 }
 
@@ -1248,7 +1252,8 @@
 
 		fclose(MR_trace_store_file);
 		MR_trace_decl_mode = MR_TRACE_INTERACTIVE;
-		MR_trace_enabled = MR_TRUE;
+		MR_debug_enabled = MR_TRUE;
+		MR_update_trace_func_enabled();
 		MR_trace_call_seqno = event_details->MR_call_seqno;
 		MR_trace_call_depth = event_details->MR_call_depth;
 		MR_trace_event_number = event_details->MR_event_number;
@@ -1260,7 +1265,8 @@
 		/*
 		** This is a quick and dirty way to debug the front end.
 		*/
-		MR_trace_enabled = MR_TRUE;
+		MR_debug_enabled = MR_TRUE;
+		MR_update_trace_func_enabled();
 		MR_trace_decl_mode = MR_TRACE_INTERACTIVE;
 	}
 
@@ -1317,7 +1323,8 @@
 		** current event, which was the event it was left from.
 		*/
 		MR_trace_decl_mode = MR_TRACE_INTERACTIVE;
-		MR_trace_enabled = MR_TRUE;
+		MR_debug_enabled = MR_TRUE;
+		MR_update_trace_func_enabled();
 		return MR_trace_event_internal(cmd, MR_TRUE, event_info);
 	}
 
@@ -1370,7 +1377,8 @@
 			fprintf(MR_mdb_err, "direct retry impossible\n");
 		}
 		MR_trace_decl_mode = MR_TRACE_INTERACTIVE;
-		MR_trace_enabled = MR_TRUE;
+		MR_debug_enabled = MR_TRUE;
+		MR_update_trace_func_enabled();
 		return MR_trace_event_internal(cmd, MR_TRUE, event_info);
 	}
 
@@ -1380,7 +1388,8 @@
 	cmd->MR_trace_strict = MR_TRUE;
 	cmd->MR_trace_must_check = MR_FALSE;
 	MR_trace_decl_mode = MR_TRACE_INTERACTIVE;
-	MR_trace_enabled = MR_TRUE;
+	MR_debug_enabled = MR_TRUE;
+	MR_update_trace_func_enabled();
 	return jumpaddr;
 }
 
Index: trace/mercury_trace_external.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/trace/mercury_trace_external.c,v
retrieving revision 1.75
diff -u -r1.75 mercury_trace_external.c
--- trace/mercury_trace_external.c	23 May 2004 22:16:56 -0000	1.75
+++ trace/mercury_trace_external.c	10 Aug 2004 10:36:57 -0000
@@ -477,11 +477,11 @@
 MR_Code *
 MR_trace_event_external(MR_Trace_Cmd_Info *cmd, MR_Event_Info *event_info)
 {
-	static MR_Word	search_data;
-	static void	(*initialize_ptr)(MR_Word *);
-	static void	(*get_collect_var_type_ptr)(MR_Word *);
+	static MR_Word		search_data;
+	static void		(*initialize_ptr)(MR_Word *);
+	static void		(*get_collect_var_type_ptr)(MR_Word *);
 	static MR_bool    	collect_linked = MR_FALSE;
-	MR_bool    	stop_collecting = MR_FALSE;
+	MR_bool    		stop_collecting = MR_FALSE;
 	MR_Integer		debugger_request_type;
 	MR_Word			debugger_request;
 	MR_Word			var_list;
@@ -504,7 +504,8 @@
 	static MR_String	MR_object_file_name;
 	int			lineno = 0;
 
-	MR_trace_enabled = MR_FALSE;
+	MR_debug_enabled = MR_FALSE;
+	MR_update_trace_func_enabled();
 
 	/*
 	** These globals can be overwritten when we call Mercury code,
@@ -915,7 +916,8 @@
 	MR_trace_call_depth = event_details.MR_call_depth;
 	MR_trace_event_number = event_details.MR_event_number;
 
-	MR_trace_enabled = MR_TRUE;
+	MR_debug_enabled = MR_TRUE;
+	MR_update_trace_func_enabled();
 
 	return jumpaddr;
 }
Index: trace/mercury_trace_tables.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/trace/mercury_trace_tables.c,v
retrieving revision 1.28
diff -u -r1.28 mercury_trace_tables.c
--- trace/mercury_trace_tables.c	23 May 2004 22:16:56 -0000	1.28
+++ trace/mercury_trace_tables.c	9 Aug 2004 11:30:24 -0000
@@ -40,10 +40,6 @@
 				/* the list entries are MR_Module_Layouts */
 } MR_Module_Nick;
 
-static	const MR_Module_Layout	**MR_module_infos;
-static	int			MR_module_info_next = 0;
-static	int			MR_module_info_max  = 0;
-
 static	MR_Module_Nick		*MR_module_nicks;
 static	int			MR_module_nick_next = 0;
 static	int			MR_module_nick_max  = 0;
@@ -191,13 +187,8 @@
 	MR_bool		found;
 	const char	*nickname;
 
-	MR_GC_ensure_room_for_next(MR_module_info, const MR_Module_Layout *,
-		INIT_MODULE_TABLE_SIZE);
-	MR_prepare_insert_into_sorted(MR_module_infos, MR_module_info_next,
-		slot,
-		strcmp(MR_module_infos[slot]->MR_ml_name, module->MR_ml_name));
+	MR_insert_module_info_into_module_table(module);
 
-	MR_module_infos[slot] = module;
 	MR_module_info_proc_count += module->MR_ml_proc_count;
 
 	nickname = strchr(module->MR_ml_name, '.');
Index: trace/mercury_trace_vars.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/trace/mercury_trace_vars.c,v
retrieving revision 1.58
diff -u -r1.58 mercury_trace_vars.c
--- trace/mercury_trace_vars.c	19 Jul 2004 03:37:55 -0000	1.58
+++ trace/mercury_trace_vars.c	10 Aug 2004 10:38:36 -0000
@@ -1486,13 +1486,14 @@
     int             level;
     const char      *problem;
     char            buf[MR_INTEGRITY_ERROR_BUF_SIZE];
-    MR_bool         saved_trace_enabled;
+    MR_bool         saved_debug_enabled;
     int             MR_check_max_mr_num;
     MR_Word         MR_check_saved_regs[MR_MAX_FAKE_REG];
     static  int     MR_check_integrity_seq_num = 0;
 
-    saved_trace_enabled = MR_trace_enabled;
-    MR_trace_enabled = MR_FALSE;
+    saved_debug_enabled = MR_debug_enabled;
+    MR_debug_enabled = MR_FALSE;
+    MR_update_trace_func_enabled();
 
     MR_compute_max_mr_num(MR_check_max_mr_num, layout);
     MR_restore_transient_registers();
@@ -1524,7 +1525,8 @@
     MR_saved_global_hp(MR_check_saved_regs) = MR_global_hp;
     MR_copy_saved_regs_to_regs(MR_check_max_mr_num, MR_check_saved_regs);
     MR_trace_report_msg = NULL;
-    MR_trace_enabled = saved_trace_enabled;
+    MR_debug_enabled = saved_debug_enabled;
+    MR_update_trace_func_enabled();
 }
 
 #endif  /* MR_TRACE_CHECK_INTEGRITY */
cvs diff: Diffing util
cvs diff: Diffing vim
cvs diff: Diffing vim/after
cvs diff: Diffing vim/ftplugin
cvs diff: Diffing vim/syntax
--------------------------------------------------------------------------
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