[pypy-svn] r76907 - pypy/branch/jit-bounds/pypy/jit/metainterp/optimizeopt
hakanardo at codespeak.net
hakanardo at codespeak.net
Tue Sep 7 07:25:16 CEST 2010
Author: hakanardo
Date: Tue Sep 7 07:25:13 2010
New Revision: 76907
Modified:
pypy/branch/jit-bounds/pypy/jit/metainterp/optimizeopt/optimizer.py
pypy/branch/jit-bounds/pypy/jit/metainterp/optimizeopt/rewrite.py
Log:
moved some optimizations infront of the heap optimizer
Modified: pypy/branch/jit-bounds/pypy/jit/metainterp/optimizeopt/optimizer.py
==============================================================================
--- pypy/branch/jit-bounds/pypy/jit/metainterp/optimizeopt/optimizer.py (original)
+++ pypy/branch/jit-bounds/pypy/jit/metainterp/optimizeopt/optimizer.py Tue Sep 7 07:25:13 2010
@@ -416,89 +416,9 @@
# in this case
self.emit_operation(op)
- def _optimize_nullness(self, op, box, expect_nonnull):
- value = self.getvalue(box)
- if value.is_nonnull():
- self.make_constant_int(op.result, expect_nonnull)
- elif value.is_null():
- self.make_constant_int(op.result, not expect_nonnull)
- else:
- self.optimize_default(op)
-
- def optimize_INT_IS_TRUE(self, op):
- if self.getvalue(op.args[0]) in self.bool_boxes:
- self.make_equal_to(op.result, self.getvalue(op.args[0]))
- return
- self._optimize_nullness(op, op.args[0], True)
-
- def optimize_INT_IS_ZERO(self, op):
- self._optimize_nullness(op, op.args[0], False)
-
- def _optimize_oois_ooisnot(self, op, expect_isnot):
- value0 = self.getvalue(op.args[0])
- value1 = self.getvalue(op.args[1])
- if value0.is_virtual():
- if value1.is_virtual():
- intres = (value0 is value1) ^ expect_isnot
- self.make_constant_int(op.result, intres)
- else:
- self.make_constant_int(op.result, expect_isnot)
- elif value1.is_virtual():
- self.make_constant_int(op.result, expect_isnot)
- elif value1.is_null():
- self._optimize_nullness(op, op.args[0], expect_isnot)
- elif value0.is_null():
- self._optimize_nullness(op, op.args[1], expect_isnot)
- elif value0 is value1:
- self.make_constant_int(op.result, not expect_isnot)
- else:
- cls0 = value0.get_constant_class(self.cpu)
- if cls0 is not None:
- cls1 = value1.get_constant_class(self.cpu)
- if cls1 is not None and not cls0.same_constant(cls1):
- # cannot be the same object, as we know that their
- # class is different
- self.make_constant_int(op.result, expect_isnot)
- return
- self.optimize_default(op)
-
- def optimize_PTR_NE(self, op):
- self._optimize_oois_ooisnot(op, True)
-
- def optimize_PTR_EQ(self, op):
- self._optimize_oois_ooisnot(op, False)
-
- def optimize_INSTANCEOF(self, op):
- value = self.getvalue(op.args[0])
- realclassbox = value.get_constant_class(self.cpu)
- if realclassbox is not None:
- checkclassbox = self.cpu.typedescr2classbox(op.descr)
- result = self.cpu.ts.subclassOf(self.cpu, realclassbox,
- checkclassbox)
- self.make_constant_int(op.result, result)
- return
- self.emit_operation(op)
-
def optimize_DEBUG_MERGE_POINT(self, op):
self.emit_operation(op)
- def optimize_CALL_LOOPINVARIANT(self, op):
- funcvalue = self.getvalue(op.args[0])
- if not funcvalue.is_constant():
- self.optimize_default(op)
- return
- key = make_hashable_int(op.args[0].getint())
- resvalue = self.loop_invariant_results.get(key, None)
- if resvalue is not None:
- self.make_equal_to(op.result, resvalue)
- return
- # change the op to be a normal call, from the backend's point of view
- # there is no reason to have a separate operation for this
- op.opnum = rop.CALL
- self.optimize_default(op)
- resvalue = self.getvalue(op.result)
- self.loop_invariant_results[key] = resvalue
-
optimize_ops = _findall(Optimizer, 'optimize_')
Modified: pypy/branch/jit-bounds/pypy/jit/metainterp/optimizeopt/rewrite.py
==============================================================================
--- pypy/branch/jit-bounds/pypy/jit/metainterp/optimizeopt/rewrite.py (original)
+++ pypy/branch/jit-bounds/pypy/jit/metainterp/optimizeopt/rewrite.py Tue Sep 7 07:25:13 2010
@@ -238,6 +238,87 @@
self.emit_operation(op)
self.optimizer.exception_might_have_happened = False
+ def optimize_CALL_LOOPINVARIANT(self, op):
+ funcvalue = self.getvalue(op.args[0])
+ if not funcvalue.is_constant():
+ self.emit_operation(op)
+ return
+ key = make_hashable_int(op.args[0].getint())
+ resvalue = self.optimizer.loop_invariant_results.get(key, None)
+ if resvalue is not None:
+ self.make_equal_to(op.result, resvalue)
+ return
+ # change the op to be a normal call, from the backend's point of view
+ # there is no reason to have a separate operation for this
+ op.opnum = rop.CALL
+ self.emit_operation(op)
+ resvalue = self.getvalue(op.result)
+ self.optimizer.loop_invariant_results[key] = resvalue
+
+ def _optimize_nullness(self, op, box, expect_nonnull):
+ value = self.getvalue(box)
+ if value.is_nonnull():
+ self.make_constant_int(op.result, expect_nonnull)
+ elif value.is_null():
+ self.make_constant_int(op.result, not expect_nonnull)
+ else:
+ self.emit_operation(op)
+
+ def optimize_INT_IS_TRUE(self, op):
+ if self.getvalue(op.args[0]) in self.optimizer.bool_boxes:
+ self.make_equal_to(op.result, self.getvalue(op.args[0]))
+ return
+ self._optimize_nullness(op, op.args[0], True)
+
+ def optimize_INT_IS_ZERO(self, op):
+ self._optimize_nullness(op, op.args[0], False)
+
+ def _optimize_oois_ooisnot(self, op, expect_isnot):
+ value0 = self.getvalue(op.args[0])
+ value1 = self.getvalue(op.args[1])
+ if value0.is_virtual():
+ if value1.is_virtual():
+ intres = (value0 is value1) ^ expect_isnot
+ self.make_constant_int(op.result, intres)
+ else:
+ self.make_constant_int(op.result, expect_isnot)
+ elif value1.is_virtual():
+ self.make_constant_int(op.result, expect_isnot)
+ elif value1.is_null():
+ self._optimize_nullness(op, op.args[0], expect_isnot)
+ elif value0.is_null():
+ self._optimize_nullness(op, op.args[1], expect_isnot)
+ elif value0 is value1:
+ self.make_constant_int(op.result, not expect_isnot)
+ else:
+ cls0 = value0.get_constant_class(self.optimizer.cpu)
+ if cls0 is not None:
+ cls1 = value1.get_constant_class(self.optimizer.cpu)
+ if cls1 is not None and not cls0.same_constant(cls1):
+ # cannot be the same object, as we know that their
+ # class is different
+ self.make_constant_int(op.result, expect_isnot)
+ return
+ self.emit_operation(op)
+
+ def optimize_PTR_NE(self, op):
+ self._optimize_oois_ooisnot(op, True)
+
+ def optimize_PTR_EQ(self, op):
+ self._optimize_oois_ooisnot(op, False)
+
+ def optimize_INSTANCEOF(self, op):
+ value = self.getvalue(op.args[0])
+ realclassbox = value.get_constant_class(self.optimizer.cpu)
+ if realclassbox is not None:
+ checkclassbox = self.optimizer.cpu.typedescr2classbox(op.descr)
+ result = self.optimizer.cpu.ts.subclassOf(self.optimizer.cpu,
+ realclassbox,
+ checkclassbox)
+ self.make_constant_int(op.result, result)
+ return
+ self.emit_operation(op)
+
optimize_ops = _findall(OptRewrite, 'optimize_')
More information about the Pypy-commit
mailing list