Download presentation
Presentation is loading. Please wait.
1
CMPUT 680 - Compiler Design and Optimization1 CMPUT680 - Winter 2006 Topic H: SSA for Predicated Code José Nelson Amaral http://www.cs.ualberta.ca/~amaral/courses/680
2
CMPUT 680 - Compiler Design and Optimization2 Reading Material Stoutchinin, A., Ferriere, F. de, “Efficient Static Assignment Form for Predication,” 34th Annual International Symposium on Microarchitecture, Dec. 2001, Austin, TX, pp.172-181
3
CMPUT 680 - Compiler Design and Optimization3 Motivation There are efficient algorithms based on SSA for: - constant propagation - partial redundancy elimination - induction variable recognition - etc Traditionally compilers apply the following steps: 1. Convert to SSA 2. Apply common optimizations 3. Convert out of SSA 4. Perform If-conversion 5. Do non-SSA optimization of if-converted code.
4
CMPUT 680 - Compiler Design and Optimization4 Problem In conventional SSA, the code transformation is: b = rand() b>a? b = qb = b+3 f = b*2 b1 = rand() b1>a? b2 = qb3 = b1+3 b4= (b2,b3) f = b4*2
5
CMPUT 680 - Compiler Design and Optimization5 Problem (cont.) After if conversion we have: b = rand() b>a? b = qb = b+3 f = b*2 b = rand() p1, p2 = b>a? p1: b = q p2: b = b+3 f = b*2
6
CMPUT 680 - Compiler Design and Optimization6 Problem (cont.) b1 = rand() p1, p2 = b1>a? p1: b2 = q b3 = ?? p2: b4 = b3+3 b5 = ?? f = b5*2 How to account for the multiple values produced for a variable in the same control path under SSA?
7
CMPUT 680 - Compiler Design and Optimization7 -SSA Stoutchinin defines the -SSA, a simple extension of the -SSA. In -SSA the operands of a -function indicate which predicated definition reaches a given point in the program.
8
CMPUT 680 - Compiler Design and Optimization8 Example x is live-in 1: g1?x = 2 2: g1? = x 3: g2?x = z 4: = x 5: g3?x = v 6: g4?x = w 7:g5 = g3 | g4 8: g5? = x x is dead g? operation is active when g is true g! operation is active when g’s complement is true
9
CMPUT 680 - Compiler Design and Optimization9 Example x is live-in 1: g1?x = 2 2: g1? = x 3: g2?x = z 4: = x 5: g3?x = v 6: g4?x = w 7:g5 = g3 | g4 8: g5? = x x is dead g? operation is active when g is true g! operation is active when g’s complement is true What is the value for this use of x?
10
CMPUT 680 - Compiler Design and Optimization10 Example x is live-in 1: g1?x = 2 2: g1? = x 3: g2?x = z 4: = x 5: g3?x = v 6: g4?x = w 7:g5 = g3 | g4 8: g5? = x x is dead g? operation is active when g is true g! operation is active when g’s complement is true What is the value for this use of x? Depends on the values of g1 and g2. How do you represent this dependence in -SSA? You can’t.
11
CMPUT 680 - Compiler Design and Optimization11 Example x is live-in 1: g1?x = 2 2: g1? = x 3: g2?x = z 4: = x 5: g3?x = v 6: g4?x = w 7:g5 = g3 | g4 8: g5? = x x is dead g? operation is active when g is true g! operation is active when g’s complement is true x2 = (x0, x1) 1: g1?x3 = 2 x4 = (x2, x3) 2: g1? = x4 3: g2?x5 = z x6 = ?? 4: = x6 5: g3?x = v 6: g4?x = w 7:g5 = g3 | g4 8: g5? = x x is dead x0 =x1 =
12
CMPUT 680 - Compiler Design and Optimization12 Example x is live-in 1: g1?x = 2 2: g1? = x 3: g2?x = z 4: = x 5: g3?x = v 6: g4?x = w 7:g5 = g3 | g4 8: g5? = x x is dead g? operation is active when g is true g! operation is active when g’s complement is true x2 = (x0, x1) 1: g1?x3 = 2 x4 = (x2, x3) 2: g1? = x4 3: g2?x5 = z x6 = (x2, x3, x5) 4: = x6 5: g3?x = v 6: g4?x = w 7:g5 = g3 | g4 8: g5? = x x is dead x0 =x1 = The original values are used, not the ones generated by -functions.
13
CMPUT 680 - Compiler Design and Optimization13 Example x is live-in 1: g1?x = 2 2: g1? = x 3: g2?x = z 4: = x 5: g3?x = v 6: g4?x = w 7:g5 = g3 | g4 8: g5? = x x is dead g? operation is active when g is true g! operation is active when g’s complement is true x2 = (x0, x1) 1: g1?x3 = 2 x4 = (x2, x3) 2: g1? = x4 3: g2?x5 = z x6 = (x2, x3, x5) 4: = x6 5: g3?x7 = v 6: g4?x8 = w x9 = ?? 7:g5 = g3 | g4 8: g5? = x9 x9 is dead x0 =x1 =
14
CMPUT 680 - Compiler Design and Optimization14 Example x is live-in 1: g1?x = 2 2: g1? = x 3: g2?x = z 4: = x 5: g3?x = v 6: g4?x = w 7:g5 = g3 | g4 8: g5? = x x is dead g? operation is active when g is true g! operation is active when g’s complement is true x2 = (x0, x1) 1: g1?x3 = 2 x4 = (x2, x3) 2: g1? = x4 3: g2?x5 = z x6 = (x2, x3, x5) 4: = x6 5: g3?x7 = v 6: g4?x8 = w x9 = (x2, x3, x5, x7, x8) 7:g5 = g3 | g4 8: g5? = x9 x9 is dead x0 =x1 =
15
CMPUT 680 - Compiler Design and Optimization15 Example: Optimizations x2 = (x0, x1) 1: g1?x3 = 2 x4 = (x2, x3) 2: g1? = x4 3: g2?x5 = z x6 = (x2, x3, x5) 4: = x6 5: g3?x7 = v 6: g4?x8 = w x9 = (x2, x3, x5, x7, x8) 7:g5 = g3 | g4 8: g5? = x9 x9 is dead x0 =x1 = x2 = (x0, x1) 1: g1?x3 = 2 x4 = (x2, x3) x10 = (x3) 2: g1? = x10 3: g2?x5 = z x6 = (x2, x3, x5) 4: = x6 5: g3?x7 = v 6: g4?x8 = w x9 = (x2, x3, x5, x7, x8) 7:g5 = g3 | g4 8: g5? = x9 x9 is dead x0 =x1 = X4 is only used if the assignment to x3 happens.
16
CMPUT 680 - Compiler Design and Optimization16 Example: Optimizations x2 = (x0, x1) 1: g1?x3 = 2 x10 = (x3) 2: g1? = x10 3: g2?x5 = z x6 = (x2, x3, x5) 4: = x6 5: g3?x7 = v 6: g4?x8 = w x9 = (x2, x3, x5, x7, x8) 7:g5 = g3 | g4 8: g5? = x9 x9 is dead x0 =x1 = x2 = (x0, x1) 1: g1?x3 = 2 x10 = (x3) 2: g1? = x10 3: g2?x5 = z x6 = (x2, x3, x5) 4: = x6 5: g3?x7 = v 6: g4?x8 = w x9 = (x2, x3, x5, x7, x8) x11 = (x7,x8) 7:g5 = g3 | g4 8: g5? = x11 x11 is dead x0 =x1 = G5 = g3|g4, thus x9 is only used if either x7 or x8 are defined.
17
CMPUT 680 - Compiler Design and Optimization17 Example: Optimizations x2 = (x0, x1) 1: g1?x3 = 2 x10 = (x3) 2: g1? = x10 3: g2?x5 = z x6 = (x2, x3, x5) 4: = x6 5: g3?x7 = v 6: g4?x8 = w x11 = (x7,x8) 7:g5 = g3 | g4 8: g5? = x11 x11 is dead x0 =x1 = x2 = (x0, x1) 1: g1?x3 = 2 x10 = (x3) 2: g1? = x3 3: g2?x5 = z x6 = (x2, x3, x5) 4: = x6 5: g3?x7 = v 6: g4?x8 = w x11 = (x7,x8) 7:g5 = g3 | g4 8: g5? = x11 x11 is dead x0 =x1 =
18
CMPUT 680 - Compiler Design and Optimization18 Example: Optimizations x2 = (x0, x1) 1: g1?x3 = 2 2: g1? = x3 3: g2?x5 = z x6 = (x2, x3, x5) 4: = x6 5: g3?x7 = v 6: g4?x8 = w x11 = (x7,x8) 7:g5 = g3 | g4 8: g5? = x11 x11 is dead x0 =x1 = x2 = (x0, x1) 1: g1?x3 = 2 2: g1? = x3 3: g2?x5 = z x6 = (x2, x3, x5) 4: = x6 5: g3?x7 = v 6: g4?x8 = w x11 = (x7,x8) 7:g5 = g3 | g4 8: g5? = x11 x11 is dead x0 =x1 = Assuming that g1 + g2 = 1
19
CMPUT 680 - Compiler Design and Optimization19 Example: Optimizations 1: g1?x3 = 2 2: g1? = x3 3: g2?x3 = z 4: = x3 5: g3?x7 = v 6: g4?x7 = w 7:g5 = g3 | g4 8: g5? = x7 x3 and x7 are dead x0 =x1 = x2 = (x0, x1) 1: g1?x3 = 2 2: g1? = x3 3: g2?x5 = z x6 = (x3, x5) 4: = x6 5: g3?x7 = v 6: g4?x8 = w x11 = (x7,x8) 7:g5 = g3 | g4 8: g5? = x11 x11 is dead x0 =x1 = Translating out of SSA.
20
CMPUT 680 - Compiler Design and Optimization20 -Functions Only the first operand of a -function can correspond to a non-predicated (eg. a -function) or an unconditional assignment. -function operands that are defined by another -function are inlined into the operand list. This inlining allows for the de-serialization of the -functions, and for the reordering of predicate code.
21
CMPUT 680 - Compiler Design and Optimization21 -Functions Given a -function (x 1, x 2, …, x k ), the operands x 1, x 2, … x k are defined in a single control flow path, and their order from left to right is the program order of the assignments to these variables. The value of (x 1, x 2, …, x k ) is the value of the operand whose assignment is executed the last at runtime.
22
CMPUT 680 - Compiler Design and Optimization22 Placement of -Functions The introduction of -functions does not affect the semantics of -functions. Thus in a predicated code, the -functions are inserted first to take care of the predicated assignments and then the usual SSA renaming with -functions takes place. The -functions can be placed during the Cytron-Ferrante placement algorithm.
23
CMPUT 680 - Compiler Design and Optimization23 -Congruence Two variables x and y are congruent to each other, if (i) they are referenced in the same -function; or (ii) there exist a variable z such that x is congruent to z and z is congruent to y. When translating out of -SSA, all the variables in a -congruent class can be replaced by a single temporary name.
24
CMPUT 680 - Compiler Design and Optimization24 -Congruence Order Given two variables x and y, x precedes y in congruence order, x c y, if: (i) x is an argument in a -function that defines y, or (ii) the definitions of x and y may be active at the same execution, and (a) x precedes y in the argument list of some -function, or (b) there is a variable z such that (1) x precedes z for some -function, and (2) z precedes y in (the same or another) - function.
25
CMPUT 680 - Compiler Design and Optimization25 -Congruence Order The -Congruence Order defines a partial order on the statements that define variables. This partial order must be maintained when translating out of -SSA in order to preserve the correct semantic of the program.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.