def test_setfield_forced_virtual(self): loop = """ [p1, p2] i1 = getfield_gc_i(p1, descr=valuedescr) setfield_gc(p2, i1, descr=valuedescr) p3 = new_with_vtable(descr=nodesize) jump(p2, p3) """ es, loop, preamble = self.optimize(loop) sb = ShortPreambleBuilder(loop.inputargs, es.short_boxes, es.short_inputargs, es.exported_infos) short_boxes = [ box for box in es.short_boxes if not isinstance(box.short_op, ShortInputArg) ] op = short_boxes[0].short_op.res pop = sb.use_box(op, short_boxes[0].preamble_op, FakeOptimizer()) sb.add_preamble_op(PreambleOp(op, pop, False)) exp_short = """ [p0, p1] guard_nonnull(p0) [] guard_subclass(p0, ConstClass(node_vtable)) [] i1 = getfield_gc_i(p0, descr=valuedescr) jump(i1) """ self.compare_short(sb.build_short_preamble(), exp_short)
def test_setfield_forced_virtual(self): loop = """ [p1, p2] i1 = getfield_gc_i(p1, descr=valuedescr) setfield_gc(p2, i1, descr=valuedescr) p3 = new_with_vtable(descr=nodesize) jump(p2, p3) """ es, loop, preamble = self.optimize(loop) sb = ShortPreambleBuilder(loop.inputargs, es.short_boxes, es.short_inputargs, es.exported_infos) short_boxes = [box for box in es.short_boxes if not isinstance(box.short_op, ShortInputArg)] op = short_boxes[0].short_op.res pop = sb.use_box(op, short_boxes[0].preamble_op, FakeOptimizer()) sb.add_preamble_op(PreambleOp(op, pop, False)) exp_short = """ [p0, p1] guard_nonnull(p0) [] guard_subclass(p0, ConstClass(node_vtable)) [] i1 = getfield_gc_i(p0, descr=valuedescr) jump(i1) """ self.compare_short(sb.build_short_preamble(), exp_short)
def test_short_boxes_heapcache(self): loop = """ [p0, i1] i0 = getfield_gc_i(p0, descr=valuedescr) jump(p0, i1) """ es, loop, preamble = self.optimize(loop) op = preamble.operations[0] short_boxes = [ box for box in es.short_boxes if not isinstance(box.short_op, ShortInputArg) ] assert len(short_boxes) == 1 assert short_boxes[0].short_op.res is op sb = ShortPreambleBuilder(loop.inputargs, es.short_boxes, es.short_inputargs, es.exported_infos, FakeOptimizer()) op = preamble.operations[0] short_op = sb.use_box(op, short_boxes[0].preamble_op, FakeOptimizer()) sb.add_preamble_op(PreambleOp(op, short_op, False)) exp_short = """ [p0, i1] guard_nonnull(p0) [] guard_subclass(p0, ConstClass(node_vtable)) [] i0 = getfield_gc_i(p0, descr=valuedescr) jump(i0) """ self.compare_short(sb.build_short_preamble(), exp_short)
def test_short_boxes_heapcache(self): loop = """ [p0, i1] i0 = getfield_gc_i(p0, descr=valuedescr) jump(p0, i1) """ es, loop, preamble = self.optimize(loop) op = preamble.operations[0] short_boxes = [box for box in es.short_boxes if not isinstance(box.short_op, ShortInputArg)] assert len(short_boxes) == 1 assert short_boxes[0].short_op.res is op sb = ShortPreambleBuilder(loop.inputargs, es.short_boxes, es.short_inputargs, es.exported_infos, FakeOptimizer()) op = preamble.operations[0] short_op = sb.use_box(op, short_boxes[0].preamble_op, FakeOptimizer()) sb.add_preamble_op(PreambleOp(op, short_op, False)) exp_short = """ [p0, i1] guard_nonnull(p0) [] guard_subclass(p0, ConstClass(node_vtable)) [] i0 = getfield_gc_i(p0, descr=valuedescr) jump(i0) """ self.compare_short(sb.build_short_preamble(), exp_short)