[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
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
e = foo.div f, g
c = foo.constant
b = foo.add e, d
a = foo.add c, d
s = foo.op a, b,
the utility will rewrite foo.op to the following-
s = foo.op b, a.
Signed-off-by: Srishti Srivastava <srishti.srivastava at polymagelabs.com>
rG LLVM Github Monorepo
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 28153 bytes
Desc: not available
More information about the cfe-commits