PandA-2024.02
soft_float_cg_ext.hpp
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  */
41 #ifndef SOFT_FLOAT_CG_EXT_HPP
42 #define SOFT_FLOAT_CG_EXT_HPP
43 
46 
47 #include "bit_lattice.hpp"
48 #include "call_graph.hpp"
49 #include "function_behavior.hpp"
50 #include "tree_node.hpp"
51 
53 #include "custom_map.hpp"
54 #include "custom_set.hpp"
55 #include "refcount.hpp"
56 #include "string_manipulation.hpp"
57 #include <array>
58 #include <tuple>
59 #include <vector>
60 
72 
77 {
78  private:
81 
84 
85  static bool inline_math;
86  static bool inline_conversion;
91 
92  static bool lowering_needed(const ssa_name* ssa);
93 
95  {
96  INTERFACE_TYPE_NONE = 0, // Cast rename not needed
97  INTERFACE_TYPE_INPUT = 1, // Cast rename after definition may be required
98  INTERFACE_TYPE_OUTPUT = 2, // Cast rename before usage may be required
99  INTERFACE_TYPE_REAL = 4 // Floating-point type must be persisted
100  };
101 
104 
107 
110 
113  std::vector<tree_nodeRef> topReturn;
115  std::vector<tree_nodeRef> paramBinding;
116 
117  FunctionVersionRef _version;
118 
121 
122  // Real type variables to be aliased as integer type variables {ssa_name, internal_type}
124 
125  // Real to integer view convert statements to be converted into nop statements
126  std::vector<tree_nodeRef> nopConvert;
127 
130 
133 
136 
138  std::vector<ssa_name*> hwReturn;
139 
140  tree_nodeRef int_type_for(const tree_nodeRef& type, bool use_internal) const;
141 
142  bool signature_lowering(function_decl* f_decl) const;
143 
144  void ssa_lowering(ssa_name* ssa, bool internal_type) const;
145 
157  void replaceWithCall(const FloatFormatRef& specFF, const std::string& fu_name, std::vector<tree_nodeRef> args,
158  const tree_nodeRef& current_statement, const tree_nodeRef& current_tree_node,
159  const std::string& current_scrp);
160 
168  bool RecursiveExaminate(const tree_nodeRef& current_statement, const tree_nodeRef& current_tree_node,
169  int castRename);
170 
181  tree_nodeRef generate_interface(const blocRef& bb, tree_nodeRef stmt, const tree_nodeRef& ssa, FloatFormatRef inFF,
182  FloatFormatRef outFF) const;
183 
191  tree_nodeRef cstCast(uint64_t in, const FloatFormatRef& inFF, const FloatFormatRef& outFF) const;
192 
199  tree_nodeRef floatNegate(const tree_nodeRef& op, const FloatFormatRef& ff) const;
200 
207  tree_nodeRef floatAbs(const tree_nodeRef& op, const FloatFormatRef& ff) const;
208 
214  ComputeFrontendRelationships(const DesignFlowStep::RelationshipType relationship_type) const override;
215 
216  public:
224  soft_float_cg_ext(const ParameterConstRef _parameters, const application_managerRef AppM, unsigned int _function_id,
225  const DesignFlowManagerConstRef design_flow_manager);
226 
230  ~soft_float_cg_ext() override;
231 
236 
237  bool HasToBeExecuted() const override;
238 };
239 
241 {
242  public:
244  {
245  FPRounding_Truncate = 0,
246  FPRounding_NearestEven = 1
247  };
248 
250  {
251  FPException_Overflow = 0,
252  FPException_IEEE = 1,
253  FPException_Saturation = 2
254  };
255 
256  uint8_t exp_bits;
257  uint8_t frac_bits;
258  int32_t exp_bias;
261  bool has_one;
264 
265  FloatFormat(uint8_t _exp_bits, uint8_t _frac_bits, int32_t _exp_bias,
266  FPRounding _rounding_mode = FPRounding_NearestEven, FPException _exception_mode = FPException_IEEE,
267  bool _has_one = true, bool _has_subnorm = false, bit_lattice _sign = bit_lattice::U);
268 
269  bool operator==(const FloatFormat& other) const;
270 
271  bool operator!=(const FloatFormat& other) const;
272 
273  bool ieee_format() const;
274 
275  std::string ToString() const;
276 
277  static FloatFormatRef FromString(std::string ff_str);
278 };
279 
281 {
282  public:
283  // Id of reference function
284  const CallGraph::vertex_descriptor function_vertex;
285 
286  // Float format required from the user
287  FloatFormatRef userRequired;
288 
289  // Contains callers function versions'
290  std::vector<FunctionVersionRef> callers;
291 
292  // True if all caller functions share this function float format or if this is a standard ieee format function
293  bool internal;
294 
295  FunctionVersion();
296 
297  FunctionVersion(CallGraph::vertex_descriptor func_v, const FloatFormatRef& userFormat = nullptr);
298 
299  FunctionVersion(const FunctionVersion& other);
300 
301  ~FunctionVersion();
302 
303  int compare(const FunctionVersion& other, bool format_only = false) const;
304 
305  bool operator==(const FunctionVersion& other) const;
306 
307  bool operator!=(const FunctionVersion& other) const;
308 
309  bool ieee_format() const;
310 
311  std::string ToString() const;
312 };
313 
314 #endif
static bool lowering_needed(const ssa_name *ssa)
tree_nodeRef generate_interface(const blocRef &bb, tree_nodeRef stmt, const tree_nodeRef &ssa, FloatFormatRef inFF, FloatFormatRef outFF) const
Generate necessary statements to convert ssa variable from inFF to outFF and insert them after stmt i...
tree_nodeRef floatNegate(const tree_nodeRef &op, const FloatFormatRef &ff) const
Generate float negate operation based on given floating-point format.
static tree_nodeRef float64_type
CustomMap< ssa_name *, std::set< unsigned int > > hwParam
Hardware implemented functions need parameters specified as real_type, thus it is necessary to add a ...
std::vector< tree_nodeRef > paramBinding
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.
const CallGraph::vertex_descriptor function_vertex
CustomMap< ssa_name *, std::tuple< FloatFormatRef, std::vector< unsigned int > > > inputInterface
SSA variable which requires cast renaming from standard to user-defined float format in all but given...
static bool inline_conversion
RelationshipType
The relationship type.
struct definition of the function_decl tree node.
Definition: tree_node.hpp:2759
This class manages the tree structures extracted from the raw file.
bool signature_lowering(function_decl *f_decl) const
CustomMap< ssa_name *, bool > viewConvert
DesignFlowStep_Status InternalExec() override
Fixes the var_decl duplication.
static tree_nodeRef float32_ptr_type
bool operator!=(const DiscrepancyOpInfo &a, const DiscrepancyOpInfo &b)
CustomOrderedMap< T, U > CustomMap
Definition: custom_map.hpp:167
bit_lattice sign
bool RecursiveExaminate(const tree_nodeRef &current_statement, const tree_nodeRef &current_tree_node, int castRename)
Recursive examine tree node.
void ssa_lowering(ssa_name *ssa, bool internal_type) const
This class contains the base representation for a generic frontend flow step which works on a single ...
static CustomMap< CallGraph::vertex_descriptor, FunctionVersionRef > funcFF
Floating-point function version map.
redefinition of map to manage ordered/unordered structures
FPException exception_mode
Abstract pure class for the tree structure.
Definition: tree_node.hpp:139
Auxiliary methods for manipulating string.
void replaceWithCall(const FloatFormatRef &specFF, const std::string &fu_name, std::vector< tree_nodeRef > args, const tree_nodeRef &current_statement, const tree_nodeRef &current_tree_node, const std::string &current_scrp)
Replace current_tree_node with a call_expr to fu_name function specialized with specFF fp format in c...
std::string ToString(ActorGraphBackend_Type actor_graph_backend_type)
Header include.
soft_float_cg_ext(const ParameterConstRef _parameters, const application_managerRef AppM, unsigned int _function_id, const DesignFlowManagerConstRef design_flow_manager)
Constructor.
CustomMap< ssa_name *, std::tuple< FloatFormatRef, std::vector< tree_nodeRef > > > outputInterface
SSA variable which requires cast renaming from user-defined to standard float format in given stateme...
tree_nodeRef floatAbs(const tree_nodeRef &op, const FloatFormatRef &ff) const
Generate float absolute value operation based on given floating-point format.
FloatFormatRef userRequired
static tree_nodeRef float64_ptr_type
redefinition of set to manage ordered/unordered structures
~soft_float_cg_ext() override
Destructor.
tree_nodeRef int_type_for(const tree_nodeRef &type, bool use_internal) const
const Wrefcount< const DesignFlowManager > design_flow_manager
The design flow manager.
FPRounding rounding_mode
Classes specification of the tree_node data structures.
bit_lattice
Definition: bit_lattice.hpp:60
DesignFlowStep_Status
The status of a step.
CustomUnorderedSet< unsigned int > already_visited
Already visited tree node (used to avoid infinite recursion)
Call graph hierarchy.
tree_nodeRef cstCast(uint64_t in, const FloatFormatRef &inFF, const FloatFormatRef &outFF) const
Cast real type constant from inFF to outFF format.
std::vector< tree_nodeRef > topReturn
static tree_nodeRef float32_type
Template definition of refcount.
bool operator==(const DiscrepancyOpInfo &a, const DiscrepancyOpInfo &b)
const tree_managerRef TreeM
Tree manager.
std::vector< tree_nodeRef > nopConvert
const application_managerRef AppM
The application manager.
FunctionVersionRef _version
std::vector< ssa_name * > hwReturn
Hardware implemented functions return values as real_type, thus a view_convert is necessary...
bool HasToBeExecuted() const override
Check if this step has actually to be executed.
This struct specifies the ssa_name node.
Definition: tree_node.hpp:4523
REF_FORWARD_DECL(FloatFormat)
Add to the call graph the function calls associated with the floating point primitive operations...
static CustomMap< unsigned int, std::array< tree_nodeRef, 8 > > versioning_args
Static arguments list to feed specialization parameters of versioned functions.
std::vector< FunctionVersionRef > callers
This class creates a layer to add nodes and to manipulate the tree_nodes manager. ...
const tree_manipulationRef tree_man
tree manipulation
A brief description of the C++ Header File.

Generated on Mon Feb 12 2024 13:02:52 for PandA-2024.02 by doxygen 1.8.13