[MLIR] How to make ElementsAttr into a Property?

Hi!

I have a constant operation in my dialect that contains an ElementsAttr that stores the value. It looks something like this:

def Constant : My_Op<"Constant", [NoMemoryEffect]> {
  let arguments = (ins ElementsAttr : $value);
  ...
}

This ElementsAttr is often used to store large and unique constants. Since attributes in MLIR will live for the entirety of the process, these large weights increase the memory usage of the compiler, even long after they are not needed. With the new addition of Properties in MLIR, if these ElementsAttrs become Properties, they should be de-allocated after the operation has been destroyed. This should lead to an overall decrease in memory usage.

My question is, how do we go about defining an ElementsAttr (or something equivalent) as a property in MLIR? I’ve looking through the documentation, past presentation and looking at the test dialect but couldn’t figure it out. I would like to keep using the ElementsAttr interface but just have it not be stored in the context.

Thanks in advance for the help!

Properties could allow to design such an attribute as shared_ptr into data managed by your dialect.
It would still need to be using some sort of attribute if you really want the ElementsAttrs.

That said you don’t even need properties for this, we have “resource”. Unfortunately this is one the very rare feature that isn’t documented and does not have concrete example in-tree beyond unit-test.
This allows to keep data stored outside of MLIR and access them through attributes.