SlideShare a Scribd company logo
1 of 87
Dataflow Analysis

Guido Wachsmuth




       Delft
                              Course IN4303, 2012/13
       University of
       Technology               Compiler Construction
       Challenge the future
Overview
today’s lecture

control flow graphs




                      Dataflow Analysis   2
Overview
today’s lecture

control flow graphs

data flow analyses

  •   liveness analysis
  •   reaching definitions
  •   available expressions




                              Dataflow Analysis   2
Overview
today’s lecture

control flow graphs

data flow analyses

  •   liveness analysis
  •   reaching definitions
  •   available expressions

non-local optimisations

  •   dead code elimination
  •   constant & copy propagation
  •   common subexpression elimination


                                         Dataflow Analysis   2
I
control-flow graphs




                      Dataflow Analysis   3
Intermediate language
quadruples

store                 jumps
   a ← b ⊕ c             L:
   a ← b                 goto L
                         if a ⊗ b
memory access
                              goto L1
   a ← M[b]
                         else
   M[a] ← b
                              goto L2
functions
   f(a1, …, an)
   b ← f(a1, …, an)

                                        Dataflow Analysis   4
Control-flow graphs
example

    a ← 0
L1: b ← a + 1
    c ← c + b
    a ← 2 * b
    if a < N
       goto L1
    else
       goto L2
L2: return c

                      Dataflow Analysis   5
Control-flow graphs
example

    a ← 0             a ← 0
L1: b ← a + 1
                      b ← a + 1
    c ← c + b
    a ← 2 * b         c ← c + b
    if a < N
       goto L1        a ← 2 * b

    else
                      if a < N
       goto L2
L2: return c          return c


                                  Dataflow Analysis   5
Control-flow graphs
terminology

              a ← 0


              b ← a + 1


              c ← c + b


              a ← 2 * b


              if a < N


              return c


                          Dataflow Analysis   6
Control-flow graphs
terminology

              a ← 0


node          b ← a + 1


              c ← c + b


              a ← 2 * b


              if a < N


              return c


                          Dataflow Analysis   6
Control-flow graphs
terminology

              a ← 0
                          in-edge
node          b ← a + 1


              c ← c + b


              a ← 2 * b


              if a < N


              return c


                              Dataflow Analysis   6
Control-flow graphs
terminology

              a ← 0
                          in-edge
node          b ← a + 1


              c ← c + b
                          in-edge
              a ← 2 * b


              if a < N


              return c


                              Dataflow Analysis   6
Control-flow graphs
terminology

predecessor   a ← 0
                          in-edge
node          b ← a + 1


              c ← c + b
                          in-edge
              a ← 2 * b


predecessor   if a < N


              return c


                              Dataflow Analysis   6
Control-flow graphs
terminology

predecessor   a ← 0
                          in-edge
node          b ← a + 1
                          out-edge
              c ← c + b
                          in-edge
              a ← 2 * b


predecessor   if a < N


              return c


                              Dataflow Analysis   6
Control-flow graphs
terminology

predecessor   a ← 0
                          in-edge
node          b ← a + 1
                          out-edge
successor     c ← c + b
                          in-edge
              a ← 2 * b


predecessor   if a < N


              return c


                              Dataflow Analysis   6
II
liveness analysis




                    Dataflow Analysis   7
Liveness analysis
terminology

              a ← 0


              b ← a + 1


              c ← c + b


              a ← 2 * b


              if a < N


              return c


                          Dataflow Analysis   8
Liveness analysis
terminology

definition    a ← 0


              b ← a + 1


              c ← c + b


              a ← 2 * b


              if a < N


              return c


                          Dataflow Analysis   8
Liveness analysis
terminology

definition    a ← 0


usage         b ← a + 1


              c ← c + b


              a ← 2 * b


              if a < N


              return c


                          Dataflow Analysis   8
Liveness analysis
terminology

definition    a ← 0


usage         b ← a + 1


              c ← c + b


definition    a ← 2 * b


              if a < N


              return c


                          Dataflow Analysis   8
Liveness analysis
terminology

definition    a ← 0


usage         b ← a + 1


              c ← c + b


definition    a ← 2 * b


usage         if a < N


              return c


                          Dataflow Analysis   8
Liveness analysis
terminology

definition    a ← 0


usage         b ← a + 1


              c ← c + b


definition    a ← 2 * b

                                 live-in
usage         if a < N


              return c


                          Dataflow Analysis   8
Liveness analysis
terminology

definition    a ← 0


usage         b ← a + 1


              c ← c + b


definition    a ← 2 * b
                          live-out

                                     live-in
usage         if a < N


              return c


                              Dataflow Analysis   8
Liveness analysis
terminology

definition    a ← 0

                          live-in
usage         b ← a + 1


              c ← c + b


definition    a ← 2 * b
                          live-out

                                      live-in
usage         if a < N


              return c


                               Dataflow Analysis   8
Liveness analysis
terminology

definition    a ← 0

                          live-in
usage         b ← a + 1


              c ← c + b


definition    a ← 2 * b
                          live-out

                                      live-in
usage         if a < N
                          live-out

              return c


                               Dataflow Analysis   8
Liveness analysis
terminology

definition    a ← 0       live-out

                          live-in
usage         b ← a + 1


              c ← c + b


definition    a ← 2 * b
                          live-out

                                      live-in
usage         if a < N
                          live-out

              return c


                               Dataflow Analysis   8
Liveness analysis
example

             a ← 0


             b ← a + 1


             c ← c + b


             a ← 2 * b


             if a < N


             return c


                         Dataflow Analysis   9
Liveness analysis
example

             a ← 0


             b ← a + 1


             c ← c + b


             a ← 2 * b


             if a < N


             return c


                         Dataflow Analysis   9
Liveness analysis
example

             a ← 0


             b ← a + 1


             c ← c + b


             a ← 2 * b


             if a < N


             return c


                         Dataflow Analysis   9
Liveness analysis
example

             a ← 0


             b ← a + 1


             c ← c + b


             a ← 2 * b


             if a < N


             return c


                         Dataflow Analysis   9
Liveness analysis
example

             a ← 0


             b ← a + 1


             c ← c + b


             a ← 2 * b


             if a < N


             return c


                         Dataflow Analysis   9
Liveness analysis
example

             a ← 0


             b ← a + 1


             c ← c + b


             a ← 2 * b


             if a < N


             return c


                         Dataflow Analysis   9
Liveness analysis
example

             a ← 0


             b ← a + 1


             c ← c + b


             a ← 2 * b


             if a < N


             return c


                         Dataflow Analysis   9
Liveness analysis
example

             a ← 0


             b ← a + 1


             c ← c + b


             a ← 2 * b


             if a < N


             return c


                         Dataflow Analysis   9
Liveness analysis
example

             a ← 0


             b ← a + 1


             c ← c + b


             a ← 2 * b


             if a < N


             return c


                         Dataflow Analysis   9
