PandA-2024.02
loops.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  */
50 #ifndef LOOPS_HPP
51 #define LOOPS_HPP
52 
54 #include "config_HAVE_HOST_PROFILING_BUILT.hpp"
55 
56 #include "custom_map.hpp" // for unordered_map
57 #include "custom_set.hpp" // for unordered_set
58 #include "graph.hpp"
59 #include "refcount.hpp"
60 
61 #include <cstddef> // for size_t
62 #include <list> // for list
63 #include <string> // for string
64 #include <utility> // for pair
65 #include <vector> // for vector
66 
78 
79 // This class represents a loop forest for a given method.
80 // The loop forest is built by Tarjan algorithm and each loop
81 // is represented by a loop instance (see loop.h).
82 //
83 // The class allows a client to iterate on the loops in a method
84 // and provides a map from basic block to loop to know if a block
85 // belongs to a loop.
86 //
87 // If necessary it is possible to extend the class to navigate the
88 // hierarchy in an ordered way.
89 //
90 class Loops
91 {
92  private:
95 
98 
101 
104 
106  std::list<LoopRef> modifiable_loops_list;
107  std::list<LoopConstRef> const_loops_list;
108 
109  using vertex_pair = std::pair<vertex, vertex>;
110 
112 
113  Loops() = delete;
114 
118  void DetectLoops();
119 
128  void DetectReducibleLoop(const BBGraphRef djg, CustomOrderedSet<vertex>& visited, LoopRef loop, vertex node,
129  vertex header);
130 
131  void DetectIrreducibleLoop(const BBGraphRef djg, unsigned int min_level, unsigned int max_level,
132  std::vector<std::list<vertex>>& level_vertices_rel);
133 
135  CustomUnorderedMap<vertex, unsigned int>& lowlink, std::list<vertex>& s, CustomOrderedSet<vertex>& u,
136  unsigned int& max_dfs);
137 
138  bool stack_contains(std::list<vertex> stack, vertex v);
139 
143  void BuildZeroLoop();
144 
149  void computeDepth(const LoopConstRef loop);
150 
151  public:
157  Loops(const FunctionBehaviorRef FB, const ParameterConstRef parameter);
158 
162  size_t NumLoops() const;
163 
168  const std::list<LoopConstRef>& GetList() const;
169 
174  const std::list<LoopRef>& GetModifiableList() const;
175 
180  const LoopConstRef CGetLoop(unsigned int id) const;
181 
186  const LoopRef GetLoop(unsigned int id);
187 
193  void WriteDot(const std::string& file_name
194 #if HAVE_HOST_PROFILING_BUILT
195  ,
196  const ProfilingInformationConstRef profiling_information = ProfilingInformationConstRef()
197 #endif
198  ) const;
199 };
200 
201 #endif // LOOPS_HPP
void BuildZeroLoop()
Creates Loop zero data structure.
Definition: loops.cpp:754
string target
Definition: lenet_tvm.py:16
Class specification of the graph structures.
Definition of the profiling information class.
size_t NumLoops() const
Returns the number of loops.
Definition: loops.cpp:662
REF_FORWARD_DECL(BBGraph)
redefinition of map to manage ordered/unordered structures
void computeDepth(const LoopConstRef loop)
Sets depth for each loop in the forest starting from loop.
Definition: loops.cpp:742
Class used to describe a particular graph with basic blocks as nodes.
absl::flat_hash_map< T, U, Hash, Eq, Alloc > CustomUnorderedMap
Definition: custom_map.hpp:148
CONSTREF_FORWARD_DECL(Loop)
bool is_edge_in_list(CustomUnorderedSet< vertex_pair > &l, vertex source, vertex target)
Definition: loops.cpp:203
std::list< LoopRef > modifiable_loops_list
List of found loops.
Definition: loops.hpp:106
bool stack_contains(std::list< vertex > stack, vertex v)
Definition: loops.cpp:502
redefinition of set to manage ordered/unordered structures
int debug_level
Debug level.
Definition: loops.hpp:100
boost::graph_traits< graph >::vertex_descriptor vertex
vertex definition.
Definition: graph.hpp:1303
void tarjan_scc(const BBGraphRef djg, vertex v, CustomUnorderedMap< vertex, unsigned int > &dfs_order, CustomUnorderedMap< vertex, unsigned int > &lowlink, std::list< vertex > &s, CustomOrderedSet< vertex > &u, unsigned int &max_dfs)
Definition: loops.cpp:518
Definition: loop.hpp:153
Template definition of refcount.
Loops()=delete
Definition: tree.c:10
Definition: loops.hpp:90
const std::list< LoopConstRef > & GetList() const
Returns the list of loops (const)
Definition: loops.cpp:622
const std::list< LoopRef > & GetModifiableList() const
Return the list of loops.
Definition: loops.cpp:627
const LoopConstRef CGetLoop(unsigned int id) const
Returns a loop given the id.
Definition: loops.cpp:632
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
const ParameterConstRef Param
class containing all the parameters
Definition: loops.hpp:97
void DetectLoops()
Computes the loops of the control flow graph.
Definition: loops.cpp:216
void DetectReducibleLoop(const BBGraphRef djg, CustomOrderedSet< vertex > &visited, LoopRef loop, vertex node, vertex header)
Reducible loop construction.
Definition: loops.cpp:421
const LoopRef GetLoop(unsigned int id)
Returns a loop given the id.
Definition: loops.cpp:647
std::pair< vertex, vertex > vertex_pair
Definition: loops.hpp:109
std::list< LoopConstRef > const_loops_list
Definition: loops.hpp:107
void WriteDot(const std::string &file_name) const
Write dot files representing the loop forest.
Definition: loops.cpp:667
CustomUnorderedMap< vertex, LoopRef > block_to_loop
Maps between basic block and loop to which it belongs.
Definition: loops.hpp:103
void DetectIrreducibleLoop(const BBGraphRef djg, unsigned int min_level, unsigned int max_level, std::vector< std::list< vertex >> &level_vertices_rel)
Definition: loops.cpp:464
const FunctionBehaviorRef FB
The function behavior.
Definition: loops.hpp:94

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