[m-rev.] diff: optimize away assignments moving values of dummy types
Zoltan Somogyi
zs at cs.mu.OZ.AU
Mon Aug 30 15:10:20 AEST 2004
Optimize away instructions that move around dummy values; values of the
io__state and store__store types. (We still reserve stack slots for them;
getting rid of that is future work.)
compiler/var_locn.m:
When moving values around, do not emit assignments that move around
dummy values.
Delete an unused predicate.
compiler/code_info.m:
Pass to var_locn.m the extra information it now needs.
compiler/llds_out.m:
Do not emit assignments for dummy arguments of foreign_procs.
compiler/type_util.m:
Make the code for checking whether a type is a dummy type use the
existing predicate for finding the type constructor of a type.
Zoltan.
cvs server: Diffing .
cvs server: Diffing analysis
cvs server: Diffing bindist
cvs server: Diffing boehm_gc
cvs server: Diffing boehm_gc/Mac_files
cvs server: Diffing boehm_gc/cord
cvs server: Diffing boehm_gc/cord/private
cvs server: Diffing boehm_gc/doc
cvs server: Diffing boehm_gc/include
cvs server: Diffing boehm_gc/include/private
cvs server: Diffing boehm_gc/tests
cvs server: Diffing browser
cvs server: Diffing bytecode
cvs server: Diffing compiler
Index: compiler/code_info.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/code_info.m,v
retrieving revision 1.291
diff -u -b -r1.291 code_info.m
--- compiler/code_info.m 20 Jul 2004 04:40:57 -0000 1.291
+++ compiler/code_info.m 30 Aug 2004 05:08:10 -0000
@@ -364,6 +364,7 @@
proc_info_interface_code_model(ProcInfo, CodeModel),
build_input_arg_list(ProcInfo, ArgList),
proc_info_varset(ProcInfo, VarSet),
+ proc_info_vartypes(ProcInfo, VarTypes),
proc_info_stack_slots(ProcInfo, StackSlots),
globals__get_options(Globals, Options),
globals__get_trace_level(Globals, TraceLevel),
@@ -375,8 +376,8 @@
MaybeFailVars = no,
EffLiveness = Liveness
),
- var_locn__init_state(ArgList, EffLiveness, VarSet, StackSlots,
- FollowVars, Options, VarLocnInfo),
+ var_locn__init_state(ArgList, EffLiveness, VarSet, VarTypes,
+ StackSlots, FollowVars, Options, VarLocnInfo),
stack__init(ResumePoints),
globals__lookup_bool_option(Globals, allow_hijacks, AllowHijack),
(
Index: compiler/llds_out.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/llds_out.m,v
retrieving revision 1.237
diff -u -b -r1.237 llds_out.m
--- compiler/llds_out.m 16 Aug 2004 03:51:02 -0000 1.237
+++ compiler/llds_out.m 30 Aug 2004 05:08:10 -0000
@@ -168,6 +168,7 @@
:- import_module backend_libs__name_mangle.
:- import_module backend_libs__proc_label.
:- import_module backend_libs__rtti.
+:- import_module check_hlds__type_util.
:- import_module hlds__hlds_pred.
:- import_module hlds__passes_aux.
:- import_module libs__options.
@@ -2223,6 +2224,19 @@
output_pragma_inputs([], !IO).
output_pragma_inputs([Input | Inputs], !IO) :-
+ Input = pragma_c_input(_VarName, Type, _Rval, _MaybeForeignTypeInfo),
+ ( is_dummy_argument_type(Type) ->
+ true
+ ;
+ output_pragma_input(Input, !IO)
+ ),
+ output_pragma_inputs(Inputs, !IO).
+
+ % Output the input variable assignments at the top of the
+ % pragma foreign_code code for C.
+:- pred output_pragma_input(pragma_c_input::in, io::di, io::uo) is det.
+
+output_pragma_input(Input, !IO) :-
Input = pragma_c_input(VarName, Type, Rval, MaybeForeignTypeInfo),
io__write_string("\t", !IO),
(
@@ -2267,8 +2281,7 @@
output_rval_as_type(Rval, word, !IO)
)
),
- io__write_string(";\n", !IO),
- output_pragma_inputs(Inputs, !IO).
+ io__write_string(";\n", !IO).
% Output declarations for any lvals used for the outputs
:- pred output_pragma_output_lval_decls(list(pragma_c_output)::in,
@@ -2286,8 +2299,21 @@
is det.
output_pragma_outputs([], !IO).
-output_pragma_outputs([O | Outputs], !IO) :-
- O = pragma_c_output(Lval, Type, VarName, MaybeForeignType),
+output_pragma_outputs([Output | Outputs], !IO) :-
+ Output = pragma_c_output(_Lval, Type, _VarName, _MaybeForeignType),
+ ( is_dummy_argument_type(Type) ->
+ true
+ ;
+ output_pragma_output(Output, !IO)
+ ),
+ output_pragma_outputs(Outputs, !IO).
+
+ % Output the output variable assignments at the bottom of the
+ % pragma foreign code for C
+:- pred output_pragma_output(pragma_c_output::in, io::di, io::uo) is det.
+
+output_pragma_output(Output, !IO) :-
+ Output = pragma_c_output(Lval, Type, VarName, MaybeForeignType),
io__write_string("\t", !IO),
(
MaybeForeignType = yes(ForeignTypeInfo),
@@ -2326,8 +2352,7 @@
io__write_string(VarName, !IO)
)
),
- io__write_string(";\n", !IO),
- output_pragma_outputs(Outputs, !IO).
+ io__write_string(";\n", !IO).
:- pred output_reset_trail_reason(reset_trail_reason::in, io::di, io::uo)
is det.
Index: compiler/ml_call_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_call_gen.m,v
retrieving revision 1.47
diff -u -b -r1.47 ml_call_gen.m
--- compiler/ml_call_gen.m 2 Aug 2004 08:30:06 -0000 1.47
+++ compiler/ml_call_gen.m 30 Aug 2004 05:08:11 -0000
@@ -1006,14 +1006,12 @@
% as io__state
Lval = var(_VarName, VarType),
VarType = mercury_type(ProgDataType, _, _),
- type_util__is_dummy_argument_type(
- ProgDataType)
+ type_util__is_dummy_argument_type(ProgDataType)
->
Statements = []
;
Rval = ml_gen_simple_expr(SimpleExpr),
- Statement = ml_gen_assign(Lval, Rval,
- Context),
+ Statement = ml_gen_assign(Lval, Rval, Context),
Statements = [Statement]
)
;
Index: compiler/ml_code_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_code_util.m,v
retrieving revision 1.84
diff -u -b -r1.84 ml_code_util.m
--- compiler/ml_code_util.m 2 Aug 2004 08:30:06 -0000 1.84
+++ compiler/ml_code_util.m 30 Aug 2004 05:08:11 -0000
@@ -1154,7 +1154,8 @@
( RetTypePtr = mlds__ptr_type(RetType) ->
RetTypes = [RetType]
;
- error("output mode function result doesn't have pointer type")
+ error("output mode function result " ++
+ "doesn't have pointer type")
)
;
FuncArgs = FuncArgs0,
Index: compiler/type_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/type_util.m,v
retrieving revision 1.139
diff -u -b -r1.139 type_util.m
--- compiler/type_util.m 14 Jun 2004 04:16:40 -0000 1.139
+++ compiler/type_util.m 30 Aug 2004 05:08:11 -0000
@@ -842,15 +842,14 @@
% include arguments with these types.
type_util__is_dummy_argument_type(Type) :-
- Type = term__functor(term__atom(FunctorName), [
- term__functor(term__atom(ModuleName), [], _),
- term__functor(term__atom(TypeName), TypeArgs, _)
- ], _),
- ( FunctorName = "."
- ; FunctorName = ":"
- ),
- list__length(TypeArgs, TypeArity),
- type_util__is_dummy_argument_type_2(ModuleName, TypeName, TypeArity).
+ ( type_to_ctor_and_args(Type, TypeCtor, _) ->
+ TypeCtor = CtorSymName - TypeArity,
+ CtorSymName = qualified(unqualified(ModuleName), TypeName),
+ type_util__is_dummy_argument_type_2(ModuleName, TypeName,
+ TypeArity)
+ ;
+ fail
+ ).
:- pred type_util__is_dummy_argument_type_2(string::in, string::in, arity::in)
is semidet.
Index: compiler/var_locn.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/var_locn.m,v
retrieving revision 1.19
diff -u -b -r1.19 var_locn.m
--- compiler/var_locn.m 10 Apr 2004 10:33:02 -0000 1.19
+++ compiler/var_locn.m 30 Aug 2004 05:08:11 -0000
@@ -22,6 +22,7 @@
:- import_module parse_tree__prog_data.
:- import_module hlds__hlds_goal.
:- import_module hlds__hlds_llds.
+:- import_module hlds__hlds_pred.
:- import_module ll_backend__global_data.
:- import_module ll_backend__llds.
:- import_module libs__options.
@@ -30,16 +31,17 @@
:- type var_locn_info.
-% init_state(Arguments, Liveness, Varset, StackSlots, FollowVars, Opts,
-% VarLocnInfo)
+% init_state(Arguments, Liveness, VarSet, VarTypes, StackSlots,
+% FollowVars, Opts, VarLocnInfo)
% Produces an initial state of the VarLocnInfo given
% an association list of variables and lvalues. The initial
% state places the given variables at their corresponding
% locations, with the exception of variables which are not in
% Liveness (this corresponds to input arguments that are not
-% used in the body). The Varset parameter contains a mapping from
+% used in the body). The VarSet parameter contains a mapping from
% variables to names, which is used when code is generated
-% to provide meaningful comments. StackSlots maps each variable
+% to provide meaningful comments. VarTypes gives the types of
+% of all the procedure's variables. StackSlots maps each variable
% to its stack slot, if it has one. FollowVars is the initial
% follow_vars set; such sets give guidance as to what lvals
% (if any) each variable will be needed in next. Opts gives
@@ -47,7 +49,7 @@
% are considered constants.
:- pred init_state(assoc_list(prog_var, lval)::in, set(prog_var)::in,
- prog_varset::in, stack_slots::in, abs_follow_vars::in,
+ prog_varset::in, vartypes::in, stack_slots::in, abs_follow_vars::in,
option_table::in, var_locn_info::out) is det.
% reinit_state(VarLocs, !VarLocnInfo)
@@ -324,6 +326,7 @@
:- implementation.
+:- import_module check_hlds__type_util.
:- import_module libs__options.
:- import_module libs__tree.
:- import_module ll_backend__code_util.
@@ -399,6 +402,8 @@
var_locn_info(
varset :: prog_varset, % The varset from the
% proc_info.
+ vartypes :: vartypes, % The vartypes from the
+ % proc_info.
stack_slots :: stack_slots, % Maps each var to its stack
% slot, if it has one.
exprn_opts :: exprn_opts, % The values of the options
@@ -437,8 +442,8 @@
%----------------------------------------------------------------------------%
-init_state(VarLocs, Liveness, Varset, StackSlots, FollowVars, Options,
- VarLocnInfo) :-
+init_state(VarLocs, Liveness, VarSet, VarTypes, StackSlots, FollowVars,
+ Options, VarLocnInfo) :-
map__init(VarStateMap0),
map__init(LocVarMap0),
init_state_2(VarLocs, yes(Liveness), VarStateMap0, VarStateMap,
@@ -446,7 +451,7 @@
exprn_aux__init_exprn_opts(Options, ExprnOpts),
FollowVars = abs_follow_vars(FollowVarMap, NextNonReserved),
set__init(AcquiredRegs),
- VarLocnInfo = var_locn_info(Varset, StackSlots, ExprnOpts,
+ VarLocnInfo = var_locn_info(VarSet, VarTypes, StackSlots, ExprnOpts,
FollowVarMap, NextNonReserved, VarStateMap, LocVarMap,
AcquiredRegs, 0, []).
@@ -456,9 +461,9 @@
init_state_2(VarLocs, no, VarStateMap0, VarStateMap,
LocVarMap0, LocVarMap),
set__init(AcquiredRegs),
- !.VarLocnInfo = var_locn_info(Varset, StackSlots, ExprnOpts,
+ !.VarLocnInfo = var_locn_info(VarSet, VarTypes, StackSlots, ExprnOpts,
FollowVarMap, NextNonReserved, _, _, _, _, _),
- !:VarLocnInfo = var_locn_info(Varset, StackSlots, ExprnOpts,
+ !:VarLocnInfo = var_locn_info(VarSet, VarTypes, StackSlots, ExprnOpts,
FollowVarMap, NextNonReserved, VarStateMap, LocVarMap,
AcquiredRegs, 0, []).
@@ -854,21 +859,28 @@
materialize_var(Var, no, no, [],
Rval, EvalCode, !VLI)
),
- add_additional_lval_for_var(Var, Target,
- !VLI),
+ get_vartypes(!.VLI, VarTypes),
+ map__lookup(VarTypes, Var, Type),
+ ( is_dummy_argument_type(Type) ->
+ AssignCode = empty
+ ;
+ add_additional_lval_for_var(Var, Target, !VLI),
get_var_name(!.VLI, Var, VarName),
Comment = string__append("assigning from ",
- VarName)
+ VarName),
+ AssignCode = node([
+ assign(Target, Rval) - Comment
+ ])
+ )
; Rval0 = const(_) ->
- Rval = Rval0,
EvalCode = empty,
- Comment = "assigning field from const"
+ Comment = "assigning field from const",
+ AssignCode = node([
+ assign(Target, Rval0) - Comment
+ ])
;
error("assign_cell_args: unknown rval")
),
- AssignCode = node([
- assign(Target, Rval) - Comment
- ]),
ThisCode = tree(EvalCode, AssignCode)
;
ThisCode = empty
@@ -930,8 +942,7 @@
),
State = state(Lvals, MaybeConstRval, MaybeExprRval,
Using, DeadOrAlive),
- map__det_update(VarStateMap0, ContainedVar, State,
- VarStateMap),
+ map__det_update(VarStateMap0, ContainedVar, State, VarStateMap),
set_var_state_map(VarStateMap, !VLI),
(
set__empty(Using),
@@ -961,8 +972,7 @@
set_magic_var_location(Var, Lval, !VLI) :-
get_loc_var_map(!.VLI, LocVarMap0),
- make_var_depend_on_lval_roots(Var, Lval,
- LocVarMap0, LocVarMap),
+ make_var_depend_on_lval_roots(Var, Lval, LocVarMap0, LocVarMap),
set_loc_var_map(LocVarMap, !VLI),
get_var_state_map(!.VLI, VarStateMap0),
@@ -1138,10 +1148,16 @@
string__append_list(["Placing ", VarName,
" (depth ", LengthStr, ")"], Msg)
),
+ get_vartypes(!.VLI, VarTypes),
+ map__lookup(VarTypes, Var, Type),
+ ( is_dummy_argument_type(Type) ->
+ AssignCode = empty
+ ;
AssignCode = node([
assign(Target, Rval)
- Msg
])
+ )
),
Code = tree(FreeCode, tree(EvalCode, AssignCode))
).
@@ -2197,8 +2213,8 @@
:- pred get_var_name(var_locn_info::in, prog_var::in, string::out) is det.
get_var_name(VLI, Var, Name) :-
- get_varset(VLI, Varset),
- varset__lookup_name(Varset, Var, Name).
+ get_varset(VLI, VarSet),
+ varset__lookup_name(VarSet, Var, Name).
%----------------------------------------------------------------------------%
@@ -2214,6 +2230,7 @@
%----------------------------------------------------------------------------%
:- pred get_varset(var_locn_info::in, prog_varset::out) is det.
+:- pred get_vartypes(var_locn_info::in, vartypes::out) is det.
:- pred get_exprn_opts(var_locn_info::in, exprn_opts::out) is det.
:- pred get_var_state_map(var_locn_info::in, var_state_map::out) is det.
:- pred get_loc_var_map(var_locn_info::in, loc_var_map::out) is det.
@@ -2222,8 +2239,6 @@
:- pred get_exceptions(var_locn_info::in, assoc_list(prog_var, lval)::out)
is det.
-:- pred set_varset(prog_varset::in,
- var_locn_info::in, var_locn_info::out) is det.
:- pred set_follow_var_map(abs_follow_vars_map::in,
var_locn_info::in, var_locn_info::out) is det.
:- pred set_next_non_reserved(int::in,
@@ -2240,6 +2255,7 @@
var_locn_info::in, var_locn_info::out) is det.
get_varset(VI, VI ^ varset).
+get_vartypes(VI, VI ^ vartypes).
get_stack_slots(VI, VI ^ stack_slots).
get_exprn_opts(VI, VI ^ exprn_opts).
get_follow_var_map(VI, VI ^ follow_vars_map).
@@ -2250,7 +2266,6 @@
get_locked(VI, VI ^ locked).
get_exceptions(VI, VI ^ exceptions).
-set_varset(VS, VI, VI ^ varset := VS).
set_follow_var_map(FVM, VI, VI ^ follow_vars_map := FVM).
set_next_non_reserved(NNR, VI, VI ^ next_non_res := NNR).
set_var_state_map(VSM, VI, VI ^ var_state_map := VSM).
cvs server: Diffing compiler/notes
cvs server: Diffing debian
cvs server: Diffing deep_profiler
cvs server: Diffing deep_profiler/notes
cvs server: Diffing doc
cvs server: Diffing extras
cvs server: Diffing extras/aditi
cvs server: Diffing extras/cgi
cvs server: Diffing extras/complex_numbers
cvs server: Diffing extras/complex_numbers/samples
cvs server: Diffing extras/complex_numbers/tests
cvs server: Diffing extras/concurrency
cvs server: Diffing extras/curs
cvs server: Diffing extras/curs/samples
cvs server: Diffing extras/curses
cvs server: Diffing extras/curses/sample
cvs server: Diffing extras/dynamic_linking
cvs server: Diffing extras/error
cvs server: Diffing extras/graphics
cvs server: Diffing extras/graphics/mercury_glut
cvs server: Diffing extras/graphics/mercury_opengl
cvs server: Diffing extras/graphics/mercury_tcltk
cvs server: Diffing extras/graphics/samples
cvs server: Diffing extras/graphics/samples/calc
cvs server: Diffing extras/graphics/samples/gears
cvs server: Diffing extras/graphics/samples/maze
cvs server: Diffing extras/graphics/samples/pent
cvs server: Diffing extras/lazy_evaluation
cvs server: Diffing extras/lex
cvs server: Diffing extras/lex/samples
cvs server: Diffing extras/lex/tests
cvs server: Diffing extras/logged_output
cvs server: Diffing extras/moose
cvs server: Diffing extras/moose/samples
cvs server: Diffing extras/moose/tests
cvs server: Diffing extras/morphine
cvs server: Diffing extras/morphine/non-regression-tests
cvs server: Diffing extras/morphine/scripts
cvs server: Diffing extras/morphine/source
cvs server: Diffing extras/odbc
cvs server: Diffing extras/posix
cvs server: Diffing extras/quickcheck
cvs server: Diffing extras/quickcheck/tutes
cvs server: Diffing extras/references
cvs server: Diffing extras/references/samples
cvs server: Diffing extras/references/tests
cvs server: Diffing extras/stream
cvs server: Diffing extras/trailed_update
cvs server: [15:08:17] waiting for zs's lock in /home/mercury1/repository/mercury/extras/trailed_update
cvs server: [15:08:47] obtained lock in /home/mercury1/repository/mercury/extras/trailed_update
cvs server: Diffing extras/trailed_update/samples
cvs server: Diffing extras/trailed_update/tests
cvs server: Diffing extras/xml
cvs server: Diffing extras/xml/samples
cvs server: Diffing java
cvs server: Diffing java/runtime
cvs server: Diffing library
cvs server: Diffing profiler
cvs server: Diffing robdd
cvs server: Diffing runtime
cvs server: Diffing runtime/GETOPT
cvs server: Diffing runtime/machdeps
cvs server: Diffing samples
cvs server: Diffing samples/c_interface
cvs server: Diffing samples/c_interface/c_calls_mercury
cvs server: Diffing samples/c_interface/cplusplus_calls_mercury
cvs server: Diffing samples/c_interface/mercury_calls_c
cvs server: Diffing samples/c_interface/mercury_calls_cplusplus
cvs server: Diffing samples/c_interface/mercury_calls_fortran
cvs server: Diffing samples/c_interface/simpler_c_calls_mercury
cvs server: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs server: Diffing samples/diff
cvs server: Diffing samples/muz
cvs server: Diffing samples/rot13
cvs server: Diffing samples/solutions
cvs server: Diffing samples/tests
cvs server: Diffing samples/tests/c_interface
cvs server: Diffing samples/tests/c_interface/c_calls_mercury
cvs server: Diffing samples/tests/c_interface/cplusplus_calls_mercury
cvs server: Diffing samples/tests/c_interface/mercury_calls_c
cvs server: Diffing samples/tests/c_interface/mercury_calls_cplusplus
cvs server: Diffing samples/tests/c_interface/mercury_calls_fortran
cvs server: Diffing samples/tests/c_interface/simpler_c_calls_mercury
cvs server: Diffing samples/tests/c_interface/simpler_cplusplus_calls_mercury
cvs server: Diffing samples/tests/diff
cvs server: Diffing samples/tests/muz
cvs server: Diffing samples/tests/rot13
cvs server: Diffing samples/tests/solutions
cvs server: Diffing samples/tests/toplevel
cvs server: Diffing scripts
cvs server: Diffing tests
cvs server: Diffing tests/benchmarks
cvs server: Diffing tests/debugger
cvs server: Diffing tests/debugger/declarative
cvs server: Diffing tests/dppd
cvs server: Diffing tests/general
cvs server: Diffing tests/general/accumulator
cvs server: Diffing tests/general/string_format
cvs server: Diffing tests/general/structure_reuse
cvs server: Diffing tests/grade_subdirs
cvs server: Diffing tests/hard_coded
cvs server: Diffing tests/hard_coded/exceptions
cvs server: Diffing tests/hard_coded/purity
cvs server: Diffing tests/hard_coded/sub-modules
cvs server: Diffing tests/hard_coded/typeclasses
cvs server: Diffing tests/invalid
cvs server: Diffing tests/invalid/purity
cvs server: Diffing tests/misc_tests
cvs server: Diffing tests/mmc_make
cvs server: Diffing tests/mmc_make/lib
cvs server: Diffing tests/recompilation
cvs server: Diffing tests/tabling
cvs server: Diffing tests/term
cvs server: Diffing tests/valid
cvs server: Diffing tests/warnings
cvs server: Diffing tools
cvs server: Diffing trace
cvs server: Diffing util
cvs server: Diffing vim
cvs server: Diffing vim/after
cvs server: Diffing vim/ftplugin
cvs server: Diffing vim/syntax
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list