Skip to content

Commit

Permalink
Optimize _is_call_value_used_exactly_once
Browse files Browse the repository at this point in the history
  • Loading branch information
rihi committed Oct 19, 2023
1 parent dca3964 commit 40cde04
Showing 1 changed file with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,25 @@ def _is_call_value_used_exactly_once(self, definition: Assignment) -> bool:
True on exactly one use.
False otherwise, or Call has more than one return value.
"""
if len(return_values := definition.destination.requirements) == 1:
required_variable = return_values[0]
requiring_instructions = self._use_map.get(required_variable)

usages = 0
for instruction in requiring_instructions:
for variable in instruction.accept(RequiredVariablesVisitor()):
if variable == required_variable:
usages += 1

return usages == 1
return False
if len(return_values := definition.destination.requirements) != 1:
return False

[required_variable] = return_values
requiring_instructions = self._use_map.get(required_variable)

if len(requiring_instructions) != 1:
return False

[requiring_instruction] = requiring_instructions

usages = 0
for variable in requiring_instruction.accept(RequiredVariablesVisitor()):
if variable == required_variable:
usages += 1
if usages > 1:
return False

return usages == 1

def _definition_can_be_propagated_into_target(self, definition: Assignment, target: Instruction):
"""Tests if propagation is allowed based on set of rules, namely
Expand Down

0 comments on commit 40cde04

Please sign in to comment.