Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIRRTL] LowerTypes: Manually compact newArgs vector #7869

Merged
merged 1 commit into from
Nov 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[FIRRTL] LowerTypes: Manually compact newArgs vector
  • Loading branch information
rwy7 committed Nov 21, 2024
commit a4ab81094943767b88ce29e175b799350f516871
20 changes: 14 additions & 6 deletions lib/Dialect/FIRRTL/Transforms/LowerTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Value> lowerings;
if (lowerArg(module, argIndex, argsRemoved, newArgs, lowerings)) {
auto arg = module.getArgument(argIndex);
Expand All @@ -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<NamedAttribute, 8> newModuleAttrs;

Expand Down
Loading