From c8fdcb1e0cadb9ecc6fb2b91e6566175c79c7014 Mon Sep 17 00:00:00 2001 From: Dominic Kempf Date: Mon, 12 Dec 2016 21:28:35 +0100 Subject: [PATCH] Use constant folding on base_storage sizes The current code can produce overly complicated base storage size expression, such as: `char* base[max(32, 2*2*2*4)]` These should be folded for readability of generated code. --- loopy/target/c/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/loopy/target/c/__init__.py b/loopy/target/c/__init__.py index e4835a363..7cc53d840 100644 --- a/loopy/target/c/__init__.py +++ b/loopy/target/c/__init__.py @@ -486,6 +486,8 @@ class CASTBuilder(ASTBuilderBase): * product(si for si in idi.shape)) ecm = self.get_expression_to_code_mapper(codegen_state) + from loopy.symbolic import ConstantFoldingMapper + cfm = ConstantFoldingMapper() for bs_name, bs_sizes in sorted(six.iteritems(base_storage_sizes)): bs_var_decl = Value("char", bs_name) @@ -494,6 +496,7 @@ class CASTBuilder(ASTBuilderBase): bs_var_decl, single_valued(base_storage_to_scope[bs_name])) # FIXME: Could try to use isl knowledge to simplify max. + bs_sizes = tuple(cfm.evaluate(s) for s in bs_sizes) if all(isinstance(bs, int) for bs in bs_sizes): bs_size_max = max(bs_sizes) else: -- GitLab