PandA-2024.02
function_behavior.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  */
47 #ifndef FUNCTION_BEHAVIOR_HPP
48 #define FUNCTION_BEHAVIOR_HPP
49 
50 #include "config_HAVE_ASSERTS.hpp"
51 #include "config_HAVE_HOST_PROFILING_BUILT.hpp"
52 
53 #include "custom_map.hpp"
54 #include "custom_set.hpp"
55 #include "graph.hpp"
56 #include "refcount.hpp"
57 
58 #include <deque> // for deque
59 #include <functional> // for binary_function
60 #include <iosfwd> // for ostream, size_t
61 #include <typeindex> // for hash
62 
75 REF_FORWARD_DECL(EpdGraphsCollection);
76 REF_FORWARD_DECL(EpdGraph);
77 REF_FORWARD_DECL(extended_pdg_constructor);
79 REF_FORWARD_DECL(ParallelRegionsGraph);
80 REF_FORWARD_DECL(ParallelRegionsGraphConstructor);
86 class OpVertexSet;
87 REF_FORWARD_DECL(ParallelRegionsGraphsCollection);
89 #if HAVE_HOST_PROFILING_BUILT
92 #endif
95 
96 template <typename Graph>
97 class dominance;
98 class ParallelRegionsGraphsCollection;
99 class sequence_info;
100 class xml_element;
102 enum class MemoryAllocation_Policy;
103 using tree_class = unsigned int;
105 
108 {
109  unsigned int node_id;
110 
111  unsigned int base_address;
112 
113  unsigned int offset;
114 
115  memory_access(unsigned int _node_id, unsigned int _base_address, unsigned int _offset = 0);
116 };
118 
121 {
122  UNKNOWN = 0,
123  ADDRESS,
124  USE,
125  DEFINITION,
126  OVER,
127  ARG
128 };
129 
132 {
133  UNKNOWN = 0,
134  MEMORY,
135  SCALAR,
136  VIRTUAL
137 };
138 
139 #if NO_ABSEIL_HASH
140 
144 namespace std
145 {
146  template <>
147  struct hash<FunctionBehavior_VariableAccessType> : public unary_function<FunctionBehavior_VariableAccessType, size_t>
148  {
149  size_t operator()(FunctionBehavior_VariableAccessType variable_access_type) const
150  {
151  hash<int> hasher;
152  return hasher(static_cast<int>(variable_access_type));
153  }
154  };
155 } // namespace std
156 
160 namespace std
161 {
162  template <>
163  struct hash<FunctionBehavior_VariableType> : public unary_function<FunctionBehavior_VariableType, size_t>
164  {
165  size_t operator()(FunctionBehavior_VariableType variable_access_type) const
166  {
167  hash<int> hasher;
168  return hasher(static_cast<int>(variable_access_type));
169  }
170  };
171 } // namespace std
172 
173 #endif
174 
178 {
179  private:
184  friend class BasicBlocksProfiling;
185  friend class BBCdgComputation;
186  friend class OpCdgComputation;
187  friend class hpp_profiling;
188  friend class loops_computation;
189  friend class instr_sequences_detection;
190  friend struct loop_regions_computation;
191  friend class LoopsProfiling;
192  friend class probability_path;
193  friend class HostProfiling;
194  friend class read_profiling_data;
195  friend class tp_profiling;
196  friend class BBOrderComputation;
197  friend class OpOrderComputation;
200 
203 
206 
209 
211  const BBGraphRef bb;
212 
216 
219 
221  const BBGraphRef dj;
222 
224  const BBGraphRef dt;
225 
228 
231 
234 
237 
240 
243 
246 
249 
252 
255 
258 
261 
264 
267 
270 
273 
276 
279 
280 #ifndef NDEBUG
281  const OpGraphRef flsaoddg;
283 #endif
284 
287 
290 
293 
296 
299 
301  const OpGraphRef sg;
302 
305 
306 #if HAVE_HOST_PROFILING_BUILT
307  const ProfilingInformationRef profiling_information;
309 #endif
310 
313  std::map<vertex, unsigned int> map_levels;
314 
317  std::map<vertex, unsigned int> bb_map_levels;
318 
321  std::deque<vertex> deque_levels;
322 
325  std::deque<vertex> bb_deque_levels;
326 
328  LoopsRef loops;
329 
332 
335 
338 
342 
346 
349 
352 
354 
356  unsigned int bb_version;
357 
359  unsigned int bitvalue_version;
360 
363 
366 
369 
372 
375 
378 
380  unsigned int _channels_number;
381 
384 
386 
387  public:
395  const ParameterConstRef parameters);
396  FunctionBehavior(const FunctionBehavior&) = delete;
397 
401  ~FunctionBehavior();
402 
407  {
408  CFG,
411  CDG,
413  DFG,
415  ADG,
417  ODG,
419  FLG,
420  SDG,
425 #ifndef NDEBUG
427 #endif
431  SG,
432  AGG_VIRTUALG
433  };
434 
439  {
440  BB,
441  FBB,
442  EBB,
447  PPG,
448  DJ
449  };
450 
453 
456 
458  const operations_graph_constructorRef ogc;
459 
461  const BasicBlocksGraphConstructorRef bbgc;
462 
464  const level_constructorRef lm;
465 
467  const level_constructorRef bb_lm;
468 
471 
474 
476  std::map<unsigned int, memory_accessRef> memory_info;
477 
480 
484  BehavioralHelperRef GetBehavioralHelper();
485 
489  const BehavioralHelperConstRef CGetBehavioralHelper() const;
490 
494  CustomOrderedSet<unsigned int> get_local_variables(const application_managerConstRef AppM) const;
495 
499  const std::deque<vertex>& get_levels() const;
500 
504  const std::deque<vertex>& get_bb_levels() const;
505 
509  const std::map<vertex, unsigned int>& get_map_levels() const;
510 
514  const std::map<vertex, unsigned int>& get_bb_map_levels() const;
515 
522 
528  const OpGraphConstRef CGetOpGraph(FunctionBehavior::graph_type gt) const;
529 
536  const OpGraphConstRef CGetOpGraph(FunctionBehavior::graph_type gt, const OpVertexSet& statements) const;
537 
544 
551 
555  void print(std::ostream& os) const;
556 
562  void set_epp(EdgeDescriptor e, unsigned long long value);
563 
568  friend std::ostream& operator<<(std::ostream& os, const FunctionBehavior& s)
569  {
570  s.print(os);
571  return os;
572  }
573 
578  friend std::ostream& operator<<(std::ostream& os, const FunctionBehaviorRef& s)
579  {
580  if(s)
581  {
582  s->print(os);
583  }
584  return os;
585  }
586 
590  const LoopsConstRef CGetLoops() const;
591 
595  const LoopsRef GetLoops() const;
596 
597 #if HAVE_HOST_PROFILING_BUILT
598 
602  const ProfilingInformationConstRef CGetProfilingInformation() const;
603 #endif
604 
608  void add_parm_decl_copied(unsigned int node_id);
609 
613  void add_parm_decl_loaded(unsigned int node_id);
614 
618  void add_parm_decl_stored(unsigned int node_id);
619 
623  void add_function_mem(unsigned int node_id);
624 
629  void add_dynamic_address(unsigned int node_id);
630 
634  void clean_dynamic_address();
635 
639  bool is_variable_mem(unsigned int node_id) const;
640 
644  const CustomOrderedSet<unsigned int>& get_function_mem() const;
645 
647  void clean_function_mem();
648 
652  const CustomOrderedSet<unsigned int>& get_dynamic_address() const;
653 
657  const CustomOrderedSet<unsigned int>& get_parm_decl_copied() const;
658 
662  void clean_parm_decl_copied();
663 
667  const CustomOrderedSet<unsigned int>& get_parm_decl_loaded() const;
668 
672  void clean_parm_decl_loaded();
673 
677  const CustomOrderedSet<unsigned int>& get_parm_decl_stored() const;
678 
682  void clean_parm_decl_stored();
683 
687  inline void set_dereference_unknown_addr(bool f)
688  {
689  dereference_unknown_address = f;
690  }
691 
695  inline bool get_dereference_unknown_addr() const
696  {
697  return dereference_unknown_address;
698  }
699 
703  inline void set_unaligned_accesses(bool f)
704  {
705  unaligned_accesses = f;
706  }
707 
711  inline bool get_unaligned_accesses() const
712  {
713  return unaligned_accesses;
714  }
715 
720  inline void set_has_globals(bool f)
721  {
722  has_globals = f;
723  }
724 
729  inline bool get_has_globals() const
730  {
731  return has_globals;
732  }
733 
739  {
740  has_undefined_function_receiveing_pointers = f;
741  }
742 
748  {
749  return has_undefined_function_receiveing_pointers;
750  }
751 
755  void add_state_variable(unsigned int node_id)
756  {
757  state_variables.insert(node_id);
758  }
759 
764  bool is_a_state_variable(unsigned int node_id) const
765  {
766  return state_variables.count(node_id);
767  }
768 
773  {
774  state_variables.clear();
775  }
776 
782  {
783  return state_variables;
784  }
785 
790  void set_packed_vars(bool packed)
791  {
792  packed_vars = packed_vars || packed;
793  }
794 
798  bool has_packed_vars() const
799  {
800  return packed_vars;
801  }
802 
803  bool is_pipeline_enabled() const
804  {
805  return pipeline_enabled;
806  }
807 
808  bool is_simple_pipeline() const
809  {
810  if(simple_pipeline)
811  {
812  THROW_ASSERT(pipeline_enabled, "Simple pipeline is true but pipeline is not enabled");
813  }
814  return simple_pipeline;
815  }
816 
818  {
819  THROW_ASSERT(pipeline_enabled && !simple_pipeline,
820  "Should not request initiation time when pipeline is not enabled or simple pipeline is requested");
821  return initiation_time;
822  }
823 
830  bool CheckReachability(const vertex first_operation, const vertex second_operation) const;
831 
839  bool CheckBBReachability(const vertex first_basic_block, const vertex second_basic_block) const;
840 
847  bool CheckFeedbackReachability(const vertex first_operation, const vertex second_operation) const;
848 
855  bool CheckBBFeedbackReachability(const vertex first_basic_block, const vertex second_basic_block) const;
856 
861  unsigned int GetBBVersion() const;
862 
867  unsigned int UpdateBBVersion();
868 
873  unsigned int GetBitValueVersion() const;
874 
879  unsigned int UpdateBitValueVersion();
880 
881  unsigned int GetChannelsNumber() const;
882 
883  void SetChannelsNumber(unsigned int val);
884 
885  MemoryAllocation_ChannelsType GetChannelsType() const;
886 
887  void SetChannelsType(MemoryAllocation_ChannelsType val);
888 
889  MemoryAllocation_Policy GetMemoryAllocationPolicy() const;
890 
891  void SetMemoryAllocationPolicy(MemoryAllocation_Policy val);
892 };
893 
896 
900 class op_vertex_order_by_map : std::binary_function<vertex, vertex, bool>
901 {
902  private:
904  const std::map<vertex, unsigned int>& ref;
905 
907 #if HAVE_ASSERTS
908  const graph* g;
909 #endif
910 
911  public:
917  op_vertex_order_by_map(const std::map<vertex, unsigned int>& ref_, const graph*
918 #if HAVE_ASSERTS
919  g_)
920  : ref(ref_), g(g_)
921 #else
922  )
923  : ref(ref_)
924 #endif
925  {
926  }
927 
934  bool operator()(const vertex x, const vertex y) const;
935 };
936 
937 #endif
const OpGraphRef flg
The flow edge operation graph.
CONSTREF_FORWARD_DECL(application_manager)
System dependence graph.
const level_constructorRef lm
reference to the level constructor
const BBGraphRef dj
The dj graph (used for loop computation)
unsigned int offset
const BBGraphsCollectionRef bb_graphs_collection
Global graph storing CFG, dominators and post-dominators. The nodes of this graph are basic blocks...
Dominator o post-dominator data structure.
Definition: Dominance.hpp:627
CustomOrderedSet< unsigned int > state_variables
set of global variables
Basic block control flow graph.
Anti dependence + data dependence + output dependence + flow graph with feedback. ...
unsigned int tree_class
bool get_dereference_unknown_addr() const
Return true if the function has dereference of unknown address.
bool has_undefined_function_receiveing_pointers
function calls undefined function passing pointers
Superclass include.
const operations_graph_constructorRef ogc
reference to the operations graph constructor
class providing methods to manage an operations graph.
unsigned int node_id
const OpGraphRef cdg
The control dependence graph.
const OpGraphRef odg
The output-dependencies flow graph.
Anti-dependence graph with feedback.
void set_unaligned_accesses(bool f)
Set if LOADs or STOREs perform unaligned accesses.
const OpGraphRef saodg
The system dependence, antidependence and output dependence graph.
Class specification of the graph structures.
unsigned int bb_version
The version of basic block intermediate representation.
void clean_state_variable()
clean_state_variable initialize the state variable data structure
const OpGraphRef fodg
The output-dependencies flow graph with feedback.
MemoryAllocation_ChannelsType
The number of channels.
const OpGraphRef fdfg
The data flow graph with feedback.
Definition of the profiling information class.
void set_packed_vars(bool packed)
update the the packed variables status
FunctionBehavior_VariableType
The possible type of a variable.
bool get_has_undefined_function_receiving_pointers() const
helper for has_undefined_function_receiveing_pointers variables property
Definition of hash function for EdgeDescriptor.
Definition: graph.hpp:1321
CustomOrderedSet< unsigned int > dynamic_address
store memory objects which can be indirectly addressed through a dynamic address computation ...
const std::map< vertex, unsigned int > & ref
Topological sorted vertices.
MemoryAllocation_Policy _allocation_policy
const BehavioralHelperRef helper
Behavioral helper associated with this behavioral_graph_manager.
Basic block post-dominator tree.
const OpGraphRef fcfg
The control flow graph with feedback.
const OpGraphRef fsdg
The system dependence graph with feedback.
void set_has_undefined_function_receiveing_pointers(bool f)
set if there are or not undefined functions called and which has pointers passed
redefinition of map to manage ordered/unordered structures
dominance< BBGraph > * post_dominators
This class stores post-dominator information.
A set of operation vertices.
Definition: op_graph.hpp:654
Abstract pure class for the tree structure.
Definition: tree_node.hpp:139
friend std::ostream & operator<<(std::ostream &os, const FunctionBehaviorRef &s)
Friend definition of the << operator.
const BBGraphRef bb
The basic block CFG.
System dependence + anti-dependence + output dependence graph + flow graph + debug graph...
const BBGraphRef dt
The dominator tree of the CFG on basic blocks.
The key comparison function for vertices set based on levels.
const OpGraphRef adg
The anti-dependencies graph.
const OpGraphRef sdg
The system dependence graph.
std::deque< vertex > bb_deque_levels
list of operations vertices sorted by topological order in control flow graph; in the sorting then pa...
Superclass include.
Class to perform profiling.
const BBGraphRef cdg_bb
The control dependence graph among basic blocks.
graph_type
Declaration of enum representing the type of graph.
System dependence graph with feedback.
CustomOrderedSet< unsigned int > mem_nodeID
this set represents the memory variables accessed by the function
REF_FORWARD_DECL(FunctionBehavior)
System dependence + anti-dependence graph + output dependence graph with feedback.
Output dependence graph.
Class used to describe a particular graph with basic blocks as nodes.
std::map< unsigned int, memory_accessRef > memory_info
map between node id and the corresponding memory allocation
Superclass include.
const level_constructorRef bb_lm
reference to the level constructor
Control dependence graph.
const OpGraphRef flaoddg
The anti-dependence + data dependence + output dependence + flow graph.
bool is_simple_pipeline() const
const OpGraphRef sg
The speculation graph.
const OpGraphRef fflaoddg
The anti-dependence + data dependence + output dependence + flow graph with freedback.
bool get_unaligned_accesses() const
Return true if a LOADs or STOREs perform unaligned accesses.
Control flow graph.
void print(int x)
const OpGraphRef cfg
The control flow graph.
const BBGraphRef extended_bb
The basic block Control Flow Graph extended with edges that impose that basic block inside a loop are...
const OpGraphRef dfg
The data flow graph.
Basic block dominator tree.
CustomUnorderedMapStable< vertex, CustomUnorderedSet< vertex > > feedback_bb_reachability
Reachability between basic blocks based on control flow graph with feedback.
Basic block control flow graph with feedback.
Extended control flow graph.
Control dependence graph with feedback.
void add_state_variable(unsigned int node_id)
Add a state variable: static, global or volatile variable.
redefinition of set to manage ordered/unordered structures
void print(std::ostream &os) const
Function that prints the class behavioral_manager.
boost::graph_traits< graph >::vertex_descriptor vertex
vertex definition.
Definition: graph.hpp:1303
memory_access(unsigned int _node_id, unsigned int _base_address, unsigned int _offset=0)
const OpGraphRef flsaodg
The system dependence, antidependence, output dependence and flow graph.
General class used to describe a graph in PandA.
Definition: graph.hpp:771
FunctionBehavior_VariableAccessType
The access type to a variable.
const OpGraphRef agg_virtualg
Anti + Data flow graph on aggregates.
Support basic block for path profiling.
const OpGraphRef extended_cfg
The extended control flow graph.
Basic block control dependence graph.
CustomOrderedSet< unsigned int > parm_decl_copied
this set represents the parameters that have to be copied from the caller
const OpGraphRef fsaodg
The system dependence, antidependence and output dependence graph with feedback.
bool packed_vars
True when there access to packed data.
int initiation_time
used only for stallable pipelines
Superclass include.
class providing methods to manage a basic blocks graph.
MemoryAllocation_ChannelsType _channels_type
Function scope channels type.
std::deque< vertex > deque_levels
list of operations vertices sorted by topological order in control flow graph; in the sorting then pa...
Output dependence graph with feedback.
Template definition of refcount.
dominance< BBGraph > * dominators
This class stores dominator information.
std::map< vertex, unsigned int > map_levels
Map operation vertex to position in topological order in control flow graph; in the sorting then part...
void set_has_globals(bool f)
set if there are or not externally visible global variables
bb_graph_type
Declaration of enum representing the type of bb_graph.
Definition: loops.hpp:90
const BBGraphRef fbb
The basic block CFG with feedback.
CustomUnorderedMapStable< vertex, CustomUnorderedSet< vertex > > bb_reachability
Mutual exclusion between basic blocks (based on control flow graph with flow edges) ...
int get_initiation_time() const
unsigned int base_address
const application_managerRef AppM
The application manager.
Speculation graph.
Data flow graph with feedback.
std::map< vertex, unsigned int > bb_map_levels
Map basic block vertex to position in topological order in control flow graph; in the sorting then pa...
const OpGraphRef fadg
The anti-dependencies graph with feedback.
CustomOrderedSet< unsigned int > parm_decl_loaded
this set represents the actual parameters that has to be loaded into the formal parameter from the ac...
const ParameterConstRef parameters
The set of input parameters.
bool get_has_globals() const
helper for global variables property
unsigned int _channels_number
Function scope channels number.
Anti-dependence + data dependence + output dependence + flow graph.
const BBGraphRef ppg
The support basic block graph for path profiling.
LoopsRef loops
Loops of the function.
bool pipeline_enabled
true when pipelining is enabled for the function
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
unsigned int bitvalue_version
Version of the bitvalue information.
void set_dereference_unknown_addr(bool f)
Set the use of dereference of unknown address.
System dependence + anti-dependence + output dependence graph + flow graph.
friend std::ostream & operator<<(std::ostream &os, const FunctionBehavior &s)
Friend definition of the << operator.
Class to perform profiling.
bool simple_pipeline
true when the requested pipeline does not include unbounded functions
const OpGraphRef fcdg
The control dependence graph with feedback.
const OpGraphsCollectionRef op_graphs_collection
Global graph storing CFG, DFG, FCFG, FDFG, SDG, FSDG, CDG. The nodes of this graph are operations...
Control flow graph with feedback.
bool dereference_unknown_address
the function dereference a pointer initialized with constant address.
x
Return the smallest n such that 2^n >= _x.
absl::node_hash_map< T, U, Hash, Eq, Alloc > CustomUnorderedMapStable
Definition: custom_map.hpp:152
loops computation analysis step
const CustomOrderedSet< unsigned int > & get_state_variables()
get_state_variables
Class used to describe a particular graph with operations as nodes.
Definition: op_graph.hpp:783
Struct representing memory information.
op_vertex_order_by_map(const std::map< vertex, unsigned int > &ref_, const graph *)
Graph.
const BBGraphRef pdt
The post-dominator tree of the CFG on basic blocks.
const BasicBlocksGraphConstructorRef bbgc
reference to the basic block graph constructor
System dependence + anti-dependence graph + output dependence graph.
bool has_packed_vars() const
System dependence + anti-dependence + output dependence graph + flow graph with feedback.
This structure defines graphs where nodes are operations.
Definition: op_graph.hpp:715
MemoryAllocation_Policy
The allocation memory polycy.
bool is_pipeline_enabled() const
Anti-dependence graph.
bool has_globals
when true at least one global variable is used
const OpGraphRef fflsaodg
The system dependence, antidependence, output dependence and flow graph with feedback;.
CustomOrderedSet< unsigned int > parm_decl_stored
this set represents the formal parameters that has to be stored into the formal parameter from the ac...
bool is_a_state_variable(unsigned int node_id) const
return true if a variable is a state variable or not
This structure defines graphs where nodes are basic_blocks.
boost::graph_traits< graph >::edge_descriptor EdgeDescriptor
edge definition.
Definition: graph.hpp:1316
#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:50 for PandA-2024.02 by doxygen 1.8.13