[pypy-svn] r63770 - in pypy/branch/pyjitpl5-simplify/pypy/jit: backend/llgraph backend/test backend/x86 metainterp
fijal at codespeak.net
fijal at codespeak.net
Tue Apr 7 06:40:10 CEST 2009
Author: fijal
Date: Tue Apr 7 06:40:07 2009
New Revision: 63770
Modified:
pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/llimpl.py
pypy/branch/pyjitpl5-simplify/pypy/jit/backend/test/runner.py
pypy/branch/pyjitpl5-simplify/pypy/jit/backend/x86/assembler.py
pypy/branch/pyjitpl5-simplify/pypy/jit/backend/x86/regalloc.py
pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/compile.py
pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/resoperation.py
Log:
implement reversed guards. The rationale behind having separate operations
is that it makes assembler simpler. I couldn't come up with a test showing
this behavior in a wild, please feel free to write new ones.
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/llimpl.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/llimpl.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/llimpl.py Tue Apr 7 06:40:07 2009
@@ -510,6 +510,14 @@
if value.typeptr != expected_class:
raise GuardFailed
+ def op_guard_class_inverse(self, _, value, expected_class):
+ value = lltype.cast_opaque_ptr(rclass.OBJECTPTR, value)
+ expected_class = llmemory.cast_adr_to_ptr(
+ cast_int_to_adr(self.memocast, expected_class),
+ rclass.CLASSTYPE)
+ if value.typeptr == expected_class:
+ raise GuardFailed
+
def op_guard_value(self, _, value, expected_value):
if value != expected_value:
raise GuardFailed
@@ -528,7 +536,11 @@
if _last_exception:
raise GuardFailed
- def op_guard_exception(self, _, expected_exception):
+ def op_guard_no_exception_inverse(self, _):
+ if _last_exception is None:
+ raise GuardFailed
+
+ def _check_exception(self, expected_exception):
global _last_exception
expected_exception = llmemory.cast_adr_to_ptr(
cast_int_to_adr(self.memocast, expected_exception),
@@ -542,8 +554,16 @@
_last_exception = None
return exc.args[1]
else:
+ return None
+
+ def op_guard_exception(self, _, expected_exception):
+ if self._check_exception(expected_exception) is None:
raise GuardFailed
+ def op_guard_exception_inverse(self, _, expected_exception):
+ if self._check_exception(expected_exception) is not None:
+ raise GuardFailed
+
# ----------
# delegating to the builtins do_xxx() (done automatically for simple cases)
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/backend/test/runner.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/backend/test/runner.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/backend/test/runner.py Tue Apr 7 06:40:07 2009
@@ -140,9 +140,8 @@
null_box = ConstPtr(lltype.cast_opaque_ptr(llmemory.GCREF, lltype.nullptr(T)))
self.execute_operation(rop.GUARD_CLASS, [t_box, T_box], 'void')
assert not self.cpu.guard_failed()
- #self.execute_operation(rop.GUARD_CLASS_INVERSE, [t_box, null_box],
- # 'void')
- #assert not self.cpu.guard_failed()
+ self.execute_operation(rop.GUARD_CLASS_INVERSE, [t_box, null_box],
+ 'void')
def test_failing_guards(self):
vtable_for_T = lltype.malloc(MY_VTABLE, immortal=True)
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/backend/x86/assembler.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/backend/x86/assembler.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/backend/x86/assembler.py Tue Apr 7 06:40:07 2009
@@ -628,15 +628,26 @@
self.mc.TEST(loc, loc)
self.implement_guard(addr, op, self.mc.JNZ)
- def genop_guard_guard_exception(self, op, ign_1, addr, locs, resloc):
+ def genop_guard_guard_no_exception_inverse(self, op, ign_1, addr, locs, ign_2):
loc = locs[0]
- loc1 = locs[1]
- self.mc.MOV(loc1, heap(self._exception_addr))
- self.mc.CMP(loc1, loc)
- self.implement_guard(addr, op, self.mc.JNE)
- if resloc is not None:
- self.mc.MOV(resloc, addr_add(imm(self._exception_addr), imm(WORD)))
- self.mc.MOV(heap(self._exception_addr), imm(0))
+ self.mc.MOV(loc, heap(self._exception_addr))
+ self.mc.TEST(loc, loc)
+ self.implement_guard(addr, op, self.mc.JZ)
+
+ def _new_guard_exception(cond):
+ def _guard_exception(self, op, ign_1, addr, locs, resloc):
+ loc = locs[0]
+ loc1 = locs[1]
+ self.mc.MOV(loc1, heap(self._exception_addr))
+ self.mc.CMP(loc1, loc)
+ self.implement_guard(addr, op, getattr(self.mc, cond))
+ if resloc is not None:
+ self.mc.MOV(resloc, addr_add(imm(self._exception_addr), imm(WORD)))
+ self.mc.MOV(heap(self._exception_addr), imm(0))
+ return _guard_exception
+
+ genop_guard_guard_exception = _new_guard_exception('JNE')
+ genop_guard_guard_exception_inverse = _new_guard_exception('JE')
def genop_guard_guard_false(self, op, ign_1, addr, locs, ign_2):
loc = locs[0]
@@ -656,6 +667,11 @@
self.mc.CMP(mem(locs[0], offset), locs[1])
self.implement_guard(addr, op, self.mc.JNE)
+ def genop_guard_guard_class_inverse(self, op, ign_1, addr, locs, ign_2):
+ offset = 0 # XXX for now, the vtable ptr is at the start of the obj
+ self.mc.CMP(mem(locs[0], offset), locs[1])
+ self.implement_guard(addr, op, self.mc.JE)
+
#def genop_discard_guard_nonvirtualized(self, op):
# STRUCT = op.args[0].concretetype.TO
# offset, size = symbolic.get_field_token(STRUCT, 'vable_rti')
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/backend/x86/regalloc.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/backend/x86/regalloc.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/backend/x86/regalloc.py Tue Apr 7 06:40:07 2009
@@ -626,6 +626,8 @@
self.eventually_free_vars(op.inputargs)
self.eventually_free_var(box)
+ consider_guard_no_exception_inverse = consider_guard_no_exception
+
def consider_guard_exception(self, op, ignored):
loc = self.make_sure_var_in_reg(op.args[0], [])
box = TempBox()
@@ -641,6 +643,8 @@
self.eventually_free_vars(op.args)
self.eventually_free_var(box)
+ consider_guard_exception_inverse = consider_guard_exception
+
#def consider_guard2(self, op, ignored):
# loc1, ops1 = self.make_sure_var_in_reg(op.args[0], [])
# loc2, ops2 = self.make_sure_var_in_reg(op.args[1], [])
@@ -676,6 +680,8 @@
self.perform_guard(op, regalloc, [x, y], None)
self.eventually_free_vars(op.inputargs)
self.eventually_free_vars(op.args)
+
+ consider_guard_class_inverse = consider_guard_class
def _consider_binop_part(self, op, ignored):
x = op.args[0]
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/compile.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/compile.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/compile.py Tue Apr 7 06:40:07 2009
@@ -290,6 +290,16 @@
guard_op = ResOperation(rop.GUARD_FALSE, guard_op.args, None)
elif guard_op.opnum == rop.GUARD_FALSE:
guard_op = ResOperation(rop.GUARD_TRUE, guard_op.args, None)
+ elif guard_op.opnum == rop.GUARD_EXCEPTION:
+ guard_op = ResOperation(rop.GUARD_EXCEPTION_INVERSE, guard_op.args,
+ None)
+ elif guard_op.opnum == rop.GUARD_VALUE:
+ guard_op = ResOperation(rop.GUARD_VALUE_INVERSE, guard_op.args, None)
+ elif guard_op.opnum == rop.GUARD_NO_EXCEPTION:
+ guard_op = ResOperation(rop.GUARD_NO_EXCEPTION_INVERSE, guard_op.args,
+ None)
+ elif guard_op.opnum == rop.GUARD_CLASS:
+ guard_op = ResOperation(rop.GUARD_CLASS_INVERSE, guard_op.args, None)
else:
# XXX other guards have no inverse so far
raise InverseTheOtherGuardsPlease(guard_op)
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/resoperation.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/resoperation.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/resoperation.py Tue Apr 7 06:40:07 2009
@@ -88,17 +88,20 @@
_FINAL_FIRST = 1
JUMP = 1
FAIL = 2
- _FINAL_LAST = 9
+ _FINAL_LAST = 3
- _GUARD_FIRST = 10 # ----- start of guard operations -----
- GUARD_TRUE = 10
- GUARD_FALSE = 11
- GUARD_VALUE = 12
- GUARD_CLASS = 13
- GUARD_NONVIRTUALIZED = 14
- GUARD_NO_EXCEPTION = 15
- GUARD_EXCEPTION = 16
- GUARD_VALUE_INVERSE = 17
+ _GUARD_FIRST = 8 # ----- start of guard operations -----
+ GUARD_TRUE = 8
+ GUARD_FALSE = 9
+ GUARD_VALUE = 10
+ GUARD_CLASS = 11
+ GUARD_NONVIRTUALIZED = 12
+ GUARD_NO_EXCEPTION = 13
+ GUARD_EXCEPTION = 14
+ GUARD_VALUE_INVERSE = 15
+ GUARD_CLASS_INVERSE = 16
+ GUARD_EXCEPTION_INVERSE = 17
+ GUARD_NO_EXCEPTION_INVERSE = 18
_GUARD_LAST = 19 # ----- end of guard operations -----
_NOSIDEEFFECT_FIRST = 20 # ----- start of no_side_effect operations -----
More information about the Pypy-commit
mailing list