Skip to content
Snippets Groups Projects
Commit 6b8463dc authored by Dominic Kempf's avatar Dominic Kempf
Browse files

[!281] Avoid more no op conditionals

Merge branch 'feature/more-avoiding-of-noop-conditionals' into 'master'

ref:dominic/dune-perftool By looking at the possible values of the condition.

See merge request [dominic/dune-perftool!281]

  [dominic/dune-perftool!281]: gitlab.dune-project.org/dominic/dune-perftool/merge_requests/281
parents 629c5ac6 2aaca437
No related branches found
No related tags found
No related merge requests found
......@@ -301,6 +301,17 @@ def boundary_predicates(measure, subdomain_id):
visitor = get_visitor(measure, subdomain_id)
subdomain_data = visitor(subdomain_data, do_predicates=True)
# Often, boundary predicates are just nested conditionals. We try to find
# out which of these are unfulfillable in the first place.
def possible_values(expr):
if isinstance(expr, prim.If):
return set(possible_values(expr.then)).union(possible_values(expr.else_))
else:
return set({expr})
if subdomain_id not in possible_values(subdomain_data):
return frozenset({False})
p = prim.Comparison(subdomain_data, '==', subdomain_id)
# Try to find conditions that are always 0 or always 1
......@@ -308,7 +319,7 @@ def boundary_predicates(measure, subdomain_id):
try:
eval = evaluate(p)
if not eval:
predicates.append(False)
return frozenset({False})
except:
predicates.append(p)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment