[pypy-svn] r37440 - in pypy/dist/pypy: config jit/hintannotator/test jit/timeshifter/test translator/backendopt translator/backendopt/test
pedronis at codespeak.net
pedronis at codespeak.net
Sat Jan 27 18:01:09 CET 2007
Author: pedronis
Date: Sat Jan 27 18:01:05 2007
New Revision: 37440
Modified:
pypy/dist/pypy/config/translationoption.py
pypy/dist/pypy/jit/hintannotator/test/test_annotator.py
pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py
pypy/dist/pypy/translator/backendopt/all.py
pypy/dist/pypy/translator/backendopt/inline.py
pypy/dist/pypy/translator/backendopt/test/test_all.py
pypy/dist/pypy/translator/backendopt/test/test_inline.py
pypy/dist/pypy/translator/backendopt/test/test_removenoops.py
Log:
auto_inlining and family should just take a float threshold, not the confusing mixture of multiplier and threshold
based on an hard-coded BASE threshold.
this make things slitghlty more complicated for tests, address that.
As first at letting people control the inlining strategy expose inline_thresold setting through an --inline-threshold option.
Modified: pypy/dist/pypy/config/translationoption.py
==============================================================================
--- pypy/dist/pypy/config/translationoption.py (original)
+++ pypy/dist/pypy/config/translationoption.py Sat Jan 27 18:01:05 2007
@@ -1,8 +1,11 @@
import autopath
import py, os
-from pypy.config.config import OptionDescription, BoolOption, IntOption, ArbitraryOption
+from pypy.config.config import OptionDescription, BoolOption, IntOption, ArbitraryOption, FloatOption
from pypy.config.config import ChoiceOption, StrOption, to_optparse, Config
+DEFL_INLINE_THRESHOLD = 32.4 # just enough to inline add__Int_Int()
+# and just small enough to prevend inlining of some rlist functions.
+
translation_optiondescription = OptionDescription(
"translation", "Translation Options", [
BoolOption("stackless", "compile stackless features in",
@@ -105,8 +108,8 @@
BoolOption("remove_asserts",
"Kill 'raise AssertionError', which lets the C "
"optimizer remove the asserts", default=False),
- IntOption("inline_threshold", "Threshold when to inline functions",
- default=1, cmdline=None),
+ FloatOption("inline_threshold", "Threshold when to inline functions",
+ default=DEFL_INLINE_THRESHOLD, cmdline="--inline-threshold"),
StrOption("profile_based_inline",
"Use call count profiling to drive inlining"
", specify arguments",
Modified: pypy/dist/pypy/jit/hintannotator/test/test_annotator.py
==============================================================================
--- pypy/dist/pypy/jit/hintannotator/test/test_annotator.py (original)
+++ pypy/dist/pypy/jit/hintannotator/test/test_annotator.py Sat Jan 27 18:01:05 2007
@@ -28,7 +28,7 @@
rtyper = t.buildrtyper()
rtyper.specialize()
if inline:
- auto_inlining(t, inline)
+ auto_inlining(t, threshold=inline)
if backendoptimize:
from pypy.translator.backendopt.all import backend_optimizations
backend_optimizations(t)
@@ -570,7 +570,7 @@
return acc
assert ll_plus_minus("+-+", 0, 2) == 2
hannotate(ll_plus_minus, [str, int, int])
- hannotate(ll_plus_minus, [str, int, int], inline=999)
+ hannotate(ll_plus_minus, [str, int, int], inline=100000)
def test_invalid_hint_1():
S = lltype.GcStruct('S', ('x', lltype.Signed))
Modified: pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py (original)
+++ pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py Sat Jan 27 18:01:05 2007
@@ -41,7 +41,7 @@
rtyper = t.buildrtyper()
rtyper.specialize()
if inline:
- auto_inlining(t, inline)
+ auto_inlining(t, threshold=inline)
if backendoptimize:
from pypy.translator.backendopt.all import backend_optimizations
backend_optimizations(t)
@@ -712,7 +712,7 @@
pc += 1
return acc
ll_plus_minus.convert_arguments = [LLSupport.to_rstr, int, int]
- res = self.timeshift(ll_plus_minus, ["+-+", 0, 2], [0], inline=999)
+ res = self.timeshift(ll_plus_minus, ["+-+", 0, 2], [0], inline=100000)
assert res == ll_plus_minus("+-+", 0, 2)
self.check_insns({'int_add': 2, 'int_sub': 1})
Modified: pypy/dist/pypy/translator/backendopt/all.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/all.py (original)
+++ pypy/dist/pypy/translator/backendopt/all.py Sat Jan 27 18:01:05 2007
@@ -13,6 +13,8 @@
from pypy.translator.backendopt.checkvirtual import check_virtual_methods
from pypy.objspace.flow.model import checkgraph
+INLINE_THRESHOLD_FOR_TEST = 33
+
def backend_optimizations(translator, graphs=None, secondary=False, **kwds):
# sensible keywords are
# raisingop2direct_call, inline_threshold, mallocs
Modified: pypy/dist/pypy/translator/backendopt/inline.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/inline.py (original)
+++ pypy/dist/pypy/translator/backendopt/inline.py Sat Jan 27 18:01:05 2007
@@ -16,9 +16,6 @@
from pypy.translator.backendopt.support import find_backedges, find_loop_blocks
from pypy.translator.backendopt.canraise import RaiseAnalyzer
-BASE_INLINE_THRESHOLD = 32.4 # just enough to inline add__Int_Int()
-# and just small enough to prevend inlining of some rlist functions.
-
class CannotInline(Exception):
pass
@@ -605,8 +602,7 @@
result.append((parentgraph, graph))
return result
-def instrument_inline_candidates(graphs, multiplier):
- threshold = BASE_INLINE_THRESHOLD * multiplier
+def instrument_inline_candidates(graphs, threshold):
cache = {None: False}
def candidate(graph):
try:
@@ -644,11 +640,11 @@
n += 1
log.inlining("%d call sites instrumented" % n)
-def auto_inlining(translator, multiplier=1, callgraph=None,
- threshold=BASE_INLINE_THRESHOLD,
+def auto_inlining(translator, threshold=None,
+ callgraph=None,
call_count_pred=None):
+ assert threshold is not None and threshold != 1
from heapq import heappush, heappop, heapreplace, heapify
- threshold = threshold * multiplier
callers = {} # {graph: {graphs-that-call-it}}
callees = {} # {graph: {graphs-that-it-calls}}
if callgraph is None:
Modified: pypy/dist/pypy/translator/backendopt/test/test_all.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/test/test_all.py (original)
+++ pypy/dist/pypy/translator/backendopt/test/test_all.py Sat Jan 27 18:01:05 2007
@@ -1,5 +1,6 @@
import py
from pypy.translator.backendopt.all import backend_optimizations
+from pypy.translator.backendopt.all import INLINE_THRESHOLD_FOR_TEST
from pypy.translator.backendopt.support import md5digest
from pypy.translator.backendopt.test.test_malloc import TestLLTypeMallocRemoval as LLTypeMallocRemovalTest
from pypy.translator.backendopt.test.test_malloc import TestOOTypeMallocRemoval as OOTypeMallocRemovalTest
@@ -39,6 +40,8 @@
"""
return firstthat(myfunction, condition)
+LARGE_THRESHOLD = 10*INLINE_THRESHOLD_FOR_TEST
+HUGE_THRESHOLD = 100*INLINE_THRESHOLD_FOR_TEST
class BaseTester(object):
type_system = None
@@ -57,7 +60,8 @@
def test_big(self):
assert big() == 83
- t = self.translateopt(big, [], inline_threshold=100, mallocs=True)
+ t = self.translateopt(big, [], inline_threshold=HUGE_THRESHOLD,
+ mallocs=True)
big_graph = graphof(t, big)
self.check_malloc_removed(big_graph)
@@ -74,8 +78,9 @@
total += i
return total
- t = self.translateopt(f, [int], inline_threshold=1, mallocs=True)
- # this also checks that the BASE_INLINE_THRESHOLD is enough for 'for' loops
+ t = self.translateopt(f, [int], mallocs=True)
+ # this also checks that the BASE_INLINE_THRESHOLD is enough
+ # for 'for' loops
f_graph = graph = graphof(t, f)
self.check_malloc_removed(f_graph)
@@ -103,7 +108,7 @@
#debug(" lowered -> " + a)
return 0
- t = self.translateopt(entry_point, inputtypes, inline_threshold=1, mallocs=True)
+ t = self.translateopt(entry_point, inputtypes, mallocs=True)
entry_point_graph = graphof(t, entry_point)
@@ -156,7 +161,7 @@
assert myfunc(10) == 5
- t = self.translateopt(myfunc, [int], inline_threshold=100)
+ t = self.translateopt(myfunc, [int], inline_threshold=HUGE_THRESHOLD)
interp = LLInterpreter(t.rtyper)
res = interp.eval_graph(graphof(t, myfunc), [10])
assert res == 5
@@ -204,7 +209,8 @@
c = [i for i in range(n2)]
return 33
- t = self.translateopt(f, [int, int], inline_threshold=10, mallocs=True)
+ t = self.translateopt(f, [int, int], inline_threshold=LARGE_THRESHOLD,
+ mallocs=True)
f_graph = graphof(t, f)
self.check_malloc_removed(f_graph)
Modified: pypy/dist/pypy/translator/backendopt/test/test_inline.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/test/test_inline.py (original)
+++ pypy/dist/pypy/translator/backendopt/test/test_inline.py Sat Jan 27 18:01:05 2007
@@ -15,6 +15,7 @@
from pypy.rpython.test.tool import LLRtypeMixin, OORtypeMixin
from pypy.rlib.rarithmetic import ovfcheck
from pypy.translator.test.snippet import is_perfect_number
+from pypy.translator.backendopt.all import INLINE_THRESHOLD_FOR_TEST
from pypy.conftest import option
@@ -95,17 +96,16 @@
# inline!
sanity_check(t) # also check before inlining (so we don't blame it)
+ threshold = INLINE_THRESHOLD_FOR_TEST
if multiplier is not None:
- multiplier = {'multiplier': multiplier}
- else:
- multiplier = {}
+ threshold *= multiplier
call_count_pred = None
if call_count_check:
call_count_pred = lambda lbl: True
- instrument_inline_candidates(t.graphs, **multiplier)
+ instrument_inline_candidates(t.graphs, threshold)
- auto_inlining(t, call_count_pred=call_count_pred, **multiplier)
+ auto_inlining(t, threshold, call_count_pred=call_count_pred)
sanity_check(t)
if option.view:
Modified: pypy/dist/pypy/translator/backendopt/test/test_removenoops.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/test/test_removenoops.py (original)
+++ pypy/dist/pypy/translator/backendopt/test/test_removenoops.py Sat Jan 27 18:01:05 2007
@@ -5,6 +5,7 @@
from pypy.rpython.memory.gctransform.test.test_transform import getops
from pypy.translator.test.snippet import simple_method
from pypy.translator.backendopt.all import backend_optimizations
+from pypy.translator.backendopt.all import INLINE_THRESHOLD_FOR_TEST
from pypy.objspace.flow.model import checkgraph, flatten, Block
from pypy.rpython.lltypesystem import lltype
from pypy.rpython.lltypesystem.lloperation import llop
@@ -14,12 +15,12 @@
import py
log = py.log.Producer('test_backendoptimization')
-def get_graph(fn, signature, inline_threshold=True, all_opts=True):
+def get_graph(fn, signature, all_opts=True):
t = TranslationContext()
t.buildannotator().build_types(fn, signature)
t.buildrtyper().specialize()
if all_opts:
- backend_optimizations(t, inline_threshold=inline_threshold,
+ backend_optimizations(t, inline_threshold=INLINE_THRESHOLD_FOR_TEST,
constfold=False,
raisingop2direct_call=False)
graph = graphof(t, fn)
@@ -119,7 +120,7 @@
c = B(x, x + 1, x + 2)
return a.x + a.y + b.x + b.y + b.z + c.getsum()
assert f(10, True) == 75
- graph, t = get_graph(f, [int, bool], 1, False)
+ graph, t = get_graph(f, [int, bool], all_opts=False)
num_cast_pointer = len(getops(graph)['cast_pointer'])
changed = remove_duplicate_casts(graph, t)
assert changed
More information about the Pypy-commit
mailing list