Skip to content

Commit 0e205be

Browse files
author
Owen Jones
committed
Use unordered set of irep_ids in ci_lazy_methods
Used set instead of vector to remove duplicates, which should prevent investigating the same method multiple times.
1 parent 4a5a29a commit 0e205be

File tree

4 files changed

+29
-34
lines changed

4 files changed

+29
-34
lines changed

src/java_bytecode/ci_lazy_methods.cpp

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ bool ci_lazy_methodst::operator()(
7171
method_bytecodet &method_bytecode,
7272
const method_convertert &method_converter)
7373
{
74-
std::vector<irep_idt> methods_to_convert_later;
74+
std::unordered_set<irep_idt> methods_to_convert_later;
7575

7676
main_function_resultt main_function =
7777
get_main_symbol(symbol_table, main_class, get_message_handler());
@@ -93,39 +93,33 @@ bool ci_lazy_methodst::operator()(
9393
const irep_idt methodid =
9494
"java::" + id2string(class_name) + "." + id2string(method.name)
9595
+ ":" + id2string(method.descriptor);
96-
methods_to_convert_later.push_back(methodid);
96+
methods_to_convert_later.insert(methodid);
9797
}
9898
}
9999
}
100100
else
101-
methods_to_convert_later.push_back(main_function.main_function.name);
101+
methods_to_convert_later.insert(main_function.main_function.name);
102102

103103
// Add any extra entry points specified; we should elaborate these in the
104104
// same way as the main function.
105105
std::vector<irep_idt> extra_entry_points=lazy_methods_extra_entry_points;
106106
resolve_method_names(extra_entry_points, symbol_table);
107107
methods_to_convert_later.insert(
108-
methods_to_convert_later.begin(),
109-
extra_entry_points.begin(),
110-
extra_entry_points.end());
108+
extra_entry_points.begin(), extra_entry_points.end());
111109

112-
std::set<irep_idt> instantiated_classes;
110+
std::unordered_set<irep_idt> instantiated_classes;
113111

114112
{
115-
std::vector<irep_idt> initial_callable_methods;
113+
std::unordered_set<irep_idt> initial_callable_methods;
116114
ci_lazy_methods_neededt initial_lazy_methods(
117-
initial_callable_methods,
118-
instantiated_classes,
119-
symbol_table);
115+
initial_callable_methods, instantiated_classes, symbol_table);
120116
initialize_instantiated_classes(
121117
methods_to_convert_later, namespacet(symbol_table), initial_lazy_methods);
122118
methods_to_convert_later.insert(
123-
methods_to_convert_later.end(),
124-
initial_callable_methods.begin(),
125-
initial_callable_methods.end());
119+
initial_callable_methods.begin(), initial_callable_methods.end());
126120
}
127121

128-
std::set<irep_idt> methods_already_populated;
122+
std::unordered_set<irep_idt> methods_already_populated;
129123
std::vector<const code_function_callt *> virtual_callsites;
130124

