[pypy-svn] extradoc extradoc: use index notation for SSA variables everywhere

cfbolz commits-noreply at bitbucket.org
Sun Mar 27 00:45:57 CET 2011


Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: extradoc
Changeset: r3422:78b4e79a3817
Date: 2011-03-27 00:45 +0100
http://bitbucket.org/pypy/extradoc/changeset/78b4e79a3817/

Log:	use index notation for SSA variables everywhere

diff --git a/talk/icooolps2011/code/trace3.tex b/talk/icooolps2011/code/trace3.tex
--- a/talk/icooolps2011/code/trace3.tex
+++ b/talk/icooolps2011/code/trace3.tex
@@ -1,23 +1,23 @@
 \begin{Verbatim}
-# inst.getattr("a")
-map1 = inst.map
-guard(map1 == 0xb74af4a8)
-storage1 = inst.storage
-result1 = storage1[0]
+# $inst_1$.getattr("a")
+$map_1$ = $inst_1$.map
+guard($map_1$ == 0xb74af4a8)
+$storage_1$ = $inst_1$.storage
+$result_1$ = $storage_1$[0]
 
-# inst.getattr("b")
-cls1 = inst.cls
-methods1 = cls1.methods
-result2 = dict.get(methods1, "b")
-guard(result2 is not None)
-v2 = result1 + result2
+# $inst_1$.getattr("b")
+$cls_1$ = $inst_1$.cls
+$methods_1$ = $cls_1$.methods
+$result_2$ = dict.get($methods_1$, "b")
+guard($result_2$ is not None)
+$v_2$ = $result_1$ + $result_2$
 
-# inst.getattr("c")
-cls2 = inst.cls
-methods2 = cls2.methods
-result3 = dict.get(methods2, "c")
-guard(result3 is not None)
+# $inst_1$.getattr("c")
+$cls_2$ = $inst_1$.cls
+$methods_2$ = $cls_2$.methods
+$result_3$ = dict.get($methods_2$, "c")
+guard($result_3$ is not None)
 
-v4 = v2 + result3
-return(v4)
+$v_4$ = $v_2$ + $result_3$
+return($v_4$)
 \end{Verbatim}

diff --git a/talk/icooolps2011/code/trace2.tex b/talk/icooolps2011/code/trace2.tex
--- a/talk/icooolps2011/code/trace2.tex
+++ b/talk/icooolps2011/code/trace2.tex
@@ -1,33 +1,33 @@
-\begin{lstlisting}[escapechar=|,basicstyle=\ttfamily]]
-# inst.getattr("a")
-map1 = inst.map
-guard(map1 == 0xb74af4a8)
-|{\color{gray}index1 = Map.getindex(map1, "a")}|
-|{\color{gray}guard(index1 != -1)}|
-storage1 = inst.storage
-result1 = storage1[index1]
+\begin{lstlisting}[mathescape,escapechar=|,basicstyle=\ttfamily]]
+# $inst_1$.getattr("a")
+$map_1$ = $inst_1$.map
+guard($map_1$ == 0xb74af4a8)
+|{\color{gray}$index_1$ = Map.getindex($map_1$, "a")}|
+|{\color{gray}guard($index_1$ != -1)}|
+$storage_1$ = $inst_1$.storage
+$result_1$ = $storage_1$[$index_1$]
 
-# inst.getattr("b")
-|{\color{gray}map2 = inst.map}|
-|{\color{gray}guard(map2 == 0xb74af4a8)}|
-|{\color{gray}index2 = Map.getindex(map2, "b")}|
-|{\color{gray}guard(index2 == -1)}|
-cls1 = inst.cls
-methods1 = cls.methods
-result2 = dict.get(methods1, "b")
-guard(result2 is not None)
-v2 = result1 + result2
+# $inst_1$.getattr("b")
+|{\color{gray}$map_2$ = $inst_1$.map}|
+|{\color{gray}guard($map_2$ == 0xb74af4a8)}|
+|{\color{gray}$index_2$ = Map.getindex($map_2$, "b")}|
+|{\color{gray}guard($index_2$ == -1)}|
+$cls_1$ = $inst_1$.cls
+$methods_1$ = $cls_1$.methods
+$result_2$ = dict.get($methods_1$, "b")
+guard($result_2$ is not None)
+$v_2$ = $result_1$ + $result_2$
 
