PandA-2024.02
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
simple_code_motion Class Reference

Restructure the tree control flow graph. More...

#include <simple_code_motion.hpp>

Inheritance diagram for simple_code_motion:
Inheritance graph
[legend]
Collaboration diagram for simple_code_motion:
Collaboration graph
[legend]

Public Member Functions

 simple_code_motion (const ParameterConstRef parameters, const application_managerRef AppM, unsigned int function_id, const DesignFlowManagerConstRef design_flow_manager)
 Constructor. More...
 
 ~simple_code_motion () override
 Destructor. More...
 
DesignFlowStep_Status InternalExec () override
 Updates the tree to have a more compliant CFG. More...
 
void Initialize () override
 Initialize the step (i.e., like a constructor, but executed just before exec. More...
 
bool IsScheduleBased () const
 Return true if the last run of this step was based on scheduling. More...
 
- Public Member Functions inherited from FunctionFrontendFlowStep
 FunctionFrontendFlowStep (const application_managerRef AppM, const unsigned int function_id, const FrontendFlowStepType frontend_flow_step_type, const DesignFlowManagerConstRef design_flow_manager, const ParameterConstRef parameters)
 Constructor. More...
 
 ~FunctionFrontendFlowStep () override
 Destructor. More...
 
void ComputeRelationships (DesignFlowStepSet &relationship, const DesignFlowStep::RelationshipType relationship_type) override
 Compute the relationships of a step with other steps. More...
 
std::string GetSignature () const override
 Return the signature of this step. More...
 
std::string GetName () const override
 Return the name of this design step. More...
 
DesignFlowStep_Status Exec () final
 Execute the step. More...
 
bool HasToBeExecuted () const override
 Check if this step has actually to be executed. More...
 
unsigned int CGetBBVersion () const
 
unsigned int GetBitValueVersion () const
 
void PrintInitialIR () const override
 Dump the initial intermediate representation. More...
 
void PrintFinalIR () const override
 Dump the final intermediate representation. More...
 
- Public Member Functions inherited from FrontendFlowStep
 FrontendFlowStep (const application_managerRef AppM, const FrontendFlowStepType frontend_flow_step_type, const DesignFlowManagerConstRef design_flow_manager, const ParameterConstRef parameters)
 Constructor. More...
 
 ~FrontendFlowStep () override
 Destructor. More...
 
virtual std::string GetKindText () const
 Return the name of the type of this frontend flow step. More...
 
DesignFlowStepFactoryConstRef CGetDesignFlowStepFactory () const override
 Return the factory to create this type of steps. More...
 
void PrintTreeManager (const bool before) const
 Dump the tree manager. More...
 
- Public Member Functions inherited from DesignFlowStep
 DesignFlowStep (const DesignFlowManagerConstRef design_flow_manager, const ParameterConstRef parameters)
 Constructor. More...
 
virtual ~DesignFlowStep ()
 Destructor. More...
 
DesignFlowStep_Status GetStatus () const
 Return the status of this design step. More...
 
virtual void WriteDot (std::ostream &out) const
 Write the label for a dot graph. More...
 
bool IsComposed () const
 Returns if this step is composed. More...
 
int CGetDebugLevel () const
 Return the debug level of the step. More...
 

Private Member Functions

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. More...
 
FunctionFrontendFlowStep_Movable CheckMovable (const unsigned int dest_bb_index, tree_nodeRef tn, bool &zero_delay, const tree_managerRef TM)
 Check if a statement can be moved in a basic block. More...
 
void loop_pipelined (tree_nodeRef curr_stmt, const tree_managerRef TM, unsigned int curr_bb, unsigned int curr_loop_id, std::list< tree_nodeRef > &to_be_removed, std::list< tree_nodeRef > &to_be_added_back, std::list< tree_nodeRef > &to_be_added_front, std::map< unsigned int, blocRef > &list_of_bloc, std::map< std::pair< unsigned int, blocRef >, std::pair< unsigned int, blocRef >> &dom_diff, unsigned int curr_bb_dom)
 

Private Attributes

bool restart_ifmwi_opt
 
ScheduleRef schedule
 The scheduling solution. More...
 
bool conservative
 True if only zero delay statement can be moved. More...
 

Static Private Attributes

static bool tree_dumped
 flag to check if initial tree has been dumped More...
 

Additional Inherited Members

- Public Types inherited from FrontendFlowStep
using FunctionRelationship = enum { ALL_FUNCTIONS, CALLED_FUNCTIONS, CALLING_FUNCTIONS, SAME_FUNCTION, WHOLE_APPLICATION }
 The different relationship type between function analysis. More...
 
- Public Types inherited from DesignFlowStep
enum  RelationshipType { DEPENDENCE_RELATIONSHIP, INVALIDATION_RELATIONSHIP, PRECEDENCE_RELATIONSHIP }
 The relationship type. More...
 
- Static Public Member Functions inherited from FunctionFrontendFlowStep
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. More...
 
- Static Public Member Functions inherited from FrontendFlowStep
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 between frontend flow steps. More...
 
static const std::string EnumToKindText (const FrontendFlowStepType frontend_flow_step_type)
 Given a frontend flow step type, return the name of the type. More...
 
- Protected Member Functions inherited from FunctionFrontendFlowStep
void WriteBBGraphDot (const std::string &filename) const
 Write the current version of statement list in dot format. More...
 
- Protected Attributes inherited from FunctionFrontendFlowStep
const FunctionBehaviorRef function_behavior
 The function behavior of the function to be analyzed. More...
 
const unsigned int function_id
 The index of the function to be analyzed. More...
 
unsigned int bb_version
 The version of the basic block intermediate representation on which this step has been applied. More...
 
unsigned int bitvalue_version
 The version of the bitvalue information on which this step has been applied. More...
 
- Protected Attributes inherited from FrontendFlowStep
const application_managerRef AppM
 The application manager. More...
 
const FrontendFlowStepType frontend_flow_step_type
 The type of this step. More...
 
unsigned int print_counter
 Print counter. More...
 
- Protected Attributes inherited from DesignFlowStep
bool composed
 True if this step represents a composition of design flow steps (e.g., a flow); must be set by specialized constructors. More...
 
const Wrefcount< const DesignFlowManagerdesign_flow_manager
 The design flow manager. More...
 
const ParameterConstRef parameters
 Set of input parameters. More...
 
int debug_level
 The debug level. More...
 
const int output_level
 The output level. More...
 

Detailed Description

Restructure the tree control flow graph.

Definition at line 68 of file simple_code_motion.hpp.

Constructor & Destructor Documentation

◆ simple_code_motion()

simple_code_motion::simple_code_motion ( const ParameterConstRef  _parameters,
const application_managerRef  _AppM,
unsigned int  _function_id,
const DesignFlowManagerConstRef  _design_flow_manager 
)

Constructor.

Skipping warnings due to operator() redefinition.

Parameters
parametersis the set of input parameters
AppMis the application manager
function_idis the identifier of the function
design_flow_manageris the design flow manager

header include . include algorithm/dominance include behavior includes design_flows include parser/compiler include STD include tree includes utility include

Definition at line 98 of file simple_code_motion.cpp.

References DesignFlowStep::debug_level, DEBUG_LEVEL_NONE, GET_CLASS, and ~simple_code_motion().

Here is the call graph for this function:

◆ ~simple_code_motion()

simple_code_motion::~simple_code_motion ( )
overridedefault

Destructor.

Referenced by simple_code_motion().

Here is the caller graph for this function:

Member Function Documentation

◆ CheckMovable()

FunctionFrontendFlowStep_Movable simple_code_motion::CheckMovable ( const unsigned int  dest_bb_index,
tree_nodeRef  tn,
bool zero_delay,
const tree_managerRef  TM 
)
private

Check if a statement can be moved in a basic block.

Parameters
bb_indexis the index of the basic block
gnis the statement to be moved
zero_delayreturns if statement has zero delay
TMis the tree manager
Returns
if the statement can be moved

FIXME: already added in master?

If we have the ending time information use it

binary expressions

Definition at line 189 of file simple_code_motion.cpp.

References FrontendFlowStep::AppM, Schedule::CanBeMoved(), CASE_CPP_NODES, CASE_CST_NODES, CASE_DECL_NODES, CASE_FAKE_NODES, CASE_GIMPLE_NODES, CASE_PRAGMA_NODES, CASE_QUATERNARY_EXPRESSION, CASE_TYPE_NODES, tree_helper::CGetType(), tree_helper::compute_ssa_uses_rec_ptr(), conservative, DesignFlowStep::debug_level, DEBUG_LEVEL_VERY_PEDANTIC, FunctionFrontendFlowStep::function_id, GET_INDEX_NODE, tree_node::get_kind(), tree_node::get_kind_text(), GET_NODE, tree_helper::GetConstValue(), INDENT_DBG_MEX, tree_helper::is_constant(), tree_helper::is_real(), tree_helper::IsConstant(), tree_helper::IsRealType(), max, min, MOVABLE, schedule, tree_helper::Size(), STR, THROW_UNREACHABLE, TIMING, and UNMOVABLE.

Referenced by InternalExec().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ComputeFrontendRelationships()

const CustomUnorderedSet< std::pair< FrontendFlowStepType, FunctionFrontendFlowStep::FunctionRelationship > > simple_code_motion::ComputeFrontendRelationships ( const DesignFlowStep::RelationshipType  relationship_type) const
overrideprivatevirtual

Return the set of analyses in relationship with this design step.

Parameters
relationship_typeis the type of relationship to be considered

Implements FrontendFlowStep.

Definition at line 122 of file simple_code_motion.cpp.

References DesignFlowStep::DEPENDENCE_RELATIONSHIP, DesignFlowStep::GetStatus(), DesignFlowStep::INVALIDATION_RELATIONSHIP, DesignFlowStep::PRECEDENCE_RELATIONSHIP, restart_ifmwi_opt, SAME_FUNCTION, SUCCESS, THROW_UNREACHABLE, and WHOLE_APPLICATION.

Here is the call graph for this function:

◆ Initialize()

void simple_code_motion::Initialize ( )
overridevirtual

Initialize the step (i.e., like a constructor, but executed just before exec.

Reimplemented from DesignFlowStep.

Definition at line 164 of file simple_code_motion.cpp.

References FrontendFlowStep::AppM, function_decl::body, FunctionFrontendFlowStep::function_id, GET_NODE, DesignFlowStep::parameters, schedule, and sl.

◆ InternalExec()

DesignFlowStep_Status simple_code_motion::InternalExec ( )
overridevirtual

Updates the tree to have a more compliant CFG.

store the GCC BB graph ala boost::graph

add vertices

add edges

add a connection between entry and exit thus avoiding problems with non terminating code

sort basic block vertices from the entry till the exit

If we are performing simd transformation, look for simd pragma

We must use pointer since we are erasing elements in the list

skip gimple statements defining or using virtual operands

load can be loop pipelined/predicated

only gimple_assign are considered for code motion

compute the SSA variables used by stmt

compute BB where the SSA variables are defined

check for anti-dependencies

allow to move first statements later overwritten in the same BB

skip the statement in case it uses ssa variables defined in the current BB

check if list of pred has a loop_id greater than the loop_id of curr_bb

check if current statement can be loop pipelined

load cannot be code moved

find in which BB can be moved

check the result of the dominator tree analysis

check if the controlling condition of curr_bb is constant

finally we found something of meaningful

check if the current uses in dest_bb_index are due only to phis

check if the statement can be really moved

add predication in case is required

it may happen: two consecutive BBs without conditional jump

create a negated condition

compute default condition

it may happen: two consecutive BBs without conditional jump

Going one step step forward to avoid invalidation of the pointer

Moving statement

Going one step back since pointer is already increment in for loop

Implements FunctionFrontendFlowStep.

Definition at line 672 of file simple_code_motion.cpp.

References FrontendFlowStep::AppM, CFG_SELECTOR, CheckMovable(), tree_helper::compute_ssa_uses_rec_ptr(), counter, cyclic_topological_sort(), DesignFlowStep::debug_level, DEBUG_LEVEL_VERY_PEDANTIC, bloc::ENTRY_BLOCK_ID, bloc::EXIT_BLOCK_ID, FunctionFrontendFlowStep::function_behavior, FunctionFrontendFlowStep::function_id, GET_CONST_NODE, GET_INDEX_NODE, GET_NODE, tree_helper::GetConstValue(), FunctionFrontendFlowStep::GetName(), INDENT_DBG_MEX, MOVABLE, DesignFlowStep::parameters, restart_ifmwi_opt, sl, STR, SUCCESS, lenet_tvm::target, THROW_ASSERT, THROW_ERROR, TIMING, UNCHANGED, UNMOVABLE, and BBGraph::WriteDot().

Here is the call graph for this function:

◆ IsScheduleBased()

bool simple_code_motion::IsScheduleBased ( ) const

Return true if the last run of this step was based on scheduling.

Definition at line 1357 of file simple_code_motion.cpp.

References schedule.

◆ loop_pipelined()

void simple_code_motion::loop_pipelined ( tree_nodeRef  curr_stmt,
const tree_managerRef  TM,
unsigned int  curr_bb,
unsigned int  curr_loop_id,
std::list< tree_nodeRef > &  to_be_removed,
std::list< tree_nodeRef > &  to_be_added_back,
std::list< tree_nodeRef > &  to_be_added_front,
std::map< unsigned int, blocRef > &  list_of_bloc,
std::map< std::pair< unsigned int, blocRef >, std::pair< unsigned int, blocRef >> &  dom_diff,
unsigned int  curr_bb_dom 
)
private

Field Documentation

◆ conservative

bool simple_code_motion::conservative
private

True if only zero delay statement can be moved.

Definition at line 80 of file simple_code_motion.hpp.

Referenced by CheckMovable().

◆ restart_ifmwi_opt

bool simple_code_motion::restart_ifmwi_opt
private

Definition at line 71 of file simple_code_motion.hpp.

Referenced by ComputeFrontendRelationships(), and InternalExec().

◆ schedule

ScheduleRef simple_code_motion::schedule
private

The scheduling solution.

Definition at line 74 of file simple_code_motion.hpp.

Referenced by CheckMovable(), Initialize(), and IsScheduleBased().

◆ tree_dumped

bool simple_code_motion::tree_dumped
staticprivate

flag to check if initial tree has been dumped

Definition at line 77 of file simple_code_motion.hpp.


The documentation for this class was generated from the following files:

Generated on Mon Feb 12 2024 13:04:03 for PandA-2024.02 by doxygen 1.8.13