---
gcc/ipa-utils.c | 33 +++++++++++++++++++++++++++++++++
gcc/ipa-utils.h | 4 +++-
2 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/gcc/ipa-utils.c b/gcc/ipa-utils.c
index 23e7f714306..bd3e79bd2e2 100644
--- a/gcc/ipa-utils.c
+++ b/gcc/ipa-utils.c
@@ -781,3 +781,36 @@ recursive_call_p (tree func, tree dest)
return false;
return true;
}
+
+static bool
+path_exists_dfs (hash_set<const cgraph_node *> *visited,
+ const cgraph_node *current, const cgraph_node *target)
+{
+ if (current == target)
+ return true;
+
+ visited->add (current);
+
+ cgraph_edge *cs;
+ for (cs = current->callees; cs; cs = cs->next_callee)
+ {
+ cgraph_node *callee = cs->callee->function_symbol ();
+ if (visited->contains (callee))
+ continue;
+ if (!path_exists_dfs (visited, callee, target))
+ continue;
+
+ return true;
+ }
+ return false;
+}
+
+/* Determine if there's a path between two cgraph_nodes */
+bool
+path_exists (const cgraph_node *from, const cgraph_node *to)
+{
+ hash_set<const cgraph_node *> visited;
+ bool found_path = path_exists_dfs (&visited, from, to);
+ visited.empty ();
+ return found_path;
+}
diff --git a/gcc/ipa-utils.h b/gcc/ipa-utils.h
index 98edc383461..1706deaee0a 100644
--- a/gcc/ipa-utils.h
+++ b/gcc/ipa-utils.h
@@ -263,4 +263,6 @@ get_odr_name_for_type (tree type)
return IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (type_name));
}
-#endif /* GCC_IPA_UTILS_H */
+extern bool
+path_exists (const cgraph_node *from, const cgraph_node *to);
+#endif /* GCC_IPA_UTILS_H */
--
2.18.1