Skip to content

Commit 4387257

Browse files
author
Owen
committed
Speed up resolution of virtual callsites in lazy loading v1
We removed duplicates from the list of virtual callsites by using an unordered set. This gave a large speed up on at least one use case. There is scope for further optimisation.
1 parent 3af5509 commit 4387257

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/java_bytecode/ci_lazy_methods.cpp

+9-6
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,15 @@ bool ci_lazy_methodst::operator()(
170170
<< " callsites)"
171171
<< eom;
172172

173-
for(const auto &callsite : virtual_callsites)
173+
std::unordered_set<exprt, irep_hash> unique_functions;
174+
for(const code_function_callt *virtual_callsite : virtual_callsites)
175+
unique_functions.insert(virtual_callsite->function());
176+
177+
for(const exprt &function : unique_functions)
174178
{
175179
// This will also create a stub if a virtual callsite has no targets.
176180
get_virtual_method_targets(
177-
*callsite,
181+
function,
178182
instantiated_classes,
179183
method_worklist2,
180184
symbol_table);
@@ -403,21 +407,20 @@ void ci_lazy_methodst::gather_virtual_callsites(
403407

404408
/// Find possible callees, excluding types that are not known to be
405409
/// instantiated.
406-
/// \param c: function call whose potential target functions should
407-
/// be determined.
410+
/// \param called_function: virtual function call whose concrete function calls
411+
/// should be determined.
408412
/// \param instantiated_classes: set of classes that can be instantiated. Any
409413
/// potential callee not in this set will be ignored.
410414
/// \param symbol_table: global symbol table
411415
/// \param [out] callable_methods: Populated with all possible `c` callees,
412416
/// taking `instantiated_classes` into account (virtual function overrides
413417
/// defined on classes that are not 'needed' are ignored)
414418
void ci_lazy_methodst::get_virtual_method_targets(
415-
const code_function_callt &c,
419+
const exprt &called_function,
416420
const std::set<irep_idt> &instantiated_classes,
417421
std::vector<irep_idt> &callable_methods,
418422
symbol_tablet &symbol_table)
419423
{
420-
const auto &called_function=c.function();
421424
PRECONDITION(called_function.id()==ID_virtual_function);
422425

423426
const auto &call_class=called_function.get(ID_C_class);

src/java_bytecode/ci_lazy_methods.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class ci_lazy_methodst:public messaget
134134
std::vector<const code_function_callt *> &result);
135135

136136
void get_virtual_method_targets(
137-
const code_function_callt &c,
137+
const exprt &called_function,
138138
const std::set<irep_idt> &instantiated_classes,
139139
std::vector<irep_idt> &callable_methods,
140140
symbol_tablet &symbol_table);

0 commit comments

Comments
 (0)