Get the SSA name of Value

Hi, I can print an operation easily and get something like %0 = Actor.DoSomething %1 %2. However, I find it difficult to print the results and operands, separately. For example, for debugging purposes, I would like to print %0 at one place and %1 %2 at another place. I tried to use Value::printAsOperand() but it doesn’t work out (I guess that I’m not using AsmState in a correct way). In LLVM, there is Value::getName(). I’m wondering if MLIR has a similar function to do so? Thanks!

Value naming is kind of nuanced, because the way a value gets named can depend on a lot of factors: are you printing with local scope? are you printing in the generic form? what is the top-level operation you are printing under? does something override the interface for providing names? etc. Each of those can change the end result, and many of those can be dynamic (i.e. be different on different calls to print).

MLIR values do not inherently have names, as they do in LLVM, so we don’t provide any type of getName functionality. The reasons for this are varied, and some of it has to do with things mentioned above.

AsmState should be the source of truth for how naming is done (the non-AsmState print functions just construct one internally and call into the AsmState variants). Can you share what setup you are using?

1 Like

Thanks for the heads up that the naming is dynamic. I was able to reproduce what I would like to retrieve from the AsmPrinter.