PandA-2024.02
tree_manager.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  */
46 #ifndef TREE_MANAGER_HPP
47 #define TREE_MANAGER_HPP
48 
49 #include "config_HAVE_UNORDERED.hpp"
50 
51 #include "custom_map.hpp"
52 #include "custom_set.hpp"
53 #include "hash_helper.hpp"
55 #include "panda_types.hpp"
56 #include "refcount.hpp"
57 
59 #include <deque>
60 #include <iosfwd>
61 #include <string> // for string
62 #include <utility> // for pair
63 
69 struct ssa_name;
70 struct function_decl;
71 enum kind : int;
78 
79 #define BUILTIN_SRCP "<built-in>:0:0"
80 
85 {
86  private:
89 
93 #if HAVE_UNORDERED
95 #else
97 #endif
98 
101  std::map<unsigned int, tree_nodeRef> function_decl_nodes;
102 
104  std::deque<tree_nodeRef> stack;
105 
108 
110  unsigned int n_pl;
111 
113  unsigned int added_goto;
114 
116  unsigned int removed_pointer_plus;
117 
120 
123 
126 
128  unsigned int last_node_id;
129 
132 
134 
137 
140 
142  unsigned int next_vers;
143 
145  unsigned int collapse_into_counter;
146 
157  bool check_for_decl(const tree_nodeRef& tn, const tree_managerRef& TM, std::string& symbol_name,
158  std::string& symbol_scope, unsigned int node_id,
159  const CustomUnorderedMap<unsigned int, std::string>& global_type_unql_symbol_table);
160 
164  bool check_for_type(const tree_nodeRef& tn, const tree_managerRef& TM, std::string& symbol_name,
165  std::string& symbol_scope,
166  const CustomUnorderedMapUnstable<std::string, unsigned int>& global_type_symbol_table,
167  unsigned int node_id);
168 
175  void erase_usage_info(const tree_nodeRef& tn, const tree_nodeRef& stmt);
176 
183  void insert_usage_info(const tree_nodeRef& tn, const tree_nodeRef& stmt);
184 
185  tree_nodeRef create_unique_const(const std::string& val, const tree_nodeConstRef& type);
186 
187  public:
198  void RecursiveReplaceTreeNode(tree_nodeRef& tn, const tree_nodeRef old_node, const tree_nodeRef& new_node,
199  const tree_nodeRef& stmt, bool definition); // NOLINT
200 
205  explicit tree_manager(const ParameterConstRef& Param);
206 
207  ~tree_manager();
208 
215  unsigned int get_implementation_node(unsigned int decl_node) const;
216 
217  // ************************+ handlers for tree_nodes structure **************************
218 
224  void AddTreeNode(const unsigned int i, const tree_nodeRef& curr);
225 
231  tree_nodeRef GetTreeReindex(const unsigned int i);
232 
238  const tree_nodeRef CGetTreeReindex(const unsigned int i) const;
239 
245  tree_nodeRef GetTreeNode(const unsigned int index) const;
246 
253  const tree_nodeRef get_tree_node_const(unsigned int i) const;
254  const tree_nodeConstRef CGetTreeNode(const unsigned int i) const;
255 
260  bool is_tree_node(unsigned int i) const;
261 
276  void create_tree_node(const unsigned int node_id, enum kind tree_node_type,
277  std::map<TreeVocabularyTokenTypes_TokenEnum, std::string>& tree_node_schema);
278 
284  unsigned int find(enum kind tree_node_type,
285  const std::map<TreeVocabularyTokenTypes_TokenEnum, std::string>& tree_node_schema);
286 
292  unsigned int new_tree_node_id(const unsigned int ask = 0);
293 
297  unsigned int get_next_available_tree_node_id() const;
298 
304  void add_function(unsigned int index, tree_nodeRef curr);
305 
310  unsigned long get_function_decl_node_n() const;
311 
317 
321  unsigned int find_sc_main_node() const;
322 
328  unsigned int function_index(const std::string& function_name) const;
330 
337  tree_nodeRef GetFunction(const std::string& function_name) const;
338 
345  unsigned int function_index_mngl(const std::string& function_name) const;
346 
352  void print(std::ostream& os) const;
353 
359  void PrintGimple(std::ostream& os, const bool use_uid) const;
360 
364  friend std::ostream& operator<<(std::ostream& os, const tree_manager& s)
365  {
366  s.print(os);
367  return os;
368  }
369 
373  friend std::ostream& operator<<(std::ostream& os, const tree_managerRef& s)
374  {
375  if(s)
376  {
377  s->print(os);
378  }
379  return os;
380  }
381 
389  void collapse_into(const unsigned int& funID, CustomUnorderedMapUnstable<unsigned int, unsigned int>& stmt_to_bloc,
390  const tree_nodeRef& tn, CustomUnorderedSet<unsigned int>& removed_nodes,
391  const application_managerRef AppM);
392 
394  void add_parallel_loop();
395 
397  unsigned int get_n_pl() const;
398 
403  void merge_tree_managers(const tree_managerRef& source_tree_manager);
404 
408  void add_goto();
409 
413  unsigned int get_added_goto() const;
414 
419 
423  unsigned int get_removed_pointer_plus() const;
424 
429 
433  unsigned int get_removable_pointer_plus() const;
434 
439 
443  unsigned int get_unremoved_pointer_plus() const;
444 
450  unsigned int find_identifier_nodeID(const std::string& str) const;
451 
457  void add_identifier_node(unsigned int nodeID, const std::string& str)
458  {
459  identifiers_unique_table[str] = nodeID;
460  }
461  void add_identifier_node(unsigned int nodeID, const bool& op);
462 
466  unsigned int get_next_vers();
467 
475  void ReplaceTreeNode(const tree_nodeRef& stmt, const tree_nodeRef& old_node, const tree_nodeRef& new_node);
476 
484 
491  tree_nodeRef CreateUniqueRealCst(long double value, const tree_nodeConstRef& type);
492 
497  bool is_CPP() const;
498 
504  bool is_top_function(const function_decl* fd) const;
505 
510  bool check_ssa_uses(unsigned int fun_id) const;
511 };
514 #endif
tree_nodeRef create_unique_const(const std::string &val, const tree_nodeConstRef &type)
void increment_unremoved_pointer_plus()
Increment the number of not removed pointer plus.
unsigned int next_vers
Next version number for ssa variables.
unsigned int get_removed_pointer_plus() const
Return the number of removed pointer plus.
void add_parallel_loop()
increment the number a parallel loop
const ParameterConstRef Param
Set of parameters.
void increment_removable_pointer_plus()
Increment the number of removable pointer plus.
const CustomUnorderedSet< unsigned int > GetAllFunctions() const
Returns all the functions in the tree_manager.
const tree_nodeRef CGetTreeReindex(const unsigned int i) const
Return a tree_reindex wrapping the i-th tree_node.
void ReplaceTreeNode(const tree_nodeRef &stmt, const tree_nodeRef &old_node, const tree_nodeRef &new_node)
Replace the occurrences of tree node old_node with new_node in statement identified by tn...
struct definition of the function_decl tree node.
Definition: tree_node.hpp:2759
unsigned int get_removable_pointer_plus() const
Return the number of not removed pointer plus.
This class manages the tree structures extracted from the raw file.
unsigned int last_node_id
last node_id used
friend std::ostream & operator<<(std::ostream &os, const tree_managerRef &s)
Friend definition of the << operator.
unsigned int get_next_available_tree_node_id() const
return the next available tree node id.
enum kind int REF_FORWARD_DECL(tree_manager)
void AddTreeNode(const unsigned int i, const tree_nodeRef &curr)
Add to the tree manager the current node.
unsigned int get_unremoved_pointer_plus() const
Return the number of not removed pointer plus.
CustomUnorderedSet< tree_nodeRef > already_visited
set of already examined addr_expr used to avoid circular recursion
absl::flat_hash_map< T, U, Hash, Eq, Alloc > CustomUnorderedMapUnstable
Definition: custom_map.hpp:156
unsigned int get_next_vers()
Return the next unused version number for ssa variables.
unsigned int added_goto
the number of added goto
redefinition of map to manage ordered/unordered structures
const tree_nodeConstRef CGetTreeNode(const unsigned int i) const
Abstract pure class for the tree structure.
Definition: tree_node.hpp:139
void RecursiveReplaceTreeNode(tree_nodeRef &tn, const tree_nodeRef old_node, const tree_nodeRef &new_node, const tree_nodeRef &stmt, bool definition)
Replace the occurrences of tree node old_node with new_node in statement identified by tn...
tree_manager(const ParameterConstRef &Param)
This is the constructor of the tree_manager which initializes the vector of functions.
unsigned int function_index_mngl(const std::string &function_name) const
Return the index of a function given its mangled name.
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.
unsigned int function_index(const std::string &function_name) const
Return the index of a function given its name.
bool is_top_function(const function_decl *fd) const
is_top_function checks if a function is one of the application top functions.
unsigned int find(enum kind tree_node_type, const std::map< TreeVocabularyTokenTypes_TokenEnum, std::string > &tree_node_schema)
if there exist return the node id of a tree node compatible with the tree_node_schema and of type tre...
absl::flat_hash_map< T, U, Hash, Eq, Alloc > CustomUnorderedMap
Definition: custom_map.hpp:148
CONSTREF_FORWARD_DECL(Parameter)
unsigned int new_tree_node_id(const unsigned int ask=0)
Return a new node id in the intermediate representation.
tree_nodeRef CreateUniqueRealCst(long double value, const tree_nodeConstRef &type)
memoization of integer constants
int debug_level
The debug level.
void add_function(unsigned int index, tree_nodeRef curr)
Add to the function_decl_nodes the current node.
CustomUnorderedMapUnstable< std::string, unsigned int > identifiers_unique_table
this table stores all identifier_nodes with their nodeID.
unsigned int n_pl
the number of parallel loops
bool check_ssa_uses(unsigned int fun_id) const
check_ssa_uses check if the uses of a ssa are correct
void erase_usage_info(const tree_nodeRef &tn, const tree_nodeRef &stmt)
Erase the information about variable usage (remove stmt from use_stmts attribute) in ssa variables re...
void create_tree_node(const unsigned int node_id, enum kind tree_node_type, std::map< TreeVocabularyTokenTypes_TokenEnum, std::string > &tree_node_schema)
Factory method.
void increment_removed_pointer_plus()
Increment the number of removed pointer plus.
tree_nodeRef CreateUniqueIntegerCst(integer_cst_t value, const tree_nodeConstRef &type)
memoization of integer constants
#define index(x, y)
Definition: Keccak.c:74
kind
redefinition of set to manage ordered/unordered structures
tree_nodeRef GetTreeReindex(const unsigned int i)
Return a tree_reindex wrapping the i-th tree_node.
unsigned long get_function_decl_node_n() const
Return the number of function_decl_node.
bool check_for_decl(const tree_nodeRef &tn, const tree_managerRef &TM, std::string &symbol_name, std::string &symbol_scope, unsigned int node_id, const CustomUnorderedMap< unsigned int, std::string > &global_type_unql_symbol_table)
check for decl_node and return true if not suitable for symbol table or otherwise its symbol_name and...
unsigned int get_implementation_node(unsigned int decl_node) const
Return the index of function_decl node that implements the declaration node.
void add_goto()
Increment the number of added gotos.
unsigned int unremoved_pointer_plus
the number of unremoved pointer_plus
void merge_tree_managers(const tree_managerRef &source_tree_manager)
merge two tree manager: this with TM_source
void collapse_into(const unsigned int &funID, CustomUnorderedMapUnstable< unsigned int, unsigned int > &stmt_to_bloc, const tree_nodeRef &tn, CustomUnorderedSet< unsigned int > &removed_nodes, const application_managerRef AppM)
Collapse operations chains into the examinated node.
std::map< unsigned int, tree_nodeRef > function_decl_nodes
Variable containing set of function_declaration with their index node.
friend std::ostream & operator<<(std::ostream &os, const tree_manager &s)
Friend definition of the << operator.
bool is_CPP() const
is_CPP return true in case we have at least one CPP source code
tree_nodeRef GetTreeNode(const unsigned int index) const
Return the index-th tree_node (modifiable version)
TreeVocabularyTokenTypes_TokenEnum
Template definition of refcount.
Definition: APInt.hpp:53
std::map< _Key, _Tp, _Compare, _Alloc > OrderedMapStd
Definition: custom_map.hpp:60
CustomUnorderedMap< ssa_name *, tree_nodeRef > uses_erase_temp
Map containing temporary information for ssa_name uses deletion.
unsigned int find_identifier_nodeID(const std::string &str) const
Return the nodeID of the identifier_node representing string str.
OrderedMapStd< unsigned int, tree_nodeRef > tree_nodes
Variable containing set of tree_nodes.
bool is_tree_node(unsigned int i) const
Return true if there exists a tree node associated with the given id, false otherwise.
std::unordered_map< T, U, Hash, Eq, Alloc > UnorderedMapStd
Autoheader include.
Definition: custom_map.hpp:56
This file collects some hash functors.
unsigned int get_n_pl() const
return the number of parallel loops
std::deque< tree_nodeRef > stack
list of examining statements during collapse_into recursion
char str[25]
Definition: fixedptc.c:8
unsigned int collapse_into_counter
Index of current call of collapse_into_counter.
void insert_usage_info(const tree_nodeRef &tn, const tree_nodeRef &stmt)
Insert the information about variable usage (insert stmt in use_stmts attribute) in ssa variables rec...
unsigned int get_added_goto() const
Return the number of added gotos.
This struct specifies the ssa_name node.
Definition: tree_node.hpp:4523
void print(std::ostream &os) const
Function that prints the class tree_manager.
CustomUnorderedMapUnstable< std::string, unsigned int > find_cache
cache for tree_manager::find
bool check_for_type(const tree_nodeRef &tn, const tree_managerRef &TM, std::string &symbol_name, std::string &symbol_scope, const CustomUnorderedMapUnstable< std::string, unsigned int > &global_type_symbol_table, unsigned int node_id)
check for type and return true if not suitable for symbol table or otherwise its symbol_name and symb...
void add_identifier_node(unsigned int nodeID, const std::string &str)
Add an identifier_node to the corresponding unique table.
tree_nodeRef GetFunction(const std::string &function_name) const
Return the index of a function given its name.
unsigned int find_sc_main_node() const
Determine the index node of "sc_main" function in tree_node vector.
struct definition of the declaration node structures.
Definition: tree_node.hpp:877
CustomUnorderedMap< std::pair< std::string, unsigned int >, tree_nodeRef > unique_cst_map
unsigned int removable_pointer_plus
the number of removable pointer_plus
unsigned int removed_pointer_plus
the number of removed pointer_plus
void PrintGimple(std::ostream &os, const bool use_uid) const
Function that prints the bodies of function in gimple format.

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