Skip to content

Commit 00dbc94

Browse files
authored
[CPU] Fix modernize-loop-convert clang-tidy remarks (#28966)
### Details: - Fix "modernize-loop-convert" remarks reported by clang-tidy - Enable "modernize-loop-convert" clang-tidy checks on CI by default ### Tickets: - N/A
1 parent 3ab0967 commit 00dbc94

39 files changed

+259
-247
lines changed

src/plugins/intel_cpu/src/.clang-tidy

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Checks: >
3535
-*,
3636
performance-*,
3737
google-*,
38+
modernize-loop-convert,
3839
modernize-pass-by-value,
3940
cppcoreguidelines-prefer-member-initializer,
4041
-bugprone-easily-swappable-parameters,

src/plugins/intel_cpu/src/cpu_streams_calculation.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,9 @@ std::vector<std::vector<int>> get_streams_info_table(
212212
((input_streams_changed == true) && (input_streams == 1))) {
213213
n_streams = 1;
214214
stream_info[NUMBER_OF_STREAMS] = n_streams;
215-
for (size_t n = 0; n < proc_socket_table.size(); n++) {
216-
if (proc_socket_table[n][ALL_PROC] > 0) {
217-
current_socket_id = proc_socket_table[n][PROC_SOCKET_ID];
215+
for (auto& n : proc_socket_table) {
216+
if (n[ALL_PROC] > 0) {
217+
current_socket_id = n[PROC_SOCKET_ID];
218218
break;
219219
}
220220
}

src/plugins/intel_cpu/src/dnnl_postops_composer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -527,8 +527,8 @@ bool DnnlPostOpsComposer::appendScale(const std::vector<float>& scale, bool isLa
527527
wei_scale_values[j] *= scale[j];
528528
}
529529
} else {
530-
for (size_t j = 0; j < wei_scale_values.size(); j++) {
531-
wei_scale_values[j] *= scale[0];
530+
for (float& wei_scale_value : wei_scale_values) {
531+
wei_scale_value *= scale[0];
532532
}
533533
}
534534

src/plugins/intel_cpu/src/dnnl_postops_composer_legacy.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ bool DnnlPostOpsComposerLegacy::appendScale(const std::vector<float>& scale, boo
169169
wei_scale_values[j] *= scale[j];
170170
}
171171
} else {
172-
for (size_t j = 0; j < wei_scale_values.size(); j++) {
173-
wei_scale_values[j] *= scale[0];
172+
for (float& wei_scale_value : wei_scale_values) {
173+
wei_scale_value *= scale[0];
174174
}
175175
}
176176

src/plugins/intel_cpu/src/emitters/plugin/aarch64/jit_emitter.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ void jit_emitter::emit_data() const {
6262
assert(sizeof(table_entry_val_t) == 4);
6363

6464
// Run through the map and insert values stored there
65-
for (auto it = entry_map_.begin(); it != entry_map_.end(); it++) {
66-
const auto& te = (*it).second; // get map entry for a given key
65+
for (const auto& it : entry_map_) {
66+
const auto& te = it.second; // get map entry for a given key
6767
const auto len = te.bcast ? get_vec_length() : sizeof(table_entry_val_t);
6868
for (size_t d = 0; d < len; d += sizeof(table_entry_val_t)) {
6969
h->dd(te.val);
@@ -103,8 +103,8 @@ void jit_emitter::prepare_table() {
103103
// expect the same order when injecting the table entries in
104104
// prepare_table.
105105
size_t off = 0;
106-
for (auto it = entry_map_.begin(); it != entry_map_.end(); it++) {
107-
auto& te = (*it).second;
106+
for (auto& it : entry_map_) {
107+
auto& te = it.second;
108108
te.off = off;
109109
off += te.bcast ? get_vec_length() : sizeof(table_entry_val_t);
110110
}

src/plugins/intel_cpu/src/emitters/plugin/aarch64/jit_emitter.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ class jit_emitter : public ov::snippets::Emitter {
141141
}
142142

143143
void push_entries_of(const table_t& t) {
144-
for (auto it = t.begin(); it != t.end(); it++) {
145-
auto key = (*it).first;
146-
auto te = (*it).second; // copy values from table
144+
for (const auto& it : t) {
145+
auto key = it.first;
146+
auto te = it.second; // copy values from table
147147
push_arg_entry_of(key, te.val, te.bcast);
148148
}
149149
}

src/plugins/intel_cpu/src/emitters/plugin/x64/jit_emitter.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ void jit_emitter::emitter_preamble(const std::vector<size_t>& in_idxs,
9393
}
9494

9595
// moving mask vector at the beginning of aux vectors list to simplify further processing
96-
for (size_t i = 0; i < aux_vec_idxs.size(); i++) {
97-
if (aux_vec_idxs[i] == 0) {
96+
for (size_t& aux_vec_idx : aux_vec_idxs) {
97+
if (aux_vec_idx == 0) {
9898
size_t tmp = aux_vec_idxs[0];
99-
aux_vec_idxs[0] = aux_vec_idxs[i];
100-
aux_vec_idxs[i] = tmp;
99+
aux_vec_idxs[0] = aux_vec_idx;
100+
aux_vec_idx = tmp;
101101
break;
102102
}
103103
}
@@ -176,8 +176,8 @@ void jit_emitter::emitter_preamble(const std::vector<size_t>& in_idxs,
176176
aux_gpr_idxs.erase(aux_gpr_idxs.end() - 1);
177177
}
178178

179-
for (size_t i = 0; i < preserved_gpr_idxs.size(); ++i) {
180-
h->push(Reg64(preserved_gpr_idxs[i]));
179+
for (uint64_t preserved_gpr_idx : preserved_gpr_idxs) {
180+
h->push(Reg64(preserved_gpr_idx));
181181
}
182182

183183
if (preserved_vec_idxs.size()) {
@@ -223,8 +223,8 @@ void jit_emitter::emit_data() const {
223223
assert(sizeof(table_entry_val_t) == 4);
224224

225225
// Run through the map and insert values stored there
226-
for (auto it = entry_map_.begin(); it != entry_map_.end(); it++) {
227-
const auto& te = (*it).second; // get map entry for a given key
226+
for (const auto& it : entry_map_) {
227+
const auto& te = it.second; // get map entry for a given key
228228
const auto len = te.bcast ? get_vec_length() : sizeof(table_entry_val_t);
229229
for (size_t d = 0; d < len; d += sizeof(table_entry_val_t)) {
230230
h->dd(te.val);
@@ -240,8 +240,8 @@ void jit_emitter::prepare_table() {
240240
// expect the same order when injecting the table entries in
241241
// prepare_table.
242242
size_t off = 0;
243-
for (auto it = entry_map_.begin(); it != entry_map_.end(); it++) {
244-
auto& te = (*it).second;
243+
for (auto& it : entry_map_) {
244+
auto& te = it.second;
245245
te.off = off;
246246
off += te.bcast ? get_vec_length() : sizeof(table_entry_val_t);
247247
}

src/plugins/intel_cpu/src/emitters/plugin/x64/jit_emitter.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ class jit_emitter : public ov::snippets::Emitter {
152152
}
153153

154154
void push_entries_of(const table_t& t) {
155-
for (auto it = t.begin(); it != t.end(); it++) {
156-
auto key = (*it).first;
157-
auto te = (*it).second; // copy values from table
155+
for (const auto& it : t) {
156+
auto key = it.first;
157+
auto te = it.second; // copy values from table
158158
push_arg_entry_of(key, te.val, te.bcast);
159159
}
160160
}

src/plugins/intel_cpu/src/graph.cpp

+15-12
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,13 @@ void Graph::Replicate(const std::shared_ptr<const ov::Model>& model,
241241
const auto& inputNode = input.second;
242242
const auto precToSet = inputNode->getOriginalOutputPrecisionAtPort(0);
243243
const auto childEdges = inputNode->getChildEdgesAtPort(0);
244-
for (size_t i = 0; i < childEdges.size(); i++) {
245-
const auto child = childEdges[i]->getChild();
246-
const auto child_prec = child->getOriginalInputPrecisionAtPort(childEdges[i]->getOutputNum());
244+
for (const auto& childEdge : childEdges) {
245+
const auto child = childEdge->getChild();
246+
const auto child_prec = child->getOriginalInputPrecisionAtPort(childEdge->getOutputNum());
247247
if (!one_of(child_prec, ov::element::bf16, ov::element::f16) &&
248248
// remove this WA when #78939 is resolved
249249
!hasSubgraphConsumers(child)) {
250-
child->setOriginalInputPrecisionAtPort(childEdges[i]->getOutputNum(), precToSet);
250+
child->setOriginalInputPrecisionAtPort(childEdge->getOutputNum(), precToSet);
251251
}
252252
}
253253
}
@@ -631,9 +631,9 @@ void Graph::ResolveEdgeConflicts() {
631631

632632
/* When inserting convert / reorder, two new edges are added (pushed to the end) to the graphEdges.
633633
So use a plain for loop, to handle newly inserted edges as well */
634-
for (size_t i = 0; i < graphEdges.size(); i++) {
634+
for (size_t i = 0; i < graphEdges.size(); i++) { // NOLINT(modernize-loop-convert)
635635
auto& edge = graphEdges[i];
636-
auto reorderStatus = edge->needReorder();
636+
auto reorderStatus = edge->needReorder(); // NOLINT(modernize-loop-convert)
637637
DEBUG_LOG(*edge, " reorderStatus = ", reorderStatus);
638638

639639
switch (reorderStatus) {
@@ -1757,11 +1757,11 @@ void Graph::GetPerfData(std::vector<ov::ProfilingInfo>& perfMap) const {
17571757
}
17581758
};
17591759

1760-
for (size_t i = 0; i < graphNodes.size(); i++) {
1761-
if (graphNodes[i]->isConstant()) {
1760+
for (const auto& graphNode : graphNodes) {
1761+
if (graphNode->isConstant()) {
17621762
continue;
17631763
}
1764-
getPerfMapFor(perfMap, graphNodes[i]);
1764+
getPerfMapFor(perfMap, graphNode);
17651765
}
17661766
}
17671767

@@ -1793,7 +1793,8 @@ void Graph::DropNode(const NodePtr& node) {
17931793
auto children = node->childEdges;
17941794
auto parents = node->parentEdges;
17951795

1796-
for (size_t i = 0; i < parents.size(); i++) {
1796+
// The collections are being updated while iterating. So, range based for loops cannot be used.
1797+
for (size_t i = 0; i < parents.size(); i++) { // NOLINT(modernize-loop-convert)
17971798
auto p_edge = parents[i].lock();
17981799
if (!p_edge) {
17991800
continue;
@@ -1806,7 +1807,8 @@ void Graph::DropNode(const NodePtr& node) {
18061807
const int inNum = p_edge->getInputNum();
18071808
RemoveEdge(p_edge);
18081809

1809-
for (size_t j = 0; j < children.size(); j++) {
1810+
// The collections are being updated while iterating. So, range based for loops cannot be used.
1811+
for (size_t j = 0; j < children.size(); j++) { // NOLINT(modernize-loop-convert)
18101812
auto c_edge = children[j].lock();
18111813
if (!c_edge) {
18121814
continue;
@@ -1851,7 +1853,8 @@ void Graph::DropDWConvNode(const NodePtr& node) {
18511853
const int inNum = p_edge->getInputNum();
18521854
RemoveEdge(p_edge);
18531855

1854-
for (size_t j = 0; j < children.size(); j++) {
1856+
// The collections are being updated while iterating. So, range based for loops cannot be used.
1857+
for (size_t j = 0; j < children.size(); j++) { // NOLINT(modernize-loop-convert)
18551858
auto c_edge = children[j].lock();
18561859
if (!c_edge) {
18571860
continue;

0 commit comments

Comments
 (0)