PandA-2024.02
loops_computation.cpp
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  */
45 #include "loops_computation.hpp"
47 
48 #include "Parameter.hpp"
49 #include "application_manager.hpp"
50 #include "basic_block.hpp"
51 #include "behavioral_helper.hpp"
52 #include "function_behavior.hpp"
53 #include "graph.hpp"
54 #include "loop.hpp"
55 #include "loops.hpp"
56 #include "tree_basic_block.hpp"
57 
58 #include "dbgPrintHelper.hpp" // for DEBUG_LEVEL_
59 #include "hash_helper.hpp"
60 #include "string_manipulation.hpp" // for GET_CLASS
61 #include <iosfwd>
62 
64  unsigned int _function_id, const DesignFlowManagerConstRef _design_flow_manager)
65  : FunctionFrontendFlowStep(_AppM, _function_id, LOOPS_COMPUTATION, _design_flow_manager, _parameters)
66 {
67  debug_level = parameters->get_class_debug_level(GET_CLASS(*this), DEBUG_LEVEL_NONE);
68 }
69 
71 
74 {
76  switch(relationship_type)
77  {
79  {
80  relationships.insert(std::make_pair(BASIC_BLOCKS_CFG_COMPUTATION, SAME_FUNCTION));
81  relationships.insert(std::make_pair(DOM_POST_DOM_COMPUTATION, SAME_FUNCTION));
82  break;
83  }
86  {
87  break;
88  }
89  default:
90  {
92  }
93  }
94  return relationships;
95 }
96 
98 {
99  if(bb_version != 0 and bb_version != function_behavior->GetBBVersion())
100  {
101  function_behavior->loops = LoopsRef();
102  }
103 }
104 
106 {
107  const BBGraphRef fbb = function_behavior->GetBBGraph(FunctionBehavior::FBB);
108 
109  THROW_ASSERT(function_behavior->dominators, "Dominators has to be computed!");
110  function_behavior->loops = LoopsRef(new Loops(function_behavior, parameters));
111  if(parameters->getOption<bool>(OPT_print_dot))
112  {
113  function_behavior->CGetLoops()->WriteDot("LF.dot");
114  }
115  std::list<LoopConstRef> loops = function_behavior->CGetLoops()->GetList();
116  auto loop_end = loops.end();
117  for(auto loop = loops.begin(); loop != loop_end; ++loop)
118  {
120  if((*loop)->GetId() == 0)
121  {
122  continue;
123  }
124  const CustomUnorderedSet<vertex> blocks = (*loop)->get_blocks();
125  CustomUnorderedSet<vertex>::const_iterator bb_it, bb_it_end = blocks.end();
126  for(bb_it = blocks.begin(); bb_it != bb_it_end; ++bb_it)
127  {
128  const BBNodeInfoRef bb_node_info = fbb->GetBBNodeInfo(*bb_it);
129  bb_node_info->loop_id = (*loop)->GetId();
131  " Basic block " + std::to_string(bb_node_info->block->number));
132  }
133  }
135  "Number of reducible loops: " + std::to_string(function_behavior->CGetLoops()->NumLoops()));
137 }
#define DEBUG_LEVEL_VERY_PEDANTIC
extremely verbose debugging print is performed.
File containing functions and utilities to support the printing of debug messagges.
#define PRINT_DBG_MEX(dbgLevel, curDbgLevel, mex)
We are producing a debug version of the program, so the message is printed;.
#define GET_CLASS(obj)
Macro returning the actual type of an object.
Definition of the class representing a generic C application.
RelationshipType
The relationship type.
Source must be executed to satisfy target.
Class specification of the graph structures.
Data structure describing a basic block at tree level.
unsigned int bb_version
The version of the basic block intermediate representation on which this step has been applied...
Auxiliary methods for manipulating string.
~loops_computation() override
Destructor.
#define THROW_UNREACHABLE(str_expr)
helper function used to specify that some points should never be reached
Definition: exceptions.hpp:292
Basic block control flow graph with feedback.
const ParameterConstRef parameters
Set of input parameters.
DesignFlowStep_Status
The status of a step.
#define DEBUG_LEVEL_NONE
no debugging print is performed.
void Initialize() override
Initialize the step (i.e., like a constructor, but executed just before exec.
Analysis step performing loops computation.
DesignFlowStep_Status InternalExec() override
Performs the loop computation step.
BBNodeInfoRef GetBBNodeInfo(const vertex node)
Return the info associated with a basic block.
Definition: loops.hpp:90
Class specification of the basic_block structure.
This file collects some hash functors.
interface of a loop
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
interface of loops finding algorithm
this class is used to manage the command-line or XML options.
int debug_level
The debug level.
loops_computation(const ParameterConstRef _parameters, const application_managerRef AppM, unsigned int function_id, const DesignFlowManagerConstRef design_flow_manager)
Constructor.
A brief description of the C++ Header File.
const FunctionBehaviorRef function_behavior
The function behavior of the function to be analyzed.
const CustomUnorderedSet< std::pair< FrontendFlowStepType, FunctionRelationship > > ComputeFrontendRelationships(const DesignFlowStep::RelationshipType relationship_type) const override
Return the set of analyses in relationship with this design step.
#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:51 for PandA-2024.02 by doxygen 1.8.13