[PATCH] D124750: [MLIR] Add a utility to sort the operands of commutative ops
Srishti Srivastava via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun May 1 22:31:57 PDT 2022
srishti-pm created this revision.
Herald added subscribers: sdasgup3, wenzhicui, wrengr, Chia-hungDuan, dcaballe, cota, teijeong, rdzhabarov, tatianashp, msifontes, jurahul, Kayjukh, grosul1, Joonsoo, liufengdb, aartbik, mgester, arpith-jacob, antiagainst, shauheen, rriddle, mehdi_amini, mgorny.
Herald added a project: All.
srishti-pm requested review of this revision.
Herald added subscribers: cfe-commits, stephenneuendorffer, nicolasvasilache.
Herald added projects: clang, MLIR.
Add a utility to sort the operands of commutative operations. This
utility is intended to be used inside a pass or an individual pattern to
simplify the matching of commutative operations. Note that this utility
can also be used inside PDL patterns in conjunction with the
`pdl.apply_native_rewrite` op. The sorting is done in ascending order of
"keys" associated with the operands. Each "key" represents a
breadth-first traversal of the backward slice of the operand. The
ascending order of "keys" is defined in a way that allows the (1)
operands defined by non-constant-like ops to come first, followed by (2)
block arguments, which are finally followed by the (3) operands defined
by constant-like ops. In addition to this, within the categories (1) and
(3), the order of operands is alphabetical w.r.t. the dialect name and
op name.
Illustration of the utility:
Let foo.op be a commutative op.
If the utility is called on foo.op and the DAG associated with foo.op is
as follows-
e = foo.div f, g
c = foo.constant
b = foo.add e, d
a = foo.add c, d
s = foo.op a, b,
then,
the utility will rewrite foo.op to the following-
s = foo.op b, a.
Signed-off-by: Srishti Srivastava <srishti.srivastava at polymagelabs.com>
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D124750
Files:
clang/docs/tools/clang-formatted-files.txt
mlir/include/mlir/Transforms/CommutativityUtils.h
mlir/lib/Transforms/Utils/CMakeLists.txt
mlir/lib/Transforms/Utils/CommutativityUtils.cpp
mlir/test/Transforms/test-commutativity-utils.mlir
mlir/test/lib/Dialect/Test/TestOps.td
mlir/test/lib/Transforms/CMakeLists.txt
mlir/test/lib/Transforms/TestCommutativityUtils.cpp
mlir/tools/mlir-opt/mlir-opt.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124750.426333.patch
Type: text/x-patch
Size: 28153 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220502/8ac6775a/attachment-0001.bin>
More information about the cfe-commits
mailing list