Composing Dataflow Analyses and Transformations

download Composing Dataflow Analyses and Transformations

of 58

  • date post

    11-Feb-2016
  • Category

    Documents

  • view

    21
  • download

    0

Embed Size (px)

description

Composing Dataflow Analyses and Transformations. Sorin Lerner (University of Washington) David Grove (IBM T.J. Watson) Craig Chambers (University of Washington). const prop followed by unreachable code elimination. const prop again. Phase ordering problem. - PowerPoint PPT Presentation

Transcript of Composing Dataflow Analyses and Transformations

  • Composing Dataflow Analyses and TransformationsSorin Lerner (University of Washington)David Grove (IBM T.J. Watson)Craig Chambers (University of Washington)

  • Phase ordering problemOptimizations can interact in mutually beneficial ways, and no order exploits all of these interactions.Classic example: constant propagation and unreachable code elimination.x := 11;if (x == 11) { DoSomething();}else { DoSomethingElse(); x := x + 1;}y := x; // value of y?x := 11;DoSomething();y := x;// value of y?x := 11;DoSomething();y := 11;true

  • One known solution: Iterate individual analyses until the results dont changex := 11;do { if (x == 11) { DoSomething(); } else { DoSomethingElse(); x := x + 1; }} while (...)y := x; // value of y?Compiler is slow.In the presence of loops in the source program, might not yield best possible results.

  • Another known solution: hand writtensuper-analysisLose modularity:difficult to write, reuse, and extend such analysesExamples:conditional constant propagation [Wegman and Zadeck 91]class analysis, splitting and inlining [Chambers and Ungar 90]const prop and pointer analysis [Pioli and Hind 99]

  • Ideally...... we want to:Write analyses modularlyExploit mutually beneficial interactionsHave a fast compilerWe present a framework that achieves this.

  • The key to modular compositionTraditionally, optimizations are defined in two parts:A dataflow analysis.Rules for transforming the program representation after the analysis is solved.

    The key insight is to merge these two parts:Dataflow functions return either a dataflow value OR a replacement graph with which to replace the current statement.

  • RoadmapSeveral small examples that show how flow functions workOne large example that shows how modular analyses are automatically composed togetherOverview of the theory behind the frameworkExperimental validation

  • Flow function returning a dataflow valuey := 5

  • Flow function returning a dataflow valuey := 5[ ... ][ ..., y 5]PROPAGATE

  • Flow function returning a replacement graphy := x+2

  • Flow function returning a replacement graph[x 3]y := x+2[x 3]ReplacementgraphStep 1: Initialize input edges with dataflow information

  • Flow function returning a replacement graphy := x+2[x 3][x 3]PROPAGATE[x 3, y 5]Step 2: Perform recursive dataflow analysis on the replacement graphStep 1: Initialize input edges with dataflow information

  • Flow function returning a replacement graphy := x+2[x 3][x 3]PROPAGATE[x 3, y 5][x 3, y 5]Step 2: Perform recursive dataflow analysis on the replacement graphStep 1: Initialize input edges with dataflow informationStep 3: Propagate dataflow information from output edges.

  • Flow function returning a replacement graphy := x+2[x 3][x 3, y 5]Replacement graphs:used to compute outgoing dataflow information for the current statement.

    Replacement graphs:used to compute outgoing dataflow information for the current statement.a convenient way of specifying what might otherwise be a complicated flow function.

  • Flow function returning a replacement graphy := x+2[x 3][x 3, y 5]Soundness requirement:Replacement graph must have the same concrete semantics as the original statement, but only on concrete inputs that are consistent with the current dataflow facts.

  • Flow function returning a replacement graphy := x+2[x 3][x 3, y 5]Lets assume weve reached a fixed point.

  • Flow function returning a replacement graphy := x+2[x 3][x 3, y 5]y := 5Lets assume weve reached a fixed point.

  • Flow function returning a replacement graphy := 5[x 3][x 3, y 5]Replacement graphs:used to transform the program once a fixed point has been reached.Lets assume weve reached a fixed point.

  • Iterative analysis exampley := x+2[x 3, y 5][x 3][x T]Now, lets assume we havent reached a fixed point.

  • Iterative analysis exampley := x+2[x 3, y 5]PROPAGATE[x 3][x T][x T, y T]Now, lets assume we havent reached a fixed point.

  • Branch folding exampleif (x == 11)FT

  • Branch folding exampleif (x == 11)[x 11][x 11]FT

  • Branch folding exampleif (x == 11)[x 11][x 11][x 11]FT[x 11]

  • Branch folding exampleif (x == 11)[x 11]FT[x 11]

  • Composing several analyses

  • x := new Cmergeb := x instanceof Cx := new Dx := x.foo()mergewhile()if (b)TF

  • x := new Cb := x instanceof Cx := new Dx := x.foo()if (b)PROPAGATEwhile()PROPAGATEPROPAGATE[x T][x {C}]TmergemergeTFPROPAGATET

  • x := new Cb := x instanceof Cx := new Dx := x.foo()if (b)PROPAGATEwhile()PROPAGATEPROPAGATE[x T][x {C}]T([x T], [x {C}], T, T)mergemergePROPAGATETFTPROPAGATE

  • x := new Cb := x instanceof Cx := new Dx := x.foo()if (b)PROPAGATE([x T], [x {C}], T, T)([x T], [x {C}], T, T)while()mergemergeTF

  • x := new Cb := x instanceof Cx := new Dx := x.foo()if (b)while()PROPAGATE[x T, b T]mergemergeTF([x T], [x {C}], T, T)([x T], [x {C}], T, T)

  • ([x T], [x {C}], T, T)x := new Cb := x instanceof Cx := new Dx := x.foo()if (b)([x T], [x {C}], T, T)while()[x T, b T]mergemergeTF([x T], [x {C}], T, T)

  • x := new Cb := x instanceof Cx := new Dx := x.foo()if (b)([x T], [x {C}], T, T)([x T], [x {C}], T, T)([x T], [x {C}], T, T)([x T, b true], [x {C}, b {Bool}], T, T)PROPAGATEwhile()mergemergeTF

  • ([x T, b true], [x {C}, b {Bool}], T, T)([x T, b true], [x {C}, b {Bool}], T, T)x := new Cb := x instanceof Cx := new Dx := x.foo()if (b)([x T], [x {C}], T, T)while()mergemergeTF([x T], [x {C}], T, T)([x T], [x {C}], T, T)

  • ([x T, b true], [x {C}, b {Bool}], T, T)x := new Cb := x instanceof Cx := new Dx := x.foo()if (b)Replacement graph is analyzed by composed analysis.When one analysis chooses a replacement graph, other analyses see it immediately.Analyses communicate implicitly through graph transformationswhile()mergemergeTF([x T], [x {C}], T, T)([x T], [x {C}], T, T)

  • x := new Cb := x instanceof Cx := new Dx := x.foo()if (b)([x T, b true], [x {C}, b {Bool}], T, T)while()mergemergeTF([x T], [x {C}], T, T)([x T], [x {C}], T, T)

  • x := new Cb := x instanceof Cx := new Dx := x.foo()if (b)([x T, b true], [x {C}, b {Bool}], T, T)while()mergemergeTF([x T], [x {C}], T, T)([x T], [x {C}], T, T)

  • x := new Cb := x instanceof Cx := new Dx := x.foo()if (b)([x T, b true], [x {C}, b {Bool}], T, T)while()mergemergeTF([x T], [x {C}], T, T)([x T], [x {C}], T, T)

  • x := new Cb := x instanceof Cx := new Dx := x.foo()if (b)while()mergemergeTF([x T, b true], [x {C}, b {Bool}], T, T)([x T], [x {C}], T, T)([x T], [x {C}], T, T)

  • x := new Cb := x instanceof Cx := new Dx := x.foo()if (b)([x T, b true], [x {C}, b {Bool}], T, T)while()mergemergeTF([x T, b true], [x {C}, b {Bool}], T, T)([x T], [x {C}], T, T)([x T], [x {C}], T, T)

  • x := new Cb := x instanceof Cx := new Dx := x.foo()if (b)([x T], [x {C}], T, T)([x T], [x {C}], T, T)([x T, b true], [x {C}, b {Bool}], T, T)while()mergemergeTF([x T, b true], [x {C}, b {Bool}], T, T)

  • x := new Cb := x instanceof Cx := new Dx := x.foo()if (b)([x T], [x {C}], T, T)([x T], [x {C}], T, T)([x T, b true], [x {C}, b {Bool}], T, T)while()mergemergeTF([x T, b true], [x {C}, b {Bool}], T, T)

  • x := new Cb := x instanceof Cx := new Dx := x.foo()if (b)([x T, b true], [x {C}, b {Bool}], T, T)while()mergemergeTF([x T, b true], [x {C}, b {Bool}], T, T)([x T], [x {C}], T, T)([x T], [x {C}], T, T)

  • x := new Cb := x instanceof Cx := new Dx := x.foo()if (b)([x T, b true], [x {C}, b {Bool}], T, T)while()mergemergeTF([x T, b true], [x {C}, b {Bool}], T, T)([x T], [x {C}], T, T)([x T], [x {C}], T, T)

  • x := new Cb := x instanceof Cx := new Dx := x.foo()if (b)([x T, b true], [x {C}, b {Bool}], T, T)class C extends A { A foo() { return self; }}while()mergemergeFT([x T], [x {C}], T, T)([x T], [x {C}], T, T)([x T, b true], [x {C}, b {Bool}], T, T)

  • x := new Cb := x instanceof Cx := new Dx := x.foo()if (b)PROPAGATEwhile()mergemergeFT([x T, b true], [x {C}, b {Bool}], T, T)([x T], [x {C}], T, T)([x T], [x {C}], T, T)([x T, b true], [x {C}, b {Bool}], T, T)

  • x := new Cb := x instanceof Cx := new Dx := x.foo()if (b)while()mergemergeFT([x T, b true], [x {C}, b {Bool}], T, T)([x T], [x {C}], T, T)([x T], [x {C}], T, T)([x T, b true], [x {C}, b {Bool}], T, T)

  • x := new Cb := x instanceof Cx := new Dx := x.foo()if (b)while()mergemergeFT([x T], [x {C}], T, T)([x T], [x {C}], T, T)([x T, b true], [x {C}, b {Bool}], T, T)([x T, b true], [x {C}, b {Bool}], T, T)

  • x := new Cb := x instanceof Cx := new Dx := x.foo()if (b)while()mergemergeFT([x T, b true], [x {C}, b {Bool}], T, T)([x T], [x {C}], T, T)([x T], [x {C}], T, T)([x T, b true], [x {C}, b {Bool}], T, T)([x T, b true], [x {C}, b {Bool}], T, T)

  • ([x T, b true], [x {C}, b {Bool}], T, T)x := new Cb := x instanceof Cx := x.foo()if (b)while()mergemergeT([x T, b true], [x {C}, b {Bool}], T, T)([x T, b true], [x {C}, b {Bool}], T, T)([x T], [x {C}], T, T)([x T], [x {C}], T, T)x := new DF

  • x := new Cb := x instanceof Cx := x.foo()if (b)PROPAGATE([x T, b true], [x {C}, b {Bool}], T , T)while()mergemerge