[pypy-commit] extradoc extradoc: merge
Author: Hakan Ardo Branch: extradoc Changeset: r5465:206c058dcb38 Date: 2014-11-21 09:50 +0100 http://bitbucket.org/pypy/extradoc/changeset/206c058dcb38/ Log:merge diff --git a/blog/draft/io-improvements.rst b/blog/draft/io-improvements.rst new file mode 100644 --- /dev/null +++ b/blog/draft/io-improvements.rst @@ -0,0 +1,88 @@ + +Hello everyone! + +We've wrapped up the Warsaw sprint, so I would like to describe some +branches which have been recently merged and which improved the I/O and the +GC: `gc_no_cleanup_nursery`_ and `gc-incminimark-pinning`_. + +.. _`gc_no_cleanup_nursery`: https://bitbucket.org/pypy/pypy/commits/9e2f7a37c1e2 +.. _`gc-incminimark-pinning`: https://bitbucket.org/pypy/pypy/commits/64017d818038 + +The first branch was started by Wenzhu Man for her Google Summer of Code +and finished by Maciej Fijałkowski and Armin Rigo. +The PyPy GC works by allocating new objects in the young object +area (the nursery), simply by incrementing a pointer. After each minor +collection, the nursery has to be cleaned up. For simplicity, the GC used +to do it by zeroing the whole nursery. + +This approach has bad effects on the cache, since you zero a large piece of +memory at once and do unnecessary work for things that don't require zeroing +like large strings. We mitigated the first problem somewhat with incremental +nursery zeroing, but this branch removes the zeroing completely, thus +improving the string handling and recursive code (since jitframes don't +requires zeroed memory either). I measured the effect on two examples: +a recursive implementation of `fibonacci`_ and `gcbench`_, +to measure GC performance. + +.. _`fibonacci`: https://bitbucket.org/pypy/benchmarks/src/69152c2aee7766051aab15735b0b82a46b82b802/own/fib.py?at=default +.. _`gcbench`: https://bitbucket.org/pypy/benchmarks/src/69152c2aee7766051aab15735b0b82a46b82b802/own/gcbench.py?at=default + +The results for fibonacci and gcbench are below (normalized to cpython +2.7). Benchmarks were run 50 times each (note that the big standard +deviation comes mostly from the warmup at the beginning, true figures +are smaller): + +++- +-++ +| benchmark | CPython | PyPy 2.4| PyPy non-zero | +++--+-++ +| fibonacci | 4.8+-0.15 (1.0x) | 0.59+-0.07 (8.1x) | 0.45+-0.07 (10.6x) | +++--+-++ +| gcbench| 22+-0.36 (1.0x) | 1.34+-0.28 (16.4x) | 1.02+-0.15 (21.6x) | +++--+-++ + +The second branch was done by Gregor Wegberg for his master thesis and finished +by Maciej Fijałkowski and Armin Rigo. Because of the way it works, the PyPy GC from +time to time moves the objects in memory, meaning that their address can change. +Therefore, if you want to pass pointers to some external C function (for +example, write(2) or read(2)), you need to ensure that the objects they are +pointing to will not be moved by the GC (e.g. when running a different thread). +PyPy up to 2.4 solves the problem by copying the data into or from a non-movable buffer, which +is obviously inefficient. +The branch introduce the concept of "pinning", which allows us to inform the +GC that it is not allowed to move a certain object for a short period of time. +This introduces a bit of extra complexity +in the garbage collector, but improves the I/O performance quite drastically, +because we no longer need the extra copy to and from the non-movable buffers. + +In `this benchmark`_, which does I/O in a loop, +we either write a number of bytes from a freshly allocated string into +/dev/null or read a number of bytes from /dev/full. I'm showing the results +for PyPy 2.4, PyPy with non-zero-nursery and PyPy with non-zero-nursery and +object pinning. Those are wall times for cases using ``os.read/os.write`` +and ``file.read/file.write``, normalized against CPython 2.7. + +Benchmarks were done using PyPy 2.4 and revisions ``85646d1d07fb`` for +non-zero-nursery and ``3d8fe96dc4d9`` for non-zero-nursery and pinning. +The benchmarks were run once, since the standard deviation was small. + + + +What we can see is that ``os.read`` and ``os.write`` both improved greatly +and outperforms CPython now for each combination. ``file`` operations are +a little more tricky, and while those branches improved the situation a bit, +the improvement is not as drastic as in ``os`` versions. It really should not +be the case and it showcases how our ``file`` buffering is inferior to CPython. +We plan on removing our own buffering and using ``FILE*`` in C in the near future, +so we should outperform CPython on those too (since our allocations are cheaper). +If you look carefully in the benchmark, the write function is copied three times
[pypy-commit] extradoc extradoc: numpy versions of these benchmarks
Author: Hakan Ardo Branch: extradoc Changeset: r5464:0fbd61901330 Date: 2014-11-21 09:50 +0100 http://bitbucket.org/pypy/extradoc/changeset/0fbd61901330/ Log:numpy versions of these benchmarks diff --git a/talk/dls2012/benchmarks/benchmark.sh b/talk/dls2012/benchmarks/benchmark.sh --- a/talk/dls2012/benchmarks/benchmark.sh +++ b/talk/dls2012/benchmarks/benchmark.sh @@ -59,13 +59,21 @@ #$* ./runner.py $EXTRA_OPTS convolution/convolution.py conv3 1 #$* ./runner.py $EXTRA_OPTS convolution/convolution.py conv5 1 $* ./runner.py $EXTRA_OPTS convolution/convolution.py conv3 100 +$* ./runner.py $EXTRA_OPTS convolution/convolution.py conv3_numpy 100 $* ./runner.py $EXTRA_OPTS convolution/convolution.py conv5 100 +$* ./runner.py $EXTRA_OPTS convolution/convolution.py conv5_numpy 100 $* ./runner.py $EXTRA_OPTS convolution/convolution.py conv3 1000 +$* ./runner.py $EXTRA_OPTS convolution/convolution.py conv3_numpy 1000 $* ./runner.py $EXTRA_OPTS convolution/convolution.py conv5 1000 +$* ./runner.py $EXTRA_OPTS convolution/convolution.py conv5_numpy 1000 $* ./runner.py $EXTRA_OPTS convolution/convolution.py conv3x3 100 3 +$* ./runner.py $EXTRA_OPTS convolution/convolution.py conv3x3_numpy 100 3 $* ./runner.py $EXTRA_OPTS convolution/convolution.py conv3x3 1000 1000 +$* ./runner.py $EXTRA_OPTS convolution/convolution.py conv3x3_numpy 1000 1000 $* ./runner.py $EXTRA_OPTS convolution/convolution.py dilate3x3 1000 1000 +$* ./runner.py $EXTRA_OPTS convolution/convolution.py dilate3x3_numpy 1000 1000 $* ./runner.py $EXTRA_OPTS convolution/convolution.py sobel_magnitude 1000 1000 +$* ./runner.py $EXTRA_OPTS convolution/convolution.py sobel_magnitude_numpy 1000 1000 #$* ./runner.py $EXTRA_OPTS image/noborder.py main NoBorderImagePadded #$* ./runner.py $EXTRA_OPTS image/noborder.py main NoBorderImagePadded iter #$* ./runner.py $EXTRA_OPTS image/noborder.py main NoBorderImagePadded range diff --git a/talk/dls2012/benchmarks/convolution/convolution.py b/talk/dls2012/benchmarks/convolution/convolution.py --- a/talk/dls2012/benchmarks/convolution/convolution.py +++ b/talk/dls2012/benchmarks/convolution/convolution.py @@ -1,5 +1,13 @@ from array import array from math import log10, sqrt +try: +import numpy as np +except ImportError: +try: +import numpypy as np +except ImportError: +print "Cant find nympy" + def _conv3(a, k, n=1): assert len(k)==3 @@ -14,7 +22,22 @@ n = int(args[0]) _conv3(array('d', [1]) * (1/n), array('d', [-1, 0, 1]), n) -return 'conv3(array(1e%d))' % log10(1/n) +return 'conv3(array.array(1e%d))' % log10(1/n) + +def _conv3_numpy(a, k, n=1): +assert len(k)==3 +b = np.zeros(len(a) - 2, a.dtype) +while n: +n -= 1 +for i in xrange(len(b)): +b[i] = k[2]*a[i] + k[1]*a[i+1] + k[0]*a[i+2] +return b + +def conv3_numpy(args): +n = int(args[0]) +_conv3_numpy(np.ones(1/n, 'd'), + np.array([-1, 0, 1], 'd'), n) +return 'conv3(numpy.array(1e%d))' % log10(1/n) def _conv5(a, k, n=1): assert len(k)==5 @@ -29,7 +52,22 @@ n = int(args[0]) _conv5(array('d', [1]) * (1/n), array('d', [1, 4, 6, 4, 1]), n) -return 'conv5(array(1e%d))' % log10(1/n) +return 'conv5(array.array(1e%d))' % log10(1/n) + +def _conv5_numpy(a, k, n=1): +assert len(k)==5 +b = np.zeros(len(a) - 4, a.dtype) +while n: +n -= 1 +for i in xrange(len(b)): +b[i] = k[4]*a[i] + k[3]*a[i+1] + k[2]*a[i+2] + k[1]*a[i+3] + k[0]*a[i+4] +return b + +def conv5_numpy(args): +n = int(args[0]) +_conv5_numpy(np.ones(1/n, 'd'), + np.array([1, 4, 6, 4, 1], 'd'), n) +return 'conv5(numpy.array(1e%d))' % log10(1/n) class Array2D(object): def __init__(self, w, h, data=None): @@ -71,13 +109,16 @@ def __init__(self, w, h): self.width = w self.height = h -import numpypy -self.data = numpypy.zeros([h, w], 'd') +self.data = np.zeros([h, w], 'd') def __getitem__(self, (x, y)): +if x < 0 or y < 0: +raise IndexError return self.data[y, x] def __setitem__(self, (x, y), val): +if x < 0 or y < 0: +raise IndexError self.data[y, x] = val def _conv3x3(a, b, k): @@ -125,6 +166,13 @@ _dilate3x3(a, b, Array2D(3,3)) return 'dilate3x3(Array2D(%sx%s))' % tuple(args) +def dilate3x3_numpy(args): +a = NumpyArray(int(args[0]), int(args[1])) +b = NumpyArray(a.width, a.height) +for i in range(10): +_dilate3x3(a, b, NumpyArray(3,3)) +return 'dilate3x3(NumpyArray(%sx%s))' % tuple(args) + def _sobel_magnitude(a): b = Array2D(a.width, a.height) for y in xrange(1, a.height-1): @@ -141,3 +189,8 @@ for i in
[pypy-commit] extradoc extradoc: last few results
Author: Hakan Ardo Branch: extradoc Changeset: r5466:7559563b6034 Date: 2014-11-21 13:21 +0100 http://bitbucket.org/pypy/extradoc/changeset/7559563b6034/ Log:last few results diff --git a/talk/dls2012/benchmarks/iter/result-2.4.0.txt b/talk/dls2012/benchmarks/iter/result-2.4.0.txt --- a/talk/dls2012/benchmarks/iter/result-2.4.0.txt +++ b/talk/dls2012/benchmarks/iter/result-2.4.0.txt @@ -88,3 +88,13 @@ pypy iter/nditer.py sum1d: 61.2064362049 +- 0.578041254203 sum2d: 71.1426748753 +- 1.09482960038 +whsum2d: 73.6043967247 +- 0.592259791238 +wsum1d: 62.5866453171 +- 0.677394146874 +wsum2d: 71.0087907314 +- 0.309482073549 +xsum1d: 63.4650315285 +- 0.844882977961 +xsum2d: 72.2017237663 +- 0.807526950608 +xysum2d: 71.3824438095 +- 0.28602305068 +mean1d: 83.7468230247 +- 2.77559774136 +median1d: 84.9599477768 +- 0.460831996712 +ripple1d: 83.2095424175 +- 0.427835447938 +ripple2d: 107.806012583 +- 1.06730555212 ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] extradoc extradoc: iteration becnhmakrs
Author: Hakan Ardo Branch: extradoc Changeset: r3955:17ee08a6ac71 Date: 2011-11-01 16:04 +0100 http://bitbucket.org/pypy/extradoc/changeset/17ee08a6ac71/ Log:iteration becnhmakrs diff --git a/talk/iwtc11/benchmarks/image/numpy_compare.py b/talk/iwtc11/benchmarks/image/numpy_compare.py --- a/talk/iwtc11/benchmarks/image/numpy_compare.py +++ b/talk/iwtc11/benchmarks/image/numpy_compare.py @@ -63,8 +63,14 @@ else: self.extend(data) -def new(self): -return Image(self.width, self.height, self.typecode) +def new(self, width=None, height=None, typecode=None): +if width is None: +width = self.width +if height is None: +height = self.height +if typecode is None: +typecode = self.typecode +return Image(width, height, typecode) def clone(self): return Image(self.width, self.height, self.typecode, self) diff --git a/talk/iwtc11/benchmarks/iter/generator.py b/talk/iwtc11/benchmarks/iter/generator.py new file mode 100644 --- /dev/null +++ b/talk/iwtc11/benchmarks/iter/generator.py @@ -0,0 +1,104 @@ +from array import array + +def range1(n): +i = 0 +while i < n: +yield i +i += 1 + +def range2(w, h): +y = 0 +while y < h: +x = 0 +while x < w: +yield x, y +x += 1 +y += 1 + +def _sum1d(a): +sa = 0 +for i in range1(len(a)): +sa += a[i] + +def _xsum1d(a): +sa = 0 +for i in range1(len(a)): +sa += a[i] + i + +def _wsum1d(a): +sa = 0 +for i in range1(len(a)): +sa += a[i] + len(a) + +def _sum2d(a, w, h): +sa = 0 +for x, y in range2(w, h): +sa += a[y*w + x] + +def _wsum2d(a, w, h): +sa = 0 +for x, y in range2(w, h): +sa += a[y*w + x] + w + +def _xsum2d(a, w, h): +sa = 0 +for x, y in range2(w, h): +sa += a[y*w + x] + x + +def _whsum2d(a, w, h): +sa = 0 +for x, y in range2(w, h): +sa += a[y*w + x] + w + h + +def _xysum2d(a, w, h): +sa = 0 +for x, y in range2(w, h): +sa += a[y*w + x] + x + y + +def sum1d(args): +run1d(args, _sum1d) +return "sum1d" + +def xsum1d(args): +run1d(args, _xsum1d) +return "xsum1d" + +def wsum1d(args): +run1d(args, _wsum1d) +return "wsum1d" + +def sum2d(args): +run2d(args, _sum2d) +return "sum2d" + +def wsum2d(args): +run2d(args, _wsum2d) +return "wsum2d" + +def xsum2d(args): +run2d(args, _xsum2d) +return "xsum2d" + +def whsum2d(args): +run2d(args, _whsum2d) +return "whsum2d" + +def xysum2d(args): +run2d(args, _xysum2d) +return "xysum2d" + +def run1d(args, f): +a = array('d', [1]) * 1 +n = int(args[0]) +for i in xrange(n): +f(a) +return "sum1d" + +def run2d(args, f): +a = array('d', [1]) * 1 +n = int(args[0]) +for i in xrange(n): +f(a, 1, 1) +return "sum1d" + + diff --git a/talk/iwtc11/benchmarks/iter/generator2.py b/talk/iwtc11/benchmarks/iter/generator2.py new file mode 100644 --- /dev/null +++ b/talk/iwtc11/benchmarks/iter/generator2.py @@ -0,0 +1,104 @@ +from array import array + +def range1(n): +i = 0 +while i < n: +yield i +i += 1 + +def range2(w, h): +y = x = 0 +while y < h: +yield x, y +x += 1 +if x >= w: +x = 0 +y += 1 + +def _sum1d(a): +sa = 0 +for i in range1(len(a)): +sa += a[i] + +def _xsum1d(a): +sa = 0 +for i in range1(len(a)): +sa += a[i] + i + +def _wsum1d(a): +sa = 0 +for i in range1(len(a)): +sa += a[i] + len(a) + +def _sum2d(a, w, h): +sa = 0 +for x, y in range2(w, h): +sa += a[y*w + x] + +def _wsum2d(a, w, h): +sa = 0 +for x, y in range2(w, h): +sa += a[y*w + x] + w + +def _xsum2d(a, w, h): +sa = 0 +for x, y in range2(w, h): +sa += a[y*w + x] + x + +def _whsum2d(a, w, h): +sa = 0 +for x, y in range2(w, h): +sa += a[y*w + x] + w + h + +def _xysum2d(a, w, h): +sa = 0 +for x, y in range2(w, h): +sa += a[y*w + x] + x + y + +def sum1d(args): +run1d(args, _sum1d) +return "sum1d" + +def xsum1d(args): +run1d(args, _xsum1d) +return "xsum1d" + +def wsum1d(args): +run1d(args, _wsum1d) +return "wsum1d" + +def sum2d(args): +run2d(args, _sum2d) +return "sum2d" + +def wsum2d(args): +run2d(args, _wsum2d) +return "wsum2d" + +def xsum2d(args): +run2d(args, _xsum2d) +return "xsum2d" + +def whsum2d(args): +run2d(args, _whsum2d) +return "whsum2d" + +def xysum2d(args): +run2d(args, _xysum2d) +return "xysum2d" + +def run1d(args, f): +a = array('d', [1]) * 1 +n = int(args[0]) +for i in xrange(n): +f(a) +return "sum1d" + +def run2d(args, f): +a = array('d', [1]) * 1 +n = int(args[0]) +for i in xrange(n): +f(a, 1
[pypy-commit] extradoc extradoc: typo
Author: Hakan Ardo Branch: extradoc Changeset: r3957:ab6bc92f1d6d Date: 2011-11-01 22:07 +0100 http://bitbucket.org/pypy/extradoc/changeset/ab6bc92f1d6d/ Log:typo diff --git a/talk/iwtc11/benchmarks/iter/mean1d.c b/talk/iwtc11/benchmarks/iter/mean1d.c --- a/talk/iwtc11/benchmarks/iter/mean1d.c +++ b/talk/iwtc11/benchmarks/iter/mean1d.c @@ -20,6 +20,6 @@ double data[] = {-1.0, 1.0}; for (i=0; ihttp://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] extradoc extradoc: a few more becnhmarks and some results
Author: Hakan Ardo Branch: extradoc Changeset: r3956:94871ac1f542 Date: 2011-11-01 22:06 +0100 http://bitbucket.org/pypy/extradoc/changeset/94871ac1f542/ Log:a few more becnhmarks and some results diff --git a/talk/iwtc11/benchmarks/iter/generator.py b/talk/iwtc11/benchmarks/iter/generator.py --- a/talk/iwtc11/benchmarks/iter/generator.py +++ b/talk/iwtc11/benchmarks/iter/generator.py @@ -55,6 +55,35 @@ for x, y in range2(w, h): sa += a[y*w + x] + x + y +def _mean1d(a): +sa = 0 +for i in range1(len(a)): +sa = (i*sa + a[i])/(i + 1.0); + +def _median1d(a): +sa = 0 +for i in range1(len(a)): +if sa > a[i]: +sa -= 1.0/(i + 1.0) +elif sa < a[i]: +sa += 1.0/(i + 1.0) + +def _ripple1d(a): +sa = 0 +for i in range1(len(a)): +if sa > a[i]: +sa -= 0.1 +elif sa < a[i]: +sa += 0.1 + +def _ripple2d(a, w, h): +sa = 0 +for x, y in range2(w, h): +if sa > a[y*w + x]: +sa -= 0.1 +elif sa < a[y*w + x]: +sa += 0.1 + def sum1d(args): run1d(args, _sum1d) return "sum1d" @@ -87,15 +116,37 @@ run2d(args, _xysum2d) return "xysum2d" -def run1d(args, f): -a = array('d', [1]) * 1 +def mean1d(args): +run1d(args, _mean1d, [1, -1]) +return "mean1d" + +def median1d(args): +run1d(args, _median1d, [1, -1]) +return "median1d" + +def ripple1d(args): +run1d(args, _ripple1d, [1, -1]) +return "ripple1d" + +def ripple2d(args): +run2d(args, _ripple2d, [1, -1]) +return "ripple2d" + +def run1d(args, f, data=None): +if data: +a = array('d', data) * (1/len(data)) +else: +a = array('d', [1]) * 1 n = int(args[0]) for i in xrange(n): f(a) return "sum1d" -def run2d(args, f): -a = array('d', [1]) * 1 +def run2d(args, f, data=None): +if data: +a = array('d', data) * (1/len(data)) +else: +a = array('d', [1]) * 1 n = int(args[0]) for i in xrange(n): f(a, 1, 1) diff --git a/talk/iwtc11/benchmarks/iter/generator2.py b/talk/iwtc11/benchmarks/iter/generator2.py --- a/talk/iwtc11/benchmarks/iter/generator2.py +++ b/talk/iwtc11/benchmarks/iter/generator2.py @@ -30,6 +30,35 @@ for i in range1(len(a)): sa += a[i] + len(a) +def _mean1d(a): +sa = 0 +for i in range1(len(a)): +sa = (i*sa + a[i])/(i + 1.0); + +def _median1d(a): +sa = 0 +for i in range1(len(a)): +if sa > a[i]: +sa -= 1.0/(i + 1.0) +elif sa < a[i]: +sa += 1.0/(i + 1.0) + +def _ripple1d(a): +sa = 0 +for i in range1(len(a)): +if sa > a[i]: +sa -= 0.1 +elif sa < a[i]: +sa += 0.1 + +def _ripple2d(a, w, h): +sa = 0 +for x, y in range2(w, h): +if sa > a[y*w + x]: +sa -= 0.1 +elif sa < a[y*w + x]: +sa += 0.1 + def _sum2d(a, w, h): sa = 0 for x, y in range2(w, h): @@ -87,15 +116,37 @@ run2d(args, _xysum2d) return "xysum2d" -def run1d(args, f): -a = array('d', [1]) * 1 +def mean1d(args): +run1d(args, _mean1d, [1, -1]) +return "mean1d" + +def median1d(args): +run1d(args, _median1d, [1, -1]) +return "median1d" + +def ripple1d(args): +run1d(args, _ripple1d, [1, -1]) +return "ripple1d" + +def ripple2d(args): +run2d(args, _ripple2d, [1, -1]) +return "ripple2d" + +def run1d(args, f, data=None): +if data: +a = array('d', data) * (1/len(data)) +else: +a = array('d', [1]) * 1 n = int(args[0]) for i in xrange(n): f(a) return "sum1d" -def run2d(args, f): -a = array('d', [1]) * 1 +def run2d(args, f, data=None): +if data: +a = array('d', data) * (1/len(data)) +else: +a = array('d', [1]) * 1 n = int(args[0]) for i in xrange(n): f(a, 1, 1) diff --git a/talk/iwtc11/benchmarks/iter/iterator.py b/talk/iwtc11/benchmarks/iter/iterator.py --- a/talk/iwtc11/benchmarks/iter/iterator.py +++ b/talk/iwtc11/benchmarks/iter/iterator.py @@ -82,6 +82,36 @@ for x, y in range2(w, h): sa += a[y*w + x] + x + y +def _mean1d(a): +sa = 0 +for i in range1(len(a)): +sa = (i*sa + a[i])/(i + 1.0); + +def _median1d(a): +sa = 0 +for i in range1(len(a)): +if sa > a[i]: +sa -= 1.0/(i + 1.0) +elif sa < a[i]: +sa += 1.0/(i + 1.0) + +def _ripple1d(a): +sa = 0 +for i in range1(len(a)): +if sa > a[i]: +sa -= 0.1 +elif sa < a[i]: +sa += 0.1 + +def _ripple2d(a, w, h): +sa = 0 +for x, y in range2(w, h): +if sa > a[y*w + x]: +sa -= 0.1 +elif sa < a[y*w + x]: +sa += 0.1 + + def sum1d(args):
[pypy-commit] extradoc extradoc: minor fixes
Author: Hakan Ardo Branch: extradoc Changeset: r3958:6dbe2306c60f Date: 2011-11-02 08:24 +0100 http://bitbucket.org/pypy/extradoc/changeset/6dbe2306c60f/ Log:minor fixes diff --git a/talk/iwtc11/benchmarks/iter/generator.py b/talk/iwtc11/benchmarks/iter/generator.py --- a/talk/iwtc11/benchmarks/iter/generator.py +++ b/talk/iwtc11/benchmarks/iter/generator.py @@ -152,4 +152,7 @@ f(a, 1, 1) return "sum1d" +if __name__ == '__main__': +import sys +eval(sys.argv[1])(sys.argv[2:]) diff --git a/talk/iwtc11/benchmarks/iter/generator2.py b/talk/iwtc11/benchmarks/iter/generator2.py --- a/talk/iwtc11/benchmarks/iter/generator2.py +++ b/talk/iwtc11/benchmarks/iter/generator2.py @@ -152,4 +152,6 @@ f(a, 1, 1) return "sum1d" - +if __name__ == '__main__': +import sys +eval(sys.argv[1])(sys.argv[2:]) diff --git a/talk/iwtc11/benchmarks/iter/iterator.py b/talk/iwtc11/benchmarks/iter/iterator.py --- a/talk/iwtc11/benchmarks/iter/iterator.py +++ b/talk/iwtc11/benchmarks/iter/iterator.py @@ -180,3 +180,6 @@ f(a, 1, 1) return "sum1d" +if __name__ == '__main__': +import sys +eval(sys.argv[1])(sys.argv[2:]) diff --git a/talk/iwtc11/benchmarks/iter/range.py b/talk/iwtc11/benchmarks/iter/range.py --- a/talk/iwtc11/benchmarks/iter/range.py +++ b/talk/iwtc11/benchmarks/iter/range.py @@ -143,3 +143,6 @@ f(a, 1, 1) return "sum1d" +if __name__ == '__main__': +import sys +eval(sys.argv[1])(sys.argv[2:]) diff --git a/talk/iwtc11/benchmarks/iter/result.txt b/talk/iwtc11/benchmarks/iter/result.txt --- a/talk/iwtc11/benchmarks/iter/result.txt +++ b/talk/iwtc11/benchmarks/iter/result.txt @@ -10,7 +10,7 @@ mean1d: 12.246 +- 0.0955510334847 median1d: 8.712 +- 0.0383405790254 ripple1d: 2.534 +- 0.0167332005307 -ripple2d: 1.294 +- 0.00547722557505 +ripple2d: 2.644 +- 0.0219089023002 pypy iter/generator2.py sum1d: 23.9832116127 +- 0.614888065755 diff --git a/talk/iwtc11/benchmarks/iter/ripple2d.c b/talk/iwtc11/benchmarks/iter/ripple2d.c --- a/talk/iwtc11/benchmarks/iter/ripple2d.c +++ b/talk/iwtc11/benchmarks/iter/ripple2d.c @@ -23,6 +23,8 @@ int main(int ac, char **av) { double *a = malloc(W*H*sizeof(double)); int i, n = atoi(av[1]); + double data[] = {-1.0, 1.0}; + for (i=0; ihttp://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: failing test
Author: Hakan Ardo Branch: Changeset: r48669:a6f23c0ae3e6 Date: 2011-11-02 18:49 +0100 http://bitbucket.org/pypy/pypy/changeset/a6f23c0ae3e6/ Log:failing test diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py --- a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py +++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py @@ -7307,6 +7307,26 @@ """ self.optimize_loop(ops, expected) +def test_repeated_setfield_mixed_with_guard(self): +ops = """ +[p22, p18] +setfield_gc(p22, 2, descr=valuedescr) +guard_nonnull_class(p18, ConstClass(node_vtable)) [] +setfield_gc(p22, 2, descr=valuedescr) +jump(p22, p18) +""" +preamble = """ +[p22, p18] +setfield_gc(p22, 2, descr=valuedescr) +guard_nonnull_class(p18, ConstClass(node_vtable)) [] +jump(p22, p18) +""" +expected = """ +[p22, p18] +jump(p22, p18) +""" +self.optimize_loop(ops, expected, preamble) + class TestLLtype(OptimizeOptTest, LLtypeMixin): pass ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: interning ints aswell
Author: Hakan Ardo Branch: Changeset: r48681:d0466dedbb14 Date: 2011-11-03 07:34 +0100 http://bitbucket.org/pypy/pypy/changeset/d0466dedbb14/ Log:interning ints aswell diff --git a/pypy/jit/metainterp/optimizeopt/optimizer.py b/pypy/jit/metainterp/optimizeopt/optimizer.py --- a/pypy/jit/metainterp/optimizeopt/optimizer.py +++ b/pypy/jit/metainterp/optimizeopt/optimizer.py @@ -1,6 +1,6 @@ from pypy.jit.metainterp import jitprof, resume, compile from pypy.jit.metainterp.executor import execute_nonspec -from pypy.jit.metainterp.history import BoxInt, BoxFloat, Const, ConstInt, REF +from pypy.jit.metainterp.history import BoxInt, BoxFloat, Const, ConstInt, REF, INT from pypy.jit.metainterp.optimizeopt.intutils import IntBound, IntUnbounded, \ ImmutableIntUnbounded, \ IntLowerBound, MININT, MAXINT @@ -326,6 +326,7 @@ self.bridge = bridge self.values = {} self.interned_refs = self.cpu.ts.new_ref_dict() +self.interned_ints = {} self.resumedata_memo = resume.ResumeDataLoopMemo(metainterp_sd) self.bool_boxes = {} self.producer = {} @@ -398,6 +399,9 @@ if not value: return box return self.interned_refs.setdefault(value, box) +elif constbox.type == INT: +value = constbox.getint() +return self.interned_ints.setdefault(value, box) else: return box ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: test short preamble and non constant case aswell
Author: Hakan Ardo Branch: Changeset: r48682:9f81b789732c Date: 2011-11-03 07:50 +0100 http://bitbucket.org/pypy/pypy/changeset/9f81b789732c/ Log:test short preamble and non constant case aswell diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py --- a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py +++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py @@ -7355,7 +7355,7 @@ """ self.optimize_loop(ops, expected) -def test_repeated_setfield_mixed_with_guard(self): +def test_repeated_constant_setfield_mixed_with_guard(self): ops = """ [p22, p18] setfield_gc(p22, 2, descr=valuedescr) @@ -7369,11 +7369,48 @@ guard_nonnull_class(p18, ConstClass(node_vtable)) [] jump(p22, p18) """ +short = """ +[p22, p18] +i1 = getfield_gc(p22, descr=valuedescr) +guard_value(i1, 2) [] +jump(p22, p18) +""" expected = """ [p22, p18] jump(p22, p18) """ -self.optimize_loop(ops, expected, preamble) +self.optimize_loop(ops, expected, preamble, expected_short=short) + +def test_repeated_setfield_mixed_with_guard(self): +ops = """ +[p22, p18, i1] +i2 = getfield_gc(p22, descr=valuedescr) +call(i2, descr=nonwritedescr) +setfield_gc(p22, i1, descr=valuedescr) +guard_nonnull_class(p18, ConstClass(node_vtable)) [] +setfield_gc(p22, i1, descr=valuedescr) +jump(p22, p18, i1) +""" +preamble = """ +[p22, p18, i1] +i2 = getfield_gc(p22, descr=valuedescr) +call(i2, descr=nonwritedescr) +setfield_gc(p22, i1, descr=valuedescr) +guard_nonnull_class(p18, ConstClass(node_vtable)) [] +jump(p22, p18, i1, i1) +""" +short = """ +[p22, p18, i1] +i2 = getfield_gc(p22, descr=valuedescr) +jump(p22, p18, i1, i2) +""" +expected = """ +[p22, p18, i1, i2] +call(i2, descr=nonwritedescr) +setfield_gc(p22, i1, descr=valuedescr) +jump(p22, p18, i1, i1) +""" +self.optimize_loop(ops, expected, preamble, expected_short=short) class TestLLtype(OptimizeOptTest, LLtypeMixin): pass ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: corner case not handled very well
Author: Hakan Ardo Branch: Changeset: r48683:ce8c2eb5ccba Date: 2011-11-03 08:49 +0100 http://bitbucket.org/pypy/pypy/changeset/ce8c2eb5ccba/ Log:corner case not handled very well diff --git a/pypy/jit/metainterp/optimizeopt/optimizer.py b/pypy/jit/metainterp/optimizeopt/optimizer.py --- a/pypy/jit/metainterp/optimizeopt/optimizer.py +++ b/pypy/jit/metainterp/optimizeopt/optimizer.py @@ -95,6 +95,10 @@ return guards def import_from(self, other, optimizer): +if self.level == LEVEL_CONSTANT: +assert other.level == LEVEL_CONSTANT +assert other.box.same_constant(self.box) +return assert self.level <= LEVEL_NONNULL if other.level == LEVEL_CONSTANT: self.make_constant(other.get_key_box()) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: alternative fix that does not rely on interning ints
Author: Hakan Ardo Branch: Changeset: r48685:569f16f25b1b Date: 2011-11-03 09:10 +0100 http://bitbucket.org/pypy/pypy/changeset/569f16f25b1b/ Log:alternative fix that does not rely on interning ints diff --git a/pypy/jit/metainterp/optimizeopt/heap.py b/pypy/jit/metainterp/optimizeopt/heap.py --- a/pypy/jit/metainterp/optimizeopt/heap.py +++ b/pypy/jit/metainterp/optimizeopt/heap.py @@ -43,7 +43,7 @@ optheap.optimizer.ensure_imported(cached_fieldvalue) cached_fieldvalue = self._cached_fields.get(structvalue, None) -if cached_fieldvalue is not fieldvalue: +if not fieldvalue.same_value(cached_fieldvalue): # common case: store the 'op' as lazy_setfield, and register # myself in the optheap's _lazy_setfields_and_arrayitems list self._lazy_setfield = op diff --git a/pypy/jit/metainterp/optimizeopt/optimizer.py b/pypy/jit/metainterp/optimizeopt/optimizer.py --- a/pypy/jit/metainterp/optimizeopt/optimizer.py +++ b/pypy/jit/metainterp/optimizeopt/optimizer.py @@ -145,6 +145,13 @@ return not box.nonnull() return False +def same_value(self, other): +if not other: +return False +if self.is_constant() and other.is_constant(): +return self.box.same_constant(other.box) +return self is other + def make_constant(self, constbox): """Replace 'self.box' with a Const box.""" assert isinstance(constbox, Const) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: allow setarrayitem to update the cache exported from the preamble to the loop the same way setfield does
Author: Hakan Ardo Branch: Changeset: r48686:8b75e3ece413 Date: 2011-11-03 11:02 +0100 http://bitbucket.org/pypy/pypy/changeset/8b75e3ece413/ Log:allow setarrayitem to update the cache exported from the preamble to the loop the same way setfield does diff --git a/pypy/jit/metainterp/optimizeopt/heap.py b/pypy/jit/metainterp/optimizeopt/heap.py --- a/pypy/jit/metainterp/optimizeopt/heap.py +++ b/pypy/jit/metainterp/optimizeopt/heap.py @@ -140,6 +140,17 @@ getop = ResOperation(rop.GETFIELD_GC, [op.getarg(0)], result, op.getdescr()) shortboxes.add_potential(getop, synthetic=True) +if op.getopnum() == rop.SETARRAYITEM_GC: +result = op.getarg(2) +if isinstance(result, Const): +newresult = result.clonebox() +optimizer.make_constant(newresult, result) +result = newresult +if result is op.getarg(0): # FIXME: Unsupported corner case?? +continue +getop = ResOperation(rop.GETARRAYITEM_GC, [op.getarg(0), op.getarg(1)], + result, op.getdescr()) +shortboxes.add_potential(getop, synthetic=True) elif op.result is not None: shortboxes.add_potential(op) diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py --- a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py +++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py @@ -7412,6 +7412,44 @@ """ self.optimize_loop(ops, expected, preamble, expected_short=short) +def test_cache_setfield_across_loop_boundaries(self): +ops = """ +[p1] +p2 = getfield_gc(p1, descr=valuedescr) +guard_nonnull_class(p2, ConstClass(node_vtable)) [] +call(p2, descr=nonwritedescr) +p3 = new_with_vtable(ConstClass(node_vtable)) +setfield_gc(p1, p3, descr=valuedescr) +jump(p1) +""" +expected = """ +[p1, p2] +call(p2, descr=nonwritedescr) +p3 = new_with_vtable(ConstClass(node_vtable)) +setfield_gc(p1, p3, descr=valuedescr) +jump(p1, p3) +""" +self.optimize_loop(ops, expected) + +def test_cache_setarrayitem_across_loop_boundaries(self): +ops = """ +[p1] +p2 = getarrayitem_gc(p1, 3, descr=arraydescr) +guard_nonnull_class(p2, ConstClass(node_vtable)) [] +call(p2, descr=nonwritedescr) +p3 = new_with_vtable(ConstClass(node_vtable)) +setarrayitem_gc(p1, 3, p3, descr=arraydescr) +jump(p1) +""" +expected = """ +[p1, p2] +call(p2, descr=nonwritedescr) +p3 = new_with_vtable(ConstClass(node_vtable)) +setarrayitem_gc(p1, 3, p3, descr=arraydescr) +jump(p1, p3) +""" +self.optimize_loop(ops, expected) + class TestLLtype(OptimizeOptTest, LLtypeMixin): pass ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: dissable for now, it makes test_convert_from_SmallFunctionSetPBCRepr_to_FunctionsPBCRep fail
Author: Hakan Ardo Branch: Changeset: r48684:5fb2ee9b17b4 Date: 2011-11-03 09:01 +0100 http://bitbucket.org/pypy/pypy/changeset/5fb2ee9b17b4/ Log:dissable for now, it makes test_convert_from_SmallFunctionSetPBCRepr_to_FunctionsPBCRep fail diff --git a/pypy/jit/metainterp/optimizeopt/optimizer.py b/pypy/jit/metainterp/optimizeopt/optimizer.py --- a/pypy/jit/metainterp/optimizeopt/optimizer.py +++ b/pypy/jit/metainterp/optimizeopt/optimizer.py @@ -403,9 +403,9 @@ if not value: return box return self.interned_refs.setdefault(value, box) -elif constbox.type == INT: -value = constbox.getint() -return self.interned_ints.setdefault(value, box) +#elif constbox.type == INT: +#value = constbox.getint() +#return self.interned_ints.setdefault(value, box) else: return box ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: hg merge
Author: Hakan Ardo Branch: Changeset: r48687:9aea5197a2d6 Date: 2011-11-03 11:03 +0100 http://bitbucket.org/pypy/pypy/changeset/9aea5197a2d6/ Log:hg merge diff --git a/pypy/jit/backend/x86/regloc.py b/pypy/jit/backend/x86/regloc.py --- a/pypy/jit/backend/x86/regloc.py +++ b/pypy/jit/backend/x86/regloc.py @@ -17,7 +17,7 @@ class AssemblerLocation(object): # XXX: Is adding "width" here correct? -__slots__ = ('value', 'width') +_attrs_ = ('value', 'width', '_location_code') _immutable_ = True def _getregkey(self): return self.value @@ -25,6 +25,9 @@ def is_memory_reference(self): return self.location_code() in ('b', 's', 'j', 'a', 'm') +def location_code(self): +return self._location_code + def value_r(self): return self.value def value_b(self): return self.value def value_s(self): return self.value @@ -38,6 +41,8 @@ class StackLoc(AssemblerLocation): _immutable_ = True +_location_code = 'b' + def __init__(self, position, ebp_offset, num_words, type): assert ebp_offset < 0 # so no confusion with RegLoc.value self.position = position @@ -49,9 +54,6 @@ def __repr__(self): return '%d(%%ebp)' % (self.value,) -def location_code(self): -return 'b' - def assembler(self): return repr(self) @@ -63,8 +65,10 @@ self.is_xmm = is_xmm if self.is_xmm: self.width = 8 +self._location_code = 'x' else: self.width = WORD +self._location_code = 'r' def __repr__(self): if self.is_xmm: return rx86.R.xmmnames[self.value] @@ -79,12 +83,6 @@ assert not self.is_xmm return RegLoc(rx86.high_byte(self.value), False) -def location_code(self): -if self.is_xmm: -return 'x' -else: -return 'r' - def assembler(self): return '%' + repr(self) @@ -97,14 +95,13 @@ class ImmedLoc(AssemblerLocation): _immutable_ = True width = WORD +_location_code = 'i' + def __init__(self, value): from pypy.rpython.lltypesystem import rffi, lltype # force as a real int self.value = rffi.cast(lltype.Signed, value) -def location_code(self): -return 'i' - def getint(self): return self.value @@ -149,9 +146,6 @@ info = getattr(self, attr, '?') return '' % (self._location_code, info) -def location_code(self): -return self._location_code - def value_a(self): return self.loc_a @@ -191,6 +185,7 @@ # we want a width of 8 (... I think. Check this!) _immutable_ = True width = 8 +_location_code = 'j' def __init__(self, address): self.value = address @@ -198,9 +193,6 @@ def __repr__(self): return '' % (self.value,) -def location_code(self): -return 'j' - if IS_X86_32: class FloatImmedLoc(AssemblerLocation): # This stands for an immediate float. It cannot be directly used in @@ -209,6 +201,7 @@ # instead; see below. _immutable_ = True width = 8 +_location_code = '#' # don't use me def __init__(self, floatstorage): self.aslonglong = floatstorage @@ -229,9 +222,6 @@ floatvalue = longlong.getrealfloat(self.aslonglong) return '' % (floatvalue,) -def location_code(self): -raise NotImplementedError - if IS_X86_64: def FloatImmedLoc(floatstorage): from pypy.rlib.longlong2float import float2longlong @@ -270,6 +260,11 @@ else: raise AssertionError(methname + " undefined") +def _missing_binary_insn(name, code1, code2): +raise AssertionError(name + "_" + code1 + code2 + " missing") +_missing_binary_insn._dont_inline_ = True + + class LocationCodeBuilder(object): _mixin_ = True @@ -303,6 +298,8 @@ else: # For this case, we should not need the scratch register more than here. self._load_scratch(val2) +if name == 'MOV' and loc1 is X86_64_SCRATCH_REG: +return # don't need a dummy "MOV r11, r11" INSN(self, loc1, X86_64_SCRATCH_REG) def invoke(self, codes, val1, val2): @@ -310,6 +307,23 @@ _rx86_getattr(self, methname)(val1, val2) invoke._annspecialcase_ = 'specialize:arg(1)' +def has_implementation_for(loc1, loc2): +# A memo function that returns True if there is any NAME_xy that could match. +# If it returns False we know the whole subcase can be omitted from translated +# code. Without this hack, the size of most _binaryop INSN functions ends up +# quite large in C code. +if loc1 == '?': +return any([has_implementation_for(loc1, loc2) +for loc1 i
[pypy-commit] pypy default: break up circular dependencies among short_boxes and give up
Author: Hakan Ardo Branch: Changeset: r48691:d9708bf78c40 Date: 2011-11-03 11:46 +0100 http://bitbucket.org/pypy/pypy/changeset/d9708bf78c40/ Log:break up circular dependencies among short_boxes and give up diff --git a/pypy/jit/metainterp/optimizeopt/heap.py b/pypy/jit/metainterp/optimizeopt/heap.py --- a/pypy/jit/metainterp/optimizeopt/heap.py +++ b/pypy/jit/metainterp/optimizeopt/heap.py @@ -146,8 +146,6 @@ newresult = result.clonebox() optimizer.make_constant(newresult, result) result = newresult -if result is op.getarg(0): # FIXME: Unsupported corner case?? -continue getop = ResOperation(rop.GETARRAYITEM_GC, [op.getarg(0), op.getarg(1)], result, op.getdescr()) shortboxes.add_potential(getop, synthetic=True) diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py --- a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py +++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py @@ -7450,6 +7450,55 @@ """ self.optimize_loop(ops, expected) +def test_setarrayitem_p0_p0(self): +ops = """ +[i0, i1] +p0 = escape() +setarrayitem_gc(p0, 2, p0, descr=arraydescr) +jump(i0, i1) +""" +expected = """ +[i0, i1] +p0 = escape() +setarrayitem_gc(p0, 2, p0, descr=arraydescr) +jump(i0, i1) +""" +self.optimize_loop(ops, expected) + +def test_setfield_p0_p0(self): +ops = """ +[i0, i1] +p0 = escape() +setfield_gc(p0, p0, descr=arraydescr) +jump(i0, i1) +""" +expected = """ +[i0, i1] +p0 = escape() +setfield_gc(p0, p0, descr=arraydescr) +jump(i0, i1) +""" +self.optimize_loop(ops, expected) + +def test_setfield_p0_p1_p0(self): +ops = """ +[i0, i1] +p0 = escape() +p1 = escape() +setfield_gc(p0, p1, descr=adescr) +setfield_gc(p1, p0, descr=bdescr) +jump(i0, i1) +""" +expected = """ +[i0, i1] +p0 = escape() +p1 = escape() +setfield_gc(p0, p1, descr=adescr) +setfield_gc(p1, p0, descr=bdescr) +jump(i0, i1) +""" +self.optimize_loop(ops, expected) + class TestLLtype(OptimizeOptTest, LLtypeMixin): pass diff --git a/pypy/jit/metainterp/optimizeopt/virtualstate.py b/pypy/jit/metainterp/optimizeopt/virtualstate.py --- a/pypy/jit/metainterp/optimizeopt/virtualstate.py +++ b/pypy/jit/metainterp/optimizeopt/virtualstate.py @@ -551,6 +551,7 @@ optimizer.produce_potential_short_preamble_ops(self) self.short_boxes = {} +self.short_boxes_in_production = {} for box in self.potential_ops.keys(): try: @@ -606,6 +607,10 @@ return if isinstance(box, Const): return +if box in self.short_boxes_in_production: +raise BoxNotProducable +self.short_boxes_in_production[box] = True + if box in self.potential_ops: ops = self.prioritized_alternatives(box) produced_one = False ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: only use a single counter in xrange iterators (should save a setitem)
Author: Hakan Ardo Branch: Changeset: r48694:a27a481ec877 Date: 2011-11-03 13:11 +0100 http://bitbucket.org/pypy/pypy/changeset/a27a481ec877/ Log:only use a single counter in xrange iterators (should save a setitem) diff --git a/pypy/module/__builtin__/functional.py b/pypy/module/__builtin__/functional.py --- a/pypy/module/__builtin__/functional.py +++ b/pypy/module/__builtin__/functional.py @@ -312,10 +312,11 @@ class W_XRange(Wrappable): -def __init__(self, space, start, len, step): +def __init__(self, space, start, stop, step): self.space = space self.start = start -self.len = len +self.stop = stop +self.len = get_len_of_range(space, start, stop, step) self.step = step def descr_new(space, w_subtype, w_start, w_stop=None, w_step=1): @@ -325,9 +326,8 @@ start, stop = 0, start else: stop = _toint(space, w_stop) -howmany = get_len_of_range(space, start, stop, step) obj = space.allocate_instance(W_XRange, w_subtype) -W_XRange.__init__(obj, space, start, howmany, step) +W_XRange.__init__(obj, space, start, stop, step) return space.wrap(obj) def descr_repr(self): @@ -357,12 +357,12 @@ def descr_iter(self): return self.space.wrap(W_XRangeIterator(self.space, self.start, -self.len, self.step)) +self.stop, self.step)) def descr_reversed(self): lastitem = self.start + (self.len-1) * self.step return self.space.wrap(W_XRangeIterator(self.space, lastitem, -self.len, -self.step)) +self.start - 1, -self.step)) def descr_reduce(self): space = self.space @@ -389,25 +389,24 @@ ) class W_XRangeIterator(Wrappable): -def __init__(self, space, current, remaining, step): +def __init__(self, space, start, stop, step): self.space = space -self.current = current -self.remaining = remaining +self.current = start +self.stop = stop self.step = step def descr_iter(self): return self.space.wrap(self) def descr_next(self): -if self.remaining > 0: +if (self.step > 0 and self.current < self.stop) or (self.step < 0 and self.current > self.stop): item = self.current self.current = item + self.step -self.remaining -= 1 return self.space.wrap(item) raise OperationError(self.space.w_StopIteration, self.space.w_None) -def descr_len(self): -return self.space.wrap(self.remaining) +#def descr_len(self): +#return self.space.wrap(self.remaining) def descr_reduce(self): from pypy.interpreter.mixedmodule import MixedModule @@ -418,7 +417,7 @@ w= space.wrap nt = space.newtuple -tup = [w(self.current), w(self.remaining), w(self.step)] +tup = [w(self.current), w(self.stop), w(self.step)] return nt([new_inst, nt(tup)]) W_XRangeIterator.typedef = TypeDef("rangeiterator", diff --git a/pypy/module/_pickle_support/maker.py b/pypy/module/_pickle_support/maker.py --- a/pypy/module/_pickle_support/maker.py +++ b/pypy/module/_pickle_support/maker.py @@ -66,10 +66,10 @@ new_generator.running = running return space.wrap(new_generator) -@unwrap_spec(current=int, remaining=int, step=int) -def xrangeiter_new(space, current, remaining, step): +@unwrap_spec(current=int, stop=int, step=int) +def xrangeiter_new(space, current, stop, step): from pypy.module.__builtin__.functional import W_XRangeIterator -new_iter = W_XRangeIterator(space, current, remaining, step) +new_iter = W_XRangeIterator(space, current, stop, step) return space.wrap(new_iter) @unwrap_spec(identifier=str) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy step-one-xrange: special case xrange without any step specified
Author: Hakan Ardo Branch: step-one-xrange Changeset: r48696:6cf1ae5ff5d6 Date: 2011-11-03 13:39 +0100 http://bitbucket.org/pypy/pypy/changeset/6cf1ae5ff5d6/ Log:special case xrange without any step specified diff --git a/pypy/module/__builtin__/functional.py b/pypy/module/__builtin__/functional.py --- a/pypy/module/__builtin__/functional.py +++ b/pypy/module/__builtin__/functional.py @@ -312,22 +312,28 @@ class W_XRange(Wrappable): -def __init__(self, space, start, stop, step): +def __init__(self, space, start, stop, step, promote_step=False): self.space = space self.start = start self.stop = stop self.len = get_len_of_range(space, start, stop, step) self.step = step +self.promote_step = promote_step -def descr_new(space, w_subtype, w_start, w_stop=None, w_step=1): +def descr_new(space, w_subtype, w_start, w_stop=None, w_step=None): start = _toint(space, w_start) -step = _toint(space, w_step) +if space.is_w(w_step, space.w_None): # no step argument provided +step = 1 +promote_step = True +else: +step = _toint(space, w_step) +promote_step = False if space.is_w(w_stop, space.w_None): # only 1 argument provided start, stop = 0, start else: stop = _toint(space, w_stop) obj = space.allocate_instance(W_XRange, w_subtype) -W_XRange.__init__(obj, space, start, stop, step) +W_XRange.__init__(obj, space, start, stop, step, promote_step) return space.wrap(obj) def descr_repr(self): @@ -356,8 +362,12 @@ space.wrap("xrange object index out of range")) def descr_iter(self): -return self.space.wrap(W_XRangeIterator(self.space, self.start, -self.stop, self.step)) +if self.promote_step and self.step == 1: +return self.space.wrap(W_XRangeStepOneIterator(self.space, self.start, +self.stop)) +else: +return self.space.wrap(W_XRangeIterator(self.space, self.start, +self.stop, self.step)) def descr_reversed(self): lastitem = self.start + (self.len-1) * self.step @@ -427,3 +437,24 @@ next= interp2app(W_XRangeIterator.descr_next), __reduce__ = interp2app(W_XRangeIterator.descr_reduce), ) + +class W_XRangeStepOneIterator(W_XRangeIterator): +def __init__(self, space, start, stop): +self.space = space +self.current = start +self.stop = stop +self.step = 1 + +def descr_next(self): +if self.current < self.stop: +item = self.current +self.current = item + 1 +return self.space.wrap(item) +raise OperationError(self.space.w_StopIteration, self.space.w_None) + + +W_XRangeStepOneIterator.typedef = TypeDef("xrangesteponeiterator", +__iter__= interp2app(W_XRangeStepOneIterator.descr_iter), +next= interp2app(W_XRangeStepOneIterator.descr_next), +__reduce__ = interp2app(W_XRangeStepOneIterator.descr_reduce), +) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy step-one-xrange: test ensuring xrange iterator only produces a single setitem
Author: Hakan Ardo Branch: step-one-xrange Changeset: r48701:3aaee477e4be Date: 2011-11-03 15:21 +0100 http://bitbucket.org/pypy/pypy/changeset/3aaee477e4be/ Log:test ensuring xrange iterator only produces a single setitem diff --git a/pypy/module/pypyjit/test_pypy_c/test_misc.py b/pypy/module/pypyjit/test_pypy_c/test_misc.py --- a/pypy/module/pypyjit/test_pypy_c/test_misc.py +++ b/pypy/module/pypyjit/test_pypy_c/test_misc.py @@ -128,6 +128,36 @@ jump(..., descr=...) """) +def test_xrange_iter(self): +def main(n): +def g(n): +return xrange(n) +s = 0 +for i in xrange(n): # ID: for +tmp = g(n) +s += tmp[i] # ID: getitem +a = 0 +return s +# +log = self.run(main, [1000]) +assert log.result == 1000 * 999 / 2 +loop, = log.loops_by_filename(self.filepath) +assert loop.match(""" +i15 = int_lt(i10, i11) +guard_true(i15, descr=...) +i17 = int_add(i10, 1) +i18 = force_token() +setfield_gc(p9, i17, descr=<.* .*W_XRangeIterator.inst_current .*>) +guard_not_invalidated(descr=...) +i21 = int_lt(i10, 0) +guard_false(i21, descr=...) +i22 = int_lt(i10, i14) +guard_true(i22, descr=...) +i23 = int_add_ovf(i6, i10) +guard_no_overflow(descr=...) +--TICK-- +jump(..., descr=) +""") def test_range_iter(self): def main(n): ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: introduce targets that can be placed somewhere in a trace that can be used jump targets
Author: Hakan Ardo Branch: jit-targets Changeset: r48708:505538a47fdb Date: 2011-11-03 18:20 +0100 http://bitbucket.org/pypy/pypy/changeset/505538a47fdb/ Log:introduce targets that can be placed somewhere in a trace that can be used jump targets diff --git a/pypy/jit/backend/llgraph/llimpl.py b/pypy/jit/backend/llgraph/llimpl.py --- a/pypy/jit/backend/llgraph/llimpl.py +++ b/pypy/jit/backend/llgraph/llimpl.py @@ -339,12 +339,16 @@ assert isinstance(type, str) and len(type) == 1 op.args.append(Descr(ofs, type, arg_types=arg_types)) -def compile_add_loop_token(loop, descr): +def compile_add_loop_token(loop, descr, clt): if we_are_translated(): raise ValueError("CALL_ASSEMBLER not supported") loop = _from_opaque(loop) op = loop.operations[-1] op.descr = weakref.ref(descr) +if op.opnum == rop.TARGET: +descr.compiled_loop_token = clt +descr.target_opindex = len(loop.operations) +descr.target_arguments = op.args def compile_add_var(loop, intvar): loop = _from_opaque(loop) @@ -380,13 +384,17 @@ _variables.append(v) return r -def compile_add_jump_target(loop, loop_target): +def compile_add_jump_target(loop, loop_target, target_opindex, target_inputargs): loop = _from_opaque(loop) loop_target = _from_opaque(loop_target) +if not target_inputargs: +target_inputargs = loop_target.inputargs op = loop.operations[-1] op.jump_target = loop_target +op.jump_target_opindex = target_opindex +op.jump_target_inputargs = target_inputargs assert op.opnum == rop.JUMP -assert len(op.args) == len(loop_target.inputargs) +assert len(op.args) == len(target_inputargs) if loop_target == loop: log.info("compiling new loop") else: @@ -520,10 +528,11 @@ self.opindex += 1 continue if op.opnum == rop.JUMP: -assert len(op.jump_target.inputargs) == len(args) -self.env = dict(zip(op.jump_target.inputargs, args)) +inputargs = op.jump_target_inputargs +assert len(inputargs) == len(args) +self.env = dict(zip(inputargs, args)) self.loop = op.jump_target -self.opindex = 0 +self.opindex = op.jump_target_opindex _stats.exec_jumps += 1 elif op.opnum == rop.FINISH: if self.verbose: @@ -616,6 +625,9 @@ # return _op_default_implementation +def op_target(self, _, *args): +pass + def op_debug_merge_point(self, _, *args): from pypy.jit.metainterp.warmspot import get_stats try: diff --git a/pypy/jit/backend/llgraph/runner.py b/pypy/jit/backend/llgraph/runner.py --- a/pypy/jit/backend/llgraph/runner.py +++ b/pypy/jit/backend/llgraph/runner.py @@ -136,7 +136,7 @@ clt = original_loop_token.compiled_loop_token clt.loop_and_bridges.append(c) clt.compiling_a_bridge() -self._compile_loop_or_bridge(c, inputargs, operations) +self._compile_loop_or_bridge(c, inputargs, operations, clt) old, oldindex = faildescr._compiled_fail llimpl.compile_redirect_fail(old, oldindex, c) @@ -151,14 +151,16 @@ clt.loop_and_bridges = [c] clt.compiled_version = c looptoken.compiled_loop_token = clt -self._compile_loop_or_bridge(c, inputargs, operations) +looptoken.target_opindex = 0 +looptoken.target_arguments = None +self._compile_loop_or_bridge(c, inputargs, operations, clt) def free_loop_and_bridges(self, compiled_loop_token): for c in compiled_loop_token.loop_and_bridges: llimpl.mark_as_free(c) model.AbstractCPU.free_loop_and_bridges(self, compiled_loop_token) -def _compile_loop_or_bridge(self, c, inputargs, operations): +def _compile_loop_or_bridge(self, c, inputargs, operations, clt): var2index = {} for box in inputargs: if isinstance(box, history.BoxInt): @@ -170,19 +172,19 @@ var2index[box] = llimpl.compile_start_float_var(c) else: raise Exception("box is: %r" % (box,)) -self._compile_operations(c, operations, var2index) +self._compile_operations(c, operations, var2index, clt) return c -def _compile_operations(self, c, operations, var2index): +def _compile_operations(self, c, operations, var2index, clt): for op in operations: llimpl.compile_add(c, op.getopnum()) descr = op.getdescr() if isinstance(descr, Descr): llimpl.compile_add_descr(c, descr.ofs, descr.typeinfo, descr.arg_types) -if (isinstance(descr, history.LoopToken) and -op.getopnum() != rop.JUMP): -llimpl.compile_add_loop_token(c, descr) +
[pypy-commit] pypy jit-targets: use TargetToken to refere to a target
Author: Hakan Ardo Branch: jit-targets Changeset: r48711:1860421891fe Date: 2011-11-03 19:18 +0100 http://bitbucket.org/pypy/pypy/changeset/1860421891fe/ Log:use TargetToken to refere to a target diff --git a/pypy/jit/backend/llgraph/llimpl.py b/pypy/jit/backend/llgraph/llimpl.py --- a/pypy/jit/backend/llgraph/llimpl.py +++ b/pypy/jit/backend/llgraph/llimpl.py @@ -8,6 +8,7 @@ from pypy.objspace.flow.model import Variable, Constant from pypy.annotation import model as annmodel from pypy.jit.metainterp.history import REF, INT, FLOAT +from pypy.jit.metainterp import history from pypy.jit.codewriter import heaptracker from pypy.rpython.lltypesystem import lltype, llmemory, rclass, rstr, rffi from pypy.rpython.ootypesystem import ootype @@ -339,16 +340,20 @@ assert isinstance(type, str) and len(type) == 1 op.args.append(Descr(ofs, type, arg_types=arg_types)) -def compile_add_loop_token(loop, descr, clt): +def compile_add_loop_token(loop, descr): if we_are_translated(): raise ValueError("CALL_ASSEMBLER not supported") loop = _from_opaque(loop) op = loop.operations[-1] op.descr = weakref.ref(descr) -if op.opnum == rop.TARGET: -descr.compiled_loop_token = clt -descr.target_opindex = len(loop.operations) -descr.target_arguments = op.args + +def compile_add_target_token(loop, descr): +compiled_version = loop +loop = _from_opaque(loop) +op = loop.operations[-1] +descr.compiled_version = compiled_version +descr.target_opindex = len(loop.operations) +descr.target_arguments = op.args def compile_add_var(loop, intvar): loop = _from_opaque(loop) @@ -384,11 +389,19 @@ _variables.append(v) return r -def compile_add_jump_target(loop, loop_target, target_opindex, target_inputargs): +def compile_add_jump_target(loop, targettoken): loop = _from_opaque(loop) -loop_target = _from_opaque(loop_target) -if not target_inputargs: +if isinstance(targettoken, history.LoopToken): +loop_target = _from_opaque(targettoken.compiled_loop_token.compiled_version) +target_opindex = 0 target_inputargs = loop_target.inputargs +elif isinstance(targettoken, history.TargetToken): +loop_target = _from_opaque(targettoken.compiled_version) +target_opindex = targettoken.target_opindex +target_inputargs = targettoken.target_arguments +else: +assert False + op = loop.operations[-1] op.jump_target = loop_target op.jump_target_opindex = target_opindex diff --git a/pypy/jit/backend/llgraph/runner.py b/pypy/jit/backend/llgraph/runner.py --- a/pypy/jit/backend/llgraph/runner.py +++ b/pypy/jit/backend/llgraph/runner.py @@ -136,7 +136,7 @@ clt = original_loop_token.compiled_loop_token clt.loop_and_bridges.append(c) clt.compiling_a_bridge() -self._compile_loop_or_bridge(c, inputargs, operations, clt) +self._compile_loop_or_bridge(c, inputargs, operations) old, oldindex = faildescr._compiled_fail llimpl.compile_redirect_fail(old, oldindex, c) @@ -151,16 +151,14 @@ clt.loop_and_bridges = [c] clt.compiled_version = c looptoken.compiled_loop_token = clt -looptoken.target_opindex = 0 -looptoken.target_arguments = None -self._compile_loop_or_bridge(c, inputargs, operations, clt) +self._compile_loop_or_bridge(c, inputargs, operations) def free_loop_and_bridges(self, compiled_loop_token): for c in compiled_loop_token.loop_and_bridges: llimpl.mark_as_free(c) model.AbstractCPU.free_loop_and_bridges(self, compiled_loop_token) -def _compile_loop_or_bridge(self, c, inputargs, operations, clt): +def _compile_loop_or_bridge(self, c, inputargs, operations): var2index = {} for box in inputargs: if isinstance(box, history.BoxInt): @@ -172,10 +170,10 @@ var2index[box] = llimpl.compile_start_float_var(c) else: raise Exception("box is: %r" % (box,)) -self._compile_operations(c, operations, var2index, clt) +self._compile_operations(c, operations, var2index) return c -def _compile_operations(self, c, operations, var2index, clt): +def _compile_operations(self, c, operations, var2index): for op in operations: llimpl.compile_add(c, op.getopnum()) descr = op.getdescr() @@ -184,7 +182,9 @@ descr.arg_types) if isinstance(descr, history.LoopToken): if op.getopnum() != rop.JUMP: -llimpl.compile_add_loop_token(c, descr, clt) +llimpl.compile_add_loop_token(c, descr) +if isinstance(descr, history.TargetToken) and op.getopnum() == rop.TARGET: +llimpl.compile_add_target_token(c, descr) if self.is_oo and isinstance
[pypy-commit] pypy default: fix an overlow bug
Author: Hakan Ardo Branch: Changeset: r48723:7202b0d9cb70 Date: 2011-11-03 21:14 +0100 http://bitbucket.org/pypy/pypy/changeset/7202b0d9cb70/ Log:fix an overlow bug diff --git a/pypy/module/__builtin__/functional.py b/pypy/module/__builtin__/functional.py --- a/pypy/module/__builtin__/functional.py +++ b/pypy/module/__builtin__/functional.py @@ -362,7 +362,7 @@ def descr_reversed(self): lastitem = self.start + (self.len-1) * self.step return self.space.wrap(W_XRangeIterator(self.space, lastitem, -self.start - 1, -self.step)) +self.start, -self.step, True)) def descr_reduce(self): space = self.space @@ -389,21 +389,26 @@ ) class W_XRangeIterator(Wrappable): -def __init__(self, space, start, stop, step): +def __init__(self, space, start, stop, step, inclusive=False): self.space = space self.current = start self.stop = stop self.step = step +self.inclusive = inclusive def descr_iter(self): return self.space.wrap(self) def descr_next(self): -if (self.step > 0 and self.current < self.stop) or (self.step < 0 and self.current > self.stop): -item = self.current -self.current = item + self.step -return self.space.wrap(item) -raise OperationError(self.space.w_StopIteration, self.space.w_None) +if self.inclusive: +if not ((self.step > 0 and self.current <= self.stop) or (self.step < 0 and self.current >= self.stop)): +raise OperationError(self.space.w_StopIteration, self.space.w_None) +else: +if not ((self.step > 0 and self.current < self.stop) or (self.step < 0 and self.current > self.stop)): +raise OperationError(self.space.w_StopIteration, self.space.w_None) +item = self.current +self.current = item + self.step +return self.space.wrap(item) #def descr_len(self): #return self.space.wrap(self.remaining) diff --git a/pypy/module/__builtin__/test/test_functional.py b/pypy/module/__builtin__/test/test_functional.py --- a/pypy/module/__builtin__/test/test_functional.py +++ b/pypy/module/__builtin__/test/test_functional.py @@ -157,7 +157,8 @@ raises(OverflowError, xrange, a) raises(OverflowError, xrange, 0, a) raises(OverflowError, xrange, 0, 1, a) - + assert list(reversed(xrange(-sys.maxint-1, -sys.maxint-1, -2))) == [] + def test_xrange_reduce(self): x = xrange(2, 9, 3) callable, args = x.__reduce__() ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: hg merge
Author: Hakan Ardo Branch: Changeset: r48724:7cd8e99541db Date: 2011-11-03 21:15 +0100 http://bitbucket.org/pypy/pypy/changeset/7cd8e99541db/ Log:hg merge diff --git a/pypy/module/_hashlib/interp_hashlib.py b/pypy/module/_hashlib/interp_hashlib.py --- a/pypy/module/_hashlib/interp_hashlib.py +++ b/pypy/module/_hashlib/interp_hashlib.py @@ -4,32 +4,44 @@ from pypy.interpreter.error import OperationError from pypy.tool.sourcetools import func_renamer from pypy.interpreter.baseobjspace import Wrappable -from pypy.rpython.lltypesystem import lltype, rffi +from pypy.rpython.lltypesystem import lltype, llmemory, rffi +from pypy.rlib import rgc, ropenssl from pypy.rlib.objectmodel import keepalive_until_here -from pypy.rlib import ropenssl from pypy.rlib.rstring import StringBuilder from pypy.module.thread.os_lock import Lock algorithms = ('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512') +# HASH_MALLOC_SIZE is the size of EVP_MD, EVP_MD_CTX plus their points +# Used for adding memory pressure. Last number is an (under?)estimate of +# EVP_PKEY_CTX's size. +# XXX: Make a better estimate here +HASH_MALLOC_SIZE = ropenssl.EVP_MD_SIZE + ropenssl.EVP_MD_CTX_SIZE \ ++ rffi.sizeof(ropenssl.EVP_MD) * 2 + 208 + class W_Hash(Wrappable): ctx = lltype.nullptr(ropenssl.EVP_MD_CTX.TO) +_block_size = -1 def __init__(self, space, name): self.name = name +self.digest_size = self.compute_digest_size() # Allocate a lock for each HASH object. # An optimization would be to not release the GIL on small requests, # and use a custom lock only when needed. self.lock = Lock(space) +ctx = lltype.malloc(ropenssl.EVP_MD_CTX.TO, flavor='raw') +rgc.add_memory_pressure(HASH_MALLOC_SIZE + self.digest_size) +self.ctx = ctx + +def initdigest(self, space, name): digest = ropenssl.EVP_get_digestbyname(name) if not digest: raise OperationError(space.w_ValueError, space.wrap("unknown hash function")) -ctx = lltype.malloc(ropenssl.EVP_MD_CTX.TO, flavor='raw') -ropenssl.EVP_DigestInit(ctx, digest) -self.ctx = ctx +ropenssl.EVP_DigestInit(self.ctx, digest) def __del__(self): # self.lock.free() @@ -65,33 +77,29 @@ "Return the digest value as a string of hexadecimal digits." digest = self._digest(space) hexdigits = '0123456789abcdef' -result = StringBuilder(self._digest_size() * 2) +result = StringBuilder(self.digest_size * 2) for c in digest: result.append(hexdigits[(ord(c) >> 4) & 0xf]) result.append(hexdigits[ ord(c) & 0xf]) return space.wrap(result.build()) def get_digest_size(self, space): -return space.wrap(self._digest_size()) +return space.wrap(self.digest_size) def get_block_size(self, space): -return space.wrap(self._block_size()) +return space.wrap(self.compute_block_size()) def _digest(self, space): -copy = self.copy(space) -ctx = copy.ctx -digest_size = self._digest_size() -digest = lltype.malloc(rffi.CCHARP.TO, digest_size, flavor='raw') +with lltype.scoped_alloc(ropenssl.EVP_MD_CTX.TO) as ctx: +with self.lock: +ropenssl.EVP_MD_CTX_copy(ctx, self.ctx) +digest_size = self.digest_size +with lltype.scoped_alloc(rffi.CCHARP.TO, digest_size) as digest: +ropenssl.EVP_DigestFinal(ctx, digest, None) +ropenssl.EVP_MD_CTX_cleanup(ctx) +return rffi.charpsize2str(digest, digest_size) -try: -ropenssl.EVP_DigestFinal(ctx, digest, None) -return rffi.charpsize2str(digest, digest_size) -finally: -keepalive_until_here(copy) -lltype.free(digest, flavor='raw') - - -def _digest_size(self): +def compute_digest_size(self): # XXX This isn't the nicest way, but the EVP_MD_size OpenSSL # XXX function is defined as a C macro on OS X and would be # XXX significantly harder to implement in another way. @@ -105,12 +113,14 @@ 'sha512': 64, 'SHA512': 64, }.get(self.name, 0) -def _block_size(self): +def compute_block_size(self): +if self._block_size != -1: +return self._block_size # XXX This isn't the nicest way, but the EVP_MD_CTX_block_size # XXX OpenSSL function is defined as a C macro on some systems # XXX and would be significantly harder to implement in # XXX another way. -return { +self._block_size = { 'md5': 64, 'MD5': 64, 'sha1':64, 'SHA1':64, 'sha224': 64, 'SHA224': 64, @@ -118,6 +128,7 @@ 'sha384': 128, 'SHA384': 128, 'sha512': 128, 'SHA512': 128,
[pypy-commit] pypy jit-targets: hg merge default
Author: Hakan Ardo Branch: jit-targets Changeset: r48762:67b1506999f5 Date: 2011-11-04 07:43 +0100 http://bitbucket.org/pypy/pypy/changeset/67b1506999f5/ Log:hg merge default diff --git a/pypy/module/__builtin__/functional.py b/pypy/module/__builtin__/functional.py --- a/pypy/module/__builtin__/functional.py +++ b/pypy/module/__builtin__/functional.py @@ -362,7 +362,7 @@ def descr_reversed(self): lastitem = self.start + (self.len-1) * self.step return self.space.wrap(W_XRangeIterator(self.space, lastitem, -self.start - 1, -self.step)) +self.start, -self.step, True)) def descr_reduce(self): space = self.space @@ -389,21 +389,26 @@ ) class W_XRangeIterator(Wrappable): -def __init__(self, space, start, stop, step): +def __init__(self, space, start, stop, step, inclusive=False): self.space = space self.current = start self.stop = stop self.step = step +self.inclusive = inclusive def descr_iter(self): return self.space.wrap(self) def descr_next(self): -if (self.step > 0 and self.current < self.stop) or (self.step < 0 and self.current > self.stop): -item = self.current -self.current = item + self.step -return self.space.wrap(item) -raise OperationError(self.space.w_StopIteration, self.space.w_None) +if self.inclusive: +if not ((self.step > 0 and self.current <= self.stop) or (self.step < 0 and self.current >= self.stop)): +raise OperationError(self.space.w_StopIteration, self.space.w_None) +else: +if not ((self.step > 0 and self.current < self.stop) or (self.step < 0 and self.current > self.stop)): +raise OperationError(self.space.w_StopIteration, self.space.w_None) +item = self.current +self.current = item + self.step +return self.space.wrap(item) #def descr_len(self): #return self.space.wrap(self.remaining) diff --git a/pypy/module/__builtin__/test/test_functional.py b/pypy/module/__builtin__/test/test_functional.py --- a/pypy/module/__builtin__/test/test_functional.py +++ b/pypy/module/__builtin__/test/test_functional.py @@ -157,7 +157,8 @@ raises(OverflowError, xrange, a) raises(OverflowError, xrange, 0, a) raises(OverflowError, xrange, 0, 1, a) - + assert list(reversed(xrange(-sys.maxint-1, -sys.maxint-1, -2))) == [] + def test_xrange_reduce(self): x = xrange(2, 9, 3) callable, args = x.__reduce__() diff --git a/pypy/module/_hashlib/interp_hashlib.py b/pypy/module/_hashlib/interp_hashlib.py --- a/pypy/module/_hashlib/interp_hashlib.py +++ b/pypy/module/_hashlib/interp_hashlib.py @@ -4,32 +4,44 @@ from pypy.interpreter.error import OperationError from pypy.tool.sourcetools import func_renamer from pypy.interpreter.baseobjspace import Wrappable -from pypy.rpython.lltypesystem import lltype, rffi +from pypy.rpython.lltypesystem import lltype, llmemory, rffi +from pypy.rlib import rgc, ropenssl from pypy.rlib.objectmodel import keepalive_until_here -from pypy.rlib import ropenssl from pypy.rlib.rstring import StringBuilder from pypy.module.thread.os_lock import Lock algorithms = ('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512') +# HASH_MALLOC_SIZE is the size of EVP_MD, EVP_MD_CTX plus their points +# Used for adding memory pressure. Last number is an (under?)estimate of +# EVP_PKEY_CTX's size. +# XXX: Make a better estimate here +HASH_MALLOC_SIZE = ropenssl.EVP_MD_SIZE + ropenssl.EVP_MD_CTX_SIZE \ ++ rffi.sizeof(ropenssl.EVP_MD) * 2 + 208 + class W_Hash(Wrappable): ctx = lltype.nullptr(ropenssl.EVP_MD_CTX.TO) +_block_size = -1 def __init__(self, space, name): self.name = name +self.digest_size = self.compute_digest_size() # Allocate a lock for each HASH object. # An optimization would be to not release the GIL on small requests, # and use a custom lock only when needed. self.lock = Lock(space) +ctx = lltype.malloc(ropenssl.EVP_MD_CTX.TO, flavor='raw') +rgc.add_memory_pressure(HASH_MALLOC_SIZE + self.digest_size) +self.ctx = ctx + +def initdigest(self, space, name): digest = ropenssl.EVP_get_digestbyname(name) if not digest: raise OperationError(space.w_ValueError, space.wrap("unknown hash function")) -ctx = lltype.malloc(ropenssl.EVP_MD_CTX.TO, flavor='raw') -ropenssl.EVP_DigestInit(ctx, digest) -self.ctx = ctx +ropenssl.EVP_DigestInit(self.ctx, digest) def __del__(self): # self.lock.free() @@ -65,33 +77,29 @@ "Return the digest value as a string of hexadecimal digits." digest = self._digest(space) hexdigits
[pypy-commit] pypy jit-targets: refactor unrolling to use the new target resop
Author: Hakan Ardo Branch: jit-targets Changeset: r48763:9ef690e84b21 Date: 2011-11-04 21:14 +0100 http://bitbucket.org/pypy/pypy/changeset/9ef690e84b21/ Log:refactor unrolling to use the new target resop diff --git a/pypy/jit/metainterp/history.py b/pypy/jit/metainterp/history.py --- a/pypy/jit/metainterp/history.py +++ b/pypy/jit/metainterp/history.py @@ -766,10 +766,10 @@ self.compiled_loop_token.cpu.dump_loop_token(self) class TargetToken(AbstractDescr): -pass +def __init__(self): +self.exported_state = None class TreeLoop(object): -inputargs = None operations = None token = None call_pure_results = None @@ -778,11 +778,24 @@ def __init__(self, name): self.name = name -# self.inputargs = list of distinct Boxes # self.operations = list of ResOperations # ops of the kind 'guard_xxx' contain a further list of operations, # which may itself contain 'guard_xxx' and so on, making a tree. +_inputargs = None + +def get_inputargs(self): +"NOT_RPYTHON" +if self._inputargs is not None: +return self._inputargs +assert self.operations[0].getopnum() == rop.TARGET +return self.operations[0].getarglist() + +def set_inputargs(self, inputargs): +self._inputargs = inputargs + +inputargs = property(get_inputargs, set_inputargs) + def _all_operations(self, omit_finish=False): "NOT_RPYTHON" result = [] @@ -801,7 +814,7 @@ return self.operations def get_display_text(self):# for graphpage.py -return self.name + '\n' + repr(self.inputargs) +return self.name def show(self, errmsg=None): "NOT_RPYTHON" @@ -810,15 +823,13 @@ def check_consistency(self): # for testing "NOT_RPYTHON" -self.check_consistency_of(self.inputargs, self.operations) +self.check_consistency_of(self.operations) @staticmethod -def check_consistency_of(inputargs, operations): -for box in inputargs: -assert isinstance(box, Box), "Loop.inputargs contains %r" % (box,) +def check_consistency_of(operations): +assert operations[0].getopnum() == rop.TARGET +inputargs = operations[0].getarglist() seen = dict.fromkeys(inputargs) -assert len(seen) == len(inputargs), ( - "duplicate Box in the Loop.inputargs") TreeLoop.check_consistency_of_branch(operations, seen) @staticmethod @@ -845,6 +856,14 @@ assert isinstance(box, Box) assert box not in seen seen[box] = True +if op.getopnum() == rop.TARGET: +inputargs = op.getarglist() +for box in inputargs: +assert isinstance(box, Box), "TARGET contains %r" % (box,) +seen = dict.fromkeys(inputargs) +assert len(seen) == len(inputargs), ( +"duplicate Box in the TARGET arguments") + assert operations[-1].is_final() if operations[-1].getopnum() == rop.JUMP: target = operations[-1].getdescr() @@ -853,7 +872,7 @@ def dump(self): # RPython-friendly -print '%r: inputargs =' % self, self._dump_args(self.inputargs) +print '%r: ' % self for op in self.operations: args = op.getarglist() print '\t', op.getopname(), self._dump_args(args), \ diff --git a/pypy/jit/metainterp/optimizeopt/__init__.py b/pypy/jit/metainterp/optimizeopt/__init__.py --- a/pypy/jit/metainterp/optimizeopt/__init__.py +++ b/pypy/jit/metainterp/optimizeopt/__init__.py @@ -80,3 +80,14 @@ if __name__ == '__main__': print ALL_OPTS_NAMES + +def optimize_trace(metainterp_sd, loop, enable_opts): +"""Optimize loop.operations to remove internal overheadish operations. +""" + +optimizations, unroll = build_opt_chain(metainterp_sd, enable_opts, False, False) +if unroll: +optimize_unroll(metainterp_sd, loop, optimizations) +else: +optimizer = Optimizer(metainterp_sd, loop, optimizations, bridge) +optimizer.propagate_all_forward() diff --git a/pypy/jit/metainterp/optimizeopt/optimizer.py b/pypy/jit/metainterp/optimizeopt/optimizer.py --- a/pypy/jit/metainterp/optimizeopt/optimizer.py +++ b/pypy/jit/metainterp/optimizeopt/optimizer.py @@ -497,9 +497,10 @@ else: return CVAL_ZERO -def propagate_all_forward(self): +def propagate_all_forward(self, clear=True): self.exception_might_have_happened = self.bridge -self.clear_newoperations() +if clear: +self.clear_newoperations() for op in self.loop.operations: self.first_optimization.propagate_forward(op) self.loop.operations = self.get_newoperations() @@ -556,6 +557,7 @@ def store_final_boxes_in_guard(self, op):
[pypy-commit] pypy jit-targets: allow orignial jump_args to be used in the peeled loop
Author: Hakan Ardo Branch: jit-targets Changeset: r48766:90d65a7d35c3 Date: 2011-11-04 22:19 +0100 http://bitbucket.org/pypy/pypy/changeset/90d65a7d35c3/ Log:allow orignial jump_args to be used in the peeled loop diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py --- a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py +++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py @@ -97,12 +97,12 @@ [ResOperation(rop.TARGET, jump_args, None, descr=targettoken)] self._do_optimize_loop(preamble, call_pure_results) -jump_args = preamble.operations[-1].getdescr().exported_state.jump_args # FIXME!! inliner = Inliner(inputargs, jump_args) loop.inputargs = None loop.start_resumedescr = preamble.start_resumedescr loop.operations = [preamble.operations[-1]] + \ [inliner.inline_op(op, clone=False) for op in cloned_operations] + self._do_optimize_loop(loop, call_pure_results) extra_same_as = [] while loop.operations[0].getopnum() != rop.TARGET: diff --git a/pypy/jit/metainterp/optimizeopt/unroll.py b/pypy/jit/metainterp/optimizeopt/unroll.py --- a/pypy/jit/metainterp/optimizeopt/unroll.py +++ b/pypy/jit/metainterp/optimizeopt/unroll.py @@ -152,8 +152,8 @@ loop.operations = self.optimizer.get_newoperations() def export_state(self, targetop): -jump_args = targetop.getarglist() -jump_args = [self.getvalue(a).get_key_box() for a in jump_args] +original_jump_args = targetop.getarglist() +jump_args = [self.getvalue(a).get_key_box() for a in original_jump_args] start_resumedescr = self.optimizer.loop.start_resumedescr.clone_if_mutable() assert isinstance(start_resumedescr, ResumeGuardDescr) @@ -173,6 +173,9 @@ constant_inputargs[box] = const short_boxes = ShortBoxes(self.optimizer, inputargs + constant_inputargs.keys()) +for i in range(len(original_jump_args)): +if original_jump_args[i] is not jump_args[i]: +short_boxes.alias(original_jump_args[i], jump_args[i]) self.optimizer.clear_newoperations() for box in short_inputargs: @@ -215,6 +218,9 @@ preamble_value = exported_state.optimizer.getvalue(box) value = self.optimizer.getvalue(box) value.import_from(preamble_value, self.optimizer) + +for newbox, oldbox in self.short_boxes.aliases.items(): +self.optimizer.make_equal_to(newbox, self.optimizer.getvalue(oldbox)) # Setup the state of the new optimizer by emiting the # short operations and discarding the result ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: hg backout 7202b0d9cb70
Author: Hakan Ardo Branch: Changeset: r48767:aa07c2a53f95 Date: 2011-11-04 22:37 +0100 http://bitbucket.org/pypy/pypy/changeset/aa07c2a53f95/ Log:hg backout 7202b0d9cb70 diff --git a/pypy/module/__builtin__/functional.py b/pypy/module/__builtin__/functional.py --- a/pypy/module/__builtin__/functional.py +++ b/pypy/module/__builtin__/functional.py @@ -362,7 +362,7 @@ def descr_reversed(self): lastitem = self.start + (self.len-1) * self.step return self.space.wrap(W_XRangeIterator(self.space, lastitem, -self.start, -self.step, True)) +self.start - 1, -self.step)) def descr_reduce(self): space = self.space @@ -389,26 +389,21 @@ ) class W_XRangeIterator(Wrappable): -def __init__(self, space, start, stop, step, inclusive=False): +def __init__(self, space, start, stop, step): self.space = space self.current = start self.stop = stop self.step = step -self.inclusive = inclusive def descr_iter(self): return self.space.wrap(self) def descr_next(self): -if self.inclusive: -if not ((self.step > 0 and self.current <= self.stop) or (self.step < 0 and self.current >= self.stop)): -raise OperationError(self.space.w_StopIteration, self.space.w_None) -else: -if not ((self.step > 0 and self.current < self.stop) or (self.step < 0 and self.current > self.stop)): -raise OperationError(self.space.w_StopIteration, self.space.w_None) -item = self.current -self.current = item + self.step -return self.space.wrap(item) +if (self.step > 0 and self.current < self.stop) or (self.step < 0 and self.current > self.stop): +item = self.current +self.current = item + self.step +return self.space.wrap(item) +raise OperationError(self.space.w_StopIteration, self.space.w_None) #def descr_len(self): #return self.space.wrap(self.remaining) diff --git a/pypy/module/__builtin__/test/test_functional.py b/pypy/module/__builtin__/test/test_functional.py --- a/pypy/module/__builtin__/test/test_functional.py +++ b/pypy/module/__builtin__/test/test_functional.py @@ -157,8 +157,7 @@ raises(OverflowError, xrange, a) raises(OverflowError, xrange, 0, a) raises(OverflowError, xrange, 0, 1, a) - assert list(reversed(xrange(-sys.maxint-1, -sys.maxint-1, -2))) == [] - + def test_xrange_reduce(self): x = xrange(2, 9, 3) callable, args = x.__reduce__() ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: hg backout a27a481ec877
Author: Hakan Ardo Branch: Changeset: r48768:21cb735ed98a Date: 2011-11-04 22:38 +0100 http://bitbucket.org/pypy/pypy/changeset/21cb735ed98a/ Log:hg backout a27a481ec877 diff --git a/pypy/module/__builtin__/functional.py b/pypy/module/__builtin__/functional.py --- a/pypy/module/__builtin__/functional.py +++ b/pypy/module/__builtin__/functional.py @@ -312,11 +312,10 @@ class W_XRange(Wrappable): -def __init__(self, space, start, stop, step): +def __init__(self, space, start, len, step): self.space = space self.start = start -self.stop = stop -self.len = get_len_of_range(space, start, stop, step) +self.len = len self.step = step def descr_new(space, w_subtype, w_start, w_stop=None, w_step=1): @@ -326,8 +325,9 @@ start, stop = 0, start else: stop = _toint(space, w_stop) +howmany = get_len_of_range(space, start, stop, step) obj = space.allocate_instance(W_XRange, w_subtype) -W_XRange.__init__(obj, space, start, stop, step) +W_XRange.__init__(obj, space, start, howmany, step) return space.wrap(obj) def descr_repr(self): @@ -357,12 +357,12 @@ def descr_iter(self): return self.space.wrap(W_XRangeIterator(self.space, self.start, -self.stop, self.step)) +self.len, self.step)) def descr_reversed(self): lastitem = self.start + (self.len-1) * self.step return self.space.wrap(W_XRangeIterator(self.space, lastitem, -self.start - 1, -self.step)) +self.len, -self.step)) def descr_reduce(self): space = self.space @@ -389,24 +389,25 @@ ) class W_XRangeIterator(Wrappable): -def __init__(self, space, start, stop, step): +def __init__(self, space, current, remaining, step): self.space = space -self.current = start -self.stop = stop +self.current = current +self.remaining = remaining self.step = step def descr_iter(self): return self.space.wrap(self) def descr_next(self): -if (self.step > 0 and self.current < self.stop) or (self.step < 0 and self.current > self.stop): +if self.remaining > 0: item = self.current self.current = item + self.step +self.remaining -= 1 return self.space.wrap(item) raise OperationError(self.space.w_StopIteration, self.space.w_None) -#def descr_len(self): -#return self.space.wrap(self.remaining) +def descr_len(self): +return self.space.wrap(self.remaining) def descr_reduce(self): from pypy.interpreter.mixedmodule import MixedModule @@ -417,7 +418,7 @@ w= space.wrap nt = space.newtuple -tup = [w(self.current), w(self.stop), w(self.step)] +tup = [w(self.current), w(self.remaining), w(self.step)] return nt([new_inst, nt(tup)]) W_XRangeIterator.typedef = TypeDef("rangeiterator", diff --git a/pypy/module/_pickle_support/maker.py b/pypy/module/_pickle_support/maker.py --- a/pypy/module/_pickle_support/maker.py +++ b/pypy/module/_pickle_support/maker.py @@ -66,10 +66,10 @@ new_generator.running = running return space.wrap(new_generator) -@unwrap_spec(current=int, stop=int, step=int) -def xrangeiter_new(space, current, stop, step): +@unwrap_spec(current=int, remaining=int, step=int) +def xrangeiter_new(space, current, remaining, step): from pypy.module.__builtin__.functional import W_XRangeIterator -new_iter = W_XRangeIterator(space, current, stop, step) +new_iter = W_XRangeIterator(space, current, remaining, step) return space.wrap(new_iter) @unwrap_spec(identifier=str) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: place the virtual_state on the target_token
Author: Hakan Ardo Branch: jit-targets Changeset: r48771:beacbd0267fc Date: 2011-11-05 09:04 +0100 http://bitbucket.org/pypy/pypy/changeset/beacbd0267fc/ Log:place the virtual_state on the target_token diff --git a/pypy/jit/metainterp/history.py b/pypy/jit/metainterp/history.py --- a/pypy/jit/metainterp/history.py +++ b/pypy/jit/metainterp/history.py @@ -768,6 +768,7 @@ class TargetToken(AbstractDescr): def __init__(self, merge_point): self.merge_point = merge_point +self.virtual_state = None self.exported_state = None class TreeLoop(object): diff --git a/pypy/jit/metainterp/optimizeopt/unroll.py b/pypy/jit/metainterp/optimizeopt/unroll.py --- a/pypy/jit/metainterp/optimizeopt/unroll.py +++ b/pypy/jit/metainterp/optimizeopt/unroll.py @@ -191,10 +191,11 @@ target_token = targetop.getdescr() assert isinstance(target_token, TargetToken) targetop.initarglist(inputargs) +target_token.virtual_state = virtual_state target_token.exported_state = ExportedState(values, short_inputargs, constant_inputargs, short_boxes, inputarg_setup_ops, self.optimizer, -virtual_state, start_resumedescr) +start_resumedescr) def import_state(self, targetop): target_token = targetop.getdescr() @@ -214,6 +215,7 @@ self.imported_state = exported_state self.inputargs = targetop.getarglist() self.start_resumedescr = exported_state.start_resumedescr +self.initial_virtual_state = target_token.virtual_state seen = {} for box in self.inputargs: @@ -252,7 +254,7 @@ self.optimizer.emitting_dissabled = False def close_loop(self, jumpop): -virtual_state = self.imported_state.virtual_state +virtual_state = self.initial_virtual_state short_inputargs = self.imported_state.short_inputargs constant_inputargs = self.imported_state.constant_inputargs inputargs = self.inputargs @@ -365,8 +367,6 @@ inliner.inline_descr_inplace(descr) short_loop.start_resumedescr = descr -short_loop.virtual_state = self.imported_state.virtual_state - # Forget the values to allow them to be freed for box in short_loop.inputargs: box.forget_value() @@ -574,7 +574,7 @@ class ExportedState(object): def __init__(self, values, short_inputargs, constant_inputargs, - short_boxes, inputarg_setup_ops, optimizer, virtual_state, + short_boxes, inputarg_setup_ops, optimizer, start_resumedescr): self.values = values self.short_inputargs = short_inputargs @@ -582,6 +582,5 @@ self.short_boxes = short_boxes self.inputarg_setup_ops = inputarg_setup_ops self.optimizer = optimizer -self.virtual_state = virtual_state self.start_resumedescr = start_resumedescr ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: no need to export jump_args
Author: Hakan Ardo Branch: jit-targets Changeset: r48769:9e83d7c21fba Date: 2011-11-05 08:05 +0100 http://bitbucket.org/pypy/pypy/changeset/9e83d7c21fba/ Log:no need to export jump_args diff --git a/pypy/jit/metainterp/optimizeopt/unroll.py b/pypy/jit/metainterp/optimizeopt/unroll.py --- a/pypy/jit/metainterp/optimizeopt/unroll.py +++ b/pypy/jit/metainterp/optimizeopt/unroll.py @@ -190,8 +190,7 @@ target_token.exported_state = ExportedState(values, short_inputargs, constant_inputargs, short_boxes, inputarg_setup_ops, self.optimizer, -jump_args, virtual_state, -start_resumedescr) +virtual_state, start_resumedescr) def import_state(self, targetop): target_token = targetop.getdescr() @@ -570,7 +569,7 @@ class ExportedState(object): def __init__(self, values, short_inputargs, constant_inputargs, - short_boxes, inputarg_setup_ops, optimizer, jump_args, virtual_state, + short_boxes, inputarg_setup_ops, optimizer, virtual_state, start_resumedescr): self.values = values self.short_inputargs = short_inputargs @@ -578,7 +577,6 @@ self.short_boxes = short_boxes self.inputarg_setup_ops = inputarg_setup_ops self.optimizer = optimizer -self.jump_args = jump_args self.virtual_state = virtual_state self.start_resumedescr = start_resumedescr ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: hg merge
Author: Hakan Ardo Branch: Changeset: r48774:7fdbb6ee5b80 Date: 2011-11-05 09:56 +0100 http://bitbucket.org/pypy/pypy/changeset/7fdbb6ee5b80/ Log:hg merge diff --git a/pypy/jit/metainterp/optimizeopt/optimizer.py b/pypy/jit/metainterp/optimizeopt/optimizer.py --- a/pypy/jit/metainterp/optimizeopt/optimizer.py +++ b/pypy/jit/metainterp/optimizeopt/optimizer.py @@ -247,7 +247,6 @@ CONST_1 = ConstInt(1) CVAL_ZERO= ConstantValue(CONST_0) CVAL_ZERO_FLOAT = ConstantValue(Const._new(0.0)) -CVAL_UNINITIALIZED_ZERO = ConstantValue(CONST_0) llhelper.CVAL_NULLREF = ConstantValue(llhelper.CONST_NULL) oohelper.CVAL_NULLREF = ConstantValue(oohelper.CONST_NULL) diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py b/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py --- a/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py +++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py @@ -4123,6 +4123,38 @@ """ self.optimize_strunicode_loop(ops, expected) +def test_str_concat_constant_lengths(self): +ops = """ +[i0] +p0 = newstr(1) +strsetitem(p0, 0, i0) +p1 = newstr(0) +p2 = call(0, p0, p1, descr=strconcatdescr) +i1 = call(0, p2, p0, descr=strequaldescr) +finish(i1) +""" +expected = """ +[i0] +finish(1) +""" +self.optimize_strunicode_loop(ops, expected) + +def test_str_concat_constant_lengths_2(self): +ops = """ +[i0] +p0 = newstr(0) +p1 = newstr(1) +strsetitem(p1, 0, i0) +p2 = call(0, p0, p1, descr=strconcatdescr) +i1 = call(0, p2, p1, descr=strequaldescr) +finish(i1) +""" +expected = """ +[i0] +finish(1) +""" +self.optimize_strunicode_loop(ops, expected) + def test_str_slice_1(self): ops = """ [p1, i1, i2] @@ -4883,6 +4915,27 @@ def test_plain_virtual_string_copy_content(self): ops = """ +[i1] +p0 = newstr(6) +copystrcontent(s"hello!", p0, 0, 0, 6) +p1 = call(0, p0, s"abc123", descr=strconcatdescr) +i0 = strgetitem(p1, i1) +finish(i0) +""" +expected = """ +[i1] +p0 = newstr(6) +copystrcontent(s"hello!", p0, 0, 0, 6) +p1 = newstr(12) +copystrcontent(p0, p1, 0, 0, 6) +copystrcontent(s"abc123", p1, 0, 6, 6) +i0 = strgetitem(p1, i1) +finish(i0) +""" +self.optimize_strunicode_loop(ops, expected) + +def test_plain_virtual_string_copy_content_2(self): +ops = """ [] p0 = newstr(6) copystrcontent(s"hello!", p0, 0, 0, 6) @@ -4894,10 +4947,7 @@ [] p0 = newstr(6) copystrcontent(s"hello!", p0, 0, 0, 6) -p1 = newstr(12) -copystrcontent(p0, p1, 0, 0, 6) -copystrcontent(s"abc123", p1, 0, 6, 6) -i0 = strgetitem(p1, 0) +i0 = strgetitem(p0, 0) finish(i0) """ self.optimize_strunicode_loop(ops, expected) diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py --- a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py +++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py @@ -2168,13 +2168,13 @@ ops = """ [p0, i0, p1, i1, i2] setfield_gc(p0, i1, descr=valuedescr) -copystrcontent(p0, i0, p1, i1, i2) +copystrcontent(p0, p1, i0, i1, i2) escape() jump(p0, i0, p1, i1, i2) """ expected = """ [p0, i0, p1, i1, i2] -copystrcontent(p0, i0, p1, i1, i2) +copystrcontent(p0, p1, i0, i1, i2) setfield_gc(p0, i1, descr=valuedescr) escape() jump(p0, i0, p1, i1, i2) @@ -7407,7 +7407,7 @@ expected = """ [p22, p18, i1, i2] call(i2, descr=nonwritedescr) -setfield_gc(p22, i1, descr=valuedescr) +setfield_gc(p22, i1, descr=valuedescr) jump(p22, p18, i1, i1) """ self.optimize_loop(ops, expected, preamble, expected_short=short) @@ -7434,7 +7434,7 @@ def test_cache_setarrayitem_across_loop_boundaries(self): ops = """ [p1] -p2 = getarrayitem_gc(p1, 3, descr=arraydescr) +p2 = getarrayitem_gc(p1, 3, descr=arraydescr) guard_nonnull_class(p2, ConstClass(node_vtable)) [] call(p2, descr=nonwritedescr) p3 = new_with_vtable(ConstClass(node_vtable)) diff --git a/pypy/jit/metainterp/optimizeopt/vstring.py b/pypy/jit/metainterp/optimizeopt/vstring.py --- a/pypy/jit/metainterp/optimizeopt/vstring.py +++ b/pypy/jit/metainterp/optimizeopt/vstring.py @@ -1,6 +1,6 @@ from pypy.jit.codewriter.effectinfo import EffectInfo from pypy.jit.metainterp.history import (BoxInt, Const, ConstInt, ConstPtr, -ge
[pypy-commit] pypy jit-targets: move the decition wheter to unroll or not back into optimizeopt
Author: Hakan Ardo Branch: jit-targets Changeset: r48770:0aa80cc1b315 Date: 2011-11-05 08:44 +0100 http://bitbucket.org/pypy/pypy/changeset/0aa80cc1b315/ Log:move the decition wheter to unroll or not back into optimizeopt diff --git a/pypy/jit/metainterp/history.py b/pypy/jit/metainterp/history.py --- a/pypy/jit/metainterp/history.py +++ b/pypy/jit/metainterp/history.py @@ -766,7 +766,8 @@ self.compiled_loop_token.cpu.dump_loop_token(self) class TargetToken(AbstractDescr): -def __init__(self): +def __init__(self, merge_point): +self.merge_point = merge_point self.exported_state = None class TreeLoop(object): diff --git a/pypy/jit/metainterp/optimizeopt/optimizer.py b/pypy/jit/metainterp/optimizeopt/optimizer.py --- a/pypy/jit/metainterp/optimizeopt/optimizer.py +++ b/pypy/jit/metainterp/optimizeopt/optimizer.py @@ -557,7 +557,6 @@ def store_final_boxes_in_guard(self, op): descr = op.getdescr() -print '', descr, id(descr) assert isinstance(descr, compile.ResumeGuardDescr) modifier = resume.ResumeDataVirtualAdder(descr, self.resumedata_memo) newboxes = modifier.finish(self.values, self.pendingfields) diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py --- a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py +++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py @@ -80,28 +80,33 @@ if expected_short: expected_short = self.parse(expected_short) operations = loop.operations +jumpop = operations[-1] +assert jumpop.getopnum() == rop.JUMP +inputargs = loop.inputargs +loop.inputargs = None + +jump_args = jumpop.getarglist()[:] +operations = operations[:-1] cloned_operations = [op.clone() for op in operations] preamble = TreeLoop('preamble') #loop.preamble.inputargs = loop.inputargs #loop.preamble.token = LoopToken() preamble.start_resumedescr = FakeDescr() -assert operations[-1].getopnum() == rop.JUMP -inputargs = loop.inputargs -jump_args = operations[-1].getarglist() -targettoken = TargetToken() -operations[-1].setdescr(targettoken) -cloned_operations[-1].setdescr(targettoken) -preamble.operations = [ResOperation(rop.TARGET, inputargs, None, descr=TargetToken())] + \ - operations[:-1] + \ - [ResOperation(rop.TARGET, jump_args, None, descr=targettoken)] + +token = LoopToken() # FIXME: Make this a MergePointToken? +preamble.operations = [ResOperation(rop.TARGET, inputargs, None, descr=TargetToken(token))] + \ + operations + \ + [ResOperation(rop.TARGET, jump_args, None, descr=TargetToken(token))] self._do_optimize_loop(preamble, call_pure_results) inliner = Inliner(inputargs, jump_args) -loop.inputargs = None loop.start_resumedescr = preamble.start_resumedescr loop.operations = [preamble.operations[-1]] + \ - [inliner.inline_op(op, clone=False) for op in cloned_operations] + [inliner.inline_op(op, clone=False) for op in cloned_operations] + \ + [ResOperation(rop.TARGET, [inliner.inline_arg(a) for a in jump_args], +None, descr=TargetToken(token))] + #[inliner.inline_op(jumpop)] self._do_optimize_loop(loop, call_pure_results) extra_same_as = [] diff --git a/pypy/jit/metainterp/optimizeopt/unroll.py b/pypy/jit/metainterp/optimizeopt/unroll.py --- a/pypy/jit/metainterp/optimizeopt/unroll.py +++ b/pypy/jit/metainterp/optimizeopt/unroll.py @@ -126,30 +126,34 @@ self.import_state(start_targetop) lastop = loop.operations[-1] -if lastop.getopnum() == rop.TARGET or lastop.getopnum() == rop.JUMP: -loop.operations = loop.operations[:-1] +assert lastop.getopnum() == rop.TARGET +loop.operations = loop.operations[:-1] +#if lastop.getopnum() == rop.TARGET or lastop.getopnum() == rop.JUMP: +#loop.operations = loop.operations[:-1] #FIXME: FINISH self.optimizer.propagate_all_forward(clear=False) -if lastop.getopnum() == rop.TARGET: +#if lastop.getopnum() == rop.TARGET: +if not self.did_peel_one: # Enforce the previous behaviour of always peeling exactly one iteration (for now) self.optimizer.flush() KillHugeIntBounds(self.optimizer).apply() loop.operations = self.optimizer.get_newoperations() self.export_state(lastop) loop.operations.append(lastop) -elif lastop.getopnum() == ro
[pypy-commit] pypy jit-targets: no need to export values
Author: Hakan Ardo Branch: jit-targets Changeset: r48772:5b76dc7b47e9 Date: 2011-11-05 09:06 +0100 http://bitbucket.org/pypy/pypy/changeset/5b76dc7b47e9/ Log:no need to export values diff --git a/pypy/jit/metainterp/optimizeopt/unroll.py b/pypy/jit/metainterp/optimizeopt/unroll.py --- a/pypy/jit/metainterp/optimizeopt/unroll.py +++ b/pypy/jit/metainterp/optimizeopt/unroll.py @@ -192,7 +192,7 @@ assert isinstance(target_token, TargetToken) targetop.initarglist(inputargs) target_token.virtual_state = virtual_state -target_token.exported_state = ExportedState(values, short_inputargs, +target_token.exported_state = ExportedState(short_inputargs, constant_inputargs, short_boxes, inputarg_setup_ops, self.optimizer, start_resumedescr) @@ -573,10 +573,9 @@ self.unroll.add_op_to_short(self.op, False, True) class ExportedState(object): -def __init__(self, values, short_inputargs, constant_inputargs, +def __init__(self, short_inputargs, constant_inputargs, short_boxes, inputarg_setup_ops, optimizer, start_resumedescr): -self.values = values self.short_inputargs = short_inputargs self.constant_inputargs = constant_inputargs self.short_boxes = short_boxes ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: store the short preamble on the TargetToken instead
Author: Hakan Ardo Branch: jit-targets Changeset: r48773:096da5690e5d Date: 2011-11-05 09:30 +0100 http://bitbucket.org/pypy/pypy/changeset/096da5690e5d/ Log:store the short preamble on the TargetToken instead diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py --- a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py +++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py @@ -133,9 +133,8 @@ print if expected_short: print "Short Preamble:" -short = loop.token.short_preamble[0] -print short.inputargs -print '\n'.join([str(o) for o in short.operations]) +short = loop.operations[0].getdescr().short_preamble +print '\n'.join([str(o) for o in short]) print assert expected != "crash!", "should have raised an exception" @@ -146,9 +145,11 @@ text_right='expected preamble') assert preamble.operations[-1].getdescr() == loop.operations[0].getdescr() if expected_short: -self.assert_equal(short, convert_old_style_to_targets(expected_short, jump=True), +short_preamble = TreeLoop('short preamble') +short_preamble.operations = short +self.assert_equal(short_preamble, convert_old_style_to_targets(expected_short, jump=True), text_right='expected short preamble') -assert short.operations[-1].getdescr() == loop.operations[0].getdescr() +assert short[-1].getdescr() == loop.operations[0].getdescr() return loop diff --git a/pypy/jit/metainterp/optimizeopt/unroll.py b/pypy/jit/metainterp/optimizeopt/unroll.py --- a/pypy/jit/metainterp/optimizeopt/unroll.py +++ b/pypy/jit/metainterp/optimizeopt/unroll.py @@ -145,13 +145,10 @@ else: assert lastop.getdescr().merge_point is start_targetop.getdescr().merge_point jumpop = ResOperation(rop.JUMP, lastop.getarglist(), None, descr=start_targetop.getdescr()) + self.close_loop(jumpop) -short_preamble_loop = self.produce_short_preamble(lastop) -assert isinstance(loop.token, LoopToken) -if loop.token.short_preamble: -loop.token.short_preamble.append(short_preamble_loop) # FIXME: ?? -else: -loop.token.short_preamble = [short_preamble_loop] +self.finilize_short_preamble(lastop) +start_targetop.getdescr().short_preamble = self.short #else: #loop.operations = self.optimizer.get_newoperations() @@ -192,8 +189,8 @@ assert isinstance(target_token, TargetToken) targetop.initarglist(inputargs) target_token.virtual_state = virtual_state -target_token.exported_state = ExportedState(short_inputargs, -constant_inputargs, short_boxes, +target_token.short_preamble = [ResOperation(rop.TARGET, short_inputargs, None)] +target_token.exported_state = ExportedState(constant_inputargs, short_boxes, inputarg_setup_ops, self.optimizer, start_resumedescr) @@ -207,7 +204,7 @@ return self.did_peel_one = True -self.short = [] +self.short = target_token.short_preamble self.short_seen = {} self.short_boxes = exported_state.short_boxes for box, const in exported_state.constant_inputargs.items(): @@ -255,7 +252,7 @@ def close_loop(self, jumpop): virtual_state = self.initial_virtual_state -short_inputargs = self.imported_state.short_inputargs +short_inputargs = self.short[0].getarglist() constant_inputargs = self.imported_state.constant_inputargs inputargs = self.inputargs short_jumpargs = inputargs[:] @@ -271,7 +268,7 @@ self.short_inliner = Inliner(short_inputargs, jmp_to_short_args) for box, const in constant_inputargs.items(): self.short_inliner.argmap[box] = const -for op in self.short: +for op in self.short[1:]: newop = self.short_inliner.inline_op(op) self.optimizer.send_extra_operation(newop) @@ -329,7 +326,7 @@ raise InvalidLoop debug_stop('jit-log-virtualstate') -def produce_short_preamble(self, lastop): +def finilize_short_preamble(self, lastop): short = self.short assert short[-1].getopnum() == rop.JUMP @@ -343,12 +340,8 @@ op.setdescr(descr) short[i] = op -short_loop = TreeLoop('short preamble') -short_inputargs = self.imported_state.short_inputargs -short_loop.operations = [ResOperation(rop.TARGET, short_inputargs, None)]
[pypy-commit] pypy jit-targets: hg merge default
Author: Hakan Ardo Branch: jit-targets Changeset: r48776:88580873fdfd Date: 2011-11-05 10:10 +0100 http://bitbucket.org/pypy/pypy/changeset/88580873fdfd/ Log:hg merge default diff --git a/pypy/jit/metainterp/optimizeopt/optimizer.py b/pypy/jit/metainterp/optimizeopt/optimizer.py --- a/pypy/jit/metainterp/optimizeopt/optimizer.py +++ b/pypy/jit/metainterp/optimizeopt/optimizer.py @@ -247,7 +247,6 @@ CONST_1 = ConstInt(1) CVAL_ZERO= ConstantValue(CONST_0) CVAL_ZERO_FLOAT = ConstantValue(Const._new(0.0)) -CVAL_UNINITIALIZED_ZERO = ConstantValue(CONST_0) llhelper.CVAL_NULLREF = ConstantValue(llhelper.CONST_NULL) oohelper.CVAL_NULLREF = ConstantValue(oohelper.CONST_NULL) diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py b/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py --- a/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py +++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py @@ -4123,6 +4123,38 @@ """ self.optimize_strunicode_loop(ops, expected) +def test_str_concat_constant_lengths(self): +ops = """ +[i0] +p0 = newstr(1) +strsetitem(p0, 0, i0) +p1 = newstr(0) +p2 = call(0, p0, p1, descr=strconcatdescr) +i1 = call(0, p2, p0, descr=strequaldescr) +finish(i1) +""" +expected = """ +[i0] +finish(1) +""" +self.optimize_strunicode_loop(ops, expected) + +def test_str_concat_constant_lengths_2(self): +ops = """ +[i0] +p0 = newstr(0) +p1 = newstr(1) +strsetitem(p1, 0, i0) +p2 = call(0, p0, p1, descr=strconcatdescr) +i1 = call(0, p2, p1, descr=strequaldescr) +finish(i1) +""" +expected = """ +[i0] +finish(1) +""" +self.optimize_strunicode_loop(ops, expected) + def test_str_slice_1(self): ops = """ [p1, i1, i2] @@ -4883,6 +4915,27 @@ def test_plain_virtual_string_copy_content(self): ops = """ +[i1] +p0 = newstr(6) +copystrcontent(s"hello!", p0, 0, 0, 6) +p1 = call(0, p0, s"abc123", descr=strconcatdescr) +i0 = strgetitem(p1, i1) +finish(i0) +""" +expected = """ +[i1] +p0 = newstr(6) +copystrcontent(s"hello!", p0, 0, 0, 6) +p1 = newstr(12) +copystrcontent(p0, p1, 0, 0, 6) +copystrcontent(s"abc123", p1, 0, 6, 6) +i0 = strgetitem(p1, i1) +finish(i0) +""" +self.optimize_strunicode_loop(ops, expected) + +def test_plain_virtual_string_copy_content_2(self): +ops = """ [] p0 = newstr(6) copystrcontent(s"hello!", p0, 0, 0, 6) @@ -4894,10 +4947,7 @@ [] p0 = newstr(6) copystrcontent(s"hello!", p0, 0, 0, 6) -p1 = newstr(12) -copystrcontent(p0, p1, 0, 0, 6) -copystrcontent(s"abc123", p1, 0, 6, 6) -i0 = strgetitem(p1, 0) +i0 = strgetitem(p0, 0) finish(i0) """ self.optimize_strunicode_loop(ops, expected) diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py --- a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py +++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py @@ -2224,13 +2224,13 @@ ops = """ [p0, i0, p1, i1, i2] setfield_gc(p0, i1, descr=valuedescr) -copystrcontent(p0, i0, p1, i1, i2) +copystrcontent(p0, p1, i0, i1, i2) escape() jump(p0, i0, p1, i1, i2) """ expected = """ [p0, i0, p1, i1, i2] -copystrcontent(p0, i0, p1, i1, i2) +copystrcontent(p0, p1, i0, i1, i2) setfield_gc(p0, i1, descr=valuedescr) escape() jump(p0, i0, p1, i1, i2) @@ -7493,7 +7493,7 @@ expected = """ [p22, p18, i1, i2] call(i2, descr=nonwritedescr) -setfield_gc(p22, i1, descr=valuedescr) +setfield_gc(p22, i1, descr=valuedescr) jump(p22, p18, i1, i1) """ self.optimize_loop(ops, expected, preamble, expected_short=short) @@ -7520,7 +7520,7 @@ def test_cache_setarrayitem_across_loop_boundaries(self): ops = """ [p1] -p2 = getarrayitem_gc(p1, 3, descr=arraydescr) +p2 = getarrayitem_gc(p1, 3, descr=arraydescr) guard_nonnull_class(p2, ConstClass(node_vtable)) [] call(p2, descr=nonwritedescr) p3 = new_with_vtable(ConstClass(node_vtable)) diff --git a/pypy/jit/metainterp/optimizeopt/vstring.py b/pypy/jit/metainterp/optimizeopt/vstring.py --- a/pypy/jit/metainterp/optimizeopt/vstring.py +++ b/pypy/jit/metainterp/optimizeopt/vstring.py @@ -1,6 +1,6 @@ from pypy.jit.codewriter.effectinfo import EffectInfo from pypy.jit.metainterp.history import (BoxInt, Const, ConstInt
[pypy-commit] pypy jit-targets: rename TARGET to LABEL
Author: Hakan Ardo Branch: jit-targets Changeset: r48777:743a06937826 Date: 2011-11-05 10:23 +0100 http://bitbucket.org/pypy/pypy/changeset/743a06937826/ Log:rename TARGET to LABEL diff --git a/pypy/jit/metainterp/executor.py b/pypy/jit/metainterp/executor.py --- a/pypy/jit/metainterp/executor.py +++ b/pypy/jit/metainterp/executor.py @@ -342,7 +342,7 @@ rop.SETARRAYITEM_RAW, rop.CALL_RELEASE_GIL, rop.QUASIIMMUT_FIELD, - rop.TARGET, + rop.LABEL, ): # list of opcodes never executed by pyjitpl continue raise AssertionError("missing %r" % (key,)) diff --git a/pypy/jit/metainterp/history.py b/pypy/jit/metainterp/history.py --- a/pypy/jit/metainterp/history.py +++ b/pypy/jit/metainterp/history.py @@ -790,7 +790,7 @@ "NOT_RPYTHON" if self._inputargs is not None: return self._inputargs -assert self.operations[0].getopnum() == rop.TARGET +assert self.operations[0].getopnum() == rop.LABEL return self.operations[0].getarglist() def set_inputargs(self, inputargs): @@ -829,7 +829,7 @@ @staticmethod def check_consistency_of(operations): -assert operations[0].getopnum() == rop.TARGET +assert operations[0].getopnum() == rop.LABEL inputargs = operations[0].getarglist() seen = dict.fromkeys(inputargs) TreeLoop.check_consistency_of_branch(operations, seen) @@ -858,13 +858,13 @@ assert isinstance(box, Box) assert box not in seen seen[box] = True -if op.getopnum() == rop.TARGET: +if op.getopnum() == rop.LABEL: inputargs = op.getarglist() for box in inputargs: -assert isinstance(box, Box), "TARGET contains %r" % (box,) +assert isinstance(box, Box), "LABEL contains %r" % (box,) seen = dict.fromkeys(inputargs) assert len(seen) == len(inputargs), ( -"duplicate Box in the TARGET arguments") +"duplicate Box in the LABEL arguments") assert operations[-1].is_final() if operations[-1].getopnum() == rop.JUMP: diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py --- a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py +++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py @@ -95,22 +95,22 @@ preamble.start_resumedescr = FakeDescr() token = LoopToken() # FIXME: Make this a MergePointToken? -preamble.operations = [ResOperation(rop.TARGET, inputargs, None, descr=TargetToken(token))] + \ +preamble.operations = [ResOperation(rop.LABEL, inputargs, None, descr=TargetToken(token))] + \ operations + \ - [ResOperation(rop.TARGET, jump_args, None, descr=TargetToken(token))] + [ResOperation(rop.LABEL, jump_args, None, descr=TargetToken(token))] self._do_optimize_loop(preamble, call_pure_results) inliner = Inliner(inputargs, jump_args) loop.start_resumedescr = preamble.start_resumedescr loop.operations = [preamble.operations[-1]] + \ [inliner.inline_op(op, clone=False) for op in cloned_operations] + \ - [ResOperation(rop.TARGET, [inliner.inline_arg(a) for a in jump_args], + [ResOperation(rop.LABEL, [inliner.inline_arg(a) for a in jump_args], None, descr=TargetToken(token))] #[inliner.inline_op(jumpop)] self._do_optimize_loop(loop, call_pure_results) extra_same_as = [] -while loop.operations[0].getopnum() != rop.TARGET: +while loop.operations[0].getopnum() != rop.LABEL: extra_same_as.append(loop.operations[0]) del loop.operations[0] @@ -155,11 +155,11 @@ def convert_old_style_to_targets(loop, jump): newloop = TreeLoop(loop.name) -newloop.operations = [ResOperation(rop.TARGET, loop.inputargs, None, descr=FakeDescr())] + \ +newloop.operations = [ResOperation(rop.LABEL, loop.inputargs, None, descr=FakeDescr())] + \ loop.operations if not jump: assert newloop.operations[-1].getopnum() == rop.JUMP -newloop.operations[-1] = ResOperation(rop.TARGET, newloop.operations[-1].getarglist(), None, descr=FakeDescr()) +newloop.operations[-1] = ResOperation(rop.LABEL, newloop.operations[-1].getarglist(), None, descr=FakeDescr()) return newloop class OptimizeOptTest(BaseTestWithUnroll): diff --git a/pypy/jit/metainterp/optimizeopt/unroll.py b/pypy/jit/m
[pypy-commit] pypy jit-targets: hg merge
Author: Hakan Ardo Branch: jit-targets Changeset: r48781:592bf0aa2470 Date: 2011-11-05 14:36 +0100 http://bitbucket.org/pypy/pypy/changeset/592bf0aa2470/ Log:hg merge diff --git a/pypy/jit/backend/llgraph/llimpl.py b/pypy/jit/backend/llgraph/llimpl.py --- a/pypy/jit/backend/llgraph/llimpl.py +++ b/pypy/jit/backend/llgraph/llimpl.py @@ -639,7 +639,7 @@ # return _op_default_implementation -def op_target(self, _, *args): +def op_label(self, _, *args): pass def op_debug_merge_point(self, _, *args): diff --git a/pypy/jit/backend/test/runner_test.py b/pypy/jit/backend/test/runner_test.py --- a/pypy/jit/backend/test/runner_test.py +++ b/pypy/jit/backend/test/runner_test.py @@ -2971,13 +2971,13 @@ i2 = BoxInt() i3 = BoxInt() looptoken = LoopToken() -targettoken = TargetToken() +targettoken = TargetToken(None) faildescr = BasicFailDescr(2) operations = [ ResOperation(rop.INT_ADD, [i0, ConstInt(1)], i1), ResOperation(rop.INT_LE, [i1, ConstInt(9)], i2), ResOperation(rop.GUARD_TRUE, [i2], None, descr=faildescr), -ResOperation(rop.TARGET, [i1], None, descr=targettoken), +ResOperation(rop.LABEL, [i1], None, descr=targettoken), ResOperation(rop.INT_GE, [i1, ConstInt(0)], i3), ResOperation(rop.GUARD_TRUE, [i3], None, descr=BasicFailDescr(3)), ResOperation(rop.JUMP, [i1], None, descr=looptoken), diff --git a/pypy/jit/backend/x86/assembler.py b/pypy/jit/backend/x86/assembler.py --- a/pypy/jit/backend/x86/assembler.py +++ b/pypy/jit/backend/x86/assembler.py @@ -152,14 +152,13 @@ allblocks = self.get_asmmemmgr_blocks(looptoken) self.datablockwrapper = MachineDataBlockWrapper(self.cpu.asmmemmgr, allblocks) +self.target_tokens_currently_compiling = {} def teardown(self): self.pending_guard_tokens = None if WORD == 8: self.pending_memoryerror_trampoline_from = None self.mc = None -self.looppos = -1 -self.currently_compiling_loop = None self.current_clt = None def finish_once(self): @@ -443,7 +442,6 @@ assert len(set(inputargs)) == len(inputargs) self.setup(looptoken) -self.currently_compiling_loop = looptoken if log: self._register_counter(False, looptoken.number) operations = self._inject_debugging_code(looptoken, operations) @@ -455,7 +453,9 @@ bootstrappos = self.mc.get_relative_pos() stackadjustpos = self._assemble_bootstrap_code(inputargs, arglocs) -self.looppos = self.mc.get_relative_pos() +looppos = self.mc.get_relative_pos() +looptoken._x86_loop_code = looppos +self.target_tokens_currently_compiling[looptoken] = None looptoken._x86_frame_depth = -1 # temporarily looptoken._x86_param_depth = -1 # temporarily frame_depth, param_depth = self._assemble(regalloc, operations) @@ -463,7 +463,7 @@ looptoken._x86_param_depth = param_depth directbootstrappos = self.mc.get_relative_pos() -self._assemble_bootstrap_direct_call(arglocs, self.looppos, +self._assemble_bootstrap_direct_call(arglocs, looppos, frame_depth+param_depth) self.write_pending_failure_recoveries() fullsize = self.mc.get_relative_pos() @@ -472,7 +472,7 @@ debug_start("jit-backend-addr") debug_print("Loop %d (%s) has address %x to %x (bootstrap %x)" % ( looptoken.number, loopname, -rawstart + self.looppos, +rawstart + looppos, rawstart + directbootstrappos, rawstart)) debug_stop("jit-backend-addr") @@ -488,8 +488,8 @@ looptoken._x86_ops_offset = ops_offset looptoken._x86_bootstrap_code = rawstart + bootstrappos -looptoken._x86_loop_code = rawstart + self.looppos looptoken._x86_direct_bootstrap_code = rawstart + directbootstrappos +self.fixup_target_tokens(rawstart) self.teardown() # oprofile support if self.cpu.profile_agent is not None: @@ -548,6 +548,7 @@ # patch the jump from original guard self.patch_jump_for_descr(faildescr, rawstart) ops_offset = self.mc.ops_offset +self.fixup_target_tokens(rawstart) self.teardown() # oprofile support if self.cpu.profile_agent is not None: @@ -668,6 +669,11 @@ mc.copy_to_raw_memory(adr_target) faildescr._x86_adr_jump_offset = 0# means "patched" +def fixup_target_tokens(self, rawstart): +for looptoken in self.target_tokens_currently_compiling: +looptoken._x86_loop_code += rawstart +self.target_tokens_currently_compi
[pypy-commit] pypy jit-targets: refactoring in progress
Author: Hakan Ardo Branch: jit-targets Changeset: r48780:0e0764aac5be Date: 2011-11-05 14:36 +0100 http://bitbucket.org/pypy/pypy/changeset/0e0764aac5be/ Log:refactoring in progress diff --git a/pypy/jit/backend/llgraph/llimpl.py b/pypy/jit/backend/llgraph/llimpl.py --- a/pypy/jit/backend/llgraph/llimpl.py +++ b/pypy/jit/backend/llgraph/llimpl.py @@ -391,7 +391,8 @@ def compile_add_jump_target(loop, targettoken): loop = _from_opaque(loop) -if isinstance(targettoken, history.LoopToken): +if isinstance(targettoken, history.ProcedureToken): +assert False loop_target = _from_opaque(targettoken.compiled_loop_token.compiled_version) target_opindex = 0 target_inputargs = loop_target.inputargs diff --git a/pypy/jit/backend/llgraph/runner.py b/pypy/jit/backend/llgraph/runner.py --- a/pypy/jit/backend/llgraph/runner.py +++ b/pypy/jit/backend/llgraph/runner.py @@ -180,10 +180,11 @@ if isinstance(descr, Descr): llimpl.compile_add_descr(c, descr.ofs, descr.typeinfo, descr.arg_types) -if isinstance(descr, history.LoopToken): +if isinstance(descr, history.ProcedureToken): +assert False if op.getopnum() != rop.JUMP: llimpl.compile_add_loop_token(c, descr) -if isinstance(descr, history.TargetToken) and op.getopnum() == rop.TARGET: +if isinstance(descr, history.TargetToken) and op.getopnum() == rop.LABEL: llimpl.compile_add_target_token(c, descr) if self.is_oo and isinstance(descr, (OODescr, MethDescr)): # hack hack, not rpython diff --git a/pypy/jit/metainterp/compile.py b/pypy/jit/metainterp/compile.py --- a/pypy/jit/metainterp/compile.py +++ b/pypy/jit/metainterp/compile.py @@ -9,12 +9,13 @@ from pypy.tool.sourcetools import func_with_new_name from pypy.jit.metainterp.resoperation import ResOperation, rop, get_deep_immutable_oplist -from pypy.jit.metainterp.history import TreeLoop, Box, History, LoopToken +from pypy.jit.metainterp.history import TreeLoop, Box, History, ProcedureToken, TargetToken from pypy.jit.metainterp.history import AbstractFailDescr, BoxInt from pypy.jit.metainterp.history import BoxPtr, BoxObj, BoxFloat, Const from pypy.jit.metainterp import history from pypy.jit.metainterp.typesystem import llhelper, oohelper from pypy.jit.metainterp.optimize import InvalidLoop +from pypy.jit.metainterp.inliner import Inliner from pypy.jit.metainterp.resume import NUMBERING, PENDINGFIELDSP from pypy.jit.codewriter import heaptracker, longlong @@ -45,10 +46,10 @@ return loop -def make_loop_token(nb_args, jitdriver_sd): -loop_token = LoopToken() -loop_token.outermost_jitdriver_sd = jitdriver_sd -return loop_token +def make_procedure_token(jitdriver_sd): +procedure_token = ProcedureToken() +procedure_token.outermost_jitdriver_sd = jitdriver_sd +return procedure_token def record_loop_or_bridge(metainterp_sd, loop): """Do post-backend recordings and cleanups on 'loop'. @@ -67,16 +68,18 @@ n = descr.index if n >= 0: # we also record the resumedescr number looptoken.compiled_loop_token.record_faildescr_index(n) -elif isinstance(descr, LoopToken): +elif isinstance(descr, ProcedureToken): +assert False, "FIXME" +elif isinstance(descr, TargetToken): # for a JUMP or a CALL_ASSEMBLER: record it as a potential jump. # (the following test is not enough to prevent more complicated # cases of cycles, but at least it helps in simple tests of # test_memgr.py) -if descr is not looptoken: -looptoken.record_jump_to(descr) +if descr.procedure_token is not looptoken: +looptoken.record_jump_to(descr.procedure_token) op._descr = None# clear reference, mostly for tests if not we_are_translated(): -op._jumptarget_number = descr.number +op._jumptarget_number = descr.procedure_token.number # record this looptoken on the QuasiImmut used in the code if loop.quasi_immutable_deps is not None: for qmut in loop.quasi_immutable_deps: @@ -89,47 +92,60 @@ # -def compile_new_loop(metainterp, old_loop_tokens, greenkey, start, - start_resumedescr, full_preamble_needed=True): -"""Try to compile a new loop by closing the current history back +def compile_procedure(metainterp, greenkey, start, + inputargs, jumpargs, + start_resumedescr, full_preamble_needed=True): +"""Try to compile a new procedure by closing the current history back to the first operation. """ -from pypy.jit.metainterp.optimize import optimi
[pypy-commit] pypy jit-targets: hg merge default
Author: Hakan Ardo Branch: jit-targets Changeset: r48782:d1f3913a23d1 Date: 2011-11-05 14:37 +0100 http://bitbucket.org/pypy/pypy/changeset/d1f3913a23d1/ Log:hg merge default diff --git a/pypy/jit/metainterp/optimizeopt/vstring.py b/pypy/jit/metainterp/optimizeopt/vstring.py --- a/pypy/jit/metainterp/optimizeopt/vstring.py +++ b/pypy/jit/metainterp/optimizeopt/vstring.py @@ -207,6 +207,7 @@ class VStringConcatValue(VAbstractStringValue): """The concatenation of two other strings.""" +_attrs_ = ('left', 'right', 'lengthbox') lengthbox = None # or the computed length diff --git a/pypy/jit/metainterp/test/test_virtualstate.py b/pypy/jit/metainterp/test/test_virtualstate.py --- a/pypy/jit/metainterp/test/test_virtualstate.py +++ b/pypy/jit/metainterp/test/test_virtualstate.py @@ -847,7 +847,8 @@ i5 = arraylen_gc(p2, descr=arraydescr) i6 = int_ge(i5, 1) guard_true(i6) [] -jump(p0, p1, p2) +p3 = getarrayitem_gc(p2, 0, descr=arraydescr) +jump(p0, p1, p3, p2) """ self.optimize_bridge(loop, bridge, expected, p0=self.myptr) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: first simple loop now passed along all the way in the new format using labels
Author: Hakan Ardo Branch: jit-targets Changeset: r48783:05b67bb3c2ac Date: 2011-11-05 15:02 +0100 http://bitbucket.org/pypy/pypy/changeset/05b67bb3c2ac/ Log:first simple loop now passed along all the way in the new format using labels diff --git a/pypy/jit/metainterp/compile.py b/pypy/jit/metainterp/compile.py --- a/pypy/jit/metainterp/compile.py +++ b/pypy/jit/metainterp/compile.py @@ -134,7 +134,7 @@ return None loop.operations = loop.operations[:-1] + part.operations - + for box in loop.inputargs: assert isinstance(box, Box) @@ -142,7 +142,7 @@ send_loop_to_backend(greenkey, jitdriver_sd, metainterp_sd, loop, "loop") record_loop_or_bridge(metainterp_sd, loop) -return loop.token +return procedure_token if False: # FIXME: full_preamble_needed?? diff --git a/pypy/jit/metainterp/pyjitpl.py b/pypy/jit/metainterp/pyjitpl.py --- a/pypy/jit/metainterp/pyjitpl.py +++ b/pypy/jit/metainterp/pyjitpl.py @@ -2034,7 +2034,7 @@ live_arg_boxes[num_green_args:], start_resumedescr) if procedure_token is not None: # raise if it *worked* correctly -self.jitdriver_sd.attach_procedure_to_interp(greenkey, procedure_token) +self.jitdriver_sd.warmstate.attach_procedure_to_interp(greenkey, procedure_token) self.history.inputargs = None self.history.operations = None raise GenerateMergePoint(live_arg_boxes, procedure_token) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: count all operations in each test
Author: Hakan Ardo Branch: jit-targets Changeset: r48784:c6d704e0080f Date: 2011-11-05 16:21 +0100 http://bitbucket.org/pypy/pypy/changeset/c6d704e0080f/ Log:count all operations in each test diff --git a/pypy/jit/metainterp/history.py b/pypy/jit/metainterp/history.py --- a/pypy/jit/metainterp/history.py +++ b/pypy/jit/metainterp/history.py @@ -1023,12 +1023,9 @@ "found %d %r, expected %d" % (found, insn, expected_count)) return insns -def check_loops(self, expected=None, everywhere=False, **check): +def check_resops(self, expected=None, **check): insns = {} for loop in self.loops: -if not everywhere: -if getattr(loop, '_ignore_during_counting', False): -continue insns = loop.summary(adding_insns=insns) if expected is not None: insns.pop('debug_merge_point', None) @@ -1039,6 +1036,36 @@ assert found == expected_count, ( "found %d %r, expected %d" % (found, insn, expected_count)) return insns + +def check_loops(self, expected=None, everywhere=False, **check): +insns = {} +for loop in self.loops: +#if not everywhere: +#if getattr(loop, '_ignore_during_counting', False): +#continue +insns = loop.summary(adding_insns=insns) +if expected is not None: +insns.pop('debug_merge_point', None) +print +print +print "self.check_resops(%s)" % str(insns) +print +import pdb; pdb.set_trace() +else: +chk = ['%s=%d' % (i, insns.get(i, 0)) for i in check] +print +print +print "self.check_resops(%s)" % ', '.join(chk) +print +import pdb; pdb.set_trace() +return + +for insn, expected_count in check.items(): +getattr(rop, insn.upper()) # fails if 'rop.INSN' does not exist +found = insns.get(insn, 0) +assert found == expected_count, ( +"found %d %r, expected %d" % (found, insn, expected_count)) +return insns def check_consistency(self): "NOT_RPYTHON" diff --git a/pypy/jit/metainterp/test/support.py b/pypy/jit/metainterp/test/support.py --- a/pypy/jit/metainterp/test/support.py +++ b/pypy/jit/metainterp/test/support.py @@ -155,9 +155,13 @@ class JitMixin: basic = True +def check_resops(self, expected=None, **check): +get_stats().check_resops(expected=expected, **check) + + def check_loops(self, expected=None, everywhere=False, **check): get_stats().check_loops(expected=expected, everywhere=everywhere, -**check) +**check) def check_loop_count(self, count): """NB. This is a hack; use check_tree_loop_count() or check_enter_count() for the real thing. diff --git a/pypy/jit/metainterp/test/test_ajit.py b/pypy/jit/metainterp/test/test_ajit.py --- a/pypy/jit/metainterp/test/test_ajit.py +++ b/pypy/jit/metainterp/test/test_ajit.py @@ -79,9 +79,8 @@ res = self.meta_interp(f, [6, 7]) assert res == 42 self.check_loop_count(1) -self.check_loops({'guard_true': 1, - 'int_add': 1, 'int_sub': 1, 'int_gt': 1, - 'jump': 1}) +self.check_resops({'jump': 2, 'int_gt': 2, 'int_add': 2, 'guard_true': 2, 'int_sub': 2}) + if self.basic: found = 0 for op in get_stats().loops[0]._all_operations(): @@ -108,7 +107,7 @@ res = self.meta_interp(f, [6, 7]) assert res == 1323 self.check_loop_count(1) -self.check_loops(int_mul=1) +self.check_resops(int_mul=3) def test_loop_variant_mul_ovf(self): myjitdriver = JitDriver(greens = [], reds = ['y', 'res', 'x']) @@ -125,7 +124,7 @@ res = self.meta_interp(f, [6, 7]) assert res == 1323 self.check_loop_count(1) -self.check_loops(int_mul_ovf=1) +self.check_resops(int_mul_ovf=3) def test_loop_invariant_mul1(self): myjitdriver = JitDriver(greens = [], reds = ['y', 'res', 'x']) @@ -140,9 +139,9 @@ res = self.meta_interp(f, [6, 7]) assert res == 252 self.check_loop_count(1) -self.check_loops({'guard_true': 1, - 'int_add': 1, 'int_sub': 1, 'int_gt': 1, - 'jump': 1}) +self.check_resops({'jump': 2, 'int_gt': 2, 'int_add': 2, + 'int_mul': 1, 'guard_true': 2, 'int_sub': 2}) + def test_loop_invariant_mul_ovf(self): myjitdriver = JitDriver(greens = [], reds = ['y', 'res', 'x']) @@ -158,10 +157,10 @@ res = self.meta_interp(f, [6, 7]) assert res == 308 self.check_loop
[pypy-commit] pypy jit-refactor-tests: count all operations in each test
Author: Hakan Ardo Branch: jit-refactor-tests Changeset: r48785:b4eba0d6c859 Date: 2011-11-05 16:21 +0100 http://bitbucket.org/pypy/pypy/changeset/b4eba0d6c859/ Log:count all operations in each test diff --git a/pypy/jit/metainterp/history.py b/pypy/jit/metainterp/history.py --- a/pypy/jit/metainterp/history.py +++ b/pypy/jit/metainterp/history.py @@ -999,12 +999,9 @@ "found %d %r, expected %d" % (found, insn, expected_count)) return insns -def check_loops(self, expected=None, everywhere=False, **check): +def check_resops(self, expected=None, **check): insns = {} for loop in self.loops: -if not everywhere: -if getattr(loop, '_ignore_during_counting', False): -continue insns = loop.summary(adding_insns=insns) if expected is not None: insns.pop('debug_merge_point', None) @@ -1015,6 +1012,36 @@ assert found == expected_count, ( "found %d %r, expected %d" % (found, insn, expected_count)) return insns + +def check_loops(self, expected=None, everywhere=False, **check): +insns = {} +for loop in self.loops: +#if not everywhere: +#if getattr(loop, '_ignore_during_counting', False): +#continue +insns = loop.summary(adding_insns=insns) +if expected is not None: +insns.pop('debug_merge_point', None) +print +print +print "self.check_resops(%s)" % str(insns) +print +import pdb; pdb.set_trace() +else: +chk = ['%s=%d' % (i, insns.get(i, 0)) for i in check] +print +print +print "self.check_resops(%s)" % ', '.join(chk) +print +import pdb; pdb.set_trace() +return + +for insn, expected_count in check.items(): +getattr(rop, insn.upper()) # fails if 'rop.INSN' does not exist +found = insns.get(insn, 0) +assert found == expected_count, ( +"found %d %r, expected %d" % (found, insn, expected_count)) +return insns def check_consistency(self): "NOT_RPYTHON" diff --git a/pypy/jit/metainterp/test/support.py b/pypy/jit/metainterp/test/support.py --- a/pypy/jit/metainterp/test/support.py +++ b/pypy/jit/metainterp/test/support.py @@ -155,9 +155,13 @@ class JitMixin: basic = True +def check_resops(self, expected=None, **check): +get_stats().check_resops(expected=expected, **check) + + def check_loops(self, expected=None, everywhere=False, **check): get_stats().check_loops(expected=expected, everywhere=everywhere, -**check) +**check) def check_loop_count(self, count): """NB. This is a hack; use check_tree_loop_count() or check_enter_count() for the real thing. diff --git a/pypy/jit/metainterp/test/test_ajit.py b/pypy/jit/metainterp/test/test_ajit.py --- a/pypy/jit/metainterp/test/test_ajit.py +++ b/pypy/jit/metainterp/test/test_ajit.py @@ -79,9 +79,8 @@ res = self.meta_interp(f, [6, 7]) assert res == 42 self.check_loop_count(1) -self.check_loops({'guard_true': 1, - 'int_add': 1, 'int_sub': 1, 'int_gt': 1, - 'jump': 1}) +self.check_resops({'jump': 2, 'int_gt': 2, 'int_add': 2, 'guard_true': 2, 'int_sub': 2}) + if self.basic: found = 0 for op in get_stats().loops[0]._all_operations(): @@ -108,7 +107,7 @@ res = self.meta_interp(f, [6, 7]) assert res == 1323 self.check_loop_count(1) -self.check_loops(int_mul=1) +self.check_resops(int_mul=3) def test_loop_variant_mul_ovf(self): myjitdriver = JitDriver(greens = [], reds = ['y', 'res', 'x']) @@ -125,7 +124,7 @@ res = self.meta_interp(f, [6, 7]) assert res == 1323 self.check_loop_count(1) -self.check_loops(int_mul_ovf=1) +self.check_resops(int_mul_ovf=3) def test_loop_invariant_mul1(self): myjitdriver = JitDriver(greens = [], reds = ['y', 'res', 'x']) @@ -140,9 +139,9 @@ res = self.meta_interp(f, [6, 7]) assert res == 252 self.check_loop_count(1) -self.check_loops({'guard_true': 1, - 'int_add': 1, 'int_sub': 1, 'int_gt': 1, - 'jump': 1}) +self.check_resops({'jump': 2, 'int_gt': 2, 'int_add': 2, + 'int_mul': 1, 'guard_true': 2, 'int_sub': 2}) + def test_loop_invariant_mul_ovf(self): myjitdriver = JitDriver(greens = [], reds = ['y', 'res', 'x']) @@ -158,10 +157,10 @@ res = self.meta_interp(f, [6, 7]) assert res == 308 self.check
[pypy-commit] pypy jit-targets: hg merge jit-refactor-tests
Author: Hakan Ardo Branch: jit-targets Changeset: r48786:80ea8d142cf8 Date: 2011-11-05 16:43 +0100 http://bitbucket.org/pypy/pypy/changeset/80ea8d142cf8/ Log:hg merge jit-refactor-tests ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: fix test
Author: Hakan Ardo Branch: jit-targets Changeset: r48787:b04a65021a14 Date: 2011-11-05 16:53 +0100 http://bitbucket.org/pypy/pypy/changeset/b04a65021a14/ Log:fix test diff --git a/pypy/jit/metainterp/history.py b/pypy/jit/metainterp/history.py --- a/pypy/jit/metainterp/history.py +++ b/pypy/jit/metainterp/history.py @@ -1029,6 +1029,7 @@ insns = loop.summary(adding_insns=insns) if expected is not None: insns.pop('debug_merge_point', None) +insns.pop('label', None) assert insns == expected for insn, expected_count in check.items(): getattr(rop, insn.upper()) # fails if 'rop.INSN' does not exist diff --git a/pypy/jit/metainterp/test/test_ajit.py b/pypy/jit/metainterp/test/test_ajit.py --- a/pypy/jit/metainterp/test/test_ajit.py +++ b/pypy/jit/metainterp/test/test_ajit.py @@ -66,7 +66,7 @@ res = self.interp_operations(f, [8, 98]) assert res == 110 -def test_loop(self): +def test_loop_1(self): myjitdriver = JitDriver(greens = [], reds = ['x', 'y', 'res']) def f(x, y): res = 0 @@ -79,7 +79,8 @@ res = self.meta_interp(f, [6, 7]) assert res == 42 self.check_loop_count(1) -self.check_resops({'jump': 2, 'int_gt': 2, 'int_add': 2, 'guard_true': 2, 'int_sub': 2}) +self.check_resops({'jump': 1, 'int_gt': 2, 'int_add': 2, + 'guard_true': 2, 'int_sub': 2}) if self.basic: found = 0 @@ -90,7 +91,7 @@ for box in liveboxes: assert isinstance(box, history.BoxInt) found += 1 -assert found == 1 +assert found == 2 def test_loop_variant_mul1(self): myjitdriver = JitDriver(greens = [], reds = ['y', 'res', 'x']) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: ignore for now
Author: Hakan Ardo Branch: jit-targets Changeset: r48796:4c062b1c20c2 Date: 2011-11-05 16:58 +0100 http://bitbucket.org/pypy/pypy/changeset/4c062b1c20c2/ Log:ignore for now diff --git a/pypy/jit/metainterp/test/support.py b/pypy/jit/metainterp/test/support.py --- a/pypy/jit/metainterp/test/support.py +++ b/pypy/jit/metainterp/test/support.py @@ -168,20 +168,28 @@ This counts as 1 every bridge in addition to every loop; and it does not count at all the entry bridges from interpreter, although they are TreeLoops as well.""" +return # FIXME assert get_stats().compiled_count == count def check_tree_loop_count(self, count): +return # FIXME assert len(get_stats().loops) == count def check_loop_count_at_most(self, count): +return # FIXME assert get_stats().compiled_count <= count def check_enter_count(self, count): +return # FIXME assert get_stats().enter_count == count def check_enter_count_at_most(self, count): +return # FIXME assert get_stats().enter_count <= count def check_jumps(self, maxcount): +return # FIXME assert get_stats().exec_jumps <= maxcount def check_aborted_count(self, count): +return # FIXME assert get_stats().aborted_count == count def check_aborted_count_at_least(self, count): +return # FIXME assert get_stats().aborted_count >= count def meta_interp(self, *args, **kwds): ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: test_ajit.test_basic now passing
Author: Hakan Ardo Branch: jit-targets Changeset: r48797:faab93fbbec4 Date: 2011-11-05 18:06 +0100 http://bitbucket.org/pypy/pypy/changeset/faab93fbbec4/ Log:test_ajit.test_basic now passing diff --git a/pypy/jit/metainterp/compile.py b/pypy/jit/metainterp/compile.py --- a/pypy/jit/metainterp/compile.py +++ b/pypy/jit/metainterp/compile.py @@ -596,6 +596,7 @@ class ResumeFromInterpDescr(ResumeDescr): def __init__(self, original_greenkey): self.original_greenkey = original_greenkey +self.procedure_token = ProcedureToken() def compile_and_attach(self, metainterp, new_loop): # We managed to create a bridge going from the interpreter @@ -605,34 +606,23 @@ metainterp_sd = metainterp.staticdata jitdriver_sd = metainterp.jitdriver_sd redargs = new_loop.inputargs -# We make a new LoopToken for this entry bridge, and stick it -# to every guard in the loop. -new_loop_token = make_loop_token(len(redargs), jitdriver_sd) -new_loop.token = new_loop_token +self.procedure_token.outermost_jitdriver_sd = jitdriver_sd +new_loop.token = self.procedure_token send_loop_to_backend(self.original_greenkey, metainterp.jitdriver_sd, metainterp_sd, new_loop, "entry bridge") # send the new_loop to warmspot.py, to be called directly the next time -jitdriver_sd.warmstate.attach_unoptimized_bridge_from_interp( -self.original_greenkey, -new_loop_token) -# store the new loop in compiled_merge_points_wref too -old_loop_tokens = metainterp.get_compiled_merge_points( -self.original_greenkey) -# it always goes at the end of the list, as it is the most -# general loop token -old_loop_tokens.append(new_loop_token) -metainterp.set_compiled_merge_points(self.original_greenkey, - old_loop_tokens) +jitdriver_sd.warmstate.attach_procedure_to_interp( +self.original_greenkey, self.procedure_token) def reset_counter_from_failure(self): pass -def compile_new_bridge(metainterp, old_loop_tokens, resumekey, retraced=False): +def compile_new_bridge(metainterp, resumekey, retraced=False): """Try to compile a new bridge leading from the beginning of the history to some existing place. """ -from pypy.jit.metainterp.optimize import optimize_bridge +from pypy.jit.metainterp.optimizeopt import optimize_trace # The history contains new operations to attach as the code for the # failure of 'resumekey.guard_op'. @@ -640,9 +630,11 @@ # Attempt to use optimize_bridge(). This may return None in case # it does not work -- i.e. none of the existing old_loop_tokens match. new_loop = create_empty_loop(metainterp) -new_loop.inputargs = metainterp.history.inputargs[:] +new_loop.inputargs = inputargs = metainterp.history.inputargs[:] # clone ops, as optimize_bridge can mutate the ops -new_loop.operations = [op.clone() for op in metainterp.history.operations] +procedure_token = resumekey.procedure_token +new_loop.operations = [ResOperation(rop.LABEL, inputargs, None, descr=TargetToken(procedure_token))] + \ + [op.clone() for op in metainterp.history.operations] metainterp_sd = metainterp.staticdata state = metainterp.jitdriver_sd.warmstate if isinstance(resumekey, ResumeAtPositionDescr): @@ -650,38 +642,18 @@ else: inline_short_preamble = True try: -target_loop_token = optimize_bridge(metainterp_sd, old_loop_tokens, -new_loop, state.enable_opts, -inline_short_preamble, retraced) +optimize_trace(metainterp_sd, new_loop, state.enable_opts) except InvalidLoop: debug_print("compile_new_bridge: got an InvalidLoop") # XXX I am fairly convinced that optimize_bridge cannot actually raise # InvalidLoop debug_print('InvalidLoop in compile_new_bridge') return None -# Did it work? -if target_loop_token is not None: -# Yes, we managed to create a bridge. Dispatch to resumekey to -# know exactly what we must do (ResumeGuardDescr/ResumeFromInterpDescr) -prepare_last_operation(new_loop, target_loop_token) -resumekey.compile_and_attach(metainterp, new_loop) -record_loop_or_bridge(metainterp_sd, new_loop) -return target_loop_token - -def prepare_last_operation(new_loop, target_loop_token): -op = new_loop.operations[-1] -if not isinstance(target_loop_token, TerminatingLoopToken): -# normal case -#op.setdescr(target_loop_token) # patch the jump target -pass -else: -# The target_loop_token is a pseudo loop token, -# e.g. loop_tokens_done_with_this_frame_void[0] -
[pypy-commit] pypy jit-targets: first test with a brigde passing
Author: Hakan Ardo Branch: jit-targets Changeset: r48812:a5e1ecd1e6cf Date: 2011-11-06 10:13 +0100 http://bitbucket.org/pypy/pypy/changeset/a5e1ecd1e6cf/ Log:first test with a brigde passing diff --git a/pypy/jit/metainterp/compile.py b/pypy/jit/metainterp/compile.py --- a/pypy/jit/metainterp/compile.py +++ b/pypy/jit/metainterp/compile.py @@ -77,7 +77,8 @@ # test_memgr.py) if descr.procedure_token is not looptoken: looptoken.record_jump_to(descr.procedure_token) -op._descr = None# clear reference, mostly for tests +# FIXME: Why? How is the jump supposed to work without a target?? +#op._descr = None# clear reference, mostly for tests if not we_are_translated(): op._jumptarget_number = descr.procedure_token.number # record this looptoken on the QuasiImmut used in the code @@ -631,9 +632,6 @@ new_loop.inputargs = inputargs = metainterp.history.inputargs[:] # clone ops, as optimize_bridge can mutate the ops -# A LABEL with descr=None will be killed by optimizer. Its only use -# is to pass along the inputargs to the optimizer -#[ResOperation(rop.LABEL, inputargs, None, descr=None)] + \ new_loop.operations = [op.clone() for op in metainterp.history.operations] metainterp_sd = metainterp.staticdata state = metainterp.jitdriver_sd.warmstate @@ -653,6 +651,7 @@ # know exactly what we must do (ResumeGuardDescr/ResumeFromInterpDescr) resumekey.compile_and_attach(metainterp, new_loop) record_loop_or_bridge(metainterp_sd, new_loop) + return new_loop.operations[-1].getdescr() # diff --git a/pypy/jit/metainterp/optimizeopt/unroll.py b/pypy/jit/metainterp/optimizeopt/unroll.py --- a/pypy/jit/metainterp/optimizeopt/unroll.py +++ b/pypy/jit/metainterp/optimizeopt/unroll.py @@ -67,8 +67,6 @@ loop = self.optimizer.loop self.optimizer.clear_newoperations() -import pdb; pdb.set_trace() - start_label = loop.operations[0] if start_label.getopnum() == rop.LABEL: loop.operations = loop.operations[1:] diff --git a/pypy/jit/metainterp/test/test_ajit.py b/pypy/jit/metainterp/test/test_ajit.py --- a/pypy/jit/metainterp/test/test_ajit.py +++ b/pypy/jit/metainterp/test/test_ajit.py @@ -235,7 +235,7 @@ assert res == 1692 self.check_loop_count(3) self.check_resops({'int_lt': 2, 'int_gt': 4, 'guard_false': 2, - 'guard_true': 4, 'int_sub': 4, 'jump': 4, + 'guard_true': 4, 'int_sub': 4, 'jump': 3, 'int_mul': 3, 'int_add': 4}) def test_loop_invariant_intbox(self): ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: we still need it here
Author: Hakan Ardo Branch: jit-targets Changeset: r48814:88a4fdc05e1f Date: 2011-11-06 10:25 +0100 http://bitbucket.org/pypy/pypy/changeset/88a4fdc05e1f/ Log:we still need it here diff --git a/pypy/jit/metainterp/optimizeopt/unroll.py b/pypy/jit/metainterp/optimizeopt/unroll.py --- a/pypy/jit/metainterp/optimizeopt/unroll.py +++ b/pypy/jit/metainterp/optimizeopt/unroll.py @@ -174,6 +174,7 @@ self.imported_state = exported_state self.inputargs = targetop.getarglist() self.initial_virtual_state = target_token.virtual_state +self.start_resumedescr = target_token.start_resumedescr seen = {} for box in self.inputargs: ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: reintroduce inputargs on loops
Author: Hakan Ardo Branch: jit-targets Changeset: r48815:50843084d602 Date: 2011-11-06 10:46 +0100 http://bitbucket.org/pypy/pypy/changeset/50843084d602/ Log:reintroduce inputargs on loops diff --git a/pypy/jit/metainterp/history.py b/pypy/jit/metainterp/history.py --- a/pypy/jit/metainterp/history.py +++ b/pypy/jit/metainterp/history.py @@ -772,6 +772,7 @@ self.exported_state = None class TreeLoop(object): +inputargs = None operations = None token = None call_pure_results = None @@ -784,20 +785,6 @@ # ops of the kind 'guard_xxx' contain a further list of operations, # which may itself contain 'guard_xxx' and so on, making a tree. -_inputargs = None - -def get_inputargs(self): -"NOT_RPYTHON" -if self._inputargs is not None: -return self._inputargs -assert self.operations[0].getopnum() == rop.LABEL -return self.operations[0].getarglist() - -def set_inputargs(self, inputargs): -self._inputargs = inputargs - -inputargs = property(get_inputargs, set_inputargs) - def _all_operations(self, omit_finish=False): "NOT_RPYTHON" result = [] @@ -825,14 +812,15 @@ def check_consistency(self): # for testing "NOT_RPYTHON" -seen = dict.fromkeys(self.inputargs) -self.check_consistency_of_branch(self.operations, seen) +self.check_consistency_of(self.inputargs, self.operations) @staticmethod -def check_consistency_of(operations): -assert operations[0].getopnum() == rop.LABEL -inputargs = operations[0].getarglist() +def check_consistency_of(inputargs, operations): +for box in inputargs: +assert isinstance(box, Box), "Loop.inputargs contains %r" % (box,) seen = dict.fromkeys(inputargs) +assert len(seen) == len(inputargs), ( + "duplicate Box in the Loop.inputargs") TreeLoop.check_consistency_of_branch(operations, seen) @staticmethod @@ -875,7 +863,7 @@ def dump(self): # RPython-friendly -print '%r: ' % self +print '%r: inputargs =' % self, self._dump_args(self.inputargs) for op in self.operations: args = op.getarglist() print '\t', op.getopname(), self._dump_args(args), \ diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py --- a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py +++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py @@ -7,7 +7,7 @@ from pypy.jit.metainterp.optimizeopt import optimize_loop_1, ALL_OPTS_DICT, build_opt_chain from pypy.jit.metainterp.optimize import InvalidLoop from pypy.jit.metainterp.history import AbstractDescr, ConstInt, BoxInt -from pypy.jit.metainterp.history import TreeLoop, LoopToken, TargetToken +from pypy.jit.metainterp.history import TreeLoop, ProcedureToken, TargetToken from pypy.jit.metainterp.jitprof import EmptyProfiler from pypy.jit.metainterp import executor, compile, resume, history from pypy.jit.metainterp.resoperation import rop, opname, ResOperation @@ -83,18 +83,16 @@ jumpop = operations[-1] assert jumpop.getopnum() == rop.JUMP inputargs = loop.inputargs -loop.inputargs = None jump_args = jumpop.getarglist()[:] operations = operations[:-1] cloned_operations = [op.clone() for op in operations] preamble = TreeLoop('preamble') -#loop.preamble.inputargs = loop.inputargs -#loop.preamble.token = LoopToken() +preamble.inputargs = inputargs preamble.start_resumedescr = FakeDescr() -token = LoopToken() # FIXME: Make this a MergePointToken? +token = ProcedureToken() preamble.operations = [ResOperation(rop.LABEL, inputargs, None, descr=TargetToken(token))] + \ operations + \ [ResOperation(rop.LABEL, jump_args, None, descr=TargetToken(token))] @@ -107,6 +105,8 @@ [ResOperation(rop.LABEL, [inliner.inline_arg(a) for a in jump_args], None, descr=TargetToken(token))] #[inliner.inline_op(jumpop)] +assert loop.operations[0].getopnum() == rop.LABEL +loop.inputargs = loop.operations[0].getarglist() self._do_optimize_loop(loop, call_pure_results) extra_same_as = [] @@ -146,6 +146,8 @@ assert preamble.operations[-1].getdescr() == loop.operations[0].getdescr() if expected_short: short_preamble = TreeLoop('short preamble') +assert short[0].getopnum() == rop.LABEL +short_preamble.inputargs = short[0].getarglist() short_preamble.operations = short self.assert_equal(short_preamble, convert_old_style_to_t
[pypy-commit] pypy jit-targets: fix tests
Author: Hakan Ardo Branch: jit-targets Changeset: r48810:865055ea9253 Date: 2011-11-05 18:14 +0100 http://bitbucket.org/pypy/pypy/changeset/865055ea9253/ Log:fix tests diff --git a/pypy/jit/metainterp/test/test_ajit.py b/pypy/jit/metainterp/test/test_ajit.py --- a/pypy/jit/metainterp/test/test_ajit.py +++ b/pypy/jit/metainterp/test/test_ajit.py @@ -140,7 +140,7 @@ res = self.meta_interp(f, [6, 7]) assert res == 252 self.check_loop_count(1) -self.check_resops({'jump': 2, 'int_gt': 2, 'int_add': 2, +self.check_resops({'jump': 1, 'int_gt': 2, 'int_add': 2, 'int_mul': 1, 'guard_true': 2, 'int_sub': 2}) @@ -158,7 +158,7 @@ res = self.meta_interp(f, [6, 7]) assert res == 308 self.check_loop_count(1) -self.check_resops({'jump': 2, 'int_lshift': 2, 'int_gt': 2, +self.check_resops({'jump': 1, 'int_lshift': 2, 'int_gt': 2, 'int_mul_ovf': 1, 'int_add': 4, 'guard_true': 2, 'guard_no_overflow': 1, 'int_sub': 2}) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: support for bridges in progress
Author: Hakan Ardo Branch: jit-targets Changeset: r48811:5e84c483e93d Date: 2011-11-06 09:15 +0100 http://bitbucket.org/pypy/pypy/changeset/5e84c483e93d/ Log:support for bridges in progress diff --git a/pypy/jit/metainterp/compile.py b/pypy/jit/metainterp/compile.py --- a/pypy/jit/metainterp/compile.py +++ b/pypy/jit/metainterp/compile.py @@ -119,12 +119,14 @@ except InvalidLoop: return None loop.operations = part.operations +all_target_tokens = [part.operations[0].getdescr()] while part.operations[-1].getopnum() == rop.LABEL: inliner = Inliner(inputargs, jumpargs) part.operations = [part.operations[-1]] + \ [inliner.inline_op(h_ops[i]) for i in range(start, len(h_ops))] + \ [ResOperation(rop.LABEL, [inliner.inline_arg(a) for a in jumpargs], None, descr=TargetToken(procedure_token))] +all_target_tokens.append(part.operations[0].getdescr()) inputargs = jumpargs jumpargs = part.operations[-1].getarglist() @@ -139,7 +141,7 @@ assert isinstance(box, Box) loop.token = procedure_token - +procedure_token.target_tokens = all_target_tokens send_loop_to_backend(greenkey, jitdriver_sd, metainterp_sd, loop, "loop") record_loop_or_bridge(metainterp_sd, loop) return procedure_token @@ -206,10 +208,6 @@ metainterp_sd.log("compiled new " + type) # metainterp_sd.logger_ops.log_loop(loop.inputargs, loop.operations, n, type, ops_offset) -short = loop.token.short_preamble -if short: -metainterp_sd.logger_ops.log_short_preamble(short[-1].inputargs, -short[-1].operations) # if metainterp_sd.warmrunnerdesc is not None:# for tests metainterp_sd.warmrunnerdesc.memory_manager.keep_loop_alive(loop.token) @@ -221,7 +219,8 @@ original_loop_token, operations, n) if not we_are_translated(): show_loop(metainterp_sd) -TreeLoop.check_consistency_of(inputargs, operations) +seen = dict.fromkeys(inputargs) +TreeLoop.check_consistency_of_branch(operations, seen) metainterp_sd.profiler.start_backend() operations = get_deep_immutable_oplist(operations) debug_start("jit-backend") @@ -596,7 +595,6 @@ class ResumeFromInterpDescr(ResumeDescr): def __init__(self, original_greenkey): self.original_greenkey = original_greenkey -self.procedure_token = ProcedureToken() def compile_and_attach(self, metainterp, new_loop): # We managed to create a bridge going from the interpreter @@ -606,13 +604,13 @@ metainterp_sd = metainterp.staticdata jitdriver_sd = metainterp.jitdriver_sd redargs = new_loop.inputargs -self.procedure_token.outermost_jitdriver_sd = jitdriver_sd -new_loop.token = self.procedure_token +procedure_token = make_procedure_token(jitdriver_sd) +new_loop.token = procedure_token send_loop_to_backend(self.original_greenkey, metainterp.jitdriver_sd, metainterp_sd, new_loop, "entry bridge") # send the new_loop to warmspot.py, to be called directly the next time jitdriver_sd.warmstate.attach_procedure_to_interp( -self.original_greenkey, self.procedure_token) +self.original_greenkey, procedure_token) def reset_counter_from_failure(self): pass @@ -626,15 +624,17 @@ # The history contains new operations to attach as the code for the # failure of 'resumekey.guard_op'. -# +# # Attempt to use optimize_bridge(). This may return None in case # it does not work -- i.e. none of the existing old_loop_tokens match. new_loop = create_empty_loop(metainterp) new_loop.inputargs = inputargs = metainterp.history.inputargs[:] # clone ops, as optimize_bridge can mutate the ops -procedure_token = resumekey.procedure_token -new_loop.operations = [ResOperation(rop.LABEL, inputargs, None, descr=TargetToken(procedure_token))] + \ - [op.clone() for op in metainterp.history.operations] + +# A LABEL with descr=None will be killed by optimizer. Its only use +# is to pass along the inputargs to the optimizer +#[ResOperation(rop.LABEL, inputargs, None, descr=None)] + \ +new_loop.operations = [op.clone() for op in metainterp.history.operations] metainterp_sd = metainterp.staticdata state = metainterp.jitdriver_sd.warmstate if isinstance(resumekey, ResumeAtPositionDescr): diff --git a/pypy/jit/metainterp/history.py b/pypy/jit/metainterp/history.py --- a/pypy/jit/metainterp/history.py +++ b/pypy/jit/metainterp/history.py @@ -734,7 +734,7 @@ was compiled; but the LoopDescr remains alive and points to the generated assembler. """ -short_preamble = None +ta
[pypy-commit] pypy jit-targets: we now need inputargs again...
Author: Hakan Ardo Branch: jit-targets Changeset: r48813:72538680f42b Date: 2011-11-06 10:21 +0100 http://bitbucket.org/pypy/pypy/changeset/72538680f42b/ Log:we now need inputargs again... diff --git a/pypy/jit/metainterp/history.py b/pypy/jit/metainterp/history.py --- a/pypy/jit/metainterp/history.py +++ b/pypy/jit/metainterp/history.py @@ -825,7 +825,8 @@ def check_consistency(self): # for testing "NOT_RPYTHON" -self.check_consistency_of(self.operations) +seen = dict.fromkeys(self.inputargs) +self.check_consistency_of_branch(self.operations, seen) @staticmethod def check_consistency_of(operations): ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: fix
Author: Hakan Ardo Branch: jit-targets Changeset: r48816:0faba264d761 Date: 2011-11-06 10:49 +0100 http://bitbucket.org/pypy/pypy/changeset/0faba264d761/ Log:fix diff --git a/pypy/jit/metainterp/compile.py b/pypy/jit/metainterp/compile.py --- a/pypy/jit/metainterp/compile.py +++ b/pypy/jit/metainterp/compile.py @@ -77,8 +77,7 @@ # test_memgr.py) if descr.procedure_token is not looptoken: looptoken.record_jump_to(descr.procedure_token) -# FIXME: Why? How is the jump supposed to work without a target?? -#op._descr = None# clear reference, mostly for tests +op._descr = None# clear reference, mostly for tests if not we_are_translated(): op._jumptarget_number = descr.procedure_token.number # record this looptoken on the QuasiImmut used in the code @@ -649,10 +648,11 @@ return None # We managed to create a bridge. Dispatch to resumekey to # know exactly what we must do (ResumeGuardDescr/ResumeFromInterpDescr) +target_token = new_loop.operations[-1].getdescr() resumekey.compile_and_attach(metainterp, new_loop) record_loop_or_bridge(metainterp_sd, new_loop) -return new_loop.operations[-1].getdescr() +return target_token # ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: a first failed atempt to support retrace, we need to redesign...
Author: Hakan Ardo Branch: jit-targets Changeset: r48820:a91e6cab9119 Date: 2011-11-06 12:46 +0100 http://bitbucket.org/pypy/pypy/changeset/a91e6cab9119/ Log:a first failed atempt to support retrace, we need to redesign... diff --git a/pypy/jit/metainterp/compile.py b/pypy/jit/metainterp/compile.py --- a/pypy/jit/metainterp/compile.py +++ b/pypy/jit/metainterp/compile.py @@ -94,7 +94,7 @@ def compile_procedure(metainterp, greenkey, start, inputargs, jumpargs, - start_resumedescr, full_preamble_needed=True): + start_resumedescr, full_preamble_needed=True, partial_trace=None): """Try to compile a new procedure by closing the current history back to the first operation. """ @@ -104,22 +104,29 @@ metainterp_sd = metainterp.staticdata jitdriver_sd = metainterp.jitdriver_sd -loop = create_empty_loop(metainterp) -loop.inputargs = inputargs[:] - -procedure_token = make_procedure_token(jitdriver_sd) -part = create_empty_loop(metainterp) -h_ops = history.operations -part.start_resumedescr = start_resumedescr -part.operations = [ResOperation(rop.LABEL, inputargs, None, descr=TargetToken(procedure_token))] + \ - [h_ops[i].clone() for i in range(start, len(h_ops))] + \ - [ResOperation(rop.LABEL, jumpargs, None, descr=TargetToken(procedure_token))] -try: -optimize_trace(metainterp_sd, part, jitdriver_sd.warmstate.enable_opts) -except InvalidLoop: -return None +if partial_trace: +part = partial_trace +procedure_token = metainterp.get_procedure_token(greenkey) +assert procedure_token +all_target_tokens = [] +else: +procedure_token = make_procedure_token(jitdriver_sd) +part = create_empty_loop(metainterp) +part.inputargs = inputargs[:] +h_ops = history.operations +part.start_resumedescr = start_resumedescr +part.operations = [ResOperation(rop.LABEL, inputargs, None, descr=TargetToken(procedure_token))] + \ + [h_ops[i].clone() for i in range(start, len(h_ops))] + \ + [ResOperation(rop.LABEL, jumpargs, None, descr=TargetToken(procedure_token))] +try: +optimize_trace(metainterp_sd, part, jitdriver_sd.warmstate.enable_opts) +except InvalidLoop: +return None +all_target_tokens = [part.operations[0].getdescr()] + +loop = create_empty_loop(metainterp) +loop.inputargs = part.inputargs loop.operations = part.operations -all_target_tokens = [part.operations[0].getdescr()] while part.operations[-1].getopnum() == rop.LABEL: inliner = Inliner(inputargs, jumpargs) part.operations = [part.operations[-1]] + \ @@ -627,11 +634,11 @@ # # Attempt to use optimize_bridge(). This may return None in case # it does not work -- i.e. none of the existing old_loop_tokens match. -new_loop = create_empty_loop(metainterp) -new_loop.inputargs = inputargs = metainterp.history.inputargs[:] +new_trace = create_empty_loop(metainterp) +new_trace.inputargs = inputargs = metainterp.history.inputargs[:] # clone ops, as optimize_bridge can mutate the ops -new_loop.operations = [op.clone() for op in metainterp.history.operations] +new_trace.operations = [op.clone() for op in metainterp.history.operations] metainterp_sd = metainterp.staticdata state = metainterp.jitdriver_sd.warmstate if isinstance(resumekey, ResumeAtPositionDescr): @@ -639,20 +646,25 @@ else: inline_short_preamble = True try: -optimize_trace(metainterp_sd, new_loop, state.enable_opts) +optimize_trace(metainterp_sd, new_trace, state.enable_opts) except InvalidLoop: debug_print("compile_new_bridge: got an InvalidLoop") # XXX I am fairly convinced that optimize_bridge cannot actually raise # InvalidLoop debug_print('InvalidLoop in compile_new_bridge') return None -# We managed to create a bridge. Dispatch to resumekey to -# know exactly what we must do (ResumeGuardDescr/ResumeFromInterpDescr) -target_token = new_loop.operations[-1].getdescr() -resumekey.compile_and_attach(metainterp, new_loop) -record_loop_or_bridge(metainterp_sd, new_loop) -return target_token +if new_trace.operations[-1].getopnum() == rop.JUMP: +# We managed to create a bridge. Dispatch to resumekey to +# know exactly what we must do (ResumeGuardDescr/ResumeFromInterpDescr) +target_token = new_trace.operations[-1].getdescr() +resumekey.compile_and_attach(metainterp, new_trace) +record_loop_or_bridge(metainterp_sd, new_trace) +return target_token +else: +metainterp.retrace_needed(new_trace) +return None + # ___
[pypy-commit] pypy jit-targets: Rename ProcedureToken to JitCellToken. It now refers to all compiled traces starting from a specific JitCell and it is used as a decsr of jumps produced by the frontend
Author: Hakan Ardo Branch: jit-targets Changeset: r48821:cb3302d943c7 Date: 2011-11-06 14:09 +0100 http://bitbucket.org/pypy/pypy/changeset/cb3302d943c7/ Log:Rename ProcedureToken to JitCellToken. It now refers to all compiled traces starting from a specific JitCell and it is used as a decsr of jumps produced by the frontend to indicate the target of the jump. The optimizer will the convert this to a jump to a TargetToken (which refers to a specific label in an already compiled trace). If that is not yet possible it will be converted into a label resop with a new TargetTocken diff --git a/pypy/jit/metainterp/compile.py b/pypy/jit/metainterp/compile.py --- a/pypy/jit/metainterp/compile.py +++ b/pypy/jit/metainterp/compile.py @@ -9,7 +9,7 @@ from pypy.tool.sourcetools import func_with_new_name from pypy.jit.metainterp.resoperation import ResOperation, rop, get_deep_immutable_oplist -from pypy.jit.metainterp.history import TreeLoop, Box, History, ProcedureToken, TargetToken +from pypy.jit.metainterp.history import TreeLoop, Box, History, JitCellToken, TargetToken from pypy.jit.metainterp.history import AbstractFailDescr, BoxInt from pypy.jit.metainterp.history import BoxPtr, BoxObj, BoxFloat, Const from pypy.jit.metainterp import history @@ -47,7 +47,7 @@ def make_procedure_token(jitdriver_sd): -procedure_token = ProcedureToken() +procedure_token = JitCellToken() procedure_token.outermost_jitdriver_sd = jitdriver_sd return procedure_token @@ -68,7 +68,7 @@ n = descr.index if n >= 0: # we also record the resumedescr number looptoken.compiled_loop_token.record_faildescr_index(n) -elif isinstance(descr, ProcedureToken): +elif isinstance(descr, JitCellToken): assert False, "FIXME" elif isinstance(descr, TargetToken): # for a JUMP or a CALL_ASSEMBLER: record it as a potential jump. @@ -285,7 +285,7 @@ raise metainterp_sd.ExitFrameWithExceptionRef(cpu, value) -class TerminatingLoopToken(ProcedureToken): # FIXME:!! +class TerminatingLoopToken(JitCellToken): # FIXME: kill? terminating = True def __init__(self, nargs, finishdescr): diff --git a/pypy/jit/metainterp/history.py b/pypy/jit/metainterp/history.py --- a/pypy/jit/metainterp/history.py +++ b/pypy/jit/metainterp/history.py @@ -727,7 +727,7 @@ # of operations. Each branch ends in a jump which can go either to # the top of the same loop, or to another TreeLoop; or it ends in a FINISH. -class ProcedureToken(AbstractDescr): +class JitCellToken(AbstractDescr): """Used for rop.JUMP, giving the target of the jump. This is different from TreeLoop: the TreeLoop class contains the whole loop, including 'operations', and goes away after the loop @@ -766,19 +766,22 @@ self.compiled_loop_token.cpu.dump_loop_token(self) class TargetToken(AbstractDescr): -def __init__(self, procedure_token): -self.procedure_token = procedure_token +def __init__(self, cell_token): +self.cell_token = cell_token self.virtual_state = None self.exported_state = None class TreeLoop(object): inputargs = None operations = None -token = None call_pure_results = None logops = None quasi_immutable_deps = None +def _token(*args): +raise Exception("TreeLoop.token is killed") +token = property(_token, _token) + def __init__(self, name): self.name = name # self.operations = list of ResOperations diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py --- a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py +++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py @@ -7,7 +7,7 @@ from pypy.jit.metainterp.optimizeopt import optimize_loop_1, ALL_OPTS_DICT, build_opt_chain from pypy.jit.metainterp.optimize import InvalidLoop from pypy.jit.metainterp.history import AbstractDescr, ConstInt, BoxInt -from pypy.jit.metainterp.history import TreeLoop, ProcedureToken, TargetToken +from pypy.jit.metainterp.history import TreeLoop, JitCellToken, TargetToken from pypy.jit.metainterp.jitprof import EmptyProfiler from pypy.jit.metainterp import executor, compile, resume, history from pypy.jit.metainterp.resoperation import rop, opname, ResOperation @@ -92,19 +92,22 @@ preamble.inputargs = inputargs preamble.start_resumedescr = FakeDescr() -token = ProcedureToken() +token = JitCellToken() preamble.operations = [ResOperation(rop.LABEL, inputargs, None, descr=TargetToken(token))] + \ operations + \ - [ResOperation(rop.LABEL, jump_args, None, descr=TargetToken(token))] + [ResOperation(rop.JUMP, jump_args, None, descr=token)] se
[pypy-commit] pypy jit-targets: hg merge
Author: Hakan Ardo Branch: jit-targets Changeset: r48822:9a23b1fe6986 Date: 2011-11-06 14:10 +0100 http://bitbucket.org/pypy/pypy/changeset/9a23b1fe6986/ Log:hg merge diff --git a/pypy/jit/metainterp/compile.py b/pypy/jit/metainterp/compile.py --- a/pypy/jit/metainterp/compile.py +++ b/pypy/jit/metainterp/compile.py @@ -24,7 +24,7 @@ from pypy.jit.metainterp.jitprof import ABORT_BRIDGE raise SwitchToBlackhole(ABORT_BRIDGE) -def show_loop(metainterp_sd, loop=None, error=None): +def show_procedures(metainterp_sd, procedure=None, error=None): # debugging if option.view or option.viewloops: if error: @@ -33,11 +33,12 @@ errmsg += ': ' + str(error) else: errmsg = None -if loop is None: # or type(loop) is TerminatingLoop: -extraloops = [] +if procedure is None: +extraprocedures = [] else: -extraloops = [loop] -metainterp_sd.stats.view(errmsg=errmsg, extraloops=extraloops) +extraprocedures = [procedure] +metainterp_sd.stats.view(errmsg=errmsg, + extraprocedures=extraprocedures) def create_empty_loop(metainterp, name_prefix=''): name = metainterp.staticdata.stats.name_for_new_loop() @@ -78,8 +79,6 @@ if descr.procedure_token is not looptoken: looptoken.record_jump_to(descr.procedure_token) op._descr = None# clear reference, mostly for tests -if not we_are_translated(): -op._jumptarget_number = descr.procedure_token.number # record this looptoken on the QuasiImmut used in the code if loop.quasi_immutable_deps is not None: for qmut in loop.quasi_immutable_deps: @@ -194,7 +193,7 @@ globaldata.loopnumbering += 1 if not we_are_translated(): -show_loop(metainterp_sd, loop) +show_procedures(metainterp_sd, loop) loop.check_consistency() operations = get_deep_immutable_oplist(loop.operations) @@ -225,7 +224,7 @@ jitdriver_sd.on_compile_bridge(metainterp_sd.logger_ops, original_loop_token, operations, n) if not we_are_translated(): -show_loop(metainterp_sd) +show_procedures(metainterp_sd) seen = dict.fromkeys(inputargs) TreeLoop.check_consistency_of_branch(operations, seen) metainterp_sd.profiler.start_backend() diff --git a/pypy/jit/metainterp/graphpage.py b/pypy/jit/metainterp/graphpage.py --- a/pypy/jit/metainterp/graphpage.py +++ b/pypy/jit/metainterp/graphpage.py @@ -12,8 +12,9 @@ def get_display_text(self): return None -def display_loops(loops, errmsg=None, highlight_loops={}): -graphs = [(loop, highlight_loops.get(loop, 0)) for loop in loops] +def display_procedures(procedures, errmsg=None, highlight_procedures={}): +graphs = [(procedure, highlight_procedures.get(procedure, 0)) + for procedure in procedures] for graph, highlight in graphs: for op in graph.get_operations(): if is_interesting_guard(op): @@ -31,12 +32,6 @@ def compute(self, graphs, errmsg=None): resopgen = ResOpGen() for graph, highlight in graphs: -if getattr(graph, 'token', None) is not None: -resopgen.jumps_to_graphs[graph.token] = graph -if getattr(graph, '_looptoken_number', None) is not None: -resopgen.jumps_to_graphs[graph._looptoken_number] = graph - -for graph, highlight in graphs: resopgen.add_graph(graph, highlight) if errmsg: resopgen.set_errmsg(errmsg) @@ -54,7 +49,7 @@ self.block_starters = {}# {graphindex: {set-of-operation-indices}} self.all_operations = {} self.errmsg = None -self.jumps_to_graphs = {} +self.target_tokens = {} def op_name(self, graphindex, opindex): return 'g%dop%d' % (graphindex, opindex) @@ -73,16 +68,21 @@ for graphindex in range(len(self.graphs)): self.block_starters[graphindex] = {0: True} for graphindex, graph in enumerate(self.graphs): -last_was_mergepoint = False +mergepointblock = None for i, op in enumerate(graph.get_operations()): if is_interesting_guard(op): self.mark_starter(graphindex, i+1) if op.getopnum() == rop.DEBUG_MERGE_POINT: -if not last_was_mergepoint: -last_was_mergepoint = True -self.mark_starter(graphindex, i) +if mergepointblock is None: +mergepointblock = i +elif op.getopnum() == rop.LABEL: +self.mark_starter(graphindex, i) +self.target_tokens[op.getdescr()] = (graphindex, i) +mergepointblock = i
[pypy-commit] pypy jit-targets: traces from interpreter now working again
Author: Hakan Ardo Branch: jit-targets Changeset: r48828:82923819cf55 Date: 2011-11-06 16:22 +0100 http://bitbucket.org/pypy/pypy/changeset/82923819cf55/ Log:traces from interpreter now working again diff --git a/pypy/jit/backend/llgraph/runner.py b/pypy/jit/backend/llgraph/runner.py --- a/pypy/jit/backend/llgraph/runner.py +++ b/pypy/jit/backend/llgraph/runner.py @@ -140,17 +140,17 @@ old, oldindex = faildescr._compiled_fail llimpl.compile_redirect_fail(old, oldindex, c) -def compile_loop(self, inputargs, operations, looptoken, log=True, name=''): +def compile_loop(self, inputargs, operations, jitcell_token, log=True, name=''): """In a real assembler backend, this should assemble the given list of operations. Here we just generate a similar CompiledLoop instance. The code here is RPython, whereas the code in llimpl is not. """ c = llimpl.compile_start() -clt = model.CompiledLoopToken(self, looptoken.number) +clt = model.CompiledLoopToken(self, jitcell_token.number) clt.loop_and_bridges = [c] clt.compiled_version = c -looptoken.compiled_loop_token = clt +jitcell_token.compiled_loop_token = clt self._compile_loop_or_bridge(c, inputargs, operations) def free_loop_and_bridges(self, compiled_loop_token): @@ -180,7 +180,7 @@ if isinstance(descr, Descr): llimpl.compile_add_descr(c, descr.ofs, descr.typeinfo, descr.arg_types) -if isinstance(descr, history.ProcedureToken): +if isinstance(descr, history.JitCellToken): assert False if op.getopnum() != rop.JUMP: llimpl.compile_add_loop_token(c, descr) diff --git a/pypy/jit/metainterp/compile.py b/pypy/jit/metainterp/compile.py --- a/pypy/jit/metainterp/compile.py +++ b/pypy/jit/metainterp/compile.py @@ -47,37 +47,39 @@ return loop -def make_procedure_token(jitdriver_sd): -procedure_token = JitCellToken() -procedure_token.outermost_jitdriver_sd = jitdriver_sd -return procedure_token +def make_jitcell_token(jitdriver_sd): +jitcell_token = JitCellToken() +jitcell_token.outermost_jitdriver_sd = jitdriver_sd +return jitcell_token def record_loop_or_bridge(metainterp_sd, loop): """Do post-backend recordings and cleanups on 'loop'. """ -# get the original loop token (corresponding to 'loop', or if that is -# a bridge, to the loop that this bridge belongs to) -looptoken = loop.token -assert looptoken is not None +# get the original jitcell token corresponding to jitcell form which +# this trace starts +original_jitcell_token = loop.original_jitcell_token +assert original_jitcell_token is not None if metainterp_sd.warmrunnerdesc is not None:# for tests -assert looptoken.generation > 0 # has been registered with memmgr -wref = weakref.ref(looptoken) +assert original_jitcell_token.generation > 0 # has been registered with memmgr +wref = weakref.ref(original_jitcell_token) for op in loop.operations: descr = op.getdescr() if isinstance(descr, ResumeDescr): descr.wref_original_loop_token = wref # stick it there n = descr.index if n >= 0: # we also record the resumedescr number -looptoken.compiled_loop_token.record_faildescr_index(n) + original_jitcell_token.compiled_loop_token.record_faildescr_index(n) elif isinstance(descr, JitCellToken): +# for a CALL_ASSEMBLER ... assert False, "FIXME" elif isinstance(descr, TargetToken): -# for a JUMP or a CALL_ASSEMBLER: record it as a potential jump. +# for a JUMP: record it as a potential jump. # (the following test is not enough to prevent more complicated # cases of cycles, but at least it helps in simple tests of # test_memgr.py) -if descr.procedure_token is not looptoken: -looptoken.record_jump_to(descr.procedure_token) +if descr.original_jitcell_token is not original_jitcell_token: +assert descr.original_jitcell_token is not None + original_jitcell_token.record_jump_to(descr.original_jitcell_token) op._descr = None# clear reference, mostly for tests # record this looptoken on the QuasiImmut used in the code if loop.quasi_immutable_deps is not None: @@ -85,9 +87,9 @@ qmut.register_loop_token(wref) # XXX maybe we should clear the dictionary here # mostly for tests: make sure we don't keep a reference to the LoopToken -loop.token = None +loop.original_jitcell_token = None if not we_are_translated(): -loop._looptoken_number = looptoken.number +loop._looptoken_n
[pypy-commit] pypy jit-targets: test_loop_1 passing
Author: Hakan Ardo Branch: jit-targets Changeset: r48831:b262b6ae31dd Date: 2011-11-06 16:39 +0100 http://bitbucket.org/pypy/pypy/changeset/b262b6ae31dd/ Log:test_loop_1 passing diff --git a/pypy/jit/backend/llgraph/llimpl.py b/pypy/jit/backend/llgraph/llimpl.py --- a/pypy/jit/backend/llgraph/llimpl.py +++ b/pypy/jit/backend/llgraph/llimpl.py @@ -391,7 +391,7 @@ def compile_add_jump_target(loop, targettoken): loop = _from_opaque(loop) -if isinstance(targettoken, history.ProcedureToken): +if isinstance(targettoken, history.JitCellToken): assert False loop_target = _from_opaque(targettoken.compiled_loop_token.compiled_version) target_opindex = 0 diff --git a/pypy/jit/metainterp/compile.py b/pypy/jit/metainterp/compile.py --- a/pypy/jit/metainterp/compile.py +++ b/pypy/jit/metainterp/compile.py @@ -107,18 +107,19 @@ if partial_trace: part = partial_trace -procedure_token = metainterp.get_procedure_token(greenkey) +assert False +procedur_token = metainterp.get_procedure_token(greenkey) assert procedure_token all_target_tokens = [] else: -procedure_token = make_procedure_token(jitdriver_sd) +jitcell_token = make_jitcell_token(jitdriver_sd) part = create_empty_loop(metainterp) part.inputargs = inputargs[:] h_ops = history.operations part.start_resumedescr = start_resumedescr -part.operations = [ResOperation(rop.LABEL, inputargs, None, descr=TargetToken(procedure_token))] + \ +part.operations = [ResOperation(rop.LABEL, inputargs, None, descr=TargetToken(jitcell_token))] + \ [h_ops[i].clone() for i in range(start, len(h_ops))] + \ - [ResOperation(rop.LABEL, jumpargs, None, descr=TargetToken(procedure_token))] + [ResOperation(rop.JUMP, jumpargs, None, descr=jitcell_token)] try: optimize_trace(metainterp_sd, part, jitdriver_sd.warmstate.enable_opts) except InvalidLoop: @@ -132,8 +133,8 @@ inliner = Inliner(inputargs, jumpargs) part.operations = [part.operations[-1]] + \ [inliner.inline_op(h_ops[i]) for i in range(start, len(h_ops))] + \ - [ResOperation(rop.LABEL, [inliner.inline_arg(a) for a in jumpargs], -None, descr=TargetToken(procedure_token))] + [ResOperation(rop.JUMP, [inliner.inline_arg(a) for a in jumpargs], +None, descr=jitcell_token)] all_target_tokens.append(part.operations[0].getdescr()) inputargs = jumpargs jumpargs = part.operations[-1].getarglist() @@ -148,11 +149,13 @@ for box in loop.inputargs: assert isinstance(box, Box) -loop.token = procedure_token -procedure_token.target_tokens = all_target_tokens +loop.original_jitcell_token = jitcell_token +for label in all_target_tokens: +label.original_jitcell_token = jitcell_token +jitcell_token.target_tokens = all_target_tokens send_loop_to_backend(greenkey, jitdriver_sd, metainterp_sd, loop, "loop") record_loop_or_bridge(metainterp_sd, loop) -return procedure_token +return jitcell_token if False: # FIXME: full_preamble_needed?? ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: retrace support
Author: Hakan Ardo Branch: jit-targets Changeset: r48833:d04c6e6f5e44 Date: 2011-11-06 18:25 +0100 http://bitbucket.org/pypy/pypy/changeset/d04c6e6f5e44/ Log:retrace support diff --git a/pypy/jit/metainterp/compile.py b/pypy/jit/metainterp/compile.py --- a/pypy/jit/metainterp/compile.py +++ b/pypy/jit/metainterp/compile.py @@ -93,9 +93,9 @@ # -def compile_procedure(metainterp, greenkey, start, +def compile_loop(metainterp, greenkey, start, inputargs, jumpargs, - start_resumedescr, full_preamble_needed=True, partial_trace=None): + start_resumedescr, full_preamble_needed=True): """Try to compile a new procedure by closing the current history back to the first operation. """ @@ -105,7 +105,7 @@ metainterp_sd = metainterp.staticdata jitdriver_sd = metainterp.jitdriver_sd -if partial_trace: +if False: part = partial_trace assert False procedur_token = metainterp.get_procedure_token(greenkey) @@ -155,7 +155,7 @@ jitcell_token.target_tokens = all_target_tokens send_loop_to_backend(greenkey, jitdriver_sd, metainterp_sd, loop, "loop") record_loop_or_bridge(metainterp_sd, loop) -return jitcell_token +return all_target_tokens[0] if False: # FIXME: full_preamble_needed?? @@ -180,6 +180,53 @@ record_loop_or_bridge(metainterp_sd, loop) return loop_token +def compile_retrace(metainterp, greenkey, start, +inputargs, jumpargs, +start_resumedescr, partial_trace, resumekey): +"""Try to compile a new procedure by closing the current history back +to the first operation. +""" +from pypy.jit.metainterp.optimizeopt import optimize_trace + +history = metainterp.history +metainterp_sd = metainterp.staticdata +jitdriver_sd = metainterp.jitdriver_sd + +loop_jitcell_token = metainterp.get_procedure_token(greenkey) +assert loop_jitcell_token +assert partial_trace.operations[-1].getopnum() == rop.LABEL + +part = create_empty_loop(metainterp) +part.inputargs = inputargs[:] +part.start_resumedescr = start_resumedescr +h_ops = history.operations +part.operations = [partial_trace.operations[-1]] + \ + [h_ops[i].clone() for i in range(start, len(h_ops))] + \ + [ResOperation(rop.JUMP, jumpargs, None, descr=loop_jitcell_token)] +try: +optimize_trace(metainterp_sd, part, jitdriver_sd.warmstate.enable_opts) +except InvalidLoop: +return None +assert part.operations[-1].getopnum() != rop.LABEL +label = part.operations[0] +assert label.getopnum() == rop.LABEL +target_token = label.getdescr() +assert isinstance(target_token, TargetToken) +assert loop_jitcell_token.target_tokens +loop_jitcell_token.target_tokens.append(target_token) + +loop = partial_trace +loop.operations = loop.operations[:-1] + part.operations + +for box in loop.inputargs: +assert isinstance(box, Box) + +target_token = loop.operations[-1].getdescr() +resumekey.compile_and_attach(metainterp, loop) +label.getdescr().original_jitcell_token = loop.original_jitcell_token +record_loop_or_bridge(metainterp_sd, loop) +return target_token + def insert_loop_token(old_loop_tokens, loop_token): # Find where in old_loop_tokens we should insert this new loop_token. # The following algo means "as late as possible, but before another diff --git a/pypy/jit/metainterp/history.py b/pypy/jit/metainterp/history.py --- a/pypy/jit/metainterp/history.py +++ b/pypy/jit/metainterp/history.py @@ -778,6 +778,7 @@ call_pure_results = None logops = None quasi_immutable_deps = None +start_resumedescr = None def _token(*args): raise Exception("TreeLoop.token is killed") diff --git a/pypy/jit/metainterp/optimizeopt/unroll.py b/pypy/jit/metainterp/optimizeopt/unroll.py --- a/pypy/jit/metainterp/optimizeopt/unroll.py +++ b/pypy/jit/metainterp/optimizeopt/unroll.py @@ -116,9 +116,12 @@ jump_args = [self.getvalue(a).get_key_box() for a in original_jump_args] # FIXME: I dont thnik we need this anymore -start_resumedescr = self.optimizer.loop.start_resumedescr.clone_if_mutable() -assert isinstance(start_resumedescr, ResumeGuardDescr) -start_resumedescr.rd_snapshot = self.fix_snapshot(jump_args, start_resumedescr.rd_snapshot) +if self.optimizer.loop.start_resumedescr: +start_resumedescr = self.optimizer.loop.start_resumedescr.clone_if_mutable() +assert isinstance(start_resumedescr, ResumeGuardDescr) +start_resumedescr.rd_snapshot = self.fix_snapshot(jump_args, start_resumedescr.rd_snapshot) +else: +start_resumedescr = None modifier = VirtualStateAdder(self.optimizer)
[pypy-commit] pypy jit-targets: bridge support
Author: Hakan Ardo Branch: jit-targets Changeset: r48832:9b87dd5eeb7f Date: 2011-11-06 17:05 +0100 http://bitbucket.org/pypy/pypy/changeset/9b87dd5eeb7f/ Log:bridge support diff --git a/pypy/jit/metainterp/compile.py b/pypy/jit/metainterp/compile.py --- a/pypy/jit/metainterp/compile.py +++ b/pypy/jit/metainterp/compile.py @@ -426,13 +426,13 @@ # We managed to create a bridge. Attach the new operations # to the corresponding guard_op and compile from there assert metainterp.resumekey_original_loop_token is not None -new_loop.token = metainterp.resumekey_original_loop_token +new_loop.original_jitcell_token = metainterp.resumekey_original_loop_token inputargs = metainterp.history.inputargs if not we_are_translated(): self._debug_suboperations = new_loop.operations send_bridge_to_backend(metainterp.jitdriver_sd, metainterp.staticdata, self, inputargs, new_loop.operations, - new_loop.token) + new_loop.original_jitcell_token) def copy_all_attributes_into(self, res): # XXX a bit ugly to have to list them all here diff --git a/pypy/jit/metainterp/optimizeopt/unroll.py b/pypy/jit/metainterp/optimizeopt/unroll.py --- a/pypy/jit/metainterp/optimizeopt/unroll.py +++ b/pypy/jit/metainterp/optimizeopt/unroll.py @@ -442,7 +442,7 @@ debug_start('jit-log-virtualstate') virtual_state.debug_print("Looking for ") -for target in procedure_token.target_tokens: +for target in cell_token.target_tokens: if not target.virtual_state: continue ok = False @@ -481,24 +481,24 @@ descr = target.start_resumedescr.clone_if_mutable() inliner.inline_descr_inplace(descr) guard.setdescr(descr) -self.emit_operation(guard) +self.optimizer.send_extra_operation(guard) try: for shop in target.short_preamble[1:]: newop = inliner.inline_op(shop) -self.emit_operation(newop) +self.optimizer.send_extra_operation(newop) except InvalidLoop: debug_print("Inlining failed unexpectedly", "jumping to preamble instead") assert False, "FIXME: Construct jump op" -self.emit_operation(op) +self.optimizer.send_extra_operation(op) return True debug_stop('jit-log-virtualstate') -retraced_count = procedure_token.retraced_count +retraced_count = cell_token.retraced_count limit = self.optimizer.metainterp_sd.warmrunnerdesc.memory_manager.retrace_limit if not self.retraced and retraced_counthttp://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: fix tests
Author: Hakan Ardo Branch: jit-targets Changeset: r48834:123a7a37c565 Date: 2011-11-06 18:54 +0100 http://bitbucket.org/pypy/pypy/changeset/123a7a37c565/ Log:fix tests diff --git a/pypy/jit/metainterp/test/support.py b/pypy/jit/metainterp/test/support.py --- a/pypy/jit/metainterp/test/support.py +++ b/pypy/jit/metainterp/test/support.py @@ -228,7 +228,7 @@ # this can be used after interp_operations if expected is not None: expected = dict(expected) -expected['jump'] = 1 +expected['finish'] = 1 self.metainterp.staticdata.stats.check_history(expected, **isns) diff --git a/pypy/jit/metainterp/test/test_ajit.py b/pypy/jit/metainterp/test/test_ajit.py --- a/pypy/jit/metainterp/test/test_ajit.py +++ b/pypy/jit/metainterp/test/test_ajit.py @@ -195,7 +195,7 @@ assert res == 1167 self.check_loop_count(3) self.check_resops({'int_lt': 3, 'int_gt': 2, 'int_add': 5, - 'guard_true': 3, 'int_sub': 4, 'jump': 4, + 'guard_true': 3, 'int_sub': 4, 'jump': 2, 'int_mul': 2, 'guard_false': 2}) def test_loop_invariant_mul_bridge_maintaining2(self): @@ -215,7 +215,7 @@ assert res == 1692 self.check_loop_count(3) self.check_resops({'int_lt': 3, 'int_gt': 2, 'int_add': 5, - 'guard_true': 3, 'int_sub': 4, 'jump': 4, + 'guard_true': 3, 'int_sub': 4, 'jump': 2, 'int_mul': 2, 'guard_false': 2}) def test_loop_invariant_mul_bridge_maintaining3(self): @@ -257,7 +257,7 @@ res = self.meta_interp(f, [6, 7]) assert res == 252 self.check_loop_count(1) -self.check_resops({'jump': 2, 'int_gt': 2, 'int_add': 2, +self.check_resops({'jump': 1, 'int_gt': 2, 'int_add': 2, 'getfield_gc_pure': 1, 'int_mul': 1, 'guard_true': 2, 'int_sub': 2}) @@ -861,7 +861,7 @@ res = self.meta_interp(f, [6, 7]) assert res == 42.0 self.check_loop_count(1) -self.check_resops({'jump': 2, 'float_gt': 2, 'float_add': 2, +self.check_resops({'jump': 1, 'float_gt': 2, 'float_add': 2, 'float_sub': 2, 'guard_true': 2}) def test_print(self): ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-refactor-tests: converted tests
Author: Hakan Ardo Branch: jit-refactor-tests Changeset: r48835:c16efa936b3b Date: 2011-11-06 20:57 +0100 http://bitbucket.org/pypy/pypy/changeset/c16efa936b3b/ Log:converted tests diff --git a/pypy/jit/metainterp/test/test_loop.py b/pypy/jit/metainterp/test/test_loop.py --- a/pypy/jit/metainterp/test/test_loop.py +++ b/pypy/jit/metainterp/test/test_loop.py @@ -60,7 +60,8 @@ assert res == f(6, 13) self.check_loop_count(1) if self.enable_opts: -self.check_loops(getfield_gc = 0, setfield_gc = 1) +self.check_resops(setfield_gc=2, getfield_gc=0) + def test_loop_with_two_paths(self): from pypy.rpython.lltypesystem import lltype @@ -180,7 +181,10 @@ assert res == 42 self.check_loop_count(1) # the 'int_eq' and following 'guard' should be constant-folded -self.check_loops(int_eq=0, guard_true=1, guard_false=0) +if 'unroll' in self.enable_opts: +self.check_resops(int_eq=0, guard_true=2, guard_false=0) +else: +self.check_resops(int_eq=0, guard_true=1, guard_false=0) if self.basic: found = 0 for op in get_stats().loops[0]._all_operations(): @@ -643,8 +647,12 @@ res = self.meta_interp(main_interpreter_loop, [1]) assert res == 102 self.check_loop_count(1) -self.check_loops({'int_add' : 3, 'int_gt' : 1, - 'guard_false' : 1, 'jump' : 1}) +if 'unroll' in self.enable_opts: +self.check_resops({'int_add' : 6, 'int_gt' : 2, + 'guard_false' : 2, 'jump' : 2}) +else: +self.check_resops({'int_add' : 3, 'int_gt' : 1, + 'guard_false' : 1, 'jump' : 1}) def test_automatic_promotion(self): myjitdriver = JitDriver(greens = ['i'], @@ -686,7 +694,7 @@ self.check_loop_count(1) # These loops do different numbers of ops based on which optimizer we # are testing with. -self.check_loops(self.automatic_promotion_result) +self.check_resops(self.automatic_promotion_result) def test_can_enter_jit_outside_main_loop(self): myjitdriver = JitDriver(greens=[], reds=['i', 'j', 'a']) diff --git a/pypy/jit/metainterp/test/test_loop_unroll.py b/pypy/jit/metainterp/test/test_loop_unroll.py --- a/pypy/jit/metainterp/test/test_loop_unroll.py +++ b/pypy/jit/metainterp/test/test_loop_unroll.py @@ -8,7 +8,8 @@ enable_opts = ALL_OPTS_NAMES automatic_promotion_result = { -'int_add' : 3, 'int_gt' : 1, 'guard_false' : 1, 'jump' : 1, +'int_gt': 2, 'guard_false': 2, 'jump': 2, 'int_add': 6, +'guard_value': 1 } # > test_loop.py diff --git a/pypy/jit/metainterp/test/test_recursive.py b/pypy/jit/metainterp/test/test_recursive.py --- a/pypy/jit/metainterp/test/test_recursive.py +++ b/pypy/jit/metainterp/test/test_recursive.py @@ -143,11 +143,11 @@ f = self.get_interpreter(codes) assert self.meta_interp(f, [0, 0, 0], enable_opts='') == 42 -self.check_loops(int_add = 1, call_may_force = 1, call = 0) +self.check_resops(call_may_force=1, int_add=1, call=0) assert self.meta_interp(f, [0, 0, 0], enable_opts='', inline=True) == 42 -self.check_loops(int_add = 2, call_may_force = 0, call = 0, - guard_no_exception = 0) +self.check_resops(call=0, int_add=2, call_may_force=0, + guard_no_exception=0) def test_inline_jitdriver_check(self): code = "021" @@ -160,7 +160,7 @@ inline=True) == 42 # the call is fully inlined, because we jump to subcode[1], thus # skipping completely the JUMP_BACK in subcode[0] -self.check_loops(call_may_force = 0, call_assembler = 0, call = 0) +self.check_resops(call=0, call_may_force=0, call_assembler=0) def test_guard_failure_in_inlined_function(self): def p(pc, code): @@ -491,10 +491,10 @@ return loop(100) res = self.meta_interp(main, [0], enable_opts='', trace_limit=TRACE_LIMIT) -self.check_loops(call_may_force=1, call=0) +self.check_resops(call=0, call_may_force=1) res = self.meta_interp(main, [1], enable_opts='', trace_limit=TRACE_LIMIT) -self.check_loops(call_may_force=0, call=0) +self.check_resops(call=0, call_may_force=0) def test_trace_from_start(self): def p(pc, code): @@ -576,7 +576,7 @@ result += f('-c---l-', i+100) self.meta_interp(g, [10], backendopt=True) self.check_aborted_count(1) -self.check_loops(call_assembler=1, call=0) +self.check_resops(call=0, call_assembler=2) self.check_tree_loop_count(3) def test_directly_call_assembler(self): @@ -625,8 +625,7 @@
[pypy-commit] pypy jit-targets: kill optimizer.bridge
Author: Hakan Ardo Branch: jit-targets Changeset: r48860:27048a266352 Date: 2011-11-07 11:19 +0100 http://bitbucket.org/pypy/pypy/changeset/27048a266352/ Log:kill optimizer.bridge diff --git a/pypy/jit/metainterp/optimizeopt/__init__.py b/pypy/jit/metainterp/optimizeopt/__init__.py --- a/pypy/jit/metainterp/optimizeopt/__init__.py +++ b/pypy/jit/metainterp/optimizeopt/__init__.py @@ -89,5 +89,5 @@ if unroll: optimize_unroll(metainterp_sd, loop, optimizations) else: -optimizer = Optimizer(metainterp_sd, loop, optimizations, bridge) +optimizer = Optimizer(metainterp_sd, loop, optimizations) optimizer.propagate_all_forward() diff --git a/pypy/jit/metainterp/optimizeopt/optimizer.py b/pypy/jit/metainterp/optimizeopt/optimizer.py --- a/pypy/jit/metainterp/optimizeopt/optimizer.py +++ b/pypy/jit/metainterp/optimizeopt/optimizer.py @@ -329,11 +329,10 @@ class Optimizer(Optimization): -def __init__(self, metainterp_sd, loop, optimizations=None, bridge=False): +def __init__(self, metainterp_sd, loop, optimizations=None): self.metainterp_sd = metainterp_sd self.cpu = metainterp_sd.cpu self.loop = loop -self.bridge = bridge self.values = {} self.interned_refs = self.cpu.ts.new_ref_dict() self.interned_ints = {} @@ -497,7 +496,7 @@ return CVAL_ZERO def propagate_all_forward(self, clear=True): -self.exception_might_have_happened = self.bridge +self.exception_might_have_happened = True if clear: self.clear_newoperations() for op in self.loop.operations: ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: ensure loops are freed
Author: Hakan Ardo Branch: jit-targets Changeset: r48859:712c04e8e94d Date: 2011-11-07 11:09 +0100 http://bitbucket.org/pypy/pypy/changeset/712c04e8e94d/ Log:ensure loops are freed diff --git a/pypy/jit/metainterp/compile.py b/pypy/jit/metainterp/compile.py --- a/pypy/jit/metainterp/compile.py +++ b/pypy/jit/metainterp/compile.py @@ -80,6 +80,7 @@ if descr.original_jitcell_token is not original_jitcell_token: assert descr.original_jitcell_token is not None original_jitcell_token.record_jump_to(descr.original_jitcell_token) +descr.exported_state = None op._descr = None# clear reference, mostly for tests # record this looptoken on the QuasiImmut used in the code if loop.quasi_immutable_deps is not None: @@ -673,7 +674,7 @@ pass -def compile_trace(metainterp, resumekey, retraced=False): +def compile_trace(metainterp, resumekey, start_resumedescr=None): """Try to compile a new bridge leading from the beginning of the history to some existing place. """ @@ -689,6 +690,7 @@ # clone ops, as optimize_bridge can mutate the ops new_trace.operations = [op.clone() for op in metainterp.history.operations] +new_trace.start_resumedescr = start_resumedescr metainterp_sd = metainterp.staticdata state = metainterp.jitdriver_sd.warmstate if isinstance(resumekey, ResumeAtPositionDescr): diff --git a/pypy/jit/metainterp/optimizeopt/unroll.py b/pypy/jit/metainterp/optimizeopt/unroll.py --- a/pypy/jit/metainterp/optimizeopt/unroll.py +++ b/pypy/jit/metainterp/optimizeopt/unroll.py @@ -115,13 +115,11 @@ original_jump_args = targetop.getarglist() jump_args = [self.getvalue(a).get_key_box() for a in original_jump_args] -# FIXME: I dont thnik we need this anymore -if self.optimizer.loop.start_resumedescr: -start_resumedescr = self.optimizer.loop.start_resumedescr.clone_if_mutable() -assert isinstance(start_resumedescr, ResumeGuardDescr) -start_resumedescr.rd_snapshot = self.fix_snapshot(jump_args, start_resumedescr.rd_snapshot) -else: -start_resumedescr = None +assert self.optimizer.loop.start_resumedescr +start_resumedescr = self.optimizer.loop.start_resumedescr.clone_if_mutable() +assert isinstance(start_resumedescr, ResumeGuardDescr) +start_resumedescr.rd_snapshot = self.fix_snapshot(jump_args, start_resumedescr.rd_snapshot) +# FIXME: I dont thnik we need fix_snapshot anymore modifier = VirtualStateAdder(self.optimizer) virtual_state = modifier.get_virtual_state(jump_args) @@ -180,8 +178,7 @@ self.imported_state = exported_state self.inputargs = targetop.getarglist() self.initial_virtual_state = target_token.virtual_state -#self.start_resumedescr = target_token.start_resumedescr -self.start_resumedescr = self.optimizer.loop.start_resumedescr +self.start_resumedescr = target_token.start_resumedescr seen = {} for box in self.inputargs: @@ -328,14 +325,7 @@ for i in range(len(short)): short[i] = inliner.inline_op(short[i]) -if target_token.start_resumedescr is None: # FIXME: Hack! -target_token.start_resumedescr = self.start_resumedescr.clone_if_mutable() -fix = Inliner(self.optimizer.loop.operations[-1].getarglist(), - self.optimizer.loop.inputargs) - -fix.inline_descr_inplace(target_token.start_resumedescr) -else: -target_token.start_resumedescr = self.start_resumedescr.clone_if_mutable() +target_token.start_resumedescr = self.start_resumedescr.clone_if_mutable() inliner.inline_descr_inplace(target_token.start_resumedescr) # Forget the values to allow them to be freed diff --git a/pypy/jit/metainterp/pyjitpl.py b/pypy/jit/metainterp/pyjitpl.py --- a/pypy/jit/metainterp/pyjitpl.py +++ b/pypy/jit/metainterp/pyjitpl.py @@ -1936,7 +1936,7 @@ # from the interpreter. if not self.partial_trace: # FIXME: Support a retrace to be a bridge as well as a loop -self.compile_trace(live_arg_boxes) +self.compile_trace(live_arg_boxes, resumedescr) # raises in case it works -- which is the common case, hopefully, # at least for bridges starting from a guard. @@ -2042,7 +2042,7 @@ self.history.operations = None raise GenerateMergePoint(live_arg_boxes, target_token.cell_token) -def compile_trace(self, live_arg_boxes): +def compile_trace(self, live_arg_boxes, start_resumedescr): num_green_args = self.jitdriver_sd.num_green_args greenkey = live_arg_boxes[:num_green_args] target_jitcell_token = self.get_procedure_token(greenkey) @@ -2052,7 +2052,7 @@
[pypy-commit] pypy jit-targets: rename TargetToken.cell_token into TargetToke.targeting_jitcell_token
Author: Hakan Ardo Branch: jit-targets Changeset: r48861:963c63e3066e Date: 2011-11-07 11:27 +0100 http://bitbucket.org/pypy/pypy/changeset/963c63e3066e/ Log:rename TargetToken.cell_token into TargetToke.targeting_jitcell_token diff --git a/pypy/jit/metainterp/history.py b/pypy/jit/metainterp/history.py --- a/pypy/jit/metainterp/history.py +++ b/pypy/jit/metainterp/history.py @@ -766,11 +766,15 @@ self.compiled_loop_token.cpu.dump_loop_token(self) class TargetToken(AbstractDescr): -def __init__(self, cell_token): -self.cell_token = cell_token +def __init__(self, targeting_jitcell_token): +# The jitcell to which jumps might result in a jump to this label +self.targeting_jitcell_token = targeting_jitcell_token + +# The jitcell where the trace containing the label with this TargetToken begins +self.original_jitcell_token = None + self.virtual_state = None self.exported_state = None -self.original_jitcell_token = None class TreeLoop(object): inputargs = None diff --git a/pypy/jit/metainterp/optimizeopt/unroll.py b/pypy/jit/metainterp/optimizeopt/unroll.py --- a/pypy/jit/metainterp/optimizeopt/unroll.py +++ b/pypy/jit/metainterp/optimizeopt/unroll.py @@ -104,7 +104,7 @@ self.export_state(stop_label) loop.operations.append(stop_label) else: -assert stop_label.getdescr().cell_token is start_label.getdescr().cell_token +assert stop_label.getdescr().targeting_jitcell_token is start_label.getdescr().targeting_jitcell_token jumpop = ResOperation(rop.JUMP, stop_label.getarglist(), None, descr=start_label.getdescr()) self.close_loop(jumpop) diff --git a/pypy/jit/metainterp/pyjitpl.py b/pypy/jit/metainterp/pyjitpl.py --- a/pypy/jit/metainterp/pyjitpl.py +++ b/pypy/jit/metainterp/pyjitpl.py @@ -2037,10 +2037,10 @@ live_arg_boxes[num_green_args:], start_resumedescr) if target_token is not None: # raise if it *worked* correctly -self.jitdriver_sd.warmstate.attach_procedure_to_interp(greenkey, target_token.cell_token) +self.jitdriver_sd.warmstate.attach_procedure_to_interp(greenkey, target_token.targeting_jitcell_token) self.history.inputargs = None self.history.operations = None -raise GenerateMergePoint(live_arg_boxes, target_token.cell_token) +raise GenerateMergePoint(live_arg_boxes, target_token.targeting_jitcell_token) def compile_trace(self, live_arg_boxes, start_resumedescr): num_green_args = self.jitdriver_sd.num_green_args @@ -2058,7 +2058,7 @@ if target_token is not None: # raise if it *worked* correctly self.history.inputargs = None self.history.operations = None -raise GenerateMergePoint(live_arg_boxes, target_token.cell_token) +raise GenerateMergePoint(live_arg_boxes, target_token.targeting_jitcell_token) def compile_bridge_and_loop(self, original_boxes, live_arg_boxes, start, bridge_arg_boxes, start_resumedescr): ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: make OptSimplify follow and test_optimizebasic follow the new model
Author: Hakan Ardo Branch: jit-targets Changeset: r48862:aa5ecf2901be Date: 2011-11-07 12:48 +0100 http://bitbucket.org/pypy/pypy/changeset/aa5ecf2901be/ Log:make OptSimplify follow and test_optimizebasic follow the new model diff --git a/pypy/jit/metainterp/optimizeopt/__init__.py b/pypy/jit/metainterp/optimizeopt/__init__.py --- a/pypy/jit/metainterp/optimizeopt/__init__.py +++ b/pypy/jit/metainterp/optimizeopt/__init__.py @@ -45,7 +45,7 @@ optimizations.append(OptFfiCall()) if ('rewrite' not in enable_opts or 'virtualize' not in enable_opts -or 'heap' not in enable_opts): +or 'heap' not in enable_opts or 'unroll' not in enable_opts): optimizations.append(OptSimplify()) if inline_short_preamble: diff --git a/pypy/jit/metainterp/optimizeopt/simplify.py b/pypy/jit/metainterp/optimizeopt/simplify.py --- a/pypy/jit/metainterp/optimizeopt/simplify.py +++ b/pypy/jit/metainterp/optimizeopt/simplify.py @@ -1,9 +1,12 @@ from pypy.jit.metainterp.optimizeopt.optimizer import Optimization from pypy.jit.metainterp.optimizeopt.util import make_dispatcher_method from pypy.jit.metainterp.resoperation import ResOperation, rop - +from pypy.jit.metainterp.history import TargetToken, JitCellToken class OptSimplify(Optimization): +def __init__(self): +self.last_label_descr = None + def optimize_CALL_PURE(self, op): args = op.getarglist() self.emit_operation(ResOperation(rop.CALL, args, op.result, @@ -28,6 +31,20 @@ def optimize_MARK_OPAQUE_PTR(self, op): pass +def optimize_LABEL(self, op): +self.last_label_descr = op.getdescr() +self.emit_operation(op) + +def optimize_JUMP(self, op): +descr = op.getdescr() +assert isinstance(descr, JitCellToken) +if not descr.target_tokens: +assert self.last_label_descr is not None +assert self.last_label_descr.targeting_jitcell_token is descr +op.setdescr(self.last_label_descr) +else: +import pdb; pdb.set_trace() +self.emit_operation(op) dispatch_opt = make_dispatcher_method(OptSimplify, 'optimize_', default=OptSimplify.emit_operation) diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py b/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py --- a/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py +++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py @@ -1,7 +1,8 @@ import py from pypy.rlib.objectmodel import instantiate from pypy.jit.metainterp.optimizeopt.test.test_util import ( -LLtypeMixin, BaseTest, FakeMetaInterpStaticData) +LLtypeMixin, BaseTest, FakeMetaInterpStaticData, convert_old_style_to_targets) +from pypy.jit.metainterp.history import TargetToken, JitCellToken from pypy.jit.metainterp.test.test_compile import FakeLogger import pypy.jit.metainterp.optimizeopt.optimizer as optimizeopt import pypy.jit.metainterp.optimizeopt.virtualize as virtualize @@ -11,7 +12,6 @@ from pypy.jit.metainterp.resoperation import rop, opname, ResOperation from pypy.rlib.rarithmetic import LONG_BIT - def test_store_final_boxes_in_guard(): from pypy.jit.metainterp.compile import ResumeGuardDescr from pypy.jit.metainterp.resume import tag, TAGBOX @@ -116,9 +116,13 @@ enable_opts = "intbounds:rewrite:virtualize:string:earlyforce:pure:heap" def optimize_loop(self, ops, optops, call_pure_results=None): - loop = self.parse(ops) -expected = self.parse(optops) +token = JitCellToken() +loop.operations = [ResOperation(rop.LABEL, loop.inputargs, None, descr=TargetToken(token))] + \ + loop.operations +if loop.operations[-1].getopnum() == rop.JUMP: +loop.operations[-1].setdescr(token) +expected = convert_old_style_to_targets(self.parse(optops), jump=True) self._do_optimize_loop(loop, call_pure_results) print '\n'.join([str(o) for o in loop.operations]) self.assert_equal(loop, expected) diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py --- a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py +++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py @@ -1,7 +1,7 @@ import py from pypy.rlib.objectmodel import instantiate from pypy.jit.metainterp.optimizeopt.test.test_util import ( -LLtypeMixin, BaseTest, Storage, _sortboxes) +LLtypeMixin, BaseTest, Storage, _sortboxes, convert_old_style_to_targets) import pypy.jit.metainterp.optimizeopt.optimizer as optimizeopt import pypy.jit.metainterp.optimizeopt.virtualize as virtualize from pypy.jit.metainterp.optimizeopt import optimize_loop_1, ALL_OPTS_DICT, build_opt_chain @@ -158,16 +158,6 @@ return loop -def convert_old_style_to_targets(loop, jump): -newloop = TreeLoop(loop.name) -newloop.inpu
[pypy-commit] pypy jit-targets: dont replace the the JitCellToken when retracing
Author: Hakan Ardo Branch: jit-targets Changeset: r48867:aa8ad4543ac2 Date: 2011-11-07 13:49 +0100 http://bitbucket.org/pypy/pypy/changeset/aa8ad4543ac2/ Log:dont replace the the JitCellToken when retracing diff --git a/pypy/jit/metainterp/optimizeopt/simplify.py b/pypy/jit/metainterp/optimizeopt/simplify.py --- a/pypy/jit/metainterp/optimizeopt/simplify.py +++ b/pypy/jit/metainterp/optimizeopt/simplify.py @@ -43,7 +43,8 @@ assert self.last_label_descr.targeting_jitcell_token is descr op.setdescr(self.last_label_descr) else: -import pdb; pdb.set_trace() +assert len(descr.target_tokens) == 1 +op.setdescr(descr.target_tokens[0]) self.emit_operation(op) dispatch_opt = make_dispatcher_method(OptSimplify, 'optimize_', diff --git a/pypy/jit/metainterp/pyjitpl.py b/pypy/jit/metainterp/pyjitpl.py --- a/pypy/jit/metainterp/pyjitpl.py +++ b/pypy/jit/metainterp/pyjitpl.py @@ -2036,8 +2036,10 @@ original_boxes[num_green_args:], live_arg_boxes[num_green_args:], start_resumedescr) +if target_token is not None: + self.jitdriver_sd.warmstate.attach_procedure_to_interp(greenkey, target_token.targeting_jitcell_token) + if target_token is not None: # raise if it *worked* correctly -self.jitdriver_sd.warmstate.attach_procedure_to_interp(greenkey, target_token.targeting_jitcell_token) self.history.inputargs = None self.history.operations = None raise GenerateMergePoint(live_arg_boxes, target_token.targeting_jitcell_token) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: support CALL_ASSEMBLER
Author: Hakan Ardo Branch: jit-targets Changeset: r48868:c728e120eed9 Date: 2011-11-07 14:05 +0100 http://bitbucket.org/pypy/pypy/changeset/c728e120eed9/ Log:support CALL_ASSEMBLER diff --git a/pypy/jit/backend/llgraph/runner.py b/pypy/jit/backend/llgraph/runner.py --- a/pypy/jit/backend/llgraph/runner.py +++ b/pypy/jit/backend/llgraph/runner.py @@ -181,9 +181,8 @@ llimpl.compile_add_descr(c, descr.ofs, descr.typeinfo, descr.arg_types) if isinstance(descr, history.JitCellToken): -assert False -if op.getopnum() != rop.JUMP: -llimpl.compile_add_loop_token(c, descr) +assert op.getopnum() != rop.JUMP +llimpl.compile_add_loop_token(c, descr) if isinstance(descr, history.TargetToken) and op.getopnum() == rop.LABEL: llimpl.compile_add_target_token(c, descr) if self.is_oo and isinstance(descr, (OODescr, MethDescr)): diff --git a/pypy/jit/metainterp/compile.py b/pypy/jit/metainterp/compile.py --- a/pypy/jit/metainterp/compile.py +++ b/pypy/jit/metainterp/compile.py @@ -70,8 +70,11 @@ if n >= 0: # we also record the resumedescr number original_jitcell_token.compiled_loop_token.record_faildescr_index(n) elif isinstance(descr, JitCellToken): -# for a CALL_ASSEMBLER ... -assert False, "FIXME" +# for a CALL_ASSEMBLER: record it as a potential jump. +if descr is not original_jitcell_token: +original_jitcell_token.record_jump_to(descr) +descr.exported_state = None +op._descr = None# clear reference, mostly for tests elif isinstance(descr, TargetToken): # for a JUMP: record it as a potential jump. # (the following test is not enough to prevent more complicated ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: retraces ending with a virtual state matching a previously compiled trace
Author: Hakan Ardo Branch: jit-targets Changeset: r48869:8e75cc4b5fbc Date: 2011-11-07 16:40 +0100 http://bitbucket.org/pypy/pypy/changeset/8e75cc4b5fbc/ Log:retraces ending with a virtual state matching a previously compiled trace diff --git a/pypy/jit/metainterp/compile.py b/pypy/jit/metainterp/compile.py --- a/pypy/jit/metainterp/compile.py +++ b/pypy/jit/metainterp/compile.py @@ -83,7 +83,10 @@ if descr.original_jitcell_token is not original_jitcell_token: assert descr.original_jitcell_token is not None original_jitcell_token.record_jump_to(descr.original_jitcell_token) -descr.exported_state = None +# exported_state is clear by optimizeopt when the short preamble is +# constrcucted. if that did not happen the label should not show up +# in a trace that will be used +assert descr.exported_state is None op._descr = None# clear reference, mostly for tests # record this looptoken on the QuasiImmut used in the code if loop.quasi_immutable_deps is not None: @@ -203,7 +206,8 @@ part = create_empty_loop(metainterp) part.inputargs = inputargs[:] part.start_resumedescr = start_resumedescr -h_ops = history.operations +h_ops = history.operations + part.operations = [partial_trace.operations[-1]] + \ [h_ops[i].clone() for i in range(start, len(h_ops))] + \ [ResOperation(rop.JUMP, jumpargs, None, descr=loop_jitcell_token)] diff --git a/pypy/jit/metainterp/optimizeopt/unroll.py b/pypy/jit/metainterp/optimizeopt/unroll.py --- a/pypy/jit/metainterp/optimizeopt/unroll.py +++ b/pypy/jit/metainterp/optimizeopt/unroll.py @@ -89,14 +89,18 @@ if not jumpop: return if self.jump_to_already_compiled_trace(jumpop): +# Found a compiled trace to jump to +if self.did_import: + +self.close_bridge(start_label) +self.finilize_short_preamble(start_label) return -# Failed to find a compiled trace to jump to, produce a label instead cell_token = jumpop.getdescr() assert isinstance(cell_token, JitCellToken) stop_label = ResOperation(rop.LABEL, jumpop.getarglist(), None, TargetToken(cell_token)) - -if not self.did_peel_one: # Enforce the previous behaviour of always peeling exactly one iteration (for now) + +if not self.did_import: # Enforce the previous behaviour of always peeling exactly one iteration (for now) self.optimizer.flush() KillHugeIntBounds(self.optimizer).apply() @@ -109,7 +113,6 @@ self.close_loop(jumpop) self.finilize_short_preamble(start_label) -start_label.getdescr().short_preamble = self.short def export_state(self, targetop): original_jump_args = targetop.getarglist() @@ -156,7 +159,7 @@ inputarg_setup_ops, self.optimizer) def import_state(self, targetop): -self.did_peel_one = False +self.did_import = False if not targetop: # FIXME: Set up some sort of empty state with no virtuals? return @@ -168,7 +171,7 @@ if not exported_state: # FIXME: Set up some sort of empty state with no virtuals return -self.did_peel_one = True +self.did_import = True self.short = target_token.short_preamble self.short_seen = {} @@ -216,7 +219,28 @@ self.optimizer.flush() self.optimizer.emitting_dissabled = False -def close_loop(self, jumpop): +def close_bridge(self, start_label): +inputargs = self.inputargs +short_jumpargs = inputargs[:] + +newoperations = self.optimizer.get_newoperations() +self.boxes_created_this_iteration = {} +i = 0 +while newoperations[i].getopnum() != rop.LABEL: +i += 1 +while i < len(newoperations): +op = newoperations[i] +self.boxes_created_this_iteration[op.result] = True +args = op.getarglist() +if op.is_guard(): +args = args + op.getfailargs() +for a in args: +self.import_box(a, inputargs, short_jumpargs, []) +i += 1 +newoperations = self.optimizer.get_newoperations() +self.short.append(ResOperation(rop.JUMP, short_jumpargs, None, descr=start_label.getdescr())) + +def close_loop(self, jumpop): virtual_state = self.initial_virtual_state short_inputargs = self.short[0].getarglist() constant_inputargs = self.imported_state.constant_inputargs @@ -334,6 +358,9 @@ for op in short: if op.result: op.result.forget_value() +target_token.shor
[pypy-commit] pypy jit-targets: hg merge default
Author: Hakan Ardo Branch: jit-targets Changeset: r48870:fd948f0bae66 Date: 2011-11-07 16:49 +0100 http://bitbucket.org/pypy/pypy/changeset/fd948f0bae66/ Log:hg merge default diff --git a/lib-python/conftest.py b/lib-python/conftest.py --- a/lib-python/conftest.py +++ b/lib-python/conftest.py @@ -201,7 +201,7 @@ RegrTest('test_difflib.py'), RegrTest('test_dircache.py', core=True), RegrTest('test_dis.py'), -RegrTest('test_distutils.py'), +RegrTest('test_distutils.py', skip=True), RegrTest('test_dl.py', skip=True), RegrTest('test_doctest.py', usemodules="thread"), RegrTest('test_doctest2.py'), diff --git a/lib-python/modified-2.7/ctypes/test/test_simplesubclasses.py b/lib-python/modified-2.7/ctypes/test/test_simplesubclasses.py --- a/lib-python/modified-2.7/ctypes/test/test_simplesubclasses.py +++ b/lib-python/modified-2.7/ctypes/test/test_simplesubclasses.py @@ -1,6 +1,5 @@ import unittest from ctypes import * -from ctypes.test import xfail class MyInt(c_int): def __cmp__(self, other): @@ -27,7 +26,6 @@ self.assertEqual(None, cb()) -@xfail def test_int_callback(self): args = [] def func(arg): diff --git a/lib_pypy/_ctypes/structure.py b/lib_pypy/_ctypes/structure.py --- a/lib_pypy/_ctypes/structure.py +++ b/lib_pypy/_ctypes/structure.py @@ -17,7 +17,7 @@ if len(f) == 3: if (not hasattr(tp, '_type_') or not isinstance(tp._type_, str) -or tp._type_ not in "iIhHbBlL"): +or tp._type_ not in "iIhHbBlLqQ"): #XXX: are those all types? # we just dont get the type name # in the interp levle thrown TypeError diff --git a/pypy/jit/metainterp/optimizeopt/__init__.py b/pypy/jit/metainterp/optimizeopt/__init__.py --- a/pypy/jit/metainterp/optimizeopt/__init__.py +++ b/pypy/jit/metainterp/optimizeopt/__init__.py @@ -55,7 +55,7 @@ def optimize_loop_1(metainterp_sd, loop, enable_opts, -inline_short_preamble=True, retraced=False, bridge=False): +inline_short_preamble=True, retraced=False): """Optimize loop.operations to remove internal overheadish operations. """ @@ -64,7 +64,7 @@ if unroll: optimize_unroll(metainterp_sd, loop, optimizations) else: -optimizer = Optimizer(metainterp_sd, loop, optimizations, bridge) +optimizer = Optimizer(metainterp_sd, loop, optimizations) optimizer.propagate_all_forward() def optimize_bridge_1(metainterp_sd, bridge, enable_opts, @@ -76,7 +76,7 @@ except KeyError: pass optimize_loop_1(metainterp_sd, bridge, enable_opts, -inline_short_preamble, retraced, bridge=True) +inline_short_preamble, retraced) if __name__ == '__main__': print ALL_OPTS_NAMES diff --git a/pypy/jit/metainterp/optimizeopt/heap.py b/pypy/jit/metainterp/optimizeopt/heap.py --- a/pypy/jit/metainterp/optimizeopt/heap.py +++ b/pypy/jit/metainterp/optimizeopt/heap.py @@ -234,7 +234,7 @@ or op.is_ovf()): self.posponedop = op else: -self.next_optimization.propagate_forward(op) +Optimization.emit_operation(self, op) def emitting_operation(self, op): if op.has_no_side_effect(): diff --git a/pypy/jit/metainterp/optimizeopt/intbounds.py b/pypy/jit/metainterp/optimizeopt/intbounds.py --- a/pypy/jit/metainterp/optimizeopt/intbounds.py +++ b/pypy/jit/metainterp/optimizeopt/intbounds.py @@ -6,6 +6,7 @@ IntUpperBound) from pypy.jit.metainterp.optimizeopt.util import make_dispatcher_method from pypy.jit.metainterp.resoperation import rop +from pypy.jit.metainterp.optimize import InvalidLoop from pypy.rlib.rarithmetic import LONG_BIT @@ -13,30 +14,10 @@ """Keeps track of the bounds placed on integers by guards and remove redundant guards""" -def setup(self): -self.posponedop = None -self.nextop = None - def new(self): -assert self.posponedop is None return OptIntBounds() - -def flush(self): -assert self.posponedop is None - -def setup(self): -self.posponedop = None -self.nextop = None def propagate_forward(self, op): -if op.is_ovf(): -self.posponedop = op -return -if self.posponedop: -self.nextop = op -op = self.posponedop -self.posponedop = None - dispatch_opt(self, op) def opt_default(self, op): @@ -179,68 +160,75 @@ r = self.getvalue(op.result) r.intbound.intersect(b) +def optimize_GUARD_NO_OVERFLOW(self, op): +lastop = self.last_emitted_operation +if lastop is not None: +opnum = lastop.getopnum() +args = lastop.getarglist() +result = lastop.result +# If the INT_xxx_OVF was r
[pypy-commit] pypy jit-targets: fix test
Author: Hakan Ardo Branch: jit-targets Changeset: r48871:7b0d8d8b3d9b Date: 2011-11-07 16:57 +0100 http://bitbucket.org/pypy/pypy/changeset/7b0d8d8b3d9b/ Log:fix test diff --git a/pypy/jit/metainterp/test/test_ajit.py b/pypy/jit/metainterp/test/test_ajit.py --- a/pypy/jit/metainterp/test/test_ajit.py +++ b/pypy/jit/metainterp/test/test_ajit.py @@ -1733,7 +1733,7 @@ self.check_loop_count(5) self.check_resops({'guard_class': 2, 'int_gt': 4, 'getfield_gc': 4, 'guard_true': 4, - 'int_sub': 4, 'jump': 4, 'int_mul': 2, + 'int_sub': 4, 'jump': 2, 'int_mul': 2, 'int_add': 2}) def test_multiple_specialied_versions_array(self): ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: fix test
Author: Hakan Ardo Branch: jit-targets Changeset: r48900:01cb9893b566 Date: 2011-11-07 18:28 +0100 http://bitbucket.org/pypy/pypy/changeset/01cb9893b566/ Log:fix test diff --git a/pypy/jit/metainterp/compile.py b/pypy/jit/metainterp/compile.py --- a/pypy/jit/metainterp/compile.py +++ b/pypy/jit/metainterp/compile.py @@ -89,7 +89,8 @@ assert descr.exported_state is None if not we_are_translated(): op._descr_wref = weakref.ref(op._descr) -op._descr = None# clear reference, mostly for tests +# xxx why do we need to clear op._descr?? +#op._descr = None# clear reference, mostly for tests # record this looptoken on the QuasiImmut used in the code if loop.quasi_immutable_deps is not None: for qmut in loop.quasi_immutable_deps: diff --git a/pypy/jit/metainterp/test/test_ajit.py b/pypy/jit/metainterp/test/test_ajit.py --- a/pypy/jit/metainterp/test/test_ajit.py +++ b/pypy/jit/metainterp/test/test_ajit.py @@ -1760,7 +1760,7 @@ array=array) res = res.binop(x) res.val += array[idx] + array[1] -if y < 7: +if y < 10: idx = 2 y -= 1 return res @@ -1772,10 +1772,10 @@ assert a1.val == a2.val assert b1.val == b2.val return a1.val + b1.val -res = self.meta_interp(g, [6, 14]) -assert res == g(6, 14) +res = self.meta_interp(g, [6, 20]) +assert res == g(6, 20) self.check_loop_count(9) -self.check_resops(getarrayitem_gc=8) +self.check_resops(getarrayitem_gc=10) def test_multiple_specialied_versions_bridge(self): myjitdriver = JitDriver(greens = [], reds = ['y', 'x', 'z', 'res']) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: abort unsupported case
Author: Hakan Ardo Branch: jit-targets Changeset: r48902:0a92fe884bc3 Date: 2011-11-07 19:02 +0100 http://bitbucket.org/pypy/pypy/changeset/0a92fe884bc3/ Log:abort unsupported case diff --git a/pypy/jit/metainterp/optimizeopt/unroll.py b/pypy/jit/metainterp/optimizeopt/unroll.py --- a/pypy/jit/metainterp/optimizeopt/unroll.py +++ b/pypy/jit/metainterp/optimizeopt/unroll.py @@ -527,6 +527,7 @@ retraced_count = cell_token.retraced_count limit = self.optimizer.metainterp_sd.warmrunnerdesc.memory_manager.retrace_limit if retraced_counthttp://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: fix tests
Author: Hakan Ardo Branch: jit-targets Changeset: r48904:6ad136c18d39 Date: 2011-11-07 20:15 +0100 http://bitbucket.org/pypy/pypy/changeset/6ad136c18d39/ Log:fix tests diff --git a/pypy/jit/metainterp/test/test_ajit.py b/pypy/jit/metainterp/test/test_ajit.py --- a/pypy/jit/metainterp/test/test_ajit.py +++ b/pypy/jit/metainterp/test/test_ajit.py @@ -3365,7 +3365,7 @@ res = self.meta_interp(main, [10]) assert res == main(10) self.check_resops({'int_gt': 2, 'strlen': 2, 'guard_true': 2, - 'int_sub': 2, 'jump': 2, 'call': 2, + 'int_sub': 2, 'jump': 1, 'call': 2, 'guard_no_exception': 2, 'int_add': 4}) def test_look_inside_iff_const_getarrayitem_gc_pure(self): @@ -3502,7 +3502,7 @@ res = self.meta_interp(f, [10]) assert res == 0 -self.check_resops({'jump': 2, 'guard_true': 2, 'int_gt': 2, +self.check_resops({'jump': 1, 'guard_true': 2, 'int_gt': 2, 'int_sub': 2}) def test_virtual_opaque_ptr(self): @@ -3522,7 +3522,7 @@ return n res = self.meta_interp(f, [10]) assert res == 0 -self.check_resops({'jump': 2, 'guard_true': 2, 'int_gt': 2, +self.check_resops({'jump': 1, 'guard_true': 2, 'int_gt': 2, 'int_sub': 2}) @@ -3545,7 +3545,7 @@ res = self.meta_interp(f, [10]) assert res == 0 self.check_resops({'int_gt': 2, 'getfield_gc': 1, 'int_eq': 1, - 'guard_true': 2, 'int_sub': 2, 'jump': 2, + 'guard_true': 2, 'int_sub': 2, 'jump': 1, 'guard_false': 1}) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: fallback to preamble if inlining short preamble fails
Author: Hakan Ardo Branch: jit-targets Changeset: r48901:ac810b69b113 Date: 2011-11-07 18:36 +0100 http://bitbucket.org/pypy/pypy/changeset/ac810b69b113/ Log:fallback to preamble if inlining short preamble fails diff --git a/pypy/jit/metainterp/optimizeopt/unroll.py b/pypy/jit/metainterp/optimizeopt/unroll.py --- a/pypy/jit/metainterp/optimizeopt/unroll.py +++ b/pypy/jit/metainterp/optimizeopt/unroll.py @@ -518,8 +518,9 @@ except InvalidLoop: debug_print("Inlining failed unexpectedly", "jumping to preamble instead") -assert False, "FIXME: Construct jump op" -self.optimizer.send_extra_operation(op) +assert cell_token.target_tokens[0].virtual_state is None +jumpop.setdescr(cell_token.target_tokens[0]) +self.optimizer.send_extra_operation(jumpop) return True debug_stop('jit-log-virtualstate') ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: dont inline short preamble when falling back to the full preamble
Author: Hakan Ardo Branch: jit-targets Changeset: r48903:8ed931ccc062 Date: 2011-11-07 20:08 +0100 http://bitbucket.org/pypy/pypy/changeset/8ed931ccc062/ Log:dont inline short preamble when falling back to the full preamble diff --git a/pypy/jit/metainterp/compile.py b/pypy/jit/metainterp/compile.py --- a/pypy/jit/metainterp/compile.py +++ b/pypy/jit/metainterp/compile.py @@ -708,7 +708,7 @@ else: inline_short_preamble = True try: -optimize_trace(metainterp_sd, new_trace, state.enable_opts) +optimize_trace(metainterp_sd, new_trace, state.enable_opts, inline_short_preamble) except InvalidLoop: debug_print("compile_new_bridge: got an InvalidLoop") # XXX I am fairly convinced that optimize_bridge cannot actually raise diff --git a/pypy/jit/metainterp/optimizeopt/__init__.py b/pypy/jit/metainterp/optimizeopt/__init__.py --- a/pypy/jit/metainterp/optimizeopt/__init__.py +++ b/pypy/jit/metainterp/optimizeopt/__init__.py @@ -28,8 +28,7 @@ ALL_OPTS_LIST = [name for name, _ in ALL_OPTS] ALL_OPTS_NAMES = ':'.join([name for name, _ in ALL_OPTS]) -def build_opt_chain(metainterp_sd, enable_opts, -inline_short_preamble=True, retraced=False): +def build_opt_chain(metainterp_sd, enable_opts): config = metainterp_sd.config optimizations = [] unroll = 'unroll' in enable_opts# 'enable_opts' is normally a dict @@ -48,9 +47,6 @@ or 'heap' not in enable_opts or 'unroll' not in enable_opts): optimizations.append(OptSimplify()) -if inline_short_preamble: -optimizations = [OptInlineShortPreamble(retraced)] + optimizations - return optimizations, unroll @@ -81,13 +77,13 @@ if __name__ == '__main__': print ALL_OPTS_NAMES -def optimize_trace(metainterp_sd, loop, enable_opts): +def optimize_trace(metainterp_sd, loop, enable_opts, inline_short_preamble=True): """Optimize loop.operations to remove internal overheadish operations. """ -optimizations, unroll = build_opt_chain(metainterp_sd, enable_opts, True, False) +optimizations, unroll = build_opt_chain(metainterp_sd, enable_opts) if unroll: -optimize_unroll(metainterp_sd, loop, optimizations) +optimize_unroll(metainterp_sd, loop, optimizations, inline_short_preamble) else: optimizer = Optimizer(metainterp_sd, loop, optimizations) optimizer.propagate_all_forward() diff --git a/pypy/jit/metainterp/optimizeopt/unroll.py b/pypy/jit/metainterp/optimizeopt/unroll.py --- a/pypy/jit/metainterp/optimizeopt/unroll.py +++ b/pypy/jit/metainterp/optimizeopt/unroll.py @@ -14,8 +14,9 @@ # FIXME: Introduce some VirtualOptimizer super class instead -def optimize_unroll(metainterp_sd, loop, optimizations): +def optimize_unroll(metainterp_sd, loop, optimizations, inline_short_preamble=True): opt = UnrollOptimizer(metainterp_sd, loop, optimizations) +opt.inline_short_preamble = inline_short_preamble opt.propagate_all_forward() class UnrollableOptimizer(Optimizer): @@ -23,6 +24,7 @@ self.importable_values = {} self.emitting_dissabled = False self.emitted_guards = 0 +self.inline_short_preamble = True def ensure_imported(self, value): if not self.emitting_dissabled and value in self.importable_values: @@ -464,6 +466,12 @@ if not cell_token.target_tokens: return False +if not self.inline_short_preamble: +assert cell_token.target_tokens[0].virtual_state is None +jumpop.setdescr(cell_token.target_tokens[0]) +self.optimizer.send_extra_operation(jumpop) +return True + args = jumpop.getarglist() modifier = VirtualStateAdder(self.optimizer) virtual_state = modifier.get_virtual_state(args) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: hg merge jit-refactor-tests
Author: Hakan Ardo Branch: jit-targets Changeset: r48906:e008b8114029 Date: 2011-11-08 08:07 +0100 http://bitbucket.org/pypy/pypy/changeset/e008b8114029/ Log:hg merge jit-refactor-tests diff --git a/pypy/jit/metainterp/test/test_loop.py b/pypy/jit/metainterp/test/test_loop.py --- a/pypy/jit/metainterp/test/test_loop.py +++ b/pypy/jit/metainterp/test/test_loop.py @@ -60,7 +60,8 @@ assert res == f(6, 13) self.check_loop_count(1) if self.enable_opts: -self.check_loops(getfield_gc = 0, setfield_gc = 1) +self.check_resops(setfield_gc=2, getfield_gc=0) + def test_loop_with_two_paths(self): from pypy.rpython.lltypesystem import lltype @@ -180,7 +181,10 @@ assert res == 42 self.check_loop_count(1) # the 'int_eq' and following 'guard' should be constant-folded -self.check_loops(int_eq=0, guard_true=1, guard_false=0) +if 'unroll' in self.enable_opts: +self.check_resops(int_eq=0, guard_true=2, guard_false=0) +else: +self.check_resops(int_eq=0, guard_true=1, guard_false=0) if self.basic: found = 0 for op in get_stats().loops[0]._all_operations(): @@ -643,8 +647,12 @@ res = self.meta_interp(main_interpreter_loop, [1]) assert res == 102 self.check_loop_count(1) -self.check_loops({'int_add' : 3, 'int_gt' : 1, - 'guard_false' : 1, 'jump' : 1}) +if 'unroll' in self.enable_opts: +self.check_resops({'int_add' : 6, 'int_gt' : 2, + 'guard_false' : 2, 'jump' : 2}) +else: +self.check_resops({'int_add' : 3, 'int_gt' : 1, + 'guard_false' : 1, 'jump' : 1}) def test_automatic_promotion(self): myjitdriver = JitDriver(greens = ['i'], @@ -686,7 +694,7 @@ self.check_loop_count(1) # These loops do different numbers of ops based on which optimizer we # are testing with. -self.check_loops(self.automatic_promotion_result) +self.check_resops(self.automatic_promotion_result) def test_can_enter_jit_outside_main_loop(self): myjitdriver = JitDriver(greens=[], reds=['i', 'j', 'a']) diff --git a/pypy/jit/metainterp/test/test_loop_unroll.py b/pypy/jit/metainterp/test/test_loop_unroll.py --- a/pypy/jit/metainterp/test/test_loop_unroll.py +++ b/pypy/jit/metainterp/test/test_loop_unroll.py @@ -8,7 +8,8 @@ enable_opts = ALL_OPTS_NAMES automatic_promotion_result = { -'int_add' : 3, 'int_gt' : 1, 'guard_false' : 1, 'jump' : 1, +'int_gt': 2, 'guard_false': 2, 'jump': 2, 'int_add': 6, +'guard_value': 1 } # > test_loop.py diff --git a/pypy/jit/metainterp/test/test_recursive.py b/pypy/jit/metainterp/test/test_recursive.py --- a/pypy/jit/metainterp/test/test_recursive.py +++ b/pypy/jit/metainterp/test/test_recursive.py @@ -143,11 +143,11 @@ f = self.get_interpreter(codes) assert self.meta_interp(f, [0, 0, 0], enable_opts='') == 42 -self.check_loops(int_add = 1, call_may_force = 1, call = 0) +self.check_resops(call_may_force=1, int_add=1, call=0) assert self.meta_interp(f, [0, 0, 0], enable_opts='', inline=True) == 42 -self.check_loops(int_add = 2, call_may_force = 0, call = 0, - guard_no_exception = 0) +self.check_resops(call=0, int_add=2, call_may_force=0, + guard_no_exception=0) def test_inline_jitdriver_check(self): code = "021" @@ -160,7 +160,7 @@ inline=True) == 42 # the call is fully inlined, because we jump to subcode[1], thus # skipping completely the JUMP_BACK in subcode[0] -self.check_loops(call_may_force = 0, call_assembler = 0, call = 0) +self.check_resops(call=0, call_may_force=0, call_assembler=0) def test_guard_failure_in_inlined_function(self): def p(pc, code): @@ -491,10 +491,10 @@ return loop(100) res = self.meta_interp(main, [0], enable_opts='', trace_limit=TRACE_LIMIT) -self.check_loops(call_may_force=1, call=0) +self.check_resops(call=0, call_may_force=1) res = self.meta_interp(main, [1], enable_opts='', trace_limit=TRACE_LIMIT) -self.check_loops(call_may_force=0, call=0) +self.check_resops(call=0, call_may_force=0) def test_trace_from_start(self): def p(pc, code): @@ -576,7 +576,7 @@ result += f('-c---l-', i+100) self.meta_interp(g, [10], backendopt=True) self.check_aborted_count(1) -self.check_loops(call_assembler=1, call=0) +self.check_resops(call=0, call_assembler=2) self.check_tree_loop_count(3) def test_directly_call_assembler(self): @@ -625,8 +625,7 @@
[pypy-commit] pypy jit-targets: better way of checking that the retracecount is not exceeded
Author: Hakan Ardo Branch: jit-targets Changeset: r48905:178c618d4dc3 Date: 2011-11-08 08:06 +0100 http://bitbucket.org/pypy/pypy/changeset/178c618d4dc3/ Log:better way of checking that the retracecount is not exceeded diff --git a/pypy/jit/metainterp/test/test_ajit.py b/pypy/jit/metainterp/test/test_ajit.py --- a/pypy/jit/metainterp/test/test_ajit.py +++ b/pypy/jit/metainterp/test/test_ajit.py @@ -2704,7 +2704,8 @@ res = self.meta_interp(g, [10]) assert res == g(10) # 1 preamble and 6 speciealized versions of each loop -self.check_tree_loop_count(2*(1 + 6)) +for loop in get_stats().loops: +assert len(loop.operations[0].getdescr().targeting_jitcell_token.target_tokens) <= 7 def test_nested_retrace(self): ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: recursion support
Author: Hakan Ardo Branch: jit-targets Changeset: r48909:df9f538c4ae9 Date: 2011-11-08 10:15 +0100 http://bitbucket.org/pypy/pypy/changeset/df9f538c4ae9/ Log:recursion support diff --git a/pypy/jit/metainterp/pyjitpl.py b/pypy/jit/metainterp/pyjitpl.py --- a/pypy/jit/metainterp/pyjitpl.py +++ b/pypy/jit/metainterp/pyjitpl.py @@ -2025,7 +2025,8 @@ num_green_args = self.jitdriver_sd.num_green_args greenkey = original_boxes[:num_green_args] if not self.partial_trace: -assert self.get_procedure_token(greenkey) == None # FIXME: recursion? +assert self.get_procedure_token(greenkey) is None or \ + self.get_procedure_token(greenkey).target_tokens is None if self.partial_trace: target_token = compile.compile_retrace(self, greenkey, start, original_boxes[num_green_args:], @@ -2051,6 +2052,8 @@ target_jitcell_token = self.get_procedure_token(greenkey) if not target_jitcell_token: return +if not target_jitcell_token.target_tokens: +return self.history.record(rop.JUMP, live_arg_boxes[num_green_args:], None, descr=target_jitcell_token) diff --git a/pypy/jit/metainterp/test/test_ajit.py b/pypy/jit/metainterp/test/test_ajit.py --- a/pypy/jit/metainterp/test/test_ajit.py +++ b/pypy/jit/metainterp/test/test_ajit.py @@ -3667,3 +3667,6 @@ assert x == -42 x = self.interp_operations(f, [1000, 1], translationoptions=topt) assert x == 999 + +def test_retracing_bridge_from_interpreter_to_finnish(self): +assert False # FIXME ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: jumps are allowed to jump to a TargetToken beloning to another procedure
Author: Hakan Ardo Branch: jit-targets Changeset: r48907:0ba1948f37c5 Date: 2011-11-08 08:33 +0100 http://bitbucket.org/pypy/pypy/changeset/0ba1948f37c5/ Log:jumps are allowed to jump to a TargetToken beloning to another procedure diff --git a/pypy/jit/metainterp/history.py b/pypy/jit/metainterp/history.py --- a/pypy/jit/metainterp/history.py +++ b/pypy/jit/metainterp/history.py @@ -829,7 +829,7 @@ self.check_consistency_of(self.inputargs, self.operations) for op in self.operations: descr = op.getdescr() -if isinstance(descr, TargetToken): +if op.getopnum() == rop.LABEL and isinstance(descr, TargetToken): assert descr.original_jitcell_token is self.original_jitcell_token @staticmethod diff --git a/pypy/jit/metainterp/test/test_recursive.py b/pypy/jit/metainterp/test/test_recursive.py --- a/pypy/jit/metainterp/test/test_recursive.py +++ b/pypy/jit/metainterp/test/test_recursive.py @@ -530,8 +530,8 @@ result = 0 for i in range(m): result += f('+-cl--', i) -g(50) -self.meta_interp(g, [50], backendopt=True) +res = self.meta_interp(g, [50], backendopt=True) +assert res == g(50) py.test.skip("tracing from start is by now only longer enabled " "if a trace gets too big") self.check_tree_loop_count(3) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-refactor-tests: convert test
Author: Hakan Ardo Branch: jit-refactor-tests Changeset: r48910:c52328c21f19 Date: 2011-11-08 10:25 +0100 http://bitbucket.org/pypy/pypy/changeset/c52328c21f19/ Log:convert test diff --git a/pypy/jit/metainterp/test/test_exception.py b/pypy/jit/metainterp/test/test_exception.py --- a/pypy/jit/metainterp/test/test_exception.py +++ b/pypy/jit/metainterp/test/test_exception.py @@ -35,10 +35,8 @@ return n res = self.meta_interp(f, [10]) assert res == 0 -self.check_loops({'jump': 1, - 'int_gt': 1, 'guard_true': 1, - 'int_sub': 1}) - +self.check_resops({'jump': 2, 'guard_true': 2, + 'int_gt': 2, 'int_sub': 2}) def test_bridge_from_guard_exception(self): myjitdriver = JitDriver(greens = [], reds = ['n']) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: renames
Author: Hakan Ardo Branch: jit-targets Changeset: r48908:8de0c01fb64b Date: 2011-11-08 08:55 +0100 http://bitbucket.org/pypy/pypy/changeset/8de0c01fb64b/ Log:renames diff --git a/pypy/jit/metainterp/compile.py b/pypy/jit/metainterp/compile.py --- a/pypy/jit/metainterp/compile.py +++ b/pypy/jit/metainterp/compile.py @@ -745,7 +745,7 @@ """ # 'redboxes' is only used to know the types of red arguments. inputargs = [box.clonebox() for box in redboxes] -loop_token = make_loop_token(len(inputargs), jitdriver_sd) +jitcell_token = make_jitcell_token(jitdriver_sd) # 'nb_red_args' might be smaller than len(redboxes), # because it doesn't include the virtualizable boxes. nb_red_args = jitdriver_sd.num_red_args @@ -778,7 +778,7 @@ ] operations[1].setfailargs([]) operations = get_deep_immutable_oplist(operations) -cpu.compile_loop(inputargs, operations, loop_token, log=False) +cpu.compile_loop(inputargs, operations, jitcell_token, log=False) if memory_manager is not None:# for tests -memory_manager.keep_loop_alive(loop_token) -return loop_token +memory_manager.keep_loop_alive(jitcell_token) +return jitcell_token ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: hg merge jit-refactor-tests
Author: Hakan Ardo Branch: jit-targets Changeset: r48911:893335d40c74 Date: 2011-11-08 10:26 +0100 http://bitbucket.org/pypy/pypy/changeset/893335d40c74/ Log:hg merge jit-refactor-tests diff --git a/pypy/jit/metainterp/test/test_exception.py b/pypy/jit/metainterp/test/test_exception.py --- a/pypy/jit/metainterp/test/test_exception.py +++ b/pypy/jit/metainterp/test/test_exception.py @@ -35,10 +35,8 @@ return n res = self.meta_interp(f, [10]) assert res == 0 -self.check_loops({'jump': 1, - 'int_gt': 1, 'guard_true': 1, - 'int_sub': 1}) - +self.check_resops({'jump': 2, 'guard_true': 2, + 'int_gt': 2, 'int_sub': 2}) def test_bridge_from_guard_exception(self): myjitdriver = JitDriver(greens = [], reds = ['n']) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: fix test
Author: Hakan Ardo Branch: jit-targets Changeset: r48926:340cdb94a9f5 Date: 2011-11-08 10:31 +0100 http://bitbucket.org/pypy/pypy/changeset/340cdb94a9f5/ Log:fix test diff --git a/pypy/jit/metainterp/test/test_exception.py b/pypy/jit/metainterp/test/test_exception.py --- a/pypy/jit/metainterp/test/test_exception.py +++ b/pypy/jit/metainterp/test/test_exception.py @@ -35,7 +35,7 @@ return n res = self.meta_interp(f, [10]) assert res == 0 -self.check_resops({'jump': 2, 'guard_true': 2, +self.check_resops({'jump': 1, 'guard_true': 2, 'int_gt': 2, 'int_sub': 2}) def test_bridge_from_guard_exception(self): ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: dont crash if not inlining the same short preamble as is beeing produced
Author: Hakan Ardo Branch: jit-targets Changeset: r48928:a6c88d02ef0e Date: 2011-11-08 11:07 +0100 http://bitbucket.org/pypy/pypy/changeset/a6c88d02ef0e/ Log:dont crash if not inlining the same short preamble as is beeing produced diff --git a/pypy/jit/metainterp/optimizeopt/unroll.py b/pypy/jit/metainterp/optimizeopt/unroll.py --- a/pypy/jit/metainterp/optimizeopt/unroll.py +++ b/pypy/jit/metainterp/optimizeopt/unroll.py @@ -224,6 +224,10 @@ def close_bridge(self, start_label): inputargs = self.inputargs short_jumpargs = inputargs[:] + +# We dont need to inline the short preamble we are creating as we are conneting +# the bridge to a different trace with a different short preamble +self.short_inliner = None newoperations = self.optimizer.get_newoperations() self.boxes_created_this_iteration = {} @@ -406,7 +410,7 @@ if op is None: return None if op.result is not None and op.result in self.short_seen: -if emit: +if emit and self.short_inliner: return self.short_inliner.inline_arg(op.result) else: return None @@ -425,7 +429,7 @@ self.short.append(op) self.short_seen[op.result] = True -if emit: +if emit and self.short_inliner: newop = self.short_inliner.inline_op(op) self.optimizer.send_extra_operation(newop) else: @@ -535,7 +539,7 @@ retraced_count = cell_token.retraced_count limit = self.optimizer.metainterp_sd.warmrunnerdesc.memory_manager.retrace_limit if retraced_counthttp://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-refactor-tests: conversion in progress
Author: Hakan Ardo Branch: jit-refactor-tests Changeset: r48929:27c73644ff5a Date: 2011-11-08 11:32 +0100 http://bitbucket.org/pypy/pypy/changeset/27c73644ff5a/ Log:conversion in progress diff --git a/pypy/jit/metainterp/test/test_string.py b/pypy/jit/metainterp/test/test_string.py --- a/pypy/jit/metainterp/test/test_string.py +++ b/pypy/jit/metainterp/test/test_string.py @@ -30,7 +30,7 @@ return i res = self.meta_interp(f, [10, True, _str('h')], listops=True) assert res == 5 -self.check_loops(**{self.CALL: 1, self.CALL_PURE: 0, 'everywhere': True}) +self.check_resops(**{self.CALL: 1, self.CALL_PURE: 0}) def test_eq_folded(self): _str = self._str @@ -50,7 +50,7 @@ return i res = self.meta_interp(f, [10, True, _str('h')], listops=True) assert res == 5 -self.check_loops(**{self.CALL: 0, self.CALL_PURE: 0}) +self.check_resops(**{self.CALL: 0, self.CALL_PURE: 0}) def test_newstr(self): _str, _chr = self._str, self._chr @@ -85,7 +85,7 @@ n -= 1 return 42 self.meta_interp(f, [6]) -self.check_loops(newstr=0, strsetitem=0, strlen=0, +self.check_resops(newstr=0, strsetitem=0, strlen=0, newunicode=0, unicodesetitem=0, unicodelen=0) def test_char2string_escape(self): @@ -126,7 +126,7 @@ return total res = self.meta_interp(f, [6]) assert res == 21 -self.check_loops(newstr=0, strgetitem=0, strsetitem=0, strlen=0, +self.check_resops(newstr=0, strgetitem=0, strsetitem=0, strlen=0, newunicode=0, unicodegetitem=0, unicodesetitem=0, unicodelen=0) @@ -147,7 +147,7 @@ m -= 1 return 42 self.meta_interp(f, [6, 7]) -self.check_loops(newstr=0, strsetitem=0, +self.check_resops(newstr=0, strsetitem=0, newunicode=0, unicodesetitem=0, call=0, call_pure=0) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: exception support
Author: Hakan Ardo Branch: jit-targets Changeset: r48927:31885b3fa5e9 Date: 2011-11-08 10:43 +0100 http://bitbucket.org/pypy/pypy/changeset/31885b3fa5e9/ Log:exception support diff --git a/pypy/jit/metainterp/pyjitpl.py b/pypy/jit/metainterp/pyjitpl.py --- a/pypy/jit/metainterp/pyjitpl.py +++ b/pypy/jit/metainterp/pyjitpl.py @@ -2127,20 +2127,19 @@ assert False # FIXME: kill TerminatingLoopToken? # FIXME: can we call compile_trace? -self.history.record(rop.FINISH, exits, None, descr=loop_tokens[0].finishdescr) +token = loop_tokens[0].finishdescr +self.history.record(rop.FINISH, exits, None, descr=token) target_token = compile.compile_trace(self, self.resumekey) -if not target_token: +if target_token is not token: compile.giveup() def compile_exit_frame_with_exception(self, valuebox): self.gen_store_back_in_virtualizable() -# temporarily put a JUMP to a pseudo-loop -self.history.record(rop.JUMP, [valuebox], None) sd = self.staticdata -loop_tokens = sd.loop_tokens_exit_frame_with_exception_ref -target_loop_token = compile.compile_new_bridge(self, loop_tokens, - self.resumekey) -if target_loop_token is not loop_tokens[0]: +token = sd.loop_tokens_exit_frame_with_exception_ref[0].finishdescr +self.history.record(rop.FINISH, [valuebox], None, descr=token) +target_token = compile.compile_trace(self, self.resumekey) +if target_token is not token: compile.giveup() @specialize.arg(1) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: fix test to not retrace when the guard is created and only to count the number of int_mul which is what the test is about
Author: Hakan Ardo Branch: jit-targets Changeset: r48932:1515bd7380ed Date: 2011-11-08 13:02 +0100 http://bitbucket.org/pypy/pypy/changeset/1515bd7380ed/ Log:fix test to not retrace when the guard is created and only to count the number of int_mul which is what the test is about diff --git a/pypy/jit/metainterp/test/test_ajit.py b/pypy/jit/metainterp/test/test_ajit.py --- a/pypy/jit/metainterp/test/test_ajit.py +++ b/pypy/jit/metainterp/test/test_ajit.py @@ -180,43 +180,39 @@ self.check_trace_count(3) def test_loop_invariant_mul_bridge_maintaining1(self): -myjitdriver = JitDriver(greens = [], reds = ['y', 'res', 'x']) -def f(x, y): +myjitdriver = JitDriver(greens = [], reds = ['y', 'res', 'x', 'n']) +def f(x, y, n): res = 0 while y > 0: -myjitdriver.can_enter_jit(x=x, y=y, res=res) -myjitdriver.jit_merge_point(x=x, y=y, res=res) +myjitdriver.can_enter_jit(x=x, y=y, res=res, n=n) +myjitdriver.jit_merge_point(x=x, y=y, res=res, n=n) res += x * x -if y<16: +if y 0: -myjitdriver.can_enter_jit(x=x, y=y, res=res) -myjitdriver.jit_merge_point(x=x, y=y, res=res) +myjitdriver.can_enter_jit(x=x, y=y, res=res, n=n) +myjitdriver.jit_merge_point(x=x, y=y, res=res, n=n) z = x * x res += z -if y<16: +if yhttp://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: renaming, redefining and reeanbling the "loop" counters (in progress)
Author: Hakan Ardo Branch: jit-targets Changeset: r48930:9b50e8266be0 Date: 2011-11-08 12:11 +0100 http://bitbucket.org/pypy/pypy/changeset/9b50e8266be0/ Log:renaming, redefining and reeanbling the "loop" counters (in progress) diff --git a/pypy/jit/metainterp/test/support.py b/pypy/jit/metainterp/test/support.py --- a/pypy/jit/metainterp/test/support.py +++ b/pypy/jit/metainterp/test/support.py @@ -161,34 +161,35 @@ def check_loops(self, expected=None, everywhere=False, **check): get_stats().check_loops(expected=expected, everywhere=everywhere, **check) -def check_loop_count(self, count): -"""NB. This is a hack; use check_tree_loop_count() or -check_enter_count() for the real thing. -This counts as 1 every bridge in addition to every loop; and it does -not count at all the entry bridges from interpreter, although they -are TreeLoops as well.""" -return # FIXME -assert get_stats().compiled_count == count -def check_tree_loop_count(self, count): -return # FIXME +def check_trace_count(self, count): +# The number of traces compiled assert len(get_stats().loops) == count -def check_loop_count_at_most(self, count): -return # FIXME -assert get_stats().compiled_count <= count +def check_trace_count_at_most(self, count): +assert len(get_stats().loops) <= count + +def check_jitcell_token_count(self, count): +tokens = set() +for loop in get_stats().loops: +for op in loop.operations: +descr = op.getdescr() +if isinstance(descr, history.TargetToken): +descr = descr.targeting_jitcell_token +if isinstance(descr, history.JitCellToken): +tokens.add(descr) +assert len(tokens) == count + def check_enter_count(self, count): -return # FIXME assert get_stats().enter_count == count def check_enter_count_at_most(self, count): -return # FIXME assert get_stats().enter_count <= count + def check_jumps(self, maxcount): return # FIXME assert get_stats().exec_jumps <= maxcount + def check_aborted_count(self, count): -return # FIXME assert get_stats().aborted_count == count def check_aborted_count_at_least(self, count): -return # FIXME assert get_stats().aborted_count >= count def meta_interp(self, *args, **kwds): diff --git a/pypy/jit/metainterp/test/test_ajit.py b/pypy/jit/metainterp/test/test_ajit.py --- a/pypy/jit/metainterp/test/test_ajit.py +++ b/pypy/jit/metainterp/test/test_ajit.py @@ -78,7 +78,7 @@ return res res = self.meta_interp(f, [6, 7]) assert res == 42 -self.check_loop_count(1) +self.check_trace_count(1) self.check_resops({'jump': 1, 'int_gt': 2, 'int_add': 2, 'guard_true': 2, 'int_sub': 2}) @@ -107,7 +107,7 @@ return res res = self.meta_interp(f, [6, 7]) assert res == 1323 -self.check_loop_count(1) +self.check_trace_count(1) self.check_resops(int_mul=3) def test_loop_variant_mul_ovf(self): @@ -124,7 +124,7 @@ return res res = self.meta_interp(f, [6, 7]) assert res == 1323 -self.check_loop_count(1) +self.check_trace_count(1) self.check_resops(int_mul_ovf=3) def test_loop_invariant_mul1(self): @@ -139,7 +139,7 @@ return res res = self.meta_interp(f, [6, 7]) assert res == 252 -self.check_loop_count(1) +self.check_trace_count(1) self.check_resops({'jump': 1, 'int_gt': 2, 'int_add': 2, 'int_mul': 1, 'guard_true': 2, 'int_sub': 2}) @@ -157,7 +157,7 @@ return res res = self.meta_interp(f, [6, 7]) assert res == 308 -self.check_loop_count(1) +self.check_trace_count(1) self.check_resops({'jump': 1, 'int_lshift': 2, 'int_gt': 2, 'int_mul_ovf': 1, 'int_add': 4, 'guard_true': 2, 'guard_no_overflow': 1, @@ -177,7 +177,7 @@ return res res = self.meta_interp(f, [6, 32]) assert res == 3427 -self.check_loop_count(3) +self.check_trace_count(3) def test_loop_invariant_mul_bridge_maintaining1(self): myjitdriver = JitDriver(greens = [], reds = ['y', 'res', 'x']) @@ -193,7 +193,7 @@ return res res = self.meta_interp(f, [6, 32]) assert res == 1167 -self.check_loop_count(3) +self.check_trace_count(3) self.check_resops({'int_lt': 3, 'int_gt': 2, 'int_add': 5, 'guard_true': 3, 'int_sub': 4, 'jump': 2, 'int_mul': 2, 'guard_false': 2}) @@
[pypy-commit] pypy jit-targets: fix tests
Author: Hakan Ardo Branch: jit-targets Changeset: r48933:7d1b9a847447 Date: 2011-11-08 13:27 +0100 http://bitbucket.org/pypy/pypy/changeset/7d1b9a847447/ Log:fix tests diff --git a/pypy/jit/metainterp/test/test_ajit.py b/pypy/jit/metainterp/test/test_ajit.py --- a/pypy/jit/metainterp/test/test_ajit.py +++ b/pypy/jit/metainterp/test/test_ajit.py @@ -880,7 +880,9 @@ n -= 1 self.meta_interp(f, [20], repeat=7) -self.check_jitcell_token_count(2) # the loop and the entry path +# the loop and the entry path as a single trace +self.check_jitcell_token_count(1) + # we get: #ENTER - compile the new loop and the entry bridge #ENTER - compile the leaving path @@ -1251,7 +1253,7 @@ res = self.meta_interp(f, [10, 3]) assert res == 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1 + 0 -self.check_jitcell_token_count(2) +self.check_jitcell_token_count(1) res = self.meta_interp(f, [10, 13]) assert res == 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1 + 0 @@ -1726,7 +1728,7 @@ return a1.val + b1.val res = self.meta_interp(g, [6, 7]) assert res == 6*8 + 6**8 -self.check_trace_count(5) +self.check_trace_count(4) self.check_resops({'guard_class': 2, 'int_gt': 4, 'getfield_gc': 4, 'guard_true': 4, 'int_sub': 4, 'jump': 2, 'int_mul': 2, @@ -1770,7 +1772,7 @@ return a1.val + b1.val res = self.meta_interp(g, [6, 20]) assert res == g(6, 20) -self.check_trace_count(9) +self.check_trace_count(8) self.check_resops(getarrayitem_gc=10) def test_multiple_specialied_versions_bridge(self): @@ -1958,7 +1960,7 @@ return a1.val + b1.val res = self.meta_interp(g, [3, 23]) assert res == 7068153 -self.check_trace_count(7) +self.check_trace_count(6) self.check_resops(guard_true=6, guard_class=2, int_mul=3, int_add=3, guard_false=3) @@ -2044,7 +2046,7 @@ return n res = self.meta_interp(f, [sys.maxint-10]) assert res == 11 -self.check_jitcell_token_count(2) +self.check_jitcell_token_count(1) def test_wrap_around_mul(self): myjitdriver = JitDriver(greens = [], reds = ['x', 'n']) @@ -2060,7 +2062,7 @@ return n res = self.meta_interp(f, [sys.maxint>>10]) assert res == 11 -self.check_jitcell_token_count(2) +self.check_jitcell_token_count(1) def test_wrap_around_sub(self): myjitdriver = JitDriver(greens = [], reds = ['x', 'n']) @@ -2076,7 +2078,7 @@ return n res = self.meta_interp(f, [10-sys.maxint]) assert res == 12 -self.check_jitcell_token_count(2) +self.check_jitcell_token_count(1) def test_caching_setfield(self): myjitdriver = JitDriver(greens = [], reds = ['sa', 'i', 'n', 'a', 'node']) @@ -2596,9 +2598,9 @@ i += 1 return sa assert self.meta_interp(f, [20, 2]) == f(20, 2) +self.check_jitcell_token_count(3) +assert self.meta_interp(f, [20, 3]) == f(20, 3) self.check_jitcell_token_count(4) -assert self.meta_interp(f, [20, 3]) == f(20, 3) -self.check_jitcell_token_count(5) def test_max_retrace_guards(self): myjitdriver = JitDriver(greens = [], reds = ['n', 'i', 'sa', 'a']) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: make sure all jitcell tokens and traces are actually counted
Author: Hakan Ardo Branch: jit-targets Changeset: r48931:12fef84a6bd0 Date: 2011-11-08 12:51 +0100 http://bitbucket.org/pypy/pypy/changeset/12fef84a6bd0/ Log:make sure all jitcell tokens and traces are actually counted diff --git a/pypy/jit/metainterp/compile.py b/pypy/jit/metainterp/compile.py --- a/pypy/jit/metainterp/compile.py +++ b/pypy/jit/metainterp/compile.py @@ -270,10 +270,7 @@ metainterp_sd.profiler.end_backend() metainterp_sd.stats.add_new_loop(loop) if not we_are_translated(): -if type != "entry bridge": -metainterp_sd.stats.compiled() -else: -loop._ignore_during_counting = True +metainterp_sd.stats.compiled() metainterp_sd.log("compiled new " + type) # metainterp_sd.logger_ops.log_loop(loop.inputargs, loop.operations, n, type, ops_offset) @@ -679,6 +676,7 @@ # send the new_loop to warmspot.py, to be called directly the next time jitdriver_sd.warmstate.attach_procedure_to_interp( self.original_greenkey, jitcell_token) +metainterp_sd.stats.add_jitcell_token(jitcell_token) def reset_counter_from_failure(self): pass diff --git a/pypy/jit/metainterp/history.py b/pypy/jit/metainterp/history.py --- a/pypy/jit/metainterp/history.py +++ b/pypy/jit/metainterp/history.py @@ -963,6 +963,9 @@ def clear(self): pass +def add_jitcell_token(self, token): +pass + class Stats(object): """For tests.""" @@ -976,6 +979,7 @@ self.locations = [] self.aborted_keys = [] self.invalidated_token_numbers = set() +self.jitcell_tokens = set() def clear(self): del self.loops[:] @@ -986,6 +990,9 @@ self.enter_count = 0 self.aborted_count = 0 +def add_jitcell_token(self, token): +self.jitcell_tokens.add(token) + def set_history(self, history): self.operations = history.operations diff --git a/pypy/jit/metainterp/pyjitpl.py b/pypy/jit/metainterp/pyjitpl.py --- a/pypy/jit/metainterp/pyjitpl.py +++ b/pypy/jit/metainterp/pyjitpl.py @@ -2040,6 +2040,8 @@ start_resumedescr) if target_token is not None: self.jitdriver_sd.warmstate.attach_procedure_to_interp(greenkey, target_token.targeting_jitcell_token) + self.staticdata.stats.add_jitcell_token(target_token.targeting_jitcell_token) + if target_token is not None: # raise if it *worked* correctly self.history.inputargs = None diff --git a/pypy/jit/metainterp/test/support.py b/pypy/jit/metainterp/test/support.py --- a/pypy/jit/metainterp/test/support.py +++ b/pypy/jit/metainterp/test/support.py @@ -161,22 +161,15 @@ def check_loops(self, expected=None, everywhere=False, **check): get_stats().check_loops(expected=expected, everywhere=everywhere, **check) + def check_trace_count(self, count): # The number of traces compiled -assert len(get_stats().loops) == count +assert get_stats().compiled_count == count def check_trace_count_at_most(self, count): -assert len(get_stats().loops) <= count +assert get_stats().compiled_count <= count def check_jitcell_token_count(self, count): -tokens = set() -for loop in get_stats().loops: -for op in loop.operations: -descr = op.getdescr() -if isinstance(descr, history.TargetToken): -descr = descr.targeting_jitcell_token -if isinstance(descr, history.JitCellToken): -tokens.add(descr) -assert len(tokens) == count +assert len(get_stats().jitcell_tokens) == count def check_enter_count(self, count): assert get_stats().enter_count == count diff --git a/pypy/jit/metainterp/test/test_ajit.py b/pypy/jit/metainterp/test/test_ajit.py --- a/pypy/jit/metainterp/test/test_ajit.py +++ b/pypy/jit/metainterp/test/test_ajit.py @@ -164,18 +164,18 @@ 'int_sub': 2}) def test_loop_invariant_mul_bridge1(self): -myjitdriver = JitDriver(greens = [], reds = ['y', 'res', 'x']) -def f(x, y): +myjitdriver = JitDriver(greens = [], reds = ['y', 'res', 'x', 'n']) +def f(x, y, n): res = 0 while y > 0: -myjitdriver.can_enter_jit(x=x, y=y, res=res) -myjitdriver.jit_merge_point(x=x, y=y, res=res) +myjitdriver.can_enter_jit(x=x, y=y, n=n, res=res) +myjitdriver.jit_merge_point(x=x, y=y, n=n, res=res) res += x * x -if y<16: +if yhttp://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: respect retrace limit
Author: Hakan Ardo Branch: jit-targets Changeset: r48934:8f5285d28ef9 Date: 2011-11-08 13:38 +0100 http://bitbucket.org/pypy/pypy/changeset/8f5285d28ef9/ Log:respect retrace limit diff --git a/pypy/jit/metainterp/optimizeopt/unroll.py b/pypy/jit/metainterp/optimizeopt/unroll.py --- a/pypy/jit/metainterp/optimizeopt/unroll.py +++ b/pypy/jit/metainterp/optimizeopt/unroll.py @@ -506,42 +506,48 @@ pass target.virtual_state.debug_print(debugmsg, bad) -if ok: -debug_stop('jit-log-virtualstate') +if ok: +debug_stop('jit-log-virtualstate') -values = [self.getvalue(arg) - for arg in jumpop.getarglist()] -args = target.virtual_state.make_inputargs(values, self.optimizer, - keyboxes=True) -short_inputargs = target.short_preamble[0].getarglist() -inliner = Inliner(short_inputargs, args) +values = [self.getvalue(arg) + for arg in jumpop.getarglist()] +args = target.virtual_state.make_inputargs(values, self.optimizer, + keyboxes=True) +short_inputargs = target.short_preamble[0].getarglist() +inliner = Inliner(short_inputargs, args) -for guard in extra_guards: -if guard.is_guard(): -descr = target.start_resumedescr.clone_if_mutable() -inliner.inline_descr_inplace(descr) -guard.setdescr(descr) -self.optimizer.send_extra_operation(guard) +for guard in extra_guards: +if guard.is_guard(): +descr = target.start_resumedescr.clone_if_mutable() +inliner.inline_descr_inplace(descr) +guard.setdescr(descr) +self.optimizer.send_extra_operation(guard) -try: -for shop in target.short_preamble[1:]: -newop = inliner.inline_op(shop) -self.optimizer.send_extra_operation(newop) -except InvalidLoop: -debug_print("Inlining failed unexpectedly", -"jumping to preamble instead") -assert cell_token.target_tokens[0].virtual_state is None -jumpop.setdescr(cell_token.target_tokens[0]) -self.optimizer.send_extra_operation(jumpop) -return True +try: +for shop in target.short_preamble[1:]: +newop = inliner.inline_op(shop) +self.optimizer.send_extra_operation(newop) +except InvalidLoop: +debug_print("Inlining failed unexpectedly", +"jumping to preamble instead") +assert cell_token.target_tokens[0].virtual_state is None +jumpop.setdescr(cell_token.target_tokens[0]) +self.optimizer.send_extra_operation(jumpop) +return True debug_stop('jit-log-virtualstate') -retraced_count = cell_token.retraced_count limit = self.optimizer.metainterp_sd.warmrunnerdesc.memory_manager.retrace_limit -if retraced_counthttp://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: support max_retrace_guards
Author: Hakan Ardo Branch: jit-targets Changeset: r48936:5a5c19100cf4 Date: 2011-11-08 14:09 +0100 http://bitbucket.org/pypy/pypy/changeset/5a5c19100cf4/ Log:support max_retrace_guards diff --git a/pypy/jit/metainterp/optimizeopt/unroll.py b/pypy/jit/metainterp/optimizeopt/unroll.py --- a/pypy/jit/metainterp/optimizeopt/unroll.py +++ b/pypy/jit/metainterp/optimizeopt/unroll.py @@ -322,6 +322,10 @@ raise InvalidLoop debug_stop('jit-log-virtualstate') +maxguards = self.optimizer.metainterp_sd.warmrunnerdesc.memory_manager.max_retrace_guards +if self.optimizer.emitted_guards > maxguards: +jumpop.getdescr().targeting_jitcell_token.retraced_count = sys.maxint + def finilize_short_preamble(self, start_label): short = self.short assert short[-1].getopnum() == rop.JUMP diff --git a/pypy/jit/metainterp/test/test_ajit.py b/pypy/jit/metainterp/test/test_ajit.py --- a/pypy/jit/metainterp/test/test_ajit.py +++ b/pypy/jit/metainterp/test/test_ajit.py @@ -2599,10 +2599,10 @@ return sa assert self.meta_interp(f, [20, 2]) == f(20, 2) self.check_jitcell_token_count(1) -assert len(get_stats().jitcell_tokens.pop().target_tokens) == 4 +assert len(list(get_stats().jitcell_tokens)[0].target_tokens) == 4 assert self.meta_interp(f, [20, 3]) == f(20, 3) self.check_jitcell_token_count(1) -assert len(get_stats().jitcell_tokens.pop().target_tokens) == 5 +assert len(list(get_stats().jitcell_tokens)[0].target_tokens) == 5 def test_max_retrace_guards(self): myjitdriver = JitDriver(greens = [], reds = ['n', 'i', 'sa', 'a']) @@ -2619,10 +2619,11 @@ i += 1 return sa assert self.meta_interp(f, [20, 1]) == f(20, 1) -self.check_jitcell_token_count(2) +self.check_jitcell_token_count(1) +assert len(list(get_stats().jitcell_tokens)[0].target_tokens) == 2 assert self.meta_interp(f, [20, 10]) == f(20, 10) -self.check_jitcell_token_count(5) - +self.check_jitcell_token_count(1) +assert len(list(get_stats().jitcell_tokens)[0].target_tokens) == 5 def test_retrace_limit_with_extra_guards(self): myjitdriver = JitDriver(greens = [], reds = ['n', 'i', 'sa', 'a', ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: fix test to actually count the number of specialized versions of the loop
Author: Hakan Ardo Branch: jit-targets Changeset: r48935:d200a90155ef Date: 2011-11-08 13:51 +0100 http://bitbucket.org/pypy/pypy/changeset/d200a90155ef/ Log:fix test to actually count the number of specialized versions of the loop diff --git a/pypy/jit/metainterp/optimizeopt/unroll.py b/pypy/jit/metainterp/optimizeopt/unroll.py --- a/pypy/jit/metainterp/optimizeopt/unroll.py +++ b/pypy/jit/metainterp/optimizeopt/unroll.py @@ -536,6 +536,8 @@ return True debug_stop('jit-log-virtualstate') +if self.did_import: +return False limit = self.optimizer.metainterp_sd.warmrunnerdesc.memory_manager.retrace_limit if cell_token.retraced_counthttp://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: fix test
Author: Hakan Ardo Branch: jit-targets Changeset: r48944:ac7073eb2075 Date: 2011-11-08 15:09 +0100 http://bitbucket.org/pypy/pypy/changeset/ac7073eb2075/ Log:fix test diff --git a/pypy/jit/metainterp/test/test_ajit.py b/pypy/jit/metainterp/test/test_ajit.py --- a/pypy/jit/metainterp/test/test_ajit.py +++ b/pypy/jit/metainterp/test/test_ajit.py @@ -2643,9 +2643,11 @@ i += 1 return sa assert self.meta_interp(f, [20, 2]) == f(20, 2) -self.check_jitcell_token_count(4) +self.check_jitcell_token_count(1) +assert len(list(get_stats().jitcell_tokens)[0].target_tokens) == 4 assert self.meta_interp(f, [20, 3]) == f(20, 3) -self.check_jitcell_token_count(5) +self.check_jitcell_token_count(1) +assert len(list(get_stats().jitcell_tokens)[0].target_tokens) == 5 def test_retrace_ending_up_retrazing_another_loop(self): @@ -2688,12 +2690,8 @@ # The attempts of retracing first loop will end up retracing the # second and thus fail 5 times, saturating the retrace_count. Instead a -# bridge back to the preamble of the first loop is produced. A guard in -# this bridge is later traced resulting in a retrace of the second loop. -# Thus we end up with: -# 1 preamble and 1 specialized version of first loop -# 1 preamble and 2 specialized version of second loop -self.check_jitcell_token_count(2 + 3) +# bridge back to the preamble of the first loop is produced. +self.check_trace_count(6) # FIXME: Add a gloabl retrace counter and test that we are not trying more than 5 times. @@ -2704,10 +2702,12 @@ res = self.meta_interp(g, [10]) assert res == g(10) -# 1 preamble and 6 speciealized versions of each loop -for loop in get_stats().loops: -assert len(loop.operations[0].getdescr().targeting_jitcell_token.target_tokens) <= 7 - + +self.check_jitcell_token_count(2) +for cell in get_stats().jitcell_tokens: +# Initialal trace with two labels and 5 retraces +assert len(cell.target_tokens) <= 7 + def test_nested_retrace(self): myjitdriver = JitDriver(greens = ['pc'], reds = ['n', 'a', 'i', 'j', 'sa']) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: fix tests
Author: Hakan Ardo Branch: jit-targets Changeset: r48946:b449ace83c77 Date: 2011-11-08 15:25 +0100 http://bitbucket.org/pypy/pypy/changeset/b449ace83c77/ Log:fix tests diff --git a/pypy/jit/metainterp/test/test_ajit.py b/pypy/jit/metainterp/test/test_ajit.py --- a/pypy/jit/metainterp/test/test_ajit.py +++ b/pypy/jit/metainterp/test/test_ajit.py @@ -3149,7 +3149,7 @@ return sa res = self.meta_interp(f, [32]) assert res == f(32) -self.check_jitcell_token_count(3) +self.check_trace_count(2) def test_two_loopinvariant_arrays2(self): from pypy.rpython.lltypesystem import lltype, llmemory, rffi @@ -3172,7 +3172,7 @@ return sa res = self.meta_interp(f, [32]) assert res == f(32) -self.check_jitcell_token_count(3) +self.check_trace_count(2) def test_two_loopinvariant_arrays3(self): from pypy.rpython.lltypesystem import lltype, llmemory, rffi @@ -3196,7 +3196,7 @@ return sa res = self.meta_interp(f, [32]) assert res == f(32) -self.check_jitcell_token_count(2) +self.check_trace_count(3) def test_two_loopinvariant_arrays_boxed(self): class A(object): ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-targets: indent
Author: Hakan Ardo Branch: jit-targets Changeset: r48945:7d76cfa50b41 Date: 2011-11-08 15:14 +0100 http://bitbucket.org/pypy/pypy/changeset/7d76cfa50b41/ Log:indent diff --git a/pypy/jit/metainterp/optimizeopt/unroll.py b/pypy/jit/metainterp/optimizeopt/unroll.py --- a/pypy/jit/metainterp/optimizeopt/unroll.py +++ b/pypy/jit/metainterp/optimizeopt/unroll.py @@ -510,34 +510,34 @@ pass target.virtual_state.debug_print(debugmsg, bad) -if ok: -debug_stop('jit-log-virtualstate') +if ok: +debug_stop('jit-log-virtualstate') -values = [self.getvalue(arg) - for arg in jumpop.getarglist()] -args = target.virtual_state.make_inputargs(values, self.optimizer, - keyboxes=True) -short_inputargs = target.short_preamble[0].getarglist() -inliner = Inliner(short_inputargs, args) +values = [self.getvalue(arg) + for arg in jumpop.getarglist()] +args = target.virtual_state.make_inputargs(values, self.optimizer, + keyboxes=True) +short_inputargs = target.short_preamble[0].getarglist() +inliner = Inliner(short_inputargs, args) -for guard in extra_guards: -if guard.is_guard(): -descr = target.start_resumedescr.clone_if_mutable() -inliner.inline_descr_inplace(descr) -guard.setdescr(descr) -self.optimizer.send_extra_operation(guard) +for guard in extra_guards: +if guard.is_guard(): +descr = target.start_resumedescr.clone_if_mutable() +inliner.inline_descr_inplace(descr) +guard.setdescr(descr) +self.optimizer.send_extra_operation(guard) -try: -for shop in target.short_preamble[1:]: -newop = inliner.inline_op(shop) -self.optimizer.send_extra_operation(newop) -except InvalidLoop: -debug_print("Inlining failed unexpectedly", -"jumping to preamble instead") -assert cell_token.target_tokens[0].virtual_state is None -jumpop.setdescr(cell_token.target_tokens[0]) -self.optimizer.send_extra_operation(jumpop) -return True +try: +for shop in target.short_preamble[1:]: +newop = inliner.inline_op(shop) +self.optimizer.send_extra_operation(newop) +except InvalidLoop: +debug_print("Inlining failed unexpectedly", +"jumping to preamble instead") +assert cell_token.target_tokens[0].virtual_state is None +jumpop.setdescr(cell_token.target_tokens[0]) +self.optimizer.send_extra_operation(jumpop) +return True debug_stop('jit-log-virtualstate') if self.did_import: ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-refactor-tests: convreted tests
Author: Hakan Ardo Branch: jit-refactor-tests Changeset: r48952:5b50039bad35 Date: 2011-11-08 16:39 +0100 http://bitbucket.org/pypy/pypy/changeset/5b50039bad35/ Log:convreted tests diff --git a/pypy/jit/metainterp/test/test_del.py b/pypy/jit/metainterp/test/test_del.py --- a/pypy/jit/metainterp/test/test_del.py +++ b/pypy/jit/metainterp/test/test_del.py @@ -20,12 +20,12 @@ n -= 1 return 42 self.meta_interp(f, [20]) -self.check_loops({'call': 2, # calls to a helper function - 'guard_no_exception': 2,# follows the calls - 'int_sub': 1, - 'int_gt': 1, - 'guard_true': 1, - 'jump': 1}) +self.check_resops({'call': 4, # calls to a helper function + 'guard_no_exception': 4,# follows the calls + 'int_sub': 2, + 'int_gt': 2, + 'guard_true': 2, + 'jump': 2}) def test_class_of_allocated(self): myjitdriver = JitDriver(greens = [], reds = ['n', 'x']) @@ -78,7 +78,7 @@ return 1 res = self.meta_interp(f, [20], enable_opts='') assert res == 1 -self.check_loops(call=1) # for the case B(), but not for the case A() +self.check_resops(call=1) # for the case B(), but not for the case A() class TestLLtype(DelTests, LLJitMixin): @@ -103,7 +103,7 @@ break return 42 self.meta_interp(f, [20]) -self.check_loops(getfield_raw=1, setfield_raw=1, call=0, call_pure=0) +self.check_resops(call_pure=0, setfield_raw=2, call=0, getfield_raw=2) class TestOOtype(DelTests, OOJitMixin): def setup_class(cls): diff --git a/pypy/jit/metainterp/test/test_dict.py b/pypy/jit/metainterp/test/test_dict.py --- a/pypy/jit/metainterp/test/test_dict.py +++ b/pypy/jit/metainterp/test/test_dict.py @@ -91,7 +91,7 @@ res1 = f(100) res2 = self.meta_interp(f, [100], listops=True) assert res1 == res2 -self.check_loops(int_mod=1) # the hash was traced and eq, but cached +self.check_resops(int_mod=2) # the hash was traced and eq, but cached def test_dict_setdefault(self): myjitdriver = JitDriver(greens = [], reds = ['total', 'dct']) @@ -107,7 +107,7 @@ assert f(100) == 50 res = self.meta_interp(f, [100], listops=True) assert res == 50 -self.check_loops(new=0, new_with_vtable=0) +self.check_resops(new=0, new_with_vtable=0) def test_dict_as_counter(self): myjitdriver = JitDriver(greens = [], reds = ['total', 'dct']) @@ -128,7 +128,7 @@ assert f(100) == 50 res = self.meta_interp(f, [100], listops=True) assert res == 50 -self.check_loops(int_mod=1) # key + eq, but cached +self.check_resops(int_mod=2) # key + eq, but cached def test_repeated_lookup(self): myjitdriver = JitDriver(greens = [], reds = ['n', 'd']) @@ -153,12 +153,13 @@ res = self.meta_interp(f, [100], listops=True) assert res == f(50) -self.check_loops({"call": 5, "getfield_gc": 1, "getinteriorfield_gc": 1, - "guard_false": 1, "guard_no_exception": 4, - "guard_true": 1, "int_and": 1, "int_gt": 1, - "int_is_true": 1, "int_sub": 1, "jump": 1, - "new_with_vtable": 1, "new": 1, "new_array": 1, - "setfield_gc": 3, }) +self.check_resops({'new_array': 2, 'getfield_gc': 2, + 'guard_true': 2, 'jump': 2, + 'new_with_vtable': 2, 'getinteriorfield_gc': 2, + 'setfield_gc': 6, 'int_gt': 2, 'int_sub': 2, + 'call': 10, 'int_and': 2, + 'guard_no_exception': 8, 'new': 2, + 'guard_false': 2, 'int_is_true': 2}) class TestOOtype(DictTests, OOJitMixin): diff --git a/pypy/jit/metainterp/test/test_fficall.py b/pypy/jit/metainterp/test/test_fficall.py --- a/pypy/jit/metainterp/test/test_fficall.py +++ b/pypy/jit/metainterp/test/test_fficall.py @@ -68,23 +68,23 @@ 'byval': False} supported = all(d[check] for check in jitif) if supported: -self.check_loops( -call_release_gil=1, # a CALL_RELEASE_GIL, and no other CALLs +self.check_resops( +call_release_gil=2, # a CALL_RELEASE_GIL, and no other CALLs call=0, call_may_force=0, -guard_no_exception=1, -guard_not_forced=1, -int_add=1, -int_lt=1, -guard_true=1, -jump=1) +guard_no_exception=2, +
[pypy-commit] pypy jit-refactor-tests: converted test
Author: Hakan Ardo Branch: jit-refactor-tests Changeset: r48947:9021a2a814b1 Date: 2011-11-08 15:40 +0100 http://bitbucket.org/pypy/pypy/changeset/9021a2a814b1/ Log:converted test diff --git a/pypy/jit/metainterp/test/test_string.py b/pypy/jit/metainterp/test/test_string.py --- a/pypy/jit/metainterp/test/test_string.py +++ b/pypy/jit/metainterp/test/test_string.py @@ -168,12 +168,11 @@ return 42 self.meta_interp(f, [6, 7]) if _str is str: -self.check_loops(newstr=1, strsetitem=0, copystrcontent=2, - call=1, call_pure=0) # escape +self.check_resops(call_pure=0, copystrcontent=4, + strsetitem=0, call=2, newstr=2) else: -self.check_loops(newunicode=1, unicodesetitem=0, - copyunicodecontent=2, - call=1, call_pure=0) # escape +self.check_resops(call_pure=0, unicodesetitem=0, call=2, + copyunicodecontent=4, newunicode=2) def test_strconcat_escape_str_char(self): _str, _chr = self._str, self._chr @@ -192,12 +191,11 @@ return 42 self.meta_interp(f, [6, 7]) if _str is str: -self.check_loops(newstr=1, strsetitem=1, copystrcontent=1, - call=1, call_pure=0) # escape +self.check_resops(call_pure=0, copystrcontent=2, strsetitem=2, + call=2, newstr=2) else: -self.check_loops(newunicode=1, unicodesetitem=1, - copyunicodecontent=1, - call=1, call_pure=0) # escape +self.check_resops(call_pure=0, unicodesetitem=2, call=2, + copyunicodecontent=2, newunicode=2) def test_strconcat_escape_char_str(self): _str, _chr = self._str, self._chr @@ -216,12 +214,11 @@ return 42 self.meta_interp(f, [6, 7]) if _str is str: -self.check_loops(newstr=1, strsetitem=1, copystrcontent=1, - call=1, call_pure=0) # escape +self.check_resops(call_pure=0, copystrcontent=2, + strsetitem=2, call=2, newstr=2) else: -self.check_loops(newunicode=1, unicodesetitem=1, - copyunicodecontent=1, - call=1, call_pure=0) # escape +self.check_resops(call_pure=0, unicodesetitem=2, call=2, + copyunicodecontent=2, newunicode=2) def test_strconcat_escape_char_char(self): _str, _chr = self._str, self._chr @@ -239,12 +236,11 @@ return 42 self.meta_interp(f, [6, 7]) if _str is str: -self.check_loops(newstr=1, strsetitem=2, copystrcontent=0, - call=1, call_pure=0) # escape +self.check_resops(call_pure=0, copystrcontent=0, + strsetitem=4, call=2, newstr=2) else: -self.check_loops(newunicode=1, unicodesetitem=2, - copyunicodecontent=0, - call=1, call_pure=0) # escape +self.check_resops(call_pure=0, unicodesetitem=4, call=2, + copyunicodecontent=0, newunicode=2) def test_strconcat_escape_str_char_str(self): _str, _chr = self._str, self._chr @@ -263,12 +259,11 @@ return 42 self.meta_interp(f, [6, 7]) if _str is str: -self.check_loops(newstr=1, strsetitem=1, copystrcontent=2, - call=1, call_pure=0) # escape +self.check_resops(call_pure=0, copystrcontent=4, strsetitem=2, + call=2, newstr=2) else: -self.check_loops(newunicode=1, unicodesetitem=1, - copyunicodecontent=2, - call=1, call_pure=0) # escape +self.check_resops(call_pure=0, unicodesetitem=2, call=2, + copyunicodecontent=4, newunicode=2) def test_strconcat_guard_fail(self): _str = self._str @@ -325,7 +320,7 @@ m -= 1 return 42 self.meta_interp(f, [6, 7]) -self.check_loops(newstr=0, newunicode=0) +self.check_resops(newunicode=0, newstr=0) def test_str_slice_len_surviving(self): _str = self._str @@ -504,9 +499,9 @@ sys.defaultencoding = _str('utf-8') return sa assert self.meta_interp(f, [8]) == f(8) -self.check_loops({'int_add': 1, 'guard_true': 1, 'int_sub': 1, - 'jump': 1, 'int_is_true': 1, - 'guard_not_invalidated': 1}) +self.check_resops({'jump': 2, 'int_is_true': 2, 'int_add': 2, + 'guard_tr
[pypy-commit] pypy jit-refactor-tests: converted test
Author: Hakan Ardo Branch: jit-refactor-tests Changeset: r48948:280c132cc8a4 Date: 2011-11-08 15:52 +0100 http://bitbucket.org/pypy/pypy/changeset/280c132cc8a4/ Log:converted test diff --git a/pypy/jit/metainterp/test/test_virtualizable.py b/pypy/jit/metainterp/test/test_virtualizable.py --- a/pypy/jit/metainterp/test/test_virtualizable.py +++ b/pypy/jit/metainterp/test/test_virtualizable.py @@ -77,7 +77,7 @@ return xy.inst_x res = self.meta_interp(f, [20]) assert res == 30 -self.check_loops(getfield_gc=0, setfield_gc=0) +self.check_resops(setfield_gc=0, getfield_gc=0) def test_preexisting_access_2(self): myjitdriver = JitDriver(greens = [], reds = ['n', 'xy'], @@ -102,7 +102,7 @@ assert f(5) == 185 res = self.meta_interp(f, [5]) assert res == 185 -self.check_loops(getfield_gc=0, setfield_gc=0) +self.check_resops(setfield_gc=0, getfield_gc=0) def test_two_paths_access(self): myjitdriver = JitDriver(greens = [], reds = ['n', 'xy'], @@ -124,7 +124,7 @@ return xy.inst_x res = self.meta_interp(f, [18]) assert res == 10118 -self.check_loops(getfield_gc=0, setfield_gc=0) +self.check_resops(setfield_gc=0, getfield_gc=0) def test_synchronize_in_return(self): myjitdriver = JitDriver(greens = [], reds = ['n', 'xy'], @@ -146,7 +146,7 @@ return xy.inst_x res = self.meta_interp(f, [18]) assert res == 10180 -self.check_loops(getfield_gc=0, setfield_gc=0) +self.check_resops(setfield_gc=0, getfield_gc=0) def test_virtualizable_and_greens(self): myjitdriver = JitDriver(greens = ['m'], reds = ['n', 'xy'], @@ -174,7 +174,7 @@ return res res = self.meta_interp(f, [40]) assert res == 50 * 4 -self.check_loops(getfield_gc=0, setfield_gc=0) +self.check_resops(setfield_gc=0, getfield_gc=0) def test_double_frame(self): myjitdriver = JitDriver(greens = [], reds = ['n', 'xy', 'other'], @@ -197,8 +197,7 @@ return xy.inst_x res = self.meta_interp(f, [20]) assert res == 134 -self.check_loops(getfield_gc=0, setfield_gc=1) -self.check_loops(getfield_gc=1, setfield_gc=2, everywhere=True) +self.check_resops(setfield_gc=2, getfield_gc=1) # -- @@ -248,8 +247,8 @@ return xy2.inst_l1[2] res = self.meta_interp(f, [16]) assert res == 3001 + 16 * 80 -self.check_loops(getfield_gc=0, setfield_gc=0, - getarrayitem_gc=0, setarrayitem_gc=0) +self.check_resops(setarrayitem_gc=0, setfield_gc=0, + getarrayitem_gc=0, getfield_gc=0) def test_synchronize_arrays_in_return(self): myjitdriver = JitDriver(greens = [], reds = ['n', 'xy2'], @@ -279,8 +278,7 @@ assert f(18) == 10360 res = self.meta_interp(f, [18]) assert res == 10360 -self.check_loops(getfield_gc=0, setfield_gc=0, - getarrayitem_gc=0) +self.check_resops(setfield_gc=0, getarrayitem_gc=0, getfield_gc=0) def test_array_length(self): myjitdriver = JitDriver(greens = [], reds = ['n', 'xy2'], @@ -306,8 +304,8 @@ return xy2.inst_l1[1] res = self.meta_interp(f, [18]) assert res == 2941309 + 18 -self.check_loops(getfield_gc=0, setfield_gc=0, - getarrayitem_gc=0, arraylen_gc=0) +self.check_resops(setfield_gc=0, getarrayitem_gc=0, + arraylen_gc=0, getfield_gc=0) def test_residual_function(self): myjitdriver = JitDriver(greens = [], reds = ['n', 'xy2'], @@ -340,8 +338,8 @@ return xy2.inst_l1[1] res = self.meta_interp(f, [18]) assert res == 2941309 + 18 -self.check_loops(getfield_gc=0, setfield_gc=0, - getarrayitem_gc=0, arraylen_gc=1, call=1) +self.check_resops(call=2, setfield_gc=0, getarrayitem_gc=0, + arraylen_gc=2, getfield_gc=0) def test_double_frame_array(self): myjitdriver = JitDriver(greens = [], reds = ['n', 'xy2', 'other'], @@ -377,8 +375,8 @@ expected = f(20) res = self.meta_interp(f, [20], enable_opts='') assert res == expected -self.check_loops(getfield_gc=1, setfield_gc=0, - arraylen_gc=1, getarrayitem_gc=1, setarrayitem_gc=1) +self.check_resops(setarrayitem_gc=1, setfield_gc=0, + getarrayitem_gc=1, arraylen_gc=1, getfield_gc=1) # -- @@ -425,8 +423,7 @@ assert f(18) == 10360 res = self.meta_interp(f, [18]) assert res == 10360 -self.check_loops(getfield_gc=0, setfield_gc=0, - getarrayitem_gc=0) +