Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
mlir/lib/Dialect/SCF/IR/SCF.cpp | ||
---|---|---|
1546 | 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. | |
1553 | 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 | |
1580 | rewriter.notifyMatchFailure | |
1584 | This seems like the part that performs the same as promoteIfSingleIteration for scf.forall. | |
1615 | overall the pattern itself should be ~5 lines and we gain a few new reusable APIs | |
1622 | 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. | |
1636 | This may need to be wrapped in a rewriter.startRootUpdate |
Address the comments.
mlir/lib/Dialect/SCF/IR/SCF.cpp | ||
---|---|---|
1546 | added promoteIfSingleIteration to SCF.h instead of scf utils.h, because otherwise there is a circular dependency. | |
1553 | 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. | |
1622 | 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 | ||
---|---|---|
536 | nit: please format. | |
1622 | This seems reasonable to me. | |
2772 | nit: Give this a better name. ParallelOpSingleOrZeroIterationDimsFolder maybe? That would be consistent with the other one. | |
mlir/lib/Dialect/Utils/StaticValueUtils.cpp | ||
9 | nit: is this needed? |
mlir/lib/Dialect/Utils/StaticValueUtils.cpp | ||
---|---|---|
202 | 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.