Hi all,
I am very new to MLIR and exploring the standalone project of MLIR. I have added two custom operations in StandaloneOps.td
file. The added operations looks like below -
def Standalone_AddIOp : Standalone_Op<"addi", [Commutative]> {
let summary = "integer addition operation";
let description = [{
The `addi` operation takes two operands and returns one result, each of
these is required to be the same type. This type may be an integer scalar
type, a vector whose element type is integer, or a tensor of integers. It
has no standard attributes.
Example:
```mlir
// Scalar addition.
%a = arith.addi %b, %c : i32
```
}];
let arguments = (ins I32:$lhs, I32:$rhs);
let results = (outs I32:$res);
let assemblyFormat = "$lhs `,` $rhs attr-dict `:` type($res)";
}
And the print operation -
def Standalone_PrintOp : Standalone_Op<"print"> {
let summary = "print operation";
let description = [{
The "print" builtin operation prints a given input tensor, and produces
no results.
}];
// The print operation takes an input tensor to print.
let arguments = (ins I32:$input);
let assemblyFormat = "$input attr-dict `:` type($input)";
}
Then I modified the standalone-capi-test.c
as follow -
MlirModule module = mlirModuleCreateParse(
ctx, mlirStringRefCreateFromCString( "func.func @main() {"
"%0 = arith.constant 2 : i32\n"
"%1 = arith.constant 3 : i32\n"
"%2 = standalone.addi %0, %1 : i32 \n"
"standalone.print %2 : i32 \n"
"return }"));
After this changes I can generate MLIR code from this which looks like -
module {
func.func @main() {
%c2_i32 = arith.constant 2 : i32
%c3_i32 = arith.constant 3 : i32
%0 = standalone.addi %c2_i32, %c3_i32 : i32
standalone.print %0 : i32
return
}
}
However, I am not able to lower the code to llvm.
I am trying like this -
./bin/standalone-opt ./bin/test.mlir -convert-scf-to-cf -convert-func-to-llvm -convert-cf-to-llvm -convert-memref-to-llvm -reconcile-unrealized-casts -convert-vector-to-llvm -allow-unregistered-dialect -mlir-print-debuginfo > test.llvm
This works fine and then trying to generate ll code from the llvm using the below command
./bin/standalone-translate -mlir-to-llvmir test.llvm -debug > test.ll
However, this gives me error -
test.llvm:5:10: error: Dialect `standalone' not found for custom op 'standalone.addi'
%2 = standalone.addi %0, %1 : i32 loc(#loc4)
^
test.llvm:5:10: note: Registered dialects: acc, amx, arm_neon, arm_sve, builtin, dlti, func, gpu, llvm, nvvm, omp, rocdl, x86vector ; for more info on dialect registration see https://mlir.llvm.org/getting_started/Faq/#registered-loaded-dependent-whats-up-with-dialects-management
Would you please help me to resolve this issue? Thanks in advance.
Regards
Sudip