[m-dev.] for review: layout structures for resumption points
Zoltan Somogyi
zs at cs.mu.OZ.AU
Fri Mar 12 13:48:36 AEDT 1999
> > This is for review by Tyson, since he has already seen most of it.
> You forgot the diff.
Sorry, here it is.
Zoltan.
cvs diff: Diffing .
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/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing bytecode/test
cvs diff: Diffing compiler
Index: compiler/code_info.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/code_info.m,v
retrieving revision 1.235
diff -u -b -u -r1.235 code_info.m
--- code_info.m 1998/11/20 04:07:10 1.235
+++ code_info.m 1999/03/04 04:01:07
@@ -1,5 +1,5 @@
%---------------------------------------------------------------------------%
-% Copyright (C) 1994-1998 The University of Melbourne.
+% Copyright (C) 1994-1999 The University of Melbourne.
% This file may only be copied under the terms of the GNU General
% Public License - see the file COPYING in the Mercury distribution.
%---------------------------------------------------------------------------%
@@ -634,6 +634,10 @@
code_info, code_info).
:- mode code_info__add_trace_layout_for_label(in, in, in, out) is det.
+:- pred code_info__add_gc_layout_for_label(label, layout_label_info,
+ code_info, code_info).
+:- mode code_info__add_gc_layout_for_label(in, in, in, out) is det.
+
%---------------------------------------------------------------------------%
:- implementation.
@@ -651,10 +655,6 @@
code_exprn__set_follow_vars(FollowVars, ExprnInfo0, ExprnInfo),
code_info__set_exprn_info(ExprnInfo, CI0, CI).
-:- pred code_info__get_active_temps_data(assoc_list(lval, slot_contents),
- code_info, code_info).
-:- mode code_info__get_active_temps_data(out, in, out) is det.
-
%-----------------------------------------------------------------------------%
% Update the code info structure to be consistent
@@ -709,9 +709,15 @@
%---------------------------------------------------------------------------%
-code_info__variable_type(Var, Type) -->
+:- pred code_info__get_var_types(map(prog_var, type), code_info, code_info).
+:- mode code_info__get_var_types(out, in, out) is det.
+
+code_info__get_var_types(VarTypes) -->
code_info__get_proc_info(ProcInfo),
- { proc_info_vartypes(ProcInfo, VarTypes) },
+ { proc_info_vartypes(ProcInfo, VarTypes) }.
+
+code_info__variable_type(Var, Type) -->
+ code_info__get_var_types(VarTypes),
{ map__lookup(VarTypes, Var, Type) }.
code_info__lookup_type_defn(Type, TypeDefn) -->
@@ -855,6 +861,27 @@
},
code_info__set_layout_info(Internals).
+code_info__add_gc_layout_for_label(Label, LayoutInfo) -->
+ code_info__get_layout_info(Internals0),
+ { map__search(Internals0, Label, Internal0) ->
+ Internal0 = internal_layout_info(Exec, Agc0),
+ ( Agc0 = no ->
+ true
+ ;
+ error("adding gc layout for already known label")
+ ),
+ Internal = internal_layout_info(Exec, yes(LayoutInfo)),
+ map__set(Internals0, Label, Internal, Internals)
+ ;
+ Internal = internal_layout_info(no, yes(LayoutInfo)),
+ map__det_insert(Internals0, Label, Internal, Internals)
+ },
+ code_info__set_layout_info(Internals).
+
+:- pred code_info__get_active_temps_data(assoc_list(lval, slot_contents),
+ code_info, code_info).
+:- mode code_info__get_active_temps_data(out, in, out) is det.
+
code_info__get_active_temps_data(Temps) -->
code_info__get_temps_in_use(TempsInUse),
code_info__get_temp_content_map(TempContentMap),
@@ -887,6 +914,10 @@
code_info, code_info).
:- mode code_info__after_all_branches(in, in, in, out) is det.
+:- pred code_info__save_hp_in_branch(code_tree, lval, position_info,
+ position_info).
+:- mode code_info__save_hp_in_branch(out, out, in, out) is det.
+
:- implementation.
:- type position_info
@@ -1009,6 +1040,11 @@
code_info__fixup_lvallist([V - L | Ls], [V - lval(L) | Rs]) :-
code_info__fixup_lvallist(Ls, Rs).
+code_info__save_hp_in_branch(Code, Slot, Pos0, Pos) :-
+ Pos0 = position_info(CodeInfo0),
+ code_info__save_hp(Code, Slot, CodeInfo0, CodeInfo),
+ Pos = position_info(CodeInfo).
+
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
@@ -1754,6 +1790,7 @@
HijackInfo, MaybeTrailSlots) },
code_info__set_fail_info(FailInfo),
+ % XXX should release the temp slots in each arm of the switch
(
{ HijackInfo = commit_temp_frame(MaxfrSlot) },
{ SuccessUndoCode = node([
@@ -2295,7 +2332,8 @@
label(Label1) -
"stack only failure continuation"
]) },
- code_info__set_var_locations(Map1)
+ code_info__set_var_locations(Map1),
+ code_info__generate_resume_layout(Label1, Map1)
;
{ ResumePoint = stack_and_orig(Map1, Addr1, Map2, Addr2) },
{ extract_label_from_code_addr(Addr1, Label1) },
@@ -2305,6 +2343,7 @@
"stack failure continuation before orig"
]) },
code_info__set_var_locations(Map1),
+ code_info__generate_resume_layout(Label1, Map1),
{ map__to_assoc_list(Map2, AssocList2) },
code_info__place_resume_vars(AssocList2, PlaceCode),
{ Label2Code = node([
@@ -2329,6 +2368,7 @@
"stack failure continuation after orig"
]) },
code_info__set_var_locations(Map2),
+ code_info__generate_resume_layout(Label2, Map2),
{ Code = tree(Label1Code, tree(PlaceCode, Label2Code)) }
).
@@ -3243,6 +3283,83 @@
code_info__get_live_value_type(ticket_counter, unwanted).
code_info__get_live_value_type(sync_term, unwanted).
code_info__get_live_value_type(trace_data, unwanted).
+
+%---------------------------------------------------------------------------%
+
+:- pred code_info__generate_resume_layout(label::in, resume_map::in,
+ code_info::in, code_info::out) is det.
+
+code_info__generate_resume_layout(Label, ResumeMap) -->
+ code_info__get_globals(Globals),
+ { globals__get_gc_method(Globals, GcMethod) },
+ ( { GcMethod = accurate } ->
+ { map__to_assoc_list(ResumeMap, ResumeList) },
+ code_info__get_instmap(InstMap),
+ code_info__get_var_types(VarTypes),
+ code_info__get_varset(VarSet),
+ { set__init(TVars0) },
+ { code_info__generate_resume_layout_for_vars(ResumeList,
+ VarSet, VarTypes, InstMap, VarInfos, TVars0, TVars) },
+ { set__list_to_set(VarInfos, VarInfoSet) },
+ { set__to_sorted_list(TVars, TVarList) },
+ code_info__find_typeinfos_for_tvars(TVarList, TVarInfoMap),
+ code_info__get_active_temps_data(Temps),
+ { code_info__generate_temp_var_infos(Temps, TempInfos) },
+ { set__list_to_set(TempInfos, TempInfoSet) },
+ { set__union(VarInfoSet, TempInfoSet, AllInfoSet) },
+ { Layout = layout_label_info(AllInfoSet, TVarInfoMap) },
+ code_info__add_gc_layout_for_label(Label, Layout)
+ ;
+ []
+ ).
+
+:- pred code_info__generate_resume_layout_for_vars(
+ assoc_list(prog_var, set(rval))::in, prog_varset::in,
+ map(prog_var, type)::in, instmap::in, list(var_info)::out,
+ set(tvar)::in, set(tvar)::out) is det.
+
+code_info__generate_resume_layout_for_vars([], _, _, _, [], TVars, TVars).
+code_info__generate_resume_layout_for_vars([Var - RvalSet | VarRvals], VarSet,
+ VarTypes, InstMap, [VarInfo | VarInfos], TVars0, TVars) :-
+ code_info__generate_resume_layout_for_var(Var, RvalSet, VarSet,
+ VarTypes, InstMap, VarInfo, TypeVars),
+ set__insert_list(TVars0, TypeVars, TVars1),
+ code_info__generate_resume_layout_for_vars(VarRvals, VarSet,
+ VarTypes, InstMap, VarInfos, TVars1, TVars).
+
+:- pred code_info__generate_resume_layout_for_var(prog_var::in, set(rval)::in,
+ prog_varset::in, map(prog_var, type)::in, instmap::in,
+ var_info::out, list(tvar)::out) is det.
+
+code_info__generate_resume_layout_for_var(Var, RvalSet, VarSet,
+ VarTypes, InstMap, VarInfo, TypeVars) :-
+ set__to_sorted_list(RvalSet, RvalList),
+ ( RvalList = [RvalPrime] ->
+ Rval = RvalPrime
+ ;
+ error("var has more than one rval in stack resume map")
+ ),
+ ( Rval = lval(LvalPrime) ->
+ Lval = LvalPrime
+ ;
+ error("var rval is not lval in stack resume map")
+ ),
+ varset__lookup_name(VarSet, Var, "V_", Name),
+ instmap__lookup_var(InstMap, Var, Inst),
+ map__lookup(VarTypes, Var, Type),
+ LiveType = var(Var, Name, Type, Inst),
+ VarInfo = var_info(direct(Lval), LiveType),
+ type_util__vars(Type, TypeVars).
+
+:- pred code_info__generate_temp_var_infos(
+ assoc_list(lval, slot_contents)::in, list(var_info)::out) is det.
+
+code_info__generate_temp_var_infos([], []).
+code_info__generate_temp_var_infos([Temp | Temps], [Live | Lives]) :-
+ Temp = Slot - Contents,
+ code_info__get_live_value_type(Contents, LiveLvalueType),
+ Live = var_info(direct(Slot), LiveLvalueType),
+ code_info__generate_temp_var_infos(Temps, Lives).
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
Index: compiler/disj_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/disj_gen.m,v
retrieving revision 1.67
diff -u -b -u -r1.67 disj_gen.m
--- disj_gen.m 1998/11/20 04:07:29 1.67
+++ disj_gen.m 1999/03/04 04:01:13
@@ -1,5 +1,5 @@
%-----------------------------------------------------------------------------%
-% Copyright (C) 1994-1998 The University of Melbourne.
+% Copyright (C) 1994-1999 The University of Melbourne.
% This file may only be copied under the terms of the GNU General
% Public License - see the file COPYING in the Mercury distribution.
%---------------------------------------------------------------------------%
@@ -28,7 +28,7 @@
:- implementation.
:- import_module prog_data, hlds_data, code_gen, code_util, trace.
-:- import_module options, globals.
+:- import_module options, globals, tree.
:- import_module bool, set, tree, map, std_util, term, require.
disj_gen__generate_disj(CodeModel, Goals, StoreMap, Code) -->
@@ -143,9 +143,9 @@
disj_gen__generate_disjuncts([Goal0 | Goals], CodeModel, FullResumeMap,
MaybeEntryResumePoint, HijackInfo, StoreMap, EndLabel,
ReclaimHeap, MaybeHpSlot0, MaybeTicketSlot,
- BranchStart, MaybeEnd0, MaybeEnd, Code) -->
+ BranchStart0, MaybeEnd0, MaybeEnd, Code) -->
- code_info__reset_to_position(BranchStart),
+ code_info__reset_to_position(BranchStart0),
% If this is not the first disjunct, generate the
% resume point by which arrive at this disjunct.
@@ -194,10 +194,28 @@
{ MaybeHpSlot0 = no }
->
code_info__save_hp(SaveHpCode, HpSlot),
- { MaybeHpSlot = yes(HpSlot) }
+ { MaybeHpSlot = yes(HpSlot) },
+ % This method of updating BranchStart0 is
+ % ugly. The best alternative would be to
+ % arrange things so that a remember_position
+ % here could get BranchStart, but doing so
+ % is iffy because we have already created
+ % the resumption point for entry into this
+ % disjunction, which overwrites part of the
+ % location-dependent state originally in
+ % BranchStart0.
+ { code_info__save_hp_in_branch(BranchSaveHpCode,
+ BranchHpSlot, BranchStart0, BranchStart) },
+ { tree__flatten(SaveHpCode, HpCodeList) },
+ { tree__flatten(BranchSaveHpCode, BranchHpCodeList) },
+ { require(unify(HpCodeList, BranchHpCodeList),
+ "cannot use same code for saving hp") },
+ { require(unify(HpSlot, BranchHpSlot),
+ "cannot allocate same slot for saved hp") }
;
{ SaveHpCode = empty },
- { MaybeHpSlot = MaybeHpSlot0 }
+ { MaybeHpSlot = MaybeHpSlot0 },
+ { BranchStart = BranchStart0 }
),
code_info__make_resume_point(ResumeVars, ResumeLocs,
Index: compiler/hlds_module.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_module.m,v
retrieving revision 1.39
diff -u -b -u -r1.39 hlds_module.m
--- hlds_module.m 1998/12/06 23:43:17 1.39
+++ hlds_module.m 1999/03/04 04:02:23
@@ -1,5 +1,5 @@
%-----------------------------------------------------------------------------%
-% Copyright (C) 1996-1998 The University of Melbourne.
+% Copyright (C) 1996-1999 The University of Melbourne.
% This file may only be copied under the terms of the GNU General
% Public License - see the file COPYING in the Mercury distribution.
%-----------------------------------------------------------------------------%
@@ -2065,6 +2065,9 @@
:- 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_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.
@@ -2111,6 +2114,10 @@
map__det_update(ProcLayoutMap0, PredProcId, ProcLayout, ProcLayoutMap),
global_data_set_proc_layout_map(GlobalData0, ProcLayoutMap,
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),
Index: compiler/labelopt.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/labelopt.m,v
retrieving revision 1.19
diff -u -b -u -r1.19 labelopt.m
--- labelopt.m 1998/01/23 12:56:40 1.19
+++ labelopt.m 1999/03/04 04:01:24
@@ -1,5 +1,5 @@
%-----------------------------------------------------------------------------%
-% Copyright (C) 1994-1997 The University of Melbourne.
+% Copyright (C) 1994-1999 The University of Melbourne.
% This file may only be copied under the terms of the GNU General
% Public License - see the file COPYING in the Mercury distribution.
%-----------------------------------------------------------------------------%
@@ -22,13 +22,15 @@
% If the instruction before the label branches away, we also
% remove the instruction block following the label.
-:- pred labelopt_main(list(instruction), bool, list(instruction), bool).
-:- mode labelopt_main(in, in, out, out) is det.
+:- pred labelopt_main(list(instruction)::in, bool::in, set(label)::in,
+ list(instruction)::out, bool::out) is det.
- % Build up a set showing which labels are branched to.
+ % Build up a set showing which labels are referred to.
+ % The input set is the list of labels referred to from outside
+ % the given list of instructions.
-:- pred labelopt__build_useset(list(instruction), set(label)).
-:- mode labelopt__build_useset(in, out) is det.
+:- pred labelopt__build_useset(list(instruction)::in, set(label)::in,
+ set(label)::out) is det.
%-----------------------------------------------------------------------------%
@@ -37,30 +39,23 @@
:- import_module opt_util.
:- import_module std_util.
-labelopt_main(Instrs0, Final, Instrs, Mod) :-
- labelopt__build_useset(Instrs0, Useset),
+labelopt_main(Instrs0, Final, LayoutLabelSet, Instrs, Mod) :-
+ labelopt__build_useset(Instrs0, LayoutLabelSet, Useset),
labelopt__instr_list(Instrs0, yes, Useset, Instrs1, Mod),
( Final = yes, Mod = yes ->
- labelopt_main(Instrs1, Final, Instrs, _)
+ labelopt_main(Instrs1, Final, LayoutLabelSet, Instrs, _)
;
Instrs = Instrs1
).
%-----------------------------------------------------------------------------%
-labelopt__build_useset(Instrs, Useset) :-
- set__init(Useset0),
- labelopt__build_useset_2(Instrs, Useset0, Useset).
-
-:- pred labelopt__build_useset_2(list(instruction), set(label), set(label)).
-:- mode labelopt__build_useset_2(in, in, out) is det.
-
-labelopt__build_useset_2([], Useset, Useset).
-labelopt__build_useset_2([Instr | Instructions], Useset0, Useset) :-
+labelopt__build_useset([], Useset, Useset).
+labelopt__build_useset([Instr | Instructions], Useset0, Useset) :-
Instr = Uinstr - _Comment,
opt_util__instr_labels(Uinstr, Labels, _CodeAddresses),
set__insert_list(Useset0, Labels, Useset1),
- labelopt__build_useset_2(Instructions, Useset1, Useset).
+ labelopt__build_useset(Instructions, Useset1, Useset).
%-----------------------------------------------------------------------------%
@@ -70,9 +65,8 @@
% If not, we delete it. We delete the following code as well if
% the label was preceded by code that cannot fall through.
-:- pred labelopt__instr_list(list(instruction), bool, set(label),
- list(instruction), bool).
-:- mode labelopt__instr_list(in, in, in, out, out) is det.
+:- pred labelopt__instr_list(list(instruction)::in, bool::in, set(label)::in,
+ list(instruction)::out, bool::out) is det.
labelopt__instr_list([], _Fallthrough, _Useset, [], no).
labelopt__instr_list([Instr0 | MoreInstrs0],
@@ -121,8 +115,8 @@
% field on the instruction is often enough to deduce what the
% eliminated instruction was.
-:- pred labelopt__eliminate(instruction, maybe(bool), list(instruction), bool).
-:- mode labelopt__eliminate(in, in, out, out) is det.
+:- pred labelopt__eliminate(instruction::in, maybe(bool)::in,
+ list(instruction)::out, bool::out) is det.
labelopt__eliminate(Uinstr0 - Comment0, Label, Instr, Mod) :-
labelopt_eliminate_total(Total),
@@ -154,8 +148,7 @@
Instr = [Uinstr - Comment]
).
-:- pred labelopt_eliminate_total(bool).
-:- mode labelopt_eliminate_total(out) is det.
+:- pred labelopt_eliminate_total(bool::out) is det.
labelopt_eliminate_total(yes).
Index: compiler/mercury_compile.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.118
diff -u -b -u -r1.118 mercury_compile.m
--- mercury_compile.m 1999/03/05 13:09:30 1.118
+++ mercury_compile.m 1999/03/10 06:05:26
@@ -1108,7 +1108,9 @@
{ HLDS99 = HLDS97 },
mercury_compile__maybe_dump_hlds(HLDS99, "99", "final"), !,
- mercury_compile__maybe_do_optimize(LLDS1, Verbose, Stats, LLDS).
+ { 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).
@@ -1237,7 +1239,7 @@
Proc0) },
{ globals__lookup_bool_option(Globals, optimize, Optimize) },
( { Optimize = yes } ->
- optimize__proc(Proc0, Proc)
+ optimize__proc(Proc0, GlobalData1, Proc)
;
{ Proc = Proc0 }
),
@@ -1910,17 +1912,17 @@
maybe_write_string(Verbose, "% done.\n"),
maybe_report_stats(Stats).
-:- pred mercury_compile__maybe_do_optimize(list(c_procedure), bool, bool,
- list(c_procedure), io__state, io__state).
-:- mode mercury_compile__maybe_do_optimize(in, in, in, out, di, uo) is det.
+:- pred mercury_compile__maybe_do_optimize(list(c_procedure), global_data,
+ bool, bool, list(c_procedure), io__state, io__state).
+:- mode mercury_compile__maybe_do_optimize(in, in, in, in, out, di, uo) is det.
-mercury_compile__maybe_do_optimize(LLDS0, Verbose, Stats, LLDS) -->
+mercury_compile__maybe_do_optimize(LLDS0, GlobalData, Verbose, Stats, LLDS) -->
globals__io_lookup_bool_option(optimize, Optimize),
( { Optimize = yes } ->
maybe_write_string(Verbose,
"% Doing optimizations...\n"),
maybe_flush_output(Verbose),
- optimize_main(LLDS0, LLDS),
+ optimize_main(LLDS0, GlobalData, LLDS),
maybe_write_string(Verbose, "% done.\n"),
maybe_report_stats(Stats)
;
Index: compiler/optimize.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/optimize.m,v
retrieving revision 1.15
diff -u -b -u -r1.15 optimize.m
--- optimize.m 1998/06/16 06:11:36 1.15
+++ optimize.m 1999/03/04 04:01:38
@@ -1,5 +1,5 @@
%-----------------------------------------------------------------------------%
-% Copyright (C) 1996-1998 The University of Melbourne.
+% Copyright (C) 1996-1999 The University of Melbourne.
% This file may only be copied under the terms of the GNU General
% Public License - see the file COPYING in the Mercury distribution.
%-----------------------------------------------------------------------------%
@@ -14,56 +14,71 @@
:- interface.
-:- import_module llds, io, list.
+:- import_module llds, hlds_module.
+:- import_module io, list.
-:- pred optimize_main(list(c_procedure), list(c_procedure),
- io__state, io__state).
-:- mode optimize_main(in, out, di, uo) is det.
+:- pred optimize_main(list(c_procedure)::in, global_data::in,
+ list(c_procedure)::out, io__state::di, io__state::uo) is det.
-:- pred optimize__proc(c_procedure, c_procedure, io__state, io__state).
-:- mode optimize__proc(in, out, di, uo) is det.
+:- pred optimize__proc(c_procedure::in, global_data::in,
+ c_procedure::out, io__state::di, io__state::uo) is det.
%-----------------------------------------------------------------------------%
:- implementation.
-:- import_module bool, map, bimap, int, std_util.
-
:- import_module jumpopt, labelopt, dupelim, peephole.
:- import_module frameopt, delay_slot, value_number, options.
:- import_module globals, passes_aux, opt_util, opt_debug, vn_debug.
+:- import_module continuation_info.
+
+:- import_module bool, int, map, bimap, set, std_util.
-optimize_main([], []) --> [].
-optimize_main([Proc0|Procs0], [Proc|Procs]) -->
- optimize__proc(Proc0, Proc), !,
- optimize_main(Procs0, Procs).
+optimize_main([], _, []) --> [].
+optimize_main([Proc0 | Procs0], GlobalData, [Proc | Procs]) -->
+ optimize__proc(Proc0, GlobalData, Proc), !,
+ optimize_main(Procs0, GlobalData, Procs).
-optimize__proc(c_procedure(Name, Arity, PredProcId, Instrs0),
- c_procedure(Name, Arity, PredProcId, Instrs)) -->
+optimize__proc(CProc0, GlobalData, CProc) -->
+ { CProc0 = c_procedure(Name, Arity, PredProcId, Instrs0) },
globals__io_lookup_bool_option(debug_opt, DebugOpt),
opt_debug__msg(DebugOpt, "before optimization"),
opt_debug__dump_instrs(DebugOpt, Instrs0),
globals__io_lookup_int_option(optimize_repeat, AllRepeat),
globals__io_lookup_int_option(optimize_vnrepeat, VnRepeat),
globals__io_lookup_bool_option(optimize_value_number, ValueNumber),
+ {
+ global_data_maybe_get_proc_layout(GlobalData, PredProcId,
+ ProcLayout)
+ ->
+ ProcLayout = proc_layout_info(_, _, _, _, _, _, _, LabelMap),
+ map__sorted_keys(LabelMap, LayoutLabels),
+ set__sorted_list_to_set(LayoutLabels, LayoutLabelSet)
+ ;
+ set__init(LayoutLabelSet)
+ },
( { ValueNumber = yes } ->
{ NovnRepeat is AllRepeat - VnRepeat },
- optimize__repeat(NovnRepeat, no, Instrs0, Instrs1),
- optimize__middle(Instrs1, no, Instrs2),
- optimize__repeat(VnRepeat, yes, Instrs2, Instrs3)
- ;
- optimize__repeat(AllRepeat, no, Instrs0, Instrs1),
- optimize__middle(Instrs1, yes, Instrs3)
+ optimize__repeat(NovnRepeat, no, LayoutLabelSet,
+ Instrs0, Instrs1),
+ optimize__middle(Instrs1, no, LayoutLabelSet, Instrs2),
+ optimize__repeat(VnRepeat, yes, LayoutLabelSet,
+ Instrs2, Instrs3)
+ ;
+ optimize__repeat(AllRepeat, no, LayoutLabelSet,
+ Instrs0, Instrs1),
+ optimize__middle(Instrs1, yes, LayoutLabelSet, Instrs3)
),
- optimize__last(Instrs3, Instrs).
+ optimize__last(Instrs3, LayoutLabelSet, Instrs),
+ { CProc = c_procedure(Name, Arity, PredProcId, Instrs) }.
%-----------------------------------------------------------------------------%
-:- pred optimize__repeat(int, bool, list(instruction), list(instruction),
- io__state, io__state).
-:- mode optimize__repeat(in, in, in, out, di, uo) is det.
+:- pred optimize__repeat(int::in, bool::in, set(label)::in,
+ list(instruction)::in, list(instruction)::out,
+ io__state::di, io__state::uo) is det.
-optimize__repeat(Iter0, DoVn, Instrs0, Instrs) -->
+optimize__repeat(Iter0, DoVn, LayoutLabelSet, Instrs0, Instrs) -->
(
{ Iter0 > 0 }
->
@@ -73,9 +88,11 @@
;
{ Final = no }
),
- optimize__repeated(Instrs0, DoVn, Final, Instrs1, Mod),
+ optimize__repeated(Instrs0, DoVn, Final, LayoutLabelSet,
+ Instrs1, Mod),
( { Mod = yes } ->
- optimize__repeat(Iter1, DoVn, Instrs1, Instrs)
+ optimize__repeat(Iter1, DoVn, LayoutLabelSet,
+ Instrs1, Instrs)
;
{ Instrs = Instrs1 }
)
@@ -86,11 +103,11 @@
% We short-circuit jump sequences before normal peepholing
% to create more opportunities for use of the tailcall macro.
-:- pred optimize__repeated(list(instruction), bool, bool,
- list(instruction), bool, io__state, io__state).
-:- mode optimize__repeated(in, in, in, out, out, di, uo) is det.
+:- pred optimize__repeated(list(instruction)::in, bool::in, bool::in,
+ set(label)::in, list(instruction)::out, bool::out,
+ io__state::di, io__state::uo) is det.
-optimize__repeated(Instrs0, DoVn, Final, Instrs, Mod) -->
+optimize__repeated(Instrs0, DoVn, Final, LayoutLabelSet, Instrs, Mod) -->
globals__io_lookup_bool_option(very_verbose, VeryVerbose),
globals__io_lookup_bool_option(debug_opt, DebugOpt),
{ opt_util__find_first_label(Instrs0, Label) },
@@ -105,7 +122,7 @@
;
[]
),
- value_number_main(Instrs0, Instrs1),
+ value_number_main(Instrs0, LayoutLabelSet, Instrs1),
( { Instrs1 = Instrs0 } ->
[]
;
@@ -166,7 +183,8 @@
;
[]
),
- { labelopt_main(Instrs3, Final, Instrs4, Mod3) },
+ { labelopt_main(Instrs3, Final, LayoutLabelSet,
+ Instrs4, Mod3) },
( { Mod3 = yes } ->
opt_debug__msg(DebugOpt, "after label optimization"),
opt_debug__dump_instrs(DebugOpt, Instrs4)
@@ -204,11 +222,10 @@
globals__io_lookup_bool_option(statistics, Statistics),
maybe_report_stats(Statistics).
-:- pred optimize__middle(list(instruction), bool, list(instruction),
- io__state, io__state).
-:- mode optimize__middle(in, in, out, di, uo) is det.
+:- pred optimize__middle(list(instruction)::in, bool::in, set(label)::in,
+ list(instruction)::out, io__state::di, io__state::uo) is det.
-optimize__middle(Instrs0, Final, Instrs) -->
+optimize__middle(Instrs0, Final, LayoutLabelSet, Instrs) -->
globals__io_lookup_bool_option(very_verbose, VeryVerbose),
globals__io_lookup_bool_option(debug_opt, DebugOpt),
{ opt_util__find_first_label(Instrs0, Label) },
@@ -239,7 +256,8 @@
;
[]
),
- { jumpopt_main(Instrs1, FullJumpopt, Final, Instrs2, Mod2) },
+ { jumpopt_main(Instrs1, FullJumpopt, Final,
+ Instrs2, Mod2) },
( { Mod2 = yes } ->
opt_debug__msg(DebugOpt, "after jump optimization"),
opt_debug__dump_instrs(DebugOpt, Instrs2)
@@ -257,7 +275,8 @@
;
[]
),
- { labelopt_main(Instrs2, Final, Instrs, Mod3) },
+ { labelopt_main(Instrs2, Final, LayoutLabelSet,
+ Instrs, Mod3) },
( { Mod3 = yes } ->
opt_debug__msg(DebugOpt, "after label optimization"),
opt_debug__dump_instrs(DebugOpt, Instrs)
@@ -271,11 +290,10 @@
{ Instrs = Instrs0 }
).
-:- pred optimize__last(list(instruction), list(instruction),
- io__state, io__state).
-:- mode optimize__last(in, out, di, uo) is det.
+:- pred optimize__last(list(instruction)::in, set(label)::in,
+ list(instruction)::out, io__state::di, io__state::uo) is det.
-optimize__last(Instrs0, Instrs) -->
+optimize__last(Instrs0, LayoutLabelSet, Instrs) -->
globals__io_lookup_bool_option(very_verbose, VeryVerbose),
globals__io_lookup_bool_option(debug_opt, DebugOpt),
{ opt_util__find_first_label(Instrs0, Label) },
@@ -293,7 +311,7 @@
;
[]
),
- { labelopt_main(Instrs0, no, Instrs1, Mod1) },
+ { labelopt_main(Instrs0, no, LayoutLabelSet, Instrs1, Mod1) },
( { Mod1 = yes } ->
opt_debug__msg(DebugOpt, "after label optimization"),
opt_debug__dump_instrs(DebugOpt, Instrs1)
Index: compiler/value_number.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/value_number.m,v
retrieving revision 1.96
diff -u -b -u -r1.96 value_number.m
--- value_number.m 1998/11/06 06:27:49 1.96
+++ value_number.m 1999/03/04 04:01:43
@@ -1,5 +1,5 @@
%-----------------------------------------------------------------------------%
-% Copyright (C) 1994-1998 The University of Melbourne.
+% Copyright (C) 1994-1999 The University of Melbourne.
% This file may only be copied under the terms of the GNU General
% Public License - see the file COPYING in the Mercury distribution.
%-----------------------------------------------------------------------------%
@@ -14,15 +14,15 @@
:- interface.
-:- import_module list, io.
:- import_module llds.
+:- import_module list, set, io.
% Find straight-line code sequences and optimize them using
% value numbering.
-:- pred value_number_main(list(instruction), list(instruction),
+:- pred value_number_main(list(instruction), set(label), list(instruction),
io__state, io__state).
-:- mode value_number_main(in, out, di, uo) is det.
+:- mode value_number_main(in, in, out, di, uo) is det.
% The main value numbering pass introduces references to temporary
% variables whose values need be preserved only within an extended
@@ -39,24 +39,24 @@
:- implementation.
-:- import_module set, map, bimap, require, int, string, std_util, assoc_list.
-:- import_module bool.
-
:- import_module vn_type, vn_table, vn_block, vn_order, vn_flush, vn_temploc.
:- import_module vn_cost, vn_debug, vn_util, vn_verify, vn_filter.
:- import_module opt_debug, opt_util, peephole, labelopt.
:- import_module globals, options, livemap, code_util.
+:- import_module map, bimap, require, int, string, std_util, assoc_list.
+:- import_module bool.
+
% We can't find out what variables are used by C code sequences,
% so we don't optimize any predicates containing them.
-value_number_main(Instrs0, Instrs) -->
+value_number_main(Instrs0, LayoutLabelSet, Instrs) -->
{ opt_util__get_prologue(Instrs0, ProcLabel,
LabelInstr, Comments, Instrs1) },
{ opt_util__new_label_no(Instrs1, 1000, N0) },
{ value_number__prepare_for_vn([LabelInstr | Instrs1], ProcLabel,
no, AllocSet, BreakSet, N0, N, Instrs2) },
- { labelopt__build_useset(Instrs2, UseSet) },
+ { labelopt__build_useset(Instrs2, LayoutLabelSet, UseSet) },
{ livemap__build(Instrs2, MaybeLiveMap) },
(
{ MaybeLiveMap = yes(LiveMap) },
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
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/dynamic_linking
cvs diff: Diffing extras/exceptions
cvs diff: Diffing extras/graphics
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/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing library
cvs diff: Diffing lp_solve
cvs diff: Diffing lp_solve/lp_examples
cvs diff: Diffing profiler
cvs diff: Diffing runtime
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 scripts
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
cvs diff: Diffing tests/dppd
cvs diff: Diffing tests/general
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trace
cvs diff: Diffing trial
cvs diff: Diffing util
More information about the developers
mailing list