[m-rev.] for review: reserved address data representation (part 1)

Tyson Dowd trd at cs.mu.OZ.AU
Wed Oct 24 15:51:22 AEST 2001


On 24-Oct-2001, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> On 24-Oct-2001, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> > Allow the compiler to optionally make use of reserved addresses --
> > null pointers, ints cast to pointers, and addresses of global variables --
> > to optimize the representation of constants in discriminated union types.
> 
> Estimated hours taken: 18
> Branches: main
> 
> Add compiler support for deciding when to use reserved addresses,
> and for generating code appropriately when they are used.
> 
> compiler/options.m:
> doc/user_guide.texi:
> 	Add new options `--num-reserved-addresses'
> 	and `--num-reserved-objects'.
> 
> compiler/hlds_data.m:
> 	Add new type `reserved_address ---> null_pointer ; small_pointer(int) ;
> 	reserved_object(sym_name, arity)'.
> 	Add new cons_tag alternatives `reserved_address(reserved_address)'
> 	and `shared_with_reserved_address(list(reserved_address), cons_tag)'.
> 	Also add get_secondary_tag, for use by ml_type_gen.m.
> 
> compiler/ml_type_gen.m:
> 	Don't generate types for constructors represented using reserved
> 	addresses.  For constructors represented using reserved_object,
> 	generate the reserved object.
> 	Also, use get_secondary_tag, rather than just unifying with
> 	shared_remote/2, so that it works for
> 	shared_with_reserved_tag(_, shared_remote(_, _)).
> 
> compiler/make_tags.m:
> 	If --tags none and --num-reserved-addresses are both set,
> 	then assign null_pointer and small_pointer(int) representations
> 	to constants up to the value set in num-reserved-addresses.
> 	If --tags none and --high-level-code are both set,
> 	and more constants remain unassigned, then assign reserved_object
> 	representations for those constants, and generate static member
> 	variable declarations for the reserved_objects.
> 
> compiler/make_hlds.m:
> 	Pass down the type_id to assign_constructor_tags in make_tags.m,
> 	since it is needed for reserved_object representations.
> 
> compiler/ml_unify_gen.m:
> compiler/unify_gen.m:
> 	Handle construction, deconstruction, and tag tests for
> 	types represented using reserved tags.
> 	(In unify_gen.m, only null_pointer and small_pointer(int)
> 	are supported; for reserved_object we call sorry/2).
> 
> compiler/ml_switch_gen.m:
> compiler/switch_gen.m:
> compiler/switch_util.m:
> 	Handle switches on types represented using reserved tags.
> 	XXX Currently we always use if-then-else chains for such
> 	    switches; this may not be efficient.
> 
> compiler/ml_code_util.m:
> 	Add ml_format_reserved_object_name.
> 	Also add accessibility parameter to ml_gen_static_const_defn,
> 	so that it can be used for generating the class member
> 	static constants used for reserved_objects.
> 
> compiler/ml_string_switch.m:
> compiler/ml_type_gen.m:
> compiler/ml_unify_gen.m:
> 	Handle the new parameter to ml_gen_static_const_defn.
> 
> compiler/bytecode_gen.m:
> 	Call sorry/2 if types represented using reserved addresses are
> 	encountered.


> Index: compiler/ml_code_util.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/compiler/ml_code_util.m,v
> retrieving revision 1.44
> diff -u -d -r1.44 ml_code_util.m
> --- compiler/ml_code_util.m	24 Aug 2001 15:44:51 -0000	1.44
> +++ compiler/ml_code_util.m	23 Oct 2001 03:52:27 -0000

> @@ -1402,6 +1409,19 @@
>  	term__var_to_int(Var, VarNumber),
>  	UniqueVarName = mlds__var_name(VarName, yes(VarNumber)).
>  
> +	% ml_format_reserved_object_name(CtorName, CtorArity, ReservedObjName):
> +	% Generate a name for a specially reserved global variable
> +	% (or static member variable)
> +	% whose address is used to represent the specified constructor.
> +	%
> +	% We add the "obj_" prefix to avoid a name clash in the IL back-end
> +	% between the type for a given constructor
> +	% and the reserved object for that constructor.
> +	%
> +ml_format_reserved_object_name(CtorName, CtorArity) = ReservedObjName :-
> +	Name = string__format("obj_%s_%d", [s(CtorName), i(CtorArity)]),
> +	ReservedObjName = var_name(Name, no).
> +

It would be better to either
	- make prepending "obj_" part of the MLDS - MLDS-suitable for IL
	  backend transformation
	- make it an invariant of the MLDS that such names don't clash

Generally we have been trying to solve such problems in the backend
which has the limitation, so I would prefer the former approach.


Otherwise this change seems fine, thanks.

-- 
       Tyson Dowd           # 
                            #  Surreal humour isn't everyone's cup of fur.
     trd at cs.mu.oz.au        # 
http://www.cs.mu.oz.au/~trd #
--------------------------------------------------------------------------
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