This is an archive of the discontinued LLVM Phabricator instance.

[mlir][ods] Do not print default-valued attributes when the value is equal to the default
ClosedPublic

Authored by jfurtek on Oct 14 2022, 4:03 PM.

Details

Summary

This diff causes the tblgen-erated print() function to skip printing a
DefaultValuedAttr attribute when the value is equal to the default.

This feature will reduce the amount of custom printing code that needs to be
written by users a relatively common scenario. As a motivating example, for the
fastmath flags in the LLVMIR dialect, we would prefer to print this:

%0 = llvm.fadd %arg0, %arg1 : f32

instead of this:

%0 = llvm.fadd %arg0, %arg1 {fastmathFlags = #llvm.fastmath<none>} : f32

This diff makes the handling of print functionality for default-valued attributes
standard.

This is an updated version of https://reviews.llvm.org/D135398, without the per-attribute bit to control printing.

Diff Detail

Event Timeline

jfurtek created this revision.Oct 14 2022, 4:03 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 14 2022, 4:03 PM
jfurtek requested review of this revision.Oct 14 2022, 4:03 PM
jfurtek edited the summary of this revision. (Show Details)Oct 14 2022, 4:06 PM
jfurtek added reviewers: rriddle, Mogball.
Mogball accepted this revision.Oct 14 2022, 5:22 PM
Mogball added inline comments.
mlir/docs/OpDefinitions.md
277

This seems more appropriate for the assembly format section

mlir/tools/mlir-tblgen/OpFormatGen.cpp
1647
1655

can you spell out all these autos? auto should only be used if the return type can be found on the right hard side of the assignment

1667

you can use auto here, for example

This revision is now accepted and ready to land.Oct 14 2022, 5:22 PM

@Mogball, thank you for the review. I fixed the autos and the SmallVector size before merging this on behalf of @jfurtek.

Nice. This seems like a good direction in general.