The Mercury Project
Re: [mercury-users] Newbie query about compiler optimisations

Home

News

Information
  Overview
  Features
  Documentation
  Papers
  Developers
  Events
  Reports

Mailing Lists
  Developers
  Users
  Search

Download
  Current Release
  Snapshot
  Old Releases

Related
  Applications
  MCORBA
  Contributing Code

Contact

Search

Subject: Re: [mercury-users] Newbie query about compiler optimisations
From: Fergus Henderson (fjh@cs.mu.OZ.AU)
Date: Sat Dec 02 2000 - 11:43:44 EST


On 01-Dec-2000, Sandy Harris <sandy@storm.ca> wrote:
> :- pred cipher( p, c, k1, k2).
> :- mode cipher( in, out, in, in) is det. % encryption
> :- mode cipher( out, in, in, in) is det. % decryption
>
> What I want to do, and haven't figured out, is to solve for one
> of the k's at a time, treating the other as a "don't care"
> variable.
>
> % solve directly for k1 treating k2 as don't care
> :- pred findleft(p, c, k1).
> :- mode findleft(in, in, out) is det.

Well, the code for that is trivial ;-)

        findleft(P, C, K1) :-
                cipher(P, C, K1, _K2).

The hard bit is getting the compiler to optimize that! Currently
the Mercury compiler doesn't optimize code with unused outputs like
that. We've considered doing it, but it doesn't seem to come up very
often in the benchmarks that we've looked at.

The Mercury compiler does do the converse optimization, eliminating
unused *input* arguments:

        foo(A, B, C, _) :-
                ...

The code to do this optimization is in compiler/unused_args.m
in the source dstribution; it might also be described in
Simon Taylor's honours thesis, which is available from the
papers section of the Mercury web page.

But we haven't yet taught the Mercury compiler how to eliminate unused
output arguments. This would make a good project for someone.

Cheers,
        Fergus.

-- 
Fergus Henderson <fjh@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-users mailing list
post:  mercury-users@cs.mu.oz.au
administrative address: owner-mercury-users@cs.mu.oz.au
unsubscribe: Address: mercury-users-request@cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request@cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



This mail archive was generated by hypermail 2b25 on Sun Dec 31 2000 - 00:40:03 EST.