Author: Armin Rigo <ar...@tunes.org>
Branch: remove-raisingops
Changeset: r83914:e4d43e895c35
Date: 2016-04-26 17:17 +0200
http://bitbucket.org/pypy/pypy/changeset/e4d43e895c35/

Log:    More kills

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
@@ -103,7 +103,7 @@
         self.seen_blocks = {}
         self.make_bytecode_block(self.graph.startblock)
 
-    def make_bytecode_block(self, block, handling_ovf=False):
+    def make_bytecode_block(self, block):
         if block.exits == ():
             self.make_return(block.inputargs)
             return
@@ -117,15 +117,10 @@
         #
         operations = block.operations
         for i, op in enumerate(operations):
-            if '_ovf' in op.opname:
-                if (len(block.exits) not in (2, 3) or
-                    block.exitswitch is not c_last_exception):
-                    raise Exception("detected a block containing ovfcheck()"
-                                    " but no OverflowError is caught, this"
-                                    " is not legal in jitted blocks")
+            assert '_ovf' not in op.opname   # should not exist any more
             self.serialize_op(op)
         #
-        self.insert_exits(block, handling_ovf)
+        self.insert_exits(block)
 
     def make_return(self, args):
         if len(args) == 1:
@@ -145,16 +140,16 @@
             raise Exception("?")
         self.emitline("---")
 
-    def make_link(self, link, handling_ovf):
+    def make_link(self, link):
         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, handling_ovf)
+        self.make_bytecode_block(link.target)
 
-    def make_exception_link(self, link, handling_ovf):
+    def make_exception_link(self, link):
         # 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.
@@ -162,52 +157,31 @@
         assert link.last_exc_value is not None
         if link.target.operations == () and link.args == [link.last_exception,
                                                           link.last_exc_value]:
-            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.typeOf(ll_ovf))
-                self.emitline("raise", c)
-            else:
-                self.emitline("reraise")
+            self.emitline("reraise")
             self.emitline("---")
             return   # done
-        self.make_link(link, handling_ovf)
+        self.make_link(link)
 
-    def insert_exits(self, block, handling_ovf=False):
+    def insert_exits(self, block):
         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, handling_ovf)
+            self.make_link(link)
         #
         elif block.canraise:
             # An exception block. See test_exc_exitswitch in test_flatten.py
             # for an example of what kind of code this makes.
             index = -1
             opname = block.operations[index].opname
-            if '_ovf' in opname:
-                # ovf checking operation as a lat thing, -live- should be
-                # one before it
-                line = self.popline()
-                self.emitline(opname[:7] + '_jump_if_ovf',
-                              TLabel(block.exits[1]), *line[1:])
-                assert len(block.exits) in (2, 3)
-                self.make_link(block.exits[0], False)
-                self.emitline(Label(block.exits[1]))
-                self.make_exception_link(block.exits[1], True)
-                if len(block.exits) == 3:
-                    assert block.exits[2].exitcase is Exception
-                    self.make_exception_link(block.exits[2], False)
-                return
-            else:
-                while True:
-                    lastopname = block.operations[index].opname
-                    if lastopname != '-live-':
-                        break
-                    index -= 1
+            assert '_ovf' not in opname    # should not exist any more
+            while True:
+                lastopname = block.operations[index].opname
+                if lastopname != '-live-':
+                    break
+                index -= 1
             assert block.exits[0].exitcase is None # is this always True?
             #
             if not self._include_all_exc_links:
@@ -261,10 +235,10 @@
             #if not livebefore:
             #    self.emitline('-live-', TLabel(linkfalse))
             # true path:
-            self.make_link(linktrue, handling_ovf)
+            self.make_link(linktrue)
             # false path:
             self.emitline(Label(linkfalse))
-            self.make_link(linkfalse, handling_ovf)
+            self.make_link(linkfalse)
         #
         else:
             # A switch.
@@ -287,7 +261,7 @@
                                     switchdict)
             # emit the default path
             if block.exits[-1].exitcase == 'default':
-                self.make_link(block.exits[-1], handling_ovf)
+                self.make_link(block.exits[-1])
             else:
                 self.emitline("unreachable")
                 self.emitline("---")
