diff --git a/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h b/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h --- a/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h +++ b/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h @@ -158,8 +158,8 @@ SmallVector loops; SmallVector tensorResults; }; -Optional tileLinalgOp(OpBuilder &b, LinalgOp op, - const LinalgTilingOptions &options); +FailureOr tileLinalgOp(OpBuilder &b, LinalgOp op, + const LinalgTilingOptions &options); /// Fuse a sequence of linalg operations (`ops`) using tile-and-fuse. This /// proceeds as follows: diff --git a/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp b/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp --- a/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp @@ -152,7 +152,7 @@ } template -static Optional +static FailureOr tileLinalgOpImpl(OpBuilder &b, LinalgOp op, ValueRange tileSizes, const LinalgTilingOptions &options) { auto nLoops = op.getNumLoops(); @@ -160,13 +160,13 @@ tileSizes = tileSizes.take_front(nLoops); if (llvm::all_of(tileSizes, isZero)) - return llvm::None; + return failure(); // 1. Build the tiled loop ranges. auto allShapeSizes = op.createFlatListOfOperandDims(b, op.getLoc()); AffineMap shapeSizesToLoopsMap = op.getShapesToLoopsMap(); if (!shapeSizesToLoopsMap) - return llvm::None; + return failure(); SmallVector loopRanges; LoopIndexToRangeIndexMap loopIndexToRangeIndex; @@ -291,13 +291,13 @@ } template -Optional static tileLinalgOpImpl( +FailureOr static tileLinalgOpImpl( OpBuilder &b, LinalgOp op, const LinalgTilingOptions &options) { OpBuilder::InsertionGuard g(b); b.setInsertionPoint(op); if (!options.tileSizeComputationFunction) - return llvm::None; + return failure(); // Enforce the convention that "tiling by zero" skips tiling a particular // dimension. This convention is significantly simpler to handle instead of @@ -313,7 +313,7 @@ return tileLinalgOpImpl(b, op, tileSizeVector, options); } -Optional +FailureOr mlir::linalg::tileLinalgOp(OpBuilder &b, LinalgOp op, const LinalgTilingOptions &options) { switch (options.loopType) { @@ -325,7 +325,7 @@ return tileLinalgOpImpl(b, op, options); default:; } - return llvm::None; + return failure(); } /// Generate a loop nest around a given PadTensorOp (for tiling). `newPadOp`