Is it possible to tag operations with metadata

Hi, I am writing some passes that carry different responsibilities. and i have a pass that walks through all ops and should mark some of them with some basic metadata. is there any support from MLIR for this? I am trying to avoid making this metadata part of all my ops.

Any ideas?

I’m looking for something like this:

for (auto op : ops = getOps<Thread_CreateOp>())
{
if (op->hasMetadata){ // hasMetadata does not exist and im looking for a suggestion
auto md = op->getMetadata();
...
}
}

Attributes are a more advanced mechanism that superseeds metadata. You can set arbitrary attributes on an operation by calling op->setAttr and you can query them op->getAttr. These are discardable attributes meaning that ops don’t need to know about them, but passes are not guaranteed to preserve these attributes (most passes just drop them).

So in a case where i need to store an attribute in a pass so that i can access it in the next pass, it is not guaranteed that this attribute is preserved? if so, is there some way i could preserve this?

If you don’t run any other IR transform between your passes, nothing can remove your attribute.

The only way to make sure an attribute is preserved currently is to make in inherent to the operation, meaning that the operation will always verify the presence of this attribute. Then if the pass drops this attribute, the IR will become invalid and the verifier will complain.

Yes, to Alex’s point your pass can preserve it (it’s under your control) but arbitrary passes won’t/can’t be relied on to. And attributes don’t automatically get invalidated. Another option here is an analysis (Pass Infrastructure - MLIR), which does get invalidated, but the mapping to op is more manual.

Thanks guys, this helps a lot! i think ill go with setAttr for now. AnalysisManager will be too intrusive for my usecase.