Adding attributes to function arguments?


This is probably a simple question but I could not find a reference example code for it.
I am trying to add attributes to the memref arguments of my function.

I am aware that Operations can have attributes added with op.setAttr("name", "value"), but this does not work for BlockArgument types.

How can I do it for the function arguments?

My current attempt:

for (BlockArgument argument : dstFunc.getArguments()) {

    if(argument.getType().cast<MemRefType>()) {
      dstFunc.emitWarning() << argument << " This is a memref!";

      argument.setAttr(LLVMDialect::getNoAliasAttrName(), "1"); // Error!

Errors with:

class "mlir::BlockArgument" has no member "setAttr"

Do I have to cast it to a different class? Which class?

Thanks in advance!


As an outcome I am trying to build this function signature:

func @kernel(%arg0: memref<2x2xf32> {llvm.noalias}, 
             %arg1: f32, %arg2: memref<2x2xf32> {llvm.noalias}, 
             %arg3: memref<2x2xf32> {llvm.noalias}, 
             %arg4: f32) {...

Only operations have attribute, not arguments. The llvm.func operation holds attributes for its arguments. The syntax you see, where the attributes are interleaved in the function signature, is a custom pretty printer in the function-like trait: llvm-project/FunctionImplementation.cpp at 313c657fcea371a533ad5f3adcff44fabc6531ae · llvm/llvm-project · GitHub

Thank you! Makes sense!
This is exactly what I was looking for.