Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Comparison of CPS, ANF, and SSA?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  13 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Bradd W. Szonye  
View profile  
 More options Jan 14 2005, 5:28 am
Newsgroups: comp.lang.scheme
From: "Bradd W. Szonye" <bradd+n...@szonye.com>
Date: Fri, 14 Jan 2005 10:28:28 GMT
Local: Fri, Jan 14 2005 5:28 am
Subject: Comparison of CPS, ANF, and SSA?
I learned something new this week: While reading up on continuation-
passing-style (CPS) interpreters and intermediate languages, I
discovered some literature on A-normal form (ANF) and static single
assignment (SSA) representations. I've been trying to gather more
information on the latter two forms, since they seem more promising than
CPS overall. However, my searches have been frustrating so far,
especially for ANF (which has very Google-unfriendly search terms).

I'd appreciate it if somebody could compare and contrast these
representations, answer some questions, or at least point me to good
articles and bibliographies on the topic.

I'm particularly interested in two questions:

Are there any compelling reasons to use a CPS intermediate form to
represent Scheme code, except for tutorial purposes?

How do major Scheme features like lexical closures and first-class
continuations interact with SSA representations? It seems to me that the
"non-local" aspects of those features might make it more difficult to
compute and reason about definitions and uses, but I'm not sure.
--
Bradd W. Szonye
http://www.szonye.com/bradd


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bradd W. Szonye  
View profile  
 More options Jan 14 2005, 5:51 am
Newsgroups: comp.lang.scheme
From: "Bradd W. Szonye" <bradd+n...@szonye.com>
Date: Fri, 14 Jan 2005 10:51:07 GMT
Local: Fri, Jan 14 2005 5:51 am
Subject: Re: Comparison of CPS, ANF, and SSA?

Bradd W. Szonye wrote:
> I'd appreciate it if somebody could compare and contrast these
> representations, answer some questions, or at least point me to good
> articles and bibliographies on the topic.

I forgot to mention that I've already read Amr Sabry's thesis, which is
actually how I learned about A-normal form. I'm just having a hard time
finding information beyond that. Ideally, I'd like something readable to
an engineer; while I can follow the gist of Sabry's thesis, most of the
proofs and lambda-calculus stuff is over my head.

I've also read a bit of the SSA literature, including several general
overviews and the Rice paper on semi-pruned form. I found all that very
comprehensible -- that's about the level of mathematical sophistication
I'm comfortable with. The problem with the SSA stuff is that it all
seems oriented toward Algol-family languages, and I don't have a strong
enough intuition or understanding to see how it works with Lisp-family
languages.

Thanks!
--
Bradd W. Szonye
http://www.szonye.com/bradd


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jim Bender  
View profile  
 More options Jan 14 2005, 9:16 am
Newsgroups: comp.lang.scheme
From: Jim Bender <j...@benderweb.net>
Date: Fri, 14 Jan 2005 14:16:17 GMT
Local: Fri, Jan 14 2005 9:16 am
Subject: Re: Comparison of CPS, ANF, and SSA?
In message <slrncuf7mc.unt.bradd+n...@szonye.com>
 "Bradd W. Szonye" <bradd+n...@szonye.com> wrote:

>I learned something new this week: While reading up on continuation-
>passing-style (CPS) interpreters and intermediate languages, I
>discovered some literature on A-normal form (ANF) and static single
>assignment (SSA) representations. I've been trying to gather more
>information on the latter two forms, since they seem more promising than
>CPS overall. However, my searches have been frustrating so far,
>especially for ANF (which has very Google-unfriendly search terms).

I would make the following the following literature suggestions:

Dave Tarditi's dissertation (for its use of an ANF-style representation
and the optimizations performed; this is perhaps the best "engineers
point of view" on ANF that I know of):
  David Tarditi.  Design and Implementation of Code Optimiziations for a
  Type-Directed Compiler for Standard ML.  PhD thesis, School of
  Computer Science, Carnegie Mellon University,  December 1996
  http://reports-archive.adm.cs.cmu.edu/anon/1997/CMU-CS-97-108.ps

