How can I get the name in pass that corresponds to the ssa value of a previously created op?

Hi everyone, I seem to be having a bit of a problem writing passes . It’s like this, I’m writing a pass, and when I want to create an operation, I realize that the operation needs some attributes, these attributes are the names of the ssa values (StringAttr) that are needed to create the operation.

// Make the question more specific
%aaa = ....  // I'd like to take aaa as an attribute.

But this ssa value is also created in pass, and I don’t have a good solution for this problem at the moment.It’s a bit of a strange question, but it’s true.I wonder if there is a way to be able to do that here. Hopefully someone can help me. Thank you.

%aaa in general does not exist in the IR, this is purely a textual thing.

There is a way for the parser to make it an attribute on the operation, but in any case it won’t be an “SSA value name” when you write a pass.

1 Like

Get it.I was actually thinking the same thing as this op does have a custom parser. thank you.

Thanks for the answer @mehdi_amini! For some context, the problem we’re trying to solve is using function-like operations that require pass arguments “by name”. For example, we want to have:

calyx.component @foo(a: 32, b: 32) -> (c: 16, d: 16) { ... }
calyx.component @bar(...) {
  invoke @foo(a = x, b = y)(c = z, d = w)
}

Within MLIR, we can potentially desugar this “by-name” passing into positional arguments but we need to be able to recover the named assignments during emission of the dialect (because the native toolchain requires the above format).

Are there any dialects/operations we can look at for inspiration?

In general this seems just like a combination of attribute mapping here?

You could parse invoke @foo(a = %x, b = %y)(c = %z, d = %w)
into "calyx.invoke"(%0, %1, %2, %3) { callee = @foo, named_operands=["a", "b", "c", "d"] }
for example?

Dear Sir, it is indeed possible to do this in Parser, but I think what @rachitnigam meant more specifically should be how to do it in Pass.

I don’t understand what it means to do this in a pass? Can you elaborate on this?

Dear Sir, actually it’s the same question I asked you before, as an example, I created an operation.
%a = dialect.operation ...
Here %a is shown after Pass launch. But I want to get the a here to use as an attribute before it is launched (to be honest, I think the answer to this question is actually above, as we discussed before).

Excuse me sir, I’m sorry, I think it was my mistake, I wasn’t thinking very far ahead, I can’t explain the specifics here, but our problem has been resolved.