Skip to content

Commit

Permalink
[FIRRTL] Dedup speedup (#4197)
Browse files Browse the repository at this point in the history
This change consists of a couple improvements to the deduplication pass,
the first two of which increase performance.

1. Adds an NLA Cache, which maps a namepath attribute to an HierPathOp
   which matches. Dedup uses this to reuse HierPathOps in the circuit
   instead of creating new ones. This used to cause problem by passes
   which assumed ops did not share NLAs. This has an added effect of
   doing some HierPathOp garbage collection when we delete a module.
2. The targetMap, which maps an NLA to the operations which use it, now
   uses an SmallDenseSet. The original logic could end up recording the
   same target multiple times. AnnoTarget was made hashable for this.
3. Annotation merging used to merge identical annotations, now it keeps
   both annotations and makes them non-local. The original behaviour is
   kept for only DontTouch annotations, where it will only keep one.
4. When a module is merged into another, the original modules
   annotations are now first instead of second in the annotation list.
5. Some simplification of functions, especially unused argument removal,
   and creating functions for common code.
  • Loading branch information
youngar authored Oct 27, 2022
1 parent fb91326 commit 46e9b21
Show file tree
Hide file tree
Showing 4 changed files with 217 additions and 194 deletions.
22 changes: 22 additions & 0 deletions include/circt/Dialect/FIRRTL/FIRRTLAnnotations.h
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,28 @@ struct DenseMapInfo<circt::firrtl::Annotation> {
static bool isEqual(Annotation LHS, Annotation RHS) { return LHS == RHS; }
};

/// Make `AnnoTarget` hash.
template <>
struct DenseMapInfo<circt::firrtl::AnnoTarget> {
using AnnoTarget = circt::firrtl::AnnoTarget;
using AnnoTargetImpl = circt::firrtl::detail::AnnoTargetImpl;
static AnnoTarget getEmptyKey() {
auto *o = DenseMapInfo<mlir::Operation *>::getEmptyKey();
auto i = DenseMapInfo<unsigned>::getEmptyKey();
return AnnoTarget(AnnoTargetImpl(o, i));
}
static AnnoTarget getTombstoneKey() {
auto *o = DenseMapInfo<mlir::Operation *>::getTombstoneKey();
auto i = DenseMapInfo<unsigned>::getTombstoneKey();
return AnnoTarget(AnnoTargetImpl(o, i));
}
static unsigned getHashValue(AnnoTarget val) {
auto impl = val.getImpl();
return hash_combine(impl.getOp(), impl.getPortNo());
}
static bool isEqual(AnnoTarget lhs, AnnoTarget rhs) { return lhs == rhs; }
};

} // namespace llvm

#endif // CIRCT_DIALECT_FIRRTL_ANNOTATIONS_H
Loading

0 comments on commit 46e9b21

Please sign in to comment.