diff --git a/lib/Dialect/FIRRTL/Transforms/SpecializeLayers.cpp b/lib/Dialect/FIRRTL/Transforms/SpecializeLayers.cpp index 385f5f65ed8f..1c72ab849705 100644 --- a/lib/Dialect/FIRRTL/Transforms/SpecializeLayers.cpp +++ b/lib/Dialect/FIRRTL/Transforms/SpecializeLayers.cpp @@ -655,17 +655,18 @@ struct SpecializeLayers { for (auto hierPath : llvm::make_early_inc_range( circuit.getBody().getOps())) { auto namepath = hierPath.getNamepath().getValue(); - for (auto ref : namepath.drop_back()) { - if (removedSyms.contains(ref)) { - removedPaths.insert(SymbolTable::getSymbolName(hierPath)); - hierPath->erase(); - continue; - } + auto shouldDelete = [&](Attribute ref) { + return removedSyms.contains(ref); + }; + if (llvm::any_of(namepath.drop_back(), shouldDelete)) { + removedPaths.insert(SymbolTable::getSymbolName(hierPath)); + hierPath->erase(); + continue; } // If we deleted the target of the hierpath, we don't need to add it to // the list of removedPaths, since no annotation will be left around to // reference this path. - if (removedSyms.contains(namepath.back())) + if (shouldDelete(namepath.back())) hierPath->erase(); } diff --git a/test/Dialect/FIRRTL/specialize-layers.mlir b/test/Dialect/FIRRTL/specialize-layers.mlir index dcbfede28b37..82cb12fe5063 100644 --- a/test/Dialect/FIRRTL/specialize-layers.mlir +++ b/test/Dialect/FIRRTL/specialize-layers.mlir @@ -371,6 +371,41 @@ firrtl.circuit "HierPathDelete" attributes { firrtl.extmodule @Deleted() attributes {layers = [@Layer]} } +// CHECK-LABEL: firrtl.circuit "HierPathDelete" +firrtl.circuit "HierPathDelete" attributes { + disable_layers = [@Layer] +} { + firrtl.layer @Layer bind { } + + // CHECK-NOT: hw.hierpath private @hierpath1 [@HierPathDelete::@middle, @Middle::@leaf, @Leaf] + hw.hierpath private @hierpath1 [@HierPathDelete::@middle, @Middle::@leaf, @Leaf] + // CHECK-NOT: hw.hierpath private @hierpath2 [@HierPathDelete::@middle, @Middle::@leaf] + hw.hierpath private @hierpath2 [@HierPathDelete::@middle, @Middle::@leaf] + // CHECK-NOT: hw.hierpath private @hierpath3 [@Middle::@leaf, @Leaf] + hw.hierpath private @hierpath3 [@Middle::@leaf, @Leaf] + // CHECK-NOT: hw.hierpath private @hierpath4 [@Middle::@leaf] + hw.hierpath private @hierpath4 [@Middle::@leaf] + + firrtl.module @HierPathDelete() { + firrtl.layerblock @Layer { + firrtl.instance middle sym @middle @Middle() + } + } + + firrtl.module @Middle() { + firrtl.layerblock @Layer { + firrtl.instance leaf sym @leaf @Leaf() + } + } + + firrtl.extmodule @Leaf() + + // CHECK-NOT: hw.hierpath private @DeletedPath [@Deleted] + hw.hierpath private @DeletedPath [@Deleted] + firrtl.extmodule @Deleted() attributes {layers = [@Layer]} +} + + //===----------------------------------------------------------------------===// // Annotations //===----------------------------------------------------------------------===//