-# inst.getattr("c")
-|{\color{gray}map3 = inst.map}|
-|{\color{gray}guard(map3 == 0xb74af4a8)}|
-|{\color{gray}index3 = Map.getindex(map3, "c")}|
-|{\color{gray}guard(index3 == -1)}|
-cls1 = inst.cls
-methods2 = cls.methods
-result3 = dict.get(methods2, "c")
-guard(result3 is not None)
+# $inst_1$.getattr("c")
+|{\color{gray}$map_3$ = $inst_1$.map}|
+|{\color{gray}guard($map_3$ == 0xb74af4a8)}|
+|{\color{gray}$index_3$ = Map.getindex($map_3$, "c")}|
+|{\color{gray}guard($index_3$ == -1)}|
+$cls_2$ = $inst_1$.cls
+$methods_2$ = $cls_2$.methods
+$result_3$ = dict.get($methods_2$, "c")
+guard($result_3$ is not None)
 
-v4 = v2 + result3
-return(v4)
+$v_4$ = $v_2$ + $result_3$
+return($v_4$)
 \end{lstlisting}

diff --git a/talk/icooolps2011/code/trace5.tex b/talk/icooolps2011/code/trace5.tex
--- a/talk/icooolps2011/code/trace5.tex
+++ b/talk/icooolps2011/code/trace5.tex
@@ -1,18 +1,18 @@
 \begin{lstlisting}[mathescape,basicstyle=\ttfamily]
-# inst.getattr("a")
-map1 = inst.map
-guard(map1 == 0xb74af4a8)
-storage1 = inst.storage
-result1 = storage1[0]
+# $inst_1$.getattr("a")
+$map_1$ = $inst_1$.map
+guard($map_1$ == 0xb74af4a8)
+$storage_1$ = $inst_1$.storage
+$result_1$ = $storage_1$[0]
 
-# inst.getattr("b")
-cls1 = inst.cls
-guard(cls1 == 0xb7aaaaf8)
-version1 = cls1.version
-guard(version1 == 0xb7bbbb18)
-v2 = result1 + 41
+# $inst_1$.getattr("b")
+$cls_1$ = $inst_1$.cls
+guard($cls_1$ == 0xb7aaaaf8)
+$version_1$ = $cls_1$.version
+guard($version_1$ == 0xb7bbbb18)
+$v_2$ = $result_1$ + 41
 
-# inst.getattr("c")
-v4 = v2 + 17
-return(v4)
+# $inst_1$.getattr("c")
+$v_4$ = $v_2$ + 17
+return($v_4$)
 \end{lstlisting}

diff --git a/talk/icooolps2011/code/trace4.tex b/talk/icooolps2011/code/trace4.tex
--- a/talk/icooolps2011/code/trace4.tex
+++ b/talk/icooolps2011/code/trace4.tex
@@ -1,37 +1,37 @@
 \begin{lstlisting}[escapechar=|,mathescape,basicstyle=\ttfamily]
-# inst.getattr("a")
-map1 = inst.map
-guard(map1 == 0xb74af4a8)
-|{\color{gray}index1 = Map.getindex(map1, "a")}|
-|{\color{gray}guard(index1 != -1)}|
-storage1 = inst.storage
-result1 = storage1[index1]
+# $inst_1$.getattr("a")
+$map_1$ = $inst_1$.map
+guard($map_1$ == 0xb74af4a8)
+|{\color{gray}$index_1$ = Map.getindex($map_1$, "a")}|
+|{\color{gray}guard($index_1$ != -1)}|
+$storage_1$ = $inst_1$.storage
+$result_1$ = $storage_1$[$index_1$]
 
-# inst.getattr("b")
-|{\color{gray}map2 = inst.map}|
-|{\color{gray}guard(map2 == 0xb74af4a8)}|
-|{\color{gray}index2 = Map.getindex(map2, "b")}|
-|{\color{gray}guard(index2 == -1)}|
-cls1 = inst.cls
-guard(cls1 == 0xb7aaaaf8)
-version1 = cls1.version
-guard(version1 == 0xb7bbbb18)
-|{\color{gray}result2 = Class.\_find\_method(cls, "b", version1)}|
-|{\color{gray}guard(result2 is not None)}|
-v2 = result1 + result2
+# $inst_1$.getattr("b")
+|{\color{gray}$map_2$ = $inst_1$.map}|
+|{\color{gray}guard($map_2$ == 0xb74af4a8)}|
+|{\color{gray}$index_2$ = Map.getindex($map_2$, "b")}|
+|{\color{gray}guard($index_2$ == -1)}|
+$cls_1$ = $inst_1$.cls
+guard($cls_1$ == 0xb7aaaaf8)
+$version_1$ = $cls_1$.version
+guard($version_1$ == 0xb7bbbb18)
+|{\color{gray}$result_2$ = Class.\_find\_method($cls_1$, "b", $version_1$)}|
+|{\color{gray}guard($result_2$ is not None)}|
+$v_2$ = $result_1$ + $result_2$
 
-# inst.getattr("c")
-|{\color{gray}map3 = inst.map}|
-|{\color{gray}guard(map3 == 0xb74af4a8)}|
-|{\color{gray}index3 = Map.getindex(map3, "c")}|
-|{\color{gray}guard(index3 == -1)}|
-|{\color{gray}cls2 = inst.cls}|
-|{\color{gray}guard(cls2 == 0xb7aaaaf8)}|
-|{\color{gray}version2 = cls2.version}|
-|{\color{gray}guard(version2 == 0xb7bbbb18)}|
-|{\color{gray}result3 = Class.\_find\_method(cls, "c", version2)}|
-|{\color{gray}guard(result3 is not None)}|
+# $inst_1$.getattr("c")
+|{\color{gray}$map_3$ = $inst_1$.map}|
+|{\color{gray}guard($map_3$ == 0xb74af4a8)}|
+|{\color{gray}$index_3$ = Map.getindex($map_3$, "c")}|
+|{\color{gray}guard($index_3$ == -1)}|
+|{\color{gray}$cls_2$ = $inst_1$.cls}|
+|{\color{gray}guard($cls_2$ == 0xb7aaaaf8)}|
+|{\color{gray}$version_2$ = $cls_2$.version}|
+|{\color{gray}guard($version_2$ == 0xb7bbbb18)}|
+|{\color{gray}$result_3$ = Class.\_find\_method($cls_2$, "c", $version_2$)}|
+|{\color{gray}guard($result_3$ is not None)}|
 
-v4 = v2 + result3
-return(v4)
+$v_4$ = $v_2$ + $result_3$
+return($v_4$)
 \end{lstlisting}

diff --git a/talk/icooolps2011/paper.tex b/talk/icooolps2011/paper.tex
--- a/talk/icooolps2011/paper.tex
+++ b/talk/icooolps2011/paper.tex
@@ -382,17 +382,17 @@
     y = y + x
 \end{lstlisting}
 
-If the fragment is traced with \texttt{x} being \texttt{4}, the following trace is
+If the fragment is traced with $x_1$ being \texttt{4}, the following trace is
 produced:
 %
 \begin{lstlisting}[mathescape,basicstyle=\ttfamily]
-guard(x == 4)
-y = y + x
+guard($x_1$ == 4)
+$y_2$ = $y_1$ + $x_1$
 \end{lstlisting}
 
-In the trace above, the value of \texttt{x} is statically known thanks to the
+In the trace above, the value of $x_1$ is statically known thanks to the
 guard. Remember that a guard is a runtime check. The above trace will run to
-completion when \texttt{x == 4}. If the check fails, execution of the trace is
+completion when $x_1$ \texttt{== 4}. If the check fails, execution of the trace is
 stopped and the interpreter continues to run.
 
 There are cases in which it is useful to turn an arbitrary variable
@@ -410,7 +410,7 @@
 
 Let's make this more concrete. If we trace a call to the following function:
 \begin{lstlisting}[mathescape,basicstyle=\ttfamily]
-def f2(x, y):
+def f1(x, y):
     z = x * 2 + 1
     return z + y
 \end{lstlisting}
@@ -418,18 +418,18 @@
 We get a trace that looks like this:
 
 \begin{lstlisting}[mathescape,basicstyle=\ttfamily]
-v1 = x * 2
-z = v1 + 1
-v2 = z + y
-return(v2)
+$v_1$ = $x_1$ * 2
+$z_1$ = $v_1$ + 1
+$v_2$ = $z_1$ + $y_1$
+return($v_2$)
 \end{lstlisting}
 
 Observe how the first two operations could be constant-folded if the value of
-\texttt{x} were known. Let's assume that the value of \texttt{x} can vary, but does so
+$x_1$ were known. Let's assume that the value of \texttt{x} in the Python code can vary, but does so
 rarely, i.e. only takes a few different values at runtime. If this is the
 case, we can add a hint to promote \texttt{x}, like this:
 \begin{lstlisting}[mathescape,basicstyle=\ttfamily]
-def f2(x, y):
+def f1(x, y):
     x = hint(x, promote=True)
     z = x * 2 + 1
     return z + y
@@ -444,44 +444,44 @@
 operation at the beginning:
 
 \begin{lstlisting}[mathescape,basicstyle=\ttfamily]
