[Mlir-commits] [mlir] ebdb0cb - Add missing test from #68661

Nicolas Vasilache llvmlistbot at llvm.org
Wed Oct 18 04:04:23 PDT 2023


Author: Nicolas Vasilache
Date: 2023-10-18T11:04:01Z
New Revision: ebdb0cbef5e9be57237403c46bfdbe985313bb1c

URL: https://github.com/llvm/llvm-project/commit/ebdb0cbef5e9be57237403c46bfdbe985313bb1c
DIFF: https://github.com/llvm/llvm-project/commit/ebdb0cbef5e9be57237403c46bfdbe985313bb1c.diff

LOG: Add missing test from #68661

Added: 
    mlir/test/Dialect/LLVM/lower-to-llvm-e2e-with-top-level-named-sequence.mlir
    mlir/test/Dialect/Transform/Library/lower-to-llvm-transform-symbol-def.mlir

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/mlir/test/Dialect/LLVM/lower-to-llvm-e2e-with-top-level-named-sequence.mlir b/mlir/test/Dialect/LLVM/lower-to-llvm-e2e-with-top-level-named-sequence.mlir
new file mode 100644
index 000000000000000..6a58a90be962e29
--- /dev/null
+++ b/mlir/test/Dialect/LLVM/lower-to-llvm-e2e-with-top-level-named-sequence.mlir
@@ -0,0 +1,64 @@
+// Note: We run CSE here to make the pattern matching more direct.
+
+// RUN: mlir-opt %s -test-lower-to-llvm -cse | FileCheck %s
+
+// RUN: mlir-opt %s \
+// RUN:   -transform-preload-library=transform-library-paths=%p/../Transform/Library/lower-to-llvm.mlir \
+// RUN:   -transform-interpreter="entry-point=entry_point" \
+// RUN:   -test-transform-dialect-erase-schedule \
+// RUN:   -cse \
+// RUN: | FileCheck %s
+
+// Check that we properly lower to llvm memref operations that require to be
+// expanded first, like `memref.subview`.
+func.func @subview(%0 : memref<64x4xf32, strided<[4, 1], offset: 0>>, %arg0 : index, %arg1 : index, %arg2 : index)
+-> memref<?x?xf32, strided<[?, ?], offset: ?>> {
+  // CHECK-LABEL: @subview
+  // CHECK-SAME: %[[BASE:[^:]*]]: !llvm.ptr
+  // CHECK-SAME: %[[BASE_ALIGNED:[^:]*]]: !llvm.ptr,
+  // CHECK-SAME: %[[BASE_OFFSET:[^:]*]]: i64,
+  // CHECK-SAME: %[[BASE_STRIDE0:[^:]*]]: i64,
+  // CHECK-SAME: %[[BASE_STRIDE1:[^:]*]]: i64,
+  // CHECK-SAME: %[[BASE_SIZE0:[^:]*]]: i64,
+  // CHECK-SAME: %[[BASE_SIZE1:[^:]*]]: i64,
+  // CHECK-SAME: %[[ARG0:[^:]*]]: i64,
+  // CHECK-SAME: %[[ARG1:[^:]*]]: i64,
+  // CHECK-SAME: %[[ARG2:[^:]*]]: i64)
+  // CHECK-SAME: -> !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>
+
+  // CHECK-DAG: %[[STRIDE0:.*]] = llvm.mlir.constant(4 : index) : i64
+  // CHECK-DAG: %[[DESCSTRIDE0:.*]] = llvm.mul %[[ARG0]], %[[STRIDE0]] : i64
+  // CHECK-DAG: %[[OFF2:.*]] = llvm.add %[[DESCSTRIDE0]], %[[ARG1]] : i64
+  // CHECK-DAG: %[[DESC:.*]] = llvm.mlir.undef : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)>
+
+  // Base address and algined address.
+  // CHECK-DAG: %[[DESC0:.*]] = llvm.insertvalue %[[BASE]], %[[DESC]][0] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)>
+  // CHECK-DAG: %[[DESC1:.*]] = llvm.insertvalue %[[BASE_ALIGNED]], %[[DESC0]][1] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)>
+
+  // Offset.
+  // CHECK: %[[DESC2:.*]] = llvm.insertvalue %[[OFF2]], %[[DESC1]][2] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)>
+  // Size 0.
+  // CHECK: %[[DESC3:.*]] = llvm.insertvalue %[[ARG0]], %[[DESC2]][3, 0] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)>
+  // Stride 0 == 4 * %arg0.
+  // CHECK: %[[DESC4:.*]] = llvm.insertvalue %[[DESCSTRIDE0]], %[[DESC3]][4, 0] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)>
+  // Size 1.
+  // CHECK: %[[DESC5:.*]] = llvm.insertvalue %[[ARG1]], %[[DESC4]][3, 1] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)>
+  // Stride 1 == 1 * %arg1.
+  // CHECK: %[[DESC6:.*]] = llvm.insertvalue %[[ARG1]], %[[DESC5]][4, 1] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)>
+
+  %1 = memref.subview %0[%arg0, %arg1][%arg0, %arg1][%arg0, %arg1] :
+    memref<64x4xf32, strided<[4, 1], offset: 0>>
+  to memref<?x?xf32, strided<[?, ?], offset: ?>>
+  return %1 : memref<?x?xf32, strided<[?, ?], offset: ?>>
+}
+
+module @named_inclusion_in_named attributes { transform.with_named_sequence } {
+  transform.named_sequence private @lower_to_llvm(!transform.any_op {transform.readonly}) -> !transform.any_op
+
+  transform.named_sequence @entry_point(
+    %toplevel_module : !transform.any_op {transform.readonly}) {
+    transform.include @lower_to_llvm failures(suppress) (%toplevel_module) 
+      : (!transform.any_op) -> (!transform.any_op)
+    transform.yield
+  }
+}

