Skip to content

[Support] UnusedOpPruner shouldn't erase block arguments #8991

@uenoku

Description

@uenoku

UnusedOpPruner removes block arguments but it's not generally legal, e.g. HW module requires the module type is consistent with block arguments

while (!blockArgsToEraseIfUnused.empty()) {
auto it = blockArgsToEraseIfUnused.begin();
auto arg = *it;
blockArgsToEraseIfUnused.erase(it);
if (!arg.use_empty())
continue;
if (!llvm::all_of(arg.getOwner()->getUses(), [](auto &blockOperand) {
return isa<BranchOpInterface>(blockOperand.getOwner());
}))
continue;
unsigned argIdx = arg.getArgNumber();
for (auto &blockOperand : arg.getOwner()->getUses()) {
auto branchOp = cast<BranchOpInterface>(blockOperand.getOwner());
auto operands =
branchOp.getSuccessorOperands(blockOperand.getOperandNumber());
eraseLaterIfUnused(operands[argIdx]);
operands.erase(argIdx);
}
arg.getOwner()->eraseArgument(argIdx);

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions