[pypy-commit] pypy jit-cleanup: kill cast_instance_to_base_ref, cast_to_ref and simplify some code
rlamy
pypy.commits at gmail.com
Mon Apr 1 11:50:07 EDT 2019
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: jit-cleanup
Changeset: r96396:d35167b4bf4e
Date: 2019-04-01 05:58 +0100
http://bitbucket.org/pypy/pypy/changeset/d35167b4bf4e/
Log: kill cast_instance_to_base_ref, cast_to_ref and simplify some code
diff --git a/rpython/jit/metainterp/compile.py b/rpython/jit/metainterp/compile.py
--- a/rpython/jit/metainterp/compile.py
+++ b/rpython/jit/metainterp/compile.py
@@ -1,6 +1,7 @@
import weakref
from rpython.rtyper.lltypesystem import lltype, llmemory
-from rpython.rtyper.annlowlevel import cast_instance_to_gcref
+from rpython.rtyper.annlowlevel import (
+ cast_instance_to_gcref, cast_gcref_to_instance)
from rpython.rlib.objectmodel import we_are_translated
from rpython.rlib.debug import debug_start, debug_stop, debug_print, have_debug_prints
from rpython.rlib.rarithmetic import r_uint, intmask
@@ -931,15 +932,12 @@
def __init__(self, cache):
self.cache = cache
- def hide(self, cpu):
- ptr = cpu.ts.cast_instance_to_base_ref(self)
- return cpu.ts.cast_to_ref(ptr)
+ def hide(self):
+ return cast_instance_to_gcref(self)
@staticmethod
- def show(cpu, gcref):
- from rpython.rtyper.annlowlevel import cast_base_ptr_to_instance
- ptr = cpu.ts.cast_to_baseclass(gcref)
- return cast_base_ptr_to_instance(AllVirtuals, ptr)
+ def show(gcref):
+ return cast_gcref_to_instance(AllVirtuals, gcref)
def invent_fail_descr_for_op(opnum, optimizer, copied_from_descr=None):
if opnum == rop.GUARD_NOT_FORCED or opnum == rop.GUARD_NOT_FORCED_2:
@@ -974,7 +972,7 @@
# handle_async_forcing() just a moment ago.
from rpython.jit.metainterp.blackhole import resume_in_blackhole
hidden_all_virtuals = metainterp_sd.cpu.get_savedata_ref(deadframe)
- obj = AllVirtuals.show(metainterp_sd.cpu, hidden_all_virtuals)
+ obj = AllVirtuals.show(hidden_all_virtuals)
all_virtuals = obj.cache
if all_virtuals is None:
all_virtuals = ResumeDataDirectReader.VirtualCache([], [])
@@ -1017,8 +1015,7 @@
# Handle all_virtuals: keep them for later blackholing from the
# future failure of the GUARD_NOT_FORCED
obj = AllVirtuals(all_virtuals)
- hidden_all_virtuals = obj.hide(metainterp_sd.cpu)
- metainterp_sd.cpu.set_savedata_ref(deadframe, hidden_all_virtuals)
+ metainterp_sd.cpu.set_savedata_ref(deadframe, obj.hide())
class ResumeFromInterpDescr(ResumeDescr):
def __init__(self, original_greenkey):
diff --git a/rpython/jit/metainterp/history.py b/rpython/jit/metainterp/history.py
--- a/rpython/jit/metainterp/history.py
+++ b/rpython/jit/metainterp/history.py
@@ -1,6 +1,8 @@
import sys
from rpython.rtyper.extregistry import ExtRegistryEntry
from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
+from rpython.rtyper.annlowlevel import (
+ cast_gcref_to_instance, cast_instance_to_gcref)
from rpython.rlib.objectmodel import we_are_translated, Symbolic
from rpython.rlib.objectmodel import compute_unique_id, specialize
from rpython.rlib.rarithmetic import r_int64, is_valid_int
@@ -97,14 +99,11 @@
return '%r' % (self,)
def hide(self, cpu):
- descr_ptr = cpu.ts.cast_instance_to_base_ref(self)
- return cpu.ts.cast_to_ref(descr_ptr)
+ return cast_instance_to_gcref(self)
@staticmethod
def show(cpu, descr_gcref):
- from rpython.rtyper.annlowlevel import cast_base_ptr_to_instance
- descr_ptr = cpu.ts.cast_to_baseclass(descr_gcref)
- return cast_base_ptr_to_instance(AbstractDescr, descr_ptr)
+ return cast_gcref_to_instance(AbstractDescr, descr_gcref)
def get_vinfo(self):
raise NotImplementedError
diff --git a/rpython/jit/metainterp/quasiimmut.py b/rpython/jit/metainterp/quasiimmut.py
--- a/rpython/jit/metainterp/quasiimmut.py
+++ b/rpython/jit/metainterp/quasiimmut.py
@@ -1,8 +1,9 @@
from rpython.rtyper.lltypesystem import lltype, llmemory
from rpython.rtyper import rclass
-from rpython.rtyper.annlowlevel import cast_base_ptr_to_instance
-from rpython.jit.metainterp.history import AbstractDescr, ConstPtr, ConstInt,\
- ConstFloat
+from rpython.rtyper.annlowlevel import (
+ cast_base_ptr_to_instance, cast_gcref_to_instance, cast_instance_to_gcref)
+from rpython.jit.metainterp.history import (
+ AbstractDescr, ConstPtr, ConstInt, ConstFloat)
from rpython.rlib.objectmodel import we_are_translated
@@ -18,7 +19,7 @@
"""
qmut_gcref = cpu.bh_getfield_gc_r(gcref, mutatefielddescr)
if qmut_gcref:
- qmut = QuasiImmut.show(cpu, qmut_gcref)
+ qmut = QuasiImmut.show(qmut_gcref)
else:
qmut = QuasiImmut(cpu)
cpu.bh_setfield_gc_r(gcref, qmut.hide(), mutatefielddescr)
@@ -43,8 +44,7 @@
qmut_ref = cpu.bh_getfield_gc_r(p, mutatefielddescr)
if qmut_ref:
cpu.bh_setfield_gc_r(p, ConstPtr.value, mutatefielddescr)
- qmut_ptr = lltype.cast_opaque_ptr(rclass.OBJECTPTR, qmut_ref)
- qmut = cast_base_ptr_to_instance(QuasiImmut, qmut_ptr)
+ qmut = cast_gcref_to_instance(QuasiImmut, qmut_ref)
qmut.invalidate()
@@ -60,13 +60,11 @@
self.looptokens_wrefs = []
def hide(self):
- qmut_ptr = self.cpu.ts.cast_instance_to_base_ref(self)
- return self.cpu.ts.cast_to_ref(qmut_ptr)
+ return cast_instance_to_gcref(self)
@staticmethod
- def show(cpu, qmut_gcref):
- qmut_ptr = cpu.ts.cast_to_baseclass(qmut_gcref)
- return cast_base_ptr_to_instance(QuasiImmut, qmut_ptr)
+ def show(qmut_gcref):
+ return cast_gcref_to_instance(QuasiImmut, qmut_gcref)
def register_loop_token(self, wref_looptoken):
if len(self.looptokens_wrefs) > self.compress_limit:
diff --git a/rpython/jit/metainterp/typesystem.py b/rpython/jit/metainterp/typesystem.py
--- a/rpython/jit/metainterp/typesystem.py
+++ b/rpython/jit/metainterp/typesystem.py
@@ -1,7 +1,6 @@
from rpython.rtyper.lltypesystem import lltype, llmemory
from rpython.rtyper import rclass
from rpython.rtyper.annlowlevel import cast_base_ptr_to_instance, llstr
-from rpython.rtyper.annlowlevel import cast_instance_to_base_ptr
from rpython.jit.metainterp import history
from rpython.jit.codewriter import heaptracker
from rpython.rlib.objectmodel import r_dict, specialize
@@ -29,8 +28,6 @@
class LLTypeHelper(TypeSystemHelper):
name = 'lltype'
- cast_instance_to_base_ref = staticmethod(cast_instance_to_base_ptr)
- loops_done_with_this_frame_ref = None # patched by compile.py
def get_typeptr(self, obj):
return obj.typeptr
@@ -54,8 +51,7 @@
return llmemory.cast_ptr_to_adr(fnptr)
def cls_of_box(self, box):
- PTR = lltype.Ptr(rclass.OBJECT)
- obj = lltype.cast_opaque_ptr(PTR, box.getref_base())
+ obj = lltype.cast_opaque_ptr(rclass.OBJECTPTR, box.getref_base())
cls = llmemory.cast_ptr_to_adr(obj.typeptr)
return history.ConstInt(heaptracker.adr2int(cls))
@@ -70,11 +66,11 @@
def get_exception_obj(self, evaluebox):
# only works when translated
- obj = evaluebox.getref(lltype.Ptr(rclass.OBJECT))
+ obj = evaluebox.getref(rclass.OBJECTPTR)
return cast_base_ptr_to_instance(Exception, obj)
def cast_to_baseclass(self, value):
- return lltype.cast_opaque_ptr(lltype.Ptr(rclass.OBJECT), value)
+ return lltype.cast_opaque_ptr(rclass.OBJECTPTR, value)
@specialize.ll()
def getlength(self, array):
@@ -97,8 +93,10 @@
# the value type. Note that NULL is not allowed as a key.
def new_ref_dict(self):
return r_dict(rd_eq, rd_hash, simple_hash_eq=True)
+
def new_ref_dict_2(self):
return r_dict(rd_eq, rd_hash, simple_hash_eq=True)
+
def new_ref_dict_3(self):
return r_dict(rd_eq, rd_hash, simple_hash_eq=True)
@@ -110,10 +108,6 @@
return lltype.cast_opaque_ptr(TYPE, value)
cast_from_ref._annspecialcase_ = 'specialize:arg(1)'
- def cast_to_ref(self, value):
- return lltype.cast_opaque_ptr(llmemory.GCREF, value)
- cast_to_ref._annspecialcase_ = 'specialize:ll'
-
def getaddr_for_box(self, box):
return box.getaddr()
More information about the pypy-commit
mailing list