Author: Maciej Fijalkowski <fij...@gmail.com>
Branch: optresult
Changeset: r74917:2713ea9e60e2
Date: 2014-12-14 20:05 +0200
http://bitbucket.org/pypy/pypy/changeset/2713ea9e60e2/

Log:    hack unrolling enough to pass the first actual test

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
@@ -150,6 +150,7 @@
 
         loop.operations = self.optimizer.get_newoperations()
         final_state = self.export_state(stop_label)
+        final_state.dump(self.optimizer.metainterp_sd)
         loop.operations.append(stop_label)
         return final_state
 
@@ -386,7 +387,7 @@
         for i in range(len(short)):
             op = short[i]
             if op.is_guard():
-                op = op.clone()
+                #op = op.clone() XXXX
                 op.setfailargs(None)
                 op.setdescr(None) # will be set to a proper descr when the 
preamble is used
                 short[i] = op
@@ -453,13 +454,13 @@
         if op.is_guard():
             op.setdescr(None) # will be set to a proper descr when the 
preamble is used
 
-        if guards_needed and self.short_boxes.has_producer(op.result):
-            value_guards = self.getvalue(op.result).make_guards(op.result)
+        if guards_needed and self.short_boxes.has_producer(op):
+            value_guards = self.getvalue(op).make_guards(op)
         else:
             value_guards = []
 
         self.short.append(op)
-        self.short_seen[op.result] = None
+        self.short_seen[op] = None
         if emit and self.short_inliner:
             newop = self.short_inliner.inline_op(op)
             self.optimizer.send_extra_operation(newop)
@@ -577,21 +578,22 @@
         debug_stop('jit-log-virtualstate')
         return False
 
-    def _inline_short_preamble(self, short_preamble, inliner, patchguardop,
+    def _inline_short_preamble(self, short_preamble, memo, patchguardop,
                                assumed_classes):
         i = 1
         # XXX this is intentiontal :-(. short_preamble can change during the
         # loop in some cases
         while i < len(short_preamble):
             shop = short_preamble[i]
-            newop = inliner.inline_op(shop)
+            newop = shop.clone(memo)
+            newop.is_source_op = True
             if newop.is_guard():
                 if not patchguardop:
                     raise InvalidLoop("would like to have short preamble, but 
it has a guard and there's no guard_future_condition")
-                descr = patchguardop.getdescr().clone_if_mutable()
+                descr = patchguardop.getdescr().clone_if_mutable(memo)
                 newop.setdescr(descr)
             self.optimizer.send_extra_operation(newop)
-            if shop.result in assumed_classes:
+            if shop in assumed_classes:
                 classbox = 
self.getvalue(newop.result).get_constant_class(self.optimizer.cpu)
                 if not classbox or not 
classbox.same_constant(assumed_classes[shop.result]):
                     raise InvalidLoop('The class of an opaque pointer before 
the jump ' +
@@ -617,13 +619,13 @@
         self.inputarg_setup_ops = inputarg_setup_ops
         self.exported_values = exported_values
 
-    def dump(self):
+    def dump(self, metainterp_sd):
         debug_start("jit-exported-state")
-        logops = LogOperations()
+        logops = LogOperations(metainterp_sd, False)
         debug_print("   inputarg setup")
-        logops._log_operations(self.inputarg_setup_ops)
+        logops._log_operations([], self.inputarg_setup_ops)
         debug_print("   short boxes")
         self.short_boxes.dump(logops)
         debug_print("   exported values")
-        self.exported_values.dump(logops)
+        #self.exported_values.dump(logops)
         debug_stop("jit-exported-state")
diff --git a/rpython/jit/metainterp/optimizeopt/virtualstate.py 
b/rpython/jit/metainterp/optimizeopt/virtualstate.py
--- a/rpython/jit/metainterp/optimizeopt/virtualstate.py
+++ b/rpython/jit/metainterp/optimizeopt/virtualstate.py
@@ -591,32 +591,40 @@
         self.potential_ops = {}
         self.alternatives = {}
         self.synthetic = {}
-        self.memo = Memo()
         self.optimizer = optimizer
         self.available_boxes = available_boxes
         self.assumed_classes = {}
 
-        if surviving_boxes is not None:
-            for box in surviving_boxes:
-                self.potential_ops[box] = None
-            optimizer.produce_potential_short_preamble_ops(self)
+        assert surviving_boxes is not None
+        for box in surviving_boxes:
+            self.potential_ops[box] = None
+        optimizer.produce_potential_short_preamble_ops(self)
 
-            self.short_boxes = {}
-            self.short_boxes_in_production = {}
+        self.short_boxes = {}
+        self.short_boxes_in_production = {}
 
-            for op in self.potential_ops.keys():
-                try:
-                    self.produce_short_preamble_op(op)
-                except BoxNotProducable:
-                    pass
+        for op in self.potential_ops.keys():
+            try:
+                self.produce_short_preamble_op(op)
+            except BoxNotProducable:
+                pass
 
-            self.short_boxes_in_production = None # Not needed anymore
-        else:
-            self.short_boxes = {}
+        self.short_boxes_in_production = None # Not needed anymore
+        #else:
+        #    self.short_boxes = {}
+
+    def dump(self, logops):
+        for op, resop in self.short_boxes.iteritems():
+            if isinstance(op, AbstractInputArg):
+                assert resop is None
+                debug_print(logops.repr_of_arg(op))
+            else:
+                debug_print("%s:%s"% (logops.repr_of_resop(op),
+                                      logops.repr_of_resop(resop)))
 
     def prioritized_alternatives(self, box):
         if box not in self.alternatives:
-            return [box]
+            return [self.potential_ops[box]]
         alts = self.alternatives[box]
         hi, lo = 0, len(alts) - 1
         while hi < lo:
@@ -631,11 +639,13 @@
         return alts
 
     def add_to_short(self, box, op):
-        if op:
-            op = op.clone(self.memo)
-            op.is_source_op = True
+        #if op:
+        #    op = op.clone(self.memo)
+        #    op.is_source_op = True
         if box in self.short_boxes:
+            xxx
             if op is None:
+                xxxx
                 oldop = self.short_boxes[box].clone()
                 oldres = oldop.result
                 newbox = oldop.result = oldres.clonebox()
@@ -643,6 +653,7 @@
                 self.short_boxes[box] = None
                 self.short_boxes[newbox] = oldop
             else:
+                xxxx
                 newop = op.clone()
                 newbox = newop.result = op.result.clonebox()
                 self.short_boxes[newop.result] = newop
@@ -655,11 +666,11 @@
     def produce_short_preamble_op(self, op):
         if op in self.short_boxes:
             return
-        if isinstance(op, Const) or isinstance(op, AbstractInputArg):
+        if isinstance(op, Const):
             return
         if op in self.short_boxes_in_production:
             raise BoxNotProducable
-        if self.availible_boxes is not None and op not in self.available_boxes:
+        if self.available_boxes is not None and op not in self.available_boxes:
             raise BoxNotProducable
         self.short_boxes_in_production[op] = None
 
@@ -689,7 +700,7 @@
                 if classbox:
                     self.assumed_classes[op] = classbox
         if op not in self.potential_ops:
-            self.potential_ops[op] = None
+            self.potential_ops[op] = op
         else:
             if op not in self.alternatives:
                 self.alternatives[op] = [op]
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to