[pypy-svn] r17695 - pypy/dist/pypy/translator/goal
pedronis at codespeak.net
pedronis at codespeak.net
Tue Sep 20 17:04:30 CEST 2005
Author: pedronis
Date: Tue Sep 20 17:04:29 2005
New Revision: 17695
Modified:
pypy/dist/pypy/translator/goal/query.py
Log:
experimental query about potential duplication
Modified: pypy/dist/pypy/translator/goal/query.py
==============================================================================
--- pypy/dist/pypy/translator/goal/query.py (original)
+++ pypy/dist/pypy/translator/goal/query.py Tue Sep 20 17:04:29 2005
@@ -482,3 +482,30 @@
print "Lost method!", name, subcls.cls, cls, subcls.attrs.keys()
lost += 0
return lost
+
+def graph_footprint(graph):
+ class Counter:
+ blocks = 0
+ links = 0
+ ops = 0
+ count = Counter()
+ def visit(block):
+ if isinstance(block, flowmodel.Block):
+ count.blocks += 1
+ count.ops += len(block.operations)
+ elif isinstance(block, flowmodel.Link):
+ count.links += 1
+ flowmodel.traverse(visit, graph)
+ return count.blocks, count.links, count.ops
+
+# better used before backends opts
+def duplication(t):
+ d = {}
+ funcs = t.flowgraphs.keys()
+ print len(funcs)
+ for f in funcs:
+ fingerprint = f.func_code, graph_footprint(t.flowgraphs[f])
+ d.setdefault(fingerprint ,[]).append(f)
+ for fingerprint, funcs in d.iteritems():
+ if len(funcs) > 1:
+ print fingerprint[0].co_name, len(funcs)
More information about the Pypy-commit
mailing list