PandA-2024.02
|
#include <vectorize.hpp>
Public Member Functions | |
Vectorize (const application_managerRef AppM, unsigned int function_id, const DesignFlowManagerConstRef design_flow_manager, const ParameterConstRef parameters) | |
Constructor. More... | |
~Vectorize () override | |
Destructor. More... | |
DesignFlowStep_Status | InternalExec () override |
Restructures the unstructured code. 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... | |
Private Types | |
using | SimdLoop = enum { SIMD_NONE, SIMD_INNER, SIMD_OUTER } |
Enum used to classify the loop according to the required transformation. More... | |
Private Member Functions | |
void | ClassifyLoop (const LoopConstRef loop, const size_t parallel_degree) |
Classify a loop. More... | |
void | ClassifyTreeNode (const unsigned int loop_id, const tree_nodeConstRef tree_node) |
Classify a statement. More... | |
bool | LookForScalar (const tree_nodeConstRef tree_node) |
Check recursively if at least an ssa operand is defined an operation outside simd outer loop. More... | |
unsigned int | Transform (const unsigned int tree_node_index, const size_t parallel_degree, const size_t scalar_index, std::list< tree_nodeRef > &new_stmt_list, std::vector< tree_nodeRef > &new_phi_list) |
Transform a tree node. More... | |
unsigned int | DuplicateIncrement (const unsigned int loop_id, const tree_nodeRef statement) |
Duplicate increment statement and update uses of defined variable when necessary. More... | |
void | AddGuards () |
Add the guards for predicated operations. More... | |
void | FixPhis () |
Fix the phis to consider implicitly predicated operations. More... | |
void | SetPredication () |
Set predicate of predicated instructions. More... | |
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... | |
Private Attributes | |
CustomUnorderedMapUnstable< unsigned int, unsigned int > | scalar_to_vector |
Map between scalar tree node and vector tree node. More... | |
CustomUnorderedMap< unsigned int, CustomUnorderedMapStable< size_t, unsigned int > > | scalar_to_scalar |
Map between scalar tree node and versioned scalar tree node. More... | |
const tree_managerRef | TM |
The tree manager. More... | |
const tree_manipulationRef | tree_man |
The tree_manipulation. More... | |
CustomMap< unsigned int, integer_cst_t > | iv_increment |
The increment of induction variables; id is the index of the ssa name defined in the init gimple. More... | |
CustomMap< unsigned int, SimdLoop > | simd_loop_type |
Loop classification. More... | |
CustomMap< unsigned int, size_t > | loop_parallel_degree |
Loop parallel degree. More... | |
CustomMap< unsigned int, bool > | basic_block_divergence |
Basic block classification: if value is true, the basic block can be executed or not in parallel instances. More... | |
CustomMap< unsigned int, Transformation > | transformations |
Statement classification. More... | |
CustomMap< unsigned int, tree_nodeRef > | guards |
The guards for each basic block. 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... | |
Definition at line 66 of file vectorize.hpp.
|
private |
Enum used to classify the loop according to the required transformation.
Definition at line 89 of file vectorize.hpp.
Vectorize::Vectorize | ( | const application_managerRef | AppM, |
unsigned int | function_id, | ||
const DesignFlowManagerConstRef | design_flow_manager, | ||
const ParameterConstRef | parameters | ||
) |
Constructor.
AppM | is the application manager |
function_id | is the identifier of the function |
DesignFlowManagerConstRef | is the design flow manager |
parameters | is the set of input parameters |
Definition at line 111 of file vectorize.cpp.
References DesignFlowStep::debug_level, GET_CLASS, and ~Vectorize().
|
overridedefault |
|
private |
Add the guards for predicated operations.
The guards for combination of basic_block condition
Endif
Header
Create the ssa defined by phi
Create the phi
We cannot use CreateAndExpr to add the created statement since we need to add at the beginning of the current basic block instad of the end
Fix phi
Definition at line 1117 of file vectorize.cpp.
References FrontendFlowStep::AppM, basic_block_divergence, FunctionBehavior::BB, BB_ENTRY, BUILTIN_SRCP, FunctionBehavior::CDG_BB, CDG_SELECTOR, tree_manipulation::CreateAndExpr(), DesignFlowStep::debug_level, DEBUG_LEVEL_VERY_PEDANTIC, FB_CFG_SELECTOR, FunctionBehavior::FBB, FunctionFrontendFlowStep::function_behavior, FunctionFrontendFlowStep::function_id, GET_NODE, tree_manipulation::GetBooleanType(), guards, INDENT_DBG_MEX, simd_loop_type, STR, lenet_tvm::target, THROW_ASSERT, THROW_UNREACHABLE, TM, TOK, TOK_RES, TOK_SCPE, TOK_SRCP, TOK_TYPE, TOK_VERS, TOK_VIRTUAL, TOK_VOLATILE, and tree_man.
Referenced by InternalExec().
|
private |
Classify a loop.
loop | is the loop to be analyzed |
parallel_degree | specifies the degree of parallelism |
FIXME: the parallel degree is set to default for doall loop and not read from pragma
The number of iterations can be not multiple of the parallel degree of outer loop
The header cannot diverge
The control condition which enables execution of header
Classify the remaining basic blocks
The control condition which enables execution of header
Classify the remaining basic blocks
If the current parallel degree is different from the parallel loop of the outer loop, this is an outer simd loop
Definition at line 332 of file vectorize.cpp.
References basic_block_divergence, FunctionBehavior::CDG_BB, CDG_SELECTOR, COUNTABLE_LOOP, DesignFlowStep::debug_level, DEBUG_LEVEL_VERY_PEDANTIC, DOALL_LOOP, FunctionFrontendFlowStep::function_behavior, INDENT_DBG_MEX, loop_parallel_degree, DesignFlowStep::parameters, simd_loop_type, STR, and THROW_ASSERT.
Referenced by InternalExec().
|
private |
Classify a statement.
loop_id | is the id of the looop of the statement |
tree_node | is the tree_node to be classified |
Check if the statement is the increment operation of an outer loop
This gimple assign could already be analyzed because of induction variable gimple phi
FIXME: allocation does not support this
FIXME: C backend for vec_lshift_expr is wrong
Check if the phi is the init operation of an outer loop
Check if the phi is in the header of an outer loop
Check if the gimple cond belongs to an exit of the loop
Check that one of the outgoing edge is a feedback edge
Definition at line 485 of file vectorize.cpp.
References basic_block_divergence, FunctionBehavior::BB, CASE_BINARY_EXPRESSION, CASE_CPP_NODES, CASE_CST_NODES, CASE_FAKE_NODES, CASE_PRAGMA_NODES, CASE_TYPE_NODES, CASE_UNARY_EXPRESSION, BBGraph::CGetBBGraphInfo(), BBGraph::CGetBBNodeInfo(), tree_helper::CGetType(), DesignFlowStep::debug_level, DEBUG_LEVEL_VERY_PEDANTIC, FunctionBehavior::FBB, FunctionFrontendFlowStep::function_behavior, GET_CONST_NODE, tree_node::get_kind(), tree_node::get_kind_text(), GET_NODE, tree_helper::GetConstValue(), INDENT_DBG_MEX, tree_node::index, INIT, iv_increment, NONE, SCALAR, simd_loop_type, STR, lenet_tvm::target, THROW_ASSERT, THROW_ERROR, THROW_UNREACHABLE, TM, ToString(), tree_node::ToString(), and transformations.
Referenced by DuplicateIncrement(), and 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 123 of file vectorize.cpp.
References DesignFlowStep::DEPENDENCE_RELATIONSHIP, FunctionFrontendFlowStep::function_id, GET_CONST_NODE, DesignFlowStep::GetStatus(), tree_helper::has_omp_simd(), DesignFlowStep::INVALIDATION_RELATIONSHIP, DesignFlowStep::PRECEDENCE_RELATIONSHIP, SAME_FUNCTION, SUCCESS, THROW_UNREACHABLE, TM, and WHOLE_APPLICATION.
|
private |
Duplicate increment statement and update uses of defined variable when necessary.
loop_id | is the id of the loop to which the statement belongs |
statement | is the statement to be duplicated |
First reclassify the original increment as simd
First create the new ssa_name
Duplicate increment
Replace uses
First create the new ssa_name
Duplicate computation of condition
Look for phi computing the guard of header
We create a local variable since first argument of replace_ssa_name is passed by reference. Statement root will not be modified by replace_ssa_name but only their successors
Definition at line 932 of file vectorize.cpp.
References FrontendFlowStep::AppM, ClassifyTreeNode(), tree_manipulation::create_ssa_name(), tree_node_dup::create_tree_node(), DesignFlowStep::debug_level, DEBUG_LEVEL_VERY_PEDANTIC, Loop::exit_block_iter_begin(), FunctionBehavior::FBB, FunctionFrontendFlowStep::function_behavior, GET_CONST_NODE, GET_INDEX_CONST_NODE, GET_NODE, Loop::GetHeader(), guards, INDENT_DBG_MEX, tree_node::index, Loop::IsReducible(), Loop::num_exits(), phi, STR, THROW_ASSERT, THROW_UNREACHABLE, TM, tree_node::ToString(), transformations, and tree_man.
Referenced by InternalExec().
|
private |
Fix the phis to consider implicitly predicated operations.
Check if the input basic block diverge
Create the ssa with the new input of the phi
Create the assign
Definition at line 1332 of file vectorize.cpp.
References FrontendFlowStep::AppM, basic_block_divergence, BUILTIN_SRCP, FunctionBehavior::CDG_BB, tree_helper::CGetType(), tree_manipulation::create_gimple_modify_stmt(), tree_manipulation::create_ssa_name(), tree_manipulation::create_ternary_operation(), DesignFlowStep::debug_level, DEBUG_LEVEL_VERY_PEDANTIC, FunctionBehavior::DOM_TREE, FunctionBehavior::FBB, FunctionFrontendFlowStep::function_behavior, FunctionFrontendFlowStep::function_id, GET_CONST_NODE, GET_NODE, guards, INDENT_DBG_MEX, phi, simd_loop_type, STR, THROW_ASSERT, THROW_UNREACHABLE, TM, ToString(), tree_man, and test_panda::type.
Referenced by InternalExec().
|
overridevirtual |
Check if this step has actually to be executed.
Reimplemented from FunctionFrontendFlowStep.
Definition at line 3228 of file vectorize.cpp.
References FunctionFrontendFlowStep::bb_version, DOALL_LOOP, and FunctionFrontendFlowStep::function_behavior.
|
overridevirtual |
Restructures the unstructured code.
Classify loop
Add the guards
Fix the phi
Predicate instructions which cannot be speculated
Classify statement
Duplicate the increment operation when necessary
Perform the transformation
Remove old statements
Remove old phis
Add new statements
Add new phis
Implements FunctionFrontendFlowStep.
Definition at line 169 of file vectorize.cpp.
References AddGuards(), FrontendFlowStep::AppM, basic_block_divergence, FunctionBehavior::BB, BBGraph::CGetBBNodeInfo(), ClassifyLoop(), ClassifyTreeNode(), DesignFlowStep::debug_level, DEBUG_LEVEL_VERY_PEDANTIC, DuplicateIncrement(), FixPhis(), FunctionFrontendFlowStep::function_behavior, GET_CONST_NODE, GET_NODE, FunctionFrontendFlowStep::GetName(), guards, INDENT_DBG_MEX, iv_increment, loop_parallel_degree, DesignFlowStep::parameters, phi, SetPredication(), simd_loop_type, STR, SUCCESS, TM, Transform(), transformations, UNCHANGED, and FunctionFrontendFlowStep::WriteBBGraphDot().
|
private |
Check recursively if at least an ssa operand is defined an operation outside simd outer loop.
tree_node | is the root of the tree to be checked |
Definition at line 1052 of file vectorize.cpp.
References CASE_BINARY_EXPRESSION, 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, tree_node::get_kind(), tree_node::get_kind_text(), THROW_UNREACHABLE, and symmetry::value.
|
private |
Set predicate of predicated instructions.
Definition at line 1484 of file vectorize.cpp.
References basic_block_divergence, FunctionBehavior::BB, DesignFlowStep::debug_level, DEBUG_LEVEL_VERY_PEDANTIC, FunctionFrontendFlowStep::function_behavior, GET_NODE, guards, INDENT_DBG_MEX, and STR.
Referenced by InternalExec().
|
private |
Transform a tree node.
tree_node_index | is the tree node to be transformed |
parallel_degree | is the degree of parallelism |
scalar_index | is the index of the vector when parallel statements are created as multiple statements |
created_statements | is the list of statements created during transformation |
The current init
Creating scalar from simd
Build bit_field_ref to extract the scalar
vector of Boolean types are mapped on vector of unsigned integer
Split of phi node goes to the beginning of the list of statement
Creating scalar from simd
Build bit_field_ref to extract the scalar
vector of Boolean types are mapped on vector of integer
Build simd from scalar
Build constructor for right part
Build bit_field_ref to extract the scalar
vector of Boolean types are mapped on vector of integer
Workaround due to cycle in the tree between void_type and type_decl
Size of new type
FIXME: check if the function has to parallelized
Build constructor
Creating scalar from simd
Build bit_field_ref to extract the scalar
vector of Boolean types are mapped on vector of integer
Split of phi node goes to the beginning of the list of statement
Definition at line 1519 of file vectorize.cpp.
References FrontendFlowStep::AppM, test_panda::arg, FunctionBehavior::BB, CASE_BINARY_EXPRESSION, 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, BBGraph::CGetBBGraphInfo(), BBGraph::CGetBBNodeInfo(), tree_helper::CGetType(), tree_manipulation::create_gimple_modify_stmt(), tree_manipulation::create_ternary_operation(), tree_manipulation::CreateOrExpr(), DesignFlowStep::debug_level, DEBUG_LEVEL_PEDANTIC, DEBUG_LEVEL_VERY_PEDANTIC, FunctionFrontendFlowStep::function_behavior, FunctionFrontendFlowStep::function_id, GET_CONST_NODE, tree_node::get_kind(), tree_node::get_kind_text(), GET_NODE, BBGraph::GetBBNodeInfo(), tree_helper::GetConstValue(), tree_manipulation::GetUnsignedIntegerType(), INDENT_DBG_MEX, index, tree_node::index, INIT, iv_increment, NONE, offset, FrontendFlowStep::PrintTreeManager(), pointer_type::ptd, SCALAR, scalar_to_scalar, scalar_to_vector, tree_helper::Size(), STR, THROW_ASSERT, THROW_UNREACHABLE, TM, TOK, TOK_ADDR, TOK_ALGN, TOK_ARTIFICIAL, TOK_ATTRIBUTES, TOK_BASE, TOK_C, TOK_CHAN, TOK_CLOBBER, TOK_ELTS, TOK_EXTERN, TOK_FN, TOK_IDX, TOK_IDX2, TOK_INIT, TOK_LIBBAMBU, TOK_LIBRARY_SYSTEM, TOK_MAX, TOK_MIN, TOK_MNGL, TOK_NAME, TOK_OFFSET, TOK_OP, TOK_OP0, TOK_OP1, TOK_OP2, TOK_OP3, TOK_OP4, TOK_OP5, TOK_OP6, TOK_OP7, TOK_OP8, TOK_OPERATING_SYSTEM, TOK_OPERATOR, TOK_ORIG, TOK_ORIG_VERS, TOK_PACKED, TOK_PREDICATE, TOK_PTD, TOK_QUAL, TOK_REGISTER, TOK_RES, TOK_SCPE, TOK_SIZE, TOK_SMT_ANN, TOK_SRCP, TOK_STATIC, TOK_STATIC_STATIC, TOK_STEP, TOK_STRG, TOK_SYSTEM, TOK_TMPL_ARGS, TOK_TMPL_PARMS, TOK_TYPE, TOK_UNQL, TOK_USE_TMPL, TOK_USED, TOK_VAR, TOK_VERS, TOK_VIRTUAL, TOK_VOLATILE, ToString(), transformations, tree_man, test_panda::type, and U.
Referenced by InternalExec().
Basic block classification: if value is true, the basic block can be executed or not in parallel instances.
Definition at line 98 of file vectorize.hpp.
Referenced by AddGuards(), ClassifyLoop(), ClassifyTreeNode(), FixPhis(), InternalExec(), and SetPredication().
|
private |
The guards for each basic block.
Definition at line 104 of file vectorize.hpp.
Referenced by AddGuards(), DuplicateIncrement(), FixPhis(), InternalExec(), and SetPredication().
|
private |
The increment of induction variables; id is the index of the ssa name defined in the init gimple.
Definition at line 82 of file vectorize.hpp.
Referenced by ClassifyTreeNode(), InternalExec(), and Transform().
Loop parallel degree.
Definition at line 95 of file vectorize.hpp.
Referenced by ClassifyLoop(), and InternalExec().
|
private |
Map between scalar tree node and versioned scalar tree node.
Definition at line 73 of file vectorize.hpp.
Referenced by Transform().
|
private |
Map between scalar tree node and vector tree node.
Definition at line 70 of file vectorize.hpp.
Referenced by Transform().
Loop classification.
Definition at line 92 of file vectorize.hpp.
Referenced by AddGuards(), ClassifyLoop(), ClassifyTreeNode(), FixPhis(), and InternalExec().
|
private |
The tree manager.
Definition at line 76 of file vectorize.hpp.
Referenced by AddGuards(), ClassifyTreeNode(), ComputeFrontendRelationships(), DuplicateIncrement(), FixPhis(), InternalExec(), and Transform().
|
private |
Statement classification.
Definition at line 101 of file vectorize.hpp.
Referenced by ClassifyTreeNode(), DuplicateIncrement(), InternalExec(), and Transform().
|
private |
The tree_manipulation.
Definition at line 79 of file vectorize.hpp.
Referenced by AddGuards(), DuplicateIncrement(), FixPhis(), and Transform().