From 1dc931d2c0968b5bdfb25e7a667d6b350dd5ad0d Mon Sep 17 00:00:00 2001 From: Andrew Young Date: Fri, 1 Nov 2024 23:17:12 -0700 Subject: [PATCH] [HW] InnerSymbolTable: only check top-level ops for portlists This changes the inner symbol table to only check top-level operations for portlists. Trying to dyn_cast every single operation to PortList is expensive, and is not a cost we have to pay when only module operations have port lists. --- lib/Dialect/HW/InnerSymbolTable.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/Dialect/HW/InnerSymbolTable.cpp b/lib/Dialect/HW/InnerSymbolTable.cpp index 22884f66768f..87eda09a1a88 100644 --- a/lib/Dialect/HW/InnerSymbolTable.cpp +++ b/lib/Dialect/HW/InnerSymbolTable.cpp @@ -78,6 +78,15 @@ LogicalResult InnerSymbolTable::walkSymbols(Operation *op, return success(); }; + // Check for ports + if (auto mod = dyn_cast(op)) { + for (auto [i, port] : llvm::enumerate(mod.getPortList())) { + if (auto symAttr = port.getSym()) + if (failed(walkSyms(symAttr, InnerSymTarget(i, mod)))) + return failure(); + } + } + // Walk the operation and add InnerSymbolTarget's to the table. return success( !op->walk([&](Operation *curOp) -> WalkResult { @@ -86,14 +95,6 @@ LogicalResult InnerSymbolTable::walkSymbols(Operation *op, if (failed(walkSyms(symAttr, InnerSymTarget(symOp)))) return WalkResult::interrupt(); - // Check for ports - if (auto mod = dyn_cast(curOp)) { - for (auto [i, port] : llvm::enumerate(mod.getPortList())) { - if (auto symAttr = port.getSym()) - if (failed(walkSyms(symAttr, InnerSymTarget(i, curOp)))) - return WalkResult::interrupt(); - } - } return WalkResult::advance(); }).wasInterrupted()); }