Skip to content

Commit

Permalink
Merge pull request pypy#4834 from pypy/branches/rpython-cleanups-github
Browse files Browse the repository at this point in the history
some small cleanups in rpython/: remove useless backendopts, speed up C tests, fix memory error check
  • Loading branch information
cfbolz authored Jan 6, 2024
2 parents 30f5788 + 07d3ba1 commit 243cb3b
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 1,219 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,10 @@ jobs:
sudo apt-get install -y libgc-dev
pypy2 -m pip install --user hypothesis==4.39.3
- name: Test Translator
run: pypy2 pytest.py rpython/translator
run: |
# we don't need to run test_typed.py, because test_backendoptimized.py
# runs the same tests, just with more optimizations
pypy2 pytest.py rpython/translator --ignore=rpython/translator/c/test/test_typed.py --ignore=rpython/translator/c/test/test_newgc.py
# only run the tests for the incminimark GC, the one that we always use
# in practice
pypy2 pytest.py rpython/translator/c/test/test_newgc.py -k TestIncrementalMiniMarkGC
20 changes: 0 additions & 20 deletions rpython/config/translationoption.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# and just small enough to prevend inlining of some rlist functions.

DEFL_PROF_BASED_INLINE_THRESHOLD = 32.4
DEFL_CLEVER_MALLOC_REMOVAL_INLINE_THRESHOLD = 32.4
DEFL_LOW_INLINE_THRESHOLD = DEFL_INLINE_THRESHOLD / 2.0

DEFL_GC = "incminimark" # XXX
Expand Down Expand Up @@ -242,21 +241,6 @@
"for profile based inlining",
default="rpython.translator.backendopt.inline.inlining_heuristic",
), # cmdline="--prof-based-inline-heuristic" fix me
# control clever malloc removal
BoolOption("clever_malloc_removal",
"Drives inlining to remove mallocs in a clever way",
default=False,
cmdline="--clever-malloc-removal"),
FloatOption("clever_malloc_removal_threshold",
"Threshold when to inline functions in "
"clever malloc removal",
default=DEFL_CLEVER_MALLOC_REMOVAL_INLINE_THRESHOLD,
cmdline="--clever-malloc-removal-threshold"),
StrOption("clever_malloc_removal_heuristic",
"Dotted name of an heuristic function "
"for inlining in clever malloc removal",
default="rpython.translator.backendopt.inline.inlining_heuristic",
cmdline="--clever-malloc-removal-heuristic"),

BoolOption("remove_asserts",
"Remove operations that look like 'raise AssertionError', "
Expand All @@ -267,10 +251,6 @@
"without relying on the C compiler",
default=False),

BoolOption("stack_optimization",
"Tranform graphs in SSI form into graphs tailored for "
"stack based virtual machines (only for backends that support it)",
default=True),
BoolOption("storesink", "Perform store sinking", default=True),
BoolOption("replace_we_are_jitted",
"Replace we_are_jitted() calls by False",
Expand Down
2 changes: 1 addition & 1 deletion rpython/memory/gctransform/test/test_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ def f():
return len(l)

t = rtype(f, [])
backend_optimizations(t, clever_malloc_removal=False, storesink=True)
backend_optimizations(t, storesink=True)
etrafo = ExceptionTransformer(t)
graph = etrafo.transform_completely()
collect_analyzer = CollectAnalyzer(t)
Expand Down
4 changes: 4 additions & 0 deletions rpython/rtyper/lltypesystem/lltype.py
Original file line number Diff line number Diff line change
Expand Up @@ -1882,6 +1882,10 @@ def _check_range(self, n):
# checks that it's ok to make an array of size 'n', and returns
# range(n). Explicitly overridden by some tests.
try:
# first check it's a reasonable amount of memory
# because range lists don't take much space on pypy
if n > 2 ** 30:
raise MemoryError("8 GiB should be enough for tests")
return range(n)
except OverflowError:
raise MemoryError("definitely too many items")
Expand Down
19 changes: 1 addition & 18 deletions rpython/translator/backendopt/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from rpython.translator.backendopt.stat import print_statistics
from rpython.translator.backendopt.merge_if_blocks import merge_if_blocks
from rpython.translator import simplify
from rpython.translator.backendopt import mallocprediction
from rpython.translator.backendopt.removeassert import remove_asserts
from rpython.translator.backendopt.support import log
from rpython.translator.backendopt.storesink import storesink_graph
Expand Down Expand Up @@ -36,7 +35,7 @@ def backend_optimizations(translator, graphs=None, secondary=False,
# sensible keywords are
# inline_threshold, mallocs
# merge_if_blocks, constfold, heap2stack
# clever_malloc_removal, remove_asserts
# remove_asserts
# replace_we_are_jitted

config = translator.config.translation.backendopt.copy(as_default=True)
Expand Down Expand Up @@ -90,22 +89,6 @@ def remove_obvious_noops():
inline_graph_from_anywhere=inline_graph_from_anywhere)
constfold(config, graphs)

if config.clever_malloc_removal:
threshold = config.clever_malloc_removal_threshold
heuristic = get_function(config.clever_malloc_removal_heuristic)
log.inlineandremove("phase with threshold factor: %s" % threshold)
log.inlineandremove("heuristic: %s.%s" % (heuristic.__module__,
heuristic.__name__))
count = mallocprediction.clever_inlining_and_malloc_removal(
translator, graphs,
threshold = threshold,
heuristic=heuristic)
log.inlineandremove("removed %d simple mallocs in total" % count)
constfold(config, graphs)
if config.print_statistics:
print "after clever inlining and malloc removal"
print_statistics(translator.graphs[0], translator)

if config.storesink:
for graph in graphs:
storesink_graph(graph)
Expand Down
Loading

0 comments on commit 243cb3b

Please sign in to comment.