[m-dev.] for review: new_object size in words

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Feb 8 02:08:24 AEDT 2001


For review by Julien.

Estimated hours taken: 1

Change the units for the size field in MLDS new_object
statements from bytes to words.

compiler/mlds.m:
	Update the documentation for the size field.

compiler/ml_unify_gen.m:
	Generate the sizes in words rather than bytes.
	Delete the ml_sizeof_word_lval function, since it's
	no longer used.

compiler/mlds_to_c.m:
	Multiple the size passed to MR_new_object() by
	`sizeof(MR_Word)' to convert from words to bytes.

compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
	Simplify the code by deleting hacks needed to
	convert the size from bytes to words.

runtime/mercury.h:
	Document that the definition of SIZEOF_WORD should
	not be needed any longer, except for bootstraping.

Workspace: /home/venus/fjh/ws-venus2/mercury
Index: compiler/ml_unify_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_unify_gen.m,v
retrieving revision 1.27
diff -u -d -r1.27 ml_unify_gen.m
--- compiler/ml_unify_gen.m	2001/01/23 06:01:05	1.27
+++ compiler/ml_unify_gen.m	2001/02/07 15:03:48
@@ -972,9 +972,6 @@
 		%
 		{ list__length(ArgRvals, NumArgs) },
 		{ SizeInWordsRval = const(int_const(NumArgs)) },
-		{ SizeOfWordRval = ml_sizeof_word_rval },
-		{ SizeInBytesRval = binop((*), SizeInWordsRval,
-			SizeOfWordRval) },
 		
 		%
 		% Generate a `new_object' statement to dynamically allocate
