Exemplo n.º 1
0
 def test_liveranges(self):
     i0, i1, i2 = IntFrontendOp(0), IntFrontendOp(0), IntFrontendOp(0)
     t = Trace([i0, i1, i2], metainterp_sd)
     p0 = FakeOp(t.record_op(rop.NEW_WITH_VTABLE, [], descr=SomeDescr()))
     t.record_op(rop.GUARD_TRUE, [i0])
     resume.capture_resumedata([], [i1, i2, p0], [p0, i1], t)
     assert t.get_live_ranges() == [4, 4, 4, 4]
Exemplo n.º 2
0
 def test_read_snapshot_interface(self):
     i0, i1, i2 = IntFrontendOp(0), IntFrontendOp(0), IntFrontendOp(0)
     t = Trace([i0, i1, i2], metainterp_sd)
     t.record_op(rop.GUARD_TRUE, [i1])
     frame0 = FakeFrame(1, JitCode(2), [i0, i1])
     frame1 = FakeFrame(3, JitCode(4), [i2, i2])
     resume.capture_resumedata([frame0, frame1], None, [], t)
     t.record_op(rop.GUARD_TRUE, [i1])
     resume.capture_resumedata([frame0, frame1], None, [], t)
     (i0, i1, i2), l, iter = self.unpack(t)
     pos = l[0].rd_resume_position
     snapshot_iter = iter.get_snapshot_iter(pos)
     assert snapshot_iter.vable_array == []
     assert snapshot_iter.vref_array == []
     framestack = snapshot_iter.framestack
     jc_index, pc = snapshot_iter.unpack_jitcode_pc(framestack[1])
     assert jc_index == 4
     assert pc == 3
     assert snapshot_iter.unpack_array(framestack[1].box_array) == [i2, i2]
     jc_index, pc = snapshot_iter.unpack_jitcode_pc(framestack[0])
     assert jc_index == 2
     assert pc == 1
     assert snapshot_iter.unpack_array(framestack[0].box_array) == [i0, i1]
     pos = l[1].rd_resume_position
     snapshot_iter = iter.get_snapshot_iter(pos)
     framestack = snapshot_iter.framestack
     assert snapshot_iter.vable_array == []
     assert snapshot_iter.vref_array == []
     jc_index, pc = snapshot_iter.unpack_jitcode_pc(framestack[1])
     assert jc_index == 4
     assert pc == 3
     assert snapshot_iter.unpack_array(framestack[1].box_array) == [i2, i2]
Exemplo n.º 3
0
 def test_liveranges(self):
     i0, i1, i2 = IntFrontendOp(0), IntFrontendOp(0), IntFrontendOp(0)
     t = Trace([i0, i1, i2], metainterp_sd)
     p0 = FakeOp(t.record_op(rop.NEW_WITH_VTABLE, [], descr=SomeDescr()))
     t.record_op(rop.GUARD_TRUE, [i0])
     resume.capture_resumedata([], [i1, i2, p0], [p0, i1], t)
     assert t.get_live_ranges() == [4, 4, 4, 4]
Exemplo n.º 4
0
 def test_read_snapshot_interface(self):
     i0, i1, i2 = IntFrontendOp(0), IntFrontendOp(0), IntFrontendOp(0)
     t = Trace([i0, i1, i2], metainterp_sd)
     t.record_op(rop.GUARD_TRUE, [i1])
     frame0 = FakeFrame(1, JitCode(2), [i0, i1])
     frame1 = FakeFrame(3, JitCode(4), [i2, i2])
     resume.capture_resumedata([frame0, frame1], None, [], t)
     t.record_op(rop.GUARD_TRUE, [i1])
     resume.capture_resumedata([frame0, frame1], None, [], t)
     (i0, i1, i2), l, iter = self.unpack(t)
     pos = l[0].rd_resume_position
     snapshot_iter = iter.get_snapshot_iter(pos)
     assert snapshot_iter.vable_array == []
     assert snapshot_iter.vref_array == []
     framestack = snapshot_iter.framestack
     jc_index, pc = snapshot_iter.unpack_jitcode_pc(framestack[1])
     assert jc_index == 4
     assert pc == 3
     assert snapshot_iter.unpack_array(framestack[1].box_array) == [i2, i2]
     jc_index, pc = snapshot_iter.unpack_jitcode_pc(framestack[0])
     assert jc_index == 2
     assert pc == 1
     assert snapshot_iter.unpack_array(framestack[0].box_array) == [i0, i1]
     pos = l[1].rd_resume_position
     snapshot_iter = iter.get_snapshot_iter(pos)
     framestack = snapshot_iter.framestack
     assert snapshot_iter.vable_array == []
     assert snapshot_iter.vref_array == []
     jc_index, pc = snapshot_iter.unpack_jitcode_pc(framestack[1])
     assert jc_index == 4
     assert pc == 3
     assert snapshot_iter.unpack_array(framestack[1].box_array) == [i2, i2]
