Author: Antonio Cuni <[email protected]>
Branch: x86-dump-labels
Changeset: r44096:d3c68b44b87b
Date: 2011-05-12 10:52 +0200
http://bitbucket.org/pypy/pypy/changeset/d3c68b44b87b/
Log: give the backends a chance to return a "labels" dictionary, which
will be later used by the logger
diff --git a/pypy/jit/backend/model.py b/pypy/jit/backend/model.py
--- a/pypy/jit/backend/model.py
+++ b/pypy/jit/backend/model.py
@@ -58,6 +58,14 @@
Should create and attach a fresh CompiledLoopToken to
looptoken.compiled_loop_token and stick extra attributes
on it to point to the compiled loop in assembler.
+
+ Optionally, return a ``labels`` dictionary, which maps each operation
+ to its offset in the compiled code. The ``labels`` dictionary is then
+ used by the operation logger to print the offsets in the log. The
+ offset representing the end of the last operation is stored in
+ ``labels[None]``: note that this might not coincide with the end of
+ the loop, because usually in the loop footer there is code which does
+ not belong to any particular operation.
"""
raise NotImplementedError
@@ -65,6 +73,9 @@
original_loop_token, log=True):
"""Assemble the bridge.
The FailDescr is the descr of the original guard that failed.
+
+ Optionally, return a ``labels`` dictionary. See the docstring of
+ ``compiled_loop`` for more informations about it.
"""
raise NotImplementedError
diff --git a/pypy/jit/backend/x86/assembler.py
b/pypy/jit/backend/x86/assembler.py
--- a/pypy/jit/backend/x86/assembler.py
+++ b/pypy/jit/backend/x86/assembler.py
@@ -361,11 +361,12 @@
frame_depth + param_depth)
self.patch_pending_failure_recoveries(rawstart)
#
+ labels = self.mc.labels
if not we_are_translated():
# used only by looptoken.dump() -- useful in tests
looptoken._x86_rawstart = rawstart
looptoken._x86_fullsize = fullsize
- looptoken._x86_labels = self.mc.labels
+ looptoken._x86_labels = labels
looptoken._x86_bootstrap_code = rawstart + bootstrappos
looptoken._x86_loop_code = rawstart + self.looppos
@@ -376,6 +377,7 @@
name = "Loop # %s: %s" % (looptoken.number, funcname)
self.cpu.profile_agent.native_code_written(name,
rawstart, fullsize)
+ return labels
def assemble_bridge(self, faildescr, inputargs, operations,
original_loop_token, log):
@@ -425,12 +427,14 @@
faildescr._x86_bridge_param_depth = param_depth
# patch the jump from original guard
self.patch_jump_for_descr(faildescr, rawstart)
+ labels = self.mc.labels
self.teardown()
# oprofile support
if self.cpu.profile_agent is not None:
name = "Bridge # %s: %s" % (descr_number, funcname)
self.cpu.profile_agent.native_code_written(name,
rawstart, fullsize)
+ return labels
def write_pending_failure_recoveries(self):
# for each pending guard, generate the code of the recovery stub
diff --git a/pypy/jit/backend/x86/runner.py b/pypy/jit/backend/x86/runner.py
--- a/pypy/jit/backend/x86/runner.py
+++ b/pypy/jit/backend/x86/runner.py
@@ -77,15 +77,15 @@
print ''.join(lines)
def compile_loop(self, inputargs, operations, looptoken, log=True):
- self.assembler.assemble_loop(inputargs, operations, looptoken,
- log=log)
+ return self.assembler.assemble_loop(inputargs, operations, looptoken,
+ log=log)
def compile_bridge(self, faildescr, inputargs, operations,
original_loop_token, log=True):
clt = original_loop_token.compiled_loop_token
clt.compiling_a_bridge()
- self.assembler.assemble_bridge(faildescr, inputargs, operations,
- original_loop_token, log=log)
+ return self.assembler.assemble_bridge(faildescr, inputargs, operations,
+ original_loop_token, log=log)
def set_future_value_int(self, index, intvalue):
self.assembler.fail_boxes_int.setitem(index, intvalue)
diff --git a/pypy/jit/backend/x86/test/test_runner.py
b/pypy/jit/backend/x86/test/test_runner.py
--- a/pypy/jit/backend/x86/test/test_runner.py
+++ b/pypy/jit/backend/x86/test/test_runner.py
@@ -403,11 +403,11 @@
]
inputargs = [i0]
debug._log = dlog = debug.DebugLog()
- self.cpu.compile_loop(inputargs, operations, looptoken)
+ labels = self.cpu.compile_loop(inputargs, operations, looptoken)
debug._log = None
#
# check the labels saved on the looptoken
- labels = looptoken._x86_labels
+ assert labels is looptoken._x86_labels
# getfield_raw/int_add/setfield_raw + ops + None
assert len(labels) == 3 + len(operations) + 1
assert (labels[operations[0]] <=
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
@@ -156,20 +156,14 @@
loop_token.number = n = globaldata.loopnumbering
globaldata.loopnumbering += 1
- metainterp_sd.logger_ops.log_loop(loop.inputargs, loop.operations, n, type)
- short = loop.token.short_preamble
- if short:
- metainterp_sd.logger_ops.log_short_preamble(short[-1].inputargs,
- short[-1].operations)
-
if not we_are_translated():
show_loop(metainterp_sd, loop)
loop.check_consistency()
metainterp_sd.profiler.start_backend()
debug_start("jit-backend")
try:
- metainterp_sd.cpu.compile_loop(loop.inputargs, loop.operations,
- loop.token)
+ labels = metainterp_sd.cpu.compile_loop(loop.inputargs,
loop.operations,
+ loop.token)
finally:
debug_stop("jit-backend")
metainterp_sd.profiler.end_backend()
@@ -180,27 +174,36 @@
else:
loop._ignore_during_counting = True
metainterp_sd.log("compiled new " + type)
+ #
+ metainterp_sd.logger_ops.log_loop(loop.inputargs, loop.operations, n,
type, labels)
+ short = loop.token.short_preamble
+ if short:
+ metainterp_sd.logger_ops.log_short_preamble(short[-1].inputargs,
+ short[-1].operations)
+ #
if metainterp_sd.warmrunnerdesc is not None: # for tests
metainterp_sd.warmrunnerdesc.memory_manager.keep_loop_alive(loop.token)
def send_bridge_to_backend(metainterp_sd, faildescr, inputargs, operations,
original_loop_token):
- n = metainterp_sd.cpu.get_fail_descr_number(faildescr)
- metainterp_sd.logger_ops.log_bridge(inputargs, operations, n)
if not we_are_translated():
show_loop(metainterp_sd)
TreeLoop.check_consistency_of(inputargs, operations)
metainterp_sd.profiler.start_backend()
debug_start("jit-backend")
try:
- metainterp_sd.cpu.compile_bridge(faildescr, inputargs, operations,
- original_loop_token)
+ labels = metainterp_sd.cpu.compile_bridge(faildescr, inputargs,
operations,
+ original_loop_token)
finally:
debug_stop("jit-backend")
metainterp_sd.profiler.end_backend()
if not we_are_translated():
metainterp_sd.stats.compiled()
metainterp_sd.log("compiled new bridge")
+ #
+ n = metainterp_sd.cpu.get_fail_descr_number(faildescr)
+ metainterp_sd.logger_ops.log_bridge(inputargs, operations, n, labels)
+ #
if metainterp_sd.warmrunnerdesc is not None: # for tests
metainterp_sd.warmrunnerdesc.memory_manager.keep_loop_alive(
original_loop_token)
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
@@ -14,7 +14,7 @@
self.ts = metainterp_sd.cpu.ts
self.guard_number = guard_number
- def log_loop(self, inputargs, operations, number=0, type=None):
+ def log_loop(self, inputargs, operations, number=0, type=None,
labels=None):
if type is None:
debug_start("jit-log-noopt-loop")
self._log_operations(inputargs, operations)
@@ -26,7 +26,7 @@
self._log_operations(inputargs, operations)
debug_stop("jit-log-opt-loop")
- def log_bridge(self, inputargs, operations, number=-1):
+ def log_bridge(self, inputargs, operations, number=-1, labels=None):
if number == -1:
debug_start("jit-log-noopt-bridge")
self._log_operations(inputargs, operations)
diff --git a/pypy/jit/metainterp/test/test_compile.py
b/pypy/jit/metainterp/test/test_compile.py
--- a/pypy/jit/metainterp/test/test_compile.py
+++ b/pypy/jit/metainterp/test/test_compile.py
@@ -34,7 +34,7 @@
self.seen.append((inputargs, operations, token))
class FakeLogger(object):
- def log_loop(self, inputargs, operations, number=0, type=None):
+ def log_loop(self, inputargs, operations, number=0, type=None,
labels=None):
pass
class FakeState(object):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit