Issue |
125174
|
Summary |
how to define an array in mlir?
|
Labels |
mlir
|
Assignees |
|
Reporter |
Shaquille-Wu
|
hello, llvm&mlir experts
I have a trouble about defining a 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));
}
```
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?
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs