PandA-2024.02
functions.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 #include "functions.hpp"
45 #include "behavioral_helper.hpp"
46 #include "constant_strings.hpp"
47 #include "exceptions.hpp"
48 #include "function_behavior.hpp"
49 #include "hls_device.hpp"
50 #include "hls_manager.hpp"
51 #include "library_manager.hpp"
52 #include "string_manipulation.hpp" //STR
53 #include "technology_manager.hpp"
54 #include "technology_node.hpp"
55 
56 #include <boost/algorithm/string/predicate.hpp>
57 
58 functions::functions() = default;
59 
60 functions::~functions() = default;
61 
62 void functions::map_shared_function(unsigned int funID_scope, const std::string& fun)
63 {
65  "function already mapped in a different scope: " + fun + "->" + STR(proxied_functions.at(fun)));
66  shared_functions[funID_scope].insert(fun);
67  proxied_functions[fun] = funID_scope;
68 }
69 
70 const CustomOrderedSet<std::string>& functions::get_shared_functions(unsigned int funID_scope) const
71 {
72  THROW_ASSERT(has_shared_functions(funID_scope), "");
73  return shared_functions.at(funID_scope);
74 }
75 
76 bool functions::has_shared_functions(unsigned int funID_scope) const
77 {
78  return shared_functions.count(funID_scope);
79 }
80 
81 bool functions::is_a_shared_function(unsigned int funID_scope, const std::string& fun) const
82 {
83  return has_shared_functions(funID_scope) && get_shared_functions(funID_scope).count(fun);
84 }
85 
86 void functions::add_shared_function_proxy(unsigned int funID_scope, const std::string& fun)
87 {
88  shared_function_proxy[funID_scope].insert(fun);
89 }
90 
92 {
93  THROW_ASSERT(has_proxied_shared_functions(funID_scope), "No proxy functions for " + STR(funID_scope));
94  return shared_function_proxy.at(funID_scope);
95 }
96 
97 bool functions::has_proxied_shared_functions(unsigned int funID_scope) const
98 {
99  return shared_function_proxy.count(funID_scope);
100 }
101 
102 bool functions::is_a_proxied_shared_function(unsigned int funID_scope, const std::string& fun) const
103 {
104  return has_proxied_shared_functions(funID_scope) && get_proxied_shared_functions(funID_scope).count(fun);
105 }
106 
107 bool functions::is_a_proxied_function(const std::string& fun) const
108 {
109  return proxied_functions.count(fun);
110 }
111 
112 unsigned int functions::get_proxy_mapping(const std::string& fun) const
113 {
114  THROW_ASSERT(is_a_proxied_function(fun), "this is not a proxy function");
115  return proxied_functions.at(fun);
116 }
117 
118 std::string functions::GetFUName(const std::string& fname, const HLS_managerRef HLSMgr)
119 {
120  const auto HLS_D = HLSMgr->get_HLS_device();
121  const auto TechM = HLS_D->get_technology_manager();
122  const auto fu_node = TechM->GetFunctionFU(fname);
123  return fu_node ? fu_node->get_name() : fname;
124 }
125 
126 std::string functions::GetFUName(unsigned int funID, const HLS_managerRef HLSMgr)
127 {
128  const auto original_function_name = HLSMgr->CGetFunctionBehavior(funID)->CGetBehavioralHelper()->get_function_name();
129  return GetFUName(original_function_name, HLSMgr);
130 }
Data structure representing the entire HLS information.
const CustomOrderedSet< std::string > & get_shared_functions(unsigned int funID_scope) const
return the set of shared functions allocated in a given function.
Definition: functions.cpp:70
bool is_a_shared_function(unsigned int funID_scope, const std::string &fun) const
return true if a given function is a shared function allocated in a given function scope ...
Definition: functions.cpp:81
exceptions managed by PandA
Class specification of the manager of the technology library data structures.
bool has_proxied_shared_functions(unsigned int funID_scope) const
check if the function has proxy shared functions
Definition: functions.cpp:97
#define STR(s)
Macro which performs a lexical_cast to a string.
Auxiliary methods for manipulating string.
const CustomOrderedSet< std::string > & get_proxied_shared_functions(unsigned int funID_scope) const
return the proxied internal functions associated with the function
Definition: functions.cpp:91
std::map< std::string, unsigned int > proxied_functions
define where the proxied functions are mapped
Definition: functions.hpp:60
functions()
Constructor.
Class specification of the data structures used to manage technology information. ...
void map_shared_function(unsigned int funID_scope, const std::string &fun)
allocate a shared function in a specified function.
Definition: functions.cpp:62
Datastructure to describe functions allocation in high-level synthesis.
static std::string GetFUName(const std::string &fname, const HLS_managerRef HLSMgr)
Return FU used to implement given function.
Definition: functions.cpp:118
virtual ~functions()
Destructor.
unsigned int get_proxy_mapping(const std::string &fun) const
in case the function is a proxy function, it returns where the function is actually instantiated ...
Definition: functions.cpp:112
bool is_a_proxied_shared_function(unsigned int funID_scope, const std::string &fun) const
return true if a given function is a shared function allocated in a given function scope ...
Definition: functions.cpp:102
void add_shared_function_proxy(unsigned int funID_scope, const std::string &fun)
allocate a proxy for the function referred within a given function
Definition: functions.cpp:86
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
bool is_a_proxied_function(const std::string &fun) const
return true if the function is a proxied function
Definition: functions.cpp:107
constant strings
Class specification of the manager for each library.
std::map< unsigned int, CustomOrderedSet< std::string > > shared_function_proxy
set of function proxies called by a function
Definition: functions.hpp:57
int fun(float *A, float *invA, float *b, float *x, float *I)
bool has_shared_functions(unsigned int funID_scope) const
return true in case there are shared functions allocated in a given function.
Definition: functions.cpp:76
std::map< unsigned int, CustomOrderedSet< std::string > > shared_functions
reverse map of proxied_functions
Definition: functions.hpp:63
HLS specialization of generic_device.
A brief description of the C++ Header File.
#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