diff  --git a/mlir/test/Dialect/Transform/Library/lower-to-llvm-transform-symbol-def.mlir b/mlir/test/Dialect/Transform/Library/lower-to-llvm-transform-symbol-def.mlir
new file mode 100644
index 000000000000000..0ba50bd2362b34d
--- /dev/null
+++ b/mlir/test/Dialect/Transform/Library/lower-to-llvm-transform-symbol-def.mlir
@@ -0,0 +1,48 @@
+// RUN: mlir-opt %s
+
+/// Schedule to lower to LLVM.
+module @lower_module_to_llvm attributes { transform.with_named_sequence } {
+
+transform.named_sequence @lower_to_llvm(
+    %module: !transform.any_op {transform.readonly}) -> !transform.any_op {
+
+  %func = transform.structured.match ops{["func.func"]} in %module : (!transform.any_op) -> !transform.any_op
+  %f = transform.apply_registered_pass "convert-vector-to-scf" to %func : (!transform.any_op) -> !transform.any_op
+  %f2 = transform.apply_registered_pass "convert-linalg-to-loops" to %f : (!transform.any_op) -> !transform.any_op
+  %f3 = transform.apply_registered_pass "convert-scf-to-cf" to %f2 : (!transform.any_op) -> !transform.any_op
+  %f4 = transform.apply_registered_pass "expand-strided-metadata" to %f3 : (!transform.any_op) -> !transform.any_op
+  %f5 = transform.apply_registered_pass "lower-affine" to %f4 : (!transform.any_op) -> !transform.any_op
+
+  transform.apply_conversion_patterns to %f5 {
+    transform.apply_conversion_patterns.dialect_to_llvm "math"
+    transform.apply_conversion_patterns.vector.vector_to_llvm
+    transform.apply_conversion_patterns.dialect_to_llvm "memref"
+    transform.apply_conversion_patterns.func.func_to_llvm
+    transform.apply_conversion_patterns.dialect_to_llvm "index"
+    transform.apply_conversion_patterns.dialect_to_llvm "arith"
+    transform.apply_conversion_patterns.dialect_to_llvm "cf"
+  } with type_converter {
+    transform.apply_conversion_patterns.memref.memref_to_llvm_type_converter
+      {index_bitwidth = 64,
+       use_bare_ptr = false,
+       use_bare_ptr_memref_call_conv = false,
+       use_opaque_pointers = true}
+  } {
+    legal_dialects = ["llvm"],
+    partial_conversion
+  } : !transform.any_op
+
+  // Need to rematch here because:
+  //   1. applying reconcile-unrealized-casts on the whole module yields the
+  //      transform applies to transform, when called from a named sequence, at
+  //      this time.
+  //   2. apply_conversion patterns consumes the func but does not produce 
+  //      a new llvm.func.
+  %f6 = transform.structured.match ops{["llvm.func"]} in %module 
+    : (!transform.any_op) -> !transform.any_op
+  %f7 = transform.apply_registered_pass "reconcile-unrealized-casts" to %f6
+    : (!transform.any_op) -> !transform.any_op
+  transform.yield %module : !transform.any_op
+}
+
+} // transform module


        


More information about the Mlir-commits mailing list