A Correspondence between Continuation-Passing Style and  Static
Single Assignment.  (IR'95, published as  ACM SIGPLAN Notices,
3(30), March 1995)
  http://mumble.net/~kelsey/papers/cps-ssa.ps.gz

SSA is Functional Programming. Andrew W. Appel, ACM SIGPLAN
Notices v. 33, no. 4, pp. 17-20, April 1998.
  http://www.cs.princeton.edu/~appel/papers/ssafun.pdf

Optimizing nested loops using local CPS conversion
John Reppy, In Higher-order and Symbolic Computation, 2002
  http://moby.cs.uchicago.edu/papers/2002/hosc-final.pdf

Jim Bender


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Joe Marshall  
View profile  
 More options Jan 14 2005, 9:37 am
Newsgroups: comp.lang.scheme
From: Joe Marshall <j...@ccs.neu.edu>
Date: Fri, 14 Jan 2005 09:37:10 -0500
Local: Fri, Jan 14 2005 9:37 am
Subject: Re: Comparison of CPS, ANF, and SSA?
"Bradd W. Szonye" <bradd+n...@szonye.com> writes:

> Bradd W. Szonye wrote:
>> I'd appreciate it if somebody could compare and contrast these
>> representations, answer some questions, or at least point me to good
>> articles and bibliographies on the topic.

> I forgot to mention that I've already read Amr Sabry's thesis, which is
> actually how I learned about A-normal form. I'm just having a hard time
> finding information beyond that. Ideally, I'd like something readable to
> an engineer; while I can follow the gist of Sabry's thesis, most of the
> proofs and lambda-calculus stuff is over my head.

Try this one:

 <http://citeseer.ist.psu.edu/flanagan-essence.html>
 Cormac Flanagan, Amr Sabry, Bruce F. Duba, Matthias Felleisen
 Proceedings ACM SIGPLAN 1993 Conf. on Programming Language Design and
 Implementation, PLDI'93, Albuquerque, NM, USA, 23--25 June 1993

and browse CiteSeer.

I was recently researching the same thing and discovered that nearly
anything technical has "a normal form" and Google doesn't key on the
all-important hyphen between `a' and `normal'.  However it is also
referred to as `administrative normal form' and `let normal form'.

> Are there any compelling reasons to use a CPS intermediate form to
> represent Scheme code, except for tutorial purposes?

Maybe.  Some Java-based Scheme systems use CPS conversion in order
to get continuations and tail-recursion.  Since the final form will be
CPS, the intermediate form might as well be, too.

But for `normal' compilation, it appears that ANF is superior.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matthias Blume  
View profile  
 More options Jan 14 2005, 10:41 am
Newsgroups: comp.lang.scheme
From: Matthias Blume <f...@my.address.elsewhere>
Date: Fri, 14 Jan 2005 09:41:37 -0600
Local: Fri, Jan 14 2005 10:41 am
Subject: Re: Comparison of CPS, ANF, and SSA?

<plug>

One might also have a look at a paper co-authored by Lal George
and myself regarding the language Nova and its compiler:

    Taming the IXP Network Processor. Lal George and Matthias Blume. In
    Proceedings of the ACM SIGPLAN 2003 Conference on Programming Language
    Design and Implementation (PLDI '03), San Diego, California. June
    9-11, 2003.

Our compiler used CPS as its intermediate form because in the setting
of this particular language/processor combination we found that CPS
had none of the drawbacks usually attributed to it.
(The paper does not go into much detail as far as CPS is concerned, though.)

</plug>

Matthias


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jens Axel Søgaard  
View profile  
 More options Jan 14 2005, 11:02 am
Newsgroups: comp.lang.scheme
From: Jens Axel Søgaard <use...@soegaard.net>
Date: Fri, 14 Jan 2005 17:02:35 +0100
Local: Fri, Jan 14 2005 11:02 am
Subject: Re: Comparison of CPS, ANF, and SSA?

When "The Essence of Compiling with Continuations" was reprinted in
the "20 years of SIGPLAN", the authors wrote a retrospective:

     <http://www.ccs.neu.edu/scheme/pubs/pldi-fsdf.ps>,

which is packed with references.

For actual source code look at:

     <http://schemecookbook.org/view/Cookbook/PearlANormalForm>
     <http://download.plt-scheme.org/scheme/plt/collects/compiler/private/a...>

--
Jens Axel Søgaard

/Jens Axel Søgaard


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bradd W. Szonye  
View profile  
 More options Jan 15 2005, 4:40 am
Newsgroups: comp.lang.scheme
From: "Bradd W. Szonye" <bradd+n...@szonye.com>
Date: Sat, 15 Jan 2005 09:40:27 GMT
Local: Sat, Jan 15 2005 4:40 am
Subject: Re: Comparison of CPS, ANF, and SSA?

Joe Marshall wrote:
> I was recently researching the same thing and discovered that nearly
> anything technical has "a normal form" and Google doesn't key on the
> all-important hyphen between `a' and `normal'.  However it is also
> referred to as `administrative normal form' and `let normal form'.

