Printincrease printdone printdone winter 2013 uw

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: + 2*a*b (above). –  Pros: Saves space, makes common subexpressions explicit. –  Cons: If want to change just one occurence, need to split off. If variable value may change between [email protected], may not want to treat as common. Winter 2013 UW CSE 401 (Michael Ringenburg) 14 Control Flow Graph (CFG) CSE341: CSE341: Programming Languages •  Nodes are Basic Blocks Programming Languages –  Code that always executes Logether (i.e., no branches Lecture 1 t ecture 1 into or out of the middle of the block). Course Course Mechanics Mechanics –  I.e., “straightline code” Variable Bindings ML ML Variable Bindings •  Edges represent paths that control flow could Dan Grossman take. Dan Grossman Fall 2011 –  I.e., possible [email protected] orderings. Fall 2011 –  Edge from Basic Block A to Basic Block B means Block B could execute immediately aher Block A completes. •  Required for much of the analysis done in the [email protected] Winter 2013 UW CSE 401 (Michael Ringenburg) 15 CFG Example print(“hello”);SE341: Programming Languages ! C! CSE341: Programming Languages print(“hello”); a = 7;! a = 7; Lecture 1 ! L if (x == y) {! ecture 1 Course Mechanics if (x == y)! print(“equal”);! Course Mechanics ML Variable Bindings M b = 9;! L Variable Bindings print(“equal”);! b = 10;! } else {! b = 9;! Dan Grossman Dan Grossman b = 10;! Fall 2011 Fall 2011 }! while (a < b)! while (a < b) {! a++;! a++;! print(“increase”);! print(“increase”);! }! print(“done”);! print(“done”);! Winter 2013 UW CSE 401 (Michael Ringenburg) 22 CFG Example print(“hello”);SE341: Programming Languages ! C! CSE341: Programming Languages print(“hello”); a = 7;! a = 7; Lecture 1 ! L if (x == y) {! ecture 1 Note: There are variations in how function calls!in Course Mechanics if (x == y) print(“equal”);! Course Mechanics basic blocks are treated. LIt may depend on the level M Variable Bindings M b = 9;! L Variable Bindings of abstraction of the IR, as print(“equal”);! well as the semantics of = 10;! b } else {! b = 9;! the language. DForGrossman Dif aGrossman may throw example, an function an b = 10;! Fall 2011 an exception, the all 2011 F call should terminate the basic b)! }! block (since there is no guaranteewhile (a <will that the call while (a < b) {! return to the same point). In low-level IRs, calls a++;! a++;! may also terminate blocks. print(“increase”);! print(“increase”);! }! print(“done”);! print(“done”);! Winter 2013 UW CSE 401 (Michael Ringenburg) 23 (Program/Data) Dependence Graph CSE341: Programming CSE341: Programming with another IR. •  Ohen used in [email protected] Languages Languages •  In a data dependence g1 Lecture between nodes Lecture raph, edges 1 represent Cdependencies” between the code “ ourse Mechanics Mechanics Course represented by those ML Variable Bindings nodes. ML Variable Bindings –  If A and B access the same data, and A must...
View Full Document

This document was uploaded on 04/04/2014.

Ask a homework question - tutors are online