This is an archive of the discontinued LLVM Phabricator instance.

[mlir][linalg][bufferize] Support scf.execute_region bufferization
ClosedPublic

Authored by springerm on Jan 16 2022, 4:14 AM.

Details

Summary

This op is needed for unit testing in a subsequent revision. (This is the first op that has a block that yields equivalent values via the op's results.)

Note: Bufferization of scf.execute_region ops with multiple blocks is not yet supported.

Diff Detail

Event Timeline

springerm created this revision.Jan 16 2022, 4:14 AM
springerm requested review of this revision.Jan 16 2022, 4:14 AM

Why are these tests (and the correspoding implementation) being added here instead of in the scf-bufferize pass? Many of the tests already added appear to do just with bufferization of scf.execute_region. You already have this in SCF bufferization pass in lib/Dialect/SCF/Transforms/StructuralTypeConversions.cpp.

void mlir::scf::populateSCFStructuralTypeConversionsAndLegality(
    TypeConverter &typeConverter, RewritePatternSet &patterns,
    ConversionTarget &target) {
  patterns.add<ConvertForOpTypes, ConvertIfOpTypes, ConvertYieldOpTypes,
               ConvertWhileOpTypes, ConvertConditionOpTypes>(
      typeConverter, patterns.getContext());
  target.addDynamicallyLegalOp<ForOp, IfOp>([&](Operation *op) {
    return typeConverter.isLegal(op->getResultTypes());
  });
  target.addDynamicallyLegalOp<scf::YieldOp>([&](scf::YieldOp op) {
    // We only have conversions for a subset of ops that use scf.yield
    // terminators.
    if (!isa<ForOp, IfOp, WhileOp>(op->getParentOp()))
      return true;
    return typeConverter.isLegal(op.getOperandTypes());
  });
  target.addDynamicallyLegalOp<WhileOp, ConditionOp>(
      [&](Operation *op) { return typeConverter.isLegal(op); });
}
mlir/test/Dialect/Linalg/comprehensive-module-bufferize.mlir
449–498

Likewise.

This is part of of "One-Shot Bufferization", a new bufferization with an analysis to produce fewer buffer copies. I will move it to the bufferization dialect in the next weeks and merge it with the existing passes (such as tensor-bufferize, scf-bufferize, etc.) .

For more details see: https://llvm.discourse.group/t/open-mlir-meeting-1-13-2021-one-shot-function-bufferization-of-tensor-programs/5197

This revision is now accepted and ready to land.Jan 19 2022, 12:07 AM