def setinfo_from_preamble(self, op, preamble_info, exported_infos): op = self.get_box_replacement(op) if op.get_forwarded() is not None: return if op.is_constant(): return # nothing we can learn if isinstance(preamble_info, info.PtrInfo): if preamble_info.is_virtual(): op.set_forwarded(preamble_info) self.setinfo_from_preamble_list(preamble_info.all_items(), exported_infos) return if preamble_info.is_constant(): # but op is not op.set_forwarded(preamble_info.getconst()) return if preamble_info.get_descr() is not None: if isinstance(preamble_info, info.StructPtrInfo): op.set_forwarded(info.StructPtrInfo( preamble_info.get_descr())) if isinstance(preamble_info, info.InstancePtrInfo): op.set_forwarded(info.InstancePtrInfo( preamble_info.get_descr())) known_class = preamble_info.get_known_class(self.cpu) if known_class: self.make_constant_class(op, known_class, False) if isinstance(preamble_info, info.ArrayPtrInfo): arr_info = info.ArrayPtrInfo(preamble_info.descr) bound = preamble_info.getlenbound(None).clone() assert isinstance(bound, intutils.IntBound) arr_info.lenbound = bound op.set_forwarded(arr_info) if isinstance(preamble_info, StrPtrInfo): str_info = StrPtrInfo(preamble_info.mode) bound = preamble_info.getlenbound(None).clone() assert isinstance(bound, intutils.IntBound) str_info.lenbound = bound op.set_forwarded(str_info) if preamble_info.is_nonnull(): self.make_nonnull(op) elif isinstance(preamble_info, intutils.IntBound): fix_lo = preamble_info.has_lower and preamble_info.lower >= MININT/2 fix_up = preamble_info.has_upper and preamble_info.upper <= MAXINT/2 if fix_lo or fix_up: intbound = self.getintbound(op) if fix_lo: intbound.has_lower = True intbound.lower = preamble_info.lower if fix_up: intbound.has_upper = True intbound.upper = preamble_info.upper elif isinstance(preamble_info, info.FloatConstInfo): op.set_forwarded(preamble_info._const)
def test_virtual_adder_make_vstruct(): b2s, b4s = [RefFrontendOp(0), RefFrontendOp(0)] c1s = ConstInt(111) storage = Storage() memo = ResumeDataLoopMemo(FakeMetaInterpStaticData()) modifier = ResumeDataVirtualAdder(FakeOptimizer(), storage, storage, None, memo) modifier.liveboxes_from_env = {} modifier.liveboxes = {} modifier.vfieldboxes = {} v2 = info.StructPtrInfo(LLtypeMixin.ssize, is_virtual=True) b2s.set_forwarded(v2) v2.setfield(LLtypeMixin.adescr, b2s, c1s) v2.setfield(LLtypeMixin.abisdescr, b2s, c1s) v2.setfield(LLtypeMixin.bdescr, b2s, b4s) modifier.register_virtual_fields(b2s, [c1s, c1s, b4s]) liveboxes = [] modifier._number_virtuals(liveboxes, 0) dump_storage(storage, liveboxes) storage.rd_consts = memo.consts[:] storage.rd_numb = Numbering([0]) b4t = RefFrontendOp(0) newboxes = _resume_remap( liveboxes, [ #b2s -- virtual b4s ], b4t) # NULL = ConstPtr.value metainterp = MyMetaInterp() reader = ResumeDataFakeReader(storage, newboxes, metainterp) assert len(reader.virtuals_cache.virtuals_ptr_cache) == 1 b2t = reader.decode_ref(tag(0, TAGVIRTUAL)) trace = metainterp.trace expected = [ (rop.NEW, [], b2t.getref_base(), LLtypeMixin.ssize), (rop.SETFIELD_GC, [b2t, c1s], None, LLtypeMixin.adescr), (rop.SETFIELD_GC, [b2t, c1s], None, LLtypeMixin.abisdescr), (rop.SETFIELD_GC, [b2t, b4t], None, LLtypeMixin.bdescr), ] with CompareableConsts(): for x, y in zip(expected, trace): assert x == y # ptr = b2t.getref_base()._obj.container._as_ptr() assert lltype.typeOf(ptr) == lltype.Ptr(LLtypeMixin.S) assert ptr.a == 111 assert ptr.b == lltype.nullptr(LLtypeMixin.NODE)
def test_virtual(self): loop = """ [p1, p2, i3] p0 = new_with_vtable(descr=simpledescr) setfield_gc(p0, i3, descr=simplevalue) jump(p0, p0, i3) """ es, loop, preamble = self.optimize(loop) vs = es.virtual_state assert vs.state[0] is vs.state[1] assert isinstance(vs.state[0], VirtualStateInfo) assert isinstance(vs.state[0].fieldstate[0], NotVirtualStateInfo) assert vs.state[0].fieldstate[0].level == LEVEL_UNKNOWN assert vs.numnotvirtuals == 1 p = InputArgRef() i = InputArgInt() ptrinfo = info.StructPtrInfo(self.nodesize, is_virtual=True) ptrinfo._fields = [i] p.set_forwarded(ptrinfo) vs.make_inputargs([p, p, i], FakeOptimizer())
def ensure_ptr_info_arg0(self, op): from rpython.jit.metainterp.optimizeopt import vstring arg0 = self.get_box_replacement(op.getarg(0)) if arg0.is_constant(): return info.ConstPtrInfo(arg0) opinfo = arg0.get_forwarded() if isinstance(opinfo, info.AbstractVirtualPtrInfo): return opinfo elif opinfo is not None: last_guard_pos = opinfo.get_last_guard_pos() else: last_guard_pos = -1 assert opinfo is None or opinfo.__class__ is info.NonNullPtrInfo opnum = op.opnum if (rop.is_getfield(opnum) or opnum == rop.SETFIELD_GC or opnum == rop.QUASIIMMUT_FIELD): descr = op.getdescr() parent_descr = descr.get_parent_descr() if parent_descr.is_object(): opinfo = info.InstancePtrInfo(parent_descr) else: opinfo = info.StructPtrInfo(parent_descr) opinfo.init_fields(parent_descr, descr.get_index()) elif (rop.is_getarrayitem(opnum) or opnum == rop.SETARRAYITEM_GC or opnum == rop.ARRAYLEN_GC): opinfo = info.ArrayPtrInfo(op.getdescr()) elif opnum in (rop.GUARD_CLASS, rop.GUARD_NONNULL_CLASS): opinfo = info.InstancePtrInfo() elif opnum in (rop.STRLEN, ): opinfo = vstring.StrPtrInfo(vstring.mode_string) elif opnum in (rop.UNICODELEN, ): opinfo = vstring.StrPtrInfo(vstring.mode_unicode) else: assert False, "operations %s unsupported" % op assert isinstance(opinfo, info.NonNullPtrInfo) opinfo.last_guard_pos = last_guard_pos arg0.set_forwarded(opinfo) return opinfo
def make_vstruct(self, structdescr, source_op): opinfo = info.StructPtrInfo(structdescr, is_virtual=True) opinfo.init_fields(structdescr, 0) newop = self.replace_op_with(source_op, source_op.getopnum()) newop.set_forwarded(opinfo) return opinfo