llvm / circt

Circuit IR Compilers and Tools

Home Page:https://circt.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[FIRRTL] Parser is using lookupSymbol when it could compute a SymbolTable once and re-use it.

mikeurbach opened this issue · comments

While I was working on #6771, I noticed other places we use lookupSymbol on the CircuitOp. In the case of 6771, we already computed exactly the data structure we need, so I just used it.

The reason lookupSymbol is bad is because there is no caching--this is a linear scan through the CircuitOp body every time: https://github.com/llvm/llvm-project/blob/f31ac3cb1ff7958fadf6e3e431790f2d668583b4/mlir/lib/IR/SymbolTable.cpp#L395-L397

Instead, we can probably construct a SymbolTable from the CircuitOp, and use it to look up symbols when necessary: https://github.com/llvm/llvm-project/blob/f31ac3cb1ff7958fadf6e3e431790f2d668583b4/mlir/include/mlir/IR/SymbolTable.h#L20-L35

We should be able to construct it here, after parsing the headers of any top-level declarations, before parsing any bodies:

Then, we can plumb the SymbolTable down to wherever we are calling lookupSymbol today: https://github.com/search?q=repo%3Allvm%2Fcirct%20path%3Alib%2FDialect%2FFIRRTL%2FImport%2FFIRParser.cpp%20%22lookupSymbol(%22&type=code