Commit c639475
authored
[mlir][Transforms] Dialect Conversion: Fix folder implementation (llvm#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 llvm#92683),
but that's a different issue. (In a One-Shot Dialect Conversion, it will
no longer be unsafe.)1 parent cf1abe6 commit c639475
File tree
2 files changed
+21
-8
lines changed- mlir
- lib/Transforms/Utils
- test/Transforms
2 files changed
+21
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
2240 | 2241 | | |
2241 | 2242 | | |
2242 | 2243 | | |
2243 | | - | |
| 2244 | + | |
| 2245 | + | |
| 2246 | + | |
| 2247 | + | |
| 2248 | + | |
| 2249 | + | |
| 2250 | + | |
| 2251 | + | |
| 2252 | + | |
| 2253 | + | |
| 2254 | + | |
2244 | 2255 | | |
2245 | 2256 | | |
2246 | 2257 | | |
2247 | 2258 | | |
2248 | 2259 | | |
2249 | 2260 | | |
| 2261 | + | |
2250 | 2262 | | |
2251 | 2263 | | |
| 2264 | + | |
2252 | 2265 | | |
2253 | 2266 | | |
| 2267 | + | |
2254 | 2268 | | |
2255 | 2269 | | |
2256 | 2270 | | |
2257 | 2271 | | |
2258 | 2272 | | |
2259 | 2273 | | |
| 2274 | + | |
| 2275 | + | |
| 2276 | + | |
2260 | 2277 | | |
2261 | 2278 | | |
2262 | 2279 | | |
| |||
2269 | 2286 | | |
2270 | 2287 | | |
2271 | 2288 | | |
2272 | | - | |
2273 | | - | |
2274 | | - | |
| 2289 | + | |
| 2290 | + | |
2275 | 2291 | | |
2276 | 2292 | | |
2277 | 2293 | | |
2278 | 2294 | | |
2279 | | - | |
2280 | | - | |
2281 | | - | |
2282 | 2295 | | |
2283 | 2296 | | |
2284 | 2297 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
107 | | - | |
108 | 107 | | |
| 108 | + | |
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
| |||
0 commit comments