Objectives
Download
1 / 12

Objectives - PowerPoint PPT Presentation


  • 68 Views
  • Uploaded on

Objectives. Identify advantages (and disadvantages ?) of optimizing in SSA form Given a CFG in SSA form, perform Global Constant Propagation Dead code elimination Global Value Numbering Conversion of SSA back to CFG form. Constant Propagation. Operate on sparse graph (SSA)

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Objectives ' - arnold


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Objectives
Objectives

  • Identify advantages (and disadvantages ?) of optimizing in SSA form

  • Given a CFG in SSA form, perform

    • Global Constant Propagation

    • Dead code elimination

    • Global Value Numbering

    • Conversion of SSA back to CFG form


Constant propagation
Constant Propagation

  • Operate on sparse graph (SSA)

  • Incorporate branch folding

  • Meet operations at -nodes


Evalstmt algorithm
EvalStmt Algorithm

EvalStmt( Stmt )

if Stmt is arithmetic or -node

evaluate Stmt

if result is “lowered”

foreach j  Uses (Stmt.Lval()))

propagate result

if j.block  Visited

Work = { j }

else if Stmt is a branch

foreach possible destination DB of Stmt

if Edge(Stmt, DB) not executable

mark Edge(Stmt, DB) executable

Blocks U= DB


Constant prop algorithm
Constant Prop Algorithm

Mark all CFG Edges not executable

Init node of SSA graph to T

Work = Visited = Ø

Blocks = {Entry}

While Work  Ø  Blocks Ø

While Work  Ø

Choose Stmt from Work

EvalStmt (Stmt)

While Blocks  Ø

Choose BB from Blocks

foreach Stmt in  (BB)

EvalStmt (Stmt)

if BB Visited

Visited = {BB}

foreach Stmt in  (BB)

EvalStmt (Stmt)


Dead code elimination
Dead Code Elimination

  • Use SSA to detect dead code

  • Method

    • Remove statement(s) that do not directly or indirectly use data observable outside the procedure

    • Eliminate branches never taken

    • Uses control dependence


Eliminatedeadcode
EliminateDeadCode ()

Worklist = Necessary = Ø

foreach BB  CFG

foreach StmtBB

if (Stmt defines external data )

(Stmt is and I/O instruction)

(Stmt is function call)

Necessary U= { Stmt }

WorkList U= { Stmt }

endif

endfor

endfor


Eliminate dead code algorithm
Eliminate Dead Code Algorithm

while Worklist  Ø

choose Stmt from Worklist

BB = Stmt’s basic block

foreach block, CB, upon which BB is control dependent

J = CB’s branch statement

Necessary U= J

Worklist U= J

foreach T  Stmt’s operands

Def = Stmt’s definition

Necessary U= {Def }

WorkList U= {Def }

foreach BB  CFG

foreach StmtinBB

if Stmt  Necessary

removeStmt

else if Stmt isa branch Stmt  Necessary

Stmt.target=ipdom(BB)


Global value numbering
Global Value Numbering

  • Apply value numbering at function scope

  • Associate a field (for value number) with each temporary.

  • Temps with same value number are =

  • No loops ==> reverse postorder traversal suffices (operands defined before used.)


Strongly connected components
Strongly Connected Components

  • What about loops ?

  • Value numbers for -nodes ambiguous

    • Assume best case

    • Iterate on the SCC in reverse postorder until no further changes


Processing nodes
Processing -nodes

  • If -node has a value number, VN, assign VN to temp defined by -node

  • Consider operands with non-Null value numbers: If two have different values, assign a new value for -node.

  • If all operands have same value number assign that to temp defined by -node


Efficiency refinements
Efficiency Refinements

  • If -node has non-Null value number different from its operands, don’t need a new value number

  • For SCC, use a temp value number table called scratch table. Once that table “stabilizes”, copy to value table.


Ssa to cfg
SSA to CFG

  • -nodes “not executable” directly

  • Must convert SSA back to CFG

  • “Semantics” of -nodes is that they are “executed” simultaneously upon entry to block

  • Insert code for each operand of -node in appropriate predecessor block.


ad