PandA-2024.02
behavioral_helper.hpp
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  */
43 #ifndef BEHAVIORAL_HELPER_HPP
44 #define BEHAVIORAL_HELPER_HPP
45 
47 #include "config_HAVE_FROM_PRAGMA_BUILT.hpp"
48 
49 #include "custom_map.hpp"
50 #include "custom_set.hpp" // for set
51 #include "custom_set.hpp"
52 #include "graph.hpp"
53 #include "refcount.hpp"
54 #include <list> // for list
55 #include <string> // for string
56 #include <tuple>
57 #include <utility> // for pair
70 class TreeNodeConstSet;
72 
73 using tree_class = unsigned int;
74 
75 #define INTERNAL "internal_"
76 
78 {
79  protected:
82 
85 
88 
91 
93  static std::map<unsigned int, std::pair<std::string, int>> definitions;
94 
96  static std::map<std::string, unsigned int> used_name;
97 
99  static std::map<unsigned int, std::string> vars_symbol_table;
100 
102  static std::map<unsigned int, std::string> vars_renaming_table;
103 
105  unsigned int function_index;
106 
108  std::string function_name;
109 
111  bool body;
112 
114  bool opaque;
115 
117  std::map<unsigned int, unsigned int> initializations;
118 
122  bool has_bit_field(unsigned int variable) const;
123 
124  public:
132  BehavioralHelper(const application_managerRef AppM, unsigned int index, bool body,
134 
138  virtual ~BehavioralHelper();
139 
146  virtual std::tuple<std::string, unsigned int, unsigned int> get_definition(unsigned int index,
148  bool& is_system) const;
149 
157  std::string print_vertex(const OpGraphConstRef g, const vertex v, const var_pp_functorConstRef vppf,
158  const bool dot = false) const;
159 
165  virtual std::string PrintInit(const tree_nodeConstRef& var, const var_pp_functorConstRef vppf) const;
166 
172  virtual std::string print_attributes(unsigned int var, const var_pp_functorConstRef vppf, bool first = true) const;
173 
179  std::string PrintVariable(unsigned int var) const;
180 
185  void InvaildateVariableName(const unsigned int index);
186 
192  virtual std::string PrintConstant(const tree_nodeConstRef& var,
193  const var_pp_functorConstRef vppf = var_pp_functorConstRef()) const;
194 
206  virtual std::string print_type(unsigned int type, bool global = false, bool print_qualifiers = false,
207  bool print_storage = false, unsigned int var = 0,
209  const std::string& prefix = "", const std::string& tail = "") const;
210 
215  virtual std::string print_type_declaration(unsigned int type) const;
216 
222  virtual unsigned long long get_size(unsigned int var) const;
223 
227  std::string get_function_name() const;
228 
229  std::string GetMangledFunctionName() const;
230 
235  unsigned int get_function_index() const;
236 
242  unsigned int
244  GetFunctionReturnType(unsigned int function) const;
245 
249  virtual bool is_bool(unsigned int index) const;
250 
254  virtual bool is_natural(unsigned int index) const;
255 
259  virtual bool is_int(unsigned int index) const;
260 
264  virtual bool is_an_enum(unsigned int index) const;
265 
269  virtual bool is_unsigned(unsigned int index) const;
270 
274  virtual bool is_real(unsigned int index) const;
275 
279  virtual bool is_a_complex(unsigned int index) const;
280 
284  virtual bool is_a_struct(unsigned int variable) const;
285 
291  virtual bool is_an_union(unsigned int variable) const;
292 
296  virtual bool is_an_array(unsigned int variable) const;
297 
301  bool is_a_vector(unsigned int variable) const;
302 
306  virtual bool is_a_pointer(unsigned int variable) const;
307 
312  virtual bool is_an_indirect_ref(unsigned int variable) const;
313 
318  virtual bool is_an_array_ref(unsigned int variable) const;
319 
324  virtual bool is_a_component_ref(unsigned int variable) const;
325 
330  virtual bool is_an_addr_expr(unsigned int variable) const;
331 
336  virtual bool is_a_mem_ref(unsigned int variable) const;
337 
343  virtual bool is_static(unsigned int decl) const;
344 
350  virtual bool is_extern(unsigned int decl) const;
351 
357  virtual bool is_a_constant(unsigned int obj) const;
358 
362  virtual bool is_a_result_decl(unsigned int obj) const;
363 
369  virtual bool is_a_realpart_expr(unsigned int obj) const;
370 
376  virtual bool is_a_imagpart_expr(unsigned int obj) const;
377 
383  virtual bool is_operating_system_function(const unsigned int obj) const;
384 
389  virtual int unsigned start_with_a_label(const blocRef& block) const;
390 
395  virtual unsigned int end_with_a_cond_or_goto(const blocRef& block) const;
396 
401  virtual unsigned int get_indirect_ref_var(unsigned int obj) const;
402 
407  virtual unsigned int get_array_ref_array(unsigned int obj) const;
408 
413  virtual unsigned int get_array_ref_index(unsigned int obj) const;
414 
419  virtual unsigned int get_component_ref_record(unsigned int obj) const;
420 
425  virtual unsigned int get_component_ref_field(unsigned int obj) const;
426 
431  virtual unsigned int get_mem_ref_base(unsigned int obj) const;
432 
437  virtual unsigned int get_mem_ref_offset(unsigned int obj) const;
438 
444  virtual unsigned int get_operand_from_unary_expr(unsigned int obj) const;
445 
451  virtual unsigned int GetVarFromSsa(unsigned int index) const;
452 
457  virtual unsigned int get_intermediate_var(unsigned int obj) const;
458 
463  virtual unsigned int get_type(const unsigned int var) const;
464 
469  virtual unsigned int get_pointed_type(const unsigned int type) const;
470 
476  unsigned int GetElements(const unsigned int type) const;
477 
482  virtual TreeNodeConstSet GetParameterTypes() const;
483 
487  const std::list<unsigned int> get_parameters() const;
488 
492  std::vector<tree_nodeRef> GetParameters() const;
493 
497  bool has_implementation() const;
498 
503  virtual bool is_var_args() const;
504 
509  virtual bool is_va_start_call(unsigned int stm) const;
510 
519  virtual unsigned int GetInit(unsigned int var, CustomUnorderedSet<unsigned int>& list_of_variables) const;
520 
526  virtual unsigned int get_attributes(unsigned int var) const;
527 
532  virtual unsigned int is_named_pointer(const unsigned int index) const;
533 
539  unsigned int is_name_used(std::string var) const;
540 
545  void add_read_global_variable(unsigned int variable);
546 
551  void add_written_global_variable(unsigned int variable);
552 
557 
562 
568  void add_initialization(unsigned int var, unsigned int init);
569 
570  virtual std::string print_phinode_res(unsigned int phi_node_id, vertex v, const var_pp_functorConstRef vppf) const;
571 
575  void set_opaque();
576 
580  void set_not_opaque();
581 
586  bool get_opaque() const;
587 
591  virtual const std::string get_label_name(unsigned int label_expr_nid) const;
592 
597  virtual std::string print_forward_declaration(unsigned int type) const;
598 
602  virtual bool is_empty_return(unsigned int index) const;
603 
612  virtual std::string PrintNode(const tree_nodeConstRef& node, vertex v, const var_pp_functorConstRef vppf) const;
613 
614  virtual std::string PrintNode(unsigned int node_id, vertex v, const var_pp_functorConstRef vppf) const;
615 
627  std::string PrintVarDeclaration(unsigned int var, const var_pp_functorConstRef vppf,
628  bool init_has_to_be_printed) const;
629 
635  unsigned int GetUnqualified(const unsigned int index) const;
636 
642  static void rename_a_variable(unsigned int var, const std::string& new_name);
643 
647  static void clear_renaming_table();
648 
654  virtual void GetTypecast(const tree_nodeConstRef& tn, TreeNodeConstSet& types) const;
655 
659  bool IsDefaultSsaName(const unsigned int ssa_name_index) const;
660 
661 #if HAVE_FROM_PRAGMA_BUILT
662 
665  size_t GetOmpForDegree() const;
666 
670  bool IsOmpFunctionAtomic() const;
671 
675  bool IsOmpBodyLoop() const;
676 #endif
677 
678 #if HAVE_FROM_PRAGMA_BUILT
679 
682  bool IsOmpAtomic() const;
683 #endif
684 
688  bool function_has_to_be_printed(unsigned int f_id) const;
689 
695  std::string get_asm_string(const unsigned int node_index) const;
696 
701  bool CanBeSpeculated(const unsigned int node_index) const;
702 
707  bool CanBeMoved(const unsigned int node_index) const;
708 
714  bool IsStore(const unsigned int statement_index) const;
715 
721  bool IsLoad(const unsigned int statement_index) const;
722 
728  bool IsLut(const unsigned int statement_index) const;
729 };
730 
736 
737 #endif
virtual unsigned long long get_size(unsigned int var) const
Return the size in bit of a C object.
std::string PrintVarDeclaration(unsigned int var, const var_pp_functorConstRef vppf, bool init_has_to_be_printed) const
This function prints the declaration of a variable without the closing ";".
bool CanBeMoved(const unsigned int node_index) const
Return if an operation can be moved.
bool CanBeSpeculated(const unsigned int node_index) const
Return true if an operation can be speculated.
virtual bool is_a_complex(unsigned int index) const
Return true if index is a variable or a type of type complex.
This struct specifies the field bloc (basic block).
virtual std::string PrintNode(const tree_nodeConstRef &node, vertex v, const var_pp_functorConstRef vppf) const
Print the operations corresponding to the node.
virtual std::string print_attributes(unsigned int var, const var_pp_functorConstRef vppf, bool first=true) const
Print the attributes associated to a variable.
virtual unsigned int get_intermediate_var(unsigned int obj) const
Return the intermediate variable of an operation.
virtual bool is_an_array_ref(unsigned int variable) const
Return true if the index is an array ref.
unsigned int tree_class
static void clear_renaming_table()
remove all the entries from the renaming table
std::string GetMangledFunctionName() const
virtual bool is_a_mem_ref(unsigned int variable) const
Return true if the index is a mem_ref.
bool get_opaque() const
Return the opaque flag.
virtual unsigned int get_component_ref_record(unsigned int obj) const
Return the record variable of a component ref.
std::string get_function_name() const
Return the name of the function.
void add_initialization(unsigned int var, unsigned int init)
Add the initialization of a variables.
virtual unsigned int end_with_a_cond_or_goto(const blocRef &block) const
Return the nodeID of the last statement of a basic block in case that statement is a cond or a goto e...
BehavioralHelper(const application_managerRef AppM, unsigned int index, bool body, const ParameterConstRef parameters)
Constructor.
bool is_a_vector(unsigned int variable) const
Return true if index is a variable or a type of type vector.
bool IsLoad(const unsigned int statement_index) const
Return if an operation is a load.
This class manages the tree structures extracted from the raw file.
virtual std::string PrintInit(const tree_nodeConstRef &var, const var_pp_functorConstRef vppf) const
Print the initialization part.
std::vector< tree_nodeRef > GetParameters() const
Return the list of index of original parameters of the function.
Class specification of the graph structures.
virtual std::string print_phinode_res(unsigned int phi_node_id, vertex v, const var_pp_functorConstRef vppf) const
virtual bool is_var_args() const
Returns true if this function is of var args type.
static std::map< unsigned int, std::string > vars_renaming_table
Variable renaming table.
std::string function_name
Name of the function.
unsigned int get_function_index() const
Return the index of the function.
virtual bool is_empty_return(unsigned int index) const
return true in case index is a return expr with an empty operand.
virtual unsigned int get_mem_ref_offset(unsigned int obj) const
Return the offset of a mem ref.
void set_opaque()
Set opaque flag to true.
virtual std::string print_type(unsigned int type, bool global=false, bool print_qualifiers=false, bool print_storage=false, unsigned int var=0, const var_pp_functorConstRef vppf=var_pp_functorConstRef(), const std::string &prefix="", const std::string &tail="") const
Print a type and its variable in case var is not zero.
const application_managerRef AppM
The application manager.
virtual unsigned int get_operand_from_unary_expr(unsigned int obj) const
Return the index of the operand if index is addr_expr, a realpart_expr or a imagpart_expr.
virtual bool is_a_result_decl(unsigned int obj) const
Return true if index is a result_decl.
virtual bool is_an_array(unsigned int variable) const
Return true if index is a variable or a type of type array.
std::map< unsigned int, unsigned int > initializations
Structure which stores initializations.
virtual bool is_unsigned(unsigned int index) const
Return true if index is a variable or a type of type unsigned int.
redefinition of map to manage ordered/unordered structures
bool IsDefaultSsaName(const unsigned int ssa_name_index) const
Return true if node is the default ssa_name.
bool has_implementation() const
Return true if function has implementation.
virtual bool is_a_realpart_expr(unsigned int obj) const
Return true if index is a realpart_expr.
Abstract pure class for the tree structure.
Definition: tree_node.hpp:139
const tree_managerConstRef TM
The tree manager.
A set of const tree node.
Definition: tree_node.hpp:267
virtual std::tuple< std::string, unsigned int, unsigned int > get_definition(unsigned int index, bool &is_system) const
Returns where the type index is defined.
virtual std::string PrintConstant(const tree_nodeConstRef &var, const var_pp_functorConstRef vppf=var_pp_functorConstRef()) const
Print the constant associated with var.
virtual bool is_a_pointer(unsigned int variable) const
Return true if index is a variable or a type of type pointer.
virtual bool is_operating_system_function(const unsigned int obj) const
Return true if function is an operating system function.
unsigned int is_name_used(std::string var) const
Return if a variable with this name already exists.
bool body
Flag to check if behavioral_graph_manager contains the function implementation.
static std::map< unsigned int, std::pair< std::string, int > > definitions
Maps between unqualified type and definition of a corresponding qualified type.
virtual std::string print_forward_declaration(unsigned int type) const
Print the declaration of a non built-in type.
virtual unsigned int get_array_ref_array(unsigned int obj) const
Return the array variable of an array ref.
const std::list< unsigned int > get_parameters() const
Return the list of index of original parameters of the function.
CustomOrderedSet< unsigned int > get_read_global_variables() const
Get the global variables read by the correspondent function.
void InvaildateVariableName(const unsigned int index)
Invalidate cached variable name.
const ParameterConstRef Param
The set of input parameters.
virtual bool is_an_enum(unsigned int index) const
Return true if index is a variable or a type of type enum.
virtual unsigned int GetInit(unsigned int var, CustomUnorderedSet< unsigned int > &list_of_variables) const
return the initialization object associated with the variable.
bool has_bit_field(unsigned int variable) const
Return true if the variable is a field_decl and it has a bitfield.
unsigned int GetFunctionReturnType(unsigned int function) const
Return the index associated with the type of the return of the function.
#define index(x, y)
Definition: Keccak.c:74
virtual bool is_va_start_call(unsigned int stm) const
return true in case stm is a va_start call_expr
virtual unsigned int is_named_pointer(const unsigned int index) const
return the nodeid of the named pointer (pointer_type with a name different
virtual bool is_extern(unsigned int decl) const
check if a given index is a extern declaration
redefinition of set to manage ordered/unordered structures
virtual int unsigned start_with_a_label(const blocRef &block) const
Return the nodeID of the first statement of a basic block in case that statement is a label expressio...
static void rename_a_variable(unsigned int var, const std::string &new_name)
rename a variable
virtual bool is_int(unsigned int index) const
Return true if index is a variable or a type of type int.
virtual unsigned int get_mem_ref_base(unsigned int obj) const
Return the base of a mem ref.
boost::graph_traits< graph >::vertex_descriptor vertex
vertex definition.
Definition: graph.hpp:1303
Base class functor used by prettyPrintVertex to print variables.
virtual bool is_bool(unsigned int index) const
Return true if index is a variable or a type of type bool.
bool function_has_to_be_printed(unsigned int f_id) const
returns true if the function body has to be printed by the C backend
unsigned int GetUnqualified(const unsigned int index) const
Return the unqualified version of a type.
virtual bool is_static(unsigned int decl) const
check if a given index is a static declaration
virtual bool is_a_constant(unsigned int obj) const
Return true if the index is a constant object.
std::string PrintVariable(unsigned int var) const
Print the name of the variable associated to the index.
virtual bool is_an_addr_expr(unsigned int variable) const
Return true if the index is an addr_expr.
This struct specifies the block node.
Definition: tree_node.hpp:1820
void set_not_opaque()
Set opaque flag to false.
virtual bool is_natural(unsigned int index) const
Return true if index is a variable grater than or equal to zero.
virtual bool is_a_struct(unsigned int variable) const
Return true if index is a variable or a type of type struct.
virtual ~BehavioralHelper()
Destructor.
Template definition of refcount.
void add_written_global_variable(unsigned int variable)
Add a writing of a global variables.
virtual void GetTypecast(const tree_nodeConstRef &tn, TreeNodeConstSet &types) const
return the types used in type casting by tn
void init(int bucket[BUCKETSIZE])
Definition: sort.c:42
std::string print_vertex(const OpGraphConstRef g, const vertex v, const var_pp_functorConstRef vppf, const bool dot=false) const
Print the operations corrisponding to the vertex.
virtual bool is_real(unsigned int index) const
Return true if index is a variable or a type of type real.
bool IsStore(const unsigned int statement_index) const
Return if an operation is a store.
unsigned int GetElements(const unsigned int type) const
Given an array or a vector return the element type.
virtual unsigned int GetVarFromSsa(unsigned int index) const
Return the index of the variable base of a ssa var.
virtual bool is_a_imagpart_expr(unsigned int obj) const
Return true if index is a imagpart_expr.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
virtual bool is_an_union(unsigned int variable) const
Return true if index is a variable of a type of type union.
virtual unsigned int get_indirect_ref_var(unsigned int obj) const
Return the variable of an indirect ref.
virtual unsigned int get_type(const unsigned int var) const
Return the type of the variable.
void add_read_global_variable(unsigned int variable)
Add a read of a global variable.
bool opaque
Flag to check if a call to this function has to be treated as a TYPE_OPAQUE nodeID.
unsigned int function_index
Index of the function.
virtual unsigned int get_component_ref_field(unsigned int obj) const
Return the field index of a component ref.
virtual TreeNodeConstSet GetParameterTypes() const
Returns the types of the parameters.
virtual bool is_a_component_ref(unsigned int variable) const
Return true if the index is a component ref.
virtual bool is_an_indirect_ref(unsigned int variable) const
Return true if the index is an indirect ref.
static std::map< std::string, unsigned int > used_name
Set of variables name already used.
CONSTREF_FORWARD_DECL(OpGraph)
Class used to describe a particular graph with operations as nodes.
Definition: op_graph.hpp:783
virtual std::string print_type_declaration(unsigned int type) const
Print the declaration of a non built-in type.
virtual const std::string get_label_name(unsigned int label_expr_nid) const
return the label name associated with the label expression
static std::map< unsigned int, std::string > vars_symbol_table
The var symbol table.
refcount< const var_pp_functor > var_pp_functorConstRef
bool IsLut(const unsigned int statement_index) const
Return if an operation is a lut_expr.
CustomOrderedSet< unsigned int > get_written_global_variables() const
Get the global variables written by the correspondent function.
REF_FORWARD_DECL(application_manager)
virtual unsigned int get_array_ref_index(unsigned int obj) const
Return the index variable of an array ref.
std::string get_asm_string(const unsigned int node_index) const
return the string associated with the gimple_asm
int debug_level
the debug level
virtual unsigned int get_pointed_type(const unsigned int type) const
Return the pointed type of a pointer.
virtual unsigned int get_attributes(unsigned int var) const
return the attributes associated with the variable.

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