Static single assignment: not all possible paths define a variable - how to insert a PHI?

I am implementing the SSA construct for the compiler that I am writing. There is something about SSA that I don’t understand (using the Cytron article and the book "Modern Implementation of the Java Compiler", second edition of AW Appel). What to do if the variable y defined for the first time (and used) in one direct path of the control flow, but never defined in another parallel path. Should I embed a PHI function at the junction point (block dominance border defining y )?

 x = 1; // A if (P) // A y = x + 1; // B y = y + 1; // B x = x + 1; // C return; // C 

For example, in block B there is a first definition of y . Should I insert a PHI instruction at the beginning of block C with two operands (one for each incoming control flow)? Then, when renaming SSA: how would I name an operand coming from path A -> C (not through B), where y never defined?

 Entry --- A --------- C --- Exit \ / \-- B --/ 
+4
source share
1 answer

After reading the materials again, I found a small allusion to the book "Modern Implementation of the Compiler" in Java, the second edition - AW Applet on the implicit definition of the variable c0 . A further search showed that the algorithms expect that all variables have an implicit definition immediately before the first base block. This implicit definition is the fact that the variable is a global, parameter, or uninitialized variable.

Adding this implicit definition solves my problem and the example will look like this:

 x1 = 1; // A if (P) // A y1 = x1 + 1; // B y2 = y1 + 1; // B y3 = Ο†(y0, y2) // C x2 = x1 + 1; // C return; // C 
+3
source

Source: https://habr.com/ru/post/1413545/


All Articles