[m-rev.] diff: improvement for semidet foreign_procs
Zoltan Somogyi
zs at cs.mu.OZ.AU
Fri Jun 10 16:37:09 AEST 2005
compiler/pragma_c_gen.m:
Generate somewhat faster code for semidet foreign_procs. Instead of
storing the success indication into r1, which may require moving some
data out of r1, stored it in a local C variable. Provide backward
compatibility with existing semidet foreign_procs by #defining
SUCCESS_INDICATOR to stand for this local variable in the foreign code.
compiler/llds_out.m:
Use the same name as pragma_c_gen when writing out this variable.
runtime/mercury_types.h:
Note that pragma_c_gen now temporarily redefines SUCCESS_INDICATOR.
Zoltan.
cvs diff: Diffing .
cvs diff: Diffing analysis
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/doc
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing boehm_gc/tests
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
Index: compiler/llds_out.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/llds_out.m,v
retrieving revision 1.248
diff -u -b -r1.248 llds_out.m
--- compiler/llds_out.m 22 Mar 2005 06:40:04 -0000 1.248
+++ compiler/llds_out.m 9 Jun 2005 10:09:34 -0000
@@ -181,6 +181,7 @@
:- import_module ll_backend__exprn_aux.
:- import_module ll_backend__layout.
:- import_module ll_backend__layout_out.
+:- import_module ll_backend__pragma_c_gen.
:- import_module ll_backend__rtti_out.
:- import_module parse_tree__mercury_to_mercury.
:- import_module parse_tree__modules.
@@ -2356,7 +2357,8 @@
output_pragma_c_component(pragma_c_raw_code(C_Code, _), !IO) :-
io__write_string(C_Code, !IO).
output_pragma_c_component(pragma_c_fail_to(Label), !IO) :-
- io__write_string("if (!MR_r1) MR_GOTO_LAB(", !IO),
+ io__write_string("if (!" ++ pragma_succ_ind_name ++
+ ") MR_GOTO_LAB(", !IO),
output_label(Label, no, !IO),
io__write_string(");\n", !IO).
output_pragma_c_component(pragma_c_noop, !IO).
Index: compiler/pragma_c_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/pragma_c_gen.m,v
retrieving revision 1.77
diff -u -b -r1.77 pragma_c_gen.m
--- compiler/pragma_c_gen.m 22 Mar 2005 06:40:18 -0000 1.77
+++ compiler/pragma_c_gen.m 10 Jun 2005 06:26:14 -0000
@@ -40,6 +40,11 @@
:- pred pragma_c_gen__struct_name(module_name::in, string::in, int::in,
proc_id::in, string::out) is det.
+ % The name of the variable model_semi foreign_procs in C assign to
+ % to indicate success or failure. Exported for llds_out.m.
+ %
+:- func pragma_succ_ind_name = string.
+
%---------------------------------------------------------------------------%
:- implementation.
@@ -426,16 +431,6 @@
code_info__save_variables(OutVarsSet, _, SaveVarsCode, !CI)
),
- goal_info_get_determinism(GoalInfo, Detism),
- ( CodeModel = model_semi ->
- % We want to clear r1 even for Detism = failure,
- % since code with such detism may still assign to
- % SUCCESS_INDICATOR (i.e. r1).
- code_info__reserve_r1(ReserveR1_Code, !CI)
- ;
- ReserveR1_Code = empty
- ),
-
%
% Generate the values of input variables.
% (NB we need to be careful that the rvals generated here
@@ -444,32 +439,6 @@
get_pragma_input_vars(InCArgs, InputDescs, InputVarsCode, !CI),
%
- % For semidet pragma c_code, we have to move anything that is
- % currently in r1 elsewhere, so that the C code can assign to
- % SUCCESS_INDICATOR without clobbering anything important.
- %
- % The call to code_info__reserve_r1 will have reserved r1,
- % ensuring that none of InCArgs is placed there, and
- % code_info__clear_r1 just releases r1. This reservation of r1
- % is not strictly necessary, as we generate assignments from
- % the input registers to C variables before we invoke code that could
- % assign to SUCCESS_INDICATOR. However, by not storing an argument in
- % r1, we don't require the C compiler to generate a copy instruction
- % from r1 to somewhere else in cases where the last use of the variable
- % we are trying to pass in r1 is after the first reference to
- % SUCCESS_INDICATOR. Instead we generate that argument directly
- % into some other location.
- %
- ( CodeModel = model_semi ->
- % We want to clear r1 even for Detism = failure,
- % since code with such detism may still assign to
- % SUCCESS_INDICATOR (i.e. r1).
- code_info__clear_r1(ClearR1_Code, !CI)
- ;
- ClearR1_Code = empty
- ),
-
- %
% We cannot kill the forward dead input arguments until we have
% finished generating the code producing the input variables.
% (The forward dead variables will be dead after the pragma_c_code,
@@ -542,15 +511,34 @@
C_Code_Comp = pragma_c_user_code(Context, C_Code),
%
- % <for semidet code, check of r1>
+ % <for semidet code, check of SUCCESS_INDICATOR>
%
- ( ( CodeModel = model_semi, Detism \= failure ) ->
+ goal_info_get_determinism(GoalInfo, Detism),
+ ( CodeModel = model_semi ->
+ ( Detism = failure ->
+ CheckSuccess_Comp = pragma_c_noop,
+ MaybeFailLabel = no
+ ;
code_info__get_next_label(FailLabel, !CI),
- CheckR1_Comp = pragma_c_fail_to(FailLabel),
+ CheckSuccess_Comp = pragma_c_fail_to(FailLabel),
MaybeFailLabel = yes(FailLabel)
+ ),
+ DefSuccessComp = pragma_c_raw_code(
+ "\tMR_bool " ++ pragma_succ_ind_name ++ ";\n" ++
+ "#undef SUCCESS_INDICATOR\n" ++
+ "#define SUCCESS_INDICATOR MercurySuccessIndicator\n",
+ live_lvals_info(set__init)),
+ UndefSuccessComp = pragma_c_raw_code(
+ "#undef SUCCESS_INDICATOR\n" ++
+ "#define SUCCESS_INDICATOR MR_r1\n",
+ live_lvals_info(set__init))
;
- CheckR1_Comp = pragma_c_noop,
- MaybeFailLabel = no
+ CheckSuccess_Comp = pragma_c_noop,
+ MaybeFailLabel = no,
+ DefSuccessComp = pragma_c_raw_code("",
+ live_lvals_info(set__init)),
+ UndefSuccessComp = pragma_c_raw_code("",
+ live_lvals_info(set__init))
),
%
@@ -598,10 +586,10 @@
%
% join all the components of the pragma_c together
%
- Components = [ProcLabelHashDefine, InputComp, SaveRegsComp,
- ObtainLock, C_Code_Comp, ReleaseLock,
- CheckR1_Comp, RestoreRegsComp,
- OutputComp, ProcLabelHashUndef],
+ Components = [ProcLabelHashDefine, DefSuccessComp, InputComp,
+ SaveRegsComp, ObtainLock, C_Code_Comp, ReleaseLock,
+ CheckSuccess_Comp, RestoreRegsComp,
+ OutputComp, UndefSuccessComp, ProcLabelHashUndef],
(
ExtraArgs = [],
MaybeDupl = yes
@@ -634,13 +622,10 @@
GotoSkipLabelCode = node([
goto(label(SkipLabel)) - "Skip past failure code"
]),
- SkipLabelCode = node([ label(SkipLabel) - "" ]),
- FailLabelCode = node([ label(TheFailLabel) - "" ]),
- FailureCode =
- tree(GotoSkipLabelCode,
- tree(FailLabelCode,
- tree(FailCode,
- SkipLabelCode)))
+ SkipLabelCode = node([label(SkipLabel) - ""]),
+ FailLabelCode = node([label(TheFailLabel) - ""]),
+ FailureCode = tree_list([GotoSkipLabelCode, FailLabelCode,
+ FailCode, SkipLabelCode])
; Detism = failure ->
code_info__generate_failure(FailureCode, !CI)
;
@@ -650,13 +635,8 @@
%
% join all code fragments together
%
- Code =
- tree(SaveVarsCode,
- tree(ReserveR1_Code,
- tree(InputVarsCode,
- tree(ClearR1_Code,
- tree(PragmaCCode,
- FailureCode))))).
+ Code = tree_list([SaveVarsCode, InputVarsCode, PragmaCCode,
+ FailureCode]).
:- pred make_proc_label_hash_define(module_info::in, pred_id::in, proc_id::in,
pragma_c_component::out, pragma_c_component::out) is det.
@@ -1407,6 +1387,8 @@
string__int_to_string(ProcNum, ProcNumStr),
string__append_list(["mercury_save__", MangledModuleName, "__",
MangledPredName, "__", ArityStr, "_", ProcNumStr], StructName).
+
+pragma_succ_ind_name = "MercurySuccessIndicator".
%---------------------------------------------------------------------------%
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
cvs diff: Diffing deep_profiler
cvs diff: Diffing deep_profiler/notes
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/curs
cvs diff: Diffing extras/curs/samples
cvs diff: Diffing extras/curses
cvs diff: Diffing extras/curses/sample
cvs diff: Diffing extras/dynamic_linking
cvs diff: Diffing extras/error
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/easyx
cvs diff: Diffing extras/graphics/easyx/samples
cvs diff: Diffing extras/graphics/mercury_glut
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/gears
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/lazy_evaluation
cvs diff: Diffing extras/lex
cvs diff: Diffing extras/lex/samples
cvs diff: Diffing extras/lex/tests
cvs diff: Diffing extras/logged_output
cvs diff: Diffing extras/moose
cvs diff: Diffing extras/moose/samples
cvs diff: Diffing extras/moose/tests
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/quickcheck
cvs diff: Diffing extras/quickcheck/tutes
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/stream
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing extras/xml
cvs diff: Diffing extras/xml/samples
cvs diff: Diffing extras/xml_stylesheets
cvs diff: Diffing java
cvs diff: Diffing java/runtime
cvs diff: Diffing library
cvs diff: Diffing mdbcomp
cvs diff: Diffing profiler
cvs diff: Diffing robdd
cvs diff: Diffing runtime
Index: runtime/mercury_types.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_types.h,v
retrieving revision 1.41
diff -u -b -r1.41 mercury_types.h
--- runtime/mercury_types.h 21 Apr 2005 05:47:19 -0000 1.41
+++ runtime/mercury_types.h 10 Jun 2005 06:33:12 -0000
@@ -149,8 +149,10 @@
#ifndef MR_HIGHLEVEL_CODE
/*
- ** semidet predicates indicate success or failure by leaving nonzero or zero
- ** respectively in register MR_r1
+ ** Semidet predicates indicate success or failure by leaving nonzero or zero
+ ** respectively in SUCCESS_INDICATOR, which the code generator (code_gen.m,
+ ** call_gen.m, pragma_c_gen.m etc) knows to be MR_r1. (Note that
+ ** pragma_c_gen.m temporarily redefines SUCCESS_INDICATOR.)
** (should this #define go in some other header file?)
*/
#define SUCCESS_INDICATOR MR_r1
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 slice
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/general/string_format
cvs diff: Diffing tests/general/structure_reuse
cvs diff: Diffing tests/grade_subdirs
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/mmc_make
cvs diff: Diffing tests/mmc_make/lib
cvs diff: Diffing tests/recompilation
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 util
cvs diff: Diffing vim
cvs diff: Diffing vim/after
cvs diff: Diffing vim/ftplugin
cvs diff: 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