PandA-2024.02
frontend_flow_step.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 "frontend_flow_step.hpp"
45 
46 #include "Parameter.hpp" // for Parameter, OPT_output_...
47 #include "application_frontend_flow_step.hpp" // for ApplicationFrontendFlo...
48 #include "application_manager.hpp" // for application_manager
49 #include "call_graph_manager.hpp" // for application_managerCon...
50 #include "custom_set.hpp" // for set
51 #include "design_flow_graph.hpp" // for DesignFlowGraph, Desig...
52 #include "design_flow_manager.hpp" // for DesignFlowManager, Des...
53 #include "exceptions.hpp" // for THROW_UNREACHABLE
54 #include "frontend_flow_step_factory.hpp" // for DesignFlowStepRef, Fro...
55 #include "function_frontend_flow_step.hpp" // for DesignFlowManagerConstRef
56 #include "graph.hpp" // for vertex
57 #include "hash_helper.hpp" // for hash
58 #include "string_manipulation.hpp" // for STR GET_CLASS
59 #include "tree_manager.hpp" // for tree_managerConstRef
60 
61 #include <iosfwd> // for ofstream
62 
64  const FrontendFlowStepType _frontend_flow_step_type,
65  const DesignFlowManagerConstRef _design_flow_manager,
66  const ParameterConstRef _parameters)
67  : DesignFlowStep(_design_flow_manager, _parameters),
68  AppM(_AppM),
69  frontend_flow_step_type(_frontend_flow_step_type),
70  print_counter(0)
71 {
72  debug_level = _parameters->get_class_debug_level(GET_CLASS(*this));
73 }
74 
76 
78  const DesignFlowManagerConstRef design_flow_manager,
79  const CustomUnorderedSet<std::pair<FrontendFlowStepType, FunctionRelationship>>& frontend_relationships,
81 {
82  const DesignFlowGraphConstRef design_flow_graph = design_flow_manager->CGetDesignFlowGraph();
83  const auto* frontend_flow_step_factory =
84  GetPointer<const FrontendFlowStepFactory>(design_flow_manager->CGetDesignFlowStepFactory("Frontend"));
86  frontend_relationship_end = frontend_relationships.end();
87  for(frontend_relationship = frontend_relationships.begin(); frontend_relationship != frontend_relationship_end;
88  ++frontend_relationship)
89  {
90  switch(frontend_relationship->second)
91  {
92  case(ALL_FUNCTIONS):
93  {
94  const auto call_graph_computation_step = design_flow_manager->GetDesignFlowStep(
96  const auto cg_design_flow_step =
97  call_graph_computation_step ?
98  design_flow_graph->CGetDesignFlowStepInfo(call_graph_computation_step)->design_flow_step :
99  frontend_flow_step_factory->CreateApplicationFrontendFlowStep(FUNCTION_ANALYSIS);
100  relationships.insert(cg_design_flow_step);
101  const auto functions_with_body = application_manager->CGetCallGraphManager()->GetReachedBodyFunctions();
102  for(const auto function_with_body_id : functions_with_body)
103  {
104  const auto sdf_step = design_flow_manager->GetDesignFlowStep(
105  FunctionFrontendFlowStep::ComputeSignature(frontend_relationship->first, function_with_body_id));
106  const auto design_flow_step =
107  sdf_step ? design_flow_graph->CGetDesignFlowStepInfo(sdf_step)->design_flow_step :
108  frontend_flow_step_factory->CreateFunctionFrontendFlowStep(frontend_relationship->first,
109  function_with_body_id);
110  relationships.insert(design_flow_step);
111  }
112  break;
113  }
114  case(CALLING_FUNCTIONS):
115  case(CALLED_FUNCTIONS):
116  case(SAME_FUNCTION):
117  {
119  break;
120  }
121  case(WHOLE_APPLICATION):
122  {
123  const auto sdf_signature = ApplicationFrontendFlowStep::ComputeSignature(frontend_relationship->first);
124  const auto sdf_step = design_flow_manager->GetDesignFlowStep(sdf_signature);
125  DesignFlowStepRef design_flow_step;
126  if(sdf_step)
127  {
128  design_flow_step = design_flow_graph->CGetDesignFlowStepInfo(sdf_step)->design_flow_step;
129  }
130  else
131  {
132  design_flow_step = frontend_flow_step_factory->GenerateFrontendStep(frontend_relationship->first);
133  }
134  relationships.insert(design_flow_step);
135  break;
136  }
137  default:
138  {
139  THROW_UNREACHABLE("Function relationship does not exist");
140  }
141  }
142  }
143 }
144 
146  const DesignFlowStep::RelationshipType relationship_type)
147 {
149  ComputeFrontendRelationships(relationship_type);
150  CreateSteps(design_flow_manager.lock(), frontend_relationships, AppM, relationships);
151 }
152 
153 std::string FrontendFlowStep::GetKindText() const
154 {
156 }
157 
159 {
160  switch(frontend_flow_step_type)
161  {
162  case(ADD_BB_ECFG_EDGES):
163  return "AddBbEcfgdges";
164  case ADD_ARTIFICIAL_CALL_FLOW_EDGES:
165  return "AddArtificialCallFlowEdges";
166  case(ADD_OP_EXIT_FLOW_EDGES):
167  return "AddOpExitFlowEdges";
168  case(ADD_OP_LOOP_FLOW_EDGES):
169  return "AddOpLoopFlowEdges";
170  case(ADD_OP_PHI_FLOW_EDGES):
171  return "AddOpPhiFlowEdges";
172  case(BAMBU_FRONTEND_FLOW):
173  return "BambuFrontendFlow";
174  case(BASIC_BLOCKS_CFG_COMPUTATION):
175  return "BasicBlocksCfgComputation";
176  case(BB_CONTROL_DEPENDENCE_COMPUTATION):
177  return "BBControlDependenceComputation";
178  case(BB_FEEDBACK_EDGES_IDENTIFICATION):
179  return "BBFeedbackEdgesIdentification";
180  case(BB_ORDER_COMPUTATION):
181  return "BBOrderComputation";
182 #if HAVE_HOST_PROFILING_BUILT
183  case(BASIC_BLOCKS_PROFILING):
184  return "BasicBlocksProfiling";
185 #endif
186  case(BB_REACHABILITY_COMPUTATION):
187  return "BBReachabilityComputation";
188  case(BIT_VALUE):
189  return "BitValue";
190  case(BIT_VALUE_OPT):
191  return "BitValueOpt";
192  case(BITVALUE_RANGE):
193  return "BitValueRange";
194  case BIT_VALUE_IPA:
195  return "BitValueIPA";
196  case(BLOCK_FIX):
197  return "BlockFix";
198  case BUILD_VIRTUAL_PHI:
199  return "BuildVirtualPhi";
200  case(CALL_EXPR_FIX):
201  return "CallExprFix";
202  case CALL_GRAPH_BUILTIN_CALL:
203  return "CallGraphBuiltinCall";
204  case(CHECK_SYSTEM_TYPE):
205  return "CheckSystemType";
206  case(COMPLETE_BB_GRAPH):
207  return "CompleteBBGraph";
208  case(COMPLETE_CALL_GRAPH):
209  return "CompleteCallGraph";
210  case COMPUTE_IMPLICIT_CALLS:
211  return "ComputeImplicitCalls";
212  case COMMUTATIVE_EXPR_RESTRUCTURING:
213  return "CommutativeExprRestructuring";
214  case COND_EXPR_RESTRUCTURING:
215  return "CondExprRestructuring";
216  case CSE_STEP:
217  return "CSE";
218 #if HAVE_TASTE
219  case CREATE_ADDRESS_TRANSLATION:
220  return "CreateAddressTranslation";
221 #endif
222  case(CREATE_TREE_MANAGER):
223  return "CreateTreeManager";
224  case DATAFLOW_CG_EXT:
225  return "DataflowCGExt";
226  case(DEAD_CODE_ELIMINATION):
227  return "DeadCodeElimination";
228  case(DEAD_CODE_ELIMINATION_IPA):
229  return "DeadCodeEliminationIPA";
230  case(DETERMINE_MEMORY_ACCESSES):
231  return "DetermineMemoryAccesses";
232  case(DOM_POST_DOM_COMPUTATION):
233  return "DomPostDomComputation";
234  case(FANOUT_OPT):
235  return "FanoutOpt";
236  case(MULTIPLE_ENTRY_IF_REDUCTION): // modified here
237  return "MultipleEntryIfReduction";
238  case ESSA:
239  return "eSSA";
240  case(EXTRACT_GIMPLE_COND_OP):
241  return "ExtractGimpleCondOp";
242 #if HAVE_FROM_PRAGMA_BUILT
243  case(EXTRACT_OMP_ATOMIC):
244  return "ExtractOmpAtomic";
245  case(EXTRACT_OMP_FOR):
246  return "ExtractOmpFor";
247 #endif
248  case(EXTRACT_PATTERNS):
249  return "ExtractPatterns";
250  case FIND_MAX_TRANSFORMATIONS:
251  return "FindMaxTransformations";
252  case(FUNCTION_ANALYSIS):
253  return "CallGraphComputation";
254  case FIX_STRUCTS_PASSED_BY_VALUE:
255  return "FixStructsPassedByValue";
256  case FIX_VDEF:
257  return "FixVdef";
258  case FUNCTION_CALL_TYPE_CLEANUP:
259  return "FunctionCallTypeCleanup";
260  case FUNCTION_CALL_OPT:
261  return "FunctionCallOpt";
262  case(HDL_FUNCTION_DECL_FIX):
263  return "HDLFunctionDeclFix";
264  case(HDL_VAR_DECL_FIX):
265  return "HDLVarDeclFix";
266  case(HLS_DIV_CG_EXT):
267  return "HLSDivCGExt";
268  case(HWCALL_INJECTION):
269  return "HWCallInjection";
270 #if HAVE_HOST_PROFILING_BUILT
271  case(HOST_PROFILING):
272  return "HostProfiling";
273 #endif
274  case(INTERFACE_INFER):
275  return "InterfaceInfer";
276  case(IR_LOWERING):
277  return "IrLowering";
278  case(LOOP_COMPUTATION):
279  return "LoopComputation";
280  case(LOOPS_ANALYSIS_BAMBU):
281  return "LoopsAnalysisBambu";
282  case(LOOPS_COMPUTATION):
283  return "LoopsComputation";
284  case(LUT_TRANSFORMATION):
285  return "LutTransformation";
286  case MULTI_WAY_IF:
287  return "MultiWayIf";
288  case NI_SSA_LIVENESS:
289  return "NiSsaLiveness";
290  case(OP_CONTROL_DEPENDENCE_COMPUTATION):
291  return "OpControlDependenceComputation";
292  case(OP_FEEDBACK_EDGES_IDENTIFICATION):
293  return "OpFeedbackEdgesIdentification";
294  case(OP_ORDER_COMPUTATION):
295  return "OpOrderComputation";
296  case(OP_REACHABILITY_COMPUTATION):
297  return "OpReachabilityComputation";
298  case(OPERATIONS_CFG_COMPUTATION):
299  return "OperationsCfgComputation";
300  case PARM2SSA:
301  return "Parm2SSA";
302  case PARM_DECL_TAKEN_ADDRESS:
303  return "ParmDeclTakenAddressFix";
304  case PHI_OPT:
305  return "PhiOpt";
306 #if HAVE_FROM_PRAGMA_BUILT
307  case(PRAGMA_ANALYSIS):
308  return "PragmaAnalysis";
309  case(PRAGMA_SUBSTITUTION):
310  return "PragmaSubstitution";
311 #endif
312  case PREDICATE_STATEMENTS:
313  return "PredicateStatements";
314  case RANGE_ANALYSIS:
315  return "RangeAnalysis";
316  case(REBUILD_INITIALIZATION):
317  return "RebuildInitialization";
318  case(REBUILD_INITIALIZATION2):
319  return "RebuildInitialization2";
320  case REMOVE_CLOBBER_GA:
321  return "RemoveClobberGA";
322  case REMOVE_ENDING_IF:
323  return "RemoveEndingIf";
324 #if HAVE_ILP_BUILT
325  case SDC_CODE_MOTION:
326  return "SdcCodeMotion";
327 #endif
328  case SERIALIZE_MUTUAL_EXCLUSIONS:
329  return "SerializeMutualExclusions";
330 
331  case SPLIT_RETURN:
332  return "SplitReturn";
333  case SHORT_CIRCUIT_TAF:
334  return "ShortCircuitTAF";
335  case SIMPLE_CODE_MOTION:
336  return "SimpleCodeMotion";
337  case(SOFT_FLOAT_CG_EXT):
338  return "SoftFloatCgExt";
339  case(SCALAR_SSA_DATA_FLOW_ANALYSIS):
340  return "ScalarSsaDataFlowAnalysis";
341  case(SYMBOLIC_APPLICATION_FRONTEND_FLOW_STEP):
342  return "SymbolicApplicationFrontendFlowStep";
343  case STRING_CST_FIX:
344  return "StringCstFix";
345  case(SWITCH_FIX):
346  return "SwitchFix";
347  case UN_COMPARISON_LOWERING:
348  return "UnComparisonLowering";
349  case(UNROLLING_DEGREE):
350  return "UnrollingDegree";
351 #if HAVE_ILP_BUILT
352  case UPDATE_SCHEDULE:
353  return "UpdateSchedule";
354 #endif
355  case(USE_COUNTING):
356  return "UseCounting";
357  case(VAR_ANALYSIS):
358  return "VarAnalysis";
359  case(VAR_DECL_FIX):
360  return "VarDeclFix";
361  case(VECTORIZE):
362  return "Vectorize";
363  case(VERIFICATION_OPERATION):
364  return "VerificationOperation";
365  case(VIRTUAL_AGGREGATE_DATA_FLOW_ANALYSIS):
366  return "VirtualAggregateDataFlowAnalysis";
367  case VIRTUAL_PHI_NODES_SPLIT:
368  return "VirtualPhiNodesSplit";
369  default:
370  THROW_UNREACHABLE("Frontend flow step type does not exist");
371  }
372  return "";
373 }
374 
375 DesignFlowStepFactoryConstRef FrontendFlowStep::CGetDesignFlowStepFactory() const
376 {
377  return design_flow_manager.lock()->CGetDesignFlowStepFactory("Frontend");
378 }
379 
380 void FrontendFlowStep::PrintTreeManager(const bool before) const
381 {
382  const tree_managerConstRef tree_manager = AppM->get_tree_manager();
383  const std::string prefix = before ? "before" : "after";
384  const std::string file_name =
385  parameters->getOption<std::string>(OPT_output_temporary_directory) + prefix + "_" + GetName();
386  const std::string suffix = print_counter == 0 ? "" : "_" + STR(print_counter);
387  const std::string raw_file_name = file_name + suffix + ".raw";
388  std::ofstream raw_file(raw_file_name.c_str());
389  tree_manager->print(raw_file);
390  raw_file.close();
391  const std::string gimple_file_name = file_name + ".gimple";
392  std::ofstream gimple_file(gimple_file_name.c_str());
393  tree_manager->PrintGimple(gimple_file, false);
394  gimple_file.close();
395 }
396 
398 {
399  if(!parameters->IsParameter("print-tree-manager") || parameters->GetParameter<unsigned int>("print-tree-manager"))
400  {
401  PrintTreeManager(true);
402  }
403 }
404 
406 {
407  if(!parameters->IsParameter("print-tree-manager") || parameters->GetParameter<unsigned int>("print-tree-manager"))
408  {
409  PrintTreeManager(false);
410  }
411 }
virtual const CustomUnorderedSet< std::pair< FrontendFlowStepType, FunctionRelationship > > ComputeFrontendRelationships(const DesignFlowStep::RelationshipType relationship_type) const =0
Return the set of analyses in relationship with this design step.
#define GET_CLASS(obj)
Macro returning the actual type of an object.
Definition of the class representing a generic C application.
FrontendFlowStep(const application_managerRef AppM, const FrontendFlowStepType frontend_flow_step_type, const DesignFlowManagerConstRef design_flow_manager, const ParameterConstRef parameters)
Constructor.
~FrontendFlowStep() override
Destructor.
RelationshipType
The relationship type.
This class manages the tree structures extracted from the raw file.
DesignFlowStepFactoryConstRef CGetDesignFlowStepFactory() const override
Return the factory to create this type of steps.
Class specification of the graph structures.
The base class for design step.
exceptions managed by PandA
static const std::string EnumToKindText(const FrontendFlowStepType frontend_flow_step_type)
Given a frontend flow step type, return the name of the type.
void PrintTreeManager(const bool before) const
Dump the tree manager.
virtual std::string GetKindText() const
Return the name of the type of this frontend flow step.
This class contains the base representation for a generic frontend flow step which works on a single ...
const FrontendFlowStepType frontend_flow_step_type
The type of this step.
#define STR(s)
Macro which performs a lexical_cast to a string.
Auxiliary methods for manipulating string.
#define THROW_UNREACHABLE(str_expr)
helper function used to specify that some points should never be reached
Definition: exceptions.hpp:292
Classes to describe design flow graph.
redefinition of set to manage ordered/unordered structures
void PrintInitialIR() const override
Dump the initial intermediate representation.
static const std::string ComputeSignature(const FrontendFlowStepType frontend_flow_step_type)
Compute the signature of a function frontend flow step.
const Wrefcount< const DesignFlowManager > design_flow_manager
The design flow manager.
This class contains the base representation for a generic frontend flow step.
const ParameterConstRef parameters
Set of input parameters.
Wrapper of design_flow.
virtual std::string GetName() const =0
Return the name of this design 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
refcount< T > lock() const
Definition: refcount.hpp:212
unsigned int print_counter
Print counter.
void ComputeRelationships(DesignFlowStepSet &relationship, const DesignFlowStep::RelationshipType relationship_type) override
Compute the relationships of a step with other steps.
const application_managerRef AppM
The application manager.
This file collects some hash functors.
This class contains the methods to create a frontend flow step.
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.
Wrapper to call graph.
int debug_level
The debug level.
void print(std::ostream &os) const
Function that prints the class tree_manager.
void PrintFinalIR() const override
Dump the final intermediate representation.
This class contains the base representation for a generic frontend flow step which works on the whole...
Class specification of the manager of the tree structures extracted from the raw file.
static void CreateSteps(const DesignFlowManagerConstRef design_flow_manager, const CustomUnorderedSet< std::pair< FrontendFlowStepType, FunctionRelationship >> &frontend_relationships, const application_managerConstRef application_manager, DesignFlowStepSet &relationships)
Create the relationship steps of a step with other steps starting from already specified dependencies...
static const std::string ComputeSignature(const FrontendFlowStepType frontend_flow_step_type, const unsigned int function_id)
Compute the signature of a function frontend flow step.
void PrintGimple(std::ostream &os, const bool use_uid) const
Function that prints the bodies of function in gimple format.

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