Author: Maciej Fijalkowski <[email protected]>
Branch: share-guard-info
Changeset: r79744:51f2f9c26591
Date: 2015-09-21 20:54 +0200
http://bitbucket.org/pypy/pypy/changeset/51f2f9c26591/

Log:    one more case

diff --git a/rpython/jit/codewriter/codewriter.py 
b/rpython/jit/codewriter/codewriter.py
--- a/rpython/jit/codewriter/codewriter.py
+++ b/rpython/jit/codewriter/codewriter.py
@@ -48,7 +48,7 @@
         # which means mostly producing a linear list of operations and
         # inserting jumps or conditional jumps.  This is a list of tuples
         # of the shape ("opname", arg1, ..., argN) or (Label(...),).
-        ssarepr = flatten_graph(graph, regallocs)
+        ssarepr = flatten_graph(graph, regallocs, cpu=self.callcontrol.cpu)
         #
         # step 3b: compute the liveness around certain operations
         compute_liveness(ssarepr)
diff --git a/rpython/jit/codewriter/flatten.py 
b/rpython/jit/codewriter/flatten.py
--- a/rpython/jit/codewriter/flatten.py
+++ b/rpython/jit/codewriter/flatten.py
@@ -60,10 +60,11 @@
 
 # ____________________________________________________________
 
-def flatten_graph(graph, regallocs, _include_all_exc_links=False):
+def flatten_graph(graph, regallocs, _include_all_exc_links=False,
+                  cpu=None):
     """Flatten the graph into an SSARepr, with already-computed register
     allocations.  'regallocs' in a dict {kind: RegAlloc}."""
-    flattener = GraphFlattener(graph, regallocs, _include_all_exc_links)
+    flattener = GraphFlattener(graph, regallocs, _include_all_exc_links, cpu)
     flattener.enforce_input_args()
     flattener.generate_ssa_form()
     return flattener.ssarepr
@@ -71,9 +72,11 @@
 
 class GraphFlattener(object):
 
-    def __init__(self, graph, regallocs, _include_all_exc_links=False):
+    def __init__(self, graph, regallocs, _include_all_exc_links=False,
+                 cpu=None):
         self.graph = graph
         self.regallocs = regallocs
+        self.cpu = cpu
         self._include_all_exc_links = _include_all_exc_links
         self.registers = {}
         if graph:
@@ -100,7 +103,7 @@
         self.seen_blocks = {}
         self.make_bytecode_block(self.graph.startblock)
 
-    def make_bytecode_block(self, block):
+    def make_bytecode_block(self, block, handling_ovf=False):
         if block.exits == ():
             self.make_return(block.inputargs)
             return
@@ -122,7 +125,7 @@
                                     " is not legal in jitted blocks")
             self.serialize_op(op)
         #
-        self.insert_exits(block)
+        self.insert_exits(block, handling_ovf)
 
     def make_return(self, args):
         if len(args) == 1:
@@ -142,16 +145,16 @@
             raise Exception("?")
         self.emitline("---")
 
-    def make_link(self, link):
+    def make_link(self, link, handling_ovf):
         if (link.target.exits == ()
             and link.last_exception not in link.args
             and link.last_exc_value not in link.args):
             self.make_return(link.args)     # optimization only
             return
         self.insert_renamings(link)
-        self.make_bytecode_block(link.target)
+        self.make_bytecode_block(link.target, handling_ovf)
 
-    def make_exception_link(self, link):
+    def make_exception_link(self, link, handling_ovf):
         # Like make_link(), but also introduces the 'last_exception' and
         # 'last_exc_value' as variables if needed.  Also check if the link
         # is jumping directly to the re-raising exception block.
@@ -159,19 +162,26 @@
         assert link.last_exc_value is not None
         if link.target.operations == () and link.args == [link.last_exception,
                                                           link.last_exc_value]:
-            self.emitline("reraise")
+            if handling_ovf:
+                exc_data = self.cpu.rtyper.exceptiondata
+                ll_ovf = exc_data.get_standard_ll_exc_instance_by_class(
+                    OverflowError)
+                c = Constant(ll_ovf, concretetype=lltype.Void)
+                self.emitline("raise", c)
+            else:
+                self.emitline("reraise")
             self.emitline("---")
             return   # done
-        self.make_link(link)
+        self.make_link(link, handling_ovf)
 
-    def insert_exits(self, block):
+    def insert_exits(self, block, handling_ovf=False):
         if len(block.exits) == 1:
             # A single link, fall-through
             link = block.exits[0]
             assert link.exitcase in (None, False, True)
             # the cases False or True should not really occur, but can show
             # up in the manually hacked graphs for generators...
