[pypy-svn] pypy jitypes2: Instead of storing the memo on the single global instance of Logger,
arigo
commits-noreply at bitbucket.org
Thu Mar 24 10:10:02 CET 2011
Author: Armin Rigo <arigo at tunes.org>
Branch: jitypes2
Changeset: r42893:68c27948ff6f
Date: 2011-03-24 09:56 +0100
http://bitbucket.org/pypy/pypy/changeset/68c27948ff6f/
Log: Instead of storing the memo on the single global instance of Logger,
create a new instance of LogOperations for each loop that we want to
log, and attach it to the logged loop. This allows us to print
later an operation from the loop, without the need for the global
'memo' field which breaks test_free_object.
diff --git a/pypy/jit/metainterp/optimizeopt/fficall.py b/pypy/jit/metainterp/optimizeopt/fficall.py
--- a/pypy/jit/metainterp/optimizeopt/fficall.py
+++ b/pypy/jit/metainterp/optimizeopt/fficall.py
@@ -73,7 +73,10 @@
def setup(self):
self.funcinfo = None
- self.logger = self.optimizer.metainterp_sd.logger_ops
+ if self.optimizer.loop is not None:
+ self.logops = self.optimizer.loop.logops
+ else:
+ self.logops = None
def propagate_begin_forward(self):
debug_start('jit-log-ffiopt')
@@ -100,8 +103,8 @@
#
# we immediately set funcinfo to None to prevent recursion when
# calling emit_op
- if have_debug_prints():
- debug_print('rollback: ' + msg + ': ', self.logger.repr_of_op(op))
+ if self.logops is not None:
+ debug_print('rollback: ' + msg + ': ', self.logops.repr_of_op(op))
funcinfo = self.funcinfo
self.funcinfo = None
self.emit_operation(funcinfo.prepare_op)
@@ -198,8 +201,8 @@
return ops
def propagate_forward(self, op):
- if have_debug_prints():
- debug_print(self.logger.repr_of_op(op))
+ if self.logops is not None:
+ debug_print(self.logops.repr_of_op(op))
opnum = op.getopnum()
for value, func in optimize_ops:
if opnum == value:
diff --git a/pypy/jit/metainterp/logger.py b/pypy/jit/metainterp/logger.py
--- a/pypy/jit/metainterp/logger.py
+++ b/pypy/jit/metainterp/logger.py
@@ -10,45 +10,59 @@
class Logger(object):
def __init__(self, metainterp_sd, guard_number=False):
- """
- resoperation logger. Note that you should call repr_of_op only
- *after* the corresponding loop has been fully logged, else you might
- get different results (in particular, variable numbers could be
- different)
- """
self.metainterp_sd = metainterp_sd
- self.ts = metainterp_sd.cpu.ts
self.guard_number = guard_number
- self.memo = {}
def log_loop(self, inputargs, operations, number=0, type=None):
if type is None:
debug_start("jit-log-noopt-loop")
- self._log_operations(inputargs, operations)
+ logops = self._log_operations(inputargs, operations)
debug_stop("jit-log-noopt-loop")
else:
debug_start("jit-log-opt-loop")
debug_print("# Loop", number, ":", type,
"with", len(operations), "ops")
- self._log_operations(inputargs, operations)
+ logops = self._log_operations(inputargs, operations)
debug_stop("jit-log-opt-loop")
+ return logops
def log_bridge(self, inputargs, operations, number=-1):
if number == -1:
debug_start("jit-log-noopt-bridge")
- self._log_operations(inputargs, operations)
+ logops = self._log_operations(inputargs, operations)
debug_stop("jit-log-noopt-bridge")
else:
debug_start("jit-log-opt-bridge")
debug_print("# bridge out of Guard", number,
"with", len(operations), "ops")
- self._log_operations(inputargs, operations)
+ logops = self._log_operations(inputargs, operations)
debug_stop("jit-log-opt-bridge")
+ return logops
def log_short_preamble(self, inputargs, operations):
debug_start("jit-log-short-preamble")
- self._log_operations(inputargs, operations)
- debug_stop("jit-log-short-preamble")
+ logops = self._log_operations(inputargs, operations)
+ debug_stop("jit-log-short-preamble")
+ return logops
+
+ def _log_operations(self, inputargs, operations):
+ if not have_debug_prints():
+ return None
+ logops = LogOperations(self.metainterp_sd, self.guard_number)
+ logops.log_operations(inputargs, operations)
+ return logops
+
+
+class LogOperations(object):
+ """
+ ResOperation logger. Each instance contains a memo giving numbers
+ to boxes, and is typically used to log a single loop.
+ """
+ def __init__(self, metainterp_sd, guard_number):
+ self.metainterp_sd = metainterp_sd
+ self.ts = metainterp_sd.cpu.ts
+ self.guard_number = guard_number
+ self.memo = {}
def repr_of_descr(self, descr):
return descr.repr_of_descr()
@@ -104,10 +118,7 @@
fail_args = ''
return res + op.getopname() + '(' + args + ')' + fail_args
- def _log_operations(self, inputargs, operations):
- self.memo = {}
- if not have_debug_prints():
- return
+ def log_operations(self, inputargs, operations):
if inputargs is not None:
args = ", ".join([self.repr_of_arg(arg) for arg in inputargs])
debug_print('[' + args + ']')
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
@@ -792,6 +792,7 @@
operations = None
token = None
call_pure_results = None
+ logops = None
def __init__(self, name):
self.name = name
diff --git a/pypy/jit/metainterp/optimize.py b/pypy/jit/metainterp/optimize.py
--- a/pypy/jit/metainterp/optimize.py
+++ b/pypy/jit/metainterp/optimize.py
@@ -14,7 +14,8 @@
def _optimize_loop(metainterp_sd, old_loop_tokens, loop, enable_opts):
cpu = metainterp_sd.cpu
- metainterp_sd.logger_noopt.log_loop(loop.inputargs, loop.operations)
+ loop.logops = metainterp_sd.logger_noopt.log_loop(loop.inputargs,
+ loop.operations)
# XXX do we really still need a list?
if old_loop_tokens:
return old_loop_tokens[0]
@@ -36,7 +37,8 @@
def _optimize_bridge(metainterp_sd, old_loop_tokens, bridge, enable_opts,
inline_short_preamble, retraced=False):
cpu = metainterp_sd.cpu
- metainterp_sd.logger_noopt.log_loop(bridge.inputargs, bridge.operations)
+ bridge.logops = metainterp_sd.logger_noopt.log_loop(bridge.inputargs,
+ bridge.operations)
if old_loop_tokens:
old_loop_token = old_loop_tokens[0]
bridge.operations[-1].setdescr(old_loop_token) # patch jump target
More information about the Pypy-commit
mailing list