Skip to content

Commit 59349be

Browse files
committed
[NFC] Improve DeduplicateExecutables bucketing
Use the result types as a part of the hash when grouping ops. This vastly improves the performance of this pass when there are several similar objects that have different types. This pass can become very slow because checking structural equivalence is a costly procedure pass is O(n^2) with respect to the bucket size. Signed-off-by: Ian Wood <ianwood2024@u.northwestern.edu>
1 parent f27feff commit 59349be

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

compiler/src/iree/compiler/Dialect/Flow/Transforms/DeduplicateExecutables.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,16 @@ static int deduplicateObjects(Operation *scopeOp,
8787
// 5 was randomly chosen to be small enough to not increase overhead much,
8888
// but giving at least enough of a sample that there is some bucketing. This
8989
// was not empirically determined.
90+
constexpr int kMaxHashedOps = 5;
9091
llvm::MapVector<uint32_t, SmallVector<SymbolOpInterface>> objectMap;
9192
for (auto objectOp : allObjectOps) {
9293
int count = 0;
9394
llvm::hash_code hash(1);
9495
objectOp->walk([&](Operation *it) {
9596
hash = llvm::hash_combine(hash, it->getName());
96-
return (++count >= 5) ? WalkResult::interrupt() : WalkResult::advance();
97+
hash = llvm::hash_combine(hash, it->getResultTypes());
98+
return (++count >= kMaxHashedOps) ? WalkResult::interrupt()
99+
: WalkResult::advance();
97100
});
98101
objectMap[hash_value(hash)].push_back(cast<SymbolOpInterface>(objectOp));
99102
}

0 commit comments

Comments
 (0)