Author: Carl Friedrich Bolz <cfb...@gmx.de> Branch: optinfo-into-bridges-3 Changeset: r90315:c8e2eb2e3e18 Date: 2017-02-22 22:13 +0100 http://bitbucket.org/pypy/pypy/changeset/c8e2eb2e3e18/
Log: add some comments, some nicer var names, a tiny bit of cleanup diff --git a/rpython/jit/metainterp/optimizeopt/bridgeopt.py b/rpython/jit/metainterp/optimizeopt/bridgeopt.py --- a/rpython/jit/metainterp/optimizeopt/bridgeopt.py +++ b/rpython/jit/metainterp/optimizeopt/bridgeopt.py @@ -3,8 +3,6 @@ from rpython.jit.metainterp import resumecode -# XXX at the moment this is all quite ad-hoc. Could be delegated to the -# different optimization passes # adds the following sections at the end of the resume code: # @@ -22,9 +20,11 @@ # # ---- + +# maybe should be delegated to the optimization classes? + def tag_box(box, liveboxes_from_env, memo): from rpython.jit.metainterp.history import Const - # XXX bit of code duplication (but it's a subset) if isinstance(box, Const): return memo.getconst(box) else: @@ -35,6 +35,8 @@ from rpython.jit.metainterp.resume import NULLREF, TAG_CONST_OFFSET, tagged_eq from rpython.jit.metainterp.history import ConstInt num, tag = untag(tagged) + # NB: the TAGVIRTUAL case can't happen here, because this code runs after + # virtuals are already forced again if tag == TAGCONST: if tagged_eq(tagged, NULLREF): box = cpu.ts.CONST_NULL @@ -49,13 +51,17 @@ return box def serialize_optimizer_knowledge(optimizer, numb_state, liveboxes, liveboxes_from_env, memo): - liveboxes_set = {} + available_boxes = {} for box in liveboxes: if box is not None and box in liveboxes_from_env: - liveboxes_set[box] = None + available_boxes[box] = None metainterp_sd = optimizer.metainterp_sd - # class knowledge + # class knowledge is stored as bits, true meaning the class is known, false + # means unknown. on deserializing we look at the bits, and read the runtime + # class for the known classes (which has to be the same in the bridge) and + # mark that as known. this works for guard_class too: the class is only + # known *after* the guard bitfield = 0 shifts = 0 for box in liveboxes: @@ -72,9 +78,11 @@ if shifts: numb_state.append_int(bitfield << (6 - shifts)) - # heap knowledge + # heap knowledge: we store triples of known heap fields in non-virtual + # structs + # XXX could be extended to arrays if optimizer.optheap: - triples = optimizer.optheap.serialize_optheap(liveboxes_set) + triples = optimizer.optheap.serialize_optheap(available_boxes) # can only encode descrs that have a known index into # metainterp_sd.all_descrs triples = [triple for triple in triples if triple[1].descr_index != -1] @@ -112,6 +120,8 @@ optimizer.make_constant_class(box, cls) # heap knowledge + if not optimizer.optheap: + return length = reader.next_item() result = [] for i in range(length): @@ -122,5 +132,4 @@ tagged = reader.next_item() box2 = decode_box(resumestorage, tagged, liveboxes, metainterp_sd.cpu) result.append((box1, descr, box2)) - if optimizer.optheap: - optimizer.optheap.deserialize_optheap(result) + optimizer.optheap.deserialize_optheap(result) diff --git a/rpython/jit/metainterp/optimizeopt/heap.py b/rpython/jit/metainterp/optimizeopt/heap.py --- a/rpython/jit/metainterp/optimizeopt/heap.py +++ b/rpython/jit/metainterp/optimizeopt/heap.py @@ -694,21 +694,20 @@ self._seen_guard_not_invalidated = True return self.emit(op) - def serialize_optheap(self, liveboxes_set): - # XXX wrong complexity? + def serialize_optheap(self, available_boxes): result = [] for descr, cf in self.cached_fields.iteritems(): if cf._lazy_set: continue # XXX safe default for now parent_descr = descr.get_parent_descr() if not parent_descr.is_object(): - continue + continue # XXX could be extended to non-instance objects for i, box1 in enumerate(cf.cached_structs): - if box1 not in liveboxes_set: + if box1 not in available_boxes: continue structinfo = cf.cached_infos[i] box2 = structinfo.getfield(descr).get_box_replacement() - if isinstance(box2, Const) or box2 in liveboxes_set: + if isinstance(box2, Const) or box2 in available_boxes: result.append((box1, descr, box2)) return result diff --git a/rpython/jit/metainterp/resumecode.py b/rpython/jit/metainterp/resumecode.py --- a/rpython/jit/metainterp/resumecode.py +++ b/rpython/jit/metainterp/resumecode.py @@ -121,12 +121,12 @@ self.items_read = 0 # number of items read def next_item(self): - result, self.cur_pos = numb_next_item(self.code, self.cur_pos) + result, self.cur_pos = numb_next_item(self.code, self.cur_pos) self.items_read += 1 return result def peek(self): - result, _ = numb_next_item(self.code, self.cur_pos) + result, _ = numb_next_item(self.code, self.cur_pos) return result def jump(self, size): diff --git a/rpython/jit/metainterp/test/test_bridgeopt.py b/rpython/jit/metainterp/test/test_bridgeopt.py --- a/rpython/jit/metainterp/test/test_bridgeopt.py +++ b/rpython/jit/metainterp/test/test_bridgeopt.py @@ -97,7 +97,6 @@ serialize_optimizer_knowledge(optimizer, numb_state, liveboxes, {}, None) - #assert numb_state.current[:numb_state._pos] == [1, 0b0100000, 0] assert len(numb_state.create_numbering().code) == 2 + math.ceil(len(refboxes) / 6.0) dct = {box: cls _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit