Skip to content

Commit 0145759

Browse files
committed
Fix Block::eraseArguments: keep track the first removed element while removing
Not only this is likely more efficient than BitVector::find_first(), but also if the BitVector is empty find_first() returns -1, which llvm::drop_begin isn't robust against.
1 parent 7b06786 commit 0145759

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

mlir/lib/IR/Block.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,17 @@ void Block::eraseArguments(llvm::BitVector eraseIndices) {
192192
// We do this in reverse so that we erase later indices before earlier
193193
// indices, to avoid shifting the later indices.
194194
unsigned originalNumArgs = getNumArguments();
195+
int64_t firstErased = originalNumArgs;
195196
for (unsigned i = 0; i < originalNumArgs; ++i) {
196197
int64_t currentPos = originalNumArgs - i - 1;
197198
if (eraseIndices.test(currentPos)) {
198199
arguments[currentPos].destroy();
199200
arguments.erase(arguments.begin() + currentPos);
201+
firstErased = currentPos;
200202
}
201203
}
202204
// Update the cached position for the arguments after the first erased one.
203-
int64_t index = eraseIndices.find_first();
205+
int64_t index = firstErased;
204206
for (BlockArgument arg : llvm::drop_begin(arguments, index))
205207
arg.setArgNumber(index++);
206208
}

0 commit comments

Comments
 (0)