-guard(x == 4)
-v1 = x * 2
-z = v1 + 1
-v2 = z + y
+guard($x_1$ == 4)
+$v_1$ = $x_1$ * 2
+$z_1$ = $v_1$ + 1
+$v_2$ = $z_1$ + $y_1$
 return(v2)
 \end{lstlisting}
 
 The promotion is turned into a \texttt{guard} operation in the trace. The guard
-captures the value of \texttt{x} as it was at runtime. From the point of view of the
+captures the value of $x_1$ as it was at runtime. From the point of view of the
 optimizer, this guard is not any different than the one produced by the \texttt{if}
 statement in the example above. After the guard, the rest of the trace can
-assume that \texttt{x} is equal to \texttt{4}, meaning that the optimizer will turn this
+assume that $x_1$ is equal to \texttt{4}, meaning that the optimizer will turn this
 trace into:
 
 \begin{lstlisting}[mathescape,basicstyle=\ttfamily]
-guard(x == 4)
-v2 = 9 + y
-return(v2)
+guard($x_1$ == 4)
+$v_2$ = 9 + $y_1$
+return($v_2$)
 \end{lstlisting}
 
 Notice how the first two arithmetic operations were constant folded. The hope is
 that the guard is executed quicker than the multiplication and the addition that
 was now optimized away.
 
-If this trace is executed with values of \texttt{x} other than \texttt{4}, the guard will
+If this trace is executed with values of $x_1$ other than \texttt{4}, the guard will
 fail, and execution will continue in the interpreter. If the guard fails often
 enough, a new trace will be started from the guard. This other trace will
-capture a different value of \texttt{x}. If it is e.g. \texttt{2}, then the optimized
+capture a different value of $x_1$. If it is e.g. \texttt{2}, then the optimized
 trace looks like this:
 
 \begin{lstlisting}[mathescape,basicstyle=\ttfamily]
-guard(x == 2)
-v2 = 5 + y
-return(v2)
+guard($x_1$ == 2)
+$v_2$ = 5 + $y_1$
+return($v_2$)
 \end{lstlisting}
 
 This new trace will be attached to the guard instruction of the first trace. If
-\texttt{x} takes on even more values, a new trace will eventually be made for all of them,
+$x_1$ takes on even more values, a new trace will eventually be made for all of them,
 linking them into a chain. This is clearly not desirable, so we should promote
 only variables that don't vary much. However, adding a promotion hint will never produce wrong
 results. It might just lead to too much assembler code.
@@ -527,15 +527,15 @@
 trace (note how the call to \texttt{compute} is inlined):
 %
 \begin{lstlisting}[mathescape,basicstyle=\ttfamily]
-x = a.x
-v1 = x * 2
-v2 = v1 + 1
-v3 = v2 + val
-a.y = v3
+$x_1$ = $a_1$.x
+$v_1$ = $x_1$ * 2
+$v_2$ = $v_1$ + 1
+$v_3$ = $v_2$ + $val_1$
+$a_1$.y = $v_3$
 \end{lstlisting}
 
 In this case, adding a promote of \texttt{self} in the \texttt{f} method to get rid of the
-computation of the first few operations does not help. Even if \texttt{a} is a
+computation of the first few operations does not help. Even if $a_1$ is a
 constant reference to an object, reading the \texttt{x} field does not necessarily
 always yield the same value. To solve this problem, there is another annotation,
 which lets the interpreter author communicate invariants to the optimizer. In
@@ -562,10 +562,10 @@
 Now the trace will look like this:
 %
 \begin{lstlisting}[mathescape,basicstyle=\ttfamily]
-guard(a == 0xb73984a8)
-v1 = compute(a)
-v2 = v1 + val
-a.y = v2
+guard($a_1$ == 0xb73984a8)
+$v_1$ = compute($a_1$)
+$v_2$ = $v_1$ + $val_1$
+$a_1$.y = $v_2$
 \end{lstlisting}
 
 Here, \texttt{0xb73984a8} is the address of the instance of \texttt{A} that was used
@@ -576,9 +576,9 @@
 trace looks like this:
 %
 \begin{lstlisting}[mathescape,basicstyle=\ttfamily]
-guard(a == 0xb73984a8)
-v2 = 9 + val
-a.y = v2
+guard($a_1$ == 0xb73984a8)
+$v_2$ = 9 + $val_1$
+$a_1$.y = $v_2$
 \end{lstlisting}
 
 (assuming that the \texttt{x} field's value is \texttt{4}).


More information about the Pypy-commit mailing list