diff --git a/BUILD b/BUILD index 21ae9b18c..2b41b06d9 100644 --- a/BUILD +++ b/BUILD @@ -1100,7 +1100,6 @@ cc_library( cc_library( name = "transforms_passes", srcs = [ - "mhlo/analysis/test_shape_component_analysis.cc", "transforms/alloc_to_arg_pass.cc", "transforms/bufferize.cc", "transforms/bufferize_pass.cc", diff --git a/mhlo/analysis/CMakeLists.txt b/mhlo/analysis/CMakeLists.txt index de8c9c223..c5a6a0a7f 100644 --- a/mhlo/analysis/CMakeLists.txt +++ b/mhlo/analysis/CMakeLists.txt @@ -9,18 +9,3 @@ add_mlir_library(MhloAnalysis MLIRIR LmhloDialect ) - -add_mlir_library(MhloTestAnalysis - test_shape_component_analysis.cc - - LINK_COMPONENTS - Core - - DEPENDS - LMHLOTransformsPassIncGen - - LINK_LIBS PUBLIC - MLIRAnalysis - MLIRPass - MLIRTransforms -) diff --git a/mhlo/analysis/test_shape_component_analysis.cc b/mhlo/analysis/test_shape_component_analysis.cc deleted file mode 100644 index b3b0c4a73..000000000 --- a/mhlo/analysis/test_shape_component_analysis.cc +++ /dev/null @@ -1,76 +0,0 @@ -/* Copyright 2021 The OpenXLA Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -==============================================================================*/ - -#include - -#include "mhlo/IR/hlo_ops.h" -#include "mhlo/analysis/shape_component_analysis.h" -#include "mlir/Dialect/Func/IR/FuncOps.h" -#include "mlir/Pass/Pass.h" - -namespace mlir { - -#define GEN_PASS_DEF_TESTSHAPECOMPONENTANALYSIS -#include "transforms/passes.h.inc" - -using SymbolicExpr = ShapeComponentAnalysis::SymbolicExpr; - -namespace { - -struct TestShapeComponentAnalysisPass - : public impl::TestShapeComponentAnalysisBase< - TestShapeComponentAnalysisPass> { - void getDependentDialects(DialectRegistry& registry) const override { - registry.insert(); - } - - void runOnOperation() override { - ShapeComponentAnalysis shapeComponent; - llvm::outs() << "Testing : " << getOperation().getName() << '\n'; - // Analyze anything that looks like a shape tensor. - getOperation().walk([&](Operation* op) { - // Skip ops with more than one result. - if (op->getNumResults() != 1) return; - Value result = op->getResults().front(); - - // Dump shape info if any. - if (auto shapeInfo = shapeComponent.GetShapeInfo(result)) { - llvm::outs() << "Shape info for " << result << ":\n"; - for (const SymbolicExpr& d : *shapeInfo) { - llvm::outs().indent(2); - d.dump(llvm::outs()); - } - } - - // Dump value info if any. - if (auto valueInfo = shapeComponent.GetValueInfo(result)) { - llvm::outs() << "Value info for " << result << ":\n"; - for (const SymbolicExpr& d : *valueInfo) { - llvm::outs().indent(2); - d.dump(llvm::outs()); - } - } - }); - } -}; - -} // end anonymous namespace - -std::unique_ptr> -createTestShapeComponentAnalysisPass() { - return std::make_unique(); -} - -} // namespace mlir diff --git a/tests/shape-component-analysis.mlir b/tests/shape-component-analysis.mlir deleted file mode 100644 index e088b4345..000000000 --- a/tests/shape-component-analysis.mlir +++ /dev/null @@ -1,365 +0,0 @@ -// RUN: mlir-hlo-opt --test-print-shape-components --split-input-file %s | FileCheck %s - -// CHECK-LABEL: Testing : assuming -func.func @assuming(%arg0: tensor, %arg1: tensor, %arg2 : !shape.witness) -> tensor<2xi32> { - %0:2 = shape.assuming %arg2 -> (tensor, tensor) { - shape.assuming_yield %arg0, %arg1 : tensor, tensor - } - %1 = shape.shape_of %0#0 : tensor -> tensor<2xindex> - %2 = shape.shape_of %0#1 : tensor -> tensor<2xindex> - %3 = arith.index_cast %1 : tensor<2xindex> to tensor<2xi32> - %4 = arith.index_cast %2 : tensor<2xindex> to tensor<2xi32> - // CHECK: Value info for %5 = mhlo.add %3, %4 : tensor<2xi32> - // CHECK-NEXT: s0 + s1 with - // CHECK-NEXT: s0 = shapeof( of type 'tensor' at index: 0)[0] - // CHECK-NEXT: s1 = shapeof( of type 'tensor' at index: 1)[0] - // CHECK-NEXT: s0 + s1 with - // CHECK-NEXT: s0 = shapeof( of type 'tensor' at index: 0)[1] - // CHECK-NEXT: s1 = shapeof( of type 'tensor' at index: 1)[1] - %5 = mhlo.add %3, %4 : tensor<2xi32> - // CHECK: Value info for %6 = mhlo.multiply %5, %4 : tensor<2xi32> - // CHECK-NEXT: (s0 + s1) * s2 with - // CHECK-NEXT: s0 = shapeof( of type 'tensor' at index: 0)[0] - // CHECK-NEXT: s1 = shapeof( of type 'tensor' at index: 1)[0] - // CHECK-NEXT: s2 = shapeof( of type 'tensor' at index: 1)[0] - // CHECK-NEXT: (s0 + s1) * s2 with - // CHECK-NEXT: s0 = shapeof( of type 'tensor' at index: 0)[1] - // CHECK-NEXT: s1 = shapeof( of type 'tensor' at index: 1)[1] - // CHECK-NEXT: s2 = shapeof( of type 'tensor' at index: 1)[1] - %6 = mhlo.multiply %5, %4 : tensor<2xi32> - func.return %6 : tensor<2xi32> -} - -// ----- - -// CHECK-LABEL: Testing : num_elements -func.func @num_elements(%arg0: tensor) -> index { - // CHECK: Value info for %0 = shape.shape_of %arg0 : tensor -> tensor<4xindex> - // CHECK-NEXT: s0 with - // CHECK-NEXT: s0 = shapeof( of type 'tensor' at index: 0)[0] - // CHECK-NEXT: 8 - // CHECK-NEXT: s0 with - // CHECK-NEXT: s0 = shapeof( of type 'tensor' at index: 0)[2] - // CHECK-NEXT: 64 - %0 = shape.shape_of %arg0 : tensor -> tensor<4xindex> - // CHECK: Value info for %1 = shape.num_elements %0 : tensor<4xindex> -> index: - // CHECK-NEXT: (s0 * s1) * 512 with - // CHECK-NEXT: s0 = shapeof( of type 'tensor' at index: 0)[0] - // CHECK-NEXT: s1 = shapeof( of type 'tensor' at index: 0)[2] - %1 = shape.num_elements %0 : tensor<4xindex> -> index - func.return %1 : index -} - -// ----- - -// CHECK-LABEL: Testing : dynamic_broadcast_in_dim -func.func @dynamic_broadcast_in_dim(%arg0: tensor, %arg1: tensor) -> tensor<2xindex> { - %0 = shape.shape_of %arg0 : tensor -> tensor<2xindex> - %1 = "mhlo.dynamic_broadcast_in_dim"(%arg0, %0) {broadcast_dimensions = dense<[0, 1]> : tensor<2xi64>} : (tensor, tensor<2xindex>) -> tensor - // CHECK: Value info for %2 = shape.shape_of %1 : tensor -> tensor<2xindex> - // CHECK-NEXT: s0 with - // CHECK-NEXT: s0 = shapeof( of type 'tensor' at index: 0)[0] - // CHECK-NEXT: s0 with - // CHECK-NEXT: s0 = shapeof( of type 'tensor' at index: 0)[1] - %2 = shape.shape_of %1 : tensor -> tensor<2xindex> - func.return %2 : tensor<2xindex> -} - -// ----- - -// CHECK-LABEL: Testing : dynamic_reshape -func.func @dynamic_reshape(%arg0: tensor, %arg1: tensor) -> tensor<2xindex> { - %0 = shape.shape_of %arg0 : tensor -> tensor<2xindex> - %1 = "mhlo.dynamic_reshape"(%arg0, %0) {broadcast_dimensions = dense<[0, 1]> : tensor<2xi64>} : (tensor, tensor<2xindex>) -> tensor - // CHECK: Value info for %2 = shape.shape_of %1 : tensor -> tensor<2xindex> - // CHECK-NEXT: s0 with - // CHECK-NEXT: s0 = shapeof( of type 'tensor' at index: 0)[0] - // CHECK-NEXT: s0 with - // CHECK-NEXT: s0 = shapeof( of type 'tensor' at index: 0)[1] - %2 = shape.shape_of %1 : tensor -> tensor<2xindex> - func.return %2 : tensor<2xindex> -} - -// ----- - -// CHECK-LABEL: Testing : reduce -func.func @reduce(%arg0: tensor, %arg1: tensor) -> tensor<2xindex> { - %0 = "mhlo.reduce"(%arg0, %arg1) ({ - ^bb0(%a: tensor, %b: tensor): - %26 = mhlo.add %a, %b : tensor - "mhlo.return"(%26) : (tensor) -> () - }) {dimensions = dense<1> : tensor<1xi64>} : (tensor, tensor) -> tensor - // CHECK: Value info for %1 = shape.shape_of %0 : tensor -> tensor<2xindex> - // CHECK-NEXT: s0 with - // CHECK-NEXT: s0 = shapeof( of type 'tensor' at index: 0)[0] - // CHECK-NEXT: s0 with - // CHECK-NEXT: s0 = shapeof( of type 'tensor' at index: 0)[2] - %1 = shape.shape_of %0 : tensor -> tensor<2xindex> - func.return %1 : tensor<2xindex> -} - -// ----- - -// CHECK-LABEL: Testing : transpose -func.func @transpose(%arg0: tensor) -> tensor<2xindex> { - %0 = "mhlo.transpose"(%arg0) {permutation = dense<[1, 0]> : tensor<2xi64>} : (tensor) -> tensor - // CHECK: Value info for %1 = shape.shape_of %0 : tensor -> tensor<2xindex> - // CHECK-NEXT: s0 with - // CHECK-NEXT: s0 = shapeof( of type 'tensor' at index: 0)[1] - // CHECK-NEXT: s0 with - // CHECK-NEXT: s0 = shapeof( of type 'tensor' at index: 0)[0] - %1 = shape.shape_of %0 : tensor -> tensor<2xindex> - func.return %1 : tensor<2xindex> -} - -// ----- - -// CHECK-LABEL: Testing : select -func.func @select(%arg0: tensor, %arg1: tensor, %arg2: tensor) -> tensor<2xindex> { - %0 = "mhlo.select"(%arg0, %arg1, %arg2) : (tensor, tensor, tensor) -> tensor - // CHECK: Value info for %1 = shape.shape_of %0 : tensor -> tensor<2xindex> - // CHECK-NEXT: s0 with - // CHECK-NEXT: s0 = shapeof( of type 'tensor' at index: 1)[0] - // CHECK-NEXT: s0 with - // CHECK-NEXT: s0 = shapeof( of type 'tensor' at index: 1)[1] - %1 = shape.shape_of %0 : tensor -> tensor<2xindex> - func.return %1 : tensor<2xindex> -} - -// ----- - -// CHECK-LABEL: Testing : dim -func.func @dim(%arg0: tensor) -> tensor<2xindex> { - %c0 = arith.constant 0 : index - %d0 = tensor.dim %arg0, %c0 : tensor - %t = tensor.from_elements %d0, %d0 : tensor<2xindex> - // CHECK: Value info for %{{.*}} = tensor.from_elements %{{.*}}, %{{.*}} : tensor<2xindex> - // CHECK-NEXT: s0 with - // CHECK-NEXT: s0 = shapeof( of type 'tensor' at index: 0)[0] - // CHECK-NEXT: s0 with - // CHECK-NEXT: s0 = shapeof( of type 'tensor' at index: 0)[0] - func.return %t : tensor<2xindex> -} - -// ----- - -// CHECK-LABEL: Testing : extract -func.func @extract(%arg0: tensor) -> tensor<2xindex> { - %shape = shape.shape_of %arg0 : tensor -> tensor<2xindex> - %c1 = arith.constant 1 : index - %d0 = tensor.extract %shape[%c1] : tensor<2xindex> - // CHECK: Value info for %{{.*}} = tensor.from_elements %{{.*}}, %{{.*}} : tensor<2xindex> - // CHECK-NEXT: s0 with - // CHECK-NEXT: s0 = shapeof( of type 'tensor' at index: 0)[1] - // CHECK-NEXT: s0 with - // CHECK-NEXT: s0 = shapeof( of type 'tensor' at index: 0)[1] - %t = tensor.from_elements %d0, %d0 : tensor<2xindex> - func.return %t : tensor<2xindex> -} - -// ----- - -// CHECK-LABEL: Testing : symbolic_constraint -func.func @symbolic_constraint( - %arg0: tensor - {rt.symbolic_shape = dense<[-3, -2]> : tensor<2xi64>}, - %arg1: tensor - {rt.symbolic_shape = dense<[-4, -2]> : tensor<2xi64>} -) -> tensor<2xi32> { - %0 = shape.shape_of %arg0 : tensor -> tensor<2xindex> - %1 = shape.shape_of %arg1 : tensor -> tensor<2xindex> - %2 = arith.index_cast %0 : tensor<2xindex> to tensor<2xi32> - %3 = arith.index_cast %1 : tensor<2xindex> to tensor<2xi32> - // CHECK: Value info for %4 = mhlo.add %2, %3 : tensor<2xi32>: - // CHECK-NEXT: s0 + s1 with - // CHECK-NEXT: s0 = shapeof( of type 'tensor' at index: 0)[0] - // CHECK-NEXT: s1 = shapeof( of type 'tensor' at index: 1)[0] - // CHECK-NEXT: s0 + s1 with - // CHECK-NEXT: s0 = shapeof( of type 'tensor' at index: 0)[1] - // CHECK-NEXT: s1 = shapeof( of type 'tensor' at index: 0)[1] - %4 = mhlo.add %2, %3 : tensor<2xi32> - func.return %4 : tensor<2xi32> -} - -// ----- - -// CHECK-LABEL: Testing : dynamic_reshape -func.func @dynamic_reshape(%arg0: tensor, %arg1: tensor<4xi32>) - -> tensor { - %0 = shape.shape_of %arg0 : tensor -> tensor<4xindex> - %1 = shape.num_elements %0 : tensor<4xindex> -> index - %2 = mhlo.compute_reshape_shape %1, %arg1 : (index, tensor<4xi32>) - -> tensor<4xi32> - // CHECK: Shape info for %3 = mhlo.dynamic_reshape %arg0, %2 : (tensor, tensor<4xi32>) -> tensor - // CHECK-NEXT: s0 with - // CHECK-NEXT: s0 = %2 = mhlo.compute_reshape_shape %1, %arg1 : (index, tensor<4xi32>) -> tensor<4xi32>[0] - // CHECK-NEXT: 8 - // CHECK-NEXT: s0 with - // CHECK-NEXT: s0 = %2 = mhlo.compute_reshape_shape %1, %arg1 : (index, tensor<4xi32>) -> tensor<4xi32>[2] - // CHECK-NEXT: 64 - %3 = "mhlo.dynamic_reshape"(%arg0, %2) - : (tensor, tensor<4xi32>) -> tensor - func.return %3 : tensor -} - -// ----- - -// Larger examples. - -// CHECK-LABEL: Testing : softmax -func.func @softmax(%arg0: tensor) -> tensor { - %0 = mhlo.constant dense<-1> : tensor<1xi64> - %1 = "mhlo.convert"(%arg0) : (tensor) -> tensor - %2 = mhlo.constant dense<0xFF800000> : tensor - %3 = "mhlo.reduce"(%1, %2) ({ - ^bb0(%arg1: tensor, %arg2: tensor): - %26 = mhlo.maximum %arg1, %arg2 : tensor - "mhlo.return"(%26) : (tensor) -> () - }) {dimensions = dense<1> : tensor<1xi64>} : (tensor, tensor) -> tensor - %4 = "mhlo.convert"(%3) : (tensor) -> tensor - %cst = arith.constant dense<1> : tensor<1xi32> - // CHECK: Value info for %5 = shape.shape_of - // CHECK-NEXT: s0 with - // CHECK-NEXT: s0 = shapeof( of type 'tensor' at index: 0)[0] - %5 = shape.shape_of %4 : tensor -> tensor<1xindex> - %c1 = arith.constant 1 : index - %c0 = arith.constant 0 : index - // CHECK: Value info for %{{.*}} = tensor.extract - // CHECK-NEXT: s0 with - // CHECK-NEXT: s0 = shapeof( of type 'tensor' at index: 0)[0] - %6 = tensor.extract %5[%c0] : tensor<1xindex> - // CHECK: Value info for %{{.*}} = tensor.from_elements - // CHECK-NEXT: s0 with - // CHECK-NEXT: s0 = shapeof( of type 'tensor' at index: 0)[0] - // CHECK-NEXT: 1 - %7 = tensor.from_elements %6, %c1 : tensor<2xindex> - %8 = "mhlo.dynamic_reshape"(%4, %7) : (tensor, tensor<2xindex>) -> tensor - %9 = shape.shape_of %arg0 : tensor -> tensor<2xindex> - %10 = shape.shape_of %8 : tensor -> tensor<2xindex> - %11 = shape.cstr_broadcastable %9, %10 : tensor<2xindex>, tensor<2xindex> - %12 = shape.assuming %11 -> (tensor) { - // CHECK: Value info for %{{.*}} = shape.shape_of %arg0 : tensor -> tensor<2xindex>: - // CHECK-NEXT: s0 with - // CHECK-NEXT: s0 = shapeof( of type 'tensor' at index: 0)[0] - // CHECK-NEXT: s0 with - // CHECK-NEXT: s0 = shapeof( of type 'tensor' at index: 0)[1] - %26 = shape.shape_of %arg0 : tensor -> tensor<2xindex> - // CHECK: Value info for %{{.*}} = shape.shape_of - // CHECK-NEXT: s0 with - // CHECK-NEXT: s0 = shapeof( of type 'tensor' at index: 0)[0] - // CHECK-NEXT: 1 - %27 = shape.shape_of %8 : tensor -> tensor<2xindex> - %28 = shape.broadcast %26, %27 : tensor<2xindex>, tensor<2xindex> -> tensor<2xindex> - %29 = "mhlo.dynamic_broadcast_in_dim"(%arg0, %28) {broadcast_dimensions = dense<[0, 1]> : tensor<2xi64>} : (tensor, tensor<2xindex>) -> tensor - %30 = "mhlo.dynamic_broadcast_in_dim"(%8, %28) {broadcast_dimensions = dense<[0, 1]> : tensor<2xi64>} : (tensor, tensor<2xindex>) -> tensor - %31 = mhlo.subtract %29, %30 : tensor - shape.assuming_yield %31 : tensor - } - %13 = "mhlo.exponential"(%12) : (tensor) -> tensor - %14 = "mhlo.convert"(%13) : (tensor) -> tensor - %15 = mhlo.constant dense<0.000000e+00> : tensor - %16 = "mhlo.reduce"(%14, %15) ({ - ^bb0(%arg1: tensor, %arg2: tensor): - %26 = mhlo.add %arg1, %arg2 : tensor - "mhlo.return"(%26) : (tensor) -> () - }) {dimensions = dense<1> : tensor<1xi64>} : (tensor, tensor) -> tensor - %17 = "mhlo.convert"(%16) : (tensor) -> tensor - %cst_0 = arith.constant dense<1> : tensor<1xi32> - %18 = shape.shape_of %17 : tensor -> tensor<1xindex> - %c1_1 = arith.constant 1 : index - %c0_2 = arith.constant 0 : index - %19 = tensor.extract %18[%c0_2] : tensor<1xindex> - %20 = tensor.from_elements %19, %c1_1 : tensor<2xindex> - %21 = "mhlo.dynamic_reshape"(%17, %20) : (tensor, tensor<2xindex>) -> tensor - %22 = shape.shape_of %13 : tensor -> tensor<2xindex> - %23 = shape.shape_of %21 : tensor -> tensor<2xindex> - %24 = shape.cstr_broadcastable %22, %23 : tensor<2xindex>, tensor<2xindex> - %25 = shape.assuming %24 -> (tensor) { - %26 = shape.shape_of %13 : tensor -> tensor<2xindex> - %27 = shape.shape_of %21 : tensor -> tensor<2xindex> - %28 = shape.broadcast %26, %27 : tensor<2xindex>, tensor<2xindex> -> tensor<2xindex> - %29 = "mhlo.dynamic_broadcast_in_dim"(%13, %28) {broadcast_dimensions = dense<[0, 1]> : tensor<2xi64>} : (tensor, tensor<2xindex>) -> tensor - %30 = "mhlo.dynamic_broadcast_in_dim"(%21, %28) {broadcast_dimensions = dense<[0, 1]> : tensor<2xi64>} : (tensor, tensor<2xindex>) -> tensor - %31 = mhlo.divide %29, %30 : tensor - shape.assuming_yield %31 : tensor - } - func.return %25 : tensor -} - -// ----- - -// CHECK-LABEL: Testing : reshape_integration -func.func @reshape_integration(%arg0: tensor<512x512xf32>, %arg1: tensor, %arg2: tensor<4xi32>, %arg3: tensor<512xf32>, %arg4: tensor, %arg5: tensor<512xf32>, %arg6: tensor<512xf32>, %arg7: tensor<512x2048xf32>, %arg8: tensor<2048xf32>, %arg9: tensor<2048x512xf32>, %arg10: tensor<512xf32>, %arg11: tensor<512xf32>, %arg12: tensor<512xf32>) -> tensor { - %0 = mhlo.constant dense<512> : tensor<1xi32> - %1 = shape.shape_of %arg1 : tensor -> tensor<4xindex> - %2 = shape.num_elements %1 : tensor<4xindex> -> index - %3 = mhlo.cstr_reshapable %2, %arg2 : (index, tensor<4xi32>) -> !shape.witness - %4 = "mhlo.dynamic_reshape"(%arg1, %arg2) : (tensor, tensor<4xi32>) -> tensor - %5 = "mhlo.transpose"(%4) {permutation = dense<[0, 2, 1, 3]> : tensor<4xi64>} : (tensor) -> tensor - %6 = "mhlo.transpose"(%5) {permutation = dense<[0, 1, 3, 2]> : tensor<4xi64>} : (tensor) -> tensor - %7 = shape.shape_of %6 : tensor -> tensor<4xindex> - %8 = arith.index_cast %7 : tensor<4xindex> to tensor<4xi32> - %9 = "mhlo.slice"(%8) {limit_indices = dense<1> : tensor<1xi64>, start_indices = dense<0> : tensor<1xi64>, strides = dense<1> : tensor<1xi64>} : (tensor<4xi32>) -> tensor<1xi32> - %10 = "mhlo.reshape"(%9) : (tensor<1xi32>) -> tensor - %11 = "mhlo.slice"(%8) {limit_indices = dense<2> : tensor<1xi64>, start_indices = dense<1> : tensor<1xi64>, strides = dense<1> : tensor<1xi64>} : (tensor<4xi32>) -> tensor<1xi32> - %12 = "mhlo.reshape"(%11) : (tensor<1xi32>) -> tensor - %13 = mhlo.multiply %10, %12 : tensor - %14 = "mhlo.reshape"(%13) : (tensor) -> tensor<1xi32> - // CHECK: Value info for %15 = "mhlo.concatenate"(%14, %0) {dimension = 0 : i64} : (tensor<1xi32>, tensor<1xi32>) -> tensor<2xi32> - // CHECK-NEXT: s0 * s1 with - // CHECK-NEXT: s0 = of type 'tensor<4xi32>' at index: 2[0] - // CHECK-NEXT: s1 = of type 'tensor<4xi32>' at index: 2[2] - // CHECK-NEXT: 512 - %15 = "mhlo.concatenate"(%14, %0) {dimension = 0 : i64} : (tensor<1xi32>, tensor<1xi32>) -> tensor<2xi32> - // CHECK: Value info for %16 = shape.shape_of %6 : tensor -> tensor<4xindex>: - // CHECK-NEXT: s0 with - // CHECK-NEXT: s0 = of type 'tensor<4xi32>' at index: 2[0] - // CHECK-NEXT: s0 with - // CHECK-NEXT: s0 = of type 'tensor<4xi32>' at index: 2[2] - // CHECK-NEXT: 64 - // CHECK-NEXT: 8 - %16 = shape.shape_of %6 : tensor -> tensor<4xindex> - %17 = shape.num_elements %16 : tensor<4xindex> -> index - %18 = mhlo.cstr_reshapable %17, %15 : (index, tensor<2xi32>) -> !shape.witness - %19 = shape.assuming %18 -> (tensor) { - %21 = "mhlo.dynamic_reshape"(%6, %15) : (tensor, tensor<2xi32>) -> tensor - shape.assuming_yield %21 : tensor - } - func.return %19 : tensor -} - -// ----- - -// CHECK-LABEL: Testing : broadcast -func.func @broadcast(%arg0 : tensor, %arg1 : tensor<1x?x7xf32>) - -> tensor<3xindex> { - %s0 = shape.shape_of %arg0 : tensor -> tensor<3xindex> - %s1 = shape.shape_of %arg1 : tensor<1x?x7xf32> -> tensor<3xindex> - // CHECK: Value info for %2 = shape.broadcast %0, %1 : tensor<3xindex>, tensor<3xindex> -> tensor<3xindex>: - // CHECK-NEXT: s0 with - // CHECK-NEXT: s0 = shapeof( of type 'tensor' at index: 0)[0] - // CHECK-NEXT: 5 - // CHECK-NEXT: 7 - %0 = shape.broadcast %s0, %s1 : tensor<3xindex>, tensor<3xindex> - -> tensor<3xindex> - func.return %0 : tensor<3xindex> -} - -// ----- - -// CHECK-LABEL: Testing : broadcast -func.func @broadcast(%arg0 : tensor, %arg1 : tensor<1x5x?x?xf32>) - -> tensor<4xindex> { - %s0 = shape.shape_of %arg0 : tensor -> tensor<1xindex> - %s1 = shape.shape_of %arg1 : tensor<1x5x?x?xf32> -> tensor<4xindex> - // CHECK: Value info for %2 = shape.broadcast %0, %1 : tensor<1xindex>, tensor<4xindex> -> tensor<4xindex>: - // CHECK-NEXT: 1 - // CHECK-NEXT: 5 - // CHECK-NEXT: s0 with - // CHECK-NEXT: s0 = shapeof( of type 'tensor<1x5x?x?xf32>' at index: 1)[2] - // CHECK-NEXT: s0 with - // CHECK-NEXT: s0 = %2 = shape.broadcast %{{.*}}, %{{.*}} : tensor<1xindex>, tensor<4xindex> -> tensor<4xindex>[3] - %0 = shape.broadcast %s0, %s1 : tensor<1xindex>, tensor<4xindex> - -> tensor<4xindex> - func.return %0 : tensor<4xindex> -} diff --git a/tools/mlir-hlo-opt/CMakeLists.txt b/tools/mlir-hlo-opt/CMakeLists.txt index 48c132706..08a4c9cef 100644 --- a/tools/mlir-hlo-opt/CMakeLists.txt +++ b/tools/mlir-hlo-opt/CMakeLists.txt @@ -30,7 +30,6 @@ set(LIBS MLIRBufferTransforms MLIRHLOGPUTransforms MhloRegisterDialects - MhloTestAnalysis ) add_llvm_executable(mlir-hlo-opt mlir-hlo-opt.cc DEPENDS diff --git a/transforms/passes.h b/transforms/passes.h index a668cc250..3ecee8797 100644 --- a/transforms/passes.h +++ b/transforms/passes.h @@ -51,10 +51,6 @@ using BufferizePatternsCallback = std::function> -createTestShapeComponentAnalysisPass(); - // Pass to lower index cast on tensors to tensor dialect. std::unique_ptr> createLowerIndexCastPass(); diff --git a/transforms/passes.td b/transforms/passes.td index e5a36ae6c..88b0649da 100644 --- a/transforms/passes.td +++ b/transforms/passes.td @@ -51,12 +51,6 @@ def TileLoopsPass : Pass<"tile-loops", "func::FuncOp"> { let dependentDialects = ["affine::AffineDialect"]; } -def TestShapeComponentAnalysis : Pass<"test-print-shape-components", - "func::FuncOp"> { - let summary = "Test pass for analyzing shape components."; - let constructor = "createTestShapeComponentAnalysisPass()"; -} - def LowerIndexCastPass : Pass<"lower-index-cast", "mlir::func::FuncOp"> { let summary = "Lower index cast on tensors to tensor dialect";