Adds MemRef type and adds support for parsing memref affine map composition.

PiperOrigin-RevId: 204756982
diff --git a/test/IR/parser-errors.mlir b/test/IR/parser-errors.mlir
index 27a53bd..ff03b51 100644
--- a/test/IR/parser-errors.mlir
+++ b/test/IR/parser-errors.mlir
@@ -13,6 +13,47 @@
 extfunc @nestedtensor(tensor<tensor<i8>>) -> () // expected-error {{expected type}}
 
 // -----
+// Test no comma in memref type.
+// TODO(andydavis) Fix this test if we decide to allow empty affine map to
+// imply identity affine map.
+extfunc @memrefs(memref<2x4xi8>) ; expected-error {{expected ',' in memref type}}
+
+// -----
+// Test no map in memref type.
+extfunc @memrefs(memref<2x4xi8, >) ; expected-error {{expected list element}}
+
+// -----
+// Test non-existent map in memref type.
+extfunc @memrefs(memref<2x4xi8, #map7>) ; expected-error {{undefined affine map id 'map7'}}
+
+// -----
+// Test non hash identifier in memref type.
+extfunc @memrefs(memref<2x4xi8, %map7>) ; expected-error {{expected '(' at start of dimensional identifiers list}}
+
+// -----
+// Test non-existent map in map composition of memref type.
+#map0 = (d0, d1) -> (d0, d1)
+
+extfunc @memrefs(memref<2x4xi8, #map0, #map8>) ; expected-error {{undefined affine map id 'map8'}}
+
+// -----
+// Test multiple memory space error.
+#map0 = (d0, d1) -> (d0, d1)
+extfunc @memrefs(memref<2x4xi8, #map0, 1, 2>) ; expected-error {{multiple memory spaces specified in memref type}}
+
+// -----
+// Test affine map after memory space.
+#map0 = (d0, d1) -> (d0, d1)
+#map1 = (d0, d1) -> (d0, d1)
+
+extfunc @memrefs(memref<2x4xi8, #map0, 1, #map1>) ; expected-error {{affine map after memory space in memref type}}
+
+// -----
+// Test no memory space error.
+#map0 = (d0, d1) -> (d0, d1)
+extfunc @memrefs(memref<2x4xi8, #map0>) ; expected-error {{expected memory space in memref type}}
+
+// -----
 
 cfgfunc @foo()
 cfgfunc @bar() // expected-error {{expected '{' in CFG function}}
diff --git a/test/IR/parser.mlir b/test/IR/parser.mlir
index 4ba9aa4..069c267 100644
--- a/test/IR/parser.mlir
+++ b/test/IR/parser.mlir
@@ -3,6 +3,11 @@
 //
 // RUN: %S/../../mlir-opt %s -o - | FileCheck %s
 
+#map0 = (d0, d1, d2, d3, d4) [s0] -> (d0, d1, d2, d3, d4)
+#map1 = (d0) -> (d0)
+#map2 = (d0, d1, d2) -> (d0, d1, d2)
+#map3 = (d0, d1, d2) -> (d1, d0, d2)
+#map4 = (d0, d1, d2) -> (d2, d1, d0)
 
 // CHECK: extfunc @foo(i32, i64) -> f32
 extfunc @foo(i32, i64) -> f32
@@ -27,12 +32,31 @@
 extfunc @tensors(tensor<?? f32>, tensor<?? vector<2x4xf32>>,
                  tensor<1x?x4x?x?xaffineint>, tensor<i8>)
 
-// CHECK: extfunc @memrefs(i1, i1)
-extfunc @memrefs(memref<1x?x4x?x?xaffineint>, memref<i8>)
+// TODO(andydavis) Add support to outline affine maps for these cases.
+// CHECK: extfunc @memrefs(memref<1x?x4x?x?xaffineint, (d0, d1, d2, d3, d4) [s0] -> (d0, d1, d2, d3, d4), 0>, memref<i8, (d0) -> (d0), 0>)
+extfunc @memrefs(memref<1x?x4x?x?xaffineint, #map0, 0>, memref<i8, #map1, 0>)
 
-// CHECK: extfunc @functions((i1, i1) -> (), () -> ())
-extfunc @functions((memref<1x?x4x?x?xaffineint>, memref<i8>) -> (), ()->())
+// Test memref affine map compositions.
 
+// CHECK: extfunc @memrefs2(memref<2x4x8xi8, (d0, d1, d2) -> (d0, d1, d2), 1>)
+extfunc @memrefs2(memref<2x4x8xi8, #map2, 1>)
+
+// CHECK: extfunc @memrefs23(memref<2x4x8xi8, (d0, d1, d2) -> (d0, d1, d2), (d0, d1, d2) -> (d1, d0, d2), 0>)
+extfunc @memrefs23(memref<2x4x8xi8, #map2, #map3, 0>)
+
+// CHECK: extfunc @memrefs234(memref<2x4x8xi8, (d0, d1, d2) -> (d0, d1, d2), (d0, d1, d2) -> (d1, d0, d2), (d0, d1, d2) -> (d2, d1, d0), 3>)
+extfunc @memrefs234(memref<2x4x8xi8, #map2, #map3, #map4, 3>)
+
+// Test memref inline affine map compositions.
+
+// CHECK: extfunc @memrefs2(memref<2x4x8xi8, (d0, d1, d2) -> (d0, d1, d2), 0>)
+extfunc @memrefs2(memref<2x4x8xi8, (d0, d1, d2) -> (d0, d1, d2), 0>)
+
+// CHECK: extfunc @memrefs23(memref<2x4x8xi8, (d0, d1, d2) -> (d0, d1, d2), (d0, d1, d2) -> (d1, d0, d2), 1>)
+extfunc @memrefs23(memref<2x4x8xi8, (d0, d1, d2) -> (d0, d1, d2), (d0, d1, d2) -> (d1, d0, d2), 1>)
+
+// CHECK: extfunc @functions((memref<1x?x4x?x?xaffineint, (d0, d1, d2, d3, d4) [s0] -> (d0, d1, d2, d3, d4), 0>, memref<i8, (d0) -> (d0), 0>) -> (), () -> ())
+extfunc @functions((memref<1x?x4x?x?xaffineint, #map0, 0>, memref<i8, #map1, 0>) -> (), ()->())
 
 // CHECK-LABEL: cfgfunc @simpleCFG(i32, f32) {
 cfgfunc @simpleCFG(i32, f32) {