Skip to content

Commit 5054f03

Browse files
committed
Optimise symex state management for straight-line code with GOTOs
In the situation of merge on a state that hasn't been traversed (with a false guard) try and move the names into the destination state instead of a merge or copy operation
1 parent e718a62 commit 5054f03

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

src/goto-symex/symex_goto.cpp

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,17 @@ void goto_symext::symex_goto(statet &state)
210210
// merge_gotos when we visit new_state_pc
211211
framet::goto_state_listt &goto_state_list =
212212
state.call_stack().top().goto_state_map[new_state_pc];
213-
goto_state_list.emplace_back(state);
213+
214+
// If the guard is true (and the alternative branch unreachable) we can move
215+
// the state in this case as it'll never be accessed on the alternate branch.
216+
if(new_guard.is_true())
217+
{
218+
goto_state_list.emplace_back(state, true);
219+
}
220+
else
221+
{
222+
goto_state_list.emplace_back(state);
223+
}
214224

215225
symex_transition(state, state_pc, backward);
216226

@@ -314,14 +324,23 @@ void goto_symext::merge_goto(goto_statet &&goto_state, statet &state)
314324
"atomic sections differ across branches",
315325
state.source.pc->source_location);
316326

317-
// do SSA phi functions
318-
phi_function(goto_state, state);
327+
if (!goto_state.guard.is_false())
328+
{
329+
if(state.guard.is_false())
330+
{
331+
state.level2 = std::move(goto_state.level2);
332+
state.propagation = std::move(goto_state.propagation);
333+
state.value_set = std::move(goto_state.value_set);
334+
}
335+
else
336+
{
337+
// do SSA phi functions
338+
phi_function(goto_state, state);
319339

320-
// merge value sets
321-
if(state.guard.is_false() && !goto_state.guard.is_false())
322-
state.value_set = std::move(goto_state.value_set);
323-
else if(!goto_state.guard.is_false())
324-
state.value_set.make_union(goto_state.value_set);
340+
// merge value sets
341+
state.value_set.make_union(goto_state.value_set);
342+
}
343+
}
325344

326345
// adjust guard
327346
state.guard|=goto_state.guard;

0 commit comments

Comments
 (0)