PandA-2024.02
call_expr_fix.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  */
44 #include "call_expr_fix.hpp"
46 
48 #include "Parameter.hpp"
49 
51 #include "application_manager.hpp"
52 #include "function_behavior.hpp"
53 
55 #include <fstream>
56 
58 #include "tree_basic_block.hpp"
59 #include "tree_helper.hpp"
60 #include "tree_manager.hpp"
61 #include "tree_node.hpp"
62 #include "tree_reindex.hpp"
63 
65 #include "dbgPrintHelper.hpp"
66 #include "string_manipulation.hpp" // for GET_CLASS
67 
68 call_expr_fix::call_expr_fix(const application_managerRef _AppM, unsigned int _function_id,
69  const DesignFlowManagerConstRef _design_flow_manager, const ParameterConstRef _parameters)
70  : FunctionFrontendFlowStep(_AppM, _function_id, CALL_EXPR_FIX, _design_flow_manager, _parameters)
71 {
72  debug_level = _parameters->get_class_debug_level(GET_CLASS(*this), DEBUG_LEVEL_NONE);
73 }
74 
76 
79 {
81  switch(relationship_type)
82  {
84  {
85  break;
86  }
88  {
89  break;
90  }
92  {
93  break;
94  }
95  default:
96  {
98  }
99  }
100  return relationships;
101 }
102 
104 {
105  const tree_managerRef TM = AppM->get_tree_manager();
107  auto* fdcur = GetPointer<function_decl>(temp);
108  auto* sl = GetPointer<statement_list>(GET_NODE(fdcur->body));
109  bool bb_modified = false;
110 
112  for(const auto& block : sl->list_of_bloc)
113  {
114  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "-->analyzing BB" + std::to_string(block.first));
115  for(const auto& statement : block.second->CGetStmtList())
116  {
117  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "-->Analyzing node " + GET_NODE(statement)->ToString());
118  if(GET_NODE(statement)->get_kind() == gimple_call_K)
119  {
120  auto* ce = GetPointer<gimple_call>(GET_NODE(statement));
121  std::vector<tree_nodeRef>& args = ce->args;
122  auto* ae = GetPointer<addr_expr>(GET_NODE(ce->fn));
123  if(ae && args.size())
124  {
125  auto* fd = GetPointer<function_decl>(GET_NODE(ae->op));
126  if(!fd->undefined_flag)
127  {
128  tree_nodeRef functionType = GET_NODE(fd->type);
129  auto* fun_type = GetPointer<function_type>(functionType);
130  bool is_var_args_p = fun_type->varargs_flag;
131  if(!is_var_args_p)
132  {
134  tree_nodeRef paramList = fun_type->prms;
135  unsigned int count_param = 0;
136  while(paramList)
137  {
138  tree_nodeRef elem = GET_NODE(paramList);
139  auto* node = GetPointer<tree_list>(elem);
140  paramList = node->chan;
141  if(GET_NODE(node->valu)->get_kind() != void_type_K)
142  {
143  count_param++;
144  }
145  }
146  if(fd->list_of_args.size() == 0 && count_param == 0)
147  {
148  ce->args.clear();
149  bb_modified = true;
150  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---actuals cleared");
151  }
152  }
153  }
154  else if(tree_helper::print_function_name(TM, fd) == "__builtin_dwarf_cfa")
155  {
156  ce->args.clear();
157  bb_modified = true;
158  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---actuals cleared");
159  }
160  }
161  }
162  if(GET_NODE(statement)->get_kind() == gimple_assign_K)
163  {
164  auto* ga = GetPointer<gimple_assign>(GET_NODE(statement));
165  if(GET_NODE(ga->op1)->get_kind() == call_expr_K || GET_NODE(ga->op1)->get_kind() == aggr_init_expr_K)
166  {
167  auto* ce = GetPointer<call_expr>(GET_NODE(ga->op1));
168  std::vector<tree_nodeRef>& args = ce->args;
169  auto* ae = GetPointer<addr_expr>(GET_NODE(ce->fn));
170  if(ae && args.size())
171  {
172  auto* fd = GetPointer<function_decl>(GET_NODE(ae->op));
173  if(!fd->undefined_flag)
174  {
175  tree_nodeRef functionType = GET_NODE(fd->type);
176  auto* fun_type = GetPointer<function_type>(functionType);
177  bool is_var_args_p = fun_type->varargs_flag;
178  if(!is_var_args_p)
179  {
181  tree_nodeRef paramList = fun_type->prms;
182  unsigned int count_param = 0;
183  while(paramList)
184  {
185  tree_nodeRef elem = GET_NODE(paramList);
186  auto* node = GetPointer<tree_list>(elem);
187  paramList = node->chan;
188  if(GET_NODE(node->valu)->get_kind() != void_type_K)
189  {
190  count_param++;
191  }
192  }
193  if(fd->list_of_args.size() == 0 && count_param == 0)
194  {
195  ce->args.clear();
196  bb_modified = true;
197  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---actuals cleared");
198  }
199  }
200  }
201  else if(tree_helper::print_function_name(TM, fd) == "__builtin_dwarf_cfa")
202  {
203  ce->args.clear();
204  bb_modified = true;
205  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---actuals cleared");
206  }
207  }
208  }
209  }
211  }
213  }
214 
215  bb_modified ? function_behavior->UpdateBBVersion() : 0;
217 }
#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.
#define INDENT_DBG_MEX(dbgLevel, curDbgLevel, mex)
We are producing a debug version of the program, so the message is printed;.
File containing functions and utilities to support the printing of debug messagges.
Step successfully executed.
#define GET_CLASS(obj)
Macro returning the actual type of an object.
Definition of the class representing a generic C application.
RelationshipType
The relationship type.
Source must be executed to satisfy target.
static std::string print_function_name(const tree_managerConstRef &TM, const function_decl *fd)
Return the name of the function in a string.
Data structure describing a basic block at tree level.
DesignFlowStep_Status InternalExec() override
Updates the tree to have a more compliant IR.
Auxiliary methods for manipulating string.
std::string ToString(ActorGraphBackend_Type actor_graph_backend_type)
Header include.
const tree_nodeRef get_tree_node_const(unsigned int i) const
Return the reference to the i-th tree_node Constant version of get_tree_node.
#define THROW_UNREACHABLE(str_expr)
helper function used to specify that some points should never be reached
Definition: exceptions.hpp:292
~call_expr_fix() override
Destructor.
Analysis step which fix a non-void list of parameters to function with void as input parameter type...
Classes specification of the tree_node data structures.
DesignFlowStep_Status
The status of a step.
#define DEBUG_LEVEL_NONE
no debugging print is performed.
This struct specifies the block node.
Definition: tree_node.hpp:1820
This file collects some utility functions.
const unsigned int function_id
The index of the function to be analyzed.
const application_managerRef AppM
The application manager.
Class specification of the tree_reindex support class.
call_expr_fix(const application_managerRef AppM, unsigned int function_id, const DesignFlowManagerConstRef design_flow_manager, const ParameterConstRef parameters)
Constructor.
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.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
this class is used to manage the command-line or XML options.
int debug_level
The debug level.
Class specification of the manager of the tree structures extracted from the raw file.
A brief description of the C++ Header File.
const FunctionBehaviorRef function_behavior
The function behavior of the function to be analyzed.
int sl
Definition: adpcm.c:105

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