81 #include <boost/foreach.hpp> 82 #include <boost/range/adaptor/reversed.hpp> 85 unsigned int _funId,
const DesignFlowManagerConstRef _design_flow_manager)
101 if(state_info->executing_operations.empty())
103 if(state_info->ending_operations.empty())
105 return *state_info->BB_ids.begin();
109 return GET_BB_INDEX(data, *(state_info->ending_operations).rbegin());
114 return GET_BB_INDEX(data, *(state_info->executing_operations.rbegin()));
121 const auto state_info = stg->CGetStateInfo(prev_state);
122 for(
const auto& exec_op : state_info->executing_operations)
127 for(
const auto scalar_use : scalar_uses)
129 if(HLSMgr->is_register_compatible(scalar_use))
136 for(
const auto& end_op : state_info->ending_operations)
141 for(
const auto scalar_def : scalar_defs)
143 if(HLSMgr->is_register_compatible(scalar_def))
150 if(not state_info->moved_op_use_set.empty())
152 HLS->
Rliv->
set_live_out(current_state, stg->CGetStateInfo(prev_state)->moved_op_use_set);
166 BOOST_FOREACH(
vertex v, boost::vertices(*fbb))
177 std::deque<vertex> reverse_order_state_list;
178 astg->ReverseTopologicalSort(reverse_order_state_list);
180 std::deque<vertex> dummy_states;
187 for(
const auto& rosl : reverse_order_state_list)
194 if(rosl == exit_state)
203 for(
const auto& eoc : state_info->ending_operations)
208 for(
const auto scalar_def : scalar_defs)
210 if(
HLSMgr->is_register_compatible(scalar_def))
220 if(state_info->is_dummy)
222 dummy_states.push_back(rosl);
232 if(not state_info->moved_op_use_set.empty())
240 for(
const auto& var_id : state_info->moved_op_use_set)
259 vertex src_state = boost::source(e, *stg);
273 unsigned int prev_bb_index = fbb->
CGetBBNodeInfo(bb_exit)->get_bb_index();
274 vertex prev_state = exit_state;
276 "---prev_state: " + stg->CGetStateInfo(prev_state)->name +
" prev_bb_index: " +
STR(prev_bb_index));
277 for(
const auto& rosl : reverse_order_state_list)
282 if(rosl == exit_state)
290 if(state_info->is_dummy)
297 if(state_info->is_duplicated)
300 if(state_info->isOriginalState)
304 unsigned int cloned_bb_index = *cloned_state_info->BB_ids.begin();
306 prev_bb_index = cloned_bb_index;
308 "---update prev_state: " + stg->CGetStateInfo(prev_state)->name +
309 " prev_bb_index: " +
STR(prev_bb_index));
315 StateInfoConstRef cloned_state_info = astg->CGetStateInfo(state_info->clonedState);
316 unsigned int cloned_bb_index = *cloned_state_info->BB_ids.begin();
320 "-->Considering successors of: " + cloned_state_info->name);
321 BOOST_FOREACH(
EdgeDescriptor oe, boost::out_edges(state_info->clonedState, *astg))
325 unsigned int target_bb_index = *target_state_info->BB_ids.begin();
328 if(cloned_bb_index == target_bb_index and target_state != rosl)
331 "---updating live out of : " + state_info->name +
", " + cloned_state_info->name);
333 "---adding live out of : " + target_state_info->name);
342 "<--Considered successors of: " + cloned_state_info->name);
347 for(
const auto lo : fbb->
CGetBBNodeInfo(bb_index_map[cloned_bb_index])->get_live_out())
349 if(
HLSMgr->is_register_compatible(lo))
354 "---adding to live out of " + state_info->name +
" var " + BH->
PrintVariable(lo));
356 "---adding to live out of " + cloned_state_info->name +
" var " +
365 prev_bb_index = cloned_bb_index;
367 "---update prev_state: " + stg->CGetStateInfo(prev_state)->name +
368 " prev_bb_index: " +
STR(prev_bb_index));
377 if(prev_bb_index != bb_index)
380 "---prev_bb_index " +
STR(prev_bb_index) +
" != bb_index " +
STR(bb_index));
382 "---adding live out of BB " +
STR(bb_index) +
" to live out of state " + state_info->name);
383 for(
const auto lo : fbb->
CGetBBNodeInfo(bb_index_map[bb_index])->get_live_out())
385 if(
HLSMgr->is_register_compatible(lo))
394 "---adding live out of " + stg->CGetStateInfo(prev_state)->name +
" to live out of state " +
400 prev_bb_index = bb_index;
402 "---update prev_state: " + stg->CGetStateInfo(prev_state)->name +
403 " prev_bb_index: " +
STR(prev_bb_index));
412 prev_state = entry_state;
414 for(
const auto& osl : boost::adaptors::reverse(reverse_order_state_list))
417 if(state_to_skip.find(osl) != state_to_skip.end())
420 prev_bb_index = *state_info->BB_ids.begin();
424 if(state_info->is_dummy)
429 if(state_info->is_duplicated)
431 unsigned int bb_index = *state_info->BB_ids.begin();
432 for(
const auto li : fbb->
CGetBBNodeInfo(bb_index_map[bb_index])->get_live_in())
434 if(
HLSMgr->is_register_compatible(li))
444 unsigned int target_bb_index = *target_state_info->BB_ids.begin();
445 if(bb_index == target_bb_index && !target_state_info->is_duplicated)
448 state_to_skip.insert(target_state);
452 prev_bb_index = bb_index;
457 if(prev_bb_index != bb_index)
459 for(
const auto li : fbb->
CGetBBNodeInfo(bb_index_map[bb_index])->get_live_in())
461 if(
HLSMgr->is_register_compatible(li))
472 prev_bb_index = bb_index;
478 for(
const auto& ds : dummy_states)
483 vertex src_state = boost::source(e, *astg);
487 for(
const auto& eo : state_info->executing_operations)
491 for(
const auto scalar_use : scalar_uses)
493 if(
HLSMgr->is_register_compatible(scalar_use))
513 for(
const auto& rosl : reverse_order_state_list)
517 for(
const auto& roc : state_info->executing_operations)
524 "<--Analyzed running operation of type NOP" +
GET_NAME(data, roc));
529 const auto phi_node =
531 for(
const auto& def_edge : GetPointer<const gimple_phi>(phi_node)->CGetDefEdgesList())
533 unsigned int tree_var = def_edge.first->index;
534 unsigned int bb_index = def_edge.second;
535 if(state_info->is_duplicated && !state_info->all_paths)
537 if(!state_info->isOriginalState && bb_index != state_info->sourceBb)
541 if(state_info->isOriginalState && bb_index == state_info->sourceBb)
546 if(state_info->moved_op_def_set.find(tree_var) != state_info->moved_op_def_set.end() or
547 state_info->moved_op_use_set.find(written_phi) != state_info->moved_op_use_set.end())
551 if(state_info->moved_op_use_set.find(written_phi) != state_info->moved_op_use_set.end())
556 vertex src_vrtx = boost::source(ie, *stg);
570 bool found_state =
false;
574 vertex src_state = boost::source(ie, *stg);
577 if(BB_ids.find(bb_index) != BB_ids.end())
580 "---Adding state in " + source_state_info->name +
" " +
586 "Source state for phi " +
STR(data->
CGetOpNodeInfo(roc)->GetNodeId()) +
" not found");
594 state_info->name +
" coming from BB" +
STR(bb_index));
606 for(
const auto all_but_scalar_def : all_but_scalar_defs)
608 if(
HLSMgr->is_register_compatible(all_but_scalar_def))
612 else if(
HLSMgr->Rmem->has_base_address(all_but_scalar_def) or
631 for(
const auto& eoc : state_info->ending_operations)
635 if(state_info->is_duplicated && state_info->clonedState !=
NULL_VERTEX && !state_info->all_paths)
638 bool postponed_phi =
false;
639 const auto phi_node =
641 for(
const auto& def_edge : GetPointer<const gimple_phi>(phi_node)->CGetDefEdgesList())
643 unsigned int tree_temp = def_edge.first->index;
644 unsigned int bbID = def_edge.second;
645 if(bbID != state_info->sourceBb)
649 else if(state_info->moved_op_def_set.find(tree_temp) != state_info->moved_op_def_set.end())
651 postponed_phi =
true;
653 else if(state_info->moved_op_use_set.find(written_phi) != state_info->moved_op_use_set.end())
655 postponed_phi =
true;
659 if(not postponed_phi)
672 for(
const auto scalar_def : scalar_defs)
674 if(
HLSMgr->is_register_compatible(scalar_def))
696 BOOST_FOREACH(
vertex v, boost::vertices(*astg))
void add_state_in_for_var(unsigned int var, vertex op, vertex state, vertex state_in)
put into relation for a given variable used in a state the state from which the variable comes ...
void Initialize() override
Initialize the step (i.e., like a constructor, but executed just before exec.
Class specification to contain liveness information.
#define TYPE_NOP
constant string identifying a type for a no operation.
#define DEBUG_LEVEL_VERY_PEDANTIC
extremely verbose debugging print is performed.
const HLS_managerRef HLSMgr
information about all the HLS synthesis
Data structure representing the entire HLS information.
#define INDENT_DBG_MEX(dbgLevel, curDbgLevel, mex)
We are producing a debug version of the program, so the message is printed;.
void add_state_out_for_var(unsigned int var, vertex op, vertex state, vertex state_in)
put into relation for a given variable defined in a state the state to which the variable goes ...
#define GET_TYPE(data, vertex_index)
Helper macro returning the type associated with a node.
File containing functions and utilities to support the printing of debug messagges.
#define PRINT_DBG_MEX(dbgLevel, curDbgLevel, mex)
We are producing a debug version of the program, so the message is printed;.
#define DEBUG_LEVEL_PEDANTIC
very verbose debugging print is performed.
void add_dummy_state(vertex state)
add a state to the set of dummy vertices
This file contains the structures needed to manage a graph that will represent the state transition g...
void add_state_for_running_op(vertex op, vertex v)
add a running state for a given operation
#define GET_CLASS(obj)
Macro returning the actual type of an object.
std::string get_function_name() const
Return the name of the function.
void erase_el_live_out(const vertex &v, unsigned int var)
erase a variable from the live out
vertex get_entry_state() const
Gets vertex that represents state that contains entry node.
const BBGraphInfoConstRef CGetBBGraphInfo() const
Returns the property associated with the graph.
const unsigned int funId
identifier of the function to be processed (0 means that it is a global step)
void add_state_for_ending_op(vertex op, vertex v)
add an ending state for a given operation
#define GET_NAME(data, vertex_index)
Helper macro returning the name associated with a node.
static bool is_parameter(const tree_managerConstRef &TM, const unsigned int index)
return true in case the index corresponds to a parameter in ssa form or not
#define GET_BB_INDEX(data, vertex_index)
Macro returning the index of the basic block which the node belongs to.
vertex get_exit_state() const
Gets vertex that represents state that contains exit node.
void add_support_state(vertex v)
add a support state
#define PRINT_DBG_STRING(dbgLevel, curDbgLevel, mex)
We are producing a debug version of the program, so the message is printed; no newline is added;...
void set_live_in(const vertex &v, unsigned int var)
Store a variable alive at the input of the given vertex.
static unsigned int get_bb_index_from_state_info(const OpGraphConstRef data, StateInfoConstRef state_info)
#define TYPE_PHI
constant string identifying an operation node of type PHI
#define STR(s)
Macro which performs a lexical_cast to a string.
Auxiliary methods for manipulating string.
const OpNodeInfoConstRef CGetOpNodeInfo(const vertex node) const
Returns the info associated with a node.
absl::flat_hash_map< T, U, Hash, Eq, Alloc > CustomUnorderedMap
static bool is_virtual(const tree_managerConstRef &TM, const unsigned int index)
return true in case the ssa_name is virtual
Basic block control flow graph with feedback.
boost::graph_traits< graph >::vertex_descriptor vertex
vertex definition.
This file contains the structures needed to manage a graph that will represent the state transition g...
const CustomOrderedSet< unsigned int > & get_live_out(const vertex &v) const
Get the set of variables live at the output of a vertex.
const BehavioralHelperConstRef CGetBehavioralHelper() const
Returns the helper associated with the function.
Classes specification of the tree_node data structures.
const ParameterConstRef parameters
Set of input parameters.
DesignFlowStep_Status
The status of a step.
#define THROW_ERROR(str_expr)
helper function used to throw an error in a standard way
std::string PrintVariable(unsigned int var) const
Print the name of the variable associated to the index.
DesignFlowStep_Status InternalExec() override
Execute the step.
Data structure definition for HLS constraints.
const StateTransitionGraphConstRef CGetAstg() const
Returns pointer to state transition graph created.
livenessRef Rliv
data-structure containing the variable liveness
This file collects some utility functions.
static bool is_ssa_name(const tree_managerConstRef &TM, const unsigned int index)
Return true in case index is a ssa_name.
~FSM_NI_SSA_liveness() override
Destructor.
void set_live_out(const vertex &v, const CustomOrderedSet< unsigned int > &vars)
Store the variables alive at the output of the given vertex.
const OpGraphConstRef CGetOpGraph(FunctionBehavior::graph_type gt) const
This method returns the operation graphs.
Class specification of the basic_block structure.
void add_name(vertex v, const std::string &name)
define the name of a state
hlsRef HLS
HLS data structure of the function to be analyzed.
const BBNodeInfoConstRef CGetBBNodeInfo(const vertex node) const
Return the info associated with a basic block.
Data structures used in operations graph.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
static void update_liveout_with_prev(const HLS_managerRef HLSMgr, hlsRef HLS, const StateTransitionGraphConstRef stg, const OpGraphConstRef data, vertex current_state, vertex prev_state)
const BBGraphConstRef CGetBBGraph(FunctionBehavior::bb_graph_type gt=FunctionBehavior::BB) const
This method returns the basic block graphs.
this class is used to manage the command-line or XML options.
FSM_NI_SSA_liveness(const ParameterConstRef _parameters, const HLS_managerRef HLSMgr, unsigned int funId, const DesignFlowManagerConstRef design_flow_manager)
Constructor.
liveness analysis exploiting the SSA form of the IR
unsigned int functionId
this is the identifier of the function to be implemented
StateTransitionGraphManagerRef STG
Store the refcounted state transition graph.
refcount< liveness > livenessRef
int debug_level
The debug level.
Data structure definition for high-level synthesis flow.
void Initialize() override
Initialize the step (i.e., like a constructor, but executed just before exec.
const StateTransitionGraphConstRef CGetStg() const
Returns pointer to state transition graph created.
void add_op_definition(unsigned int var, vertex v)
add a definition vertex for a variable
#define NULL_VERTEX
null vertex definition
Datastructure to represent memory information in high-level synthesis.
Class specification of the manager of the tree structures extracted from the raw file.
A brief description of the C++ Header File.
const CustomOrderedSet< unsigned int > & get_live_in(const vertex &v) const
Get the set of variables live at the input of a vertex.
std::string get_state_name(vertex state) const
Get the name of a state.
boost::graph_traits< graph >::edge_descriptor EdgeDescriptor
edge definition.
#define THROW_ASSERT(cond, str_expr)
helper function used to check an assert and if needed to throw an error in a standard way ...