|
@@ -95,32 +95,32 @@ def elide_local_checks(entry_point):
|
|
|
# The plan here is to replace all check-local-exists defs by literals if
|
|
|
# they are either dominated by an appropriate declare-local or not reachable
|
|
|
# from a declare-local.
|
|
|
- local_checks = defaultdict(set)
|
|
|
- local_defs = defaultdict(set)
|
|
|
+ local_checks = []
|
|
|
+ local_defs = defaultdict(list)
|
|
|
for block in cfg_ir.get_all_blocks(entry_point):
|
|
|
for definition in block.definitions:
|
|
|
- if cfg_ir.is_value_def(definition, cfg_ir.CheckLocalExists):
|
|
|
- local_checks[cfg_ir.get_def_variable(definition).node_id].add(definition)
|
|
|
- elif cfg_ir.is_value_def(definition, cfg_ir.DeclareLocal):
|
|
|
- local_defs[cfg_ir.get_def_variable(definition).node_id].add(definition)
|
|
|
+ def_value = definition.value
|
|
|
+ if isinstance(def_value, cfg_ir.CheckLocalExists):
|
|
|
+ local_checks.append((def_value.variable.node_id, definition))
|
|
|
+ elif isinstance(def_value, cfg_ir.DeclareLocal):
|
|
|
+ local_defs[cfg_ir.get_def_variable(definition).node_id].append(definition)
|
|
|
|
|
|
dominator_tree = cfg_dominators.get_dominator_tree(entry_point)
|
|
|
reachable_blocks = cfg_ir.get_all_reachable_blocks(entry_point)
|
|
|
- for (variable, all_checks) in local_checks.items():
|
|
|
- for check in all_checks:
|
|
|
- is_reachable = False
|
|
|
- for local_def in local_defs[variable]:
|
|
|
- if dominator_tree.dominates_instruction(local_def, check):
|
|
|
- # Check is dominated by a definition. Replace it by a 'True' literal.
|
|
|
- check.redefine(cfg_ir.Literal(True))
|
|
|
- is_reachable = True
|
|
|
- break
|
|
|
- elif check.block in reachable_blocks[local_def.block]:
|
|
|
- is_reachable = True
|
|
|
-
|
|
|
- if not is_reachable:
|
|
|
- # Check cannot be reached from any definition. Replace it by a 'False' literal.
|
|
|
- check.redefine(cfg_ir.Literal(False))
|
|
|
+ for (variable, check) in local_checks:
|
|
|
+ is_reachable = False
|
|
|
+ for local_def in local_defs[variable]:
|
|
|
+ if dominator_tree.dominates_instruction(local_def, check):
|
|
|
+ # Check is dominated by a definition. Replace it by a 'True' literal.
|
|
|
+ check.redefine(cfg_ir.Literal(True))
|
|
|
+ is_reachable = True
|
|
|
+ break
|
|
|
+ elif check.block in reachable_blocks[local_def.block]:
|
|
|
+ is_reachable = True
|
|
|
+
|
|
|
+ if not is_reachable:
|
|
|
+ # Check cannot be reached from any definition. Replace it by a 'False' literal.
|
|
|
+ check.redefine(cfg_ir.Literal(False))
|
|
|
|
|
|
def eliminate_unused_definitions(entry_point):
|
|
|
"""Tries to eliminate unused definitions in the control-flow graphb defined by the
|