Skip to content

Commit de7e1af

Browse files
committed
call graph helper functions
1 parent 357358d commit de7e1af

File tree

2 files changed

+50
-5
lines changed

2 files changed

+50
-5
lines changed

src/analyses/call_graph_helpers.cpp

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ std::set<irep_idt> get_reaching_functions(
7474
std::set<irep_idt> get_functions_reachable_within_n_steps(
7575
const call_grapht::directed_grapht &graph,
7676
const std::set<irep_idt> &start_functions,
77-
std::size_t &n)
77+
std::size_t n)
7878
{
7979
std::vector<std::size_t> start_indices;
8080
std::set<irep_idt> result;
@@ -91,8 +91,32 @@ std::set<irep_idt> get_functions_reachable_within_n_steps(
9191
std::set<irep_idt> get_functions_reachable_within_n_steps(
9292
const call_grapht::directed_grapht &graph,
9393
const irep_idt &start_function,
94-
std::size_t &n)
94+
std::size_t n)
9595
{
96-
std::set<irep_idt> start_functions({ start_function });
96+
std::set<irep_idt> start_functions({start_function});
9797
return get_functions_reachable_within_n_steps(graph, start_functions, n);
9898
}
99+
100+
void disconnect_unreachable_functions(
101+
call_grapht::directed_grapht &graph,
102+
const irep_idt &function)
103+
{
104+
graph.disconnect_unreachable(*(graph.get_node_index(function)));
105+
}
106+
107+
std::list<irep_idt> get_shortest_function_path(
108+
const call_grapht::directed_grapht &graph,
109+
const irep_idt &src,
110+
const irep_idt &dest)
111+
{
112+
std::list<irep_idt> result;
113+
std::list<std::size_t> path;
114+
115+
graph.shortest_path(
116+
*(graph.get_node_index(src)), *(graph.get_node_index(dest)), path);
117+
118+
for(const auto &n : path)
119+
result.push_back(graph[n].function);
120+
121+
return result;
122+
}

src/analyses/call_graph_helpers.h

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ std::set<irep_idt> get_reaching_functions(
5959
std::set<irep_idt> get_functions_reachable_within_n_steps(
6060
const call_grapht::directed_grapht &graph,
6161
const std::set<irep_idt> &start_functions,
62-
std::size_t &n);
62+
std::size_t n);
6363

6464
/// Get either callers or callees reachable from a given
6565
/// list of functions within N steps
@@ -71,6 +71,27 @@ std::set<irep_idt> get_functions_reachable_within_n_steps(
7171
std::set<irep_idt> get_functions_reachable_within_n_steps(
7272
const call_grapht::directed_grapht &graph,
7373
const irep_idt &start_function,
74-
std::size_t &n);
74+
std::size_t n);
75+
76+
/// Get list of functions on the shortest path between two functions
77+
/// \param graph: call graph
78+
/// \param src: function to start from
79+
/// \param dest: function to reach
80+
/// \return list of functions on shortest path
81+
std::list<irep_idt> get_shortest_function_path(
82+
const call_grapht::directed_grapht &graph,
83+
const irep_idt &src,
84+
const irep_idt &dest);
85+
86+
/// Disconnects all functions in the call graph that are unreachable from
87+
/// a given start function.
88+
/// Removing nodes requires re-indexing, so instead we disconnect them, removing
89+
/// all in and out edges from those nodes.
90+
/// This speeds up backwards reachability.
91+
/// \param graph: call graph
92+
/// \param function: start function
93+
void disconnect_unreachable_functions(
94+
call_grapht::directed_grapht &graph,
95+
const irep_idt &function);
7596

7697
#endif

0 commit comments

Comments
 (0)