From cbe82b9674da81e424071dee10090038940605b2 Mon Sep 17 00:00:00 2001 From: Prithayan Barua Date: Thu, 12 Oct 2023 07:21:03 -0700 Subject: [PATCH] [ExtractTestCode] Use non-empty unqiue port names (#6283) Update ETC to add non-empty and unique port names. --------- Co-authored-by: Nandor Licker --- .../SV/Transforms/SVExtractTestCode.cpp | 13 +++++++---- test/Dialect/SV/hw-extract-test-code.mlir | 23 +++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/lib/Dialect/SV/Transforms/SVExtractTestCode.cpp b/lib/Dialect/SV/Transforms/SVExtractTestCode.cpp index 734fd60297..f3593b6a53 100644 --- a/lib/Dialect/SV/Transforms/SVExtractTestCode.cpp +++ b/lib/Dialect/SV/Transforms/SVExtractTestCode.cpp @@ -22,8 +22,10 @@ #include "circt/Dialect/SV/SVPasses.h" #include "circt/Dialect/Seq/SeqDialect.h" #include "circt/Dialect/Seq/SeqOps.h" +#include "circt/Support/Namespace.h" #include "mlir/IR/Builders.h" #include "mlir/IR/IRMapping.h" +#include "llvm/ADT/SetVector.h" #include @@ -202,12 +204,15 @@ static hw::HWModuleOp createModuleForCut(hw::HWModuleOp op, // Construct the ports, this is just the input Values SmallVector ports; { + Namespace portNames; auto srcPorts = op.getInputNames(); for (auto port : llvm::enumerate(realInputs)) { - auto name = getNameForPort(port.value(), srcPorts); - ports.push_back( - {{name, port.value().getType(), hw::ModulePort::Direction::Input}, - port.index()}); + auto name = getNameForPort(port.value(), srcPorts).getValue(); + name = portNames.newName(name.empty() ? "port_" + Twine(port.index()) + : name); + ports.push_back({{b.getStringAttr(name), port.value().getType(), + hw::ModulePort::Direction::Input}, + port.index()}); } } diff --git a/test/Dialect/SV/hw-extract-test-code.mlir b/test/Dialect/SV/hw-extract-test-code.mlir index 32130ea9f7..b351dc3841 100644 --- a/test/Dialect/SV/hw-extract-test-code.mlir +++ b/test/Dialect/SV/hw-extract-test-code.mlir @@ -552,3 +552,26 @@ module { hw.output } } + + +// ----- + +// Check that no anonymous ports are created and all the port names are unique. + +module { + hw.module @PortName(in %clock : !seq.clock, in %in : i1) { + %x = hw.instance "pF" @PortNameFoo(clock: %clock: !seq.clock, "": %in: i1) -> (o: i1) + hw.output + } + // CHECK-LABEL: hw.module @PortNameFoo_cover + // CHECK-SAME: (in %clock : !seq.clock, in %port_1 : i1, in %port_2 : i1) + hw.module private @PortNameFoo(in %clock: !seq.clock, in %1: i1, out o : i1) { + // CHECK: hw.instance "PortNameFoo_cover" + // CHECK-SAME: @PortNameFoo_cover(clock: %clock: !seq.clock, port_1: %arg0: i1, port_2: %0: i1) -> () + %0 = seq.from_clock %clock + %2 = comb.xor %1, %1 : i1 + sv.cover.concurrent posedge %0, %1 label "cover__hello1" + sv.cover.concurrent posedge %0, %2 label "cover__hello2" + hw.output %2 : i1 + } +}