PandA-2024.02
compatibility_based_register.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  */
44 
45 #include "hls.hpp"
46 
47 #include "liveness.hpp"
48 
49 #include "Parameter.hpp"
50 #include "dbgPrintHelper.hpp"
51 
52 #if BOOST_VERSION >= 106400
53 #include <boost/serialization/array_wrapper.hpp>
54 #endif
55 #include <boost/numeric/ublas/matrix.hpp>
56 
59 
61  const ParameterConstRef _Param, const HLS_managerRef _HLSMgr, unsigned int _funId,
62  const DesignFlowManagerConstRef _design_flow_manager, const HLSFlowStep_Type _hls_flow_step_type,
63  const HLSFlowStepSpecializationConstRef _hls_flow_step_specialization)
64  : reg_binding_creator(_Param, _HLSMgr, _funId, _design_flow_manager, _hls_flow_step_type,
65  _hls_flow_step_specialization),
66  CG(nullptr)
67 {
68 }
69 
71 
73 {
74  verts.clear();
75  THROW_ASSERT(HLS->Rliv, "Liveness analysis not yet computed");
76  const auto CG_num_vertices = HLS->storage_value_information->get_number_of_storage_values();
77  CG = new compatibility_graph(CG_num_vertices);
78  boost::numeric::ublas::matrix<bool> conflict_map(CG_num_vertices, CG_num_vertices);
79 
80  boost::numeric::ublas::noalias(conflict_map) =
81  boost::numeric::ublas::zero_matrix<bool>(CG_num_vertices, CG_num_vertices);
82  for(auto vi = 0U; vi < CG_num_vertices; ++vi)
83  {
84  verts.push_back(boost::vertex(vi, *CG));
85  }
86 
88  const auto& support = HLS->Rliv->get_support();
89  for(const auto v : support)
90  {
91  const auto& live = HLS->Rliv->get_live_in(v);
92  register_lower_bound = std::max(static_cast<unsigned int>(live.size()), register_lower_bound);
93  const auto k_end = live.cend();
94  for(auto k = live.cbegin(); k != k_end; ++k)
95  {
96  auto k_inner = k;
97  ++k_inner;
98  while(k_inner != k_end)
99  {
100  const auto tail = HLS->storage_value_information->get_storage_value_index(v, *k);
101  THROW_ASSERT(tail < CG_num_vertices, "wrong compatibility graph index");
102  const auto head = HLS->storage_value_information->get_storage_value_index(v, *k_inner);
103  THROW_ASSERT(head < CG_num_vertices, "wrong compatibility graph index");
104  if(tail < head)
105  {
106  conflict_map(tail, head) = true;
107  }
108  else if(tail > head)
109  {
110  conflict_map(head, tail) = true;
111  }
112  ++k_inner;
113  }
114  }
115  }
116  for(auto vj = 1U; vj < CG_num_vertices; ++vj)
117  {
118  for(auto vi = 0U; vi < vj; ++vi)
119  {
120  if(!conflict_map(vi, vj) && HLS->storage_value_information->are_value_bitsize_compatible(vi, vj))
121  {
122  boost::graph_traits<compatibility_graph>::edge_descriptor e1;
123  const auto edge_weight = HLS->storage_value_information->get_compatibility_weight(vi, vj);
125  if(edge_weight > 1)
126  {
127  bool in1;
128  boost::tie(e1, in1) =
129  boost::add_edge(verts[vi], verts[vj], edge_compatibility_property(edge_weight), *CG);
130  THROW_ASSERT(in1, "unable to add edge");
131  }
132  }
133  }
134  }
135 }
136 
137 bool compatibility_based_register::is_compatible(unsigned int sv1, unsigned int sv2) const
138 {
139  std::pair<boost::graph_traits<compatibility_graph>::edge_descriptor, bool> edge =
140  boost::edge(verts[sv1], verts[sv2], *CG);
141  return edge.second;
142 }
Class specification to contain liveness information.
int get_compatibility_weight(unsigned int storage_value_index1, unsigned int storage_value_index2) const
return a weight that estimate how much two storage values are compatible.
File containing functions and utilities to support the printing of debug messagges.
compatibility_graph * CG
compatibility graph
std::vector< CG_vertex_descriptor > verts
ordered vector containing the vertices of the compatibility graph
#define max
Definition: backprop.h:17
bool are_value_bitsize_compatible(unsigned int storage_value_index1, unsigned int storage_value_index2) const
return the in case the storage values have compatible size
boost::adjacency_matrix< boost::undirectedS, boost::no_property, edge_compatibility_property > compatibility_graph
const std::list< vertex > & get_support() const
return the support set of the live in/out
Definition: liveness.hpp:212
StorageValueInformationRef storage_value_information
data-structure for storage values
Definition: hls.hpp:130
static const uint32_t k[]
Definition: sha-256.c:22
HLSFlowStep_Type
Definition: hls_step.hpp:95
bool is_compatible(unsigned int sv1, unsigned int sv2) const
Checks if two storage values are compatible.
boost::graph_traits< graph >::vertex_descriptor vertex
vertex definition.
Definition: graph.hpp:1303
Generic class managing the different register allocation algorithms.
unsigned int register_lower_bound
lower bound
This package is used to define the storage value scheme adopted by the register allocation algorithms...
livenessRef Rliv
data-structure containing the variable liveness
Definition: hls.hpp:127
hlsRef HLS
HLS data structure of the function to be analyzed.
virtual unsigned int get_storage_value_index(vertex curr_vertex, unsigned int var_index)=0
Returns the index of the storage value associated with the variable in a given vertex.
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.
Base class specification for register allocation algorithm based on a compatibility graph...
~compatibility_based_register() override
unsigned int get_number_of_storage_values() const
Returns the number of storage values inserted.
void create_compatibility_graph()
Creates the compatibility graph.
compatibility_based_register(const ParameterConstRef Param, const HLS_managerRef HLSMgr, unsigned int funId, const DesignFlowManagerConstRef design_flow_manager, const HLSFlowStep_Type hls_flow_step_type, const HLSFlowStepSpecializationConstRef hls_flow_step_specialization=HLSFlowStepSpecializationConstRef())
Constructor.
Data structure definition for high-level synthesis flow.
const CustomOrderedSet< unsigned int > & get_live_in(const vertex &v) const
Get the set of variables live at the input of a vertex.
Definition: liveness.cpp:109
#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