Skip to content

Commit

Permalink
refine unique symbols requirement
Browse files Browse the repository at this point in the history
there might be true dead code, so only run the exactly-once symbol
checker on binop optimizations.
  • Loading branch information
charles-cooper committed Jun 18, 2022
1 parent c148926 commit c057cb6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
1 change: 1 addition & 0 deletions vyper/codegen/ir_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ def is_complex_ir(self):
and self.value.lower() not in do_not_cache
)

# unused, but might be useful for analysis at some point
def unique_symbols(self):
ret = set()
if self.value == "unique_symbol":
Expand Down
12 changes: 3 additions & 9 deletions vyper/ir/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,15 +380,7 @@ def _conservative_eq(x, y):


def optimize(node: IRnode) -> IRnode:
initial_symbols = node.unique_symbols()

ret = _optimize(node, parent=None)

if ret.unique_symbols() != initial_symbols:
diff = initial_symbols - ret.unique_symbols()
raise CompilerPanic(f"Bad optimizer pass, missing {diff}")

return ret
return _optimize(node, parent=None)


def _optimize(node: IRnode, parent: Optional[IRnode]) -> IRnode:
Expand Down Expand Up @@ -426,9 +418,11 @@ def finalize(ir_builder):
elif value in arith:
parent_op = parent.value if parent is not None else None

starting_symbols = node.unique_symbols()
res = _optimize_binop(value, argz, annotation, parent_op)
if res is not None:
optimize_more = True
assert starting_symbols == argz[0].unique_symbols() | argz[1].unique_symbols(), "bad optimizer pass"
value, argz, annotation = res

###
Expand Down

0 comments on commit c057cb6

Please sign in to comment.