Author: Carl Friedrich Bolz <[email protected]>
Branch:
Changeset: r81636:67211e59dc29
Date: 2016-01-08 21:14 +0100
http://bitbucket.org/pypy/pypy/changeset/67211e59dc29/
Log: put the really shared method into an abstract base class
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
@@ -21,7 +21,10 @@
pass
-class CachedField(object):
+class AbstractCachedEntry(object):
+ """ abstract base class abstracting over the difference between caching
+ struct fields and array items. """
+
def __init__(self):
# Cache information for a field descr, or for an (array descr, index)
# pair. It can be in one of two states:
@@ -48,13 +51,6 @@
self.cached_structs.append(structop)
self.cached_infos.append(info)
- def invalidate(self, descr):
- for opinfo in self.cached_infos:
- assert isinstance(opinfo, info.AbstractStructPtrInfo)
- opinfo._fields[descr.get_index()] = None
- self.cached_infos = []
- self.cached_structs = []
-
def produce_potential_short_preamble_ops(self, optimizer, shortboxes,
descr, index=-1):
assert self._lazy_setfield is None
@@ -118,22 +114,6 @@
return res.get_box_replacement()
return None
- def _get_rhs_from_set_op(self, op):
- """ given a set(field or arrayitem) op, return the rhs argument """
- return op.getarg(1)
-
- def _getfield(self, opinfo, descr, optheap, true_force=True):
- res = opinfo.getfield(descr, optheap)
- if not we_are_translated() and res:
- if isinstance(opinfo, info.AbstractStructPtrInfo):
- assert opinfo in self.cached_infos
- if isinstance(res, PreambleOp):
- if not true_force:
- return res.op
- res = optheap.optimizer.force_op_from_preamble(res)
- opinfo.setfield(descr, None, res, optheap)
- return res
-
def force_lazy_setfield(self, optheap, descr, can_cache=True):
op = self._lazy_setfield
if op is not None:
@@ -159,6 +139,27 @@
elif not can_cache:
self.invalidate(descr)
+
+ # abstract methods
+
+ def _get_rhs_from_set_op(self, op):
+ raise NotImplementedError("abstract method")
+
+ def put_field_back_to_info(self, op, opinfo, optheap):
+ raise NotImplementedError("abstract method")
+
+ def _getfield(self, opinfo, descr, optheap, true_force=True):
+ raise NotImplementedError("abstract method")
+
+ def invalidate(self, descr):
+ raise NotImplementedError("abstract method")
+
+
+class CachedField(AbstractCachedEntry):
+ def _get_rhs_from_set_op(self, op):
+ """ given a set(field or arrayitem) op, return the rhs argument """
+ return op.getarg(1)
+
def put_field_back_to_info(self, op, opinfo, optheap):
""" this method is called just after a lazy setfield was ommitted. it
puts the information of the lazy setfield back into the proper cache in
@@ -167,10 +168,30 @@
struct = optheap.get_box_replacement(op.getarg(0))
opinfo.setfield(op.getdescr(), struct, arg, optheap, self)
-class ArrayCachedField(CachedField):
+ def _getfield(self, opinfo, descr, optheap, true_force=True):
+ res = opinfo.getfield(descr, optheap)
+ if not we_are_translated() and res:
+ if isinstance(opinfo, info.AbstractStructPtrInfo):
+ assert opinfo in self.cached_infos
+ if isinstance(res, PreambleOp):
+ if not true_force:
+ return res.op
+ res = optheap.optimizer.force_op_from_preamble(res)
+ opinfo.setfield(descr, None, res, optheap)
+ return res
+
+ def invalidate(self, descr):
+ for opinfo in self.cached_infos:
+ assert isinstance(opinfo, info.AbstractStructPtrInfo)
+ opinfo._fields[descr.get_index()] = None
+ self.cached_infos = []
+ self.cached_structs = []
+
+
+class ArrayCachedItem(AbstractCachedEntry):
def __init__(self, index):
self.index = index
- CachedField.__init__(self)
+ AbstractCachedEntry.__init__(self)
def _get_rhs_from_set_op(self, op):
return op.getarg(2)
@@ -284,7 +305,7 @@
try:
cf = submap[index]
except KeyError:
- cf = submap[index] = ArrayCachedField(index)
+ cf = submap[index] = ArrayCachedItem(index)
return cf
def emit_operation(self, op):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit