public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: Per Bothner <per@bothner.com>
Cc: Zack Weinberg <zack@codesourcery.com>, gcc@gcc.gnu.org
Subject: Re: Language-independent functions-as-trees representation
Date: Wed, 28 Aug 2002 06:50:00 -0000	[thread overview]
Message-ID: <wvl1y8j3xed.fsf@prospero.cambridge.redhat.com> (raw)
In-Reply-To: <3D6718BA.2050207@bothner.com>

On Fri, 23 Aug 2002 22:25:14 -0700, Per Bothner <per@bothner.com> wrote:

> Zack Weinberg wrote:
>> I'm a little concerned about memory consumption if we have to have a
>> COMPOUND_EXPR for (nearly) every statement, on top of whatever sort of
>> thing the statement itself is.  A two-operand EXPR node is 24 bytes,
>> which currently gets rounded up to 32 (I plan to fix that).
>
> Two possible solutions:
>
> We could have a variable-sized COMPOUND_EXPR (a la TREE_VEC).
> A chain of 20 "statements" is a single COMPOUND_EXPR with 20
> "operands".  Compact, fast, great locality, easy to traverse
> in either direction.  Not so easy to build incrementally
> - but for that a parser can use a temporary obstack, or
> temporary TREE_LIST, and then re-cycle the TREE_LIST at the
> end of the block.  Or just use 2-operand COMPOUND_EXPR, and
> recycle them at the end of the block.
>
> This may be awkward for some optimizations, but its more of a
> coding issue than a performance issue, I believe.  E.g. an
> optimization that does major re-organization should perhaps
> just copy the entire tree, and throw away the old one.  If you
> do only a few insertions, use an extra 2-operand COMPOUND_EXPR.

This does sound awkward, particularly for simplification.  In the code I've
been writing which uses 2-operand COMPOUND_EXPR, simplifying a complex
statement just means replacing it with a COMPOUND_EXPR; later, we go
through and flatten the COMPOUND_EXPRs so that they're only
right-recursive.  Of course, this last step could replace them with a
variable-sized one instead, but this would add complexity in order to avoid
doing it too early.

Allocating and then throwing away all these COMPOUND_EXPRs would use even
more memory in the short term than just using the 2-operand forms, since we
don't do GC until we're done with the function.  We might be able to reduce
the wastage by using a varray for temporary storage.

Deleting a statement could be handled by replacing it with empty_stmt_node
until we get around to compacting.

Of course, even an array involves more memory use and pointer chasing than
just using the TREE_CHAIN.

I don't see any real benefit to random access.

> Alternatively, we can just use the TREE_CHAIN of expression
> nodes to chain them  Some valid expressions, including
> constants and declaration references would need to be wrapped
> in some other expression, if they are to be chained, but
> that is any enough.

Those expressions shouldn't appear at statement context (since they have no
side-effects), so we're OK.  It does seem fragile, though, and code that
currently uses the TREE_CHAIN of other expressions (i.e. PUSH_LABELED_BLOCK
in Java) would need to be changed.

This leaves the question of how to handle double-chaining of statements.
The type of any expression at statement context isn't important (and will
usually be void), so we could reuse that field like the current code does.
Or look up backwards links in another table.

This scheme makes substitution more complicated; if we have some sort of
wrapper, we can just replace one statement with another (or with a
COMPOUND_EXPR).  If we use the TREE_CHAIN directly, we need to splice the
replacement in at both beginning and end.

This scheme provides no easy way of finding the end of a chain; walking
over the whole list each time could get expensive in large functions.

> The solution of just chaining expressions together does the
> smentic problem of when are we talking about the component
> expression, and are we talking about the chain.  Should expand_expr
> applied to an expression implicitly also expand its TREE_CHAIN?
> That appears to be what c-semantics.c does, at first glance.

Makes sense.  Or there could be a CHAINED_EXPR_LIST node wrapping the first
one, which could also have a pointer to the end of the chain.

I'm not compelled by any of the options mentioned.  Any other opinions?

Jason

  parent reply	other threads:[~2002-08-28  6:50 UTC|newest]