Liveness analysis
example

             a ← 0


             b ← a + 1


             c ← c + b


             a ← 2 * b


             if a < N


             return c


                         Dataflow Analysis   9
Liveness analysis
example

             a ← 0


             b ← a + 1


             c ← c + b


             a ← 2 * b


             if a < N


             return c


                         Dataflow Analysis   9
Liveness analysis
formalisation

                    in[n] = use[n]   ∪ (out[n] - def[n])

                          out[n] =   ∪  s∈succ[n]   in[s]



1. If a variable is used at node n, then it is live-in at n.

2. If a variable is live-out but not defined at node n, it is live-in at n.

3. If a variable is live-in at node n, then it is live-out at its predecessors.

                                                            Dataflow Analysis 10
Liveness analysis
algorithm

for each n
   in[n] ← {} ; out[n] ← {}
repeat
   for each n
         in'[n] = in[n] ; out'[n] = out[n]
         in[n] = use[n] ∪ (out[n] - def[n])
         for each s in succ[n]
            out[n] = out[n] ∪ in[s]
until
   for all n: in[n] = in'[n] and out[n] = out'[n]


                                              Dataflow Analysis 11
Liveness analysis
example

1a ← 0                       1       2           3           4           5          6       7

                 u d     i o     i o         i o         i o         i o        i o     i o
2b ← a + 1
             1       a                   a           a       ac c ac c ac c ac

3c ← c + b   2   a b     a       a bc ac bc ac bc ac bc ac bc ac bc

             3 bc c bc           bc b bc b bc b bc b bc bc bc bc
4a ← 2 * b
             4   b a     b       b a         b a         b ac bc ac bc ac bc ac
5 if a < N   5   a       a a     a ac ac ac ac ac ac ac ac ac ac ac

             6   c       c       c           c           c           c          c       c
6 return c


                                                                 Dataflow Analysis 12
Liveness analysis
example

1a ← 0                       1       2           3           4           5          6       7

                 u d     i o     i o         i o         i o         i o        i o     i o
2b ← a + 1
             1       a                   a           a       ac c ac c ac c ac

3c ← c + b   2   a b     a       a bc ac bc ac bc ac bc ac bc ac bc

             3 bc c bc           bc b bc b bc b bc b bc bc bc bc
4a ← 2 * b
             4   b a     b       b a         b a         b ac bc ac bc ac bc ac
5 if a < N   5   a       a a     a ac ac ac ac ac ac ac ac ac ac ac

             6   c       c       c           c           c           c          c       c
6 return c


                                                                 Dataflow Analysis 12
Liveness analysis
example

1a ← 0                       1       2           3           4           5          6       7

                 u d     i o     i o         i o         i o         i o        i o     i o
2b ← a + 1
             1       a                   a           a       ac c ac c ac c ac

3c ← c + b   2   a b     a       a bc ac bc ac bc ac bc ac bc ac bc

             3 bc c bc           bc b bc b bc b bc b bc bc bc bc
4a ← 2 * b
             4   b a     b       b a         b a         b ac bc ac bc ac bc ac
5 if a < N   5   a       a a     a ac ac ac ac ac ac ac ac ac ac ac

             6   c       c       c           c           c           c          c       c
6 return c


                                                                 Dataflow Analysis 12
Liveness analysis
example

1a ← 0                       1       2           3           4           5          6       7

                 u d     i o     i o         i o         i o         i o        i o     i o
2b ← a + 1
             1       a                   a           a       ac c ac c ac c ac

3c ← c + b   2   a b     a       a bc ac bc ac bc ac bc ac bc ac bc

             3 bc c bc           bc b bc b bc b bc b bc bc bc bc
4a ← 2 * b
             4   b a     b       b a         b a         b ac bc ac bc ac bc ac
5 if a < N   5   a       a a     a ac ac ac ac ac ac ac ac ac ac ac

             6   c       c       c           c           c           c          c       c
6 return c


                                                                 Dataflow Analysis 12
Liveness analysis
example

1a ← 0                       1       2           3           4           5          6       7

                 u d     i o     i o         i o         i o         i o        i o     i o
2b ← a + 1
             1       a                   a           a       ac c ac c ac c ac

3c ← c + b   2   a b     a       a bc ac bc ac bc ac bc ac bc ac bc

             3 bc c bc           bc b bc b bc b bc b bc bc bc bc
4a ← 2 * b
             4   b a     b       b a         b a         b ac bc ac bc ac bc ac
5 if a < N   5   a       a a     a ac ac ac ac ac ac ac ac ac ac ac

             6   c       c       c           c           c           c          c       c
6 return c


                                                                 Dataflow Analysis 12
Liveness analysis
example

1a ← 0                       1       2           3           4           5          6       7

                 u d     i o     i o         i o         i o         i o        i o     i o
2b ← a + 1
             1       a                   a           a       ac c ac c ac c ac

3c ← c + b   2   a b     a       a bc ac bc ac bc ac bc ac bc ac bc

             3 bc c bc           bc b bc b bc b bc b bc bc bc bc
4a ← 2 * b
             4   b a     b       b a         b a         b ac bc ac bc ac bc ac
5 if a < N   5   a       a a     a ac ac ac ac ac ac ac ac ac ac ac

             6   c       c       c           c           c           c          c       c
6 return c


                                                                 Dataflow Analysis 12
Liveness analysis
example

1a ← 0                       1       2           3           4           5          6       7

                 u d     i o     i o         i o         i o         i o        i o     i o
2b ← a + 1
             1       a                   a           a       ac c ac c ac c ac

3c ← c + b   2   a b     a       a bc ac bc ac bc ac bc ac bc ac bc

             3 bc c bc           bc b bc b bc b bc b bc bc bc bc
4a ← 2 * b
             4   b a     b       b a         b a         b ac bc ac bc ac bc ac
5 if a < N   5   a       a a     a ac ac ac ac ac ac ac ac ac ac ac

             6   c       c       c           c           c           c          c       c
6 return c


                                                                 Dataflow Analysis 12
Liveness analysis
example

1a ← 0                       1       2           3           4           5          6       7

                 u d     i o     i o         i o         i o         i o        i o     i o
2b ← a + 1
             1       a                   a           a       ac c ac c ac c ac

3c ← c + b   2   a b     a       a bc ac bc ac bc ac bc ac bc ac bc

             3 bc c bc           bc b bc b bc b bc b bc bc bc bc
4a ← 2 * b
             4   b a     b       b a         b a         b ac bc ac bc ac bc ac
5 if a < N   5   a       a a     a ac ac ac ac ac ac ac ac ac ac ac

             6   c       c       c           c           c           c          c       c
6 return c


                                                                 Dataflow Analysis 12
Liveness analysis
example

1a ← 0                       1       2           3           4           5          6       7

                 u d     i o     i o         i o         i o         i o        i o     i o
2b ← a + 1
             1       a                   a           a       ac c ac c ac c ac

