Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
mlir/lib/Dialect/SCF/IR/SCF.cpp | ||
---|---|---|
1477 | How about generalizing promoteIfSingleIteration to also have an implementation for scf.forall ? We can certainly wrap a pattern around and expose with populate functions but by now it is pretty well established the key functionality is better exposed via single functional-style functions. Additionally, the promoteIfSingleIteration are in need of a refresh while we are at it: they predate the proper use of rewriter APIs and perform unsafe RAUW, this is a good opportunity to tighten things up. | |
1484 | Please add a helper in StaticValueUtils that returns the optional number of steps: optional<int64_t> constantTripCount(OpFoldResult lb, OpFoldResult ub, OpFoldResult step); We could go as far as to implement that with OpFoldResult applied = makeComposedFoldedAffineApply which would capture a bunch of nontrivial cases (but would potentially build an op unless evolved to guarantee it remains in type-land). Then your loop goes away and the code is significantly more idiomatic: if (llvm::any_of(... [](){ return ... == 0; })) rewriter.replaceOp(op, op.getOutputs()); llvm::make_filter_range(... [](){ if (... != 1) ...; }) etc | |
1511 | rewriter.notifyMatchFailure | |
1515 | This seems like the part that performs the same as promoteIfSingleIteration for scf.forall. | |
1553 | This feels like a generally useful utility on the op itself to provide a helper that "projects out" one of the dimensions and returning an (N-1)-D version of the op. | |
1567 | This may need to be wrapped in a rewriter.startRootUpdate | |
1581 | overall the pattern itself should be ~5 lines and we gain a few new reusable APIs |
Address the comments.
mlir/lib/Dialect/SCF/IR/SCF.cpp | ||
---|---|---|
1477 | added promoteIfSingleIteration to SCF.h instead of scf utils.h, because otherwise there is a circular dependency. | |
1484 | I introduced the helper, but I am not sure about idiomatic part. I tried it and it was similar amount of code, but less efficient. | |
1553 | Shall we refactor it later, when we know the exact use case? |
Looks good conditional on small nits.
mlir/lib/Dialect/SCF/IR/SCF.cpp | ||
---|---|---|
529 | nit: please format. | |
1553 | This seems reasonable to me. | |
2738 | nit: Give this a better name. ParallelOpSingleOrZeroIterationDimsFolder maybe? That would be consistent with the other one. | |
mlir/lib/Dialect/Utils/StaticValueUtils.cpp | ||
9 ↗ | (On Diff #504449) | nit: is this needed? |
mlir/lib/Dialect/Utils/StaticValueUtils.cpp | ||
---|---|---|
202 ↗ | (On Diff #504449) | You use .has_value() in several places. They are all redundant. |
thanks for picking up the slack @herhut , won't have time to look deeper atm so please go with this
nit: please format.