PandA-2024.02
call_graph_computation.cpp
Go to the documentation of this file.
1 /*
2  *
3  * _/_/_/ _/_/ _/ _/ _/_/_/ _/_/
4  * _/ _/ _/ _/ _/_/ _/ _/ _/ _/ _/
5  * _/_/_/ _/_/_/_/ _/ _/_/ _/ _/ _/_/_/_/
6  * _/ _/ _/ _/ _/ _/ _/ _/ _/
7  * _/ _/ _/ _/ _/ _/_/_/ _/ _/
8  *
9  * ***********************************************
10  * PandA Project
11  * URL: http://panda.dei.polimi.it
12  * Politecnico di Milano - DEIB
13  * System Architectures Group
14  * ***********************************************
15  * Copyright (C) 2004-2024 Politecnico di Milano
16  *
17  * This file is part of the PandA framework.
18  *
19  * The PandA framework is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation; either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program. If not, see <http://www.gnu.org/licenses/>.
31  *
32  */
46 
47 #include "Parameter.hpp"
48 #include "application_manager.hpp"
49 #include "behavioral_helper.hpp"
50 #include "call_graph.hpp"
51 #include "call_graph_manager.hpp"
52 #include "dbgPrintHelper.hpp"
53 #include "ext_tree_node.hpp"
54 #include "function_behavior.hpp"
55 #include "hls_manager.hpp"
56 #include "string_manipulation.hpp"
57 #include "tree_basic_block.hpp"
58 #include "tree_helper.hpp"
59 #include "tree_manager.hpp"
60 #include "tree_node.hpp"
61 #include "tree_reindex.hpp"
62 
64  const DesignFlowManagerConstRef _design_flow_manager)
65  : ApplicationFrontendFlowStep(_AppM, FUNCTION_ANALYSIS, _design_flow_manager, _parameters)
66 {
67  debug_level = parameters->get_class_debug_level(GET_CLASS(*this), DEBUG_LEVEL_NONE);
68 }
69 
71 
74 {
76  switch(relationship_type)
77  {
79  {
80  relationships.insert(std::make_pair(CREATE_TREE_MANAGER, WHOLE_APPLICATION));
81  break;
82  }
84  {
85 #if HAVE_TASTE
86  relationships.insert(std::make_pair(CREATE_ADDRESS_TRANSLATION, WHOLE_APPLICATION));
87 #endif
88  relationships.insert(std::make_pair(HDL_FUNCTION_DECL_FIX, WHOLE_APPLICATION));
89 #if HAVE_FROM_PRAGMA_BUILT
90  relationships.insert(std::make_pair(PRAGMA_ANALYSIS, WHOLE_APPLICATION));
91 #endif
92  break;
93  }
95  {
96  break;
97  }
98  default:
99  {
100  THROW_UNREACHABLE("");
101  }
102  }
103  return relationships;
104 }
105 
107 {
108  INDENT_DBG_MEX(DEBUG_LEVEL_PEDANTIC, debug_level, "-->Creating call graph data structure");
109  const auto HLSMgr = GetPointer<HLS_manager>(AppM);
110  const auto TM = AppM->get_tree_manager();
111  const auto CGM = AppM->GetCallGraphManager();
112  already_visited.clear();
113 
116  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Top functions passed by user");
117  auto function_symbols = parameters->getOption<std::vector<std::string>>(OPT_top_functions_names);
118  for(const auto& [symbol, arch] : *HLSMgr->module_arch)
119  {
120  THROW_ASSERT(arch, "Expected function architecture for function " + symbol);
121  const auto dataflow_attr = arch->attrs.find(FunctionArchitecture::func_dataflow);
122  if(dataflow_attr != arch->attrs.end() && dataflow_attr->second == "module")
123  {
124  function_symbols.push_back(symbol);
125  }
126  }
127  for(const auto& symbol : function_symbols)
128  {
129  const auto fnode = TM->GetFunction(symbol);
130  if(fnode)
131  {
133  "---Root function " + STR(GET_INDEX_CONST_NODE(fnode)) + " - " + symbol);
134  functions.insert(GET_INDEX_CONST_NODE(fnode));
135  }
136  else
137  {
138  THROW_ERROR("Function " + symbol + " not found in IR");
139  }
140  }
141  CGM->SetRootFunctions(functions);
142 
143  // iterate on functions and add them to the call graph
144  for(const auto f_id : functions)
145  {
146  const auto fu_name = tree_helper::name_function(TM, f_id);
148  "---Adding function " + STR(f_id) + " " + fu_name + " to call graph");
149  if(fu_name == "__start_pragma__" || fu_name == "__close_pragma__" || fu_name.find("__pragma__") == 0)
150  {
152  continue;
153  }
154  // avoid nested functions
155  const auto fun = TM->CGetTreeNode(f_id);
156  const auto fd = GetPointerS<const function_decl>(fun);
157  if(fd->scpe && GET_NODE(fd->scpe)->get_kind() == function_decl_K)
158  {
159  THROW_ERROR_CODE(NESTED_FUNCTIONS_EC, "Nested functions not yet supported " + STR(f_id));
160  }
161 
162  // add the function to the call graph if necessary
163  if(!CGM->IsVertex(f_id))
164  {
165  const auto has_body = TM->get_implementation_node(f_id) != 0;
166  const auto helper = BehavioralHelperRef(new BehavioralHelper(AppM, f_id, has_body, parameters));
167  const auto FB = FunctionBehaviorRef(new FunctionBehavior(AppM, helper, parameters));
168  CGM->AddFunction(f_id, FB);
171  "---Added function " + STR(f_id) + " " + fu_name + " to call graph");
172  }
173  else
174  {
176  "---Function " + STR(f_id) + " " + fu_name + " was already in call graph");
177  }
178  }
179 
180  if(debug_level >= DEBUG_LEVEL_PEDANTIC || parameters->getOption<bool>(OPT_print_dot))
181  {
182  CGM->CGetCallGraph()->WriteDot("call_graph.dot");
183  }
184  INDENT_DBG_MEX(DEBUG_LEVEL_PEDANTIC, debug_level, "<--Created call graph");
186 }
#define GET_NODE(t)
Macro used to hide implementation details when accessing a tree_node from another tree_node...
Definition: tree_node.hpp:343
#define DEBUG_LEVEL_VERY_PEDANTIC
extremely verbose debugging print is performed.
Data structure representing the entire HLS information.
#define INDENT_DBG_MEX(dbgLevel, curDbgLevel, mex)
We are producing a debug version of the program, so the message is printed;.
static std::string name_function(const tree_managerConstRef &tm, const unsigned int index)
Return the name of the function.
CustomUnorderedSet< unsigned int > already_visited
Already visited tree node (used to avoid infinite recursion)
Build call_graph data structure starting from the tree_manager.
File containing functions and utilities to support the printing of debug messagges.
#define DEBUG_LEVEL_PEDANTIC
very verbose debugging print is performed.
#define GET_CLASS(obj)
Macro returning the actual type of an object.
Definition of the class representing a generic C application.
refcount< BehavioralHelper > BehavioralHelperRef
RefCount type definition of the tree_to_graph class structure.
RelationshipType
The relationship type.
Source must be executed to satisfy target.
Data structure describing a basic block at tree level.
call_graph_computation(const ParameterConstRef _parameters, const application_managerRef AppM, const DesignFlowManagerConstRef design_flow_manager)
Constructor.
#define STR(s)
Macro which performs a lexical_cast to a string.
Auxiliary methods for manipulating string.
#define THROW_UNREACHABLE(str_expr)
helper function used to specify that some points should never be reached
Definition: exceptions.hpp:292
Classes specification of the tree_node data structures.
const ParameterConstRef parameters
Set of input parameters.
DesignFlowStep_Status
The status of a step.
Call graph hierarchy.
#define DEBUG_LEVEL_NONE
no debugging print is performed.
#define THROW_ERROR(str_expr)
helper function used to throw an error in a standard way
Definition: exceptions.hpp:263
This file collects some utility functions.
refcount< FunctionBehavior > FunctionBehaviorRef
DesignFlowStep_Status Exec() override
Computes the call graph data structure.
const application_managerRef AppM
The application manager.
Class specification of the tree_reindex support class.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
#define THROW_ERROR_CODE(code, str_expr)
helper function used to throw an error with a code error
Definition: exceptions.hpp:266
Classes specification of the tree_node data structures not present in the gcc.
this class is used to manage the command-line or XML options.
nested functions are not currently supported
Definition: exceptions.hpp:325
Wrapper to call graph.
int debug_level
The debug level.
int fun(float *A, float *invA, float *b, float *x, float *I)
#define GET_INDEX_CONST_NODE(t)
Definition: tree_node.hpp:363
const CustomUnorderedSet< std::pair< FrontendFlowStepType, FunctionRelationship > > ComputeFrontendRelationships(const DesignFlowStep::RelationshipType relationship_type) const override
Return the set of analyses in relationship with this design step.
static void expandCallGraphFromFunction(CustomUnorderedSet< unsigned int > &AV, const application_managerRef AM, unsigned int f_id, int DL)
Class specification of the manager of the tree structures extracted from the raw file.
A brief description of the C++ Header File.
~call_graph_computation() override
Destructor.
#define THROW_ASSERT(cond, str_expr)
helper function used to check an assert and if needed to throw an error in a standard way ...
Definition: exceptions.hpp:289

Generated on Mon Feb 12 2024 13:02:51 for PandA-2024.02 by doxygen 1.8.13