This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Introduce callback-based builders to SCF Parallel and Reduce ops
ClosedPublic

Authored by ftynse on Jun 15 2020, 12:59 PM.

Details

Summary

Similarly to scf::ForOp, introduce additional function_ref arguments to
::build functions of SCF ParallelOp and ReduceOp. The provided functions
will be called to construct the body of the respective operations while
constructing the operation itself. Exercise them in LoopUtils.

Diff Detail

Event Timeline

ftynse created this revision.Jun 15 2020, 12:59 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 15 2020, 12:59 PM
pifon2a accepted this revision.Jun 16 2020, 4:42 AM

thanks, Alex!

mlir/lib/Dialect/SCF/SCF.cpp
541

nit: will smth like that work?

function_ref<void(OpBuilder &, Location, ValueRange, ValueRange)> wrapper;
if (bodyBuilderFn) {
  wrapper = [&bodyBuilderFn](OpBuilder &nestedBuilder, Location nestedLoc,
                                  ValueRange ivs, ValueRange) {
    bodyBuilderFn(nestedBuilder, nestedLoc, ivs);
  };
}
 build(builder, result, lowerBounds, upperBounds, steps, ValueRange(), wrapper);
This revision is now accepted and ready to land.Jun 16 2020, 4:42 AM
ftynse updated this revision to Diff 271058.Jun 16 2020, 5:25 AM
ftynse marked an inline comment as done.

Address review

ftynse added inline comments.Jun 16 2020, 5:29 AM
mlir/lib/Dialect/SCF/SCF.cpp
541

This way, the wrapper will refer to a temporary scoped within the if block, so it will become dangling after that.

I'll factor out the lambda into a function-level variable to help readability.

This revision was automatically updated to reflect the committed changes.