Skip to content

Commit 9af5219

Browse files
committed
Centralize generational increases of level2 names
Refactor all local name operations to within the level2 object itself to allow for shadowing global state with the local dictionary.
1 parent 937d557 commit 9af5219

File tree

5 files changed

+82
-21
lines changed

5 files changed

+82
-21
lines changed

src/goto-symex/goto_symex_state.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,7 @@ void goto_symex_statet::assignment(
181181
#endif
182182

183183
// do the l2 renaming
184-
const auto level2_it =
185-
level2.current_names.emplace(l1_identifier, std::make_pair(lhs, 0)).first;
186-
symex_renaming_levelt::increase_counter(level2_it);
184+
level2.increase_generation(l1_identifier, lhs);
187185
set_l2_indices(lhs, ns);
188186

189187
// in case we happen to be multi-threaded, record the memory access
@@ -429,10 +427,7 @@ bool goto_symex_statet::l2_thread_read_encoding(
429427

430428
if(a_s_read.second.empty())
431429
{
432-
auto level2_it =
433-
level2.current_names.emplace(l1_identifier, std::make_pair(ssa_l1, 0))
434-
.first;
435-
symex_renaming_levelt::increase_counter(level2_it);
430+
level2.increase_generation(l1_identifier, ssa_l1);
436431
a_s_read.first=level2.current_count(l1_identifier);
437432
}
438433

@@ -468,10 +463,6 @@ bool goto_symex_statet::l2_thread_read_encoding(
468463
return true;
469464
}
470465

471-
const auto level2_it =
472-
level2.current_names.emplace(l1_identifier, std::make_pair(ssa_l1, 0))
473-
.first;
474-
475466
// No event and no fresh index, but avoid constant propagation
476467
if(!record_events)
477468
{
@@ -481,7 +472,8 @@ bool goto_symex_statet::l2_thread_read_encoding(
481472
}
482473

483474
// produce a fresh L2 name
484-
symex_renaming_levelt::increase_counter(level2_it);
475+
level2.increase_generation(l1_identifier, ssa_l1);
476+
485477
set_l2_indices(ssa_l1, ns);
486478
expr=ssa_l1;
487479

src/goto-symex/renaming_level.h

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ Author: Romain Brenguier, [email protected]
1414

1515
#include <map>
1616
#include <unordered_set>
17+
#include <memory>
1718

1819
#include <util/irep.h>
1920
#include <util/ssa_expr.h>
21+
#include <iostream>
2022

2123
/// Wrapper for a \c current_names map, which maps each identifier to an SSA
2224
/// expression and a counter.
@@ -31,7 +33,7 @@ struct symex_renaming_levelt
3133
current_namest current_names;
3234

3335
/// Counter corresponding to an identifier
34-
unsigned current_count(const irep_idt &identifier) const
36+
virtual unsigned current_count(const irep_idt &identifier) const
3537
{
3638
const auto it = current_names.find(identifier);
3739
return it == current_names.end() ? 0 : it->second.second;
@@ -84,6 +86,77 @@ struct symex_level2t : public symex_renaming_levelt
8486
{
8587
symex_level2t() = default;
8688
~symex_level2t() override = default;
89+
90+
/// In the case of a state split, we want to keep track of the overall
91+
/// name generation across all states for identifier creation.
92+
optionalt<current_namest> local_generations;
93+
94+
void erase(const irep_idt &identifier)
95+
{
96+
current_names.erase(identifier);
97+
if (local_generations)
98+
local_generations->erase(identifier);
99+
}
100+
101+
/// If we have a local counter, use that instead of our global.
102+
unsigned current_count(const irep_idt &identifier) const override
103+
{
104+
if(local_generations)
105+
{
106+
const auto it = local_generations->find(identifier);
107+
return it == local_generations->end() ? 0 : it->second.second;
108+
}
109+
else
110+
{
111+
return symex_renaming_levelt::current_count(identifier);
112+
}
113+
}
114+
115+
/// Ages the generation of an ssa expression by one.
116+
void increase_generation(
117+
const irep_idt l1_identifier,
118+
const ssa_exprt &lhs)
119+
{
120+
current_names.emplace(l1_identifier, std::make_pair(lhs, 0));
121+
increase_generation(l1_identifier);
122+
}
123+
124+
/// Ages the generation of an ssa expression by one. Does nothing
125+
/// if there isn't an expression keyed by the l1 identifier.
126+
void increase_generation(
127+
const irep_idt l1_identifier)
128+
{
129+
auto current_names_iter = current_names.find(l1_identifier);
130+
if (current_names_iter == current_names.end())
131+
return;
132+
133+
current_names_iter->second.second++;
134+
if(local_generations)
135+
{
136+
auto local_iter = local_generations->find(l1_identifier);
137+
if (local_iter != local_generations->end()) {}
138+
local_iter->second.second = current_names_iter->second.second;
139+
}
140+
}
141+
142+
current_namest get_current_names()
143+
{
144+
return local_generations ? *local_generations : current_names;
145+
}
146+
147+
void print_differences()
148+
{
149+
if (!local_generations)
150+
return;
151+
152+
for(const auto &dave : *local_generations)
153+
{
154+
auto local = dave.second.second;
155+
auto global = current_names->find(dave.first)->second.second;
156+
if (local != global)
157+
std::cout << "ID: " << id2string(dave.first) << ", local: " << local << " global: " << global << '\n';
158+
}
159+
}
87160
};
88161

89162
/// Undo all levels of renaming

src/goto-symex/symex_dead.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,5 @@ void goto_symext::symex_dead(statet &state)
5252
state.propagation.erase(l1_identifier);
5353

5454
// L2 renaming
55-
auto level2_it = state.level2.current_names.find(l1_identifier);
56-
if(level2_it != state.level2.current_names.end())
57-
symex_renaming_levelt::increase_counter(level2_it);
55+
state.level2.increase_generation(l1_identifier);
5856
}

src/goto-symex/symex_decl.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,8 @@ void goto_symext::symex_decl(statet &state, const symbol_exprt &expr)
6868
// L2 renaming
6969
// inlining may yield multiple declarations of the same identifier
7070
// within the same L1 context
71-
const auto level2_it =
72-
state.level2.current_names.emplace(l1_identifier, std::make_pair(ssa, 0))
73-
.first;
74-
symex_renaming_levelt::increase_counter(level2_it);
71+
state.level2.increase_generation(l1_identifier, ssa);
72+
7573
const bool record_events=state.record_events;
7674
state.record_events=false;
7775
state.rename(ssa, ns);

src/goto-symex/symex_function_call.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ static void pop_frame(goto_symext::statet &state)
361361
}
362362
auto cur = c_it;
363363
++c_it;
364-
state.level2.current_names.erase(cur);
364+
state.level2.erase(cur->first);
365365
}
366366
}
367367

0 commit comments

Comments
 (0)