From 9b06e792a0a958a5309bb8f66fd975d05b38e676 Mon Sep 17 00:00:00 2001 From: Alexandra Sidorova Date: Tue, 13 Jun 2023 10:26:26 +0400 Subject: [PATCH] [Snippets] Fixed unsafe insertion iterators: added asserts --- src/common/snippets/src/lowered/pass/insert_buffers.cpp | 4 +++- src/common/snippets/src/lowered/pass/insert_load_store.cpp | 5 ++++- .../src/lowered/pass/load_movebroadcast_to_broadcastload.cpp | 4 +++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/common/snippets/src/lowered/pass/insert_buffers.cpp b/src/common/snippets/src/lowered/pass/insert_buffers.cpp index 1b1d65a504cb86..2de97447dea436 100644 --- a/src/common/snippets/src/lowered/pass/insert_buffers.cpp +++ b/src/common/snippets/src/lowered/pass/insert_buffers.cpp @@ -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); } } diff --git a/src/common/snippets/src/lowered/pass/insert_load_store.cpp b/src/common/snippets/src/lowered/pass/insert_load_store.cpp index 4899cc13c3635d..ab4b362484a080 100644 --- a/src/common/snippets/src/lowered/pass/insert_load_store.cpp +++ b/src/common/snippets/src/lowered/pass/insert_load_store.cpp @@ -49,7 +49,9 @@ bool InsertLoadStore::insert_load(LinearIR& linear_ir, const LinearIR::constExpr const auto load = std::make_shared(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); @@ -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(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)); diff --git a/src/common/snippets/src/lowered/pass/load_movebroadcast_to_broadcastload.cpp b/src/common/snippets/src/lowered/pass/load_movebroadcast_to_broadcastload.cpp index f0384911ac8f3e..f3977e8ed8ed1b 100644 --- a/src/common/snippets/src/lowered/pass/load_movebroadcast_to_broadcastload.cpp +++ b/src/common/snippets/src/lowered/pass/load_movebroadcast_to_broadcastload.cpp @@ -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;