@@ -983,7 +980,7 @@
 		% with boxed versions of the specified arguments.
 		%
 		{ MakeNewObject = new_object(VarLval, MaybeTag, MLDS_Type,
-			yes(SizeInBytesRval), yes(CtorName), ArgRvals,
+			yes(SizeInWordsRval), yes(CtorName), ArgRvals,
 			MLDS_ArgTypes) },
 		{ MLDS_Stmt = atomic(MakeNewObject) },
 		{ MLDS_Statement = mlds__statement(MLDS_Stmt,
@@ -1207,18 +1204,6 @@
 
 ml_cons_name(ConsId, ConsName) -->
 	{ hlds_out__cons_id_to_string(ConsId, ConsName) }.
-
-	% Return an rval for the `SIZEOF_WORD' constant.
-	% This constant is supposed to be defined by the Mercury library.
-	% It holds `sizeof(Word)'.  (Using this constant allows us to avoid
-	% hard-coding the word size without having to add support for
-	% `sizeof' to MLDS.)
-	%
-:- func ml_sizeof_word_rval = mlds__rval.
-ml_sizeof_word_rval = SizeofWordRval :-
-	mercury_private_builtin_module(PrivateBuiltin),
-	MLDS_Module = mercury_module_name_to_mlds(PrivateBuiltin),
-	SizeofWordRval = lval(var(qual(MLDS_Module, "SIZEOF_WORD"))).
 
 :- pred ml_gen_cons_args(list(mlds__lval), list(prog_type),
 		list(uni_mode), module_info, list(mlds__rval)).
Index: compiler/mlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds.m,v
retrieving revision 1.45
diff -u -d -r1.45 mlds.m
--- compiler/mlds.m	2001/01/17 17:37:17	1.45
+++ compiler/mlds.m	2001/02/07 14:48:43
@@ -942,7 +942,6 @@
 			% Compile time garbage collect (ie explicitly
 			% deallocate) the memory used by the lval.
 
-		% XXX the following is still quite tentative
 			% new_object(Target, Tag, Type,
 			%	Size, CtorName, Args, ArgTypes):
 			% Allocate a memory block of the given size,
@@ -963,10 +962,7 @@
 			maybe(mlds__rval),
 					% The amount of memory that needs to
 					% be allocated for the new object,
-					% measured in bytes.
-					% (XXX would it be better to measure
-					% this in bits or words rather than
-					% bytes?)
+					% measured in words (NOT bytes!).
 			maybe(ctor_name),
 					% The name of the constructor to
 					% invoke.
Index: compiler/mlds_to_c.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_c.m,v
retrieving revision 1.79
diff -u -d -r1.79 mlds_to_c.m
--- compiler/mlds_to_c.m	2001/02/05 16:51:32	1.79
+++ compiler/mlds_to_c.m	2001/02/07 14:50:44
@@ -2416,7 +2416,9 @@
 	mlds_output_type(Type),
 	io__write_string(", "),
 	( { MaybeSize = yes(Size) } ->
-		mlds_output_rval(Size)
+		io__write_string("("),
+		mlds_output_rval(Size),
+		io__write_string(" * sizeof(MR_Word))")
 	;
 		% XXX what should we do here?
 		io__write_int(-1)
Index: compiler/mlds_to_gcc.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_gcc.m,v
retrieving revision 1.30
diff -u -d -r1.30 mlds_to_gcc.m
--- compiler/mlds_to_gcc.m	2001/02/01 01:09:55	1.30
+++ compiler/mlds_to_gcc.m	2001/02/07 14:52:35
@@ -2839,28 +2839,10 @@
 	%
 	% Calculate the size that we're going to allocate.
 	%
-	( { MaybeSize = yes(SizeInBytes0) } ->
-		% Rather than generating a reference to a global variable
-		% mercury__private_builtin__SIZEOF_WORD, we ignore the
-		% word size multiplier, and instead get the word size
-		% from the bytes_per_word option.
-		% XXX This is kludgy.  We should change new_object
-		% so that it has the size in words rather than in bytes.
-		(
-			{ SizeInBytes0 = binop((*), SizeInWords,
-				_SizeOfWord) }
-		->
-			globals__io_lookup_int_option(bytes_per_word,
-				BytesPerWord),
-			{ SizeOfWord = const(int_const(BytesPerWord)) },
-			{ SizeInBytes = binop((*), SizeInWords, SizeOfWord) }
-		;
-			{ sorry(this_file, "unexpected size in new_object") },
-			{ SizeInBytes0 = SizeInBytes }
-		)
-		% For debugging:
-		% io__print("SizeInBytes0 = "), io__print(SizeInBytes0), io__nl,
-		% io__print("SizeInBytes = "), io__print(SizeInBytes), io__nl,
+	( { MaybeSize = yes(SizeInWords) } ->
+		globals__io_lookup_int_option(bytes_per_word, BytesPerWord),
+		{ SizeOfWord = const(int_const(BytesPerWord)) },
+		{ SizeInBytes = binop((*), SizeInWords, SizeOfWord) }
 	;
 		{ sorry(this_file, "new_object with unknown size") }
 	),
Index: compiler/mlds_to_il.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_il.m,v
retrieving revision 1.11
diff -u -d -r1.11 mlds_to_il.m
--- compiler/mlds_to_il.m	2001/01/22 04:20:31	1.11
+++ compiler/mlds_to_il.m	2001/02/07 14:55:22
@@ -1068,14 +1068,11 @@
 		get_load_store_lval_instrs(Target, LoadMemRefInstrs,
 			StoreLvalInstrs),
 
-			% XXX some hackery here to get around the MLDS memory
-			% allocation that tries to allocate in bytes.
-		{ Size = yes(binop((*), SizeInWordsRval0, _)) ->
-			SizeInWordsRval = SizeInWordsRval0
-		; Size = yes(SizeInWordsRval0) ->
+		{ Size = yes(SizeInWordsRval0) ->
 			SizeInWordsRval = SizeInWordsRval0
 		;
-			% XXX something else
+			% XXX do we need to handle this case?
+			% I think it's needed for --high-level-data
 			error("unknown size in MLDS new_object")
 		},
 		load(SizeInWordsRval, LoadSizeInstrs),
Index: runtime/mercury.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury.h,v
retrieving revision 1.34
diff -u -d -r1.34 mercury.h
--- runtime/mercury.h	2001/01/22 16:08:03	1.34
+++ runtime/mercury.h	2001/02/07 15:03:22
@@ -271,9 +271,8 @@
 	mercury__builtin__builtin__type_ctor_info_tuple_0
 
 /*
-** The compiler generates references to this constant.
-** This avoids the need for the mlds__rval type to
-** have a `sizeof' operator.
+** The compiler used to generate references to this constant.
+** XXX This should only be needed for bootstrapping now.
 */
 #ifdef MR_AVOID_MACROS
   enum { mercury__private_builtin__SIZEOF_WORD = sizeof(MR_Word) };

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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