[pypy-commit] pypy x86-dump-labels: refactoring: instead of storing a list of "labels", we store a mapping between ops and offsets. Next step is to print the offsets directly in the jit-lot-opt section of the log
antocuni
noreply at buildbot.pypy.org
Thu May 12 13:53:26 CEST 2011
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: x86-dump-labels
Changeset: r44095:14e8b6b078ac
Date: 2011-05-11 17:51 +0200
http://bitbucket.org/pypy/pypy/changeset/14e8b6b078ac/
Log: refactoring: instead of storing a list of "labels", we store a
mapping between ops and offsets. Next step is to print the offsets
directly in the jit-lot-opt section of the log
diff --git a/pypy/jit/backend/x86/codebuf.py b/pypy/jit/backend/x86/codebuf.py
--- a/pypy/jit/backend/x86/codebuf.py
+++ b/pypy/jit/backend/x86/codebuf.py
@@ -27,14 +27,17 @@
# at [p-4:p] encode an absolute address that will need to be
# made relative.
self.relocations = []
- self.labels = []
+ # ResOperation --> offset in the assembly.
+ # labels[None] represents the beginning of the code after the last op
+ # (i.e., the tail of the loop
+ self.labels = {}
def add_pending_relocation(self):
self.relocations.append(self.get_relative_pos())
- def mark_label(self, name):
+ def mark_op(self, op):
pos = self.get_relative_pos()
- self.labels.append((pos, name))
+ self.labels[op] = pos
def copy_to_raw_memory(self, addr):
self._copy_to_raw_memory(addr)
@@ -44,13 +47,3 @@
adr[0] = intmask(adr[0] - p)
valgrind.discard_translations(addr, self.get_relative_pos())
self._dump(addr, "jit-backend-dump", backend_name)
- self.dump_labels(addr, "jit-backend-dump-labels")
-
- def dump_labels(self, addr, logname):
- debug_start(logname)
- if have_debug_prints():
- debug_print('LABELS @%x' % addr)
- for offset, name in self.labels:
- debug_print('+%d: %s' % (offset, name))
- debug_stop(logname)
-
diff --git a/pypy/jit/backend/x86/regalloc.py b/pypy/jit/backend/x86/regalloc.py
--- a/pypy/jit/backend/x86/regalloc.py
+++ b/pypy/jit/backend/x86/regalloc.py
@@ -406,7 +406,7 @@
#self.operations = operations
while i < len(operations):
op = operations[i]
- self.assembler.mc.mark_label(op.repr())
+ self.assembler.mc.mark_op(op)
self.rm.position = i
self.xrm.position = i
if op.has_no_side_effect() and op.result not in self.longevity:
@@ -425,7 +425,7 @@
i += 1
assert not self.rm.reg_bindings
assert not self.xrm.reg_bindings
- self.assembler.mc.mark_label('--end of the loop--')
+ self.assembler.mc.mark_op(None) # end of the loop
def _compute_vars_longevity(self, inputargs, operations):
# compute a dictionary that maps variables to index in
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
@@ -61,15 +61,19 @@
self.profile_agent.shutdown()
def dump_loop_token(self, looptoken):
+ """
+ NOT_RPYTHON
+ """
from pypy.jit.backend.x86.tool.viewcode import machine_code_dump
data = []
+ label_list = [(offset, name) for name, offset in looptoken._x86_labels.iteritems()]
+ label_list.sort()
addr = looptoken._x86_rawstart
src = rffi.cast(rffi.CCHARP, addr)
for p in range(looptoken._x86_fullsize):
data.append(src[p])
data = ''.join(data)
- lines = machine_code_dump(data, addr, self.backend_name,
- labels=looptoken._x86_labels)
+ lines = machine_code_dump(data, addr, self.backend_name, label_list)
print ''.join(lines)
def compile_loop(self, inputargs, operations, looptoken, log=True):
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
@@ -405,30 +405,15 @@
debug._log = dlog = debug.DebugLog()
self.cpu.compile_loop(inputargs, operations, looptoken)
debug._log = None
- expected = ['getfield_raw',
- 'int_add',
- 'setfield_raw',
- 'int_add',
- 'int_le',
- 'jump',
- '--end of the loop--']
#
# check the labels saved on the looptoken
labels = looptoken._x86_labels
- assert len(labels) == len(expected)
- for (off, lbl), exp_lbl in zip(labels, expected):
- assert exp_lbl in lbl
- #
- # -----
- # check the labels dumped to the log
- # discards code blocks which do not belong to loops
- dumped_labels, = [content for category, content in dlog
- if (category == 'jit-backend-dump-labels' and
- len(content) > 1)]
- # the first debug_print is LABELS @address
- assert len(dumped_labels) == len(expected) + 1
- for (_, lbl), exp_lbl in zip(dumped_labels[1:], expected):
- assert exp_lbl in lbl
+ # getfield_raw/int_add/setfield_raw + ops + None
+ assert len(labels) == 3 + len(operations) + 1
+ assert (labels[operations[0]] <=
+ labels[operations[1]] <=
+ labels[operations[2]] <=
+ labels[None])
class TestDebuggingAssembler(object):
def setup_method(self, meth):
diff --git a/pypy/jit/backend/x86/tool/test/test_viewcode.py b/pypy/jit/backend/x86/tool/test/test_viewcode.py
--- a/pypy/jit/backend/x86/tool/test/test_viewcode.py
+++ b/pypy/jit/backend/x86/tool/test/test_viewcode.py
@@ -14,8 +14,8 @@
aa12: eight
""".strip()).readlines()
#
- labels = [(0x00, 'AAA'), (0x03, 'BBB'), (0x0c, 'CCC')]
- lines = format_code_dump_with_labels(0xAA00, lines, labels)
+ label_list = [(0x00, 'AAA'), (0x03, 'BBB'), (0x0c, 'CCC')]
+ lines = format_code_dump_with_labels(0xAA00, lines, label_list)
out = ''.join(lines)
assert out == """
aa00 <.data>:
@@ -50,6 +50,6 @@
""".strip()
lines = StringIO(input).readlines()
#
- lines = format_code_dump_with_labels(0xAA00, lines, labels=None)
+ lines = format_code_dump_with_labels(0xAA00, lines, label_list=None)
out = ''.join(lines)
assert out.strip() == input
diff --git a/pypy/jit/backend/x86/tool/viewcode.py b/pypy/jit/backend/x86/tool/viewcode.py
--- a/pypy/jit/backend/x86/tool/viewcode.py
+++ b/pypy/jit/backend/x86/tool/viewcode.py
@@ -31,7 +31,7 @@
if sys.platform == "win32":
XXX # lots more in Psyco
-def machine_code_dump(data, originaddr, backend_name, labels=None):
+def machine_code_dump(data, originaddr, backend_name, label_list=None):
objdump_backend_option = {
'x86': 'i386',
'x86_64': 'x86-64',
@@ -52,22 +52,25 @@
result = g.readlines()
g.close()
lines = result[6:] # drop some objdump cruft
- return format_code_dump_with_labels(originaddr, lines, labels)
+ return format_code_dump_with_labels(originaddr, lines, label_list)
-def format_code_dump_with_labels(originaddr, lines, labels):
+def format_code_dump_with_labels(originaddr, lines, label_list):
from pypy.rlib.rarithmetic import r_uint
- if not labels:
- labels = []
+ if not label_list:
+ label_list = []
originaddr = r_uint(originaddr)
itlines = iter(lines)
yield itlines.next() # don't process the first line
- for lbl_start, lbl_name in labels:
+ for lbl_start, lbl_name in label_list:
for line in itlines:
addr, _ = line.split(':', 1)
addr = int(addr, 16)
if addr >= originaddr+lbl_start:
yield '\n'
- yield lbl_name + '\n'
+ if lbl_name is None:
+ yield '--end of the loop--\n'
+ else:
+ yield str(lbl_name) + '\n'
yield line
break
yield line
More information about the pypy-commit
mailing list