[m-dev.] for review: counters for label and cell number allocation
Zoltan Somogyi
zs at cs.mu.OZ.AU
Wed Aug 9 14:03:20 AEST 2000
Consistently use counters to allocate label numbers and cell numbers
throughout the compiler.
compiler/hlds_module.m:
Change the module_info structure to store a counter instead of an
integer for cell numbers.
compiler/llds.m:
Change the c_procedure structure to include a proc_label and a counter,
to allow LLDS to LLDS optimizations to use this counter to allocate
new label numbers. (The labels also include the proc_label.)
compiler/code_info.m:
Change the code_info structure to store counters instead of integers
for both label numbers and cell numbers.
compiler/code_gen.m:
When creating the c_procedure, copy the final value of the counter
from code_info to the c_procedure.
compiler/opt_util.m:
Delete the existing, inefficient procedure for allocating label
numbers, and modify the interface of the get_prologue predicate
to no longer return the proc_label (since it can now be looked up
more directly).
compiler/*.m:
Minor changes to conform to the new data structures and to use
counters instead of direct addition.
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 compiler
Index: compiler/basic_block.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/basic_block.m,v
retrieving revision 1.9
diff -u -r1.9 basic_block.m
--- compiler/basic_block.m 1999/11/15 00:42:07 1.9
+++ compiler/basic_block.m 2000/08/07 15:02:00
@@ -18,7 +18,7 @@
:- interface.
:- import_module llds.
-:- import_module list, map, std_util.
+:- import_module list, map, std_util, counter.
:- type block_map == map(label, block_info).
@@ -40,7 +40,8 @@
).
:- pred create_basic_blocks(list(instruction)::in, list(instruction)::out,
- proc_label::out, int::out, list(label)::out, block_map::out) is det.
+ proc_label::in, counter::in, counter::out,
+ list(label)::out, block_map::out) is det.
:- pred flatten_basic_blocks(list(label)::in, block_map::in,
list(instruction)::out) is det.
@@ -52,15 +53,14 @@
:- import_module opt_util.
:- import_module bool, int, require.
-create_basic_blocks(Instrs0, Comments, ProcLabel, N,
+create_basic_blocks(Instrs0, Comments, ProcLabel, C0, C,
LabelSeq, BlockMap) :-
- opt_util__get_prologue(Instrs0, ProcLabel, LabelInstr,
- Comments, AfterLabelInstrs),
+ opt_util__get_prologue(Instrs0, LabelInstr, Comments,
+ AfterLabelInstrs),
Instrs1 = [LabelInstr | AfterLabelInstrs],
- opt_util__new_label_no(Instrs0, 1000, N0),
map__init(BlockMap0),
build_block_map(Instrs1, LabelSeq, BlockMap0, BlockMap,
- ProcLabel, N0, N).
+ ProcLabel, C0, C).
% Add labels to the given instruction sequence so that
% every basic block has labels around it.
@@ -68,27 +68,27 @@
%-----------------------------------------------------------------------------%
:- pred build_block_map(list(instruction)::in, list(label)::out,
- block_map::in, block_map::out, proc_label::in, int::in, int::out)
- is det.
+ block_map::in, block_map::out, proc_label::in,
+ counter::in, counter::out) is det.
-build_block_map([], [], BlockMap, BlockMap, _, N, N).
+build_block_map([], [], BlockMap, BlockMap, _, C, C).
build_block_map([OrigInstr0 | OrigInstrs0], LabelSeq, BlockMap0, BlockMap,
- ProcLabel, N0, N) :-
+ ProcLabel, C0, C) :-
( OrigInstr0 = label(OrigLabel) - _ ->
Label = OrigLabel,
LabelInstr = OrigInstr0,
RestInstrs = OrigInstrs0,
- N1 = N0
+ C1 = C0
;
- N1 is N0 + 1,
- Label = local(ProcLabel, N0),
+ counter__allocate(N, C0, C1),
+ Label = local(ProcLabel, N),
LabelInstr = label(Label) - "",
RestInstrs = [OrigInstr0 | OrigInstrs0]
),
(
take_until_end_of_block(RestInstrs, BlockInstrs, Instrs1),
build_block_map(Instrs1, LabelSeq0,
- BlockMap0, BlockMap1, ProcLabel, N1, N),
+ BlockMap0, BlockMap1, ProcLabel, C1, C),
( list__last(BlockInstrs, LastInstr) ->
LastInstr = LastUinstr - _,
possible_targets(LastUinstr, SideLabels),
Index: compiler/code_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/code_gen.m,v
retrieving revision 1.77
diff -u -r1.77 code_gen.m
--- compiler/code_gen.m 2000/04/26 05:40:04 1.77
+++ compiler/code_gen.m 2000/08/07 15:00:05
@@ -32,7 +32,7 @@
:- import_module hlds_module, hlds_pred, hlds_goal, llds, code_info.
:- import_module globals.
-:- import_module list, io.
+:- import_module list, io, counter.
% Translate a HLDS module to LLDS.
@@ -47,7 +47,7 @@
:- pred generate_proc_code(pred_info::in, proc_info::in,
proc_id::in, pred_id::in, module_info::in, globals::in,
- global_data::in, global_data::out, int::in, int::out,
+ global_data::in, global_data::out, counter::in, counter::out,
c_procedure::out) is det.
% Translate a HLDS goal to LLDS.
@@ -133,32 +133,33 @@
;
[]
),
- { module_info_get_cell_count(ModuleInfo0, CellCount0) },
+ { module_info_get_cell_counter(ModuleInfo0, CellCounter0) },
globals__io_get_globals(Globals),
{ generate_proc_list_code(ProcIds, PredId, PredInfo, ModuleInfo0,
- Globals, GlobalData0, GlobalData, CellCount0, CellCount,
+ Globals, GlobalData0, GlobalData, CellCounter0, CellCounter,
[], Code) },
- { module_info_set_cell_count(ModuleInfo0, CellCount, ModuleInfo) }.
+ { module_info_set_cell_counter(ModuleInfo0, CellCounter, ModuleInfo) }.
% Translate all the procedures of a HLDS predicate to LLDS.
:- pred generate_proc_list_code(list(proc_id)::in, pred_id::in, pred_info::in,
module_info::in, globals::in, global_data::in, global_data::out,
- int::in, int::out, list(c_procedure)::in, list(c_procedure)::out)
- is det.
+ counter::in, counter::out,
+ list(c_procedure)::in, list(c_procedure)::out) is det.
generate_proc_list_code([], _PredId, _PredInfo, _ModuleInfo, _Globals,
- GlobalData, GlobalData, CellCount, CellCount, Procs, Procs).
+ GlobalData, GlobalData, CellCounter, CellCounter,
+ Procs, Procs).
generate_proc_list_code([ProcId | ProcIds], PredId, PredInfo, ModuleInfo0,
- Globals, GlobalData0, GlobalData, CellCount0, CellCount,
+ Globals, GlobalData0, GlobalData, CellCounter0, CellCounter,
Procs0, Procs) :-
pred_info_procedures(PredInfo, ProcInfos),
map__lookup(ProcInfos, ProcId, ProcInfo),
generate_proc_code(PredInfo, ProcInfo, ProcId, PredId, ModuleInfo0,
- Globals, GlobalData0, GlobalData1, CellCount0, CellCount1,
+ Globals, GlobalData0, GlobalData1, CellCounter0, CellCounter1,
Proc),
generate_proc_list_code(ProcIds, PredId, PredInfo, ModuleInfo0,
- Globals, GlobalData1, GlobalData, CellCount1, CellCount,
+ Globals, GlobalData1, GlobalData, CellCounter1, CellCounter,
[Proc | Procs0], Procs).
%---------------------------------------------------------------------------%
@@ -181,7 +182,7 @@
%---------------------------------------------------------------------------%
generate_proc_code(PredInfo, ProcInfo, ProcId, PredId, ModuleInfo, Globals,
- GlobalData0, GlobalData, CellCount0, CellCount, Proc) :-
+ GlobalData0, GlobalData, CellCounter0, CellCounter, Proc) :-
proc_info_interface_determinism(ProcInfo, Detism),
proc_info_interface_code_model(ProcInfo, CodeModel),
proc_info_goal(ProcInfo, Goal),
@@ -209,7 +210,7 @@
% needed for model_non procedures only if we are doing
% execution tracing.
code_info__init(SaveSuccip, Globals, PredId, ProcId, ProcInfo,
- FollowVars, ModuleInfo, CellCount0, OutsideResumePoint,
+ FollowVars, ModuleInfo, CellCounter0, OutsideResumePoint,
TraceSlotInfo, CodeInfo0),
% Generate code for the procedure.
@@ -217,7 +218,7 @@
TraceSlotInfo, CodeTree, MaybeTraceCallLabel, FrameInfo,
CodeInfo0, CodeInfo),
code_info__get_max_reg_in_use_at_trace(MaxTraceReg, CodeInfo, _),
- code_info__get_cell_count(CellCount, CodeInfo, _),
+ code_info__get_cell_counter(CellCounter, CodeInfo, _),
% Turn the code tree into a list.
tree__flatten(CodeTree, FragmentList),
@@ -255,8 +256,9 @@
code_info__get_non_common_static_data(NonCommonStatics, CodeInfo, _),
global_data_add_new_non_common_static_datas(GlobalData1,
NonCommonStatics, GlobalData2),
+ code_util__make_proc_label(ModuleInfo, PredId, ProcId, ProcLabel),
maybe_add_tabling_pointer_var(ModuleInfo, PredId, ProcId, ProcInfo,
- GlobalData2, GlobalData),
+ ProcLabel, GlobalData2, GlobalData),
pred_info_name(PredInfo, Name),
pred_info_arity(PredInfo, Arity),
@@ -268,19 +270,23 @@
),
% Construct a c_procedure structure with all the information.
- Proc = c_procedure(Name, Arity, proc(PredId, ProcId),
- Instructions, ContainsReconstruction).
+ code_info__get_label_counter(LabelCounter, CodeInfo, _),
+ % For historical reasons, the code generator allocates labels
+ % by remembering the last allocated label number, while the
+ % various optimizations remember the next label number to be
+ % allocated. The addition in the last argument performs the
+ % conversion.
+ Proc = c_procedure(Name, Arity, proc(PredId, ProcId), Instructions,
+ ProcLabel, LabelCounter, ContainsReconstruction).
:- pred maybe_add_tabling_pointer_var(module_info, pred_id, proc_id, proc_info,
- global_data, global_data).
-:- mode maybe_add_tabling_pointer_var(in, in, in, in, in, out) is det.
+ proc_label, global_data, global_data).
+:- mode maybe_add_tabling_pointer_var(in, in, in, in, in, in, out) is det.
-maybe_add_tabling_pointer_var(ModuleInfo, PredId, ProcId, ProcInfo,
+maybe_add_tabling_pointer_var(ModuleInfo, PredId, ProcId, ProcInfo, ProcLabel,
GlobalData0, GlobalData) :-
proc_info_eval_method(ProcInfo, EvalMethod),
( eval_method_has_per_proc_tabling_pointer(EvalMethod) = yes ->
- code_util__make_proc_label(ModuleInfo, PredId, ProcId,
- ProcLabel),
module_info_name(ModuleInfo, ModuleName),
Var = tabling_pointer_var(ModuleName, ProcLabel),
global_data_add_new_proc_var(GlobalData0,
Index: compiler/code_info.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/code_info.m,v
retrieving revision 1.249
diff -u -r1.249 code_info.m
--- compiler/code_info.m 2000/04/26 05:40:06 1.249
+++ compiler/code_info.m 2000/08/07 14:59:57
@@ -32,7 +32,7 @@
:- import_module hlds_module, hlds_pred, hlds_goal, llds, instmap, trace.
:- import_module continuation_info, prog_data, hlds_data, globals.
-:- import_module bool, set, list, map, std_util, assoc_list.
+:- import_module bool, set, list, map, std_util, assoc_list, counter.
:- implementation.
@@ -65,155 +65,147 @@
% Create a new code_info structure. Also return the
% outermost resumption point, and info about the non-fixed
% stack slots used for tracing purposes.
-:- pred code_info__init(bool, globals, pred_id, proc_id, proc_info,
- follow_vars, module_info, int, resume_point_info,
- trace_slot_info, code_info).
-:- mode code_info__init(in, in, in, in, in, in, in, in, out, out, out) is det.
+:- pred code_info__init(bool::in, globals::in, pred_id::in, proc_id::in,
+ proc_info::in, follow_vars::in, module_info::in, counter::in,
+ resume_point_info::out, trace_slot_info::out, code_info::out) is det.
% Get the globals table.
-:- pred code_info__get_globals(globals, code_info, code_info).
-:- mode code_info__get_globals(out, in, out) is det.
+:- pred code_info__get_globals(globals::out,
+ code_info::in, code_info::out) is det.
% Get the HLDS of the entire module.
-:- pred code_info__get_module_info(module_info, code_info, code_info).
-:- mode code_info__get_module_info(out, in, out) is det.
+:- pred code_info__get_module_info(module_info::out,
+ code_info::in, code_info::out) is det.
% Get the id of the predicate we are generating code for.
-:- pred code_info__get_pred_id(pred_id, code_info, code_info).
-:- mode code_info__get_pred_id(out, in, out) is det.
+:- pred code_info__get_pred_id(pred_id::out,
+ code_info::in, code_info::out) is det.
% Get the id of the procedure we are generating code for.
-:- pred code_info__get_proc_id(proc_id, code_info, code_info).
-:- mode code_info__get_proc_id(out, in, out) is det.
+:- pred code_info__get_proc_id(proc_id::out,
+ code_info::in, code_info::out) is det.
% Get the HLDS of the procedure we are generating code for.
-:- pred code_info__get_proc_info(proc_info, code_info, code_info).
-:- mode code_info__get_proc_info(out, in, out) is det.
+:- pred code_info__get_proc_info(proc_info::out,
+ code_info::in, code_info::out) is det.
% Get the variables for the current procedure.
-:- pred code_info__get_varset(prog_varset, code_info, code_info).
-:- mode code_info__get_varset(out, in, out) is det.
+:- pred code_info__get_varset(prog_varset::out,
+ code_info::in, code_info::out) is det.
-:- pred code_info__get_maybe_trace_info(maybe(trace_info),
- code_info, code_info).
-:- mode code_info__get_maybe_trace_info(out, in, out) is det.
+:- pred code_info__get_maybe_trace_info(maybe(trace_info)::out,
+ code_info::in, code_info::out) is det.
% Get the set of currently forward-live variables.
-:- pred code_info__get_forward_live_vars(set(prog_var), code_info, code_info).
-:- mode code_info__get_forward_live_vars(out, in, out) is det.
+:- pred code_info__get_forward_live_vars(set(prog_var)::out,
+ code_info::in, code_info::out) is det.
% Set the set of currently forward-live variables.
-:- pred code_info__set_forward_live_vars(set(prog_var), code_info, code_info).
-:- mode code_info__set_forward_live_vars(in, in, out) is det.
+:- pred code_info__set_forward_live_vars(set(prog_var)::in,
+ code_info::in, code_info::out) is det.
% Get the table mapping variables to the current
% instantiation states.
-:- pred code_info__get_instmap(instmap, code_info, code_info).
-:- mode code_info__get_instmap(out, in, out) is det.
+:- pred code_info__get_instmap(instmap::out,
+ code_info::in, code_info::out) is det.
% Set the table mapping variables to the current
% instantiation states.
-:- pred code_info__set_instmap(instmap, code_info, code_info).
-:- mode code_info__set_instmap(in, in, out) is det.
+:- pred code_info__set_instmap(instmap::in,
+ code_info::in, code_info::out) is det.
+
+ % The number of the last local label allocated.
+:- pred code_info__get_label_counter(counter::out,
+ code_info::in, code_info::out) is det.
% The current value of the counter we use to give
% each "create" rval its unique cell number, for use
% in case the cell can be allocated statically.
-:- pred code_info__get_cell_count(int, code_info, code_info).
-:- mode code_info__get_cell_count(out, in, out) is det.
+:- pred code_info__get_cell_counter(counter::out,
+ code_info::in, code_info::out) is det.
-:- pred code_info__set_cell_count(int, code_info, code_info).
-:- mode code_info__set_cell_count(in, in, out) is det.
+:- pred code_info__set_cell_counter(counter::in,
+ code_info::in, code_info::out) is det.
% Get the flag that indicates whether succip is used or not.
-:- pred code_info__get_succip_used(bool, code_info, code_info).
-:- mode code_info__get_succip_used(out, in, out) is det.
+:- pred code_info__get_succip_used(bool::out,
+ code_info::in, code_info::out) is det.
% Get the label layout information created by tracing
% during code generation.
-:- pred code_info__get_layout_info(map(label, internal_layout_info),
- code_info, code_info).
-:- mode code_info__get_layout_info(out, in, out) is det.
+:- pred code_info__get_layout_info(map(label, internal_layout_info)::out,
+ code_info::in, code_info::out) is det.
% Get the global static data structures that have
% been created during code generation and which do
% not have to be scanned by llds_common, since they
% have no common parts by construction.
-:- pred code_info__get_non_common_static_data(list(comp_gen_c_data),
- code_info, code_info).
-:- mode code_info__get_non_common_static_data(out, in, out) is det.
+:- pred code_info__get_non_common_static_data(list(comp_gen_c_data)::out,
+ code_info::in, code_info::out) is det.
-:- pred code_info__get_max_reg_in_use_at_trace(int, code_info, code_info).
-:- mode code_info__get_max_reg_in_use_at_trace(out, in, out) is det.
+:- pred code_info__get_max_reg_in_use_at_trace(int::out,
+ code_info::in, code_info::out) is det.
-:- pred code_info__set_max_reg_in_use_at_trace(int, code_info, code_info).
-:- mode code_info__set_max_reg_in_use_at_trace(in, in, out) is det.
+:- pred code_info__set_max_reg_in_use_at_trace(int::in,
+ code_info::in, code_info::out) is det.
%---------------------------------------------------------------------------%
:- implementation.
-
-:- pred code_info__get_var_slot_count(int, code_info, code_info).
-:- mode code_info__get_var_slot_count(out, in, out) is det.
-:- pred code_info__set_maybe_trace_info(maybe(trace_info),
- code_info, code_info).
-:- mode code_info__set_maybe_trace_info(in, in, out) is det.
+:- pred code_info__get_var_slot_count(int::out,
+ code_info::in, code_info::out) is det.
-:- pred code_info__get_zombies(set(prog_var), code_info, code_info).
-:- mode code_info__get_zombies(out, in, out) is det.
+:- pred code_info__set_maybe_trace_info(maybe(trace_info)::in,
+ code_info::in, code_info::out) is det.
-:- pred code_info__set_zombies(set(prog_var), code_info, code_info).
-:- mode code_info__set_zombies(in, in, out) is det.
+:- pred code_info__get_zombies(set(prog_var)::out,
+ code_info::in, code_info::out) is det.
-:- pred code_info__get_exprn_info(exprn_info, code_info, code_info).
-:- mode code_info__get_exprn_info(out, in, out) is det.
+:- pred code_info__set_zombies(set(prog_var)::in,
+ code_info::in, code_info::out) is det.
-:- pred code_info__set_exprn_info(exprn_info, code_info, code_info).
-:- mode code_info__set_exprn_info(in, in, out) is det.
+:- pred code_info__get_exprn_info(exprn_info::out,
+ code_info::in, code_info::out) is det.
-:- pred code_info__get_temps_in_use(set(lval), code_info, code_info).
-:- mode code_info__get_temps_in_use(out, in, out) is det.
+:- pred code_info__set_exprn_info(exprn_info::in,
+ code_info::in, code_info::out) is det.
-:- pred code_info__set_temps_in_use(set(lval), code_info, code_info).
-:- mode code_info__set_temps_in_use(in, in, out) is det.
+:- pred code_info__get_temps_in_use(set(lval)::out,
+ code_info::in, code_info::out) is det.
-:- pred code_info__get_fail_info(fail_info, code_info, code_info).
-:- mode code_info__get_fail_info(out, in, out) is det.
+:- pred code_info__set_temps_in_use(set(lval)::in,
+ code_info::in, code_info::out) is det.
-:- pred code_info__set_fail_info(fail_info, code_info, code_info).
-:- mode code_info__set_fail_info(in, in, out) is det.
+:- pred code_info__get_fail_info(fail_info::out,
+ code_info::in, code_info::out) is det.
-:- pred code_info__get_label_count(int, code_info, code_info).
-:- mode code_info__get_label_count(out, in, out) is det.
+:- pred code_info__set_fail_info(fail_info::in,
+ code_info::in, code_info::out) is det.
-:- pred code_info__set_label_count(int, code_info, code_info).
-:- mode code_info__set_label_count(in, in, out) is det.
+:- pred code_info__set_label_counter(counter::in,
+ code_info::in, code_info::out) is det.
-:- pred code_info__set_succip_used(bool, code_info, code_info).
-:- mode code_info__set_succip_used(in, in, out) is det.
+:- pred code_info__set_succip_used(bool::in,
+ code_info::in, code_info::out) is det.
-:- pred code_info__set_layout_info(map(label, internal_layout_info),
- code_info, code_info).
-:- mode code_info__set_layout_info(in, in, out) is det.
+:- pred code_info__set_layout_info(map(label, internal_layout_info)::in,
+ code_info::in, code_info::out) is det.
-:- pred code_info__get_max_temp_slot_count(int, code_info, code_info).
-:- mode code_info__get_max_temp_slot_count(out, in, out) is det.
+:- pred code_info__get_max_temp_slot_count(int::out,
+ code_info::in, code_info::out) is det.
-:- pred code_info__set_max_temp_slot_count(int, code_info, code_info).
-:- mode code_info__set_max_temp_slot_count(in, in, out) is det.
+:- pred code_info__set_max_temp_slot_count(int::in,
+ code_info::in, code_info::out) is det.
-:- pred code_info__get_temp_content_map(map(lval, slot_contents),
- code_info, code_info).
-:- mode code_info__get_temp_content_map(out, in, out) is det.
+:- pred code_info__get_temp_content_map(map(lval, slot_contents)::out,
+ code_info::in, code_info::out) is det.
-:- pred code_info__set_temp_content_map(map(lval, slot_contents),
- code_info, code_info).
-:- mode code_info__set_temp_content_map(in, in, out) is det.
+:- pred code_info__set_temp_content_map(map(lval, slot_contents)::in,
+ code_info::in, code_info::out) is det.
-:- pred code_info__set_non_common_static_data(list(comp_gen_c_data),
- code_info, code_info).
-:- mode code_info__set_non_common_static_data(in, in, out) is det.
+:- pred code_info__set_non_common_static_data(list(comp_gen_c_data)::in,
+ code_info::in, code_info::out) is det.
%---------------------------------------------------------------------------%
@@ -284,17 +276,17 @@
% Information about how to manage failures.
% PERSISTENT fields
- next_label_num :: int,
+ label_num_src :: counter,
% Counter for the local labels used
% by this procedure.
- next_cell_num :: int,
+ cell_num_src :: counter,
% Counter for cells in this proc.
store_succip :: bool,
% do we need to store succip?
label_info :: map(label, internal_layout_info),
% Information on which values
% are live and where at which labels,
- % for tracing. Accurate gc
+ % for tracing and/or accurate gc.
stackslot_max :: int,
% The maximum number of extra
% temporary stackslots that have been
@@ -329,7 +321,8 @@
%---------------------------------------------------------------------------%
code_info__init(SaveSuccip, Globals, PredId, ProcId, ProcInfo, FollowVars,
- ModuleInfo, CellCount, ResumePoint, TraceSlotInfo, CodeInfo) :-
+ ModuleInfo, CellCounter, ResumePoint, TraceSlotInfo, CodeInfo)
+ :-
proc_info_get_initial_instmap(ProcInfo, ModuleInfo, InstMap),
proc_info_liveness_info(ProcInfo, Liveness),
proc_info_headvars(ProcInfo, HeadVars),
@@ -377,8 +370,8 @@
TempsInUse,
DummyFailInfo, % code_info__init_fail_info
% will override this dummy value
- 0,
- CellCount,
+ counter__init(1),
+ CellCounter,
SaveSuccip,
LayoutMap,
0,
@@ -411,79 +404,44 @@
%---------------------------------------------------------------------------%
code_info__get_globals(CI^globals, CI, CI).
-
code_info__get_module_info(CI^module_info, CI, CI).
-
code_info__get_pred_id(CI^pred_id, CI, CI).
-
code_info__get_proc_id(CI^proc_id, CI, CI).
-
code_info__get_proc_info(CI^proc_info, CI, CI).
-
code_info__get_varset(CI^varset, CI, CI).
-
code_info__get_var_slot_count(CI^var_slot_count, CI, CI).
-
code_info__get_maybe_trace_info(CI^maybe_trace_info, CI, CI).
-
code_info__get_forward_live_vars(CI^forward_live_vars, CI, CI).
-
code_info__get_instmap(CI^instmap, CI, CI).
-
code_info__get_zombies(CI^zombies, CI, CI).
-
code_info__get_exprn_info(CI^exprn_info, CI, CI).
-
code_info__get_temps_in_use(CI^temps_in_use, CI, CI).
-
code_info__get_fail_info(CI^fail_info, CI, CI).
-
-code_info__get_label_count(CI^next_label_num, CI, CI).
-
-code_info__get_cell_count(CI^next_cell_num, CI, CI).
-
+code_info__get_label_counter(CI^label_num_src, CI, CI).
+code_info__get_cell_counter(CI^cell_num_src, CI, CI).
code_info__get_succip_used(CI^store_succip, CI, CI).
-
code_info__get_layout_info(CI^label_info, CI, CI).
-
code_info__get_max_temp_slot_count(CI^stackslot_max, CI, CI).
-
code_info__get_temp_content_map(CI^temp_contents, CI, CI).
-
code_info__get_non_common_static_data(CI^comp_gen_c_data, CI, CI).
-
code_info__get_max_reg_in_use_at_trace(CI^max_reg_used, CI, CI).
%---------------------------------------------------------------------------%
code_info__set_maybe_trace_info(TI, CI, CI^maybe_trace_info := TI).
-
code_info__set_forward_live_vars(LV, CI, CI^forward_live_vars := LV).
-
code_info__set_instmap(IM, CI, CI^instmap := IM).
-
code_info__set_zombies(Zs, CI, CI^zombies := Zs).
-
code_info__set_exprn_info(EI, CI, CI^exprn_info := EI).
-
code_info__set_temps_in_use(TI, CI, CI^temps_in_use := TI).
-
code_info__set_fail_info(FI, CI, CI^fail_info := FI).
-
-code_info__set_label_count(LC, CI, CI^next_label_num := LC).
-
-code_info__set_cell_count(CC, CI, CI^next_cell_num := CC).
-
+code_info__set_label_counter(LC, CI, CI^label_num_src := LC).
+code_info__set_cell_counter(CC, CI, CI^cell_num_src := CC).
code_info__set_succip_used(SU, CI, CI^store_succip := SU).
-
code_info__set_layout_info(LI, CI, CI^label_info := LI).
-
code_info__set_max_temp_slot_count(TM, CI, CI^stackslot_max := TM).
-
code_info__set_temp_content_map(CM, CI, CI^temp_contents := CM).
-
code_info__set_non_common_static_data(CG, CI, CI^comp_gen_c_data := CG).
-
code_info__set_max_reg_in_use_at_trace(MR, CI, CI^max_reg_used := MR).
%---------------------------------------------------------------------------%
@@ -762,16 +720,16 @@
code_info__get_module_info(ModuleInfo),
code_info__get_pred_id(PredId),
code_info__get_proc_id(ProcId),
- code_info__get_label_count(N0),
- { N is N0 + 1 },
- code_info__set_label_count(N),
+ code_info__get_label_counter(C0),
+ { counter__allocate(N, C0, C) },
+ code_info__set_label_counter(C),
{ code_util__make_internal_label(ModuleInfo, PredId, ProcId, N,
Label) }.
code_info__get_next_cell_number(N) -->
- code_info__get_cell_count(N0),
- { N is N0 + 1 },
- code_info__set_cell_count(N).
+ code_info__get_cell_counter(C0),
+ { counter__allocate(N, C0, C) },
+ code_info__set_cell_counter(C).
code_info__succip_is_used -->
code_info__set_succip_used(yes).
@@ -877,7 +835,7 @@
code_info__reset_to_position(position_info(PosCI), CurCI, NextCI) :-
% The static fields in PosCI and CurCI should be identical.
- PosCI = code_info(_, _, _, _, _, _, _, _,
+ PosCI = code_info(_, _, _, _, _, _, _, _,
LA, LB, LC, LD, LE, LF, _, _, _, _, _, _, _, _ ),
CurCI = code_info(SA, SB, SC, SD, SE, SF, SG, SH,
_, _, _, _, _, _, PA, PB, PC, PD, PE, PF, PG, PH),
@@ -1068,7 +1026,7 @@
:- type simple_neg_info.
-:- pred code_info__enter_simple_neg(set(prog_var)::in, hlds_goal_info::in,
+:- pred code_info__enter_simple_neg(set(prog_var)::in, hlds_goal_info::in,
simple_neg_info::out, code_info::in, code_info::out) is det.
:- pred code_info__leave_simple_neg(hlds_goal_info::in, simple_neg_info::in,
Index: compiler/continuation_info.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/continuation_info.m,v
retrieving revision 1.31
diff -u -r1.31 continuation_info.m
--- compiler/continuation_info.m 2000/02/16 02:15:35 1.31
+++ compiler/continuation_info.m 2000/08/07 09:26:56
@@ -297,7 +297,7 @@
continuation_info__maybe_process_llds([], _) --> [].
continuation_info__maybe_process_llds([Proc | Procs], ModuleInfo) -->
- { Proc = c_procedure(_, _, PredProcId, Instrs, _) },
+ { Proc = c_procedure(_, _, PredProcId, Instrs, _, _, _) },
continuation_info__maybe_process_proc_llds(Instrs, PredProcId,
ModuleInfo),
continuation_info__maybe_process_llds(Procs, ModuleInfo).
Index: compiler/dupelim.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/dupelim.m,v
retrieving revision 1.47
diff -u -r1.47 dupelim.m
--- compiler/dupelim.m 2000/04/26 05:40:11 1.47
+++ compiler/dupelim.m 2000/08/07 14:55:37
@@ -43,9 +43,11 @@
:- interface.
-:- import_module list, llds.
+:- import_module llds.
+:- import_module list, counter.
-:- pred dupelim_main(list(instruction)::in, list(instruction)::out) is det.
+:- pred dupelim_main(list(instruction)::in, proc_label::in,
+ counter::in, counter::out, list(instruction)::out) is det.
%-----------------------------------------------------------------------------%
@@ -65,8 +67,8 @@
% OtherLabels must be nonempty.
:- type cluster ---> cluster(label, list(label)).
-dupelim_main(Instrs0, Instrs) :-
- create_basic_blocks(Instrs0, Comments, _ProcLabel, _N,
+dupelim_main(Instrs0, ProcLabel, C0, C, Instrs) :-
+ create_basic_blocks(Instrs0, Comments, ProcLabel, C0, C,
LabelSeq0, BlockMap0),
map__init(StdMap0),
set__init(Fixed0),
Index: compiler/frameopt.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/frameopt.m,v
retrieving revision 1.75
diff -u -r1.75 frameopt.m
--- compiler/frameopt.m 2000/04/26 05:40:13 1.75
+++ compiler/frameopt.m 2000/08/07 15:01:08
@@ -89,14 +89,15 @@
:- interface.
:- import_module llds.
-:- import_module bool, list.
+:- import_module bool, list, counter.
% The first bool output says whether we performed any modifications.
% If yes, then we also introduced some extra labels that should be
% deleted. The second says whether we introduced any jumps that
% can be profitably be short-circuited.
-:- pred frameopt_main(list(instruction)::in, list(instruction)::out,
+:- pred frameopt_main(list(instruction)::in, proc_label::in,
+ counter::in, counter::out, list(instruction)::out,
bool::out, bool::out) is det.
%-----------------------------------------------------------------------------%
@@ -106,18 +107,16 @@
:- import_module livemap, prog_data, opt_util, code_util, opt_debug.
:- import_module int, string, require, std_util, assoc_list, set, map, queue.
-frameopt_main(Instrs0, Instrs, Mod, Jumps) :-
- opt_util__get_prologue(Instrs0, ProcLabel, LabelInstr,
- Comments0, Instrs1),
+frameopt_main(Instrs0, ProcLabel, C0, C, Instrs, Mod, Jumps) :-
+ opt_util__get_prologue(Instrs0, LabelInstr, Comments0, Instrs1),
(
frameopt__detstack_setup(Instrs1, FrameSize, Msg, _, _, _)
->
- opt_util__new_label_no(Instrs0, 1000, N0),
map__init(BlockMap0),
- divide_into_basic_blocks([LabelInstr | Instrs1], ProcLabel, N0,
- BasicInstrs, N1),
+ divide_into_basic_blocks([LabelInstr | Instrs1], ProcLabel, C0,
+ BasicInstrs, C1),
build_block_map(BasicInstrs, FrameSize, LabelSeq0,
- BlockMap0, BlockMap1, ProcLabel, N1, N2),
+ BlockMap0, BlockMap1, ProcLabel, C1, C2),
analyze_block_map(LabelSeq0, BlockMap1, BlockMap2, KeepFrame),
(
KeepFrame = yes(FirstLabel - SecondLabel),
@@ -131,14 +130,15 @@
list__append(Comments0, [NewComment], Comments),
flatten_block_seq(LabelSeq, BlockMap, BodyInstrs),
list__append(Comments, BodyInstrs, Instrs),
+ C = C2,
Mod = yes,
Jumps = yes
;
KeepFrame = no,
( can_delay_frame(LabelSeq0, BlockMap2, yes) ->
delay_frame(LabelSeq0, BlockMap2,
- FrameSize, Msg,
- ProcLabel, N2, LabelSeq, BlockMap),
+ FrameSize, Msg, ProcLabel, C2, C,
+ LabelSeq, BlockMap),
NewComment = comment("delaying stack frame")
- "",
list__append(Comments0, [NewComment], Comments),
@@ -149,12 +149,14 @@
Jumps = no
;
Instrs = Instrs0,
+ C = C0,
Mod = no,
Jumps = no
)
)
;
Instrs = Instrs0,
+ C = C0,
Mod = no,
Jumps = no
).
@@ -212,36 +214,36 @@
% every basic block has labels around it.
:- pred divide_into_basic_blocks(list(instruction)::in, proc_label::in,
- int::in, list(instruction)::out, int::out) is det.
+ counter::in, list(instruction)::out, counter::out) is det.
-divide_into_basic_blocks([], _, N, [], N).
+divide_into_basic_blocks([], _, C, [], C).
% Control can fall of the end of a procedure if that procedure
% ends with a call to another procedure that cannot succeed.
% This is the only situation in which the base case can be reached.
-divide_into_basic_blocks([Instr0 | Instrs0], ProcLabel, N0, Instrs, N) :-
+divide_into_basic_blocks([Instr0 | Instrs0], ProcLabel, C0, Instrs, C) :-
Instr0 = Uinstr0 - _Comment,
( opt_util__can_instr_branch_away(Uinstr0, yes) ->
(
Instrs0 = [Instr1 | _],
( Instr1 = label(_) - _ ->
divide_into_basic_blocks(Instrs0, ProcLabel,
- N0, Instrs1, N),
+ C0, Instrs1, C),
Instrs = [Instr0 | Instrs1]
;
- N1 is N0 + 1,
- NewLabel = local(ProcLabel, N0),
+ counter__allocate(N, C0, C1),
+ NewLabel = local(ProcLabel, N),
NewInstr = label(NewLabel) - "",
divide_into_basic_blocks(Instrs0, ProcLabel,
- N1, Instrs1, N),
+ C1, Instrs1, C),
Instrs = [Instr0, NewInstr | Instrs1]
)
;
Instrs0 = [],
Instrs = [Instr0],
- N = N0
+ C = C0
)
;
- divide_into_basic_blocks(Instrs0, ProcLabel, N0, Instrs1, N),
+ divide_into_basic_blocks(Instrs0, ProcLabel, C0, Instrs1, C),
Instrs = [Instr0 | Instrs1]
).
@@ -268,12 +270,12 @@
% order.
:- pred build_block_map(list(instruction)::in, int::in, list(label)::out,
- block_map::in, block_map::out, proc_label::in, int::in, int::out)
- is det.
+ block_map::in, block_map::out, proc_label::in,
+ counter::in, counter::out) is det.
-build_block_map([], _, [], BlockMap, BlockMap, _, N, N).
+build_block_map([], _, [], BlockMap, BlockMap, _, C, C).
build_block_map([Instr0 | Instrs0], FrameSize, LabelSeq, BlockMap0, BlockMap,
- ProcLabel, N0, N) :-
+ ProcLabel, C0, C) :-
( Instr0 = label(Label) - _ ->
(
frameopt__detstack_setup(Instrs0, _, _, Setup,
@@ -289,16 +291,16 @@
Instrs1 = [Instr1 | _],
Instr1 = label(_) - _
->
- N1 = N0,
+ C1 = C0,
Instrs2 = Instrs1
;
- N1 is N0 + 1,
- NewLabel = local(ProcLabel, N0),
+ counter__allocate(N, C0, C1),
+ NewLabel = local(ProcLabel, N),
NewInstr = label(NewLabel) - "",
Instrs2 = [NewInstr | Instrs1]
),
build_block_map(Instrs2, FrameSize, LabelSeq0,
- BlockMap0, BlockMap1, ProcLabel, N1, N),
+ BlockMap0, BlockMap1, ProcLabel, C1, C),
map__det_insert(BlockMap1, Label, BlockInfo, BlockMap),
LabelSeq = [Label | LabelSeq0]
;
@@ -310,7 +312,7 @@
list__append(Succip, Teardown1, Teardown),
( Tail = [] ->
MaybeTailInfo = no,
- N1 = N0,
+ C1 = C0,
LabelledBlock = [Instr0 | Teardown],
TeardownLabel = Label,
TeardownInfo = block_info(TeardownLabel,
@@ -321,8 +323,8 @@
TailInfo = block_info(Label, [Instr0 | Tail],
[], no, ordinary(Needs)),
MaybeTailInfo = yes(TailInfo - Label),
- N1 is N0 + 1,
- NewLabel = local(ProcLabel, N0),
+ counter__allocate(N, C0, C1),
+ NewLabel = local(ProcLabel, N),
NewInstr = label(NewLabel) - "",
LabelledBlock = [NewInstr | Teardown],
TeardownLabel = NewLabel,
@@ -331,7 +333,7 @@
teardown(Succip, Livevals, Goto))
),
build_block_map(Remain, FrameSize, LabelSeq0,
- BlockMap0, BlockMap1, ProcLabel, N1, N),
+ BlockMap0, BlockMap1, ProcLabel, C1, C),
(
MaybeTailInfo = no,
map__det_insert(BlockMap1, TeardownLabel,
@@ -352,7 +354,7 @@
BlockInfo = block_info(Label, [Instr0 | Block],
[], no, ordinary(Needs)),
build_block_map(Instrs1, FrameSize, LabelSeq0,
- BlockMap0, BlockMap1, ProcLabel, N0, N),
+ BlockMap0, BlockMap1, ProcLabel, C0, C),
map__det_insert(BlockMap1, Label, BlockInfo, BlockMap),
LabelSeq = [Label | LabelSeq0]
)
@@ -833,9 +835,10 @@
% either just before or just after the original block.
:- pred delay_frame(list(label)::in, block_map::in, int::in, string::in,
- proc_label::in, int::in, list(label)::out, block_map::out) is det.
+ proc_label::in, counter::in, counter::out,
+ list(label)::out, block_map::out) is det.
-delay_frame(LabelSeq0, BlockMap0, FrameSize, Msg, ProcLabel, N0,
+delay_frame(LabelSeq0, BlockMap0, FrameSize, Msg, ProcLabel, C0, C,
LabelSeq, BlockMap) :-
map__init(RevMap0),
queue__init(Queue0),
@@ -847,7 +850,7 @@
map__init(ParMap0),
set__init(FallIntoParallel0),
process_frame_delay(LabelSeq0, BlockMap0, ParMap0, FallIntoParallel0,
- FramedLabels, FrameSize, Msg, ProcLabel, N0,
+ FramedLabels, FrameSize, Msg, ProcLabel, C0, C,
LabelSeq1, BlockMap1, ParMap, FallIntoParallel),
create_parallels(LabelSeq1, BlockMap1, ParMap, FallIntoParallel,
LabelSeq, BlockMap).
@@ -958,14 +961,14 @@
% see the comment at the top of delay_frame.
:- pred process_frame_delay(list(label)::in, block_map::in,
- par_map::in, set(label)::in,
- set(label)::in, int::in, string::in, proc_label::in, int::in,
+ par_map::in, set(label)::in, set(label)::in, int::in, string::in,
+ proc_label::in, counter::in, counter::out,
list(label)::out, block_map::out, par_map::out, set(label)::out) is det.
-process_frame_delay([], BlockMap, ParMap, FallIntoParallel, _, _, _, _, _,
+process_frame_delay([], BlockMap, ParMap, FallIntoParallel, _, _, _, _, C, C,
[], BlockMap, ParMap, FallIntoParallel).
process_frame_delay([Label0 | Labels0], BlockMap0, ParMap0, FallIntoParallel0,
- FramedLabels, FrameSize, Msg, ProcLabel, N0,
+ FramedLabels, FrameSize, Msg, ProcLabel, C0, C,
Labels, BlockMap, ParMap, FallIntoParallel) :-
map__lookup(BlockMap0, Label0, BlockInfo0),
BlockInfo0 = block_info(Label0Copy, Instrs0, SideLabels0,
@@ -1000,6 +1003,7 @@
% we can't delay the frame setup,
% so return everything unchanged
Labels = [Label0 | Labels0],
+ C = C0,
BlockMap = BlockMap0,
ParMap = ParMap0,
FallIntoParallel = FallIntoParallel0
@@ -1010,7 +1014,7 @@
BlockMap1),
process_frame_delay(Labels0, BlockMap1,
ParMap0, FallIntoParallel0, FramedLabels,
- FrameSize, Msg, ProcLabel, N0,
+ FrameSize, Msg, ProcLabel, C0, C,
Labels1, BlockMap, ParMap, FallIntoParallel),
Labels = [Label0 | Labels1]
)
@@ -1024,7 +1028,7 @@
% successors expect one, so we need not do anything.
process_frame_delay(Labels0, BlockMap0,
ParMap0, FallIntoParallel0, FramedLabels,
- FrameSize, Msg, ProcLabel, N0,
+ FrameSize, Msg, ProcLabel, C0, C,
Labels1, BlockMap, ParMap, FallIntoParallel),
Labels = [Label0 | Labels1]
;
@@ -1038,30 +1042,30 @@
% instead.
transform_ordinary_block(Label0, Labels0, BlockInfo0,
BlockMap0, ParMap0, FallIntoParallel0,
- FramedLabels, FrameSize, Msg, ProcLabel, N0,
+ FramedLabels, FrameSize, Msg, ProcLabel, C0, C,
Labels, BlockMap, ParMap, FallIntoParallel)
)
;
Type = teardown(_, _, _),
process_frame_delay(Labels0, BlockMap0,
ParMap0, FallIntoParallel0, FramedLabels,
- FrameSize, Msg, ProcLabel, N0,
+ FrameSize, Msg, ProcLabel, C0, C,
Labels1, BlockMap, ParMap, FallIntoParallel),
Labels = [Label0 | Labels1]
).
:- pred transform_ordinary_block(label::in, list(label)::in, block_info::in,
- block_map::in, par_map::in, set(label)::in,
- set(label)::in, int::in, string::in, proc_label::in, int::in,
+ block_map::in, par_map::in, set(label)::in, set(label)::in, int::in,
+ string::in, proc_label::in, counter::in, counter::out,
list(label)::out, block_map::out, par_map::out, set(label)::out) is det.
transform_ordinary_block(Label0, Labels0, BlockInfo0, BlockMap0, ParMap0,
- FallIntoParallel0, FramedLabels, FrameSize, Msg,
- ProcLabel, N0, Labels, BlockMap, ParMap, FallIntoParallel) :-
+ FallIntoParallel0, FramedLabels, FrameSize, Msg, ProcLabel,
+ C0, C, Labels, BlockMap, ParMap, FallIntoParallel) :-
BlockInfo0 = block_info(_, Instrs0, SideLabels0,
MaybeFallThrough0, Type),
mark_parallels_for_teardown(SideLabels0, SideLabels,
- AssocLabelMap, BlockMap0, ProcLabel, N0, N1, ParMap0, ParMap1),
+ AssocLabelMap, BlockMap0, ProcLabel, C0, C1, ParMap0, ParMap1),
pick_last(Instrs0, PrevInstrs, LastInstr0),
map__from_assoc_list(AssocLabelMap, LabelMap),
opt_util__replace_labels_instruction(LastInstr0, LabelMap, no,
@@ -1083,10 +1087,10 @@
% stack frame to a block which needs a
% stack frame, so we must create one.
- NewLabel = local(ProcLabel, N1),
+ counter__allocate(N, C1, C2),
+ NewLabel = local(ProcLabel, N),
MaybeFallThrough = yes(NewLabel),
MaybeNewLabel = yes(NewLabel),
- N2 is N1 + 1,
SetupCode = [
label(NewLabel)
- "late setup label",
@@ -1104,7 +1108,7 @@
MaybeFallThrough = yes(FallThrough),
BlockMap1 = BlockMap0,
MaybeNewLabel = no,
- N2 = N1
+ C2 = C1
)
;
FallThroughType = teardown(_, _, _),
@@ -1113,7 +1117,7 @@
set__insert(FallIntoParallel0,
FallThrough, FallIntoParallel1),
MaybeNewLabel = no,
- mark_parallel(FallThrough, _, ProcLabel, N1, N2,
+ mark_parallel(FallThrough, _, ProcLabel, C1, C2,
ParMap1, ParMap2)
)
;
@@ -1123,13 +1127,13 @@
FallIntoParallel1 = FallIntoParallel0,
ParMap2 = ParMap1,
MaybeNewLabel = no,
- N2 = N1
+ C2 = C1
),
BlockInfo = block_info(Label0, Instrs, SideLabels,
MaybeFallThrough, Type),
map__set(BlockMap1, Label0, BlockInfo, BlockMap2),
process_frame_delay(Labels0, BlockMap2, ParMap2, FallIntoParallel1,
- FramedLabels, FrameSize, Msg, ProcLabel, N2,
+ FramedLabels, FrameSize, Msg, ProcLabel, C2, C,
Labels1, BlockMap, ParMap, FallIntoParallel),
( MaybeNewLabel = yes(NewLabel2) ->
Labels = [Label0, NewLabel2 | Labels1]
@@ -1149,12 +1153,13 @@
:- pred mark_parallels_for_teardown(list(label)::in, list(label)::out,
assoc_list(label)::out, block_map::in,
- proc_label::in, int::in, int::out, par_map::in, par_map::out) is det.
+ proc_label::in, counter::in, counter::out,
+ par_map::in, par_map::out) is det.
-mark_parallels_for_teardown([], [], [], _, _, N, N, ParMap, ParMap).
+mark_parallels_for_teardown([], [], [], _, _, C, C, ParMap, ParMap).
mark_parallels_for_teardown([Label0 | Labels0], [Label | Labels],
[Label0 - Label | LabelMap], BlockMap,
- ProcLabel, N0, N, ParMap0, ParMap) :-
+ ProcLabel, C0, C, ParMap0, ParMap) :-
map__lookup(BlockMap, Label0, BlockInfo),
BlockInfo = block_info(_, _, _, _, Type),
(
@@ -1163,31 +1168,31 @@
;
Type = ordinary(_),
Label = Label0,
- N1 = N0,
+ C1 = C0,
ParMap1 = ParMap0
;
Type = teardown(_, _, _),
- mark_parallel(Label0, Label, ProcLabel, N0, N1,
+ mark_parallel(Label0, Label, ProcLabel, C0, C1,
ParMap0, ParMap1)
),
mark_parallels_for_teardown(Labels0, Labels, LabelMap,
- BlockMap, ProcLabel, N1, N, ParMap1, ParMap).
+ BlockMap, ProcLabel, C1, C, ParMap1, ParMap).
% Given the label of a teardown block, allocate a label for its
% non-teardown parallel if it doesn't already have one.
-:- pred mark_parallel(label::in, label::out,
- proc_label::in, int::in, int::out, par_map::in, par_map::out) is det.
+:- pred mark_parallel(label::in, label::out, proc_label::in,
+ counter::in, counter::out, par_map::in, par_map::out) is det.
-mark_parallel(Label0, Label, ProcLabel, N0, N, ParMap0, ParMap) :-
+mark_parallel(Label0, Label, ProcLabel, C0, C, ParMap0, ParMap) :-
( map__search(ParMap0, Label0, OldParallel) ->
Label = OldParallel,
- N = N0,
+ C = C0,
ParMap = ParMap0
;
- NewParallel = local(ProcLabel, N0),
+ counter__allocate(N, C0, C),
+ NewParallel = local(ProcLabel, N),
Label = NewParallel,
- N is N0 + 1,
map__det_insert(ParMap0, Label0, NewParallel, ParMap)
).
Index: compiler/hlds_module.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_module.m,v
retrieving revision 1.57
diff -u -r1.57 hlds_module.m
--- compiler/hlds_module.m 2000/07/20 10:39:22 1.57
+++ compiler/hlds_module.m 2000/08/07 15:01:32
@@ -24,7 +24,7 @@
:- import_module prog_data, module_qual.
:- import_module hlds_pred, hlds_data, unify_proc, special_pred.
:- import_module globals, llds.
-:- import_module relation, map, std_util, list, set, multi_map.
+:- import_module relation, map, std_util, list, set, multi_map, counter.
:- implementation.
@@ -203,11 +203,11 @@
% The cell count is used as a unique cell number for
% constants in the generated C code.
-:- pred module_info_get_cell_count(module_info, int).
-:- mode module_info_get_cell_count(in, out) is det.
+:- pred module_info_get_cell_counter(module_info, counter).
+:- mode module_info_get_cell_counter(in, out) is det.
-:- pred module_info_set_cell_count(module_info, int, module_info).
-:- mode module_info_set_cell_count(in, in, out) is det.
+:- pred module_info_set_cell_counter(module_info, counter, module_info).
+:- mode module_info_set_cell_counter(in, in, out) is det.
:- pred module_add_imported_module_specifiers(list(module_specifier),
module_info, module_info).
@@ -453,7 +453,7 @@
superclass_table :: superclass_table,
assertion_table :: assertion_table,
ctor_field_table :: ctor_field_table,
- cell_count :: int
+ cell_counter :: counter
% cell count, passed into code_info
% and used to generate unique label
% numbers for constant terms in the
@@ -538,7 +538,7 @@
ModuleInfo = module(ModuleSubInfo, PredicateTable, Requests,
UnifyPredMap, QualifierInfo, Types, Insts, Modes, Ctors,
ClassTable, SuperClassTable, InstanceTable, AssertionTable,
- FieldNameTable, 0).
+ FieldNameTable, counter__init(1)).
%-----------------------------------------------------------------------------%
@@ -557,7 +557,7 @@
module_info_superclasses(MI, MI^superclass_table).
module_info_assertion_table(MI, MI^assertion_table).
module_info_ctor_field_table(MI, MI^ctor_field_table).
-module_info_get_cell_count(MI, MI^cell_count).
+module_info_get_cell_counter(MI, MI^cell_counter).
%-----------------------------------------------------------------------------%
@@ -577,7 +577,7 @@
module_info_set_superclasses(MI, S, MI^superclass_table := S).
module_info_set_assertion_table(MI, A, MI^assertion_table := A).
module_info_set_ctor_field_table(MI, CF, MI^ctor_field_table := CF).
-module_info_set_cell_count(MI, CC, MI^cell_count := CC).
+module_info_set_cell_counter(MI, CC, MI^cell_counter := CC).
%-----------------------------------------------------------------------------%
Index: compiler/jumpopt.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/jumpopt.m,v
retrieving revision 1.51
diff -u -r1.51 jumpopt.m
--- compiler/jumpopt.m 2000/01/14 01:10:20 1.51
+++ compiler/jumpopt.m 2000/08/07 15:10:52
@@ -15,7 +15,7 @@
:- interface.
:- import_module llds, globals.
-:- import_module list, set, bool.
+:- import_module list, set, bool, counter.
% Take an instruction list and optimize jumps. This includes jumps
% implicit in procedure returns.
@@ -39,8 +39,9 @@
% by the optimization.
:- pred jumpopt_main(list(instruction)::in, set(label)::in, trace_level::in,
- bool::in, bool::in, bool::in, list(instruction)::out, bool::out)
- is det.
+ proc_label::in, counter::in, counter::out,
+ bool::in, bool::in, bool::in,
+ list(instruction)::out, bool::out) is det.
%-----------------------------------------------------------------------------%
@@ -75,8 +76,8 @@
% numbering, which can do a better job of optimizing this block, have
% been applied.
-jumpopt_main(Instrs0, LayoutLabels, TraceLevel, Blockopt, Recjump,
- MostlyDetTailCall, Instrs, Mod) :-
+jumpopt_main(Instrs0, LayoutLabels, TraceLevel, ProcLabel, C0, C,
+ Blockopt, Recjump, MostlyDetTailCall, Instrs, Mod) :-
map__init(Instrmap0),
map__init(Lvalmap0),
map__init(Procmap0),
@@ -89,15 +90,24 @@
map__init(Forkmap0),
jumpopt__build_forkmap(Instrs0, Sdprocmap, Forkmap0, Forkmap),
( MostlyDetTailCall = yes ->
- opt_util__get_prologue(Instrs0, ProcLabel, _, _, _),
- opt_util__new_label_no(Instrs0, 500, LabelNum),
- CheckedNondetTailCallInfo = yes(ProcLabel - LabelNum)
+ CheckedNondetTailCallInfo0 = yes(ProcLabel - C0),
+ jumpopt__instr_list(Instrs0, comment(""), Instrmap, Blockmap,
+ Lvalmap, Procmap, Sdprocmap, Forkmap, Succmap,
+ LayoutLabels, TraceLevel, CheckedNondetTailCallInfo0,
+ CheckedNondetTailCallInfo, Instrs1),
+ ( CheckedNondetTailCallInfo = yes(_ - Cprime) ->
+ C = Cprime
+ ;
+ error("jumpopt_main: lost the next label number")
+ )
;
- CheckedNondetTailCallInfo = no
+ CheckedNondetTailCallInfo0 = no,
+ jumpopt__instr_list(Instrs0, comment(""), Instrmap, Blockmap,
+ Lvalmap, Procmap, Sdprocmap, Forkmap, Succmap,
+ LayoutLabels, TraceLevel, CheckedNondetTailCallInfo0,
+ _, Instrs1),
+ C = C0
),
- jumpopt__instr_list(Instrs0, comment(""), Instrmap, Blockmap, Lvalmap,
- Procmap, Sdprocmap, Forkmap, Succmap, LayoutLabels,
- TraceLevel, CheckedNondetTailCallInfo, _, Instrs1),
opt_util__filter_out_bad_livevals(Instrs1, Instrs),
( Instrs = Instrs0 ->
Mod = no
@@ -216,7 +226,7 @@
:- pred jumpopt__instr_list(list(instruction), instr, instrmap, tailmap,
lvalmap, tailmap, tailmap, tailmap, tailmap, set(label), trace_level,
- maybe(pair(proc_label, int)), maybe(pair(proc_label, int)),
+ maybe(pair(proc_label, counter)), maybe(pair(proc_label, counter)),
list(instruction)).
:- mode jumpopt__instr_list(in, in, in, in, in, in, in, in, in, in, in,
in, out, out) is det.
@@ -289,14 +299,15 @@
% a runtime check.
CallModel = nondet(checked_tail_call),
CheckedNondetTailCallInfo0 =
- yes(ProcLabel - LabelNum0),
+ yes(ProcLabel - Counter0),
map__search(Succmap, RetLabel, BetweenIncl),
BetweenIncl = [livevals(_) - _, goto(_) - _],
PrevInstr = livevals(Livevals),
TraceLevel = none,
not set__member(RetLabel, LayoutLabels)
->
- NewLabel = local(ProcLabel, LabelNum0),
+ counter__allocate(LabelNum, Counter0, Counter1),
+ NewLabel = local(ProcLabel, LabelNum),
NewInstrs = [
if_val(binop(ne, lval(curfr), lval(maxfr)),
label(NewLabel))
@@ -313,8 +324,7 @@
Instr0
],
RemainInstrs = Instrs0,
- LabelNum1 is LabelNum0 + 1,
- CheckedNondetTailCallInfo1 = yes(ProcLabel - LabelNum1)
+ CheckedNondetTailCallInfo1 = yes(ProcLabel - Counter1)
;
% Short circuit the return label if possible.
map__search(Instrmap, RetLabel, RetInstr),
Index: compiler/ll_pseudo_type_info.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ll_pseudo_type_info.m,v
retrieving revision 1.1
diff -u -r1.1 ll_pseudo_type_info.m
--- compiler/ll_pseudo_type_info.m 2000/04/02 08:09:17 1.1
+++ compiler/ll_pseudo_type_info.m 2000/08/07 15:11:13
@@ -24,6 +24,7 @@
:- interface.
:- import_module prog_data, llds.
+:- import_module counter.
% ll_pseudo_type_info__construct_typed_pseudo_type_info(Type,
% NumUnivQTvars, ExistQVars, Rval, LldsType, LabelNum0, LabelNum)
@@ -44,13 +45,14 @@
:- pred ll_pseudo_type_info__construct_typed_llds_pseudo_type_info((type)::in,
int::in, existq_tvars::in, rval::out, llds_type::out,
- int::in, int::out) is det.
+ counter::in, counter::out) is det.
% This is the same as the previous predicate, but does not return
% the LLDS type.
:- pred ll_pseudo_type_info__construct_llds_pseudo_type_info((type)::in,
- int::in, existq_tvars::in, rval::out, int::in, int::out) is det.
+ int::in, existq_tvars::in, rval::out, counter::in, counter::out)
+ is det.
%-----------------------------------------------------------------------------%
@@ -59,58 +61,58 @@
:- import_module std_util, list, bool, int.
ll_pseudo_type_info__construct_llds_pseudo_type_info(Type, NumUnivQTvars,
- ExistQTvars, Pseudo, CNum0, CNum) :-
+ ExistQTvars, Pseudo, C0, C) :-
ll_pseudo_type_info__construct_typed_llds_pseudo_type_info(Type,
- NumUnivQTvars, ExistQTvars, Pseudo, _LldsType, CNum0, CNum).
+ NumUnivQTvars, ExistQTvars, Pseudo, _LldsType, C0, C).
ll_pseudo_type_info__construct_typed_llds_pseudo_type_info(Type, NumUnivQTvars,
- ExistQTvars, PseudoRval, LldsType, CNum0, CNum) :-
+ ExistQTvars, PseudoRval, LldsType, C0, C) :-
pseudo_type_info__construct_pseudo_type_info(Type, NumUnivQTvars,
ExistQTvars, Pseudo),
- convert_pseudo(Pseudo, PseudoRval, LldsType, CNum0, CNum).
+ convert_pseudo(Pseudo, PseudoRval, LldsType, C0, C).
-:- pred convert_pseudo(pseudo_type_info, rval, llds_type, int, int).
+:- pred convert_pseudo(pseudo_type_info, rval, llds_type, counter, counter).
:- mode convert_pseudo(in, out, out, in, out) is det.
-convert_pseudo(Pseudo, Rval, LldsType, CNum0, CNum) :-
+convert_pseudo(Pseudo, Rval, LldsType, C0, C) :-
(
Pseudo = type_var(Int),
Rval = const(int_const(Int)),
LldsType = integer,
- CNum = CNum0
+ C = C0
;
Pseudo = type_ctor_info(RttiTypeId),
DataAddr = rtti_addr(RttiTypeId, pseudo_type_info(Pseudo)),
Rval = const(data_addr_const(DataAddr)),
LldsType = data_ptr,
- CNum = CNum0
+ C = C0
;
Pseudo = type_info(RttiTypeId, Args),
convert_compound_pseudo(RttiTypeId, [], Args, Rval, LldsType,
- CNum0, CNum)
+ C0, C)
;
Pseudo = higher_order_type_info(RttiTypeId, Arity, Args),
ArityArg = yes(const(int_const(Arity))),
convert_compound_pseudo(RttiTypeId, [ArityArg], Args, Rval,
- LldsType, CNum0, CNum)
+ LldsType, C0, C)
).
:- pred convert_compound_pseudo(rtti_type_id, list(maybe(rval)),
- list(pseudo_type_info), rval, llds_type, int, int).
+ list(pseudo_type_info), rval, llds_type, counter, counter).
:- mode convert_compound_pseudo(in, in, in, out, out, in, out) is det.
convert_compound_pseudo(RttiTypeId, ArgRvals0, Args,
- Rval, LldsType, CNum0, CNum) :-
+ Rval, LldsType, C0, C) :-
TypeCtorInfoPseudo = pseudo_type_info(type_ctor_info(RttiTypeId)),
TypeCtorInfoDataAddr = rtti_addr(RttiTypeId, TypeCtorInfoPseudo),
TypeCtorInfoRval = yes(const(data_addr_const(TypeCtorInfoDataAddr))),
LldsType = data_ptr,
- CNum1 = CNum0 + 1,
- list__map_foldl((pred(A::in, yes(AR)::out, C0::in, C::out) is det :-
- convert_pseudo(A, AR, _LldsType, C0, C)
- ), Args, ArgRvals1, CNum1, CNum),
+ counter__allocate(CNum, C0, C1),
+ list__map_foldl((pred(A::in, yes(AR)::out, CS0::in, CS::out) is det :-
+ convert_pseudo(A, AR, _LldsType, CS0, CS)
+ ), Args, ArgRvals1, C1, C),
list__append(ArgRvals0, ArgRvals1, ArgRvals),
Reuse = no,
Rval = create(0, [TypeCtorInfoRval | ArgRvals],
- uniform(no), must_be_static, CNum1, "type_info",
+ uniform(no), must_be_static, CNum, "type_info",
Reuse).
Index: compiler/llds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/llds.m,v
retrieving revision 1.261
diff -u -r1.261 llds.m
--- compiler/llds.m 2000/04/26 05:40:16 1.261
+++ compiler/llds.m 2000/08/07 14:33:58
@@ -19,7 +19,7 @@
:- import_module hlds_pred, hlds_data, tree, prog_data, (inst).
:- import_module rtti, builtin_ops.
-:- import_module bool, assoc_list, list, map, set, std_util.
+:- import_module bool, assoc_list, list, map, set, std_util, counter.
%-----------------------------------------------------------------------------%
@@ -167,6 +167,8 @@
int, % arity
pred_proc_id, % the pred_proc_id this code
list(instruction), % the code for this procedure
+ proc_label, % proc_label of this procedure
+ counter, % source for new label numbers
contains_reconstruction % value numbering needs
% to handle goals that
% perform structure reuse
Index: compiler/llds_common.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/llds_common.m,v
retrieving revision 1.32
diff -u -r1.32 llds_common.m
--- compiler/llds_common.m 2000/04/26 05:40:19 1.32
+++ compiler/llds_common.m 2000/08/07 09:26:32
@@ -138,9 +138,11 @@
common_info::in, common_info::out) is det.
llds_common__process_proc(Proc0, Proc, Info0, Info) :-
- Proc0 = c_procedure(Name, Arity, PredProcId, Instrs0, Reconstruction),
+ Proc0 = c_procedure(Name, Arity, PredProcId, Instrs0,
+ ProcLabel, N, Reconstruction),
llds_common__process_instrs(Instrs0, Instrs, Info0, Info),
- Proc = c_procedure(Name, Arity, PredProcId, Instrs, Reconstruction).
+ Proc = c_procedure(Name, Arity, PredProcId, Instrs,
+ ProcLabel, N, Reconstruction).
:- pred llds_common__process_instrs(list(instruction)::in,
list(instruction)::out, common_info::in, common_info::out) is det.
Index: compiler/llds_out.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/llds_out.m,v
retrieving revision 1.146
diff -u -r1.146 llds_out.m
--- compiler/llds_out.m 2000/08/03 06:10:33 1.146
+++ compiler/llds_out.m 2000/08/07 14:35:37
@@ -1145,7 +1145,7 @@
:- mode output_c_procedure_decls(in, in, out, di, uo) is det.
output_c_procedure_decls(Proc, DeclSet0, DeclSet) -->
- { Proc = c_procedure(_Name, _Arity, _PredProcId, Instrs, _Recons) },
+ { Proc = c_procedure(_Name, _Arity, _PredProcId, Instrs, _, _, _) },
output_instruction_list_decls(Instrs, DeclSet0, DeclSet).
:- pred output_c_procedure(c_procedure, bool, bool,
@@ -1153,8 +1153,7 @@
:- mode output_c_procedure(in, in, in, di, uo) is det.
output_c_procedure(Proc, PrintComments, EmitCLoops) -->
- { Proc = c_procedure(Name, Arity, proc(_PredId, ProcId),
- Instrs, _Recons) },
+ { Proc = c_procedure(Name, Arity, proc(_, ProcId), Instrs, _, _, _) },
{ proc_id_to_int(ProcId, ModeNum) },
( { PrintComments = yes } ->
io__write_string("\n/*-------------------------------------"),
@@ -4283,7 +4282,7 @@
list(label)::in, list(label)::out) is det.
gather_labels_from_c_procs([], Labels, Labels).
-gather_labels_from_c_procs([c_procedure(_, _, _, Instrs, _) | Procs],
+gather_labels_from_c_procs([c_procedure(_, _, _, Instrs, _, _, _) | Procs],
Labels0, Labels) :-
gather_labels_from_instrs(Instrs, Labels0, Labels1),
gather_labels_from_c_procs(Procs, Labels1, Labels).
Index: compiler/mercury_compile.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.169
diff -u -r1.169 mercury_compile.m
--- compiler/mercury_compile.m 2000/08/08 04:44:42 1.169
+++ compiler/mercury_compile.m 2000/08/09 03:33:19
@@ -1332,9 +1332,9 @@
write_proc_progress_message(
"% Generating low-level (LLDS) code for ",
PredId, ProcId, ModuleInfo3),
- { module_info_get_cell_count(ModuleInfo3, CellCount0) },
+ { module_info_get_cell_counter(ModuleInfo3, CellCounter0) },
{ generate_proc_code(PredInfo, ProcInfo, ProcId, PredId, ModuleInfo3,
- Globals, GlobalData0, GlobalData1, CellCount0, CellCount,
+ Globals, GlobalData0, GlobalData1, CellCounter0, CellCounter,
Proc0) },
{ globals__lookup_bool_option(Globals, optimize, Optimize) },
( { Optimize = yes } ->
@@ -1342,13 +1342,13 @@
;
{ Proc = Proc0 }
),
- { Proc = c_procedure(_, _, PredProcId, Instructions, _) },
+ { Proc = c_procedure(_, _, PredProcId, Instructions, _, _, _) },
write_proc_progress_message(
"% Generating call continuation information for ",
PredId, ProcId, ModuleInfo3),
{ continuation_info__maybe_process_proc_llds(Instructions, PredProcId,
ModuleInfo3, GlobalData1, GlobalData) },
- { module_info_set_cell_count(ModuleInfo3, CellCount, ModuleInfo) }.
+ { module_info_set_cell_counter(ModuleInfo3, CellCounter, ModuleInfo) }.
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
Index: compiler/opt_debug.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/opt_debug.m,v
retrieving revision 1.104
diff -u -r1.104 opt_debug.m
--- compiler/opt_debug.m 2000/05/10 18:06:57 1.104
+++ compiler/opt_debug.m 2000/08/07 09:11:44
@@ -19,8 +19,8 @@
:- import_module io, bool, list, assoc_list, std_util.
-:- pred opt_debug__msg(bool, string, io__state, io__state).
-:- mode opt_debug__msg(in, in, di, uo) is det.
+:- pred opt_debug__msg(bool, int, string, io__state, io__state).
+:- mode opt_debug__msg(in, in, in, di, uo) is det.
:- pred opt_debug__dump_instrs(bool, list(instruction), io__state, io__state).
:- mode opt_debug__dump_instrs(in, in, di, uo) is det.
@@ -199,11 +199,17 @@
:- import_module int, set, map, string.
-opt_debug__msg(OptDebug, Msg) -->
+opt_debug__msg(OptDebug, LabelNo, Msg) -->
(
{ OptDebug = yes },
io__write_string("\n"),
io__write_string(Msg),
+ ( { LabelNo >= 0 } ->
+ io__write_string(", next label no: "),
+ io__write_int(LabelNo)
+ ;
+ []
+ ),
io__write_string("\n")
;
{ OptDebug = no }
Index: compiler/opt_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/opt_util.m,v
retrieving revision 1.108
diff -u -r1.108 opt_util.m
--- compiler/opt_util.m 2000/04/26 05:40:31 1.108
+++ compiler/opt_util.m 2000/05/05 04:08:00
@@ -21,9 +21,9 @@
:- type tailmap == map(label, list(instruction)).
:- type succmap == map(label, bool).
-:- pred opt_util__get_prologue(list(instruction), proc_label, instruction,
+:- pred opt_util__get_prologue(list(instruction), instruction,
list(instruction), list(instruction)).
-:- mode opt_util__get_prologue(in, out, out, out, out) is det.
+:- mode opt_util__get_prologue(in, out, out, out) is det.
:- pred opt_util__gather_comments(list(instruction),
list(instruction), list(instruction)).
@@ -220,12 +220,6 @@
:- pred opt_util__possible_targets(instr, list(label)).
:- mode opt_util__possible_targets(in, out) is det.
- % Find a label number that does not occur in the instruction list,
- % starting the search at a given number.
-
-:- pred opt_util__new_label_no(list(instruction), int, int).
-:- mode opt_util__new_label_no(in, in, out) is det.
-
% Find the maximum temp variable number used.
:- pred opt_util__count_temps_instr_list(list(instruction), int, int, int, int).
@@ -330,20 +324,13 @@
:- import_module builtin_ops, exprn_aux, llds_out, hlds_pred.
:- import_module int, string, set, require.
-opt_util__get_prologue(Instrs0, ProcLabel, LabelInstr, Comments, Instrs) :-
+opt_util__get_prologue(Instrs0, LabelInstr, Comments, Instrs) :-
opt_util__gather_comments(Instrs0, Comments1, Instrs1),
(
Instrs1 = [Instr1 | Instrs2],
- Instr1 = label(FirstLabel) - _
+ Instr1 = label(_) - _
->
LabelInstr = Instr1,
- ( FirstLabel = exported(ProcLabelPrime) ->
- ProcLabel = ProcLabelPrime
- ; FirstLabel = local(ProcLabelPrime) ->
- ProcLabel = ProcLabelPrime
- ;
- error("procedure begins with bad label type")
- ),
opt_util__gather_comments(Instrs2, Comments2, Instrs),
list__append(Comments1, Comments2, Comments)
;
@@ -991,18 +978,6 @@
Op = eq,
Rval1 = Rval2,
Taken = yes.
-
-opt_util__new_label_no([], N, N).
-opt_util__new_label_no([Instr0 | Instrs0], N0, N) :-
- (
- Instr0 = label(local(_, K)) - _,
- K >= N0
- ->
- N1 is K + 1
- ;
- N1 = N0
- ),
- opt_util__new_label_no(Instrs0, N1, N).
opt_util__can_instr_branch_away(comment(_), no).
opt_util__can_instr_branch_away(livevals(_), no).
Index: compiler/optimize.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/optimize.m,v
retrieving revision 1.23
diff -u -r1.23 optimize.m
--- compiler/optimize.m 2000/03/28 03:40:29 1.23
+++ compiler/optimize.m 2000/08/07 16:06:22
@@ -32,7 +32,7 @@
:- import_module globals, passes_aux, opt_util, opt_debug, vn_debug.
:- import_module continuation_info.
-:- import_module bool, int, map, bimap, set, std_util.
+:- import_module bool, int, map, bimap, set, std_util, counter.
optimize_main([], _, []) --> [].
optimize_main([Proc0 | Procs0], GlobalData, [Proc | Procs]) -->
@@ -40,10 +40,11 @@
optimize_main(Procs0, GlobalData, Procs).
optimize__proc(CProc0, GlobalData, CProc) -->
- { CProc0 = c_procedure(Name, Arity, PredProcId,
- Instrs0, ContainsReconstruction) },
+ { CProc0 = c_procedure(Name, Arity, PredProcId, Instrs0,
+ ProcLabel, C0, ContainsReconstruction) },
globals__io_lookup_bool_option(debug_opt, DebugOpt),
- opt_debug__msg(DebugOpt, "before optimization"),
+ { counter__allocate(N0, C0, _) },
+ opt_debug__msg(DebugOpt, N0, "before optimization"),
opt_debug__dump_instrs(DebugOpt, Instrs0),
globals__io_lookup_int_option(optimize_repeat, AllRepeat),
globals__io_lookup_int_option(optimize_vnrepeat, VnRepeat),
@@ -62,27 +63,30 @@
( { ValueNumber = yes } ->
{ NovnRepeat is AllRepeat - VnRepeat },
optimize__repeat(NovnRepeat, no, ContainsReconstruction,
- LayoutLabelSet, Instrs0, Instrs1),
- optimize__middle(Instrs1, no, LayoutLabelSet, Instrs2),
+ LayoutLabelSet, Instrs0, ProcLabel, C0, C1, Instrs1),
+ optimize__middle(Instrs1, no, LayoutLabelSet,
+ ProcLabel, C1, C2, Instrs2),
optimize__repeat(VnRepeat, yes, ContainsReconstruction,
- LayoutLabelSet, Instrs2, Instrs3)
+ LayoutLabelSet, Instrs2, ProcLabel, C2, C, Instrs3)
;
optimize__repeat(AllRepeat, no, ContainsReconstruction,
- LayoutLabelSet, Instrs0, Instrs1),
- optimize__middle(Instrs1, yes, LayoutLabelSet, Instrs3)
+ LayoutLabelSet, Instrs0, ProcLabel, C0, C1, Instrs1),
+ optimize__middle(Instrs1, yes, LayoutLabelSet,
+ ProcLabel, C1, C, Instrs3)
),
optimize__last(Instrs3, LayoutLabelSet, Instrs),
{ CProc = c_procedure(Name, Arity, PredProcId, Instrs,
- ContainsReconstruction) }.
+ ProcLabel, C, ContainsReconstruction) }.
%-----------------------------------------------------------------------------%
:- pred optimize__repeat(int::in, bool::in, contains_reconstruction::in,
- set(label)::in, list(instruction)::in, list(instruction)::out,
+ set(label)::in, list(instruction)::in,
+ proc_label::in, counter::in, counter::out, list(instruction)::out,
io__state::di, io__state::uo) is det.
-optimize__repeat(Iter0, DoVn, ContainsReconstruction,
- LayoutLabelSet, Instrs0, Instrs) -->
+optimize__repeat(Iter0, DoVn, ContainsReconstruction, LayoutLabelSet, Instrs0,
+ ProcLabel, C0, C, Instrs) -->
(
{ Iter0 > 0 }
->
@@ -93,27 +97,31 @@
{ Final = no }
),
optimize__repeated(Instrs0, DoVn, ContainsReconstruction,
- Final, LayoutLabelSet, Instrs1, Mod),
+ Final, LayoutLabelSet, ProcLabel, C0, C1,
+ Instrs1, Mod),
( { Mod = yes } ->
optimize__repeat(Iter1, DoVn, ContainsReconstruction,
- LayoutLabelSet, Instrs1, Instrs)
+ LayoutLabelSet, Instrs1, ProcLabel, C1, C,
+ Instrs)
;
- { Instrs = Instrs1 }
+ { Instrs = Instrs1 },
+ { C = C1 }
)
;
- { Instrs = Instrs0 }
+ { Instrs = Instrs0 },
+ { C = C0 }
).
% We short-circuit jump sequences before normal peepholing
% to create more opportunities for use of the tailcall macro.
:- pred optimize__repeated(list(instruction)::in, bool::in,
- contains_reconstruction::in, bool::in,
- set(label)::in, list(instruction)::out, bool::out,
- io__state::di, io__state::uo) is det.
+ contains_reconstruction::in, bool::in, set(label)::in,
+ proc_label::in, counter::in, counter::out, list(instruction)::out,
+ bool::out, io__state::di, io__state::uo) is det.
-optimize__repeated(Instrs0, DoVn, ContainsReconstruction,
- Final, LayoutLabelSet, Instrs, Mod) -->
+optimize__repeated(Instrs0, DoVn, ContainsReconstruction, Final,
+ LayoutLabelSet, ProcLabel, C0, C, 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) },
@@ -129,15 +137,17 @@
[]
),
value_number_main(Instrs0, ContainsReconstruction,
- LayoutLabelSet, Instrs1),
+ LayoutLabelSet, ProcLabel, C0, C1, Instrs1),
( { Instrs1 = Instrs0 } ->
[]
;
- opt_debug__msg(DebugOpt, "after value numbering"),
+ { counter__allocate(N1, C1, _) },
+ opt_debug__msg(DebugOpt, N1, "after value numbering"),
opt_debug__dump_instrs(DebugOpt, Instrs1)
)
;
- { Instrs1 = Instrs0 }
+ { Instrs1 = Instrs0 },
+ { C1 = C0 }
),
globals__io_lookup_bool_option(optimize_jumps, Jumpopt),
globals__io_lookup_bool_option(optimize_fulljumps, FullJumpopt),
@@ -152,17 +162,20 @@
;
[]
),
- { jumpopt_main(Instrs1, LayoutLabelSet, TraceLevel,
- FullJumpopt, Final, CheckedNondetTailCalls,
+ { jumpopt_main(Instrs1, LayoutLabelSet, TraceLevel, ProcLabel,
+ C1, C2, FullJumpopt, Final, CheckedNondetTailCalls,
Instrs2, Mod1) },
( { Mod1 = yes } ->
- opt_debug__msg(DebugOpt, "after jump optimization"),
+ { counter__allocate(N2A, C2, _) },
+ opt_debug__msg(DebugOpt, N2A,
+ "after jump optimization"),
opt_debug__dump_instrs(DebugOpt, Instrs2)
;
[]
)
;
{ Instrs2 = Instrs1 },
+ { C2 = C1 },
{ Mod1 = no }
),
globals__io_lookup_bool_option(optimize_peep, Peephole),
@@ -177,7 +190,8 @@
globals__io_get_gc_method(GC_Method),
{ peephole__optimize(GC_Method, Instrs2, Instrs3, Mod2) },
( { Mod2 = yes } ->
- opt_debug__msg(DebugOpt, "after peepholing"),
+ { counter__allocate(N2B, C2, _) },
+ opt_debug__msg(DebugOpt, N2B, "after peepholing"),
opt_debug__dump_instrs(DebugOpt, Instrs3)
;
[]
@@ -198,7 +212,9 @@
{ labelopt_main(Instrs3, Final, LayoutLabelSet,
Instrs4, Mod3) },
( { Mod3 = yes } ->
- opt_debug__msg(DebugOpt, "after label optimization"),
+ { counter__allocate(N2C, C2, _) },
+ opt_debug__msg(DebugOpt, N2C,
+ "after label optimization"),
opt_debug__dump_instrs(DebugOpt, Instrs4)
;
[]
@@ -216,15 +232,18 @@
;
[]
),
- { dupelim_main(Instrs4, Instrs) },
+ { dupelim_main(Instrs4, ProcLabel, C2, C, Instrs) },
( { Instrs = Instrs4 } ->
[]
;
- opt_debug__msg(DebugOpt, "after duplicate elimination"),
+ { counter__allocate(N, C, _) },
+ opt_debug__msg(DebugOpt, N,
+ "after duplicate elimination"),
opt_debug__dump_instrs(DebugOpt, Instrs)
)
;
- { Instrs = Instrs4 }
+ { Instrs = Instrs4 },
+ { C = C2 }
),
{ Mod1 = no, Mod2 = no, Mod3 = no, Instrs = Instrs0 ->
Mod = no
@@ -235,9 +254,10 @@
maybe_report_stats(Statistics).
:- pred optimize__middle(list(instruction)::in, bool::in, set(label)::in,
- list(instruction)::out, io__state::di, io__state::uo) is det.
+ proc_label::in, counter::in, counter::out, list(instruction)::out,
+ io__state::di, io__state::uo) is det.
-optimize__middle(Instrs0, Final, LayoutLabelSet, Instrs) -->
+optimize__middle(Instrs0, Final, LayoutLabelSet, ProcLabel, C0, C, Instrs) -->
globals__io_lookup_bool_option(very_verbose, VeryVerbose),
globals__io_lookup_bool_option(debug_opt, DebugOpt),
{ opt_util__find_first_label(Instrs0, Label) },
@@ -252,9 +272,12 @@
;
[]
),
- { frameopt_main(Instrs0, Instrs1, Mod1, Jumps) },
+ { frameopt_main(Instrs0, ProcLabel, C0, C1, Instrs1,
+ Mod1, Jumps) },
( { Mod1 = yes } ->
- opt_debug__msg(DebugOpt, "after frame optimization"),
+ { counter__allocate(N1, C1, _) },
+ opt_debug__msg(DebugOpt, N1,
+ "after frame optimization"),
opt_debug__dump_instrs(DebugOpt, Instrs1)
;
[]
@@ -272,16 +295,19 @@
[]
),
{ jumpopt_main(Instrs1, LayoutLabelSet, TraceLevel,
- FullJumpopt, Final, CheckedNondetTailCalls,
- Instrs2, Mod2) },
+ ProcLabel, C1, C, FullJumpopt, Final,
+ CheckedNondetTailCalls, Instrs2, Mod2) },
( { Mod2 = yes } ->
- opt_debug__msg(DebugOpt, "after jump optimization"),
+ { counter__allocate(NA, C, _) },
+ opt_debug__msg(DebugOpt, NA,
+ "after jump optimization"),
opt_debug__dump_instrs(DebugOpt, Instrs2)
;
[]
)
;
- { Instrs2 = Instrs1 }
+ { Instrs2 = Instrs1 },
+ { C = C1 }
),
( { Mod1 = yes } ->
( { VeryVerbose = yes } ->
@@ -294,7 +320,9 @@
{ labelopt_main(Instrs2, Final, LayoutLabelSet,
Instrs, Mod3) },
( { Mod3 = yes } ->
- opt_debug__msg(DebugOpt, "after label optimization"),
+ { counter__allocate(NB, C, _) },
+ opt_debug__msg(DebugOpt, NB,
+ "after label optimization"),
opt_debug__dump_instrs(DebugOpt, Instrs)
;
[]
@@ -303,7 +331,8 @@
{ Instrs = Instrs2 }
)
;
- { Instrs = Instrs0 }
+ { Instrs = Instrs0 },
+ { C = C0 }
).
:- pred optimize__last(list(instruction)::in, set(label)::in,
@@ -329,7 +358,8 @@
),
{ labelopt_main(Instrs0, no, LayoutLabelSet, Instrs1, Mod1) },
( { Mod1 = yes } ->
- opt_debug__msg(DebugOpt, "after label optimization"),
+ opt_debug__msg(DebugOpt, -1,
+ "after label optimization"),
opt_debug__dump_instrs(DebugOpt, Instrs1)
;
[]
@@ -347,7 +377,8 @@
),
{ fill_branch_delay_slot(Instrs1, Instrs2) },
( { Instrs1 = Instrs0 } ->
- opt_debug__msg(DebugOpt, "after delay slot filling"),
+ opt_debug__msg(DebugOpt, -1,
+ "after delay slot filling"),
opt_debug__dump_instrs(DebugOpt, Instrs2)
;
[]
@@ -367,7 +398,8 @@
( { Instrs = Instrs2 } ->
[]
;
- opt_debug__msg(DebugOpt, "after post value number"),
+ opt_debug__msg(DebugOpt, -1,
+ "after post value number"),
opt_debug__dump_instrs(DebugOpt, Instrs)
)
;
Index: compiler/stack_layout.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/stack_layout.m,v
retrieving revision 1.47
diff -u -r1.47 stack_layout.m
--- compiler/stack_layout.m 2000/07/20 05:44:02 1.47
+++ compiler/stack_layout.m 2000/08/07 16:10:55
@@ -239,7 +239,7 @@
:- interface.
:- import_module continuation_info, hlds_module, llds.
-:- import_module std_util, list, set_bbbtree.
+:- import_module std_util, list, set_bbbtree, counter.
:- pred stack_layout__generate_llds(module_info::in, module_info::out,
global_data::in,
@@ -248,7 +248,7 @@
:- pred stack_layout__construct_closure_layout(proc_label::in,
closure_layout_info::in, list(maybe(rval))::out,
- create_arg_types::out, int::in, int::out) is det.
+ create_arg_types::out, counter::in, counter::out) is det.
:- implementation.
@@ -268,7 +268,7 @@
global_data_get_all_proc_layouts(GlobalData, ProcLayoutList),
module_info_name(ModuleInfo0, ModuleName),
- module_info_get_cell_count(ModuleInfo0, CellCount),
+ module_info_get_cell_counter(ModuleInfo0, CellCounter0),
module_info_globals(ModuleInfo0, Globals),
globals__lookup_bool_option(Globals, agc_stack_layout, AgcLayout),
globals__lookup_bool_option(Globals, trace_stack_layout, TraceLayout),
@@ -280,7 +280,7 @@
map__init(StringMap0),
map__init(LabelTables0),
StringTable0 = string_table(StringMap0, [], 0),
- LayoutInfo0 = stack_layout_info(ModuleName, CellCount,
+ LayoutInfo0 = stack_layout_info(ModuleName, CellCounter0,
AgcLayout, TraceLayout, ProcIdLayout, StaticCodeAddr,
[], [], LayoutLabels0, [], StringTable0, LabelTables0),
stack_layout__lookup_string_in_table("", _, LayoutInfo0, LayoutInfo1),
@@ -334,8 +334,8 @@
LayoutInfo = LayoutInfo3
),
PossiblyDynamicLayouts = ProcLayouts,
- stack_layout__get_cell_number(FinalCellCount, LayoutInfo, _),
- module_info_set_cell_count(ModuleInfo0, FinalCellCount, ModuleInfo).
+ stack_layout__get_cell_counter(CellCounter, LayoutInfo, _),
+ module_info_set_cell_counter(ModuleInfo0, CellCounter, ModuleInfo).
%---------------------------------------------------------------------------%
@@ -948,10 +948,10 @@
{ stack_layout__sort_livevals(LiveLvals, SortedLiveLvals) },
stack_layout__construct_liveval_arrays(SortedLiveLvals,
VarLengthRval, LiveValRval, NamesRval),
- stack_layout__get_cell_number(CNum0),
+ stack_layout__get_cell_counter(C0),
{ stack_layout__construct_tvar_vector(TVarLocnMap,
- TypeParamRval, CNum0, CNum) },
- stack_layout__set_cell_number(CNum),
+ TypeParamRval, C0, C) },
+ stack_layout__set_cell_counter(C),
{ RvalList = [yes(VarLengthRval), yes(LiveValRval),
yes(NamesRval), yes(TypeParamRval)] },
{ ArgTypes = initial([1 - yes(integer), 3 - yes(data_ptr)],
@@ -962,16 +962,16 @@
).
:- pred stack_layout__construct_tvar_vector(map(tvar, set(layout_locn))::in,
- rval::out, int::in, int::out) is det.
+ rval::out, counter::in, counter::out) is det.
-stack_layout__construct_tvar_vector(TVarLocnMap, TypeParamRval, CNum0, CNum) :-
+stack_layout__construct_tvar_vector(TVarLocnMap, TypeParamRval, C0, C) :-
( map__is_empty(TVarLocnMap) ->
TypeParamRval = const(int_const(0)),
- CNum = CNum0
+ C = C0
;
stack_layout__construct_tvar_rvals(TVarLocnMap,
Vector, VectorTypes),
- CNum is CNum0 + 1,
+ counter__allocate(CNum, C0, C),
Reuse = no,
TypeParamRval = create(0, Vector, VectorTypes,
must_be_static, CNum,
@@ -1247,15 +1247,15 @@
% the data structures we build here.
stack_layout__construct_closure_layout(ProcLabel, ClosureLayoutInfo,
- Rvals, ArgTypes, CNum0, CNum) :-
+ Rvals, ArgTypes, C0, C) :-
stack_layout__construct_procid_rvals(ProcLabel, ProcIdRvals,
ProcIdTypes),
ClosureLayoutInfo = closure_layout_info(ClosureArgs,
TVarLocnMap),
stack_layout__construct_closure_arg_rvals(ClosureArgs,
- ClosureArgRvals, ClosureArgTypes, CNum0, CNum1),
+ ClosureArgRvals, ClosureArgTypes, C0, C1),
stack_layout__construct_tvar_vector(TVarLocnMap, TVarVectorRval,
- CNum1, CNum),
+ C1, C),
TVarVectorRvals = [yes(TVarVectorRval)],
TVarVectorTypes = [1 - yes(data_ptr)],
list__append(TVarVectorRvals, ClosureArgRvals, LayoutRvals),
@@ -1264,13 +1264,13 @@
initial(ClosureArgTypes, none))).
:- pred stack_layout__construct_closure_arg_rvals(list(closure_arg_info)::in,
- list(maybe(rval))::out, initial_arg_types::out, int::in, int::out)
- is det.
+ list(maybe(rval))::out, initial_arg_types::out,
+ counter::in, counter::out) is det.
stack_layout__construct_closure_arg_rvals(ClosureArgs, ClosureArgRvals,
- ClosureArgTypes, CNum0, CNum) :-
+ ClosureArgTypes, C0, C) :-
list__map_foldl(stack_layout__construct_closure_arg_rval,
- ClosureArgs, MaybeArgRvalsTypes, CNum0, CNum),
+ ClosureArgs, MaybeArgRvalsTypes, C0, C),
assoc_list__keys(MaybeArgRvalsTypes, MaybeArgRvals),
AddOne = lambda([Pair::in, CountLldsType::out] is det, (
Pair = _ - LldsType,
@@ -1282,10 +1282,10 @@
ClosureArgTypes = [1 - yes(integer) | ArgRvalTypes].
:- pred stack_layout__construct_closure_arg_rval(closure_arg_info::in,
- pair(maybe(rval), llds_type)::out, int::in, int::out) is det.
+ pair(maybe(rval), llds_type)::out, counter::in, counter::out) is det.
stack_layout__construct_closure_arg_rval(ClosureArg,
- yes(ArgRval) - ArgRvalType, CNum0, CNum) :-
+ yes(ArgRval) - ArgRvalType, C0, C) :-
ClosureArg = closure_arg_info(Type, _Inst),
% For a stack layout, we can treat all type variables as
@@ -1297,7 +1297,7 @@
NumUnivQTvars = -1,
ll_pseudo_type_info__construct_typed_llds_pseudo_type_info(Type,
- NumUnivQTvars, ExistQTvars, ArgRval, ArgRvalType, CNum0, CNum).
+ NumUnivQTvars, ExistQTvars, ArgRval, ArgRvalType, C0, C).
%---------------------------------------------------------------------------%
@@ -1353,7 +1353,7 @@
{ Rval = const(data_addr_const(DataAddr)) }.
stack_layout__represent_live_value_type(var(_, _, Type, _), Rval, LldsType)
-->
- stack_layout__get_cell_number(CNum0),
+ stack_layout__get_cell_counter(C0),
% For a stack layout, we can treat all type variables as
% universally quantified. This is not the argument of a
@@ -1364,8 +1364,8 @@
{ NumUnivQTvars = -1 },
{ ll_pseudo_type_info__construct_typed_llds_pseudo_type_info(Type,
NumUnivQTvars, ExistQTvars,
- Rval, LldsType, CNum0, CNum) },
- stack_layout__set_cell_number(CNum).
+ Rval, LldsType, C0, C) },
+ stack_layout__set_cell_counter(C).
%---------------------------------------------------------------------------%
@@ -1620,31 +1620,33 @@
:- type stack_layout_info --->
stack_layout_info(
- module_name, % module name
- int, % next available cell number
- bool, % generate agc layout info?
- bool, % generate tracing layout info?
- bool, % generate procedure id layout info?
- bool, % have static code addresses?
- list(comp_gen_c_data), % generated proc layouts
- list(comp_gen_c_data), % generated internal layouts
- set_bbbtree(label),
- % the set of labels (both entry and internal)
- % with layouts
- list(maybe(rval)),
- % the list of proc_layouts in the module,
- % represented as create args
- string_table,
- map(string, label_table)
- % maps each filename that contributes labels
- % to this module to a table describing those
- % labels.
+ module_name :: module_name,
+ cell_counter :: counter,
+ agc_stack_layout :: bool, % generate agc info?
+ trace_stack_layout :: bool, % generate tracing info?
+ procid_stack_layout :: bool, % generate proc id info?
+ static_code_addresses :: bool, % have static code addresses?
+ proc_layouts :: list(comp_gen_c_data),
+ internal_layouts :: list(comp_gen_c_data),
+ label_set :: set_bbbtree(label),
+ % the set of labels (both entry
+ % and internal) with layouts
+ proc_layout_args :: list(maybe(rval)),
+ % the list of proc_layouts in
+ % the module, represented as create
+ % args
+ string_table :: string_table,
+ label_tables :: map(string, label_table)
+ % maps each filename that
+ % contributes labels to this module
+ % to a table describing those
+ % labels.
).
:- pred stack_layout__get_module_name(module_name::out,
stack_layout_info::in, stack_layout_info::out) is det.
-:- pred stack_layout__get_cell_number(int::out,
+:- pred stack_layout__get_cell_counter(counter::out,
stack_layout_info::in, stack_layout_info::out) is det.
:- pred stack_layout__get_agc_stack_layout(bool::out,
@@ -1673,87 +1675,68 @@
:- pred stack_layout__get_label_tables(map(string, label_table)::out,
stack_layout_info::in, stack_layout_info::out) is det.
-
-stack_layout__get_module_name(A, LayoutInfo, LayoutInfo) :-
- LayoutInfo = stack_layout_info(A, _, _, _, _, _, _, _, _, _, _, _).
-
-stack_layout__get_cell_number(B, LayoutInfo, LayoutInfo) :-
- LayoutInfo = stack_layout_info(_, B, _, _, _, _, _, _, _, _, _, _).
-
-stack_layout__get_agc_stack_layout(C, LayoutInfo, LayoutInfo) :-
- LayoutInfo = stack_layout_info(_, _, C, _, _, _, _, _, _, _, _, _).
-
-stack_layout__get_trace_stack_layout(D, LayoutInfo, LayoutInfo) :-
- LayoutInfo = stack_layout_info(_, _, _, D, _, _, _, _, _, _, _, _).
-
-stack_layout__get_procid_stack_layout(E, LayoutInfo, LayoutInfo) :-
- LayoutInfo = stack_layout_info(_, _, _, _, E, _, _, _, _, _, _, _).
-
-stack_layout__get_static_code_addresses(F, LayoutInfo, LayoutInfo) :-
- LayoutInfo = stack_layout_info(_, _, _, _, _, F, _, _, _, _, _, _).
-stack_layout__get_proc_layout_data(G, LayoutInfo, LayoutInfo) :-
- LayoutInfo = stack_layout_info(_, _, _, _, _, _, G, _, _, _, _, _).
+stack_layout__get_module_name(LI^module_name, LI, LI).
+stack_layout__get_cell_counter(LI^cell_counter, 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_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_internal_layout_data(H, LayoutInfo, LayoutInfo) :-
- LayoutInfo = stack_layout_info(_, _, _, _, _, _, _, H, _, _, _, _).
-
-stack_layout__get_label_set(I, LayoutInfo, LayoutInfo) :-
- LayoutInfo = stack_layout_info(_, _, _, _, _, _, _, _, I, _, _, _).
-
-stack_layout__get_string_table(K, LayoutInfo, LayoutInfo) :-
- LayoutInfo = stack_layout_info(_, _, _, _, _, _, _, _, _, _, K, _).
-
-stack_layout__get_label_tables(L, LayoutInfo, LayoutInfo) :-
- LayoutInfo = stack_layout_info(_, _, _, _, _, _, _, _, _, _, _, L).
-
:- pred stack_layout__add_proc_layout_data(comp_gen_c_data::in, data_name::in,
label::in, stack_layout_info::in, stack_layout_info::out) is det.
-stack_layout__add_proc_layout_data(NewG, NewJ, NewI, LayoutInfo0, LayoutInfo) :-
- LayoutInfo0 = stack_layout_info(A, B, C, D, E, F, G0, H, I0, J0, K, L),
- G = [NewG | G0],
- set_bbbtree__insert(I0, NewI, I),
- J = [yes(const(data_addr_const(data_addr(A, NewJ)))) | J0],
- LayoutInfo = stack_layout_info(A, B, C, D, E, F, G , H, I , J , K, L).
+stack_layout__add_proc_layout_data(NewProcLayout, NewDataName, NewLabel,
+ LI0, LI) :-
+ ProcLayouts0 = LI0^proc_layouts,
+ ProcLayouts = [NewProcLayout | ProcLayouts0],
+ LabelSet0 = LI0^label_set,
+ set_bbbtree__insert(LabelSet0, NewLabel, LabelSet),
+ ModuleName = LI0^module_name,
+ NewProcLayoutArg = yes(const(data_addr_const(
+ data_addr(ModuleName, NewDataName)))),
+ ProcLayoutArgs0 = LI0^proc_layout_args,
+ ProcLayoutArgs = [NewProcLayoutArg | ProcLayoutArgs0],
+ LI = (((LI0^proc_layouts := ProcLayouts)
+ ^label_set := LabelSet)
+ ^proc_layout_args := ProcLayoutArgs).
:- pred stack_layout__add_internal_layout_data(comp_gen_c_data::in,
label::in, stack_layout_info::in, stack_layout_info::out) is det.
-stack_layout__add_internal_layout_data(NewH, NewI, LayoutInfo0, LayoutInfo) :-
- LayoutInfo0 = stack_layout_info(A, B, C, D, E, F, G, H0, I0, J, K, L),
- H = [NewH | H0],
- set_bbbtree__insert(I0, NewI, I),
- LayoutInfo = stack_layout_info(A, B, C, D, E, F, G, H , I , J, K, L).
+stack_layout__add_internal_layout_data(NewInternalLayout, NewLabel, LI0, LI) :-
+ InternalLayouts0 = LI0^internal_layouts,
+ InternalLayouts = [NewInternalLayout | InternalLayouts0],
+ LabelSet0 = LI0^label_set,
+ set_bbbtree__insert(LabelSet0, NewLabel, LabelSet),
+ LI = ((LI0^internal_layouts := InternalLayouts)
+ ^label_set := LabelSet).
:- pred stack_layout__get_next_cell_number(int::out,
stack_layout_info::in, stack_layout_info::out) is det.
-stack_layout__get_next_cell_number(B, LayoutInfo0, LayoutInfo) :-
- LayoutInfo0 = stack_layout_info(A, B0, C, D, E, F, G, H, I, J, K, L),
- B is B0 + 1,
- LayoutInfo = stack_layout_info(A, B, C, D, E, F, G, H, I, J, K, L).
+stack_layout__get_next_cell_number(CN, LI0, LI) :-
+ C0 = LI0^cell_counter,
+ counter__allocate(CN, C0, C),
+ LI = LI0^cell_counter := C.
-:- pred stack_layout__set_cell_number(int::in,
+:- pred stack_layout__set_cell_counter(counter::in,
stack_layout_info::in, stack_layout_info::out) is det.
-stack_layout__set_cell_number(B, LayoutInfo0, LayoutInfo) :-
- LayoutInfo0 = stack_layout_info(A, _, C, D, E, F, G, H, I, J, K, L),
- LayoutInfo = stack_layout_info(A, B, C, D, E, F, G, H, I, J, K, L).
-
:- pred stack_layout__set_string_table(string_table::in,
stack_layout_info::in, stack_layout_info::out) is det.
-stack_layout__set_string_table(K, LayoutInfo0, LayoutInfo) :-
- LayoutInfo0 = stack_layout_info(A, B, C, D, E, F, G, H, I, J, _, L),
- LayoutInfo = stack_layout_info(A, B, C, D, E, F, G, H, I, J, K, L).
-
:- pred stack_layout__set_label_tables(map(string, label_table)::in,
stack_layout_info::in, stack_layout_info::out) is det.
-stack_layout__set_label_tables(L, LayoutInfo0, LayoutInfo) :-
- LayoutInfo0 = stack_layout_info(A, B, C, D, E, F, G, H, I, J, K, _),
- LayoutInfo = stack_layout_info(A, B, C, D, E, F, G, H, I, J, K, L).
+stack_layout__set_cell_counter(CC, LI0, LI0^cell_counter := CC).
+stack_layout__set_string_table(ST, LI0, LI0^string_table := ST).
+stack_layout__set_label_tables(LT, LI0, LI0^label_tables := LT).
%---------------------------------------------------------------------------%
Index: compiler/transform_llds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/transform_llds.m,v
retrieving revision 1.5
diff -u -r1.5 transform_llds.m
--- compiler/transform_llds.m 2000/02/10 04:37:40 1.5
+++ compiler/transform_llds.m 2000/08/07 16:19:53
@@ -32,7 +32,7 @@
:- implementation.
:- import_module builtin_ops, globals, options, opt_util, prog_data.
-:- import_module bool, int, list, require, std_util.
+:- import_module bool, int, list, require, std_util, counter.
transform_llds(LLDS0, LLDS) -->
globals__io_lookup_int_option(max_jump_table_size, Size),
@@ -90,50 +90,49 @@
:- pred transform_c_procedure(c_procedure, c_procedure, io__state, io__state).
:- mode transform_c_procedure(in, out, di, uo) is det.
-transform_c_procedure(
- c_procedure(Name, Arity, PredProcId, Instructions0, Recons),
- c_procedure(Name, Arity, PredProcId, Instructions, Recons)) -->
- transform_instructions(Instructions0, Instructions).
+transform_c_procedure(Proc0, Proc) -->
+ { Proc0 = c_procedure(Name, Arity, PPId, Instrs0,
+ ProcLabel, C0, Recons) },
+ { Proc = c_procedure(Name, Arity, PPId, Instrs,
+ ProcLabel, C, Recons) },
+ transform_instructions(Instrs0, ProcLabel, C0, C, Instrs).
%-----------------------------------------------------------------------------%
-:- pred transform_instructions(list(instruction), list(instruction),
- io__state, io__state).
-:- mode transform_instructions(in, out, di, uo) is det.
-
-transform_instructions(Instrs0, Instrs) -->
- { opt_util__get_prologue(Instrs0, ProcLabel, _, _, _) },
- { max_label_int(Instrs0, 0, N) },
- transform_instructions_2(Instrs0, ProcLabel, N, Instrs).
-
-:- pred transform_instructions_2(list(instruction), proc_label, int,
+:- pred transform_instructions(list(instruction), proc_label, counter, counter,
list(instruction), io__state, io__state).
-:- mode transform_instructions_2(in, in, in, out, di, uo) is det.
+:- mode transform_instructions(in, in, in, out, out, di, uo) is det.
-transform_instructions_2([], _, _, []) --> [].
-transform_instructions_2([Instr0 | Instrs0], ProcLabel, N0, Instrs) -->
- transform_instruction(Instr0, ProcLabel, N0, InstrsA, N),
- transform_instructions_2(Instrs0, ProcLabel, N, InstrsB),
- { list__append(InstrsA, InstrsB, Instrs) }.
+transform_instructions(Instrs0, ProcLabel, C0, C, Instrs) -->
+ transform_instructions_2(Instrs0, ProcLabel, C0, C, Instrs).
+:- pred transform_instructions_2(list(instruction), proc_label,
+ counter, counter, list(instruction), io__state, io__state).
+:- mode transform_instructions_2(in, in, in, out, out, di, uo) is det.
+
+transform_instructions_2([], _, C, C, []) --> [].
+transform_instructions_2([Instr0 | Instrs0], ProcLabel, C0, C, Instrs) -->
+ transform_instruction(Instr0, ProcLabel, C0, InstrsA, C1),
+ transform_instructions_2(Instrs0, ProcLabel, C1, C, InstrsB),
+ { list__append(InstrsA, InstrsB, Instrs) }.
%-----------------------------------------------------------------------------%
-:- pred transform_instruction(instruction, proc_label, int,
- list(instruction), int, io__state, io__state).
+:- pred transform_instruction(instruction, proc_label, counter,
+ list(instruction), counter, io__state, io__state).
:- mode transform_instruction(in, in, in, out, out, di, uo) is det.
-transform_instruction(Instr0, ProcLabel, N0, Instrs, N) -->
+transform_instruction(Instr0, ProcLabel, C0, Instrs, C) -->
globals__io_lookup_int_option(max_jump_table_size, Size),
(
{ Instr0 = computed_goto(_Rval, Labels) - _},
{ list__length(Labels, L) },
{ L > Size }
->
- split_computed_goto(Instr0, Size, L, ProcLabel, N0, Instrs, N)
+ split_computed_goto(Instr0, Size, L, ProcLabel, C0, Instrs, C)
;
{ Instrs = [Instr0] },
- { N = N0 }
+ { C = C0 }
).
%-----------------------------------------------------------------------------%
@@ -146,21 +145,20 @@
% instructions, Is, to do a binary search down to a jump_table
% whose size is sufficiently small.
%
-:- pred split_computed_goto(instruction, int, int, proc_label, int,
- list(instruction), int, io__state, io__state).
+:- pred split_computed_goto(instruction, int, int, proc_label, counter,
+ list(instruction), counter, io__state, io__state).
:- mode split_computed_goto(in, in, in, in, in, out, out, di, uo) is det.
-split_computed_goto(Instr0, MaxSize, Length, ProcLabel, N0, Instrs, N) -->
+split_computed_goto(Instr0, MaxSize, Length, ProcLabel, C0, Instrs, C) -->
(
{ Length =< MaxSize }
->
{ Instrs = [Instr0] },
- { N = N0 }
+ { C = C0 }
;
{ Instr0 = computed_goto(Rval, Labels) - _Comment }
->
- { N1 is N0 + 1},
- { N2 is N1 + 1},
+ { counter__allocate(N, C0, C1) },
{ Mid = Length // 2 },
(
@@ -173,44 +171,22 @@
{ Index = binop((-), Rval, const(int_const(Mid))) },
{ Test = binop((>=), Rval, const(int_const(Mid))) },
- { ElseAddr = label(local(ProcLabel, N1)) },
- { ElseLabel = label(local(ProcLabel, N1)) - ""},
+ { ElseAddr = label(local(ProcLabel, N)) },
+ { ElseLabel = label(local(ProcLabel, N)) - ""},
{ IfInstr = if_val(Test, ElseAddr ) - "Binary search"},
{ ThenInstr = computed_goto(Rval, Start) - "Then section" },
{ ElseInstr = computed_goto(Index, End) - "Else section" },
- split_computed_goto(ThenInstr, MaxSize, Mid, ProcLabel, N2,
- ThenInstrs, N3),
+ split_computed_goto(ThenInstr, MaxSize, Mid, ProcLabel, C1,
+ ThenInstrs, C2),
split_computed_goto(ElseInstr, MaxSize, Length - Mid,
- ProcLabel, N3, ElseInstrs, N),
+ ProcLabel, C2, ElseInstrs, C),
{ list__append(ThenInstrs, [ElseLabel | ElseInstrs], InstrsA) },
{ Instrs = [IfInstr | InstrsA] }
;
{ error("split_computed_goto") }
- ).
-
-%-----------------------------------------------------------------------------%
-
- %
- % max_label_int(Is, M0, M)
- %
- % Find the highest integer, M, used in local labels from the list of
- % intructions, Is, where M0 is the highest integer found so far.
- %
-:- pred max_label_int(list(instruction), int, int).
-:- mode max_label_int(in, in, out) is det.
-
-max_label_int([], N, N).
-max_label_int([Instr - _Comment | Instrs], N0, N) :-
- (
- Instr = label(local(_, Num)),
- Num > N0
- ->
- max_label_int(Instrs, Num, N)
- ;
- max_label_int(Instrs, N0, N)
).
%-----------------------------------------------------------------------------%
Index: compiler/unify_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/unify_gen.m,v
retrieving revision 1.106
diff -u -r1.106 unify_gen.m
--- compiler/unify_gen.m 2000/04/14 08:38:31 1.106
+++ compiler/unify_gen.m 2000/08/07 14:17:24
@@ -546,11 +546,11 @@
),
{ continuation_info__generate_closure_layout(
ModuleInfo, PredId, ProcId, ClosureInfo) },
- code_info__get_cell_count(CNum0),
+ code_info__get_cell_counter(C0),
{ stack_layout__construct_closure_layout(ProcLabel,
ClosureInfo, ClosureLayoutMaybeRvals,
- ClosureLayoutArgTypes, CNum0, CNum) },
- code_info__set_cell_count(CNum),
+ ClosureLayoutArgTypes, C0, C) },
+ code_info__set_cell_counter(C),
code_info__get_next_cell_number(ClosureLayoutCellNo),
{ Reuse = no },
{ ClosureLayout = create(0, ClosureLayoutMaybeRvals,
Index: compiler/value_number.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/value_number.m,v
retrieving revision 1.104
diff -u -r1.104 value_number.m
--- compiler/value_number.m 2000/04/26 05:40:37 1.104
+++ compiler/value_number.m 2000/08/07 16:37:29
@@ -15,14 +15,14 @@
:- interface.
:- import_module llds.
-:- import_module list, set, io.
+:- import_module list, set, io, counter.
% Find straight-line code sequences and optimize them using
% value numbering.
-:- pred value_number_main(list(instruction), contains_reconstruction,
- set(label), list(instruction), io__state, io__state).
-:- mode value_number_main(in, in, in, out, di, uo) is det.
+:- pred value_number_main(list(instruction)::in, contains_reconstruction::in,
+ set(label)::in, proc_label::in, counter::in, counter::out,
+ list(instruction)::out, io__state::di, io__state::uo) is det.
% The main value numbering pass introduces references to temporary
% variables whose values need be preserved only within an extended
@@ -51,25 +51,25 @@
% 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, ContainsReconstruction, LayoutLabelSet, Instrs) -->
- { opt_util__get_prologue(Instrs0, ProcLabel,
- LabelInstr, Comments, Instrs1) },
- { opt_util__new_label_no(Instrs1, 1000, N0) },
+value_number_main(Instrs0, ContainsReconstruction, LayoutLabelSet,
+ ProcLabel, C0, C, Instrs) -->
+ { opt_util__get_prologue(Instrs0, LabelInstr, Comments, Instrs1) },
{ value_number__prepare_for_vn([LabelInstr | Instrs1], ProcLabel,
no, ContainsReconstruction, AllocSet, BreakSet,
- N0, N, Instrs2) },
+ C0, C1, Instrs2) },
{ labelopt__build_useset(Instrs2, LayoutLabelSet, UseSet) },
{ livemap__build(Instrs2, MaybeLiveMap) },
(
{ MaybeLiveMap = yes(LiveMap) },
vn_debug__livemap_msg(LiveMap),
value_number__procedure(Instrs2, LiveMap, UseSet,
- AllocSet, BreakSet, N, Instrs3),
+ AllocSet, BreakSet, C1, C, Instrs3),
{ list__append(Comments, Instrs3, Instrs) }
;
% Can't find live lvals and thus can't perform value numbering
% if there is a c_code or a pragma_c in the instructions.
{ MaybeLiveMap = no },
+ { C = C1 },
{ Instrs = Instrs0 }
).
@@ -127,41 +127,40 @@
% conservative -- we could mark the assignments which need to be
% treated this way during code generation.
-:- pred value_number__prepare_for_vn(list(instruction), proc_label, bool,
- contains_reconstruction, set(label), set(label),
- int, int, list(instruction)).
-:- mode value_number__prepare_for_vn(in, in, in, in,
- out, out, in, out, out) is det.
+:- pred value_number__prepare_for_vn(list(instruction)::in,
+ proc_label::in, bool::in, contains_reconstruction::in,
+ set(label)::out, set(label)::out,
+ counter::in, counter::out, list(instruction)::out) is det.
-value_number__prepare_for_vn([], _, _, _, AllocSet, BreakSet, N, N, []) :-
+value_number__prepare_for_vn([], _, _, _, AllocSet, BreakSet, C, C, []) :-
set__init(AllocSet),
set__init(BreakSet).
value_number__prepare_for_vn([Instr0 | Instrs0], ProcLabel, SeenAlloc,
- ContainsReconstruction, AllocSet, BreakSet, N0, N, Instrs) :-
+ ContainsReconstruction, AllocSet, BreakSet, C0, C, Instrs) :-
Instr0 = Uinstr0 - _Comment,
( Uinstr0 = if_val(Test, TrueAddr) ->
( ( TrueAddr = do_redo ; TrueAddr = do_fail ) ->
- MaybeBeforeLabel = yes(local(ProcLabel, N0)),
- N1 is N0 + 1
+ counter__allocate(N0, C0, C1),
+ MaybeBeforeLabel = yes(local(ProcLabel, N0))
;
MaybeBeforeLabel = no,
- N1 = N0
+ C1 = C0
),
( Instrs0 = [label(OldFalseLabel) - _ | _] ->
FalseLabel = OldFalseLabel,
MaybeNewFalseLabel = no,
- N2 = N1
+ C2 = C1
;
+ counter__allocate(N1, C1, C2),
FalseLabel = local(ProcLabel, N1),
- MaybeNewFalseLabel = yes(FalseLabel),
- N2 is N1 + 1
+ MaybeNewFalseLabel = yes(FalseLabel)
),
FalseAddr = label(FalseLabel),
value_number__breakup_complex_if(Test, TrueAddr, FalseAddr,
- FalseAddr, ProcLabel, N2, N3, IfInstrs),
+ FalseAddr, ProcLabel, C2, C3, IfInstrs),
value_number__prepare_for_vn(Instrs0, ProcLabel, SeenAlloc,
ContainsReconstruction, AllocSet, BreakSet0,
- N3, N, Instrs1),
+ C3, C, Instrs1),
( MaybeNewFalseLabel = yes(NewFalseLabel) ->
FalseInstr = label(NewFalseLabel) - "vn false label",
list__append(IfInstrs, [FalseInstr | Instrs1], Instrs2)
@@ -179,18 +178,18 @@
)
; Uinstr0 = incr_hp(_, _, _, _) ->
( SeenAlloc = yes ->
- N1 is N0 + 1,
+ counter__allocate(N0, C0, C1),
NewLabel = local(ProcLabel, N0),
value_number__prepare_for_vn(Instrs0, ProcLabel,
yes, ContainsReconstruction,
- AllocSet0, BreakSet, N1, N, Instrs1),
+ AllocSet0, BreakSet, C1, C, Instrs1),
set__insert(AllocSet0, NewLabel, AllocSet),
LabelInstr = label(NewLabel) - "vn incr divide label",
Instrs = [LabelInstr, Instr0 | Instrs1]
;
value_number__prepare_for_vn(Instrs0, ProcLabel, yes,
ContainsReconstruction, AllocSet, BreakSet,
- N0, N, Instrs1),
+ C0, C, Instrs1),
Instrs = [Instr0 | Instrs1]
)
;
@@ -219,55 +218,54 @@
Uinstr0 = free_heap(_)
)
->
- N1 is N0 + 1,
+ counter__allocate(N0, C0, C1),
BeforeLabel = local(ProcLabel, N0),
BeforeInstr = label(BeforeLabel) - "vn stack ctrl before label",
- N2 is N1 + 1,
+ counter__allocate(N1, C1, C2),
AfterLabel = local(ProcLabel, N1),
AfterInstr = label(AfterLabel) - "vn stack ctrl after label",
value_number__prepare_for_vn(Instrs0, ProcLabel, yes,
ContainsReconstruction, AllocSet, BreakSet0,
- N2, N, Instrs1),
+ C2, C, Instrs1),
set__insert(BreakSet0, BeforeLabel, BreakSet1),
set__insert(BreakSet1, AfterLabel, BreakSet),
Instrs = [BeforeInstr, Instr0, AfterInstr | Instrs1]
;
value_number__prepare_for_vn(Instrs0, ProcLabel, SeenAlloc,
ContainsReconstruction, AllocSet,
- BreakSet, N0, N, Instrs1),
+ BreakSet, C0, C, Instrs1),
Instrs = [Instr0 | Instrs1]
).
-:- pred value_number__breakup_complex_if(rval, code_addr, code_addr, code_addr,
- proc_label, int, int, list(instruction)).
-:- mode value_number__breakup_complex_if(in, in, in, in, in, in, out, out)
- is det.
+:- pred value_number__breakup_complex_if(rval::in,
+ code_addr::in, code_addr::in, code_addr::in, proc_label::in,
+ counter::in, counter::out, list(instruction)::out) is det.
value_number__breakup_complex_if(Test, TrueAddr, FalseAddr, NextAddr,
- ProcLabel, N0, N, Instrs) :-
+ ProcLabel, C0, C, Instrs) :-
( Test = binop(and, Test1, Test2) ->
+ counter__allocate(N0, C0, C1),
NewLabel = local(ProcLabel, N0),
NewAddr = label(NewLabel),
- N1 is N0 + 1,
value_number__breakup_complex_if(Test1, NewAddr, FalseAddr,
- NewAddr, ProcLabel, N1, N2, Instrs1),
+ NewAddr, ProcLabel, C1, C2, Instrs1),
value_number__breakup_complex_if(Test2, TrueAddr, FalseAddr,
- NextAddr, ProcLabel, N2, N, Instrs2),
+ NextAddr, ProcLabel, C2, C, Instrs2),
list__append(Instrs1, [label(NewLabel) - "" | Instrs2], Instrs)
; Test = binop(or, Test1, Test2) ->
+ counter__allocate(N0, C0, C1),
NewLabel = local(ProcLabel, N0),
NewAddr = label(NewLabel),
- N1 is N0 + 1,
value_number__breakup_complex_if(Test1, TrueAddr, NewAddr,
- NewAddr, ProcLabel, N1, N2, Instrs1),
+ NewAddr, ProcLabel, C1, C2, Instrs1),
value_number__breakup_complex_if(Test2, TrueAddr, FalseAddr,
- NextAddr, ProcLabel, N2, N, Instrs2),
+ NextAddr, ProcLabel, C2, C, Instrs2),
list__append(Instrs1, [label(NewLabel) - "" | Instrs2], Instrs)
; Test = unop(not, Test1) ->
value_number__breakup_complex_if(Test1, FalseAddr, TrueAddr,
- NextAddr, ProcLabel, N0, N, Instrs)
+ NextAddr, ProcLabel, C0, C, Instrs)
;
- N = N0,
+ C = C0,
( NextAddr = FalseAddr ->
Instrs = [if_val(Test, TrueAddr) - ""]
; NextAddr = TrueAddr ->
@@ -284,12 +282,13 @@
% Optimize the code of a procedure.
-:- pred value_number__procedure(list(instruction), livemap, set(label),
- set(label), set(label), int, list(instruction), io__state, io__state).
-:- mode value_number__procedure(in, in, in, in, in, in, out, di, uo) is det.
+:- pred value_number__procedure(list(instruction)::in, livemap::in,
+ set(label)::in, set(label)::in, set(label)::in,
+ counter::in, counter::out, list(instruction)::out,
+ io__state::di, io__state::uo) is det.
value_number__procedure(Instrs0, LiveMap, UseSet, AllocSet, BreakSet,
- N0, OptInstrs) -->
+ C0, C, OptInstrs) -->
globals__io_get_globals(Globals),
{ opt_util__gather_comments(Instrs0, Comments, Instrs1) },
{ globals__get_gc_method(Globals, GC) },
@@ -304,8 +303,8 @@
{ vn_block__divide_into_blocks(Instrs1, DivideSet, Blocks) },
{ globals__get_options(Globals, OptionTable) },
{ vn_type__init_params(OptionTable, Params) },
- value_number__optimize_blocks(Blocks, LiveMap, Params, N0, OptBlocks0,
- [], RevTuples),
+ value_number__optimize_blocks(Blocks, LiveMap, Params, C0, C1,
+ OptBlocks0, [], RevTuples),
{ list__condense([Comments | OptBlocks0], OptInstrs0) },
{ opt_util__propagate_livevals(OptInstrs0, OptInstrs1) },
vn_debug__cost_header_msg("procedure after non-pred value numbering"),
@@ -333,46 +332,50 @@
->
{ list__reverse(RevTuples, Tuples) },
value_number__process_parallel_tuples(Tuples,
- OptBlocks0, LiveMap, Params, OptBlocks),
+ OptBlocks0, LiveMap, Params, OptBlocks, C1, C),
{ list__condense([Comments | OptBlocks], OptInstrs2) },
{ opt_util__propagate_livevals(OptInstrs2, OptInstrs) },
vn_debug__cost_header_msg("procedure after parallels"),
vn_debug__dump_instrs(OptInstrs)
;
vn_debug__cost_header_msg("parallels do not apply"),
- { OptInstrs = OptInstrs0 }
+ { OptInstrs = OptInstrs0 },
+ { C = C1 }
)
;
- { OptInstrs = OptInstrs0 }
+ { OptInstrs = OptInstrs0 },
+ { C = C1 }
).
:- pred value_number__optimize_blocks(list(list(instruction)), livemap,
- vn_params, int, list(list(instruction)), list(maybe(vn_ctrl_tuple)),
- list(maybe(vn_ctrl_tuple)), io__state, io__state).
-% :- mode value_number__optimize_blocks(in, in, in, in, out, di, uo, di, uo)
-% is det.
-:- mode value_number__optimize_blocks(in, in, in, in, out, in, out, di, uo)
- is det.
+ vn_params, counter, counter, list(list(instruction)),
+ list(maybe(vn_ctrl_tuple)), list(maybe(vn_ctrl_tuple)),
+ io__state, io__state).
+% :- mode value_number__optimize_blocks(in, in, in, in, out, out, di, uo,
+% di, uo) is det.
+:- mode value_number__optimize_blocks(in, in, in, in, out, out, in, out,
+ di, uo) is det.
-value_number__optimize_blocks([], _, _, _, [], Tuples, Tuples) --> [].
-value_number__optimize_blocks([Block0 | Blocks0], LiveMap, Params, LabelNo0,
+value_number__optimize_blocks([], _, _, C, C, [], Tuples, Tuples) --> [].
+value_number__optimize_blocks([Block0 | Blocks0], LiveMap, Params, C0, C,
[Block | Blocks], RevTuples0, RevTuples) -->
value_number__optimize_block(Block0, LiveMap, Params, [],
- LabelNo0, LabelNo1, Block, RevTuples0, RevTuples1),
- value_number__optimize_blocks(Blocks0, LiveMap, Params, LabelNo1,
- Blocks, RevTuples1, RevTuples).
+ C0, C1, Block, RevTuples0, RevTuples1),
+ value_number__optimize_blocks(Blocks0, LiveMap, Params,
+ C1, C, Blocks, RevTuples1, RevTuples).
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
:- pred value_number__optimize_block(list(instruction), livemap, vn_params,
- list(parentry), int, int, list(instruction), list(maybe(vn_ctrl_tuple)),
- list(maybe(vn_ctrl_tuple)), io__state, io__state).
+ list(parentry), counter, counter, list(instruction),
+ list(maybe(vn_ctrl_tuple)), list(maybe(vn_ctrl_tuple)),
+ io__state, io__state).
:- mode value_number__optimize_block(in, in, in, in, in, out, out, in, out,
di, uo) is det.
-value_number__optimize_block(Instrs0, LiveMap, Params, ParEntries,
- LabelNo0, LabelNo, Instrs, RevTuples0, RevTuples) -->
+value_number__optimize_block(Instrs0, LiveMap, Params, ParEntries, C0, C,
+ Instrs, RevTuples0, RevTuples) -->
(
{ list__reverse(Instrs0, RevInstrs) },
{ RevInstrs = [LastInstr - _ | _] },
@@ -381,13 +384,13 @@
% The block ends with a call to an erroneous procedure
% and its never to be used return label
{ Instrs = Instrs0 },
- { LabelNo = LabelNo0 },
+ { C = C0 },
{ RevTuples = [no | RevTuples0] }
;
value_number__optimize_fragment(Instrs0, LiveMap, Params,
- ParEntries, LabelNo0, Tuple, Instrs),
+ ParEntries, C0, Tuple, Instrs),
vn_debug__tuple_msg(no, Instrs, Tuple),
- { Tuple = tuple(_, _, _, LabelNo, _) },
+ { Tuple = tuple(_, _, _, C, _) },
{ RevTuples = [yes(Tuple) | RevTuples0] }
).
@@ -398,13 +401,11 @@
% or it may be a part of the block; we optimize parts of blocks if
% a conflict prevents us from optimizing the whole block together.
-:- pred value_number__optimize_fragment(list(instruction), livemap, vn_params,
- list(parentry), int, vn_ctrl_tuple, list(instruction),
- io__state, io__state).
-:- mode value_number__optimize_fragment(in, in, in, in, in, out, out, di, uo)
- is det.
+:- pred value_number__optimize_fragment(list(instruction)::in, livemap::in,
+ vn_params::in, list(parentry)::in, counter::in, vn_ctrl_tuple::out,
+ list(instruction)::out, io__state::di, io__state::uo) is det.
-value_number__optimize_fragment(Instrs0, LiveMap, Params, ParEntries, LabelNo0,
+value_number__optimize_fragment(Instrs0, LiveMap, Params, ParEntries, C0,
Tuple, Instrs) -->
globals__io_get_gc_method(GC),
(
@@ -417,17 +418,15 @@
{ error("instruction sequence with several incr_hps in value_number__optimize_fragment") }
;
value_number__optimize_fragment_2(Instrs0, LiveMap, Params,
- ParEntries, LabelNo0, Tuple, Instrs)
+ ParEntries, C0, Tuple, Instrs)
).
-:- pred value_number__optimize_fragment_2(list(instruction), livemap, vn_params,
- list(parentry), int, vn_ctrl_tuple, list(instruction),
- io__state, io__state).
-:- mode value_number__optimize_fragment_2(in, in, in, in, in, out, out, di, uo)
- is det.
+:- pred value_number__optimize_fragment_2(list(instruction)::in, livemap::in,
+ vn_params::in, list(parentry)::in, counter::in, vn_ctrl_tuple::out,
+ list(instruction)::out, io__state::di, io__state::uo) is det.
value_number__optimize_fragment_2(Instrs0, LiveMap, Params, ParEntries,
- LabelNo0, Tuple, Instrs) -->
+ C0, Tuple, Instrs) -->
( { Instrs0 = [Uinstr0Prime - _ | _] } ->
{ Uinstr0 = Uinstr0Prime },
vn_debug__fragment_msg(Uinstr0)
@@ -435,8 +434,8 @@
{ error("empty instruction sequence in value_number__optimize_fragment") }
),
{ vn_block__build_block_info(Instrs0, LiveMap, Params, ParEntries,
- LabelNo0, VnTables0, Liveset0, SeenIncr0, Tuple0) },
- { Tuple0 = tuple(Ctrl, Ctrlmap, Flushmap, LabelNo, _Parmap) },
+ C0, VnTables0, Liveset0, SeenIncr0, Tuple0) },
+ { Tuple0 = tuple(Ctrl, Ctrlmap, Flushmap, C, _Parmap) },
{ vn_util__build_uses(Liveset0, Ctrlmap, VnTables0, VnTables1) },
@@ -482,7 +481,7 @@
->
vn_debug__cost_msg(yes, OrigCost, VnCost),
{ vn_block__build_block_info(Instrs6, LiveMap, Params,
- ParEntries, LabelNo0, VnTables6, Liveset6,
+ ParEntries, C0, VnTables6, Liveset6,
SeenIncr6, Tuple6) },
vn_verify__ok(Instrs6, Uinstr0, SeenIncr0, SeenIncr6,
Liveset0, Liveset6, VnTables0, VnTables6, OK),
@@ -512,13 +511,13 @@
% )
->
value_number__try_again(Instrs0, [], RestartLabel,
- LiveMap, Params, LabelNo, Instrs)
+ LiveMap, Params, C, Instrs)
;
value_number__last_ditch(Instrs0,
- LiveMap, Params, LabelNo, Instrs)
+ LiveMap, Params, C, Instrs)
),
{ vn_block__build_block_info(Instrs, LiveMap, Params,
- ParEntries, LabelNo0, _, _, _, Tuple) },
+ ParEntries, C0, _, _, _, Tuple) },
vn_debug__tuple_msg(yes(yes), Instrs, Tuple)
).
@@ -566,20 +565,20 @@
),
value_number__compatible_positions(Entries, Positions1, Positions).
-:- pred value_number__try_again(list(instruction), list(instruction), label,
- livemap, vn_params, int, list(instruction), io__state, io__state).
-:- mode value_number__try_again(in, in, in, in, in, in, out, di, uo) is det.
+:- pred value_number__try_again(list(instruction)::in, list(instruction)::in,
+ label::in, livemap::in, vn_params::in, counter::in,
+ list(instruction)::out, io__state::di, io__state::uo) is det.
-value_number__try_again([], RevInstrs, _Label, LiveMap, Params, LabelNo0,
+value_number__try_again([], RevInstrs, _Label, LiveMap, Params, C0,
Instrs) -->
{ list__reverse(RevInstrs, Instrs0) },
- value_number__last_ditch(Instrs0, LiveMap, Params, LabelNo0, Instrs).
+ value_number__last_ditch(Instrs0, LiveMap, Params, C0, Instrs).
value_number__try_again([Instr0 | Instrs0], RevInstrs0, RestartLabel, LiveMap,
- Params, LabelNo0, Instrs) -->
+ Params, C0, Instrs) -->
( { Instr0 = label(RestartLabel) - _ } ->
( { RevInstrs0 = [] } ->
value_number__last_ditch(Instrs0, LiveMap, Params,
- LabelNo0, Instrs1),
+ C0, Instrs1),
{ Instrs = [Instr0 | Instrs1] }
;
vn_debug__divide_msg(Instr0),
@@ -592,9 +591,9 @@
{ list__reverse([GotoInstr | RevInstrs0],
FrontInstrs0) },
value_number__optimize_fragment(FrontInstrs0, LiveMap,
- Params, [], LabelNo0, _, FrontInstrs1),
+ Params, [], C0, _, FrontInstrs1),
value_number__optimize_fragment(Instrs0, LiveMap,
- Params, [], LabelNo0, _, BackInstrs),
+ Params, [], C0, _, BackInstrs),
%
% we need to get rid of the introduced goto,
% which should still be at the end of FrontInstrs1,
@@ -614,17 +613,17 @@
;
{ RevInstrs1 = [Instr0 | RevInstrs0] },
value_number__try_again(Instrs0, RevInstrs1, RestartLabel,
- LiveMap, Params, LabelNo0, Instrs)
+ LiveMap, Params, C0, Instrs)
).
%-----------------------------------------------------------------------------%
-:- pred value_number__last_ditch(list(instruction), livemap, vn_params, int,
- list(instruction), io__state, io__state).
-:- mode value_number__last_ditch(in, in, in, in, out, di, uo) is det.
+:- pred value_number__last_ditch(list(instruction)::in, livemap::in,
+ vn_params::in, counter::in, list(instruction)::out,
+ io__state::di, io__state::uo) is det.
value_number__last_ditch([], _, _, _, []) --> [].
-value_number__last_ditch([Instr0 | Instrs0], LiveMap, Params, LabelNo0,
+value_number__last_ditch([Instr0 | Instrs0], LiveMap, Params, C0,
Instrs) -->
(
{ Instr0 = Uinstr0 - _ },
@@ -638,11 +637,11 @@
->
vn_debug__restart_msg(Instr0),
value_number__optimize_fragment(Instrs0, LiveMap, Params,
- [], LabelNo0, _, Instrs1),
+ [], C0, _, Instrs1),
{ Instrs = [Instr0 | Instrs1] }
;
value_number__last_ditch(Instrs0, LiveMap, Params,
- LabelNo0, Instrs1),
+ C0, Instrs1),
{ Instrs = [Instr0 | Instrs1] }
).
@@ -651,17 +650,17 @@
:- pred value_number__process_parallel_tuples(list(maybe(vn_ctrl_tuple)),
list(list(instruction)), livemap, vn_params, list(list(instruction)),
- io__state, io__state).
-:- mode value_number__process_parallel_tuples(in, in, in, in, out, di, uo)
- is det.
+ counter, counter, io__state, io__state).
+:- mode value_number__process_parallel_tuples(in, in, in, in, out, in, out,
+ di, uo) is det.
value_number__process_parallel_tuples(Tuples0, Blocks0, LiveMap, Params,
- Blocks) -->
+ Blocks, C0, C) -->
{ list__length(Tuples0, TupleLength) },
{ list__length(Blocks0, BlockLength) },
( { TupleLength = BlockLength } ->
value_number__process_parallel_tuples_2(Blocks0, Tuples0,
- LiveMap, Params, Blocks0, Blocks1, Extras),
+ LiveMap, Params, Blocks0, Blocks1, Extras, C0, C),
{ value_number__insert_new_blocks(Extras, Blocks1, Blocks) }
;
{ error("number of tuples and blocks differ") }
@@ -681,13 +680,15 @@
:- pred value_number__process_parallel_tuples_2(list(list(instruction)),
list(maybe(vn_ctrl_tuple)), livemap, vn_params,
list(list(instruction)), list(list(instruction)),
- assoc_list(label, list(instruction)), io__state, io__state).
+ assoc_list(label, list(instruction)), counter, counter,
+ io__state, io__state).
:- mode value_number__process_parallel_tuples_2(in, in, in, in, in, out, out,
- di, uo) is det.
+ in, out, di, uo) is det.
-value_number__process_parallel_tuples_2([], _, _, _, _, [], []) --> [].
+value_number__process_parallel_tuples_2([], _, _, _, _, [], [], C, C) --> [].
value_number__process_parallel_tuples_2([Block0 | Blocks0], MaybeTuples0,
- LiveMap, Params, AllBlocks, [Block | Blocks], Extras) -->
+ LiveMap, Params, AllBlocks, [Block | Blocks], Extras, C0, C)
+ -->
{ MaybeTuples0 = [MaybeTuple0Prime | MaybeTuples1Prime] ->
MaybeTuple0 = MaybeTuple0Prime,
MaybeTuples1 = MaybeTuples1Prime
@@ -697,31 +698,34 @@
(
{ MaybeTuple0 = yes(Tuple) },
value_number__process_parallel_tuple(Block0, Tuple,
- LiveMap, Params, AllBlocks, Block, Extras1)
+ LiveMap, Params, AllBlocks, Block, Extras1, C0, C1)
;
{ MaybeTuple0 = no },
{ Block = Block0 },
- { Extras1 = [] }
+ { Extras1 = [] },
+ { C1 = C0 }
),
value_number__process_parallel_tuples_2(Blocks0, MaybeTuples1,
- LiveMap, Params, AllBlocks, Blocks, Extras2),
+ LiveMap, Params, AllBlocks, Blocks, Extras2, C1, C),
{ list__append(Extras1, Extras2, Extras) }.
:- pred value_number__process_parallel_tuple(list(instruction), vn_ctrl_tuple,
livemap, vn_params, list(list(instruction)), list(instruction),
- assoc_list(label, list(instruction)), io__state, io__state).
+ assoc_list(label, list(instruction)), counter, counter,
+ io__state, io__state).
:- mode value_number__process_parallel_tuple(in, in, in, in, in, out, out,
- di, uo) is det.
+ in, out, di, uo) is det.
value_number__process_parallel_tuple(Block0, tuple(_, _, _, _, Parmap),
- LiveMap, Params, AllBlocks, Block, Extras) -->
+ LiveMap, Params, AllBlocks, Block, Extras, C0, C) -->
{ map__values(Parmap, ParList) },
( { value_number__all_empty_lists(ParList) } ->
{ Block = Block0 },
- { Extras = [] }
+ { Extras = [] },
+ { C = C0 }
;
value_number__process_parallel_nodes(ParList, LiveMap, Params,
- Block0, AllBlocks, Block, Extras)
+ Block0, AllBlocks, Block, Extras, C0, C)
).
:- pred value_number__all_empty_lists(list(list(T))).
@@ -734,39 +738,43 @@
:- pred value_number__process_parallel_nodes(list(list(parallel)), livemap,
vn_params, list(instruction), list(list(instruction)),
list(instruction), assoc_list(label, list(instruction)),
- io__state, io__state).
+ counter, counter, io__state, io__state).
:- mode value_number__process_parallel_nodes(in, in, in, in, in, out, out,
- di, uo) is det.
+ in, out, di, uo) is det.
-value_number__process_parallel_nodes([], _, _, Block, _, Block, []) --> [].
+value_number__process_parallel_nodes([], _, _, Block, _, Block, [], C, C)
+ --> [].
value_number__process_parallel_nodes([Par0 | Pars1], LiveMap, Params,
- Block0, AllBlocks, Block, Extras) -->
+ Block0, AllBlocks, Block, Extras, C0, C) -->
{ vn_block__split_at_next_ctrl_instr(Block0, Start, NodeInstr,
Block1) },
value_number__process_parallels(Par0, LiveMap, Params,
- NodeInstr, NewNodeInstr, AllBlocks, Extras1),
+ NodeInstr, NewNodeInstr, AllBlocks, Extras1, C0, C1),
value_number__process_parallel_nodes(Pars1, LiveMap, Params,
- Block1, AllBlocks, Block2, Extras2),
+ Block1, AllBlocks, Block2, Extras2, C1, C),
{ list__condense([Start, [NewNodeInstr], Block2], Block) },
{ list__append(Extras1, Extras2, Extras) }.
:- pred value_number__process_parallels(list(parallel), livemap, vn_params,
instruction, instruction, list(list(instruction)),
- assoc_list(label, list(instruction)), io__state, io__state).
-:- mode value_number__process_parallels(in, in, in, in, out, in, out, di, uo)
- is det.
+ assoc_list(label, list(instruction)), counter, counter,
+ io__state, io__state).
+:- mode value_number__process_parallels(in, in, in, in, out, in, out, in, out,
+ di, uo) is det.
value_number__process_parallels(Pars, LiveMap, Params, Instr0, Instr,
- AllBlocks, Extras) -->
+ AllBlocks, Extras, C0, C) -->
{ Instr0 = Uinstr0 - Comment },
( { Pars = [] } ->
{ Instr = Instr0 },
- { Extras = []}
+ { Extras = []},
+ { C = C0 }
; { Uinstr0 = if_val(Rval, label(Label)) } ->
( { Pars = [Par] } ->
( { Par = parallel(Label, _NewLabel, _ParEntries) } ->
value_number__process_parallel(Par, LiveMap,
- Params, AllBlocks, FinalLabel, Extras),
+ Params, AllBlocks, FinalLabel, Extras,
+ C0, C),
{ Instr = if_val(Rval, label(FinalLabel))
- Comment }
;
@@ -779,7 +787,8 @@
( { Pars = [Par] } ->
( { Par = parallel(Label, _NewLabel, _ParEntries) } ->
value_number__process_parallel(Par, LiveMap,
- Params, AllBlocks, FinalLabel, Extras),
+ Params, AllBlocks, FinalLabel, Extras,
+ C0, C),
{ Instr = goto(label(FinalLabel)) - Comment }
;
{ error("wrong label in parallel for goto") }
@@ -791,11 +800,12 @@
{ value_number__pair_labels_pars(Labels, Pars, LabelPars) },
vn_debug__computed_goto_msg(Labels, Pars, LabelPars),
value_number__process_parallel_list(LabelPars, LiveMap,
- Params, AllBlocks, FinalLabels, Extras),
+ Params, AllBlocks, FinalLabels, Extras, C0, C),
{ Instr = computed_goto(Rval, FinalLabels) - Comment }
;
{ Instr = Instr0 },
- { Extras = [] }
+ { Extras = [] },
+ { C = C0 }
).
:- pred value_number__pair_labels_pars(list(label), list(parallel),
@@ -834,13 +844,14 @@
:- pred value_number__process_parallel_list(assoc_list(label, maybe(parallel)),
livemap, vn_params, list(list(instruction)), list(label),
- assoc_list(label, list(instruction)), io__state, io__state).
-:- mode value_number__process_parallel_list(in, in, in, in, out, out, di, uo)
- is det.
-
-value_number__process_parallel_list([], _, _, _, [], []) --> [].
-value_number__process_parallel_list([OldLabel - MaybePar | LabelPars],
- LiveMap, Params, AllBlocks, [Label | Labels], Extras) -->
+ assoc_list(label, list(instruction)), counter, counter,
+ io__state, io__state).
+:- mode value_number__process_parallel_list(in, in, in, in, out, out, in, out,
+ di, uo) is det.
+
+value_number__process_parallel_list([], _, _, _, [], [], C, C) --> [].
+value_number__process_parallel_list([OldLabel - MaybePar | LabelPars], LiveMap,
+ Params, AllBlocks, [Label | Labels], Extras, C0, C) -->
( { MaybePar = yes(Par) } ->
( { Par = parallel(OldLabel, _, _) } ->
[]
@@ -848,28 +859,29 @@
{ error("wrong label in parallel for computed_goto") }
),
value_number__process_parallel(Par, LiveMap, Params,
- AllBlocks, Label, Extras1),
+ AllBlocks, Label, Extras1, C0, C1),
value_number__process_parallel_list(LabelPars, LiveMap, Params,
- AllBlocks, Labels, Extras2),
+ AllBlocks, Labels, Extras2, C1, C),
{ list__append(Extras1, Extras2, Extras) }
;
{ Label = OldLabel },
value_number__process_parallel_list(LabelPars, LiveMap, Params,
- AllBlocks, Labels, Extras)
+ AllBlocks, Labels, Extras, C0, C)
).
:- pred value_number__process_parallel(parallel, livemap, vn_params,
list(list(instruction)), label, assoc_list(label, list(instruction)),
- io__state, io__state).
-:- mode value_number__process_parallel(in, in, in, in, out, out, di, uo) is det.
+ counter, counter, io__state, io__state).
+:- mode value_number__process_parallel(in, in, in, in, out, out, in, out,
+ di, uo) is det.
value_number__process_parallel(Par, LiveMap, Params, AllBlocks, FinalLabel,
- Extras) -->
+ Extras, C0, C) -->
vn_debug__parallel_msg(Par),
{ Par = parallel(OldLabel, NewLabel, ParEntries) },
{ value_number__find_block_by_label(AllBlocks, OldLabel, _, Block, _) },
value_number__optimize_block(Block, LiveMap, Params, ParEntries,
- 2000, _, NewBlock0, [], _),
+ C0, C, NewBlock0, [], _),
vn_cost__block_cost(Block, Params, no, OrigCost),
vn_cost__block_cost(NewBlock0, Params, no, ParCost),
{
Index: compiler/vn_block.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/vn_block.m,v
retrieving revision 1.64
diff -u -r1.64 vn_block.m
--- compiler/vn_block.m 2000/04/26 05:40:41 1.64
+++ compiler/vn_block.m 2000/08/07 16:25:27
@@ -15,15 +15,15 @@
:- interface.
-:- import_module list, set, bool.
:- import_module llds, vn_table, vn_type, livemap.
+:- import_module list, set, bool, counter.
:- pred vn_block__divide_into_blocks(list(instruction), set(label),
list(list(instruction))).
:- mode vn_block__divide_into_blocks(in, in, out) is det.
:- pred vn_block__build_block_info(list(instruction), livemap, vn_params,
- list(parentry), int, vn_tables, vnlvalset, bool, vn_ctrl_tuple).
+ list(parentry), counter, vn_tables, vnlvalset, bool, vn_ctrl_tuple).
:- mode vn_block__build_block_info(in, in, in, in, in, out, out, out, out)
is det.
@@ -90,7 +90,7 @@
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
-vn_block__build_block_info(Instrs, Livemap, Params, ParEntries, LabelNo0,
+vn_block__build_block_info(Instrs, Livemap, Params, ParEntries, C0,
VnTables, Liveset, SeenIncr, Tuple) :-
vn_table__init_tables(VnTables0),
vn_block__build_from_parallel(ParEntries, VnTables0, VnTables1),
@@ -98,7 +98,7 @@
map__init(Ctrlmap0),
map__init(Flushmap0),
map__init(Parmap0),
- Tuple0 = tuple(0, Ctrlmap0, Flushmap0, LabelNo0, Parmap0),
+ Tuple0 = tuple(0, Ctrlmap0, Flushmap0, C0, Parmap0),
vn_block__handle_instrs(Instrs, Livemap, Params, VnTables1, VnTables,
Liveset0, Liveset, no, SeenIncr, Tuple0, Tuple).
@@ -405,8 +405,8 @@
vn_block__new_ctrl_node(VnInstr, Livemap, Params,
VnTables0, VnTables, Liveset0, Liveset,
- tuple(Ctrl0, Ctrlmap0, Flushmap0, LabelNo0, Parmap0),
- tuple(Ctrl, Ctrlmap, Flushmap, LabelNo, Parmap)) :-
+ tuple(Ctrl0, Ctrlmap0, Flushmap0, C0, Parmap0),
+ tuple(Ctrl, Ctrlmap, Flushmap, C, Parmap)) :-
map__init(FlushEntry0),
(
VnInstr = vn_livevals(Livevals),
@@ -415,27 +415,27 @@
Liveset0, Liveset),
VnTables = VnTables0,
FlushEntry = FlushEntry0,
- LabelNo = LabelNo0,
+ C = C0,
Parallels = []
;
VnInstr = vn_call(_, _, _, _, _),
vn_block__record_at_call(VnTables0, VnTables, Liveset0, Liveset,
FlushEntry0, FlushEntry),
- LabelNo = LabelNo0,
+ C = C0,
Parallels = []
;
VnInstr = vn_mkframe(_, _),
VnTables = VnTables0,
Liveset = Liveset0,
FlushEntry = FlushEntry0,
- LabelNo = LabelNo0,
+ C = C0,
Parallels = []
;
VnInstr = vn_label(_),
VnTables = VnTables0,
Liveset = Liveset0,
FlushEntry = FlushEntry0,
- LabelNo = LabelNo0,
+ C = C0,
Parallels = []
;
VnInstr = vn_goto(TargetAddr),
@@ -446,44 +446,44 @@
vn_block__record_one_label(Label, Livemap, Params,
VnTables0, VnTables, Liveset0, Liveset,
FlushEntry0, FlushEntry,
- LabelNo0, LabelNo, Parallels)
+ C0, C, Parallels)
;
vn_block__record_at_call(VnTables0, VnTables,
Liveset0, Liveset, FlushEntry0, FlushEntry),
- LabelNo = LabelNo0,
+ C = C0,
Parallels = []
)
;
VnInstr = vn_computed_goto(_, Labels),
vn_block__record_several_labels(Labels, Livemap, Params,
VnTables0, VnTables, Liveset0, Liveset,
- FlushEntry0, FlushEntry, LabelNo0, LabelNo, Parallels)
+ FlushEntry0, FlushEntry, C0, C, Parallels)
;
VnInstr = vn_if_val(_, TargetAddr),
vn_block__new_if_node(TargetAddr, Livemap, Params,
Ctrlmap0, Ctrl0, VnTables0, VnTables, Liveset0, Liveset,
- FlushEntry0, FlushEntry, LabelNo0, LabelNo, Parallels)
+ FlushEntry0, FlushEntry, C0, C, Parallels)
;
VnInstr = vn_mark_hp(Vnlval),
vn_util__rval_to_vn(lval(hp), Vn, VnTables0, VnTables1),
vn_table__set_desired_value(Vnlval, Vn, VnTables1, VnTables),
set__insert(Liveset0, Vnlval, Liveset),
FlushEntry = FlushEntry0,
- LabelNo = LabelNo0,
+ C = C0,
Parallels = []
;
VnInstr = vn_restore_hp(_),
VnTables = VnTables0,
Liveset = Liveset0,
FlushEntry = FlushEntry0,
- LabelNo = LabelNo0,
+ C = C0,
Parallels = []
;
VnInstr = vn_free_heap(_),
VnTables = VnTables0,
Liveset = Liveset0,
FlushEntry = FlushEntry0,
- LabelNo = LabelNo0,
+ C = C0,
Parallels = []
;
VnInstr = vn_store_ticket(Vnlval),
@@ -497,28 +497,28 @@
vn_table__set_desired_value(Vnlval, Vn, VnTables1, VnTables),
set__insert(Liveset0, Vnlval, Liveset),
FlushEntry = FlushEntry0,
- LabelNo = LabelNo0,
+ C = C0,
Parallels = []
;
VnInstr = vn_reset_ticket(_, _),
VnTables = VnTables0,
Liveset = Liveset0,
FlushEntry = FlushEntry0,
- LabelNo = LabelNo0,
+ C = C0,
Parallels = []
;
VnInstr = vn_discard_ticket,
VnTables = VnTables0,
Liveset = Liveset0,
FlushEntry = FlushEntry0,
- LabelNo = LabelNo0,
+ C = C0,
Parallels = []
;
VnInstr = vn_prune_ticket,
VnTables = VnTables0,
Liveset = Liveset0,
FlushEntry = FlushEntry0,
- LabelNo = LabelNo0,
+ C = C0,
Parallels = []
;
VnInstr = vn_mark_ticket_stack(Vnlval),
@@ -532,28 +532,28 @@
vn_table__set_desired_value(Vnlval, Vn, VnTables1, VnTables),
set__insert(Liveset0, Vnlval, Liveset),
FlushEntry = FlushEntry0,
- LabelNo = LabelNo0,
+ C = C0,
Parallels = []
;
VnInstr = vn_prune_tickets_to(_),
VnTables = VnTables0,
Liveset = Liveset0,
FlushEntry = FlushEntry0,
- LabelNo = LabelNo0,
+ C = C0,
Parallels = []
;
VnInstr = vn_incr_sp(_, _),
VnTables = VnTables0,
Liveset = Liveset0,
FlushEntry = FlushEntry0,
- LabelNo = LabelNo0,
+ C = C0,
Parallels = []
;
VnInstr = vn_decr_sp(_),
VnTables = VnTables0,
Liveset = Liveset0,
FlushEntry = FlushEntry0,
- LabelNo = LabelNo0,
+ C = C0,
Parallels = []
),
Ctrl is Ctrl0 + 1,
@@ -563,13 +563,13 @@
:- pred vn_block__new_if_node(code_addr, livemap, vn_params, ctrlmap, int,
vn_tables, vn_tables, vnlvalset, vnlvalset,
- flushmapentry, flushmapentry, int, int, list(parallel)).
+ flushmapentry, flushmapentry, counter, counter, list(parallel)).
:- mode vn_block__new_if_node(in, in, in, in, in, in, out, in, out, in, out, in,
out, out) is det.
vn_block__new_if_node(TargetAddr, Livemap, Params, Ctrlmap0, Ctrl0,
VnTables0, VnTables, Liveset0, Liveset, FlushEntry0, FlushEntry,
- LabelNo0, LabelNo, Parallels) :-
+ C0, C, Parallels) :-
(
TargetAddr = label(Label),
map__search(Livemap, Label, _)
@@ -577,7 +577,7 @@
vn_block__record_one_label(Label, Livemap, Params,
VnTables0, VnTables1, Liveset0, Liveset1,
FlushEntry0, FlushEntry1,
- LabelNo0, LabelNoPrime, ParallelsPrime),
+ C0, CPrime, ParallelsPrime),
vn_block__record_compulsory_lvals(VnTables1, Liveset1, Liveset2,
FlushEntry1, FlushEntry2),
(
@@ -592,13 +592,13 @@
VnTables1, VnTables,
Liveset2, Liveset,
FlushEntry2, FlushEntry),
- LabelNo = LabelNo0,
+ C = C0,
Parallels = []
;
VnTables = VnTables1,
Liveset = Liveset2,
FlushEntry = FlushEntry2,
- LabelNo = LabelNoPrime,
+ C = CPrime,
Parallels = ParallelsPrime
)
;
@@ -607,7 +607,7 @@
VnTables = VnTables0,
Liveset = Liveset0,
FlushEntry = FlushEntry0,
- LabelNo = LabelNo0,
+ C = C0,
Parallels = []
;
TargetAddr = do_redo
@@ -615,13 +615,13 @@
vn_block__record_compulsory_lvals(VnTables0, Liveset0, Liveset,
FlushEntry0, FlushEntry),
VnTables = VnTables0,
- LabelNo = LabelNo0,
+ C = C0,
Parallels = []
;
set__to_sorted_list(Liveset0, Vnlivelist),
vn_block__record_livevnlvals(Vnlivelist, VnTables0, VnTables,
Liveset0, Liveset, FlushEntry0, FlushEntry),
- LabelNo = LabelNo0,
+ C = C0,
Parallels = []
).
@@ -658,7 +658,7 @@
:- pred vn_block__record_several_labels(list(label), livemap, vn_params,
vn_tables, vn_tables, vnlvalset, vnlvalset,
- flushmapentry, flushmapentry, int, int, list(parallel)).
+ flushmapentry, flushmapentry, counter, counter, list(parallel)).
% :- mode vn_block__record_several_labels(in, in, in, di, uo, di, uo, di, uo,
% in, out, out) is det.
:- mode vn_block__record_several_labels(in, in, in, in, out, in, out, in, out,
@@ -666,25 +666,25 @@
vn_block__record_several_labels(Labels, Livemap, Params, VnTables0, VnTables,
Livevals0, Livevals, FlushEntry0, FlushEntry,
- LabelNo0, LabelNo, Parallels) :-
+ C0, C, Parallels) :-
vn_block__record_labels(Labels, Livemap, Params, VnTables0, VnTables,
Livevals0, Livevals1, FlushEntry0, FlushEntry1,
- LabelNo0, LabelNo, Parallels),
+ C0, C, Parallels),
vn_block__record_compulsory_lvals(VnTables, Livevals1, Livevals,
FlushEntry1, FlushEntry).
:- pred vn_block__record_one_label(label, livemap, vn_params,
vn_tables, vn_tables, vnlvalset, vnlvalset,
- flushmapentry, flushmapentry, int, int, list(parallel)).
+ flushmapentry, flushmapentry, counter, counter, list(parallel)).
:- mode vn_block__record_one_label(in, in, in, in, out, in, out, in, out, in,
out, out) is det.
vn_block__record_one_label(Label, Livemap, Params, VnTables0, VnTables,
Livevals0, Livevals, FlushEntry0, FlushEntry,
- LabelNo0, LabelNo, Parallels) :-
+ C0, C, Parallels) :-
vn_block__record_label(Label, Livemap, Params, VnTables0, VnTables,
Livevals0, Livevals1, FlushEntry0, FlushEntry1,
- LabelNo0, LabelNo, Parallels),
+ C0, C, Parallels),
vn_block__record_compulsory_lvals(VnTables, Livevals1, Livevals,
FlushEntry1, FlushEntry).
@@ -692,28 +692,28 @@
:- pred vn_block__record_labels(list(label), livemap, vn_params,
vn_tables, vn_tables, vnlvalset, vnlvalset,
- flushmapentry, flushmapentry, int, int, list(parallel)).
+ flushmapentry, flushmapentry, counter, counter, list(parallel)).
% :- mode vn_block__record_labels(in, in, in, di, uo, di, uo, di, uo, in,
% out, out) is det.
:- mode vn_block__record_labels(in, in, in, in, out, in, out, in, out, in,
out, out) is det.
vn_block__record_labels([], _, _, VnTables, VnTables, Livevals, Livevals,
- FlushEntry, FlushEntry, LabelNo, LabelNo, []).
+ FlushEntry, FlushEntry, C, C, []).
vn_block__record_labels([Label | Labels], Livemap, Params, VnTables0, VnTables,
Livevals0, Livevals, FlushEntry0, FlushEntry,
- LabelNo0, LabelNo, Parallels) :-
+ C0, C, Parallels) :-
vn_block__record_label(Label, Livemap, Params, VnTables0, VnTables1,
Livevals0, Livevals1, FlushEntry0, FlushEntry1,
- LabelNo0, LabelNo1, Parallels0),
+ C0, C1, Parallels0),
vn_block__record_labels(Labels, Livemap, Params, VnTables1, VnTables,
Livevals1, Livevals, FlushEntry1, FlushEntry,
- LabelNo1, LabelNo, Parallels1),
+ C1, C, Parallels1),
list__append(Parallels0, Parallels1, Parallels).
:- pred vn_block__record_label(label, livemap, vn_params, vn_tables, vn_tables,
vnlvalset, vnlvalset, flushmapentry, flushmapentry,
- int, int, list(parallel)).
+ counter, counter, list(parallel)).
% :- mode vn_block__record_label(in, in, in, di, uo, di, uo, di, uo, in,
% out, out) is det.
:- mode vn_block__record_label(in, in, in, in, out, in, out, in, out, in,
@@ -721,23 +721,23 @@
vn_block__record_label(Label, Livemap, Params, VnTables0, VnTables,
Livevals0, Livevals, FlushEntry0, FlushEntry,
- LabelNo0, LabelNo, Parallels) :-
+ C0, C, Parallels) :-
( map__search(Livemap, Label, Liveset) ->
set__to_sorted_list(Liveset, Livelist),
vn_block__record_livevals(Livelist, Params, VnTables0, VnTables,
Livevals0, Livevals, FlushEntry0, FlushEntry,
ParEntries),
( ParEntries = [] ->
- LabelNo = LabelNo0,
+ C = C0,
Parallels = []
;
( Label = local(ProcLabel, _) ->
- LabelNo is LabelNo0 + 1,
- NewLabel = local(ProcLabel, LabelNo),
+ counter__allocate(N, C0, C),
+ NewLabel = local(ProcLabel, N),
Parallels = [parallel(Label, NewLabel,
ParEntries)]
;
- LabelNo = LabelNo0,
+ C = C0,
Parallels = []
)
)
Index: compiler/vn_debug.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/vn_debug.m,v
retrieving revision 1.30
diff -u -r1.30 vn_debug.m
--- compiler/vn_debug.m 1998/03/03 17:36:33 1.30
+++ compiler/vn_debug.m 1999/12/03 13:12:15
@@ -400,7 +400,7 @@
vn_debug__cost_header_msg(Header) -->
vn_debug__cost_msg_flag(Flag),
- opt_debug__msg(Flag, Header).
+ opt_debug__msg(Flag, -1, Header).
vn_debug__cost_msg(Used, OrigCost, VnCost) -->
vn_debug__cost_msg_flag(Flag),
Index: compiler/vn_type.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/vn_type.m,v
retrieving revision 1.44
diff -u -r1.44 vn_type.m
--- compiler/vn_type.m 2000/03/20 05:26:45 1.44
+++ compiler/vn_type.m 2000/08/07 16:12:49
@@ -14,7 +14,7 @@
:- interface.
:- import_module llds, builtin_ops, livemap, options.
-:- import_module getopt, map, set, list, std_util.
+:- import_module getopt, map, set, list, std_util, counter.
:- type vn == int.
@@ -99,7 +99,7 @@
:- type flushmapentry == map(vnlval, vn).
:- type parmap == map(int, list(parallel)).
-:- type vn_ctrl_tuple ---> tuple(int, ctrlmap, flushmap, int, parmap).
+:- type vn_ctrl_tuple ---> tuple(int, ctrlmap, flushmap, counter, parmap).
:- type vn_params.
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/concurrency
cvs diff: Diffing extras/curses
cvs diff: Diffing extras/curses/sample
cvs diff: Diffing extras/dynamic_linking
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/lazy_evaluation
cvs diff: Diffing extras/moose
cvs diff: Diffing extras/moose/samples
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/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 profiler
cvs diff: Diffing robdd
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 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/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/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
--------------------------------------------------------------------------
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