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

#include <dead_code_elimination.hpp>

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

Public Member Functions

 dead_code_elimination (const ParameterConstRef _parameters, const application_managerRef AppM, unsigned int function_id, const DesignFlowManagerConstRef design_flow_manager)
 Constructor. More...
 
 ~dead_code_elimination () override
 Destructor. More...
 
DesignFlowStep_Status InternalExec () override
 Performs dead code elimination. More...
 
bool HasToBeExecuted () const override
 Check if this step has actually to be executed. 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...
 
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...
 
virtual void Initialize ()
 Initialize the step (i.e., like a constructor, but executed just before exec. 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...
 

Static Public Member Functions

static tree_nodeRef kill_vdef (const tree_managerRef &TM, const tree_nodeRef &vdef)
 Replace virtual ssa definition with gimple nop. More...
 
static void fix_sdc_motion (DesignFlowManagerConstRef design_flow_manager, unsigned int function_id, tree_nodeRef removedStmt)
 
- 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...
 

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...
 
void kill_uses (const tree_managerRef &TM, const tree_nodeRef &op0) const
 
tree_nodeRef add_gimple_nop (const tree_managerRef &TM, const tree_nodeRef &cur_stmt, const blocRef &bb)
 
void fix_sdc_motion (tree_nodeRef removedStmt) const
 
blocRef move2emptyBB (const tree_managerRef &TM, const unsigned int new_bbi, const statement_list *sl, const blocRef &bb_pred, const unsigned int cand_bb_dest, const unsigned int bb_dest) const
 

Private Attributes

std::map< unsigned int, boollast_writing_memory
 
std::map< unsigned int, boollast_reading_memory
 
bool restart_if_opt
 
bool restart_mwi_opt
 
bool restart_mem
 

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...
 
- 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

Definition at line 72 of file dead_code_elimination.hpp.

Constructor & Destructor Documentation

◆ dead_code_elimination()

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

Constructor.

header include

Parameters
Paramis the set of the parameters
AppMis the application manager
function_idis the index of the function
design_flow_manageris the design flow manager

STD includes

Definition at line 79 of file dead_code_elimination.cpp.

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

Here is the call graph for this function:

◆ ~dead_code_elimination()

dead_code_elimination::~dead_code_elimination ( )
overridedefault

Destructor.

Referenced by dead_code_elimination().

Here is the caller graph for this function:

Member Function Documentation

◆ add_gimple_nop()

tree_nodeRef dead_code_elimination::add_gimple_nop ( const tree_managerRef TM,
const tree_nodeRef cur_stmt,
const blocRef &  bb 
)
private
Parameters
gc
TM
cur_stmt
bb
Returns
tree_nodeRef

Definition at line 261 of file dead_code_elimination.cpp.

References FrontendFlowStep::AppM, tree_manager::create_tree_node(), FunctionFrontendFlowStep::function_id, GET_NODE, tree_manager::GetTreeReindex(), tree_manager::new_tree_node_id(), STR, THROW_ASSERT, TOK, TOK_SCPE, and TOK_SRCP.

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, FrontendFlowStep::FunctionRelationship > > dead_code_elimination::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 93 of file dead_code_elimination.cpp.

References CALLED_FUNCTIONS, DesignFlowStep::DEPENDENCE_RELATIONSHIP, DesignFlowStep::GetStatus(), DesignFlowStep::INVALIDATION_RELATIONSHIP, DesignFlowStep::parameters, DesignFlowStep::PRECEDENCE_RELATIONSHIP, restart_if_opt, restart_mem, restart_mwi_opt, SAME_FUNCTION, SUCCESS, THROW_UNREACHABLE, and WHOLE_APPLICATION.

Here is the call graph for this function:

◆ fix_sdc_motion() [1/2]

void dead_code_elimination::fix_sdc_motion ( tree_nodeRef  removedStmt) const
private

Definition at line 194 of file dead_code_elimination.cpp.

References DesignFlowStep::design_flow_manager, FunctionFrontendFlowStep::function_id, and Wrefcount< T >::lock().

Referenced by InternalExec().

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

◆ fix_sdc_motion() [2/2]

void dead_code_elimination::fix_sdc_motion ( DesignFlowManagerConstRef  design_flow_manager,
unsigned int  function_id,
tree_nodeRef  removedStmt 
)
static

Definition at line 178 of file dead_code_elimination.cpp.

References HLSFunctionStep::ComputeSignature(), and GET_INDEX_CONST_NODE.

Here is the call graph for this function:

◆ HasToBeExecuted()

bool dead_code_elimination::HasToBeExecuted ( ) const
overridevirtual

Check if this step has actually to be executed.

Returns
true if the step has to be executed

Reimplemented from FunctionFrontendFlowStep.

Definition at line 159 of file dead_code_elimination.cpp.

References FrontendFlowStep::AppM, FunctionFrontendFlowStep::function_id, FunctionFrontendFlowStep::HasToBeExecuted(), last_reading_memory, and last_writing_memory.

Here is the call graph for this function:

◆ InternalExec()

DesignFlowStep_Status dead_code_elimination::InternalExec ( )
overridevirtual

Performs dead code elimination.

single sweep analysis, block by block, from the bottom to up.

Returns
the exit status of this step

Each ssa which is used zero times is eliminated and the uses of the variables used in the assignment are recomputed multi-way and two way IFs simplified when conditions are constants gimple_call without side effects are removed store-load pairs checked for simplification dead stores removed

Retrieve the list of block

find out if it is a gimple_assign

in case of virtual uses it is better not perform the elimination

op0 is the left side of the assignment, op1 is the right side

very strict condition for the elimination

conservative analysis

very strict condition for the elimination

TODO in case read and write values are integers but of different signedness a cast could allow the load/store simplification

check if this load is killed by a following vover

remove same conditions

Fix PHIs

fix vdef

all vovers become vuse

fix vdef

update function memory write flag

conservative analysis

more conservative than really needed

Implements FunctionFrontendFlowStep.

Definition at line 358 of file dead_code_elimination.cpp.

References add_gimple_nop(), FrontendFlowStep::AppM, function_decl::body, ssa_name::CGetDefStmts(), ssa_name::CGetNumberUses(), tree_helper::CGetType(), ssa_name::CGetUseStmts(), DesignFlowStep::debug_level, DEBUG_LEVEL_PEDANTIC, DEBUG_LEVEL_VERY_PEDANTIC, bloc::ENTRY_BLOCK_ID, bloc::EXIT_BLOCK_ID, tree_helper::find_obj_type_ref_function(), fix_sdc_motion(), FunctionFrontendFlowStep::function_behavior, FunctionFrontendFlowStep::function_id, GET_CONST_NODE, GET_INDEX_NODE, GET_NODE, tree_helper::GetConstValue(), FunctionFrontendFlowStep::GetName(), tree_node::GetString(), INDENT_DBG_MEX, tree_node::index, tree_helper::is_a_nop_function_decl(), tree_helper::IsSameType(), tree_helper::IsVectorType(), kill_uses(), kill_vdef(), last_reading_memory, last_writing_memory, max, move2emptyBB(), DesignFlowStep::parameters, phi, function_decl::reading_memory, restart_if_opt, restart_mem, restart_mwi_opt, tree_helper::Size(), sl, STR, SUCCESS, THROW_ASSERT, THROW_ERROR, U, UNCHANGED, function_decl::undefined_flag, and function_decl::writing_memory.

Here is the call graph for this function:

◆ kill_uses()

void dead_code_elimination::kill_uses ( const tree_managerRef TM,
const tree_nodeRef op0 
) const
private

◆ kill_vdef()

tree_nodeRef dead_code_elimination::kill_vdef ( const tree_managerRef TM,
const tree_nodeRef vdef 
)
static

Replace virtual ssa definition with gimple nop.

Parameters
TMtree manager instance
vdefvirtual ssa
Returns
tree_nodeRef generated gimple nop statement

Definition at line 244 of file dead_code_elimination.cpp.

References BUILTIN_SRCP, tree_manager::create_tree_node(), FunctionFrontendFlowStep::function_id, GET_INDEX_CONST_NODE, GET_NODE, tree_manager::GetTreeReindex(), tree_manager::new_tree_node_id(), STR, TOK, TOK_SCPE, and TOK_SRCP.

Referenced by CleanVirtuals(), and InternalExec().

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

◆ move2emptyBB()

blocRef dead_code_elimination::move2emptyBB ( const tree_managerRef TM,
const unsigned int  new_bbi,
const statement_list sl,
const blocRef &  bb_pred,
const unsigned int  cand_bb_dest,
const unsigned int  bb_dest 
) const
private

Create empty basic block

Fix PHIs

Definition at line 293 of file dead_code_elimination.cpp.

References DesignFlowStep::debug_level, DEBUG_LEVEL_VERY_PEDANTIC, GET_NODE, INDENT_DBG_MEX, statement_list::list_of_bloc, phi, and STR.

Referenced by InternalExec().

Here is the caller graph for this function:

Field Documentation

◆ last_reading_memory

std::map<unsigned int, bool> dead_code_elimination::last_reading_memory
private

Definition at line 77 of file dead_code_elimination.hpp.

Referenced by HasToBeExecuted(), and InternalExec().

◆ last_writing_memory

std::map<unsigned int, bool> dead_code_elimination::last_writing_memory
private

Definition at line 75 of file dead_code_elimination.hpp.

Referenced by HasToBeExecuted(), and InternalExec().

◆ restart_if_opt

bool dead_code_elimination::restart_if_opt
private

Definition at line 79 of file dead_code_elimination.hpp.

Referenced by ComputeFrontendRelationships(), and InternalExec().

◆ restart_mem

bool dead_code_elimination::restart_mem
private

Definition at line 83 of file dead_code_elimination.hpp.

Referenced by ComputeFrontendRelationships(), and InternalExec().

◆ restart_mwi_opt

bool dead_code_elimination::restart_mwi_opt
private

Definition at line 81 of file dead_code_elimination.hpp.

Referenced by ComputeFrontendRelationships(), and InternalExec().


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

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