Files
mercury/compiler/code_util.m
Zoltan Somogyi 7bf0cd03af Reduce the overhead of all forms of tabling by eliminating in many cases
Estimated hours taken: 32
Branches: main

Reduce the overhead of all forms of tabling by eliminating in many cases
the overhead of transferring data across the C/Mercury boundary. These
involve lots of control transfers as well as assignments to and from
Mercury abstract machine registers, which are not real machine registers
on x86 machines. Benchmarking in Uppsala revealed this overhead to be
a real problem.

The way we do that is by changing the tabling transformation so that instead
of generating sequences of calls to predicates from library/table_builtin.m,
we generate sequences of calls to C macros from runtime/mercury_tabling_pred.h,
and emit the resulting code string as the body of a foreign_proc goal.
(The old transformation is still available via a new option,
--no-tabling-via-extra-args.)

Since the number of inputs and outputs of the resulting C code sequences
are not always fixed (they can depend on the number of input or output
arguments of predicate being transformed), implementing this required
adding to foreign_procs a new field that allows the specification of extra
arguments to be passed to and from the given foreign code fragment. For now,
this mechanism is implemented only by the C backends, since it is needed
only by the C backends. (We don't support yet tabling on other backends.)

To simplify the new implementation of the field on foreign_procs, consolidate
three existing fields into one. Each of these fields was a list with one
element per argument, so turning them into a single list with a combined record
per argument should also improve reliability, since it reduces the likelyhood
of updates leaving the data structure inconsistent.

The goal paths of components of a tabled predicate depend on whether
-no-tabling-via-extra-args was specified. To enable the expected outputs
of the debugger test cases testing tabling, we add a new mdb command,
goal_paths, that controls whether goal paths are printed by the debugger
at events, and turn off the printing of events in the relevant test cases.

Also, prepare for a future change to optimize the trie structure for
user-defined types by handling type_infos (and once we support them,
typeclass_infos) specially.

compiler/table_gen.m:
	Change the tabling transformation along the lines described above.

	To allow us to factor out as much of the new code as possible,
	we change the meaning of the call_table_tip variable for minimal
	model subgoals: instead of the trie node at the end of the answer
	table, it is not now the subgoal reachable from it. This change
	has no effect as yet, because we use call_table_tip variables
	only to perform resets across retries in the debugger, and we
	don't do retries across calls to minimal model tabled predicates.

	Put predicates into logical groups.

library/table_builtin.m:
runtime/mercury_tabling_preds.h:
	When the new transformations in table_gen.m generate foreign_procs
	with variable numbers of arguments, the interfaces of those
	foreign_procs often do not match the interfaces of the existing
	library predicates at their core: they frequently have one more
	or one fewer argument. To prevent any possible confusion, in such
	cases we add a new variant of the predicate. These predicates
	have the suffix _shortcut in their name. Their implementations
	are dummy macros that do nothing; they serve merely as placeholders
	before or after which the macros that actually do the work are
	inserted.

	Move the definitions of the lookup, save and restore predicates
	into mercury_tabling_preds.h. Make the naming scheme of their
	arguments more regular.

runtime/mercury_minimal_model.c:
runtime/mercury_tabling_preds.h:
	Move the definition of a predicate from mercury_minimal_model.c
	to mercury_tabling_preds.h, since the compiler now needs to be
	able to generate an inlined version of it.

compiler/hlds_goal.m:
	Replace the three existing fields describing the arguments of
	foreign_procs with one, and add a new field describing the extra
	arguments that may be inserted by table_gen.m.

	Add utility predicates for processing the arguments of foreign_procs.

	Change the order of some existing groups of declarations make it
	more logical.

compiler/hlds_pred.m:
runtime/mercury_stack_layout.h:
	Extend the data structures recording the structure of tabling tries
	to allow the representation of trie steps for type_infos and
	typeclass_infos.

runtime/mercury_tabling_macros.c:
	Fix a bug regarding the tabling of typeclass_infos, which is now
	required for a clean compile.

compiler/pragma_c_gen.m:
compiler/ml_code_gen.m:
	Modify the generation of code for foreign_procs to handle extra
	arguments, and to conform to the new data structures for foreign_proc
	arguments.

compiler/llds.m:
	The tabling transformations can now generate significantly sized
	foreign_procs bodies, which the LLDS code generator translates to
	pragma_c instructions. Duplicating these by jump optimization
	may lose more by worsening locality than it gains in avoiding jumps,
	so we add an extra field to pragma_c instructions that tells jumpopt
	not to duplicate code sequences containing such pragma_cs.

compiler/jumpopt.m:
	Respect the new flag on pragma_cs.

compiler/goal_util.m:
	Add a predicate to create foreign_procs with specified contents,
	modelled on the existing predicate to create calls.

	Change the order of the arguments of that existing predicate
	to make it more logical.

compiler/polymorphism.m:
	Conform to the new definition of foreign_procs. Try to simplify
	the mechanism for generating the type_info and typeclass_info
	arguments of foreign_proc goals, but it is not clear that this
	code is even ever executed.

compiler/aditi_builtin_ops.m:
compiler/assertion.m:
compiler/bytecode_gen.m:
compiler/clause_to_proc.m:
compiler/code_gen.m:
compiler/code_info.m:
compiler/code_util.m:
compiler/constraint.m:
compiler/deep_profiling.m:
compiler/deforest.m:
compiler/delay_construct.m:
compiler/dependency_graph.m:
compiler/det_analysis.m:
compiler/det_report.m:
compiler/dnf.m:
compiler/dupelim.m:
compiler/equiv_type_hlds.m:
compiler/exprn_aux.m:
compiler/follow_code.m:
compiler/follow_vars.m:
compiler/frameopt.m:
compiler/goal_form.m:
compiler/goal_path.m:
compiler/higher_order.m:
compiler/higher_order.m:
compiler/hlds_module.m:
compiler/hlds_out.m:
compiler/inlining.m:
compiler/ite_gen.m:
compiler/layout_out.m:
compiler/livemap.m:
compiler/liveness.m:
compiler/llds_out.m:
compiler/loop_inv.m:
compiler/magic.m:
compiler/make_hlds.m:
compiler/mark_static_terms.m:
compiler/middle_rec.m:
compiler/modes.m:
compiler/modules.m:
compiler/opt_debug.m:
compiler/pd_cost.m:
compiler/prog_rep.m:
compiler/purity.m:
compiler/quantification.m:
compiler/reassign.m:
compiler/rl_exprn.m:
compiler/saved_vars.m:
compiler/simplify.m:
compiler/size_prof.m:
compiler/store_alloc.m:
compiler/stratify.m:
compiler/switch_detection.m:
compiler/term_pass1.m:
compiler/term_traversal.m:
compiler/termination.m:
compiler/trace.m:
compiler/typecheck.m:
compiler/unify_proc.m:
compiler/unique_modes.m:
compiler/unneeed_code.m:
compiler/unused_args.m:
compiler/use_local_vars.m:
	Conform to the new definition of foreign_procs, pragma_cs and/or
	table trie steps, or to changed argument orders.

compiler/add_heap_ops.m:
compiler/add_trail_ops.m:
compiler/cse_detection.m:
compiler/dead_proc_elim.m:
compiler/equiv_type.m:
compiler/intermod.m:
compiler/lambda.m:
compiler/lco.m:
compiler/module_util.m:
compiler/opt_util.m:
compiler/stack_opt.m:
compiler/trans_opt.m:
	Conform to the new definition of foreign_procs.

	Bring these modules up to date with our current code style guidelines,
	using predmode declarations, state variable syntax and unification
	expressions as appropriate.

compiler/mercury_compile.m:
	Conform to the changed argument order of a predicate in trans_opt.m.

compiler/options.m:
	Add the --no-tabling-via-extra-args option, but leave the
	documentation commented out since the option is for developers only.

doc/user_guide.texi:
	Document --no-tabling-via-extra-args option, though leave the
	documentation commented out since the option is for developers only.

doc/user_guide.texi:
doc/mdb_categories:
	Document the new goal_paths mdb command.

trace/mercury_trace_internals.c:
	Implement the new goal_paths mdb command.

tests/debugger/completion.exp:
	Conform to the presence of the goal_paths mdb command.

tests/debugger/mdb_command_test.inp:
	Test the existence of documentation for the goal_paths mdb command.

tests/debugger/print_table.{inp,exp*}:
tests/debugger/retry.{inp,exp*}:
	Use the goal_paths command to avoid having the expected output
	depend on the presence or absence of --tabling-via-extra-args.

tests/tabling/table_foreign_output.{m,exp}:
	Add a new test case to test the save/restore of arguments of foreign
	types.

tests/tabling/Mmakefile:
	Enable the new test case.

tests/tabling/test_tabling:
	Make this script more robust.

	Add an option for testing only the standard model forms of tabling.
2004-06-07 09:07:23 +00:00

446 lines
16 KiB
Mathematica

%-----------------------------------------------------------------------------%
% Copyright (C) 1994-2004 The University of Melbourne.
% This file may only be copied under the terms of the GNU General
% Public License - see the file COPYING in the Mercury distribution.
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
%
% file: code_util.m.
%
% various utilities routines for code generation and recognition
% of builtins.
%
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
:- module ll_backend__code_util.
:- interface.
:- import_module backend_libs__proc_label.
:- import_module hlds__hlds_goal.
:- import_module hlds__hlds_llds.
:- import_module hlds__hlds_module.
:- import_module hlds__hlds_pred.
:- import_module ll_backend__llds.
:- import_module parse_tree__prog_data.
:- import_module list, assoc_list, std_util.
% Create a code address which holds the address of the specified
% procedure.
% The `immed' argument should be `no' if the the caller wants the
% returned address to be valid from everywhere in the program.
% If being valid from within the current procedure is enough,
% this argument should be `yes' wrapped around the value of the
% --procs-per-c-function option and the current procedure id.
% Using an address that is only valid from within the current
% procedure may make jumps more efficient.
:- type immed == maybe(pair(int, pred_proc_id)).
:- pred code_util__make_entry_label(module_info::in, pred_id::in, proc_id::in,
immed::in, code_addr::out) is det.
:- pred code_util__make_entry_label_from_rtti(rtti_proc_label::in, immed::in,
code_addr::out) is det.
% Create a label which holds the address of the specified procedure,
% which must be defined in the current module (procedures that are
% imported from other modules have representations only as code_addrs,
% not as labels, since their address is not known at C compilation
% time).
% The fourth argument has the same meaning as for
% code_util__make_entry_label.
:- pred code_util__make_local_entry_label(module_info::in,
pred_id::in, proc_id::in, immed::in, label::out) is det.
% Create a label internal to a Mercury procedure.
:- pred code_util__make_internal_label(module_info::in,
pred_id::in, proc_id::in, int::in, label::out) is det.
:- pred code_util__extract_proc_label_from_code_addr(code_addr::in,
proc_label::out) is det.
:- pred code_util__arg_loc_to_register(arg_loc::in, lval::out) is det.
:- pred code_util__max_mentioned_reg(list(lval)::in, int::out) is det.
:- pred code_util__max_mentioned_abs_reg(list(abs_locn)::in, int::out) is det.
:- pred code_util__goal_may_alloc_temp_frame(hlds_goal::in) is semidet.
% Negate a condition.
% This is used mostly just to make the generated code more readable.
:- pred code_util__neg_rval(rval::in, rval::out) is det.
:- pred code_util__negate_the_test(list(instruction)::in,
list(instruction)::out) is det.
% These predicates return the set of lvals referenced in an rval
% and an lval respectively. Lvals referenced indirectly through
% lvals of the form var(_) are not counted.
:- pred code_util__lvals_in_rval(rval::in, list(lval)::out) is det.
:- pred code_util__lvals_in_lval(lval::in, list(lval)::out) is det.
:- pred code_util__lvals_in_lvals(list(lval)::in, list(lval)::out) is det.
% Given a procedure that already has its arg_info field filled in,
% return a list giving its input variables and their initial locations.
:- pred build_input_arg_list(proc_info::in,
assoc_list(prog_var, lval)::out) is det.
%---------------------------------------------------------------------------%
:- implementation.
:- import_module backend_libs__builtin_ops.
:- import_module backend_libs__rtti.
:- import_module hlds__code_model.
:- import_module hlds__special_pred.
:- import_module libs__globals.
:- import_module libs__options.
:- import_module parse_tree__prog_util.
:- import_module bool, char, int, string, set, term, varset, require.
%---------------------------------------------------------------------------%
code_util__make_entry_label(ModuleInfo, PredId, ProcId, Immed, ProcAddr) :-
RttiProcLabel = rtti__make_rtti_proc_label(ModuleInfo, PredId, ProcId),
code_util__make_entry_label_from_rtti(RttiProcLabel, Immed, ProcAddr).
code_util__make_entry_label_from_rtti(RttiProcLabel, Immed, ProcAddr) :-
( RttiProcLabel ^ proc_is_imported = yes ->
ProcLabel = make_proc_label_from_rtti(RttiProcLabel),
ProcAddr = imported(ProcLabel)
;
code_util__make_local_entry_label_from_rtti(RttiProcLabel,
Immed, Label),
ProcAddr = label(Label)
).
code_util__make_local_entry_label(ModuleInfo, PredId, ProcId, Immed, Label) :-
RttiProcLabel = rtti__make_rtti_proc_label(ModuleInfo, PredId, ProcId),
code_util__make_local_entry_label_from_rtti(RttiProcLabel,
Immed, Label).
:- pred code_util__make_local_entry_label_from_rtti(rtti_proc_label::in,
immed::in, label::out) is det.
code_util__make_local_entry_label_from_rtti(RttiProcLabel, Immed, Label) :-
ProcLabel = make_proc_label_from_rtti(RttiProcLabel),
(
Immed = no,
% If we want to define the label or use it to put it
% into a data structure, a label that is usable only
% within the current C module won't do.
( RttiProcLabel ^ proc_is_exported = yes ->
EntryType = exported
;
EntryType = local
),
Label = entry(EntryType, ProcLabel)
;
Immed = yes(ProcsPerFunc - proc(CurPredId, CurProcId)),
choose_local_label_type(ProcsPerFunc, CurPredId, CurProcId,
RttiProcLabel^pred_id, RttiProcLabel^proc_id,
ProcLabel, Label)
).
:- pred choose_local_label_type(int::in, pred_id::in, proc_id::in,
pred_id::in, proc_id::in, proc_label::in, label::out) is det.
choose_local_label_type(ProcsPerFunc, CurPredId, CurProcId,
PredId, ProcId, ProcLabel, Label) :-
(
% If we want to branch to the label now,
% we prefer a form that are usable only within
% the current C module, since it is likely
% to be faster.
(
ProcsPerFunc = 0
;
PredId = CurPredId,
ProcId = CurProcId
)
->
EntryType = c_local
;
EntryType = local
),
Label = entry(EntryType, ProcLabel).
%-----------------------------------------------------------------------------%
code_util__make_internal_label(ModuleInfo, PredId, ProcId, LabelNum, Label) :-
ProcLabel = make_proc_label(ModuleInfo, PredId, ProcId),
Label = internal(LabelNum, ProcLabel).
code_util__extract_proc_label_from_code_addr(CodeAddr, ProcLabel) :-
( CodeAddr = label(Label) ->
ProcLabel = get_proc_label(Label)
; CodeAddr = imported(ProcLabelPrime) ->
ProcLabel = ProcLabelPrime
;
error("code_util__extract_label_from_code_addr failed")
).
%-----------------------------------------------------------------------------%
code_util__arg_loc_to_register(ArgLoc, reg(r, ArgLoc)).
%-----------------------------------------------------------------------------%
code_util__max_mentioned_reg(Lvals, MaxRegNum) :-
code_util__max_mentioned_reg_2(Lvals, 0, MaxRegNum).
:- pred code_util__max_mentioned_reg_2(list(lval)::in, int::in, int::out)
is det.
code_util__max_mentioned_reg_2([], !MaxRegNum).
code_util__max_mentioned_reg_2([Lval | Lvals], !MaxRegNum) :-
( Lval = reg(r, N) ->
int__max(N, !MaxRegNum)
;
true
),
code_util__max_mentioned_reg_2(Lvals, !MaxRegNum).
code_util__max_mentioned_abs_reg(Lvals, MaxRegNum) :-
code_util__max_mentioned_abs_reg_2(Lvals, 0, MaxRegNum).
:- pred code_util__max_mentioned_abs_reg_2(list(abs_locn)::in,
int::in, int::out) is det.
code_util__max_mentioned_abs_reg_2([], !MaxRegNum).
code_util__max_mentioned_abs_reg_2([Lval | Lvals], !MaxRegNum) :-
( Lval = abs_reg(N) ->
int__max(N, !MaxRegNum)
;
true
),
code_util__max_mentioned_abs_reg_2(Lvals, !MaxRegNum).
%-----------------------------------------------------------------------------%
code_util__goal_may_alloc_temp_frame(Goal) :-
code_util__goal_may_alloc_temp_frame(Goal, yes).
:- pred code_util__goal_may_alloc_temp_frame(hlds_goal::in, bool::out) is det.
code_util__goal_may_alloc_temp_frame(Goal - _GoalInfo, May) :-
code_util__goal_may_alloc_temp_frame_2(Goal, May).
:- pred code_util__goal_may_alloc_temp_frame_2(hlds_goal_expr::in, bool::out)
is det.
code_util__goal_may_alloc_temp_frame_2(generic_call(_, _, _, _), no).
code_util__goal_may_alloc_temp_frame_2(call(_, _, _, _, _, _), no).
code_util__goal_may_alloc_temp_frame_2(unify(_, _, _, _, _), no).
% We cannot safely say that a foreign code fragment does not allocate
% temporary nondet frames without knowing all the #defined macros
% that expand to mktempframe and variants thereof. The performance
% impact of being too conservative is probably not too bad.
code_util__goal_may_alloc_temp_frame_2(foreign_proc(_, _, _, _, _, _), yes).
code_util__goal_may_alloc_temp_frame_2(some(_Vars, _, Goal), May) :-
Goal = _ - GoalInfo,
goal_info_get_code_model(GoalInfo, CodeModel),
( CodeModel = model_non ->
May = yes
;
code_util__goal_may_alloc_temp_frame(Goal, May)
).
code_util__goal_may_alloc_temp_frame_2(not(Goal), May) :-
code_util__goal_may_alloc_temp_frame(Goal, May).
code_util__goal_may_alloc_temp_frame_2(conj(Goals), May) :-
code_util__goal_list_may_alloc_temp_frame(Goals, May).
code_util__goal_may_alloc_temp_frame_2(par_conj(Goals), May) :-
code_util__goal_list_may_alloc_temp_frame(Goals, May).
code_util__goal_may_alloc_temp_frame_2(disj(Goals), May) :-
code_util__goal_list_may_alloc_temp_frame(Goals, May).
code_util__goal_may_alloc_temp_frame_2(switch(_Var, _Det, Cases), May) :-
code_util__cases_may_alloc_temp_frame(Cases, May).
code_util__goal_may_alloc_temp_frame_2(if_then_else(_Vars, C, T, E), May) :-
( code_util__goal_may_alloc_temp_frame(C, yes) ->
May = yes
; code_util__goal_may_alloc_temp_frame(T, yes) ->
May = yes
;
code_util__goal_may_alloc_temp_frame(E, May)
).
code_util__goal_may_alloc_temp_frame_2(shorthand(ShorthandGoal), May) :-
code_util__goal_may_alloc_temp_frame_2_shorthand(ShorthandGoal,May).
:- pred code_util__goal_may_alloc_temp_frame_2_shorthand(
shorthand_goal_expr::in, bool::out) is det.
code_util__goal_may_alloc_temp_frame_2_shorthand(bi_implication(G1, G2),
May) :-
( code_util__goal_may_alloc_temp_frame(G1, yes) ->
May = yes
;
code_util__goal_may_alloc_temp_frame(G2, May)
).
:- pred code_util__goal_list_may_alloc_temp_frame(list(hlds_goal)::in,
bool::out) is det.
code_util__goal_list_may_alloc_temp_frame([], no).
code_util__goal_list_may_alloc_temp_frame([Goal | Goals], May) :-
( code_util__goal_may_alloc_temp_frame(Goal, yes) ->
May = yes
;
code_util__goal_list_may_alloc_temp_frame(Goals, May)
).
:- pred code_util__cases_may_alloc_temp_frame(list(case)::in, bool::out)
is det.
code_util__cases_may_alloc_temp_frame([], no).
code_util__cases_may_alloc_temp_frame([case(_, Goal) | Cases], May) :-
( code_util__goal_may_alloc_temp_frame(Goal, yes) ->
May = yes
;
code_util__cases_may_alloc_temp_frame(Cases, May)
).
%-----------------------------------------------------------------------------%
% Negate a condition.
% This is used mostly just to make the generated code more readable.
code_util__neg_rval(Rval, NegRval) :-
( code_util__neg_rval_2(Rval, NegRval0) ->
NegRval = NegRval0
;
NegRval = unop(not, Rval)
).
:- pred code_util__neg_rval_2(rval::in, rval::out) is semidet.
code_util__neg_rval_2(const(Const), const(NegConst)) :-
(
Const = true, NegConst = false
;
Const = false, NegConst = true
).
code_util__neg_rval_2(unop(not, Rval), Rval).
code_util__neg_rval_2(binop(Op, X, Y), binop(NegOp, X, Y)) :-
code_util__neg_op(Op, NegOp).
:- pred code_util__neg_op(binary_op::in, binary_op::out) is semidet.
code_util__neg_op(eq, ne).
code_util__neg_op(ne, eq).
code_util__neg_op(<, >=).
code_util__neg_op(<=, >).
code_util__neg_op(>, <=).
code_util__neg_op(>=, <).
code_util__neg_op(str_eq, str_ne).
code_util__neg_op(str_ne, str_eq).
code_util__neg_op(str_lt, str_ge).
code_util__neg_op(str_le, str_gt).
code_util__neg_op(str_gt, str_le).
code_util__neg_op(str_ge, str_lt).
code_util__neg_op(float_eq, float_ne).
code_util__neg_op(float_ne, float_eq).
code_util__neg_op(float_lt, float_ge).
code_util__neg_op(float_le, float_gt).
code_util__neg_op(float_gt, float_le).
code_util__neg_op(float_ge, float_lt).
code_util__negate_the_test([], _) :-
error("code_util__negate_the_test on empty list").
code_util__negate_the_test([Instr0 | Instrs0], Instrs) :-
( Instr0 = if_val(Test, Target) - Comment ->
code_util__neg_rval(Test, NewTest),
Instrs = [if_val(NewTest, Target) - Comment]
;
code_util__negate_the_test(Instrs0, Instrs1),
Instrs = [Instr0 | Instrs1]
).
%-----------------------------------------------------------------------------%
code_util__lvals_in_lvals([], []).
code_util__lvals_in_lvals([First | Rest], Lvals) :-
code_util__lvals_in_lval(First, FirstLvals),
code_util__lvals_in_lvals(Rest, RestLvals),
list__append(FirstLvals, RestLvals, Lvals).
code_util__lvals_in_rval(lval(Lval), [Lval | Lvals]) :-
code_util__lvals_in_lval(Lval, Lvals).
code_util__lvals_in_rval(var(_), []).
code_util__lvals_in_rval(mkword(_, Rval), Lvals) :-
code_util__lvals_in_rval(Rval, Lvals).
code_util__lvals_in_rval(const(_), []).
code_util__lvals_in_rval(unop(_, Rval), Lvals) :-
code_util__lvals_in_rval(Rval, Lvals).
code_util__lvals_in_rval(binop(_, Rval1, Rval2), Lvals) :-
code_util__lvals_in_rval(Rval1, Lvals1),
code_util__lvals_in_rval(Rval2, Lvals2),
list__append(Lvals1, Lvals2, Lvals).
code_util__lvals_in_rval(mem_addr(MemRef), Lvals) :-
code_util__lvals_in_mem_ref(MemRef, Lvals).
code_util__lvals_in_lval(reg(_, _), []).
code_util__lvals_in_lval(stackvar(_), []).
code_util__lvals_in_lval(framevar(_), []).
code_util__lvals_in_lval(succip, []).
code_util__lvals_in_lval(maxfr, []).
code_util__lvals_in_lval(curfr, []).
code_util__lvals_in_lval(succip(Rval), Lvals) :-
code_util__lvals_in_rval(Rval, Lvals).
code_util__lvals_in_lval(redofr(Rval), Lvals) :-
code_util__lvals_in_rval(Rval, Lvals).
code_util__lvals_in_lval(redoip(Rval), Lvals) :-
code_util__lvals_in_rval(Rval, Lvals).
code_util__lvals_in_lval(succfr(Rval), Lvals) :-
code_util__lvals_in_rval(Rval, Lvals).
code_util__lvals_in_lval(prevfr(Rval), Lvals) :-
code_util__lvals_in_rval(Rval, Lvals).
code_util__lvals_in_lval(hp, []).
code_util__lvals_in_lval(sp, []).
code_util__lvals_in_lval(field(_, Rval1, Rval2), Lvals) :-
code_util__lvals_in_rval(Rval1, Lvals1),
code_util__lvals_in_rval(Rval2, Lvals2),
list__append(Lvals1, Lvals2, Lvals).
code_util__lvals_in_lval(lvar(_), []).
code_util__lvals_in_lval(temp(_, _), []).
code_util__lvals_in_lval(mem_ref(Rval), Lvals) :-
code_util__lvals_in_rval(Rval, Lvals).
:- pred code_util__lvals_in_mem_ref(mem_ref::in, list(lval)::out) is det.
code_util__lvals_in_mem_ref(stackvar_ref(_), []).
code_util__lvals_in_mem_ref(framevar_ref(_), []).
code_util__lvals_in_mem_ref(heap_ref(Rval, _, _), Lvals) :-
code_util__lvals_in_rval(Rval, Lvals).
%-----------------------------------------------------------------------------%
build_input_arg_list(ProcInfo, VarLvals) :-
proc_info_headvars(ProcInfo, HeadVars),
proc_info_arg_info(ProcInfo, ArgInfos),
assoc_list__from_corresponding_lists(HeadVars, ArgInfos, VarArgInfos),
build_input_arg_list_2(VarArgInfos, VarLvals).
:- pred build_input_arg_list_2(assoc_list(prog_var, arg_info)::in,
assoc_list(prog_var, lval)::out) is det.
build_input_arg_list_2([], []).
build_input_arg_list_2([V - Arg | Rest0], VarArgs) :-
Arg = arg_info(Loc, Mode),
( Mode = top_in ->
code_util__arg_loc_to_register(Loc, Reg),
VarArgs = [V - Reg | VarArgs0]
;
VarArgs = VarArgs0
),
build_input_arg_list_2(Rest0, VarArgs0).
%-----------------------------------------------------------------------------%