[pypy-svn] r25532 - pypy/dist/pypy/translator/backendopt
cfbolz at codespeak.net
cfbolz at codespeak.net
Sat Apr 8 10:14:49 CEST 2006
Author: cfbolz
Date: Sat Apr 8 10:14:47 2006
New Revision: 25532
Modified:
pypy/dist/pypy/translator/backendopt/inline.py
Log:
(pedronis, cfbolz):
increase the weight of edges that go back in a loop because they are much more
likely
Modified: pypy/dist/pypy/translator/backendopt/inline.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/inline.py (original)
+++ pypy/dist/pypy/translator/backendopt/inline.py Sat Apr 8 10:14:47 2006
@@ -9,7 +9,7 @@
from pypy.rpython.lltypesystem.lltype import Bool, typeOf, Void, Ptr
from pypy.rpython import rmodel
from pypy.tool.algo import sparsemat
-from pypy.translator.backendopt.support import log, split_block_with_keepalive, generate_keepalive
+from pypy.translator.backendopt.support import log, split_block_with_keepalive, generate_keepalive, find_backedges, find_loop_blocks
BASE_INLINE_THRESHOLD = 32.4 # just enough to inline add__Int_Int()
# and just small enough to prevend inlining of some rlist functions.
@@ -426,6 +426,7 @@
'keepalive': 0,
'direct_call': 2, # guess
'indirect_call': 2, # guess
+# 'malloc': 2,
'yield_current_frame_to_caller': sys.maxint, # XXX bit extreme
}
@@ -444,18 +445,38 @@
for block in graph.iterblocks():
blockmap[block] = len(blocks)
blocks.append(block)
+ backedges = dict.fromkeys(find_backedges(graph), True)
+ loops = find_loop_blocks(graph)
M = sparsemat.SparseMatrix(len(blocks))
vector = []
for i, block in enumerate(blocks):
vector.append(block_weight(block))
M[i, i] = 1
if block.exits:
- f = 1.0 / len(block.exits)
+ if block not in loops:
+ current_loop_start = None
+ else:
+ current_loop_start = loops[block]
+ loop_exits = []
+ for link in block.exits:
+ if (link.target in loops and
+ loops[link.target] is current_loop_start):
+ loop_exits.append(link)
+ if len(loop_exits) and len(loop_exits) < len(block.exits):
+ f = 0.3 / (len(block.exits) - len(loop_exits))
+ b = 0.7 / len(loop_exits)
+ else:
+ b = f = 1.0 / len(block.exits)
for link in block.exits:
- M[i, blockmap[link.target]] -= f
+ if (link.target in loops and
+ loops[link.target] is current_loop_start):
+ M[i, blockmap[link.target]] -= b
+ else:
+ M[i, blockmap[link.target]] -= f
try:
Solution = M.solve(vector)
except ValueError:
+ raise
return sys.maxint
else:
res = Solution[blockmap[graph.startblock]]
More information about the Pypy-commit
mailing list