Skip to content

Commit 195f88e

Browse files
committed
use std::distance
1 parent f663b14 commit 195f88e

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

mlir/lib/Conversion/Normalize/Normalize.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "mlir/Support/LLVM.h"
1616
#include "llvm/ADT/Hashing.h"
1717

18+
#include <algorithm>
1819
#include <iomanip>
1920
#include <sstream>
2021

@@ -428,14 +429,19 @@ SetVector<int> NormalizePass::getOutputFootprint(
428429

429430
unsigned count = 0;
430431
for (Block &block : func.getRegion()) {
431-
for (Operation &innerOp : block) {
432-
if (&innerOp == op) {
433-
outputsVec.insert(count);
434-
return outputsVec;
435-
}
436-
count++;
432+
if (auto it = std::find_if(
433+
block.begin(), block.end(),
434+
[op](Operation &innerOp) { return &innerOp == op; });
435+
it != block.end()) {
436+
count += std::distance(block.begin(), it);
437+
outputsVec.insert(count);
438+
break;
439+
} else {
440+
count += std::distance(block.begin(), block.end());
437441
}
438442
}
443+
444+
return outputsVec;
439445
}
440446

441447
for (OpOperand &use : op->getUses()) {

0 commit comments

Comments
 (0)