Thread overview: 95+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-20 19:47 Jason Merrill
2002-07-20 13:58 ` Per Bothner
2002-07-21 22:04   ` Jason Merrill
2002-07-20 22:17 ` Steven Bosscher
2002-07-21  6:20   ` Richard Henderson
2002-07-21  9:43     ` Steven Bosscher
2002-07-21 14:31       ` Richard Henderson
2002-07-21 15:07         ` Daniel Berlin
2002-07-21 15:15         ` Steven Bosscher
2002-07-21  0:09 ` Neil Booth
2002-07-21  0:41   ` Richard Henderson
2002-07-21  0:13 ` Richard Henderson
2002-07-21  7:06 ` Andreas Jaeger
2002-07-21 11:09   ` Pop Sébastian
2002-07-21 11:44     ` Andreas Jaeger
2002-07-21 23:20       ` Phil Edwards
2002-07-22  2:24         ` Daniel Berlin
2002-07-22  6:23           ` Phil Edwards
2002-07-22  7:10       ` where is tree dump utility Sathiskanna
2002-07-22 13:25         ` Diego Novillo
2002-07-21 17:03 ` Language-independent functions-as-trees representation Mark Mitchell
2002-07-21 20:30   ` Jason Merrill
2002-07-21 22:44     ` Mark Mitchell
2002-07-21 23:06       ` Jason Merrill
2002-07-21 23:53         ` Mark Mitchell
2002-07-22  0:13           ` Jason Merrill
2002-07-22  3:17             ` Daniel Berlin
2002-07-22  5:11     ` Daniel Berlin
2002-07-22  7:18       ` Jason Merrill
2002-07-22 13:11         ` Daniel Berlin
2002-07-23 18:20           ` Jason Merrill
2002-07-27 14:10             ` Pop Sébastian
2002-07-30  9:02               ` Jason Merrill
2002-07-22 21:09   ` Diego Novillo
2002-07-22  2:42 ` where is the data Sathiskanna
2002-07-22 19:04 ` Language-independent functions-as-trees representation Diego Novillo
2002-07-23 10:21   ` Fergus Henderson
2002-07-23 11:26     ` Diego Novillo
2002-07-23 11:34       ` Toon Moene
2002-07-23 12:01         ` Diego Novillo
2002-07-23 17:48           ` Pop Sébastian
2002-07-26 15:56             ` Jason Merrill
2002-07-23 17:48   ` Jason Merrill
2002-07-23 18:29     ` Andrew Haley
2002-07-23 19:07     ` Richard Henderson
2002-07-23 23:40       ` Jason Merrill
2002-07-24  3:01         ` Richard Henderson
2002-07-24 11:34           ` Jason Merrill
2002-07-23 21:57     ` Fergus Henderson
2002-07-24  0:22       ` Jason Merrill
2002-08-23  5:41 ` Jason Merrill
2002-08-23  6:00   ` Gabriel Dos Reis
2002-08-23  7:41     ` Jason Merrill
2002-08-23  8:22   ` Pop Sébastian
2002-08-23  8:46     ` Jason Merrill
2002-08-23  8:23   ` Jason Merrill
2002-08-23 12:16   ` Diego Novillo
2002-08-23 15:42     ` Daniel Berlin
2002-08-23 17:26     ` Jason Merrill
2002-08-23 17:42       ` Zack Weinberg
2002-08-23 22:25         ` Per Bothner
2002-08-26  0:07           ` Zack Weinberg
2002-08-26  3:07             ` Neil Booth
2002-08-26  3:18               ` Gabriel Dos Reis
2002-08-28  6:50           ` Jason Merrill [this message]
2002-08-28 16:42             ` Per Bothner
2002-08-23 22:31       ` Per Bothner
2002-08-26 19:56       ` Diego Novillo
2002-08-29 14:35         ` Richard Henderson
2002-09-03  5:38           ` Jason Merrill
2002-08-26 16:58     ` Paul Brook
2002-08-29 14:21     ` Richard Henderson
2002-08-23 13:01   ` Neil Booth
2002-08-28  4:44     ` Jason Merrill
2002-08-28  5:17       ` Gabriel Dos Reis
2002-08-28  7:10         ` Jason Merrill
2002-08-28  8:02           ` Diego Novillo
2002-08-28  8:32           ` Gabriel Dos Reis
2002-08-28 14:06   ` Jason Merrill
2002-09-10 17:08     ` Gerald Pfeifer
2002-08-29 14:10   ` Richard Henderson
2002-09-03  5:16     ` Jason Merrill
2002-09-04 10:20       ` Paul Brook
2002-08-23 13:53 Robert Dewar
2002-08-23 14:10 ` Neil Booth
2002-08-23 14:14 Robert Dewar
2002-08-23 14:14 ` Neil Booth
2002-08-23 14:35 Robert Dewar
2002-08-23 15:21 ` Neil Booth
2002-08-24  7:59 ` Michael S. Zick
2002-08-23 15:25 Richard Kenner
2002-08-23 15:33 ` Neil Booth
2002-08-23 18:20 Robert Dewar
2002-08-24 12:47 Robert Dewar
2002-08-28  5:03 Robert Dewar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=wvl1y8j3xed.fsf@prospero.cambridge.redhat.com \
    --to=jason@redhat.com \
    --cc=gcc@gcc.gnu.org \
    --cc=per@bothner.com \
    --cc=zack@codesourcery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).