1 / 11

CS 201 Compiler Construction

CS 201 Compiler Construction. Lecture 10 SSA-Based Sparse Conditional Constant Propagation. Conditional Constant Propagation. SSA-based algorithm is faster than the previous algorithm that was presented earlier.

feleti
Download Presentation

CS 201 Compiler Construction

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 201Compiler Construction Lecture 10 SSA-Based Sparse Conditional Constant Propagation

  2. Conditional Constant Propagation SSA-based algorithm is faster than the previous algorithm that was presented earlier. Basic Idea: Use SSA-edges for faster propagation of constants from definitions to uses.

  3. Contd.. Handling Executable vs Non-Executable Edges • At ϕ-functions non-executable operands have lattice value of top-undef- • This allows conditional constant propagation. • Process nodes only when they are known to be executable. • Non-executable SSA edges will transmit

  4. Contd.. When can we process a SSA edge ? • When we know the destination of the edge is executable. • Destination statement is executable when at least one of the incoming control flow edge is executable. Justification: In SSA form ecah use receives value from only one definition. Thus, no matter how we get to the use it will get the value from the same SSA-edge.

  5. Contd.. Maintain two worklists: FlowWorkList (for control flow edges) SSAWorkList (for SSA edges) • Initialize: FlowWorkList  Edges leaving the entry node. SSAWorkList  {} ExecutableFlag(FlowEdge)False Lattice cells initialized to UNDEF or top 2. Halt execution when both worklists are empty. Execution may proceed by processing edges from either worklist.

  6. Contd.. 3. if e is CFG-edge from FlowWorkList then if ExecutableFlag(e)=false then ExecutableFlag(e) = true Perform Visitϕ for all ϕ-nodes at destination node. if only one incoming CFG-edges is TRUE (i.e., this this is the first visit to the node) then Perform VisitExpression at the node if the node contains one outgoing CFGedge then add the edge to FlowWorkList

  7. Contd.. 4. if e is SSA-edge from SSAWorkList then if destination of e is a ϕ-node then Perform Visitϕ elseif destination of e is an expression then examine ExecutableFlags for the CFG edges reaching that node and if any one flag is true then perform VisitExpression.

  8. Contd.. Visitϕ For each operand in the ϕ-node examine the ExecutableFlag of the corresponding CFG-edge and set the operand’s lattice value as follows: CFG-edge executable  lattice value same as lattice value at the definition edge of the SSA-edge. CFG-edge non-executable lattice value is UNDEF or top. Compute the lattice value of the variable on the left hand side.

  9. Contd.. VisitExpression Evaluate lattice value of the expression using lattice values of operands from places where they were defined. If lattice value changes then if expression is part of an assignment statement then add SSA-edge starting from left hand side to SSAWorkList elseif expression is conditional/predicate then based upon the result add appropriate CFG-edges to the FlowWorkList: TRUEtrue edge; FALSEfalse edge; and bottom  both edges.

  10. Def-Use Edges vs SSA-edges executable executable executable We cannot take advantage of non-executable edges if def-use edges are used for propagation. Why? Because def-use chains include def-use edges formed through non-executable edges.

  11. Def-Use Edges vs SSA-edges Algorithm based upon Def-Use chains will be less efficient. SSA-based algorithm: Time spent is proportional to number of SSA-edges. Number of SSA-edges per variable is O(N) where N is the number of statements. Therefore time complexity is O(NxV) where V is the number of variables. Def-Use based algorithm: There can be O(N) definitions and uses of one variable. Thus, number of def-use edges is O(N2) and hence the time complexity is O(N2xV).

More Related