@@ -301,7 +275,7 @@
                 # if the switched value doesn't match any case.
                 self.emitline(Label(switch))
                 self.emitline('-live-')
-                self.make_link(switch, handling_ovf)
+                self.make_link(switch)
 
     def insert_renamings(self, link):
         renamings = {}
diff --git a/rpython/jit/codewriter/jtransform.py 
b/rpython/jit/codewriter/jtransform.py
--- a/rpython/jit/codewriter/jtransform.py
+++ b/rpython/jit/codewriter/jtransform.py
@@ -333,17 +333,6 @@
     rewrite_op_float_gt  = _rewrite_symmetric
     rewrite_op_float_ge  = _rewrite_symmetric
 
-    def rewrite_op_int_add_ovf(self, op):
-        op0 = self._rewrite_symmetric(op)
-        op1 = SpaceOperation('-live-', [], None)
-        return [op1, op0]
-
-    rewrite_op_int_mul_ovf = rewrite_op_int_add_ovf
-
-    def rewrite_op_int_sub_ovf(self, op):
-        op1 = SpaceOperation('-live-', [], None)
-        return [op1, op]
-
     def _noop_rewrite(self, op):
         return op
 
@@ -518,23 +507,12 @@
 
     # XXX some of the following functions should not become residual calls
     # but be really compiled
-    rewrite_op_int_floordiv_ovf_zer   = _do_builtin_call
-    rewrite_op_int_floordiv_ovf       = _do_builtin_call
-    rewrite_op_int_floordiv_zer       = _do_builtin_call
-    rewrite_op_int_mod_ovf_zer        = _do_builtin_call
-    rewrite_op_int_mod_ovf            = _do_builtin_call
-    rewrite_op_int_mod_zer            = _do_builtin_call
-    rewrite_op_int_lshift_ovf         = _do_builtin_call
     rewrite_op_int_abs                = _do_builtin_call
     rewrite_op_llong_abs              = _do_builtin_call
     rewrite_op_llong_floordiv         = _do_builtin_call
-    rewrite_op_llong_floordiv_zer     = _do_builtin_call
     rewrite_op_llong_mod              = _do_builtin_call
-    rewrite_op_llong_mod_zer          = _do_builtin_call
     rewrite_op_ullong_floordiv        = _do_builtin_call
-    rewrite_op_ullong_floordiv_zer    = _do_builtin_call
     rewrite_op_ullong_mod             = _do_builtin_call
-    rewrite_op_ullong_mod_zer         = _do_builtin_call
     rewrite_op_gc_identityhash        = _do_builtin_call
     rewrite_op_gc_id                  = _do_builtin_call
     rewrite_op_gc_pin                 = _do_builtin_call
