PandA-2024.02
|
Compute the control flow graph for the operations. More...
#include <IR_lowering.hpp>
Public Member Functions | |
IR_lowering (const ParameterConstRef Param, const application_managerRef AppM, unsigned int function_id, const DesignFlowManagerConstRef design_flow_manager) | |
Constructor. More... | |
~IR_lowering () override | |
Destructor. More... | |
DesignFlowStep_Status | InternalExec () override |
traverse the data structure to simplify and make more homogeneous as possible. More... | |
void | Initialize () override |
Initialize the step (i.e., like a constructor, but executed just before exec. More... | |
void | ComputeRelationships (DesignFlowStepSet &relationship, const DesignFlowStep::RelationshipType relationship_type) override |
Compute the relationships of a step with other steps. 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... | |
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 | |
tree_nodeRef | expand_mult_const (const tree_nodeRef &op0, unsigned long long int val, const struct algorithm &alg, enum mult_variant &variant, const tree_nodeRef &stmt, const blocRef &block, const tree_nodeRef &type, const std::string &srcp_default) |
A subroutine of expand_mult, used for constant multiplications. More... | |
tree_nodeRef | expand_smod_pow2 (const tree_nodeRef &op0, unsigned long long int d, const tree_nodeRef &stmt, const blocRef &block, const tree_nodeRef &type, const std::string &srcp_default) |
Expand signed modulus of OP0 by a power of two D in mode MODE. More... | |
tree_nodeRef | expand_sdiv_pow2 (const tree_nodeRef &op0, unsigned long long int d, const tree_nodeRef &stmt, const blocRef &block, const tree_nodeRef &type, const std::string &srcp_default) |
Expand signed division of OP0 by a power of two D in mode MODE. More... | |
tree_nodeRef | expand_MC (const tree_nodeRef &op0, const integer_cst *ic_node, const tree_nodeRef &old_target, const tree_nodeRef &stmt, const blocRef &block, const tree_nodeRef &type_expr, const std::string &srcp_default) |
bool | expand_target_mem_ref (target_mem_ref461 *tmr, const tree_nodeRef &stmt, const blocRef &block, const std::string &srcp_default, bool temp_addr) |
tree_nodeRef | expand_mult_highpart (const tree_nodeRef &op0, unsigned long long int ml, const tree_nodeRef &type_expr, int data_bitsize, const std::list< tree_nodeRef >::const_iterator it_los, const blocRef &block, const std::string &srcp_default) |
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... | |
tree_nodeRef | array_ref_lowering (array_ref *AR, const std::string &srcp_default, std::pair< unsigned int, blocRef > block, std::list< tree_nodeRef >::const_iterator it_los, bool temp_addr) |
bool | reached_max_transformation_limit (const tree_nodeRef &stmt) |
check if the max transformation limit has been reached More... | |
void | division_by_a_constant (const std::pair< unsigned int, blocRef > &block, std::list< tree_nodeRef >::const_iterator &it_los, gimple_assign *ga, const tree_nodeRef &op1, enum kind code1, bool &restart_analysis, const std::string &srcp_default, const std::string &step_name) |
Private Attributes | |
tree_managerRef | TM |
The tree manager. More... | |
tree_manipulationRef | tree_man |
The IR manipulation. 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 DesignFlowManager > | design_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... | |
Compute the control flow graph for the operations.
Definition at line 84 of file IR_lowering.hpp.
IR_lowering::IR_lowering | ( | const ParameterConstRef | Param, |
const application_managerRef | AppM, | ||
unsigned int | function_id, | ||
const DesignFlowManagerConstRef | design_flow_manager | ||
) |
Constructor.
Param | is the set of the parameters |
AppM | is the application manager |
function_id | is the identifier of the function |
DesignFlowManagerConstRef | is the design flow manager |
Definition at line 82 of file IR_lowering.cpp.
References DesignFlowStep::debug_level, GET_CLASS, and DesignFlowStep::parameters.
|
overridedefault |
Destructor.
Referenced by ComputeFrontendRelationships().
|
private |
Definition at line 1733 of file IR_lowering.cpp.
References FrontendFlowStep::AppM, tree_helper::CGetType(), compute_n_bytes(), tree_manipulation::create_binary_operation(), tree_manipulation::create_unary_operation(), tree_manipulation::CreateGimpleAssign(), tree_manager::CreateUniqueIntegerCst(), DesignFlowStep::debug_level, DEBUG_LEVEL_VERY_PEDANTIC, FunctionFrontendFlowStep::function_id, GET_CONST_NODE, GET_INDEX_NODE, GET_NODE, tree_helper::GetArrayDimensions(), tree_helper::GetArrayElementSize(), tree_manipulation::GetPointerType(), tree_manipulation::GetSizeType(), INDENT_DBG_MEX, tree_node::index, offset, STR, THROW_ASSERT, TM, ToString(), tree_man, and test_panda::type.
Referenced by InternalExec().
|
overrideprivatevirtual |
Return the set of analyses in relationship with this design step.
relationship_type | is the type of relationship to be considered |
Implements FrontendFlowStep.
Definition at line 90 of file IR_lowering.cpp.
References DesignFlowStep::DEPENDENCE_RELATIONSHIP, DesignFlowStep::INVALIDATION_RELATIONSHIP, DesignFlowStep::PRECEDENCE_RELATIONSHIP, SAME_FUNCTION, THROW_UNREACHABLE, WHOLE_APPLICATION, and ~IR_lowering().
|
overridevirtual |
Compute the relationships of a step with other steps.
dependencies | is where relationships will be stored |
relationship_type | is the type of relationship to be computed |
Reimplemented from FunctionFrontendFlowStep.
Definition at line 129 of file IR_lowering.cpp.
References FunctionFrontendFlowStep::ComputeRelationships(), TechnologyFlowStep::ComputeSignature(), DesignFlowStep::DEPENDENCE_RELATIONSHIP, DesignFlowStep::design_flow_manager, DesignFlowStep::INVALIDATION_RELATIONSHIP, LOAD_TECHNOLOGY, Wrefcount< T >::lock(), DesignFlowStep::PRECEDENCE_RELATIONSHIP, and THROW_UNREACHABLE.
|
private |
very special case op1 == 1
Find a suitable multiplier and right shift count instead of multiplying with D.
restrict if needed the input bit-widths
We have computed OP0 / abs(OP1). If OP1 is negative, negate the quotient.
Definition at line 406 of file IR_lowering_exec.cpp.
References FrontendFlowStep::AppM, CASE_CPP_NODES, CASE_CST_NODES, CASE_DECL_NODES, CASE_FAKE_NODES, CASE_GIMPLE_NODES, CASE_PRAGMA_NODES, CASE_QUATERNARY_EXPRESSION, CASE_TERNARY_EXPRESSION, CASE_TYPE_NODES, CASE_UNARY_EXPRESSION, ceil_log2(), tree_helper::CGetType(), choose_multiplier(), tree_manipulation::create_binary_operation(), tree_manipulation::create_unary_operation(), tree_manipulation::CreateGimpleAssign(), tree_manager::CreateUniqueIntegerCst(), DesignFlowStep::debug_level, DEBUG_LEVEL_VERY_PEDANTIC, EXACT_POWER_OF_2_OR_ZERO_P, expand_mult_highpart(), expand_sdiv_pow2(), expand_smod_pow2(), floor_log2(), FunctionFrontendFlowStep::function_id, GET_CONST_NODE, GET_NODE, tree_manipulation::GetBooleanType(), tree_helper::GetConstValue(), INDENT_DBG_MEX, INDENT_OUT_MEX, invert_mod2n(), tree_helper::IsConstant(), tree_helper::IsUnsignedIntegerType(), max, min, gimple_assign::op0, gimple_assign::op1, DesignFlowStep::output_level, OUTPUT_LEVEL_VERBOSE, tree_helper::Size(), STR, THROW_ASSERT, THROW_ERROR, TM, tree_man, and test_panda::type.
Referenced by InternalExec().
|
private |
very special case op1 == 0
very special case op1 == 1
very special case op1 == -1
keep the old assign
keep the old assign
Definition at line 1163 of file IR_lowering.cpp.
References ADDER_STD, FrontendFlowStep::AppM, choose_mult_variant(), tree_manipulation::create_binary_operation(), tree_manipulation::create_unary_operation(), tree_manipulation::CreateGimpleAssign(), tree_manager::CreateUniqueIntegerCst(), EXACT_POWER_OF_2_OR_ZERO_P, expand_mult_const(), floor_log2(), FunctionFrontendFlowStep::function_id, technology_manager::get_fu(), tree_helper::get_integer_cst_value(), GET_NODE, generic_device::get_parameter(), generic_device::get_technology_manager(), generic_device::has_parameter(), LIBRARY_STD_FU, max, MULTIPLIER_STD, tree_helper::Size(), STR, THROW_ASSERT, TM, and tree_man.
Referenced by expand_target_mem_ref(), and InternalExec().
|
private |
A subroutine of expand_mult, used for constant multiplications.
Multiply OP0 by VAL in mode MODE, storing the result in TARGET if convenient. Use the shift/add sequence described by ALG and apply the final fixup specified by VARIANT.
Compare only the bits of val and val_so_far that are significant in the result mode, to avoid sign-/zero-extension confusion.
Definition at line 782 of file IR_lowering.cpp.
References add_variant, alg_add_factor, alg_add_t2_m, alg_add_t_m2, alg_impossible, alg_m, alg_shift, alg_sub_factor, alg_sub_t2_m, alg_sub_t_m2, alg_unknown, alg_zero, FrontendFlowStep::AppM, tree_helper::CGetType(), tree_manipulation::create_binary_operation(), tree_manipulation::create_unary_operation(), tree_manipulation::CreateGimpleAssign(), tree_manager::CreateUniqueIntegerCst(), DesignFlowStep::debug_level, DEBUG_LEVEL_VERY_PEDANTIC, FunctionFrontendFlowStep::function_id, GET_NODE, INDENT_DBG_MEX, algorithm::log, negate_variant, algorithm::op, algorithm::ops, tree_helper::Size(), THROW_ASSERT, THROW_ERROR, THROW_UNREACHABLE, TM, tree_node::ToString(), and tree_man.
Referenced by expand_MC().
|
private |
long long int u0, v0, u1, v1, u0v0, u0v0h, u1v0, u0v0hu1v0, u0v1, u0v0hu1v0u0v1, u0v0hu1v0u0v1h, u1v1; u0 = u & ((1LL<<32)-1); u1 = u >>32; v0 = v & ((1LL<<32)-1); v1 = v >>32; u0v0 = u0 * v0; u0v0h = u0v0>>32; u0v0hU = u0v0h & ((1LL<<32)-1);///only for signed computation u1v0 = u1 * v0; u0v0hu1v0 = u0v0hU + u1v0; w1 = u0v0hu1v0 & ((1LL<<32)-1); w2 = u0v0hu1v0 >>32; u0v1 = u0 * v1; w1u0v1 = w1+u0v1; w1u0v1h = w1u0v1 >> 32; u1v1 = u1 * v1; w1u0v1hw2 = w1u0v1h + w2; return w1u0v1hw2 + u1v1;
Definition at line 1466 of file IR_lowering.cpp.
References FrontendFlowStep::AppM, tree_manipulation::create_binary_operation(), tree_manipulation::CreateGimpleAssign(), tree_manager::CreateUniqueIntegerCst(), FunctionFrontendFlowStep::function_id, GET_INDEX_NODE, GET_NODE, tree_helper::is_unsigned(), THROW_ASSERT, TM, and tree_man.
Referenced by division_by_a_constant().
|
private |
Expand signed division of OP0 by a power of two D in mode MODE.
This routine is only called for positive values of D.
Definition at line 1116 of file IR_lowering.cpp.
References FrontendFlowStep::AppM, tree_manipulation::create_binary_operation(), tree_manipulation::create_ternary_operation(), tree_manipulation::CreateGimpleAssign(), tree_manager::CreateUniqueIntegerCst(), floor_log2(), FunctionFrontendFlowStep::function_id, GET_NODE, tree_manipulation::GetBooleanType(), TM, and tree_man.
Referenced by division_by_a_constant().
|
private |
Expand signed modulus of OP0 by a power of two D in mode MODE.
Definition at line 1041 of file IR_lowering.cpp.
References FrontendFlowStep::AppM, tree_manipulation::create_binary_operation(), tree_manipulation::create_ternary_operation(), tree_manipulation::CreateGimpleAssign(), tree_manipulation::CreateNopExpr(), tree_manager::CreateUniqueIntegerCst(), tree_manipulation::CreateUnsigned(), floor_log2(), FunctionFrontendFlowStep::function_id, GET_NODE, tree_manipulation::GetBooleanType(), FunctionFrontendFlowStep::GetName(), tree_helper::IsUnsignedIntegerType(), tree_helper::Size(), THROW_ERROR, TM, and tree_man.
Referenced by division_by_a_constant().
|
private |
nothing to optimize
It is required to de-share some IR nodes
Definition at line 1285 of file IR_lowering.cpp.
References FrontendFlowStep::AppM, target_mem_ref461::base, tree_manipulation::create_binary_operation(), tree_manipulation::create_unary_operation(), tree_manipulation::CreateGimpleAssign(), DesignFlowStep::debug_level, DEBUG_LEVEL_VERY_PEDANTIC, expand_MC(), FunctionFrontendFlowStep::function_id, GET_INDEX_NODE, GET_NODE, tree_helper::get_type_index(), tree_helper::GetConstValue(), tree_manipulation::GetPointerType(), tree_manipulation::GetSizeType(), target_mem_ref461::idx, target_mem_ref461::idx2, INDENT_DBG_MEX, target_mem_ref461::offset, lenet_tvm::params, target_mem_ref461::step, TM, ToString(), tree_man, test_panda::type, and target_mem_ref461::type.
Referenced by InternalExec().
|
overridevirtual |
Initialize the step (i.e., like a constructor, but executed just before exec.
Reimplemented from DesignFlowStep.
Definition at line 123 of file IR_lowering.cpp.
References FrontendFlowStep::AppM, DesignFlowStep::parameters, TM, and tree_man.
|
overridevirtual |
traverse the data structure to simplify and make more homogeneous as possible.
first analyze phis
It is required to de-share some IR nodes
for each basic block B in CFG do > Consider all blocks successively
found a a clobber assignment do nothing
required by the CLANG/LLVM plugin
required by the CLANG/LLVM plugin
required by the CLANG/LLVM plugin
required by the CLANG/LLVM plugin
check for a missing cast
normalize op0
expose some part of the target_mem_ref statement
check missing cast
split the target_mem_ref in a address computation statement and in a load statement
check if there is a misaligned access
required by CLANG/LLVM plugin
required by CLANG/LLVM plugin
if the previous transformation still give a multiplication let's check if this multiplication is actually widen_mult_expr
check if a mult_expr may become a widen_mult_expr
check if there is a misaligned access
check if the mem_ref corresponds to an implicit memset and then it will be lowered to simple loop initializing the variable
split the target_mem_ref in a address computation statement and in a store statement
manage something as binary operand
required by the CLANG/LLVM plugin
required by the CLANG/LLVM plugin
optimize less than 0 or greater than or equal than 0
required by the CLANG/LLVM plugin
Implements FunctionFrontendFlowStep.
Definition at line 1035 of file IR_lowering_exec.cpp.
References align(), FrontendFlowStep::AppM, test_panda::arg, array_ref_lowering(), tree_helper::CGetElements(), tree_helper::CGetType(), tree_manipulation::create_binary_operation(), tree_manipulation::create_unary_operation(), tree_manipulation::CreateAddrExpr(), tree_manipulation::CreateGimpleAssign(), tree_manipulation::CreateNopExpr(), tree_manager::CreateUniqueIntegerCst(), tree_manipulation::CreateUnsigned(), tree_manipulation::CreateVectorBooleanType(), DesignFlowStep::debug_level, DEBUG_LEVEL_PEDANTIC, DEBUG_LEVEL_VERY_PEDANTIC, division_by_a_constant(), expand_MC(), expand_target_mem_ref(), FunctionFrontendFlowStep::function_behavior, FunctionFrontendFlowStep::function_id, tree_helper::get_base_index(), GET_CONST_NODE, GET_INDEX_CONST_NODE, GET_INDEX_NODE, tree_node::get_kind(), GET_NODE, tree_manager::get_tree_node_const(), tree_helper::get_type_index(), tree_manipulation::GetBooleanType(), tree_helper::GetConstValue(), tree_manipulation::GetCustomIntegerType(), tree_helper::GetFunctionReturnType(), FunctionFrontendFlowStep::GetName(), tree_manipulation::GetPointerType(), tree_manipulation::GetSizeType(), tree_manager::GetTreeNode(), tree_manager::GetTreeReindex(), INDENT_DBG_MEX, INDENT_OUT_MEX, tree_helper::is_int(), tree_helper::is_real(), tree_helper::IsBooleanType(), tree_helper::IsRealType(), tree_helper::IsSameType(), tree_helper::IsSignedIntegerType(), tree_helper::IsUnsignedIntegerType(), tree_helper::IsVectorType(), max, offset, DesignFlowStep::output_level, OUTPUT_LEVEL_MINIMUM, DesignFlowStep::parameters, phi, tree_helper::print_function_name(), reached_max_transformation_limit(), tree_helper::Size(), sl, STR, SUCCESS, THROW_ASSERT, THROW_ERROR, THROW_UNREACHABLE, THROW_WARNING, TM, ToString(), tree_man, and test_panda::type.
|
private |
check if the max transformation limit has been reached
stmt | is the current statement |
Definition at line 1792 of file IR_lowering.cpp.
References FrontendFlowStep::AppM, GET_CONST_NODE, and tree_node::get_kind().
Referenced by InternalExec().
|
private |
The tree manager.
Definition at line 88 of file IR_lowering.hpp.
Referenced by array_ref_lowering(), division_by_a_constant(), expand_MC(), expand_mult_const(), expand_mult_highpart(), expand_sdiv_pow2(), expand_smod_pow2(), expand_target_mem_ref(), Initialize(), and InternalExec().
|
private |
The IR manipulation.
Definition at line 91 of file IR_lowering.hpp.
Referenced by array_ref_lowering(), division_by_a_constant(), expand_MC(), expand_mult_const(), expand_mult_highpart(), expand_sdiv_pow2(), expand_smod_pow2(), expand_target_mem_ref(), Initialize(), and InternalExec().