Author: Maciej Fijalkowski <fij...@gmail.com> Branch: Changeset: r75090:c9019489d422 Date: 2014-12-23 19:56 +0200 http://bitbucket.org/pypy/pypy/changeset/c9019489d422/
Log: small level as a tag. that way we can store a few bits for future use (not used yet) 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 @@ -4,7 +4,8 @@ from rpython.jit.metainterp.optimizeopt.util import args_dict from rpython.jit.metainterp.history import Const from rpython.jit.metainterp.jitexc import JitException -from rpython.jit.metainterp.optimizeopt.optimizer import Optimization, MODE_ARRAY, LEVEL_KNOWNCLASS, REMOVED, LEVEL_CONSTANT +from rpython.jit.metainterp.optimizeopt.optimizer import Optimization,\ + MODE_ARRAY, LEVEL_KNOWNCLASS, REMOVED from rpython.jit.metainterp.optimizeopt.util import make_dispatcher_method from rpython.jit.metainterp.optimize import InvalidLoop from rpython.jit.metainterp.resoperation import rop, ResOperation @@ -137,7 +138,7 @@ continue value = optimizer.getvalue(op.getarg(0)) if value in optimizer.opaque_pointers: - if value.level < LEVEL_KNOWNCLASS: + if value.getlevel() < LEVEL_KNOWNCLASS: continue if op.getopnum() != rop.SETFIELD_GC and op.getopnum() != rop.GETFIELD_GC: continue diff --git a/rpython/jit/metainterp/optimizeopt/optimizer.py b/rpython/jit/metainterp/optimizeopt/optimizer.py --- a/rpython/jit/metainterp/optimizeopt/optimizer.py +++ b/rpython/jit/metainterp/optimizeopt/optimizer.py @@ -13,11 +13,16 @@ from rpython.rlib.debug import debug_print from rpython.rlib.objectmodel import specialize +""" The tag field on OptValue has a following meaning: -LEVEL_UNKNOWN = '\x00' -LEVEL_NONNULL = '\x01' -LEVEL_KNOWNCLASS = '\x02' # might also mean KNOWNARRAYDESCR, for arrays -LEVEL_CONSTANT = '\x03' +lower two bits are LEVEL +next 16 bits is the position in the original list, 0 if unknown or a constant +""" + +LEVEL_UNKNOWN = 0 +LEVEL_NONNULL = 1 +LEVEL_KNOWNCLASS = 2 # might also mean KNOWNARRAYDESCR, for arrays +LEVEL_CONSTANT = 3 MODE_ARRAY = '\x00' MODE_STR = '\x01' @@ -41,35 +46,41 @@ class OptValue(object): __metaclass__ = extendabletype - _attrs_ = ('box', 'level') + _attrs_ = ('box', '_tag') - level = LEVEL_UNKNOWN + _tag = 0 def __init__(self, box, level=None, known_class=None, intbound=None): self.box = box if level is not None: - self.level = level + self._tag = level if isinstance(box, Const): self.make_constant(box) # invariant: box is a Const if and only if level == LEVEL_CONSTANT + def getlevel(self): + return self._tag & 0x3 + + def setlevel(self, level): + self._tag = (self._tag & (~0x3)) | level + def import_from(self, other, optimizer): - if self.level == LEVEL_CONSTANT: - assert other.level == LEVEL_CONSTANT + if self.getlevel() == LEVEL_CONSTANT: + assert other.getlevel() == LEVEL_CONSTANT assert other.box.same_constant(self.box) return - assert self.level <= LEVEL_NONNULL - if other.level == LEVEL_CONSTANT: + assert self.getlevel() <= LEVEL_NONNULL + if other.getlevel() == LEVEL_CONSTANT: self.make_constant(other.get_key_box()) - elif other.level == LEVEL_KNOWNCLASS: + elif other.getlevel() == LEVEL_KNOWNCLASS: self.make_constant_class(other.get_known_class(), None) else: - if other.level == LEVEL_NONNULL: + if other.getlevel() == LEVEL_NONNULL: self.ensure_nonnull() def make_guards(self, box): - if self.level == LEVEL_CONSTANT: + if self.getlevel() == LEVEL_CONSTANT: op = ResOperation(rop.GUARD_VALUE, [box, self.box], None) return [op] return [] @@ -77,7 +88,7 @@ def copy_from(self, other_value): assert isinstance(other_value, OptValue) self.box = other_value.box - self.level = other_value.level + self._tag = other_value._tag def force_box(self, optforce): return self.box @@ -105,7 +116,7 @@ assert 0, "unreachable" def is_constant(self): - return self.level == LEVEL_CONSTANT + return self.getlevel() == LEVEL_CONSTANT def is_null(self): if self.is_constant(): @@ -122,7 +133,7 @@ return self is other def is_nonnull(self): - level = self.level + level = self.getlevel() if level == LEVEL_NONNULL or level == LEVEL_KNOWNCLASS: return True elif level == LEVEL_CONSTANT: @@ -133,8 +144,8 @@ return False def ensure_nonnull(self): - if self.level < LEVEL_NONNULL: - self.level = LEVEL_NONNULL + if self.getlevel() < LEVEL_NONNULL: + self.setlevel(LEVEL_NONNULL) def is_virtual(self): # Don't check this with 'isinstance(_, VirtualValue)'! @@ -179,7 +190,7 @@ """Replace 'self.box' with a Const box.""" assert isinstance(constbox, Const) self.box = constbox - self.level = LEVEL_CONSTANT + self.setlevel(LEVEL_CONSTANT) def get_last_guard(self): return None @@ -212,7 +223,7 @@ assert isinstance(other_value, PtrOptValue) self.box = other_value.box self.known_class = other_value.known_class - self.level = other_value.level + self._tag = other_value._tag self.last_guard = other_value.last_guard self.lenbound = other_value.lenbound @@ -225,19 +236,19 @@ self.lenbound = LenBound(mode, descr, IntLowerBound(val + 1)) def make_nonnull(self, guardop): - assert self.level < LEVEL_NONNULL - self.level = LEVEL_NONNULL + assert self.getlevel() < LEVEL_NONNULL + self.setlevel(LEVEL_NONNULL) self.last_guard = guardop def make_constant_class(self, classbox, guardop): - assert self.level < LEVEL_KNOWNCLASS + assert self.getlevel() < LEVEL_KNOWNCLASS self.known_class = classbox - self.level = LEVEL_KNOWNCLASS + self.setlevel(LEVEL_KNOWNCLASS) self.last_guard = guardop def import_from(self, other, optimizer): OptValue.import_from(self, other, optimizer) - if self.level != LEVEL_CONSTANT: + if self.getlevel() != LEVEL_CONSTANT: if other.getlenbound(): if self.lenbound: assert other.getlenbound().mode == self.lenbound.mode @@ -248,16 +259,17 @@ def make_guards(self, box): guards = [] - if self.level == LEVEL_CONSTANT: + level = self.getlevel() + if level == LEVEL_CONSTANT: op = ResOperation(rop.GUARD_VALUE, [box, self.box], None) guards.append(op) - elif self.level == LEVEL_KNOWNCLASS: + elif level == LEVEL_KNOWNCLASS: op = ResOperation(rop.GUARD_NONNULL, [box], None) guards.append(op) op = ResOperation(rop.GUARD_CLASS, [box, self.known_class], None) guards.append(op) else: - if self.level == LEVEL_NONNULL: + if level == LEVEL_NONNULL: op = ResOperation(rop.GUARD_NONNULL, [box], None) guards.append(op) if self.lenbound: @@ -276,7 +288,7 @@ return guards def get_constant_class(self, cpu): - level = self.level + level = self.getlevel() if level == LEVEL_KNOWNCLASS: return self.known_class elif level == LEVEL_CONSTANT: @@ -314,13 +326,13 @@ assert isinstance(other_value, IntOptValue) self.box = other_value.box self.intbound = other_value.intbound - self.level = other_value.level + self._tag = other_value._tag def make_constant(self, constbox): """Replace 'self.box' with a Const box.""" assert isinstance(constbox, ConstInt) self.box = constbox - self.level = LEVEL_CONSTANT + self.setlevel(LEVEL_CONSTANT) val = constbox.getint() self.intbound = IntBound(val, val) @@ -334,25 +346,26 @@ return False def make_nonnull(self, guardop): - assert self.level < LEVEL_NONNULL - self.level = LEVEL_NONNULL + assert self.getlevel() < LEVEL_NONNULL + self.setlevel(LEVEL_NONNULL) def import_from(self, other, optimizer): OptValue.import_from(self, other, optimizer) - if self.level != LEVEL_CONSTANT: + if self.getlevel() != LEVEL_CONSTANT: if other.getintbound() is not None: # VRawBufferValue self.intbound.intersect(other.getintbound()) def make_guards(self, box): guards = [] - if self.level == LEVEL_CONSTANT: + level = self.getlevel() + if level == LEVEL_CONSTANT: op = ResOperation(rop.GUARD_VALUE, [box, self.box], None) guards.append(op) - elif self.level == LEVEL_KNOWNCLASS: + elif level == LEVEL_KNOWNCLASS: op = ResOperation(rop.GUARD_NONNULL, [box], None) guards.append(op) else: - if self.level == LEVEL_NONNULL: + if level == LEVEL_NONNULL: op = ResOperation(rop.GUARD_NONNULL, [box], None) guards.append(op) self.intbound.make_guards(box, guards) @@ -508,6 +521,8 @@ self.optpure = None self.optheap = None self.optearlyforce = None + # the following two fields is the data kept for unrolling, + # those are the operations that can go to the short_preamble if loop is not None: self.call_pure_results = loop.call_pure_results @@ -609,8 +624,8 @@ except KeyError: pass else: - assert value.level != LEVEL_CONSTANT - assert cur_value.level != LEVEL_CONSTANT + assert value.getlevel() != LEVEL_CONSTANT + assert cur_value.getlevel() != LEVEL_CONSTANT # replacing with a different box cur_value.copy_from(value) return diff --git a/rpython/jit/metainterp/optimizeopt/virtualize.py b/rpython/jit/metainterp/optimizeopt/virtualize.py --- a/rpython/jit/metainterp/optimizeopt/virtualize.py +++ b/rpython/jit/metainterp/optimizeopt/virtualize.py @@ -16,7 +16,7 @@ class AbstractVirtualValue(optimizer.PtrOptValue): _attrs_ = ('keybox', 'source_op', '_cached_vinfo') box = None - level = optimizer.LEVEL_NONNULL + _tag = optimizer.LEVEL_NONNULL is_about_raw = False _cached_vinfo = None @@ -198,7 +198,7 @@ fieldvalue.visitor_walk_recursive(visitor) class VirtualValue(AbstractVirtualStructValue): - level = optimizer.LEVEL_KNOWNCLASS + _tag = optimizer.LEVEL_KNOWNCLASS def __init__(self, cpu, known_class, keybox, source_op=None): AbstractVirtualStructValue.__init__(self, cpu, keybox, source_op) diff --git a/rpython/jit/metainterp/optimizeopt/virtualstate.py b/rpython/jit/metainterp/optimizeopt/virtualstate.py --- a/rpython/jit/metainterp/optimizeopt/virtualstate.py +++ b/rpython/jit/metainterp/optimizeopt/virtualstate.py @@ -281,7 +281,7 @@ def __init__(self, value, is_opaque=False): self.is_opaque = is_opaque self.known_class = value.get_known_class() - self.level = value.level + self.level = value.getlevel() if value.getintbound() is None: self.intbound = IntUnbounded() else: _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit