How to print the same attribute only once and print alias in the IR

Hi, I want to dump an IR where each Value has a layout Attribute (encoding of RankedTensorType). Many Values have the same layout. I don’t want to print the full layout string each time it appears in the IR, but only once at the beginning and use alias in the IR:

#layout0 = a_very_long_layout_string
#layout1 = a_very_long_layout_string

%2 = arith.add %0, %1: #layout0
%3 = arith.add %4, %5: #layout0

I noticed that the PassManager prints in this format before and after passes, but when I print like this:

llvm::outs() << myFuncOp;

alias will not be used.

I think there might be a certain option that controls this, but I failed to find it in the source code.

Any advice?

Thanks in advance!

Qingyi

It’ll only happen if we print the top-level operation: that is if the operation to print does not have a parent. We could add an OpPrintingFlags to force it though I think, feel free to send a PR if you want to give it a try!