From: Matthias Springer Date: Wed, 15 Mar 2023 10:49:55 +0000 (+0100) Subject: [mlir][Transforms] OperationFolder: Remove redundant `create` API X-Git-Tag: upstream/17.0.6~14722 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=506fd6725166d2688b7d15b09f00da1abaa1f157;p=platform%2Fupstream%2Fllvm.git [mlir][Transforms] OperationFolder: Remove redundant `create` API These functions are available on the `OpBuilder` API. Differential Revision: https://reviews.llvm.org/D146126 --- diff --git a/mlir/include/mlir/Transforms/FoldUtils.h b/mlir/include/mlir/Transforms/FoldUtils.h index ff10837..a6dc183 100644 --- a/mlir/include/mlir/Transforms/FoldUtils.h +++ b/mlir/include/mlir/Transforms/FoldUtils.h @@ -58,50 +58,6 @@ public: /// externally to this OperationFolder. `op` must be a constant op. void notifyRemoval(Operation *op); - /// Create an operation of specific op type with the given builder, - /// and immediately try to fold it. This function populates 'results' with - /// the results after folding the operation. - template - void create(OpBuilder &builder, SmallVectorImpl &results, - Location location, Args &&...args) { - // The op needs to be inserted only if the fold (below) fails, or the number - // of results produced by the successful folding is zero (which is treated - // as an in-place fold). Using create methods of the builder will insert the - // op, so not using it here. - OperationState state(location, OpTy::getOperationName()); - OpTy::build(builder, state, std::forward(args)...); - Operation *op = Operation::create(state); - - if (failed(tryToFold(builder, op, results)) || results.empty()) { - builder.insert(op); - results.assign(op->result_begin(), op->result_end()); - return; - } - op->destroy(); - } - - /// Overload to create or fold a single result operation. - template - std::enable_if_t(), Value> - create(OpBuilder &builder, Location location, Args &&...args) { - SmallVector results; - create(builder, results, location, std::forward(args)...); - return results.front(); - } - - /// Overload to create or fold a zero result operation. - template - std::enable_if_t(), OpTy> - create(OpBuilder &builder, Location location, Args &&...args) { - auto op = builder.create(location, std::forward(args)...); - SmallVector unused; - (void)tryToFold(op.getOperation(), unused); - - // Folding cannot remove a zero-result operation, so for convenience we - // continue to return it. - return op; - } - /// Clear out any constants cached inside of the folder. void clear(); diff --git a/mlir/test/lib/Dialect/Test/TestPatterns.cpp b/mlir/test/lib/Dialect/Test/TestPatterns.cpp index 29dc580..20d3d48 100644 --- a/mlir/test/lib/Dialect/Test/TestPatterns.cpp +++ b/mlir/test/lib/Dialect/Test/TestPatterns.cpp @@ -86,14 +86,13 @@ public: LogicalResult matchAndRewrite(Operation *op, PatternRewriter &rewriter) const override { - // Exercise OperationFolder API for a single-result operation that is folded - // upon construction. The operation being created through the folder has an - // in-place folder, and it should be still present in the output. - // Furthermore, the folder should not crash when attempting to recover the - // (unchanged) operation result. - OperationFolder folder(op->getContext()); - Value result = folder.create( - rewriter, op->getLoc(), rewriter.getIntegerType(32), op->getOperand(0)); + // Exercise createOrFold API for a single-result operation that is folded + // upon construction. The operation being created has an in-place folder, + // and it should be still present in the output. Furthermore, the folder + // should not crash when attempting to recover the (unchanged) operation + // result. + Value result = rewriter.createOrFold( + op->getLoc(), rewriter.getIntegerType(32), op->getOperand(0)); assert(result); rewriter.replaceOp(op, result); return success();