Skip to content

Commit 810b70c

Browse files
committed
call graph helper interface to "disconnect unreachable functions"
1 parent cee6d7d commit 810b70c

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/analyses/call_graph_helpers.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ std::set<irep_idt> get_functions_reachable_within_n_steps(
102102
graph, start_functions, n, forwards);
103103
}
104104

105+
void disconnect_unreachable_functions(
106+
call_grapht::directed_grapht &graph,
107+
const irep_idt &function)
108+
{
109+
std::size_t start_idx = *(graph.get_node_index(function));
110+
if(start_idx != optionalt<std::size_t>())
111+
graph.disconnect_unreachable(start_idx);
112+
}
113+
105114
std::set<irep_idt> get_shortest_function_path(
106115
const call_grapht::directed_grapht &graph,
107116
const irep_idt &src,

src/analyses/call_graph_helpers.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,15 @@ std::set<irep_idt> get_functions_reachable_within_n_steps(
8282
std::size_t &n,
8383
bool forwards);
8484

85+
/// Disconnects all functions in the call graph that are unreachable from
86+
/// a given start function.
87+
/// Removing nodes requires re-indexing, so instead we disconnect them, removing
88+
/// all in and out edges from those nodes.
89+
/// This speeds up backwards reachability.
90+
/// \param graph: call graph
91+
/// \param function: start function
92+
void disconnect_unreachable_functions(
93+
call_grapht::directed_grapht &graph,
94+
const irep_idt &function);
95+
8596
#endif

0 commit comments

Comments
 (0)