LLVM Discussion Forums

Deprecate EDSC {Loop/Block}Builder

SCF LoopOp and IfOp now leverage the recent capability of building the body of the region within the builder of the parent op by taking optional functors that construct the body. This is largely sufficient to achieve the same level of structured building APIs as EDSC Loop/Block Builder with 5x less infrastructure code. Examples can be found in https://reviews.llvm.org/D79688. Similar changes will follow for other region-holding operations that currently use Loop/Block Builder upstream.

Therefore I propose to deprecate EDSC {Loop/Block}Builder and remove them within 2 weeks timeframe. Replacement functions compatible with EDSC ScopedContext will be made available, e.g. https://github.com/llvm/llvm-project/blob/cadb7ccf2cebcaa2d546db77223bde3d69a162af/mlir/include/mlir/Dialect/SCF/EDSC/Builders.h#L74

@nicolasvasilache for visibility

Context:


1 Like

SGTM, thanks for the refactoring effort!

Thanks for cleaning all this up!

Do we already have some documentation about this new idiom of nested builders for op with regions? Is this something we could add to the Toy tutorial as well somehow?

The changes removing Loop/Block builder are landing tomorrow morning CEST.

Alternatives are provided as functions buildAffineLoopNest, scf::buildLoopNest (based on OpBuilder) and edsc::affineLoopNestBuilder, scf::edsc::loopNestBuilder (based on edsc::ScopedContext).

The generic structure of both .create calls and helper function is as follows:

build.create<OpWithRegion>(loc, usual-operands...,
                           function_ref<OpBuilder &, Location, ValueRange> blockFn);

where blockFn takes a new builder and location that can be used to construct the body of the region or block (if only one expected), and a list of region/block arguments. Similar schemes can be implemented for modules and functions if desired.

I updated the tutorial code to use buildAffineLoopNest instead of hand-rolled implementation. It was not mentioned in the tutorial text, LMK if we should.

Feel free to add sections in that chapter on it.