| 1 |
import pytest |
| 2 |
from rpython.jit.metainterp.test.support import LLJitMixin |
| 3 |
from rpython.rlib.jit import JitDriver, assert_green |
| 4 |
|
| 5 |
pytest.skip("this feature is disabled at the moment!") |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
class GreenFieldsTests: |
| 17 |
|
| 18 |
def test_green_field_1(self): |
| 19 |
myjitdriver = JitDriver(greens=['ctx.x'], reds=['ctx']) |
| 20 |
class Ctx(object): |
| 21 |
_immutable_fields_ = ['x'] |
| 22 |
def __init__(self, x, y): |
| 23 |
self.x = x |
| 24 |
self.y = y |
| 25 |
def f(x, y): |
| 26 |
ctx = Ctx(x, y) |
| 27 |
while 1: |
| 28 |
myjitdriver.can_enter_jit(ctx=ctx) |
| 29 |
myjitdriver.jit_merge_point(ctx=ctx) |
| 30 |
ctx.y -= 1 |
| 31 |
if ctx.y < 0: |
| 32 |
return ctx.y |
| 33 |
def g(y): |
| 34 |
return f(5, y) + f(6, y) |
| 35 |
|
| 36 |
res = self.meta_interp(g, [7]) |
| 37 |
assert res == -2 |
| 38 |
self.check_trace_count(2) |
| 39 |
self.check_resops(guard_value=0) |
| 40 |
|
| 41 |
def test_green_field_2(self): |
| 42 |
myjitdriver = JitDriver(greens=['ctx.x'], reds=['ctx']) |
| 43 |
class Ctx(object): |
| 44 |
_immutable_fields_ = ['x'] |
| 45 |
def __init__(self, x, y): |
| 46 |
self.x = x |
| 47 |
self.y = y |
| 48 |
def f(x, y): |
| 49 |
ctx = Ctx(x, y) |
| 50 |
while 1: |
| 51 |
myjitdriver.can_enter_jit(ctx=ctx) |
| 52 |
myjitdriver.jit_merge_point(ctx=ctx) |
| 53 |
ctx.y -= 1 |
| 54 |
if ctx.y < 0: |
| 55 |
pass |
| 56 |
if ctx.y < -10: |
| 57 |
return ctx.y |
| 58 |
def g(y): |
| 59 |
return f(5, y) + f(6, y) |
| 60 |
|
| 61 |
res = self.meta_interp(g, [7]) |
| 62 |
assert res == -22 |
| 63 |
self.check_trace_count(4) |
| 64 |
self.check_resops(guard_value=0) |
| 65 |
|
| 66 |
def test_green_field_3(self): |
| 67 |
myjitdriver = JitDriver(greens=['ctx.x'], reds=['ctx']) |
| 68 |
class Ctx(object): |
| 69 |
_immutable_fields_ = ['x'] |
| 70 |
def __init__(self, x, y): |
| 71 |
self.x = x |
| 72 |
self.y = y |
| 73 |
def f(x, y): |
| 74 |
ctx = Ctx(x, y) |
| 75 |
while ctx.y > 0: |
| 76 |
myjitdriver.can_enter_jit(ctx=ctx) |
| 77 |
myjitdriver.jit_merge_point(ctx=ctx) |
| 78 |
assert_green(ctx.x) |
| 79 |
ctx.y -= ctx.x |
| 80 |
return -2100 |
| 81 |
def g(): |
| 82 |
return f(5, 35) + f(6, 42) |
| 83 |
|
| 84 |
res = self.meta_interp(g, []) |
| 85 |
assert res == -4200 |
| 86 |
|
| 87 |
|
| 88 |
class TestLLtypeGreenFieldsTests(GreenFieldsTests, LLJitMixin): |
| 89 |
pass |