This is an archive of the discontinued LLVM Phabricator instance.

[mlir][bufferization] Cache enclosing repetitive region
ClosedPublic

Authored by maerhart on Jul 7 2023, 6:07 AM.

Details

Summary

The getEnclosingRepetitiveRegion functions walk the ancestor regions everytime which can be expensive especially when there are multiple regions inbetween. This commit adds a cache to the bufferization analysis to remember the result of the walk.

Diff Detail

Event Timeline

maerhart created this revision.Jul 7 2023, 6:07 AM
Herald added a project: Restricted Project. · View Herald Transcript
maerhart requested review of this revision.Jul 7 2023, 6:07 AM
springerm added inline comments.Jul 7 2023, 6:23 AM
mlir/include/mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h
575–577

This cache should be cleared when OneShotAnalysisState::resetCache() is called. We need a virtual resetCache function in this class. (And override + call base impl. in OneShotAnalysisState.)

mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp
57–61

An enclosing repetitive region can be nullptr. In that case, the stored region in the cache will be nullptr and this check will return "false". I would change this to if (enclosingRepetitiveRegionCache.contains(op)).

maerhart updated this revision to Diff 538138.Jul 7 2023, 7:31 AM

Cache nullptr results as well and consider them in the lookups. I used find_as to avoid looking up the value twice. Also, add the resetCache virtual method.

springerm accepted this revision.Jul 7 2023, 7:39 AM
This revision is now accepted and ready to land.Jul 7 2023, 7:39 AM
This revision was automatically updated to reflect the committed changes.