Re: Optimizing stack access for a stack based VM

Louis Krupp <lkrupp@pssw.com>
Thu, 13 Sep 2007 05:33:43 -0600

          From comp.compilers

Related articles
Optimizing stack access for a stack based VM jirik.svoboda@seznam.cz (Jiri Svoboda) (2007-09-11)
Re: Optimizing stack access for a stack based VM DrDiettrich1@aol.com (Hans-Peter Diettrich) (2007-09-13)
Re: Optimizing stack access for a stack based VM blog@rivadpm.com (Alex McDonald) (2007-09-13)
Re: Optimizing stack access for a stack based VM lkrupp@pssw.com (Louis Krupp) (2007-09-13)
Re: Optimizing stack access for a stack based VM DrDiettrich1@aol.com (Hans-Peter Diettrich) (2007-09-13)
Re: Optimizing stack access for a stack based VM DrDiettrich1@aol.com (Hans-Peter Diettrich) (2007-09-13)
Re: Optimizing stack access for a stack based VM jvorbrueggen@not-mediasec.de (=?ISO-8859-1?Q?Jan_Vorbr=FCggen?=) (2007-09-14)
Re: Optimizing stack access for a stack based VM blog@rivadpm.com (Alex McDonald) (2007-09-14)
Re: Optimizing stack access for a stack based VM kenney@cix.compulink.co.uk (2007-09-14)
Re: Optimizing stack access for a stack based VM jeffrey.kenton@comcast.net (Jeff Kenton) (2007-09-16)
[2 later articles]
| List of all articles for this month |
From: Louis Krupp <lkrupp@pssw.com>
Newsgroups: comp.compilers
Date: Thu, 13 Sep 2007 05:33:43 -0600
Organization: Posted via Supernews, http://www.supernews.com
References: 07-09-030
Keywords: storage
Posted-Date: 13 Sep 2007 13:33:54 EDT

Jiri Svoboda wrote:
> I'm working on a compiler of a Pascal-like language for a specific
> stack-based virtual machine. To produce small code, I would like to
> optimize the storage of variables and temporaries akin to register
> allocation on a register-based machine.


I've seen something like this done in two places:


One is Postscript, where programmers do this manually. There are no
statements or expressions as such, just a stack and operators.


To do the equivalent of "x := x + 1":


dict /x get 1 add dict /x exch put


You can also do optimize away one dictionary lookup with something like
this:


dict /x 2 copy get 1 add put


Then there's the Unisys MCP Series and their Burroughs ancestors, all
stack machines. I've seen those compilers optimize expressions, e.g.:


x ** 5 would be something like


load x
dupl
dupl
mult
dupl
mult
mult


I'm not sure these compilers do everything you're looking for.


I do know that the earlier machines in this series (Burroughs B6700)
kept the top two words of the stack (and their double precision
extensions) in registers and the rest of the stack in memory. Later
machines cached the top n words of the stack, which made stack access
faster.


I'm not sure I understand all of what you're trying to do. Are you
trying to reuse stack offsets when variables are no longer needed?
Are you trying to avoid assigning a stack offset to a variable that
can be bounced around the top of the stack until it can simply go
away?


Are you sure you'd be saving memory? More complex code means more
memory (and more development time and more bugs).


Louis


lkrupp *at* pssw *dot* com



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.