llvm / circt

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

[FIRRTL][NFC] Fast-path removeAnnotations for operations having none. #7203

Closed dtzSiFive closed 1 week ago

dtzSiFive commented 1 week ago

Common pattern of walk/visit many operations looking for annotations and removing along the way is taking considerable amount of time in ArrayAttr::get. Optimize the fast path for operations having no annotations.

youngar commented 1 week ago

I think there are a couple of places that have this code inlined, as not doing this attaches an empty annotation attribute which I usually only catch when I am writing tests. e.g. very recently: https://github.com/llvm/circt/blob/main/lib/Dialect/FIRRTL/Transforms/SpecializeLayers.cpp#L66

youngar commented 1 week ago

I think I misunderstood what this code is doing - just creating an empty annotation set creates an empty array attribute, and that is what we're trying to avoid? 🤦