PandA-2024.02
|
This class manages the accesses to the CallGraph. More...
#include <call_graph_manager.hpp>
Public Member Functions | |
CallGraphManager (const FunctionExpanderConstRef function_expander, const bool allow_recursive_functions, const tree_managerConstRef tree_manager, const ParameterConstRef Param) | |
Constructor. More... | |
~CallGraphManager () | |
Destructor. More... | |
CallGraphConstRef | CGetAcyclicCallGraph () const |
Return an acyclic version of the call graph. More... | |
CallGraphConstRef | CGetCallGraph () const |
Return the call graph. More... | |
CallGraphConstRef | CGetCallSubGraph (const CustomUnorderedSet< vertex > &vertices) const |
Return a subset of the call graph. More... | |
CustomSet< unsigned int > | get_called_by (unsigned int index) const |
Returns the set of functions called by a function. More... | |
CustomSet< unsigned int > | get_called_by (const OpGraphConstRef cfg, const vertex &caller) const |
Returns the set of functions called by an operation vertex. More... | |
unsigned int | get_function (vertex node) const |
Given a vertex of the call graph, this returns the index of the corresponding function. More... | |
vertex | GetVertex (const unsigned int index) const |
Return the vertex given the function id. More... | |
void | SetRootFunctions (const CustomSet< unsigned int > &root_functions) |
Set the root functions. More... | |
CustomSet< unsigned int > | GetRootFunctions () const |
Returns the root functions (i.e., the functions that are not called by any other ones. More... | |
const CustomSet< unsigned int > & | GetReachedBodyFunctions () const |
Returns the source code functions called by the root functions. More... | |
CustomSet< unsigned int > | GetReachedFunctionsFrom (unsigned int from_f, bool with_body=true) const |
compute the list of reached function starting from a given function More... | |
unsigned int | GetRootFunction (unsigned int fid) const |
Get the parent root function. More... | |
CustomSet< unsigned int > | GetReachedLibraryFunctions () const |
Returns the library functions called by the root functions. More... | |
bool | IsVertex (unsigned int functionID) const |
return true in case the vertex has been already created More... | |
void | AddFunction (unsigned int new_function_id, const FunctionBehaviorRef fun_behavior) |
void | AddFunctionAndCallPoint (const application_managerRef AppM, unsigned int caller_id, unsigned int called_id, unsigned int call_id, enum FunctionEdgeInfo::CallType call_type) |
Creates a new called function and directly adds the call to the call graph. More... | |
void | RemoveCallPoint (const unsigned int caller_id, const unsigned int called_id, const unsigned int call_id) |
Remove a function call, like RemoveCallPoint with a different API. More... | |
void | RemoveCallPoint (EdgeDescriptor e, const unsigned int callid) |
Removes a call point. More... | |
void | ReplaceCallPoint (const EdgeDescriptor e, const unsigned int orig, const unsigned int repl) |
Replaces a call point. More... | |
bool | ExistsAddressedFunction () const |
Returns true is there is at least a reachable function that is called through a function pointer or its address is taken. More... | |
CustomSet< unsigned int > | GetAddressedFunctions () const |
Returns a set containing all the reachable addressed_functions. More... | |
Static Public Member Functions | |
static void | call_graph_computation_recursive (CustomUnorderedSet< unsigned int > &AV, const application_managerRef AM, unsigned int current, const tree_managerRef &TM, const tree_nodeRef &tn, unsigned int node_stmt, enum FunctionEdgeInfo::CallType call_type, int DL) |
Recursive analysis of the tree nodes looking for call expressions. More... | |
static void | expandCallGraphFromFunction (CustomUnorderedSet< unsigned int > &AV, const application_managerRef AM, unsigned int f_id, int DL) |
static void | addCallPointAndExpand (CustomUnorderedSet< unsigned int > &AV, const application_managerRef AM, unsigned int caller_id, unsigned int called_id, unsigned int call_id, enum FunctionEdgeInfo::CallType call_type, int DL) |
Data Fields | |
const FunctionExpanderConstRef | function_expander |
Functor used to check if the analysis should consider the body of a function. More... | |
Private Member Functions | |
void | AddCallPoint (unsigned int caller_id, unsigned int called_id, unsigned int call_id, enum FunctionEdgeInfo::CallType call_type) |
Creates a new call point. More... | |
void | AddFunctionAndCallPoint (unsigned int caller_id, unsigned int called_id, unsigned int call_id, const FunctionBehaviorRef called_function_behavior, enum FunctionEdgeInfo::CallType call_type) |
Creates a new called function and directly adds the call to the call graph. More... | |
bool | IsCallPoint (unsigned int caller_id, unsigned int called_id, unsigned int call_id, enum FunctionEdgeInfo::CallType call_type) const |
Returns true if the call point is present. More... | |
void | ComputeRootAndReachedFunctions () |
Compute the root and reached functions, maintaining the internal data structures coherent. More... | |
Private Attributes | |
const CallGraphsCollectionRef | call_graphs_collection |
const CallGraphRef | call_graph |
The view of call graph with all the edges. More... | |
const tree_managerConstRef | tree_manager |
The tree manager. More... | |
std::map< unsigned int, CustomSet< unsigned int > > | called_by |
put into relation function F_i and the list of functions called by F_i More... | |
std::map< unsigned int, vertex > | functionID_vertex_map |
put into relation function F_i and the vertex in the call graph representing it More... | |
const bool | allow_recursive_functions |
True if recursive calls are allowed. More... | |
CustomSet< unsigned int > | root_functions |
Root functions. More... | |
CustomSet< unsigned int > | reached_body_functions |
source code functions directly or indirectly called by the root functions More... | |
CustomSet< unsigned int > | reached_library_functions |
library functions directly or indirectly called by the root functions More... | |
CustomSet< unsigned int > | addressed_functions |
set of functions whose address is taken More... | |
const ParameterConstRef | Param |
set of input parameters More... | |
const int | debug_level |
the debug level More... | |
Friends | |
class | call_graph_computation |
This class manages the accesses to the CallGraph.
Definition at line 71 of file call_graph_manager.hpp.
CallGraphManager::CallGraphManager | ( | const FunctionExpanderConstRef | function_expander, |
const bool | allow_recursive_functions, | ||
const tree_managerConstRef | tree_manager, | ||
const ParameterConstRef | Param | ||
) |
Constructor.
The data structure is initialized.
function_expander | is the functor used to determine if a function has to be considered during construction of call graph |
allow_recursive_functions | specifies if recursive functions are allowed |
tree_manager | is the tree manager |
Param | is the set of input parameters |
Definition at line 153 of file call_graph_manager.cpp.
References ~CallGraphManager().
|
default |
|
private |
Creates a new call point.
caller_id | is the function id of the caller |
called_id | is the function id of the called function |
call_id | is the tree node index of the call statement |
call_type | is the type of call |
Definition at line 193 of file call_graph_manager.cpp.
References addressed_functions, FunctionEdgeInfo::call_any, call_graph, call_graphs_collection, called_by, CGetCallGraph(), tree_manager::CGetTreeNode(), ComputeRootAndReachedFunctions(), debug_level, DEBUG_LEVEL_VERY_PEDANTIC, FunctionEdgeInfo::direct_call, FEEDBACK_SELECTOR, FunctionEdgeInfo::function_address, GetVertex(), INDENT_DBG_MEX, FunctionEdgeInfo::indirect_call, IsCallPoint(), IsVertex(), tree_helper::print_function_name(), STD_SELECTOR, STR, THROW_ASSERT, THROW_UNREACHABLE, and graph::TopologicalSort().
Referenced by AddFunctionAndCallPoint(), and ReplaceCallPoint().
|
static |
Definition at line 702 of file call_graph_manager.cpp.
References expandCallGraphFromFunction().
Referenced by CallGraphBuiltinCall::ExtendCallGraph(), CallGraphBuiltinCall::lookForBuiltinCall(), bloc::manageCallGraph(), hls_div_cg_ext::recursive_examinate(), soft_float_cg_ext::RecursiveExaminate(), soft_float_cg_ext::replaceWithCall(), InterfaceInfer::setReadInterface(), and tree_manipulation::VersionFunctionCall().
void CallGraphManager::AddFunction | ( | unsigned int | new_function_id, |
const FunctionBehaviorRef | fun_behavior | ||
) |
new_function_id | is the index of the function to add |
fun_behavior | is the corresponding function behavior |
Definition at line 168 of file call_graph_manager.cpp.
References call_graph, call_graphs_collection, called_by, ComputeRootAndReachedFunctions(), debug_level, DEBUG_LEVEL_VERY_PEDANTIC, functionID_vertex_map, refcount< T >::get(), GET_NODE_INFO, INDENT_DBG_MEX, IsVertex(), STR, and THROW_ASSERT.
Referenced by AddFunctionAndCallPoint().
|
private |
Creates a new called function and directly adds the call to the call graph.
caller_id | is the function id of the caller |
called_id | is the function id of the called function |
call_id | is the tree node index of the call statement |
called_function_behavior | is the FunctionBehavior of the called function |
call_type | is the type of call |
Definition at line 331 of file call_graph_manager.cpp.
References AddCallPoint(), and AddFunction().
Referenced by AddFunctionAndCallPoint().
void CallGraphManager::AddFunctionAndCallPoint | ( | const application_managerRef | AppM, |
unsigned int | caller_id, | ||
unsigned int | called_id, | ||
unsigned int | call_id, | ||
enum FunctionEdgeInfo::CallType | call_type | ||
) |
Creates a new called function and directly adds the call to the call graph.
AppM | is the application manager |
caller_id | is the function id of the caller |
called_id | is the function id of the called function |
call_id | is the tree node index of the call statement |
call_type | is the type of call |
Definition at line 339 of file call_graph_manager.cpp.
References AddCallPoint(), AddFunctionAndCallPoint(), BUILTIN_WAIT_CALL, tree_manager::CGetTreeNode(), tree_manager::get_implementation_node(), IsVertex(), and tree_helper::print_function_name().
|
static |
Recursive analysis of the tree nodes looking for call expressions.
TM | is the tree manager. |
tn | is current tree node. |
node_stmt | is the analyzed tree node |
call_type | is the type of call to be added |
check for nested function
var decl performs an assignment when init is not null
Definition at line 714 of file call_graph_manager.cpp.
References test_panda::arg, CASE_BINARY_EXPRESSION, CASE_CPP_NODES, CASE_FAKE_NODES, CASE_PRAGMA_NODES, CASE_QUATERNARY_EXPRESSION, CASE_TYPE_NODES, CASE_UNARY_EXPRESSION, DEBUG_LEVEL_PEDANTIC, FunctionEdgeInfo::direct_call, expandCallGraphFromFunction(), tree_helper::find_obj_type_ref_function(), fun(), tree_manager::get_implementation_node(), GET_INDEX_NODE, tree_node::get_kind(), GET_NODE, tree_manager::get_tree_node_const(), INDENT_DBG_MEX, NESTED_FUNCTIONS_EC, STR, THROW_ASSERT, THROW_ERROR, THROW_ERROR_CODE, THROW_UNREACHABLE, and tree_node::ToString().
Referenced by expandCallGraphFromFunction().
CallGraphConstRef CallGraphManager::CGetAcyclicCallGraph | ( | ) | const |
Return an acyclic version of the call graph.
Definition at line 522 of file call_graph_manager.cpp.
References call_graphs_collection, and STD_SELECTOR.
CallGraphConstRef CallGraphManager::CGetCallGraph | ( | ) | const |
Return the call graph.
Definition at line 527 of file call_graph_manager.cpp.
References call_graph.
Referenced by AddCallPoint(), IsCallPoint(), and RemoveCallPoint().
CallGraphConstRef CallGraphManager::CGetCallSubGraph | ( | const CustomUnorderedSet< vertex > & | vertices | ) | const |
Return a subset of the call graph.
vertices | is the subset of vertices to be considered |
Definition at line 532 of file call_graph_manager.cpp.
References call_graphs_collection, FEEDBACK_SELECTOR, and STD_SELECTOR.
|
private |
Compute the root and reached functions, maintaining the internal data structures coherent.
Definition at line 569 of file call_graph_manager.cpp.
References allow_recursive_functions, call_graph, GetVertex(), IsVertex(), reached_body_functions, reached_library_functions, and root_functions.
Referenced by AddCallPoint(), AddFunction(), and RemoveCallPoint().
bool CallGraphManager::ExistsAddressedFunction | ( | ) | const |
Returns true is there is at least a reachable function that is called through a function pointer or its address is taken.
Definition at line 501 of file call_graph_manager.cpp.
References addressed_functions, and reached_body_functions.
|
static |
Definition at line 674 of file call_graph_manager.cpp.
References call_graph_computation_recursive(), DEBUG_LEVEL_PEDANTIC, fun(), FunctionEdgeInfo::function_address, GET_NODE, INDENT_DBG_MEX, tree_helper::name_function(), sl, and THROW_ERROR.
Referenced by addCallPointAndExpand(), call_graph_computation_recursive(), and call_graph_computation::Exec().
CustomSet< unsigned int > CallGraphManager::get_called_by | ( | unsigned int | index | ) | const |
Returns the set of functions called by a function.
index | is the index of the caller function |
Definition at line 554 of file call_graph_manager.cpp.
References called_by.
CustomSet< unsigned int > CallGraphManager::get_called_by | ( | const OpGraphConstRef | cfg, |
const vertex & | caller | ||
) | const |
Returns the set of functions called by an operation vertex.
cfg | is the pointer to the graph which the operation belongs to |
caller | is the caller vertex |
Definition at line 564 of file call_graph_manager.cpp.
References OpGraph::CGetOpNodeInfo().
unsigned int CallGraphManager::get_function | ( | vertex | node | ) | const |
Given a vertex of the call graph, this returns the index of the corresponding function.
node | is the vertex of the function |
Definition at line 549 of file call_graph_manager.cpp.
References call_graph.
Referenced by CalledFunctionsVisitor::back_edge().
CustomSet< unsigned int > CallGraphManager::GetAddressedFunctions | ( | ) | const |
Returns a set containing all the reachable addressed_functions.
Definition at line 513 of file call_graph_manager.cpp.
References addressed_functions, and reached_body_functions.
const CustomOrderedSet< unsigned int > & CallGraphManager::GetReachedBodyFunctions | ( | ) | const |
Returns the source code functions called by the root functions.
Definition at line 606 of file call_graph_manager.cpp.
References reached_body_functions.
CustomOrderedSet< unsigned int > CallGraphManager::GetReachedFunctionsFrom | ( | unsigned int | from_f, |
bool | with_body = true |
||
) | const |
compute the list of reached function starting from a given function
from_f | is the starting function |
with_body | consider only functions with body IR |
Definition at line 611 of file call_graph_manager.cpp.
References allow_recursive_functions, call_graph, GetVertex(), and root_functions.
CustomOrderedSet< unsigned int > CallGraphManager::GetReachedLibraryFunctions | ( | ) | const |
Returns the library functions called by the root functions.
Definition at line 669 of file call_graph_manager.cpp.
References reached_library_functions.
unsigned int CallGraphManager::GetRootFunction | ( | unsigned int | fid | ) | const |
Get the parent root function.
fid | Function id |
Definition at line 632 of file call_graph_manager.cpp.
References allow_recursive_functions, call_graph, GetVertex(), root_functions, and THROW_ASSERT.
CustomSet< unsigned int > CallGraphManager::GetRootFunctions | ( | ) | const |
Returns the root functions (i.e., the functions that are not called by any other ones.
Definition at line 599 of file call_graph_manager.cpp.
References call_graph, root_functions, and THROW_ASSERT.
vertex CallGraphManager::GetVertex | ( | const unsigned int | index | ) | const |
Return the vertex given the function id.
index | is the function index |
Definition at line 537 of file call_graph_manager.cpp.
References functionID_vertex_map, STR, and THROW_ASSERT.
Referenced by AddCallPoint(), ComputeRootAndReachedFunctions(), GetReachedFunctionsFrom(), GetRootFunction(), IsCallPoint(), and RemoveCallPoint().
|
private |
Returns true if the call point is present.
caller_id | is the function id of the caller |
called_id | is the function id of the called function |
call_id | is the tree node index of the call statement |
call_type | is the type of call |
Definition at line 269 of file call_graph_manager.cpp.
References FunctionEdgeInfo::call_any, call_graph, called_by, CGetCallGraph(), tree_manager::CGetTreeNode(), debug_level, DEBUG_LEVEL_VERY_PEDANTIC, FunctionEdgeInfo::direct_call, FunctionEdgeInfo::function_address, GetVertex(), INDENT_DBG_MEX, FunctionEdgeInfo::indirect_call, IsVertex(), tree_helper::print_function_name(), STR, THROW_ASSERT, and THROW_UNREACHABLE.
Referenced by AddCallPoint().
bool CallGraphManager::IsVertex | ( | unsigned int | functionID | ) | const |
return true in case the vertex has been already created
functionID | is the function identifier |
Definition at line 544 of file call_graph_manager.cpp.
References functionID_vertex_map.
Referenced by AddCallPoint(), AddFunction(), AddFunctionAndCallPoint(), ComputeRootAndReachedFunctions(), and IsCallPoint().
void CallGraphManager::RemoveCallPoint | ( | const unsigned int | caller_id, |
const unsigned int | called_id, | ||
const unsigned int | call_id | ||
) |
Remove a function call, like RemoveCallPoint with a different API.
caller_id | is the index of the calling function |
called_id | is the index of the called function |
call_id | is the index of the statement containing the call |
Definition at line 446 of file call_graph_manager.cpp.
References BUILTIN_WAIT_CALL, CGetCallGraph(), tree_manager::CGetTreeNode(), GetVertex(), tree_helper::print_function_name(), STR, and THROW_ASSERT.
Referenced by ReplaceCallPoint().
void CallGraphManager::RemoveCallPoint | ( | EdgeDescriptor | e, |
const unsigned int | callid | ||
) |
Removes a call point.
e | is the edge in the call graph |
call_id | is the call graph point to remove |
Definition at line 361 of file call_graph_manager.cpp.
References addressed_functions, BUILTIN_WAIT_CALL, call_graph, call_graphs_collection, called_by, tree_manager::CGetTreeNode(), ComputeRootAndReachedFunctions(), debug_level, DEBUG_LEVEL_VERY_PEDANTIC, INDENT_DBG_MEX, tree_helper::print_function_name(), STR, lenet_tvm::target, and THROW_ASSERT.
void CallGraphManager::ReplaceCallPoint | ( | const EdgeDescriptor | e, |
const unsigned int | orig, | ||
const unsigned int | repl | ||
) |
Replaces a call point.
e | is the edge in the call graph |
old_call_id | is the old call tree node id |
new_call_id | is the new call tree node id |
Definition at line 470 of file call_graph_manager.cpp.
References AddCallPoint(), call_graph, FunctionEdgeInfo::direct_call, FunctionEdgeInfo::function_address, FunctionEdgeInfo::indirect_call, RemoveCallPoint(), lenet_tvm::target, and THROW_ASSERT.
void CallGraphManager::SetRootFunctions | ( | const CustomSet< unsigned int > & | root_functions | ) |
Set the root functions.
root_functions | Set of root function ids |
Definition at line 594 of file call_graph_manager.cpp.
References root_functions.
|
friend |
Definition at line 74 of file call_graph_manager.hpp.
|
private |
set of functions whose address is taken
Definition at line 103 of file call_graph_manager.hpp.
Referenced by AddCallPoint(), ExistsAddressedFunction(), GetAddressedFunctions(), and RemoveCallPoint().
|
private |
True if recursive calls are allowed.
Definition at line 91 of file call_graph_manager.hpp.
Referenced by ComputeRootAndReachedFunctions(), GetReachedFunctionsFrom(), and GetRootFunction().
|
private |
The view of call graph with all the edges.
Definition at line 79 of file call_graph_manager.hpp.
Referenced by AddCallPoint(), AddFunction(), CGetCallGraph(), ComputeRootAndReachedFunctions(), get_function(), GetReachedFunctionsFrom(), GetRootFunction(), GetRootFunctions(), IsCallPoint(), RemoveCallPoint(), and ReplaceCallPoint().
|
private |
Definition at line 76 of file call_graph_manager.hpp.
Referenced by AddCallPoint(), AddFunction(), CGetAcyclicCallGraph(), CGetCallSubGraph(), and RemoveCallPoint().
put into relation function F_i and the list of functions called by F_i
Definition at line 85 of file call_graph_manager.hpp.
Referenced by AddCallPoint(), AddFunction(), get_called_by(), IsCallPoint(), and RemoveCallPoint().
|
private |
the debug level
Definition at line 109 of file call_graph_manager.hpp.
Referenced by AddCallPoint(), AddFunction(), IsCallPoint(), and RemoveCallPoint().
const FunctionExpanderConstRef CallGraphManager::function_expander |
Functor used to check if the analysis should consider the body of a function.
Definition at line 149 of file call_graph_manager.hpp.
put into relation function F_i and the vertex in the call graph representing it
Definition at line 88 of file call_graph_manager.hpp.
Referenced by AddFunction(), GetVertex(), and IsVertex().
|
private |
set of input parameters
Definition at line 106 of file call_graph_manager.hpp.
|
private |
source code functions directly or indirectly called by the root functions
Definition at line 97 of file call_graph_manager.hpp.
Referenced by ComputeRootAndReachedFunctions(), ExistsAddressedFunction(), GetAddressedFunctions(), and GetReachedBodyFunctions().
|
private |
library functions directly or indirectly called by the root functions
Definition at line 100 of file call_graph_manager.hpp.
Referenced by ComputeRootAndReachedFunctions(), and GetReachedLibraryFunctions().
|
private |
Root functions.
Definition at line 94 of file call_graph_manager.hpp.
Referenced by ComputeRootAndReachedFunctions(), GetReachedFunctionsFrom(), GetRootFunction(), GetRootFunctions(), and SetRootFunctions().
|
private |
The tree manager.
Definition at line 82 of file call_graph_manager.hpp.