[Mlir-commits] [mlir] fd11cda - [mlir] StdToLLVM: Add error when the sourceMemRef of a subview is not a llvm type.

Alex Zinenko llvmlistbot at llvm.org
Wed Feb 12 06:13:36 PST 2020


Author: Pierre Oechsel
Date: 2020-02-12T15:13:18+01:00
New Revision: fd11cda2519f91e2f522f58f137b3082a65b5f62

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

LOG: [mlir] StdToLLVM: Add error when the sourceMemRef of a subview is not a llvm type.

A memref_cast casting to a memref with a non identity map can't be
lowered to llvm. Take the following case:

```

func @invalid_memref_cast(%arg0: memref<?x?xf64>) {
  %c1 = constant 1 : index
  %c0 = constant 0 : index
  %5 = memref_cast %arg0 : memref<?x?xf64> to memref<?x?xf64, #map1>
  %25 = std.subview %5[%c0, %c0][%c1, %c1][] : memref<?x?xf64, #map1> to memref<?x?xf64, #map1>
  return
}
```

When lowering the subview mlir was assuming `%5` to have an llvm type
(which is not the case as mlir failed to lower the memref_cast).

Differential Revision: https://reviews.llvm.org/D74466

Added: 
    mlir/test/Conversion/StandardToLLVM/invalid.mlir

Modified: 
    mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp b/mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp
index 17209c72e054..8d97ff1bd8ab 100644
--- a/mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp
+++ b/mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp
@@ -385,7 +385,8 @@ LLVMOpLowering::LLVMOpLowering(StringRef rootOpName, MLIRContext *context,
 /*============================================================================*/
 StructBuilder::StructBuilder(Value v) : value(v) {
   assert(value != nullptr && "value cannot be null");
-  structType = value.getType().cast<LLVM::LLVMType>();
+  structType = value.getType().dyn_cast<LLVM::LLVMType>();
+  assert(structType && "expected llvm type");
 }
 
 Value StructBuilder::extractPtr(OpBuilder &builder, Location loc,
@@ -2303,6 +2304,8 @@ struct SubViewOpLowering : public LLVMLegalizationPattern<SubViewOp> {
       return matchFailure();
 
     // Create the descriptor.
+    if (!operands.front().getType().isa<LLVM::LLVMType>())
+      return matchFailure();
     MemRefDescriptor sourceMemRef(operands.front());
     auto targetMemRef = MemRefDescriptor::undef(rewriter, loc, targetDescTy);
 

diff  --git a/mlir/test/Conversion/StandardToLLVM/invalid.mlir b/mlir/test/Conversion/StandardToLLVM/invalid.mlir
new file mode 100644
index 000000000000..e0b1889e95c8
--- /dev/null
+++ b/mlir/test/Conversion/StandardToLLVM/invalid.mlir
@@ -0,0 +1,13 @@
+// RUN: mlir-opt %s -verify-diagnostics -split-input-file
+
+#map1 = affine_map<(d0, d1)[s0, s1, s2] -> (d0 * s1 + s0 + d1 * s2)>
+
+func @invalid_memref_cast(%arg0: memref<?x?xf64>) {
+  %c1 = constant 1 : index
+  %c0 = constant 0 : index
+  // expected-error at +1: 'std.memref_cast' op operand #0 must be unranked.memref of any type values or memref of any type values,
+  %5 = memref_cast %arg0 : memref<?x?xf64> to memref<?x?xf64, #map1>
+  %25 = std.subview %5[%c0, %c0][%c1, %c1][] : memref<?x?xf64, #map1> to memref<?x?xf64, #map1>
+  return
+}
+


        


More information about the Mlir-commits mailing list