Skip to content

Commit

Permalink
[Snippets] Fixed unsafe insertion iterators: added asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
a-sidorova committed Jul 3, 2023
1 parent 3a0d437 commit 9b06e79
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/common/snippets/src/lowered/pass/insert_buffers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ void InsertBuffers::insertion(LinearIR& linear_ir, const LinearIR::LoopManagerPt
const auto buffer_consumers_inputs = buffer_out->get_consumers();
linear_ir.replace_input(buffer_consumers_inputs, output_connector);
potential_consumers.insert(buffer_consumers_inputs.begin(), buffer_consumers_inputs.end());
linear_ir.erase(std::find(linear_ir.begin(), linear_ir.end(), buffer));
const auto buffer_pos = std::find(linear_ir.cbegin(), linear_ir.cend(), buffer);
OPENVINO_ASSERT(buffer_pos != linear_ir.cend(), "Buffer has not been found in Linear IR");
linear_ir.erase(buffer_pos);
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/common/snippets/src/lowered/pass/insert_load_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ bool InsertLoadStore::insert_load(LinearIR& linear_ir, const LinearIR::constExpr
const auto load = std::make_shared<op::Load>(data_node->output(0), get_count(data_expr->get_output_port_descriptor(0)));
PortDescriptorUtils::set_port_descriptor_ptr(load->output(0), consumer_input.get_descriptor_ptr()->clone());
const auto load_expr = linear_ir.create_expression(load, {output_connector});
linear_ir.insert(std::find(data_expr_it, linear_ir.cend(), consumer_expr), load_expr);
const auto insertion_pos = std::find(data_expr_it, linear_ir.cend(), consumer_expr);
OPENVINO_ASSERT(insertion_pos != linear_ir.cend(), "Consumer should be after data producer in Linear IR");
linear_ir.insert(insertion_pos, load_expr);
linear_ir.replace_input(consumer_input, load_expr->get_output_port_connector(0));
// Copy Loop identifies
load_expr->set_loop_ids(loop_ids);
Expand Down Expand Up @@ -81,6 +83,7 @@ bool InsertLoadStore::insert_store(LinearIR& linear_ir, const LinearIR::constExp
PortDescriptorUtils::set_port_descriptor_ptr(store->output(0), parent_output.get_descriptor_ptr()->clone());
const auto store_expr = linear_ir.create_expression(store, {input_connector});
const auto& reverse_insertion_pos = std::find(std::reverse_iterator<LinearIR::constExprIt>(data_expr_it), linear_ir.crend(), parent_expr);
OPENVINO_ASSERT(reverse_insertion_pos != linear_ir.crend(), "Consumer should be after data producer in Linear IR");
const auto& insertion_pos = reverse_insertion_pos.base();
linear_ir.insert(insertion_pos, store_expr);
linear_ir.replace_input(data_expr->get_input_port(0), store_expr->get_output_port_connector(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ bool LoadMoveBroadcastToBroadcastLoad::run(LinearIR& linear_ir) {
const auto mv_expr_it = expr_it;
const auto insertion_pos = std::next(expr_it);
expr_it = linear_ir.insert(insertion_pos, broadcastload_expr);
linear_ir.erase(std::find(linear_ir.begin(), mv_expr_it, parent_expr));
const auto load_it = std::find(linear_ir.begin(), mv_expr_it, parent_expr);
OPENVINO_ASSERT(load_it != mv_expr_it, "Failed fuse Load and MoveBroadcast: Load should be before MoveBroadcast in Linear IR");
linear_ir.erase(load_it);
linear_ir.erase(mv_expr_it);
linear_ir.replace_input(move_consumers, broadcastload_expr->get_output_port_connector(0));
modified |= true;
Expand Down

0 comments on commit 9b06e79

Please sign in to comment.