3c ← c + b   2   a b     a       a bc ac bc ac bc ac bc ac bc ac bc

             3 bc c bc           bc b bc b bc b bc b bc bc bc bc
4a ← 2 * b
             4   b a     b       b a         b a         b ac bc ac bc ac bc ac
5 if a < N   5   a       a a     a ac ac ac ac ac ac ac ac ac ac ac

             6   c       c       c           c           c           c          c       c
6 return c


                                                                 Dataflow Analysis 12
Liveness analysis
optimisation

1a ← 0                           1            2              3

                    u   d   o        i   o        i      o       i
2b ← a + 1
               6    c                c            c              c

3c ← c + b     5    a       c        ac ac ac ac ac

               4    b   a   ac bc ac bc ac bc
4a ← 2 * b
               3   bc   c   bc bc bc bc bc bc
5 if a < N     2    a   b   bc ac bc ac bc ac

               1        a   ac       a   ac       c     ac       c
6 return c


                                                      Dataflow Analysis 13
Liveness analysis
optimisation

1a ← 0                           1            2              3

                    u   d   o        i   o        i      o       i
2b ← a + 1
               6    c                c            c              c

3c ← c + b     5    a       c        ac ac ac ac ac

               4    b   a   ac bc ac bc ac bc
4a ← 2 * b
               3   bc   c   bc bc bc bc bc bc
5 if a < N     2    a   b   bc ac bc ac bc ac

               1        a   ac       a   ac       c     ac       c
6 return c


                                                      Dataflow Analysis 13
Liveness analysis
optimisation

1a ← 0                           1            2              3

                    u   d   o        i   o        i      o       i
2b ← a + 1
               6    c                c            c              c

3c ← c + b     5    a       c        ac ac ac ac ac

               4    b   a   ac bc ac bc ac bc
4a ← 2 * b
               3   bc   c   bc bc bc bc bc bc
5 if a < N     2    a   b   bc ac bc ac bc ac

               1        a   ac       a   ac       c     ac       c
6 return c


                                                      Dataflow Analysis 13
Liveness analysis
optimisation

1a ← 0                           1            2              3

                    u   d   o        i   o        i      o       i
2b ← a + 1
               6    c                c            c              c

3c ← c + b     5    a       c        ac ac ac ac ac

               4    b   a   ac bc ac bc ac bc
4a ← 2 * b
               3   bc   c   bc bc bc bc bc bc
5 if a < N     2    a   b   bc ac bc ac bc ac

               1        a   ac       a   ac       c     ac       c
6 return c


                                                      Dataflow Analysis 13
Liveness analysis
optimisation

1a ← 0                           1            2              3

                    u   d   o        i   o        i      o       i
2b ← a + 1
               6    c                c            c              c

3c ← c + b     5    a       c        ac ac ac ac ac

               4    b   a   ac bc ac bc ac bc
4a ← 2 * b
               3   bc   c   bc bc bc bc bc bc
5 if a < N     2    a   b   bc ac bc ac bc ac

               1        a   ac       a   ac       c     ac       c
6 return c


                                                      Dataflow Analysis 13
Liveness analysis
generalisation

                 a ← 0


                 b ← a + 1


                 c ← c + b


                 a ← 2 * b


                 if a < N


                 return c


                             Dataflow Analysis 14
Liveness analysis
generalisation

kill             a ← 0


                 b ← a + 1


                 c ← c + b


                 a ← 2 * b


                 if a < N


                 return c


                             Dataflow Analysis 14
Liveness analysis
generalisation

kill             a ← 0


gen              b ← a + 1


                 c ← c + b


                 a ← 2 * b


                 if a < N


                 return c


                             Dataflow Analysis 14
Liveness analysis
generalisation

kill             a ← 0


gen              b ← a + 1


                 c ← c + b


kill             a ← 2 * b


                 if a < N


                 return c


                             Dataflow Analysis 14
Liveness analysis
generalisation

kill             a ← 0


gen              b ← a + 1


                 c ← c + b


kill             a ← 2 * b


gen              if a < N


                 return c


                             Dataflow Analysis 14
Liveness analysis
generalisation

kill             a ← 0

                             in
gen              b ← a + 1


                 c ← c + b


kill             a ← 2 * b


gen              if a < N


                 return c


                                  Dataflow Analysis 14
Liveness analysis
generalisation

kill             a ← 0       out

                             in
gen              b ← a + 1


                 c ← c + b


kill             a ← 2 * b


gen              if a < N


                 return c


                                   Dataflow Analysis 14
Liveness analysis
generalisation

kill             a ← 0       out

                             in
gen              b ← a + 1


                 c ← c + b


kill             a ← 2 * b


gen              if a < N
                             out

                 return c


                                   Dataflow Analysis 14
Liveness analysis
generalisation

kill             a ← 0       out

                             in
gen              b ← a + 1


                 c ← c + b


kill             a ← 2 * b

                                         in
gen              if a < N
                             out

                 return c


                                   Dataflow Analysis 14
Liveness analysis
generalisation

kill             a ← 0       out

                             in
gen              b ← a + 1


                 c ← c + b


kill             a ← 2 * b
                             out

                                         in
gen              if a < N
                             out

                 return c


                                   Dataflow Analysis 14
Liveness analysis
gen & kill

                     gen       kill
a ← b ⊕ c           {b,c}      {a}
a ← b                {b}       {a}
a ← M[b]             {b}       {a}
M[a] ← b            {a,b}
f(a1, …, an)       {a1,…,an}
a ← f(a1, …, an)   {a1,…,an}   {a}
goto L
if a ⊗ b            {a,b}



                                      Dataflow Analysis 15
Liveness analysis
gen & kill

                     gen       kill
a ← b ⊕ c           {b,c}      {a}
a ← b                {b}       {a}
a ← M[b]             {b}       {a}
M[a] ← b            {a,b}
f(a1, …, an)       {a1,…,an}
a ← f(a1, …, an)   {a1,…,an}   {a}
goto L
if a ⊗ b            {a,b}



                                      Dataflow Analysis 15
Liveness analysis
generalisation




            in[n] = gen[n]   ∪ (out[n] - kill[n])

                 out[n] =   ∪  s∈succ[n]   in[s]




                                                    Dataflow Analysis 16
coffee break




               Dataflow Analysis 17
III
more analyses




                Dataflow Analysis 18
More analyses
reaching definitions

                       1a ← 5


                       2c ← 1


                       3 if c > a


                       4c ← c + c


                       5 goto 3


                       6a ← c - a


                                    Dataflow Analysis 19
Reaching definitions
gen & kill

                      gen      kill
d: a ← b ⊕ c          {d}   defs(a)-{d}
d: a ← b              {d}   defs(a)-{d}
d: a ← M[b]           {d}   defs(a)-{d}
M[a] ← b
f(a1, …, an)
d: a ← f(a1, …, an)   {d}   defs(a)-{d}
goto L
if a ⊗ b



                                          Dataflow Analysis 20
