GCC questions
Radu Cornea
radu@ics.uci.edu
Tue Aug 31 23:20:00 GMT 1999
>>On Tue, 3 Aug 1999, Mike Stump wrote:
> > Date: Tue, 3 Aug 1999 16:57:50 -0700 (PDT)
> > From: Radu Cornea <radu@ics.uci.edu>
>
...
> > 5. I am asking these questions because I need to solve this problem in gcc:
> > in some cases, gcc transforms initial structured code into unstructured
> > code. This happens for example for if statements that have as condition
> > logical OR (||) or AND (&&) expressions. In order to generate structured
> > code, the then-statement have to be duplicated (as many times as the number
> > of ORs or ANDs). For this, i need to save somehow the then-statement tree
> > when it is generated and duplicate it (and of course, the jumps need to be
> > changed).
>
> Ok, too bad you didn't say exactly what you wanted to do. Sounds like
> it is mostly outside the scope of compilation though. We can give
> better answers to your question, if the question is the right
> question. Tell us what you really want to do...
>
> I think what you want is an full function ast, that preserves
> constructs like if and while. If that is it, then if you can use just
> C++, then you might consider turning on the template code everywhere,
> and munching on it instead. In that style of code we preserve things
> like:
>
> DEFTREECODE (DECL_STMT, "decl_stmt", 'e', 3)
> DEFTREECODE (IF_STMT, "if_stmt", 'e', 3)
> DEFTREECODE (FOR_STMT, "for_stmt", 'e', 4)
> DEFTREECODE (WHILE_STMT, "while_stmt", 'e', 2)
> DEFTREECODE (DO_STMT, "do_stmt", 'e', 2)
> DEFTREECODE (RETURN_STMT, "return_stmt", 'e', 1)
> DEFTREECODE (BREAK_STMT, "break_stmt", 'e', 0)
> DEFTREECODE (CONTINUE_STMT, "continue_stmt", 'e', 0)
> DEFTREECODE (SWITCH_STMT, "switch_stmt", 'e', 2)
> DEFTREECODE (GOTO_STMT, "goto_stmt", 'e', 1)
>
> directly, and you can the walk that code and do what you want. But
> since I don't know what you want to do, I don't know if this is a
> solution to what you want to do.
>
I will try to explain what I am trying to do.
We are working here at a compiler that uses gcc (a modified version for
generating three-address code). Some optimizations and scheduling
techniques that we use work only if the code is what we call "structured".
In some situations, gcc transforms "structured code" into "unstructured".
I will explain below what we mean by that.
For e.g., for the C code:
...
if (a||b)
<x>;
else
<y>;
<z>;
...
(x, y and z are statements, a and b are expressions)
gcc generates something like this:
|
<a>
/ \
/ <b> This is what we call
| / \ "unstructured code"
[x] [y]
\ /
\ /
|
[z]
|
We want to get a code like this:
|
<a>
/ \
/ <b>
/ / \ This is what we call
[x] [x] [y] "structured code"
\ | / i.e. can be viewed
\ | / as an if inside
\ |/ another if.
\|
|
[z]
|
So, the [x] statement must be duplicated.
This problem happens only when the if condition is a OR or AND logical
expression (it is an optimization made by gcc).
If you have any idea how could I modify gcc to get that kind of code, I
would appreciate very much.
Thanks,
Radu.
--
Radu Cornea
Graduate Student
Information & Computer Science
University of California - Irvine
E-mail: radu@ics.uci.edu
More information about the Gcc
mailing list