PandA-2024.02
find_max_transformations.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) 2016-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 "Parameter.hpp" // for Parameter, OPT_output_tem...
43 #include "dbgPrintHelper.hpp" // for INDENT_OUT_MEX, OUTPUT_LE...
44 #include "exceptions.hpp" // for IsError, THROW_ASSERT
45 #include "fileIO.hpp" // for PandaSystem
46 #include "hash_helper.hpp" // for hash
47 #include "string_manipulation.hpp" // for STR GET_CLASS
48 #include <filesystem> // for create_directory, exists
49 
51  const DesignFlowManagerConstRef _design_flow_manager,
52  const ParameterConstRef _parameters)
53  : ApplicationFrontendFlowStep(_AppM, FrontendFlowStepType::FIND_MAX_TRANSFORMATIONS, _design_flow_manager,
54  _parameters)
55 {
56  debug_level = parameters->get_class_debug_level(GET_CLASS(*this));
57 }
58 
60 
63 {
65 }
66 
67 const std::string FindMaxTransformations::ComputeArgString(const size_t max_transformations) const
68 {
69  const auto argv = parameters->CGetArgv();
70  std::string arg_string;
71  for(const auto& arg : argv)
72  {
74  if(arg_string == "")
75  {
76  THROW_ASSERT(arg.size() and arg[0] == '/', "Relative path executable not supported " + arg);
77  arg_string += arg;
78  }
79  else
80  {
81  arg_string += " ";
82  if(arg.find("--max-transformations") == std::string::npos and
83  arg.find("--find-max-transformations") == std::string::npos)
84  {
85  arg_string += arg;
86  }
87  }
88  }
89  arg_string += " --max-transformations=" + STR(max_transformations);
90  return arg_string;
91 }
92 
93 bool FindMaxTransformations::ExecuteBambu(const size_t max_transformations) const
94 {
96  "-->Executing with max transformations " + STR(max_transformations));
97  const auto arg_string = ComputeArgString(max_transformations);
98  const auto temp_directory = parameters->getOption<std::string>(OPT_output_temporary_directory);
99  const auto new_directory = temp_directory + "/" + STR(max_transformations);
100  if(std::filesystem::exists(new_directory))
101  {
102  std::filesystem::remove_all(new_directory);
103  }
104  std::filesystem::create_directory(new_directory);
105  const auto ret = PandaSystem(parameters, "cd " + new_directory + "; " + arg_string, false,
106  new_directory + "/bambu_execution_output");
107  std::filesystem::remove_all(new_directory);
108  if(IsError(ret))
109  {
111  return false;
112  }
113  else
114  {
116  return true;
117  }
118 }
119 
121 {
122  size_t correct_cmt = 1;
123  size_t wrong_cmt = 0;
124  if(parameters->IsParameter("wrong-transformation"))
125  {
126  wrong_cmt = parameters->GetParameter<unsigned int>("wrong-transformation");
127  }
128  if(parameters->IsParameter("correct-transformation"))
129  {
130  correct_cmt = parameters->GetParameter<unsigned int>("correct-transformation");
131  }
132 
133  if(!wrong_cmt)
134  {
136  const auto zero_execution = ExecuteBambu(0);
137  if(not zero_execution)
138  {
139  INDENT_OUT_MEX(0, 0, "Bambu fails with --max-transformations=0");
141  }
142  INDENT_OUT_MEX(OUTPUT_LEVEL_MINIMUM, output_level, "-->Looking for upper bound of max transformations");
143 
144  while(ExecuteBambu(correct_cmt))
145  {
146  correct_cmt *= 2;
147  }
148  INDENT_OUT_MEX(OUTPUT_LEVEL_MINIMUM, output_level, "<--Upper bound is " + STR(correct_cmt));
149  wrong_cmt = correct_cmt;
150  correct_cmt = wrong_cmt / 2;
151  }
152  while(wrong_cmt - correct_cmt > 1)
153  {
155  "---Current range is [" + STR(correct_cmt) + ":" + STR(wrong_cmt) + "]");
156  size_t middle_cmt = (wrong_cmt + correct_cmt) / 2;
157  const auto middle_execution = ExecuteBambu(middle_cmt);
158  if(middle_execution)
159  {
160  correct_cmt = middle_cmt;
161  }
162  else
163  {
164  wrong_cmt = middle_cmt;
165  }
166  }
167  INDENT_OUT_MEX(OUTPUT_LEVEL_MINIMUM, output_level, "---Error occours at " + STR(wrong_cmt) + " transformation");
169 }
#define DEBUG_LEVEL_VERY_PEDANTIC
extremely verbose debugging print is performed.
#define INDENT_DBG_MEX(dbgLevel, curDbgLevel, mex)
We are producing a debug version of the program, so the message is printed;.
~FindMaxTransformations() override
Destructor.
File containing functions and utilities to support the printing of debug messagges.
bool ExecuteBambu(const size_t max_transformations) const
Execute bambu with max-transformations.
#define GET_CLASS(obj)
Macro returning the actual type of an object.
const int output_level
The output level.
RelationshipType
The relationship type.
#define INDENT_OUT_MEX(outLevel, curOutLevel, mex)
DesignFlowStep_Status Exec() override
Performs the profiling step.
exceptions managed by PandA
#define OUTPUT_LEVEL_MINIMUM
minimum debugging print is performed.
const std::string ComputeArgString(const size_t max_transformations) const
Compute the arg list string of bambu.
#define STR(s)
Macro which performs a lexical_cast to a string.
Auxiliary methods for manipulating string.
bool IsError(const int error_value)
Utility include.
Definition: exceptions.cpp:58
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.
utility function used to read files.
const ParameterConstRef parameters
Set of input parameters.
DesignFlowStep_Status
The status of a step.
enum FrontendFlowStepType { CREATE_TREE_MANAGER, FIND_MAX_TRANSFORMATIONS, FUNCTION_ANALYSIS, SYMBOLIC_APPLICATION_FRONTEND_FLOW_STEP, ADD_BB_ECFG_EDGES, ADD_ARTIFICIAL_CALL_FLOW_EDGES, ADD_OP_EXIT_FLOW_EDGES, ADD_OP_LOOP_FLOW_EDGES, ADD_OP_PHI_FLOW_EDGES, BAMBU_FRONTEND_FLOW, BASIC_BLOCKS_CFG_COMPUTATION, BB_CONTROL_DEPENDENCE_COMPUTATION, BB_FEEDBACK_EDGES_IDENTIFICATION, BB_ORDER_COMPUTATION, BB_REACHABILITY_COMPUTATION, BIT_VALUE, BIT_VALUE_OPT, BITVALUE_RANGE, BIT_VALUE_IPA, BLOCK_FIX, BUILD_VIRTUAL_PHI, CALL_EXPR_FIX, CALL_GRAPH_BUILTIN_CALL, CHECK_SYSTEM_TYPE, COMPLETE_BB_GRAPH, COMPLETE_CALL_GRAPH, COMPUTE_IMPLICIT_CALLS, COMMUTATIVE_EXPR_RESTRUCTURING, COND_EXPR_RESTRUCTURING, CSE_STEP, DATAFLOW_CG_EXT, DEAD_CODE_ELIMINATION, DEAD_CODE_ELIMINATION_IPA, DETERMINE_MEMORY_ACCESSES, DOM_POST_DOM_COMPUTATION, EXTRACT_GIMPLE_COND_OP, EXTRACT_PATTERNS, FIX_STRUCTS_PASSED_BY_VALUE, FUNCTION_CALL_TYPE_CLEANUP, FUNCTION_CALL_OPT, FANOUT_OPT, FIX_VDEF, HDL_FUNCTION_DECL_FIX, HDL_VAR_DECL_FIX, HLS_DIV_CG_EXT, HWCALL_INJECTION, INTERFACE_INFER, IR_LOWERING, LOOP_COMPUTATION, LOOPS_ANALYSIS_BAMBU, LOOPS_COMPUTATION, LUT_TRANSFORMATION, MULTI_WAY_IF, MULTIPLE_ENTRY_IF_REDUCTION, NI_SSA_LIVENESS, OP_CONTROL_DEPENDENCE_COMPUTATION, OP_FEEDBACK_EDGES_IDENTIFICATION, OP_ORDER_COMPUTATION, OP_REACHABILITY_COMPUTATION, OPERATIONS_CFG_COMPUTATION, PARM2SSA, PARM_DECL_TAKEN_ADDRESS, PHI_OPT, PREDICATE_STATEMENTS, ESSA, RANGE_ANALYSIS, REBUILD_INITIALIZATION, REBUILD_INITIALIZATION2, REMOVE_CLOBBER_GA, REMOVE_ENDING_IF, SCALAR_SSA_DATA_FLOW_ANALYSIS, SERIALIZE_MUTUAL_EXCLUSIONS, SPLIT_RETURN, SHORT_CIRCUIT_TAF, SIMPLE_CODE_MOTION, SOFT_FLOAT_CG_EXT, STRING_CST_FIX, SWITCH_FIX, UN_COMPARISON_LOWERING, UNROLLING_DEGREE, USE_COUNTING, VAR_ANALYSIS, VAR_DECL_FIX, VECTORIZE, VERIFICATION_OPERATION, VIRTUAL_AGGREGATE_DATA_FLOW_ANALYSIS, VIRTUAL_PHI_NODES_SPLIT } FrontendFlowStepType
FindMaxTransformations(const application_managerRef AppM, const DesignFlowManagerConstRef design_flow_manager, const ParameterConstRef parameters)
Constructor.
int PandaSystem(const ParameterConstRef Param, const std::string &system_command, bool host_exec, const std::string &output, const unsigned int type, const bool background, const size_t timeout)
System call forcing execution with bash.
Definition: fileIO.cpp:78
This file collects some hash functors.
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.
Analysis step to find transformation which breaks synthesis flow by launching bambu with different va...
#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:51 for PandA-2024.02 by doxygen 1.8.13