[pypy-svn] r65364 - in pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp: . test
antocuni at codespeak.net
antocuni at codespeak.net
Sat May 23 18:05:45 CEST 2009
Author: antocuni
Date: Sat May 23 18:05:43 2009
New Revision: 65364
Modified:
pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/optimize3.py
pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/test/test_optimize3.py
Log:
implement constant folding, and add a test for it
Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/optimize3.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/optimize3.py (original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/optimize3.py Sat May 23 18:05:43 2009
@@ -129,6 +129,29 @@
return op
+class ConstFold(AbstractOptimization):
+
+ def handle_default_op(self, spec, op):
+ op = op.clone()
+ op.args = spec.new_arguments(op)
+ if op.is_always_pure():
+ for box in op.args:
+ if isinstance(box, Box):
+ break
+ else:
+ # all constant arguments: constant-fold away
+ box = op.result
+ assert box is not None
+ instnode = InstanceNode(box.constbox(), const=True)
+ spec.nodes[box] = instnode
+ return
+ elif not op.has_no_side_effect():
+ # XXX
+ pass
+ #spec.clean_up_caches(newoperations)
+ return op
+
+
class OptimizeGuards(AbstractOptimization):
def optimize_guard(self, spec, op):
@@ -172,6 +195,7 @@
OPTLIST = [
OptimizeGuards(),
+ ConstFold(),
]
specializer = Specializer(OPTLIST)
Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/test/test_optimize3.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/test/test_optimize3.py (original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/test/test_optimize3.py Sat May 23 18:05:43 2009
@@ -73,6 +73,13 @@
loop.operations = operations
return loop
+ def test_constfold(self):
+ ops = [
+ ResOperation(rop.INT_ADD, [ConstInt(10), ConstInt(20)], ConstInt(30)),
+ ]
+ loop = self.newloop([], ops)
+ optimize_loop(None, [], loop)
+ assert len(loop.operations) == 0
def test_remove_guard_class(self):
ops = [
More information about the Pypy-commit
mailing list