[m-rev.] for review: optimizations for foreign_procs

Julien Fischer juliensf at csse.unimelb.edu.au
Fri Jan 12 14:37:32 AEDT 2007


On Thu, 11 Jan 2007, Zoltan Somogyi wrote:

> compiler/use_local_vars.m:
> 	Extend this optimization to handle temporaries being both defined in
> 	and used by foreign_proc_code instructions. This should eliminate
> 	unnecessary accesses to the MR_fake_reg array, and thus speed up
> 	programs that use foreign code a lot, including typeclass- and
> 	tabling-intensive programs, since those features are implemented using
> 	inline foreign code. I/O intensive should also benefit, but not much,

I/O intensive programs should ...

> 	since the cost of the I/O itself overwhelms the cost of the
> 	MR_fake_reg accesses.
>
> 	Group together the LLDS instructions that are handled similarly.
> 	Factor out some common code.
>
> compiler/opt_util.m:
> 	Allow for the fact that foreign_proc_codes can now refer to
> 	temporaries.
>
> compiler/opt_debug.m:
> 	Print more useful information about foreign_proc_code components.
>
> compiler/prog_data.m:
> 	Rename the types and function symbols of the recently added
> 	foreign_proc attributes to avoid clashing with the keywords
> 	representing them in source code.
>
> 	Add a new foreign_proc attribute, proc_may_duplicate, that governs
> 	whether the body of foreign code is allowed to be duplicated.
>
> compiler/table_gen.m:
> 	Include does_not_affect_liveness among the annotations for the
> 	foreign_proc calls generated by this module. Some of these procedures
> 	affect memory beyond their arguments, but that memory is in tables,
> 	not in unlisted registers.
>
> 	Allow some of the smaller code fragments generated by this module
> 	to be duplicated.
>
> compiler/inlining.m:
> 	Respect the may_not_duplicate foreign_proc attribute.
>
> compiler/pragma_c_gen.m:
> 	Transmit any annotations about liveness from the HLDS to the LLDS,
> 	since without does_not_affect_liveness annotations use_local_vars.m
> 	cannot optimize foreign_proc_codes.
>
> 	Transmit any annotations about may_duplicate from the HLDS to the LLDS,
> 	since with them jumpopt can do a better job.
>
> compiler/llds.m:
> 	Use the new foreign_proc attribute instead of a boolean to represent
> 	whether a foreign code fragment may be duplicated.
>
> compiler/jumpopt.m:
> compiler/livemap.m:
> compiler/proc_gen.m:
> compiler/trace_gen.m:
> 	Conform to the changes above.
>
> doc/reference_manual.texi:
> 	Document the new foreign_proc attribute.
>
> library/array.m:
> library/builtin.m:
> library/char.m:
> library/dir.m:
> library/float.m:
> library/int.m:
> library/io.m:
> library/lexer.m:
> library/math.m:
> library/private_builtin.m:
> library/string.m:
> library/version_array.m:
> 	Add does_not_affect_liveness annotations to the C foreign_procs that
> 	deserve them.
>
> configure.in:
> 	Require the installed compiler to support does_not_affect_liveness.

...
> Index: doc/reference_manual.texi
> ===================================================================
> RCS file: /home/mercury/mercury1/repository/mercury/doc/reference_manual.texi,v
> retrieving revision 1.377
> diff -u -b -r1.377 reference_manual.texi
> --- doc/reference_manual.texi	6 Jan 2007 10:49:04 -0000	1.377
> +++ doc/reference_manual.texi	11 Jan 2007 07:10:28 -0000
> @@ -6390,6 +6390,16 @@
> the compiler assumes @samp{affects_liveness},
> unless the code of the foreign_proc in question is empty.
>
> + at item @samp{may_duplicate/may_not_duplicate}
> +This attribute tells the compiler
> +whether it is allowed to duplicate the foreign code fragment
> +through optimizations such as inlining.
> +The @samp{may_duplicate} attribute says that it may;
> +The @samp{may_not_duplicate} attribute says that it may not.
> +In the absence of either attribute,
> +the compiler is allowed make its own judgement in the matter,
> +based on factors such as the size of the code fragment.

As far as the decision made by the inliner to inline or not goes is
may_duplicate equivalent in its effect to an inline pragma for the
predicate?  If so, the I suggest mentioning that here.

I suggest changing the diff so that the compiler emits an error message if a
may_duplicate or may_not_duplicate conflicts with a pragam inline or pragma
no_inline declaration for the predicate.  (Please add a test case(s) to 
tests/invalid for this error message as well.)

The rest of that looks fine.

Julien.
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list