Using SymbolUserOpInterface properly

Hi.
I am trying to use the example in include/mlir/Dialect/MemRef/IR/MemRefOps.td to define my own GetGlobalOp to access global memref.
This is skeleton of my implementation

def myDialect_GetGlobalOp : myDialect_Op<"get_global",
    [NoSideEffect, DeclareOpInterfaceMethods<SymbolUserOpInterface>]> {
  let summary = "get the memref pointing to a global variable";
  let description = [{.. }];
   let arguments = (ins FlatSymbolRefAttr:$name);
   let results = (outs myDialect_MemrefType:$result);
   let assemblyFormat = "$name `:` type($result) attr-dict";
   let verifier = ?;
}

Just doing this and nothing else leads to error

error: undefined reference to `mlir::myDialect::GetGlobalOp::verifySymbolUses(mlir::SymbolTableCollection&)’

which told me that much like …
lib/Dialect/MemRef/IR/MemRefOps.cpp:: GetGlobalOp::verifySymbolUses(SymbolTableCollection &symbolTable) {…}

… i need to define my own 'GetGlobalOp::verifySymbolUses’
But when I do define

mlir::LogicalResult
myDialect::GetGlobalOp::verifySymbolUses(mlir::SymbolTableCollection &symbolTable) {
  return mlir::success();
}

I get the error
error: 'myDialect::GetGlobalOp' has not been declared
which is right because I did not declare a class ‘myDialect::GetGlobalOp’ explicitly anywhere. But then when I search I find that neither did MemRef (and I assume it is created automatically?). What am I missing?

You don’t need to declare it, it should be done by the TableGen generated file for the operation.
The issue here seems that you trying to define this in a place that does not include the generated header for the operation. If you take example on MemRefOps.td, the CMakeLists.txt in the same folder invokes add_mlir_dialect(MemRefOps memref) which will take care of invoking mlir-tblgen to generate the classes here: llvm-project/AddMLIR.cmake at main · llvm/llvm-project · GitHub

In the build directory you should see this: $ cat tools/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.h.inc

This is then exposed through a regular header here: llvm-project/MemRef.h at main · llvm/llvm-project · GitHub

Thank you. That explanation helped (otherwise i was thinking of writing GetGlobal class) and I have moved pass that issue. May I ask about how to define custom mlir assembly e.g.
'let assemblyFormat = "$name : type($result) attr-dict";'
In my case, despite specifying exactly as above (also as in full code shraed above), when i write the following mlir, assembler does not seem to head above format, but instead complains

error: expected '(' to start operand list
%x = "myDialect.get_global" @foo : !myDialect<"memref<3xf32, 1>">
                                ^

I guess I am not sure how assemblyFormat works in this case.

I think if the operation name is in quotes, MLIR assumes its parsing a generic assembly format, which is "dialect.opname"(operands) : attr-dict and that’s why its complaining. Can you try removing the quotes around “myDialect.get_global” and see if that works?

You are right. that works. thanks!