46 std::unique_ptr<StructuredSDFG, ConditionalDeleter<StructuredSDFG>> structured_sdfg_;
50 std::unordered_set<const control_flow::State*>
57 void structure_region(
62 const std::unordered_set<const InterstateEdge*>& continues,
63 const std::unordered_set<const InterstateEdge*>& breaks,
64 const std::unordered_map<const control_flow::State*, const control_flow::State*>& pdom_tree,
65 std::unordered_set<const control_flow::State*>& visited,
66 bool is_loop_body =
false
71 static constexpr int32_t INSERT_AT_END = -10;
73 template<
typename T,
typename... Args>
74 T& insert_node_internal(
Sequence& parent, int32_t insert_idx,
const DebugInfo& debug_info, Args&&... args) {
75 auto child = std::unique_ptr<T>(
76 new T(this->
new_element_id_batch(T::REQUIRED_ELEMENT_IDS), debug_info, &parent, std::forward<Args>(args)...)
78 auto& new_child = *child;
80 if (insert_idx == INSERT_AT_END) {
81 parent.children_.push_back(std::move(child));
83 parent.children_.insert(parent.children_.begin() + insert_idx, std::move(child));
89 Block& insert_block_internal(
124 std::unique_ptr<StructuredSDFG>
move();
126 void rename_container(
const std::string& old_name,
const std::string& new_name)
const override;
320 const std::vector<structured_control_flow::ReductionInfo>& reductions,
332 const std::vector<structured_control_flow::ReductionInfo>& reductions,
344 const std::vector<structured_control_flow::ReductionInfo>& reductions,
371 Sequence& parent,
For& loop,
const std::vector<structured_control_flow::ReductionInfo>& reductions
409 const std::string& data,
417 const std::string& output,
418 const std::vector<std::string>& inputs,
425 const std::string& src_conn,
427 const std::string& dst_conn,
437 const std::string& dst_conn,
446 const std::string& src_conn,
457 const std::string& dst_conn,
465 const std::string& src_conn,
489 template<
typename T,
typename... Args>
492 static_assert(std::is_base_of<data_flow::LibraryNode, T>::value,
"T must be a subclass of data_flow::LibraryNode");
495 auto vertex = boost::add_vertex(dataflow.graph_);
496 dataflow.invalidate_topological_order();
498 std::unique_ptr<T>(
new T(this->
new_element_id(), debug_info, vertex, dataflow, std::move(arguments)...));
499 auto res = dataflow.nodes_.insert({vertex, std::move(node)});
506 auto vertex = boost::add_vertex(dataflow.graph_);
507 dataflow.invalidate_topological_order();
509 auto res = dataflow.nodes_.insert({vertex, std::move(node_clone)});
510 return *res.first->second;
556 const std::unordered_set<const data_flow::DataFlowNode*>& ignore_side_effects
Definition structured_sdfg.h:30
Definition function_builder.h:12
size_t new_element_id_batch(size_t batch) const
size_t new_element_id() const
data_flow::DataFlowNode & copy_node(structured_control_flow::Block &block, const data_flow::DataFlowNode &node)
Definition structured_sdfg_builder.h:504
void move_children(Sequence &source, Sequence &target)
Reduce & add_reduce_before(Sequence &parent, ControlFlowNode &child, const symbolic::Symbol indvar, const symbolic::Condition condition, const symbolic::Expression init, const symbolic::Expression update, const std::vector< structured_control_flow::ReductionInfo > &reductions, const ScheduleType &schedule_type, const DebugInfo &debug_info=DebugInfo())
void update_loop(StructuredLoop &loop, const symbolic::Symbol indvar, const symbolic::Condition condition, const symbolic::Expression init, const symbolic::Expression update)
AssignmentBlock & add_assignments_before(Sequence &parent, ControlFlowNode &child, const Assignments &assignments, const DebugInfo &debug_info=DebugInfo())
void update_schedule_type(StructuredLoop &loop, const ScheduleType &schedule_type, bool keep_nest_annotations=true)
Replace the schedule type of a loop.
Return & add_constant_return(Sequence &parent, const std::string &data, const types::IType &type, const DebugInfo &debug_info=DebugInfo())
Reduce & add_reduce_after(Sequence &parent, ControlFlowNode &child, const symbolic::Symbol indvar, const symbolic::Condition condition, const symbolic::Expression init, const symbolic::Expression update, const std::vector< structured_control_flow::ReductionInfo > &reductions, const ScheduleType &schedule_type, const DebugInfo &debug_info=DebugInfo())
std::unique_ptr< StructuredSDFG > move()
AssignmentBlock & add_assignments_at(Sequence &parent, InsertionPoint insertion_point, const Assignments &assignments, const DebugInfo &debug_info=DebugInfo())
Block & add_block(Sequence &parent, const data_flow::DataFlowGraph &data_flow_graph, const DebugInfo &debug_info=DebugInfo())
Block & add_block_at(Sequence &parent, InsertionPoint insertion_point, const DebugInfo &debug_info=DebugInfo())
Block & add_block_after(Sequence &parent, ControlFlowNode &child, const DebugInfo &debug_info=DebugInfo())
data_flow::LibraryNode & add_library_node(structured_control_flow::Block &block, const DebugInfo &debug_info, Args... arguments)
Definition structured_sdfg_builder.h:491
IfElse & add_if_else(Sequence &parent, const DebugInfo &debug_info=DebugInfo())
Sequence & add_sequence_after(Sequence &parent, ControlFlowNode &block, const DebugInfo &debug_info=DebugInfo())
void update_if_else_condition(IfElse &if_else, size_t branch, const symbolic::Condition cond)
Block & add_block_after(Sequence &parent, ControlFlowNode &child, data_flow::DataFlowGraph &data_flow_graph, const DebugInfo &debug_info=DebugInfo())
Block & add_block(Sequence &parent, const DebugInfo &debug_info=DebugInfo())
void remove_schedule_property(StructuredLoop &loop, const std::string &key)
Remove a single property (if present) from the schedule type of a loop.
data_flow::Memlet & add_memlet(structured_control_flow::Block &block, data_flow::DataFlowNode &src, const std::string &src_conn, data_flow::DataFlowNode &dst, const std::string &dst_conn, const data_flow::Subset &subset, const types::IType &base_type, const DebugInfo &debug_info)
data_flow::Memlet & add_computational_memlet(structured_control_flow::Block &block, data_flow::CodeNode &src, const std::string &src_conn, data_flow::AccessNode &dst, const data_flow::Subset &subset, const types::IType &base_type, const DebugInfo &debug_info=DebugInfo())
data_flow::ConstantNode & add_constant(structured_control_flow::Block &block, const std::string &data, const types::IType &type, const DebugInfo &debug_info=DebugInfo())
StructuredSDFGBuilder(const std::string &name, FunctionType type, const types::IType &return_type)
StructuredSDFGBuilder(const std::string &name, FunctionType type)
Sequence & add_sequence_before(Sequence &parent, ControlFlowNode &block, const DebugInfo &debug_info=DebugInfo())
data_flow::Memlet & add_computational_memlet(structured_control_flow::Block &block, data_flow::AccessNode &src, data_flow::Tasklet &dst, const std::string &dst_conn, const data_flow::Subset &subset, const DebugInfo &debug_info=DebugInfo())
Function & function() const override
For & add_for_at(Sequence &parent, InsertionPoint insertion_point, const symbolic::Symbol indvar, const symbolic::Condition condition, const symbolic::Expression init, const symbolic::Expression update, const ScheduleType &schedule_type, const DebugInfo &debug_info=DebugInfo())
While & add_while(Sequence &parent, const DebugInfo &debug_info=DebugInfo())
data_flow::Memlet & add_computational_memlet(structured_control_flow::Block &block, data_flow::Tasklet &src, const std::string &src_conn, data_flow::AccessNode &dst, const data_flow::Subset &subset, const DebugInfo &debug_info=DebugInfo())
void merge_siblings(data_flow::AccessNode &in_node)
Element * find_element_by_id(const size_t &element_id) const
data_flow::AccessNode & add_access(structured_control_flow::Block &block, const std::string &data, const DebugInfo &debug_info=DebugInfo())
void move_child(Sequence &source, size_t source_index, Sequence &target)
void move_children(Sequence &source, Sequence &target, size_t target_index)
Return & add_return(Sequence &parent, const std::string &data, const DebugInfo &debug_info=DebugInfo())
Block & add_block_before(Sequence &parent, ControlFlowNode &child, data_flow::DataFlowGraph &data_flow_graph, const DebugInfo &debug_info=DebugInfo())
Map & convert_for(Sequence &parent, For &loop)
Break & add_break(Sequence &parent, const DebugInfo &debug_info=DebugInfo())
Sequence & add_case(IfElse &scope, const sdfg::symbolic::Condition cond, const DebugInfo &debug_info=DebugInfo())
For & convert_while(Sequence &parent, While &loop, const symbolic::Symbol indvar, const symbolic::Condition condition, const symbolic::Expression init, const symbolic::Expression update)
AssignmentBlock & add_assignments_after(Sequence &parent, ControlFlowNode &child, const Assignments &assignments, const DebugInfo &debug_info=DebugInfo())
Map & add_map_at(Sequence &parent, InsertionPoint insertion_point, const symbolic::Symbol indvar, const symbolic::Condition condition, const symbolic::Expression init, const symbolic::Expression update, const ScheduleType &schedule_type, const DebugInfo &debug_info=DebugInfo())
AssignmentBlock & add_assignments(Sequence &parent, const Assignments &assignments, const DebugInfo &debug_info=DebugInfo())
void clear_code_node_legacy(structured_control_flow::Block &block, const data_flow::CodeNode &node)
Removes a code node and all its input and output edges.
For & add_for_before(Sequence &parent, ControlFlowNode &child, const symbolic::Symbol indvar, const symbolic::Condition condition, const symbolic::Expression init, const symbolic::Expression update, const DebugInfo &debug_info=DebugInfo())
Continue & add_continue(Sequence &parent, const DebugInfo &debug_info=DebugInfo())
void move_child(Sequence &source, size_t source_index, Sequence &target, size_t target_index)
For & add_for_after(Sequence &parent, ControlFlowNode &child, const symbolic::Symbol indvar, const symbolic::Condition condition, const symbolic::Expression init, const symbolic::Expression update, const DebugInfo &debug_info=DebugInfo())
void remove_from_parent(ControlFlowNode &child)
Reduce & add_reduce(Sequence &parent, const symbolic::Symbol indvar, const symbolic::Condition condition, const symbolic::Expression init, const symbolic::Expression update, const std::vector< structured_control_flow::ReductionInfo > &reductions, const ScheduleType &schedule_type, const DebugInfo &debug_info=DebugInfo())
data_flow::Memlet & add_reference_memlet(structured_control_flow::Block &block, data_flow::AccessNode &src, data_flow::AccessNode &dst, const data_flow::Subset &subset, const types::IType &base_type, const DebugInfo &debug_info=DebugInfo())
int clear_ptr_borrow_edge(Block &block, const data_flow::Memlet &edge)
void remove_node(structured_control_flow::Block &block, const data_flow::DataFlowNode &node)
void rename_container(const std::string &old_name, const std::string &new_name) const override
Sequence & add_sequence(Sequence &parent, const DebugInfo &debug_info=DebugInfo())
int clear_node(structured_control_flow::Block &block, const data_flow::DataFlowNode &node)
Shorthand for clear_node with the node itself being the only one to ignore side-effects on.
StructuredSDFGBuilder(StructuredSDFG &sdfg)
To modify an existing SDFG.
int32_t InsertionPoint
Definition structured_sdfg_builder.h:97
Map & add_map_before(Sequence &parent, ControlFlowNode &child, const symbolic::Symbol indvar, const symbolic::Condition condition, const symbolic::Expression init, const symbolic::Expression update, const ScheduleType &schedule_type, const DebugInfo &debug_info=DebugInfo())
Block & add_block_before(Sequence &parent, ControlFlowNode &child, const DebugInfo &debug_info=DebugInfo())
Map & add_map(Sequence &parent, const symbolic::Symbol indvar, const symbolic::Condition condition, const symbolic::Expression init, const symbolic::Expression update, const ScheduleType &schedule_type, const DebugInfo &debug_info=DebugInfo())
void remove_children(Sequence &parent)
data_flow::Memlet & add_computational_memlet(structured_control_flow::Block &block, data_flow::AccessNode &src, data_flow::CodeNode &dst, const std::string &dst_conn, const data_flow::Subset &subset, const types::IType &base_type, const DebugInfo &debug_info=DebugInfo())
void rename_containers(const std::vector< std::pair< std::string, std::string > > &renames) const
Applies several renames with a single tree traversal; old names must be distinct and not renamed targ...
Reduce & convert_for_to_reduce(Sequence &parent, For &loop, const std::vector< structured_control_flow::ReductionInfo > &reductions)
For & add_for(Sequence &parent, const symbolic::Symbol indvar, const symbolic::Condition condition, const symbolic::Expression init, const symbolic::Expression update, const DebugInfo &debug_info=DebugInfo())
virtual void replace_symbols(const symbolic::ExpressionMapping &replacements) override
void remove_memlet(structured_control_flow::Block &block, const data_flow::Memlet &edge)
virtual void replace_symbols(const symbolic::Expression old_expression, const symbolic::Expression new_expression) override
Replace symbolic expressions on the whole SDFG.
data_flow::Memlet & add_dereference_memlet(structured_control_flow::Block &block, data_flow::AccessNode &src, data_flow::AccessNode &dst, bool derefs_src, const types::IType &base_type, const DebugInfo &debug_info=DebugInfo())
Map & convert_reduce_to_map(Sequence &parent, Reduce &reduce)
StructuredSDFGBuilder(SDFG &sdfg)
data_flow::Tasklet & add_tasklet(structured_control_flow::Block &block, const data_flow::TaskletCode code, const std::string &output, const std::vector< std::string > &inputs, const DebugInfo &debug_info=DebugInfo())
void clear_access_node_legacy(structured_control_flow::Block &block, const data_flow::AccessNode &node)
Removes a code node and maybe some of its inputs as well.
int clear_node(structured_control_flow::Block &block, const data_flow::DataFlowNode &node, const std::unordered_set< const data_flow::DataFlowNode * > &ignore_side_effects)
New function to remove all unneeded edges and nodes transitively.
StructuredSDFG & subject() const
void remove_case(IfElse &scope, size_t i, const DebugInfo &debug_info=DebugInfo())
StructuredSDFGBuilder(std::unique_ptr< StructuredSDFG > &sdfg)
Will take ownership of the SDFG Increases compatibility with legacy code.
void merge_sinks(structured_control_flow::Block &block)
Walks all sink nodes of a block's dataflow graph and merges access nodes that refer to the same conta...
IfElse & add_if_else_after(Sequence &parent, ControlFlowNode &child, const DebugInfo &debug_info=DebugInfo())
Sequence & add_sequence_at(Sequence &parent, InsertionPoint insertion_point, const DebugInfo &debug_info=DebugInfo())
data_flow::Memlet & replace_memlet_src_with_constant(structured_control_flow::Block &block, data_flow::Memlet &edge, const std::string &data, const types::IType &type)
Replaces the source of a computational read memlet with a new ConstantNode carrying data/type.
void remove_child(Sequence &parent, size_t index)
Map & add_map_after(Sequence &parent, ControlFlowNode &child, const symbolic::Symbol indvar, const symbolic::Condition condition, const symbolic::Expression init, const symbolic::Expression update, const ScheduleType &schedule_type, const DebugInfo &debug_info=DebugInfo())
IfElse & add_if_else_before(Sequence &parent, ControlFlowNode &child, const DebugInfo &debug_info=DebugInfo())
A state in a Stateful DataFlow Graph (SDFG).
Definition state.h:38
Node representing access to a data container in the dataflow graph.
Definition access_node.h:84
Base class for computational nodes with inputs and outputs.
Definition code_node.h:88
Node representing a constant literal value in the dataflow graph.
Definition access_node.h:205
Definition data_flow_graph.h:29
Abstract base class for all dataflow graph nodes.
Definition data_flow_node.h:106
virtual std::unique_ptr< DataFlowNode > clone(size_t element_id, const graph::Vertex vertex, DataFlowGraph &parent) const =0
Clone this node for graph transformations.
Base class for all library nodes in the dataflow graph.
Definition library_node.h:106
Edge in the dataflow graph representing data movement.
Definition memlet.h:131
Simple computational operation in the dataflow graph.
Definition tasklet.h:348
A control flow node representing a basic block with dataflow computations.
Definition block.h:42
const data_flow::DataFlowGraph & dataflow() const
Access the dataflow graph (const version).
Represents a break statement that exits the innermost loop.
Definition while.h:93
Represents a continue statement that skips to the next loop iteration.
Definition while.h:128
Base class for all structured control flow nodes in a StructuredSDFG.
Definition control_flow_node.h:44
Represents a traditional for-loop with sequential execution.
Definition for.h:43
Represents a conditional if-else control flow node with multiple cases.
Definition if_else.h:47
Represents a parallel map loop with configurable scheduling.
Definition map.h:47
Represents a loop with an associative/commutative reduction carried dependency.
Definition reduce.h:106
Represents a return statement that exits the function with a value.
Definition return.h:32
Represents a schedule type for Map nodes.
Definition structured_loop.h:31
A sequential container of control flow nodes.
Definition sequence.h:52
Base class for structured loop constructs.
Definition structured_loop.h:244
Represents a while-loop with condition-controlled iteration.
Definition while.h:37
Abstract base interface for all types in the sdfglib type system.
Definition type.h:625
SymEngine::RCP< const SymEngine::Basic > Expression
Reference-counted pointer to a symbolic expression (SymEngine Basic).
Definition symbolic.h:83
SymEngine::RCP< const SymEngine::Symbol > Symbol
Reference-counted pointer to a SymEngine Symbol.
Definition symbolic.h:71
SymEngine::RCP< const SymEngine::Boolean > Condition
Reference-counted pointer to a boolean condition expression.
Definition symbolic.h:86
SymEngine::map_basic_basic ExpressionMapping
Definition symbolic.h:109
Library node definitions for calling functions beyond simple instructions.
Definition function_builder.h:10
Definition interstate_edge.h:22
symbolic::SymbolMap Assignments
Type alias for symbol assignments on interstate edges.
Definition interstate_edge.h:30
symbolic::MultiExpression Subset
Type alias for a subset specification (array of symbolic expressions).
Definition memlet.h:103
TaskletCode
Operation codes for tasklet computations.
Definition tasklet.h:94
Definition language_extension.h:18
StringEnum FunctionType
Definition function.h:37
Scalar (primitive) type representation.
Definition structured_sdfg_builder.h:28
ConditionalDeleter(bool should_delete=true)
Definition structured_sdfg_builder.h:31
bool should_delete_
Definition structured_sdfg_builder.h:29
void operator()(T *ptr) const
Definition structured_sdfg_builder.h:34