The Gateway to Computer Science Excellence
+8 votes
814 views

Give Equivalent SSA.

in Compiler Design by Boss (25.6k points)
edited by | 814 views
0
@Arjun sir plz help here ...
+1
what is SSA ?
0
Is this topic in syllabus ? If so under which portion ? My coaching institute didn't teach any questions like this :(
0
compiler ! in syllabus...

1 Answer

+6 votes
Best answer

SSA requires that each variable is assigned exactly once,i.e, the variable cannot be repeated on the LHS of assignment.

For the above Code Snippet, Equivalent SSA is

R1 = 5
R2 = R1 - 3

/* In the Below lines Y may have either R3 or R5 depending on which block executes,
But just that there blocks are different and at a time only one Block executes does not mean,
that they have a same value R3 in both the blocks */

if (R2 < 3)               // This is not LHS of assignment, hence same LHS
{
    R3 = R2 * 2        // Here, Y same but due to SSA, LHS must be different
    R4 = R3
}
else
{
    R5 = R2 - 3        //Here, Y same but due to SSA, LHS must be different
}

/* In the Below lines Y may have either R3 or R5 depending on which block executes */

R6 = (R3,R5) 
R7 = R2 - R6           
R8 = R2 + R7         
by Veteran (50.9k points)
selected by
0
R6 = R2 - (R3,R5) but how to know which one should we need to take R3 or R5 ??

one more dout ,

int sum=0;

for (i=0;i<10;i++)

{

  sum =sum + i;         

}

how to convert into SSA ??
0

That depends on which block is accessed, either IF or ELSE and that respective value is used.


In your second question, if I write as

Sum 1 = 0 ;
Sum 2 = Sum 1 + i ;
Sum 3 = Sum 2 + i ;
..
..
..
..
Sum 9 = Sum 8 + i ;

Then, also Compiler will have no problem in evaluating the sum of 10 consecutive terms, just that it is now SSA, a refined version of TAC.  

0
"That depends on which block is accessed, either IF or ELSE and that respective value is used."

Since IF and ELSE both having different variable so how can we identify which need to use??

How can it track ??? I think here we need one more variable...
0

Yes, you can take one more variable, just care has to be taken that it does not violates SSA.

Something like R6 = (R3,R5) 

Now, R6 will have either value.

Actually, U R right, ẃriting it as

 R6 = R2 - (R3,R5) violates TAC. I''ll edit it.

0
i think r8 should be r2+r3 . otherwise result will be wrong
0
How !! Any reason for that ?
0

even though wiki says that its 8 register https://en.wikipedia.org/wiki/Static_single_assignment_form

I think we can actually use the same variabe for y in both block as only one case is going to hit at a time. so no need of the phi function, nor the defination of ssa is voilated. @arjun

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,292 answers
198,237 comments
104,920 users