Reaching definitions
gen & kill

                      gen      kill
d: a ← b ⊕ c          {d}   defs(a)-{d}
d: a ← b              {d}   defs(a)-{d}
d: a ← M[b]           {d}   defs(a)-{d}
M[a] ← b
f(a1, …, an)
d: a ← f(a1, …, an)   {d}   defs(a)-{d}
goto L
if a ⊗ b



                                          Dataflow Analysis 20
Reaching definitions
formalisation




                in[n] =   ∪
                          p∈pred[n]   out[p]

            out[n] = gen[n]   ∪ (in[n] - kill[n])




                                                    Dataflow Analysis 21
More analyses
available expressions

                    1c ← a + b


                    2d ← 1


                    3e ← a + b




                                 Dataflow Analysis 22
Available expressions
gen & kill

                          gen               kill
d: a ← b ⊕ c          {b⊕c}-kill          exps(a)
d: a ← b
d: a ← M[b]           {M[b]}-kill         exps(a)
M[a] ← b                                 exps(M[_])
f(a1, …, an)                             exps(M[_])
d: a ← f(a1, …, an)                 exps(M[_]) ∪ exps(a)
goto L
if a ⊗ b



                                             Dataflow Analysis 23
Available expressions
gen & kill

                          gen               kill
d: a ← b ⊕ c          {b⊕c}-kill          exps(a)
d: a ← b
d: a ← M[b]           {M[b]}-kill         exps(a)
M[a] ← b                                 exps(M[_])
f(a1, …, an)                             exps(M[_])
d: a ← f(a1, …, an)                 exps(M[_]) ∪ exps(a)
goto L
if a ⊗ b



                                             Dataflow Analysis 23
Available expressions
formalisation




                in[n] =   ∩
                          p∈pred[n]   out[p]

            out[n] = gen[n]   ∪ (in[n] - kill[n])




                                                    Dataflow Analysis 24
IV
optimisations




                Term Rewriting 25
Dead code elimination
example

a ← 0              a ← 0
b ← a + 1          b ← a + 1
c ← c + b          c ← c + b
a ← 2 * b          return c
return c




                               Dataflow Analysis 26
Constant propagation
example

a ← 0             a ← 0
b ← a + 1         b ← 0 + 1
c ← c + b         c ← c + b
a ← 2 * b         a ← 2 * b
return c          return c




                              Dataflow Analysis 27
Copy propagation
example

a ← e              a ← e
b ← a + 1          b ← e + 1
c ← c + b          c ← c + b
a ← 2 * b          a ← 2 * b
return c           return c




                               Dataflow Analysis 28
Common subexpression elimination
example

c ← a + b         x ← a + b
d ← 1             c ← x
e ← a + b         d ← 1
                  e ← x




                              Dataflow Analysis 29
V
summary




          Term Rewriting 30
Summary
lessons learned

liveness analysis

  •   intermediate language
  •   control-flow graphs
  •   definition & algorithm

more dataflow analyses

  •   reaching definitions
  •   available expressions

optimisations



                               Dataflow Analysis 31
Literature
learn more

Andrew W. Appel, Jens Palsberg: Modern Compiler
Implementation in Java, 2nd edition. 2002




                                                  Dataflow Analysis 32
copyrights & credits




                       Dataflow Analysis 33
Dataflow Analysis 34
Pictures
copyrights

Slide 1:
   ink swirl by Graham Richardson, some rights reserved

Slide 25:
   Seattle's Best Coffee by Dominica Williamson, some rights reserved

Slide 32:
   Animal Ark Reno by Joel Riley, some rights reserved




                                                                        Dataflow Analysis 35

More Related Content

What's hot

Multilayer Neural Networks
Multilayer Neural NetworksMultilayer Neural Networks
Multilayer Neural Networks
ESCOM
 
RedisConf18 - Lower Latency Graph Queries in Cypher with Redis Graph
RedisConf18 - Lower Latency Graph Queries in Cypher with Redis GraphRedisConf18 - Lower Latency Graph Queries in Cypher with Redis Graph
RedisConf18 - Lower Latency Graph Queries in Cypher with Redis Graph
Redis Labs
 
On Resolution Proofs for Combinational Equivalence
On Resolution Proofs for Combinational EquivalenceOn Resolution Proofs for Combinational Equivalence
On Resolution Proofs for Combinational Equivalence
satrajit
 
Module 13 Gradient And Area Under A Graph
Module 13  Gradient And Area Under A GraphModule 13  Gradient And Area Under A Graph
Module 13 Gradient And Area Under A Graph
guestcc333c
 
Reducing Structural Bias in Technology Mapping
Reducing Structural Bias in Technology MappingReducing Structural Bias in Technology Mapping
Reducing Structural Bias in Technology Mapping
satrajit
 
icml2004 tutorial on spectral clustering part I
icml2004 tutorial on spectral clustering part Iicml2004 tutorial on spectral clustering part I
icml2004 tutorial on spectral clustering part I
zukun
 
icml2004 tutorial on spectral clustering part II
icml2004 tutorial on spectral clustering part IIicml2004 tutorial on spectral clustering part II
icml2004 tutorial on spectral clustering part II
zukun
 
IJCER (www.ijceronline.com) International Journal of computational Engineerin...
IJCER (www.ijceronline.com) International Journal of computational Engineerin...IJCER (www.ijceronline.com) International Journal of computational Engineerin...
IJCER (www.ijceronline.com) International Journal of computational Engineerin...
ijceronline
 

What's hot (20)

Multilayer Neural Networks
Multilayer Neural NetworksMultilayer Neural Networks
Multilayer Neural Networks
 
RedisConf18 - Lower Latency Graph Queries in Cypher with Redis Graph
RedisConf18 - Lower Latency Graph Queries in Cypher with Redis GraphRedisConf18 - Lower Latency Graph Queries in Cypher with Redis Graph
RedisConf18 - Lower Latency Graph Queries in Cypher with Redis Graph
 
Query Rewriting and Optimization for Ontological Databases
Query Rewriting and Optimization for Ontological DatabasesQuery Rewriting and Optimization for Ontological Databases
Query Rewriting and Optimization for Ontological Databases
 
Story of static code analyzer development
Story of static code analyzer developmentStory of static code analyzer development
Story of static code analyzer development
 
bayesImageS: Bayesian computation for medical Image Segmentation using a hidd...
bayesImageS: Bayesian computation for medical Image Segmentation using a hidd...bayesImageS: Bayesian computation for medical Image Segmentation using a hidd...
bayesImageS: Bayesian computation for medical Image Segmentation using a hidd...
 
R package 'bayesImageS': a case study in Bayesian computation using Rcpp and ...
R package 'bayesImageS': a case study in Bayesian computation using Rcpp and ...R package 'bayesImageS': a case study in Bayesian computation using Rcpp and ...
R package 'bayesImageS': a case study in Bayesian computation using Rcpp and ...
 
Ef24836841
Ef24836841Ef24836841
Ef24836841
 
Data Stream Outlier Detection Algorithm
Data Stream Outlier Detection Algorithm Data Stream Outlier Detection Algorithm
Data Stream Outlier Detection Algorithm
 
On Resolution Proofs for Combinational Equivalence
On Resolution Proofs for Combinational EquivalenceOn Resolution Proofs for Combinational Equivalence
On Resolution Proofs for Combinational Equivalence
 
Kernel for Chordal Vertex Deletion
Kernel for Chordal Vertex DeletionKernel for Chordal Vertex Deletion
Kernel for Chordal Vertex Deletion
 
Bayesian Inference and Uncertainty Quantification for Inverse Problems
Bayesian Inference and Uncertainty Quantification for Inverse ProblemsBayesian Inference and Uncertainty Quantification for Inverse Problems
Bayesian Inference and Uncertainty Quantification for Inverse Problems
 
Querying Temporal Databases via OWL 2 QL
Querying Temporal Databases via OWL 2 QLQuerying Temporal Databases via OWL 2 QL
Querying Temporal Databases via OWL 2 QL
 
Vectorization in ATLAS
Vectorization in ATLASVectorization in ATLAS
Vectorization in ATLAS
 
Module 13 Gradient And Area Under A Graph
Module 13  Gradient And Area Under A GraphModule 13  Gradient And Area Under A Graph
Module 13 Gradient And Area Under A Graph
 
Reducing Structural Bias in Technology Mapping
Reducing Structural Bias in Technology MappingReducing Structural Bias in Technology Mapping
Reducing Structural Bias in Technology Mapping
 
icml2004 tutorial on spectral clustering part I
icml2004 tutorial on spectral clustering part Iicml2004 tutorial on spectral clustering part I
icml2004 tutorial on spectral clustering part I
 
icml2004 tutorial on spectral clustering part II
icml2004 tutorial on spectral clustering part IIicml2004 tutorial on spectral clustering part II
icml2004 tutorial on spectral clustering part II
 
Deep Convolutional GANs - meaning of latent space
Deep Convolutional GANs - meaning of latent spaceDeep Convolutional GANs - meaning of latent space
Deep Convolutional GANs - meaning of latent space
 
By32474479
By32474479By32474479
By32474479
 
IJCER (www.ijceronline.com) International Journal of computational Engineerin...
IJCER (www.ijceronline.com) International Journal of computational Engineerin...IJCER (www.ijceronline.com) International Journal of computational Engineerin...
IJCER (www.ijceronline.com) International Journal of computational Engineerin...
 

More from Guido Wachsmuth

Domain-Specific Type Systems
Domain-Specific Type SystemsDomain-Specific Type Systems
Domain-Specific Type Systems
Guido Wachsmuth
 

More from Guido Wachsmuth (16)

Language
LanguageLanguage
Language
 
Domain-Specific Type Systems
Domain-Specific Type SystemsDomain-Specific Type Systems
Domain-Specific Type Systems
 
Declarative Syntax Definition - Pretty Printing
Declarative Syntax Definition - Pretty PrintingDeclarative Syntax Definition - Pretty Printing
Declarative Syntax Definition - Pretty Printing
 
Compiler Components and their Generators - LR Parsing
Compiler Components and their Generators - LR ParsingCompiler Components and their Generators - LR Parsing
Compiler Components and their Generators - LR Parsing
 
Compiling Imperative and Object-Oriented Languages - Garbage Collection
Compiling Imperative and Object-Oriented Languages - Garbage CollectionCompiling Imperative and Object-Oriented Languages - Garbage Collection
Compiling Imperative and Object-Oriented Languages - Garbage Collection
 
Compiler Components and their Generators - Lexical Analysis
Compiler Components and their Generators - Lexical AnalysisCompiler Components and their Generators - Lexical Analysis
Compiler Components and their Generators - Lexical Analysis
 
Compiler Components and their Generators - Traditional Parsing Algorithms
Compiler Components and their Generators - Traditional Parsing AlgorithmsCompiler Components and their Generators - Traditional Parsing Algorithms
Compiler Components and their Generators - Traditional Parsing Algorithms
 
Pure and Declarative Syntax Definition: Paradise Lost and Regained
Pure and Declarative Syntax Definition: Paradise Lost and RegainedPure and Declarative Syntax Definition: Paradise Lost and Regained
Pure and Declarative Syntax Definition: Paradise Lost and Regained
 
Introduction - Imperative and Object-Oriented Languages
Introduction - Imperative and Object-Oriented LanguagesIntroduction - Imperative and Object-Oriented Languages
Introduction - Imperative and Object-Oriented Languages
 
Compiling Imperative and Object-Oriented Languages - Activation Records
Compiling Imperative and Object-Oriented Languages - Activation RecordsCompiling Imperative and Object-Oriented Languages - Activation Records
Compiling Imperative and Object-Oriented Languages - Activation Records
 
Declarative Semantics Definition - Code Generation
Declarative Semantics Definition - Code Generation Declarative Semantics Definition - Code Generation
Declarative Semantics Definition - Code Generation
 
Declarative Semantics Definition - Static Analysis and Error Checking
Declarative Semantics Definition - Static Analysis and Error CheckingDeclarative Semantics Definition - Static Analysis and Error Checking
Declarative Semantics Definition - Static Analysis and Error Checking
 
Declarative Semantics Definition - Term Rewriting
Declarative Semantics Definition - Term RewritingDeclarative Semantics Definition - Term Rewriting
Declarative Semantics Definition - Term Rewriting
 
Syntax Definition
Syntax DefinitionSyntax Definition
Syntax Definition
 
Declarative Syntax Definition - Grammars and Trees
Declarative Syntax Definition - Grammars and TreesDeclarative Syntax Definition - Grammars and Trees
Declarative Syntax Definition - Grammars and Trees
 
Software Languages
Software LanguagesSoftware Languages
Software Languages
 

Recently uploaded

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Recently uploaded (20)

This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 

