Accessing SymbolTableCollection for an operation


If one defines an Op such as GetGlobal with Trait DeclareOpInterfaceMethods<SymbolUserOpInterface>]
then the AsmParser for GetGlobal automatically calls verifySymbolUses (such as in …
GetGlobalOp::verifySymbolUses(SymbolTableCollection &).
But how do I verify the symbol use for in-memory built mlir (i.e. not read through parser). I mean 'how to I get hold of the right SymbolTableCollection? Or is that not needed (cannot be done) ?

My question may seem odd in case I may have misunderstood how verifySymbolUse is intended to be used.

This topic is related to Extracting attributes as operands - #10 by mehdi_amini , Using SymbolUserOpInterface properly - #5 by javedabsar and Globals in MLIR - #4 by javedabsar


I was able to solve it this way, but I am keen to know a better way

bool checkGetGlobalOpAccess(mlir::Operation *inst) {
  auto getGlobalOp = dyn_cast<mlir::myDialect::GetGlobalOp>(inst);
  auto op2 =
          inst, getGlobalOp.nameAttr());
  if (!op2) {
    throw my_error_report("myDialect.get_global did not reference a valid global");
  if (op2.type() != getGlobalOp.result().getType()) {
    throw my_error_report("myDialect.get_global type did not match");
  return true;