def deserialize_optheap(self, triples_struct, triples_array): for box1, descr, box2 in triples_struct: parent_descr = descr.get_parent_descr() assert parent_descr.is_object() if box1.is_constant(): structinfo = info.ConstPtrInfo(box1) else: structinfo = box1.get_forwarded() if not isinstance(structinfo, info.AbstractVirtualPtrInfo): structinfo = info.InstancePtrInfo(parent_descr) structinfo.init_fields(parent_descr, descr.get_index()) box1.set_forwarded(structinfo) cf = self.field_cache(descr) structinfo.setfield(descr, box1, box2, optheap=self, cf=cf) for box1, index, descr, box2 in triples_array: if box1.is_constant(): arrayinfo = info.ConstPtrInfo(box1) else: arrayinfo = box1.get_forwarded() if not isinstance(arrayinfo, info.AbstractVirtualPtrInfo): arrayinfo = info.ArrayPtrInfo(descr) box1.set_forwarded(arrayinfo) cf = self.arrayitem_cache(descr, index) arrayinfo.setitem(descr, index, box1, box2, optheap=self, cf=cf)
def test_virtual_adder_make_varray(): b2s, b4s = [RefFrontendOp(0), IntFrontendOp(0)] b4s.setint(4) 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.ArrayPtrInfo(LLtypeMixin.arraydescr, size=2, is_virtual=True) b2s.set_forwarded(v2) v2._items = [b4s, c1s] modifier.register_virtual_fields(b2s, [b4s, c1s]) liveboxes = [] modifier._number_virtuals(liveboxes, 0) dump_storage(storage, liveboxes) storage.rd_consts = memo.consts[:] storage.rd_numb = Numbering([0]) # resume b1t, b3t, b4t = [IntFrontendOp(0), IntFrontendOp(0), IntFrontendOp(0)] b1t.setint(11) b3t.setint(33) b4t.setint(44) newboxes = _resume_remap( liveboxes, [ #b2s -- virtual b4s ], b4t) # resume 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_ARRAY, [ConstInt(2)], b2t.getref_base(), LLtypeMixin.arraydescr), (rop.SETARRAYITEM_GC, [b2t, ConstInt(0), b4t], None, LLtypeMixin.arraydescr), (rop.SETARRAYITEM_GC, [b2t, ConstInt(1), c1s], None, LLtypeMixin.arraydescr), ] 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(lltype.GcArray(lltype.Signed)) assert len(ptr) == 2 assert ptr[0] == 44 assert ptr[1] == 111
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 make_varray(self, arraydescr, size, source_op, clear=False): if arraydescr.is_array_of_structs(): assert clear opinfo = info.ArrayStructInfo(arraydescr, size, is_virtual=True) else: const = self.new_const_item(arraydescr) opinfo = info.ArrayPtrInfo(arraydescr, const, size, clear, is_virtual=True) # Replace 'source_op' with a version in which the length is # given as directly a Const, without relying on forwarding. # See test_virtual_array_length_discovered_constant_2. newop = self.replace_op_with(source_op, source_op.getopnum(), args=[ConstInt(size)]) newop.set_forwarded(opinfo) return opinfo
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