PandA-2024.02
remove_clobber_ga.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  */
42 #include "remove_clobber_ga.hpp"
44 
46 #include "Parameter.hpp"
47 
49 #include "application_manager.hpp"
50 #include "function_behavior.hpp"
51 
53 #include <fstream>
54 
56 #include "tree_basic_block.hpp"
57 #include "tree_helper.hpp"
58 #include "tree_manager.hpp"
59 #include "tree_node.hpp"
60 #include "tree_reindex.hpp"
61 
62 #include "hls_device.hpp"
63 #include "hls_manager.hpp"
64 
66 #include "dbgPrintHelper.hpp"
67 #include "string_manipulation.hpp" // for GET_CLASS
68 
69 remove_clobber_ga::remove_clobber_ga(const application_managerRef _AppM, unsigned int _function_id,
70  const DesignFlowManagerConstRef _design_flow_manager,
71  const ParameterConstRef _parameters)
72  : FunctionFrontendFlowStep(_AppM, _function_id, REMOVE_CLOBBER_GA, _design_flow_manager, _parameters)
73 {
74  debug_level = _parameters->get_class_debug_level(GET_CLASS(*this), DEBUG_LEVEL_NONE);
75 }
76 
78 
81 {
83  switch(relationship_type)
84  {
86  {
87  relationships.insert(std::make_pair(BLOCK_FIX, SAME_FUNCTION));
88  relationships.insert(std::make_pair(SWITCH_FIX, SAME_FUNCTION));
89  relationships.insert(std::make_pair(REBUILD_INITIALIZATION, SAME_FUNCTION));
90  break;
91  }
94  {
95  break;
96  }
97  default:
98  {
100  }
101  }
102  return relationships;
103 }
104 
106 {
107  const tree_managerRef TM = AppM->get_tree_manager();
108  std::map<unsigned int, tree_nodeRef> var_substitution_table;
109  std::map<unsigned int, CustomOrderedSet<tree_nodeRef>> stmt_to_be_removed;
110 
112  auto* fd = GetPointer<function_decl>(temp);
113  auto* sl = GetPointer<statement_list>(GET_NODE(fd->body));
114  const bool is_single_write_memory =
115  GetPointer<const HLS_manager>(AppM) and GetPointer<const HLS_manager>(AppM)->IsSingleWriteMemory();
116 
117  for(const auto& block : sl->list_of_bloc)
118  {
119  const auto curr_bb = block.first;
120  if(curr_bb == bloc::ENTRY_BLOCK_ID)
121  {
122  continue;
123  }
124  if(curr_bb == bloc::EXIT_BLOCK_ID)
125  {
126  continue;
127  }
128  for(const auto& stmt : block.second->CGetStmtList())
129  {
131  tree_nodeRef tn = GET_NODE(stmt);
132  auto* ga = GetPointer<gimple_assign>(tn);
133  if(!ga || !ga->clobber)
134  {
135  continue;
136  }
137  if(is_single_write_memory)
138  {
139  var_substitution_table[GET_INDEX_NODE(ga->memdef)] = ga->memuse;
140  }
141  stmt_to_be_removed[curr_bb].insert(stmt);
142  }
143  }
144 
145  if(is_single_write_memory)
146  {
148  for(const auto& block : sl->list_of_bloc)
149  {
150  const auto curr_bb = block.first;
151  if(curr_bb == bloc::ENTRY_BLOCK_ID)
152  {
153  continue;
154  }
155  if(curr_bb == bloc::EXIT_BLOCK_ID)
156  {
157  continue;
158  }
159  for(const auto& phi : block.second->CGetPhiList())
160  {
161  auto* gp = GetPointer<gimple_phi>(GET_NODE(phi));
162  if(gp->virtual_flag)
163  {
164  for(const auto& def_edge : gp->CGetDefEdgesList())
165  {
166  if(var_substitution_table.find(GET_INDEX_NODE(def_edge.first)) != var_substitution_table.end())
167  {
168  tree_nodeRef res = var_substitution_table.find(GET_INDEX_NODE(def_edge.first))->second;
169  while(var_substitution_table.find(GET_INDEX_NODE(res)) != var_substitution_table.end())
170  {
171  res = var_substitution_table.find(GET_INDEX_NODE(res))->second;
172  }
173  THROW_ASSERT(
174  !(GetPointer<ssa_name>(GET_NODE(res)) &&
175  GetPointer<gimple_assign>(GET_NODE(GetPointer<ssa_name>(GET_NODE(res))->CGetDefStmt())) &&
176  GetPointer<gimple_assign>(GET_NODE(GetPointer<ssa_name>(GET_NODE(res))->CGetDefStmt()))
177  ->clobber),
178  "unexpected condition");
179  gp->ReplaceDefEdge(TM, def_edge,
180  gimple_phi::DefEdge(TM->GetTreeReindex(GET_INDEX_NODE(res)), def_edge.second));
181  }
182  }
183  }
184  }
185  for(const auto& stmt : block.second->CGetStmtList())
186  {
188  tree_nodeRef tn = GET_NODE(stmt);
189  auto* gn = GetPointer<gimple_node>(tn);
190  THROW_ASSERT(gn, "unexpected condition");
191  if(!gn->memuse)
192  {
193  continue;
194  }
195  if(var_substitution_table.find(GET_INDEX_NODE(gn->memuse)) != var_substitution_table.end())
196  {
197  gn->memuse =
198  TM->GetTreeReindex(GET_INDEX_NODE(var_substitution_table.find(GET_INDEX_NODE(gn->memuse))->second));
199  }
200  }
201  }
202  }
203 
205  const auto stbr_it_end = stmt_to_be_removed.end();
206  for(auto stbr_it = stmt_to_be_removed.begin(); stbr_it != stbr_it_end; ++stbr_it)
207  {
208  unsigned int curr_bb = stbr_it->first;
209  for(const auto& to_be_removed : stbr_it->second)
210  {
211  sl->list_of_bloc[curr_bb]->RemoveStmt(to_be_removed, AppM);
212  }
213  }
214 
215  function_behavior->UpdateBBVersion();
217 }
#define GET_NODE(t)
Macro used to hide implementation details when accessing a tree_node from another tree_node...
Definition: tree_node.hpp:343
Analysis step that removes clobber gimple_assign introduced by GCC v4.7 and greater.
Data structure representing the entire HLS information.
File containing functions and utilities to support the printing of debug messagges.
#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.
remove_clobber_ga(const application_managerRef AppM, unsigned int function_id, const DesignFlowManagerConstRef design_flow_manager, const ParameterConstRef parameters)
Constructor.
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.
static const unsigned int EXIT_BLOCK_ID
constant identifying the exit basic block
#define GET_INDEX_NODE(t)
Macro used to hide implementation details when accessing a tree_node from another tree_node...
Definition: tree_node.hpp:361
Data structure describing a basic block at tree level.
Auxiliary methods for manipulating string.
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
std::pair< tree_nodeRef, unsigned int > DefEdge
The type of the def edge.
Definition: tree_node.hpp:3750
tree_nodeRef GetTreeReindex(const unsigned int i)
Return a tree_reindex wrapping the i-th tree_node.
Classes specification of the tree_node data structures.
DesignFlowStep_Status
The status of a step.
#define DEBUG_LEVEL_NONE
no debugging print is performed.
~remove_clobber_ga() override
Destructor.
This struct specifies the block node.
Definition: tree_node.hpp:1820
This file collects some utility functions.
const unsigned int function_id
The index of the function to be analyzed.
const application_managerRef AppM
The application manager.
Class specification of the tree_reindex support class.
static const unsigned int ENTRY_BLOCK_ID
constant identifying the entry basic block
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.
Class specification of the manager of the tree structures extracted from the raw file.
HLS specialization of generic_device.
A brief description of the C++ Header File.
DesignFlowStep_Status InternalExec() override
Updates the tree to have a more compliant CFG.
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:52 for PandA-2024.02 by doxygen 1.8.13