[pypy-svn] pypy default: add a way to get only the operations that correspond to the specified ID
antocuni
commits-noreply at bitbucket.org
Tue Feb 22 14:45:21 CET 2011
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch:
Changeset: r42205:7b2b0d388008
Date: 2011-02-22 14:34 +0100
http://bitbucket.org/pypy/pypy/changeset/7b2b0d388008/
Log: add a way to get only the operations that correspond to the
specified ID
diff --git a/pypy/module/pypyjit/test_pypy_c/model.py b/pypy/module/pypyjit/test_pypy_c/model.py
--- a/pypy/module/pypyjit/test_pypy_c/model.py
+++ b/pypy/module/pypyjit/test_pypy_c/model.py
@@ -77,7 +77,7 @@
return res
def compute_ids(self):
- self.ids = set()
+ self.ids = {}
self.code = None
if not self.filename:
return
@@ -88,7 +88,7 @@
for id, opcodes in ids.iteritems():
targetop = opcodes[0]
if targetop in all_my_opcodes:
- self.ids.add(id)
+ self.ids[id] = opcodes
def get_set_of_opcodes(self):
res = set()
@@ -100,12 +100,25 @@
def has_id(self, id):
return id in self.ids
+ def _ops_for_chunk(self, chunk, include_debug_merge_points):
+ for op in chunk.operations:
+ if op.name != 'debug_merge_point' or include_debug_merge_points:
+ yield op
+
def allops(self, include_debug_merge_points=False):
for chunk in self.chunks:
- for op in chunk.operations:
- if op.name != 'debug_merge_point' or include_debug_merge_points:
+ for op in self._ops_for_chunk(chunk, include_debug_merge_points):
+ yield op
+
+ def ops_by_id(self, id, include_debug_merge_points=False):
+ target_opcodes = self.ids[id]
+ for chunk in self.chunks:
+ opcode = self.code.map[chunk.bytecode_no]
+ if opcode in target_opcodes:
+ for op in self._ops_for_chunk(chunk, include_debug_merge_points):
yield op
+
@classmethod
def parse_ops(cls, src):
ops = [cls.parse_op(line) for line in src.splitlines()]
diff --git a/pypy/module/pypyjit/test_pypy_c/test_model.py b/pypy/module/pypyjit/test_pypy_c/test_model.py
--- a/pypy/module/pypyjit/test_pypy_c/test_model.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_model.py
@@ -96,7 +96,7 @@
loops = log.loops_by_filename(self.filepath, is_entry_bridge='*')
assert len(loops) == 2
- def test_by_id(self):
+ def test_loops_by_id(self):
def f():
i = 0
while i < 1003:
@@ -118,6 +118,21 @@
'jump'
]
+ def test_ops_by_id(self):
+ def f():
+ i = 0
+ while i < 1003:
+ i += 1 # ID: increment
+ a = 0 # to make sure that JUMP_ABSOLUTE is not part of the ID
+ return i
+ #
+ log = self.run(f)
+ loop, = log.loops_by_id('increment')
+ #
+ ops = list(loop.ops_by_id('increment'))
+ opnames = [op.name for op in ops]
+ assert opnames == ['int_add']
+
def test_parse_op(self):
res = LoopWithIds.parse_op(" a = int_add( b, 3 ) # foo")
assert res == ("int_add", "a", ["b", "3"])
More information about the Pypy-commit
mailing list