PageRenderTime 231ms CodeModel.GetById 110ms app.highlight 67ms RepoModel.GetById 29ms app.codeStats 1ms

/pypy/jit/metainterp/optimizeopt/test/test_util.py

https://bitbucket.org/pypy/pypy/
Python | 498 lines | 494 code | 4 blank | 0 comment | 4 complexity | 596a444a2d082f4551d64a45e935178f MD5 | raw file
  1import py, random
  2
  3from pypy.rpython.lltypesystem import lltype, llmemory, rclass, rstr
  4from pypy.rpython.ootypesystem import ootype
  5from pypy.rpython.lltypesystem.rclass import OBJECT, OBJECT_VTABLE
  6from pypy.rpython.rclass import FieldListAccessor, IR_QUASIIMMUTABLE
  7
  8from pypy.jit.backend.llgraph import runner
  9from pypy.jit.metainterp.history import (BoxInt, BoxPtr, ConstInt, ConstPtr,
 10                                         Const, TreeLoop, BoxObj,
 11                                         ConstObj, AbstractDescr,
 12                                         JitCellToken, TargetToken)
 13from pypy.jit.metainterp.optimizeopt.util import sort_descrs, equaloplists
 14from pypy.jit.metainterp.optimize import InvalidLoop
 15from pypy.jit.codewriter.effectinfo import EffectInfo
 16from pypy.jit.codewriter.heaptracker import register_known_gctype, adr2int
 17from pypy.jit.tool.oparser import parse, pure_parse
 18from pypy.jit.metainterp.quasiimmut import QuasiImmutDescr
 19from pypy.jit.metainterp import compile, resume, history
 20from pypy.jit.metainterp.jitprof import EmptyProfiler
 21from pypy.config.pypyoption import get_pypy_config
 22from pypy.jit.metainterp.resoperation import rop, opname, ResOperation
 23from pypy.jit.metainterp.optimizeopt.unroll import Inliner
 24
 25def test_sort_descrs():
 26    class PseudoDescr(AbstractDescr):
 27        def __init__(self, n):
 28            self.n = n
 29        def sort_key(self):
 30            return self.n
 31    for i in range(17):
 32        lst = [PseudoDescr(j) for j in range(i)]
 33        lst2 = lst[:]
 34        random.shuffle(lst2)
 35        sort_descrs(lst2)
 36        assert lst2 == lst
 37
 38def test_equaloplists():
 39    ops = """
 40    [i0]
 41    i1 = int_add(i0, 1)
 42    i2 = int_add(i1, 1)
 43    guard_true(i1) [i2]
 44    jump(i1)
 45    """
 46    namespace = {}
 47    loop1 = pure_parse(ops, namespace=namespace)
 48    loop2 = pure_parse(ops, namespace=namespace)
 49    loop3 = pure_parse(ops.replace("i2 = int_add", "i2 = int_sub"),
 50                       namespace=namespace)
 51    assert equaloplists(loop1.operations, loop2.operations)
 52    py.test.raises(AssertionError,
 53                   "equaloplists(loop1.operations, loop3.operations)")
 54
 55def test_equaloplists_fail_args():
 56    ops = """
 57    [i0]
 58    i1 = int_add(i0, 1)
 59    i2 = int_add(i1, 1)
 60    guard_true(i1) [i2, i1]
 61    jump(i1)
 62    """
 63    namespace = {}
 64    loop1 = pure_parse(ops, namespace=namespace)
 65    loop2 = pure_parse(ops.replace("[i2, i1]", "[i1, i2]"),
 66                       namespace=namespace)
 67    py.test.raises(AssertionError,
 68                   "equaloplists(loop1.operations, loop2.operations)")
 69    assert equaloplists(loop1.operations, loop2.operations,
 70                        strict_fail_args=False)
 71    loop3 = pure_parse(ops.replace("[i2, i1]", "[i2, i0]"),
 72                       namespace=namespace)
 73    py.test.raises(AssertionError,
 74                   "equaloplists(loop1.operations, loop3.operations)")
 75
 76# ____________________________________________________________
 77
 78class LLtypeMixin(object):
 79    type_system = 'lltype'
 80
 81    def get_class_of_box(self, box):
 82        return box.getref(rclass.OBJECTPTR).typeptr
 83
 84    node_vtable = lltype.malloc(OBJECT_VTABLE, immortal=True)
 85    node_vtable.name = rclass.alloc_array_name('node')
 86    node_vtable_adr = llmemory.cast_ptr_to_adr(node_vtable)
 87    node_vtable2 = lltype.malloc(OBJECT_VTABLE, immortal=True)
 88    node_vtable2.name = rclass.alloc_array_name('node2')
 89    node_vtable_adr2 = llmemory.cast_ptr_to_adr(node_vtable2)
 90    cpu = runner.LLtypeCPU(None)
 91
 92    NODE = lltype.GcForwardReference()
 93    NODE.become(lltype.GcStruct('NODE', ('parent', OBJECT),
 94                                        ('value', lltype.Signed),
 95                                        ('floatval', lltype.Float),
 96                                        ('next', lltype.Ptr(NODE))))
 97    NODE2 = lltype.GcStruct('NODE2', ('parent', NODE),
 98                                     ('other', lltype.Ptr(NODE)))
 99    node = lltype.malloc(NODE)
