[pypy-commit] pypy jit-simplify-backendintf: Fix the front-end. Some reduction in the total
arigo
noreply at buildbot.pypy.org
Tue Oct 25 22:38:29 CEST 2011
Author: Armin Rigo <arigo at tunes.org>
Branch: jit-simplify-backendintf
Changeset: r48458:cce408b68723
Date: 2011-10-25 22:04 +0200
http://bitbucket.org/pypy/pypy/changeset/cce408b68723/
Log: Fix the front-end. Some reduction in the total number of lines, but
due to a change --- when tracing is done, we raise
ContinueRunningNormally instead of building the arguments directly
for the next iteration, including virtuals --- a number of tests
fail now :-(
diff --git a/pypy/jit/metainterp/blackhole.py b/pypy/jit/metainterp/blackhole.py
--- a/pypy/jit/metainterp/blackhole.py
+++ b/pypy/jit/metainterp/blackhole.py
@@ -1500,7 +1500,6 @@
all_virtuals=None):
from pypy.jit.metainterp.resume import blackhole_from_resumedata
#debug_start('jit-blackhole')
- metainterp_sd.profiler.start_blackhole()
blackholeinterp = blackhole_from_resumedata(
metainterp_sd.blackholeinterpbuilder,
jitdriver_sd,
@@ -1514,10 +1513,9 @@
current_exc = blackholeinterp._prepare_resume_from_failure(
resumedescr.guard_opnum, dont_change_position)
- try:
- _run_forever(blackholeinterp, current_exc)
- finally:
- metainterp_sd.profiler.end_blackhole()
+ #try:
+ _run_forever(blackholeinterp, current_exc)
+ #finally:
#debug_stop('jit-blackhole')
def convert_and_run_from_pyjitpl(metainterp, raising_exception=False):
@@ -1525,7 +1523,6 @@
# 'metainterp.framestack'.
#debug_start('jit-blackhole')
metainterp_sd = metainterp.staticdata
- metainterp_sd.profiler.start_blackhole()
nextbh = None
for frame in metainterp.framestack:
curbh = metainterp_sd.blackholeinterpbuilder.acquire_interp()
@@ -1542,8 +1539,7 @@
firstbh.exception_last_value = current_exc
current_exc = lltype.nullptr(rclass.OBJECTPTR.TO)
#
- try:
- _run_forever(firstbh, current_exc)
- finally:
- metainterp_sd.profiler.end_blackhole()
+ #try:
+ _run_forever(firstbh, current_exc)
+ #finally:
#debug_stop('jit-blackhole')
diff --git a/pypy/jit/metainterp/compile.py b/pypy/jit/metainterp/compile.py
--- a/pypy/jit/metainterp/compile.py
+++ b/pypy/jit/metainterp/compile.py
@@ -340,12 +340,11 @@
def handle_fail(self, metainterp_sd, jitdriver_sd):
if self.must_compile(metainterp_sd, jitdriver_sd):
- return self._trace_and_compile_from_bridge(metainterp_sd,
- jitdriver_sd)
+ self._trace_and_compile_from_bridge(metainterp_sd, jitdriver_sd)
else:
from pypy.jit.metainterp.blackhole import resume_in_blackhole
resume_in_blackhole(metainterp_sd, jitdriver_sd, self)
- assert 0, "unreachable"
+ assert 0, "unreachable"
def _trace_and_compile_from_bridge(self, metainterp_sd, jitdriver_sd):
# 'jitdriver_sd' corresponds to the outermost one, i.e. the one
@@ -354,7 +353,7 @@
# jitdrivers.
from pypy.jit.metainterp.pyjitpl import MetaInterp
metainterp = MetaInterp(metainterp_sd, jitdriver_sd)
- return metainterp.handle_guard_failure(self)
+ metainterp.handle_guard_failure(self)
_trace_and_compile_from_bridge._dont_inline_ = True
def must_compile(self, metainterp_sd, jitdriver_sd):
diff --git a/pypy/jit/metainterp/history.py b/pypy/jit/metainterp/history.py
--- a/pypy/jit/metainterp/history.py
+++ b/pypy/jit/metainterp/history.py
@@ -123,9 +123,6 @@
def sort_key(self):
raise NotImplementedError
- def set_future_value(self, cpu, j):
- raise NotImplementedError
-
def nonnull(self):
raise NotImplementedError
@@ -288,9 +285,6 @@
def _get_hash_(self):
return make_hashable_int(self.value)
- def set_future_value(self, cpu, j):
- cpu.set_future_value_int(j, self.value)
-
def same_constant(self, other):
if isinstance(other, ConstInt):
return self.value == other.value
@@ -328,9 +322,6 @@
def _get_hash_(self):
return longlong.gethash(self.value)
- def set_future_value(self, cpu, j):
- cpu.set_future_value_float(j, self.value)
-
def same_constant(self, other):
if isinstance(other, ConstFloat):
return self.value == other.value
@@ -377,9 +368,6 @@
def getaddr(self):
return llmemory.cast_ptr_to_adr(self.value)
- def set_future_value(self, cpu, j):
- cpu.set_future_value_ref(j, self.value)
-
def same_constant(self, other):
if isinstance(other, ConstPtr):
return self.value == other.value
@@ -431,9 +419,6 @@
else:
return 0
- def set_future_value(self, cpu, j):
- cpu.set_future_value_ref(j, self.value)
-
## def getaddr(self):
## # so far this is used only when calling
## # CodeWriter.IndirectCallset.bytecode_for_address. We don't need a
@@ -539,9 +524,6 @@
def _get_hash_(self):
return make_hashable_int(self.value)
- def set_future_value(self, cpu, j):
- cpu.set_future_value_int(j, self.value)
-
def nonnull(self):
return self.value != 0
@@ -574,9 +556,6 @@
def _get_hash_(self):
return longlong.gethash(self.value)
- def set_future_value(self, cpu, j):
- cpu.set_future_value_float(j, self.value)
-
def nonnull(self):
return self.value != longlong.ZEROF
@@ -619,9 +598,6 @@
else:
return 0
- def set_future_value(self, cpu, j):
- cpu.set_future_value_ref(j, self.value)
-
def nonnull(self):
return bool(self.value)
@@ -666,19 +642,12 @@
def nonnull(self):
return bool(self.value)
- def set_future_value(self, cpu, j):
- cpu.set_future_value_ref(j, self.value)
-
def repr_rpython(self):
return repr_rpython(self, 'bo')
_getrepr_ = repr_object
-def set_future_values(cpu, boxes):
- for j in range(len(boxes)):
- boxes[j].set_future_value(cpu, j)
-
# ____________________________________________________________
diff --git a/pypy/jit/metainterp/jitprof.py b/pypy/jit/metainterp/jitprof.py
--- a/pypy/jit/metainterp/jitprof.py
+++ b/pypy/jit/metainterp/jitprof.py
@@ -10,8 +10,6 @@
counters="""
TRACING
BACKEND
-RUNNING
-BLACKHOLE
OPS
RECORDED_OPS
GUARDS
@@ -67,18 +65,6 @@
def end_backend(self):
pass
- def start_running(self):
- pass
-
- def end_running(self):
- pass
-
- def start_blackhole(self):
- pass
-
- def end_blackhole(self):
- pass
-
def count(self, kind, inc=1):
pass
@@ -134,16 +120,6 @@
def start_backend(self): self._start(BACKEND)
def end_backend(self): self._end (BACKEND)
- # Don't record times for 'running' and 'blackhole' because there are
- # too many of them: calling time.time() is a major blocker.
- # If you are interested in these numbers, use 'PYPYLOG=file' and
- # look at the resulting file with pypy/tool/logparser.py.
- def start_running(self): self.count(RUNNING)
- def end_running(self): pass
-
- def start_blackhole(self): self.count(BLACKHOLE)
- def end_blackhole(self): pass
-
def count(self, kind, inc=1):
self.counters[kind] += inc
@@ -165,8 +141,6 @@
calls = self.calls
self._print_line_time("Tracing", cnt[TRACING], tim[TRACING])
self._print_line_time("Backend", cnt[BACKEND], tim[BACKEND])
- self._print_intline("Running asm", cnt[RUNNING])
- self._print_intline("Blackhole", cnt[BLACKHOLE])
line = "TOTAL: \t\t%f" % (self.tk - self.starttime, )
debug_print(line)
self._print_intline("ops", cnt[OPS])
diff --git a/pypy/jit/metainterp/pyjitpl.py b/pypy/jit/metainterp/pyjitpl.py
--- a/pypy/jit/metainterp/pyjitpl.py
+++ b/pypy/jit/metainterp/pyjitpl.py
@@ -1795,7 +1795,7 @@
def _interpret(self):
# Execute the frames forward until we raise a DoneWithThisFrame,
- # a ExitFrameWithException, or a GenerateMergePoint exception.
+ # a ExitFrameWithException, or a ContinueRunningNormally exception.
self.staticdata.stats.entered()
while True:
self.framestack[-1].run_one_step()
@@ -1843,8 +1843,6 @@
self.seen_loop_header_for_jdindex = -1
try:
self.interpret()
- except GenerateMergePoint, gmp:
- return self.designate_target_loop(gmp)
except SwitchToBlackhole, stb:
self.run_blackhole_interp_to_cancel_tracing(stb)
assert False, "should always raise"
@@ -1879,8 +1877,6 @@
if self.resumekey_original_loop_token is None: # very rare case
raise SwitchToBlackhole(ABORT_BRIDGE)
self.interpret()
- except GenerateMergePoint, gmp:
- return self.designate_target_loop(gmp)
except SwitchToBlackhole, stb:
self.run_blackhole_interp_to_cancel_tracing(stb)
assert False, "should always raise"
@@ -1974,12 +1970,25 @@
start = len(self.history.operations)
self.current_merge_points.append((live_arg_boxes, start))
- def designate_target_loop(self, gmp):
- loop_token = gmp.target_loop_token
+ def _unpack_boxes(self, boxes, start, stop):
+ ints = []; refs = []; floats = []
+ for i in range(start, stop):
+ box = boxes[i]
+ if box.type == history.INT: ints.append(box.getint())
+ elif box.type == history.REF: refs.append(box.getref_base())
+ elif box.type == history.FLOAT:floats.append(box.getfloatstorage())
+ else: assert 0
+ return ints[:], refs[:], floats[:]
+
+ def raise_continue_running_normally(self, live_arg_boxes):
+ self.history.inputargs = None
+ self.history.operations = None
num_green_args = self.jitdriver_sd.num_green_args
- residual_args = gmp.argboxes[num_green_args:]
- history.set_future_values(self.cpu, residual_args)
- return loop_token
+ gi, gr, gf = self._unpack_boxes(live_arg_boxes, 0, num_green_args)
+ ri, rr, rf = self._unpack_boxes(live_arg_boxes, num_green_args,
+ len(live_arg_boxes))
+ CRN = self.staticdata.ContinueRunningNormally
+ raise CRN(gi, gr, gf, ri, rr, rf)
def prepare_resume_from_failure(self, opnum, dont_change_position=False):
frame = self.framestack[-1]
@@ -2042,9 +2051,7 @@
greenkey, start, start_resumedescr)
if loop_token is not None: # raise if it *worked* correctly
self.set_compiled_merge_points(greenkey, old_loop_tokens)
- self.history.inputargs = None
- self.history.operations = None
- raise GenerateMergePoint(live_arg_boxes, loop_token)
+ self.raise_continue_running_normally(live_arg_boxes)
self.history.inputargs = original_inputargs
self.history.operations.pop() # remove the JUMP
@@ -2065,9 +2072,7 @@
finally:
self.history.operations.pop() # remove the JUMP
if target_loop_token is not None: # raise if it *worked* correctly
- self.history.inputargs = None
- self.history.operations = None
- raise GenerateMergePoint(live_arg_boxes, target_loop_token)
+ self.raise_continue_running_normally(live_arg_boxes)
def compile_bridge_and_loop(self, original_boxes, live_arg_boxes, start,
bridge_arg_boxes, start_resumedescr):
@@ -2103,10 +2108,7 @@
except RetraceLoop:
assert False
assert target_loop_token is not None
-
- self.history.inputargs = None
- self.history.operations = None
- raise GenerateMergePoint(live_arg_boxes, old_loop_tokens[0])
+ self.raise_continue_running_normally(live_arg_boxes)
def compile_done_with_this_frame(self, exitbox):
self.gen_store_back_in_virtualizable()
@@ -2484,12 +2486,6 @@
# ____________________________________________________________
-class GenerateMergePoint(JitException):
- def __init__(self, args, target_loop_token):
- assert target_loop_token is not None
- self.argboxes = args
- self.target_loop_token = target_loop_token
-
class ChangeFrame(JitException):
"""Raised after we mutated metainterp.framestack, in order to force
it to reload the current top-of-stack frame that gets interpreted."""
diff --git a/pypy/jit/metainterp/test/support.py b/pypy/jit/metainterp/test/support.py
--- a/pypy/jit/metainterp/test/support.py
+++ b/pypy/jit/metainterp/test/support.py
@@ -4,9 +4,9 @@
from pypy.rpython.ootypesystem import ootype
from pypy.jit.backend.llgraph import runner
from pypy.jit.metainterp.warmspot import ll_meta_interp, get_stats
+from pypy.jit.metainterp.warmstate import unspecialize_value
from pypy.jit.metainterp.optimizeopt import ALL_OPTS_DICT
from pypy.jit.metainterp import pyjitpl, history
-from pypy.jit.metainterp.warmstate import set_future_value
from pypy.jit.codewriter.policy import JitPolicy
from pypy.jit.codewriter import codewriter, longlong
from pypy.rlib.rfloat import isnan
@@ -136,11 +136,11 @@
return NotImplemented
# a loop was successfully created by _run_with_pyjitpl(); call it
cpu = metainterp.cpu
+ args1 = []
for i in range(len(args) - num_green_args):
x = args[num_green_args + i]
- typecode = history.getkind(lltype.typeOf(x))
- set_future_value(cpu, i, x, typecode)
- faildescr = cpu.execute_token(loop_tokens[0])
+ args1.append(unspecialize_value(x))
+ faildescr = cpu.execute_token(loop_tokens[0], *args1)
assert faildescr.__class__.__name__.startswith('DoneWithThisFrameDescr')
if metainterp.jitdriver_sd.result_type == history.INT:
return cpu.get_latest_value_int(0)
diff --git a/pypy/jit/metainterp/test/test_ajit.py b/pypy/jit/metainterp/test/test_ajit.py
--- a/pypy/jit/metainterp/test/test_ajit.py
+++ b/pypy/jit/metainterp/test/test_ajit.py
@@ -9,7 +9,6 @@
from pypy.jit.metainterp.test.support import LLJitMixin, OOJitMixin, noConst
from pypy.jit.metainterp.typesystem import LLTypeHelper, OOTypeHelper
from pypy.jit.metainterp.warmspot import get_stats
-from pypy.jit.metainterp.warmstate import set_future_value
from pypy.rlib.jit import (JitDriver, we_are_jitted, hint, dont_look_inside,
loop_invariant, elidable, promote, jit_debug, assert_green,
AssertGreenFailed, unroll_safe, current_trace_length, look_inside_iff,
diff --git a/pypy/jit/metainterp/warmspot.py b/pypy/jit/metainterp/warmspot.py
--- a/pypy/jit/metainterp/warmspot.py
+++ b/pypy/jit/metainterp/warmspot.py
@@ -895,10 +895,3 @@
graphs = self.translator.graphs
for graph, block, i in find_force_quasi_immutable(graphs):
self.replace_force_quasiimmut_with_direct_call(block.operations[i])
-
- # ____________________________________________________________
-
- def execute_token(self, loop_token):
- fail_descr = self.cpu.execute_token(loop_token)
- self.memory_manager.keep_loop_alive(loop_token)
- return fail_descr
diff --git a/pypy/jit/metainterp/warmstate.py b/pypy/jit/metainterp/warmstate.py
--- a/pypy/jit/metainterp/warmstate.py
+++ b/pypy/jit/metainterp/warmstate.py
@@ -142,26 +142,6 @@
else:
return rffi.cast(lltype.Signed, x)
- at specialize.ll_and_arg(3)
-def set_future_value(cpu, j, value, typecode):
- if typecode == 'ref':
- refvalue = cpu.ts.cast_to_ref(value)
- cpu.set_future_value_ref(j, refvalue)
- elif typecode == 'int':
- if isinstance(lltype.typeOf(value), lltype.Ptr):
- intvalue = llmemory.AddressAsInt(llmemory.cast_ptr_to_adr(value))
- else:
- intvalue = lltype.cast_primitive(lltype.Signed, value)
- cpu.set_future_value_int(j, intvalue)
- elif typecode == 'float':
- if lltype.typeOf(value) is lltype.Float:
- value = longlong.getfloatstorage(value)
- else:
- assert longlong.is_longlong(lltype.typeOf(value))
- value = rffi.cast(lltype.SignedLongLong, value)
- cpu.set_future_value_float(j, value)
- else:
- assert False
class JitCell(BaseJitCell):
# the counter can mean the following things:
@@ -310,20 +290,36 @@
index_of_virtualizable = jitdriver_sd.index_of_virtualizable
num_green_args = jitdriver_sd.num_green_args
get_jitcell = self.make_jitcell_getter()
- set_future_values = self.make_set_future_values()
self.make_jitdriver_callbacks()
confirm_enter_jit = self.confirm_enter_jit
+ range_red_args = unrolling_iterable(
+ range(num_green_args, num_green_args + jitdriver_sd.num_red_args))
+
+ def execute_assembler(loop_token, *args):
+ # Call the backend to run the 'looptoken' with the given
+ # input args.
+ fail_descr = self.cpu.execute_token(loop_token, *args)
+ #
+ # If we have a virtualizable, we have to reset its
+ # 'vable_token' field afterwards
+ if vinfo is not None:
+ virtualizable = args[index_of_virtualizable]
+ virtualizable = vinfo.cast_to_vtype(virtualizable)
+ vinfo.reset_vable_token(virtualizable)
+ #
+ # Record in the memmgr that we just ran this loop,
+ # so that it will keep it alive for a longer time
+ warmrunnerdesc.memory_manager.keep_loop_alive(loop_token)
+ #
+ # Handle the failure
+ fail_descr.handle_fail(metainterp_sd, jitdriver_sd)
+ #
+ assert 0, "should have raised"
def maybe_compile_and_run(threshold, *args):
"""Entry point to the JIT. Called at the point with the
can_enter_jit() hint.
"""
- if vinfo is not None:
- virtualizable = args[num_green_args + index_of_virtualizable]
- virtualizable = vinfo.cast_to_vtype(virtualizable)
- else:
- virtualizable = None
-
# look for the cell corresponding to the current greenargs
greenargs = args[:num_green_args]
cell = get_jitcell(True, *greenargs)
@@ -343,42 +339,36 @@
# set counter to -2, to mean "tracing in effect"
cell.counter = -2
try:
- loop_token = metainterp.compile_and_run_once(jitdriver_sd,
- *args)
+ metainterp.compile_and_run_once(jitdriver_sd, *args)
finally:
if cell.counter == -2:
cell.counter = 0
else:
- if cell.counter == -2:
+ if cell.counter != -1:
+ assert cell.counter == -2
# tracing already happening in some outer invocation of
# this function. don't trace a second time.
return
- assert cell.counter == -1
if not confirm_enter_jit(*args):
return
+ # machine code was already compiled for these greenargs
loop_token = cell.get_entry_loop_token()
if loop_token is None: # it was a weakref that has been freed
cell.counter = 0
return
- # machine code was already compiled for these greenargs
- # get the assembler and fill in the boxes
- set_future_values(*args[num_green_args:])
-
- # ---------- execute assembler ----------
- while True: # until interrupted by an exception
- metainterp_sd.profiler.start_running()
- #debug_start("jit-running")
- fail_descr = warmrunnerdesc.execute_token(loop_token)
- #debug_stop("jit-running")
- metainterp_sd.profiler.end_running()
- loop_token = None # for test_memmgr
- if vinfo is not None:
- vinfo.reset_vable_token(virtualizable)
- loop_token = fail_descr.handle_fail(metainterp_sd,
- jitdriver_sd)
+ # extract and unspecialize the red arguments to pass to
+ # the assembler
+ execute_args = ()
+ for i in range_red_args:
+ execute_args += (unspecialize_value(args[i]), )
+ # run it! this executes until interrupted by an exception
+ execute_assembler(loop_token, *execute_args)
+ #
+ assert 0, "should not reach this point"
maybe_compile_and_run._dont_inline_ = True
self.maybe_compile_and_run = maybe_compile_and_run
+ self.execute_assembler = execute_assembler
return maybe_compile_and_run
# ----------
@@ -515,56 +505,6 @@
# ----------
- def make_set_future_values(self):
- "NOT_RPYTHON"
- if hasattr(self, 'set_future_values'):
- return self.set_future_values
-
- jitdriver_sd = self.jitdriver_sd
- cpu = self.cpu
- vinfo = jitdriver_sd.virtualizable_info
- red_args_types = unrolling_iterable(jitdriver_sd._red_args_types)
- #
- def set_future_values(*redargs):
- i = 0
- for typecode in red_args_types:
- set_future_value(cpu, i, redargs[i], typecode)
- i = i + 1
- if vinfo is not None:
- set_future_values_from_vinfo(*redargs)
- #
- if vinfo is not None:
- i0 = len(jitdriver_sd._red_args_types)
- index_of_virtualizable = jitdriver_sd.index_of_virtualizable
- vable_static_fields = unrolling_iterable(
- zip(vinfo.static_extra_types, vinfo.static_fields))
- vable_array_fields = unrolling_iterable(
- zip(vinfo.arrayitem_extra_types, vinfo.array_fields))
- getlength = cpu.ts.getlength
- getarrayitem = cpu.ts.getarrayitem
- #
- def set_future_values_from_vinfo(*redargs):
- i = i0
- virtualizable = redargs[index_of_virtualizable]
- virtualizable = vinfo.cast_to_vtype(virtualizable)
- for typecode, fieldname in vable_static_fields:
- x = getattr(virtualizable, fieldname)
- set_future_value(cpu, i, x, typecode)
- i = i + 1
- for typecode, fieldname in vable_array_fields:
- lst = getattr(virtualizable, fieldname)
- for j in range(getlength(lst)):
- x = getarrayitem(lst, j)
- set_future_value(cpu, i, x, typecode)
- i = i + 1
- else:
- set_future_values_from_vinfo = None
- #
- self.set_future_values = set_future_values
- return set_future_values
-
- # ----------
-
def make_jitdriver_callbacks(self):
if hasattr(self, 'get_location_str'):
return
More information about the pypy-commit
mailing list