Compiling Imperative and Object-Oriented Languages - Dataflow Analysis

  • 1. Dataflow Analysis Guido Wachsmuth Delft Course IN4303, 2012/13 University of Technology Compiler Construction Challenge the future
  • 2. Overview today’s lecture control flow graphs Dataflow Analysis 2
  • 3. Overview today’s lecture control flow graphs data flow analyses • liveness analysis • reaching definitions • available expressions Dataflow Analysis 2
  • 4. Overview today’s lecture control flow graphs data flow analyses • liveness analysis • reaching definitions • available expressions non-local optimisations • dead code elimination • constant & copy propagation • common subexpression elimination Dataflow Analysis 2
  • 5. I control-flow graphs Dataflow Analysis 3
  • 6. Intermediate language quadruples store jumps a ← b ⊕ c L: a ← b goto L if a ⊗ b memory access goto L1 a ← M[b] else M[a] ← b goto L2 functions f(a1, …, an) b ← f(a1, …, an) Dataflow Analysis 4
  • 7. Control-flow graphs example a ← 0 L1: b ← a + 1 c ← c + b a ← 2 * b if a < N goto L1 else goto L2 L2: return c Dataflow Analysis 5
  • 8. Control-flow graphs example a ← 0 a ← 0 L1: b ← a + 1 b ← a + 1 c ← c + b a ← 2 * b c ← c + b if a < N goto L1 a ← 2 * b else if a < N goto L2 L2: return c return c Dataflow Analysis 5
  • 9. Control-flow graphs terminology a ← 0 b ← a + 1 c ← c + b a ← 2 * b if a < N return c Dataflow Analysis 6
  • 10. Control-flow graphs terminology a ← 0 node b ← a + 1 c ← c + b a ← 2 * b if a < N return c Dataflow Analysis 6
  • 11. Control-flow graphs terminology a ← 0 in-edge node b ← a + 1 c ← c + b a ← 2 * b if a < N return c Dataflow Analysis 6
  • 12. Control-flow graphs terminology a ← 0 in-edge node b ← a + 1 c ← c + b in-edge a ← 2 * b if a < N return c Dataflow Analysis 6
  • 13. Control-flow graphs terminology predecessor a ← 0 in-edge node b ← a + 1 c ← c + b in-edge a ← 2 * b predecessor if a < N return c Dataflow Analysis 6
  • 14. Control-flow graphs terminology predecessor a ← 0 in-edge node b ← a + 1 out-edge c ← c + b in-edge a ← 2 * b predecessor if a < N return c Dataflow Analysis 6
  • 15. Control-flow graphs terminology predecessor a ← 0 in-edge node b ← a + 1 out-edge successor c ← c + b in-edge a ← 2 * b predecessor if a < N return c Dataflow Analysis 6
  • 16. II liveness analysis Dataflow Analysis 7
  • 17. Liveness analysis terminology a ← 0 b ← a + 1 c ← c + b a ← 2 * b if a < N return c Dataflow Analysis 8
  • 18. Liveness analysis terminology definition a ← 0 b ← a + 1 c ← c + b a ← 2 * b if a < N return c Dataflow Analysis 8
  • 19. Liveness analysis terminology definition a ← 0 usage b ← a + 1 c ← c + b a ← 2 * b if a < N return c Dataflow Analysis 8
  • 20. Liveness analysis terminology definition a ← 0 usage b ← a + 1 c ← c + b definition a ← 2 * b if a < N return c Dataflow Analysis 8
  • 21. Liveness analysis terminology definition a ← 0 usage b ← a + 1 c ← c + b definition a ← 2 * b usage if a < N return c Dataflow Analysis 8
  • 22. Liveness analysis terminology definition a ← 0 usage b ← a + 1 c ← c + b definition a ← 2 * b live-in usage if a < N return c Dataflow Analysis 8
  • 23. Liveness analysis terminology definition a ← 0 usage b ← a + 1 c ← c + b definition a ← 2 * b live-out live-in usage if a < N return c Dataflow Analysis 8
  • 24. Liveness analysis terminology definition a ← 0 live-in usage b ← a + 1 c ← c + b definition a ← 2 * b live-out live-in usage if a < N return c Dataflow Analysis 8
  • 25. Liveness analysis terminology definition a ← 0 live-in usage b ← a + 1 c ← c + b definition a ← 2 * b live-out live-in usage if a < N live-out return c Dataflow Analysis 8
  • 26. Liveness analysis terminology definition a ← 0 live-out live-in usage b ← a + 1 c ← c + b definition a ← 2 * b live-out live-in usage if a < N live-out return c Dataflow Analysis 8
  • 27. Liveness analysis example a ← 0 b ← a + 1 c ← c + b a ← 2 * b if a < N return c Dataflow Analysis 9
  • 28. Liveness analysis example a ← 0 b ← a + 1 c ← c + b a ← 2 * b if a < N return c Dataflow Analysis 9
  • 29. Liveness analysis example a ← 0 b ← a + 1 c ← c + b a ← 2 * b if a < N return c Dataflow Analysis 9
  • 30. Liveness analysis example a ← 0 b ← a + 1 c ← c + b a ← 2 * b if a < N return c Dataflow Analysis 9
  • 31. Liveness analysis example a ← 0 b ← a + 1 c ← c + b a ← 2 * b if a < N return c Dataflow Analysis 9
  • 32. Liveness analysis example a ← 0 b ← a + 1 c ← c + b a ← 2 * b if a < N return c Dataflow Analysis 9
  • 33. Liveness analysis example a ← 0 b ← a + 1 c ← c + b a ← 2 * b if a < N return c Dataflow Analysis 9
  • 34. Liveness analysis example a ← 0 b ← a + 1 c ← c + b a ← 2 * b if a < N return c Dataflow Analysis 9
  • 35. Liveness analysis example a ← 0 b ← a + 1 c ← c + b a ← 2 * b if a < N return c Dataflow Analysis 9
  • 36. Liveness analysis example a ← 0 b ← a + 1 c ← c + b a ← 2 * b if a < N return c Dataflow Analysis 9
  • 37. Liveness analysis example a ← 0 b ← a + 1 c ← c + b a ← 2 * b if a < N return c Dataflow Analysis 9
  • 38. Liveness analysis formalisation in[n] = use[n] ∪ (out[n] - def[n]) out[n] = ∪ s∈succ[n] in[s] 1. If a variable is used at node n, then it is live-in at n. 2. If a variable is live-out but not defined at node n, it is live-in at n. 3. If a variable is live-in at node n, then it is live-out at its predecessors. Dataflow Analysis 10
  • 39. Liveness analysis algorithm for each n in[n] ← {} ; out[n] ← {} repeat for each n in'[n] = in[n] ; out'[n] = out[n] in[n] = use[n] ∪ (out[n] - def[n]) for each s in succ[n] out[n] = out[n] ∪ in[s] until for all n: in[n] = in'[n] and out[n] = out'[n] Dataflow Analysis 11
  • 40. Liveness analysis example 1a ← 0 1 2 3 4 5 6 7 u d i o i o i o i o i o i o i o 2b ← a + 1 1 a a a ac c ac c ac c ac 3c ← c + b 2 a b a a bc ac bc ac bc ac bc ac bc ac bc 3 bc c bc bc b bc b bc b bc b bc bc bc bc 4a ← 2 * b 4 b a b b a b a b ac bc ac bc ac bc ac 5 if a < N 5 a a a a ac ac ac ac ac ac ac ac ac ac ac 6 c c c c c c c c 6 return c Dataflow Analysis 12
  • 41. Liveness analysis example 1a ← 0 1 2 3 4 5 6 7 u d i o i o i o i o i o i o i o 2b ← a + 1 1 a a a ac c ac c ac c ac 3c ← c + b 2 a b a a bc ac bc ac bc ac bc ac bc ac bc 3 bc c bc bc b bc b bc b bc b bc bc bc bc 4a ← 2 * b 4 b a b b a b a b ac bc ac bc ac bc ac 5 if a < N 5 a a a a ac ac ac ac ac ac ac ac ac ac ac 6 c c c c c c c c 6 return c Dataflow Analysis 12
  • 42. Liveness analysis example 1a ← 0 1 2 3 4 5 6 7 u d i o i o i o i o i o i o i o 2b ← a + 1 1 a a a ac c ac c ac c ac 3c ← c + b 2 a b a a bc ac bc ac bc ac bc ac bc ac bc 3 bc c bc bc b bc b bc b bc b bc bc bc bc 4a ← 2 * b 4 b a b b a b a b ac bc ac bc ac bc ac 5 if a < N 5 a a a a ac ac ac ac ac ac ac ac ac ac ac 6 c c c c c c c c 6 return c Dataflow Analysis 12
  • 43. Liveness analysis example 1a ← 0 1 2 3 4 5 6 7 u d i o i o i o i o i o i o i o 2b ← a + 1 1 a a a ac c ac c ac c ac 3c ← c + b 2 a b a a bc ac bc ac bc ac bc ac bc ac bc 3 bc c bc bc b bc b bc b bc b bc bc bc bc 4a ← 2 * b 4 b a b b a b a b ac bc ac bc ac bc ac 5 if a < N 5 a a a a ac ac ac ac ac ac ac ac ac ac ac 6 c c c c c c c c 6 return c Dataflow Analysis 12
  • 44. Liveness analysis example 1a ← 0 1 2 3 4 5 6 7 u d i o i o i o i o i o i o i o 2b ← a + 1 1 a a a ac c ac c ac c ac 3c ← c + b 2 a b a a bc ac bc ac bc ac bc ac bc ac bc 3 bc c bc bc b bc b bc b bc b bc bc bc bc 4a ← 2 * b 4 b a b b a b a b ac bc ac bc ac bc ac 5 if a < N 5 a a a a ac ac ac ac ac ac ac ac ac ac ac 6 c c c c c c c c 6 return c Dataflow Analysis 12
  • 45. Liveness analysis example 1a ← 0 1 2 3 4 5 6 7 u d i o i o i o i o i o i o i o 2b ← a + 1 1 a a a ac c ac c ac c ac 3c ← c + b 2 a b a a bc ac bc ac bc ac bc ac bc ac bc 3 bc c bc bc b bc b bc b bc b bc bc bc bc 4a ← 2 * b 4 b a b b a b a b ac bc ac bc ac bc ac 5 if a < N 5 a a a a ac ac ac ac ac ac ac ac ac ac ac 6 c c c c c c c c 6 return c Dataflow Analysis 12
  • 46. Liveness analysis example 1a ← 0 1 2 3 4 5 6 7 u d i o i o i o i o i o i o i o 2b ← a + 1 1 a a a ac c ac c ac c ac 3c ← c + b 2 a b a a bc ac bc ac bc ac bc ac bc ac bc 3 bc c bc bc b bc b bc b bc b bc bc bc bc 4a ← 2 * b 4 b a b b a b a b ac bc ac bc ac bc ac 5 if a < N 5 a a a a ac ac ac ac ac ac ac ac ac ac ac 6 c c c c c c c c 6 return c Dataflow Analysis 12
  • 47. Liveness analysis example 1a ← 0 1 2 3 4 5 6 7 u d i o i o i o i o i o i o i o 2b ← a + 1 1 a a a ac c ac c ac c ac 3c ← c + b 2 a b a a bc ac bc ac bc ac bc ac bc ac bc 3 bc c bc bc b bc b bc b bc b bc bc bc bc 4a ← 2 * b 4 b a b b a b a b ac bc ac bc ac bc ac 5 if a < N 5 a a a a ac ac ac ac ac ac ac ac ac ac ac 6 c c c c c c c c 6 return c Dataflow Analysis 12
  • 48. Liveness analysis example 1a ← 0 1 2 3 4 5 6 7 u d i o i o i o i o i o i o i o 2b ← a + 1 1 a a a ac c ac c ac c ac 3c ← c + b 2 a b a a bc ac bc ac bc ac bc ac bc ac bc 3 bc c bc bc b bc b bc b bc b bc bc bc bc 4a ← 2 * b 4 b a b b a b a b ac bc ac bc ac bc ac 5 if a < N 5 a a a a ac ac ac ac ac ac ac ac ac ac ac 6 c c c c c c c c 6 return c Dataflow Analysis 12
  • 49. Liveness analysis optimisation 1a ← 0 1 2 3 u d o i o i o i 2b ← a + 1 6 c c c c 3c ← c + b 5 a c ac ac ac ac ac 4 b a ac bc ac bc ac bc 4a ← 2 * b 3 bc c bc bc bc bc bc bc 5 if a < N 2 a b bc ac bc ac bc ac 1 a ac a ac c ac c 6 return c Dataflow Analysis 13
  • 50. Liveness analysis optimisation 1a ← 0 1 2 3 u d o i o i o i 2b ← a + 1 6 c c c c 3c ← c + b 5 a c ac ac ac ac ac 4 b a ac bc ac bc ac bc 4a ← 2 * b 3 bc c bc bc bc bc bc bc 5 if a < N 2 a b bc ac bc ac bc ac 1 a ac a ac c ac c 6 return c Dataflow Analysis 13
  • 51. Liveness analysis optimisation 1a ← 0 1 2 3 u d o i o i o i 2b ← a + 1 6 c c c c 3c ← c + b 5 a c ac ac ac ac ac 4 b a ac bc ac bc ac bc 4a ← 2 * b 3 bc c bc bc bc bc bc bc 5 if a < N 2 a b bc ac bc ac bc ac 1 a ac a ac c ac c 6 return c Dataflow Analysis 13
  • 52. Liveness analysis optimisation 1a ← 0 1 2 3 u d o i o i o i 2b ← a + 1 6 c c c c 3c ← c + b 5 a c ac ac ac ac ac 4 b a ac bc ac bc ac bc 4a ← 2 * b 3 bc c bc bc bc bc bc bc 5 if a < N 2 a b bc ac bc ac bc ac 1 a ac a ac c ac c 6 return c Dataflow Analysis 13
  • 53. Liveness analysis optimisation 1a ← 0 1 2 3 u d o i o i o i 2b ← a + 1 6 c c c c 3c ← c + b 5 a c ac ac ac ac ac 4 b a ac bc ac bc ac bc 4a ← 2 * b 3 bc c bc bc bc bc bc bc 5 if a < N 2 a b bc ac bc ac bc ac 1 a ac a ac c ac c 6 return c Dataflow Analysis 13
  • 54. Liveness analysis generalisation a ← 0 b ← a + 1 c ← c + b a ← 2 * b if a < N return c Dataflow Analysis 14
  • 55. Liveness analysis generalisation kill a ← 0 b ← a + 1 c ← c + b a ← 2 * b if a < N return c Dataflow Analysis 14
  • 56. Liveness analysis generalisation kill a ← 0 gen b ← a + 1 c ← c + b a ← 2 * b if a < N return c Dataflow Analysis 14
  • 57. Liveness analysis generalisation kill a ← 0 gen b ← a + 1 c ← c + b kill a ← 2 * b if a < N return c Dataflow Analysis 14
  • 58. Liveness analysis generalisation kill a ← 0 gen b ← a + 1 c ← c + b kill a ← 2 * b gen if a < N return c Dataflow Analysis 14
  • 59. Liveness analysis generalisation kill a ← 0 in gen b ← a + 1 c ← c + b kill a ← 2 * b gen if a < N return c Dataflow Analysis 14
  • 60. Liveness analysis generalisation kill a ← 0 out in gen b ← a + 1 c ← c + b kill a ← 2 * b gen if a < N return c Dataflow Analysis 14
  • 61. Liveness analysis generalisation kill a ← 0 out in gen b ← a + 1 c ← c + b kill a ← 2 * b gen if a < N out return c Dataflow Analysis 14
  • 62. Liveness analysis generalisation kill a ← 0 out in gen b ← a + 1 c ← c + b kill a ← 2 * b in gen if a < N out return c Dataflow Analysis 14
  • 63. Liveness analysis generalisation kill a ← 0 out in gen b ← a + 1 c ← c + b kill a ← 2 * b out in gen if a < N out return c Dataflow Analysis 14
  • 64. Liveness analysis gen & kill gen kill a ← b ⊕ c {b,c} {a} a ← b {b} {a} a ← M[b] {b} {a} M[a] ← b {a,b} f(a1, …, an) {a1,…,an} a ← f(a1, …, an) {a1,…,an} {a} goto L if a ⊗ b {a,b} Dataflow Analysis 15
  • 65. Liveness analysis gen & kill gen kill a ← b ⊕ c {b,c} {a} a ← b {b} {a} a ← M[b] {b} {a} M[a] ← b {a,b} f(a1, …, an) {a1,…,an} a ← f(a1, …, an) {a1,…,an} {a} goto L if a ⊗ b {a,b} Dataflow Analysis 15
  • 66. Liveness analysis generalisation in[n] = gen[n] ∪ (out[n] - kill[n]) out[n] = ∪ s∈succ[n] in[s] Dataflow Analysis 16
  • 67. coffee break Dataflow Analysis 17
  • 68. III more analyses Dataflow Analysis 18
  • 69. More analyses reaching definitions 1a ← 5 2c ← 1 3 if c > a 4c ← c + c 5 goto 3 6a ← c - a Dataflow Analysis 19
  • 70. Reaching definitions gen & kill gen kill d: a ← b ⊕ c {d} defs(a)-{d} d: a ← b {d} defs(a)-{d} d: a ← M[b] {d} defs(a)-{d} M[a] ← b f(a1, …, an) d: a ← f(a1, …, an) {d} defs(a)-{d} goto L if a ⊗ b Dataflow Analysis 20
  • 71. Reaching definitions gen & kill gen kill d: a ← b ⊕ c {d} defs(a)-{d} d: a ← b {d} defs(a)-{d} d: a ← M[b] {d} defs(a)-{d} M[a] ← b f(a1, …, an) d: a ← f(a1, …, an) {d} defs(a)-{d} goto L if a ⊗ b Dataflow Analysis 20
  • 72. Reaching definitions formalisation in[n] = ∪ p∈pred[n] out[p] out[n] = gen[n] ∪ (in[n] - kill[n]) Dataflow Analysis 21
  • 73. More analyses available expressions 1c ← a + b 2d ← 1 3e ← a + b Dataflow Analysis 22
  • 74. Available expressions gen & kill gen kill d: a ← b ⊕ c {b⊕c}-kill exps(a) d: a ← b d: a ← M[b] {M[b]}-kill exps(a) M[a] ← b exps(M[_]) f(a1, …, an) exps(M[_]) d: a ← f(a1, …, an) exps(M[_]) ∪ exps(a) goto L if a ⊗ b Dataflow Analysis 23
  • 75. Available expressions gen & kill gen kill d: a ← b ⊕ c {b⊕c}-kill exps(a) d: a ← b d: a ← M[b] {M[b]}-kill exps(a) M[a] ← b exps(M[_]) f(a1, …, an) exps(M[_]) d: a ← f(a1, …, an) exps(M[_]) ∪ exps(a) goto L if a ⊗ b Dataflow Analysis 23
  • 76. Available expressions formalisation in[n] = ∩ p∈pred[n] out[p] out[n] = gen[n] ∪ (in[n] - kill[n]) Dataflow Analysis 24
  • 77. IV optimisations Term Rewriting 25
  • 78. Dead code elimination example a ← 0 a ← 0 b ← a + 1 b ← a + 1 c ← c + b c ← c + b a ← 2 * b return c return c Dataflow Analysis 26
  • 79. Constant propagation example a ← 0 a ← 0 b ← a + 1 b ← 0 + 1 c ← c + b c ← c + b a ← 2 * b a ← 2 * b return c return c Dataflow Analysis 27
  • 80. Copy propagation example a ← e a ← e b ← a + 1 b ← e + 1 c ← c + b c ← c + b a ← 2 * b a ← 2 * b return c return c Dataflow Analysis 28
  • 81. Common subexpression elimination example c ← a + b x ← a + b d ← 1 c ← x e ← a + b d ← 1 e ← x Dataflow Analysis 29
  • 82. V summary Term Rewriting 30
  • 83. Summary lessons learned liveness analysis • intermediate language • control-flow graphs • definition & algorithm more dataflow analyses • reaching definitions • available expressions optimisations Dataflow Analysis 31
  • 84. Literature learn more Andrew W. Appel, Jens Palsberg: Modern Compiler Implementation in Java, 2nd edition. 2002 Dataflow Analysis 32
  • 85. copyrights & credits Dataflow Analysis 33
  • 87. Pictures copyrights Slide 1: ink swirl by Graham Richardson, some rights reserved Slide 25: Seattle's Best Coffee by Dominica Williamson, some rights reserved Slide 32: Animal Ark Reno by Joel Riley, some rights reserved Dataflow Analysis 35

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. \n
  71. \n
  72. \n
  73. \n
  74. \n
  75. \n
  76. \n
  77. \n
  78. \n
  79. \n
  80. \n
  81. \n
  82. \n
  83. \n
  84. \n
  85. \n
  86. \n
  87. \n
  88. \n
  89. \n
  90. \n
  91. \n
  92. \n
  93. \n
  94. \n
  95. \n
  96. \n
  97. \n
  98. \n
  99. \n
  100. \n
  101. \n
  102. round-up on every lecture\n\nwhat to take with you\n\ncheck yourself, pre- and post-paration\n
  103. \n
  104. \n