Exemplo n.º 5
0
 def test_virtualizable_virtualref(self):
     i0, i1, i2 = IntFrontendOp(0), IntFrontendOp(0), IntFrontendOp(0)
     t = Trace([i0, i1, i2], metainterp_sd)
     p0 = FakeOp(t.record_op(rop.NEW_WITH_VTABLE, [], descr=SomeDescr()))
     t.record_op(rop.GUARD_TRUE, [i0])
     resume.capture_resumedata([], [i1, i2, p0], [p0, i1], t)
     (i0, i1, i2), l, iter = self.unpack(t)
     assert not l[1].framestack
     assert l[1].virtualizables == [l[0], i1, i2]
     assert l[1].vref_boxes == [l[0], i1]
Exemplo n.º 6
0
 def test_virtualizable_virtualref(self):
     i0, i1, i2 = IntFrontendOp(0), IntFrontendOp(0), IntFrontendOp(0)
     t = Trace([i0, i1, i2], metainterp_sd)
     p0 = FakeOp(t.record_op(rop.NEW_WITH_VTABLE, [], descr=SomeDescr()))
     t.record_op(rop.GUARD_TRUE, [i0])
     resume.capture_resumedata([], [i1, i2, p0], [p0, i1], t)
     (i0, i1, i2), l, iter = self.unpack(t)
     assert not l[1].framestack
     assert l[1].virtualizables == [l[0], i1, i2]
     assert l[1].vref_boxes == [l[0], i1]
Exemplo n.º 7
0
 def test_cut_trace_from(self):
     i0, i1, i2 = IntFrontendOp(0), IntFrontendOp(0), IntFrontendOp(0)
     t = Trace([i0, i1, i2], metainterp_sd)
     add1 = FakeOp(t.record_op(rop.INT_ADD, [i0, i1]))
     cut_point = t.cut_point()
     add2 = FakeOp(t.record_op(rop.INT_ADD, [add1, i1]))
     t.record_op(rop.GUARD_TRUE, [add2])
     resume.capture_resumedata([FakeFrame(3, JitCode(4), [add2, add1, i1])],
                               None, [], t)
     t.record_op(rop.INT_SUB, [add2, add1])
     t2 = t.cut_trace_from(cut_point, [add1, i1])
     (i0, i1), l, iter = self.unpack(t2)
     assert len(l) == 3
     assert l[0].getarglist() == [i0, i1]
Exemplo n.º 8
0
 def test_cut_trace_from(self):
     i0, i1, i2 = IntFrontendOp(0), IntFrontendOp(0), IntFrontendOp(0)
     t = Trace([i0, i1, i2], metainterp_sd)
     add1 = FakeOp(t.record_op(rop.INT_ADD, [i0, i1]))
     cut_point = t.cut_point()
     add2 = FakeOp(t.record_op(rop.INT_ADD, [add1, i1]))
     t.record_op(rop.GUARD_TRUE, [add2])
     resume.capture_resumedata([FakeFrame(3, JitCode(4), [add2, add1, i1])],
         None, [], t)
     t.record_op(rop.INT_SUB, [add2, add1])
     t2 = t.cut_trace_from(cut_point, [add1, i1])
     (i0, i1), l, iter = self.unpack(t2)
     assert len(l) == 3
     assert l[0].getarglist() == [i0, i1]
