Re: Eliminate break/continue statements in loops

Martin Ward <>
Wed, 9 Dec 2009 12:16:08 +0000

          From comp.compilers

Related articles
Eliminate break/continue statements in loops (=?ISO-8859-1?Q?Roland_Lei=DFa?=) (2009-12-07)
Re: Eliminate break/continue statements in loops (Martin Ward) (2009-12-09)
Re: Eliminate break/continue statements in loops ( (2009-12-09)
| List of all articles for this month |

From: Martin Ward <>
Newsgroups: comp.compilers
Date: Wed, 9 Dec 2009 12:16:08 +0000
Organization: Compilers Central
References: 09-12-010
Keywords: analysis, optimize
Posted-Date: 10 Dec 2009 02:22:53 EST

On Monday 07 Dec 2009 12:32, Roland LeiCa wrote:
> I know that irreducible CFGs can be transformed to reducible ones by
> node splitting. So I don't have to worry about cross edges if I
> implement that. But my question is whether there has been done some
> research to eliminate continue and break statements out of loops so an
> equivalent program results which does only make use of simple loops.

I have done some work on this, but it has not been published
(except as source code: see below).

The WSL language includes loops with multiple EXITs, where an EXIT(n)
statement terminates the n enclosing nested loops. So this is the same
as a multi-level break statement. Note that the "n" in EXIT(n) must be
a positive integer: not a variable or an expression.

A continue statement can be implemented using EXITs by doubling the loop
if necessary. For instance:

DO ...
      ... OD


DO DO ...
            ... OD OD

where all the original EXIT(n) statements in the loop are incremented
to EXIT(n+1), to ensure that they terminate the same number of enclosing
nested loops.

In the FermaT transformation system, WSL is compiled into Scheme
which in turn is compiled into C using the Hobbit Scheme compiler.
The hobbit compiler generally produces very efficient C code,
but does not compile call-with-current-continuation efficiently
(and this is used to implement loops with EXIT statements).

So the transformation Floop_To_While is applied before compiling
to transform all Floops (loops with EXITs) to equivalent WHILE loops:
possibly using a flag variable if necessary.

Note that in the worst case, this transformation (as with node splitting
in general) can lead to an exponential growth in the size of the program.

The FermaT source code is available here:


STRL Senior Research Fellow and Royal Society Industry Fellow Erdos number: 4
Mirrors: and

Post a followup to this message

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