llvm / circt

Circuit IR Compilers and Tools
https://circt.org
Other
1.65k stars 291 forks source link

[HW] GlobalRef verifier performance #2794

Closed teqdruid closed 2 years ago

teqdruid commented 2 years ago

The internal application on which I'm working contains 1800 global refs. This results in GlobalRefOp::verify() being 64% of the runtime. Drilling in further: each time the verifier runs (1800 times per IR verify), it builds a new SymbolTable which shows as the vast majority of time in verify().

https://github.com/llvm/circt/blob/31205ddd090313e73e2b10462d424c1a56ca9545/lib/Dialect/HW/HWOps.cpp#L1460

What's the right way to share the SymbolTable across all the 1800 GlobalRefOp::verify() invocations in a verification pass?

youngar commented 2 years ago

You can implement SymbolUserOpInterface to make this faster. See FIRRTL's instance op for an example: https://github.com/llvm/circt/blob/main/lib/Dialect/FIRRTL/FIRRTLOps.cpp#L1294 There is a small issue here where the Op verification order verifies parent ops first and this means that the parent SymbolTable op will call this function before the normal InstanceOp verifiers are run. There is some discussion about this on discourse which I will try to find.

teqdruid commented 2 years ago

Thanks @youngar! That seemed to work (see my PR).