Exemplo n.º 9
0
 def test_deadranges(self):
     i0, i1, i2 = IntFrontendOp(0), IntFrontendOp(0), IntFrontendOp(0)
     t = Trace([i0, i1, i2], metainterp_sd)
     p0 = FakeOp(t.record_op(rop.NEW_WITH_VTABLE, [], descr=SomeDescr()))
     t.record_op(rop.GUARD_TRUE, [i0])
     resume.capture_resumedata([], [i1, i2, p0], [p0, i1], t)
     i3 = FakeOp(t.record_op(rop.INT_ADD, [i1, ConstInt(1)]))
     i4 = FakeOp(t.record_op(rop.INT_ADD, [i3, ConstInt(1)]))
     t.record_op(rop.ESCAPE_N, [ConstInt(3)])
     t.record_op(rop.ESCAPE_N, [ConstInt(3)])
     t.record_op(rop.ESCAPE_N, [ConstInt(3)])
     t.record_op(rop.ESCAPE_N, [ConstInt(3)])
     t.record_op(rop.ESCAPE_N, [ConstInt(3)])
     t.record_op(rop.FINISH, [i4])
     assert t.get_dead_ranges() == [0, 0, 0, 0, 0, 3, 4, 5]
Exemplo n.º 10
0
 def test_deadranges(self):
     i0, i1, i2 = IntFrontendOp(0), IntFrontendOp(0), IntFrontendOp(0)
     t = Trace([i0, i1, i2], metainterp_sd)
     p0 = FakeOp(t.record_op(rop.NEW_WITH_VTABLE, [], descr=SomeDescr()))
     t.record_op(rop.GUARD_TRUE, [i0])
     resume.capture_resumedata([], [i1, i2, p0], [p0, i1], t)
     i3 = FakeOp(t.record_op(rop.INT_ADD, [i1, ConstInt(1)]))
     i4 = FakeOp(t.record_op(rop.INT_ADD, [i3, ConstInt(1)]))
     t.record_op(rop.ESCAPE_N, [ConstInt(3)])
     t.record_op(rop.ESCAPE_N, [ConstInt(3)])
     t.record_op(rop.ESCAPE_N, [ConstInt(3)])
     t.record_op(rop.ESCAPE_N, [ConstInt(3)])
     t.record_op(rop.ESCAPE_N, [ConstInt(3)])
     t.record_op(rop.FINISH, [i4])
     assert t.get_dead_ranges() == [0, 0, 0, 0, 0, 3, 4, 5]
Exemplo n.º 11
0
 def xxx_test_random_snapshot(self, lst):
     inputargs, ops = lst
     t = Trace(inputargs, metainterp_sd)
     for op in ops:
         newop = FakeOp(t.record_op(op.getopnum(), op.getarglist()))
         newop.orig_op = op
         if newop.is_guard():
             resume.capture_resumedata(op.framestack, None, [], t)
         op.position = newop.get_position()
     inpargs, l, iter = self.unpack(t)
     loop1 = TreeLoop("loop1")
     loop1.inputargs = inputargs
     loop1.operations = ops
     loop2 = TreeLoop("loop2")
     loop2.inputargs = inpargs
     loop2.operations = l
     BaseTest.assert_equal(loop1, loop2)
Exemplo n.º 12
0
 def xxx_test_random_snapshot(self, lst):
     inputargs, ops = lst
     t = Trace(inputargs, metainterp_sd)
     for op in ops:
         newop = FakeOp(t.record_op(op.getopnum(), op.getarglist()))
         newop.orig_op = op
         if newop.is_guard():
             resume.capture_resumedata(op.framestack,
                 None, [], t)
         op.position = newop.get_position()
     inpargs, l, iter = self.unpack(t)
     loop1 = TreeLoop("loop1")
     loop1.inputargs = inputargs
     loop1.operations = ops
     loop2 = TreeLoop("loop2")
     loop2.inputargs = inpargs
     loop2.operations = l
     BaseTest.assert_equal(loop1, loop2)
Exemplo n.º 13
0
def convert_loop_to_trace(loop, metainterp_sd, skip_last=False):
    from rpython.jit.metainterp.opencoder import Trace
    from rpython.jit.metainterp.test.test_opencoder import FakeFrame
    from rpython.jit.metainterp import history, resume

    def get(a):
        if isinstance(a, history.Const):
            return a
        return mapping[a]

    class jitcode:
        index = 200

    inputargs = [
        pick_cls(inparg)(i) for i, inparg in enumerate(loop.inputargs)
    ]
    mapping = {}
    for one, two in zip(loop.inputargs, inputargs):
        mapping[one] = two
    trace = Trace(inputargs, metainterp_sd)
    ops = loop.operations
    if skip_last:
        ops = ops[:-1]
    for op in ops:
        newpos = trace.record_op(op.getopnum(),
                                 [get(arg) for arg in op.getarglist()],
                                 op.getdescr())
        if rop.is_guard(op.getopnum()):
            failargs = []
            if op.getfailargs():
                failargs = [get(arg) for arg in op.getfailargs()]
            frame = FakeFrame(100, jitcode, failargs)
            resume.capture_resumedata([frame], None, [], trace)
        if op.type != 'v':
            newop = pick_cls(op)(newpos)
            mapping[op] = newop
    trace._mapping = mapping  # for tests
    return trace
