Commit 5c2418f
Implement RegionBranchOpInterface on air hierarchy ops (#1566)
* Implement RegionBranchOpInterface on air hierarchy ops
air.rank, air.launch, air.segment, and air.herd now implement
RegionBranchOpInterface so that upstream MLIR analyses (alias
analysis, dataflow, dead-code elimination, ...) can walk the
parent-operand → body-block-arg mapping that IsolatedFromAbove
already constrains explicitly.
The mapping is the same one HierarchyInterface already exposes via
getKernelOperands / getKernelArguments / getTiedKernelOperand, but
re-stated through the upstream interface so generic infrastructure
finds it. With this in place, mlir::LocalAliasAnalysis can now
trace through hierarchy block args, which removes the need for the
custom hierarchy walk in CanonicalizeAsyncOpDeps's getRoot.
Three caveats addressed:
- AIRDependency.cpp dispatched generic RegionBranchOpInterface ops
through scf.if/affine.if-only handling. Skip air hierarchy ops
there — they have their own async-token machinery.
- HerdOp::getKernelArguments hardcoded drop_front(4), assuming 2D.
The new auto-verifier on RegionBranchOpInterface exercises this
path on the existing 0-dim-herd test, exposing the latent bug.
Replaced with drop_front(getNumDims() * 2) to match the other
three ops.
- The body→parent successor yields no values; the async token
result is a launch side-effect, not a yielded value, so
getEntrySuccessorOperands and getSuccessorInputs return empty
for that direction.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* Advertise hierarchy invocation bounds via getRegionInvocationBounds
air.launch / air.segment / air.herd / air.rank now implement the
RegionBranchOpInterface::getRegionInvocationBounds method. The body
executes once per (x, y, ...) coordinate of the iteration space; if
every size operand folds to a non-negative IntegerAttr we report a
tight {n, n} bound, otherwise Unknown.
This matches scf.forall's convention (each lattice point invokes the
body once, in parallel) and is needed so that upstream passes keyed on
RegionBranchOpInterface (ControlFlowSink, the inliner's repetition
heuristics, future LICM-style work) do not assume hierarchy bodies are
non-iterative just because there is no body->body edge in
getSuccessorRegions.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* Use upstream LocalAliasAnalysis in CanonicalizeAsyncOpDeps
Two changes that compose:
1. air.execute now implements MemoryEffectOpInterface. The body's
effects are mirrored to the outer op (so RAW/WAR/WAW analyses do
not assume the execute is side-effect free), and Allocate effects
on yielded values are retargeted to the corresponding outer op
result. With this in place upstream alias analyses can reason
that two distinct `air.execute -> memref` ops produce non-aliasing
storage, which previously needed the bespoke SSA-identity getRoot
walk to recognise.
2. CanonicalizeAsyncOpDeps' mayAlias predicate now consults
mlir::LocalAliasAnalysis first and falls back to the existing
getRoot SSA-identity check only when alias() returns MayAlias.
The fallback is still needed because LocalAliasAnalysis is
intentionally conservative for two distinct entry-block func args
(a caller could in principle pass the same buffer twice, and MLIR
has no `noalias` annotation on func args by default), while AIR's
domain assumption is that distinct top-level memref SSA values
address distinct storage.
Net effect: strictly >= the previous precision. Cases LocalAliasAnalysis
can decide pick up the upstream analysis (subviews-of-distinct-allocs,
hierarchy-arg traversal, future passes that improve LocalAliasAnalysis);
cases it cannot decide fall through to the AIR-domain heuristic.
This is the followup hinted at in the previous commit's PR description.
The interface unlock would also let new passes use upstream alias
analysis directly, without re-implementing getRoot.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* Address Copilot review
- computeHierarchyBounds: pre-multiply overflow guard so a single
oversized size operand cannot wrap uint64_t and silently report a
small invocation bound.
- ExecuteOp::getEffects: when an inner op does not implement
MemoryEffectOpInterface, consult mlir::isMemoryEffectFree before
falling back to the conservative Read+Write+Free. arith.constant /
affine.apply / similar Pure-trait ops are common in execute bodies
and were pessimising the declared effects without it.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* Trim verbose comments
Comments now name only the WHY when it isn't obvious from the code.
PR-description-style narration (history, alternatives, rationale chains)
removed from the source.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 911ec57 commit 5c2418f
4 files changed
Lines changed: 220 additions & 42 deletions
File tree
- mlir
- include/air/Dialect/AIR
- lib
- Dialect/AIR/IR
- Transform
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
| |||
142 | 143 | | |
143 | 144 | | |
144 | 145 | | |
| 146 | + | |
145 | 147 | | |
146 | 148 | | |
147 | 149 | | |
| |||
231 | 233 | | |
232 | 234 | | |
233 | 235 | | |
| 236 | + | |
234 | 237 | | |
235 | 238 | | |
236 | 239 | | |
| |||
351 | 354 | | |
352 | 355 | | |
353 | 356 | | |
| 357 | + | |
354 | 358 | | |
355 | 359 | | |
356 | 360 | | |
| |||
805 | 809 | | |
806 | 810 | | |
807 | 811 | | |
808 | | - | |
| 812 | + | |
| 813 | + | |
809 | 814 | | |
810 | 815 | | |
811 | 816 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| 24 | + | |
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
| 31 | + | |
29 | 32 | | |
30 | 33 | | |
31 | 34 | | |
| |||
233 | 236 | | |
234 | 237 | | |
235 | 238 | | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
254 | 244 | | |
255 | 245 | | |
256 | 246 | | |
| |||
275 | 265 | | |
276 | 266 | | |
277 | 267 | | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
278 | 274 | | |
279 | 275 | | |
280 | 276 | | |
| |||
320 | 316 | | |
321 | 317 | | |
322 | 318 | | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
328 | 322 | | |
329 | | - | |
330 | | - | |
| 323 | + | |
| 324 | + | |
331 | 325 | | |
332 | | - | |
333 | 326 | | |
334 | | - | |
| 327 | + | |
335 | 328 | | |
336 | 329 | | |
337 | 330 | | |
| |||
340 | 333 | | |
341 | 334 | | |
342 | 335 | | |
343 | | - | |
| 336 | + | |
344 | 337 | | |
345 | 338 | | |
346 | 339 | | |
347 | 340 | | |
348 | 341 | | |
349 | 342 | | |
350 | 343 | | |
351 | | - | |
| 344 | + | |
352 | 345 | | |
353 | 346 | | |
354 | 347 | | |
| |||
447 | 440 | | |
448 | 441 | | |
449 | 442 | | |
450 | | - | |
451 | | - | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
452 | 451 | | |
453 | | - | |
454 | | - | |
455 | | - | |
456 | | - | |
457 | | - | |
458 | | - | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
459 | 455 | | |
460 | | - | |
461 | | - | |
462 | | - | |
| 456 | + | |
463 | 457 | | |
464 | 458 | | |
465 | 459 | | |
| |||
845 | 839 | | |
846 | 840 | | |
847 | 841 | | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
848 | 889 | | |
849 | 890 | | |
850 | 891 | | |
| |||
1223 | 1264 | | |
1224 | 1265 | | |
1225 | 1266 | | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
1226 | 1291 | | |
1227 | 1292 | | |
1228 | 1293 | | |
| |||
1500 | 1565 | | |
1501 | 1566 | | |
1502 | 1567 | | |
| 1568 | + | |
| 1569 | + | |
| 1570 | + | |
| 1571 | + | |
| 1572 | + | |
| 1573 | + | |
| 1574 | + | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
| 1584 | + | |
| 1585 | + | |
| 1586 | + | |
| 1587 | + | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + | |
| 1591 | + | |
1503 | 1592 | | |
1504 | 1593 | | |
1505 | 1594 | | |
| |||
1856 | 1945 | | |
1857 | 1946 | | |
1858 | 1947 | | |
1859 | | - | |
| 1948 | + | |
1860 | 1949 | | |
1861 | 1950 | | |
1862 | 1951 | | |
| |||
1870 | 1959 | | |
1871 | 1960 | | |
1872 | 1961 | | |
| 1962 | + | |
| 1963 | + | |
| 1964 | + | |
| 1965 | + | |
| 1966 | + | |
| 1967 | + | |
| 1968 | + | |
| 1969 | + | |
| 1970 | + | |
| 1971 | + | |
| 1972 | + | |
| 1973 | + | |
| 1974 | + | |
| 1975 | + | |
| 1976 | + | |
| 1977 | + | |
| 1978 | + | |
| 1979 | + | |
| 1980 | + | |
| 1981 | + | |
| 1982 | + | |
| 1983 | + | |
| 1984 | + | |
| 1985 | + | |
1873 | 1986 | | |
1874 | 1987 | | |
1875 | 1988 | | |
| |||
1901 | 2014 | | |
1902 | 2015 | | |
1903 | 2016 | | |
| 2017 | + | |
| 2018 | + | |
| 2019 | + | |
| 2020 | + | |
| 2021 | + | |
| 2022 | + | |
| 2023 | + | |
| 2024 | + | |
| 2025 | + | |
| 2026 | + | |
| 2027 | + | |
| 2028 | + | |
| 2029 | + | |
| 2030 | + | |
| 2031 | + | |
| 2032 | + | |
| 2033 | + | |
| 2034 | + | |
| 2035 | + | |
| 2036 | + | |
| 2037 | + | |
| 2038 | + | |
| 2039 | + | |
| 2040 | + | |
| 2041 | + | |
| 2042 | + | |
| 2043 | + | |
| 2044 | + | |
| 2045 | + | |
| 2046 | + | |
| 2047 | + | |
| 2048 | + | |
| 2049 | + | |
| 2050 | + | |
| 2051 | + | |
| 2052 | + | |
| 2053 | + | |
| 2054 | + | |
| 2055 | + | |
| 2056 | + | |
| 2057 | + | |
| 2058 | + | |
| 2059 | + | |
| 2060 | + | |
| 2061 | + | |
| 2062 | + | |
| 2063 | + | |
| 2064 | + | |
| 2065 | + | |
| 2066 | + | |
| 2067 | + | |
| 2068 | + | |
1904 | 2069 | | |
1905 | 2070 | | |
1906 | 2071 | | |
| |||
0 commit comments