1 / 12

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. Operate on sparse graph (SSA)

arnold
Download Presentation

Objectives

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

  2. Constant Propagation • Operate on sparse graph (SSA) • Incorporate branch folding • Meet operations at -nodes

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

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

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

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

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

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

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

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

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

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

More Related