PandA-2024.02
sdc_code_motion.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  */
40 #include "sdc_code_motion.hpp"
41 #include "Parameter.hpp"
42 #include "basic_block.hpp"
43 #include "dbgPrintHelper.hpp" // for DEBUG_LEVEL_
44 #include "design_flow_graph.hpp"
45 #include "design_flow_manager.hpp"
47 #include "function_behavior.hpp"
48 #include "hls.hpp"
50 #include "hls_manager.hpp"
51 #include "op_graph.hpp"
52 #include "sdc_scheduling.hpp"
53 #include "simple_code_motion.hpp"
54 #include "string_manipulation.hpp" // for GET_CLASS
55 #include "tree_basic_block.hpp"
56 #include "tree_helper.hpp"
57 #include "tree_manager.hpp"
58 #include "tree_node.hpp"
59 #include "tree_reindex.hpp"
60 
61 SDCCodeMotion::SDCCodeMotion(const application_managerRef _AppM, unsigned int _function_id,
62  const DesignFlowManagerConstRef _design_flow_manager, const ParameterConstRef _parameters)
63  : FunctionFrontendFlowStep(_AppM, _function_id, SDC_CODE_MOTION, _design_flow_manager, _parameters),
64  restart_ifmwi_opt(false)
65 {
66  debug_level = parameters->get_class_debug_level(GET_CLASS(*this), DEBUG_LEVEL_NONE);
67 }
68 
70 
73 {
75  switch(relationship_type)
76  {
78  {
79  relationships.insert(std::make_pair(DEAD_CODE_ELIMINATION_IPA, WHOLE_APPLICATION));
80  break;
81  }
83  {
85  {
87  {
88  relationships.insert(std::make_pair(SHORT_CIRCUIT_TAF, SAME_FUNCTION));
89  relationships.insert(std::make_pair(PHI_OPT, SAME_FUNCTION));
90  relationships.insert(std::make_pair(MULTI_WAY_IF, SAME_FUNCTION));
91  relationships.insert(std::make_pair(UPDATE_SCHEDULE, SAME_FUNCTION));
92  }
93  }
94  break;
95  }
97  {
98  relationships.insert(std::make_pair(SHORT_CIRCUIT_TAF, SAME_FUNCTION));
99  relationships.insert(std::make_pair(PHI_OPT, SAME_FUNCTION));
100  relationships.insert(std::make_pair(MULTI_WAY_IF, SAME_FUNCTION));
101  relationships.insert(std::make_pair(UPDATE_SCHEDULE, SAME_FUNCTION));
102  break;
103  }
104  default:
105  {
106  THROW_UNREACHABLE("");
107  }
108  }
109  return relationships;
110 }
111 
113 {
114  if(bb_version != 0)
115  {
116  return false;
117  }
118  return parameters->getOption<HLSFlowStep_Type>(OPT_scheduling_algorithm) == HLSFlowStep_Type::SDC_SCHEDULING and
119  GetPointer<const HLS_manager>(AppM) and GetPointer<const HLS_manager>(AppM)->get_HLS(function_id) and
120  GetPointer<const HLS_manager>(AppM)->get_HLS(function_id)->Rsch &&
122 }
123 
125 {
126  const auto design_flow_graph = design_flow_manager.lock()->CGetDesignFlowGraph();
127  restart_ifmwi_opt = false;
128 
129  const tree_managerRef TM = AppM->get_tree_manager();
130  auto* fd = GetPointer<function_decl>(TM->get_tree_node_const(function_id));
131  auto* sl = GetPointer<statement_list>(GET_NODE(fd->body));
132  std::map<unsigned int, blocRef>& list_of_bloc = sl->list_of_bloc;
133 
135  const auto sdc_scheduling_step = design_flow_manager.lock()->GetDesignFlowStep(HLSFunctionStep::ComputeSignature(
136  HLSFlowStep_Type::SDC_SCHEDULING, HLSFlowStepSpecializationConstRef(), function_id));
137  THROW_ASSERT(sdc_scheduling_step, "SDC scheduling hls step not found");
138  const auto sdc_scheduling = GetPointer<const SDCScheduling>(
139  design_flow_graph->CGetDesignFlowStepInfo(sdc_scheduling_step)->design_flow_step);
140  const auto& movements_list = sdc_scheduling->movements_list;
141  if(movements_list.empty())
142  {
144  }
145  for(const auto& movement : movements_list)
146  {
147  const auto statement_index = movement[0];
148  const auto old_basic_block = movement[1];
149  const auto new_basic_block = movement[2];
150  THROW_ASSERT(list_of_bloc.find(old_basic_block) != list_of_bloc.end() &&
151  list_of_bloc.find(new_basic_block) != list_of_bloc.end(),
152  "unexpected condition: BB are missing");
154  "-->Moving " + STR(TM->GetTreeReindex(statement_index)) + " from BB" + STR(old_basic_block) +
155  " to BB" + STR(new_basic_block));
156  if(not AppM->ApplyNewTransformation())
157  {
159  "<--Skipped because reached limit of cfg transformations");
160  continue;
161  }
162  list_of_bloc.at(old_basic_block)->RemoveStmt(TM->GetTreeReindex(statement_index), AppM);
163  if(list_of_bloc.at(old_basic_block)->CGetStmtList().empty() &&
164  list_of_bloc.at(old_basic_block)->CGetPhiList().empty())
165  {
166  restart_ifmwi_opt = true;
167  }
168  list_of_bloc.at(new_basic_block)->PushBack(TM->GetTreeReindex(statement_index), AppM);
169  AppM->RegisterTransformation(GetName(), TM->CGetTreeNode(statement_index));
170  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "<--Moved " + STR(statement_index));
171  }
172  function_behavior->UpdateBBVersion();
174 }
#define GET_NODE(t)
Macro used to hide implementation details when accessing a tree_node from another tree_node...
Definition: tree_node.hpp:343
#define DEBUG_LEVEL_VERY_PEDANTIC
extremely verbose debugging print is performed.
Data structure representing the entire HLS information.
#define INDENT_DBG_MEX(dbgLevel, curDbgLevel, mex)
We are producing a debug version of the program, so the message is printed;.
DesignFlowStep_Status InternalExec() override
Performs the loops analysis.
File containing functions and utilities to support the printing of debug messagges.
Step successfully executed.
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 GET_CLASS(obj)
Macro returning the actual type of an object.
std::string GetName() const override
Return the name of this design step.
RelationshipType
The relationship type.
Source must be executed to satisfy target.
~SDCCodeMotion() override
Destructor.
Data structure describing a basic block at tree level.
static std::string ComputeSignature(const HLSFlowStep_Type hls_flow_step_type, const HLSFlowStepSpecializationConstRef hls_flow_step_specialization, const unsigned int function_id)
Compute the signature of a hls flow step.
unsigned int bb_version
The version of the basic block intermediate representation on which this step has been applied...
const tree_nodeConstRef CGetTreeNode(const unsigned int i) const
#define STR(s)
Macro which performs a lexical_cast to a string.
Auxiliary methods for manipulating string.
bool HasToBeExecuted() const override
Check if this step has actually to be executed.
const tree_nodeRef get_tree_node_const(unsigned int i) const
Return the reference to the i-th tree_node Constant version of get_tree_node.
#define THROW_UNREACHABLE(str_expr)
helper function used to specify that some points should never be reached
Definition: exceptions.hpp:292
SDCCodeMotion(const application_managerRef AppM, unsigned int function_id, const DesignFlowManagerConstRef design_flow_manager, const ParameterConstRef parameters)
Constructor.
Factory for hls flow step.
HLSFlowStep_Type
Definition: hls_step.hpp:95
Classes to describe design flow graph.
tree_nodeRef GetTreeReindex(const unsigned int i)
Return a tree_reindex wrapping the i-th tree_node.
const Wrefcount< const DesignFlowManager > design_flow_manager
The design flow manager.
bool HasToBeExecuted() const override
Check if this step has actually to be executed.
Class definition of the sdc scheduling.
DesignFlowStep_Status GetStatus() const
Return the status of this design step.
Classes specification of the tree_node data structures.
const ParameterConstRef parameters
Set of input parameters.
DesignFlowStep_Status
The status of a step.
#define DEBUG_LEVEL_NONE
no debugging print is performed.
Wrapper of design_flow.
This file collects some utility functions.
refcount< T > lock() const
Definition: refcount.hpp:212
const unsigned int function_id
The index of the function to be analyzed.
Analysis step that performs some simple code motions over the IR.
Analysis step performing code motion speculation on the basis of sdc results.
const application_managerRef AppM
The application manager.
Class specification of the tree_reindex support class.
Class specification of the basic_block structure.
This class contains the methods to create a frontend flow step.
Data structures used in operations graph.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
this class is used to manage the command-line or XML options.
int debug_level
The debug level.
refcount< const HLSFlowStepSpecialization > HLSFlowStepSpecializationConstRef
const refcount definition of the class
Definition: hls_step.hpp:93
Data structure definition for high-level synthesis flow.
Class specification of the manager of the tree structures extracted from the raw file.
A brief description of the C++ Header File.
const FunctionBehaviorRef function_behavior
The function behavior of the function to be analyzed.
int sl
Definition: adpcm.c:105
#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:53 for PandA-2024.02 by doxygen 1.8.13