131125
bool any_new_methods = true;
@@ -134,7 +128,7 @@ bool ci_lazy_methodst::operator()(
134128
any_new_methods=false;
135129
while(!methods_to_convert_later.empty())
136130
{
137-
std::vector<irep_idt> methods_to_convert;
131+
std::unordered_set<irep_idt> methods_to_convert;
138132
std::swap(methods_to_convert, methods_to_convert_later);
139133
for(const auto &mname : methods_to_convert)
140134
{
@@ -274,7 +268,7 @@ void ci_lazy_methodst::resolve_method_names(
274268
/// whose references may be passed, directly or indirectly, to any of the
275269
/// functions in `entry_points`.
276270
void ci_lazy_methodst::initialize_instantiated_classes(
277-
const std::vector<irep_idt> &entry_points,
271+
const std::unordered_set<irep_idt> &entry_points,
278272
const namespacet &ns,
279273
ci_lazy_methods_neededt &needed_lazy_methods)
280274
{
@@ -410,8 +404,8 @@ void ci_lazy_methodst::gather_virtual_callsites(
410404
/// defined on classes that are not 'needed' are ignored)
411405
void ci_lazy_methodst::get_virtual_method_targets(
412406
const exprt &called_function,
413-
const std::set<irep_idt> &instantiated_classes,
414-
std::vector<irep_idt> &callable_methods,
407+
const std::unordered_set<irep_idt> &instantiated_classes,
408+
std::unordered_set<irep_idt> &callable_methods,
415409
symbol_tablet &symbol_table)
416410
{
417411
PRECONDITION(called_function.id()==ID_virtual_function);
@@ -433,7 +427,7 @@ void ci_lazy_methodst::get_virtual_method_targets(
433427
const irep_idt method_name = get_virtual_method_target(
434428
instantiated_classes, call_basename, class_name, symbol_table);
435429
if(!method_name.empty())
436-
callable_methods.push_back(method_name);
430+
callable_methods.insert(method_name);
437431
}
438432
}
439433

@@ -539,7 +533,7 @@ void ci_lazy_methodst::gather_field_types(
539533
/// `call_basename` if found and `classname` is present in
540534
/// `instantiated_classes`, or irep_idt() otherwise.
541535
irep_idt ci_lazy_methodst::get_virtual_method_target(
542-
const std::set<irep_idt> &instantiated_classes,
536+
const std::unordered_set<irep_idt> &instantiated_classes,
543537
const irep_idt &call_basename,
544538
const irep_idt &classname,
545539
const symbol_tablet &symbol_table)

src/java_bytecode/ci_lazy_methods.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class ci_lazy_methodst:public messaget
115115
const symbol_tablet &symbol_table);
116116

117117
void initialize_instantiated_classes(
118-
const std::vector<irep_idt> &entry_points,
118+
const std::unordered_set<irep_idt> &entry_points,
119119
const namespacet &ns,
120120
ci_lazy_methods_neededt &needed_lazy_methods);
121121

@@ -135,8 +135,8 @@ class ci_lazy_methodst:public messaget
135135

136136
void get_virtual_method_targets(
137137
const exprt &called_function,
138-
const std::set<irep_idt> &instantiated_classes,
139-
std::vector<irep_idt> &callable_methods,
138+
const std::unordered_set<irep_idt> &instantiated_classes,
139+
std::unordered_set<irep_idt> &callable_methods,
140140
symbol_tablet &symbol_table);
141141

142142
void gather_needed_globals(
@@ -150,7 +150,7 @@ class ci_lazy_methodst:public messaget
150150
ci_lazy_methods_neededt &needed_lazy_methods);
151151

152152
irep_idt get_virtual_method_target(
153-
const std::set<irep_idt> &instantiated_classes,
153+
const std::unordered_set<irep_idt> &instantiated_classes,
154154
const irep_idt &call_basename,
155155
const irep_idt &classname,
156156
const symbol_tablet &symbol_table);

src/java_bytecode/ci_lazy_methods_needed.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Author: Chris Smowton, [email protected]
2020
void ci_lazy_methods_neededt::add_needed_method(
2121
const irep_idt &method_symbol_name)
2222
{
23-
callable_methods.push_back(method_symbol_name);
23+
callable_methods.insert(method_symbol_name);
2424
}
2525

2626
/// Notes class `class_symbol_name` will be instantiated, or a static field

src/java_bytecode/ci_lazy_methods_needed.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,19 @@ Author: Chris Smowton, [email protected]
1414

1515
#include <vector>
1616
#include <set>
17+
#include <unordered_set>
1718
#include <util/symbol_table.h>
1819

1920
class ci_lazy_methods_neededt
2021
{
2122
public:
2223
ci_lazy_methods_neededt(
23-
std::vector<irep_idt> &_callable_methods,
24-
std::set<irep_idt> &_instantiated_classes,
25-
symbol_tablet &_symbol_table):
26-
callable_methods(_callable_methods),
27-
instantiated_classes(_instantiated_classes),
28-
symbol_table(_symbol_table)
24+
std::unordered_set<irep_idt> &_callable_methods,
25+
std::unordered_set<irep_idt> &_instantiated_classes,
26+
symbol_tablet &_symbol_table)
27+
: callable_methods(_callable_methods),
28+
instantiated_classes(_instantiated_classes),
29+
symbol_table(_symbol_table)
2930
{}
3031

3132
void add_needed_method(const irep_idt &);
@@ -38,11 +39,11 @@ class ci_lazy_methods_neededt
3839
// contain all methods that have previously been elaborated.
3940
// It should be changed to a set if we develop the need to use
4041
// it that way.
41-
std::vector<irep_idt> &callable_methods;
42+
std::unordered_set<irep_idt> &callable_methods;
4243
// instantiated_classes on the other hand is a true set of every class
4344
// found so far, so we can use a membership test to avoid
4445
// repeatedly exploring a class hierarchy.
45-
std::set<irep_idt> &instantiated_classes;
46+
std::unordered_set<irep_idt> &instantiated_classes;
4647
symbol_tablet &symbol_table;
4748
};
4849

0 commit comments

Comments
 (0)