diff options
author | Matthias Springer <me@m-sp.org> | 2025-07-27 12:01:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-07-27 12:01:01 +0200 |
commit | c639475974c4fe95951e2598e65a2be07ed05af1 (patch) | |
tree | d36b70c1e2e40373bee850f1a905844348a80677 /llvm/lib/TextAPI/TextAPIError.cpp | |
parent | cf1abe67b9c6881527e42c1f6571665bb506b708 (diff) | |
download | llvm-c639475974c4fe95951e2598e65a2be07ed05af1.zip llvm-c639475974c4fe95951e2598e65a2be07ed05af1.tar.gz llvm-c639475974c4fe95951e2598e65a2be07ed05af1.tar.bz2 |
[mlir][Transforms] Dialect Conversion: Fix folder implementation (#150775)
Operation folders can do two things:
1. Modify IR (in-place op modification). Failing to legalize an in-place
folded operation does not trigger an immediate rollback. This happens
only if the driver decides to try a different lowering path, requiring
it to roll back a bunch of modifications, including the application of
the folder.
2. Create new IR (constant op materialization of a folded attribute).
Failing to legalize a newly created constant op triggers an immediate
rollback.
In-place op modifications should be guarded by
`startOpModification`/`finalizeOpModification` because they are no
different from other in-place op modifications. (They just happen
outside of a pattern, but that does not mean that we should not track
those changes; we are tracking everything else.) This commit adds those
two function calls.
This commit also moves the `rewriter.replaceOp(op, replacementValues);`
function call before the loop nest that legalizes the newly created
constant ops (and therefore `replacementValues`). Conceptually, the
folded op must be replaced before attempting to legalize the constants
because the constant ops may themselves be replaced as part of their own
legalization process. The previous implementation happened to work in
the current conversion driver, but is incompatible with the One-Shot
Dialect Conversion driver, which expects to see the most recent IR at
all time.
From an end-user perspective, this commit should be NFC. A common
folder-rollback pattern that is exercised by multiple tests cases: A
`memref.dim` is folded to `arith.constant`, but `arith.constant` is not
marked as legal as per the conversion target, triggering a rollback.
Note: Folding is generally unsafe in a dialect conversion (see #92683),
but that's a different issue. (In a One-Shot Dialect Conversion, it will
no longer be unsafe.)
Diffstat (limited to 'llvm/lib/TextAPI/TextAPIError.cpp')
0 files changed, 0 insertions, 0 deletions