[pypy-commit] pypy optimizeopt-cleanup: Move use_unroll logic completely out of compile_loop()

rlamy pypy.commits at gmail.com
Thu May 9 10:40:00 EDT 2019


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: optimizeopt-cleanup
Changeset: r96581:11de4273c126
Date: 2019-04-29 19:52 +0100
http://bitbucket.org/pypy/pypy/changeset/11de4273c126/

Log:	Move use_unroll logic completely out of compile_loop()

diff --git a/rpython/jit/metainterp/pyjitpl.py b/rpython/jit/metainterp/pyjitpl.py
--- a/rpython/jit/metainterp/pyjitpl.py
+++ b/rpython/jit/metainterp/pyjitpl.py
@@ -2579,6 +2579,8 @@
         # green keys, representing the beginning of the same loop as the one
         # we end now.
 
+        can_use_unroll = (self.staticdata.cpu.supports_guard_gc_type and
+            'unroll' in self.jitdriver_sd.warmstate.enable_opts)
         for j in range(len(self.current_merge_points)-1, -1, -1):
             original_boxes, start = self.current_merge_points[j]
             assert len(original_boxes) == len(live_arg_boxes)
@@ -2600,18 +2602,19 @@
                     self.staticdata.log('cancelled too many times!')
                     raise SwitchToBlackhole(Counters.ABORT_BAD_LOOP)
             else:
-                can_use_unroll = (self.staticdata.cpu.supports_guard_gc_type and
-                    'unroll' in self.jitdriver_sd.warmstate.enable_opts)
                 target_token = self.compile_loop(
-                    original_boxes, live_arg_boxes, start, can_use_unroll=can_use_unroll)
+                    original_boxes, live_arg_boxes, start,
+                    use_unroll=can_use_unroll)
                 self.raise_if_successful(live_arg_boxes, target_token)
                 # creation of the loop was cancelled!
                 self.cancel_count += 1
                 if self.cancelled_too_many_times():
-                    target_token = self.compile_loop(
-                        original_boxes, live_arg_boxes, start,
-                        try_disabling_unroll=True, can_use_unroll=can_use_unroll)
-                    self.raise_if_successful(live_arg_boxes, target_token)
+                    if can_use_unroll:
+                        # try one last time without unrolling
+                        target_token = self.compile_loop(
+                            original_boxes, live_arg_boxes, start,
+                            use_unroll=False)
+                        self.raise_if_successful(live_arg_boxes, target_token)
                     #
                     self.staticdata.log('cancelled too many times!')
                     raise SwitchToBlackhole(Counters.ABORT_BAD_LOOP)
@@ -2734,13 +2737,7 @@
             return None
         return cell.get_procedure_token()
 
-    def compile_loop(self, original_boxes, live_arg_boxes, start,
-                     try_disabling_unroll=False, can_use_unroll=True):
-        use_unroll = can_use_unroll
-        if try_disabling_unroll:
-            if not use_unroll:
-                return
-            use_unroll = False
+    def compile_loop(self, original_boxes, live_arg_boxes, start, use_unroll):
         num_green_args = self.jitdriver_sd.num_green_args
         greenkey = original_boxes[:num_green_args]
         ptoken = self.get_procedure_token(greenkey)
diff --git a/rpython/jit/metainterp/test/test_ajit.py b/rpython/jit/metainterp/test/test_ajit.py
--- a/rpython/jit/metainterp/test/test_ajit.py
+++ b/rpython/jit/metainterp/test/test_ajit.py
@@ -2884,8 +2884,8 @@
                 i += 1
             return i
         #
-        def my_compile_loop(self, original_boxes, live_arg_boxes, start,
-                        try_disabling_unroll=False, can_use_unroll=None):
+        def my_compile_loop(
+                self, original_boxes, live_arg_boxes, start, use_unroll):
             return None
         old_compile_loop = MetaInterp.compile_loop
         MetaInterp.compile_loop = my_compile_loop
@@ -2918,9 +2918,9 @@
             return i
         #
         seen = []
-        def my_compile_loop(self, original_boxes, live_arg_boxes, start,
-                        try_disabling_unroll=False, can_use_unroll=None):
-            seen.append(try_disabling_unroll)
+        def my_compile_loop(
+                self, original_boxes, live_arg_boxes, start, use_unroll):
+            seen.append(use_unroll)
             return None
         old_compile_loop = MetaInterp.compile_loop
         MetaInterp.compile_loop = my_compile_loop


More information about the pypy-commit mailing list