PandA-2024.02
op_graph.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  */
44 #ifndef OP_GRAPH_HPP
45 #define OP_GRAPH_HPP
46 
48 #include "config_HAVE_HLS_BUILT.hpp"
49 #include "config_HAVE_UNORDERED.hpp"
50 
52 #include "cdfg_edge_info.hpp"
53 #include "graph.hpp"
54 #include "typed_node_info.hpp"
55 
57 #include "function_behavior.hpp"
58 
59 #include <boost/graph/graph_traits.hpp> // for graph_traits<>::...
60 #include <iosfwd> // for ostream
61 #include <limits> // for numeric_limits
62 #include <list> // for list
63 #include <set> // for set
64 #include <string> // for string
65 
67 #include "custom_map.hpp"
68 #include "custom_set.hpp"
69 #include "refcount.hpp"
70 #include "strong_typedef.hpp" // for UINT_STRONG_TYPEDEF
71 
75 class OpVertexSet;
76 
77 UINT_STRONG_TYPEDEF(MemoryAddress);
79 #define ENTRY_ID (std::numeric_limits<unsigned int>::max())
80 #define EXIT_ID (std::numeric_limits<unsigned int>::max() - 1)
82 
90 #define TYPE_OPAQUE 1 << 0
91 
95 #define TYPE_EXTERNAL 1 << 4
96 
100 #define TYPE_IF 1 << 5
101 
105 #define TYPE_SWITCH 1 << 6
106 
110 #define TYPE_WHILE 1 << 7
111 
115 #define TYPE_FOR 1 << 8
116 
120 #define TYPE_DO 1 << 9
121 
125 #define TYPE_ASSIGN 1 << 10
126 
130 #define TYPE_NOP 1 << 11
131 
135 #define TYPE_PHI 1 << 12
136 
140 #define TYPE_RET 1 << 13
141 
145 #define TYPE_TO_BE_REMOVED 1 << 14
146 
151 #define TYPE_LABEL 1 << 15
152 
157 #define TYPE_GOTO 1 << 16
158 
162 #define TYPE_VPHI 1 << 17
163 
167 #define TYPE_INIT 1 << 18
168 
172 #define TYPE_LOAD 1 << 19
173 
177 #define TYPE_STORE 1 << 20
178 
182 #define TYPE_MEMCPY 1 << 21
183 
187 #define TYPE_WAS_GIMPLE_PHI 1 << 22
188 
192 #define TYPE_FIRST_OP 1 << 23
193 
197 #define TYPE_LAST_OP 1 << 24
198 
202 #define TYPE_MULTIIF 1 << 25
203 
207 #define TYPE_ATOMIC 1 << 26
208 
212 #define TYPE_PREDICATED 1 << 27
213 
217 #define TYPE_RW 1 << 28
218 
220 
224 #define ASSIGN "ASSIGN"
225 #if 0
226 
229 #define STORE "STORE"
230 #define PREDICATED_STORE "PREDICATED_STORE"
231 
234 #define LOAD "LOAD"
235 #define PREDICATED_LOAD "PREDICATED_LOAD"
236 #endif
237 
240 #define ASSERT_EXPR "assert_expr"
241 
245 #define EXTRACT_BIT_EXPR "extract_bit_expr"
246 
250 #define LUT_EXPR "lut_expr"
251 
255 #define READ_COND "READ_COND"
256 
260 #define MULTI_READ_COND "MULTI_READ_COND"
261 
265 #define SWITCH_COND "SWITCH_COND"
266 
270 #define GIMPLE_LABEL "gimple_label"
271 
275 #define GIMPLE_GOTO "gimple_goto"
276 
280 #define NOP "NOP"
281 
285 #define GIMPLE_RETURN "gimple_return"
286 
290 #define GIMPLE_NOP "gimple_nop"
291 
295 #define GIMPLE_PHI "gimple_phi"
296 
300 #define GIMPLE_ASM "gimple_asm"
301 
305 #define GIMPLE_PRAGMA "gimple_pragma"
306 
310 #define MEMCPY "__internal_bambu_memcpy"
311 
315 #define MEMCMP "memcmp"
316 
320 #define MEMSET "__internal_bambu_memset"
321 
325 #define VECT_CONCATENATION "VECT_CONCATENATION"
326 
330 #define ADDR_EXPR "addr_expr"
331 
335 #define NOP_EXPR "nop_expr"
336 
340 #define FLOAT_EXPR "float_expr"
341 
345 #define FIX_TRUNC_EXPR "fix_trunc_expr"
346 
350 #define CONVERT_EXPR "convert_expr"
351 
355 #define VIEW_CONVERT_EXPR "view_convert_expr"
356 
358 #define BUILTIN_WAIT_CALL "__builtin_wait_call"
359 
363 struct OpNodeInfo : public TypedNodeInfo
364 {
367 
371 
373  std::list<unsigned int> actual_parameters;
374 
377 
380 
382  unsigned int bb_index;
383 
385  unsigned int cer;
386 
390  OpNodeInfo();
391 
395  ~OpNodeInfo() override;
396 
400  void Initialize();
401 
408  const FunctionBehavior_VariableAccessType access_type) const;
409 
413  const std::string GetOperation() const;
414 
418  unsigned int GetNodeId() const;
419 
426  void Print(std::ostream& stream, const BehavioralHelperConstRef behavioral_helper, const bool dotty_format) const;
427 };
430 
435 #define GET_BB_INDEX(data, vertex_index) Cget_node_info<OpNodeInfo>(vertex_index, *(data))->bb_index
436 
441 #define GET_CER(data, vertex_index) Cget_node_info<OpNodeInfo>(vertex_index, *(data))->cer
442 
446 #define DFG_SCA_SELECTOR 1 << 7
448 #define DFG_AGG_SELECTOR 1 << 8
450 #define DFG_SELECTOR (DFG_SCA_SELECTOR | DFG_AGG_SELECTOR)
452 #define FB_DFG_SCA_SELECTOR 1 << 9
454 #define FB_DFG_AGG_SELECTOR 1 << 10
456 #define FB_DFG_SELECTOR (FB_DFG_SCA_SELECTOR | FB_DFG_AGG_SELECTOR)
458 #define FDFG_SELECTOR (DFG_SELECTOR | FB_DFG_SELECTOR)
460 
462 #define ADG_SCA_SELECTOR 1 << 11
463 #define ADG_AGG_SELECTOR 1 << 12
465 #define ADG_SELECTOR (ADG_SCA_SELECTOR | ADG_AGG_SELECTOR)
467 #define FB_ADG_SCA_SELECTOR 1 << 13
469 #define FB_ADG_AGG_SELECTOR 1 << 14
471 #define FB_ADG_SELECTOR (FB_ADG_SCA_SELECTOR | FB_ADG_AGG_SELECTOR)
473 #define FADG_SELECTOR (ADG_SELECTOR | FB_ADG_SELECTOR)
475 
477 #define ODG_SCA_SELECTOR 1 << 15
478 #define ODG_AGG_SELECTOR 1 << 16
480 #define ODG_SELECTOR (ODG_SCA_SELECTOR | ODG_AGG_SELECTOR)
482 #define FB_ODG_SCA_SELECTOR 1 << 17
484 #define FB_ODG_AGG_SELECTOR 1 << 18
486 #define FB_ODG_SELECTOR (FB_ODG_SCA_SELECTOR | FB_ODG_AGG_SELECTOR)
488 #define FODG_SELECTOR (ODG_SELECTOR | FB_ODG_SELECTOR)
490 
492 #define SDG_SELECTOR (CDG_SELECTOR | DFG_SELECTOR)
493 #define FSDG_SELECTOR (FCDG_SELECTOR | FDFG_SELECTOR)
495 #define RSDG_SELECTOR (TRED_SELECTOR)
497 
499 #define FSADG_SELECTOR \
500  (CDG_SELECTOR | DFG_SELECTOR | ADG_SELECTOR | FB_CDG_SELECTOR | FB_DFG_SELECTOR | FB_ADG_SELECTOR)
501 #define SAODG_SELECTOR (CDG_SELECTOR | DFG_SELECTOR | ADG_SELECTOR | ODG_SELECTOR)
503 #define FADFG_SELECTOR (DFG_SELECTOR | ADG_SELECTOR)
505 
507 #define CSG_SELECTOR 1 << 19
508 #define SG_SELECTOR (CSG_SELECTOR | DFG_SELECTOR | ADG_SELECTOR | ODG_SELECTOR | FLG_SELECTOR)
510 
512 #define RPDG_SELECTOR 1 << 20
513 
515 #define FLG_SELECTOR 1 << 21
516 
518 #define FB_FLG_SELECTOR 1 << 22
519 
521 #define DEBUG_SELECTOR 1 << 23
522 
526 class OpEdgeInfo : public CdfgEdgeInfo
527 {
528  public:
532  OpEdgeInfo();
533 
537  ~OpEdgeInfo() override;
538 
542  bool FlgEdgeT() const;
543 
547  bool FlgEdgeF() const;
548 };
552 
556 struct OpGraphInfo : public GraphInfo
557 {
561  OpGraphInfo();
562 
566  ~OpGraphInfo() override;
567 
570 
573 
576 
579 
584  explicit OpGraphInfo(const BehavioralHelperConstRef BH);
585 };
586 
590 
591 #if HAVE_UNORDERED
592 
595 class OpVertexSet : public CustomUnorderedSet<vertex>
596 {
597  public:
601  explicit OpVertexSet(const OpGraphConstRef op_graph);
602 };
603 
607 template <typename value>
608 class OpVertexMap : public CustomUnorderedMap<vertex, value>
609 {
610  public:
615  {
616  }
617 };
618 
619 class OpEdgeSet : public CustomUnorderedSet<EdgeDescriptor>
620 {
621  public:
625  explicit OpEdgeSet(const OpGraphConstRef op_graph);
626 };
627 #else
628 class OpVertexSorter : std::binary_function<vertex, vertex, bool>
629 {
630  private:
634 
635  public:
640  explicit OpVertexSorter(const OpGraphConstRef op_graph);
641 
648  bool operator()(const vertex x, const vertex y) const;
649 };
650 
654 class OpVertexSet : public std::set<vertex, OpVertexSorter>
655 {
656  public:
660  explicit OpVertexSet(const OpGraphConstRef op_graph);
661 };
662 
666 template <typename value>
667 class OpVertexMap : public std::map<vertex, value, OpVertexSorter>
668 {
669  public:
673  explicit OpVertexMap(const OpGraphConstRef op_graph)
675  {
676  }
677 };
678 
679 class OpEdgeSorter : std::binary_function<EdgeDescriptor, EdgeDescriptor, bool>
680 {
681  private:
685 
686  public:
691  explicit OpEdgeSorter(const OpGraphConstRef op_graph);
692 
699  bool operator()(const EdgeDescriptor x, const EdgeDescriptor y) const;
700 };
701 
702 class OpEdgeSet : public std::set<EdgeDescriptor, OpEdgeSorter>
703 {
704  public:
708  explicit OpEdgeSet(const OpGraphConstRef op_graph);
709 };
710 #endif
711 
716 {
717  protected:
720 
721  public:
728 
732  ~OpGraphsCollection() override;
733 
741  inline EdgeDescriptor AddEdge(const vertex source, const vertex target, const int selector)
742  {
743  if(ExistsEdge(source, target))
744  {
745  return AddSelector(source, target, selector);
746  }
747  else
748  {
749  return InternalAddEdge(source, target, selector, EdgeInfoRef(new OpEdgeInfo()));
750  }
751  }
752 
758  boost::graph_traits<boost_graphs_collection>::vertex_descriptor AddVertex(const NodeInfoRef info) override;
759 
764  void RemoveVertex(boost::graph_traits<boost_graphs_collection>::vertex_descriptor v) override;
765 
769  const OpVertexSet CGetOperations() const;
770 
774  void Clear();
775 };
776 
779 
783 struct OpGraph : public graph
784 {
786  friend class Schedule;
787 
788  public:
794  OpGraph(const OpGraphsCollectionRef _op_graphs_collection, int selector);
795 
802  OpGraph(const OpGraphsCollectionRef _op_graphs_collection, int selector,
803  const CustomUnorderedSet<boost::graph_traits<OpGraphsCollection>::vertex_descriptor>& sub);
804 
808  ~OpGraph() override;
809 
815  void WriteDot(const std::string& file_name, const int detail_level = 0) const;
816 
817 #if HAVE_HLS_BUILT
818 
824  void WriteDot(const std::string& file_name, const hlsConstRef HLS,
825  const CustomSet<unsigned int> critical_paths) const;
826 #endif
827 
834  {
835  return RefcountCast<OpNodeInfo>(graph::GetNodeInfo(node));
836  }
837 
843  inline const OpNodeInfoConstRef CGetOpNodeInfo(const vertex node) const
844  {
845  return RefcountCast<const OpNodeInfo>(graph::CGetNodeInfo(node));
846  }
847 
853  inline const OpEdgeInfoConstRef CGetOpEdgeInfo(const EdgeDescriptor edge) const
854  {
855  return RefcountCast<const OpEdgeInfo>(graph::CGetEdgeInfo(edge));
856  }
857 
863  {
864  return RefcountCast<OpGraphInfo>(GetGraphInfo());
865  }
866 
872  {
873  return RefcountCast<const OpGraphInfo>(CGetGraphInfo());
874  }
875 
881  {
882  return RefcountCast<OpGraphInfo>(GetGraphInfo());
883  }
884 
894  CustomUnorderedMap<vertex, OpVertexSet> GetSrcVertices(const OpVertexSet& toCheck, int edgeType) const;
895 
899  const OpVertexSet CGetOperations() const;
900 
905 #if HAVE_UNORDERED
906  boost::iterator_range<InEdgeIterator> CGetInEdges(const vertex v) const;
907 #else
908  OpEdgeSet CGetInEdges(const vertex v) const;
909 #endif
910 
915 #if HAVE_UNORDERED
916  boost::iterator_range<OutEdgeIterator> CGetOutEdges(const vertex v) const;
917 #else
918  OpEdgeSet CGetOutEdges(const vertex v) const;
919 #endif
920 };
924 
925 #endif
CustomSet< unsigned int > called
Store the index of called functions.
Definition: op_graph.hpp:379
CustomMap< FunctionBehavior_VariableType, CustomMap< FunctionBehavior_VariableAccessType, CustomSet< unsigned int > > > variables
set of scalar ssa accessed in this node
Definition: op_graph.hpp:370
~OpNodeInfo() override
Destructor.
OpGraphConstRef op_graph
The operation graph to which vertices belong Note: this should be const, but can not because of assig...
Definition: op_graph.hpp:684
unsigned int cer
Store the index of the control equivalent region.
Definition: op_graph.hpp:385
Base class storing user data information to the whole graph.
Definition: graph_info.hpp:60
string target
Definition: lenet_tvm.py:16
vertex exit_vertex
Index identifying the exit vertex.
Definition: op_graph.hpp:572
vertex entry_vertex
Index identifying the entry vertex.
Definition: op_graph.hpp:569
Class managing the schedule of the operations.
Definition: schedule.hpp:118
std::list< unsigned int > actual_parameters
Set of actual parameters of called function (used in pthread backend.
Definition: op_graph.hpp:373
Class specification of the graph structures.
Information associated with a generic operation node.
Definition: op_graph.hpp:363
CustomOrderedMap< T, U > CustomMap
Definition: custom_map.hpp:167
Information associated with an operation or basic block graph.
const EdgeInfoConstRef CGetEdgeInfo(typename boost::graph_traits< graphs_collection >::vertex_descriptor source, typename boost::graph_traits< graphs_collection >::vertex_descriptor target) const
Get the edge property.
Definition: graph.hpp:811
FunctionBehavior_VariableType
The possible type of a variable.
Definition of hash function for EdgeDescriptor.
Definition: graph.hpp:1321
OpGraphInfoRef GetOpGraphInfo()
Returns the property associated with the graph.
Definition: op_graph.hpp:862
EdgeDescriptor AddEdge(const vertex source, const vertex target, const int selector)
Add an edge with empty information associated.
Definition: op_graph.hpp:741
const OpEdgeInfoConstRef CGetOpEdgeInfo(const EdgeDescriptor edge) const
Returns the info associated with an edge.
Definition: op_graph.hpp:853
Base class description of data information associated with each node of a graph.
NodeInfoRef GetNodeInfo(typename boost::graph_traits< graphs_collection >::vertex_descriptor node)
FIXME: this method should become protected and called by equivalent method in subclasses Get the node...
Definition: graph.hpp:1039
redefinition of map to manage ordered/unordered structures
A set of operation vertices.
Definition: op_graph.hpp:654
OpGraphConstRef op_graph
The operation graph to which vertices belong Note: this should be const, but can not because of assig...
Definition: op_graph.hpp:633
unsigned int GetNodeId() const
Return the node id of the operation associated with the vertex.
Definition: op_graph.cpp:144
tree_nodeRef node
The tree node associated with this vertex.
Definition: op_graph.hpp:376
CustomSet< unsigned int > cited_variables
set of cited variables (i.e., variables which are included in the c printing of this statement) ...
Definition: op_graph.hpp:366
OpNodeInfoRef GetOpNodeInfo(const vertex node)
Returns the info associated with a node.
Definition: op_graph.hpp:833
information associated with the whole graph
Definition: op_graph.hpp:556
const OpNodeInfoConstRef CGetOpNodeInfo(const vertex node) const
Returns the info associated with a node.
Definition: op_graph.hpp:843
void WriteDot(const std::string &file_name, OpGraphConstRef sub_op_graph=OpGraphConstRef(), OpVertexSet *opSet=nullptr) const
Function that writes the dot file of the scheduling by using the AT&T direct graph representation...
Definition: schedule.cpp:214
unsigned int bb_index
Store the index of the basic block which this operation vertex belongs to.
Definition: op_graph.hpp:382
unsigned map[NUM_VERTICES]
Definition: bfs.c:12
absl::flat_hash_map< T, U, Hash, Eq, Alloc > CustomUnorderedMap
Definition: custom_map.hpp:148
CustomMap< unsigned int, vertex > tree_node_to_operation
For each statement, the vertex in which it is contained.
Definition: op_graph.hpp:578
const NodeInfoConstRef CGetNodeInfo(typename boost::graph_traits< graphs_collection >::vertex_descriptor node) const
Get the node property.
Definition: graph.hpp:781
const CustomSet< unsigned int > & GetVariables(const FunctionBehavior_VariableType variable_type, const FunctionBehavior_VariableAccessType access_type) const
Return a set of accessed scalar variables.
Definition: op_graph.cpp:118
refcount< EdgeInfo > EdgeInfoRef
RefCount type definition of the edge_info class structure.
Definition: edge_info.hpp:67
The info associated with an edge of operation graph.
Definition: op_graph.hpp:526
const std::string GetOperation() const
Return the operation associated with the vertex.
Definition: op_graph.cpp:124
redefinition of set to manage ordered/unordered structures
const OpGraphInfoConstRef CGetOpGraphInfo() const
Returns the property associated with the graph.
Definition: op_graph.hpp:871
OpNodeInfo()
Constructor.
Definition: op_graph.cpp:82
void Print(std::ostream &stream, const BehavioralHelperConstRef behavioral_helper, const bool dotty_format) const
Print the content of this node.
Definition: op_graph.cpp:231
This class macros for the definition of strong typedef.
boost::graph_traits< graph >::vertex_descriptor vertex
vertex definition.
Definition: graph.hpp:1303
Map from operation vertices to value.
Definition: op_graph.hpp:667
General class used to describe a graph in PandA.
Definition: graph.hpp:771
FunctionBehavior_VariableAccessType
The access type to a variable.
CONSTREF_FORWARD_DECL(BehavioralHelper)
Autoheader include.
OpVertexSet operations
The set of operations.
Definition: op_graph.hpp:719
Template definition of refcount.
OpVertexMap(const OpGraphConstRef op_graph)
Constructor.
Definition: op_graph.hpp:673
Data structures used to represent an edge in operation and basic block graphs.
bulk graph.
Definition: graph.hpp:287
const BehavioralHelperConstRef BH
The behavioral helper.
Definition: op_graph.hpp:575
void Initialize()
Initialize variable maps.
Definition: op_graph.cpp:87
UINT_STRONG_TYPEDEF(MemoryAddress)
Data structure that contains all information about high level synthesis process.
Definition: hls.hpp:83
x
Return the smallest n such that 2^n >= _x.
Class used to describe a particular graph with operations as nodes.
Definition: op_graph.hpp:783
OpGraphInfoRef CGetOpGraphInfo()
Returns the property associated with the graph.
Definition: op_graph.hpp:880
This structure defines graphs where nodes are operations.
Definition: op_graph.hpp:715
A brief description of the C++ Header File.
boost::graph_traits< graph >::edge_descriptor EdgeDescriptor
edge definition.
Definition: graph.hpp:1316

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