Re: Stack-based IR vs. Register-based IR (Anton Ertl)
26 Jul 1996 23:22:02 -0400

          From comp.compilers

Related articles
Stack-based IR vs. Register-based IR (Evan Cheng) (1996-07-20)
Stack-based IR vs. Register-based IR (John Gough) (1996-07-22)
Re: Stack-based IR vs. Register-based IR (Patrick Logan) (1996-07-23)
Re: Stack-based IR vs. Register-based IR (1996-07-26)
| List of all articles for this month |

From: (Anton Ertl)
Newsgroups: comp.compilers
Date: 26 Jul 1996 23:22:02 -0400
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
References: 96-07-137
Keywords: optimize

Evan Cheng <> writes:
|> I am hoping to induce some discussion on the merits (or lack of)
|> of stack-based intermediate representations and register-based ones.

It depends on the purpose. If you want to use the intermediate
representation for interpreting, then a stack-based IR is best, if
your source language translates easily into it. You can find my
arguments on this in

    author = "M. Anton Ertl",
    title = "Stack Caching for Interpreters",
    crossref = "sigplan95",
    pages = "315--327",
    url = "",
    abstract = "An interpreter can spend a significant part of its
                                    execution time on arguments of virtual machine
                                    instructions. This paper explores two methods to
                                    reduce this overhead for virtual stack machines by
                                    caching top-of-stack values in (real machine)
                                    registers. The {\em dynamic method} is based on
                                    having, for every possible state of the cache, one
                                    specialized version of the whole interpreter; the
                                    execution of an instruction usually changes the
                                    state of the cache and the next instruction is
                                    executed in the version corresponding to the new
                                    state. In the {\em static method} a state machine
                                    that keeps track of the cache state is added to the
                                    compiler. Common instructions exist in specialized
                                    versions for several states, but it is not necessary
                                    to have a version of every instruction for every
                                    cache state. Stack manipulation instructions are
                                    optimized away."

If, OTOH I need a sequentialized intermediate representation for the
optimization stage of a compiler targetting a register machine (and
probably even for other architecture classes), I would use a an IR
with an infinte number of registers. Such a representation makes it
easier to reorder code and to introduce new values (e.g., in strength

- anton
M. Anton Ertl

Post a followup to this message

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