1 / 12

# Objectives - PowerPoint PPT Presentation

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)

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

## PowerPoint Slideshow about 'Objectives' - arnold

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

• Given a CFG in SSA form, perform

• Global Constant Propagation

• Global Value Numbering

• Conversion of SSA back to CFG form

• Operate on sparse graph (SSA)

• Incorporate branch folding

• Meet operations at -nodes

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

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)

• 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

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

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)

• 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.)

• Value numbers for -nodes ambiguous

• Assume best case

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

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

• 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.

• -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.