[m-rev.] for review: base variable for field access

Zoltan Somogyi zs at cs.mu.OZ.AU
Thu Nov 6 16:40:59 AEDT 2003


For review by Fergus.

Zoltan.

compiler/mlds_to_c.m:
	When filling in the fields of a newly allocated cell, use a fresh local
	variable as the base address for the field references in preference to
	lvals that are more expensive to access. This yields a speedup of about
	0.3%. (The LLDS backend has had a similar optimization for a long
	time.)

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/mlds_to_c.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mlds_to_c.m,v
retrieving revision 1.153
diff -u -b -r1.153 mlds_to_c.m
--- compiler/mlds_to_c.m	23 Oct 2003 02:07:56 -0000	1.153
+++ compiler/mlds_to_c.m	6 Nov 2003 00:45:34 -0000
@@ -2838,8 +2838,22 @@
 	mlds_maybe_output_heap_profile_instr(Context, Indent + 1, Args,
 			FuncName, MaybeCtorName),
 
+	( { Target = var(_, _) } ->
+		{ Base = lval(Target) }
+	;
+		% It doesn't matter what string we pick for BaseVarName,
+		% as long as its declaration doesn't hide any of the variables
+		% inside Args. This is not hard to ensure, since the printed
+		% forms of the variables inside Args all include "__".
+		{ BaseVarName = "base" },
+		{ Base = string(BaseVarName) },
 	mlds_indent(Context, Indent + 1),
-	mlds_output_lval(Target),
+		io__write_string("MR_Word "),
+		io__write_string(BaseVarName),
+		io__write_string(";\n")
+	),
+	mlds_indent(Context, Indent + 1),
+	write_lval_or_string(Base),
 	io__write_string(" = "),
 	( { MaybeTag = yes(Tag0) } ->
 		{ Tag = Tag0 },
@@ -2883,7 +2897,17 @@
 	io__write_string(")"),
 	io__write_string(EndMkword),
 	io__write_string(";\n"),
-	mlds_output_init_args(Args, ArgTypes, Context, 0, Target, Tag,
+	(
+		{ Base = lval(_) }
+	;
+		{ Base = string(BaseVarName1) },
+		mlds_indent(Context, Indent + 1),
+		mlds_output_lval(Target),
+		io__write_string(" = "),
+		io__write_string(BaseVarName1),
+		io__write_string(";\n")
+	),
+	mlds_output_init_args(Args, ArgTypes, Context, 0, Base, Tag,
 		Indent + 1),
 	mlds_indent(Context, Indent),
 	io__write_string("}\n").
@@ -2993,8 +3017,12 @@
 	unexpected(this_file,
 		"type_needs_forwarding_pointer_space: unknown_type"). 
 
+:- type lval_or_string
+	--->	lval(mlds__lval)
+	;	string(string).
+
 :- pred mlds_output_init_args(list(mlds__rval), list(mlds__type), mlds__context,
-		int, mlds__lval, mlds__tag, indent, io__state, io__state).
+	int, lval_or_string, mlds__tag, indent, io__state, io__state).
 :- mode mlds_output_init_args(in, in, in, in, in, in, in, di, uo) is det.
 
 mlds_output_init_args([_|_], [], _, _, _, _, _) -->
@@ -3003,7 +3031,7 @@
 	{ error("mlds_output_init_args: length mismatch") }.
 mlds_output_init_args([], [], _, _, _, _, _) --> [].
 mlds_output_init_args([Arg|Args], [ArgType|ArgTypes], Context,
-		ArgNum, Target, Tag, Indent) -->
+		ArgNum, Base, Tag, Indent) -->
 	%
 	% The MR_hl_field() macro expects its argument to
 	% have type MR_Box, so we need to box the arguments
@@ -3019,14 +3047,25 @@
 	io__write_string("MR_hl_field("),
 	mlds_output_tag(Tag),
 	io__write_string(", "),
-	mlds_output_lval(Target),
+	write_lval_or_string(Base),
 	io__write_string(", "),
 	io__write_int(ArgNum),
 	io__write_string(") = "),
 	mlds_output_boxed_rval(ArgType, Arg),
 	io__write_string(";\n"),
 	mlds_output_init_args(Args, ArgTypes, Context,
-		ArgNum + 1, Target, Tag, Indent).
+		ArgNum + 1, Base, Tag, Indent).
+
+:- pred write_lval_or_string(lval_or_string::in, io::di, io::uo) is det.
+
+write_lval_or_string(Base) -->
+	(
+		{ Base = lval(Target) },
+		mlds_output_lval(Target)
+	;
+		{ Base = string(BaseVarName) },
+		io__write_string(BaseVarName)
+	).
 
 %-----------------------------------------------------------------------------%
 %
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/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/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/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 java
cvs diff: Diffing java/library
cvs diff: Diffing java/runtime
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/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