This is an archive of the discontinued LLVM Phabricator instance.

[mlir] GreedyPatternRewriteDriver: Keep track of surviving ops
ClosedPublic

Authored by springerm on Jan 17 2023, 5:04 AM.

Details

Summary

This change adds allErased to the applyOpPatternsAndFold(ArrayRef<Operation *>, ...) overload. This overload now supports all functionality that is also supported by applyOpPatternsAndFold(Operation *, ...) and can be used as a replacement.

This change has no performance implications when allErased = nullptr.

The single-operation overload is removed in a subsequent NFC change.

Depends On: D141904

Diff Detail

Event Timeline

springerm created this revision.Jan 17 2023, 5:04 AM
springerm requested review of this revision.Jan 17 2023, 5:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 17 2023, 5:04 AM

The purpose of this change is to remove OpPatternRewriteDriver to avoid duplicate code.

mehdi_amini added inline comments.Jan 19 2023, 8:55 AM
mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
609

Since an operation can be erased once, we should be able to use a vector here?

I guess the issue is that vector does not help later if the intent is checking if an op has been erased.

That said this all seems a bit "expensive" overall here, and I'm not sure that the extra bool *allOpsErased justified this (in itself it seems already like a bit "ad-hoc" in the API).

springerm updated this revision to Diff 490756.Jan 20 2023, 1:54 AM

address comments

mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
609

The purpose of this revision is to support all functionality of OpPatternRewriteDriver, so that it can be removed and we don't have to maintain two simplifyLocally implementations (and we get the existing debug log messages for free).

How about instead of storing all erased ops, we maintain a set of "surviving ops". It would initially be populated with the list of ops that is passed to simplifyLocally. That way there is an upper bound on the size of the set and it will only shrink, never grow. It has the same overhead as strictModeFilteredOps. Also, the set is maintained only if allErased is specified. So if allErased == nullptr, there is no performance implication at all.

springerm retitled this revision from [mlir] GreedyPatternRewriteDriver: Keep track of erased ops to [mlir] GreedyPatternRewriteDriver: Keep track of surviving ops.Jan 20 2023, 1:55 AM
springerm edited the summary of this revision. (Show Details)
mehdi_amini accepted this revision.Jan 25 2023, 9:13 AM
mehdi_amini added inline comments.
mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
624

Can you clarify that these are ops from the initially provided list of ops?

721

Can you use RAII ( llvm/include/llvm/ADT/ScopeExit.h ) for this?

This revision is now accepted and ready to land.Jan 25 2023, 9:13 AM
This revision was automatically updated to reflect the committed changes.
springerm marked 3 inline comments as done.