PandA-2024.02
basic_blocks_profiling_c_writer.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) 2015-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 
43 #include "Parameter.hpp"
44 #include "basic_block.hpp"
45 #include "behavioral_helper.hpp"
46 #include "function_behavior.hpp"
47 #include "hls_manager.hpp"
50 #include "string_manipulation.hpp"
51 #include "tree_basic_block.hpp"
52 #include "tree_manager.hpp"
53 #include "tree_node.hpp"
54 #include "tree_reindex.hpp"
55 
57  const InstructionWriterRef _instruction_writer,
58  const IndentedOutputStreamRef _indented_output_stream,
59  const ParameterConstRef _Param, bool _verbose)
60  : EdgeCWriter(_HLSMgr, _instruction_writer, _indented_output_stream, _Param, _verbose)
61 {
62  debug_level = _Param->get_class_debug_level(GET_CLASS(*this));
63 }
64 
66 
68 {
69  print_edge(e, 0);
70 }
71 
73 {
74  print_edge(e, 0);
75 }
76 
78 {
79  print_edge(e, 0);
80 }
81 
83 {
84  const auto target_id = support_cfg->CGetBBNodeInfo(boost::target(e, *support_cfg))->block->number;
85  const auto function_name = HLSMgr->CGetFunctionBehavior(fun_id)->CGetBehavioralHelper()->get_function_name();
86  indented_output_stream->Append(function_name + "_counter[" + STR(target_id) + "]++;\n");
87  dumped_edges.insert(e);
88 }
89 
91 {
92  print_edge(e, 0);
93 }
94 
96 {
98  indented_output_stream->Append("#include <stdlib.h>\n");
99  indented_output_stream->Append("#include <stdio.h>\n");
101  CustomOrderedSet<unsigned int> functions = HLSMgr->get_functions_with_body();
102  for(const auto function : functions)
103  {
104  const auto function_behavior = HLSMgr->CGetFunctionBehavior(function);
105  const auto function_name = function_behavior->CGetBehavioralHelper()->get_function_name();
106  const auto fd = GetPointer<const function_decl>(TM->CGetTreeNode(function));
107  const auto sl = GetPointer<statement_list>(GET_CONST_NODE(fd->body));
108  const auto biggest_bb_number = sl->list_of_bloc.rbegin()->first;
109  indented_output_stream->Append("int " + function_name + "_counter[" + STR(biggest_bb_number + 1) + "];\n");
110  }
111  indented_output_stream->Append("void _init_tp() __attribute__ ((no_instrument_function, constructor));\n");
112  indented_output_stream->Append("void _init_tp()\n");
114  indented_output_stream->Append("int i = 0;\n");
115  for(const auto function : functions)
116  {
117  const auto function_behavior = HLSMgr->CGetFunctionBehavior(function);
118  const auto function_name = function_behavior->CGetBehavioralHelper()->get_function_name();
119  const auto fd = GetPointer<const function_decl>(TM->CGetTreeNode(function));
120  const auto sl = GetPointer<statement_list>(GET_NODE(fd->body));
121  const auto biggest_bb_number = sl->list_of_bloc.rbegin()->first;
122  indented_output_stream->Append("for(i = 0; i < " + STR(biggest_bb_number + 1) + "; i++)\n");
123  indented_output_stream->Append(" " + function_name + "_counter[i] = 0;\n");
124  }
126  indented_output_stream->Append("void _end_tp() __attribute__ ((no_instrument_function, destructor));\n");
127  indented_output_stream->Append("void _end_tp()\n");
129  indented_output_stream->Append("FILE* h_file = fopen(\"" +
130  Param->getOption<std::string>(OPT_output_temporary_directory) +
131  STR_CST_host_profiling_data + "\", \"w\");\n");
132  indented_output_stream->Append("int i = 0;\n");
133  for(const auto function : functions)
134  {
135  const auto function_behavior = HLSMgr->CGetFunctionBehavior(function);
136  const auto function_name = function_behavior->CGetBehavioralHelper()->get_function_name();
137  const auto fd = GetPointer<const function_decl>(TM->CGetTreeNode(function));
138  const auto sl = GetPointer<statement_list>(GET_NODE(fd->body));
139  const auto biggest_bb_number = sl->list_of_bloc.rbegin()->first;
140  indented_output_stream->Append(R"(fprintf(h_file, "Function %d\n", )" + STR(function) + ");\n");
141  indented_output_stream->Append("for(i = 0; i < " + STR(biggest_bb_number + 1) + "; i++)\n");
142  indented_output_stream->Append(R"( fprintf(h_file, "%d %d\n", i, )" + function_name + "_counter[i]);\n");
143  }
144  indented_output_stream->Append("fclose(h_file);\n");
145 
147 }
#define GET_NODE(t)
Macro used to hide implementation details when accessing a tree_node from another tree_node...
Definition: tree_node.hpp:343
Data structure representing the entire HLS information.
string target
Definition: lenet_tvm.py:16
#define GET_CLASS(obj)
Macro returning the actual type of an object.
int debug_level
the debug level
Definition: c_writer.hpp:122
constants used in host profiling library
#define STR_CST_host_profiling_data
The file where profiling data are written by instrumented executable.
void print_loop_switching(EdgeDescriptor e) override
Print operation requested for record information about a path which exit from a loop and immediately ...
unsigned int fun_id
Index of the current function.
Class to print indented code.
BBGraphConstRef support_cfg
Special control flow graphs.
const tree_managerConstRef TM
The tree manager.
Definition: c_writer.hpp:98
Data structure describing a basic block at tree level.
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.
void WriteGlobalDeclarations() final
Writes the global declarations.
Class use to write the C code with instrumented edges.
const IndentedOutputStreamRef indented_output_stream
Represents the stream we are currently writing to.
Definition: c_writer.hpp:101
void print_loop_starting(EdgeDescriptor e) override
Dump initializations of variable for recording a loop path.
void print_loop_ending(EdgeDescriptor e) override
Dump operations requested for record information about a loop path which ends.
const ParameterConstRef Param
set of parameters
Definition: c_writer.hpp:119
void Append(const std::string &str)
Append a string to the output.
This file contains the routines necessary to create a C executable program with instrumented edges fo...
#define GET_CONST_NODE(t)
Definition: tree_node.hpp:347
Classes specification of the tree_node data structures.
BasicBlocksProfilingCWriter(const HLS_managerConstRef _HLSMgr, const InstructionWriterRef instruction_writer, const IndentedOutputStreamRef indented_output_stream, const ParameterConstRef Param, bool verbose=true)
Constructor of the class.
void print_edge(EdgeDescriptor e, unsigned int index) override
Dump operation requested for instrument an edges.
std::set< EdgeDescriptor, ltedge< BBGraph > > dumped_edges
Set of already dumped edges.
const HLS_managerConstRef HLSMgr
the hls manager
Definition: c_writer.hpp:95
Class specification of the tree_reindex support class.
Class specification of the basic_block structure.
const BBNodeInfoConstRef CGetBBNodeInfo(const vertex node) const
Return the info associated with a 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.
virtual void WriteGlobalDeclarations()
Writes the global declarations.
Definition: c_writer.cpp:307
void print_loop_escaping(EdgeDescriptor e) override
Dump operations requested for record information about a path which exit from a loop.
Class specification of the manager of the tree structures extracted from the raw file.
A brief description of the C++ Header File.
int sl
Definition: adpcm.c:105
boost::graph_traits< graph >::edge_descriptor EdgeDescriptor
edge definition.
Definition: graph.hpp:1316

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