Adding Attribute to an Op after creation

Hi Folks:

If I needed to add an attribute to an op after it is created. Is there a way?
The code below won’t work (as FuncOp has no addAttribute method), but something similar to this is what I need:

  auto func_type = builder.getFunctionType({}, llvm::None);
 mlir::FuncOp function =
      builder.create<mlir::FuncOp>(location, "foo", func_type);
  function.addAttribute("myAttrName", builder.getI32IntegerAttr(myAttrValue));

I see that OperationState has ‘addAttribute’ method. How do I correctly get the ‘OperationState’ of an Op if possible.
Thanks

OperationState is a transient object that is only used to construct ops. What you are looking for is called Operation::setAttr.

1 Like