<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/125173>125173</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            how to define an array in mlir?
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            mlir
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Shaquille-Wu
      </td>
    </tr>
</table>

<pre>
    hello, llvm&mlir experts
I have a trouble about defining an array in mlir.
first, I define a Dialect named as lunar, it is very simple dialect like this in .td file:
```
#ifndef LIB_DIALECT_LUNAR_LUNARDIALECT_TD_
#define LIB_DIALECT_LUNAR_LUNARDIALECT_TD_

include "mlir/IR/OpBase.td"

def Lunar_Dialect : Dialect {
  let name = "lunar";
  let summary = "A dialect for elementwise math";
  let description = [{
    The lunar dialect defines types and operations for elementwise computation.
  }];

 let cppNamespace = "::mlir::lunar";
  let useDefaultTypePrinterParser = 1;
}

#endif  // LIB_DIALECT_LUNAR_LUNARDIALECT_TD_
```
second, I define a datatype named as "array" in another .td file, like this:
```
#ifndef LIB_DIALECT_LUNAR_LUNARTYPES_TD_
#define LIB_DIALECT_LUNAR_LUNARTYPES_TD_

include "LunarDialect.td"
include "mlir/IR/AttrTypeBase.td"
include "mlir/IR/BuiltinTypes.td"
include "mlir/IR/BuiltinTypeInterfaces.td"

// A base class for all types in this dialect
class Lunar_Type<string name, string typeMnemonic, list<Trait> traits = []> : TypeDef<Lunar_Dialect, name, traits> {
  let mnemonic = typeMnemonic;
}

def ArrayData : Lunar_Type<"ArrayData", "array"> {
 let summary = "A array data";

  let description = [{
    A type for array.
  }];

  let parameters = (ins "Type":$dataType, "int":$size);
  let assemblyFormat = [{ `<` $dataType `x` $size `>` }];
}

#endif  // LIB_DIALECT_LUNAR_LUNARTYPES_TD_
```
the third, I modify my the .cpp file about LunarDialect like this:
```
#include "LunarDialect.h"
#include "LunarTypes.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/DialectImplementation.h"
#include "llvm/ADT/TypeSwitch.h"
#include "Dialect/Lunar/LunarDialect.cpp.inc"

#define GET_TYPEDEF_CLASSES
#include "Dialect/Lunar/LunarTypes.cpp.inc"

namespace mlir {
namespace lunar {

void LunarDialect::initialize() {
  addTypes<
#define GET_TYPEDEF_LIST
#include "Dialect/Lunar/LunarTypes.cpp.inc"
 >();
}

} // namespace poly
} // namespace mlir

```
the forth, I modify my verify tool(named as "lunar-opt"), and the .cpp file like this:
```
#include "mlir/InitAllDialects.h"
#include "mlir/InitAllPasses.h"
#include "mlir/Pass/PassManager.h"
#include "mlir/Pass/PassRegistry.h"
#include "mlir/Tools/mlir-opt/MlirOptMain.h"
#include "Dialect/Lunar/LunarDialect.h"

int main(int argc, char **argv) {
 mlir::DialectRegistry registry;
 registry.insert<mlir::lunar::LunarDialect>();
 mlir::registerAllDialects(registry);
  mlir::registerAllPasses();

 return mlir::asMainReturnCode(
      mlir::MlirOptMain(argc, argv, "lunar_opt Pass Driver", registry));
}
```
the fifth, I create a verify .mlir file, like this:
```
module {
  func.func @main(%arg0: !lunar.array<i32x10>) -> !lunar.array<i32x10> {
    return %arg0 : !lunar.array<i32x10>
  }
}
```
at last, I execute the "lunar-opt", and it throws the errors as following:
```
lunar_test_0.mlir:2:39: error: expected non-function type
  func.func @main(%arg0: !lunar.array<i32x10>) -> !lunar.array<i32x10> {
 ^
lunar_test_0.mlir:2:39: error: failed to parse ArrayData parameter 'dataType' which is to be a `Type`
  func.func @main(%arg0: !lunar.array<i32x10>) -> !lunar.array<i32x10> {
```

I guess the "i32" is not in the enums of mlir.Type according to above errors, 
I don't know why the mlir cannot accept the "i32"

So, is there anyone would like to teach me how to fix this trouble?


</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy8WN1u47oRfhr6hoghU3EcX_hC8U9hIHvOYuOi6FVASyOLPRSpkpQd9-mLISVZ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