Polite number: Difference between revisions

From formulasearchengine
Jump to navigation Jump to search
en>Giftlite
 
en>Graham87
m copyedit
Line 1: Line 1:
They contact me Emilia. Hiring is her day job now and she will not change it whenever quickly. One of the very best issues in the globe for me is to do aerobics and now I'm trying to make money with it. For many years he's been living in North Dakota and his family loves it.<br><br>Check out my web blog: at home std test ([http://Independentmumbaiescort.com/anamika/blogs/post/4358 please click the next website])
In [[compiler theory]], '''live variable analysis''' (or simply '''liveness analysis''') is a classic [[data-flow analysis]] performed by [[compiler]]s to calculate for each program point the [[Variable (programming)|variables]] that may be potentially read before their next write, that is, the variables that are ''live'' at the exit from each program point.
 
Stated simply: a variable is '''live''' if it holds a value that may be needed in the future.
 
It is a "backwards way" analysis. The analysis is done in a backwards order, and the dataflow [[confluence operator]] is [[set union]].
 
<table>
<tr>
<td>
The set of live variables at line L3 is {<code>b</code>, <code>c</code>} because both are used in the addition, and thereby the call to <code>f</code> and assignment to <code>a</code>.  But the set of live variables at line L1 is
only {<code>b</code>} since variable <code>c</code> is updated in L2.  The value of variable <code>a</code> is never used.  Note that <code>f</code> may be stateful, so the never-live assignment to <code>a</code> can be eliminated, but there is insufficient information to rule on the entirety of <code>L3</code>.
</td>
 
<td>
<code>
L1: b := 3;
L2: c := 5;
L3: a := f(b + c);
goto L1;
</code>
</td>
</tr>
</table>
 
The dataflow equations used for a given basic block ''s'' and exiting block ''f'' in live variable analysis are the following:
 
:<math>
{\mbox{GEN}}[s] </math>: The set of variables that are used in s before any assignment.
 
:<math>
{\mbox{KILL}}[s] </math>: The set of variables that are assigned a value in s (in many books, KILL (s) is also defined as the set of variables assigned a value in s ''before any use'', but this doesn't change the solution of the dataflow equation):
 
 
:<math>
{\mbox{LIVE}}_{in}[s] = {\mbox{GEN}}[s] \cup ({\mbox{LIVE}}_{out}[s] - {\mbox{KILL}}[s])
</math>
:<math>
{\mbox{LIVE}}_{out}[final] = {\emptyset}
</math>
:<math>
{\mbox{LIVE}}_{out}[s] = \bigcup_{p \in succ[S]} {\mbox{LIVE}}_{in}[p]
</math>
 
:<math>
{\mbox{GEN}}[d : y \leftarrow f(x_1,\cdots,x_n)] = \{x_1,...,x_n\}
</math>
:<math>
{\mbox{KILL}}[d : y \leftarrow f(x_1,\cdots,x_n)] = \{y\}
</math>
 
The in-state of a block is the set of variables that are live at the start of the block. Its out-state is the set of variables that are live at the end of it. The out-state is the union of the in-states of the block's successors. The transfer function of a statement is applied by making the variables that are written dead, then making the variables that are read live.
 
<table>
<tr><td>
// in: {}
b1: a = 3;
    b = 5;
    d = 4;
    x = 100; //x is never being used later thus not in the out set {a,b,d}
    if a > b then
// out: {a,b,d}    //union of all (in) successors of b1 => b2: {a,b}, and b3:{b,d} 
// in: {a,b}
b2: c = a + b;
    d = 2;
// out: {b,d}
// in: {b,d}
b3: endif
    c = 4;
    return b * d + c;
// out:{}
</td>
</tr>
</table>
 
The in-state of b3 only contains ''b'' and ''d'', since ''c'' has been written. The out-state of b1 is the union of the in-states of b2 and b3. The definition of ''c'' in b2 can be removed, since ''c'' is not live immediately after the statement.
 
Solving the data flow equations starts with initializing all in-states and out-states to the empty set. The work list is initialized by inserting the exit point (b3) in the work list (typical for backward flow). Its computed out-state differs from the previous one, so its predecessors b1 and b2 are inserted and the process continues. The progress is summarized in the table below.
 
{| class="wikitable"
|-
! processing
! out-state
! old in-state
! new in-state
! work list
|-
| b3
| {}
| {}
| {b,d}
| (b1,b2)
|-
| b1
| {b,d}
| {}
| {}
| (b2)
|-
| b2
| {b,d}
| {}
| {a,b}
| (b1)
|-
| b1
| {a,b,d}
| {}
| {}
| ()
|}
 
Note that b1 was entered in the list before b2, which forced processing b1 twice (b1 was re-entered as predecessor of b2). Inserting b2 before b1 would have allowed earlier completion.
 
Initializing with the empty set is an optimistic initialization: all variables start out as dead. Note that the out-states cannot shrink from one iteration to the next, although the out-state can be smaller than the in-state. This can be seen from the fact that after the first iteration the out-state can only change by a change of the in-state. Since the in-state starts as the empty set, it can only grow in further iterations.
 
<!-- Is this paragraph relevant? -->
Recently {{As of|2006|lc=on}}, various program analyses such as live variable analysis have been solved using [[Datalog]]. The Datalog specifications for such analyses are generally an order of magnitude shorter than their imperative counterparts (e.g. [[iterative analysis]]), and are at least as efficient.<ref>{{cite book | author=Whaley | title=Using Datalog with Binary Decision Diagrams for Program Analysis | year=2004 | display-authors=1}}</ref>
 
==References==
<references/>
 
[[Category:Data-flow analysis]]

Revision as of 03:14, 6 September 2013

In compiler theory, live variable analysis (or simply liveness analysis) is a classic data-flow analysis performed by compilers to calculate for each program point the variables that may be potentially read before their next write, that is, the variables that are live at the exit from each program point.

Stated simply: a variable is live if it holds a value that may be needed in the future.

It is a "backwards way" analysis. The analysis is done in a backwards order, and the dataflow confluence operator is set union.

The set of live variables at line L3 is {b, c} because both are used in the addition, and thereby the call to f and assignment to a. But the set of live variables at line L1 is only {b} since variable c is updated in L2. The value of variable a is never used. Note that f may be stateful, so the never-live assignment to a can be eliminated, but there is insufficient information to rule on the entirety of L3.

L1: b := 3;
L2: c := 5;
L3: a := f(b + c);
goto L1;

The dataflow equations used for a given basic block s and exiting block f in live variable analysis are the following:

GEN[s]: The set of variables that are used in s before any assignment.
KILL[s]: The set of variables that are assigned a value in s (in many books, KILL (s) is also defined as the set of variables assigned a value in s before any use, but this doesn't change the solution of the dataflow equation):


LIVEin[s]=GEN[s](LIVEout[s]KILL[s])
LIVEout[final]=
LIVEout[s]=psucc[S]LIVEin[p]
GEN[d:yf(x1,,xn)]={x1,...,xn}
KILL[d:yf(x1,,xn)]={y}

The in-state of a block is the set of variables that are live at the start of the block. Its out-state is the set of variables that are live at the end of it. The out-state is the union of the in-states of the block's successors. The transfer function of a statement is applied by making the variables that are written dead, then making the variables that are read live.

// in: {}
b1: a = 3; 
    b = 5;
    d = 4;
    x = 100; //x is never being used later thus not in the out set {a,b,d}
    if a > b then
// out: {a,b,d}    //union of all (in) successors of b1 => b2: {a,b}, and b3:{b,d}  

// in: {a,b}
b2: c = a + b;
    d = 2;
// out: {b,d}

// in: {b,d}
b3: endif
    c = 4;
    return b * d + c;
// out:{}

The in-state of b3 only contains b and d, since c has been written. The out-state of b1 is the union of the in-states of b2 and b3. The definition of c in b2 can be removed, since c is not live immediately after the statement.

Solving the data flow equations starts with initializing all in-states and out-states to the empty set. The work list is initialized by inserting the exit point (b3) in the work list (typical for backward flow). Its computed out-state differs from the previous one, so its predecessors b1 and b2 are inserted and the process continues. The progress is summarized in the table below.

processing out-state old in-state new in-state work list
b3 {} {} {b,d} (b1,b2)
b1 {b,d} {} {} (b2)
b2 {b,d} {} {a,b} (b1)
b1 {a,b,d} {} {} ()

Note that b1 was entered in the list before b2, which forced processing b1 twice (b1 was re-entered as predecessor of b2). Inserting b2 before b1 would have allowed earlier completion.

Initializing with the empty set is an optimistic initialization: all variables start out as dead. Note that the out-states cannot shrink from one iteration to the next, although the out-state can be smaller than the in-state. This can be seen from the fact that after the first iteration the out-state can only change by a change of the in-state. Since the in-state starts as the empty set, it can only grow in further iterations.

Recently Template:As of, various program analyses such as live variable analysis have been solved using Datalog. The Datalog specifications for such analyses are generally an order of magnitude shorter than their imperative counterparts (e.g. iterative analysis), and are at least as efficient.[1]

References

  1. 20 year-old Real Estate Agent Rusty from Saint-Paul, has hobbies and interests which includes monopoly, property developers in singapore and poker. Will soon undertake a contiki trip that may include going to the Lower Valley of the Omo.

    My blog: http://www.primaboinca.com/view_profile.php?userid=5889534