[pypy-commit] pypy jit-cleanup: Create ptr2int() helper
rlamy
pypy.commits at gmail.com
Fri Apr 5 13:14:22 EDT 2019
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: jit-cleanup
Changeset: r96421:8e5f665823d9
Date: 2019-04-05 03:36 +0100
http://bitbucket.org/pypy/pypy/changeset/8e5f665823d9/
Log: Create ptr2int() helper
diff --git a/rpython/jit/backend/llgraph/runner.py b/rpython/jit/backend/llgraph/runner.py
--- a/rpython/jit/backend/llgraph/runner.py
+++ b/rpython/jit/backend/llgraph/runner.py
@@ -9,7 +9,7 @@
from rpython.jit.metainterp.resoperation import rop
from rpython.jit.metainterp.optimizeopt import intbounds
from rpython.jit.metainterp.optimize import SpeculativeError
-from rpython.jit.metainterp.support import adr2int, int2adr, int_signext
+from rpython.jit.metainterp.support import ptr2int, int_signext
from rpython.jit.codewriter import longlong, heaptracker
from rpython.jit.codewriter.effectinfo import EffectInfo
@@ -137,7 +137,7 @@
if self._vtable is Ellipsis:
self._vtable = heaptracker.get_vtable_for_gcstruct(self._runner,
self.S)
- return adr2int(llmemory.cast_ptr_to_adr(self._vtable))
+ return ptr2int(self._vtable)
def is_immutable(self):
return heaptracker.is_immutable_struct(self.S)
@@ -877,8 +877,7 @@
def bh_classof(self, struct):
struct = lltype.cast_opaque_ptr(rclass.OBJECTPTR, struct)
- result_adr = llmemory.cast_ptr_to_adr(struct.typeptr)
- return adr2int(result_adr)
+ return ptr2int(struct.typeptr)
# vector operations
vector_arith_code = """
@@ -1552,13 +1551,12 @@
return res
def execute_restore_exception(self, descr, kls, e):
- kls = int2adr(kls)
if e:
value = lltype.cast_opaque_ptr(rclass.OBJECTPTR, e)
- assert llmemory.cast_ptr_to_adr(value.typeptr) == kls
+ assert ptr2int(value.typeptr) == kls
lle = LLException(value.typeptr, e)
else:
- assert kls == llmemory.NULL
+ assert kls == 0
lle = None
self.last_exception = lle
diff --git a/rpython/jit/backend/llgraph/support.py b/rpython/jit/backend/llgraph/support.py
--- a/rpython/jit/backend/llgraph/support.py
+++ b/rpython/jit/backend/llgraph/support.py
@@ -1,6 +1,6 @@
from rpython.jit.codewriter import longlong
-from rpython.jit.metainterp.support import adr2int
+from rpython.jit.metainterp.support import adr2int, ptr2int
from rpython.jit.metainterp.history import getkind
from rpython.rlib.rarithmetic import r_longlong, r_ulonglong, r_uint
@@ -19,7 +19,7 @@
def cast_to_int(x):
TP = lltype.typeOf(x)
if isinstance(TP, lltype.Ptr):
- return adr2int(llmemory.cast_ptr_to_adr(x))
+ return ptr2int(x)
if TP == llmemory.Address:
return adr2int(x)
if TP is lltype.SingleFloat:
diff --git a/rpython/jit/backend/llsupport/descr.py b/rpython/jit/backend/llsupport/descr.py
--- a/rpython/jit/backend/llsupport/descr.py
+++ b/rpython/jit/backend/llsupport/descr.py
@@ -4,7 +4,7 @@
from rpython.jit.backend.llsupport import symbolic, support
from rpython.jit.metainterp.history import AbstractDescr, getkind, FLOAT, INT
from rpython.jit.metainterp import history
-from rpython.jit.metainterp.support import adr2int, int2adr
+from rpython.jit.metainterp.support import ptr2int, int2adr
from rpython.jit.codewriter import heaptracker, longlong
from rpython.jit.codewriter.longlong import is_longlong
from rpython.jit.metainterp.optimizeopt import intbounds
@@ -96,7 +96,7 @@
return self.immutable_flag
def get_vtable(self):
- return adr2int(llmemory.cast_ptr_to_adr(self.vtable))
+ return ptr2int(self.vtable)
def get_type_id(self):
assert self.tid
diff --git a/rpython/jit/backend/llsupport/gc.py b/rpython/jit/backend/llsupport/gc.py
--- a/rpython/jit/backend/llsupport/gc.py
+++ b/rpython/jit/backend/llsupport/gc.py
@@ -11,7 +11,7 @@
from rpython.jit.codewriter import heaptracker
from rpython.jit.metainterp.history import ConstPtr, AbstractDescr, ConstInt
from rpython.jit.metainterp.resoperation import rop, ResOperation
-from rpython.jit.metainterp.support import adr2int
+from rpython.jit.metainterp.support import ptr2int
from rpython.jit.backend.llsupport import symbolic, jitframe
from rpython.jit.backend.llsupport.symbolic import WORD
from rpython.jit.backend.llsupport.descr import SizeDescr, ArrayDescr, FieldDescr
@@ -67,7 +67,7 @@
@specialize.arg(1)
def get_malloc_fn_addr(self, funcname):
ll_func = self.get_malloc_fn(funcname)
- return adr2int(llmemory.cast_ptr_to_adr(ll_func))
+ return ptr2int(ll_func)
def _freeze_(self):
return True
diff --git a/rpython/jit/backend/llsupport/llmodel.py b/rpython/jit/backend/llsupport/llmodel.py
--- a/rpython/jit/backend/llsupport/llmodel.py
+++ b/rpython/jit/backend/llsupport/llmodel.py
@@ -8,7 +8,7 @@
from rpython.rlib.objectmodel import we_are_translated, specialize, compute_hash
from rpython.jit.metainterp import history, compile
from rpython.jit.metainterp.optimize import SpeculativeError
-from rpython.jit.metainterp.support import adr2int
+from rpython.jit.metainterp.support import adr2int, ptr2int
from rpython.jit.codewriter import longlong
from rpython.jit.backend.model import AbstractCPU
from rpython.jit.backend.llsupport import symbolic, jitframe
@@ -159,7 +159,7 @@
graph = mixlevelann.getgraph(realloc_frame, args_s, s_result)
fptr = mixlevelann.graph2delayed(graph, FUNC)
mixlevelann.finish()
- self.realloc_frame = adr2int(llmemory.cast_ptr_to_adr(fptr))
+ self.realloc_frame = ptr2int(fptr)
if not translate_support_code:
fptr = llhelper(FUNC_TP, realloc_frame_crash)
@@ -171,7 +171,7 @@
graph = mixlevelann.getgraph(realloc_frame_crash, args_s, s_result)
fptr = mixlevelann.graph2delayed(graph, FUNC)
mixlevelann.finish()
- self.realloc_frame_crash = adr2int(llmemory.cast_ptr_to_adr(fptr))
+ self.realloc_frame_crash = ptr2int(fptr)
def _setup_exception_handling_untranslated(self):
# for running un-translated only, all exceptions occurring in the
@@ -775,8 +775,7 @@
def bh_classof(self, struct):
struct = lltype.cast_opaque_ptr(rclass.OBJECTPTR, struct)
- result_adr = llmemory.cast_ptr_to_adr(struct.typeptr)
- return adr2int(result_adr)
+ return ptr2int(struct.typeptr)
def bh_new_array(self, length, arraydescr):
return self.gc_ll_descr.gc_malloc_array(length, arraydescr)
diff --git a/rpython/jit/backend/llsupport/rewrite.py b/rpython/jit/backend/llsupport/rewrite.py
--- a/rpython/jit/backend/llsupport/rewrite.py
+++ b/rpython/jit/backend/llsupport/rewrite.py
@@ -6,7 +6,7 @@
from rpython.jit.metainterp.history import (
ConstInt, ConstPtr, JitCellToken, new_ref_dict)
from rpython.jit.metainterp.resoperation import ResOperation, rop, OpHelpers
-from rpython.jit.metainterp.support import adr2int
+from rpython.jit.metainterp.support import ptr2int
from rpython.jit.backend.llsupport.symbolic import (WORD,
get_field_token, get_array_token)
from rpython.jit.backend.llsupport.descr import SizeDescr, ArrayDescr
@@ -606,11 +606,9 @@
descrs = self.gc_ll_descr.getframedescrs(self.cpu)
loop_token = op.getdescr()
assert isinstance(loop_token, JitCellToken)
- jfi = loop_token.compiled_loop_token.frame_info
- llfi = adr2int(llmemory.cast_ptr_to_adr(jfi))
+ llfi = ptr2int(loop_token.compiled_loop_token.frame_info)
frame = self.gen_malloc_frame(llfi)
- self.emit_setfield(frame, ConstInt(llfi),
- descr=descrs.jf_frame_info)
+ self.emit_setfield(frame, ConstInt(llfi), descr=descrs.jf_frame_info)
arglist = op.getarglist()
index_list = loop_token.compiled_loop_token._ll_initial_locs
for i, arg in enumerate(arglist):
diff --git a/rpython/jit/backend/test/calling_convention_test.py b/rpython/jit/backend/test/calling_convention_test.py
--- a/rpython/jit/backend/test/calling_convention_test.py
+++ b/rpython/jit/backend/test/calling_convention_test.py
@@ -2,7 +2,7 @@
from rpython.jit.metainterp.history import BasicFinalDescr,\
JitCellToken, ConstInt, ConstFloat
from rpython.jit.metainterp.resoperation import rop, InputArgInt, InputArgFloat
-from rpython.jit.metainterp.support import adr2int
+from rpython.jit.metainterp.support import ptr2int
from rpython.jit.codewriter.effectinfo import EffectInfo
from rpython.jit.tool.oparser import parse
from rpython.rtyper.lltypesystem import lltype, llmemory
@@ -50,8 +50,7 @@
@classmethod
def get_funcbox(cls, cpu, func_ptr):
- addr = llmemory.cast_ptr_to_adr(func_ptr)
- return ConstInt(adr2int(addr))
+ return ConstInt(ptr2int(func_ptr))
def test_call_aligned_with_spilled_values(self):
cpu = self.cpu
diff --git a/rpython/jit/backend/test/runner_test.py b/rpython/jit/backend/test/runner_test.py
--- a/rpython/jit/backend/test/runner_test.py
+++ b/rpython/jit/backend/test/runner_test.py
@@ -11,7 +11,7 @@
from rpython.jit.metainterp.resoperation import (
ResOperation, rop, InputArgInt, InputArgFloat, InputArgRef)
from rpython.jit.metainterp.executor import wrap_constant
-from rpython.jit.metainterp.support import adr2int, int_signext
+from rpython.jit.metainterp.support import ptr2int, int_signext
from rpython.jit.codewriter.effectinfo import EffectInfo
from rpython.jit.tool.oparser import parse
from rpython.rtyper.lltypesystem import lltype, llmemory, rstr, rffi
@@ -1846,8 +1846,7 @@
@classmethod
def get_funcbox(cls, cpu, func_ptr):
- addr = llmemory.cast_ptr_to_adr(func_ptr)
- return ConstInt(adr2int(addr))
+ return ConstInt(ptr2int(func_ptr))
MY_VTABLE = rclass.OBJECT_VTABLE # for tests only
@@ -1869,7 +1868,6 @@
def alloc_instance(self, T):
if hasattr(T, 'parent'):
vtable_for_T = lltype.malloc(self.MY_VTABLE, immortal=True)
- vtable_for_T_addr = llmemory.cast_ptr_to_adr(vtable_for_T)
else:
vtable_for_T = lltype.nullptr(rclass.OBJECT_VTABLE)
cpu = self.cpu
@@ -1898,7 +1896,7 @@
T_box = None
else:
vtable = vtable_for_T
- T_box = ConstInt(adr2int(vtable_for_T_addr))
+ T_box = ConstInt(ptr2int(vtable_for_T_addr))
descr = cpu.sizeof(T, vtable)
return t_box, T_box, descr
@@ -1987,7 +1985,7 @@
def test_ooops_non_gc(self):
x = lltype.malloc(lltype.Struct('x'), flavor='raw')
- v = adr2int(llmemory.cast_ptr_to_adr(x))
+ v = ptr2int(x)
r = self.execute_operation(rop.PTR_EQ, [InputArgInt(v), InputArgInt(v)], 'int')
assert r == 1
r = self.execute_operation(rop.PTR_NE, [InputArgInt(v), InputArgInt(v)], 'int')
@@ -2779,8 +2777,7 @@
lltype.free(buffer, flavor='raw')
cpu = self.cpu
- func_adr = llmemory.cast_ptr_to_adr(c_GetCurrentDir.funcsym)
- funcbox = ConstInt(adr2int(func_adr))
+ funcbox = ConstInt(ptr2int(c_GetCurrentDir.funcsym))
calldescr = cpu._calldescr_dynamic_for_tests(
[types.ulong, types.pointer],
types.ulong,
@@ -3619,14 +3616,10 @@
descrfld_rx = cpu.fielddescrof(RS, 'x')
rs = lltype.malloc(RS, immortal=True)
rs.x = '?'
- x = cpu.bh_getfield_raw_i(
- adr2int(llmemory.cast_ptr_to_adr(rs)),
- descrfld_rx)
+ x = cpu.bh_getfield_raw_i(ptr2int(rs), descrfld_rx)
assert x == ord('?')
#
- cpu.bh_setfield_raw_i(
- adr2int(llmemory.cast_ptr_to_adr(rs)),
- ord('!'), descrfld_rx)
+ cpu.bh_setfield_raw_i(ptr2int(rs), ord('!'), descrfld_rx)
assert rs.x == '!'
#
@@ -3700,7 +3693,7 @@
def test_guards_nongc(self):
x = lltype.malloc(lltype.Struct('x'), flavor='raw')
- v = adr2int(llmemory.cast_ptr_to_adr(x))
+ v = ptr2int(x)
vbox = InputArgInt(v)
ops = [
(rop.GUARD_NONNULL, vbox, False),
@@ -3907,8 +3900,7 @@
descr = self.cpu.arraydescrof(ARRAY)
a = lltype.malloc(ARRAY, 10, flavor='raw')
a[7] = -4242
- addr = llmemory.cast_ptr_to_adr(a)
- abox = InputArgInt(adr2int(addr))
+ abox = InputArgInt(ptr2int(a))
r1 = self.execute_operation(rop.GETARRAYITEM_RAW_I, [abox, InputArgInt(7)],
'int', descr=descr)
assert r1 == -4242
@@ -3918,8 +3910,7 @@
ARRAY = rffi.CArray(lltype.Signed)
descr = self.cpu.arraydescrof(ARRAY)
a = lltype.malloc(ARRAY, 10, flavor='raw')
- addr = llmemory.cast_ptr_to_adr(a)
- abox = InputArgInt(adr2int(addr))
+ abox = InputArgInt(ptr2int(a))
self.execute_operation(rop.SETARRAYITEM_RAW, [abox, InputArgInt(5),
InputArgInt(12345)],
'void', descr=descr)
@@ -4193,7 +4184,7 @@
value = intmask(0xFFEEDDCCBBAA9988)
expected = rffi.cast(lltype.Signed, rffi.cast(RESTYPE, value))
a[3] = rffi.cast(RESTYPE, value)
- a_rawint = adr2int(llmemory.cast_ptr_to_adr(a))
+ a_rawint = ptr2int(a)
x = cpu.bh_getarrayitem_raw_i(a_rawint, 3, descrarray)
assert x == expected, (
"%r: got %r, expected %r" % (RESTYPE, x, expected))
@@ -4214,7 +4205,7 @@
value = intmask(0xFFEEDDCCBBAA9988)
expected = rffi.cast(lltype.Signed, rffi.cast(RESTYPE, value))
a[3] = rffi.cast(RESTYPE, value)
- a_rawint = adr2int(llmemory.cast_ptr_to_adr(a))
+ a_rawint = ptr2int(a)
res = self.execute_operation(rop.GETARRAYITEM_RAW_I,
[InputArgInt(a_rawint), InputArgInt(3)],
'int', descr=descrarray)
@@ -5069,8 +5060,7 @@
a = lltype.malloc(A, 2, flavor='raw')
a[0] = rffi.cast(rffi.SHORT, 666)
a[1] = rffi.cast(rffi.SHORT, 777)
- addr = llmemory.cast_ptr_to_adr(a)
- a_int = adr2int(addr)
+ a_int = ptr2int(a)
print 'a_int:', a_int
self.execute_operation(rop.SETARRAYITEM_RAW,
[ConstInt(a_int), ConstInt(0), ConstInt(-7654)],
@@ -5104,8 +5094,7 @@
A = lltype.GcArray(OF)
arraydescr = self.cpu.arraydescrof(A)
a = lltype.malloc(A, 100)
- addr = llmemory.cast_ptr_to_adr(a)
- a_int = adr2int(addr)
+ a_int = ptr2int(a)
a_ref = lltype.cast_opaque_ptr(llmemory.GCREF, a)
for (start, length) in [(0, 100), (49, 49), (1, 98),
(15, 9), (10, 10), (47, 0),
@@ -5260,7 +5249,7 @@
xptr = lltype.malloc(X)
xptr.parent.typeptr = xtp
x_box = InputArgRef(lltype.cast_opaque_ptr(llmemory.GCREF, xptr))
- X_box = ConstInt(adr2int(llmemory.cast_ptr_to_adr(xtp)))
+ X_box = ConstInt(ptr2int(xtp))
ytp = lltype.malloc(rclass.OBJECT_VTABLE, immortal=True)
ytp.subclassrange_min = 2
@@ -5271,7 +5260,7 @@
yptr = lltype.malloc(Y)
yptr.parent.parent.typeptr = ytp
y_box = InputArgRef(lltype.cast_opaque_ptr(llmemory.GCREF, yptr))
- Y_box = ConstInt(adr2int(llmemory.cast_ptr_to_adr(ytp)))
+ Y_box = ConstInt(ptr2int(ytp))
ztp = lltype.malloc(rclass.OBJECT_VTABLE, immortal=True)
ztp.subclassrange_min = 4
@@ -5283,7 +5272,7 @@
zptr = lltype.malloc(Z)
zptr.parent.typeptr = ztp
z_box = InputArgRef(lltype.cast_opaque_ptr(llmemory.GCREF, zptr))
- Z_box = ConstInt(adr2int(llmemory.cast_ptr_to_adr(ztp)))
+ Z_box = ConstInt(ptr2int(ztp))
for num, arg, klass, is_subclass in [
(1, x_box, X_box, True),
diff --git a/rpython/jit/backend/test/test_ll_random.py b/rpython/jit/backend/test/test_ll_random.py
--- a/rpython/jit/backend/test/test_ll_random.py
+++ b/rpython/jit/backend/test/test_ll_random.py
@@ -5,7 +5,7 @@
from rpython.jit.backend.test.test_random import getint, getref_base, getref
from rpython.jit.metainterp.resoperation import ResOperation, rop, optypes
from rpython.jit.metainterp.history import ConstInt, ConstPtr, getkind
-from rpython.jit.metainterp.support import adr2int
+from rpython.jit.metainterp.support import ptr2int
from rpython.jit.codewriter import heaptracker
from rpython.jit.codewriter.effectinfo import EffectInfo
from rpython.rtyper.annlowlevel import llhelper
@@ -219,9 +219,6 @@
# ____________________________________________________________
-def ConstAddr(addr):
- return ConstInt(adr2int(addr))
-
class GuardClassOperation(test_random.GuardOperation):
def gen_guard(self, builder, r):
ptrvars = [(v, S) for (v, S) in builder.ptrvars
@@ -236,7 +233,7 @@
v2, S2 = builder.get_structptr_var(r, must_have_vtable=True)
vtable = S._hints['vtable']._as_ptr()
vtable2 = S2._hints['vtable']._as_ptr()
- c_vtable2 = ConstAddr(llmemory.cast_ptr_to_adr(vtable2))
+ c_vtable2 = ConstInt(ptr2int(vtable2))
op = ResOperation(self.opnum, [v, c_vtable2], None)
return op, (vtable == vtable2)
@@ -250,7 +247,7 @@
builder.loop.operations.append(op)
v2, S2 = builder.get_structptr_var(r, must_have_vtable=True)
vtable2 = S2._hints['vtable']._as_ptr()
- c_vtable2 = ConstAddr(llmemory.cast_ptr_to_adr(vtable2))
+ c_vtable2 = ConstInt(ptr2int(vtable2))
op = ResOperation(self.opnum, [op, c_vtable2], None)
return op, False
@@ -571,7 +568,7 @@
sum = %s
return %s
""" % (funcargs, sum, result)).compile()
- d = {'intmask' : intmask}
+ d = {'intmask': intmask}
exec code in d
return subset, d['f']
@@ -587,8 +584,8 @@
vtableptr = v._hints['vtable']._as_ptr()
d = {
'ptr': getref_base(S),
- 'vtable' : vtableptr,
- 'LLException' : LLException,
+ 'vtable': vtableptr,
+ 'LLException': LLException,
}
exec code in d
return subset, d['f'], vtableptr
@@ -616,7 +613,7 @@
RES = self.getresulttype()
TP = lltype.FuncType([lltype.Signed] * len(subset), RES)
ptr = llhelper(lltype.Ptr(TP), f)
- c_addr = ConstAddr(llmemory.cast_ptr_to_adr(ptr))
+ c_addr = ConstInt(ptr2int(ptr))
args = [c_addr] + subset
descr = self.getcalldescr(builder, TP)
self.put(builder, args, descr)
@@ -633,12 +630,12 @@
RES = self.getresulttype()
TP = lltype.FuncType([lltype.Signed] * len(subset), RES)
ptr = llhelper(lltype.Ptr(TP), f)
- c_addr = ConstAddr(llmemory.cast_ptr_to_adr(ptr))
+ c_addr = ConstInt(ptr2int(ptr))
args = [c_addr] + subset
descr = self.getcalldescr(builder, TP)
self.put(builder, args, descr)
_, vtableptr = builder.get_random_structure_type_and_vtable(r)
- exc_box = ConstAddr(llmemory.cast_ptr_to_adr(vtableptr))
+ exc_box = ConstInt(ptr2int(vtableptr))
op = ResOperation(rop.GUARD_EXCEPTION, [exc_box],
descr=builder.getfaildescr())
op.setfailargs(builder.subset_of_intvars(r))
@@ -655,11 +652,11 @@
subset, f, exc = self.raising_func_code(builder, r)
TP = lltype.FuncType([lltype.Signed] * len(subset), lltype.Void)
ptr = llhelper(lltype.Ptr(TP), f)
- c_addr = ConstAddr(llmemory.cast_ptr_to_adr(ptr))
+ c_addr = ConstInt(ptr2int(ptr))
args = [c_addr] + subset
descr = self.getcalldescr(builder, TP)
self.put(builder, args, descr)
- exc_box = ConstAddr(llmemory.cast_ptr_to_adr(exc))
+ exc_box = ConstInt(ptr2int(exc))
op = ResOperation(rop.GUARD_EXCEPTION, [exc_box],
descr=builder.getfaildescr())
op.setfailargs(fail_subset)
@@ -672,13 +669,13 @@
subset, f, exc = self.raising_func_code(builder, r)
TP = lltype.FuncType([lltype.Signed] * len(subset), lltype.Void)
ptr = llhelper(lltype.Ptr(TP), f)
- c_addr = ConstAddr(llmemory.cast_ptr_to_adr(ptr))
+ c_addr = ConstInt(ptr2int(ptr))
args = [c_addr] + subset
descr = self.getcalldescr(builder, TP)
self.put(builder, args, descr)
op = ResOperation(rop.GUARD_NO_EXCEPTION, [],
descr=builder.getfaildescr())
- op._exc_box = ConstAddr(llmemory.cast_ptr_to_adr(exc))
+ op._exc_box = ConstInt(ptr2int(exc))
op.setfailargs(builder.subset_of_intvars(r))
builder.should_fail_by = op
builder.guard_op = op
@@ -691,7 +688,7 @@
subset, f, exc = self.raising_func_code(builder, r)
TP = lltype.FuncType([lltype.Signed] * len(subset), lltype.Void)
ptr = llhelper(lltype.Ptr(TP), f)
- c_addr = ConstAddr(llmemory.cast_ptr_to_adr(ptr))
+ c_addr = ConstInt(ptr2int(ptr))
args = [c_addr] + subset
descr = self.getcalldescr(builder, TP)
self.put(builder, args, descr)
@@ -699,10 +696,10 @@
_, vtableptr = builder.get_random_structure_type_and_vtable(r)
if vtableptr != exc:
break
- other_box = ConstAddr(llmemory.cast_ptr_to_adr(vtableptr))
+ other_box = ConstInt(ptr2int(vtableptr))
op = ResOperation(rop.GUARD_EXCEPTION, [other_box],
descr=builder.getfaildescr())
- op._exc_box = ConstAddr(llmemory.cast_ptr_to_adr(exc))
+ op._exc_box = ConstInt(ptr2int(exc))
op.setfailargs(builder.subset_of_intvars(r))
builder.should_fail_by = op
builder.guard_op = op
@@ -735,7 +732,7 @@
#
TP = lltype.FuncType([lltype.Signed] * len(subset), RESULT_TYPE)
ptr = llhelper(lltype.Ptr(TP), call_me)
- c_addr = ConstAddr(llmemory.cast_ptr_to_adr(ptr))
+ c_addr = ConstInt(ptr2int(ptr))
args = [v_cond, c_addr] + subset
descr = self.getcalldescr(builder, TP)
self.put(builder, args, descr)
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
@@ -7,7 +7,7 @@
from rpython.jit.metainterp import quasiimmut
from rpython.jit.metainterp.history import getkind
from rpython.jit.metainterp.blackhole import BlackholeInterpreter
-from rpython.jit.metainterp.support import adr2int
+from rpython.jit.metainterp.support import ptr2int
from rpython.flowspace.model import SpaceOperation, Variable, Constant
from rpython.rlib import objectmodel
from rpython.rlib.jit import _we_are_jitted
@@ -1955,8 +1955,7 @@
if isinstance(op.args[0].value, str):
pass # for tests only
else:
- func = adr2int(
- llmemory.cast_ptr_to_adr(op.args[0].value))
+ func = ptr2int(op.args[0].value)
self.callcontrol.callinfocollection.add(oopspecindex,
calldescr, func)
op1 = self.rewrite_call(op, 'residual_call',
@@ -1983,8 +1982,7 @@
if isinstance(c_func.value, str): # in tests only
func = c_func.value
else:
- func = adr2int(
- llmemory.cast_ptr_to_adr(c_func.value))
+ func = ptr2int(c_func.value)
self.callcontrol.callinfocollection.add(oopspecindex, calldescr, func)
def _handle_int_special(self, op, oopspec_name, args):
diff --git a/rpython/jit/codewriter/test/test_assembler.py b/rpython/jit/codewriter/test/test_assembler.py
--- a/rpython/jit/codewriter/test/test_assembler.py
+++ b/rpython/jit/codewriter/test/test_assembler.py
@@ -5,7 +5,7 @@
from rpython.jit.codewriter.jitcode import MissingLiveness
from rpython.jit.codewriter import longlong
from rpython.jit.metainterp.history import AbstractDescr
-from rpython.jit.metainterp.support import adr2int
+from rpython.jit.metainterp.support import ptr2int
from rpython.flowspace.model import Constant
from rpython.rtyper.lltypesystem import lltype, llmemory
from rpython.rlib.rarithmetic import r_int, r_uint
@@ -107,7 +107,7 @@
assert assembler.insns == {'int_return/c': 0,
'int_return/i': 1,
'ref_return/r': 2}
- f_int = adr2int(llmemory.cast_ptr_to_adr(f))
+ f_int = ptr2int(f)
assert jitcode.constants_i == [0x1234, f_int]
s_gcref = lltype.cast_opaque_ptr(llmemory.GCREF, s)
assert jitcode.constants_r == [s_gcref]
diff --git a/rpython/jit/metainterp/blackhole.py b/rpython/jit/metainterp/blackhole.py
--- a/rpython/jit/metainterp/blackhole.py
+++ b/rpython/jit/metainterp/blackhole.py
@@ -944,8 +944,7 @@
def bhimpl_last_exception(self):
real_instance = self.exception_last_value
assert real_instance
- adr = llmemory.cast_ptr_to_adr(real_instance.typeptr)
- return adr2int(adr)
+ return ptr2int(real_instance.typeptr)
@arguments("self", returns="r")
def bhimpl_last_exc_value(self):
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
@@ -14,7 +14,7 @@
from rpython.jit.metainterp.resoperation import ResOperation, rop,\
AbstractValue, oparity, AbstractResOp, IntOp, RefOp, FloatOp,\
opclasses
-from rpython.jit.metainterp.support import adr2int, int2adr
+from rpython.jit.metainterp.support import ptr2int, int2adr
from rpython.jit.codewriter import longlong
import weakref
from rpython.jit.metainterp import jitexc
@@ -182,7 +182,7 @@
kind = getkind(T)
if kind == "int":
if isinstance(T, lltype.Ptr):
- intval = adr2int(llmemory.cast_ptr_to_adr(x))
+ intval = ptr2int(x)
else:
intval = lltype.cast_primitive(lltype.Signed, x)
return ConstInt(intval)
diff --git a/rpython/jit/metainterp/pyjitpl.py b/rpython/jit/metainterp/pyjitpl.py
--- a/rpython/jit/metainterp/pyjitpl.py
+++ b/rpython/jit/metainterp/pyjitpl.py
@@ -13,7 +13,7 @@
from rpython.jit.metainterp.logger import Logger
from rpython.jit.metainterp.optimizeopt.util import args_dict
from rpython.jit.metainterp.resoperation import rop, OpHelpers, GuardResOp
-from rpython.jit.metainterp.support import adr2int
+from rpython.jit.metainterp.support import adr2int, ptr2int
from rpython.rlib.rjitlog import rjitlog as jl
from rpython.rlib import nonconst, rstack
from rpython.rlib.debug import debug_start, debug_stop, debug_print
@@ -2676,8 +2676,7 @@
exception_obj = lltype.cast_opaque_ptr(rclass.OBJECTPTR, exception)
if exception_obj:
- exc_class = adr2int(
- llmemory.cast_ptr_to_adr(exception_obj.typeptr))
+ exc_class = ptr2int(exception_obj.typeptr)
else:
exc_class = 0
assert self.history.trace is None
@@ -2975,8 +2974,7 @@
def handle_possible_exception(self):
if self.last_exc_value:
- exception_box = ConstInt(adr2int(
- llmemory.cast_ptr_to_adr(self.last_exc_value.typeptr)))
+ exception_box = ConstInt(ptr2int(self.last_exc_value.typeptr))
op = self.generate_guard(rop.GUARD_EXCEPTION,
None, [exception_box])
val = lltype.cast_opaque_ptr(llmemory.GCREF, self.last_exc_value)
diff --git a/rpython/jit/metainterp/support.py b/rpython/jit/metainterp/support.py
--- a/rpython/jit/metainterp/support.py
+++ b/rpython/jit/metainterp/support.py
@@ -17,6 +17,15 @@
"""
return llmemory.cast_int_to_adr(int)
+def ptr2int(ptr):
+ """
+ Cast a pointer to int.
+
+ Returns an AddressAsInt object.
+ """
+ addr = llmemory.cast_ptr_to_adr(ptr)
+ return llmemory.cast_adr_to_int(addr, "symbolic")
+
def int_signext(value, numbytes):
b8 = numbytes * 8
a = r_uint(value)
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,7 @@
from rpython.rtyper.lltypesystem import lltype, llmemory
from rpython.rtyper import rclass
from rpython.jit.metainterp import history
-from rpython.jit.metainterp.support import adr2int
+from rpython.jit.metainterp.support import ptr2int
from rpython.rlib.objectmodel import r_dict
@@ -16,7 +16,6 @@
def cls_of_box(self, box):
obj = lltype.cast_opaque_ptr(rclass.OBJECTPTR, box.getref_base())
- cls = llmemory.cast_ptr_to_adr(obj.typeptr)
- return history.ConstInt(adr2int(cls))
+ return history.ConstInt(ptr2int(obj.typeptr))
llhelper = LLTypeHelper()
diff --git a/rpython/jit/metainterp/virtualref.py b/rpython/jit/metainterp/virtualref.py
--- a/rpython/jit/metainterp/virtualref.py
+++ b/rpython/jit/metainterp/virtualref.py
@@ -2,7 +2,7 @@
from rpython.rtyper.lltypesystem import lltype, llmemory
from rpython.rtyper import rclass
from rpython.jit.metainterp import history
-from rpython.jit.metainterp.support import adr2int
+from rpython.jit.metainterp.support import ptr2int
from rpython.jit.metainterp.virtualizable import (
TOKEN_NONE, TOKEN_TRACING_RESCALL)
from rpython.jit.codewriter import heaptracker
@@ -34,8 +34,7 @@
self.jit_virtual_ref_vtable.name = rclass.alloc_array_name(
'jit_virtual_ref')
# build some constants
- adr = llmemory.cast_ptr_to_adr(self.jit_virtual_ref_vtable)
- adr = adr2int(adr)
+ adr = ptr2int(self.jit_virtual_ref_vtable)
self.jit_virtual_ref_const_class = history.ConstInt(adr)
fielddescrof = self.cpu.fielddescrof
self.descr_virtual_token = fielddescrof(self.JIT_VIRTUAL_REF,
diff --git a/rpython/jit/metainterp/warmstate.py b/rpython/jit/metainterp/warmstate.py
--- a/rpython/jit/metainterp/warmstate.py
+++ b/rpython/jit/metainterp/warmstate.py
@@ -3,7 +3,7 @@
from rpython.jit.codewriter import support, longlong
from rpython.jit.metainterp import resoperation, history, jitexc
-from rpython.jit.metainterp.support import adr2int, int2adr
+from rpython.jit.metainterp.support import ptr2int, int2adr
from rpython.rlib.debug import debug_start, debug_stop, debug_print
from rpython.rlib.debug import have_debug_prints_for
from rpython.rlib.jit import PARAMETERS
@@ -48,8 +48,7 @@
if lltype.typeOf(value).TO._gckind == 'gc':
return lltype.cast_opaque_ptr(llmemory.GCREF, value)
else:
- adr = llmemory.cast_ptr_to_adr(value)
- return adr2int(adr)
+ return ptr2int(value)
elif isinstance(value, float):
return longlong.getfloatstorage(value)
else:
@@ -82,8 +81,7 @@
res.setref_base(value)
return res
else:
- adr = llmemory.cast_ptr_to_adr(value)
- value = adr2int(adr)
+ value = ptr2int(value)
# fall through to the end of the function
elif (isinstance(value, float) or
longlong.is_longlong(lltype.typeOf(value))):
diff --git a/rpython/jit/tool/oparser_model.py b/rpython/jit/tool/oparser_model.py
--- a/rpython/jit/tool/oparser_model.py
+++ b/rpython/jit/tool/oparser_model.py
@@ -1,4 +1,4 @@
-from rpython.jit.metainterp.support import adr2int
+from rpython.jit.metainterp.support import ptr2int
class Boxes(object):
pass
@@ -23,8 +23,7 @@
@staticmethod
def ptr_to_int(obj):
- from rpython.rtyper.lltypesystem import llmemory
- return adr2int(llmemory.cast_ptr_to_adr(obj))
+ return ptr2int(obj)
return LoopModel
More information about the pypy-commit
mailing list