[m-dev.] for review: bootstrap hlc.gc.memprof grade
Peter Ross
peter.ross at miscrit.be
Tue Aug 1 21:06:55 AEST 2000
Hi,
For Fergus or Zoltan to review.
===================================================================
Estimated hours taken: 16
Bootstrap in the grade hlc.gc.memprof.
This change generates the correct output for the flat profile, but not
for the call graph profile.
To analyse the generated Prof.* files you need to supply the option
--no-demangle to the profiler.
compiler/ml_code_gen.m:
Define MR_PROC_LABEL in pragma c_code.
compiler/mlds.m:
Add a new alternative to the type target_code_component which
records a mlds_entity_name. This information is needed when
outputing the MR_PROC_LABEL #define.
compiler/ml_elim_nested.m:
Changes due to the change to the type target_code_component.
compiler/mlds_to_c.m:
#include mercury_imp.h at the start of the src module so that all
the definitions for profiling are available.
Define a new predicate mlds_output_init_fn which outputs the
initialisation function. This body of the initialisation function
consists of calls to init_entry for each function in the src
module.
At the site of each function call: call PROFILE(callee, caller) to
record the arc. Note that this bit of the change is not yet
complete as the Prof.CallPair file definately doesn't contain every
arc, however we need at least some of this information for the
profiler to generate meaningful output for the flat profile.
At the site of each heap allocation call MR_maybe_record_allocation().
Changes due to the change to the type target_code_component.
library/array.m:
library/builtin.m:
library/exception.m:
library/private_builtin.m:
library/std_util.m:
As c2init doesn't understand preprocessor directives we need to
define some empty initialisation functions.
trace/mercury_trace_vars.c:
Avoid a linking problem with MR_trace_ignored_type_ctors.
Add a dummy member to MR_trace_ignored_type_ctors so that the array
is never empty.
util/mkinit.c:
Call do_init_modules() if MR_HIGHLEVEL_CODE is defined.
Index: compiler/ml_code_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_code_gen.m,v
retrieving revision 1.55
diff -u -r1.55 ml_code_gen.m
--- compiler/ml_code_gen.m 2000/07/20 11:24:07 1.55
+++ compiler/ml_code_gen.m 2000/08/01 10:43:26
@@ -1619,7 +1619,7 @@
% }
%
ml_gen_nondet_pragma_c_code(CodeModel, Attributes,
- PredId, _ProcId, ArgVars, ArgDatas, OrigArgTypes, Context,
+ PredId, ProcId, ArgVars, ArgDatas, OrigArgTypes, Context,
LocalVarsDecls, LocalVarsContext, FirstCode, FirstContext,
LaterCode, LaterContext, SharedCode, SharedContext,
MLDS_Decls, MLDS_Statements) -->
@@ -1670,10 +1670,16 @@
ObtainLock, ReleaseLock),
%
+ % Generate the MR_PROC_LABEL #define
+ %
+ ml_gen_hash_define_mr_proc_label(PredId, ProcId, HashDefine),
+
+ %
% Put it all together
%
{ Starting_C_Code = list__condense([
[raw_target_code("{\n")],
+ HashDefine,
ArgDeclsList,
[raw_target_code("\tstruct {\n"),
user_target_code(LocalVarsDecls, LocalVarsContext),
@@ -1693,6 +1699,7 @@
raw_target_code("\t\t{\n"),
user_target_code(SharedCode, SharedContext),
raw_target_code("\n\t\t;}\n"),
+ raw_target_code("#undef MR_PROC_LABEL\n"),
raw_target_code(ReleaseLock),
raw_target_code("\t\tif (MR_succeeded) {\n")],
AssignOutputsList
@@ -1782,7 +1789,7 @@
% Java.
%
ml_gen_ordinary_pragma_c_code(CodeModel, Attributes,
- PredId, _ProcId, ArgVars, ArgDatas, OrigArgTypes,
+ PredId, ProcId, ArgVars, ArgDatas, OrigArgTypes,
C_Code, Context, MLDS_Decls, MLDS_Statements) -->
%
% Combine all the information about the each arg
@@ -1814,11 +1821,17 @@
ObtainLock, ReleaseLock),
%
+ % Generate the MR_PROC_LABEL #define
+ %
+ ml_gen_hash_define_mr_proc_label(PredId, ProcId, HashDefine),
+
+ %
% Put it all together
%
( { CodeModel = model_det } ->
{ Starting_C_Code = list__condense([
[raw_target_code("{\n")],
+ HashDefine,
ArgDeclsList,
[raw_target_code("\n")],
AssignInputsList,
@@ -1826,6 +1839,7 @@
raw_target_code("\t\t{\n"),
user_target_code(C_Code, yes(Context)),
raw_target_code("\n\t\t;}\n"),
+ raw_target_code("#undef MR_PROC_LABEL\n"),
raw_target_code(ReleaseLock)],
AssignOutputsList
]) },
@@ -1834,6 +1848,7 @@
ml_success_lval(SucceededLval),
{ Starting_C_Code = list__condense([
[raw_target_code("{\n")],
+ HashDefine,
ArgDeclsList,
[raw_target_code("\tbool SUCCESS_INDICATOR;\n"),
raw_target_code("\n")],
@@ -1842,6 +1857,7 @@
raw_target_code("\t\t{\n"),
user_target_code(C_Code, yes(Context)),
raw_target_code("\n\t\t;}\n"),
+ raw_target_code("#undef MR_PROC_LABEL\n"),
raw_target_code(ReleaseLock),
raw_target_code("\tif (SUCCESS_INDICATOR) {\n")],
AssignOutputsList
@@ -1897,6 +1913,18 @@
ObtainLock = "",
ReleaseLock = ""
}.
+
+:- pred ml_gen_hash_define_mr_proc_label(pred_id::in, proc_id::in,
+ list(target_code_component)::out,
+ ml_gen_info::in, ml_gen_info::out) is det.
+
+ml_gen_hash_define_mr_proc_label(PredId, ProcId, HashDefine) -->
+ =(MLDSGenInfo),
+ { ml_gen_info_get_module_info(MLDSGenInfo, ModuleInfo) },
+ { HashDefine = [raw_target_code("#define MR_PROC_LABEL "),
+ name(ml_gen_proc_label(ModuleInfo, PredId, ProcId)),
+ raw_target_code("\n")] }.
+
%---------------------------------------------------------------------------%
Index: compiler/ml_elim_nested.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_elim_nested.m,v
retrieving revision 1.10
diff -u -r1.10 ml_elim_nested.m
--- compiler/ml_elim_nested.m 2000/07/20 10:39:30 1.10
+++ compiler/ml_elim_nested.m 2000/08/01 10:43:30
@@ -779,6 +779,7 @@
fixup_target_code_component(target_code_output(Lval0),
target_code_output(Lval)) -->
fixup_lval(Lval0, Lval).
+fixup_target_code_component(name(Name), name(Name)) --> [].
:- pred fixup_trail_op(trail_op, trail_op, elim_info, elim_info).
:- mode fixup_trail_op(in, out, in, out) is det.
Index: compiler/mlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds.m,v
retrieving revision 1.28
diff -u -r1.28 mlds.m
--- compiler/mlds.m 2000/07/20 10:39:30 1.28
+++ compiler/mlds.m 2000/08/01 10:43:33
@@ -925,6 +925,7 @@
% end in `\n' (or `\n' followed by whitespace).
; target_code_input(mlds__rval)
; target_code_output(mlds__lval)
+ ; name(mlds__entity_name)
.
% XXX I'm not sure what representation we should use here
Index: compiler/mlds_to_c.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_c.m,v
retrieving revision 1.46
diff -u -r1.46 mlds_to_c.m
--- compiler/mlds_to_c.m 2000/08/01 09:04:18 1.46
+++ compiler/mlds_to_c.m 2000/08/01 10:43:38
@@ -240,6 +240,7 @@
mlds_output_c_defns(MLDS_ModuleName, Indent, ForeignCode), io__nl,
mlds_output_defns(Indent, MLDS_ModuleName, NonTypeDefns), io__nl,
+ mlds_output_init_fn(MLDS_ModuleName, NonTypeDefns), io__nl,
mlds_output_src_end(Indent, ModuleName).
:- pred mlds_output_hdr_start(indent, mercury_module_name,
@@ -280,6 +281,7 @@
io__write_string(". */\n"),
mlds_indent(Indent),
io__write_string("/* :- implementation. */\n"),
+ io__write_string("#include ""mercury_imp.h""\n"),
io__nl,
mlds_output_src_import(Indent,
mercury_module_name_to_mlds(ModuleName)),
@@ -311,6 +313,70 @@
io__write_string(". */\n").
%-----------------------------------------------------------------------------%
+
+ %
+ % Output the function `mercury__<modulename>_init()'.
+ % The body of the function consists of calls
+ % init_entry(<function>) for each function defined in the
+ % module.
+ %
+:- pred mlds_output_init_fn(mlds_module_name::in, mlds__defns::in,
+ io__state::di, io__state::uo) is det.
+
+mlds_output_init_fn(ModuleName, Defns) -->
+ % Here we ensure that we only get on "mercury__" at the
+ % start of the function name.
+ { prog_out__sym_name_to_string(
+ mlds_module_name_to_sym_name(ModuleName), "__",
+ ModuleNameString0) },
+ {
+ string__prefix(ModuleNameString0, "mercury__")
+ ->
+ ModuleNameString = ModuleNameString0
+ ;
+ string__append("mercury__", ModuleNameString0,
+ ModuleNameString)
+ },
+
+ % Function prototype.
+ output_init_fn_name(ModuleNameString),
+ io__write_string(";\n"),
+
+ % Function body.
+ output_init_fn_name(ModuleNameString),
+ io__write_string("\n{\n"),
+ io__write_strings(["\tstatic int initialised=0;\n",
+ "\tif (initialised) return;\n",
+ "\tinitialised=1;\n\n"]),
+ mlds_output_init_fn_2(ModuleName, Defns),
+ io__write_string("\n}\n").
+
+:- pred output_init_fn_name(string::in, io__state::di, io__state::uo) is det.
+
+output_init_fn_name(Name) -->
+ io__write_string("void "),
+ io__write_string(Name),
+ io__write_string("__mlds_output_init_fn(void)").
+
+:- pred mlds_output_init_fn_2(mlds_module_name::in, mlds__defns::in,
+ io__state::di, io__state::uo) is det.
+
+mlds_output_init_fn_2(_ModuleName, []) --> [].
+mlds_output_init_fn_2(ModuleName, [Defn | Defns]) -->
+ { Defn = mlds__defn(EntityName, _Context, _Flags, _EntityDefn) },
+ (
+ { EntityName = function(_, _, _, _) }
+ ->
+ { QualName = qual(ModuleName, EntityName) },
+ io__write_string("\tinit_entry("),
+ mlds_output_fully_qualified_name(QualName),
+ io__write_string(");\n")
+ ;
+ []
+ ),
+ mlds_output_init_fn_2(ModuleName, Defns).
+
+%-----------------------------------------------------------------------------%
%
% C interface stuff
%
@@ -1856,6 +1922,14 @@
io__write_string("return ")
;
io__write_string("{\n"),
+ mlds_indent(Context, Indent + 1),
+
+ io__write_string("PROFILE("),
+ mlds_output_bracketed_rval(FuncRval),
+ io__write_string(", "),
+ mlds_output_fully_qualified_name(Name),
+ io__write_string(");\n"),
+
mlds_indent(Context, Indent + 1)
)
;
@@ -2108,8 +2182,8 @@
%
% atomic statements
%
-mlds_output_stmt(Indent, _FuncInfo, atomic(AtomicStatement), Context) -->
- mlds_output_atomic_stmt(Indent, AtomicStatement, Context).
+mlds_output_stmt(Indent, FuncInfo, atomic(AtomicStatement), Context) -->
+ mlds_output_atomic_stmt(Indent, FuncInfo, AtomicStatement, Context).
:- pred mlds_output_label_name(mlds__label, io__state, io__state).
:- mode mlds_output_label_name(in, di, uo) is det.
@@ -2117,14 +2191,14 @@
mlds_output_label_name(LabelName) -->
mlds_output_mangled_name(LabelName).
-:- pred mlds_output_atomic_stmt(indent, mlds__atomic_statement, mlds__context,
- io__state, io__state).
-:- mode mlds_output_atomic_stmt(in, in, in, di, uo) is det.
+:- pred mlds_output_atomic_stmt(indent, func_info,
+ mlds__atomic_statement, mlds__context, io__state, io__state).
+:- mode mlds_output_atomic_stmt(in, in, in, in, di, uo) is det.
%
% comments
%
-mlds_output_atomic_stmt(Indent, comment(Comment), _) -->
+mlds_output_atomic_stmt(Indent, _FuncInfo, comment(Comment), _) -->
% XXX we should escape any "*/"'s in the Comment.
% we should also split the comment into lines and indent
% each line appropriately.
@@ -2136,7 +2210,7 @@
%
% assignment
%
-mlds_output_atomic_stmt(Indent, assign(Lval, Rval), _) -->
+mlds_output_atomic_stmt(Indent, _FuncInfo, assign(Lval, Rval), _) -->
mlds_indent(Indent),
mlds_output_lval(Lval),
io__write_string(" = "),
@@ -2146,12 +2220,29 @@
%
% heap management
%
-mlds_output_atomic_stmt(Indent, NewObject, Context) -->
+mlds_output_atomic_stmt(Indent, FuncInfo, NewObject, Context) -->
{ NewObject = new_object(Target, MaybeTag, Type, MaybeSize,
MaybeCtorName, Args, ArgTypes) },
mlds_indent(Indent),
io__write_string("{\n"),
mlds_indent(Context, Indent + 1),
+
+ { FuncInfo = func_info(FuncName, _FuncParams) },
+ io__write_string("MR_maybe_record_allocation("),
+ io__write_int(list__length(Args)),
+ io__write_string(", "),
+ mlds_output_fully_qualified_name(FuncName),
+ io__write_string(", "),
+ ( { MaybeCtorName = yes(CtorNameA) } ->
+ io__write_char('"'),
+ c_util__output_quoted_string(CtorNameA),
+ io__write_char('"')
+ ;
+ io__write_string("NULL")
+ ),
+ io__write_string(");\n"),
+
+ mlds_indent(Context, Indent + 1),
mlds_output_lval(Target),
io__write_string(" = "),
( { MaybeTag = yes(Tag0) } ->
@@ -2201,13 +2292,13 @@
mlds_indent(Context, Indent),
io__write_string("}\n").
-mlds_output_atomic_stmt(Indent, mark_hp(Lval), _) -->
+mlds_output_atomic_stmt(Indent, _FuncInfo, mark_hp(Lval), _) -->
mlds_indent(Indent),
io__write_string("MR_mark_hp("),
mlds_output_lval(Lval),
io__write_string(");\n").
-mlds_output_atomic_stmt(Indent, restore_hp(Rval), _) -->
+mlds_output_atomic_stmt(Indent, _FuncInfo, restore_hp(Rval), _) -->
mlds_indent(Indent),
io__write_string("MR_mark_hp("),
mlds_output_rval(Rval),
@@ -2216,26 +2307,28 @@
%
% trail management
%
-mlds_output_atomic_stmt(_Indent, trail_op(_TrailOp), _) -->
+mlds_output_atomic_stmt(_Indent, _FuncInfo, trail_op(_TrailOp), _) -->
{ error("mlds_to_c.m: sorry, trail_ops not implemented") }.
%
% foreign language interfacing
%
-mlds_output_atomic_stmt(_Indent, target_code(TargetLang, Components),
+mlds_output_atomic_stmt(_Indent, FuncInfo, target_code(TargetLang, Components),
Context) -->
( { TargetLang = lang_C } ->
- list__foldl(mlds_output_target_code_component(Context),
+ { FuncInfo = func_info(qual(ModuleName, _), _FuncParams) },
+ list__foldl(
+ mlds_output_target_code_component(ModuleName, Context),
Components)
;
{ error("mlds_to_c.m: sorry, target_code only works for lang_C") }
).
-:- pred mlds_output_target_code_component(mlds__context, target_code_component,
- io__state, io__state).
-:- mode mlds_output_target_code_component(in, in, di, uo) is det.
+:- pred mlds_output_target_code_component(mlds_module_name, mlds__context,
+ target_code_component, io__state, io__state).
+:- mode mlds_output_target_code_component(in, in, in, di, uo) is det.
-mlds_output_target_code_component(Context,
+mlds_output_target_code_component(_ModuleName, Context,
user_target_code(CodeString, MaybeUserContext)) -->
( { MaybeUserContext = yes(UserContext) } ->
mlds_output_context(mlds__make_context(UserContext))
@@ -2244,17 +2337,23 @@
),
io__write_string(CodeString),
io__write_string("\n").
-mlds_output_target_code_component(Context, raw_target_code(CodeString)) -->
+mlds_output_target_code_component(_ModuleName, Context,
+ raw_target_code(CodeString)) -->
mlds_output_context(Context),
io__write_string(CodeString).
-mlds_output_target_code_component(Context, target_code_input(Rval)) -->
+mlds_output_target_code_component(_ModuleName, Context,
+ target_code_input(Rval)) -->
mlds_output_context(Context),
mlds_output_rval(Rval),
io__write_string("\n").
-mlds_output_target_code_component(Context, target_code_output(Lval)) -->
+mlds_output_target_code_component(_ModuleName, Context,
+ target_code_output(Lval)) -->
mlds_output_context(Context),
mlds_output_lval(Lval),
io__write_string("\n").
+mlds_output_target_code_component(ModuleName, _Context, name(Name)) -->
+ mlds_output_fully_qualified_name(qual(ModuleName, Name)).
+
:- pred mlds_output_init_args(list(mlds__rval), list(mlds__type), mlds__context,
int, mlds__lval, mlds__tag, indent, io__state, io__state).
Index: library/array.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/array.m,v
retrieving revision 1.71
diff -u -r1.71 array.m
--- library/array.m 2000/05/08 13:48:33 1.71
+++ library/array.m 2000/08/01 10:43:41
@@ -271,7 +271,12 @@
:- pragma c_code("
-#ifndef MR_HIGHLEVEL_CODE
+#ifdef MR_HIGHLEVEL_CODE
+void sys_init_array_module_builtins(void);
+void sys_init_array_module_builtins(void) {
+ return;
+}
+#else
MR_DEFINE_BUILTIN_TYPE_CTOR_INFO(array, array, 1, MR_TYPECTOR_REP_ARRAY);
Index: library/builtin.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/builtin.m,v
retrieving revision 1.37
diff -u -r1.37 builtin.m
--- library/builtin.m 2000/07/12 13:54:40 1.37
+++ library/builtin.m 2000/08/01 10:43:41
@@ -234,7 +234,10 @@
:- pragma c_code("
-#ifndef MR_HIGHLEVEL_CODE
+#ifdef MR_HIGHLEVEL_CODE
+void sys_init_builtin_types_module(void); /* suppress gcc warning */
+void sys_init_builtin_types_module(void) { return; }
+#else
MR_DEFINE_BUILTIN_TYPE_CTOR_INFO_NOCM(builtin, int, 0,
MR_TYPECTOR_REP_INT,
@@ -388,6 +391,9 @@
mercury__builtin__copy_2_p_0(type_info, x, y);
}
+void sys_init_copy_module(void);
+void sys_init_copy_module(void) { return; }
+
#else /* ! MR_HIGHLEVEL_CODE */
Define_extern_entry(mercury__copy_2_0);
@@ -443,7 +449,10 @@
:- pragma c_code("
-#ifndef MR_HIGHLEVEL_CODE
+#ifdef MR_HIGHLEVEL_CODE
+void sys_init_unify_c_pointer_module(void);
+void sys_init_unify_c_pointer_module(void) { return; }
+#else
MR_DEFINE_BUILTIN_TYPE_CTOR_INFO_PRED(builtin, c_pointer, 0,
MR_TYPECTOR_REP_C_POINTER,
Index: library/exception.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/exception.m,v
retrieving revision 1.27
diff -u -r1.27 exception.m
--- library/exception.m 2000/08/01 05:33:33 1.27
+++ library/exception.m 2000/08/01 10:43:45
@@ -893,7 +893,10 @@
").
:- pragma c_code("
-#ifndef MR_HIGHLEVEL_CODE
+#ifdef MR_HIGHLEVEL_CODE
+void mercury_sys_init_exceptions(void);
+void mercury_sys_init_exceptions(void) { return; }
+#else
/*
** MR_trace_throw():
Index: library/private_builtin.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/private_builtin.m,v
retrieving revision 1.52
diff -u -r1.52 private_builtin.m
--- library/private_builtin.m 2000/05/08 16:10:59 1.52
+++ library/private_builtin.m 2000/08/01 10:43:57
@@ -279,7 +279,10 @@
:- pragma c_code("
-#ifndef MR_HIGHLEVEL_CODE
+#ifdef MR_HIGHLEVEL_CODE
+void sys_init_type_info_module(void); /* suppress gcc -Wmissing-decl warning */
+void sys_init_type_info_module(void) { return; }
+#else
/*
** For most purposes, type_ctor_info can be treated just like
Index: library/std_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/std_util.m,v
retrieving revision 1.194
diff -u -r1.194 std_util.m
--- library/std_util.m 2000/07/18 00:46:19 1.194
+++ library/std_util.m 2000/08/01 10:44:07
@@ -1040,7 +1040,10 @@
:- pragma c_code("
-#ifndef MR_HIGHLEVEL_CODE
+#ifdef MR_HIGHLEVEL_CODE
+void sys_init_unify_univ_module(void); /* suppress gcc -Wmissing-decl warning */
+void sys_init_unify_univ_module(void) { return; }
+#else
MR_DEFINE_BUILTIN_TYPE_CTOR_INFO(std_util, type_desc, 0,
MR_TYPECTOR_REP_C_POINTER);
Index: trace/mercury_trace_vars.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_vars.c,v
retrieving revision 1.19
diff -u -r1.19 mercury_trace_vars.c
--- trace/mercury_trace_vars.c 2000/07/18 05:53:16 1.19
+++ trace/mercury_trace_vars.c 2000/08/01 10:44:13
@@ -162,6 +162,7 @@
MR_trace_ignored_type_ctors[] =
{
/* we ignore these until the debugger can handle their varying arity */
+#ifndef MR_HIGHLEVEL_CODE
&mercury_data_private_builtin__type_ctor_info_type_info_1,
&mercury_data_private_builtin__type_ctor_info_type_ctor_info_1,
&mercury_data_private_builtin__type_ctor_info_typeclass_info_1,
@@ -175,6 +176,7 @@
/* we ignore these because they should never be needed */
&mercury_data___type_ctor_info_void_0,
+#endif
#ifdef NATIVE_GC
/* we ignore these because they are not interesting */
@@ -185,6 +187,8 @@
&mercury_data___type_ctor_info_redoip_0,
&mercury_data___type_ctor_info_redofr_0,
#endif
+ /* dummy member */
+ NULL
};
static bool
Index: util/mkinit.c
===================================================================
RCS file: /home/mercury1/repository/mercury/util/mkinit.c,v
retrieving revision 1.64
diff -u -r1.64 mkinit.c
--- util/mkinit.c 2000/06/08 07:59:13 1.64
+++ util/mkinit.c 2000/08/01 10:44:15
@@ -202,7 +202,8 @@
" MR_address_of_trace_final_external = NULL;\n"
" #endif\n"
"#endif\n"
- "#if defined(USE_GCC_NONLOCAL_GOTOS) && !defined(USE_ASM_LABELS)\n"
+ "#if (defined(USE_GCC_NONLOCAL_GOTOS) && !defined(USE_ASM_LABELS)) || "
+ "defined(MR_HIGHLEVEL_CODE)\n"
" do_init_modules();\n"
"#endif\n"
"#ifdef MR_HIGHLEVEL_CODE\n"
--------------------------------------------------------------------------
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