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_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_simple(self): loop = """ [i0] i1 = int_add(i0, 1) guard_value(i1, 1) [] jump(i1) """ es, loop, preamble = self.optimize(loop) vs = es.virtual_state assert isinstance(vs.state[0], NotVirtualStateInfo) # the virtual state is constant, so we don't need to have it in # inputargs assert vs.make_inputargs([1], FakeOptimizer()) == [] assert vs.state[0].level == LEVEL_CONSTANT # we have exported values for i1, which happens to be an inputarg sb = ShortPreambleBuilder([], es.short_boxes, es.short_inputargs, es.exported_infos) sp = sb.build_short_preamble() exp = """ [] jump() """ self.compare_short(sp, exp)