Skip to content

Commit

Permalink
#18 Deepest position ignoring cstack index
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcere committed Dec 10, 2024
1 parent 30deaf0 commit 8ceb48f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/greedy/greedy_new_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,12 @@ def _available_positions(self, var_elem: var_id_T, cstate: SymbolicState) -> Gen
elif STACK_DEPTH >= fidx >= 0 and cstate.stack[fidx] != var_elem:
yield position

def _deepest_position(self, var_elem: var_id_T) -> Optional[int]:
"""
Deepest position in the final stack of var_elem (if any). Used to determine which computation is chosen first
"""
return self._var2pos_stack[var_elem][-1] if len(self._var2pos_stack[var_elem]) > 0 else None

def var_must_be_moved(self, var_elem: var_id_T, cstate: SymbolicState) -> bool:
"""
By construction, a var element must be moved if there is an available position in which it
Expand Down Expand Up @@ -504,7 +510,7 @@ def _score_candidate(self, candidates: List[instr_id_T], cstate: SymbolicState)
# Function invocations might generate multiple values that we should take into account
for out_var in top_instr['outpt_sk']:
# We detect which is the deepest position in which the element can be placed
deepest_occurrence = next(self._available_positions(out_var, cstate), None)
deepest_occurrence = self._deepest_position(out_var)
if deepest_occurrence is not None:
deepest_pos[out_var] = deepest_occurrence

Expand Down

0 comments on commit 8ceb48f

Please sign in to comment.