diff --git a/loopy/preprocess.py b/loopy/preprocess.py index f8fe8eef8ec7d5cbfb9b4fd8949acc671db2ca7c..87b42160de68f898c49df957b7bb754726d40815 100644 --- a/loopy/preprocess.py +++ b/loopy/preprocess.py @@ -2362,6 +2362,15 @@ def inline_kernels_with_gbarriers(program): # }}} +def filter_reachable_callables(t_unit): + from loopy.translation_unit import _get_callable_ids + reachable_function_ids = _get_callable_ids(t_unit.callables_table, + t_unit.entrypoints) + new_callables = {name: clbl for name, clbl in t_unit.callables_table.items() + if name in (reachable_function_ids | t_unit.entrypoints)} + return t_unit.copy(callables_table=new_callables) + + preprocess_cache = WriteOncePersistentDict( "loopy-preprocess-cache-v2-"+DATA_MODEL_VERSION, key_builder=LoopyKeyBuilder()) @@ -2449,6 +2458,8 @@ def preprocess_program(program, device=None): from loopy.translation_unit import resolve_callables program = resolve_callables(program) + program = filter_reachable_callables(program) + if device is not None: # FIXME: Time to remove this? (Git blame shows 5 years ago) from warnings import warn diff --git a/loopy/transform/callable.py b/loopy/transform/callable.py index 651f4457cbaba02879b2c81892a789719ee382c5..e88c88239d5d66ee7e6241936b5906fe6e8ba1f7 100644 --- a/loopy/transform/callable.py +++ b/loopy/transform/callable.py @@ -491,7 +491,7 @@ def inline_callable_kernel(translation_unit, function_name): Returns a copy of *translation_unit* with the callable kernel named *function_name* inlined at all call-sites. """ - from loopy.preprocess import infer_arg_descr + from loopy.preprocess import infer_arg_descr, filter_reachable_callables from loopy.translation_unit import resolve_callables # {{{ must have argument shape information at call sites to inline @@ -503,7 +503,9 @@ def inline_callable_kernel(translation_unit, function_name): callee = translation_unit[function_name] - return _inline_single_callable_kernel(translation_unit, callee) + return filter_reachable_callables( + _inline_single_callable_kernel(translation_unit, + callee)) # }}}