Exemplo n.º 14
0
 def test_rd_snapshot(self):
     i0, i1 = IntFrontendOp(0), IntFrontendOp(0)
     t = Trace([i0, i1], metainterp_sd)
     add = FakeOp(t.record_op(rop.INT_ADD, [i0, i1]))
     t.record_op(rop.GUARD_FALSE, [add])
     # now we write rd_snapshot and friends
     frame0 = FakeFrame(1, JitCode(2), [i0, i1])
     frame1 = FakeFrame(3, JitCode(4), [i0, i0, add])
     framestack = [frame0]
     resume.capture_resumedata(framestack, None, [], t)
     (i0, i1), l, iter = self.unpack(t)
     assert l[1].opnum == rop.GUARD_FALSE
     assert l[1].framestack[0].boxes == [i0, i1]
     t.record_op(rop.GUARD_FALSE, [add])
     resume.capture_resumedata([frame0, frame1], None, [], t)
     t.record_op(rop.INT_ADD, [add, add])
     (i0, i1), l, iter = self.unpack(t)
     assert l[1].opnum == rop.GUARD_FALSE
     assert l[1].framestack[0].boxes == [i0, i1]
     assert l[2].opnum == rop.GUARD_FALSE
     fstack = l[2].framestack
     assert fstack[0].boxes == [i0, i1]
     assert fstack[1].boxes == [i0, i0, l[0]]
Exemplo n.º 15
0
 def test_rd_snapshot(self):
     i0, i1 = IntFrontendOp(0), IntFrontendOp(0)
     t = Trace([i0, i1], metainterp_sd)
     add = FakeOp(t.record_op(rop.INT_ADD, [i0, i1]))
     t.record_op(rop.GUARD_FALSE, [add])
     # now we write rd_snapshot and friends
     frame0 = FakeFrame(1, JitCode(2), [i0, i1])
     frame1 = FakeFrame(3, JitCode(4), [i0, i0, add])
     framestack = [frame0]
     resume.capture_resumedata(framestack, None, [], t)
     (i0, i1), l, iter = self.unpack(t)
     assert l[1].opnum == rop.GUARD_FALSE
     assert l[1].framestack[0].boxes == [i0, i1]
     t.record_op(rop.GUARD_FALSE, [add])
     resume.capture_resumedata([frame0, frame1], None, [], t)
     t.record_op(rop.INT_ADD, [add, add])
     (i0, i1), l, iter = self.unpack(t)
     assert l[1].opnum == rop.GUARD_FALSE
     assert l[1].framestack[0].boxes == [i0, i1]
     assert l[2].opnum == rop.GUARD_FALSE
     fstack = l[2].framestack
     assert fstack[0].boxes == [i0, i1]
     assert fstack[1].boxes == [i0, i0, l[0]]
Exemplo n.º 16
0
def convert_loop_to_trace(loop, metainterp_sd, skip_last=False):
    from rpython.jit.metainterp.opencoder import Trace
    from rpython.jit.metainterp.test.test_opencoder import FakeFrame
    from rpython.jit.metainterp import history, resume

    def get(a):
        if isinstance(a, history.Const):
            return a
        return mapping[a]

    class jitcode:
        index = 200

    inputargs = [pick_cls(inparg)(i) for i, inparg in
                 enumerate(loop.inputargs)]
    mapping = {}
    for one, two in zip(loop.inputargs, inputargs):
        mapping[one] = two
    trace = Trace(inputargs, metainterp_sd)
    ops = loop.operations
    if skip_last:
        ops = ops[:-1]
    for op in ops:
        newpos = trace.record_op(op.getopnum(), [get(arg) for arg in 
            op.getarglist()], op.getdescr())
        if rop.is_guard(op.getopnum()):
            failargs = []
            if op.getfailargs():
                failargs = [get(arg) for arg in op.getfailargs()]
            frame = FakeFrame(100, jitcode, failargs)
            resume.capture_resumedata([frame], None, [], trace)
        if op.type != 'v':
            newop = pick_cls(op)(newpos)
            mapping[op] = newop
    trace._mapping = mapping # for tests
    return trace