@@ -1499,7 +1477,6 @@
     for _old, _new in [('bool_not', 'int_is_zero'),
                        ('cast_bool_to_float', 'cast_int_to_float'),
 
-                       ('int_add_nonneg_ovf', 'int_add_ovf'),
                        ('keepalive', '-live-'),
 
                        ('char_lt', 'int_lt'),
@@ -1532,12 +1509,6 @@
                 return self.rewrite_operation(op1)
         ''' % (_old, _new)).compile()
 
-    def rewrite_op_int_neg_ovf(self, op):
-        op1 = SpaceOperation('int_sub_ovf',
-                             [Constant(0, lltype.Signed), op.args[0]],
-                             op.result)
-        return self.rewrite_operation(op1)
-
     def rewrite_op_float_is_true(self, op):
         op1 = SpaceOperation('float_ne',
                              [op.args[0], Constant(0.0, lltype.Float)],
diff --git a/rpython/jit/codewriter/support.py 
b/rpython/jit/codewriter/support.py
--- a/rpython/jit/codewriter/support.py
+++ b/rpython/jit/codewriter/support.py
@@ -243,45 +243,6 @@
     return llop.jit_force_virtual(lltype.typeOf(inst), inst)
 
 
-def _ll_2_int_floordiv_ovf_zer(x, y):
-    if y == 0:
-        raise ZeroDivisionError
-    return _ll_2_int_floordiv_ovf(x, y)
-
-def _ll_2_int_floordiv_ovf(x, y):
-    # intentionally not short-circuited to produce only one guard
-    # and to remove the check fully if one of the arguments is known
-    if (x == -sys.maxint - 1) & (y == -1):
-        raise OverflowError
-    return llop.int_floordiv(lltype.Signed, x, y)
-
-def _ll_2_int_floordiv_zer(x, y):
-    if y == 0:
-        raise ZeroDivisionError
-    return llop.int_floordiv(lltype.Signed, x, y)
-
-def _ll_2_int_mod_ovf_zer(x, y):
-    if y == 0:
-        raise ZeroDivisionError
-    return _ll_2_int_mod_ovf(x, y)
-
-def _ll_2_int_mod_ovf(x, y):
-    #see comment in _ll_2_int_floordiv_ovf
-    if (x == -sys.maxint - 1) & (y == -1):
-        raise OverflowError
-    return llop.int_mod(lltype.Signed, x, y)
-
-def _ll_2_int_mod_zer(x, y):
-    if y == 0:
-        raise ZeroDivisionError
-    return llop.int_mod(lltype.Signed, x, y)
-
-def _ll_2_int_lshift_ovf(x, y):
-    result = x << y
-    if (result >> y) != x:
-        raise OverflowError
-    return result
-
 def _ll_1_int_abs(x):
     # this version doesn't branch
     mask = x >> (LONG_BIT - 1)
@@ -455,48 +416,21 @@
 def _ll_2_llong_floordiv(xll, yll):
     return llop.llong_floordiv(lltype.SignedLongLong, xll, yll)
 
-def _ll_2_llong_floordiv_zer(xll, yll):
-    if yll == 0:
-        raise ZeroDivisionError
-    return llop.llong_floordiv(lltype.SignedLongLong, xll, yll)
-
 def _ll_2_llong_mod(xll, yll):
     return llop.llong_mod(lltype.SignedLongLong, xll, yll)
 
-def _ll_2_llong_mod_zer(xll, yll):
-    if yll == 0:
-        raise ZeroDivisionError
-    return llop.llong_mod(lltype.SignedLongLong, xll, yll)
-
 def _ll_2_ullong_floordiv(xll, yll):
     return llop.ullong_floordiv(lltype.UnsignedLongLong, xll, yll)
 
-def _ll_2_ullong_floordiv_zer(xll, yll):
-    if yll == 0:
-        raise ZeroDivisionError
-    return llop.ullong_floordiv(lltype.UnsignedLongLong, xll, yll)
-
 def _ll_2_ullong_mod(xll, yll):
     return llop.ullong_mod(lltype.UnsignedLongLong, xll, yll)
 
-def _ll_2_ullong_mod_zer(xll, yll):
-    if yll == 0:
-        raise ZeroDivisionError
-    return llop.ullong_mod(lltype.UnsignedLongLong, xll, yll)
-
 def _ll_2_uint_mod(xll, yll):
     return llop.uint_mod(lltype.Unsigned, xll, yll)
 
 
 # in the following calls to builtins, the JIT is allowed to look inside:
 inline_calls_to = [
-    ('int_floordiv_ovf_zer', [lltype.Signed, lltype.Signed], lltype.Signed),
-    ('int_floordiv_ovf',     [lltype.Signed, lltype.Signed], lltype.Signed),
-    ('int_floordiv_zer',     [lltype.Signed, lltype.Signed], lltype.Signed),
-    ('int_mod_ovf_zer',      [lltype.Signed, lltype.Signed], lltype.Signed),
-    ('int_mod_ovf',          [lltype.Signed, lltype.Signed], lltype.Signed),
-    ('int_mod_zer',          [lltype.Signed, lltype.Signed], lltype.Signed),
-    ('int_lshift_ovf',       [lltype.Signed, lltype.Signed], lltype.Signed),
     ('int_abs',              [lltype.Signed],                lltype.Signed),
     ('ll_math.ll_math_sqrt', [lltype.Float],                 lltype.Float),
 ]
diff --git a/rpython/rtyper/llinterp.py b/rpython/rtyper/llinterp.py
--- a/rpython/rtyper/llinterp.py
+++ b/rpython/rtyper/llinterp.py
@@ -1063,95 +1063,6 @@
     def op_track_alloc_stop(self, addr):
         checkadr(addr)
 
-    # ____________________________________________________________
-    # Overflow-detecting variants
-
-    def op_int_neg_ovf(self, x):
-        assert is_valid_int(x)
-        try:
-            return ovfcheck(-x)
-        except OverflowError:
-            self.make_llexception()
-
-    def op_int_abs_ovf(self, x):
-        assert is_valid_int(x)
-        try:
-            return ovfcheck(abs(x))
-        except OverflowError:
-            self.make_llexception()
-
-    def op_int_lshift_ovf(self, x, y):
-        assert is_valid_int(x)
-        assert is_valid_int(y)
-        try:
-            return ovfcheck(x << y)
-        except OverflowError:
-            self.make_llexception()
-
-    def _makefunc2(fn, operator, xtype, ytype=None):
-        import sys
-        d = sys._getframe(1).f_locals
-        if ytype is None:
-            ytype = xtype
-        if '_ovf' in fn:
-            checkfn = 'ovfcheck'
-        elif fn.startswith('op_int_'):
-            checkfn = 'intmask'
-        else:
-            checkfn = ''
-        if operator == '//':
-            code = '''r = %(checkfn)s(x // y)
-                if x^y < 0 and x%%y != 0:
-                    r += 1
-                return r
-                ''' % locals()
-        elif operator == '%':
-            ## overflow check on % does not work with emulated int
-            code = '''%(checkfn)s(x // y)
-                r = x %% y
-                if x^y < 0 and x%%y != 0:
-                    r -= y
-                return r
-                ''' % locals()
-        else:
-            code = 'return %(checkfn)s(x %(operator)s y)' % locals()
-        exec py.code.Source("""
-        def %(fn)s(self, x, y):
-            assert isinstance(x, %(xtype)s)
-            assert isinstance(y, %(ytype)s)
-            try:
-                %(code)s
-            except (OverflowError, ValueError, ZeroDivisionError):
-                self.make_llexception()
-        """ % locals()).compile() in globals(), d
-
-    _makefunc2('op_int_add_ovf', '+', '(int, long, llmemory.AddressOffset)')
-    _makefunc2('op_int_mul_ovf', '*', '(int, long, llmemory.AddressOffset)', 
'(int, long)')
-    _makefunc2('op_int_sub_ovf',          '-',  '(int, long)')
-    _makefunc2('op_int_floordiv_ovf',     '//', '(int, long)')  # XXX negative 
args
-    _makefunc2('op_int_floordiv_zer',     '//', '(int, long)')  # can get 
off-by-one
-    _makefunc2('op_int_floordiv_ovf_zer', '//', '(int, long)')  # (see 
op_int_floordiv)
-    _makefunc2('op_int_mod_ovf',          '%',  '(int, long)')
-    _makefunc2('op_int_mod_zer',          '%',  '(int, long)')
-    _makefunc2('op_int_mod_ovf_zer',      '%',  '(int, long)')
-
-    _makefunc2('op_uint_floordiv_zer',    '//', 'r_uint')
-    _makefunc2('op_uint_mod_zer',         '%',  'r_uint')
-
-    _makefunc2('op_llong_floordiv_zer',   '//', 'r_longlong')
-    _makefunc2('op_llong_mod_zer',        '%',  'r_longlong')
-
-    _makefunc2('op_ullong_floordiv_zer',  '//', 'r_ulonglong')
-    _makefunc2('op_ullong_mod_zer',       '%',  'r_ulonglong')
-
-    _makefunc2('op_lllong_floordiv_zer',   '//', 'r_longlonglong')
-    _makefunc2('op_lllong_mod_zer',        '%',  'r_longlonglong')
-
-    def op_int_add_nonneg_ovf(self, x, y):
-        if isinstance(y, int):
-            assert y >= 0
-        return self.op_int_add_ovf(x, y)
-
     def op_int_is_true(self, x):
         # special case
         if type(x) is CDefinedIntSymbolic:
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to