In .td file,where is getSource defined?

hi all, I define a simple Dialect,

def PrintOp : Flow_Op<"print"> {
    let summary = "print operation";
    let description = [{ "flow.print" }];
    let arguments = (ins AnyTypeOf<[F64Tensor, F64MemRef, F64]>:$input);

    let extraClassDeclaration = [{
        Type getPrintType() {
            return getSource().getType();

    let assemblyFormat = "$input attr-dict `:` type($input)";

when I refer llvm-project/ at release/16.x · llvm/llvm-project · GitHub, but error: use of undeclared identifier 'getSource' return getSource().getType();

The line following the one you referenced (llvm-project/ at release/16.x · llvm/llvm-project · GitHub) contains Arguments<(ins AnyType:$source)>. Getters and setters are generated for all named arguments by converting their names into camelBack with get/set prefix. Your op does not have an argument or result named $source.

You can always run mlir-tblgen -gen-op-decls manually to see the code that gets generated.

1 Like

Thanks, I understand it. In my demo, the get function is called getInput(). thanks.

when I lowering cutom printOp, I use llvm builtin function to call flow.print %2: f64

      if (type.isF64()) {
        Operation *printer = LLVM::lookupOrCreatePrintF64Fn(parent);
        rewriter.create<LLVM::CallOp>(op->getLoc(), TypeRange(), SymbolRefAttr::get(printer), operands);
        return success();

the final llvmir is

declare void @printF64(double)
define void @main() {
call void @printF64(double %36)

when I run it with jit like mlir toy language, found
JIT session error: Symbols not found: [ printF64 ] JIT invocation failed Program aborted due to an unhandled Error: Failed to materialize symbols: { (main, { main, _mlir_main }) } Aborted (core dumped)

how can I link my execuate binary to llvm dynamic library like or others and run it. Thanks.

The JIT runner resolves libraries here llvm-project/ExecutionEngine.cpp at eee3477722dea32e3d5e9d3a517e1bd5e124a1bf · llvm/llvm-project · GitHub. If your code is using MLIR JIT, make sure it hits these lines by setting the right options.

Ok, but I use this options

mlir::ExecutionEngineOptions engineOptions;
engineOptions.sharedLibPaths = {"", ""};

I suppose you need to put actual paths to the libs there, not empty lines.

yes. This is example, I run it successfully. Thank you for your help.

so confused. when I run my custom dialect on x86 linux, it is success. but on my M1 Mac, same code, when run with jit, it is segmentation fault.

the jit source code

int runJit(mlir::ModuleOp module) {


  auto optPipeline = mlir::makeOptimizingTransformer(0, 0, nullptr);

  mlir::ExecutionEngineOptions engineOptions;
  engineOptions.transformer = optPipeline;
//  engineOptions.sharedLibPaths = {"/home/lay/llvm/build/lib/", "/home/lay/llvm/build/lib/"};
  engineOptions.sharedLibPaths = {"/Users/lei/soft/llvm-project/build/lib/libmlir_runner_utils.dylib", "/Users/lei/soft/llvm-project/build/lib/libmlir_c_runner_utils.dylib"};

  auto maybeEngine = mlir::ExecutionEngine::create(module, engineOptions);
  assert(maybeEngine && "failed to construct an execution engine");
  auto &engine = maybeEngine.get();

  auto invocationResult = engine->invokePacked("main");
  if (invocationResult) {
    llvm::errs() << "JIT invocation failed\n";
    return -1;

  return 0;
❯ ./flow-opt/flow-opt ../example/flow.mlir --emit=jit
[1]    55153 segmentation fault  ./flow-opt/flow-opt ../example/flow.mlir --emit=jit

but when I use mlir-opt to lowing this dialect to .ll and run it with mlir-cpu-runner is it success. and the bash is /Users/lei/soft/llvm-project/build/bin/mlir-opt ../example/affine.mlir | /Users/lei/soft/llvm-project/build/bin/mlir-cpu-runner -e main -entry-point-result=void -shared-libs=/Users/lei/soft/llvm-project/build/lib/libmlir_runner_utils.dylib -shared-libs=/Users/lei/soft/llvm-project/build/lib/libmlir_c_runner_utils.dylib 51%

and M1 and x86 linux use same llvm repo(release 16.x).