Debian Codegraph @

rpython/jit/metainterp/optimizeopt/test/test_short.py

raw symbols SCIP
1
2 """ Short preamble tests
3 """
4
5 import py
6 from rpython.jit.metainterp.resoperation import InputArgInt, ResOperation, rop
7 from rpython.jit.metainterp.optimizeopt.shortpreamble import ShortBoxes
8 from rpython.jit.metainterp.history import AbstractDescr
9
10 class Descr(AbstractDescr):
11 pass
12
13 class Opt(object):
14 def __init__(self, oplist):
15 self.oplist = oplist
16
17 def produce_potential_short_preamble_ops(self, sb):
18 for op in self.oplist:
19 if isinstance(op, tuple):
20 sb.add_heap_op(*op)
21 else:
22 sb.add_pure_op(op)
23
24 class TestShortBoxes(object):
25 def test_pure_ops(self):
26 i0 = InputArgInt()
27 i1 = InputArgInt()
28 op = ResOperation(rop.INT_ADD, [i0, i1])
29 sb = ShortBoxes()
30 short_boxes = sb.create_short_boxes(Opt([op]), [i0, i1], [i0, i1])
31 assert len(short_boxes) == 3
32 short_boxes.sort(key=str)
33 # inputarg
34 for i in range(3):
35 if short_boxes[i].short_op.res is i0:
36 assert short_boxes[i].preamble_op is sb.short_inputargs[0]
37 break
38 else:
39 raise Exception("did not find!")
40 # pure op
41 for i in range(3):
42 if short_boxes[2].preamble_op.getarg(0) is sb.short_inputargs[0]:
43 assert short_boxes[2].short_op.res is op
44 break
45 else:
46 raise Exception("did not find!")
47
48 def test_pure_ops_does_not_work(self):
49 i0 = InputArgInt()
50 i1 = InputArgInt()
51 op = ResOperation(rop.INT_ADD, [i0, i1])
52 sb = ShortBoxes()
53 short_boxes = sb.create_short_boxes(Opt([op]), [i0], [i0])
54 assert len(short_boxes) == 1 # just inparg
55