Re: Basic blocks and CFG

Diego Novillo <>
Tue, 17 Mar 2009 09:45:22 -0400

          From comp.compilers

Related articles
Basic blocks and CFG (lican) (2009-03-16)
Re: Basic blocks and CFG (Diego Novillo) (2009-03-17)
Re: Basic blocks and CFG (kamal) (2009-03-17)
| List of all articles for this month |

From: Diego Novillo <>
Newsgroups: comp.compilers
Date: Tue, 17 Mar 2009 09:45:22 -0400
Organization: Compilers Central
References: 09-03-078
Keywords: analysis, AST
Posted-Date: 17 Mar 2009 17:05:33 EDT

On Mon, Mar 16, 2009 at 22:22, lican <> wrote:

> Does anyone know if it is possible to build basic blocks without
> generating IR, directly from an AST? I find it rather difficult.

In general, it is not possible because you will have basic blocks with
multiple control flow paths inside. At the very least, you should
factor the ASTs so that each node contains no control side effects.
This means decomposing all the statements in your language that affect
control flow so that they are isolated in a single AST node. For
instance, using C's ?: operator

x = f ? u : v

decompose into

if (f)
    t.1 = u
    t.1 = v
x = t.1

Your next problem will be additional side-effects in expressions. If
you are going to do analysis and optimizations on your AST, having
expressions with side-effects will complicate matters (e.g., x = b++ *

Once you start down this road, you will very quickly converge into
some variant of 3-address representations. You can still keep using
your AST, you just apply stricter and stricter syntax requirements on


Post a followup to this message

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