Author: Armin Rigo <[email protected]>
Branch: continulet-jit-3
Changeset: r58728:3b6f9eeddd06
Date: 2012-11-05 02:46 +0100
http://bitbucket.org/pypy/pypy/changeset/3b6f9eeddd06/
Log: Some more tweaks in this branch in order to try implementing the
idea on a real backend.
diff --git a/pypy/jit/backend/llgraph/runner.py
b/pypy/jit/backend/llgraph/runner.py
--- a/pypy/jit/backend/llgraph/runner.py
+++ b/pypy/jit/backend/llgraph/runner.py
@@ -13,6 +13,9 @@
from pypy.rlib.rarithmetic import ovfcheck, r_uint, r_ulonglong
from pypy.rlib.rtimer import read_timestamp
+from pypy.tool.uid import uid
+
+
class LLTrace(object):
has_been_freed = False
invalid = False
@@ -176,6 +179,7 @@
'i': 0,
'f': 0.0}
+
class LLGraphCPU(model.AbstractCPU):
from pypy.jit.metainterp.typesystem import llhelper as ts
supports_floats = True
@@ -183,7 +187,7 @@
supports_singlefloats = True
translate_support_code = False
- JITFRAMEPTR = llmemory.GCREF
+ JITFRAMEPTR = lltype.Ptr(lltype.GcStruct('JITFRAME'))
jfdescr_for_int = JFValueDescr('int')
jfdescr_for_ref = JFValueDescr('ref')
@@ -291,9 +295,12 @@
frame.last_exception = None
return gcref
- def force(self, frame):
+ def force(self, token):
+ assert lltype.typeOf(token) == llmemory.GCREF
+ frame = token._obj.llframe
assert not frame._forced
frame._forced = True
+ return frame
def force_vable_if_necessary(self, vable):
if vable.jitframe:
@@ -615,18 +622,10 @@
return not (self == other)
class LLFrame(object):
- _TYPE = llmemory.GCREF
-
- # some obscure hacks to support comparison with llmemory.GCREF
- def __ne__(self, other):
- return not self == other
- def __eq__(self, other):
- return isinstance(other, LLFrame) and self is other
-
_forced = False
_execution_finished_normally = False
finish_value = None
-
+
def __init__(self, cpu, argboxes, args):
self.env = {}
self.cpu = cpu
@@ -884,6 +883,7 @@
else:
jd = descr.outermost_jitdriver_sd
assembler_helper_ptr = jd.assembler_helper_adr.ptr # fish
+ frame._TYPE = LLGraphCPU.JITFRAMEPTR # hack
try:
result = assembler_helper_ptr(frame)
except LLException, lle:
@@ -913,8 +913,11 @@
descr = heaptracker.vtable2descr(self.cpu, vtable)
return self.cpu.bh_new_with_vtable(vtable, descr)
- def execute_jit_frame(self, _):
- return self
+ def execute_force_token(self, _):
+ p = lltype.malloc(llmemory.GCREF.TO)
+ p._obj.llframe = self
+ p._obj._name = 'force_token to LLFrame at 0x%x' % (uid(self,))
+ return p
def _getdescr(op):
d = op.getdescr()
diff --git a/pypy/jit/backend/test/runner_test.py
b/pypy/jit/backend/test/runner_test.py
--- a/pypy/jit/backend/test/runner_test.py
+++ b/pypy/jit/backend/test/runner_test.py
@@ -2198,17 +2198,16 @@
def test_force_operations_returning_void(self):
values = []
def maybe_force(token, flag):
- assert lltype.typeOf(token) == cpu.JITFRAMEPTR
+ assert lltype.typeOf(token) == llmemory.GCREF
if flag:
- descr = self.cpu.get_latest_descr(token)
+ frame = self.cpu.force(token)
+ descr = self.cpu.get_latest_descr(frame)
values.append(descr)
- x = self.cpu.force(token)
- assert x is None
- values.append(self.cpu.get_latest_value_int(token, 0))
- values.append(self.cpu.get_latest_value_int(token, 1))
- values.append(token)
+ values.append(self.cpu.get_latest_value_int(frame, 0))
+ values.append(self.cpu.get_latest_value_int(frame, 1))
+ values.append(frame)
- FUNC = self.FuncType([self.cpu.JITFRAMEPTR, lltype.Signed],
lltype.Void)
+ FUNC = self.FuncType([llmemory.GCREF, lltype.Signed], lltype.Void)
func_ptr = llhelper(lltype.Ptr(FUNC), maybe_force)
funcbox = self.get_funcbox(self.cpu, func_ptr).constbox()
calldescr = self.cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT,
@@ -2219,7 +2218,7 @@
tok = BoxPtr()
faildescr = BasicFailDescr(1)
ops = [
- ResOperation(rop.JIT_FRAME, [], tok),
+ ResOperation(rop.FORCE_TOKEN, [], tok),
ResOperation(rop.CALL_MAY_FORCE, [funcbox, tok, i1], None,
descr=calldescr),
ResOperation(rop.GUARD_NOT_FORCED, [], None, descr=faildescr),
@@ -2234,22 +2233,22 @@
assert values == []
frame = self.cpu.execute_token(looptoken, 10, 1)
+ assert values == [faildescr, 1, 10, frame]
assert self.cpu.get_latest_descr(frame).identifier == 1
assert self.cpu.get_latest_value_int(frame, 0) == 1
assert self.cpu.get_latest_value_int(frame, 1) == 10
- assert values == [faildescr, 1, 10, frame]
def test_force_operations_returning_int(self):
values = []
def maybe_force(token, flag):
if flag:
- self.cpu.force(token)
- values.append(self.cpu.get_latest_value_int(token, 0))
- values.append(self.cpu.get_latest_value_int(token, 2))
- values.append(token)
+ frame = self.cpu.force(token)
+ values.append(self.cpu.get_latest_value_int(frame, 0))
+ values.append(self.cpu.get_latest_value_int(frame, 2))
+ values.append(frame)
return 42
- FUNC = self.FuncType([self.cpu.JITFRAMEPTR, lltype.Signed],
+ FUNC = self.FuncType([llmemory.GCREF, lltype.Signed],
lltype.Signed)
func_ptr = llhelper(lltype.Ptr(FUNC), maybe_force)
funcbox = self.get_funcbox(self.cpu, func_ptr).constbox()
@@ -2262,7 +2261,7 @@
tok = BoxPtr()
faildescr = BasicFailDescr(1)
ops = [
- ResOperation(rop.JIT_FRAME, [], tok),
+ ResOperation(rop.FORCE_TOKEN, [], tok),
ResOperation(rop.CALL_MAY_FORCE, [funcbox, tok, i1], i2,
descr=calldescr),
ResOperation(rop.GUARD_NOT_FORCED, [], None, descr=faildescr),
@@ -2289,13 +2288,13 @@
values = []
def maybe_force(token, flag):
if flag:
- self.cpu.force(token)
- values.append(self.cpu.get_latest_value_int(token, 0))
- values.append(self.cpu.get_latest_value_int(token, 2))
- values.append(token)
+ frame = self.cpu.force(token)
+ values.append(self.cpu.get_latest_value_int(frame, 0))
+ values.append(self.cpu.get_latest_value_int(frame, 2))
+ values.append(frame)
return 42.5
- FUNC = self.FuncType([self.cpu.JITFRAMEPTR, lltype.Signed],
lltype.Float)
+ FUNC = self.FuncType([llmemory.GCREF, lltype.Signed], lltype.Float)
func_ptr = llhelper(lltype.Ptr(FUNC), maybe_force)
funcbox = self.get_funcbox(self.cpu, func_ptr).constbox()
calldescr = self.cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT,
@@ -2307,7 +2306,7 @@
tok = BoxPtr()
faildescr = BasicFailDescr(1)
ops = [
- ResOperation(rop.JIT_FRAME, [], tok),
+ ResOperation(rop.FORCE_TOKEN, [], tok),
ResOperation(rop.CALL_MAY_FORCE, [funcbox, tok, i1], f2,
descr=calldescr),
ResOperation(rop.GUARD_NOT_FORCED, [], None, descr=faildescr),
@@ -2331,6 +2330,7 @@
assert values == [1, 10, frame]
def test_force_from_finish(self):
+ py.test.skip("can't force from finish in this version")
finishdescr = BasicFailDescr(1)
loop = parse('''
[i1, i2]
@@ -2747,7 +2747,7 @@
called.append(failindex)
return 4 + 9
- FUNCPTR = lltype.Ptr(lltype.FuncType([llmemory.GCREF],
+ FUNCPTR = lltype.Ptr(lltype.FuncType([self.cpu.JITFRAMEPTR],
lltype.Signed))
class FakeJitDriverSD:
_assembler_helper_ptr = llhelper(FUNCPTR, assembler_helper)
@@ -2819,7 +2819,7 @@
called.append(failindex)
return 13.5
- FUNCPTR = lltype.Ptr(lltype.FuncType([llmemory.GCREF],
+ FUNCPTR = lltype.Ptr(lltype.FuncType([self.cpu.JITFRAMEPTR],
lltype.Float))
class FakeJitDriverSD:
_assembler_helper_ptr = llhelper(FUNCPTR, assembler_helper)
@@ -2879,14 +2879,16 @@
def test_assembler_call_get_latest_descr(self):
called = []
def assembler_helper(jitframe):
- jitframe1 = self.cpu.get_finish_value_ref(jitframe)
- called.append(self.cpu.get_latest_descr(jitframe1))
+ token = self.cpu.get_finish_value_ref(jitframe)
+ assert token == called[0]
return lltype.nullptr(llmemory.GCREF.TO)
- FUNCPTR = lltype.Ptr(lltype.FuncType([llmemory.GCREF],
+ FUNCPTR = lltype.Ptr(lltype.FuncType([self.cpu.JITFRAMEPTR],
llmemory.GCREF))
- def func2(jitframe1):
+ def func2(token):
+ called.append(token)
+ jitframe1 = self.cpu.force(token)
called.append(self.cpu.get_latest_descr(jitframe1))
FPTR2 = lltype.Ptr(lltype.FuncType([llmemory.GCREF], lltype.Void))
fptr2 = llhelper(FPTR2, func2)
@@ -2917,7 +2919,7 @@
foodescr = BasicFailDescr(66)
ops = '''
[]
- p0 = jit_frame()
+ p0 = force_token()
p1 = call_assembler(p0, descr=looptoken)
guard_not_forced(descr=foodescr) []
finish() []
@@ -2927,8 +2929,9 @@
self.cpu.compile_loop(loop2.inputargs, loop2.operations, othertoken)
frame = self.cpu.execute_token(othertoken)
- assert not self.cpu.get_finish_value_ref(frame)
- assert called == [foodescr] * 2
+ assert self.cpu.get_latest_descr(frame) is foodescr
+ assert len(called) == 2
+ assert called[1] == foodescr
def test_raw_malloced_getarrayitem(self):
ARRAY = rffi.CArray(lltype.Signed)
@@ -2964,7 +2967,7 @@
called.append(failindex)
return 13.5
- FUNCPTR = lltype.Ptr(lltype.FuncType([llmemory.GCREF],
+ FUNCPTR = lltype.Ptr(lltype.FuncType([self.cpu.JITFRAMEPTR],
lltype.Float))
class FakeJitDriverSD:
_assembler_helper_ptr = llhelper(FUNCPTR, assembler_helper)
@@ -3745,12 +3748,12 @@
def test_forcing_op_with_fail_arg_in_reg(self):
values = []
def maybe_force(token, flag):
- self.cpu.force(token)
- values.append(self.cpu.get_latest_value_int(token, 0))
- values.append(token)
+ frame = self.cpu.force(token)
+ values.append(self.cpu.get_latest_value_int(frame, 0))
+ values.append(frame)
return 42
- FUNC = self.FuncType([self.cpu.JITFRAMEPTR, lltype.Signed],
lltype.Signed)
+ FUNC = self.FuncType([llmemory.GCREF, lltype.Signed], lltype.Signed)
func_ptr = llhelper(lltype.Ptr(FUNC), maybe_force)
funcbox = self.get_funcbox(self.cpu, func_ptr).constbox()
calldescr = self.cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT,
@@ -3761,7 +3764,7 @@
tok = BoxPtr()
faildescr = BasicFailDescr(23)
ops = [
- ResOperation(rop.JIT_FRAME, [], tok),
+ ResOperation(rop.FORCE_TOKEN, [], tok),
ResOperation(rop.CALL_MAY_FORCE, [funcbox, tok, i1], i2,
descr=calldescr),
ResOperation(rop.GUARD_NOT_FORCED, [], None, descr=faildescr),
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit