Hey all, I'm trying to run firtool on the FIRRTL output of a Chisel-based design from my company (which unfortunately means I can't provide the input .fir file), and running into a segfault during the DedupPass. The stacktrace follows:
I'm working on putting together a minimal input that duplicates the issue that I'd be able to share, but so far I haven't had luck duplicating the segfault. The design I'm testing on has a few modules that need to be deduplicated, but the majority of the design has a lot of multiply-instantiated modules, so we're extensively using the Chisel 3.5 Instance/Definition feature to cut down on the dedup work.
The issue appears to come from the part of the pass where we iterate over the instance graph with the llvm::post_order iterator, and then remove elements from that graph when we detect a duplicate module. Here is where the segfault comes from:
Given the presence of this comment, this issue was certainly foreseen, but something about my design is still triggering this problem.
I was able to make the following change to resolve the segfault:
diff --git a/lib/Dialect/FIRRTL/Transforms/Dedup.cpp b/lib/Dialect/FIRRTL/Transforms/Dedup.cpp
index a65d1d25..2286386c 100644
--- a/lib/Dialect/FIRRTL/Transforms/Dedup.cpp
+++ b/lib/Dialect/FIRRTL/Transforms/Dedup.cpp
@@ -1169,7 +1169,10 @@ class DedupPass : public DedupBase<DedupPass> {
// We must iterate the modules from the bottom up so that we can properly
// deduplicate the modules. We have to store the visit order first so that
// we can safely delete nodes as we go from the instance graph.
- for (auto *node : llvm::post_order(&instanceGraph)) {
+ auto i = llvm::po_begin(&instanceGraph);
+ auto e = llvm::po_end(&instanceGraph);
+ while (i != e) {
+ auto *node = *i++;
auto module = cast<FModuleLike>(*node->getModule());
auto moduleName = module.moduleNameAttr();
// If the module is marked with NoDedup, just skip it.
Then again, I'm no C++ expert, so it's likely there's something else going on (perhaps with the for-each loop syntax) that I don't yet understand. If there are any other tests I can try to narrow down the issue/solution, please let me know!
Platform: macOS 12.4, x86_64 circt commit: be20cdeebf9fcc3c0ca249f89c8913778a3d94f6
Hey all, I'm trying to run
firtool
on the FIRRTL output of a Chisel-based design from my company (which unfortunately means I can't provide the input.fir
file), and running into a segfault during theDedupPass
. The stacktrace follows:I'm working on putting together a minimal input that duplicates the issue that I'd be able to share, but so far I haven't had luck duplicating the segfault. The design I'm testing on has a few modules that need to be deduplicated, but the majority of the design has a lot of multiply-instantiated modules, so we're extensively using the Chisel 3.5 Instance/Definition feature to cut down on the dedup work.
The issue appears to come from the part of the pass where we iterate over the instance graph with the
llvm::post_order
iterator, and then remove elements from that graph when we detect a duplicate module. Here is where the segfault comes from:https://github.com/llvm/circt/blob/23ae1a7391c3d4d03eceade2189e224c4bb1ebaf/lib/Dialect/FIRRTL/Transforms/Dedup.cpp#L1172
And here is where the
instanceGraph
is modified within the loop iteration:https://github.com/llvm/circt/blob/23ae1a7391c3d4d03eceade2189e224c4bb1ebaf/lib/Dialect/FIRRTL/Transforms/Dedup.cpp#L1192
Given the presence of this comment, this issue was certainly foreseen, but something about my design is still triggering this problem.
I was able to make the following change to resolve the segfault:
However, I don't entirely understand why this has any different behavior, since the
post_order(...)
function creates an iterator out of thepo_begin
andpo_end
functions: https://github.com/llvm/llvm-project/blob/b422dac240f1475999a2c1b5fc242a0ef2e08727/llvm/include/llvm/ADT/PostOrderIterator.h#L182-L191Then again, I'm no C++ expert, so it's likely there's something else going on (perhaps with the for-each loop syntax) that I don't yet understand. If there are any other tests I can try to narrow down the issue/solution, please let me know!
-Tynan