PandA-2024.02
loop.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  */
102 #ifndef LOOP_HPP
103 #define LOOP_HPP
104 
105 #include "custom_map.hpp"
106 #include "custom_set.hpp"
107 #include "graph.hpp"
108 #include "panda_types.hpp"
109 #include "refcount.hpp"
110 
111 #include <cstddef>
112 #include <list>
113 #include <utility>
114 
119 #define SINGLE_EXIT_LOOP 1
121 
123 #define UNKNOWN_LOOP 2
124 
126 #define WHILE_LOOP 4
127 
129 #define FOR_LOOP 8
130 
132 #define DOALL_LOOP 16
133 
135 #define DO_WHILE_LOOP 32
136 
138 #define COUNTABLE_LOOP 64
139 
141 #define PIPELINABLE_LOOP 128
142 
144 
150 class OpVertexSet;
152 
153 class Loop
154 {
155  private:
157  friend class Loops;
158 
160  void ComputeLandingPadExits();
161 
163  const BBGraphRef g;
164 
167 
170 
173 
176 
178  std::list<vertex> exits;
179 
182 
185 
188 
191 
193  unsigned int loop_id;
194 
196  std::map<vertex, CustomUnorderedSet<vertex>> exit_landing_association;
197 
199  static unsigned int curr_unused_irreducible_id;
200 
203 
204  public:
206  unsigned int depth;
207 
210 
212  long long footprint_size;
213 
215  long long instruction_size;
216 
219 
221  unsigned int main_iv;
222 
225 
228  unsigned int init_gimple_id;
229 
231  unsigned int inc_id;
232 
235 
238 
242 
246 
249 
253 
258  explicit Loop(const BBGraphRef g);
259 
265  Loop(const BBGraphRef _bb_graph, vertex _header_block);
266 
271  unsigned int GetId() const;
272 
277  bool is_innermost() const;
278 
283  bool IsReducible() const;
284 
289  vertex GetHeader() const;
290 
293  {
294  return alternative_entries;
295  }
296 
299  {
300  alternative_entries.insert(v);
301  }
302 
307  const LoopRef Parent() const;
308 
313  void add_block(vertex block);
314 
319  size_t num_blocks() const;
320 
325  const CustomUnorderedSet<vertex>& get_blocks() const;
326 
327  // Info on the exit blocks
328  size_t num_exits() const;
329  std::list<vertex>::const_iterator exit_block_iter_begin() const;
330  std::list<vertex>::const_iterator exit_block_iter_end() const;
331 
332  // Info on the landing pads
333  size_t num_landing_pads() const;
334 
340 
341  // Return the primary landing pad if it exists, NULL otherwise
342  // The primary landing pad is the one that is the unique successor
343  // of all the other LPs
344  vertex primary_landing_pad() const;
345 
350  void SetParent(LoopRef parent);
351 
356  void AddChild(LoopRef child);
357 
362 
368 
374  OpVertexSet GetRecursivelyOps(const OpGraphConstRef op_graph) const;
375 
380  const std::map<vertex, CustomUnorderedSet<vertex>>& get_exit_landing_association() const;
381 
384  {
385  std::pair<vertex, vertex> vpair(vs, vd);
386  sp_back_edges.insert(vpair);
387  }
388 
390  bool is_sp_back_edge(vertex vs, vertex vd) const
391  {
392  std::pair<vertex, vertex> vpair(vs, vd);
393  return sp_back_edges.find(vpair) != sp_back_edges.end();
394  }
395 
398  {
399  return sp_back_edges;
400  }
401 
403  friend class add_loop_nop;
404 };
407 
408 #endif // LOOP_HPP
Loop(const BBGraphRef g)
Constructor for empty loop (used for irreducible)
Definition: loop.cpp:63
std::list< vertex > exits
exit blocks for this loop
Definition: loop.hpp:178
void SetParent(LoopRef parent)
Sets parent for this loop.
Definition: loop.cpp:244
vertex body_start
body start basic block (at the moment defined only for SIMPLE_LOOP & WHILE_LOOP)
Definition: loop.hpp:218
bool close_interval
flag for induction variable close interval defined when loop_type is COUNTABLE_LOOP ...
Definition: loop.hpp:252
long long instruction_size
loop instruction footprint
Definition: loop.hpp:215
bool is_innermost_loop
tells if there aren&#39;t loop nested in this
Definition: loop.hpp:166
std::map< vertex, CustomUnorderedSet< vertex > > exit_landing_association
Map storing the association between an exit basic block and the corresponding landing pads...
Definition: loop.hpp:196
void AddChild(LoopRef child)
Adds a child loop.
Definition: loop.cpp:287
long long footprint_size
loop memory footprint
Definition: loop.hpp:212
refcount< Loop > parent_loop
Parent loop.
Definition: loop.hpp:169
tree_nodeRef upper_bound_tn
Final value of induction variable.
Definition: loop.hpp:248
const LoopRef Parent() const
returns the parent loop
Definition: loop.cpp:239
REF_FORWARD_DECL(BBGraph)
void add_entry(vertex v)
add an entry of the loop
Definition: loop.hpp:298
vertex primary_landing_pad() const
Definition: loop.cpp:186
integer_cst_t lower_bound
Initial value of induction variable defined when loop_type is COUNTABLE_LOOP.
Definition: loop.hpp:241
int loop_type
loop type
Definition: loop.hpp:209
Class specification of the graph structures.
void add_block(vertex block)
adds a block to this loop
Definition: loop.cpp:282
const BBGraphRef g
The basic block control flow graph.
Definition: loop.hpp:163
const CustomUnorderedSet< vertex > & get_blocks() const
returns the blocks
Definition: loop.cpp:156
size_t num_exits() const
Definition: loop.cpp:161
CustomOrderedSet< LoopConstRef > children
Child loops.
Definition: loop.hpp:172
std::list< vertex >::const_iterator exit_block_iter_end() const
Definition: loop.cpp:171
CustomOrderedSet< vertex > alternative_entries
in case the loop is irreducible the loop has multiple entries while for reducible loops the entry is ...
Definition: loop.hpp:190
redefinition of map to manage ordered/unordered structures
std::list< vertex >::const_iterator exit_block_iter_begin() const
Definition: loop.cpp:166
A set of operation vertices.
Definition: op_graph.hpp:654
Abstract pure class for the tree structure.
Definition: tree_node.hpp:139
const CustomUnorderedSet< vertex > GetLandingPadBlocks() const
Return the landing pads of the loops.
Definition: loop.cpp:181
CONSTREF_FORWARD_DECL(Loop)
tree_nodeRef init
value of the initialization of the induction variable
Definition: loop.hpp:224
size_t num_blocks() const
returns the number of basic blocks belonging to this loop
Definition: loop.cpp:151
CustomUnorderedSet< vertex > blocks
Blocks which belong to this loop.
Definition: loop.hpp:175
OpVertexSet GetRecursivelyOps(const OpGraphConstRef op_graph) const
Returns the operation which belongs to this loop or to a nested loop.
Definition: loop.cpp:302
Class used to describe a particular graph with basic blocks as nodes.
unsigned int inc_id
The node id containing the increment statement.
Definition: loop.hpp:231
redefinition of set to manage ordered/unordered structures
unsigned int loop_id
the id of the loop
Definition: loop.hpp:193
const std::map< vertex, CustomUnorderedSet< vertex > > & get_exit_landing_association() const
Returns the map exit_landing_association.
Definition: loop.cpp:317
integer_cst_t upper_bound
Final value of induction variable defined when loop_type is COUNTABLE_LOOP.
Definition: loop.hpp:245
boost::graph_traits< graph >::vertex_descriptor vertex
vertex definition.
Definition: graph.hpp:1303
CustomOrderedSet< vertex > get_entries() const
return the alternative entries of a loop
Definition: loop.hpp:292
void add_sp_back_edge(vertex vs, vertex vd)
add a spanning tree back edge
Definition: loop.hpp:383
CustomUnorderedSet< vertex > landing_pads
landing_pads for this loop
Definition: loop.hpp:181
tree_nodeRef increment_tn
Increment of induction variable.
Definition: loop.hpp:237
Definition: loop.hpp:153
This struct specifies the block node.
Definition: tree_node.hpp:1820
Template definition of refcount.
unsigned int init_gimple_id
The index of the gimple tree node containing the initialization of the induction variable; right oper...
Definition: loop.hpp:228
Definition: APInt.hpp:53
unsigned int GetId() const
returns the loop id
Definition: loop.cpp:131
void ComputeLandingPadExits()
compute landing pad exits
Definition: loop.cpp:249
Definition: loops.hpp:90
size_t num_landing_pads() const
Definition: loop.cpp:176
bool is_sp_back_edge(vertex vs, vertex vd) const
check if a pair of vertex is a spanning tree back edge for the loop
Definition: loop.hpp:390
bool is_innermost() const
tells if the loop is innermost
Definition: loop.cpp:141
vertex GetHeader() const
returns loop header
Definition: loop.cpp:136
CustomOrderedSet< std::pair< vertex, vertex > > sp_back_edges
set of vertex pairs describing a spanning tree back edge for the loop
Definition: loop.hpp:202
CustomOrderedSet< std::pair< vertex, vertex > > get_sp_back_edges() const
return the list of spanning tree back edges
Definition: loop.hpp:397
void get_recursively_bb(CustomUnorderedSet< vertex > &ret) const
Returns the basic blocks which belong to this loop and to loop nested in this loop.
Definition: loop.cpp:292
static unsigned int curr_unused_irreducible_id
used to label irreducible loops
Definition: loop.hpp:199
integer_cst_t increment
Increment of induction variable.
Definition: loop.hpp:234
Class used to describe a particular graph with operations as nodes.
Definition: op_graph.hpp:783
bool IsReducible() const
tells if the loop is reducible
Definition: loop.cpp:146
vertex primary_landing_pad_block
???
Definition: loop.hpp:184
const CustomOrderedSet< LoopConstRef > & GetChildren() const
Returns the children of this loop in the loop forest.
Definition: loop.cpp:322
friend class add_loop_nop
Definition of friend class add_loop_nop.
Definition: loop.hpp:403
unsigned int depth
Nesting depth of this loop.
Definition: loop.hpp:206
unsigned int main_iv
the main induction variable of countable loop;
Definition: loop.hpp:221
vertex header_block
the header of the loop
Definition: loop.hpp:187

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