100    node.parent.typeptr = node_vtable
101    node2 = lltype.malloc(NODE2)
102    node2.parent.parent.typeptr = node_vtable2
103    nodebox = BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, node))
104    myptr = nodebox.value
105    myptr2 = lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(NODE))
106    nullptr = lltype.nullptr(llmemory.GCREF.TO)
107    nodebox2 = BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, node2))
108    nodesize = cpu.sizeof(NODE)
109    nodesize2 = cpu.sizeof(NODE2)
110    valuedescr = cpu.fielddescrof(NODE, 'value')
111    floatdescr = cpu.fielddescrof(NODE, 'floatval')
112    nextdescr = cpu.fielddescrof(NODE, 'next')
113    otherdescr = cpu.fielddescrof(NODE2, 'other')
114
115    accessor = FieldListAccessor()
116    accessor.initialize(None, {'inst_field': IR_QUASIIMMUTABLE})
117    QUASI = lltype.GcStruct('QUASIIMMUT', ('inst_field', lltype.Signed),
118                            ('mutate_field', rclass.OBJECTPTR),
119                            hints={'immutable_fields': accessor})
120    quasisize = cpu.sizeof(QUASI)
121    quasi = lltype.malloc(QUASI, immortal=True)
122    quasi.inst_field = -4247
123    quasifielddescr = cpu.fielddescrof(QUASI, 'inst_field')
124    quasibox = BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, quasi))
125    quasiimmutdescr = QuasiImmutDescr(cpu, quasibox,
126                                      quasifielddescr,
127                                      cpu.fielddescrof(QUASI, 'mutate_field'))
128
129    NODEOBJ = lltype.GcStruct('NODEOBJ', ('parent', OBJECT),
130                                         ('ref', lltype.Ptr(OBJECT)))
131    nodeobj = lltype.malloc(NODEOBJ)
132    nodeobjvalue = lltype.cast_opaque_ptr(llmemory.GCREF, nodeobj)
133    refdescr = cpu.fielddescrof(NODEOBJ, 'ref')
134
135    INTOBJ_NOIMMUT = lltype.GcStruct('INTOBJ_NOIMMUT', ('parent', OBJECT),
136                                                ('intval', lltype.Signed))
137    INTOBJ_IMMUT = lltype.GcStruct('INTOBJ_IMMUT', ('parent', OBJECT),
138                                            ('intval', lltype.Signed),
139                                            hints={'immutable': True})
140    intobj_noimmut_vtable = lltype.malloc(OBJECT_VTABLE, immortal=True)
141    intobj_immut_vtable = lltype.malloc(OBJECT_VTABLE, immortal=True)
142    noimmut_intval = cpu.fielddescrof(INTOBJ_NOIMMUT, 'intval')
143    immut_intval = cpu.fielddescrof(INTOBJ_IMMUT, 'intval')
144
145    PTROBJ_IMMUT = lltype.GcStruct('PTROBJ_IMMUT', ('parent', OBJECT),
146                                            ('ptrval', lltype.Ptr(OBJECT)),
147                                            hints={'immutable': True})
148    ptrobj_immut_vtable = lltype.malloc(OBJECT_VTABLE, immortal=True)
149    immut_ptrval = cpu.fielddescrof(PTROBJ_IMMUT, 'ptrval')
150
151    arraydescr = cpu.arraydescrof(lltype.GcArray(lltype.Signed))
152    floatarraydescr = cpu.arraydescrof(lltype.GcArray(lltype.Float))
153
154    # a GcStruct not inheriting from OBJECT
155    S = lltype.GcStruct('TUPLE', ('a', lltype.Signed), ('b', lltype.Ptr(NODE)))
156    ssize = cpu.sizeof(S)
157    adescr = cpu.fielddescrof(S, 'a')
158    bdescr = cpu.fielddescrof(S, 'b')
159    sbox = BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(S)))
160    arraydescr2 = cpu.arraydescrof(lltype.GcArray(lltype.Ptr(S)))
161
162    T = lltype.GcStruct('TUPLE',
163                        ('c', lltype.Signed),
164                        ('d', lltype.Ptr(lltype.GcArray(lltype.Ptr(NODE)))))
165    tsize = cpu.sizeof(T)
166    cdescr = cpu.fielddescrof(T, 'c')
167    ddescr = cpu.fielddescrof(T, 'd')
168    arraydescr3 = cpu.arraydescrof(lltype.GcArray(lltype.Ptr(NODE)))
169
170    U = lltype.GcStruct('U',
171                        ('parent', OBJECT),
172                        ('one', lltype.Ptr(lltype.GcArray(lltype.Ptr(NODE)))))
173    u_vtable = lltype.malloc(OBJECT_VTABLE, immortal=True)
174    u_vtable_adr = llmemory.cast_ptr_to_adr(u_vtable)
175    usize = cpu.sizeof(U)
176    onedescr = cpu.fielddescrof(U, 'one')
177
178    FUNC = lltype.FuncType([lltype.Signed], lltype.Signed)
179    plaincalldescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT,
180                                     EffectInfo.MOST_GENERAL)
181    nonwritedescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT,
182                                    EffectInfo([], [], [], []))
183    writeadescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT,
184                                  EffectInfo([], [], [adescr], []))
185    writearraydescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT,
186                                  EffectInfo([], [], [adescr], [arraydescr]))
187    readadescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT,
188                                 EffectInfo([adescr], [], [], []))
189    mayforcevirtdescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT,
190                 EffectInfo([nextdescr], [], [], [],
191                            EffectInfo.EF_FORCES_VIRTUAL_OR_VIRTUALIZABLE,
192                            can_invalidate=True))
193    arraycopydescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT,
194             EffectInfo([], [arraydescr], [], [arraydescr],
195                        EffectInfo.EF_CANNOT_RAISE,
196                        oopspecindex=EffectInfo.OS_ARRAYCOPY))
197
198
199    # array of structs (complex data)
200    complexarray = lltype.GcArray(
201        lltype.Struct("complex",
202            ("real", lltype.Float),
203            ("imag", lltype.Float),
204        )
205    )
206    complexarraydescr = cpu.arraydescrof(complexarray)
207    complexrealdescr = cpu.interiorfielddescrof(complexarray, "real")
208    compleximagdescr = cpu.interiorfielddescrof(complexarray, "imag")
209
210    for _name, _os in [
211        ('strconcatdescr',               'OS_STR_CONCAT'),
212        ('strslicedescr',                'OS_STR_SLICE'),
213        ('strequaldescr',                'OS_STR_EQUAL'),
214        ('streq_slice_checknull_descr',  'OS_STREQ_SLICE_CHECKNULL'),
215        ('streq_slice_nonnull_descr',    'OS_STREQ_SLICE_NONNULL'),
216        ('streq_slice_char_descr',       'OS_STREQ_SLICE_CHAR'),
217        ('streq_nonnull_descr',          'OS_STREQ_NONNULL'),
218        ('streq_nonnull_char_descr',     'OS_STREQ_NONNULL_CHAR'),
219        ('streq_checknull_char_descr',   'OS_STREQ_CHECKNULL_CHAR'),
220        ('streq_lengthok_descr',         'OS_STREQ_LENGTHOK'),
221        ]:
222        _oopspecindex = getattr(EffectInfo, _os)
223        locals()[_name] = \
224            cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT,
225                EffectInfo([], [], [], [], EffectInfo.EF_CANNOT_RAISE,
226                           oopspecindex=_oopspecindex))
227        #
228        _oopspecindex = getattr(EffectInfo, _os.replace('STR', 'UNI'))
229        locals()[_name.replace('str', 'unicode')] = \
230            cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT,
231                EffectInfo([], [], [], [], EffectInfo.EF_CANNOT_RAISE,
232                           oopspecindex=_oopspecindex))
233
234    s2u_descr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT,
235            EffectInfo([], [], [], [], oopspecindex=EffectInfo.OS_STR2UNICODE))
236    #
237
238    class LoopToken(AbstractDescr):
239        pass
240    asmdescr = LoopToken() # it can be whatever, it's not a descr though
241
242    from pypy.jit.metainterp.virtualref import VirtualRefInfo
243    class FakeWarmRunnerDesc:
244        pass
245    FakeWarmRunnerDesc.cpu = cpu
246    vrefinfo = VirtualRefInfo(FakeWarmRunnerDesc)
247    virtualtokendescr = vrefinfo.descr_virtual_token
248    virtualforceddescr = vrefinfo.descr_forced
249    jit_virtual_ref_vtable = vrefinfo.jit_virtual_ref_vtable
250    jvr_vtable_adr = llmemory.cast_ptr_to_adr(jit_virtual_ref_vtable)
251
252    register_known_gctype(cpu, node_vtable,  NODE)
253    register_known_gctype(cpu, node_vtable2, NODE2)
254    register_known_gctype(cpu, u_vtable,     U)
255    register_known_gctype(cpu, jit_virtual_ref_vtable,vrefinfo.JIT_VIRTUAL_REF)
256    register_known_gctype(cpu, intobj_noimmut_vtable, INTOBJ_NOIMMUT)
257    register_known_gctype(cpu, intobj_immut_vtable,   INTOBJ_IMMUT)
258    register_known_gctype(cpu, ptrobj_immut_vtable,   PTROBJ_IMMUT)
259
260    namespace = locals()
261
262class OOtypeMixin_xxx_disabled(object):
263    type_system = 'ootype'
264
265##    def get_class_of_box(self, box):
266##        root = box.getref(ootype.ROOT)
267##        return ootype.classof(root)
268
269##    cpu = runner.OOtypeCPU(None)
270##    NODE = ootype.Instance('NODE', ootype.ROOT, {})
271##    NODE._add_fields({'value': ootype.Signed,
272##                      'floatval' : ootype.Float,
273##                      'next': NODE})
274##    NODE2 = ootype.Instance('NODE2', NODE, {'other': NODE})
275
276##    node_vtable = ootype.runtimeClass(NODE)
277##    node_vtable_adr = ootype.cast_to_object(node_vtable)
278##    node_vtable2 = ootype.runtimeClass(NODE2)
279##    node_vtable_adr2 = ootype.cast_to_object(node_vtable2)
280
281##    node = ootype.new(NODE)
282##    nodebox = BoxObj(ootype.cast_to_object(node))
283##    myptr = nodebox.value
284##    myptr2 = ootype.cast_to_object(ootype.new(NODE))
285##    nodebox2 = BoxObj(ootype.cast_to_object(node))
286##    valuedescr = cpu.fielddescrof(NODE, 'value')
287##    floatdescr = cpu.fielddescrof(NODE, 'floatval')
288##    nextdescr = cpu.fielddescrof(NODE, 'next')
289##    otherdescr = cpu.fielddescrof(NODE2, 'other')
290##    nodesize = cpu.typedescrof(NODE)
291##    nodesize2 = cpu.typedescrof(NODE2)
292
293##    arraydescr = cpu.arraydescrof(ootype.Array(ootype.Signed))
294##    floatarraydescr = cpu.arraydescrof(ootype.Array(ootype.Float))
295
296##    # a plain Record
297##    S = ootype.Record({'a': ootype.Signed, 'b': NODE})
298##    ssize = cpu.typedescrof(S)
299##    adescr = cpu.fielddescrof(S, 'a')
300##    bdescr = cpu.fielddescrof(S, 'b')
301##    sbox = BoxObj(ootype.cast_to_object(ootype.new(S)))
302##    arraydescr2 = cpu.arraydescrof(ootype.Array(S))
303
304##    T = ootype.Record({'c': ootype.Signed,
305##                       'd': ootype.Array(NODE)})
306##    tsize = cpu.typedescrof(T)
307##    cdescr = cpu.fielddescrof(T, 'c')
308##    ddescr = cpu.fielddescrof(T, 'd')
309##    arraydescr3 = cpu.arraydescrof(ootype.Array(NODE))
310
311##    U = ootype.Instance('U', ootype.ROOT, {'one': ootype.Array(NODE)})
312##    usize = cpu.typedescrof(U)
313##    onedescr = cpu.fielddescrof(U, 'one')
314##    u_vtable = ootype.runtimeClass(U)
315##    u_vtable_adr = ootype.cast_to_object(u_vtable)
316
317##    # force a consistent order
318##    valuedescr.sort_key()
319##    nextdescr.sort_key()
320##    adescr.sort_key()
321##    bdescr.sort_key()
322
323##    FUNC = lltype.FuncType([lltype.Signed], lltype.Signed)
324##    nonwritedescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT) # XXX fix ootype
325
326##    cpu.class_sizes = {node_vtable_adr: cpu.typedescrof(NODE),
327##                       node_vtable_adr2: cpu.typedescrof(NODE2),
328##                       u_vtable_adr: cpu.typedescrof(U)}
329##    namespace = locals()
330
331# ____________________________________________________________
332
333
334
335class Fake(object):
336    failargs_limit = 1000
337    storedebug = None
338
339
340class FakeMetaInterpStaticData(object):
341
342    def __init__(self, cpu):
343        self.cpu = cpu
344        self.profiler = EmptyProfiler()
345        self.options = Fake()
346        self.globaldata = Fake()
347        self.config = get_pypy_config(translating=True)
348        self.config.translation.jit_ffi = True
349
350    class logger_noopt:
351        @classmethod
352        def log_loop(*args):
353            pass
354
355    class warmrunnerdesc:
356        class memory_manager:
357            retrace_limit = 5
358            max_retrace_guards = 15
359
360class Storage(compile.ResumeGuardDescr):
361    "for tests."
362    def __init__(self, metainterp_sd=None, original_greenkey=None):
363        self.metainterp_sd = metainterp_sd
364        self.original_greenkey = original_greenkey
365    def store_final_boxes(self, op, boxes):
366        op.setfailargs(boxes)
367    def __eq__(self, other):
368        return type(self) is type(other)      # xxx obscure
369    def clone_if_mutable(self):
370        res = Storage(self.metainterp_sd, self.original_greenkey)
371        self.copy_all_attributes_into(res)
372        return res
373
374def _sortboxes(boxes):
375    _kind2count = {history.INT: 1, history.REF: 2, history.FLOAT: 3}
376    return sorted(boxes, key=lambda box: _kind2count[box.type])
377
378class BaseTest(object):
379
380    def parse(self, s, boxkinds=None):
381        return parse(s, self.cpu, self.namespace,
382                     type_system=self.type_system,
383                     boxkinds=boxkinds,
384                     invent_fail_descr=self.invent_fail_descr)
385
386    def invent_fail_descr(self, model, fail_args):
387        if fail_args is None:
388            return None
389        descr = Storage()
390        descr.rd_frame_info_list = resume.FrameInfo(None, "code", 11)
391        descr.rd_snapshot = resume.Snapshot(None, _sortboxes(fail_args))
392        return descr
393
394    def assert_equal(self, optimized, expected, text_right=None):
395        from pypy.jit.metainterp.optimizeopt.util import equaloplists
396        assert len(optimized.inputargs) == len(expected.inputargs)
397        remap = {}
398        for box1, box2 in zip(optimized.inputargs, expected.inputargs):
399            assert box1.__class__ == box2.__class__
400            remap[box2] = box1
401        assert equaloplists(optimized.operations,
402                            expected.operations, False, remap, text_right)
403
404    def _do_optimize_loop(self, loop, call_pure_results):
405        from pypy.jit.metainterp.optimizeopt import optimize_trace
406        from pypy.jit.metainterp.optimizeopt.util import args_dict
407
408        self.loop = loop
409        loop.call_pure_results = args_dict()
410        if call_pure_results is not None:
411            for k, v in call_pure_results.items():
412                loop.call_pure_results[list(k)] = v
413        metainterp_sd = FakeMetaInterpStaticData(self.cpu)
414        if hasattr(self, 'vrefinfo'):
415            metainterp_sd.virtualref_info = self.vrefinfo
416        if hasattr(self, 'callinfocollection'):
417            metainterp_sd.callinfocollection = self.callinfocollection
418        #
419        optimize_trace(metainterp_sd, loop, self.enable_opts)
420
421    def unroll_and_optimize(self, loop, call_pure_results=None):
422        operations =  loop.operations
423        jumpop = operations[-1]
424        assert jumpop.getopnum() == rop.JUMP
425        inputargs = loop.inputargs
426
427        jump_args = jumpop.getarglist()[:]
428        operations = operations[:-1]
429        cloned_operations = [op.clone() for op in operations]
430
431        preamble = TreeLoop('preamble')
432        preamble.inputargs = inputargs
433        preamble.resume_at_jump_descr = FakeDescrWithSnapshot()
434
435        token = JitCellToken() 
436        preamble.operations = [ResOperation(rop.LABEL, inputargs, None, descr=TargetToken(token))] + \
437                              operations +  \
438                              [ResOperation(rop.LABEL, jump_args, None, descr=token)]
439        self._do_optimize_loop(preamble, call_pure_results)
440
441        assert preamble.operations[-1].getopnum() == rop.LABEL
442
443        inliner = Inliner(inputargs, jump_args)
444        loop.resume_at_jump_descr = preamble.resume_at_jump_descr
445        loop.operations = [preamble.operations[-1]] + \
446                          [inliner.inline_op(op, clone=False) for op in cloned_operations] + \
447                          [ResOperation(rop.JUMP, [inliner.inline_arg(a) for a in jump_args],
448                                        None, descr=token)] 
449                          #[inliner.inline_op(jumpop)]
450        assert loop.operations[-1].getopnum() == rop.JUMP
451        assert loop.operations[0].getopnum() == rop.LABEL
452        loop.inputargs = loop.operations[0].getarglist()
453
454        self._do_optimize_loop(loop, call_pure_results)
455        extra_same_as = []
456        while loop.operations[0].getopnum() != rop.LABEL:
457            extra_same_as.append(loop.operations[0])
458            del loop.operations[0]
459
460        # Hack to prevent random order of same_as ops
461        extra_same_as.sort(key=lambda op: str(preamble.operations).find(str(op.getarg(0))))
462
463        for op in extra_same_as:
464            preamble.operations.insert(-1, op)
465
466        return preamble
467        
468
469class FakeDescr(compile.ResumeGuardDescr):
470    def clone_if_mutable(self):
471        return FakeDescr()
472    def __eq__(self, other):
473        return isinstance(other, FakeDescr)
474
475class FakeDescrWithSnapshot(compile.ResumeGuardDescr):
476    class rd_snapshot:
477        class prev:
478            prev = None
479            boxes = []
480        boxes = []
481    def clone_if_mutable(self):
482        return FakeDescrWithSnapshot()
483    def __eq__(self, other):
484        return isinstance(other, Storage) or isinstance(other, FakeDescrWithSnapshot)
485
486
487def convert_old_style_to_targets(loop, jump):
488    newloop = TreeLoop(loop.name)
489    newloop.inputargs = loop.inputargs
490    newloop.operations = [ResOperation(rop.LABEL, loop.inputargs, None, descr=FakeDescr())] + \
491                      loop.operations
492    if not jump:
493        assert newloop.operations[-1].getopnum() == rop.JUMP
494        newloop.operations[-1] = ResOperation(rop.LABEL, newloop.operations[-1].getarglist(), None, descr=FakeDescr())
495    return newloop
496
497# ____________________________________________________________
498