Skip to content

Commit 33d9154

Browse files
Extract filter_symbol_table method
1 parent 02a0e54 commit 33d9154

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

jbmc/src/java_bytecode/ci_lazy_methods.cpp

+21-9
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,30 @@ bool ci_lazy_methodst::operator()(
186186
}
187187

188188
// Remove symbols for methods that were declared but never used:
189-
symbol_tablet keep_symbols;
189+
symbol_tablet keep_symbols = filter_symbol_table(
190+
symbol_table, method_bytecode, methods_already_populated);
191+
190192
// Manually keep @inflight_exception, as it is unused at this stage
191193
// but will become used when the `remove_exceptions` pass is run:
192194
keep_symbols.add(symbol_table.lookup_ref(INFLIGHT_EXCEPTION_VARIABLE_NAME));
193195

196+
debug() << "CI lazy methods: removed "
197+
<< symbol_table.symbols.size() - keep_symbols.symbols.size()
198+
<< " unreachable methods and globals" << eom;
199+
200+
symbol_table.swap(keep_symbols);
201+
return false;
202+
}
203+
204+
/// Only keep functions that have been converted and global variables that are
205+
/// used in these functions.
206+
/// \return new symbol table
207+
symbol_tablet ci_lazy_methodst::filter_symbol_table(
208+
const symbol_tablet &symbol_table,
209+
const method_bytecodet &method_bytecode,
210+
const std::unordered_set<irep_idt> &methods_already_populated)
211+
{
212+
symbol_tablet keep_symbols;
194213
for(const auto &sym : symbol_table.symbols)
195214
{
196215
// Don't keep global variables (unless they're gathered below from a
@@ -213,14 +232,7 @@ bool ci_lazy_methodst::operator()(
213232
}
214233
keep_symbols.add(sym.second);
215234
}
216-
217-
debug() << "CI lazy methods: removed "
218-
<< symbol_table.symbols.size() - keep_symbols.symbols.size()
219-
<< " unreachable methods and globals" << eom;
220-
221-
symbol_table.swap(keep_symbols);
222-
223-
return false;
235+
return keep_symbols;
224236
}
225237

226238
/// Look for virtual callsites with no candidate targets. If we have

jbmc/src/java_bytecode/ci_lazy_methods.h

+5
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ class ci_lazy_methodst:public messaget
194194
std::unordered_set<irep_idt> &instantiated_classes,
195195
const std::unordered_set<exprt, irep_hash> &virtual_function_calls,
196196
symbol_tablet &symbol_table);
197+
198+
symbol_tablet filter_symbol_table(
199+
const symbol_tablet &symbol_table,
200+
const method_bytecodet &method_bytecode,
201+
const std::unordered_set<irep_idt> &methods_already_populated);
197202
};
198203

199204
#endif // CPROVER_JAVA_BYTECODE_GATHER_METHODS_LAZILY_H

0 commit comments

Comments
 (0)