[NFC] Apply naming cleanup for init_tensor -> tensor.empty changes. (#12221)
diff --git a/compiler/src/iree/compiler/Codegen/Common/ConvertToDestinationPassingStylePass.cpp b/compiler/src/iree/compiler/Codegen/Common/ConvertToDestinationPassingStylePass.cpp index 6e73a5b..55db046 100644 --- a/compiler/src/iree/compiler/Codegen/Common/ConvertToDestinationPassingStylePass.cpp +++ b/compiler/src/iree/compiler/Codegen/Common/ConvertToDestinationPassingStylePass.cpp
@@ -7,7 +7,7 @@ // // Transformations that are performed before calling upstream Comprehensive // Bufferization pass. These change the dispatch region to use destination -// passing style, mostly to get rid of `init_tensor` ops that result in an +// passing style, mostly to get rid of `empty` ops that result in an // allocation. // //===----------------------------------------------------------------------===// @@ -168,8 +168,8 @@ op.setDpsInitOperand(resultValue.getResultNumber(), destinationValue); return success(); }) - .Case<tensor::EmptyOp>([&](auto emptyTensorOp) { - emptyTensorOp.replaceAllUsesWith(destinationValue); + .Case<tensor::EmptyOp>([&](auto emptyOp) { + emptyOp.replaceAllUsesWith(destinationValue); return success(); }) .Default([](auto defaultOp) { @@ -250,8 +250,8 @@ llvm::DenseSet<Value> processed; auto walkResult = funcOp.walk<WalkOrder::PreOrder>( - [&](tensor::EmptyOp emptyTensorOp) -> WalkResult { - for (auto result : emptyTensorOp->getResults()) { + [&](tensor::EmptyOp emptyOp) -> WalkResult { + for (auto result : emptyOp->getResults()) { if (!result.getType().isa<RankedTensorType>()) continue; if (plan.isInStoreSet(result) && !processed.count(result)) { return modifyResultToUseStoreBuffer(b, result, plan, processed); @@ -264,17 +264,17 @@ /// Multiple uses of `tensor.empty()` results in a copy since upstream /// treats `tensor.empty()` as an allocation and sees uses as a data-hazard -/// creating copies/allocations. Since the `init_tensor` op is a proxy for +/// creating copies/allocations. Since the `empty` op is a proxy for /// undef, these could just be duplicated to have a single use. This removes /// unnecessary data-hazards. -static LogicalResult duplicateInitTensorOps(OpBuilder &b, - tensor::EmptyOp emptyTensorOp) { +static LogicalResult duplicateTensorEmptyOps(OpBuilder &b, + tensor::EmptyOp emptyOp) { OpBuilder::InsertionGuard g(b); - b.setInsertionPoint(emptyTensorOp); - SmallVector<OpOperand *> uses = llvm::to_vector(llvm::map_range( - emptyTensorOp->getUses(), [](OpOperand &use) { return &use; })); + b.setInsertionPoint(emptyOp); + SmallVector<OpOperand *> uses = llvm::to_vector( + llvm::map_range(emptyOp->getUses(), [](OpOperand &use) { return &use; })); for (auto use : llvm::make_range(std::next(uses.begin()), uses.end())) { - auto newOp = cast<tensor::EmptyOp>(b.clone(*emptyTensorOp.getOperation())); + auto newOp = cast<tensor::EmptyOp>(b.clone(*emptyOp.getOperation())); Operation *user = use->getOwner(); user->setOperand(use->getOperandNumber(), newOp); } @@ -504,12 +504,10 @@ MLIRContext *context = &getContext(); OpBuilder b(context); - SmallVector<tensor::EmptyOp> emptyTensorOps; - funcOp.walk([&](tensor::EmptyOp emptyTensorOp) { - emptyTensorOps.push_back(emptyTensorOp); - }); - if (llvm::any_of(emptyTensorOps, [&](tensor::EmptyOp emptyTensorOp) { - return failed(duplicateInitTensorOps(b, emptyTensorOp)); + SmallVector<tensor::EmptyOp> emptyOps; + funcOp.walk([&](tensor::EmptyOp emptyOp) { emptyOps.push_back(emptyOp); }); + if (llvm::any_of(emptyOps, [&](tensor::EmptyOp emptyOp) { + return failed(duplicateTensorEmptyOps(b, emptyOp)); })) { return signalPassFailure(); }
diff --git a/compiler/src/iree/compiler/Codegen/Common/TileDispatchUsingInterface.cpp b/compiler/src/iree/compiler/Codegen/Common/TileDispatchUsingInterface.cpp index 04e7b5e..a840e5d 100644 --- a/compiler/src/iree/compiler/Codegen/Common/TileDispatchUsingInterface.cpp +++ b/compiler/src/iree/compiler/Codegen/Common/TileDispatchUsingInterface.cpp
@@ -616,12 +616,12 @@ }; //===----------------------------------------------------------------------===// -// SwapExtractSliceWithInitTensor +// SwapExtractSliceWithTensorEmpty //===----------------------------------------------------------------------===// -/// Pattern to swap `init_tensor` -> `tensor.extract_slice` with -/// `init_tensor` of the slice. -struct SwapExtractSliceWithInitTensor +/// Pattern to swap `empty` -> `tensor.extract_slice` with +/// `empty` of the slice. +struct SwapExtractSliceWithTensorEmpty : public OpRewritePattern<tensor::ExtractSliceOp> { using OpRewritePattern<tensor::ExtractSliceOp>::OpRewritePattern; @@ -653,7 +653,7 @@ RewritePatternSet &patterns, linalg::LinalgTilingOptions options) { MLIRContext *context = patterns.getContext(); patterns.insert<SwapExtractSliceWithDispatchTensorLoad, - SwapExtractSliceWithInitTensor, + SwapExtractSliceWithTensorEmpty, SwapExtractSliceWithTiledProducer>(context); }
diff --git a/compiler/src/iree/compiler/Codegen/LLVMCPU/test/pipeline_tests.mlir b/compiler/src/iree/compiler/Codegen/LLVMCPU/test/pipeline_tests.mlir index d1230b7..e3eca6e 100644 --- a/compiler/src/iree/compiler/Codegen/LLVMCPU/test/pipeline_tests.mlir +++ b/compiler/src/iree/compiler/Codegen/LLVMCPU/test/pipeline_tests.mlir
@@ -5,7 +5,7 @@ // By proxy checks that destination passing style kicked in correctly // and no CSE was run between first level tile + fuse + distribute // and the conversion to destination passing style. Running CSE -// before hoists the fill and the init_tensor out of the loop causing +// before hoists the fill and the empty out of the loop causing // issues with the conversion. #map3 = affine_map<(d0) -> (d0)> #map4 = affine_map<(d0, d1) -> (d0)>
diff --git a/compiler/src/iree/compiler/Dialect/Flow/Transforms/DetachElementwiseFromNamedOps.cpp b/compiler/src/iree/compiler/Dialect/Flow/Transforms/DetachElementwiseFromNamedOps.cpp index 764b6db..0a130a5 100644 --- a/compiler/src/iree/compiler/Dialect/Flow/Transforms/DetachElementwiseFromNamedOps.cpp +++ b/compiler/src/iree/compiler/Dialect/Flow/Transforms/DetachElementwiseFromNamedOps.cpp
@@ -120,7 +120,7 @@ }; /// Replace uses of splat constants as `outs` operands of `LinalgExt` -/// operations. More canonical representation is to use a `init_tensor -> fill +/// operations. More canonical representation is to use a `empty -> fill /// -> outs` operand sequence. Splat constants pulled in this way causes issues /// with allocations. Using `fill` will allow for fusing with the op just like /// fill -> linalg ops are fused. If not as a fallback they would be converted
diff --git a/compiler/src/iree/compiler/Dialect/Flow/Transforms/InitializeEmptyTensors.cpp b/compiler/src/iree/compiler/Dialect/Flow/Transforms/InitializeEmptyTensors.cpp index 9450845..d49fd9a 100644 --- a/compiler/src/iree/compiler/Dialect/Flow/Transforms/InitializeEmptyTensors.cpp +++ b/compiler/src/iree/compiler/Dialect/Flow/Transforms/InitializeEmptyTensors.cpp
@@ -34,7 +34,7 @@ namespace { /// Converts an tensor.empty() op to `flow.tensor.splat` op. -struct RewriteInitTensorToSplat : public OpRewritePattern<tensor::EmptyOp> { +struct RewriteTensorEmptyToSplat : public OpRewritePattern<tensor::EmptyOp> { using OpRewritePattern<tensor::EmptyOp>::OpRewritePattern; LogicalResult matchAndRewrite(tensor::EmptyOp emptyTensorOp, PatternRewriter &rewriter) const override { @@ -62,7 +62,7 @@ }; /// Converts an tensor.empty() op to `flow.tensor.empty` op. -struct RewriteInitTensorToEmpty : public OpRewritePattern<tensor::EmptyOp> { +struct RewriteTensorEmptyToEmpty : public OpRewritePattern<tensor::EmptyOp> { using OpRewritePattern<tensor::EmptyOp>::OpRewritePattern; LogicalResult matchAndRewrite(tensor::EmptyOp emptyTensorOp, PatternRewriter &rewriter) const override { @@ -94,9 +94,9 @@ MLIRContext *context = &getContext(); RewritePatternSet patterns(context); if (zeroFill) { - patterns.insert<RewriteInitTensorToSplat>(context); + patterns.insert<RewriteTensorEmptyToSplat>(context); } else { - patterns.insert<RewriteInitTensorToEmpty>(context); + patterns.insert<RewriteTensorEmptyToEmpty>(context); } if (failed(applyPatternsAndFoldGreedily(getOperation(), std::move(patterns)))) {
diff --git a/compiler/src/iree/compiler/Dialect/Flow/Transforms/OptimizeNumerics.cpp b/compiler/src/iree/compiler/Dialect/Flow/Transforms/OptimizeNumerics.cpp index 55c5ec4..f8c4fe1 100644 --- a/compiler/src/iree/compiler/Dialect/Flow/Transforms/OptimizeNumerics.cpp +++ b/compiler/src/iree/compiler/Dialect/Flow/Transforms/OptimizeNumerics.cpp
@@ -99,20 +99,20 @@ Optional<std::pair<int64_t, int64_t>> range; }; -// Eliminates a cast produced by an init_tensor by just initializing to that +// Eliminates a cast produced by an empty by just initializing to that // type directly. -struct LinalgInitTensorCast +struct TensorEmptyCast : OpInterfaceRewritePattern<IREE::Util::NumericCastOpInterface> { using OpInterfaceRewritePattern::OpInterfaceRewritePattern; LogicalResult matchAndRewrite(IREE::Util::NumericCastOpInterface castOp, PatternRewriter &rewriter) const override { - auto emptyTensorOp = castOp.getInput().getDefiningOp<tensor::EmptyOp>(); - if (!emptyTensorOp) return failure(); + auto emptyOp = castOp.getInput().getDefiningOp<tensor::EmptyOp>(); + if (!emptyOp) return failure(); Type resultType = castOp.getCasted().getType(); - rewriter.replaceOpWithNewOp<tensor::EmptyOp>( - castOp, resultType, emptyTensorOp.getDynamicSizes()); + rewriter.replaceOpWithNewOp<tensor::EmptyOp>(castOp, resultType, + emptyOp.getDynamicSizes()); return success(); } }; @@ -263,7 +263,7 @@ patterns.insert<LinalgFpMatmulToLowP>(context); // Cast propagation. - patterns.insert<LinalgInitTensorCast>(context); + patterns.insert<TensorEmptyCast>(context); patterns.insert<LinalgFillCast>(context); if (failed(applyPatternsAndFoldGreedily(getOperation(),
diff --git a/compiler/src/iree/compiler/Dialect/Flow/Transforms/test/convert_region_to_workgroups.mlir b/compiler/src/iree/compiler/Dialect/Flow/Transforms/test/convert_region_to_workgroups.mlir index f448fa6..c2d0a6e 100644 --- a/compiler/src/iree/compiler/Dialect/Flow/Transforms/test/convert_region_to_workgroups.mlir +++ b/compiler/src/iree/compiler/Dialect/Flow/Transforms/test/convert_region_to_workgroups.mlir
@@ -25,8 +25,8 @@ // CHECK-NEXT: (%[[arg3:.*]]: !flow.dispatch.tensor<readonly:tensor<5x10xf32>>, %[[arg4:.*]]: !flow.dispatch.tensor<readonly:tensor<10x11xf32>>, %[[arg5:.*]]: !flow.dispatch.tensor<writeonly:tensor<5x11xf32>>) // CHECK-DAG: %[[loadB:.*]] = flow.dispatch.tensor.load %[[arg3]], offsets = [0, 0], sizes = [5, 10], strides = [1, 1] : !flow.dispatch.tensor<readonly:tensor<5x10xf32>> -> tensor<5x10xf32> // CHECK-DAG: %[[loadC:.*]] = flow.dispatch.tensor.load %[[arg4]], offsets = [0, 0], sizes = [10, 11], strides = [1, 1] : !flow.dispatch.tensor<readonly:tensor<10x11xf32>> -> tensor<10x11xf32> - // CHECK: %[[init_tensor:.*]] = tensor.empty() : tensor<5x11xf32> - // CHECK: %[[fill:.*]] = linalg.fill ins(%{{.*}} : f32) outs(%[[init_tensor]] : tensor<5x11xf32>) -> tensor<5x11xf32> + // CHECK: %[[empty:.*]] = tensor.empty() : tensor<5x11xf32> + // CHECK: %[[fill:.*]] = linalg.fill ins(%{{.*}} : f32) outs(%[[empty]] : tensor<5x11xf32>) -> tensor<5x11xf32> // CHECK: %[[matmul:.*]] = linalg.matmul ins(%[[loadB]], %[[loadC]] : tensor<5x10xf32>, tensor<10x11xf32>) outs(%[[fill]] : tensor<5x11xf32>) -> tensor<5x11xf32> // CHECK: flow.dispatch.tensor.store %[[matmul]], %[[arg5]], offsets = [0, 0], sizes = [5, 11], strides = [1, 1] : tensor<5x11xf32> -> !flow.dispatch.tensor<writeonly:tensor<5x11xf32>> // CHECK: flow.return
diff --git a/compiler/src/iree/compiler/Dialect/Util/Analysis/Constant/OpOracle.cpp b/compiler/src/iree/compiler/Dialect/Util/Analysis/Constant/OpOracle.cpp index 279e9ff..891532f 100644 --- a/compiler/src/iree/compiler/Dialect/Util/Analysis/Constant/OpOracle.cpp +++ b/compiler/src/iree/compiler/Dialect/Util/Analysis/Constant/OpOracle.cpp
@@ -138,7 +138,7 @@ } } - // Never hoist init_tensor. These are sometimes used for pure shape metadata + // Never hoist empty. These are sometimes used for pure shape metadata // and must not be separated from their consumers. if (isa<tensor::EmptyOp>(op)) { return false;
diff --git a/compiler/src/iree/compiler/Dialect/Util/Transforms/test/hoist_into_globals_linalg.mlir b/compiler/src/iree/compiler/Dialect/Util/Transforms/test/hoist_into_globals_linalg.mlir index 49b9471..b144b60 100644 --- a/compiler/src/iree/compiler/Dialect/Util/Transforms/test/hoist_into_globals_linalg.mlir +++ b/compiler/src/iree/compiler/Dialect/Util/Transforms/test/hoist_into_globals_linalg.mlir
@@ -34,7 +34,7 @@ // ----- // Verifies that projected permutations (broadcasts) will never be materialized -// as a leaf. Also verifies that init_tensor operands, which can be considered +// as a leaf. Also verifies that empty operands, which can be considered // const-expr, are not materialized as a leaf. // CHECK-LABEL: @broadcast_treated_as_leaf #map0 = affine_map<(d0, d1) -> ()>
diff --git a/compiler/src/iree/compiler/InputConversion/MHLO/test/convert_mhlo_to_linalg_ext.mlir b/compiler/src/iree/compiler/InputConversion/MHLO/test/convert_mhlo_to_linalg_ext.mlir index ef677bb..1504703 100644 --- a/compiler/src/iree/compiler/InputConversion/MHLO/test/convert_mhlo_to_linalg_ext.mlir +++ b/compiler/src/iree/compiler/InputConversion/MHLO/test/convert_mhlo_to_linalg_ext.mlir
@@ -376,12 +376,12 @@ // CHECK: func.func @rfft_1d // CHECK-SAME: %[[REAL:[a-zA-Z0-9]+]] // CHECK-DAG: %[[INDICES:.+]] = arith.constant dense<[0, 4, 2, 6, 1, 5, 3, 7]> : tensor<8xi32> -// CHECK-DAG: %[[INIT_TENSOR:.+]] = tensor.empty() : tensor<8xf32> +// CHECK-DAG: %[[EMPTY:.+]] = tensor.empty() : tensor<8xf32> // CHECK: %[[REORDERED:.+]] = linalg.generic // CHECK-SAME: {indexing_maps = [#[[MAP]], #[[MAP]]] // CHECK-SAME: iterator_types = ["parallel"] // CHECK-SAME: ins(%[[INDICES]] -// CHECK-SAME: outs(%[[INIT_TENSOR]] +// CHECK-SAME: outs(%[[EMPTY]] // CHECK: ^bb0(%[[IDX:.+]]: i32, %{{.+}}: f32): // CHECK: %[[IDXVAL:.+]] = arith.index_cast %[[IDX]] : i32 to index // CHECK: %[[LOAD:.+]] = tensor.extract %[[REAL]][%[[IDXVAL]]] : tensor<8xf32> @@ -424,12 +424,12 @@ // CHECK: func.func @rfft_2d // CHECK-SAME: %[[REAL:[a-zA-Z0-9]+]] // CHECK-DAG: %[[INDICES:.+]] = arith.constant dense<[0, 4, 2, 6, 1, 5, 3, 7]> : tensor<8xi32> -// CHECK-DAG: %[[INIT_TENSOR:.+]] = tensor.empty() : tensor<4x8xf32> +// CHECK-DAG: %[[EMPTY:.+]] = tensor.empty() : tensor<4x8xf32> // CHECK: %[[REORDERED:.+]] = linalg.generic // CHECK-SAME: {indexing_maps = [#[[MAP0]], #[[MAP1]]] // CHECK-SAME: iterator_types = ["parallel", "parallel"] // CHECK-SAME: ins(%[[INDICES]] -// CHECK-SAME: outs(%[[INIT_TENSOR]] +// CHECK-SAME: outs(%[[EMPTY]] // CHECK: ^bb0(%[[IDX:.+]]: i32, %{{.+}}: f32): // CHECK: %[[I:.+]] = linalg.index 0 // CHECK: %[[IDXVAL:.+]] = arith.index_cast %[[IDX]] : i32 to index
diff --git a/llvm-external-projects/iree-dialects/lib/Dialect/LinalgExt/Passes/MaterializeEncoding.cpp b/llvm-external-projects/iree-dialects/lib/Dialect/LinalgExt/Passes/MaterializeEncoding.cpp index 72fca61..dcfcb92 100644 --- a/llvm-external-projects/iree-dialects/lib/Dialect/LinalgExt/Passes/MaterializeEncoding.cpp +++ b/llvm-external-projects/iree-dialects/lib/Dialect/LinalgExt/Passes/MaterializeEncoding.cpp
@@ -147,11 +147,11 @@ PackOp::getResultShape(rewriter, loc, sourceDims, *innerTileSizesOfr, materializeEncodingInfo->innerDimsPos, materializeEncodingInfo->outerDimsPerm); - auto initTensor = rewriter.create<tensor::EmptyOp>( - loc, resultDims, resultType.getElementType()); + auto emptyOp = rewriter.create<tensor::EmptyOp>(loc, resultDims, + resultType.getElementType()); Optional<Value> paddingValue = getPaddingValue(source); auto packOp = rewriter.create<PackOp>( - loc, source, initTensor, materializeEncodingInfo->innerDimsPos, + loc, source, emptyOp, materializeEncodingInfo->innerDimsPos, *innerTileSizesOfr, paddingValue, materializeEncodingInfo->outerDimsPerm); // As we rewrite the SetEncoding and its old result tensor, which used to hold // the TensorEncodingAttr, into a pack op with a new result tensor which does @@ -183,8 +183,8 @@ Location loc = encodingOp.getLoc(); SmallVector<OpFoldResult> resultDims = getDims(rewriter, loc, encodingOp.getSource()); - auto initTensor = rewriter.create<tensor::EmptyOp>( - loc, resultDims, sourceType.getElementType()); + auto emptyOp = rewriter.create<tensor::EmptyOp>(loc, resultDims, + sourceType.getElementType()); FailureOr<SmallVector<OpFoldResult>> innerTileSizesOfr = getInnerTileSizesOfr(rewriter, loc, sourceType, *materializeEncodingInfo, materializeEncodingValueFn); @@ -193,7 +193,7 @@ encodingOp, "failed to generate runtime tile size query"); } return rewriter.create<UnPackOp>( - loc, packedValue, initTensor, materializeEncodingInfo->innerDimsPos, + loc, packedValue, emptyOp, materializeEncodingInfo->innerDimsPos, *innerTileSizesOfr, materializeEncodingInfo->outerDimsPerm); }