1. Pypy
  2. Untitled project
  3. pypy

Commits

Maciej Fijalkowski  committed 58bcd5d

implement dead ops removal

  • Participants
  • Parent commits 70a3702
  • Branches dead-code-optimization

Comments (0)

Files changed (3)

File pypy/jit/metainterp/optimizeopt/__init__.py

View file
  • Ignore whitespace
 from pypy.jit.metainterp.optimizeopt.simplify import OptSimplify
 from pypy.jit.metainterp.optimizeopt.pure import OptPure
 from pypy.jit.metainterp.optimizeopt.earlyforce import OptEarlyForce
+from pypy.jit.metainterp.optimizeopt.deadops import remove_dead_ops
 from pypy.rlib.jit import PARAMETERS
 from pypy.rlib.unroll import unrolling_iterable
 from pypy.rlib.debug import debug_start, debug_stop, debug_print
         else:
             optimizer = Optimizer(metainterp_sd, loop, optimizations)
             optimizer.propagate_all_forward()
+        remove_dead_ops(loop)
     finally:
         debug_stop("jit-optimize")
         

File pypy/jit/metainterp/optimizeopt/deadops.py

View file
  • Ignore whitespace
+
+def remove_dead_ops(loop):
+    newops = []
+    seen = {}
+    for i in range(len(loop.operations) -1, -1, -1):
+        op = loop.operations[i]
+        if op.has_no_side_effect() and op.result not in seen:
+            continue
+        for arg in op.getarglist():
+            seen[arg] = None
+        if op.getfailargs():
+            for arg in op.getfailargs():
+                seen[arg] = None
+        newops.append(op)
+    newops.reverse()
+    loop.operations[:] = newops

File pypy/jit/metainterp/optimizeopt/test/test_deadops.py

View file
  • Ignore whitespace
+
+from pypy.jit.metainterp.optimizeopt.test.test_util import LLtypeMixin
+from pypy.jit.metainterp.optimizeopt.test.test_optimizebasic import BaseTestBasic
+
+class TestRemoveDeadOps(BaseTestBasic, LLtypeMixin):
+    def test_deadops(self):
+        ops = """
+        [i0]
+        i1 = int_add(i0, 1)
+        jump()
+        """
+        expected = """
+        [i0]
+        jump()
+        """
+        self.optimize_loop(ops, expected)
+
+    def test_not_deadops(self):
+        ops = """
+        [i0]
+        i1 = int_add(i0, 1)
+        jump(i1)
+        """
+        expected = """
+        [i0]
+        i1 = int_add(i0, 1)
+        jump(i1)
+        """
+        self.optimize_loop(ops, expected)
+
+    def test_not_deadops_1(self):
+        ops = """
+        [i0]
+        i1 = int_add(i0, 1)
+        guard_true(i0) [i1]
+        jump()
+        """
+        expected = """
+        [i0] 
+        i1 = int_add(i0, 1)
+        guard_true(i0) [i1]
+        jump()
+        """
+        self.optimize_loop(ops, expected)
+
+    def test_not_deadops_2(self):
+        ops = """
+        [p0, i0]
+        setfield_gc(p0, i0)
+        jump()
+        """
+        expected = """
+        [p0, i0]
+        setfield_gc(p0, i0)
+        jump()
+        """
+        self.optimize_loop(ops, expected)