Yeah, I ran into the same problem.

>> Are there any compelling reasons to use a CPS intermediate form to
>> represent Scheme code, except for tutorial purposes?
> Maybe.  Some Java-based Scheme systems use CPS conversion in order to
> get continuations and tail-recursion.  Since the final form will be
> CPS, the intermediate form might as well be, too.

That makes sense. However, I'm more interested in ground-up interpreters
and compilers, so I don't think that's important to me.

> But for `normal' compilation, it appears that ANF is superior.

That's the impression I got.

Thanks to everyone for the references. I may have more questions after
I've had time to digest it all.
--
Bradd W. Szonye
http://www.szonye.com/bradd


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bradd W. Szonye  
View profile  
 More options Jan 15 2005, 6:05 am
Newsgroups: comp.lang.scheme
From: "Bradd W. Szonye" <bradd+n...@szonye.com>
Date: Sat, 15 Jan 2005 11:05:23 GMT
Local: Sat, Jan 15 2005 6:05 am
Subject: Re: Comparison of CPS, ANF, and SSA?

Jim Bender wrote:
> A Correspondence between Continuation-Passing Style and  Static
> Single Assignment.  (IR'95, published as  ACM SIGPLAN Notices,
> 3(30), March 1995)
>   http://mumble.net/~kelsey/papers/cps-ssa.ps.gz

This is the only paper I've found that mentions both call/cc and SSA,
and it simply notes that call/cc is one of the CPS forms that can't
generally be translated to SSA. Does this imply that SSA is only useful
for certain subsets of Scheme code (i.e., procedures that can be proven
to have no non-local jumps)?

I'm a bit puzzled by this, because even C and C++ have non-local jumps
(e.g., longjmp and exception handling). Therefore, SSA compilers must
have some way of coping with them. Assuming that techniques do exist for
representing non-local jumps in SSA representations, is there hope for
using them in a Scheme compiler? Or is SSA useful only for certain
procedures?
--
Bradd W. Szonye
http://www.szonye.com/bradd


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jens Axel Søgaard  
View profile  
 More options Jan 15 2005, 7:04 am
Newsgroups: comp.lang.scheme
From: Jens Axel Søgaard <use...@soegaard.net>
Date: Sat, 15 Jan 2005 13:04:10 +0100
Local: Sat, Jan 15 2005 7:04 am
Subject: Re: Comparison of CPS, ANF, and SSA?

Bradd W. Szonye wrote:
> Thanks to everyone for the references. I may have more questions after
> I've had time to digest it all.

This is a short, very readable article of Appel, which relates SSA to
lexical scope in functional programs.

     <http://www.cs.princeton.edu/~appel/papers/ssafun.pdf>

--
Jens Axel Søgaard


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jens Axel Søgaard  
View profile  
 More options Jan 15 2005, 7:06 am
Newsgroups: comp.lang.scheme
From: Jens Axel Søgaard <use...@soegaard.net>
Date: Sat, 15 Jan 2005 13:06:24 +0100
Local: Sat, Jan 15 2005 7:06 am
Subject: Re: Comparison of CPS, ANF, and SSA?

Bradd W. Szonye wrote:
> However, my searches have been frustrating so far,
> especially for ANF (which has very Google-unfriendly search terms).

Here is the trick, search for:

     administrative normal form static single assignment

--
Jens Axel Søgaard


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jens Axel Søgaard  
View profile  
 More options Jan 15 2005, 7:15 am
Newsgroups: comp.lang.scheme
From: Jens Axel Søgaard <use...@soegaard.net>
Date: Sat, 15 Jan 2005 13:15:22 +0100
Local: Sat, Jan 15 2005 7:15 am
Subject: Re: Comparison of CPS, ANF, and SSA?

Bradd W. Szonye wrote:
> Are there any compelling reasons to use a CPS intermediate form to
> represent Scheme code, except for tutorial purposes?

John Reppy has some thoughts about this in the introduction to:

     <http://moby.cs.uchicago.edu/papers/2002/hosc-final.pdf>

The paper describes how to use a local CPS conversion
on a direct style intermediary representation in order to
optimize nested loops. This suggests that one can benefit
from using both ANF- and CPS-techniques in the same compiler.

--
Jens Axel Søgaard


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
George Neuner  
View profile  
 More options Jan 19 2005, 5:21 pm
Newsgroups: comp.lang.scheme
From: George Neuner <gneune...@comcast.net>
Date: Wed, 19 Jan 2005 17:21:34 -0500
Local: Wed, Jan 19 2005 5:21 pm
Subject: Re: Comparison of CPS, ANF, and SSA?
On Sat, 15 Jan 2005 11:05:23 GMT, "Bradd W. Szonye"

SSA doesn't address non-local jumps differently.  Any control transfer
can be accomodated by inserting the appropriate phi function to join
data definitions on separate entry paths.  

The class of upward-only continuations ( including longjmps and
exceptions ) is relatively easy to handle.  Because the code path is
essentially being abandoned, locals within it don't need to be
considered on exit.  The join function(s) at the continuation point
need only consider data external to the abandoned path which may have
been side effected (including any persisting data which may have been
newly created).

I've never tried to use SSA with general continuations but I suspect
it is not a very good fit.  I expect that each continuation path would
have to be treated as if it were nested recursions or loops ...
working on the assumption that coroutines could have modified data
defined below the entry point unless an examination of the code could
prove no lower entry point.  Does anyone who has actually worked with
this care to comment?

George
--
for email reply remove "/" from address


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
William D Clinger  
View profile  
 More options Jan 21 2005, 11:05 pm
Newsgroups: comp.lang.scheme
From: "William D Clinger" <cesuraS...@verizon.net>
Date: 21 Jan 2005 20:05:27 -0800
Local: Fri, Jan 21 2005 11:05 pm
Subject: Re: Comparison of CPS, ANF, and SSA?

George Neuner wrote:
> I've never tried to use SSA with general continuations
> but I suspect it is not a very good fit. I expect that each
> continuation path would have to be treated as if it were
> nested recursions or loops ...

Sounds about right.  Basically, every return point has to
be treated almost as though it were a lambda expression,
because the continuation (i.e. the closure of the return
point) can be captured and called multiple times.  This
means you can't move side effects or some allocation
effects across a return point.  You can still move pure
terminating computations across a return point, however.

SSA forms must deal with similar restrictions.  You can't
move arbitrary side effects across a call site, because
the effect might be visible to the callee.

I think of A-normal form as a normal form for DAGs, SSA
as a normal form for loops, and CPS as a normal form for
interprocedural control flow.  My Twobit compiler uses
A-normal form together with several interprocedural
optimizations that don't require CPS, and doesn't do any
loop optimization per se at all.

Will


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google