[pypy-commit] pypy optresult-unroll: improve checks for short preamble

fijal noreply at buildbot.pypy.org
Tue Jul 7 09:36:37 CEST 2015


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: optresult-unroll
Changeset: r78481:59e4de30e491
Date: 2015-07-06 19:00 +0200
http://bitbucket.org/pypy/pypy/changeset/59e4de30e491/

Log:	improve checks for short preamble

diff --git a/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py b/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py
@@ -177,9 +177,6 @@
             """ % expected_value
             self.optimize_loop(ops, expected)
 
-    #def test_cast_1(self):
-    #    xxx
-
     def test_reverse_of_cast_1(self):
         ops = """
         [i0]
@@ -196,7 +193,7 @@
         p3 = cast_int_to_ptr(i2)
         #jump(i2) <- think about it
         """
-        self.optimize_loop(ops, expected) #, expected_short=short)
+        self.optimize_loop(ops, expected, expected_short=short)
 
     def test_reverse_of_cast_2(self):
         ops = """
diff --git a/rpython/jit/metainterp/optimizeopt/test/test_util.py b/rpython/jit/metainterp/optimizeopt/test/test_util.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_util.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_util.py
@@ -446,14 +446,14 @@
         end_label = ResOperation(rop.LABEL, start_state.end_args)
         loop_data = compile.UnrolledLoopData(end_label, jump_op,
                                              ops, start_state)
-        _, ops = self._do_optimize_loop(loop_data, call_pure_results)
+        loop_info, ops = self._do_optimize_loop(loop_data, call_pure_results)
         preamble = TreeLoop('preamble')
         preamble.inputargs = start_label.getarglist()
         preamble.operations = [start_label] + preamble_ops
         emit_end_label = ResOperation(rop.LABEL, start_state.end_args)
         loop.inputargs = start_state.end_args
         loop.operations = [emit_end_label] + ops
-        return Info(preamble)
+        return Info(preamble, loop_info.short_preamble)
 
     def foo(self):
         metainterp_sd = FakeMetaInterpStaticData(self.cpu)
diff --git a/rpython/jit/metainterp/optimizeopt/unroll.py b/rpython/jit/metainterp/optimizeopt/unroll.py
--- a/rpython/jit/metainterp/optimizeopt/unroll.py
+++ b/rpython/jit/metainterp/optimizeopt/unroll.py
@@ -56,7 +56,6 @@
     def __init__(self, metainterp_sd, jitdriver_sd, optimizations):
         self.optimizer = UnrollableOptimizer(metainterp_sd, jitdriver_sd,
                                              optimizations)
-        self.short = []
         self.optimizer.optunroll = self
 
     def get_virtual_state(self, args):
@@ -76,6 +75,7 @@
         return exported_state, self.optimizer._newoperations
 
     def optimize_peeled_loop(self, start_label, end_jump, ops, state):
+        self.short = []
         self._check_no_forwarding([[start_label, end_jump], ops])
         self.import_state(start_label, state)
         self.optimizer.propagate_all_forward(start_label.getarglist()[:], ops)
@@ -85,7 +85,13 @@
                                                        self.optimizer)
         jump_op = ResOperation(rop.JUMP, jump_args)
         self.optimizer._newoperations.append(jump_op)
-        return None, self.optimizer._newoperations
+        return (UnrollInfo(self.make_short_preamble(start_label.getarglist())),
+                self.optimizer._newoperations)
+
+    def make_short_preamble(self, args):
+        label = ResOperation(rop.LABEL, args)
+        short = [label] + self.short
+        return short
 
     def random_garbage(self):
         # WTF is the rest of this function
@@ -688,18 +694,28 @@
                                       'it has at the start of the target loop')
             i += 1
 
-class ShortPreambleBuilder(object):
-    """ A place that builds short preamble and the necessary
-    arguments for the label and the jump
+class LoopInfo(object):
+    pass
+
+class UnrollInfo(LoopInfo):
+    """ A state after optimizing the peeled loop, contains the following:
+
+    * short_preamble - list of operations that go into short preamble
     """
-
-class ExportedState(object):
+    def __init__(self, short_preamble):
+        self.short_preamble = short_preamble
+            
+class ExportedState(LoopInfo):
     """ Exported state consists of a few pieces of information:
 
     * inputarg_mapping - a list of tuples with original inputarg box
                          as the first element and the second element being
                          what it maps to (potentially const)
     * exported_infos - a mapping from ops to infos, including inputargs
+    * end_args - arguments that end up in the label leading to the next
+                 iteration
+    * virtual_state - instance of VirtualState representing current state
+                      of virtuals at this label
     * short boxes - a mapping op -> preamble_op
     """
     


More information about the pypy-commit mailing list