From a4ab81094943767b88ce29e175b799350f516871 Mon Sep 17 00:00:00 2001 From: Robert Young Date: Mon, 18 Nov 2024 13:56:56 -0500 Subject: [PATCH] [FIRRTL] LowerTypes: Manually compact newArgs vector --- lib/Dialect/FIRRTL/Transforms/LowerTypes.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/Dialect/FIRRTL/Transforms/LowerTypes.cpp b/lib/Dialect/FIRRTL/Transforms/LowerTypes.cpp index 29b98cd86926..4dedd86fbce9 100644 --- a/lib/Dialect/FIRRTL/Transforms/LowerTypes.cpp +++ b/lib/Dialect/FIRRTL/Transforms/LowerTypes.cpp @@ -1146,8 +1146,9 @@ bool TypeLoweringVisitor::visitDecl(FModuleOp module) { auto newArgs = llvm::map_to_vector(module.getPorts(), [](auto pi) { return PortInfoWithIP{pi, std::nullopt}; }); - for (size_t argIndex = 0, argsRemoved = 0; argIndex < newArgs.size(); - ++argIndex) { + + size_t argsRemoved = 0; + for (size_t argIndex = 0; argIndex < newArgs.size(); ++argIndex) { SmallVector lowerings; if (lowerArg(module, argIndex, argsRemoved, newArgs, lowerings)) { auto arg = module.getArgument(argIndex); @@ -1160,10 +1161,17 @@ bool TypeLoweringVisitor::visitDecl(FModuleOp module) { } // Remove block args that have been lowered. - body->eraseArguments(argsToRemove); - for (auto deadArg = argsToRemove.find_last(); deadArg != -1; - deadArg = argsToRemove.find_prev(deadArg)) - newArgs.erase(newArgs.begin() + deadArg); + if (argsRemoved != 0) { + body->eraseArguments(argsToRemove); + size_t size = newArgs.size(); + for (size_t src = 0, dst = 0; src < size; ++src) { + if (argsToRemove[src]) + continue; + newArgs[dst] = newArgs[src]; + ++dst; + } + newArgs.erase(newArgs.end() - argsRemoved, newArgs.end()); + } SmallVector newModuleAttrs;