73 const DesignFlowManagerConstRef _design_flow_manager,
76 _design_flow_manager, _parameters)
87 switch(relationship_type)
91 relationships.insert(std::make_pair(BB_CONTROL_DEPENDENCE_COMPUTATION,
SAME_FUNCTION));
92 relationships.insert(std::make_pair(BB_REACHABILITY_COMPUTATION,
SAME_FUNCTION));
93 relationships.insert(std::make_pair(BB_FEEDBACK_EDGES_IDENTIFICATION,
SAME_FUNCTION));
94 relationships.insert(std::make_pair(DOM_POST_DOM_COMPUTATION,
SAME_FUNCTION));
101 relationships.insert(std::make_pair(BASIC_BLOCKS_CFG_COMPUTATION,
SAME_FUNCTION));
107 relationships.insert(std::make_pair(BASIC_BLOCKS_CFG_COMPUTATION,
SAME_FUNCTION));
115 return relationships;
125 const auto TM =
AppM->get_tree_manager();
127 bool bb_modified =
false;
131 const auto bb_index_map = cfg_bb_graph->CGetBBGraphInfo()->bb_index_map;
133 std::deque<vertex> basic_blocks;
134 cdg_bb_graph->ReverseTopologicalSort(basic_blocks);
136 for(
const auto& basic_block : basic_blocks)
138 if(boost::in_degree(basic_block, *cdg_bb_graph) > 1)
140 THROW_ERROR(
"Basic block structure not supported: BB" +
141 STR(cdg_bb_graph->CGetBBNodeInfo(basic_block)->block->number));
146 for(
const auto& basic_block : basic_blocks)
152 if(basic_block == cfg_bb_graph->CGetBBGraphInfo()->entry_vertex ||
153 basic_block == cfg_bb_graph->CGetBBGraphInfo()->exit_vertex)
158 "-->Analyzing BB" +
STR(cfg_bb_graph->CGetBBNodeInfo(basic_block)->block->number));
159 const auto bb_node_info = cfg_bb_graph->CGetBBNodeInfo(basic_block)->block;
160 if(!bb_node_info->loop_id)
168 if(boost::out_degree(basic_block, *cfg_bb_graph) == 2 &&
169 GET_CONST_NODE(cfg_bb_graph->CGetBBNodeInfo(basic_block)->block->CGetStmtList().back())->get_kind() ==
174 for(boost::tie(oe, oe_end) = boost::out_edges(basic_block, *cfg_bb_graph); oe != oe_end; oe++)
176 if(cfg_bb_graph->CGetBBEdgeInfo(*oe)->cfg_edge_T())
180 else if(cfg_bb_graph->CGetBBEdgeInfo(*oe)->cfg_edge_F())
190 "True-->BB" +
STR(cfg_bb_graph->CGetBBNodeInfo(true_vertex)->block->number) +
" - False-->BB" +
191 STR(cfg_bb_graph->CGetBBNodeInfo(false_vertex)->block->number));
197 std::swap(bb_node_info->true_edge, bb_node_info->false_edge);
198 const auto last_stmt = bb_node_info->CGetStmtList().back();
199 const auto gc = GetPointer<const gimple_cond>(
GET_CONST_NODE(last_stmt));
205 const auto new_cond = GetPointerS<const gimple_assign>(
GET_CONST_NODE(ga_cond))->op0;
206 bb_node_info->PushBefore(ga_cond, last_stmt,
AppM);
207 TM->ReplaceTreeNode(last_stmt, gc->op0, new_cond);
212 const auto basic_block_id = bb_node_info->number;
214 "-->Subgraph dominated by BB" +
STR(basic_block_id) +
" has to be restructured");
215 const auto fd = GetPointerS<function_decl>(TM->GetTreeNode(
function_id));
216 auto sl = GetPointerS<statement_list>(
GET_NODE(fd->body));
217 const blocRef new_block(
new bloc(sl->list_of_bloc.rbegin()->first + 1));
218 new_block->SetSSAUsesComputed();
219 sl->list_of_bloc[new_block->number] = new_block;
222 THROW_ASSERT(boost::in_degree(basic_block, *post_dom_bb_graph) == 1,
"");
223 boost::tie(ie, ie_end) = boost::in_edges(basic_block, *post_dom_bb_graph);
224 const auto end_if = boost::source(*ie, *post_dom_bb_graph);
225 const auto end_if_block = post_dom_bb_graph->CGetBBNodeInfo(end_if)->block;
226 const auto end_if_id = end_if_block->number;
228 const auto true_bb_id = bb_node_info->true_edge;
229 const auto true_bb = bb_index_map.at(true_bb_id);
230 const auto false_bb_id = bb_node_info->false_edge;
231 const auto false_bb = bb_index_map.at(false_bb_id);
236 for(boost::tie(ie, ie_end) = boost::in_edges(end_if, *cfg_bb_graph); ie != ie_end; ie++)
238 const auto source = boost::source(*ie, *cfg_bb_graph);
246 "---Inserting BB" +
STR(cfg_bb_graph->CGetBBNodeInfo(source)->block->number) +
248 true_bb_ends.insert(source);
251 if(source == false_bb or
function_behavior->CheckBBReachability(false_bb, source))
254 "---Inserting BB" +
STR(cfg_bb_graph->CGetBBNodeInfo(source)->block->number) +
256 false_bb_ends.insert(source);
262 new_block->list_of_pred.push_back(basic_block_id);
263 bb_node_info->list_of_succ.erase(
264 std::find(bb_node_info->list_of_succ.begin(), bb_node_info->list_of_succ.end(), false_bb_id));
265 bb_node_info->list_of_succ.push_back(new_block->number);
266 bb_node_info->false_edge = new_block->number;
267 for(
const auto& true_bb_end : true_bb_ends)
269 auto true_bb_block = cfg_bb_graph->CGetBBNodeInfo(true_bb_end)->block;
270 true_bb_block->list_of_succ.erase(
271 std::find(true_bb_block->list_of_succ.begin(), true_bb_block->list_of_succ.end(), end_if_id));
272 true_bb_block->list_of_succ.push_back(new_block->number);
273 if(true_bb_block->true_edge == end_if_id)
275 true_bb_block->true_edge = new_block->number;
277 else if(true_bb_block->false_edge == end_if_id)
279 true_bb_block->false_edge = new_block->number;
281 new_block->list_of_pred.push_back(true_bb_block->number);
282 end_if_block->list_of_pred.erase(std::find(end_if_block->list_of_pred.begin(),
283 end_if_block->list_of_pred.end(), true_bb_block->number));
286 auto false_bb_block = cfg_bb_graph->CGetBBNodeInfo(false_bb)->block;
287 new_block->true_edge = false_bb_id;
288 new_block->list_of_succ.push_back(false_bb_id);
289 false_bb_block->list_of_pred.erase(
290 std::find(false_bb_block->list_of_pred.begin(), false_bb_block->list_of_pred.end(), basic_block_id));
291 false_bb_block->list_of_pred.push_back(new_block->number);
293 new_block->false_edge = end_if_id;
294 new_block->list_of_succ.push_back(end_if_id);
295 end_if_block->list_of_pred.push_back(new_block->number);
298 const auto gc = GetPointer<const gimple_cond>(
GET_NODE(bb_node_info->CGetStmtList().back()));
304 new_block->PushBack(ga_cond,
AppM);
305 const auto new_cond = GetPointerS<const gimple_assign>(
GET_CONST_NODE(ga_cond))->op0;
307 new_block->PushBack(new_tree_node,
AppM);
311 for(
const auto&
phi : end_if_block->CGetPhiList())
313 const auto gp = GetPointerS<gimple_phi>(
GET_NODE(
phi));
318 std::map<TreeVocabularyTokenTypes_TokenEnum, std::string> ssa_schema;
319 auto ssa_vers = TM->get_next_vers();
320 auto ssa_node_nid = TM->new_tree_node_id();
325 if(GetPointer<ssa_name>(
GET_NODE(gp->res))->var)
329 TM->create_tree_node(ssa_node_nid, ssa_name_K, ssa_schema);
331 "---Created " +
STR(TM->CGetTreeNode(ssa_node_nid)));
333 std::map<TreeVocabularyTokenTypes_TokenEnum, std::string> gimple_phi_schema;
334 const auto gimple_phi_id = TM->new_tree_node_id();
339 TM->create_tree_node(gimple_phi_id, gimple_phi_K, gimple_phi_schema);
340 auto new_gp = GetPointer<gimple_phi>(TM->get_tree_node_const(gimple_phi_id));
341 new_gp->SetSSAUsesComputed();
346 return TM->CreateUniqueIntegerCst(0,
type);
354 for(
const auto& def_edge : gp->CGetDefEdgesList())
357 "---Considering source BB" +
STR(def_edge.second));
358 const auto source_bb = bb_index_map.find(def_edge.second)->second;
359 if(true_bb_ends.find(source_bb) != true_bb_ends.end())
361 new_gp->AddDefEdge(TM, def_edge);
363 else if(false_bb_ends.find(source_bb) != false_bb_ends.end())
365 end_if_new_def_edge_list.push_back(def_edge);
374 end_if_new_def_edge_list.push_back(def_edge);
377 new_block->AddPhi(TM->GetTreeReindex(gimple_phi_id));
378 gp->SetDefEdgeList(TM, end_if_new_def_edge_list);
380 "<--Added phi " +
STR(TM->CGetTreeNode(gimple_phi_id)) +
" - Fixed phi " +
387 else if(boost::out_degree(basic_block, *cfg_bb_graph) >= 2)
390 const auto last_stmt =
GET_CONST_NODE(cfg_bb_graph->CGetBBNodeInfo(basic_block)->block->CGetStmtList().back());
391 const auto gmwi = GetPointer<const gimple_multi_way_if>(last_stmt);
394 for(
const auto& cond : gmwi->list_of_cond)
396 const auto current_basic_block_index = cond.second;
397 const auto current_basic_block = bb_index_map.at(current_basic_block_index);
399 function_behavior->CheckBBReachability(previous_basic_block, current_basic_block),
405 "<--Analyzed BB" +
STR(cfg_bb_graph->CGetBBNodeInfo(basic_block)->block->number));
#define GET_NODE(t)
Macro used to hide implementation details when accessing a tree_node from another tree_node...
tree_nodeRef CreateNotExpr(const tree_nodeConstRef &condition, const blocRef &block, unsigned int function_decl_nid) const
UTILITY.
~SerializeMutualExclusions() override
Destructor.
#define DEBUG_LEVEL_VERY_PEDANTIC
extremely verbose debugging print is performed.
This struct specifies the field bloc (basic block).
#define INDENT_DBG_MEX(dbgLevel, curDbgLevel, mex)
We are producing a debug version of the program, so the message is printed;.
boost::graph_traits< graph >::out_edge_iterator OutEdgeIterator
out_edge_iterator definition.
Basic block control flow graph.
File containing functions and utilities to support the printing of debug messagges.
tree_nodeRef create_gimple_cond(const tree_nodeRef &expr, unsigned int function_decl_nid, const std::string &srcp) const
GIMPLE_COND.
Step successfully executed.
#define GET_CLASS(obj)
Macro returning the actual type of an object.
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.
Definition of the class representing a generic C application.
This class contains the methods for remove mutual exclusions from simd loops.
struct definition of the source position.
RelationshipType
The relationship type.
Source must be executed to satisfy target.
std::list< DefEdge > DefEdgeList
The type of the def edge list.
boost::graph_traits< graph >::in_edge_iterator InEdgeIterator
in_edge_iterator definition.
A simple interface to token object of the raw files.
Basic block post-dominator tree.
Data structure describing a basic block at tree level.
#define TOK(token)
Macro used to convert a token symbol into a treeVocabularyTokenTypes.
std::string include_name
include_name is a filename string, this can be the location of a reference, if no definition has been...
tree_nodeRef CreateGimpleAssign(const tree_nodeConstRef &type, const tree_nodeConstRef &min, const tree_nodeConstRef &max, const tree_nodeRef &op, unsigned int function_decl_nid, const std::string &srcp) const
Create gimple assignment.
#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
SerializeMutualExclusions(const application_managerRef AppM, unsigned int function_id, const DesignFlowManagerConstRef design_flow_manager, const ParameterConstRef parameters)
Constructor.
Classes to describe design flow graph.
Target must be reexecuted.
std::pair< tree_nodeRef, unsigned int > DefEdge
The type of the def edge.
boost::graph_traits< graph >::vertex_descriptor vertex
vertex definition.
#define GET_CONST_NODE(t)
DesignFlowStep_Status GetStatus() const
Return the status of this design step.
Classes specification of the tree_node data structures.
const ParameterConstRef parameters
Set of input parameters.
DesignFlowStep_Status
The status of a step.
Basic block control dependence graph.
Class defining some useful functions to create tree nodes and to manipulate the tree manager...
#define THROW_ERROR(str_expr)
helper function used to throw an error in a standard way
DesignFlowStep_Status InternalExec() override
Restructures the unstructured code.
This file collects some utility functions.
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
const unsigned int function_id
The index of the function to be analyzed.
const application_managerRef AppM
The application manager.
Class specification of the tree_reindex support class.
Class specification of the basic_block structure.
bool HasToBeExecuted() const override
Check if this step has actually to be executed.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
static tree_nodeConstRef CGetType(const tree_nodeConstRef &node)
Return the treenode of the type of node.
Classes specification of the tree_node data structures not present in the gcc.
this class is used to manage the command-line or XML options.
refcount< tree_node > tree_nodeRef
RefCount type definition of the tree_node class structure.
int debug_level
The debug level.
#define NULL_VERTEX
null vertex definition
This class creates a layer to add nodes and to manipulate the tree_nodes manager. ...
Class specification of the manager of the tree structures extracted from the raw file.
A brief description of the C++ Header File.
const FunctionBehaviorRef function_behavior
The function behavior of the function to be analyzed.
#define THROW_ASSERT(cond, str_expr)
helper function used to check an assert and if needed to throw an error in a standard way ...