Skip to content

Commit 58d440a

Browse files
Merge pull request #3559 from romainbrenguier/optimize/get_l1_name
Optimize remove_level_2
2 parents 7a30b00 + 7114c57 commit 58d440a

File tree

4 files changed

+22
-23
lines changed

4 files changed

+22
-23
lines changed

src/goto-symex/goto_symex_state.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Author: Daniel Kroening, [email protected]
2525

2626
#include <analyses/dirty.h>
2727

28+
static void get_l1_name(exprt &expr);
29+
2830
goto_symex_statet::goto_symex_statet()
2931
: depth(0),
3032
symex_target(nullptr),
@@ -220,7 +222,7 @@ void goto_symex_statet::assignment(
220222
get_l1_name(l1_rhs);
221223

222224
ssa_exprt l1_lhs(lhs);
223-
get_l1_name(l1_lhs);
225+
l1_lhs.remove_level_2();
224226

225227
if(run_validation_checks)
226228
{
@@ -750,7 +752,7 @@ void goto_symex_statet::get_original_name(typet &type) const
750752
}
751753
}
752754

753-
void goto_symex_statet::get_l1_name(exprt &expr) const
755+
static void get_l1_name(exprt &expr)
754756
{
755757
// do not reset the type !
756758

src/goto-symex/goto_symex_state.h

-3
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ class goto_symex_statet final
9797
void set_l1_indices(ssa_exprt &expr, const namespacet &ns);
9898
void set_l2_indices(ssa_exprt &expr, const namespacet &ns);
9999

100-
// only required for value_set.assign
101-
void get_l1_name(exprt &expr) const;
102-
103100
// this maps L1 names to (L2) types
104101
typedef std::unordered_map<irep_idt, typet> l1_typest;
105102
l1_typest l1_types;

src/util/ssa_expr.cpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ Author: Daniel Kroening, [email protected]
1313

1414
#include <util/arith_tools.h>
1515

16+
/// If \p expr is a symbol "s" add to \p os "s!l0@l1#l2" and to \p l1_object_os
17+
/// "s!l0@l1".
18+
/// If \p expr is a member or index expression, recursively apply the procedure
19+
/// and add ".component_name" or "[index]" to \p os.
1620
static void build_ssa_identifier_rec(
1721
const exprt &expr,
1822
const irep_idt &l0,
@@ -82,7 +86,7 @@ bool ssa_exprt::can_build_identifier(const exprt &expr)
8286
return false;
8387
}
8488

85-
std::pair<irep_idt, irep_idt> ssa_exprt::build_identifier(
89+
static std::pair<irep_idt, irep_idt> build_identifier(
8690
const exprt &expr,
8791
const irep_idt &l0,
8892
const irep_idt &l1,
@@ -95,3 +99,14 @@ std::pair<irep_idt, irep_idt> ssa_exprt::build_identifier(
9599

96100
return std::make_pair(irep_idt(oss.str()), irep_idt(l1_object_oss.str()));
97101
}
102+
103+
void ssa_exprt::update_identifier()
104+
{
105+
const irep_idt &l0 = get_level_0();
106+
const irep_idt &l1 = get_level_1();
107+
const irep_idt &l2 = get_level_2();
108+
109+
auto idpair = build_identifier(get_original_expr(), l0, l1, l2);
110+
set_identifier(idpair.first);
111+
set(ID_L1_object_identifier, idpair.second);
112+
}

src/util/ssa_expr.h

+2-17
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class ssa_exprt:public symbol_exprt
101101
void remove_level_2()
102102
{
103103
remove(ID_L2);
104-
update_identifier();
104+
set_identifier(get_l1_object_identifier());
105105
}
106106

107107
const irep_idt get_level_0() const
@@ -119,22 +119,7 @@ class ssa_exprt:public symbol_exprt
119119
return get(ID_L2);
120120
}
121121

122-
void update_identifier()
123-
{
124-
const irep_idt &l0=get_level_0();
125-
const irep_idt &l1=get_level_1();
126-
const irep_idt &l2=get_level_2();
127-
128-
auto idpair=build_identifier(get_original_expr(), l0, l1, l2);
129-
set_identifier(idpair.first);
130-
set(ID_L1_object_identifier, idpair.second);
131-
}
132-
133-
static std::pair<irep_idt, irep_idt> build_identifier(
134-
const exprt &src,
135-
const irep_idt &l0,
136-
const irep_idt &l1,
137-
const irep_idt &l2);
122+
void update_identifier();
138123

139124
/* Used to determine whether or not an identifier can be built
140125
* before trying and getting an exception */

0 commit comments

Comments
 (0)