-            self.make_link(link)
+            self.make_link(link, handling_ovf)
         #
         elif block.canraise:
             # An exception block. See test_exc_exitswitch in test_flatten.py
@@ -185,9 +195,9 @@
                 self.emitline(opname[:7] + '_jump_if_ovf',
                               TLabel(block.exits[1]), *line[1:])
                 assert len(block.exits) == 2
-                self.make_link(block.exits[0])
+                self.make_link(block.exits[0], False)
                 self.emitline(Label(block.exits[1]))
-                self.make_exception_link(block.exits[1])
+                self.make_exception_link(block.exits[1], True)
                 return
             else:
                 while True:
@@ -201,22 +211,22 @@
                 if index == -1:
                     # cannot raise: the last instruction is not
                     # actually a '-live-'
-                    self.make_link(block.exits[0])
+                    self.make_link(block.exits[0], False)
                     return
             #
             self.emitline('catch_exception', TLabel(block.exits[0]))
-            self.make_link(block.exits[0])
+            self.make_link(block.exits[0], False)
             self.emitline(Label(block.exits[0]))
             for link in block.exits[1:]:
                 if link.exitcase is Exception:
                     # this link captures all exceptions
-                    self.make_exception_link(link)
+                    self.make_exception_link(link, False)
                     break
                 self.emitline('goto_if_exception_mismatch',
                               Constant(link.llexitcase,
                                        lltype.typeOf(link.llexitcase)),
                               TLabel(link))
-                self.make_exception_link(link)
+                self.make_exception_link(link, False)
                 self.emitline(Label(link))
             else:
                 # no link captures all exceptions, so we have to put a reraise
@@ -248,10 +258,10 @@
             #if not livebefore:
             #    self.emitline('-live-', TLabel(linkfalse))
             # true path:
-            self.make_link(linktrue)
+            self.make_link(linktrue, handling_ovf)
             # false path:
             self.emitline(Label(linkfalse))
-            self.make_link(linkfalse)
+            self.make_link(linkfalse, handling_ovf)
         #
         else:
             # A switch.
@@ -274,7 +284,7 @@
                                     switchdict)
             # emit the default path
             if block.exits[-1].exitcase == 'default':
-                self.make_link(block.exits[-1])
+                self.make_link(block.exits[-1], handling_ovf)
             else:
                 self.emitline("unreachable")
                 self.emitline("---")
@@ -288,7 +298,7 @@
                 # if the switched value doesn't match any case.
                 self.emitline(Label(switch))
                 self.emitline('-live-')
-                self.make_link(switch)
+                self.make_link(switch, handling_ovf)
 
     def insert_renamings(self, link):
         renamings = {}
diff --git a/rpython/jit/codewriter/test/test_flatten.py 
b/rpython/jit/codewriter/test/test_flatten.py
--- a/rpython/jit/codewriter/test/test_flatten.py
+++ b/rpython/jit/codewriter/test/test_flatten.py
@@ -140,6 +140,7 @@
 
     def encoding_test(self, func, args, expected,
                       transform=False, liveness=False, cc=None, jd=None):
+        
         graphs = self.make_graphs(func, args)
         #graphs[0].show()
         if transform:
@@ -147,7 +148,8 @@
             cc = cc or FakeCallControl()
             transform_graph(graphs[0], FakeCPU(self.rtyper), cc, jd)
         ssarepr = flatten_graph(graphs[0], fake_regallocs(),
-                                _include_all_exc_links=not transform)
+                                _include_all_exc_links=not transform,
+                                cpu=FakeCPU(self.rtyper))
         if liveness:
             from rpython.jit.codewriter.liveness import compute_liveness
             compute_liveness(ssarepr)
@@ -576,6 +578,21 @@
                              "transform=True, liveness=True)")
         assert "ovfcheck()" in str(err)
 
+    def test_ovfcheck_reraise(self):
+        def f(i, j):
+            try:
+                ovfcheck(j + i)
+            except OverflowError:
+                raise
+        self.encoding_test(f, [7, 2], """
+            -live- %i0, %i1
+            int_add_jump_if_ovf L1, %i1, %i0 -> %i2
+            void_return
+            ---
+            L1:
+            raise $<* struct object { typeptr=... }>
+        """, transform=True, liveness=True)
+
     def test_residual_call_raising(self):
         @dont_look_inside
         def g(i, j):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to