Skip to content

Commit 61507bd

Browse files
committed
Kill let-bound variables after the current instruction completes
This avoids both wasted storage due to let-bound variables staying in the L2 renaming map, propagator and/or value-set, and avoids generating pointless PHI-node instructions for them.
1 parent dc10d51 commit 61507bd

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

src/goto-symex/goto_symex.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ class goto_symext
219219

220220
/// \brief Called for each step in the symbolic execution
221221
/// This calls \ref print_symex_step to print symex's current instruction if
222-
/// required, then \ref execute_instruction to execute the actual instruction
223-
/// body.
222+
/// required, then \ref execute_next_instruction to execute the actual
223+
/// instruction body.
224224
/// \param get_goto_function: The delegate to retrieve function bodies (see
225225
/// \ref get_goto_functiont)
226226
/// \param state: Symbolic execution state for current instruction
@@ -239,6 +239,11 @@ class goto_symext
239239
const get_goto_functiont &get_goto_function,
240240
statet &state);
241241

242+
/// Kills any variables in \ref instruction_local_symbols (these are currently
243+
/// always let-bound variables defined in the course of executing the current
244+
/// instruction), then clears \ref instruction_local_symbols.
245+
void kill_instruction_local_symbols(statet &state);
246+
242247
/// Prints the route of symex as it walks through the code. Used for
243248
/// debugging.
244249
void print_symex_step(statet &state);
@@ -281,6 +286,11 @@ class goto_symext
281286
/// instruction
282287
unsigned atomic_section_counter;
283288

289+
/// Variables that should be killed at the end of the current symex_step
290+
/// invocation. Currently this is used for let-bound variables executed during
291+
/// symex, whose lifetime is at most one instruction long.
292+
std::vector<symbol_exprt> instruction_local_symbols;
293+
284294
/// The messaget to write log messages to
285295
mutable messaget log;
286296

@@ -531,8 +541,8 @@ class goto_symext
531541

532542
/// Execute a single let expression, which should not have any nested let
533543
/// expressions (use \ref lift_lets instead if there might be).
534-
/// The caller is responsible for killing the newly-defined variable when
535-
/// appropriate.
544+
/// Records the newly-defined variable in \ref instruction_local_symbols,
545+
/// meaning it will be killed when \ref symex_step concludes.
536546
void lift_let(statet &state, const let_exprt &let_expr);
537547

538548
void symex_assign_rec(

src/goto-symex/symex_clean_expr.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ void goto_symext::lift_let(statet &state, const let_exprt &let_expr)
186186
let_value,
187187
value_assignment_guard,
188188
symex_targett::assignment_typet::HIDDEN);
189+
190+
// Schedule the bound variable to be cleaned up at the end of symex_step:
191+
instruction_local_symbols.push_back(let_expr.symbol());
189192
}
190193

191194
void goto_symext::lift_lets(statet &state, exprt &rhs)

src/goto-symex/symex_main.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ void goto_symext::symex_step(
513513
// Print debug statements if they've been enabled.
514514
print_symex_step(state);
515515
execute_next_instruction(get_goto_function, state);
516+
kill_instruction_local_symbols(state);
516517
}
517518

518519
void goto_symext::execute_next_instruction(
@@ -652,6 +653,13 @@ void goto_symext::execute_next_instruction(
652653
}
653654
}
654655

656+
void goto_symext::kill_instruction_local_symbols(statet &state)
657+
{
658+
for(const auto &symbol_expr : instruction_local_symbols)
659+
symex_dead(state, symbol_expr);
660+
instruction_local_symbols.clear();
661+
}
662+
655663
/// Check if an expression only contains one unique symbol (possibly repeated
656664
/// multiple times)
657665
/// \param expr: The expression to examine

0 commit comments

Comments
 (0)