Commits

Carl Friedrich Bolz committed 63d82c4

make generate_guards take an OptValue instead of a box

(in theory, it is not necessary to make it take a second virtual state now, but
well)

  • Participants
  • Parent commits 9a05f92
  • Branches small-unroll-improvements

Comments (0)

Files changed (3)

File rpython/jit/metainterp/optimizeopt/test/test_virtualstate.py

 
 
 class BaseTestGenerateGuards(BaseTest):
-    def guards(self, info1, info2, box, expected):
+    def guards(self, info1, info2, box_or_value, expected):
+        if isinstance(box_or_value, OptValue):
+            value = box_or_value
+            box = value.box
+        else:
+            box = box_or_value
+            value = OptValue(box)
         info1.position = info2.position = 0
         guards = []
-        info1.generate_guards(info2, box, self.cpu, guards, {})
+        info1.generate_guards(info2, value, self.cpu, guards, {})
         self.compare(guards, expected, [box])
 
     def compare(self, guards, expected, inputargs):
         assert equaloplists(guards, loop.operations, False,
                             boxmap)        
     def test_intbounds(self):
-        value1 = OptValue(BoxInt())
+        value1 = OptValue(BoxInt(15))
         value1.intbound.make_ge(IntBound(0, 10))
         value1.intbound.make_le(IntBound(20, 30))
         info1 = NotVirtualStateInfo(value1)
         i2 = int_le(i0, 30)
         guard_true(i2) []
         """
-        self.guards(info1, info2, BoxInt(15), expected)
+        self.guards(info1, info2, value1, expected)
         py.test.raises(InvalidLoop, self.guards,
                        info1, info2, BoxInt(50), expected)
 
         self.compare(guards, expected, [box])
 
     def test_equal_inputargs(self):
-        value = OptValue(self.nodebox)        
+        value = OptValue(self.nodebox)
         classbox = self.cpu.ts.cls_of_box(self.nodebox)
         value.make_constant_class(classbox, -1)
         knownclass_info = NotVirtualStateInfo(value)
 
         expected = """
         [p0]
-        guard_nonnull(p0) []        
+        guard_nonnull(p0) []
         guard_class(p0, ConstClass(node_vtable)) []
         """
         guards = []
-        vstate1.generate_guards(vstate2, [self.nodebox, self.nodebox], self.cpu, guards)
+        vstate1.generate_guards(vstate2, [value, value], self.cpu, guards)
         self.compare(guards, expected, [self.nodebox])
 
         with py.test.raises(InvalidLoop):
             guards = []
-            vstate1.generate_guards(vstate3, [self.nodebox, self.nodebox],
+            vstate1.generate_guards(vstate3, [value, value],
                                     self.cpu, guards)
         with py.test.raises(InvalidLoop):
             guards = []
-            vstate2.generate_guards(vstate3, [self.nodebox, self.nodebox],
+            vstate2.generate_guards(vstate3, [value, value],
                                     self.cpu, guards)
 
     def test_known_value_virtualstate(self):
         guard_value(i0, 1) []
         """
         guards = []
-        vstate1.generate_guards(vstate2, [box2], self.cpu, guards)
+        vstate1.generate_guards(vstate2, [value2], self.cpu, guards)
         self.compare(guards, expected, [box2])
 
 

File rpython/jit/metainterp/optimizeopt/unroll.py

         args = jumpop.getarglist()
         modifier = VirtualStateAdder(self.optimizer)
         virtual_state = modifier.get_virtual_state(args)
+        values = [self.getvalue(arg)
+                  for arg in jumpop.getarglist()]
         debug_start('jit-log-virtualstate')
         virtual_state.debug_print("Looking for ")
 
                 try:
                     cpu = self.optimizer.cpu
                     target.virtual_state.generate_guards(virtual_state,
-                                                         args, cpu,
+                                                         values,
+                                                         cpu,
                                                          extra_guards)
 
                     ok = True
                     debugmsg = 'Guarded to match '
                 except InvalidLoop:
                     pass
-            #else:
-            #    import pdb; pdb.set_trace()
             if ok and not patchguardop:
                 # if we can't patch the guards to go to a good target, no use
                 # in jumping to this label
             if ok:
                 debug_stop('jit-log-virtualstate')
 
-                values = [self.getvalue(arg)
-                          for arg in jumpop.getarglist()]
                 args = target.virtual_state.make_inputargs(values, self.optimizer,
                                                            keyboxes=True)
                 short_inputargs = target.short_preamble[0].getarglist()
                     self.optimizer.send_extra_operation(guard)
 
                 try:
+                    # NB: the short_preamble ends with a jump
                     for shop in target.short_preamble[1:]:
                         newop = inliner.inline_op(shop)
                         if newop.is_guard():

File rpython/jit/metainterp/optimizeopt/virtualstate.py

 from rpython.jit.metainterp.optimizeopt import virtualize
 from rpython.jit.metainterp.optimizeopt.intutils import IntUnbounded
 from rpython.jit.metainterp.optimizeopt.optimizer import (LEVEL_CONSTANT,
-    LEVEL_KNOWNCLASS, LEVEL_NONNULL, LEVEL_UNKNOWN)
+    LEVEL_KNOWNCLASS, LEVEL_NONNULL, LEVEL_UNKNOWN, OptValue)
 from rpython.jit.metainterp.resoperation import rop, ResOperation
 from rpython.rlib.debug import debug_start, debug_stop, debug_print
 from rpython.rlib.objectmodel import we_are_translated
             bad[self] = bad[other] = None
         return result
 
-    def generate_guards(self, other, box, cpu, extra_guards, renum):
+    def generate_guards(self, other, value, cpu, extra_guards, renum):
+        assert isinstance(value, OptValue)
         if self.generalization_of(other, renum, {}):
             return
         if renum[self.position] != other.position:
                               'match. This means that two virtual fields ' +
                               'have been set to the same Box in one of the ' +
                               'virtual states but not in the other.')
-        self._generate_guards(other, box, cpu, extra_guards)
+        self._generate_guards(other, value, cpu, extra_guards, renum)
 
-    def _generate_guards(self, other, box, cpu, extra_guards):
+    def _generate_guards(self, other, value, cpu, extra_guards, renum):
         raise InvalidLoop('Generating guards for making the VirtualStates ' +
                           'at hand match have not been implemented')
 
             return False
         return True
 
-    def _generate_guards(self, other, box, cpu, extra_guards):
+    def _generate_guards(self, other, value, cpu, extra_guards, renum):
+        box = value.box
         if not isinstance(other, NotVirtualStateInfo):
             raise InvalidLoop('The VirtualStates does not match as a ' +
                               'virtual appears where a pointer is needed ' +
                 return False
         return True
 
-    def generate_guards(self, other, args, cpu, extra_guards):
-        assert len(self.state) == len(other.state) == len(args)
+    def generate_guards(self, other, values, cpu, extra_guards):
+        assert len(self.state) == len(other.state) == len(values)
         renum = {}
         for i in range(len(self.state)):
-            self.state[i].generate_guards(other.state[i], args[i],
+            self.state[i].generate_guards(other.state[i], values[i],
                                           cpu, extra_guards, renum)
 
     def make_inputargs(self, values, optimizer, keyboxes=False):