Skip to content

Commit e09a575

Browse files
committed
Use sharing_mapt
1 parent ca520cd commit e09a575

File tree

6 files changed

+48
-22
lines changed

6 files changed

+48
-22
lines changed

src/goto-symex/goto_symex_state.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ void goto_symex_statet::rename(
307307
// L1 identifiers are used for propagation!
308308
auto p_it = propagation.find(ssa.get_identifier());
309309

310-
if(p_it != propagation.end())
311-
expr=p_it->second; // already L2
310+
if(p_it.second)
311+
expr = p_it.first; // already L2
312312
else
313313
set_l2_indices(ssa, ns);
314314
}
@@ -796,7 +796,10 @@ void goto_symex_statet::print_backtrace(std::ostream &out) const
796796
/// because there aren't any current callers.
797797
void goto_statet::output_propagation_map(std::ostream &out)
798798
{
799-
for(const auto &name_value : propagation)
799+
sharing_mapt<irep_idt, exprt>::viewt view;
800+
propagation.get_view(view);
801+
802+
for(const auto &name_value : view)
800803
{
801804
out << name_value.first << " <- " << format(name_value.second) << "\n";
802805
}

src/goto-symex/goto_symex_state.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ Author: Daniel Kroening, [email protected]
1515
#include <memory>
1616
#include <unordered_set>
1717

18-
#include <util/invariant.h>
1918
#include <util/guard.h>
20-
#include <util/std_expr.h>
21-
#include <util/ssa_expr.h>
19+
#include <util/invariant.h>
2220
#include <util/make_unique.h>
21+
#include <util/sharing_map.h>
22+
#include <util/ssa_expr.h>
23+
#include <util/std_expr.h>
2324

2425
#include <pointer-analysis/value_set.h>
2526
#include <goto-programs/goto_function.h>
@@ -61,7 +62,7 @@ class goto_statet
6162
// "constants" can include symbols, but only in the context of an address-of
6263
// op (i.e. &x can be propagated), and an address-taken thing should only be
6364
// L1.
64-
std::map<irep_idt, exprt> propagation;
65+
sharing_mapt<irep_idt, exprt> propagation;
6566

6667
void output_propagation_map(std::ostream &);
6768

src/goto-symex/symex_goto.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,17 +445,17 @@ static void merge_names(
445445
{
446446
const auto p_it = goto_state.propagation.find(l1_identifier);
447447

448-
if(p_it != goto_state.propagation.end())
449-
goto_state_rhs = p_it->second;
448+
if(p_it.second)
449+
goto_state_rhs = p_it.first;
450450
else
451451
to_ssa_expr(goto_state_rhs).set_level_2(goto_count);
452452
}
453453

454454
{
455455
const auto p_it = dest_state.propagation.find(l1_identifier);
456456

457-
if(p_it != dest_state.propagation.end())
458-
dest_state_rhs = p_it->second;
457+
if(p_it.second)
458+
dest_state_rhs = p_it.first;
459459
else
460460
to_ssa_expr(dest_state_rhs).set_level_2(dest_count);
461461
}

src/pointer-analysis/value_set.cpp

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const value_sett::entryt *value_sett::find_entry(const value_sett::idt &id)
5252
const
5353
{
5454
auto found = values.find(id);
55-
return found == values.end() ? nullptr : &found->second;
55+
return !found.second ? nullptr : &found.first;
5656
}
5757

5858
value_sett::entryt &value_sett::get_entry(const entryt &e, const typet &type)
@@ -64,10 +64,7 @@ value_sett::entryt &value_sett::get_entry(const entryt &e, const typet &type)
6464
else
6565
index=e.identifier;
6666

67-
std::pair<valuest::iterator, bool> r=
68-
values.insert(std::pair<idt, entryt>(index, e));
69-
70-
return r.first->second;
67+
return values.place(index, e).first;
7168
}
7269

7370
bool value_sett::insert(
@@ -98,7 +95,10 @@ void value_sett::output(
9895
const namespacet &ns,
9996
std::ostream &out) const
10097
{
101-
for(const auto &values_entry : values)
98+
valuest::viewt view;
99+
values.get_view(view);
100+
101+
for(const auto &values_entry : view)
102102
{
103103
irep_idt identifier, display_name;
104104

@@ -205,6 +205,7 @@ bool value_sett::make_union(const value_sett::valuest &new_values)
205205
{
206206
bool result=false;
207207

208+
#if 0
208209
valuest::iterator v_it=values.begin();
209210

210211
for(valuest::const_iterator
@@ -236,6 +237,23 @@ bool value_sett::make_union(const value_sett::valuest &new_values)
236237
v_it++;
237238
it++;
238239
}
240+
#else
241+
value_sett::valuest::delta_viewt delta_view;
242+
243+
new_values.get_delta_view(values, delta_view, false);
244+
245+
for(const auto &delta_entry : delta_view)
246+
{
247+
if(delta_entry.in_both)
248+
result |= make_union(
249+
values.at(delta_entry.k).object_map, delta_entry.m.object_map);
250+
else
251+
{
252+
values.insert(delta_entry.k, delta_entry.m);
253+
result = true;
254+
}
255+
}
256+
#endif
239257

240258
return result;
241259
}

src/pointer-analysis/value_set.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Author: Daniel Kroening, [email protected]
1616

1717
#include <util/mp_arith.h>
1818
#include <util/reference_counting.h>
19+
#include <util/sharing_map.h>
1920

2021
#include "object_numbering.h"
2122
#include "value_sets.h"
@@ -290,11 +291,11 @@ class value_sett
290291
///
291292
/// The components of the ID are thus duplicated in the `valuest` key and in
292293
/// `entryt` fields.
293-
#ifdef USE_DSTRING
294-
typedef std::map<idt, entryt> valuest;
295-
#else
294+
#ifdef USE_DSTRING
295+
typedef sharing_mapt<idt, entryt> valuest;
296+
#else
296297
typedef std::unordered_map<idt, entryt, string_hash> valuest;
297-
#endif
298+
#endif
298299

299300
/// Gets values pointed to by `expr`, including following dereference
300301
/// operators (i.e. this is not a simple lookup in `valuest`).

src/pointer-analysis/value_set_analysis.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ void value_sets_to_xml(
4141
xmlt &i=dest.new_element("instruction");
4242
i.new_element()=::xml(location);
4343

44-
for(const auto &values_entry : value_set.values)
44+
value_sett::valuest::viewt view;
45+
value_set.values.get_view(view);
46+
47+
for(const auto &values_entry : view)
4548
{
4649
xmlt &var=i.new_element("variable");
4750
var.new_element("identifier").data=

0 commit comments

Comments
 (0)